From e7cef6edd2dc9e6c8466f31a489ce0dfad807431 Mon Sep 17 00:00:00 2001 From: fearkov Date: Sat, 19 Sep 2026 14:33:07 -0400 Subject: [PATCH 1/2] Make the crash report useful when the stack is gone The report scans the guest stack for values that look like code and prints them as a call chain. That works until the thing that crashed is a block copy: the copy is a host memmove, its caller's frame is further up than the scan reaches, and if the copy ran past its buffer it has overwritten the stack on the way. The list then comes out empty under a confident heading, which reads as "nothing to see" rather than "the evidence is destroyed". Three additions, each of which earned its place on one crash: - Say so when nothing was found, instead of printing a heading and no list. - Print the indirect-call history. The stack cannot overwrite it, and on the crash this was written for it was the only thing that named a function -- and it named the right one. - Print the frame unfiltered, twenty words of it. The pointers and lengths handed to whatever faulted live there and look nothing like code, so the filter drops exactly what is wanted. One of them turned out to be the end of the mapped RAM mirror, which is what identified the fault as a copy running off its buffer rather than a bad pointer. --- templates/new-game/src/main.c | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/templates/new-game/src/main.c b/templates/new-game/src/main.c index 90d4744f..12f680a7 100644 --- a/templates/new-game/src/main.c +++ b/templates/new-game/src/main.c @@ -155,6 +155,35 @@ static void print_guest_context(void *rip) shown++; } } + /* When the frame is gone, say so, and fall back on what is left. + * + * A fault inside a block copy leaves no return address in range: the + * copy is a host memmove and its caller's frame is further up than + * this reaches. Worse, a copy that ran past its buffer overwrites the + * stack itself, so the list comes out empty exactly when it is most + * needed -- and an empty list under a promising heading reads like + * "nothing to see" rather than "the evidence is destroyed". */ + if (!shown) + fprintf(stderr, " (no return addresses in range)\n"); + + /* The indirect-call history, which the stack cannot overwrite. On the + * crash this was added for it was the only thing that named a + * function, and it named the right one. */ + { + extern volatile uint32_t g_icall_trace[16]; + extern volatile uint32_t g_icall_trace_idx; + uint32_t k; + fprintf(stderr, " recent ICALL targets:"); + for (k = 0; k < 16; k++) + fprintf(stderr, " %08X", + g_icall_trace[(g_icall_trace_idx + k) & 15]); + fprintf(stderr, "\n"); + } + + /* The frame unfiltered. The pointers and lengths handed to whatever + * faulted live here, and they look nothing like code. */ + for (i = 0; i < 20; i++) + fprintf(stderr, " raw[esp+%-4d] 0x%08X\n", i * 4, sp[i]); } } From 3a8dd39e2d47a85a97373a2638519a07da31f1ca Mon Sep 17 00:00:00 2001 From: fearkov Date: Sun, 20 Sep 2026 23:15:06 -0400 Subject: [PATCH 2/2] Only print the fallbacks when the scan found nothing Two things wrong with the first version, both found by reading it back rather than by running it. The twenty raw stack words printed on every crash, including the ones where the scan recovered the chain. The argument for them is that the filter drops exactly what is wanted -- pointers and lengths, which look nothing like code -- and that argument only holds when the filter came back empty. On a crash that already named the guest function, twenty more lines make the common report worse to read for no gain. Both fallbacks now sit behind the same `!shown` the "(no return addresses in range)" line uses. The ICALL dump also needed saying out loud that recomp_manual.c already prints this, from recomp_icall_fail_log. That is a different path: a page fault inside a block copy never reaches it. Same information, by the route the fault actually took. Worth a comment so the next reader does not delete one as a duplicate of the other. The local extern is deliberate and now says so: main.c does not include recomp_types.h, and recomp_manual.c spells the declaration the same way. --- templates/new-game/src/main.c | 35 +++++++++++++++++++++++++---------- 1 file changed, 25 insertions(+), 10 deletions(-) diff --git a/templates/new-game/src/main.c b/templates/new-game/src/main.c index 12f680a7..01a36312 100644 --- a/templates/new-game/src/main.c +++ b/templates/new-game/src/main.c @@ -166,24 +166,39 @@ static void print_guest_context(void *rip) if (!shown) fprintf(stderr, " (no return addresses in range)\n"); - /* The indirect-call history, which the stack cannot overwrite. On the - * crash this was added for it was the only thing that named a - * function, and it named the right one. */ - { + /* Everything below only pays for itself when the scan came back + * empty. A crash where the chain was recovered already says what + * happened, and burying that under another twenty lines makes the + * common report worse to read. */ + if (!shown) { + uint32_t k; + + /* The indirect-call history, which the stack cannot overwrite. + * recomp_manual.c prints this too, but only from + * recomp_icall_fail_log -- a page fault inside a block copy + * never reaches that path, and this is the same information by + * the route the fault actually took. + * + * Declared here rather than included: main.c does not pull in + * recomp_types.h, and recomp_manual.c spells it the same way. */ extern volatile uint32_t g_icall_trace[16]; extern volatile uint32_t g_icall_trace_idx; - uint32_t k; + fprintf(stderr, " recent ICALL targets:"); for (k = 0; k < 16; k++) fprintf(stderr, " %08X", g_icall_trace[(g_icall_trace_idx + k) & 15]); fprintf(stderr, "\n"); - } - /* The frame unfiltered. The pointers and lengths handed to whatever - * faulted live here, and they look nothing like code. */ - for (i = 0; i < 20; i++) - fprintf(stderr, " raw[esp+%-4d] 0x%08X\n", i * 4, sp[i]); + /* The frame unfiltered. The pointers and lengths handed to + * whatever faulted live here and look nothing like code, so the + * filter above drops exactly what is wanted. On the crash this + * was written for, one of these words was the end of the mapped + * RAM mirror -- which is what identified the fault as a copy + * running off its buffer rather than a stray pointer. */ + for (i = 0; i < 20; i++) + fprintf(stderr, " raw[esp+%-4d] 0x%08X\n", i * 4, sp[i]); + } } }