没有合适的资源?快使用搜索试试~ 我知道了~
资源详情
资源评论
资源推荐
Debugging with gdb
The gnu Source-Level Debugger
Tenth Edition, for gdb version 10.2.90.20210621-git
(GNU Tools for STM32 10.3-2021.10.20211105-1100)
Richard Stallman, Roland Pesch, Stan Shebs, et al.
(Send bugs and comments on gdb to https://www.gnu.org/software/gdb/bugs/.)
Debugging with gdb
T
E
Xinfo 2018-01-09.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-2021 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 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18
2.4 Logging Output . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19
3 gdb Commands. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21
3.1 Command Syntax . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21
3.2 Command Settings . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21
3.3 Command Completion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22
3.4 Command Options . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25
3.5 Automatically Prepend Default
Arguments to User-Defined Aliases . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26
3.6 Getting Help . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 27
4 Running Programs under gdb . . . . . . . . . . . . . . . . 31
4.1 Compiling for Debugging . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 31
4.2 Starting Your Program . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 32
4.3 Your Program’s Arguments . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 36
4.4 Your Program’s Environment . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 36
4.5 Your Program’s Working Directory . . . . . . . . . . . . . . . . . . . . . . . . . . . . 37
4.6 Your Program’s Input and Output . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 38
4.7 Debugging an Already-Running Process. . . . . . . . . . . . . . . . . . . . . . . . 39
4.8 Killing the Child Process . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 40
4.9 Debugging Multiple Inferiors Connections and Programs . . . . . . . 40
4.10 Debugging Programs with Multiple Threads . . . . . . . . . . . . . . . . . . 44
4.11 Debugging Forks . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 49
4.12 Setting a Bookmark to Return to Later . . . . . . . . . . . . . . . . . . . . . . . 51
4.12.1 A Non-obvious Benefit of Using Checkpoints . . . . . . . . . . . . . 53
ii Debugging with gdb
5 Stopping and Continuing . . . . . . . . . . . . . . . . . . . . . . 55
5.1 Breakpoints, Watchpoints, and Catchpoints . . . . . . . . . . . . . . . . . . . . 55
5.1.1 Setting Breakpoints. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 56
5.1.2 Setting Watchpoints . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 62
5.1.3 Setting Catchpoints. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 65
5.1.4 Deleting Breakpoints . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 70
5.1.5 Disabling Breakpoints . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 70
5.1.6 Break Conditions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 72
5.1.7 Breakpoint Command Lists . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 73
5.1.8 Dynamic printf . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 74
5.1.9 How to Save Breakpoints to a File . . . . . . . . . . . . . . . . . . . . . . . . 76
5.1.10 Static Probe Points . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 76
5.1.11 “Cannot insert breakpoints” . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 78
5.1.12 “Breakpoint address adjusted...” . . . . . . . . . . . . . . . . . . . . . . . . . 78
5.2 Continuing and Stepping . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 79
5.3 Skipping over Functions and Files. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 82
5.4 Signals . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 85
5.5 Stopping and Starting Multi-Thread Programs . . . . . . . . . . . . . . . . . 88
5.5.1 All-Stop Mode. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 89
5.5.2 Non-Stop Mode. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 90
5.5.3 Background Execution . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 91
5.5.4 Thread-Specific Breakpoints . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 92
5.5.5 Interrupted System Calls . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 92
5.5.6 Observer Mode . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 93
6 Running Programs Backward . . . . . . . . . . . . . . . . . 95
7 Recording Inferior’s Execution
and Replaying It . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 97
8 Examining the Stack . . . . . . . . . . . . . . . . . . . . . . . . . 105
8.1 Stack Frames. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 105
8.2 Backtraces . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 106
8.3 Selecting a Frame . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 109
8.4 Information about a Frame . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 111
8.5 Applying a Command to Several Frames . . . . . . . . . . . . . . . . . . . . . . 112
8.6 Management of Frame Filters. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 114
9 Examining Source Files . . . . . . . . . . . . . . . . . . . . . . 117
9.1 Printing Source Lines. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 117
9.2 Specifying a Location. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 118
9.2.1 Linespec Locations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 118
9.2.2 Explicit Locations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 119
9.2.3 Address Locations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 120
9.3 Editing Source Files . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 121
9.3.1 Choosing Your Editor . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 121
iii
9.4 Searching Source Files . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 122
9.5 Specifying Source Directories . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 122
9.6 Source and Machine Code . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 126
10 Examining Data . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 131
10.1 Expressions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 134
10.2 Ambiguous Expressions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 135
10.3 Program Variables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 136
10.4 Artificial Arrays. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 139
10.5 Output Formats. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 140
10.6 Examining Memory . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 141
10.7 Automatic Display . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 144
10.8 Print Settings . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 145
10.9 Pretty Printing. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 155
10.9.1 Pretty-Printer Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 155
10.9.2 Pretty-Printer Example. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 155
10.9.3 Pretty-Printer Commands . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 156
10.10 Value History . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 157
10.11 Convenience Variables. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 158
10.12 Convenience Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 161
10.13 Registers. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 165
10.14 Floating Point Hardware . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 167
10.15 Vector Unit . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 167
10.16 Operating System Auxiliary Information . . . . . . . . . . . . . . . . . . . 167
10.17 Memory Region Attributes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 169
10.17.1 Attributes. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 170
10.17.1.1 Memory Access Mode . . . . . . . . . . . . . . . . . . . . . . . . . . . . 170
10.17.1.2 Memory Access Size . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 171
10.17.1.3 Data Cache . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 171
10.17.2 Memory Access Checking. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 171
10.18 Copy between Memory and a File . . . . . . . . . . . . . . . . . . . . . . . . . . 171
10.19 How to Produce a Core File from Your Program . . . . . . . . . . . . 172
10.20 Character Sets . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 173
10.21 Caching Data of Targets . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 176
10.22 Search Memory . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 177
10.23 Value Sizes. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 179
11 Debugging Optimized Code . . . . . . . . . . . . . . . . 181
11.1 Inline Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 181
11.2 Tail Call Frames . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 182
12 C Preprocessor Macros . . . . . . . . . . . . . . . . . . . . . 185
剩余877页未读,继续阅读
1e00zs
- 粉丝: 1
- 资源: 13
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功
评论0