Introduce "set debug separate-debug-file"
authorSimon Marchi <simon.marchi@ericsson.com>
Sun, 11 Jun 2017 21:16:01 +0000 (23:16 +0200)
committerSimon Marchi <simon.marchi@ericsson.com>
Sun, 11 Jun 2017 21:16:28 +0000 (23:16 +0200)
I helped someone figure out why their separate debug info (debug
link-based) was not found by gdb.  It turns out that the debug file was
not named properly.  It made me realize that it is quite difficult to
diagnose this kind of problems.  This patch adds some debug output to
show where GDB looks for those files, so that it should be (more)
obvious to find what's wrong.

Here's an example of the result, first with an example of unsuccessful lookup,
and then a successful one.

  (gdb) set debug separate-debug-file on
  (gdb) file /usr/bin/gnome-calculator
  Reading symbols from /usr/bin/gnome-calculator...
  Looking for separate debug info (build-id) for /usr/bin/gnome-calculator
    Trying /usr/local/lib/debug/.build-id/0d/5c5e8c86dbe4f4f95f7a13de04f91d377f3c6a.debug

  Looking for separate debug info (debug link) for /usr/bin/gnome-calculator
    Trying /usr/bin/5c5e8c86dbe4f4f95f7a13de04f91d377f3c6a.debug
    Trying /usr/bin/.debug/5c5e8c86dbe4f4f95f7a13de04f91d377f3c6a.debug
    Trying /usr/local/lib/debug//usr/bin/5c5e8c86dbe4f4f95f7a13de04f91d377f3c6a.debug
  (no debugging symbols found)...done.
  (gdb) set debug-file-directory /usr/lib/debug
  (gdb) file /usr/bin/gnome-calculator
  Reading symbols from /usr/bin/gnome-calculator...
  Looking for separate debug info by build-id for /usr/bin/gnome-calculator
    Trying /usr/lib/debug/.build-id/0d/5c5e8c86dbe4f4f95f7a13de04f91d377f3c6a.debug
  Reading symbols from /usr/lib/debug/.build-id/0d/5c5e8c86dbe4f4f95f7a13de04f91d377f3c6a.debug...done.
  done.

Note: here, the debug link happens to be named like the build-id, but it
doesn't have to be this way.  It puzzled me for a minute.

gdb/ChangeLog:

* NEWS (Changes since GDB 8.0): Announce {set,show} debug
separate-debug-file commands.
* symfile.h (separate_debug_file_debug): New global.
* symfile.c (separate_debug_file_debug): New global.
(separate_debug_file_exists, find_separate_debug_file): Add
debug output.
(_initialize_symfile): Add "set debug separate-debug-file"
command.
* build-id.c (build_id_to_debug_bfd,
find_separate_debug_file_by_buildid): Add debug output.

gdb/doc/ChangeLog:

* gdb.texinfo (Optional Messages about Internal Happenings):
Document {set,show} debug separate-debug-file commands.

gdb/ChangeLog
gdb/NEWS
gdb/build-id.c
gdb/doc/ChangeLog
gdb/doc/gdb.texinfo
gdb/symfile.c
gdb/symfile.h

index c48fb92e9e002388448aa6fa8942a3a0abfb966c..38a40e13027ecf6a4c9961171f17ffcf6ffeee07 100644 (file)
@@ -1,3 +1,16 @@
+2017-06-11  Simon Marchi  <simon.marchi@ericsson.com>
+
+       * NEWS (Changes since GDB 8.0): Announce {set,show} debug
+       separate-debug-file commands.
+       * symfile.h (separate_debug_file_debug): New global.
+       * symfile.c (separate_debug_file_debug): New global.
+       (separate_debug_file_exists, find_separate_debug_file): Add
+       debug output.
+       (_initialize_symfile): Add "set debug separate-debug-file"
+       command.
+       * build-id.c (build_id_to_debug_bfd,
+       find_separate_debug_file_by_buildid): Add debug output.
+
 2017-06-10  Simon Marchi  <simon.marchi@polymtl.ca>
 
        * gdbarch.sh (displaced_step_free_closure): Remove.
index 8dab5d3d8fbca8c9266e9698e36f11ee7fad5d90..7c8a8f63de2a5575e89099728d1ec9ae7dc414da 100644 (file)
--- a/gdb/NEWS
+++ b/gdb/NEWS
 QStartupWithShell
   Indicates whether the inferior must be started with a shell or not.
 
+* New commands
+
+set debug separate-debug-file
+show debug separate-debug-file
+  Control the display of debug output about separate debug file search.
+
 *** Changes in GDB 8.0
 
 * GDB now supports access to the PKU register on GNU/Linux. The register is
