Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can't get gdb to display C code #171

Open
nbosio1001 opened this issue Mar 6, 2023 · 2 comments
Open

Can't get gdb to display C code #171

nbosio1001 opened this issue Mar 6, 2023 · 2 comments

Comments

@nbosio1001
Copy link

nbosio1001 commented Mar 6, 2023

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
Copy link

meighti commented Mar 27, 2023

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.

@chenzhiy2001
Copy link

chenzhiy2001 commented Nov 28, 2024

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

That's true if you use gdb-multiarch. If you want to single stepping from kernel to a user process, you can use riscv64-unknown-elf-gdb instead of gdb-multiarch. I guess they handle single stepping sret instructions differently.

I recommend you to compile riscv64-unknown-elf-gdb yourself from riscv-gnu-toolchain.

Source: https://stackoverflow.com/a/69961102/24061604

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants