[PATCH] D159471: [DWARFVerifier] Allow ObjectiveC names in dwarf_debug tables
Felipe de Azevedo Piovezan via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Wed Sep 6 13:21:30 PDT 2023
fdeazeve created this revision.
fdeazeve added a reviewer: aprantl.
Herald added a subscriber: hiraditya.
Herald added a reviewer: JDevlieghere.
Herald added a project: All.
fdeazeve requested review of this revision.
Herald added subscribers: llvm-commits, wangpc.
Herald added a project: LLVM.
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.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D159471
Files:
llvm/lib/DebugInfo/DWARF/DWARFVerifier.cpp
llvm/test/tools/dsymutil/X86/objc.test
Index: llvm/test/tools/dsymutil/X86/objc.test
===================================================================
--- llvm/test/tools/dsymutil/X86/objc.test
+++ 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: 0x0000005d "method1:"
+;D5: String: 0x00000094 "method2:"
+;D5: String: 0x00000066 "A"
+;D5: String: 0x0000007c "-[A(Category) method2:]"
+;D5: String: 0x0000004f "-[A method1:]"
+;D5: String: 0x000000a9 "-[Amethod2:]"
+
CHECK: .apple_types contents:
CHECK: String: 0x00000066 "A"
CHECK-NEXT: Data 0 [
Index: llvm/lib/DebugInfo/DWARF/DWARFVerifier.cpp
===================================================================
--- llvm/lib/DebugInfo/DWARF/DWARFVerifier.cpp
+++ llvm/lib/DebugInfo/DWARF/DWARFVerifier.cpp
@@ -1351,16 +1351,32 @@
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 first, otherwise a vector resize may
+ // destroy the StringRef memory.
+ Result.push_back(StrippedName->str());
+ }
+
+ if (IncludeObjCNames) {
+ if (std::optional<ObjectiveCNames> 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;
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D159471.556074.patch
Type: text/x-patch
Size: 3710 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20230906/8274059a/attachment.bin>
More information about the llvm-commits
mailing list