This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
[PATCH] Avoid DW_AT_name: <anonymous struct> etc. (PR debug/41828)
- From: Jakub Jelinek <jakub at redhat dot com>
- To: Jason Merrill <jason at redhat dot com>
- Cc: gcc-patches at gcc dot gnu dot org, Roland McGrath <roland at redhat dot com>
- Date: Mon, 26 Oct 2009 17:03:58 +0100
- Subject: [PATCH] Avoid DW_AT_name: <anonymous struct> etc. (PR debug/41828)
- Reply-to: Jakub Jelinek <jakub at redhat dot com>
Hi!
The struct/union/enum names is not <anonymous {struct,union,enum}>,
so we just shouldn't emit any DW_AT_name at all instead of outputting
something artificial. Also, we shouldn't enter names like ._0 into
.debug_pubtypes.
Fixed thusly, bootstrapped/regtested on x86_64-linux and i686-linux.
2009-10-26 Jakub Jelinek <jakub@redhat.com>
PR debug/41828
* cp-lang.c (cxx_dwarf_name): Return NULL instead of
<anonymous ...> for anonymous aggregate names.
* dwarf2out.c (add_pubname, add_pubtype, generic_parameter_die,
add_name_and_src_coords_attributes, gen_namespace_die,
dwarf2out_set_name): Handle dwarf2_name returning NULL.
* g++.dg/debug/dwarf2/anonname1.C: New test.
--- gcc/cp/cp-lang.c.jj 2009-09-23 13:53:29.000000000 +0200
+++ gcc/cp/cp-lang.c 2009-10-26 10:08:38.000000000 +0100
@@ -137,6 +137,8 @@ cxx_dwarf_name (tree t, int verbosity)
{
gcc_assert (DECL_P (t));
+ if (DECL_NAME (t) && ANON_AGGRNAME_P (DECL_NAME (t)))
+ return NULL;
if (verbosity >= 2)
return decl_as_string (t,
TFF_DECL_SPECIFIERS | TFF_UNQUALIFIED_NAME
--- gcc/dwarf2out.c.jj 2009-10-19 16:34:21.000000000 +0200
+++ gcc/dwarf2out.c 2009-10-26 10:12:23.000000000 +0100
@@ -10781,7 +10781,11 @@ static void
add_pubname (tree decl, dw_die_ref die)
{
if (TREE_PUBLIC (decl))
- add_pubname_string (dwarf2_name (decl, 1), die);
+ {
+ const char *name = dwarf2_name (decl, 1);
+ if (name)
+ add_pubname_string (name, die);
+ }
}
/* Add a new entry to .debug_pubtypes if appropriate. */
@@ -10811,7 +10815,11 @@ add_pubtype (tree decl, dw_die_ref die)
}
}
else
- e.name = xstrdup (dwarf2_name (decl, 1));
+ {
+ e.name = dwarf2_name (decl, 1);
+ if (e.name)
+ e.name = xstrdup (e.name);
+ }
/* If we don't have a name for the type, there's no point in adding
it to the table. */
@@ -12359,7 +12367,8 @@ generic_parameter_die (tree parm, tree a
/* The DW_AT_GNU_template_name attribute of the DIE must be set
to the name of the argument. */
name = dwarf2_name (TYPE_P (arg) ? TYPE_NAME (arg) : arg, 1);
- add_AT_string (tmpl_die, DW_AT_GNU_template_name, name);
+ if (name)
+ add_AT_string (tmpl_die, DW_AT_GNU_template_name, name);
}
if (TREE_CODE (parm) == PARM_DECL)
@@ -16464,7 +16473,9 @@ add_name_and_src_coords_attributes (dw_d
decl_name = DECL_NAME (decl);
if (decl_name != NULL && IDENTIFIER_POINTER (decl_name) != NULL)
{
- add_name_attribute (die, dwarf2_name (decl, 0));
+ const char *name = dwarf2_name (decl, 0);
+ if (name)
+ add_name_attribute (die, name);
if (! DECL_ARTIFICIAL (decl))
add_src_coords_attributes (die, decl);
@@ -19222,7 +19233,11 @@ gen_namespace_die (tree decl, dw_die_ref
context_die, decl);
/* For Fortran modules defined in different CU don't add src coords. */
if (namespace_die->die_tag == DW_TAG_module && DECL_EXTERNAL (decl))
- add_name_attribute (namespace_die, dwarf2_name (decl, 0));
+ {
+ const char *name = dwarf2_name (decl, 0);
+ if (name)
+ add_name_attribute (namespace_die, name);
+ }
else
add_name_and_src_coords_attributes (namespace_die, decl);
if (DECL_EXTERNAL (decl))
@@ -19910,23 +19925,28 @@ dwarf2out_set_name (tree decl, tree name
{
dw_die_ref die;
dw_attr_ref attr;
+ const char *dname;
die = TYPE_SYMTAB_DIE (decl);
if (!die)
return;
+ dname = dwarf2_name (name, 0);
+ if (!dname)
+ return;
+
attr = get_AT (die, DW_AT_name);
if (attr)
{
struct indirect_string_node *node;
- node = find_AT_string (dwarf2_name (name, 0));
+ node = find_AT_string (dname);
/* replace the string. */
attr->dw_attr_val.v.val_str = node;
}
else
- add_name_attribute (die, dwarf2_name (name, 0));
+ add_name_attribute (die, dname);
}
/* Called by the final INSN scan whenever we see a direct function call.
--- gcc/testsuite/g++.dg/debug/dwarf2/anonname1.C.jj 2009-10-26 10:03:49.000000000 +0100
+++ gcc/testsuite/g++.dg/debug/dwarf2/anonname1.C 2009-10-26 10:19:33.000000000 +0100
@@ -0,0 +1,18 @@
+// PR debug/41828
+// { dg-do compile }
+// { dg-options "-gdwarf-2 -dA" }
+// { dg-final { scan-assembler-not "<anonymous" } }
+// { dg-final { scan-assembler-not "\._\[0-9\]" } }
+// { dg-final { scan-assembler-not "\$_\[0-9\]" } }
+// { dg-final { scan-assembler-not "__anon_" } }
+
+struct
+{
+ union
+ {
+ struct
+ {
+ enum { a, b, c } x;
+ } s;
+ };
+} x;
Jakub