@@ -753,11 +753,14 @@ static void jl_print_debugloc(const char *pre_str, jl_debuginfo_t *debuginfo, jl
753
753
void jl_print_bt_entry_codeloc (int sig , jl_bt_element_t * bt_entry ) JL_NOTSAFEPOINT
754
754
{
755
755
char sig_str [32 ], pre_str [64 ];
756
- sig_str [0 ] = '\0' ;
756
+ sig_str [0 ] = pre_str [ 0 ] = '\0' ;
757
757
if (sig != -1 ) {
758
758
snprintf (sig_str , 32 , "signal (%d) " , sig );
759
759
}
760
- snprintf (pre_str , 64 , "%sthread (%d) " , sig_str , jl_threadid () + 1 );
760
+ // do not call jl_threadid if there's no current task
761
+ if (jl_get_current_task ()) {
762
+ snprintf (pre_str , 64 , "%sthread (%d) " , sig_str , jl_threadid () + 1 );
763
+ }
761
764
762
765
if (jl_bt_is_native (bt_entry )) {
763
766
jl_print_native_codeloc (pre_str , bt_entry [0 ].uintptr );
@@ -1369,7 +1372,11 @@ JL_DLLEXPORT jl_record_backtrace_result_t jl_record_backtrace(jl_task_t *t, jl_b
1369
1372
JL_DLLEXPORT void jl_gdblookup (void * ip )
1370
1373
{
1371
1374
char pre_str [64 ];
1372
- snprintf (pre_str , 64 , "thread (%d) " , jl_threadid () + 1 );
1375
+ pre_str [0 ] = '\0' ;
1376
+ // do not call jl_threadid if there's no current task
1377
+ if (jl_get_current_task ()) {
1378
+ snprintf (pre_str , 64 , "thread (%d) " , jl_threadid () + 1 );
1379
+ }
1373
1380
jl_print_native_codeloc (pre_str , (uintptr_t )ip );
1374
1381
}
1375
1382
@@ -1429,7 +1436,11 @@ JL_DLLEXPORT void jl_print_task_backtraces(int show_done) JL_NOTSAFEPOINT
1429
1436
1430
1437
size_t nthreads = jl_atomic_load_acquire (& jl_n_threads );
1431
1438
jl_ptls_t * allstates = jl_atomic_load_relaxed (& jl_all_tls_states );
1432
- int ctid = jl_threadid () + 1 ;
1439
+ int ctid = -1 ;
1440
+ // do not call jl_threadid if there's no current task
1441
+ if (jl_get_current_task ()) {
1442
+ ctid = jl_threadid () + 1 ;
1443
+ }
1433
1444
jl_safe_printf ("thread (%d) ++++ Task backtraces\n" , ctid );
1434
1445
for (size_t i = 0 ; i < nthreads ; i ++ ) {
1435
1446
jl_ptls_t ptls2 = allstates [i ];
0 commit comments