Add instruction tracing to step_fast and improve error messages

step_fast() never recorded trace entries, so crash dumps always showed
an empty trace. Now records PC + opcode info in the same deque as
step(). Also includes exception type in player-facing error messages
when the exception string is empty.
This commit is contained in:
Jared Miller 2026-02-10 18:29:27 -05:00
parent c8d9bdfae9
commit 5a98adb6ee
Signed by: shmup
GPG key ID: 22B5C6D66A38B06C
2 changed files with 14 additions and 3 deletions

View file

@ -165,7 +165,8 @@ class EmbeddedIFSession:
except Exception as e:
tb = traceback.format_exc()
logger.error(f"Interpreter crashed:\n{tb}")
self._error = f"interpreter error: {e}"
msg = str(e) or type(e).__name__
self._error = f"interpreter error: {msg}"
finally:
self._done = True
self._keyboard._waiting.set()

View file

@ -226,17 +226,27 @@ class ZCpu:
return table
def step_fast(self):
"""Execute a single instruction without tracing.
"""Execute a single instruction with lightweight tracing.
Returns True if execution should continue.
"""
current_pc = self._opdecoder.program_counter
(opcode_class, opcode_number, operands) = self._opdecoder.get_next_instruction()
entry = self._dispatch[opcode_class][opcode_number]
if entry is None:
raise ZCpuIllegalInstruction
self._trace.append(f" {current_pc:06x} ILLEGAL")
self._dump_trace()
raise ZCpuIllegalInstruction(
f"illegal opcode class={opcode_class} num={opcode_number}"
f" at PC={current_pc:#x}"
)
implemented, func = entry
if not implemented:
return False
self._trace.append(
f" {current_pc:06x} {func.__name__}"
f"({', '.join(str(x) for x in operands)})"
)
try:
func(self, *operands)
except (ZCpuQuit, ZCpuRestart):