From 0e62b4321a0f7200d361ef69a36ed14fb40e10de Mon Sep 17 00:00:00 2001 From: Dmitry Vyukov Date: Wed, 17 Jul 2024 10:09:21 +0200 Subject: executor: print signal info for SIGILL/SIGFPE as well There are also synchnous fatal signals that can happen due to bugs in executor code. So handle them as SIGSEGV. --- executor/executor_runner.h | 33 ++++++++++++++++++++++++--------- 1 file changed, 24 insertions(+), 9 deletions(-) (limited to 'executor') diff --git a/executor/executor_runner.h b/executor/executor_runner.h index 3481c052f..260d4a5de 100644 --- a/executor/executor_runner.h +++ b/executor/executor_runner.h @@ -727,7 +727,7 @@ static void SigchldHandler(int sig) // We need just blocking syscall preemption. } -static void SigsegvHandler(int sig, siginfo_t* info, void* ucontext) +static void FatalHandler(int sig, siginfo_t* info, void* ucontext) { // Print minimal debugging info we can extract reasonably easy. uintptr_t pc = 0xdeadbeef; @@ -740,11 +740,26 @@ static void SigsegvHandler(int sig, siginfo_t* info, void* ucontext) pc = mctx.pc; #endif #endif + const char* name = "unknown signal"; + switch (sig) { + case SIGSEGV: + name = "SIGSEGV"; + break; + case SIGBUS: + name = "SIGBUS"; + break; + case SIGILL: + name = "SIGILL"; + break; + case SIGFPE: + name = "SIGFPE"; + break; + } // Print the current function PC so that it's possible to map the failing PC // to a symbol in the binary offline (we usually compile as PIE). - failmsg(sig == SIGSEGV ? "SIGSEGV" : "SIGBUS", "handler:0x%zx pc:%p addr:%p", - reinterpret_cast(reinterpret_cast(SigsegvHandler)) - pc, - reinterpret_cast(pc), info->si_addr); + failmsg(name, "pc-offset:0x%zx pc:%p addr:%p code=%d", + reinterpret_cast(reinterpret_cast(FatalHandler)) - pc, + reinterpret_cast(pc), info->si_addr, info->si_code); } static void runner(char** argv, int argc) @@ -774,11 +789,11 @@ static void runner(char** argv, int argc) fail("signal(SIGCHLD) failed"); struct sigaction act = {}; act.sa_flags = SA_SIGINFO; - act.sa_sigaction = SigsegvHandler; - if (sigaction(SIGSEGV, &act, nullptr)) - fail("signal(SIGSEGV) failed"); - if (sigaction(SIGBUS, &act, nullptr)) - fail("signal(SIGBUS) failed"); + act.sa_sigaction = FatalHandler; + for (auto sig : {SIGSEGV, SIGBUS, SIGILL, SIGFPE}) { + if (sigaction(sig, &act, nullptr)) + failmsg("sigaction failed", "sig=%d", sig); + } Connection conn(manager_addr, manager_port); -- cgit mrf-deployment