[llvm] ab0eb59 - [DWARFVerifier] Allow ObjectiveC names in dwarf_debug tables

Felipe de Azevedo Piovezan via llvm-commits llvm-commits at lists.llvm.org
Thu Sep 7 11:27:28 PDT 2023


Author: Felipe de Azevedo Piovezan
Date: 2023-09-07T14:26:49-04:00
New Revision: ab0eb59f1cdace22b1c38c2e1e3e81cc3b923228

URL: https://github.com/llvm/llvm-project/commit/ab0eb59f1cdace22b1c38c2e1e3e81cc3b923228
DIFF: https://github.com/llvm/llvm-project/commit/ab0eb59f1cdace22b1c38c2e1e3e81cc3b923228.diff

LOG: [DWARFVerifier] Allow ObjectiveC names in dwarf_debug tables

ObjectiveC has its own extra accelerator table entries that are helpful for the
debugger. This patch relaxes the DWARFVerifier so that it accepts those in DWARF
5's debug_names.

Differential Revision: https://reviews.llvm.org/D159471

Added: 
    

Modified: 
    llvm/lib/DebugInfo/DWARF/DWARFVerifier.cpp
    llvm/test/tools/dsymutil/X86/objc.test

Removed: 
    


################################################################################
diff  --git a/llvm/lib/DebugInfo/DWARF/DWARFVerifier.cpp b/llvm/lib/DebugInfo/DWARF/DWARFVerifier.cpp
index 9e3e791a13927e..43ed60d7f9775d 100644
--- a/llvm/lib/DebugInfo/DWARF/DWARFVerifier.cpp
+++ b/llvm/lib/DebugInfo/DWARF/DWARFVerifier.cpp
@@ -1351,16 +1351,32 @@ DWARFVerifier::verifyNameIndexAbbrevs(const DWARFDebugNames::NameIndex &NI) {
   return NumErrors;
 }
 
-static SmallVector<StringRef, 3> getNames(const DWARFDie &DIE,
-                                          bool IncludeStrippedTemplateNames,
-                                          bool IncludeLinkageName = true) {
-  SmallVector<StringRef, 3> Result;
+static SmallVector<std::string, 3> getNames(const DWARFDie &DIE,
+                                            bool IncludeStrippedTemplateNames,
+                                            bool IncludeObjCNames = true,
+                                            bool IncludeLinkageName = true) {
+  SmallVector<std::string, 3> Result;
   if (const char *Str = DIE.getShortName()) {
-    Result.emplace_back(Str);
+    StringRef Name(Str);
+    Result.emplace_back(Name);
     if (IncludeStrippedTemplateNames) {
       if (std::optional<StringRef> 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<ObjCSelectorNames> 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 @@ unsigned DWARFVerifier::verifyNameIndexCompleteness(
   // 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
index 1dd3ff19f2f5d2..d3df95802e0f00 100644
--- 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 [


        


More information about the llvm-commits mailing list