-   Notifications  You must be signed in to change notification settings 
- Fork 15k
[llvm][dwarfdump] Show name of referenced DW_TAG_APPLE_property #165537
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
[llvm][dwarfdump] Show name of referenced DW_TAG_APPLE_property #165537
Conversation
| @llvm/pr-subscribers-debuginfo Author: Michael Buch (Michael137) ChangesThis patch makes  Before: After: Full diff: https://github.com/llvm/llvm-project/pull/165537.diff 2 Files Affected: 
 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  | 
| ✅ 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"); | 
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit:
| return llvm::createStringError("referencing not a DW_TAG_APPLE_property"); | |
| return llvm::createStringError("not referencing a DW_TAG_APPLE_property"); | 
This patch makes
dwarfdumpshow theDW_AT_APPLE_property_nameof a referencedDW_TAG_APPLE_property(similar to how we show the name of a referencedDW_AT_type). Eventually we'll extend this to the DWARFv6 property tags too.Before:
After: