Commit 03e992ac by Tom de Vries Committed by Tom de Vries

[debug] Add -gdescribe-dies

This patch adds option -gdescribe-dies.  It sets the DW_AT_description
attribute of dies that do not get a DW_AT_name 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_description: "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_description: "main"
 DW_AT_abstract_origin: die -> label: vla_1.c.6719312a + 29 (0x7fa88b965140)
...
and likewise to DW_TAG_call_site_parameter DIEs.

Bootstrapped and reg-tested on x86_64.

2018-09-12  Tom de Vries  <tdevries@suse.de>

	* common.opt (gdescribe-dies): Add option.
	* dwarf2out.c (add_name_and_src_coords_attributes): Add description
	attribute for artifical and nameless decls.
	(dwarf2out_register_external_die): Add description attribute to
	external reference die.
	(add_desc_attribute): New functions.
	(gen_subprogram_die): Add description attribute to
	DW_TAG_call_site_parameter.
	* tree-pretty-print.c (print_generic_expr_to_str): New function.
	* tree-pretty-print.h (print_generic_expr_to_str): Declare.
	* doc/invoke.texi (@item Debugging Options): Add -gdescribe-dies and
	-gno-describe-dies.
	(@item -gdescribe-dies): Add.

From-SVN: r264229
parent 28aa6323
2018-09-12 Tom de Vries <tdevries@suse.de>
* common.opt (gdescribe-dies): Add option.
* dwarf2out.c (add_name_and_src_coords_attributes): Add description
attribute for artifical and nameless decls.
(dwarf2out_register_external_die): Add description attribute to
external reference die.
(add_desc_attribute): New functions.
(gen_subprogram_die): Add description attribute to
DW_TAG_call_site_parameter.
* tree-pretty-print.c (print_generic_expr_to_str): New function.
* tree-pretty-print.h (print_generic_expr_to_str): Declare.
* doc/invoke.texi (@item Debugging Options): Add -gdescribe-dies and
-gno-describe-dies.
(@item -gdescribe-dies): Add.
2018-09-12 Aldy Hernandez <aldyh@redhat.com> 2018-09-12 Aldy Hernandez <aldyh@redhat.com>
* tree-vrp.c (vrp_shift_undefined_p): Remove. * tree-vrp.c (vrp_shift_undefined_p): Remove.
......
...@@ -2976,6 +2976,10 @@ gstrict-dwarf ...@@ -2976,6 +2976,10 @@ gstrict-dwarf
Common Driver Report Var(dwarf_strict) Init(0) Common Driver Report Var(dwarf_strict) Init(0)
Don't emit DWARF additions beyond selected version. Don't emit DWARF additions beyond selected version.
gdescribe-dies
Common Driver Report Var(flag_describe_dies) Init(0)
Add description attributes to some DWARF DIEs that have no name attribute.
gtoggle gtoggle
Common Driver Report Var(flag_gtoggle) Common Driver Report Var(flag_gtoggle)
Toggle debug information generation. Toggle debug information generation.
......
...@@ -373,7 +373,7 @@ Objective-C and Objective-C++ Dialects}. ...@@ -373,7 +373,7 @@ Objective-C and Objective-C++ Dialects}.
-ginternal-reset-location-views -gno-internal-reset-location-views @gol -ginternal-reset-location-views -gno-internal-reset-location-views @gol
-ginline-points -gno-inline-points @gol -ginline-points -gno-inline-points @gol
-gvms -gxcoff -gxcoff+ -gz@r{[}=@var{type}@r{]} @gol -gvms -gxcoff -gxcoff+ -gz@r{[}=@var{type}@r{]} @gol
-gsplit-dwarf @gol -gsplit-dwarf -gdescribe-dies -gno-describe-dies @gol
-fdebug-prefix-map=@var{old}=@var{new} -fdebug-types-section @gol -fdebug-prefix-map=@var{old}=@var{new} -fdebug-types-section @gol
-fno-eliminate-unused-debug-types @gol -fno-eliminate-unused-debug-types @gol
-femit-struct-debug-baseonly -femit-struct-debug-reduced @gol -femit-struct-debug-baseonly -femit-struct-debug-reduced @gol
...@@ -7466,6 +7466,12 @@ the build system to avoid linking files with debug information. To ...@@ -7466,6 +7466,12 @@ the build system to avoid linking files with debug information. To
be useful, this option requires a debugger capable of reading @file{.dwo} be useful, this option requires a debugger capable of reading @file{.dwo}
files. files.
@item -gdescribe-dies
@opindex gdescribe-dies
Add description attributes to some DWARF DIEs that have no name attribute,
such as artificial variables, external references and call site
parameter DIEs.
@item -gpubnames @item -gpubnames
@opindex gpubnames @opindex gpubnames
Generate DWARF @code{.debug_pubnames} and @code{.debug_pubtypes} sections. Generate DWARF @code{.debug_pubnames} and @code{.debug_pubtypes} sections.
...@@ -3816,6 +3816,7 @@ static bool add_location_or_const_value_attribute (dw_die_ref, tree, bool); ...@@ -3816,6 +3816,7 @@ static bool add_location_or_const_value_attribute (dw_die_ref, tree, bool);
static bool tree_add_const_value_attribute (dw_die_ref, tree); static bool tree_add_const_value_attribute (dw_die_ref, tree);
static bool tree_add_const_value_attribute_for_decl (dw_die_ref, tree); static bool tree_add_const_value_attribute_for_decl (dw_die_ref, tree);
static void add_name_attribute (dw_die_ref, const char *); static void add_name_attribute (dw_die_ref, const char *);
static void add_desc_attribute (dw_die_ref, tree);
static void add_gnat_descriptive_type_attribute (dw_die_ref, tree, dw_die_ref); static void add_gnat_descriptive_type_attribute (dw_die_ref, tree, dw_die_ref);
static void add_comp_dir_attribute (dw_die_ref); static void add_comp_dir_attribute (dw_die_ref);
static void add_scalar_info (dw_die_ref, enum dwarf_attribute, tree, int, static void add_scalar_info (dw_die_ref, enum dwarf_attribute, tree, int,
...@@ -6030,6 +6031,8 @@ dwarf2out_register_external_die (tree decl, const char *sym, ...@@ -6030,6 +6031,8 @@ dwarf2out_register_external_die (tree decl, const char *sym,
else else
equate_decl_number_to_die (decl, die); equate_decl_number_to_die (decl, die);
add_desc_attribute (die, decl);
/* Add a reference to the DIE providing early debug at $sym + off. */ /* Add a reference to the DIE providing early debug at $sym + off. */
add_AT_external_die_ref (die, DW_AT_abstract_origin, sym, off); add_AT_external_die_ref (die, DW_AT_abstract_origin, sym, off);
} }
...@@ -20536,6 +20539,52 @@ add_name_attribute (dw_die_ref die, const char *name_string) ...@@ -20536,6 +20539,52 @@ add_name_attribute (dw_die_ref die, const char *name_string)
} }
} }
/* Generate a DW_AT_description attribute given some string value to be included
as the value of the attribute. */
static void
add_desc_attribute (dw_die_ref die, const char *name_string)
{
if (!flag_describe_dies || (dwarf_version < 3 && dwarf_strict))
return;
if (name_string == NULL || *name_string == 0)
return;
if (demangle_name_func)
name_string = (*demangle_name_func) (name_string);
add_AT_string (die, DW_AT_description, name_string);
}
/* Generate a DW_AT_description attribute given some decl to be included
as the value of the attribute. */
static void
add_desc_attribute (dw_die_ref die, tree decl)
{
tree decl_name;
if (!flag_describe_dies || (dwarf_version < 3 && dwarf_strict))
return;
if (decl == NULL_TREE || !DECL_P (decl))
return;
decl_name = DECL_NAME (decl);
if (decl_name != NULL && IDENTIFIER_POINTER (decl_name) != NULL)
{
const char *name = dwarf2_name (decl, 0);
add_desc_attribute (die, name ? name : IDENTIFIER_POINTER (decl_name));
}
else
{
char *desc = print_generic_expr_to_str (decl);
add_desc_attribute (die, desc);
free (desc);
}
}
/* Retrieve the descriptive type of TYPE, if any, make sure it has a /* Retrieve the descriptive type of TYPE, if any, make sure it has a
DIE and attach a DW_AT_GNAT_descriptive_type attribute to the DIE DIE and attach a DW_AT_GNAT_descriptive_type attribute to the DIE
of TYPE accordingly. of TYPE accordingly.
...@@ -21294,12 +21343,17 @@ add_name_and_src_coords_attributes (dw_die_ref die, tree decl, ...@@ -21294,12 +21343,17 @@ add_name_and_src_coords_attributes (dw_die_ref die, tree decl,
const char *name = dwarf2_name (decl, 0); const char *name = dwarf2_name (decl, 0);
if (name) if (name)
add_name_attribute (die, name); add_name_attribute (die, name);
else
add_desc_attribute (die, decl);
if (! DECL_ARTIFICIAL (decl)) if (! DECL_ARTIFICIAL (decl))
add_src_coords_attributes (die, decl); add_src_coords_attributes (die, decl);
if (!no_linkage_name) if (!no_linkage_name)
add_linkage_name (die, decl); add_linkage_name (die, decl);
} }
else
add_desc_attribute (die, decl);
#ifdef VMS_DEBUGGING_INFO #ifdef VMS_DEBUGGING_INFO
/* Get the function's name, as described by its RTL. This may be different /* Get the function's name, as described by its RTL. This may be different
...@@ -23272,6 +23326,7 @@ gen_subprogram_die (tree decl, dw_die_ref context_die) ...@@ -23272,6 +23326,7 @@ gen_subprogram_die (tree decl, dw_die_ref context_die)
dw_die_ref die = NULL; dw_die_ref die = NULL;
rtx tloc = NULL_RTX, tlocc = NULL_RTX; rtx tloc = NULL_RTX, tlocc = NULL_RTX;
rtx arg, next_arg; rtx arg, next_arg;
tree arg_decl = NULL_TREE;
for (arg = (ca_loc->call_arg_loc_note != NULL_RTX for (arg = (ca_loc->call_arg_loc_note != NULL_RTX
? XEXP (ca_loc->call_arg_loc_note, 0) ? XEXP (ca_loc->call_arg_loc_note, 0)
...@@ -23336,6 +23391,7 @@ gen_subprogram_die (tree decl, dw_die_ref context_die) ...@@ -23336,6 +23391,7 @@ gen_subprogram_die (tree decl, dw_die_ref context_die)
tdie = lookup_decl_die (tdecl); tdie = lookup_decl_die (tdecl);
if (tdie == NULL) if (tdie == NULL)
continue; continue;
arg_decl = tdecl;
} }
else else
continue; continue;
...@@ -23352,6 +23408,7 @@ gen_subprogram_die (tree decl, dw_die_ref context_die) ...@@ -23352,6 +23408,7 @@ gen_subprogram_die (tree decl, dw_die_ref context_die)
die = gen_call_site_die (decl, subr_die, ca_loc); die = gen_call_site_die (decl, subr_die, ca_loc);
cdie = new_die (dwarf_TAG (DW_TAG_call_site_parameter), die, cdie = new_die (dwarf_TAG (DW_TAG_call_site_parameter), die,
NULL_TREE); NULL_TREE);
add_desc_attribute (cdie, arg_decl);
if (reg != NULL) if (reg != NULL)
add_AT_loc (cdie, DW_AT_location, reg); add_AT_loc (cdie, DW_AT_location, reg);
else if (tdie != NULL) else if (tdie != NULL)
......
...@@ -162,6 +162,16 @@ print_generic_expr (FILE *file, tree t, dump_flags_t flags) ...@@ -162,6 +162,16 @@ print_generic_expr (FILE *file, tree t, dump_flags_t flags)
pp_flush (tree_pp); pp_flush (tree_pp);
} }
/* Print a single expression T to string, and return it. */
char *
print_generic_expr_to_str (tree t)
{
pretty_printer pp;
dump_generic_node (&pp, t, 0, TDF_VOPS|TDF_MEMSYMS, false);
return xstrdup (pp_formatted_text (&pp));
}
/* Dump NAME, an IDENTIFIER_POINTER, sanitized so that D<num> sequences /* Dump NAME, an IDENTIFIER_POINTER, sanitized so that D<num> sequences
in it are replaced with Dxxxx, as long as they are at the start or in it are replaced with Dxxxx, as long as they are at the start or
preceded by $ and at the end or followed by $. See make_fancy_name preceded by $ and at the end or followed by $. See make_fancy_name
......
...@@ -38,6 +38,7 @@ extern void print_generic_decl (FILE *, tree, dump_flags_t); ...@@ -38,6 +38,7 @@ extern void print_generic_decl (FILE *, tree, dump_flags_t);
extern void print_generic_stmt (FILE *, tree, dump_flags_t = TDF_NONE); extern void print_generic_stmt (FILE *, tree, dump_flags_t = TDF_NONE);
extern void print_generic_stmt_indented (FILE *, tree, dump_flags_t, int); extern void print_generic_stmt_indented (FILE *, tree, dump_flags_t, int);
extern void print_generic_expr (FILE *, tree, dump_flags_t = TDF_NONE); extern void print_generic_expr (FILE *, tree, dump_flags_t = TDF_NONE);
extern char *print_generic_expr_to_str (tree);
extern void dump_omp_clauses (pretty_printer *, tree, int, dump_flags_t); extern void dump_omp_clauses (pretty_printer *, tree, int, dump_flags_t);
extern int dump_generic_node (pretty_printer *, tree, int, dump_flags_t, bool); extern int dump_generic_node (pretty_printer *, tree, int, dump_flags_t, bool);
extern void print_declaration (pretty_printer *, tree, int, dump_flags_t); extern void print_declaration (pretty_printer *, tree, int, dump_flags_t);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment