signals: Add thread name to unhandled signal message.

This commit is contained in:
squidbus 2024-11-29 08:33:12 -08:00
parent db888ab8b3
commit 6d2235809f

View File

@ -41,6 +41,14 @@ static LONG WINAPI SignalHandler(EXCEPTION_POINTERS* pExp) noexcept {
#else #else
static std::string GetThreadName() {
char name[256];
if (pthread_getname_np(pthread_self(), name, sizeof(name)) != 0) {
return "<unknown name>";
}
return std::string{name};
}
static std::string DisassembleInstruction(void* code_address) { static std::string DisassembleInstruction(void* code_address) {
char buffer[256] = "<unable to decode>"; char buffer[256] = "<unable to decode>";
@ -71,16 +79,18 @@ static void SignalHandler(int sig, siginfo_t* info, void* raw_context) {
case SIGBUS: { case SIGBUS: {
const bool is_write = Common::IsWriteError(raw_context); const bool is_write = Common::IsWriteError(raw_context);
if (!signals->DispatchAccessViolation(raw_context, info->si_addr)) { if (!signals->DispatchAccessViolation(raw_context, info->si_addr)) {
UNREACHABLE_MSG("Unhandled access violation at code address {}: {} address {}", UNREACHABLE_MSG(
fmt::ptr(code_address), is_write ? "Write to" : "Read from", "Unhandled access violation in thread '{}' at code address {}: {} address {}",
fmt::ptr(info->si_addr)); GetThreadName(), fmt::ptr(code_address), is_write ? "Write to" : "Read from",
fmt::ptr(info->si_addr));
} }
break; break;
} }
case SIGILL: case SIGILL:
if (!signals->DispatchIllegalInstruction(raw_context)) { if (!signals->DispatchIllegalInstruction(raw_context)) {
UNREACHABLE_MSG("Unhandled illegal instruction at code address {}: {}", UNREACHABLE_MSG("Unhandled illegal instruction in thread '{}' at code address {}: {}",
fmt::ptr(code_address), DisassembleInstruction(code_address)); GetThreadName(), fmt::ptr(code_address),
DisassembleInstruction(code_address));
} }
break; break;
case SIGUSR1: { // Sleep thread until signal is received case SIGUSR1: { // Sleep thread until signal is received