================ @@ -250,11 +250,52 @@ static unsigned GetCXXMethodCVQuals(const DWARFDIE &subprogram, return cv_quals; } +static const char *GetMangledOrStructorName(const DWARFDIE &die) { + const char *name = die.GetMangledName(/*substitute_name_allowed*/ false); + if (name) + return name; + + name = die.GetName(); + if (!name) + return nullptr; + + DWARFDIE parent = die.GetParent(); + if (!parent.IsStructUnionOrClass()) + return nullptr; + + const char *parent_name = parent.GetName(); + if (!parent_name) + return nullptr; + + // Constructor. + if (::strcmp(parent_name, name) == 0) + return name; + + // Destructor. + if (name[0] == '~' && ::strcmp(parent_name, name + 1) == 0) + return name; + + return nullptr; +} + static std::string MakeLLDBFuncAsmLabel(const DWARFDIE &die) { - char const *name = die.GetMangledName(/*substitute_name_allowed*/ false); + char const *name = GetMangledOrStructorName(die); if (!name) return {}; + auto *cu = die.GetCU(); + if (!cu) + return {}; + + // FIXME: When resolving function call labels, we check that + // that the definition's DW_AT_specification points to the + // declaration that we encoded into the label here. But if the + // declaration came from a type-unit (and the definition from + // .debug_info), that check won't work. So for now, don't use + // function call labels for declaration DIEs from type-units. + if (cu->IsTypeUnit()) + return {}; ---------------- labath wrote:
I don't understand how this is related to type units. Even without them, I don't see how we can guarantee we always wind up at the same declaration DIE. A definition of the type (along with declarations of its methods) can be present in ~every CU, but the definition of a specific method will (normally) only be present in a single CU (however, it doesn't always have to be the same CU as c++ allows you to spread the definition of a class across multiple CUs). That definition DIE will point to *a* declaration, but that doesn't have to be the same declaration that we started with. If anything, type units should make finding the canonical declaration easier because the linker will deduplicate all of the type definitions (similar to how dsymutil would do it), but even that's not guaranteed because not all CUs have to have type units enabled. Why do we need to go back the the original DIE? I don't quite understand how, but I think lldb deals with this problem (multiple definitions of a using the `DWARFASTParserClang::CopyUniqueClassMethodTypes` function. Is it possible this patch breaks that somehow? https://github.com/llvm/llvm-project/pull/149827 _______________________________________________ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits