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

OpenOCD/GDB Support #453

Open
TimMThomas opened this issue Apr 17, 2024 · 5 comments
Open

OpenOCD/GDB Support #453

TimMThomas opened this issue Apr 17, 2024 · 5 comments
Labels
enhancement New feature or request

Comments

@TimMThomas
Copy link

Hi everyone,
i wanted to ask if support for openocd/gdb or an interactive debug mode (similar to spike) exists, or is maybe planned?
I found that feature quite useful, when adding custom functionality to spike.
Cheers

@Alasdair
Copy link
Collaborator

If you mean something like spike -d, I think that maybe wouldn't be too hard to implement.

I had some GDBMI support in Sail in the past, but that was for a rather esoteric use case where I would run Qemu until I hit a breakpoint in Linux or some other code, then swap the execution from Qemu to the Sail interpreter at that point, so it probably isn't what you want.

@TimMThomas
Copy link
Author

TimMThomas commented Apr 23, 2024

If you mean something like spike -d, I think that maybe wouldn't be too hard to implement.

Something like that, yes. When i find the time, i can look into it myself but currently im sadly busy with a lot of other things. Might take a while

@rsnikhil
Copy link
Collaborator

rsnikhil commented Apr 23, 2024

I have some code that may be useful in implementing gdb control of the Sail simulator (open-source, Apache license):

https://github.com/bluespec/RISCV_gdbstub

At Bluespec, Inc., we use this for GDB control of our own simulators. Briefly, it works like this:

                                +--------------+
+-----+                         |    gdbstub   |
| gdb | <--remote connection--> | front | back | <--> RISC-V CPU and Memory
+-----+                         |  end  |  end |
                                +--------------+

Notes

  • 'gdb' is standard gdb (configured for the RISC-V ISA)

  • 'remote connection' is a standard Unix connection (TCP, pipe, ...)

  • The remote connection carries messages back and forth according to
    gdb's RSP (Remote Serial Protocol)

      https://sourceware.org/gdb/current/onlinedocs/gdb.html/Remote-Protocol.html
    
  • 'front end' parses incoming RSP messages from gdb and formats
    outgoing RSP messages to gdb, and converts them into 'API' calls
    to the back end, such as 'read/write register', 'read/write
    memory', 'continue', 'step', 'abort (^C)', etc.

  • The supplied 'back end' converts these API calls into standard
    RISC-V Debug Module 'DMI' requests/responses.

For the Sail simulator, one would simply replace the back end API implementation with direct functions to read/write registers, read/write memory, start/stop simulation, ... etc. (Note: this will not need OpenOCD or a RISC-V Debug Module, which are
unnecessary extra steps when controlling a simulator).

gdbstub needs to be multiplexed with the main simulation thread (because it has to listen for gdb messages while simulation is running). This can be done either with a separate pthread or by calls within the main simulation loop.

I don't have the time at the moment to do this work, but I'll be happy to answer any questions and provide help (I wrote this code).

@bacam
Copy link
Collaborator

bacam commented Apr 23, 2024

I did some work on a general gdb interface for Sail generated C simulators for a different architectural model (loosely based on a prototype Prashanth did for risc-v). Unfortunately I didn't have time to generalize it for other models but I would like to return to it at some point in the future.

@billmcspadden-riscv
Copy link
Collaborator

billmcspadden-riscv commented Apr 23, 2024 via email

@Timmmm Timmmm added the enhancement New feature or request label May 7, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

6 participants