Using GDB with Ghidra and melonDS

What you'll need:

Configuring melonDS

To enable the GDB, you need to do the following:

  1. Click on the Config menu at the top of the emulator, then click on Emu Settings
  2. Click on the Devtools tab
  3. Check Enable GDB stub
  4. If you do not see the Devtools tab, then you have not built melonDS with GDB enabled. Please check the link at the start of the guide to find a download with GDB enabled or build it yourself enabling GDB in CMake

melonDS is ready to go!

Setting up Ghidra

To begin, open your Ghidra project in the code viewer as you normally would.

  1. Click on File -> Configure, which should open a list of tools
  2. Check the "Debugger" box

image.png

This should cause windows to appear in your current project, likely making the following steps redundant. If you are unable to find a window, the following steps will either open the window, or present it to you in the project.

Creating a Debugger Target

This method has been tested on Linux and macOS. You should be able to follow these steps using WSL on Windows. Follow this guide if you need help setting up WSL.

To begin, open the Debugger Targets window by navigating to Windows -> Debugger -> Debugger Targets.

The window should look something like this:

image.pngAs you'll notice, there is an active connection in the screenshot but nothing on your end...let's fix that!

Click on the image.png button to open the connect window.

If you are on Linux:
If you are on macOS
If you are on Windows

You have now created a Debugger Target

Connecting to melonDS

The gdb interpreter should have opened for you when you connected to the debugging target.

Now, in the interpreter menu, run the command target remote localhost:[ARM9 Port] (Where [ARM9 Port] is the ARM9 Port set in the Devtools tab.)

If melonDS pauses after running this command, GDB is now talking to melonDS

You have now connected Ghidra to melonDS 

Using Breakpoints

If you would like to set breakpoints, you'll need to use the Dynamic PC

  1. Open the Dynamic PC window by clicking Window -> Listing -> Dynamic - Auto PC, [...]
    1. If you do not see this option, you can alternatively open it via Window -> Debugger -> New Dynamic Listing

  2. Next, open the Modules window by clicking Window -> Debugger -> Modules
  3. Lastly, click on image.png in the Modules window.

Now, setting a breakpoint in your code view should set a breakpoint in the Dynamic PC

You have now set up Ghidra to debug melonDS. Happy coding!


Revision #4
Created 16 April 2024 13:43:10 by Ndymario
Updated 14 April 2025 16:11:02 by Ndymario