Skip to content

Commit bcc2cf4

Browse files
authored
Split test_dwarf.c into a separate file. NFC (emscripten-core#16063)
This allows the line and column numbers used in the test to match that of an actual file under source control.
1 parent a0fbebc commit bcc2cf4

2 files changed

Lines changed: 28 additions & 27 deletions

File tree

tests/core/test_dwarf.c

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
#include <emscripten.h>
2+
3+
EM_JS(int, out_to_js, (int x), {})
4+
5+
void foo() {
6+
out_to_js(0); // line 5
7+
out_to_js(1); // line 6
8+
out_to_js(2); // line 7
9+
// A silly possible recursion to avoid binaryen doing any inlining.
10+
if (out_to_js(3)) foo();
11+
}
12+
13+
int main() {
14+
foo();
15+
}

tests/test_core.py

Lines changed: 13 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -7206,25 +7206,11 @@ def test_source_map(self, args):
72067206
def test_dwarf(self):
72077207
self.emcc_args.append('-g')
72087208

7209-
create_file('src.cpp', '''
7210-
#include <emscripten.h>
7211-
EM_JS(int, out_to_js, (int x), {})
7212-
void foo() {
7213-
out_to_js(0); // line 5
7214-
out_to_js(1); // line 6
7215-
out_to_js(2); // line 7
7216-
// A silly possible recursion to avoid binaryen doing any inlining.
7217-
if (out_to_js(3)) foo();
7218-
}
7219-
int main() {
7220-
foo();
7221-
}
7222-
''')
7223-
72247209
js_filename = 'a.out.js'
72257210
wasm_filename = 'a.out.wasm'
7211+
shutil.copyfile(test_file('core/test_dwarf.c'), 'test_dwarf.c')
72267212

7227-
self.emcc('src.cpp', self.get_emcc_args(), js_filename)
7213+
self.emcc('test_dwarf.c', self.get_emcc_args(), js_filename)
72287214

72297215
out = self.run_process([shared.LLVM_DWARFDUMP, wasm_filename, '-all'], stdout=PIPE).stdout
72307216

@@ -7257,17 +7243,17 @@ def add_section():
72577243
self.assertIn('.debug_ranges', sections)
72587244

72597245
# verify some content in the sections
7260-
self.assertIn('"src.cpp"', sections['.debug_info'])
7246+
self.assertIn('"test_dwarf.c"', sections['.debug_info'])
72617247
# the line section looks like this:
72627248
# Address Line Column File ISA Discriminator Flags
72637249
# ------------------ ------ ------ ------ --- ------------- -------------
72647250
# 0x000000000000000b 5 0 3 0 0 is_stmt
72657251
src_to_addr = {}
7266-
found_src_cpp = False
7252+
found_dwarf_c = False
72677253
for line in sections['.debug_line'].splitlines():
7268-
if 'name: "src.cpp"' in line:
7269-
found_src_cpp = True
7270-
if not found_src_cpp:
7254+
if 'name: "test_dwarf.c"' in line:
7255+
found_dwarf_c = True
7256+
if not found_dwarf_c:
72717257
continue
72727258
if 'debug_line' in line:
72737259
break
@@ -7279,9 +7265,9 @@ def add_section():
72797265
src_to_addr.setdefault(key, []).append(addr)
72807266

72817267
# each of the calls must remain in the binary, and be mapped
7282-
self.assertIn((5, 9), src_to_addr)
7283-
self.assertIn((6, 9), src_to_addr)
7284-
self.assertIn((7, 9), src_to_addr)
7268+
self.assertIn((6, 3), src_to_addr)
7269+
self.assertIn((7, 3), src_to_addr)
7270+
self.assertIn((8, 3), src_to_addr)
72857271

72867272
def get_dwarf_addr(line, col):
72877273
addrs = src_to_addr[(line, col)]
@@ -7291,8 +7277,8 @@ def get_dwarf_addr(line, col):
72917277

72927278
# the lines must appear in sequence (as calls to JS, the optimizer cannot
72937279
# reorder them)
7294-
self.assertLess(get_dwarf_addr(5, 9), get_dwarf_addr(6, 9))
7295-
self.assertLess(get_dwarf_addr(6, 9), get_dwarf_addr(7, 9))
7280+
self.assertLess(get_dwarf_addr(6, 3), get_dwarf_addr(7, 3))
7281+
self.assertLess(get_dwarf_addr(7, 3), get_dwarf_addr(8, 3))
72967282

72977283
# Get the wat, printing with -g which has binary offsets
72987284
wat = self.run_process([Path(building.get_binaryen_bin(), 'wasm-opt'),
@@ -7349,7 +7335,7 @@ def get_wat_addr(call_index):
73497335

73507336
# match up the DWARF and the wat
73517337
for i in range(3):
7352-
dwarf_addr = get_dwarf_addr(5 + i, 9)
7338+
dwarf_addr = get_dwarf_addr(6 + i, 3)
73537339
start_wat_addr, end_wat_addr = get_wat_addr(i)
73547340
# the dwarf may match any of the 3 instructions that form the stream of
73557341
# of instructions implementing the call in the source code, in theory

0 commit comments

Comments
 (0)