Make DW_TAG_enumerator's consistent, regardless of containing scope

Sterling Augustine
2011-10-07T21:27:14Z

[-- Attachment #1: Type: text/plain, Size: 1426 bytes --]

This patch fixes the issue described in
http://sourceware.org/ml/gdb/2011-09/msg00119.html. To recap, consider
the testcase below. Dividing the namespace definition into two
compilation units and their order on the command-line is essential to
see the problem.

enum0_main.cc:

namespace foo { }

int main() { return 0; }

enum0.cc:

namespace foo {
enum B { B_B };

enum B b = B_B;
};

saugustine@sterling$ g++ -g enum0_main.cc enum0.cc -o enum-namespace
saugustine@sterling$ gdb ./enum-namespace
GNU gdb (GDB) 7.3.50.20111007-cvs
...
(gdb) p foo::B_B
No symbol "B_B" in namespace "foo".
(gdb) p foo::B::B_B
`foo::B' is not defined as an aggregate type.

GDB puts this definition into the partial symbol table as foo::B::B_B,
but it should be foo::B_B.

After partial symbols have been converted to full symbols, the
enum-type is not be included as part of the enumerator's scope.

The enclosed patch fixes the situation dropping the enum-type name for
all enumerators. The original code was commented that it should do
that, but didn't work because it was looking at the enumerator die's
parent die, rather than the enumerator die itself.

The file split in the test case is required to avoid reading all of
namespace foo's symbols in the intermediate symbol lookup.

OK to commit?

Sterling

2011-10-07 Sterling Augustine <saugustine@google.com>

* dwarf2read.c (partial_die_parent_scope): Rearrange conditional logic.

[-- Attachment #2: enumerator-patch --]
[-- Type: application/octet-stream, Size: 1030 bytes --]

Index: dwarf2read.c
===================================================================
RCS file: /cvs/src/src/gdb/dwarf2read.c,v
retrieving revision 1.561
diff -d -u -r1.561 dwarf2read.c
--- dwarf2read.c 13 Sep 2011 21:44:27 -0000 1.561
+++ dwarf2read.c 7 Oct 2011 17:51:52 -0000
@@ -3878,7 +3878,10 @@
return NULL;
}

- if (parent->tag == DW_TAG_namespace
+ if (pdi->tag == DW_TAG_enumerator)
+ /* Enumerators should not get the name of the enumeration as a prefix. */
+ parent->scope = grandparent_scope;
+ else if (parent->tag == DW_TAG_namespace
|| parent->tag == DW_TAG_module
|| parent->tag == DW_TAG_structure_type
|| parent->tag == DW_TAG_class_type
@@ -3893,9 +3896,6 @@
grandparent_scope,
parent->name, 0, cu);
}
- else if (parent->tag == DW_TAG_enumerator)
- /* Enumerators should not get the name of the enumeration as a prefix. */
- parent->scope = grandparent_scope;
else
{
/* FIXME drow/2004-04-01: What should we be doing with