mirror of
https://github.com/RetroPortingToolKit/psxrecomp
synced 2026-10-27 10:38:46 -04:00
fdbd2b515f
Two distinct bugs were causing OPTIONS-black hard freezes after 12K-65K frames: 1. interrupts.c + traps.c: exception_jmpbuf is a single global. setjmp captures the running fiber, but longjmp may be requested from a different fiber via psx_exception_longjmp / psx_restore_state_escape during chain-handler dispatch. Cross-fiber longjmp restores RSP to the wrong stack while Win32 still tracks the calling fiber, corrupting fiber state until SwitchToFiber eventually hangs. Fix: track g_exception_owner_fiber at setjmp time. New deferred_exception_longjmp checks the current fiber; if it's not the owner, sets a pending flag and SwitchToFiber's back to the owner. psx_change_thread_fiber's post-SwitchToFiber path observes the flag and executes the longjmp on the correct stack. 2. gpu.c: gpu_read_gpustat fired gpu_vblank_tick() after 1000 polls, which invoked sdl_vblank_present (SDL_Delay -> Sleep) from inside an MMIO read code path. That meant recompiled MIPS spent wall time in Sleep deep inside the fiber call tree -- confusing to reason about and a contributor to fiber/longjmp interactions. Fix: synthetic VBLANK from a poll-storm only updates emulation state (LCF + I_STAT). The host-side render+sleep happens only at the proper cycle-paced VBLANK trigger in psx_check_interrupts. Also adds: dirty_block ring slice to the freeze auto-dump, Win32 main- thread stack capture for wedge_kind=1 hard freezes (SuspendThread + StackWalk64 + SymFromAddr), and dbghelp link. Validated: TombaRecomp psx-runtime ran 30+ minutes / 105K+ frames at OPTIONS with no hard freeze. Previous freezes consistently hit at 11900, 20493, and 64596 frames. Diagnostic tooling under tools/_options_session/ that produced this diagnosis is included. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
62 lines
2.3 KiB
Python
62 lines
2.3 KiB
Python
"""Map captured stack offsets to nearest preceding symbol from nm output."""
|
|
import subprocess, sys
|
|
|
|
# captured stack-frame offsets (relative to runtime image base)
|
|
offsets = [
|
|
("[ 2] SleepEx caller", 0x000B2219),
|
|
("[ 3]", 0x000B4E51),
|
|
("[ 4]", 0x000BE7F7),
|
|
("[ 5]", 0x00460B2D),
|
|
("[ 6]", 0x0063ECC7),
|
|
("[ 7]", 0x006B12B0),
|
|
("[ 8]", 0x000D889C),
|
|
("[ 9]", 0x0045FCF0),
|
|
("[10] dispatcher", 0x0045FDC9),
|
|
("[11]", 0x00011BC0A & 0xFFFFFF), # 0x11BC0A is unusual
|
|
("[12] dispatcher", 0x0045FC97),
|
|
("[14] dispatcher", 0x0045FDC9),
|
|
("[15]", 0x001A37AB),
|
|
("[16] dispatcher", 0x0045FC97),
|
|
("[18]", 0x00142516),
|
|
("[20]", 0x0013D8AC),
|
|
("[23]", 0x00144B00),
|
|
("[26]", 0x000B2B77),
|
|
("[27]", 0x006BB07C),
|
|
("[28]", 0x000B10C9),
|
|
("[29] start", 0x000B1416),
|
|
]
|
|
|
|
# Load nm output
|
|
nm = subprocess.run(
|
|
['nm', 'F:/Projects/TombaRecomp/build/psx-runtime.exe'],
|
|
capture_output=True, text=True
|
|
).stdout
|
|
|
|
# Build sorted list of (addr, name) for text symbols
|
|
syms = []
|
|
for line in nm.splitlines():
|
|
parts = line.split()
|
|
if len(parts) >= 3 and parts[1] in ('t','T','w','W'):
|
|
try:
|
|
a = int(parts[0], 16)
|
|
except:
|
|
continue
|
|
# filter to image-base range (0x140000000+ standard mingw)
|
|
if 0x140000000 <= a < 0x150000000:
|
|
syms.append((a - 0x140000000, ' '.join(parts[2:])))
|
|
syms.sort()
|
|
print(f"Loaded {len(syms)} text symbols")
|
|
|
|
import bisect
|
|
addrs = [a for a,_ in syms]
|
|
for label, off in offsets:
|
|
i = bisect.bisect_right(addrs, off) - 1
|
|
if i < 0:
|
|
print(f" {label}: offset 0x{off:08X} -> (before all symbols)")
|
|
continue
|
|
sym_off, sym_name = syms[i]
|
|
disp = off - sym_off
|
|
# only show if displacement is reasonable (< 0x10000 = 64KB)
|
|
note = "" if disp < 0x10000 else " (LARGE displacement — probably between symbols)"
|
|
print(f" {label}: offset 0x{off:08X} -> {sym_name} + 0x{disp:X}{note}")
|