]> Git Repo - binutils.git/blame - gdb/doc/gdb.texinfo
Restructured manual; introduced introductory sample session.
[binutils.git] / gdb / doc / gdb.texinfo
CommitLineData
e91b87a3 1\input texinfo
5a131cc7
RP
2@setfilename _GDBP__.info
3@c
4@c NOTE: this manual is marked up for preprocessing with a collection
5@c of m4 macros called "pretex.m4". If you see <_if__> and <_fi__>
6@c scattered around the source, you have the full source before
7@c preprocessing; if you don't, you have the source configured for
8@c _HOST__ architectures (and you can of course get the full source,
9@c with all configurations, from wherever you got this).
10_if__(0)
fe3f5fc8 11_0__
5a131cc7
RP
12
13THIS IS THE FULL SOURCE. The full source needs to be run through m4
14before either tex- or info- formatting: for example,
fe3f5fc8 15 m4 pretex.m4 none.m4 m680x0.m4 gdb.texinfo >gdb-680x0.texinfo
5a131cc7
RP
16will produce (assuming your path finds either GNU or SysV m4; Berkeley
17won't do) a file suitable for formatting. See the text in "pretex.m4"
18for a fuller explanation (and the macro definitions).
fe3f5fc8 19_1__
5a131cc7
RP
20_fi__(0)
21@c
fe3f5fc8 22@syncodeindex ky cp
369a6ade 23@c FOR UPDATES LEADING TO THIS DRAFT, GDB CHANGELOG CONSULTED BETWEEN:
23e2e5e1
RP
24@c Tue Feb 26 01:47:07 1991 Cygnus John Gilmore (cygnus at yuba)
25@c Sat Dec 22 02:51:40 1990 John Gilmore (gnu at cygint)
e91b87a3 26@ifinfo
5a131cc7 27This file documents the GNU debugger _GDBN__.
e91b87a3 28
d62719de 29Copyright (C) 1988, 1989, 1990, 1991 Free Software Foundation, Inc.
e91b87a3 30
31Permission is granted to make and distribute verbatim copies of
32this manual provided the copyright notice and this permission notice
33are preserved on all copies.
34
35@ignore
36Permission is granted to process this file through Tex and print the
37results, provided the printed document carries copying permission
38notice identical to this one except for the removal of this paragraph
39(this paragraph not being relevant to the printed manual).
40
41@end ignore
42Permission is granted to copy and distribute modified versions of this
43manual under the conditions for verbatim copying, provided also that the
4187119d 44section entitled ``GNU General Public License'' is included exactly as
45in the original, and provided that the entire resulting derived work is
46distributed under the terms of a permission notice identical to this
47one.
e91b87a3 48
49Permission is granted to copy and distribute translations of this manual
50into another language, under the above conditions for modified versions,
4187119d 51except that the section entitled ``GNU General Public License'' may be
52included in a translation approved by the author instead of in the
53original English.
e91b87a3 54@end ifinfo
cb9d2049 55@smallbook
e91b87a3 56@setchapternewpage odd
5a131cc7
RP
57_if__(_GENERIC__)
58@settitle Using _GDBN__ (v4.0)
59_fi__(_GENERIC__)
60_if__(!_GENERIC__)
61@settitle Using _GDBN__ v4.0 (_HOST__)
62_fi__(!_GENERIC__)
616875fd 63@iftex
cb9d2049 64@c @finalout
616875fd 65@end iftex
e91b87a3 66@titlepage
5a131cc7 67@title{Using _GDBN__}
26376b06 68@subtitle{A Guide to the GNU Source-Level Debugger}
5a131cc7
RP
69_if__(!_GENERIC__)
70@subtitle{On _HOST__ Systems}
71_fi__(!_GENERIC__)
e91b87a3 72@sp 1
369a6ade 73@c Maybe crank this up to "Fourth Edition" when released at FSF
5a131cc7
RP
74@c @subtitle Third Edition---_GDBN__ version 4.0
75@subtitle _GDBN__ version 4.0
369a6ade 76@subtitle January 1991
26376b06 77@author{Richard M. Stallman}
5a131cc7 78@author{Roland H. Pesch (Cygnus Support)}
e91b87a3 79@page
26376b06
RP
80
81@tex
82\def\$#1${{#1}} % Kluge: collect RCS revision info without $...$
83\xdef\manvers{\$Revision$} % For use in headers, footers too
84{\parskip=0pt
85\hfill Cygnus Support\par
1695733e 86\hfill {\it Using _GDBN__}, \manvers\par
26376b06
RP
87\hfill \TeX{}info \texinfoversion\par
88}
89@end tex
90
e91b87a3 91@vskip 0pt plus 1filll
d62719de 92Copyright @copyright{} 1988, 1989, 1990, 1991 Free Software Foundation, Inc.
e91b87a3 93
94Permission is granted to make and distribute verbatim copies of
95this manual provided the copyright notice and this permission notice
96are preserved on all copies.
97
98Permission is granted to copy and distribute modified versions of this
99manual under the conditions for verbatim copying, provided also that the
4187119d 100section entitled ``GNU General Public License'' is included exactly as
101in the original, and provided that the entire resulting derived work is
102distributed under the terms of a permission notice identical to this
103one.
e91b87a3 104
105Permission is granted to copy and distribute translations of this manual
106into another language, under the above conditions for modified versions,
4187119d 107except that the section entitled ``GNU General Public License'' may be
108included in a translation approved by the author instead of in the
109original English.
e91b87a3 110@end titlepage
111@page
112
54e4a398 113@node Top, New Features, (dir), (dir)
5a131cc7 114@unnumbered Summary of _GDBN__
e91b87a3 115
5a131cc7 116The purpose of a debugger such as _GDBN__ is to allow you to see what is
9da601bf 117going on ``inside'' another program while it executes---or what another
5a131cc7 118program was doing at the moment it crashed.
e91b87a3 119
5a131cc7 120_GDBN__ can do four main kinds of things (plus other things in support of
9da601bf 121these) to help you catch bugs in the act:
e91b87a3 122
123@enumerate
124@item
9da601bf 125Start your program, specifying anything that might affect its behavior.
e91b87a3 126
127@item
9da601bf 128Make your program stop on specified conditions.
e91b87a3 129
130@item
9da601bf 131Examine what has happened, when your program has stopped.
e91b87a3 132
133@item
9da601bf
RP
134Change things in your program, so you can experiment with correcting the
135effects of one bug and go on to learn about another.
e91b87a3 136@end enumerate
137
5a131cc7 138_GDBN__ can be used to debug programs written in C and C++. Pascal support
e91b87a3 139is being implemented, and Fortran support will be added when a GNU
5a131cc7 140Fortran compiler is ready.
e91b87a3 141
cb9d2049 142@node Free Software,,,
369a6ade 143@unnumberedsec Free Software
5a131cc7 144_GDBN__ is Free Software, protected by the GNU General Public License (GPL).
369a6ade
RP
145The GPL gives you the freedom to copy or adapt a licensed
146program---but every person getting a copy also gets with it the
147freedom to modify that copy (which means that they must get access to
148the source code), and the freedom to distribute further copies.
149Typical software companies use copyrights to limit your freedoms; the
150Free Software Foundation uses the GPL to preserve these freedoms.
151
152Fundamentally, the General Public License is a license which says that
153you have these freedoms and that you can't take these freedoms away
154from anyone else.
155
156For full details, @pxref{License}.
157
369a6ade 158@node New Features, Invocation, Top, Top
5a131cc7 159@unnumbered New Features in _GDBN__ version 4.0
9da601bf
RP
160
161@itemize @bullet
162@item
163TARGETS: Using the new command @samp{target}, you can select at runtime
164whether you are debugging local files, local processes, standalone
165systems over the serial port, realtime systems over a TCP/IP
5a131cc7 166connection, etc. _GDBN__ now uses a function vector to mediate access to
9da601bf
RP
167all the different possible targets, making it much easier to add
168support for new remote protocols.
169
170@item
5a131cc7 171WATCHPOINTS: _GDBN__ now sports watchpoints as well as breakpoints. You can
9da601bf
RP
172use a watchpoint to stop execution whenever the value of an expression
173changes, without having to predict a particular place in the inferior
174process where this may happen.
175
176@item
5a131cc7 177OBJECT CODE FORMATS: _GDBN__ uses a new scheme called Binary File
9da601bf
RP
178Descriptors (BFD) to permit it to switch dynamically, without
179reconfiguration or recompilation, between different object-file
180formats. Formats currently supported are COFF, a.out, and the new
181Intel 960 b.out; files may be read as .o's, archive libraries, or core
182dumps. BFD is available as a subroutine library so that other
183programs may take advantage of it, and the other GNU binary utilities
184are being converted to use it.
185
186@item
187CONFIGURATION: You must still choose a particular machine architecture
5a131cc7 188and operating system for _GDBN__'s host and target systems when _GDBN__ is built.
9da601bf
RP
189The script @samp{config.gdb} now handles specification of separate host
190and target configurations.
191
192@item
5a131cc7 193INTERACTION: _GDBN__ now uses the GNU @code{readline} interface to read its
9da601bf 194input; this provides inline editing of commands, using the familiar
5a131cc7
RP
195Emacs or @code{vi} keymaps, and command-history support. The user interface
196to _GDBN__'s control variables has been simplified and consolidated in two
a58d77ad
JG
197commands, @samp{set} and @samp{show}. Output lines are now broken at
198readable places, rather than overflowing onto the next line.
9da601bf
RP
199
200@item
5a131cc7 201SOURCE LANGUAGE: _GDBN__ now understands C++ source as well as C. Multiple
9da601bf 202inheritance is supported when used with G++ 2.0. There is also limited
5a131cc7 203support for C++ exception handling: _GDBN__ can break when an exception is
d2e08421 204raised, before the stack is peeled back to the exception handler's
a58d77ad
JG
205context. You can suppress output of machine-level addresses,
206displaying only source language information.
9da601bf
RP
207
208@item
5a131cc7 209PORTS: _GDBN__ has been ported to the following new architectures:
9da601bf
RP
210AT&T 3b1, Acorn RISC machine, HP300 running HPUX, big- and little-
211endian MIPS machines, Motorola 88k, Sun 386i, and Sun 3 running SunOS
2124. In addition, the following are supported as targets only: AMD
21329k, Intel 960, and Wind River's VxWorks.
214
215@item
5a131cc7 216SHARED LIBRARIES: _GDBN__ 4.0 supports SunOS shared libraries.
9da601bf
RP
217
218@item
219WORK IN PROGRESS: kernel debugging for BSD and Mach systems; Tahoe and
220HPPA architecture support.
221
222@end itemize
223
fe3f5fc8
RP
224@node Sample Session,,,
225@chapter A Sample _GDB__ Session
226
227You can use this manual at your leisure to read all about _GDBN__.
228However, a handful of commands are enough to get started using the
229debugger. This chapter illustrates these commands.
230
231In this sample session, we emphasize user input like this: @var{input},
232to make it easier to pick out from the surrounding output.
233
234We'll be using _GDBN__ to inspect GNU @code{m4} (a generic macro
235processor).
236
237_0__@smallexample
238$ @var{cd gm4/common}
239
240$ @var{_GDBP__ m4}
241Reading symbol data from m4...done.
242@end smallexample
243
244@noindent
245_GDBN__ only reads enough symbol data to know where to find the rest
246when needed; as a result, the first prompt comes up very quickly.
247
248@smallexample
249(_GDBP__) @var{break m4_changequote}
250Breakpoint 1 at 0x59d4: file builtin.c, line 812.
251@end smallexample
252
253@noindent
254We've chosen to see how the @code{m4} builtin @samp{changequote}
255works. We know the relevant subroutine is @samp{m4_changequote} (from
256inspecting the source), so we set a breakpoint there.
257
258@smallexample
259(_GDBP__) @var{run}
260Starting program: /s1/gnu/src/gm4/common/m4
261@var{`usual' quotes <not these>}
262usual quotes <not these>
263@end smallexample
264
265@noindent
266Now we've started @code{m4} running under _GDBN__ control; while we don't touch
267the @samp{m4_changequote} subroutine, the program runs as usual.
268
269@smallexample
270@var{changequote(<,>)}
271
272Breakpoint 1, m4_changequote (argc=3, argv=0x2b958) at builtin.c:812
273812 if (bad_argc(TOKEN_DATA_TEXT(argv[0]), argc, 1, 3))
274@end smallexample
275@noindent
276Once we've encountered the breakpoint, _GDBN__ suspends execution
277of our program, displaying information about where it stopped.
278
279@smallexample
280(_GDBP__) @var{s}
281bad_argc (name=0xf833cfb4<Address 0xf833cfb4 out of
282 bounds>, argc=3, min=1, max=3) at builtin.c:230
283230 if (min > 0 && argc < min) @{
284@end smallexample
285@noindent
286We single-stepped with the command @samp{s}; since there was a subroutine
287call, we've stopped in the first line of that subroutine, not in the next line
288of @code{m4_changequote}.
289
290The command @samp{next} would have taken us to the next line of the same
291subroutine. Now that we've stopped deeper in the stack, we can use the
292@samp{backtrace} command (which can also be spelled @samp{bt}) to get
293information about where we are.
294
295@smallexample
296(_GDBP__) @var{bt}
297#0 bad_argc (name=0xf833cfb4<Address 0xf833cfb4 out of bounds>, argc=3,
298 min=1, max=3) at builtin.c:230
299#1 0x59ec in m4_changequote (argc=3, argv=0x2b958) at builtin.c:812
300#2 0x6e38 in expand_macro (sym=0x2b060) at macro.c:242
301#3 0x6840 in expand_token (obs=0x0, t=176224, td=0xf7fffb08) at macro.c:71
302#4 0x6794 in expand_input () at macro.c:40
303#5 0x28dc in main (argc=0, argv=0xf7fffbf8) at m4.c:174
304@end smallexample
305
306@noindent
307We'll tell _GDBN__ to finish execution of this subroutine, to get back
308to @code{m4_changequote}.
309
310@smallexample
311(_GDBP__) @var{finish}
312Run till exit from #0 bad_argc (name=0xf833cfb4<Address 0xf833cfb4 out of
313 bounds>, argc=3, min=1, max=3) at builtin.c:230
3140x59ec in m4_changequote (argc=3, argv=0x2b958) at builtin.c:812
315812 if (bad_argc(TOKEN_DATA_TEXT(argv[0]), argc, 1, 3))
316Value returned is $1 = false
317(_GDBP__) @var{s}
318815 lquote = (argc >= 2) ? TOKEN_DATA_TEXT(argv[1])[0] : DEF_LQUOTE;
319(_GDBP__) @var{whatis lquote}
320type = char
321(_GDBP__) @var{p lquote}
322$2 = 96 '`'
323@end smallexample
324
325@noindent
326When we stepped to another line, @code{m4} was about to set a variable
327@samp{lquote}; we inspected its type with @samp{whatis} and its value
328with @samp{p} (the @samp{print} command). We can see some context by
329displaying the surrounding source code, with the @samp{l} (@code{list})
330command.
331
332@smallexample
333(_GDBP__) @var{l}
334810 token_data **argv;
335811 @{
336812 if (bad_argc(TOKEN_DATA_TEXT(argv[0]), argc, 1, 3))
337813 return;
338814
339815 lquote = (argc >= 2) ? TOKEN_DATA_TEXT(argv[1])[0] : DEF_LQUOTE;
340816 rquote = (argc >= 3) ? TOKEN_DATA_TEXT(argv[2])[0] : DEF_RQUOTE;
341817 @}
342818
343819 /*
344(_GDBP__) @var{s}
345816 rquote = (argc >= 3) ? TOKEN_DATA_TEXT(argv[2])[0] : DEF_RQUOTE;
346(_GDBP__) @var{s}
347817 @}
348(_GDBP__) @var{p lquote}
349$3 = 60 '<'
350(_GDBP__) @var{p rquote}
351$4 = 62 '>'
352@end smallexample
353
354@noindent
355We proceeded past another line with @samp{s}, and inspected the new
356values of @code{m4}'s internal variables @code{rquote} and
357@code{lquote}.
358
359Since we're done with our inspection of this subroutine, we'll tell
360_GDBN__ to allow @code{m4} to continue running, with the @samp{c}
361(@code{continue}) command:
362
363@smallexample
364(_GDBP__) @var{c}
365Continuing.
366
367@var{`usual' quotes <not these>}
368`usual' quotes not these
369
370Program exited normally.
371(_GDBP__) @var{quit}
372
373$
374_1__@end smallexample
375
376@noindent
377Finally, when we ended the @code{m4} run, _GDBN__ told us
378``@code{Program exited normally.}'' We ended our _GDBN__ session with
379the _GDBN__ @samp{quit} command.
380
381
382@node Starting and Stopping,,,
383@chapter Starting and Stopping
384
385@node Starting _GDBN__,,,
386@section Starting _GDBN__
9da601bf 387
5a131cc7 388_GDBN__ is invoked with the shell command @samp{_GDBP__}. Once started, it reads
54e4a398 389commands from the terminal until you tell it to exit.
9da601bf 390
fe3f5fc8
RP
391You can start by just calling @samp{_GDBP__} with no arguments or
392options; but the most usual way to start _GDBN__ is with one argument or
393two, specifying an executable program as the argument:
369a6ade 394@example
5a131cc7 395_GDBP__ program
369a6ade
RP
396@end example
397@noindent
398or you can start with both an executable program and a core file specified:
399@example
5a131cc7 400_GDBP__ program core
369a6ade
RP
401@end example
402
5a131cc7 403You can get more detailed control over how _GDBN__ starts up using some of
cb9d2049 404the command-line options.
369a6ade
RP
405
406All the options and command line arguments given are processed
407in sequential order. The order makes a difference when the
408@samp{-x} option is used.
409
369a6ade 410@node File Options, Mode Options, Invocation, Invocation
fe3f5fc8 411@subsection Options and Arguments to Choose Files
369a6ade 412
cb9d2049
RP
413As shown above, any arguments other than options specify an executable
414file and core file; that is, the first argument encountered with no
415associated option flag is equivalent to a @samp{-se} option, and the
416second, if any, is equivalent to a @samp{-c} option.
369a6ade
RP
417
418@table @code
419@item -s @var{file}
420Read symbol table from file @var{file}.
421
422@item -e @var{file}
423Use file @var{file} as the executable file to execute when
424appropriate, and for examining pure data in conjunction with a core
425dump.
426
427@item -se @var{file}
428Read symbol table from file @var{file} and use it as the executable
429file.
430
431@item -c @var{file}
432Use file @var{file} as a core dump to examine.
433
434@item -x @var{file}
5a131cc7 435Execute _GDBN__ commands from file @var{file}. @xref{Command Files}.
369a6ade
RP
436
437@item -d @var{directory}
438Add @var{directory} to the path to search for source files.
439@end table
440
fe3f5fc8
RP
441@node Mode Options, , ,
442@subsection Options to Choose Modes
369a6ade
RP
443
444@table @code
445@item -nx
5a131cc7 446Do not execute commands from the init files @file{._GDBP__init}.
369a6ade
RP
447Normally, the commands in these files are executed after all the
448command options and arguments have been processed. @xref{Command
449Files}.
450
451@item -q
452``Quiet''. Do not print the introductory and copyright messages. These
453messages are also suppressed in batch mode, or if an executable file name is
5a131cc7 454specified on the _GDBN__ command line.
369a6ade
RP
455
456@item -batch
9d7c0513 457Run in batch mode. Exit with code @code{0} after processing all the command
5a131cc7
RP
458files specified with @samp{-x} (and @file{._GDBP__init}, if not inhibited).
459Exit with nonzero status if an error occurs in executing the _GDBN__
369a6ade
RP
460commands in the command files.
461
5a131cc7 462Batch mode may be useful for running _GDBN__ as a filter, for example to
369a6ade 463download and run a program on another computer; in order to make this
9d7c0513
RP
464more useful, the message
465@example
466Program exited normally.
467@end example
468@noindent
5a131cc7 469(which is ordinarily issued whenever a program running under _GDBN__ control
9d7c0513 470terminates) is not issued when running in batch mode.
369a6ade
RP
471
472@item -fullname
5a131cc7 473This option is used when Emacs runs _GDBN__ as a subprocess. It tells _GDBN__
369a6ade
RP
474to output the full file name and line number in a standard,
475recognizable fashion each time a stack frame is displayed (which
476includes each time the program stops). This recognizable format looks
477like two @samp{\032} characters, followed by the file name, line number
478and character position separated by colons, and a newline. The
5a131cc7 479Emacs-to-_GDBN__ interface program uses the two @samp{\032} characters as
369a6ade
RP
480a signal to display the source code for the frame.
481
482@item -b @var{bps}
483Set the line speed (baud rate or bps) of any serial interface used by
5a131cc7 484_GDBN__ for remote debugging.
369a6ade
RP
485@end table
486
5a131cc7 487_if__(_I960__)
cb9d2049 488@node i960-Nindy Remote,,,
fe3f5fc8 489@subsection _GDBN__ with a Remote Intel 960 (Nindy)
369a6ade 490
9d7c0513 491``Nindy'' is the name of a Rom Monitor program for Intel 960 target
5a131cc7
RP
492systems. When _GDBN__ is configured to control a remote Intel 960 using
493Nindy, you can tell _GDBN__ how to connect to the 960 in several ways:
369a6ade
RP
494
495@itemize @bullet
496@item
497Through command line options specifying device, baud rate, and protocol;
498
499@item
500By responding to a prompt on startup;
501
502@item
5a131cc7 503By using the @samp{target} command at any point during your _GDBN__ session.
369a6ade
RP
504@end itemize
505
5a131cc7 506@node Nindy Startup,,,
fe3f5fc8 507@subsubsection Startup with Nindy
5a131cc7 508
369a6ade 509The command-line options for Nindy are detailed below. If you simply
5a131cc7
RP
510start @code{_GDBP__} without using options to specify a serial port, you are
511prompted for it, @emph{before} you reach the ordinary _GDBN__ prompt:
369a6ade
RP
512@example
513Attach /dev/ttyNN -- specify NN, or "quit" to quit:
514@end example
515@noindent
516You can, if you choose, simply start up with no Nindy connection by
517responding to the prompt with an empty line. If you do this, and later
518wish to attach to Nindy, use @samp{target} (@pxref{Target Commands}).
519
5a131cc7 520@node Nindy Options,,,
fe3f5fc8 521@subsubsection Options for Nindy
5a131cc7
RP
522
523These are the startup options for beginning your _GDBN__ session with a
369a6ade
RP
524Nindy-960 board attached:
525
526@table @code
527@item -r @var{port}
528Specify the serial port name of a serial interface to be used to connect
5a131cc7 529to the target system. This option is only available when _GDBN__ is
9d7c0513
RP
530configured for the Intel 960 target architecture. You may specify
531@var{port} as any of: a full pathname (e.g. @samp{-r /dev/ttya}), a
369a6ade
RP
532device name in @samp{/dev} (e.g. @samp{-r ttya}), or simply the unique
533suffix for a specific @code{tty} (e.g. @samp{-r a}).
534
535@item -O
5a131cc7 536(An uppercase letter ``O'', not a zero.) Specify that _GDBN__ should use
9d7c0513 537the ``old'' Nindy monitor protocol to connect to the target system.
5a131cc7 538This option is only available when _GDBN__ is configured for the Intel 960
9d7c0513 539target architecture.
369a6ade
RP
540
541@quotation
542@emph{Warning:} if you specify @samp{-O}, but are actually trying to
543connect to a target system using the current protocol, the connection
5a131cc7 544will fail appearing to be a speed mismatch, and _GDBN__ will repeatedly
369a6ade
RP
545attempt to reconnect at several different line speeds. You can abort
546this process with an interrupt.
547@end quotation
548
549@item -brk
5a131cc7 550Specify that _GDBN__ should first send a @samp{BREAK} signal to the target
369a6ade 551system, in an attempt to reset it, before connecting to a Nindy target.
5a131cc7 552This option is only available when _GDBN__ is configured for the Intel 960
369a6ade
RP
553target architecture.
554
9d7c0513
RP
555@quotation
556@emph{Warning:} Many target systems do not have the hardware that this
557requires; it only works with a few boards.
558@end quotation
559
369a6ade
RP
560@end table
561
9d7c0513
RP
562The standard @samp{-b} option controls the line speed used on the serial
563port.
5a131cc7 564_fi__(_I960__)
9d7c0513 565
5a131cc7
RP
566_if__(_AMD29K__)
567@node EB29K Remote,,,
fe3f5fc8 568@subsection _GDBN__ with a Remote EB29K
cb9d2049
RP
569
570@cindex EB29K board
571@cindex running 29K programs
572@cindex 29K
573
5a131cc7 574To use _GDBN__ from a Unix system to run programs on AMD's EB29K
cb9d2049
RP
575board in a PC, you must first connect a serial cable between the PC
576and a serial port on the Unix system. In the following, we assume
577you've hooked the cable between the PC's @samp{COM1} port and
578@samp{/dev/ttya} on the Unix system.
579
5a131cc7 580@node Comms (EB29K),,,
fe3f5fc8 581@subsubsection Communications Setup
cb9d2049
RP
582The next step is to set up the PC's port, by doing something like the
583following in DOS on the PC:
fe3f5fc8 584_0__@example
1695733e 585C:\> MODE com1:9600,n,8,1,none
fe3f5fc8 586_1__@end example
cb9d2049
RP
587@noindent
588This example---run on an MS DOS 4.0 system---sets the PC port to 9600
589bps, no parity, eight data bits, one stop bit, and no ``retry'' action;
590you must match the communications parameters when establishing the Unix
591end of the connection as well.
592@c FIXME: Who knows what this "no retry action" crud from the DOS manual may
593@c mean? It's optional; leave it out? [email protected], 25feb91
594
595To give control of the PC to the Unix side of the serial line, type
596the following at the DOS console:
fe3f5fc8 597_0__@example
1695733e 598C:\> CTTY com1
fe3f5fc8 599_1__@end example
cb9d2049
RP
600@noindent
601(Later, if you wish to return control to the DOS console, you can use
602the command @samp{CTTY con}---but you must send it over the device that
603had control, in our example over the @samp{com1} serial line).
604
cb9d2049
RP
605From the Unix host, use a communications program such as @code{tip} or
606@code{cu} to communicate with the PC; for example,
607@example
608cu -s 9600 -l /dev/ttya
609@end example
610@noindent
611The @code{cu} options shown specify, respectively, the linespeed and the
1695733e
RP
612serial port to use. If you use @code{tip} instead, your command line
613may look something like the following instead:
614@example
615tip -9600 /dev/ttya
616@end example
617@noindent
618Your system may define a different name where our example uses
619@samp{/dev/ttya} (the argument to @code{tip}). The communications
620parameters, including what port to use, are associated with the
621@code{tip} argument in the ``remote'' descriptions file---normally the
622system table @file{/etc/remote}.
cb9d2049
RP
623@c FIXME: What if anything needs doing to match the "n,8,1,none" part of
624@c the DOS side's comms setup? cu can support -o (odd
625@c parity), -e (even parity)---apparently no settings for no parity or
626@c for character size. Taken from stty maybe...? John points out tip
627@c can set these as internal variables, eg ~s parity=none; man stty
628@c suggests that it *might* work to stty these options with stdin or
1695733e 629@c stdout redirected... [email protected], 25feb91
cb9d2049 630
cb9d2049
RP
631@kindex EBMON
632Using the @samp{tip} or @samp{cu} connection, change the DOS working
633directory to the directory containing a copy of your 29K program, then
634start the PC program @samp{EBMON} (an EB29K control program supplied
1695733e
RP
635with your board by AMD). You should see an initial display from
636@code{EBMON} similar to the one in our example, ending with the
637@code{EBMON} prompt @samp{#}---
fe3f5fc8 638_0__@example
1695733e
RP
639C:\> g:
640
641G:\> CD \usr\joe\work29k
642
643G:\USR\JOE\WORK29K> EBMON
644Am29000 PC Coprocessor Board Monitor, version 3.0-18
645Copyright 1990 Advanced Micro Devices, Inc.
646Written by Gibbons and Associates, Inc.
647
648Enter '?' or 'H' for help
649
650PC Coprocessor Type = EB29K
651I/O Base = 0x208
652Memory Base = 0xd0000
653
654Data Memory Size = 2048KB
655Available I-RAM Range = 0x8000 to 0x1fffff
656Available D-RAM Range = 0x80002000 to 0x801fffff
657
658PageSize = 0x400
659Register Stack Size = 0x800
660Memory Stack Size = 0x1800
661
662CPU PRL = 0x3
663Am29027 Available = No
664Byte Write Available = Yes
665
666# ~.
fe3f5fc8 667_1__@end example
cb9d2049 668
5a131cc7 669Then exit the @code{cu} or @code{tip} program (done in the example by
1695733e
RP
670typing @code{~.} at the @code{EBMON} prompt). @code{EBMON} will keep
671running, ready for _GDBN__ to take over.
cb9d2049 672
cb9d2049
RP
673For this example, we've assumed what is probably the most convenient
674way to make sure the same 29K program is on both the PC and the Unix
1695733e 675system: a PC/NFS connection that establishes ``drive @code{G:}'' on the
cb9d2049
RP
676PC as a file system on the Unix host. If you don't have PC/NFS or
677something similar connecting the two systems, you must arrange some
678other way---perhaps floppy-disk transfer---of getting the 29K program
5a131cc7 679from the Unix system to the PC; _GDBN__ will @emph{not} download it over the
cb9d2049
RP
680serial line.
681
fe3f5fc8
RP
682@node _GDBP__-EB29K,,,
683@subsubsection EB29K cross-debugging
cb9d2049 684Finally, @code{cd} to the directory containing an image of your 29K
5a131cc7 685program on the Unix system, and start _GDBN__---specifying as argument the
cb9d2049
RP
686name of your 29K program:
687@example
688cd /usr/joe/work29k
5a131cc7 689_GDBP__ myfoo
cb9d2049
RP
690@end example
691Now you can use the @code{target} command:
692@example
693target amd-eb /dev/ttya 9600 MYFOO
694@end example
695@c FIXME: test above 'target amd-eb' as spelled, with caps! caps are meant to
696@c emphasize that this is the name as seen by DOS (since I think DOS is
697@c single-minded about case of letters). [email protected], 25feb91
698
699@noindent
700In this example, we've assumed your program is in a file called
701@samp{myfoo}. Note that the filename given as the last argument to
702@samp{target amd-eb} should be the name of the program as it appears to DOS.
703In our example it is simply @samp{MYFOO}, but in general it can include
704a DOS path, and depending on your transfer mechanism may not resemble
705the name on the Unix side.
706
707At this point, you can set any breakpoints you wish; when you're ready
5a131cc7 708to see your program run on the 29K board, use the _GDBN__ command
cb9d2049
RP
709@example
710run
711@end example
712
5a131cc7 713To stop debugging the remote program, use the _GDBN__ @samp{detach}
cb9d2049
RP
714command.
715
716To return control of the PC to its console, use @code{tip} or @code{cu}
5a131cc7 717once again, after your _GDBN__ session has concluded, to attach to
cb9d2049
RP
718@code{EBMON}. You can then type the command @samp{q} to shut down
719@code{EBMON}, returning control to the DOS command-line interpreter.
720Type @samp{CTTY con} to return command input to the main DOS console,
721and type @samp{~.} to leave @code{tip} or @code{cu}.
722
723@node Remote Log, , Remote Commands, Remote
fe3f5fc8 724@subsubsection Remote Log
cb9d2049
RP
725@kindex eb.log
726@cindex log file for EB29K
5a131cc7 727The @samp{target amd-eb} command creates a file @file{eb.log} in the
cb9d2049
RP
728current working directory, to help debug problems with the connection.
729@file{eb.log} records all the output from @code{EBMON}, including echoes
730of the commands sent to it. Running @samp{tail -f} on this file in
731another window often helps to debug trouble with @code{EBMON}, or
732unexpected events on the PC side of the connection.
5a131cc7 733_fi__(_AMD29K__)
369a6ade 734
fe3f5fc8
RP
735@node Stopping _GDBN__,,,
736@section Stopping _GDBN__
737@cindex exiting _GDBN__
738@kindex quit
739To exit _GDBN__, use the @samp{quit} command (abbreviated @samp{q}), or type
740an end-of-file character (usually @kbd{C-d}).
741
742@cindex interrupt
743An interrupt (often @kbd{C-c}) will not exit from _GDBN__, but rather
744will terminate the action of any _GDBN__ command that is in progress and
745return to _GDBN__ command level. It is safe to type the interrupt
746character at any time because _GDBN__ does not allow it to take effect
747until a time when it is safe.
369a6ade 748
fe3f5fc8
RP
749If you've been using _GDBN__ to control an attached process or device,
750you can release it with the @samp{detach} command; @pxref{Attach}.
751
752@node Shell Commands,,,
753@section Shell Commands
754If you just need to execute occasional shell commands during your
755debugging session, there's no need to stop or suspend _GDBN__; you can
756just use the @samp{shell} command.
757
758@table @code
759@item shell @var{command string}
760@kindex shell
761@cindex shell escape
762Directs _GDBN__ to invoke an inferior shell to execute @var{command string}.
763The environment variable @code{SHELL} is used if it exists, otherwise _GDBN__
764uses @samp{/bin/sh}.
765@end table
766
767The utility @samp{make} is often needed in development environments.
768You don't have to use the @samp{shell} command for this purpose in _GDBN__:
769
770@table @code
771@item make @dots{}
772@kindex make
773@cindex calling make
774Causes _GDBN__ to execute an inferior @code{make} program with the specified
775arguments. This is equivalent to @samp{shell make @dots{}}.
776@end table
777
778@node Commands,,,
779@chapter _GDBN__ Commands
780
781@node Command Syntax,,,
782@section Command Syntax
5a131cc7 783A _GDBN__ command is a single line of input. There is no limit on how long
54e4a398
RP
784it can be. It starts with a command name, which is followed by arguments
785whose meaning depends on the command name. For example, the command
786@samp{step} accepts an argument which is the number of times to step,
787as in @samp{step 5}. You can also use the @samp{step} command with
788no arguments. Some command names do not allow any arguments.
4187119d 789
54e4a398 790@cindex abbreviation
5a131cc7 791_GDBN__ command names may always be truncated if that abbreviation is
54e4a398
RP
792unambiguous. Other possible command abbreviations are listed in the
793documentation of the individual commands. Sometimes even ambiguous
794abbreviations are allowed; for example, @samp{s} is specially defined as
795equivalent to @samp{step} even though there are other commands whose
796names start with @samp{s}.
4187119d 797
54e4a398 798@cindex repeating commands
5a131cc7 799A blank line as input to _GDBN__ means to repeat the previous command.
54e4a398
RP
800Certain commands will not repeat this way; these are commands for which
801unintentional repetition might cause trouble and which you are unlikely
802to want to repeat. Certain others (@samp{list} and @samp{x}) act
803differently when repeated because that is more useful.
4187119d 804
54e4a398
RP
805@kindex #
806@cindex comment
807A line of input starting with @samp{#} is a comment; it does nothing.
808This is useful mainly in command files (@xref{Command Files}).
4187119d 809
fe3f5fc8
RP
810@node Help,,,
811@section Getting Help
54e4a398
RP
812@cindex online documentation
813@kindex help
5a131cc7 814You can always ask _GDBN__ itself for information on its commands, using the
fe3f5fc8 815command @samp{help}.
e91b87a3 816
54e4a398 817@table @code
fe3f5fc8
RP
818@item help
819Used with no arguments, @samp{help} displays a short list of named
820categories of commands:
821@example
822(_GDBP__) help
823List of classes of commands:
824
825running -- Running the program
826stack -- Examining the stack
827data -- Examining data
828breakpoints -- Making program stop at certain points
829files -- Specifying and examining files
830status -- Status inquiries
831support -- Support facilities
832user-defined -- User-defined commands
833aliases -- Aliases of other commands
834obscure -- Obscure features
835
836Type "help" followed by a class name for a list of commands in that class.
837Type "help" followed by command name for full documentation.
838Command name abbreviations are allowed if unambiguous.
839(_GDBP__)
840@end example
4187119d 841
fe3f5fc8
RP
842@item help @var{category}
843Using one of the general help categories as an argument, you can get a
844list of the individual commands in a category. For example, here is the
845help display for category @samp{status}:
846@example
847(_GDBP__) help status
848Status inquiries.
e91b87a3 849
fe3f5fc8 850List of commands:
e91b87a3 851
fe3f5fc8
RP
852show -- Generic command for showing things set with "set"
853info -- Generic command for printing status
e91b87a3 854
fe3f5fc8
RP
855Type "help" followed by command name for full documentation.
856Command name abbreviations are allowed if unambiguous.
857(_GDBP__)
858@end example
e91b87a3 859
fe3f5fc8
RP
860@item help @var{command}
861With a command name as @samp{help} argument, _GDBN__ will display a
862short paragraph on how to use that command.
54e4a398 863@end table
e91b87a3 864
fe3f5fc8
RP
865In addition to @samp{help}, you can use the _GDBN__ commands @samp{info}
866and @samp{show} to inquire about the state of your program, or the state
867of _GDBN__ itself. Both commands support many ``sub-commands'', or
868topics of inquiry; this manual introduces each of them in the
869appropriate context. The listings under ``@code{info}'' and under
870``@code{show}'' in the Index point to all the sub-commands
871(@pxref{Index}).
96a816c5
JG
872
873@table @code
fe3f5fc8
RP
874@kindex info
875@item info
876This command is for describing the state of your program; for example,
877it can list the arguments given to your program (@samp{info args}), the
878registers currently in use (@samp{info registers}), or the breakpoints
879you've set (@samp{info breakpoints}). You can get a complete list of
880the @code{info} sub-commands with @samp{help info}.
9da601bf 881
23e2e5e1 882@kindex show
23e2e5e1 883@item show
fe3f5fc8
RP
884In contrast, @samp{show} is for describing the state of _GDBN__ itself.
885You can change most of the things you can @code{show}, by using the
886related command @samp{set}; for example, you can control what number
887system is used for displays with @samp{set radix}, or simply inquire
888which possibility is currently in use with @samp{show radix}.
889
890@kindex info set
891To display all the settable parameters and their current
23e2e5e1
RP
892values, you can use @samp{show} with no arguments; you may also use
893@samp{info set}. Both commands produce the same display.
fe3f5fc8
RP
894@c FIXME: "info set" violates the rule that "info" is for state of
895@c FIXME...program. Ck w/ GNU: "info set" to be called something else,
896@c FIXME...or change desc of rule---eg "state of prog and debugging session"?
897
898
899@kindex show version
900@item show version
901@c FIXME: chgd to "show version" from "info". Verify John doing same to GDBv4.
902This @samp{show} subcommand is one of those with no corresponding
903@samp{set} subcommand. As _GDBN__ evolves, new commands are introduced,
904and old ones may wither away. If multiple versions of _GDBN__ are in
905use at your site, it may occasionally be useful to make sure what
906version of _GDBN__ you're running. It is also useful to include this
907information in _GDBN__ bug-reports. _GDBN__ announces its version
908number if you start it with no arguments; but you can make it give this
909information on request, with the @samp{show version} command.
23e2e5e1 910
96a816c5
JG
911@end table
912
fe3f5fc8
RP
913@node Running,,,
914@chapter Running Programs Under _GDBN__
9c91ee3e 915
fe3f5fc8
RP
916@node Compilation,,,
917@section Compiling for Debugging
9c91ee3e 918
fe3f5fc8
RP
919In order to debug a program effectively, you need to ask for debugging
920information when you compile it. This debugging information is stored
921in the object file; it describes the data type of each variable or
922function and the correspondence between source line numbers and
923addresses in the executable code.
9da601bf 924
fe3f5fc8
RP
925To request debugging information, specify the @samp{-g} option when you run
926the compiler.
96a816c5 927
fe3f5fc8
RP
928The Unix C compiler is unable to handle the @samp{-g} and @samp{-O} options
929together. This means that you cannot ask for optimization if you ask for
930debugger information.
96a816c5 931
fe3f5fc8
RP
932The GNU C compiler supports @samp{-g} with or without @samp{-O}, making it
933possible to debug optimized code. We recommend that you @emph{always} use
934@samp{-g} whenever you compile a program. You may think the program is
935correct, but there's no sense in pushing your luck.
96a816c5 936
fe3f5fc8
RP
937Some things do not work as well with @samp{-g -O} as with just
938@samp{-g}, particularly on machines with instruction scheduling. If in
939doubt, recompile with @samp{-g} alone, and if this fixes the problem,
940please report it as a bug (including a test case---@pxref{_GDBN__ Bugs}).
d62719de 941
fe3f5fc8
RP
942Older versions of the GNU C compiler, _GCC__, permitted a variant option
943@samp{-gg} for debugging information. _GDBN__ no longer supports this format;
944if your GNU C compiler has this option, do not use it.
9c91ee3e 945
fe3f5fc8
RP
946@ignore
947@comment As far as I know, there are no cases in which _GDBN__ will
948@comment produce strange output in this case. (but no promises).
949If your program includes archives made with the @code{ar} program, and
950if the object files used as input to @code{ar} were compiled without the
951@samp{-g} option and have names longer than 15 characters, _GDBN__ will get
952confused reading the program's symbol table. No error message will be
953given, but _GDBN__ may behave strangely. The reason for this problem is a
954deficiency in the Unix archive file format, which cannot represent file
955names longer than 15 characters.
a58d77ad 956
fe3f5fc8
RP
957To avoid this problem, compile the archive members with the @samp{-g}
958option or use shorter file names. Alternatively, use a version of GNU
959@code{ar} dated more recently than August 1989.
960@end ignore
4187119d 961
4187119d 962
fe3f5fc8
RP
963@node Starting,,,
964@section Starting your Program
965@cindex starting
966@cindex running
967@kindex run
968To start your program under _GDBN__, use the @samp{run} command. Except on
969VxWorks, the program must already have been specified using the
970@samp{file} or @samp{exec-file} command, or with an argument to _GDBN__
971(@pxref{Files}).
9da601bf 972
fe3f5fc8
RP
973On targets that support processes, @samp{run} creates an inferior
974process and makes that process run your program. On other targets,
975@samp{run} jumps to the location it has recorded for the start of the
976program.
9da601bf 977
fe3f5fc8
RP
978The execution of a program is affected by certain information it
979receives from its superior. _GDBN__ provides ways to specify this
980information, which you must do @i{before} starting the program. (You
981can change it after starting the program, but such changes do not affect
982the program unless you start it over again.) This information may be
983divided into three categories:
9da601bf 984
fe3f5fc8
RP
985@table @asis
986@item The @i{arguments.}
987You specify the arguments to give the program as the arguments of the
988@samp{run} command. If a shell is available on your target, the shell
989is used to pass the arguments, so that you may use normal conventions
990(for example regular expression expansion or variable substitution) in
991describing the arguments. In Unix systems, you can control which shell
992is used with the @code{SHELL} environment variable.
9da601bf 993
fe3f5fc8
RP
994@item The @i{environment.}
995The program normally inherits its environment from _GDBN__, but you can
996use the _GDBN__ commands @samp{set environment} and
997@samp{unset environment} to change parts of the environment that will
998be given to the program.@refill
9da601bf 999
fe3f5fc8
RP
1000@item The @i{working directory.}
1001The program inherits its working directory from _GDBN__. You can set _GDBN__'s
1002working directory with the @samp{cd} command in _GDBN__.
9da601bf
RP
1003@end table
1004
fe3f5fc8
RP
1005When you issue the @samp{run} command, your program begins to execute
1006immediately. @xref{Stopping}, for discussion of how to arrange for your
1007program to stop.
4187119d 1008
fe3f5fc8
RP
1009Note that once your program has been started by the @samp{run} command,
1010you may evaluate expressions that involve calls to functions in the
1011inferior, using the @samp{print} or @samp{call} commands. @xref{Data}.
4187119d 1012
fe3f5fc8
RP
1013If the modification time of your symbol file has changed since the last
1014time _GDBN__ read its symbols, _GDBN__ will discard its symbol table and re-read
1015it. In this process, it tries to retain your current breakpoints.
9c91ee3e 1016
fe3f5fc8
RP
1017@menu
1018* Arguments:: Specifying the arguments for your program.
1019* Environment:: Specifying the environment for your program.
1020* Working Directory:: Specifying the working directory for giving
1021 to your program when it is run.
1022* Input/Output:: Specifying the program's standard input and output.
1023* Attach:: Debugging a process started outside _GDBN__.
1024* Kill Process:: Getting rid of the child process running your program.
1025@end menu
9c91ee3e 1026
fe3f5fc8
RP
1027@node Arguments, Environment, Running, Running
1028@section Your Program's Arguments
9c91ee3e 1029
fe3f5fc8
RP
1030@cindex arguments (to your program)
1031The arguments to your program are specified by the arguments of the
1032@samp{run} command. They are passed to a shell, which expands wildcard
1033characters and performs redirection of I/O, and thence to the program.
d62719de 1034
fe3f5fc8
RP
1035@samp{run} with no arguments uses the same arguments used by the previous
1036@samp{run}.
1037
1038@kindex set args
d62719de 1039@table @code
fe3f5fc8
RP
1040@item set args
1041The command @samp{set args} can be used to specify the arguments to be used
1042the next time the program is run. If @samp{set args} has no arguments, it
1043means to use no arguments the next time the program is run. If you have
1044run your program with arguments and want to run it again with no arguments,
1045this is the only way to do so.
d62719de 1046
fe3f5fc8
RP
1047@item show args
1048@kindex show args
1049Show the arguments to give your program when it is started.
d62719de
JG
1050@end table
1051
fe3f5fc8
RP
1052@node Environment, Working Directory, Arguments, Running
1053@section Your Program's Environment
9c91ee3e 1054
fe3f5fc8
RP
1055@cindex environment (of your program)
1056The @dfn{environment} consists of a set of @dfn{environment variables} and
1057their values. Environment variables conventionally record such things as
1058your user name, your home directory, your terminal type, and your search
1059path for programs to run. Usually you set up environment variables with
1060the shell and they are inherited by all the other programs you run. When
1061debugging, it can be useful to try running the program with different
1062environments without having to start the debugger over again.
9c91ee3e
RP
1063
1064@table @code
fe3f5fc8
RP
1065@item show environment @var{varname}
1066@kindex show environment
1067Print the value of environment variable @var{varname} to be given to
1068your program when it is started.
9c91ee3e 1069
fe3f5fc8
RP
1070@item show environment
1071Print the names and values of all environment variables to be given to
1072your program when it is started.
9da601bf 1073
fe3f5fc8
RP
1074@item set environment @var{varname} @var{value}
1075@itemx set environment @var{varname} = @var{value}
1076@kindex set environment
1077Sets environment variable @var{varname} to @var{value}, for your program
1078only, not for _GDBN__ itself. @var{value} may be any string; the values of
1079environment variables are just strings, and any interpretation is
1080supplied by your program itself. The @var{value} parameter is optional;
1081if it is eliminated, the variable is set to a null value.
9c91ee3e 1082
fe3f5fc8 1083For example, this command:
e91b87a3 1084
fe3f5fc8
RP
1085@example
1086set env USER = foo
1087@end example
e91b87a3 1088
fe3f5fc8
RP
1089@noindent
1090tells the program, when subsequently run, to assume it is being run
1091on behalf of the user named @samp{foo}.
e91b87a3 1092
fe3f5fc8
RP
1093@item delete environment @var{varname}
1094@itemx unset environment @var{varname}
1095@kindex delete environment
1096@kindex unset environment
1097Remove variable @var{varname} from the environment to be passed to your
1098program. This is different from @samp{set env @var{varname}@ =};
1099@samp{delete environment} removes the variable from the environment,
1100rather than assigning it an empty value. This command can be
1101abbreviated @samp{d e}.
1102@end table
e91b87a3 1103
fe3f5fc8
RP
1104@node Working Directory, Input/Output, Environment, Running
1105@section Your Program's Working Directory
9c91ee3e 1106
fe3f5fc8
RP
1107@cindex working directory (of your program)
1108Each time you start your program with @samp{run}, it inherits its
1109working directory from the current working directory of _GDBN__. _GDBN__'s
1110working directory is initially whatever it inherited from its parent
1111process (typically the shell), but you can specify a new working
1112directory in _GDBN__ with the @samp{cd} command.
9c91ee3e 1113
fe3f5fc8
RP
1114The _GDBN__ working directory also serves as a default for the commands
1115that specify files for _GDBN__ to operate on. @xref{Files}.
e91b87a3 1116
fe3f5fc8
RP
1117@table @code
1118@item cd @var{directory}
1119@kindex cd
1120Set _GDBN__'s working directory to @var{directory}.
e91b87a3 1121
fe3f5fc8
RP
1122@item pwd
1123@kindex pwd
1124Print _GDBN__'s working directory.
1125@end table
e91b87a3 1126
fe3f5fc8
RP
1127@node Input/Output, Attach, Working Directory, Running
1128@section Your Program's Input and Output
9da601bf 1129
fe3f5fc8
RP
1130@cindex redirection
1131@cindex i/o
1132@cindex terminal
1133@cindex controlling terminal
1134By default, the program you run under _GDBN__ does input and output to the same
1135terminal that _GDBN__ uses.
4187119d 1136
fe3f5fc8
RP
1137You can redirect the program's input and/or output using @samp{sh}-style
1138redirection commands in the @samp{run} command. For example,
4187119d 1139
fe3f5fc8
RP
1140_0__@example
1141run > outfile
1142_1__@end example
4187119d 1143
fe3f5fc8
RP
1144@noindent
1145starts the program, diverting its output to the file @file{outfile}.
9d7c0513 1146
fe3f5fc8
RP
1147@kindex tty
1148Another way to specify where the program should do input and output is
1149with the @samp{tty} command. This command accepts a file name as
1150argument, and causes this file to be the default for future @samp{run}
1151commands. It also resets the controlling terminal for the child
1152process, for future @samp{run} commands. For example,
d62719de 1153
fe3f5fc8
RP
1154@example
1155tty /dev/ttyb
1156@end example
d62719de 1157
fe3f5fc8
RP
1158@noindent
1159directs that processes started with subsequent @samp{run} commands
1160default to do input and output on the terminal @file{/dev/ttyb} and have
1161that as their controlling terminal.
d62719de 1162
fe3f5fc8
RP
1163An explicit redirection in @samp{run} overrides the @samp{tty} command's
1164effect on input/output redirection, but not its effect on the
1165controlling terminal.
d62719de 1166
fe3f5fc8
RP
1167When you use the @samp{tty} command or redirect input in the @samp{run}
1168command, only the @emph{input for your program} is affected. The input
1169for _GDBN__ still comes from your terminal.
d62719de 1170
fe3f5fc8
RP
1171@node Attach, Kill Process, Input/Output, Running
1172@section Debugging an Already-Running Process
1173@kindex attach
1174@cindex attach
d62719de 1175
fe3f5fc8
RP
1176@table @code
1177@item attach @var{process--id}
1178This command attaches to a running process, if your currently selected
1179target supports processes. (@samp{info files} will show your active
1180targets). The command takes as argument a process ID.
d62719de 1181
fe3f5fc8
RP
1182You specify a process ID to debug an already-running process that was
1183started outside of _GDBN__. (The usual way to find out the process-id of
1184a Unix process is with the @code{ps} utility, or with the @code{jobs -l}
1185shell command.) In this case, you must have permission to send the
1186process a signal, and it must have the same effective user ID as the
1187debugger.
1188@end table
d62719de 1189
fe3f5fc8
RP
1190When using @samp{attach}, you should first use the @samp{file} command
1191to specify the program running in the process and load its symbol table.
d62719de 1192
fe3f5fc8
RP
1193The first thing _GDBN__ does after arranging to debug the process is to stop
1194it. You can examine and modify an attached process with all the _GDBN__
1195commands that ordinarily available when you start processes with
1196@samp{run}. You can insert breakpoints; you can step and continue; you
1197can modify storage. If you would rather the process continue running,
1198you may use the @samp{continue} command after attaching _GDBN__ to the
1199process.
d62719de 1200
fe3f5fc8
RP
1201@kindex detach
1202When you have finished debugging the attached process, you can use the
1203@samp{detach} command to release it from _GDBN__'s control. Detaching
1204the process continues its execution. After the @samp{detach} command,
1205that process and _GDBN__ become completely independent once more, and you
1206are ready to @samp{attach} another process or start one with @samp{run}.
d62719de 1207
fe3f5fc8
RP
1208If you exit _GDBN__ or use the @samp{run} command while you have an attached
1209process, you kill that process. By default, you will be asked for
1210confirmation if you try to do either of these things; you can control
1211whether or not this happens by using the @samp{set caution} command
1212(@pxref{User Interface}).
d62719de 1213
fe3f5fc8
RP
1214@node Kill Process, , Attach, Running
1215@section Killing the Child Process
d62719de 1216
fe3f5fc8
RP
1217@table @code
1218@item kill
1219@kindex kill
1220Kill the child process in which your program is running under _GDBN__.
1221@end table
d62719de 1222
fe3f5fc8
RP
1223This command is useful if you wish to debug a core dump instead. _GDBN__
1224ignores any core dump file if it is actually running the program.
d62719de 1225
fe3f5fc8
RP
1226On some operating systems, you can't execute your program in another
1227process while breakpoints are active inside _GDBN__. The @samp{kill}
1228command is also useful in this situation, if you wish to run the program
1229outside the debugger.
d62719de 1230
fe3f5fc8
RP
1231The @samp{kill} command is also useful if you wish to recompile and
1232relink the program, since on many systems it is impossible to modify an
1233executable file which is running in a process. In this case, when you
1234next type @samp{run}, _GDBN__ will notice that the file has changed, and
1235will re-read the symbol table (while trying to preserve your current
1236breakpoint settings).
d62719de 1237
fe3f5fc8
RP
1238@node Stopping, Stack, Running, Top
1239@chapter Stopping and Continuing
d62719de 1240
fe3f5fc8
RP
1241When you run a program normally, it runs until it terminates. The
1242principal purpose of using a debugger is so that you can stop it before
1243that point; or so that if the program runs into trouble you can
1244investigate and find out why.
e91b87a3 1245
fe3f5fc8
RP
1246@menu
1247* Signals:: Fatal signals in your program just stop it;
1248 then you can use _GDBN__ to see what is going on.
1249* Breakpoints:: Breakpoints let you stop your program when it
1250 reaches a specified point in the code.
1251 an expression changes.
1252* Continuing:: Resuming execution until the next signal or breakpoint.
1253* Stepping:: Stepping runs the program a short distance and
1254 then stops it wherever it has come to.
1255@end menu
e91b87a3 1256
fe3f5fc8
RP
1257@node Signals, Breakpoints, Stopping, Stopping
1258@section Signals
1259@cindex signals
4187119d 1260
fe3f5fc8
RP
1261A signal is an asynchronous event that can happen in a program. The
1262operating system defines the possible kinds of signals, and gives each kind
1263a name and a number. For example, @code{SIGINT} is the signal a program
1264gets when you type @kbd{Ctrl-c}; @code{SIGSEGV} is the signal a program
1265gets from referencing a place in memory far away from all the areas in use;
1266@code{SIGALRM} occurs when the alarm clock timer goes off (which happens
1267only if the program has requested an alarm).
23e2e5e1 1268
fe3f5fc8
RP
1269@cindex fatal signals
1270Some signals, including @code{SIGALRM}, are a normal part of the
1271functioning of the program. Others, such as @code{SIGSEGV}, indicate
1272errors; these signals are @dfn{fatal} (kill the program immediately) if the
1273program has not specified in advance some other way to handle the signal.
1274@code{SIGINT} does not indicate an error in the program, but it is normally
1275fatal so it can carry out the purpose of @kbd{Ctrl-c}: to kill the program.
9c91ee3e 1276
fe3f5fc8
RP
1277_GDBN__ has the ability to detect any occurrence of a signal in the program
1278running under _GDBN__'s control. You can tell _GDBN__ in advance what to do for
1279each kind of signal.
e91b87a3 1280
fe3f5fc8
RP
1281@cindex handling signals
1282Normally, _GDBN__ is set up to ignore non-erroneous signals like @code{SIGALRM}
1283(so as not to interfere with their role in the functioning of the program)
1284but to stop the program immediately whenever an error signal happens.
1285You can change these settings with the @samp{handle} command.
23e2e5e1 1286
fe3f5fc8
RP
1287@table @code
1288@item info signal
1289@kindex info signal
1290Print a table of all the kinds of signals and how _GDBN__ has been told to
1291handle each one. You can use this to see the signal numbers of all
1292the defined types of signals.
9c91ee3e 1293
fe3f5fc8
RP
1294@item handle @var{signal} @var{keywords}@dots{}
1295@kindex handle
1296Change the way _GDBN__ handles signal @var{signal}. @var{signal} can be the
1297number of a signal or its name (with or without the @samp{SIG} at the
1298beginning). The @var{keywords} say what change to make.
9c91ee3e 1299@end table
e91b87a3 1300
fe3f5fc8
RP
1301The keywords allowed by the @samp{handle} command can be abbreviated.
1302Their full names are
96a816c5 1303
9c91ee3e 1304@table @code
fe3f5fc8
RP
1305@item nostop
1306_GDBN__ should not stop the program when this signal happens. It may
1307still print a message telling you that the signal has come in.
96a816c5 1308
fe3f5fc8
RP
1309@item stop
1310_GDBN__ should stop the program when this signal happens. This implies
1311the @samp{print} keyword as well.
96a816c5 1312
fe3f5fc8
RP
1313@item print
1314_GDBN__ should print a message when this signal happens.
96a816c5 1315
fe3f5fc8
RP
1316@item noprint
1317_GDBN__ should not mention the occurrence of the signal at all. This
1318implies the @samp{nostop} keyword as well.
96a816c5 1319
fe3f5fc8
RP
1320@item pass
1321_GDBN__ should allow the program to see this signal; the program will be
1322able to handle the signal, or may be terminated if the signal is fatal
1323and not handled.
e91b87a3 1324
fe3f5fc8
RP
1325@item nopass
1326_GDBN__ should not allow the program to see this signal.
1327@end table
e91b87a3 1328
fe3f5fc8
RP
1329When a signal has been set to stop the program, the program cannot see the
1330signal until you continue. It will see the signal then, if @samp{pass} is
1331in effect for the signal in question @i{at that time}. In other words,
1332after _GDBN__ reports a signal, you can use the @samp{handle} command with
1333@samp{pass} or @samp{nopass} to control whether that signal will be seen by
1334the program when you later continue it.
e91b87a3 1335
fe3f5fc8
RP
1336You can also use the @samp{signal} command to prevent the program from
1337seeing a signal, or cause it to see a signal it normally would not see,
1338or to give it any signal at any time. @xref{Signaling}.
e91b87a3 1339
fe3f5fc8
RP
1340@node Breakpoints, Continuing, Signals, Stopping
1341@section Breakpoints
e91b87a3 1342
fe3f5fc8
RP
1343@cindex breakpoints
1344A @dfn{breakpoint} makes your program stop whenever a certain point in the
1345program is reached. You set breakpoints explicitly with _GDBN__ commands,
1346specifying the place where the program should stop by line number, function
1347name or exact address in the program. You can add various other conditions
1348to control whether the program will stop.
9c91ee3e 1349
fe3f5fc8
RP
1350Each breakpoint is assigned a number when it is created; these numbers are
1351successive integers starting with 1. In many of the commands for controlling
1352various features of breakpoints you use the breakpoint number to say which
1353breakpoint you want to change. Each breakpoint may be @dfn{enabled} or
1354@dfn{disabled}; if disabled, it has no effect on the program until you
1355enable it again.
e91b87a3 1356
fe3f5fc8
RP
1357@table @code
1358@kindex info break
1359@kindex $_
1360@item info break
1361The command @samp{info break} prints a list of all breakpoints set and not
1362deleted, showing their numbers, where in the program they are, and any
1363special features in use for them. Disabled breakpoints are included in the
1364list, but marked as disabled. @samp{info break} with a breakpoint number
1365as argument lists only that breakpoint. The convenience variable @code{$_}
1366and the default examining-address for the @samp{x} command are set to the
1367address of the last breakpoint listed (@pxref{Memory}).
e91b87a3 1368
fe3f5fc8
RP
1369@kindex info watch
1370@item info watch
1371This command prints a list of watchpoints.
e91b87a3 1372
fe3f5fc8
RP
1373@cindex watchpoints
1374A @dfn{watchpoint} is a special breakpoint that stops your program when
1375the value of an expression changes. You can use a watchpoint to stop
1376execution whenever the value of an expression changes, without having to
1377predict a particular place in the inferior process where this may
1378happen. Aside from the different syntax in setting a watchpoint, it is
1379managed exactly like any other breakpoint and is enabled, disabled, and
1380deleted using exactly the same commands.
23e2e5e1 1381
fe3f5fc8
RP
1382Watchpoints currently execute two orders of magnitude more slowly than
1383other breakpoints, but this can well be worth it to catch errors where
1384you have no clue what part of your program is the culprit. Some
1385processors provide special hardware to implement this feature; future
1386releases of _GDBN__ will use such hardware if it is available.
1387
1388@end table
9c91ee3e 1389
369a6ade 1390@menu
fe3f5fc8
RP
1391* Set Breaks:: How to establish breakpoints.
1392* Exception Handling:: How _GDBN__ supports exception handling for C++.
1393* Delete Breaks:: How to remove breakpoints no longer needed.
1394* Disabling:: How to disable breakpoints (turn them off temporarily).
1395* Conditions:: Making extra conditions on whether to stop.
1396* Break Commands:: Commands to be executed at a breakpoint.
1397* Error in Breakpoints::
369a6ade
RP
1398@end menu
1399
fe3f5fc8
RP
1400@node Set Breaks, Exception Handling, Breakpoints, Breakpoints
1401@subsection Setting Breakpoints
23e2e5e1 1402
fe3f5fc8
RP
1403@kindex break
1404@kindex watch
1405Breakpoints are set with the @samp{break} command (abbreviated @samp{b}).
1406Watchpoints are set with the @samp{watch} command.
23e2e5e1 1407
fe3f5fc8 1408You have several ways to say where the breakpoint should go.
23e2e5e1 1409
fe3f5fc8
RP
1410@table @code
1411@item break @var{function}
1412Set a breakpoint at entry to function @var{function}.
23e2e5e1 1413
fe3f5fc8
RP
1414@item break @var{+offset}
1415@itemx break @var{-offset}
1416Set a breakpoint some number of lines forward or back from the position
1417at which execution stopped in the currently selected frame.
23e2e5e1 1418
fe3f5fc8
RP
1419@item break @var{linenum}
1420Set a breakpoint at line @var{linenum} in the current source file.
1421That file is the last file whose source text was printed. This
1422breakpoint will stop the program just before it executes any of the
1423code on that line.
23e2e5e1 1424
fe3f5fc8
RP
1425@item break @var{filename}:@var{linenum}
1426Set a breakpoint at line @var{linenum} in source file @var{filename}.
23e2e5e1 1427
fe3f5fc8
RP
1428@item break @var{filename}:@var{function}
1429Set a breakpoint at entry to function @var{function} found in file
1430@var{filename}. Specifying a file name as well as a function name is
1431superfluous except when multiple files contain similarly named
1432functions.
1433
1434@item break *@var{address}
1435Set a breakpoint at address @var{address}. You can use this to set
1436breakpoints in parts of the program which do not have debugging
1437information or source files.
1438
1439@item break
1440Set a breakpoint at the next instruction to be executed in the selected
1441stack frame (@pxref{Stack}). In any selected frame but the innermost,
1442this will cause the program to stop as soon as control returns to that
1443frame. This is equivalent to a @samp{finish} command in the frame
1444inside the selected frame. If this is done in the innermost frame, _GDBN__
1445will stop the next time it reaches the current location; this may be
1446useful inside of loops.
1447
1448_GDBN__ normally ignores breakpoints when it resumes execution, until at
1449least one instruction has been executed. If it did not do this, you
1450would be unable to proceed past a breakpoint without first disabling the
1451breakpoint. This rule applies whether or not the breakpoint already
1452existed when the program stopped.
1453
1454@item break @dots{} if @var{cond}
1455Set a breakpoint with condition @var{cond}; evaluate the expression
1456@var{cond} each time the breakpoint is reached, and stop only if the
1457value is nonzero. @samp{@dots{}} stands for one of the possible
1458arguments described above (or no argument) specifying where to break.
1459@xref{Conditions}, for more information on breakpoint conditions.
1460
1461@item tbreak @var{args}
1462@kindex tbreak
1463Set a breakpoint enabled only for one stop. @var{args} are the
1464same as in the @samp{break} command, and the breakpoint is set in the same
1465way, but the breakpoint is automatically disabled the first time it
1466is hit. @xref{Disabling}.
1467
1468@item rbreak @var{regex}
1469@kindex rbreak
1470Set a breakpoint on all functions matching @var{regex}. This is
1471useful for setting breakpoints on overloaded functions that are not
1472members of any special classes. This command sets an unconditional
1473breakpoint on all matches, printing a list of all breakpoints it set.
1474Once these breakpoints are set, they are treated just like the
1475breakpoints set with the @samp{break} command. They can be deleted,
1476disabled, made conditional, etc., in the standard ways.
1477
1478@kindex watch
1479@item watch @var{expr}
1480Set a watchpoint for an expression.
1481@end table
1482
1483_GDBN__ allows you to set any number of breakpoints at the same place in the
1484program. There is nothing silly or meaningless about this. When the
1485breakpoints are conditional, this is even useful (@pxref{Conditions}).
1486
1487@node Exception Handling, Delete Breaks, Set Breaks, Breakpoints
1488@subsection Breakpoints and Exceptions
1489@cindex exception handlers
1490
1491Some languages, such as GNU C++, implement exception handling. _GDBN__
1492can be used to examine what caused the program to raise an exception
1493and to list the exceptions the program is prepared to handle at a
1494given point in time.
1495
1496@cindex raise exceptions
1497GNU C++ raises an exception by calling a library function named
1498@code{__raise_exception} which has the following ANSI C interface:
9c91ee3e 1499
9c91ee3e 1500@example
fe3f5fc8
RP
1501 /* ADDR is where the exception identifier is stored.
1502 ID is the exception identifier. */
1503 void __raise_exception (void **addr, void *id);
9c91ee3e
RP
1504@end example
1505
23e2e5e1 1506@noindent
fe3f5fc8
RP
1507You can make the debugger catch all exceptions @emph{before} any stack
1508unwinding takes place: set a breakpoint on @code{__raise_exception}
1509(@pxref{Breakpoints}). If you set a breakpoint in an exception handler
1510instead, it may not be easy to find out where the exception was raised.
9c91ee3e 1511
fe3f5fc8
RP
1512By using a conditional breakpoint (@xref{Conditions}), you can cause
1513the debugger to stop only when a specific exception is raised.
1514Multiple conditional breakpoints can be used to stop the program when
1515any of a number of exceptions are raised.
1516
1517@table @code
1518@item catch @var{exceptions}
1519@kindex catch
1520
1521Breakpoints can be set at active exception handlers by using the
1522@samp{catch} command. @var{exceptions} is a list of names of exceptions
1523to catch.
9c91ee3e
RP
1524@end table
1525
fe3f5fc8
RP
1526You can use @samp{info catch} to list active exception handlers;
1527@pxref{Frame Info}.
9d7c0513 1528
fe3f5fc8
RP
1529There are currently some limitations to exception handling in _GDBN__.
1530These will be corrected in a future release.
9d7c0513 1531
fe3f5fc8
RP
1532@itemize @bullet
1533@item
1534If you call a function interactively, _GDBN__ will normally return
1535control to you when the function has finished executing. If the call
1536raises an exception, however, the call may bypass the mechanism that
1537returns control to the user and cause the program to simply continue
1538running until it hits a breakpoint, catches a signal that _GDBN__ is
1539listening for, or exits.
1540@item
1541You cannot raise an exception interactively.
1542@item
1543You cannot interactively install an exception handler.
1544@end itemize
9d7c0513 1545
fe3f5fc8
RP
1546@node Delete Breaks, Disabling, Exception Handling, Breakpoints
1547@subsection Deleting Breakpoints
cb9d2049 1548
fe3f5fc8
RP
1549@cindex clearing breakpoints, watchpoints
1550@cindex deleting breakpoints, watchpoints
1551It is often necessary to eliminate a breakpoint once it has done its job
1552and you no longer want the program to stop there. This is called
1553@dfn{deleting} the breakpoint. A breakpoint that has been deleted no
1554longer exists in any sense; it is forgotten.
cb9d2049 1555
fe3f5fc8
RP
1556With the @samp{clear} command you can delete breakpoints according to where
1557they are in the program. With the @samp{delete} command you can delete
1558individual breakpoints by specifying their breakpoint numbers.
9d7c0513 1559
fe3f5fc8
RP
1560It is not necessary to delete a breakpoint to proceed past it. _GDBN__
1561automatically ignores breakpoints on the first instruction to be executed
1562when you continue execution without changing the execution address.
9d7c0513 1563
fe3f5fc8
RP
1564@table @code
1565@item clear
1566@kindex clear
1567Delete any breakpoints at the next instruction to be executed in the
1568selected stack frame (@pxref{Selection}). When the innermost frame
1569is selected, this is a good way to delete a breakpoint that the program
1570just stopped at.
1571
1572@item clear @var{function}
1573@itemx clear @var{filename}:@var{function}
1574Delete any breakpoints set at entry to the function @var{function}.
1575
1576@item clear @var{linenum}
1577@itemx clear @var{filename}:@var{linenum}
1578Delete any breakpoints set at or within the code of the specified line.
1579
1580@item delete breakpoints @var{bnums}@dots{}
1581@itemx delete @var{bnums}@dots{}
1582@itemx delete
1583@kindex delete breakpoints
1584@kindex delete
1585Delete the breakpoints of the numbers specified as arguments. If no
1586argument is specified, delete all breakpoints.
9d7c0513
RP
1587@end table
1588
fe3f5fc8
RP
1589@node Disabling, Conditions, Delete Breaks, Breakpoints
1590@subsection Disabling Breakpoints
9d7c0513 1591
fe3f5fc8
RP
1592@cindex disabled breakpoints
1593@cindex enabled breakpoints
1594Rather than deleting a breakpoint, you might prefer to @dfn{disable} it.
1595This makes the breakpoint inoperative as if it had been deleted, but
1596remembers the information on the breakpoint so that you can @dfn{enable}
1597it again later.
e91b87a3 1598
fe3f5fc8
RP
1599You disable and enable breakpoints with the @samp{enable} and
1600@samp{disable} commands, optionally specifying one or more breakpoint
1601numbers as arguments. Use @samp{info break} to print a list of
1602breakpoints if you don't know which breakpoint numbers to use.
9d7c0513 1603
fe3f5fc8 1604A breakpoint can have any of four different states of enablement:
e91b87a3 1605
fe3f5fc8
RP
1606@itemize @bullet
1607@item
1608Enabled. The breakpoint will stop the program. A breakpoint made
1609with the @samp{break} command starts out in this state.
1610@item
1611Disabled. The breakpoint has no effect on the program.
1612@item
1613Enabled once. The breakpoint will stop the program, but
1614when it does so it will become disabled. A breakpoint made
1615with the @samp{tbreak} command starts out in this state.
1616@item
1617Enabled for deletion. The breakpoint will stop the program, but
1618immediately after it does so it will be deleted permanently.
1619@end itemize
e91b87a3 1620
fe3f5fc8 1621You can use the following commands to enable or disable a breakpoint:
e91b87a3 1622
fe3f5fc8
RP
1623@table @code
1624@item disable breakpoints @var{bnums}@dots{}
1625@itemx disable @var{bnums}@dots{}
1626@itemx disable
1627@kindex disable breakpoints
1628@kindex disable
1629Disable the specified breakpoints---or all breakpoints, if none are
1630listed. A disabled breakpoint has no effect but is not forgotten. All
1631options such as ignore-counts, conditions and commands are remembered in
1632case the breakpoint is enabled again later.
e91b87a3 1633
fe3f5fc8
RP
1634@item enable breakpoints @var{bnums}@dots{}
1635@itemx enable @var{bnums}@dots{}
1636@itemx enable
1637@kindex enable breakpoints
1638@kindex enable
1639Enable the specified breakpoints (or all defined breakpoints). They
1640become effective once again in stopping the program, until you specify
1641otherwise.
1642
1643@item enable breakpoints once @var{bnums}@dots{}
1644@itemx enable once @var{bnums}@dots{}
1645Enable the specified breakpoints temporarily. Each will be disabled
1646again the next time it stops the program (unless you have used one of
1647these commands to specify a different state before that time comes).
1648
1649@item enable breakpoints delete @var{bnums}@dots{}
1650@itemx enable delete @var{bnums}@dots{}
1651Enable the specified breakpoints to work once and then die. Each of
1652the breakpoints will be deleted the next time it stops the program
1653(unless you have used one of these commands to specify a different
1654state before that time comes).
e91b87a3 1655@end table
1656
fe3f5fc8
RP
1657Save for a breakpoint set with @samp{tbreak} (@pxref{Set Breaks}),
1658breakpoints that you set are enabled or disabled only when you use one
1659of the commands above. (The command @samp{until} can set and delete a
1660breakpoint on its own, but it will not change the state of your
1661breakpoints).
e91b87a3 1662
fe3f5fc8
RP
1663@node Conditions, Break Commands, Disabling, Breakpoints
1664@subsection Break Conditions
1665@cindex conditional breakpoints
1666@cindex breakpoint conditions
9c91ee3e 1667
fe3f5fc8
RP
1668The simplest sort of breakpoint breaks every time the program reaches a
1669specified place. You can also specify a @dfn{condition} for a
1670breakpoint. A condition is just a boolean expression in your
1671programming language. (@xref{Expressions}). A breakpoint with a
1672condition evaluates the expression each time the program reaches it, and
1673the program stops only if the condition is true.
e91b87a3 1674
fe3f5fc8
RP
1675Break conditions may have side effects, and may even call functions in your
1676program. These may sound like strange things to do, but their effects are
1677completely predictable unless there is another enabled breakpoint at the
1678same address. (In that case, _GDBN__ might see the other breakpoint first and
1679stop the program without checking the condition of this one.) Note that
1680breakpoint commands are usually more convenient and flexible for the
1681purpose of performing side effects when a breakpoint is reached
1682(@pxref{Break Commands}).
e91b87a3 1683
fe3f5fc8
RP
1684Break conditions can be specified when a breakpoint is set, by using
1685@samp{if} in the arguments to the @samp{break} command. @xref{Set Breaks}.
1686They can also be changed at any time with the @samp{condition} command:
e91b87a3 1687
fe3f5fc8
RP
1688@table @code
1689@item condition @var{bnum} @var{expression}
1690@kindex condition
1691Specify @var{expression} as the break condition for breakpoint number
1692@var{bnum}. From now on, this breakpoint will stop the program only if
1693the value of @var{expression} is true (nonzero, in C). @var{expression}
1694is not evaluated at the time the @samp{condition} command is given.
1695When you call @samp{condition}, the expression you specify is checked
1696immediately for syntactic correctness, and to determine whether symbols
1697in it have referents in the context of your breakpoint.
1698@xref{Expressions}.
e91b87a3 1699
fe3f5fc8
RP
1700@item condition @var{bnum}
1701Remove the condition from breakpoint number @var{bnum}. It becomes
1702an ordinary unconditional breakpoint.
1703@end table
1704
1705@cindex ignore count (of breakpoint)
1706A special case of a breakpoint condition is to stop only when the
1707breakpoint has been reached a certain number of times. This is so
1708useful that there is a special way to do it, using the @dfn{ignore
1709count} of the breakpoint. Every breakpoint has an ignore count, which
1710is an integer. Most of the time, the ignore count is zero, and
1711therefore has no effect. But if the program reaches a breakpoint whose
1712ignore count is positive, then instead of stopping, it just decrements
1713the ignore count by one and continues. As a result, if the ignore count
1714value is @var{n}, the breakpoint will not stop the next @var{n} times it
1715is reached.
e91b87a3 1716
9da601bf 1717@table @code
fe3f5fc8
RP
1718@item ignore @var{bnum} @var{count}
1719@kindex ignore
1720Set the ignore count of breakpoint number @var{bnum} to @var{count}.
1721The next @var{count} times the breakpoint is reached, your program's
1722execution will not stop; other than to decrement the ignore count, _GDBN__
1723takes no action.
e91b87a3 1724
fe3f5fc8
RP
1725To make the breakpoint stop the next time it is reached, specify
1726a count of zero.
1727
1728@item continue @var{count}
1729@itemx cont @var{count}
1730@itemx c @var{count}
1731@itemx fg @var{count}
1732@kindex cont @var{count}
1733@kindex continue @var{count}
1734Continue execution of the program, setting the ignore count of the
1735breakpoint that the program stopped at to @var{count} minus one.
1736Thus, the program will not stop at this breakpoint until the
1737@var{count}'th time it is reached.
1738
1739This command is allowed only when the program stopped due to a
1740breakpoint. At other times, the argument to @samp{cont} is ignored.
1741
1742The synonym @samp{fg} is provided purely for convenience, and has
1743exactly the same behavior as other forms of the command.
9da601bf
RP
1744@end table
1745
fe3f5fc8
RP
1746If a breakpoint has a positive ignore count and a condition, the condition
1747is not checked. Once the ignore count reaches zero, the condition will
1748be checked.
e91b87a3 1749
fe3f5fc8
RP
1750Note that you could achieve the effect of the ignore count with a
1751condition such as _0__@w{@samp{$foo-- <= 0}}_1__ using a debugger convenience
1752variable that is decremented each time. @xref{Convenience Vars}.
1753
1754@node Break Commands, Error in Breakpoints, Conditions, Breakpoints
1755@subsection Commands Executed on Breaking
1756
1757@cindex breakpoint commands
1758You can give any breakpoint a series of commands to execute when the
1759program stops due to that breakpoint. For example, you might want to
1760print the values of certain expressions, or enable other breakpoints.
1761
1762@table @code
1763@item commands @var{bnum}
1764@kindex commands
1765Specify a list of commands for breakpoint number @var{bnum}. The commands
1766themselves appear on the following lines. Type a line containing just
1767@samp{end} to terminate the commands.
1768
1769To remove all commands from a breakpoint, use the command
1770@samp{commands} and follow it immediately by @samp{end}; that is, give
1771no commands.
1772
1773With no arguments, @samp{commands} refers to the last breakpoint set
1774(not to the breakpoint most recently encountered).
1775@end table
1776
1777You can use breakpoint commands to start the program up again. Simply
1778use the @samp{cont} command, or @samp{step}, or any other command to
1779resume execution. However, if you do this, any further commands in the
1780same breakpoint's command list are ignored. When the program stops
1781again, _GDBN__ will act according to the cause of that stop.
1782
1783@kindex silent
1784If the first command specified is @samp{silent}, the usual message about
1785stopping at a breakpoint is not printed. This may be desirable for
1786breakpoints that are to print a specific message and then continue.
1787If the remaining commands too print nothing, you will see no sign that
1788the breakpoint was reached at all. @samp{silent} is not really a command;
1789it is meaningful only at the beginning of the commands for a breakpoint.
e91b87a3 1790
fe3f5fc8
RP
1791The commands @samp{echo} and @samp{output} that allow you to print precisely
1792controlled output are often useful in silent breakpoints. @xref{Output}.
e91b87a3 1793
fe3f5fc8
RP
1794For example, here is how you could use breakpoint commands to print the
1795value of @code{x} at entry to @code{foo} whenever it is positive.
e91b87a3 1796
fe3f5fc8
RP
1797_0__@example
1798break foo if x>0
1799commands
1800silent
1801echo x is\040
1802output x
1803echo \n
1804cont
1805end
1806_1__@end example
e91b87a3 1807
fe3f5fc8
RP
1808One application for breakpoint commands is to correct one bug so you can
1809test another. Put a breakpoint just after the erroneous line of code, give
1810it a condition to detect the case in which something erroneous has been
1811done, and give it commands to assign correct values to any variables that
1812need them. End with the @samp{cont} command so that the program does not
1813stop, and start with the @samp{silent} command so that no output is
1814produced. Here is an example:
4187119d 1815
1816@example
fe3f5fc8
RP
1817break 403
1818commands
1819silent
1820set x = y + 4
1821cont
1822end
4187119d 1823@end example
1824
fe3f5fc8
RP
1825One deficiency in the operation of automatically continuing breakpoints
1826under Unix appears when your program uses raw mode for the terminal.
1827_GDBN__ switches back to its own terminal modes (not raw) before executing
1828commands, and then must switch back to raw mode when your program is
1829continued. This causes any pending terminal input to be lost.
1830In the GNU system, this will be fixed by changing the behavior of
1831terminal modes.
4187119d 1832
fe3f5fc8
RP
1833Under Unix, when you have this problem, you might be able to get around
1834it by putting your actions into the breakpoint condition instead of
1835commands. For example
e91b87a3 1836
fe3f5fc8
RP
1837@example
1838condition 5 (x = y + 4), 0
1839@end example
e91b87a3 1840
fe3f5fc8
RP
1841@noindent
1842specifies a condition expression (@xref{Expressions}) that will change
1843@code{x} as needed, then always have the value 0 so the program will not
1844stop. Loss of input is avoided here because break conditions are
1845evaluated without changing the terminal modes. When you want to have
1846nontrivial conditions for performing the side effects, the operators
1847@samp{&&}, @samp{||} and @samp{?@dots{}:} may be useful.
e91b87a3 1848
fe3f5fc8
RP
1849@node Error in Breakpoints, , Break Commands, Breakpoints
1850@subsection ``Cannot Insert Breakpoints''
e91b87a3 1851
fe3f5fc8
RP
1852@c FIXME: "cannot insert breakpoints" error, v unclear.
1853@c Q in pending mail to Gilmore. [email protected], 26mar91
1854Under some operating systems, breakpoints cannot be used in a program if
1855any other process is running that program. In this situation,
1856attempting to run or continue a program with a breakpoint will cause _GDBN__
1857to stop the other process.
e91b87a3 1858
fe3f5fc8 1859When this happens, you have three ways to proceed:
e91b87a3 1860
fe3f5fc8
RP
1861@enumerate
1862@item
1863Remove or disable the breakpoints, then continue.
e91b87a3 1864
fe3f5fc8
RP
1865@item
1866Suspend _GDBN__, and copy the file containing the program to a new name.
1867Resume _GDBN__ and use the @samp{exec-file} command to specify that _GDBN__
1868should run the program under that name. Then start the program again.
e91b87a3 1869
fe3f5fc8
RP
1870@item
1871Relink the program so that the text segment is nonsharable, using the
1872linker option @samp{-N}. The operating system limitation may not apply
1873to nonsharable executables.
1874@end enumerate
e91b87a3 1875
fe3f5fc8
RP
1876@node Continuing, Stepping, Breakpoints, Stopping
1877@section Continuing
e91b87a3 1878
fe3f5fc8
RP
1879After your program stops, most likely you will want it to run some more if
1880the bug you are looking for has not happened yet.
e91b87a3 1881
fe3f5fc8
RP
1882@table @code
1883@item continue
1884@item cont
1885@kindex cont
1886@kindex continue
1887Continue running the program at the place where it stopped.
1888@end table
e91b87a3 1889
fe3f5fc8
RP
1890If the program stopped at a breakpoint, the place to continue running
1891is the address of the breakpoint. You might expect that continuing would
1892just stop at the same breakpoint immediately. In fact, @samp{cont}
1893takes special care to prevent that from happening. You do not need
1894to delete the breakpoint to proceed through it after stopping at it.
e91b87a3 1895
fe3f5fc8
RP
1896You can, however, specify an ignore-count for the breakpoint that the
1897program stopped at, by means of an argument to the @samp{cont} command.
1898@xref{Conditions}.
4187119d 1899
fe3f5fc8
RP
1900If the program stopped because of a signal other than @code{SIGINT} or
1901@code{SIGTRAP}, continuing will cause the program to see that signal.
1902You may not want this to happen. For example, if the program stopped
1903due to some sort of memory reference error, you might store correct
1904values into the erroneous variables and continue, hoping to see more
1905execution; but the program would probably terminate immediately as
1906a result of the fatal signal once it sees the signal. To prevent this,
1907you can continue with @samp{signal 0}. @xref{Signaling}. You can
1908also act in advance to control what signals your program will see, using
1909the @samp{handle} command (@pxref{Signals}).
e91b87a3 1910
fe3f5fc8
RP
1911@node Stepping, , Continuing, Stopping
1912@section Stepping
e91b87a3 1913
fe3f5fc8
RP
1914@cindex stepping
1915@dfn{Stepping} means setting your program in motion for a limited time, so
1916that control will return automatically to the debugger after one line of
1917code or one machine instruction. Breakpoints are active during stepping
1918and the program will stop for them even if it has not gone as far as the
1919stepping command specifies.
e91b87a3 1920
9c91ee3e 1921@table @code
fe3f5fc8
RP
1922@item step
1923@kindex step
1924Continue running the program until control reaches a different line,
1925then stop it and return control to the debugger. This command is
1926abbreviated @samp{s}.
9c91ee3e 1927
fe3f5fc8
RP
1928This command may be given when control is within a function for which
1929there is no debugging information. In that case, execution will proceed
1930until control reaches a different function, or is about to return from
1931this function. An argument repeats this action.
e91b87a3 1932
fe3f5fc8
RP
1933@item step @var{count}
1934Continue running as in @samp{step}, but do so @var{count} times. If a
1935breakpoint is reached or a signal not related to stepping occurs before
1936@var{count} steps, stepping stops right away.
e91b87a3 1937
fe3f5fc8
RP
1938@item next
1939@kindex next
1940Similar to @samp{step}, but any function calls appearing within the line of
1941code are executed without stopping. Execution stops when control reaches a
1942different line of code at the stack level which was executing when the
1943@samp{next} command was given. This command is abbreviated @samp{n}.
e91b87a3 1944
fe3f5fc8 1945An argument is a repeat count, as in @samp{step}.
e91b87a3 1946
fe3f5fc8
RP
1947@samp{next} within a function without debugging information acts as does
1948@samp{step}, but any function calls appearing within the code of the
1949function are executed without stopping.
1950
1951@item finish
1952@kindex finish
1953Continue running until just after the selected stack frame returns (or
1954until there is some other reason to stop, such as a fatal signal or a
1955breakpoint). Print value returned by the selected stack frame (if any).
1956
1957Contrast this with the @samp{return} command (@pxref{Returning}).
e91b87a3 1958
fe3f5fc8
RP
1959@item until
1960@kindex until
1961This command is used to avoid single stepping through a loop more than
1962once. It is like the @samp{next} command, except that when @samp{until}
1963encounters a jump, it automatically continues execution until the
1964program counter is greater than the address of the jump.
4187119d 1965
fe3f5fc8
RP
1966This means that when you reach the end of a loop after single stepping
1967though it, @samp{until} will cause the program to continue execution
1968until the loop is exited. In contrast, a @samp{next} command at the end
1969of a loop will simply step back to the beginning of the loop, which
1970would force you to step through the next iteration.
4187119d 1971
fe3f5fc8
RP
1972@samp{until} always stops the program if it attempts to exit the current
1973stack frame.
4187119d 1974
fe3f5fc8
RP
1975@samp{until} may produce somewhat counterintuitive results if the order
1976of the source lines does not match the actual order of execution. For
1977example, in a typical C @code{for}-loop, the third expression in the
1978@code{for}-statement (the loop-step expression) is executed after the
1979statements in the body of the loop, but is written before them.
1980Therefore, the @samp{until} command would appear to step back to the
1981beginning of the loop when it advances to this expression. However, it
1982has not really done so, not in terms of the actual machine code.
4187119d 1983
fe3f5fc8
RP
1984Note that @samp{until} with no argument works by means of single
1985instruction stepping, and hence is slower than @samp{until} with an
1986argument.
4187119d 1987
fe3f5fc8
RP
1988@item until @var{location}
1989Continue running the program until either the specified location is
1990reached, or the current (innermost) stack frame returns. @var{location}
1991is any of the forms of argument acceptable to @samp{break} (@pxref{Set
1992Breaks}). This form of the command uses breakpoints, and hence is
1993quicker than @samp{until} without an argument.
e91b87a3 1994
fe3f5fc8
RP
1995@item stepi
1996@itemx si
1997@kindex stepi
1998@kindex si
1999Execute one machine instruction, then stop and return to the debugger.
e91b87a3 2000
fe3f5fc8
RP
2001It is often useful to do @samp{display/i $pc} when stepping by machine
2002instructions. This will cause the next instruction to be executed to
2003be displayed automatically at each stop. @xref{Auto Display}.
e91b87a3 2004
fe3f5fc8 2005An argument is a repeat count, as in @samp{step}.
e91b87a3 2006
fe3f5fc8
RP
2007@item nexti
2008@itemx ni
2009@kindex nexti
2010@kindex ni
2011Execute one machine instruction, but if it is a subroutine call,
2012proceed until the subroutine returns.
e91b87a3 2013
fe3f5fc8
RP
2014An argument is a repeat count, as in @samp{next}.
2015@end table
e91b87a3 2016
fe3f5fc8
RP
2017A typical technique for using stepping is to put a breakpoint
2018(@pxref{Breakpoints}) at the beginning of the function or the section of
2019the program in which a problem is believed to lie, and then step through
2020the suspect area, examining the variables that are interesting, until the
2021problem happens.
e91b87a3 2022
fe3f5fc8
RP
2023The @samp{cont} command can be used after stepping to resume execution
2024until the next breakpoint or signal.
e91b87a3 2025
fe3f5fc8
RP
2026@node Stack, Source, Stopping, Top
2027@chapter Examining the Stack
e91b87a3 2028
fe3f5fc8
RP
2029When your program has stopped, the first thing you need to know is where it
2030stopped and how it got there.
e91b87a3 2031
fe3f5fc8
RP
2032@cindex call stack
2033Each time your program performs a function call, the information about
2034where in the program the call was made from is saved in a block of data
2035called a @dfn{stack frame}. The frame also contains the arguments of the
2036call and the local variables of the function that was called. All the
2037stack frames are allocated in a region of memory called the @dfn{call
2038stack}.
e91b87a3 2039
fe3f5fc8
RP
2040When your program stops, the _GDBN__ commands for examining the stack allow you
2041to see all of this information.
9da601bf 2042
fe3f5fc8
RP
2043One of the stack frames is @dfn{selected} by _GDBN__ and many _GDBN__ commands
2044refer implicitly to the selected frame. In particular, whenever you ask
2045_GDBN__ for the value of a variable in the program, the value is found in the
2046selected frame. There are special _GDBN__ commands to select whichever frame
2047you are interested in.
e91b87a3 2048
fe3f5fc8
RP
2049When the program stops, _GDBN__ automatically selects the currently executing
2050frame and describes it briefly as the @samp{frame} command does
2051(@pxref{Frame Info, Info}).
e91b87a3 2052
fe3f5fc8
RP
2053@menu
2054* Frames:: Explanation of stack frames and terminology.
2055* Backtrace:: Summarizing many frames at once.
2056* Selection:: How to select a stack frame.
2057* Frame Info:: Information on a Frame
2058@end menu
e91b87a3 2059
fe3f5fc8
RP
2060@node Frames, Backtrace, Stack, Stack
2061@section Stack Frames
e91b87a3 2062
fe3f5fc8
RP
2063@cindex frame
2064@cindex stack frame
2065The call stack is divided up into contiguous pieces called @dfn{stack
2066frames}, or @dfn{frames} for short; each frame is the data associated
2067with one call to one function. The frame contains the arguments given
2068to the function, the function's local variables, and the address at
2069which the function is executing.
e91b87a3 2070
fe3f5fc8
RP
2071@cindex initial frame
2072@cindex outermost frame
2073@cindex innermost frame
2074When your program is started, the stack has only one frame, that of the
2075function @code{main}. This is called the @dfn{initial} frame or the
2076@dfn{outermost} frame. Each time a function is called, a new frame is
2077made. Each time a function returns, the frame for that function invocation
2078is eliminated. If a function is recursive, there can be many frames for
2079the same function. The frame for the function in which execution is
2080actually occurring is called the @dfn{innermost} frame. This is the most
2081recently created of all the stack frames that still exist.
e91b87a3 2082
fe3f5fc8
RP
2083@cindex frame pointer
2084Inside your program, stack frames are identified by their addresses. A
2085stack frame consists of many bytes, each of which has its own address; each
2086kind of computer has a convention for choosing one of those bytes whose
2087address serves as the address of the frame. Usually this address is kept
2088in a register called the @dfn{frame pointer register} while execution is
2089going on in that frame.
e91b87a3 2090
fe3f5fc8
RP
2091@cindex frame number
2092_GDBN__ assigns numbers to all existing stack frames, starting with zero for
2093the innermost frame, one for the frame that called it, and so on upward.
2094These numbers do not really exist in your program; they are to give you a
2095way of talking about stack frames in _GDBN__ commands.
e91b87a3 2096
fe3f5fc8
RP
2097@cindex selected frame
2098Many _GDBN__ commands refer implicitly to one stack frame, called the
2099@dfn{selected} stack frame. You can select any frame using one set of
2100_GDBN__ commands, and then other commands will operate on that frame. When
2101your program stops, _GDBN__ automatically selects the innermost frame.
e91b87a3 2102
fe3f5fc8
RP
2103@cindex frameless execution
2104Some compilers allow functions to be compiled to run without a frame
2105reserved for them on the stack. (For example, the _GCC__ option
2106@samp{-fomit-frame-pointer} will generate functions without a frame.)
2107This is occasionally done with heavily used library functions to save
2108the frame setup time. _GDBN__ has limited facilities for dealing with these
2109function invocations; if the innermost function invocation has no stack
2110frame, _GDBN__ will give it a virtual stack frame of 0 and correctly allow
2111tracing of the function call chain. Results are undefined if a function
2112invocation besides the innermost one is frameless.
e91b87a3 2113
fe3f5fc8
RP
2114@node Backtrace, Selection, Frames, Stack
2115@section Backtraces
e91b87a3 2116
fe3f5fc8
RP
2117A backtrace is a summary of how the program got where it is. It shows one
2118line per frame, for many frames, starting with the currently executing
2119frame (frame zero), followed by its caller (frame one), and on up the
2120stack.
9c91ee3e 2121
fe3f5fc8
RP
2122@table @code
2123@item backtrace
2124@itemx bt
2125@kindex backtrace
2126@kindex bt
2127Print a backtrace of the entire stack: one line per frame for all
2128frames in the stack.
9c91ee3e 2129
fe3f5fc8
RP
2130You can stop the backtrace at any time by typing the system interrupt
2131character, normally @kbd{Control-C}.
2132
2133@item backtrace @var{n}
2134@itemx bt @var{n}
2135Similar, but print only the innermost @var{n} frames.
9c91ee3e 2136
fe3f5fc8
RP
2137@item backtrace @var{-n}
2138@itemx bt @var{-n}
2139Similar, but print only the outermost @var{n} frames.
6ad6aa52 2140@end table
96a816c5 2141
fe3f5fc8
RP
2142@kindex where
2143@kindex info stack
2144The names @samp{where} and @samp{info stack} are additional aliases
2145for @samp{backtrace}.
e91b87a3 2146
fe3f5fc8
RP
2147Every line in the backtrace shows the frame number and the function
2148name. The program counter value is also shown---unless you use
2149@samp{set addressprint off}.
e91b87a3 2150
fe3f5fc8
RP
2151If the function is in a source file whose symbol table data has been
2152fully read, the backtrace shows the source file name and line number, as
2153well as the arguments to the function. When the line number is shown,
2154the program counter value is omitted if it is at the beginning of the
2155code for that line number.
96a816c5 2156
fe3f5fc8
RP
2157Here is an example of a backtrace. It was made with the command
2158@samp{bt 3}, so it shows the innermost three frames.
e91b87a3 2159
fe3f5fc8
RP
2160@example
2161#0 rtx_equal_p (x=(rtx) 0x8e58c, y=(rtx) 0x1086c4) \
2162(/gp/rms/cc/rtlanal.c line 337)
2163#1 0x246b0 in expand_call (...) (...)
2164#2 0x21cfc in expand_expr (...) (...)
2165(More stack frames follow...)
2166@end example
e91b87a3 2167
fe3f5fc8
RP
2168@noindent
2169The functions @code{expand_call} and @code{expand_expr} are in a file
2170whose symbol details have not been fully read. Full detail is available
2171for the function @code{rtx_equal_p}, which is in the file
2172@file{rtlanal.c}. Its arguments, named @code{x} and @code{y}, are shown
2173with their typed values.
4187119d 2174
fe3f5fc8
RP
2175@node Selection, Frame Info, Backtrace, Stack
2176@section Selecting a Frame
e91b87a3 2177
fe3f5fc8
RP
2178Most commands for examining the stack and other data in the program work on
2179whichever stack frame is selected at the moment. Here are the commands for
2180selecting a stack frame; all of them finish by printing a brief description
2181of the stack frame just selected.
e91b87a3 2182
fe3f5fc8
RP
2183@table @code
2184@item frame @var{n}
2185@kindex frame
2186Select frame number @var{n}. Recall that frame zero is the innermost
2187(currently executing) frame, frame one is the frame that called the
2188innermost one, and so on. The highest-numbered frame is @code{main}'s
2189frame.
e91b87a3 2190
fe3f5fc8
RP
2191@item frame @var{addr}
2192Select the frame at address @var{addr}. This is useful mainly if the
2193chaining of stack frames has been damaged by a bug, making it
2194impossible for _GDBN__ to assign numbers properly to all frames. In
2195addition, this can be useful when the program has multiple stacks and
2196switches between them.
e91b87a3 2197
fe3f5fc8
RP
2198@item up @var{n}
2199@kindex up
2200Select the frame @var{n} frames up from the frame previously selected.
2201For positive numbers @var{n}, this advances toward the outermost
2202frame, to higher frame numbers, to frames that have existed longer.
2203@var{n} defaults to one.
4187119d 2204
fe3f5fc8
RP
2205@item down @var{n}
2206@kindex down
2207Select the frame @var{n} frames down from the frame previously
2208selected. For positive numbers @var{n}, this advances toward the
2209innermost frame, to lower frame numbers, to frames that were created
2210more recently. @var{n} defaults to one.
2211@end table
e91b87a3 2212
fe3f5fc8
RP
2213All of these commands end by printing some information on the frame that
2214has been selected: the frame number, the function name, the arguments, the
2215source file and line number of execution in that frame, and the text of
2216that source line. For example:
e91b87a3 2217
fe3f5fc8
RP
2218@example
2219#3 main (argc=3, argv=??, env=??) at main.c:67
222067 read_input_file (argv[i]);
2221@end example
96a816c5 2222
fe3f5fc8
RP
2223After such a printout, the @samp{list} command with no arguments will print
2224ten lines centered on the point of execution in the frame. @xref{List}.
6ad6aa52 2225
fe3f5fc8
RP
2226@table @code
2227@item up-silently @var{n}
2228@itemx down-silently @var{n}
2229@kindex down-silently
2230@kindex up-silently
2231These two commands are variants of @samp{up} and @samp{down},
2232respectively; they differ in that they do their work silently, without
2233causing display of the new frame. They are intended primarily for use
2234in _GDBN__ command scripts, where the output might be unnecessary and
2235distracting.
e91b87a3 2236
fe3f5fc8 2237@end table
e91b87a3 2238
fe3f5fc8
RP
2239@node Frame Info, , Selection, Stack
2240@section Information on a Frame
d2e08421 2241
fe3f5fc8
RP
2242There are several other commands to print information about the selected
2243stack frame.
d2e08421 2244
fe3f5fc8
RP
2245@table @code
2246@item frame
2247When used without any argument, this command does not change which frame
2248is selected, but still prints a brief description of the currently
2249selected stack frame. It can be abbreviated @samp{f}. With an
2250argument, this command is used to select a stack frame; with no
2251argument, it does not change which frame is selected, but still prints
2252the same kind of information.
d2e08421 2253
fe3f5fc8
RP
2254@item info frame
2255@kindex info frame
2256This command prints a verbose description of the selected stack frame,
2257including the address of the frame, the addresses of the next frame in
2258(called by this frame) and the next frame out (caller of this frame),
2259the address of the frame's arguments, the program counter saved in it
2260(the address of execution in the caller frame), and which registers
2261were saved in the frame. The verbose description is useful when
2262something has gone wrong that has made the stack format fail to fit
2263the usual conventions.
d2e08421 2264
fe3f5fc8
RP
2265@item info frame @var{addr}
2266Print a verbose description of the frame at address @var{addr},
2267without selecting that frame. The selected frame remains unchanged by
2268this command.
d2e08421 2269
fe3f5fc8
RP
2270@item info args
2271@kindex info args
2272Print the arguments of the selected frame, each on a separate line.
d2e08421 2273
fe3f5fc8
RP
2274@item info locals
2275@kindex info locals
2276Print the local variables of the selected frame, each on a separate
2277line. These are all variables declared static or automatic within all
2278program blocks that execution in this frame is currently inside of.
d2e08421 2279
fe3f5fc8
RP
2280@item info catch
2281@kindex info catch
2282@cindex catch exceptions
2283@cindex exception handlers
2284Print a list of all the exception handlers that are active in the
2285current stack frame given the current value of @code{pc}. To see other
2286exception handlers, visit the associated frame (using the @samp{up},
2287@samp{down}, or @samp{frame} commands); then type @samp{info catch}.
2288@xref{Exception Handling}.
d2e08421
RP
2289@end table
2290
fe3f5fc8
RP
2291@node Source, Data, Stack, Top
2292@chapter Examining Source Files
d2e08421 2293
fe3f5fc8
RP
2294_GDBN__ knows which source files your program was compiled from, and
2295can print parts of their text. When your program stops, _GDBN__
2296spontaneously prints the line it stopped in. Likewise, when you
2297select a stack frame (@pxref{Selection}), _GDBN__ prints the line
2298which execution in that frame has stopped in. You can also
2299print parts of source files by explicit command.
d2e08421 2300
fe3f5fc8
RP
2301@menu
2302* List:: Using the @samp{list} command to print source files.
2303* Search:: Commands for searching source files.
2304* Source Path:: Specifying the directories to search for source files.
2305@end menu
e91b87a3 2306
fe3f5fc8
RP
2307@node List, Search, Source, Source
2308@section Printing Source Lines
e91b87a3 2309
fe3f5fc8
RP
2310@kindex list
2311@kindex l
2312To print lines from a source file, use the @samp{list} command
2313(abbreviated @samp{l}). There are several ways to specify what part
2314of the file you want to print.
e91b87a3 2315
fe3f5fc8 2316Here are the forms of the @samp{list} command most commonly used:
e91b87a3 2317
2318@table @code
fe3f5fc8
RP
2319@item list @var{linenum}
2320Print ten lines centered around line number @var{linenum} in the
2321current source file.
e91b87a3 2322
fe3f5fc8
RP
2323@item list @var{function}
2324Print ten lines centered around the beginning of function
2325@var{function}.
e91b87a3 2326
fe3f5fc8
RP
2327@item list
2328Print ten more lines. If the last lines printed were printed with a
2329@samp{list} command, this prints ten lines following the last lines
2330printed; however, if the last line printed was a solitary line printed
2331as part of displaying a stack frame (@pxref{Stack}), this prints ten
2332lines centered around that line.
e91b87a3 2333
fe3f5fc8
RP
2334@item list -
2335Print ten lines just before the lines last printed.
e91b87a3 2336@end table
2337
fe3f5fc8
RP
2338Repeating a @samp{list} command with @key{RET} discards the argument,
2339so it is equivalent to typing just @samp{list}. This is more useful
2340than listing the same lines again. An exception is made for an
2341argument of @samp{-}; that argument is preserved in repetition so that
2342each repetition moves up in the file.
e91b87a3 2343
fe3f5fc8
RP
2344@cindex linespec
2345In general, the @samp{list} command expects you to supply zero, one or two
2346@dfn{linespecs}. Linespecs specify source lines; there are several ways
2347of writing them but the effect is always to specify some source line.
2348Here is a complete description of the possible arguments for @samp{list}:
e91b87a3 2349
fe3f5fc8
RP
2350@table @code
2351@item list @var{linespec}
2352Print ten lines centered around the line specified by @var{linespec}.
e91b87a3 2353
fe3f5fc8
RP
2354@item list @var{first},@var{last}
2355Print lines from @var{first} to @var{last}. Both arguments are
2356linespecs.
e91b87a3 2357
fe3f5fc8
RP
2358@item list ,@var{last}
2359Print ten lines ending with @var{last}.
e91b87a3 2360
fe3f5fc8
RP
2361@item list @var{first},
2362Print ten lines starting with @var{first}.
e91b87a3 2363
fe3f5fc8
RP
2364@item list +
2365Print ten lines just after the lines last printed.
e91b87a3 2366
fe3f5fc8
RP
2367@item list -
2368Print ten lines just before the lines last printed.
e91b87a3 2369
fe3f5fc8
RP
2370@item list
2371As described in the preceding table.
e91b87a3 2372@end table
2373
fe3f5fc8
RP
2374Here are the ways of specifying a single source line---all the
2375kinds of linespec.
e91b87a3 2376
fe3f5fc8
RP
2377@table @code
2378@item @var{linenum}
2379Specifies line @var{linenum} of the current source file.
2380When a @samp{list} command has two linespecs, this refers to
2381the same source file as the first linespec.
e91b87a3 2382
fe3f5fc8
RP
2383@item +@var{offset}
2384Specifies the line @var{offset} lines after the last line printed.
2385When used as the second linespec in a @samp{list} command that has
2386two, this specifies the line @var{offset} lines down from the
2387first linespec.
e91b87a3 2388
fe3f5fc8
RP
2389@item -@var{offset}
2390Specifies the line @var{offset} lines before the last line printed.
e91b87a3 2391
fe3f5fc8
RP
2392@item @var{filename}:@var{linenum}
2393Specifies line @var{linenum} in the source file @var{filename}.
e91b87a3 2394
fe3f5fc8
RP
2395@item @var{function}
2396Specifies the line of the open-brace that begins the body of the
2397function @var{function}.
e91b87a3 2398
fe3f5fc8
RP
2399@item @var{filename}:@var{function}
2400Specifies the line of the open-brace that begins the body of the
2401function @var{function} in the file @var{filename}. The file name is
2402needed with a function name only for disambiguation of identically
2403named functions in different source files.
e91b87a3 2404
fe3f5fc8
RP
2405@item *@var{address}
2406Specifies the line containing the program address @var{address}.
2407@var{address} may be any expression.
2408@end table
e91b87a3 2409
fe3f5fc8 2410One other command is used to map source lines to program addresses.
e91b87a3 2411
fe3f5fc8
RP
2412@table @code
2413@item info line @var{linenum}
2414@kindex info line
2415Print the starting and ending addresses of the compiled code for
2416source line @var{linenum}.
9d7c0513 2417
fe3f5fc8
RP
2418@kindex $_
2419The default examine address for the @samp{x} command is changed to the
2420starting address of the line, so that @samp{x/i} is sufficient to
2421begin examining the machine code (@pxref{Memory}). Also, this address
2422is saved as the value of the convenience variable @code{$_}
2423(@pxref{Convenience Vars}).
e91b87a3 2424@end table
2425
fe3f5fc8
RP
2426@node Search, Source Path, List, Source
2427@section Searching Source Files
2428@cindex searching
2429@kindex search
2430@kindex forward-search
2431@kindex reverse-search
e91b87a3 2432
fe3f5fc8
RP
2433There are two commands for searching through the current source file for a
2434regular expression.
e91b87a3 2435
fe3f5fc8
RP
2436The command @samp{forward-search @var{regexp}} checks each line, starting
2437with the one following the last line listed, for a match for @var{regexp}.
2438It lists the line that is found. You can abbreviate the command name
2439as @samp{fo}. The synonym @samp{search @var{regexp}} is also supported.
e91b87a3 2440
fe3f5fc8
RP
2441The command @samp{reverse-search @var{regexp}} checks each line, starting
2442with the one before the last line listed and going backward, for a match
2443for @var{regexp}. It lists the line that is found. You can abbreviate
2444this command with as little as @samp{rev}.
e91b87a3 2445
fe3f5fc8
RP
2446@node Source Path, , Search, Source
2447@section Specifying Source Directories
e91b87a3 2448
fe3f5fc8
RP
2449@cindex source path
2450@cindex directories for source files
2451Executable programs sometimes do not record the directories of the source
2452files from which they were compiled, just the names. Even when they do,
2453the directories could be moved between the compilation and your debugging
2454session. _GDBN__ remembers a list of directories to search for source files;
2455this is called the @dfn{source path}. Each time _GDBN__ wants a source file,
2456it tries all the directories in the list, in the order they are present
2457in the list, until it finds a file with the desired name. Note that
2458the executable search path is @emph{not} used for this purpose. Neither is
2459the current working directory, unless it happens to be in the source
2460path.
e91b87a3 2461
fe3f5fc8
RP
2462If it can't find a source file in the source path, and the object program
2463records what directory it was compiled in, _GDBN__ tries that directory too.
2464If the source path is empty, and there is no record of the compilation
2465directory, _GDBN__ will, as a last resort, look in the current directory.
e91b87a3 2466
fe3f5fc8
RP
2467Whenever you reset or rearrange the source path, _GDBN__ will clear out
2468any information it has cached about where source files are found, where
2469each line is in the file, etc.
e91b87a3 2470
fe3f5fc8
RP
2471@kindex directory
2472When you start _GDBN__, its source path is empty.
2473To add other directories, use the @samp{directory} command.
e91b87a3 2474
fe3f5fc8
RP
2475@table @code
2476@item directory @var{dirnames...}
2477Add directory @var{dirname} to the front of the source path. Several
2478directory names may be given to this command, separated by whitespace or
2479@samp{:}. If a name is already in the source path, it is moved to the
2480front of the path, so it will be searched sooner.
e91b87a3 2481
fe3f5fc8
RP
2482@item directory
2483Reset the source path to empty again. This requires confirmation.
e91b87a3 2484
fe3f5fc8
RP
2485@item info directories
2486@kindex info directories
2487Print the source path: show which directories it contains.
2488@end table
e91b87a3 2489
fe3f5fc8
RP
2490Because the @samp{directory} command, when used with arguments, adds to
2491the front of the source path, it can affect files that _GDBN__ has already
2492found. If the source path contains directories that you do not want,
2493and these directories contain misleading files with names matching your
2494source files, the way to correct the situation is as follows:
e91b87a3 2495
fe3f5fc8
RP
2496@enumerate
2497@item
2498Use @samp{directory} with no argument to reset the source path to empty.
e91b87a3 2499
fe3f5fc8
RP
2500@item
2501Use @samp{directory} with suitable arguments to add any other
2502directories you want in the source path. You can add all the directories
2503in one command.
2504@end enumerate
e91b87a3 2505
fe3f5fc8
RP
2506@node Data, Symbols, Source, Top
2507@chapter Examining Data
2508
2509@cindex printing data
2510@cindex examining data
2511@kindex print
2512@kindex inspect
2513The usual way to examine data in your program is with the @samp{print}
2514command (abbreviated @samp{p}), or its synonym @samp{inspect}. It
2515evaluates and prints the value of any valid expression of the language
2516the program is written in (for now, C or C++). You type
e91b87a3 2517
2518@example
fe3f5fc8 2519print @var{exp}
e91b87a3 2520@end example
2521
2522@noindent
fe3f5fc8
RP
2523where @var{exp} is any valid expression (in the source language), and
2524the value of @var{exp} is printed in a format appropriate to its data
2525type.
e91b87a3 2526
fe3f5fc8
RP
2527A more low-level way of examining data is with the @samp{x} command.
2528It examines data in memory at a specified address and prints it in a
2529specified format.
e91b87a3 2530
fe3f5fc8
RP
2531@menu
2532* Expressions:: Expressions that can be computed and printed.
2533* Variables:: Using your program's variables in expressions.
2534* Arrays:: Examining part of memory as an array.
2535* Format options:: Controlling how structures and arrays are printed.
2536* Output formats:: Specifying formats for printing values.
2537* Auto Display:: Printing certain expressions whenever program stops.
2538* Value History:: Referring to values previously printed.
2539* Convenience Vars:: Giving names to values for future reference.
2540* Registers:: Referring to and storing in machine registers.
2541@end menu
e91b87a3 2542
fe3f5fc8
RP
2543@node Expressions, Variables, Data, Data
2544@section Expressions
e91b87a3 2545
fe3f5fc8
RP
2546@cindex expressions
2547Many different _GDBN__ commands accept an expression and compute its value.
2548Any kind of constant, variable or operator defined by the programming
2549language you are using is legal in an expression in _GDBN__. This includes
2550conditional expressions, function calls, casts and string constants. It
2551unfortunately does not include symbols defined by preprocessor
2552@code{#define} commands, or C++ expressions involving @samp{::}, the
2553name resolution operator.
e91b87a3 2554
fe3f5fc8
RP
2555Casts are supported in all languages, not just in C, because it is so
2556useful to cast a number into a pointer so as to examine a structure
2557at that address in memory.
e91b87a3 2558
fe3f5fc8
RP
2559_GDBN__ supports three kinds of operator in addition to those of programming
2560languages:
e91b87a3 2561
2562@table @code
fe3f5fc8
RP
2563@item @@
2564@samp{@@} is a binary operator for treating parts of memory as arrays.
2565@xref{Arrays}, for more information.
e91b87a3 2566
fe3f5fc8
RP
2567@item ::
2568@samp{::} allows you to specify a variable in terms of the file or
2569function it is defined in. @xref{Variables}.
e91b87a3 2570
fe3f5fc8
RP
2571@item @{@var{type}@} @var{addr}
2572Refers to an object of type @var{type} stored at address @var{addr} in
2573memory. @var{addr} may be any expression whose value is an integer or
2574pointer (but parentheses are required around nonunary operators, just as in
2575a cast). This construct is allowed regardless of what kind of data is
2576officially supposed to reside at @var{addr}.@refill
2577@end table
e91b87a3 2578
fe3f5fc8
RP
2579@node Variables, Arrays, Expressions, Data
2580@section Program Variables
e91b87a3 2581
fe3f5fc8
RP
2582The most common kind of expression to use is the name of a variable
2583in your program.
e91b87a3 2584
fe3f5fc8
RP
2585Variables in expressions are understood in the selected stack frame
2586(@pxref{Selection}); they must either be global (or static) or be visible
2587according to the scope rules of the programming language from the point of
2588execution in that frame. This means that in the function
e91b87a3 2589
fe3f5fc8
RP
2590@example
2591foo (a)
2592 int a;
2593@{
2594 bar (a);
2595 @{
2596 int b = test ();
2597 bar (b);
2598 @}
2599@}
2600@end example
e91b87a3 2601
fe3f5fc8
RP
2602@noindent
2603the variable @code{a} is usable whenever the program is executing
2604within the function @code{foo}, but the variable @code{b} is visible
2605only while the program is executing inside the block in which @code{b}
2606is declared.
4187119d 2607
fe3f5fc8
RP
2608As a special exception, you can refer to a variable or function whose
2609scope is a single source file even if the current execution point is not
2610in this file. But it is possible to have more than one such variable
2611or function with the same name (if they are in different source files).
2612In such a case, it is not defined which one you will get. If you wish,
2613you can specify any one of them using the colon-colon construct:
e91b87a3 2614
fe3f5fc8
RP
2615@cindex colon-colon
2616@cindex scope
2617@kindex ::
2618@example
2619@var{block}::@var{variable}
2620@end example
e91b87a3 2621
fe3f5fc8
RP
2622@noindent
2623Here @var{block} is the name of the source file whose variable you want.
e91b87a3 2624
fe3f5fc8
RP
2625@cindex name resolution (C++)
2626Unfortunately, this use of @samp{::} conflicts with the very similar use
2627of the same notation in C++; accordingly, _GDBN__ does not support use of
2628the C++ name resolution operator in _GDBN__ expressions.
e91b87a3 2629
fe3f5fc8
RP
2630@node Arrays, Format options, Variables, Data
2631@section Artificial Arrays
e91b87a3 2632
fe3f5fc8
RP
2633@cindex artificial array
2634@kindex @@
2635It is often useful to print out several successive objects of the
2636same type in memory; a section of an array, or an array of
2637dynamically determined size for which only a pointer exists in the
2638program.
e91b87a3 2639
fe3f5fc8
RP
2640This can be done by constructing an @dfn{artificial array} with the
2641binary operator @samp{@@}. The left operand of @samp{@@} should be
2642the first element of the desired array, as an individual object.
2643The right operand should be the length of the array. The result is
2644an array value whose elements are all of the type of the left argument.
2645The first element is actually the left argument; the second element
2646comes from bytes of memory immediately following those that hold the
2647first element, and so on. Here is an example. If a program says
4187119d 2648
fe3f5fc8
RP
2649@example
2650int *array = (int *) malloc (len * sizeof (int));
2651@end example
4187119d 2652
fe3f5fc8
RP
2653@noindent
2654you can print the contents of @code{array} with
4187119d 2655
fe3f5fc8
RP
2656@example
2657p *array@@len
2658@end example
4187119d 2659
fe3f5fc8
RP
2660The left operand of @samp{@@} must reside in memory. Array values made
2661with @samp{@@} in this way behave just like other arrays in terms of
2662subscripting, and are coerced to pointers when used in expressions.
2663(It would probably appear in an expression via the value history,
2664after you had printed it out.)
e91b87a3 2665
fe3f5fc8
RP
2666@node Format options, Output formats, Arrays, Data
2667@section Format options
e91b87a3 2668
fe3f5fc8
RP
2669@cindex format options
2670_GDBN__ provides a few ways to control how arrays, structures, and symbols are
2671printed.
e91b87a3 2672
fe3f5fc8
RP
2673@table @code
2674@item set array-max @var{number-of-elements}
2675@kindex set array-max
2676If _GDBN__ is printing a large array, it will stop printing after it has
2677printed the number of elements set by the @samp{set array-max} command.
2678This limit also applies to the display of strings.
e91b87a3 2679
fe3f5fc8
RP
2680@item show array-max
2681@kindex show array-max
2682Display the number of elements of a large array that _GDBN__ will print
2683before losing patience.
e91b87a3 2684
fe3f5fc8
RP
2685@item set arrayprint
2686@itemx set arrayprint on
2687@kindex set arrayprint
2688_GDBN__ will pretty print arrays. This format is more convenient to read,
2689but uses more space. The default is off.
e91b87a3 2690
fe3f5fc8
RP
2691@item set arrayprint off.
2692Return to compressed format for arrays.
e91b87a3 2693
fe3f5fc8
RP
2694@item show arrayprint
2695@kindex show arrayprint
2696Show whether compressed or pretty format is selected for displaying
2697arrays.
e91b87a3 2698
fe3f5fc8
RP
2699@item set demangle
2700@itemx set demangle on
2701@kindex set demangle
2702Print C++ names in their source form rather than in the mangled form
2703in which they are passed to the assembler and linker for type-safe linkage.
2704The default is on.
e91b87a3 2705
fe3f5fc8
RP
2706@item show demangle
2707@kindex show demangle
2708Show whether C++ names will be printed in mangled or demangled form.
e91b87a3 2709
fe3f5fc8
RP
2710@item set asm-demangle
2711@itemx set asm-demangle on
2712@kindex set asm-demangle
2713Print C++ names in their source form rather than their mangled form, even
2714in assembler code printouts such as instruction disassemblies.
2715The default is off.
2716
2717@item show asm-demangle
2718@kindex show asm-demangle
2719Show whether C++ names in assembly listings will be printed in mangled
2720or demangled form.
e91b87a3 2721
fe3f5fc8
RP
2722@item set vtblprint
2723@itemx set vtblprint on
2724@kindex set vtblprint
2725Pretty print C++ virtual function tables. The default is off.
e91b87a3 2726
fe3f5fc8
RP
2727@item set vtblprint off
2728Do not pretty print C++ virtual function tables.
e91b87a3 2729
fe3f5fc8
RP
2730@item show vtblprint
2731@kindex show vtblprint
2732Show whether C++ virtual function tables are pretty printed, or not.
e91b87a3 2733
fe3f5fc8
RP
2734@item set addressprint
2735@item set addressprint on
2736@kindex set addressprint
2737_GDBN__ will print memory addresses in stack traces, structure values, pointer
2738values, breakpoints, etc. The default is on.
e91b87a3 2739
fe3f5fc8
RP
2740@item set addressprint off
2741Do not print addresses.
e91b87a3 2742
fe3f5fc8
RP
2743@item show addressprint
2744@kindex show addressprint
2745Show whether or not addresses are to be printed.
e91b87a3 2746
fe3f5fc8
RP
2747@item set prettyprint on
2748@kindex set prettyprint
2749Cause _GDBN__ to print structures in an indented format with one member per
2750line, like this:
e91b87a3 2751
fe3f5fc8
RP
2752@example
2753$1 = @{
2754 next = 0x0,
2755 flags = @{
2756 sweet = 1,
2757 sour = 1
2758 @},
2759 meat = 0x54 "Pork"
2760@}
2761@end example
e91b87a3 2762
fe3f5fc8
RP
2763@item set prettyprint off
2764Cause _GDBN__ to print structures in a compact format, like this:
e91b87a3 2765
fe3f5fc8
RP
2766@smallexample
2767$1 = @{next = 0x0, flags = @{sweet = 1, sour = 1@}, meat \
2768= 0x54 "Pork"@}
2769@end smallexample
e91b87a3 2770
fe3f5fc8
RP
2771@noindent
2772This is the default format.
e91b87a3 2773
fe3f5fc8
RP
2774@item show prettyprint
2775@kindex show prettyprint
2776Show which format _GDBN__ will use to print structures.
4187119d 2777
fe3f5fc8
RP
2778@item set unionprint on
2779@kindex set unionprint
2780Tell _GDBN__ to print unions which are contained in structures. This is the
2781default setting.
e91b87a3 2782
fe3f5fc8
RP
2783@item set unionprint off
2784Tell _GDBN__ not to print unions which are contained in structures.
e91b87a3 2785
fe3f5fc8
RP
2786@item show unionprint
2787@kindex show unionprint
2788Ask _GDBN__ whether or not it will print unions which are contained in
2789structures.
e91b87a3 2790
fe3f5fc8 2791For example, given the declarations
e91b87a3 2792
fe3f5fc8
RP
2793@smallexample
2794typedef enum @{Tree, Bug@} Species;
2795typedef enum @{Big_tree, Acorn, Seedling@} Tree_forms;
2796typedef enum @{Caterpillar, Cocoon, Butterfly@} Bug_forms;
e91b87a3 2797
fe3f5fc8
RP
2798struct thing @{
2799 Species it;
2800 union @{
2801 Tree_forms tree;
2802 Bug_forms bug;
2803 @} form;
2804@};
e91b87a3 2805
fe3f5fc8
RP
2806struct thing foo = @{Tree, @{Acorn@}@};
2807@end smallexample
4187119d 2808
fe3f5fc8
RP
2809@noindent
2810with @samp{set unionprint on} in effect @samp{p foo} would print
4187119d 2811
fe3f5fc8
RP
2812@smallexample
2813$1 = @{it = Tree, form = @{tree = Acorn, bug = Cocoon@}@}
2814@end smallexample
4187119d 2815
fe3f5fc8
RP
2816@noindent
2817and with @samp{set unionprint off} in effect it would print
4187119d 2818
2819@example
fe3f5fc8 2820$1 = @{it = Tree, form = @{...@}@}
4187119d 2821@end example
fe3f5fc8 2822@end table
4187119d 2823
fe3f5fc8
RP
2824@node Output formats, Auto Display, Format options, Data
2825@section Output formats
e91b87a3 2826
fe3f5fc8
RP
2827@cindex formatted output
2828@cindex output formats
2829_GDBN__ normally prints all values according to their data types. Sometimes
2830this is not what you want. For example, you might want to print a number
2831in hex, or a pointer in decimal. Or you might want to view data in memory
2832at a certain address as a character string or an instruction. These things
2833can be done with @dfn{output formats}.
e91b87a3 2834
fe3f5fc8
RP
2835The simplest use of output formats is to say how to print a value
2836already computed. This is done by starting the arguments of the
2837@samp{print} command with a slash and a format letter. The format
2838letters supported are:
e91b87a3 2839
fe3f5fc8
RP
2840@table @samp
2841@item x
2842Regard the bits of the value as an integer, and print the integer in
2843hexadecimal.
e91b87a3 2844
fe3f5fc8
RP
2845@item d
2846Print as integer in signed decimal.
e91b87a3 2847
fe3f5fc8
RP
2848@item u
2849Print as integer in unsigned decimal.
e91b87a3 2850
fe3f5fc8
RP
2851@item o
2852Print as integer in octal.
e91b87a3 2853
fe3f5fc8
RP
2854@item a
2855Print as an address, both absolute in hex and as an offset from the
2856nearest preceding symbol. This format can be used to discover where (in
2857what function) an unknown address is located:
e91b87a3 2858@example
fe3f5fc8
RP
2859(_GDBP__) p/a 0x54320
2860_0__$3 = 0x54320 <_initialize_vx+396>_1__
e91b87a3 2861@end example
2862
e91b87a3 2863
fe3f5fc8
RP
2864@item c
2865Regard as an integer and print it as a character constant.
23e2e5e1 2866
fe3f5fc8
RP
2867@item f
2868Regard the bits of the value as a floating point number and print
2869using typical floating point syntax.
369a6ade
RP
2870@end table
2871
fe3f5fc8 2872For example, to print the program counter in hex (@pxref{Registers}), type
e91b87a3 2873
fe3f5fc8
RP
2874@example
2875p/x $pc
2876@end example
e91b87a3 2877
fe3f5fc8
RP
2878@noindent
2879Note that no space is required before the slash; this is because command
2880names in _GDBN__ cannot contain a slash.
e91b87a3 2881
fe3f5fc8
RP
2882To reprint the last value in the value history with a different format,
2883you can use the @samp{print} command with just a format and no
2884expression. For example, @samp{p/x} reprints the last value in hex.
e91b87a3 2885
fe3f5fc8
RP
2886@menu
2887* Memory:: Examining Memory
2888@end menu
e91b87a3 2889
fe3f5fc8
RP
2890@node Memory, , Output formats, Output formats
2891@subsection Examining Memory
e91b87a3 2892
fe3f5fc8
RP
2893@cindex examining memory
2894@table @code
2895@kindex disassemble
2896@item disassemble
2897This specialized command is provided to dump a range of memory as
2898machine instructions. The default memory range is the function
2899surrounding the program counter of the selected frame. A single
2900argument to this command is a program counter value; the function
2901surrounding this value will be dumped. Two arguments (separated by one
2902or more spaces) specify a range of addresses (first inclusive, second
2903exclusive) to be dumped.
e91b87a3 2904
fe3f5fc8
RP
2905@kindex x
2906@item x
2907The command @samp{x} (for `examine') can be used to examine memory
2908without reference to the program's data types. The format in which you
2909wish to examine memory is instead explicitly specified. The allowable
2910formats are a superset of the formats described in the previous section.
9da601bf 2911@end table
6ad6aa52 2912
fe3f5fc8
RP
2913@samp{x} is followed by a slash and an output format specification,
2914followed by an expression for an address. The expression need not have
2915a pointer value (though it may); it is used as an integer, as the
2916address of a byte of memory. @xref{Expressions} for more information on
2917expressions. For example, @samp{x/4xw $sp} prints the four words of
2918memory above the stack pointer in hexadecimal.
e91b87a3 2919
fe3f5fc8
RP
2920The output format in this case specifies both how big a unit of memory
2921to examine and how to print the contents of that unit. It is done
2922with one or two of the following letters:
e91b87a3 2923
fe3f5fc8 2924These letters specify just the size of unit to examine:
e91b87a3 2925
fe3f5fc8
RP
2926@table @samp
2927@item b
2928Examine individual bytes.
e91b87a3 2929
fe3f5fc8
RP
2930@item h
2931Examine halfwords (two bytes each).
e91b87a3 2932
fe3f5fc8
RP
2933@item w
2934Examine words (four bytes each).
e91b87a3 2935
fe3f5fc8
RP
2936@cindex word
2937Many assemblers and cpu designers still use `word' for a 16-bit quantity,
2938as a holdover from specific predecessor machines of the 1970's that really
2939did use two-byte words. But more generally the term `word' has always
2940referred to the size of quantity that a machine normally operates on and
2941stores in its registers. This is 32 bits for all the machines that _GDBN__
2942runs on.
e91b87a3 2943
fe3f5fc8
RP
2944@item g
2945Examine giant words (8 bytes).
e91b87a3 2946@end table
2947
fe3f5fc8 2948These letters specify just the way to print the contents:
e91b87a3 2949
fe3f5fc8
RP
2950@table @samp
2951@item x
2952Print as integers in unsigned hexadecimal.
e91b87a3 2953
fe3f5fc8
RP
2954@item d
2955Print as integers in signed decimal.
e91b87a3 2956
fe3f5fc8
RP
2957@item u
2958Print as integers in unsigned decimal.
e91b87a3 2959
fe3f5fc8
RP
2960@item o
2961Print as integers in unsigned octal.
e91b87a3 2962
fe3f5fc8
RP
2963@item a
2964Print as an address, both absolute in hex and then relative
2965to a symbol defined as an address below it.
e91b87a3 2966
fe3f5fc8
RP
2967@item c
2968Print as character constants.
e91b87a3 2969
fe3f5fc8
RP
2970@item f
2971Print as floating point. This works only with sizes @samp{w} and
2972@samp{g}.
e91b87a3 2973
fe3f5fc8
RP
2974@item s
2975Print a null-terminated string of characters. The specified unit size
2976is ignored; instead, the unit is however many bytes it takes to reach
2977a null character (including the null character).
e91b87a3 2978
fe3f5fc8
RP
2979@item i
2980Print a machine instruction in assembler syntax (or nearly). The
2981specified unit size is ignored; the number of bytes in an instruction
2982varies depending on the type of machine, the opcode and the addressing
2983modes used. The command @samp{disassemble} gives an alternative way of
2984inspecting machine instructions.
2985@end table
e91b87a3 2986
fe3f5fc8
RP
2987If either the manner of printing or the size of unit fails to be specified,
2988the default is to use the same one that was used last. If you don't want
2989to use any letters after the slash, you can omit the slash as well.
e91b87a3 2990
fe3f5fc8
RP
2991You can also omit the address to examine. Then the address used is just
2992after the last unit examined. This is why string and instruction
2993formats actually compute a unit-size based on the data: so that the next
2994string or instruction examined will start in the right place.
e91b87a3 2995
fe3f5fc8
RP
2996When the @samp{print} command shows a value that resides in memory,
2997@samp{print} also sets the default address for the @samp{x} command.
2998@samp{info line} also sets the default for @samp{x}, to the address of
2999the start of the machine code for the specified line and @samp{info
3000breakpoints} sets it to the address of the last breakpoint listed.
e91b87a3 3001
fe3f5fc8
RP
3002When you use @key{RET} to repeat an @samp{x} command, the address
3003specified previously (if any) is ignored, so that the repeated command
3004examines the successive locations in memory rather than the same ones.
e91b87a3 3005
fe3f5fc8
RP
3006You can examine several consecutive units of memory with one command by
3007writing a repeat-count after the slash (before the format letters, if any).
3008The repeat count must be a decimal integer. It has the same effect as
3009repeating the @samp{x} command that many times except that the output may
3010be more compact with several units per line. For example,
e91b87a3 3011
fe3f5fc8
RP
3012@example
3013x/10i $pc
3014@end example
e91b87a3 3015
fe3f5fc8
RP
3016@noindent
3017prints ten instructions starting with the one to be executed next in the
3018selected frame. After doing this, you could print another seven following
3019instructions with
e91b87a3 3020
fe3f5fc8
RP
3021@example
3022x/7
3023@end example
e91b87a3 3024
fe3f5fc8
RP
3025@noindent
3026in which the format and address are allowed to default.
e91b87a3 3027
3028@kindex $_
fe3f5fc8
RP
3029@kindex $__
3030The addresses and contents printed by the @samp{x} command are not put in
3031the value history because there is often too much of them and they would
3032get in the way. Instead, _GDBN__ makes these values available for subsequent
3033use in expressions as values of the convenience variables @code{$_} and
3034@code{$__}.
e91b87a3 3035
fe3f5fc8
RP
3036After an @samp{x} command, the last address examined is available for use
3037in expressions in the convenience variable @code{$_}. The contents of that
3038address, as examined, are available in the convenience variable @code{$__}.
e91b87a3 3039
fe3f5fc8
RP
3040If the @samp{x} command has a repeat count, the address and contents saved
3041are from the last memory unit printed; this is not the same as the last
3042address printed if several units were printed on the last line of output.
e91b87a3 3043
fe3f5fc8
RP
3044@node Auto Display, Value History, Output formats, Data
3045@section Automatic Display
3046@cindex automatic display
3047@cindex display of expressions
e91b87a3 3048
fe3f5fc8
RP
3049If you find that you want to print the value of an expression frequently
3050(to see how it changes), you might want to add it to the @dfn{automatic
3051display list} so that _GDBN__ will print its value each time the program stops.
3052Each expression added to the list is given a number to identify it;
3053to remove an expression from the list, you specify that number.
3054The automatic display looks like this:
e91b87a3 3055
fe3f5fc8
RP
3056@example
30572: foo = 38
30583: bar[5] = (struct hack *) 0x3804
3059@end example
e91b87a3 3060
fe3f5fc8
RP
3061@noindent
3062showing item numbers, expressions and their current values.
0bed9994 3063
fe3f5fc8
RP
3064If the expression refers to local variables, then it does not make sense
3065outside the lexical context for which it was set up. Such an expression
3066is disabled when execution enters a context where one of its variables
3067is not defined. For example, if you give the command
3068@samp{display name} while inside a function with an argument
3069@code{name}, then this argument will be displayed while the program
3070continues to stop inside that function. When it stops elsewhere---where
3071there is no variable @samp{name}---display is disabled. The next time
3072your program stops where @samp{name} is meaningful, you can enable the
3073display expression once again.
0bed9994 3074
fe3f5fc8
RP
3075@table @code
3076@item display @var{exp}
3077@kindex display
3078Add the expression @var{exp} to the list of expressions to display
3079each time the program stops. @xref{Expressions}.
e91b87a3 3080
fe3f5fc8
RP
3081@item display/@var{fmt} @var{exp}
3082For @var{fmt} specifying only a display format and not a size or
3083count, add the expression @var{exp} to the auto-display list but
3084arranges to display it each time in the specified format @var{fmt}.
e91b87a3 3085
fe3f5fc8
RP
3086@item display/@var{fmt} @var{addr}
3087For @var{fmt} @samp{i} or @samp{s}, or including a unit-size or a
3088number of units, add the expression @var{addr} as a memory address to
3089be examined each time the program stops. Examining means in effect
3090doing @samp{x/@var{fmt} @var{addr}}. @xref{Memory}.
e91b87a3 3091
fe3f5fc8
RP
3092@item undisplay @var{dnums}@dots{}
3093@itemx delete display @var{dnums}@dots{}
3094@kindex delete display
3095@kindex undisplay
3096Remove item numbers @var{dnums} from the list of expressions to display.
e91b87a3 3097
fe3f5fc8
RP
3098@item disable display @var{dnums}@dots{}
3099@kindex disable display
3100Disable the display of item numbers @var{dnums}. A disabled display
3101item is not printed automatically, but is not forgotten. It may be
3102enabled again later.
3103
3104@item enable display @var{dnums}@dots{}
3105@kindex enable display
3106Enable display of item numbers @var{dnums}. It becomes effective once
3107again in auto display of its expression, until you specify otherwise.
3108
3109@item display
3110Display the current values of the expressions on the list, just as is
3111done when the program stops.
3112
3113@item info display
3114@kindex info display
3115Print the list of expressions previously set up to display
3116automatically, each one with its item number, but without showing the
3117values. This includes disabled expressions, which are marked as such.
3118It also includes expressions which would not be displayed right now
3119because they refer to automatic variables not currently available.
e91b87a3 3120@end table
3121
fe3f5fc8
RP
3122@node Value History, Convenience Vars, Auto Display, Data
3123@section Value History
e91b87a3 3124
fe3f5fc8
RP
3125@cindex value history
3126Values printed by the @samp{print} command are saved in _GDBN__'s @dfn{value
3127history} so that you can refer to them in other expressions. Values are
3128kept until the symbol table is re-read or discarded (for example with
3129the @samp{file} or @samp{symbol-file} commands). When the symbol table
3130changes, the value history is discarded, since the values may contain
3131pointers back to the types defined in the symbol table.
e91b87a3 3132
fe3f5fc8
RP
3133@cindex @code{$}
3134@cindex @code{$$}
3135@cindex history number
3136The values printed are given @dfn{history numbers} for you to refer to them
3137by. These are successive integers starting with 1. @samp{print} shows you
3138the history number assigned to a value by printing @samp{$@var{num} = }
3139before the value; here @var{num} is the history number.
e91b87a3 3140
fe3f5fc8
RP
3141To refer to any previous value, use @samp{$} followed by the value's
3142history number. The output printed by @samp{print} is designed to
3143remind you of this. Just @code{$} refers to the most recent value in
3144the history, and @code{$$} refers to the value before that.
3145@code{$$@var{n}} refers to the @var{n}th value from the end; @code{$$2}
3146is the value just prior to @code{$$}, @code{$$1} is equivalent to
3147@code{$$}, and @code{$$0} is equivalent to @code{$}.
e91b87a3 3148
fe3f5fc8
RP
3149For example, suppose you have just printed a pointer to a structure and
3150want to see the contents of the structure. It suffices to type
e91b87a3 3151
3152@example
fe3f5fc8 3153p *$
e91b87a3 3154@end example
3155
fe3f5fc8
RP
3156If you have a chain of structures where the component @samp{next} points
3157to the next one, you can print the contents of the next one with this:
e91b87a3 3158
fe3f5fc8
RP
3159@example
3160p *$.next
3161@end example
e91b87a3 3162
fe3f5fc8
RP
3163@noindent
3164It might be useful to repeat this command many times by typing @key{RET}.
e91b87a3 3165
fe3f5fc8
RP
3166Note that the history records values, not expressions. If the value of
3167@code{x} is 4 and you type this command:
e91b87a3 3168
fe3f5fc8
RP
3169@example
3170print x
3171set x=5
3172@end example
e91b87a3 3173
fe3f5fc8
RP
3174@noindent
3175then the value recorded in the value history by the @samp{print} command
3176remains 4 even though the value of @code{x} has changed.
e91b87a3 3177
3178@table @code
fe3f5fc8
RP
3179@kindex info values
3180@item info values
3181@itemx info history
3182@kindex info history
3183These two commands are synonymous. Either form will print the last ten
3184values in the value history, with their item numbers. This is like
3185@samp{p@ $$9} repeated ten times, except that @samp{info values} does
3186not change the history.
e91b87a3 3187
fe3f5fc8
RP
3188@item info values @var{n}
3189Print ten history values centered on history item number @var{n}.
e91b87a3 3190
fe3f5fc8
RP
3191@item info values +
3192Print ten history values just after the values last printed.
e91b87a3 3193@end table
3194
fe3f5fc8
RP
3195@node Convenience Vars, Registers, Value History, Data
3196@section Convenience Variables
e91b87a3 3197
fe3f5fc8
RP
3198@cindex convenience variables
3199_GDBN__ provides @dfn{convenience variables} that you can use within _GDBN__ to
3200hold on to a value and refer to it later. These variables exist entirely
3201within _GDBN__; they are not part of your program, and setting a convenience
3202variable has no effect on further execution of your program. That's why
3203you can use them freely.
e91b87a3 3204
fe3f5fc8
RP
3205Convenience variables have names starting with @samp{$}. Any name starting
3206with @samp{$} can be used for a convenience variable, unless it is one of
3207the predefined set of register names (@pxref{Registers}).
3208
3209You can save a value in a convenience variable with an assignment
3210expression, just as you would set a variable in your program. Example:
e91b87a3 3211
3212@example
fe3f5fc8 3213set $foo = *object_ptr
e91b87a3 3214@end example
3215
3216@noindent
fe3f5fc8
RP
3217would save in @code{$foo} the value contained in the object pointed to by
3218@code{object_ptr}.
e91b87a3 3219
fe3f5fc8
RP
3220Using a convenience variable for the first time creates it; but its value
3221is @code{void} until you assign a new value. You can alter the value with
3222another assignment at any time.
e91b87a3 3223
fe3f5fc8
RP
3224Convenience variables have no fixed types. You can assign a convenience
3225variable any type of value, including structures and arrays, even if
3226that variable already has a value of a different type. The convenience
3227variable as an expression has whatever type its current value has.
e91b87a3 3228
fe3f5fc8
RP
3229@table @code
3230@item info convenience
3231@kindex info convenience
3232Print a list of convenience variables used so far, and their values.
3233Abbreviated @samp{i con}.
3234@end table
e91b87a3 3235
fe3f5fc8
RP
3236One of the ways to use a convenience variable is as a counter to be
3237incremented or a pointer to be advanced. For example:
d2e08421 3238
fe3f5fc8
RP
3239_0__@example
3240set $i = 0
3241print bar[$i++]->contents
3242@i{@dots{}repeat that command by typing @key{RET}.}
3243_1__@end example
e91b87a3 3244
fe3f5fc8
RP
3245Some convenience variables are created automatically by _GDBN__ and given
3246values likely to be useful.
e91b87a3 3247
fe3f5fc8
RP
3248@table @code
3249@item $_
3250The variable @code{$_} is automatically set by the @samp{x} command to
3251the last address examined (@pxref{Memory}). Other commands which
3252provide a default address for @samp{x} to examine also set @code{$_}
3253to that address; these commands include @samp{info line} and @samp{info
3254breakpoint}.
e91b87a3 3255
fe3f5fc8
RP
3256@item $__
3257The variable @code{$__} is automatically set by the @samp{x} command
3258to the value found in the last address examined.
3259@end table
e91b87a3 3260
fe3f5fc8
RP
3261@node Registers, , Convenience Vars, Data
3262@section Registers
e91b87a3 3263
fe3f5fc8
RP
3264@cindex registers
3265Machine register contents can be referred to in expressions as variables
3266with names starting with @samp{$}. The names of registers are different
3267for each machine; use @samp{info registers} to see the names used on your
3268machine. The names @code{$pc} and @code{$sp} are used on most machines for
3269the program counter register and the stack pointer. Often @code{$fp} is
3270used for a register that contains a pointer to the current stack frame,
3271and @code{$ps} is used for a register that contains the processor
3272status. These standard register names may be available on your machine
3273even though the @code{info registers} command displays them with a
3274different name. For example, on the SPARC, @code{info registers}
3275displays the processor status register as @code{$psr} but you can also
3276refer to it as @code{$ps}.
e91b87a3 3277
fe3f5fc8
RP
3278_GDBN__ always considers the contents of an ordinary register as an integer
3279when the register is examined in this way. Some machines have special
3280registers which can hold nothing but floating point; these registers are
3281considered floating point. There is no way to refer to the contents of an
3282ordinary register as floating point value (although you can @emph{print}
3283it as a floating point value with @samp{print/f $@var{regname}}).
e91b87a3 3284
fe3f5fc8
RP
3285Some registers have distinct ``raw'' and ``virtual'' data formats. This
3286means that the data format in which the register contents are saved by
3287the operating system is not the same one that your program normally
3288sees. For example, the registers of the 68881 floating point
3289coprocessor are always saved in ``extended'' (raw) format, but all C
3290programs expect to work with ``double'' (virtual) format. In such
3291cases, _GDBN__ normally works with the virtual format only (the format that
3292makes sense for your program), but the @samp{info registers} command
3293prints the data in both formats.
4187119d 3294
fe3f5fc8
RP
3295Register values are relative to the selected stack frame
3296(@pxref{Selection}). This means that you get the value that the register
3297would contain if all stack frames farther in were exited and their saved
3298registers restored. In order to see the real contents of all registers,
3299you must select the innermost frame (with @samp{frame 0}).
3300
3301Some registers are never saved (typically those numbered zero or one)
3302because they are used for returning function values. In some operating
3303systems (those using the ``caller saves'' convention), there are other
3304registers intended for free alteration by a called routine. For these
3305registers, relativization makes no difference.
4187119d 3306
3307@table @code
fe3f5fc8
RP
3308@item info registers
3309@kindex info registers
3310Print the names and relativized values of all registers.
4187119d 3311
fe3f5fc8
RP
3312@item info registers @var{regname}
3313Print the relativized value of register @var{regname}. @var{regname}
3314may be any register name valid on the machine you are using, with
3315or without the initial @samp{$}.
3316@end table
9da601bf 3317
fe3f5fc8 3318@subsection Examples
96a816c5 3319
fe3f5fc8 3320You could print the program counter in hex with
96a816c5 3321
fe3f5fc8
RP
3322@example
3323p/x $pc
3324@end example
9da601bf 3325
fe3f5fc8
RP
3326@noindent
3327or print the instruction to be executed next with
a58d77ad 3328
fe3f5fc8
RP
3329@example
3330x/i $pc
3331@end example
a58d77ad 3332
fe3f5fc8
RP
3333@noindent
3334or add four to the stack pointer with
a58d77ad 3335
fe3f5fc8
RP
3336@example
3337set $sp += 4
3338@end example
3339
3340@noindent
3341The last is a way of removing one word from the stack, on machines where
3342stacks grow downward in memory (most machines, nowadays). This assumes
3343that the innermost stack frame is selected. Setting @code{$sp} is
3344not allowed when other stack frames are selected. (To pop entire frames
3345off the stack, regardless of machine architecture, use @samp{return};
3346@pxref{Returning}.)
a58d77ad 3347
fe3f5fc8
RP
3348@node Symbols, Altering, Data, Top
3349@chapter Examining the Symbol Table
96a816c5 3350
fe3f5fc8
RP
3351The commands described in this section allow you to inquire about the
3352symbols (names of variables, functions and types) defined in your
3353program. This information is found by _GDBN__ in the symbol table loaded by
3354the @samp{symbol-file} command; it is inherent in the text of your
3355program and does not change as the program executes.
96a816c5 3356
fe3f5fc8
RP
3357@table @code
3358@item info address @var{symbol}
3359@kindex info address
3360Describe where the data for @var{symbol} is stored. For a register
3361variable, this says which register it is kept in. For a non-register
3362local variable, this prints the stack-frame offset at which the variable
3363is always stored.
9da601bf 3364
fe3f5fc8
RP
3365Note the contrast with @samp{print &@var{symbol}}, which does not work
3366at all for a register variables, and for a stack local variable prints
3367the exact address of the current instantiation of the variable.
96a816c5 3368
fe3f5fc8
RP
3369@item whatis @var{exp}
3370@kindex whatis
3371Print the data type of expression @var{exp}. @var{exp} is not
3372actually evaluated, and any side-effecting operations (such as
3373assignments or function calls) inside it do not take place.
3374@xref{Expressions}.
96a816c5 3375
fe3f5fc8
RP
3376@item whatis
3377Print the data type of @code{$}, the last value in the value history.
96a816c5 3378
fe3f5fc8
RP
3379@item ptype @var{typename}
3380@kindex ptype
3381Print a description of data type @var{typename}. @var{typename} may be
3382the name of a type, or for C code it may have the form
3383@samp{struct @var{struct-tag}}, @samp{union @var{union-tag}} or
3384@samp{enum @var{enum-tag}}.@refill
4187119d 3385
fe3f5fc8
RP
3386@item ptype @var{exp}
3387Print a description of the type of expression @var{exp}. This is like
3388@samp{whatis} except it prints a detailed description, instead of just
3389the name of the type. For example, if the type of a variable is
3390@samp{struct complex @{double real; double imag;@}}, @samp{whatis} will
3391print @samp{struct complex} and @samp{ptype} will print @samp{struct
3392complex @{double real; double imag;@}}
4187119d 3393
fe3f5fc8
RP
3394@item info sources
3395@kindex info sources
3396Print the names of all source files in the program for which there
3397is debugging information.
4187119d 3398
fe3f5fc8
RP
3399@item info functions
3400@kindex info functions
3401Print the names and data types of all defined functions.
4187119d 3402
fe3f5fc8
RP
3403@item info functions @var{regexp}
3404Print the names and data types of all defined functions
3405whose names contain a match for regular expression @var{regexp}.
3406Thus, @samp{info fun step} finds all functions whose names
3407include @samp{step}; @samp{info fun ^step} finds those whose names
3408start with @samp{step}.
4187119d 3409
fe3f5fc8
RP
3410@item info variables
3411@kindex info variables
3412Print the names and data types of all variables that are declared
3413outside of functions (i.e., except for local variables).
9da601bf 3414
fe3f5fc8
RP
3415@item info variables @var{regexp}
3416Print the names and data types of all variables (except for local
3417variables) whose names contain a match for regular expression
3418@var{regexp}.
9da601bf 3419
4187119d 3420
fe3f5fc8
RP
3421@ignore
3422This was never implemented.
3423@item info methods
3424@itemx info methods @var{regexp}
3425@kindex info methods
3426The @samp{info-methods} command permits the user to examine all defined
3427methods within C++ program, or (with the @var{regexp} argument) a
3428specific set of methods found in the various C++ classes. Many
3429C++ classes provide a large number of methods. Thus, the output
3430from the @samp{ptype} command can be overwhelming and hard to use. The
3431@samp{info-methods} command filters the methods, printing only those
3432which match the regular-expression @var{regexp}.
3433@end ignore
9da601bf 3434
fe3f5fc8
RP
3435@item printsyms @var{filename}
3436@kindex printsyms
3437Write a complete dump of the debugger's symbol data into the
3438file @var{filename}.
3439@end table
4187119d 3440
fe3f5fc8
RP
3441@node Altering, Sequences, Symbols, Top
3442@chapter Altering Execution
4187119d 3443
fe3f5fc8
RP
3444Once you think you have found an error in the program, you might want to
3445find out for certain whether correcting the apparent error would lead to
3446correct results in the rest of the run. You can find the answer by
3447experiment, using the _GDBN__ features for altering execution of the
3448program.
4187119d 3449
fe3f5fc8
RP
3450For example, you can store new values into variables or memory
3451locations, give the program a signal, restart it at a different address,
3452or even return prematurely from a function to its caller.
4187119d 3453
fe3f5fc8
RP
3454@menu
3455* Assignment:: Altering variable values or memory contents.
3456* Jumping:: Altering control flow.
3457* Signaling:: Making signals happen in the program.
3458* Returning:: Making a function return prematurely.
3459* Calling:: Calling functions from your program
3460@end menu
4187119d 3461
fe3f5fc8
RP
3462@node Assignment, Jumping, Altering, Altering
3463@section Assignment to Variables
4187119d 3464
fe3f5fc8
RP
3465@cindex assignment
3466@cindex setting variables
3467To alter the value of a variable, evaluate an assignment expression.
3468@xref{Expressions}. For example,
4187119d 3469
3470@example
fe3f5fc8 3471print x=4
4187119d 3472@end example
e91b87a3 3473
fe3f5fc8
RP
3474@noindent
3475would store the value 4 into the variable @code{x}, and then print
3476the value of the assignment expression (which is 4).
e91b87a3 3477
fe3f5fc8
RP
3478All the assignment operators of C are supported, including the
3479increment operators @samp{++} and @samp{--}, and combining
3480assignments such as @samp{+=} and _0__@samp{<<=}_1__.
e91b87a3 3481
fe3f5fc8
RP
3482@kindex set
3483@kindex set variable
3484@cindex variables, setting
3485If you are not interested in seeing the value of the assignment, use the
3486@samp{set} command instead of the @samp{print} command. @samp{set} is
3487really the same as @samp{print} except that the expression's value is not
3488printed and is not put in the value history (@pxref{Value History}). The
3489expression is evaluated only for side effects.
e91b87a3 3490
fe3f5fc8
RP
3491Note that if the beginning of the argument string of the @samp{set} command
3492appears identical to a @samp{set} subcommand, it may be necessary to use
3493the @samp{set variable} command. This command is identical to @samp{set}
3494except for its lack of subcommands.
e91b87a3 3495
fe3f5fc8
RP
3496_GDBN__ allows more implicit conversions in assignments than C does; you can
3497freely store an integer value into a pointer variable or vice versa, and
3498any structure can be converted to any other structure that is the same
3499length or shorter.
3500@comment FIXME: how do structs align/pad in these conversions?
3501@comment /[email protected] 18dec1990
e91b87a3 3502
fe3f5fc8
RP
3503To store values into arbitrary places in memory, use the @samp{@{@dots{}@}}
3504construct to generate a value of specified type at a specified address
3505(@pxref{Expressions}). For example, @code{@{int@}0x83040} would refer
3506to memory location 0x83040 as an integer (which implies a certain size
3507and representation in memory), and
e91b87a3 3508
9da601bf 3509@example
fe3f5fc8 3510set @{int@}0x83040 = 4
9da601bf
RP
3511@end example
3512
fe3f5fc8
RP
3513would store the value 4 into that memory location.
3514
3515@node Jumping, Signaling, Assignment, Altering
3516@section Continuing at a Different Address
3517
3518Ordinarily, when you continue the program, you do so at the place where
3519it stopped, with the @samp{cont} command. You can instead continue at
3520an address of your own choosing, with the following commands:
3521
3522@table @code
3523@item jump @var{linenum}
3524@kindex jump
3525Resume execution at line number @var{linenum}. Execution may stop
3526immediately if there is a breakpoint there.
e91b87a3 3527
fe3f5fc8
RP
3528The @samp{jump} command does not change the current stack frame, or
3529the stack pointer, or the contents of any memory location or any
3530register other than the program counter. If line @var{linenum} is in
3531a different function from the one currently executing, the results may
3532be bizarre if the two functions expect different patterns of arguments or
3533of local variables. For this reason, the @samp{jump} command requests
3534confirmation if the specified line is not in the function currently
3535executing. However, even bizarre results are predictable based on
3536careful study of the machine-language code of the program.
e91b87a3 3537
fe3f5fc8
RP
3538@item jump *@var{address}
3539Resume execution at the instruction at address @var{address}.
e91b87a3 3540@end table
3541
fe3f5fc8
RP
3542You can get much the same effect as the @code{jump} command by storing a
3543new value into the register @code{$pc}. The difference is that this
3544does not start the program running; it only changes the address where it
3545@emph{will} run when it is continued. For example,
e91b87a3 3546
3547@example
fe3f5fc8 3548set $pc = 0x485
e91b87a3 3549@end example
3550
3551@noindent
fe3f5fc8
RP
3552causes the next @samp{cont} command or stepping command to execute at
3553address 0x485, rather than at the address where the program stopped.
3554@xref{Stepping}.
e91b87a3 3555
fe3f5fc8
RP
3556The most common occasion to use the @samp{jump} command is to back up,
3557perhaps with more breakpoints set, over a portion of a program that has
3558already executed.
54e4a398 3559
fe3f5fc8
RP
3560@node Signaling, Returning, Jumping, Altering
3561@section Giving the Program a Signal
e91b87a3 3562
9da601bf 3563@table @code
fe3f5fc8
RP
3564@item signal @var{signalnum}
3565@kindex signal
3566Resume execution where the program stopped, but give it immediately the
3567signal number @var{signalnum}.
9da601bf 3568
fe3f5fc8
RP
3569Alternatively, if @var{signalnum} is zero, continue execution without
3570giving a signal. This is useful when the program stopped on account of
3571a signal and would ordinary see the signal when resumed with the
3572@samp{cont} command; @samp{signal 0} causes it to resume without a
3573signal.
9da601bf 3574@end table
e91b87a3 3575
fe3f5fc8
RP
3576@node Returning, Calling, Signaling, Altering
3577@section Returning from a Function
e91b87a3 3578
fe3f5fc8
RP
3579@table @code
3580@item return
3581@cindex returning from a function
3582@kindex return
3583You can cancel execution of a function call with the @samp{return}
3584command.
3585@end table
e91b87a3 3586
fe3f5fc8
RP
3587This command has the effect of discarding the selected stack
3588frame (and all frames within it), so that control moves to the caller of
3589that function. You can think of this as making the discarded frame
3590return prematurely.
e91b87a3 3591
fe3f5fc8
RP
3592First select the stack frame that you wish to return from
3593(@pxref{Selection}). Then type the @samp{return} command. If you wish
3594to specify the value to be returned, give that as an argument.
e91b87a3 3595
fe3f5fc8
RP
3596This pops the selected stack frame (and any other frames inside of it),
3597leaving its caller as the innermost remaining frame. That frame becomes
3598selected. The specified value is stored in the registers used for
3599returning values of functions.
e91b87a3 3600
fe3f5fc8
RP
3601The @samp{return} command does not resume execution; it leaves the
3602program stopped in the state that would exist if the function had just
3603returned. Contrast this with the @samp{finish} command
3604(@pxref{Stepping}), which resumes execution until the selected stack
3605frame returns @emph{naturally}.
e91b87a3 3606
fe3f5fc8
RP
3607@node Calling, , Returning, Altering
3608@comment node-name, next, previous, up
3609@section Calling your Program's Functions
e91b87a3 3610
fe3f5fc8
RP
3611@cindex calling functions
3612@kindex call
3613@table @code
3614@item call @var{expr}
3615Evaluate the expression @var{expr} without displaying @code{void}
3616returned values.
e91b87a3 3617@end table
3618
fe3f5fc8
RP
3619You can use this variant of the @samp{print} command if you want to
3620execute some piece of your program, but without cluttering the output
3621with @code{void} returned values. The result is printed and saved in
3622the value history, if it is not void.
e91b87a3 3623
fe3f5fc8
RP
3624@node Files,,,
3625@chapter _GDBN__'s Files
e91b87a3 3626
fe3f5fc8
RP
3627@section Commands to Specify Files
3628@cindex core dump file
3629@cindex symbol table
3630_GDBN__ needs to know the file name of the program to be debugged, both in
3631order to read its symbol table and in order to start the program. To
3632debug a core dump of a previous run, _GDBN__ must be told the file name of
3633the core dump.
e91b87a3 3634
fe3f5fc8
RP
3635The usual way to specify the executable and core dump file names is with
3636the command arguments given when you start _GDBN__, as discussed in
3637@pxref{Invocation}.
e91b87a3 3638
fe3f5fc8
RP
3639But occasionally it is necessary to change to a different file during a
3640_GDBN__ session. Or you may run _GDBN__ and forget to specify the files you
3641want to use. In these situations the _GDBN__ commands to specify new files
3642are useful.
e91b87a3 3643
fe3f5fc8
RP
3644@table @code
3645@item file @var{filename}
3646@cindex executable file
3647@kindex file
3648Use @var{filename} as the program to be debugged. It is read for its
3649symbols, for getting the contents of pure memory, and it is the program
3650executed when you use the @samp{run} command. If you do not specify a
3651directory and the file is not found in _GDBN__'s working directory,
3652_GDBN__ will use the environment variable @code{PATH} as a list of
3653directories to search, just as the shell does when looking for a program
3654to run.
e91b87a3 3655
fe3f5fc8
RP
3656@samp{file} with no argument makes both executable file and symbol
3657table become unspecified.
e91b87a3 3658
fe3f5fc8
RP
3659@item exec-file @var{filename}
3660@kindex exec-file
3661Specify that the program to be run (but not the symbol table) is found
3662in @var{filename}. _GDBN__ will search the environment variable @code{PATH}
3663if necessary to locate the program.
e91b87a3 3664
fe3f5fc8
RP
3665@item symbol-file @var{filename}
3666@kindex symbol-file
3667Read symbol table information from file @var{filename}. @code{PATH} is
3668searched when necessary. Use the @samp{file} command to get both symbol
3669table and program to run from the same file.
e91b87a3 3670
fe3f5fc8
RP
3671@samp{symbol-file} with no argument clears out _GDBN__'s information on your
3672program's symbol table.
d2e08421 3673
fe3f5fc8
RP
3674The @samp{symbol-file} command causes _GDBN__ to forget the contents of its
3675convenience variables, the value history, and all breakpoints and
3676auto-display expressions. This is because they may contain pointers to
3677the internal data recording symbols and data types, which are part of
3678the old symbol table data being discarded inside _GDBN__.
d2e08421 3679
fe3f5fc8
RP
3680On some kinds of object files, the @samp{symbol-file} command does not
3681actually read the symbol table in full right away. Instead, it scans
3682the symbol table quickly to find which source files and which symbols
3683are present. The details are read later, one source file at a time,
3684when they are needed.
e91b87a3 3685
fe3f5fc8
RP
3686The purpose of this two-stage reading strategy is to make _GDBN__ start up
3687faster. For the most part, it is invisible except for occasional pauses
3688while the symbol table details for a particular source file are being
3689read. (The @samp{set verbose} command can turn these pauses into
3690messages if desired. @xref{User Interface}).
e91b87a3 3691
fe3f5fc8
RP
3692When the symbol table is stored in COFF format, @samp{symbol-file} does
3693read the symbol table data in full right away. We haven't implemented
3694the two-stage strategy for COFF yet.
e91b87a3 3695
fe3f5fc8
RP
3696When _GDBN__ is configured for a particular environment, it will understand
3697debugging information in whatever format is the standard generated for
3698that environment; you may use either the GNU compiler _GCC__, or other
3699compilers that adhere to the local conventions. Best results are
3700usually obtained from _GCC__; for example, using _GCC__ you can generate
3701debugging information for optimized code.
e91b87a3 3702
fe3f5fc8
RP
3703@item core-file @var{filename}
3704@itemx core @var{filename}
3705@kindex core
3706@kindex core-file
3707Specify the whereabouts of a core dump file to be used as the ``contents
3708of memory''. Traditionally, core files contain only some parts of the
3709address space of the process that generated them; _GDBN__ can access the
3710executable file itself for other parts.
e91b87a3 3711
fe3f5fc8
RP
3712@samp{core-file} with no argument specifies that no core file is
3713to be used.
e91b87a3 3714
fe3f5fc8
RP
3715Note that the core file is ignored when your program is actually running
3716under _GDBN__. So, if you have been running the program and you wish to
3717debug a core file instead, you must kill the subprocess in which the
3718program is running. To do this, use the @samp{kill} command
3719(@pxref{Kill Process}).
e91b87a3 3720
fe3f5fc8
RP
3721@item load @var{filename}
3722@kindex load
3723This command will dynamically link @var{filename} on the current target,
3724performing any necessary downloads, then add @var{filename}'s symbol
3725table in the same way as the @samp{add-syms} command.
e91b87a3 3726
fe3f5fc8
RP
3727@item add-syms @var{filename} @var{address}
3728@kindex add-syms
3729@cindex dynamic linking
3730The @samp{add-syms} command reads additional symbol table information
3731from the file @var{filename}. You would use this command when that file
3732has been dynamically loaded (by some other means) into the program that
3733is running. @var{address} should be the memory address at which the
3734file has been loaded; _GDBN__ cannot figure this out for itself.
e91b87a3 3735
fe3f5fc8
RP
3736The symbol table of the file @var{filename} is added to the symbol table
3737originally read with the @samp{symbol-file} command. You can use the
3738@samp{add-syms} command any number of times; the new symbol data thus
3739read keeps adding to the old. The @samp{symbol-file} command forgets
3740all the symbol data _GDBN__ has read.
e91b87a3 3741
fe3f5fc8
RP
3742@item info files
3743@itemx info target
3744@kindex info files
3745@kindex info target
3746@samp{info files} and @samp{info target} are synonymous; both print the
3747current targets (@pxref{Targets}), including the names of the
3748executable and core dump files currently in use by _GDBN__, and the files
3749from which symbols were loaded.
e91b87a3 3750
fe3f5fc8
RP
3751Beware: the similar command @samp{info targets} lists all possible
3752targets rather than current ones.
e91b87a3 3753
fe3f5fc8 3754@end table
e91b87a3 3755
fe3f5fc8
RP
3756While all three file-specifying commands allow both absolute and relative
3757file names as arguments, _GDBN__ always converts the file name to an absolute
3758one and remembers it that way.
4187119d 3759
fe3f5fc8
RP
3760@kindex sharedlibrary
3761@kindex share
3762@cindex shared libraries
e91b87a3 3763
fe3f5fc8
RP
3764_GDBN__ supports the SunOS shared library format. Symbols from a shared
3765library cannot be referenced before the shared library has been linked
3766with the program. (That is to say, after one types @samp{run} and
3767the function @code{main()} has been entered; or when examining core
3768files.) Once the shared library has been linked in, you can use the
3769following commands:
e91b87a3 3770
fe3f5fc8
RP
3771@table @code
3772@item sharedlibrary @var{regex}
3773@itemx share @var{regex}
3774Load shared object library symbols for files matching a UNIX regular
3775expression.
e91b87a3 3776
fe3f5fc8
RP
3777@item share
3778@itemx sharedlibrary
3779Load symbols for all shared libraries.
e91b87a3 3780
fe3f5fc8
RP
3781@item info share
3782@itemx info sharedlibrary
3783@kindex info sharedlibrary
3784@kindex info share
3785Print the names of the shared libraries which are currently loaded.
3786@end table
e91b87a3 3787
fe3f5fc8
RP
3788@section Errors Reading Symbols
3789While a symbol file is being read, _GDBN__ will occasionally encounter
3790problems, such as symbol types it does not recognize, or known bugs in
3791compiler output. By default, it prints one message about each such
3792type of problem, no matter how many times the problem occurs. You can
3793ask it to print more messages, to see how many times the problems occur,
3794or can shut the messages off entirely, with the @samp{set
3795complaints} command (@xref{User Interface}).
e91b87a3 3796
fe3f5fc8 3797The messages currently printed, and their meanings, are:
e91b87a3 3798
fe3f5fc8
RP
3799@table @code
3800@item inner block not inside outer block in @var{symbol}
e91b87a3 3801
fe3f5fc8
RP
3802The symbol information shows where symbol scopes begin and end
3803(such as at the start of a function or a block of statements). This
3804error indicates that an inner scope block is not fully contained
3805in its outer scope blocks. _GDBN__ circumvents the problem by treating
3806the inner block as if it had the same scope as the outer block.
3807@var{symbol} may be ``(don't know)'' if the outer block is not
3808a function.
e91b87a3 3809
fe3f5fc8 3810@item block at @var{address} out of order
e91b87a3 3811
fe3f5fc8
RP
3812The symbol information for symbol scope blocks should occur in
3813order of increasing addresses. This error indicates that it does not
3814do so. _GDBN__ does not circumvent this problem, and will have trouble
3815locating symbols in the source file whose symbols being read. (You
3816can often determine what source file is affected by turning on
3817@samp{info verbose}. @xref{User Interface}.)
e91b87a3 3818
fe3f5fc8 3819@item bad block start address patched
e91b87a3 3820
fe3f5fc8
RP
3821The symbol information for a symbol scope block has a start address
3822smaller than the address of the preceding source line. This is known
3823to occur in the SunOS 4.1.1 (and earlier) C compiler. _GDBN__ circumvents
3824the problem by treating the symbol scope block as starting on the
3825previous source line.
e91b87a3 3826
fe3f5fc8
RP
3827@comment @item{encountered DBX-style class variable debugging information.
3828@comment You seem to have compiled your program with "g++ -g0" instead of "g++ -g".
3829@comment Therefore _GDBN__ will not know about your class variables}
3830@comment
3831@comment This error indicates that the symbol information produced for a C++
3832@comment program includes zero-size fields, which indicated static fields in
3833@comment a previous release of the G++ compiler. This message is probably
3834@comment obsolete.
3835@comment
3836@item bad string table offset in symbol @var{n}
e91b87a3 3837
fe3f5fc8
RP
3838Symbol number @var{n} contains a pointer into the string table which is
3839larger than the size of the string table. _GDBN__ circumvents the problem
3840by considering the symbol to have the name @code{foo}, which may cause
3841other problems if many symbols end up with this name. @cindex{foo}
e91b87a3 3842
fe3f5fc8 3843@item unknown symbol type @code{0xNN}
e91b87a3 3844
fe3f5fc8
RP
3845The symbol information contains new data types that _GDBN__ does not yet
3846know how to read. @code{0xNN} is the symbol type of the misunderstood
3847information, in hexadecimal. _GDBN__ circumvents the error by ignoring
3848this symbol information. This will usually allow the program to be
3849debugged, though certain symbols will not be accessible. If you
3850encounter such a problem and feel like debugging it, you can debug _GDBP__
3851with itself, breakpoint on "complain", then go "up" to
3852read_dbx_symtab() and examine *bufp to see the symbol.
e91b87a3 3853
fe3f5fc8
RP
3854@c @item stub type has NULL name
3855@c
3856@c FIXME, Mike Tiemann needs to write about what this means.
e91b87a3 3857
fe3f5fc8 3858@item const/volatile indicator missing, got 'X'
e91b87a3 3859
fe3f5fc8
RP
3860The symbol information for a C++ type is missing some information that
3861the compiler should have output for it.
e91b87a3 3862
fe3f5fc8 3863@item C++ type mismatch between compiler and debugger
e91b87a3 3864
fe3f5fc8
RP
3865The debugger could not parse a type specification output by the compiler
3866for some C++ object.
4187119d 3867
e91b87a3 3868@end table
3869
fe3f5fc8
RP
3870@node Targets, Running, Compilation, Top
3871@chapter Specifying a Debugging Target
3872@cindex debugging target
3873@kindex target
3874A @dfn{target} is an interface between the debugger and a particular
3875kind of file or process.
e91b87a3 3876
fe3f5fc8
RP
3877Often, you will be able to run _GDBN__ in the same host environment as the
3878program you are debugging; in that case, the debugging target can just be
3879specified as a side effect of the @samp{file} or @samp{core} commands.
3880When you need more flexibility---for example, running _GDBN__ on a
3881physically separate host, controlling standalone systems over a
3882serial port, or realtime systems over a TCP/IP connection---you can use
3883the @samp{target} command.
e91b87a3 3884
fe3f5fc8
RP
3885@menu
3886* Active Targets:: Active Targets
3887* Target Commands:: Commands for Managing Targets
3888@end menu
e91b87a3 3889
fe3f5fc8
RP
3890@node Active Targets, Target Commands, Targets, Targets
3891@section Active Targets
3892@cindex stacking targets
3893@cindex active targets
3894@cindex multiple targets
e91b87a3 3895
fe3f5fc8
RP
3896Targets are managed in three @dfn{strata} that correspond to different
3897classes of target: processes, core files, and executable files. This
3898allows you to (for example) start a process and inspect its activity
3899without abandoning your work on a core file.
e91b87a3 3900
fe3f5fc8
RP
3901More than one target can potentially respond to a request. In
3902particular, when you access memory _GDBN__ will walk down the three strata of
3903targets until it finds a target that can handle that particular address.
e91b87a3 3904
fe3f5fc8
RP
3905Strata are always examined in a fixed order: first a process if there is
3906one, then a core file if there is one, and finally an executable file if
3907there is one of those.
e91b87a3 3908
fe3f5fc8
RP
3909When you specify a new target in a given stratum, it replaces any target
3910previously in that stratum.
e91b87a3 3911
fe3f5fc8
RP
3912To get rid of a target without replacing it, use the @samp{detach}
3913command. The related command @samp{attach} provides you with a way of
3914choosing a particular running process as a new target. @xref{Attach}.
e91b87a3 3915
fe3f5fc8
RP
3916@node Target Commands, , Active Targets, Targets
3917@section Commands for Managing Targets
e91b87a3 3918
fe3f5fc8
RP
3919@table @code
3920@item target @var{type} @var{parameters}
3921Connects the _GDBN__ host environment to a target machine or process. A
3922target is typically a protocol for talking to debugging facilities. You
3923use the argument @var{type} to specify the type or protocol of the
3924target machine; for example, @samp{target vxworks} for a TCP/IP link to
3925a VxWorks system.
3926
3927Further @var{parameters} are interpreted by the target protocol, but
3928typically include things like device names or host names to connect
3929with, process numbers, and baud rates. Executing
e91b87a3 3930@example
fe3f5fc8 3931 target @var{type}
e91b87a3 3932@end example
3933
fe3f5fc8
RP
3934@noindent
3935(without any parameters) will issue a message about what
3936parameters are required for that target type.
e91b87a3 3937
fe3f5fc8
RP
3938@item info targets
3939@kindex info targets
3940Displays the names of all targets available. Beware: the similar
3941command @samp{info target} displays targets currently in use rather than
3942all available ones. @samp{info files} gives the same information as
3943@samp{info target} (@pxref{Files}).
e91b87a3 3944@end table
3945
fe3f5fc8
RP
3946Here are some common targets (available, or not, depending on _GDBN__
3947configuration):
e91b87a3 3948
fe3f5fc8
RP
3949@table @code
3950@item target exec @var{prog}
3951@kindex target exec
3952An executable file. @samp{target exec @var{prog}} is the same as
3953@samp{exec-file @var{prog}}.
e91b87a3 3954
fe3f5fc8
RP
3955@item target core @var{filename}
3956@kindex target core
3957A core dump file. @samp{target core @var{filename}} is the same as
3958@samp{core-file @var{filename}}.
e91b87a3 3959
fe3f5fc8
RP
3960@item target remote @var{dev}
3961@kindex target remote
3962Remote serial target in _GDBP__-specific protocol. The argument @var{dev}
3963specifies what serial device to use for the connection (e.g.
3964@code{/dev/ttya}).
e91b87a3 3965
fe3f5fc8
RP
3966_if__(_AMD29K__)
3967@item target amd-eb @var{dev} @var{speed} @var{PROG}
3968@kindex target amd-eb
3969@cindex AMD EB29K
3970Remote PC-resident AMD EB29K board, attached over serial lines.
3971@var{dev} is the serial device, as for @samp{target remote};
3972@samp{speed} allows you to specify the linespeed; and @var{PROG} is the
3973name of the program to be debugged, as it appears to DOS on the PC.
3974@xref{EB29K Remote}.
e91b87a3 3975
fe3f5fc8
RP
3976_fi__(_AMD29K__)
3977_if__(_I960__)
3978@item target nindy @var{devicename}
3979@kindex target nindy
3980An Intel 960 board controlled by a Nindy Monitor. @var{devicename} is
3981the name of the serial device to use for the connection, e.g.
3982@samp{/dev/ttya}.
e91b87a3 3983
fe3f5fc8
RP
3984_fi__(_I960__)
3985_if__(_VXWORKS__)
3986@item target vxworks @var{machinename}
3987@kindex target vxworks
3988A VxWorks system, attached via TCP/IP. The argument @var{machinename}
3989is the target system's machine name or IP address.
e91b87a3 3990
fe3f5fc8 3991_fi__(_VXWORKS__)
e91b87a3 3992@end table
3993
fe3f5fc8
RP
3994_if__(_GENERIC__)
3995Different targets are available on different configurations of _GDBN__; your
3996configuration may have more or fewer targets.
3997_fi__(_GENERIC__)
e91b87a3 3998
fe3f5fc8
RP
3999@node Remote,,,
4000@section Remote Debugging
4001@cindex remote debugging
e91b87a3 4002
fe3f5fc8
RP
4003If you are trying to debug a program running on a machine that can't run
4004_GDBN__ in the usual way, it is often useful to use remote debugging. For
4005example, you might be debugging an operating system kernel, or debugging
4006a small system which does not have a general purpose operating system
4007powerful enough to run a full-featured debugger. Currently _GDBN__ supports
4008remote debugging over a serial connection, and (using Sun RPC) over a
4009TCP/IP connection.
e91b87a3 4010
fe3f5fc8
RP
4011The program to be debugged on the remote machine needs to contain a
4012debugging device driver which talks to _GDBN__ over the serial line. The
4013same version of _GDBN__ that is used ordinarily can be used for this.
4014Several sample remote debugging drivers are distributed with _GDBN__; see
4015the @file{README} file in the _GDBN__ distribution for more information.
e91b87a3 4016
fe3f5fc8
RP
4017@menu
4018* Remote Commands:: Commands used to start and finish remote debugging.
4019@end menu
e91b87a3 4020
fe3f5fc8
RP
4021For details of the communication protocol, see the comments in the _GDBN__
4022source file @file{remote.c}.
e91b87a3 4023
fe3f5fc8
RP
4024@node Remote Commands, , Remote, Remote
4025@subsection Commands for Remote Debugging
e91b87a3 4026
fe3f5fc8
RP
4027To start remote debugging, first run _GDBN__ and specify as an executable file
4028the program that is running in the remote machine. This tells _GDBN__ how
4029to find the program's symbols and the contents of its pure text. Then
4030establish communication using the @samp{target remote} command with a device
4031name as an argument. For example:
e91b87a3 4032
fe3f5fc8
RP
4033@example
4034target remote /dev/ttyb
4035@end example
e91b87a3 4036
fe3f5fc8
RP
4037@noindent
4038if the serial line is connected to the device named @file{/dev/ttyb}. This
4039will stop the remote machine if it is not already stopped.
4187119d 4040
fe3f5fc8
RP
4041Now you can use all the usual commands to examine and change data and to
4042step and continue the remote program.
e91b87a3 4043
fe3f5fc8
RP
4044To resume the remote program and stop debugging it, use the @samp{detach}
4045command.
831c8511 4046
fe3f5fc8
RP
4047Other remote targets be available in your
4048configuration of _GDBN__; use @samp{info targets} to list them.
831c8511 4049
fe3f5fc8
RP
4050@table @code
4051@item reset
4052@kindex reset
4053For a target attached through a serial line, this command sends a
4054``break'' to the remote target system; this is only useful if the target
4055has been equipped with a circuit to perform a hard reset (or some other
4056interesting action) when a break is detected.
4057@end table
e91b87a3 4058
fe3f5fc8
RP
4059@node Controlling _GDBN__,,,
4060@chapter Controlling _GDBN__
831c8511 4061
fe3f5fc8
RP
4062You can alter many aspects of _GDBN__'s interaction with you by using
4063the @samp{set} command.
e91b87a3 4064
fe3f5fc8
RP
4065@node Prompt,,,
4066@section Prompt
4067@cindex prompt
4068_GDBN__ indicates its readiness to read a command by printing a string
4069called the @dfn{prompt}. This string is normally @samp{(_GDBP__)}. You can
4070change the prompt string with the @samp{set prompt} command. For
4071instance, when debugging _GDBN__ with _GDBN__, it is useful to change the prompt
4072in one of the _GDBN__s so that you tell which one you are talking to.
e91b87a3 4073
fe3f5fc8
RP
4074@table @code
4075@item set prompt @var{newprompt}
4076@kindex set prompt
4077Directs _GDBN__ to use @var{newprompt} as its prompt string henceforth.
4078@kindex show prompt
4079@item show prompt
4080Prints a line of the form: @samp{Gdb's prompt is: @var{your-prompt}}
4081@end table
e91b87a3 4082
fe3f5fc8
RP
4083@node Editing/History,,,
4084@section Command Editing and History
4085@cindex readline
4086@cindex command line editing
4087@cindex history substitution
4088_GDBN__ reads its input commands via the @code{readline} interface. This
4089GNU library provides consistent behavior for programs which provide a
4090command line interface to the user. Advantages are @samp{emacs}-style
4091or @samp{vi}-style inline editing of commands, @samp{csh}-like history
4092substitution, and a storage and recall of command history across
4093debugging sessions.
e91b87a3 4094
fe3f5fc8
RP
4095You may control the behavior of command line editing in _GDBN__ with the
4096command @samp{set}. You may check the status of any of these settings
4097with the command @samp{show}.
e91b87a3 4098
fe3f5fc8
RP
4099@table @code
4100@kindex set editing
4101@cindex editing
4102@item set editing
4103@itemx set editing on
4104Enable command line editing (enabled by default).
e91b87a3 4105
fe3f5fc8
RP
4106@item set editing off
4107Disable command line editing.
e91b87a3 4108
fe3f5fc8
RP
4109@kindex show editing
4110@item show editing
4111Show whether command line editing is enabled.
e91b87a3 4112
fe3f5fc8
RP
4113@cindex history file
4114@kindex set history file
4115@item set history file @var{filename}
4116Set the name of the _GDBN__ command history file to @samp{filename}. This is
4117the file from which _GDBN__ will read an initial command history
4118list or to which it will write this list when it exits. This list is
4119accessed through history expansion or through the history
4120command editing characters listed below. This file defaults to the
4121value of the environmental variable @code{GDBHISTFILE}, or to
4122@code{./.gdb_history} if this variable is not set.
e91b87a3 4123
fe3f5fc8
RP
4124@cindex history write
4125@kindex set history write
4126@item set history write
4127@itemx set history write on
4128Make _GDBN__ record command history in a file, whose name may be specified with the
4129@samp{set history file} command. By default, this option is disabled.
4187119d 4130
fe3f5fc8
RP
4131@item set history write off
4132Make _GDBN__ stop recording command history in a file.
e91b87a3 4133
fe3f5fc8
RP
4134@cindex history size
4135@kindex set history size
4136@item set history size @var{size}
4137Set the number of commands which _GDBN__ will keep in its history list.
4138This defaults to the value of the environmental variable
4139@code{HISTSIZE}, or to 256 if this variable is not set.
4140@end table
e91b87a3 4141
fe3f5fc8
RP
4142@cindex history expansion
4143History expansion assigns special meaning to the character @samp{!}
4144(@pxref{Event Designators}). Since @samp{!} is also the logical not
4145operator in C, history expansion is off by default. If you decide to
4146enable history expansion with the @samp{set history expansion on}
4147command, you may sometimes need to follow @samp{!} (when it is used as
4148logical not, in an expression) with a space or a tab to prevent it from
4149being expanded. The @code{readline} history facilities will not attempt
4150substitution on the strings @samp{!=} and @samp{!(}, even when history
4151expansion is enabled.
e91b87a3 4152
fe3f5fc8 4153The commands to control history expansion are:
e91b87a3 4154
fe3f5fc8 4155@table @code
e91b87a3 4156
fe3f5fc8
RP
4157@kindex set history expansion
4158@item set history expansion on
4159@itemx set history expansion
4160Enable history expansion. History expansion is off by default.
e91b87a3 4161
fe3f5fc8
RP
4162@item set history expansion off
4163Disable history expansion.
4187119d 4164
fe3f5fc8
RP
4165The @code{readline} code comes with more complete documentation of
4166editing and history expansion features. Users unfamiliar with @samp{emacs}
4167or @samp{vi} may wish to read it. @xref{Command Line Editing}.
e91b87a3 4168
fe3f5fc8
RP
4169@kindex show history
4170@item show history
4171@itemx show history file
4172@itemx show history write
4173@itemx show history size
4174@itemx show history expansion
4175These commands display the state of the _GDBN__ history parameters.
4176@samp{show history} by itself displays all four states.
e91b87a3 4177
fe3f5fc8 4178@end table
e91b87a3 4179
fe3f5fc8
RP
4180@table @code
4181@kindex info editing
4182@item info editing
4183Display the last ten commands in the command history.
e91b87a3 4184
fe3f5fc8
RP
4185@item info editing @var{n}
4186Print ten commands centered on command number @var{n}.
e91b87a3 4187
fe3f5fc8
RP
4188@item info editing +
4189Print ten commands just after the commands last printed.
4187119d 4190
fe3f5fc8 4191@end table
e91b87a3 4192
fe3f5fc8
RP
4193@node Screen Size,,,
4194@section Screen Size
4195@cindex size of screen
4196@cindex pauses in output
4197Certain commands to _GDBN__ may produce large amounts of information output
4198to the screen. To help you read all of it, _GDBN__ pauses and asks you for
4199input at the end of each page of output. Type @key{RET} when you want
4200to continue the output. Normally _GDBN__ knows the size of the screen from
4201the termcap data base together with the value of the @code{TERM}
4202environment variable and the @code{stty rows} and @code{stty cols}
4203settings. If this is not correct, you can override it with
4204the @samp{set screen-height} and @samp{set screen-width} commands:
4187119d 4205
fe3f5fc8
RP
4206_GDBN__ also uses the screen width setting to determine when to wrap lines
4207of output. Depending what is being printed, it tries to break the
4208line at a readable place, rather than simply letting it overflow onto
4209the following line.
e91b87a3 4210
fe3f5fc8
RP
4211@table @code
4212@item set screen-height @var{lpp}
4213@itemx show screen-height
4214@itemx set screen-width @var{cpl}
4215@itemx show screen-width
4216@kindex set screen-height
4217@kindex set screen-width
4218@kindex show screen-width
4219@kindex show screen-height
4220These @samp{set} commands specify a screen height of @var{lpp} lines and
4221a screen width of @var{cpl} characters. The associated @samp{show}
4222commands display the current settings.
e91b87a3 4223
fe3f5fc8
RP
4224If you specify a height of zero lines, _GDBN__ will not pause during output
4225no matter how long the output is. This is useful if output is to a file
4226or to an editor buffer.
e91b87a3 4227@end table
4228
fe3f5fc8
RP
4229@node Numbers,,,
4230@section Numbers
4231@cindex number representation
4232@cindex entering numbers
4233You can always enter numbers in octal, decimal, or hexadecimal in _GDBN__ by
4234the usual conventions: octal numbers begin with @samp{0}, decimal
4235numbers end with @samp{.}, and hexadecimal numbers begin with @samp{0x}.
4236Numbers that begin with none of these are, by default, entered in base
423710; likewise, the default display for numbers---when no particular
4238format is specified---is base 10. You can change the default base for
4239both input and output with the @samp{set radix} command.
4240
4241@table @code
4242@kindex set radix
4243@item set radix @var{base}
4244Set the default base for numeric input and display. Supported choices
4245for @var{base} are decimal 8, 10, 16. @var{base} must itself be
4246specified either unambiguously or using the current default radix; for
4247example, any of
e91b87a3 4248
4249@example
fe3f5fc8
RP
4250set radix 012
4251set radix 10.
4252set radix 0xa
e91b87a3 4253@end example
4254
4255@noindent
fe3f5fc8
RP
4256will set the base to decimal. On the other hand, @samp{set radix 10}
4257will leave the radix unchanged no matter what it was.
4187119d 4258
fe3f5fc8
RP
4259@kindex show radix
4260@item show radix
4261Display the current default base for numeric input and display.
e91b87a3 4262
fe3f5fc8
RP
4263@end table
4264
4265@node Messages/Warnings,,,
4266@section Optional Warnings and Messages
4267By default, _GDBN__ is silent about its inner workings. If you are running
4268on a slow machine, you may want to use the @samp{set verbose} command.
4269It will make _GDBN__ tell you when it does a lengthy internal operation, so
4270you won't think it has crashed.
4271
4272Currently, the messages controlled by @samp{set verbose} are those which
4273announce that the symbol table for a source file is being read
4274(@pxref{Files}, in the description of the command
4275@samp{symbol-file}).
4276@c The following is the right way to do it, but emacs 18.55 doesn't support
4277@c @ref, and neither the emacs lisp manual version of texinfmt or makeinfo
4278@c is released.
4279@ignore
4280see @samp{symbol-file} in @ref{Files}).
4281@end ignore
e91b87a3 4282
4283@table @code
fe3f5fc8
RP
4284@kindex set verbose
4285@item set verbose on
4286Enables _GDBN__'s output of certain informational messages.
4187119d 4287
fe3f5fc8
RP
4288@item set verbose off
4289Disables _GDBN__'s output of certain informational messages.
4290
4291@kindex show verbose
4292@item show verbose
4293Displays whether @samp{set verbose} is on or off.
e91b87a3 4294@end table
4295
fe3f5fc8
RP
4296By default, if _GDBN__ encounters bugs in the symbol table of an object file,
4297it prints a single message about each type of problem it finds, then
4298shuts up. You can suppress these messages, or allow more than one such
4299message to be printed if you want to see how frequent the problems are.
4300@xref{Files}.
e91b87a3 4301
d2e08421 4302@table @code
fe3f5fc8
RP
4303@kindex set complaints
4304@item set complaints @var{limit}
4305Permits _GDBN__ to output @var{limit} complaints about each type of unusual
4306symbols before becoming silent about the problem. Set @var{limit} to
4307zero to suppress all complaints; set it to a large number to prevent
4308complaints from being suppressed.
4309
4310@kindex show complaints
4311@item show complaints
4312Displays how many symbol complaints _GDBN__ is permitted to produce.
d2e08421
RP
4313@end table
4314
fe3f5fc8
RP
4315By default, _GDBN__ is cautious, and asks what sometimes seem to be a lot of
4316stupid questions. For example, if you try to run a program which is
4317already running:
4318@example
e91b87a3 4319
fe3f5fc8
RP
4320(_GDBP__) run
4321The program being debugged has been started already.
4322Start it from the beginning? (y or n)
4323@end example
e91b87a3 4324
fe3f5fc8
RP
4325If you're willing to unflinchingly face the consequences of your own
4326commands, you can disable this ``feature'':
e91b87a3 4327
fe3f5fc8
RP
4328@table @code
4329@kindex set caution
4330@cindex flinching
4331@cindex stupid questions
4332@item set caution off
4333Disables cautious questions.
e91b87a3 4334
fe3f5fc8
RP
4335@item set caution on
4336Enables cautious questions (the default).
9da601bf 4337
fe3f5fc8
RP
4338@item show caution
4339@kindex show caution
4340Displays state of cautious questions.
9da601bf 4341@end table
d2e08421 4342
369a6ade 4343@node Sequences, Emacs, Altering, Top
e91b87a3 4344@chapter Canned Sequences of Commands
4345
5a131cc7 4346Aside from breakpoint commands (@pxref{Break Commands}),_GDBN__ provides two
d2e08421
RP
4347ways to store sequences of commands for execution as a unit:
4348user-defined commands and command files.
e91b87a3 4349
4350@menu
54e4a398
RP
4351* Define:: User-defined commands.
4352* Command Files:: Command files.
4353* Output:: Controlled output commands useful in
e91b87a3 4354 user-defined commands and command files.
4355@end menu
4356
4357@node Define, Command Files, Sequences, Sequences
4358@section User-Defined Commands
4359
4187119d 4360@cindex user-defined command
5a131cc7 4361A @dfn{user-defined command} is a sequence of _GDBN__ commands to which you
e91b87a3 4362assign a new name as a command. This is done with the @samp{define}
4363command.
4364
4365@table @code
4366@item define @var{commandname}
4367@kindex define
4368Define a command named @var{commandname}. If there is already a command
4369by that name, you are asked to confirm that you want to redefine it.
4370
5a131cc7 4371The definition of the command is made up of other _GDBN__ command lines,
e91b87a3 4372which are given following the @samp{define} command. The end of these
4373commands is marked by a line containing @samp{end}.
4374
4375@item document @var{commandname}
4376@kindex document
4377Give documentation to the user-defined command @var{commandname}. The
4378command @var{commandname} must already be defined. This command reads
4379lines of documentation just as @samp{define} reads the lines of the
4187119d 4380command definition, ending with @samp{end}. After the @samp{document}
4381command is finished, @samp{help} on command @var{commandname} will print
4382the documentation you have specified.
e91b87a3 4383
4384You may use the @samp{document} command again to change the
4385documentation of a command. Redefining the command with @samp{define}
4386does not change the documentation.
4387@end table
4388
4389User-defined commands do not take arguments. When they are executed, the
4390commands of the definition are not printed. An error in any command
4391stops execution of the user-defined command.
4392
4393Commands that would ask for confirmation if used interactively proceed
5a131cc7 4394without asking when used inside a user-defined command. Many _GDBN__ commands
e91b87a3 4395that normally print messages to say what they are doing omit the messages
4396when used in user-defined command.
4397
4398@node Command Files, Output, Define, Sequences
4399@section Command Files
4400
4401@cindex command files
5a131cc7 4402A command file for _GDBN__ is a file of lines that are _GDBN__ commands. Comments
e91b87a3 4403(lines starting with @samp{#}) may also be included. An empty line in a
4404command file does nothing; it does not mean to repeat the last command, as
4405it would from the terminal.
4406
4407@cindex init file
5a131cc7
RP
4408@cindex @file{._GDBP__init}
4409When you start _GDBN__, it first executes commands from its @dfn{init files}.
4410These are files named @file{._GDBP__init}. _GDBN__ reads the init file (if any)
4afc6002
RP
4411in your home directory and then the init file (if any) in the current
4412working directory. (The init files are not executed if the @samp{-nx}
4413option is given.) You can also request the execution of a command file
4414with the @samp{source} command:
e91b87a3 4415
4416@table @code
4417@item source @var{filename}
4418@kindex source
4419Execute the command file @var{filename}.
4420@end table
4421
4422The lines in a command file are executed sequentially. They are not
4423printed as they are executed. An error in any command terminates execution
4424of the command file.
4425
4426Commands that would ask for confirmation if used interactively proceed
5a131cc7 4427without asking when used in a command file. Many _GDBN__ commands that
e91b87a3 4428normally print messages to say what they are doing omit the messages
4429when used in a command file.
4430
54e4a398 4431@node Output, , Command Files, Sequences
e91b87a3 4432@section Commands for Controlled Output
4433
4434During the execution of a command file or a user-defined command, the only
4435output that appears is what is explicitly printed by the commands of the
4436definition. This section describes three commands useful for generating
4437exactly the output you want.
4438
4439@table @code
4440@item echo @var{text}
4441@kindex echo
4187119d 4442@comment I don't consider backslash-space a standard C escape sequence
4443@comment because it's not in ANSI.
4444Print @var{text}. Nonprinting characters can be included in @var{text}
4445using C escape sequences, such as @samp{\n} to print a newline. @b{No
4446newline will be printed unless you specify one.} In addition to the
4447standard C escape sequences a backslash followed by a space stands for a
4448space. This is useful for outputting a string with spaces at the
9c91ee3e
RP
4449beginning or the end, since leading and trailing spaces are otherwise
4450trimmed from all arguments. Thus, to print @samp{@ and foo =@ }, use the
4451command @samp{echo \@ and foo = \@ }.
4452@comment FIXME: verify hard copy actually issues enspaces for '@ '! Will this
4453@comment confuse texinfo?
4187119d 4454
4455A backslash at the end of @var{text} can be used, as in C, to continue
4456the command onto subsequent lines. For example,
e91b87a3 4457
4187119d 4458@example
4459echo This is some text\n\
4460which is continued\n\
4461onto several lines.\n
4462@end example
4463
4464produces the same output as
e91b87a3 4465
4466@example
4187119d 4467echo This is some text\n
4468echo which is continued\n
4469echo onto several lines.\n
e91b87a3 4470@end example
4471
4472@item output @var{expression}
4473@kindex output
4474Print the value of @var{expression} and nothing but that value: no
4475newlines, no @samp{$@var{nn} = }. The value is not entered in the
4187119d 4476value history either. @xref{Expressions} for more information on
4477expressions.
e91b87a3 4478
4479@item output/@var{fmt} @var{expression}
4480Print the value of @var{expression} in format @var{fmt}.
4187119d 4481@xref{Output formats}, for more information.
e91b87a3 4482
4483@item printf @var{string}, @var{expressions}@dots{}
4484@kindex printf
4485Print the values of the @var{expressions} under the control of
4486@var{string}. The @var{expressions} are separated by commas and may
4487be either numbers or pointers. Their values are printed as specified
4488by @var{string}, exactly as if the program were to execute
4489
4490@example
4491printf (@var{string}, @var{expressions}@dots{});
4492@end example
4493
4494For example, you can print two values in hex like this:
4495
4496@example
4497printf "foo, bar-foo = 0x%x, 0x%x\n", foo, bar-foo
4498@end example
4499
9da601bf
RP
4500The only backslash-escape sequences that you can use in the format
4501string are the simple ones that consist of backslash followed by a
4502letter.
e91b87a3 4503@end table
4504
369a6ade 4505@node Emacs, Remote, Sequences, Top
5a131cc7 4506@chapter Using _GDBN__ under GNU Emacs
e91b87a3 4507
45007746 4508@cindex emacs
e91b87a3 4509A special interface allows you to use GNU Emacs to view (and
4510edit) the source files for the program you are debugging with
5a131cc7 4511_GDBN__.
e91b87a3 4512
4187119d 4513To use this interface, use the command @kbd{M-x gdb} in Emacs. Give the
4514executable file you want to debug as an argument. This command starts
5a131cc7 4515_GDBN__ as a subprocess of Emacs, with input and output through a newly
4187119d 4516created Emacs buffer.
e91b87a3 4517
5a131cc7 4518Using _GDBN__ under Emacs is just like using _GDBN__ normally except for two
4187119d 4519things:
e91b87a3 4520
4521@itemize @bullet
4522@item
4523All ``terminal'' input and output goes through the Emacs buffer. This
5a131cc7 4524applies both to _GDBN__ commands and their output, and to the input and
e91b87a3 4525output done by the program you are debugging.
4526
4527This is useful because it means that you can copy the text of previous
4528commands and input them again; you can even use parts of the output
4529in this way.
4530
880d228b 4531All the facilities of Emacs' Shell mode are available for this purpose.
e91b87a3 4532
4533@item
5a131cc7 4534_GDBN__ displays source code through Emacs. Each time _GDBN__ displays a
e91b87a3 4535stack frame, Emacs automatically finds the source file for that frame
fe3f5fc8 4536and puts an arrow (_0__@samp{=>}_1__) at the left margin of the current line.
9c91ee3e 4537Emacs uses a separate buffer for source display, and splits the window
5a131cc7 4538to show both your _GDBN__ session and the source.
e91b87a3 4539
5a131cc7 4540Explicit _GDBN__ @samp{list} or search commands still produce output as
e91b87a3 4541usual, but you probably will have no reason to use them.
4542@end itemize
4543
369a6ade
RP
4544@quotation
4545@emph{Warning:} If the directory where your program resides is not your
4546current directory, it can be easy to confuse Emacs about the location of
4547the source files, in which case the auxiliary display buffer will not
5a131cc7
RP
4548appear to show your source. _GDBN__ can find programs by searching your
4549environment's @samp{PATH} variable, so the _GDBN__ I/O session will proceed
4550normally; but Emacs doesn't get enough information back from _GDBN__ to
369a6ade 4551locate the source files in this situation. To avoid this problem,
5a131cc7 4552either start _GDBN__ mode from the directory where your program resides, or
369a6ade
RP
4553specify a full path name when prompted for the @kbd{M-x gdb} argument.
4554
5a131cc7 4555A similar confusion can result if you use the _GDBN__ @samp{file} command to
369a6ade 4556switch to debugging a program in some other location, from an existing
5a131cc7 4557_GDBN__ I/O buffer in Emacs.
369a6ade
RP
4558@end quotation
4559
4560By default, @kbd{M-x gdb} calls the program called ``@code{gdb}''. If
5a131cc7 4561you need to call _GDBN__ by a different name (for example, if you keep
369a6ade
RP
4562several configurations around, with different names) you can set the
4563Emacs variable @code{gdb-command-name}; for example,
4564@example
4565(setq gdb-command-name "mygdb")
4566@end example
4567@noindent
4568(preceded by @kbd{ESC ESC}, or typed in the @code{*scratch*} buffer, or
4569in your @samp{.emacs} file) will make Emacs call the program named
4570``@code{mygdb}'' instead.
4571
5a131cc7 4572In the _GDBN__ I/O buffer, you can use these special Emacs commands in
369a6ade 4573addition to the standard Shell mode commands:
e91b87a3 4574
4575@table @kbd
26376b06 4576@item C-h m
5a131cc7 4577Describe the features of Emacs' _GDBN__ Mode.
26376b06 4578
e91b87a3 4579@item M-s
5a131cc7 4580Execute to another source line, like the _GDBN__ @samp{step} command; also
369a6ade 4581update the display window to show the current file and location.
e91b87a3 4582
4583@item M-n
4584Execute to next source line in this function, skipping all function
5a131cc7 4585calls, like the _GDBN__ @samp{next} command. Then update the display window
369a6ade 4586to show the current file and location.
e91b87a3 4587
4588@item M-i
5a131cc7 4589Execute one instruction, like the _GDBN__ @samp{stepi} command; update
369a6ade
RP
4590display window accordingly.
4591
4592@item M-x gdb-nexti
5a131cc7 4593Execute to next instruction, using the _GDBN__ @samp{nexti} command; update
369a6ade 4594display window accordingly.
e91b87a3 4595
e91b87a3 4596@item C-c C-f
5a131cc7 4597Execute until exit from the selected stack frame, like the _GDBN__
e91b87a3 4598@samp{finish} command.
4187119d 4599
7a67dd45 4600@item M-c
4601@comment C-c C-p in emacs 19
5a131cc7 4602Continue execution of the program, like the _GDBN__ @samp{cont} command.
7a67dd45 4603
4604@item M-u
4605@comment C-c C-u in emacs 19
4606Go up the number of frames indicated by the numeric argument
4607(@pxref{Arguments, , Numeric Arguments, emacs, The GNU Emacs Manual}),
5a131cc7 4608like the _GDBN__ @samp{up} command.@refill
7a67dd45 4609
4610@item M-d
4611@comment C-c C-d in emacs 19
4612Go down the number of frames indicated by the numeric argument, like the
5a131cc7 4613_GDBN__ @samp{down} command.
369a6ade
RP
4614
4615@item C-x &
4616Read the number where the cursor is positioned, and insert it at the end
5a131cc7 4617of the _GDBN__ I/O buffer. For example, if you wish to disassemble code
369a6ade
RP
4618around an address that was displayed earlier, type @kbd{disassemble};
4619then move the cursor to the address display, and pick up the
4620argument for @samp{disassemble} by typing @kbd{C-x &}.
4621
4622You can customize this further on the fly by defining elements of the list
4623@samp{gdb-print-command}; once it is defined, you can format or
4624otherwise process numbers picked up by @kbd{C-x &} before they are
4625inserted. A numeric argument to @kbd{C-x &} will both flag that you
4626wish special formatting, and act as an index to pick an element of the
4627list. If the list element is a string, the number to be inserted is
4628formatted using the Emacs function @samp{format}; otherwise the number
4629is passed as an argument to the corresponding list element.
4630
4631@item M-x gdb-display-frame
4632Explicitly request display of the source code surrounding the current
5a131cc7 4633frame location, in another window. _GDBN__ does this display automatically;
369a6ade
RP
4634but if, for example, you accidentally kill the buffer where it is
4635displayed, this command is a way of getting it back.
e91b87a3 4636@end table
4637
4638In any source file, the Emacs command @kbd{C-x SPC} (@code{gdb-break})
5a131cc7 4639tells _GDBN__ to set a breakpoint on the source line point is on.
e91b87a3 4640
4641The source files displayed in Emacs are in ordinary Emacs buffers
4642which are visiting the source files in the usual way. You can edit
5a131cc7 4643the files with these buffers if you wish; but keep in mind that _GDBN__
e91b87a3 4644communicates with Emacs in terms of line numbers. If you add or
5a131cc7 4645delete lines from the text, the line numbers that _GDBN__ knows will cease
e91b87a3 4646to correspond properly to the code.
4647
4afc6002
RP
4648@comment The following dropped because Epoch is nonstandard. Reactivate
4649@comment if/when v19 does something similar. [email protected] 19dec1990
4650@ignore
96a816c5
JG
4651@kindex emacs epoch environment
4652@kindex epoch
4653@kindex inspect
4654
4655Version 18 of Emacs has a built-in window system called the @samp{epoch}
4656environment. Users of this environment can use a new command,
4657@samp{inspect} which performs identically to @samp{print} except that
4658each value is printed in its own window.
4afc6002 4659@end ignore
96a816c5 4660
5a131cc7 4661@node _GDBN__ Bugs, Installing _GDBN__, Remote, Top
54e4a398 4662@comment node-name, next, previous, up
5a131cc7
RP
4663@chapter Reporting Bugs in _GDBN__
4664@cindex Bugs in _GDBN__
4665@cindex Reporting Bugs in _GDBN__
54e4a398 4666
5a131cc7 4667Your bug reports play an essential role in making _GDBN__ reliable.
54e4a398
RP
4668
4669Reporting a bug may help you by bringing a solution to your problem, or it
4670may not. But in any case the important function of a bug report is to help
5a131cc7
RP
4671the entire community by making the next version of _GDBN__ work better. Bug
4672reports are your contribution to the maintenance of _GDBN__.
54e4a398
RP
4673
4674In order for a bug report to serve its purpose, you must include the
4675information that makes for fixing the bug.
4676
4677@menu
4678* Bug Criteria:: Have You Found a Bug?
4679* Bug Reporting:: How to Report Bugs
4680@end menu
4681
5a131cc7 4682@node Bug Criteria, Bug Reporting, _GDBN__ Bugs, _GDBN__ Bugs
54e4a398
RP
4683@section Have You Found a Bug?
4684@cindex Bug Criteria
4685
4686If you are not sure whether you have found a bug, here are some guidelines:
4687
4688@itemize @bullet
4689@item
4690@cindex Fatal Signal
4691@cindex Core Dump
4692If the debugger gets a fatal signal, for any input whatever, that is a
5a131cc7 4693_GDBN__ bug. Reliable debuggers never crash.
54e4a398
RP
4694
4695@item
4696@cindex error on Valid Input
5a131cc7 4697If _GDBN__ produces an error message for valid input, that is a bug.
54e4a398
RP
4698
4699@item
4700@cindex Invalid Input
5a131cc7 4701If _GDBN__ does not produce an error message for invalid input,
54e4a398
RP
4702that is a bug. However, you should note that your idea of
4703``invalid input'' might be our idea of ``an extension'' or ``support
4704for traditional practice''.
4705
4706@item
4707If you are an experienced user of debugging tools, your suggestions
5a131cc7 4708for improvement of _GDBN__ are welcome in any case.
54e4a398
RP
4709@end itemize
4710
5a131cc7 4711@node Bug Reporting, , Bug Criteria, _GDBN__ Bugs
54e4a398
RP
4712@section How to Report Bugs
4713@cindex Bug Reports
4714@cindex Compiler Bugs, Reporting
4715
54e4a398 4716A number of companies and individuals offer support for GNU products.
5a131cc7 4717If you obtained _GDBN__ from a support organization, we recommend you
54e4a398
RP
4718contact that organization first.
4719
fe3f5fc8
RP
4720Contact information for many support companies and individuals is
4721available in the file @samp{etc/SERVICE} in the GNU Emacs distribution.
54e4a398 4722
5a131cc7 4723In any event, we also recommend that you send bug reports for _GDBN__ to one
54e4a398
RP
4724of these addresses:
4725
4726@example
4727bug-gdb@@prep.ai.mit.edu
4728@{ucbvax|mit-eddie|uunet@}!prep.ai.mit.edu!bug-gdb
4729@end example
4730
4731@strong{Do not send bug reports to @samp{info-gdb}, or to
5a131cc7 4732@samp{help-gdb}, or to any newsgroups.} Most users of _GDBN__ do not want to
54e4a398
RP
4733receive bug reports. Those that do, have asked to be on @samp{bug-gdb}.
4734
4735The mailing list @samp{bug-gdb} has a newsgroup which serves as a
4736repeater. The mailing list and the newsgroup carry exactly the same
4737messages. Often people think of posting bug reports to the newsgroup
4738instead of mailing them. This appears to work, but it has one problem
4739which can be crucial: a newsgroup posting does not contain a mail path
4740back to the sender. Thus, if we need to ask for more information, we
4741may be unable to reach you. For this reason, it is better to send bug
4742reports to the mailing list.
4743
4744As a last resort, send bug reports on paper to:
4745
4746@example
4747GNU Debugger Bugs
9d7c0513 4748545 Tech Square
54e4a398
RP
4749Cambridge, MA 02139
4750@end example
4751
4752The fundamental principle of reporting bugs usefully is this:
4753@strong{report all the facts}. If you are not sure whether to state a
4754fact or leave it out, state it!
4755
4756Often people omit facts because they think they know what causes the
4757problem and they conclude that some details don't matter. Thus, you might
4758assume that the name of the variable you use in an example does not matter.
4759Well, probably it doesn't, but one cannot be sure. Perhaps the bug is a
4760stray memory reference which happens to fetch from the location where that
4761name is stored in memory; perhaps, if the name were different, the contents
4762of that location would fool the debugger into doing the right thing despite
4763the bug. Play it safe and give a specific, complete example. That is the
4764easiest thing for you to do, and the most helpful.
4765
4766Keep in mind that the purpose of a bug report is to enable us to fix
4767the bug if it is not known. It isn't very important what happens if
4768the bug is already known. Therefore, always write your bug reports on
4769the assumption that the bug is not known.
4770
4771Sometimes people give a few sketchy facts and ask, ``Does this ring a
4772bell?'' Those bug reports are useless, and we urge everyone to
4773@emph{refuse to respond to them} except to chide the sender to report
4774bugs properly.
4775
4776To enable us to fix the bug, you should include all these things:
4777
4778@itemize @bullet
4779@item
fe3f5fc8
RP
4780The version of _GDBN__. _GDBN__ announces it if you start with no
4781arguments; you can also print it at any time using @samp{show version}.
54e4a398
RP
4782
4783Without this, we won't know whether there is any point in looking for
5a131cc7 4784the bug in the current version of _GDBN__.
54e4a398
RP
4785
4786@item
4787A complete input script, and all necessary source files, that will
4788reproduce the bug.
4789
4790@item
5a131cc7
RP
4791What compiler (and its version) was used to compile _GDBN__---e.g.
4792``_GCC__-1.37.1''.
54e4a398
RP
4793
4794@item
5a131cc7 4795What compiler (and its version) was used to compile _GDBN__.
54e4a398
RP
4796
4797@item
4798The command arguments you gave the compiler to compile that example and
4799observe the bug. For example, did you use @samp{-O}? To guarantee
4800you won't omit something important, list them all.
4801
4802If we were to try to guess the arguments, we would probably guess wrong
4803and then we would not encounter the bug.
4804
4805@item
4806The type of machine you are using, and the operating system name and
4807version number.
4808
4809@item
4810A description of what behavior you observe that you believe is
4811incorrect. For example, ``It gets a fatal signal.''
4812
5a131cc7 4813Of course, if the bug is that _GDBN__ gets a fatal signal, then we
54e4a398
RP
4814will certainly notice it. But if the bug is incorrect output, we might
4815not notice unless it is glaringly wrong.
4816
4817Even if the problem you experience is a fatal signal, you should still
4818say so explicitly. Suppose something strange is going on, such as,
5a131cc7 4819your copy of _GDBN__ is out of synch, or you have encountered a
54e4a398
RP
4820bug in the C library on your system. (This has happened!) Your copy
4821might crash and ours would not. If you @i{told} us to expect a crash,
4822then when ours fails to crash, we would know that the bug was not
4823happening for us. If you had not told us to expect a crash, then we
4824would not be able to draw any conclusion from our observations.
4825
4826@item
5a131cc7
RP
4827If you wish to suggest changes to the _GDBN__ source, send us context
4828diffs. If you even discuss something in the _GDBN__ source, refer to
54e4a398
RP
4829it by context, not by line number.
4830
4831The line numbers in our development sources don't match those in your
4832sources. Your line numbers would convey no useful information to us.
4833
4834@end itemize
4835
4836Here are some things that are not necessary:
4837
4838@itemize @bullet
4839@item
4840A description of the envelope of the bug.
4841
4842Often people who encounter a bug spend a lot of time investigating
4843which changes to the input file will make the bug go away and which
4844changes will not affect it.
4845
4846This is often time consuming and not very useful, because the way we
4847will find the bug is by running a single example under the debugger
4848with breakpoints, not by pure deduction from a series of examples.
4849We recommend that you save your time for something else.
4850
4851Of course, if you can find a simpler example to report @emph{instead}
4852of the original one, that is a convenience for us. Errors in the
4853output will be easier to spot, running under the debugger will take
4854less time, etc.
4855
4856However, simplification is not vital; if you don't want to do this,
4857report the bug anyway and send us the entire test case you used.
4858
4859@item
4860A patch for the bug.
4861
4862A patch for the bug does help us if it is a good one. But don't omit
4863the necessary information, such as the test case, on the assumption that
4864a patch is all we need. We might see problems with your patch and decide
4865to fix the problem another way, or we might not understand it at all.
4866
5a131cc7 4867Sometimes with a program as complicated as _GDBN__ it is very hard to
54e4a398
RP
4868construct an example that will make the program follow a certain path
4869through the code. If you don't send us the example, we won't be able
4870to construct one, so we won't be able to verify that the bug is fixed.
4871
4872And if we can't understand what bug you are trying to fix, or why your
4873patch should be an improvement, we won't install it. A test case will
4874help us to understand.
e91b87a3 4875
54e4a398
RP
4876@item
4877A guess about what the bug is or what it depends on.
e91b87a3 4878
54e4a398
RP
4879Such guesses are usually wrong. Even we can't guess right about such
4880things without first using the debugger to find the facts.
4881@end itemize
e91b87a3 4882
54e4a398
RP
4883@iftex
4884@include readline/inc-readline.texinfo
4885@include readline/inc-history.texinfo
4886@end iftex
9da601bf 4887
5a131cc7
RP
4888@node Installing _GDBN__, License, _GDBN__ Bugs, Top
4889@appendix Installing _GDBN__
4890@cindex configuring _GDBN__
54e4a398 4891@cindex installation
9c91ee3e 4892
5a131cc7 4893The script @samp{config.gdb} automates the process of preparing _GDBN__ for
54e4a398
RP
4894installation; you can then use @samp{make} to actually build it. For
4895example,
9c91ee3e 4896
54e4a398
RP
4897@example
4898config.gdb sun3os4
4899make
4900@end example
9c91ee3e 4901
54e4a398 4902@noindent
5a131cc7 4903is all that's required to install _GDBN__ on a Sun 3 running SunOS 4.
9c91ee3e 4904
54e4a398
RP
4905@table @code
4906@kindex config.gdb
4907@item config.gdb @var{machine}
23e2e5e1 4908@itemx config.gdb -srcdir=@var{dir} @var{machine}
5a131cc7
RP
4909This is the most usual way of configuring _GDBN__; to debug programs running
4910on the same machine as _GDBN__ itself. If you wish to build the _GDBN__ binaries
54e4a398 4911in a completely different directory from the sources, specify a path to
23e2e5e1 4912the source directory using the @samp{-srcdir} option.
9c91ee3e 4913
23e2e5e1 4914@item config.gdb -host
54e4a398 4915@cindex host environments
5a131cc7 4916Display a list of supported host environments for _GDBN__.
9c91ee3e 4917
54e4a398 4918@item config.gdb @var{host} @var{target}
23e2e5e1 4919@itemx config.gdb -srcdir=@var{dir} @var{host} @var{target}
54e4a398 4920@cindex cross-debugging
5a131cc7 4921_GDBN__ can also be used as a cross-debugger, running on a machine of one
54e4a398
RP
4922type while debugging a program running on a machine of another type.
4923You configure it this way by specifying first the @var{host}, then the
4924@var{target} environment on the @code{config.gdb} argument list; the
5a131cc7 4925@var{host} is where _GDBN__ runs, and the @var{target} is where your program
23e2e5e1 4926runs. @xref{Remote}. Again, you can use @samp{-srcdir} to specify a
5a131cc7 4927path to the _GDBN__ source.
9c91ee3e 4928
23e2e5e1 4929@item config.gdb -target
54e4a398 4930@cindex target environments
5a131cc7 4931Display a list of supported target environments for _GDBN__.
54e4a398 4932@end table
9c91ee3e 4933
5a131cc7 4934@node License,,,
54e4a398
RP
4935@unnumbered GNU GENERAL PUBLIC LICENSE
4936@center Version 1, February 1989
9c91ee3e 4937
54e4a398
RP
4938@display
4939Copyright @copyright{} 1989 Free Software Foundation, Inc.
4940675 Mass Ave, Cambridge, MA 02139, USA
9c91ee3e 4941
54e4a398
RP
4942Everyone is permitted to copy and distribute verbatim copies
4943of this license document, but changing it is not allowed.
4944@end display
9c91ee3e 4945
54e4a398 4946@unnumberedsec Preamble
9c91ee3e 4947
54e4a398
RP
4948 The license agreements of most software companies try to keep users
4949at the mercy of those companies. By contrast, our General Public
4950License is intended to guarantee your freedom to share and change free
4951software---to make sure the software is free for all its users. The
4952General Public License applies to the Free Software Foundation's
4953software and to any other program whose authors commit to using it.
4954You can use it for your programs, too.
d2e08421 4955
54e4a398
RP
4956 When we speak of free software, we are referring to freedom, not
4957price. Specifically, the General Public License is designed to make
4958sure that you have the freedom to give away or sell copies of free
4959software, that you receive source code or can get it if you want it,
4960that you can change the software or use pieces of it in new free
4961programs; and that you know you can do these things.
d2e08421 4962
54e4a398
RP
4963 To protect your rights, we need to make restrictions that forbid
4964anyone to deny you these rights or to ask you to surrender the rights.
4965These restrictions translate to certain responsibilities for you if you
4966distribute copies of the software, or if you modify it.
d2e08421 4967
54e4a398
RP
4968 For example, if you distribute copies of a such a program, whether
4969gratis or for a fee, you must give the recipients all the rights that
4970you have. You must make sure that they, too, receive or can get the
4971source code. And you must tell them their rights.
9c91ee3e 4972
54e4a398
RP
4973 We protect your rights with two steps: (1) copyright the software, and
4974(2) offer you this license which gives you legal permission to copy,
4975distribute and/or modify the software.
9c91ee3e 4976
54e4a398
RP
4977 Also, for each author's protection and ours, we want to make certain
4978that everyone understands that there is no warranty for this free
4979software. If the software is modified by someone else and passed on, we
4980want its recipients to know that what they have is not the original, so
4981that any problems introduced by others will not reflect on the original
4982authors' reputations.
9c91ee3e 4983
54e4a398
RP
4984 The precise terms and conditions for copying, distribution and
4985modification follow.
9c91ee3e 4986
54e4a398
RP
4987@iftex
4988@unnumberedsec TERMS AND CONDITIONS
4989@end iftex
4990@ifinfo
4991@center TERMS AND CONDITIONS
4992@end ifinfo
9c91ee3e 4993
54e4a398
RP
4994@enumerate
4995@item
4996This License Agreement applies to any program or other work which
4997contains a notice placed by the copyright holder saying it may be
4998distributed under the terms of this General Public License. The
4999``Program'', below, refers to any such program or work, and a ``work based
5000on the Program'' means either the Program or any work containing the
5001Program or a portion of it, either verbatim or with modifications. Each
5002licensee is addressed as ``you''.
9c91ee3e 5003
54e4a398
RP
5004@item
5005You may copy and distribute verbatim copies of the Program's source
5006code as you receive it, in any medium, provided that you conspicuously and
5007appropriately publish on each copy an appropriate copyright notice and
5008disclaimer of warranty; keep intact all the notices that refer to this
5009General Public License and to the absence of any warranty; and give any
5010other recipients of the Program a copy of this General Public License
5011along with the Program. You may charge a fee for the physical act of
5012transferring a copy.
9c91ee3e 5013
54e4a398
RP
5014@item
5015You may modify your copy or copies of the Program or any portion of
5016it, and copy and distribute such modifications under the terms of Paragraph
50171 above, provided that you also do the following:
9c91ee3e 5018
54e4a398
RP
5019@itemize @bullet
5020@item
5021cause the modified files to carry prominent notices stating that
5022you changed the files and the date of any change; and
9c91ee3e 5023
54e4a398
RP
5024@item
5025cause the whole of any work that you distribute or publish, that
5026in whole or in part contains the Program or any part thereof, either
5027with or without modifications, to be licensed at no charge to all
5028third parties under the terms of this General Public License (except
5029that you may choose to grant warranty protection to some or all
5030third parties, at your option).
9c91ee3e 5031
54e4a398
RP
5032@item
5033If the modified program normally reads commands interactively when
5034run, you must cause it, when started running for such interactive use
5035in the simplest and most usual way, to print or display an
5036announcement including an appropriate copyright notice and a notice
5037that there is no warranty (or else, saying that you provide a
5038warranty) and that users may redistribute the program under these
5039conditions, and telling the user how to view a copy of this General
5040Public License.
9c91ee3e 5041
9c91ee3e 5042@item
54e4a398
RP
5043You may charge a fee for the physical act of transferring a
5044copy, and you may at your option offer warranty protection in
5045exchange for a fee.
5046@end itemize
9c91ee3e 5047
54e4a398
RP
5048Mere aggregation of another independent work with the Program (or its
5049derivative) on a volume of a storage or distribution medium does not bring
5050the other work under the scope of these terms.
9c91ee3e
RP
5051
5052@item
54e4a398
RP
5053You may copy and distribute the Program (or a portion or derivative of
5054it, under Paragraph 2) in object code or executable form under the terms of
5055Paragraphs 1 and 2 above provided that you also do one of the following:
9c91ee3e 5056
54e4a398 5057@itemize @bullet
26376b06 5058@item
54e4a398
RP
5059accompany it with the complete corresponding machine-readable
5060source code, which must be distributed under the terms of
5061Paragraphs 1 and 2 above; or,
9c91ee3e
RP
5062
5063@item
54e4a398
RP
5064accompany it with a written offer, valid for at least three
5065years, to give any third party free (except for a nominal charge
5066for the cost of distribution) a complete machine-readable copy of the
5067corresponding source code, to be distributed under the terms of
5068Paragraphs 1 and 2 above; or,
d2e08421
RP
5069
5070@item
54e4a398
RP
5071accompany it with the information you received as to where the
5072corresponding source code may be obtained. (This alternative is
5073allowed only for noncommercial distribution and only if you
5074received the program in object code or executable form alone.)
5075@end itemize
9c91ee3e 5076
54e4a398
RP
5077Source code for a work means the preferred form of the work for making
5078modifications to it. For an executable file, complete source code means
5079all the source code for all modules it contains; but, as a special
5080exception, it need not include source code for modules which are standard
5081libraries that accompany the operating system on which the executable
5082file runs, or for standard header files or definitions files that
5083accompany that operating system.
9c91ee3e
RP
5084
5085@item
54e4a398
RP
5086You may not copy, modify, sublicense, distribute or transfer the
5087Program except as expressly provided under this General Public License.
5088Any attempt otherwise to copy, modify, sublicense, distribute or transfer
5089the Program is void, and will automatically terminate your rights to use
5090the Program under this License. However, parties who have received
5091copies, or rights to use copies, from you under this General Public
5092License will not have their licenses terminated so long as such parties
5093remain in full compliance.
9c91ee3e
RP
5094
5095@item
54e4a398
RP
5096By copying, distributing or modifying the Program (or any work based
5097on the Program) you indicate your acceptance of this license to do so,
5098and all its terms and conditions.
9c91ee3e
RP
5099
5100@item
54e4a398
RP
5101Each time you redistribute the Program (or any work based on the
5102Program), the recipient automatically receives a license from the original
5103licensor to copy, distribute or modify the Program subject to these
5104terms and conditions. You may not impose any further restrictions on the
5105recipients' exercise of the rights granted herein.
9c91ee3e 5106
54e4a398
RP
5107@item
5108The Free Software Foundation may publish revised and/or new versions
5109of the General Public License from time to time. Such new versions will
5110be similar in spirit to the present version, but may differ in detail to
5111address new problems or concerns.
9c91ee3e 5112
54e4a398
RP
5113Each version is given a distinguishing version number. If the Program
5114specifies a version number of the license which applies to it and ``any
5115later version'', you have the option of following the terms and conditions
5116either of that version or of any later version published by the Free
5117Software Foundation. If the Program does not specify a version number of
5118the license, you may choose any version ever published by the Free Software
5119Foundation.
9c91ee3e 5120
9c91ee3e 5121@item
54e4a398
RP
5122If you wish to incorporate parts of the Program into other free
5123programs whose distribution conditions are different, write to the author
5124to ask for permission. For software which is copyrighted by the Free
5125Software Foundation, write to the Free Software Foundation; we sometimes
5126make exceptions for this. Our decision will be guided by the two goals
5127of preserving the free status of all derivatives of our free software and
5128of promoting the sharing and reuse of software generally.
9c91ee3e 5129
54e4a398
RP
5130@iftex
5131@heading NO WARRANTY
5132@end iftex
5133@ifinfo
5134@center NO WARRANTY
5135@end ifinfo
9c91ee3e 5136
54e4a398
RP
5137@item
5138BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
5139FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN
5140OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
5141PROVIDE THE PROGRAM ``AS IS'' WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED
5142OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
5143MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS
5144TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE
5145PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,
5146REPAIR OR CORRECTION.
9c91ee3e 5147
54e4a398
RP
5148@item
5149IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL
5150ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
5151REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,
5152INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES
5153ARISING OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT
5154LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES
5155SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE
5156WITH ANY OTHER PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN
5157ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
5158@end enumerate
9c91ee3e 5159
54e4a398
RP
5160@iftex
5161@heading END OF TERMS AND CONDITIONS
5162@end iftex
5163@ifinfo
5164@center END OF TERMS AND CONDITIONS
5165@end ifinfo
9c91ee3e 5166
54e4a398 5167@page
cb9d2049 5168@unnumberedsec Applying These Terms to Your New Programs
9c91ee3e 5169
54e4a398
RP
5170 If you develop a new program, and you want it to be of the greatest
5171possible use to humanity, the best way to achieve this is to make it
5172free software which everyone can redistribute and change under these
5173terms.
9c91ee3e 5174
54e4a398
RP
5175 To do so, attach the following notices to the program. It is safest to
5176attach them to the start of each source file to most effectively convey
5177the exclusion of warranty; and each file should have at least the
5178``copyright'' line and a pointer to where the full notice is found.
9c91ee3e 5179
54e4a398
RP
5180@smallexample
5181@var{one line to give the program's name and a brief idea of what it does.}
5182Copyright (C) 19@var{yy} @var{name of author}
9c91ee3e 5183
54e4a398
RP
5184This program is free software; you can redistribute it and/or modify
5185it under the terms of the GNU General Public License as published by
5186the Free Software Foundation; either version 1, or (at your option)
5187any later version.
9c91ee3e 5188
54e4a398
RP
5189This program is distributed in the hope that it will be useful,
5190but WITHOUT ANY WARRANTY; without even the implied warranty of
5191MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
5192GNU General Public License for more details.
9c91ee3e 5193
54e4a398
RP
5194You should have received a copy of the GNU General Public License
5195along with this program; if not, write to the Free Software
5196Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
5197@end smallexample
4187119d 5198
54e4a398 5199Also add information on how to contact you by electronic and paper mail.
d2e08421 5200
54e4a398
RP
5201If the program is interactive, make it output a short notice like this
5202when it starts in an interactive mode:
d2e08421 5203
54e4a398
RP
5204@smallexample
5205Gnomovision version 69, Copyright (C) 19@var{yy} @var{name of author}
5206Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
5207This is free software, and you are welcome to redistribute it
5208under certain conditions; type `show c' for details.
5209@end smallexample
d2e08421 5210
54e4a398
RP
5211The hypothetical commands `show w' and `show c' should show the
5212appropriate parts of the General Public License. Of course, the
5213commands you use may be called something other than `show w' and `show
5214c'; they could even be mouse-clicks or menu items---whatever suits your
5215program.
d2e08421 5216
54e4a398
RP
5217You should also get your employer (if you work as a programmer) or your
5218school, if any, to sign a ``copyright disclaimer'' for the program, if
5219necessary. Here is a sample; alter the names:
d2e08421 5220
54e4a398
RP
5221@smallexample
5222Yoyodyne, Inc., hereby disclaims all copyright interest in the
5223program `Gnomovision' (a program to direct compilers to make passes
5224at assemblers) written by James Hacker.
d2e08421 5225
54e4a398
RP
5226@var{signature of Ty Coon}, 1 April 1989
5227Ty Coon, President of Vice
5228@end smallexample
d2e08421 5229
54e4a398 5230That's all there is to it!
d2e08421 5231
fe3f5fc8 5232@node Index,,,
d2e08421 5233@unnumbered Index
e91b87a3 5234
5235@printindex cp
5236
fe3f5fc8
RP
5237@tex
5238% I think something like @colophon should be in texinfo. In the
5239% meantime:
5240\long\def\colophon{\hbox to0pt{}\vfill
5241\centerline{The body of this manual is set in}
5242\centerline{\fontname\tenrm,}
5243\centerline{with headings in {\bf\fontname\tenbf}}
5244\centerline{and examples in {\tt\fontname\tentt}.}
5245\centerline{{\it\fontname\tenit\/} and}
5246\centerline{{\sl\fontname\tensl\/}}
5247\centerline{are used for emphasis.}\vfill}
5248\page\colophon
5249% Blame: [email protected], 28mar91.
5250@end tex
5251
e91b87a3 5252@contents
5253@bye
This page took 0.769018 seconds and 4 git commands to generate.