@@ -11021,6 +11021,57 @@ def check_symbolmap_info(address, func):
1102111021 # The name section will not show bar, as it's inlined into main
1102211022 check_symbolmap_info(unreachable_addr, '__original_main')
1102311023
11024+ def test_emsymbolizer_symbol_map_names(self):
11025+ "Test emsymbolizer with symbol map which contains demangled C++ names"
11026+ create_file('test_symbol_map.cpp', r'''
11027+ #include <emscripten.h>
11028+ EM_JS(int, out_to_js, (), { return 0; });
11029+
11030+ namespace Namespace {
11031+ class ClassA{};
11032+ class ClassB{};
11033+
11034+ void __attribute__((noinline)) foo(ClassA v) { out_to_js(); }
11035+
11036+ template <typename T>
11037+ void __attribute__((noinline)) bar(ClassB t) { __builtin_trap(); }
11038+ };
11039+
11040+ int main() {
11041+ // call function to avoid Dead-code elimination
11042+ Namespace::foo({});
11043+ // instantiate template function
11044+ Namespace::bar<Namespace::ClassA>(Namespace::ClassB{});
11045+ return 0;
11046+ }
11047+ ''')
11048+ self.run_process([EMXX, 'test_symbol_map.cpp',
11049+ '-O1', '--emit-symbol-map', '-o', 'test_symbol_map.js'])
11050+ self.assertExists('test_symbol_map.js.symbols')
11051+
11052+ out_to_js_call_addr = self.get_instr_addr('call\t0', 'test_symbol_map.wasm')
11053+ unreachable_addr = self.get_instr_addr('unreachable', 'test_symbol_map.wasm')
11054+
11055+ def check_cpp_symbolmap_info(address, func):
11056+ out = self.run_process([emsymbolizer, '--source=symbolmap', '-f', 'test_symbol_map.js.symbols', 'test_symbol_map.wasm', address], stdout=PIPE).stdout
11057+ self.assertIn(func, out)
11058+
11059+ def check_symbol_map_contains(func):
11060+ out = read_file('test_symbol_map.js.symbols')
11061+ self.assertIn(func, out)
11062+
11063+ # function name: "Namespace::foo(Namespace::ClassA)"
11064+ check_cpp_symbolmap_info(out_to_js_call_addr, 'Namespace::foo')
11065+ check_cpp_symbolmap_info(out_to_js_call_addr, 'Namespace::ClassA')
11066+
11067+ # function name: "void Namespace::bar<Namespace::ClassA>(Namespace::ClassB)"
11068+ check_cpp_symbolmap_info(unreachable_addr, 'Namespace::bar')
11069+ check_cpp_symbolmap_info(unreachable_addr, 'Namespace::ClassA')
11070+ check_cpp_symbolmap_info(unreachable_addr, 'Namespace::ClassB')
11071+
11072+ # JS imports
11073+ check_symbol_map_contains('out_to_js')
11074+
1102411075 def test_separate_dwarf(self):
1102511076 self.run_process([EMCC, test_file('hello_world.c'), '-g'])
1102611077 self.assertExists('a.out.wasm')
0 commit comments