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