From 78a55b5a001c1753260cb46d041277c5fe6eada3 Mon Sep 17 00:00:00 2001 From: Alon Zakai Date: Tue, 19 Nov 2019 16:01:21 -0800 Subject: [PATCH 1/4] Support -gline-tables-only --- emcc.py | 26 +++++++++++++++++------ site/source/docs/tools_reference/emcc.rst | 4 ++-- tests/test_other.py | 25 ++++++++++++++++++++++ 3 files changed, 46 insertions(+), 9 deletions(-) diff --git a/emcc.py b/emcc.py index 3044476e05389..cb374ff7f4509 100755 --- a/emcc.py +++ b/emcc.py @@ -1891,11 +1891,8 @@ def check_human_readable_list(items): logger.debug("running (for precompiled headers): " + clang_compiler + ' ' + ' '.join(args)) return run_process([clang_compiler] + args, check=False).returncode - if need_llvm_debug_info(options): - newargs.append('-g') - # For asm.js, the generated JavaScript could preserve LLVM value names, which can be useful for debugging. - if options.debug_level >= 3 and not shared.Settings.WASM: + if options.debug_level >= 3 and not shared.Settings.WASM and not shared.Settings.WASM_BACKEND: newargs.append('-fno-discard-value-names') def is_link_flag(flag): @@ -2640,10 +2637,25 @@ def check_bad_eq(arg): newargs[i] = '' newargs[i + 1] = '' elif newargs[i].startswith('-g'): - requested_level = newargs[i][2:] or '3' - options.debug_level = validate_arg_level(requested_level, 4, 'Invalid debug level: ' + newargs[i]) options.requested_debug = newargs[i] - newargs[i] = '' + requested_level = newargs[i][2:] or '3' + if requested_level == 'line-tables-only': + # line-tables-only means function names and source positions, and no + # other debug info. keep that flag for the clang frontend to emit + # corresponding DWARF info. + # set the emscripten debug level to 3 so that we do not remove that + # debug info during link (during compile, this does not make a + # difference). + options.debug_level = 3 + else: + # the -gX value is the debug level (-g1, -g2, etc.) + options.debug_level = validate_arg_level(requested_level, 4, 'Invalid debug level: ' + newargs[i]) + # if we don't need to preserve LLVM debug info, do not keep this flag + # for clang + if options.debug_level < 3: + newargs[i] = '' + else: + newargs[i] = '-g' elif newargs[i] == '-profiling' or newargs[i] == '--profiling': options.debug_level = max(options.debug_level, 2) options.profiling = True diff --git a/site/source/docs/tools_reference/emcc.rst b/site/source/docs/tools_reference/emcc.rst index 3e9180eb35423..d6a0ff33dec3d 100644 --- a/site/source/docs/tools_reference/emcc.rst +++ b/site/source/docs/tools_reference/emcc.rst @@ -112,7 +112,7 @@ Options that are modified or new in *emcc* are listed below: Preserve debug information. - When compiling to object files, this is the same as in *Clang* and *gcc*, it adds debug information to the object files. - - When linking, this is equivalent to :ref:`-g3 ` (preserve JS whitespace and compiled function names). + - When linking, this is equivalent to :ref:`-g3 `. .. _emcc-gN: @@ -137,7 +137,7 @@ Options that are modified or new in *emcc* are listed below: - .. _emcc-g3: - ``-g3``: When compiling to object files, keep debug info (this is the same as :ref:`-g `). + ``-g3``: When compiling to object files, keep debug info, including JS whitespace, function names, and LLVM debug info if any (this is the same as :ref:`-g `). .. _emcc-g4: diff --git a/tests/test_other.py b/tests/test_other.py index 3087d825b7816..84ef521bffab6 100644 --- a/tests/test_other.py +++ b/tests/test_other.py @@ -2329,6 +2329,31 @@ def test_debuginfo(self): else: self.assertIn('strip-debug', err) + @no_fastcomp() + def test_debuginfo_line_tables_only(self): + def test(do_compile): + do_compile([]) + no_size = os.path.getsize('a.out.wasm') + do_compile(['-gline-tables-only']) + line_size = os.path.getsize('a.out.wasm') + do_compile(['-g']) + full_size = os.path.getsize('a.out.wasm') + self.assertLess(no_size, line_size) + self.assertLess(line_size, full_size) + + def compile_directly(compile_args): + run_process([PYTHON, EMCC, path_from_root('tests', 'hello_world.cpp')] + compile_args) + + test(compile_directly) + + def compile_to_object_first(compile_args): + # compile with the specified args + run_process([PYTHON, EMCC, path_from_root('tests', 'hello_world.cpp')] + compile_args + ['-c', '-o', 'a.o']) + # link with debug info + run_process([PYTHON, EMCC, 'a.o', '-g']) + + test(compile_to_object_first) + @unittest.skipIf(not scons_path, 'scons not found in PATH') @with_env_modify({'EMSCRIPTEN_ROOT': path_from_root()}) def test_scons(self): From 2aff3cef15b34854be8fb0f3b54e73314cdd4ec3 Mon Sep 17 00:00:00 2001 From: Alon Zakai Date: Tue, 19 Nov 2019 16:38:59 -0800 Subject: [PATCH 2/4] fix cyberdwarf --- emcc.py | 1 + 1 file changed, 1 insertion(+) diff --git a/emcc.py b/emcc.py index cb374ff7f4509..a7192d932d471 100755 --- a/emcc.py +++ b/emcc.py @@ -1821,6 +1821,7 @@ def check_human_readable_list(items): shared.Settings.BUNDLED_CD_DEBUG_FILE = target + ".cd" shared.Settings.SYSTEM_JS_LIBRARIES.append(shared.path_from_root('src', 'library_cyberdwarf.js')) shared.Settings.SYSTEM_JS_LIBRARIES.append(shared.path_from_root('src', 'library_debugger_toolkit.js')) + newargs.append('-g') if options.tracing: if shared.Settings.ALLOW_MEMORY_GROWTH: From 9dba571957d71fa0a5ab3660cd28593624c9c62d Mon Sep 17 00:00:00 2001 From: Alon Zakai Date: Wed, 20 Nov 2019 10:21:33 -0800 Subject: [PATCH 3/4] Support arbitrari passthrough, and limit frontend debug info to line tables --- emcc.py | 29 +++++++++++++++++++---------- tests/test_other.py | 4 +++- 2 files changed, 22 insertions(+), 11 deletions(-) diff --git a/emcc.py b/emcc.py index 2c2950d1d6e81..a38169f8b9b4a 100755 --- a/emcc.py +++ b/emcc.py @@ -2640,15 +2640,7 @@ def check_bad_eq(arg): elif newargs[i].startswith('-g'): options.requested_debug = newargs[i] requested_level = newargs[i][2:] or '3' - if requested_level == 'line-tables-only': - # line-tables-only means function names and source positions, and no - # other debug info. keep that flag for the clang frontend to emit - # corresponding DWARF info. - # set the emscripten debug level to 3 so that we do not remove that - # debug info during link (during compile, this does not make a - # difference). - options.debug_level = 3 - else: + if is_int(requested_level): # the -gX value is the debug level (-g1, -g2, etc.) options.debug_level = validate_arg_level(requested_level, 4, 'Invalid debug level: ' + newargs[i]) # if we don't need to preserve LLVM debug info, do not keep this flag @@ -2656,7 +2648,16 @@ def check_bad_eq(arg): if options.debug_level < 3: newargs[i] = '' else: - newargs[i] = '-g' + # until we support full DWARF info, limit the clang frontend to just + # emit line tables, which can be represented in source maps + newargs[i] = '-gline-tables-only' + else: + # a non-integer level can be something like -gline-tables-only. keep + # the flag for the clang frontend to emit the appropriate DWARF info. + # set the emscripten debug level to 3 so that we do not remove that + # debug info during link (during compile, this does not make a + # difference). + options.debug_level = 3 elif newargs[i] == '-profiling' or newargs[i] == '--profiling': options.debug_level = max(options.debug_level, 2) options.profiling = True @@ -3689,6 +3690,14 @@ def validate_arg_level(level_string, max_level, err_msg, clamp=False): return level +def is_int(s): + try: + int(s) + return True + except: + return False + + if __name__ == '__main__': try: sys.exit(run(sys.argv)) diff --git a/tests/test_other.py b/tests/test_other.py index 60658202f438e..b89532226669c 100644 --- a/tests/test_other.py +++ b/tests/test_other.py @@ -2339,7 +2339,9 @@ def test(do_compile): do_compile(['-g']) full_size = os.path.getsize('a.out.wasm') self.assertLess(no_size, line_size) - self.assertLess(line_size, full_size) + # currently we don't support full debug info anyhow, so line tables + # is all we have + self.assertEqual(line_size, full_size) def compile_directly(compile_args): run_process([PYTHON, EMCC, path_from_root('tests', 'hello_world.cpp')] + compile_args) From c2e4a4b7e5e74eaf151c69ad940dd1fc2e80c56a Mon Sep 17 00:00:00 2001 From: Alon Zakai Date: Wed, 20 Nov 2019 10:30:38 -0800 Subject: [PATCH 4/4] flake8 --- emcc.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/emcc.py b/emcc.py index a38169f8b9b4a..62560baa768d3 100755 --- a/emcc.py +++ b/emcc.py @@ -3694,7 +3694,7 @@ def is_int(s): try: int(s) return True - except: + except ValueError: return False