[cfe-dev] Emiting linkage names for Types to Debuginfo (C++ RTTI support in GDB/LLDB)
Roman Popov via cfe-dev
cfe-dev at lists.llvm.org
Fri Mar 2 15:58:45 PST 2018
Hi all,
As you may know modern C++ debuggers (GDB and LLDB) support dynamic type
identification for polymorphic objects, by utilizing C++ RTTI.
Unfortunately this feature does not work with Clang and GDB >= 7.x . The
last compiler that worked well was G++ 6.x
I've asked about this issue both on GDB and LLDB maillists. Unfortunately
it's hard or impossible to fix it on debugger side.
The problem is that compilers do not emit linkage name of type to debug
information, and so debuggers can't link RTTI with DW_TAG_*_types reliably.
Consider example:
////////////////////////////////////////////////////////////////
enum class EN{ONE,TWO};
template<auto x>
struct foo { virtual ~foo() {} };
foo<11u> fu;
foo<11> fi;
foo<EN::ONE> fe;
////////////////////////////////////////////////////////////////
Clang will put following names to RTTI:
3fooILi11EE -> foo<11>
3fooILj11EE -> foo<11u>
3fooIL2EN0EE -> foo<(EN)0>
And to debuginfo it will emit 3 DW_TAG_structure_types with
following DW_AT_names:
DW_AT_name: foo<11>
DW_AT_name: foo<11>
DW_AT_name: foo<EN::ONE>
Currently what debugger has to do is to demangle RTTI name and try to match
it to DW_AT_name attribute to find type. As you can see it does not work
for any of 3 examples.
I've asked about the problem on G++ maillist, and one of the proposed
solutions is to emit DW_AT_linkage_name for types.
Can this solution be also implemented in LLVM?
I've checked LLVM docs and found out that LLVM generates DWARF from LLVM
metadata. LLVM metadata for types already contains linkage name in
"identifier" field: https://llvm.org/docs/LangRef.html#dicompositetype
So LLVM itself can identify types by name, the only remaining issue is to
emit it to debuginfo. That should be two lines of code in
: DwarfUnit::constructTypeDIE, something like:
StringRef LinkageName = CTy->getIdentifier();
addString(Buffer, dwarf::DW_AT_linkage_name, LinkageName);
Thanks,
Roman
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20180302/10e773f8/attachment.html>
More information about the cfe-dev
mailing list