@@ -614,22 +614,25 @@ JL_DLLEXPORT jl_value_t *jl_lookup_code_address(void *ip, int skipC)
614614 return rs ;
615615}
616616
617- static void jl_safe_print_codeloc (const char * func_name , const char * file_name ,
617+ static void jl_safe_print_codeloc (const char * pre_str ,
618+ const char * func_name , const char * file_name ,
618619 int line , int inlined ) JL_NOTSAFEPOINT
619620{
620621 const char * inlined_str = inlined ? " [inlined]" : "" ;
621622 if (line != -1 ) {
622- jl_safe_printf ("%s at %s:%d%s\n" , func_name , file_name , line , inlined_str );
623+ jl_safe_printf ("%s%s at %s:%d%s\n" ,
624+ pre_str , func_name , file_name , line , inlined_str );
623625 }
624626 else {
625- jl_safe_printf ("%s at %s (unknown line)%s\n" , func_name , file_name , inlined_str );
627+ jl_safe_printf ("%s%s at %s (unknown line)%s\n" ,
628+ pre_str , func_name , file_name , inlined_str );
626629 }
627630}
628631
629632// Print function, file and line containing native instruction pointer `ip` by
630633// looking up debug info. Prints multiple such frames when `ip` points to
631634// inlined code.
632- void jl_print_native_codeloc (uintptr_t ip ) JL_NOTSAFEPOINT
635+ void jl_print_native_codeloc (char * pre_str , uintptr_t ip ) JL_NOTSAFEPOINT
633636{
634637 // This function is not allowed to reference any TLS variables since
635638 // it can be called from an unmanaged thread on OSX.
@@ -641,10 +644,11 @@ void jl_print_native_codeloc(uintptr_t ip) JL_NOTSAFEPOINT
641644 for (i = 0 ; i < n ; i ++ ) {
642645 jl_frame_t frame = frames [i ];
643646 if (!frame .func_name ) {
644- jl_safe_printf ("unknown function (ip: %p)\n" , (void * )ip );
647+ jl_safe_printf ("%sunknown function (ip: %p)\n" , pre_str , (void * )ip );
645648 }
646649 else {
647- jl_safe_print_codeloc (frame .func_name , frame .file_name , frame .line , frame .inlined );
650+ jl_safe_print_codeloc (pre_str , frame .func_name ,
651+ frame .file_name , frame .line , frame .inlined );
648652 free (frame .func_name );
649653 free (frame .file_name );
650654 }
@@ -653,10 +657,17 @@ void jl_print_native_codeloc(uintptr_t ip) JL_NOTSAFEPOINT
653657}
654658
655659// Print code location for backtrace buffer entry at *bt_entry
656- void jl_print_bt_entry_codeloc (jl_bt_element_t * bt_entry ) JL_NOTSAFEPOINT
660+ void jl_print_bt_entry_codeloc (int sig , jl_bt_element_t * bt_entry ) JL_NOTSAFEPOINT
657661{
662+ char sig_str [32 ], pre_str [64 ];
663+ sig_str [0 ] = '\0' ;
664+ if (sig != -1 ) {
665+ snprintf (sig_str , 32 , "signal (%d) " , sig );
666+ }
667+ snprintf (pre_str , 64 , "%sthread (%d) " , sig_str , jl_threadid () + 1 );
668+
658669 if (jl_bt_is_native (bt_entry )) {
659- jl_print_native_codeloc (bt_entry [0 ].uintptr );
670+ jl_print_native_codeloc (pre_str , bt_entry [0 ].uintptr );
660671 }
661672 else if (jl_bt_entry_tag (bt_entry ) == JL_BT_INTERP_FRAME_TAG ) {
662673 size_t ip = jl_bt_entry_header (bt_entry );
@@ -682,7 +693,7 @@ void jl_print_bt_entry_codeloc(jl_bt_element_t *bt_entry) JL_NOTSAFEPOINT
682693 method = (jl_value_t * )((jl_method_t * )method )-> name ;
683694 if (jl_is_symbol (method ))
684695 func_name = jl_symbol_name ((jl_sym_t * )method );
685- jl_safe_print_codeloc (func_name , jl_symbol_name (locinfo -> file ),
696+ jl_safe_print_codeloc (pre_str , func_name , jl_symbol_name (locinfo -> file ),
686697 locinfo -> line , locinfo -> inlined_at );
687698 debuginfoloc = locinfo -> inlined_at ;
688699 }
@@ -1108,7 +1119,9 @@ static void jl_rec_backtrace(jl_task_t *t) JL_NOTSAFEPOINT
11081119
11091120JL_DLLEXPORT void jl_gdblookup (void * ip )
11101121{
1111- jl_print_native_codeloc ((uintptr_t )ip );
1122+ char pre_str [64 ];
1123+ snprintf (pre_str , 64 , "thread (%d) " , jl_threadid () + 1 );
1124+ jl_print_native_codeloc (pre_str , (uintptr_t )ip );
11121125}
11131126
11141127// Print backtrace for current exception in catch block
@@ -1123,7 +1136,7 @@ JL_DLLEXPORT void jlbacktrace(void) JL_NOTSAFEPOINT
11231136 size_t i , bt_size = jl_excstack_bt_size (s , s -> top );
11241137 jl_bt_element_t * bt_data = jl_excstack_bt_data (s , s -> top );
11251138 for (i = 0 ; i < bt_size ; i += jl_bt_entry_size (bt_data + i )) {
1126- jl_print_bt_entry_codeloc (bt_data + i );
1139+ jl_print_bt_entry_codeloc (-1 , bt_data + i );
11271140 }
11281141}
11291142
@@ -1136,7 +1149,7 @@ JL_DLLEXPORT void jlbacktracet(jl_task_t *t) JL_NOTSAFEPOINT
11361149 size_t i , bt_size = ptls -> bt_size ;
11371150 jl_bt_element_t * bt_data = ptls -> bt_data ;
11381151 for (i = 0 ; i < bt_size ; i += jl_bt_entry_size (bt_data + i )) {
1139- jl_print_bt_entry_codeloc (bt_data + i );
1152+ jl_print_bt_entry_codeloc (-1 , bt_data + i );
11401153 }
11411154}
11421155
0 commit comments