Skip to content

Commit a524013

Browse files
authored
Add some tests for debug info behavior (#24650)
In particular, the behavior being discussed in #20462 Also decouple settings.DEBUG_LEVEL (which is the final debug level output) from cases where we just need e.g. intermediate DWARF. This will hopefully make cases like "full optimizations + source maps" more clear.
1 parent 3886466 commit a524013

File tree

4 files changed

+25
-18
lines changed

4 files changed

+25
-18
lines changed

test/test_other.py

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3156,6 +3156,7 @@ def test_dwarf_sourcemap_names(self):
31563156
(['-g2', '-gsource-map'], False, True, True),
31573157
(['-gsplit-dwarf', '-gsource-map'], True, True, True),
31583158
(['-gsource-map', '-sERROR_ON_WASM_CHANGES_AFTER_LINK'], False, True, True),
3159+
(['-Oz', '-gsource-map'], False, True, True),
31593160
]:
31603161
print(flags, expect_dwarf, expect_sourcemap, expect_names)
31613162
self.emcc(test_file(source_file), flags, js_file)
@@ -9190,21 +9191,24 @@ def test_ctor_ordering(self, args):
91909191
# test debug info and debuggability of JS output
91919192
@crossplatform
91929193
def test_binaryen_debug(self):
9193-
for args, expect_emit_text, expect_clean_js, expect_whitespace_js, expect_closured in [
9194-
(['-O0'], False, False, True, False),
9195-
(['-O0', '-g1'], False, False, True, False),
9196-
(['-O0', '-g2'], False, False, True, False), # in -g2+, we emit -g to asm2wasm so function names are saved
9197-
(['-O0', '-g'], True, False, True, False),
9198-
(['-O0', '--profiling-funcs'], False, False, True, False),
9199-
(['-O1'], False, False, True, False),
9200-
(['-O2'], False, True, False, False),
9201-
(['-O2', '-gz'], False, True, False, False), # -gz means debug compression, it should not enable debugging
9202-
(['-O2', '-g1'], False, False, True, False),
9203-
(['-O2', '-g'], True, False, True, False),
9204-
(['-O2', '--closure=1'], False, True, False, True),
9205-
(['-O2', '--closure=1', '-g1'], False, True, True, True),
9194+
for args, expect_clean_js, expect_whitespace_js, expect_closured in [
9195+
(['-O0'], False, True, False),
9196+
(['-O0', '-g1'], False, True, False),
9197+
(['-O0', '-g2'], False, True, False), # in -g2+, we emit -g to asm2wasm so function names are saved
9198+
(['-O0', '-g'], False, True, False),
9199+
(['-O0', '--profiling-funcs'], False, True, False),
9200+
(['-O0', '-gline-tables-only'], False, True, False),
9201+
(['-O1'], False, True, False),
9202+
(['-O3'], True, False, False),
9203+
(['-Oz', '-gsource-map'], False, True, False), # TODO: fix this (#20462)
9204+
(['-O2'], True, False, False),
9205+
(['-O2', '-gz'], True, False, False), # -gz means debug compression, it should not enable debugging
9206+
(['-O2', '-g1'], False, True, False),
9207+
(['-O2', '-g'], False, True, False),
9208+
(['-O2', '--closure=1'], True, False, True),
9209+
(['-O2', '--closure=1', '-g1'], True, True, True),
92069210
]:
9207-
print(args, expect_emit_text, expect_clean_js, expect_whitespace_js, expect_closured)
9211+
print(args, expect_clean_js, expect_whitespace_js, expect_closured)
92089212
delete_file('a.out.wat')
92099213
cmd = [EMCC, test_file('hello_world.c')] + args
92109214
print(' '.join(cmd))

tools/building.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -163,9 +163,11 @@ def lld_flags_for_executable(external_symbols):
163163
# wasm-ld can strip debug info for us. this strips both the Names
164164
# section and DWARF, so we can only use it when we don't need any of
165165
# those things.
166-
if settings.DEBUG_LEVEL < 2 and (not settings.EMIT_SYMBOL_MAP and
167-
not settings.EMIT_NAME_SECTION and
168-
not settings.ASYNCIFY):
166+
if (not settings.GENERATE_DWARF and
167+
not settings.EMIT_SYMBOL_MAP and
168+
not settings.GENERATE_SOURCE_MAP and
169+
not settings.EMIT_NAME_SECTION and
170+
not settings.ASYNCIFY):
169171
cmd.append('--strip-debug')
170172

171173
if settings.LINKABLE:

tools/cmdline.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -409,6 +409,7 @@ def consume_arg_file():
409409
settings.EMIT_NAME_SECTION = 1
410410
# In all cases set the emscripten debug level to 3 so that we do not
411411
# strip during link (during compile, this does not make a difference).
412+
# TODO: possibly decouple some of these flags from the final debug level (#20462)
412413
settings.DEBUG_LEVEL = 3
413414
elif check_flag('-profiling') or check_flag('--profiling'):
414415
settings.DEBUG_LEVEL = max(settings.DEBUG_LEVEL, 2)

tools/link.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2411,7 +2411,7 @@ def phase_binaryen(target, options, wasm_target):
24112411
building.handle_final_wasm_symbols(wasm_file=wasm_target, symbols_file=symbols_file, debug_info=intermediate_debug_info)
24122412
save_intermediate_with_wasm('symbolmap', wasm_target)
24132413

2414-
if settings.DEBUG_LEVEL >= 3 and settings.SEPARATE_DWARF and generating_wasm:
2414+
if settings.GENERATE_DWARF and settings.SEPARATE_DWARF and generating_wasm:
24152415
# if the dwarf filename wasn't provided, use the default target + a suffix
24162416
wasm_file_with_dwarf = settings.SEPARATE_DWARF
24172417
if wasm_file_with_dwarf is True:

0 commit comments

Comments
 (0)