Install gdbserver on PATH (and gdb for the MCP tools below). -S enables the native-code stub on loopback port 1234
(the QEMU default port). The game runs until a debugger connects.
-s enables the stub and waits before runtime initialization. It implies -S.
./build/scarletnx -s "Game.xci"
# Or: recompiled/<id>/<id> -Hs
In GDB, load the deployed executable's symbols and connect:
file recompiled/Game/Game
tar rem :1234
continue
The launcher prints a connection hint before waiting. A separate helper keeps accepting
connections while the game is stopped, then delegates the remote protocol to gdbserver.
The stub debugs host/native registers and code, not an emulated ARM64 CPU. It supports one
connection per run. Local ptrace permissions must allow attachment. Binding failures and
missing gdbserver are reported instead of silently running without a debugger.
No debugger flags or combined short flags are supported on Windows.
The recompiled game module is a shared library with a symbol for each function, so GDB names game
frames as it loads. A 64-bit game's functions are F_<address>, and a 32-bit game's blocks are
A_<address> (A32) and T_<address> (Thumb). Code the JIT compiles at run time lives in an
anonymous code arena. With --gdb-jit=1 (the [Debug] setting gdb_jit) and the stub (-S or
-s), the runtime hands each compile to GDB through its JIT interface, with its symbols. A 32-bit
game's are a32_<address>_<thumb>. GDB stops the whole game to read each compile while it is
attached, and again for each at the game's end. That slows a 32-bit game (its blocks compile one
at a time) to a crawl, so it is off by default. Without the stub the setting does nothing.
The runtime handles SIGSEGV and SIGBUS itself: memory it moves while a thread writes to it stops
that thread on a fault, and a crash's fault writes the crash report. Tell GDB
handle SIGSEGV SIGBUS nostop noprint pass and break on crash_report to stop only at a crash.
A SIGSEGV or SIGBUS another process sends (kill -SEGV, or GDB's signal SIGSEGV) is not a
crash. The runtime prints a line saying so and runs on.
An agent can drive GDB through the MCP server (scarletnx --mcp). It needs gdb (9 or later)
on PATH as well as gdbserver, and a runtime with its debug information (the default
RelWithDebInfo build, not one built with -g0).
gdb_attach connects to a game started with -S or -s and stops it. It sets the handle
line above and a breakpoint on crash_report. Given the game (a folder, a game of work/ or a
title ID, of the same version), the other tools name guest addresses and the symbols above by
the game's own symbols. The stub takes one connection per run, so a second attach is refused.gdb_command runs one GDB command from a list of reading, breakpoint and execution commands
(backtrace, info, print, x, frame, thread, break, watch, set var and the
like), by GDB's names, aliases and unambiguous prefixes. Shells, scripts, file writes, command
bodies (commands, define, if, while) and session changes are refused. print and
call still run the game's own functions. A resume (continue, next, step, finish and
the rest) runs in the background and waits up to wait seconds for the game to stop at a
breakpoint or a crash, then interrupts it. With wait 0 the game runs on, and only
interrupt is taken until it stops.gdb_threads lists each host thread, and each guest thread's id, its SDK name, whether it is
in an SVC and its guest pc and lr. It finds a guest thread through its host thread's TLS, which
GDB reads with the C library's libthread_db. Without it (a musl build) every thread is listed
as the runtime's.gdb_guest shows a guest thread's registers and its guest backtrace from its frame records.gdb_memory reads guest memory. A page the GPU holds can't be read until the game's CPU
touches it.gdb_detach lets the game run on without the debugger.Made from docs/user/usage.md at 69237645142c. GPL-3.0-or-later.