没有合适的资源?快使用搜索试试~ 我知道了~
首页Debugging with gdb Tenth Edition
Debugging with gdb Tenth Edition
需积分: 10 112 浏览量
更新于2023-03-16
评论
收藏 3.08MB PDF 举报
Debugging with gdb The gnu Source-Level Debugger Tenth Edition, for gdb version 7.5-1.0.53
资源详情
资源评论
资源推荐

Debugging with gdb
The gnu Source-Level Debugger
Tenth Edition, for gdb version 7.5-1.0.53
(GDB)
Richard Stallman, Roland Pesch, Stan Shebs, et al .

(Send bugs and comments on gdb to http://www.gnu.org/software/gdb/bugs/.)
Debugging with gdb
T
E
Xinfo 2005-01-30.17
Published by the Free Software Foundation
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
ISBN 978-0-9831592-3-0
Copyright
c
1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1998, 1999, 2000, 2001,
2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010 2011, 2012 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.3 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 w ith 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 Man-
ual. Buying copies from GNU Press supports the FSF in developing GNU and promoting
software freedom.”

i
Table of Contents
Summary of gdb . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1
Free Software . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1
Free Software Ne eds 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 gd b Does During Startup . . . . . . . . . . . . . . . . . . . . . . . . 16
2.2 Quitting gd b . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17
2.3 Shell Com mands . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17
2.4 Logging Output . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17
3 gdb Commands . . . . . . . . . . . . . . . . . . . . . . . . . . . 19
3.1 Command Syntax . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19
3.2 Command Completion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19
3.3 Getting He lp . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21
4 Running Programs Under gdb . . . . . . . . . . . . . 25
4.1 Compiling for Debugging . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25
4.2 Starting your Program . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26
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 Re turn to Later . . . . . . . . . . . . . . . . . . . . . 40
4.12.1 A Non-obvious Benefit of Using Checkpoints . . . . . . . . . . . . 42

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 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 50
5.1.3 Setting Catchpoints . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 53
5.1.4 Deleting Breakpoints . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 56
5.1.5 Disabling Breakpoints. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 57
5.1.6 Break Conditions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 58
5.1.7 Breakpoint Command Lists . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 60
5.1.8 Dynamic Printf . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 61
5.1.9 How to save breakpoints to a file . . . . . . . . . . . . . . . . . . . . . . . . 62
5.1.10 Static Probe Points . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 63
5.1.11 “Cannot insert breakpoints” . . . . . . . . . . . . . . . . . . . . . . . . . . . 63
5.1.12 “Breakpoint address adjusted...” . . . . . . . . . . . . . . . . . . . . . . . 64
5.2 Continuing and Stepping. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 64
5.3 Skipping Over Functions and Files . . . . . . . . . . . . . . . . . . . . . . . . . . . 67
5.4 Signals . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 69
5.5 Stopping and Starting Multi-thread Programs . . . . . . . . . . . . . . . . 71
5.5.1 All-Stop Mode. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 71
5.5.2 Non-Stop Mode. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 72
5.5.3 Background Execution . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 74
5.5.4 Thread-Specific Breakpoints . . . . . . . . . . . . . . . . . . . . . . . . . . . . 75
5.5.5 Interrupted System Calls . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 75
5.5.6 Observer Mode . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 76
6 Debugging Data Race Conditions . . . . . . . . . . 79
6.1 Enable, Disable, and Reset . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 79
6.2 Filters . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 80
6.3 Filter Sets . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 81
6.4 Race Detection History . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 83
7 Running programs backward . . . . . . . . . . . . . . 85
8 Recording Inferior’s Execution and Replaying
It . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 87
9 Examining the Stack . . . . . . . . . . . . . . . . . . . . . . 91
9.1 Stack Frames . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 91
9.2 Backtraces . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 92
9.3 Selecting a Frame . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 94
9.4 Information About a Frame . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 95

iii
10 Examining Source Files . . . . . . . . . . . . . . . . . . 97
10.1 Printing Source Lines . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 97
10.2 Specifying a Location . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 98
10.3 Editing Source Files . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 99
10.3.1 Choosing your Editor . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 100
10.4 Searching Source Files . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 100
10.5 Specifying Source Directories . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 100
10.6 Source and Machine Code . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 103
11 Examining Data . . . . . . . . . . . . . . . . . . . . . . . . 107
11.1 Expressions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 109
11.2 Ambiguous Expressions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 110
11.3 Program Variables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 111
11.4 Artificial Arrays. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 113
11.5 Output Formats. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 114
11.6 Examining Memory . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 115
11.7 Automatic Display . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 117
11.8 Print Settings . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 119
11.9 Pretty Printing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 127
11.9.1 Pretty-Printer Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . 127
11.9.2 Pretty-Printer Example . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 127
11.9.3 Pretty-Printer Commands . . . . . . . . . . . . . . . . . . . . . . . . . . . . 128
11.10 Value History . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 129
11.11 Convenience Variables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 130
11.12 Registers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 132
11.13 Floating Point Hardware. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 133
11.14 Vector Unit. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 133
11.15 Operating System Auxiliary Information . . . . . . . . . . . . . . . . . . 134
11.16 Memory Region Attributes. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 136
11.16.1 Attributes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 137
11.16.1.1 Memory Access Mode . . . . . . . . . . . . . . . . . . . . . . . . . . 137
11.16.1.2 Memory Access Size . . . . . . . . . . . . . . . . . . . . . . . . . . . . 137
11.16.1.3 Data C ache. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 137
11.16.2 Memory Access Checking . . . . . . . . . . . . . . . . . . . . . . . . . . . 137
11.17 Copy Between Memory and a File . . . . . . . . . . . . . . . . . . . . . . . . 138
11.18 How to Produce a Core File from Your Program. . . . . . . . . . . 138
11.19 Character Sets . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 139
11.20 Caching Data of Rem ote Targets . . . . . . . . . . . . . . . . . . . . . . . . . 142
11.21 Search Memory . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 143
12 Debugging Optimized Code . . . . . . . . . . . . . 145
12.1 Inline Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 145
12.2 Tail Call Frames . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 146
13 C Preprocessor Macros . . . . . . . . . . . . . . . . . 149
剩余653页未读,继续阅读















安全验证
文档复制为VIP权益,开通VIP直接复制

评论0