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

asm2wasm debuginfo #4917

Merged
merged 5 commits into from
Feb 7, 2017
Merged
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
20 changes: 18 additions & 2 deletions emcc.py
Original file line number Diff line number Diff line change
Expand Up @@ -2103,6 +2103,8 @@ def do_minify(): # minifies the code. this is also when we do certain optimizati
combined.write('\n//^wasm.js\n')
combined.write(js)
combined.close()
# normally we emit binary, but for debug info, we might emit text first
wrote_wasm_text = False
# finish compiling to WebAssembly, using asm2wasm, if we didn't already emit WebAssembly directly using the wasm backend.
if not shared.Settings.WASM_BACKEND:
cmd = [os.path.join(binaryen_bin, 'asm2wasm'), asm_target, '--total-memory=' + str(shared.Settings.TOTAL_MEMORY)]
Expand Down Expand Up @@ -2130,10 +2132,24 @@ def do_minify(): # minifies the code. this is also when we do certain optimizati
cmd += ['-g']
if emit_symbol_map or shared.Settings.CYBERDWARF:
cmd += ['--symbolmap=' + target + '.symbols']
cmd += ['-o', wasm_binary_target]
# we prefer to emit a binary, as it is more efficient. however, when we
# want full debug info support (not just function names), then we must
# emit text (at least until wasm gains support for debug info in binaries)
target_binary = debug_level < 3
if target_binary:
cmd += ['-o', wasm_binary_target]
else:
cmd += ['-o', wasm_text_target, '-S']
wrote_wasm_text = True
logging.debug('asm2wasm (asm.js => WebAssembly): ' + ' '.join(cmd))
TimeLogger.update()
subprocess.check_call(cmd)
if not target_binary:
cmd = [os.path.join(binaryen_bin, 'wasm-as'), wasm_text_target, '-o', wasm_binary_target]
if debug_level >= 2 or profiling_funcs:
cmd += ['-g']
logging.debug('wasm-as (text => binary): ' + ' '.join(cmd))
subprocess.check_call(cmd)
if import_mem_init:
# remove and forget about the mem init file in later processing; it does not need to be prefetched in the html, etc.
os.unlink(memfile)
Expand All @@ -2144,7 +2160,7 @@ def do_minify(): # minifies the code. this is also when we do certain optimizati
cmd = [os.path.join(binaryen_bin, 'wasm-opt'), wasm_binary_target + '.pre', '-o', wasm_binary_target] + map(lambda p: '--' + p, shared.Settings.BINARYEN_PASSES.split(','))
logging.debug('wasm-opt on BINARYEN_PASSES: ' + ' '.join(cmd))
subprocess.check_call(cmd)
if 'interpret-s-expr' in shared.Settings.BINARYEN_METHOD:
if not wrote_wasm_text and 'interpret-s-expr' in shared.Settings.BINARYEN_METHOD:
cmd = [os.path.join(binaryen_bin, 'wasm-dis'), wasm_binary_target, '-o', wasm_text_target]
logging.debug('wasm-dis (binary => text): ' + ' '.join(cmd))
subprocess.check_call(cmd)
Expand Down
30 changes: 30 additions & 0 deletions tests/test_other.py
Original file line number Diff line number Diff line change
Expand Up @@ -7315,6 +7315,36 @@ def test_binaryen_ctors(self):
seen = run_js('b.out.js', engine=SPIDERMONKEY_ENGINE)
assert correct == seen, correct + '\n vs \n' + seen

def test_binaryen_debuginfo(self):
if os.environ.get('EMCC_DEBUG'): return self.skip('cannot run in debug mode')

try:
os.environ['EMCC_DEBUG'] = '1'
for args, expect_dash_g, expect_emit_text in [
(['-O0'], False, False),
(['-O0', '-g1'], False, False),
(['-O0', '-g2'], True, False), # in -g2+, we emit -g to asm2wasm so function names are saved
(['-O0', '-g'], True, True),
(['-O0', '--profiling-funcs'], True, False),
(['-O1'], False, False),
]:
print args, expect_dash_g, expect_emit_text
try_delete('a.out.wast')
cmd = [PYTHON, EMCC, path_from_root('tests', 'hello_world.cpp'), '-s', 'WASM=1'] + args
print ' '.join(cmd)
output, err = Popen(cmd, stdout=PIPE, stderr=PIPE).communicate()
asm2wasm_line = filter(lambda x: 'asm2wasm' in x, err.split('\n'))[0]
asm2wasm_line = asm2wasm_line.strip() + ' ' # ensure it ends with a space, for simpler searches below
print '|' + asm2wasm_line + '|'
assert expect_dash_g == (' -g ' in asm2wasm_line)
assert expect_emit_text == (' -S ' in asm2wasm_line)
if expect_emit_text:
text = open('a.out.wast').read()
assert ';;' in text, 'must see debug info comment'
assert 'hello_world.cpp:6' in text, 'must be file:line info'
finally:
del os.environ['EMCC_DEBUG']

def test_wasm_targets(self):
for f in ['a.wasm', 'a.wast']:
process = Popen([PYTHON, EMCC, path_from_root('tests', 'hello_world.cpp'), '-o', f], stdout=PIPE, stderr=PIPE)
Expand Down
2 changes: 1 addition & 1 deletion tools/ports/binaryen.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import os, shutil, logging

TAG = 'version_26'
TAG = 'version_27'

def needed(settings, shared, ports):
if not settings.BINARYEN: return False
Expand Down