diff --git a/llvm/lib/DebugInfo/DWARF/DWARFVerifier.cpp b/llvm/lib/DebugInfo/DWARF/DWARFVerifier.cpp --- a/llvm/lib/DebugInfo/DWARF/DWARFVerifier.cpp +++ b/llvm/lib/DebugInfo/DWARF/DWARFVerifier.cpp @@ -1351,16 +1351,32 @@ return NumErrors; } -static SmallVector getNames(const DWARFDie &DIE, - bool IncludeStrippedTemplateNames, - bool IncludeLinkageName = true) { - SmallVector Result; +static SmallVector getNames(const DWARFDie &DIE, + bool IncludeStrippedTemplateNames, + bool IncludeObjCNames = true, + bool IncludeLinkageName = true) { + SmallVector Result; if (const char *Str = DIE.getShortName()) { - Result.emplace_back(Str); + StringRef Name(Str); + Result.emplace_back(Name); if (IncludeStrippedTemplateNames) { if (std::optional StrippedName = StripTemplateParameters(Result.back())) - Result.push_back(*StrippedName); + // Convert to std::string and push; emplacing the StringRef may trigger + // a vector resize which may destroy the StringRef memory. + Result.push_back(StrippedName->str()); + } + + if (IncludeObjCNames) { + if (std::optional ObjCNames = + getObjCNamesIfSelector(Name)) { + Result.emplace_back(ObjCNames->ClassName); + Result.emplace_back(ObjCNames->Selector); + if (ObjCNames->ClassNameNoCategory) + Result.emplace_back(*ObjCNames->ClassNameNoCategory); + if (ObjCNames->MethodNameNoCategory) + Result.push_back(std::move(*ObjCNames->MethodNameNoCategory)); + } } } else if (DIE.getTag() == dwarf::DW_TAG_namespace) Result.emplace_back("(anonymous namespace)"); @@ -1507,11 +1523,12 @@ // the linkage name." auto IncludeLinkageName = Die.getTag() == DW_TAG_subprogram || Die.getTag() == DW_TAG_inlined_subroutine; - // We *allow* stripped template names as an extra entry into the template, - // but we don't *require* them to pass the completeness test. + // We *allow* stripped template names / ObjectiveC names as extra entries into + // the table, but we don't *require* them to pass the completeness test. auto IncludeStrippedTemplateNames = false; - auto EntryNames = - getNames(Die, IncludeStrippedTemplateNames, IncludeLinkageName); + auto IncludeObjCNames = false; + auto EntryNames = getNames(Die, IncludeStrippedTemplateNames, + IncludeObjCNames, IncludeLinkageName); if (EntryNames.empty()) return 0; diff --git a/llvm/test/tools/dsymutil/X86/objc.test b/llvm/test/tools/dsymutil/X86/objc.test --- a/llvm/test/tools/dsymutil/X86/objc.test +++ b/llvm/test/tools/dsymutil/X86/objc.test @@ -1,6 +1,17 @@ RUN: dsymutil --verify-dwarf=output -f -oso-prepend-path=%p/.. %p/../Inputs/objc.macho.x86_64 -o %t.d4 RUN: llvm-dwarfdump -apple-types -apple-objc %t.d4 | FileCheck %s +; Test DWARF 5 tables +RUN: dsymutil --verify-dwarf=output --accelerator='Dwarf' -f -oso-prepend-path=%p/.. %p/../Inputs/objc.macho.x86_64 -o %t.d5 +RUN: llvm-dwarfdump -debug-names %t.d5 | FileCheck %s --check-prefix=D5 + +D5: String: {{.*}} "method1:" +D5: String: {{.*}} "method2:" +D5: String: {{.*}} "A" +D5: String: {{.*}} "-[A(Category) method2:]" +D5: String: {{.*}} "-[A method1:]" +D5: String: {{.*}} "-[Amethod2:]" + CHECK: .apple_types contents: CHECK: String: 0x00000066 "A" CHECK-NEXT: Data 0 [