@@ -757,11 +757,14 @@ static void jl_print_debugloc(const char *pre_str, jl_debuginfo_t *debuginfo, jl
757757void  jl_print_bt_entry_codeloc (int  sig , jl_bt_element_t  * bt_entry ) JL_NOTSAFEPOINT 
758758{
759759    char  sig_str [32 ], pre_str [64 ];
760-     sig_str [0 ] =  '\0' ;
760+     sig_str [0 ] =  pre_str [ 0 ]  =   '\0' ;
761761    if  (sig  !=  -1 ) {
762762        snprintf (sig_str , 32 , "signal (%d) " , sig );
763763    }
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+     }
765768
766769    if  (jl_bt_is_native (bt_entry )) {
767770        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
13731376JL_DLLEXPORT  void  jl_gdblookup (void *  ip )
13741377{
13751378    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+     }
13771384    jl_print_native_codeloc (pre_str , (uintptr_t )ip );
13781385}
13791386
@@ -1433,7 +1440,11 @@ JL_DLLEXPORT void jl_print_task_backtraces(int show_done) JL_NOTSAFEPOINT
14331440
14341441    size_t  nthreads  =  jl_atomic_load_acquire (& jl_n_threads );
14351442    jl_ptls_t  * allstates  =  jl_atomic_load_relaxed (& jl_all_tls_states );
1436-     int  ctid  =  jl_threadid () +  1 ;
1443+     int  ctid  =  -1 ;
1444+     // do not call jl_threadid if there's no current task 
1445+     if  (jl_get_current_task ()) {
1446+         ctid  =  jl_threadid () +  1 ;
1447+     }
14371448    jl_safe_printf ("thread (%d) ++++ Task backtraces\n" , ctid );
14381449    for  (size_t  i  =  0 ; i  <  nthreads ; i ++ ) {
14391450        jl_ptls_t  ptls2  =  allstates [i ];
0 commit comments