-
Notifications
You must be signed in to change notification settings - Fork 6
GDB on Xous
To build, add --gdb-stub
to the xtask
command line argument:
cargo xtask app-image-xip --gdb-stub
Note that the target service being debugged can not be an XIP (flash-based) binary, because GDB depends upon being able to patch the binary to set breakpoints.
Then load the kernel into an image onto the target device.
To use, attach gdb to the serial port.
You can run GDB from your build machine, if you have wired up your device to a serial adapter (e.g. by powering up the debug HAT from a bench supply and using jumper cables to patch into an RS-232 adapter).
For example, to debug the ticktimer, you might run:
$ riscv-none-elf-gdb \
-ex 'tar ext \\.\COM43' \
-ex 'attach 2' \
target/riscv32imac-unknown-xous-elf/release/xous-ticktimer
This will load the xous-ticktimer
ELF file, then attach to the GDB server running on the serial port connected to COM43, then attach to process ID 2.
To set up a Raspberry Pi with the debug HAT:
- Load a RISC-V toolchain onto the Raspberry Pi (such as this one), and add it to your
PATH
- Load the custom kernel with
--gdb-stub
enabled (either via USB update or by thebetrusted-scripts
helpers) - Ensure that ttyS0 is configured for 115200 mode. This can be done by, for example, first running
screen -fn /dev/ttyS0 115200
and then quitting the session with key sequence ofctrl-a
then\
theny
. The baud rate configuration only has to happen once per boot. - Ensure that there are no open
screen
sessions or other serial terminals active on the RPi that are attached to the serial port (perhaps by runningps aux | grep -i screen
)
To debug using the Raspberry Pi:
- Boot the target, then type
console app
intoshellchat
. This switches the UART over to the GDB-owned UART. - Copy the binary for the server of interest to the Raspberry Pi
- Run the above command line with
'tar ext /dev/ttyS0'
as the external target specifier, and your target binary as the last argument. Ensure that the 'attach PID' argument uses the PID as enumerated in the build script output.
For example:
riscv-none-elf-gdb -ex 'tar ext /dev/ttyS0' -ex 'attach 27' ~/vault
You will then be able to use normal GDB commands to inspect memory, single-step, add breakpoints, and switch threads.
The info thr
command will list current threads. You may then switch threads with e.g. thr 4
to switch to thread 4.
The x
command can be used to examine arbitrary memory.
b
is used to insert breakpoints. Note that breakpoints are accomplished by replacing instructions in memory with c.ebreak
instructions, so debugging does not work with XIP processes.
c
will continue execution, and Control-C
will pause execution.
stepi
will single-step assembly execution.
You may switch processes with attach [PID]
When a process is under debug, messages will queue up. Interrupts are masked, and the process is paused.
When you continue
a process under debug, it is unpaused, interrupts are re-enabled, and messages are delivered.
When running this under Renode, a very recent copy (from April 2023 or later) is required. This also requires adjustments to the simulation models, which are included in this patchset.
If the serial link seems unstable, it may help to add
-ex 'set remote noack-packet off'
first in your GDB command list.
You can also use
-ex 'set debug remote 1'
to print debug info.