From 459d52c84aa5eee986006b793794e382861c073d Mon Sep 17 00:00:00 2001 From: Doug Evans Date: Thu, 7 Nov 2013 14:58:41 -0800 Subject: [PATCH] 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. --- binutils/ChangeLog | 12 ++++++ binutils/dwarf.c | 104 +++++++++++++++++++++++++++++---------------- binutils/dwarf.h | 4 ++ binutils/readelf.c | 2 + 4 files changed, 86 insertions(+), 36 deletions(-) diff --git a/binutils/ChangeLog b/binutils/ChangeLog index 1ab6e0de10..237debe8aa 100644 --- a/binutils/ChangeLog +++ b/binutils/ChangeLog @@ -1,3 +1,15 @@ +2013-11-07 Doug Evans + + 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 * objdump.c (dump_dwarf): Grok bfd_mach_x86_64_nacl and diff --git a/binutils/dwarf.c b/binutils/dwarf.c index ae50a65fbd..c78f1243d2 100644 --- a/binutils/dwarf.c +++ b/binutils/dwarf.c @@ -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 }, diff --git a/binutils/dwarf.h b/binutils/dwarf.h index 68e93f1ccd..1cd4201649 100644 --- a/binutils/dwarf.h +++ b/binutils/dwarf.h @@ -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, diff --git a/binutils/readelf.c b/binutils/readelf.c index 0389f147c1..b9b06a1d5f 100644 --- a/binutils/readelf.c +++ b/binutils/readelf.c @@ -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")) -- 2.34.1