This is the mail archive of the binutils@sourceware.org mailing list for the binutils 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: [RFA] Add support for pretty-printing .debug_gnu_pubnames, pubtypes


Tom Tromey writes:
 > >>>>> "Doug" == Doug Evans <dje@google.com> writes:
 > 
 > Doug> +static const char *
 > Doug> +get_gdb_index_symbol_kind_name (gdb_index_symbol_kind kind)
 > Doug> +{
 > Doug> +  /* See gdb/gdb-index.h.  */
 > Doug> +  static const char * const kinds[] =
 > Doug> +  {
 > Doug> +    N_ ("no info"),
 > Doug> +    N_ ("type"),
 > Doug> +    N_ ("variable"),
 > Doug> +    N_ ("function"),
 > Doug> +    N_ ("other"),
 > Doug> +    N_ ("unused5"),
 > Doug> +    N_ ("unused6"),
 > Doug> +    N_ ("unused7")
 > Doug> +  };
 > Doug> +
 > Doug> +  return kinds[kind];
 > 
 > These are marked with N_ and returned verbatim, but...
 > 
 > Doug> +		  kind_name = get_gdb_index_symbol_kind_name (kind);
 > Doug> +		  is_static = GDB_INDEX_SYMBOL_STATIC_VALUE (kind_data);
 > Doug> +		  printf ("    %-6lx  %s,%-10s  %s\n",
 > Doug> +			  offset, is_static ? "s" : "g", kind_name, data);
 > 
 > ... printed without passing them through gettext.
 > 
 > Either they should not be marked, or you need an explicit call to
 > gettext somewhere.

I had a feeling I was missing something ...

How about this?

2013-10-21  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.

Index: dwarf.c
===================================================================
RCS file: /cvs/src/src/binutils/dwarf.c,v
retrieving revision 1.142
diff -u -p -r1.142 dwarf.c
--- dwarf.c	9 Oct 2013 16:37:44 -0000	1.142
+++ dwarf.c	21 Oct 2013 19:05:41 -0000
@@ -3507,9 +3507,29 @@ find_debug_info_for_offset (unsigned lon
   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_sec
       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_sec
 	  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;
 	    }
 	}
@@ -3598,6 +3643,18 @@ display_debug_pubnames (struct dwarf_sec
 }
 
 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 
 	      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_displ
     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_displ
     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: dwarf.h
===================================================================
RCS file: /cvs/src/src/binutils/dwarf.h,v
retrieving revision 1.28
diff -u -p -r1.28 dwarf.h
--- dwarf.h	25 Mar 2013 13:16:41 -0000	1.28
+++ dwarf.h	21 Oct 2013 19:05:41 -0000
@@ -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: readelf.c
===================================================================
RCS file: /cvs/src/src/binutils/readelf.c,v
retrieving revision 1.612
diff -u -p -r1.612 readelf.c
--- readelf.c	14 Oct 2013 18:45:46 -0000	1.612
+++ readelf.c	21 Oct 2013 19:05:41 -0000
@@ -4909,6 +4909,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"))


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