Debugging User Mode Applications

Please note that you should always set the correct paths when debugging an application which uses shared libraries.

Make Debug

To be able to debug a program, you must build it with debugging in mind. With the Axis software distribution there is a make target that does this for you, called 'debug' (check tools/build/rules/common.mak for details).

To build your application for debugging, go to the subsystem you want to debug and:

make debug && make clean && make install

(and 'make nodebug' to turn off debug).

Below follows a summary of what 'make debug' does (and what you need to do if you don't use it).

  • Adds -g to the compiler flags. This will include debug information in the program. (The default debug format is Dwarf-2.)
  • Removes -s (which strips the program from its symbol information) from the link flags. (If your program is in ELF format, the 'file' command will tell you whether it's stripped or not.) The symbols are only needed on the host side when debugging, and 'make install' automatically strips the binary when putting it in the install directory (/bin, for example).
  • Turns off optimizations (adds -O0 to the compiler flags). This makes it easier to debug the program, but it may affect the behaviour. You can debug optimized code, but be aware that the compiler has probably rearranged the execution order of your statements. Also, variables may have been optimized away.
  • Adds -fno-omit-frame-pointer to your compiler flags. This is a nop when the optimization level is set to 0, but it's there as a reminder that you should keep it if you change the debug optimization level (gcc optimizations starting at -O2 imply -fomit-frame-pointer). The frame pointer acts as a local stack pointer inside a function, and will be placed in register r8.

Return to the top-level of the build system and:

make images

Flash load your target as described in the section on flash loading.

Starting a Program

Note: The gdbserver must be installed on the target. If not, see gdb-server for instructions.

Telnet, or log in via the serial port (if you have agetty on that port) to your board. The preferred way to communicate with gdb on the host side is over TCP/IP. On the target:

  gdbserver [<hostname/ip address>]:<port> <program> [<arguments for program>]
  Example: gdbserver hostname:1234 /tmp/hello_world

Now start gdb-cris on the host.

  gdb-cris [<program>]
  Example: gdb-cris ~/axis/devboard/apps/hello/hello_world

If you don't load the program in gdb-cris you must make sure that the current cris-version is correct before connecting to the target. Axis Etrax 100LX har cris version 10 and Axis Etrax FS has cris-version 32.

  (gdb) show cris-version 
  The current CRIS version is 10.
  (gdb) set cris-version 32
  (gdb) show cris-version 
  The current CRIS version is 32.

To connect to the target:

  target <hostname/ip address>:<port> (make sure you specify the same port number)
  Example: (gdb) target remote

To debug over a serial connection, make sure it is enabled in the kernel configuration (under “Drivers for Etrax built-in interfaces”) and not used for anything else. One of the ports is often used by the kernel for debug printouts, or agetty might be using it (check your /etc/inittab). On the target:

  gdbserver <device> <program>
  Example: gdbserver /dev/ttyS2 /tmp/hello_world

Then start gdb-cris on the host. To connect you need to specify what device on the host you have connected the serial cable to:

  target remote <device>
  Example: (gdb) target remote /dev/ttyS0

After you have connected to the target, you will end up in the startup routine for the C library the application is using (often called _start). To get to the main function of your application, simply set a breakpoint at main and continue:

  (gdb) break main
  Breakpoint 1 at 0x80342: file hello.c, line 3.
  (gdb) continue 
  Breakpoint 1, main (argc=1, argv=0xaf897ec4) at hello.c:3
  3         printf("Hello World!\n");

Attaching to a Process

You may attach to an already running process by giving the process id as an argument to the gdbserver:

  gdbserver [<hostname/ip address/device>]:<port> <pid>
  Example: gdbserver hostname:2345 32
axis/gdb-debug-apps.txt · Last modified: 2007/03/27 15:31 by jesper
All text is available under the terms of the GNU Free Documentation License (see Copyrights for details).