Thinking in C and *nix (CSC 295/282 2014S) : 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]
Related Courses: [CSC 295 2013S]
Misc: [SamR] [Glimmer Labs] [CS@Grinnell] [Grinnell] [Issue Tracker]
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
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*
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]
Related Courses: [CSC 295 2013S]
Misc: [SamR] [Glimmer Labs] [CS@Grinnell] [Grinnell] [Issue Tracker]
Copyright (c) 2013-14 Samuel A. Rebelsky.

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.