GDB server for PCSXR

Start a work log and update it occasionally with your projects progress
Post Reply
Xavi92
C Programming Expert
C Programming Expert
Posts: 161
Joined: Oct 06, 2012
PlayStation Model: SCPH-5502
Contact:

GDB server for PCSXR

Post by Xavi92 » 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.

Image

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 .
Now you can run pcsxr with:

Code: Select all

cd gui && ./pcsxr
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:

Code: Select all

mipsel-unknown-elf-gdb your-game.elf --tui # --tui not needed, but helpful nonetheless
target remote 3333
b main
c
Now pcsxr should stop at main() and source level should be displayed.

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 ()
For Visual Studio Code (or its fully FOSS variant VSCodium) users, the NativeDebug extension can be easily configured to support mipsel-unknown-elf-gdb.

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"
        }
    ]
}
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.
Last edited by Xavi92 on October 29th, 2020, 5:47 am, edited 1 time in total.

ackerman
Curious PSXDEV User
Curious PSXDEV User
Posts: 29
Joined: Aug 21, 2019

Post by ackerman » July 17th, 2020, 11:03 pm

Congratulations, that's interesting.

Xavi92
C Programming Expert
C Programming Expert
Posts: 161
Joined: Oct 06, 2012
PlayStation Model: SCPH-5502
Contact:

Post by Xavi92 » October 27th, 2020, 9:44 am

New bugfixes have been pushed into the repository. Please check them out!

algebro
What is PSXDEV?
What is PSXDEV?
Posts: 3
Joined: Dec 30, 2020

Post by algebro » December 30th, 2020, 3:11 am

Thanks for sharing this! I'm excited to try it but I'm having a couple of issues and I was hoping you could help.

First, the gdbstub revision pinned for the submodule no longer exists--it looks like it was removed with a force push or something. I updated it to the latest `master` and now the project checks out and builds OK.

Second, after starting the gdbserver with `-gdb` and trying to connect with gdb-multiarch, I'm getting a remote communication error:

Client:

Code: Select all

(gdb) set arch mips
The target architecture is set to "mips".
(gdb) set endian little
The target is set to little endian.
(gdb) set debug remote 1
(gdb) target extended-remote :3333
Remote debugging using :3333
Sending packet: $qSupported:multiprocess+;swbreak+;hwbreak+;qRelocInsn+;fork-events+;vfork-events+;exec-events+;vContSupported+;QThreadEvents+;no-resumed+;xmlRegisters=i386#6a...Remote communication error.  Target disconnected.: Connection reset by peer.
pcsxr server:

Code: Select all

./pcsxr -gdb
GDB server started on port 3333.
Accepted gdb connection
pthread_join(): No such file or directory
Terminated active gdb connection
Closed gdb server

Any idea how to troubleshoot?

Xavi92
C Programming Expert
C Programming Expert
Posts: 161
Joined: Oct 06, 2012
PlayStation Model: SCPH-5502
Contact:

Post by Xavi92 » December 31st, 2020, 10:16 am

algebro wrote: December 30th, 2020, 3:11 am First, the gdbstub revision pinned for the submodule no longer exists--it looks like it was removed with a force push or something. I updated it to the latest `master` and now the project checks out and builds OK.
More like I forgot to push the commits stored in my computer. :lol: I have just pushed them - could you please try it again?

algebro
What is PSXDEV?
What is PSXDEV?
Posts: 3
Joined: Dec 30, 2020

Post by algebro » January 1st, 2021, 6:55 am

Thanks! That fixes the build problems but I'm still not having any luck with remote debugging:

Code: Select all

./pcsxr -gdb
GDB server started on port 3333.
Accepted gdb connection
send():: Broken pipe
send():: Broken pipe
send():: Broken pipe
send():: Broken pipe
send():: Broken pipe
send():: Broken pipe
send():: Broken pipe

Code: Select all

