Skip to content

Commit 1e7c082

Browse files
authored
[llvm][dwarfdump] Show name of referenced DW_TAG_APPLE_property (#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") ```
1 parent 44fefe7 commit 1e7c082

File tree

2 files changed

+154
-0
lines changed

2 files changed

+154
-0
lines changed

llvm/lib/DebugInfo/DWARF/DWARFDie.cpp

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,25 @@ prettyLanguageVersionString(const DWARFAttribute &AttrValue,
129129
static_cast<SourceLanguageName>(*LName), *LVersion);
130130
}
131131

132+
static llvm::Expected<llvm::StringRef>
133+
getApplePropertyName(const DWARFDie &PropDIE) {
134+
if (!PropDIE)
135+
return llvm::createStringError("invalid DIE");
136+
137+
if (PropDIE.getTag() != DW_TAG_APPLE_property)
138+
return llvm::createStringError("not referencing a DW_TAG_APPLE_property");
139+
140+
auto PropNameForm = PropDIE.find(DW_AT_APPLE_property_name);
141+
if (!PropNameForm)
142+
return "";
143+
144+
auto NameOrErr = PropNameForm->getAsCString();
145+
if (!NameOrErr)
146+
return NameOrErr.takeError();
147+
148+
return *NameOrErr;
149+
}
150+
132151
static void dumpAttribute(raw_ostream &OS, const DWARFDie &Die,
133152
const DWARFAttribute &AttrValue, unsigned Indent,
134153
DIDumpOptions DumpOpts) {
@@ -233,6 +252,15 @@ static void dumpAttribute(raw_ostream &OS, const DWARFDie &Die,
233252
Die.getAttributeValueAsReferencedDie(FormValue).getName(
234253
DINameKind::LinkageName))
235254
OS << Space << "\"" << Name << '\"';
255+
} else if (Attr == DW_AT_APPLE_property) {
256+
auto PropDIE = Die.getAttributeValueAsReferencedDie(FormValue);
257+
if (auto PropNameOrErr = getApplePropertyName(PropDIE))
258+
OS << Space << "\"" << *PropNameOrErr << '\"';
259+
else
260+
DumpOpts.RecoverableErrorHandler(createStringError(
261+
errc::invalid_argument,
262+
llvm::formatv("decoding DW_AT_APPLE_property_name: {}",
263+
toString(PropNameOrErr.takeError()))));
236264
} else if (Attr == DW_AT_type || Attr == DW_AT_containing_type) {
237265
DWARFDie D = resolveReferencedType(Die, FormValue);
238266
if (D && !D.isNULL()) {
Lines changed: 126 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,126 @@
1+
# Checks that we correctly display the DW_AT_APPLE_property_name of a
2+
# referenced DW_TAG_APPLE_property.
3+
#
4+
# RUN: llvm-mc -triple=aarch64--darwin -filetype=obj -o %t.o < %s
5+
# RUN: not llvm-dwarfdump %t.o 2> %t.errs.txt | FileCheck %s
6+
# RUN: FileCheck %s --check-prefix=ERRORS < %t.errs.txt
7+
8+
# CHECK: 0x[[PROP_REF:[0-9a-f]+]]: DW_TAG_APPLE_property
9+
# CHECK-NEXT: DW_AT_APPLE_property_name ("autoSynthProp")
10+
#
11+
# CHECK: 0x[[NO_NAME_PROP:[0-9a-f]+]]: DW_TAG_APPLE_property
12+
# CHECK-NOT: DW_AT_APPLE_property_name
13+
#
14+
# CHECK: 0x[[INVALID_STRP:[0-9a-f]+]]: DW_TAG_APPLE_property
15+
# CHECK-NEXT: DW_AT_APPLE_property_name
16+
#
17+
# CHECK: DW_TAG_member
18+
# CHECK: DW_AT_APPLE_property (0x[[PROP_REF]] "autoSynthProp")
19+
# CHECK: DW_AT_APPLE_property (0x[[NO_NAME_PROP]] "")
20+
# CHECK: DW_AT_APPLE_property (0x{{.*}})
21+
# CHECK: DW_AT_APPLE_property (0x{{.*}})
22+
# CHECK: DW_AT_APPLE_property (0x[[INVALID_STRP]])
23+
24+
# ERRORS: error: decoding DW_AT_APPLE_property_name: not referencing a DW_TAG_APPLE_property
25+
# ERRORS: error: decoding DW_AT_APPLE_property_name: invalid DIE
26+
# ERRORS: error: decoding DW_AT_APPLE_property_name: DW_FORM_strp offset 102 is beyond .debug_str bounds
27+
28+
.section __DWARF,__debug_abbrev,regular,debug
29+
Lsection_abbrev:
30+
.byte 1 ; Abbreviation Code
31+
.byte 17 ; DW_TAG_compile_unit
32+
.byte 1 ; DW_CHILDREN_yes
33+
.byte 114 ; DW_AT_str_offsets_base
34+
.byte 23 ; DW_FORM_sec_offset
35+
.byte 0 ; EOM(1)
36+
.byte 0 ; EOM(2)
37+
.byte 2 ; Abbreviation Code
38+
.byte 19 ; DW_TAG_structure_type
39+
.byte 1 ; DW_CHILDREN_yes
40+
.byte 3 ; DW_AT_name
41+
.byte 37 ; DW_FORM_strx1
42+
.byte 0 ; EOM(1)
43+
.byte 0 ; EOM(2)
44+
.byte 3 ; Abbreviation Code
45+
.ascii "\200\204\001" ; DW_TAG_APPLE_property
46+
.byte 0 ; DW_CHILDREN_no
47+
.ascii "\350\177" ; DW_AT_APPLE_property_name
48+
.byte 37 ; DW_FORM_strx1
49+
.byte 0 ; EOM(1)
50+
.byte 0 ; EOM(2)
51+
.byte 4 ; Abbreviation Code
52+
.ascii "\200\204\001" ; DW_TAG_APPLE_property
53+
.byte 0 ; DW_CHILDREN_no
54+
.byte 0 ; EOM(1)
55+
.byte 0 ; EOM(2)
56+
.byte 5 ; Abbreviation Code
57+
.ascii "\200\204\001" ; DW_TAG_APPLE_property
58+
.byte 0 ; DW_CHILDREN_no
59+
.ascii "\350\177" ; DW_AT_APPLE_property_name
60+
.byte 14 ; DW_FORM_strp
61+
.byte 0 ; EOM(1)
62+
.byte 0 ; EOM(2)
63+
.byte 6 ; Abbreviation Code
64+
.byte 13 ; DW_TAG_member
65+
.byte 0 ; DW_CHILDREN_no
66+
.byte 3 ; DW_AT_name
67+
.byte 37 ; DW_FORM_strx1
68+
.ascii "\355\177" ; DW_AT_APPLE_property
69+
.byte 19 ; DW_FORM_ref4
70+
.ascii "\355\177" ; DW_AT_APPLE_property
71+
.byte 19 ; DW_FORM_ref4
72+
.ascii "\355\177" ; DW_AT_APPLE_property
73+
.byte 19 ; DW_FORM_ref4
74+
.ascii "\355\177" ; DW_AT_APPLE_property
75+
.byte 19 ; DW_FORM_ref4
76+
.ascii "\355\177" ; DW_AT_APPLE_property
77+
.byte 19 ; DW_FORM_ref4
78+
.byte 0 ; EOM(1)
79+
.byte 0 ; EOM(2)
80+
.byte 0 ; EOM(3)
81+
.section __DWARF,__debug_info,regular,debug
82+
Lsection_info:
83+
Lcu_begin0:
84+
Lset0 = Ldebug_info_end0-Ldebug_info_start0 ; Length of Unit
85+
.long Lset0
86+
Ldebug_info_start0:
87+
.short 5 ; DWARF version number
88+
.byte 1 ; DWARF Unit Type
89+
.byte 8 ; Address Size (in bytes)
90+
Lset1 = Lsection_abbrev-Lsection_abbrev ; Offset Into Abbrev. Section
91+
.long Lset1
92+
.byte 1 ; Abbrev [1] DW_TAG_compile_unit
93+
Lset2 = Lstr_offsets_base0-Lsection_str_off ; DW_AT_str_offsets_base
94+
.long Lset2
95+
.byte 2 ; Abbrev [2] DW_TAG_structure_type
96+
.byte 2 ; DW_AT_name
97+
.byte 3 ; Abbrev [3] DW_TAG_APPLE_property
98+
.byte 0 ; DW_AT_APPLE_property_name
99+
.byte 4 ; Abbrev [4] DW_TAG_APPLE_property
100+
.byte 5 ; Abbrev [5] DW_TAG_APPLE_property
101+
.long 102 ; DW_AT_APPLE_property_name
102+
.byte 6 ; Abbrev [6] DW_TAG_member
103+
.byte 1 ; DW_AT_name
104+
.long 19 ; DW_AT_APPLE_property
105+
.long 21 ; DW_AT_APPLE_property
106+
.long 17 ; DW_AT_APPLE_property
107+
.long 0 ; DW_AT_APPLE_property
108+
.long 22 ; DW_AT_APPLE_property
109+
.byte 0 ; End Of Children Mark
110+
.byte 0 ; End Of Children Mark
111+
Ldebug_info_end0:
112+
.section __DWARF,__debug_str_offs,regular,debug
113+
Lsection_str_off:
114+
.long 16 ; Length of String Offsets Set
115+
.short 5
116+
.short 0
117+
Lstr_offsets_base0:
118+
.section __DWARF,__debug_str,regular,debug
119+
Linfo_string:
120+
.asciz "autoSynthProp" ; string offset=0
121+
.asciz "_var" ; string offset=14
122+
.asciz "Foo" ; string offset=19
123+
.section __DWARF,__debug_str_offs,regular,debug
124+
.long 0
125+
.long 14
126+
.long 19

0 commit comments

Comments
 (0)