Xous is capable of debugging userspace processes via GDB over serial.
To do this, you need to do the following:
- Compile using the
--gdb-stubargument toxtask - Flash all the built artifacts into the device
- Connect a physical serial port to the serial wires (on dabao, that would be PB14 for dabao->host, and PB13 for host->dabao).
- Ensure you have a recent version of GDB installed. Some compatibility issues were seen in older verisons of GDB.
Once these prerequisites are satisfied, you can attempt to debug a binary by starting GDB pointing to the ELF file of the binary. For example, to debug dabao-console, you might use
riscv-none-elf-gdb target/riscv32imac-unknown-xous-elf/release/dabao-console
Once inside GDB, you might have a session like this:
$ riscv-none-elf-gdb dabao-console
GNU gdb (xPack GNU RISC-V Embedded GCC aarch64) 16.3
Copyright (C) 2024 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
Type "show copying" and "show warranty" for details.
This GDB was configured as "--host=aarch64-unknown-linux-gnu --target=riscv-none-elf".
Type "show configuration" for configuration details.
For bug reporting instructions, please see:
<https://www.gnu.org/software/gdb/bugs/>.
Find the GDB manual and other documentation resources online at:
<http://www.gnu.org/software/gdb/documentation/>.
For help, type "help".
Type "apropos word" to search for commands related to "word"...
Reading symbols from dabao-console...
(No debugging symbols found in dabao-console)
(gdb) tar ext /dev/ttyUSB0
Remote debugging using /dev/ttyUSB0
(gdb) mon pr
Available processes:
1 kernel
2 xous-ticktimer
3 keystore
4 xous-log
5 xous-names
6 usb-bao1x
7 bao1x-hal-service
8
(gdb) mon pr 8
Now debugging PID 8
(gdb) info thr
[New Thread 8.2]
[New Thread 8.3]
Id Target Id Frame
* 1 Thread 8.2 0x00044066 in <xous_api_log::XousLogger as log::Log>::log ()
2 Thread 8.3 0x00044066 in <xous_api_log::XousLogger as log::Log>::log ()
(gdb) info reg
ra 0x439b0 0x439b0 <xous::arch::riscv::syscall::syscall+1038>
sp 0x7ffffca0 0x7ffffca0
gp 0x0 0x0
tp 0x60000000 0x60000000
t0 0x7ffffcb8 2147482808
t1 0x15 21
t2 0x43e9a 278170
fp 0x7ffffd2c 0x7ffffd2c
s1 0x1 1
a0 0xe 14
a1 0x0 0
a2 0x0 0
a3 0x0 0
a4 0x0 0
a5 0x0 0
a6 0x0 0
a7 0x0 0
s2 0x20000110 536871184
s3 0x20000300 536871680
s4 0x1 1
s5 0x0 0
s6 0x3 3
s7 0x0 0
s8 0x7 7
s9 0xff2b38ff -13944577
s10 0x0 0
s11 0xfefefeff -16843009
t3 0x44088 278664
t4 0xdb7b2cae -612684626
t5 0xf0f599ba -252339782
t6 0x7ffffcf8 2147482872
pc 0x44066 0x44066 <<xous_api_log::XousLogger as log::Log>::log+460>This is about as far as I can get with the GDB session. There is a feature where in order to do breakpoints, in theory, but I don't know how to use them or how to test them. Maybe someone else can try them out and share what commands seem useful.
I could also use @xobs code review of poke_memory:
Whenever you get a chance. I think this is not a huge hurry, because I'm not a GDB user myself, but given the noises that were made at Congress about the dissatisfaction over not having GDB I'm guessing eventually someone is going to have to tilt at this windmill, ideally someone who actually uses GDB and understand the protocol.
Hey @bunnie I tried quickly on a Renode simulation for Precursor with shellchat. It looks like I can set breakpoints. Is that what you are looking for?