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