Repository: JuliaLang/julia
File: src/stackwalk.c (C)

Code before:
    jl_print_native_codeloc((uintptr_t)ip);
}

// Print backtrace for current exception in catch block
JL_DLLEXPORT void jlbacktrace(void) JL_NOTSAFEPOINT
{
    jl_task_t *ct = jl_current_task;
    if (ct->ptls == NULL)
        return;
    jl_excstack_t *s = ct->excstack;
    if (!s)
        return;
    size_t i, bt_size = jl_excstack_bt_size(s, s->top);
    jl_bt_element_t *bt_data = jl_excstack_bt_data(s, s->top);
    for (i = 0; i < bt_size; i += jl_bt_entry_size(bt_data + i)) {
        jl_print_bt_entry_codeloc(bt_data + i);
    }
}

// Print backtrace for specified task to jl_safe_printf stderr
JL_DLLEXPORT void jlbacktracet(jl_task_t *t) JL_NOTSAFEPOINT
{
    jl_bt_element_t *bt_data;
    jl_task_t *ct = jl_current_task;
    size_t max_bt_size;
    if (ct->ptls != NULL) {
        jl_ptls_t ptls = ct->ptls;
        ptls->bt_size = 0;
        bt_data = ptls->bt_data;
        max_bt_size = JL_MAX_BT_SIZE;
    } else {
        max_bt_size = 1024; //8kb of stack should be safe
        bt_data = (jl_bt_element_t *)alloca(max_bt_size * sizeof(jl_bt_element_t));
    }
    jl_record_backtrace_result_t r = jl_record_backtrace(t, bt_data, max_bt_size, 0);
    size_t bt_size = r.bt_size;
    size_t i;
    for (i = 0; i < bt_size; i += jl_bt_entry_size(bt_data + i)) {
        jl_print_bt_entry_codeloc(bt_data + i);
    }
    if (bt_size == 0)
        jl_safe_printf("      no backtrace recorded\n");
}

JL_DLLEXPORT void jl_print_backtrace(void) JL_NOTSAFEPOINT
{
    jlbacktrace();
}

// Print backtraces for all live tasks, for all threads, to jl_safe_printf stderr
JL_DLLEXPORT void jl_print_task_backtraces(int show_done) JL_NOTSAFEPOINT

Review comment (suggestion):
```suggestion
    if (ct && ct->ptls != NULL) {
```

Code after:
    jl_fprint_native_codeloc(ios_safe_stderr, (uintptr_t)ip);
}

// Print backtrace for current exception in catch block
JL_DLLEXPORT void jl_fprint_backtrace(ios_t *s) JL_NOTSAFEPOINT
{
    jl_task_t *ct = jl_current_task;
    if (ct->ptls == NULL)
        return;
    jl_excstack_t *stack = ct->excstack;
    if (!stack)
        return;
    size_t i, bt_size = jl_excstack_bt_size(stack, stack->top);
    jl_bt_element_t *bt_data = jl_excstack_bt_data(stack, stack->top);
    for (i = 0; i < bt_size; i += jl_bt_entry_size(bt_data + i)) {
        jl_fprint_bt_entry_codeloc(s, bt_data + i);
    }
}

JL_DLLEXPORT void jlbacktrace(void) JL_NOTSAFEPOINT
{
    jl_fprint_backtrace(ios_safe_stderr);
}

JL_DLLEXPORT void jl_print_backtrace(void) JL_NOTSAFEPOINT
{
    jl_fprint_backtrace(ios_safe_stderr);
}

// Print backtrace for specified task to `s`
JL_DLLEXPORT void jl_fprint_backtracet(ios_t *s, jl_task_t *t) JL_NOTSAFEPOINT
{
    jl_bt_element_t *bt_data;
    jl_task_t *ct = jl_get_current_task();
    size_t max_bt_size;
    if (ct && ct->ptls != NULL) {
        jl_ptls_t ptls = ct->ptls;
        ptls->bt_size = 0;
        bt_data = ptls->bt_data;
        max_bt_size = JL_MAX_BT_SIZE;
    } else {
        max_bt_size = 1024; //8kb of stack should be safe
        bt_data = (jl_bt_element_t *)alloca(max_bt_size * sizeof(jl_bt_element_t));
    }
    jl_record_backtrace_result_t r = jl_record_backtrace(t, bt_data, max_bt_size, 0);
    size_t bt_size = r.bt_size;
    size_t i;
    for (i = 0; i < bt_size; i += jl_bt_entry_size(bt_data + i)) {
        jl_fprint_bt_entry_codeloc(s, bt_data + i);
    }
    if (bt_size == 0)