EBC Exercise 28 Remote gdb and more

From eLinux.org
Revision as of 09:07, 9 April 2011 by Yoder (Talk | contribs) (The Sample Program: Added gdb commands)

Jump to: navigation, search

There are many handy tools to know how to use.


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 both local execution on the BeagleBoard and remote execution with gdb running on your host and debugging code on your Beagle.

Installing gdb

On your host computer run:

$ apt-get install gdb

On your Beagle run:

$ opkg install gdb gdbserver

The Sample Program

You can get the sample program from dfs.

$ sftp dfs.rose-hulman.edu
Connecting to dfs.rose-hulman.edu...
yoder@dfs.rose-hulman.edu's password: 
sftp> cd users/y/yoder/shared/beagleboard                                                                            
sftp> get gdbExample.tar.gz
sftp> exit
$ tar xvf gdbExample.tar.gz 
$ cd gdbExample
$ gedit Makefile

Edit the Makefile and correct ARM_TOOLCHAIN_PATH for your machine. Also search for install: and fix it for your beagle.

$ make all install

This will compile the code and scp to your Beagle. You've just compiled a program that performs a complex fft on random data. It's main purpose is to see how fast it runs on the Beagle. (In case you are interested, I added to rule so you can compile it for your host computer. Try make x86 and compare the times on your host to those on the Beagle.)

The program takes several seconds to run on the Beagle, so you may want to edit the code so it doesn't run so many iterations.

Running gdb on the Beagle

On your Beagle try:

$ gdb cfft_arm
gdb cfft_arm 
GNU gdb (GDB) 7.1
Copyright (C) 2010 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.  Type "show copying"
and "show warranty" for details.
This GDB was configured as "arm-angstrom-linux-gnueabi".
For bug reporting instructions, please see:
Reading symbols from /home/root/gdbExample/cfft_arm...done.
(gdb) b main
Breakpoint 1 at 0x8554
(gdb) r
Starting program: /home/root/gdbExample/cfft_arm 

Breakpoint 1, 0x00008554 in main ()

When first starting gdb notice the line This GDB was configured as "arm-angstrom-linux-gnueabi. This is a good sign. The first command b main sets a breakpoint at main. The next command runs to that break point. Now lets look at our code a this point. Try the list command.

(gdb) l
1	/home/yoder/BeagleBoard/oe/build/tmp-angstrom_2008_1/work/armv7a-angstrom-linux-gnueabi/glibc-2.9-r36.3/build-arm-angstrom-linux-gnueabi/csu/crtn.S: No such file or directory.
	in /home/yoder/BeagleBoard/oe/build/tmp-angstrom_2008_1/work/armv7a-angstrom-linux-gnueabi/glibc-2.9-r36.3/build-arm-angstrom-linux-gnueabi/csu/crtn.S
(gdb) quit

Hmmm.... We have a problem. For gdb to be most useful we need to tell gcc to include debugging information. Back to your host computer and edit the Makefile and find ARM_CFLAGS and add -g. The line should look like:


Now clean everything and remake.

$ make clean all install

Back to the Beagle.

$ gdp cfft_arm
(gdb) b main
(gdb) r
(gdb) l
42	}
44	static complex *new_complex_vector(int size);
46	int main ()
47	{
48	  int i;
49	  int N, n;
50	  int nTimes;
51	  float secs;
(gdb) n
56	    complex *in = new_complex_vector(N);
(gdb) n
57	    complex *out = new_complex_vector(N);
(gdb) n
59	    fft_init (N);
(gdb) p N
$1 = 16

Now l shows the code around the breakpoint. If you aren't seeing code, be sure to scp your .c and .h files to the Beagle.

The n steps to the next line in the program, the p command prints the variable that is listed. Use the s command to step into a function.

(gdb) s
fft_init (N=16) at cfft.c:33
warning: Source file is more recent than executable.
33	  tableW = malloc ((N / 2) * sizeof (complex));
(gdb) l
29	void fft_init (int N)
30	{
31	  int i, j;
33	  tableW = malloc ((N / 2) * sizeof (complex));
34	  bndx = malloc (N * sizeof (int));
35	  ndx = malloc ((N / 2) * sizeof (int));
37	  ndx[0] = 0;

That's enough to get you around a bit. help will get you information about more commands. c will continue from where you stopped.



Binary Utilities