Skip to content

Commit

Permalink
Fix segfault if root task is NULL (#51471)
Browse files Browse the repository at this point in the history
In `jl_print_task_backtraces()`. Follow-on to
#51430.

(cherry picked from commit cde964f)
  • Loading branch information
kpamnany authored and KristofferC committed Nov 27, 2023
1 parent e4ad8ab commit 4120fd8
Showing 1 changed file with 16 additions and 9 deletions.
25 changes: 16 additions & 9 deletions src/stackwalk.c
Original file line number Diff line number Diff line change
Expand Up @@ -1152,23 +1152,30 @@ JL_DLLEXPORT void jl_print_task_backtraces(int show_done) JL_NOTSAFEPOINT
jl_ptls_t *allstates = jl_atomic_load_relaxed(&jl_all_tls_states);
for (size_t i = 0; i < nthreads; i++) {
jl_ptls_t ptls2 = allstates[i];
if (ptls2 == NULL)
if (ptls2 == NULL) {
continue;
}
small_arraylist_t *live_tasks = &ptls2->heap.live_tasks;
size_t n = mtarraylist_length(live_tasks);
int t_state = JL_TASK_STATE_DONE;
jl_task_t *t = ptls2->root_task;
int t_state = jl_atomic_load_relaxed(&t->_state);
if (t != NULL)
t_state = jl_atomic_load_relaxed(&t->_state);
jl_safe_printf("==== Thread %d created %zu live tasks\n",
ptls2->tid + 1, n + (t_state != JL_TASK_STATE_DONE));
if (show_done || t_state != JL_TASK_STATE_DONE) {
jl_safe_printf(" ---- Root task (%p)\n", ptls2->root_task);
jl_safe_printf(" (sticky: %d, started: %d, state: %d, tid: %d)\n",
t->sticky, t->started, t_state,
jl_atomic_load_relaxed(&t->tid) + 1);
if (t->stkbuf != NULL)
jlbacktracet(t);
else
jl_safe_printf(" no stack\n");
if (t != NULL) {
jl_safe_printf(" (sticky: %d, started: %d, state: %d, tid: %d)\n",
t->sticky, t->started, t_state,
jl_atomic_load_relaxed(&t->tid) + 1);
if (t->stkbuf != NULL) {
jlbacktracet(t);
}
else {
jl_safe_printf(" no stack\n");
}
}
jl_safe_printf(" ---- End root task\n");
}

Expand Down

0 comments on commit 4120fd8

Please sign in to comment.