Skip to content

Commit b6c06d1

Browse files
committed
[ORC] Fix bug in source file name finding in DebuggerSupportPlugin.
The debug section map was using MachO section names (with the "__" prefix), but DWARFContext expects section names with the object format prefix stripped off. This was preventing DWARFContext from accessing the debug_str section, resulting in bogus source name strings.
1 parent 56e944b commit b6c06d1

File tree

2 files changed

+333
-8
lines changed

2 files changed

+333
-8
lines changed

llvm/lib/ExecutionEngine/Orc/Debugging/DebuggerSupportPlugin.cpp

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ class MachODebugObjectSynthesizer : public MachODebugObjectSynthesizerBase {
148148
DSec.BuilderSec->align = Log2_64(SR.getFirstBlock()->getAlignment());
149149
StringRef SectionData(SR.getFirstBlock()->getContent().data(),
150150
SR.getFirstBlock()->getSize());
151-
DebugSectionMap[SecName] =
151+
DebugSectionMap[SecName.drop_front(2)] = // drop "__" prefix.
152152
MemoryBuffer::getMemBuffer(SectionData, G.getName(), false);
153153
if (SecName == "__debug_line")
154154
DebugLineSectionData = SectionData;
@@ -167,11 +167,10 @@ class MachODebugObjectSynthesizer : public MachODebugObjectSynthesizerBase {
167167
DebugLineSectionData, G.getEndianness() == llvm::endianness::little,
168168
G.getPointerSize());
169169
uint64_t Offset = 0;
170-
DWARFDebugLine::LineTable LineTable;
170+
DWARFDebugLine::Prologue P;
171171

172172
// Try to parse line data. Consume error on failure.
173-
if (auto Err = LineTable.parse(DebugLineData, &Offset, *DWARFCtx, nullptr,
174-
consumeError)) {
173+
if (auto Err = P.parse(DebugLineData, &Offset, consumeError, *DWARFCtx)) {
175174
handleAllErrors(std::move(Err), [&](ErrorInfoBase &EIB) {
176175
LLVM_DEBUG({
177176
dbgs() << "Cannot parse line table for \"" << G.getName() << "\": ";
@@ -180,15 +179,26 @@ class MachODebugObjectSynthesizer : public MachODebugObjectSynthesizerBase {
180179
});
181180
});
182181
} else {
183-
if (!LineTable.Prologue.FileNames.empty())
184-
FileName = *dwarf::toString(LineTable.Prologue.FileNames[0].Name);
182+
for (auto &FN : P.FileNames)
183+
if ((FileName = dwarf::toString(FN.Name))) {
184+
LLVM_DEBUG({
185+
dbgs() << "Using FileName = \"" << *FileName
186+
<< "\" from DWARF line table\n";
187+
});
188+
break;
189+
}
185190
}
186191
}
187192

188193
// If no line table (or unable to use) then use graph name.
189194
// FIXME: There are probably other debug sections we should look in first.
190-
if (!FileName)
191-
FileName = StringRef(G.getName());
195+
if (!FileName) {
196+
LLVM_DEBUG({
197+
dbgs() << "Could not find source name from DWARF line table. "
198+
"Using FileName = \"\"\n";
199+
});
200+
FileName = "";
201+
}
192202

193203
Builder.addSymbol("", MachO::N_SO, 0, 0, 0);
194204
Builder.addSymbol(*FileName, MachO::N_SO, 0, 0, 0);
Lines changed: 315 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,315 @@
1+
# RUN: llvm-mc -triple=x86_64-apple-macosx10.9 -filetype=obj -o %t.o %s
2+
# RUN: llvm-jitlink -debug-only=orc -noexec -debugger-support %t.o 2>&1 | \
3+
# RUN: FileCheck %s
4+
#
5+
# Test that source file names can be indentified from DWARF line tables.
6+
7+
# CHECK: Using FileName = "check-dwarf-filename.c" from DWARF line table
8+
9+
.section __TEXT,__text,regular,pure_instructions
10+
.build_version macos, 15, 0 sdk_version 15, 0
11+
.globl _main ## -- Begin function main
12+
.p2align 4, 0x90
13+
_main: ## @main
14+
Lfunc_begin0:
15+
.file 0 "/Users/lhames/Projects/scratch" "check-dwarf-filename.c" md5 0x331a6c7ae0cfcd2896eca60ac6f5703e
16+
.loc 0 1 0 ## check-dwarf-filename.c:1:0
17+
.cfi_startproc
18+
## %bb.0:
19+
##DEBUG_VALUE: main:argc <- $edi
20+
##DEBUG_VALUE: main:argv <- $rsi
21+
pushq %rbp
22+
.cfi_def_cfa_offset 16
23+
.cfi_offset %rbp, -16
24+
movq %rsp, %rbp
25+
.cfi_def_cfa_register %rbp
26+
Ltmp0:
27+
.loc 0 2 3 prologue_end ## check-dwarf-filename.c:2:3
28+
xorl %eax, %eax
29+
.loc 0 2 3 epilogue_begin is_stmt 0 ## check-dwarf-filename.c:2:3
30+
popq %rbp
31+
retq
32+
Ltmp1:
33+
Lfunc_end0:
34+
.cfi_endproc
35+
## -- End function
36+
.section __DWARF,__debug_abbrev,regular,debug
37+
Lsection_abbrev:
38+
.byte 1 ## Abbreviation Code
39+
.byte 17 ## DW_TAG_compile_unit
40+
.byte 1 ## DW_CHILDREN_yes
41+
.byte 37 ## DW_AT_producer
42+
.byte 37 ## DW_FORM_strx1
43+
.byte 19 ## DW_AT_language
44+
.byte 5 ## DW_FORM_data2
45+
.byte 3 ## DW_AT_name
46+
.byte 37 ## DW_FORM_strx1
47+
.ascii "\202|" ## DW_AT_LLVM_sysroot
48+
.byte 37 ## DW_FORM_strx1
49+
.ascii "\357\177" ## DW_AT_APPLE_sdk
50+
.byte 37 ## DW_FORM_strx1
51+
.byte 114 ## DW_AT_str_offsets_base
52+
.byte 23 ## DW_FORM_sec_offset
53+
.byte 16 ## DW_AT_stmt_list
54+
.byte 23 ## DW_FORM_sec_offset
55+
.byte 27 ## DW_AT_comp_dir
56+
.byte 37 ## DW_FORM_strx1
57+
.ascii "\341\177" ## DW_AT_APPLE_optimized
58+
.byte 25 ## DW_FORM_flag_present
59+
.byte 17 ## DW_AT_low_pc
60+
.byte 27 ## DW_FORM_addrx
61+
.byte 18 ## DW_AT_high_pc
62+
.byte 6 ## DW_FORM_data4
63+
.byte 115 ## DW_AT_addr_base
64+
.byte 23 ## DW_FORM_sec_offset
65+
.byte 0 ## EOM(1)
66+
.byte 0 ## EOM(2)
67+
.byte 2 ## Abbreviation Code
68+
.byte 46 ## DW_TAG_subprogram
69+
.byte 1 ## DW_CHILDREN_yes
70+
.byte 17 ## DW_AT_low_pc
71+
.byte 27 ## DW_FORM_addrx
72+
.byte 18 ## DW_AT_high_pc
73+
.byte 6 ## DW_FORM_data4
74+
.byte 64 ## DW_AT_frame_base
75+
.byte 24 ## DW_FORM_exprloc
76+
.byte 122 ## DW_AT_call_all_calls
77+
.byte 25 ## DW_FORM_flag_present
78+
.byte 3 ## DW_AT_name
79+
.byte 37 ## DW_FORM_strx1
80+
.byte 58 ## DW_AT_decl_file
81+
.byte 11 ## DW_FORM_data1
82+
.byte 59 ## DW_AT_decl_line
83+
.byte 11 ## DW_FORM_data1
84+
.byte 39 ## DW_AT_prototyped
85+
.byte 25 ## DW_FORM_flag_present
86+
.byte 73 ## DW_AT_type
87+
.byte 19 ## DW_FORM_ref4
88+
.byte 63 ## DW_AT_external
89+
.byte 25 ## DW_FORM_flag_present
90+
.ascii "\341\177" ## DW_AT_APPLE_optimized
91+
.byte 25 ## DW_FORM_flag_present
92+
.byte 0 ## EOM(1)
93+
.byte 0 ## EOM(2)
94+
.byte 3 ## Abbreviation Code
95+
.byte 5 ## DW_TAG_formal_parameter
96+
.byte 0 ## DW_CHILDREN_no
97+
.byte 2 ## DW_AT_location
98+
.byte 24 ## DW_FORM_exprloc
99+
.byte 3 ## DW_AT_name
100+
.byte 37 ## DW_FORM_strx1
101+
.byte 58 ## DW_AT_decl_file
102+
.byte 11 ## DW_FORM_data1
103+
.byte 59 ## DW_AT_decl_line
104+
.byte 11 ## DW_FORM_data1
105+
.byte 73 ## DW_AT_type
106+
.byte 19 ## DW_FORM_ref4
107+
.byte 0 ## EOM(1)
108+
.byte 0 ## EOM(2)
109+
.byte 4 ## Abbreviation Code
110+
.byte 36 ## DW_TAG_base_type
111+
.byte 0 ## DW_CHILDREN_no
112+
.byte 3 ## DW_AT_name
113+
.byte 37 ## DW_FORM_strx1
114+
.byte 62 ## DW_AT_encoding
115+
.byte 11 ## DW_FORM_data1
116+
.byte 11 ## DW_AT_byte_size
117+
.byte 11 ## DW_FORM_data1
118+
.byte 0 ## EOM(1)
119+
.byte 0 ## EOM(2)
120+
.byte 5 ## Abbreviation Code
121+
.byte 15 ## DW_TAG_pointer_type
122+
.byte 0 ## DW_CHILDREN_no
123+
.byte 73 ## DW_AT_type
124+
.byte 19 ## DW_FORM_ref4
125+
.byte 0 ## EOM(1)
126+
.byte 0 ## EOM(2)
127+
.byte 0 ## EOM(3)
128+
.section __DWARF,__debug_info,regular,debug
129+
Lsection_info:
130+
Lcu_begin0:
131+
.set Lset0, Ldebug_info_end0-Ldebug_info_start0 ## Length of Unit
132+
.long Lset0
133+
Ldebug_info_start0:
134+
.short 5 ## DWARF version number
135+
.byte 1 ## DWARF Unit Type
136+
.byte 8 ## Address Size (in bytes)
137+
.set Lset1, Lsection_abbrev-Lsection_abbrev ## Offset Into Abbrev. Section
138+
.long Lset1
139+
.byte 1 ## Abbrev [1] 0xc:0x50 DW_TAG_compile_unit
140+
.byte 0 ## DW_AT_producer
141+
.short 29 ## DW_AT_language
142+
.byte 1 ## DW_AT_name
143+
.byte 2 ## DW_AT_LLVM_sysroot
144+
.byte 3 ## DW_AT_APPLE_sdk
145+
.set Lset2, Lstr_offsets_base0-Lsection_str_off ## DW_AT_str_offsets_base
146+
.long Lset2
147+
.set Lset3, Lline_table_start0-Lsection_line ## DW_AT_stmt_list
148+
.long Lset3
149+
.byte 4 ## DW_AT_comp_dir
150+
## DW_AT_APPLE_optimized
151+
.byte 0 ## DW_AT_low_pc
152+
.set Lset4, Lfunc_end0-Lfunc_begin0 ## DW_AT_high_pc
153+
.long Lset4
154+
.set Lset5, Laddr_table_base0-Lsection_info0 ## DW_AT_addr_base
155+
.long Lset5
156+
.byte 2 ## Abbrev [2] 0x25:0x24 DW_TAG_subprogram
157+
.byte 0 ## DW_AT_low_pc
158+
.set Lset6, Lfunc_end0-Lfunc_begin0 ## DW_AT_high_pc
159+
.long Lset6
160+
.byte 1 ## DW_AT_frame_base
161+
.byte 86
162+
## DW_AT_call_all_calls
163+
.byte 5 ## DW_AT_name
164+
.byte 0 ## DW_AT_decl_file
165+
.byte 1 ## DW_AT_decl_line
166+
## DW_AT_prototyped
167+
.long 73 ## DW_AT_type
168+
## DW_AT_external
169+
## DW_AT_APPLE_optimized
170+
.byte 3 ## Abbrev [3] 0x34:0xa DW_TAG_formal_parameter
171+
.byte 1 ## DW_AT_location
172+
.byte 85
173+
.byte 7 ## DW_AT_name
174+
.byte 0 ## DW_AT_decl_file
175+
.byte 1 ## DW_AT_decl_line
176+
.long 73 ## DW_AT_type
177+
.byte 3 ## Abbrev [3] 0x3e:0xa DW_TAG_formal_parameter
178+
.byte 1 ## DW_AT_location
179+
.byte 84
180+
.byte 8 ## DW_AT_name
181+
.byte 0 ## DW_AT_decl_file
182+
.byte 1 ## DW_AT_decl_line
183+
.long 77 ## DW_AT_type
184+
.byte 0 ## End Of Children Mark
185+
.byte 4 ## Abbrev [4] 0x49:0x4 DW_TAG_base_type
186+
.byte 6 ## DW_AT_name
187+
.byte 5 ## DW_AT_encoding
188+
.byte 4 ## DW_AT_byte_size
189+
.byte 5 ## Abbrev [5] 0x4d:0x5 DW_TAG_pointer_type
190+
.long 82 ## DW_AT_type
191+
.byte 5 ## Abbrev [5] 0x52:0x5 DW_TAG_pointer_type
192+
.long 87 ## DW_AT_type
193+
.byte 4 ## Abbrev [4] 0x57:0x4 DW_TAG_base_type
194+
.byte 9 ## DW_AT_name
195+
.byte 6 ## DW_AT_encoding
196+
.byte 1 ## DW_AT_byte_size
197+
.byte 0 ## End Of Children Mark
198+
Ldebug_info_end0:
199+
.section __DWARF,__debug_str_offs,regular,debug
200+
Lsection_str_off:
201+
.long 44 ## Length of String Offsets Set
202+
.short 5
203+
.short 0
204+
Lstr_offsets_base0:
205+
.section __DWARF,__debug_str,regular,debug
206+
Linfo_string:
207+
.asciz "Apple clang version 16.0.0 (clang-1600.0.26.3)" ## string offset=0
208+
.asciz "check-dwarf-filename.c" ## string offset=47
209+
.asciz "/Library/Developer/CommandLineTools/SDKs/MacOSX15.0.sdk" ## string offset=70
210+
.asciz "MacOSX15.0.sdk" ## string offset=126
211+
.asciz "/Users/lhames/Projects/scratch" ## string offset=141
212+
.asciz "main" ## string offset=172
213+
.asciz "int" ## string offset=177
214+
.asciz "argc" ## string offset=181
215+
.asciz "argv" ## string offset=186
216+
.asciz "char" ## string offset=191
217+
.section __DWARF,__debug_str_offs,regular,debug
218+
.long 0
219+
.long 47
220+
.long 70
221+
.long 126
222+
.long 141
223+
.long 172
224+
.long 177
225+
.long 181
226+
.long 186
227+
.long 191
228+
.section __DWARF,__debug_addr,regular,debug
229+
Lsection_info0:
230+
.set Lset7, Ldebug_addr_end0-Ldebug_addr_start0 ## Length of contribution
231+
.long Lset7
232+
Ldebug_addr_start0:
233+
.short 5 ## DWARF version number
234+
.byte 8 ## Address size
235+
.byte 0 ## Segment selector size
236+
Laddr_table_base0:
237+
.quad Lfunc_begin0
238+
Ldebug_addr_end0:
239+
.section __DWARF,__debug_names,regular,debug
240+
Ldebug_names_begin:
241+
.set Lset8, Lnames_end0-Lnames_start0 ## Header: unit length
242+
.long Lset8
243+
Lnames_start0:
244+
.short 5 ## Header: version
245+
.short 0 ## Header: padding
246+
.long 1 ## Header: compilation unit count
247+
.long 0 ## Header: local type unit count
248+
.long 0 ## Header: foreign type unit count
249+
.long 3 ## Header: bucket count
250+
.long 3 ## Header: name count
251+
.set Lset9, Lnames_abbrev_end0-Lnames_abbrev_start0 ## Header: abbreviation table size
252+
.long Lset9
253+
.long 8 ## Header: augmentation string size
254+
.ascii "LLVM0700" ## Header: augmentation string
255+
.set Lset10, Lcu_begin0-Lsection_info ## Compilation unit 0
256+
.long Lset10
257+
.long 0 ## Bucket 0
258+
.long 1 ## Bucket 1
259+
.long 2 ## Bucket 2
260+
.long 2090499946 ## Hash in Bucket 1
261+
.long 193495088 ## Hash in Bucket 2
262+
.long 2090147939 ## Hash in Bucket 2
263+
.long 172 ## String in Bucket 1: main
264+
.long 177 ## String in Bucket 2: int
265+
.long 191 ## String in Bucket 2: char
266+
.set Lset11, Lnames0-Lnames_entries0 ## Offset in Bucket 1
267+
.long Lset11
268+
.set Lset12, Lnames1-Lnames_entries0 ## Offset in Bucket 2
269+
.long Lset12
270+
.set Lset13, Lnames2-Lnames_entries0 ## Offset in Bucket 2
271+
.long Lset13
272+
Lnames_abbrev_start0:
273+
.ascii "\230." ## Abbrev code
274+
.byte 46 ## DW_TAG_subprogram
275+
.byte 3 ## DW_IDX_die_offset
276+
.byte 19 ## DW_FORM_ref4
277+
.byte 4 ## DW_IDX_parent
278+
.byte 25 ## DW_FORM_flag_present
279+
.byte 0 ## End of abbrev
280+
.byte 0 ## End of abbrev
281+
.ascii "\230$" ## Abbrev code
282+
.byte 36 ## DW_TAG_base_type
283+
.byte 3 ## DW_IDX_die_offset
284+
.byte 19 ## DW_FORM_ref4
285+
.byte 4 ## DW_IDX_parent
286+
.byte 25 ## DW_FORM_flag_present
287+
.byte 0 ## End of abbrev
288+
.byte 0 ## End of abbrev
289+
.byte 0 ## End of abbrev list
290+
Lnames_abbrev_end0:
291+
Lnames_entries0:
292+
Lnames0:
293+
L1:
294+
.ascii "\230." ## Abbreviation code
295+
.long 37 ## DW_IDX_die_offset
296+
.byte 0 ## DW_IDX_parent
297+
## End of list: main
298+
Lnames1:
299+
L0:
300+
.ascii "\230$" ## Abbreviation code
301+
.long 73 ## DW_IDX_die_offset
302+
.byte 0 ## DW_IDX_parent
303+
## End of list: int
304+
Lnames2:
305+
L2:
306+
.ascii "\230$" ## Abbreviation code
307+
.long 87 ## DW_IDX_die_offset
308+
.byte 0 ## DW_IDX_parent
309+
## End of list: char
310+
.p2align 2, 0x0
311+
Lnames_end0:
312+
.subsections_via_symbols
313+
.section __DWARF,__debug_line,regular,debug
314+
Lsection_line:
315+
Lline_table_start0:

0 commit comments

Comments
 (0)