Skip to content

Commit 4d04c22

Browse files
authored
[DWARF] Add handling for DW_LNS_set_epilogue_begin (#8414)
Fixes ``` Fatal: unknown debug line opcode: b ``` Code is similar to DW_LNS_set_prologue_end. The test binary is a modified version of the binary used for the existing test for prologue end too.
1 parent 85c606b commit 4d04c22

File tree

4 files changed

+251
-3
lines changed

4 files changed

+251
-3
lines changed

src/wasm/wasm-debug.cpp

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,10 @@ struct LineState {
195195
prologueEnd = true;
196196
break;
197197
}
198+
case llvm::dwarf::DW_LNS_set_epilogue_begin: {
199+
epilogueBegin = true;
200+
break;
201+
}
198202
case llvm::dwarf::DW_LNS_copy: {
199203
return true;
200204
}
@@ -331,8 +335,8 @@ struct LineState {
331335
if (prologueEnd) {
332336
newOpcodes.push_back(makeItem(llvm::dwarf::DW_LNS_set_prologue_end));
333337
}
334-
if (epilogueBegin != old.epilogueBegin) {
335-
Fatal() << "eb";
338+
if (epilogueBegin) {
339+
newOpcodes.push_back(makeItem(llvm::dwarf::DW_LNS_set_epilogue_begin));
336340
}
337341
if (useSpecial) {
338342
// Emit a special, which emits a line automatically.
@@ -349,7 +353,10 @@ struct LineState {
349353
}
350354

351355
// Some flags are automatically reset after each debug line.
352-
void resetAfterLine() { prologueEnd = false; }
356+
void resetAfterLine() {
357+
prologueEnd = false;
358+
epilogueBegin = false;
359+
}
353360

354361
private:
355362
llvm::DWARFYAML::LineTableOpcode
Lines changed: 240 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,240 @@
1+
DWARF debug info
2+
================
3+
4+
Contains section .debug_info (58 bytes)
5+
Contains section .debug_abbrev (39 bytes)
6+
Contains section .debug_line (57 bytes)
7+
Contains section .debug_str (212 bytes)
8+
9+
.debug_abbrev contents:
10+
Abbrev table for offset: 0x00000000
11+
[1] DW_TAG_compile_unit DW_CHILDREN_yes
12+
DW_AT_producer DW_FORM_strp
13+
DW_AT_language DW_FORM_data2
14+
DW_AT_name DW_FORM_strp
15+
DW_AT_stmt_list DW_FORM_sec_offset
16+
DW_AT_comp_dir DW_FORM_strp
17+
DW_AT_low_pc DW_FORM_addr
18+
DW_AT_high_pc DW_FORM_data4
19+
20+
[2] DW_TAG_subprogram DW_CHILDREN_no
21+
DW_AT_low_pc DW_FORM_addr
22+
DW_AT_high_pc DW_FORM_data4
23+
DW_AT_linkage_name DW_FORM_strp
24+
DW_AT_name DW_FORM_strp
25+
DW_AT_decl_file DW_FORM_data1
26+
DW_AT_decl_line DW_FORM_data1
27+
DW_AT_external DW_FORM_flag_present
28+
29+
30+
.debug_info contents:
31+
0x00000000: Compile Unit: length = 0x00000036 version = 0x0004 abbr_offset = 0x0000 addr_size = 0x04 (next unit at 0x0000003a)
32+
33+
0x0000000b: DW_TAG_compile_unit [1] *
34+
DW_AT_producer [DW_FORM_strp] ( .debug_str[0x00000000] = "clang version 10.0.0 (/b/s/w/ir/cache/git/chromium.googlesource.com-external-github.com-llvm-llvm--project f2e65447b3cb6340883957e033e77095a025ebdc)")
35+
DW_AT_language [DW_FORM_data2] (DW_LANG_C_plus_plus)
36+
DW_AT_name [DW_FORM_strp] ( .debug_str[0x00000095] = "a.cpp")
37+
DW_AT_stmt_list [DW_FORM_sec_offset] (0x00000000)
38+
DW_AT_comp_dir [DW_FORM_strp] ( .debug_str[0x0000009b] = "/usr/local/google/home/azakai/Dev/emscripten")
39+
DW_AT_low_pc [DW_FORM_addr] (0x0000000000000005)
40+
DW_AT_high_pc [DW_FORM_data4] (0x00000002)
41+
42+
0x00000026: DW_TAG_subprogram [2]
43+
DW_AT_low_pc [DW_FORM_addr] (0x0000000000000005)
44+
DW_AT_high_pc [DW_FORM_data4] (0x00000002)
45+
DW_AT_linkage_name [DW_FORM_strp] ( .debug_str[0x000000c8] = "_Z3foov")
46+
DW_AT_name [DW_FORM_strp] ( .debug_str[0x000000d0] = "foo")
47+
DW_AT_decl_file [DW_FORM_data1] ("/usr/local/google/home/azakai/Dev/emscripten/a.cpp")
48+
DW_AT_decl_line [DW_FORM_data1] (3)
49+
DW_AT_external [DW_FORM_flag_present] (true)
50+
51+
0x00000039: NULL
52+
53+
.debug_line contents:
54+
debug_line[0x00000000]
55+
Line table prologue:
56+
total_length: 0x00000035
57+
version: 4
58+
prologue_length: 0x0000001d
59+
min_inst_length: 1
60+
max_ops_per_inst: 1
61+
default_is_stmt: 1
62+
line_base: -5
63+
line_range: 14
64+
opcode_base: 13
65+
standard_opcode_lengths[DW_LNS_copy] = 0
66+
standard_opcode_lengths[DW_LNS_advance_pc] = 1
67+
standard_opcode_lengths[DW_LNS_advance_line] = 1
68+
standard_opcode_lengths[DW_LNS_set_file] = 1
69+
standard_opcode_lengths[DW_LNS_set_column] = 1
70+
standard_opcode_lengths[DW_LNS_negate_stmt] = 0
71+
standard_opcode_lengths[DW_LNS_set_basic_block] = 0
72+
standard_opcode_lengths[DW_LNS_const_add_pc] = 0
73+
standard_opcode_lengths[DW_LNS_fixed_advance_pc] = 1
74+
standard_opcode_lengths[DW_LNS_set_prologue_end] = 0
75+
standard_opcode_lengths[DW_LNS_set_epilogue_begin] = 0
76+
standard_opcode_lengths[DW_LNS_set_isa] = 1
77+
file_names[ 1]:
78+
name: "a.cpp"
79+
dir_index: 0
80+
mod_time: 0x00000000
81+
length: 0x00000000
82+
0x00000027: 00 DW_LNE_set_address (0x0000000000000005)
83+
0x0000002e: 14 address += 0, line += 2
84+
0x0000000000000005 3 0 1 0 0 is_stmt
85+
86+
0x0000002f: 05 DW_LNS_set_column (1)
87+
0x00000031: 0a DW_LNS_set_prologue_end
88+
0x00000032: 0b DW_LNS_set_epilogue_begin
89+
0x00000033: 21 address += 1, line += 1
90+
0x0000000000000006 4 1 1 0 0 is_stmt prologue_end epilogue_begin
91+
92+
0x00000034: 02 DW_LNS_advance_pc (1)
93+
0x00000036: 00 DW_LNE_end_sequence
94+
0x0000000000000007 4 1 1 0 0 is_stmt end_sequence
95+
96+
97+
.debug_str contents:
98+
0x00000000: "clang version 10.0.0 (/b/s/w/ir/cache/git/chromium.googlesource.com-external-github.com-llvm-llvm--project f2e65447b3cb6340883957e033e77095a025ebdc)"
99+
0x00000095: "a.cpp"
100+
0x0000009b: "/usr/local/google/home/azakai/Dev/emscripten"
101+
0x000000c8: "_Z3foov"
102+
0x000000d0: "foo"
103+
DWARF debug info
104+
================
105+
106+
Contains section .debug_info (58 bytes)
107+
Contains section .debug_abbrev (39 bytes)
108+
Contains section .debug_line (63 bytes)
109+
Contains section .debug_str (212 bytes)
110+
111+
.debug_abbrev contents:
112+
Abbrev table for offset: 0x00000000
113+
[1] DW_TAG_compile_unit DW_CHILDREN_yes
114+
DW_AT_producer DW_FORM_strp
115+
DW_AT_language DW_FORM_data2
116+
DW_AT_name DW_FORM_strp
117+
DW_AT_stmt_list DW_FORM_sec_offset
118+
DW_AT_comp_dir DW_FORM_strp
119+
DW_AT_low_pc DW_FORM_addr
120+
DW_AT_high_pc DW_FORM_data4
121+
122+
[2] DW_TAG_subprogram DW_CHILDREN_no
123+
DW_AT_low_pc DW_FORM_addr
124+
DW_AT_high_pc DW_FORM_data4
125+
DW_AT_linkage_name DW_FORM_strp
126+
DW_AT_name DW_FORM_strp
127+
DW_AT_decl_file DW_FORM_data1
128+
DW_AT_decl_line DW_FORM_data1
129+
DW_AT_external DW_FORM_flag_present
130+
131+
132+
.debug_info contents:
133+
0x00000000: Compile Unit: length = 0x00000036 version = 0x0004 abbr_offset = 0x0000 addr_size = 0x04 (next unit at 0x0000003a)
134+
135+
0x0000000b: DW_TAG_compile_unit [1] *
136+
DW_AT_producer [DW_FORM_strp] ( .debug_str[0x00000000] = "clang version 10.0.0 (/b/s/w/ir/cache/git/chromium.googlesource.com-external-github.com-llvm-llvm--project f2e65447b3cb6340883957e033e77095a025ebdc)")
137+
DW_AT_language [DW_FORM_data2] (DW_LANG_C_plus_plus)
138+
DW_AT_name [DW_FORM_strp] ( .debug_str[0x00000095] = "a.cpp")
139+
DW_AT_stmt_list [DW_FORM_sec_offset] (0x00000000)
140+
DW_AT_comp_dir [DW_FORM_strp] ( .debug_str[0x0000009b] = "/usr/local/google/home/azakai/Dev/emscripten")
141+
DW_AT_low_pc [DW_FORM_addr] (0x0000000000000000)
142+
DW_AT_high_pc [DW_FORM_data4] (0x00000007)
143+
144+
0x00000026: DW_TAG_subprogram [2]
145+
DW_AT_low_pc [DW_FORM_addr] (0x0000000000000000)
146+
DW_AT_high_pc [DW_FORM_data4] (0x00000007)
147+
DW_AT_linkage_name [DW_FORM_strp] ( .debug_str[0x000000c8] = "_Z3foov")
148+
DW_AT_name [DW_FORM_strp] ( .debug_str[0x000000d0] = "foo")
149+
DW_AT_decl_file [DW_FORM_data1] ("/usr/local/google/home/azakai/Dev/emscripten/a.cpp")
150+
DW_AT_decl_line [DW_FORM_data1] (3)
151+
DW_AT_external [DW_FORM_flag_present] (true)
152+
153+
0x00000039: NULL
154+
155+
.debug_line contents:
156+
debug_line[0x00000000]
157+
Line table prologue:
158+
total_length: 0x0000003b
159+
version: 4
160+
prologue_length: 0x0000001d
161+
min_inst_length: 1
162+
max_ops_per_inst: 1
163+
default_is_stmt: 1
164+
line_base: -5
165+
line_range: 14
166+
opcode_base: 13
167+
standard_opcode_lengths[DW_LNS_copy] = 0
168+
standard_opcode_lengths[DW_LNS_advance_pc] = 1
169+
standard_opcode_lengths[DW_LNS_advance_line] = 1
170+
standard_opcode_lengths[DW_LNS_set_file] = 1
171+
standard_opcode_lengths[DW_LNS_set_column] = 1
172+
standard_opcode_lengths[DW_LNS_negate_stmt] = 0
173+
standard_opcode_lengths[DW_LNS_set_basic_block] = 0
174+
standard_opcode_lengths[DW_LNS_const_add_pc] = 0
175+
standard_opcode_lengths[DW_LNS_fixed_advance_pc] = 1
176+
standard_opcode_lengths[DW_LNS_set_prologue_end] = 0
177+
standard_opcode_lengths[DW_LNS_set_epilogue_begin] = 0
178+
standard_opcode_lengths[DW_LNS_set_isa] = 1
179+
file_names[ 1]:
180+
name: "a.cpp"
181+
dir_index: 0
182+
mod_time: 0x00000000
183+
length: 0x00000000
184+
0x00000027: 00 DW_LNE_set_address (0x0000000000000006)
185+
0x0000002e: 03 DW_LNS_advance_line (4)
186+
0x00000030: 05 DW_LNS_set_column (1)
187+
0x00000032: 0a DW_LNS_set_prologue_end
188+
0x00000033: 0b DW_LNS_set_epilogue_begin
189+
0x00000034: 01 DW_LNS_copy
190+
0x0000000000000006 4 1 1 0 0 is_stmt prologue_end epilogue_begin
191+
192+
193+
0x00000035: 00 DW_LNE_set_address (0x0000000000000007)
194+
0x0000003c: 00 DW_LNE_end_sequence
195+
0x0000000000000007 4 1 1 0 0 is_stmt end_sequence
196+
197+
198+
.debug_str contents:
199+
0x00000000: "clang version 10.0.0 (/b/s/w/ir/cache/git/chromium.googlesource.com-external-github.com-llvm-llvm--project f2e65447b3cb6340883957e033e77095a025ebdc)"
200+
0x00000095: "a.cpp"
201+
0x0000009b: "/usr/local/google/home/azakai/Dev/emscripten"
202+
0x000000c8: "_Z3foov"
203+
0x000000d0: "foo"
204+
(module
205+
(type $0 (func (param i32) (result i32)))
206+
(type $1 (func (param i32)))
207+
(type $2 (func (result i32)))
208+
(type $3 (func))
209+
(type $4 (func (param i32 i32)))
210+
(import "env" "__wasm_call_ctors" (func $fimport$0))
211+
(import "env" "dlmalloc" (func $fimport$1 (param i32) (result i32)))
212+
(import "env" "dlfree" (func $fimport$2 (param i32)))
213+
(import "env" "setThrew" (func $fimport$3 (param i32 i32)))
214+
(import "env" "stackSave" (func $fimport$4 (result i32)))
215+
(import "env" "stackAlloc" (func $fimport$5 (param i32) (result i32)))
216+
(import "env" "stackRestore" (func $fimport$6 (param i32)))
217+
(import "env" "__growWasmMemory" (func $fimport$7 (param i32) (result i32)))
218+
(global $global$0 i32 (i32.const 1532))
219+
(export "__wasm_call_ctors" (func $fimport$0))
220+
(export "_Z3foov" (func $fimport$0))
221+
(export "__errno_location" (func $0))
222+
(export "setThrew" (func $fimport$3))
223+
(export "malloc" (func $fimport$1))
224+
(export "free" (func $fimport$2))
225+
(export "__data_end" (global $global$0))
226+
(export "stackSave" (func $fimport$4))
227+
(export "stackAlloc" (func $fimport$5))
228+
(export "stackRestore" (func $fimport$6))
229+
(export "__growWasmMemory" (func $fimport$7))
230+
(func $0 (result i32)
231+
;; code offset: 0x3
232+
(i32.const 1024)
233+
)
234+
;; custom section "sourceMappingURL", size 15
235+
;; custom section "sourceMappingURL", size 15
236+
;; custom section ".debug_info", size 58
237+
;; custom section ".debug_abbrev", size 39
238+
;; custom section ".debug_line", size 63
239+
;; custom section ".debug_str", size 212
240+
)
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
g_dwarfdump_roundtrip_dwarfdump
844 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)