Debugging With GDB The GNU Source Level Debugger 9th Edition Richard M. Stallman Download
Debugging With GDB The GNU Source Level Debugger 9th Edition Richard M. Stallman Download
https://ebookgate.com/product/debugging-with-gdb-the-gnu-source-
level-debugger-9th-edition-richard-m-stallman/
https://ebookgate.com/product/gnu-emacs-manual-14th-edition-richard-m-
stallman/
ebookgate.com
https://ebookgate.com/product/free-software-free-society-selected-
essays-of-richard-m-stallman-first-printing-edition-richard-m-
stallman/
ebookgate.com
https://ebookgate.com/product/free-software-free-society-selected-
essays-of-richard-stallman-2nd-edition-edition-richard-stallman/
ebookgate.com
https://ebookgate.com/product/gnu-linux-application-programming-1st-
edition-m-timm-tim-jones-jones/
ebookgate.com
Electrical Trainee Guide Level 3 9th Edition Nccer
https://ebookgate.com/product/electrical-trainee-guide-level-3-9th-
edition-nccer/
ebookgate.com
https://ebookgate.com/product/the-debugger-s-handbook-1st-edition-j-f-
dimarzio/
ebookgate.com
https://ebookgate.com/product/free-as-in-freedom-2-0-richard-stallman-
and-the-free-software-revolution-2nd-edition-sam-williams/
ebookgate.com
https://ebookgate.com/product/programming-embedded-systems-with-c-and-
gnu-development-tools-2nd-edition-michael-barr/
ebookgate.com
Permission is granted to copy, distribute and/or modify this document under the terms
of the GNU Free Documentation License, Version 1.1 or any later version published by
the Free Software Foundation; with the Invariant Sections being “Free Software” and “Free
Software Needs Free Documentation”, with the Front-Cover Texts being “A GNU Manual,”
and with the Back-Cover Texts as in (a) below.
(a) The Free Software Foundation’s Back-Cover Text is: “You have freedom to copy and
modify this GNU Manual, like GNU software. Copies published by the Free Software
Foundation raise funds for GNU development.”
i
Table of Contents
Summary of GDB . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1
Free software . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1
Free Software Needs Free Documentation . . . . . . . . . . . . . . . . . . . . . . 1
Contributors to GDB . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3
3 GDB Commands . . . . . . . . . . . . . . . . . . . . . . . . . 17
3.1 Command syntax . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17
3.2 Command completion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17
3.3 Getting help . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19
8 Examining Data . . . . . . . . . . . . . . . . . . . . . . . . . . 63
8.1 Expressions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 63
8.2 Program variables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 64
8.3 Artificial arrays . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 65
8.4 Output formats . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 66
8.5 Examining memory. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 67
8.6 Automatic display . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 68
8.7 Print settings . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 70
8.8 Value history . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 75
8.9 Convenience variables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 76
8.10 Registers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 77
8.11 Floating point hardware . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 78
8.12 Memory Region Attributes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 78
8.12.1 Attributes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 79
8.12.1.1 Memory Access Mode . . . . . . . . . . . . . . . . 79
8.12.1.2 Memory Access Size . . . . . . . . . . . . . . . . . . 79
8.12.1.3 Data Cache . . . . . . . . . . . . . . . . . . . . . . . . . . 80
9 Tracepoints. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 81
9.1 Commands to Set Tracepoints . . . . . . . . . . . . . . . . . . . . . . . . . . . 81
9.1.1 Create and Delete Tracepoints . . . . . . . . . . . . . . . . . . 81
9.1.2 Enable and Disable Tracepoints . . . . . . . . . . . . . . . . . 82
9.1.3 Tracepoint Passcounts . . . . . . . . . . . . . . . . . . . . . . . . . 82
9.1.4 Tracepoint Action Lists . . . . . . . . . . . . . . . . . . . . . . . . 83
9.1.5 Listing Tracepoints . . . . . . . . . . . . . . . . . . . . . . . . . . . . 84
9.1.6 Starting and Stopping Trace Experiment . . . . . . . . 85
9.2 Using the collected data . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 85
9.2.1 tfind n . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 85
9.2.2 tdump. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 87
9.2.3 save-tracepoints filename . . . . . . . . . . . . . . . . . . . . 88
9.3 Convenience Variables for Tracepoints . . . . . . . . . . . . . . . . . . . 88
iii
Index . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 307
Summary of GDB 1
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 executes—or what another program was doing at the moment it
crashed.
GDB can do four main kinds of things (plus other things in support of these) to help
you catch bugs in the act:
• Start your program, specifying anything that might affect its behavior.
• Make your program stop on specified conditions.
• Examine what has happened, when your program has stopped.
• 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 and C++. For more information, see
Section 11.4 [Supported languages], page 101. For more information, see Section 11.4.1 [C
and C++], page 102.
Support for Modula-2 and Chill is partial. For information on Modula-2, see Sec-
tion 11.4.2 [Modula-2], page 107. For information on Chill, see Section 11.4.3 [Chill],
page 112.
Debugging Pascal programs which use sets, subranges, file variables, or nested functions
does not currently work. GDB does not support entering expressions, printing values, or
similar features using Pascal syntax.
GDB can be used to debug programs written in Fortran, although it may be necessary
to refer to some variables with a trailing underscore.
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 program—but 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.
Consider Perl, for instance. The tutorial manuals that people normally use are non-free.
How did this come about? Because the authors of those manuals published them with
restrictive terms—no copying, no modification, source files not available—which exclude
them from the free software world.
That wasn’t the first time this sort of thing happened, and it was far from the last.
Many times we have heard a GNU user eagerly describe a manual that he is writing, his
intended contribution to the community, only to learn that he had ruined everything by
signing a publication contract to make it non-free.
Free documentation, like free software, is a matter of freedom, not price. The problem
with the non-free manual is not that publishers charge a price for printed copies—that in
itself is fine. (The Free Software Foundation sells printed copies of manuals, too.) The
problem is the restrictions on the use of the manual. Free manuals are available in source
code form, and give you permission to copy and modify. Non-free manuals do not allow
this.
The criteria of freedom for a free manual are roughly the same as for free software.
Redistribution (including the normal kinds of commercial redistribution) must be permitted,
so that the manual can accompany every copy of the program, both on-line and on paper.
Permission for modification of the technical content is crucial too. When people mod-
ify the software, adding or changing features, if they are conscientious they will change
the manual too—so they can provide accurate and clear documentation for the modified
program. A manual that leaves you no choice but to write a new manual to document a
changed version of the program is not really available to our community.
Some kinds of limits on the way modification is handled are acceptable. For example,
requirements to preserve the original author’s copyright notice, the distribution terms, or
the list of authors, are ok. It is also no problem to require modified versions to include
notice that they were modified. Even entire sections that may not be deleted or changed
are acceptable, as long as they deal with nontechnical topics (like this one). These kinds of
restrictions are acceptable because they don’t obstruct the community’s normal use of the
manual.
However, it must be possible to modify all the technical content of the manual, and then
distribute the result in all the usual media, through all the usual channels. Otherwise, the
restrictions obstruct the use of the manual, it is not free, and we need another manual to
replace it.
Please spread the word about this issue. Our community continues to lose manuals
to proprietary publishing. If we spread the word that free software needs free reference
manuals and free tutorials, perhaps the next person who wants to contribute by writing
documentation will realize, before it is too late, that only free manuals contribute to the
free software community.
If you are writing documentation, please insist on publishing it under the GNU Free
Documentation License or another free documentation license. Remember that this deci-
sion requires your approval—you don’t have to let the publisher decide. Some commercial
publishers will use a free license if you insist, but they will not propose the option; it is up
to you to raise the issue and say firmly that this is what you want. If the publisher you
are dealing with refuses, please try other publishers. If you’re not sure whether a proposed
license is free, write to [email protected].
Summary of GDB 3
You can encourage commercial publishers to sell more free, copylefted manuals and
tutorials by buying them, and particularly by buying copies from the publishers that paid
for their writing or for major improvements. Meanwhile, try to avoid buying non-free
documentation at all. Check the distribution terms of a manual before you buy it, and
insist that whoever seeks your business must respect your freedom. Check the history of
the book, and try to reward the publishers that have paid or pay the authors to work on it.
The Free Software Foundation maintains a list of free documentation published by other
publishers, at http://www.fsf.org/doc/other-free-books.html.
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 (releases 5.0 and 5.1);
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 and Daniel Berlin. 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 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 DWARF2 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 con-
tributed 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
4 Debugging with GDB
Nighthawk CX-UX support. Chris Smith contributed Convex support (and Fortran de-
bugging). Jonathan Stone contributed Pyramid support. Michael Tiemann contributed
SPARC support. Tim Tucker contributed support for the Gould NP1 and Gould Powern-
ode. 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 sup-
port, 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.
Hitachi America, Ltd. sponsored the support for H8/300, H8/500, and Super-H proces-
sors.
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 PA-
RISC 2.0 architecture, HP-UX 10.20, 10.30, and 11.0 (narrow mode), HP’s implementation
of kernel threads, HP’s 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 provided HP-specific information in this manual.
DJ Delorie ported GDB to MS-DOS, for the DJGPP project. Robert Hoehne made
significant contributions to the DJGPP port.
Cygnus Solutions has sponsored GDB maintenance and much of its development since
1991. Cygnus engineers who have worked on GDB fulltime 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,
Summary of GDB 5
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.
6 Debugging with GDB
Chapter 1: A Sample GDB Session 7
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
Let us use GDB to try to see what is going on.
$ gdb m4
GDB is free software and you are welcome to 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.
foo
0000
To trigger the breakpoint, we call changequote. GDB suspends execution of m4, displaying
information about the context where it stops.
changequote(<QUOTE>,<UNQUOTE>)
(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);
The last line displayed looks a little odd; we can examine the variables lquote and rquote
to see if they are in fact the new left and right quotes we specified. We use the command
p (print) to see their values.
(gdb) p lquote
$1 = 0x35d40 "<QUOTE>"
(gdb) p rquote
$2 = 0x35d50 "<UNQUOTE>"
lquote and rquote are indeed the new left and right quotes. To look at some context, we
can display ten lines of source surrounding the current line with the l (list) command.
(gdb) l
533 xfree(rquote);
534
535 lquote = (lq == nil || *lq == ’\0’) ? def_lquote\
: xstrdup (lq);
536 rquote = (rq == nil || *rq == ’\0’) ? def_rquote\
: xstrdup (rq);
537
538 len_lquote = strlen(rquote);
539 len_rquote = strlen(lquote);
540 }
541
542 void
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
That certainly looks wrong, assuming len_lquote and len_rquote are meant to be the
lengths of lquote and rquote respectively. We can set them to better values using the p
command, since it can print the value of any expression—and that expression can include
subroutine calls and assignments.
(gdb) p len lquote=strlen(lquote)
10 Debugging with GDB
$5 = 7
(gdb) p len rquote=strlen(rquote)
$6 = 9
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 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 exe-
cuting. We can end our GDB session with the GDB quit command.
(gdb) quit
Chapter 2: Getting In and Out of GDB 11
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.
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 file’s 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 14.1 [Commands to specify
files], page 127, 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
-cd directory
Run GDB using directory as its working directory, instead of the current direc-
tory.
-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 sub-
process. 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 22 [Annotations], page 183). 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 pro-
cesses 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 don’t need to wait for control to return to GDB be-
fore you type the next command. (Note: as of version 5.1, 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.
-noasync Disable the asynchronous event loop for the command-line interface.
--args Change interpretation of command line so that arguments following the exe-
cutable file are passed as command line arguments to the inferior. This option
stops option processing.
-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 program’s standard input and output.
-tui Activate the Terminal User Interface when starting. The Terminal User Inter-
face manages several text windows on the terminal, showing source, assembly,
1
GDB built with djgpp tools for MS-DOS/MS-Windows supports this mode of operation, but the event
loop is suspended when the debuggee runs.
Chapter 2: Getting In and Out of GDB 15
registers and GDB command outputs (see Chapter 20 [GDB Text User Inter-
face], page 177). Do not use this option if you run GDB from Emacs (see
Chapter 21 [Using GDB under gnu Emacs], page 181).
-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.
‘--interpreter=mi’ (or ‘--interpreter=mi1’) causes GDB to use the
gdb/mi interface (see Chapter 23 [The gdb/mi Interface], page 191). The
older gdb/mi interface, included in GDB version 5.0 can be selected with
‘--interpreter=mi0’.
-write Open the executable and core files for both reading and writing. This is equiv-
alent to the ‘set write on’ command inside GDB (see Section 13.6 [Patching],
page 126).
-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.
An interrupt (often C-c) does not exit from GDB, but rather terminates the action of
any GDB command that is in progress and returns to GDB command level. It is safe to
type the interrupt character at any time because GDB does not allow it to take effect until
a time when it is safe.
If you have been using GDB to control an attached process or device, you can release
it with the detach command (see Section 4.7 [Debugging an already-running process],
page 27).
The utility make is often needed in development environments. You do not have to use
the shell command for this purpose in GDB:
make make-args
Execute the make program with the specified arguments. This is equivalent to
‘shell make make-args’.
Chapter 3: GDB Commands 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).
GDB alters your input line to the following, and rings a bell:
(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 11.4.1.3 [C++ expressions],
page 104. You can use the command set overload-resolution off to disable overload
resolution; see Section 11.4.1.7 [GDB features for C++], page 106.
help
h 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:
List of commands:
20 Debugging with GDB
info 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.
Chapter 3: GDB Commands 21
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.
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 Debugging with GDB
Chapter 4: Running Programs Under GDB 23
program. (You can change it after starting your program, but such changes only affect your
program the next time you start it.) This information may be divided into four categories:
The arguments.
Specify the arguments to give your program as the arguments of the run com-
mand. If a shell is available on your target, the shell is used to pass the argu-
ments, so that you may use normal conventions (such as wildcard expansion or
variable substitution) in describing the arguments. In Unix systems, you can
control which shell is used with the SHELL environment variable. See Section 4.3
[Your program’s arguments], page 24.
The environment.
Your program normally inherits its environment from GDB, but you can use the
GDB commands set environment and unset environment to change parts of
the environment that affect your program. See Section 4.4 [Your program’s
environment], page 25.
The working directory.
Your program inherits its working directory from GDB. You can set the GDB
working directory with the cd command in GDB. See Section 4.5 [Your pro-
gram’s working directory], page 26.
The standard input and output.
Your program normally uses the same device for standard input and standard
output as GDB is using. You can redirect input and output in the run command
line, or you can use the tty command to set a different device for your program.
See Section 4.6 [Your program’s input and output], page 26.
Warning: While input and output redirection work, you cannot use pipes to
pass the output of the program you are debugging to another program; if you
attempt this, GDB is likely to wind up debugging the wrong program.
When you issue the run command, your program begins to execute immediately. See
Chapter 5 [Stopping and continuing], page 33, for discussion of how to arrange for your
program to stop. Once your program has stopped, you may call functions in your program,
using the print or call commands. See Chapter 8 [Examining Data], page 63.
If the modification time of your symbol file has changed since the last time GDB read
its symbols, GDB discards its symbol table, and reads it again. When it does this, GDB
tries to retain your current breakpoints.
run with no arguments uses the same arguments used by the previous run, or those set
by the set args command.
set args 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.
path directory
Add directory to the front of the PATH environment variable (the search path
for executables) that will be passed to your program. The value of PATH used
by GDB does not change. You may specify several directory names, separated
by whitespace or by a system-dependent separator character (‘:’ on Unix, ‘;’
on MS-DOS and MS-Windows). If directory is already in the path, it is moved
to the front, so it is searched sooner.
You can use the string ‘$cwd’ to refer to whatever is the current working di-
rectory at the time GDB searches the path. If you use ‘.’ instead, it refers
to the directory where you executed the path command. GDB replaces ‘.’ in
the directory argument (with the current path) before adding directory to the
search path.
show paths
Display the list of search paths for executables (the PATH environment variable).
show environment [varname]
Print the value of environment variable varname to be given to your program
when it starts. If you do not supply varname, print the names and values of
all environment variables to be given to your program. You can abbreviate
environment as env.
set environment varname [=value]
Set environment variable varname to value. The value changes for your program
only, not for GDB itself. value may be any string; the values of environment
variables are just strings, and any interpretation is supplied by your program
itself. The value parameter is optional; if it is eliminated, the variable is set to
a null value.
For example, this command:
26 Debugging with GDB
cd directory
Set the GDB working directory to directory.
pwd Print the GDB working directory.
info terminal
Displays information recorded by GDB about the terminal modes your program
is using.
You can redirect your program’s input and/or output using shell redirection with the
run command. For example,
run > outfile
starts your program, diverting its output to the file ‘outfile’.
Another way to specify where your program should do input and output is with the
tty command. This command accepts a file name as argument, and causes this file to be
Chapter 4: Running Programs Under GDB 27
the default for future run commands. It also resets the controlling terminal for the child
process, for future run commands. For example,
tty /dev/ttyb
directs that processes started with subsequent run commands default to do input and output
on the terminal ‘/dev/ttyb’ and have that as their controlling terminal.
An explicit redirection in run overrides the tty command’s effect on the input/output
device, but not its effect on the controlling terminal.
When you use the tty command or redirect input in the run command, only the input
for your program is affected. The input for GDB still comes from your terminal.
detach When you have finished debugging the attached process, you can use the detach
command to release it from GDB control. Detaching the process continues its
execution. After the detach command, that process and GDB become com-
pletely 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.
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 18.6 [Optional warnings and messages], page 168).
28 Debugging with GDB
info threads
Display a summary of all threads currently in your program. GDB displays for
each thread (in this order):
1. the thread number assigned by GDB
2. the target system’s thread identifier (systag)
3. the current stack frame summary for that thread
An asterisk ‘*’ to the left of the GDB thread number indicates the current
thread.
For example,
(gdb) info threads
3 process 35 thread 27 0x34e5 in sigpause ()
2 process 35 thread 23 0x34e5 in sigpause ()
* 1 process 35 thread 13 main (argc=1, argv=0x7ffffff8)
at threadtest.c:68
On HP-UX systems:
For debugging purposes, GDB associates its own thread number—a small integer as-
signed in thread-creation order—with each thread in your program.
Whenever GDB detects a new thread in your program, it displays both GDB’s thread
number and the target system’s 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
[New thread 2 (system thread 26594)]
when GDB notices a new thread.
info threads
Display a summary of all threads currently in your program. GDB displays for
each thread (in this order):
1. the thread number assigned by GDB
2. the target system’s thread identifier (systag)
3. the current stack frame summary for that thread
An asterisk ‘*’ to the left of the GDB thread number indicates the current
thread.
For example,
(gdb) info threads
* 3 system thread 26607 worker (wptr=0x7b09c318 "@") \
at quicksort.c:137
30 Debugging with GDB
from /usr/lib/libc.2
1 system thread 27905 0x7b003498 in _brk () \
from /usr/lib/libc.2
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 process 35 thread 23]
0x34e5 in sigpause ()
As with the ‘[New ...]’ message, the form of the text after ‘Switching to’
depends on your system’s conventions for identifying threads.
thread apply [threadno] [all] args
The thread apply command allows you to apply a command to one or more
threads. Specify the numbers of the threads that you want affected with the
command argument threadno. threadno is the internal GDB thread number,
as shown in the first field of the ‘info threads’ display. To apply a command
to all threads, use thread apply all args.
Section 4.7 [Attach], page 27). From that point on you can debug the child process just like
any other process which you attached to.
On HP-UX (11.x and later only?), GDB provides support for debugging programs that
create additional processes using the fork or vfork function.
By default, when a program forks, GDB will continue to debug the parent process and
the child process will run unimpeded.
If you want to follow the child process instead of the parent process, use the command
set follow-fork-mode.
info program
Display information about the status of your program: whether it is running
or not, what process it is, and why it stopped.
Language: English
HARRY E. WEDECK
Lecturer in Classics, Brooklyn College of the City University, N. Y.
Fellow, International Institute of Arts and Letters
© Copyright, 1963
I Antiquity 1
II Greek 67
III Romans 82
IV Orient 119
While I was thus at prayers, an old woman, with her hair about
her eyes, and disfigur’d with a mournful habit, coming in, disturb’d
my devotions; when taking hold of me, she drew all fear out of the
entry; and “what hag,” said she, “has devour’d your manhood? Or
what ominous carcase have you stumbl’d over in your nightly walks?
You have not acquitted your self above a boy; but faint, weak, and
like a horse o’re-charg’d in a steep, tyr’d have lost your toyl and
sweat; nor content to sin alone, but have unreveng’d against me,
provokt the offended gods?”
When leading me, obedient to all her commands, a second time
to the cell of a neighboring priestess of Priapus, she threw me upon
the bed, and taking up a stick that fastened the door, reveng’d her
self on me, that very patiently receiv’d her fury: and at the first
stroak, if the breaking of the stick had not lessened its force, she
might have broke my head and arm.
I groan’d, and hiding with my arm my head, in a flood of tears
lean’d on the pillow: Nor did she then, less troubled, sit on the bed,
and began in a shrill voice, to blame her age, till the priestess came
in upon us; and “what,” said she, “do you do in my chappel, as if
some funeral had lately been, rather than a holy-day, in which, even
the mournful are merry?”
“Alas, my Enothea!” said she, “this youth was born under an ill
star; for neither boy nor maid can raise him to a perfect appetite;
you ne’re beheld a more unhappy man: In his garden the weak
willow, not the lusty cedar grows; in short, you may guess what he
is, that cou’d rise unblest from Circe’s bed.”
Upon this, Enothea fixt her self between us, and moving her
head a while; “I,” said she, “am the only one that can give remedy
for that disease; and not to delay it, let him sleep with me to-night;
and next morning, examine how vigorous I shall have made him:
“All Nature’s work my magick powers obey,
The blooming earth shall wither and decay,
And when I please, agen be fresh and gay.
From rugged rocks, I make sweet waters flow,
And raging billows to me humbly bow.
With rivers, winds, when I command, obey,
And at my feet, their fans contracted lay,
Tygers and dragons too, my will obey,
But these are small, when of my magick verse,
Descending Cynthia does the power confess.
When my commands, make trembling Phoebus reign,
His fiery steeds, their journey back again.
Such power have charms, by whose prevailing aid
The fury of the raging bulls was laid.
The Heaven-born Circe, with her magic song,
Ulysses’s men, did unto monsters turn.
Proteus, with this assum’d, what shape he wou’d.
I, who this art so long have understood,
Can send proud Ida’s top into the main,
And make the billows bear it up again.”
By this time the other two had eat up the pieces of the bean
that lay scatter’d on the floor, and having lost their leader, return’d to
the temple. When glad of the booty and my revenge, I heal’d the
slight old woman’s anger, I design’d to make off; and taking up my
cloaths, began my march; nor had I reach’d the door, e’re I saw
Enothea bringing in her hand an earthen pot fill’d with fire; upon
which I retreated, and throwing down my cloaths, fixt my self in the
entry, as if I were impatiently expecting her coming.
Enothea, entring, plac’d the fire, that with broken sticks she had
got together, and having heapt more wood upon those, began to
excuse her stay, that her friend wou’d not let her go before she had,
against the laws of drinking, taken off three healths together. When
looking about her, “What,” said she, “have you been doing in my
absence? Where’s the bean?”
I, who thought I had behav’d my self very honorably, told her
the whole fight; and to end her grief for the loss of her bean,
presented the goose: when I shew’d the goose, the old woman set
up such an outcry, that you wou’d have thought the geese were re-
entering the place.
In confusion and amaz’d at so strange a humor, I askt the
meaning of her passion? or why she pity’d the goose rather than
me.
But wringing her hands, “you wicked wretch,” said she, “d’ye
speak too? D’ye know what you’ve done? You’ve killed the gods
delight, a goose the pleasure of all matrons: And, lest you shou’d
think your self innocent, if a magistrate shou’d hear of it, you’d be
hang’d. You have defil’d with blood my cell, that to this day had
been inviolate. You have done that, for which, if any’s so malicious,
he may expel me my office.”
She said, and trembling, rends her aged hairs,
And both her cheeks with wilder fury tears:
Sad murmurs from her troubl’d breast arise,
A shower of tears there issu’d from her eyes.
And down her face a rapid deluge run,
Such as is seen, when a hills frosty crown,
By warm Favonius is melted down.
ebookgate.com