mit-pdos / xv6-riscv

Xv6 for RISC-V
Other
6.58k stars 2.38k forks source link

Can't get gdb to display C code #171

Open nbosio1001 opened 1 year ago

nbosio1001 commented 1 year ago

I am working on primes.c and I can't get my gdb environment setup so I can debug the code visually. I have the same .gdbinit.tmpl-riscv file and put $U/_primes\ in my Makefile. I am also running on a Raspberry Pi OS.

I run make qemu-gdb and then run gdb-multiarch user/_primes. After I run lay next, press enter and get the gdb environment in the picture.

image

meighti commented 1 year ago

When you run make qemu-gdb, you are debugging the kernel, not user processes like user/_primes.

You might want to take a look at trampoline.S, which has a 'sret' instruction for returning to user mode. I think after 'sret' you won't be able to debug into user process and you will get back to gdb once you are back somewhere in the kernel, (probably via a syscal or timer interrupt).

In GDB, use "b trap.c:128" to break before jumping to userret. Then use "si" to step by instruction, until you reach to 'sret'. after that you will see that GDB sill not step from supervisor mode into user mode.