Skip to content

Commit d792fa6

Browse files
committed
add c++ symbol map test
1 parent 3e5a57a commit d792fa6

File tree

2 files changed

+39
-0
lines changed

2 files changed

+39
-0
lines changed

test/test_other.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11011,6 +11011,21 @@ def check_symbolmap_info(address, func):
1101111011
# The name section will not show bar, as it's inlined into main
1101211012
check_symbolmap_info(unreachable_addr, '__original_main')
1101311013

11014+
# 3. Test symbol map on C++ name mangling
11015+
self.run_process([EMCC, test_file('test_symbolmap.cpp'),
11016+
'-O1', '--emit-symbol-map', '-o', 'test_symbolmap.js'])
11017+
self.assertExists('test_symbolmap.js.symbols')
11018+
11019+
out_to_js_call_addr = self.get_instr_addr('call\t0', 'test_symbolmap.wasm')
11020+
unreachable_addr = self.get_instr_addr('unreachable', 'test_symbolmap.wasm')
11021+
11022+
def check_cpp_symbolmap_info(address, func):
11023+
out = self.run_process([emsymbolizer, '--source=symbolmap', '-f', 'test_symbolmap.js.symbols', 'test_symbolmap.wasm', address], stdout=PIPE).stdout
11024+
self.assertIn(func, out)
11025+
11026+
check_cpp_symbolmap_info(out_to_js_call_addr, 'Namespace::foo(Namespace::SomeClass)')
11027+
check_cpp_symbolmap_info(unreachable_addr, 'void Namespace::bar<Namespace::SomeClass>(Namespace::SomeClass)')
11028+
1101411029
def test_separate_dwarf(self):
1101511030
self.run_process([EMCC, test_file('hello_world.c'), '-g'])
1101611031
self.assertExists('a.out.wasm')

test/test_symbolmap.cpp

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
#include <emscripten.h>
2+
3+
namespace Namespace {
4+
5+
EM_JS(int, out_to_js, (int x), {})
6+
7+
class SomeClass{};
8+
9+
void __attribute__((noinline)) foo(SomeClass v) {
10+
out_to_js(0);
11+
}
12+
13+
template <typename T>
14+
void __attribute__((noinline)) bar(T t) {
15+
__builtin_trap();
16+
}
17+
18+
}; // endof Namespace
19+
20+
int main() {
21+
Namespace::foo({});
22+
Namespace::bar(Namespace::SomeClass{});
23+
return 0;
24+
}

0 commit comments

Comments
 (0)