Debugging with gdb
Debugging with gdb
The gnu Source-Level Debugger
Ninth Edition, for gdb version 7.0.50.20100218-cvs
(Sourcery G++ Lite 2010q1-188)
Richard Stallman, Roland Pesch, Stan Shebs, et al.
(Send bugs and comments on gdb to .)
Debugging with gdb TEXinfo 2008-04-18.10
Published by the Free Software Foundation 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA ISBN 1-882114-77-9 Copyright c 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010 Free Software Foundation, Inc. Permission is granted to copy, distribute and/or modify this document under the terms of the GNU Free Documentation License, Version 1.1 or any later version published by the Free Software Foundation; with the Invariant Sections being "Free Software" and "Free Software Needs Free Documentation", with the Front-Cover Texts being "A GNU Manual," and with the Back-Cover Texts as in (a) below. (a) The FSF's Back-Cover Text is: "You are free to copy and modify this GNU Manual. Buying copies from GNU Press supports the FSF in developing GNU and promoting software freedom."
This edition of the GDB manual is dedicated to the memory of Fred Fish. Fred was a long-standing contributor to GDB and to Free software in general. We will miss him.
i
Table of Contents
Summary of gdb . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1
Free Software . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1 Free Software Needs Free Documentation . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1 Contributors to gdb. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3
1 A Sample gdb Session . . . . . . . . . . . . . . . . . . . . . . . . . . 7
2 Getting In and Out of gdb . . . . . . . . . . . . . . . . . . . 11
2.1 Invoking gdb . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11 2.1.1 Choosing Files . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12 2.1.2 Choosing Modes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13 2.1.3 What gdb Does During Startup . . . . . . . . . . . . . . . . . . . . . . . . . . 15
2.2 Quitting gdb . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16 2.3 Shell Commands . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16 2.4 Logging Output . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17
3 gdb Commands . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19
3.1 Command Syntax . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19 3.2 Command Completion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19 3.3 Getting Help . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21
4 Running Programs Under gdb . . . . . . . . . . . . . . . 25
4.1 Compiling for Debugging . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25 4.2 Starting your Program . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25 4.3 Your Program's Arguments . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 28 4.4 Your Program's Environment. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 29 4.5 Your Program's Working Directory . . . . . . . . . . . . . . . . . . . . . . . . . . . . 30 4.6 Your Program's Input and Output . . . . . . . . . . . . . . . . . . . . . . . . . . . . 30 4.7 Debugging an Already-running Process . . . . . . . . . . . . . . . . . . . . . . . . 31 4.8 Killing the Child Process . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 32 4.9 Debugging Multiple Inferiors and Programs. . . . . . . . . . . . . . . . . . . . 32 4.10 Debugging Programs with Multiple Threads . . . . . . . . . . . . . . . . . . 35 4.11 Debugging Forks . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 38 4.12 Setting a Bookmark to Return to Later. . . . . . . . . . . . . . . . . . . . . . . 40
4.12.1 A Non-obvious Benefit of Using Checkpoints . . . . . . . . . . . . . 41
ii
Debugging with gdb
5 Stopping and Continuing . . . . . . . . . . . . . . . . . . . . . 43
5.1 Breakpoints, Watchpoints, and Catchpoints . . . . . . . . . . . . . . . . . . . 43 5.1.1 Setting Breakpoints . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 44 5.1.2 Setting Watchpoints . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 49 5.1.3 Setting Catchpoints . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 51 5.1.4 Deleting Breakpoints . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 55 5.1.5 Disabling Breakpoints . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 55 5.1.6 Break Conditions. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 56 5.1.7 Breakpoint Command Lists . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 58 5.1.8 "Cannot insert breakpoints" . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 59 5.1.9 "Breakpoint address adjusted...". . . . . . . . . . . . . . . . . . . . . . . . . . 59
5.2 Continuing and Stepping . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 60 5.3 Signals . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 63 5.4 Stopping and Starting Multi-thread Programs . . . . . . . . . . . . . . . . . 65
5.4.1 All-Stop Mode . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 65 5.4.2 Non-Stop Mode . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 67 5.4.3 Background Execution . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 68 5.4.4 Thread-Specific Breakpoints . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 69 5.4.5 Interrupted System Calls . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 69
6 Running programs backward . . . . . . . . . . . . . . . . . 71
7 Recording Inferior's Execution and Replaying It . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 73
8 Examining the Stack . . . . . . . . . . . . . . . . . . . . . . . . . . 77
8.1 Stack Frames . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 77 8.2 Backtraces . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 78 8.3 Selecting a Frame . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 80 8.4 Information About a Frame . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 81
9 Examining Source Files . . . . . . . . . . . . . . . . . . . . . . . 83
9.1 Printing Source Lines . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 83 9.2 Specifying a Location . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 84 9.3 Editing Source Files . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 85
9.3.1 Choosing your Editor . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 85 9.4 Searching Source Files . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 86 9.5 Specifying Source Directories . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 86 9.6 Source and Machine Code . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 89
................
................
In order to avoid copyright disputes, this page is only a partial summary.
To fulfill the demand for quickly locating and searching documents.
It is intelligent file search solution for home and business.
Related searches
- working with teens with autism
- dealing with teenagers with asperger s
- dealing with someone with asperger s
- cheat with friends with words
- words with friends with friends
- dealing with people with asperger s
- living with someone with asperger s
- help with word with friends
- communicating with someone with asperger s
- help with words with friends
- personal loan with bad credit with cosigner
- dealing with adults with asperger s