Skip to content

Run emulator as gdbserver #22

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

Closed
jserv opened this issue Jul 28, 2022 · 4 comments
Closed

Run emulator as gdbserver #22

jserv opened this issue Jul 28, 2022 · 4 comments
Assignees

Comments

@jserv
Copy link
Contributor

jserv commented Jul 28, 2022

rISA implements an interesting GDB mode, which runs the simulator as a gdbserver. That is, it allows us to connect RISC-V program with a remote GDB via target remote or target extended-remote -- but without linking in the usual debugging stub. Hopefully, rv32emu can follow the experimental feature in rISA to provide builtin gdbserver.

See also:

  • riscv-gdbserver: GDB Server for interacting with RISC-V models, boards and FPGAs
@jserv
Copy link
Contributor Author

jserv commented Aug 7, 2022

WIP: mini-gdbstub

@RinHizakura
Copy link
Collaborator

An experimental solution to this issue is created on my local branch now, which lets rv32emu support a small set of GDB Remote Serial Protocol packet with my mini-gdbstub library.

Here's a small example to play with the debug mode, which shows the convenience to set a breakpoint to stop the emulator by a function symbol.

rv32emu:

$ riscv32-unknown-elf-gcc -g tests/puzzle.c
$ ./build/rv32emu --debug a.out

GDB:

$ riscv32-unknown-elf-gdb
(gdb) file ./a.out 
Reading symbols from ./a.out...
(gdb) target remote :1234
Remote debugging using :1234
0x000100c2 in _start ()
(gdb) set debug remote 1
...
(gdb) break main
...
(gdb) cont
Continuing.
...
argc=0, argv=0xfffff004) at tests/puzzle.c:213
213	    run_puzzle();

A small concern here is that mini-gdbstub is still a WIP and unstable library, so it's not very convenient to use it as a submodule since we may have to sync the library frequently. I'm still thinking if that's a good idea to develop the part of gdbserver as another project. But I think mini-gdbstub is about to be integrated to rv32emu soon.

NOTE: There are still many features and possible bugs that must be refined in mini-gdbstub, and rv32emu also have to provide a better implementation of the gdbstub abstraction (For example, rv_set_bp should be able to set more than one breakpoint).

@jserv
Copy link
Contributor Author

jserv commented Aug 24, 2022

I'm still thinking if that's a good idea to develop the part of gdbserver as another project. But I think mini-gdbstub is about to be integrated to rv32emu soon.

Both git submodule and in-repository maintenance are fine to me. Pick one when you are ready to submit pull request(s).

@jserv
Copy link
Contributor Author

jserv commented Aug 25, 2022

See also

@jserv jserv closed this as completed in 1712435 Sep 1, 2022
vestata pushed a commit to vestata/rv32emu that referenced this issue Jan 24, 2025
With the help of the external mini-gdbstub library, rv32emu offers an
experimental way to support a limited number of GDB Remote Serial
Protocol (GDBRSP) packets. After applying this patch, we were able to
connect rv32emu to GDB and interact with it using basic commands
such as "print $pc" to dump the value of current program counter or
"continue" to resume program running.

It is important to note that this patch only permits the use of one
breakpoint. Future upgrades will be made.

Close sysprog21#22
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

2 participants