Add pretty-printing of .debug_gnu_pubnames, .debug_gnu_pubtypes.
authorDoug Evans <dje@google.com>
Thu, 7 Nov 2013 22:58:41 +0000 (14:58 -0800)
committerDoug Evans <dje@google.com>
Thu, 7 Nov 2013 23:37:44 +0000 (15:37 -0800)
* dwarf.c (get_gdb_index_symbol_kind_name): New function.
(display_debug_pubnames_worker): Renamed from display_debug_pubnames.
Add support for .debug_gnu_pubnames, .debug_gnu_pubtypes.
(display_debug_pubnames, display_debug_pubnames_gnu): New functions.
(display_gdb_index): Redo printing of symbol kind.
(debug_displays): Add .debug_gnu_pubnames, .debug_gnu_pubtypes.
* dwarf.h (dwarf_section_display_enum): Add gnu_pubnames, gnu_pubtypes.
* readelf.c (process_section_headers): Add gnu_pubnames, gnu_pubtypes.

binutils/ChangeLog
binutils/dwarf.c
binutils/dwarf.h
binutils/readelf.c

index 1ab6e0de10f17ee59f3f994420023b320ece018c..237debe8aaa4e370e58f32e9dbe3b7d57321eb29 100644 (file)
@@ -1,3 +1,15 @@
+2013-11-07  Doug Evans  <dje@google.com>
+
+       Add pretty-printing of .debug_gnu_pubnames, .debug_gnu_pubtypes.
+       * dwarf.c (get_gdb_index_symbol_kind_name): New function.
+       (display_debug_pubnames_worker): Renamed from display_debug_pubnames.
+       Add support for .debug_gnu_pubnames, .debug_gnu_pubtypes.
+       (display_debug_pubnames, display_debug_pubnames_gnu): New functions.
+       (display_gdb_index): Redo printing of symbol kind.
+       (debug_displays): Add .debug_gnu_pubnames, .debug_gnu_pubtypes.
+       * dwarf.h (dwarf_section_display_enum): Add gnu_pubnames, gnu_pubtypes.
+       * readelf.c (process_section_headers): Add gnu_pubnames, gnu_pubtypes.
+
 2013-11-07  Roland McGrath  <mcgrathr@google.com>
 
        * objdump.c (dump_dwarf): Grok bfd_mach_x86_64_nacl and
index ae50a65fbdf026d764d7ca350a74faddeb4dd633..c78f1243d248299ab45562b96a02ad5b28b828b1 100644 (file)
@@ -3507,9 +3507,29 @@ find_debug_info_for_offset (unsigned long offset)
   return NULL;
 }
 
+static const char *
+get_gdb_index_symbol_kind_name (gdb_index_symbol_kind kind)
+{
+  /* See gdb/gdb-index.h.  */
+  static const char * const kinds[] =
+  {
+    N_ ("no info"),
+    N_ ("type"),
+    N_ ("variable"),
+    N_ ("function"),
+    N_ ("other"),
+    N_ ("unused5"),
+    N_ ("unused6"),
+    N_ ("unused7")
+  };
+
+  return _ (kinds[kind]);
+}
+
 static int
