* configure.ac (DEBUGDIR_RELOCATABLE): Define for debugdir inside
authorDaniel Jacobowitz <drow@false.org>
Tue, 9 Jan 2007 21:34:30 +0000 (21:34 +0000)
committerDaniel Jacobowitz <drow@false.org>
Tue, 9 Jan 2007 21:34:30 +0000 (21:34 +0000)
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.

gdb/ChangeLog
gdb/config.in
gdb/configure
gdb/configure.ac
gdb/defs.h
gdb/main.c
gdb/symfile.c

index 3cbfc67..eecf639 100644 (file)
@@ -1,3 +1,19 @@
+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.
+
 2007-01-09  Jim Blandy  <jimb@codesourcery.com>
 
        * score-tdep.c (score_push_dummy_call): Don't mix declarations and
index 11647f1..59793f5 100644 (file)
@@ -14,6 +14,9 @@
 /* Global directory for separate debug files. */
 #undef DEBUGDIR
 
+/* Define if the debug directory should be relocated when GDB is moved. */
+#undef DEBUGDIR_RELOCATABLE
+
 /* Define to BFD's default architecture. */
 #undef DEFAULT_BFD_ARCH
 
index 69cb9cd..adbb231 100755 (executable)
@@ -3053,6 +3053,26 @@ _ACEOF
 
 #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}/'*)
+
+cat >>confdefs.h <<\_ACEOF
+#define DEBUGDIR_RELOCATABLE 1
+_ACEOF
+
+  ;;
+esac
+
 
 
 subdirs="$subdirs doc testsuite"
@@ -21172,7 +21192,7 @@ if test "${with_sysroot+set}" = set; then
 
  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 3a55c51..f0ce462 100644 (file)
@@ -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 3ab633e..c7e6d3a 100644 (file)
@@ -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 7e25d77..7cc14ad 100644 (file)
@@ -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 99c965e..37a57c8 100644 (file)
@@ -1156,7 +1156,7 @@ separate_debug_file_exists (const char *name, unsigned long crc)
   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 *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 *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."), _("\