没有合适的资源?快使用搜索试试~ 我知道了~
首页Linux GDB调试文档
资源详情
资源评论
资源推荐

Debugging with gdb
The gnu Source-Level Debugger
Tenth Edition, for gdb version 8.0.1.19.a76e2bffa6+1714abab88
(GDB)
Intel documentation version number 1.18.0
Documentation extensions by Intel Corporation
Richard Stallman, Roland Pesch, Stan Shebs, et al.

(Send bugs and comments on gdb to Intel’s Debug Solutions User Forum (http://
software.intel.com/forums/debug-solutions).)
See Chapter 32 [GDB Bugs], page 579, for details on how to report bugs.
Debugging with gdb
T
E
Xinfo 2017-06-04.19
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-2017 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.”
Copyright
c
2016-2018, Intel Corporation. Intel’s modifications are provided pursuant to
the GNU Free Documentation license. For more information, see Appendix M [GNU Free
Documentation License], page 749.

List of extended features for gdb version 8.0.1.19.a76e2bffa6+1714abab88:
• Debugging OpenMP*:
Section 12.5 [OpenMP* Debugging], page 169.
• Debugging Data Race Conditions:
Section 12.1 [Data Race Detection], page 163.
• Decoding Abort Reasons of a Speculative Execution:
Section 12.2 [Decoding Abort Reasons], page 167,
• Detecting Boundary Violations in code:
Section 12.3 [Pointer Checker], page 168,
• Serializing the execution of parallel applications with Intel
R
Cilk(TM) Plus:
Section 12.4 [Serializing Parallel Execution], page 168.
‘gdb-ia’ For debugging IA-32/Intel
R
64 Applications, the command to invoke gdb is
gdb-ia.

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 . . . . . . . . . . . . . . . . . . . . . . . . 32
4.8 Killing the Child Process . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 33
4.9 Debugging Multiple Inferiors and Programs . . . . . . . . . . . . . . . . . . . . 33
4.10 Debugging Programs with Multiple Threads . . . . . . . . . . . . . . . . . . 36
4.11 Debugging Forks . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 40
4.12 Setting a Bookmark to Return to Later . . . . . . . . . . . . . . . . . . . . . . . 43
4.12.1 A Non-obvious Benefit of Using Checkpoints . . . . . . . . . . . . . 44
5 Stopping and Continuing . . . . . . . . . . . . . . . . . . . . . . 45
5.1 Breakpoints, Watchpoints, and Catchpoints . . . . . . . . . . . . . . . . . . . . 45
5.1.1 Setting Breakpoints. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 46
5.1.2 Setting Watchpoints . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 52
5.1.3 Setting Catchpoints. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 54

ii Debugging with gdb
5.1.4 Deleting Breakpoints . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 59
5.1.5 Disabling Breakpoints . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 60
5.1.6 Break Conditions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 61
5.1.7 Breakpoint Command Lists . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 62
5.1.8 Dynamic Printf . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 64
5.1.9 How to save breakpoints to a file . . . . . . . . . . . . . . . . . . . . . . . . . . 65
5.1.10 Static Probe Points . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 65
5.1.11 “Cannot insert breakpoints” . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 67
5.1.12 “Breakpoint address adjusted...” . . . . . . . . . . . . . . . . . . . . . . . . . 67
5.2 Continuing and Stepping . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 68
5.3 Skipping Over Functions and Files . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 71
5.4 Signals . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 74
5.5 Stopping and Starting Multi-thread Programs. . . . . . . . . . . . . . . . . . 77
5.5.1 All-Stop Mode. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 78
5.5.2 Non-Stop Mode. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 79
5.5.3 Background Execution . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 80
5.5.4 Thread-Specific Breakpoints . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 81
5.5.5 Interrupted System Calls . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 81
5.5.6 Observer Mode . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 82
6 Running programs backward . . . . . . . . . . . . . . . . . . 85
7 Recording Inferior’s Execution
and Replaying It . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 87
8 Examining the Stack . . . . . . . . . . . . . . . . . . . . . . . . . . . 95
8.1 Stack Frames . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 95
8.2 Backtraces . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 96
8.3 Selecting a Frame . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 98
8.4 Information About a Frame. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 99
8.5 Management of Frame Filters. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 100
9 Examining Source Files . . . . . . . . . . . . . . . . . . . . . . 103
9.1 Printing Source Lines. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 103
9.2 Specifying a Location. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 104
9.2.1 Linespec Locations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 104
9.2.2 Explicit Locations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 105
9.2.3 Address Locations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 106
9.3 Editing Source Files . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 106
9.3.1 Choosing your Editor . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 107
9.4 Searching Source Files . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 107
9.5 Specifying Source Directories . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 107
9.6 Source and Machine Code . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 110
剩余810页未读,继续阅读












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

评论0