Remote debugging

From Klaus' wiki
Revision as of 09:34, 29 February 2012 by Klaus (Talk | contribs)

Jump to: navigation, search

Debugging on a tiny target system may be impossible, because there are no room for the gdb and all the source and binary files on the target system. Luckily remote debugging is available.

There are two (at least) options: DDD or Eclipse.

DDD is a gui for gdb, the GNU debugger. DDD might be available in Cygwin, I don't know. But it is available in all decent Linux distributions.

There are some prerequisites:

  • There shall be opened a port for connecting on the target, if a firewall is installed on it
  • The source shall be available on the debugging host
  • The gdbserver shall be included on the target system (use make menuconfig)

When the code has been compiled and transferred to the target host start the remote gdbserver on the target:

gdbserver

]$ gdbserver <host-to-expect-connection-from>:<port-number> <programme>

example:

]$ gdbserver 10.1.18.73:11000 myprogram

On the devhost

Fire up your debugging environment, i.e. DDD or Eclipse.

DDD

Now on the debugging host start DDD. In the command window below type in:

target extended-remote <target-host>:<port-number> <programme>

example:

(gdb) target 10.1.18.210:11000 myprogram

In the console where you've started the gdbserver you should now see that a remote debugger has connected.

Remote debugging from host 10.1.18.73

Next open the executable in the DDD using the file command:

file <path-to-executable>/<executable>

example:

file myprogram

The source shall open in the upper window.

Set a breakpoint either by continuously right-click on the line you want the breakpoint or by typing

break <path-to-source>/<source-file>:<line-number>

example:

break ../main.cpp:14

Now run the program using the small window with the Run, Interrupt, Step,... buttons or typing run in the lower window.

You can single step by clicking on the Step button or by typing step in the lower window.

Ddd debugging.png

Try the different possibilities - its almost like using the built-in debugger in Eclipse (which by the way is also gdb :-) ).

Eclipse

In order to setup Eclipse as a debug station follow these instructions:

First setup the debug configuration as shown.

Gdbserver debugging1.png

In the debugger tab choose gdbserver debugger.

Gdbserver debugging2.png

Finally set-up the communication in the Connection tab.

Gdbserver debugging3.png