Re: Make DW_TAG_enumerator's consistent, regardless of containing scope

Keith Seitz
2011-10-07T23:43:29Z

On 10/07/2011 02:26 PM, Sterling Augustine wrote:
> 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.

First things first: this is going to need a test case.

I've tried to reproduce this, but I cannot seem to replicate using your
instructions:

$ cat > enum0_main.cc << EOF
> namespace foo { }
> int main () { return 0; }
> EOF
$ cat > enum0.cc << EOF
> namespace foo {
> enum B { B_B };
> enum B b = B_B;
> };
> EOF
$ g++ -g enum0*.cc -o enum; popd
$ ./gdb -v
GNU gdb (GDB) 7.3.50.20111005-cvs
Copyright (C) 2011 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later
<http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law. Type "show copying"
and "show warranty" for details.
This GDB was configured as "x86_64-unknown-linux-gnu".
For bug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>...
Reading symbols from /home/keiths/tmp/enum...done.
(gdb) p foo::B_B
$1 = foo::B_B

Although this appears to work, your patch looks correct to me. If I
inspect the partial die names and the physnames, they do differ
(foo::B::B_B vs foo::B_B), and clearly foo::B::B_B is incorrect, since
enum B_B is of the unscoped variety.

I would also not expect to see any child dies for DW_TAG_enumerator, so
I agree that testing parent_die->tag == DW_TAG_enumerator doesn't make
sense.

IMO, I would recommend that a maintainer accept this patch (with a test
case).

Aside: If support is added for scoped enumerations, this will need
modifying -- the original behavior is correct in that case (but still
not for unscoped enums). dwarf2_compute_name will also need fixing. :-)]

Keith