Skip to content
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
25 changes: 20 additions & 5 deletions src/preamble.js
Original file line number Diff line number Diff line change
Expand Up @@ -858,15 +858,20 @@ function lengthBytesUTF32(str) {
{{{ maybeExport('lengthBytesUTF32') }}}

function demangle(func) {
var hasLibcxxabi = !!Module['___cxa_demangle'];
if (hasLibcxxabi) {
var __cxa_demangle_func = Module['___cxa_demangle'] || Module['__cxa_demangle'];
if (__cxa_demangle_func) {
try {
var s = func.substr(1);
var s =
#if WASM_BACKEND
func;
#else
func.substr(1);
#endif
var len = lengthBytesUTF8(s)+1;
var buf = _malloc(len);
stringToUTF8(s, buf, len);
var status = _malloc(4);
var ret = Module['___cxa_demangle'](buf, 0, 0, status);
var ret = __cxa_demangle_func(buf, 0, 0, status);
if (getValue(status, 'i32') === 0 && ret) {
return Pointer_stringify(ret);
}
Expand All @@ -886,7 +891,17 @@ function demangle(func) {
}

function demangleAll(text) {
return text.replace(/__Z[\w\d_]+/g, function(x) { var y = demangle(x); return x === y ? x : (x + ' [' + y + ']') });
var regex =
#if WASM_BACKEND
/_Z[\w\d_]+/g;
#else
/__Z[\w\d_]+/g;
#endif
return text.replace(regex,
function(x) {
var y = demangle(x);
return x === y ? x : (x + ' [' + y + ']');
});
}

function jsStackTrace() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
namespace NameSpace {
class Class {
public:
__attribute__((noinline))
void Aborter(double x, char y, int *z) {
int addr = x + y + (int)z;
void *p = (void *)addr;
Expand Down
6 changes: 1 addition & 5 deletions tests/test_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -6115,26 +6115,22 @@ def test_emulate_function_pointer_casts(self):
'''
self.do_run(src, '|1.266,1|\n')

@no_wasm_backend()
def test_demangle_stacks(self):
if self.is_wasm():
self.banned_js_engines = [V8_ENGINE] # https://bugs.chromium.org/p/v8/issues/detail?id=5632
Settings.DEMANGLE_SUPPORT = 1
if '-O' in str(self.emcc_args):
self.emcc_args += ['--profiling-funcs', '--llvm-opts', '0']

self.do_run_in_out_file_test('tests', 'core', 'test_demangle_stacks')

@no_emterpreter
@no_wasm_backend()
def test_demangle_stacks_symbol_map(self):
Settings.DEMANGLE_SUPPORT = 1
if '-O' in str(self.emcc_args) and '-O0' not in self.emcc_args and '-O1' not in self.emcc_args and '-g' not in self.emcc_args:
self.emcc_args += ['--llvm-opts', '0']
else:
return self.skip("without opts, we don't emit a symbol map")
self.emcc_args += ['--emit-symbol-map']
self.do_run(open(path_from_root('tests', 'core', 'test_demangle_stacks.c')).read(), 'abort')
self.do_run(open(path_from_root('tests', 'core', 'test_demangle_stacks.cpp')).read(), 'abort')
# make sure the shortened name is the right one
symbols = open('src.cpp.o.js.symbols').read().split('\n')
for line in symbols:
Expand Down