Difference between revisions of "EBC Exercise 14 gdb Debugging"

From eLinux.org
Jump to: navigation, search
m (A gbd Tutorial)
(A gdb Tutorial)
 
(22 intermediate revisions by 4 users not shown)
Line 22: Line 22:
  
 
On your Beagle run:
 
On your Beagle run:
<pre>
 
$ opkg update
 
$ opkg install gdb
 
</pre>
 
  
=== A gbd Tutorial ===
+
beagle$ '''opkg update'''
 +
beagle$ '''opkg install gdb'''
  
There are a number of gbd tutorials out there.  I like [http://www.dirac.org/linux/gdb/ Using GNU's GDB Debugger By Peter Jay Salzman]. Read Chapter 1, the IntroDo the examples in Chapters 2 and 3. Look over Breakpoints in Chapter 4.
+
=== A gdb Tutorial ===
 +
 
 +
There are a number of gdb tutorials out there.  I like [http://rsquared.sdf.org/gdb/ Using GNU's GDB Debugger By Peter Jay Salzman].  
 +
 
 +
* Read Chapter 1, the Intro
 +
* Do the examples in Chapters 2 (skip the spinning cube example in 2.8 unless you are interested in openGL)  Hint: the commands to uncompress a .tar.bz2 file are:
 +
beagle$ '''bunzip2 file.tar.bz2'''
 +
beagle$ '''tar xvf file.tar'''
 +
* Do Chapter 3 examples  
 +
* Look over Breakpoints in Chapter 4
 +
 
 +
([http://www.unknownroad.com/rtfm/gdbtut/gdbtoc.html RMS's gdb Debugger Tutorial] may be another good reference.)
 +
 
 +
Chapter 3 has you download a Makefile that will fail because it can't find '''ctags'''.  Either comment out that line, or follow the directions below to install ctags.
 +
 
 +
=== Remote debugging with gdb ===
 +
You can run a gdb server on the bone and control it from a gdb session on your host. [[EBC Exercise 28 Remote gdb and more]] has details on how this is done.
  
 
=== ctags on the host ===
 
=== ctags on the host ===
Line 35: Line 48:
 
Here's what I did to get ctags running in gedit on the host.
 
Here's what I did to get ctags running in gedit on the host.
  
<pre>
+
host$ '''sudo apt-get install exuberant-ctags'''
$ sudo apt-get install exuberant-ctags
+
 
</pre>
 
 
gedit has a ctags plugin.  Details are [http://sourceforge.net/projects/symbol-browser/ here]. Download from [http://sourceforge.net/projects/symbol-browser/files/symbol-browser-bin/ here].  Installation details are [http://www.micahcarrick.com/gedit-symbol-browser-plugin.html#2 here].
 
gedit has a ctags plugin.  Details are [http://sourceforge.net/projects/symbol-browser/ here]. Download from [http://sourceforge.net/projects/symbol-browser/files/symbol-browser-bin/ here].  Installation details are [http://www.micahcarrick.com/gedit-symbol-browser-plugin.html#2 here].
  
 
You also need to load '''libgnomeprintui'''.  Go to '''System:Administration:Synaptic Package Manager''' and search for libgnomeprintui and select it.  Click Apply.
 
You also need to load '''libgnomeprintui'''.  Go to '''System:Administration:Synaptic Package Manager''' and search for libgnomeprintui and select it.  Click Apply.
  
Now you can use ctags. Go a directory with some .c and .h files and run:
+
NOTE FOR Newest Ubuntu Releases!
<pre>
+
Synaptic Package Manager is not natively installed, do the following commands:
$ ctags *.c *.h
+
 
$ gedit *.c *.h
+
host$ '''sudo apt-get install synaptic'''
</pre>
 
This will create a file called '''tags''' that tells where each symbol is defined. Enable the ctags plugin by going to '''Edit:Preferences'''.  Click the '''Plugins''' tag and scroll down to '''Symbol Browser''' and check it.  You can click the '''Configure Plugin''' button to apply some options.
 
  
To make the symbols visible, select ''' View:Side Pane''' in gedit.  Click the symbol [[File:SymbolBrowser.png]] at the bottom of the side pane.  You will now see all the symbols.  Click on one to go to its definition.
+
Then you can install the above file.  
  
=== ctags on the Beagle ===
+
Now you can use ctags.  Go a directory with some .c and .h files and run:
  
Details some day.
+
host$ '''ctags *.c *.h'''
 +
host$ '''gedit *.c *.h'''
  
== strace ==
+
This will create a file called '''tags''' that tells where each symbol is defined. Enable the ctags plugin by going to '''Edit:Preferences'''.  Click the '''Plugins''' tag and scroll down to '''Symbol Browser''' and check it.  You can click the '''Configure Plugin''' button to apply some options.
  
'''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.
+
To make the symbols visible, select ''' View:Side Pane''' in gedit.  Click the symbol [[File:SymbolBrowser.png]] at the bottom of the side pane. You will now see all the symbols.  Click on one to go to its definition.
<pre>
 
$ 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
 
</pre>
 

Latest revision as of 12:33, 25 September 2013


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:

beagle$ opkg update
beagle$ opkg install gdb

A gdb Tutorial

There are a number of gdb tutorials out there. I like Using GNU's GDB Debugger By Peter Jay Salzman.

  • Read Chapter 1, the Intro
  • Do the examples in Chapters 2 (skip the spinning cube example in 2.8 unless you are interested in openGL) Hint: the commands to uncompress a .tar.bz2 file are:
beagle$ bunzip2 file.tar.bz2
beagle$ tar xvf file.tar
  • Do Chapter 3 examples
  • Look over Breakpoints in Chapter 4

(RMS's gdb Debugger Tutorial may be another good reference.)

Chapter 3 has you download a Makefile that will fail because it can't find ctags. Either comment out that line, or follow the directions below to install ctags.

Remote debugging with gdb

You can run a gdb server on the bone and control it from a gdb session on your host. EBC Exercise 28 Remote gdb and more has details on how this is done.

ctags on the host

Here's what I did to get ctags running in gedit on the host.

host$ sudo apt-get install exuberant-ctags

gedit has a ctags plugin. Details are here. Download from here. Installation details are here.

You also need to load libgnomeprintui. Go to System:Administration:Synaptic Package Manager and search for libgnomeprintui and select it. Click Apply.

NOTE FOR Newest Ubuntu Releases! Synaptic Package Manager is not natively installed, do the following commands:

host$ sudo apt-get install synaptic

Then you can install the above file.

Now you can use ctags. Go a directory with some .c and .h files and run:

host$ ctags *.c *.h
host$ gedit *.c *.h

This will create a file called tags that tells where each symbol is defined. Enable the ctags plugin by going to Edit:Preferences. Click the Plugins tag and scroll down to Symbol Browser and check it. You can click the Configure Plugin button to apply some options.

To make the symbols visible, select View:Side Pane in gedit. Click the symbol SymbolBrowser.png at the bottom of the side pane. You will now see all the symbols. Click on one to go to its definition.