没有合适的资源?快使用搜索试试~ 我知道了~
首页Debugging with gdb.pdf
Debugging with gdb.pdf

Debugging with gdb.pdf,【源码】RapidJSON 源码剖析(0.1):调试工具 GDB 的使用
资源详情
资源评论
资源推荐

Debugging with gdb
The gnu Source-Level Debugger
Tenth Edition, for gdb version 8.2.50.20180708-git
(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 2011-02-14.11
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-2018 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 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 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 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 . . . . . . . . . . . . . . . . . . . . . . . . . . 16
2.2 Quitting gdb . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17
2.3 Shell Commands . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17
2.4 Logging Output . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18
3 gdb Commands . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19
3.1 Command Syntax . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19
3.2 Command Completion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19
3.3 Getting Help . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22
4 Running Programs Under gdb . . . . . . . . . . . . . . . 25
4.1 Compiling for Debugging . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25
4.2 Starting your Program . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26
4.3 Your Program’s Arguments . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 30
4.4 Your Program’s Environment. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 30
4.5 Your Program’s Working Directory . . . . . . . . . . . . . . . . . . . . . . . . . . . . 31
4.6 Your Program’s Input and Output . . . . . . . . . . . . . . . . . . . . . . . . . . . . 32
4.7 Debugging an Already-running Process . . . . . . . . . . . . . . . . . . . . . . . . 33
4.8 Killing the Child Process . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 34
4.9 Debugging Multiple Inferiors and Programs. . . . . . . . . . . . . . . . . . . . 34
4.10 Debugging Programs with Multiple Threads . . . . . . . . . . . . . . . . . . 37
4.11 Debugging Forks . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 41
4.12 Setting a Bookmark to Return to Later. . . . . . . . . . . . . . . . . . . . . . . 44
4.12.1 A Non-obvious Benefit of Using Checkpoints. . . . . . . . . . . . . 45

ii Debugging with gdb
5 Stopping and Continuing . . . . . . . . . . . . . . . . . . . . . 47
5.1 Breakpoints, Watchpoints, and Catchpoints . . . . . . . . . . . . . . . . . . . 47
5.1.1 Setting Breakpoints . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 48
5.1.2 Setting Watchpoints. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 54
5.1.3 Setting Catchpoints . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 56
5.1.4 Deleting Breakpoints . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 61
5.1.5 Disabling Breakpoints . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 62
5.1.6 Break Conditions. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 63
5.1.7 Breakpoint Command Lists . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 65
5.1.8 Dynamic Printf . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 66
5.1.9 How to save breakpoints to a file . . . . . . . . . . . . . . . . . . . . . . . . . 67
5.1.10 Static Probe Points . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 68
5.1.11 “Cannot insert breakpoints”. . . . . . . . . . . . . . . . . . . . . . . . . . . . . 69
5.1.12 “Breakpoint address adjusted...” . . . . . . . . . . . . . . . . . . . . . . . . 70
5.2 Continuing and Stepping . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 70
5.3 Skipping Over Functions and Files . . . . . . . . . . . . . . . . . . . . . . . . . . . . 74
5.4 Signals. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 76
5.5 Stopping and Starting Multi-thread Programs . . . . . . . . . . . . . . . . . 79
5.5.1 All-Stop Mode . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 80
5.5.2 Non-Stop Mode . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 81
5.5.3 Background Execution . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 82
5.5.4 Thread-Specific Breakpoints . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 83
5.5.5 Interrupted System Calls . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 83
5.5.6 Observer Mode . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 84
6 Running programs backward . . . . . . . . . . . . . . . . . 87
7 Recording Inferior’s Execution and Replaying
It . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 89
8 Examining the Stack . . . . . . . . . . . . . . . . . . . . . . . . . . 97
8.1 Stack Frames . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 97
8.2 Backtraces . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 98
8.3 Selecting a Frame . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 100
8.4 Information About a Frame . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 101
8.5 Management of Frame Filters.. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 102

iii
9 Examining Source Files . . . . . . . . . . . . . . . . . . . . . . 105
9.1 Printing Source Lines . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 105
9.2 Specifying a Location . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 106
9.2.1 Linespec Locations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 106
9.2.2 Explicit Locations. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 107
9.2.3 Address Locations. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 108
9.3 Editing Source Files. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 109
9.3.1 Choosing your Editor . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 109
9.4 Searching Source Files . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 110
9.5 Specifying Source Directories . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 110
9.6 Source and Machine Code . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 113
10 Examining Data. . . . . . . . . . . . . . . . . . . . . . . . . . . . . 119
10.1 Expressions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 121
10.2 Ambiguous Expressions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 122
10.3 Program Variables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 123
10.4 Artificial Arrays . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 126
10.5 Output Formats . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 126
10.6 Examining Memory . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 128
10.7 Automatic Display . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 130
10.8 Print Settings. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 132
10.9 Pretty Printing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 140
10.9.1 Pretty-Printer Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . 140
10.9.2 Pretty-Printer Example . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 141
10.9.3 Pretty-Printer Commands. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 141
10.10 Value History. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 142
10.11 Convenience Variables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 143
10.12 Convenience Functions. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 146
10.13 Registers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 148
10.14 Floating Point Hardware. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 150
10.15 Vector Unit. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 150
10.16 Operating System Auxiliary Information . . . . . . . . . . . . . . . . . . . 150
10.17 Memory Region Attributes. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 152
10.17.1 Attributes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 153
10.17.1.1 Memory Access Mode . . . . . . . . . . . . . . . . . . . . . . . . . . . . 153
10.17.1.2 Memory Access Size. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 154
10.17.1.3 Data Cache . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 154
10.17.2 Memory Access Checking . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 154
10.18 Copy Between Memory and a File . . . . . . . . . . . . . . . . . . . . . . . . . 154
10.19 How to Produce a Core File from Your Program . . . . . . . . . . . 155
10.20 Character Sets. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 156
10.21 Caching Data of Targets . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 159
10.22 Search Memory . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 160
10.23 Value Sizes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 162
11 Debugging Optimized Code . . . . . . . . . . . . . . . . 163
11.1 Inline Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 163
11.2 Tail Call Frames . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 164
剩余821页未读,继续阅读












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

评论1