Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
[llvm][dwarfdump] Show name of referenced DW_TAG_APPLE_property (llvm…
…#165537)

This patch makes `dwarfdump` show the `DW_AT_APPLE_property_name` of a
referenced `DW_TAG_APPLE_property` (similar to how we show the name of a
referenced `DW_AT_type`). Eventually we'll extend this to the DWARFv6
property tags too.

Before:
```
0x00000013:     DW_TAG_APPLE_property
                  DW_AT_APPLE_property_name     ("propertyName")

0x0000001b:     DW_TAG_member
                  DW_AT_name    ("_ivar")
                  DW_AT_APPLE_property  (0x00000013)
```
After:
```
0x00000013:     DW_TAG_APPLE_property
                  DW_AT_APPLE_property_name     ("propertyName")

0x0000001b:     DW_TAG_member
                  DW_AT_name    ("_ivar")
                  DW_AT_APPLE_property  (0x00000013 "propertyName")
```

(cherry picked from commit 1e7c082)
  • Loading branch information
Michael137 committed Nov 5, 2025
commit 401a413a35307477716942db07950f65515aa506
28 changes: 28 additions & 0 deletions llvm/lib/DebugInfo/DWARF/DWARFDie.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,25 @@ static DWARFDie resolveReferencedType(DWARFDie D, DWARFFormValue F) {
return D.getAttributeValueAsReferencedDie(F).resolveTypeUnitReference();
}

static llvm::Expected<llvm::StringRef>
getApplePropertyName(const DWARFDie &PropDIE) {
if (!PropDIE)
return llvm::createStringError("invalid DIE");

if (PropDIE.getTag() != DW_TAG_APPLE_property)
return llvm::createStringError("not referencing a DW_TAG_APPLE_property");

auto PropNameForm = PropDIE.find(DW_AT_APPLE_property_name);
if (!PropNameForm)
return "";

auto NameOrErr = PropNameForm->getAsCString();
if (!NameOrErr)
return NameOrErr.takeError();

return *NameOrErr;
}

static void dumpAttribute(raw_ostream &OS, const DWARFDie &Die,
const DWARFAttribute &AttrValue, unsigned Indent,
DIDumpOptions DumpOpts) {
Expand Down Expand Up @@ -197,6 +216,15 @@ static void dumpAttribute(raw_ostream &OS, const DWARFDie &Die,
Die.getAttributeValueAsReferencedDie(FormValue).getName(
DINameKind::LinkageName))
OS << Space << "\"" << Name << '\"';
} else if (Attr == DW_AT_APPLE_property) {
auto PropDIE = Die.getAttributeValueAsReferencedDie(FormValue);
if (auto PropNameOrErr = getApplePropertyName(PropDIE))
OS << Space << "\"" << *PropNameOrErr << '\"';
else
DumpOpts.RecoverableErrorHandler(createStringError(
errc::invalid_argument,
llvm::formatv("decoding DW_AT_APPLE_property_name: {}",
toString(PropNameOrErr.takeError()))));
} else if (Attr == DW_AT_type || Attr == DW_AT_containing_type) {
DWARFDie D = resolveReferencedType(Die, FormValue);
if (D && !D.isNULL()) {
Expand Down
126 changes: 126 additions & 0 deletions llvm/test/tools/llvm-dwarfdump/AArch64/DW_AT_APPLE_property.s
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
# Checks that we correctly display the DW_AT_APPLE_property_name of a
# referenced DW_TAG_APPLE_property.
#
# RUN: llvm-mc -triple=aarch64--darwin -filetype=obj -o %t.o < %s
# RUN: not llvm-dwarfdump %t.o 2> %t.errs.txt | FileCheck %s
# RUN: FileCheck %s --check-prefix=ERRORS < %t.errs.txt

# CHECK: 0x[[PROP_REF:[0-9a-f]+]]: DW_TAG_APPLE_property
# CHECK-NEXT: DW_AT_APPLE_property_name ("autoSynthProp")
#
# CHECK: 0x[[NO_NAME_PROP:[0-9a-f]+]]: DW_TAG_APPLE_property
# CHECK-NOT: DW_AT_APPLE_property_name
#
# CHECK: 0x[[INVALID_STRP:[0-9a-f]+]]: DW_TAG_APPLE_property
# CHECK-NEXT: DW_AT_APPLE_property_name
#
# CHECK: DW_TAG_member
# CHECK: DW_AT_APPLE_property (0x[[PROP_REF]] "autoSynthProp")
# CHECK: DW_AT_APPLE_property (0x[[NO_NAME_PROP]] "")
# CHECK: DW_AT_APPLE_property (0x{{.*}})
# CHECK: DW_AT_APPLE_property (0x{{.*}})
# CHECK: DW_AT_APPLE_property (0x[[INVALID_STRP]])

# ERRORS: error: decoding DW_AT_APPLE_property_name: not referencing a DW_TAG_APPLE_property
# ERRORS: error: decoding DW_AT_APPLE_property_name: invalid DIE
# ERRORS: error: decoding DW_AT_APPLE_property_name: DW_FORM_strp offset 102 is beyond .debug_str bounds

.section __DWARF,__debug_abbrev,regular,debug
Lsection_abbrev:
.byte 1 ; Abbreviation Code
.byte 17 ; DW_TAG_compile_unit
.byte 1 ; DW_CHILDREN_yes
.byte 114 ; DW_AT_str_offsets_base
.byte 23 ; DW_FORM_sec_offset
.byte 0 ; EOM(1)
.byte 0 ; EOM(2)
.byte 2 ; Abbreviation Code
.byte 19 ; DW_TAG_structure_type
.byte 1 ; DW_CHILDREN_yes
.byte 3 ; DW_AT_name
.byte 37 ; DW_FORM_strx1
.byte 0 ; EOM(1)
.byte 0 ; EOM(2)
.byte 3 ; Abbreviation Code
.ascii "\200\204\001" ; DW_TAG_APPLE_property
.byte 0 ; DW_CHILDREN_no
.ascii "\350\177" ; DW_AT_APPLE_property_name
.byte 37 ; DW_FORM_strx1
.byte 0 ; EOM(1)
.byte 0 ; EOM(2)
.byte 4 ; Abbreviation Code
.ascii "\200\204\001" ; DW_TAG_APPLE_property
.byte 0 ; DW_CHILDREN_no
.byte 0 ; EOM(1)
.byte 0 ; EOM(2)
.byte 5 ; Abbreviation Code
.ascii "\200\204\001" ; DW_TAG_APPLE_property
.byte 0 ; DW_CHILDREN_no
.ascii "\350\177" ; DW_AT_APPLE_property_name
.byte 14 ; DW_FORM_strp
.byte 0 ; EOM(1)
.byte 0 ; EOM(2)
.byte 6 ; Abbreviation Code
.byte 13 ; DW_TAG_member
.byte 0 ; DW_CHILDREN_no
.byte 3 ; DW_AT_name
.byte 37 ; DW_FORM_strx1
.ascii "\355\177" ; DW_AT_APPLE_property
.byte 19 ; DW_FORM_ref4
.ascii "\355\177" ; DW_AT_APPLE_property
.byte 19 ; DW_FORM_ref4
.ascii "\355\177" ; DW_AT_APPLE_property
.byte 19 ; DW_FORM_ref4
.ascii "\355\177" ; DW_AT_APPLE_property
.byte 19 ; DW_FORM_ref4
.ascii "\355\177" ; DW_AT_APPLE_property
.byte 19 ; DW_FORM_ref4
.byte 0 ; EOM(1)
.byte 0 ; EOM(2)
.byte 0 ; EOM(3)
.section __DWARF,__debug_info,regular,debug
Lsection_info:
Lcu_begin0:
Lset0 = Ldebug_info_end0-Ldebug_info_start0 ; Length of Unit
.long Lset0
Ldebug_info_start0:
.short 5 ; DWARF version number
.byte 1 ; DWARF Unit Type
.byte 8 ; Address Size (in bytes)
Lset1 = Lsection_abbrev-Lsection_abbrev ; Offset Into Abbrev. Section
.long Lset1
.byte 1 ; Abbrev [1] DW_TAG_compile_unit
Lset2 = Lstr_offsets_base0-Lsection_str_off ; DW_AT_str_offsets_base
.long Lset2
.byte 2 ; Abbrev [2] DW_TAG_structure_type
.byte 2 ; DW_AT_name
.byte 3 ; Abbrev [3] DW_TAG_APPLE_property
.byte 0 ; DW_AT_APPLE_property_name
.byte 4 ; Abbrev [4] DW_TAG_APPLE_property
.byte 5 ; Abbrev [5] DW_TAG_APPLE_property
.long 102 ; DW_AT_APPLE_property_name
.byte 6 ; Abbrev [6] DW_TAG_member
.byte 1 ; DW_AT_name
.long 19 ; DW_AT_APPLE_property
.long 21 ; DW_AT_APPLE_property
.long 17 ; DW_AT_APPLE_property
.long 0 ; DW_AT_APPLE_property
.long 22 ; DW_AT_APPLE_property
.byte 0 ; End Of Children Mark
.byte 0 ; End Of Children Mark
Ldebug_info_end0:
.section __DWARF,__debug_str_offs,regular,debug
Lsection_str_off:
.long 16 ; Length of String Offsets Set
.short 5
.short 0
Lstr_offsets_base0:
.section __DWARF,__debug_str,regular,debug
Linfo_string:
.asciz "autoSynthProp" ; string offset=0
.asciz "_var" ; string offset=14
.asciz "Foo" ; string offset=19
.section __DWARF,__debug_str_offs,regular,debug
.long 0
.long 14
.long 19