Open XVilka opened 1 year ago
It sounds like what you want is a way to debug things running with a simulator and not the simulator itself which can already be debugged directly with normal software tools.
If that is true, then gdbstub could be used to interface and control the contents of simulators using possibly some simulator specific code and the simh frontpanel API.
If you want to explore this and you actually have a use case for one or more simulators, I'll be glad to work with your to put something together.
Someone's long ago request for something like this was one of the inspirations for implementing the frontpanel API.
Feel free to contact me here or offline at mark@infocomm.com
A number of simulators already have a breakpoint facility. So with that and basic things like register and memory access you have pretty much all the things needed for GDB. The stub protocol is quite easy. The obvious issue is that GDB supports few of the ISAs that SIMH emulates. VAX is about the only one that comes to mind. I've toyed with doing a quick & dirty PDP11 GDB, but that's made problematic by the fact that GDB is dropping support for STABS (which wasn't reliable anyway) and there isn't a PDP11 ELF handler. Or rather there is most of one but the author died last year and so far I haven't been able to get permission to publish it. I suppose it could be redone, it should not be terribly hard.
@XVilka: Can you write up an initial design? Are you leveraging the gdbstub protocol with existing SIMH internals? Or a whole new debugger?
Yes. Leveraging GDBRemote protocol looks like easiest and proven solution, even if the GDB itself might not support the target architecture. As for STABS we plan to implement it in Rizin: https://github.com/rizinorg/rizin/issues/3578 Rizin doesn't support all architectures but already can handle GDB protocol out of the box. I am thinking if it makes possible to leverage that.
I can see how the Rizin effort might be useful, e.g., reverse engineering VAX diagnostics or PDP-11 diagnostics. There's a little more to this design that needs expansion, though.
@pkoning2, @sethm: @XVilka's proposal adds the GDB remote debugging protocol as a frontend to SIMH. That would make it possible for the Rizin tools to reverse engineer VAX diagnostics (or the 3b2 diags) and potentially recover them as C code or as documented assembler sources.
@XVilka: STABS is a debugging format; I'm not conceptually connecting STABS to the GDB remote protocol. Would it be used to augment the reverse engineering process by tracking symbolic info associated with the image being reverse engineered? Where would that STABS info get stored?
Also, adding an alternate frontend to SIMH suggests fixing the SDL weirdness. SDL should always be the main thread (implying that the SIMH command line lives in its own thread), per the SDL design, not just for macOS and BESM6. That would result in a more consistent compile methodology, vice exceptions for platforms and specific simulators.
The reason I mentioned STABS is that the debugger wants a binary format that includes debug data, and the compiler and/or assembler needs to generate that. STABS is the old format which is rapidly disappearing, ELF with DWARF is the new one. The issue is that some GCC targets -- pdp11 at least -- is only STABS and that was actually removed from GCC recently, so the current GCC still supports pdp11 but without debug data. pdp11-elf is doable but not done yet. For VAX it is, I believe. The other question is what to do about older ISAs for which no debug format was ever defined -- for example, remote debugging of IBM 1620 is presumably doable, but it wouldn't be symbolic.
Many emulators support ways to debug their guests using more suitable tools - GDB, LLDB, EDB, WinDbg, IDA Pro, etc.
Implementing something like gdbstub, just like QEMU does this, will allow remote debugger connection, e.g. GDB itself, or something else: