Add an example host to demonstrate gdbstub

This commit is contained in:
Hamid Rostami 2026-04-15 22:41:54 +01:00
parent 1f7132e1e8
commit faecd6bbef
4 changed files with 2000 additions and 0 deletions

View file

@ -0,0 +1,29 @@
# Why?
To debug your guest application. GDB can attach to the host over TCP socket, stdio,
serial connection, etc. In the provided example, it communicate over stdio, however
using `socat` it can be redirected to a TCP socket.
# How to use it
1. Compile a guest application, for example from [apps](../../apps/) directory.
To have a better debugging experience, use `-O0` and `-g3`.
2. Run the host prividing the app binary file. Use the following command to
redirect stdio to a TCP socket:
```
socat -v -x
TCP-LISTEN:1234,reuseaddr \
EXEC:"./host-gdbstub ../../apps/maze/maze.bin"
```
`-v` and `-x` are used to see the traffic in hex.
3. Fire up a `riscv32-elf-gdb` (might be different name on your OS) and give
it the generated elf file from step 1:
`riscv32-elf-gdb -ex 'target remote :1234' -ex 'layout src' maze.elf`
4. Happy debugging. `s`, `si`, `n`, breakpoint, etc should be working :)