mirror of
https://github.com/valentderah/totk-pc-recomp.git
synced 2026-11-19 20:25:57 +00:00
Report host registers, code bytes and memory at a crash
The crash report named the lifted function and printed the guest registers, but the lifted code keeps guest registers in host locals and writes them back only at calls, so the dump showed stale values and the faulting instruction stayed unknown. Logs from #1005, #967 and #998 could not be traced further than the function. The report now adds the x86 registers of the faulting thread (Windows and Linux), 64 bytes of machine code around rip with the offset into the lifted function, so the instruction can be found in a local build of the same version, 64 bytes of memory around every register value that points at readable memory, and the first 128 bytes of the guest stack. --probe-kernel checks the new lines with a child that faults with known values in rbx and x19. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
7e440be7ca
commit
06d70d0dfa
5 files changed
+149
-5
No files matched your search
@@ -957,6 +957,10 @@ static void fault_handler(int sig, siginfo_t *si, void *uc) {
|
||||
}
|
||||
if (sig == SIGSEGV || sig == SIGBUS)
|
||||
c.access = (err & 16) ? 8 : (err & 2) ? 1 : 0, c.addr = (uint64_t)(uintptr_t)si->si_addr;
|
||||
static const int gr[16] = {REG_RAX, REG_RCX, REG_RDX, REG_RBX, REG_RSP, REG_RBP, REG_RSI, REG_RDI,
|
||||
REG_R8, REG_R9, REG_R10, REG_R11, REG_R12, REG_R13, REG_R14, REG_R15};
|
||||
for (int i = 0; i < 16; i++) c.gpr[i] = (uint64_t)u->uc_mcontext.gregs[gr[i]];
|
||||
c.has_regs = 1;
|
||||
crash_fn(&c);
|
||||
}
|
||||
signal(sig, SIG_DFL); // returns into the faulting instruction, which faults again with the default action
|
||||
|
||||
@@ -249,7 +249,11 @@ typedef struct {
|
||||
const char *module; // the module holding rip: NULL for this executable, "" for none (a jump to address 0)
|
||||
const char *cxx_type; // a C++ exception from MSVC-built code: the thrown type's decorated name (.?AV...@@)
|
||||
const char *cxx_what; // and what() when the type derives from std::exception; NULL when unknown
|
||||
int has_regs; // gpr holds the faulting thread's registers (a fault; not abort or invalid parameter)
|
||||
uint64_t gpr[16]; // rax rcx rdx rbx rsp rbp rsi rdi r8..r15, in the x86 encoding order
|
||||
} PlatCrash;
|
||||
#define PLAT_GPR_NAMES {"rax", "rcx", "rdx", "rbx", "rsp", "rbp", "rsi", "rdi", \
|
||||
"r8", "r9", "r10", "r11", "r12", "r13", "r14", "r15"}
|
||||
void plat_crash_hook(void (*fn)(const PlatCrash *c));
|
||||
int plat_mem_read(uint64_t addr, void *out, size_t n); // copies n bytes, 0 instead of faulting on unmapped memory
|
||||
int plat_screen_size(int *w, int *h); // the primary display's current mode in pixels; 0 unknown
|
||||
|
||||
@@ -736,6 +736,14 @@ void plat_mem_fault_hook(int (*fn)(uint64_t addr)) {
|
||||
|
||||
static void (*crash_fn)(const PlatCrash *c);
|
||||
|
||||
// The faulting thread's general registers, for the report to tie the faulting instruction to its operands.
|
||||
static void regs_of(const CONTEXT *x, PlatCrash *c) {
|
||||
const DWORD64 r[16] = {x->Rax, x->Rcx, x->Rdx, x->Rbx, x->Rsp, x->Rbp, x->Rsi, x->Rdi,
|
||||
x->R8, x->R9, x->R10, x->R11, x->R12, x->R13, x->R14, x->R15};
|
||||
for (int i = 0; i < 16; i++) c->gpr[i] = r[i];
|
||||
c->has_regs = 1;
|
||||
}
|
||||
|
||||
static LONG WINAPI crash_filter(EXCEPTION_POINTERS *ep);
|
||||
|
||||
static LONG CALLBACK crash_veh(EXCEPTION_POINTERS *ep) {
|
||||
@@ -758,6 +766,7 @@ static LONG CALLBACK crash_veh(EXCEPTION_POINTERS *ep) {
|
||||
PlatCrash c = {what, (uint32_t)code, rip, rip - (uintptr_t)mi.lpBaseOfDll, -1, 0};
|
||||
if (code == EXCEPTION_ACCESS_VIOLATION && ep->ExceptionRecord->NumberParameters >= 2)
|
||||
c.access = (int)ep->ExceptionRecord->ExceptionInformation[0], c.addr = ep->ExceptionRecord->ExceptionInformation[1];
|
||||
regs_of(ep->ContextRecord, &c);
|
||||
crash_fn(&c);
|
||||
return EXCEPTION_CONTINUE_SEARCH;
|
||||
}
|
||||
@@ -895,6 +904,7 @@ static LONG WINAPI crash_filter(EXCEPTION_POINTERS *ep) {
|
||||
(uint32_t)code, rip, 0, -1, 0};
|
||||
if (code == EXCEPTION_ACCESS_VIOLATION && er->NumberParameters >= 2)
|
||||
c.access = (int)er->ExceptionInformation[0], c.addr = er->ExceptionInformation[1];
|
||||
regs_of(ep->ContextRecord, &c);
|
||||
void *base = NULL;
|
||||
RtlPcToFileHeader((void *)rip, &base);
|
||||
uintptr_t exe = (uintptr_t)GetModuleHandleW(NULL);
|
||||
|
||||
Reference in new issue
Block a user