-display_debug_pubnames (struct dwarf_section *section,
-                       void *file ATTRIBUTE_UNUSED)
+display_debug_pubnames_worker (struct dwarf_section *section,
+                              void *file ATTRIBUTE_UNUSED,
+                              int is_gnu)
 {
   DWARF2_Internal_PubNames names;
   unsigned char *start = section->start;
@@ -3577,7 +3597,10 @@ display_debug_pubnames (struct dwarf_section *section,
       printf (_("  Size of area in .debug_info section: %ld\n"),
              (long) names.pn_size);
 
-      printf (_("\n    Offset\tName\n"));
+      if (is_gnu)
+       printf (_("\n    Offset  Kind          Name\n"));
+      else
+       printf (_("\n    Offset\tName\n"));
 
       do
        {
@@ -3586,7 +3609,29 @@ display_debug_pubnames (struct dwarf_section *section,
          if (offset != 0)
            {
              data += offset_size;
-             printf ("    %-6lx\t%s\n", offset, data);
+             if (is_gnu)
+               {
+                 unsigned int kind_data;
+                 gdb_index_symbol_kind kind;
+                 const char *kind_name;
+                 int is_static;
+
+                 SAFE_BYTE_GET (kind_data, data, 1, end);
+                 data++;
+                 /* GCC computes the kind as the upper byte in the CU index
+                    word, and then right shifts it by the CU index size.
+                    Left shift KIND to where the gdb-index.h accessor macros
+                    can use it.  */
+                 kind_data <<= GDB_INDEX_CU_BITSIZE;
+                 kind = GDB_INDEX_SYMBOL_KIND_VALUE (kind_data);
+                 kind_name = get_gdb_index_symbol_kind_name (kind);
+                 is_static = GDB_INDEX_SYMBOL_STATIC_VALUE (kind_data);
+                 printf ("    %-6lx  %s,%-10s  %s\n",
+                         offset, is_static ? _("s") : _("g"),
+                         kind_name, data);
+               }
+             else
+               printf ("    %-6lx\t%s\n", offset, data);
              data += strnlen ((char *) data, end - data) + 1;
            }
        }
@@ -3597,6 +3642,18 @@ display_debug_pubnames (struct dwarf_section *section,
   return 1;
 }
 
+static int
+display_debug_pubnames (struct dwarf_section *section, void *file)
+{
+  return display_debug_pubnames_worker (section, file, 0);
+}
+
+static int
+display_debug_gnu_pubnames (struct dwarf_section *section, void *file)
+{
+  return display_debug_pubnames_worker (section, file, 1);
+}
+
 static int
 display_debug_macinfo (struct dwarf_section *section,
                       void *file ATTRIBUTE_UNUSED)
@@ -6141,38 +6198,9 @@ display_gdb_index (struct dwarf_section *section,
              else
                printf ("%c%lu", num_cus > 1 ? '\t' : ' ', (unsigned long) cu);
 
-             switch (kind)
-               {
-               case GDB_INDEX_SYMBOL_KIND_NONE:
-                 printf (_(" [no symbol information]"));
-                 break;
-               case GDB_INDEX_SYMBOL_KIND_TYPE:
-                 printf (is_static
-                         ? _(" [static type]")
-                         : _(" [global type]"));
-                 break;
-               case GDB_INDEX_SYMBOL_KIND_VARIABLE:
-                 printf (is_static
-                         ? _(" [static variable]")
-                         : _(" [global variable]"));
-                 break;
-               case GDB_INDEX_SYMBOL_KIND_FUNCTION:
-                 printf (is_static
-                         ? _(" [static function]")
-                         : _(" [global function]"));
-                 break;
-               case GDB_INDEX_SYMBOL_KIND_OTHER:
-                 printf (is_static
-                         ? _(" [static other]")
-                         : _(" [global other]"));
-                 break;
-               default:
-                 printf (is_static
-                         ? _(" [static unknown: %d]")
-                         : _(" [global unknown: %d]"),
-                         kind);
-                 break;
-               }
+             printf (" [%s, %s]",
+                     is_static ? _("static") : _("global"),
+                     get_gdb_index_symbol_kind_name (kind));
              if (num_cus > 1)
                printf ("\n");
            }
@@ -6796,6 +6824,8 @@ struct dwarf_section_display debug_displays[] =
     display_debug_lines,    &do_debug_lines,   1 },
   { { ".debug_pubnames",    ".zdebug_pubnames",        NULL, NULL, 0, 0, 0 },
     display_debug_pubnames, &do_debug_pubnames,        0 },
+  { { ".debug_gnu_pubnames", ".zdebug_gnu_pubnames", NULL, NULL, 0, 0, 0 },
+    display_debug_gnu_pubnames, &do_debug_pubnames, 0 },
   { { ".eh_frame",         "",                 NULL, NULL, 0, 0, 0 },
     display_debug_frames,   &do_debug_frames,  1 },
   { { ".debug_macinfo",            ".zdebug_macinfo",  NULL, NULL, 0, 0, 0 },
@@ -6808,6 +6838,8 @@ struct dwarf_section_display debug_displays[] =
     display_debug_loc,     &do_debug_loc,      1 },
   { { ".debug_pubtypes",    ".zdebug_pubtypes",        NULL, NULL, 0, 0, 0 },
     display_debug_pubnames, &do_debug_pubtypes,        0 },
+  { { ".debug_gnu_pubtypes", ".zdebug_gnu_pubtypes", NULL, NULL, 0, 0, 0 },
+    display_debug_gnu_pubnames, &do_debug_pubtypes, 0 },
   { { ".debug_ranges",     ".zdebug_ranges",   NULL, NULL, 0, 0, 0 },
     display_debug_ranges,   &do_debug_ranges,  1 },
   { { ".debug_static_func", ".zdebug_static_func", NULL, NULL, 0, 0, 0 },
index 68e93f1ccd6ae003cac4b6b192ee84a02b4da55e..1cd4201649856b81db0cf55f3a6fe7994d9d481c 100644 (file)
@@ -108,6 +108,8 @@ typedef struct
 }
 DWARF2_Internal_ARange;
 
+/* N.B. The order here must match the order in debug_displays.  */
+
 enum dwarf_section_display_enum
 {
   abbrev = 0,
@@ -116,12 +118,14 @@ enum dwarf_section_display_enum
   info,
   line,
   pubnames,
+  gnu_pubnames,
   eh_frame,
   macinfo,
   macro,
   str,
   loc,
   pubtypes,
+  gnu_pubtypes,
   ranges,
   static_func,
   static_vars,
index 0389f147c127b449db29a2a48bf718becd289a47..b9b06a1d5f42f0b990f3bc57da0f93571c2b25e5 100644 (file)
@@ -4919,6 +4919,8 @@ process_section_headers (FILE * file)
              || (do_debug_lines    && const_strneq (name, "line."))
              || (do_debug_pubnames && const_strneq (name, "pubnames"))
              || (do_debug_pubtypes && const_strneq (name, "pubtypes"))
+             || (do_debug_pubnames && const_strneq (name, "gnu_pubnames"))
+             || (do_debug_pubtypes && const_strneq (name, "gnu_pubtypes"))
              || (do_debug_aranges  && const_strneq (name, "aranges"))
              || (do_debug_ranges   && const_strneq (name, "ranges"))
              || (do_debug_frames   && const_strneq (name, "frame"))