Skip to content

Add some tests for debug info behavior #24650

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 18 additions & 14 deletions test/test_other.py
Original file line number Diff line number Diff line change
Expand Up @@ -3162,6 +3162,7 @@ def test_dwarf_sourcemap_names(self):
(['-g2', '-gsource-map'], False, True, True),
(['-gsplit-dwarf', '-gsource-map'], True, True, True),
(['-gsource-map', '-sWASM_BIGINT', '-sERROR_ON_WASM_CHANGES_AFTER_LINK'], False, True, True),
(['-Oz', '-gsource-map'], False, True, True),
]:
print(flags, expect_dwarf, expect_sourcemap, expect_names)
self.emcc(test_file(source_file), flags, js_file)
Expand Down Expand Up @@ -9198,21 +9199,24 @@ def test_ctor_ordering(self, args):
# test debug info and debuggability of JS output
@crossplatform
def test_binaryen_debug(self):
for args, expect_emit_text, expect_clean_js, expect_whitespace_js, expect_closured in [
(['-O0'], False, False, True, False),
(['-O0', '-g1'], False, False, True, False),
(['-O0', '-g2'], False, False, True, False), # in -g2+, we emit -g to asm2wasm so function names are saved
(['-O0', '-g'], True, False, True, False),
(['-O0', '--profiling-funcs'], False, False, True, False),
(['-O1'], False, False, True, False),
(['-O2'], False, True, False, False),
(['-O2', '-gz'], False, True, False, False), # -gz means debug compression, it should not enable debugging
(['-O2', '-g1'], False, False, True, False),
(['-O2', '-g'], True, False, True, False),
(['-O2', '--closure=1'], False, True, False, True),
(['-O2', '--closure=1', '-g1'], False, True, True, True),
for args, expect_clean_js, expect_whitespace_js, expect_closured in [
(['-O0'], False, True, False),
(['-O0', '-g1'], False, True, False),
(['-O0', '-g2'], False, True, False), # in -g2+, we emit -g to asm2wasm so function names are saved
(['-O0', '-g'], False, True, False),
(['-O0', '--profiling-funcs'], False, True, False),
(['-O0', '-gline-tables-only'], False, True, False),
(['-O1'], False, True, False),
(['-O3'], True, False, False),
(['-Oz', '-gsource-map'], False, True, False), # TODO: fix this (#20462)
(['-O2'], True, False, False),
(['-O2', '-gz'], True, False, False), # -gz means debug compression, it should not enable debugging
(['-O2', '-g1'], False, True, False),
(['-O2', '-g'], False, True, False),
(['-O2', '--closure=1'], True, False, True),
(['-O2', '--closure=1', '-g1'], True, True, True),
]:
print(args, expect_emit_text, expect_clean_js, expect_whitespace_js, expect_closured)
print(args, expect_clean_js, expect_whitespace_js, expect_closured)
delete_file('a.out.wat')
cmd = [EMCC, test_file('hello_world.c')] + args
print(' '.join(cmd))
Expand Down
8 changes: 5 additions & 3 deletions tools/building.py
Original file line number Diff line number Diff line change
Expand Up @@ -163,9 +163,11 @@ def lld_flags_for_executable(external_symbols):
# wasm-ld can strip debug info for us. this strips both the Names
# section and DWARF, so we can only use it when we don't need any of
# those things.
if settings.DEBUG_LEVEL < 2 and (not settings.EMIT_SYMBOL_MAP and
not settings.EMIT_NAME_SECTION and
not settings.ASYNCIFY):
if (not settings.GENERATE_DWARF and
not settings.EMIT_SYMBOL_MAP and
not settings.GENERATE_SOURCE_MAP and
not settings.EMIT_NAME_SECTION and
not settings.ASYNCIFY):
cmd.append('--strip-debug')

if settings.LINKABLE:
Expand Down
1 change: 1 addition & 0 deletions tools/cmdline.py
Original file line number Diff line number Diff line change
Expand Up @@ -409,6 +409,7 @@ def consume_arg_file():
settings.EMIT_NAME_SECTION = 1
# In all cases set the emscripten debug level to 3 so that we do not
# strip during link (during compile, this does not make a difference).
# TODO: possibly decouple some of these flags from the final debug level (#20462)
settings.DEBUG_LEVEL = 3
elif check_flag('-profiling') or check_flag('--profiling'):
settings.DEBUG_LEVEL = max(settings.DEBUG_LEVEL, 2)
Expand Down
2 changes: 1 addition & 1 deletion tools/link.py
Original file line number Diff line number Diff line change
Expand Up @@ -2419,7 +2419,7 @@ def phase_binaryen(target, options, wasm_target):
building.handle_final_wasm_symbols(wasm_file=wasm_target, symbols_file=symbols_file, debug_info=intermediate_debug_info)
save_intermediate_with_wasm('symbolmap', wasm_target)

if settings.DEBUG_LEVEL >= 3 and settings.SEPARATE_DWARF and generating_wasm:
if settings.GENERATE_DWARF and settings.SEPARATE_DWARF and generating_wasm:
# if the dwarf filename wasn't provided, use the default target + a suffix
wasm_file_with_dwarf = settings.SEPARATE_DWARF
if wasm_file_with_dwarf is True:
Expand Down
Loading