Skip to content

Commit 3cbc4c4

Browse files
committed
llvm-dwarfdump: Rebuild type names in dwo type units
1 parent dc1c271 commit 3cbc4c4

File tree

6 files changed

+500
-23
lines changed

6 files changed

+500
-23
lines changed

llvm/include/llvm/DebugInfo/DWARF/DWARFContext.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -243,7 +243,7 @@ class DWARFContext : public DIContext {
243243
}
244244

245245
DWARFCompileUnit *getDWOCompileUnitForHash(uint64_t Hash);
246-
DWARFTypeUnit *getTypeUnitForHash(uint16_t Version, uint64_t Hash);
246+
DWARFTypeUnit *getTypeUnitForHash(uint16_t Version, uint64_t Hash, bool IsDWO);
247247

248248
/// Return the compile unit that includes an offset (relative to .debug_info).
249249
DWARFCompileUnit *getCompileUnitForOffset(uint64_t Offset);

llvm/lib/DebugInfo/DWARF/DWARFContext.cpp

Lines changed: 9 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -693,24 +693,15 @@ void DWARFContext::dump(
693693
getDebugNames().dump(OS);
694694
}
695695

696-
DWARFTypeUnit *DWARFContext::getTypeUnitForHash(uint16_t Version,
697-
uint64_t Hash) {
698-
// FIXME: Include support for Split DWARF here
699-
parseNormalUnits();
700-
701-
auto IsTypeWithHash = [&](const std::unique_ptr<DWARFUnit> &Unit) {
702-
DWARFTypeUnit *TU = dyn_cast<DWARFTypeUnit>(Unit.get());
703-
if (!TU)
704-
return false;
705-
return TU->getTypeHash() == Hash;
706-
};
707-
auto I = llvm::find_if(types_section_units(), IsTypeWithHash);
708-
if (I != types_section_units().end())
709-
return cast<DWARFTypeUnit>(I->get());
710-
// Search normal .debug_info units in case it's a DWARFv5 type unit.
711-
I = llvm::find_if(normal_units(), IsTypeWithHash);
712-
if (I != types_section_units().end())
713-
return cast<DWARFTypeUnit>(I->get());
696+
DWARFTypeUnit *DWARFContext::getTypeUnitForHash(uint16_t Version, uint64_t Hash,
697+
bool IsDWO) {
698+
// FIXME: Check for/use the tu_index here, if there is one.
699+
for (const auto &U : IsDWO ? dwo_units() : normal_units()) {
700+
if (DWARFTypeUnit *TU = dyn_cast<DWARFTypeUnit>(U.get())) {
701+
if (TU->getTypeHash() == Hash)
702+
return TU;
703+
}
704+
}
714705
return nullptr;
715706
}
716707

llvm/lib/DebugInfo/DWARF/DWARFDie.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -891,8 +891,8 @@ DWARFDie::getAttributeValueAsReferencedDie(const DWARFFormValue &V) const {
891891
DWARFDie DWARFDie::resolveTypeUnitReference() const {
892892
if (auto Attr = find(DW_AT_signature)) {
893893
if (Optional<uint64_t> Sig = Attr->getAsReferenceUVal()) {
894-
if (DWARFTypeUnit *TU =
895-
U->getContext().getTypeUnitForHash(U->getVersion(), *Sig))
894+
if (DWARFTypeUnit *TU = U->getContext().getTypeUnitForHash(
895+
U->getVersion(), *Sig, U->isDWOUnit()))
896896
return TU->getDIEForOffset(TU->getTypeOffset() + TU->getOffset());
897897
}
898898
}

llvm/test/tools/llvm-dwarfdump/X86/prettyprint_type_units.s

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,9 @@
2121

2222

2323
# CHECK: DW_TAG_template_type_parameter
24-
# CHECK: DW_AT_type (0x00000058 "t1")
24+
# CHECK: DW_AT_type ({{.*}} "t1")
2525
# CHECK: DW_TAG_template_type_parameter
26-
# CHECK: DW_AT_type (0x00000061 "t2")
26+
# CHECK: DW_AT_type ({{.*}} "t2")
2727

2828
.text
2929
.file "test.cpp"
Lines changed: 243 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,243 @@
1+
# RUN: llvm-mc < %s -filetype obj -triple x86_64 -o - \
2+
# RUN: | llvm-dwarfdump - | FileCheck %s
3+
4+
# Generated from:
5+
#
6+
# struct t1 { };
7+
# t1 v1;
8+
#
9+
# $ clang++ -S -g -fdebug-types-section -gsplit-dwarf -o test.5.split.s -gdwarf-5 -g
10+
11+
# CHECK: DW_TAG_variable
12+
# CHECK: DW_AT_type ({{.*}} "t1")
13+
14+
.text
15+
.file "test.cpp"
16+
.section .debug_types.dwo,"e",@progbits
17+
.long .Ldebug_info_dwo_end0-.Ldebug_info_dwo_start0 # Length of Unit
18+
.Ldebug_info_dwo_start0:
19+
.short 4 # DWARF version number
20+
.long 0 # Offset Into Abbrev. Section
21+
.byte 8 # Address Size (in bytes)
22+
.quad -4149699470930386446 # Type Signature
23+
.long 30 # Type DIE Offset
24+
.byte 1 # Abbrev [1] 0x17:0xe DW_TAG_type_unit
25+
.short 33 # DW_AT_language
26+
.long 0 # DW_AT_stmt_list
27+
.byte 2 # Abbrev [2] 0x1e:0x6 DW_TAG_structure_type
28+
.byte 5 # DW_AT_calling_convention
29+
.byte 1 # DW_AT_name
30+
.byte 1 # DW_AT_byte_size
31+
.byte 1 # DW_AT_decl_file
32+
.byte 1 # DW_AT_decl_line
33+
.byte 0 # End Of Children Mark
34+
.Ldebug_info_dwo_end0:
35+
.file 1 "/usr/local/google/home/blaikie/dev/scratch" "test.cpp"
36+
.type v1,@object # @v1
37+
.bss
38+
.globl v1
39+
v1:
40+
.zero 1
41+
.size v1, 1
42+
43+
.section .debug_abbrev,"",@progbits
44+
.byte 1 # Abbreviation Code
45+
.byte 17 # DW_TAG_compile_unit
46+
.byte 0 # DW_CHILDREN_no
47+
.byte 16 # DW_AT_stmt_list
48+
.byte 23 # DW_FORM_sec_offset
49+
.byte 27 # DW_AT_comp_dir
50+
.byte 14 # DW_FORM_strp
51+
.ascii "\264B" # DW_AT_GNU_pubnames
52+
.byte 25 # DW_FORM_flag_present
53+
.ascii "\260B" # DW_AT_GNU_dwo_name
54+
.byte 14 # DW_FORM_strp
55+
.ascii "\261B" # DW_AT_GNU_dwo_id
56+
.byte 7 # DW_FORM_data8
57+
.ascii "\263B" # DW_AT_GNU_addr_base
58+
.byte 23 # DW_FORM_sec_offset
59+
.byte 0 # EOM(1)
60+
.byte 0 # EOM(2)
61+
.byte 0 # EOM(3)
62+
.section .debug_info,"",@progbits
63+
.Lcu_begin0:
64+
.long .Ldebug_info_end0-.Ldebug_info_start0 # Length of Unit
65+
.Ldebug_info_start0:
66+
.short 4 # DWARF version number
67+
.long .debug_abbrev # Offset Into Abbrev. Section
68+
.byte 8 # Address Size (in bytes)
69+
.byte 1 # Abbrev [1] 0xb:0x19 DW_TAG_compile_unit
70+
.long .Lline_table_start0 # DW_AT_stmt_list
71+
.long .Lskel_string0 # DW_AT_comp_dir
72+
# DW_AT_GNU_pubnames
73+
.long .Lskel_string1 # DW_AT_GNU_dwo_name
74+
.quad 5272896739482311860 # DW_AT_GNU_dwo_id
75+
.long .Laddr_table_base0 # DW_AT_GNU_addr_base
76+
.Ldebug_info_end0:
77+
.section .debug_str,"MS",@progbits,1
78+
.Lskel_string0:
79+
.asciz "/usr/local/google/home/blaikie/dev/scratch" # string offset=0
80+
.Lskel_string1:
81+
.asciz "test.dwo" # string offset=43
82+
.section .debug_str.dwo,"eMS",@progbits,1
83+
.Linfo_string0:
84+
.asciz "v1" # string offset=0
85+
.Linfo_string1:
86+
.asciz "t1" # string offset=3
87+
.Linfo_string2:
88+
.asciz "clang version 14.0.0 ([email protected]:llvm/llvm-project.git c9e46219f38da5c3fbfe41012173dc893516826e)" # string offset=6
89+
.Linfo_string3:
90+
.asciz "test.cpp" # string offset=107
91+
.Linfo_string4:
92+
.asciz "test.dwo" # string offset=116
93+
.section .debug_str_offsets.dwo,"e",@progbits
94+
.long 0
95+
.long 3
96+
.long 6
97+
.long 107
98+
.long 116
99+
.section .debug_info.dwo,"e",@progbits
100+
.long .Ldebug_info_dwo_end1-.Ldebug_info_dwo_start1 # Length of Unit
101+
.Ldebug_info_dwo_start1:
102+
.short 4 # DWARF version number
103+
.long 0 # Offset Into Abbrev. Section
104+
.byte 8 # Address Size (in bytes)
105+
.byte 3 # Abbrev [3] 0xb:0x23 DW_TAG_compile_unit
106+
.byte 2 # DW_AT_producer
107+
.short 33 # DW_AT_language
108+
.byte 3 # DW_AT_name
109+
.byte 4 # DW_AT_GNU_dwo_name
110+
.quad 5272896739482311860 # DW_AT_GNU_dwo_id
111+
.byte 4 # Abbrev [4] 0x19:0xb DW_TAG_variable
112+
.byte 0 # DW_AT_name
113+
.long 36 # DW_AT_type
114+
# DW_AT_external
115+
.byte 1 # DW_AT_decl_file
116+
.byte 2 # DW_AT_decl_line
117+
.byte 2 # DW_AT_location
118+
.byte 251
119+
.byte 0
120+
.byte 5 # Abbrev [5] 0x24:0x9 DW_TAG_structure_type
121+
# DW_AT_declaration
122+
.quad -4149699470930386446 # DW_AT_signature
123+
.byte 0 # End Of Children Mark
124+
.Ldebug_info_dwo_end1:
125+
.section .debug_abbrev.dwo,"e",@progbits
126+
.byte 1 # Abbreviation Code
127+
.byte 65 # DW_TAG_type_unit
128+
.byte 1 # DW_CHILDREN_yes
129+
.byte 19 # DW_AT_language
130+
.byte 5 # DW_FORM_data2
131+
.byte 16 # DW_AT_stmt_list
132+
.byte 23 # DW_FORM_sec_offset
133+
.byte 0 # EOM(1)
134+
.byte 0 # EOM(2)
135+
.byte 2 # Abbreviation Code
136+
.byte 19 # DW_TAG_structure_type
137+
.byte 0 # DW_CHILDREN_no
138+
.byte 54 # DW_AT_calling_convention
139+
.byte 11 # DW_FORM_data1
140+
.byte 3 # DW_AT_name
141+
.ascii "\202>" # DW_FORM_GNU_str_index
142+
.byte 11 # DW_AT_byte_size
143+
.byte 11 # DW_FORM_data1
144+
.byte 58 # DW_AT_decl_file
145+
.byte 11 # DW_FORM_data1
146+
.byte 59 # DW_AT_decl_line
147+
.byte 11 # DW_FORM_data1
148+
.byte 0 # EOM(1)
149+
.byte 0 # EOM(2)
150+
.byte 3 # Abbreviation Code
151+
.byte 17 # DW_TAG_compile_unit
152+
.byte 1 # DW_CHILDREN_yes
153+
.byte 37 # DW_AT_producer
154+
.ascii "\202>" # DW_FORM_GNU_str_index
155+
.byte 19 # DW_AT_language
156+
.byte 5 # DW_FORM_data2
157+
.byte 3 # DW_AT_name
158+
.ascii "\202>" # DW_FORM_GNU_str_index
159+
.ascii "\260B" # DW_AT_GNU_dwo_name
160+
.ascii "\202>" # DW_FORM_GNU_str_index
161+
.ascii "\261B" # DW_AT_GNU_dwo_id
162+
.byte 7 # DW_FORM_data8
163+
.byte 0 # EOM(1)
164+
.byte 0 # EOM(2)
165+
.byte 4 # Abbreviation Code
166+
.byte 52 # DW_TAG_variable
167+
.byte 0 # DW_CHILDREN_no
168+
.byte 3 # DW_AT_name
169+
.ascii "\202>" # DW_FORM_GNU_str_index
170+
.byte 73 # DW_AT_type
171+
.byte 19 # DW_FORM_ref4
172+
.byte 63 # DW_AT_external
173+
.byte 25 # DW_FORM_flag_present
174+
.byte 58 # DW_AT_decl_file
175+
.byte 11 # DW_FORM_data1
176+
.byte 59 # DW_AT_decl_line
177+
.byte 11 # DW_FORM_data1
178+
.byte 2 # DW_AT_location
179+
.byte 24 # DW_FORM_exprloc
180+
.byte 0 # EOM(1)
181+
.byte 0 # EOM(2)
182+
.byte 5 # Abbreviation Code
183+
.byte 19 # DW_TAG_structure_type
184+
.byte 0 # DW_CHILDREN_no
185+
.byte 60 # DW_AT_declaration
186+
.byte 25 # DW_FORM_flag_present
187+
.byte 105 # DW_AT_signature
188+
.byte 32 # DW_FORM_ref_sig8
189+
.byte 0 # EOM(1)
190+
.byte 0 # EOM(2)
191+
.byte 0 # EOM(3)
192+
.section .debug_line.dwo,"e",@progbits
193+
.Ltmp0:
194+
.long .Ldebug_line_end0-.Ldebug_line_start0 # unit length
195+
.Ldebug_line_start0:
196+
.short 4
197+
.long .Lprologue_end0-.Lprologue_start0
198+
.Lprologue_start0:
199+
.byte 1
200+
.byte 1
201+
.byte 1
202+
.byte -5
203+
.byte 14
204+
.byte 1
205+
.byte 0
206+
.ascii "test.cpp"
207+
.byte 0
208+
.byte 0
209+
.byte 0
210+
.byte 0
211+
.byte 0
212+
.Lprologue_end0:
213+
.Ldebug_line_end0:
214+
.section .debug_addr,"",@progbits
215+
.Laddr_table_base0:
216+
.quad v1
217+
.section .debug_gnu_pubnames,"",@progbits
218+
.long .LpubNames_end0-.LpubNames_start0 # Length of Public Names Info
219+
.LpubNames_start0:
220+
.short 2 # DWARF Version
221+
.long .Lcu_begin0 # Offset of Compilation Unit Info
222+
.long 36 # Compilation Unit Length
223+
.long 25 # DIE offset
224+
.byte 32 # Attributes: VARIABLE, EXTERNAL
225+
.asciz "v1" # External Name
226+
.long 0 # End Mark
227+
.LpubNames_end0:
228+
.section .debug_gnu_pubtypes,"",@progbits
229+
.long .LpubTypes_end0-.LpubTypes_start0 # Length of Public Types Info
230+
.LpubTypes_start0:
231+
.short 2 # DWARF Version
232+
.long .Lcu_begin0 # Offset of Compilation Unit Info
233+
.long 36 # Compilation Unit Length
234+
.long 36 # DIE offset
235+
.byte 16 # Attributes: TYPE, EXTERNAL
236+
.asciz "t1" # External Name
237+
.long 0 # End Mark
238+
.LpubTypes_end0:
239+
.ident "clang version 14.0.0 ([email protected]:llvm/llvm-project.git c9e46219f38da5c3fbfe41012173dc893516826e)"
240+
.section ".note.GNU-stack","",@progbits
241+
.addrsig
242+
.section .debug_line,"",@progbits
243+
.Lline_table_start0:

0 commit comments

Comments
 (0)