LibC: Reorder stack trace dump printing

If we fault while getting start of stack frame at least we now print
that we were trying to get the stack trace :^)
This commit is contained in:
2026-05-05 13:53:20 +03:00
parent 4b12770485
commit 47650980f2

View File

@@ -209,6 +209,18 @@ static void __dump_backtrace(int sig, siginfo_t*, void* context)
return "unknown signal";
};
// NOTE: we cannot use stddbg as that is not async-signal-safe.
// POSIX says dprintf isn't either but our implementation is!
int fd = open("/dev/debug", O_WRONLY);
if (fd == -1)
{
perror("failed to open debug device for backtrace");
return;
}
dprintf(fd, "received %s, backtrace:\n", signal_name(sig));
const auto* ucontext = static_cast<ucontext_t*>(context);
#if defined(__x86_64__)
const uintptr_t stack_base = ucontext->uc_mcontext.gregs[REG_RBP];
@@ -226,18 +238,6 @@ static void __dump_backtrace(int sig, siginfo_t*, void* context)
const auto* stackframe = reinterpret_cast<struct stackframe*>(stack_base);
// NOTE: we cannot use stddbf as that is not async-signal-safe.
// POSIX says dprintf isn't either but our implementation is!
int fd = open("/dev/debug", O_WRONLY);
if (fd == -1)
{
perror("failed to open debug device for backtrace");
return;
}
dprintf(fd, "received %s, backtrace:\n", signal_name(sig));
__dump_symbol(fd, reinterpret_cast<void*>(instruction));
for (size_t i = 0; i < 128 && stackframe; i++)
{