I am currently writing a Vectrex emulator and wanted some way of debugging any code I wrote for it. I'm new to writing emulators, writing for the Vectrex and also new to the language (Rust) that I'm writing it in. So I need a lot of help :)
It took me a little while to find out what I needed to do so here it is for reference.
For GDB to remotely connect to your emulator it needs to support GDB's remote protocol over a TCP/IP socket.
My emulator is written in Rust and I found some code in a PlayStation emulator that did some of the basics. So I used that as a base and added a few more features using sixie's xroar dragon emulator sources for reference.
I still need to implement some more of the protocol, breakpoints in particular but right now I can single step code, look at memory and set registers. Score.
My emulator's GDB server runs on port 6809 (what a surprise!). Once you run GDB connecting is pretty easy using the remote command. In my case:
target remote localhost:6809
Uploading Your Code
You can use restore to upload a binary file. For example
restore asm/out/all.bin binary 0x9900
uploads asm.bin to the address 0x9900. To run it I set the program counter to the entry point for my code, sensibly at the start of the file.
After that you can g or si or whatever you want
Disassemble doesn't work without source either. Luckily you can use examine memory with the i format modifier. So to disassemble where the PC is pointing to use:
If you want more than a single line you then use
to disassemble 10 instructions
Step doesn't work but Step Instruction does. Just use si instead