gdb-multiarch 
Exception caught while booting Guile.
Error in function "make_objcode_from_file":
bad header on object file: "\x7fELF\x02\x01\x01ÿ\x00\x00\x00\x00\x00\x00\x00\x00"
gdb-multiarch: warning: Could not complete Guile gdb module initialization from:
/usr/share/gdb/guile/gdb/boot.scm.
Limited Guile support is available.
Suggest passing --data-directory=/path/to/gdb/data-directory.

[...]

(gdb) set arch mips
The target architecture is set to "mips".
(gdb) set endian little
The target is set to little endian.
(gdb) target remote localhost:3333
Remote debugging using localhost:3333
Ignoring packet error, continuing...
warning: unrecognized item "timeout" in "qSupported" response
Ignoring packet error, continuing...
Remote replied unexpectedly to 'vMustReplyEmpty': timeout
(gdb) disass *main
No symbol table is loaded.  Use the "file" command.
(gdb) c
The program is not being run.
Any ideas on what could be wrong? Looking at the call stack, the broken pipe error occurs in dbg_sys_send_packet when called from the beginning of dbg_main (dbg_send_signal_packet):

Code: Select all

[#0] 0x451c9b → WriteSocket(client_socket=0xc, buffer=0x7fffe7afe3c4, len=0x1)
[#1] 0x491bac → dbg_sys_putchar(ch=0x24)
[#2] 0x492e27 → dbg_send_packet(pkt_data=0x7fffe7afe4d0 "S00F", pkt_len=0x3)
[#3] 0x493a1a → dbg_send_signal_packet(buf=0x7fffe7afe4d0 "S00F", buf_len=0x258, signal=0x0)
[#4] 0x493b5f → dbg_main(state=0x7fffe7afe760)
[#5] 0x492771 → loop(args=0x0)
[#6] 0x7ffff71ca3e9 → start_thread()
[#7] 0x7ffff5358293 → clone()

Xavi92
C Programming Expert
C Programming Expert
Posts: 161
Joined: Oct 06, 2012
PlayStation Model: SCPH-5502
Contact:

Post by Xavi92 » January 1st, 2021, 2:37 pm

algebro wrote: January 1st, 2021, 6:55 am

Code: Select all

gdb-multiarch 
Exception caught while booting Guile.
Error in function "make_objcode_from_file":
bad header on object file: "\x7fELF\x02\x01\x01ÿ\x00\x00\x00\x00\x00\x00\x00\x00"
gdb-multiarch: warning: Could not complete Guile gdb module initialization from:
/usr/share/gdb/guile/gdb/boot.scm.
Limited Guile support is available.
Suggest passing --data-directory=/path/to/gdb/data-directory.
That bit worries me. I have followed the same steps you described and none of these error messages appeared at all. Are you sure all dependencies needed by gdb are satisfied?

algebro
What is PSXDEV?
What is PSXDEV?
Posts: 3
Joined: Dec 30, 2020

Post by algebro » January 1st, 2021, 2:45 pm

They should be, I'm using https://aur.archlinux.org/packages/gdb-multiarch/ on Arch Linux. What version of gdb are you testing with? Sometimes arch has newer versions of packages that break things (for example, gcc10 forces pcsxr to be compiled with -fcommon because -fno-common became the default)

update: i recompiled gdb-multiarch with `--with-guile` instead of `--with-guile=2.0` and that solved the guile errors, but I'm still getting the broken pipe errors when connecting to localhost:3333.

another update: looks like compiling pcsxr with gcc 10.2 instead of clang solved the problem. I'll reach out if I have more questions--thanks!

User avatar
NDR008
What is PSXDEV?
What is PSXDEV?
Posts: 4
Joined: May 22, 2020
I am a: Many things
Motto: Experience is better than pro

Post by NDR008 » January 5th, 2021, 11:42 pm

FYI... I'll throw this out there:
https://github.com/NDR008/VSCodePSX

Post Reply

Who is online

Users browsing this forum: Greg and 7 guests