Thinking in C and *nix (CSC 282 2015S) : Outlines

Outline 07: Debugging with gdb


Held: Thursday, 5 March 2015

Back to Outline 06 - Compilation, Macros, and the C Preprocessor. On to Outline 08 - Using Macros for Logging.

Summary

We quickly explore gdb, the GNU debugger.

Related Pages

Overview

Administrivia

Debuggers

gdb

Tracing Crashes

We'll start with one typical use of gdb - figuring out what line in your program caused a segfault.

We'll use boom.c, a program that I designed to crash.

$ gdb boom
(gdb) run
Program received signal SIGSEGV, Segmentation fault.
0x08048440 in baz (i=0) at boom.c:64
64          *ip = i;
(gdb) bt
#0  0x08048440 in baz (i=0) at boom.c:64
#1  0x080483f5 in qux (i=1) at boom.c:55
#2  0x0804840c in qux (i=2) at boom.c:57
...
#12 0x0804844f in baz (i=67) at boom.c:66
#13 0x08048466 in main (argc=1, argv=0xbffffa54) at boom.c:77
(gdb) p i
$1 = 0
(gdb) p ip
$2 = (int *) 0x0

Some other operations

l *LINE_NUMBER*

l *PROCEDURE*

b *LINE_NUMBER*

run

n

s

c

p *EXPRESSION*

watch *variable*

Another Example