@@ -637,22 +637,25 @@ JL_DLLEXPORT jl_value_t *jl_lookup_code_address(void *ip, int skipC)
637
637
return rs ;
638
638
}
639
639
640
- static void jl_safe_print_codeloc (const char * func_name , const char * file_name ,
640
+ static void jl_safe_print_codeloc (const char * pre_str ,
641
+ const char * func_name , const char * file_name ,
641
642
int line , int inlined ) JL_NOTSAFEPOINT
642
643
{
643
644
const char * inlined_str = inlined ? " [inlined]" : "" ;
644
645
if (line != -1 ) {
645
- jl_safe_printf ("%s at %s:%d%s\n" , func_name , file_name , line , inlined_str );
646
+ jl_safe_printf ("%s%s at %s:%d%s\n" ,
647
+ pre_str , func_name , file_name , line , inlined_str );
646
648
}
647
649
else {
648
- jl_safe_printf ("%s at %s (unknown line)%s\n" , func_name , file_name , inlined_str );
650
+ jl_safe_printf ("%s%s at %s (unknown line)%s\n" ,
651
+ pre_str , func_name , file_name , inlined_str );
649
652
}
650
653
}
651
654
652
655
// Print function, file and line containing native instruction pointer `ip` by
653
656
// looking up debug info. Prints multiple such frames when `ip` points to
654
657
// inlined code.
655
- void jl_print_native_codeloc (uintptr_t ip ) JL_NOTSAFEPOINT
658
+ void jl_print_native_codeloc (char * pre_str , uintptr_t ip ) JL_NOTSAFEPOINT
656
659
{
657
660
// This function is not allowed to reference any TLS variables since
658
661
// it can be called from an unmanaged thread on OSX.
@@ -664,10 +667,11 @@ void jl_print_native_codeloc(uintptr_t ip) JL_NOTSAFEPOINT
664
667
for (i = 0 ; i < n ; i ++ ) {
665
668
jl_frame_t frame = frames [i ];
666
669
if (!frame .func_name ) {
667
- jl_safe_printf ("unknown function (ip: %p) at %s\n" , (void * )ip , frame .file_name ? frame .file_name : "(unknown file)" );
670
+ jl_safe_printf ("%sunknown function (ip: %p) at %s\n" , pre_str , (void * )ip , frame .file_name ? frame .file_name : "(unknown file)" );
668
671
}
669
672
else {
670
- jl_safe_print_codeloc (frame .func_name , frame .file_name , frame .line , frame .inlined );
673
+ jl_safe_print_codeloc (pre_str , frame .func_name ,
674
+ frame .file_name , frame .line , frame .inlined );
671
675
free (frame .func_name );
672
676
}
673
677
free (frame .file_name );
@@ -725,7 +729,7 @@ const char *jl_debuginfo_name(jl_value_t *func)
725
729
726
730
// func == module : top-level
727
731
// func == NULL : macro expansion
728
- static void jl_print_debugloc (jl_debuginfo_t * debuginfo , jl_value_t * func , size_t ip , int inlined ) JL_NOTSAFEPOINT
732
+ static void jl_print_debugloc (const char * pre_str , jl_debuginfo_t * debuginfo , jl_value_t * func , size_t ip , int inlined ) JL_NOTSAFEPOINT
729
733
{
730
734
if (!jl_is_symbol (debuginfo -> def )) // this is a path or
731
735
func = debuginfo -> def ; // this is inlined code
@@ -734,26 +738,33 @@ static void jl_print_debugloc(jl_debuginfo_t *debuginfo, jl_value_t *func, size_
734
738
if (edges_idx ) {
735
739
jl_debuginfo_t * edge = (jl_debuginfo_t * )jl_svecref (debuginfo -> edges , edges_idx - 1 );
736
740
assert (jl_typetagis (edge , jl_debuginfo_type ));
737
- jl_print_debugloc (edge , NULL , stmt .pc , 1 );
741
+ jl_print_debugloc (pre_str , edge , NULL , stmt .pc , 1 );
738
742
}
739
743
intptr_t ip2 = stmt .line ;
740
744
if (ip2 >= 0 && ip > 0 && (jl_value_t * )debuginfo -> linetable != jl_nothing ) {
741
- jl_print_debugloc (debuginfo -> linetable , func , ip2 , 0 );
745
+ jl_print_debugloc (pre_str , debuginfo -> linetable , func , ip2 , 0 );
742
746
}
743
747
else {
744
748
if (ip2 < 0 ) // set broken debug info to ignored
745
749
ip2 = 0 ;
746
750
const char * func_name = jl_debuginfo_name (func );
747
751
const char * file = jl_debuginfo_file (debuginfo );
748
- jl_safe_print_codeloc (func_name , file , ip2 , inlined );
752
+ jl_safe_print_codeloc (pre_str , func_name , file , ip2 , inlined );
749
753
}
750
754
}
751
755
752
756
// Print code location for backtrace buffer entry at *bt_entry
753
- void jl_print_bt_entry_codeloc (jl_bt_element_t * bt_entry ) JL_NOTSAFEPOINT
757
+ void jl_print_bt_entry_codeloc (int sig , jl_bt_element_t * bt_entry ) JL_NOTSAFEPOINT
754
758
{
759
+ char sig_str [32 ], pre_str [64 ];
760
+ sig_str [0 ] = '\0' ;
761
+ if (sig != -1 ) {
762
+ snprintf (sig_str , 32 , "signal (%d) " , sig );
763
+ }
764
+ snprintf (pre_str , 64 , "%sthread (%d) " , sig_str , jl_threadid () + 1 );
765
+
755
766
if (jl_bt_is_native (bt_entry )) {
756
- jl_print_native_codeloc (bt_entry [0 ].uintptr );
767
+ jl_print_native_codeloc (pre_str , bt_entry [0 ].uintptr );
757
768
}
758
769
else if (jl_bt_entry_tag (bt_entry ) == JL_BT_INTERP_FRAME_TAG ) {
759
770
size_t ip = jl_bt_entry_header (bt_entry ); // zero-indexed
@@ -772,7 +783,7 @@ void jl_print_bt_entry_codeloc(jl_bt_element_t *bt_entry) JL_NOTSAFEPOINT
772
783
if (jl_is_code_info (code )) {
773
784
jl_code_info_t * src = (jl_code_info_t * )code ;
774
785
// See also the debug info handling in codegen.cpp.
775
- jl_print_debugloc (src -> debuginfo , def , ip + 1 , 0 );
786
+ jl_print_debugloc (pre_str , src -> debuginfo , def , ip + 1 , 0 );
776
787
}
777
788
else {
778
789
// If we're using this function something bad has already happened;
@@ -1361,7 +1372,9 @@ JL_DLLEXPORT jl_record_backtrace_result_t jl_record_backtrace(jl_task_t *t, jl_b
1361
1372
1362
1373
JL_DLLEXPORT void jl_gdblookup (void * ip )
1363
1374
{
1364
- jl_print_native_codeloc ((uintptr_t )ip );
1375
+ char pre_str [64 ];
1376
+ snprintf (pre_str , 64 , "thread (%d) " , jl_threadid () + 1 );
1377
+ jl_print_native_codeloc (pre_str , (uintptr_t )ip );
1365
1378
}
1366
1379
1367
1380
// Print backtrace for current exception in catch block
@@ -1376,7 +1389,7 @@ JL_DLLEXPORT void jlbacktrace(void) JL_NOTSAFEPOINT
1376
1389
size_t i , bt_size = jl_excstack_bt_size (s , s -> top );
1377
1390
jl_bt_element_t * bt_data = jl_excstack_bt_data (s , s -> top );
1378
1391
for (i = 0 ; i < bt_size ; i += jl_bt_entry_size (bt_data + i )) {
1379
- jl_print_bt_entry_codeloc (bt_data + i );
1392
+ jl_print_bt_entry_codeloc (-1 , bt_data + i );
1380
1393
}
1381
1394
}
1382
1395
@@ -1391,7 +1404,7 @@ JL_DLLEXPORT void jlbacktracet(jl_task_t *t) JL_NOTSAFEPOINT
1391
1404
size_t bt_size = r .bt_size ;
1392
1405
size_t i ;
1393
1406
for (i = 0 ; i < bt_size ; i += jl_bt_entry_size (bt_data + i )) {
1394
- jl_print_bt_entry_codeloc (bt_data + i );
1407
+ jl_print_bt_entry_codeloc (-1 , bt_data + i );
1395
1408
}
1396
1409
if (bt_size == 0 )
1397
1410
jl_safe_printf (" no backtrace recorded\n" );
0 commit comments