demangle stacks in abort(), using new stackTrace utility
This commit is contained in:
Родитель
5e00090b12
Коммит
5e6b5e313c
|
@ -4296,7 +4296,7 @@ LibraryManager.library = {
|
|||
},
|
||||
|
||||
llvm_trap: function() {
|
||||
throw 'trap! ' + new Error().stack;
|
||||
abort('trap!');
|
||||
},
|
||||
|
||||
__assert_fail: function(condition, filename, line, func) {
|
||||
|
|
|
@ -180,7 +180,7 @@ function abort(text) {
|
|||
ABORT = true;
|
||||
EXITSTATUS = 1;
|
||||
|
||||
throw 'abort() at ' + (new Error().stack);
|
||||
throw 'abort() at ' + stackTrace();
|
||||
}
|
||||
Module['abort'] = Module.abort = abort;
|
||||
|
||||
|
|
|
@ -644,7 +644,7 @@ function demangle(func) {
|
|||
try {
|
||||
if (typeof func === 'number') func = Pointer_stringify(func);
|
||||
if (func[0] !== '_') return func;
|
||||
if (func[1] !== '_') return func.substr(1); // C function
|
||||
if (func[1] !== '_') return func; // C function
|
||||
if (func[2] !== 'Z') return func;
|
||||
var i = 3;
|
||||
// params, etc.
|
||||
|
@ -747,10 +747,18 @@ function demangle(func) {
|
|||
}
|
||||
return parse();
|
||||
} catch(e) {
|
||||
return func + '<demangle-err>' + e;
|
||||
return func;
|
||||
}
|
||||
}
|
||||
|
||||
function demangleAll(text) {
|
||||
return text.replace(/__Z[\w\d_]+/, function(x) { var y = demangle(x); return x === y ? x : (x + ' (' + y + ')') });
|
||||
}
|
||||
|
||||
function stackTrace() {
|
||||
return demangleAll(new Error().stack);
|
||||
}
|
||||
|
||||
// Memory management
|
||||
|
||||
var PAGE_SIZE = 4096;
|
||||
|
|
|
@ -9476,6 +9476,32 @@ def process(filename):
|
|||
Settings.ALIASING_FUNCTION_POINTERS = 1 - Settings.ALIASING_FUNCTION_POINTERS # flip the test
|
||||
self.do_run(src, '''Hello 7 from JS!''')
|
||||
|
||||
def test_demangle_stacks(self):
|
||||
if Settings.ASM_JS: return self.skip('spidermonkey has stack trace issues')
|
||||
|
||||
src = r'''
|
||||
#include<stdio.h>
|
||||
#include<stdlib.h>
|
||||
|
||||
namespace NameSpace {
|
||||
class Class {
|
||||
public:
|
||||
int Aborter(double x, char y, int *z) {
|
||||
int addr = x+y+(int)z;
|
||||
void *p = (void*)addr;
|
||||
for (int i = 0; i < 100; i++) free(p); // will abort, should show proper stack trace
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
int main(int argc, char **argv) {
|
||||
NameSpace::Class c;
|
||||
c.Aborter(1.234, 'a', NULL);
|
||||
return 0;
|
||||
}
|
||||
'''
|
||||
self.do_run(src, 'NameSpace::Class::Aborter(double, char, int*)');
|
||||
|
||||
def test_embind(self):
|
||||
if self.emcc_args is None: return self.skip('requires emcc')
|
||||
Building.COMPILER_TEST_OPTS += ['--bind']
|
||||
|
|
Загрузка…
Ссылка в новой задаче