This is the mail archive of the gdb-patches@sourceware.org mailing list for the GDB project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [rfc] Separate debug files and --with-sysroot


On Wed, Nov 01, 2006 at 12:08:16PM -0500, Daniel Jacobowitz wrote:
> The attached patch does two things:
>   - We relocate the default sysroot when GDB is moved, based on the runtime
>     prefix.  Extend the same logic to the default debug directory, so that
>     a prepared installation can be dropped in at any path - very useful
>     when distributing.
>   - If a system root is configured, and an object file is inside the system
>     root, the system root path is removed when searching the debug file
>     directory.
> 
> This seems pretty reasonable to me.  Looking at it now, I'm thinking of an
> additional tweak: adding "set sysroot", and making solib-absolute-prefix
> an alias to that, so that the sysroot is configurable at runtime.  That
> will need a documentation update.

I've now added set sysroot, so I checked this in.  Updated version attached.

-- 
Daniel Jacobowitz
CodeSourcery

2007-01-09  Daniel Jacobowitz  <dan@codesourcery.com>

	* configure.ac (DEBUGDIR_RELOCATABLE): Define for debugdir inside
	exec_prefix.
	(TARGET_SYSTEM_ROOT_RELOCATABLE): Allow for exec_prefix being
	'${prefix}'.
	* configure, config.in: Regenerate.
	* defs.h (debug_file_directory): Declare.
	* main.c (captured_main): Canonicalize gdb_sysroot.  Assume
	TARGET_SYSTEM_ROOT is defined.  Initialize debug_file_directory and
	relocate it if DEBUGDIR_RELOCATABLE.
	* symfile.c (debug_file_directory): Make non-static.
	(find_separate_debug_file): Look for debug info for SYSROOT/PATH
	in DEBUGDIR/PATH if DEBUGDIR is inside SYSROOT.
	(_initialize_symfile): Don't initialize debug_file_directory here.

Index: configure.ac
===================================================================
RCS file: /cvs/src/src/gdb/configure.ac,v
retrieving revision 1.40
diff -u -p -r1.40 configure.ac
--- configure.ac	9 Jan 2007 14:58:57 -0000	1.40
+++ configure.ac	9 Jan 2007 21:29:21 -0000
@@ -75,6 +75,22 @@ AC_DEFINE_DIR(DEBUGDIR, debugdir,
               [Global directory for separate debug files. ])
 #AC_DEFINE_UNQUOTED(DEBUGDIR, "$debugdir"),
 
+if test "x$exec_prefix" = xNONE || test "x$exec_prefix" = 'x${prefix}'; then
+  if test "x$prefix" = xNONE; then
+    test_prefix=/usr/local
+  else
+    test_prefix=$prefix
+  fi
+else
+  test_prefix=$exec_prefix
+fi
+case ${debugdir} in
+"${test_prefix}"|"${test_prefix}/"*|\
+'${exec_prefix}'|'${exec_prefix}/'*)
+  AC_DEFINE(DEBUGDIR_RELOCATABLE, 1, [Define if the debug directory should be relocated when GDB is moved.])
+  ;;
+esac
+
 AC_CONFIG_SUBDIRS(doc testsuite)
 
 # Provide defaults for some variables set by the per-host and per-target
@@ -1102,7 +1118,7 @@ AC_ARG_WITH(sysroot,
 
  TARGET_SYSTEM_ROOT_DEFINE='-DTARGET_SYSTEM_ROOT=\"$(TARGET_SYSTEM_ROOT)\"'
 
- if test "x$exec_prefix" = xNONE; then
+ if test "x$exec_prefix" = xNONE || test "x$exec_prefix" = 'x${prefix}'; then
   if test "x$prefix" = xNONE; then
    test_prefix=/usr/local
   else
Index: defs.h
===================================================================
RCS file: /cvs/src/src/gdb/defs.h,v
retrieving revision 1.199
diff -u -p -r1.199 defs.h
--- defs.h	9 Jan 2007 17:58:50 -0000	1.199
+++ defs.h	9 Jan 2007 21:29:21 -0000
@@ -167,6 +167,9 @@ extern int dbx_commands;
 /* System root path, used to find libraries etc.  */
 extern char *gdb_sysroot;
 
+/* Search path for separate debug files.  */
+extern char *debug_file_directory;
+
 extern int quit_flag;
 extern int immediate_quit;
 extern int sevenbit_strings;
Index: main.c
===================================================================
RCS file: /cvs/src/src/gdb/main.c,v
retrieving revision 1.61
diff -u -p -r1.61 main.c
--- main.c	9 Jan 2007 17:58:52 -0000	1.61
+++ main.c	9 Jan 2007 21:29:22 -0000
@@ -221,19 +221,60 @@ captured_main (void *data)
       if (res == 0)
 	{
 	  xfree (gdb_sysroot);
-	  gdb_sysroot = TARGET_SYSTEM_ROOT;
+	  gdb_sysroot = xstrdup (TARGET_SYSTEM_ROOT);
 	}
     }
   else