index 0f632238776e747bb7a141b0c2aed942c3aefe8f..4b2b63ecb4ec44ddd657743516ec75d90ba581d8 100644 (file)
@@ -112,6 +112,9 @@ build_id_to_debug_bfd (size_t build_id_len, const bfd_byte *build_id)
        s += sprintf (s, "%02x", (unsigned) *data++);
       strcpy (s, ".debug");
 
+      if (separate_debug_file_debug)
+       printf_unfiltered (_("  Trying %s\n"), link);
+
       /* lrealpath() is expensive even for the usually non-existent files.  */
       if (access (link, F_OK) == 0)
        filename = lrealpath (link);
@@ -147,6 +150,10 @@ find_separate_debug_file_by_buildid (struct objfile *objfile)
   build_id = build_id_bfd_get (objfile->obfd);
   if (build_id != NULL)
     {
+      if (separate_debug_file_debug)
+       printf_unfiltered (_("\nLooking for separate debug info (build-id) for "
+                            "%s\n"), objfile_name (objfile));
+
       gdb_bfd_ref_ptr abfd (build_id_to_debug_bfd (build_id->size,
                                                   build_id->data));
       /* Prevent looping on a stripped .debug file.  */
index 868cde90dd8c305dce31a37c4b3b4f59d422e0ea..aa4a9ce2f061b5661433d6244ae78e909aba90fc 100644 (file)
@@ -1,3 +1,8 @@
+2017-06-11  Simon Marchi  <simon.marchi@ericsson.com>
+
+       * gdb.texinfo (Optional Messages about Internal Happenings):
+       Document {set,show} debug separate-debug-file commands.
+
 2017-06-07  Sergio Durigan Junior  <sergiodj@redhat.com>
 
        * gdb.texinfo (Starting) <startup-with-shell>: Add @anchor.
index 8d7a1c956c9a8cf1290ec13af80daf6e89a33319..c167a8654f242a5f035401548dcbd3bd076de772 100644 (file)
@@ -23984,6 +23984,12 @@ the serial line to the remote machine.  The info is printed on the
 @value{GDBN} standard output stream. The default is off.
 @item show debug remote
 Displays the state of display of remote packets.
+
+@item set debug separate-debug-file
+Turns on or off display of debug output about separate debug file search.
+@item show debug separate-debug-file
+Displays the state of separate debug file search debug output.
+
 @item set debug serial
 Turns on or off display of @value{GDBN} serial debugging info. The
 default is off.
index 846aabec481565eeb09ef395ca740d4a7dc7809a..f936cf3fa5efcacfa13e820fc05b9d3ca5340bdd 100644 (file)
@@ -1333,6 +1333,10 @@ symbol_file_clear (int from_tty)
     printf_unfiltered (_("No symbol file now.\n"));
 }
 
+/* See symfile.h.  */
+
+int separate_debug_file_debug = 0;
+
 static int
 separate_debug_file_exists (const char *name, unsigned long crc,
                            struct objfile *parent_objfile)
@@ -1351,6 +1355,9 @@ separate_debug_file_exists (const char *name, unsigned long crc,
   if (filename_cmp (name, objfile_name (parent_objfile)) == 0)
     return 0;
 
+  if (separate_debug_file_debug)
+    printf_unfiltered (_("  Trying %s\n"), name);
+
   gdb_bfd_ref_ptr abfd (gdb_bfd_open (name, gnutarget, -1));
 
   if (abfd == NULL)
@@ -1444,6 +1451,10 @@ find_separate_debug_file (const char *dir,
   struct cleanup *back_to;
   int ix;
 
+  if (separate_debug_file_debug)
+    printf_unfiltered (_("\nLooking for separate debug info (debug link) for "
+                        "%s\n"), objfile_name (objfile));
+
   /* Set I to std::max (strlen (canon_dir), strlen (dir)).  */
   i = strlen (dir);
   if (canon_dir != NULL && strlen (canon_dir) > i)
@@ -3975,4 +3986,11 @@ full  == print messages for the executable,\n\
                        NULL,
                        NULL,
                        &setprintlist, &showprintlist);
+
+  add_setshow_boolean_cmd ("separate-debug-file", no_class,
+                          &separate_debug_file_debug, _("\
+Set printing of separate debug info file search debug."), _("\
+Show printing of separate debug info file search debug."), _("\
+When on, GDB prints the searched locations while looking for separate debug \
+info files."), NULL, NULL, &setdebuglist, &showdebuglist);
 }
index ab536e8083d7835c449acfc2de69b4bb71031ef8..bb47fdf7cf848f0c3e9283715f7fab87b9183931 100644 (file)
@@ -646,4 +646,8 @@ extern void elfmdebug_build_psymtabs (struct objfile *,
 
 extern gdb_bfd_ref_ptr find_separate_debug_file_in_section (struct objfile *);
 
+/* True if we are printing debug output about separate debug info files.  */
+
+extern int separate_debug_file_debug;
+
 #endif /* !defined(SYMFILE_H) */
This page took 0.05316 seconds and 4 git commands to generate.