-
Notifications
You must be signed in to change notification settings - Fork 15.3k
Description
Problem
TL;DR Compiling the following code generates an object file whose DWARF doesn't contain the preferred name. This is true when compiling with -ggdb and with -glldb. Inspecting the DWARF shows that the variable is declared as Foo<Foo<int> >. The preferred name, i.e. BarInt (case sensitive), is no where to be found in the DWARF.
Code:
template <typename T> struct Foo;
typedef Foo<int> BarInt;
template <typename T>
struct [[clang::preferred_name(BarInt)]] Foo{};
int main() {
// BarInt barInt;
Foo<BarInt> fooBarInt;
return 0;
}
DWARF:
0x00000033: DW_TAG_variable
DW_AT_location (DW_OP_fbreg +11)
DW_AT_name ("fooBarInt")
DW_AT_decl_file ("/Users/royshi/demo/preferred_name/two.cpp")
DW_AT_decl_line (10)
DW_AT_type (0x00000043 "Foo<Foo<int> >")
So lldb cannot print the preferred name:
(lldb) p fooBarInt
(Foo<Foo<int> >) {}
Repro
Use the above source code (call it two.cpp), then:
~/public_llvm/build/bin/clang -O0 -glldb -c two.cpp # or -ggdb
dwarfdump two.o
# Note: For me, the above clang cannot link, so I used xcrun clang++. It shouldn't matter which one you use.
xcrun clang++ two.o
lldb a.out -o "b two.cpp:10" -o "r" -o "p fooBarInt"
See compilation, dwarfdump, and lldb output:
-ggdb: https://gist.github.com/royitaqi/cbf7a4d038f5b73dc60e5932bb2b593d-glldb: https://gist.github.com/royitaqi/46af47f0472976eb94b9725c073668df
I tested these on macOS. Haven't tested on Linux.
Note: If we uncomment that line // BarInt barInt;, the preferred name will be generated for barInt (type = BarInt), but not for fooBarInt (type = Foo<Foo<int > >; I'm expecting Foo<BarInt>, since the type BarInt now exists).
--
cc @Michael137 , @clayborg