GDB server for PCSXR
Posted: July 16th, 2020, 4:51 am
Based on this fork of pcsxr and this dependency-free GDB stub implementation, I have implemented a GDB server for PCSXR to be used with mipsel-unknown-elf-gdb. This allows source-level debugging and usual commands such as breakpoints, reading/writing variables, step into, step over, continue, break, etc.
Download
https://github.com/XaviDCR92/pcsxr
Installation
Now you can run pcsxr with:
How to use
pcsxr now has a "-gdb" command line flag that starts the GDB server on port 3333. The same effect can be achieved by starting pcsxr with no flags and selecting "Configuration->CPU->Enable GDB Server". Ensure "Enable Interpreter CPU" is enabled and "Enable Debugger" (the telnet-based server) remains disabled. Once configured, "GDB server started on port 3333." should appear on stdout. Finally, load the .bin/.cue/.exe file that is attached to your .elf file.
Next, execute mipsel-unknown-elf-gdb using a valid .elf file with debug symbol information (available when compiling with mipsel-unknown-elf-gcc with the "-g" or "-ggdb" flags). If using the command line:
Now pcsxr should stop at main() and source level should be displayed.
For Visual Studio Code (or its fully FOSS variant VSCodium) users, the NativeDebug extension can be easily configured to support mipsel-unknown-elf-gdb.
Known issues
- Porting to Windows is not done yet, but should not be too hard. Only Linux (using Kubuntu 20.04 LTS) has been tested so far.
- Running the GDB server might block the GUI, so if you want to close pcsxr please kill the process if blocked.
- CPU usage is high when waiting for continue/break signals as it must look up two different sockets simultaneously. Hint: I think this could be fixed by using select().
- Warning: PCSXr already had a Telnet-based server which I had to do some breaking changes to. If you find any bug, feel free to create a pull request.
Download
https://github.com/XaviDCR92/pcsxr
Installation
Code: Select all
git clone https://github.com/XaviDCR92/pcsxr
cd pcsxr/
mkdir build && cd build
cmake -G Ninja -DCMAKE_BUILD_TYPE=Debug .. && cmake --build .
Code: Select all
cd gui && ./pcsxr
pcsxr now has a "-gdb" command line flag that starts the GDB server on port 3333. The same effect can be achieved by starting pcsxr with no flags and selecting "Configuration->CPU->Enable GDB Server". Ensure "Enable Interpreter CPU" is enabled and "Enable Debugger" (the telnet-based server) remains disabled. Once configured, "GDB server started on port 3333." should appear on stdout. Finally, load the .bin/.cue/.exe file that is attached to your .elf file.
Next, execute mipsel-unknown-elf-gdb using a valid .elf file with debug symbol information (available when compiling with mipsel-unknown-elf-gcc with the "-g" or "-ggdb" flags). If using the command line:
Code: Select all
mipsel-unknown-elf-gdb your-game.elf --tui # --tui not needed, but helpful nonetheless
target remote 3333
b main
c
Code: Select all
(gdb) target remote :3333
Remote debugging using :3333
0xbfc00000 in ?? ()
(gdb) b main
Breakpoint 1 at 0x80020000
(gdb) c
Continuing.
Program stopped.
0x80020000 in main ()
Code: Select all
{
"version": "0.2.0",
"configurations":
[
{
"type": "gdb",
"request": "launch",
"name": "Launch Program",
"target": "Set application name e.g.: ${workspaceFolder}/my-game.elf",
"cwd": "${workspaceFolder}",
"gdbpath": "mipsel-unknown-elf-gdb",
"autorun":
[
"target remote :3333",
"b main",
"c",
"d"
],
"valuesFormatting": "prettyPrinters"
}
]
}
- Porting to Windows is not done yet, but should not be too hard. Only Linux (using Kubuntu 20.04 LTS) has been tested so far.
- Running the GDB server might block the GUI, so if you want to close pcsxr please kill the process if blocked.
- CPU usage is high when waiting for continue/break signals as it must look up two different sockets simultaneously. Hint: I think this could be fixed by using select().
- Warning: PCSXr already had a Telnet-based server which I had to do some breaking changes to. If you find any bug, feel free to create a pull request.