public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [RFC][debug] Add -greadable-dwarf
@ 2018-08-15 14:02 Tom de Vries
  2018-08-20 12:59 ` Richard Biener
  0 siblings, 1 reply; 15+ messages in thread
From: Tom de Vries @ 2018-08-15 14:02 UTC (permalink / raw)
  To: gcc-patches; +Cc: Richard Biener, Jakub Jelinek, Jason Merrill, Cary Coutant

Hi,

This patch adds option -greadable-dwarf.  In absence of an DW_AT_comment
attribute, it sets the DW_AT_name attribute of dies that otherwise do not get
that attribute, to make it easier to figure out what the die is describing.

The option exports the names of artificial variables:
...
 DIE    0: DW_TAG_variable (0x7fa934dd54b0)
+  DW_AT_name: "D.1922"
   DW_AT_type: die -> 0 (0x7fa934dd0d70)
   DW_AT_artificial: 1

...
which can be traced back to gimple dumps:
...
  char a[0:D.1922] [value-expr: *a.0];
...

Furthermore, it adds names to external references:
...
 DIE    0: DW_TAG_subprogram (0x7fa88b9650f0)
+DW_AT_name: "main"
 DW_AT_abstract_origin: die -> label: vla_1.c.6719312a + 29 (0x7fa88b965140)
...

This is an undocumented developer-only option, because using this option may
change behaviour of dwarf consumers, f.i., gdb shows the artificial variables:
...
(gdb) info locals
a = 0x7fffffffda90 "\005"
D.4278 = <optimized out>
...

Any comments?

Thanks,
- Tom

[debug] Add -greadable-dwarf

2018-08-15  Tom de Vries  <tdevries@suse.de>

	* common.opt (greadable-dwarf): Add option.
	* dwarf2out.c (add_name_and_src_coords_attributes): Add param. Add name
	for artifical decls.
	(add_decl_name): New function.
	(dwarf2out_register_external_die): Add name to external reference die.

---
 gcc/common.opt  |  5 +++++
 gcc/dwarf2out.c | 24 +++++++++++++++++++++---
 2 files changed, 26 insertions(+), 3 deletions(-)

diff --git a/gcc/common.opt b/gcc/common.opt
index b2f2215ecc6..6e5e0558e49 100644
--- a/gcc/common.opt
+++ b/gcc/common.opt
@@ -2972,6 +2972,11 @@ gstrict-dwarf
 Common Driver Report Var(dwarf_strict) Init(0)
 Don't emit DWARF additions beyond selected version.
 
+greadable-dwarf
+Common Driver Undocumented Report Var(flag_readable_dwarf) Init(0)
+Make generated dwarf more readable, at the cost of space and exposing compiler
+internals.
+
 gtoggle
 Common Driver Report Var(flag_gtoggle)
 Toggle debug information generation.
diff --git a/gcc/dwarf2out.c b/gcc/dwarf2out.c
index 4b63cbd8a1e..8c6b4372874 100644
--- a/gcc/dwarf2out.c
+++ b/gcc/dwarf2out.c
@@ -3824,7 +3824,9 @@ static void add_prototyped_attribute (dw_die_ref, tree);
 static dw_die_ref add_abstract_origin_attribute (dw_die_ref, tree);
 static void add_pure_or_virtual_attribute (dw_die_ref, tree);
 static void add_src_coords_attributes (dw_die_ref, tree);
-static void add_name_and_src_coords_attributes (dw_die_ref, tree, bool = false);
+static void add_name_and_src_coords_attributes (dw_die_ref, tree, bool = false,
+						bool = false);
+static void add_decl_name (dw_die_ref, tree);
 static void add_discr_value (dw_die_ref, dw_discr_value *);
 static void add_discr_list (dw_die_ref, dw_discr_list_ref);
 static inline dw_discr_list_ref AT_discr_list (dw_attr_node *);
@@ -6022,6 +6024,8 @@ dwarf2out_register_external_die (tree decl, const char *sym,
   else
     equate_decl_number_to_die (decl, die);
 
+  if (flag_readable_dwarf)
+    add_decl_name (die, decl);
   /* Add a reference to the DIE providing early debug at $sym + off.  */
   add_AT_external_die_ref (die, DW_AT_abstract_origin, sym, off);
 }
@@ -21269,7 +21273,8 @@ add_linkage_name (dw_die_ref die, tree decl)
 
 static void
 add_name_and_src_coords_attributes (dw_die_ref die, tree decl,
-				    bool no_linkage_name)
+				    bool no_linkage_name,
+				    bool no_src_coords_attributes)
 {
   tree decl_name;
 
@@ -21279,12 +21284,19 @@ add_name_and_src_coords_attributes (dw_die_ref die, tree decl,
       const char *name = dwarf2_name (decl, 0);
       if (name)
 	add_name_attribute (die, name);
-      if (! DECL_ARTIFICIAL (decl))
+      if (!no_src_coords_attributes && ! DECL_ARTIFICIAL (decl))
 	add_src_coords_attributes (die, decl);
 
       if (!no_linkage_name)
 	add_linkage_name (die, decl);
     }
+  else if (flag_readable_dwarf && decl_name == NULL)
+    {
+      char *buf = XNEWVEC (char, 32);
+      char decl_letter = TREE_CODE (decl) == CONST_DECL ? 'C' : 'D';
+      sprintf (buf, "%c.%u", decl_letter, DECL_UID (decl));
+      add_name_attribute (die, buf);
+    }
 
 #ifdef VMS_DEBUGGING_INFO
   /* Get the function's name, as described by its RTL.  This may be different
@@ -21298,6 +21310,12 @@ add_name_and_src_coords_attributes (dw_die_ref die, tree decl,
 #endif /* VMS_DEBUGGING_INFO */
 }
 
+static void
+add_decl_name (dw_die_ref die, tree decl)
+{
+  add_name_and_src_coords_attributes (die, decl, true, true);
+}
+
 /* Add VALUE as a DW_AT_discr_value attribute to DIE.  */
 
 static void

^ permalink raw reply	[flat|nested] 15+ messages in thread

end of thread, other threads:[~2018-09-11 16:16 UTC | newest]

Thread overview: 15+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-08-15 14:02 [RFC][debug] Add -greadable-dwarf Tom de Vries
2018-08-20 12:59 ` Richard Biener
2018-08-21  7:01   ` Jason Merrill
2018-08-21  7:16     ` Richard Biener
2018-08-21 12:40     ` Tom de Vries
2018-08-21 12:22   ` Tom de Vries
2018-08-22  6:56     ` [PATCH][debug] Add -gforce-named-dies Tom de Vries
2018-08-22  9:46       ` Tom de Vries
2018-08-22 13:23         ` [PATCH][debug] Add -gdescriptive-dies Tom de Vries
2018-08-24 10:44           ` Richard Biener
2018-08-24 15:38             ` [PATCH][debug] Add -gdescribe-dies Tom de Vries
2018-08-31 21:19               ` Jason Merrill
2018-09-01 18:10                 ` Tom de Vries
2018-09-11 15:32                   ` [PING][PATCH][debug] " Tom de Vries
2018-09-11 16:16                   ` [PATCH][debug] " Jason Merrill

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).