From efd9a7d0d5c11311825afc0559887c94c076a659 Mon Sep 17 00:00:00 2001 From: Derek Schuff Date: Thu, 3 Jul 2025 01:10:59 +0000 Subject: [PATCH] Add some tests for debug info behavior 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. --- test/test_other.py | 32 ++++++++++++++++++-------------- tools/building.py | 8 +++++--- tools/cmdline.py | 1 + tools/link.py | 2 +- 4 files changed, 25 insertions(+), 18 deletions(-) diff --git a/test/test_other.py b/test/test_other.py index 4ce2b8b3960a1..5c85b1528f49a 100644 --- a/test/test_other.py +++ b/test/test_other.py @@ -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) @@ -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)) diff --git a/tools/building.py b/tools/building.py index 2939139ada5ef..7f908267e08bc 100644 --- a/tools/building.py +++ b/tools/building.py @@ -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: diff --git a/tools/cmdline.py b/tools/cmdline.py index 9df7ef4fc6526..75faceab3ea64 100644 --- a/tools/cmdline.py +++ b/tools/cmdline.py @@ -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) diff --git a/tools/link.py b/tools/link.py index f47c41b25c3a9..6b261446463f3 100644 --- a/tools/link.py +++ b/tools/link.py @@ -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: