Skip to content

Commit 9016235

Browse files
authored
Remove source map 'names' field support (emscripten-core#26149)
We used 'names' field to encode the enclosing function name of a given offset, so that we can provide the correct source location + function info that can be used in displaying stack traces. I wasn't aware JS uses it for a very different purpose. JS uses it to display original variable/function names for minified names. In JS an 'offset' is a location in the minified JS code, and if that location happens to point to a minified variable name `a` whose original name was `apple`, its mapping contains `apple`. So while we can use this field to support emsymbolizer, the browser devtools is unlikely to ever implement the support for our 'names' field for stack traces, which is basically unrelated from what JS does. So this removes the support for the 'names' field. But it doesn't actually remove the implementation; it just puts it behind a fake flag that is set to `False` for now. The reason is, we want to provide this function info anyway for better stack traces support, and "Scopes" proposal for source maps, which was recently added, seems designed for this purpose. And I think we can reuse much of our current implementation (`extract_func_ranges`) to generate that format. Fixes emscripten-core#26100.
1 parent aad5488 commit 9016235

File tree

3 files changed

+32
-22
lines changed

3 files changed

+32
-22
lines changed

ChangeLog.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@ See docs/process.md for more on how version tagging works.
2020

2121
4.0.24 (in development)
2222
-----------------------
23+
- Source map's 'names' field support is removed, because the way we used it was
24+
inconsistent with JS and was not supported in browser devtools. We plan to
25+
provide this information using Scopes encoding later. (#26149)
2326
- compiler-rt, libcxx, libcxxabi, and libunwind were updated to LLVM 21.1.8.
2427
- (#26036, #26045, and #26058)
2528
- Calling pthread_create in a single-threaded build will now return ENOTSUP

test/test_other.py

Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -9651,36 +9651,32 @@ def check_source_map_loc_info(address, func, loc):
96519651
out = self.run_process(
96529652
[emsymbolizer, '-s', 'sourcemap', 'test_dwarf.wasm', address],
96539653
stdout=PIPE).stdout
9654-
self.assertIn(func, out)
9654+
if func:
9655+
self.assertIn(func, out)
96559656
self.assertIn(loc, out)
96569657

96579658
def do_tests(src):
96589659
# 1. Test DWARF + source map together
9659-
# For DWARF, we check for the full inlined info for both function names and
9660-
# source locations. Source maps does not provide inlined info. So we only
9661-
# check for the info of the outermost function.
9660+
# For DWARF, we check for the full inlined info for both function names
9661+
# and source locations. Source maps does not provide inlining information
9662+
# and function name, so we only check for the info of the outermost
9663+
# location.
96629664
self.run_process([EMCC, test_file(src), '-g', '-gsource-map', '-O1', '-o',
96639665
'test_dwarf.js'])
96649666
check_dwarf_loc_info(out_to_js_call_addr, out_to_js_call_func,
96659667
out_to_js_call_loc)
9666-
check_source_map_loc_info(out_to_js_call_addr, out_to_js_call_func[0],
9668+
check_source_map_loc_info(out_to_js_call_addr, None,
96679669
out_to_js_call_loc[0])
96689670
check_dwarf_loc_info(unreachable_addr, unreachable_func, unreachable_loc)
9669-
# Source map shows the original (inlined) source location with the original
9670-
# function name
9671-
check_source_map_loc_info(unreachable_addr, unreachable_func[0],
9672-
unreachable_loc[0])
9671+
# Source map shows the original (inlined) source location
9672+
check_source_map_loc_info(unreachable_addr, None, unreachable_loc[0])
96739673

96749674
# 2. Test source map only
9675-
# The addresses, function names, and source locations are the same across
9676-
# the builds because they are relative offsets from the code section, so we
9677-
# don't need to recompute them
96789675
self.run_process([EMCC, test_file(src), '-gsource-map', '-O1', '-o',
96799676
'test_dwarf.js'])
9680-
check_source_map_loc_info(out_to_js_call_addr, out_to_js_call_func[0],
9677+
check_source_map_loc_info(out_to_js_call_addr, None,
96819678
out_to_js_call_loc[0])
9682-
check_source_map_loc_info(unreachable_addr, unreachable_func[0],
9683-
unreachable_loc[0])
9679+
check_source_map_loc_info(unreachable_addr, None, unreachable_loc[0])
96849680

96859681
# 3. Test DWARF only
96869682
self.run_process([EMCC, test_file(src), '-g', '-O1', '-o',

tools/wasm-sourcemap.py

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,9 @@
3131

3232
logger = logging.getLogger('wasm-sourcemap')
3333

34+
# FIXME: Generate Scopes info
35+
generate_scopes = False
36+
3437

3538
def parse_args(args):
3639
parser = argparse.ArgumentParser(prog='wasm-sourcemap.py', description=__doc__)
@@ -399,12 +402,17 @@ def read_dwarf_info(wasm, options):
399402
logger.debug('Reading DWARF information from %s' % wasm)
400403
if not os.path.exists(options.dwarfdump):
401404
utils.exit_with_error('llvm-dwarfdump not found: ' + options.dwarfdump)
402-
# We need only three tags in the debug info: DW_TAG_compile_unit for
403-
# source location, and DW_TAG_subprogram and DW_TAG_inlined_subroutine
404-
# for the function ranges.
405-
dwarfdump_cmd = [options.dwarfdump, '-debug-info', '-debug-line', wasm,
406-
'-t', 'DW_TAG_compile_unit', '-t', 'DW_TAG_subprogram',
407-
'-t', 'DW_TAG_inlined_subroutine']
405+
dwarfdump_cmd = [options.dwarfdump, '-debug-info', '-debug-line', wasm]
406+
if generate_scopes:
407+
# We need only three tags in the debug info: DW_TAG_compile_unit for
408+
# source location, and DW_TAG_subprogram and DW_TAG_inlined_subroutine
409+
# for the function ranges.
410+
dwarfdump_cmd += ['-t', 'DW_TAG_compile_unit', '-t', 'DW_TAG_subprogram',
411+
'-t', 'DW_TAG_inlined_subroutine']
412+
else:
413+
# We only need the top-level DW_TAG_compile_unit tags when not generating
414+
# the names field
415+
dwarfdump_cmd += ['--recurse-depth=0']
408416
proc = shared.check_call(dwarfdump_cmd, stdout=shared.PIPE)
409417
output = proc.stdout
410418
else:
@@ -481,7 +489,10 @@ def read_dwarf_info(wasm, options):
481489
# return entries sorted by the address field
482490
entries = sorted(entries, key=lambda entry: entry['address'])
483491

484-
func_ranges = extract_func_ranges(debug_info)
492+
if generate_scopes:
493+
func_ranges = extract_func_ranges(debug_info)
494+
else:
495+
func_ranges = []
485496
return entries, func_ranges
486497

487498

0 commit comments

Comments
 (0)