ChangeLog entry for sparc.mt added last week.
[deliverable/binutils-gdb.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. ---pesch@cygnus.com, 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 3051* List:: Printing Source Lines
6f28dd0b 3052_if__(_GENERIC__ || !_H8__)
b80282d5 3053* Search:: Searching Source Files
6f28dd0b 3054_fi__(_GENERIC__ || !_H8__)
b80282d5
RP
3055* Source Path:: Specifying Source Directories
3056* Machine Code:: Source and Machine Code
70b88761
RP
3057@end menu
3058
4eb4cf57 3059@node List
70b88761
RP
3060@section Printing Source Lines
3061
3062@kindex list
3063@kindex l
3064To print lines from a source file, use the @code{list} command
3065(abbreviated @code{l}). There are several ways to specify what part
3066of the file you want to print.
3067
3068Here are the forms of the @code{list} command most commonly used:
3069
3070@table @code
3071@item list @var{linenum}
c338a2fd 3072Print lines centered around line number @var{linenum} in the
70b88761
RP
3073current source file.
3074
3075@item list @var{function}
c338a2fd 3076Print lines centered around the beginning of function
70b88761
RP
3077@var{function}.
3078
3079@item list
c338a2fd
RP
3080Print more lines. If the last lines printed were printed with a
3081@code{list} command, this prints lines following the last lines
70b88761 3082printed; however, if the last line printed was a solitary line printed
29a2b744 3083as part of displaying a stack frame (@pxref{Stack, ,Examining the
1041a570 3084Stack}), this prints lines centered around that line.
70b88761
RP
3085
3086@item list -
c338a2fd
RP
3087Print lines just before the lines last printed.
3088@end table
3089
3090By default, _GDBN__ prints ten source lines with any of these forms of
3091the @code{list} command. You can change this using @code{set listsize}:
3092
3093@table @code
3094@item set listsize @var{count}
3095@kindex set listsize
3096Make the @code{list} command display @var{count} source lines (unless
3097the @code{list} argument explicitly specifies some other number).
3098
3099@item show listsize
3100@kindex show listsize
3101Display the number of lines that @code{list} will currently display by
e251e767 3102default.
70b88761
RP
3103@end table
3104
3105Repeating a @code{list} command with @key{RET} discards the argument,
3106so it is equivalent to typing just @code{list}. This is more useful
3107than listing the same lines again. An exception is made for an
3108argument of @samp{-}; that argument is preserved in repetition so that
3109each repetition moves up in the source file.
3110
3111@cindex linespec
3112In general, the @code{list} command expects you to supply zero, one or two
3113@dfn{linespecs}. Linespecs specify source lines; there are several ways
3114of writing them but the effect is always to specify some source line.
3115Here is a complete description of the possible arguments for @code{list}:
3116
3117@table @code
3118@item list @var{linespec}
c338a2fd 3119Print lines centered around the line specified by @var{linespec}.
70b88761
RP
3120
3121@item list @var{first},@var{last}
3122Print lines from @var{first} to @var{last}. Both arguments are
3123linespecs.
3124
3125@item list ,@var{last}
c338a2fd 3126Print lines ending with @var{last}.
70b88761
RP
3127
3128@item list @var{first},
c338a2fd 3129Print lines starting with @var{first}.
70b88761
RP
3130
3131@item list +
c338a2fd 3132Print lines just after the lines last printed.
70b88761
RP
3133
3134@item list -
c338a2fd 3135Print lines just before the lines last printed.
70b88761
RP
3136
3137@item list
3138As described in the preceding table.
3139@end table
3140
3141Here are the ways of specifying a single source line---all the
3142kinds of linespec.
3143
3144@table @code
3145@item @var{number}
3146Specifies line @var{number} of the current source file.
3147When a @code{list} command has two linespecs, this refers to
3148the same source file as the first linespec.
3149
3150@item +@var{offset}
3151Specifies the line @var{offset} lines after the last line printed.
3152When used as the second linespec in a @code{list} command that has
3153two, this specifies the line @var{offset} lines down from the
3154first linespec.
3155
3156@item -@var{offset}
3157Specifies the line @var{offset} lines before the last line printed.
3158
3159@item @var{filename}:@var{number}
3160Specifies line @var{number} in the source file @var{filename}.
3161
3162@item @var{function}
3163@c FIXME: "of the open-brace" is C-centric. When we add other langs...
3164Specifies the line of the open-brace that begins the body of the
3165function @var{function}.
3166
3167@item @var{filename}:@var{function}
3168Specifies the line of the open-brace that begins the body of the
3169function @var{function} in the file @var{filename}. You only need the
3170file name with a function name to avoid ambiguity when there are
3171identically named functions in different source files.
3172
3173@item *@var{address}
3174Specifies the line containing the program address @var{address}.
3175@var{address} may be any expression.
3176@end table
3177
6f28dd0b 3178_if__(_GENERIC__ || !_H8__)
4eb4cf57 3179@node Search
70b88761
RP
3180@section Searching Source Files
3181@cindex searching
3182@kindex reverse-search
3183
3184There are two commands for searching through the current source file for a
3185regular expression.
3186
3187@table @code
3188@item forward-search @var{regexp}
3189@itemx search @var{regexp}
3190@kindex search
3191@kindex forward-search
1041a570
RP
3192The command @samp{forward-search @var{regexp}} checks each line,
3193starting with the one following the last line listed, for a match for
3194@var{regexp}. It lists the line that is found. You can use
3195synonym @samp{search @var{regexp}} or abbreviate the command name as
3196@code{fo}.
70b88761
RP
3197
3198@item reverse-search @var{regexp}
3199The command @samp{reverse-search @var{regexp}} checks each line, starting
3200with the one before the last line listed and going backward, for a match
3201for @var{regexp}. It lists the line that is found. You can abbreviate
3202this command as @code{rev}.
3203@end table
6f28dd0b 3204_fi__(_GENERIC__ || !_H8__)
70b88761 3205
4eb4cf57 3206@node Source Path
70b88761
RP
3207@section Specifying Source Directories
3208
3209@cindex source path
3210@cindex directories for source files
3211Executable programs sometimes do not record the directories of the source
3212files from which they were compiled, just the names. Even when they do,
3213the directories could be moved between the compilation and your debugging
3214session. _GDBN__ has a list of directories to search for source files;
3215this is called the @dfn{source path}. Each time _GDBN__ wants a source file,
3216it tries all the directories in the list, in the order they are present
3217in the list, until it finds a file with the desired name. Note that
3218the executable search path is @emph{not} used for this purpose. Neither is
3219the current working directory, unless it happens to be in the source
3220path.
3221
29a2b744 3222If _GDBN__ cannot find a source file in the source path, and the object
70b88761
RP
3223program records a directory, _GDBN__ tries that directory too. If the
3224source path is empty, and there is no record of the compilation
3225directory, _GDBN__ will, as a last resort, look in the current
3226directory.
3227
3228Whenever you reset or rearrange the source path, _GDBN__ will clear out
3229any information it has cached about where source files are found, where
3230each line is in the file, etc.
3231
3232@kindex directory
3233When you start _GDBN__, its source path is empty.
3234To add other directories, use the @code{directory} command.
3235
3236@table @code
3237@item directory @var{dirname} @dots{}
3238Add directory @var{dirname} to the front of the source path. Several
3239directory names may be given to this command, separated by @samp{:} or
3240whitespace. You may specify a directory that is already in the source
e251e767 3241path; this moves it forward, so it will be searched sooner.
7463aadd
RP
3242
3243You can use the string @samp{$cdir} to refer to the compilation
3244directory (if one is recorded), and @samp{$cwd} to refer to the current
3245working directory. @samp{$cwd} is not the same as @samp{.}---the former
3246tracks the current working directory as it changes during your _GDBN__
3247session, while the latter is immediately expanded to the current
3248directory at the time you add an entry to the source path.
70b88761
RP
3249
3250@item directory
3251Reset the source path to empty again. This requires confirmation.
3252
3253@c RET-repeat for @code{directory} is explicitly disabled, but since
29a2b744 3254@c repeating it would be a no-op we do not say that. (thanks to RMS)
70b88761
RP
3255
3256@item show directories
3257@kindex show directories
3258Print the source path: show which directories it contains.
3259@end table
3260
3261If your source path is cluttered with directories that are no longer of
3262interest, _GDBN__ may sometimes cause confusion by finding the wrong
3263versions of source. You can correct the situation as follows:
3264
3265@enumerate
3266@item
3267Use @code{directory} with no argument to reset the source path to empty.
3268
3269@item
3270Use @code{directory} with suitable arguments to reinstall the
3271directories you want in the source path. You can add all the
3272directories in one command.
3273@end enumerate
3274
4eb4cf57 3275@node Machine Code
70b88761 3276@section Source and Machine Code
1041a570 3277
70b88761
RP
3278You can use the command @code{info line} to map source lines to program
3279addresses (and viceversa), and the command @code{disassemble} to display
3280a range of addresses as machine instructions.
3281
3282@table @code
3283@item info line @var{linespec}
3284@kindex info line
3285Print the starting and ending addresses of the compiled code for
1041a570
RP
3286source line @var{linespec}. You can specify source lines in any of
3287the ways understood by the @code{list} command (@pxref{List, ,Printing
3288Source Lines}).
70b88761
RP
3289@end table
3290
1041a570
RP
3291For example, we can use @code{info line} to discover the location of
3292the object code for the first line of function
3293@code{m4_changequote}:
3294
70b88761
RP
3295@smallexample
3296(_GDBP__) info line m4_changecom
3297Line 895 of "builtin.c" starts at pc 0x634c and ends at 0x6350.
3298@end smallexample
3299
3300@noindent
3301We can also inquire (using @code{*@var{addr}} as the form for
3302@var{linespec}) what source line covers a particular address:
3303@smallexample
3304(_GDBP__) info line *0x63ff
3305Line 926 of "builtin.c" starts at pc 0x63e4 and ends at 0x6404.
3306@end smallexample
3307
c338a2fd 3308@cindex @code{$_} and @code{info line}
29a2b744
RP
3309After @code{info line}, the default address for the @code{x} command
3310is changed to the starting address of the line, so that @samp{x/i} is
3311sufficient to begin examining the machine code (@pxref{Memory,
3312,Examining Memory}). Also, this address is saved as the value of the
3313convenience variable @code{$_} (@pxref{Convenience Vars, ,Convenience
3314Variables}).
70b88761
RP
3315
3316@table @code
3317@kindex disassemble
3318@item disassemble
e94b4a2b
RP
3319This specialized command dumps a range of memory as machine
3320instructions. The default memory range is the function surrounding the
3321program counter of the selected frame. A single argument to this
3322command is a program counter value; the function surrounding this value
3323will be dumped. Two arguments specify a range of addresses (first
3324inclusive, second exclusive) to dump.
70b88761
RP
3325@end table
3326
4eb4cf57 3327_if__(_GENERIC__||!_H8__)
70b88761 3328We can use @code{disassemble} to inspect the object code
4eb4cf57
RP
3329range shown in the last @code{info line} example (the example
3330shows SPARC machine instructions):
70b88761 3331
4eb4cf57 3332_0__
70b88761
RP
3333@smallexample
3334(_GDBP__) disas 0x63e4 0x6404
3335Dump of assembler code from 0x63e4 to 0x6404:
b80282d5
RP
33360x63e4 <builtin_init+5340>: ble 0x63f8 <builtin_init+5360>
33370x63e8 <builtin_init+5344>: sethi %hi(0x4c00), %o0
33380x63ec <builtin_init+5348>: ld [%i1+4], %o0
33390x63f0 <builtin_init+5352>: b 0x63fc <builtin_init+5364>
33400x63f4 <builtin_init+5356>: ld [%o0+4], %o0
33410x63f8 <builtin_init+5360>: or %o0, 0x1a4, %o0
33420x63fc <builtin_init+5364>: call 0x9288 <path_search>
e251e767 33430x6400 <builtin_init+5368>: nop
70b88761 3344End of assembler dump.
70b88761 3345@end smallexample
4eb4cf57
RP
3346_1__
3347_fi__(_GENERIC__||!_H8__)
3348
3349_if__(!_GENERIC__||_H8__)
3350For example, here is the beginning of the output for the
3351disassembly of a function @code{fact}:
70b88761 3352
4eb4cf57
RP
3353_0__
3354@smallexample
3355(_GDBP__) disas fact
3356Dump of assembler code for function fact:
3357to 0x808c:
33580x802c <fact>: 6d f2 mov.w r2,@@-r7
33590x802e <fact+2>: 6d f3 mov.w r3,@@-r7
33600x8030 <fact+4>: 6d f6 mov.w r6,@@-r7
33610x8032 <fact+6>: 0d 76 mov.w r7,r6
33620x8034 <fact+8>: 6f 70 00 08 mov.w @@(0x8,r7),r0
33630x8038 <fact+12> 19 11 sub.w r1,r1
3364 .
3365 .
3366 .
3367@end smallexample
3368_1__
3369_fi__(!_GENERIC__||_H8__)
3370
3371
3372@node Data
70b88761
RP
3373@chapter Examining Data
3374
3375@cindex printing data
3376@cindex examining data
3377@kindex print
3378@kindex inspect
1041a570 3379@c "inspect" is not quite a synonym if you are using Epoch, which we do not
29a2b744 3380@c document because it is nonstandard... Under Epoch it displays in a
70b88761
RP
3381@c different window or something like that.
3382The usual way to examine data in your program is with the @code{print}
4eb4cf57
RP
3383command (abbreviated @code{p}), or its synonym @code{inspect}.
3384_if__(!_CONLY__)
3385It evaluates and prints the value of an expression of the language your
1041a570 3386program is written in (@pxref{Languages, ,Using _GDBN__ with Different
4eb4cf57
RP
3387Languages}).
3388_fi__(!_CONLY__)
70b88761 3389
e0dacfd1
RP
3390@table @code
3391@item print @var{exp}
3392@itemx print /@var{f} @var{exp}
3393@var{exp} is an expression (in the source language). By default
70b88761 3394the value of @var{exp} is printed in a format appropriate to its data
e0dacfd1
RP
3395type; you can choose a different format by specifying @samp{/@var{f}},
3396where @var{f} is a letter specifying the format; @pxref{Output formats}.
3397
3398@item print
3399@itemx print /@var{f}
3400If you omit @var{exp}, _GDBN__ displays the last value again (from the
1041a570 3401@dfn{value history}; @pxref{Value History, ,Value History}). This allows you to
e0dacfd1
RP
3402conveniently inspect the same value in an alternative format.
3403@end table
70b88761
RP
3404
3405A more low-level way of examining data is with the @code{x} command.
3406It examines data in memory at a specified address and prints it in a
29a2b744 3407specified format. @xref{Memory, ,Examining Memory}.
70b88761 3408
29a2b744 3409If you are interested in information about types, or about how the fields
b80282d5 3410of a struct or class are declared, use the @code{ptype @var{exp}}
1041a570 3411command rather than @code{print}. @xref{Symbols, ,Examining the Symbol Table}.
b80282d5 3412
70b88761 3413@menu
b80282d5
RP
3414* Expressions:: Expressions
3415* Variables:: Program Variables
3416* Arrays:: Artificial Arrays
3417* Output formats:: Output formats
3418* Memory:: Examining Memory
3419* Auto Display:: Automatic Display
3420* Print Settings:: Print Settings
3421* Value History:: Value History
3422* Convenience Vars:: Convenience Variables
3423* Registers:: Registers
4eb4cf57 3424_if__(_GENERIC__ || !_H8__)
b80282d5 3425* Floating Point Hardware:: Floating Point Hardware
4eb4cf57 3426_fi__(_GENERIC__ || !_H8__)
70b88761
RP
3427@end menu
3428
4eb4cf57 3429@node Expressions
70b88761
RP
3430@section Expressions
3431
3432@cindex expressions
3433@code{print} and many other _GDBN__ commands accept an expression and
3434compute its value. Any kind of constant, variable or operator defined
3435by the programming language you are using is legal in an expression in
3436_GDBN__. This includes conditional expressions, function calls, casts
3437and string constants. It unfortunately does not include symbols defined
b80282d5 3438by preprocessor @code{#define} commands.
70b88761 3439
4eb4cf57 3440_if__(!_CONLY__)
c2bbbb22 3441Because C is so widespread, most of the expressions shown in examples in
1041a570 3442this manual are in C. @xref{Languages, , Using _GDBN__ with Different
c2bbbb22 3443Languages}, for information on how to use expressions in other
e251e767 3444languages.
c2bbbb22
RP
3445
3446In this section, we discuss operators that you can use in _GDBN__
e251e767 3447expressions regardless of your programming language.
c2bbbb22 3448
70b88761
RP
3449Casts are supported in all languages, not just in C, because it is so
3450useful to cast a number into a pointer so as to examine a structure
3451at that address in memory.
c2bbbb22 3452@c FIXME: casts supported---Mod2 true?
4eb4cf57 3453_fi__(!_CONLY__)
70b88761 3454
c2bbbb22 3455_GDBN__ supports these operators in addition to those of programming
70b88761
RP
3456languages:
3457
3458@table @code
3459@item @@
3460@samp{@@} is a binary operator for treating parts of memory as arrays.
1041a570 3461@xref{Arrays, ,Artificial Arrays}, for more information.
70b88761
RP
3462
3463@item ::
3464@samp{::} allows you to specify a variable in terms of the file or
1041a570 3465function where it is defined. @xref{Variables, ,Program Variables}.
70b88761
RP
3466
3467@item @{@var{type}@} @var{addr}
3468Refers to an object of type @var{type} stored at address @var{addr} in
3469memory. @var{addr} may be any expression whose value is an integer or
3470pointer (but parentheses are required around binary operators, just as in
3471a cast). This construct is allowed regardless of what kind of data is
1041a570 3472normally supposed to reside at @var{addr}.
70b88761
RP
3473@end table
3474
4eb4cf57 3475@node Variables
70b88761
RP
3476@section Program Variables
3477
3478The most common kind of expression to use is the name of a variable
3479in your program.
3480
3481Variables in expressions are understood in the selected stack frame
29a2b744
RP
3482(@pxref{Selection, ,Selecting a Frame}); they must either be global
3483(or static) or be visible according to the scope rules of the
3484programming language from the point of execution in that frame. This
3485means that in the function
70b88761
RP
3486
3487@example
3488foo (a)
3489 int a;
3490@{
3491 bar (a);
3492 @{
3493 int b = test ();
3494 bar (b);
3495 @}
3496@}
3497@end example
3498
3499@noindent
29a2b744 3500the variable @code{a} is usable whenever your program is executing
70b88761 3501within the function @code{foo}, but the variable @code{b} is visible
29a2b744 3502only while your program is executing inside the block in which @code{b}
70b88761
RP
3503is declared.
3504
3505@cindex variable name conflict
3506There is an exception: you can refer to a variable or function whose
3507scope is a single source file even if the current execution point is not
3508in this file. But it is possible to have more than one such variable or
6ca72cc6
RP
3509function with the same name (in different source files). If that
3510happens, referring to that name has unpredictable effects. If you wish,
3511you can specify a static variable in a particular function or file,
3512using the colon-colon notation:
70b88761
RP
3513
3514@cindex colon-colon
a6d0b6d3 3515@iftex
29a2b744 3516@c info cannot cope with a :: index entry, but why deprive hard copy readers?
70b88761 3517@kindex ::
a6d0b6d3 3518@end iftex
70b88761
RP
3519@example
3520@var{file}::@var{variable}
6ca72cc6 3521@var{function}::@var{variable}
70b88761
RP
3522@end example
3523
3524@noindent
6ca72cc6 3525Here @var{file} or @var{function} is the name of the context for the
6c380b13
RP
3526static @var{variable}. In the case of file names, you can use quotes to
3527make sure _GDBN__ parses the file name as a single word---for example,
3528to print a global value of @code{x} defined in @file{f2.c}:
3529
3530@example
3531(_GDBP__) p 'f2.c'::x
3532@end example
70b88761 3533
c2bbbb22 3534@cindex C++ scope resolution
70b88761
RP
3535This use of @samp{::} is very rarely in conflict with the very similar
3536use of the same notation in C++. _GDBN__ also supports use of the C++
c2bbbb22 3537scope resolution operator in _GDBN__ expressions.
70b88761 3538
3d3ab540
RP
3539@cindex wrong values
3540@cindex variable values, wrong
3541@quotation
3542@emph{Warning:} Occasionally, a local variable may appear to have the
3543wrong value at certain points in a function---just after entry to the
29a2b744 3544function, and just before exit. You may see this problem when you are
3d3ab540
RP
3545stepping by machine instructions. This is because on most machines, it
3546takes more than one instruction to set up a stack frame (including local
29a2b744 3547variable definitions); if you are stepping by machine instructions,
3d3ab540
RP
3548variables may appear to have the wrong values until the stack frame is
3549completely built. On function exit, it usually also takes more than one
3550machine instruction to destroy a stack frame; after you begin stepping
3551through that group of instructions, local variable definitions may be
3552gone.
3553@end quotation
3554
4eb4cf57 3555@node Arrays
70b88761
RP
3556@section Artificial Arrays
3557
3558@cindex artificial array
3559@kindex @@
3560It is often useful to print out several successive objects of the
3561same type in memory; a section of an array, or an array of
3562dynamically determined size for which only a pointer exists in the
3563program.
3564
3565This can be done by constructing an @dfn{artificial array} with the
3566binary operator @samp{@@}. The left operand of @samp{@@} should be
3567the first element of the desired array, as an individual object.
3568The right operand should be the desired length of the array. The result is
3569an array value whose elements are all of the type of the left argument.
3570The first element is actually the left argument; the second element
3571comes from bytes of memory immediately following those that hold the
3572first element, and so on. Here is an example. If a program says
3573
3574@example
3575int *array = (int *) malloc (len * sizeof (int));
3576@end example
3577
3578@noindent
3579you can print the contents of @code{array} with
3580
3581@example
3582p *array@@len
3583@end example
3584
3585The left operand of @samp{@@} must reside in memory. Array values made
3586with @samp{@@} in this way behave just like other arrays in terms of
3587subscripting, and are coerced to pointers when used in expressions.
3588Artificial arrays most often appear in expressions via the value history
1041a570 3589(@pxref{Value History, ,Value History}), after printing one out.)
70b88761 3590
1041a570 3591Sometimes the artificial array mechanism is not quite enough; in
3d3ab540 3592moderately complex data structures, the elements of interest may not
1041a570
RP
3593actually be adjacent---for example, if you are interested in the values
3594of pointers in an array. One useful work-around in this situation is
3595to use a convenience variable (@pxref{Convenience Vars, ,Convenience
3596Variables}) as a counter in an expression that prints the first
3597interesting value, and then repeat that expression via @key{RET}. For
3598instance, suppose you have an array @code{dtab} of pointers to
3599structures, and you are interested in the values of a field @code{fv}
3600in each structure. Here is an example of what you might type:
3601
3d3ab540
RP
3602@example
3603set $i = 0
3604p dtab[$i++]->fv
3605@key{RET}
3606@key{RET}
3607@dots{}
3608@end example
3609
4eb4cf57 3610@node Output formats
70b88761
RP
3611@section Output formats
3612
3613@cindex formatted output
3614@cindex output formats
3615By default, _GDBN__ prints a value according to its data type. Sometimes
3616this is not what you want. For example, you might want to print a number
3617in hex, or a pointer in decimal. Or you might want to view data in memory
3618at a certain address as a character string or as an instruction. To do
3619these things, specify an @dfn{output format} when you print a value.
3620
3621The simplest use of output formats is to say how to print a value
3622already computed. This is done by starting the arguments of the
3623@code{print} command with a slash and a format letter. The format
3624letters supported are:
3625
3626@table @code
3627@item x
3628Regard the bits of the value as an integer, and print the integer in
3629hexadecimal.
3630
3631@item d
3632Print as integer in signed decimal.
3633
3634@item u
3635Print as integer in unsigned decimal.
3636
3637@item o
3638Print as integer in octal.
3639
3640@item t
3641Print as integer in binary. The letter @samp{t} stands for ``two''.
3642
3643@item a
3644Print as an address, both absolute in hex and as an offset from the
3645nearest preceding symbol. This format can be used to discover where (in
3646what function) an unknown address is located:
1041a570 3647
70b88761
RP
3648@example
3649(_GDBP__) p/a 0x54320
3650_0__$3 = 0x54320 <_initialize_vx+396>_1__
3651@end example
3652
70b88761
RP
3653@item c
3654Regard as an integer and print it as a character constant.
3655
3656@item f
3657Regard the bits of the value as a floating point number and print
3658using typical floating point syntax.
3659@end table
3660
3661For example, to print the program counter in hex (@pxref{Registers}), type
3662
3663@example
3664p/x $pc
3665@end example
3666
3667@noindent
3668Note that no space is required before the slash; this is because command
3669names in _GDBN__ cannot contain a slash.
3670
3671To reprint the last value in the value history with a different format,
3672you can use the @code{print} command with just a format and no
3673expression. For example, @samp{p/x} reprints the last value in hex.
3674
4eb4cf57 3675@node Memory
70b88761
RP
3676@section Examining Memory
3677
1041a570
RP
3678You can use the command @code{x} (for ``examine'') to examine memory in
3679any of several formats, independently of your program's data types.
3680
70b88761
RP
3681@cindex examining memory
3682@table @code
3683@kindex x
cedaf8bc
RP
3684@item x/@var{nfu} @var{addr}
3685@itemx x @var{addr}
3686@itemx x
1041a570
RP
3687Use the command @code{x} to examine memory.
3688@end table
3689
3690@var{n}, @var{f}, and @var{u} are all optional parameters that specify how
3691much memory to display and how to format it; @var{addr} is an
cedaf8bc
RP
3692expression giving the address where you want to start displaying memory.
3693If you use defaults for @var{nfu}, you need not type the slash @samp{/}.
3694Several commands set convenient defaults for @var{addr}.
70b88761 3695
1041a570
RP
3696@table @r
3697@item @var{n}, the repeat count
3698The repeat count is a decimal integer; the default is 1. It specifies
3699how much memory (counting by units @var{u}) to display.
cedaf8bc
RP
3700@c This really is **decimal**; unaffected by 'set radix' as of GDB
3701@c 4.1.2.
70b88761 3702
1041a570
RP
3703@item @var{f}, the display format
3704The display format is one of the formats used by @code{print},
cedaf8bc
RP
3705or @samp{s} (null-terminated string) or @samp{i} (machine instruction).
3706The default is @samp{x} (hexadecimal) initially, or the format from the
3707last time you used either @code{x} or @code{print}.
70b88761 3708
1041a570
RP
3709@item @var{u}, the unit size
3710The unit size is any of
70b88761
RP
3711@table @code
3712@item b
cedaf8bc 3713Bytes.
70b88761 3714@item h
cedaf8bc 3715Halfwords (two bytes).
70b88761 3716@item w
cedaf8bc 3717Words (four bytes). This is the initial default.
70b88761 3718@item g
cedaf8bc 3719Giant words (eight bytes).
70b88761
RP
3720@end table
3721
cedaf8bc
RP
3722Each time you specify a unit size with @code{x}, that size becomes the
3723default unit the next time you use @code{x}. (For the @samp{s} and
3724@samp{i} formats, the unit size is ignored and is normally not written.)
3725
1041a570 3726@item @var{addr}, starting display address
cedaf8bc
RP
3727@var{addr} is the address where you want _GDBN__ to begin displaying
3728memory. The expression need not have a pointer value (though it may);
3729it is always interpreted as an integer address of a byte of memory.
1041a570 3730@xref{Expressions, ,Expressions}, for more information on expressions. The default for
cedaf8bc
RP
3731@var{addr} is usually just after the last address examined---but several
3732other commands also set the default address: @code{info breakpoints} (to
3733the address of the last breakpoint listed), @code{info line} (to the
3734starting address of a line), and @code{print} (if you use it to display
3735a value from memory).
1041a570 3736@end table
70b88761 3737
cedaf8bc
RP
3738For example, @samp{x/3uh 0x54320} is a request to display three halfwords
3739(@code{h}) of memory, formatted as unsigned decimal integers (@samp{u}),
3740starting at address @code{0x54320}. @samp{x/4xw $sp} prints the four
3741words (@samp{w}) of memory above the stack pointer (here, @samp{$sp};
3742@pxref{Registers}) in hexadecimal (@samp{x}).
70b88761 3743
cedaf8bc 3744Since the letters indicating unit sizes are all distinct from the
29a2b744 3745letters specifying output formats, you do not have to remember whether
cedaf8bc
RP
3746unit size or format comes first; either order will work. The output
3747specifications @samp{4xw} and @samp{4wx} mean exactly the same thing.
3748(However, the count @var{n} must come first; @samp{wx4} will not work.)
3749
3750Even though the unit size @var{u} is ignored for the formats @samp{s}
3751and @samp{i}, you might still want to use a count @var{n}; for example,
3752@samp{3i} specifies that you want to see three machine instructions,
3753including any operands. The command @code{disassemble} gives an
3754alternative way of inspecting machine instructions; @pxref{Machine
3755Code}.
3756
3757All the defaults for the arguments to @code{x} are designed to make it
3758easy to continue scanning memory with minimal specifications each time
1041a570 3759you use @code{x}. For example, after you have inspected three machine
cedaf8bc
RP
3760instructions with @samp{x/3i @var{addr}}, you can inspect the next seven
3761with just @samp{x/7}. If you use @key{RET} to repeat the @code{x} command,
3762the repeat count @var{n} is used again; the other arguments default as
3763for successive uses of @code{x}.
70b88761 3764
c338a2fd 3765@cindex @code{$_}, @code{$__}, and value history
cedaf8bc 3766The addresses and contents printed by the @code{x} command are not saved
70b88761
RP
3767in the value history because there is often too much of them and they
3768would get in the way. Instead, _GDBN__ makes these values available for
3769subsequent use in expressions as values of the convenience variables
3770@code{$_} and @code{$__}. After an @code{x} command, the last address
3771examined is available for use in expressions in the convenience variable
3772@code{$_}. The contents of that address, as examined, are available in
3773the convenience variable @code{$__}.
3774
3775If the @code{x} command has a repeat count, the address and contents saved
3776are from the last memory unit printed; this is not the same as the last
3777address printed if several units were printed on the last line of output.
3778
4eb4cf57 3779@node Auto Display
70b88761
RP
3780@section Automatic Display
3781@cindex automatic display
3782@cindex display of expressions
3783
3784If you find that you want to print the value of an expression frequently
3785(to see how it changes), you might want to add it to the @dfn{automatic
29a2b744 3786display list} so that _GDBN__ will print its value each time your program stops.
70b88761
RP
3787Each expression added to the list is given a number to identify it;
3788to remove an expression from the list, you specify that number.
3789The automatic display looks like this:
3790
3791@example
37922: foo = 38
37933: bar[5] = (struct hack *) 0x3804
3794@end example
3795
3796@noindent
3797showing item numbers, expressions and their current values. As with
3798displays you request manually using @code{x} or @code{print}, you can
3799specify the output format you prefer; in fact, @code{display} decides
3800whether to use @code{print} or @code{x} depending on how elaborate your
3801format specification is---it uses @code{x} if you specify a unit size,
3802or one of the two formats (@samp{i} and @samp{s}) that are only
3803supported by @code{x}; otherwise it uses @code{print}.
3804
3805@table @code
3806@item display @var{exp}
3807@kindex display
3808Add the expression @var{exp} to the list of expressions to display
1041a570 3809each time your program stops. @xref{Expressions, ,Expressions}.
70b88761
RP
3810
3811@code{display} will not repeat if you press @key{RET} again after using it.
3812
3813@item display/@var{fmt} @var{exp}
3814For @var{fmt} specifying only a display format and not a size or
3815count, add the expression @var{exp} to the auto-display list but
3816arranges to display it each time in the specified format @var{fmt}.
3817@xref{Output formats}.
3818
3819@item display/@var{fmt} @var{addr}
3820For @var{fmt} @samp{i} or @samp{s}, or including a unit-size or a
3821number of units, add the expression @var{addr} as a memory address to
29a2b744
RP
3822be examined each time your program stops. Examining means in effect
3823doing @samp{x/@var{fmt} @var{addr}}. @xref{Memory, ,Examining Memory}.
70b88761
RP
3824@end table
3825
3826For example, @samp{display/i $pc} can be helpful, to see the machine
3827instruction about to be executed each time execution stops (@samp{$pc}
3828is a common name for the program counter; @pxref{Registers}).
3829
3830@table @code
3831@item undisplay @var{dnums}@dots{}
3832@itemx delete display @var{dnums}@dots{}
3833@kindex delete display
3834@kindex undisplay
3835Remove item numbers @var{dnums} from the list of expressions to display.
3836
3837@code{undisplay} will not repeat if you press @key{RET} after using it.
3838(Otherwise you would just get the error @samp{No display number @dots{}}.)
3839
3840@item disable display @var{dnums}@dots{}
3841@kindex disable display
3842Disable the display of item numbers @var{dnums}. A disabled display
3843item is not printed automatically, but is not forgotten. It may be
3844enabled again later.
3845
3846@item enable display @var{dnums}@dots{}
3847@kindex enable display
3848Enable display of item numbers @var{dnums}. It becomes effective once
3849again in auto display of its expression, until you specify otherwise.
3850
3851@item display
3852Display the current values of the expressions on the list, just as is
29a2b744 3853done when your program stops.
70b88761
RP
3854
3855@item info display
3856@kindex info display
3857Print the list of expressions previously set up to display
3858automatically, each one with its item number, but without showing the
3859values. This includes disabled expressions, which are marked as such.
3860It also includes expressions which would not be displayed right now
3861because they refer to automatic variables not currently available.
3862@end table
3863
3864If a display expression refers to local variables, then it does not make
3865sense outside the lexical context for which it was set up. Such an
3866expression is disabled when execution enters a context where one of its
3867variables is not defined. For example, if you give the command
3868@code{display last_char} while inside a function with an argument
29a2b744 3869@code{last_char}, then this argument will be displayed while your program
70b88761
RP
3870continues to stop inside that function. When it stops elsewhere---where
3871there is no variable @code{last_char}---display is disabled. The next time
3872your program stops where @code{last_char} is meaningful, you can enable the
3873display expression once again.
3874
4eb4cf57 3875@node Print Settings
70b88761
RP
3876@section Print Settings
3877
3878@cindex format options
3879@cindex print settings
3880_GDBN__ provides the following ways to control how arrays, structures,
e251e767 3881and symbols are printed.
70b88761
RP
3882
3883@noindent
3884These settings are useful for debugging programs in any language:
3885
3886@table @code
3887@item set print address
3888@item set print address on
3889@kindex set print address
3890_GDBN__ will print memory addresses showing the location of stack
3891traces, structure values, pointer values, breakpoints, and so forth,
3892even when it also displays the contents of those addresses. The default
3893is on. For example, this is what a stack frame display looks like, with
3894@code{set print address on}:
1041a570 3895
70b88761 3896@smallexample
1041a570 3897@group
70b88761 3898(_GDBP__) f
e251e767 3899#0 set_quotes (lq=0x34c78 "<<", rq=0x34c88 ">>")
70b88761 3900 at input.c:530
b80282d5 3901530 if (lquote != def_lquote)
1041a570 3902@end group
70b88761
RP
3903@end smallexample
3904
3905@item set print address off
3906Do not print addresses when displaying their contents. For example,
3907this is the same stack frame displayed with @code{set print address off}:
1041a570 3908
70b88761 3909@example
1041a570 3910@group
70b88761
RP
3911(_GDBP__) set print addr off
3912(_GDBP__) f
3913#0 set_quotes (lq="<<", rq=">>") at input.c:530
b80282d5 3914530 if (lquote != def_lquote)
1041a570 3915@end group
70b88761
RP
3916@end example
3917
3918@item show print address
3919@kindex show print address
3920Show whether or not addresses are to be printed.
3921
3922@item set print array
3923@itemx set print array on
3924@kindex set print array
3925_GDBN__ will pretty print arrays. This format is more convenient to read,
3926but uses more space. The default is off.
3927
3928@item set print array off.
3929Return to compressed format for arrays.
3930
3931@item show print array
3932@kindex show print array
3933Show whether compressed or pretty format is selected for displaying
e251e767 3934arrays.
70b88761
RP
3935
3936@item set print elements @var{number-of-elements}
3937@kindex set print elements
3938If _GDBN__ is printing a large array, it will stop printing after it has
3939printed the number of elements set by the @code{set print elements} command.
3940This limit also applies to the display of strings.
3941
3942@item show print elements
3943@kindex show print elements
3944Display the number of elements of a large array that _GDBN__ will print
3945before losing patience.
3946
3947@item set print pretty on
3948@kindex set print pretty
3949Cause _GDBN__ to print structures in an indented format with one member per
3950line, like this:
3951
3952@example
1041a570 3953@group
70b88761
RP
3954$1 = @{
3955 next = 0x0,
3956 flags = @{
3957 sweet = 1,
3958 sour = 1
3959 @},
3960 meat = 0x54 "Pork"
3961@}
1041a570 3962@end group
70b88761
RP
3963@end example
3964
3965@item set print pretty off
3966Cause _GDBN__ to print structures in a compact format, like this:
3967
3968@smallexample
1041a570 3969@group
38962738
RP
3970$1 = @{next = 0x0, flags = @{sweet = 1, sour = 1@}, \
3971meat = 0x54 "Pork"@}
1041a570 3972@end group
70b88761
RP
3973@end smallexample
3974
3975@noindent
3976This is the default format.
3977
3978@item show print pretty
3979@kindex show print pretty
3980Show which format _GDBN__ will use to print structures.
3981
3982@item set print sevenbit-strings on
f2857bd9 3983@kindex set print sevenbit-strings
e251e767 3984Print using only seven-bit characters; if this option is set,
70b88761
RP
3985_GDBN__ will display any eight-bit characters (in strings or character
3986values) using the notation @code{\}@var{nnn}. For example, @kbd{M-a} is
3987displayed as @code{\341}.
3988
3989@item set print sevenbit-strings off
3990Print using either seven-bit or eight-bit characters, as required. This
3991is the default.
3992
3993@item show print sevenbit-strings
f2857bd9 3994@kindex show print sevenbit-strings
70b88761
RP
3995Show whether or not _GDBN__ will print only seven-bit characters.
3996
3997@item set print union on
3998@kindex set print union
3999Tell _GDBN__ to print unions which are contained in structures. This is the
4000default setting.
4001
4002@item set print union off
4003Tell _GDBN__ not to print unions which are contained in structures.
4004
4005@item show print union
4006@kindex show print union
4007Ask _GDBN__ whether or not it will print unions which are contained in
e251e767 4008structures.
70b88761
RP
4009
4010For example, given the declarations
4011
4012@smallexample
4013typedef enum @{Tree, Bug@} Species;
4014typedef enum @{Big_tree, Acorn, Seedling@} Tree_forms;
203eea5d
RP
4015typedef enum @{Caterpillar, Cocoon, Butterfly@}
4016 Bug_forms;
70b88761
RP
4017
4018struct thing @{
4019 Species it;
4020 union @{
4021 Tree_forms tree;
4022 Bug_forms bug;
4023 @} form;
4024@};
4025
4026struct thing foo = @{Tree, @{Acorn@}@};
4027@end smallexample
4028
4029@noindent
4030with @code{set print union on} in effect @samp{p foo} would print
4031
4032@smallexample
4033$1 = @{it = Tree, form = @{tree = Acorn, bug = Cocoon@}@}
4034@end smallexample
4035
4036@noindent
4037and with @code{set print union off} in effect it would print
4038
4039@smallexample
4040$1 = @{it = Tree, form = @{...@}@}
4041@end smallexample
4042@end table
4043
4044@noindent
4045These settings are of interest when debugging C++ programs:
4046
4047@table @code
e251e767
RP
4048@item set print demangle
4049@itemx set print demangle on
70b88761
RP
4050@kindex set print demangle
4051Print C++ names in their source form rather than in the mangled form
4052in which they are passed to the assembler and linker for type-safe linkage.
4053The default is on.
4054
4055@item show print demangle
4056@kindex show print demangle
4057Show whether C++ names will be printed in mangled or demangled form.
4058
e251e767
RP
4059@item set print asm-demangle
4060@itemx set print asm-demangle on
70b88761
RP
4061@kindex set print asm-demangle
4062Print C++ names in their source form rather than their mangled form, even
4063in assembler code printouts such as instruction disassemblies.
4064The default is off.
4065
4066@item show print asm-demangle
4067@kindex show print asm-demangle
4068Show whether C++ names in assembly listings will be printed in mangled
4069or demangled form.
4070
4071@item set print object
4072@itemx set print object on
4073@kindex set print object
4074When displaying a pointer to an object, identify the @emph{actual}
4075(derived) type of the object rather than the @emph{declared} type, using
4076the virtual function table.
4077
4078@item set print object off
4079Display only the declared type of objects, without reference to the
4080virtual function table. This is the default setting.
4081
4082@item show print object
4083@kindex show print object
4084Show whether actual, or declared, object types will be displayed.
4085
e251e767
RP
4086@item set print vtbl
4087@itemx set print vtbl on
70b88761
RP
4088@kindex set print vtbl
4089Pretty print C++ virtual function tables. The default is off.
4090
4091@item set print vtbl off
4092Do not pretty print C++ virtual function tables.
4093
4094@item show print vtbl
4095@kindex show print vtbl
4096Show whether C++ virtual function tables are pretty printed, or not.
70b88761
RP
4097@end table
4098
4eb4cf57 4099@node Value History
70b88761
RP
4100@section Value History
4101
4102@cindex value history
4103Values printed by the @code{print} command are saved in _GDBN__'s @dfn{value
4104history} so that you can refer to them in other expressions. Values are
4105kept until the symbol table is re-read or discarded (for example with
4106the @code{file} or @code{symbol-file} commands). When the symbol table
4107changes, the value history is discarded, since the values may contain
4108pointers back to the types defined in the symbol table.
4109
4110@cindex @code{$}
4111@cindex @code{$$}
4112@cindex history number
4113The values printed are given @dfn{history numbers} for you to refer to them
4114by. These are successive integers starting with one. @code{print} shows you
4115the history number assigned to a value by printing @samp{$@var{num} = }
4116before the value; here @var{num} is the history number.
4117
4118To refer to any previous value, use @samp{$} followed by the value's
4119history number. The way @code{print} labels its output is designed to
4120remind you of this. Just @code{$} refers to the most recent value in
4121the history, and @code{$$} refers to the value before that.
4122@code{$$@var{n}} refers to the @var{n}th value from the end; @code{$$2}
4123is the value just prior to @code{$$}, @code{$$1} is equivalent to
4124@code{$$}, and @code{$$0} is equivalent to @code{$}.
4125
4126For example, suppose you have just printed a pointer to a structure and
4127want to see the contents of the structure. It suffices to type
4128
4129@example
4130p *$
4131@end example
4132
4133If you have a chain of structures where the component @code{next} points
4134to the next one, you can print the contents of the next one with this:
4135
4136@example
4137p *$.next
4138@end example
4139
4140@noindent
4141You can print successive links in the chain by repeating this
4142command---which you can do by just typing @key{RET}.
4143
4144Note that the history records values, not expressions. If the value of
4145@code{x} is 4 and you type these commands:
4146
4147@example
4148print x
4149set x=5
4150@end example
4151
4152@noindent
4153then the value recorded in the value history by the @code{print} command
4154remains 4 even though the value of @code{x} has changed.
4155
4156@table @code
4157@kindex show values
4158@item show values
4159Print the last ten values in the value history, with their item numbers.
4160This is like @samp{p@ $$9} repeated ten times, except that @code{show
4161values} does not change the history.
4162
4163@item show values @var{n}
4164Print ten history values centered on history item number @var{n}.
4165
4166@item show values +
4167Print ten history values just after the values last printed. If no more
4168values are available, produces no display.
4169@end table
4170
4171Pressing @key{RET} to repeat @code{show values @var{n}} has exactly the
e251e767 4172same effect as @samp{show values +}.
70b88761 4173
4eb4cf57 4174@node Convenience Vars
70b88761
RP
4175@section Convenience Variables
4176
4177@cindex convenience variables
4178_GDBN__ provides @dfn{convenience variables} that you can use within
4179_GDBN__ to hold on to a value and refer to it later. These variables
4180exist entirely within _GDBN__; they are not part of your program, and
4181setting a convenience variable has no direct effect on further execution
1041a570 4182of your program. That is why you can use them freely.
70b88761
RP
4183
4184Convenience variables are prefixed with @samp{$}. Any name preceded by
4185@samp{$} can be used for a convenience variable, unless it is one of
4186the predefined machine-specific register names (@pxref{Registers}).
4187(Value history references, in contrast, are @emph{numbers} preceded
1041a570 4188by @samp{$}. @xref{Value History, ,Value History}.)
70b88761
RP
4189
4190You can save a value in a convenience variable with an assignment
4191expression, just as you would set a variable in your program. Example:
4192
4193@example
4194set $foo = *object_ptr
4195@end example
4196
4197@noindent
4198would save in @code{$foo} the value contained in the object pointed to by
4199@code{object_ptr}.
4200
4201Using a convenience variable for the first time creates it; but its value
4202is @code{void} until you assign a new value. You can alter the value with
4203another assignment at any time.
4204
4205Convenience variables have no fixed types. You can assign a convenience
4206variable any type of value, including structures and arrays, even if
4207that variable already has a value of a different type. The convenience
4208variable, when used as an expression, has the type of its current value.
4209
4210@table @code
4211@item show convenience
4212@kindex show convenience
4213Print a list of convenience variables used so far, and their values.
4214Abbreviated @code{show con}.
4215@end table
4216
4217One of the ways to use a convenience variable is as a counter to be
4218incremented or a pointer to be advanced. For example, to print
4219a field from successive elements of an array of structures:
4220
4221_0__@example
4222set $i = 0
4223print bar[$i++]->contents
4224@i{@dots{} repeat that command by typing @key{RET}.}
4225_1__@end example
4226
4227Some convenience variables are created automatically by _GDBN__ and given
4228values likely to be useful.
4229
4230@table @code
4231@item $_
c338a2fd 4232@kindex $_
70b88761 4233The variable @code{$_} is automatically set by the @code{x} command to
29a2b744
RP
4234the last address examined (@pxref{Memory, ,Examining Memory}). Other
4235commands which provide a default address for @code{x} to examine also
4236set @code{$_} to that address; these commands include @code{info line}
4237and @code{info breakpoint}. The type of @code{$_} is @code{void *}
4238except when set by the @code{x} command, in which case it is a pointer
4239to the type of @code{$__}.
70b88761
RP
4240
4241@item $__
c338a2fd 4242@kindex $__
70b88761 4243The variable @code{$__} is automatically set by the @code{x} command
c2bbbb22
RP
4244to the value found in the last address examined. Its type is chosen
4245to match the format in which the data was printed.
70b88761
RP
4246@end table
4247
4eb4cf57 4248@node Registers
70b88761
RP
4249@section Registers
4250
4251@cindex registers
b80282d5 4252You can refer to machine register contents, in expressions, as variables
70b88761
RP
4253with names starting with @samp{$}. The names of registers are different
4254for each machine; use @code{info registers} to see the names used on
e251e767 4255your machine.
70b88761
RP
4256
4257@table @code
4258@item info registers
4259@kindex info registers
b80282d5
RP
4260Print the names and values of all registers except floating-point
4261registers (in the selected stack frame).
4262
4263@item info all-registers
4264@kindex info all-registers
4265@cindex floating point registers
4266Print the names and values of all registers, including floating-point
4267registers.
70b88761 4268
4eb4cf57 4269@item info registers @var{regname} @dots{}
0d1cd01e
JG
4270Print the relativized value of each specified register @var{regname}.
4271@var{regname} may be any register name valid on the machine you are using, with
70b88761
RP
4272or without the initial @samp{$}.
4273@end table
4274
09267865 4275_GDBN__ has four ``standard'' register names that are available (in
29a2b744 4276expressions) on most machines---whenever they do not conflict with an
09267865
RP
4277architecture's canonical mnemonics for registers. The register names
4278@code{$pc} and @code{$sp} are used for the program counter register and
4279the stack pointer. @code{$fp} is used for a register that contains a
4280pointer to the current stack frame, and @code{$ps} is used for a
4281register that contains the processor status. For example,
70b88761 4282you could print the program counter in hex with
1041a570 4283
70b88761
RP
4284@example
4285p/x $pc
4286@end example
4287
4288@noindent
4289or print the instruction to be executed next with
1041a570 4290
70b88761
RP
4291@example
4292x/i $pc
4293@end example
4294
4295@noindent
29a2b744
RP
4296or add four to the stack pointer @footnote{This is a way of removing
4297one word from the stack, on machines where stacks grow downward in
4298memory (most machines, nowadays). This assumes that the innermost
4299stack frame is selected; setting @code{$sp} is not allowed when other
4300stack frames are selected. To pop entire frames off the stack,
4301regardless of machine architecture, use @code{return};
1041a570
RP
4302@pxref{Returning, ,Returning from a Function}.} with
4303
70b88761
RP
4304@example
4305set $sp += 4
4306@end example
4307
09267865
RP
4308Whenever possible, these four standard register names are available on
4309your machine even though the machine has different canonical mnemonics,
4310so long as there is no conflict. The @code{info registers} command
4311shows the canonical names. For example, on the SPARC, @code{info
70b88761
RP
4312registers} displays the processor status register as @code{$psr} but you
4313can also refer to it as @code{$ps}.
4314
4315_GDBN__ always considers the contents of an ordinary register as an
4316integer when the register is examined in this way. Some machines have
4317special registers which can hold nothing but floating point; these
4318registers are considered to have floating point values. There is no way
4319to refer to the contents of an ordinary register as floating point value
4320(although you can @emph{print} it as a floating point value with
4321@samp{print/f $@var{regname}}).
4322
4323Some registers have distinct ``raw'' and ``virtual'' data formats. This
4324means that the data format in which the register contents are saved by
4325the operating system is not the same one that your program normally
4326sees. For example, the registers of the 68881 floating point
4327coprocessor are always saved in ``extended'' (raw) format, but all C
4328programs expect to work with ``double'' (virtual) format. In such
4329cases, _GDBN__ normally works with the virtual format only (the format that
4330makes sense for your program), but the @code{info registers} command
4331prints the data in both formats.
4332
4333Normally, register values are relative to the selected stack frame
29a2b744
RP
4334(@pxref{Selection, ,Selecting a Frame}). This means that you get the
4335value that the register would contain if all stack frames farther in
4336were exited and their saved registers restored. In order to see the
4337true contents of hardware registers, you must select the innermost
4338frame (with @samp{frame 0}).
70b88761
RP
4339
4340However, _GDBN__ must deduce where registers are saved, from the machine
4341code generated by your compiler. If some registers are not saved, or if
4342_GDBN__ is unable to locate the saved registers, the selected stack
4343frame will make no difference.
4344
d8a68b28 4345_if__(_AMD29K__)
03a77779 4346@table @code
d8a68b28
JG
4347@item set rstack_high_address @var{address}
4348@kindex set rstack_high_address
03a77779
RP
4349@cindex AMD 29K register stack
4350@cindex register stack, AMD29K
4351On AMD 29000 family processors, registers are saved in a separate
4352``register stack''. There is no way for _GDBN__ to determine the extent
4353of this stack. Normally, _GDBN__ just assumes that the stack is ``large
4354enough''. This may result in _GDBN__ referencing memory locations that
4355don't exist. If necessary, you can get around this problem by
4356specifying the ending address of the register stack with the @code{set
4357rstack_high_address} command. The argument should be an address, which
4358you will probably want to precede with @samp{0x} to specify in
4359hexadecimal.
d8a68b28
JG
4360
4361@item show rstack_high_address
4362@kindex show rstack_high_address
03a77779
RP
4363Display the current limit of the register stack, on AMD 29000 family
4364processors.
4365@end table
d8a68b28
JG
4366_fi__(_AMD29K__)
4367
4eb4cf57
RP
4368_if__(_GENERIC__ || !_H8__)
4369@node Floating Point Hardware
70b88761
RP
4370@section Floating Point Hardware
4371@cindex floating point
1041a570 4372
70b88761
RP
4373Depending on the host machine architecture, _GDBN__ may be able to give
4374you more information about the status of the floating point hardware.
4375
4376@table @code
4377@item info float
4378@kindex info float
4379If available, provides hardware-dependent information about the floating
4380point unit. The exact contents and layout vary depending on the
4381floating point chip.
4382@end table
4383@c FIXME: this is a cop-out. Try to get examples, explanations. Only
e251e767
RP
4384@c FIXME...supported currently on arm's and 386's. Mark properly with
4385@c FIXME... m4 macros to isolate general statements from hardware-dep,
70b88761 4386@c FIXME... at that point.
4eb4cf57 4387_fi__(_GENERIC__ || !_H8__)
70b88761 4388
4eb4cf57
RP
4389_if__(!_CONLY__)
4390@node Languages
c2bbbb22
RP
4391@chapter Using _GDBN__ with Different Languages
4392@cindex languages
4393
4394Although programming languages generally have common aspects, they are
4395rarely expressed in the same manner. For instance, in ANSI C,
4396dereferencing a pointer @code{p} is accomplished by @code{*p}, but in
4397Modula-2, it is accomplished by @code{p^}. Values can also be
4398represented (and displayed) differently. Hex numbers in C are written
4399like @samp{0x1ae}, while in Modula-2 they appear as @samp{1AEH}.
4400
4401@cindex working language
4402Language-specific information is built into _GDBN__ for some languages,
29a2b744 4403allowing you to express operations like the above in your program's
c2bbbb22 4404native language, and allowing _GDBN__ to output values in a manner
29a2b744 4405consistent with the syntax of your program's native language. The
c2bbbb22
RP
4406language you use to build expressions, called the @dfn{working
4407language}, can be selected manually, or _GDBN__ can set it
4408automatically.
4409
4410@menu
4411* Setting:: Switching between source languages
4412* Show:: Displaying the language
4413* Checks:: Type and Range checks
4414* Support:: Supported languages
4415@end menu
4416
4eb4cf57 4417@node Setting
c2bbbb22
RP
4418@section Switching between source languages
4419
4420There are two ways to control the working language---either have _GDBN__
4421set it automatically, or select it manually yourself. You can use the
4422@code{set language} command for either purpose. On startup, _GDBN__
4423defaults to setting the language automatically.
4424
4425@menu
4426* Manually:: Setting the working language manually
4427* Automatically:: Having _GDBN__ infer the source language
4428@end menu
4429
4eb4cf57 4430@node Manually
c2bbbb22
RP
4431@subsection Setting the working language
4432
4433@kindex set language
4434To set the language, issue the command @samp{set language @var{lang}},
c338a2fd
RP
4435where @var{lang} is the name of a language: @code{c} or @code{modula-2}.
4436For a list of the supported languages, type @samp{set language}.
c2bbbb22
RP
4437
4438Setting the language manually prevents _GDBN__ from updating the working
4439language automatically. This can lead to confusion if you try
4440to debug a program when the working language is not the same as the
4441source language, when an expression is acceptable to both
4442languages---but means different things. For instance, if the current
4443source file were written in C, and _GDBN__ was parsing Modula-2, a
4444command such as:
4445
4446@example
4447print a = b + c
4448@end example
4449
4450@noindent
4451might not have the effect you intended. In C, this means to add
4452@code{b} and @code{c} and place the result in @code{a}. The result
4453printed would be the value of @code{a}. In Modula-2, this means to compare
4454@code{a} to the result of @code{b+c}, yielding a @code{BOOLEAN} value.
4455
4456If you allow _GDBN__ to set the language automatically, then
4457you can count on expressions evaluating the same way in your debugging
4458session and in your program.
4459
4eb4cf57 4460@node Automatically
c2bbbb22
RP
4461@subsection Having _GDBN__ infer the source language
4462
4463To have _GDBN__ set the working language automatically, use @samp{set
4464language local} or @samp{set language auto}. _GDBN__ then infers the
4465language that a program was written in by looking at the name of its
4466source files, and examining their extensions:
4467
4468@table @file
4469@item *.mod
4470Modula-2 source file
4471
4472@item *.c
5a2c1d85
RP
4473C source file
4474
4475@item *.C
c2bbbb22 4476@itemx *.cc
5a2c1d85 4477C++ source file
c2bbbb22
RP
4478@end table
4479
4480This information is recorded for each function or procedure in a source
4481file. When your program stops in a frame (usually by encountering a
4482breakpoint), _GDBN__ sets the working language to the language recorded
4483for the function in that frame. If the language for a frame is unknown
4484(that is, if the function or block corresponding to the frame was
4485defined in a source file that does not have a recognized extension), the
4486current working language is not changed, and _GDBN__ issues a warning.
4487
4488This may not seem necessary for most programs, which are written
4489entirely in one source language. However, program modules and libraries
4490written in one source language can be used by a main program written in
4491a different source language. Using @samp{set language auto} in this
4492case frees you from having to set the working language manually.
4493
4eb4cf57 4494@node Show
c2bbbb22
RP
4495@section Displaying the language
4496
4497The following commands will help you find out which language is the
4498working language, and also what language source files were written in.
4499
4500@kindex show language
4501@kindex info frame
4502@kindex info source
4503@table @code
4504@item show language
4505Display the current working language. This is the
4506language you can use with commands such as @code{print} to
29a2b744 4507build and compute expressions that may involve variables in your program.
c2bbbb22
RP
4508
4509@item info frame
1041a570 4510Among the other information listed here (@pxref{Frame Info, ,Information
c2bbbb22
RP
4511about a Frame}) is the source language for this frame. This is the
4512language that will become the working language if you ever use an
4513identifier that is in this frame.
4514
4515@item info source
1041a570 4516Among the other information listed here (@pxref{Symbols, ,Examining the
c2bbbb22 4517Symbol Table}) is the source language of this source file.
c2bbbb22
RP
4518@end table
4519
4eb4cf57 4520@node Checks
c2bbbb22
RP
4521@section Type and range Checking
4522
4523@quotation
4524@emph{Warning:} In this release, the _GDBN__ commands for type and range
4525checking are included, but they do not yet have any effect. This
4526section documents the intended facilities.
4527@end quotation
4528@c FIXME remove warning when type/range code added
4529
4530Some languages are designed to guard you against making seemingly common
4531errors through a series of compile- and run-time checks. These include
4532checking the type of arguments to functions and operators, and making
4533sure mathematical overflows are caught at run time. Checks such as
4534these help to ensure a program's correctness once it has been compiled
4535by eliminating type mismatches, and providing active checks for range
29a2b744 4536errors when your program is running.
c2bbbb22 4537
1041a570
RP
4538_GDBN__ can check for conditions like the above if you wish.
4539Although _GDBN__ will not check the statements in your program, it
4540can check expressions entered directly into _GDBN__ for evaluation via
4541the @code{print} command, for example. As with the working language,
c2bbbb22 4542_GDBN__ can also decide whether or not to check automatically based on
1041a570
RP
4543your program's source language. @xref{Support, ,Supported Languages},
4544for the default settings of supported languages.
c2bbbb22
RP
4545
4546@menu
4547* Type Checking:: An overview of type checking
4548* Range Checking:: An overview of range checking
4549@end menu
4550
4551@cindex type checking
4552@cindex checks, type
4eb4cf57 4553@node Type Checking
c2bbbb22
RP
4554@subsection An overview of type checking
4555
4556Some languages, such as Modula-2, are strongly typed, meaning that the
4557arguments to operators and functions have to be of the correct type,
4558otherwise an error occurs. These checks prevent type mismatch
4559errors from ever causing any run-time problems. For example,
4560
4561@example
45621 + 2 @result{} 3
1041a570 4563@exdent but
c2bbbb22
RP
4564@error{} 1 + 2.3
4565@end example
4566
4567The second example fails because the @code{CARDINAL} 1 is not
4568type-compatible with the @code{REAL} 2.3.
4569
4570For expressions you use in _GDBN__ commands, you can tell the _GDBN__
4571type checker to skip checking; to treat any mismatches as errors and
4572abandon the expression; or only issue warnings when type mismatches
4573occur, but evaluate the expression anyway. When you choose the last of
4574these, _GDBN__ evaluates expressions like the second example above, but
4575also issues a warning.
4576
4577Even though you may turn type checking off, other type-based reasons may
4578prevent _GDBN__ from evaluating an expression. For instance, _GDBN__ does not
4579know how to add an @code{int} and a @code{struct foo}. These particular
4580type errors have nothing to do with the language in use, and usually
4581arise from expressions, such as the one described above, which make
4582little sense to evaluate anyway.
4583
4584Each language defines to what degree it is strict about type. For
4585instance, both Modula-2 and C require the arguments to arithmetical
4586operators to be numbers. In C, enumerated types and pointers can be
4587represented as numbers, so that they are valid arguments to mathematical
1041a570 4588operators. @xref{Support, ,Supported Languages}, for further
c2bbbb22
RP
4589details on specific languages.
4590
4591_GDBN__ provides some additional commands for controlling the type checker:
4592
4593@kindex set check
4594@kindex set check type
4595@kindex show check type
4596@table @code
4597@item set check type auto
e251e767 4598Set type checking on or off based on the current working language.
1041a570 4599@xref{Support, ,Supported Languages}, for the default settings for
c2bbbb22
RP
4600each language.
4601
4602@item set check type on
4603@itemx set check type off
4604Set type checking on or off, overriding the default setting for the
4605current working language. Issue a warning if the setting does not
4606match the language's default. If any type mismatches occur in
4607evaluating an expression while typechecking is on, _GDBN__ prints a
4608message and aborts evaluation of the expression.
4609
4610@item set check type warn
4611Cause the type checker to issue warnings, but to always attempt to
4612evaluate the expression. Evaluating the expression may still
4613be impossible for other reasons. For example, _GDBN__ cannot add
4614numbers and structures.
4615
4616@item show type
e251e767 4617Show the current setting of the type checker, and whether or not _GDBN__ is
c2bbbb22
RP
4618setting it automatically.
4619@end table
4620
4621@cindex range checking
4622@cindex checks, range
4eb4cf57 4623@node Range Checking
c2bbbb22
RP
4624@subsection An overview of Range Checking
4625
4626In some languages (such as Modula-2), it is an error to exceed the
4627bounds of a type; this is enforced with run-time checks. Such range
4628checking is meant to ensure program correctness by making sure
4629computations do not overflow, or indices on an array element access do
4630not exceed the bounds of the array.
4631
4632For expressions you use in _GDBN__ commands, you can tell _GDBN__ to
4633ignore range errors; to always treat them as errors and abandon the
4634expression; or to issue warnings when a range error occurs but evaluate
4635the expression anyway.
4636
4637A range error can result from numerical overflow, from exceeding an
4638array index bound, or when you type in a constant that is not a member
4639of any type. Some languages, however, do not treat overflows as an
4640error. In many implementations of C, mathematical overflow causes the
4641result to ``wrap around'' to lower values---for example, if @var{m} is
4642the largest integer value, and @var{s} is the smallest, then
1041a570 4643
c2bbbb22
RP
4644@example
4645@var{m} + 1 @result{} @var{s}
4646@end example
4647
4648This, too, is specific to individual languages, and in some cases
1041a570 4649specific to individual compilers or machines. @xref{Support, ,
c2bbbb22
RP
4650Supported Languages}, for further details on specific languages.
4651
4652_GDBN__ provides some additional commands for controlling the range checker:
4653
4654@kindex set check
4655@kindex set check range
4656@kindex show check range
4657@table @code
4658@item set check range auto
e251e767 4659Set range checking on or off based on the current working language.
1041a570 4660@xref{Support, ,Supported Languages}, for the default settings for
c2bbbb22
RP
4661each language.
4662
4663@item set check range on
4664@itemx set check range off
4665Set range checking on or off, overriding the default setting for the
4666current working language. A warning is issued if the setting does not
4667match the language's default. If a range error occurs, then a message
4668is printed and evaluation of the expression is aborted.
4669
4670@item set check range warn
4671Output messages when the _GDBN__ range checker detects a range error,
4672but attempt to evaluate the expression anyway. Evaluating the
4673expression may still be impossible for other reasons, such as accessing
4674memory that the process does not own (a typical example from many UNIX
4675systems).
4676
4677@item show range
e251e767 4678Show the current setting of the range checker, and whether or not it is
c2bbbb22
RP
4679being set automatically by _GDBN__.
4680@end table
4681
4eb4cf57 4682@node Support
c2bbbb22
RP
4683@section Supported Languages
4684
5a2c1d85 4685_GDBN__ 4 supports C, C++, and Modula-2. Some _GDBN__
1041a570
RP
4686features may be used in expressions regardless of the language you
4687use: the _GDBN__ @code{@@} and @code{::} operators, and the
4688@samp{@{type@}addr} construct (@pxref{Expressions, ,Expressions}) can be
4689used with the constructs of any of the supported languages.
c2bbbb22
RP
4690
4691The following sections detail to what degree each of these
4692source languages is supported by _GDBN__. These sections are
4693not meant to be language tutorials or references, but serve only as a
4694reference guide to what the _GDBN__ expression parser will accept, and
4695what input and output formats should look like for different languages.
4696There are many good books written on each of these languages; please
4697look to these for a language reference or tutorial.
4698
4699@menu
4700* C:: C and C++
4701* Modula-2:: Modula-2
4702@end menu
4703
4eb4cf57 4704@node C
c2bbbb22 4705@subsection C and C++
4eb4cf57
RP
4706_fi__(!_CONLY__)
4707_if__(_CONLY__)
4708@node C
4709@chapter C and C++
4710_fi__(_CONLY__)
c2bbbb22
RP
4711@cindex C and C++
4712
4713@cindex expressions in C or C++
5a2c1d85
RP
4714Since C and C++ are so closely related, many features of _GDBN__ apply
4715to both languages. Whenever this is the case, we discuss both languages
4716together.
b80282d5
RP
4717
4718@cindex C++
4719@kindex g++
4720@cindex GNU C++
c2bbbb22
RP
4721The C++ debugging facilities are jointly implemented by the GNU C++
4722compiler and _GDBN__. Therefore, to debug your C++ code effectively,
4723you must compile your C++ programs with the GNU C++ compiler,
4724@code{g++}.
4725
b80282d5 4726@menu
c2bbbb22
RP
4727* C Operators:: C and C++ Operators
4728* C Constants:: C and C++ Constants
4729* Cplusplus expressions:: C++ Expressions
4eb4cf57 4730_if__(!_CONLY__)
c2bbbb22 4731* C Defaults:: Default settings for C and C++
4eb4cf57 4732_fi__(!_CONLY__)
c2bbbb22
RP
4733* C Checks:: C and C++ Type and Range Checks
4734* Debugging C:: _GDBN__ and C
4735* Debugging C plus plus:: Special features for C++
b80282d5
RP
4736@end menu
4737
c2bbbb22 4738@cindex C and C++ operators
4eb4cf57
RP
4739@node C Operators
4740_if__(!_CONLY__)
c2bbbb22 4741@subsubsection C and C++ Operators
4eb4cf57
RP
4742_fi__(!_CONLY__)
4743_if__(_CONLY__)
4744@section C and C++ Operators
4745_fi__(_CONLY__)
c2bbbb22
RP
4746
4747Operators must be defined on values of specific types. For instance,
4748@code{+} is defined on numbers, but not on structures. Operators are
4749often defined on groups of types. For the purposes of C and C++, the
4750following definitions hold:
4751
4752@itemize @bullet
e251e767 4753@item
c2bbbb22
RP
4754@emph{Integral types} include @code{int} with any of its storage-class
4755specifiers, @code{char}, and @code{enum}s.
4756
4757@item
4758@emph{Floating-point types} include @code{float} and @code{double}.
4759
4760@item
4761@emph{Pointer types} include all types defined as @code{(@var{type}
4762*)}.
4763
e251e767 4764@item
c2bbbb22 4765@emph{Scalar types} include all of the above.
c2bbbb22
RP
4766@end itemize
4767
4768@noindent
4769The following operators are supported. They are listed here
4770in order of increasing precedence:
4771
4772@table @code
1041a570 4773_0__@item ,
c2bbbb22
RP
4774The comma or sequencing operator. Expressions in a comma-separated list
4775are evaluated from left to right, with the result of the entire
4776expression being the last expression evaluated.
4777
4778@item =
4779Assignment. The value of an assignment expression is the value
4780assigned. Defined on scalar types.
4781
4782@item @var{op}=
1041a570
RP
4783Used in an expression of the form @w{@code{@var{a} @var{op}= @var{b}}},
4784and translated to @w{@code{@var{a} = @var{a op b}}}.
4785@w{@code{@var{op}=}} and @code{=} have the same precendence.
4786@var{op} is any one of the operators @code{|}, @code{^}, @code{&},
4787@code{<<}, @code{>>}, @code{+}, @code{-}, @code{*}, @code{/}, @code{%}.
c2bbbb22
RP
4788
4789@item ?:
4790The ternary operator. @code{@var{a} ? @var{b} : @var{c}} can be thought
4791of as: if @var{a} then @var{b} else @var{c}. @var{a} should be of an
4792integral type.
4793
4794@item ||
1041a570 4795Logical @sc{or}. Defined on integral types.
c2bbbb22
RP
4796
4797@item &&
1041a570 4798Logical @sc{and}. Defined on integral types.
c2bbbb22
RP
4799
4800@item |
1041a570 4801Bitwise @sc{or}. Defined on integral types.
c2bbbb22
RP
4802
4803@item ^
1041a570 4804Bitwise exclusive-@sc{or}. Defined on integral types.
c2bbbb22
RP
4805
4806@item &
1041a570 4807Bitwise @sc{and}. Defined on integral types.
c2bbbb22
RP
4808
4809@item ==@r{, }!=
4810Equality and inequality. Defined on scalar types. The value of these
4811expressions is 0 for false and non-zero for true.
4812
4813@item <@r{, }>@r{, }<=@r{, }>=
4814Less than, greater than, less than or equal, greater than or equal.
4815Defined on scalar types. The value of these expressions is 0 for false
4816and non-zero for true.
4817
4818@item <<@r{, }>>
4819left shift, and right shift. Defined on integral types.
4820
e251e767 4821@item @@
1041a570 4822The _GDBN__ ``artificial array'' operator (@pxref{Expressions, ,Expressions}).
c2bbbb22
RP
4823
4824@item +@r{, }-
4825Addition and subtraction. Defined on integral types, floating-point types and
e251e767 4826pointer types.
c2bbbb22
RP
4827
4828@item *@r{, }/@r{, }%
4829Multiplication, division, and modulus. Multiplication and division are
4830defined on integral and floating-point types. Modulus is defined on
4831integral types.
4832
4833@item ++@r{, }--
4834Increment and decrement. When appearing before a variable, the
4835operation is performed before the variable is used in an expression;
4836when appearing after it, the variable's value is used before the
4837operation takes place.
4838
4839@item *
4840Pointer dereferencing. Defined on pointer types. Same precedence as
4841@code{++}.
4842
4843@item &
4844Address operator. Defined on variables. Same precedence as @code{++}.
4845
6ca72cc6
RP
4846For debugging C++, _GDBN__ implements a use of @samp{&} beyond what's
4847allowed in the C++ language itself: you can use @samp{&(&@var{ref})}
4848(or, if you prefer, simply @samp{&&@var{ref}} to examine the address
4849where a C++ reference variable (declared with @samp{&@var{ref}}) is
4850stored.
4851
c2bbbb22
RP
4852@item -
4853Negative. Defined on integral and floating-point types. Same
4854precedence as @code{++}.
4855
4856@item !
4857Logical negation. Defined on integral types. Same precedence as
4858@code{++}.
4859
4860@item ~
4861Bitwise complement operator. Defined on integral types. Same precedence as
4862@code{++}.
4863
4864@item .@r{, }->
4865Structure member, and pointer-to-structure member. For convenience,
4866_GDBN__ regards the two as equivalent, choosing whether to dereference a
e251e767 4867pointer based on the stored type information.
c2bbbb22
RP
4868Defined on @code{struct}s and @code{union}s.
4869
4870@item []
4871Array indexing. @code{@var{a}[@var{i}]} is defined as
4872@code{*(@var{a}+@var{i})}. Same precedence as @code{->}.
4873
4874@item ()
4875Function parameter list. Same precedence as @code{->}.
4876
4877@item ::
4878C++ scope resolution operator. Defined on
4879@code{struct}, @code{union}, and @code{class} types.
4880
4881@item ::
1041a570
RP
4882The _GDBN__ scope operator (@pxref{Expressions, ,Expressions}). Same precedence as
4883@code{::}, above._1__
c2bbbb22
RP
4884@end table
4885
4886@cindex C and C++ constants
4eb4cf57
RP
4887@node C Constants
4888_if__(!_CONLY__)
c2bbbb22 4889@subsubsection C and C++ Constants
4eb4cf57
RP
4890_fi__(!_CONLY__)
4891_if__(_CONLY__)
4892@section C and C++ Constants
4893_fi__(_CONLY__)
c2bbbb22
RP
4894
4895_GDBN__ allows you to express the constants of C and C++ in the
4896following ways:
4897
4898@itemize @bullet
c2bbbb22
RP
4899@item
4900Integer constants are a sequence of digits. Octal constants are
4901specified by a leading @samp{0} (ie. zero), and hexadecimal constants by
1041a570 4902a leading @samp{0x} or @samp{0X}. Constants may also end with a letter
c2bbbb22
RP
4903@samp{l}, specifying that the constant should be treated as a
4904@code{long} value.
4905
4906@item
4907Floating point constants are a sequence of digits, followed by a decimal
4908point, followed by a sequence of digits, and optionally followed by an
4909exponent. An exponent is of the form:
4910@samp{@w{e@r{[[}+@r{]|}-@r{]}@var{nnn}}}, where @var{nnn} is another
4911sequence of digits. The @samp{+} is optional for positive exponents.
4912
4913@item
4914Enumerated constants consist of enumerated identifiers, or their
4915integral equivalents.
4916
4917@item
4918Character constants are a single character surrounded by single quotes
4919(@code{'}), or a number---the ordinal value of the corresponding character
4920(usually its @sc{ASCII} value). Within quotes, the single character may
4921be represented by a letter or by @dfn{escape sequences}, which are of
4922the form @samp{\@var{nnn}}, where @var{nnn} is the octal representation
4923of the character's ordinal value; or of the form @samp{\@var{x}}, where
4924@samp{@var{x}} is a predefined special character---for example,
4925@samp{\n} for newline.
4926
4927@item
4928String constants are a sequence of character constants surrounded
4929by double quotes (@code{"}).
4930
4931@item
4932Pointer constants are an integral value.
c2bbbb22
RP
4933@end itemize
4934
4eb4cf57
RP
4935@node Cplusplus expressions
4936_if__(!_CONLY__)
c2bbbb22 4937@subsubsection C++ Expressions
4eb4cf57
RP
4938_fi__(!_CONLY__)
4939_if__(_CONLY__)
4940@section C++ Expressions
4941_fi__(_CONLY__)
b80282d5
RP
4942
4943@cindex expressions in C++
b1385986
RP
4944_GDBN__'s expression handling has a number of extensions to
4945interpret a significant subset of C++ expressions.
4946
4947@cindex C++ support, not in @sc{coff}
4948@cindex @sc{coff} versus C++
4949@cindex C++ and object formats
4950@cindex object formats and C++
4951@cindex a.out and C++
4952@cindex @sc{ecoff} and C++
4953@cindex @sc{xcoff} and C++
4954@cindex @sc{elf}/stabs and C++
4955@cindex @sc{elf}/@sc{dwarf} and C++
4956@quotation
4957@emph{Warning:} Most of these extensions depend on the use of additional
4958debugging information in the symbol table, and thus require a rich,
4959extendable object code format. In particular, if your system uses
4960a.out, MIPS @sc{ecoff}, RS/6000 @sc{xcoff}, or Sun @sc{elf} with stabs
4961extensions to the symbol table, these facilities are all available.
4962Where the object code format is standard @sc{coff}, on the other hand,
4963most of the C++ support in _GDBN__ will @emph{not} work, nor can it.
4964For the standard SVr4 debugging format, @sc{dwarf} in @sc{elf}, the
4965standard is still evolving, so the C++ support in _GDBN__ is still
4966fragile; when this debugging format stabilizes, however, C++ support
4967will also be available on systems that use it.
4968@end quotation
b80282d5
RP
4969
4970@enumerate
4971
4972@cindex member functions
e251e767 4973@item
b80282d5 4974Member function calls are allowed; you can use expressions like
1041a570 4975
b80282d5
RP
4976@example
4977count = aml->GetOriginal(x, y)
4978@end example
4979
4980@kindex this
4981@cindex namespace in C++
e251e767 4982@item
b80282d5
RP
4983While a member function is active (in the selected stack frame), your
4984expressions have the same namespace available as the member function;
4985that is, _GDBN__ allows implicit references to the class instance
4986pointer @code{this} following the same rules as C++.
4987
4988@cindex call overloaded functions
4989@cindex type conversions in C++
e251e767 4990@item
b80282d5
RP
4991You can call overloaded functions; _GDBN__ will resolve the function
4992call to the right definition, with one restriction---you must use
4993arguments of the type required by the function that you want to call.
4994_GDBN__ will not perform conversions requiring constructors or
4995user-defined type operators.
4996
4997@cindex reference declarations
4998@item
4999_GDBN__ understands variables declared as C++ references; you can use them in
5000expressions just as you do in C++ source---they are automatically
e251e767 5001dereferenced.
b80282d5
RP
5002
5003In the parameter list shown when _GDBN__ displays a frame, the values of
5004reference variables are not displayed (unlike other variables); this
5005avoids clutter, since references are often used for large structures.
5006The @emph{address} of a reference variable is always shown, unless
1041a570 5007you have specified @samp{set print address off}.
b80282d5
RP
5008
5009@item
5010_GDBN__ supports the C++ name resolution operator @code{::}---your
c2bbbb22
RP
5011expressions can use it just as expressions in your program do. Since
5012one scope may be defined in another, you can use @code{::} repeatedly if
5013necessary, for example in an expression like
5014@samp{@var{scope1}::@var{scope2}::@var{name}}. _GDBN__ also allows
5015resolving name scope by reference to source files, in both C and C++
1041a570 5016debugging (@pxref{Variables, ,Program Variables}).
b80282d5
RP
5017@end enumerate
5018
4eb4cf57
RP
5019_if__(!_CONLY__)
5020@node C Defaults
c2bbbb22
RP
5021@subsubsection C and C++ Defaults
5022@cindex C and C++ defaults
5023
e251e767
RP
5024If you allow _GDBN__ to set type and range checking automatically, they
5025both default to @code{off} whenever the working language changes to
5a2c1d85 5026C or C++. This happens regardless of whether you, or _GDBN__,
c2bbbb22
RP
5027selected the working language.
5028
5029If you allow _GDBN__ to set the language automatically, it sets the
5a2c1d85
RP
5030working language to C or C++ on entering code compiled from a source file
5031whose name ends with @file{.c}, @file{.C}, or @file{.cc}.
1041a570 5032@xref{Automatically, ,Having _GDBN__ infer the source language}, for
c2bbbb22 5033further details.
4eb4cf57 5034_fi__(!_CONLY__)
c2bbbb22 5035
4eb4cf57
RP
5036@node C Checks
5037_if__(!_CONLY__)
c2bbbb22 5038@subsubsection C and C++ Type and Range Checks
4eb4cf57
RP
5039_fi__(!_CONLY__)
5040_if__(_CONLY__)
5041@section C and C++ Type and Range Checks
5042_fi__(_CONLY__)
c2bbbb22
RP
5043@cindex C and C++ checks
5044
5045@quotation
5046@emph{Warning:} in this release, _GDBN__ does not yet perform type or
5047range checking.
5048@end quotation
5049@c FIXME remove warning when type/range checks added
5050
5051By default, when _GDBN__ parses C or C++ expressions, type checking
5052is not used. However, if you turn type checking on, _GDBN__ will
5053consider two variables type equivalent if:
5054
5055@itemize @bullet
5056@item
5057The two variables are structured and have the same structure, union, or
5058enumerated tag.
5059
e251e767 5060@item
c2bbbb22
RP
5061Two two variables have the same type name, or types that have been
5062declared equivalent through @code{typedef}.
5063
5064@ignore
5065@c leaving this out because neither J Gilmore nor R Pesch understand it.
5066@c FIXME--beers?
5067@item
5068The two @code{struct}, @code{union}, or @code{enum} variables are
5069declared in the same declaration. (Note: this may not be true for all C
5070compilers.)
5071@end ignore
c2bbbb22
RP
5072@end itemize
5073
5074Range checking, if turned on, is done on mathematical operations. Array
5075indices are not checked, since they are often used to index a pointer
5076that is not itself an array.
5077
4eb4cf57
RP
5078@node Debugging C
5079_if__(!_CONLY__)
c2bbbb22 5080@subsubsection _GDBN__ and C
4eb4cf57
RP
5081_fi__(!_CONLY__)
5082_if__(_CONLY__)
5083@section _GDBN__ and C
5084_fi__(_CONLY__)
c2bbbb22
RP
5085
5086The @code{set print union} and @code{show print union} commands apply to
5087the @code{union} type. When set to @samp{on}, any @code{union} that is
5088inside a @code{struct} or @code{class} will also be printed.
5089Otherwise, it will appear as @samp{@{...@}}.
5090
5091The @code{@@} operator aids in the debugging of dynamic arrays, formed
1041a570 5092with pointers and a memory allocation function. (@pxref{Expressions, ,Expressions})
c2bbbb22 5093
4eb4cf57
RP
5094@node Debugging C plus plus
5095_if__(!_CONLY__)
6f3ec223 5096@subsubsection _GDBN__ Features for C++
4eb4cf57
RP
5097_fi__(!_CONLY__)
5098_if__(_CONLY__)
5099@section _GDBN__ Features for C++
5100_fi__(_CONLY__)
b80282d5
RP
5101
5102@cindex commands for C++
5103Some _GDBN__ commands are particularly useful with C++, and some are
5104designed specifically for use with C++. Here is a summary:
5105
5106@table @code
5107@cindex break in overloaded functions
5108@item @r{breakpoint menus}
5109When you want a breakpoint in a function whose name is overloaded,
5110_GDBN__'s breakpoint menus help you specify which function definition
5111you want. @xref{Breakpoint Menus}.
5112
5113@cindex overloading in C++
5114@item rbreak @var{regex}
5115Setting breakpoints using regular expressions is helpful for setting
5116breakpoints on overloaded functions that are not members of any special
e251e767 5117classes.
29a2b744 5118@xref{Set Breaks, ,Setting Breakpoints}.
b80282d5
RP
5119
5120@cindex C++ exception handling
5121@item catch @var{exceptions}
5122@itemx info catch
29a2b744 5123Debug C++ exception handling using these commands. @xref{Exception
1041a570 5124Handling, ,Breakpoints and Exceptions}.
b80282d5 5125
e251e767 5126@cindex inheritance
b80282d5
RP
5127@item ptype @var{typename}
5128Print inheritance relationships as well as other information for type
e251e767 5129@var{typename}.
1041a570 5130@xref{Symbols, ,Examining the Symbol Table}.
b80282d5
RP
5131
5132@cindex C++ symbol display
5133@item set print demangle
5134@itemx show print demangle
5135@itemx set print asm-demangle
5136@itemx show print asm-demangle
5137Control whether C++ symbols display in their source form, both when
5138displaying code as C++ source and when displaying disassemblies.
1041a570 5139@xref{Print Settings, ,Print Settings}.
b80282d5
RP
5140
5141@item set print object
5142@itemx show print object
e251e767 5143Choose whether to print derived (actual) or declared types of objects.
1041a570 5144@xref{Print Settings, ,Print Settings}.
b80282d5
RP
5145
5146@item set print vtbl
5147@itemx show print vtbl
5148Control the format for printing virtual function tables.
1041a570 5149@xref{Print Settings, ,Print Settings}.
6f3ec223
RP
5150
5151@item @r{Overloaded symbol names}
5152You can specify a particular definition of an overloaded symbol, using
5153the same notation that's used to declare such symbols in C++: type
5154@code{@var{symbol}(@var{types})} rather than just @var{symbol}. You can
5155also use _GDBN__'s command-line word completion facilities to list the
5156available choices, or to finish the type list for you.
5157@xref{Completion,, Command Completion}, for details on how to do this.
b80282d5
RP
5158@end table
5159
4eb4cf57
RP
5160_if__(!_CONLY__)
5161@node Modula-2
c2bbbb22
RP
5162@subsection Modula-2
5163@cindex Modula-2
5164
5165The extensions made to _GDBN__ to support Modula-2 support output
5166from the GNU Modula-2 compiler (which is currently being developed).
5167Other Modula-2 compilers are not currently supported, and attempting to
5168debug executables produced by them will most likely result in an error
5169as _GDBN__ reads in the executable's symbol table.
5170
5171@cindex expressions in Modula-2
5172@menu
5173* M2 Operators:: Built-in operators
29a2b744 5174* Built-In Func/Proc:: Built-in Functions and Procedures
c2bbbb22
RP
5175* M2 Constants:: Modula-2 Constants
5176* M2 Defaults:: Default settings for Modula-2
5177* Deviations:: Deviations from standard Modula-2
5178* M2 Checks:: Modula-2 Type and Range Checks
5179* M2 Scope:: The scope operators @code{::} and @code{.}
5180* GDB/M2:: _GDBN__ and Modula-2
5181@end menu
5182
4eb4cf57 5183@node M2 Operators
c2bbbb22
RP
5184@subsubsection Operators
5185@cindex Modula-2 operators
5186
5187Operators must be defined on values of specific types. For instance,
5188@code{+} is defined on numbers, but not on structures. Operators are
5189often defined on groups of types. For the purposes of Modula-2, the
5190following definitions hold:
5191
5192@itemize @bullet
5193
5194@item
5195@emph{Integral types} consist of @code{INTEGER}, @code{CARDINAL}, and
5196their subranges.
5197
5198@item
5199@emph{Character types} consist of @code{CHAR} and its subranges.
5200
5201@item
5202@emph{Floating-point types} consist of @code{REAL}.
5203
5204@item
5205@emph{Pointer types} consist of anything declared as @code{POINTER TO
5206@var{type}}.
5207
5208@item
5209@emph{Scalar types} consist of all of the above.
5210
5211@item
5212@emph{Set types} consist of @code{SET}s and @code{BITSET}s.
5213
5214@item
5215@emph{Boolean types} consist of @code{BOOLEAN}.
c2bbbb22
RP
5216@end itemize
5217
5218@noindent
5219The following operators are supported, and appear in order of
5220increasing precedence:
5221
5222@table @code
c2bbbb22
RP
5223@item ,
5224Function argument or array index separator.
1041a570 5225_0__
c2bbbb22
RP
5226@item :=
5227Assignment. The value of @var{var} @code{:=} @var{value} is
5228@var{value}.
5229
5230@item <@r{, }>
5231Less than, greater than on integral, floating-point, or enumerated
5232types.
5233
5234@item <=@r{, }>=
5235Less than, greater than, less than or equal to, greater than or equal to
5236on integral, floating-point and enumerated types, or set inclusion on
5237set types. Same precedence as @code{<}.
5238
5239@item =@r{, }<>@r{, }#
5240Equality and two ways of expressing inequality, valid on scalar types.
5241Same precedence as @code{<}. In _GDBN__ scripts, only @code{<>} is
5242available for inequality, since @code{#} conflicts with the script
5243comment character.
5244
5245@item IN
5246Set membership. Defined on set types and the types of their members.
5247Same precedence as @code{<}.
5248
5249@item OR
5250Boolean disjunction. Defined on boolean types.
5251
5252@item AND@r{, }&
5253Boolean conjuction. Defined on boolean types.
5254
5255@item @@
1041a570 5256The _GDBN__ ``artificial array'' operator (@pxref{Expressions, ,Expressions}).
c2bbbb22
RP
5257
5258@item +@r{, }-
5259Addition and subtraction on integral and floating-point types, or union
5260and difference on set types.
5261
5262@item *
5263Multiplication on integral and floating-point types, or set intersection
5264on set types.
5265
5266@item /
5267Division on floating-point types, or symmetric set difference on set
5268types. Same precedence as @code{*}.
5269
5270@item DIV@r{, }MOD
5271Integer division and remainder. Defined on integral types. Same
5272precedence as @code{*}.
5273
5274@item -
5275Negative. Defined on @code{INTEGER}s and @code{REAL}s.
5276
5277@item ^
e251e767 5278Pointer dereferencing. Defined on pointer types.
c2bbbb22
RP
5279
5280@item NOT
5281Boolean negation. Defined on boolean types. Same precedence as
5282@code{^}.
5283
5284@item .
5285@code{RECORD} field selector. Defined on @code{RECORD}s. Same
5286precedence as @code{^}.
5287
5288@item []
5289Array indexing. Defined on @code{ARRAY}s. Same precedence as @code{^}.
5290
5291@item ()
5292Procedure argument list. Defined on @code{PROCEDURE}s. Same precedence
5293as @code{^}.
5294
5295@item ::@r{, }.
5296_GDBN__ and Modula-2 scope operators.
c2bbbb22
RP
5297@end table
5298
5299@quotation
5300@emph{Warning:} Sets and their operations are not yet supported, so _GDBN__
5301will treat the use of the operator @code{IN}, or the use of operators
5302@code{+}, @code{-}, @code{*}, @code{/}, @code{=}, , @code{<>}, @code{#},
5303@code{<=}, and @code{>=} on sets as an error.
5304@end quotation
5305_1__
29a2b744 5306@cindex Modula-2 built-ins
4eb4cf57 5307@node Built-In Func/Proc
c2bbbb22
RP
5308@subsubsection Built-in Functions and Procedures
5309
5310Modula-2 also makes available several built-in procedures and functions.
5311In describing these, the following metavariables are used:
5312
5313@table @var
5314
5315@item a
5316represents an @code{ARRAY} variable.
5317
5318@item c
5319represents a @code{CHAR} constant or variable.
5320
5321@item i
5322represents a variable or constant of integral type.
5323
5324@item m
5325represents an identifier that belongs to a set. Generally used in the
5326same function with the metavariable @var{s}. The type of @var{s} should
5327be @code{SET OF @var{mtype}} (where @var{mtype} is the type of @var{m}.
5328
5329@item n
5330represents a variable or constant of integral or floating-point type.
5331
5332@item r
5333represents a variable or constant of floating-point type.
5334
5335@item t
5336represents a type.
5337
5338@item v
5339represents a variable.
5340
5341@item x
5342represents a variable or constant of one of many types. See the
5343explanation of the function for details.
c2bbbb22
RP
5344@end table
5345
5346All Modula-2 built-in procedures also return a result, described below.
5347
5348@table @code
5349@item ABS(@var{n})
5350Returns the absolute value of @var{n}.
5351
5352@item CAP(@var{c})
5353If @var{c} is a lower case letter, it returns its upper case
5354equivalent, otherwise it returns its argument
5355
5356@item CHR(@var{i})
5357Returns the character whose ordinal value is @var{i}.
5358
5359@item DEC(@var{v})
5360Decrements the value in the variable @var{v}. Returns the new value.
5361
5362@item DEC(@var{v},@var{i})
5363Decrements the value in the variable @var{v} by @var{i}. Returns the
5364new value.
5365
5366@item EXCL(@var{m},@var{s})
5367Removes the element @var{m} from the set @var{s}. Returns the new
5368set.
5369
5370@item FLOAT(@var{i})
5371Returns the floating point equivalent of the integer @var{i}.
5372
5373@item HIGH(@var{a})
5374Returns the index of the last member of @var{a}.
5375
5376@item INC(@var{v})
5377Increments the value in the variable @var{v}. Returns the new value.
5378
5379@item INC(@var{v},@var{i})
5380Increments the value in the variable @var{v} by @var{i}. Returns the
5381new value.
5382
5383@item INCL(@var{m},@var{s})
5384Adds the element @var{m} to the set @var{s} if it is not already
5385there. Returns the new set.
5386
5387@item MAX(@var{t})
5388Returns the maximum value of the type @var{t}.
5389
5390@item MIN(@var{t})
5391Returns the minimum value of the type @var{t}.
5392
5393@item ODD(@var{i})
5394Returns boolean TRUE if @var{i} is an odd number.
5395
5396@item ORD(@var{x})
5397Returns the ordinal value of its argument. For example, the ordinal
5398value of a character is its ASCII value (on machines supporting the
5399ASCII character set). @var{x} must be of an ordered type, which include
5400integral, character and enumerated types.
5401
5402@item SIZE(@var{x})
5403Returns the size of its argument. @var{x} can be a variable or a type.
5404
5405@item TRUNC(@var{r})
5406Returns the integral part of @var{r}.
5407
5408@item VAL(@var{t},@var{i})
5409Returns the member of the type @var{t} whose ordinal value is @var{i}.
5410@end table
5411
5412@quotation
5413@emph{Warning:} Sets and their operations are not yet supported, so
5414_GDBN__ will treat the use of procedures @code{INCL} and @code{EXCL} as
5415an error.
5416@end quotation
5417
5418@cindex Modula-2 constants
4eb4cf57 5419@node M2 Constants
c2bbbb22
RP
5420@subsubsection Constants
5421
5422_GDBN__ allows you to express the constants of Modula-2 in the following
5423ways:
5424
5425@itemize @bullet
5426
5427@item
5428Integer constants are simply a sequence of digits. When used in an
5429expression, a constant is interpreted to be type-compatible with the
5430rest of the expression. Hexadecimal integers are specified by a
5431trailing @samp{H}, and octal integers by a trailing @samp{B}.
5432
5433@item
5434Floating point constants appear as a sequence of digits, followed by a
5435decimal point and another sequence of digits. An optional exponent can
5436then be specified, in the form @samp{E@r{[}+@r{|}-@r{]}@var{nnn}}, where
5437@samp{@r{[}+@r{|}-@r{]}@var{nnn}} is the desired exponent. All of the
5438digits of the floating point constant must be valid decimal (base 10)
5439digits.
5440
5441@item
5442Character constants consist of a single character enclosed by a pair of
5443like quotes, either single (@code{'}) or double (@code{"}). They may
5444also be expressed by their ordinal value (their ASCII value, usually)
5445followed by a @samp{C}.
5446
5447@item
1041a570
RP
5448String constants consist of a sequence of characters enclosed by a
5449pair of like quotes, either single (@code{'}) or double (@code{"}).
5450Escape sequences in the style of C are also allowed. @xref{C
5451Constants, ,C and C++ Constants}, for a brief explanation of escape
5452sequences.
c2bbbb22
RP
5453
5454@item
5455Enumerated constants consist of an enumerated identifier.
5456
5457@item
5458Boolean constants consist of the identifiers @code{TRUE} and
5459@code{FALSE}.
5460
5461@item
5462Pointer constants consist of integral values only.
5463
5464@item
5465Set constants are not yet supported.
c2bbbb22
RP
5466@end itemize
5467
4eb4cf57 5468@node M2 Defaults
c2bbbb22
RP
5469@subsubsection Modula-2 Defaults
5470@cindex Modula-2 defaults
5471
e251e767
RP
5472If type and range checking are set automatically by _GDBN__, they
5473both default to @code{on} whenever the working language changes to
c2bbbb22
RP
5474Modula-2. This happens regardless of whether you, or _GDBN__,
5475selected the working language.
5476
5477If you allow _GDBN__ to set the language automatically, then entering
5478code compiled from a file whose name ends with @file{.mod} will set the
1041a570 5479working language to Modula-2. @xref{Automatically, ,Having _GDBN__ set
c2bbbb22
RP
5480the language automatically}, for further details.
5481
4eb4cf57 5482@node Deviations
c2bbbb22
RP
5483@subsubsection Deviations from Standard Modula-2
5484@cindex Modula-2, deviations from
5485
5486A few changes have been made to make Modula-2 programs easier to debug.
5487This is done primarily via loosening its type strictness:
5488
5489@itemize @bullet
e251e767 5490@item
c2bbbb22
RP
5491Unlike in standard Modula-2, pointer constants can be formed by
5492integers. This allows you to modify pointer variables during
5493debugging. (In standard Modula-2, the actual address contained in a
5494pointer variable is hidden from you; it can only be modified
5495through direct assignment to another pointer variable or expression that
5496returned a pointer.)
5497
e251e767 5498@item
c2bbbb22
RP
5499C escape sequences can be used in strings and characters to represent
5500non-printable characters. _GDBN__ will print out strings with these
5501escape sequences embedded. Single non-printable characters are
5502printed using the @samp{CHR(@var{nnn})} format.
5503
5504@item
5505The assignment operator (@code{:=}) returns the value of its right-hand
5506argument.
5507
5508@item
29a2b744 5509All built-in procedures both modify @emph{and} return their argument.
e251e767 5510@end itemize
c2bbbb22 5511
4eb4cf57 5512@node M2 Checks
c2bbbb22
RP
5513@subsubsection Modula-2 Type and Range Checks
5514@cindex Modula-2 checks
5515
5516@quotation
5517@emph{Warning:} in this release, _GDBN__ does not yet perform type or
5518range checking.
5519@end quotation
5520@c FIXME remove warning when type/range checks added
5521
5522_GDBN__ considers two Modula-2 variables type equivalent if:
5523
5524@itemize @bullet
5525@item
5526They are of types that have been declared equivalent via a @code{TYPE
5527@var{t1} = @var{t2}} statement
5528
5529@item
5530They have been declared on the same line. (Note: This is true of the
5531GNU Modula-2 compiler, but it may not be true of other compilers.)
c2bbbb22
RP
5532@end itemize
5533
5534As long as type checking is enabled, any attempt to combine variables
5535whose types are not equivalent is an error.
5536
5537Range checking is done on all mathematical operations, assignment, array
29a2b744 5538index bounds, and all built-in functions and procedures.
c2bbbb22 5539
4eb4cf57 5540@node M2 Scope
c2bbbb22
RP
5541@subsubsection The scope operators @code{::} and @code{.}
5542@cindex scope
5543@kindex .
e94b4a2b 5544@cindex colon, doubled as scope operator
1041a570
RP
5545@ifinfo
5546@kindex colon-colon
5547@c Info cannot handoe :: but TeX can.
5548@end ifinfo
5549@iftex
c2bbbb22 5550@kindex ::
1041a570 5551@end iftex
c2bbbb22
RP
5552
5553There are a few subtle differences between the Modula-2 scope operator
5554(@code{.}) and the _GDBN__ scope operator (@code{::}). The two have
5555similar syntax:
5556
5557@example
5558
5559@var{module} . @var{id}
5560@var{scope} :: @var{id}
c2bbbb22
RP
5561@end example
5562
5563@noindent
5564where @var{scope} is the name of a module or a procedure,
29a2b744
RP
5565@var{module} the name of a module, and @var{id} is any declared
5566identifier within your program, except another module.
c2bbbb22
RP
5567
5568Using the @code{::} operator makes _GDBN__ search the scope
5569specified by @var{scope} for the identifier @var{id}. If it is not
5570found in the specified scope, then _GDBN__ will search all scopes
5571enclosing the one specified by @var{scope}.
5572
5573Using the @code{.} operator makes _GDBN__ search the current scope for
5574the identifier specified by @var{id} that was imported from the
5575definition module specified by @var{module}. With this operator, it is
5576an error if the identifier @var{id} was not imported from definition
5577module @var{module}, or if @var{id} is not an identifier in
5578@var{module}.
5579
4eb4cf57 5580@node GDB/M2
c2bbbb22
RP
5581@subsubsection _GDBN__ and Modula-2
5582
5583Some _GDBN__ commands have little use when debugging Modula-2 programs.
5584Five subcommands of @code{set print} and @code{show print} apply
5585specifically to C and C++: @samp{vtbl}, @samp{demangle},
5586@samp{asm-demangle}, @samp{object}, and @samp{union}. The first four
5587apply to C++, and the last to C's @code{union} type, which has no direct
5588analogue in Modula-2.
5589
1041a570 5590The @code{@@} operator (@pxref{Expressions, ,Expressions}), while available
c2bbbb22
RP
5591while using any language, is not useful with Modula-2. Its
5592intent is to aid the debugging of @dfn{dynamic arrays}, which cannot be
5593created in Modula-2 as they can in C or C++. However, because an
5594address can be specified by an integral constant, the construct
1041a570 5595@samp{@{@var{type}@}@var{adrexp}} is still useful. (@pxref{Expressions, ,Expressions})
c2bbbb22
RP
5596_0__
5597@cindex @code{#} in Modula-2
5598In _GDBN__ scripts, the Modula-2 inequality operator @code{#} is
5599interpreted as the beginning of a comment. Use @code{<>} instead.
5600_1__
4eb4cf57
RP
5601_fi__(!_CONLY__)
5602
5603@node Symbols
70b88761
RP
5604@chapter Examining the Symbol Table
5605
5606The commands described in this section allow you to inquire about the
5607symbols (names of variables, functions and types) defined in your
5608program. This information is inherent in the text of your program and
29a2b744 5609does not change as your program executes. _GDBN__ finds it in your
e251e767 5610program's symbol table, in the file indicated when you started _GDBN__
1041a570
RP
5611(@pxref{File Options, ,Choosing Files}), or by one of the
5612file-management commands (@pxref{Files, ,Commands to Specify Files}).
70b88761 5613
6c380b13
RP
5614@c FIXME! This might be intentionally specific to C and C++; if so, move
5615@c to someplace in C section of lang chapter.
5616@cindex symbol names
5617@cindex names of symbols
5618@cindex quoting names
5619Occasionally, you may need to refer to symbols that contain unusual
5620characters, which _GDBN__ ordinarily treats as word delimiters. The
5621most frequent case is in referring to static variables in other
5622source files (@pxref{Variables,,Program Variables}). File names
5623are recorded in object files as debugging symbols, but _GDBN__ would
5624ordinarily parse a typical file name, like @file{foo.c}, as the three words
5625@samp{foo} @samp{.} @samp{c}. To allow _GDBN__ to recognize
5626@samp{foo.c} as a single symbol, enclose it in single quotes; for example,
5627
5628@example
5629p 'foo.c'::x
5630@end example
5631
5632@noindent
5633looks up the value of @code{x} in the scope of the file @file{foo.c}.
5634
70b88761
RP
5635@table @code
5636@item info address @var{symbol}
5637@kindex info address
5638Describe where the data for @var{symbol} is stored. For a register
5639variable, this says which register it is kept in. For a non-register
5640local variable, this prints the stack-frame offset at which the variable
5641is always stored.
5642
5643Note the contrast with @samp{print &@var{symbol}}, which does not work
5644at all for a register variables, and for a stack local variable prints
5645the exact address of the current instantiation of the variable.
5646
5647@item whatis @var{exp}
5648@kindex whatis
5649Print the data type of expression @var{exp}. @var{exp} is not
5650actually evaluated, and any side-effecting operations (such as
5651assignments or function calls) inside it do not take place.
1041a570 5652@xref{Expressions, ,Expressions}.
70b88761
RP
5653
5654@item whatis
5655Print the data type of @code{$}, the last value in the value history.
5656
5657@item ptype @var{typename}
5658@kindex ptype
5659Print a description of data type @var{typename}. @var{typename} may be
5660the name of a type, or for C code it may have the form
5661@samp{struct @var{struct-tag}}, @samp{union @var{union-tag}} or
1041a570 5662@samp{enum @var{enum-tag}}.
70b88761
RP
5663
5664@item ptype @var{exp}
e0dacfd1 5665@itemx ptype
70b88761 5666Print a description of the type of expression @var{exp}. @code{ptype}
1041a570
RP
5667differs from @code{whatis} by printing a detailed description, instead
5668of just the name of the type. For example, if your program declares a
5669variable as
5670
70b88761
RP
5671@example
5672struct complex @{double real; double imag;@} v;
5673@end example
1041a570 5674
70b88761
RP
5675@noindent
5676compare the output of the two commands:
1041a570 5677
70b88761 5678@example
1041a570 5679@group
70b88761
RP
5680(_GDBP__) whatis v
5681type = struct complex
5682(_GDBP__) ptype v
5683type = struct complex @{
5684 double real;
5685 double imag;
5686@}
1041a570 5687@end group
70b88761 5688@end example
1041a570 5689
e0dacfd1
RP
5690@noindent
5691As with @code{whatis}, using @code{ptype} without an argument refers to
5692the type of @code{$}, the last value in the value history.
70b88761
RP
5693
5694@item info types @var{regexp}
5695@itemx info types
e251e767 5696@kindex info types
70b88761
RP
5697Print a brief description of all types whose name matches @var{regexp}
5698(or all types in your program, if you supply no argument). Each
5699complete typename is matched as though it were a complete line; thus,
5700@samp{i type value} gives information on all types in your program whose
5701name includes the string @code{value}, but @samp{i type ^value$} gives
5702information only on types whose complete name is @code{value}.
5703
5704This command differs from @code{ptype} in two ways: first, like
5705@code{whatis}, it does not print a detailed description; second, it
5706lists all source files where a type is defined.
5707
5708@item info source
5709@kindex info source
5710Show the name of the current source file---that is, the source file for
c2bbbb22
RP
5711the function containing the current point of execution---and the language
5712it was written in.
70b88761
RP
5713
5714@item info sources
5715@kindex info sources
29a2b744 5716Print the names of all source files in your program for which there is
b80282d5
RP
5717debugging information, organized into two lists: files whose symbols
5718have already been read, and files whose symbols will be read when needed.
70b88761
RP
5719
5720@item info functions
5721@kindex info functions
5722Print the names and data types of all defined functions.
5723
5724@item info functions @var{regexp}
5725Print the names and data types of all defined functions
5726whose names contain a match for regular expression @var{regexp}.
5727Thus, @samp{info fun step} finds all functions whose names
5728include @code{step}; @samp{info fun ^step} finds those whose names
5729start with @code{step}.
5730
5731@item info variables
5732@kindex info variables
5733Print the names and data types of all variables that are declared
5734outside of functions (i.e., excluding local variables).
5735
5736@item info variables @var{regexp}
5737Print the names and data types of all variables (except for local
5738variables) whose names contain a match for regular expression
5739@var{regexp}.
5740
70b88761
RP
5741@ignore
5742This was never implemented.
5743@item info methods
5744@itemx info methods @var{regexp}
5745@kindex info methods
5746The @code{info methods} command permits the user to examine all defined
5747methods within C++ program, or (with the @var{regexp} argument) a
5748specific set of methods found in the various C++ classes. Many
5749C++ classes provide a large number of methods. Thus, the output
5750from the @code{ptype} command can be overwhelming and hard to use. The
5751@code{info-methods} command filters the methods, printing only those
5752which match the regular-expression @var{regexp}.
5753@end ignore
5754
d48da190
RP
5755@item maint print symbols @var{filename}
5756@itemx maint print psymbols @var{filename}
5757@itemx maint print msymbols @var{filename}
5758@kindex maint print symbols
440d9834 5759@cindex symbol dump
d48da190 5760@kindex maint print psymbols
440d9834
RP
5761@cindex partial symbol dump
5762Write a dump of debugging symbol data into the file @var{filename}.
e0dacfd1 5763These commands are used to debug the _GDBN__ symbol-reading code. Only
d48da190
RP
5764symbols with debugging data are included. If you use @samp{maint print
5765symbols}, _GDBN__ includes all the symbols for which it has already
5766collected full details: that is, @var{filename} reflects symbols for
5767only those files whose symbols _GDBN__ has read. You can use the
5768command @code{info sources} to find out which files these are. If you
5769use @samp{maint print psymbols} instead, the dump shows information about
5770symbols that _GDBN__ only knows partially---that is, symbols defined in
5771files that _GDBN__ has skimmed, but not yet read completely. Finally,
5772@samp{maint print msymbols} dumps just the minimal symbol information
5773required for each object file from which _GDBN__ has read some symbols.
5774The description of @code{symbol-file} explains how _GDBN__ reads
5775symbols; both @code{info source} and @code{symbol-file} are described in
5776@ref{Files, ,Commands to Specify Files}.
70b88761
RP
5777@end table
5778
4eb4cf57 5779@node Altering
70b88761
RP
5780@chapter Altering Execution
5781
29a2b744 5782Once you think you have found an error in your program, you might want to
70b88761
RP
5783find out for certain whether correcting the apparent error would lead to
5784correct results in the rest of the run. You can find the answer by
5785experiment, using the _GDBN__ features for altering execution of the
5786program.
5787
5788For example, you can store new values into variables or memory
29a2b744 5789locations, give your program a signal, restart it at a different address,
70b88761
RP
5790or even return prematurely from a function to its caller.
5791
5792@menu
b80282d5
RP
5793* Assignment:: Assignment to Variables
5794* Jumping:: Continuing at a Different Address
4eb4cf57 5795_if__(!_BARE__)
29a2b744 5796* Signaling:: Giving your program a Signal
4eb4cf57 5797_fi__(!_BARE__)
b80282d5
RP
5798* Returning:: Returning from a Function
5799* Calling:: Calling your Program's Functions
c338a2fd 5800* Patching:: Patching your Program
70b88761
RP
5801@end menu
5802
4eb4cf57 5803@node Assignment
70b88761
RP
5804@section Assignment to Variables
5805
5806@cindex assignment
5807@cindex setting variables
5808To alter the value of a variable, evaluate an assignment expression.
1041a570 5809@xref{Expressions, ,Expressions}. For example,
70b88761
RP
5810
5811@example
5812print x=4
5813@end example
5814
5815@noindent
1041a570 5816stores the value 4 into the variable @code{x}, and then prints the
4eb4cf57
RP
5817value of the assignment expression (which is 4).
5818_if__(!_CONLY__)
5819@xref{Languages, ,Using _GDBN__ with Different Languages}, for more
5820information on operators in supported languages.
5821_fi__(!_CONLY__)
70b88761 5822
70b88761
RP
5823@kindex set variable
5824@cindex variables, setting
5825If you are not interested in seeing the value of the assignment, use the
5826@code{set} command instead of the @code{print} command. @code{set} is
5827really the same as @code{print} except that the expression's value is not
1041a570 5828printed and is not put in the value history (@pxref{Value History, ,Value History}). The
70b88761
RP
5829expression is evaluated only for its effects.
5830
5831If the beginning of the argument string of the @code{set} command
5832appears identical to a @code{set} subcommand, use the @code{set
5833variable} command instead of just @code{set}. This command is identical
5834to @code{set} except for its lack of subcommands. For example, a
5835program might well have a variable @code{width}---which leads to
5836an error if we try to set a new value with just @samp{set width=13}, as
1041a570
RP
5837we might if @code{set width} did not happen to be a _GDBN__ command:
5838
70b88761
RP
5839@example
5840(_GDBP__) whatis width
5841type = double
5842(_GDBP__) p width
5843$4 = 13
5844(_GDBP__) set width=47
5845Invalid syntax in expression.
5846@end example
1041a570 5847
70b88761
RP
5848@noindent
5849The invalid expression, of course, is @samp{=47}. What we can do in
e251e767 5850order to actually set our program's variable @code{width} is
1041a570 5851
70b88761
RP
5852@example
5853(_GDBP__) set var width=47
5854@end example
5855
1041a570
RP
5856_GDBN__ allows more implicit conversions in assignments than C; you can
5857freely store an integer value into a pointer variable or vice versa,
5858and any structure can be converted to any other structure that is the
5859same length or shorter.
e251e767 5860@comment FIXME: how do structs align/pad in these conversions?
70b88761
RP
5861@comment /pesch@cygnus.com 18dec1990
5862
5863To store values into arbitrary places in memory, use the @samp{@{@dots{}@}}
5864construct to generate a value of specified type at a specified address
1041a570 5865(@pxref{Expressions, ,Expressions}). For example, @code{@{int@}0x83040} refers
70b88761
RP
5866to memory location @code{0x83040} as an integer (which implies a certain size
5867and representation in memory), and
5868
5869@example
5870set @{int@}0x83040 = 4
5871@end example
5872
5873@noindent
5874stores the value 4 into that memory location.
5875
4eb4cf57 5876@node Jumping
70b88761
RP
5877@section Continuing at a Different Address
5878
29a2b744 5879Ordinarily, when you continue your program, you do so at the place where
70b88761
RP
5880it stopped, with the @code{continue} command. You can instead continue at
5881an address of your own choosing, with the following commands:
5882
5883@table @code
5884@item jump @var{linespec}
5885@kindex jump
5886Resume execution at line @var{linespec}. Execution will stop
29a2b744
RP
5887immediately if there is a breakpoint there. @xref{List, ,Printing
5888Source Lines}, for a description of the different forms of
5889@var{linespec}.
70b88761
RP
5890
5891The @code{jump} command does not change the current stack frame, or
5892the stack pointer, or the contents of any memory location or any
5893register other than the program counter. If line @var{linespec} is in
5894a different function from the one currently executing, the results may
5895be bizarre if the two functions expect different patterns of arguments or
5896of local variables. For this reason, the @code{jump} command requests
5897confirmation if the specified line is not in the function currently
5898executing. However, even bizarre results are predictable if you are
29a2b744 5899well acquainted with the machine-language code of your program.
70b88761
RP
5900
5901@item jump *@var{address}
5902Resume execution at the instruction at address @var{address}.
5903@end table
5904
5905You can get much the same effect as the @code{jump} command by storing a
5906new value into the register @code{$pc}. The difference is that this
29a2b744 5907does not start your program running; it only changes the address where it
70b88761
RP
5908@emph{will} run when it is continued. For example,
5909
5910@example
5911set $pc = 0x485
5912@end example
5913
5914@noindent
5915causes the next @code{continue} command or stepping command to execute at
1041a570
RP
5916address @code{0x485}, rather than at the address where your program stopped.
5917@xref{Continuing and Stepping, ,Continuing and Stepping}.
70b88761
RP
5918
5919The most common occasion to use the @code{jump} command is to back up,
5920perhaps with more breakpoints set, over a portion of a program that has
5921already executed, in order to examine its execution in more detail.
5922
4eb4cf57
RP
5923_if__(!_BARE__)
5924@node Signaling
70b88761 5925@c @group
29a2b744 5926@section Giving your program a Signal
70b88761
RP
5927
5928@table @code
5929@item signal @var{signalnum}
5930@kindex signal
29a2b744 5931Resume execution where your program stopped, but give it immediately the
70b88761
RP
5932signal number @var{signalnum}.
5933
5934Alternatively, if @var{signalnum} is zero, continue execution without
29a2b744 5935giving a signal. This is useful when your program stopped on account of
70b88761
RP
5936a signal and would ordinary see the signal when resumed with the
5937@code{continue} command; @samp{signal 0} causes it to resume without a
5938signal.
5939
5940@code{signal} does not repeat when you press @key{RET} a second time
5941after executing the command.
5942@end table
5943@c @end group
4eb4cf57 5944_fi__(!_BARE__)
70b88761 5945
4eb4cf57 5946@node Returning
70b88761
RP
5947@section Returning from a Function
5948
5949@table @code
5950@item return
5951@itemx return @var{expression}
5952@cindex returning from a function
5953@kindex return
5954You can cancel execution of a function call with the @code{return}
5955command. If you give an
5956@var{expression} argument, its value is used as the function's return
e251e767 5957value.
70b88761
RP
5958@end table
5959
5960When you use @code{return}, _GDBN__ discards the selected stack frame
5961(and all frames within it). You can think of this as making the
5962discarded frame return prematurely. If you wish to specify a value to
5963be returned, give that value as the argument to @code{return}.
5964
29a2b744
RP
5965This pops the selected stack frame (@pxref{Selection, ,Selecting a
5966Frame}), and any other frames inside of it, leaving its caller as the
5967innermost remaining frame. That frame becomes selected. The
5968specified value is stored in the registers used for returning values
5969of functions.
70b88761
RP
5970
5971The @code{return} command does not resume execution; it leaves the
5972program stopped in the state that would exist if the function had just
1041a570
RP
5973returned. In contrast, the @code{finish} command (@pxref{Continuing
5974and Stepping, ,Continuing and Stepping}) resumes execution until the
5975selected stack frame returns naturally.
70b88761 5976
4eb4cf57 5977@node Calling
70b88761
RP
5978@section Calling your Program's Functions
5979
5980@cindex calling functions
5981@kindex call
5982@table @code
5983@item call @var{expr}
5984Evaluate the expression @var{expr} without displaying @code{void}
5985returned values.
5986@end table
5987
5988You can use this variant of the @code{print} command if you want to
5989execute a function from your program, but without cluttering the output
5990with @code{void} returned values. The result is printed and saved in
5991the value history, if it is not void.
5992
4eb4cf57 5993@node Patching
c338a2fd
RP
5994@section Patching your Program
5995@cindex patching binaries
5996@cindex writing into executables
5997@cindex writing into corefiles
1041a570 5998
c338a2fd
RP
5999By default, _GDBN__ opens the file containing your program's executable
6000code (or the corefile) read-only. This prevents accidental alterations
6001to machine code; but it also prevents you from intentionally patching
6002your program's binary.
6003
6004If you'd like to be able to patch the binary, you can specify that
6005explicitly with the @code{set write} command. For example, you might
6006want to turn on internal debugging flags, or even to make emergency
e251e767 6007repairs.
c338a2fd
RP
6008
6009@table @code
6010@item set write on
6011@itemx set write off
6012@kindex set write
6013If you specify @samp{set write on}, _GDBN__ will open executable and
6014core files for both reading and writing; if you specify @samp{set write
6015off} (the default), _GDBN__ will open them read-only.
6016
1041a570 6017If you have already loaded a file, you must load it
c338a2fd
RP
6018again (using the @code{exec-file} or @code{core-file} command) after
6019changing @code{set write}, for your new setting to take effect.
6020
6021@item show write
7d7ff5f6 6022@kindex show write
c338a2fd
RP
6023Display whether executable files and core files will be opened for
6024writing as well as reading.
c338a2fd
RP
6025@end table
6026
4eb4cf57 6027@node _GDBN__ Files
70b88761
RP
6028@chapter _GDBN__'s Files
6029
1041a570 6030_GDBN__ needs to know the file name of the program to be debugged, both in
4eb4cf57
RP
6031order to read its symbol table and in order to start your program.
6032_if__(!_BARE__)
6033To debug a core dump of a previous run, _GDBN__ must be told the file
6034name of the core dump.
6035_fi__(!_BARE__)
1041a570 6036
70b88761 6037@menu
b80282d5
RP
6038* Files:: Commands to Specify Files
6039* Symbol Errors:: Errors Reading Symbol Files
70b88761
RP
6040@end menu
6041
4eb4cf57 6042@node Files
70b88761
RP
6043@section Commands to Specify Files
6044@cindex core dump file
6045@cindex symbol table
70b88761 6046
4eb4cf57 6047_if__(!_BARE__)
1041a570
RP
6048The usual way to specify executable and core dump file names is with
6049the command arguments given when you start _GDBN__, (@pxref{Invocation,
6050,Getting In and Out of _GDBN__}.
4eb4cf57
RP
6051_fi__(!_BARE__)
6052_if__(_BARE__)
6053The usual way to specify an executable file name is with
6054the command argument given when you start _GDBN__, (@pxref{Invocation,
6055,Getting In and Out of _GDBN__}.
6056_fi__(_BARE__)
70b88761
RP
6057
6058Occasionally it is necessary to change to a different file during a
4eb4cf57 6059_GDBN__ session. Or you may run _GDBN__ and forget to specify a file you
70b88761
RP
6060want to use. In these situations the _GDBN__ commands to specify new files
6061are useful.
6062
6063@table @code
6064@item file @var{filename}
6065@cindex executable file
6066@kindex file
6067Use @var{filename} as the program to be debugged. It is read for its
6068symbols and for the contents of pure memory. It is also the program
6069executed when you use the @code{run} command. If you do not specify a
1041a570
RP
6070directory and the file is not found in _GDBN__'s working directory, _GDBN__
6071uses the environment variable @code{PATH} as a list of directories to
6072search, just as the shell does when looking for a program to run. You
6073can change the value of this variable, for both _GDBN__ and your program,
6074using the @code{path} command.
70b88761 6075
14d01801
RP
6076On systems with memory-mapped files, an auxiliary symbol table file
6077@file{@var{filename}.syms} may be available for @var{filename}. If it
6078is, _GDBN__ will map in the symbol table from
6079@file{@var{filename}.syms}, starting up more quickly. See the
95d5ceb9 6080descriptions of the options @samp{-mapped} and @samp{-readnow} (available
77b46d13
JG
6081on the command line, and with the commands @code{file}, @code{symbol-file},
6082or @code{add-symbol-file}), for more information.
14d01801 6083
e0dacfd1 6084@item file
70b88761
RP
6085@code{file} with no argument makes _GDBN__ discard any information it
6086has on both executable file and the symbol table.
6087
e0dacfd1 6088@item exec-file @r{[} @var{filename} @r{]}
70b88761
RP
6089@kindex exec-file
6090Specify that the program to be run (but not the symbol table) is found
6091in @var{filename}. _GDBN__ will search the environment variable @code{PATH}
29a2b744 6092if necessary to locate your program. Omitting @var{filename} means to
e0dacfd1 6093discard information on the executable file.
70b88761 6094
e0dacfd1 6095@item symbol-file @r{[} @var{filename} @r{]}
70b88761
RP
6096@kindex symbol-file
6097Read symbol table information from file @var{filename}. @code{PATH} is
6098searched when necessary. Use the @code{file} command to get both symbol
6099table and program to run from the same file.
6100
6101@code{symbol-file} with no argument clears out _GDBN__'s information on your
6102program's symbol table.
6103
6104The @code{symbol-file} command causes _GDBN__ to forget the contents of its
6105convenience variables, the value history, and all breakpoints and
6106auto-display expressions. This is because they may contain pointers to
6107the internal data recording symbols and data types, which are part of
6108the old symbol table data being discarded inside _GDBN__.
6109
6110@code{symbol-file} will not repeat if you press @key{RET} again after
6111executing it once.
6112
14d01801
RP
6113When _GDBN__ is configured for a particular environment, it will
6114understand debugging information in whatever format is the standard
6115generated for that environment; you may use either a GNU compiler, or
6116other compilers that adhere to the local conventions. Best results are
6117usually obtained from GNU compilers; for example, using @code{_GCC__}
6118you can generate debugging information for optimized code.
6119
70b88761 6120On some kinds of object files, the @code{symbol-file} command does not
14d01801 6121normally read the symbol table in full right away. Instead, it scans
70b88761
RP
6122the symbol table quickly to find which source files and which symbols
6123are present. The details are read later, one source file at a time,
1041a570 6124as they are needed.
70b88761
RP
6125
6126The purpose of this two-stage reading strategy is to make _GDBN__ start up
1041a570
RP
6127faster. For the most part, it is invisible except for occasional
6128pauses while the symbol table details for a particular source file are
6129being read. (The @code{set verbose} command can turn these pauses
6130into messages if desired. @xref{Messages/Warnings, ,Optional Warnings
6131and Messages}.)
70b88761
RP
6132
6133When the symbol table is stored in COFF format, @code{symbol-file} does
1041a570 6134read the symbol table data in full right away. We have not implemented
70b88761
RP
6135the two-stage strategy for COFF yet.
6136
95d5ceb9
RP
6137@item symbol-file @var{filename} @r{[} -readnow @r{]} @r{[} -mapped @r{]}
6138@itemx file @var{filename} @r{[} -readnow @r{]} @r{[} -mapped @r{]}
14d01801
RP
6139@kindex readnow
6140@cindex reading symbols immediately
6141@cindex symbols, reading immediately
6142@kindex mapped
6143@cindex memory-mapped symbol file
38962738 6144@cindex saving symbol table
14d01801 6145You can override the _GDBN__ two-stage strategy for reading symbol
95d5ceb9 6146tables by using the @samp{-readnow} option with any of the commands that
14d01801
RP
6147load symbol table information, if you want to be sure _GDBN__ has the
6148entire symbol table available.
6149
4eb4cf57 6150_if__(!_BARE__)
14d01801 6151If memory-mapped files are available on your system through the
95d5ceb9 6152@code{mmap} system call, you can use another option, @samp{-mapped}, to
77b46d13
JG
6153cause _GDBN__ to write the symbols for your program into a reusable
6154file. Future _GDBN__ debugging sessions will map in symbol information
6155from this auxiliary symbol file (if the program hasn't changed), rather
6156than spending time reading the symbol table from the executable
6157program. Using the @samp{-mapped} option has the same effect as
6158starting _GDBN__ with the @samp{-mapped} command-line option.
14d01801 6159
95d5ceb9 6160You can use both options together, to make sure the auxiliary symbol
14d01801
RP
6161file has all the symbol information for your program.
6162
77b46d13
JG
6163The @code{.syms} file is specific to the host machine on which GDB is run.
6164It holds an exact image of GDB's internal symbol table. It cannot be
6165shared across multiple host platforms.
6166
14d01801
RP
6167The auxiliary symbol file for a program called @var{myprog} is called
6168@samp{@var{myprog}.syms}. Once this file exists (so long as it is newer
6169than the corresponding executable), _GDBN__ will always attempt to use
6170it when you debug @var{myprog}; no special options or commands are
6171needed.
6172@c FIXME: for now no mention of directories, since this seems to be in
6173@c flux. 13mar1992 status is that in theory GDB would look either in
6174@c current dir or in same dir as myprog; but issues like competing
6175@c GDB's, or clutter in system dirs, mean that in practice right now
6176@c only current dir is used. FFish says maybe a special GDB hierarchy
6177@c (eg rooted in val of env var GDBSYMS) could exist for mappable symbol
6178@c files.
70b88761 6179
e0dacfd1 6180@item core-file @r{[} @var{filename} @r{]}
70b88761
RP
6181@kindex core
6182@kindex core-file
6183Specify the whereabouts of a core dump file to be used as the ``contents
6184of memory''. Traditionally, core files contain only some parts of the
6185address space of the process that generated them; _GDBN__ can access the
6186executable file itself for other parts.
6187
6188@code{core-file} with no argument specifies that no core file is
6189to be used.
6190
6191Note that the core file is ignored when your program is actually running
29a2b744 6192under _GDBN__. So, if you have been running your program and you wish to
70b88761
RP
6193debug a core file instead, you must kill the subprocess in which the
6194program is running. To do this, use the @code{kill} command
1041a570 6195(@pxref{Kill Process, ,Killing the Child Process}).
4eb4cf57 6196_fi__(!_BARE__)
70b88761
RP
6197
6198@item load @var{filename}
6199@kindex load
6200_if__(_GENERIC__)
6201Depending on what remote debugging facilities are configured into
6202_GDBN__, the @code{load} command may be available. Where it exists, it
6203is meant to make @var{filename} (an executable) available for debugging
6204on the remote system---by downloading, or dynamic linking, for example.
6205@code{load} also records @var{filename}'s symbol table in _GDBN__, like
6206the @code{add-symbol-file} command.
6207
6208If @code{load} is not available on your _GDBN__, attempting to execute
6209it gets the error message ``@code{You can't do that when your target is
e251e767 6210@dots{}}''
70b88761
RP
6211_fi__(_GENERIC__)
6212
e251e767 6213_if__(_VXWORKS__)
70b88761
RP
6214On VxWorks, @code{load} will dynamically link @var{filename} on the
6215current target system as well as adding its symbols in _GDBN__.
6216_fi__(_VXWORKS__)
6217
6218_if__(_I960__)
6219@cindex download to Nindy-960
6220With the Nindy interface to an Intel 960 board, @code{load} will
6221download @var{filename} to the 960 as well as adding its symbols in
e251e767 6222_GDBN__.
70b88761
RP
6223_fi__(_I960__)
6224
c7cb8acb
RP
6225_if__(_H8__)
6226@cindex download to H8/300
6227@cindex H8/300 download
6228When you select remote debugging to a Hitachi H8/300 board (@pxref{Hitachi
6229H8/300 Remote,,_GDBN__ and the Hitachi H8/300}), the
6230@code{load} command downloads your program to the H8/300 and also opens
6231it as the current executable target for _GDBN__ on your host (like the
6232@code{file} command).
6233_fi__(_H8__)
6234
70b88761
RP
6235@code{load} will not repeat if you press @key{RET} again after using it.
6236
6237@item add-symbol-file @var{filename} @var{address}
95d5ceb9 6238@itemx add-symbol-file @var{filename} @var{address} @r{[} -readnow @r{]} @r{[} -mapped @r{]}
70b88761
RP
6239@kindex add-symbol-file
6240@cindex dynamic linking
6241The @code{add-symbol-file} command reads additional symbol table information
b80282d5 6242from the file @var{filename}. You would use this command when @var{filename}
70b88761
RP
6243has been dynamically loaded (by some other means) into the program that
6244is running. @var{address} should be the memory address at which the
6245file has been loaded; _GDBN__ cannot figure this out for itself.
6246
6247The symbol table of the file @var{filename} is added to the symbol table
6248originally read with the @code{symbol-file} command. You can use the
6249@code{add-symbol-file} command any number of times; the new symbol data thus
6250read keeps adding to the old. To discard all old symbol data instead,
e251e767 6251use the @code{symbol-file} command.
70b88761
RP
6252
6253@code{add-symbol-file} will not repeat if you press @key{RET} after using it.
6254
95d5ceb9
RP
6255You can use the @samp{-mapped} and @samp{-readnow} options just as with
6256the @code{symbol-file} command, to change how _GDBN__ manages the symbol
6257tabl einformation for @var{filename}.
6258
70b88761
RP
6259@item info files
6260@itemx info target
6261@kindex info files
6262@kindex info target
1041a570
RP
6263@code{info files} and @code{info target} are synonymous; both print
6264the current targets (@pxref{Targets, ,Specifying a Debugging Target}),
6265including the names of the executable and core dump files currently in
6266use by _GDBN__, and the files from which symbols were loaded. The command
6267@code{help targets} lists all possible targets rather than current
6268ones.
70b88761
RP
6269
6270@end table
6271
6272All file-specifying commands allow both absolute and relative file names
6273as arguments. _GDBN__ always converts the file name to an absolute path
6274name and remembers it that way.
6275
4eb4cf57 6276_if__(!_BARE__)
70b88761 6277@cindex shared libraries
77b46d13
JG
6278_GDBN__ supports SunOS, SVR4, and IBM RS/6000 shared libraries.
6279_GDBN__ automatically loads symbol definitions from shared libraries
6280when you use the @code{run} command, or when you examine a core file.
6281(Before you issue the @code{run} command, _GDBN__ will not understand
6282references to a function in a shared library, however---unless you are
6283debugging a core file).
c338a2fd 6284@c FIXME: next _GDBN__ release should permit some refs to undef
1041a570 6285@c FIXME...symbols---eg in a break cmd---assuming they are from a shared lib
70b88761
RP
6286
6287@table @code
70b88761
RP
6288@item info share
6289@itemx info sharedlibrary
6290@kindex info sharedlibrary
6291@kindex info share
c338a2fd 6292Print the names of the shared libraries which are currently loaded.
70b88761 6293
c338a2fd
RP
6294@item sharedlibrary @var{regex}
6295@itemx share @var{regex}
6296@kindex sharedlibrary
6297@kindex share
6298This is an obsolescent command; you can use it to explicitly
6299load shared object library symbols for files matching a UNIX regular
6300expression, but as with files loaded automatically, it will only load
6301shared libraries required by your program for a core file or after
6302typing @code{run}. If @var{regex} is omitted all shared libraries
6303required by your program are loaded.
6304@end table
4eb4cf57 6305_fi__(!_BARE__)
70b88761 6306
4eb4cf57 6307@node Symbol Errors
70b88761 6308@section Errors Reading Symbol Files
1041a570
RP
6309
6310While reading a symbol file, _GDBN__ will occasionally encounter problems,
6311such as symbol types it does not recognize, or known bugs in compiler
6312output. By default, _GDBN__ does not notify you of such problems, since
6313they are relatively common and primarily of interest to people
6314debugging compilers. If you are interested in seeing information
b80282d5
RP
6315about ill-constructed symbol tables, you can either ask _GDBN__ to print
6316only one message about each such type of problem, no matter how many
6317times the problem occurs; or you can ask _GDBN__ to print more messages,
1041a570
RP
6318to see how many times the problems occur, with the @code{set
6319complaints} command (@pxref{Messages/Warnings, ,Optional Warnings and
6320Messages}).
70b88761
RP
6321
6322The messages currently printed, and their meanings, are:
6323
6324@table @code
6325@item inner block not inside outer block in @var{symbol}
6326
6327The symbol information shows where symbol scopes begin and end
6328(such as at the start of a function or a block of statements). This
6329error indicates that an inner scope block is not fully contained
e251e767 6330in its outer scope blocks.
70b88761
RP
6331
6332_GDBN__ circumvents the problem by treating the inner block as if it had
6333the same scope as the outer block. In the error message, @var{symbol}
6334may be shown as ``@code{(don't know)}'' if the outer block is not a
6335function.
6336
6337@item block at @var{address} out of order
6338
e251e767 6339The symbol information for symbol scope blocks should occur in
70b88761 6340order of increasing addresses. This error indicates that it does not
e251e767 6341do so.
70b88761
RP
6342
6343_GDBN__ does not circumvent this problem, and will have trouble locating
6344symbols in the source file whose symbols being read. (You can often
6345determine what source file is affected by specifying @code{set verbose
29a2b744 6346on}. @xref{Messages/Warnings, ,Optional Warnings and Messages}.)
70b88761
RP
6347
6348@item bad block start address patched
6349
6350The symbol information for a symbol scope block has a start address
6351smaller than the address of the preceding source line. This is known
e251e767 6352to occur in the SunOS 4.1.1 (and earlier) C compiler.
70b88761
RP
6353
6354_GDBN__ circumvents the problem by treating the symbol scope block as
6355starting on the previous source line.
6356
70b88761
RP
6357@item bad string table offset in symbol @var{n}
6358
6359@cindex foo
6360Symbol number @var{n} contains a pointer into the string table which is
e251e767 6361larger than the size of the string table.
70b88761
RP
6362
6363_GDBN__ circumvents the problem by considering the symbol to have the
6364name @code{foo}, which may cause other problems if many symbols end up
6365with this name.
6366
6367@item unknown symbol type @code{0x@var{nn}}
6368
6369The symbol information contains new data types that _GDBN__ does not yet
6370know how to read. @code{0x@var{nn}} is the symbol type of the misunderstood
e251e767 6371information, in hexadecimal.
70b88761
RP
6372
6373_GDBN__ circumvents the error by ignoring this symbol information. This
29a2b744 6374will usually allow your program to be debugged, though certain symbols
70b88761
RP
6375will not be accessible. If you encounter such a problem and feel like
6376debugging it, you can debug @code{_GDBP__} with itself, breakpoint on
6377@code{complain}, then go up to the function @code{read_dbx_symtab} and
6378examine @code{*bufp} to see the symbol.
6379
6380@item stub type has NULL name
e251e767 6381_GDBN__ could not find the full definition for a struct or class.
70b88761 6382
440d9834 6383@item const/volatile indicator missing (ok if using g++ v1.x), got@dots{}
70b88761
RP
6384
6385The symbol information for a C++ member function is missing some
440d9834
RP
6386information that recent versions of the compiler should have output
6387for it.
70b88761 6388
440d9834 6389@item info mismatch between compiler and debugger
70b88761 6390
440d9834 6391_GDBN__ could not parse a type specification output by the compiler.
70b88761
RP
6392@end table
6393
4eb4cf57 6394@node Targets
e251e767 6395@chapter Specifying a Debugging Target
70b88761
RP
6396@cindex debugging target
6397@kindex target
1041a570 6398
cedaf8bc 6399A @dfn{target} is the execution environment occupied by your program.
1041a570
RP
6400Often, _GDBN__ runs in the same host environment as your program; in
6401that case, the debugging target is specified as a side effect when you
6402use the @code{file} or @code{core} commands. When you need more
6403flexibility---for example, running _GDBN__ on a physically separate
6404host, or controlling a standalone system over a serial port or a
6405realtime system over a TCP/IP connection---you can use the @code{target}
6406command to specify one of the target types configured for _GDBN__
6407(@pxref{Target Commands, ,Commands for Managing Targets}).
70b88761
RP
6408
6409@menu
b80282d5
RP
6410* Active Targets:: Active Targets
6411* Target Commands:: Commands for Managing Targets
6412* Remote:: Remote Debugging
70b88761
RP
6413@end menu
6414
4eb4cf57 6415@node Active Targets
70b88761
RP
6416@section Active Targets
6417@cindex stacking targets
6418@cindex active targets
6419@cindex multiple targets
6420
cedaf8bc
RP
6421There are three classes of targets: processes, core files, and
6422executable files. _GDBN__ can work concurrently on up to three active
6423targets, one in each class. This allows you to (for example) start a
6424process and inspect its activity without abandoning your work on a core
6425file.
70b88761 6426
cedaf8bc
RP
6427If, for example, you execute @samp{gdb a.out}, then the executable file
6428@code{a.out} is the only active target. If you designate a core file as
6429well---presumably from a prior run that crashed and coredumped---then
6430_GDBN__ has two active targets and will use them in tandem, looking
6431first in the corefile target, then in the executable file, to satisfy
6432requests for memory addresses. (Typically, these two classes of target
29a2b744 6433are complementary, since core files contain only a program's
cedaf8bc
RP
6434read-write memory---variables and so on---plus machine status, while
6435executable files contain only the program text and initialized data.)
6436
6437When you type @code{run}, your executable file becomes an active process
6438target as well. When a process target is active, all _GDBN__ commands
6439requesting memory addresses refer to that target; addresses in an active
6440core file or executable file target are obscured while the process
6441target is active.
6442
4eb4cf57
RP
6443_if__(_BARE__)
6444Use the @code{exec-file} command to select a
6445new executable target (@pxref{Files, ,Commands to Specify
6446Files}).
6447_fi__(_BARE__)
6448_if__(!_BARE__)
1041a570
RP
6449Use the @code{core-file} and @code{exec-file} commands to select a
6450new core file or executable target (@pxref{Files, ,Commands to Specify
6451Files}). To specify as a target a process that is already running, use
6452the @code{attach} command (@pxref{Attach, ,Debugging an
6453Already-Running Process}.).
4eb4cf57 6454_fi__(!_BARE__)
70b88761 6455
4eb4cf57 6456@node Target Commands
70b88761
RP
6457@section Commands for Managing Targets
6458
6459@table @code
6460@item target @var{type} @var{parameters}
6461Connects the _GDBN__ host environment to a target machine or process. A
6462target is typically a protocol for talking to debugging facilities. You
6463use the argument @var{type} to specify the type or protocol of the
6464target machine.
6465
6466Further @var{parameters} are interpreted by the target protocol, but
6467typically include things like device names or host names to connect
e251e767 6468with, process numbers, and baud rates.
70b88761
RP
6469
6470The @code{target} command will not repeat if you press @key{RET} again
6471after executing the command.
6472
6473@item help target
6474@kindex help target
6475Displays the names of all targets available. To display targets
6476currently selected, use either @code{info target} or @code{info files}
29a2b744 6477(@pxref{Files, ,Commands to Specify Files}).
70b88761
RP
6478
6479@item help target @var{name}
6480Describe a particular target, including any parameters necessary to
6481select it.
6482@end table
6483
c7cb8acb 6484Here are some common targets (available, or not, depending on the GDB
70b88761
RP
6485configuration):
6486
6487@table @code
6488@item target exec @var{prog}
6489@kindex target exec
6490An executable file. @samp{target exec @var{prog}} is the same as
6491@samp{exec-file @var{prog}}.
6492
6493@item target core @var{filename}
6494@kindex target core
6495A core dump file. @samp{target core @var{filename}} is the same as
6496@samp{core-file @var{filename}}.
6497
6498@item target remote @var{dev}
6499@kindex target remote
c7cb8acb 6500Remote serial target in GDB-specific protocol. The argument @var{dev}
70b88761 6501specifies what serial device to use for the connection (e.g.
1041a570 6502@file{/dev/ttya}). @xref{Remote, ,Remote Debugging}.
70b88761
RP
6503
6504_if__(_AMD29K__)
6505@item target amd-eb @var{dev} @var{speed} @var{PROG}
6506@kindex target amd-eb
6507@cindex AMD EB29K
6508Remote PC-resident AMD EB29K board, attached over serial lines.
6509@var{dev} is the serial device, as for @code{target remote};
6510@var{speed} allows you to specify the linespeed; and @var{PROG} is the
6511name of the program to be debugged, as it appears to DOS on the PC.
1041a570 6512@xref{EB29K Remote, ,GDB with a Remote EB29K}.
70b88761
RP
6513
6514_fi__(_AMD29K__)
c7cb8acb
RP
6515_if__(_H8__)
6516@item target hms
6517@kindex target hms
6518A Hitachi H8/300 board, attached via serial line to your host. Use
6519special commands @code{device} and @code{speed} to control the serial
6520line and the communications speed used. @xref{Hitachi H8/300
6521Remote,,_GDBN__ and the Hitachi H8/300}.
6522
6523_fi__(_H8__)
70b88761
RP
6524_if__(_I960__)
6525@item target nindy @var{devicename}
6526@kindex target nindy
6527An Intel 960 board controlled by a Nindy Monitor. @var{devicename} is
6528the name of the serial device to use for the connection, e.g.
1041a570 6529@file{/dev/ttya}. @xref{i960-Nindy Remote, ,_GDBN__ with a Remote i960 (Nindy)}.
70b88761
RP
6530
6531_fi__(_I960__)
6532_if__(_VXWORKS__)
6533@item target vxworks @var{machinename}
6534@kindex target vxworks
6535A VxWorks system, attached via TCP/IP. The argument @var{machinename}
6536is the target system's machine name or IP address.
1041a570 6537@xref{VxWorks Remote, ,_GDBN__ and VxWorks}.
70b88761
RP
6538_fi__(_VXWORKS__)
6539@end table
6540
6541_if__(_GENERIC__)
6542Different targets are available on different configurations of _GDBN__; your
6543configuration may have more or fewer targets.
6544_fi__(_GENERIC__)
6545
4eb4cf57 6546@node Remote
70b88761
RP
6547@section Remote Debugging
6548@cindex remote debugging
6549
29a2b744 6550If you are trying to debug a program running on a machine that cannot run
c7cb8acb 6551GDB in the usual way, it is often useful to use remote debugging. For
70b88761
RP
6552example, you might use remote debugging on an operating system kernel, or on
6553a small system which does not have a general purpose operating system
e251e767 6554powerful enough to run a full-featured debugger.
70b88761 6555
c7cb8acb 6556Some configurations of GDB have special serial or TCP/IP interfaces
70b88761 6557to make this work with particular debugging targets. In addition,
c7cb8acb 6558GDB comes with a generic serial protocol (specific to GDB, but
70b88761
RP
6559not specific to any particular target system) which you can use if you
6560write the remote stubs---the code that will run on the remote system to
c7cb8acb 6561communicate with GDB.
70b88761 6562
c7cb8acb 6563To use the GDB remote serial protocol, the program to be debugged on
70b88761 6564the remote machine needs to contain a debugging stub which talks to
c7cb8acb
RP
6565GDB over the serial line. Several working remote stubs are
6566distributed with GDB; see the @file{README} file in the GDB
70b88761
RP
6567distribution for more information.
6568
6569For details of this communication protocol, see the comments in the
c7cb8acb 6570GDB source file @file{remote.c}.
70b88761 6571
c7cb8acb
RP
6572To start remote debugging, first run GDB and specify as an executable file
6573the program that is running in the remote machine. This tells GDB how
29a2b744 6574to find your program's symbols and the contents of its pure text. Then
70b88761
RP
6575establish communication using the @code{target remote} command with a device
6576name as an argument. For example:
6577
6578@example
6579target remote /dev/ttyb
6580@end example
6581
6582@noindent
6583if the serial line is connected to the device named @file{/dev/ttyb}. This
6584will stop the remote machine if it is not already stopped.
6585
6586Now you can use all the usual commands to examine and change data and to
6587step and continue the remote program.
6588
6589To resume the remote program and stop debugging it, use the @code{detach}
6590command.
6591
d8a68b28
JG
6592@kindex set remotedebug
6593@kindex show remotedebug
6a8cb0e7
RP
6594@cindex packets, reporting on stdout
6595@cindex serial connections, debugging
6596If you have trouble with the serial connection, you can use the command
6597@code{set remotedebug}. This makes _GDBN__ report on all packets sent
6598back and forth across the serial line to the remote machine. The
6599packet-debugging information is printed on the _GDBN__ standard output
6600stream. @code{set remotedebug off} turns it off, and @code{show
6601remotedebug} will show you its current state.
d8a68b28 6602
70b88761 6603Other remote targets may be available in your
c7cb8acb 6604configuration of GDB; use @code{help targets} to list them.
70b88761
RP
6605
6606_if__(_GENERIC__)
1041a570
RP
6607_dnl__ Text on starting up GDB in various specific cases; it goes up front
6608_dnl__ in manuals configured for any of those particular situations, here
6609_dnl__ otherwise.
6610@menu
6611_include__(gdbinv-m.m4)<>_dnl__
6612@end menu
70b88761
RP
6613_include__(gdbinv-s.m4)
6614_fi__(_GENERIC__)
6615
4eb4cf57 6616@node Controlling _GDBN__
70b88761
RP
6617@chapter Controlling _GDBN__
6618
6619You can alter many aspects of _GDBN__'s interaction with you by using
6620the @code{set} command. For commands controlling how _GDBN__ displays
1041a570 6621data, @pxref{Print Settings, ,Print Settings}; other settings are described here.
70b88761
RP
6622
6623@menu
b80282d5
RP
6624* Prompt:: Prompt
6625* Editing:: Command Editing
6626* History:: Command History
6627* Screen Size:: Screen Size
6628* Numbers:: Numbers
6629* Messages/Warnings:: Optional Warnings and Messages
70b88761
RP
6630@end menu
6631
4eb4cf57 6632@node Prompt
70b88761
RP
6633@section Prompt
6634@cindex prompt
1041a570 6635
70b88761
RP
6636_GDBN__ indicates its readiness to read a command by printing a string
6637called the @dfn{prompt}. This string is normally @samp{(_GDBP__)}. You
6638can change the prompt string with the @code{set prompt} command. For
6639instance, when debugging _GDBN__ with _GDBN__, it is useful to change
6640the prompt in one of the _GDBN__<>s so that you can always tell which
6641one you are talking to.
6642
6643@table @code
6644@item set prompt @var{newprompt}
6645@kindex set prompt
6646Directs _GDBN__ to use @var{newprompt} as its prompt string henceforth.
6647@kindex show prompt
6648@item show prompt
6649Prints a line of the form: @samp{Gdb's prompt is: @var{your-prompt}}
6650@end table
6651
4eb4cf57 6652@node Editing
70b88761
RP
6653@section Command Editing
6654@cindex readline
6655@cindex command line editing
1041a570 6656
70b88761
RP
6657_GDBN__ reads its input commands via the @dfn{readline} interface. This
6658GNU library provides consistent behavior for programs which provide a
6659command line interface to the user. Advantages are @code{emacs}-style
6660or @code{vi}-style inline editing of commands, @code{csh}-like history
6661substitution, and a storage and recall of command history across
6662debugging sessions.
6663
6664You may control the behavior of command line editing in _GDBN__ with the
e251e767 6665command @code{set}.
70b88761
RP
6666
6667@table @code
6668@kindex set editing
6669@cindex editing
6670@item set editing
6671@itemx set editing on
6672Enable command line editing (enabled by default).
6673
6674@item set editing off
6675Disable command line editing.
6676
6677@kindex show editing
6678@item show editing
6679Show whether command line editing is enabled.
6680@end table
6681
4eb4cf57 6682@node History
70b88761 6683@section Command History
1041a570 6684
70b88761
RP
6685@table @code
6686@cindex history substitution
6687@cindex history file
6688@kindex set history filename
6689@item set history filename @var{fname}
6690Set the name of the _GDBN__ command history file to @var{fname}. This is
6691the file from which _GDBN__ will read an initial command history
6692list or to which it will write this list when it exits. This list is
6693accessed through history expansion or through the history
6694command editing characters listed below. This file defaults to the
6695value of the environment variable @code{GDBHISTFILE}, or to
6696@file{./.gdb_history} if this variable is not set.
6697
6698@cindex history save
6699@kindex set history save
6700@item set history save
6701@itemx set history save on
6702Record command history in a file, whose name may be specified with the
6703@code{set history filename} command. By default, this option is disabled.
6704
6705@item set history save off
6706Stop recording command history in a file.
6707
6708@cindex history size
6709@kindex set history size
6710@item set history size @var{size}
6711Set the number of commands which _GDBN__ will keep in its history list.
6712This defaults to the value of the environment variable
6713@code{HISTSIZE}, or to 256 if this variable is not set.
6714@end table
6715
6716@cindex history expansion
6717History expansion assigns special meaning to the character @kbd{!}.
6718@iftex
1041a570 6719@xref{Event Designators}.
70b88761
RP
6720@end iftex
6721Since @kbd{!} is also the logical not operator in C, history expansion
6722is off by default. If you decide to enable history expansion with the
6723@code{set history expansion on} command, you may sometimes need to
6724follow @kbd{!} (when it is used as logical not, in an expression) with
6725a space or a tab to prevent it from being expanded. The readline
6726history facilities will not attempt substitution on the strings
6727@kbd{!=} and @kbd{!(}, even when history expansion is enabled.
6728
6729The commands to control history expansion are:
6730
6731@table @code
6732
6733@kindex set history expansion
6734@item set history expansion on
6735@itemx set history expansion
6736Enable history expansion. History expansion is off by default.
6737
6738@item set history expansion off
6739Disable history expansion.
6740
6741The readline code comes with more complete documentation of
6742editing and history expansion features. Users unfamiliar with @code{emacs}
e251e767 6743or @code{vi} may wish to read it.
70b88761
RP
6744@iftex
6745@xref{Command Line Editing}.
6746@end iftex
6747
6748@c @group
6749@kindex show history
6750@item show history
6751@itemx show history filename
6752@itemx show history save
6753@itemx show history size
6754@itemx show history expansion
6755These commands display the state of the _GDBN__ history parameters.
6756@code{show history} by itself displays all four states.
6757@c @end group
70b88761
RP
6758@end table
6759
6760@table @code
6761@kindex show commands
6762@item show commands
6763Display the last ten commands in the command history.
6764
6765@item show commands @var{n}
6766Print ten commands centered on command number @var{n}.
6767
6768@item show commands +
6769Print ten commands just after the commands last printed.
70b88761
RP
6770@end table
6771
4eb4cf57 6772@node Screen Size
70b88761
RP
6773@section Screen Size
6774@cindex size of screen
6775@cindex pauses in output
1041a570 6776
70b88761
RP
6777Certain commands to _GDBN__ may produce large amounts of information
6778output to the screen. To help you read all of it, _GDBN__ pauses and
6779asks you for input at the end of each page of output. Type @key{RET}
6780when you want to continue the output. _GDBN__ also uses the screen
6781width setting to determine when to wrap lines of output. Depending on
6782what is being printed, it tries to break the line at a readable place,
6783rather than simply letting it overflow onto the following line.
6784
6785Normally _GDBN__ knows the size of the screen from the termcap data base
6786together with the value of the @code{TERM} environment variable and the
6787@code{stty rows} and @code{stty cols} settings. If this is not correct,
6788you can override it with the @code{set height} and @code{set
6789width} commands:
6790
6791@table @code
6792@item set height @var{lpp}
6793@itemx show height
6794@itemx set width @var{cpl}
6795@itemx show width
6796@kindex set height
6797@kindex set width
6798@kindex show width
6799@kindex show height
6800These @code{set} commands specify a screen height of @var{lpp} lines and
6801a screen width of @var{cpl} characters. The associated @code{show}
6802commands display the current settings.
6803
6804If you specify a height of zero lines, _GDBN__ will not pause during output
6805no matter how long the output is. This is useful if output is to a file
6806or to an editor buffer.
6807@end table
6808
4eb4cf57 6809@node Numbers
70b88761
RP
6810@section Numbers
6811@cindex number representation
6812@cindex entering numbers
1041a570 6813
70b88761
RP
6814You can always enter numbers in octal, decimal, or hexadecimal in _GDBN__ by
6815the usual conventions: octal numbers begin with @samp{0}, decimal
6816numbers end with @samp{.}, and hexadecimal numbers begin with @samp{0x}.
6817Numbers that begin with none of these are, by default, entered in base
681810; likewise, the default display for numbers---when no particular
6819format is specified---is base 10. You can change the default base for
6820both input and output with the @code{set radix} command.
6821
6822@table @code
6823@kindex set radix
6824@item set radix @var{base}
6825Set the default base for numeric input and display. Supported choices
c2bbbb22 6826for @var{base} are decimal 2, 8, 10, 16. @var{base} must itself be
70b88761
RP
6827specified either unambiguously or using the current default radix; for
6828example, any of
6829
6830@example
c2bbbb22 6831set radix 1010
70b88761
RP
6832set radix 012
6833set radix 10.
6834set radix 0xa
6835@end example
6836
6837@noindent
6838will set the base to decimal. On the other hand, @samp{set radix 10}
6839will leave the radix unchanged no matter what it was.
6840
6841@kindex show radix
6842@item show radix
6843Display the current default base for numeric input and display.
70b88761
RP
6844@end table
6845
4eb4cf57 6846@node Messages/Warnings
70b88761 6847@section Optional Warnings and Messages
1041a570 6848
70b88761
RP
6849By default, _GDBN__ is silent about its inner workings. If you are running
6850on a slow machine, you may want to use the @code{set verbose} command.
6851It will make _GDBN__ tell you when it does a lengthy internal operation, so
1041a570 6852you will not think it has crashed.
70b88761 6853
1041a570 6854Currently, the messages controlled by @code{set verbose} are those
d48da190
RP
6855which announce that the symbol table for a source file is being read;
6856see @code{symbol-file} in @ref{Files, ,Commands to Specify Files}.
70b88761
RP
6857
6858@table @code
6859@kindex set verbose
6860@item set verbose on
6861Enables _GDBN__'s output of certain informational messages.
6862
6863@item set verbose off
6864Disables _GDBN__'s output of certain informational messages.
6865
6866@kindex show verbose
6867@item show verbose
6868Displays whether @code{set verbose} is on or off.
6869@end table
6870
b80282d5
RP
6871By default, if _GDBN__ encounters bugs in the symbol table of an object
6872file, it is silent; but if you are debugging a compiler, you may find
1041a570 6873this information useful (@pxref{Symbol Errors, ,Errors Reading Symbol Files}).
70b88761
RP
6874
6875@table @code
6876@kindex set complaints
6877@item set complaints @var{limit}
6878Permits _GDBN__ to output @var{limit} complaints about each type of unusual
6879symbols before becoming silent about the problem. Set @var{limit} to
6880zero to suppress all complaints; set it to a large number to prevent
6881complaints from being suppressed.
6882
6883@kindex show complaints
6884@item show complaints
6885Displays how many symbol complaints _GDBN__ is permitted to produce.
6886@end table
6887
6888By default, _GDBN__ is cautious, and asks what sometimes seem to be a
6889lot of stupid questions to confirm certain commands. For example, if
6890you try to run a program which is already running:
1041a570 6891
70b88761
RP
6892@example
6893(_GDBP__) run
6894The program being debugged has been started already.
e251e767 6895Start it from the beginning? (y or n)
70b88761
RP
6896@end example
6897
29a2b744 6898If you are willing to unflinchingly face the consequences of your own
70b88761
RP
6899commands, you can disable this ``feature'':
6900
6901@table @code
6902@kindex set confirm
6903@cindex flinching
6904@cindex confirmation
6905@cindex stupid questions
6906@item set confirm off
6907Disables confirmation requests.
6908
6909@item set confirm on
6910Enables confirmation requests (the default).
6911
6912@item show confirm
6913@kindex show confirm
6914Displays state of confirmation requests.
6915@end table
6916
29a2b744 6917@c FIXME this does not really belong here. But where *does* it belong?
b80282d5
RP
6918@cindex reloading symbols
6919Some systems allow individual object files that make up your program to
6920be replaced without stopping and restarting your program.
6921_if__(_VXWORKS__)
6922For example, in VxWorks you can simply recompile a defective object file
6923and keep on running.
6924_fi__(_VXWORKS__)
29a2b744 6925If you are running on one of these systems, you can allow _GDBN__ to
1041a570
RP
6926reload the symbols for automatically relinked modules:
6927
b80282d5
RP
6928@table @code
6929@kindex set symbol-reloading
6930@item set symbol-reloading on
6931Replace symbol definitions for the corresponding source file when an
6932object file with a particular name is seen again.
6933
6934@item set symbol-reloading off
1041a570 6935Do not replace symbol definitions when re-encountering object files of
29a2b744 6936the same name. This is the default state; if you are not running on a
b80282d5
RP
6937system that permits automatically relinking modules, you should leave
6938@code{symbol-reloading} off, since otherwise _GDBN__ may discard symbols
6939when linking large programs, that may contain several modules (from
6940different directories or libraries) with the same name.
6941
6942@item show symbol-reloading
6943Show the current @code{on} or @code{off} setting.
6944@end table
6945
4eb4cf57 6946@node Sequences
70b88761
RP
6947@chapter Canned Sequences of Commands
6948
29a2b744 6949Aside from breakpoint commands (@pxref{Break Commands, ,Breakpoint
1041a570
RP
6950Command Lists}), _GDBN__ provides two ways to store sequences of commands
6951for execution as a unit: user-defined commands and command files.
70b88761
RP
6952
6953@menu
b80282d5
RP
6954* Define:: User-Defined Commands
6955* Command Files:: Command Files
6956* Output:: Commands for Controlled Output
70b88761
RP
6957@end menu
6958
4eb4cf57 6959@node Define
70b88761
RP
6960@section User-Defined Commands
6961
6962@cindex user-defined command
6963A @dfn{user-defined command} is a sequence of _GDBN__ commands to which you
6964assign a new name as a command. This is done with the @code{define}
6965command.
6966
6967@table @code
6968@item define @var{commandname}
6969@kindex define
6970Define a command named @var{commandname}. If there is already a command
6971by that name, you are asked to confirm that you want to redefine it.
6972
6973The definition of the command is made up of other _GDBN__ command lines,
6974which are given following the @code{define} command. The end of these
6975commands is marked by a line containing @code{end}.
6976
6977@item document @var{commandname}
6978@kindex document
6979Give documentation to the user-defined command @var{commandname}. The
6980command @var{commandname} must already be defined. This command reads
6981lines of documentation just as @code{define} reads the lines of the
6982command definition, ending with @code{end}. After the @code{document}
6983command is finished, @code{help} on command @var{commandname} will print
6984the documentation you have specified.
6985
6986You may use the @code{document} command again to change the
6987documentation of a command. Redefining the command with @code{define}
6988does not change the documentation.
6989
6990@item help user-defined
6991@kindex help user-defined
6992List all user-defined commands, with the first line of the documentation
6993(if any) for each.
6994
4768ba62
JG
6995@item show user
6996@itemx show user @var{commandname}
6997@kindex show user
70b88761
RP
6998Display the _GDBN__ commands used to define @var{commandname} (but not its
6999documentation). If no @var{commandname} is given, display the
7000definitions for all user-defined commands.
7001@end table
7002
7003User-defined commands do not take arguments. When they are executed, the
7004commands of the definition are not printed. An error in any command
7005stops execution of the user-defined command.
7006
7007Commands that would ask for confirmation if used interactively proceed
7008without asking when used inside a user-defined command. Many _GDBN__ commands
7009that normally print messages to say what they are doing omit the messages
7010when used in a user-defined command.
7011
4eb4cf57 7012@node Command Files
70b88761
RP
7013@section Command Files
7014
7015@cindex command files
7016A command file for _GDBN__ is a file of lines that are _GDBN__ commands. Comments
7017(lines starting with @kbd{#}) may also be included. An empty line in a
7018command file does nothing; it does not mean to repeat the last command, as
7019it would from the terminal.
7020
7021@cindex init file
7022@cindex @file{_GDBINIT__}
7023When you start _GDBN__, it automatically executes commands from its
1041a570
RP
7024@dfn{init files}. These are files named @file{_GDBINIT__}. _GDBN__ reads
7025the init file (if any) in your home directory and then the init file
7026(if any) in the current working directory. (The init files are not
7027executed if you use the @samp{-nx} option; @pxref{Mode Options,
7028,Choosing Modes}.) You can also request the execution of a command
7029file with the @code{source} command:
70b88761
RP
7030
7031@table @code
7032@item source @var{filename}
7033@kindex source
7034Execute the command file @var{filename}.
7035@end table
7036
7037The lines in a command file are executed sequentially. They are not
7038printed as they are executed. An error in any command terminates execution
7039of the command file.
7040
7041Commands that would ask for confirmation if used interactively proceed
7042without asking when used in a command file. Many _GDBN__ commands that
7043normally print messages to say what they are doing omit the messages
7044when called from command files.
7045
4eb4cf57 7046@node Output
70b88761
RP
7047@section Commands for Controlled Output
7048
7049During the execution of a command file or a user-defined command, normal
7050_GDBN__ output is suppressed; the only output that appears is what is
7051explicitly printed by the commands in the definition. This section
7052describes three commands useful for generating exactly the output you
7053want.
7054
7055@table @code
7056@item echo @var{text}
7057@kindex echo
29a2b744
RP
7058@c I do not consider backslash-space a standard C escape sequence
7059@c because it is not in ANSI.
1041a570
RP
7060Print @var{text}. Nonprinting characters can be included in
7061@var{text} using C escape sequences, such as @samp{\n} to print a
7062newline. @strong{No newline will be printed unless you specify one.}
7063In addition to the standard C escape sequences, a backslash followed
7064by a space stands for a space. This is useful for outputting a
7065string with spaces at the beginning or the end, since leading and
7066trailing spaces are otherwise trimmed from all arguments.
7067To print @samp{@w{ }and foo =@w{ }}, use the command
7068@samp{echo \@w{ }and foo = \@w{ }}.
70b88761
RP
7069
7070A backslash at the end of @var{text} can be used, as in C, to continue
7071the command onto subsequent lines. For example,
7072
7073@example
7074echo This is some text\n\
7075which is continued\n\
7076onto several lines.\n
7077@end example
7078
7079produces the same output as
7080
7081@example
7082echo This is some text\n
7083echo which is continued\n
7084echo onto several lines.\n
7085@end example
7086
7087@item output @var{expression}
7088@kindex output
7089Print the value of @var{expression} and nothing but that value: no
7090newlines, no @samp{$@var{nn} = }. The value is not entered in the
1041a570 7091value history either. @xref{Expressions, ,Expressions}, for more information on
e251e767 7092expressions.
70b88761
RP
7093
7094@item output/@var{fmt} @var{expression}
7095Print the value of @var{expression} in format @var{fmt}. You can use
7096the same formats as for @code{print}; @pxref{Output formats}, for more
7097information.
7098
7099@item printf @var{string}, @var{expressions}@dots{}
7100@kindex printf
7101Print the values of the @var{expressions} under the control of
7102@var{string}. The @var{expressions} are separated by commas and may
7103be either numbers or pointers. Their values are printed as specified
29a2b744 7104by @var{string}, exactly as if your program were to execute
70b88761
RP
7105
7106@example
7107printf (@var{string}, @var{expressions}@dots{});
7108@end example
7109
7110For example, you can print two values in hex like this:
7111
0fd24984 7112@smallexample
70b88761 7113printf "foo, bar-foo = 0x%x, 0x%x\n", foo, bar-foo
0fd24984 7114@end smallexample
70b88761
RP
7115
7116The only backslash-escape sequences that you can use in the format
7117string are the simple ones that consist of backslash followed by a
7118letter.
7119@end table
7120
4eb4cf57
RP
7121_if__(!_DOSHOST__)
7122@node Emacs
70b88761
RP
7123@chapter Using _GDBN__ under GNU Emacs
7124
7125@cindex emacs
7126A special interface allows you to use GNU Emacs to view (and
7127edit) the source files for the program you are debugging with
7128_GDBN__.
7129
7130To use this interface, use the command @kbd{M-x gdb} in Emacs. Give the
7131executable file you want to debug as an argument. This command starts
7132_GDBN__ as a subprocess of Emacs, with input and output through a newly
7133created Emacs buffer.
7134
7135Using _GDBN__ under Emacs is just like using _GDBN__ normally except for two
7136things:
7137
7138@itemize @bullet
7139@item
e251e767 7140All ``terminal'' input and output goes through the Emacs buffer.
70b88761
RP
7141@end itemize
7142
7143This applies both to _GDBN__ commands and their output, and to the input
7144and output done by the program you are debugging.
7145
7146This is useful because it means that you can copy the text of previous
7147commands and input them again; you can even use parts of the output
7148in this way.
7149
3d3ab540
RP
7150All the facilities of Emacs' Shell mode are available for interacting
7151with your program. In particular, you can send signals the usual
7152way---for example, @kbd{C-c C-c} for an interrupt, @kbd{C-c C-z} for a
7153stop.
70b88761
RP
7154
7155@itemize @bullet
7156@item
e251e767 7157_GDBN__ displays source code through Emacs.
70b88761
RP
7158@end itemize
7159
7160Each time _GDBN__ displays a stack frame, Emacs automatically finds the
7161source file for that frame and puts an arrow (_0__@samp{=>}_1__) at the
7162left margin of the current line. Emacs uses a separate buffer for
7163source display, and splits the window to show both your _GDBN__ session
7164and the source.
7165
7166Explicit _GDBN__ @code{list} or search commands still produce output as
7167usual, but you probably will have no reason to use them.
7168
7169@quotation
7170@emph{Warning:} If the directory where your program resides is not your
7171current directory, it can be easy to confuse Emacs about the location of
7172the source files, in which case the auxiliary display buffer will not
7173appear to show your source. _GDBN__ can find programs by searching your
7174environment's @code{PATH} variable, so the _GDBN__ input and output
29a2b744 7175session will proceed normally; but Emacs does not get enough information
70b88761
RP
7176back from _GDBN__ to locate the source files in this situation. To
7177avoid this problem, either start _GDBN__ mode from the directory where
7178your program resides, or specify a full path name when prompted for the
7179@kbd{M-x gdb} argument.
7180
7181A similar confusion can result if you use the _GDBN__ @code{file} command to
7182switch to debugging a program in some other location, from an existing
7183_GDBN__ buffer in Emacs.
7184@end quotation
7185
7186By default, @kbd{M-x gdb} calls the program called @file{gdb}. If
7187you need to call _GDBN__ by a different name (for example, if you keep
7188several configurations around, with different names) you can set the
7189Emacs variable @code{gdb-command-name}; for example,
1041a570 7190
70b88761
RP
7191@example
7192(setq gdb-command-name "mygdb")
7193@end example
1041a570 7194
70b88761
RP
7195@noindent
7196(preceded by @kbd{ESC ESC}, or typed in the @code{*scratch*} buffer, or
7197in your @file{.emacs} file) will make Emacs call the program named
7198``@code{mygdb}'' instead.
7199
7200In the _GDBN__ I/O buffer, you can use these special Emacs commands in
7201addition to the standard Shell mode commands:
7202
7203@table @kbd
7204@item C-h m
7205Describe the features of Emacs' _GDBN__ Mode.
7206
7207@item M-s
7208Execute to another source line, like the _GDBN__ @code{step} command; also
7209update the display window to show the current file and location.
7210
7211@item M-n
7212Execute to next source line in this function, skipping all function
7213calls, like the _GDBN__ @code{next} command. Then update the display window
7214to show the current file and location.
7215
7216@item M-i
7217Execute one instruction, like the _GDBN__ @code{stepi} command; update
7218display window accordingly.
7219
7220@item M-x gdb-nexti
7221Execute to next instruction, using the _GDBN__ @code{nexti} command; update
7222display window accordingly.
7223
7224@item C-c C-f
7225Execute until exit from the selected stack frame, like the _GDBN__
7226@code{finish} command.
7227
7228@item M-c
29a2b744 7229Continue execution of your program, like the _GDBN__ @code{continue}
1041a570 7230command.
203eea5d
RP
7231
7232@emph{Warning:} In Emacs v19, this command is @kbd{C-c C-p}.
70b88761
RP
7233
7234@item M-u
7235Go up the number of frames indicated by the numeric argument
7236(@pxref{Arguments, , Numeric Arguments, emacs, The GNU Emacs Manual}),
1041a570 7237like the _GDBN__ @code{up} command.
203eea5d 7238
1041a570 7239@emph{Warning:} In Emacs v19, this command is @kbd{C-c C-u}.
70b88761
RP
7240
7241@item M-d
7242Go down the number of frames indicated by the numeric argument, like the
1041a570 7243_GDBN__ @code{down} command.
203eea5d
RP
7244
7245@emph{Warning:} In Emacs v19, this command is @kbd{C-c C-d}.
70b88761
RP
7246
7247@item C-x &
7248Read the number where the cursor is positioned, and insert it at the end
7249of the _GDBN__ I/O buffer. For example, if you wish to disassemble code
7250around an address that was displayed earlier, type @kbd{disassemble};
7251then move the cursor to the address display, and pick up the
e251e767 7252argument for @code{disassemble} by typing @kbd{C-x &}.
70b88761
RP
7253
7254You can customize this further on the fly by defining elements of the list
7255@code{gdb-print-command}; once it is defined, you can format or
7256otherwise process numbers picked up by @kbd{C-x &} before they are
c2bbbb22 7257inserted. A numeric argument to @kbd{C-x &} will both indicate that you
70b88761
RP
7258wish special formatting, and act as an index to pick an element of the
7259list. If the list element is a string, the number to be inserted is
7260formatted using the Emacs function @code{format}; otherwise the number
7261is passed as an argument to the corresponding list element.
70b88761
RP
7262@end table
7263
7264In any source file, the Emacs command @kbd{C-x SPC} (@code{gdb-break})
7265tells _GDBN__ to set a breakpoint on the source line point is on.
7266
7267If you accidentally delete the source-display buffer, an easy way to get
7268it back is to type the command @code{f} in the _GDBN__ buffer, to
7269request a frame display; when you run under Emacs, this will recreate
7270the source buffer if necessary to show you the context of the current
7271frame.
7272
7273The source files displayed in Emacs are in ordinary Emacs buffers
7274which are visiting the source files in the usual way. You can edit
7275the files with these buffers if you wish; but keep in mind that _GDBN__
7276communicates with Emacs in terms of line numbers. If you add or
7277delete lines from the text, the line numbers that _GDBN__ knows will cease
7278to correspond properly to the code.
7279
7280@c The following dropped because Epoch is nonstandard. Reactivate
7281@c if/when v19 does something similar. ---pesch@cygnus.com 19dec1990
7282@ignore
e251e767 7283@kindex emacs epoch environment
70b88761
RP
7284@kindex epoch
7285@kindex inspect
7286
7287Version 18 of Emacs has a built-in window system called the @code{epoch}
7288environment. Users of this environment can use a new command,
7289@code{inspect} which performs identically to @code{print} except that
7290each value is printed in its own window.
7291@end ignore
4eb4cf57 7292_fi__(!_DOSHOST__)
70b88761 7293
6ca72cc6 7294_if__(_LUCID__)
4eb4cf57 7295@node Energize
6ca72cc6
RP
7296@chapter Using _GDBN__ with Energize
7297
7298@cindex Energize
7299The Energize Programming System is an integrated development environment
7300that includes a point-and-click interface to many programming tools.
7301When you use _GDBN__ in this environment, you can use the standard
7302Energize graphical interface to drive _GDBN__; you can also, if you
7303choose, type _GDBN__ commands as usual in a debugging window. Even if
7304you use the graphical interface, the debugging window (which uses Emacs,
7305and resembles the standard Emacs interface to _GDBN__) displays the
7306equivalent commands, so that the history of your debugging session is
7307properly reflected.
7308
7309When Energize starts up a _GDBN__ session, it uses one of the
7310command-line options @samp{-energize} or @samp{-cadillac} (``cadillac''
7311is the name of the communications protocol used by the Energize system).
7312This option makes _GDBN__ run as one of the tools in the Energize Tool
7313Set: it sends all output to the Energize kernel, and accept input from
7314it as well.
7315
7316See the user manual for the Energize Programming System for
7317information on how to use the Energize graphical interface and the other
7318development tools that Energize integrates with _GDBN__.
7319
6ca72cc6 7320_fi__(_LUCID__)
4eb4cf57
RP
7321
7322@node _GDBN__ Bugs
70b88761
RP
7323@chapter Reporting Bugs in _GDBN__
7324@cindex Bugs in _GDBN__
7325@cindex Reporting Bugs in _GDBN__
7326
7327Your bug reports play an essential role in making _GDBN__ reliable.
7328
7329Reporting a bug may help you by bringing a solution to your problem, or it
7330may not. But in any case the principal function of a bug report is to help
7331the entire community by making the next version of _GDBN__ work better. Bug
7332reports are your contribution to the maintenance of _GDBN__.
7333
7334In order for a bug report to serve its purpose, you must include the
7335information that enables us to fix the bug.
7336
7337@menu
b80282d5
RP
7338* Bug Criteria:: Have You Found a Bug?
7339* Bug Reporting:: How to Report Bugs
70b88761
RP
7340@end menu
7341
4eb4cf57 7342@node Bug Criteria
70b88761
RP
7343@section Have You Found a Bug?
7344@cindex Bug Criteria
7345
7346If you are not sure whether you have found a bug, here are some guidelines:
7347
7348@itemize @bullet
7349@item
7350@cindex Fatal Signal
7351@cindex Core Dump
7352If the debugger gets a fatal signal, for any input whatever, that is a
7353_GDBN__ bug. Reliable debuggers never crash.
7354
7355@item
7356@cindex error on Valid Input
7357If _GDBN__ produces an error message for valid input, that is a bug.
7358
7359@item
7360@cindex Invalid Input
7361If _GDBN__ does not produce an error message for invalid input,
7362that is a bug. However, you should note that your idea of
7363``invalid input'' might be our idea of ``an extension'' or ``support
7364for traditional practice''.
7365
7366@item
7367If you are an experienced user of debugging tools, your suggestions
7368for improvement of _GDBN__ are welcome in any case.
7369@end itemize
7370
4eb4cf57 7371@node Bug Reporting
70b88761
RP
7372@section How to Report Bugs
7373@cindex Bug Reports
3d3ab540 7374@cindex _GDBN__ Bugs, Reporting
70b88761
RP
7375
7376A number of companies and individuals offer support for GNU products.
7377If you obtained _GDBN__ from a support organization, we recommend you
e251e767 7378contact that organization first.
70b88761
RP
7379
7380Contact information for many support companies and individuals is
7381available in the file @file{etc/SERVICE} in the GNU Emacs distribution.
7382
7383In any event, we also recommend that you send bug reports for _GDBN__ to one
7384of these addresses:
7385
7386@example
7387bug-gdb@@prep.ai.mit.edu
7388@{ucbvax|mit-eddie|uunet@}!prep.ai.mit.edu!bug-gdb
7389@end example
7390
7391@strong{Do not send bug reports to @samp{info-gdb}, or to
7392@samp{help-gdb}, or to any newsgroups.} Most users of _GDBN__ do not want to
7393receive bug reports. Those that do, have arranged to receive @samp{bug-gdb}.
7394
3d3ab540
RP
7395The mailing list @samp{bug-gdb} has a newsgroup @samp{gnu.gdb.bug} which
7396serves as a repeater. The mailing list and the newsgroup carry exactly
7397the same messages. Often people think of posting bug reports to the
7398newsgroup instead of mailing them. This appears to work, but it has one
7399problem which can be crucial: a newsgroup posting often lacks a mail
7400path back to the sender. Thus, if we need to ask for more information,
7401we may be unable to reach you. For this reason, it is better to send
7402bug reports to the mailing list.
70b88761
RP
7403
7404As a last resort, send bug reports on paper to:
7405
7406@example
7407GNU Debugger Bugs
3d3ab540 7408Free Software Foundation
70b88761
RP
7409545 Tech Square
7410Cambridge, MA 02139
7411@end example
7412
7413The fundamental principle of reporting bugs usefully is this:
7414@strong{report all the facts}. If you are not sure whether to state a
7415fact or leave it out, state it!
7416
7417Often people omit facts because they think they know what causes the
29a2b744 7418problem and assume that some details do not matter. Thus, you might
70b88761 7419assume that the name of the variable you use in an example does not matter.
29a2b744 7420Well, probably it does not, but one cannot be sure. Perhaps the bug is a
70b88761
RP
7421stray memory reference which happens to fetch from the location where that
7422name is stored in memory; perhaps, if the name were different, the contents
7423of that location would fool the debugger into doing the right thing despite
7424the bug. Play it safe and give a specific, complete example. That is the
7425easiest thing for you to do, and the most helpful.
7426
7427Keep in mind that the purpose of a bug report is to enable us to fix
1041a570 7428the bug if it is new to us. It is not as important as what happens if
70b88761
RP
7429the bug is already known. Therefore, always write your bug reports on
7430the assumption that the bug has not been reported previously.
7431
7432Sometimes people give a few sketchy facts and ask, ``Does this ring a
7433bell?'' Those bug reports are useless, and we urge everyone to
7434@emph{refuse to respond to them} except to chide the sender to report
7435bugs properly.
7436
7437To enable us to fix the bug, you should include all these things:
7438
7439@itemize @bullet
7440@item
7441The version of _GDBN__. _GDBN__ announces it if you start with no
7442arguments; you can also print it at any time using @code{show version}.
7443
1041a570 7444Without this, we will not know whether there is any point in looking for
70b88761
RP
7445the bug in the current version of _GDBN__.
7446
7447@item
ddf21240
JG
7448The type of machine you are using, and the operating system name and
7449version number.
70b88761
RP
7450
7451@item
7452What compiler (and its version) was used to compile _GDBN__---e.g.
c7cb8acb 7453``_GCC__-2.0''.
70b88761 7454
ddf21240
JG
7455@item
7456What compiler (and its version) was used to compile the program you
c7cb8acb 7457are debugging---e.g. ``_GCC__-2.0''.
ddf21240 7458
70b88761
RP
7459@item
7460The command arguments you gave the compiler to compile your example and
7461observe the bug. For example, did you use @samp{-O}? To guarantee
1041a570 7462you will not omit something important, list them all. A copy of the
ddf21240 7463Makefile (or the output from make) is sufficient.
70b88761
RP
7464
7465If we were to try to guess the arguments, we would probably guess wrong
7466and then we might not encounter the bug.
7467
7468@item
ddf21240
JG
7469A complete input script, and all necessary source files, that will
7470reproduce the bug.
70b88761
RP
7471
7472@item
7473A description of what behavior you observe that you believe is
7474incorrect. For example, ``It gets a fatal signal.''
7475
7476Of course, if the bug is that _GDBN__ gets a fatal signal, then we will
7477certainly notice it. But if the bug is incorrect output, we might not
7478notice unless it is glaringly wrong. We are human, after all. You
7479might as well not give us a chance to make a mistake.
7480
7481Even if the problem you experience is a fatal signal, you should still
7482say so explicitly. Suppose something strange is going on, such as,
7483your copy of _GDBN__ is out of synch, or you have encountered a
7484bug in the C library on your system. (This has happened!) Your copy
7485might crash and ours would not. If you told us to expect a crash,
7486then when ours fails to crash, we would know that the bug was not
7487happening for us. If you had not told us to expect a crash, then we
7488would not be able to draw any conclusion from our observations.
7489
7490@item
7491If you wish to suggest changes to the _GDBN__ source, send us context
7492diffs. If you even discuss something in the _GDBN__ source, refer to
7493it by context, not by line number.
7494
1041a570 7495The line numbers in our development sources will not match those in your
70b88761 7496sources. Your line numbers would convey no useful information to us.
70b88761
RP
7497@end itemize
7498
7499Here are some things that are not necessary:
7500
7501@itemize @bullet
7502@item
7503A description of the envelope of the bug.
7504
7505Often people who encounter a bug spend a lot of time investigating
7506which changes to the input file will make the bug go away and which
7507changes will not affect it.
7508
7509This is often time consuming and not very useful, because the way we
7510will find the bug is by running a single example under the debugger
7511with breakpoints, not by pure deduction from a series of examples.
7512We recommend that you save your time for something else.
7513
7514Of course, if you can find a simpler example to report @emph{instead}
7515of the original one, that is a convenience for us. Errors in the
7516output will be easier to spot, running under the debugger will take
e251e767 7517less time, etc.
70b88761 7518
29a2b744 7519However, simplification is not vital; if you do not want to do this,
70b88761
RP
7520report the bug anyway and send us the entire test case you used.
7521
7522@item
7523A patch for the bug.
7524
29a2b744 7525A patch for the bug does help us if it is a good one. But do not omit
70b88761
RP
7526the necessary information, such as the test case, on the assumption that
7527a patch is all we need. We might see problems with your patch and decide
7528to fix the problem another way, or we might not understand it at all.
7529
7530Sometimes with a program as complicated as _GDBN__ it is very hard to
7531construct an example that will make the program follow a certain path
1041a570
RP
7532through the code. If you do not send us the example, we will not be able
7533to construct one, so we will not be able to verify that the bug is fixed.
70b88761 7534
29a2b744 7535And if we cannot understand what bug you are trying to fix, or why your
1041a570 7536patch should be an improvement, we will not install it. A test case will
70b88761
RP
7537help us to understand.
7538
7539@item
7540A guess about what the bug is or what it depends on.
7541
29a2b744 7542Such guesses are usually wrong. Even we cannot guess right about such
70b88761
RP
7543things without first using the debugger to find the facts.
7544@end itemize
7545
1041a570
RP
7546@c Note: no need to update nodes for rdl-apps.texi since it appears
7547@c *only* in the TeX version of the manual.
7548@c Note: eventually, make a cross reference to the readline Info nodes.
70b88761 7549@iftex
cacf5942
RP
7550@c appendices describing GNU readline. Distributed with readline code.
7551@include rluser.texinfo
7552@include inc-hist.texi
70b88761
RP
7553@end iftex
7554
4eb4cf57
RP
7555_if__(_GENERIC__||!_H8__)
7556@node Renamed Commands
70b88761
RP
7557@appendix Renamed Commands
7558
c7cb8acb 7559The following commands were renamed in GDB 4, in order to make the
70b88761
RP
7560command set as a whole more consistent and easier to use and remember:
7561
e251e767
RP
7562@kindex add-syms
7563@kindex delete environment
7564@kindex info copying
7565@kindex info convenience
7566@kindex info directories
7567@kindex info editing
7568@kindex info history
7569@kindex info targets
7570@kindex info values
7571@kindex info version
7572@kindex info warranty
7573@kindex set addressprint
7574@kindex set arrayprint
7575@kindex set prettyprint
7576@kindex set screen-height
7577@kindex set screen-width
7578@kindex set unionprint
7579@kindex set vtblprint
7580@kindex set demangle
7581@kindex set asm-demangle
7582@kindex set sevenbit-strings
7583@kindex set array-max
7584@kindex set caution
7585@kindex set history write
7586@kindex show addressprint
7587@kindex show arrayprint
7588@kindex show prettyprint
7589@kindex show screen-height
7590@kindex show screen-width
7591@kindex show unionprint
7592@kindex show vtblprint
7593@kindex show demangle
7594@kindex show asm-demangle
7595@kindex show sevenbit-strings
7596@kindex show array-max
7597@kindex show caution
7598@kindex show history write
7599@kindex unset
70b88761 7600
92b73793 7601@c TEXI2ROFF-KILL
70b88761 7602@ifinfo
92b73793 7603@c END TEXI2ROFF-KILL
cf496415
RP
7604@example
7605OLD COMMAND NEW COMMAND
92b73793 7606@c TEXI2ROFF-KILL
cf496415 7607--------------- -------------------------------
92b73793 7608@c END TEXI2ROFF-KILL
cf496415
RP
7609add-syms add-symbol-file
7610delete environment unset environment
7611info convenience show convenience
7612info copying show copying
e251e767 7613info directories show directories
cf496415
RP
7614info editing show commands
7615info history show values
7616info targets help target
7617info values show values
7618info version show version
7619info warranty show warranty
7620set/show addressprint set/show print address
7621set/show array-max set/show print elements
7622set/show arrayprint set/show print array
7623set/show asm-demangle set/show print asm-demangle
7624set/show caution set/show confirm
7625set/show demangle set/show print demangle
7626set/show history write set/show history save
7627set/show prettyprint set/show print pretty
7628set/show screen-height set/show height
7629set/show screen-width set/show width
7630set/show sevenbit-strings set/show print sevenbit-strings
7631set/show unionprint set/show print union
7632set/show vtblprint set/show print vtbl
7633
7634unset [No longer an alias for delete]
7635@end example
92b73793 7636@c TEXI2ROFF-KILL
70b88761
RP
7637@end ifinfo
7638
7639@tex
7640\vskip \parskip\vskip \baselineskip
7641\halign{\tt #\hfil &\qquad#&\tt #\hfil\cr
7642{\bf Old Command} &&{\bf New Command}\cr
7643add-syms &&add-symbol-file\cr
7644delete environment &&unset environment\cr
7645info convenience &&show convenience\cr
7646info copying &&show copying\cr
7647info directories &&show directories \cr
7648info editing &&show commands\cr
7649info history &&show values\cr
7650info targets &&help target\cr
7651info values &&show values\cr
7652info version &&show version\cr
7653info warranty &&show warranty\cr
7654set{\rm / }show addressprint &&set{\rm / }show print address\cr
7655set{\rm / }show array-max &&set{\rm / }show print elements\cr
7656set{\rm / }show arrayprint &&set{\rm / }show print array\cr
7657set{\rm / }show asm-demangle &&set{\rm / }show print asm-demangle\cr
7658set{\rm / }show caution &&set{\rm / }show confirm\cr
7659set{\rm / }show demangle &&set{\rm / }show print demangle\cr
7660set{\rm / }show history write &&set{\rm / }show history save\cr
7661set{\rm / }show prettyprint &&set{\rm / }show print pretty\cr
7662set{\rm / }show screen-height &&set{\rm / }show height\cr
7663set{\rm / }show screen-width &&set{\rm / }show width\cr
7664set{\rm / }show sevenbit-strings &&set{\rm / }show print sevenbit-strings\cr
7665set{\rm / }show unionprint &&set{\rm / }show print union\cr
7666set{\rm / }show vtblprint &&set{\rm / }show print vtbl\cr
7667\cr
7668unset &&\rm(No longer an alias for delete)\cr
7669}
7670@end tex
92b73793 7671@c END TEXI2ROFF-KILL
4eb4cf57 7672_fi__(_GENERIC__||!_H8__)
70b88761 7673
4eb4cf57 7674@node Formatting Documentation
77b46d13
JG
7675@appendix Formatting the Documentation
7676
7677@cindex GDB reference card
7678@cindex reference card
7679The GDB 4 release includes an already-formatted reference card, ready
b1385986 7680for printing with PostScript or GhostScript, in the @file{gdb}
77b46d13 7681subdirectory of the main source directory---in
b1385986
RP
7682@file{gdb-_GDB_VN__/gdb/refcard.ps} of the version _GDB_VN__ release.
7683If you can use PostScript or GhostScript with your printer, you can
7684print the reference card immediately with @file{refcard.ps}.
77b46d13
JG
7685
7686The release also includes the source for the reference card. You
7687can format it, using @TeX{}, by typing:
7688
7689@example
7690make refcard.dvi
7691@end example
7692
7693The GDB reference card is designed to print in landscape mode on US
7694``letter'' size paper; that is, on a sheet 11 inches wide by 8.5 inches
7695high. You will need to specify this form of printing as an option to
7696your @sc{dvi} output program.
7697
7698@cindex documentation
7699
7700All the documentation for GDB comes as part of the machine-readable
7701distribution. The documentation is written in Texinfo format, which is
7702a documentation system that uses a single source file to produce both
7703on-line information and a printed manual. You can use one of the Info
7704formatting commands to create the on-line version of the documentation
7705and @TeX{} (or @code{texi2roff}) to typeset the printed version.
7706
7707GDB includes an already formatted copy of the on-line Info version of
7708this manual in the @file{gdb} subdirectory. The main Info file is
7709@file{gdb-@var{version-number}/gdb/gdb.info}, and it refers to
a89f94c2
RP
7710subordinate files matching @samp{gdb.info*} in the same directory. If
7711necessary, you can print out these files, or read them with any editor;
7712but they are easier to read using the @code{info} subsystem in GNU Emacs
7713or the standalone @code{info} program, available as part of the GNU
7714Texinfo distribution.
77b46d13
JG
7715
7716If you want to format these Info files yourself, you need one of the
7717Info formatting programs, such as @code{texinfo-format-buffer} or
7718@code{makeinfo}.
7719
7720If you have @code{makeinfo} installed, and are in the top level GDB
7721source directory (@file{gdb-_GDB_VN__}, in the case of version _GDB_VN__), you can
7722make the Info file by typing:
7723
7724@example
7725cd gdb
7726make gdb.info
7727@end example
7728
7729If you want to typeset and print copies of this manual, you need
7730@TeX{}, a printing program such as @code{lpr}, and @file{texinfo.tex},
7731the Texinfo definitions file.
7732
7733@TeX{} is typesetting program; it does not print files directly, but
7734produces output files called @sc{dvi} files. To print a typeset
7735document, you need a program to print @sc{dvi} files. If your system
7736has @TeX{} installed, chances are it has such a program. The precise
7737command to use depends on your system; @kbd{lpr -d} is common; another
7738is @kbd{dvips}. The @sc{dvi} print command may require a file name
7739without any extension or a @samp{.dvi} extension.
7740
7741@TeX{} also requires a macro definitions file called
7742@file{texinfo.tex}. This file tells @TeX{} how to typeset a document
7743written in Texinfo format. On its own, @TeX{} cannot read, much less
7744typeset a Texinfo file. @file{texinfo.tex} is distributed with GDB
7745and is located in the @file{gdb-@var{version-number}/texinfo}
7746directory.
7747
7748If you have @TeX{} and a @sc{dvi} printer program installed, you can
7749typeset and print this manual. First switch to the the @file{gdb}
7750subdirectory of the main source directory (for example, to
7751@file{gdb-_GDB_VN__/gdb}) and then type:
7752
7753@example
7754make gdb.dvi
7755@end example
7756
4eb4cf57 7757@node Installing GDB
c7cb8acb
RP
7758@appendix Installing GDB
7759@cindex configuring GDB
70b88761
RP
7760@cindex installation
7761
f672bb7f
RP
7762@iftex
7763@c irrelevant in info file; it's as current as the code it lives with.
7764@quotation
7765@emph{Warning:} These installation instructions are current as of
c7cb8acb
RP
7766GDB version _GDB_VN__. If you're installing a more recent release
7767of GDB, we may have improved the installation procedures since
f672bb7f
RP
7768printing this manual; see the @file{README} file included in your
7769release for the most recent instructions.
7770@end quotation
7771@end iftex
7772
c7cb8acb
RP
7773GDB comes with a @code{configure} script that automates the process
7774of preparing GDB for installation; you can then use @code{make} to
7775build the program.
b80282d5 7776
c7cb8acb 7777The GDB distribution includes all the source code you need for GDB in
1041a570
RP
7778a single directory, whose name is usually composed by appending the
7779version number to @samp{gdb}.
7780
c7cb8acb 7781For example, the GDB version _GDB_VN__ distribution is in the @file{gdb-_GDB_VN__}
1041a570 7782directory. That directory contains:
b80282d5 7783
3d3ab540 7784@table @code
c7637ea6 7785@item gdb-_GDB_VN__/configure @r{(and supporting files)}
c7cb8acb 7786script for configuring GDB and all its supporting libraries.
b80282d5 7787
3e0d0a27 7788@item gdb-_GDB_VN__/gdb
c7cb8acb 7789the source specific to GDB itself
3d3ab540 7790
3e0d0a27 7791@item gdb-_GDB_VN__/bfd
77b46d13 7792source for the Binary File Descriptor library
3d3ab540 7793
3e0d0a27 7794@item gdb-_GDB_VN__/include
b80282d5 7795GNU include files
3d3ab540 7796
3e0d0a27 7797@item gdb-_GDB_VN__/libiberty
3d3ab540
RP
7798source for the @samp{-liberty} free software library
7799
3e0d0a27 7800@item gdb-_GDB_VN__/readline
b80282d5 7801source for the GNU command-line interface
77b46d13
JG
7802
7803@item gdb-_GDB_VN__/glob
7804source for the GNU filename pattern-matching subroutine
7805
7806@item gdb-_GDB_VN__/mmalloc
7807source for the GNU memory-mapped malloc package
3d3ab540 7808@end table
1041a570 7809
c7cb8acb 7810The simplest way to configure and build GDB is to run @code{configure}
1041a570
RP
7811from the @file{gdb-@var{version-number}} source directory, which in
7812this example is the @file{gdb-_GDB_VN__} directory.
7813
7814First switch to the @file{gdb-@var{version-number}} source directory
7815if you are not already in it; then run @code{configure}. Pass the
c7cb8acb 7816identifier for the platform on which GDB will run as an
1041a570
RP
7817argument.
7818
7819For example:
7820
7463aadd 7821@example
3e0d0a27 7822cd gdb-_GDB_VN__
3d3ab540 7823./configure @var{host}
7463aadd
RP
7824make
7825@end example
1041a570 7826
7463aadd 7827@noindent
1041a570 7828where @var{host} is an identifier such as @samp{sun4} or
c7cb8acb 7829@samp{decstation}, that identifies the platform where GDB will run.
1041a570 7830
38962738
RP
7831Running @samp{configure @var{host}} followed by @code{make} builds the
7832@file{bfd}, @file{readline}, @file{mmalloc}, and @file{libiberty}
7833libraries, then @code{gdb} itself. The configured source files, and the
7834binaries, are left in the corresponding source directories.
3d3ab540 7835
e251e767 7836@code{configure} is a Bourne-shell (@code{/bin/sh}) script; if your
29a2b744 7837system does not recognize this automatically when you run a different
1041a570
RP
7838shell, you may need to run @code{sh} on it explicitly:
7839
7840@example
7841sh configure @var{host}
7842@end example
e251e767 7843
f672bb7f
RP
7844If you run @code{configure} from a directory that contains source
7845directories for multiple libraries or programs, such as the
7846@file{gdb-_GDB_VN__} source directory for version _GDB_VN__, @code{configure}
7847creates configuration files for every directory level underneath (unless
98349959 7848you tell it not to, with the @samp{--norecursion} option).
f672bb7f
RP
7849
7850You can run the @code{configure} script from any of the
c7cb8acb 7851subordinate directories in the GDB distribution, if you only want to
1041a570
RP
7852configure that subdirectory; but be sure to specify a path to it.
7853
7854For example, with version _GDB_VN__, type the following to configure only
7855the @code{bfd} subdirectory:
7856
e251e767 7857@example
203eea5d 7858@group
e251e767
RP
7859cd gdb-_GDB_VN__/bfd
7860../configure @var{host}
203eea5d 7861@end group
e251e767
RP
7862@end example
7863
1041a570
RP
7864You can install @code{_GDBP__} anywhere; it has no hardwired paths.
7865However, you should make sure that the shell on your path (named by
7866the @samp{SHELL} environment variable) is publicly readable. Remember
c7cb8acb
RP
7867that GDB uses the shell to start your program---some systems refuse to
7868let GDB debug child processes whose programs are not readable.
3d3ab540
RP
7869
7870@menu
c7cb8acb 7871* Separate Objdir:: Compiling GDB in another directory
b80282d5
RP
7872* Config Names:: Specifying names for hosts and targets
7873* configure Options:: Summary of options for configure
3d3ab540
RP
7874@end menu
7875
4eb4cf57 7876@node Separate Objdir
c7cb8acb 7877@section Compiling GDB in Another Directory
1041a570 7878
c7cb8acb
RP
7879If you want to run GDB versions for several host or target machines,
7880you'll need a different @code{gdb} compiled for each combination of
1041a570 7881host and target. @code{configure} is designed to make this easy by
f672bb7f
RP
7882allowing you to generate each configuration in a separate subdirectory,
7883rather than in the source directory. If your @code{make} program
7884handles the @samp{VPATH} feature (GNU @code{make} does), running
c7cb8acb 7885@code{make} in each of these directories then builds the @code{gdb}
f672bb7f 7886program specified there.
b80282d5 7887
c7cb8acb 7888To build @code{gdb} in a separate directory, run @code{configure}
f672bb7f 7889with the @samp{--srcdir} option to specify where to find the source.
77b46d13
JG
7890(You'll also need to specify a path to find @code{configure}
7891itself from your working directory. If the path to @code{configure}
7892would be the same as the argument to @samp{--srcdir}, you can leave out
7893the @samp{--srcdir} option; it will be assumed.)
1041a570 7894
c7cb8acb 7895For example, with version _GDB_VN__, you can build GDB in a separate
f672bb7f 7896directory for a Sun 4 like this:
70b88761
RP
7897
7898@example
3d3ab540 7899@group
3e0d0a27 7900cd gdb-_GDB_VN__
f672bb7f
RP
7901mkdir ../gdb-sun4
7902cd ../gdb-sun4
77b46d13 7903../gdb-_GDB_VN__/configure sun4
70b88761 7904make
3d3ab540 7905@end group
70b88761
RP
7906@end example
7907
f672bb7f
RP
7908When @code{configure} builds a configuration using a remote source
7909directory, it creates a tree for the binaries with the same structure
7910(and using the same names) as the tree under the source directory. In
7911the example, you'd find the Sun 4 library @file{libiberty.a} in the
c7cb8acb 7912directory @file{gdb-sun4/libiberty}, and GDB itself in
f672bb7f 7913@file{gdb-sun4/gdb}.
1041a570 7914
38962738 7915One popular reason to build several GDB configurations in separate
c7cb8acb 7916directories is to configure GDB for cross-compiling (where GDB
f672bb7f
RP
7917runs on one machine---the host---while debugging programs that run on
7918another machine---the target). You specify a cross-debugging target by
7919giving the @samp{--target=@var{target}} option to @code{configure}.
c7637ea6 7920
1041a570 7921When you run @code{make} to build a program or library, you must run
f672bb7f
RP
7922it in a configured directory---whatever directory you were in when you
7923called @code{configure} (or one of its subdirectories).
c7637ea6
RP
7924
7925The @code{Makefile} generated by @code{configure} for each source
f672bb7f
RP
7926directory also runs recursively. If you type @code{make} in a source
7927directory such as @file{gdb-_GDB_VN__} (or in a separate configured
7928directory configured with @samp{--srcdir=@var{path}/gdb-_GDB_VN__}), you
c7cb8acb 7929will build all the required libraries, then build GDB.
3d3ab540 7930
f672bb7f
RP
7931When you have multiple hosts or targets configured in separate
7932directories, you can run @code{make} on them in parallel (for example,
7933if they are NFS-mounted on each of the hosts); they will not interfere
7934with each other.
3d3ab540 7935
4eb4cf57 7936@node Config Names
b80282d5
RP
7937@section Specifying Names for Hosts and Targets
7938
7939The specifications used for hosts and targets in the @code{configure}
7940script are based on a three-part naming scheme, but some short predefined
7941aliases are also supported. The full naming scheme encodes three pieces
e251e767 7942of information in the following pattern:
1041a570 7943
b80282d5
RP
7944@example
7945@var{architecture}-@var{vendor}-@var{os}
7946@end example
7947
7948For example, you can use the alias @code{sun4} as a @var{host} argument
5e3186ab 7949or in a @code{--target=@var{target}} option, but the equivalent full name
e251e767 7950is @samp{sparc-sun-sunos4}.
b80282d5 7951
c7cb8acb 7952The @code{configure} script accompanying GDB does not provide
b80282d5
RP
7953any query facility to list all supported host and target names or
7954aliases. @code{configure} calls the Bourne shell script
7955@code{config.sub} to map abbreviations to full names; you can read the
7956script, if you wish, or you can use it to test your guesses on
7957abbreviations---for example:
1041a570 7958
b1385986 7959@smallexample
b80282d5 7960% sh config.sub sun4
6a8cb0e7 7961sparc-sun-sunos411
b80282d5 7962% sh config.sub sun3
6a8cb0e7 7963m68k-sun-sunos411
b80282d5 7964% sh config.sub decstation
6a8cb0e7 7965mips-dec-ultrix42
b80282d5
RP
7966% sh config.sub hp300bsd
7967m68k-hp-bsd
7968% sh config.sub i386v
6a8cb0e7 7969i386-unknown-sysv
e94b4a2b 7970% sh config.sub i786v
6a8cb0e7 7971Invalid configuration `i786v': machine `i786v' not recognized
b1385986 7972@end smallexample
1041a570 7973
c7637ea6 7974@noindent
1041a570
RP
7975@code{config.sub} is also distributed in the GDB source
7976directory (@file{gdb-_GDB_VN__}, for version _GDB_VN__).
b80282d5 7977
4eb4cf57 7978@node configure Options
3d3ab540 7979@section @code{configure} Options
7463aadd 7980
d48da190
RP
7981Here is a summary of the @code{configure} options and arguments that
7982are most often useful for building _GDBN__. @code{configure} also has
7983several other options not listed here. @inforef{What Configure
7984Does,,configure.info}, for a full explanation of @code{configure}.
7985@c FIXME: Would this be more, or less, useful as an xref (ref to printed
7986@c manual in the printed manual, ref to info file only from the info file)?
7463aadd
RP
7987
7988@example
d48da190
RP
7989configure @r{[}--help@r{]}
7990 @r{[}--prefix=@var{dir}@r{]}
7991 @r{[}--srcdir=@var{path}@r{]}
f672bb7f
RP
7992 @r{[}--norecursion@r{]} @r{[}--rm@r{]}
7993 @r{[}--target=@var{target}@r{]} @var{host}
7463aadd 7994@end example
1041a570 7995
3d3ab540 7996@noindent
f672bb7f
RP
7997You may introduce options with a single @samp{-} rather than
7998@samp{--} if you prefer; but you may abbreviate option names if you use
7999@samp{--}.
70b88761
RP
8000
8001@table @code
d48da190
RP
8002@item --help
8003Display a quick summary of how to invoke @code{configure}.
8004
8005@item -prefix=@var{dir}
8006Configure the source to install programs and files under directory
8007@file{@var{dir}}.
8008
f672bb7f 8009@item --srcdir=@var{path}
6ca72cc6
RP
8010@strong{Warning: using this option requires GNU @code{make}, or another
8011@code{make} that implements the @code{VPATH} feature.}@*
f672bb7f 8012Use this option to make configurations in directories separate from the
c7cb8acb 8013GDB source directories. Among other things, you can use this to
f672bb7f
RP
8014build (or maintain) several configurations simultaneously, in separate
8015directories. @code{configure} writes configuration specific files in
8016the current directory, but arranges for them to use the source in the
8017directory @var{path}. @code{configure} will create directories under
8018the working directory in parallel to the source directories below
8019@var{path}.
8020
8021@item --norecursion
8022Configure only the directory level where @code{configure} is executed; do not
7463aadd
RP
8023propagate configuration to subdirectories.
8024
f672bb7f 8025@item --rm
b80282d5 8026Remove the configuration that the other arguments specify.
7463aadd 8027
29a2b744 8028@c This does not work (yet if ever). FIXME.
f672bb7f 8029@c @item --parse=@var{lang} @dots{}
c7cb8acb
RP
8030@c Configure the GDB expression parser to parse the listed languages.
8031@c @samp{all} configures GDB for all supported languages. To get a
d7b569d5 8032@c list of all supported languages, omit the argument. Without this
c7cb8acb 8033@c option, GDB is configured to parse all supported languages.
c2bbbb22 8034
f672bb7f 8035@item --target=@var{target}
c7cb8acb
RP
8036Configure GDB for cross-debugging programs running on the specified
8037@var{target}. Without this option, GDB is configured to debug
8038programs that run on the same machine (@var{host}) as GDB itself.
b80282d5
RP
8039
8040There is no convenient way to generate a list of all available targets.
7463aadd
RP
8041
8042@item @var{host} @dots{}
c7cb8acb 8043Configure GDB to run on the specified @var{host}.
b80282d5
RP
8044
8045There is no convenient way to generate a list of all available hosts.
70b88761
RP
8046@end table
8047
3d3ab540
RP
8048@noindent
8049@code{configure} accepts other options, for compatibility with
b80282d5 8050configuring other GNU tools recursively; but these are the only
c7cb8acb 8051options that affect GDB or its supporting libraries.
3d3ab540 8052
4eb4cf57 8053@node Copying
70b88761 8054@unnumbered GNU GENERAL PUBLIC LICENSE
7463aadd 8055@center Version 2, June 1991
70b88761
RP
8056
8057@display
7463aadd 8058Copyright @copyright{} 1989, 1991 Free Software Foundation, Inc.
70b88761
RP
8059675 Mass Ave, Cambridge, MA 02139, USA
8060
8061Everyone is permitted to copy and distribute verbatim copies
8062of this license document, but changing it is not allowed.
8063@end display
8064
8065@unnumberedsec Preamble
8066
7463aadd
RP
8067 The licenses for most software are designed to take away your
8068freedom to share and change it. By contrast, the GNU General Public
70b88761 8069License is intended to guarantee your freedom to share and change free
7463aadd
RP
8070software---to make sure the software is free for all its users. This
8071General Public License applies to most of the Free Software
8072Foundation's software and to any other program whose authors commit to
8073using it. (Some other Free Software Foundation software is covered by
8074the GNU Library General Public License instead.) You can apply it to
8075your programs, too.
70b88761
RP
8076
8077 When we speak of free software, we are referring to freedom, not
7463aadd
RP
8078price. Our General Public Licenses are designed to make sure that you
8079have the freedom to distribute copies of free software (and charge for
8080this service if you wish), that you receive source code or can get it
8081if you want it, that you can change the software or use pieces of it
8082in new free programs; and that you know you can do these things.
70b88761
RP
8083
8084 To protect your rights, we need to make restrictions that forbid
8085anyone to deny you these rights or to ask you to surrender the rights.
8086These restrictions translate to certain responsibilities for you if you
8087distribute copies of the software, or if you modify it.
8088
7463aadd 8089 For example, if you distribute copies of such a program, whether
70b88761
RP
8090gratis or for a fee, you must give the recipients all the rights that
8091you have. You must make sure that they, too, receive or can get the
7463aadd
RP
8092source code. And you must show them these terms so they know their
8093rights.
70b88761
RP
8094
8095 We protect your rights with two steps: (1) copyright the software, and
8096(2) offer you this license which gives you legal permission to copy,
8097distribute and/or modify the software.
8098
8099 Also, for each author's protection and ours, we want to make certain
8100that everyone understands that there is no warranty for this free
8101software. If the software is modified by someone else and passed on, we
8102want its recipients to know that what they have is not the original, so
8103that any problems introduced by others will not reflect on the original
8104authors' reputations.
8105
7463aadd
RP
8106 Finally, any free program is threatened constantly by software
8107patents. We wish to avoid the danger that redistributors of a free
8108program will individually obtain patent licenses, in effect making the
8109program proprietary. To prevent this, we have made it clear that any
8110patent must be licensed for everyone's free use or not licensed at all.
8111
70b88761
RP
8112 The precise terms and conditions for copying, distribution and
8113modification follow.
8114
8115@iftex
7463aadd 8116@unnumberedsec TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
70b88761
RP
8117@end iftex
8118@ifinfo
7463aadd 8119@center TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
70b88761
RP
8120@end ifinfo
8121
8122@enumerate
8123@item
7463aadd
RP
8124This License applies to any program or other work which contains
8125a notice placed by the copyright holder saying it may be distributed
8126under the terms of this General Public License. The ``Program'', below,
8127refers to any such program or work, and a ``work based on the Program''
8128means either the Program or any derivative work under copyright law:
8129that is to say, a work containing the Program or a portion of it,
8130either verbatim or with modifications and/or translated into another
8131language. (Hereinafter, translation is included without limitation in
8132the term ``modification''.) Each licensee is addressed as ``you''.
8133
8134Activities other than copying, distribution and modification are not
8135covered by this License; they are outside its scope. The act of
8136running the Program is not restricted, and the output from the Program
8137is covered only if its contents constitute a work based on the
8138Program (independent of having been made by running the Program).
8139Whether that is true depends on what the Program does.
70b88761
RP
8140
8141@item
7463aadd
RP
8142You may copy and distribute verbatim copies of the Program's
8143source code as you receive it, in any medium, provided that you
8144conspicuously and appropriately publish on each copy an appropriate
8145copyright notice and disclaimer of warranty; keep intact all the
8146notices that refer to this License and to the absence of any warranty;
8147and give any other recipients of the Program a copy of this License
8148along with the Program.
70b88761 8149
7463aadd
RP
8150You may charge a fee for the physical act of transferring a copy, and
8151you may at your option offer warranty protection in exchange for a fee.
70b88761 8152
70b88761 8153@item
7463aadd
RP
8154You may modify your copy or copies of the Program or any portion
8155of it, thus forming a work based on the Program, and copy and
8156distribute such modifications or work under the terms of Section 1
8157above, provided that you also meet all of these conditions:
70b88761 8158
1041a570 8159@enumerate a
70b88761 8160@item
7463aadd
RP
8161You must cause the modified files to carry prominent notices
8162stating that you changed the files and the date of any change.
70b88761
RP
8163
8164@item
7463aadd
RP
8165You must cause any work that you distribute or publish, that in
8166whole or in part contains or is derived from the Program or any
8167part thereof, to be licensed as a whole at no charge to all third
8168parties under the terms of this License.
70b88761
RP
8169
8170@item
7463aadd
RP
8171If the modified program normally reads commands interactively
8172when run, you must cause it, when started running for such
8173interactive use in the most ordinary way, to print or display an
8174announcement including an appropriate copyright notice and a
8175notice that there is no warranty (or else, saying that you provide
8176a warranty) and that users may redistribute the program under
8177these conditions, and telling the user how to view a copy of this
8178License. (Exception: if the Program itself is interactive but
8179does not normally print such an announcement, your work based on
8180the Program is not required to print an announcement.)
1041a570 8181@end enumerate
7463aadd
RP
8182
8183These requirements apply to the modified work as a whole. If
8184identifiable sections of that work are not derived from the Program,
8185and can be reasonably considered independent and separate works in
8186themselves, then this License, and its terms, do not apply to those
8187sections when you distribute them as separate works. But when you
8188distribute the same sections as part of a whole which is a work based
8189on the Program, the distribution of the whole must be on the terms of
8190this License, whose permissions for other licensees extend to the
8191entire whole, and thus to each and every part regardless of who wrote it.
8192
8193Thus, it is not the intent of this section to claim rights or contest
8194your rights to work written entirely by you; rather, the intent is to
8195exercise the right to control the distribution of derivative or
8196collective works based on the Program.
8197
8198In addition, mere aggregation of another work not based on the Program
8199with the Program (or with a work based on the Program) on a volume of
8200a storage or distribution medium does not bring the other work under
8201the scope of this License.
70b88761
RP
8202
8203@item
7463aadd
RP
8204You may copy and distribute the Program (or a work based on it,
8205under Section 2) in object code or executable form under the terms of
8206Sections 1 and 2 above provided that you also do one of the following:
70b88761 8207
1041a570 8208@enumerate a
70b88761 8209@item
7463aadd
RP
8210Accompany it with the complete corresponding machine-readable
8211source code, which must be distributed under the terms of Sections
82121 and 2 above on a medium customarily used for software interchange; or,
70b88761
RP
8213
8214@item
7463aadd
RP
8215Accompany it with a written offer, valid for at least three
8216years, to give any third party, for a charge no more than your
8217cost of physically performing source distribution, a complete
8218machine-readable copy of the corresponding source code, to be
8219distributed under the terms of Sections 1 and 2 above on a medium
8220customarily used for software interchange; or,
70b88761
RP
8221
8222@item
7463aadd
RP
8223Accompany it with the information you received as to the offer
8224to distribute corresponding source code. (This alternative is
70b88761 8225allowed only for noncommercial distribution and only if you
7463aadd
RP
8226received the program in object code or executable form with such
8227an offer, in accord with Subsection b above.)
1041a570 8228@end enumerate
7463aadd
RP
8229
8230The source code for a work means the preferred form of the work for
8231making modifications to it. For an executable work, complete source
8232code means all the source code for all modules it contains, plus any
8233associated interface definition files, plus the scripts used to
8234control compilation and installation of the executable. However, as a
8235special exception, the source code distributed need not include
8236anything that is normally distributed (in either source or binary
8237form) with the major components (compiler, kernel, and so on) of the
8238operating system on which the executable runs, unless that component
8239itself accompanies the executable.
8240
8241If distribution of executable or object code is made by offering
8242access to copy from a designated place, then offering equivalent
8243access to copy the source code from the same place counts as
8244distribution of the source code, even though third parties are not
8245compelled to copy the source along with the object code.
70b88761
RP
8246
8247@item
7463aadd
RP
8248You may not copy, modify, sublicense, or distribute the Program
8249except as expressly provided under this License. Any attempt
8250otherwise to copy, modify, sublicense or distribute the Program is
8251void, and will automatically terminate your rights under this License.
8252However, parties who have received copies, or rights, from you under
8253this License will not have their licenses terminated so long as such
8254parties remain in full compliance.
70b88761
RP
8255
8256@item
7463aadd
RP
8257You are not required to accept this License, since you have not
8258signed it. However, nothing else grants you permission to modify or
8259distribute the Program or its derivative works. These actions are
8260prohibited by law if you do not accept this License. Therefore, by
8261modifying or distributing the Program (or any work based on the
8262Program), you indicate your acceptance of this License to do so, and
8263all its terms and conditions for copying, distributing or modifying
8264the Program or works based on it.
70b88761
RP
8265
8266@item
8267Each time you redistribute the Program (or any work based on the
7463aadd
RP
8268Program), the recipient automatically receives a license from the
8269original licensor to copy, distribute or modify the Program subject to
8270these terms and conditions. You may not impose any further
8271restrictions on the recipients' exercise of the rights granted herein.
8272You are not responsible for enforcing compliance by third parties to
8273this License.
8274
8275@item
8276If, as a consequence of a court judgment or allegation of patent
8277infringement or for any other reason (not limited to patent issues),
8278conditions are imposed on you (whether by court order, agreement or
8279otherwise) that contradict the conditions of this License, they do not
8280excuse you from the conditions of this License. If you cannot
8281distribute so as to satisfy simultaneously your obligations under this
8282License and any other pertinent obligations, then as a consequence you
8283may not distribute the Program at all. For example, if a patent
8284license would not permit royalty-free redistribution of the Program by
8285all those who receive copies directly or indirectly through you, then
8286the only way you could satisfy both it and this License would be to
8287refrain entirely from distribution of the Program.
8288
8289If any portion of this section is held invalid or unenforceable under
8290any particular circumstance, the balance of the section is intended to
8291apply and the section as a whole is intended to apply in other
8292circumstances.
8293
8294It is not the purpose of this section to induce you to infringe any
8295patents or other property right claims or to contest validity of any
8296such claims; this section has the sole purpose of protecting the
8297integrity of the free software distribution system, which is
8298implemented by public license practices. Many people have made
8299generous contributions to the wide range of software distributed
8300through that system in reliance on consistent application of that
8301system; it is up to the author/donor to decide if he or she is willing
8302to distribute software through any other system and a licensee cannot
8303impose that choice.
8304
8305This section is intended to make thoroughly clear what is believed to
8306be a consequence of the rest of this License.
8307
8308@item
8309If the distribution and/or use of the Program is restricted in
8310certain countries either by patents or by copyrighted interfaces, the
8311original copyright holder who places the Program under this License
8312may add an explicit geographical distribution limitation excluding
8313those countries, so that distribution is permitted only in or among
8314countries not thus excluded. In such case, this License incorporates
8315the limitation as if written in the body of this License.
70b88761
RP
8316
8317@item
8318The Free Software Foundation may publish revised and/or new versions
8319of the General Public License from time to time. Such new versions will
8320be similar in spirit to the present version, but may differ in detail to
8321address new problems or concerns.
8322
8323Each version is given a distinguishing version number. If the Program
7463aadd 8324specifies a version number of this License which applies to it and ``any
70b88761
RP
8325later version'', you have the option of following the terms and conditions
8326either of that version or of any later version published by the Free
8327Software Foundation. If the Program does not specify a version number of
7463aadd 8328this License, you may choose any version ever published by the Free Software
70b88761
RP
8329Foundation.
8330
8331@item
8332If you wish to incorporate parts of the Program into other free
8333programs whose distribution conditions are different, write to the author
8334to ask for permission. For software which is copyrighted by the Free
8335Software Foundation, write to the Free Software Foundation; we sometimes
8336make exceptions for this. Our decision will be guided by the two goals
8337of preserving the free status of all derivatives of our free software and
8338of promoting the sharing and reuse of software generally.
8339
8340@iftex
8341@heading NO WARRANTY
8342@end iftex
8343@ifinfo
8344@center NO WARRANTY
8345@end ifinfo
8346
8347@item
8348BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
8349FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN
8350OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
8351PROVIDE THE PROGRAM ``AS IS'' WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED
8352OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
8353MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS
8354TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE
8355PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,
8356REPAIR OR CORRECTION.
8357
8358@item
7463aadd
RP
8359IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
8360WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
70b88761 8361REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,
7463aadd
RP
8362INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING
8363OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED
8364TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY
8365YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER
8366PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE
8367POSSIBILITY OF SUCH DAMAGES.
70b88761
RP
8368@end enumerate
8369
8370@iftex
8371@heading END OF TERMS AND CONDITIONS
8372@end iftex
8373@ifinfo
8374@center END OF TERMS AND CONDITIONS
8375@end ifinfo
8376
8377@page
54e6b3c3 8378@unnumberedsec Applying These Terms to Your New Programs
70b88761
RP
8379
8380 If you develop a new program, and you want it to be of the greatest
7463aadd
RP
8381possible use to the public, the best way to achieve this is to make it
8382free software which everyone can redistribute and change under these terms.
70b88761 8383
7463aadd
RP
8384 To do so, attach the following notices to the program. It is safest
8385to attach them to the start of each source file to most effectively
8386convey the exclusion of warranty; and each file should have at least
8387the ``copyright'' line and a pointer to where the full notice is found.
70b88761
RP
8388
8389@smallexample
203eea5d 8390@var{one line to give the program's name and an idea of what it does.}
70b88761
RP
8391Copyright (C) 19@var{yy} @var{name of author}
8392
203eea5d
RP
8393This program is free software; you can redistribute it and/or
8394modify it under the terms of the GNU General Public License
8395as published by the Free Software Foundation; either version 2
8396of the License, or (at your option) any later version.
70b88761
RP
8397
8398This program is distributed in the hope that it will be useful,
8399but WITHOUT ANY WARRANTY; without even the implied warranty of
8400MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
8401GNU General Public License for more details.
8402
8403You should have received a copy of the GNU General Public License
203eea5d
RP
8404along with this program; if not, write to the
8405Free Software Foundation, Inc., 675 Mass Ave,
8406Cambridge, MA 02139, USA.
70b88761
RP
8407@end smallexample
8408
8409Also add information on how to contact you by electronic and paper mail.
8410
8411If the program is interactive, make it output a short notice like this
8412when it starts in an interactive mode:
8413
8414@smallexample
8415Gnomovision version 69, Copyright (C) 19@var{yy} @var{name of author}
203eea5d
RP
8416Gnomovision comes with ABSOLUTELY NO WARRANTY; for details
8417type `show w'. This is free software, and you are welcome
8418to redistribute it under certain conditions; type `show c'
8419for details.
70b88761
RP
8420@end smallexample
8421
7463aadd
RP
8422The hypothetical commands @samp{show w} and @samp{show c} should show
8423the appropriate parts of the General Public License. Of course, the
8424commands you use may be called something other than @samp{show w} and
8425@samp{show c}; they could even be mouse-clicks or menu items---whatever
8426suits your program.
70b88761
RP
8427
8428You should also get your employer (if you work as a programmer) or your
8429school, if any, to sign a ``copyright disclaimer'' for the program, if
8430necessary. Here is a sample; alter the names:
8431
1041a570
RP
8432@example
8433Yoyodyne, Inc., hereby disclaims all copyright
8434interest in the program `Gnomovision'
8435(which makes passes at compilers) written
8436by James Hacker.
70b88761
RP
8437
8438@var{signature of Ty Coon}, 1 April 1989
8439Ty Coon, President of Vice
1041a570 8440@end example
7463aadd
RP
8441
8442This General Public License does not permit incorporating your program into
8443proprietary programs. If your program is a subroutine library, you may
8444consider it more useful to permit linking proprietary applications with the
8445library. If this is what you want to do, use the GNU Library General
8446Public License instead of this License.
70b88761 8447
4eb4cf57 8448@node Index
d2e08421 8449@unnumbered Index
e91b87a3 8450
8451@printindex cp
8452
fe3f5fc8
RP
8453@tex
8454% I think something like @colophon should be in texinfo. In the
8455% meantime:
8456\long\def\colophon{\hbox to0pt{}\vfill
8457\centerline{The body of this manual is set in}
8458\centerline{\fontname\tenrm,}
8459\centerline{with headings in {\bf\fontname\tenbf}}
8460\centerline{and examples in {\tt\fontname\tentt}.}
a6d0b6d3
RP
8461\centerline{{\it\fontname\tenit\/},}
8462\centerline{{\bf\fontname\tenbf}, and}
fe3f5fc8
RP
8463\centerline{{\sl\fontname\tensl\/}}
8464\centerline{are used for emphasis.}\vfill}
8465\page\colophon
a6d0b6d3 8466% Blame: pesch@cygnus.com, 1991.
fe3f5fc8
RP
8467@end tex
8468
e91b87a3 8469@contents
8470@bye
This page took 0.520933 seconds and 4 git commands to generate.