Skip to content
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

SIDE_DEBUG option: emit DWARF in a wasm on the side #10568

Merged
merged 8 commits into from
Feb 26, 2020
Merged
Show file tree
Hide file tree
Changes from 4 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
3 changes: 3 additions & 0 deletions emcc.py
Original file line number Diff line number Diff line change
Expand Up @@ -3339,6 +3339,9 @@ def run_closure_compiler(final):
with open(final, 'w') as f:
f.write(js)

if shared.Settings.FULL_DWARF and shared.Settings.SIDE_DEBUG:
shared.Building.emit_debug_on_side(wasm_binary_target)


def modularize():
global final
Expand Down
8 changes: 8 additions & 0 deletions src/settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -1492,6 +1492,14 @@ var ELIMINATE_DUPLICATE_FUNCTIONS_PASSES = 5;
// the ctors.
var EVAL_CTORS = 0;

// Whether to emit DWARF in a wasm file on the side (this is not called
// "split"/"separate" because there is already a DWARF concept by that name).
// When DWARF is on the side, the main file has no DWARF info, while the side
// file, ending in .debug.wasm, has the same wasm binary + all the debug
// sections.
// This has no effect if DWARF is not being emitted.
var SIDE_DEBUG = 0;

// see http://kripken.github.io/emscripten-site/docs/debugging/CyberDWARF.html
// [fastcomp-only]
var CYBERDWARF = 0;
Expand Down
9 changes: 9 additions & 0 deletions tests/test_other.py
Original file line number Diff line number Diff line change
Expand Up @@ -9033,6 +9033,15 @@ def test(infile, source_map_added_dir=''):
ensure_dir('inner')
test('inner/a.cpp', 'inner')

def test_side_debug(self):
run_process([PYTHON, EMCC, path_from_root('tests', 'hello_world.c'), '-gforce_dwarf'])
self.assertExists('a.out.wasm')
self.assertNotExists('a.out.wasm.debug.wasm')
run_process([PYTHON, EMCC, path_from_root('tests', 'hello_world.c'), '-gforce_dwarf', '-s', 'SIDE_DEBUG'])
self.assertExists('a.out.wasm')
self.assertExists('a.out.wasm.debug.wasm')
self.assertLess(os.path.getsize('a.out.wasm'), os.path.getsize('a.out.wasm.debug.wasm'))

def test_wasm_producers_section(self):
# no producers section by default
run_process([PYTHON, EMCC, path_from_root('tests', 'hello_world.c')])
Expand Down
10 changes: 10 additions & 0 deletions tools/shared.py
Original file line number Diff line number Diff line change
Expand Up @@ -704,6 +704,7 @@ def replace_or_append_suffix(filename, new_suffix):
LLVM_INTERPRETER = os.path.expanduser(build_llvm_tool_path(exe_suffix('lli')))
LLVM_COMPILER = os.path.expanduser(build_llvm_tool_path(exe_suffix('llc')))
LLVM_DWARFDUMP = os.path.expanduser(build_llvm_tool_path(exe_suffix('llvm-dwarfdump')))
LLVM_OBJCOPY = os.path.expanduser(build_llvm_tool_path(exe_suffix('llvm-objcopy')))
WASM_LD = os.path.expanduser(build_llvm_tool_path(exe_suffix('wasm-ld')))

EMSCRIPTEN = path_from_root('emscripten.py')
Expand Down Expand Up @@ -2756,6 +2757,15 @@ def wasm2js(js_file, wasm_file, opt_level, minify_whitespace, use_closure_compil
f.write(all_js)
return js_file

@staticmethod
def emit_debug_on_side(wasm_file):
# extract the DWARF info from the main file, and leave the wasm with
# debug into as a file on the side
# TODO: use strip directly; for now use objcopy
kripken marked this conversation as resolved.
Show resolved Hide resolved
wasm_file_with_dwarf = wasm_file + '.debug.wasm'
shutil.copyfile(wasm_file, wasm_file_with_dwarf)
kripken marked this conversation as resolved.
Show resolved Hide resolved
run_process([LLVM_OBJCOPY, wasm_file, '--remove-section=.debug*', wasm_file])

@staticmethod
def apply_wasm_memory_growth(js_file):
logger.debug('supporting wasm memory growth with pthreads')
Expand Down