gbadev.org forum archive

This is a read-only mirror of the content originally found on forum.gbadev.org (now offline), salvaged from Wayback machine copies. A new forum can be found here.

DS development > GDB stub for Desmume

#110574 - masscat - Wed Nov 29, 2006 12:19 pm

PLEASE NOTE:The GDB stub in desmume discussed in this thread is old, you can find information on a newer version here.

I have added a GDB stub to desmume so you can now use it to do debugging on your PC.
Currently it has only been integrated into the GTK version of desmume (linux only? - other builds are likely to be broken and not build/run).
The stub can only do stepping, instruction breakpoints, continue and stopping a running target. There is no setting register and memory values or memory watchpoints yet.
One reason I developed this was to provide a tool to investigate the NDS itself, i.e. stepping through code to see how it sets things up.

EDIT: If you use Windows you can get a binary from here. The patch below does not contain the Windows code.

Building and patching Desmume source
You need to get and be able to build the Desmume for he sourceforge repository. When asked for a password by cvs just hit return. Change to tthe directory where you want the desmume source to be placed and do the following.

Code: Select all

 cvs -d:pserver:anonymous@desmume.cvs.sourceforge.net:/cvsroot/desmume login
 cvs -z3 -d:pserver:anonymous@desmume.cvs.sourceforge.net:/cvsroot/desmume co -D 2006-11-27 -P desmume
This will create a copy of the desmume source with files no later than their 2006-11-27 version, i.e. the same source as the gdb stub is being developed against. Make sure that you can build the source by running the configure script in the desmume directory - resolve any missing libraries and the like until the script completes successfully.

Download the tarball containing the gdbstub code and patch. Change into the desmume directory and extract the tarball.

Code: Select all

tar -xvjf path_to_tarball/desmume_gdbstub_20061129.tar.bz2
This will create the src/gdb_stub directory and its contents and the gdbstub_20061129.patch patch file. Finally run the patch file to patch the desmume source.

Code: Select all

patch -p0 <gdbstub_20061129.patch
Rerun the configure script and type make to build the GDB stub enabled Desmume.

Using the GDB stub
The GDB stub creates two TCP sockets for GDB to connect to. The one at port 20000 is for the ARM7 and the one at port 20001 is for the ARM9 (only the ARM9 stub is active as delivered - to disable/enable the stub for each ARM edit /src/gtk/main.c at line 1313. This shows the ARM9 been activated).
Run desmume and load the .nds file you wish to debug. Press the play button. The emulation will start running but nothing will appear on screen as the ARM9 is stalled until GDB connects and tells it to run.
Get yourself a ARM aware version of GDB or Insight (see here and here for info on how to get one or build one). Run GDB with the .elf ile corresponding to the ARM9 code (optional) and connect to the stub as follows.

Code: Select all

target remote 127.0.0.1&#58;20001
If you issue the continue command desmume will leap into life. You can now debug to your heart's delight.

#110627 - GPFerror - Thu Nov 30, 2006 12:13 am

awesome work, wish I had a way to run this, i took a look at trying to get it working on windows but I haven't been able to get the gtk/sdl version to build on windows, and then the matter of converting the linux socket code to winsock is beyond my experience unfortunetly.


Troy(GPF)

#110661 - Ryan FB - Thu Nov 30, 2006 4:50 am

Thanks, this is working great for me so far. I can see it being very useful for development.

Is there any way to suppress the packet debugging information? I tried playing with "set debug remote" and the various other debug variables in gdb but wasn't able to turn it off.

#110683 - masscat - Thu Nov 30, 2006 11:47 am

Ryan FB wrote:Is there any way to suppress the packet debugging information?
If you mean the stuff like:

Code: Select all

Processing packet ?
Putting packet size 3 S05
Processing packet H
Putting packet size 0
Processing packet g
The only way to stop that is to edit src/gdb_stub/gdbstub.c and comment out any LOG calls. Since this is still in development I have not gone through and removed them.
GPFerror wrote:... and then the matter of converting the linux socket code to winsock
From a quick look at winsock, I believe the conversion should not be too hard as the calls are similar.
The trickier part is the Emulation to GDB stub thread communications. Under Linux this is done using a pipe. This is nice and easy and means the GDB stub thread has a single wait point, the call to select. Under Windows, I believe, this pipe would need to be a socket in order to be used with the select call. This creates a complication as a thread would be required for creating this communications socket.
There may be a better way of doing this under Windows and still leave the GDB stub code similar between both versions.

