GDB PDF
GDB PDF
Table of Contents
Summary of GDB . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1
Free software . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1
Contributors to GDB . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1
2.2
2.3
Invoking GDB . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
2.1.1 Choosing files . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
2.1.2 Choosing modes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
2.1.3 Redirecting WDB input and output to a file . . . . .
Quitting GDB . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Shell commands . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
11
11
13
15
15
16
GDB Commands . . . . . . . . . . . . . . . . . . . . . . . . . 17
3.1
3.2
3.3
5
6
6
6
6
6
7
7
7
8
Command syntax . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17
Command completion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17
Getting help . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19
23
23
24
25
26
26
27
28
28
31
ii
5.2
5.3
5.4
Stack frames . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Stacks Without frames . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Commands for Examining the Stack . . . . . . . . . . . . . . . . . . . . .
Backtraces . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Selecting a frame . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Information about a frame . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
51
51
52
52
53
54
33
33
37
38
39
40
41
42
43
44
46
48
Breakpoints. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
5.1.1 Setting breakpoints . . . . . . . . . . . . . . . . . . . . . . . . . . . .
5.1.2 Setting catchpoints . . . . . . . . . . . . . . . . . . . . . . . . . . . .
5.1.3 Deleting breakpoints . . . . . . . . . . . . . . . . . . . . . . . . . . .
5.1.4 Disabling breakpoints . . . . . . . . . . . . . . . . . . . . . . . . . .
5.1.5 Break conditions. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
5.1.6 Breakpoint command lists . . . . . . . . . . . . . . . . . . . . . .
5.1.7 Breakpoint menus . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
5.1.8 Cannot insert breakpoints . . . . . . . . . . . . . . . . . . . .
Continuing and stepping . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Signals . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Stopping and starting multi-thread programs . . . . . . . . . . . . .
57
58
59
59
Examining Data . . . . . . . . . . . . . . . . . . . . . . . . . . 63
8.1
8.2
8.3
8.4
8.5
8.6
8.7
8.8
8.9
8.10
8.11
8.12
Expressions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Program variables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Artificial arrays . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Output formats . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Examining memory. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Automatic display . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Print settings . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Value history . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Convenience variables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Registers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Printing Floating Point Values . . . . . . . . . . . . . . . . . . . . . . . . .
Floating point hardware . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
63
64
65
66
67
68
70
74
75
76
78
78
iii
9.2
9.3
9.4
79
79
80
80
80
81
81
82
83
83
84
85
86
87
88
88
88
89
90
90
91
10
11
Altering Execution . . . . . . . . . . . . . . . . . . . . . . 97
11.1
11.2
11.3
11.4
11.5
11.6
12
13
Assignment to variables. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 97
Continuing at a different address . . . . . . . . . . . . . . . . . . . . . . . 98
Giving your program a signal . . . . . . . . . . . . . . . . . . . . . . . . . . 99
Returning from a function . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 99
Calling program functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . 100
Patching programs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 100
iv
14
v
14.10.8.1 Stop when freeing unallocated or
deallocated blocks . . . . . . . . . . . . . . . . . . . . . . . 146
14.10.8.2 Stop when freeing a block if bad writes
occurred outside block boundary . . . . . . . . . . 146
14.10.8.3 Stop when a specified block address is
allocated or deallocated . . . . . . . . . . . . . . . . . . 147
14.10.8.4 Scramble previous memory contents at
malloc/free calls . . . . . . . . . . . . . . . . . . . . . . . . . 147
14.10.9 Comparison of Memory Debugging Commands in
Interactive Mode and Batch Mode . . . . . . . . . . . . . . . 147
14.10.10 Heap Profiling . . . . . . . . . . . . . . . . . . . . . . . . . . . . 150
14.10.10.1 Commands for heap profiling . . . . . . 150
14.10.10.2 info heap arena . . . . . . . . . . . . . . . . . 150
14.10.10.3 info heap arena [0 |1|2|..] blocks
stacks . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 150
14.10.10.4 info module ADDRESS . . . . . . . . . . . . . 151
14.10.10.5 info heap process . . . . . . . . . . . . . . . 151
14.10.10.6 Example for heap profiling. . . . . . . . . 151
14.10.11 Memory Checking Analysis for User Defined
Memory Management Routines . . . . . . . . . . . . . . . . . . 152
14.10.12 Commands to track the change in data segment
value . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 152
14.11 Thread Debugging Support . . . . . . . . . . . . . . . . . . . . . . . . . . 153
14.11.1 Support for Enabling and Disabling Specific
Threads . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 153
14.11.2 Backtrace Support for Thread Debugging . . . . 154
14.11.3 Advanced Thread Debugging Support . . . . . . . . 154
14.11.3.1 Pre-requisites for Advanced Thread
Debugging . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 155
14.11.3.2 Enabling and Disabling Advanced
Thread Debugging Features. . . . . . . . . . . . . . . 155
14.11.3.3 Commands to view information on
pthread primitives . . . . . . . . . . . . . . . . . . . . . . . 158
14.11.4 Debugging Threads Interactively After Attaching
to a Process . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 158
14.12 Debugging MPI Programs . . . . . . . . . . . . . . . . . . . . . . . . . . . 159
14.13 Debugging multiple processes ( programs with fork and
vfork calls) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 159
14.13.1 Ask mode for set follow-fork-mode . . . . . . . . 159
14.13.2 serial mode for set follow-fork-mode . . . . . . . 160
14.13.3 Support for showing unwind info. . . . . . . . . . . . . 160
14.13.4 Printing CFM and PFS registers. . . . . . . . . . . . . 161
14.14 Debugging Core Files. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 161
14.14.1 Generating core files with packcore
/unpackcore/getcore . . . . . . . . . . . . . . . . . . . . . . . . . . 161
14.14.2 Support for the dumpcore command . . . . . . . . . 162
14.14.2.1 Enhancements to the dumpcore
command . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 162
vi
vii
14.23.5 Support for steplast command for C and C++
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 178
14.24 Getting information from a non-debug executable . . . . . 179
14.25 Debugging optimized code . . . . . . . . . . . . . . . . . . . . . . . . . . . 180
14.25.1 Debugging Optimized Code at Various
Optimization Levels . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 182
14.25.1.1 +O0 and +O1 . . . . . . . . . . . . . . . . . . . . . . . 182
14.25.1.2 +O2/+O3/+O4/-ipo. . . . . . . . . . . . . . . . . 182
14.26 Visual Interface for WDB . . . . . . . . . . . . . . . . . . . . . . . . . . . . 183
14.26.1 Starting and stopping Visual Interface for WDB
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 184
14.26.2 Navigating the Visual Interface for WDB display
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 184
14.26.3 Specifying foreground and background colors . . 186
14.26.4 Using the X-window graphical interface . . . . . . 187
14.26.5 Using the TUI mode . . . . . . . . . . . . . . . . . . . . . . . . 187
14.26.6 Changing the size of the source or debugger pane
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 188
14.26.7 Using commands to browse through source files
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 188
14.26.8 Loading source files . . . . . . . . . . . . . . . . . . . . . . . . . 189
14.26.9 Editing source files . . . . . . . . . . . . . . . . . . . . . . . . . 189
14.26.10 Editing the command line and command-line
history . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 189
14.26.11 Saving the contents of a debugging session to a
file. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 189
14.27 Support for ddd. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 189
14.28 Support for XDB commands . . . . . . . . . . . . . . . . . . . . . . . . . 190
14.28.1 stop in/at dbx commands . . . . . . . . . . . . . . . . . . . 190
14.29 GNU GDB Logging Commands . . . . . . . . . . . . . . . . . . . . . . 190
14.30 Support for command line calls in a stripped executable
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 190
14.30.1 Support for command line calls in a stripped
executable on PA-RISC systems . . . . . . . . . . . . . . . . . 190
14.30.2 Additional support for command line calls in a
stripped executable . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 191
14.30.2.1 For 32-bit applications: . . . . . . . . . . . . . 191
14.30.2.2 For 64-bit applications . . . . . . . . . . . . . 191
14.30.3 Support for debugging stripped binaries . . . . . . 191
14.30.3.1 Printing of locals and globals in a
stripped module . . . . . . . . . . . . . . . . . . . . . . . . . 192
14.30.3.2 Backtrace on stripped frames . . . . . . . 192
14.30.3.3 Command line calls to non-stripped
library . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 192
14.30.3.4 Setting breakpoints in unstripped shared
library . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 192
14.31 Displaying the current block scope information . . . . . . . . 192
14.32 Linux support . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 192
viii
15
15.4
15.5
15.6
15.7
15.8
15.9
16
195
196
197
197
197
198
199
200
201
201
204
204
206
207
ix
16.8.3
16.8.4
16.8.5
16.8.6
16.8.7
16.8.8
16.8.9
16.8.10
17
232
233
234
235
236
238
238
240
18
C through D . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
F through K . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
L. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
M through P . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Q through S . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
T ..........................................
U through Z . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Symbols . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
245
245
245
247
247
248
249
User-defined commands . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
User-defined command hooks . . . . . . . . . . . . . . . . . . . . . . . . .
Command files . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Commands for controlled output . . . . . . . . . . . . . . . . . . . . . .
251
252
253
253
19
20
What is an annotation? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
The server prefix . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Values. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Frames . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Displays . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Annotation for GDB input . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Errors . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Information on breakpoints . . . . . . . . . . . . . . . . . . . . . . . . . . .
Invalidation notices. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Running the program . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Displaying source . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Annotations We Might Want in the Future . . . . . . . . . . . .
257
257
258
259
260
261
261
262
262
263
263
264
21
22
265
265
265
265
266
268
268
269
269
269
269
270
271
279
289
300
302
307
310
315
317
317
Index . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 333
Summary of GDB
Summary of GDB
The purpose of a debugger such as GDB is to allow you to see what is going on inside
another program while it executesor what another program was doing at the moment it
crashed.
GDB allows you to do the following:
Load the executable along with any required arguments.
Stop your program on specified blocks of code.
Examine your program when it has stopped running due to an error.
Change things in your program, so you can experiment with correcting the effects of
one bug and go on to learn about another.
You can use GDB to debug programs written in C, C++ and Fortran. For more information, refer to the Section 9.4 [Supported languages], page 83. For more information on
supported languages, refer to the Section 9.4.1 [C and C++], page 84.
GDB can be used to debug programs written in Fortran, although it may be necessary
to refer to some variables with a trailing underscore. See Section 9.4.2 [Fortran], page 90.
This version of the manual documents WDB, implemented on HP 9000 or HP Integrity
systems running Release 11.x of the HP-UX operating system. WDB can be used to debug
code generated by the HP ANSI C, HP ANSI aC++ and HP Fortran compilers as well as
the gnu C and C++ compilers. It does not support the debugging of Pascal, Modula-2 or
Chill programs.
Free software
GDB is free software, protected by the gnu General Public License (GPL). The GPL
gives you the freedom to copy or adapt a licensed programbut every person getting a
copy also gets with it the freedom to modify that copy (which means that they must get
access to the source code), and the freedom to distribute further copies. Typical software
companies use copyrights to limit your freedoms; the Free Software Foundation uses the
GPL to preserve these freedoms.
Fundamentally, the General Public License is a license which says that you have these
freedoms and that you cannot take these freedoms away from anyone else.
Contributors to GDB
Richard Stallman was the original author of GDB, and of many other gnu programs.
Many others have contributed to its development. This section attempts to credit major
contributors. One of the virtues of free software is that everyone is free to contribute to
it; with regret, we cannot actually acknowledge everyone here. The file ChangeLog in the
GDB distribution approximates a blow-by-blow account.
Changes much prior to version 2.0 are lost in the mists of time.
Plea: Additions to this section are particularly welcome. If you or your friends
(or enemies, to be evenhanded) have been unfairly omitted from this list, we
would like to add your names!
So that they may not regard their many labors as thankless, we particularly thank those
who shepherded GDB through major releases: Andrew Cagney (release 5.0); Jim Blandy
(release 4.18); Jason Molenda (release 4.17); Stan Shebs (release 4.14); Fred Fish (releases
4.16, 4.15, 4.13, 4.12, 4.11, 4.10, and 4.9); Stu Grossman and John Gilmore (releases 4.8,
4.7, 4.6, 4.5, and 4.4); John Gilmore (releases 4.3, 4.2, 4.1, 4.0, and 3.9); Jim Kingdon
(releases 3.5, 3.4, and 3.3); and Randy Smith (releases 3.2, 3.1, and 3.0).
Richard Stallman, assisted at various times by Peter TerMaat, Chris Hanson, and
Richard Mlynarik, handled releases through 2.8.
Michael Tiemann is the author of most of the gnu C++ support in GDB, with significant
additional contributions from Per Bothner. James Clark wrote the gnu C++ demangler.
Early work on C++ was by Peter TerMaat (who also did much general update work leading
to release 3.0).
GDB 4 uses the BFD subroutine library to examine multiple object-file formats; BFD
was a joint project of David V. Henkel-Wallace, Rich Pixley, Steve Chamberlain, and John
Gilmore.
David Johnson wrote the original COFF support; Pace Willison did the original support
for encapsulated COFF.
Brent Benson of Harris Computer Systems contributed DWARF 2 support.
Adam de Boor and Bradley Davis contributed the ISI Optimum V support. Per Bothner,
Noboyuki Hikichi, and Alessandro Forin contributed MIPS support. Jean-Daniel Fekete
contributed Sun 386i support. Chris Hanson improved the HP9000 support. Noboyuki
Hikichi and Tomoyuki Hasei contributed Sony/News OS 3 support. David Johnson contributed Encore Umax support. Jyrki Kuoppala contributed Altos 3068 support. Jeff
Law contributed HP PA and SOM support. Keith Packard contributed NS32K support.
Doug Rabson contributed Acorn Risc Machine support. Bob Rusk contributed Harris
Nighthawk CX-UX support. Chris Smith contributed Convex support (and Fortran debugging). Jonathan Stone contributed Pyramid support. Michael Tiemann contributed
SPARC support. Tim Tucker contributed support for the Gould NP1 and Gould Powernode. Pace Willison contributed Intel 386 support. Jay Vosburgh contributed Symmetry
support.
Andreas Schwab contributed M68K Linux support.
Rich Schaefer and Peter Schauer helped with support of SunOS shared libraries.
Jay Fenlason and Roland McGrath ensured that GDB and GAS agree about several
machine instruction sets.
Patrick Duval, Ted Goldstein, Vikram Koka and Glenn Engel helped develop remote
debugging. Intel Corporation, Wind River Systems, AMD, and ARM contributed remote
debugging modules for the i960, VxWorks, A29K UDI, and RDI targets, respectively.
Brian Fox is the author of the readline libraries providing command-line editing and
command history.
Andrew Beers of SUNY Buffalo wrote the language-switching code, the Modula-2 support, and contributed the Languages chapter of this manual.
Fred Fish wrote most of the support for Unix System Vr4. He also enhanced the
command-completion support to cover C++ overloaded symbols.
Summary of GDB
Hitachi America, Ltd. sponsored the support for H8/300, H8/500, and Super-H processors.
NEC sponsored the support for the v850, Vr4xxx, and Vr5xxx processors.
Mitsubishi sponsored the support for D10V, D30V, and M32R/D processors.
Toshiba sponsored the support for the TX39 Mips processor.
Matsushita sponsored the support for the MN10200 and MN10300 processors.
Fujitsu sponsored the support for SPARClite and FR30 processors.
Kung Hsu, Jeff Law, and Rick Sladkey added support for hardware watchpoints.
Michael Snyder added support for tracepoints.
Stu Grossman wrote gdbserver.
Jim Kingdon, Peter Schauer, Ian Taylor, and Stu Grossman made nearly innumerable
bug fixes and cleanups throughout GDB.
The following people at the Hewlett-Packard Company contributed support for the PARISC 2.0 architecture, HP-UX 10.20, 10.30, and 11.x (narrow mode), HPs implementation
of kernel threads, HPs aC++ compiler, and the terminal user interface: Ben Krepp, Richard
Title, John Bishop, Susan Macchia, Kathy Mann, Satish Pai, India Paul, Steve Rehrauer,
and Elena Zannoni. Kim Haase, Rosario de la Torre, Alex McKale, Michael Coulter, Carl
Burch, Bharath Chndramohan, Diwakar Nag, Muthuswami, Dennis Handly, Subash Babu,
and Aparna Gopalakrishnan provided HP-specific information in this manual.
Cygnus Solutions has sponsored GDB maintenance and much of its development since
1991. Cygnus engineers who have worked on GDB full time include Mark Alexander, Jim
Blandy, Per Bothner, Kevin Buettner, Edith Epstein, Chris Faylor, Fred Fish, Martin
Hunt, Jim Ingham, John Gilmore, Stu Grossman, Kung Hsu, Jim Kingdon, John Metzler,
Fernando Nasser, Geoffrey Noer, Dawn Perchik, Rich Pixley, Zdenek Radouch, Keith Seitz,
Stan Shebs, David Taylor, and Elena Zannoni. In addition, Dave Brolley, Ian Carmichael,
Steve Chamberlain, Nick Clifton, JT Conklin, Stan Cox, DJ Delorie, Ulrich Drepper, Frank
Eigler, Doug Evans, Sean Fagan, David Henkel-Wallace, Richard Henderson, Jeff Holcomb,
Jeff Law, Jim Lemke, Tom Lord, Bob Manson, Michael Meissner, Jason Merrill, Catherine
Moore, Drew Moseley, Ken Raeburn, Gavin Romig-Koch, Rob Savoye, Jamie Smith, Mike
Stump, Ian Taylor, Angela Thomas, Michael Tiemann, Tom Tromey, Ron Unrau, Jim
Wilson, and David Zuhn have made contributions both large and small.
//change your current directory to the location where the m4 ex//run the m4 application
foo
0000
define(bar,defn(foo))
bar
0000
changequote(<QUOTE>,<UNQUOTE>)
define(baz,defn(<QUOTE>foo<UNQUOTE>))
baz
C-d
m4: End of input: 0: fatal error: EOF in string
GDB reads only enough symbol data to know where to find the rest when needed; as a
result, the first prompt comes up very quickly.
We need to see how the m4 built-in changequote works. Having looked at the source,
we know the relevant subroutine is m4_changequote, so we set a breakpoint there with the
GDB break command.
To trigger the breakpoint, we call changequote. GDB suspends execution of m4, displaying
information about the context where it stops.
changequote(<QUOTE>,<UNQUOTE>)
Breakpoint 1, m4_changequote (argc=3, argv=0x33c70)
at builtin.c:879
879
if (bad_argc(TOKEN_DATA_TEXT(argv[0]),argc,1,3))
We step through a few more lines to see what happens. The first two times, we can use s;
the next two times we use n to avoid falling into the xstrdup subroutine.
(gdb) s
0x3b5c 532
if (rquote != def_rquote)
(gdb) s
0x3b80 535
lquote = (lq == nil || *lq == \0) ? \
def_lquote : xstrdup(lq);
(gdb) n
536
rquote = (rq == nil || *rq == \0) ? def_rquote\
: xstrdup(rq);
(gdb) n
538
len_lquote = strlen(rquote);
Let us step past the two lines that set len_lquote and len_rquote, and then examine
the values of those variables.
(gdb) n
539
len_rquote = strlen(lquote);
(gdb) n
540
}
(gdb) p len lquote
$3 = 9
(gdb) p len rquote
$4 = 7
Is that enough to fix the problem of using the new quotes with the m4 built-in defn? We can
allow m4 to continue executing with the c (continue) command, and then try the example
that caused trouble initially:
(gdb) c
Continuing.
define(baz,defn(<QUOTE>foo<UNQUOTE>))
baz
0000
Success! The new quotes now work just as well as the default ones. The problem seems to
have been just the two typos defining the wrong lengths. We allow m4 to exit by giving it
an EOF as input:
C-d
Program exited normally.
The message Program exited normally. is from GDB; it indicates m4 has finished executing. We can end our GDB session with the GDB quit command.
(gdb) quit
10
11
You can further control how GDB starts up by using command-line options. GDB itself
can remind you of the options available.
Type
gdb -help
to display all available options and briefly describe their use (gdb -h is a shorter equivalent).
All options and command line arguments you give are processed in sequential order. The
order makes a difference when the -x option is used.
12
Read symbol table from file file and use it as the executable file.
-core file
-c file
Use file file as a core dump to examine.
-c number
Connect to process ID number, as with the attach command (unless there is
a file in core-dump format named number, in which case -c specifies that file
as a core dump to read).
-command file
-x file
Execute GDB commands from file file.
page 253.
-directory directory
-d directory
Add directory to the path to search for source files.
-m
-mapped
Warning: this option depends on operating system facilities that are not supported on all systems.
If memory-mapped files are available on your system through the mmap system
call, you can use this option to have GDB write the symbols from your program
into a reusable file in the current directory. If the program you are debugging
is called /tmp/fred, the mapped symbol file is /tmp/fred.syms. Future
GDB debugging sessions notice the presence of this file, and can quickly map
in symbol information from it, rather than reading the symbol table from the
executable program.
13
The .syms file is specific to the host machine where GDB is run. It holds
an exact image of the internal GDB symbol table. It cannot be shared across
multiple host platforms.
-r
-readnow
Read each symbol files entire symbol table immediately, rather than the default,
which is to read it incrementally as it is needed. This makes startup slower,
but makes future operations faster.
You typically combine the -mapped and -readnow options in order to build a .syms
file that contains complete symbol information. (See Section 12.1 [Commands to specify
files], page 103, for information on .syms files.) A simple GDB invocation to do nothing
but build a .syms file for future use is:
gdb -batch -nx -mapped -readnow programname
-quiet
-silent
-q
-batch
Quiet. Do not print the introductory and copyright messages. These messages are also suppressed in batch mode.
Run in batch mode. Exit with status 0 after processing all the command files
specified with -x (and all commands from initialization files, if not inhibited
with -n). Exit with nonzero status if an error occurs in executing the GDB
commands in the command files.
Batch mode may be useful for running GDB as a filter, for example to download
and run a program on another computer; in order to make this more useful, the
message
Program exited normally.
(which is ordinarily issued whenever a program running under GDB control
terminates) is not issued when running in batch mode.
-nowindows
-nw
No windows. If GDB comes with a graphical user interface (GUI) built in,
then this option tells GDB to only use the command-line interface. If no GUI
is available, this option has no effect.
-windows
-w
14
-cd directory
Run GDB using directory as its working directory, instead of the current directory.
-dbx
-fullname
-f
gnu Emacs sets this option when it runs GDB as a subprocess. It tells GDB to
output the full file name and line number in a standard, recognizable fashion
each time a stack frame is displayed (which includes each time your program
stops). This recognizable format looks like two \032 characters, followed by
the file name, line number and character position separated by colons, and a
newline. The Emacs-to-GDB interface program uses the two \032 characters
as a signal to display the source code for the frame.
-epoch
The Epoch Emacs-GDB interface sets this option when it runs GDB as a subprocess. It tells GDB to modify its print routines so as to allow Epoch to
display values of expressions in a separate window.
-annotate level
This option sets the annotation level inside GDB. Its effect is identical to using
set annotate level (see Chapter 20 [Annotations], page 257). Annotation
level controls how much information does GDB print together with its prompt,
values of expressions, source lines, and other types of output. Level 0 is the
normal, level 1 is for use when GDB is run as a subprocess of gnu Emacs, level
2 is the maximum annotation suitable for programs that control GDB.
-async
Use the asynchronous event loop for the command-line interface. GDB processes all events, such as user keyboard input, via a special event loop. This
allows GDB to accept and process user commands in parallel with the debugged
process being run1 , so you dont need to wait for control to return to GDB before you type the next command. (Note: as of version 5.0, the target side of
the asynchronous operation is not yet in place, so -async does not work fully
yet.)
When the standard input is connected to a terminal device, GDB uses the
asynchronous event loop by default, unless disabled by the -noasync option.
GDB built with djgpp tools for MS-DOS/MS-Windows supports this mode of operation, but the event
loop is suspended when the debug target runs.
-noasync
15
-baud bps
-b bps
Set the line speed (baud rate or bits per second) of any serial interface used by
GDB for remote debugging.
-tty device
-t device
Run using device for your programs standard input and output.
-tui
Use a Terminal User Interface. For information, use your Web browser
to read the file tui.html, which is usually installed in the directory
/opt/langtools/wdb/doc on HP-UX systems. Do not use this option if you
run GDB from Emacs (see see Chapter 19 [Using GDB under gnu Emacs],
page 255).
-xdb
Run in XDB compatibility mode, allowing the use of certain XDB commands.
For information, see the file xdb_trans.html, which is usually installed in the
directory /opt/langtools/wdb/doc on HP-UX systems.
-interpreter interp
Use the interpreter interp for interface with the controlling program or device.
This option is meant to be set by programs which communicate with GDB
using it as a back end. For example, --interpreter=mi causes GDB to use
the gdbmi interface (see Chapter 21 [The gdb/mi Interface], page 265).
-write
Open the executable and core files for both reading and writing. This is equivalent to the set write on command inside GDB (see Section 11.6 [Patching],
page 100).
-statistics
This option causes GDB to print statistics about time and memory usage after
it completes each command and returns to the prompt.
-version
This option causes GDB to print its version number and no-warranty blurb,
and exit.
-pid
-inline
This option causes the debugger to start with the inline debugging on.
-src_no_g
This option is used to set the limited source level debugging without compiling.
16
17
3 GDB Commands
You can abbreviate a GDB command to the first few letters of the command name, if
that abbreviation is unambiguous; and you can repeat certain GDB commands by typing
just hRETi. You can also use the hTABi key to get GDB to fill out the rest of a word in a
command (or to show you the alternatives available, if there is more than one possibility).
18
You can either press hRETi at this point, to run the info breakpoints command, or
backspace and enter something else, if breakpoints does not look like the command you
expected. (If you were sure you wanted info breakpoints in the first place, you might as
well just type hRETi immediately after info bre, to exploit command abbreviations rather
than command completion.)
If there is more than one possibility for the next word when you press hTABi, GDB sounds
a bell. You can either supply more characters and try again, or just press hTABi a second
time; GDB displays all the possible completions for that word. For example, you might
want to set a breakpoint on a subroutine whose name begins with make_, but when you
type b make_hTABi GDB just sounds the bell. Typing hTABi again displays all the function
names in your program that begin with those characters, for example:
(gdb) b make_ hTABi
GDB sounds bell; press hTABi again, to see:
make_a_section_from_file
make_environ
make_abs_section
make_function_type
make_blockvector
make_pointer_type
make_cleanup
make_reference_type
make_command
make_symbol_completion_list
(gdb) b make_
After displaying the available possibilities, GDB copies your partial input (b make_ in the
example) so you can finish the command.
If you just want to see the list of alternatives in the first place, you can press M-? rather
than pressing hTABi twice. M-? means hMETAi ?. You can type this either by holding down
a key designated as the hMETAi shift on your keyboard (if there is one) while typing ?, or as
hESCi followed by ?.
Sometimes the string you need, while logically a word, may contain parentheses or
other characters that GDB normally excludes from its notion of a word. To permit word
completion to work in this situation, you may enclose words in (single quote marks) in
GDB commands.
The most likely situation where you might need this is in typing the name of a C++
function. This is because C++ allows function overloading (multiple definitions of the same
function, distinguished by argument type). For example, when you want to set a breakpoint
you may need to distinguish whether you mean the version of name that takes an int
parameter, name(int), or the version that takes a float parameter, name(float). To use
the word-completion facilities in this situation, type a single quote at the beginning of
the function name. This alerts GDB that it may need to consider more information than
usual when you press hTABi or M-? to request word completion:
(gdb) b bubble( M-?
bubble(double,double)
bubble(int,int)
(gdb) b bubble(
In some cases, GDB can tell that completing a name requires using quotes. When this
happens, GDB inserts the quote for you (while completing as much as it can) if you do not
type the quote in the first place:
(gdb) b bub hTABi
GDB alters your input line to the following, and rings a bell:
19
(gdb) b bubble(
In general, GDB can tell that a quote is needed (and inserts it) if you have not yet started
typing the argument list when you ask for completion on an overloaded symbol.
For more information about overloaded functions, see Section 9.4.1.3 [C++ expressions],
page 86. You can use the command set overload-resolution off to disable overload
resolution; see Section 9.4.1.7 [GDB features for C++], page 88.
You can use help (abbreviated h) with no arguments to display a short list of
named classes of commands:
(gdb) help
List of classes of commands:
aliases -- Aliases of other commands
breakpoints -- Making program stop at certain points
data -- Examining data
files -- Specifying and examining files
internals -- Maintenance commands
obscure -- Obscure features
running -- Running the program
stack -- Examining the stack
status -- Status inquiries
support -- Support facilities
tracepoints -- Tracing of program execution without
stopping the program
user-defined -- User-defined commands
Type "help" followed by a class name for a list of
commands in that class.
Type "help" followed by command name for full
documentation.
Command name abbreviations are allowed if unambiguous.
(gdb)
help class
Using one of the general help classes as an argument, you can get a list of the
individual commands in that class. For example, here is the help display for
the class status:
(gdb) help status
Status inquiries.
List of commands:
info -- Generic command for showing things
about the program being debugged
show -- Generic command for showing things
about the debugger
20
help command
With a command name as help argument, GDB displays a short paragraph on
how to use that command.
apropos args
The apropos args command searches through all of the GDB commands, and
their documentation, for the regular expression specified in args. It prints out
all matches found. For example:
apropos reload
results in:
set symbol-reloading -- Set dynamic symbol table reloading
multiple times in one run
show symbol-reloading -- Show dynamic symbol table reloading
multiple times in one run
complete args
The complete args command lists all the possible completions for the beginning of a command. Use args to specify the beginning of the command you
want completed. For example:
complete i
results in:
if
ignore
info
inspect
This command (abbreviated i) is for describing the state of your program. For
example, you can list the arguments given to your program with info args,
list the registers currently in use with info registers, or list the breakpoints
you have set with info breakpoints. You can get a complete list of the info
sub-commands with help info.
set
You can assign the result of an expression to an environment variable with set.
For example, you can set the GDB prompt to a $-sign with set prompt $.
show
In contrast to info, show is for describing the state of GDB itself. You can
change most of the things you can show, by using the related command set;
for example, you can control what number system is used for displays with set
radix, or simply inquire which is currently in use with show radix.
To display all the settable parameters and their current values, you can use
show with no arguments; you may also use info set. Both commands produce
the same display.
21
Here are three miscellaneous show subcommands, all of which are exceptional in lacking
corresponding set commands:
show version
Show what version of GDB is running. You should include this information in
GDB bug-reports. If multiple versions of GDB are in use at your site, you may
need to determine which version of GDB you are running; as GDB evolves, new
commands are introduced, and old ones may wither away. Also, many system
vendors ship variant versions of GDB, and there are variant versions of GDB
in gnu/Linux distributions as well. The version number is the same as the one
announced when you start GDB.
show copying
Display information about permission for copying GDB.
show warranty
Display the gnu NO WARRANTY statement, or a warranty, if your version
of GDB comes with one.
22
23
Use the run command to start your program under GDB. You must first specify the program name (except on VxWorks) with an argument to GDB (see
Chapter 2 [Getting In and Out of GDB], page 11), or by using the file or
exec-file command (see Section 12.1 [Commands to specify files], page 103).
Note:
If you are running your program in an execution environment that supports processes,
run creates an inferior process and makes that process run your program. (In environments
without processes, run jumps to the start of your program.)
The execution of a program is affected by the information it receives from the parent
process. You must provide GDB the information before starting the program. (You can
change the information after starting your program, but such changes only affect your
program the next time you start it.) The information that must be passed to GDB can be
categorized into four categories:
arguments.
Specify the arguments to give your program as the arguments of the run command. If a shell is available on your target, the shell is used to pass the arguments, so that you may use normal conventions (such as wildcard expansion
24
set args
25
Specify the arguments to be used the next time your program is run. If set
args has no arguments, run executes your program with no arguments. Once
you have run your program with arguments, using set args before the next
run is the only way to run it again without arguments.
show args Show the arguments to give your program when it is started.
26
27
GDB stops the process being attached for debugging. You can examine and modify an
attached process with the GDB commands that are available when you start processes
with run. You can insert breakpoints; you can step and continue; you can modify
storage. See Section 5.1 [Breakpoints in shared libraries], page 33. If you want the
process to continue running, you can use the continue command after attaching GDB
to the process.
detach
When you have finished debugging the attached process, you can use the detach
command to release it from GDB control. The process continues its execution
after being detached. After the detach command, that process and GDB become completely independent once more, and you are ready to attach another
process or start one with run. detach does not repeat if you press hRETi again
after executing the command.
28
If you exit GDB or use the run command while you have an attached process, you kill
that process. By default, GDB asks for confirmation if you try to do either of these things;
you can control whether or not you need to confirm by using the set confirm command
(see Section 17.6 [Optional warnings and messages], page 248).
NOTE: When GDB attaches to a running program you may get a message
saying "Attaching to process #nnnnn failed."
The most likely cause for this message is that you have attached to a process
that was started across an NFS mount. Versions of the HP-UX kernel before
11.x have a restriction that prevents a debugger from attaching to a process
started from an NFS mount, unless the mount was made non-interruptible
with the -nointr flag, see mount(1).
Kill the child process in which your program is running under GDB.
The kill command is useful if you wish to debug a core dump instead of a running
process. GDB ignores any core dump file while your program is running.
On some operating systems, a program cannot be executed outside GDB while you have
breakpoints set on it inside GDB. You can use the kill command in this situation to permit
running your program outside the debugger.
The kill command is also useful if you wish to recompile and relink your program,
since on many systems it is impossible to modify an executable file while it is running in a
process. In this case, when you next type run, GDB notices that the file has changed, and
reads the symbol table again (while trying to preserve your current breakpoint settings).
29
0x34e5 in sigpause ()
0x34e5 in sigpause ()
main (argc=1, argv=0x7ffffff8)
On HP-UX systems:
For debugging purposes, GDB associates its own thread numbera small integer assigned in thread-creation orderwith each thread in your program.
Whenever GDB detects a new thread in your program, it displays both GDBs thread
number and the target systems identification for the thread with a message in the form
[New systag ]. systag is a thread identifier whose form varies depending on the particular
system. For example, on HP-UX, you see
30
thread threadno
Make thread number threadno the current thread. The command argument
threadno is the internal GDB thread number, as shown in the first field of the
info threads display. GDB responds by displaying the system identifier of
the thread you selected, and its current stack frame summary:
(gdb) thread 2
[Switching to thread 2 (system thread 26594)]
0x34e5 in sigpause ()
As with the [New ...] message, the form of the text after Switching to
depends on your systems conventions for identifying threads.
31
32
parent
child
The new process is debugged after a fork. The parent process runs
unimpeded.
show follow-fork-mode
Display the current debugger response to a fork or vfork call.
If you ask to debug a child process and a vfork is followed by an exec, GDB executes
the new target up to the first breakpoint in the new target. If you have a breakpoint set on
main in your original program, the breakpoint will also be set on the child processs main.
When a child process is spawned by vfork, you cannot debug the child or parent until
an exec call completes.
If you issue a run command to GDB after an exec call executes, the new target restarts.
To restart the parent process, use the file command with the parent executable name as
its argument.
You can use the catch command to make GDB stop whenever a fork, vfork, or exec
call is made. See Section 5.1.2 [Setting catchpoints], page 37.
33
5.1 Breakpoints
A breakpoint makes your program stop whenever a certain point in the program is
reached. For each breakpoint, you can add conditions to control in finer detail whether
your program stops. You can set breakpoints with the break command and its variants.
(see Section 5.1.1 [Setting breakpoints], page 33) You can stop your program by line number,
function name or an address in the program.
You can arrange to have values from your program displayed automatically whenever
GDB stops at a breakpoint. See Section 8.6 [Automatic display], page 68.
In HP-UX, SunOS 4.x, SVR4, and Alpha OSF/1 configurations, you can set breakpoints
in shared libraries before the executable is run. See Section 14.20 [Stopping and starting in
shared libraries], page 170.
A catchpoint is another special breakpoint that stops your program when a certain kind
of event occurs, such as the throwing of a C++ exception or the loading of a library. As with
watchpoints, you use a different command to set a catchpoint (see Section 5.1.2 [Setting
catchpoints], page 37), but aside from that, you can manage a catchpoint like any other
breakpoint. (To stop when your program receives a signal, use the handle command; see
Section 5.3 [Signals], page 46.)
GDB assigns a number to each breakpoint, watchpoint, or catchpoint when you create
it; these numbers are successive integers starting with one. In many of the commands for
controlling various features of breakpoints you use the breakpoint number to say which
breakpoint you want to change. Each breakpoint may be enabled or disabled; if disabled,
it has no effect on your program until you enable it again.
Some GDB commands accept a range of breakpoints on which to operate. A breakpoint
range is either a single breakpoint number, like 5, or two such numbers, in increasing
order, separated by a hyphen, like 5-7. When a breakpoint range is given to a command,
all breakpoint in that range are operated on.
34
see Section 8.9 [Convenience variables], page 75, for a discussion of what you can do with
convenience variables.
You have several ways to say where the breakpoint should go.
break function
Set a breakpoint at entry to function function. When using source languages
that permit overloading of symbols, such as C++, function may refer to more
than one possible place to break. See Section 5.1.7 [Breakpoint menus], page 43,
for a discussion of that situation.
break +offset
break -offset
Set a breakpoint some number of lines forward or back from the position at
which execution stopped in the currently selected stack frame. (See Section 6.1
[Frames], page 51, for a description of stack frames.)
break linenum
Set a breakpoint at line linenum in the current source file. The current source
file is the last file whose source text was printed. The breakpoint will stop your
program just before it executes any of the code on that line.
break filename :linenum
Set a breakpoint at line linenum in source file filename.
break filename :function
Set a breakpoint at entry to function function found in file filename. Specifying
a file name as well as a function name is superfluous except when multiple files
contain similarly named functions.
break *address
Set a breakpoint at address address. You can use this to set breakpoints in
parts of your program which do not have debugging information or source files.
break
When called without any arguments, break sets a breakpoint at the next instruction to be executed in the selected stack frame (see Chapter 6 [Examining
the Stack], page 51). In any selected frame but the innermost, this makes your
program stop as soon as control returns to that frame. This is similar to the
effect of a finish command in the frame inside the selected frameexcept that
finish does not leave an active breakpoint. If you use break without an argument in the innermost frame, GDB stops the next time it reaches the current
location; this may be useful inside loops.
GDB normally ignores breakpoints when it resumes execution, until at least one
instruction has been executed. If it did not do this, you would be unable to proceed past a breakpoint without first disabling the breakpoint. This rule applies
whether or not the breakpoint already existed when your program stopped.
35
tbreak args
Set a breakpoint enabled only for one stop. args are the same as for the break
command, and the breakpoint is set in the same way, but the breakpoint is
automatically deleted after the first time your program stops there. See Section 5.1.4 [Disabling breakpoints], page 39.
xbreak args
Set breakpoint at procedure exit. Argument may be function name, or "*"
and an address. If a function is specified, execution breaks at end of code for
that function. If an address is specified, execution breaks at the end of the
function that contains the specified address. When no arguments are specified,
the current execution address of the selected stack frame is used by default.
This is useful for breaking on return to a stack frame.
hbreak args
Set a hardware-assisted breakpoint. args are the same as for the break command and the breakpoint is set in the same way, but the breakpoint requires
hardware support and some target hardware may not have this support. The
main purpose of this is EPROM/ROM code debugging, so you can set a breakpoint at an instruction without changing the instruction. This can be used
with the new trap-generation provided by SPARClite DSU and some x86-based
targets. These targets will generate traps when a program accesses some data
or instruction address that is assigned to the debug registers. However the
hardware breakpoint registers can take a limited number of breakpoints. For
example, on the DSU, only two data breakpoints can be set at a time, and GDB
will reject this command if more than two are used. Delete or disable unused
hardware breakpoints before setting new ones (see Section 5.1.4 [Disabling],
page 39). See Section 5.1.5 [Break conditions], page 40.
thbreak args
Set a hardware-assisted breakpoint enabled only for one stop. args are the
same as for the hbreak command and the breakpoint is set in the same way.
However, like the tbreak command, the breakpoint is automatically deleted
after the first time your program stops there. Also, like the hbreak command,
the breakpoint requires hardware support and some target hardware may not
have this support. See Section 5.1.4 [Disabling breakpoints], page 39. See also
Section 5.1.5 [Break conditions], page 40.
rbreak regex
Set breakpoints on all functions matching the regular expression regex. This
command sets an unconditional breakpoint on all matches, printing a list of all
breakpoints it set. Once these breakpoints are set, they are treated just like the
breakpoints set with the break command. You can delete them, disable them,
or make them conditional the same way as any other breakpoint.
The syntax of the regular expression is the standard one used with tools like
grep. Note that this is different from the syntax used by shells, so for instance
foo* matches all functions that include an fo followed by zero or more os. There
is an implicit .* leading and trailing the regular expression you supply, so to
match only functions that begin with foo, use ^foo.
36
What
If a breakpoint is conditional, info break shows the condition on the line following the affected breakpoint; breakpoint commands, if any, are listed after
that.
info break with a breakpoint number n as argument lists only that breakpoint. The convenience variable $_ and the default examining-address for the
x command are set to the address of the last breakpoint listed (see Section 8.5
[Examining memory], page 67).
info break displays a count of the number of times the breakpoint has been
hit. This is especially useful in conjunction with the ignore command. You
can ignore a large number of breakpoint hits, look at the breakpoint info to see
how many times the breakpoint was hit, and then run again, ignoring one less
than that number. This will get you quickly to the last hit of that breakpoint.
GDB allows you to set any number of breakpoints at the same place in your program.
There is nothing silly or meaningless about this. When the breakpoints are conditional,
this is even useful (see Section 5.1.5 [Break conditions], page 40).
GDB itself sometimes sets breakpoints in your program for special purposes, such as
proper handling of longjmp (in C programs). These internal breakpoints are assigned
negative numbers, starting with -1; info breakpoints does not display them.
You can see these breakpoints with the GDB maintenance command maint info
breakpoints.
maint info breakpoints
Using the same format as info breakpoints, display both the breakpoints
youve set explicitly, and those GDB is using for internal purposes. Internal
breakpoints are shown with negative breakpoint numbers. The type column
identifies what kind of breakpoint is shown:
37
breakpoint
Normal, explicitly set breakpoint.
watchpoint
Normal, explicitly set watchpoint.
longjmp
longjmp resume
Internal breakpoint at the target of a longjmp.
until
finish
shlib events
Shared library events.
catch
exec
fork
vfork
load
load libname
The dynamic loading of any shared library, or the loading of the
library libname. This is currently only available for HP-UX.
unload
unload libname
The unloading of any dynamically loaded shared library, or the
unloading of the library libname. This is currently only available
for HP-UX.
tcatch event
Set a catchpoint that is enabled only for one stop. The catchpoint is automatically deleted after the first time the event is caught.
Use the info break command to list the current catchpoints.
There are currently some limitations to C++ exception handling (catch throw and catch
catch) in GDB:
38
If you call a function interactively, GDB normally returns control to you when the
function has finished executing. If the call raises an exception, however, the call may
bypass the mechanism that returns control to you and cause your program either to
abort or to simply continue running until it hits a breakpoint, catches a signal that
GDB is listening for, or exits. This is the case even if you set a catchpoint for the
exception; catchpoints on exceptions are disabled within interactive calls.
You cannot raise an exception interactively.
You cannot install an exception handler interactively.
Sometimes catch is not the best way to debug exception handling: if you need to know
exactly where an exception is raised, it is better to stop before the exception handler is
called, since that way you can see the stack before any unwinding takes place. If you set
a breakpoint in an exception handler instead, it may not be easy to find out where the
exception was raised.
To stop just before an exception handler is called, you need some knowledge of the
implementation. In the case of gnu C++, exceptions are raised by calling a library function
named __raise_exception which has the following ANSI C interface:
/* addr is where the exception identifier is stored.
id is the exception identifier. */
void __raise_exception (void **addr, void *id);
To make the debugger catch all exceptions before any stack unwinding takes place, set a
breakpoint on __raise_exception (see Section 5.1 [Breakpoints; watchpoints; and exceptions], page 33).
With a conditional breakpoint (see Section 5.1.5 [Break conditions], page 40) that depends on the value of id, you can stop your program when a specific exception is raised.
You can use multiple conditional breakpoints to stop your program when any of a number
of exceptions are raised.
39
clear function
clear filename :function
Delete any breakpoints set at entry to the function function.
clear linenum
clear filename :linenum
Delete any breakpoints set at or within the code of the specified line.
delete [breakpoints] [range ...]
Delete the breakpoints, watchpoints, or catchpoints of the breakpoint ranges
specified as arguments. If no argument is specified, delete all breakpoints (GDB
asks confirmation, unless you have set confirm off). You can abbreviate this
command as d.
40
41
42
To remove all commands from a breakpoint, type commands and follow it immediately with end; that is, give no commands.
With no bnum argument, commands refers to the last breakpoint, watchpoint,
or catchpoint set (not to the breakpoint most recently encountered).
Pressing hRETi as a means of repeating the last GDB command is disabled within a
command-list.
You can use breakpoint commands to start your program up again. Simply use the
continue command, or step, or any other command that resumes execution.
Any other commands in the command list, after a command that resumes execution, are
ignored. This is because any time you resume execution (even with a simple next or step),
you may encounter another breakpointwhich could have its own command list, leading
to ambiguities about which list to execute.
If the first command you specify in a command list is silent, the usual message about
stopping at a breakpoint is not printed. This may be desirable for breakpoints that are
to print a specific message and then continue. If none of the remaining commands print
anything, you see no sign that the breakpoint was reached. silent is meaningful only at
the beginning of a breakpoint command list.
The commands echo, output, and printf allow you to print precisely controlled output,
and are often useful in silent breakpoints. See Section 18.4 [Commands for controlled
output], page 254.
For example, here is how you could use breakpoint commands to print the value of x at
entry to foo whenever x is positive.
break foo if x>0
commands
silent
printf "x is %d\n",x
cont
end
One application for breakpoint commands is to compensate for one bug so you can test
for another. Put a breakpoint just after the erroneous line of code, give it a condition
to detect the case in which something erroneous has been done, and give it commands to
assign correct values to any variables that need them. End with the continue command so
that your program does not stop, and start with the silent command so that no output
is produced. Here is an example:
break 403
commands
silent
set x = y + 4
cont
end
43
function name is overloaded, break function is not enough to tell GDB where you want
a breakpoint. If you realize this is a problem, you can use something like break function (types ) to specify which particular version of the function you want. Otherwise,
GDB offers you a menu of numbered choices for different possible breakpoints, and waits
for your selection with the prompt >. The first two options are always [0] cancel and
[1] all. Typing 1 sets a breakpoint at each definition of function, and typing 0 aborts
the break command without setting any new breakpoints.
For example, the following session excerpt shows an attempt to set a breakpoint at the
overloaded symbol String::after. We choose three particular definitions of that function
name:
(gdb) b String::after
[0] cancel
[1] all
[2] file:String.cc; line number:867
[3] file:String.cc; line number:860
[4] file:String.cc; line number:875
[5] file:String.cc; line number:853
[6] file:String.cc; line number:846
[7] file:String.cc; line number:735
> 2 4 6
Breakpoint 1 at 0xb26c: file String.cc, line 867.
Breakpoint 2 at 0xb344: file String.cc, line 875.
Breakpoint 3 at 0xafcc: file String.cc, line 846.
Multiple breakpoints were set.
Use the "delete" command to delete unwanted
breakpoints.
(gdb)
This message is printed when you attempt to resume the program, since only then GDB
knows exactly how many hardware breakpoints and watchpoints it needs to insert.
44
When this message is printed, you need to disable or remove some of the hardwareassisted breakpoints and watchpoints, and then continue.
Continue running your program until control reaches a different source line,
then stop it and return control to GDB. This command is abbreviated s.
Warning: If you use the step command while control is within
a function that was compiled without debugging information, execution proceeds until control reaches a function that does have
debugging information. Likewise, it will not step into a function
which is compiled without debugging information. To step through
functions without debugging information, use the stepi command,
described below.
The step command only stops at the first instruction of a source line. This
prevents the multiple stops that could otherwise occur in switch statements, for
45
loops, etc. step continues to stop if a function that has debugging information
is called within the line. In other words, step steps inside any functions called
within the line.
Also, the step command only enters a function if there is line number information for the function. Otherwise it acts like the next command. This avoids
problems when using cc -gl on MIPS machines. Previously, step entered subroutines if there was any debugging information about the routine.
step count
Continue running as in step, but do so count times. If a breakpoint is reached,
or a signal not related to stepping occurs before count steps, stepping stops
right away.
next [count ]
Continue to the next source line in the current (innermost) stack frame. This
is similar to step, but function calls that appear within the line of code are
executed without stopping. Execution stops when control reaches a different
line of code at the original stack level that was executing when you gave the
next command. This command is abbreviated n.
An argument count is a repeat count, as for step.
The next command only stops at the first instruction of a source line. This
prevents multiple stops that could otherwise occur in switch statements, for
loops, etc.
finish
Continue running until just after function in the selected stack frame returns.
Print the returned value (if any).
Contrast this with the return command (see Section 11.4 [Returning from a
function], page 99).
until
u
Continue running until a source line past the current line, in the current stack
frame, is reached. This command is used to avoid single stepping through a loop
more than once. It is like the next command, except that when until encounters a jump, it automatically continues execution until the program counter is
greater than the address of the jump.
This means that when you reach the end of a loop after single stepping though
it, until makes your program continue execution until it exits the loop. In contrast, a next command at the end of a loop simply steps back to the beginning
of the loop, which forces you to step through the next iteration.
until always stops your program if it attempts to exit the current stack frame.
until may produce somewhat counterintuitive results if the order of machine
code does not match the order of the source lines. For example, in the following
excerpt from a debugging session, the f (frame) command shows that execution
is stopped at line 206; yet when we use until, we get to line 195:
(gdb) f
#0 main (argc=4, argv=0xf7fffae8) at m4.c:206
206
expand_input();
46
(gdb) until
195
This happened because, for execution efficiency, the compiler had generated
code for the loop closure test at the end, rather than the start, of the loop
even though the test in a C for-loop is written before the body of the loop.
The until command appeared to step back to the beginning of the loop when
it advanced to this expression; however, it has not really gone to an earlier
statementnot in terms of the actual machine code.
until with no argument works by means of single instruction stepping, and
hence is slower than until with an argument.
until location
u location
Continue running your program until either the specified location is reached,
or the current stack frame returns. location is any of the forms of argument
acceptable to break (see Section 5.1.1 [Setting breakpoints], page 33). This form
of the command uses breakpoints, and hence is quicker than until without an
argument.
stepi
stepi arg
si
Execute one machine instruction, then stop and return to the debugger.
It is often useful to do display/i $pc when stepping by machine instructions.
This makes GDB automatically display the next instruction to be executed,
each time your program stops. See Section 8.6 [Automatic display], page 68.
An argument is a repeat count, as in step.
nexti
nexti arg
ni
Execute one machine instruction, but if it is a function call, proceed until the
function returns.
An argument is a repeat count, as in next.
5.3 Signals
A signal is an asynchronous event that can happen in a program. The operating system
defines the possible kinds of signals, and gives each kind a name and a number. For example,
in Unix SIGINT is the signal a program gets when you type an interrupt character (often Cc); SIGSEGV is the signal a program gets from referencing a place in memory far away from
all the areas in use; SIGALRM occurs when the alarm clock timer goes off (which happens
only if your program has requested an alarm).
Some signals, including SIGALRM, are a normal part of the functioning of your program.
Others, such as SIGSEGV, indicate errors; these signals are fatal (they kill your program
immediately) if the program has not specified in advance some other way to handle the
signal. SIGINT does not indicate an error in your program, but it is normally fatal so it can
carry out the purpose of the interrupt: to kill the program.
47
GDB has the ability to detect any occurrence of a signal in your program. You can tell
GDB in advance what to do for each kind of signal.
Normally, GDB is set up to ignore non-erroneous signals like SIGALRM (so as not to
interfere with their role in the functioning of your program) but to stop your program
immediately whenever an error signal happens. You can change these settings with the
handle command.
Note: Use caution if you disable all signals from certain processes. Disabling
SIGTRAP in your program may cause your program to hang.
HP-UX uses SIGTRAP to communicate with the debugger. If you disable all
signals from certain processes so that signals will be delivered to the right
process, your program may hang when you try to debug it. This behavior occurs
because if you disable SIGTRAP, the debugger no longer receives notification
of events such as breakpoint hits and loading or unloading of shared libraries.
To prevent this problem:
Make certain you set this flag:
(gdb) set complain-if-sigtrap-disabled on
Also make certain the following warning was not emitted by the debugger before
your program hung:
Warning: Thread %d (in process %d) has disabled SIGTRAPs.
Debugging this thread is probably impossible.
If you do not want to see this message again, use:
"set complain-if-sigtrap-disabled 0"
info signals
info handle
Print a table of all the kinds of signals and how GDB has been told to handle
each one. You can use this to see the signal numbers of all the defined types of
signals.
info handle is an alias for info signals.
handle signal keywords ...
Change the way GDB handles signal signal. signal can be the number of a
signal or its name (with or without the SIG at the beginning). The keywords
say what change to make.
The keywords allowed by the handle command can be abbreviated. Their full names
are:
nostop
GDB should not stop your program when this signal happens. It may still print
a message telling you that the signal has come in.
stop
GDB should stop your program when this signal happens. This implies the
print keyword as well.
noprint
GDB should not mention the occurrence of the signal at all. This implies the
nostop keyword as well.
48
pass
GDB should allow your program to see this signal; your program can handle
the signal, or else it may terminate if the signal is fatal and not handled.
nopass
When a signal stops your program, the signal is not visible to the program until you
continue. Your program sees the signal then, if pass is in effect for the signal in question
at that time. In other words, after GDB reports a signal, you can use the handle command
with pass or nopass to control whether your program sees that signal when you continue.
You can also use the signal command to prevent your program from seeing a signal, or
cause it to see a signal it normally would not see, or to give it any signal at any time. For
example, if your program stopped due to some sort of memory reference error, you might
store correct values into the erroneous variables and continue, hoping to see more execution;
but your program would probably terminate immediately as a result of the fatal signal once
it saw the signal. To prevent this, you can continue with signal 0. See Section 11.3
[Giving your program a signal], page 99.
Whenever your program stops under GDB for any reason, all threads of execution stop,
not just the current thread. This allows you to examine the overall state of the program,
including switching between threads, without worrying that things may change underfoot.
Conversely, whenever you restart the program, all threads start executing. This is true
even when single-stepping with commands like step or next.
In particular, GDB cannot single-step all threads in lockstep. Since thread scheduling
is up to your debugging targets operating system (not controlled by GDB), other threads
may execute more than one statement while the current thread completes a single step.
Moreover, in general other threads stop in the middle of a statement, rather than at a clean
statement boundary, when the program stops.
49
You might even find your program stopped in another thread after continuing or even
single-stepping. This happens whenever some other thread runs into a breakpoint, a signal,
or an exception before the first thread completes whatever you requested.
On some OSes, you can lock the OS scheduler and thus allow only a single thread to
run.
set scheduler-locking mode
Set the scheduler locking mode. If it is off, then there is no locking and any
thread may run at any time. If on, then only the current thread may run
when the inferior is resumed. The step mode optimizes for single-stepping.
It stops other threads from seizing the prompt by preempting the current
thread while you are stepping. Other threads will only rarely (or never) get a
chance to run when you step. They are more likely to run when you next over
a function call, and they are completely free to run when you use commands
like continue, until, or finish. However, unless another thread hits a
breakpoint during its timeslice, they will never steal the GDB prompt away
from the thread that you are debugging.
show scheduler-locking
Display the current scheduler locking mode.
50
51
52
-fomit-frame-pointer
generates functions without a frame.) This is occasionally done with heavily used library functions to save the frame setup time. GDB has limited facilities for dealing with
these function invocations. If the innermost function invocation has no stack frame, GDB
nevertheless regards it as though it had a separate frame, which is numbered zero as usual,
allowing correct tracing of the function call chain. However, GDB has no provision for
frameless functions elsewhere in the stack.
6.4 Backtraces
A backtrace is a report of the active stack frames instantiated by the execution of a
program. It shows one line per frame, for all the active frames, starting with the currently
executing frame (frame zero), followed by its caller (frame one), and on up the stack.
The following commands are used for backtrace:
backtrace
bt
Print a backtrace of the entire stack: one line per frame for all frames in the
stack.
You can stop the backtrace at any time by typing the system interrupt character, normally C-c.
backtrace n
bt n
Similar, but print only the innermost n frames.
backtrace -n
bt -n
Similar, but print only the outermost n frames.
backtrace-other-thread
Print backtrace of all stack frames for a thread with stack pointer SP and
program counter PC. This command is useful in cases where the debugger does
not support a user thread package fully.
The names where and info stack (abbreviated info s) are additional aliases for
backtrace.
53
Each line in the backtrace shows the frame number and the function name. The program
counter value is also shownunless you use set print address off. The backtrace also
shows the source file name and line number, as well as the arguments to the function. The
program counter value is omitted if it is at the beginning of the code for that line number.
Here is an example of a backtrace. It was made with the command bt 3, so it shows
the innermost three frames.
#0
The display for frame zero does not begin with a program counter value, indicating that
your program has stopped at the beginning of the code for line 993 of builtin.c.
Select frame number n. Recall that frame zero is the innermost (currently
executing) frame, frame one is the frame that called the innermost one, and so
on. The highest-numbered frame is the one for main.
frame addr
f addr
Select the frame at address addr. This is useful mainly if the chaining of stack
frames has been damaged by a bug, making it impossible for GDB to assign
numbers properly to all frames. In addition, this can be useful when your
program has multiple stacks and switches between them.
Note:
On the SPARC architecture, frame needs two addresses to select an arbitrary frame: a frame pointer and a stack pointer.
On the MIPS and Alpha architecture, it needs two addresses: a stack
pointer and a program counter.
On the 29k architecture, it needs three addresses: a register stack pointer,
a program counter, and a memory stack pointer.
up n
Move n frames up the stack. For positive numbers n, this advances toward the
outermost frame, to higher frame numbers, to frames that have existed longer.
n defaults to one.
down n
Move n frames down the stack. For positive numbers n, this advances toward
the innermost frame, to lower frame numbers, to frames that were created more
recently. n defaults to one. You may abbreviate down as do.
54
All of these commands end by printing two lines of output describing the frame. The
first line shows the frame number, the function name, the arguments, and the source file
and line number of execution in that frame. The second line shows the text of that source
line.
For example:
(gdb) up
#1 0x22f0 in main (argc=1, argv=0xf7fffbf4, env=0xf7fffbfc)
at env.c:10
10
read_input_file (argv[i]);
After such a printout, the list command with no arguments prints ten lines centered
on the point of execution in the frame. See Section 7.1 [Printing source lines], page 57.
up-silently n
down-silently n
These two commands are variants of up and down, respectively; they differ
in that they do their work silently, without causing display of the new frame.
They are intended primarily for use in GDB command scripts, where the output
might be unnecessary and distracting.
When used without any argument, this command does not change which frame
is selected, but prints a brief description of the currently selected stack frame.
It can be abbreviated f. With an argument, this command is used to select a
stack frame. See Section 6.5 [Selecting a frame], page 53.
info frame
info f
This command prints a verbose description of the selected stack frame, including:
the address of the frame
the address of the next frame down (called by this frame)
the address of the next frame up (caller of this frame)
the language in which the source code corresponding to this frame is written
the address of the frames arguments
the address of the frames local variables
the program counter saved in it (the address of execution in the caller
frame)
which registers were saved in the frame
The verbose description is useful when something has gone wrong that has made
the stack format fail to fit the usual conventions.
info frame addr
info f addr
Print a verbose description of the frame at address addr, without selecting that
frame. The selected frame remains unchanged by this command. This requires
55
the same kind of address (more than one for some architectures) that you specify
in the frame command. See Section 6.5 [Selecting a frame], page 53.
info args Print the arguments of the selected frame, each on a separate line.
info locals
Print the local variables of the selected frame, each on a separate line. These
are all variables (declared either static or automatic) accessible at the point of
execution of the selected frame.
info catch
Print a list of all the exception handlers that are active in the current stack
frame at the current point of execution. To see other exception handlers, visit
the associated frame (using the up, down, or frame commands); then type info
catch. See Section 5.1.2 [Setting catchpoints], page 37.
56
57
Prints more lines. The list command prints lines following the lines printed
by a previously executed list command. If the command prior to executing
a list just printed the stack frame, then the list command only prints the
lines around that line.
list -
By default, GDB prints ten source lines with any of these forms of the list command.
The number of lines printed by GDB can be set by the set listsize command. The
following two forms are supported:
set listsize count
Makes the list command display count source lines (unless the list argument
explicitly specifies some other number).
show listsize
Displays the number of lines that list prints.
Repeating a list command with hRETi discards the argument, so it is equivalent to
typing just list. This is more useful than listing the same lines again. An exception is
made for an argument of -; that argument is preserved in repetition so that each repetition
moves up in the source file.
In general, the list command expects you to supply zero, one or two linespecs.
Linespecs specify source lines. There are several ways of writing them, but the most
common way is to specify some source line.
The following arguments can be given to the list command:
58
list linespec
Print lines centered around the line specified by linespec.
list first,last
Print lines from first to last. Both arguments must be linespecs.
list ,last
Print lines ending with last.
list first,
Print lines starting with first.
list +
list -
list
Specifies line number of the current source file. When a list command has
two linespecs, this refers to the same source file as the first linespec.
+offset
Specifies the line offset lines after the last line printed. When used as the second
linespec in a list command that has two, this specifies the line offset lines down
from the first linespec.
-offset
Specifies the line offset lines before the last line printed.
filename :number
Specifies line number in the source file filename.
function
Specifies the line that begins the body of the function function. For example:
in C, this is the line with the open brace.
filename :function
Specifies the line of the open-brace that begins the body of the function function
in the file filename. You only need the file name with a function name to avoid
ambiguity when there are identically named functions in different source files.
*address
Specifies the line containing the program address address. address may be any
expression.
59
reverse-search regexp
The command reverse-search regexp checks each line, starting with the
one before the last line listed and going backward, for a match for the regexp.
It lists the line(s) that is found. You can abbreviate this command as rev.
60
We can also inquire (using *addr as the form for linespec) what source line covers a particular address. For example,
(gdb) info line *0x63ff
Line 926 of "builtin.c" starts at pc 0x63e4 and ends at 0x6404.
After info line, the default address for the x command is changed to the starting
address of the line, so that x/i is sufficient to begin examining the machine code (see
Section 8.5 [Examining memory], page 67). Also, this address is saved as the value of the
convenience variable $_ (see Section 8.9 [Convenience variables], page 75).
disassemble
This specialized command dumps a range of memory as machine instructions.
The default memory range is the function surrounding the program counter of
the selected frame. A single argument to this command is a program counter
value; GDB dumps the function surrounding this value. Two arguments specify
a range of addresses (first inclusive, second exclusive) to dump.
The following example shows the disassembly of a range of addresses of HP PA-RISC
2.0 code:
(gdb) disas 0x32c4 0x32e4
Dump of assembler code from 0x32c4 to 0x32e4:
0x32c4 <main+204>:
addil 0,dp
0x32c8 <main+208>:
ldw 0x22c(sr0,r1),r26
0x32cc <main+212>:
ldil 0x3000,r31
0x32d0 <main+216>:
ble 0x3f8(sr4,r31)
0x32d4 <main+220>:
ldo 0(r31),rp
0x32d8 <main+224>:
addil -0x800,dp
0x32dc <main+228>:
ldo 0x588(r1),r26
0x32e0 <main+232>:
ldil 0x3000,r31
End of assembler dump.
61
Some architectures have more than one commonly-used set of instruction mnemonics or
other syntax.
set disassembly-flavor instruction-set
Select the instruction set to use when disassembling the program via the
disassemble or x/i commands.
Currently this command is only defined for the Intel x86 family. You can set
instruction-set to either intel or att. The default is att, the AT&T flavor
used by default by Unix assemblers for x86-based targets.
62
63
8 Examining Data
The usual way to examine data in your program is with the print command (abbreviated
p), or its synonym inspect. It evaluates and prints the value of an expression of the
language your program is written in (see Chapter 9 [Using GDB with Different Languages],
page 79).
The following forms of print command are supported:
print expr
print /f expr
expr is an expression (in the source language). By default the value of expr is
printed in a format appropriate to its data type; you can choose a different format by specifying /f , where f is a letter specifying the format; see Section 8.4
[Output formats], page 66.
print
print /f
If you omit expr, GDB displays the last value again (from the value history; see
Section 8.8 [Value history], page 74). This allows you to conveniently inspect
the same value in an alternative format.
A more low-level way of examining data is with the x command. It examines data in
memory at a specified address and prints it in a specified format. See Section 8.5 [Examining
memory], page 67.
If you are interested in information about types, or about how the fields of a struct
or a class are declared, use the ptype exp command rather than print. See Chapter 10
[Examining the Symbol Table], page 93.
8.1 Expressions
print and many other GDB commands accept an expression and compute its value. Any
kind of constant, variable or operator defined by the programming language you are using
is valid in an expression in GDB. This includes conditional expressions, function calls, casts
and string constants. It unfortunately does not include symbols defined by preprocessor
#define commands.
GDB supports array constants in expressions input by the user. The syntax is {element,
element. . . }. For example, you can use the command print {1, 2, 3} to build up an array
in memory that calls malloc in the target program.
Because C is so widespread, most of the expressions shown in examples in this manual
are in C. See Chapter 9 [Using GDB with Different Languages], page 79, for information
on how to use expressions in other languages.
In this section, we discuss operators that you can use in GDB expressions regardless of
your programming language.
Casts are supported in all languages, not just in C, because it is so useful to cast a
number into a pointer in order to examine a structure at that address in memory.
GDB supports these operators, in addition to those common to programming languages:
64
::
{type } addr
Refers to an object of type type stored at address addr in memory. addr may
be any expression whose value is an integer or pointer (but parentheses are
required around binary operators, just as in a cast). This construct is allowed
regardless of what kind of data is normally supposed to reside at addr.
65
(gdb) p f2.c::x
This use of :: is very rarely in conflict with the very similar use of the same notation
in C++. GDB also supports use of the C++ scope resolution operator in GDB expressions.
Warning: Occasionally, a local variable may appear to have the wrong value
at certain points in a function just after entry to a new scope, and just before
exit.
You may see this problem when you are stepping by machine instructions. This is
because, on most machines, it takes more than one instruction to set up a stack frame
(including local variable definitions); if you are stepping by machine instructions, variables
may appear to have the wrong values until the stack frame is completely built. On exit, it
usually also takes more than one machine instruction to destroy a stack frame; after you
begin stepping through that group of instructions, local variable definitions may be gone.
This may also happen when the compiler does significant optimizations. To be sure of
always seeing accurate values, turn off all optimization when compiling.
Another possible effect of compiler optimizations is to optimize unused variables out of
existence, or assign variables to registers (as opposed to memory addresses). Depending
on the support for such cases offered by the debug info format used by the compiler, GDB
might not be able to display values for such local variables. If that happens, GDB will print
a message like this:
No symbol "foo" in current context.
To solve such problems, either recompile without optimizations, or use a different debug
info format, if the compiler supports several such formats. For example, GCC, the gnu
C/C++ compiler usually supports the -gstabs option. The -gstabs produces debug
information in a format that is superior to formats such as COFF. You may be able to use
DWARF-2 (-gdwarf-2), which is also an effective form for debug info. See Section 4.1
[Compiling for Debugging], page 23.
66
used in expressions. Artificial arrays most often appear in expressions via the value history
(see Section 8.8 [Value history], page 74), after printing one out.
Another way to create an artificial array is to use a cast. This re-interprets a value as if
it were an array. The value need not be in memory:
(gdb) p/x (short[2])0x12345678
$1 = {0x1234, 0x5678}
As a convenience, if you leave the array length out (as in (type [])value ), GDB
calculates the size to fill the value (as sizeof(value )/sizeof(type ):
(gdb) p/x (short[])0x12345678
$2 = {0x1234, 0x5678}
Sometimes the artificial array mechanism is not quite enough; in moderately complex
data structures, the elements of interest may not actually be adjacentfor example, if you
are interested in the values of pointers in an array. One useful work-around in this situation
is to use a convenience variable (See (see Section 8.9 [Convenience variables], page 75))
as a counter in an expression that prints the first interesting value, and then repeat that
expression via hRETi. For instance, suppose you have an array dtab of pointers to structures,
and you are interested in the values of a field fv in each structure. Here is an example of
what you might type:
set $i = 0
p dtab[$i++]->fv
hRETi
hRETi
...
Regard the bits of the value as an integer, and print the integer in hexadecimal.
b cannot be used because these format letters are also used with the x command, where b stands for
byte; see Section 8.5 [Examining memory], page 67.
67
Regard the bits of the value as a floating point number and print using typical
floating point syntax.
For example, to print the program counter in hex (see Section 8.10 [Registers], page 77),
type
p/x $pc
Note that no space is required before the slash; this is because command names in GDB
cannot contain a slash.
To reprint the last value in the value history with a different format, you can use the
print command with just a format and no expression. For example, p/x reprints the last
value in hex.
Bytes.
68
Each time you specify a unit size with x, that size becomes the default unit the
next time you use x. (For the s and i formats, the unit size is ignored and
is normally not written.)
addr, starting display address
addr is the address where you want GDB to begin displaying memory. The expression need not have a pointer value (though it may); it is always interpreted
as an integer address of a byte of memory. Refer to See Section 8.1 [Expressions], page 63, for more information on expressions. The default for addr is
usually just after the last address examinedbut several other commands also
set the default address: info breakpoints (to the address of the last breakpoint listed), info line (to the starting address of a line), and print (if you
use it to display a value from memory).
For example, x/3uh 0x54320 is a request to display three halfwords (h) of memory,
formatted as unsigned decimal integers (u), starting at address 0x54320. x/4xw $sp
prints the four words (w) of memory above the stack pointer (here, $sp; see Section 8.10
[Registers], page 77) in hexadecimal (x).
Since the letters indicating unit sizes are all distinct from the letters specifying output
formats, you do not have to remember whether unit size or format comes first; either order
works. The output specifications 4xw and 4wx mean exactly the same thing. (However,
the count n must come first; wx4 does not work.)
Even though the unit size u is ignored for the formats s and i, you might still want to
use a count n; for example, 3i specifies that you want to see three machine instructions,
including any operands. The command disassemble gives an alternative way of inspecting
machine instructions; see Section 7.4 [Source and machine code], page 60.
All the defaults for the arguments to x are designed to make it easy to continue scanning
memory with minimal specifications each time you use x. For example, after you have
inspected three machine instructions with x/3i addr , you can inspect the next seven with
just x/7. If you use hRETi to repeat the x command, the repeat count n is used again; the
other arguments default as for successive uses of x.
The addresses and contents printed by the x command are not saved in the value history
because there is often too much of them and they would get in the way. Instead, GDB
makes these values available for subsequent use in expressions as values of the convenience
variables $_ and $__. After an x command, the last address examined is available for use
in expressions in the convenience variable $_. The contents of that address, as examined,
are available in the convenience variable $__.
If the x command has a repeat count, the address and contents saved are from the last
memory unit printed; this is not the same as the last address printed if several units were
printed on the last line of output.
69
value each time your program stops. Each expression added to the list is given a number to
identify it; to remove an expression from the list, you specify that number. The automatic
display looks like this:
2: foo = 38
3: bar[5] = (struct hack *) 0x3804
This display shows item numbers, expressions and their current values. As with displays
you request manually using x or print, you can specify the output format you prefer; in
fact, display decides whether to use print or x depending on how elaborate your format
specification isit uses x if you specify a unit size, or one of the two formats (i and s)
that are only supported by x; otherwise it uses print.
display expr
Add the expression expr to the list of expressions to display each time your
program stops. See Section 8.1 [Expressions], page 63.
display does not repeat if you press hRETi again after using it.
display/fmt expr
For fmt specifying only a display format and not a size or count, add the
expression expr to the auto-display list but arrange to display it each time in
the specified format fmt. See Section 8.4 [Output formats], page 66.
display/fmt addr
For fmt i or s, or including a unit-size or a number of units, add the expression addr as a memory address to be examined each time your program stops.
Examining means in effect doing x/fmt addr . See Section 8.5 [Examining
memory], page 67.
For example, display/i $pc can be helpful, to view the machine instruction about to
be executed each time execution stops ($pc is a common name for the program counter;
see Section 8.10 [Registers], page 77).
undisplay dnums ...
delete display dnums ...
Remove item numbers dnums from the list of expressions to display.
undisplay does not repeat if you press hRETi after using it. (Otherwise you
would just get the error No display number ....)
disable display dnums ...
Disable the display of item numbers dnums. A disabled display item is not
printed automatically, but is not forgotten. It may be enabled again later.
enable display dnums ...
Enable display of item numbers dnums. It becomes effective once again in auto
display of its expression, until you specify otherwise.
display
Display the current values of the expressions on the list, just as is done when
your program stops.
info display
Print the list of expressions previously set up to display automatically, each
one with its item number, but without showing the values. This includes disabled expressions, which are marked as such. It also includes expressions which
70
would not be displayed right now because they refer to automatic variables not
currently available.
If a display expression refers to local variables, then it does not make sense outside the
lexical context for which it was set up. Such an expression is disabled when execution enters
a context where one of its variables is not defined. For example, if you give the command
display last_char while inside a function with an argument last_char, GDB displays
this argument while your program continues to stop inside that function. When it stops
elsewhere, where there is no variable last_char, the display is disabled automatically. The
next time your program stops where last_char is meaningful, you can enable the display
expression again.
You can use set print address off to eliminate all machine dependent displays from the GDB interface. For example, with print address off, you
should get the same text for backtraces on all machineswhether or not they
involve pointer arguments.
show print address
Show whether or not addresses are to be printed.
When GDB prints a symbolic address, it normally prints the closest previous symbol
plus an offset. If that symbol does not uniquely identify the address (for example, it is a
name whose scope is a single source file), you may need to clarify it. One way to do this is
with info line. For example info line *0x4537. Alternately, you can set GDB to print
the source file and the line number when it prints a symbolic address:
71
72
73
74
gnu
hp
lucid
arm
Decode using the algorithm in the C++ Annotated Reference Manual. Warning: this setting alone is not sufficient to allow debugging cfront generated executables. GDB would require further
enhancement to permit that.
75
or discarded (for example with the file or symbol-file commands). When the symbol
table changes, the value history is discarded, since the values may contain pointers back to
the types defined in the symbol table.
The values printed are given history numbers by which you can refer to them. These
are a range of integers starting with one. print shows you the history number assigned to
a value by printing $num = before the value; here num is the history number.
To refer to any previous value, use $ followed by the history number of the value. The
way print labels its output is designed to remind you of this. Just $ refers to the most
recent value in the history, and $$ refers to the value before that. $$n refers to the nth
value from the end; $$2 is the value just prior to $$, $$1 is equivalent to $$, and $$0 is
equivalent to $.
For example, suppose you have just printed a pointer to a structure and want to see the
contents of the structure. It suffices to type
p *$
If you have a chain of structures where the component next points to the next one, you
can print the contents of the next one with this:
p *$.next
You can print successive links in the chain by repeating this command using the hRETi key.
Note that the history records values, not expressions. If the value of x is 4 and you type
these commands:
print x
set x=5
then the value recorded in the value history by the print command remains 4 even though
the value of x has changed.
show values
Print the last ten values in the value history, with their item numbers. This is
like p $$9 repeated ten times, except that show values does not change the
history.
show values n
Print ten history values centered on history item number n.
show values +
Print ten history values following the values last printed. If no more values are
available, show values + produces no display.
Pressing hRETi to repeat show values n has exactly the same effect as show values +.
76
Convenience variables are prefixed with $. Any name preceded by $ can be used for
a convenience variable, unless it is one of the predefined machine-specific register names
(see Section 8.10 [Registers], page 77). (Value history references, in contrast, are numbers
preceded by $. See Section 8.8 [Value history], page 74.)
You can save a value in a convenience variable with an assignment expression, just as
you would set a variable in your program. For example:
set $foo = *object_ptr
would save in $foo the value contained in the object pointed to by object_ptr.
Using a convenience variable for the first time creates it, but its value is void until you
assign a new value. You can alter the value with another assignment at any time.
Convenience variables have no fixed types. You can assign a convenience variable any
type of value, including structures and arrays, even if that variable already has a value of
a different type. The convenience variable, when used as an expression, has the type of its
current value.
show convenience
Print a list of convenience variables used so far, and their values. Abbreviated
show conv.
A convenient variable can be used as a counter to be incremented or a pointer to be
advanced. For example, to print a field from successive elements of an array of structures:
set $i = 0
print bar[$i++]->contents
Repeat that command by typing hRETi.
Some convenience variables are created automatically by GDB and assigned values.
$_
$__
The variable $__ is automatically set by the x command to the value found in
the last address examined. Its type is chosen to match the format in which the
data was printed.
$_exitcode
The variable $_exitcode is automatically set to the exit code when the program
being debugged terminates.
On HP-UX systems, if you refer to a function or variable name that begins with a dollar
sign, GDB searches for a user or system name first, before it searches for a convenience
variable.
77
8.10 Registers
You can refer to machine register contents, in expressions, as variables with names
starting with $. The names of registers are different for each machine. Use info registers
to view the names used on your machine.
info registers
Print the names and values of all registers except floating-point registers (in
the selected stack frame).
info all-registers
Print the names and values of all registers, including floating-point registers.
info registers regname ...
Print the relativized value of each specified register regname. As discussed in
detail below, register values are normally relative to the selected stack frame.
regname may be any register name valid on the machine you are using, with or
without the initial $.
GDB has four standard register names that are available (in expressions) on most
machineswhenever they do not conflict with an architectures canonical mnemonics for
registers. The register names $pc and $sp are used for the program counter register and
the stack pointer. $fp is used for a register that contains a pointer to the current stack
frame, and $ps is used for a register that contains the processor status. For example, you
could print the program counter in hex with
p/x $pc
or print the instruction to be executed next with
x/i $pc
or add four to the stack pointer2 with
set $sp += 4
Whenever possible, these four standard register names are available on your machine
even though the machine has different canonical mnemonics, so long as there is no conflict.
The info registers command shows the canonical names. For example, on the SPARC,
info registers displays the processor status register as $psr but you can also refer to it
as $ps; and on x86-based machines $ps is an alias for the eflags register.
GDB always considers the contents of an ordinary register as an integer when the register
is examined in this way. Some machines have special registers which can hold nothing but
floating point; these registers are considered to have floating point values. There is no way
to refer to the contents of an ordinary register as floating point value (although you can
print it as a floating point value with print/f $regname ).
Some registers have distinct raw and virtual data formats. This means that the data
format in which the register contents are saved by the operating system is not the same
one that your program normally sees. For example, the registers of the 68881 floating point
2
This is a way of removing one word from the stack, on machines where stacks grow downward in memory
(most machines, nowadays). This assumes that the innermost stack frame is selected; setting $sp is not
allowed when other stack frames are selected. To pop entire frames off the stack, regardless of machine
architecture, use return; see Section 11.4 [Returning from a function], page 99.
78
coprocessor are always saved in extended (raw) format, but all C programs expect to work
with double (virtual) format. In such cases, GDB normally works with the virtual format
only (the format that makes sense for your program), but the info registers command
prints the data in both formats.
Normally, register values are relative to the selected stack frame (see Section 6.5 [Selecting a frame], page 53). This means that you get the value that the register would contain
if all stack frames farther in were exited and their saved registers restored. In order to see
the true contents of hardware registers, you must select the innermost frame (with frame
0).
However, GDB must deduce where registers are saved, from the machine code generated
by your compiler. If some registers are not saved, or if GDB is unable to locate the saved
registers, the selected stack frame makes no difference.
79
C source file
.C
.cc
.cp
.cpp
.cxx
.c++
80
.f
.F
.f90
.s
.S
Fortran source file. GDB does not distinguish between Fortran 77 and Fortran
90 files.
Assembler source file. This actually behaves almost like C, but GDB does not
skip over function prologues when stepping.
In addition, you may set the language associated with a filename extension. See Section 9.2 [Displaying the language], page 80.
81
show language
Display the current working language. This is the language you can use with
commands such as print to build and compute expressions that may involve
variables in your program.
info frame
Display the source language for this frame. This language becomes the working
language if you use an identifier from this frame. See Section 6.6 [Information
about a frame], page 54, to identify the other information listed here.
info source
Display the source language of this source file. Refer to See Chapter 10 [Examining the Symbol Table], page 93, to identify the other information listed
here.
In unusual circumstances, you may have source files with extensions not in the standard
list. You can then set the extension associated with a language explicitly:
set extension-language .ext language
Set source files with extension .ext to be assumed to be in the source language
language. However, this is not valid on Unix systems.
info extensions
List all the filename extensions and the associated languages. Not valid on Unix
systems.
error
1 + 2.3
82
The second example fails because the CARDINAL 1 is not type-compatible with the REAL
2.3.
For the expressions you use in GDB commands, you can tell the GDB type checker to
skip checking; to treat any mismatches as errors and abandon the expression; or to only
issue warnings when type mismatches occur, and evaluate the expression anyway. When
you choose the last of these, GDB evaluates expressions like the second example above, but
also issues a warning.
Even if you turn type checking off, there may be other reasons related to type that
prevent GDB from evaluating an expression. For instance, GDB does not know how to
add an int and a struct foo. These particular type errors have nothing to do with the
language in use, and usually arise from expressions, such as the one described above, which
make little sense to evaluate anyway.
Each language defines to what degree it is strict about type. For instance C requires the
arguments to arithmetical operators to be numbers. In C, enumerated types and pointers
can be represented as numbers, so that they are valid arguments to mathematical operators.
See Section 9.4 [Supported languages], page 83, for further details on specific languages.
GDB provides some additional commands for controlling the type checker:
set check type auto
Set type checking on or off based on the current working language. See Section 9.4 [Supported languages], page 83, for the default settings for each language.
set check type on
set check type off
Set type checking on or off, overriding the default setting for the current working
language. Issue a warning if the setting does not match the language default.
If any type mismatches occur in evaluating an expression while type checking
is on, GDB prints a message and aborts evaluation of the expression.
set check type warn
Cause the type checker to issue warnings, but to always attempt to evaluate the
expression. Evaluating the expression may still be impossible for other reasons.
For example, GDB cannot add numbers and structures.
show type Show the current setting of the type checker, and whether or not GDB is setting
it automatically.
83
A range error can result from numerical overflow, from exceeding an array index bound,
or when you type a constant that is not a member of any type. Some languages, however,
do not treat overflows as an error. In many implementations of C, mathematical overflow
causes the result to wrap around to lower valuesfor example, if m is the largest integer
value, and s is the smallest, then
m + 1 s
This, too, is specific to individual languages, and in some cases specific to individual
compilers or machines. Refer to See Section 9.4 [Supported languages], page 83, for further
details on specific languages.
GDB provides the following additional commands for controlling the range checker:
set check range auto
Set range checking on or off based on the current working language. See Section 9.4 [Supported languages], page 83, for the default settings for each language.
set check range on
set check range off
Set range checking on or off, overriding the default setting for the current working language. A warning is issued if the setting does not match the default
language. If a range error occurs and range checking is on, then a message is
printed and evaluation of the expression is aborted.
set check range warn
Output messages when the GDB range checker detects a range error, but attempt to evaluate the expression anyway. Evaluating the expression may still
be impossible for other reasons, such as accessing memory that the process does
not own (a typical example from many Unix systems).
show range
Show the current setting of the range checker, and whether or not it is being
set automatically by GDB.
84
Assignment. The value of an assignment expression is the value assigned. Defined on scalar types.
op =
?:
||
&&
&
==, !=
85
Equality and inequality. Defined on scalar types. The value of these expressions
is 0 for false and non-zero for true.
The GDB artificial array operator (see Section 8.1 [Expressions], page 63).
+, -
*, /, %
++, --
&
., ->
.*, ->*
[]
()
::
C++ scope resolution operator. Defined on struct, union, and class types.
::
Double colons also represent the GDB scope operator (see Section 8.1 [Expressions], page 63). Same precedence as ::, above.
If an operator is redefined in the user code, GDB usually attempts to invoke the redefined
version instead of using the original meaning.
86
87
2. While a member function is active (in the selected stack frame), your expressions have
the same namespace available as the member function; that is, GDB allows implicit
references to the class instance pointer this following the same rules as C++.
3. You can call overloaded functions; GDB resolves the function call to the right definition,
with some restrictions. GDB does not perform overload resolution involving userdefined type conversions, calls to constructors, or instantiations of templates that do not
exist in the program. It also cannot handle ellipsis argument lists or default arguments.
It does perform integral conversions and promotions, floating-point promotions, arithmetic conversions, pointer conversions, conversions of class objects to base classes, and
standard conversions such as those of functions or arrays to pointers; it requires an
exact match on the number of function arguments.
Overload resolution is always performed, unless you have specified set overloadresolution off. See Section 9.4.1.7 [GDB features for C++], page 88.
You must specify set overload-resolution off in order to use an explicit function
signature to call an overloaded function, as in
p foo(char,int)(x, 13)
The GDB command-completion facility can simplify this. Refer to Section 3.2 [Command completion], page 17.
4. GDB understands variables declared as C++ references; you can use them in expressions
just as you do in C++ sourcethey are automatically dereferenced.
In the parameter list shown when GDB displays a frame, the values of reference variables are not displayed (unlike other variables); this avoids clutter, since references are
often used for large structures. The address of a reference variable is always shown,
unless you have specified set print address off.
5. GDB supports the C++ name resolution operator ::your expressions can use it just as
expressions in your program do. Since one scope may be defined in another, you can use
:: repeatedly if necessary, for example in an expression like scope1 ::scope2 ::name .
GDB also allows resolving name scope by reference to source files, in both C and C++
debugging (see Section 8.2 [Program variables], page 64).
In addition, when used with the HP aC++ compiler, GDB supports calling virtual functions correctly, printing out virtual bases of objects, calling functions in a base subobject,
casting objects, and invoking user-defined operators.
Note: GDB cannot display debugging information for classes or functions defined in a shared library that is not compiled for debugging (with the -g0
option). GDB displays the function with the message <no data fields>.
For example, after d3 is created by the following line:
RWCollectableDate d3(15,5,2001);
printing the variable or class returns:
(gdb) p d3
$3 = {<No data fields>}
(gdb) ptype RWCollectableDate
type = class RWCollectableDate {
<no data fields>
88
89
catch throw
catch catch
Debug C++ exception handling using these commands. See Section 5.1.2 [Setting catchpoints], page 37.
ptype typename
Print inheritance relationships as well as other information for type. typename.
See Chapter 10 [Examining the Symbol Table], page 93.
set print demangle
show print demangle
set print asm-demangle
show print asm-demangle
Control whether C++ symbols display in their source form, both when displaying
code as C++ source and when displaying disassemblies. See Section 8.7 [Print
settings], page 70.
set print object
show print object
Choose whether to print derived (actual) or declared types of objects. See
Section 8.7 [Print settings], page 70.
set print vtbl
show print vtbl
Control the format for printing virtual function tables. See Section 8.7 [Print
settings], page 70. (The vtbl commands do not work on programs compiled
with the HP ANSI C++ compiler (aCC).)
set overload-resolution on
Enable overload resolution for C++ expression evaluation. The default is on.
For overloaded functions, GDB evaluates the arguments and searches for a
function whose signature matches the argument types, using the standard C++
conversion rules (see Section 9.4.1.3 [C++ expressions], page 86, for details). If
it cannot find a match, it emits a message.
set overload-resolution off
Disable overload resolution for C++ expression evaluation. For overloaded functions that are not class member functions, GDB chooses the first function of
the specified name that it finds in the symbol table, whether or not its arguments are of the correct type. For overloaded functions that are class member
functions, GDB searches for a function whose signature exactly matches the
argument types.
show overload-resolution
Display current overload resolution setting for C++ expression evaluation.
Overloaded symbol names
You can specify a particular definition of an overloaded symbol, using the same
notation that is used to declare such symbols in C++: type symbol (types )
rather than just symbol. You can also use the GDB command-line word completion facilities to list the available choices, or to finish the type list for you.
See Section 3.2 [Command completion], page 17, for details on how to do this.
90
9.4.2 Fortran
You can use WDB to debug programs written in Fortran. WDB does not distinguish
between Fortran 77 and Fortran 90 files.
WDB provides the following command to control case sensitivity:
case-sensitive [on | off]
The default for Fortran is off, while for other languages the default is on.
Other supported features are:
Fortran 90 pointers
Structures and unions
Calling functions with integer, logical, real, complex arguments
Intrinsic support
Assignment
*, -, *, /
Binary operators
+, -
Unary operators
**
Exponentiation
.EQ., =
Equal
.NE., /=
.LT., <
Less than
.LE., <=
.GT., >
Greater than
.GE., >=
//
Concatenation
.NOT.
Logical negation
.AND.
Logical AND
.OR.
Logical OR
.EQV.
Logical equivalence
91
.NEQV., .XOR.
Logical non-equivalence
Logical constants are represented as .TRUE. or .FALSE.
GDB includes support for viewing Fortran common blocks.
info common
Lists common blocks visible in the current frame.
info common <common_block_name>
Lists values of variables in the named common block.
Fortran entry points are supported.
You can set a break point specifying an entry point name.
92
93
Print the data type of $, the last value in the value history.
ptype typename
Print a description of data type typename. typename may be the name of a
type, or for C code it may have the form class class-name , struct structtag , union union-tag or enum enum-tag .
ptype expr
ptype
Print a description of the type of expression expr. ptype differs from whatis
by printing a detailed description, instead of just the name of the type.
For example, for this variable declaration:
struct complex {double real; double imag;} v;
the two commands give this output:
94
(gdb) whatis v
type = struct complex
(gdb) ptype v
type = struct complex {
double real;
double imag;
}
As with whatis, using ptype without an argument refers to the type of $, the
last value in the value history.
info types regexp
info types
Print a brief description of all types whose names match regexp (or all types in
your program, if you supply no argument). Each complete typename is matched
as though it were a complete line; thus, i type value gives information on
all types in your program whose names include the string value, but i type
^value$ gives information only on types whose complete name is value.
This command differs from ptype in two ways: first, like whatis, it does not
print a detailed description; second, it lists all source files where a type is
defined.
info source
Show the name of the current source filethat is, the source file for the function
containing the current point of executionand the language it was written in.
info sources
Print the names of all source files in your program for which there is debugging
information, organized into two lists: files whose symbols have already been
read, and files whose symbols will be read when needed.
info functions
Print the names and data types of all defined functions.
info functions regexp
Print the names and data types of all defined functions whose names contain a
match for regular expression regexp. Thus, info fun step finds all functions
whose names include step; info fun ^step finds those whose names start
with step.
info variables
Print the names and data types of all variables that are declared outside of
functions (i.e., excluding local variables).
info variables regexp
Print the names and data types of all variables (except for local variables) whose
names contain a match for regular expression regexp.
Some systems allow individual object files that make up your program to be
replaced without stopping and restarting your program. For example, in VxWorks you can simply recompile a defective object file and keep on running.
If you are running on one of these systems, you can allow GDB to reload the
symbols for automatically relinked modules:
95
set symbol-reloading on
Replace symbol definitions for the corresponding source file when
an object file with a particular name is seen again.
set symbol-reloading off
Do not replace symbol definitions when encountering object files of
the same name more than once. This is the default state; if you
are not running on a system that permits automatic relinking of
modules, you should leave symbol-reloading off, since otherwise
GDB may discard symbols when linking large programs, that may
contain several modules (from different directories or libraries) with
the same name.
show symbol-reloading
Show the current on or off setting.
set opaque-type-resolution on
Tell GDB to resolve opaque types. An opaque type is a type declared as a
pointer to a struct, class, or unionfor example, struct MyType *that
is used in one source file although the full declaration of struct MyType is in
another source file. The default is on.
A change in the setting of this subcommand will not take effect until the next
time symbols for a file are loaded.
set opaque-type-resolution off
Tell GDB not to resolve opaque types. In this case, the type is printed as
follows:
{<no data fields>}
show opaque-type-resolution
Show whether opaque types are resolved or not.
maint print symbols filename
maint print psymbols filename
maint print msymbols filename
Write a dump of debugging symbol data into the file filename. These commands are used to debug the GDB symbol-reading code. Only symbols with
debugging data are included. If you use maint print symbols, GDB includes
all the symbols for which it has already collected full details: that is, filename
reflects symbols for only those files whose symbols GDB has read. You can
use the command info sources to find out which files these are. If you use
maint print psymbols instead, the dump shows information about symbols
that GDB only knows partiallythat is, symbols defined in files that GDB
has skimmed, but not yet read completely. Finally, maint print msymbols
dumps just the minimal symbol information required for each object file from
which GDB has read some symbols. See Section 12.1 [Commands to specify
files], page 103, for a discussion of how GDB reads symbols (in the description
of symbol-file).
96
97
11 Altering Execution
Once you think you have found an error in your program, you might want to find out
for certain whether correcting the apparent error would lead to correct results in the rest
of the run. You can find the answer by experiment, using the GDB features for altering
execution of the program.
For example, you can store new values into variables or memory locations, give your program a signal, restart it at a different address, or even return prematurely from a function.
98
(gdb) whatis g
type = double
(gdb) p g
$1 = 1
(gdb) set g=4
(gdb) p g
$2 = 1
(gdb) r
The program being debugged has been started already.
Start it from the beginning? (y or n) y
Starting program: /home/smith/cc_progs/a.out
"/home/smith/cc_progs/a.out": cant open to read symbols:
Invalid bfd target.
(gdb) show g
The current BFD target is "=4".
The steps shown above sets the gnutarget to an invalid value in place of the program
variable g.
In order to set the variable g, use
(gdb) set var g=4
GDB allows more implicit conversions in assignments than C; you can freely store an
integer value into a pointer variable or vice versa, and you can convert any structure to any
other structure that is the same length or shorter.
To store values into arbitrary places in memory, use the {...} construct to generate a
value of specified type at a specified address (see Section 8.1 [Expressions], page 63). For
example, {int}0x83040 refers to memory location 0x83040 as an integer (which implies a
certain size and representation in memory), and
set {int}0x83040 = 4
stores the value 4 into that memory location.
99
counter. If line linespec is in a different function from the one currently executing, the results may be bizarre if the two functions expect different patterns
of arguments or of local variables. For this reason, the jump command requests
confirmation if the specified line is not in the function currently executing.
However, even bizarre results are predictable if you are well acquainted with
the machine-language code of your program.
jump *address
Resume execution at the instruction at address address.
On many systems, you can get much the same effect as the jump command by storing a
new value into the register $pc. This does not start the execution of your program at the
specified address, instead only changes the program counter.
For example,
set $pc = 0x485
makes the next continue command or stepping command execute at address 0x485, rather
than at the address where your program stopped. See Section 5.2 [Continuing and stepping],
page 44.
The most common occasion to use the jump command is to back upperhaps with more
breakpoints setover a portion of a program that has already executed, in order to examine
its execution in more detail.
100
return
return expression
You can cancel execution of a function call with the return command. If you
give an expression argument, its value is used as the return value from the
function value.
When you use return, GDB discards the selected stack frame (and all frames within
it). You can think of this as making the discarded frame return prematurely. If you wish
to specify a value to be returned, give that value as the argument to return.
This pops the selected stack frame (see Section 6.5 [Selecting a frame], page 53), and any
other frames inside of it, leaving its caller as the innermost remaining frame. That frame
becomes selected. The specified value is stored in the registers used for returning values of
functions.
The return command does not resume execution; it leaves the program stopped in the
state that would exist if the function had just returned. In contrast, the finish command
(see Section 5.2 [Continuing and stepping], page 44) resumes execution until the selected
stack frame returns naturally.
101
If you have already loaded a file, you must load it again (using the exec-file
or core-file command) after changing set write, for your new setting to take
effect.
show write
Display whether executable files and core files are opened for writing as well as
reading.
102
103
12 GDB Files
GDB needs to know the file name of the program to be debugged, both in order to read
its symbol table and in order to start your program. To debug a core dump of a previous
run, you must also tell GDB the name of the core dump file.
file with no argument makes GDB discard any information it has on both
executable file and the symbol table.
exec-file [ filename ]
Specify that the program to be run (but not the symbol table) is found in filename. GDB searches the environment variable PATH if necessary to locate your
program. Omitting filename means to discard information on the executable
file.
symbol-file [ filename ]
Read symbol table information from file filename. PATH is searched when necessary. Use the file command to get both symbol table and program to run
from the same file.
symbol-file with no argument clears out GDB information on the symbol
table of your program.
The symbol-file command causes GDB to forget the contents of its convenience variables, the value history, and all breakpoints and auto-display expressions. This is because they may contain pointers to the internal data recording
symbols and data types, which are part of the old symbol table data being
discarded inside GDB.
104
symbol-file does not repeat if you press hRETi again after executing it once.
When GDB is configured for a particular environment, it understands debugging information in whatever format is the standard generated for that environment; you may use either a gnu compiler, or other compilers that adhere
to the local conventions.
For most kinds of object files, the symbol-file command does not normally
read the symbol table in full right away. Instead, it scans the symbol table
quickly to find which source files and which symbols are present. The details
are read later, one source file at a time, as they are needed.
The purpose of this two-stage reading strategy is to make GDB start up faster.
For the most part, it is invisible except for occasional pauses while the symbol
table details for a particular source file are being read. (The set verbose
command can turn these pauses into messages if desired. See Section 17.6
[Optional warnings and messages], page 248.)
symbol-file filename [ -readnow ] [ -mapped ]
file filename [ -readnow ] [ -mapped ]
You can override the GDB two-stage strategy for reading symbol tables by
using the -readnow option with any of the commands that load symbol table
information, if you want to be sure GDB has the entire symbol table available.
If memory-mapped files are available on your system through the mmap system
call, you can use another option, -mapped, to cause GDB to write the symbols
for your program into a reusable file. Future GDB debugging sessions map
in symbol information from this auxiliary symbol file (if the program has not
changed), rather than spending time reading the symbol table from the executable program. Using the -mapped option has the same effect as starting
GDB with the -mapped command-line option.
You can use both options together, to make sure the auxiliary symbol file has
all the symbol information for your program.
The auxiliary symbol file for a program called myprog is called myprog.syms.
Once this file exists (so long as it is newer than the corresponding executable),
GDB always attempts to use it when you debug myprog; no special options or
commands are needed.
The .syms file is specific to the host machine where you run GDB. It holds
an exact image of the internal GDB symbol table. It cannot be shared across
multiple host platforms.
core-file [ filename ]
Specify the whereabouts of a core dump file to be used as the contents of
memory. Traditionally, core files contain only some parts of the address space
of the process that generated them; GDB can access the executable file itself
for other parts.
core-file with no argument specifies that no core file is to be used.
Note that the core file is ignored when your program is actually running under
GDB. So, if you have been running your program and you wish to debug a
core file instead, you must kill the subprocess in which the program is running.
105
To do this, use the kill command (see Section 4.8 [Killing the child process],
page 28).
add-symbol-file filename address
add-symbol-file filename address [ -readnow ] [ -mapped ]
add-symbol-file filename address data_address bss_address
add-symbol-file filename -ssection address
The add-symbol-file command reads additional symbol table information
from the file filename. You would use this command when filename has been
dynamically loaded (by some other means) into the program that is running.
address should be the memory address at which the file has been loaded; GDB
cannot figure this out for itself. You can specify up to three addresses, in which
case they are taken to be the addresses of the text, data, and bss segments
respectively. For complicated cases, you can specify an arbitrary number of
-ssection address pairs, to give an explicit section name and base address for
that section. You can specify any address as an expression.
The symbol table of the file filename is added to the symbol table originally read
with the symbol-file command. You can use the add-symbol-file command
any number of times; the new symbol data thus read keeps adding to the old.
To discard all old symbol data instead, use the symbol-file command without
any arguments.
add-symbol-file does not repeat if you press hRETi after using it.
You can use the -mapped and -readnow options just as with the symbolfile command, to change how GDB manages the symbol table information for
filename.
section
The section command changes the base address of section SECTION of the
exec file to ADDR. This can be used if the exec file does not contain section
addresses, (such as in the a.out format), or when the addresses specified in the
file itself are wrong. Each section must be changed separately. The info files
command, described below, lists all the sections and their addresses.
info files
info target
info files and info target are synonymous; both print the current target
(see Chapter 13 [Specifying a Debugging Target], page 109), including the
names of the executable and core dump files currently in use by GDB, and
the files from which symbols were loaded. The command help target lists all
possible targets rather than current ones.
All file-specifying commands allow both absolute and relative file names as arguments.
GDB always converts the file name to an absolute file name and remembers it that way.
GDB automatically loads symbol definitions from shared libraries when you use the run
command, or when you examine a core file. (Before you issue the run command, GDB
does not understand references to a function in a shared library, howeverunless you are
debugging a core file).
On HP-UX, if the program loads a library explicitly, GDB automatically loads the
symbols at the time of the shl_load call. See Section 5.1 [Stopping and starting in shared
libraries], page 33, for more information.
106
info share
info sharedlibrary
Print the names of the shared libraries which are currently loaded.
sharedlibrary regex
share regex
Load shared object library symbols for files matching a Unix regular expression.
As with files loaded automatically, it only loads shared libraries required by your
program for a core file or after typing run. If regex is omitted all shared libraries
required by your program are loaded.
On HP-UX systems, GDB detects the loading of a shared library and automatically
reads in symbols from the newly loaded library, up to a threshold that is initially set but
that you can modify if you wish.
Beyond that threshold, symbols from shared libraries must be explicitly loaded. To load
these symbols, use the command sharedlibrary filename . The base address of the shared
library is determined automatically by GDB and need not be specified.
To display or set the threshold, use the commands:
set auto-solib-add threshold
Set the autoloading size threshold, in megabytes. If threshold is nonzero, symbols from all shared object libraries will be loaded automatically when the
inferior begins execution or when the dynamic linker informs GDB that a new
library has been loaded, until the symbol table of the program and libraries
exceeds this threshold. Otherwise, symbols must be loaded manually, using the
sharedlibrary command. The default threshold is 100 megabytes.
show auto-solib-add
Display the current autoloading size threshold, in megabytes.
107
For example, if you want GDB to search for libraries in /home/debugger/lib and
/tmp/lib before searching the default system directories for libraries, you can use this
setting:
GDB_SHLIB_PATH=/home/debugger/lib:/tmp/lib
With this setting, GDB searches the directories in the order specified until it finds a
library with the correct name.
In this example, if GDB encounters a library by the name of /usr/lib/libsubs.sl,
GDB searches first for /home/debugger/lib/libsubs.sl and then for
/tmp/lib/libsubs.sl.
If neither of these exists, then GDB searches the
default system directories and finds /usr/lib/libsubs.sl.
In most cases, GDB_SHLIB_PATH allows more flexibility than GDB_SHLIB_ROOT because
it allows you to specify more than one path. However, there are some cases in which you
may want to choose to use GDB_SHLIB_ROOT.
For example, if you have more than one shared library with the same name but different
path names, you may want to use GDB_SHLIB_ROOT because GDB searches for libraries
based on the full path name.
Note that GDB_SHLIB_PATH may not give you the results you expect because GDB
searches for libraries that match only the name, regardless of the path, and always accepts
the first library that matches the name.
For example, if you want to use /tmp/usr/lib/libsubs.sl and /tmp/usr/share/lib/libsubs.sl,
you can set GDB_SHLIB_ROOT to /tmp. Now whenever GDB encounters a library with
the name /usr/lib/libsubs.sl and /usr/share/lib/libsubs.sl, GDB looks at
/tmp/usr/lib/libsubs.sl and /tmp/usr/share/lib/libsubs.sl respectively.
108
109
110
help target
Displays the names of all targets available. To display targets currently selected,
use either info target or info files (see Section 12.1 [Commands to specify
files], page 103).
help target name
Describe a particular target, including any parameters necessary to select it.
set gnutarget args
GDB uses its own library BFD to read your files. GDB knows whether it is
reading an executable, a core, or a .o file; however, you can specify the file
format with the set gnutarget command. Unlike most target commands,
with gnutarget the target refers to a program, not a machine.
Warning: To specify a file format with set gnutarget, you must
know the actual BFD name.
See Section 12.1 [Commands to specify files], page 103.
show gnutarget
Use the show gnutarget command to display what file format gnutarget is set
to read. If you have not set gnutarget, GDB will determine the file format for
each file automatically, and show gnutarget displays The current BDF target
is "auto".
Here are some common targets (available, or not, depending on the GDB configuration):
target exec program
An executable file. target exec program is the same as exec-file program .
target core filename
A core dump file. target core filename is the same as core-file filename .
target remote dev
Remote serial target in GDB-specific protocol. The argument dev specifies
what serial device to use for the connection (e.g. /dev/ttya). target remote
supports the load command. This is only useful if you have some other way of
getting the stub to the target system, and you can put it somewhere in memory
where it wont get clobbered by the download.
target sim
Builtin CPU simulator. GDB includes simulators for most architectures. In
general,
target sim
load
run
works; however, you cannot assume that a specific memory map, device drivers,
or even basic I/O is available, although some simulators do provide these.
Some configurations may include these targets as well:
111
112
113
114
Support for core file commands packcore, unpackcore, getcore and dumpcore.
On PA-RISC systems, sanity check for core files dumped by hardware generated signals
can be performed. HP WDB can detect and warn the user about certain cases of
corrupted core files.
Inline support is on by default on Integrity systems. On PA-RISC, the inline support
is still off by default.
For PA 64-bit applications, WDB can step into shared library bind-on-reference calls.
This support is available for PA 32-bit as well.
Interception of synchronous signals used by sigwait(), sigwaitinfo() and
sigtimedwait() functions.
These signals are displayed by WDB just like
asynchronous signals but are always passed to the debugger whether nopass is set or
not.
Support for debugging hardware watchpoints and shared libraries.
For PA 64-bit applications, WDB can step into shared library bind-on-reference calls.
This support is available for PA 32-bit as well.
Implementation of -mapshared option to suppress mapping all the shared libraries in
a process private.
Support for deferred breakpoints on dlopened and shl_loaded libraries with stripped
main program.
Additional support for procedural breakpoints.
C99 variable arrays implemented on Integrity systems. This support is available on
PA-RISC as well.
The show envvars command can be used to print information on environment variables
supported by WDB.
Support for handling __fpreg data type.
Support for making changes to the program when debugging without having to recompile or re-link it.
Hardware breakpoints on Integrity systems.
Support for debugging PA-RISC Applications on Integrity systems.
Unwinding Java stack frames on Integrity systems. The 64-bit version of gdb can
unwind through Java stack frames using the shared library in the Java product.The
64-bit library is part of the JDK 1.4.2.10 and JDK 1.5.0.03 products.
Enhanced nexti and stepi commands. The WDB nexti and stepi commands, prints
the assembly instruction along with the next source line.
Enhanced info symbol ADDRESS command. The info symbol ADDRESS command has
been enhanced to search for a symbol at the given address. Previously, the info symbol
command could be used only to search the global namespace.
Enhanced Java debugging support.
Support for debugging C++ programs running under Linux Runtime Environment.
Support for stop in/at dbx commands.
Support for GNU GDB logging commands.
115
Support for persistent display of expressions across re-runs. The user does not need to
re-initiate the display settings for every run.
Viewing wide character and wide-character strings of type wchar_t using the type
print command.
Support for debugging of executables with method and expressions involving covariant
return types
Support for commands, catch throw, catch catch, and info catch, for debugging
exception handlers in C++ on Integrity systems, with the aCC compiler A.06.00 and
later.
Support for the steplast command for C and C++. However, steplast command is
not supported.
Support for dumping an array into an ASCII file.
Support for the Fortran array slices.
Source level debugging of Fortran applications that contain nested routines.
Support for making command line calls in a stripped executable.
Support for a terminal user interface that provides view of source while debugging at
the WDB command line.
Support for debugging 32-bit and 64-bit PA-RISC programs as well as 64-bit Itanium
programs .
Support for assembly-level debugging.
Support for a subset of xdb commands, enabled with -xdb mode.
Support for Java/C/aCC++ stack unwinding with Java SDK version 1.3.1.02 or later
for HP-UX.
Visual Interface for HP WDB -tui mode supports output logging
Command line calls for 64-bit PA-RISC applications that are not linked with end.o.
Command watch_target.
Command line option set display-full-path that displays the full pathname of the
source file name while printing the frame information.
Command line option set dereference [on |off] when off, WDB does not dereference char * variables by default.
Support for show macro, and macro expand to view, and expand macro expressions.
Support for evaluating macros.
Support for printing the execution path entries in the current frame, or thread.
Note:
For new commands
http://www.hp.com/go/wdb.
see
HP
WDB
Release
Notes
available
at
116
atoi()
dlsym()
strstr()
ctime()
memchr()
dlgetname()
strcat()
dlclose()
strrchr()
dlget()
clock_gettime()
strlen()
dlhook()
environ()
dlmodinfo()
getenv()
strlen()
exit()
fork()
execl()
fclose()
strdup()
fopen()
fprintf()
fscanf()
strcasecmp()
sscanf()
getcwd()
getpagesize()
getpid()
srand()
uwx_register_callbacks()
unlink()
lseek()
open()
sprintf()
strcmp()
printf()
pthread_self()
putenv()
shmctl()
rand()
strchr()
uwx_self_lookupip()
shl_get()
shl_unload()
shl_findsym ()
strtok_r()
time()
uwx_get_reg()
shl_get_r()
perror()
uwx_init()
uwx_self_copyin()
creat()
uwx_step()
write()
pthread_getschedparam()
uwx_self_init_context()
uwx_self_init_info()
uwx_register_alloc_cb()
U_STACK_TRACE()
117
close()
strchr()
The runtime checking (of dynamic memory, libraries, and pthreads) in the debugger relies
on the semantic and standard behavior of these library routines. Run Time Checking results
in unexpected and unpredictable behavior when used with applications that substitute or
re-define these library routines.
Before enabling the Run Time Checking feature in WDB, use the nm(1) command
to determine if the application or the dependent libraries in the application re-define or
substitute these standard library routines
118
Defined Variable
None
WDB_ROOT
GDB_ROOT
GDB_SERVER
LIBRTC_SERVER
WDB Location
/opt/langtools/bin
$WDB_ROOT/bin
n/a
n/a
n/a
GDB location
/opt/langtools/bin
$WDB_ROOT/bin
$GDB_ROOT/bin
$GDB_SERVER
n/a
119
librtc.sl location
/opt/langtools/lib
$WDB_ROOT/lib
/opt/langtools/bin
n/a
$LIBRTC_SERVER
Note: If you define WDB_ROOT or GDB_ROOT but do not create the correct directory structure below it, the debugger may fail.
120
1. Make certain the files were compiled with the -g switch. Type info sources to find
the list of files that the debugger knows were compiled with -g.
2.
Make certain that the debugger can find the source file. Type show dir to find the list
of directories the debugger uses to search for source files and type set dir to change
that path.
On HP-UX, the debug information does not contain the full path name to the source
file, only the relative path name that was recorded at compile time. Consequently,
you may need several dir commands for a complex application with multiple source
directories. One way to do this is to place them in a .gdbinit file placed in the
directory used to debug the application.
A sample of the .gdbinit file might look like the following:
dir /home/fred/appx/system
dir /home/fred/appx/display
dir /home/fred/appx/actor
dir /home/fred/appx/actor/sys
...
When you compile the program with the +objdebug option, the debugger may find
the source files without using the dir command. This happens because the debugger
stores the full path name to the object files and searches for source files in the same
directories.
121
represents one or more source files for the current executable. If you do not specify a
file name, WDB edits the currently open source file.
When you edit a file with the edit command and save the changes, the original source
file contains the changes, even if you do not use the fix command to recompile the program
in the debugger.
122
123
cc sum.c -g -o mysum
/usr/ccs/bin/ld: (Warning) At least one PA 2.0 object file
(sum.o) was detected.
The linked output may not run on a PA 1.x system.
2. Run the program.
./mysum
The sum from 1 to 10 is = 0
This result is obviously wrong. We need to debug the program.
3. Run the debugger:
gdb mysum
HP gdb 3.0 for PA-RISC 1.1 or 2.0 (narrow), HP-UX 11.00.
Copyright 1986 - 2001 Free Software Foundation, Inc.
Hewlett-Packard Wildebeest 3.0 (based on GDB ) is covered by the
GNU General Public License. Type "show copying" to see the
conditions to change it and/or distribute copies. Type
"show warranty" for warranty/support.
..
If the TERM environment variable is not set to hpterm, start the debugger and set the
terminal type for editing in WDB with this command (ksh shell):
TERM=hpterm gdb mysum
The problem might be that there is no return for the num function. You can correct
this without leaving the debugger.
4. Set a break point at main:
(gdb) b main
Breakpoint 1 at 0x23f8: file sum.c, line 11.
5. Run the program:
(gdb) run
Starting program: /tmp/hmc/mysum
Breakpoint 1, main () at sum.c:11
11
int num = 10;
6. When the program stops at the break point, use the edit command to make changes
to the source file.
Because you are going to edit the current file, you do not need to specify a source file
name.
(gdb) edit
The edit command opens a new terminal session using your environment variable
settings for terminal and editor. The debugger automatically loads the source file.
7. Make the necessary changes. In this case, add:
return total;
124
125
126
You can toggle the options for inline debugging by entering either of the following commands:
(gdb) set inline-debug <option>
or
$ gdb --inline= <option>
The following options available for the set inline-debug command:
on
off
inline_bp_all
inline_bp_individual
The set inline-debug on command enables the inline debugging feature without the
inline breakpoints options in Integrity systems. This command is enabled by default.
The set inline-debug off command disables the inline debugging feature. You can
disable inline debugging by entering this command before attaching the debugger to the
application.
The set inline-debug inline_bp_all command enables you to set and modify breakpoints on all instances of a particular inline function. It also enables the inline debugging
feature. A single instance of the specified inline function is displayed as a representative instance for all the instances of the specified inline function. This creates a single-breakpoint
illusion for multiple instances of the inline function. You can set and modify breakpoints
on all the instances of the inline functions by setting and modifying breakpoints on the
displayed instance of the inline function. You must enter this command before attaching
the debugger to the application.
The set inline-debug inline_bp_individual command enables you to set and modify breakpoints on a specific instance of an inline function. It also enables the inline debugging feature. All instances of the inline function are displayed separately with individual
breakpoint occurrences. You can set or delete individual breakpoints on a specific instance
of an inline function without modifying the breakpoints on other instances of the inline
function. You must enter this command before attaching the debugger to the application.
Limitations:
The inline breakpoint features are not available for programs that are compiled with +O2 optimization level and above.
The inline breakpoint features can degrade performance of the application that is being debugged. You can explicitly disable the breakpoint features when the features are not required and continue to use other inline debugging features, such as step
and next.
127
128
Step 3:
You can use the following commands for debugging inline functions in Integrity systems:
step
next
list
backtrace
frame <n>
info locals
info args
breakpoint
The following commands are not available for debugging inline functions in Integrity systems:
info frame
disassembly
129
...
(gdb) macro expand MAC
expands to: (67 + 6)
Evaluating Macros
HP WDB enables you to evaluate a macro and display the output. You can evaluate
the macro by using the commonly used gdb commands for evaluating and displaying
expressions, such as print. HP WDB supports the evaluation of macros with variables, constants, complex algebraic expressions involving variables, nested macros, and
function calls. HP WDB does not support the evaluation of macros with multiple
statements in the macro definitions, or the evaluation of macros with stringifying and
pasting tokens in the macro definitions.
To view and evaluate all the macro expressions in the program, you must compile the program with +macro_debug=all. This option can cause a significant
increase in object file size.
ref
To view and evaluate only the reference macros in the program, you must
compile the program with +macro_debug=ref. This is the default for -g, -g0,
or -g1.
none
To disable macro debugging, you must compile the program with +macro_
debug=none
The macro debugging features are supported for +objdebug and +noobjdebug compiler
options.
130
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
#define DUMMY1
#define DUMMY2
int
main ()
{
int val = USED1;
#undef UNUSED1
#undef USED2
#undef USED1
#define USED1 101
#define USED2 201
val = USED1 + USED2;
#undef USED1
#undef UNUSED2
#undef USED2
#define USED1 102
val = USED1;
return 0;
}
HP-UX 11.2x.
Inc.
13 from sc.
23 from sc.
30 from sc.
131
100
(gdb) print USED1+10
110
(gdb) info macro USED1
Defined at scope.c:4
#define USED1 100
(gdb) info macro USED2
Defined at scope.c:5
#define USED2 200
(gdb) c
Continuing.
Breakpoint 2, main () at scope.c:23
23
val = USED1 + USED2;
(gdb) info macro USED1
Defined at scope.c:20
#define USED1 101
(gdb) info macro USED2
Defined at scope.c:21
#define USED2 201
(gdb) c
Continuing.
Breakpoint 3, main () at scope.c:30
30
val = USED1;
(gdb) info macro USED1
Defined at scope.c:28
#define USED1 102
(gdb) info macro USED2
The macro USED2 has no definition in the current scope.
(gdb)
The following debugging session illustrates macro debugging when the program is compiled with +macro_debug=referenced option:
$ cc -g +macro_debug=referenced -o sc1 scope.c
$ gdb sc1
HP gdb for HP Itanium (32 or 64 bit) and target
Copyright 1986 - 2001 Free Software Foundation,
...
(gdb) b 13
Breakpoint 1 at 0x40007d0:0: file scope.c, line
(gdb) b 23
Breakpoint 2 at 0x40007d0:2: file scope.c, line
(gdb) b 30
Breakpoint 3 at 0x40007e0:0: file scope.c, line
(gdb) r
Starting program: sc1
HP-UX 11.2x.
Inc.
13 from sc1.
23 from sc1.
30 from sc1.
132
133
For more information on memory debugging with WDB, see the Debugging Dynamic
Memory Usage Errors Using HP WDB whitepaper at the HP WDB Documentation webpage at:
http://www.hp.com/go/wdb.
134
135
136
137
Total bytes
1234
333
245
Blocks
1
1
8
Address
0x40419710
0x40410bf8
0x40410838
Function
foo()
main()
strdup()
[...]
The debugger assigns each leak a numeric identifier.
7. To display a stack trace for a specific leak, use the info leak command and specify
the number from the list associated with a leak:
(gdb) info leak 2
245 bytes leaked in 8 blocks (10.05% of all bytes leaked)
These range in size from 26 to 36 bytes and are allocated
in strdup ()
in link_the_list () at test.c:55
in main () at test.c:13
in _start ()
138
Note:
The batch mode commands may not always work when invoked through a
shell script.
139
For example:
Correct Usage:
$ cat rtcconfig
check_leaks=on
check_heap=on
files=batchrtc4
$
Incorrect Usage:
$ cat rtcconfig
check_leaks=on
check_heap = on
files=batchrtc4
$
140
To preload the librtc runtime library from a path that is different from the default
paths, you must use the LD_PRELOAD environment variable.
(Or)
Instead of automatically preloading librtc and mapping the shared libraries, you
can explicitly preload the required librtc library after mapping the shared libraries private.
In the case of HP 9000 systems, you must explicitly map the share libraries as
private by using the +dbg enable option for the chatrcommand, as follows:
$ chatr +dbg enable ./<executable>
(This step is not required on Integrity systems.)
To explicitly preload the librtc runtime library and start the target application,
enter one of the following commands:
- For 32 bit IPF applications,
LD_PRELOAD=/opt/langtools/lib/hpux32/librtc.so <executable>
- For 64 bit IPF applications,
LD_PRELOAD=/opt/langtools/lib/hpux64/librtc.so <executable>
- For 32 bit PA applications,
LD_PRELOAD=/opt/langtools/lib/librtc.sl <executable>
- For 64-bit PA applications,
LD_PRELOAD=/opt/langtools/lib/pa20_64/librtc.sl <executable>
If LD_PRELOAD and chatr +mem_check are used to preload the librtc runtime
library , the librtc runtime library is loaded from the path specified by LD_
PRELOAD.
Note:
Batch Mode RTC displays one of the following errors and causes the program to temporarily hang if the version of WDB and librtc.[sl|so] do
not match, or if WDB is not available on the system:
"/opt/langtools/bin/gdb: unrecognized option -brtc
Use /opt/langtools/bin/gdb --help for a complete list of options."
(OR)
"execl failed. Cannot print RTC info: No such file or directory"
This error does not occur under normal usage where WDB or
librtc.[sl|so] is used from the default location at /opt/langtools/...
However, this error occurs if GDB_SERVER and/or LIBRTC_SERVER are set
to a mismatched version of WDB or librtc.[sl|so] respectively.
5. At the end of the run, output data file is created in output_data_dir, if defined in
rtcconfig,or the current directory. HP WDB creates output data file for each run. It
creates a separate file for leak detection and heap information. The naming convention
for output files is as follows:
<file_name>.<pid>.<suffix>
Where, <pid> is the process id and the value for <suffix> can be either leaks, heap, or
mem.
141
Note:
During operations such as system(3s)and popen(), which invoke a new
shell, librtc.sl|so must not be loaded to the invoked shell. You must
use LD_PRELOAD_ONCE, instead of LD_PRELOAD, to exclusively load the
librtc.sl|so file to the calling process only. Following is the syntax for
using LD_PRELOAD_ONCE:
LD_PRELOAD_ONCE= /opt/langtools/lib/librtc.sl
142
143
check_leaks=on
check_free=on
files=executable_name
output_dir=/tmp/results
Step 3: Set the following environment variables as follows:
export BATCH_RTC=on
Step 4: Complete one of the following steps:
- Preload the librtc runtime library,
as follows:
LD_
PRELOAD=/opt/langtools/lib/hpux32/librtc.so <executable>
<arguments if any>
(Or)
- Preload the librtc runtime library, as follows: $ chatr +mem_check
enable <executable>
Example from Integrity Systems: Example-2
Step 1: Compile the source files.
Step 2: The rtcconfig file should contain entries such as the following:
check_heap=on
check_leaks=on
check_free=on
files=exec1:exec2:exec3
output_dir=/tmp/results
Step 3: Set the following environment variables as follows:
export BATCH_RTC=on
Step 4: Complete one of the following steps:
- Use the +mem_check option for the chatr command on each of the required executable files that must be instrumented, as follows:
$ chatr +mem_check enable exec1 exec2 exec3
(Or)
- Preload the librtc library as follows:
export LD_PRELOAD /opt/langtools/lib/hpux32/librtc.so
Step 5: Run the program as follows:
./exec1
Suppose exec1 eventually spawns exec2, exec3, exec4, exec5, only exec1,
exec2, exec3 will be instrumented based on the settings in the rtcconfig
file.
144
145
146
147
Interactive mode
Batch mode
148
capability
[on |off]
(or)
free()
[on |off]
Specify
whether
freed
set heap-check
heap blocks
[on| off]
set heap-check
call-site.
min-heap-size <num>
scramble_blocks=[on| off](or)
set heap-check scramble [on
|off]
min_heap_size = <num>
(or)
set heap-check min-heap-size
<num>
set heap-check
min-leak-size <num>
149
min_leak_size = <num>
(or)
set heap-check min-leak-size
<num>
set heap-check
stack to be captured
frame-count <num>
address
or deallocated.
Instructs malloc to return
null after <num> invocations of malloc.
set heap-check
set heap-check
null-check-size
<size>
set heap-check
null-check <num>
seed-value <num>
dom null-check-count
Specifies the random range
set heap-check
random-range <num>
set heap-check
interval <num>
<num>
150
catch nomem
enabled
Note:
The files=<executable-name> and output_dir=<path> options are exclusive to batch mode debugging.
151
152
No.
0
1
2
3
Total bytes
34567
4096
1234
245
Blocks
1
1
1
8
Address
0x40411000
0x7bd63000
0x40419710
0x404108b0
Function
foo()
bar()
baz()
boo()
[...]
The display shows the currently allocated heap blocks. Any blocks that have been
allocated and already freed are not listed.
To look at a specific allocation, specify the allocation number with the info heap
command:
(gdb) info heap 1
4096 bytes at 0x7bd63000 (9.86% of all bytes allocated)
in bar () at test.c:108
in main () at test.c:17
in _start ()
in $START$ ()
When multiple blocks are allocated from the same call stack, WDB displays additional
information:
(gdb) info heap 3
245 bytes in 8 blocks (0.59% of all bytes allocated)
These range in size from 26 to 36 bytes and are allocated
in boo ()
in link_the_list () at test.c:55
in main () at test.c:13
in _start ()
153
154
155
The thread terminates execution, and the resources associated with the terminated
thread continues to exist in the application because the thread has not been joined
or detached.
The thread uses more than the specified percentage of the stack allocated to the
thread.
The number of threads waiting on any pthread object exceeds the specified threshold number.
156
157
This option is used to detect unintentional use of multiple mutexes with the same
condition variable by different threads. In the case of applications that use a
dynamic pool of mutexes, the cv-multiple-mxs option is not required because
this usage is normal and expected application behavior.
cv-wait-no-mx [on|off]
The set thread-check cv-wait-no-mx [on|off] checks if the associated mutex
of a condition variable is locked when the thread calls the pthread_cond_wait()
routine. The debugger transfers the execution control to the user and prints a
warning message when this condition is detected. This check is not a POSIX.1
standard requirement for the pthread_cond_wait() routine. It is an additional
check provided by WDB.
thread-exit-own-mutex [on|off]
The set thread-check thread-exit-own-mutex [on|off] command checks if
any thread has terminated execution without unlocking the mutexes or read-write
locks that are associated with the thread. The debugger transfers the execution
control to the user and prints a warning message when this condition is detected.
This situation can result in deadlocks if other threads are waiting to acquire the
locked mutexes or read-write locks.
thread-exit-no-join-detach [on|off]
The set thread-check thread-exit-no-join-detach [on|off] command
checks if a thread has terminated execution (either successfully or because of an
exception or a cancel) without joining or detaching the thread. The debugger
transfers the execution control to the user and prints a warning message when
this condition is detected. The resources associated with a terminated thread
continue to exist in the application if the thread is not joined or detached. The
thread must be explicitly joined or detached, or it must be created with the
detach attribute. When an application repeatedly creates threads without a
join or detach operation, the application leaks resources. This may result in
application failure.
stack-util [num]
The set thread-check stack-util [num] command checks if any thread has used
more than the specified percentage [num] of the stack allocation. The debugger
transfers the execution control to the user and prints a warning message when this
condition is detected. You can use this option to verify if there is a margin of safety
in stack utilization by the threads. The application must ensure that the thread
stack size is sufficient for all the operations of the thread. Each thread is assigned
a stack allocation when it is created. If the stack allocation is not specified for a
thread, the default value is used. The stack allocation cannot be modified after a
thread is created. If a thread attempts to use more stack space than the allocated
stack space, it results in a stack overflow. Stack overflow can result in memory
access violations, bus errors, or segmentation faults.
num-waiters [num]
The set thread-check num-waiters [num] command checks if the number of
threads waiting on any pthread object exceeds the specified threshold number
158
[num]. The debugger transfers the execution control to the user and prints a
warning message when this condition is detected.
159
160
0x40172b29:
0x40172b2b:
0x40172b2c:
0x40172b2e:
0x40172b2f:
(61)
(81)
(c0)
(00)
(00)
161
R3body rlen=33
B1label_state label=1
B2epilogue t=44
R1prologue rlen=0
R1prologue rlen=0
162
The unpackcore command has two optional arguments. The first defaults to
packcore.tar.Z and is the name of the packcore file to be unpacked. The second
argument is given if the core file is too large to fit in the packcore file. It is the
path to the core file to be used if the packcore directory does not contain a core file.
If used,this second argument causes a symbolic link to be created in the packcore
directory in place of the missing core file.
The getcore command can be used to examine a packcore directory which was previously created by unpackcore. It takes one optional argument, the name of the
packcore directory, which defaults to packcore.
163
The dumpcore command with no arguments saves the core image for the current process
being debugged in the file named core.<pid>, where pid is the process ID number.
To analyze this core file with HP WDB on HP-UX 11i version 2, you must do the
following:
When starting from HP WDB command line:
(gdb) core-file [core.pid | core-filename]
When starting from shell prompt:
$ gdb -core a.out [core.pid | core-filename]
164
165
166
(gdb) i gep
Global execution path table:
G0
0x4000a80:2
main
(execpath.c:10)
(gdb) n
16
printf("Value of c greater than 0\n");
(gdb) n
Value of c greater than 0
18
printf("All condition checking done\n");
(gdb) i ep
Local execution path table for main():
0
0x4000a80:2
(execpath.c:10)
2
0x4000bd0:2
(execpath.c:16)
(gdb) i ep summary
Summary for local execution path table for main()
Size: 3
\*Total Number of Branch Paths in Current Function
Effective entries: 2
\*Number of Branches executed till this instant
Current entry: 2
\* Last executed branch number
(gdb) i gep
Global execution path table:
G0
0x4000a80:2
main
(execpath.c:10)
G1
0x4000bd0:2
main
(execpath.c:16)
(gdb) i gep summary
Summary for global execution path table
Size: 65536
\*Maximum execution path entries to be stored
Effective entries: 2
\*Number of global execution path entries
Current entry: 1
\*The last Global Path ID executed
(gdb)
167
168
169
performed when the breakpoint is reached. These breakpoints work like procedural
breakpoints in the xdb debugger.
The breakpoint commands are rbp and rdp.
rbp: Sets breakpoints at the first executable statement in all the functions that
can be debugged, including any shared libraries that are already loaded. The rbp
command sets breakpoints in all the functions, which can be debugged, in all the
source files.After you set these breakpoints, you can manage them like any standard
breakpoints. You can delete them, disable them, or make them conditional.Each
time you use the rbp command, HP WDB adds an additional breakpoint at the
beginning of each function that performs the commands you specify, if any.
rdp: Deletes all the breakpoints set by the rbp command.
This example shows how to set a breakpoint at the start of each procedure that displays
information at the breakpoint:
(gdb) file a.out
Reading symbols from a.out...done.
(gdb) rbp
Breakpoints set from 170 to 211
Type commands to execute when the breakpoint is hit (one command per line).
End with a line saying just "end".
>info break
>end
(gdb)
170
171
a warning message that it is setting a deferred breakpoint on foo. If any shared library
is loaded that contains a foo, then GDB sets the breakpoint.
If this is not what you want (for example, if the name was mistyped), then you can
delete the breakpoint.
172
private, regardless of whether the chatr command is run for a particular shlib with
+dbg or not.
The -mapshared option is used to save virtual memory for debugging applications
with large amounts of code in shared libraries on machines with simultaneous debug
sessions. The chatr +dbg option, and the _HP_DLDOPTS environment variable are used
to identify shared libraries for debugging. The -mapshared option ensures that the text
segments of all other shared libraries is shared across the system. The shared libraries
are not mapped private and cannot have breakpoints set in them.
The set mapshared on command can be used to change modes from the (gdb) prompt.
(gdb) set mapshared on
The set mapshared off command can be used to load shared libraries after the current
point is mapped private.
(gdb) set mapshared off
The -mapshared option is implemented on both PA-RISC and Itanium platforms in
HP WDB 5.2. This option is provided in the WDB GUI and HP WDB. The default
behavior does not change if the -mapshared option for all shared libraries in processes
started under the debugger, or dynamically loaded after an attach, are mapped private.
173
174
availability of Java SDK version 1.3.1.02 or later, go to the HP web site for Java,
http://www.hp.com/go/java.
To enable this feature, set the environment variable, GDB_JAVA_UNWINDLIB, to the path
to libjunwind.sl. This library is part of the Java SDK version 1.3.1.02 or later for
HP-UX. When GDB_JAVA_UNWINDLIB is set to the path for a valid Java unwind library,
stack traces display Java and C/C++ frames.
The types of Java frames supported are as follows:
Interpreter
Compiled frames
Adapter frames
175
176
another imaginary number. You can take a normal number and add it to an imaginary
number to get a complex number.
Complex numbers cannot be used in arithmetic expressions in the debugger.
For more information of _Complex type, refer to the HP C/ANSI C documentation.
177
178
0
2
4
6
8
2
..
..
where, ARRAY is the name of the array, and its size is 5x5.
The first two lines are comments about this file and the array. The third line denotes
the array coordinates. From the fourth line, the elements of the array are listed.
Note: This feature is not supported for the Fortran array slices.
179
includes the steplast command, which helps to step into a function, and not into the
calls for evaluating the arguments. However, the steplast command is not available
on Integrity systems. The following example illustrates how GDB behaves when you
execute the steplast command:
(gdb) 16 foo (bar ()); ---> bar() will return 10 (gdb) steplast foo (x=10) at
foo.c:4 4 int k = 10;
If the steplast command is not meaningful for the current line, GDB displays the
following error message:
"Steplast is not meaningful for the current line."
For example,
(gdb) 4 int k = 10; (gdb) sl ---> alias to "steplast" command error: Steplast
is not meaningful for the current line
To execute the steplast command in C++ compiled applications, you must compile
the application using the HP aC++ version A.03.50 or later with the -g0 option.
In C++, the steplast command is helpful while debugging heavy templated functions,
because it directly steps into the call, thus skipping the constructor calls, if any. This
behavior is unlike the step command that steps into the constructor itself.
Consider the following example:
void call_me ( string s ) ... (gdb)
10
call_me ( "hello" );
(gdb) steplast call_me (s=static npos = 4294967295,
static nullref = ref_hdr = mutex_= dummy1 = 0x7f4f79e0, dummy2 = 2136325568,
refs_ = 2136327612,
capacity_ = 2136327468, nchars_ = 2136327464, eos_char = 64 @,
alloc_ = <No data fields>,
value_allocator = alloc_ = 0x7f7f133c,
data_ = 0x40003a64 "hello") at str.C:55
printf ("Will just print the value of \n");
If there are multiple top-level calls, the steplast command enables you to step into
each top-level call. For example, for the following line, the steplast command takes
you to the first top-level call, (foo()):
foo(bar()) + bar(foo());
Debug foo(), use the finish command to exit from the first top-level call, (foo()),
execute the steplast command to step into the next top-level call, (bar()). The
following example illustrates the use of steplast command:
(gdb)10 foo( bar() ) + bar( foo() ) (gdb) sl Use the steplast (sl) command to
step
180
When GDB has no debug information; it does not know where the arguments are
located or even the type of the arguments. GDB cannot infer this in an optimized,
non-debug executable.
However, for integer arguments you can find the first few parameters for the top-ofstack frame by looking at the registers. On PA-RISC systems, the first parameter will
be in $r26, the second in $r25 and so on. On IPF systems, the first few parameters
will be in $gr32 and $gr33.
181
next
step
tbreak
rbreak
up
The following commands are not affected by the optimization level of the program
being debugged:
attach
catch
commands
continue
core
delete
define
detach
disable
enable *
exec
file
forw
handle *
help *
ignore
kill
load
nexti
path
quit
rev
run
set args, set env, set <param>
show args, show <param>
signal
source
stepi
symbol
target
tty
undisplay
182
unset env
until
14.25.1.2 +O2/+O3/+O4/-ipo
Stepping by line number (step/next) and running to a breakpoint(break) moves the
state of a program forward. However, the program execution does not necessarily stop
at the given line.
You can set breakpoints (break) at the entry to a routine that is not inlined and
examine the values of parameters when the program execution stops at the entry of a
routine. The local variables can be examined within a function. However, the values of
the local variables may not be available at all code locations in the function. Assignment
of new values to formal parameters or local variables is NOT supported in code compiled
with optimization above +O1.
Optimization of code results in the reordering of the instructions and the source linenumbers. Hence, the value of the variable, which is printed by the debugger may not
correspond to the reported source code location. The debugger may print the value of
the variable at a source code location either before or after the reported source code
location.(If the printed value is not current with respect to the current source line,
the printed value will be the immediately previous or immediately later value for the
variable.)
Backtrace commands (backtrace) can be used to display the current nest of function
calls, including calls that are inlined. When stopped within the code for an inlined
183
call, the parameters and the local variables of the inlined routine are not reported
or available. The disassem command does not work for functions that have no code
(because all calls to these functions are inlined or these functions are not called at all).
HP WDB 5.7 and later versions provide support to prevent the debugged program
from stopping at instructions that are predicated false. The program execution can be
stopped by a software breakpoint, a hardware breakpoint, or an asynchronous signal. In
the case of optimizations such as if-conversion, the predicated false instructions indicate
that an alternate source path is executed. Hence, stopping the program at a predicated
false instruction results in the misleading conclusion that the path corresponding to
the predicated false instruction is executed. To prevent this ambiguity, HP WDB does
not stop at predicated false instructions.
The predicated false instructions are equated to NOPs (No OPeration), because these
instructions do not modify the processor state. The exception to this rule is the use
of certain instructions, such as wtop, wexit, and frcpa, which modify the processor
state even when predicated false. In such cases, the debugger stops at the instructions irrespective of the predicate value of the instructions. Assembly and low-level
programmers, who require the old behavior of the debugger to stop at the instructions
irrespective of the predicate value of these instructions, can explicitly turn off this
feature. To explicitly turn off this feature, enter the following command at the gdb
prompt:
(gdb) set no-predication-handling
The following limitations apply when debugging optimized code:
Support for high-level loop transformations such as modulo-scheduled loops, or
LNO-optimized loop nests is limited. (This limited support includes all loop optimizations that are enabled at +O3 and above, and some loop optimizations at +O2
or -O.)
Debug support for local aggregates and arrays is limited.
Complete debug support for inlined subroutines is not available.
Values that are not at the current code location will be reported as being unavailable, even if these values can be computed from some other values that are
available.
Step operations may include occasional "backwards" steps, because of the reordered code during optimization.
The program stops at asynchronous signal stops even if the reported instruction
is predicated false.
Complete support is available for debugging at the assembly language level. Stepping
by instructions (stepi/nexti) steps as expected and reports the associated source line
numbers for each instruction.
Note: The -ipo compilation implies the +noobjdebug option because the
-ipo object files do not store executable code or debug info.
184
185
186
33 #include <stdlib.h>
34 #include "Deck.h"
35 #include "Player.h"
36 #include "House.h"
37
38 int main ()
39 {
*>
40
srand ((int) time(0));
41
42
Deck theDeck;
43
Player thePlayer (100);
44
House theHouse (16);
45
46
theHouse.Instructions();
47 }
File: BlackJack.C
Function: main
Line: 40
Pc: 0x3ea0
(wdb) b main
Breakpoint 1 at 0x3ea0: file BlackJack.C, line 40.
(wdb) run
Starting program: /work/wdb/blackjack/blackjack
Breakpoint 1, main () at BlackJack.C:40
40
srand ((int) time(0));
(wdb)
Run
Faq
Resume Stop
Stop
Next
Up
Down
Visual
Interface
WDB
Finish
Type
List
for
Prompt Print* Edit
Credits
You can click the softkey or press a function key on the keyboard to invoke the command.
The function keys F1 through F8 correspond to the bottom row of softkeys. The
function keys F9 and up correspond to the top row.
HPterm*foreground:
HPterm*background:
187
white
rgb:68/90/C4
188
Shift <Key>Prior:
string(0x2) \n \
Shift <Key>Next:
string(0x6) \n \
Shift <Key>Up:
string(0x5) \n \
Shift <Key>Down:
string(0x19) \n \
Shift <Key>Left:
string(0x1b) string(i) \n \
Shift <Key>Right:
string(0x1b) string(la)
For DtTerm use the following:
*DtTerm*Translations: #override\n \
Shift <Key>osfPageUp: string(0x2) \n \
Shift <Key>osfPageDown: string(0x6) \n \
Shift <Key>osfUp:
string(0x5) \n \
Shift <Key>osfDown:
string(0x19) \n \
Shift <Key>osfLeft:
string(0x1b) string(i) \n \
Shift <Key>osfRight:
string(0x1b) string(la)
Mouse operations are not supported in the -tui mode. Also the paging and shift keys
do not work well with VT100.
+
to increase
hCTRLi-W
to decrease
In Visual Interface for WDB, the current window is usually the debugger window.
Search forward
Search backward
n
N
Repeat search
Match braces
[[
]]
189
:line number
Go to any line number
All these commands require you to escape to vi command mode first. When you
are done, type a for append or i for insert or other vi commands to return to text
insertion mode.
Or you can simply click the Prompt softkey.
190
191
192
193
194
195
|----------------------------------------------------------------------|
|30
{
|
|31
/* Try two test cases. */
|
|32
print_average (my_list, first, last);
|
|33
print_average (my_list, first, last - 3);
|
|34
}
|
|35
|
|36
|
|37
|
|38
|
|39
|
|40
|
|41
|
|42
|
|----------------------------------------------------------------------|
File: average.c
Procedure: ??
Line: ??
pc: ??
Wildebeest is free software, covered by the GNU General Public License, and
you are welcome to change it and/or distribute copies of it under certain
conditions. Type "show copying" to see the conditions. There is
absolutely no warranty for Wildebeest. Type "show warranty" for details.
---Type <return> to continue, or q <return> to quit--Wildebeest was built for PA-RISC 1.1 or 2.0 (narrow), HP-UX 11.00.
..
(gdb)
196
The terminal window is divided into two panes: a Source pane at the top and a Command
pane at the bottom. In the middle is a locator bar that shows the current file, procedure,
line, and program counter (PC) address, when they are known to the debugger.
When you set a breakpoint on the main program by issuing the command
b main
an asterisk (*) appears opposite the first executable line of the program. When you execute
the program up to the first breakpoint by issuing the command
run
a right angle bracket (>) points to the current location. So after you issue those commands,
the window looks something like this:
Figure 2
|----------------------------------------------------------------------|
|27
}
|
|28
|
|29
int main(void)
|
|30
{
|
|31
/* Try two test cases. */
|
*>|32
print_average (my_list, first, last);
|
|33
print_average (my_list, first, last - 3);
|
|34
}
|
|35
|
|36
|
|37
|
|38
|
|39
|
|----------------------------------------------------------------------|
File: average.c
Procedure: main
Line: 32
pc: 0x3524
..
(gdb) b main
Breakpoint 1 at 0x3524: file average.c, line 32.
(gdb) run
Starting program: /home/work/wdb/a.out
Breakpoint 1, main () at average.c:32
(gdb)
197
198
Figure 3
|----------------------------------------------------------------------|
|;;;
print_average (my_list, first, last);
|
*>|0x3524 <main+8> addil L-0x800,%dp,%r1
|
|0x3528 <main+12>
ldo 0x730(%r1),%r26
|
|0x352c <main+16>
ldi 9,%r24
|
|0x3530 <main+20>
ldi 0,%r25
|
|0x3534 <main+24>
ldil L0x3000,%r31
|
|0x3538 <main+28>
be,l 0x498(%sr4,%r31)
|
|0x353c <main+32>
copy %r31,%rp
|
|;;;
print_average (my_list, first, last - 3);
|
|0x3540 <main+36>
addil L-0x800,%dp,%r1
|
|0x3544 <main+40>
ldo 0x730(%r1),%r26
|
|0x3548 <main+44>
ldi 6,%r24
|
|0x354c <main+48>
ldi 0,%r25
|
|----------------------------------------------------------------------|
File: average.c
Procedure: main
Line: 32
pc: 0x3524
(gdb) b main
Breakpoint 1 at 0x3524: file average.c, line 32.
(gdb) r
Starting program: /home/work/wdb/a.out
Breakpoint 1, main () at average.c:32
(gdb) la asm
(gdb)
Figure 4
199
:......................................................................:
*>:32
print_average (my_list, first, last);
:
:33
print_average (my_list, first, last - 3);
:
:34
}
:
:35
:
:36
:
:37
:
:......................................................................:
|;;;
print_average (my_list, first, last);
|
*>|0x3524 <main+8> addil L-0x800,%dp,%r1
|
|0x3528 <main+12>
ldo 0x730(%r1),%r26
|
|0x352c <main+16>
ldi 9,%r24
|
|0x3530 <main+20>
ldi 0,%r25
|
|0x3534 <main+24>
ldil L0x3000,%r31
|
|----------------------------------------------------------------------|
File: average.c
Procedure: main
Line: 32
pc: 0x3524
Breakpoint 1 at 0x3524: file average.c, line 32.
(gdb) r
Starting program: /home/work/wdb/a.out
Breakpoint 1, main () at average.c:32
(gdb) la asm
(gdb) la split
(gdb)
Figure 5
200
:.........................................................................:
:flags 29000041
r1 51a800
rp 7f6ce597
:
:r3 7f7f0000
r4 1
r5 7f7f06f4
:
:r6 7f7f06fc
r7 7f7f0800
r8 7f7f0800
:
:r9 40006b10
r10 0
r11 40004b78
:
:r12 1
r13 0
r14 0
:
:r15 0
r16 40003fb8
r17 4
:
:.........................................................................:
|;;;
print_average (my_list, first, last);
|
*>|0x3524 <main+8> addil L-0x800,%dp,%r1
|
|0x3528 <main+12>
ldo 0x730(%r1),%r26
|
|0x352c <main+16>
ldi 9,%r24
|
|0x3530 <main+20>
ldi 0,%r25
|
|0x3534 <main+24>
ldil L0x3000,%r31
|
|----------------------------------------------------------------------|
File: average.c
Procedure: main
Line: 32
pc: 0x3524
(gdb) r
Starting program: /home/work/wdb/a.out
Breakpoint 1, main () at average.c:32
(gdb) la asm
(gdb) la split
(gdb) la regs
(gdb)
Figure 6
201
:.........................................................................:
:flags 29000041
r1 51a800
rp 7f6ce597
:
:r3 7f7f0000
r4 1
r5 7f7f06f4
:
:r6 7f7f06fc
r7 7f7f0800
r8 7f7f0800
:
:r9 40006b10
r10 0
r11 40004b78
:
:r12 1
r13 0
r14 0
:
:r15 0
r16 40003fb8
r17 4
:
:.........................................................................:
*>|32
print_average (my_list, first, last);
|
|33
print_average (my_list, first, last - 3);
|
|34
}
|
|35
|
|36
|
|37
|
|----------------------------------------------------------------------|
File: average.c
Procedure: main
Line: 32
pc: 0x3524
Breakpoint 1, main () at average.c:32
(gdb) la asm
(gdb) la split
(gdb) la regs
(gdb) la src
(gdb) la regs
(gdb)
ts
202
The command pane always has keyboard focus, so that you can enter debugger commands. If there is only one other pane (Source or Disassembly), the other pane has the
logical focus, so that you can scroll within that pane by using the arrow keys or the hPage Upi
and hPage Downi keys (on some keyboards these are hPrevi and hNexti).
Note: In the command pane, the scrolling behavior only works for an hpterm and not
for an xterm or dtterm.
If you are in split-screen mode, you may want to change the logical focus of the pane.
To do so, use the command
Remember, if you change the focus to a pane other than the command pane, you need to
use focus cmd to switch back to the command pane to enter or scroll through commands.
For example, with the sequence of commands just issued, you are in split-screen mode
with the focus in the Source pane.
The pane with logical focus has a border constructed from "|" and "-".
A pane that does not have logical focus has a border constructed from ":"vand ".":
Figure 7
203
:.........................................................................:
:flags 29000041
r1 51a800
rp 7f6ce597
:
:r3 7f7f0000
r4 1
r5 7f7f06f4
:
:r6 7f7f06fc
r7 7f7f0800
r8 7f7f0800
:
:r9 40006b10
r10 0
r11 40004b78
:
:r12 1
r13 0
r14 0
:
:r15 0
r16 40003fb8
r17 4
:
:.........................................................................:
*>|32
print_average (my_list, first, last);
|
|33
print_average (my_list, first, last - 3);
|
|34
}
|
|35
|
|36
|
|37
|
|----------------------------------------------------------------------|
File: average.c
Procedure: main
Line: 32
pc: 0x3524
Breakpoint 1, main () at average.c:32
(gdb) la asm
(gdb) la split
(gdb) la regs
(gdb) la src
(gdb) la regs
(gdb)
By default, the Source pane can scroll. To change the focus so that you can scroll in the
Register pane, use the focus command (abbreviated foc or fs):
fs regs
or
foc next
If you then use the hPage Downi key to scroll in the Register pane, the window looks like
this:
Figure 8
204
|-------------------------------------------------------------------------|
|flags 29000041
r1 51a800
rp 7f6ce597
|
|r3 7f7f0000
r4 1
r5 7f7f06f4
|
|r6 7f7f06fc
r7 7f7f0800
r8 7f7f0800
|
|r9 40006b10
r10 0
r11 40004b78
|
|r12 1
r13 0
r14 0
|
|r15 0
r16 40003fb8
r17 4
|
|-------------------------------------------------------------------------|
*>:32
print_average (my_list, first, last);
:
:33
print_average (my_list, first, last - 3);
:
:34
}
:
:35
:
:36
:
:37
:
:......................................................................:
File: average.c
Procedure: main
Line: 32
pc: 0x3524
(gdb) la asm
(gdb) la split
(gdb) la regs
(gdb) la src
(gdb) la regs
(gdb) foc next
Focus set to REGS window.
(gdb)
205
fr
display $fregs
Display the floating-point registers.
sr
display $sregs
Display the special registers.
gr
display $gregs
Display the general registers.
For example, if you use the fr command, the window looks like this:
Figure 9
|-------------------------------------------------------------------------|
|flags 29000041
r1 51a800
rp 7f6ce597
|
|r3 7f7f0000
r4 1
r5 7f7f06f4
|
|r6 7f7f06fc
r7 7f7f0800
r8 7f7f0800
|
|r9 40006b10
r10 0
r11 40004b78
|
|r12 1
r13 0
r14 0
|
|r15 0
r16 40003fb8
r17 4
|
:......................................................................:
:30
{
:
:31
/* Try two test cases. */
:
*>:32
print_average (my_list, first, last);
:
:33
print_average (my_list, first, last - 3);
:
:34
}
:
:35
:
:......................................................................:
File: average.c
Procedure: main
Line: 32
pc: 0x3524
(gdb) la regs
(gdb) la src
(gdb) la regs
(gdb) foc next
Focus set to REGS window.
(gdb) fr
#0 main () at average.c:32
(gdb)
206
Figure 10
|-------------------------------------------------------------------------|
|fpsr 0
fpe1 0
|
|fpe2 0
fpe3 0
|
|fpe4 0
fpe5 0
|
|fpe6 0
fpe7 0
|
|fr4
0
fr4R
0
|
|fr5
1.0000000000000011
fr5R
7.00649232e-45
|
|-------------------------------------------------------------------------|
*>:32
print_average (my_list, first, last);
:
:33
print_average (my_list, first, last - 3);
:
:34
}
:
:35
:
:36
:
:37
:
:......................................................................:
File: average.c
Procedure: main
Line: 32
pc: 0x3524
(gdb) la regs
(gdb) la src
(gdb) la regs
(gdb) foc next
Focus set to REGS window.
(gdb) fr
(gdb) tf
(gdb)
207
wh src +3
increases the size of the source pane, and decreases the size of the command pane, by 3
lines.
To find out the current sizes of all panes, use the info win command. For example, if
you have a split-screen layout, the command output might be as follows:
(gdb) i win
SRC
(8 lines)
REGS
(8 lines)
CMD
(8 lines)
If you use the mouse or window menus to resize the terminal window during a debugging
session, the window remains the same size it was when you started. To change the window
size, you must exit the debugger and restart it.
208
209
Section
Section
Section
Section
Section
Section
Section
Section
Section
Section
Section
Section
Section
210
WDB Equivalent
xdb program
Meaning
gdb -xdb
Debug program
-tui program
xdb program corefile
xdb -d dir
xdb -i
xdb -o
Meaning
211
{+ | -}r
fr
Display
registers
gr
sr
td
Toggle
mode
tf
ts
w
number
w number
(with
-xdb -tui),
winheight src
floating-point
disassembly
212
search
?[string]
D "dir"
D "dir"
/[string]
(with
-xdb),
dir
pathname
L
L (with -xdb)
ld
ld
(with
directories
lf
lf [string]
No equivalent
fo or rev
fo or rev
v location
v location
-xdb),
(with
show
list
-xdb),
location
va address
address
va label
va label + offset
window
213
WDB Equivalent
Meaning
by info locals
lc [string]
info
info
common string
lg [string]
ll [string]
msymbols file
lm
show user
lm string
lo
[[class]::][string]
lp
info functions
lp
[[class]::]string
addr [[class]::]string
lr
info
214
lr string
string
ls [string]
No equivalent
mm
info sharedlibrary
mm string
No equivalent
p expr[\format
p/format &expr
p class::
No equivalent
p $lang
show language
p {+ | -}[\format
pq expr
"x $_ - 1".
set expr, set var expr
pq expr?format
No equivalent
pq class::
No equivalent
pq {+
215
No equivalent
-}[\format
up
down number
up number
t [depth]
T [depth]
[depth]
top
frame 0
View procedure
frame of stack
up
down
up number
down number
V [depth]
frame
at
innermost
216
XDB Command
WDB Equivalent
Meaning
kinds)
WDB Equivalent
Meaning
c, continue
c location
until location
Continue from breakpoint, ignoring any pending signal, set temporary breakpoint at location
c, continue
C [location]
until location
g line
No equivalent
g {+ | -}lines
by jump {+ | -}lines
g {+ | -}
217
r [arguments]
r [arguments]
R (with -xdb), r
s, si
s number
s number, si number
S (with -xdb), n, ni
S number
ninumber
WDB Equivalent
Meaning
lb
lb (with -xdb), i b
List breakpoints
tb
No equivalent
WDB Equivalent
Meaning
218
"any string"
p "any string"
if expr
Quiet breakpoints
{cmds}
[{cmds}]
Q
WDB Equivalent
Meaning
b loc
b loc
ba address
ba address
(with
-xdb),
*address
bb [depth]
bi expr.proc
== expr)
bi -c expr
No equivalent
219
bi -C expr
No equivalent
bpc -c class
rb ^class::*
Set a class breakpoint at first executable line of all member functions of the instances class (no
base classes)
bpc -C class
Set a class breakpoint at first executable line of all member functions of the class (base classes included)
bpo proc
rb proc
bpo class::proc
b class::proc
bt [depth]
No equivalent
bt proc
end
bu [depth]
220
XDB Command
WDB Equivalent
Meaning
ab number
enable number
ab *
enable
ab @sharedlibrary
No equivalent
bc number expr
commands list)
db
clear
db number
delete number
db *
delete
sb number
disable number
sb *
disable
sb @sharedlibrary
No equivalent
221
Dpx
WDB Equivalent
Meaning
abc cmds
expr
dbc
undisplay
222
WDB Equivalent
def name
replacement-text
def name
tm
No equivalent
undef name
def name
command list]
No equivalent
undef *
[GDB
Meaning
prompts
for
commands]
WDB Equivalent
Meaning
lz
z number s
nostop
z number i
z number r
223
noprint
z number Q
WDB Equivalent
Meaning
Return
Return
Return
! cmd line
(with
-xdb),
she
Invoke a shell
cmd line
{cmd list}
Control-C
Control-C
# [text]
# [text]
A comment
am
f ["printf-style-
No equivalent
Help
M[{t | c} [expr[;
No equivalent
fmt"]
expr...]]]
224
Quit debugger
sm
ss file
No equivalent
tc
No equivalent
p expr \fmt
p/fmt expr
Use the set print pretty command to obtain a structured display similar to the default
XDB display.
The following table lists the XDB and equivalent WDB commands for setting data
display formats:
XDB Command
WDB Equivalent
Meaning
Byte in decimal
B (1)
Byte in decimal
Character
C (1)
Wide character
Decimal integer
D (1)
No equivalent
225
E (1)
No equivalent
No equivalent
F (1)
No equivalent
G (1)
No equivalent
K (1)
No equivalent
O (1)
No equivalent
String
No equivalent
226
whatis, ptype
T (1)
ptype
U (1)
No equivalent
W (1)
No equivalent
Print in hexadecimal
X (1)
Print in binary
Z (1)
(1) HP WDB will display data in the size appropriate for the data. It will not extend
the length displayed in response to one of the uppercase formchars (e.g. O, D, F).
WDB Equivalent
Meaning
line
line
file[:line]
file[:line]
227
proc
proc
Procedure name
[file:]proc[:proc[...]][:line]
No equivalent
[file:]proc[:proc[...]][:#label] No equivalent
[class]::proc
[class]::proc
[class]::proc[:line]
No equivalent
[class]::proc[#label]
No equivalent
proc#line
No equivalent
Code address
[class]::proc#line
No equivalent
Code address
#label
No equivalent
name@shared-library
No equivalent
WDB Equivalent
Meaning
$addr
Depends on language
$in
No equivalent
$sizeof
sizeof
228
GDB does not provide special variables of the kind that XDB has, but you can use show
and set to display and modify many debugger settings.
WDB Equivalent
Meaning
$cplusplus
No equivalent
$depth
No equivalent
$fpa
No equivalent
$fpa_reg
No equivalent
$lang
show language
$line
No equivalent
$malloc
No equivalent
Debugger
(bytes)
No equivalent
$regname
$regname
Hardware registers
$result
memory
allocation
desired result)
$signal
No equivalent
229
$step
No equivalent
$var
$var
WDB Equivalent
Meaning
var
var
class::var
class::var
[[class]::]proc:[class::]var
proc::var
[[class]::]proc:depth:[class::]No equivalent
Empty string; for example, p is the equivalent of
. (dot)
p.
:var or ::var
::var to distinguish a
global from a local vari-
Section
Section
Section
Section
Section
Section
Section
Section
16.8.1
16.8.2
16.8.3
16.8.4
16.8.5
16.8.6
16.8.7
16.8.8
230
16.8.1 A
XDB Command
a [cmds]
No equivalent
aa number
No equivalent
aa *
No equivalent
ab number
enable number
ab *
enable
ab @shared-library
No equivalent
abc cmds
am
No equivalent
No equivalent
16.8.2 B
XDB Command
b loc
b loc
231
ba address
bb [depth]
bc number expr
bi expr.proc
bi -c expr
No equivalent
bi -C expr
No equivalent
bp
No equivalent
bp cmds
No equivalent
bpc -c class
rb ^class::*
bpc -C class
bpo proc
rb proc
bpo class::proc
b class::proc
bpt
No equivalent
bpt cmds
No equivalent
bpx
No equivalent
232
bpx cmds
No equivalent
bt [depth]
No equivalent
bt proc
bu [depth]
bx [depth]
16.8.3 C through D
XDB Command
c, continue
c location
until location
c, continue
C location
until location
D "dir"
da number
No equivalent
da *
No equivalent
db
clear
db number
delete number
db *
delete
dbc
undisplay
down
up
down number
up number
dp
No equivalent
dpm index
No equivalent
dpm *
No equivalent
Dpt
No equivalent
Dpx
No equivalent
16.8.4 F through K
XDB Command
f ["printf-style-fmt"]
No equivalent
fr
g line
233
234
g #label
No equivalent
g {+ | -}lines
g {+ | -}
gr
16.8.5 L
XDB Command
L (with -xdb)
la
No equivalent
lb
lb (with -xdb), i b
lc [string]
235
ld
lf
lf [string]
No equivalent
lg [string]
ll [string]
lm [string]
lo [[class]::][string]
lp
info functions
lp [[class]::]string
lpm
No equivalent
lr
lr string
ls [string]
No equivalent
lz
16.8.6 M through P
XDB Command
maint
236
No equivalent
mm
info sharedlibrary
mm string
No equivalent
fo or rev
fo or rev
p expr[\format]
p expr?format
p/format &expr
p class::
No equivalent
p $lang
show language
p {+ | -}[\format
pq expr
pq expr?format
No equivalent
pq class::
No equivalent
pq [+ | -][\format
No equivalent
16.8.7 Q through S
237
XDB Command
r [arguments]
r [arguments]
R (with -xdb), r
s, si
s number
s number, si number
S (with -xdb), n, ni
S number
sa number
No equivalent
sa *
No equivalent
sb number
disable number
sb *
disable
sb @shared-library
No equivalent
sm
sr
238
ss file
No equivalent
16.8.8 T
XDB Command
t [depth]
T [depth]
ta
No equivalent
tb
No equivalent
tc
No equivalent
td
tf
tm
No equivalent
top
frame 0
tr [@]
No equivalent
ts
16.8.9 U through Z
XDB Command
239
undef name
undef *
No equivalent
up
down
up number
down number
v location
V [depth]
va address
va label
va label + offset
w number
x [expr]
No equivalent
xdb program
240
xdb -d dir
xdb -i
xdb -o
z number s
z number i
z number r
z number Q
16.8.10 Symbols
XDB Symbol
line
line
file[:line]
file[:line]
proc
proc
[file:]proc[:proc[...]][:line]
No equivalent
[file:]proc[:proc[...]][:#label]
No equivalent
241
[class]::proc
[class]::proc
[class]::proc[:line]
No equivalent
[class]::proc[#label]
No equivalent
proc#line
No equivalent
[class]::proc#line
No equivalent
name@shared-library
No equivalent
var
var
class::var
[[class]::]proc:[class::]var
[[class]::]proc:depth:[class::]var
No equivalent
Return
Return
"any string"
p "any string"
. (dot)
Return
{+ | -}r
242
{+ | -}[number]
/[string]
?[string]
:var or ::var
::var
! cmd line
{cmd list}
<file
source file
<<file
No equivalent
>
No equivalent
>file
No equivalent
>c
No equivalent
>f
No equivalent
>t
No equivalent
>@[c | f | t]
No equivalent
243
>@file
No equivalent
>>
No equivalent
>>file
No equivalent
>>@
No equivalent
>>@file
No equivalent
Control-C
Control-C
# [text]
# [text]
#label
No equivalent
244
245
17 Controlling GDB
You can alter the way GDB interacts with you by using the set command. For commands
controlling how GDB displays data, see Section 8.7 [Print settings], page 70. Other settings
are described here.
246
set editing-mode vi
The readline interface uses the .inputrc file to control the settings.
set history filename fname
Set the name of the GDB command history file to fname. This is the file where
GDB reads an initial command history list, and where it writes the command
history from this session when it exits. You can access this list through history
expansion or through the history command editing characters listed below.
This file defaults to the value of the environment variable GDBHISTFILE, or to
./.gdb_history (./_gdb_history on MS-DOS) if this variable is not set.
set history save
set history save on
Record command history in a file, whose name may be specified with the set
history filename command. By default, this option is disabled.
set history save off
Stop recording command history in a file.
set history size size
Set the number of commands which GDB keeps in its history list. This defaults
to the value of the environment variable HISTSIZE, or to 256 if this variable is
not set.
History expansion assigns special meaning to the character !.
Since ! is also the logical not operator in C, history expansion is off by default. If you
decide to enable history expansion with the set history expansion on command, you may
sometimes need to follow ! (when it is used as logical not, in an expression) with a space
or a tab to prevent it from being expanded. The readline history facilities do not attempt
substitution on the strings != and !(, even when history expansion is enabled.
The commands to control history expansion are:
set history expansion on
set history expansion
Enable history expansion. History expansion is off by default.
set history expansion off
Disable history expansion.
The readline code comes with more complete documentation of editing and
history expansion features. Users unfamiliar with gnu Emacs or vi may wish
to read it.
show
show
show
show
show
history
history filename
history save
history size
history expansion
These commands display the state of the GDB history parameters.
history by itself displays all four states.
show
247
show commands
Display the last ten commands in the command history.
show commands n
Print ten commands centered on command number n.
show commands +
Print ten commands just after the commands last printed.
248
sets the base to decimal. On the other hand, set radix 10 leaves the radix
unchanged no matter what it was.
set output-radix base
Set the default base for numeric display. Supported choices for base are decimal
8, 10, or 16. base must itself be specified either unambiguously or using the
current default radix.
show input-radix
Display the current default base for numeric input.
show output-radix
Display the current default base for numeric display.
249
250
251
This defines the command adder, which prints the sum of its three arguments. Note the
arguments are text substitutions, so they may reference variables, use complex expressions,
or even perform further functions calls.
The following contructs can be used to create canned sequence of commands:
define commandname
Define a command named commandname. If there is already a command by
that name, you are asked to confirm that you want to redefine it.
The definition of the command is made up of other GDB command lines, which
are given following the define command. The end of these commands is marked
by a line containing end.
if
while
The syntax is similar to if: the command takes a single argument, which is
an expression to evaluate, and must be followed by the commands to execute,
one per line, terminated by an end. The commands are executed repeatedly as
long as the expression evaluates to true.
document commandname
Document the user-defined command commandname, so that it can be accessed by help. The command commandname must already be defined. This
command reads lines of documentation just as define reads the lines of the
command definition, ending with end. After the document command is finished, help on command commandname displays the documentation you have
written.
252
You may use the document command again to change the documentation of a
command. Redefining the command with define does not change the documentation.
help user-defined
List all user-defined commands, with the first line of the documentation (if any)
for each.
show user
show user commandname
Display the GDB commands used to define commandname (but not its documentation). If no commandname is given, display the definitions for all userdefined commands.
When user-defined commands are executed, the commands of the definition are not
printed. An error in any command stops execution of the user-defined command.
If used interactively, commands that would ask for confirmation proceed without asking
when used inside a user-defined command. Many GDB commands that normally print messages to say what they are doing omit the messages when used in a user-defined command.
253
If you try to define a hook which does not match any known command, GDB issues a
warning from the define command.
On DOS/Windows systems, the home directory is the one pointed to by the HOME environment variable.
254
The only backslash-escape sequences that you can use in the format string are
the simple ones that consist of backslash followed by a letter.
255
256
C-h m
M-s
Execute to another source line, like the GDB step command; also update the
display window to show the current file and location.
M-n
Execute to next source line in this function, skipping all function calls, like the
GDB next command. Then update the display window to show the current file
and location.
M-i
Execute one instruction, like the GDB stepi command; update display window
accordingly.
M-x gdb-nexti
Execute to next instruction, using the GDB nexti command; update display
window accordingly.
C-c C-f
Execute until exit from the selected stack frame, like the GDB finish command.
M-c
M-u
M-d
Go down the number of frames indicated by the numeric argument, like the
GDB down command.
Warning: In Emacs v19, this command is C-c C-d.
C-x &
Read the number where the cursor is positioned, and insert it at the end of
the GDB I/O buffer. For example, if you wish to disassemble code around an
address that was displayed earlier, type disassemble; then move the cursor to
the address display, and pick up the argument for disassemble by typing C-x
&.
You can customize this further by defining elements of the list gdb-printcommand; once it is defined, you can format or otherwise process numbers picked
up by C-x & before they are inserted. A numeric argument to C-x & indicates
that you wish special formatting, and also acts as an index to pick an element
of the list. If the list element is a string, the number to be inserted is formatted using the Emacs function format; otherwise the number is passed as an
argument to the corresponding list element.
In any source file, the Emacs command C-x SPC (gdb-break) tells GDB to set a breakpoint on the source line point is on.
If you accidentally delete the source-display buffer, an easy way to get it back is to type
the command f in the GDB buffer, to request a frame display; when you run under Emacs,
this recreates the source buffer if necessary to show you the context of the current frame.
The source files displayed in Emacs are in ordinary Emacs buffers which are visiting the
source files in the usual way. You can edit the files with these buffers if you wish; but keep
in mind that GDB communicates with Emacs in terms of line numbers. If you add or delete
lines from the text, the line numbers that GDB knows cease to correspond properly with
the code.
257
20 GDB Annotations
This chapter describes annotations in GDB. Annotations are designed to interface GDB
to graphical user interfaces or other similar programs which want to interact with GDB at
a relatively high level.
Here quit is input to GDB; the rest is output from GDB. The three lines beginning
^Z^Z (where ^Z denotes a control-z character) are annotations; the rest is output from
GDB.
258
The server prefix does not affect the recording of values into the value history; to print
a value without recording it into the value history, use the output command instead of the
print command.
20.3 Values
When a value is printed in various contexts, GDB uses annotations to delimit the value
from the surrounding text.
If a value is printed using print and added to the value history, the annotation looks
like
^Z^Zvalue-history-begin history-number value-flags
history-string
^Z^Zvalue-history-value
the-value
^Z^Zvalue-history-end
When GDB prints an argument to a function (for example, in the output from the
backtrace command), it annotates it as follows:
^Z^Zarg-begin
argument-name
^Z^Zarg-name-end
separator-string
^Z^Zarg-value value-flags
the-value
^Z^Zarg-end
where argument-name is the name of the argument, separator-string is text which separates the name from the value for the users benefit (such as =), and value-flags and
the-value have the same meanings as in a value-history-begin annotation.
When printing a structure, GDB annotates it as follows:
^Z^Zfield-begin value-flags
field-name
^Z^Zfield-name-end
separator-string
^Z^Zfield-value
the-value
^Z^Zfield-end
where field-name is the name of the field, separator-string is text which separates the
name from the value for the users benefit (such as =), and value-flags and the-value have
the same meanings as in a value-history-begin annotation.
When printing an array, GDB annotates it as follows:
259
where array-index is the index of the first element being annotated and value-flags has
the same meaning as in a value-history-begin annotation. This is followed by any
number of elements, where the element can be either a single element or a repeated element
as shown in the examples below:
, whitespace
; omitted for the first element
the-value
^Z^Zelt
, whitespace
; omitted for the first element
the-value
^Z^Zelt-rep number-of-repititions
repetition-string
^Z^Zelt-rep-end
In both cases, the-value is the output for the value of the element and whitespace can
contain spaces, tabs, and newlines. In the repeated case, number-of-repititons is the number
of consecutive array elements which contain that value, and repetition-string is a string
which is designed to convey to the user that repitition is being depicted.
Once all the array elements have been output, the array annotation is ended with
^Z^Zarray-section-end
20.4 Frames
Whenever GDB prints a frame, it annotates it. For example, this applies to frames
printed when GDB stops, output from commands such as backtrace or up, etc.
The frame annotation begins with
^Z^Zframe-begin level address
level-string
where level is the number of the frame (0 is the innermost frame, and other frames have
positive numbers), address is the address of the code executing in that frame, and levelstring is a string designed to convey the level to the user. address is in the form 0x followed
by one or more lowercase hex digits (note that this does not depend on the language). The
frame ends with
^Z^Zframe-end
Between these annotations is the main body of the frame, which can consist of
^Z^Zfunction-call
function-call-string
where function-call-string is text designed to convey to the user that this frame is
associated with a function call made by GDB to a function in the program being
debugged.
^Z^Zsignal-handler-caller
signal-handler-caller-string
where signal-handler-caller-string is text designed to convey to the user that this frame
is associated with whatever mechanism is used by this operating system to call a signal
handler (it is the frame which calls the signal handler, not the frame for the signal
handler itself).
260
A normal frame.
This can optionally (depending on whether this is thought of as interesting information
for the user to see) begin with
^Z^Zframe-address
address
^Z^Zframe-address-end
separator-string
where address is the address executing in the frame (the same address as in the framebegin annotation, but printed in a form which is intended for user consumptionin
particular, the syntax varies depending on the language), and separator-string is a
string intended to separate this address from what follows for the users benefit.
Then comes
^Z^Zframe-function-name
function-name
^Z^Zframe-args
arguments
where function-name is the name of the function executing in the frame, or ?? if not
known, and arguments are the arguments to the frame, with parentheses around them
(each argument is annotated individually as well, see Section 20.3 [Value Annotations],
page 258).
If source information is available, a reference to it is then printed:
^Z^Zframe-source-begin
source-intro-string
^Z^Zframe-source-file
filename
^Z^Zframe-source-file-end
:
^Z^Zframe-source-line
line-number
^Z^Zframe-source-end
where source-intro-string separates for the users benefit the reference from the text
which precedes it, filename is the name of the source file, and line-number is the line
number within that file (the first line is line 1).
If GDB prints some information about where the frame is from (which library, which
load segment, etc.; currently only done on the RS/6000), it is annotated with
^Z^Zframe-where
information
Then, if source is to be actually displayed for this frame (for example, this is not true
for output from the backtrace command), then a source annotation (see Section 20.11
[Source Annotations], page 264) is displayed. Unlike most annotations, this is output
instead of the normal text which would be output, not in addition.
20.5 Displays
When GDB is told to display something using the display command, the results of the
display are annotated:
^Z^Zdisplay-begin
number
261
^Z^Zdisplay-number-end
number-separator
^Z^Zdisplay-format
format
^Z^Zdisplay-expression
expression
^Z^Zdisplay-expression-end
expression-separator
^Z^Zdisplay-value
value
^Z^Zdisplay-end
where number is the number of the display, number-separator is intended to separate the
number from what follows for the user, format includes information such as the size, format,
or other information about how the value is being displayed, expression is the expression
being displayed, expression-separator is intended to separate the expression from the text
that follows for the user,and value is the actual value being displayed.
commands
When GDB prompts for a set of commands, like in the commands command.
The annotations are repeated for each command which is input.
overload-choice
When GDB wants the user to select between various overloaded functions.
query
prompt-for-continue
When GDB is asking the user to press return to continue. Note: Dont expect
this to work well; instead use set height 0 to disable prompting. This is
because the counting of lines is buggy in the presence of annotations.
20.7 Errors
^Z^Zquit
262
^Z^Zerror
Any output between that and the quit or error annotation is the error message.
Warning messages are not yet annotated.
where header-entry has the same syntax as an entry (see below) but instead of containing
data, it contains strings which are intended to convey the meaning of each field to the user.
This is followed by any number of entries. If a field does not apply for this entry, it is
omitted. Fields may contain trailing whitespace. Each entry consists of:
^Z^Zrecord
^Z^Zfield 0
number
^Z^Zfield 1
type
^Z^Zfield 2
disposition
^Z^Zfield 3
enable
^Z^Zfield 4
address
^Z^Zfield 5
what
^Z^Zfield 6
frame
^Z^Zfield 7
condition
^Z^Zfield 8
ignore-count
^Z^Zfield 9
commands
Note that address is intended for user consumptionthe syntax varies depending on the
language.
The output ends with
^Z^Zbreakpoints-table-end
263
is output. Before the stopped annotation, a variety of annotations describe how the
program stopped.
^Z^Zexited exit-status
The program exited, and exit-status is the exit status (zero for successful exit,
otherwise nonzero).
^Z^Zsignalled
The program exited with a signal. After the ^Z^Zsignalled, the annotation
continues:
intro-text
^Z^Zsignal-name
name
^Z^Zsignal-name-end
middle-text
^Z^Zsignal-string
string
^Z^Zsignal-string-end
end-text
where name is the name of the signal, such as SIGILL or SIGSEGV, and string is
the explanation of the signal, such as Illegal Instruction or Segmentation
fault. intro-text, middle-text, and end-text are for the users benefit and have
no particular format.
^Z^Zsignal
The syntax of this annotation is just like signalled, but GDB is just saying
that the program received the signal, not that it was terminated with it.
^Z^Zbreakpoint number
The program hit breakpoint number number.
^Z^Zwatchpoint number
The program hit watchpoint number number.
264
where filename is an absolute file name indicating which source file, line is the line
number within that file (where 1 is the first line in the file), character is the character
position within the file (where 0 is the first character in the file) (for most debug formats
this will necessarily point to the beginning of a line), middle is middle if addr is in the
middle of the line, or beg if addr is at the beginning of the line, and addr is the address
in the target program associated with the source which is being displayed. addr is in the
form 0x followed by one or more lowercase hex digits (note that this does not depend on
the language).
265
Acknowledgments
In alphabetic order: Andrew Cagney, Fernando Nasser, Stan Shebs and Elena Zannoni.
option 7
"-" parameter [ " " parameter ]
parameter 7
non-blank-sequence | c-string
266
operation 7
any of the operations described in this chapter
non-blank-sequence 7
anything, provided it doesnt contain special characters such as "-", nl, """ and
of course " "
c-string 7
""" seven-bit-iso-c-string-content """
nl 7
CR | CR-LF
Notes:
The CLI commands are still handled by the mi interpreter; their output is described
below.
The token , when present, is passed back when the command finishes.
Some mi commands accept optional arguments as part of the parameter list. Each
option is identified by a leading - (dash) and may be followed by an optional argument
parameter. Options occur first in the parameter list and can be delimited from normal
parameters using -- (this is useful when some parameters begin with a dash).
Pragmatics:
We want easy access to the existing CLI syntax (for debugging).
We want it to be easy to spot a mi operation.
267
async-output 7
async-class ( "," result )* nl
result-class 7
"done" | "running" | "connected" | "error" | "exit"
async-class 7
"stopped" | others (where others will be added depending on the needsthis
is still in development).
result 7
variable "=" value
variable 7
string
value 7
const 7
tuple 7
list 7
"[]" | "[" value ( "," value )* "]" | "[" result ( "," result )* "]"
stream-record 7
console-stream-output | target-stream-output | log-stream-output
console-stream-output 7
"~" c-string
target-stream-output 7
"@" c-string
log-stream-output 7
"&" c-string
nl 7
CR | CR-LF
token 7
Notes:
All output sequences end in a single line containing a period.
The token is from the corresponding request. If an execution command is interrupted
by the -exec-interrupt command, the token associated with the *stopped message
is the one of the original execution command, not the one of the interrupt command.
status-async-output contains on-going status information about the progress of a slow
operation. It can be discarded. All status output is prefixed by +.
exec-async-output contains asynchronous state change on the target (stopped, started,
disappeared). All async output is prefixed by *.
notify-async-output contains supplementary information that the client should handle
(e.g., a new breakpoint information). All notify output is prefixed by =.
console-stream-output is output that should be displayed as is in the console. It is the
textual response to a CLI command. All the console output is prefixed by ~.
268
target-stream-output is the output produced by the target program. All the target
output is prefixed by @.
log-stream-output is output text coming from GDBs internals, for instance messages
that should be displayed as part of an error log. All the log output is prefixed by &.
New gdb/mi commands should only output lists containing values.
See Section 21.3.2 [gdb/mi Stream Records], page 269, for more details about the various
output records.
Evaluate expression
Here is an example to evaluate an expression:
->
<<<-
-data-evaluate-expression 2+3
(gdb)
^done,value="5"
(gdb)
and later:
<- *stop,reason="stop",address="0x123",source="a.c:123"
<- (gdb)
print 1+2
&"print 1+2\n"
~"$1 = 3\n"
^done
(gdb)
A bad command
Here is what happens if you pass a bad command:
-> -rubbish
<- ^error,msg="Undefined MI command: rubbish"
<- (gdb)
269
270
Motivation
The motivation for this collection of commands.
Introduction
A brief introduction to this collection of commands as a whole.
Commands
For each command in the block, the following is described:
Synopsis
-command args ...
GDB command
The corresponding GDB CLI command.
Result
Out-of-band
Notes
271
Example
GDB command
The corresponding GDB command is ignore.
Example
(gdb)
-break-insert main
^done,bkpt=number="1",type="breakpoint",disp="keep",enabled="y",
addr="0x000100d0",func="main",file="hello.c",line="5",times="0"(gdb)
-break-after 1 3
~
^done
(gdb)
-break-list
^done,BreakpointTable={nr_rows="1",nr_cols="6",
hdr=[{width="3",alignment="-1",col_name="number",colhdr="Num"},
{width="14",alignment="-1",col_name="type",colhdr="Type"},
{width="4",alignment="-1",col_name="disp",colhdr="Disp"},
{width="3",alignment="-1",col_name="enabled",colhdr="Enb"},
{width="10",alignment="-1",col_name="addr",colhdr="Address"},
{width="40",alignment="2",col_name="what",colhdr="What"}],
body=[bkpt={number="1",type="breakpoint",disp="keep",enabled="y",
addr="0x000100d0",func="main",file="hello.c",line="5",times="0",
ignore="3"}]}
(gdb)
272
Synopsis
-break-condition number expr
Breakpoint number will stop the program only if the condition in expr is true. The condition becomes part of the -break-list output (see the description of the -break-list
command below).
GDB command
The corresponding GDB command is condition.
Example
(gdb)
-break-condition 1 1
^done
(gdb)
-break-list
^done,BreakpointTable={nr_rows="1",nr_cols="6",
hdr=[{width="3",alignment="-1",col_name="number",colhdr="Num"},
{width="14",alignment="-1",col_name="type",colhdr="Type"},
{width="4",alignment="-1",col_name="disp",colhdr="Disp"},
{width="3",alignment="-1",col_name="enabled",colhdr="Enb"},
{width="10",alignment="-1",col_name="addr",colhdr="Address"},
{width="40",alignment="2",col_name="what",colhdr="What"}],
body=[bkpt={number="1",type="breakpoint",disp="keep",enabled="y",
addr="0x000100d0",func="main",file="hello.c",line="5",cond="1",
times="0",ignore="3"}]}
(gdb)
GDB command
The corresponding GDB command is delete.
Example
(gdb)
273
-break-delete 1
^done
(gdb)
-break-list
^done,BreakpointTable={nr_rows="0",nr_cols="6",
hdr=[{width="3",alignment="-1",col_name="number",colhdr="Num"},
{width="14",alignment="-1",col_name="type",colhdr="Type"},
{width="4",alignment="-1",col_name="disp",colhdr="Disp"},
{width="3",alignment="-1",col_name="enabled",colhdr="Enb"},
{width="10",alignment="-1",col_name="addr",colhdr="Address"},
{width="40",alignment="2",col_name="what",colhdr="What"}],
body=[]}
(gdb)
Synopsis
-break-disable ( breakpoint )+
Disable the named breakpoint(s). The field enabled in the break list is now set to n
for the named breakpoint(s).
GDB command
The corresponding GDB command is disable.
Example
(gdb)
-break-disable 2
^done
(gdb)
-break-list
^done,BreakpointTable={nr_rows="1",nr_cols="6",
hdr=[{width="3",alignment="-1",col_name="number",colhdr="Num"},
{width="14",alignment="-1",col_name="type",colhdr="Type"},
{width="4",alignment="-1",col_name="disp",colhdr="Disp"},
{width="3",alignment="-1",col_name="enabled",colhdr="Enb"},
{width="10",alignment="-1",col_name="addr",colhdr="Address"},
{width="40",alignment="2",col_name="what",colhdr="What"}],
body=[bkpt={number="2",type="breakpoint",disp="keep",enabled="n",
addr="0x000100d0",func="main",file="hello.c",line="5",times="0"}]}
(gdb)
274
Synopsis
-break-enable ( breakpoint )+
Enable (previously disabled) breakpoint(s).
GDB command
The corresponding GDB command is enable.
Example
(gdb)
-break-enable 2
^done
(gdb)
-break-list
^done,BreakpointTable={nr_rows="1",nr_cols="6",
hdr=[{width="3",alignment="-1",col_name="number",colhdr="Num"},
{width="14",alignment="-1",col_name="type",colhdr="Type"},
{width="4",alignment="-1",col_name="disp",colhdr="Disp"},
{width="3",alignment="-1",col_name="enabled",colhdr="Enb"},
{width="10",alignment="-1",col_name="addr",colhdr="Address"},
{width="40",alignment="2",col_name="what",colhdr="What"}],
body=[bkpt={number="2",type="breakpoint",disp="keep",enabled="y",
addr="0x000100d0",func="main",file="hello.c",line="5",times="0"}]}
(gdb)
Synopsis
-break-info breakpoint
Get information about a single breakpoint.
GDB command
The corresponding GDB command is info break breakpoint .
Example
N.A.
275
Synopsis
-break-insert [ -t ] [ -h ] [ -r ]
[ -c condition ] [ -i ignore-count ]
[ -p thread ] [ line | addr ]
If specified, line, can be one of:
function
filename:linenum
filename:function
*address
The possible optional parameters of this command are:
-t
-h
-c condition
Make the breakpoint conditional on condition.
-i ignore-count
Initialize the ignore-count.
-r
Insert a regular breakpoint in all the functions whose names match the given
regular expression. Other flags are not applicable to regular expression.
Result
The result is in the form:
^done,bkptno="number ",func="funcname ",
file="filename ",line="lineno "
where number is the GDB number for this breakpoint, funcname is the name of the function
where the breakpoint was inserted, filename is the name of the source file which contains
this function, and lineno is the source line number within that file.
Note: this format is open to change.
GDB command
The corresponding GDB commands are break, tbreak, hbreak, thbreak, and
rbreak.
Example
(gdb)
-break-insert main
^done,bkpt=number="1",type="breakpoint",disp="keep",enabled="y",addr="0x0001072c",
file="recursive2.c",line="4",times="0"
(gdb)
-break-insert -t foo
276
^done,bkpt=number="2",type="breakpoint",disp="keep",enabled="y",addr="0x00010774",
file="recursive2.c",line="11",times="0"(gdb)
-break-list
^done,BreakpointTable={nr_rows="2",nr_cols="6",
hdr=[{width="3",alignment="-1",col_name="number",colhdr="Num"},
{width="14",alignment="-1",col_name="type",colhdr="Type"},
{width="4",alignment="-1",col_name="disp",colhdr="Disp"},
{width="3",alignment="-1",col_name="enabled",colhdr="Enb"},
{width="10",alignment="-1",col_name="addr",colhdr="Address"},
{width="40",alignment="2",col_name="what",colhdr="What"}],
body=[bkpt={number="1",type="breakpoint",disp="keep",enabled="y",
addr="0x0001072c", func="main",file="recursive2.c",line="4",times="0"},
bkpt={number="2",type="breakpoint",disp="del",enabled="y",
addr="0x00010774",func="foo",file="recursive2.c",line="11",times="0"}]}
(gdb)
-break-insert -r foo.*
~int foo(int, int);
^done,bkpt={number="3",addr="0x00010774",file="recursive2.c",line="11"}
(gdb)
Type
Disposition
should the breakpoint be deleted or disabled when it is hit: keep or nokeep
Enabled
Address
What
logical location of the breakpoint, expressed by function name, file name, line
number
Times
GDB command
The corresponding GDB command is info break.
Example
(gdb)
-break-list
277
^done,BreakpointTable={nr_rows="2",nr_cols="6",
hdr=[{width="3",alignment="-1",col_name="number",colhdr="Num"},
{width="14",alignment="-1",col_name="type",colhdr="Type"},
{width="4",alignment="-1",col_name="disp",colhdr="Disp"},
{width="3",alignment="-1",col_name="enabled",colhdr="Enb"},
{width="10",alignment="-1",col_name="addr",colhdr="Address"},
{width="40",alignment="2",col_name="what",colhdr="What"}],
body=[bkpt={number="1",type="breakpoint",disp="keep",enabled="y",
addr="0x000100d0",func="main",file="hello.c",line="5",times="0"},
bkpt={number="2",type="breakpoint",disp="keep",enabled="y",
addr="0x00010114",func="foo",file="hello.c",line="13",times="0"}]}
(gdb)
GDB command
The corresponding GDB commands are watch, awatch, and rwatch.
Example
Setting a watchpoint on a variable in the main function:
(gdb)
-break-watch i
^done,wpt=number="2",exp="i"
(gdb)
-exec-continue
278
^running
(gdb)
*stopped,reason="watchpoint-trigger",wpt=number="2",exp="i",value=old="0",new="7"
,thread-id="1",frame=addr="0x000029c4",func="main",args=[],file="hello.c",line="8"
(gdb)
Setting a watchpoint on a variable local to a function. GDB will stop the program
execution twice: first for the variable changing value, then for the watchpoint going out of
scope.
(gdb)
-break-watch j
^done,wpt=number="2",exp="j"
(gdb)
-exec-continue
^running
(gdb)
*stopped,reason="watchpoint-trigger",wpt=number="2",exp="j",value=old="0",new="17",
thread-id="1",frame=addr="0x000029bc",func="call",args=[],file="hello.c",line="10"
(gdb)
-exec-continue
^running
(gdb)
*stopped,reason="watchpoint-scope",wpnum="2",thread-id="1",frame=addr="0x000029ec",
func="main",args=[],file="hello.c",line="18"
(gdb)
Listing breakpoints and watchpoints, at different points in the program execution. Note
that once the watchpoint goes out of scope, it is deleted.
-break-watch j
^done,wpt=number="2",exp="j"
(gdb)
-break-list
^done,BreakpointTable=nr_rows="2",nr_cols="6",hdr=[width="3",
alignment="-1",col_name="number",colhdr="Num",width="14",alignment="-1",
col_name="type",colhdr"Type",width="4",alignment="-1",col_name="disp",
colhdr="Disp",width="3",alinment="-1",col_name="enabled",colhdr="Enb",
width="10",alignment="-1",col_name"addr",colhdr="Address",
width="40",alignment="2",col_name="what",colhdr="What],body=[bkpt=number="1",
type="breakpoint",disp="keep",enabled="y",addr="0x00029b4",func="call",
file="hello.c",line="9",times="1",bkpt=number="2",type="wathpoint",disp="keep",
enabled="y",addr="",what="j",times="0"]
(gdb)
-exec-continue
^running
(gdb)
*stopped,reason="watchpoint-trigger",wpt=number="2",exp="j",value=old="0",ne="17",
thread-id="1",frame=addr="0x000029bc",func="call",args=[],file="hello.c,line="10"
(gdb)
-break-list
^done,BreakpointTable=nr_rows="2",nr_cols="6",hdr=[width="3",alignment="-1",
col_name="number",colhdr="Num",width="14",alignment="-1",col_name="type",colhdr"Type",
width="4",alignment="-1",col_name="disp",colhdr="Disp",width="3",alinment="-1",
col_name="enabled",colhdr="Enb",width="10",alignment="-1",col_name"addr",colhdr="Address",
width="40",alignment="2",col_name="what",colhdr="What],body=[bkpt=number="1",
type="breakpoint",disp="keep",enabled="y",addr="0x00029b4",func="call",file="hello.c",
line="9",times="1",bkpt=number="2",type="wathpoint",disp="keep",enabled="y",addr="",
what="j",times="1"]
(gdb)
279
-exec-continue
^running
(gdb)
*stopped,reason="watchpoint-scope",wpnum="2",thread-id="1",frame=addr="0x000029ec",
func="main",args=[],file="hello.c",line="18"
(gdb)
-break-list
^done,BreakpointTable=nr_rows="1",nr_cols="6",hdr=[width="3",alignment="-1",
col_name="number",colhdr="Num",width="14",alignment="-1",col_name="type",colhdr="Type",
width="4",alignment="-1",col_name="disp",colhdr="Disp",width="3",alignment="-1",
col_name="enabled",colhdr="Enb",width="10",alignment="-1",col_name="addr",
colhdr="Address",width="40",alignment="2",col_name="what",colhdr="What"],
body=[bkpt=number="1",type="breakpoint",disp="keep",enabled="y",addr="0x000029b4",
func="call",file="hello.c",line="9",times="1"]
(gdb)
mode
280
Result
The output for each instruction is composed of four fields:
Address
Func-name
Offset
Instruction
Note that whatever included in the instruction field, is not manipulated directly by
gdb/mi, i.e. it is not possible to adjust its format.
GDB command
There is no direct mapping from this command to the CLI.
Example
Disassemble from the current value of $pc to $pc + 20:
(gdb)
-data-disassemble -s $pc -e "$pc + 20" -- 0
^done,
asm_insns=[
{address="0x000107c0",func-name="main",offset="4",
inst="mov 2, %o0"},
{address="0x000107c4",func-name="main",offset="8",
inst="sethi %hi(0x11800), %o2"},
{address="0x000107c8",func-name="main",offset="12",
inst="or %o2, 0x140, %o1\t! 0x11940 <_lib_version+8>"},
{address="0x000107cc",func-name="main",offset="16",
inst="sethi %hi(0x11800), %o2"},
{address="0x000107d0",func-name="main",offset="20",
inst="or %o2, 0x168, %o4\t! 0x11968 <_lib_version+48>"}]
(gdb)
281
GDB command
The corresponding GDB commands are print, output, and call. In gdbtk only,
theres a corresponding gdb_eval command.
Example
In the following example, the numbers that precede the commands are the tokens described in Section 21.1 [gdb/mi Command Syntax], page 265. Notice how gdb/mi returns
the same tokens in its output.
211-data-evaluate-expression A
211^done,value="1"
(gdb)
311-data-evaluate-expression &A
311^done,value="0xefffeb7c"
(gdb)
411-data-evaluate-expression A+3
282
411^done,value="4"
(gdb)
511-data-evaluate-expression "A + 3"
511^done,value="4"
(gdb)
Synopsis
-data-list-changed-registers
Display a list of the registers that have changed.
GDB command
GDB doesnot have a direct analog for this command; gdbtk has the corresponding
command gdb_changed_register_list.
Example
On a PPC MBX board:
(gdb)
-exec-continue
^running
(gdb)
*stopped,reason="breakpoint-hit",bkptno="1",frame={func="main",
args=[],file="try.c",line="5"}
(gdb)
-data-list-changed-registers
^done,changed-registers=["0","1","2","4","5","6","7","8","9",
"10","11","13","14","15","16","17","18","19","20","21","22","23",
"24","25","26","27","28","30","31","64","65","66","67","69"]
(gdb)
Synopsis
-data-list-register-names [ ( regno )+ ]
Show a list of register names for the current target. If no arguments are given, it shows a
list of the names of all the registers. If integer numbers are given as arguments, it will print
a list of the names of the registers corresponding to the arguments. To ensure consistency
between a register name and its number, the output list may include empty register names.
283
GDB command
GDB does not have a command which corresponds to -data-list-register-names.
In gdbtk there is a corresponding command gdb_regnames.
Example
For the PPC MBX board:
(gdb)
-data-list-register-names
^done,register-names=["r0","r1","r2","r3","r4","r5","r6","r7",
"r8","r9","r10","r11","r12","r13","r14","r15","r16","r17","r18",
"r19","r20","r21","r22","r23","r24","r25","r26","r27","r28","r29",
"r30","r31","f0","f1","f2","f3","f4","f5","f6","f7","f8","f9",
"f10","f11","f12","f13","f14","f15","f16","f17","f18","f19","f20",
"f21","f22","f23","f24","f25","f26","f27","f28","f29","f30","f31",
"", "pc","ps","cr","lr","ctr","xer"]
(gdb)
-data-list-register-names 1 2 3
^done,register-names=["r1","r2","r3"]
(gdb)
Hexadecimal
Octal
Binary
Decimal
Raw
Natural
GDB command
The corresponding GDB commands are info reg, info all-reg, and (in gdbtk)
gdb_fetch_registers.
284
Example
For a PPC MBX board (note: line breaks are for readability only, they donot appear in
the actual output):
(gdb)
-data-list-register-values r 64 65
^done,register-values=[{number="64",value="0xfe00a300"},
{number="65",value="0x00029002"}]
(gdb)
-data-list-register-values x
^done,register-values=[{number="0",value="0xfe0043c8"},
{number="1",value="0x3fff88"},{number="2",value="0xfffffffe"},
{number="3",value="0x0"},{number="4",value="0xa"},
{number="5",value="0x3fff68"},{number="6",value="0x3fff58"},
{number="7",value="0xfe011e98"},{number="8",value="0x2"},
{number="9",value="0xfa202820"},{number="10",value="0xfa202808"},
{number="11",value="0x1"},{number="12",value="0x0"},
{number="13",value="0x4544"},{number="14",value="0xffdfffff"},
{number="15",value="0xffffffff"},{number="16",value="0xfffffeff"},
{number="17",value="0xefffffed"},{number="18",value="0xfffffffe"},
{number="19",value="0xffffffff"},{number="20",value="0xffffffff"},
{number="21",value="0xffffffff"},{number="22",value="0xfffffff7"},
{number="23",value="0xffffffff"},{number="24",value="0xffffffff"},
{number="25",value="0xffffffff"},{number="26",value="0xfffffffb"},
{number="27",value="0xffffffff"},{number="28",value="0xf7bfffff"},
{number="29",value="0x0"},{number="30",value="0xfe010000"},
{number="31",value="0x0"},{number="32",value="0x0"},
{number="33",value="0x0"},{number="34",value="0x0"},
{number="35",value="0x0"},{number="36",value="0x0"},
{number="37",value="0x0"},{number="38",value="0x0"},
{number="39",value="0x0"},{number="40",value="0x0"},
{number="41",value="0x0"},{number="42",value="0x0"},
{number="43",value="0x0"},{number="44",value="0x0"},
{number="45",value="0x0"},{number="46",value="0x0"},
{number="47",value="0x0"},{number="48",value="0x0"},
{number="49",value="0x0"},{number="50",value="0x0"},
{number="51",value="0x0"},{number="52",value="0x0"},
{number="53",value="0x0"},{number="54",value="0x0"},
{number="55",value="0x0"},{number="56",value="0x0"},
{number="57",value="0x0"},{number="58",value="0x0"},
{number="59",value="0x0"},{number="60",value="0x0"},
{number="61",value="0x0"},{number="62",value="0x0"},
{number="63",value="0x0"},{number="64",value="0xfe00a300"},
{number="65",value="0x29002"},{number="66",value="0x202f04b5"},
{number="67",value="0xfe0043b0"},{number="68",value="0xfe00b3e4"},
{number="69",value="0x20002b03"}]
(gdb)
285
If present, indicates that each row should include an ascii dump. The value
of aschar is used as a padding character when a byte is not a member of the
printable ascii character set (printable ascii characters are those whose code
is between 32 and 126, inclusively).
byte-offset
An offset to add to the address before fetching memory.
This command displays memory contents as a table of nr-rows by nr-cols words, each
word being word-size bytes. In total, nr-rows * nr-cols * word-size bytes are read
(returned as total-bytes). Should less than the requested number of bytes be returned
by the target, the missing words are identified using N/A. The number of bytes read from
the target is returned in nr-bytes and the starting address used to read memory in addr.
The address of the next/previous row or page is available in next-row and prev-row,
next-page and prev-page.
GDB command
The corresponding GDB command is x. gdbtk has gdb_get_mem memory read command.
Example
Read six bytes of memory starting at bytes+6 but then offset by -6 bytes. Format as
three rows of two columns. One byte per word. Display each word in hex.
(gdb)
9-data-read-memory -o -6 -- bytes+6 x 1 3 2
9^done,addr="0x00001390",nr-bytes="6",total-bytes="6",
next-row="0x00001396",prev-row="0x0000138e",next-page="0x00001396",
prev-page="0x0000138a",memory=[
{addr="0x00001390",data=["0x00","0x01"]},
{addr="0x00001392",data=["0x02","0x03"]},
{addr="0x00001394",data=["0x04","0x05"]}]
(gdb)
286
Read two bytes of memory starting at address shorts + 64 and display as a single word
formatted in decimal.
(gdb)
5-data-read-memory shorts+64 d 2 1 1
5^done,addr="0x00001510",nr-bytes="2",total-bytes="2",
next-row="0x00001512",prev-row="0x0000150e",
next-page="0x00001512",prev-page="0x0000150e",memory=[
{addr="0x00001510",data=["128"]}]
(gdb)
Read thirty two bytes of memory starting at bytes+16 and format as eight rows of four
columns. Include a string encoding with x used as the non-printable character.
(gdb)
4-data-read-memory bytes+16 x 1 8 4 x
4^done,addr="0x000013a0",nr-bytes="32",total-bytes="32",
next-row="0x000013c0",prev-row="0x0000139c",
next-page="0x000013c0",prev-page="0x00001380",memory=[
{addr="0x000013a0",data=["0x10","0x11","0x12","0x13"],ascii="xxxx"},
{addr="0x000013a4",data=["0x14","0x15","0x16","0x17"],ascii="xxxx"},
{addr="0x000013a8",data=["0x18","0x19","0x1a","0x1b"],ascii="xxxx"},
{addr="0x000013ac",data=["0x1c","0x1d","0x1e","0x1f"],ascii="xxxx"},
{addr="0x000013b0",data=["0x20","0x21","0x22","0x23"],ascii=" !\"#"},
{addr="0x000013b4",data=["0x24","0x25","0x26","0x27"],ascii="$%&"},
{addr="0x000013b8",data=["0x28","0x29","0x2a","0x2b"],ascii="()*+"},
{addr="0x000013bc",data=["0x2c","0x2d","0x2e","0x2f"],ascii=",-./"}]
(gdb)
GDB command
The corresponding GDB command is delete display.
Example
N.A.
GDB command
The corresponding GDB command is disable display.
Example
N.A.
GDB command
The corresponding GDB command is enable display.
Example
N.A.
GDB command
The corresponding GDB command is display.
Example
N.A.
287
288
Synopsis
-display-list
List the displays. Do not show the current values.
GDB command
The corresponding GDB command is info display.
Example
N.A.
GDB command
The corresponding GDB command is cd.
Example
(gdb)
-environment-cd /kwikemart/marge/ezannoni/flathead-dev/devo/gdb
^done
(gdb)
GDB command
The corresponding GDB command is dir.
Example
(gdb)
-environment-directory /kwikemart/marge/ezannoni/flathead-dev/devo/gdb
^done
(gdb)
GDB command
The corresponding GDB command is path.
Example
(gdb)
-environment-path /kwikemart/marge/ezannoni/flathead-dev/ppc-eabi/gdb
^done
(gdb)
GDB command
The corresponding GDB command is pwd.
Example
(gdb)
-environment-pwd
~Working directory /kwikemart/marge/ezannoni/flathead-dev/devo/gdb.
^done
(gdb)
289
290
Examples
Program exited normally:
(gdb)
-exec-run
^running
(gdb)
x = 55
*stopped,reason="exited-normally"
(gdb)
Another way the program can terminate is if it receives a signal such as SIGINT. In this
case, gdb/mi displays this:
(gdb)
*stopped,reason="exited-signalled",signal-name="SIGINT",
signal-meaning="Interrupt"
GDB command
The corresponding GDB command is kill.
Example
N.A.
291
GDB command
The corresponding GDB command is set args.
Example
Donot have one around.
GDB command
The corresponding GDB is continue.
Example
-exec-continue
^running
(gdb)
@Hello world
*stopped,reason="breakpoint-hit",bkptno="2",thread-id="1",frame=addr="0x000029d8",
func="foo",args=[],file="hello.c",line="16"file="hello.c",line="13"}
(gdb)
292
GDB command
The corresponding GDB command is finish.
Example
Function returning void.
-exec-finish
^running
(gdb)
@hello from foo
*stopped,reason="function-finished",thread-id="1",frame=addr="0x000029ec",
func="main",args=[],file="hello.c",line="7file="hello.c",line="7"}
(gdb)
Function returning other than void. The name of the internal GDB variable storing the
result is printed, together with the value itself.
-exec-finish
^running
(gdb)
*stopped,reason="function-finished",thread-id="1",
frame=addr="0x000107b0",func="foo",
args=[name="a"],name="b",
file="recursive2.c",line="14"},
gdb-result-var="$1",return-value="0"
(gdb)
GDB command
The corresponding GDB command is interrupt.
Example
(gdb)
111-exec-continue
111^running
293
(gdb)
222-exec-interrupt
222^done
(gdb)
111*stopped,signal-name="SIGINT",signal-meaning="Interrupt",
frame={addr="0x00010140",func="foo",args=[],file="try.c",line="13"}
(gdb)
(gdb)
-exec-interrupt
^error,msg="mi_cmd_exec_interrupt: Inferior not executing."
(gdb)
GDB command
The corresponding GDB command is next.
Example
-exec-next
^running
(gdb)
*stopped,reason="end-stepping-range",thread-id="1",frame=addr="0x00002a10",
func="main",args=[],file="hello.c",line="24"(gdb)
GDB command
The corresponding GDB command is nexti.
294
Example
(gdb)
-exec-next-instruction
^running
(gdb)
*stopped,reason="end-stepping-range",threadid="1",frame=addr="0x00002a14",func="main",args=[],file="hello.c",line="24"
(gdb)
GDB command
The corresponding GDB command is return.
Example
(gdb)
-break-insert call1
^done,bkpt=number="1",type="breakpoint",disp="keep",enabled="y",addr="0x000029ac",
func="call1",file="hello.c",line="9",times="0"
(gdb)
-exec-run
^running
(gdb)
~"3"
*stopped,reason="breakpoint-hit",bkptno="1",thread-id="1",frame=addr="0x000029ac",
func="call1",args=[name="a"],file="hello.c",line="9"
(gdb)
-exec-return
~"2"
~"3"
^done,frame=level="0 ",addr="0x000029e8",func="call",args=[name="a",name="b"],
file="hello.c",line="17"
(gdb)
295
Asynchronous command. Starts execution of the inferior from the beginning. The
inferior executes until either a breakpoint is encountered or the program exits.
GDB command
The corresponding GDB command is run.
Example
(gdb)
-break-insert main
^done,bkpt=number="1",type="breakpoint",disp="keep",enabled="y",addr="0x00002a08",
func="main",file="hello.c",line="23",times="0"
(gdb)
-exec-run
^running
(gdb)
*stopped,reason="breakpoint-hit",bkptno="1",thread-id="1",frame=addr="0x00002a08",
func="main",args=[],file="hello.c",line="23"
(gdb)
GDB command
The corresponding GDB command is show args.
Example
N.A.
296
GDB command
The corresponding GDB command is step.
Example
Stepping into a function:
-exec-step
^running
(gdb)
~"2"
~"3"
*stopped,reason="end-stepping-range",thread-id="1",frame=addr="0x000029d0",
func="call",args=[name="a",name="b"],file="hello.c",line="15"
(gdb)
Regular stepping:
-exec-step
^running
(gdb)
~"2"
~"3"
*stopped,reason="end-stepping-range",thread-id="1",frame=addr="0x000029d8",
func="call",args=[name="a",name="b"],file="hello.c",line="16"
(gdb)
GDB command
The corresponding GDB command is stepi.
Example
(gdb)
-exec-step-instruction
^running
(gdb)
~"2"
~"3"
*stopped,reason="end-stepping-range",thread-id="1",frame=addr="0x000029dc",
func="call",args=[name="a",name="b"],file="hello.c",line="16"
297
(gdb)
-exec-step-instruction
^running
(gdb)
*stopped,reason="end-stepping-range",
frame={addr="0x000100f4",func="foo",args=[],file="try.c",line="10"}
(gdb)
GDB command
The corresponding GDB command is until.
Example
(gdb)
-exec-until recursive2.c:6
^running
(gdb)
x = 55
*stopped,reason="location-reached",thread-id="1",frame=addr="0x00002a24",func="main",args=[],
file="recursive2.c",line="6"
(gdb)
GDB command
The corresponding GDB command is file.
298
Example
(gdb)
-file-exec-and-symbols /kwikemart/marge/ezannoni/TRUNK/mbx/hello.mbx
^done
(gdb)
GDB command
The corresponding GDB command is exec-file.
Example
(gdb)
-file-exec-file /kwikemart/marge/ezannoni/TRUNK/mbx/hello.mbx
^done
(gdb)
GDB command
The GDB command info file shows, among the rest, the same information as this
command. gdbtk has a corresponding command gdb_load_info.
Example
N.A.
299
Synopsis
-file-list-exec-source-files
List the source files for the current executable.
GDB command
Theres no GDB command which directly corresponds to this one. gdbtk has an analogous command gdb_listfiles.
Example
N.A.
GDB command
The corresponding GDB command is info shared.
Example
N.A.
GDB command
The corresponding GDB command is info file (part of it).
Example
N.A.
300
GDB command
The corresponding GDB command is symbol-file.
Example
(gdb)
-file-symbol-file /kwikemart/marge/ezannoni/TRUNK/mbx/hello.mbx
^done
(gdb)
GDB command
Approximately corresponds to quit.
Example
(gdb)
-gdb-exit
GDB command
The corresponding GDB command is set.
Example
(gdb)
-gdb-set $foo=3
^done
(gdb)
GDB command
The corresponding GDB command is show.
Example
(gdb)
-gdb-show annotate
^done,value="0"
(gdb)
GDB command
The corresponding GDB command is show version.
Example
(gdb)
-gdb-version
~GNU gdb 5.2.1
~Copyright 2000 Free Software Foundation, Inc.
301
302
~GDB is free software, covered by the GNU General Public License, and
~you are welcome to change it and/or distribute copies of it under
~ certain conditions.
~Type "show copying" to see the conditions.
~There is absolutely no warranty for GDB. Type "show warranty" for
~ details.
~This GDB was configured as
"--host=sparc-sun-solaris2.5.1 --target=ppc-eabi".
^done
(gdb)
Synopsis
-stack-info-frame
Get info on the current frame.
GDB command
The corresponding GDB command is info frame or frame (without arguments).
Example
N.A.
Synopsis
-stack-info-depth [ max-depth ]
Return the depth of the stack. If the integer argument max-depth is specified, do not
count beyond max-depth frames.
GDB command
There no equivalent GDB command.
303
Example
For a stack with frame levels 0 through 11:
(gdb)
-stack-info-depth
^done,depth="12"
(gdb)
-stack-info-depth
^done,depth="4"
(gdb)
-stack-info-depth
^done,depth="12"
(gdb)
-stack-info-depth
^done,depth="11"
(gdb)
-stack-info-depth
^done,depth="12"
(gdb)
12
11
13
GDB command
GDB does not have an equivalent command. gdbtk has a gdb_get_args command
which partially overlaps with the functionality of -stack-list-arguments.
Example
(gdb)
-stack-list-frames
^done,
stack=[
frame={level="0 ",addr="0x00010734",func="callee4",
file="../../../devo/gdb/testsuite/gdb.mi/basics.c",line="8"},
frame={level="1 ",addr="0x0001076c",func="callee3",
file="../../../devo/gdb/testsuite/gdb.mi/basics.c",line="17"},
304
frame={level="2 ",addr="0x0001078c",func="callee2",
file="../../../devo/gdb/testsuite/gdb.mi/basics.c",line="22"},
frame={level="3 ",addr="0x000107b4",func="callee1",
file="../../../devo/gdb/testsuite/gdb.mi/basics.c",line="27"},
frame={level="4 ",addr="0x000107e0",func="main",
file="../../../devo/gdb/testsuite/gdb.mi/basics.c",line="32"}]
(gdb)
-stack-list-arguments 0
^done,
stack-args=[
frame={level="0",args=[]},
frame={level="1",args=[name="strarg"]},
frame={level="2",args=[name="intarg",name="strarg"]},
frame={level="3",args=[name="intarg",name="strarg",name="fltarg"]},
frame={level="4",args=[]}]
(gdb)
-stack-list-arguments 1
^done,
stack-args=[
frame={level="0",args=[]},
frame={level="1",
args=[{name="strarg",value="0x11940 \"A string argument.\""}]},
frame={level="2",args=[
{name="intarg",value="2"},
{name="strarg",value="0x11940 \"A string argument.\""}]},
{frame={level="3",args=[
{name="intarg",value="2"},
{name="strarg",value="0x11940 \"A string argument.\""},
{name="fltarg",value="3.5"}]},
frame={level="4",args=[]}]
(gdb)
-stack-list-arguments 0 2 2
^done,stack-args=[frame={level="2",args=[name="intarg",name="strarg"]}]
(gdb)
-stack-list-arguments 1 2 2
^done,stack-args=[frame={level="2",
args=[{name="intarg",value="2"},
{name="strarg",value="0x11940 \"A string argument.\""}]}]
(gdb)
305
level
The frame number, 0 being the topmost frame, i.e. the innermost function.
addr
func
Function name.
file
line
If invoked without arguments, this command prints a backtrace for the whole stack. If
given two integer arguments, it shows the frames whose levels are between the two arguments
(inclusive). If the two arguments are equal, it shows the single frame at the corresponding
level.
GDB command
The corresponding GDB commands are backtrace and where.
Example
Full stack backtrace:
(gdb)
-stack-list-frames
^done,stack=
[frame={level="0 ",addr="0x0001076c",func="foo",
file="recursive2.c",line="11"},
frame={level="1 ",addr="0x000107a4",func="foo",
file="recursive2.c",line="14"},
frame={level="2 ",addr="0x000107a4",func="foo",
file="recursive2.c",line="14"},
frame={level="3 ",addr="0x000107a4",func="foo",
file="recursive2.c",line="14"},
frame={level="4 ",addr="0x000107a4",func="foo",
file="recursive2.c",line="14"},
frame={level="5 ",addr="0x000107a4",func="foo",
file="recursive2.c",line="14"},
frame={level="6 ",addr="0x000107a4",func="foo",
file="recursive2.c",line="14"},
frame={level="7 ",addr="0x000107a4",func="foo",
file="recursive2.c",line="14"},
frame={level="8 ",addr="0x000107a4",func="foo",
file="recursive2.c",line="14"},
frame={level="9 ",addr="0x000107a4",func="foo",
file="recursive2.c",line="14"},
frame={level="10",addr="0x000107a4",func="foo",
file="recursive2.c",line="14"},
frame={level="11",addr="0x00010738",func="main",
file="recursive2.c",line="4"}]
(gdb)
306
file="recursive2.c",line="14"},
frame={level="4 ",addr="0x000107a4",func="foo",
file="recursive2.c",line="14"},
frame={level="5 ",addr="0x000107a4",func="foo",
file="recursive2.c",line="14"}]
(gdb)
GDB Command
info locals in GDB, gdb_get_locals in gdbtk.
Example
(gdb)
-stack-list-locals 0
^done,locals=[name="A",name="B",name="C"]
(gdb)
-stack-list-locals 1
^done,locals=[{name="A",value="1"},{name="B",value="2"},
{name="C",value="3"}]
(gdb)
GDB command
The corresponding GDB commands are frame, up, down, select-frame,
up-silent, and down-silent.
Example
(gdb)
-stack-select-frame 2
^done
(gdb)
GDB command
The corresponding GDB command is info address.
Example
N.A.
GDB command
There is no equivalent GDB command. gdbtk has gdb_find_file.
Example
N.A.
307
308
Synopsis
-symbol-info-function
Show which function the symbol lives in.
GDB command
gdb_get_function in gdbtk.
Example
N.A.
GDB command
The corresponding GDB comamnd is info line. gdbtk has the gdb_get_line and
gdb_get_file commands.
Example
N.A.
GDB command
The corresponding GDB command is info symbol.
Example
N.A.
GDB command
info functions in GDB, gdb_listfunc and gdb_search in gdbtk.
Example
N.A.
GDB command
The corresponding commands are info types in GDB, gdb_search in gdbtk.
Example
N.A.
GDB command
info variables in GDB, gdb_search in gdbtk.
309
310
Example
N.A.
GDB command
gdb_loc in gdbtk.
Example
N.A.
GDB command
The corresponding GDB command is ptype, gdbtk has gdb_obj_variable.
Example
N.A.
311
GDB command
The corresponding GDB command is attach.
Example
N.A.
GDB command
The GDB equivalent is compare-sections.
Example
N.A.
GDB command
The corresponding GDB command is detach.
Example
(gdb)
-target-detach
^done
(gdb)
312
Synopsis
-target-download
Loads the executable onto the remote target. It prints out an update message every half
second, which includes the fields:
section
section-sent
The size of what has been sent so far for that section.
section-size
The size of the section.
total-sent
The total size of what was sent so far (the current and the previous sections).
total-size
The size of the overall executable to download.
Each message is sent as status record (see Section 21.1.2 [gdb/mi Output Syntax], page 266).
In addition, it prints the name and size of the sections, as they are downloaded. These
messages include the following fields:
section
section-size
The size of the section.
total-size
The size of the overall executable to download.
At the end, a summary is printed.
GDB command
The corresponding GDB command is load.
Example
Note: each status message appears on a single line. Here the messages have been broken
down so that they can fit onto a page.
(gdb)
-target-download
+download,{section=".text",section-size="6668",total-size="9880"}
+download,{section=".text",section-sent="512",section-size="6668",
total-sent="512",total-size="9880"}
+download,{section=".text",section-sent="1024",section-size="6668",
total-sent="1024",total-size="9880"}
+download,{section=".text",section-sent="1536",section-size="6668",
total-sent="1536",total-size="9880"}
+download,{section=".text",section-sent="2048",section-size="6668",
total-sent="2048",total-size="9880"}
+download,{section=".text",section-sent="2560",section-size="6668",
313
total-sent="2560",total-size="9880"}
+download,{section=".text",section-sent="3072",section-size="6668",
total-sent="3072",total-size="9880"}
+download,{section=".text",section-sent="3584",section-size="6668",
total-sent="3584",total-size="9880"}
+download,{section=".text",section-sent="4096",section-size="6668",
total-sent="4096",total-size="9880"}
+download,{section=".text",section-sent="4608",section-size="6668",
total-sent="4608",total-size="9880"}
+download,{section=".text",section-sent="5120",section-size="6668",
total-sent="5120",total-size="9880"}
+download,{section=".text",section-sent="5632",section-size="6668",
total-sent="5632",total-size="9880"}
+download,{section=".text",section-sent="6144",section-size="6668",
total-sent="6144",total-size="9880"}
+download,{section=".text",section-sent="6656",section-size="6668",
total-sent="6656",total-size="9880"}
+download,{section=".init",section-size="28",total-size="9880"}
+download,{section=".fini",section-size="28",total-size="9880"}
+download,{section=".data",section-size="3156",total-size="9880"}
+download,{section=".data",section-sent="512",section-size="3156",
total-sent="7236",total-size="9880"}
+download,{section=".data",section-sent="1024",section-size="3156",
total-sent="7748",total-size="9880"}
+download,{section=".data",section-sent="1536",section-size="3156",
total-sent="8260",total-size="9880"}
+download,{section=".data",section-sent="2048",section-size="3156",
total-sent="8772",total-size="9880"}
+download,{section=".data",section-sent="2560",section-size="3156",
total-sent="9284",total-size="9880"}
+download,{section=".data",section-sent="3072",section-size="3156",
total-sent="9796",total-size="9880"}
^done,address="0x10004",load-size="9880",transfer-rate="6586",
write-rate="429"
(gdb)
GDB command
There is no equivalent GDB command.
Example
N.A.
314
Synopsis
-target-list-available-targets
List the possible targets to connect to.
GDB command
The corresponding GDB command is help target.
Example
N.A.
GDB command
The corresponding information is printed by info file (among other things).
Example
N.A.
GDB command
No equivalent.
Example
N.A.
315
parameters
Device names, host names and the like. See Section 13.2 [Commands for managing targets], page 109, for more details.
The output is a connection notification, followed by the address at which the target
program is, in the following form:
^connected,addr="address ",func="function name ",
args=[arg list ]
GDB command
The corresponding GDB command is target.
Example
(gdb)
-target-select async /dev/ttya
^connected,addr="0xfe00a300",func="??",args=[]
(gdb)
GDB command
No equivalent.
Example
N.A.
316
GDB command
The equivalent GDB command is info threads.
Example
N.A.
GDB command
Part of info threads supplies the same information.
Example
No threads present, besides the main process:
(gdb)
-thread-list-ids
^done,thread-ids={},number-of-threads="0"
(gdb)
Several threads:
(gdb)
-thread-list-ids
^done,thread-ids={thread-id="3",thread-id="2",thread-id="1"},
number-of-threads="3"
(gdb)
317
Synopsis
-thread-select threadnum
Make threadnum the current thread. It prints the number of the new current thread,
and the topmost frame for that thread.
GDB command
The corresponding GDB command is thread.
Example
(gdb)
-exec-next
^running
(gdb)
~"0x7f7f0aec"
*stopped,reason="end-stepping-range",thread-id="2",frame=addr="0x00002ca4",func
="printme",args=[name="ip"],file="multithread.c",line="9"
(gdb)
-thread-list-ids
^done,thread-ids=thread-id="2",thread-id="1",number-of-threads="2"
(gdb)
-thread-select 1
^done,new-thread-id="1",frame=level="0 ",addr="0x7ad47d70",func="_lwp_create","
+0x10",args=[],from="/usr/lib/libpthread.1"
(gdb)
318
-gdb-show output-radix
-stack-list-arguments
-stack-list-locals
-stack-select-frame
Description
-var-create
-var-delete
-var-set-format
-var-show-format
-var-info-num-children
-var-list-children
-var-info-type
-var-info-expression
-var-show-attributes
-var-evaluate-expression
-var-assign
-var-update
update the variable and its children
In the next subsection we describe each operation in detail and suggest how it can be
used.
319
Synopsis
-var-create {name | "-"}
{frame-addr | "*"} expression
This operation creates a variable object, which allows the monitoring of a variable, the
result of an expression, a memory cell or a CPU register.
The name parameter is the string by which the object can be referenced. It must
be unique. If - is specified, the varobj system will generate a string varNNNNNN
automatically. It will be unique provided that one does not specify name on that format.
The command fails if a duplicate name is found.
The frame under which the expression should be evaluated can be specified by frameaddr. A * indicates that the current frame should be used.
expression is any expression valid on the current language set (must not begin with a
*), or one of the following:
*addr , where addr is the address of a memory cell
*addr-addr a memory address range (TBD)
$regname a CPU register name
Result
This operation returns the name, number of children and the type of the object created.
Type is returned as a string as the ones generated by the GDB CLI:
name="name ",numchild="N",type="type "
320
321
Synopsis
-var-info-expression name
Returns what is represented by the variable object name:
lang=lang-spec,exp=expression
where lang-spec is {"C" | "C++" | "Java"}.
322
323
324
Sometimes people give a few sketchy facts and ask, Does this ring a bell? Those bug
reports are useless, and we urge everyone to refuse to respond to them except to chide the
sender to report bugs properly.
To enable us to fix the bug, you should include all these things:
The version of GDB. GDB announces it if you start with no arguments; you can also
print it at any time using show version.
Without this, we will not know whether there is any point in looking for the bug in the
current version of GDB.
The type of machine you are using, and the operating system name and version number.
What compiler (and its version) was used to compile the program you are debugging
e.g. HP92453-01 A.10.32.03 HP C Compiler. Use the what command with the
pathname of the compile command (what /opt/ansic/bin/cc, for example) to obtain
this information.
The command arguments you gave the compiler to compile your example and observe
the bug. For example, did you use -O? To guarantee you will not omit something
important, list them all. A copy of the Makefile (or the output from make) is sufficient.
If we were to try to guess the arguments, we would probably guess wrong and then we
might not encounter the bug.
A complete input script, and all necessary source files, that will reproduce the bug.
A description of what behavior you observe that you believe is incorrect. For example,
It gets a fatal signal.
Of course, if the bug is that GDB gets a fatal signal, then we will certainly notice it.
But if the bug is incorrect output, we might not notice unless it is glaringly wrong.
You might as well not give us a chance to make a mistake.
Even if the problem you experience is a fatal signal, you should still say so explicitly.
Suppose something strange is going on, such as, your copy of GDB is out of synch, or
you have encountered a bug in the C library on your system. (This has happened!)
Your copy might crash and ours would not. If you told us to expect a crash, then when
ours fails to crash, we would know that the bug was not happening for us. If you had
not told us to expect a crash, then we would not be able to draw any conclusion from
our observations.
Here are some things that are not necessary:
A description of the envelope of the bug.
Often people who encounter a bug spend a lot of time investigating which changes to
the input file will make the bug go away and which changes will not affect it.
This is often time consuming and not very useful, because the way we will find the
bug is by running a single example under the debugger with breakpoints, not by pure
deduction from a series of examples. We recommend that you save your time for
something else.
Of course, if you can find a simpler example to report instead of the original one, that
is a convenience for us. Errors in the output will be easier to spot, running under the
debugger will take less time, and so on.
However, simplification is not vital; if you do not want to do this, report the bug
anyway and send us the entire test case you used.
325
326
327
Alternatively, it is possible to build GDB from the source distribution. If you want to
modify the debugger sources to tailor GDB to your needs, you may wish to do this. The
source distribution consists of a tar file containing the source tree rooted at gdb-4.17/....
The instructions that follow describe how to build a gdb executable from this source
tree. HP believes that these instructions apply to the WDB source tree that it distributes.
However, HP does not explicitly support building a gdb for any non-HP platform from
the WDB source tree. It may work, but HP has not tested it for any platforms other than
those described in the WDB Release Notes.
You can find additional information specific to Hewlett-Packard in the README.HP.WDB
file at the root of the source tree.
GDB comes with a configure script that automates the process of preparing GDB for
installation; you can then use make to build the gdb program.1
The GDB distribution includes all the source code you need for GDB in a single directory,
whose name is usually composed by appending the version number to gdb.
For example, the GDB version gdb-199991101 distribution is in the gdb-gdb-199991101
directory. That directory contains:
gdb-gdb-199991101/configure (and supporting files)
script for configuring GDB and all its supporting libraries
gdb-gdb-199991101/gdb
the source specific to GDB itself
gdb-gdb-199991101/bfd
source for the Binary File Descriptor library
gdb-gdb-199991101/include
gnu include files
gdb-gdb-199991101/libiberty
source for the -liberty free software library
gdb-gdb-199991101/opcodes
source for the library of opcode tables and disassemblers
gdb-gdb-199991101/readline
source for the gnu command-line interface
1
If you have a more recent version of GDB than gdb-199991101, look at the README file in the sources;
we may have improved the installation procedures since publishing this manual.
328
gdb-gdb-199991101/glob
source for the gnu filename pattern-matching subroutine
gdb-gdb-199991101/mmalloc
source for the gnu memory-mapped malloc package
The simplest way to configure and build GDB is to run configure from the
gdb-version-number source directory, which in this example is the gdb-gdb-199991101
directory.
First switch to the gdb-version-number source directory if you are not already in it;
then run configure. Pass the identifier for the platform on which GDB will run as an
argument.
For example:
cd gdb-gdb-199991101
./configure host
make
where host is an identifier such as sun4 or decstation, that identifies the platform where
GDB will run. (You can often leave off host; configure tries to guess the correct value by
examining your system.)
Running configure host and then running make builds the bfd, readline,
mmalloc, and libiberty libraries, then gdb itself. The configured source files, and the
binaries, are left in the corresponding source directories.
configure is a Bourne-shell (/bin/sh) script; if your system does not recognize this
automatically when you run a different shell, you may need to run sh on it explicitly:
sh configure host
If you run configure from a directory that contains source directories for multiple
libraries or programs, such as the gdb-gdb-199991101 source directory for version gdb199991101, configure creates configuration files for every directory level underneath (unless
you tell it not to, with the --norecursion option).
You can run the configure script from any of the subordinate directories in the GDB
distribution if you only want to configure that subdirectory, but be sure to specify a path
to it.
For example, with version gdb-199991101, type the following to configure only the bfd
subdirectory:
cd gdb-gdb-199991101/bfd
../configure host
You can install gdb anywhere; it has no hardwired paths. However, you should make
sure that the shell on your path (named by the SHELL environment variable) is publicly
readable. Remember that GDB uses the shell to start your programsome systems refuse
to let GDB debug child processes whose programs are not readable.
329
easy by allowing you to generate each configuration in a separate subdirectory, rather than
in the source directory. If your make program handles the VPATH feature (gnu make does),
running make in each of these directories builds the gdb program specified there.
To build gdb in a separate directory, run configure with the --srcdir option to
specify where to find the source. (You also need to specify a path to find configure itself
from your working directory. If the path to configure would be the same as the argument
to --srcdir, you can leave out the --srcdir option; it is assumed.)
For example, with version gdb-199991101, you can build GDB in a separate directory
for a Sun 4 like this:
cd gdb-gdb-199991101
mkdir ../gdb-sun4
cd ../gdb-sun4
../gdb-gdb-199991101/configure sun4
make
When configure builds a configuration using a remote source directory, it creates a
tree for the binaries with the same structure (and using the same names) as the tree under
the source directory. In the example, youd find the Sun 4 library libiberty.a in the
directory gdb-sun4/libiberty, and GDB itself in gdb-sun4/gdb.
One popular reason to build several GDB configurations in separate directories is to
configure GDB for cross-compiling (where GDB runs on one machinethe hostwhile debugging programs that run on another machinethe target). You specify a cross-debugging
target by giving the --target=target option to configure.
When you run make to build a program or library, you must run it in a configured
directorywhatever directory you were in when you called configure (or one of its subdirectories).
The Makefile that configure generates in each source directory also runs recursively.
If you type make in a source directory such as gdb-gdb-199991101 (or in a separate
configured directory configured with --srcdir=dirname /gdb-gdb-199991101), you will
build all the required libraries, and then build GDB.
When you have multiple hosts or targets configured in separate directories, you can run
make on them in parallel (for example, if they are NFS-mounted on each of the hosts); they
will not interfere with each other.
330
config.sub to map abbreviations to full names; you can read the script, if you wish, or
you can use it to test your guesses on abbreviationsfor example:
% sh config.sub i386-linux
i386-pc-linux-gnu
% sh config.sub alpha-linux
alpha-unknown-linux-gnu
% sh config.sub hp9k700
hppa1.1-hp-hpux
% sh config.sub sun4
sparc-sun-sunos4.1.1
% sh config.sub sun3
m68k-sun-sunos4.1.1
% sh config.sub i986v
Invalid configuration i986v: machine i986v not recognized
--prefix=dir
Configure the source to install programs and files under directory dir .
--exec-prefix=dir
Configure the source to install programs under directory dir .
--srcdir=dirname
Warning: using this option requires gnu make, or another make that implements the VPATH feature.
Use this option to make configurations in directories separate from the GDB
source directories. Among other things, you can use this to build (or maintain)
several configurations simultaneously, in separate directories. configure writes
configuration specific files in the current directory, but arranges for them to use
the source in the directory dirname. configure creates directories under the
working directory in parallel to the source directories below dirname.
331
--norecursion
Configure only the directory level where configure is executed; do not propagate configuration to subdirectories.
--target=target
Configure GDB for cross-debugging programs running on the specified target.
Without this option, GDB is configured to debug programs that run on the
same machine (host) as GDB itself.
There is no convenient way to generate a list of all available targets.
host ...
There are many other options available as well, but they are generally needed for special
purposes only.
\enddocument
332
Index
333
Index
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 127
$
$ ...........................................
$$ . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
$, variable names starting with . . . . . . . . . . . . . . .
$_ and info breakpoints . . . . . . . . . . . . . . . . . . . .
$_ and info line . . . . . . . . . . . . . . . . . . . . . . . . . . . .
$_, $__, and value history . . . . . . . . . . . . . . . . . . . .
$_, convenience variable . . . . . . . . . . . . . . . . . . . . . .
$__, convenience variable . . . . . . . . . . . . . . . . . . . . .
$_exitcode, convenience variable . . . . . . . . . . . . .
$bpnum, convenience variable . . . . . . . . . . . . . . . . . .
$cdir, convenience variable . . . . . . . . . . . . . . . . . . .
$cwd, convenience variable . . . . . . . . . . . . . . . . . . . .
75
75
76
35
60
68
76
76
76
33
59
59
--annotate . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14
--async . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14
--batch . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13
--baud . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15
--cd . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14
--command . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12
--core . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12
--dbx . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14
--directory . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12
--epoch . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14
--exec . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12
--fullname . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14
--inline. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15
--interpreter . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15
--mapped. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12
--noasync . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15
--nowindows . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13
--nx . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13
--pid . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15
--quiet . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13
--readnow . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13
--se . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12
--silent. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13
--src_no_g . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15
--statistics . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15
--symbols . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12
--tty . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15
--tui . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15
--version . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15
--windows . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13
--write . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15
--xdb . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15
-b . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15
-break-after . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 245
-break-condition . . . . . . . . . . . . . . . . . . . . . . . . . . 245
-break-delete . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 246
-break-disable . . . . . . . . . . . . . . . . . . . . . . . . . . . . 247
-break-enable . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 247
-break-info . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 248
-break-insert . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 248
-break-list . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 250
-break-watch . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 251
-c . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12
-d . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12
-data-disassemble . . . . . . . . . . . . . . . . . . . . . . . . . 253
-data-evaluate-expression . . . . . . . . . . . . . . . . 255
-data-list-changed-registers . . . . . . . . . . . . . 256
-data-list-register-names . . . . . . . . . . . . . . . . 256
-data-list-register-values . . . . . . . . . . . . . . . 257
-data-read-memory . . . . . . . . . . . . . . . . . . . . . . . . . 258
-display-delete . . . . . . . . . . . . . . . . . . . . . . . . . . . 260
-display-disable . . . . . . . . . . . . . . . . . . . . . . . . . . 260
-display-enable . . . . . . . . . . . . . . . . . . . . . . . . . . . 261
-display-insert . . . . . . . . . . . . . . . . . . . . . . . . . . . 261
-display-list . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 261
-e . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12
-environment-cd . . . . . . . . . . . . . . . . . . . . . . . . . . . 262
-environment-directory . . . . . . . . . . . . . . . . . . . 262
-environment-path . . . . . . . . . . . . . . . . . . . . . . . . . 263
-environment-pwd . . . . . . . . . . . . . . . . . . . . . . . . . . 263
-exec-abort . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 264
-exec-arguments . . . . . . . . . . . . . . . . . . . . . . . . . . . 265
-exec-continue . . . . . . . . . . . . . . . . . . . . . . . . . . . . 265
-exec-finish . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 265
-exec-interrupt . . . . . . . . . . . . . . . . . . . . . . . . . . . 266
-exec-next . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 267
-exec-next-instruction . . . . . . . . . . . . . . . . . . . 267
-exec-return . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 268
-exec-run . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 268
-exec-show-arguments. . . . . . . . . . . . . . . . . . . . . . 269
-exec-step . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 269
-exec-step-instruction . . . . . . . . . . . . . . . . . . . 270
-exec-until . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 271
-f . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14
-file-exec-and-symbols . . . . . . . . . . . . . . . . . . . 271
-file-exec-file . . . . . . . . . . . . . . . . . . . . . . . . . . . 272
-file-list-exec-sections . . . . . . . . . . . . . . . . . 272
-file-list-exec-source-files . . . . . . . . . . . . . 272
-file-list-shared-libraries . . . . . . . . . . . . . . 273
-file-list-symbol-files . . . . . . . . . . . . . . . . . . 273
-file-symbol-file . . . . . . . . . . . . . . . . . . . . . . . . . 274
-gdb-exit . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 274
-gdb-set . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 274
-gdb-show . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 275
-gdb-version . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 275
-m . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12
-n . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13
-nointr . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 31
-nw . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13
334
-q . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13
-r . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13
-s . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12
-stack-info-depth . . . . . . . . . . . . . . . . . . . . . . . . . 276
-stack-info-frame . . . . . . . . . . . . . . . . . . . . . . . . . 276
-stack-list-arguments . . . . . . . . . . . . . . . . . . . . 277
-stack-list-frames . . . . . . . . . . . . . . . . . . . . . . . . 278
-stack-list-locals . . . . . . . . . . . . . . . . . . . . . . . . 280
-stack-select-frame . . . . . . . . . . . . . . . . . . . . . . . 280
-symbol-info-address. . . . . . . . . . . . . . . . . . . . . . 281
-symbol-info-file . . . . . . . . . . . . . . . . . . . . . . . . . 281
-symbol-info-function . . . . . . . . . . . . . . . . . . . . 281
-symbol-info-line . . . . . . . . . . . . . . . . . . . . . . . . . 282
-symbol-info-symbol . . . . . . . . . . . . . . . . . . . . . . . 282
-symbol-list-functions . . . . . . . . . . . . . . . . . . . 283
-symbol-list-types . . . . . . . . . . . . . . . . . . . . . . . . 283
-symbol-list-variables . . . . . . . . . . . . . . . . . . . 283
-symbol-locate . . . . . . . . . . . . . . . . . . . . . . . . . . . . 284
-symbol-type . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 284
-t . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15
-target-attach . . . . . . . . . . . . . . . . . . . . . . . . . . . . 284
-target-compare-sections . . . . . . . . . . . . . . . . . 285
-target-detach . . . . . . . . . . . . . . . . . . . . . . . . . . . . 285
-target-download . . . . . . . . . . . . . . . . . . . . . . . . . . 285
-target-exec-status . . . . . . . . . . . . . . . . . . . . . . . 287
-target-list-available-targets . . . . . . . . . . . 287
-target-list-current-targets . . . . . . . . . . . . . 288
-target-list-parameters . . . . . . . . . . . . . . . . . . 288
-target-select . . . . . . . . . . . . . . . . . . . . . . . . . . . . 289
-thread-info . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 289
-thread-list-all-threads . . . . . . . . . . . . . . . . . 290
-thread-list-ids . . . . . . . . . . . . . . . . . . . . . . . . . . 290
-thread-select . . . . . . . . . . . . . . . . . . . . . . . . . . . . 290
-var-assign . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 295
-var-create . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 292
-var-delete . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 293
-var-evaluate-expression . . . . . . . . . . . . . . . . . 295
-var-info-expression. . . . . . . . . . . . . . . . . . . . . . 294
-var-info-num-children . . . . . . . . . . . . . . . . . . . 294
-var-info-type . . . . . . . . . . . . . . . . . . . . . . . . . . . . 294
-var-list-children . . . . . . . . . . . . . . . . . . . . . . . . 294
-var-set-format . . . . . . . . . . . . . . . . . . . . . . . . . . . 293
-var-show-attributes. . . . . . . . . . . . . . . . . . . . . . 295
-var-show-format . . . . . . . . . . . . . . . . . . . . . . . . . . 294
-var-update . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 295
-w . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13
-x . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12
.
.esgdbinit . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
.gdbinit . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
.gdbinit . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
.gdbinit, application specific . . . . . . . . . . .
.inputrc . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
.os68gdbinit . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
.vxgdbinit . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
227
138
227
227
219
227
227
:
::, context for variables/functions . . . . . . . . . . . . 64
@
@, referencing memory as an array. . . . . . . . . . . . . 65
^
^done . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 243
^error . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 243
^running . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 243
{
{type} . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 64
A
a.out and C++ . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 86
abort_on_bad_free=[01] . . . . . . . . . . . . . . . . . . . 129
abort_on_bounds=[01]. . . . . . . . . . . . . . . . . . . . . . 129
abort_on_nomem=[01] . . . . . . . . . . . . . . . . . . . . . . . 129
active targets . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 109
add-symbol-file . . . . . . . . . . . . . . . . . . . . . . . . . . . 105
annotations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 231
annotations for breakpoints . . . . . . . . . . . . . . . . . . 236
annotations for display . . . . . . . . . . . . . . . . . . . . . . 234
annotations for errors, warnings and interrupts
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 235
annotations for frames . . . . . . . . . . . . . . . . . . . . . . 233
annotations for invalidation messages . . . . . . . . . 237
annotations for prompts . . . . . . . . . . . . . . . . . . . . . 235
annotations for running programs . . . . . . . . . . . . 237
annotations for source display . . . . . . . . . . . . . . . 238
annotations for values . . . . . . . . . . . . . . . . . . . . . . . 232
application specific settings . . . . . . . . . . . . . . . . . . 227
apropos . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20
arg-begin . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 232
arg-end . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 232
arg-name-end . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 232
arg-value . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 232
arguments (to your program) . . . . . . . . . . . . . . . . . 24
Arguments, Calling Fortran functions . . . . . . . . . 90
array-section-end . . . . . . . . . . . . . . . . . . . . . . . . . 233
artificial array . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 65
Assembler language file name extensions . . . . . . . 80
assembly instructions . . . . . . . . . . . . . . . . . . . . . 60, 61
assertion control, xdb . . . . . . . . . . . . . . . . . . . . . . . 195
assignment . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 97
async output in gdb/mi . . . . . . . . . . . . . . . . . . . . . 241
AT&T disassembly flavor . . . . . . . . . . . . . . . . . . . . . 61
attach . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 27
Index
automatic display . . . . . . . . . . . . . . . . . . . . . . . . . . . . 68
automatic thread selection . . . . . . . . . . . . . . . . . . . . 31
B
b (break) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 33
backtrace . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 52, 154
backtrace-other-thread . . . . . . . . . . . . . . . . . . . . 52
backtraces. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 52
batch memory leak checking . . . . . . . . . . . . . . . . . 123
break . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 33
break ... thread threadno . . . . . . . . . . . . . . . . . . 48
break in overloaded functions . . . . . . . . . . . . . . . . . 88
breakpoint . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 237
breakpoint commands . . . . . . . . . . . . . . . . . . . . . . . . 41
breakpoint commands for gdb/mi . . . . . . . . . . . . 245
breakpoint conditions . . . . . . . . . . . . . . . . . . . . . . . . 40
breakpoint numbers . . . . . . . . . . . . . . . . . . . . . . . . . . 33
breakpoint on events . . . . . . . . . . . . . . . . . . . . . . . . . 33
breakpoint ranges . . . . . . . . . . . . . . . . . . . . . . . . . . . . 33
breakpoints . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 33
breakpoints and threads . . . . . . . . . . . . . . . . . . . . . . 48
breakpoints-headers . . . . . . . . . . . . . . . . . . . . . . . 236
breakpoints-invalid . . . . . . . . . . . . . . . . . . . . . . . 237
breakpoints-table . . . . . . . . . . . . . . . . . . . . . . . . . 236
breakpoints-table-end . . . . . . . . . . . . . . . . . . . . 236
bt (backtrace) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 52
bug criteria . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 297
bug reports . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 297
bugs in GDB . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 297
C
c (continue) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 44
C and C++ . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 84
C and C++ checks . . . . . . . . . . . . . . . . . . . . . . . . . . . . 88
C and C++ constants . . . . . . . . . . . . . . . . . . . . . . . . . 86
C and C++ defaults . . . . . . . . . . . . . . . . . . . . . . . . . . 88
C and C++ operators . . . . . . . . . . . . . . . . . . . . . . . . . 84
C language file name extensions . . . . . . . . . . . . . . . 79
C++ . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 84
C++ and object formats . . . . . . . . . . . . . . . . . . . . . . 86
C++ exception handling . . . . . . . . . . . . . . . . . . . . . . 88
C++ language file name extensions . . . . . . . . . . . . 79
C++ scope resolution . . . . . . . . . . . . . . . . . . . . . . . . . 65
C++ support, not in coff . . . . . . . . . . . . . . . . . . . . 86
C++ symbol decoding style . . . . . . . . . . . . . . . . . . . 73
C++ symbol display . . . . . . . . . . . . . . . . . . . . . . . . . . 89
call . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 100
call overloaded functions . . . . . . . . . . . . . . . . . . . . . 87
call stack . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 51
calling functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . 100
calling make . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16
case-sensitive . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 90
casts, to view memory . . . . . . . . . . . . . . . . . . . . . . . 64
catch . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 37
catch catch . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 37
catch exceptions, list active handlers . . . . . . . . . . 55
335
catch exec . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 37
catch fork . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 37
catch load . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 37, 140
catch nomem . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 125
catch throw . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 37
catch unload . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 37
catch vfork . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 37
catchpoint set for one stop . . . . . . . . . . . . . . . . . . . 37
catchpoints . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 33
catchpoints, setting . . . . . . . . . . . . . . . . . . . . . . . . . . 37
cd . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26
cdir . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 59
changing, TUI window focus . . . . . . . . . . . . . . . . . 177
check_bound=on|off . . . . . . . . . . . . . . . . . . . . . . . . 127
check_bounds|bounds=on|off . . . . . . . . . . . . . . . 127
check_heap|heap=on|off . . . . . . . . . . . . . . . . . . . 127
check_leaks|leaks=on|off . . . . . . . . . . . . . . . . . 127
check_string=on|off . . . . . . . . . . . . . . . . . . . . . . . 127
checks, range . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 82
checks, type . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 81
choosing target byte order . . . . . . . . . . . . . . . . . . . 111
classes, opaque . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 87
clear . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 38
clearing breakpoints, watchpoints, catchpoints . . 38
coff versus C++ . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 86
colon-colon, context for variables/functions . . . . 64
command files . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 227
command history . . . . . . . . . . . . . . . . . . . . . . . . . . . 219
command hooks . . . . . . . . . . . . . . . . . . . . . . . . . . . . 226
command line editing . . . . . . . . . . . . . . . . . . . . . . . 219
command window, TUI . . . . . . . . . . . . . . . . . . . . . 177
commands . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 41, 235
commands for C++ . . . . . . . . . . . . . . . . . . . . . . . . . . . 88
compatibility, gdb/mi and CLI . . . . . . . . . . . . . . 243
compilation directory . . . . . . . . . . . . . . . . . . . . . . . . 59
compiler version . . . . . . . . . . . . . . . . . . . . . . . . . . . . 298
complete. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20
completion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17
completion of quoted strings . . . . . . . . . . . . . . . . . . 18
condition . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 40
conditional breakpoints . . . . . . . . . . . . . . . . . . . . . . 40
configuring GDB . . . . . . . . . . . . . . . . . . . . . . . . . . . 301
confirmation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 223
console output in gdb/mi . . . . . . . . . . . . . . . . . . . 241
continue. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 44
continuing. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 44
continuing threads . . . . . . . . . . . . . . . . . . . . . . . . . . . 48
controlling assertions, xdb . . . . . . . . . . . . . . . . . . . 195
convenience variables. . . . . . . . . . . . . . . . . . . . . . . . . 75
core . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 104
core dump file . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 103
core file, debugging . . . . . . . . . . . . . . . . . . . . . . . . . 106
core file, shared library location . . . . . . . . . . . . . . 106
core-file . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 104
crash of debugger . . . . . . . . . . . . . . . . . . . . . . . . . . . 297
current directory. . . . . . . . . . . . . . . . . . . . . . . . . . . . . 59
current stack frame . . . . . . . . . . . . . . . . . . . . . . . . . . 52
current thread . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 29
336
cwd . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 59
D
d (delete) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 38
data manipulation, in gdb/mi . . . . . . . . . . . . . . . 253
ddd . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 147
deadlock, NFS mounted multi-thread programs
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 31
debugger crash . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 297
debugging sessions . . . . . . . . . . . . . . . . . . . . . 104, 219
debugging target . . . . . . . . . . . . . . . . . . . . . . . . . . . 109
debugging, core file . . . . . . . . . . . . . . . . . . . . . . . . . 106
define . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 225
delete . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 38
delete breakpoints . . . . . . . . . . . . . . . . . . . . . . . . . . . 38
delete display . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 69
deleting breakpoints, watchpoints, catchpoints
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 38
demangling . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 73
detach . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 27
dir . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 59, 138
directories for source files . . . . . . . . . . . . . . . . . . . . . 59
directory . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 59
directory, compilation . . . . . . . . . . . . . . . . . . . . . . . . 59
directory, current . . . . . . . . . . . . . . . . . . . . . . . . . . . . 59
dis (disable) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 39
disable . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 39
disable breakpoints . . . . . . . . . . . . . . . . . . . . . . . . 39
disable display . . . . . . . . . . . . . . . . . . . . . . . . . . . . 69
disabling signals . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 47
disassemble . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 60
display . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 69
display of expressions . . . . . . . . . . . . . . . . . . . . . . . . 68
display-begin . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 234
display-end . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 234
display-expression . . . . . . . . . . . . . . . . . . . . . . . . 234
display-expression-end . . . . . . . . . . . . . . . . . . . 234
display-format . . . . . . . . . . . . . . . . . . . . . . . . . . . . 234
display-number-end . . . . . . . . . . . . . . . . . . . . . . . . 234
display-value . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 234
do (down) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 53
document . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 225
down . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 53
down-silently . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 54
dump, debugging core dump . . . . . . . . . . . . . . . . . 106
dynamic linking . . . . . . . . . . . . . . . . . . . . . . . . . . . . 105
E
echo . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 228
ecoff and C++ . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 86
edit . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 117
editing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 219
elf/dwarf and C++ . . . . . . . . . . . . . . . . . . . . . . . . . 86
elf/stabs and C++ . . . . . . . . . . . . . . . . . . . . . . . . . . . 86
else . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 225
elt . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 233
elt-rep . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 233
elt-rep-end . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 233
Emacs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 229
enable . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 39
enable breakpoints . . . . . . . . . . . . . . . . . . . . . . . . . 39
enable display . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 69
end . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 41
entering numbers . . . . . . . . . . . . . . . . . . . . . . . . . . . 221
environment (of your program) . . . . . . . . . . . . . . . 25
environment variables, shared library path . . . . 106
error . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 235
error on valid input . . . . . . . . . . . . . . . . . . . . . . . . . 297
error-begin . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 236
event handling . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 37
examining data . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 63
examining memory. . . . . . . . . . . . . . . . . . . . . . . . . . . 67
exception handlers . . . . . . . . . . . . . . . . . . . . . . . . . . . 37
exception handlers, how to list . . . . . . . . . . . . . . . . 55
exec . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 37
exec-file . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 103
executable file . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 103
exit() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 126
exited . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 237
exiting GDB . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16
expressions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 63
expressions in C or C++ . . . . . . . . . . . . . . . . . . . . . . 84
expressions in C++ . . . . . . . . . . . . . . . . . . . . . . . . . . . 86
extenstions, file names . . . . . . . . . . . . . . . . . . . . . . . 79
F
f (frame) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 53
fatal signal . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 297
fatal signals . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 46
fg (resume foreground execution) . . . . . . . . . . . . . 44
field . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 236
field-begin . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 232
field-end . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 232
field-name-end . . . . . . . . . . . . . . . . . . . . . . . . . . . . 232
field-value . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 232
file . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 103
file names, extensions . . . . . . . . . . . . . . . . . . . . . . . . 79
files, mounting over NFS . . . . . . . . . . . . . . . . . . . . . 31
finish . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 45
Fix and Continue . . . . . . . . . . . . . . . . . . . . . . . . . . . 117
Fix and Continue dependencies . . . . . . . . . . . . . . 118
flinching . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 223
floating point . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 78
floating point registers . . . . . . . . . . . . . . . . . . . . . . . 77
floating point registers, printing . . . . . . . . . . . . . . . 78
focus . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 177
focus of debugging . . . . . . . . . . . . . . . . . . . . . . . . . . . 29
focus, TUI window. . . . . . . . . . . . . . . . . . . . . . . . . . 177
foo . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 108
fork . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 37
fork, debugging programs which call . . . . . . . . . . . 31
format options . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 70
formatted output . . . . . . . . . . . . . . . . . . . . . . . . . . . . 66
Index
Fortran . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1
Fortran common blocks . . . . . . . . . . . . . . . . . . . . . . 91
Fortran entry points . . . . . . . . . . . . . . . . . . . . . . . . . 91
Fortran language file name extensions . . . . . . . . . 79
Fortran operators . . . . . . . . . . . . . . . . . . . . . . . . . . . . 90
Fortran support . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 90
Fortran types . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 90
Fortran variables . . . . . . . . . . . . . . . . . . . . . . . . . . . . 91
Fortran, intrinsic support . . . . . . . . . . . . . . . . . . . . . 90
forward-search . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 58
frame number . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 51
frame pointer . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 51
frame, command . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 52
frame, definition . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 51
frame, selecting . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 53
frame-address . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 234
frame-address-end . . . . . . . . . . . . . . . . . . . . . . . . . 234
frame-args . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 234
frame-begin . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 233
frame-end . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 233
frame-function-name . . . . . . . . . . . . . . . . . . . . . . . 234
frame-source-begin . . . . . . . . . . . . . . . . . . . . . . . . 234
frame-source-end . . . . . . . . . . . . . . . . . . . . . . . . . . 234
frame-source-file . . . . . . . . . . . . . . . . . . . . . . . . . 234
frame-source-file-end . . . . . . . . . . . . . . . . . . . . 234
frame-source-line . . . . . . . . . . . . . . . . . . . . . . . . . 234
frame-where . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 234
frame_count=no_frames . . . . . . . . . . . . . . . . . . . . 127
frameless execution . . . . . . . . . . . . . . . . . . . . . . . . . . 51
frames-invalid . . . . . . . . . . . . . . . . . . . . . . . . . . . . 237
function-call . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 233
functions, opaque . . . . . . . . . . . . . . . . . . . . . . . . . . . . 87
G
g++, gnu C++ compiler . . . . . . . . . . . . . . . . . . . . . . . 84
GDB bugs, reporting . . . . . . . . . . . . . . . . . . . . . . . . 297
gdb.ini . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 227
gdb/mi, breakpoint commands . . . . . . . . . . . . . . 245
gdb/mi, compatibility with CLI . . . . . . . . . . . . . 243
gdb/mi, data manipulation . . . . . . . . . . . . . . . . . . 253
gdb/mi, input syntax . . . . . . . . . . . . . . . . . . . . . . . 239
gdb/mi, its purpose. . . . . . . . . . . . . . . . . . . . . . . . . 239
gdb/mi, out-of-band records . . . . . . . . . . . . . . . . . 244
gdb/mi, output syntax . . . . . . . . . . . . . . . . . . . . . . 240
gdb/mi, result records . . . . . . . . . . . . . . . . . . . . . . 243
gdb/mi, simple examples . . . . . . . . . . . . . . . . . . . . 242
gdb/mi, stream records . . . . . . . . . . . . . . . . . . . . . 243
GDB SHLIB PATH . . . . . . . . . . . . . . . . . . . . . . . . 106
GDB SHLIB ROOT . . . . . . . . . . . . . . . . . . . . . . . . 106
GDBHISTFILE . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 220
gnu C++ . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 84
gnu Emacs. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 229
337
H
h (help) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19
handle . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 47
handling signals . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 46
hanging program when debugging . . . . . . . . . . . . . 47
hbreak . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 35
help . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19
help java . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 155
help target . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 109
help user-defined . . . . . . . . . . . . . . . . . . . . . . . . . 226
history expansion . . . . . . . . . . . . . . . . . . . . . . . . . . . 220
history file . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 220
history number . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 75
history save . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 220
history size . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 220
history substitution . . . . . . . . . . . . . . . . . . . . . . . . . 220
history vi key bindings . . . . . . . . . . . . . . . . . . . . . . 219
hooks, for commands. . . . . . . . . . . . . . . . . . . . . . . . 226
HP C++ . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 84
HP-UX case sensitivity . . . . . . . . . . . . . . . . . . . . . . . 90
HP-UX demangle-style . . . . . . . . . . . . . . . . . . . . . . . 73
HP-UX fork function . . . . . . . . . . . . . . . . . . . . . . . . . 31
HP-UX key bindings . . . . . . . . . . . . . . . . . . . . . . . . 219
HP-UX loading shared library . . . . . . . . . . . . . . . 106
HP-UX Setting catchpoints . . . . . . . . . . . . . . . . . . . 37
HP-UX shared library breakpoints . . . . . . . . . . . . 33
HP-UX support . . . . . . . . . . . . . . . . . . . . . . . . . . . . 297
HP-UX supported versions . . . . . . . . . . . . . . . . . . . . 1
HP-UX Terminal User Interface . . . . . . . . . . 15, 169
HP-UX thread numbers . . . . . . . . . . . . . . . . . . . . . . 29
HP-UX TUI and Emacs . . . . . . . . . . . . . . . . . . . . . 229
HP-UX variable names . . . . . . . . . . . . . . . . . . . . . . . 76
HP-UX virtual functions . . . . . . . . . . . . . . . . . . . . . 87
HP-UX XDB compatibility . . . . . . . . . . . . . . . . . . . 15
HP-UX, multi-thread process limitations . . . . . . 31
HP-UX, shared libraries . . . . . . . . . . . . . . . . . . . . . 105
I
i (info) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20
i/o . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26
if . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 225
ignore . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 41
ignore count (of breakpoint) . . . . . . . . . . . . . . . . . . 41
info . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20
info address . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 93
info all-registers . . . . . . . . . . . . . . . . . . . . . . . . . 77
info args . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 55
info breakpoints . . . . . . . . . . . . . . . . . . . . . . . . . . . 35
info catch . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 55
info coruption leaks . . . . . . . . . . . . . . . . . . . . . . 124
info display . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 69
info extensions . . . . . . . . . . . . . . . . . . . . . . . . . . . . 81
info f (info frame) . . . . . . . . . . . . . . . . . . . . . . . . . 54
info files . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 105
info float . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 78
info frame . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 54, 154
info frame, show the source language . . . . . . . . . 80
338
info functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 94
info heap . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 134
info heap filename . . . . . . . . . . . . . . . . . . . . . . . . 134
info heap idnumber . . . . . . . . . . . . . . . . . . . . . . . . 134
info heap-interval < file name > . . . . . . . . . . 125
info leak leaknumber . . . . . . . . . . . . . . . . . . . . . . 124
info leaks . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 124
info leaks filename . . . . . . . . . . . . . . . . . . . . . . . 124
info line . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 60
info locals . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 55
info program . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 33
info registers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 77
info s (info stack) . . . . . . . . . . . . . . . . . . . . . . . . . 52
info set . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20
info share . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 106
info sharedlibrary . . . . . . . . . . . . . . . . . . . . . . . . 106
info signals . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 47
info source . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 94
info source, show the source language . . . . . . . . 80
info sources . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 94
info stack . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 52
info target . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 105
info terminal. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26
info threads . . . . . . . . . . . . . . . . . . . . . . . . 29, 30, 154
info types . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 94
info variables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 94
inheritance . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 89
init file. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 227
init file name . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 227
initial frame . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 51
innermost frame . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 51
input syntax for gdb/mi . . . . . . . . . . . . . . . . . . . . 239
inputrc . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 219
inspect . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 63
installation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 301
Instruction Level Stepping . . . . . . . . . . . . . . . . . . . 167
instructions, assembly . . . . . . . . . . . . . . . . . . . . 60, 61
Intel disassembly flavor . . . . . . . . . . . . . . . . . . . . . . . 61
internal GDB breakpoints . . . . . . . . . . . . . . . . . . . . 36
interrupt . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16
intrinsic support, Fortran . . . . . . . . . . . . . . . . . . . . . 90
invalid input . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 297
J
java . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
java args <frame-number> . . . . . . . . . . . . . . . . . .
java bytecodes <methodOop> . . . . . . . . . . . . . . . .
java heap-histogram . . . . . . . . . . . . . . . . . . . . . . .
java instances <klassOop> . . . . . . . . . . . . . . . . .
java jvm-state . . . . . . . . . . . . . . . . . . . . . . . . . . . .
java locals . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
java mutex-info . . . . . . . . . . . . . . . . . . . . . . . . . . .
java object <object-ptr> . . . . . . . . . . . . . . . . . .
java oop <Java_heap_address> . . . . . . . . . . . . . .
java references <oop> . . . . . . . . . . . . . . . . . . . . .
java unwind-info <pc> . . . . . . . . . . . . . . . . . . . . .
java unwind-table . . . . . . . . . . . . . . . . . . . . . . . . .
155
155
155
155
155
155
155
155
155
155
155
155
155
jump . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 98
K
kill . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 28
L
l (list) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 57
language, file name extensions . . . . . . . . . . . . . . . . 79
languages . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 79
latest breakpoint . . . . . . . . . . . . . . . . . . . . . . . . . . . . 33
leak_logfile=stderr[+]filename . . . . . . . . . . . 129
leaving GDB . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16
library, setting path . . . . . . . . . . . . . . . . . . . . . . . . . 106
linespec . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 57
Linux Runtime Environment (LRE) . . . . . . . . . . 167
list . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 57
list output in gdb/mi . . . . . . . . . . . . . . . . . . . . . . . 242
listing machine instructions . . . . . . . . . . . . . . . 60, 61
load . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 37
load filename . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 111
loading shared libraries . . . . . . . . . . . . . . . . . . . . . . 106
lock, deadlock caused by NFS-mounted files. . . . 31
log output in gdb/mi . . . . . . . . . . . . . . . . . . . . . . . 242
M
machine instructions . . . . . . . . . . . . . . . . . . . . . . 60, 61
main in Fortran . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 91
maint info breakpoints . . . . . . . . . . . . . . . . . . . . . 36
maint print psymbols . . . . . . . . . . . . . . . . . . . . . . . 95
maint print symbols . . . . . . . . . . . . . . . . . . . . . . . . 95
make . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16
mapped . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 104
member functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . 86
memory, viewing as typed object . . . . . . . . . . . . . . 64
memory-mapped symbol file . . . . . . . . . . . . . . . . . 104
min-heap-size . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 124
min_heap_size=block_size . . . . . . . . . . . . . . . . . 127
min_leak_size=block_size . . . . . . . . . . . . . . . . . 127
missing debug information . . . . . . . . . . . . . . . . . . . . 87
missing function or class. . . . . . . . . . . . . . . . . . . . . . 87
mount, process started across NFS . . . . . . . . . . . . 28
mounts, NFS-mounted files cause deadlock . . . . . 31
multiple processes . . . . . . . . . . . . . . . . . . . . . . . . . . . 31
multiple targets . . . . . . . . . . . . . . . . . . . . . . . . . . . . 109
multiple threads . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 28
multiple threads, deadlock . . . . . . . . . . . . . . . . . . . . 31
Index
N
n (next) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 45
names of symbols . . . . . . . . . . . . . . . . . . . . . . . . . . . . 93
namespace in C++ . . . . . . . . . . . . . . . . . . . . . . . . . . . 86
negative breakpoint numbers . . . . . . . . . . . . . . . . . 36
network, NFS mounted files . . . . . . . . . . . . . . . . . . 31
New systag message . . . . . . . . . . . . . . . . . . . . . . . . . . 29
New systag message, on HP-UX . . . . . . . . . . . . . . . 29
next . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 45
nexti . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 46
NFS limitation with multiple threads . . . . . . . . . . 31
NFS mounts . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 28
ni (nexti) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 46
no data fields, error . . . . . . . . . . . . . . . . . . . . . . . . . . 87
nointr, NFS-mounted files . . . . . . . . . . . . . . . . . . . 31
notational conventions, for gdb/mi . . . . . . . . . . . 239
notify output in gdb/mi. . . . . . . . . . . . . . . . . . . . . 241
number representation . . . . . . . . . . . . . . . . . . . . . . 221
numbers for breakpoints . . . . . . . . . . . . . . . . . . . . . . 33
339
post-prompt-for-continue . . . . . . . . . . . . . . . . . 235
post-query . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 235
pre-commands . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 235
pre-overload-choice . . . . . . . . . . . . . . . . . . . . . . . 235
pre-prompt . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 235
pre-prompt-for-continue . . . . . . . . . . . . . . . . . . 235
pre-query . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 235
print . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 63
print settings . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 70
printf . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 228
printing data . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 63
printing floating point registers . . . . . . . . . . . . . . . 78
processes, multiple . . . . . . . . . . . . . . . . . . . . . . . . . . . 31
program hangs when debugging . . . . . . . . . . . . . . . 47
prompt . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 219
prompt . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 235
prompt-for-continue . . . . . . . . . . . . . . . . . . . . . . . 235
ptype . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 93
pwd . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26
pxdb -s . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 140
O
object formats and C++ . . . . . . . . . . . . . . . . . . . . . . 86
objectdir . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 137
objectload . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 138
objectretry . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 138
online documentation . . . . . . . . . . . . . . . . . . . . . . . . 19
opaque function . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 87
out-of-band records in gdb/mi . . . . . . . . . . . . . . . 244
outermost frame . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 51
output . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 228
output formats . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 66
output syntax of gdb/mi . . . . . . . . . . . . . . . . . . . . 240
output_dir=output_data_dir . . . . . . . . . . . . . . . 127
overload resolution . . . . . . . . . . . . . . . . . . . . . . . . . . . 89
overload-choice . . . . . . . . . . . . . . . . . . . . . . . . . . . 235
overloaded functions, calling . . . . . . . . . . . . . . . . . . 87
overloaded functions, overload resolution . . . . . . 89
overloading . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 42
overloading in C++ . . . . . . . . . . . . . . . . . . . . . . . . . . . 88
P
packets, reporting on stdout . . . . . . . . . . . . . . . . . 223
partial symbol dump . . . . . . . . . . . . . . . . . . . . . . . . . 95
patching binaries . . . . . . . . . . . . . . . . . . . . . . . . . . . 100
path . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25
path, shared libraries . . . . . . . . . . . . . . . . . . . . . . . 106
pathmap . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 138
pauses in output . . . . . . . . . . . . . . . . . . . . . . . . . . . . 221
permission denied, attach to a running program
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 28
pipes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24
pointer, finding referent . . . . . . . . . . . . . . . . . . . . . . 71
Pointers, Fortran . . . . . . . . . . . . . . . . . . . . . . . . . . . . 90
post-commands . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 235
post-overload-choice. . . . . . . . . . . . . . . . . . . . . . 235
post-prompt . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 235
Q
q (quit) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16
query . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 235
quit . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 235
quit [expression ] . . . . . . . . . . . . . . . . . . . . . . . . . . . 16
quotes in commands . . . . . . . . . . . . . . . . . . . . . . . . . 18
quoting names . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 93
R
r (run). . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23
raise exceptions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 38
range checking . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 82
ranges of breakpoints . . . . . . . . . . . . . . . . . . . . . . . . 33
rbreak . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 35
reading symbols immediately . . . . . . . . . . . . . . . . 104
readline . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 219
readnow . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 104
record . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 236
redirection . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26
reference declarations . . . . . . . . . . . . . . . . . . . . . . . . 87
registers. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 77
regular expression. . . . . . . . . . . . . . . . . . . . . . . . . . . . 35
reloading symbols . . . . . . . . . . . . . . . . . . . . . . . . . . . . 94
reporting bugs in GDB . . . . . . . . . . . . . . . . . . . . . . 297
result records in gdb/mi . . . . . . . . . . . . . . . . . . . . 243
resuming execution . . . . . . . . . . . . . . . . . . . . . . . . . . 44
return . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 99
returning from a function. . . . . . . . . . . . . . . . . . . . . 99
reverse-search . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 58
rmode NFS-caused deadlock . . . . . . . . . . . . . . . . . . 31
run . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23
running . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23
340
S
s (step) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 44
saving symbol table . . . . . . . . . . . . . . . . . . . . . . . . . 104
scramble_blocks=on|off . . . . . . . . . . . . . . . . . . . 127
scrolling, TUI command window . . . . . . . . . . . . . 177
search . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 58
searching . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 58
section . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 105
select-frame . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 52
selected frame . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 51
selecting frame silently . . . . . . . . . . . . . . . . . . . . . . . 52
serial connections, debugging . . . . . . . . . . . . . . . . 223
server prefix for annotations . . . . . . . . . . . . . . . . . 231
sessions, debugging . . . . . . . . . . . . . . . . . . . . . 104, 219
set . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20
set args . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24
set auto-solib-add . . . . . . . . . . . . . . . . . . . . . . . . 106
set check range . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 83
set check type . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 82
set check, range . . . . . . . . . . . . . . . . . . . . . . . . . . . . 83
set check, type . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 82
set complaints . . . . . . . . . . . . . . . . . . . . . . . . . . . . 222
set confirm . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 223
set debug arch . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 223
set debug event . . . . . . . . . . . . . . . . . . . . . . . . . . . . 223
set debug expression . . . . . . . . . . . . . . . . . . . . . . 223
set debug overload . . . . . . . . . . . . . . . . . . . . . . . . 223
set debug remote . . . . . . . . . . . . . . . . . . . . . . . . . . . 223
set debug serial . . . . . . . . . . . . . . . . . . . . . . . . . . . 223
set debug target . . . . . . . . . . . . . . . . . . . . . . . . . . . 224
set debug varobj . . . . . . . . . . . . . . . . . . . . . . . . . . . 224
set demangle-style . . . . . . . . . . . . . . . . . . . . . . . . . 73
set disassembly-flavor . . . . . . . . . . . . . . . . . . . . . 61
set editing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 219
set endian auto . . . . . . . . . . . . . . . . . . . . . . . . . . . . 111
set endian big . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 111
set endian little. . . . . . . . . . . . . . . . . . . . . . . . . . 111
set environment . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25
set extension-language . . . . . . . . . . . . . . . . . . . . . 81
set follow-fork-mode . . . . . . . . . . . . . . . . . . . . . . . 31
set gnutarget . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 110
set heap-check block-size num-bytes . . . . . . 124
set heap-check bounds [on | off] . . . . . . . . . . 124
set heap-check frame-count num . . . . . . . 124, 134
set heap-check free [on | off] . . . . . . . . . . . . . 124
set heap-check heap-size num-size . . . . . . . . 124
set heap-check interval < nn > . . . . . . . . . . . . . 125
set heap-check leaks . . . . . . . . . . . . . . . . . . . . . . 123
set heap-check min-leak-size num . . . . . . . . . 124
set heap-check null-check [N | random] . . . . 125
set heap-check null-check-size N . . . . . . . . . . 125
set heap-check repeat < nn > . . . . . . . . . . . . . . . 125
set heap-check reset . . . . . . . . . . . . . . . . . . . . . . 125
set heap-check scramble [on | off] . . . . . . . . 124
set heap-check watch address . . . . . . . . . . . . . . 124
set height . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 221
set history expansion . . . . . . . . . . . . . . . . . . . . . 220
set history filename . . . . . . . . . . . . . . . . . . . . . . 220
Index
show directories . . . . . . . . . . . . . . . . . . . . . . . . . . . 59
show editing. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 219
show environment . . . . . . . . . . . . . . . . . . . . . . . . . . . 25
show envvar . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25
show gnutarget . . . . . . . . . . . . . . . . . . . . . . . . . . . . 110
show heap-check . . . . . . . . . . . . . . . . . . . . . . . 123, 135
show height . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 221
show history. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 220
show input-radix . . . . . . . . . . . . . . . . . . . . . . . . . . 222
show language. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 80
show listsize. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 57
show opaque-type-resolution . . . . . . . . . . . . . . . 95
show output-radix . . . . . . . . . . . . . . . . . . . . . . . . . 222
show overload-resolution . . . . . . . . . . . . . . . . . . . 89
show paths . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25
show print address . . . . . . . . . . . . . . . . . . . . . . . . . 70
show print array . . . . . . . . . . . . . . . . . . . . . . . . . . . . 71
show print asm-demangle . . . . . . . . . . . . . . . . . . . . 73
show print demangle . . . . . . . . . . . . . . . . . . . . . . . . 73
show print elements . . . . . . . . . . . . . . . . . . . . . . . . 72
show print max-symbolic-offset. . . . . . . . . . . . . 71
show print object . . . . . . . . . . . . . . . . . . . . . . . . . . . 74
show print pretty . . . . . . . . . . . . . . . . . . . . . . . . . . . 72
show print sevenbit-strings . . . . . . . . . . . . . . . . 72
show print static-members . . . . . . . . . . . . . . . . . . 74
show print symbol-filename . . . . . . . . . . . . . . . . . 71
show print union . . . . . . . . . . . . . . . . . . . . . . . . . . . . 73
show print vtbl . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 74
show prompt . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 219
show symbol-reloading . . . . . . . . . . . . . . . . . . . . . . 95
show threadverbose . . . . . . . . . . . . . . . . . . . . . . . . . 30
show user . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 226
show values . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 75
show verbose. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 222
show version . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21
show warranty. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21
show width . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 221
show write . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 101
shows . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 220
si (stepi) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 46
signal . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 99, 237
signal-handler-caller . . . . . . . . . . . . . . . . . . . . 233
signal-name . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 237
signal-name-end . . . . . . . . . . . . . . . . . . . . . . . . . . . 237
signal-string . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 237
signal-string-end . . . . . . . . . . . . . . . . . . . . . . . . . 237
signalled . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 237
signals . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 46
signals, disabling. . . . . . . . . . . . . . . . . . . . . . . . . . . . . 47
SIGTRAP, disable . . . . . . . . . . . . . . . . . . . . . . . . . . . 47
silent . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 42
size of screen . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 221
source . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 227, 238
source path . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 59
stack frame. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 51
stack traces . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 52
stacking targets. . . . . . . . . . . . . . . . . . . . . . . . . . . . . 109
starting . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23
341
starting . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 237
status output in gdb/mi . . . . . . . . . . . . . . . . . . . . 241
step . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 44
stepi . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 46
stepping . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 44
stop, a pseudo-command . . . . . . . . . . . . . . . . . . . . 226
stopped threads . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 48
stopping . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 237
stream records in gdb/mi . . . . . . . . . . . . . . . . . . . 243
structure fields, Fix and Continue . . . . . . . . . . . . 118
Structures, Fortran . . . . . . . . . . . . . . . . . . . . . . . . . . 90
stupid questions . . . . . . . . . . . . . . . . . . . . . . . . . . . . 223
support . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 297
switching threads . . . . . . . . . . . . . . . . . . . . . . . . . . . . 28
switching threads automatically . . . . . . . . . . . . . . . 31
symbol decoding style, C++ . . . . . . . . . . . . . . . . . . . 73
symbol dump . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 95
symbol names . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 93
symbol overloading . . . . . . . . . . . . . . . . . . . . . . . . . . 42
symbol table . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 103
symbol-file . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 103
symbols, loading from shared libraries . . . . . . . . 106
symbols, reading immediately . . . . . . . . . . . . . . . . 104
T
target . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 109
target byte order . . . . . . . . . . . . . . . . . . . . . . . . . . . 111
target core . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 110
target exec . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 110
target nrom . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 110
target output in gdb/mi . . . . . . . . . . . . . . . . . . . . 242
target remote . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 110
target sim . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 110
tbreak . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 34
tcatch . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 37
terminal . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26
Terminal User Interface . . . . . . . . . . . . . . . . . . 15, 169
thbreak . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 35
this, inside C++ member functions . . . . . . . . . . . . 86
thread . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 155
thread apply . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 30
thread breakpoints . . . . . . . . . . . . . . . . . . . . . . . . . . . 48
thread identifier (GDB) . . . . . . . . . . . . . . . . . . . . . . 29
thread identifier (system) . . . . . . . . . . . . . . . . . . . . . 29
thread identifier (system), on HP-UX. . . . . . . . . . 29
thread number . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 29
thread threadno . . . . . . . . . . . . . . . . . . . . . . . . . . . . 30
threads of execution . . . . . . . . . . . . . . . . . . . . . . . . . 28
threads, automatic switching . . . . . . . . . . . . . . . . . 31
threads, backtrace . . . . . . . . . . . . . . . . . . . . . . . . . . . 52
threads, continuing . . . . . . . . . . . . . . . . . . . . . . . . . . 48
threads, NFS-caused deadlock . . . . . . . . . . . . . . . . 31
threads, stopped . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 48
threadverbose . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 30
throw . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 37
tracebacks. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 52
tty . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26
342
TUI . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 169
TUI and Emacs . . . . . . . . . . . . . . . . . . . . . . . . . . . . 229
TUI, command window . . . . . . . . . . . . . . . . . . . . . 177
type casting memory . . . . . . . . . . . . . . . . . . . . . . . . . 64
type checking . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 81
type conversions in C++ . . . . . . . . . . . . . . . . . . . . . . 87
types, Fortran . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 90
variables, setting . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 97
version number . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21
versions, compiler . . . . . . . . . . . . . . . . . . . . . . . . . . . 298
vfork . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 37
vi key bindings . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 219
Viewing Wide Character Strings . . . . . . . . . . . . . 167
virtual functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 87
u (until) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 45
undisplay . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 69
Unions, Fortran. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 90
unknown address, locating . . . . . . . . . . . . . . . . . . . . 67
unload . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 37
unset environment . . . . . . . . . . . . . . . . . . . . . . . . . . 25
until . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 45
up . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 53
up-silently . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 54
user-defined command . . . . . . . . . . . . . . . . . . . . . . 225
watchpoint . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 237
watchpoints, xdb assertion control . . . . . . . . . . . . 195
whatis . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 93
where . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 52
while . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 225
wild pointer, interpreting . . . . . . . . . . . . . . . . . . . . . 71
window, changing focus in TUI . . . . . . . . . . . . . . 177
word completion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17
working directory . . . . . . . . . . . . . . . . . . . . . . . . . . . . 59
working directory (of your program). . . . . . . . . . . 26
working language . . . . . . . . . . . . . . . . . . . . . . . . . . . . 79
writing into corefiles . . . . . . . . . . . . . . . . . . . . . . . . 100
writing into executables . . . . . . . . . . . . . . . . . . . . . 100
wrong values . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 65
V
value history . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 74
value-begin . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 232
value-end . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 232
value-history-begin . . . . . . . . . . . . . . . . . . . . . . . 232
value-history-end . . . . . . . . . . . . . . . . . . . . . . . . . 232
value-history-value . . . . . . . . . . . . . . . . . . . . . . . 232
variable name conflict . . . . . . . . . . . . . . . . . . . . . . . . 64
variable names . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 76
variable objects in gdb/mi . . . . . . . . . . . . . . . . . . 292
variable values, wrong . . . . . . . . . . . . . . . . . . . . . . . . 65
X
x (examine memory) . . . . . . . . . . . . . . . . . . . . . . . . . 67
x(examine), and info line . . . . . . . . . . . . . . . . . . . 60
xcoff and C++ . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 86
XDB compatibility . . . . . . . . . . . . . . . . . . . . . . . . . . . 15
XDB transition guide . . . . . . . . . . . . . . . . . . . . . . . 183
Index
343
344