Skip to content

Commit

Permalink
RAI: do not prepend thread ID to backtraces from signal handler context
Browse files Browse the repository at this point in the history
Also show the signal number when we have it.
  • Loading branch information
kpamnany authored and nickrobinson251 committed Jan 29, 2025
1 parent 5b64d22 commit 3f264ab
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 5 deletions.
2 changes: 1 addition & 1 deletion src/signals-unix.c
Original file line number Diff line number Diff line change
Expand Up @@ -1084,7 +1084,7 @@ static void *signal_listener(void *arg)
jl_safe_printf("\nsignal (%d): %s\n", sig, strsignal(sig));
size_t i;
for (i = 0; i < signal_bt_size; i += jl_bt_entry_size(signal_bt_data + i)) {
jl_print_bt_entry_codeloc(-1, signal_bt_data + i);
jl_print_bt_entry_codeloc(sig, signal_bt_data + i);
}
}
}
Expand Down
19 changes: 15 additions & 4 deletions src/stackwalk.c
Original file line number Diff line number Diff line change
Expand Up @@ -753,11 +753,14 @@ static void jl_print_debugloc(const char *pre_str, jl_debuginfo_t *debuginfo, jl
void jl_print_bt_entry_codeloc(int sig, jl_bt_element_t *bt_entry) JL_NOTSAFEPOINT
{
char sig_str[32], pre_str[64];
sig_str[0] = '\0';
sig_str[0] = pre_str[0] = '\0';
if (sig != -1) {
snprintf(sig_str, 32, "signal (%d) ", sig);
}
snprintf(pre_str, 64, "%sthread (%d) ", sig_str, jl_threadid() + 1);
// do not call jl_threadid if there's no current task
if (jl_get_current_task()) {
snprintf(pre_str, 64, "%sthread (%d) ", sig_str, jl_threadid() + 1);
}

if (jl_bt_is_native(bt_entry)) {
jl_print_native_codeloc(pre_str, bt_entry[0].uintptr);
Expand Down Expand Up @@ -1369,7 +1372,11 @@ JL_DLLEXPORT jl_record_backtrace_result_t jl_record_backtrace(jl_task_t *t, jl_b
JL_DLLEXPORT void jl_gdblookup(void* ip)
{
char pre_str[64];
snprintf(pre_str, 64, "thread (%d) ", jl_threadid() + 1);
pre_str[0] = '\0';
// do not call jl_threadid if there's no current task
if (jl_get_current_task()) {
snprintf(pre_str, 64, "thread (%d) ", jl_threadid() + 1);
}
jl_print_native_codeloc(pre_str, (uintptr_t)ip);
}

Expand Down Expand Up @@ -1429,7 +1436,11 @@ JL_DLLEXPORT void jl_print_task_backtraces(int show_done) JL_NOTSAFEPOINT

size_t nthreads = jl_atomic_load_acquire(&jl_n_threads);
jl_ptls_t *allstates = jl_atomic_load_relaxed(&jl_all_tls_states);
int ctid = jl_threadid() + 1;
int ctid = -1;
// do not call jl_threadid if there's no current task
if (jl_get_current_task()) {
ctid = jl_threadid() + 1;
}
jl_safe_printf("thread (%d) ++++ Task backtraces\n", ctid);
for (size_t i = 0; i < nthreads; i++) {
jl_ptls_t ptls2 = allstates[i];
Expand Down

0 comments on commit 3f264ab

Please sign in to comment.