Print .debug_names augmentation as a string

Message ID 20190711170026.23409-1-tromey@adacore.com
State New
Headers show
Series
  • Print .debug_names augmentation as a string
Related show

Commit Message

Tom Tromey July 11, 2019, 5 p.m.
The DWARF 5 .debug_names section includes an "augmentation string"
that can be used to identify the producer.  While this string is just
arbitrary data, in practice the two producers I know of (gdb and
clang) use an ASCII string here.

This patch changes display_debug_names to display the augmentation as
a string when possible.  This makes it a bit simpler to see what
producer created the section.

With the patch the output for a gdb-created section now looks like
this:

    Augmentation string: 47 44 42 00  ("GDB")

Tested on x86-64 Fedora 29.  Ok?

binutils/ChangeLog
2019-07-11  Tom Tromey  <tromey@adacore.com>

	* dwarf.c (display_debug_names): Print augmentation string as
	string when possible.
---
 binutils/ChangeLog |  5 +++++
 binutils/dwarf.c   | 17 +++++++++++++++++
 2 files changed, 22 insertions(+)

-- 
2.20.1

Patch

diff --git a/binutils/dwarf.c b/binutils/dwarf.c
index f86e20db40f..fcfb9550a70 100644
--- a/binutils/dwarf.c
+++ b/binutils/dwarf.c
@@ -30,6 +30,7 @@ 
 #include "gdb/gdb-index.h"
 #include "filenames.h"
 #include <assert.h>
+#include "safe-ctype.h"
 
 #undef MAX
 #undef MIN
@@ -8544,6 +8545,8 @@  display_debug_names (struct dwarf_section *section, void *file)
       uint32_t augmentation_string_size;
       unsigned int i;
       unsigned long sec_off;
+      int augmentation_printable;
+      const char *augmentation_string;
 
       unit_start = hdrptr;
 
@@ -8608,12 +8611,26 @@  display_debug_names (struct dwarf_section *section, void *file)
 	  augmentation_string_size += (-augmentation_string_size) & 3;
 	}
       printf (_("Augmentation string:"));
+      augmentation_printable = 1;
+      augmentation_string = (const char *) hdrptr;
       for (i = 0; i < augmentation_string_size; i++)
 	{
 	  unsigned char uc;
 
 	  SAFE_BYTE_GET_AND_INC (uc, hdrptr, 1, unit_end);
 	  printf (" %02x", uc);
+
+	  if (uc != 0 && !ISPRINT (uc))
+	    augmentation_printable = 0;
+	}
+      if (augmentation_printable)
+	{
+	  printf ("  (\"");
+	  for (i = 0;
+	       i < augmentation_string_size && augmentation_string[i];
+	       ++i)
+	    putchar (augmentation_string[i]);
+	  printf ("\")");
 	}
       putchar ('\n');
       putchar ('\n');