-    gdb_sysroot = TARGET_SYSTEM_ROOT;
+    gdb_sysroot = xstrdup (TARGET_SYSTEM_ROOT);
 #else
-#if defined (TARGET_SYSTEM_ROOT)
-  gdb_sysroot = TARGET_SYSTEM_ROOT;
-#else
-  gdb_sysroot = "";
+  gdb_sysroot = xstrdup (TARGET_SYSTEM_ROOT);
 #endif
+
+  /* Canonicalize the sysroot path.  */
+  if (*gdb_sysroot)
+    {
+      char *canon_sysroot = lrealpath (gdb_sysroot);
+      if (canon_sysroot)
+	{
+	  xfree (gdb_sysroot);
+	  gdb_sysroot = canon_sysroot;
+	}
+    }
+
+#ifdef DEBUGDIR_RELOCATABLE
+  debug_file_directory = make_relative_prefix (argv[0], BINDIR, DEBUGDIR);
+  if (debug_file_directory)
+    {
+      struct stat s;
+      int res = 0;
+
+      if (stat (debug_file_directory, &s) == 0)
+	if (S_ISDIR (s.st_mode))
+	  res = 1;
+
+      if (res == 0)
+	{
+	  xfree (debug_file_directory);
+	  debug_file_directory = xstrdup (DEBUGDIR);
+	}
+    }
+  else
+    debug_file_directory = xstrdup (DEBUGDIR);
+#else
+  debug_file_directory = xstrdup (DEBUGDIR);
 #endif
 
+  /* Canonicalize the debugfile path.  */
+  if (*debug_file_directory)
+    {
+      char *canon_debug = lrealpath (debug_file_directory);
+      if (canon_debug)
+	{
+	  xfree (debug_file_directory);
+	  debug_file_directory = canon_debug;
+	}
+    }
+
   /* There will always be an interpreter.  Either the one passed into
      this captured main, or one specified by the user at start up, or
      the console.  Initialize the interpreter to the one requested by 
Index: symfile.c
===================================================================
RCS file: /cvs/src/src/gdb/symfile.c,v
retrieving revision 1.178
diff -u -p -r1.178 symfile.c
--- symfile.c	9 Jan 2007 17:58:59 -0000	1.178
+++ symfile.c	9 Jan 2007 21:29:23 -0000
@@ -1156,7 +1156,7 @@ separate_debug_file_exists (const char *
   return crc == file_crc;
 }
 
-static char *debug_file_directory = NULL;
+char *debug_file_directory = NULL;
 static void
 show_debug_file_directory (struct ui_file *file, int from_tty,
 			   struct cmd_list_element *c, const char *value)
@@ -1178,6 +1178,7 @@ find_separate_debug_file (struct objfile
   char *dir;
   char *debugfile;
   char *name_copy;
+  char *canon_name;
   bfd_size_type debuglink_size;
   unsigned long crc32;
   int i;
@@ -1245,6 +1246,30 @@ find_separate_debug_file (struct objfile
       return xstrdup (debugfile);
     }
 
+  /* If the file is in the sysroot, try using its base path in the
+     global debugfile directory.  */
+  canon_name = lrealpath (dir);
+  if (canon_name
+      && strncmp (canon_name, gdb_sysroot, strlen (gdb_sysroot)) == 0
+      && IS_DIR_SEPARATOR (canon_name[strlen (gdb_sysroot)]))
+    {
+      strcpy (debugfile, debug_file_directory);
+      strcat (debugfile, canon_name + strlen (gdb_sysroot));
+      strcat (debugfile, "/");
+      strcat (debugfile, basename);
+
+      if (separate_debug_file_exists (debugfile, crc32))
+	{
+	  xfree (canon_name);
+	  xfree (basename);
+	  xfree (dir);
+	  return xstrdup (debugfile);
+	}
+    }
+  
+  if (canon_name)
+    xfree (canon_name);
+
   xfree (basename);
   xfree (dir);
   return NULL;
@@ -3857,7 +3882,6 @@ Usage: set extension-language .foo bar")
   add_info ("extensions", info_ext_lang_command,
 	    _("All filename extensions associated with a source language."));
 
-  debug_file_directory = xstrdup (DEBUGDIR);
   add_setshow_optional_filename_cmd ("debug-file-directory", class_support,
 				     &debug_file_directory, _("\
 Set the directory where separate debug symbols are searched for."), _("\


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]