#110703 - masscat - Thu Nov 30, 2006 7:55 pm

Here is a binary for you lucky Windows users out there.
Works for me on a Windows XP machine and, strangely enough, under WINE on Linux.

#110724 - GPFerror - Thu Nov 30, 2006 11:57 pm

masscat wrote:Here is a binary for you lucky Windows users out there.
Works for me on a Windows XP machine and, strangely enough, under WINE on Linux.
cool works great, just as I finally got the gtk build working on windows and was about to apply your patch lol and try to learn sockets :)

the gtk version on windows is extremly slow, look forward to your source diffs for gdb :)

Thanks,
Troy(GPF)

#110772 - masscat - Fri Dec 01, 2006 12:38 pm

Here is a patch for the Windows version of the source (should work for both Windows and Linux). This is against the main Desmume CVS dated 2006-11-27.

Having posted over on the Desmume sourceforge forums it looks like the GDB stub code may get put into the main CVS (after a bit of tweaking and tidying). If this happens I will not post further source changes here.

#110794 - GPFerror - Fri Dec 01, 2006 4:44 pm

masscat wrote:Here is a patch for the Windows version of the source (should work for both Windows and Linux). This is against the main Desmume CVS dated 2006-11-27.

Having posted over on the Desmume sourceforge forums it looks like the GDB stub code may get put into the main CVS (after a bit of tweaking and tidying). If this happens I will not post further source changes here.
great job, thanks again for all your gdb work in hardware as well :)

Troy(GPF)

#118246 - masscat - Sun Feb 11, 2007 2:51 pm

Been working of the DeSmuME GDB stub again. This version should be better (can step code and not go stepping into the interrupt handler).

Go to the DeSmuME forums for further info and download.

#126550 - masscat - Tue Apr 24, 2007 12:07 pm

I have updated the GDB stub in Desmume.

Please use, test and post comments over on the Desmume forums.

#126553 - LiraNuna - Tue Apr 24, 2007 12:21 pm

holy shit batman!
Great work!

#126658 - Jevin - Wed Apr 25, 2007 6:59 pm

thank you so much! :D

#128574 - masscat - Sat May 12, 2007 10:53 pm

Following the release of Desmume 0.7, I have updated Desmume + GDB stub to the same code base. I have built a Windows binary too.

Pop over to the Desmume formums.

#128647 - Jevin - Sun May 13, 2007 8:29 pm

The sources don't compile on OS X for some reason. The latest CVS works fine though (minus OpenGL =()

make output: http://pastebin.ca/486113

configure info:

Code: Select all

checking for gzopen in -lz... yes
checking for zzip_open in -lzzip... no
checking for sdl-config... /sw/bin/sdl-config
checking GL/gl.h usability... no
checking GL/gl.h presence... no
checking for GL/gl.h... no
checking GL/glu.h usability... no
checking GL/glu.h presence... no
checking for GL/glu.h... no
checking for pkg-config... pkg-config
checking for pkg-config... /sw/bin/pkg-config
checking pkg-config is at least version 0.9.0... yes
checking for GTK... yes
checking for GTKGLEXT... no
checking for GTHREAD... yes
checking for gdk_gl_init in -lgdkglext-x11-1.0... no
checking for LIBGLADE... no
checking whether to enable maintainer-specific portions of Makefiles... no

#128657 - masscat - Sun May 13, 2007 10:19 pm

Can you try this:

In src/cli/main.c add the SDL_thread.h include file.

For example, change:

Code: Select all

#include "SDL.h"
#include <stdlib.h>
#include <string.h>
#include <libgen.h>
to

Code: Select all

#include "SDL.h"
#include "SDL_thread.h"
#include <stdlib.h>
#include <string.h>
#include <libgen.h>
This is not explicitly needed under Linux but maybe under OSX.

PS: for OpenGL support for 3D emulation in the GTK port you need the gtkGLext library. A quick search for "OSX gtkGLext" lead to this page. I do not know if that is usable by you or if there is another source to install it from though.