Skip to content

Commit 37fe200

Browse files
authored
Stack trace and heap cleanups (#5988)
* minor cleanups in the js glue code, avoiding redundancy and unnecessary things * test for assertions notice
1 parent 53d1256 commit 37fe200

File tree

6 files changed

+35
-20
lines changed

6 files changed

+35
-20
lines changed

src/postamble.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -414,18 +414,17 @@ function abort(what) {
414414
EXITSTATUS = 1;
415415

416416
#if ASSERTIONS == 0
417-
var extra = '\nIf this abort() is unexpected, build with -s ASSERTIONS=1 which can give more information.';
417+
throw 'abort(' + what + '). Build with -s ASSERTIONS=1 for more info.';
418418
#else
419419
var extra = '';
420-
#endif
421-
422420
var output = 'abort(' + what + ') at ' + stackTrace() + extra;
423421
if (abortDecorators) {
424422
abortDecorators.forEach(function(decorator) {
425423
output = decorator(output, what);
426424
});
427425
}
428426
throw output;
427+
#endif // ASSERTIONS
429428
}
430429
Module['abort'] = abort;
431430

src/preamble.js

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1180,6 +1180,7 @@ if (Module['buffer']) {
11801180
#if ASSERTIONS
11811181
assert(buffer.byteLength === TOTAL_MEMORY);
11821182
#endif // ASSERTIONS
1183+
Module['buffer'] = buffer;
11831184
}
11841185
updateGlobalBufferViews();
11851186
#else // SPLIT_MEMORY
@@ -1474,17 +1475,6 @@ HEAP16[1] = 0x6373;
14741475
if (HEAPU8[2] !== 0x73 || HEAPU8[3] !== 0x63) throw 'Runtime error: expected the system to be little-endian!';
14751476
#endif
14761477

1477-
Module['HEAP'] = HEAP;
1478-
Module['buffer'] = buffer;
1479-
Module['HEAP8'] = HEAP8;
1480-
Module['HEAP16'] = HEAP16;
1481-
Module['HEAP32'] = HEAP32;
1482-
Module['HEAPU8'] = HEAPU8;
1483-
Module['HEAPU16'] = HEAPU16;
1484-
Module['HEAPU32'] = HEAPU32;
1485-
Module['HEAPF32'] = HEAPF32;
1486-
Module['HEAPF64'] = HEAPF64;
1487-
14881478
function callRuntimeCallbacks(callbacks) {
14891479
while(callbacks.length > 0) {
14901480
var callback = callbacks.shift();
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
#include <stdio.h>
2+
#include <stdlib.h>
3+
4+
namespace NameSpace {
5+
class Class {
6+
public:
7+
__attribute__((noinline))
8+
void Aborter(double x, char y, int *z) {
9+
volatile int w = 1;
10+
if (w) {
11+
abort();
12+
}
13+
}
14+
};
15+
}
16+
17+
int main(int argc, char **argv) {
18+
NameSpace::Class c;
19+
c.Aborter(1.234, 'a', NULL);
20+
return 0;
21+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Build with -s ASSERTIONS=1 for more info.

tests/test_core.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6085,12 +6085,12 @@ def test(expected, args=[], no_build=False):
60856085
# Kill off the dead function, and check a code path using it aborts
60866086
Settings.DEAD_FUNCTIONS = ['_unused']
60876087
test('*2*')
6088-
test('abort(-1) at', args=['x'], no_build=True)
6088+
test('abort(', args=['x'], no_build=True)
60896089

60906090
# Kill off a library function, check code aborts
60916091
Settings.DEAD_FUNCTIONS = ['_printf']
6092-
test('abort(-1) at')
6093-
test('abort(-1) at', args=['x'], no_build=True)
6092+
test('abort(')
6093+
test('abort(', args=['x'], no_build=True)
60946094

60956095
def test_pgo(self):
60966096
if Settings.ASM_JS: return self.skip('PGO does not work in asm mode')
@@ -6338,10 +6338,14 @@ def test_emulate_function_pointer_casts(self):
63386338

63396339
def test_demangle_stacks(self):
63406340
Settings.DEMANGLE_SUPPORT = 1
6341+
Settings.ASSERTIONS = 1
63416342
if '-O' in str(self.emcc_args):
63426343
self.emcc_args += ['--profiling-funcs', '--llvm-opts', '0']
6343-
63446344
self.do_run_in_out_file_test('tests', 'core', 'test_demangle_stacks')
6345+
if 'ASSERTIONS' not in str(self.emcc_args):
6346+
print('without assertions, the stack is not printed, but a message suggesting assertions is')
6347+
Settings.ASSERTIONS = 0
6348+
self.do_run_in_out_file_test('tests', 'core', 'test_demangle_stacks_noassert')
63456349

63466350
@no_emterpreter
63476351
@no_wasm_backend('s2wasm does not generate symbol maps')

tests/test_other.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -764,7 +764,7 @@ def test(args, expected, moar_expected=None):
764764
if moar_expected: self.assertContained(moar_expected, out)
765765

766766
# fastcomp. all asm, so it can't just work with wrong sigs. but, ASSERTIONS=2 gives much better info to debug
767-
test(['-O1'], 'If this abort() is unexpected, build with -s ASSERTIONS=1 which can give more information.') # no useful info, but does mention ASSERTIONS
767+
test(['-O1'], 'Build with -s ASSERTIONS=1 for more info.') # no useful info, but does mention ASSERTIONS
768768
test(['-O1', '-s', 'ASSERTIONS=1'], '''Invalid function pointer called with signature 'v'. Perhaps this is an invalid value (e.g. caused by calling a virtual method on a NULL pointer)? Or calling a function with an incorrect type, which will fail? (it is worth building your source files with -Werror (warnings are errors), as warnings can indicate undefined behavior which can cause this)
769769
Build with ASSERTIONS=2 for more info.
770770
''') # some useful text
@@ -3674,7 +3674,7 @@ def test_bad_function_pointer_cast(self):
36743674
if opts == 0:
36753675
assert 'Invalid function pointer called' in output, output
36763676
else:
3677-
assert 'abort()' in output, output
3677+
assert 'abort(' in output, output
36783678

36793679
def test_aliased_func_pointers(self):
36803680
open('src.cpp', 'w').write(r'''

0 commit comments

Comments
 (0)