Thinking in C and *nix (CSC 282 2015S) : Outlines
Primary: [Front Door] [Schedule] - [Academic Honesty] [Disabilities] [Email] [FAQ] [Teaching & Learning] - [Calendar]
Current: [Outline] [EBoard] [Lab] [Assignment]
Sections: [Assignments] [EBoards] [Examples] [Handouts] [Labs] [Outlines]
Reference: [EBook] - [ISO] [GNU Coding Standards] [GCC Documentation] - [TAoUP] [Make3]
Previous Offerings: [CSC 295 2013S] [CSC 295 2014S]
Misc: [SamR] [Glimmer Labs] [CS@Grinnell] [Grinnell] [Issue Tracker]
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
assert.printf statements. (Not a great idea.)printf, so we'll look at using a debugger.printf? Because you spend a lot of time
inserting and removing print statements. A debugger is usually much faster.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.
-g flag. This enables debugging
information. $ 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
l *LINE_NUMBER*
l *PROCEDURE*
b *LINE_NUMBER*
run
n
s
c
p *EXPRESSION*
watch *variable*