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

Debugging with gdb
The gnu Source-Level Debugger
Ninth Edition, for gdb version 6.0
Richard Stallman, Roland Pesch, Stan Shebs, et al.

(Send bugs and comments on gdb to bug-gdb@gnu.org.)
Debugging with gdb
T
E
Xinfo 2003-02-03.16
Copyright
c
1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1998, 1999, 2000, 2001,
2002, 2003 Free Software Foundation, Inc.
Published by the Free Software Foundation
59 Temple Place - Suite 330,
Boston, MA 02111-1307 USA
ISBN 1-882114-77-9
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 w ith the Back-Cover Texts as in (a) below.
(a) The Free Software Foundation’s Back-Cover Text is: “You have freedom to copy and
modify this GNU Manual, like GNU software. Copies published by the Free Software
Foundation raise funds for GNU development.”

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 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11
2.1.2 Choosing modes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13
2.2 Quitting gd b . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15
2.3 Shell c ommands . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15
2.4 Logging output . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16
3 gdb Commands . . . . . . . . . . . . . . . . . . . . . . . . . . . 17
3.1 Command syntax . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17
3.2 Command completion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17
3.3 Getting help . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19
4 Running Programs Under gdb . . . . . . . . . . . . . 23
4.1 Compiling for debugging . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23
4.2 Starting your program . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24
4.3 Your program’s arguments . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25
4.4 Your program’s environment . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25
4.5 Your program’s working directory . . . . . . . . . . . . . . . . . . . . . . . 26
4.6 Your program’s input and output . . . . . . . . . . . . . . . . . . . . . . . . 26
4.7 Debugging an already-running process . . . . . . . . . . . . . . . . . . . 27
4.8 Killing the child process . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 28
4.9 Debugging programs with multiple threads . . . . . . . . . . . . . . . 28
4.10 Debugging programs with multiple processes . . . . . . . . . . . . 30
5 Stopping and Continuing . . . . . . . . . . . . . . . . . . 33
5.1 Breakpoints, watchpoints, and catchpoints . . . . . . . . . . . . . . . 33
5.1.1 Setting breakpoints . . . . . . . . . . . . . . . . . . . . . . . . . . . . 34
5.1.2 Setting watchpoints . . . . . . . . . . . . . . . . . . . . . . . . . . . . 36
5.1.3 Setting c atchpoints . . . . . . . . . . . . . . . . . . . . . . . . . . . . 38
5.1.4 Deleting breakpoints . . . . . . . . . . . . . . . . . . . . . . . . . . . 40
5.1.5 Disabling breakpoints . . . . . . . . . . . . . . . . . . . . . . . . . . 40
5.1.6 Break conditions. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 41
5.1.7 Breakpoint command lists . . . . . . . . . . . . . . . . . . . . . . 43

ii Debugging with gdb
5.1.8 Breakpoint menus . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 44
5.1.9 “Cannot insert breakpoints” . . . . . . . . . . . . . . . . . . . . 44
5.2 Continuing and stepping . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 45
5.3 Signals . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 48
5.4 Stopping and starting multi-thread programs . . . . . . . . . . . . . 50
6 Examining the Stack . . . . . . . . . . . . . . . . . . . . . . 53
6.1 Stack frames . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 53
6.2 Backtraces . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 54
6.3 Selecting a frame . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 55
6.4 Information about a frame . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 56
7 Examining Source Files . . . . . . . . . . . . . . . . . . . 59
7.1 Printing source lines . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 59
7.2 Editing source files . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 60
7.2.1 Choosing your editor. . . . . . . . . . . . . . . . . . . . . . . . . . . 61
7.3 Searching source files . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 61
7.4 Specifying source directories . . . . . . . . . . . . . . . . . . . . . . . . . . . . 61
7.5 Source and m achine code . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 62
8 Examining Data . . . . . . . . . . . . . . . . . . . . . . . . . . 65
8.1 Expressions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 65
8.2 Program variables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 66
8.3 Artificial arrays . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 67
8.4 Output formats . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 68
8.5 Examining mem ory. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 69
8.6 Automatic display. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 70
8.7 Print settings . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 72
8.8 Value history . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 76
8.9 Convenience variables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 77
8.10 Registers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 78
8.11 Floating point hardware . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 79
8.12 Vector Unit . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 80
8.13 Memory region attributes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 80
8.13.1 Attributes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 81
8.13.1.1 Memory Access Mode . . . . . . . . . . . . . . . . 81
8.13.1.2 Memory Access Size. . . . . . . . . . . . . . . . . . 81
8.13.1.3 Data C ache. . . . . . . . . . . . . . . . . . . . . . . . . . 81
8.14 Copy between memory and a file . . . . . . . . . . . . . . . . . . . . . . . 81
8.15 Character Sets . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 82
9 C Preprocessor Macros . . . . . . . . . . . . . . . . . . . 87

