Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ignore SEGV during profiler unwind on Unix #28291

Merged
merged 3 commits into from
Jul 30, 2018
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 18 additions & 3 deletions src/signals-unix.c
Original file line number Diff line number Diff line change
Expand Up @@ -220,11 +220,19 @@ static int jl_is_on_sigstack(jl_ptls_t ptls, void *ptr, void *context)
is_addr_on_sigstack(ptls, (void*)jl_get_rsp_from_ctx(context)));
}

volatile static int profiler_state = 0;
static ucontext_t profiler_uc;

static void segv_handler(int sig, siginfo_t *info, void *context)
{
jl_ptls_t ptls = jl_get_ptls_states();
assert(sig == SIGSEGV || sig == SIGBUS);

if (profiler_state == 1) {
profiler_state = 2;
setcontext(&profiler_uc);
}

if (jl_addr_is_safepoint((uintptr_t)info->si_addr)) {
#ifdef JULIA_ENABLE_THREADING
jl_set_gc_and_wait();
Expand Down Expand Up @@ -667,9 +675,16 @@ static void *signal_listener(void *arg)
// do backtrace for profiler
if (profile && running) {
if (bt_size_cur < bt_size_max - 1) {
// Get backtrace data
bt_size_cur += rec_backtrace_ctx((uintptr_t*)bt_data_prof + bt_size_cur,
bt_size_max - bt_size_cur - 1, signal_context);
profiler_state = 1;
getcontext(&profiler_uc);
if (profiler_state == 1) {
// Get backtrace data
bt_size_cur += rec_backtrace_ctx((uintptr_t*)bt_data_prof + bt_size_cur,
bt_size_max - bt_size_cur - 1, signal_context);
} else {
jl_safe_printf("WARNING: profiler attempt to access an invalid memory location\n");
Copy link
Sponsor Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there any risk of printing this message on each profile interval?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just mimicking

jl_safe_printf("WARNING: profiler attempt to access an invalid memory location\n");
. I agree it's not an interesting message for users though, but I've only seen it print at most a couple of times during nontrivial (1-10s) profile invocations.

Copy link
Sponsor Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok.

}

// Mark the end of this block with 0
bt_data_prof[bt_size_cur++] = 0;
}
Expand Down