@@ -753,11 +753,14 @@ static void jl_print_debugloc(const char *pre_str, jl_debuginfo_t *debuginfo, jl
753753void  jl_print_bt_entry_codeloc (int  sig , jl_bt_element_t  * bt_entry ) JL_NOTSAFEPOINT 
754754{
755755    char  sig_str [32 ], pre_str [64 ];
756-     sig_str [0 ] =  '\0' ;
756+     sig_str [0 ] =  pre_str [ 0 ]  =   '\0' ;
757757    if  (sig  !=  -1 ) {
758758        snprintf (sig_str , 32 , "signal (%d) " , sig );
759759    }
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+     }
761764
762765    if  (jl_bt_is_native (bt_entry )) {
763766        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
13691372JL_DLLEXPORT  void  jl_gdblookup (void *  ip )
13701373{
13711374    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+     }
13731380    jl_print_native_codeloc (pre_str , (uintptr_t )ip );
13741381}
13751382
@@ -1429,7 +1436,11 @@ JL_DLLEXPORT void jl_print_task_backtraces(int show_done) JL_NOTSAFEPOINT
14291436
14301437    size_t  nthreads  =  jl_atomic_load_acquire (& jl_n_threads );
14311438    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+     }
14331444    jl_safe_printf ("thread (%d) ++++ Task backtraces\n" , ctid );
14341445    for  (size_t  i  =  0 ; i  <  nthreads ; i ++ ) {
14351446        jl_ptls_t  ptls2  =  allstates [i ];
0 commit comments