Debugging Your Application on Embedded Device

From Embedded Nirvana

Jump to: navigation, search

Setting up debug environment for your embedded application can be quite a tricky task.The debug environment, GDB, the GNU debugger helps in easy debugging of the applications which are created for an embedded target device. Instead of setting up a full fledged GDB on the target platform, a GDBserver can be set up on the target which debugs the executable created for the target, provided the executable must be resident on the target itself. The GDB must be run on the host and the source code and copy of the binary file to be debugged must reside on the host. Here are the steps in setting up your debug environment.

  1. Compile gdb for your target architecture (e.g. ARM, AVR, etc).
  2. Cross-compile gdbserver for your target device (mini2440, beagleboard, etc).
  3. Upload gdbserver on your target device.
  4. Use gdb from your host to debug the code.

Before starting this, let's assume following IP address

# Host   :
# Target :

Good to see a tnaelt at work. I can't match that.

Cross Compiling gdbserver

Go to the gdbserver directory

cd /xxx/gdb-x.x/gdb/gdbserver
./configure --target=arm-linux --host=arm-linux CFLAGS='-march=armv4t -mtune=arm920 -O0'
make CC=arm-linux-gcc <path of the cross compiler>

you should add [| CFLAGS] while configuring the gdbserver. The make file directives are

  1. -march=armv4t : Suggests that the target architecture (Machine architecture, hence m-arch) is arm9
  2. -mtune=arm920 : Same as march, but this is for compatibility with the older version.
  3. O0 : Optimisation level is set to zero, i.e. do not optimise the code, since we are using it for debugging.

use arm-linux-gcc to build this project. A binary gdbserver will be generated.

Running gdbserver on your host

You can copy the gdbserver file in /usr/bin dir of your target device for easier access. Also you need to copy you program to the target device before debugging. Now start the gdbserver

gdbserver hostip:port binary
e.g gdbserver a.out

You should get a message

Listening on port 1234

Now start gdb on our host, simply by running arm-linux-core-gdb command.

you would get the gdb prompt.

Now specify your remote device with this instruction:

target remote targetip:port
e.g. target remote

specify break point.

b <line number>

and start debugging with continue instruction


Also see using eclipse IDE for remote debugging and Debugging realtime application

Personal tools