<div dir="ltr">Hi all,<div><br></div><div>As you may know modern C++ debuggers (GDB and LLDB) support dynamic type identification for polymorphic objects, by utilizing C++ RTTI.  </div><div>Unfortunately this feature does not work with Clang and GDB >= 7.x .  The last compiler that worked well was G++ 6.x</div><div><br></div><div>I've asked about this issue both on GDB and LLDB maillists. Unfortunately it's hard or impossible to fix it on debugger side. </div><div>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.</div><div><br></div><div>Consider example:</div><div><div><br></div><div>////////////////////////////////////////////////////////////////</div><div><font face="monospace, monospace">enum class EN{ONE,TWO};</font></div><div><font face="monospace, monospace"><br></font></div><div><font face="monospace, monospace">template<auto x></font></div><div><font face="monospace, monospace">struct foo { virtual ~foo() {} };</font></div><div><font face="monospace, monospace"><br></font></div><div><font face="monospace, monospace">foo<11u> fu;</font></div><div><font face="monospace, monospace">foo<11> fi;</font></div><div><font face="monospace, monospace">foo<EN::ONE> fe;</font></div></div><div><div style="color:rgb(34,34,34);font-family:arial,sans-serif;font-size:small;font-style:normal;font-variant-ligatures:normal;font-variant-caps:normal;font-weight:400;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;background-color:rgb(255,255,255);text-decoration-style:initial;text-decoration-color:initial">////////////////////////////////////////////////////////////////</div><div><br></div>Clang will put following names to RTTI:</div><div><br></div><div><div><font face="monospace, monospace">3fooILi11EE         ->      foo<11></font></div><div><font face="monospace, monospace">3fooILj11EE         <span style="color:rgb(34,34,34);font-size:small;font-style:normal;font-variant-ligatures:normal;font-variant-caps:normal;font-weight:400;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;background-color:rgb(255,255,255);text-decoration-style:initial;text-decoration-color:initial;float:none;display:inline">-></span>      foo<11u></font></div><div><font face="monospace, monospace">3fooIL2EN0EE        <span style="color:rgb(34,34,34);font-size:small;font-style:normal;font-variant-ligatures:normal;font-variant-caps:normal;font-weight:400;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;background-color:rgb(255,255,255);text-decoration-style:initial;text-decoration-color:initial;float:none;display:inline">-></span>      foo<(EN)0></font></div><div><br></div><div>And to debuginfo it will emit 3 DW_TAG_structure_types with following DW_AT_names:</div><div><br></div><div><font face="monospace, monospace">DW_AT_name: foo<11><br></font></div><font face="monospace, monospace"><span style="color:rgb(34,34,34);font-size:small;font-style:normal;font-variant-ligatures:normal;font-variant-caps:normal;font-weight:400;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;background-color:rgb(255,255,255);text-decoration-style:initial;text-decoration-color:initial;float:none;display:inline">DW_AT_name: foo<11></span><br class="gmail-Apple-interchange-newline"><span style="color:rgb(34,34,34);font-size:small;font-style:normal;font-variant-ligatures:normal;font-variant-caps:normal;font-weight:400;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;background-color:rgb(255,255,255);text-decoration-style:initial;text-decoration-color:initial;float:none;display:inline">DW_AT_name: foo<EN::ONE></span><br style="color:rgb(34,34,34);font-size:small;font-style:normal;font-variant-ligatures:normal;font-variant-caps:normal;font-weight:400;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;background-color:rgb(255,255,255);text-decoration-style:initial;text-decoration-color:initial"></font><br>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.</div><div><br></div><div>I've asked about the problem on G++ maillist, and one of the proposed solutions is to emit DW_AT_linkage_name for types. </div><div><br></div><div>Can this solution be also implemented in LLVM? </div><div><br></div><div>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: <a href="https://llvm.org/docs/LangRef.html#dicompositetype">https://llvm.org/docs/LangRef.html#dicompositetype</a></div><div>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:</div><div><div><br></div><div>StringRef LinkageName = CTy->getIdentifier();</div><div>addString(Buffer, dwarf::DW_AT_linkage_name, LinkageName);</div></div><div><br></div><div></div><div><br></div><div><br></div><div>Thanks, </div><div>Roman</div><div> </div></div>