EBC Exercise 14 gdb Debugging

From eLinux.org
Revision as of 15:12, 18 August 2011 by Yoder (talk | contribs) (A gbd Tutorial)
Jump to: navigation, search


As the code becomes more complex, more powerful debugging tools are needed. The GNU Project debugger (gdb) is the granddaddy of all debuggers. In this exercise you will learn how to install and use it on the Beagle. In a later exercise you will learn how to install it on your host and debug the Beagle remotely.

gdb

gdb, the GNU Project debugger, allows you to see what is going on inside another program while it executes -- or what another program was doing at the moment it crashed.

gdb can do four main kinds of things to help you catch bugs in the act:

  • Start your program, specifying anything that might affect its behavior.
  • Make your program stop on specified conditions.
  • Examine what has happened, when your program has stopped.
  • Change things in your program, so you can experiment with correcting the effects of one bug and go on to learn about another.

The program being debugged can be written in Ada, C, C++, Objective-C, Pascal (and many other languages). Those programs might be executing on the same machine as GDB (native) or on another machine (remote). GDB can run on most popular UNIX and Microsoft Windows variants.

For our lab we'll be using a C program and do local execution on the Beagle.

Installing gdb

On your Beagle run:

$ opkg update
$ opkg install gdb

A gbd Tutorial

There are a number of gbd tutorials out there. I like this one.

See if you can find ctags on the Beagle.

strace

strace is a nice debugging tool that shows all the system calls a program is making. The book gives some nice examples of using strace. One place I used it was to learn where httpd looked for configuration files.

$ strace httpd
...
open("/etc/httpd.conf", O_RDONLY|O_LARGEFILE) = -1 ENOENT (No such file or directory)
open("httpd.conf", O_RDONLY|O_LARGEFILE) = -1 ENOENT (No such file or directory)
rt_sigaction(SIGHUP, {0x1a39c, [], SA_RESTART|0x4000000}, NULL, 8) = 0
open("/dev/null", O_RDWR|O_LARGEFILE)   = 4
clone(child_stack=0, flags=CLONE_CHILD_CLEARTID|CLONE_CHILD_SETTID|SIGCHLD, child_tidptr=0x4001df98) = 3595
io_submit(0, 0, 0xfbad2088 <unfinished ... exit status 0>
Process 3594 detached