#775

GDB implementation/testing (help wanted)

Openbunnieopened 9mo ago

Xous is capable of debugging userspace processes via GDB over serial.

To do this, you need to do the following:

  1. Compile using the --gdb-stub argument to xtask
  2. Flash all the built artifacts into the device
  3. Connect a physical serial port to the serial wires (on dabao, that would be PB14 for dabao->host, and PB13 for host->dabao).
  4. 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:

https://github.com/betrusted-io/xous-core/blob/47f529f2d238a7e5fda410c5c46c71dca119a128/kernel/src/arch/riscv/mem.rs#L614-L704

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.

Activity

1
nguyenminhtuan18026mo ago

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?

(gdb) break xous::syscall::receive_message                                                                                                       
Breakpoint 2 at 0x9e3b8                                                                                                                          
(gdb) c                                                                                                                                          
Continuing.                                                                                                                                      
                                                                                                                                                 
Thread 1 received signal EXC_BREAKPOINT, Breakpoint.                                                                                             
0x0009e3b8 in xous::syscall::receive_message ()                                                                                                  
(gdb) info threads                                                                                                                               
  Id   Target Id         Frame                                                                                                                   
* 1    Thread 24.2       0x0009e3b8 in xous::syscall::receive_message ()                                                                         
(gdb) bt                                                                                                                                         
#0  0x0009e3b8 in xous::syscall::receive_message ()                                                                                              
#1  0x00042c60 in shellchat::wrapped_main ()                                                                                                     
#2  0x0004139a in shellchat::main ()                                                                                                             
#3  0x0006ee76 in main () 

(gdb) info registers
ra             0x42c60  0x42c60 <shellchat::wrapped_main+6342>
sp             0x7ffff5e0       0x7ffff5e0
gp             0x0      0x0
tp             0x60000000       0x60000000
t0             0x7ffff574       2147480948
t1             0xa036a  656234
t2             0x0      0
fp             0x7ffffa1c       0x7ffffa1c
s1             0x7d     125
a0             0x8      8
a1             0x28f337f9       687028217
a2             0x7b9574a5       2073392293
a3             0x44c1c4ae       1153549486
a4             0x7ffff5b4       2147481012
a5             0x20000  131072
a6             0x0      0
a7             0x18     24
s2             0x1      1
s3             0x1      1
s4             0x7ffffdc8       2147483080
s5             0x20000218       536871448
s6             0x200003a0       536871840
s7             0x24f58  151384
s8             0x13     19
s9             0xa0     160
s10            0x200005d8       536872408
s11            0x7d     125
t3             0x9e0f8  647416
t4             0xb5     181
t5             0x25a70  154224
t6             0x7ffff5b4       2147481012
pc             0x9e3b8  0x9e3b8 <xous::syscall::receive_message+24>