@@ -757,11 +757,14 @@ static void jl_print_debugloc(const char *pre_str, jl_debuginfo_t *debuginfo, jl
757
757
void jl_print_bt_entry_codeloc (int sig , jl_bt_element_t * bt_entry ) JL_NOTSAFEPOINT
758
758
{
759
759
char sig_str [32 ], pre_str [64 ];
760
- sig_str [0 ] = '\0' ;
760
+ sig_str [0 ] = pre_str [ 0 ] = '\0' ;
761
761
if (sig != -1 ) {
762
762
snprintf (sig_str , 32 , "signal (%d) " , sig );
763
763
}
764
- snprintf (pre_str , 64 , "%sthread (%d) " , sig_str , jl_threadid () + 1 );
764
+ // do not call jl_threadid if there's no current task
765
+ if (jl_get_current_task ()) {
766
+ snprintf (pre_str , 64 , "%sthread (%d) " , sig_str , jl_threadid () + 1 );
767
+ }
765
768
766
769
if (jl_bt_is_native (bt_entry )) {
767
770
jl_print_native_codeloc (pre_str , bt_entry [0 ].uintptr );
@@ -1373,7 +1376,11 @@ JL_DLLEXPORT jl_record_backtrace_result_t jl_record_backtrace(jl_task_t *t, jl_b
1373
1376
JL_DLLEXPORT void jl_gdblookup (void * ip )
1374
1377
{
1375
1378
char pre_str [64 ];
1376
- snprintf (pre_str , 64 , "thread (%d) " , jl_threadid () + 1 );
1379
+ pre_str [0 ] = '\0' ;
1380
+ // do not call jl_threadid if there's no current task
1381
+ if (jl_get_current_task ()) {
1382
+ snprintf (pre_str , 64 , "thread (%d) " , jl_threadid () + 1 );
1383
+ }
1377
1384
jl_print_native_codeloc (pre_str , (uintptr_t )ip );
1378
1385
}
1379
1386
@@ -1441,7 +1448,11 @@ JL_DLLEXPORT void jl_print_task_backtraces(int show_done) JL_NOTSAFEPOINT
1441
1448
1442
1449
size_t nthreads = jl_atomic_load_acquire (& jl_n_threads );
1443
1450
jl_ptls_t * allstates = jl_atomic_load_relaxed (& jl_all_tls_states );
1444
- int ctid = jl_threadid () + 1 ;
1451
+ int ctid = -1 ;
1452
+ // do not call jl_threadid if there's no current task
1453
+ if (jl_get_current_task ()) {
1454
+ ctid = jl_threadid () + 1 ;
1455
+ }
1445
1456
jl_safe_printf ("thread (%d) ++++ Task backtraces\n" , ctid );
1446
1457
for (size_t i = 0 ; i < nthreads ; i ++ ) {
1447
1458
jl_ptls_t ptls2 = allstates [i ];
0 commit comments