Thinking in C and *nix (CSC 295/282 2014S) : Outlines

Outline 11: Debugging with GDB


Held: Thursday, 17 April 2014

Back to Outline 10 - Improved Make. On to Outline 12 - Miscellaneous C Programming Issues.

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

Copyright (c) 2013-14 Samuel A. Rebelsky.

Creative Commons License

This work is licensed under a Creative Commons Attribution 3.0 Unported License. To view a copy of this license, visit http://creativecommons.org/licenses/by/3.0/ or send a letter to Creative Commons, 543 Howard Street, 5th Floor, San Francisco, California, 94105, USA.