Debugging uClinux apps over the Network with Eclipse

 

 

GDB can communicate with remote applications using a stub program.

This stub program, called gdbserver, launches applications and serves up to a network interface. GDB can then connect to these programs and step through the program as if it was native the development machine.

 

Serving up the program

To serve up a remote program over the network start up gdbserver with the program to be debugged as an argument.

 

This is done as follows:

 

gdbserver  :port application arguments

 

“port” is the network port to connect on, it doesn’t really matter what you choose so long as it’s not in use by another service.

6000 is commonly one for this.

 

“application” is the program to be debugged. Note that this program must have 3 characteristics to work and be debuggable

  1. It must be built to run on the target. (i.e. for a Coldfire it should be compiled with the Coldfire compiler)
  2. It must be executable, if you just uploaded it you will probably need to run chmod on it.
  3. It must be built with the –g flag. (CFLAGS+=-g)

 

“arguments” Any arguments that need to be passed to the function

 

 

Connecting with Eclipse

Once the program is available on the network, Eclipse can connect to it through it’s CDT debugger.

From the C perspective, right click on the hello file with the .gdb extension (created during compilation)

This will bring up a menu, from which you can select “debug as”, and then select “debug”.

(There will be another option for debugging local applications but that’s not what we want here)

 

 

 

This will bring up the debug menu, from which you can create a debug target, tell eclipse where it is on the network, etc.

You will need to create a new C/C++ Local Application. Click on C/C++ Local Application and select “New” from the buttons below the “Configurations” dialog.

 

 

 

 

 

This will create a new debug target an save it in the Eclipse workspace. Notice that Eclipse is telling you there is an error at this point. It’s reporting “The CPU is not supported by the selected debugger”, and it’s correct because by default Eclipse tries to use the standard x86 debugger.

 

To change this, click on the debugger tab, and change the GDB debugger to be “m68k-bdm-elf-gdb”. This will eliminate the error. While in this window, change the Connection to TCP, The hostname to the IP address of your target, and the port number to the port number given to gdbserver.

 

 

 

 

 

This concludes the setup, hit apply to save the changes. From here on out, to debug this target you can use the pre-created debug configuration from the “configurations” dialog.

 

Now debugging can begin. Hit the debug button to connect, if everything is set up correctly, the debugger will start, connect to the remote target, start the remote program and stop on main.

 

 

 

 

From here on out it’s essentially a regular CDT debugging session, click directly on the code to set breakpoints, use the green arrow to run, the yellow arrows to step, etc….