Crashes and debugging
What a crash looks like
With no handler, a CPU fault (bad pointer, misaligned access in write-combined memory, illegal instruction) gives a black screen. Within 1-2 s the console is back in the dashboard. Nothing is logged.
A stack overflow hangs the console whether there is a handler or not: the kernel puts the exception record on the overflowed stack. Hold the power button.
crash.txt
xexkit installs a vectored exception handler before the constructors run (RtlSetVectoredExceptionHandler, ordinal 0x36D, the handler passed as both arguments; xsdk found this on hardware). For a fault in the title's own code it writes game:/crash.txt, then ends the title:
xexkit: title crashed: access violation (code c0000005) at 820876b0
read of address f687cc9a
IAR 820876b0 LR 82085bf8 CTR 00000000 CR 44000244 XER 00000000
r0 ...
stack:
82085bf8
8203add0
...
Look the addresses up with the ELF of the same build:
docker run --rm -v $PWD:/src -w /src free60/libxenon:latest \
xenon-addr2line -f -C -e build/mygame/app.elf 820876b0 82085bf8 8203add0
The context layout (xsdk's probe): IAR at +0x08, LR at +0x0C, CTR at +0x10, r0-r31 as 64-bit values from +0x18, CR at +0x118, XER at +0x11C.
Faults outside the title's code are passed on (return 0). The handler is called with the console ABI, so it goes through xbox360_entry. Keep the handler simple: our first version also showed a notification and slept, and it froze the console after writing the report.
Logging
DbgPrintoutput (stdout/stderr go there) shows in Xenia's log with--log_level=4. On a retail console nothing reads it.- Write a log file and close it after every line (
fopen("a")…fclose), so a crash or hang can't lose it. Fetch it over FTP. - Log the build id and time on the first line. It is the only way to be
sure the console runs the build you think it runs; see Pitfalls.
Finding hardware-only bugs
Our approach, which found the black screen, the LUT and the USB bug:
- A small test XEX that logs every step to
game:/...-log.txt. - Dump the registers or state involved before and after each step.
- Try one change per run, or several in timed phases ("phase 2 at 6 s: …"),
and have the person at the TV report when the picture changed.
- Compare with what Xenia, libxenon and xsdk say. Xenia is not the console;
see Xenia vs. hardware.
- A capture card or a camera pointed at the TV helps. So does a test that
makes timing visible, like the flash and click of
tests/audio.