https://gcc.gnu.org/bugzilla/show_bug.cgi?id=86362

            Bug ID: 86362
           Summary: Members of enum class in .debug_gnu_pubnames without
                    scope, leading to gdbindex issues
           Product: gcc
           Version: unknown
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: debug
          Assignee: unassigned at gcc dot gnu.org
          Reporter: loic.yhuel at gmail dot com
  Target Milestone: ---

Enum class values are added to .debug_gnu_pubnames without scope, which leads
to conflicts in gdbindex when there are classes with the same name (for example
WebCore::Frame class and WebCore::ObjectContentType::Frame enum class value in
WebKit). Then gdb isn't able to get the correct type info for the class.

I think .debug_gnu_pubnames in bar.o should either :
 - don't have the enum class value (gdb seems to be able to get it looking at
the enum class debuginfo)
 - have it with the class scope

foo.cpp :
class Foo {
    Foo();
};
// make sure g++ will put class type in debug info
// .debug_gnu_pubtypes will contain "g,type Foo"
Foo::Foo()
{
}

bar.cpp :
enum class Bar {
    Foo
};
// .debug_gnu_pubnames will contain "g,variable Foo" !
Bar var = Bar::Foo;


g++ -gsplit-dwarf -c foo.cpp -o foo.o
g++ -gsplit-dwarf -c bar.cpp -o bar.o
g++ -fuse-ld=gold -shared -o lib.so -Wl,--gdb-index bar.o foo.o

=> "readelf --debug-dump=gdb_index lib.so" shows :
[661] Foo:
        0 [global, variable]
        1 [global, type]

In gdb, "ptype Foo" returns "No symbol "Foo" in current context." (due to
https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;a=blobdiff;f=gdb/dwarf2read.c;h=c5c3b5c225493d52cd96ddd52d57244e02485128;hp=7e87ed9adde38402d707ac2bd7c3757ba87847a6;hb=8943b874760d9cf35b71890a70af9866e4fab2a6;hpb=6adcee1866fe6b700bc1cc5a9675479530af7205,
gdb only loads the first CU).
If I put foo.o before bar.o, it works since the CU are swapped.

With -g instead of -gsplit-dwarf, and gdb_index still generated by gold
[661] Foo:
        0 [global, no info]
        1 [global, no info]
=> "ptype Foo" correctly prints "class Foo ...", since symbol attributes aren't
present so the gdb loads both CUs

With -g instead of -gsplit-dwarf, and gdb_index generated by gdb
[661] Foo:
        1 [global, type]
        0 [global, variable]
=> "ptype Foo" correctly prints "class Foo ...", since the CU 1 is first
I don't know if it's by chance or not.

With clang, it generates .debug_pubnames/.debug_pubtypes by default, then gold
produces an empty index, and gdb loads both CU on start.
But with -ggnu-pubnames, I get .debug_gnu_pubnames/.debug_gnu_pubtypes, and an
index with only the class for "Foo".

Reply via email to