Skip to content
Lionel Flandrin edited this page Mar 6, 2016 · 1 revision

Rustation debugger

Introduction

While Rustation doesn't have a full fledged debugging interface built in it implements a subset of the [GDB remote serial protocol] (https://sourceware.org/gdb/current/onlinedocs/gdb/Remote-Protocol.html#Remote-Protocol) over a local TCP socket.

This means that you can connect to a running Rustation instance using GDB or any debugger implementing its remote protocol. Then you can dump registers, memory, set breakpoints and watch points etc...

Building GDB

You'll need a GDB build targetting the PlayStation. Fortunately there's upstream support for the console's MIPS CPU so it's relatively straightforward.

First you need to download GDB's source code from https://ftp.gnu.org/gnu/gdb/. As I'm writing this document the latest version is gdb-7.11. Download the tarball and extract it in your work directory:

$ wget https://ftp.gnu.org/gnu/gdb/gdb-7.11.tar.gz
$ tar xzvf gdb-7.11.tar.gz

Then create a build directory inside the gdb-7.11 and cd into it:

$ cd gdb-7.11
$ mkdir build
$ cd build

Now we need to run the configure script to target the PlayStation's CPU:

$ ../configure --prefix="/opt/psx-tools" --target=mipsel-unknown-elf --with-float=soft --enable-softfloat
  • --prefix="/opt/psx-tools" configures where GDB will be installed when we run make install. You can of course put a different path here.
  • --target=mipsel-unknown-elf says that we're targeting a "MIPS little endian" and we will be debugging "freestanding" programs without an OS.
  • --with-float=soft --enable-softfloat say that the floating point operations will be done in "software", that is using regular CPU instructions and not the floating point coprocessor. Since the PlayStation's CPU doesn't have this coprocessor it can't support "hardfloat".

If everything goes well you should now be able to build GDB proper:

$ make -j4

If the compilation is successful you can install newly built GDB using make install. If like me you're targetting a system-wide location that you can't write as a regular user you'll probably need sudo to install the files:

$ sudo make install

And you should now have a PlayStation-compatible GDB ready to use! To test it simply run the gdb binary installed in your prefix which should be called mipsel-unknown-elf-gdb:

$ /opt/psx-tools/bin/mipsel-unknown-elf-gdb
GNU gdb (GDB) 7.11
Copyright (C) 2016 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.  Type "show copying"
and "show warranty" for details.
This GDB was configured as "--host=x86_64-pc-linux-gnu --target=mipsel-unknown-elf".
Type "show configuration" for configuration details.
For bug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>.
Find the GDB manual and other documentation resources online at:
<http://www.gnu.org/software/gdb/documentation/>.
For help, type "help".
Type "apropos word" to search for commands related to "word".
(gdb) 

In order to do some actual debugging we need to connect GDB to Rustation.

Clone this wiki locally