iii
10 Tracepoints . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 91
10.1 Commands to Set Tracepoints. . . . . . . . . . . . . . . . . . . . . . . . . . 91
10.1.1 Create and Delete Tracepoints . . . . . . . . . . . . . . . . . 91
10.1.2 Enable and Disable Tracepoints. . . . . . . . . . . . . . . . 92
10.1.3 Tracepoint Passcounts . . . . . . . . . . . . . . . . . . . . . . . . 92
10.1.4 Tracepoint Action Lists . . . . . . . . . . . . . . . . . . . . . . . 93
10.1.5 Listing Tracep oints . . . . . . . . . . . . . . . . . . . . . . . . . . . 94
10.1.6 Starting and Stopping Trace Experiment . . . . . . . 94
10.2 Using the collected data . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 95
10.2.1 tfind n . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 95
10.2.2 tdump . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 97
10.2.3 save-tracepoints filename . . . . . . . . . . . . . . . . . 98
10.3 Convenience Variables for Tracepoints . . . . . . . . . . . . . . . . . . 98
11 Debugging Programs That Use Overlays . . 99
11.1 How Overlays Work . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 99
11.2 Overlay Commands . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 100
11.3 Automatic Overlay Debugging . . . . . . . . . . . . . . . . . . . . . . . . 102
11.4 Overlay Sample Program . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 103
12 Using gdb with Different Languages . . . . . 105
12.1 Switching between source languages . . . . . . . . . . . . . . . . . . . 105
12.1.1 List of filename e xtensions and languages . . . . . . 105
12.1.2 Setting the working language . . . . . . . . . . . . . . . . . 106
12.1.3 Having gdb infer the source language . . . . . . . . . 106
12.2 Displaying the language . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 106
12.3 Type and range checking . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 107
12.3.1 An overview of type checking . . . . . . . . . . . . . . . . . 107
12.3.2 An overview of range checking . . . . . . . . . . . . . . . . 108
12.4 Supported languages . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 109
12.4.1 C and C++ . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 109
12.4.1.1 C and C++ operators . . . . . . . . . . . . . . . . 110
12.4.1.2 C and C++ constants . . . . . . . . . . . . . . . . 111
12.4.1.3 C++ expressions. . . . . . . . . . . . . . . . . . . . . 112
12.4.1.4 C and C++ defaults . . . . . . . . . . . . . . . . . 113
12.4.1.5 C and C++ type and range checks . . . . 113
12.4.1.6 gdb and C . . . . . . . . . . . . . . . . . . . . . . . . . 114
12.4.1.7 gdb features for C++ . . . . . . . . . . . . . . . . 114
12.4.2 Objective-C . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 115
12.4.2.1 Method Names in Commands . . . . . . . . 115
12.4.2.2 The Print Command With Objective-C
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 116
12.4.3 Modula-2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 116
12.4.3.1 Operators . . . . . . . . . . . . . . . . . . . . . . . . . . 116
12.4.3.2 Built-in functions and procedures . . . . 118
12.4.3.3 Constants . . . . . . . . . . . . . . . . . . . . . . . . . . 119
12.4.3.4 Modula-2 defaults. . . . . . . . . . . . . . . . . . . 119
剩余377页未读,继续阅读












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

评论3