Skip to content

Commit 3b3d791

Browse files
authored
Enable dbg() helper function whenever ASSERTIONS are enabled (#18616)
The debug function is useful even when `RUNTIME_DEBUG` is not enabled.
1 parent 987b48e commit 3b3d791

File tree

3 files changed

+30
-7
lines changed

3 files changed

+30
-7
lines changed

src/library_pthread.js

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ var LibraryPThread = {
5555
// the reverse mapping, each worker has a `pthread_ptr` when its running a
5656
// pthread.
5757
pthreads: {},
58-
#if PTHREADS_DEBUG
58+
#if ASSERTIONS
5959
nextWorkerID: 1,
6060
debugInit: function() {
6161
function pthreadLogPrefix() {
@@ -70,16 +70,18 @@ var LibraryPThread = {
7070
return 'w:' + (Module['workerID'] || 0) + ',t:' + ptrToString(t) + ': ';
7171
}
7272

73-
// When PTHREAD_DEBUG is enabled, prefix all err()/dbg() messages with the
74-
// calling thread ID.
75-
var origErr = err;
76-
err = (message) => origErr(pthreadLogPrefix() + message);
73+
// Prefix all err()/dbg() messages with the calling thread ID.
7774
var origDbg = dbg;
7875
dbg = (message) => origDbg(pthreadLogPrefix() + message);
76+
#if PTHREADS_DEBUG
77+
// With PTHREADS_DEBUG also prefix all err() messages.
78+
var origErr = err;
79+
err = (message) => origErr(pthreadLogPrefix() + message);
80+
#endif
7981
},
8082
#endif
8183
init: function() {
82-
#if PTHREADS_DEBUG
84+
#if ASSERTIONS
8385
PThread.debugInit();
8486
#endif
8587
if (ENVIRONMENT_IS_PTHREAD) {
@@ -390,7 +392,7 @@ var LibraryPThread = {
390392
#if MAIN_MODULE
391393
'dynamicLibraries': Module['dynamicLibraries'],
392394
#endif
393-
#if PTHREADS_DEBUG
395+
#if ASSERTIONS
394396
'workerID': PThread.nextWorkerID++,
395397
#endif
396398
});

src/runtime_debug.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,9 @@ function prettyPrint(arg) {
124124
}
125125
return arg;
126126
}
127+
#endif
127128

129+
#if ASSERTIONS || RUNTIME_DEBUG
128130
// Used by XXXXX_DEBUG settings to output debug messages.
129131
function dbg(text) {
130132
// TODO(sbc): Make this configurable somehow. Its not always convient for

test/test_other.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12857,3 +12857,22 @@ def test_itimer_proxy_to_pthread(self):
1285712857
self.set_setting('PROXY_TO_PTHREAD')
1285812858
self.set_setting('EXIT_RUNTIME')
1285912859
self.do_other_test('test_itimer.c')
12860+
12861+
@node_pthreads
12862+
def test_dbg(self):
12863+
create_file('pre.js', '''
12864+
dbg('start');
12865+
Module.onRuntimeInitialized = () => dbg('done init');
12866+
''')
12867+
self.emcc_args.append('--pre-js=pre.js')
12868+
# Verify that, after initialization, dbg() messages are prefixed with
12869+
# worker and thread ID.
12870+
self.do_runf(test_file('hello_world.c'),
12871+
'start\nw:0,t:0x[0-9a-fA-F]+: done init\nhello, world!\n',
12872+
regex=True)
12873+
12874+
# When assertions are disabled `dbg` function is not defined
12875+
self.do_runf(test_file('hello_world.c'),
12876+
'ReferenceError: dbg is not defined',
12877+
emcc_args=['-sASSERTIONS=0'],
12878+
assert_returncode=NON_ZERO)

0 commit comments

Comments
 (0)