]> Git Repo - binutils.git/blame - gdb/doc/gdb.texinfo
Added \n to error message.
[binutils.git] / gdb / doc / gdb.texinfo
CommitLineData
b80282d5 1_dnl__ -*-Texinfo-*-
1041a570 2_dnl__ Copyright (c) 1988 1989 1990 1991 1992 Free Software Foundation, Inc.
b21b18e1 3_dnl__ $Id$<>_dnl__
29a2b744 4\input texinfo @c -*-texinfo-*-
1041a570 5@c Copyright (c) 1988 1989 1990 1991 1992 Free Software Foundation, Inc.
29a2b744 6@c %**start of header
5a131cc7 7@setfilename _GDBP__.info
29a2b744 8_if__(_GENERIC__)
a6463583 9@settitle Debugging with _GDBN__
29a2b744
RP
10_fi__(_GENERIC__)
11_if__(!_GENERIC__)
a6463583 12@settitle Debugging with _GDBN__ (_HOST__)
29a2b744
RP
13_fi__(!_GENERIC__)
14@setchapternewpage odd
fb4bb43e
RP
15@c @smallbook
16@c @cropmarks
29a2b744
RP
17@c %**end of header
18
19@finalout
20@syncodeindex ky cp
21
22_0__@c ===> NOTE! <==_1__
23@c Determine the edition number in *three* places by hand:
24@c 1. First ifinfo section 2. title page 3. top node
25@c To find the locations, search for !!set
26
27@c The following is for Pesch for his RCS system.
28@c This revision number *not* the same as the Edition number.
29@tex
30\def\$#1${{#1}} % Kluge: collect RCS revision info without $...$
31\xdef\manvers{\$Revision$} % For use in headers, footers too
32@end tex
33
d24e0922 34@c GDB CHANGELOG CONSULTED BETWEEN:
29a2b744
RP
35@c Fri Oct 11 23:27:06 1991 John Gilmore (gnu at cygnus.com)
36@c Sat Dec 22 02:51:40 1990 John Gilmore (gnu at cygint)
37
9c3ad547 38@c THIS MANUAL REQUIRES TEXINFO-2 macros and info-makers to format properly.
29a2b744 39
b7becc8f
RP
40@ifinfo
41@format
42START-INFO-DIR-ENTRY
29a2b744 43* Gdb: (gdb). The GNU debugger.
b7becc8f
RP
44END-INFO-DIR-ENTRY
45@end format
46@end ifinfo
5a131cc7
RP
47_if__(0)
48
a6d0b6d3
RP
49NOTE: this manual is marked up for preprocessing with a collection
50of m4 macros called "pretex.m4".
51
9bcc06ef
RP
52THIS IS THE SOURCE PRIOR TO PREPROCESSING. The full source needs to
53be run through m4 before either tex- or info- formatting: for example,
08665207 54_0__
3e0d0a27 55 m4 pretex.m4 none.m4 all.m4 gdb.texinfo >gdb-all.texinfo
70b88761 56will produce (assuming your path finds either GNU m4 >= 0.84, or SysV
1041a570 57m4; Berkeley will not do) a file suitable for formatting. See the text in
70b88761 58"pretex.m4" for a fuller explanation (and the macro definitions).
29a2b744 59_1__
e91b87a3 60
9bcc06ef 61_fi__(0)
70b88761 62@c
70b88761
RP
63@ifinfo
64This file documents the GNU debugger _GDBN__.
65
29a2b744 66@c !!set edition, date, version
a37d76c9 67This is Edition 4.06, October 1992,
a6463583 68of @cite{Debugging with _GDBN__: the GNU Source-Level Debugger}
29a2b744
RP
69for GDB Version _GDB_VN__.
70
95d5ceb9 71Copyright (C) 1988, 1989, 1990, 1991, 1992 Free Software Foundation, Inc.
70b88761
RP
72
73Permission is granted to make and distribute verbatim copies of
74this manual provided the copyright notice and this permission notice
75are preserved on all copies.
76
77@ignore
78Permission is granted to process this file through TeX and print the
79results, provided the printed document carries copying permission
80notice identical to this one except for the removal of this paragraph
81(this paragraph not being relevant to the printed manual).
82
83@end ignore
84Permission is granted to copy and distribute modified versions of this
85manual under the conditions for verbatim copying, provided also that the
86section entitled ``GNU General Public License'' is included exactly as
87in the original, and provided that the entire resulting derived work is
88distributed under the terms of a permission notice identical to this
89one.
90
91Permission is granted to copy and distribute translations of this manual
92into another language, under the above conditions for modified versions,
93except that the section entitled ``GNU General Public License'' may be
94included in a translation approved by the Free Software Foundation
95instead of in the original English.
96@end ifinfo
1041a570 97
70b88761 98@titlepage
a6463583 99@title Debugging with _GDBN__
95d5ceb9 100@subtitle The GNU Source-Level Debugger
70b88761 101_if__(!_GENERIC__)
c7cb8acb 102@subtitle on _HOST__ Systems
70b88761
RP
103_fi__(!_GENERIC__)
104@sp 1
29a2b744 105@c !!set edition, date, version
a6463583 106@subtitle Edition 4.06, for _GDBN__ version _GDB_VN__
a37d76c9 107@subtitle October 1992
29a2b744 108@author by Richard M. Stallman and Roland H. Pesch
70b88761
RP
109@page
110@tex
111{\parskip=0pt
93ac5532 112\hfill pesch\@cygnus.com\par
a6463583 113\hfill {\it Debugging with _GDBN__}, \manvers\par
70b88761
RP
114\hfill \TeX{}info \texinfoversion\par
115}
116@end tex
117
118@vskip 0pt plus 1filll
1041a570 119Copyright @copyright{} 1988, 1989, 1990, 1991, 1992 Free Software Foundation, Inc.
70b88761
RP
120
121Permission is granted to make and distribute verbatim copies of
122this manual provided the copyright notice and this permission notice
123are preserved on all copies.
124
125Permission is granted to copy and distribute modified versions of this
126manual under the conditions for verbatim copying, provided also that the
127section entitled ``GNU General Public License'' is included exactly as
128in the original, and provided that the entire resulting derived work is
129distributed under the terms of a permission notice identical to this
130one.
131
132Permission is granted to copy and distribute translations of this manual
133into another language, under the above conditions for modified versions,
134except that the section entitled ``GNU General Public License'' may be
135included in a translation approved by the Free Software Foundation
136instead of in the original English.
137@end titlepage
138@page
139
70b88761 140@ifinfo
4eb4cf57 141@node Top
a6463583 142@top Debugging with _GDBN__
29a2b744
RP
143
144This file describes _GDBN__, the GNU symbolic debugger.
145
146@c !!set edition, date, version
a37d76c9 147This is Edition 4.06, October 1992, for GDB Version _GDB_VN__.
70b88761
RP
148@end ifinfo
149
150@menu
b80282d5 151* Summary:: Summary of _GDBN__
4eb4cf57 152_if__(_GENERIC__ || !_H8__)
c7cb8acb 153* New Features:: New features since GDB version 3.5
4eb4cf57 154_fi__(_GENERIC__ || !_H8__)
0f153e74 155_if__(!_BARE__)
95d5ceb9 156* Sample Session:: A sample _GDBN__ session
0f153e74 157_fi__(!_BARE__)
29a2b744
RP
158* Invocation:: Getting in and out of _GDBN__
159* Commands:: _GDBN__ commands
160* Running:: Running programs under _GDBN__
161* Stopping:: Stopping and continuing
162* Stack:: Examining the stack
163* Source:: Examining source files
164* Data:: Examining data
4eb4cf57 165_if__(!_CONLY__)
29a2b744 166* Languages:: Using _GDBN__ with different languages
4eb4cf57
RP
167_fi__(!_CONLY__)
168_if__(_CONLY__)
169* C:: C and C++
170_fi__(_CONLY__)
29a2b744
RP
171* Symbols:: Examining the symbol table
172* Altering:: Altering execution
173* _GDBN__ Files:: _GDBN__'s files
174* Targets:: Specifying a debugging target
c2bbbb22 175* Controlling _GDBN__:: Controlling _GDBN__
29a2b744 176* Sequences:: Canned sequences of commands
4eb4cf57 177_if__(!_DOSHOST__)
b80282d5 178* Emacs:: Using _GDBN__ under GNU Emacs
4eb4cf57 179_fi__(!_DOSHOST__)
29a2b744 180* _GDBN__ Bugs:: Reporting bugs in _GDBN__
77fe5411 181_if__(_GENERIC__||!_H8__)
e251e767 182* Renamed Commands::
77fe5411 183_fi__(_GENERIC__||!_H8__)
77b46d13 184* Formatting Documentation:: How to format and print GDB documentation
c7cb8acb 185* Installing GDB:: Installing GDB
b80282d5
RP
186* Copying:: GNU GENERAL PUBLIC LICENSE
187* Index:: Index
70b88761
RP
188@end menu
189
4eb4cf57 190@node Summary
70b88761
RP
191@unnumbered Summary of _GDBN__
192
193The purpose of a debugger such as _GDBN__ is to allow you to see what is
194going on ``inside'' another program while it executes---or what another
1041a570 195program was doing at the moment it crashed.
70b88761
RP
196
197_GDBN__ can do four main kinds of things (plus other things in support of
1041a570 198these) to help you catch bugs in the act:
70b88761
RP
199
200@itemize @bullet
201@item
202Start your program, specifying anything that might affect its behavior.
203
204@item
205Make your program stop on specified conditions.
206
207@item
208Examine what has happened, when your program has stopped.
209
210@item
211Change things in your program, so you can experiment with correcting the
212effects of one bug and go on to learn about another.
213@end itemize
214
0f153e74 215_if__(!_CONLY__)
c2bbbb22
RP
216You can use _GDBN__ to debug programs written in C, C++, and Modula-2.
217Fortran support will be added when a GNU Fortran compiler is ready.
0f153e74 218_fi__(!_CONLY__)
70b88761
RP
219
220@menu
b80282d5
RP
221* Free Software:: Free Software
222* Contributors:: Contributors to GDB
70b88761
RP
223@end menu
224
4eb4cf57 225@node Free Software
70b88761 226@unnumberedsec Free Software
1041a570
RP
227
228_GDBN__ is @dfn{free software}, protected by the GNU General Public License
229(GPL). The GPL gives you the freedom to copy or adapt a licensed
70b88761
RP
230program---but every person getting a copy also gets with it the
231freedom to modify that copy (which means that they must get access to
232the source code), and the freedom to distribute further copies.
233Typical software companies use copyrights to limit your freedoms; the
234Free Software Foundation uses the GPL to preserve these freedoms.
235
236Fundamentally, the General Public License is a license which says that
29a2b744 237you have these freedoms and that you cannot take these freedoms away
70b88761
RP
238from anyone else.
239
0f153e74 240_if__(!_AGGLOMERATION__)
29a2b744 241For full details, @pxref{Copying, ,GNU GENERAL PUBLIC LICENSE}.
0f153e74 242_fi__(!_AGGLOMERATION__)
1041a570 243
4eb4cf57 244@node Contributors
70b88761
RP
245@unnumberedsec Contributors to GDB
246
247Richard Stallman was the original author of GDB, and of many other GNU
248programs. Many others have contributed to its development. This
249section attempts to credit major contributors. One of the virtues of
250free software is that everyone is free to contribute to it; with
251regret, we cannot actually acknowledge everyone here. The file
252@file{ChangeLog} in the GDB distribution approximates a blow-by-blow
253account.
254
255Changes much prior to version 2.0 are lost in the mists of time.
256
257@quotation
258@emph{Plea:} Additions to this section are particularly welcome. If you
259or your friends (or enemies; let's be evenhanded) have been unfairly
260omitted from this list, we would like to add your names!
261@end quotation
262
263So that they may not regard their long labor as thankless, we
69bbcf05 264particularly thank those who shepherded GDB through major releases: Stu
6f3ec223
RP
265Grossman and John Gilmore (releases 4.6, 4.5, 4.4), John Gilmore
266(releases 4.3, 4.2, 4.1, 4.0, and 3.9); Jim Kingdon (releases 3.5, 3.4,
2673.3); and Randy Smith (releases 3.2, 3.1, 3.0). As major maintainer of
268GDB for some period, each contributed significantly to the structure,
269stability, and capabilities of the entire debugger.
70b88761
RP
270
271Richard Stallman, assisted at various times by Pete TerMaat, Chris
272Hanson, and Richard Mlynarik, handled releases through 2.8.
273
274Michael Tiemann is the author of most of the GNU C++ support in GDB,
275with significant additional contributions from Per Bothner. James
276Clark wrote the GNU C++ demangler. Early work on C++ was by Peter
277TerMaat (who also did much general update work leading to release 3.0).
278
1041a570
RP
279GDB 4 uses the BFD subroutine library to examine multiple
280object-file formats; BFD was a joint project of David V.
281Henkel-Wallace, Rich Pixley, Steve Chamberlain, and John Gilmore.
70b88761 282
1041a570
RP
283David Johnson wrote the original COFF support; Pace Willison did
284the original support for encapsulated COFF.
70b88761
RP
285
286Adam de Boor and Bradley Davis contributed the ISI Optimum V support.
287Per Bothner, Noboyuki Hikichi, and Alessandro Forin contributed MIPS
1041a570
RP
288support. Jean-Daniel Fekete contributed Sun 386i support. Chris
289Hanson improved the HP9000 support. Noboyuki Hikichi and Tomoyuki
290Hasei contributed Sony/News OS 3 support. David Johnson contributed
291Encore Umax support. Jyrki Kuoppala contributed Altos 3068 support.
292Keith Packard contributed NS32K support. Doug Rabson contributed
293Acorn Risc Machine support. Chris Smith contributed Convex support
294(and Fortran debugging). Jonathan Stone contributed Pyramid support.
295Michael Tiemann contributed SPARC support. Tim Tucker contributed
296support for the Gould NP1 and Gould Powernode. Pace Willison
297contributed Intel 386 support. Jay Vosburgh contributed Symmetry
298support.
70b88761 299
c338a2fd
RP
300Rich Schaefer and Peter Schauer helped with support of SunOS shared
301libraries.
70b88761
RP
302
303Jay Fenlason and Roland McGrath ensured that GDB and GAS agree about
304several machine instruction sets.
305
1041a570
RP
306Patrick Duval, Ted Goldstein, Vikram Koka and Glenn Engel helped
307develop remote debugging. Intel Corporation and Wind River Systems
308contributed remote debugging modules for their products.
70b88761 309
1041a570
RP
310Brian Fox is the author of the readline libraries providing
311command-line editing and command history.
70b88761 312
1041a570
RP
313Andrew Beers of SUNY Buffalo wrote the language-switching code and
314the Modula-2 support, and contributed the Languages chapter of this
315manual.
c2bbbb22 316
6f3ec223
RP
317Fred Fish wrote most of the support for Unix System Vr4, and enhanced
318the command-completion support to cover C++ overloaded symbols.
14d01801 319
4eb4cf57
RP
320_if__(_GENERIC__ || !_H8__)
321@node New Features
c7cb8acb 322@unnumbered New Features since GDB version 3.5
70b88761
RP
323
324@table @emph
325@item Targets
326Using the new command @code{target}, you can select at runtime whether
327you are debugging local files, local processes, standalone systems over
b80282d5
RP
328a serial port, realtime systems over a TCP/IP connection, etc. The
329command @code{load} can download programs into a remote system. Serial
b21b18e1
RP
330stubs are available for Motorola 680x0, Intel 80386, and Sparc remote
331systems; GDB also supports debugging realtime processes running under
b80282d5 332VxWorks, using SunRPC Remote Procedure Calls over TCP/IP to talk to a
b21b18e1
RP
333debugger stub on the target system. Internally, GDB now uses a function
334vector to mediate access to different targets; if you need to add your
335own support for a remote protocol, this makes it much easier.
70b88761
RP
336
337@item Watchpoints
c7cb8acb 338GDB now sports watchpoints as well as breakpoints. You can use a
70b88761
RP
339watchpoint to stop execution whenever the value of an expression
340changes, without having to predict a particular place in your program
341where this may happen.
342
b80282d5
RP
343@item Wide Output
344Commands that issue wide output now insert newlines at places designed
345to make the output more readable.
346
70b88761 347@item Object Code Formats
c7cb8acb 348GDB uses a new library called the Binary File Descriptor (BFD)
3d3ab540
RP
349Library to permit it to switch dynamically, without reconfiguration or
350recompilation, between different object-file formats. Formats currently
351supported are COFF, a.out, and the Intel 960 b.out; files may be read as
352.o's, archive libraries, or core dumps. BFD is available as a
353subroutine library so that other programs may take advantage of it, and
354the other GNU binary utilities are being converted to use it.
70b88761 355
b80282d5 356@item Configuration and Ports
70b88761 357Compile-time configuration (to select a particular architecture and
7463aadd 358operating system) is much easier. The script @code{configure} now
c7cb8acb
RP
359allows you to configure GDB as either a native debugger or a
360cross-debugger. @xref{Installing GDB}, for details on how to
6a8cb0e7 361configure.
70b88761
RP
362
363@item Interaction
c7cb8acb 364The user interface to GDB's control variables has been simplified
70b88761
RP
365and consolidated in two commands, @code{set} and @code{show}. Output
366lines are now broken at readable places, rather than overflowing onto
367the next line. You can suppress output of machine-level addresses,
368displaying only source language information.
369
b80282d5 370@item C++
c7cb8acb 371GDB now supports C++ multiple inheritance (if used with a GCC
b80282d5 372version 2 compiler), and also has limited support for C++ exception
c7cb8acb 373handling, with the commands @code{catch} and @code{info catch}: GDB
b80282d5
RP
374can break when an exception is raised, before the stack is peeled back
375to the exception handler's context.
70b88761 376
c2bbbb22 377@item Modula-2
c7cb8acb 378GDB now has preliminary support for the GNU Modula-2 compiler,
c2bbbb22 379currently under development at the State University of New York at
c7cb8acb 380Buffalo. Coordinated development of both GDB and the GNU Modula-2
5b0fdf7b
RP
381compiler will continue into 1992. Other Modula-2 compilers are
382currently not supported, and attempting to debug programs compiled with
383them will likely result in an error as the symbol table of the
384executable is read in.
c2bbbb22 385
70b88761 386@item Command Rationalization
c7cb8acb 387Many GDB commands have been renamed to make them easier to remember
70b88761
RP
388and use. In particular, the subcommands of @code{info} and
389@code{show}/@code{set} are grouped to make the former refer to the state
c7cb8acb 390of your program, and the latter refer to the state of GDB itself.
70b88761
RP
391@xref{Renamed Commands}, for details on what commands were renamed.
392
70b88761 393@item Shared Libraries
77b46d13
JG
394GDB 4 can debug programs and core files that use SunOS, SVR4, or IBM RS/6000
395shared libraries.
b80282d5
RP
396
397@item Reference Card
6f3ec223
RP
398GDB 4 has a reference card. @xref{Formatting Documentation,,Formatting
399the Documentation}, for instructions to print it.
70b88761
RP
400
401@item Work in Progress
402Kernel debugging for BSD and Mach systems; Tahoe and HPPA architecture
403support.
70b88761 404@end table
4eb4cf57 405_fi__(_GENERIC__ || !_H8__)
70b88761 406
0f153e74 407_if__(!_BARE__)
4eb4cf57 408@node Sample Session
70b88761
RP
409@chapter A Sample _GDBN__ Session
410
411You can use this manual at your leisure to read all about _GDBN__.
412However, a handful of commands are enough to get started using the
413debugger. This chapter illustrates these commands.
414
415@iftex
6ca72cc6 416In this sample session, we emphasize user input like this: @b{input},
70b88761
RP
417to make it easier to pick out from the surrounding output.
418@end iftex
419
420@c FIXME: this example may not be appropriate for some configs, where
421@c FIXME...primary interest is in remote use.
422_0__
423One of the preliminary versions of GNU @code{m4} (a generic macro
424processor) exhibits the following bug: sometimes, when we change its
425quote strings from the default, the commands used to capture one macro's
426definition in another stop working. In the following short @code{m4}
427session, we define a macro @code{foo} which expands to @code{0000}; we
29a2b744 428then use the @code{m4} built-in @code{defn} to define @code{bar} as the
70b88761
RP
429same thing. However, when we change the open quote string to
430@code{<QUOTE>} and the close quote string to @code{<UNQUOTE>}, the same
431procedure fails to define a new synonym @code{baz}:
432
433@smallexample
6ca72cc6
RP
434$ @b{cd gnu/m4}
435$ @b{./m4}
436@b{define(foo,0000)}
70b88761 437
6ca72cc6 438@b{foo}
70b88761 4390000
6ca72cc6 440@b{define(bar,defn(`foo'))}
70b88761 441
6ca72cc6 442@b{bar}
70b88761 4430000
6ca72cc6 444@b{changequote(<QUOTE>,<UNQUOTE>)}
70b88761 445
6ca72cc6
RP
446@b{define(baz,defn(<QUOTE>foo<UNQUOTE>))}
447@b{baz}
448@b{C-d}
70b88761
RP
449m4: End of input: 0: fatal error: EOF in string
450@end smallexample
451
452@noindent
453Let's use _GDBN__ to try to see what's going on.
454
455@smallexample
6ca72cc6 456$ @b{_GDBP__ m4}
203eea5d
RP
457@c FIXME: this falsifies the exact text played out, to permit smallbook
458@c FIXME... format to come out better.
459GDB is free software and you are welcome to distribute copies
460 of it under certain conditions; type "show copying" to see
461 the conditions.
462There is absolutely no warranty for GDB; type "show warranty"
463for details.
5b0fdf7b 464GDB _GDB_VN__, Copyright 1992 Free Software Foundation, Inc...
e251e767 465(_GDBP__)
70b88761
RP
466@end smallexample
467
468@noindent
1041a570
RP
469_GDBN__ reads only enough symbol data to know where to find the rest when
470needed; as a result, the first prompt comes up very quickly. We now
471tell _GDBN__ to use a narrower display width than usual, so that examples
472will fit in this manual.
70b88761
RP
473
474@smallexample
6ca72cc6 475(_GDBP__) @b{set width 70}
70b88761
RP
476@end smallexample
477
e251e767 478@noindent
29a2b744 479Let's see how the @code{m4} built-in @code{changequote} works.
70b88761
RP
480Having looked at the source, we know the relevant subroutine is
481@code{m4_changequote}, so we set a breakpoint there with _GDBN__'s
482@code{break} command.
483
484@smallexample
6ca72cc6 485(_GDBP__) @b{break m4_changequote}
70b88761
RP
486Breakpoint 1 at 0x62f4: file builtin.c, line 879.
487@end smallexample
488
489@noindent
490Using the @code{run} command, we start @code{m4} running under _GDBN__
491control; as long as control does not reach the @code{m4_changequote}
492subroutine, the program runs as usual:
493
494@smallexample
6ca72cc6 495(_GDBP__) @b{run}
e251e767 496Starting program: /work/Editorial/gdb/gnu/m4/m4
6ca72cc6 497@b{define(foo,0000)}
70b88761 498
6ca72cc6 499@b{foo}
70b88761
RP
5000000
501@end smallexample
502
503@noindent
504To trigger the breakpoint, we call @code{changequote}. _GDBN__
505suspends execution of @code{m4}, displaying information about the
506context where it stops.
507
508@smallexample
6ca72cc6 509@b{changequote(<QUOTE>,<UNQUOTE>)}
70b88761 510
203eea5d
RP
511Breakpoint 1, m4_changequote (argc=3, argv=0x33c70)
512 at builtin.c:879
38962738 513879 if (bad_argc(TOKEN_DATA_TEXT(argv[0]),argc,1,3))
70b88761
RP
514@end smallexample
515
516@noindent
517Now we use the command @code{n} (@code{next}) to advance execution to
518the next line of the current function.
519
520@smallexample
6ca72cc6 521(_GDBP__) @b{n}
203eea5d
RP
522882 set_quotes((argc >= 2) ? TOKEN_DATA_TEXT(argv[1])\
523 : nil,
70b88761
RP
524@end smallexample
525
526@noindent
527@code{set_quotes} looks like a promising subroutine. We can go into it
528by using the command @code{s} (@code{step}) instead of @code{next}.
529@code{step} goes to the next line to be executed in @emph{any}
e251e767 530subroutine, so it steps into @code{set_quotes}.
70b88761
RP
531
532@smallexample
6ca72cc6 533(_GDBP__) @b{s}
70b88761
RP
534set_quotes (lq=0x34c78 "<QUOTE>", rq=0x34c88 "<UNQUOTE>")
535 at input.c:530
536530 if (lquote != def_lquote)
537@end smallexample
538
539@noindent
29a2b744
RP
540The display that shows the subroutine where @code{m4} is now
541suspended (and its arguments) is called a stack frame display. It
542shows a summary of the stack. We can use the @code{backtrace}
543command (which can also be spelled @code{bt}), to see where we are
544in the stack as a whole: the @code{backtrace} command displays a
545stack frame for each active subroutine.
70b88761
RP
546
547@smallexample
6ca72cc6 548(_GDBP__) @b{bt}
70b88761
RP
549#0 set_quotes (lq=0x34c78 "<QUOTE>", rq=0x34c88 "<UNQUOTE>")
550 at input.c:530
203eea5d
RP
551#1 0x6344 in m4_changequote (argc=3, argv=0x33c70)
552 at builtin.c:882
70b88761
RP
553#2 0x8174 in expand_macro (sym=0x33320) at macro.c:242
554#3 0x7a88 in expand_token (obs=0x0, t=209696, td=0xf7fffa30)
555 at macro.c:71
556#4 0x79dc in expand_input () at macro.c:40
557#5 0x2930 in main (argc=0, argv=0xf7fffb20) at m4.c:195
558@end smallexample
559
560@noindent
561Let's step through a few more lines to see what happens. The first two
562times, we can use @samp{s}; the next two times we use @code{n} to avoid
563falling into the @code{xstrdup} subroutine.
1041a570 564
70b88761 565@smallexample
6ca72cc6 566(_GDBP__) @b{s}
70b88761 5670x3b5c 532 if (rquote != def_rquote)
6ca72cc6 568(_GDBP__) @b{s}
203eea5d
RP
5690x3b80 535 lquote = (lq == nil || *lq == '\0') ? \
570def_lquote : xstrdup(lq);
6ca72cc6 571(_GDBP__) @b{n}
203eea5d
RP
572536 rquote = (rq == nil || *rq == '\0') ? def_rquote\
573 : xstrdup(rq);
6ca72cc6 574(_GDBP__) @b{n}
70b88761
RP
575538 len_lquote = strlen(rquote);
576@end smallexample
577
578@noindent
579The last line displayed looks a little odd; let's examine the variables
580@code{lquote} and @code{rquote} to see if they are in fact the new left
581and right quotes we specified. We can use the command @code{p}
582(@code{print}) to see their values.
583
584@smallexample
6ca72cc6 585(_GDBP__) @b{p lquote}
70b88761 586$1 = 0x35d40 "<QUOTE>"
6ca72cc6 587(_GDBP__) @b{p rquote}
70b88761
RP
588$2 = 0x35d50 "<UNQUOTE>"
589@end smallexample
590
591@noindent
592@code{lquote} and @code{rquote} are indeed the new left and right quotes.
593Let's look at some context; we can display ten lines of source
594surrounding the current line, with the @code{l} (@code{list}) command.
595
596@smallexample
6ca72cc6 597(_GDBP__) @b{l}
70b88761 598533 xfree(rquote);
e251e767 599534
203eea5d
RP
600535 lquote = (lq == nil || *lq == '\0') ? def_lquote\
601 : xstrdup (lq);
602536 rquote = (rq == nil || *rq == '\0') ? def_rquote\
603 : xstrdup (rq);
e251e767 604537
70b88761
RP
605538 len_lquote = strlen(rquote);
606539 len_rquote = strlen(lquote);
607540 @}
e251e767 608541
70b88761
RP
609542 void
610@end smallexample
611
612@noindent
613Let's step past the two lines that set @code{len_lquote} and
614@code{len_rquote}, and then examine the values of those variables.
615
616@smallexample
6ca72cc6 617(_GDBP__) @b{n}
70b88761 618539 len_rquote = strlen(lquote);
6ca72cc6 619(_GDBP__) @b{n}
70b88761 620540 @}
6ca72cc6 621(_GDBP__) @b{p len_lquote}
70b88761 622$3 = 9
6ca72cc6 623(_GDBP__) @b{p len_rquote}
70b88761
RP
624$4 = 7
625@end smallexample
626
627@noindent
628That certainly looks wrong, assuming @code{len_lquote} and
629@code{len_rquote} are meant to be the lengths of @code{lquote} and
630@code{rquote} respectively. Let's try setting them to better values.
631We can use the @code{p} command for this, since it'll print the value of
632any expression---and that expression can include subroutine calls and
e251e767 633assignments.
70b88761
RP
634
635@smallexample
6ca72cc6 636(_GDBP__) @b{p len_lquote=strlen(lquote)}
70b88761 637$5 = 7
6ca72cc6 638(_GDBP__) @b{p len_rquote=strlen(rquote)}
70b88761
RP
639$6 = 9
640@end smallexample
641
642@noindent
643Let's see if that fixes the problem of using the new quotes with the
644@code{m4} built-in @code{defn}. We can allow @code{m4} to continue
645executing with the @code{c} (@code{continue}) command, and then try the
646example that caused trouble initially:
647
648@smallexample
6ca72cc6 649(_GDBP__) @b{c}
70b88761
RP
650Continuing.
651
6ca72cc6 652@b{define(baz,defn(<QUOTE>foo<UNQUOTE>))}
70b88761
RP
653
654baz
6550000
656@end smallexample
657
658@noindent
659Success! The new quotes now work just as well as the default ones. The
660problem seems to have been just the two typos defining the wrong
661lengths. We'll let @code{m4} exit by giving it an EOF as input.
662
663@smallexample
6ca72cc6 664@b{C-d}
70b88761
RP
665Program exited normally.
666@end smallexample
667
e251e767 668@noindent
70b88761
RP
669The message @samp{Program exited normally.} is from _GDBN__; it
670indicates @code{m4} has finished executing. We can end our _GDBN__
671session with the _GDBN__ @code{quit} command.
672
673@smallexample
6ca72cc6 674(_GDBP__) @b{quit}
70b88761 675_1__@end smallexample
0f153e74 676_fi__(!_BARE__)
70b88761 677
4eb4cf57 678@node Invocation
70b88761
RP
679@chapter Getting In and Out of _GDBN__
680
c7cb8acb
RP
681This chapter discusses how to start _GDBN__, and how to get out of it.
682(The essentials: type @samp{_GDBP__} to start GDB, and type @kbd{quit}
683or @kbd{C-d} to exit.)
29a2b744 684
70b88761 685@menu
29a2b744 686* Invoking _GDBN__:: Starting _GDBN__
c2bbbb22 687* Leaving _GDBN__:: Leaving _GDBN__
4eb4cf57 688_if__(!_BARE__)
b80282d5 689* Shell Commands:: Shell Commands
4eb4cf57 690_fi__(!_BARE__)
70b88761
RP
691@end menu
692
4eb4cf57 693@node Invoking _GDBN__
70b88761
RP
694@section Starting _GDBN__
695
4eb4cf57
RP
696_if__(_H8__)
697For details on starting up _GDBP__ as a
698remote debugger attached to a Hitachi H8/300 board, see @ref{Hitachi
699H8/300 Remote,,_GDBN__ and the Hitachi H8/300}.
700_fi__(_H8__)
701
702Start _GDBN__ by running the program @code{_GDBP__}. Once it's running,
1041a570 703_GDBN__ reads commands from the terminal until you tell it to exit.
70b88761 704
c7cb8acb
RP
705You can also run @code{_GDBP__} with a variety of arguments and options,
706to specify more of your debugging environment at the outset.
707
0005054f 708_if__(_GENERIC__)
c7cb8acb
RP
709The command-line options described here are designed
710to cover a variety of situations; in some environments, some of these
711options may effectively be unavailable.
0005054f 712_fi__(_GENERIC__)
c7cb8acb 713
4eb4cf57
RP
714The most usual way to start _GDBN__ is with one argument,
715specifying an executable program:
1041a570 716
70b88761 717@example
29a2b744 718_GDBP__ @var{program}
70b88761 719@end example
1041a570 720
4eb4cf57 721_if__(!_BARE__)
70b88761 722@noindent
29a2b744
RP
723You can also start with both an executable program and a core file
724specified:
1041a570 725
70b88761 726@example
29a2b744 727_GDBP__ @var{program} @var{core}
70b88761
RP
728@end example
729
b80282d5
RP
730You can, instead, specify a process ID as a second argument, if you want
731to debug a running process:
1041a570 732
b80282d5 733@example
29a2b744 734_GDBP__ @var{program} 1234
b80282d5 735@end example
1041a570 736
b80282d5
RP
737@noindent
738would attach _GDBN__ to process @code{1234} (unless you also have a file
739named @file{1234}; _GDBN__ does check for a core file first).
740
c7cb8acb
RP
741Taking advantage of the second command-line argument requires a fairly
742complete operating system; when you use _GDBN__ as a remote debugger
743attached to a bare board, there may not be any notion of ``process'',
744and there is often no way to get a core dump.
4eb4cf57 745_fi__(!_BARE__)
c7cb8acb 746
70b88761
RP
747@noindent
748You can further control how _GDBN__ starts up by using command-line
29a2b744
RP
749options. _GDBN__ itself can remind you of the options available.
750
751@noindent
752Type
753
70b88761
RP
754@example
755_GDBP__ -help
756@end example
29a2b744 757
70b88761 758@noindent
29a2b744 759to display all available options and briefly describe their use
70b88761
RP
760(@samp{_GDBP__ -h} is a shorter equivalent).
761
762All options and command line arguments you give are processed
763in sequential order. The order makes a difference when the
e251e767 764@samp{-x} option is used.
70b88761
RP
765
766@menu
70b88761
RP
767_if__(!_GENERIC__)
768_include__(gdbinv-m.m4)_dnl__
769_fi__(!_GENERIC__)
4eb4cf57
RP
770* File Options:: Choosing Files
771* Mode Options:: Choosing Modes
70b88761
RP
772@end menu
773
4eb4cf57
RP
774_if__(!_GENERIC__)
775_include__(gdbinv-s.m4)
776_fi__(!_GENERIC__)
777
778@node File Options
70b88761
RP
779@subsection Choosing Files
780
4eb4cf57 781_if__(!_BARE__)
29a2b744
RP
782When _GDBN__ starts, it reads any arguments other than options as
783specifying an executable file and core file (or process ID). This is
784the same as if the arguments were specified by the @samp{-se} and
785@samp{-c} options respectively. (_GDBN__ reads the first argument
786that does not have an associated option flag as equivalent to the
787@samp{-se} option followed by that argument; and the second argument
788that does not have an associated option flag, if any, as equivalent to
789the @samp{-c} option followed by that argument.)
4eb4cf57
RP
790_fi__(!_BARE__)
791_if__(_BARE__)
792When _GDBN__ starts, it reads any argument other than options as
793specifying an executable file. This is the same as if the argument was
794specified by the @samp{-se} option.
795_fi__(_BARE__)
29a2b744
RP
796
797Many options have both long and short forms; both are shown in the
798following list. _GDBN__ also recognizes the long forms if you truncate
799them, so long as enough of the option is present to be unambiguous.
800(If you prefer, you can flag option arguments with @samp{--} rather
801than @samp{-}, though we illustrate the more usual convention.)
70b88761
RP
802
803@table @code
804@item -symbols=@var{file}
805@itemx -s @var{file}
806Read symbol table from file @var{file}.
807
808@item -exec=@var{file}
809@itemx -e @var{file}
810Use file @var{file} as the executable file to execute when
811appropriate, and for examining pure data in conjunction with a core
812dump.
813
3d3ab540 814@item -se=@var{file}
70b88761
RP
815Read symbol table from file @var{file} and use it as the executable
816file.
817
4eb4cf57 818_if__(!_BARE__)
70b88761
RP
819@item -core=@var{file}
820@itemx -c @var{file}
821Use file @var{file} as a core dump to examine.
4eb4cf57 822_fi__(!_BARE__)
70b88761
RP
823
824@item -command=@var{file}
825@itemx -x @var{file}
826Execute _GDBN__ commands from file @var{file}. @xref{Command Files}.
827
828@item -directory=@var{directory}
829@itemx -d @var{directory}
830Add @var{directory} to the path to search for source files.
14d01801 831
4eb4cf57 832_if__(!_BARE__)
14d01801
RP
833@item -m
834@itemx -mapped
835@emph{Warning: this option depends on operating system facilities that are not
836supported on all systems.}@*
77b46d13
JG
837If memory-mapped files are available on your system through the @code{mmap}
838system call, you can use this option
5a2c1d85 839to have _GDBN__ write the symbols from your
77b46d13
JG
840program into a reusable file in the current directory. If the program you are debugging is
841called @file{/tmp/fred}, the mapped symbol file will be @file{./fred.syms}.
842Future _GDBN__ debugging sessions will notice the presence of this file,
843and will quickly map in symbol information from it, rather than reading
844the symbol table from the executable program.
845
846The @file{.syms} file is specific to the host machine on which _GDBN__ is run.
847It holds an exact image of _GDBN__'s internal symbol table. It cannot be
848shared across multiple host platforms.
4eb4cf57 849_fi__(!_BARE__)
77b46d13
JG
850
851@item -r
852@itemx -readnow
853Read each symbol file's entire symbol table immediately, rather than
854the default, which is to read it incrementally as it is needed.
855This makes startup slower, but makes future operations faster.
70b88761
RP
856@end table
857
4eb4cf57 858_if__(!_BARE__)
77b46d13
JG
859The @code{-mapped} and @code{-readnow} options are typically combined in order to
860build a @file{.syms} file that contains complete symbol information.
861A simple GDB invocation to do nothing but build a @file{.syms} file for future
862use is:
863
864@example
865 gdb -batch -nx -mapped -readnow programname
866@end example
4eb4cf57 867_fi__(!_BARE__)
77b46d13 868
4eb4cf57 869@node Mode Options
1041a570
RP
870@subsection Choosing Modes
871
29a2b744
RP
872You can run _GDBN__ in various alternative modes---for example, in
873batch mode or quiet mode.
70b88761
RP
874
875@table @code
876@item -nx
877@itemx -n
878Do not execute commands from any @file{_GDBINIT__} initialization files.
879Normally, the commands in these files are executed after all the
e251e767 880command options and arguments have been processed.
c728f1f0 881@xref{Command Files}.
70b88761
RP
882
883@item -quiet
884@itemx -q
885``Quiet''. Do not print the introductory and copyright messages. These
c338a2fd 886messages are also suppressed in batch mode.
70b88761
RP
887
888@item -batch
889Run in batch mode. Exit with status @code{0} after processing all the command
890files specified with @samp{-x} (and @file{_GDBINIT__}, if not inhibited).
891Exit with nonzero status if an error occurs in executing the _GDBN__
e251e767 892commands in the command files.
70b88761
RP
893
894Batch mode may be useful for running _GDBN__ as a filter, for example to
895download and run a program on another computer; in order to make this
e251e767 896more useful, the message
1041a570 897
70b88761
RP
898@example
899Program exited normally.
900@end example
1041a570 901
70b88761
RP
902@noindent
903(which is ordinarily issued whenever a program running under _GDBN__ control
904terminates) is not issued when running in batch mode.
905
3d3ab540 906@item -cd=@var{directory}
70b88761
RP
907Run _GDBN__ using @var{directory} as its working directory,
908instead of the current directory.
909
6ca72cc6 910_if__(_LUCID__)
45c53080 911@item -context @var{authentication}
6ca72cc6
RP
912When the Energize programming system starts up _GDBN__, it uses this
913option to trigger an alternate mode of interaction.
914@var{authentication} is a pair of numeric codes that identify _GDBN__
915as a client in the Energize environment. Avoid this option when you run
916_GDBN__ directly from the command line. See @ref{Energize,,Using
917_GDBN__ with Energize} for more discussion of using _GDBN__ with Energize.
918_fi__(_LUCID__)
919
70b88761
RP
920@item -fullname
921@itemx -f
922Emacs sets this option when it runs _GDBN__ as a subprocess. It tells _GDBN__
923to output the full file name and line number in a standard,
924recognizable fashion each time a stack frame is displayed (which
29a2b744 925includes each time your program stops). This recognizable format looks
70b88761
RP
926like two @samp{\032} characters, followed by the file name, line number
927and character position separated by colons, and a newline. The
928Emacs-to-_GDBN__ interface program uses the two @samp{\032} characters as
929a signal to display the source code for the frame.
930
4eb4cf57 931_if__(_GENERIC__ || !_H8__)
70b88761
RP
932@item -b @var{bps}
933Set the line speed (baud rate or bits per second) of any serial
934interface used by _GDBN__ for remote debugging.
935
3d3ab540 936@item -tty=@var{device}
70b88761 937Run using @var{device} for your program's standard input and output.
29a2b744 938@c FIXME: kingdon thinks there is more to -tty. Investigate.
4eb4cf57 939_fi__(_GENERIC__ || !_H8__)
70b88761
RP
940@end table
941
4eb4cf57 942@node Leaving _GDBN__
70b88761
RP
943@section Leaving _GDBN__
944@cindex exiting _GDBN__
1041a570 945
70b88761
RP
946@table @code
947@item quit
948@kindex quit
949@kindex q
950To exit _GDBN__, use the @code{quit} command (abbreviated @code{q}), or type
e251e767 951an end-of-file character (usually @kbd{C-d}).
70b88761
RP
952@end table
953
954@cindex interrupt
955An interrupt (often @kbd{C-c}) will not exit from _GDBN__, but rather
956will terminate the action of any _GDBN__ command that is in progress and
957return to _GDBN__ command level. It is safe to type the interrupt
958character at any time because _GDBN__ does not allow it to take effect
959until a time when it is safe.
960
4eb4cf57 961_if__(!_BARE__)
1041a570
RP
962If you have been using _GDBN__ to control an attached process or device, you
963can release it with the @code{detach} command; @pxref{Attach,
964,Debugging an Already-Running Process}..
4eb4cf57 965_fi__(!_BARE__)
70b88761 966
4eb4cf57
RP
967_if__(!_BARE__)
968@node Shell Commands
70b88761 969@section Shell Commands
1041a570 970
70b88761 971If you need to execute occasional shell commands during your
29a2b744 972debugging session, there is no need to leave or suspend _GDBN__; you can
70b88761
RP
973just use the @code{shell} command.
974
975@table @code
976@item shell @var{command string}
977@kindex shell
978@cindex shell escape
979Directs _GDBN__ to invoke an inferior shell to execute @var{command
980string}. If it exists, the environment variable @code{SHELL} is used
981for the name of the shell to run. Otherwise _GDBN__ uses
982@code{/bin/sh}.
983@end table
984
985The utility @code{make} is often needed in development environments.
29a2b744 986You do not have to use the @code{shell} command for this purpose in _GDBN__:
70b88761
RP
987
988@table @code
989@item make @var{make-args}
990@kindex make
991@cindex calling make
992Causes _GDBN__ to execute an inferior @code{make} program with the specified
993arguments. This is equivalent to @samp{shell make @var{make-args}}.
994@end table
4eb4cf57 995_fi__(!_BARE__)
70b88761 996
4eb4cf57 997@node Commands
70b88761
RP
998@chapter _GDBN__ Commands
999
6f3ec223
RP
1000You can abbreviate a _GDBN__ command to the first few letters of the command
1001name, if that abbreviation is unambiguous; and you can repeat certain
84c2fcad 1002_GDBN__ commands by typing just @key{RET}. You can also use the @key{TAB}
6f3ec223
RP
1003key to get _GDBN__ to fill out the rest of a word in a command (or to
1004show you the alternatives available, if there's more than one possibility).
29a2b744 1005
70b88761 1006@menu
b80282d5 1007* Command Syntax:: Command Syntax
6f3ec223 1008* Completion:: Command Completion
b80282d5 1009* Help:: Getting Help
70b88761
RP
1010@end menu
1011
4eb4cf57 1012@node Command Syntax
70b88761 1013@section Command Syntax
1041a570 1014
70b88761
RP
1015A _GDBN__ command is a single line of input. There is no limit on how long
1016it can be. It starts with a command name, which is followed by arguments
1017whose meaning depends on the command name. For example, the command
1018@code{step} accepts an argument which is the number of times to step,
1019as in @samp{step 5}. You can also use the @code{step} command with
1020no arguments. Some command names do not allow any arguments.
1021
1022@cindex abbreviation
1023_GDBN__ command names may always be truncated if that abbreviation is
1024unambiguous. Other possible command abbreviations are listed in the
1025documentation for individual commands. In some cases, even ambiguous
1026abbreviations are allowed; for example, @code{s} is specially defined as
1027equivalent to @code{step} even though there are other commands whose
1028names start with @code{s}. You can test abbreviations by using them as
7463aadd 1029arguments to the @code{help} command.
70b88761 1030
e251e767 1031@cindex repeating commands
70b88761
RP
1032@kindex RET
1033A blank line as input to _GDBN__ (typing just @key{RET}) means to
1034repeat the previous command. Certain commands (for example, @code{run})
1035will not repeat this way; these are commands for which unintentional
1036repetition might cause trouble and which you are unlikely to want to
1037repeat.
1038
1039The @code{list} and @code{x} commands, when you repeat them with
1040@key{RET}, construct new arguments rather than repeating
1041exactly as typed. This permits easy scanning of source or memory.
1042
b80282d5
RP
1043_GDBN__ can also use @key{RET} in another way: to partition lengthy
1044output, in a way similar to the common utility @code{more}
29a2b744 1045(@pxref{Screen Size}). Since it is easy to press one @key{RET} too many
b80282d5
RP
1046in this situation, _GDBN__ disables command repetition after any command
1047that generates this sort of display.
1048
70b88761
RP
1049@kindex #
1050@cindex comment
1051A line of input starting with @kbd{#} is a comment; it does nothing.
29a2b744 1052This is useful mainly in command files (@pxref{Command Files}).
70b88761 1053
4eb4cf57 1054@node Completion
6f3ec223
RP
1055@section Command Completion
1056
1057@cindex completion
1058@cindex word completion
1059_GDBN__ can fill in the rest of a word in a command for you, if there's
1060only one possibility; it can also show you what the valid possibilities
1061are for the next word in a command, at any time. This works for _GDBN__
1062commands, _GDBN__ subcommands, and the names of symbols in your program.
1063
1064Press the @key{TAB} key whenever you want _GDBN__ to fill out the rest
1065of a word. If there's only one possibility, _GDBN__ will fill in the
1066word, and wait for you to finish the command (or press @key{RET} to
1067enter it). For example, if you type
1068
0fdc6e27
RP
1069@c FIXME "@key" doesn't distinguish its argument sufficiently to permit
1070@c complete accuracy in these examples; space introduced for clarity.
1071@c If texinfo enhancements make it unnecessary, it would be nice to
1072@c replace " @key" by "@key" in the following...
6f3ec223 1073@example
0fdc6e27 1074(_GDBP__) info bre @key{TAB}
6f3ec223
RP
1075@end example
1076
1077@noindent
1078_GDBN__ fills in the rest of the word @samp{breakpoints}, since that's
1079the only @code{info} subcommand beginning with @samp{bre}:
1080
1081@example
1082(_GDBP__) info breakpoints
1083@end example
1084
1085@noindent
1086You can either press @key{RET} at this point, to run the @code{info
1087breakpoints} command, or backspace and enter something else, if
1088@samp{breakpoints} doesn't look like the command you expected. (If you
1089were sure you wanted @code{info breakpoints} in the first place, you
1090might as well just type @key{RET} immediately after @samp{info bre},
1091to exploit command abbreviations rather than command completion).
1092
1093If there is more than one possibility for the next word when you press
1094@key{TAB}, _GDBN__ will sound a bell. You can either supply more
1095characters and try again, or just press @key{TAB} a second time, and
1096_GDBN__ will display all the possible completions for that word. For
1097example, you might want to set a breakpoint on a subroutine whose name
b1385986 1098begins with @samp{make_}, but when you type @kbd{b make_@key{TAB}} _GDBN__
6f3ec223
RP
1099just sounds the bell. Typing @key{TAB} again will display all the
1100function names in your program that begin with those characters, for
1101example:
1102
1103@example
0fdc6e27 1104(_GDBP__) b make_ @key{TAB}
b1385986 1105@exdent _GDBN__ sounds bell; press @key{TAB} again, to see:
6f3ec223
RP
1106make_a_section_from_file make_environ
1107make_abs_section make_function_type
1108make_blockvector make_pointer_type
1109make_cleanup make_reference_type
1110make_command make_symbol_completion_list
b1385986 1111(GDBP__) b make_
6f3ec223
RP
1112@end example
1113
1114@noindent
1115After displaying the available possibilities, _GDBN__ copies your
b1385986 1116partial input (@samp{b make_} in the example) so you can finish the
6f3ec223
RP
1117command.
1118
1119If you just want to see the list of alternatives in the first place, you
b1385986 1120can press @kbd{M-?} rather than pressing @key{TAB} twice. @kbd{M-?}
0f153e74
RP
1121means @kbd{@key{META} ?}. You can type this
1122_if__(_GENERIC__||!_DOSHOST__)
1123either by holding down a
b1385986 1124key designated as the @key{META} shift on your keyboard (if there is
0f153e74
RP
1125one) while typing @kbd{?}, or
1126_fi__(_GENERIC__||!_DOSHOST__)
1127as @key{ESC} followed by @kbd{?}.
6f3ec223
RP
1128
1129@cindex quotes in commands
1130@cindex completion of quoted strings
1131Sometimes the string you need, while logically a ``word'', may contain
1132parentheses or other characters that _GDBN__ normally excludes from its
1133notion of a word. To permit word completion to work in this situation,
1134you may enclose words in @code{'} (single quote marks) in _GDBN__ commands.
1135
1136The most likely situation where you might need this is in typing the
1137name of a C++ function. This is because C++ allows function overloading
1138(multiple definitions of the same function, distinguished by argument
b1385986
RP
1139type). For example, when you want to set a breakpoint you may need to
1140distinguish whether you mean the version of @code{name} that takes an
1141@code{int} parameter, @code{name(int)}, or the version that takes a
1142@code{float} parameter, @code{name(float)}. To use the word-completion
1143facilities in this situation, type a single quote @code{'} at the
1144beginning of the function name. This alerts _GDBN__ that it may need to
1145consider more information than usual when you press @key{TAB} or
1146@kbd{M-?} to request word completion:
6f3ec223
RP
1147
1148@example
0fdc6e27
RP
1149(_GDBP__) b 'bubble( @key{M-?}
1150bubble(double,double) bubble(int,int)
1151(_GDBP__) b 'bubble(
6f3ec223
RP
1152@end example
1153
0fdc6e27
RP
1154In some cases, _GDBN__ can tell that completing a name will require
1155quotes. When this happens, _GDBN__ will insert the quote for you (while
1156completing as much as it can) if you do not type the quote in the first
1157place:
1158
1159@example
1160(_GDBP__) b bub @key{TAB}
1161@exdent _GDBN__ alters your input line to the following, and rings a bell:
1162(_GDBP__) b 'bubble(
1163@end example
1164
1165@noindent
1166In general, _GDBN__ can tell that a quote is needed (and inserts it) if
1167you have not yet started typing the argument list when you ask for
1168completion on an overloaded symbol.
1169
1170
4eb4cf57 1171@node Help
70b88761
RP
1172@section Getting Help
1173@cindex online documentation
1174@kindex help
1041a570 1175
70b88761 1176You can always ask _GDBN__ itself for information on its commands, using the
e251e767 1177command @code{help}.
70b88761
RP
1178
1179@table @code
1180@item help
1181@itemx h
1182@kindex h
1183You can use @code{help} (abbreviated @code{h}) with no arguments to
1184display a short list of named classes of commands:
1041a570 1185
70b88761
RP
1186@smallexample
1187(_GDBP__) help
1188List of classes of commands:
1189
1190running -- Running the program
1191stack -- Examining the stack
1192data -- Examining data
1193breakpoints -- Making program stop at certain points
1194files -- Specifying and examining files
1195status -- Status inquiries
1196support -- Support facilities
1197user-defined -- User-defined commands
1198aliases -- Aliases of other commands
1199obscure -- Obscure features
1200
203eea5d
RP
1201Type "help" followed by a class name for a list of
1202commands in that class.
1203Type "help" followed by command name for full
1204documentation.
70b88761 1205Command name abbreviations are allowed if unambiguous.
e251e767 1206(_GDBP__)
70b88761
RP
1207@end smallexample
1208
1209@item help @var{class}
1210Using one of the general help classes as an argument, you can get a
1211list of the individual commands in that class. For example, here is the
1212help display for the class @code{status}:
1041a570 1213
70b88761
RP
1214@smallexample
1215(_GDBP__) help status
1216Status inquiries.
1217
1218List of commands:
1219
1220show -- Generic command for showing things set with "set"
1221info -- Generic command for printing status
1222
203eea5d
RP
1223Type "help" followed by command name for full
1224documentation.
70b88761 1225Command name abbreviations are allowed if unambiguous.
e251e767 1226(_GDBP__)
70b88761
RP
1227@end smallexample
1228
1229@item help @var{command}
1230With a command name as @code{help} argument, _GDBN__ will display a
e251e767 1231short paragraph on how to use that command.
70b88761
RP
1232@end table
1233
1234In addition to @code{help}, you can use the _GDBN__ commands @code{info}
1235and @code{show} to inquire about the state of your program, or the state
1236of _GDBN__ itself. Each command supports many topics of inquiry; this
1237manual introduces each of them in the appropriate context. The listings
1238under @code{info} and under @code{show} in the Index point to
29a2b744 1239all the sub-commands. @xref{Index}.
70b88761
RP
1240
1241@c @group
1242@table @code
1243@item info
1244@kindex info
1245@kindex i
1246This command (abbreviated @code{i}) is for describing the state of your
1247program; for example, it can list the arguments given to your program
1248(@code{info args}), the registers currently in use (@code{info
1041a570 1249registers}), or the breakpoints you have set (@code{info breakpoints}).
70b88761
RP
1250You can get a complete list of the @code{info} sub-commands with
1251@w{@code{help info}}.
1252
1253@kindex show
1254@item show
1255In contrast, @code{show} is for describing the state of _GDBN__ itself.
1256You can change most of the things you can @code{show}, by using the
1257related command @code{set}; for example, you can control what number
1258system is used for displays with @code{set radix}, or simply inquire
e251e767 1259which is currently in use with @code{show radix}.
70b88761
RP
1260
1261@kindex info set
1262To display all the settable parameters and their current
1263values, you can use @code{show} with no arguments; you may also use
1264@code{info set}. Both commands produce the same display.
1265@c FIXME: "info set" violates the rule that "info" is for state of
1266@c FIXME...program. Ck w/ GNU: "info set" to be called something else,
1267@c FIXME...or change desc of rule---eg "state of prog and debugging session"?
1268@end table
1269@c @end group
1270
1271Here are three miscellaneous @code{show} subcommands, all of which are
1272exceptional in lacking corresponding @code{set} commands:
1273
1274@table @code
1275@kindex show version
3d3ab540 1276@cindex version number
70b88761
RP
1277@item show version
1278Show what version of _GDBN__ is running. You should include this
1041a570
RP
1279information in _GDBN__ bug-reports. If multiple versions of _GDBN__ are in
1280use at your site, you may occasionally want to make sure what version
1281of _GDBN__ you are running; as _GDBN__ evolves, new commands are introduced,
1282and old ones may wither away. The version number is also announced
1283when you start _GDBN__ with no arguments.
70b88761
RP
1284
1285@kindex show copying
1286@item show copying
1287Display information about permission for copying _GDBN__.
1288
1289@kindex show warranty
1290@item show warranty
1291Display the GNU ``NO WARRANTY'' statement.
1292@end table
1293
4eb4cf57 1294@node Running
70b88761
RP
1295@chapter Running Programs Under _GDBN__
1296
1041a570
RP
1297To debug a program, you must run it under _GDBN__.
1298
70b88761 1299@menu
b80282d5
RP
1300* Compilation:: Compiling for Debugging
1301* Starting:: Starting your Program
4eb4cf57 1302_if__(!_BARE__)
b80282d5
RP
1303* Arguments:: Your Program's Arguments
1304* Environment:: Your Program's Environment
1305* Working Directory:: Your Program's Working Directory
1306* Input/Output:: Your Program's Input and Output
1307* Attach:: Debugging an Already-Running Process
1308* Kill Process:: Killing the Child Process
d24e0922 1309* Process Information:: Additional Process Information
4eb4cf57 1310_fi__(!_BARE__)
70b88761
RP
1311@end menu
1312
4eb4cf57 1313@node Compilation
70b88761
RP
1314@section Compiling for Debugging
1315
1316In order to debug a program effectively, you need to generate
1317debugging information when you compile it. This debugging information
1318is stored in the object file; it describes the data type of each
1319variable or function and the correspondence between source line numbers
1320and addresses in the executable code.
1321
1322To request debugging information, specify the @samp{-g} option when you run
1323the compiler.
1324
1325Many C compilers are unable to handle the @samp{-g} and @samp{-O}
1326options together. Using those compilers, you cannot generate optimized
1327executables containing debugging information.
1328
c7cb8acb
RP
1329_GCC__, the GNU C compiler, supports @samp{-g} with or without
1330@samp{-O}, making it possible to debug optimized code. We recommend
1331that you @emph{always} use @samp{-g} whenever you compile a program.
1332You may think your program is correct, but there is no sense in pushing
1333your luck.
70b88761 1334
6ca72cc6
RP
1335@cindex optimized code, debugging
1336@cindex debugging optimized code
1337When you debug a program compiled with @samp{-g -O}, remember that the
1338optimizer is rearranging your code; the debugger will show you what's
1339really there. Don't be too surprised when the execution path doesn't
1340exactly match your source file! An extreme example: if you define a
1341variable, but never use it, _GDBN__ will never see that
1342variable---because the compiler optimizes it out of existence.
1343
70b88761
RP
1344Some things do not work as well with @samp{-g -O} as with just
1345@samp{-g}, particularly on machines with instruction scheduling. If in
1346doubt, recompile with @samp{-g} alone, and if this fixes the problem,
1347please report it as a bug (including a test case!).
1348
1349Older versions of the GNU C compiler permitted a variant option
c7cb8acb 1350@w{@samp{-gg}} for debugging information. _GDBN__ no longer supports this
70b88761
RP
1351format; if your GNU C compiler has this option, do not use it.
1352
1353@ignore
1354@comment As far as I know, there are no cases in which _GDBN__ will
1355@comment produce strange output in this case. (but no promises).
1356If your program includes archives made with the @code{ar} program, and
1357if the object files used as input to @code{ar} were compiled without the
1358@samp{-g} option and have names longer than 15 characters, _GDBN__ will get
29a2b744 1359confused reading your program's symbol table. No error message will be
70b88761
RP
1360given, but _GDBN__ may behave strangely. The reason for this problem is a
1361deficiency in the Unix archive file format, which cannot represent file
1362names longer than 15 characters.
1363
1364To avoid this problem, compile the archive members with the @samp{-g}
1365option or use shorter file names. Alternatively, use a version of GNU
1366@code{ar} dated more recently than August 1989.
1367@end ignore
1368
4eb4cf57 1369@node Starting
70b88761
RP
1370@section Starting your Program
1371@cindex starting
1372@cindex running
1041a570 1373
70b88761
RP
1374@table @code
1375@item run
1376@itemx r
1377@kindex run
1041a570
RP
1378Use the @code{run} command to start your program under _GDBN__. You must
1379first specify the program name
e251e767 1380_if__(_VXWORKS__)
7463aadd 1381(except on VxWorks)
70b88761 1382_fi__(_VXWORKS__)
1041a570
RP
1383with an argument to
1384_GDBN__ (@pxref{Invocation, ,Getting In and Out of _GDBN__}), or by using the
1385@code{file} or @code{exec-file} command (@pxref{Files, ,Commands to
1386Specify Files}).
1387
70b88761
RP
1388@end table
1389
4eb4cf57 1390_if__(!_BARE__)
29a2b744
RP
1391If you are running your program in an execution environment that
1392supports processes, @code{run} creates an inferior process and makes
1393that process run your program. (In environments without processes,
1394@code{run} jumps to the start of your program.)
70b88761
RP
1395
1396The execution of a program is affected by certain information it
1397receives from its superior. _GDBN__ provides ways to specify this
6ca72cc6 1398information, which you must do @emph{before} starting your program. (You
29a2b744
RP
1399can change it after starting your program, but such changes will only affect
1400your program the next time you start it.) This information may be
70b88761
RP
1401divided into four categories:
1402
1403@table @asis
6ca72cc6 1404@item The @emph{arguments.}
29a2b744 1405Specify the arguments to give your program as the arguments of the
1041a570
RP
1406@code{run} command. If a shell is available on your target, the shell
1407is used to pass the arguments, so that you may use normal conventions
1408(such as wildcard expansion or variable substitution) in describing
1409the arguments. In Unix systems, you can control which shell is used
1410with the @code{SHELL} environment variable. @xref{Arguments, ,Your
1411Program's Arguments}.
70b88761 1412
6ca72cc6 1413@item The @emph{environment.}
70b88761
RP
1414Your program normally inherits its environment from _GDBN__, but you can
1415use the _GDBN__ commands @code{set environment} and @code{unset
1416environment} to change parts of the environment that will be given to
1041a570 1417your program. @xref{Environment, ,Your Program's Environment}.
70b88761 1418
6ca72cc6 1419@item The @emph{working directory.}
70b88761
RP
1420Your program inherits its working directory from _GDBN__. You can set
1421_GDBN__'s working directory with the @code{cd} command in _GDBN__.
29a2b744 1422@xref{Working Directory, ,Your Program's Working Directory}.
70b88761 1423
6ca72cc6 1424@item The @emph{standard input and output.}
70b88761
RP
1425Your program normally uses the same device for standard input and
1426standard output as _GDBN__ is using. You can redirect input and output
1427in the @code{run} command line, or you can use the @code{tty} command to
1428set a different device for your program.
1041a570 1429@xref{Input/Output, ,Your Program's Input and Output}.
3d3ab540
RP
1430
1431@cindex pipes
29a2b744
RP
1432@emph{Warning:} While input and output redirection work, you cannot use
1433pipes to pass the output of the program you are debugging to another
3d3ab540
RP
1434program; if you attempt this, _GDBN__ is likely to wind up debugging the
1435wrong program.
70b88761 1436@end table
4eb4cf57 1437_fi__(!_BARE__)
70b88761 1438
1041a570 1439When you issue the @code{run} command, your program begins to execute
4eb4cf57
RP
1440immediately. @xref{Stopping, ,Stopping and Continuing}, for discussion
1441of how to arrange for your program to stop. Once your program has
1442stopped, you may calls functions in your program, using the @code{print}
1443or @code{call} commands. @xref{Data, ,Examining Data}.
70b88761 1444
29a2b744 1445If the modification time of your symbol file has changed since the
1041a570
RP
1446last time _GDBN__ read its symbols, _GDBN__ will discard its symbol table and
1447re-read it. When it does this, _GDBN__ tries to retain your current
1448breakpoints.
70b88761 1449
4eb4cf57
RP
1450_if__(!_BARE__)
1451@node Arguments
70b88761
RP
1452@section Your Program's Arguments
1453
1454@cindex arguments (to your program)
1455The arguments to your program can be specified by the arguments of the
1456@code{run} command. They are passed to a shell, which expands wildcard
29a2b744 1457characters and performs redirection of I/O, and thence to your program.
70b88761
RP
1458_GDBN__ uses the shell indicated by your environment variable
1459@code{SHELL} if it exists; otherwise, _GDBN__ uses @code{/bin/sh}.
1460
1461@code{run} with no arguments uses the same arguments used by the previous
1462@code{run}, or those set by the @code{set args} command.
1463
1464@kindex set args
1465@table @code
1466@item set args
1467Specify the arguments to be used the next time your program is run. If
1468@code{set args} has no arguments, @code{run} will execute your program
e251e767 1469with no arguments. Once you have run your program with arguments,
70b88761
RP
1470using @code{set args} before the next @code{run} is the only way to run
1471it again without arguments.
1472
1473@item show args
1474@kindex show args
1475Show the arguments to give your program when it is started.
1476@end table
1477
4eb4cf57 1478@node Environment
70b88761
RP
1479@section Your Program's Environment
1480
1481@cindex environment (of your program)
1482The @dfn{environment} consists of a set of environment variables and
1483their values. Environment variables conventionally record such things as
1484your user name, your home directory, your terminal type, and your search
1485path for programs to run. Usually you set up environment variables with
1486the shell and they are inherited by all the other programs you run. When
29a2b744 1487debugging, it can be useful to try running your program with a modified
70b88761
RP
1488environment without having to start _GDBN__ over again.
1489
1490@table @code
1491@item path @var{directory}
1492@kindex path
1493Add @var{directory} to the front of the @code{PATH} environment variable
1494(the search path for executables), for both _GDBN__ and your program.
1495You may specify several directory names, separated by @samp{:} or
1496whitespace. If @var{directory} is already in the path, it is moved to
e251e767 1497the front, so it will be searched sooner.
7463aadd
RP
1498
1499You can use the string @samp{$cwd} to refer to whatever is the current
1500working directory at the time _GDBN__ searches the path. If you use
1501@samp{.} instead, it refers to the directory where you executed the
1502@code{path} command. _GDBN__ fills in the current path where needed in
1503the @var{directory} argument, before adding it to the search path.
29a2b744 1504@c 'path' is explicitly nonrepeatable, but RMS points out it is silly to
70b88761
RP
1505@c document that, since repeating it would be a no-op.
1506
1507@item show paths
1508@kindex show paths
1509Display the list of search paths for executables (the @code{PATH}
1510environment variable).
1511
1512@item show environment @r{[}@var{varname}@r{]}
1513@kindex show environment
1514Print the value of environment variable @var{varname} to be given to
29a2b744 1515your program when it starts. If you do not supply @var{varname},
70b88761
RP
1516print the names and values of all environment variables to be given to
1517your program. You can abbreviate @code{environment} as @code{env}.
1518
7463aadd 1519@item set environment @var{varname} @r{[}=@r{]} @var{value}
70b88761
RP
1520@kindex set environment
1521Sets environment variable @var{varname} to @var{value}. The value
1522changes for your program only, not for _GDBN__ itself. @var{value} may
1523be any string; the values of environment variables are just strings, and
1524any interpretation is supplied by your program itself. The @var{value}
1525parameter is optional; if it is eliminated, the variable is set to a
1526null value.
29a2b744 1527@c "any string" here does not include leading, trailing
70b88761
RP
1528@c blanks. Gnu asks: does anyone care?
1529
1530For example, this command:
1531
1532@example
1533set env USER = foo
1534@end example
1535
1536@noindent
1537tells a Unix program, when subsequently run, that its user is named
1538@samp{foo}. (The spaces around @samp{=} are used for clarity here; they
1539are not actually required.)
1540
1541@item unset environment @var{varname}
1542@kindex unset environment
1543Remove variable @var{varname} from the environment to be passed to your
1544program. This is different from @samp{set env @var{varname} =};
1545@code{unset environment} removes the variable from the environment,
e251e767 1546rather than assigning it an empty value.
70b88761
RP
1547@end table
1548
4eb4cf57 1549@node Working Directory
70b88761
RP
1550@section Your Program's Working Directory
1551
1552@cindex working directory (of your program)
1553Each time you start your program with @code{run}, it inherits its
1554working directory from the current working directory of _GDBN__. _GDBN__'s
1555working directory is initially whatever it inherited from its parent
1556process (typically the shell), but you can specify a new working
1557directory in _GDBN__ with the @code{cd} command.
1558
1559The _GDBN__ working directory also serves as a default for the commands
1041a570
RP
1560that specify files for _GDBN__ to operate on. @xref{Files, ,Commands to
1561Specify Files}.
70b88761
RP
1562
1563@table @code
1564@item cd @var{directory}
1565@kindex cd
1566Set _GDBN__'s working directory to @var{directory}.
1567
1568@item pwd
1569@kindex pwd
1570Print _GDBN__'s working directory.
1571@end table
1572
4eb4cf57 1573@node Input/Output
70b88761
RP
1574@section Your Program's Input and Output
1575
1576@cindex redirection
1577@cindex i/o
1578@cindex terminal
1579By default, the program you run under _GDBN__ does input and output to
1580the same terminal that _GDBN__ uses. _GDBN__ switches the terminal to
1581its own terminal modes to interact with you, but it records the terminal
1582modes your program was using and switches back to them when you continue
1583running your program.
1584
1585@table @code
1586@item info terminal
1587@kindex info terminal
1588Displays _GDBN__'s recorded information about the terminal modes your
1589program is using.
1590@end table
1591
29a2b744 1592You can redirect your program's input and/or output using shell
70b88761
RP
1593redirection with the @code{run} command. For example,
1594
1595_0__@example
1596run > outfile
1597_1__@end example
1598
1599@noindent
29a2b744 1600starts your program, diverting its output to the file @file{outfile}.
70b88761
RP
1601
1602@kindex tty
1603@cindex controlling terminal
29a2b744 1604Another way to specify where your program should do input and output is
70b88761
RP
1605with the @code{tty} command. This command accepts a file name as
1606argument, and causes this file to be the default for future @code{run}
1607commands. It also resets the controlling terminal for the child
1608process, for future @code{run} commands. For example,
1609
1610@example
1611tty /dev/ttyb
1612@end example
1613
1614@noindent
1615directs that processes started with subsequent @code{run} commands
1616default to do input and output on the terminal @file{/dev/ttyb} and have
1617that as their controlling terminal.
1618
1619An explicit redirection in @code{run} overrides the @code{tty} command's
1620effect on the input/output device, but not its effect on the controlling
1621terminal.
1622
1623When you use the @code{tty} command or redirect input in the @code{run}
1624command, only the input @emph{for your program} is affected. The input
1625for _GDBN__ still comes from your terminal.
1626
4eb4cf57 1627@node Attach
70b88761
RP
1628@section Debugging an Already-Running Process
1629@kindex attach
1630@cindex attach
1631
1632@table @code
1633@item attach @var{process-id}
1634This command
1635attaches to a running process---one that was started outside _GDBN__.
1636(@code{info files} will show your active targets.) The command takes as
1637argument a process ID. The usual way to find out the process-id of
1638a Unix process is with the @code{ps} utility, or with the @samp{jobs -l}
e251e767 1639shell command.
70b88761
RP
1640
1641@code{attach} will not repeat if you press @key{RET} a second time after
1642executing the command.
1643@end table
1644
1645To use @code{attach}, you must be debugging in an environment which
1646supports processes. You must also have permission to send the process a
1647signal, and it must have the same effective user ID as the _GDBN__
1648process.
1649
1650When using @code{attach}, you should first use the @code{file} command
1651to specify the program running in the process and load its symbol table.
29a2b744 1652@xref{Files, ,Commands to Specify Files}.
70b88761
RP
1653
1654The first thing _GDBN__ does after arranging to debug the specified
1655process is to stop it. You can examine and modify an attached process
1656with all the _GDBN__ commands that are ordinarily available when you start
1657processes with @code{run}. You can insert breakpoints; you can step and
1658continue; you can modify storage. If you would rather the process
1659continue running, you may use the @code{continue} command after
1660attaching _GDBN__ to the process.
1661
1662@table @code
1663@item detach
1664@kindex detach
1665When you have finished debugging the attached process, you can use the
1666@code{detach} command to release it from _GDBN__'s control. Detaching
1667the process continues its execution. After the @code{detach} command,
1668that process and _GDBN__ become completely independent once more, and you
1669are ready to @code{attach} another process or start one with @code{run}.
1670@code{detach} will not repeat if you press @key{RET} again after
1671executing the command.
1672@end table
1673
1674If you exit _GDBN__ or use the @code{run} command while you have an attached
1675process, you kill that process. By default, you will be asked for
1676confirmation if you try to do either of these things; you can control
1677whether or not you need to confirm by using the @code{set confirm} command
29a2b744 1678(@pxref{Messages/Warnings, ,Optional Warnings and Messages}).
70b88761 1679
4eb4cf57 1680@node Kill Process
70b88761
RP
1681@c @group
1682@section Killing the Child Process
1683
1684@table @code
1685@item kill
1686@kindex kill
1687Kill the child process in which your program is running under _GDBN__.
1688@end table
1689
1690This command is useful if you wish to debug a core dump instead of a
1691running process. _GDBN__ ignores any core dump file while your program
1692is running.
1693@c @end group
1694
29a2b744 1695On some operating systems, a program cannot be executed outside _GDBN__
70b88761 1696while you have breakpoints set on it inside _GDBN__. You can use the
29a2b744 1697@code{kill} command in this situation to permit running your program
70b88761
RP
1698outside the debugger.
1699
1700The @code{kill} command is also useful if you wish to recompile and
29a2b744 1701relink your program, since on many systems it is impossible to modify an
70b88761
RP
1702executable file while it is running in a process. In this case, when you
1703next type @code{run}, _GDBN__ will notice that the file has changed, and
1704will re-read the symbol table (while trying to preserve your current
1705breakpoint settings).
1706
4eb4cf57 1707@node Process Information
d24e0922
RP
1708@section Additional Process Information
1709
1710@kindex /proc
1711@cindex process image
1712Some operating systems provide a facility called @samp{/proc} that can
cc9bc574
RP
1713be used to examine the image of a running process using file-system
1714subroutines. If _GDBN__ is configured for an operating system with this
1715facility, the command @code{info proc} is available to report on several
1716kinds of information about the process running your program.
d24e0922
RP
1717
1718@table @code
1719@item info proc
1720@kindex info proc
1721Summarize available information about the process.
1722
1723@item info proc mappings
1724@kindex info proc mappings
1725Report on the address ranges accessible in the program, with information
1726on whether your program may read, write, or execute each range.
1727
1728@item info proc times
1729@kindex info proc times
1730Starting time, user CPU time, and system CPU time for your program and
1731its children.
1732
1733@item info proc id
1734@kindex info proc id
1735Report on the process ID's related to your program: its own process id,
1736the id of its parent, the process group id, and the session id.
1737
1738@item info proc status
1739@kindex info proc status
1740General information on the state of the process. If the process is
1741stopped, this report includes the reason for stopping, and any signal
1742received.
cc9bc574
RP
1743
1744@item info proc all
1745Show all the above information about the process.
d24e0922 1746@end table
4eb4cf57 1747_fi__(!_BARE__)
d24e0922 1748
4eb4cf57 1749@node Stopping
70b88761
RP
1750@chapter Stopping and Continuing
1751
1752The principal purpose of using a debugger is so that you can stop your
29a2b744 1753program before it terminates; or so that, if your program runs into
70b88761
RP
1754trouble, you can investigate and find out why.
1755
1756Inside _GDBN__, your program may stop for any of several reasons, such
1757as a signal, a breakpoint, or reaching a new line after a _GDBN__
1758command such as @code{step}. You may then examine and change
1759variables, set new breakpoints or remove old ones, and then continue
1760execution. Usually, the messages shown by _GDBN__ provide ample
1761explanation of the status of your program---but you can also explicitly
1762request this information at any time.
1763
1764@table @code
1765@item info program
1766@kindex info program
1767Display information about the status of your program: whether it is
1768running or not, what process it is, and why it stopped.
1769@end table
1770
1771@menu
0f153e74 1772_if__(!_CONLY__)
b80282d5 1773* Breakpoints:: Breakpoints, Watchpoints, and Exceptions
0f153e74
RP
1774_fi__(!_CONLY__)
1775_if__(_CONLY__)
1776* Breakpoints:: Breakpoints and Watchpoints
1777_fi__(_CONLY__)
b80282d5 1778* Continuing and Stepping:: Resuming Execution
4eb4cf57 1779_if__(_GENERIC__ || !_H8__)
b80282d5 1780* Signals:: Signals
4eb4cf57 1781_fi__(_GENERIC__ || !_H8__)
70b88761
RP
1782@end menu
1783
4eb4cf57 1784@node Breakpoints
0f153e74 1785_if__(!_CONLY__)
70b88761 1786@section Breakpoints, Watchpoints, and Exceptions
0f153e74
RP
1787_fi__(!_CONLY__)
1788_if__(_CONLY__)
1789@section Breakpoints and Watchpoints
1790_fi__(_CONLY__)
70b88761
RP
1791
1792@cindex breakpoints
1793A @dfn{breakpoint} makes your program stop whenever a certain point in
1041a570 1794the program is reached. For each breakpoint, you can add various
29a2b744 1795conditions to control in finer detail whether your program will stop.
70b88761 1796You can set breakpoints with the @code{break} command and its variants
29a2b744
RP
1797(@pxref{Set Breaks, ,Setting Breakpoints}), to specify the place where
1798your program should stop by line number, function name or exact address
0f153e74
RP
1799in the program.
1800_if__(!_CONLY__)
1801In languages with exception handling (such as GNU C++), you can also set
1802breakpoints where an exception is raised (@pxref{Exception Handling,
1803,Breakpoints and Exceptions}).
1804_fi__(!_CONLY__)
70b88761
RP
1805
1806@cindex watchpoints
6ca72cc6
RP
1807@cindex memory tracing
1808@cindex breakpoint on memory address
1809@cindex breakpoint on variable modification
29a2b744
RP
1810A @dfn{watchpoint} is a special breakpoint that stops your program
1811when the value of an expression changes. You must use a different
1812command to set watchpoints (@pxref{Set Watchpoints, ,Setting
1813Watchpoints}), but aside from that, you can manage a watchpoint like
1814any other breakpoint: you enable, disable, and delete both breakpoints
1041a570 1815and watchpoints using the same commands.
70b88761 1816
6ca72cc6
RP
1817@cindex breakpoint numbers
1818@cindex numbers for breakpoints
1819_GDBN__ assigns a number to each breakpoint or watchpoint when you
1820create it; these numbers are successive integers starting with one. In
1821many of the commands for controlling various features of breakpoints you
1822use the breakpoint number to say which breakpoint you want to change.
1823Each breakpoint may be @dfn{enabled} or @dfn{disabled}; if disabled, it has
29a2b744 1824no effect on your program until you enable it again.
70b88761
RP
1825
1826@menu
b80282d5
RP
1827* Set Breaks:: Setting Breakpoints
1828* Set Watchpoints:: Setting Watchpoints
1829* Exception Handling:: Breakpoints and Exceptions
1830* Delete Breaks:: Deleting Breakpoints
1831* Disabling:: Disabling Breakpoints
1832* Conditions:: Break Conditions
1833* Break Commands:: Breakpoint Command Lists
1834* Breakpoint Menus:: Breakpoint Menus
e251e767 1835* Error in Breakpoints::
70b88761
RP
1836@end menu
1837
4eb4cf57 1838@node Set Breaks
70b88761
RP
1839@subsection Setting Breakpoints
1840
4906534f
RP
1841@c FIXME LMB what does GDB do if no code on line of breakpt?
1842@c consider in particular declaration with/without initialization.
1843@c
1844@c FIXME 2 is there stuff on this already? break at fun start, already init?
1845
70b88761
RP
1846@kindex break
1847@kindex b
6ca72cc6
RP
1848@kindex $bpnum
1849@cindex latest breakpoint
1850Breakpoints are set with the @code{break} command (abbreviated
1851@code{b}). The debugger convenience variable @samp{$bpnum} records the
1852number of the beakpoint you've set most recently; see @ref{Convenience
d24e0922 1853Vars,, Convenience Variables}, for a discussion of what you can do with
6ca72cc6 1854convenience variables.
70b88761
RP
1855
1856You have several ways to say where the breakpoint should go.
1857
1858@table @code
1859@item break @var{function}
0f153e74
RP
1860Set a breakpoint at entry to function @var{function}.
1861_if__(!_CONLY__)
1862When using source languages that permit overloading of symbols, such as
1863C++, @var{function} may refer to more than one possible place to break.
70b88761 1864@xref{Breakpoint Menus}, for a discussion of that situation.
0f153e74 1865_fi__(!_CONLY__)
70b88761
RP
1866
1867@item break +@var{offset}
1868@itemx break -@var{offset}
1869Set a breakpoint some number of lines forward or back from the position
1870at which execution stopped in the currently selected frame.
1871
1872@item break @var{linenum}
1873Set a breakpoint at line @var{linenum} in the current source file.
1874That file is the last file whose source text was printed. This
29a2b744 1875breakpoint will stop your program just before it executes any of the
70b88761
RP
1876code on that line.
1877
1878@item break @var{filename}:@var{linenum}
1879Set a breakpoint at line @var{linenum} in source file @var{filename}.
1880
1881@item break @var{filename}:@var{function}
1882Set a breakpoint at entry to function @var{function} found in file
1883@var{filename}. Specifying a file name as well as a function name is
1884superfluous except when multiple files contain similarly named
1885functions.
1886
1887@item break *@var{address}
1888Set a breakpoint at address @var{address}. You can use this to set
29a2b744 1889breakpoints in parts of your program which do not have debugging
70b88761
RP
1890information or source files.
1891
1892@item break
29a2b744
RP
1893When called without any arguments, @code{break} sets a breakpoint at
1894the next instruction to be executed in the selected stack frame
1895(@pxref{Stack, ,Examining the Stack}). In any selected frame but the
1896innermost, this will cause your program to stop as soon as control
1897returns to that frame. This is similar to the effect of a
1898@code{finish} command in the frame inside the selected frame---except
1899that @code{finish} does not leave an active breakpoint. If you use
1041a570
RP
1900@code{break} without an argument in the innermost frame, _GDBN__ will stop
1901the next time it reaches the current location; this may be useful
1902inside loops.
70b88761
RP
1903
1904_GDBN__ normally ignores breakpoints when it resumes execution, until at
1905least one instruction has been executed. If it did not do this, you
1906would be unable to proceed past a breakpoint without first disabling the
1907breakpoint. This rule applies whether or not the breakpoint already
29a2b744 1908existed when your program stopped.
70b88761
RP
1909
1910@item break @dots{} if @var{cond}
1911Set a breakpoint with condition @var{cond}; evaluate the expression
1912@var{cond} each time the breakpoint is reached, and stop only if the
3d3ab540 1913value is nonzero---that is, if @var{cond} evaluates as true.
1041a570
RP
1914@samp{@dots{}} stands for one of the possible arguments described
1915above (or no argument) specifying where to break. @xref{Conditions,
1916,Break Conditions}, for more information on breakpoint conditions.
70b88761
RP
1917
1918@item tbreak @var{args}
1919@kindex tbreak
1920Set a breakpoint enabled only for one stop. @var{args} are the
1921same as for the @code{break} command, and the breakpoint is set in the same
29a2b744
RP
1922way, but the breakpoint is automatically disabled after the first time your
1923program stops there. @xref{Disabling, ,Disabling Breakpoints}.
70b88761
RP
1924
1925@item rbreak @var{regex}
1926@kindex rbreak
1927@cindex regular expression
4906534f 1928@c FIXME what kind of regexp?
70b88761 1929Set breakpoints on all functions matching the regular expression
b80282d5 1930@var{regex}. This command
70b88761
RP
1931sets an unconditional breakpoint on all matches, printing a list of all
1932breakpoints it set. Once these breakpoints are set, they are treated
1933just like the breakpoints set with the @code{break} command. They can
1934be deleted, disabled, made conditional, etc., in the standard ways.
1935
0f153e74 1936_if__(!_CONLY__)
b80282d5
RP
1937When debugging C++ programs, @code{rbreak} is useful for setting
1938breakpoints on overloaded functions that are not members of any special
1939classes.
0f153e74 1940_fi__(!_CONLY__)
b80282d5 1941
70b88761 1942@kindex info breakpoints
c338a2fd 1943@cindex @code{$_} and @code{info breakpoints}
70b88761 1944@item info breakpoints @r{[}@var{n}@r{]}
6ca72cc6
RP
1945@itemx info break @r{[}@var{n}@r{]}
1946@itemx info watchpoints @r{[}@var{n}@r{]}
1947Print a table of all breakpoints and watchpoints set and not
1948deleted, with the following columns for each breakpoint:
1949
1950@table @emph
1951@item Breakpoint Numbers
1952@item Type
1953Breakpoint or watchpoint.
1954@item Disposition
1955Whether the breakpoint is marked to be disabled or deleted when hit.
1956@item Enabled or Disabled
d24e0922 1957Enabled breakpoints are marked with @samp{y}. @samp{n} marks breakpoints
6ca72cc6
RP
1958that are not enabled.
1959@item Address
1960Where the breakpoint is in your program, as a memory address
1961@item What
1962Where the breakpoint is in the source for your program, as a file and
1963line number.
1964@end table
1965
1966@noindent
1967Breakpoint commands, if any, are listed after the line for the
1968corresponding breakpoint.
1969
1970@noindent
1971@code{info break} with a breakpoint
29a2b744
RP
1972number @var{n} as argument lists only that breakpoint. The
1973convenience variable @code{$_} and the default examining-address for
1974the @code{x} command are set to the address of the last breakpoint
6ca72cc6 1975listed (@pxref{Memory, ,Examining Memory}).
1041a570 1976@end table
70b88761 1977
1041a570
RP
1978_GDBN__ allows you to set any number of breakpoints at the same place in
1979your program. There is nothing silly or meaningless about this. When
1980the breakpoints are conditional, this is even useful
29a2b744 1981(@pxref{Conditions, ,Break Conditions}).
70b88761 1982
6ca72cc6
RP
1983@cindex negative breakpoint numbers
1984@cindex internal _GDBN__ breakpoints
1985_GDBN__ itself sometimes sets breakpoints in your program for special
1986purposes, such as proper handling of @code{longjmp} (in C programs).
1987These internal breakpoints are assigned negative numbers, starting with
5a2c1d85 1988@code{-1}; @samp{info breakpoints} does not display them.
d48da190 1989
5a2c1d85
RP
1990You can see these breakpoints with the _GDBN__ maintenance command
1991@samp{maint info breakpoints}.
6ca72cc6
RP
1992
1993@table @code
d48da190
RP
1994@kindex maint info breakpoints
1995@item maint info breakpoints
6ca72cc6
RP
1996Using the same format as @samp{info breakpoints}, display both the
1997breakpoints you've set explicitly, and those _GDBN__ is using for
1998internal purposes. Internal breakpoints are shown with negative
1999breakpoint numbers. The type column identifies what kind of breakpoint
2000is shown:
2001
2002@table @code
2003@item breakpoint
2004Normal, explicitly set breakpoint.
2005
2006@item watchpoint
2007Normal, explicitly set watchpoint.
2008
2009@item longjmp
2010Internal breakpoint, used to handle correctly stepping through
2011@code{longjmp} calls.
2012
2013@item longjmp resume
2014Internal breakpoint at the target of a @code{longjmp}.
2015
2016@item until
2017Temporary internal breakpoint used by the _GDBN__ @code{until} command.
2018
2019@item finish
2020Temporary internal breakpoint used by the _GDBN__ @code{finish} command.
2021@end table
2022
2023@end table
2024
2025
4eb4cf57 2026@node Set Watchpoints
70b88761
RP
2027@subsection Setting Watchpoints
2028@cindex setting watchpoints
1041a570 2029
70b88761 2030You can use a watchpoint to stop execution whenever the value of an
e251e767 2031expression changes, without having to predict a particular place
70b88761
RP
2032where this may happen.
2033
2034Watchpoints currently execute two orders of magnitude more slowly than
2035other breakpoints, but this can well be worth it to catch errors where
2036you have no clue what part of your program is the culprit. Some
2037processors provide special hardware to support watchpoint evaluation; future
2038releases of _GDBN__ will use such hardware if it is available.
2039
2040@table @code
e251e767 2041@kindex watch
70b88761
RP
2042@item watch @var{expr}
2043Set a watchpoint for an expression.
2044
2045@kindex info watchpoints
2046@item info watchpoints
6ca72cc6
RP
2047This command prints a list of watchpoints and breakpoints; it is the
2048same as @code{info break}.
70b88761
RP
2049@end table
2050
4eb4cf57 2051@node Exception Handling
70b88761
RP
2052@subsection Breakpoints and Exceptions
2053@cindex exception handlers
2054
b80282d5 2055Some languages, such as GNU C++, implement exception handling. You can
29a2b744
RP
2056use _GDBN__ to examine what caused your program to raise an exception,
2057and to list the exceptions your program is prepared to handle at a
70b88761
RP
2058given point in time.
2059
2060@table @code
2061@item catch @var{exceptions}
2062@kindex catch
2063You can set breakpoints at active exception handlers by using the
2064@code{catch} command. @var{exceptions} is a list of names of exceptions
2065to catch.
2066@end table
2067
29a2b744
RP
2068You can use @code{info catch} to list active exception handlers.
2069@xref{Frame Info, ,Information About a Frame}.
70b88761
RP
2070
2071There are currently some limitations to exception handling in _GDBN__.
2072These will be corrected in a future release.
2073
2074@itemize @bullet
2075@item
2076If you call a function interactively, _GDBN__ normally returns
2077control to you when the function has finished executing. If the call
2078raises an exception, however, the call may bypass the mechanism that
29a2b744 2079returns control to you and cause your program to simply continue
70b88761
RP
2080running until it hits a breakpoint, catches a signal that _GDBN__ is
2081listening for, or exits.
2082@item
2083You cannot raise an exception interactively.
2084@item
2085You cannot interactively install an exception handler.
2086@end itemize
2087
2088@cindex raise exceptions
2089Sometimes @code{catch} is not the best way to debug exception handling:
29a2b744 2090if you need to know exactly where an exception is raised, it is better to
70b88761
RP
2091stop @emph{before} the exception handler is called, since that way you
2092can see the stack before any unwinding takes place. If you set a
2093breakpoint in an exception handler instead, it may not be easy to find
2094out where the exception was raised.
2095
2096To stop just before an exception handler is called, you need some
b80282d5 2097knowledge of the implementation. In the case of GNU C++, exceptions are
70b88761
RP
2098raised by calling a library function named @code{__raise_exception}
2099which has the following ANSI C interface:
2100
2101@example
b80282d5 2102 /* @var{addr} is where the exception identifier is stored.
70b88761
RP
2103 ID is the exception identifier. */
2104 void __raise_exception (void **@var{addr}, void *@var{id});
2105@end example
2106
2107@noindent
2108To make the debugger catch all exceptions before any stack
2109unwinding takes place, set a breakpoint on @code{__raise_exception}
29a2b744 2110(@pxref{Breakpoints, ,Breakpoints Watchpoints and Exceptions}).
70b88761 2111
29a2b744
RP
2112With a conditional breakpoint (@pxref{Conditions, ,Break Conditions})
2113that depends on the value of @var{id}, you can stop your program when
2114a specific exception is raised. You can use multiple conditional
2115breakpoints to stop your program when any of a number of exceptions are
2116raised.
70b88761 2117
4eb4cf57 2118@node Delete Breaks
70b88761
RP
2119@subsection Deleting Breakpoints
2120
2121@cindex clearing breakpoints, watchpoints
2122@cindex deleting breakpoints, watchpoints
2123It is often necessary to eliminate a breakpoint or watchpoint once it
29a2b744 2124has done its job and you no longer want your program to stop there. This
70b88761
RP
2125is called @dfn{deleting} the breakpoint. A breakpoint that has been
2126deleted no longer exists; it is forgotten.
2127
2128With the @code{clear} command you can delete breakpoints according to
29a2b744 2129where they are in your program. With the @code{delete} command you can
70b88761
RP
2130delete individual breakpoints or watchpoints by specifying their
2131breakpoint numbers.
2132
2133It is not necessary to delete a breakpoint to proceed past it. _GDBN__
2134automatically ignores breakpoints on the first instruction to be executed
2135when you continue execution without changing the execution address.
2136
2137@table @code
2138@item clear
2139@kindex clear
2140Delete any breakpoints at the next instruction to be executed in the
29a2b744
RP
2141selected stack frame (@pxref{Selection, ,Selecting a Frame}). When
2142the innermost frame is selected, this is a good way to delete a
2143breakpoint where your program just stopped.
70b88761
RP
2144
2145@item clear @var{function}
2146@itemx clear @var{filename}:@var{function}
2147Delete any breakpoints set at entry to the function @var{function}.
2148
2149@item clear @var{linenum}
2150@itemx clear @var{filename}:@var{linenum}
2151Delete any breakpoints set at or within the code of the specified line.
2152
2153@item delete @r{[}breakpoints@r{]} @r{[}@var{bnums}@dots{}@r{]}
2154@cindex delete breakpoints
2155@kindex delete
2156@kindex d
2157Delete the breakpoints or watchpoints of the numbers specified as
2158arguments. If no argument is specified, delete all breakpoints (_GDBN__
1041a570 2159asks confirmation, unless you have @code{set confirm off}). You
70b88761
RP
2160can abbreviate this command as @code{d}.
2161@end table
2162
4eb4cf57 2163@node Disabling
70b88761
RP
2164@subsection Disabling Breakpoints
2165
2166@cindex disabled breakpoints
2167@cindex enabled breakpoints
2168Rather than deleting a breakpoint or watchpoint, you might prefer to
2169@dfn{disable} it. This makes the breakpoint inoperative as if it had
2170been deleted, but remembers the information on the breakpoint so that
2171you can @dfn{enable} it again later.
2172
2173You disable and enable breakpoints and watchpoints with the
2174@code{enable} and @code{disable} commands, optionally specifying one or
2175more breakpoint numbers as arguments. Use @code{info break} or
2176@code{info watch} to print a list of breakpoints or watchpoints if you
29a2b744 2177do not know which numbers to use.
70b88761
RP
2178
2179A breakpoint or watchpoint can have any of four different states of
2180enablement:
2181
2182@itemize @bullet
2183@item
29a2b744 2184Enabled. The breakpoint will stop your program. A breakpoint set
70b88761
RP
2185with the @code{break} command starts out in this state.
2186@item
29a2b744 2187Disabled. The breakpoint has no effect on your program.
70b88761 2188@item
29a2b744 2189Enabled once. The breakpoint will stop your program, but
70b88761
RP
2190when it does so it will become disabled. A breakpoint set
2191with the @code{tbreak} command starts out in this state.
2192@item
29a2b744 2193Enabled for deletion. The breakpoint will stop your program, but
70b88761
RP
2194immediately after it does so it will be deleted permanently.
2195@end itemize
2196
2197You can use the following commands to enable or disable breakpoints and
2198watchpoints:
2199
2200@table @code
2201@item disable @r{[}breakpoints@r{]} @r{[}@var{bnums}@dots{}@r{]}
2202@kindex disable breakpoints
2203@kindex disable
2204@kindex dis
2205Disable the specified breakpoints---or all breakpoints, if none are
2206listed. A disabled breakpoint has no effect but is not forgotten. All
2207options such as ignore-counts, conditions and commands are remembered in
2208case the breakpoint is enabled again later. You may abbreviate
2209@code{disable} as @code{dis}.
2210
2211@item enable @r{[}breakpoints@r{]} @r{[}@var{bnums}@dots{}@r{]}
2212@kindex enable breakpoints
2213@kindex enable
2214Enable the specified breakpoints (or all defined breakpoints). They
29a2b744 2215become effective once again in stopping your program.
70b88761
RP
2216
2217@item enable @r{[}breakpoints@r{]} once @var{bnums}@dots{}
2218Enable the specified breakpoints temporarily. Each will be disabled
29a2b744 2219again the next time it stops your program.
70b88761
RP
2220
2221@item enable @r{[}breakpoints@r{]} delete @var{bnums}@dots{}
2222Enable the specified breakpoints to work once and then die. Each of
29a2b744 2223the breakpoints will be deleted the next time it stops your program.
70b88761
RP
2224@end table
2225
29a2b744
RP
2226Save for a breakpoint set with @code{tbreak} (@pxref{Set Breaks,
2227,Setting Breakpoints}), breakpoints that you set are initially
2228enabled; subsequently, they become disabled or enabled only when you
2229use one of the commands above. (The command @code{until} can set and
2230delete a breakpoint of its own, but it will not change the state of
98fe4566 2231your other breakpoints; see @ref{Continuing and Stepping, ,Continuing and Stepping}.)
70b88761 2232
4eb4cf57 2233@node Conditions
70b88761
RP
2234@subsection Break Conditions
2235@cindex conditional breakpoints
2236@cindex breakpoint conditions
2237
4906534f
RP
2238@c FIXME what is scope of break condition expr? Context where wanted?
2239@c in particular for a watchpoint?
29a2b744 2240The simplest sort of breakpoint breaks every time your program reaches a
70b88761
RP
2241specified place. You can also specify a @dfn{condition} for a
2242breakpoint. A condition is just a Boolean expression in your
1041a570
RP
2243programming language (@pxref{Expressions, ,Expressions}). A breakpoint with
2244a condition evaluates the expression each time your program reaches it,
2245and your program stops only if the condition is @emph{true}.
3d3ab540
RP
2246
2247This is the converse of using assertions for program validation; in that
2248situation, you want to stop when the assertion is violated---that is,
2249when the condition is false. In C, if you want to test an assertion expressed
e251e767 2250by the condition @var{assert}, you should set the condition
3d3ab540 2251@samp{! @var{assert}} on the appropriate breakpoint.
70b88761
RP
2252
2253Conditions are also accepted for watchpoints; you may not need them,
2254since a watchpoint is inspecting the value of an expression anyhow---but
2255it might be simpler, say, to just set a watchpoint on a variable name,
2256and specify a condition that tests whether the new value is an interesting
e251e767 2257one.
70b88761 2258
29a2b744 2259Break conditions can have side effects, and may even call functions in
70b88761 2260your program. This can be useful, for example, to activate functions
29a2b744
RP
2261that log program progress, or to use your own print functions to
2262format special data structures. The effects are completely predictable
2263unless there is another enabled breakpoint at the same address. (In
2264that case, _GDBN__ might see the other breakpoint first and stop your
2265program without checking the condition of this one.) Note that
2266breakpoint commands are usually more convenient and flexible for the
2267purpose of performing side effects when a breakpoint is reached
2268(@pxref{Break Commands, ,Breakpoint Command Lists}).
70b88761
RP
2269
2270Break conditions can be specified when a breakpoint is set, by using
29a2b744
RP
2271@samp{if} in the arguments to the @code{break} command. @xref{Set
2272Breaks, ,Setting Breakpoints}. They can also be changed at any time
2273with the @code{condition} command. The @code{watch} command does not
2274recognize the @code{if} keyword; @code{condition} is the only way to
2275impose a further condition on a watchpoint.
70b88761 2276
e251e767
RP
2277@table @code
2278@item condition @var{bnum} @var{expression}
2279@kindex condition
70b88761
RP
2280Specify @var{expression} as the break condition for breakpoint or
2281watchpoint number @var{bnum}. From now on, this breakpoint will stop
29a2b744 2282your program only if the value of @var{expression} is true (nonzero, in
70b88761
RP
2283C). When you use @code{condition}, _GDBN__ checks @var{expression}
2284immediately for syntactic correctness, and to determine whether symbols
1041a570 2285in it have referents in the context of your breakpoint.
29a2b744 2286@c FIXME so what does GDB do if there is no referent? Moreover, what
4906534f
RP
2287@c about watchpoints?
2288_GDBN__ does
70b88761 2289not actually evaluate @var{expression} at the time the @code{condition}
1041a570 2290command is given, however. @xref{Expressions, ,Expressions}.
70b88761
RP
2291
2292@item condition @var{bnum}
2293Remove the condition from breakpoint number @var{bnum}. It becomes
2294an ordinary unconditional breakpoint.
2295@end table
2296
2297@cindex ignore count (of breakpoint)
2298A special case of a breakpoint condition is to stop only when the
2299breakpoint has been reached a certain number of times. This is so
2300useful that there is a special way to do it, using the @dfn{ignore
2301count} of the breakpoint. Every breakpoint has an ignore count, which
2302is an integer. Most of the time, the ignore count is zero, and
29a2b744 2303therefore has no effect. But if your program reaches a breakpoint whose
70b88761
RP
2304ignore count is positive, then instead of stopping, it just decrements
2305the ignore count by one and continues. As a result, if the ignore count
2306value is @var{n}, the breakpoint will not stop the next @var{n} times it
2307is reached.
2308
2309@table @code
2310@item ignore @var{bnum} @var{count}
2311@kindex ignore
2312Set the ignore count of breakpoint number @var{bnum} to @var{count}.
2313The next @var{count} times the breakpoint is reached, your program's
2314execution will not stop; other than to decrement the ignore count, _GDBN__
2315takes no action.
2316
2317To make the breakpoint stop the next time it is reached, specify
2318a count of zero.
2319
2320@item continue @var{count}
2321@itemx c @var{count}
2322@itemx fg @var{count}
2323@kindex continue @var{count}
29a2b744
RP
2324Continue execution of your program, setting the ignore count of the
2325breakpoint where your program stopped to @var{count} minus one.
2326Thus, your program will not stop at this breakpoint until the
70b88761
RP
2327@var{count}'th time it is reached.
2328
29a2b744 2329An argument to this command is meaningful only when your program stopped
70b88761
RP
2330due to a breakpoint. At other times, the argument to @code{continue} is
2331ignored.
2332
2333The synonym @code{fg} is provided purely for convenience, and has
2334exactly the same behavior as other forms of the command.
2335@end table
2336
2337If a breakpoint has a positive ignore count and a condition, the condition
2338is not checked. Once the ignore count reaches zero, the condition will
2339be checked.
2340
29a2b744 2341You could achieve the effect of the ignore count with a condition such
1041a570
RP
2342as _0__@w{@samp{$foo-- <= 0}}_1__ using a debugger convenience variable that
2343is decremented each time. @xref{Convenience Vars, ,Convenience
2344Variables}.
70b88761 2345
4eb4cf57 2346@node Break Commands
70b88761
RP
2347@subsection Breakpoint Command Lists
2348
2349@cindex breakpoint commands
2350You can give any breakpoint (or watchpoint) a series of commands to
29a2b744 2351execute when your program stops due to that breakpoint. For example, you
70b88761
RP
2352might want to print the values of certain expressions, or enable other
2353breakpoints.
2354
2355@table @code
2356@item commands @r{[}@var{bnum}@r{]}
2357@itemx @dots{} @var{command-list} @dots{}
2358@itemx end
2359@kindex commands
2360@kindex end
2361Specify a list of commands for breakpoint number @var{bnum}. The commands
2362themselves appear on the following lines. Type a line containing just
2363@code{end} to terminate the commands.
2364
203eea5d
RP
2365To remove all commands from a breakpoint, type @code{commands} and
2366follow it immediately with @code{end}; that is, give no commands.
70b88761
RP
2367
2368With no @var{bnum} argument, @code{commands} refers to the last
2369breakpoint or watchpoint set (not to the breakpoint most recently
2370encountered).
2371@end table
2372
2373Pressing @key{RET} as a means of repeating the last _GDBN__ command is
2374disabled within a @var{command-list}.
2375
29a2b744 2376You can use breakpoint commands to start your program up again. Simply
70b88761
RP
2377use the @code{continue} command, or @code{step}, or any other command
2378that resumes execution. Subsequent commands in the command list are
2379ignored.
2380
2381@kindex silent
2382If the first command specified is @code{silent}, the usual message about
2383stopping at a breakpoint is not printed. This may be desirable for
2384breakpoints that are to print a specific message and then continue.
2385If the remaining commands too print nothing, you will see no sign that
e251e767 2386the breakpoint was reached at all. @code{silent} is meaningful only
70b88761
RP
2387at the beginning of a breakpoint command list.
2388
29a2b744
RP
2389The commands @code{echo} and @code{output} that allow you to print
2390precisely controlled output are often useful in silent breakpoints.
2391@xref{Output, ,Commands for Controlled Output}.
70b88761
RP
2392
2393For example, here is how you could use breakpoint commands to print the
2394value of @code{x} at entry to @code{foo} whenever @code{x} is positive.
2395
2396_0__@example
2397break foo if x>0
2398commands
2399silent
2400echo x is\040
2401output x
2402echo \n
2403cont
2404end
2405_1__@end example
2406
2407One application for breakpoint commands is to compensate for one bug so
2408you can test for another. Put a breakpoint just after the erroneous line
2409of code, give it a condition to detect the case in which something
2410erroneous has been done, and give it commands to assign correct values
2411to any variables that need them. End with the @code{continue} command
29a2b744 2412so that your program does not stop, and start with the @code{silent}
70b88761
RP
2413command so that no output is produced. Here is an example:
2414
2415@example
2416break 403
2417commands
2418silent
2419set x = y + 4
2420cont
2421end
2422@end example
2423
2424@cindex lost output
2425One deficiency in the operation of automatically continuing breakpoints
2426under Unix appears when your program uses raw mode for the terminal.
2427_GDBN__ switches back to its own terminal modes (not raw) before executing
2428commands, and then must switch back to raw mode when your program is
e251e767 2429continued. This causes any pending terminal input to be lost.
70b88761
RP
2430@c FIXME: revisit below when GNU sys avail.
2431@c In the GNU system, this will be fixed by changing the behavior of
2432@c terminal modes.
2433
2434Under Unix, you can get around this problem by writing actions into
2435the breakpoint condition rather than in commands. For example
2436
2437@example
2438condition 5 (x = y + 4), 0
2439@end example
2440
2441@noindent
1041a570
RP
2442specifies a condition expression (@pxref{Expressions, ,Expressions}) that will
2443change @code{x} as needed, then always have the value zero so your
2444program will not stop. No input is lost here, because _GDBN__ evaluates
2445break conditions without changing the terminal modes. When you want
2446to have nontrivial conditions for performing the side effects, the
2447operators @samp{&&}, @samp{||} and @samp{?@dots{}:} may be useful.
70b88761 2448
4eb4cf57 2449@node Breakpoint Menus
70b88761 2450@subsection Breakpoint Menus
b80282d5 2451@cindex overloading
e251e767 2452@cindex symbol overloading
70b88761
RP
2453
2454Some programming languages (notably C++) permit a single function name
2455to be defined several times, for application in different contexts.
2456This is called @dfn{overloading}. When a function name is overloaded,
6f3ec223
RP
2457@samp{break @var{function}} is not enough to tell _GDBN__ where you want
2458a breakpoint. If you realize this will be a problem, you can use
2459something like @samp{break @var{function}(@var{types})} to specify which
2460particular version of the function you want. Otherwise, _GDBN__ offers
2461you a menu of numbered choices for different possible breakpoints, and
2462waits for your selection with the prompt @samp{>}. The first two
2463options are always @samp{[0] cancel} and @samp{[1] all}. Typing @kbd{1}
2464sets a breakpoint at each definition of @var{function}, and typing
2465@kbd{0} aborts the @code{break} command without setting any new
2466breakpoints.
70b88761
RP
2467
2468For example, the following session excerpt shows an attempt to set a
e251e767 2469breakpoint at the overloaded symbol @code{String::after}.
70b88761
RP
2470We choose three particular definitions of that function name:
2471
6f3ec223 2472@c FIXME! This is likely to change to show arg type lists, at least
70b88761
RP
2473@example
2474(_GDBP__) b String::after
2475[0] cancel
2476[1] all
2477[2] file:String.cc; line number:867
2478[3] file:String.cc; line number:860
2479[4] file:String.cc; line number:875
2480[5] file:String.cc; line number:853
2481[6] file:String.cc; line number:846
2482[7] file:String.cc; line number:735
2483> 2 4 6
2484Breakpoint 1 at 0xb26c: file String.cc, line 867.
2485Breakpoint 2 at 0xb344: file String.cc, line 875.
2486Breakpoint 3 at 0xafcc: file String.cc, line 846.
2487Multiple breakpoints were set.
2488Use the "delete" command to delete unwanted breakpoints.
e251e767 2489(_GDBP__)
70b88761
RP
2490@end example
2491
4eb4cf57 2492@node Error in Breakpoints
70b88761
RP
2493@subsection ``Cannot Insert Breakpoints''
2494
e251e767 2495@c FIXME: "cannot insert breakpoints" error, v unclear.
70b88761 2496@c Q in pending mail to Gilmore. [email protected], 26mar91
e251e767 2497@c some light may be shed by looking at instances of
d24e0922 2498@c ONE_PROCESS_WRITETEXT. But error message seems possible otherwise
c338a2fd 2499@c too. pesch, 20sep91
70b88761
RP
2500Under some operating systems, breakpoints cannot be used in a program if
2501any other process is running that program. In this situation,
2502attempting to run or continue a program with a breakpoint causes _GDBN__
2503to stop the other process.
2504
2505When this happens, you have three ways to proceed:
2506
2507@enumerate
2508@item
2509Remove or disable the breakpoints, then continue.
2510
2511@item
29a2b744 2512Suspend _GDBN__, and copy the file containing your program to a new name.
70b88761 2513Resume _GDBN__ and use the @code{exec-file} command to specify that _GDBN__
29a2b744 2514should run your program under that name. Then start your program again.
70b88761
RP
2515
2516@c FIXME: RMS commented here "Show example". Maybe when someone
2517@c explains the first FIXME: in this section...
2518
2519@item
29a2b744 2520Relink your program so that the text segment is nonsharable, using the
70b88761
RP
2521linker option @samp{-N}. The operating system limitation may not apply
2522to nonsharable executables.
2523@end enumerate
2524
4eb4cf57 2525@node Continuing and Stepping
3d3ab540 2526@section Continuing and Stepping
70b88761
RP
2527
2528@cindex stepping
7463aadd
RP
2529@cindex continuing
2530@cindex resuming execution
3d3ab540 2531@dfn{Continuing} means resuming program execution until your program
cedaf8bc
RP
2532completes normally. In contrast, @dfn{stepping} means executing just
2533one more ``step'' of your program, where ``step'' may mean either one
2534line of source code, or one machine instruction (depending on what
2535particular command you use). Either when continuing
4eb4cf57
RP
2536or when stepping, your program may stop even sooner, due to
2537_if__(_BARE__)
2538a breakpoint.
2539_fi__(_BARE__)
2540_if__(!_BARE__)
2541a breakpoint or to a signal. (If due to a signal, you may want to use
2542@code{handle}, or use @samp{signal 0} to resume execution.
2543@xref{Signals, ,Signals}.)
2544_fi__(!_BARE__)
3d3ab540
RP
2545
2546@table @code
2547@item continue @r{[}@var{ignore-count}@r{]}
2548@kindex continue
29a2b744 2549Resume program execution, at the address where your program last stopped;
3d3ab540
RP
2550any breakpoints set at that address are bypassed. The optional argument
2551@var{ignore-count} allows you to specify a further number of times to
2552ignore a breakpoint at this location; its effect is like that of
29a2b744 2553@code{ignore} (@pxref{Conditions, ,Break Conditions}).
3d3ab540
RP
2554
2555To resume execution at a different place, you can use @code{return}
29a2b744
RP
2556(@pxref{Returning, ,Returning from a Function}) to go back to the
2557calling function; or @code{jump} (@pxref{Jumping, ,Continuing at a
1041a570 2558Different Address}) to go to an arbitrary location in your program.
3d3ab540 2559@end table
7463aadd
RP
2560
2561A typical technique for using stepping is to set a breakpoint
29a2b744
RP
2562(@pxref{Breakpoints, ,Breakpoints Watchpoints and Exceptions}) at the
2563beginning of the function or the section of your program where a
2564problem is believed to lie, run your program until it stops at that
2565breakpoint, and then step through the suspect area, examining the
2566variables that are interesting, until you see the problem happen.
70b88761
RP
2567
2568@table @code
2569@item step
2570@kindex step
2571@kindex s
29a2b744 2572Continue running your program until control reaches a different source
7463aadd 2573line, then stop it and return control to _GDBN__. This command is
70b88761
RP
2574abbreviated @code{s}.
2575
3d3ab540
RP
2576@quotation
2577@emph{Warning:} If you use the @code{step} command while control is
2578within a function that was compiled without debugging information,
2579execution will proceed until control reaches another function.
2580@end quotation
70b88761
RP
2581
2582@item step @var{count}
2583Continue running as in @code{step}, but do so @var{count} times. If a
2584breakpoint is reached or a signal not related to stepping occurs before
2585@var{count} steps, stepping stops right away.
2586
7463aadd 2587@item next @r{[}@var{count}@r{]}
70b88761
RP
2588@kindex next
2589@kindex n
7463aadd
RP
2590Continue to the next source line in the current (innermost) stack frame.
2591Similar to @code{step}, but any function calls appearing within the line
2592of code are executed without stopping. Execution stops when control
2593reaches a different line of code at the stack level which was executing
2594when the @code{next} command was given. This command is abbreviated
2595@code{n}.
70b88761 2596
7463aadd 2597An argument @var{count} is a repeat count, as for @code{step}.
70b88761
RP
2598
2599@code{next} within a function that lacks debugging information acts like
2600@code{step}, but any function calls appearing within the code of the
2601function are executed without stopping.
2602
2603@item finish
2604@kindex finish
7463aadd
RP
2605Continue running until just after function in the selected stack frame
2606returns. Print the returned value (if any).
70b88761 2607
29a2b744 2608Contrast this with the @code{return} command (@pxref{Returning,
1041a570 2609,Returning from a Function}).
70b88761
RP
2610
2611@item until
2612@kindex until
2613@item u
2614@kindex u
2615Continue running until a source line past the current line, in the
2616current stack frame, is reached. This command is used to avoid single
2617stepping through a loop more than once. It is like the @code{next}
2618command, except that when @code{until} encounters a jump, it
2619automatically continues execution until the program counter is greater
2620than the address of the jump.
2621
2622This means that when you reach the end of a loop after single stepping
29a2b744 2623though it, @code{until} will cause your program to continue execution
70b88761
RP
2624until the loop is exited. In contrast, a @code{next} command at the end
2625of a loop will simply step back to the beginning of the loop, which
2626would force you to step through the next iteration.
2627
29a2b744 2628@code{until} always stops your program if it attempts to exit the current
70b88761
RP
2629stack frame.
2630
2631@code{until} may produce somewhat counterintuitive results if the order
7463aadd 2632of machine code does not match the order of the source lines. For
70b88761
RP
2633example, in the following excerpt from a debugging session, the @code{f}
2634(@code{frame}) command shows that execution is stopped at line
2635@code{206}; yet when we use @code{until}, we get to line @code{195}:
2636
2637@example
2638(_GDBP__) f
2639#0 main (argc=4, argv=0xf7fffae8) at m4.c:206
b80282d5 2640206 expand_input();
70b88761 2641(_GDBP__) until
b80282d5 2642195 for ( ; argc > 0; NEXTARG) @{
70b88761
RP
2643@end example
2644
7463aadd
RP
2645This happened because, for execution efficiency, the compiler had
2646generated code for the loop closure test at the end, rather than the
2647start, of the loop---even though the test in a C @code{for}-loop is
2648written before the body of the loop. The @code{until} command appeared
2649to step back to the beginning of the loop when it advanced to this
2650expression; however, it has not really gone to an earlier
2651statement---not in terms of the actual machine code.
70b88761
RP
2652
2653@code{until} with no argument works by means of single
2654instruction stepping, and hence is slower than @code{until} with an
2655argument.
2656
2657@item until @var{location}
2658@item u @var{location}
29a2b744
RP
2659Continue running your program until either the specified location is
2660reached, or the current stack frame returns. @var{location} is any of
2661the forms of argument acceptable to @code{break} (@pxref{Set Breaks,
2662,Setting Breakpoints}). This form of the command uses breakpoints,
1041a570 2663and hence is quicker than @code{until} without an argument.
70b88761
RP
2664
2665@item stepi
2666@itemx si
2667@kindex stepi
2668@kindex si
2669Execute one machine instruction, then stop and return to the debugger.
2670
2671It is often useful to do @samp{display/i $pc} when stepping by machine
2672instructions. This will cause the next instruction to be executed to
29a2b744
RP
2673be displayed automatically at each stop. @xref{Auto Display,
2674,Automatic Display}.
70b88761
RP
2675
2676An argument is a repeat count, as in @code{step}.
2677
2678@item nexti
2679@itemx ni
2680@kindex nexti
2681@kindex ni
2682Execute one machine instruction, but if it is a function call,
2683proceed until the function returns.
2684
2685An argument is a repeat count, as in @code{next}.
70b88761
RP
2686@end table
2687
4eb4cf57
RP
2688_if__(_GENERIC__ || !_H8__)
2689@node Signals
70b88761
RP
2690@section Signals
2691@cindex signals
2692
2693A signal is an asynchronous event that can happen in a program. The
2694operating system defines the possible kinds of signals, and gives each
2695kind a name and a number. For example, in Unix @code{SIGINT} is the
2696signal a program gets when you type an interrupt (often @kbd{C-c});
2697@code{SIGSEGV} is the signal a program gets from referencing a place in
2698memory far away from all the areas in use; @code{SIGALRM} occurs when
29a2b744 2699the alarm clock timer goes off (which happens only if your program has
70b88761
RP
2700requested an alarm).
2701
2702@cindex fatal signals
2703Some signals, including @code{SIGALRM}, are a normal part of the
29a2b744
RP
2704functioning of your program. Others, such as @code{SIGSEGV}, indicate
2705errors; these signals are @dfn{fatal} (kill your program immediately) if the
70b88761 2706program has not specified in advance some other way to handle the signal.
29a2b744 2707@code{SIGINT} does not indicate an error in your program, but it is normally
70b88761
RP
2708fatal so it can carry out the purpose of the interrupt: to kill the program.
2709
29a2b744
RP
2710_GDBN__ has the ability to detect any occurrence of a signal in your
2711program. You can tell _GDBN__ in advance what to do for each kind of
2712signal.
70b88761
RP
2713
2714@cindex handling signals
2715Normally, _GDBN__ is set up to ignore non-erroneous signals like @code{SIGALRM}
29a2b744
RP
2716(so as not to interfere with their role in the functioning of your program)
2717but to stop your program immediately whenever an error signal happens.
70b88761
RP
2718You can change these settings with the @code{handle} command.
2719
2720@table @code
2721@item info signals
2722@kindex info signals
2723Print a table of all the kinds of signals and how _GDBN__ has been told to
2724handle each one. You can use this to see the signal numbers of all
2725the defined types of signals.
2726
2727@item handle @var{signal} @var{keywords}@dots{}
2728@kindex handle
2729Change the way _GDBN__ handles signal @var{signal}. @var{signal} can be the
2730number of a signal or its name (with or without the @samp{SIG} at the
2731beginning). The @var{keywords} say what change to make.
2732@end table
2733
2734@c @group
2735The keywords allowed by the @code{handle} command can be abbreviated.
2736Their full names are:
2737
2738@table @code
2739@item nostop
29a2b744 2740_GDBN__ should not stop your program when this signal happens. It may
70b88761
RP
2741still print a message telling you that the signal has come in.
2742
2743@item stop
29a2b744 2744_GDBN__ should stop your program when this signal happens. This implies
70b88761
RP
2745the @code{print} keyword as well.
2746
2747@item print
2748_GDBN__ should print a message when this signal happens.
2749
2750@item noprint
2751_GDBN__ should not mention the occurrence of the signal at all. This
2752implies the @code{nostop} keyword as well.
2753
2754@item pass
29a2b744 2755_GDBN__ should allow your program to see this signal; your program will be
70b88761
RP
2756able to handle the signal, or may be terminated if the signal is fatal
2757and not handled.
2758
2759@item nopass
29a2b744 2760_GDBN__ should not allow your program to see this signal.
70b88761
RP
2761@end table
2762@c @end group
2763
29a2b744 2764When a signal has been set to stop your program, your program cannot see the
70b88761 2765signal until you continue. It will see the signal then, if @code{pass} is
6ca72cc6 2766in effect for the signal in question @emph{at that time}. In other words,
70b88761
RP
2767after _GDBN__ reports a signal, you can use the @code{handle} command with
2768@code{pass} or @code{nopass} to control whether that signal will be seen by
29a2b744 2769your program when you later continue it.
70b88761 2770
29a2b744 2771You can also use the @code{signal} command to prevent your program from
70b88761 2772seeing a signal, or cause it to see a signal it normally would not see,
29a2b744 2773or to give it any signal at any time. For example, if your program stopped
7463aadd
RP
2774due to some sort of memory reference error, you might store correct
2775values into the erroneous variables and continue, hoping to see more
29a2b744
RP
2776execution; but your program would probably terminate immediately as
2777a result of the fatal signal once it saw the signal. To prevent this,
2778you can continue with @samp{signal 0}. @xref{Signaling, ,Giving your
2779Program a Signal}.
4eb4cf57 2780_fi__(_GENERIC__ || !_H8__)
70b88761 2781
4eb4cf57 2782@node Stack
70b88761
RP
2783@chapter Examining the Stack
2784
2785When your program has stopped, the first thing you need to know is where it
2786stopped and how it got there.
2787
2788@cindex call stack
2789Each time your program performs a function call, the information about
29a2b744 2790where in your program the call was made from is saved in a block of data
70b88761
RP
2791called a @dfn{stack frame}. The frame also contains the arguments of the
2792call and the local variables of the function that was called. All the
2793stack frames are allocated in a region of memory called the @dfn{call
2794stack}.
2795
2796When your program stops, the _GDBN__ commands for examining the stack allow you
2797to see all of this information.
2798
2799@cindex selected frame
2800One of the stack frames is @dfn{selected} by _GDBN__ and many _GDBN__ commands
2801refer implicitly to the selected frame. In particular, whenever you ask
29a2b744 2802_GDBN__ for the value of a variable in your program, the value is found in the
70b88761
RP
2803selected frame. There are special _GDBN__ commands to select whichever frame
2804you are interested in.
2805
29a2b744 2806When your program stops, _GDBN__ automatically selects the currently executing
70b88761 2807frame and describes it briefly as the @code{frame} command does
29a2b744 2808(@pxref{Frame Info, ,Information About a Frame}).
70b88761
RP
2809
2810@menu
b80282d5
RP
2811* Frames:: Stack Frames
2812* Backtrace:: Backtraces
2813* Selection:: Selecting a Frame
2814* Frame Info:: Information on a Frame
70b88761
RP
2815@end menu
2816
4eb4cf57 2817@node Frames
70b88761
RP
2818@section Stack Frames
2819
2820@cindex frame
2821@cindex stack frame
2822The call stack is divided up into contiguous pieces called @dfn{stack
2823frames}, or @dfn{frames} for short; each frame is the data associated
2824with one call to one function. The frame contains the arguments given
2825to the function, the function's local variables, and the address at
2826which the function is executing.
2827
2828@cindex initial frame
2829@cindex outermost frame
2830@cindex innermost frame
2831When your program is started, the stack has only one frame, that of the
2832function @code{main}. This is called the @dfn{initial} frame or the
2833@dfn{outermost} frame. Each time a function is called, a new frame is
2834made. Each time a function returns, the frame for that function invocation
2835is eliminated. If a function is recursive, there can be many frames for
2836the same function. The frame for the function in which execution is
2837actually occurring is called the @dfn{innermost} frame. This is the most
2838recently created of all the stack frames that still exist.
2839
2840@cindex frame pointer
2841Inside your program, stack frames are identified by their addresses. A
2842stack frame consists of many bytes, each of which has its own address; each
2843kind of computer has a convention for choosing one of those bytes whose
2844address serves as the address of the frame. Usually this address is kept
2845in a register called the @dfn{frame pointer register} while execution is
2846going on in that frame.
2847
2848@cindex frame number
2849_GDBN__ assigns numbers to all existing stack frames, starting with
2850zero for the innermost frame, one for the frame that called it,
2851and so on upward. These numbers do not really exist in your program;
2852they are assigned by _GDBN__ to give you a way of designating stack
2853frames in _GDBN__ commands.
2854
2855@cindex frameless execution
2856Some compilers allow functions to be compiled so that they operate
2857without stack frames. (For example, the @code{_GCC__} option
2858@samp{-fomit-frame-pointer} will generate functions without a frame.)
2859This is occasionally done with heavily used library functions to save
2860the frame setup time. _GDBN__ has limited facilities for dealing with
2861these function invocations. If the innermost function invocation has no
2862stack frame, _GDBN__ will nevertheless regard it as though it had a
2863separate frame, which is numbered zero as usual, allowing correct
2864tracing of the function call chain. However, _GDBN__ has no provision
2865for frameless functions elsewhere in the stack.
2866
4eb4cf57 2867@node Backtrace
70b88761
RP
2868@section Backtraces
2869
29a2b744 2870A backtrace is a summary of how your program got where it is. It shows one
70b88761
RP
2871line per frame, for many frames, starting with the currently executing
2872frame (frame zero), followed by its caller (frame one), and on up the
2873stack.
2874
2875@table @code
2876@item backtrace
2877@itemx bt
2878@kindex backtrace
2879@kindex bt
2880Print a backtrace of the entire stack: one line per frame for all
2881frames in the stack.
2882
2883You can stop the backtrace at any time by typing the system interrupt
2884character, normally @kbd{C-c}.
2885
2886@item backtrace @var{n}
2887@itemx bt @var{n}
2888Similar, but print only the innermost @var{n} frames.
2889
2890@item backtrace -@var{n}
2891@itemx bt -@var{n}
2892Similar, but print only the outermost @var{n} frames.
2893@end table
2894
2895@kindex where
2896@kindex info stack
2897@kindex info s
2898The names @code{where} and @code{info stack} (abbreviated @code{info s})
2899are additional aliases for @code{backtrace}.
2900
2901Each line in the backtrace shows the frame number and the function name.
2902The program counter value is also shown---unless you use @code{set
2903print address off}. The backtrace also shows the source file name and
2904line number, as well as the arguments to the function. The program
2905counter value is omitted if it is at the beginning of the code for that
2906line number.
2907
2908Here is an example of a backtrace. It was made with the command
2909@samp{bt 3}, so it shows the innermost three frames.
2910
2911@smallexample
2912@group
203eea5d
RP
2913#0 m4_traceon (obs=0x24eb0, argc=1, argv=0x2b8c8)
2914 at builtin.c:993
70b88761
RP
2915#1 0x6e38 in expand_macro (sym=0x2b600) at macro.c:242
2916#2 0x6840 in expand_token (obs=0x0, t=177664, td=0xf7fffb08)
2917 at macro.c:71
2918(More stack frames follow...)
2919@end group
2920@end smallexample
2921
2922@noindent
29a2b744
RP
2923The display for frame zero does not begin with a program counter
2924value, indicating that your program has stopped at the beginning of the
70b88761
RP
2925code for line @code{993} of @code{builtin.c}.
2926
4eb4cf57 2927@node Selection
70b88761
RP
2928@section Selecting a Frame
2929
29a2b744 2930Most commands for examining the stack and other data in your program work on
70b88761
RP
2931whichever stack frame is selected at the moment. Here are the commands for
2932selecting a stack frame; all of them finish by printing a brief description
2933of the stack frame just selected.
2934
2935@table @code
2936@item frame @var{n}
2937@itemx f @var{n}
2938@kindex frame
2939@kindex f
2940Select frame number @var{n}. Recall that frame zero is the innermost
2941(currently executing) frame, frame one is the frame that called the
2942innermost one, and so on. The highest-numbered frame is @code{main}'s
2943frame.
2944
2945@item frame @var{addr}
2946@itemx f @var{addr}
2947Select the frame at address @var{addr}. This is useful mainly if the
2948chaining of stack frames has been damaged by a bug, making it
2949impossible for _GDBN__ to assign numbers properly to all frames. In
29a2b744 2950addition, this can be useful when your program has multiple stacks and
70b88761
RP
2951switches between them.
2952
c728f1f0 2953_if__(_SPARC__)
70b88761 2954On the SPARC architecture, @code{frame} needs two addresses to
e251e767 2955select an arbitrary frame: a frame pointer and a stack pointer.
70b88761
RP
2956@c note to future updaters: this is conditioned on a flag
2957@c FRAME_SPECIFICATION_DYADIC in the tm-*.h files, currently only used
2958@c by SPARC, hence the specific attribution. Generalize or list all
2959@c possibilities if more supported machines start doing this.
c728f1f0 2960_fi__(_SPARC__)
70b88761
RP
2961
2962@item up @var{n}
2963@kindex up
2964Move @var{n} frames up the stack. For positive numbers @var{n}, this
2965advances toward the outermost frame, to higher frame numbers, to frames
2966that have existed longer. @var{n} defaults to one.
2967
2968@item down @var{n}
2969@kindex down
2970@kindex do
2971Move @var{n} frames down the stack. For positive numbers @var{n}, this
2972advances toward the innermost frame, to lower frame numbers, to frames
2973that were created more recently. @var{n} defaults to one. You may
2974abbreviate @code{down} as @code{do}.
2975@end table
2976
2977All of these commands end by printing two lines of output describing the
2978frame. The first line shows the frame number, the function name, the
2979arguments, and the source file and line number of execution in that
2980frame. The second line shows the text of that source line. For
2981example:
2982
2983@smallexample
29a2b744 2984@group
70b88761 2985(_GDBP__) up
203eea5d
RP
2986#1 0x22f0 in main (argc=1, argv=0xf7fffbf4, env=0xf7fffbfc)
2987 at env.c:10
70b88761 298810 read_input_file (argv[i]);
29a2b744 2989@end group
70b88761
RP
2990@end smallexample
2991
29a2b744
RP
2992After such a printout, the @code{list} command with no arguments will
2993print ten lines centered on the point of execution in the frame.
2994@xref{List, ,Printing Source Lines}.
70b88761
RP
2995
2996@table @code
2997@item up-silently @var{n}
2998@itemx down-silently @var{n}
2999@kindex down-silently
3000@kindex up-silently
3001These two commands are variants of @code{up} and @code{down},
3002respectively; they differ in that they do their work silently, without
3003causing display of the new frame. They are intended primarily for use
3004in _GDBN__ command scripts, where the output might be unnecessary and
e251e767 3005distracting.
70b88761
RP
3006@end table
3007
4eb4cf57 3008@node Frame Info
70b88761
RP
3009@section Information About a Frame
3010
3011There are several other commands to print information about the selected
3012stack frame.
3013
3014@table @code
3015@item frame
3016@itemx f
29a2b744
RP
3017When used without any argument, this command does not change which
3018frame is selected, but prints a brief description of the currently
70b88761 3019selected stack frame. It can be abbreviated @code{f}. With an
29a2b744
RP
3020argument, this command is used to select a stack frame
3021(@pxref{Selection, ,Selecting a Frame}).
70b88761
RP
3022
3023@item info frame
70b88761 3024@itemx info f
29a2b744 3025@kindex info frame
70b88761
RP
3026@kindex info f
3027This command prints a verbose description of the selected stack frame,
3028including the address of the frame, the addresses of the next frame down
c2bbbb22
RP
3029(called by this frame) and the next frame up (caller of this frame), the
3030language that the source code corresponding to this frame was written in,
70b88761
RP
3031the address of the frame's arguments, the program counter saved in it
3032(the address of execution in the caller frame), and which registers
3033were saved in the frame. The verbose description is useful when
3034something has gone wrong that has made the stack format fail to fit
3035the usual conventions.
3036
3037@item info frame @var{addr}
3038@itemx info f @var{addr}
3039Print a verbose description of the frame at address @var{addr},
3040without selecting that frame. The selected frame remains unchanged by
3041this command.
3042
3043@item info args
3044@kindex info args
3045Print the arguments of the selected frame, each on a separate line.
3046
3047@item info locals
3048@kindex info locals
3049Print the local variables of the selected frame, each on a separate
3050line. These are all variables declared static or automatic within all
3051program blocks that execution in this frame is currently inside of.
3052
3053@item info catch
3054@kindex info catch
3055@cindex catch exceptions
3056@cindex exception handlers
3057Print a list of all the exception handlers that are active in the
3058current stack frame at the current point of execution. To see other
3059exception handlers, visit the associated frame (using the @code{up},
3060@code{down}, or @code{frame} commands); then type @code{info catch}.
1041a570 3061@xref{Exception Handling, ,Breakpoints and Exceptions}.
70b88761
RP
3062@end table
3063
4eb4cf57 3064@node Source
70b88761
RP
3065@chapter Examining Source Files
3066
3067_GDBN__ can print parts of your program's source, since the debugging
1041a570
RP
3068information recorded in your program tells _GDBN__ what source files were
3069used to build it. When your program stops, _GDBN__ spontaneously prints
3070the line where it stopped. Likewise, when you select a stack frame
3071(@pxref{Selection, ,Selecting a Frame}), _GDBN__ prints the line where
3072execution in that frame has stopped. You can print other portions of
3073source files by explicit command.
70b88761 3074
4eb4cf57 3075_if__(!_DOSHOST__)
1041a570
RP
3076If you use _GDBN__ through its GNU Emacs interface, you may prefer to use
3077Emacs facilities to view source; @pxref{Emacs, ,Using _GDBN__ under GNU
3078Emacs}.
4eb4cf57 3079_fi__(!_DOSHOST__)
70b88761
RP
3080
3081@menu
b80282d5 3082* List:: Printing Source Lines
6f28dd0b 3083_if__(_GENERIC__ || !_H8__)
b80282d5 3084* Search:: Searching Source Files
6f28dd0b 3085_fi__(_GENERIC__ || !_H8__)
b80282d5
RP
3086* Source Path:: Specifying Source Directories
3087* Machine Code:: Source and Machine Code
70b88761
RP
3088@end menu
3089
4eb4cf57 3090@node List
70b88761
RP
3091@section Printing Source Lines
3092
3093@kindex list
3094@kindex l
3095To print lines from a source file, use the @code{list} command
3096(abbreviated @code{l}). There are several ways to specify what part
3097of the file you want to print.
3098
3099Here are the forms of the @code{list} command most commonly used:
3100
3101@table @code
3102@item list @var{linenum}
c338a2fd 3103Print lines centered around line number @var{linenum} in the
70b88761
RP
3104current source file.
3105
3106@item list @var{function}
c338a2fd 3107Print lines centered around the beginning of function
70b88761
RP
3108@var{function}.
3109
3110@item list
c338a2fd
RP
3111Print more lines. If the last lines printed were printed with a
3112@code{list} command, this prints lines following the last lines
70b88761 3113printed; however, if the last line printed was a solitary line printed
29a2b744 3114as part of displaying a stack frame (@pxref{Stack, ,Examining the
1041a570 3115Stack}), this prints lines centered around that line.
70b88761
RP
3116
3117@item list -
c338a2fd
RP
3118Print lines just before the lines last printed.
3119@end table
3120
3121By default, _GDBN__ prints ten source lines with any of these forms of
3122the @code{list} command. You can change this using @code{set listsize}:
3123
3124@table @code
3125@item set listsize @var{count}
3126@kindex set listsize
3127Make the @code{list} command display @var{count} source lines (unless
3128the @code{list} argument explicitly specifies some other number).
3129
3130@item show listsize
3131@kindex show listsize
3132Display the number of lines that @code{list} will currently display by
e251e767 3133default.
70b88761
RP
3134@end table
3135
3136Repeating a @code{list} command with @key{RET} discards the argument,
3137so it is equivalent to typing just @code{list}. This is more useful
3138than listing the same lines again. An exception is made for an
3139argument of @samp{-}; that argument is preserved in repetition so that
3140each repetition moves up in the source file.
3141
3142@cindex linespec
3143In general, the @code{list} command expects you to supply zero, one or two
3144@dfn{linespecs}. Linespecs specify source lines; there are several ways
3145of writing them but the effect is always to specify some source line.
3146Here is a complete description of the possible arguments for @code{list}:
3147
3148@table @code
3149@item list @var{linespec}
c338a2fd 3150Print lines centered around the line specified by @var{linespec}.
70b88761
RP
3151
3152@item list @var{first},@var{last}
3153Print lines from @var{first} to @var{last}. Both arguments are
3154linespecs.
3155
3156@item list ,@var{last}
c338a2fd 3157Print lines ending with @var{last}.
70b88761
RP
3158
3159@item list @var{first},
c338a2fd 3160Print lines starting with @var{first}.
70b88761
RP
3161
3162@item list +
c338a2fd 3163Print lines just after the lines last printed.
70b88761
RP
3164
3165@item list -
c338a2fd 3166Print lines just before the lines last printed.
70b88761
RP
3167
3168@item list
3169As described in the preceding table.
3170@end table
3171
3172Here are the ways of specifying a single source line---all the
3173kinds of linespec.
3174
3175@table @code
3176@item @var{number}
3177Specifies line @var{number} of the current source file.
3178When a @code{list} command has two linespecs, this refers to
3179the same source file as the first linespec.
3180
3181@item +@var{offset}
3182Specifies the line @var{offset} lines after the last line printed.
3183When used as the second linespec in a @code{list} command that has
3184two, this specifies the line @var{offset} lines down from the
3185first linespec.
3186
3187@item -@var{offset}
3188Specifies the line @var{offset} lines before the last line printed.
3189
3190@item @var{filename}:@var{number}
3191Specifies line @var{number} in the source file @var{filename}.
3192
3193@item @var{function}
3194@c FIXME: "of the open-brace" is C-centric. When we add other langs...
3195Specifies the line of the open-brace that begins the body of the
3196function @var{function}.
3197
3198@item @var{filename}:@var{function}
3199Specifies the line of the open-brace that begins the body of the
3200function @var{function} in the file @var{filename}. You only need the
3201file name with a function name to avoid ambiguity when there are
3202identically named functions in different source files.
3203
3204@item *@var{address}
3205Specifies the line containing the program address @var{address}.
3206@var{address} may be any expression.
3207@end table
3208
6f28dd0b 3209_if__(_GENERIC__ || !_H8__)
4eb4cf57 3210@node Search
70b88761
RP
3211@section Searching Source Files
3212@cindex searching
3213@kindex reverse-search
3214
3215There are two commands for searching through the current source file for a
3216regular expression.
3217
3218@table @code
3219@item forward-search @var{regexp}
3220@itemx search @var{regexp}
3221@kindex search
3222@kindex forward-search
1041a570
RP
3223The command @samp{forward-search @var{regexp}} checks each line,
3224starting with the one following the last line listed, for a match for
3225@var{regexp}. It lists the line that is found. You can use
3226synonym @samp{search @var{regexp}} or abbreviate the command name as
3227@code{fo}.
70b88761
RP
3228
3229@item reverse-search @var{regexp}
3230The command @samp{reverse-search @var{regexp}} checks each line, starting
3231with the one before the last line listed and going backward, for a match
3232for @var{regexp}. It lists the line that is found. You can abbreviate
3233this command as @code{rev}.
3234@end table
6f28dd0b 3235_fi__(_GENERIC__ || !_H8__)
70b88761 3236
4eb4cf57 3237@node Source Path
70b88761
RP
3238@section Specifying Source Directories
3239
3240@cindex source path
3241@cindex directories for source files
3242Executable programs sometimes do not record the directories of the source
3243files from which they were compiled, just the names. Even when they do,
3244the directories could be moved between the compilation and your debugging
3245session. _GDBN__ has a list of directories to search for source files;
3246this is called the @dfn{source path}. Each time _GDBN__ wants a source file,
3247it tries all the directories in the list, in the order they are present
3248in the list, until it finds a file with the desired name. Note that
3249the executable search path is @emph{not} used for this purpose. Neither is
3250the current working directory, unless it happens to be in the source
3251path.
3252
29a2b744 3253If _GDBN__ cannot find a source file in the source path, and the object
70b88761
RP
3254program records a directory, _GDBN__ tries that directory too. If the
3255source path is empty, and there is no record of the compilation
3256directory, _GDBN__ will, as a last resort, look in the current
3257directory.
3258
3259Whenever you reset or rearrange the source path, _GDBN__ will clear out
3260any information it has cached about where source files are found, where
3261each line is in the file, etc.
3262
3263@kindex directory
3264When you start _GDBN__, its source path is empty.
3265To add other directories, use the @code{directory} command.
3266
3267@table @code
3268@item directory @var{dirname} @dots{}
3269Add directory @var{dirname} to the front of the source path. Several
3270directory names may be given to this command, separated by @samp{:} or
3271whitespace. You may specify a directory that is already in the source
e251e767 3272path; this moves it forward, so it will be searched sooner.
7463aadd
RP
3273
3274You can use the string @samp{$cdir} to refer to the compilation
3275directory (if one is recorded), and @samp{$cwd} to refer to the current
3276working directory. @samp{$cwd} is not the same as @samp{.}---the former
3277tracks the current working directory as it changes during your _GDBN__
3278session, while the latter is immediately expanded to the current
3279directory at the time you add an entry to the source path.
70b88761
RP
3280
3281@item directory
3282Reset the source path to empty again. This requires confirmation.
3283
3284@c RET-repeat for @code{directory} is explicitly disabled, but since
29a2b744 3285@c repeating it would be a no-op we do not say that. (thanks to RMS)
70b88761
RP
3286
3287@item show directories
3288@kindex show directories
3289Print the source path: show which directories it contains.
3290@end table
3291
3292If your source path is cluttered with directories that are no longer of
3293interest, _GDBN__ may sometimes cause confusion by finding the wrong
3294versions of source. You can correct the situation as follows:
3295
3296@enumerate
3297@item
3298Use @code{directory} with no argument to reset the source path to empty.
3299
3300@item
3301Use @code{directory} with suitable arguments to reinstall the
3302directories you want in the source path. You can add all the
3303directories in one command.
3304@end enumerate
3305
4eb4cf57 3306@node Machine Code
70b88761 3307@section Source and Machine Code
1041a570 3308
70b88761
RP
3309You can use the command @code{info line} to map source lines to program
3310addresses (and viceversa), and the command @code{disassemble} to display
3311a range of addresses as machine instructions.
3312
3313@table @code
3314@item info line @var{linespec}
3315@kindex info line
3316Print the starting and ending addresses of the compiled code for
1041a570
RP
3317source line @var{linespec}. You can specify source lines in any of
3318the ways understood by the @code{list} command (@pxref{List, ,Printing
3319Source Lines}).
70b88761
RP
3320@end table
3321
1041a570
RP
3322For example, we can use @code{info line} to discover the location of
3323the object code for the first line of function
3324@code{m4_changequote}:
3325
70b88761
RP
3326@smallexample
3327(_GDBP__) info line m4_changecom
3328Line 895 of "builtin.c" starts at pc 0x634c and ends at 0x6350.
3329@end smallexample
3330
3331@noindent
3332We can also inquire (using @code{*@var{addr}} as the form for
3333@var{linespec}) what source line covers a particular address:
3334@smallexample
3335(_GDBP__) info line *0x63ff
3336Line 926 of "builtin.c" starts at pc 0x63e4 and ends at 0x6404.
3337@end smallexample
3338
c338a2fd 3339@cindex @code{$_} and @code{info line}
29a2b744
RP
3340After @code{info line}, the default address for the @code{x} command
3341is changed to the starting address of the line, so that @samp{x/i} is
3342sufficient to begin examining the machine code (@pxref{Memory,
3343,Examining Memory}). Also, this address is saved as the value of the
3344convenience variable @code{$_} (@pxref{Convenience Vars, ,Convenience
3345Variables}).
70b88761
RP
3346
3347@table @code
3348@kindex disassemble
3349@item disassemble
e94b4a2b
RP
3350This specialized command dumps a range of memory as machine
3351instructions. The default memory range is the function surrounding the
3352program counter of the selected frame. A single argument to this
3353command is a program counter value; the function surrounding this value
3354will be dumped. Two arguments specify a range of addresses (first
3355inclusive, second exclusive) to dump.
70b88761
RP
3356@end table
3357
4eb4cf57 3358_if__(_GENERIC__||!_H8__)
70b88761 3359We can use @code{disassemble} to inspect the object code
4eb4cf57
RP
3360range shown in the last @code{info line} example (the example
3361shows SPARC machine instructions):
70b88761 3362
4eb4cf57 3363_0__
70b88761
RP
3364@smallexample
3365(_GDBP__) disas 0x63e4 0x6404
3366Dump of assembler code from 0x63e4 to 0x6404:
b80282d5
RP
33670x63e4 <builtin_init+5340>: ble 0x63f8 <builtin_init+5360>
33680x63e8 <builtin_init+5344>: sethi %hi(0x4c00), %o0
33690x63ec <builtin_init+5348>: ld [%i1+4], %o0
33700x63f0 <builtin_init+5352>: b 0x63fc <builtin_init+5364>
33710x63f4 <builtin_init+5356>: ld [%o0+4], %o0
33720x63f8 <builtin_init+5360>: or %o0, 0x1a4, %o0
33730x63fc <builtin_init+5364>: call 0x9288 <path_search>
e251e767 33740x6400 <builtin_init+5368>: nop
70b88761 3375End of assembler dump.
70b88761 3376@end smallexample
4eb4cf57
RP
3377_1__
3378_fi__(_GENERIC__||!_H8__)
3379
3380_if__(!_GENERIC__||_H8__)
3381For example, here is the beginning of the output for the
3382disassembly of a function @code{fact}:
70b88761 3383
4eb4cf57
RP
3384_0__
3385@smallexample
3386(_GDBP__) disas fact
3387Dump of assembler code for function fact:
3388to 0x808c:
33890x802c <fact>: 6d f2 mov.w r2,@@-r7
33900x802e <fact+2>: 6d f3 mov.w r3,@@-r7
33910x8030 <fact+4>: 6d f6 mov.w r6,@@-r7
33920x8032 <fact+6>: 0d 76 mov.w r7,r6
33930x8034 <fact+8>: 6f 70 00 08 mov.w @@(0x8,r7),r0
33940x8038 <fact+12> 19 11 sub.w r1,r1
3395 .
3396 .
3397 .
3398@end smallexample
3399_1__
3400_fi__(!_GENERIC__||_H8__)
3401
3402
3403@node Data
70b88761
RP
3404@chapter Examining Data
3405
3406@cindex printing data
3407@cindex examining data
3408@kindex print
3409@kindex inspect
1041a570 3410@c "inspect" is not quite a synonym if you are using Epoch, which we do not
29a2b744 3411@c document because it is nonstandard... Under Epoch it displays in a
70b88761
RP
3412@c different window or something like that.
3413The usual way to examine data in your program is with the @code{print}
4eb4cf57
RP
3414command (abbreviated @code{p}), or its synonym @code{inspect}.
3415_if__(!_CONLY__)
3416It evaluates and prints the value of an expression of the language your
1041a570 3417program is written in (@pxref{Languages, ,Using _GDBN__ with Different
4eb4cf57
RP
3418Languages}).
3419_fi__(!_CONLY__)
70b88761 3420
e0dacfd1
RP
3421@table @code
3422@item print @var{exp}
3423@itemx print /@var{f} @var{exp}
3424@var{exp} is an expression (in the source language). By default
70b88761 3425the value of @var{exp} is printed in a format appropriate to its data
e0dacfd1
RP
3426type; you can choose a different format by specifying @samp{/@var{f}},
3427where @var{f} is a letter specifying the format; @pxref{Output formats}.
3428
3429@item print
3430@itemx print /@var{f}
3431If you omit @var{exp}, _GDBN__ displays the last value again (from the
1041a570 3432@dfn{value history}; @pxref{Value History, ,Value History}). This allows you to
e0dacfd1
RP
3433conveniently inspect the same value in an alternative format.
3434@end table
70b88761
RP
3435
3436A more low-level way of examining data is with the @code{x} command.
3437It examines data in memory at a specified address and prints it in a
29a2b744 3438specified format. @xref{Memory, ,Examining Memory}.
70b88761 3439
29a2b744 3440If you are interested in information about types, or about how the fields
b80282d5 3441of a struct or class are declared, use the @code{ptype @var{exp}}
1041a570 3442command rather than @code{print}. @xref{Symbols, ,Examining the Symbol Table}.
b80282d5 3443
70b88761 3444@menu
b80282d5
RP
3445* Expressions:: Expressions
3446* Variables:: Program Variables
3447* Arrays:: Artificial Arrays
3448* Output formats:: Output formats
3449* Memory:: Examining Memory
3450* Auto Display:: Automatic Display
3451* Print Settings:: Print Settings
3452* Value History:: Value History
3453* Convenience Vars:: Convenience Variables
3454* Registers:: Registers
4eb4cf57 3455_if__(_GENERIC__ || !_H8__)
b80282d5 3456* Floating Point Hardware:: Floating Point Hardware
4eb4cf57 3457_fi__(_GENERIC__ || !_H8__)
70b88761
RP
3458@end menu
3459
4eb4cf57 3460@node Expressions
70b88761
RP
3461@section Expressions
3462
3463@cindex expressions
3464@code{print} and many other _GDBN__ commands accept an expression and
3465compute its value. Any kind of constant, variable or operator defined
3466by the programming language you are using is legal in an expression in
3467_GDBN__. This includes conditional expressions, function calls, casts
3468and string constants. It unfortunately does not include symbols defined
b80282d5 3469by preprocessor @code{#define} commands.
70b88761 3470
4eb4cf57 3471_if__(!_CONLY__)
c2bbbb22 3472Because C is so widespread, most of the expressions shown in examples in
1041a570 3473this manual are in C. @xref{Languages, , Using _GDBN__ with Different
c2bbbb22 3474Languages}, for information on how to use expressions in other
e251e767 3475languages.
c2bbbb22
RP
3476
3477In this section, we discuss operators that you can use in _GDBN__
e251e767 3478expressions regardless of your programming language.
c2bbbb22 3479
70b88761
RP
3480Casts are supported in all languages, not just in C, because it is so
3481useful to cast a number into a pointer so as to examine a structure
3482at that address in memory.
c2bbbb22 3483@c FIXME: casts supported---Mod2 true?
4eb4cf57 3484_fi__(!_CONLY__)
70b88761 3485
c2bbbb22 3486_GDBN__ supports these operators in addition to those of programming
70b88761
RP
3487languages:
3488
3489@table @code
3490@item @@
3491@samp{@@} is a binary operator for treating parts of memory as arrays.
1041a570 3492@xref{Arrays, ,Artificial Arrays}, for more information.
70b88761
RP
3493
3494@item ::
3495@samp{::} allows you to specify a variable in terms of the file or
1041a570 3496function where it is defined. @xref{Variables, ,Program Variables}.
70b88761
RP
3497
3498@item @{@var{type}@} @var{addr}
3499Refers to an object of type @var{type} stored at address @var{addr} in
3500memory. @var{addr} may be any expression whose value is an integer or
3501pointer (but parentheses are required around binary operators, just as in
3502a cast). This construct is allowed regardless of what kind of data is
1041a570 3503normally supposed to reside at @var{addr}.
70b88761
RP
3504@end table
3505
4eb4cf57 3506@node Variables
70b88761
RP
3507@section Program Variables
3508
3509The most common kind of expression to use is the name of a variable
3510in your program.
3511
3512Variables in expressions are understood in the selected stack frame
29a2b744
RP
3513(@pxref{Selection, ,Selecting a Frame}); they must either be global
3514(or static) or be visible according to the scope rules of the
3515programming language from the point of execution in that frame. This
3516means that in the function
70b88761
RP
3517
3518@example
3519foo (a)
3520 int a;
3521@{
3522 bar (a);
3523 @{
3524 int b = test ();
3525 bar (b);
3526 @}
3527@}
3528@end example
3529
3530@noindent
29a2b744 3531the variable @code{a} is usable whenever your program is executing
70b88761 3532within the function @code{foo}, but the variable @code{b} is visible
29a2b744 3533only while your program is executing inside the block in which @code{b}
70b88761
RP
3534is declared.
3535
3536@cindex variable name conflict
3537There is an exception: you can refer to a variable or function whose
3538scope is a single source file even if the current execution point is not
3539in this file. But it is possible to have more than one such variable or
6ca72cc6
RP
3540function with the same name (in different source files). If that
3541happens, referring to that name has unpredictable effects. If you wish,
3542you can specify a static variable in a particular function or file,
3543using the colon-colon notation:
70b88761
RP
3544
3545@cindex colon-colon
a6d0b6d3 3546@iftex
29a2b744 3547@c info cannot cope with a :: index entry, but why deprive hard copy readers?
70b88761 3548@kindex ::
a6d0b6d3 3549@end iftex
70b88761
RP
3550@example
3551@var{file}::@var{variable}
6ca72cc6 3552@var{function}::@var{variable}
70b88761
RP
3553@end example
3554
3555@noindent
6ca72cc6 3556Here @var{file} or @var{function} is the name of the context for the
6c380b13
RP
3557static @var{variable}. In the case of file names, you can use quotes to
3558make sure _GDBN__ parses the file name as a single word---for example,
3559to print a global value of @code{x} defined in @file{f2.c}:
3560
3561@example
3562(_GDBP__) p 'f2.c'::x
3563@end example
70b88761 3564
0f153e74 3565_if__(!_CONLY__)
c2bbbb22 3566@cindex C++ scope resolution
70b88761
RP
3567This use of @samp{::} is very rarely in conflict with the very similar
3568use of the same notation in C++. _GDBN__ also supports use of the C++
c2bbbb22 3569scope resolution operator in _GDBN__ expressions.
0f153e74 3570_fi__(!_CONLY__)
70b88761 3571
3d3ab540
RP
3572@cindex wrong values
3573@cindex variable values, wrong
3574@quotation
3575@emph{Warning:} Occasionally, a local variable may appear to have the
3576wrong value at certain points in a function---just after entry to the
29a2b744 3577function, and just before exit. You may see this problem when you are
3d3ab540
RP
3578stepping by machine instructions. This is because on most machines, it
3579takes more than one instruction to set up a stack frame (including local
29a2b744 3580variable definitions); if you are stepping by machine instructions,
3d3ab540
RP
3581variables may appear to have the wrong values until the stack frame is
3582completely built. On function exit, it usually also takes more than one
3583machine instruction to destroy a stack frame; after you begin stepping
3584through that group of instructions, local variable definitions may be
3585gone.
3586@end quotation
3587
4eb4cf57 3588@node Arrays
70b88761
RP
3589@section Artificial Arrays
3590
3591@cindex artificial array
3592@kindex @@
3593It is often useful to print out several successive objects of the
3594same type in memory; a section of an array, or an array of
3595dynamically determined size for which only a pointer exists in the
3596program.
3597
3598This can be done by constructing an @dfn{artificial array} with the
3599binary operator @samp{@@}. The left operand of @samp{@@} should be
3600the first element of the desired array, as an individual object.
3601The right operand should be the desired length of the array. The result is
3602an array value whose elements are all of the type of the left argument.
3603The first element is actually the left argument; the second element
3604comes from bytes of memory immediately following those that hold the
3605first element, and so on. Here is an example. If a program says
3606
3607@example
3608int *array = (int *) malloc (len * sizeof (int));
3609@end example
3610
3611@noindent
3612you can print the contents of @code{array} with
3613
3614@example
3615p *array@@len
3616@end example
3617
3618The left operand of @samp{@@} must reside in memory. Array values made
3619with @samp{@@} in this way behave just like other arrays in terms of
3620subscripting, and are coerced to pointers when used in expressions.
3621Artificial arrays most often appear in expressions via the value history
1041a570 3622(@pxref{Value History, ,Value History}), after printing one out.)
70b88761 3623
1041a570 3624Sometimes the artificial array mechanism is not quite enough; in
3d3ab540 3625moderately complex data structures, the elements of interest may not
1041a570
RP
3626actually be adjacent---for example, if you are interested in the values
3627of pointers in an array. One useful work-around in this situation is
3628to use a convenience variable (@pxref{Convenience Vars, ,Convenience
3629Variables}) as a counter in an expression that prints the first
3630interesting value, and then repeat that expression via @key{RET}. For
3631instance, suppose you have an array @code{dtab} of pointers to
3632structures, and you are interested in the values of a field @code{fv}
3633in each structure. Here is an example of what you might type:
3634
3d3ab540
RP
3635@example
3636set $i = 0
3637p dtab[$i++]->fv
3638@key{RET}
3639@key{RET}
3640@dots{}
3641@end example
3642
4eb4cf57 3643@node Output formats
70b88761
RP
3644@section Output formats
3645
3646@cindex formatted output
3647@cindex output formats
3648By default, _GDBN__ prints a value according to its data type. Sometimes
3649this is not what you want. For example, you might want to print a number
3650in hex, or a pointer in decimal. Or you might want to view data in memory
3651at a certain address as a character string or as an instruction. To do
3652these things, specify an @dfn{output format} when you print a value.
3653
3654The simplest use of output formats is to say how to print a value
3655already computed. This is done by starting the arguments of the
3656@code{print} command with a slash and a format letter. The format
3657letters supported are:
3658
3659@table @code
3660@item x
3661Regard the bits of the value as an integer, and print the integer in
3662hexadecimal.
3663
3664@item d
3665Print as integer in signed decimal.
3666
3667@item u
3668Print as integer in unsigned decimal.
3669
3670@item o
3671Print as integer in octal.
3672
3673@item t
3674Print as integer in binary. The letter @samp{t} stands for ``two''.
3675
3676@item a
3677Print as an address, both absolute in hex and as an offset from the
3678nearest preceding symbol. This format can be used to discover where (in
3679what function) an unknown address is located:
1041a570 3680
70b88761
RP
3681@example
3682(_GDBP__) p/a 0x54320
3683_0__$3 = 0x54320 <_initialize_vx+396>_1__
3684@end example
3685
70b88761
RP
3686@item c
3687Regard as an integer and print it as a character constant.
3688
3689@item f
3690Regard the bits of the value as a floating point number and print
3691using typical floating point syntax.
3692@end table
3693
3694For example, to print the program counter in hex (@pxref{Registers}), type
3695
3696@example
3697p/x $pc
3698@end example
3699
3700@noindent
3701Note that no space is required before the slash; this is because command
3702names in _GDBN__ cannot contain a slash.
3703
3704To reprint the last value in the value history with a different format,
3705you can use the @code{print} command with just a format and no
3706expression. For example, @samp{p/x} reprints the last value in hex.
3707
4eb4cf57 3708@node Memory
70b88761
RP
3709@section Examining Memory
3710
1041a570
RP
3711You can use the command @code{x} (for ``examine'') to examine memory in
3712any of several formats, independently of your program's data types.
3713
70b88761
RP
3714@cindex examining memory
3715@table @code
3716@kindex x
cedaf8bc
RP
3717@item x/@var{nfu} @var{addr}
3718@itemx x @var{addr}
3719@itemx x
1041a570
RP
3720Use the command @code{x} to examine memory.
3721@end table
3722
3723@var{n}, @var{f}, and @var{u} are all optional parameters that specify how
3724much memory to display and how to format it; @var{addr} is an
cedaf8bc
RP
3725expression giving the address where you want to start displaying memory.
3726If you use defaults for @var{nfu}, you need not type the slash @samp{/}.
3727Several commands set convenient defaults for @var{addr}.
70b88761 3728
1041a570
RP
3729@table @r
3730@item @var{n}, the repeat count
3731The repeat count is a decimal integer; the default is 1. It specifies
3732how much memory (counting by units @var{u}) to display.
cedaf8bc
RP
3733@c This really is **decimal**; unaffected by 'set radix' as of GDB
3734@c 4.1.2.
70b88761 3735
1041a570
RP
3736@item @var{f}, the display format
3737The display format is one of the formats used by @code{print},
cedaf8bc
RP
3738or @samp{s} (null-terminated string) or @samp{i} (machine instruction).
3739The default is @samp{x} (hexadecimal) initially, or the format from the
3740last time you used either @code{x} or @code{print}.
70b88761 3741
1041a570
RP
3742@item @var{u}, the unit size
3743The unit size is any of
70b88761
RP
3744@table @code
3745@item b
cedaf8bc 3746Bytes.
70b88761 3747@item h
cedaf8bc 3748Halfwords (two bytes).
70b88761 3749@item w
cedaf8bc 3750Words (four bytes). This is the initial default.
70b88761 3751@item g
cedaf8bc 3752Giant words (eight bytes).
70b88761
RP
3753@end table
3754
cedaf8bc
RP
3755Each time you specify a unit size with @code{x}, that size becomes the
3756default unit the next time you use @code{x}. (For the @samp{s} and
3757@samp{i} formats, the unit size is ignored and is normally not written.)
3758
1041a570 3759@item @var{addr}, starting display address
cedaf8bc
RP
3760@var{addr} is the address where you want _GDBN__ to begin displaying
3761memory. The expression need not have a pointer value (though it may);
3762it is always interpreted as an integer address of a byte of memory.
1041a570 3763@xref{Expressions, ,Expressions}, for more information on expressions. The default for
cedaf8bc
RP
3764@var{addr} is usually just after the last address examined---but several
3765other commands also set the default address: @code{info breakpoints} (to
3766the address of the last breakpoint listed), @code{info line} (to the
3767starting address of a line), and @code{print} (if you use it to display
3768a value from memory).
1041a570 3769@end table
70b88761 3770
cedaf8bc
RP
3771For example, @samp{x/3uh 0x54320} is a request to display three halfwords
3772(@code{h}) of memory, formatted as unsigned decimal integers (@samp{u}),
3773starting at address @code{0x54320}. @samp{x/4xw $sp} prints the four
3774words (@samp{w}) of memory above the stack pointer (here, @samp{$sp};
3775@pxref{Registers}) in hexadecimal (@samp{x}).
70b88761 3776
cedaf8bc 3777Since the letters indicating unit sizes are all distinct from the
29a2b744 3778letters specifying output formats, you do not have to remember whether
cedaf8bc
RP
3779unit size or format comes first; either order will work. The output
3780specifications @samp{4xw} and @samp{4wx} mean exactly the same thing.
3781(However, the count @var{n} must come first; @samp{wx4} will not work.)
3782
3783Even though the unit size @var{u} is ignored for the formats @samp{s}
3784and @samp{i}, you might still want to use a count @var{n}; for example,
3785@samp{3i} specifies that you want to see three machine instructions,
3786including any operands. The command @code{disassemble} gives an
3787alternative way of inspecting machine instructions; @pxref{Machine
3788Code}.
3789
3790All the defaults for the arguments to @code{x} are designed to make it
3791easy to continue scanning memory with minimal specifications each time
1041a570 3792you use @code{x}. For example, after you have inspected three machine
cedaf8bc
RP
3793instructions with @samp{x/3i @var{addr}}, you can inspect the next seven
3794with just @samp{x/7}. If you use @key{RET} to repeat the @code{x} command,
3795the repeat count @var{n} is used again; the other arguments default as
3796for successive uses of @code{x}.
70b88761 3797
c338a2fd 3798@cindex @code{$_}, @code{$__}, and value history
cedaf8bc 3799The addresses and contents printed by the @code{x} command are not saved
70b88761
RP
3800in the value history because there is often too much of them and they
3801would get in the way. Instead, _GDBN__ makes these values available for
3802subsequent use in expressions as values of the convenience variables
3803@code{$_} and @code{$__}. After an @code{x} command, the last address
3804examined is available for use in expressions in the convenience variable
3805@code{$_}. The contents of that address, as examined, are available in
3806the convenience variable @code{$__}.
3807
3808If the @code{x} command has a repeat count, the address and contents saved
3809are from the last memory unit printed; this is not the same as the last
3810address printed if several units were printed on the last line of output.
3811
4eb4cf57 3812@node Auto Display
70b88761
RP
3813@section Automatic Display
3814@cindex automatic display
3815@cindex display of expressions
3816
3817If you find that you want to print the value of an expression frequently
3818(to see how it changes), you might want to add it to the @dfn{automatic
29a2b744 3819display list} so that _GDBN__ will print its value each time your program stops.
70b88761
RP
3820Each expression added to the list is given a number to identify it;
3821to remove an expression from the list, you specify that number.
3822The automatic display looks like this:
3823
3824@example
38252: foo = 38
38263: bar[5] = (struct hack *) 0x3804
3827@end example
3828
3829@noindent
3830showing item numbers, expressions and their current values. As with
3831displays you request manually using @code{x} or @code{print}, you can
3832specify the output format you prefer; in fact, @code{display} decides
3833whether to use @code{print} or @code{x} depending on how elaborate your
3834format specification is---it uses @code{x} if you specify a unit size,
3835or one of the two formats (@samp{i} and @samp{s}) that are only
3836supported by @code{x}; otherwise it uses @code{print}.
3837
3838@table @code
3839@item display @var{exp}
3840@kindex display
3841Add the expression @var{exp} to the list of expressions to display
1041a570 3842each time your program stops. @xref{Expressions, ,Expressions}.
70b88761
RP
3843
3844@code{display} will not repeat if you press @key{RET} again after using it.
3845
3846@item display/@var{fmt} @var{exp}
3847For @var{fmt} specifying only a display format and not a size or
3848count, add the expression @var{exp} to the auto-display list but
3849arranges to display it each time in the specified format @var{fmt}.
3850@xref{Output formats}.
3851
3852@item display/@var{fmt} @var{addr}
3853For @var{fmt} @samp{i} or @samp{s}, or including a unit-size or a
3854number of units, add the expression @var{addr} as a memory address to
29a2b744
RP
3855be examined each time your program stops. Examining means in effect
3856doing @samp{x/@var{fmt} @var{addr}}. @xref{Memory, ,Examining Memory}.
70b88761
RP
3857@end table
3858
3859For example, @samp{display/i $pc} can be helpful, to see the machine
3860instruction about to be executed each time execution stops (@samp{$pc}
3861is a common name for the program counter; @pxref{Registers}).
3862
3863@table @code
3864@item undisplay @var{dnums}@dots{}
3865@itemx delete display @var{dnums}@dots{}
3866@kindex delete display
3867@kindex undisplay
3868Remove item numbers @var{dnums} from the list of expressions to display.
3869
3870@code{undisplay} will not repeat if you press @key{RET} after using it.
3871(Otherwise you would just get the error @samp{No display number @dots{}}.)
3872
3873@item disable display @var{dnums}@dots{}
3874@kindex disable display
3875Disable the display of item numbers @var{dnums}. A disabled display
3876item is not printed automatically, but is not forgotten. It may be
3877enabled again later.
3878
3879@item enable display @var{dnums}@dots{}
3880@kindex enable display
3881Enable display of item numbers @var{dnums}. It becomes effective once
3882again in auto display of its expression, until you specify otherwise.
3883
3884@item display
3885Display the current values of the expressions on the list, just as is
29a2b744 3886done when your program stops.
70b88761
RP
3887
3888@item info display
3889@kindex info display
3890Print the list of expressions previously set up to display
3891automatically, each one with its item number, but without showing the
3892values. This includes disabled expressions, which are marked as such.
3893It also includes expressions which would not be displayed right now
3894because they refer to automatic variables not currently available.
3895@end table
3896
3897If a display expression refers to local variables, then it does not make
3898sense outside the lexical context for which it was set up. Such an
3899expression is disabled when execution enters a context where one of its
3900variables is not defined. For example, if you give the command
3901@code{display last_char} while inside a function with an argument
29a2b744 3902@code{last_char}, then this argument will be displayed while your program
70b88761
RP
3903continues to stop inside that function. When it stops elsewhere---where
3904there is no variable @code{last_char}---display is disabled. The next time
3905your program stops where @code{last_char} is meaningful, you can enable the
3906display expression once again.
3907
4eb4cf57 3908@node Print Settings
70b88761
RP
3909@section Print Settings
3910
3911@cindex format options
3912@cindex print settings
3913_GDBN__ provides the following ways to control how arrays, structures,
e251e767 3914and symbols are printed.
70b88761
RP
3915
3916@noindent
3917These settings are useful for debugging programs in any language:
3918
3919@table @code
3920@item set print address
3921@item set print address on
3922@kindex set print address
3923_GDBN__ will print memory addresses showing the location of stack
3924traces, structure values, pointer values, breakpoints, and so forth,
3925even when it also displays the contents of those addresses. The default
3926is on. For example, this is what a stack frame display looks like, with
3927@code{set print address on}:
1041a570 3928
70b88761 3929@smallexample
1041a570 3930@group
70b88761 3931(_GDBP__) f
e251e767 3932#0 set_quotes (lq=0x34c78 "<<", rq=0x34c88 ">>")
70b88761 3933 at input.c:530
b80282d5 3934530 if (lquote != def_lquote)
1041a570 3935@end group
70b88761
RP
3936@end smallexample
3937
3938@item set print address off
3939Do not print addresses when displaying their contents. For example,
3940this is the same stack frame displayed with @code{set print address off}:
1041a570 3941
70b88761 3942@example
1041a570 3943@group
70b88761
RP
3944(_GDBP__) set print addr off
3945(_GDBP__) f
3946#0 set_quotes (lq="<<", rq=">>") at input.c:530
b80282d5 3947530 if (lquote != def_lquote)
1041a570 3948@end group
70b88761
RP
3949@end example
3950
3951@item show print address
3952@kindex show print address
3953Show whether or not addresses are to be printed.
3954
3955@item set print array
3956@itemx set print array on
3957@kindex set print array
3958_GDBN__ will pretty print arrays. This format is more convenient to read,
3959but uses more space. The default is off.
3960
3961@item set print array off.
3962Return to compressed format for arrays.
3963
3964@item show print array
3965@kindex show print array
3966Show whether compressed or pretty format is selected for displaying
e251e767 3967arrays.
70b88761
RP
3968
3969@item set print elements @var{number-of-elements}
3970@kindex set print elements
3971If _GDBN__ is printing a large array, it will stop printing after it has
3972printed the number of elements set by the @code{set print elements} command.
3973This limit also applies to the display of strings.
3974
3975@item show print elements
3976@kindex show print elements
3977Display the number of elements of a large array that _GDBN__ will print
3978before losing patience.
3979
3980@item set print pretty on
3981@kindex set print pretty
3982Cause _GDBN__ to print structures in an indented format with one member per
3983line, like this:
3984
3985@example
1041a570 3986@group
70b88761
RP
3987$1 = @{
3988 next = 0x0,
3989 flags = @{
3990 sweet = 1,
3991 sour = 1
3992 @},
3993 meat = 0x54 "Pork"
3994@}
1041a570 3995@end group
70b88761
RP
3996@end example
3997
3998@item set print pretty off
3999Cause _GDBN__ to print structures in a compact format, like this:
4000
4001@smallexample
1041a570 4002@group
38962738
RP
4003$1 = @{next = 0x0, flags = @{sweet = 1, sour = 1@}, \
4004meat = 0x54 "Pork"@}
1041a570 4005@end group
70b88761
RP
4006@end smallexample
4007
4008@noindent
4009This is the default format.
4010
4011@item show print pretty
4012@kindex show print pretty
4013Show which format _GDBN__ will use to print structures.
4014
4015@item set print sevenbit-strings on
f2857bd9 4016@kindex set print sevenbit-strings
e251e767 4017Print using only seven-bit characters; if this option is set,
70b88761
RP
4018_GDBN__ will display any eight-bit characters (in strings or character
4019values) using the notation @code{\}@var{nnn}. For example, @kbd{M-a} is
4020displayed as @code{\341}.
4021
4022@item set print sevenbit-strings off
4023Print using either seven-bit or eight-bit characters, as required. This
4024is the default.
4025
4026@item show print sevenbit-strings
f2857bd9 4027@kindex show print sevenbit-strings
70b88761
RP
4028Show whether or not _GDBN__ will print only seven-bit characters.
4029
4030@item set print union on
4031@kindex set print union
4032Tell _GDBN__ to print unions which are contained in structures. This is the
4033default setting.
4034
4035@item set print union off
4036Tell _GDBN__ not to print unions which are contained in structures.
4037
4038@item show print union
4039@kindex show print union
4040Ask _GDBN__ whether or not it will print unions which are contained in
e251e767 4041structures.
70b88761
RP
4042
4043For example, given the declarations
4044
4045@smallexample
4046typedef enum @{Tree, Bug@} Species;
4047typedef enum @{Big_tree, Acorn, Seedling@} Tree_forms;
203eea5d
RP
4048typedef enum @{Caterpillar, Cocoon, Butterfly@}
4049 Bug_forms;
70b88761
RP
4050
4051struct thing @{
4052 Species it;
4053 union @{
4054 Tree_forms tree;
4055 Bug_forms bug;
4056 @} form;
4057@};
4058
4059struct thing foo = @{Tree, @{Acorn@}@};
4060@end smallexample
4061
4062@noindent
4063with @code{set print union on} in effect @samp{p foo} would print
4064
4065@smallexample
4066$1 = @{it = Tree, form = @{tree = Acorn, bug = Cocoon@}@}
4067@end smallexample
4068
4069@noindent
4070and with @code{set print union off} in effect it would print
4071
4072@smallexample
4073$1 = @{it = Tree, form = @{...@}@}
4074@end smallexample
4075@end table
4076
4077@noindent
4078These settings are of interest when debugging C++ programs:
4079
4080@table @code
e251e767
RP
4081@item set print demangle
4082@itemx set print demangle on
70b88761
RP
4083@kindex set print demangle
4084Print C++ names in their source form rather than in the mangled form
4085in which they are passed to the assembler and linker for type-safe linkage.
4086The default is on.
4087
4088@item show print demangle
4089@kindex show print demangle
4090Show whether C++ names will be printed in mangled or demangled form.
4091
e251e767
RP
4092@item set print asm-demangle
4093@itemx set print asm-demangle on
70b88761
RP
4094@kindex set print asm-demangle
4095Print C++ names in their source form rather than their mangled form, even
4096in assembler code printouts such as instruction disassemblies.
4097The default is off.
4098
4099@item show print asm-demangle
4100@kindex show print asm-demangle
4101Show whether C++ names in assembly listings will be printed in mangled
4102or demangled form.
4103
4104@item set print object
4105@itemx set print object on
4106@kindex set print object
4107When displaying a pointer to an object, identify the @emph{actual}
4108(derived) type of the object rather than the @emph{declared} type, using
4109the virtual function table.
4110
4111@item set print object off
4112Display only the declared type of objects, without reference to the
4113virtual function table. This is the default setting.
4114
4115@item show print object
4116@kindex show print object
4117Show whether actual, or declared, object types will be displayed.
4118
e251e767
RP
4119@item set print vtbl
4120@itemx set print vtbl on
70b88761
RP
4121@kindex set print vtbl
4122Pretty print C++ virtual function tables. The default is off.
4123
4124@item set print vtbl off
4125Do not pretty print C++ virtual function tables.
4126
4127@item show print vtbl
4128@kindex show print vtbl
4129Show whether C++ virtual function tables are pretty printed, or not.
70b88761
RP
4130@end table
4131
4eb4cf57 4132@node Value History
70b88761
RP
4133@section Value History
4134
4135@cindex value history
4136Values printed by the @code{print} command are saved in _GDBN__'s @dfn{value
4137history} so that you can refer to them in other expressions. Values are
4138kept until the symbol table is re-read or discarded (for example with
4139the @code{file} or @code{symbol-file} commands). When the symbol table
4140changes, the value history is discarded, since the values may contain
4141pointers back to the types defined in the symbol table.
4142
4143@cindex @code{$}
4144@cindex @code{$$}
4145@cindex history number
4146The values printed are given @dfn{history numbers} for you to refer to them
4147by. These are successive integers starting with one. @code{print} shows you
4148the history number assigned to a value by printing @samp{$@var{num} = }
4149before the value; here @var{num} is the history number.
4150
4151To refer to any previous value, use @samp{$} followed by the value's
4152history number. The way @code{print} labels its output is designed to
4153remind you of this. Just @code{$} refers to the most recent value in
4154the history, and @code{$$} refers to the value before that.
4155@code{$$@var{n}} refers to the @var{n}th value from the end; @code{$$2}
4156is the value just prior to @code{$$}, @code{$$1} is equivalent to
4157@code{$$}, and @code{$$0} is equivalent to @code{$}.
4158
4159For example, suppose you have just printed a pointer to a structure and
4160want to see the contents of the structure. It suffices to type
4161
4162@example
4163p *$
4164@end example
4165
4166If you have a chain of structures where the component @code{next} points
4167to the next one, you can print the contents of the next one with this:
4168
4169@example
4170p *$.next
4171@end example
4172
4173@noindent
4174You can print successive links in the chain by repeating this
4175command---which you can do by just typing @key{RET}.
4176
4177Note that the history records values, not expressions. If the value of
4178@code{x} is 4 and you type these commands:
4179
4180@example
4181print x
4182set x=5
4183@end example
4184
4185@noindent
4186then the value recorded in the value history by the @code{print} command
4187remains 4 even though the value of @code{x} has changed.
4188
4189@table @code
4190@kindex show values
4191@item show values
4192Print the last ten values in the value history, with their item numbers.
4193This is like @samp{p@ $$9} repeated ten times, except that @code{show
4194values} does not change the history.
4195
4196@item show values @var{n}
4197Print ten history values centered on history item number @var{n}.
4198
4199@item show values +
4200Print ten history values just after the values last printed. If no more
4201values are available, produces no display.
4202@end table
4203
4204Pressing @key{RET} to repeat @code{show values @var{n}} has exactly the
e251e767 4205same effect as @samp{show values +}.
70b88761 4206
4eb4cf57 4207@node Convenience Vars
70b88761
RP
4208@section Convenience Variables
4209
4210@cindex convenience variables
4211_GDBN__ provides @dfn{convenience variables} that you can use within
4212_GDBN__ to hold on to a value and refer to it later. These variables
4213exist entirely within _GDBN__; they are not part of your program, and
4214setting a convenience variable has no direct effect on further execution
1041a570 4215of your program. That is why you can use them freely.
70b88761
RP
4216
4217Convenience variables are prefixed with @samp{$}. Any name preceded by
4218@samp{$} can be used for a convenience variable, unless it is one of
4219the predefined machine-specific register names (@pxref{Registers}).
4220(Value history references, in contrast, are @emph{numbers} preceded
1041a570 4221by @samp{$}. @xref{Value History, ,Value History}.)
70b88761
RP
4222
4223You can save a value in a convenience variable with an assignment
4224expression, just as you would set a variable in your program. Example:
4225
4226@example
4227set $foo = *object_ptr
4228@end example
4229
4230@noindent
4231would save in @code{$foo} the value contained in the object pointed to by
4232@code{object_ptr}.
4233
4234Using a convenience variable for the first time creates it; but its value
4235is @code{void} until you assign a new value. You can alter the value with
4236another assignment at any time.
4237
4238Convenience variables have no fixed types. You can assign a convenience
4239variable any type of value, including structures and arrays, even if
4240that variable already has a value of a different type. The convenience
4241variable, when used as an expression, has the type of its current value.
4242
4243@table @code
4244@item show convenience
4245@kindex show convenience
4246Print a list of convenience variables used so far, and their values.
4247Abbreviated @code{show con}.
4248@end table
4249
4250One of the ways to use a convenience variable is as a counter to be
4251incremented or a pointer to be advanced. For example, to print
4252a field from successive elements of an array of structures:
4253
4254_0__@example
4255set $i = 0
4256print bar[$i++]->contents
4257@i{@dots{} repeat that command by typing @key{RET}.}
4258_1__@end example
4259
4260Some convenience variables are created automatically by _GDBN__ and given
4261values likely to be useful.
4262
4263@table @code
4264@item $_
c338a2fd 4265@kindex $_
70b88761 4266The variable @code{$_} is automatically set by the @code{x} command to
29a2b744
RP
4267the last address examined (@pxref{Memory, ,Examining Memory}). Other
4268commands which provide a default address for @code{x} to examine also
4269set @code{$_} to that address; these commands include @code{info line}
4270and @code{info breakpoint}. The type of @code{$_} is @code{void *}
4271except when set by the @code{x} command, in which case it is a pointer
4272to the type of @code{$__}.
70b88761
RP
4273
4274@item $__
c338a2fd 4275@kindex $__
70b88761 4276The variable @code{$__} is automatically set by the @code{x} command
c2bbbb22
RP
4277to the value found in the last address examined. Its type is chosen
4278to match the format in which the data was printed.
70b88761
RP
4279@end table
4280
4eb4cf57 4281@node Registers
70b88761
RP
4282@section Registers
4283
4284@cindex registers
b80282d5 4285You can refer to machine register contents, in expressions, as variables
70b88761
RP
4286with names starting with @samp{$}. The names of registers are different
4287for each machine; use @code{info registers} to see the names used on
e251e767 4288your machine.
70b88761
RP
4289
4290@table @code
4291@item info registers
4292@kindex info registers
b80282d5
RP
4293Print the names and values of all registers except floating-point
4294registers (in the selected stack frame).
4295
4296@item info all-registers
4297@kindex info all-registers
4298@cindex floating point registers
4299Print the names and values of all registers, including floating-point
4300registers.
70b88761 4301
4eb4cf57 4302@item info registers @var{regname} @dots{}
0d1cd01e
JG
4303Print the relativized value of each specified register @var{regname}.
4304@var{regname} may be any register name valid on the machine you are using, with
70b88761
RP
4305or without the initial @samp{$}.
4306@end table
4307
09267865 4308_GDBN__ has four ``standard'' register names that are available (in
29a2b744 4309expressions) on most machines---whenever they do not conflict with an
09267865
RP
4310architecture's canonical mnemonics for registers. The register names
4311@code{$pc} and @code{$sp} are used for the program counter register and
4312the stack pointer. @code{$fp} is used for a register that contains a
4313pointer to the current stack frame, and @code{$ps} is used for a
4314register that contains the processor status. For example,
70b88761 4315you could print the program counter in hex with
1041a570 4316
70b88761
RP
4317@example
4318p/x $pc
4319@end example
4320
4321@noindent
4322or print the instruction to be executed next with
1041a570 4323
70b88761
RP
4324@example
4325x/i $pc
4326@end example
4327
4328@noindent
29a2b744
RP
4329or add four to the stack pointer @footnote{This is a way of removing
4330one word from the stack, on machines where stacks grow downward in
4331memory (most machines, nowadays). This assumes that the innermost
4332stack frame is selected; setting @code{$sp} is not allowed when other
4333stack frames are selected. To pop entire frames off the stack,
4334regardless of machine architecture, use @code{return};
1041a570
RP
4335@pxref{Returning, ,Returning from a Function}.} with
4336
70b88761
RP
4337@example
4338set $sp += 4
4339@end example
4340
09267865
RP
4341Whenever possible, these four standard register names are available on
4342your machine even though the machine has different canonical mnemonics,
4343so long as there is no conflict. The @code{info registers} command
4344shows the canonical names. For example, on the SPARC, @code{info
70b88761
RP
4345registers} displays the processor status register as @code{$psr} but you
4346can also refer to it as @code{$ps}.
4347
4348_GDBN__ always considers the contents of an ordinary register as an
4349integer when the register is examined in this way. Some machines have
4350special registers which can hold nothing but floating point; these
4351registers are considered to have floating point values. There is no way
4352to refer to the contents of an ordinary register as floating point value
4353(although you can @emph{print} it as a floating point value with
4354@samp{print/f $@var{regname}}).
4355
4356Some registers have distinct ``raw'' and ``virtual'' data formats. This
4357means that the data format in which the register contents are saved by
4358the operating system is not the same one that your program normally
4359sees. For example, the registers of the 68881 floating point
4360coprocessor are always saved in ``extended'' (raw) format, but all C
4361programs expect to work with ``double'' (virtual) format. In such
4362cases, _GDBN__ normally works with the virtual format only (the format that
4363makes sense for your program), but the @code{info registers} command
4364prints the data in both formats.
4365
4366Normally, register values are relative to the selected stack frame
29a2b744
RP
4367(@pxref{Selection, ,Selecting a Frame}). This means that you get the
4368value that the register would contain if all stack frames farther in
4369were exited and their saved registers restored. In order to see the
4370true contents of hardware registers, you must select the innermost
4371frame (with @samp{frame 0}).
70b88761
RP
4372
4373However, _GDBN__ must deduce where registers are saved, from the machine
4374code generated by your compiler. If some registers are not saved, or if
4375_GDBN__ is unable to locate the saved registers, the selected stack
4376frame will make no difference.
4377
d8a68b28 4378_if__(_AMD29K__)
03a77779 4379@table @code
d8a68b28
JG
4380@item set rstack_high_address @var{address}
4381@kindex set rstack_high_address
03a77779
RP
4382@cindex AMD 29K register stack
4383@cindex register stack, AMD29K
4384On AMD 29000 family processors, registers are saved in a separate
4385``register stack''. There is no way for _GDBN__ to determine the extent
4386of this stack. Normally, _GDBN__ just assumes that the stack is ``large
4387enough''. This may result in _GDBN__ referencing memory locations that
4388don't exist. If necessary, you can get around this problem by
4389specifying the ending address of the register stack with the @code{set
4390rstack_high_address} command. The argument should be an address, which
4391you will probably want to precede with @samp{0x} to specify in
4392hexadecimal.
d8a68b28
JG
4393
4394@item show rstack_high_address
4395@kindex show rstack_high_address
03a77779
RP
4396Display the current limit of the register stack, on AMD 29000 family
4397processors.
4398@end table
d8a68b28
JG
4399_fi__(_AMD29K__)
4400
4eb4cf57
RP
4401_if__(_GENERIC__ || !_H8__)
4402@node Floating Point Hardware
70b88761
RP
4403@section Floating Point Hardware
4404@cindex floating point
1041a570 4405
70b88761
RP
4406Depending on the host machine architecture, _GDBN__ may be able to give
4407you more information about the status of the floating point hardware.
4408
4409@table @code
4410@item info float
4411@kindex info float
4412If available, provides hardware-dependent information about the floating
4413point unit. The exact contents and layout vary depending on the
4414floating point chip.
4415@end table
4416@c FIXME: this is a cop-out. Try to get examples, explanations. Only
e251e767
RP
4417@c FIXME...supported currently on arm's and 386's. Mark properly with
4418@c FIXME... m4 macros to isolate general statements from hardware-dep,
70b88761 4419@c FIXME... at that point.
4eb4cf57 4420_fi__(_GENERIC__ || !_H8__)
70b88761 4421
4eb4cf57
RP
4422_if__(!_CONLY__)
4423@node Languages
c2bbbb22
RP
4424@chapter Using _GDBN__ with Different Languages
4425@cindex languages
4426
4427Although programming languages generally have common aspects, they are
4428rarely expressed in the same manner. For instance, in ANSI C,
4429dereferencing a pointer @code{p} is accomplished by @code{*p}, but in
4430Modula-2, it is accomplished by @code{p^}. Values can also be
4431represented (and displayed) differently. Hex numbers in C are written
4432like @samp{0x1ae}, while in Modula-2 they appear as @samp{1AEH}.
4433
4434@cindex working language
4435Language-specific information is built into _GDBN__ for some languages,
29a2b744 4436allowing you to express operations like the above in your program's
c2bbbb22 4437native language, and allowing _GDBN__ to output values in a manner
29a2b744 4438consistent with the syntax of your program's native language. The
c2bbbb22
RP
4439language you use to build expressions, called the @dfn{working
4440language}, can be selected manually, or _GDBN__ can set it
4441automatically.
4442
4443@menu
4444* Setting:: Switching between source languages
4445* Show:: Displaying the language
4446* Checks:: Type and Range checks
4447* Support:: Supported languages
4448@end menu
4449
4eb4cf57 4450@node Setting
c2bbbb22
RP
4451@section Switching between source languages
4452
4453There are two ways to control the working language---either have _GDBN__
4454set it automatically, or select it manually yourself. You can use the
4455@code{set language} command for either purpose. On startup, _GDBN__
4456defaults to setting the language automatically.
4457
4458@menu
4459* Manually:: Setting the working language manually
4460* Automatically:: Having _GDBN__ infer the source language
4461@end menu
4462
4eb4cf57 4463@node Manually
c2bbbb22
RP
4464@subsection Setting the working language
4465
4466@kindex set language
4467To set the language, issue the command @samp{set language @var{lang}},
c338a2fd
RP
4468where @var{lang} is the name of a language: @code{c} or @code{modula-2}.
4469For a list of the supported languages, type @samp{set language}.
c2bbbb22
RP
4470
4471Setting the language manually prevents _GDBN__ from updating the working
4472language automatically. This can lead to confusion if you try
4473to debug a program when the working language is not the same as the
4474source language, when an expression is acceptable to both
4475languages---but means different things. For instance, if the current
4476source file were written in C, and _GDBN__ was parsing Modula-2, a
4477command such as:
4478
4479@example
4480print a = b + c
4481@end example
4482
4483@noindent
4484might not have the effect you intended. In C, this means to add
4485@code{b} and @code{c} and place the result in @code{a}. The result
4486printed would be the value of @code{a}. In Modula-2, this means to compare
4487@code{a} to the result of @code{b+c}, yielding a @code{BOOLEAN} value.
4488
4489If you allow _GDBN__ to set the language automatically, then
4490you can count on expressions evaluating the same way in your debugging
4491session and in your program.
4492
4eb4cf57 4493@node Automatically
c2bbbb22
RP
4494@subsection Having _GDBN__ infer the source language
4495
4496To have _GDBN__ set the working language automatically, use @samp{set
4497language local} or @samp{set language auto}. _GDBN__ then infers the
4498language that a program was written in by looking at the name of its
4499source files, and examining their extensions:
4500
4501@table @file
4502@item *.mod
4503Modula-2 source file
4504
4505@item *.c
5a2c1d85
RP
4506C source file
4507
4508@item *.C
c2bbbb22 4509@itemx *.cc
5a2c1d85 4510C++ source file
c2bbbb22
RP
4511@end table
4512
4513This information is recorded for each function or procedure in a source
4514file. When your program stops in a frame (usually by encountering a
4515breakpoint), _GDBN__ sets the working language to the language recorded
4516for the function in that frame. If the language for a frame is unknown
4517(that is, if the function or block corresponding to the frame was
4518defined in a source file that does not have a recognized extension), the
4519current working language is not changed, and _GDBN__ issues a warning.
4520
4521This may not seem necessary for most programs, which are written
4522entirely in one source language. However, program modules and libraries
4523written in one source language can be used by a main program written in
4524a different source language. Using @samp{set language auto} in this
4525case frees you from having to set the working language manually.
4526
4eb4cf57 4527@node Show
c2bbbb22
RP
4528@section Displaying the language
4529
4530The following commands will help you find out which language is the
4531working language, and also what language source files were written in.
4532
4533@kindex show language
4534@kindex info frame
4535@kindex info source
4536@table @code
4537@item show language
4538Display the current working language. This is the
4539language you can use with commands such as @code{print} to
29a2b744 4540build and compute expressions that may involve variables in your program.
c2bbbb22
RP
4541
4542@item info frame
1041a570 4543Among the other information listed here (@pxref{Frame Info, ,Information
c2bbbb22
RP
4544about a Frame}) is the source language for this frame. This is the
4545language that will become the working language if you ever use an
4546identifier that is in this frame.
4547
4548@item info source
1041a570 4549Among the other information listed here (@pxref{Symbols, ,Examining the
c2bbbb22 4550Symbol Table}) is the source language of this source file.
c2bbbb22
RP
4551@end table
4552
4eb4cf57 4553@node Checks
c2bbbb22
RP
4554@section Type and range Checking
4555
4556@quotation
4557@emph{Warning:} In this release, the _GDBN__ commands for type and range
4558checking are included, but they do not yet have any effect. This
4559section documents the intended facilities.
4560@end quotation
4561@c FIXME remove warning when type/range code added
4562
4563Some languages are designed to guard you against making seemingly common
4564errors through a series of compile- and run-time checks. These include
4565checking the type of arguments to functions and operators, and making
4566sure mathematical overflows are caught at run time. Checks such as
4567these help to ensure a program's correctness once it has been compiled
4568by eliminating type mismatches, and providing active checks for range
29a2b744 4569errors when your program is running.
c2bbbb22 4570
1041a570
RP
4571_GDBN__ can check for conditions like the above if you wish.
4572Although _GDBN__ will not check the statements in your program, it
4573can check expressions entered directly into _GDBN__ for evaluation via
4574the @code{print} command, for example. As with the working language,
c2bbbb22 4575_GDBN__ can also decide whether or not to check automatically based on
1041a570
RP
4576your program's source language. @xref{Support, ,Supported Languages},
4577for the default settings of supported languages.
c2bbbb22
RP
4578
4579@menu
4580* Type Checking:: An overview of type checking
4581* Range Checking:: An overview of range checking
4582@end menu
4583
4584@cindex type checking
4585@cindex checks, type
4eb4cf57 4586@node Type Checking
c2bbbb22
RP
4587@subsection An overview of type checking
4588
4589Some languages, such as Modula-2, are strongly typed, meaning that the
4590arguments to operators and functions have to be of the correct type,
4591otherwise an error occurs. These checks prevent type mismatch
4592errors from ever causing any run-time problems. For example,
4593
4594@example
45951 + 2 @result{} 3
1041a570 4596@exdent but
c2bbbb22
RP
4597@error{} 1 + 2.3
4598@end example
4599
4600The second example fails because the @code{CARDINAL} 1 is not
4601type-compatible with the @code{REAL} 2.3.
4602
4603For expressions you use in _GDBN__ commands, you can tell the _GDBN__
4604type checker to skip checking; to treat any mismatches as errors and
4605abandon the expression; or only issue warnings when type mismatches
4606occur, but evaluate the expression anyway. When you choose the last of
4607these, _GDBN__ evaluates expressions like the second example above, but
4608also issues a warning.
4609
4610Even though you may turn type checking off, other type-based reasons may
4611prevent _GDBN__ from evaluating an expression. For instance, _GDBN__ does not
4612know how to add an @code{int} and a @code{struct foo}. These particular
4613type errors have nothing to do with the language in use, and usually
4614arise from expressions, such as the one described above, which make
4615little sense to evaluate anyway.
4616
4617Each language defines to what degree it is strict about type. For
4618instance, both Modula-2 and C require the arguments to arithmetical
4619operators to be numbers. In C, enumerated types and pointers can be
4620represented as numbers, so that they are valid arguments to mathematical
1041a570 4621operators. @xref{Support, ,Supported Languages}, for further
c2bbbb22
RP
4622details on specific languages.
4623
4624_GDBN__ provides some additional commands for controlling the type checker:
4625
4626@kindex set check
4627@kindex set check type
4628@kindex show check type
4629@table @code
4630@item set check type auto
e251e767 4631Set type checking on or off based on the current working language.
1041a570 4632@xref{Support, ,Supported Languages}, for the default settings for
c2bbbb22
RP
4633each language.
4634
4635@item set check type on
4636@itemx set check type off
4637Set type checking on or off, overriding the default setting for the
4638current working language. Issue a warning if the setting does not
4639match the language's default. If any type mismatches occur in
4640evaluating an expression while typechecking is on, _GDBN__ prints a
4641message and aborts evaluation of the expression.
4642
4643@item set check type warn
4644Cause the type checker to issue warnings, but to always attempt to
4645evaluate the expression. Evaluating the expression may still
4646be impossible for other reasons. For example, _GDBN__ cannot add
4647numbers and structures.
4648
4649@item show type
e251e767 4650Show the current setting of the type checker, and whether or not _GDBN__ is
c2bbbb22
RP
4651setting it automatically.
4652@end table
4653
4654@cindex range checking
4655@cindex checks, range
4eb4cf57 4656@node Range Checking
c2bbbb22
RP
4657@subsection An overview of Range Checking
4658
4659In some languages (such as Modula-2), it is an error to exceed the
4660bounds of a type; this is enforced with run-time checks. Such range
4661checking is meant to ensure program correctness by making sure
4662computations do not overflow, or indices on an array element access do
4663not exceed the bounds of the array.
4664
4665For expressions you use in _GDBN__ commands, you can tell _GDBN__ to
4666ignore range errors; to always treat them as errors and abandon the
4667expression; or to issue warnings when a range error occurs but evaluate
4668the expression anyway.
4669
4670A range error can result from numerical overflow, from exceeding an
4671array index bound, or when you type in a constant that is not a member
4672of any type. Some languages, however, do not treat overflows as an
4673error. In many implementations of C, mathematical overflow causes the
4674result to ``wrap around'' to lower values---for example, if @var{m} is
4675the largest integer value, and @var{s} is the smallest, then
1041a570 4676
c2bbbb22
RP
4677@example
4678@var{m} + 1 @result{} @var{s}
4679@end example
4680
4681This, too, is specific to individual languages, and in some cases
1041a570 4682specific to individual compilers or machines. @xref{Support, ,
c2bbbb22
RP
4683Supported Languages}, for further details on specific languages.
4684
4685_GDBN__ provides some additional commands for controlling the range checker:
4686
4687@kindex set check
4688@kindex set check range
4689@kindex show check range
4690@table @code
4691@item set check range auto
e251e767 4692Set range checking on or off based on the current working language.
1041a570 4693@xref{Support, ,Supported Languages}, for the default settings for
c2bbbb22
RP
4694each language.
4695
4696@item set check range on
4697@itemx set check range off
4698Set range checking on or off, overriding the default setting for the
4699current working language. A warning is issued if the setting does not
4700match the language's default. If a range error occurs, then a message
4701is printed and evaluation of the expression is aborted.
4702
4703@item set check range warn
4704Output messages when the _GDBN__ range checker detects a range error,
4705but attempt to evaluate the expression anyway. Evaluating the
4706expression may still be impossible for other reasons, such as accessing
4707memory that the process does not own (a typical example from many UNIX
4708systems).
4709
4710@item show range
e251e767 4711Show the current setting of the range checker, and whether or not it is
c2bbbb22
RP
4712being set automatically by _GDBN__.
4713@end table
4714
4eb4cf57 4715@node Support
c2bbbb22
RP
4716@section Supported Languages
4717
5a2c1d85 4718_GDBN__ 4 supports C, C++, and Modula-2. Some _GDBN__
1041a570
RP
4719features may be used in expressions regardless of the language you
4720use: the _GDBN__ @code{@@} and @code{::} operators, and the
4721@samp{@{type@}addr} construct (@pxref{Expressions, ,Expressions}) can be
4722used with the constructs of any of the supported languages.
c2bbbb22
RP
4723
4724The following sections detail to what degree each of these
4725source languages is supported by _GDBN__. These sections are
4726not meant to be language tutorials or references, but serve only as a
4727reference guide to what the _GDBN__ expression parser will accept, and
4728what input and output formats should look like for different languages.
4729There are many good books written on each of these languages; please
4730look to these for a language reference or tutorial.
4731
4732@menu
4733* C:: C and C++
4734* Modula-2:: Modula-2
4735@end menu
4736
4eb4cf57 4737@node C
c2bbbb22
RP
4738@subsection C and C++
4739@cindex C and C++
c2bbbb22 4740@cindex expressions in C or C++
0f153e74 4741
5a2c1d85
RP
4742Since C and C++ are so closely related, many features of _GDBN__ apply
4743to both languages. Whenever this is the case, we discuss both languages
4744together.
b80282d5
RP
4745
4746@cindex C++
4747@kindex g++
4748@cindex GNU C++
c2bbbb22
RP
4749The C++ debugging facilities are jointly implemented by the GNU C++
4750compiler and _GDBN__. Therefore, to debug your C++ code effectively,
4751you must compile your C++ programs with the GNU C++ compiler,
4752@code{g++}.
0f153e74
RP
4753_fi__(!_CONLY__)
4754_if__(_CONLY__)
4755@node C
4756@chapter C Language Support
4757@cindex C language
4758@cindex expressions in C
4759
4760Information specific to the C language is built into _GDBN__ so that you
4761can use C expressions while degugging. This also permits _GDBN__ to
4762output values in a manner consistent with C conventions.
c2bbbb22 4763
0f153e74
RP
4764@menu
4765* C Operators:: C Operators
4766* C Constants:: C Constants
4767* Debugging C:: _GDBN__ and C
4768@end menu
4769_fi__(_CONLY__)
4770_if__(!_CONLY__)
b80282d5 4771@menu
c2bbbb22
RP
4772* C Operators:: C and C++ Operators
4773* C Constants:: C and C++ Constants
4774* Cplusplus expressions:: C++ Expressions
4775* C Defaults:: Default settings for C and C++
4776* C Checks:: C and C++ Type and Range Checks
4777* Debugging C:: _GDBN__ and C
4778* Debugging C plus plus:: Special features for C++
b80282d5 4779@end menu
0f153e74 4780_fi__(!_CONLY__)
b80282d5 4781
0f153e74 4782_if__(!_CONLY__)
c2bbbb22 4783@cindex C and C++ operators
4eb4cf57 4784@node C Operators
c2bbbb22 4785@subsubsection C and C++ Operators
4eb4cf57
RP
4786_fi__(!_CONLY__)
4787_if__(_CONLY__)
0f153e74
RP
4788@cindex C operators
4789@node C Operators
4790@section C Operators
4eb4cf57 4791_fi__(_CONLY__)
c2bbbb22
RP
4792
4793Operators must be defined on values of specific types. For instance,
4794@code{+} is defined on numbers, but not on structures. Operators are
0f153e74
RP
4795often defined on groups of types.
4796
4797_if__(!_CONLY__)
4798For the purposes of C and C++, the following definitions hold:
4799_fi__(!_CONLY__)
c2bbbb22
RP
4800
4801@itemize @bullet
e251e767 4802@item
c2bbbb22
RP
4803@emph{Integral types} include @code{int} with any of its storage-class
4804specifiers, @code{char}, and @code{enum}s.
4805
4806@item
4807@emph{Floating-point types} include @code{float} and @code{double}.
4808
4809@item
4810@emph{Pointer types} include all types defined as @code{(@var{type}
4811*)}.
4812
e251e767 4813@item
c2bbbb22 4814@emph{Scalar types} include all of the above.
c2bbbb22
RP
4815@end itemize
4816
4817@noindent
4818The following operators are supported. They are listed here
4819in order of increasing precedence:
4820
4821@table @code
1041a570 4822_0__@item ,
c2bbbb22
RP
4823The comma or sequencing operator. Expressions in a comma-separated list
4824are evaluated from left to right, with the result of the entire
4825expression being the last expression evaluated.
4826
4827@item =
4828Assignment. The value of an assignment expression is the value
4829assigned. Defined on scalar types.
4830
4831@item @var{op}=
1041a570
RP
4832Used in an expression of the form @w{@code{@var{a} @var{op}= @var{b}}},
4833and translated to @w{@code{@var{a} = @var{a op b}}}.
4834@w{@code{@var{op}=}} and @code{=} have the same precendence.
4835@var{op} is any one of the operators @code{|}, @code{^}, @code{&},
4836@code{<<}, @code{>>}, @code{+}, @code{-}, @code{*}, @code{/}, @code{%}.
c2bbbb22
RP
4837
4838@item ?:
4839The ternary operator. @code{@var{a} ? @var{b} : @var{c}} can be thought
4840of as: if @var{a} then @var{b} else @var{c}. @var{a} should be of an
4841integral type.
4842
4843@item ||
1041a570 4844Logical @sc{or}. Defined on integral types.
c2bbbb22
RP
4845
4846@item &&
1041a570 4847Logical @sc{and}. Defined on integral types.
c2bbbb22
RP
4848
4849@item |
1041a570 4850Bitwise @sc{or}. Defined on integral types.
c2bbbb22
RP
4851
4852@item ^
1041a570 4853Bitwise exclusive-@sc{or}. Defined on integral types.
c2bbbb22
RP
4854
4855@item &
1041a570 4856Bitwise @sc{and}. Defined on integral types.
c2bbbb22
RP
4857
4858@item ==@r{, }!=
4859Equality and inequality. Defined on scalar types. The value of these
4860expressions is 0 for false and non-zero for true.
4861
4862@item <@r{, }>@r{, }<=@r{, }>=
4863Less than, greater than, less than or equal, greater than or equal.
4864Defined on scalar types. The value of these expressions is 0 for false
4865and non-zero for true.
4866
4867@item <<@r{, }>>
0f153e74 4868left shift, and right shift. Defined on integral types._1__
c2bbbb22 4869
e251e767 4870@item @@
1041a570 4871The _GDBN__ ``artificial array'' operator (@pxref{Expressions, ,Expressions}).
c2bbbb22
RP
4872
4873@item +@r{, }-
4874Addition and subtraction. Defined on integral types, floating-point types and
e251e767 4875pointer types.
c2bbbb22
RP
4876
4877@item *@r{, }/@r{, }%
4878Multiplication, division, and modulus. Multiplication and division are
4879defined on integral and floating-point types. Modulus is defined on
4880integral types.
4881
4882@item ++@r{, }--
4883Increment and decrement. When appearing before a variable, the
4884operation is performed before the variable is used in an expression;
4885when appearing after it, the variable's value is used before the
4886operation takes place.
4887
4888@item *
4889Pointer dereferencing. Defined on pointer types. Same precedence as
4890@code{++}.
4891
4892@item &
4893Address operator. Defined on variables. Same precedence as @code{++}.
4894
0f153e74 4895_if__(!_CONLY__)
6ca72cc6
RP
4896For debugging C++, _GDBN__ implements a use of @samp{&} beyond what's
4897allowed in the C++ language itself: you can use @samp{&(&@var{ref})}
4898(or, if you prefer, simply @samp{&&@var{ref}} to examine the address
4899where a C++ reference variable (declared with @samp{&@var{ref}}) is
4900stored.
0f153e74 4901_fi__(!_CONLY__)
6ca72cc6 4902
c2bbbb22
RP
4903@item -
4904Negative. Defined on integral and floating-point types. Same
4905precedence as @code{++}.
4906
4907@item !
4908Logical negation. Defined on integral types. Same precedence as
4909@code{++}.
4910
4911@item ~
4912Bitwise complement operator. Defined on integral types. Same precedence as
4913@code{++}.
4914
0f153e74 4915_0__
c2bbbb22
RP
4916@item .@r{, }->
4917Structure member, and pointer-to-structure member. For convenience,
4918_GDBN__ regards the two as equivalent, choosing whether to dereference a
e251e767 4919pointer based on the stored type information.
c2bbbb22
RP
4920Defined on @code{struct}s and @code{union}s.
4921
4922@item []
4923Array indexing. @code{@var{a}[@var{i}]} is defined as
4924@code{*(@var{a}+@var{i})}. Same precedence as @code{->}.
4925
4926@item ()
0f153e74 4927Function parameter list. Same precedence as @code{->}._1__
c2bbbb22 4928
0f153e74 4929_if__(!_CONLY__)
c2bbbb22
RP
4930@item ::
4931C++ scope resolution operator. Defined on
4932@code{struct}, @code{union}, and @code{class} types.
0f153e74 4933_fi__(!_CONLY__)
c2bbbb22
RP
4934
4935@item ::
0f153e74
RP
4936The _GDBN__ scope operator (@pxref{Expressions, ,Expressions}).
4937_if__(!_CONLY__)
4938Same precedence as @code{::}, above.
4939_fi__(!_CONLY__)
c2bbbb22
RP
4940@end table
4941
0f153e74 4942_if__(!_CONLY__)
c2bbbb22 4943@cindex C and C++ constants
4eb4cf57 4944@node C Constants
c2bbbb22 4945@subsubsection C and C++ Constants
0f153e74
RP
4946
4947_GDBN__ allows you to express the constants of C and C++ in the
4948following ways:
4eb4cf57
RP
4949_fi__(!_CONLY__)
4950_if__(_CONLY__)
0f153e74
RP
4951@cindex C constants
4952@node C Constants
4953@section C Constants
c2bbbb22 4954
0f153e74 4955_GDBN__ allows you to express the constants of C in the
c2bbbb22 4956following ways:
0f153e74 4957_fi__(_CONLY__)
c2bbbb22
RP
4958
4959@itemize @bullet
c2bbbb22
RP
4960@item
4961Integer constants are a sequence of digits. Octal constants are
4962specified by a leading @samp{0} (ie. zero), and hexadecimal constants by
1041a570 4963a leading @samp{0x} or @samp{0X}. Constants may also end with a letter
c2bbbb22
RP
4964@samp{l}, specifying that the constant should be treated as a
4965@code{long} value.
4966
4967@item
4968Floating point constants are a sequence of digits, followed by a decimal
4969point, followed by a sequence of digits, and optionally followed by an
4970exponent. An exponent is of the form:
4971@samp{@w{e@r{[[}+@r{]|}-@r{]}@var{nnn}}}, where @var{nnn} is another
4972sequence of digits. The @samp{+} is optional for positive exponents.
4973
4974@item
4975Enumerated constants consist of enumerated identifiers, or their
4976integral equivalents.
4977
4978@item
4979Character constants are a single character surrounded by single quotes
4980(@code{'}), or a number---the ordinal value of the corresponding character
4981(usually its @sc{ASCII} value). Within quotes, the single character may
4982be represented by a letter or by @dfn{escape sequences}, which are of
4983the form @samp{\@var{nnn}}, where @var{nnn} is the octal representation
4984of the character's ordinal value; or of the form @samp{\@var{x}}, where
4985@samp{@var{x}} is a predefined special character---for example,
4986@samp{\n} for newline.
4987
4988@item
4989String constants are a sequence of character constants surrounded
4990by double quotes (@code{"}).
4991
4992@item
4993Pointer constants are an integral value.
c2bbbb22
RP
4994@end itemize
4995
4eb4cf57 4996_if__(!_CONLY__)
0f153e74 4997@node Cplusplus expressions
c2bbbb22 4998@subsubsection C++ Expressions
b80282d5
RP
4999
5000@cindex expressions in C++
b1385986
RP
5001_GDBN__'s expression handling has a number of extensions to
5002interpret a significant subset of C++ expressions.
5003
5004@cindex C++ support, not in @sc{coff}
5005@cindex @sc{coff} versus C++
5006@cindex C++ and object formats
5007@cindex object formats and C++
5008@cindex a.out and C++
5009@cindex @sc{ecoff} and C++
5010@cindex @sc{xcoff} and C++
5011@cindex @sc{elf}/stabs and C++
5012@cindex @sc{elf}/@sc{dwarf} and C++
5013@quotation
5014@emph{Warning:} Most of these extensions depend on the use of additional
5015debugging information in the symbol table, and thus require a rich,
5016extendable object code format. In particular, if your system uses
5017a.out, MIPS @sc{ecoff}, RS/6000 @sc{xcoff}, or Sun @sc{elf} with stabs
5018extensions to the symbol table, these facilities are all available.
5019Where the object code format is standard @sc{coff}, on the other hand,
5020most of the C++ support in _GDBN__ will @emph{not} work, nor can it.
5021For the standard SVr4 debugging format, @sc{dwarf} in @sc{elf}, the
5022standard is still evolving, so the C++ support in _GDBN__ is still
5023fragile; when this debugging format stabilizes, however, C++ support
5024will also be available on systems that use it.
5025@end quotation
b80282d5
RP
5026
5027@enumerate
5028
5029@cindex member functions
e251e767 5030@item
b80282d5 5031Member function calls are allowed; you can use expressions like
1041a570 5032
b80282d5
RP
5033@example
5034count = aml->GetOriginal(x, y)
5035@end example
5036
5037@kindex this
5038@cindex namespace in C++
e251e767 5039@item
b80282d5
RP
5040While a member function is active (in the selected stack frame), your
5041expressions have the same namespace available as the member function;
5042that is, _GDBN__ allows implicit references to the class instance
5043pointer @code{this} following the same rules as C++.
5044
5045@cindex call overloaded functions
5046@cindex type conversions in C++
e251e767 5047@item
b80282d5
RP
5048You can call overloaded functions; _GDBN__ will resolve the function
5049call to the right definition, with one restriction---you must use
5050arguments of the type required by the function that you want to call.
5051_GDBN__ will not perform conversions requiring constructors or
5052user-defined type operators.
5053
5054@cindex reference declarations
5055@item
5056_GDBN__ understands variables declared as C++ references; you can use them in
5057expressions just as you do in C++ source---they are automatically
e251e767 5058dereferenced.
b80282d5
RP
5059
5060In the parameter list shown when _GDBN__ displays a frame, the values of
5061reference variables are not displayed (unlike other variables); this
5062avoids clutter, since references are often used for large structures.
5063The @emph{address} of a reference variable is always shown, unless
1041a570 5064you have specified @samp{set print address off}.
b80282d5
RP
5065
5066@item
5067_GDBN__ supports the C++ name resolution operator @code{::}---your
c2bbbb22
RP
5068expressions can use it just as expressions in your program do. Since
5069one scope may be defined in another, you can use @code{::} repeatedly if
5070necessary, for example in an expression like
5071@samp{@var{scope1}::@var{scope2}::@var{name}}. _GDBN__ also allows
5072resolving name scope by reference to source files, in both C and C++
1041a570 5073debugging (@pxref{Variables, ,Program Variables}).
b80282d5
RP
5074@end enumerate
5075
4eb4cf57 5076@node C Defaults
c2bbbb22
RP
5077@subsubsection C and C++ Defaults
5078@cindex C and C++ defaults
5079
e251e767
RP
5080If you allow _GDBN__ to set type and range checking automatically, they
5081both default to @code{off} whenever the working language changes to
5a2c1d85 5082C or C++. This happens regardless of whether you, or _GDBN__,
c2bbbb22
RP
5083selected the working language.
5084
5085If you allow _GDBN__ to set the language automatically, it sets the
5a2c1d85
RP
5086working language to C or C++ on entering code compiled from a source file
5087whose name ends with @file{.c}, @file{.C}, or @file{.cc}.
1041a570 5088@xref{Automatically, ,Having _GDBN__ infer the source language}, for
c2bbbb22
RP
5089further details.
5090
4eb4cf57 5091@node C Checks
c2bbbb22
RP
5092@subsubsection C and C++ Type and Range Checks
5093@cindex C and C++ checks
5094
5095@quotation
5096@emph{Warning:} in this release, _GDBN__ does not yet perform type or
5097range checking.
5098@end quotation
5099@c FIXME remove warning when type/range checks added
5100
5101By default, when _GDBN__ parses C or C++ expressions, type checking
5102is not used. However, if you turn type checking on, _GDBN__ will
5103consider two variables type equivalent if:
5104
5105@itemize @bullet
5106@item
5107The two variables are structured and have the same structure, union, or
5108enumerated tag.
5109
e251e767 5110@item
c2bbbb22
RP
5111Two two variables have the same type name, or types that have been
5112declared equivalent through @code{typedef}.
5113
5114@ignore
5115@c leaving this out because neither J Gilmore nor R Pesch understand it.
5116@c FIXME--beers?
5117@item
5118The two @code{struct}, @code{union}, or @code{enum} variables are
5119declared in the same declaration. (Note: this may not be true for all C
5120compilers.)
5121@end ignore
c2bbbb22
RP
5122@end itemize
5123
5124Range checking, if turned on, is done on mathematical operations. Array
5125indices are not checked, since they are often used to index a pointer
5126that is not itself an array.
0f153e74 5127_fi__(!_CONLY__)
c2bbbb22 5128
4eb4cf57
RP
5129@node Debugging C
5130_if__(!_CONLY__)
c2bbbb22 5131@subsubsection _GDBN__ and C
4eb4cf57
RP
5132_fi__(!_CONLY__)
5133_if__(_CONLY__)
5134@section _GDBN__ and C
5135_fi__(_CONLY__)
c2bbbb22
RP
5136
5137The @code{set print union} and @code{show print union} commands apply to
5138the @code{union} type. When set to @samp{on}, any @code{union} that is
5139inside a @code{struct} or @code{class} will also be printed.
5140Otherwise, it will appear as @samp{@{...@}}.
5141
5142The @code{@@} operator aids in the debugging of dynamic arrays, formed
1041a570 5143with pointers and a memory allocation function. (@pxref{Expressions, ,Expressions})
c2bbbb22 5144
0f153e74 5145_if__(!_CONLY__)
4eb4cf57
RP
5146@node Debugging C plus plus
5147_if__(!_CONLY__)
6f3ec223 5148@subsubsection _GDBN__ Features for C++
4eb4cf57
RP
5149_fi__(!_CONLY__)
5150_if__(_CONLY__)
5151@section _GDBN__ Features for C++
5152_fi__(_CONLY__)
b80282d5
RP
5153
5154@cindex commands for C++
5155Some _GDBN__ commands are particularly useful with C++, and some are
5156designed specifically for use with C++. Here is a summary:
5157
5158@table @code
5159@cindex break in overloaded functions
5160@item @r{breakpoint menus}
5161When you want a breakpoint in a function whose name is overloaded,
5162_GDBN__'s breakpoint menus help you specify which function definition
5163you want. @xref{Breakpoint Menus}.
5164
5165@cindex overloading in C++
5166@item rbreak @var{regex}
5167Setting breakpoints using regular expressions is helpful for setting
5168breakpoints on overloaded functions that are not members of any special
e251e767 5169classes.
29a2b744 5170@xref{Set Breaks, ,Setting Breakpoints}.
b80282d5
RP
5171
5172@cindex C++ exception handling
5173@item catch @var{exceptions}
5174@itemx info catch
29a2b744 5175Debug C++ exception handling using these commands. @xref{Exception
1041a570 5176Handling, ,Breakpoints and Exceptions}.
b80282d5 5177
e251e767 5178@cindex inheritance
b80282d5
RP
5179@item ptype @var{typename}
5180Print inheritance relationships as well as other information for type
e251e767 5181@var{typename}.
1041a570 5182@xref{Symbols, ,Examining the Symbol Table}.
b80282d5
RP
5183
5184@cindex C++ symbol display
5185@item set print demangle
5186@itemx show print demangle
5187@itemx set print asm-demangle
5188@itemx show print asm-demangle
5189Control whether C++ symbols display in their source form, both when
5190displaying code as C++ source and when displaying disassemblies.
1041a570 5191@xref{Print Settings, ,Print Settings}.
b80282d5
RP
5192
5193@item set print object
5194@itemx show print object
e251e767 5195Choose whether to print derived (actual) or declared types of objects.
1041a570 5196@xref{Print Settings, ,Print Settings}.
b80282d5
RP
5197
5198@item set print vtbl
5199@itemx show print vtbl
5200Control the format for printing virtual function tables.
1041a570 5201@xref{Print Settings, ,Print Settings}.
6f3ec223
RP
5202
5203@item @r{Overloaded symbol names}
5204You can specify a particular definition of an overloaded symbol, using
5205the same notation that's used to declare such symbols in C++: type
5206@code{@var{symbol}(@var{types})} rather than just @var{symbol}. You can
5207also use _GDBN__'s command-line word completion facilities to list the
5208available choices, or to finish the type list for you.
5209@xref{Completion,, Command Completion}, for details on how to do this.
b80282d5
RP
5210@end table
5211
4eb4cf57 5212@node Modula-2
c2bbbb22
RP
5213@subsection Modula-2
5214@cindex Modula-2
5215
5216The extensions made to _GDBN__ to support Modula-2 support output
5217from the GNU Modula-2 compiler (which is currently being developed).
5218Other Modula-2 compilers are not currently supported, and attempting to
5219debug executables produced by them will most likely result in an error
5220as _GDBN__ reads in the executable's symbol table.
5221
5222@cindex expressions in Modula-2
5223@menu
5224* M2 Operators:: Built-in operators
29a2b744 5225* Built-In Func/Proc:: Built-in Functions and Procedures
c2bbbb22
RP
5226* M2 Constants:: Modula-2 Constants
5227* M2 Defaults:: Default settings for Modula-2
5228* Deviations:: Deviations from standard Modula-2
5229* M2 Checks:: Modula-2 Type and Range Checks
5230* M2 Scope:: The scope operators @code{::} and @code{.}
5231* GDB/M2:: _GDBN__ and Modula-2
5232@end menu
5233
4eb4cf57 5234@node M2 Operators
c2bbbb22
RP
5235@subsubsection Operators
5236@cindex Modula-2 operators
5237
5238Operators must be defined on values of specific types. For instance,
5239@code{+} is defined on numbers, but not on structures. Operators are
5240often defined on groups of types. For the purposes of Modula-2, the
5241following definitions hold:
5242
5243@itemize @bullet
5244
5245@item
5246@emph{Integral types} consist of @code{INTEGER}, @code{CARDINAL}, and
5247their subranges.
5248
5249@item
5250@emph{Character types} consist of @code{CHAR} and its subranges.
5251
5252@item
5253@emph{Floating-point types} consist of @code{REAL}.
5254
5255@item
5256@emph{Pointer types} consist of anything declared as @code{POINTER TO
5257@var{type}}.
5258
5259@item
5260@emph{Scalar types} consist of all of the above.
5261
5262@item
5263@emph{Set types} consist of @code{SET}s and @code{BITSET}s.
5264
5265@item
5266@emph{Boolean types} consist of @code{BOOLEAN}.
c2bbbb22
RP
5267@end itemize
5268
5269@noindent
5270The following operators are supported, and appear in order of
5271increasing precedence:
5272
5273@table @code
c2bbbb22
RP
5274@item ,
5275Function argument or array index separator.
1041a570 5276_0__
c2bbbb22
RP
5277@item :=
5278Assignment. The value of @var{var} @code{:=} @var{value} is
5279@var{value}.
5280
5281@item <@r{, }>
5282Less than, greater than on integral, floating-point, or enumerated
5283types.
5284
5285@item <=@r{, }>=
5286Less than, greater than, less than or equal to, greater than or equal to
5287on integral, floating-point and enumerated types, or set inclusion on
5288set types. Same precedence as @code{<}.
5289
5290@item =@r{, }<>@r{, }#
5291Equality and two ways of expressing inequality, valid on scalar types.
5292Same precedence as @code{<}. In _GDBN__ scripts, only @code{<>} is
5293available for inequality, since @code{#} conflicts with the script
5294comment character.
5295
5296@item IN
5297Set membership. Defined on set types and the types of their members.
5298Same precedence as @code{<}.
5299
5300@item OR
5301Boolean disjunction. Defined on boolean types.
5302
5303@item AND@r{, }&
5304Boolean conjuction. Defined on boolean types.
5305
5306@item @@
1041a570 5307The _GDBN__ ``artificial array'' operator (@pxref{Expressions, ,Expressions}).
c2bbbb22
RP
5308
5309@item +@r{, }-
5310Addition and subtraction on integral and floating-point types, or union
5311and difference on set types.
5312
5313@item *
5314Multiplication on integral and floating-point types, or set intersection
5315on set types.
5316
5317@item /
5318Division on floating-point types, or symmetric set difference on set
5319types. Same precedence as @code{*}.
5320
5321@item DIV@r{, }MOD
5322Integer division and remainder. Defined on integral types. Same
5323precedence as @code{*}.
5324
5325@item -
5326Negative. Defined on @code{INTEGER}s and @code{REAL}s.
5327
5328@item ^
e251e767 5329Pointer dereferencing. Defined on pointer types.
c2bbbb22
RP
5330
5331@item NOT
5332Boolean negation. Defined on boolean types. Same precedence as
5333@code{^}.
5334
5335@item .
5336@code{RECORD} field selector. Defined on @code{RECORD}s. Same
5337precedence as @code{^}.
5338
5339@item []
5340Array indexing. Defined on @code{ARRAY}s. Same precedence as @code{^}.
5341
5342@item ()
5343Procedure argument list. Defined on @code{PROCEDURE}s. Same precedence
5344as @code{^}.
5345
5346@item ::@r{, }.
5347_GDBN__ and Modula-2 scope operators.
c2bbbb22
RP
5348@end table
5349
5350@quotation
5351@emph{Warning:} Sets and their operations are not yet supported, so _GDBN__
5352will treat the use of the operator @code{IN}, or the use of operators
5353@code{+}, @code{-}, @code{*}, @code{/}, @code{=}, , @code{<>}, @code{#},
5354@code{<=}, and @code{>=} on sets as an error.
5355@end quotation
5356_1__
29a2b744 5357@cindex Modula-2 built-ins
4eb4cf57 5358@node Built-In Func/Proc
c2bbbb22
RP
5359@subsubsection Built-in Functions and Procedures
5360
5361Modula-2 also makes available several built-in procedures and functions.
5362In describing these, the following metavariables are used:
5363
5364@table @var
5365
5366@item a
5367represents an @code{ARRAY} variable.
5368
5369@item c
5370represents a @code{CHAR} constant or variable.
5371
5372@item i
5373represents a variable or constant of integral type.
5374
5375@item m
5376represents an identifier that belongs to a set. Generally used in the
5377same function with the metavariable @var{s}. The type of @var{s} should
5378be @code{SET OF @var{mtype}} (where @var{mtype} is the type of @var{m}.
5379
5380@item n
5381represents a variable or constant of integral or floating-point type.
5382
5383@item r
5384represents a variable or constant of floating-point type.
5385
5386@item t
5387represents a type.
5388
5389@item v
5390represents a variable.
5391
5392@item x
5393represents a variable or constant of one of many types. See the
5394explanation of the function for details.
c2bbbb22
RP
5395@end table
5396
5397All Modula-2 built-in procedures also return a result, described below.
5398
5399@table @code
5400@item ABS(@var{n})
5401Returns the absolute value of @var{n}.
5402
5403@item CAP(@var{c})
5404If @var{c} is a lower case letter, it returns its upper case
5405equivalent, otherwise it returns its argument
5406
5407@item CHR(@var{i})
5408Returns the character whose ordinal value is @var{i}.
5409
5410@item DEC(@var{v})
5411Decrements the value in the variable @var{v}. Returns the new value.
5412
5413@item DEC(@var{v},@var{i})
5414Decrements the value in the variable @var{v} by @var{i}. Returns the
5415new value.
5416
5417@item EXCL(@var{m},@var{s})
5418Removes the element @var{m} from the set @var{s}. Returns the new
5419set.
5420
5421@item FLOAT(@var{i})
5422Returns the floating point equivalent of the integer @var{i}.
5423
5424@item HIGH(@var{a})
5425Returns the index of the last member of @var{a}.
5426
5427@item INC(@var{v})
5428Increments the value in the variable @var{v}. Returns the new value.
5429
5430@item INC(@var{v},@var{i})
5431Increments the value in the variable @var{v} by @var{i}. Returns the
5432new value.
5433
5434@item INCL(@var{m},@var{s})
5435Adds the element @var{m} to the set @var{s} if it is not already
5436there. Returns the new set.
5437
5438@item MAX(@var{t})
5439Returns the maximum value of the type @var{t}.
5440
5441@item MIN(@var{t})
5442Returns the minimum value of the type @var{t}.
5443
5444@item ODD(@var{i})
5445Returns boolean TRUE if @var{i} is an odd number.
5446
5447@item ORD(@var{x})
5448Returns the ordinal value of its argument. For example, the ordinal
5449value of a character is its ASCII value (on machines supporting the
5450ASCII character set). @var{x} must be of an ordered type, which include
5451integral, character and enumerated types.
5452
5453@item SIZE(@var{x})
5454Returns the size of its argument. @var{x} can be a variable or a type.
5455
5456@item TRUNC(@var{r})
5457Returns the integral part of @var{r}.
5458
5459@item VAL(@var{t},@var{i})
5460Returns the member of the type @var{t} whose ordinal value is @var{i}.
5461@end table
5462
5463@quotation
5464@emph{Warning:} Sets and their operations are not yet supported, so
5465_GDBN__ will treat the use of procedures @code{INCL} and @code{EXCL} as
5466an error.
5467@end quotation
5468
5469@cindex Modula-2 constants
4eb4cf57 5470@node M2 Constants
c2bbbb22
RP
5471@subsubsection Constants
5472
5473_GDBN__ allows you to express the constants of Modula-2 in the following
5474ways:
5475
5476@itemize @bullet
5477
5478@item
5479Integer constants are simply a sequence of digits. When used in an
5480expression, a constant is interpreted to be type-compatible with the
5481rest of the expression. Hexadecimal integers are specified by a
5482trailing @samp{H}, and octal integers by a trailing @samp{B}.
5483
5484@item
5485Floating point constants appear as a sequence of digits, followed by a
5486decimal point and another sequence of digits. An optional exponent can
5487then be specified, in the form @samp{E@r{[}+@r{|}-@r{]}@var{nnn}}, where
5488@samp{@r{[}+@r{|}-@r{]}@var{nnn}} is the desired exponent. All of the
5489digits of the floating point constant must be valid decimal (base 10)
5490digits.
5491
5492@item
5493Character constants consist of a single character enclosed by a pair of
5494like quotes, either single (@code{'}) or double (@code{"}). They may
5495also be expressed by their ordinal value (their ASCII value, usually)
5496followed by a @samp{C}.
5497
5498@item
1041a570
RP
5499String constants consist of a sequence of characters enclosed by a
5500pair of like quotes, either single (@code{'}) or double (@code{"}).
5501Escape sequences in the style of C are also allowed. @xref{C
5502Constants, ,C and C++ Constants}, for a brief explanation of escape
5503sequences.
c2bbbb22
RP
5504
5505@item
5506Enumerated constants consist of an enumerated identifier.
5507
5508@item
5509Boolean constants consist of the identifiers @code{TRUE} and
5510@code{FALSE}.
5511
5512@item
5513Pointer constants consist of integral values only.
5514
5515@item
5516Set constants are not yet supported.
c2bbbb22
RP
5517@end itemize
5518
4eb4cf57 5519@node M2 Defaults
c2bbbb22
RP
5520@subsubsection Modula-2 Defaults
5521@cindex Modula-2 defaults
5522
e251e767
RP
5523If type and range checking are set automatically by _GDBN__, they
5524both default to @code{on} whenever the working language changes to
c2bbbb22
RP
5525Modula-2. This happens regardless of whether you, or _GDBN__,
5526selected the working language.
5527
5528If you allow _GDBN__ to set the language automatically, then entering
5529code compiled from a file whose name ends with @file{.mod} will set the
1041a570 5530working language to Modula-2. @xref{Automatically, ,Having _GDBN__ set
c2bbbb22
RP
5531the language automatically}, for further details.
5532
4eb4cf57 5533@node Deviations
c2bbbb22
RP
5534@subsubsection Deviations from Standard Modula-2
5535@cindex Modula-2, deviations from
5536
5537A few changes have been made to make Modula-2 programs easier to debug.
5538This is done primarily via loosening its type strictness:
5539
5540@itemize @bullet
e251e767 5541@item
c2bbbb22
RP
5542Unlike in standard Modula-2, pointer constants can be formed by
5543integers. This allows you to modify pointer variables during
5544debugging. (In standard Modula-2, the actual address contained in a
5545pointer variable is hidden from you; it can only be modified
5546through direct assignment to another pointer variable or expression that
5547returned a pointer.)
5548
e251e767 5549@item
c2bbbb22
RP
5550C escape sequences can be used in strings and characters to represent
5551non-printable characters. _GDBN__ will print out strings with these
5552escape sequences embedded. Single non-printable characters are
5553printed using the @samp{CHR(@var{nnn})} format.
5554
5555@item
5556The assignment operator (@code{:=}) returns the value of its right-hand
5557argument.
5558
5559@item
29a2b744 5560All built-in procedures both modify @emph{and} return their argument.
e251e767 5561@end itemize
c2bbbb22 5562
4eb4cf57 5563@node M2 Checks
c2bbbb22
RP
5564@subsubsection Modula-2 Type and Range Checks
5565@cindex Modula-2 checks
5566
5567@quotation
5568@emph{Warning:} in this release, _GDBN__ does not yet perform type or
5569range checking.
5570@end quotation
5571@c FIXME remove warning when type/range checks added
5572
5573_GDBN__ considers two Modula-2 variables type equivalent if:
5574
5575@itemize @bullet
5576@item
5577They are of types that have been declared equivalent via a @code{TYPE
5578@var{t1} = @var{t2}} statement
5579
5580@item
5581They have been declared on the same line. (Note: This is true of the
5582GNU Modula-2 compiler, but it may not be true of other compilers.)
c2bbbb22
RP
5583@end itemize
5584
5585As long as type checking is enabled, any attempt to combine variables
5586whose types are not equivalent is an error.
5587
5588Range checking is done on all mathematical operations, assignment, array
29a2b744 5589index bounds, and all built-in functions and procedures.
c2bbbb22 5590
4eb4cf57 5591@node M2 Scope
c2bbbb22
RP
5592@subsubsection The scope operators @code{::} and @code{.}
5593@cindex scope
5594@kindex .
e94b4a2b 5595@cindex colon, doubled as scope operator
1041a570
RP
5596@ifinfo
5597@kindex colon-colon
5598@c Info cannot handoe :: but TeX can.
5599@end ifinfo
5600@iftex
c2bbbb22 5601@kindex ::
1041a570 5602@end iftex
c2bbbb22
RP
5603
5604There are a few subtle differences between the Modula-2 scope operator
5605(@code{.}) and the _GDBN__ scope operator (@code{::}). The two have
5606similar syntax:
5607
5608@example
5609
5610@var{module} . @var{id}
5611@var{scope} :: @var{id}
c2bbbb22
RP
5612@end example
5613
5614@noindent
5615where @var{scope} is the name of a module or a procedure,
29a2b744
RP
5616@var{module} the name of a module, and @var{id} is any declared
5617identifier within your program, except another module.
c2bbbb22
RP
5618
5619Using the @code{::} operator makes _GDBN__ search the scope
5620specified by @var{scope} for the identifier @var{id}. If it is not
5621found in the specified scope, then _GDBN__ will search all scopes
5622enclosing the one specified by @var{scope}.
5623
5624Using the @code{.} operator makes _GDBN__ search the current scope for
5625the identifier specified by @var{id} that was imported from the
5626definition module specified by @var{module}. With this operator, it is
5627an error if the identifier @var{id} was not imported from definition
5628module @var{module}, or if @var{id} is not an identifier in
5629@var{module}.
5630
4eb4cf57 5631@node GDB/M2
c2bbbb22
RP
5632@subsubsection _GDBN__ and Modula-2
5633
5634Some _GDBN__ commands have little use when debugging Modula-2 programs.
5635Five subcommands of @code{set print} and @code{show print} apply
5636specifically to C and C++: @samp{vtbl}, @samp{demangle},
5637@samp{asm-demangle}, @samp{object}, and @samp{union}. The first four
5638apply to C++, and the last to C's @code{union} type, which has no direct
5639analogue in Modula-2.
5640
1041a570 5641The @code{@@} operator (@pxref{Expressions, ,Expressions}), while available
c2bbbb22
RP
5642while using any language, is not useful with Modula-2. Its
5643intent is to aid the debugging of @dfn{dynamic arrays}, which cannot be
5644created in Modula-2 as they can in C or C++. However, because an
5645address can be specified by an integral constant, the construct
1041a570 5646@samp{@{@var{type}@}@var{adrexp}} is still useful. (@pxref{Expressions, ,Expressions})
c2bbbb22
RP
5647_0__
5648@cindex @code{#} in Modula-2
5649In _GDBN__ scripts, the Modula-2 inequality operator @code{#} is
5650interpreted as the beginning of a comment. Use @code{<>} instead.
5651_1__
4eb4cf57
RP
5652_fi__(!_CONLY__)
5653
5654@node Symbols
70b88761
RP
5655@chapter Examining the Symbol Table
5656
5657The commands described in this section allow you to inquire about the
5658symbols (names of variables, functions and types) defined in your
5659program. This information is inherent in the text of your program and
29a2b744 5660does not change as your program executes. _GDBN__ finds it in your
e251e767 5661program's symbol table, in the file indicated when you started _GDBN__
1041a570
RP
5662(@pxref{File Options, ,Choosing Files}), or by one of the
5663file-management commands (@pxref{Files, ,Commands to Specify Files}).
70b88761 5664
6c380b13
RP
5665@c FIXME! This might be intentionally specific to C and C++; if so, move
5666@c to someplace in C section of lang chapter.
5667@cindex symbol names
5668@cindex names of symbols
5669@cindex quoting names
5670Occasionally, you may need to refer to symbols that contain unusual
5671characters, which _GDBN__ ordinarily treats as word delimiters. The
5672most frequent case is in referring to static variables in other
5673source files (@pxref{Variables,,Program Variables}). File names
5674are recorded in object files as debugging symbols, but _GDBN__ would
5675ordinarily parse a typical file name, like @file{foo.c}, as the three words
5676@samp{foo} @samp{.} @samp{c}. To allow _GDBN__ to recognize
5677@samp{foo.c} as a single symbol, enclose it in single quotes; for example,
5678
5679@example
5680p 'foo.c'::x
5681@end example
5682
5683@noindent
5684looks up the value of @code{x} in the scope of the file @file{foo.c}.
5685
70b88761
RP
5686@table @code
5687@item info address @var{symbol}
5688@kindex info address
5689Describe where the data for @var{symbol} is stored. For a register
5690variable, this says which register it is kept in. For a non-register
5691local variable, this prints the stack-frame offset at which the variable
5692is always stored.
5693
5694Note the contrast with @samp{print &@var{symbol}}, which does not work
5695at all for a register variables, and for a stack local variable prints
5696the exact address of the current instantiation of the variable.
5697
5698@item whatis @var{exp}
5699@kindex whatis
5700Print the data type of expression @var{exp}. @var{exp} is not
5701actually evaluated, and any side-effecting operations (such as
5702assignments or function calls) inside it do not take place.
1041a570 5703@xref{Expressions, ,Expressions}.
70b88761
RP
5704
5705@item whatis
5706Print the data type of @code{$}, the last value in the value history.
5707
5708@item ptype @var{typename}
5709@kindex ptype
5710Print a description of data type @var{typename}. @var{typename} may be
5711the name of a type, or for C code it may have the form
5712@samp{struct @var{struct-tag}}, @samp{union @var{union-tag}} or
1041a570 5713@samp{enum @var{enum-tag}}.
70b88761
RP
5714
5715@item ptype @var{exp}
e0dacfd1 5716@itemx ptype
70b88761 5717Print a description of the type of expression @var{exp}. @code{ptype}
1041a570
RP
5718differs from @code{whatis} by printing a detailed description, instead
5719of just the name of the type. For example, if your program declares a
5720variable as
5721
70b88761
RP
5722@example
5723struct complex @{double real; double imag;@} v;
5724@end example
1041a570 5725
70b88761
RP
5726@noindent
5727compare the output of the two commands:
1041a570 5728
70b88761 5729@example
1041a570 5730@group
70b88761
RP
5731(_GDBP__) whatis v
5732type = struct complex
5733(_GDBP__) ptype v
5734type = struct complex @{
5735 double real;
5736 double imag;
5737@}
1041a570 5738@end group
70b88761 5739@end example
1041a570 5740
e0dacfd1
RP
5741@noindent
5742As with @code{whatis}, using @code{ptype} without an argument refers to
5743the type of @code{$}, the last value in the value history.
70b88761
RP
5744
5745@item info types @var{regexp}
5746@itemx info types
e251e767 5747@kindex info types
70b88761
RP
5748Print a brief description of all types whose name matches @var{regexp}
5749(or all types in your program, if you supply no argument). Each
5750complete typename is matched as though it were a complete line; thus,
5751@samp{i type value} gives information on all types in your program whose
5752name includes the string @code{value}, but @samp{i type ^value$} gives
5753information only on types whose complete name is @code{value}.
5754
5755This command differs from @code{ptype} in two ways: first, like
5756@code{whatis}, it does not print a detailed description; second, it
5757lists all source files where a type is defined.
5758
5759@item info source
5760@kindex info source
5761Show the name of the current source file---that is, the source file for
c2bbbb22
RP
5762the function containing the current point of execution---and the language
5763it was written in.
70b88761
RP
5764
5765@item info sources
5766@kindex info sources
29a2b744 5767Print the names of all source files in your program for which there is
b80282d5
RP
5768debugging information, organized into two lists: files whose symbols
5769have already been read, and files whose symbols will be read when needed.
70b88761
RP
5770
5771@item info functions
5772@kindex info functions
5773Print the names and data types of all defined functions.
5774
5775@item info functions @var{regexp}
5776Print the names and data types of all defined functions
5777whose names contain a match for regular expression @var{regexp}.
5778Thus, @samp{info fun step} finds all functions whose names
5779include @code{step}; @samp{info fun ^step} finds those whose names
5780start with @code{step}.
5781
5782@item info variables
5783@kindex info variables
5784Print the names and data types of all variables that are declared
5785outside of functions (i.e., excluding local variables).
5786
5787@item info variables @var{regexp}
5788Print the names and data types of all variables (except for local
5789variables) whose names contain a match for regular expression
5790@var{regexp}.
5791
70b88761
RP
5792@ignore
5793This was never implemented.
5794@item info methods
5795@itemx info methods @var{regexp}
5796@kindex info methods
5797The @code{info methods} command permits the user to examine all defined
5798methods within C++ program, or (with the @var{regexp} argument) a
5799specific set of methods found in the various C++ classes. Many
5800C++ classes provide a large number of methods. Thus, the output
5801from the @code{ptype} command can be overwhelming and hard to use. The
5802@code{info-methods} command filters the methods, printing only those
5803which match the regular-expression @var{regexp}.
5804@end ignore
5805
d48da190
RP
5806@item maint print symbols @var{filename}
5807@itemx maint print psymbols @var{filename}
5808@itemx maint print msymbols @var{filename}
5809@kindex maint print symbols
440d9834 5810@cindex symbol dump
d48da190 5811@kindex maint print psymbols
440d9834
RP
5812@cindex partial symbol dump
5813Write a dump of debugging symbol data into the file @var{filename}.
e0dacfd1 5814These commands are used to debug the _GDBN__ symbol-reading code. Only
d48da190
RP
5815symbols with debugging data are included. If you use @samp{maint print
5816symbols}, _GDBN__ includes all the symbols for which it has already
5817collected full details: that is, @var{filename} reflects symbols for
5818only those files whose symbols _GDBN__ has read. You can use the
5819command @code{info sources} to find out which files these are. If you
5820use @samp{maint print psymbols} instead, the dump shows information about
5821symbols that _GDBN__ only knows partially---that is, symbols defined in
5822files that _GDBN__ has skimmed, but not yet read completely. Finally,
5823@samp{maint print msymbols} dumps just the minimal symbol information
5824required for each object file from which _GDBN__ has read some symbols.
5825The description of @code{symbol-file} explains how _GDBN__ reads
5826symbols; both @code{info source} and @code{symbol-file} are described in
5827@ref{Files, ,Commands to Specify Files}.
70b88761
RP
5828@end table
5829
4eb4cf57 5830@node Altering
70b88761
RP
5831@chapter Altering Execution
5832
29a2b744 5833Once you think you have found an error in your program, you might want to
70b88761
RP
5834find out for certain whether correcting the apparent error would lead to
5835correct results in the rest of the run. You can find the answer by
5836experiment, using the _GDBN__ features for altering execution of the
5837program.
5838
5839For example, you can store new values into variables or memory
29a2b744 5840locations, give your program a signal, restart it at a different address,
70b88761
RP
5841or even return prematurely from a function to its caller.
5842
5843@menu
b80282d5
RP
5844* Assignment:: Assignment to Variables
5845* Jumping:: Continuing at a Different Address
4eb4cf57 5846_if__(!_BARE__)
29a2b744 5847* Signaling:: Giving your program a Signal
4eb4cf57 5848_fi__(!_BARE__)
b80282d5
RP
5849* Returning:: Returning from a Function
5850* Calling:: Calling your Program's Functions
c338a2fd 5851* Patching:: Patching your Program
70b88761
RP
5852@end menu
5853
4eb4cf57 5854@node Assignment
70b88761
RP
5855@section Assignment to Variables
5856
5857@cindex assignment
5858@cindex setting variables
5859To alter the value of a variable, evaluate an assignment expression.
1041a570 5860@xref{Expressions, ,Expressions}. For example,
70b88761
RP
5861
5862@example
5863print x=4
5864@end example
5865
5866@noindent
1041a570 5867stores the value 4 into the variable @code{x}, and then prints the
4eb4cf57
RP
5868value of the assignment expression (which is 4).
5869_if__(!_CONLY__)
5870@xref{Languages, ,Using _GDBN__ with Different Languages}, for more
5871information on operators in supported languages.
5872_fi__(!_CONLY__)
70b88761 5873
70b88761
RP
5874@kindex set variable
5875@cindex variables, setting
5876If you are not interested in seeing the value of the assignment, use the
5877@code{set} command instead of the @code{print} command. @code{set} is
5878really the same as @code{print} except that the expression's value is not
1041a570 5879printed and is not put in the value history (@pxref{Value History, ,Value History}). The
70b88761
RP
5880expression is evaluated only for its effects.
5881
5882If the beginning of the argument string of the @code{set} command
5883appears identical to a @code{set} subcommand, use the @code{set
5884variable} command instead of just @code{set}. This command is identical
5885to @code{set} except for its lack of subcommands. For example, a
5886program might well have a variable @code{width}---which leads to
5887an error if we try to set a new value with just @samp{set width=13}, as
1041a570
RP
5888we might if @code{set width} did not happen to be a _GDBN__ command:
5889
70b88761
RP
5890@example
5891(_GDBP__) whatis width
5892type = double
5893(_GDBP__) p width
5894$4 = 13
5895(_GDBP__) set width=47
5896Invalid syntax in expression.
5897@end example
1041a570 5898
70b88761
RP
5899@noindent
5900The invalid expression, of course, is @samp{=47}. What we can do in
e251e767 5901order to actually set our program's variable @code{width} is
1041a570 5902
70b88761
RP
5903@example
5904(_GDBP__) set var width=47
5905@end example
5906
1041a570
RP
5907_GDBN__ allows more implicit conversions in assignments than C; you can
5908freely store an integer value into a pointer variable or vice versa,
5909and any structure can be converted to any other structure that is the
5910same length or shorter.
e251e767 5911@comment FIXME: how do structs align/pad in these conversions?
70b88761
RP
5912@comment /[email protected] 18dec1990
5913
5914To store values into arbitrary places in memory, use the @samp{@{@dots{}@}}
5915construct to generate a value of specified type at a specified address
1041a570 5916(@pxref{Expressions, ,Expressions}). For example, @code{@{int@}0x83040} refers
70b88761
RP
5917to memory location @code{0x83040} as an integer (which implies a certain size
5918and representation in memory), and
5919
5920@example
5921set @{int@}0x83040 = 4
5922@end example
5923
5924@noindent
5925stores the value 4 into that memory location.
5926
4eb4cf57 5927@node Jumping
70b88761
RP
5928@section Continuing at a Different Address
5929
29a2b744 5930Ordinarily, when you continue your program, you do so at the place where
70b88761
RP
5931it stopped, with the @code{continue} command. You can instead continue at
5932an address of your own choosing, with the following commands:
5933
5934@table @code
5935@item jump @var{linespec}
5936@kindex jump
5937Resume execution at line @var{linespec}. Execution will stop
29a2b744
RP
5938immediately if there is a breakpoint there. @xref{List, ,Printing
5939Source Lines}, for a description of the different forms of
5940@var{linespec}.
70b88761
RP
5941
5942The @code{jump} command does not change the current stack frame, or
5943the stack pointer, or the contents of any memory location or any
5944register other than the program counter. If line @var{linespec} is in
5945a different function from the one currently executing, the results may
5946be bizarre if the two functions expect different patterns of arguments or
5947of local variables. For this reason, the @code{jump} command requests
5948confirmation if the specified line is not in the function currently
5949executing. However, even bizarre results are predictable if you are
29a2b744 5950well acquainted with the machine-language code of your program.
70b88761
RP
5951
5952@item jump *@var{address}
5953Resume execution at the instruction at address @var{address}.
5954@end table
5955
5956You can get much the same effect as the @code{jump} command by storing a
5957new value into the register @code{$pc}. The difference is that this
29a2b744 5958does not start your program running; it only changes the address where it
70b88761
RP
5959@emph{will} run when it is continued. For example,
5960
5961@example
5962set $pc = 0x485
5963@end example
5964
5965@noindent
5966causes the next @code{continue} command or stepping command to execute at
1041a570
RP
5967address @code{0x485}, rather than at the address where your program stopped.
5968@xref{Continuing and Stepping, ,Continuing and Stepping}.
70b88761
RP
5969
5970The most common occasion to use the @code{jump} command is to back up,
5971perhaps with more breakpoints set, over a portion of a program that has
5972already executed, in order to examine its execution in more detail.
5973
4eb4cf57
RP
5974_if__(!_BARE__)
5975@node Signaling
70b88761 5976@c @group
29a2b744 5977@section Giving your program a Signal
70b88761
RP
5978
5979@table @code
5980@item signal @var{signalnum}
5981@kindex signal
29a2b744 5982Resume execution where your program stopped, but give it immediately the
70b88761
RP
5983signal number @var{signalnum}.
5984
5985Alternatively, if @var{signalnum} is zero, continue execution without
29a2b744 5986giving a signal. This is useful when your program stopped on account of
70b88761
RP
5987a signal and would ordinary see the signal when resumed with the
5988@code{continue} command; @samp{signal 0} causes it to resume without a
5989signal.
5990
5991@code{signal} does not repeat when you press @key{RET} a second time
5992after executing the command.
5993@end table
5994@c @end group
4eb4cf57 5995_fi__(!_BARE__)
70b88761 5996
4eb4cf57 5997@node Returning
70b88761
RP
5998@section Returning from a Function
5999
6000@table @code
6001@item return
6002@itemx return @var{expression}
6003@cindex returning from a function
6004@kindex return
6005You can cancel execution of a function call with the @code{return}
6006command. If you give an
6007@var{expression} argument, its value is used as the function's return
e251e767 6008value.
70b88761
RP
6009@end table
6010
6011When you use @code{return}, _GDBN__ discards the selected stack frame
6012(and all frames within it). You can think of this as making the
6013discarded frame return prematurely. If you wish to specify a value to
6014be returned, give that value as the argument to @code{return}.
6015
29a2b744
RP
6016This pops the selected stack frame (@pxref{Selection, ,Selecting a
6017Frame}), and any other frames inside of it, leaving its caller as the
6018innermost remaining frame. That frame becomes selected. The
6019specified value is stored in the registers used for returning values
6020of functions.
70b88761
RP
6021
6022The @code{return} command does not resume execution; it leaves the
6023program stopped in the state that would exist if the function had just
1041a570
RP
6024returned. In contrast, the @code{finish} command (@pxref{Continuing
6025and Stepping, ,Continuing and Stepping}) resumes execution until the
6026selected stack frame returns naturally.
70b88761 6027
4eb4cf57 6028@node Calling
70b88761
RP
6029@section Calling your Program's Functions
6030
6031@cindex calling functions
6032@kindex call
6033@table @code
6034@item call @var{expr}
6035Evaluate the expression @var{expr} without displaying @code{void}
6036returned values.
6037@end table
6038
6039You can use this variant of the @code{print} command if you want to
6040execute a function from your program, but without cluttering the output
6041with @code{void} returned values. The result is printed and saved in
6042the value history, if it is not void.
6043
4eb4cf57 6044@node Patching
c338a2fd
RP
6045@section Patching your Program
6046@cindex patching binaries
6047@cindex writing into executables
6048@cindex writing into corefiles
1041a570 6049
c338a2fd
RP
6050By default, _GDBN__ opens the file containing your program's executable
6051code (or the corefile) read-only. This prevents accidental alterations
6052to machine code; but it also prevents you from intentionally patching
6053your program's binary.
6054
6055If you'd like to be able to patch the binary, you can specify that
6056explicitly with the @code{set write} command. For example, you might
6057want to turn on internal debugging flags, or even to make emergency
e251e767 6058repairs.
c338a2fd
RP
6059
6060@table @code
6061@item set write on
6062@itemx set write off
6063@kindex set write
0f153e74
RP
6064If you specify @samp{set write on}, _GDBN__ will open executable
6065_if__(!_BARE__)
6066and core
6067_fi__(!_BARE__)
6068files for both reading and writing; if you specify @samp{set write
c338a2fd
RP
6069off} (the default), _GDBN__ will open them read-only.
6070
1041a570 6071If you have already loaded a file, you must load it
c338a2fd
RP
6072again (using the @code{exec-file} or @code{core-file} command) after
6073changing @code{set write}, for your new setting to take effect.
6074
6075@item show write
7d7ff5f6 6076@kindex show write
0f153e74
RP
6077Display whether executable files
6078_if__(!_BARE__)
6079and core files
6080_fi__(!_BARE__)
6081will be opened for writing as well as reading.
c338a2fd
RP
6082@end table
6083
4eb4cf57 6084@node _GDBN__ Files
70b88761
RP
6085@chapter _GDBN__'s Files
6086
1041a570 6087_GDBN__ needs to know the file name of the program to be debugged, both in
4eb4cf57
RP
6088order to read its symbol table and in order to start your program.
6089_if__(!_BARE__)
6090To debug a core dump of a previous run, _GDBN__ must be told the file
6091name of the core dump.
6092_fi__(!_BARE__)
1041a570 6093
70b88761 6094@menu
b80282d5
RP
6095* Files:: Commands to Specify Files
6096* Symbol Errors:: Errors Reading Symbol Files
70b88761
RP
6097@end menu
6098
4eb4cf57 6099@node Files
70b88761 6100@section Commands to Specify Files
70b88761 6101@cindex symbol table
70b88761 6102
4eb4cf57 6103_if__(!_BARE__)
0f153e74 6104@cindex core dump file
1041a570
RP
6105The usual way to specify executable and core dump file names is with
6106the command arguments given when you start _GDBN__, (@pxref{Invocation,
6107,Getting In and Out of _GDBN__}.
4eb4cf57
RP
6108_fi__(!_BARE__)
6109_if__(_BARE__)
6110The usual way to specify an executable file name is with
6111the command argument given when you start _GDBN__, (@pxref{Invocation,
6112,Getting In and Out of _GDBN__}.
6113_fi__(_BARE__)
70b88761
RP
6114
6115Occasionally it is necessary to change to a different file during a
4eb4cf57 6116_GDBN__ session. Or you may run _GDBN__ and forget to specify a file you
70b88761
RP
6117want to use. In these situations the _GDBN__ commands to specify new files
6118are useful.
6119
6120@table @code
6121@item file @var{filename}
6122@cindex executable file
6123@kindex file
6124Use @var{filename} as the program to be debugged. It is read for its
6125symbols and for the contents of pure memory. It is also the program
6126executed when you use the @code{run} command. If you do not specify a
1041a570
RP
6127directory and the file is not found in _GDBN__'s working directory, _GDBN__
6128uses the environment variable @code{PATH} as a list of directories to
6129search, just as the shell does when looking for a program to run. You
6130can change the value of this variable, for both _GDBN__ and your program,
6131using the @code{path} command.
70b88761 6132
14d01801
RP
6133On systems with memory-mapped files, an auxiliary symbol table file
6134@file{@var{filename}.syms} may be available for @var{filename}. If it
6135is, _GDBN__ will map in the symbol table from
6136@file{@var{filename}.syms}, starting up more quickly. See the
95d5ceb9 6137descriptions of the options @samp{-mapped} and @samp{-readnow} (available
77b46d13
JG
6138on the command line, and with the commands @code{file}, @code{symbol-file},
6139or @code{add-symbol-file}), for more information.
14d01801 6140
e0dacfd1 6141@item file
70b88761
RP
6142@code{file} with no argument makes _GDBN__ discard any information it
6143has on both executable file and the symbol table.
6144
e0dacfd1 6145@item exec-file @r{[} @var{filename} @r{]}
70b88761
RP
6146@kindex exec-file
6147Specify that the program to be run (but not the symbol table) is found
6148in @var{filename}. _GDBN__ will search the environment variable @code{PATH}
29a2b744 6149if necessary to locate your program. Omitting @var{filename} means to
e0dacfd1 6150discard information on the executable file.
70b88761 6151
e0dacfd1 6152@item symbol-file @r{[} @var{filename} @r{]}
70b88761
RP
6153@kindex symbol-file
6154Read symbol table information from file @var{filename}. @code{PATH} is
6155searched when necessary. Use the @code{file} command to get both symbol
6156table and program to run from the same file.
6157
6158@code{symbol-file} with no argument clears out _GDBN__'s information on your
6159program's symbol table.
6160
6161The @code{symbol-file} command causes _GDBN__ to forget the contents of its
6162convenience variables, the value history, and all breakpoints and
6163auto-display expressions. This is because they may contain pointers to
6164the internal data recording symbols and data types, which are part of
6165the old symbol table data being discarded inside _GDBN__.
6166
6167@code{symbol-file} will not repeat if you press @key{RET} again after
6168executing it once.
6169
14d01801
RP
6170When _GDBN__ is configured for a particular environment, it will
6171understand debugging information in whatever format is the standard
6172generated for that environment; you may use either a GNU compiler, or
6173other compilers that adhere to the local conventions. Best results are
6174usually obtained from GNU compilers; for example, using @code{_GCC__}
6175you can generate debugging information for optimized code.
6176
70b88761 6177On some kinds of object files, the @code{symbol-file} command does not
14d01801 6178normally read the symbol table in full right away. Instead, it scans
70b88761
RP
6179the symbol table quickly to find which source files and which symbols
6180are present. The details are read later, one source file at a time,
1041a570 6181as they are needed.
70b88761
RP
6182
6183The purpose of this two-stage reading strategy is to make _GDBN__ start up
1041a570
RP
6184faster. For the most part, it is invisible except for occasional
6185pauses while the symbol table details for a particular source file are
6186being read. (The @code{set verbose} command can turn these pauses
6187into messages if desired. @xref{Messages/Warnings, ,Optional Warnings
6188and Messages}.)
70b88761
RP
6189
6190When the symbol table is stored in COFF format, @code{symbol-file} does
1041a570 6191read the symbol table data in full right away. We have not implemented
70b88761
RP
6192the two-stage strategy for COFF yet.
6193
95d5ceb9
RP
6194@item symbol-file @var{filename} @r{[} -readnow @r{]} @r{[} -mapped @r{]}
6195@itemx file @var{filename} @r{[} -readnow @r{]} @r{[} -mapped @r{]}
14d01801
RP
6196@kindex readnow
6197@cindex reading symbols immediately
6198@cindex symbols, reading immediately
6199@kindex mapped
6200@cindex memory-mapped symbol file
38962738 6201@cindex saving symbol table
14d01801 6202You can override the _GDBN__ two-stage strategy for reading symbol
95d5ceb9 6203tables by using the @samp{-readnow} option with any of the commands that
14d01801
RP
6204load symbol table information, if you want to be sure _GDBN__ has the
6205entire symbol table available.
6206
4eb4cf57 6207_if__(!_BARE__)
14d01801 6208If memory-mapped files are available on your system through the
95d5ceb9 6209@code{mmap} system call, you can use another option, @samp{-mapped}, to
77b46d13
JG
6210cause _GDBN__ to write the symbols for your program into a reusable
6211file. Future _GDBN__ debugging sessions will map in symbol information
6212from this auxiliary symbol file (if the program hasn't changed), rather
6213than spending time reading the symbol table from the executable
6214program. Using the @samp{-mapped} option has the same effect as
6215starting _GDBN__ with the @samp{-mapped} command-line option.
14d01801 6216
95d5ceb9 6217You can use both options together, to make sure the auxiliary symbol
14d01801
RP
6218file has all the symbol information for your program.
6219
77b46d13
JG
6220The @code{.syms} file is specific to the host machine on which GDB is run.
6221It holds an exact image of GDB's internal symbol table. It cannot be
6222shared across multiple host platforms.
6223
14d01801
RP
6224The auxiliary symbol file for a program called @var{myprog} is called
6225@samp{@var{myprog}.syms}. Once this file exists (so long as it is newer
6226than the corresponding executable), _GDBN__ will always attempt to use
6227it when you debug @var{myprog}; no special options or commands are
6228needed.
6229@c FIXME: for now no mention of directories, since this seems to be in
6230@c flux. 13mar1992 status is that in theory GDB would look either in
6231@c current dir or in same dir as myprog; but issues like competing
6232@c GDB's, or clutter in system dirs, mean that in practice right now
6233@c only current dir is used. FFish says maybe a special GDB hierarchy
6234@c (eg rooted in val of env var GDBSYMS) could exist for mappable symbol
6235@c files.
70b88761 6236
e0dacfd1 6237@item core-file @r{[} @var{filename} @r{]}
70b88761
RP
6238@kindex core
6239@kindex core-file
6240Specify the whereabouts of a core dump file to be used as the ``contents
6241of memory''. Traditionally, core files contain only some parts of the
6242address space of the process that generated them; _GDBN__ can access the
6243executable file itself for other parts.
6244
6245@code{core-file} with no argument specifies that no core file is
6246to be used.
6247
6248Note that the core file is ignored when your program is actually running
29a2b744 6249under _GDBN__. So, if you have been running your program and you wish to
70b88761
RP
6250debug a core file instead, you must kill the subprocess in which the
6251program is running. To do this, use the @code{kill} command
1041a570 6252(@pxref{Kill Process, ,Killing the Child Process}).
4eb4cf57 6253_fi__(!_BARE__)
70b88761
RP
6254
6255@item load @var{filename}
6256@kindex load
6257_if__(_GENERIC__)
6258Depending on what remote debugging facilities are configured into
6259_GDBN__, the @code{load} command may be available. Where it exists, it
6260is meant to make @var{filename} (an executable) available for debugging
6261on the remote system---by downloading, or dynamic linking, for example.
6262@code{load} also records @var{filename}'s symbol table in _GDBN__, like
6263the @code{add-symbol-file} command.
6264
6265If @code{load} is not available on your _GDBN__, attempting to execute
6266it gets the error message ``@code{You can't do that when your target is
e251e767 6267@dots{}}''
70b88761
RP
6268_fi__(_GENERIC__)
6269
e251e767 6270_if__(_VXWORKS__)
70b88761
RP
6271On VxWorks, @code{load} will dynamically link @var{filename} on the
6272current target system as well as adding its symbols in _GDBN__.
6273_fi__(_VXWORKS__)
6274
6275_if__(_I960__)
6276@cindex download to Nindy-960
6277With the Nindy interface to an Intel 960 board, @code{load} will
6278download @var{filename} to the 960 as well as adding its symbols in
e251e767 6279_GDBN__.
70b88761
RP
6280_fi__(_I960__)
6281
c7cb8acb
RP
6282_if__(_H8__)
6283@cindex download to H8/300
6284@cindex H8/300 download
6285When you select remote debugging to a Hitachi H8/300 board (@pxref{Hitachi
6286H8/300 Remote,,_GDBN__ and the Hitachi H8/300}), the
6287@code{load} command downloads your program to the H8/300 and also opens
6288it as the current executable target for _GDBN__ on your host (like the
6289@code{file} command).
6290_fi__(_H8__)
6291
70b88761
RP
6292@code{load} will not repeat if you press @key{RET} again after using it.
6293
0f153e74 6294_if__(!_BARE__)
70b88761 6295@item add-symbol-file @var{filename} @var{address}
95d5ceb9 6296@itemx add-symbol-file @var{filename} @var{address} @r{[} -readnow @r{]} @r{[} -mapped @r{]}
70b88761
RP
6297@kindex add-symbol-file
6298@cindex dynamic linking
6299The @code{add-symbol-file} command reads additional symbol table information
b80282d5 6300from the file @var{filename}. You would use this command when @var{filename}
70b88761
RP
6301has been dynamically loaded (by some other means) into the program that
6302is running. @var{address} should be the memory address at which the
6303file has been loaded; _GDBN__ cannot figure this out for itself.
6304
6305The symbol table of the file @var{filename} is added to the symbol table
6306originally read with the @code{symbol-file} command. You can use the
6307@code{add-symbol-file} command any number of times; the new symbol data thus
6308read keeps adding to the old. To discard all old symbol data instead,
e251e767 6309use the @code{symbol-file} command.
70b88761
RP
6310
6311@code{add-symbol-file} will not repeat if you press @key{RET} after using it.
6312
95d5ceb9
RP
6313You can use the @samp{-mapped} and @samp{-readnow} options just as with
6314the @code{symbol-file} command, to change how _GDBN__ manages the symbol
0f153e74
RP
6315table information for @var{filename}.
6316_fi__(!_BARE__)
95d5ceb9 6317
70b88761
RP
6318@item info files
6319@itemx info target
6320@kindex info files
6321@kindex info target
1041a570
RP
6322@code{info files} and @code{info target} are synonymous; both print
6323the current targets (@pxref{Targets, ,Specifying a Debugging Target}),
6324including the names of the executable and core dump files currently in
6325use by _GDBN__, and the files from which symbols were loaded. The command
6326@code{help targets} lists all possible targets rather than current
6327ones.
70b88761
RP
6328
6329@end table
6330
6331All file-specifying commands allow both absolute and relative file names
6332as arguments. _GDBN__ always converts the file name to an absolute path
6333name and remembers it that way.
6334
4eb4cf57 6335_if__(!_BARE__)
70b88761 6336@cindex shared libraries
77b46d13
JG
6337_GDBN__ supports SunOS, SVR4, and IBM RS/6000 shared libraries.
6338_GDBN__ automatically loads symbol definitions from shared libraries
6339when you use the @code{run} command, or when you examine a core file.
6340(Before you issue the @code{run} command, _GDBN__ will not understand
6341references to a function in a shared library, however---unless you are
6342debugging a core file).
c338a2fd 6343@c FIXME: next _GDBN__ release should permit some refs to undef
1041a570 6344@c FIXME...symbols---eg in a break cmd---assuming they are from a shared lib
70b88761
RP
6345
6346@table @code
70b88761
RP
6347@item info share
6348@itemx info sharedlibrary
6349@kindex info sharedlibrary
6350@kindex info share
c338a2fd 6351Print the names of the shared libraries which are currently loaded.
70b88761 6352
c338a2fd
RP
6353@item sharedlibrary @var{regex}
6354@itemx share @var{regex}
6355@kindex sharedlibrary
6356@kindex share
6357This is an obsolescent command; you can use it to explicitly
6358load shared object library symbols for files matching a UNIX regular
6359expression, but as with files loaded automatically, it will only load
6360shared libraries required by your program for a core file or after
6361typing @code{run}. If @var{regex} is omitted all shared libraries
6362required by your program are loaded.
6363@end table
4eb4cf57 6364_fi__(!_BARE__)
70b88761 6365
4eb4cf57 6366@node Symbol Errors
70b88761 6367@section Errors Reading Symbol Files
1041a570
RP
6368
6369While reading a symbol file, _GDBN__ will occasionally encounter problems,
6370such as symbol types it does not recognize, or known bugs in compiler
6371output. By default, _GDBN__ does not notify you of such problems, since
6372they are relatively common and primarily of interest to people
6373debugging compilers. If you are interested in seeing information
b80282d5
RP
6374about ill-constructed symbol tables, you can either ask _GDBN__ to print
6375only one message about each such type of problem, no matter how many
6376times the problem occurs; or you can ask _GDBN__ to print more messages,
1041a570
RP
6377to see how many times the problems occur, with the @code{set
6378complaints} command (@pxref{Messages/Warnings, ,Optional Warnings and
6379Messages}).
70b88761
RP
6380
6381The messages currently printed, and their meanings, are:
6382
6383@table @code
6384@item inner block not inside outer block in @var{symbol}
6385
6386The symbol information shows where symbol scopes begin and end
6387(such as at the start of a function or a block of statements). This
6388error indicates that an inner scope block is not fully contained
e251e767 6389in its outer scope blocks.
70b88761
RP
6390
6391_GDBN__ circumvents the problem by treating the inner block as if it had
6392the same scope as the outer block. In the error message, @var{symbol}
6393may be shown as ``@code{(don't know)}'' if the outer block is not a
6394function.
6395
6396@item block at @var{address} out of order
6397
e251e767 6398The symbol information for symbol scope blocks should occur in
70b88761 6399order of increasing addresses. This error indicates that it does not
e251e767 6400do so.
70b88761
RP
6401
6402_GDBN__ does not circumvent this problem, and will have trouble locating
6403symbols in the source file whose symbols being read. (You can often
6404determine what source file is affected by specifying @code{set verbose
29a2b744 6405on}. @xref{Messages/Warnings, ,Optional Warnings and Messages}.)
70b88761
RP
6406
6407@item bad block start address patched
6408
6409The symbol information for a symbol scope block has a start address
6410smaller than the address of the preceding source line. This is known
e251e767 6411to occur in the SunOS 4.1.1 (and earlier) C compiler.
70b88761
RP
6412
6413_GDBN__ circumvents the problem by treating the symbol scope block as
6414starting on the previous source line.
6415
70b88761
RP
6416@item bad string table offset in symbol @var{n}
6417
6418@cindex foo
6419Symbol number @var{n} contains a pointer into the string table which is
e251e767 6420larger than the size of the string table.
70b88761
RP
6421
6422_GDBN__ circumvents the problem by considering the symbol to have the
6423name @code{foo}, which may cause other problems if many symbols end up
6424with this name.
6425
6426@item unknown symbol type @code{0x@var{nn}}
6427
6428The symbol information contains new data types that _GDBN__ does not yet
6429know how to read. @code{0x@var{nn}} is the symbol type of the misunderstood
e251e767 6430information, in hexadecimal.
70b88761
RP
6431
6432_GDBN__ circumvents the error by ignoring this symbol information. This
29a2b744 6433will usually allow your program to be debugged, though certain symbols
70b88761
RP
6434will not be accessible. If you encounter such a problem and feel like
6435debugging it, you can debug @code{_GDBP__} with itself, breakpoint on
6436@code{complain}, then go up to the function @code{read_dbx_symtab} and
6437examine @code{*bufp} to see the symbol.
6438
6439@item stub type has NULL name
e251e767 6440_GDBN__ could not find the full definition for a struct or class.
70b88761 6441
440d9834 6442@item const/volatile indicator missing (ok if using g++ v1.x), got@dots{}
70b88761
RP
6443
6444The symbol information for a C++ member function is missing some
440d9834
RP
6445information that recent versions of the compiler should have output
6446for it.
70b88761 6447
440d9834 6448@item info mismatch between compiler and debugger
70b88761 6449
440d9834 6450_GDBN__ could not parse a type specification output by the compiler.
70b88761
RP
6451@end table
6452
4eb4cf57 6453@node Targets
e251e767 6454@chapter Specifying a Debugging Target
70b88761
RP
6455@cindex debugging target
6456@kindex target
1041a570 6457
cedaf8bc 6458A @dfn{target} is the execution environment occupied by your program.
0f153e74 6459_if__(!_BARE__)
1041a570
RP
6460Often, _GDBN__ runs in the same host environment as your program; in
6461that case, the debugging target is specified as a side effect when you
6462use the @code{file} or @code{core} commands. When you need more
6463flexibility---for example, running _GDBN__ on a physically separate
6464host, or controlling a standalone system over a serial port or a
0f153e74
RP
6465realtime system over a TCP/IP connection---you
6466_fi__(!_BARE__)
6467_if__(_BARE__)
6468You
6469_fi__(_BARE__)
6470can use the @code{target} command to specify one of the target types
6471configured for _GDBN__ (@pxref{Target Commands, ,Commands for Managing
6472Targets}).
70b88761
RP
6473
6474@menu
b80282d5
RP
6475* Active Targets:: Active Targets
6476* Target Commands:: Commands for Managing Targets
6477* Remote:: Remote Debugging
70b88761
RP
6478@end menu
6479
4eb4cf57 6480@node Active Targets
70b88761
RP
6481@section Active Targets
6482@cindex stacking targets
6483@cindex active targets
6484@cindex multiple targets
6485
0f153e74 6486_if__(!_BARE__)
cedaf8bc
RP
6487There are three classes of targets: processes, core files, and
6488executable files. _GDBN__ can work concurrently on up to three active
6489targets, one in each class. This allows you to (for example) start a
6490process and inspect its activity without abandoning your work on a core
6491file.
70b88761 6492
cedaf8bc
RP
6493If, for example, you execute @samp{gdb a.out}, then the executable file
6494@code{a.out} is the only active target. If you designate a core file as
6495well---presumably from a prior run that crashed and coredumped---then
6496_GDBN__ has two active targets and will use them in tandem, looking
6497first in the corefile target, then in the executable file, to satisfy
6498requests for memory addresses. (Typically, these two classes of target
29a2b744 6499are complementary, since core files contain only a program's
cedaf8bc
RP
6500read-write memory---variables and so on---plus machine status, while
6501executable files contain only the program text and initialized data.)
0f153e74 6502_fi__(!_BARE__)
cedaf8bc
RP
6503
6504When you type @code{run}, your executable file becomes an active process
6505target as well. When a process target is active, all _GDBN__ commands
0f153e74
RP
6506requesting memory addresses refer to that target; addresses in an
6507_if__(!_BARE__)
6508active core file or
6509_fi__(!_BARE__)
6510executable file target are obscured while the process
cedaf8bc
RP
6511target is active.
6512
4eb4cf57
RP
6513_if__(_BARE__)
6514Use the @code{exec-file} command to select a
6515new executable target (@pxref{Files, ,Commands to Specify
6516Files}).
6517_fi__(_BARE__)
6518_if__(!_BARE__)
1041a570
RP
6519Use the @code{core-file} and @code{exec-file} commands to select a
6520new core file or executable target (@pxref{Files, ,Commands to Specify
6521Files}). To specify as a target a process that is already running, use
6522the @code{attach} command (@pxref{Attach, ,Debugging an
6523Already-Running Process}.).
4eb4cf57 6524_fi__(!_BARE__)
70b88761 6525
4eb4cf57 6526@node Target Commands
70b88761
RP
6527@section Commands for Managing Targets
6528
6529@table @code
6530@item target @var{type} @var{parameters}
6531Connects the _GDBN__ host environment to a target machine or process. A
6532target is typically a protocol for talking to debugging facilities. You
6533use the argument @var{type} to specify the type or protocol of the
6534target machine.
6535
6536Further @var{parameters} are interpreted by the target protocol, but
6537typically include things like device names or host names to connect
e251e767 6538with, process numbers, and baud rates.
70b88761
RP
6539
6540The @code{target} command will not repeat if you press @key{RET} again
6541after executing the command.
6542
6543@item help target
6544@kindex help target
6545Displays the names of all targets available. To display targets
6546currently selected, use either @code{info target} or @code{info files}
29a2b744 6547(@pxref{Files, ,Commands to Specify Files}).
70b88761
RP
6548
6549@item help target @var{name}
6550Describe a particular target, including any parameters necessary to
6551select it.
6552@end table
6553
c7cb8acb 6554Here are some common targets (available, or not, depending on the GDB
70b88761
RP
6555configuration):
6556
6557@table @code
6558@item target exec @var{prog}
6559@kindex target exec
6560An executable file. @samp{target exec @var{prog}} is the same as
6561@samp{exec-file @var{prog}}.
6562
6563@item target core @var{filename}
6564@kindex target core
6565A core dump file. @samp{target core @var{filename}} is the same as
6566@samp{core-file @var{filename}}.
6567
0f153e74 6568_if__(_REMOTESTUB__)
70b88761
RP
6569@item target remote @var{dev}
6570@kindex target remote
c7cb8acb 6571Remote serial target in GDB-specific protocol. The argument @var{dev}
70b88761 6572specifies what serial device to use for the connection (e.g.
1041a570 6573@file{/dev/ttya}). @xref{Remote, ,Remote Debugging}.
0f153e74 6574_fi__(_REMOTESTUB__)
70b88761
RP
6575
6576_if__(_AMD29K__)
6577@item target amd-eb @var{dev} @var{speed} @var{PROG}
6578@kindex target amd-eb
6579@cindex AMD EB29K
6580Remote PC-resident AMD EB29K board, attached over serial lines.
6581@var{dev} is the serial device, as for @code{target remote};
6582@var{speed} allows you to specify the linespeed; and @var{PROG} is the
6583name of the program to be debugged, as it appears to DOS on the PC.
77fe5411
RP
6584@xref{EB29K Remote, ,_GDBN__ with a Remote EB29K}.
6585
70b88761 6586_fi__(_AMD29K__)
c7cb8acb
RP
6587_if__(_H8__)
6588@item target hms
6589@kindex target hms
6590A Hitachi H8/300 board, attached via serial line to your host. Use
6591special commands @code{device} and @code{speed} to control the serial
6592line and the communications speed used. @xref{Hitachi H8/300
6593Remote,,_GDBN__ and the Hitachi H8/300}.
6594
6595_fi__(_H8__)
70b88761
RP
6596_if__(_I960__)
6597@item target nindy @var{devicename}
6598@kindex target nindy
6599An Intel 960 board controlled by a Nindy Monitor. @var{devicename} is
6600the name of the serial device to use for the connection, e.g.
1041a570 6601@file{/dev/ttya}. @xref{i960-Nindy Remote, ,_GDBN__ with a Remote i960 (Nindy)}.
70b88761
RP
6602
6603_fi__(_I960__)
77fe5411
RP
6604_if__(_ST2000__)
6605@item target st2000 @var{dev} @var{speed}
6606@kindex target st2000
6607A Tandem ST2000 phone switch, running Tandem's STDBUG protocol. @var{dev}
6608is the name of the device attached to the ST2000 serial line;
6609@var{speed} is the communication line speed. The arguments are not used
6610if _GDBN__ is configured to connect to the ST2000 using TCP or Telnet.
6611@xref{ST2000 Remote,,_GDBN__ with a Tandem ST2000}.
6612
6613_fi__(_ST2000__)
70b88761
RP
6614_if__(_VXWORKS__)
6615@item target vxworks @var{machinename}
6616@kindex target vxworks
6617A VxWorks system, attached via TCP/IP. The argument @var{machinename}
6618is the target system's machine name or IP address.
1041a570 6619@xref{VxWorks Remote, ,_GDBN__ and VxWorks}.
70b88761
RP
6620_fi__(_VXWORKS__)
6621@end table
6622
6623_if__(_GENERIC__)
6624Different targets are available on different configurations of _GDBN__; your
6625configuration may have more or fewer targets.
6626_fi__(_GENERIC__)
6627
4eb4cf57 6628@node Remote
70b88761
RP
6629@section Remote Debugging
6630@cindex remote debugging
6631
29a2b744 6632If you are trying to debug a program running on a machine that cannot run
c7cb8acb 6633GDB in the usual way, it is often useful to use remote debugging. For
70b88761
RP
6634example, you might use remote debugging on an operating system kernel, or on
6635a small system which does not have a general purpose operating system
e251e767 6636powerful enough to run a full-featured debugger.
70b88761 6637
c7cb8acb 6638Some configurations of GDB have special serial or TCP/IP interfaces
70b88761 6639to make this work with particular debugging targets. In addition,
c7cb8acb 6640GDB comes with a generic serial protocol (specific to GDB, but
70b88761
RP
6641not specific to any particular target system) which you can use if you
6642write the remote stubs---the code that will run on the remote system to
c7cb8acb 6643communicate with GDB.
70b88761 6644
70b88761 6645Other remote targets may be available in your
c7cb8acb 6646configuration of GDB; use @code{help targets} to list them.
70b88761
RP
6647
6648_if__(_GENERIC__)
1041a570
RP
6649_dnl__ Text on starting up GDB in various specific cases; it goes up front
6650_dnl__ in manuals configured for any of those particular situations, here
6651_dnl__ otherwise.
6652@menu
6653_include__(gdbinv-m.m4)<>_dnl__
6654@end menu
70b88761
RP
6655_include__(gdbinv-s.m4)
6656_fi__(_GENERIC__)
6657
4eb4cf57 6658@node Controlling _GDBN__
70b88761
RP
6659@chapter Controlling _GDBN__
6660
6661You can alter many aspects of _GDBN__'s interaction with you by using
6662the @code{set} command. For commands controlling how _GDBN__ displays
1041a570 6663data, @pxref{Print Settings, ,Print Settings}; other settings are described here.
70b88761
RP
6664
6665@menu
b80282d5
RP
6666* Prompt:: Prompt
6667* Editing:: Command Editing
6668* History:: Command History
6669* Screen Size:: Screen Size
6670* Numbers:: Numbers
6671* Messages/Warnings:: Optional Warnings and Messages
70b88761
RP
6672@end menu
6673
4eb4cf57 6674@node Prompt
70b88761
RP
6675@section Prompt
6676@cindex prompt
1041a570 6677
70b88761
RP
6678_GDBN__ indicates its readiness to read a command by printing a string
6679called the @dfn{prompt}. This string is normally @samp{(_GDBP__)}. You
6680can change the prompt string with the @code{set prompt} command. For
6681instance, when debugging _GDBN__ with _GDBN__, it is useful to change
6682the prompt in one of the _GDBN__<>s so that you can always tell which
6683one you are talking to.
6684
6685@table @code
6686@item set prompt @var{newprompt}
6687@kindex set prompt
6688Directs _GDBN__ to use @var{newprompt} as its prompt string henceforth.
6689@kindex show prompt
6690@item show prompt
6691Prints a line of the form: @samp{Gdb's prompt is: @var{your-prompt}}
6692@end table
6693
4eb4cf57 6694@node Editing
70b88761
RP
6695@section Command Editing
6696@cindex readline
6697@cindex command line editing
1041a570 6698
70b88761
RP
6699_GDBN__ reads its input commands via the @dfn{readline} interface. This
6700GNU library provides consistent behavior for programs which provide a
6701command line interface to the user. Advantages are @code{emacs}-style
6702or @code{vi}-style inline editing of commands, @code{csh}-like history
6703substitution, and a storage and recall of command history across
6704debugging sessions.
6705
6706You may control the behavior of command line editing in _GDBN__ with the
e251e767 6707command @code{set}.
70b88761
RP
6708
6709@table @code
6710@kindex set editing
6711@cindex editing
6712@item set editing
6713@itemx set editing on
6714Enable command line editing (enabled by default).
6715
6716@item set editing off
6717Disable command line editing.
6718
6719@kindex show editing
6720@item show editing
6721Show whether command line editing is enabled.
6722@end table
6723
4eb4cf57 6724@node History
70b88761 6725@section Command History
1041a570 6726
70b88761
RP
6727@table @code
6728@cindex history substitution
6729@cindex history file
6730@kindex set history filename
6731@item set history filename @var{fname}
6732Set the name of the _GDBN__ command history file to @var{fname}. This is
6733the file from which _GDBN__ will read an initial command history
6734list or to which it will write this list when it exits. This list is
6735accessed through history expansion or through the history
6736command editing characters listed below. This file defaults to the
6737value of the environment variable @code{GDBHISTFILE}, or to
6738@file{./.gdb_history} if this variable is not set.
6739
6740@cindex history save
6741@kindex set history save
6742@item set history save
6743@itemx set history save on
6744Record command history in a file, whose name may be specified with the
6745@code{set history filename} command. By default, this option is disabled.
6746
6747@item set history save off
6748Stop recording command history in a file.
6749
6750@cindex history size
6751@kindex set history size
6752@item set history size @var{size}
6753Set the number of commands which _GDBN__ will keep in its history list.
6754This defaults to the value of the environment variable
6755@code{HISTSIZE}, or to 256 if this variable is not set.
6756@end table
6757
6758@cindex history expansion
6759History expansion assigns special meaning to the character @kbd{!}.
6760@iftex
1041a570 6761@xref{Event Designators}.
70b88761
RP
6762@end iftex
6763Since @kbd{!} is also the logical not operator in C, history expansion
6764is off by default. If you decide to enable history expansion with the
6765@code{set history expansion on} command, you may sometimes need to
6766follow @kbd{!} (when it is used as logical not, in an expression) with
6767a space or a tab to prevent it from being expanded. The readline
6768history facilities will not attempt substitution on the strings
6769@kbd{!=} and @kbd{!(}, even when history expansion is enabled.
6770
6771The commands to control history expansion are:
6772
6773@table @code
6774
6775@kindex set history expansion
6776@item set history expansion on
6777@itemx set history expansion
6778Enable history expansion. History expansion is off by default.
6779
6780@item set history expansion off
6781Disable history expansion.
6782
6783The readline code comes with more complete documentation of
6784editing and history expansion features. Users unfamiliar with @code{emacs}
e251e767 6785or @code{vi} may wish to read it.
70b88761
RP
6786@iftex
6787@xref{Command Line Editing}.
6788@end iftex
6789
6790@c @group
6791@kindex show history
6792@item show history
6793@itemx show history filename
6794@itemx show history save
6795@itemx show history size
6796@itemx show history expansion
6797These commands display the state of the _GDBN__ history parameters.
6798@code{show history} by itself displays all four states.
6799@c @end group
70b88761
RP
6800@end table
6801
6802@table @code
6803@kindex show commands
6804@item show commands
6805Display the last ten commands in the command history.
6806
6807@item show commands @var{n}
6808Print ten commands centered on command number @var{n}.
6809
6810@item show commands +
6811Print ten commands just after the commands last printed.
70b88761
RP
6812@end table
6813
4eb4cf57 6814@node Screen Size
70b88761
RP
6815@section Screen Size
6816@cindex size of screen
6817@cindex pauses in output
1041a570 6818
70b88761
RP
6819Certain commands to _GDBN__ may produce large amounts of information
6820output to the screen. To help you read all of it, _GDBN__ pauses and
6821asks you for input at the end of each page of output. Type @key{RET}
6822when you want to continue the output. _GDBN__ also uses the screen
6823width setting to determine when to wrap lines of output. Depending on
6824what is being printed, it tries to break the line at a readable place,
6825rather than simply letting it overflow onto the following line.
6826
6827Normally _GDBN__ knows the size of the screen from the termcap data base
6828together with the value of the @code{TERM} environment variable and the
6829@code{stty rows} and @code{stty cols} settings. If this is not correct,
6830you can override it with the @code{set height} and @code{set
6831width} commands:
6832
6833@table @code
6834@item set height @var{lpp}
6835@itemx show height
6836@itemx set width @var{cpl}
6837@itemx show width
6838@kindex set height
6839@kindex set width
6840@kindex show width
6841@kindex show height
6842These @code{set} commands specify a screen height of @var{lpp} lines and
6843a screen width of @var{cpl} characters. The associated @code{show}
6844commands display the current settings.
6845
6846If you specify a height of zero lines, _GDBN__ will not pause during output
6847no matter how long the output is. This is useful if output is to a file
6848or to an editor buffer.
6849@end table
6850
4eb4cf57 6851@node Numbers
70b88761
RP
6852@section Numbers
6853@cindex number representation
6854@cindex entering numbers
1041a570 6855
70b88761
RP
6856You can always enter numbers in octal, decimal, or hexadecimal in _GDBN__ by
6857the usual conventions: octal numbers begin with @samp{0}, decimal
6858numbers end with @samp{.}, and hexadecimal numbers begin with @samp{0x}.
6859Numbers that begin with none of these are, by default, entered in base
686010; likewise, the default display for numbers---when no particular
6861format is specified---is base 10. You can change the default base for
6862both input and output with the @code{set radix} command.
6863
6864@table @code
6865@kindex set radix
6866@item set radix @var{base}
6867Set the default base for numeric input and display. Supported choices
c2bbbb22 6868for @var{base} are decimal 2, 8, 10, 16. @var{base} must itself be
70b88761
RP
6869specified either unambiguously or using the current default radix; for
6870example, any of
6871
6872@example
c2bbbb22 6873set radix 1010
70b88761
RP
6874set radix 012
6875set radix 10.
6876set radix 0xa
6877@end example
6878
6879@noindent
6880will set the base to decimal. On the other hand, @samp{set radix 10}
6881will leave the radix unchanged no matter what it was.
6882
6883@kindex show radix
6884@item show radix
6885Display the current default base for numeric input and display.
70b88761
RP
6886@end table
6887
4eb4cf57 6888@node Messages/Warnings
70b88761 6889@section Optional Warnings and Messages
1041a570 6890
70b88761
RP
6891By default, _GDBN__ is silent about its inner workings. If you are running
6892on a slow machine, you may want to use the @code{set verbose} command.
6893It will make _GDBN__ tell you when it does a lengthy internal operation, so
1041a570 6894you will not think it has crashed.
70b88761 6895
1041a570 6896Currently, the messages controlled by @code{set verbose} are those
d48da190
RP
6897which announce that the symbol table for a source file is being read;
6898see @code{symbol-file} in @ref{Files, ,Commands to Specify Files}.
70b88761
RP
6899
6900@table @code
6901@kindex set verbose
6902@item set verbose on
6903Enables _GDBN__'s output of certain informational messages.
6904
6905@item set verbose off
6906Disables _GDBN__'s output of certain informational messages.
6907
6908@kindex show verbose
6909@item show verbose
6910Displays whether @code{set verbose} is on or off.
6911@end table
6912
b80282d5
RP
6913By default, if _GDBN__ encounters bugs in the symbol table of an object
6914file, it is silent; but if you are debugging a compiler, you may find
1041a570 6915this information useful (@pxref{Symbol Errors, ,Errors Reading Symbol Files}).
70b88761
RP
6916
6917@table @code
6918@kindex set complaints
6919@item set complaints @var{limit}
6920Permits _GDBN__ to output @var{limit} complaints about each type of unusual
6921symbols before becoming silent about the problem. Set @var{limit} to
6922zero to suppress all complaints; set it to a large number to prevent
6923complaints from being suppressed.
6924
6925@kindex show complaints
6926@item show complaints
6927Displays how many symbol complaints _GDBN__ is permitted to produce.
6928@end table
6929
b21b18e1 6930By default, _GDBN__ is cautious, and asks what sometimes seems to be a
70b88761
RP
6931lot of stupid questions to confirm certain commands. For example, if
6932you try to run a program which is already running:
1041a570 6933
70b88761
RP
6934@example
6935(_GDBP__) run
6936The program being debugged has been started already.
e251e767 6937Start it from the beginning? (y or n)
70b88761
RP
6938@end example
6939
29a2b744 6940If you are willing to unflinchingly face the consequences of your own
70b88761
RP
6941commands, you can disable this ``feature'':
6942
6943@table @code
6944@kindex set confirm
6945@cindex flinching
6946@cindex confirmation
6947@cindex stupid questions
6948@item set confirm off
6949Disables confirmation requests.
6950
6951@item set confirm on
6952Enables confirmation requests (the default).
6953
6954@item show confirm
6955@kindex show confirm
6956Displays state of confirmation requests.
6957@end table
6958
29a2b744 6959@c FIXME this does not really belong here. But where *does* it belong?
b80282d5
RP
6960@cindex reloading symbols
6961Some systems allow individual object files that make up your program to
6962be replaced without stopping and restarting your program.
6963_if__(_VXWORKS__)
6964For example, in VxWorks you can simply recompile a defective object file
6965and keep on running.
6966_fi__(_VXWORKS__)
29a2b744 6967If you are running on one of these systems, you can allow _GDBN__ to
1041a570
RP
6968reload the symbols for automatically relinked modules:
6969
b80282d5
RP
6970@table @code
6971@kindex set symbol-reloading
6972@item set symbol-reloading on
6973Replace symbol definitions for the corresponding source file when an
6974object file with a particular name is seen again.
6975
6976@item set symbol-reloading off
1041a570 6977Do not replace symbol definitions when re-encountering object files of
29a2b744 6978the same name. This is the default state; if you are not running on a
b80282d5
RP
6979system that permits automatically relinking modules, you should leave
6980@code{symbol-reloading} off, since otherwise _GDBN__ may discard symbols
6981when linking large programs, that may contain several modules (from
6982different directories or libraries) with the same name.
6983
6984@item show symbol-reloading
6985Show the current @code{on} or @code{off} setting.
6986@end table
6987
4eb4cf57 6988@node Sequences
70b88761
RP
6989@chapter Canned Sequences of Commands
6990
29a2b744 6991Aside from breakpoint commands (@pxref{Break Commands, ,Breakpoint
1041a570
RP
6992Command Lists}), _GDBN__ provides two ways to store sequences of commands
6993for execution as a unit: user-defined commands and command files.
70b88761
RP
6994
6995@menu
b80282d5 6996* Define:: User-Defined Commands
35a15d60 6997* Hooks:: User-Defined Command Hooks
b80282d5
RP
6998* Command Files:: Command Files
6999* Output:: Commands for Controlled Output
70b88761
RP
7000@end menu
7001
4eb4cf57 7002@node Define
70b88761
RP
7003@section User-Defined Commands
7004
7005@cindex user-defined command
7006A @dfn{user-defined command} is a sequence of _GDBN__ commands to which you
7007assign a new name as a command. This is done with the @code{define}
7008command.
7009
7010@table @code
7011@item define @var{commandname}
7012@kindex define
7013Define a command named @var{commandname}. If there is already a command
7014by that name, you are asked to confirm that you want to redefine it.
7015
7016The definition of the command is made up of other _GDBN__ command lines,
7017which are given following the @code{define} command. The end of these
7018commands is marked by a line containing @code{end}.
7019
7020@item document @var{commandname}
7021@kindex document
7022Give documentation to the user-defined command @var{commandname}. The
7023command @var{commandname} must already be defined. This command reads
7024lines of documentation just as @code{define} reads the lines of the
7025command definition, ending with @code{end}. After the @code{document}
7026command is finished, @code{help} on command @var{commandname} will print
7027the documentation you have specified.
7028
7029You may use the @code{document} command again to change the
7030documentation of a command. Redefining the command with @code{define}
7031does not change the documentation.
7032
7033@item help user-defined
7034@kindex help user-defined
7035List all user-defined commands, with the first line of the documentation
7036(if any) for each.
7037
4768ba62
JG
7038@item show user
7039@itemx show user @var{commandname}
7040@kindex show user
70b88761
RP
7041Display the _GDBN__ commands used to define @var{commandname} (but not its
7042documentation). If no @var{commandname} is given, display the
7043definitions for all user-defined commands.
7044@end table
7045
7046User-defined commands do not take arguments. When they are executed, the
7047commands of the definition are not printed. An error in any command
7048stops execution of the user-defined command.
7049
7050Commands that would ask for confirmation if used interactively proceed
7051without asking when used inside a user-defined command. Many _GDBN__ commands
7052that normally print messages to say what they are doing omit the messages
7053when used in a user-defined command.
7054
35a15d60
JG
7055@node Hooks
7056@section User-Defined Command Hooks
7057@cindex command files
7058
7059You may define @emph{hooks}, which are a special kind of user-defined
7060command. Whenever you run the command @samp{foo}, if the user-defined
7061command @samp{hook-foo} exists, it is executed (with no arguments)
7062before that command.
7063
7064In addition, a pseudo-command, @samp{stop} exists. Hooking this command
7065will cause your hook to be executed every time execution stops in the
7066inferior program, before breakpoint commands are run, displays are
7067printed, or the stack frame is printed.
7068
7069For example, to cause @code{SIGALRM} signals to be ignored while
7070single-stepping, but cause them to be resumed during normal execution,
7071you could do:
7072
7073@example
7074define hook-stop
7075handle SIGALRM nopass
7076end
7077
7078define hook-run
7079handle SIGALRM pass
7080end
7081
7082define hook-continue
7083handle SIGLARM pass
7084end
7085@end example
7086
7087Any single-word command in GDB can be hooked. Aliases for other commands
7088cannot be hooked (you should hook the basic command name, e.g. @code{backtrace}
7089rather than @code{bt}). If an error occurs during the execution of your
7090hook, execution of GDB commands stops and you are returned to the GDB
7091prompt (before the command that you actually typed had a chance to run).
7092
7093If you try to define a hook which doesn't match any known command, you
7094will get a warning from the @code{define} command.
7095
4eb4cf57 7096@node Command Files
70b88761
RP
7097@section Command Files
7098
7099@cindex command files
7100A command file for _GDBN__ is a file of lines that are _GDBN__ commands. Comments
7101(lines starting with @kbd{#}) may also be included. An empty line in a
7102command file does nothing; it does not mean to repeat the last command, as
7103it would from the terminal.
7104
7105@cindex init file
7106@cindex @file{_GDBINIT__}
7107When you start _GDBN__, it automatically executes commands from its
1041a570
RP
7108@dfn{init files}. These are files named @file{_GDBINIT__}. _GDBN__ reads
7109the init file (if any) in your home directory and then the init file
7110(if any) in the current working directory. (The init files are not
7111executed if you use the @samp{-nx} option; @pxref{Mode Options,
7112,Choosing Modes}.) You can also request the execution of a command
7113file with the @code{source} command:
70b88761
RP
7114
7115@table @code
7116@item source @var{filename}
7117@kindex source
7118Execute the command file @var{filename}.
7119@end table
7120
7121The lines in a command file are executed sequentially. They are not
7122printed as they are executed. An error in any command terminates execution
7123of the command file.
7124
7125Commands that would ask for confirmation if used interactively proceed
7126without asking when used in a command file. Many _GDBN__ commands that
7127normally print messages to say what they are doing omit the messages
7128when called from command files.
7129
4eb4cf57 7130@node Output
70b88761
RP
7131@section Commands for Controlled Output
7132
7133During the execution of a command file or a user-defined command, normal
7134_GDBN__ output is suppressed; the only output that appears is what is
7135explicitly printed by the commands in the definition. This section
7136describes three commands useful for generating exactly the output you
7137want.
7138
7139@table @code
7140@item echo @var{text}
7141@kindex echo
29a2b744
RP
7142@c I do not consider backslash-space a standard C escape sequence
7143@c because it is not in ANSI.
1041a570
RP
7144Print @var{text}. Nonprinting characters can be included in
7145@var{text} using C escape sequences, such as @samp{\n} to print a
7146newline. @strong{No newline will be printed unless you specify one.}
7147In addition to the standard C escape sequences, a backslash followed
7148by a space stands for a space. This is useful for outputting a
7149string with spaces at the beginning or the end, since leading and
7150trailing spaces are otherwise trimmed from all arguments.
7151To print @samp{@w{ }and foo =@w{ }}, use the command
7152@samp{echo \@w{ }and foo = \@w{ }}.
70b88761
RP
7153
7154A backslash at the end of @var{text} can be used, as in C, to continue
7155the command onto subsequent lines. For example,
7156
7157@example
7158echo This is some text\n\
7159which is continued\n\
7160onto several lines.\n
7161@end example
7162
7163produces the same output as
7164
7165@example
7166echo This is some text\n
7167echo which is continued\n
7168echo onto several lines.\n
7169@end example
7170
7171@item output @var{expression}
7172@kindex output
7173Print the value of @var{expression} and nothing but that value: no
7174newlines, no @samp{$@var{nn} = }. The value is not entered in the
1041a570 7175value history either. @xref{Expressions, ,Expressions}, for more information on
e251e767 7176expressions.
70b88761
RP
7177
7178@item output/@var{fmt} @var{expression}
7179Print the value of @var{expression} in format @var{fmt}. You can use
7180the same formats as for @code{print}; @pxref{Output formats}, for more
7181information.
7182
7183@item printf @var{string}, @var{expressions}@dots{}
7184@kindex printf
7185Print the values of the @var{expressions} under the control of
7186@var{string}. The @var{expressions} are separated by commas and may
7187be either numbers or pointers. Their values are printed as specified
29a2b744 7188by @var{string}, exactly as if your program were to execute
70b88761
RP
7189
7190@example
7191printf (@var{string}, @var{expressions}@dots{});
7192@end example
7193
7194For example, you can print two values in hex like this:
7195
0fd24984 7196@smallexample
70b88761 7197printf "foo, bar-foo = 0x%x, 0x%x\n", foo, bar-foo
0fd24984 7198@end smallexample
70b88761
RP
7199
7200The only backslash-escape sequences that you can use in the format
7201string are the simple ones that consist of backslash followed by a
7202letter.
7203@end table
7204
4eb4cf57
RP
7205_if__(!_DOSHOST__)
7206@node Emacs
70b88761
RP
7207@chapter Using _GDBN__ under GNU Emacs
7208
7209@cindex emacs
7210A special interface allows you to use GNU Emacs to view (and
7211edit) the source files for the program you are debugging with
7212_GDBN__.
7213
7214To use this interface, use the command @kbd{M-x gdb} in Emacs. Give the
7215executable file you want to debug as an argument. This command starts
7216_GDBN__ as a subprocess of Emacs, with input and output through a newly
7217created Emacs buffer.
7218
7219Using _GDBN__ under Emacs is just like using _GDBN__ normally except for two
7220things:
7221
7222@itemize @bullet
7223@item
e251e767 7224All ``terminal'' input and output goes through the Emacs buffer.
70b88761
RP
7225@end itemize
7226
7227This applies both to _GDBN__ commands and their output, and to the input
7228and output done by the program you are debugging.
7229
7230This is useful because it means that you can copy the text of previous
7231commands and input them again; you can even use parts of the output
7232in this way.
7233
3d3ab540
RP
7234All the facilities of Emacs' Shell mode are available for interacting
7235with your program. In particular, you can send signals the usual
7236way---for example, @kbd{C-c C-c} for an interrupt, @kbd{C-c C-z} for a
7237stop.
70b88761
RP
7238
7239@itemize @bullet
7240@item
e251e767 7241_GDBN__ displays source code through Emacs.
70b88761
RP
7242@end itemize
7243
7244Each time _GDBN__ displays a stack frame, Emacs automatically finds the
7245source file for that frame and puts an arrow (_0__@samp{=>}_1__) at the
7246left margin of the current line. Emacs uses a separate buffer for
7247source display, and splits the window to show both your _GDBN__ session
7248and the source.
7249
7250Explicit _GDBN__ @code{list} or search commands still produce output as
7251usual, but you probably will have no reason to use them.
7252
7253@quotation
7254@emph{Warning:} If the directory where your program resides is not your
7255current directory, it can be easy to confuse Emacs about the location of
7256the source files, in which case the auxiliary display buffer will not
7257appear to show your source. _GDBN__ can find programs by searching your
7258environment's @code{PATH} variable, so the _GDBN__ input and output
29a2b744 7259session will proceed normally; but Emacs does not get enough information
70b88761
RP
7260back from _GDBN__ to locate the source files in this situation. To
7261avoid this problem, either start _GDBN__ mode from the directory where
7262your program resides, or specify a full path name when prompted for the
7263@kbd{M-x gdb} argument.
7264
7265A similar confusion can result if you use the _GDBN__ @code{file} command to
7266switch to debugging a program in some other location, from an existing
7267_GDBN__ buffer in Emacs.
7268@end quotation
7269
7270By default, @kbd{M-x gdb} calls the program called @file{gdb}. If
7271you need to call _GDBN__ by a different name (for example, if you keep
7272several configurations around, with different names) you can set the
7273Emacs variable @code{gdb-command-name}; for example,
1041a570 7274
70b88761
RP
7275@example
7276(setq gdb-command-name "mygdb")
7277@end example
1041a570 7278
70b88761
RP
7279@noindent
7280(preceded by @kbd{ESC ESC}, or typed in the @code{*scratch*} buffer, or
7281in your @file{.emacs} file) will make Emacs call the program named
7282``@code{mygdb}'' instead.
7283
7284In the _GDBN__ I/O buffer, you can use these special Emacs commands in
7285addition to the standard Shell mode commands:
7286
7287@table @kbd
7288@item C-h m
7289Describe the features of Emacs' _GDBN__ Mode.
7290
7291@item M-s
7292Execute to another source line, like the _GDBN__ @code{step} command; also
7293update the display window to show the current file and location.
7294
7295@item M-n
7296Execute to next source line in this function, skipping all function
7297calls, like the _GDBN__ @code{next} command. Then update the display window
7298to show the current file and location.
7299
7300@item M-i
7301Execute one instruction, like the _GDBN__ @code{stepi} command; update
7302display window accordingly.
7303
7304@item M-x gdb-nexti
7305Execute to next instruction, using the _GDBN__ @code{nexti} command; update
7306display window accordingly.
7307
7308@item C-c C-f
7309Execute until exit from the selected stack frame, like the _GDBN__
7310@code{finish} command.
7311
7312@item M-c
29a2b744 7313Continue execution of your program, like the _GDBN__ @code{continue}
1041a570 7314command.
203eea5d
RP
7315
7316@emph{Warning:} In Emacs v19, this command is @kbd{C-c C-p}.
70b88761
RP
7317
7318@item M-u
7319Go up the number of frames indicated by the numeric argument
7320(@pxref{Arguments, , Numeric Arguments, emacs, The GNU Emacs Manual}),
1041a570 7321like the _GDBN__ @code{up} command.
203eea5d 7322
1041a570 7323@emph{Warning:} In Emacs v19, this command is @kbd{C-c C-u}.
70b88761
RP
7324
7325@item M-d
7326Go down the number of frames indicated by the numeric argument, like the
1041a570 7327_GDBN__ @code{down} command.
203eea5d
RP
7328
7329@emph{Warning:} In Emacs v19, this command is @kbd{C-c C-d}.
70b88761
RP
7330
7331@item C-x &
7332Read the number where the cursor is positioned, and insert it at the end
7333of the _GDBN__ I/O buffer. For example, if you wish to disassemble code
7334around an address that was displayed earlier, type @kbd{disassemble};
7335then move the cursor to the address display, and pick up the
e251e767 7336argument for @code{disassemble} by typing @kbd{C-x &}.
70b88761
RP
7337
7338You can customize this further on the fly by defining elements of the list
7339@code{gdb-print-command}; once it is defined, you can format or
7340otherwise process numbers picked up by @kbd{C-x &} before they are
c2bbbb22 7341inserted. A numeric argument to @kbd{C-x &} will both indicate that you
70b88761
RP
7342wish special formatting, and act as an index to pick an element of the
7343list. If the list element is a string, the number to be inserted is
7344formatted using the Emacs function @code{format}; otherwise the number
7345is passed as an argument to the corresponding list element.
70b88761
RP
7346@end table
7347
7348In any source file, the Emacs command @kbd{C-x SPC} (@code{gdb-break})
7349tells _GDBN__ to set a breakpoint on the source line point is on.
7350
7351If you accidentally delete the source-display buffer, an easy way to get
7352it back is to type the command @code{f} in the _GDBN__ buffer, to
7353request a frame display; when you run under Emacs, this will recreate
7354the source buffer if necessary to show you the context of the current
7355frame.
7356
7357The source files displayed in Emacs are in ordinary Emacs buffers
7358which are visiting the source files in the usual way. You can edit
7359the files with these buffers if you wish; but keep in mind that _GDBN__
7360communicates with Emacs in terms of line numbers. If you add or
7361delete lines from the text, the line numbers that _GDBN__ knows will cease
7362to correspond properly to the code.
7363
7364@c The following dropped because Epoch is nonstandard. Reactivate
7365@c if/when v19 does something similar. [email protected] 19dec1990
7366@ignore
e251e767 7367@kindex emacs epoch environment
70b88761
RP
7368@kindex epoch
7369@kindex inspect
7370
7371Version 18 of Emacs has a built-in window system called the @code{epoch}
7372environment. Users of this environment can use a new command,
7373@code{inspect} which performs identically to @code{print} except that
7374each value is printed in its own window.
7375@end ignore
4eb4cf57 7376_fi__(!_DOSHOST__)
70b88761 7377
6ca72cc6 7378_if__(_LUCID__)
4eb4cf57 7379@node Energize
6ca72cc6
RP
7380@chapter Using _GDBN__ with Energize
7381
7382@cindex Energize
7383The Energize Programming System is an integrated development environment
7384that includes a point-and-click interface to many programming tools.
7385When you use _GDBN__ in this environment, you can use the standard
7386Energize graphical interface to drive _GDBN__; you can also, if you
7387choose, type _GDBN__ commands as usual in a debugging window. Even if
7388you use the graphical interface, the debugging window (which uses Emacs,
7389and resembles the standard Emacs interface to _GDBN__) displays the
7390equivalent commands, so that the history of your debugging session is
7391properly reflected.
7392
7393When Energize starts up a _GDBN__ session, it uses one of the
7394command-line options @samp{-energize} or @samp{-cadillac} (``cadillac''
7395is the name of the communications protocol used by the Energize system).
7396This option makes _GDBN__ run as one of the tools in the Energize Tool
7397Set: it sends all output to the Energize kernel, and accept input from
7398it as well.
7399
7400See the user manual for the Energize Programming System for
7401information on how to use the Energize graphical interface and the other
7402development tools that Energize integrates with _GDBN__.
7403
6ca72cc6 7404_fi__(_LUCID__)
4eb4cf57
RP
7405
7406@node _GDBN__ Bugs
70b88761
RP
7407@chapter Reporting Bugs in _GDBN__
7408@cindex Bugs in _GDBN__
7409@cindex Reporting Bugs in _GDBN__
7410
7411Your bug reports play an essential role in making _GDBN__ reliable.
7412
7413Reporting a bug may help you by bringing a solution to your problem, or it
7414may not. But in any case the principal function of a bug report is to help
7415the entire community by making the next version of _GDBN__ work better. Bug
7416reports are your contribution to the maintenance of _GDBN__.
7417
7418In order for a bug report to serve its purpose, you must include the
7419information that enables us to fix the bug.
7420
7421@menu
b80282d5
RP
7422* Bug Criteria:: Have You Found a Bug?
7423* Bug Reporting:: How to Report Bugs
70b88761
RP
7424@end menu
7425
4eb4cf57 7426@node Bug Criteria
70b88761
RP
7427@section Have You Found a Bug?
7428@cindex Bug Criteria
7429
7430If you are not sure whether you have found a bug, here are some guidelines:
7431
7432@itemize @bullet
7433@item
0f153e74
RP
7434@cindex fatal signal
7435@cindex core dump
70b88761
RP
7436If the debugger gets a fatal signal, for any input whatever, that is a
7437_GDBN__ bug. Reliable debuggers never crash.
7438
7439@item
0f153e74 7440@cindex error on valid input
70b88761
RP
7441If _GDBN__ produces an error message for valid input, that is a bug.
7442
7443@item
7444@cindex Invalid Input
7445If _GDBN__ does not produce an error message for invalid input,
7446that is a bug. However, you should note that your idea of
7447``invalid input'' might be our idea of ``an extension'' or ``support
7448for traditional practice''.
7449
7450@item
7451If you are an experienced user of debugging tools, your suggestions
7452for improvement of _GDBN__ are welcome in any case.
7453@end itemize
7454
4eb4cf57 7455@node Bug Reporting
70b88761 7456@section How to Report Bugs
0f153e74
RP
7457@cindex bug reports
7458@cindex _GDBN__ bugs, reporting
70b88761
RP
7459
7460A number of companies and individuals offer support for GNU products.
7461If you obtained _GDBN__ from a support organization, we recommend you
e251e767 7462contact that organization first.
70b88761
RP
7463
7464Contact information for many support companies and individuals is
7465available in the file @file{etc/SERVICE} in the GNU Emacs distribution.
7466
7467In any event, we also recommend that you send bug reports for _GDBN__ to one
7468of these addresses:
7469
7470@example
7471bug-gdb@@prep.ai.mit.edu
7472@{ucbvax|mit-eddie|uunet@}!prep.ai.mit.edu!bug-gdb
7473@end example
7474
7475@strong{Do not send bug reports to @samp{info-gdb}, or to
7476@samp{help-gdb}, or to any newsgroups.} Most users of _GDBN__ do not want to
7477receive bug reports. Those that do, have arranged to receive @samp{bug-gdb}.
7478
3d3ab540
RP
7479The mailing list @samp{bug-gdb} has a newsgroup @samp{gnu.gdb.bug} which
7480serves as a repeater. The mailing list and the newsgroup carry exactly
7481the same messages. Often people think of posting bug reports to the
7482newsgroup instead of mailing them. This appears to work, but it has one
7483problem which can be crucial: a newsgroup posting often lacks a mail
7484path back to the sender. Thus, if we need to ask for more information,
7485we may be unable to reach you. For this reason, it is better to send
7486bug reports to the mailing list.
70b88761
RP
7487
7488As a last resort, send bug reports on paper to:
7489
7490@example
7491GNU Debugger Bugs
3d3ab540 7492Free Software Foundation
70b88761
RP
7493545 Tech Square
7494Cambridge, MA 02139
7495@end example
7496
7497The fundamental principle of reporting bugs usefully is this:
7498@strong{report all the facts}. If you are not sure whether to state a
7499fact or leave it out, state it!
7500
7501Often people omit facts because they think they know what causes the
29a2b744 7502problem and assume that some details do not matter. Thus, you might
70b88761 7503assume that the name of the variable you use in an example does not matter.
29a2b744 7504Well, probably it does not, but one cannot be sure. Perhaps the bug is a
70b88761
RP
7505stray memory reference which happens to fetch from the location where that
7506name is stored in memory; perhaps, if the name were different, the contents
7507of that location would fool the debugger into doing the right thing despite
7508the bug. Play it safe and give a specific, complete example. That is the
7509easiest thing for you to do, and the most helpful.
7510
7511Keep in mind that the purpose of a bug report is to enable us to fix
1041a570 7512the bug if it is new to us. It is not as important as what happens if
70b88761
RP
7513the bug is already known. Therefore, always write your bug reports on
7514the assumption that the bug has not been reported previously.
7515
7516Sometimes people give a few sketchy facts and ask, ``Does this ring a
7517bell?'' Those bug reports are useless, and we urge everyone to
7518@emph{refuse to respond to them} except to chide the sender to report
7519bugs properly.
7520
7521To enable us to fix the bug, you should include all these things:
7522
7523@itemize @bullet
7524@item
7525The version of _GDBN__. _GDBN__ announces it if you start with no
7526arguments; you can also print it at any time using @code{show version}.
7527
1041a570 7528Without this, we will not know whether there is any point in looking for
70b88761
RP
7529the bug in the current version of _GDBN__.
7530
7531@item
ddf21240
JG
7532The type of machine you are using, and the operating system name and
7533version number.
70b88761
RP
7534
7535@item
7536What compiler (and its version) was used to compile _GDBN__---e.g.
c7cb8acb 7537``_GCC__-2.0''.
70b88761 7538
ddf21240
JG
7539@item
7540What compiler (and its version) was used to compile the program you
c7cb8acb 7541are debugging---e.g. ``_GCC__-2.0''.
ddf21240 7542
70b88761
RP
7543@item
7544The command arguments you gave the compiler to compile your example and
7545observe the bug. For example, did you use @samp{-O}? To guarantee
1041a570 7546you will not omit something important, list them all. A copy of the
ddf21240 7547Makefile (or the output from make) is sufficient.
70b88761
RP
7548
7549If we were to try to guess the arguments, we would probably guess wrong
7550and then we might not encounter the bug.
7551
7552@item
ddf21240
JG
7553A complete input script, and all necessary source files, that will
7554reproduce the bug.
70b88761
RP
7555
7556@item
7557A description of what behavior you observe that you believe is
7558incorrect. For example, ``It gets a fatal signal.''
7559
7560Of course, if the bug is that _GDBN__ gets a fatal signal, then we will
7561certainly notice it. But if the bug is incorrect output, we might not
7562notice unless it is glaringly wrong. We are human, after all. You
7563might as well not give us a chance to make a mistake.
7564
7565Even if the problem you experience is a fatal signal, you should still
7566say so explicitly. Suppose something strange is going on, such as,
7567your copy of _GDBN__ is out of synch, or you have encountered a
7568bug in the C library on your system. (This has happened!) Your copy
7569might crash and ours would not. If you told us to expect a crash,
7570then when ours fails to crash, we would know that the bug was not
7571happening for us. If you had not told us to expect a crash, then we
7572would not be able to draw any conclusion from our observations.
7573
7574@item
7575If you wish to suggest changes to the _GDBN__ source, send us context
7576diffs. If you even discuss something in the _GDBN__ source, refer to
7577it by context, not by line number.
7578
1041a570 7579The line numbers in our development sources will not match those in your
70b88761 7580sources. Your line numbers would convey no useful information to us.
70b88761
RP
7581@end itemize
7582
7583Here are some things that are not necessary:
7584
7585@itemize @bullet
7586@item
7587A description of the envelope of the bug.
7588
7589Often people who encounter a bug spend a lot of time investigating
7590which changes to the input file will make the bug go away and which
7591changes will not affect it.
7592
7593This is often time consuming and not very useful, because the way we
7594will find the bug is by running a single example under the debugger
7595with breakpoints, not by pure deduction from a series of examples.
7596We recommend that you save your time for something else.
7597
7598Of course, if you can find a simpler example to report @emph{instead}
7599of the original one, that is a convenience for us. Errors in the
7600output will be easier to spot, running under the debugger will take
e251e767 7601less time, etc.
70b88761 7602
29a2b744 7603However, simplification is not vital; if you do not want to do this,
70b88761
RP
7604report the bug anyway and send us the entire test case you used.
7605
7606@item
7607A patch for the bug.
7608
29a2b744 7609A patch for the bug does help us if it is a good one. But do not omit
70b88761
RP
7610the necessary information, such as the test case, on the assumption that
7611a patch is all we need. We might see problems with your patch and decide
7612to fix the problem another way, or we might not understand it at all.
7613
7614Sometimes with a program as complicated as _GDBN__ it is very hard to
7615construct an example that will make the program follow a certain path
1041a570
RP
7616through the code. If you do not send us the example, we will not be able
7617to construct one, so we will not be able to verify that the bug is fixed.
70b88761 7618
29a2b744 7619And if we cannot understand what bug you are trying to fix, or why your
1041a570 7620patch should be an improvement, we will not install it. A test case will
70b88761
RP
7621help us to understand.
7622
7623@item
7624A guess about what the bug is or what it depends on.
7625
29a2b744 7626Such guesses are usually wrong. Even we cannot guess right about such
70b88761
RP
7627things without first using the debugger to find the facts.
7628@end itemize
7629
1041a570
RP
7630@c Note: no need to update nodes for rdl-apps.texi since it appears
7631@c *only* in the TeX version of the manual.
7632@c Note: eventually, make a cross reference to the readline Info nodes.
70b88761 7633@iftex
cacf5942
RP
7634@c appendices describing GNU readline. Distributed with readline code.
7635@include rluser.texinfo
7636@include inc-hist.texi
70b88761
RP
7637@end iftex
7638
4eb4cf57
RP
7639_if__(_GENERIC__||!_H8__)
7640@node Renamed Commands
70b88761
RP
7641@appendix Renamed Commands
7642
c7cb8acb 7643The following commands were renamed in GDB 4, in order to make the
70b88761
RP
7644command set as a whole more consistent and easier to use and remember:
7645
e251e767
RP
7646@kindex add-syms
7647@kindex delete environment
7648@kindex info copying
7649@kindex info convenience
7650@kindex info directories
7651@kindex info editing
7652@kindex info history
7653@kindex info targets
7654@kindex info values
7655@kindex info version
7656@kindex info warranty
7657@kindex set addressprint
7658@kindex set arrayprint
7659@kindex set prettyprint
7660@kindex set screen-height
7661@kindex set screen-width
7662@kindex set unionprint
7663@kindex set vtblprint
7664@kindex set demangle
7665@kindex set asm-demangle
7666@kindex set sevenbit-strings
7667@kindex set array-max
7668@kindex set caution
7669@kindex set history write
7670@kindex show addressprint
7671@kindex show arrayprint
7672@kindex show prettyprint
7673@kindex show screen-height
7674@kindex show screen-width
7675@kindex show unionprint
7676@kindex show vtblprint
7677@kindex show demangle
7678@kindex show asm-demangle
7679@kindex show sevenbit-strings
7680@kindex show array-max
7681@kindex show caution
7682@kindex show history write
7683@kindex unset
70b88761 7684
92b73793 7685@c TEXI2ROFF-KILL
70b88761 7686@ifinfo
92b73793 7687@c END TEXI2ROFF-KILL
cf496415
RP
7688@example
7689OLD COMMAND NEW COMMAND
92b73793 7690@c TEXI2ROFF-KILL
cf496415 7691--------------- -------------------------------
92b73793 7692@c END TEXI2ROFF-KILL
cf496415
RP
7693add-syms add-symbol-file
7694delete environment unset environment
7695info convenience show convenience
7696info copying show copying
e251e767 7697info directories show directories
cf496415
RP
7698info editing show commands
7699info history show values
7700info targets help target
7701info values show values
7702info version show version
7703info warranty show warranty
7704set/show addressprint set/show print address
7705set/show array-max set/show print elements
7706set/show arrayprint set/show print array
7707set/show asm-demangle set/show print asm-demangle
7708set/show caution set/show confirm
7709set/show demangle set/show print demangle
7710set/show history write set/show history save
7711set/show prettyprint set/show print pretty
7712set/show screen-height set/show height
7713set/show screen-width set/show width
7714set/show sevenbit-strings set/show print sevenbit-strings
7715set/show unionprint set/show print union
7716set/show vtblprint set/show print vtbl
7717
7718unset [No longer an alias for delete]
7719@end example
92b73793 7720@c TEXI2ROFF-KILL
70b88761
RP
7721@end ifinfo
7722
7723@tex
7724\vskip \parskip\vskip \baselineskip
7725\halign{\tt #\hfil &\qquad#&\tt #\hfil\cr
7726{\bf Old Command} &&{\bf New Command}\cr
7727add-syms &&add-symbol-file\cr
7728delete environment &&unset environment\cr
7729info convenience &&show convenience\cr
7730info copying &&show copying\cr
7731info directories &&show directories \cr
7732info editing &&show commands\cr
7733info history &&show values\cr
7734info targets &&help target\cr
7735info values &&show values\cr
7736info version &&show version\cr
7737info warranty &&show warranty\cr
7738set{\rm / }show addressprint &&set{\rm / }show print address\cr
7739set{\rm / }show array-max &&set{\rm / }show print elements\cr
7740set{\rm / }show arrayprint &&set{\rm / }show print array\cr
7741set{\rm / }show asm-demangle &&set{\rm / }show print asm-demangle\cr
7742set{\rm / }show caution &&set{\rm / }show confirm\cr
7743set{\rm / }show demangle &&set{\rm / }show print demangle\cr
7744set{\rm / }show history write &&set{\rm / }show history save\cr
7745set{\rm / }show prettyprint &&set{\rm / }show print pretty\cr
7746set{\rm / }show screen-height &&set{\rm / }show height\cr
7747set{\rm / }show screen-width &&set{\rm / }show width\cr
7748set{\rm / }show sevenbit-strings &&set{\rm / }show print sevenbit-strings\cr
7749set{\rm / }show unionprint &&set{\rm / }show print union\cr
7750set{\rm / }show vtblprint &&set{\rm / }show print vtbl\cr
7751\cr
7752unset &&\rm(No longer an alias for delete)\cr
7753}
7754@end tex
92b73793 7755@c END TEXI2ROFF-KILL
4eb4cf57 7756_fi__(_GENERIC__||!_H8__)
70b88761 7757
0f153e74 7758_if__(!_PRECONFIGURED__)
4eb4cf57 7759@node Formatting Documentation
77b46d13
JG
7760@appendix Formatting the Documentation
7761
7762@cindex GDB reference card
7763@cindex reference card
7764The GDB 4 release includes an already-formatted reference card, ready
b1385986 7765for printing with PostScript or GhostScript, in the @file{gdb}
77b46d13 7766subdirectory of the main source directory---in
b1385986
RP
7767@file{gdb-_GDB_VN__/gdb/refcard.ps} of the version _GDB_VN__ release.
7768If you can use PostScript or GhostScript with your printer, you can
7769print the reference card immediately with @file{refcard.ps}.
77b46d13
JG
7770
7771The release also includes the source for the reference card. You
7772can format it, using @TeX{}, by typing:
7773
7774@example
7775make refcard.dvi
7776@end example
7777
7778The GDB reference card is designed to print in landscape mode on US
7779``letter'' size paper; that is, on a sheet 11 inches wide by 8.5 inches
7780high. You will need to specify this form of printing as an option to
7781your @sc{dvi} output program.
7782
7783@cindex documentation
7784
7785All the documentation for GDB comes as part of the machine-readable
7786distribution. The documentation is written in Texinfo format, which is
7787a documentation system that uses a single source file to produce both
7788on-line information and a printed manual. You can use one of the Info
7789formatting commands to create the on-line version of the documentation
7790and @TeX{} (or @code{texi2roff}) to typeset the printed version.
7791
7792GDB includes an already formatted copy of the on-line Info version of
7793this manual in the @file{gdb} subdirectory. The main Info file is
7794@file{gdb-@var{version-number}/gdb/gdb.info}, and it refers to
a89f94c2
RP
7795subordinate files matching @samp{gdb.info*} in the same directory. If
7796necessary, you can print out these files, or read them with any editor;
7797but they are easier to read using the @code{info} subsystem in GNU Emacs
7798or the standalone @code{info} program, available as part of the GNU
7799Texinfo distribution.
77b46d13
JG
7800
7801If you want to format these Info files yourself, you need one of the
7802Info formatting programs, such as @code{texinfo-format-buffer} or
7803@code{makeinfo}.
7804
7805If you have @code{makeinfo} installed, and are in the top level GDB
7806source directory (@file{gdb-_GDB_VN__}, in the case of version _GDB_VN__), you can
7807make the Info file by typing:
7808
7809@example
7810cd gdb
7811make gdb.info
7812@end example
7813
7814If you want to typeset and print copies of this manual, you need
7815@TeX{}, a printing program such as @code{lpr}, and @file{texinfo.tex},
7816the Texinfo definitions file.
7817
7818@TeX{} is typesetting program; it does not print files directly, but
7819produces output files called @sc{dvi} files. To print a typeset
7820document, you need a program to print @sc{dvi} files. If your system
7821has @TeX{} installed, chances are it has such a program. The precise
7822command to use depends on your system; @kbd{lpr -d} is common; another
7823is @kbd{dvips}. The @sc{dvi} print command may require a file name
7824without any extension or a @samp{.dvi} extension.
7825
7826@TeX{} also requires a macro definitions file called
7827@file{texinfo.tex}. This file tells @TeX{} how to typeset a document
7828written in Texinfo format. On its own, @TeX{} cannot read, much less
7829typeset a Texinfo file. @file{texinfo.tex} is distributed with GDB
7830and is located in the @file{gdb-@var{version-number}/texinfo}
7831directory.
7832
7833If you have @TeX{} and a @sc{dvi} printer program installed, you can
7834typeset and print this manual. First switch to the the @file{gdb}
7835subdirectory of the main source directory (for example, to
7836@file{gdb-_GDB_VN__/gdb}) and then type:
7837
7838@example
7839make gdb.dvi
7840@end example
7841
4eb4cf57 7842@node Installing GDB
c7cb8acb
RP
7843@appendix Installing GDB
7844@cindex configuring GDB
70b88761
RP
7845@cindex installation
7846
f672bb7f
RP
7847@iftex
7848@c irrelevant in info file; it's as current as the code it lives with.
7849@quotation
7850@emph{Warning:} These installation instructions are current as of
c7cb8acb
RP
7851GDB version _GDB_VN__. If you're installing a more recent release
7852of GDB, we may have improved the installation procedures since
f672bb7f
RP
7853printing this manual; see the @file{README} file included in your
7854release for the most recent instructions.
7855@end quotation
7856@end iftex
7857
c7cb8acb
RP
7858GDB comes with a @code{configure} script that automates the process
7859of preparing GDB for installation; you can then use @code{make} to
7860build the program.
b80282d5 7861
c7cb8acb 7862The GDB distribution includes all the source code you need for GDB in
1041a570
RP
7863a single directory, whose name is usually composed by appending the
7864version number to @samp{gdb}.
7865
c7cb8acb 7866For example, the GDB version _GDB_VN__ distribution is in the @file{gdb-_GDB_VN__}
1041a570 7867directory. That directory contains:
b80282d5 7868
3d3ab540 7869@table @code
c7637ea6 7870@item gdb-_GDB_VN__/configure @r{(and supporting files)}
c7cb8acb 7871script for configuring GDB and all its supporting libraries.
b80282d5 7872
3e0d0a27 7873@item gdb-_GDB_VN__/gdb
c7cb8acb 7874the source specific to GDB itself
3d3ab540 7875
3e0d0a27 7876@item gdb-_GDB_VN__/bfd
77b46d13 7877source for the Binary File Descriptor library
3d3ab540 7878
3e0d0a27 7879@item gdb-_GDB_VN__/include
b80282d5 7880GNU include files
3d3ab540 7881
3e0d0a27 7882@item gdb-_GDB_VN__/libiberty
3d3ab540
RP
7883source for the @samp{-liberty} free software library
7884
3214c51c
JG
7885@item gdb-_GDB_VN__/opcodes
7886source for the library of opcode tables and disassemblers
7887
3e0d0a27 7888@item gdb-_GDB_VN__/readline
b80282d5 7889source for the GNU command-line interface
77b46d13
JG
7890
7891@item gdb-_GDB_VN__/glob
7892source for the GNU filename pattern-matching subroutine
7893
7894@item gdb-_GDB_VN__/mmalloc
7895source for the GNU memory-mapped malloc package
3d3ab540 7896@end table
1041a570 7897
c7cb8acb 7898The simplest way to configure and build GDB is to run @code{configure}
1041a570
RP
7899from the @file{gdb-@var{version-number}} source directory, which in
7900this example is the @file{gdb-_GDB_VN__} directory.
7901
7902First switch to the @file{gdb-@var{version-number}} source directory
7903if you are not already in it; then run @code{configure}. Pass the
c7cb8acb 7904identifier for the platform on which GDB will run as an
1041a570
RP
7905argument.
7906
7907For example:
7908
7463aadd 7909@example
3e0d0a27 7910cd gdb-_GDB_VN__
3d3ab540 7911./configure @var{host}
7463aadd
RP
7912make
7913@end example
1041a570 7914
7463aadd 7915@noindent
1041a570 7916where @var{host} is an identifier such as @samp{sun4} or
c7cb8acb 7917@samp{decstation}, that identifies the platform where GDB will run.
1041a570 7918
38962738
RP
7919Running @samp{configure @var{host}} followed by @code{make} builds the
7920@file{bfd}, @file{readline}, @file{mmalloc}, and @file{libiberty}
7921libraries, then @code{gdb} itself. The configured source files, and the
7922binaries, are left in the corresponding source directories.
3d3ab540 7923
e251e767 7924@code{configure} is a Bourne-shell (@code{/bin/sh}) script; if your
29a2b744 7925system does not recognize this automatically when you run a different
1041a570
RP
7926shell, you may need to run @code{sh} on it explicitly:
7927
7928@example
7929sh configure @var{host}
7930@end example
e251e767 7931
f672bb7f
RP
7932If you run @code{configure} from a directory that contains source
7933directories for multiple libraries or programs, such as the
7934@file{gdb-_GDB_VN__} source directory for version _GDB_VN__, @code{configure}
7935creates configuration files for every directory level underneath (unless
98349959 7936you tell it not to, with the @samp{--norecursion} option).
f672bb7f
RP
7937
7938You can run the @code{configure} script from any of the
c7cb8acb 7939subordinate directories in the GDB distribution, if you only want to
1041a570
RP
7940configure that subdirectory; but be sure to specify a path to it.
7941
7942For example, with version _GDB_VN__, type the following to configure only
7943the @code{bfd} subdirectory:
7944
e251e767 7945@example
203eea5d 7946@group
e251e767
RP
7947cd gdb-_GDB_VN__/bfd
7948../configure @var{host}
203eea5d 7949@end group
e251e767
RP
7950@end example
7951
1041a570
RP
7952You can install @code{_GDBP__} anywhere; it has no hardwired paths.
7953However, you should make sure that the shell on your path (named by
7954the @samp{SHELL} environment variable) is publicly readable. Remember
c7cb8acb
RP
7955that GDB uses the shell to start your program---some systems refuse to
7956let GDB debug child processes whose programs are not readable.
3d3ab540
RP
7957
7958@menu
c7cb8acb 7959* Separate Objdir:: Compiling GDB in another directory
b80282d5
RP
7960* Config Names:: Specifying names for hosts and targets
7961* configure Options:: Summary of options for configure
3d3ab540
RP
7962@end menu
7963
4eb4cf57 7964@node Separate Objdir
c7cb8acb 7965@section Compiling GDB in Another Directory
1041a570 7966
c7cb8acb
RP
7967If you want to run GDB versions for several host or target machines,
7968you'll need a different @code{gdb} compiled for each combination of
1041a570 7969host and target. @code{configure} is designed to make this easy by
f672bb7f
RP
7970allowing you to generate each configuration in a separate subdirectory,
7971rather than in the source directory. If your @code{make} program
7972handles the @samp{VPATH} feature (GNU @code{make} does), running
c7cb8acb 7973@code{make} in each of these directories then builds the @code{gdb}
f672bb7f 7974program specified there.
b80282d5 7975
c7cb8acb 7976To build @code{gdb} in a separate directory, run @code{configure}
f672bb7f 7977with the @samp{--srcdir} option to specify where to find the source.
77b46d13
JG
7978(You'll also need to specify a path to find @code{configure}
7979itself from your working directory. If the path to @code{configure}
7980would be the same as the argument to @samp{--srcdir}, you can leave out
7981the @samp{--srcdir} option; it will be assumed.)
1041a570 7982
c7cb8acb 7983For example, with version _GDB_VN__, you can build GDB in a separate
f672bb7f 7984directory for a Sun 4 like this:
70b88761
RP
7985
7986@example
3d3ab540 7987@group
3e0d0a27 7988cd gdb-_GDB_VN__
f672bb7f
RP
7989mkdir ../gdb-sun4
7990cd ../gdb-sun4
77b46d13 7991../gdb-_GDB_VN__/configure sun4
70b88761 7992make
3d3ab540 7993@end group
70b88761
RP
7994@end example
7995
f672bb7f
RP
7996When @code{configure} builds a configuration using a remote source
7997directory, it creates a tree for the binaries with the same structure
7998(and using the same names) as the tree under the source directory. In
7999the example, you'd find the Sun 4 library @file{libiberty.a} in the
c7cb8acb 8000directory @file{gdb-sun4/libiberty}, and GDB itself in
f672bb7f 8001@file{gdb-sun4/gdb}.
1041a570 8002
38962738 8003One popular reason to build several GDB configurations in separate
c7cb8acb 8004directories is to configure GDB for cross-compiling (where GDB
f672bb7f
RP
8005runs on one machine---the host---while debugging programs that run on
8006another machine---the target). You specify a cross-debugging target by
8007giving the @samp{--target=@var{target}} option to @code{configure}.
c7637ea6 8008
1041a570 8009When you run @code{make} to build a program or library, you must run
f672bb7f
RP
8010it in a configured directory---whatever directory you were in when you
8011called @code{configure} (or one of its subdirectories).
c7637ea6
RP
8012
8013The @code{Makefile} generated by @code{configure} for each source
f672bb7f
RP
8014directory also runs recursively. If you type @code{make} in a source
8015directory such as @file{gdb-_GDB_VN__} (or in a separate configured
8016directory configured with @samp{--srcdir=@var{path}/gdb-_GDB_VN__}), you
c7cb8acb 8017will build all the required libraries, then build GDB.
3d3ab540 8018
f672bb7f
RP
8019When you have multiple hosts or targets configured in separate
8020directories, you can run @code{make} on them in parallel (for example,
8021if they are NFS-mounted on each of the hosts); they will not interfere
8022with each other.
3d3ab540 8023
4eb4cf57 8024@node Config Names
b80282d5
RP
8025@section Specifying Names for Hosts and Targets
8026
8027The specifications used for hosts and targets in the @code{configure}
8028script are based on a three-part naming scheme, but some short predefined
8029aliases are also supported. The full naming scheme encodes three pieces
e251e767 8030of information in the following pattern:
1041a570 8031
b80282d5
RP
8032@example
8033@var{architecture}-@var{vendor}-@var{os}
8034@end example
8035
8036For example, you can use the alias @code{sun4} as a @var{host} argument
5e3186ab 8037or in a @code{--target=@var{target}} option, but the equivalent full name
e251e767 8038is @samp{sparc-sun-sunos4}.
b80282d5 8039
c7cb8acb 8040The @code{configure} script accompanying GDB does not provide
b80282d5
RP
8041any query facility to list all supported host and target names or
8042aliases. @code{configure} calls the Bourne shell script
8043@code{config.sub} to map abbreviations to full names; you can read the
8044script, if you wish, or you can use it to test your guesses on
8045abbreviations---for example:
1041a570 8046
b1385986 8047@smallexample
b80282d5 8048% sh config.sub sun4
6a8cb0e7 8049sparc-sun-sunos411
b80282d5 8050% sh config.sub sun3
6a8cb0e7 8051m68k-sun-sunos411
b80282d5 8052% sh config.sub decstation
6a8cb0e7 8053mips-dec-ultrix42
b80282d5
RP
8054% sh config.sub hp300bsd
8055m68k-hp-bsd
8056% sh config.sub i386v
6a8cb0e7 8057i386-unknown-sysv
e94b4a2b 8058% sh config.sub i786v
6a8cb0e7 8059Invalid configuration `i786v': machine `i786v' not recognized
b1385986 8060@end smallexample
1041a570 8061
c7637ea6 8062@noindent
1041a570
RP
8063@code{config.sub} is also distributed in the GDB source
8064directory (@file{gdb-_GDB_VN__}, for version _GDB_VN__).
b80282d5 8065
4eb4cf57 8066@node configure Options
3d3ab540 8067@section @code{configure} Options
7463aadd 8068
d48da190
RP
8069Here is a summary of the @code{configure} options and arguments that
8070are most often useful for building _GDBN__. @code{configure} also has
8071several other options not listed here. @inforef{What Configure
8072Does,,configure.info}, for a full explanation of @code{configure}.
8073@c FIXME: Would this be more, or less, useful as an xref (ref to printed
8074@c manual in the printed manual, ref to info file only from the info file)?
7463aadd
RP
8075
8076@example
d48da190
RP
8077configure @r{[}--help@r{]}
8078 @r{[}--prefix=@var{dir}@r{]}
8079 @r{[}--srcdir=@var{path}@r{]}
f672bb7f
RP
8080 @r{[}--norecursion@r{]} @r{[}--rm@r{]}
8081 @r{[}--target=@var{target}@r{]} @var{host}
7463aadd 8082@end example
1041a570 8083
3d3ab540 8084@noindent
f672bb7f
RP
8085You may introduce options with a single @samp{-} rather than
8086@samp{--} if you prefer; but you may abbreviate option names if you use
8087@samp{--}.
70b88761
RP
8088
8089@table @code
d48da190
RP
8090@item --help
8091Display a quick summary of how to invoke @code{configure}.
8092
8093@item -prefix=@var{dir}
8094Configure the source to install programs and files under directory
8095@file{@var{dir}}.
8096
f672bb7f 8097@item --srcdir=@var{path}
6ca72cc6
RP
8098@strong{Warning: using this option requires GNU @code{make}, or another
8099@code{make} that implements the @code{VPATH} feature.}@*
f672bb7f 8100Use this option to make configurations in directories separate from the
c7cb8acb 8101GDB source directories. Among other things, you can use this to
f672bb7f
RP
8102build (or maintain) several configurations simultaneously, in separate
8103directories. @code{configure} writes configuration specific files in
8104the current directory, but arranges for them to use the source in the
8105directory @var{path}. @code{configure} will create directories under
8106the working directory in parallel to the source directories below
8107@var{path}.
8108
8109@item --norecursion
8110Configure only the directory level where @code{configure} is executed; do not
7463aadd
RP
8111propagate configuration to subdirectories.
8112
f672bb7f 8113@item --rm
b80282d5 8114Remove the configuration that the other arguments specify.
7463aadd 8115
29a2b744 8116@c This does not work (yet if ever). FIXME.
f672bb7f 8117@c @item --parse=@var{lang} @dots{}
c7cb8acb
RP
8118@c Configure the GDB expression parser to parse the listed languages.
8119@c @samp{all} configures GDB for all supported languages. To get a
d7b569d5 8120@c list of all supported languages, omit the argument. Without this
c7cb8acb 8121@c option, GDB is configured to parse all supported languages.
c2bbbb22 8122
f672bb7f 8123@item --target=@var{target}
c7cb8acb
RP
8124Configure GDB for cross-debugging programs running on the specified
8125@var{target}. Without this option, GDB is configured to debug
8126programs that run on the same machine (@var{host}) as GDB itself.
b80282d5
RP
8127
8128There is no convenient way to generate a list of all available targets.
7463aadd
RP
8129
8130@item @var{host} @dots{}
c7cb8acb 8131Configure GDB to run on the specified @var{host}.
b80282d5
RP
8132
8133There is no convenient way to generate a list of all available hosts.
70b88761
RP
8134@end table
8135
3d3ab540
RP
8136@noindent
8137@code{configure} accepts other options, for compatibility with
b80282d5 8138configuring other GNU tools recursively; but these are the only
c7cb8acb 8139options that affect GDB or its supporting libraries.
0f153e74 8140_fi__(!_PRECONFIGURED__)
3d3ab540 8141
0f153e74 8142_if__(!_AGGLOMERATION__)
4eb4cf57 8143@node Copying
70b88761 8144@unnumbered GNU GENERAL PUBLIC LICENSE
7463aadd 8145@center Version 2, June 1991
70b88761
RP
8146
8147@display
7463aadd 8148Copyright @copyright{} 1989, 1991 Free Software Foundation, Inc.
70b88761
RP
8149675 Mass Ave, Cambridge, MA 02139, USA
8150
8151Everyone is permitted to copy and distribute verbatim copies
8152of this license document, but changing it is not allowed.
8153@end display
8154
8155@unnumberedsec Preamble
8156
7463aadd
RP
8157 The licenses for most software are designed to take away your
8158freedom to share and change it. By contrast, the GNU General Public
70b88761 8159License is intended to guarantee your freedom to share and change free
7463aadd
RP
8160software---to make sure the software is free for all its users. This
8161General Public License applies to most of the Free Software
8162Foundation's software and to any other program whose authors commit to
8163using it. (Some other Free Software Foundation software is covered by
8164the GNU Library General Public License instead.) You can apply it to
8165your programs, too.
70b88761
RP
8166
8167 When we speak of free software, we are referring to freedom, not
7463aadd
RP
8168price. Our General Public Licenses are designed to make sure that you
8169have the freedom to distribute copies of free software (and charge for
8170this service if you wish), that you receive source code or can get it
8171if you want it, that you can change the software or use pieces of it
8172in new free programs; and that you know you can do these things.
70b88761
RP
8173
8174 To protect your rights, we need to make restrictions that forbid
8175anyone to deny you these rights or to ask you to surrender the rights.
8176These restrictions translate to certain responsibilities for you if you
8177distribute copies of the software, or if you modify it.
8178
7463aadd 8179 For example, if you distribute copies of such a program, whether
70b88761
RP
8180gratis or for a fee, you must give the recipients all the rights that
8181you have. You must make sure that they, too, receive or can get the
7463aadd
RP
8182source code. And you must show them these terms so they know their
8183rights.
70b88761
RP
8184
8185 We protect your rights with two steps: (1) copyright the software, and
8186(2) offer you this license which gives you legal permission to copy,
8187distribute and/or modify the software.
8188
8189 Also, for each author's protection and ours, we want to make certain
8190that everyone understands that there is no warranty for this free
8191software. If the software is modified by someone else and passed on, we
8192want its recipients to know that what they have is not the original, so
8193that any problems introduced by others will not reflect on the original
8194authors' reputations.
8195
7463aadd
RP
8196 Finally, any free program is threatened constantly by software
8197patents. We wish to avoid the danger that redistributors of a free
8198program will individually obtain patent licenses, in effect making the
8199program proprietary. To prevent this, we have made it clear that any
8200patent must be licensed for everyone's free use or not licensed at all.
8201
70b88761
RP
8202 The precise terms and conditions for copying, distribution and
8203modification follow.
8204
8205@iftex
7463aadd 8206@unnumberedsec TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
70b88761
RP
8207@end iftex
8208@ifinfo
7463aadd 8209@center TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
70b88761
RP
8210@end ifinfo
8211
8212@enumerate
8213@item
7463aadd
RP
8214This License applies to any program or other work which contains
8215a notice placed by the copyright holder saying it may be distributed
8216under the terms of this General Public License. The ``Program'', below,
8217refers to any such program or work, and a ``work based on the Program''
8218means either the Program or any derivative work under copyright law:
8219that is to say, a work containing the Program or a portion of it,
8220either verbatim or with modifications and/or translated into another
8221language. (Hereinafter, translation is included without limitation in
8222the term ``modification''.) Each licensee is addressed as ``you''.
8223
8224Activities other than copying, distribution and modification are not
8225covered by this License; they are outside its scope. The act of
8226running the Program is not restricted, and the output from the Program
8227is covered only if its contents constitute a work based on the
8228Program (independent of having been made by running the Program).
8229Whether that is true depends on what the Program does.
70b88761
RP
8230
8231@item
7463aadd
RP
8232You may copy and distribute verbatim copies of the Program's
8233source code as you receive it, in any medium, provided that you
8234conspicuously and appropriately publish on each copy an appropriate
8235copyright notice and disclaimer of warranty; keep intact all the
8236notices that refer to this License and to the absence of any warranty;
8237and give any other recipients of the Program a copy of this License
8238along with the Program.
70b88761 8239
7463aadd
RP
8240You may charge a fee for the physical act of transferring a copy, and
8241you may at your option offer warranty protection in exchange for a fee.
70b88761 8242
70b88761 8243@item
7463aadd
RP
8244You may modify your copy or copies of the Program or any portion
8245of it, thus forming a work based on the Program, and copy and
8246distribute such modifications or work under the terms of Section 1
8247above, provided that you also meet all of these conditions:
70b88761 8248
1041a570 8249@enumerate a
70b88761 8250@item
7463aadd
RP
8251You must cause the modified files to carry prominent notices
8252stating that you changed the files and the date of any change.
70b88761
RP
8253
8254@item
7463aadd
RP
8255You must cause any work that you distribute or publish, that in
8256whole or in part contains or is derived from the Program or any
8257part thereof, to be licensed as a whole at no charge to all third
8258parties under the terms of this License.
70b88761
RP
8259
8260@item
7463aadd
RP
8261If the modified program normally reads commands interactively
8262when run, you must cause it, when started running for such
8263interactive use in the most ordinary way, to print or display an
8264announcement including an appropriate copyright notice and a
8265notice that there is no warranty (or else, saying that you provide
8266a warranty) and that users may redistribute the program under
8267these conditions, and telling the user how to view a copy of this
8268License. (Exception: if the Program itself is interactive but
8269does not normally print such an announcement, your work based on
8270the Program is not required to print an announcement.)
1041a570 8271@end enumerate
7463aadd
RP
8272
8273These requirements apply to the modified work as a whole. If
8274identifiable sections of that work are not derived from the Program,
8275and can be reasonably considered independent and separate works in
8276themselves, then this License, and its terms, do not apply to those
8277sections when you distribute them as separate works. But when you
8278distribute the same sections as part of a whole which is a work based
8279on the Program, the distribution of the whole must be on the terms of
8280this License, whose permissions for other licensees extend to the
8281entire whole, and thus to each and every part regardless of who wrote it.
8282
8283Thus, it is not the intent of this section to claim rights or contest
8284your rights to work written entirely by you; rather, the intent is to
8285exercise the right to control the distribution of derivative or
8286collective works based on the Program.
8287
8288In addition, mere aggregation of another work not based on the Program
8289with the Program (or with a work based on the Program) on a volume of
8290a storage or distribution medium does not bring the other work under
8291the scope of this License.
70b88761
RP
8292
8293@item
7463aadd
RP
8294You may copy and distribute the Program (or a work based on it,
8295under Section 2) in object code or executable form under the terms of
8296Sections 1 and 2 above provided that you also do one of the following:
70b88761 8297
1041a570 8298@enumerate a
70b88761 8299@item
7463aadd
RP
8300Accompany it with the complete corresponding machine-readable
8301source code, which must be distributed under the terms of Sections
83021 and 2 above on a medium customarily used for software interchange; or,
70b88761
RP
8303
8304@item
7463aadd
RP
8305Accompany it with a written offer, valid for at least three
8306years, to give any third party, for a charge no more than your
8307cost of physically performing source distribution, a complete
8308machine-readable copy of the corresponding source code, to be
8309distributed under the terms of Sections 1 and 2 above on a medium
8310customarily used for software interchange; or,
70b88761
RP
8311
8312@item
7463aadd
RP
8313Accompany it with the information you received as to the offer
8314to distribute corresponding source code. (This alternative is
70b88761 8315allowed only for noncommercial distribution and only if you
7463aadd
RP
8316received the program in object code or executable form with such
8317an offer, in accord with Subsection b above.)
1041a570 8318@end enumerate
7463aadd
RP
8319
8320The source code for a work means the preferred form of the work for
8321making modifications to it. For an executable work, complete source
8322code means all the source code for all modules it contains, plus any
8323associated interface definition files, plus the scripts used to
8324control compilation and installation of the executable. However, as a
8325special exception, the source code distributed need not include
8326anything that is normally distributed (in either source or binary
8327form) with the major components (compiler, kernel, and so on) of the
8328operating system on which the executable runs, unless that component
8329itself accompanies the executable.
8330
8331If distribution of executable or object code is made by offering
8332access to copy from a designated place, then offering equivalent
8333access to copy the source code from the same place counts as
8334distribution of the source code, even though third parties are not
8335compelled to copy the source along with the object code.
70b88761
RP
8336
8337@item
7463aadd
RP
8338You may not copy, modify, sublicense, or distribute the Program
8339except as expressly provided under this License. Any attempt
8340otherwise to copy, modify, sublicense or distribute the Program is
8341void, and will automatically terminate your rights under this License.
8342However, parties who have received copies, or rights, from you under
8343this License will not have their licenses terminated so long as such
8344parties remain in full compliance.
70b88761
RP
8345
8346@item
7463aadd
RP
8347You are not required to accept this License, since you have not
8348signed it. However, nothing else grants you permission to modify or
8349distribute the Program or its derivative works. These actions are
8350prohibited by law if you do not accept this License. Therefore, by
8351modifying or distributing the Program (or any work based on the
8352Program), you indicate your acceptance of this License to do so, and
8353all its terms and conditions for copying, distributing or modifying
8354the Program or works based on it.
70b88761
RP
8355
8356@item
8357Each time you redistribute the Program (or any work based on the
7463aadd
RP
8358Program), the recipient automatically receives a license from the
8359original licensor to copy, distribute or modify the Program subject to
8360these terms and conditions. You may not impose any further
8361restrictions on the recipients' exercise of the rights granted herein.
8362You are not responsible for enforcing compliance by third parties to
8363this License.
8364
8365@item
8366If, as a consequence of a court judgment or allegation of patent
8367infringement or for any other reason (not limited to patent issues),
8368conditions are imposed on you (whether by court order, agreement or
8369otherwise) that contradict the conditions of this License, they do not
8370excuse you from the conditions of this License. If you cannot
8371distribute so as to satisfy simultaneously your obligations under this
8372License and any other pertinent obligations, then as a consequence you
8373may not distribute the Program at all. For example, if a patent
8374license would not permit royalty-free redistribution of the Program by
8375all those who receive copies directly or indirectly through you, then
8376the only way you could satisfy both it and this License would be to
8377refrain entirely from distribution of the Program.
8378
8379If any portion of this section is held invalid or unenforceable under
8380any particular circumstance, the balance of the section is intended to
8381apply and the section as a whole is intended to apply in other
8382circumstances.
8383
8384It is not the purpose of this section to induce you to infringe any
8385patents or other property right claims or to contest validity of any
8386such claims; this section has the sole purpose of protecting the
8387integrity of the free software distribution system, which is
8388implemented by public license practices. Many people have made
8389generous contributions to the wide range of software distributed
8390through that system in reliance on consistent application of that
8391system; it is up to the author/donor to decide if he or she is willing
8392to distribute software through any other system and a licensee cannot
8393impose that choice.
8394
8395This section is intended to make thoroughly clear what is believed to
8396be a consequence of the rest of this License.
8397
8398@item
8399If the distribution and/or use of the Program is restricted in
8400certain countries either by patents or by copyrighted interfaces, the
8401original copyright holder who places the Program under this License
8402may add an explicit geographical distribution limitation excluding
8403those countries, so that distribution is permitted only in or among
8404countries not thus excluded. In such case, this License incorporates
8405the limitation as if written in the body of this License.
70b88761
RP
8406
8407@item
8408The Free Software Foundation may publish revised and/or new versions
8409of the General Public License from time to time. Such new versions will
8410be similar in spirit to the present version, but may differ in detail to
8411address new problems or concerns.
8412
8413Each version is given a distinguishing version number. If the Program
7463aadd 8414specifies a version number of this License which applies to it and ``any
70b88761
RP
8415later version'', you have the option of following the terms and conditions
8416either of that version or of any later version published by the Free
8417Software Foundation. If the Program does not specify a version number of
7463aadd 8418this License, you may choose any version ever published by the Free Software
70b88761
RP
8419Foundation.
8420
8421@item
8422If you wish to incorporate parts of the Program into other free
8423programs whose distribution conditions are different, write to the author
8424to ask for permission. For software which is copyrighted by the Free
8425Software Foundation, write to the Free Software Foundation; we sometimes
8426make exceptions for this. Our decision will be guided by the two goals
8427of preserving the free status of all derivatives of our free software and
8428of promoting the sharing and reuse of software generally.
8429
8430@iftex
8431@heading NO WARRANTY
8432@end iftex
8433@ifinfo
8434@center NO WARRANTY
8435@end ifinfo
8436
8437@item
8438BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
8439FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN
8440OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
8441PROVIDE THE PROGRAM ``AS IS'' WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED
8442OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
8443MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS
8444TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE
8445PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,
8446REPAIR OR CORRECTION.
8447
8448@item
7463aadd
RP
8449IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
8450WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
70b88761 8451REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,
7463aadd
RP
8452INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING
8453OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED
8454TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY
8455YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER
8456PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE
8457POSSIBILITY OF SUCH DAMAGES.
70b88761
RP
8458@end enumerate
8459
8460@iftex
8461@heading END OF TERMS AND CONDITIONS
8462@end iftex
8463@ifinfo
8464@center END OF TERMS AND CONDITIONS
8465@end ifinfo
8466
8467@page
54e6b3c3 8468@unnumberedsec Applying These Terms to Your New Programs
70b88761
RP
8469
8470 If you develop a new program, and you want it to be of the greatest
7463aadd
RP
8471possible use to the public, the best way to achieve this is to make it
8472free software which everyone can redistribute and change under these terms.
70b88761 8473
7463aadd
RP
8474 To do so, attach the following notices to the program. It is safest
8475to attach them to the start of each source file to most effectively
8476convey the exclusion of warranty; and each file should have at least
8477the ``copyright'' line and a pointer to where the full notice is found.
70b88761
RP
8478
8479@smallexample
203eea5d 8480@var{one line to give the program's name and an idea of what it does.}
70b88761
RP
8481Copyright (C) 19@var{yy} @var{name of author}
8482
203eea5d
RP
8483This program is free software; you can redistribute it and/or
8484modify it under the terms of the GNU General Public License
8485as published by the Free Software Foundation; either version 2
8486of the License, or (at your option) any later version.
70b88761
RP
8487
8488This program is distributed in the hope that it will be useful,
8489but WITHOUT ANY WARRANTY; without even the implied warranty of
8490MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
8491GNU General Public License for more details.
8492
8493You should have received a copy of the GNU General Public License
203eea5d
RP
8494along with this program; if not, write to the
8495Free Software Foundation, Inc., 675 Mass Ave,
8496Cambridge, MA 02139, USA.
70b88761
RP
8497@end smallexample
8498
8499Also add information on how to contact you by electronic and paper mail.
8500
8501If the program is interactive, make it output a short notice like this
8502when it starts in an interactive mode:
8503
8504@smallexample
8505Gnomovision version 69, Copyright (C) 19@var{yy} @var{name of author}
203eea5d
RP
8506Gnomovision comes with ABSOLUTELY NO WARRANTY; for details
8507type `show w'. This is free software, and you are welcome
8508to redistribute it under certain conditions; type `show c'
8509for details.
70b88761
RP
8510@end smallexample
8511
7463aadd
RP
8512The hypothetical commands @samp{show w} and @samp{show c} should show
8513the appropriate parts of the General Public License. Of course, the
8514commands you use may be called something other than @samp{show w} and
8515@samp{show c}; they could even be mouse-clicks or menu items---whatever
8516suits your program.
70b88761
RP
8517
8518You should also get your employer (if you work as a programmer) or your
8519school, if any, to sign a ``copyright disclaimer'' for the program, if
8520necessary. Here is a sample; alter the names:
8521
1041a570
RP
8522@example
8523Yoyodyne, Inc., hereby disclaims all copyright
8524interest in the program `Gnomovision'
8525(which makes passes at compilers) written
8526by James Hacker.
70b88761
RP
8527
8528@var{signature of Ty Coon}, 1 April 1989
8529Ty Coon, President of Vice
1041a570 8530@end example
7463aadd
RP
8531
8532This General Public License does not permit incorporating your program into
8533proprietary programs. If your program is a subroutine library, you may
8534consider it more useful to permit linking proprietary applications with the
8535library. If this is what you want to do, use the GNU Library General
8536Public License instead of this License.
0f153e74 8537_fi__(!_AGGLOMERATION__)
70b88761 8538
4eb4cf57 8539@node Index
d2e08421 8540@unnumbered Index
e91b87a3 8541
8542@printindex cp
8543
fe3f5fc8
RP
8544@tex
8545% I think something like @colophon should be in texinfo. In the
8546% meantime:
8547\long\def\colophon{\hbox to0pt{}\vfill
8548\centerline{The body of this manual is set in}
8549\centerline{\fontname\tenrm,}
8550\centerline{with headings in {\bf\fontname\tenbf}}
8551\centerline{and examples in {\tt\fontname\tentt}.}
a6d0b6d3
RP
8552\centerline{{\it\fontname\tenit\/},}
8553\centerline{{\bf\fontname\tenbf}, and}
fe3f5fc8
RP
8554\centerline{{\sl\fontname\tensl\/}}
8555\centerline{are used for emphasis.}\vfill}
8556\page\colophon
a6d0b6d3 8557% Blame: [email protected], 1991.
fe3f5fc8
RP
8558@end tex
8559
e91b87a3 8560@contents
8561@bye
This page took 1.349964 seconds and 4 git commands to generate.