Skip to content

Conversation

@Michael137
Copy link
Member

@Michael137 Michael137 commented Oct 29, 2025

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") 
@llvmbot
Copy link
Member

llvmbot commented Oct 29, 2025

@llvm/pr-subscribers-debuginfo

Author: Michael Buch (Michael137)

Changes

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 ("autoSynthProp") 0x0000001b: DW_TAG_member DW_AT_name ("_var") DW_AT_APPLE_property (0x00000013) 

After:

0x00000013: DW_TAG_APPLE_property DW_AT_APPLE_property_name ("autoSynthProp") 0x0000001b: DW_TAG_member DW_AT_name ("_var") DW_AT_APPLE_property (0x00000013 "autoSynthProp") 

Full diff: https://github.com/llvm/llvm-project/pull/165537.diff

2 Files Affected:

  • (modified) llvm/lib/DebugInfo/DWARF/DWARFDie.cpp (+28)
  • (added) llvm/test/tools/llvm-dwarfdump/AArch64/DW_AT_APPLE_property.s (+126)
diff --git a/llvm/lib/DebugInfo/DWARF/DWARFDie.cpp b/llvm/lib/DebugInfo/DWARF/DWARFDie.cpp index db5cc37c93f90..94da588c439d4 100644 --- a/llvm/lib/DebugInfo/DWARF/DWARFDie.cpp +++ b/llvm/lib/DebugInfo/DWARF/DWARFDie.cpp @@ -129,6 +129,25 @@ prettyLanguageVersionString(const DWARFAttribute &AttrValue, static_cast<SourceLanguageName>(*LName), *LVersion); } +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("referencing not 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) { @@ -233,6 +252,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()) { diff --git a/llvm/test/tools/llvm-dwarfdump/AArch64/DW_AT_APPLE_property.s b/llvm/test/tools/llvm-dwarfdump/AArch64/DW_AT_APPLE_property.s new file mode 100644 index 0000000000000..416ad352c2254 --- /dev/null +++ b/llvm/test/tools/llvm-dwarfdump/AArch64/DW_AT_APPLE_property.s @@ -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: referencing not 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 
@github-actions
Copy link

github-actions bot commented Oct 29, 2025

✅ With the latest revision this PR passed the C/C++ code formatter.

return llvm::createStringError("invalid DIE");

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

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit:

Suggested change
return llvm::createStringError("referencing not a DW_TAG_APPLE_property");
return llvm::createStringError("not referencing a DW_TAG_APPLE_property");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

4 participants