]> Git Repo - binutils.git/blame - gdb/doc/gdb.texinfo
* binutils.texinfo: minor typos, phrasing, formatting fixes.
[binutils.git] / gdb / doc / gdb.texinfo
CommitLineData
9bcc06ef
RP
1_dnl__ -*-Texinfo-*-
2_dnl__ Copyright (c) 1988 1989 1990 1991 Free Software Foundation, Inc.
e91b87a3 3\input texinfo
5a131cc7 4@setfilename _GDBP__.info
8734fc33 5@c $Id$
9c3ad547 6@c THIS MANUAL REQUIRES TEXINFO-2 macros and info-makers to format properly.
5a131cc7
RP
7@c
8@c NOTE: this manual is marked up for preprocessing with a collection
9@c of m4 macros called "pretex.m4". If you see <_if__> and <_fi__>
10@c scattered around the source, you have the full source before
11@c preprocessing; if you don't, you have the source configured for
12@c _HOST__ architectures (and you can of course get the full source,
13@c with all configurations, from wherever you got this).
14_if__(0)
15
9bcc06ef
RP
16THIS IS THE SOURCE PRIOR TO PREPROCESSING. The full source needs to
17be run through m4 before either tex- or info- formatting: for example,
08665207 18_0__
8734fc33 19 m4 pretex.m4 none.m4 m680x0.m4 gdb.texinfo >gdb-680x0.texinfo
08665207 20_1__
70b88761
RP
21will produce (assuming your path finds either GNU m4 >= 0.84, or SysV
22m4; Berkeley won't do) a file suitable for formatting. See the text in
23"pretex.m4" for a fuller explanation (and the macro definitions).
e91b87a3 24
9bcc06ef 25_fi__(0)
0e0fa7ce
RP
26@tex
27\def\$#1${{#1}} % Kluge: collect RCS revision info without $...$
28\xdef\manvers{\$Revision$} % For use in headers, footers too
0e0fa7ce 29@end tex
70b88761
RP
30@c
31@syncodeindex ky cp
32@c FOR UPDATES LEADING TO THIS DRAFT, GDB CHANGELOG CONSULTED BETWEEN:
3d3ab540 33@c Wed Jul 31 12:06:29 1991 John Gilmore (gnu at cygint.cygnus.com)
70b88761
RP
34@c Sat Dec 22 02:51:40 1990 John Gilmore (gnu at cygint)
35@ifinfo
36This file documents the GNU debugger _GDBN__.
37
38Copyright (C) 1988, 1989, 1990, 1991 Free Software Foundation, Inc.
39
40Permission is granted to make and distribute verbatim copies of
41this manual provided the copyright notice and this permission notice
42are preserved on all copies.
43
44@ignore
45Permission is granted to process this file through TeX and print the
46results, provided the printed document carries copying permission
47notice identical to this one except for the removal of this paragraph
48(this paragraph not being relevant to the printed manual).
49
50@end ignore
51Permission is granted to copy and distribute modified versions of this
52manual under the conditions for verbatim copying, provided also that the
53section entitled ``GNU General Public License'' is included exactly as
54in the original, and provided that the entire resulting derived work is
55distributed under the terms of a permission notice identical to this
56one.
57
58Permission is granted to copy and distribute translations of this manual
59into another language, under the above conditions for modified versions,
60except that the section entitled ``GNU General Public License'' may be
61included in a translation approved by the Free Software Foundation
62instead of in the original English.
63@end ifinfo
64@smallbook
65@setchapternewpage odd
66_if__(_GENERIC__)
67@settitle Using _GDBN__ (v4.0)
68_fi__(_GENERIC__)
69_if__(!_GENERIC__)
70@settitle Using _GDBN__ v4.0 (_HOST__)
71_fi__(!_GENERIC__)
72@iftex
73@finalout
74@end iftex
75@titlepage
76@title{Using _GDBN__}
77@subtitle{A Guide to the GNU Source-Level Debugger}
78_if__(!_GENERIC__)
79@subtitle{On _HOST__ Systems}
80_fi__(!_GENERIC__)
81@sp 1
82@c Maybe crank this up to "Fourth Edition" when released at FSF
83@c @subtitle Third Edition---_GDBN__ version 4.0
84@subtitle _GDBN__ version 4.0
54e6b3c3 85@subtitle July 1991
70b88761
RP
86@author{Richard M. Stallman@qquad @hfill Free Software Foundation}
87@author{Roland H. Pesch@qquad @hfill Cygnus Support}
88@page
89@tex
90{\parskip=0pt
91\hfill rms\@ai.mit.edu, pesch\@cygnus.com\par
92\hfill {\it Using _GDBN__}, \manvers\par
93\hfill \TeX{}info \texinfoversion\par
94}
95@end tex
96
97@vskip 0pt plus 1filll
98Copyright @copyright{} 1988, 1989, 1990, 1991 Free Software Foundation, Inc.
99
100Permission is granted to make and distribute verbatim copies of
101this manual provided the copyright notice and this permission notice
102are preserved on all copies.
103
104Permission is granted to copy and distribute modified versions of this
105manual under the conditions for verbatim copying, provided also that the
106section entitled ``GNU General Public License'' is included exactly as
107in the original, and provided that the entire resulting derived work is
108distributed under the terms of a permission notice identical to this
109one.
110
111Permission is granted to copy and distribute translations of this manual
112into another language, under the above conditions for modified versions,
113except that the section entitled ``GNU General Public License'' may be
114included in a translation approved by the Free Software Foundation
115instead of in the original English.
116@end titlepage
117@page
118
119@node Top, Summary, (dir), (dir)
120@ifinfo
121This file describes version 4.0 of GDB, the GNU symbolic debugger.
122@end ifinfo
123
124@menu
125* Summary:: Summary of _GDBN__
126* New Features:: New Features in _GDBN__ version 4.0
127* Sample Session:: A Sample _GDBN__ Session
128* Invocation:: Getting In and Out of _GDBN__
129* Commands::
130* Running:: Running Programs Under _GDBN__
131* Stopping:: Stopping and Continuing
132* Stack:: Examining the Stack
133* Source:: Examining Source Files
134* Data:: Examining Data
135* Symbols:: Examining the Symbol Table
136* Altering:: Altering Execution
137* _GDBN__ Files::
138* Targets:: Specifying a Debugging Target
139* Controlling _GDBN__:: Controlling _GDBN__
140* Sequences:: Canned Sequences of Commands
141* Emacs:: Using _GDBN__ under GNU Emacs
142* _GDBN__ Bugs:: Reporting Bugs in _GDBN__
143* Renamed Commands::
144* Installing _GDBN__:: Installing _GDBN__
145* Copying:: GNU GENERAL PUBLIC LICENSE
146* Index:: Index
147 --- The Detailed Node Listing ---
148
149Summary of _GDBN__
150
151* Free Software:: Free Software
152* Contributors:: Contributors to _GDBN__
153
154Getting In and Out of _GDBN__
155
156* Starting _GDBN__:: Starting _GDBN__
157* Leaving _GDBN__:: Leaving _GDBN__
158* Shell Commands:: Shell Commands
159
160Starting _GDBN__
161
162* File Options:: Choosing Files
163* Mode Options:: Choosing Modes
164
165_GDBN__ Commands
166
167* Command Syntax:: Command Syntax
168* Help:: Getting Help
169
170Running Programs Under _GDBN__
171
172* Compilation:: Compiling for Debugging
173* Starting:: Starting your Program
174* Arguments:: Your Program's Arguments
175* Environment:: Your Program's Environment
176* Working Directory:: Your Program's Working Directory
177* Input/Output:: Your Program's Input and Output
178* Attach:: Debugging an Already-Running Process
179* Kill Process:: Killing the Child Process
180
181Stopping and Continuing
182
183* Breakpoints:: Breakpoints, Watchpoints, and Exceptions
3d3ab540 184* Continuing and Stepping:: Resuming Execution
70b88761
RP
185* Signals:: Signals
186
187Breakpoints, Watchpoints, and Exceptions
188
189* Set Breaks:: Setting Breakpoints
190* Set Watchpoints:: Setting Watchpoints
191* Exception Handling:: Breakpoints and Exceptions
192* Delete Breaks:: Deleting Breakpoints
193* Disabling:: Disabling Breakpoints
194* Conditions:: Break Conditions
195* Break Commands:: Breakpoint Command Lists
196* Breakpoint Menus:: Breakpoint Menus
197* Error in Breakpoints::
198
199Examining the Stack
200
201* Frames:: Stack Frames
202* Backtrace:: Backtraces
203* Selection:: Selecting a Frame
204* Frame Info:: Information on a Frame
205
206Examining Source Files
207
208* List:: Printing Source Lines
209* Search:: Searching Source Files
210* Source Path:: Specifying Source Directories
211* Machine Code:: Source and Machine Code
212
213Examining Data
214
215* Expressions:: Expressions
216* Variables:: Program Variables
217* Arrays:: Artificial Arrays
218* Output formats:: Output formats
219* Memory:: Examining Memory
220* Auto Display:: Automatic Display
221* Print Settings:: Print Settings
222* Value History:: Value History
223* Convenience Vars:: Convenience Variables
224* Registers:: Registers
225* Floating Point Hardware:: Floating Point Hardware
226
227Altering Execution
228
229* Assignment:: Assignment to Variables
230* Jumping:: Continuing at a Different Address
231* Signaling:: Giving the Program a Signal
232* Returning:: Returning from a Function
233* Calling:: Calling your Program's Functions
234
235_GDBN__'s Files
236
237* Files:: Commands to Specify Files
238* Symbol Errors:: Errors Reading Symbol Files
239
240Specifying a Debugging Target
241
242* Active Targets:: Active Targets
243* Target Commands:: Commands for Managing Targets
244* Remote:: Remote Debugging
245
246Remote Debugging
247
248* i960-Nindy Remote::
249* EB29K Remote::
250* VxWorks Remote::
251
252_GDBN__ with a Remote i960 (Nindy)
253
254* Nindy Startup:: Startup with Nindy
255* Nindy Options:: Options for Nindy
256* Nindy reset:: Nindy Reset Command
257
258_GDBN__ with a Remote EB29K
259
260* Comms (EB29K):: Communications Setup
261* gdb-EB29K:: EB29K cross-debugging
262* Remote Log:: Remote Log
263
264_GDBN__ and VxWorks
265
266* VxWorks connection:: Connecting to VxWorks
267* VxWorks download:: VxWorks Download
268* VxWorks attach:: Running Tasks
269
270Controlling _GDBN__
271
272* Prompt:: Prompt
273* Editing:: Command Editing
274* History:: Command History
275* Screen Size:: Screen Size
276* Numbers:: Numbers
277* Messages/Warnings:: Optional Warnings and Messages
278
279Canned Sequences of Commands
280
281* Define:: User-Defined Commands
282* Command Files:: Command Files
283* Output:: Commands for Controlled Output
284
285Reporting Bugs in _GDBN__
286
287* Bug Criteria:: Have You Found a Bug?
288* Bug Reporting:: How to Report Bugs
289@end menu
290
291@node Summary, New Features, Top, Top
292@unnumbered Summary of _GDBN__
293
294The purpose of a debugger such as _GDBN__ is to allow you to see what is
295going on ``inside'' another program while it executes---or what another
296program was doing at the moment it crashed.
297
298_GDBN__ can do four main kinds of things (plus other things in support of
299these) to help you catch bugs in the act:
300
301@itemize @bullet
302@item
303Start your program, specifying anything that might affect its behavior.
304
305@item
306Make your program stop on specified conditions.
307
308@item
309Examine what has happened, when your program has stopped.
310
311@item
312Change things in your program, so you can experiment with correcting the
313effects of one bug and go on to learn about another.
314@end itemize
315
316_GDBN__ can be used to debug programs written in C and C++. Pascal support
317is being implemented, and Fortran support will be added when a GNU
318Fortran compiler is ready.
319
320@menu
321* Free Software:: Free Software
322* Contributors:: Contributors to GDB
323@end menu
324
325@node Free Software, Contributors, Summary, Summary
326@unnumberedsec Free Software
327_GDBN__ is @dfn{free software}, protected by the GNU General Public License (GPL).
328The GPL gives you the freedom to copy or adapt a licensed
329program---but every person getting a copy also gets with it the
330freedom to modify that copy (which means that they must get access to
331the source code), and the freedom to distribute further copies.
332Typical software companies use copyrights to limit your freedoms; the
333Free Software Foundation uses the GPL to preserve these freedoms.
334
335Fundamentally, the General Public License is a license which says that
336you have these freedoms and that you can't take these freedoms away
337from anyone else.
338
339@c FIXME: (passim) go through all xrefs, expanding to use text headings
340For full details, @pxref{Copying}.
341@node Contributors, , Free Software, Summary
342@unnumberedsec Contributors to GDB
343
344Richard Stallman was the original author of GDB, and of many other GNU
345programs. Many others have contributed to its development. This
346section attempts to credit major contributors. One of the virtues of
347free software is that everyone is free to contribute to it; with
348regret, we cannot actually acknowledge everyone here. The file
349@file{ChangeLog} in the GDB distribution approximates a blow-by-blow
350account.
351
352Changes much prior to version 2.0 are lost in the mists of time.
353
354@quotation
355@emph{Plea:} Additions to this section are particularly welcome. If you
356or your friends (or enemies; let's be evenhanded) have been unfairly
357omitted from this list, we would like to add your names!
358@end quotation
359
360So that they may not regard their long labor as thankless, we
361particularly thank those who shepherded GDB through major releases:
362John Gilmore (release 4.0); Jim Kingdon (releases 3.9, 3.5, 3.4, 3.3);
363and Randy Smith (releases 3.2, 3.1, 3.0). As major maintainer of GDB
364for some period, each contributed significantly to the structure,
365stability, and capabilities of the entire debugger.
366
367Richard Stallman, assisted at various times by Pete TerMaat, Chris
368Hanson, and Richard Mlynarik, handled releases through 2.8.
369
370Michael Tiemann is the author of most of the GNU C++ support in GDB,
371with significant additional contributions from Per Bothner. James
372Clark wrote the GNU C++ demangler. Early work on C++ was by Peter
373TerMaat (who also did much general update work leading to release 3.0).
374
375GDB 4.0 uses the BFD subroutine library to examine multiple
376object-file formats; BFD was a joint project of V. Gumby
377Henkel-Wallace, Rich Pixley, Steve Chamberlain, and John Gilmore.
378
379David Johnson wrote the original COFF support; Pace Willison did
380the original support for encapsulated COFF.
381
382Adam de Boor and Bradley Davis contributed the ISI Optimum V support.
383Per Bothner, Noboyuki Hikichi, and Alessandro Forin contributed MIPS
384support. Jean-Daniel Fekete contributed Sun 386i support. Chris
385Hanson improved the HP9000 support. Noboyuki Hikichi and Tomoyuki
386Hasei contributed Sony/News OS 3 support. David Johnson contributed
387Encore Umax support. Jyrki Kuoppala contributed Altos 3068 support.
388Keith Packard contributed NS32K support. Doug Rabson contributed
389Acorn Risc Machine support. Chris Smith contributed Convex support
390(and Fortran debugging). Jonathan Stone contributed Pyramid support.
391Michael Tiemann contributed SPARC support. Tim Tucker contributed
392support for the Gould NP1 and Gould Powernode. Pace Willison
393contributed Intel 386 support. Jay Vosburgh contributed Symmetry
394support.
395
396Rich Schaefer helped with support of SunOS shared libraries.
397
398Jay Fenlason and Roland McGrath ensured that GDB and GAS agree about
399several machine instruction sets.
400
401Patrick Duval, Ted Goldstein, Vikram Koka and Glenn Engel helped
402develop remote debugging. Intel Corporation and Wind River Systems
403contributed remote debugging modules for their products.
404
405Brian Fox is the author of the readline libraries providing
406command-line editing and command history.
407
408@node New Features, Sample Session, Summary, Top
409@unnumbered New Features since _GDBN__ version 3.5
410
411@table @emph
412@item Targets
413Using the new command @code{target}, you can select at runtime whether
414you are debugging local files, local processes, standalone systems over
415a serial port, realtime systems over a TCP/IP connection, etc.
416Internally, _GDBN__ now uses a function vector to mediate access to
417different targets; if you need to add your own support for a remote
418protocol, this makes it much easier.
419
420@item Watchpoints
421_GDBN__ now sports watchpoints as well as breakpoints. You can use a
422watchpoint to stop execution whenever the value of an expression
423changes, without having to predict a particular place in your program
424where this may happen.
425
426@item Object Code Formats
3d3ab540
RP
427_GDBN__ uses a new scheme called the Binary File Descriptor (BFD)
428Library to permit it to switch dynamically, without reconfiguration or
429recompilation, between different object-file formats. Formats currently
430supported are COFF, a.out, and the Intel 960 b.out; files may be read as
431.o's, archive libraries, or core dumps. BFD is available as a
432subroutine library so that other programs may take advantage of it, and
433the other GNU binary utilities are being converted to use it.
70b88761
RP
434
435@item Configuration
436Compile-time configuration (to select a particular architecture and
7463aadd 437operating system) is much easier. The script @code{configure} now
3d3ab540
RP
438allows you to configure _GDBN__ as either a native debugger or a
439cross-debugger.
70b88761
RP
440
441@item Interaction
442The user interface to _GDBN__'s control variables has been simplified
443and consolidated in two commands, @code{set} and @code{show}. Output
444lines are now broken at readable places, rather than overflowing onto
445the next line. You can suppress output of machine-level addresses,
446displaying only source language information.
447
448
449@item Source Language
450_GDBN__ now has limited support for C++ exception handling: _GDBN__ can
451break when an exception is raised, before the stack is peeled back to
452the exception handler's context.
453
454@item Command Rationalization
455Many _GDBN__ commands have been renamed to make them easier to remember
456and use. In particular, the subcommands of @code{info} and
457@code{show}/@code{set} are grouped to make the former refer to the state
458of your program, and the latter refer to the state of _GDBN__ itself.
459@xref{Renamed Commands}, for details on what commands were renamed.
460
461@item Ports
462_GDBN__ has been ported to the following new architectures: AT&T 3b1,
463Acorn RISC machine, HP300 running HPUX, big- and little-endian MIPS
464machines, Motorola 88k, Sun 386i, and Sun 3 running SunOS 4. In
465addition, the following are supported as targets only: AMD 29k, Intel
466960, and Wind River's VxWorks.
467
468@item Shared Libraries
469_GDBN__ 4.0 supports SunOS shared libraries.
470
471@item Work in Progress
472Kernel debugging for BSD and Mach systems; Tahoe and HPPA architecture
473support.
474
475@end table
476
477@node Sample Session, Invocation, New Features, Top
478@chapter A Sample _GDBN__ Session
479
480You can use this manual at your leisure to read all about _GDBN__.
481However, a handful of commands are enough to get started using the
482debugger. This chapter illustrates these commands.
483
484@iftex
485In this sample session, we emphasize user input like this: @i{input},
486to make it easier to pick out from the surrounding output.
487@end iftex
488
489@c FIXME: this example may not be appropriate for some configs, where
490@c FIXME...primary interest is in remote use.
491_0__
492One of the preliminary versions of GNU @code{m4} (a generic macro
493processor) exhibits the following bug: sometimes, when we change its
494quote strings from the default, the commands used to capture one macro's
495definition in another stop working. In the following short @code{m4}
496session, we define a macro @code{foo} which expands to @code{0000}; we
497then use the @code{m4} builtin @code{defn} to define @code{bar} as the
498same thing. However, when we change the open quote string to
499@code{<QUOTE>} and the close quote string to @code{<UNQUOTE>}, the same
500procedure fails to define a new synonym @code{baz}:
501
502@smallexample
503$ @i{cd gnu/m4}
504$ @i{./m4}
505@i{define(foo,0000)}
506
507@i{foo}
5080000
509@i{define(bar,defn(`foo'))}
510
511@i{bar}
5120000
513@i{changequote(<QUOTE>,<UNQUOTE>)}
514
515@i{define(baz,defn(<QUOTE>foo<UNQUOTE>))}
516@i{baz}
517@i{C-d}
518m4: End of input: 0: fatal error: EOF in string
519@end smallexample
520
521@noindent
522Let's use _GDBN__ to try to see what's going on.
523
524@smallexample
525$ @i{_GDBP__ m4}
526Reading symbol data from m4...done.
527(_GDBP__)
528@end smallexample
529
530@noindent
531_GDBN__ reads only enough symbol data to know where to find the rest
532when needed; as a result, the first prompt comes up very quickly. We
533then tell _GDBN__ to use a narrower display width than usual, so
534that examples will fit in this manual.
535
536@smallexample
537(_GDBP__) @i{set width 70}
538@end smallexample
539
540@noindent
541Let's see how the @code{m4} builtin @code{changequote} works.
542Having looked at the source, we know the relevant subroutine is
543@code{m4_changequote}, so we set a breakpoint there with _GDBN__'s
544@code{break} command.
545
546@smallexample
547(_GDBP__) @i{break m4_changequote}
548Breakpoint 1 at 0x62f4: file builtin.c, line 879.
549@end smallexample
550
551@noindent
552Using the @code{run} command, we start @code{m4} running under _GDBN__
553control; as long as control does not reach the @code{m4_changequote}
554subroutine, the program runs as usual:
555
556@smallexample
557(_GDBP__) @i{run}
558Starting program: /work/Editorial/gdb/gnu/m4/m4
559@i{define(foo,0000)}
560
561@i{foo}
5620000
563@end smallexample
564
565@noindent
566To trigger the breakpoint, we call @code{changequote}. _GDBN__
567suspends execution of @code{m4}, displaying information about the
568context where it stops.
569
570@smallexample
571@i{changequote(<QUOTE>,<UNQUOTE>)}
572
573Breakpoint 1, m4_changequote (argc=3, argv=0x33c70) at builtin.c:879
574879 if (bad_argc(TOKEN_DATA_TEXT(argv[0]), argc, 1, 3))
575@end smallexample
576
577@noindent
578Now we use the command @code{n} (@code{next}) to advance execution to
579the next line of the current function.
580
581@smallexample
582(_GDBP__) @i{n}
583882 set_quotes((argc >= 2) ? TOKEN_DATA_TEXT(argv[1]) : nil,
584@end smallexample
585
586@noindent
587@code{set_quotes} looks like a promising subroutine. We can go into it
588by using the command @code{s} (@code{step}) instead of @code{next}.
589@code{step} goes to the next line to be executed in @emph{any}
590subroutine, so it steps into @code{set_quotes}.
591
592@smallexample
593(_GDBP__) @i{s}
594set_quotes (lq=0x34c78 "<QUOTE>", rq=0x34c88 "<UNQUOTE>")
595 at input.c:530
596530 if (lquote != def_lquote)
597@end smallexample
598
599@noindent
600The summary display showing the subroutine where @code{m4} is now
601suspended (and its arguments) is called a stack frame display. We can
602use the @code{backtrace} command (which can also be spelled @code{bt}),
603to see where we are in the stack: it displays a stack frame for each
604active subroutine.
605
606@smallexample
607(_GDBP__) @i{bt}
608#0 set_quotes (lq=0x34c78 "<QUOTE>", rq=0x34c88 "<UNQUOTE>")
609 at input.c:530
610#1 0x6344 in m4_changequote (argc=3, argv=0x33c70) at builtin.c:882
611#2 0x8174 in expand_macro (sym=0x33320) at macro.c:242
612#3 0x7a88 in expand_token (obs=0x0, t=209696, td=0xf7fffa30)
613 at macro.c:71
614#4 0x79dc in expand_input () at macro.c:40
615#5 0x2930 in main (argc=0, argv=0xf7fffb20) at m4.c:195
616@end smallexample
617
618@noindent
619Let's step through a few more lines to see what happens. The first two
620times, we can use @samp{s}; the next two times we use @code{n} to avoid
621falling into the @code{xstrdup} subroutine.
622@smallexample
623(_GDBP__) @i{s}
6240x3b5c 532 if (rquote != def_rquote)
625(_GDBP__) @i{s}
6260x3b80 535 lquote = (lq == nil || *lq == '\0') ? def_lquote :\
627 xstrdup(lq);
628(_GDBP__) @i{n}
629536 rquote = (rq == nil || *rq == '\0') ? def_rquote : xstrdup\
630(rq);
631(_GDBP__) @i{n}
632538 len_lquote = strlen(rquote);
633@end smallexample
634
635@noindent
636The last line displayed looks a little odd; let's examine the variables
637@code{lquote} and @code{rquote} to see if they are in fact the new left
638and right quotes we specified. We can use the command @code{p}
639(@code{print}) to see their values.
640
641@smallexample
642(_GDBP__) @i{p lquote}
643$1 = 0x35d40 "<QUOTE>"
644(_GDBP__) @i{p rquote}
645$2 = 0x35d50 "<UNQUOTE>"
646@end smallexample
647
648@noindent
649@code{lquote} and @code{rquote} are indeed the new left and right quotes.
650Let's look at some context; we can display ten lines of source
651surrounding the current line, with the @code{l} (@code{list}) command.
652
653@smallexample
654(_GDBP__) @i{l}
655533 xfree(rquote);
656534
657535 lquote = (lq == nil || *lq == '\0') ? def_lquote : xstrdup\
658(lq);
659536 rquote = (rq == nil || *rq == '\0') ? def_rquote : xstrdup\
660(rq);
661537
662538 len_lquote = strlen(rquote);
663539 len_rquote = strlen(lquote);
664540 @}
665541
666542 void
667@end smallexample
668
669@noindent
670Let's step past the two lines that set @code{len_lquote} and
671@code{len_rquote}, and then examine the values of those variables.
672
673@smallexample
674(_GDBP__) @i{n}
675539 len_rquote = strlen(lquote);
676(_GDBP__) @i{n}
677540 @}
678(_GDBP__) @i{p len_lquote}
679$3 = 9
680(_GDBP__) @i{p len_rquote}
681$4 = 7
682@end smallexample
683
684@noindent
685That certainly looks wrong, assuming @code{len_lquote} and
686@code{len_rquote} are meant to be the lengths of @code{lquote} and
687@code{rquote} respectively. Let's try setting them to better values.
688We can use the @code{p} command for this, since it'll print the value of
689any expression---and that expression can include subroutine calls and
690assignments.
691
692@smallexample
693(_GDBP__) p len_lquote=strlen(lquote)
694$5 = 7
695(_GDBP__) p len_rquote=strlen(rquote)
696$6 = 9
697@end smallexample
698
699@noindent
700Let's see if that fixes the problem of using the new quotes with the
701@code{m4} built-in @code{defn}. We can allow @code{m4} to continue
702executing with the @code{c} (@code{continue}) command, and then try the
703example that caused trouble initially:
704
705@smallexample
706(_GDBP__) @i{c}
707Continuing.
708
709@i{define(baz,defn(<QUOTE>foo<UNQUOTE>))}
710
711baz
7120000
713@end smallexample
714
715@noindent
716Success! The new quotes now work just as well as the default ones. The
717problem seems to have been just the two typos defining the wrong
718lengths. We'll let @code{m4} exit by giving it an EOF as input.
719
720@smallexample
721@i{C-d}
722Program exited normally.
723@end smallexample
724
725@noindent
726The message @samp{Program exited normally.} is from _GDBN__; it
727indicates @code{m4} has finished executing. We can end our _GDBN__
728session with the _GDBN__ @code{quit} command.
729
730@smallexample
731(_GDBP__) @i{quit}
70b88761
RP
732_1__@end smallexample
733
734@node Invocation, Commands, Sample Session, Top
735@chapter Getting In and Out of _GDBN__
736
737@menu
738* Starting _GDBN__:: Starting _GDBN__
739* Leaving _GDBN__:: Leaving _GDBN__
740* Shell Commands:: Shell Commands
741@end menu
742
743@node Starting _GDBN__, Leaving _GDBN__, Invocation, Invocation
744@section Starting _GDBN__
745
746_GDBN__ is invoked with the shell command @code{_GDBP__}. Once started,
747it reads commands from the terminal until you tell it to exit.
748
749You can run @code{_GDBP__} with no arguments or options; but the most
750usual way to start _GDBN__ is with one argument or two, specifying an
751executable program as the argument:
752@example
753_GDBP__ program
754@end example
755@noindent
756You can also start with both an executable program and a core file specified:
757@example
758_GDBP__ program core
759@end example
760
761@noindent
762You can further control how _GDBN__ starts up by using command-line
763options. _GDBN__ itself can remind you of the options available:
764@example
765_GDBP__ -help
766@end example
767@noindent
768will display all available options and briefly describe their use
769(@samp{_GDBP__ -h} is a shorter equivalent).
770
771All options and command line arguments you give are processed
772in sequential order. The order makes a difference when the
773@samp{-x} option is used.
774
775@menu
776* File Options:: Choosing Files
777* Mode Options:: Choosing Modes
778_if__(!_GENERIC__)
779_include__(gdbinv-m.m4)_dnl__
780_fi__(!_GENERIC__)
781@end menu
782
783@node File Options, Mode Options, Starting _GDBN__, Starting _GDBN__
784@subsection Choosing Files
785
786As shown above, any arguments other than options specify an executable
787file and core file; that is, the first argument encountered with no
788associated option flag is equivalent to a @samp{-se} option, and the
789second, if any, is equivalent to a @samp{-c} option. Many options have
790both long and short forms; both are shown here. The long forms are also
791recognized if you truncate them, so long as enough of the option is
792present to be unambiguous. (If you prefer, you can flag option
793arguments with @samp{+} rather than @samp{-}, though we illustrate the
794more usual convention.)
795
796@table @code
797@item -symbols=@var{file}
798@itemx -s @var{file}
799Read symbol table from file @var{file}.
800
801@item -exec=@var{file}
802@itemx -e @var{file}
803Use file @var{file} as the executable file to execute when
804appropriate, and for examining pure data in conjunction with a core
805dump.
806
3d3ab540 807@item -se=@var{file}
70b88761
RP
808Read symbol table from file @var{file} and use it as the executable
809file.
810
811@item -core=@var{file}
812@itemx -c @var{file}
813Use file @var{file} as a core dump to examine.
814
815@item -command=@var{file}
816@itemx -x @var{file}
817Execute _GDBN__ commands from file @var{file}. @xref{Command Files}.
818
819@item -directory=@var{directory}
820@itemx -d @var{directory}
821Add @var{directory} to the path to search for source files.
822@end table
823
824_if__(!_GENERIC__)
825@node Mode Options, i960-Nindy Remote, File Options, Starting _GDBN__
826_fi__(!_GENERIC__)
827_if__(_GENERIC__)
828@node Mode Options, , File Options, Starting _GDBN__
829_fi__(_GENERIC__)
830@subsection Choosing Modes
831
832@table @code
833@item -nx
834@itemx -n
835Do not execute commands from any @file{_GDBINIT__} initialization files.
836Normally, the commands in these files are executed after all the
837command options and arguments have been processed. @xref{Command
838Files}.
839
840@item -quiet
841@itemx -q
842``Quiet''. Do not print the introductory and copyright messages. These
843messages are also suppressed in batch mode, or if an executable file name is
844specified on the _GDBN__ command line.
845
846@item -batch
847Run in batch mode. Exit with status @code{0} after processing all the command
848files specified with @samp{-x} (and @file{_GDBINIT__}, if not inhibited).
849Exit with nonzero status if an error occurs in executing the _GDBN__
850commands in the command files.
851
852Batch mode may be useful for running _GDBN__ as a filter, for example to
853download and run a program on another computer; in order to make this
854more useful, the message
855@example
856Program exited normally.
857@end example
858@noindent
859(which is ordinarily issued whenever a program running under _GDBN__ control
860terminates) is not issued when running in batch mode.
861
3d3ab540 862@item -cd=@var{directory}
70b88761
RP
863Run _GDBN__ using @var{directory} as its working directory,
864instead of the current directory.
865
866@item -fullname
867@itemx -f
868Emacs sets this option when it runs _GDBN__ as a subprocess. It tells _GDBN__
869to output the full file name and line number in a standard,
870recognizable fashion each time a stack frame is displayed (which
871includes each time the program stops). This recognizable format looks
872like two @samp{\032} characters, followed by the file name, line number
873and character position separated by colons, and a newline. The
874Emacs-to-_GDBN__ interface program uses the two @samp{\032} characters as
875a signal to display the source code for the frame.
876
877@item -b @var{bps}
878Set the line speed (baud rate or bits per second) of any serial
879interface used by _GDBN__ for remote debugging.
880
3d3ab540 881@item -tty=@var{device}
70b88761
RP
882Run using @var{device} for your program's standard input and output.
883@c FIXME: kingdon thinks there's more to -tty. Investigate.
884@end table
885
886_if__(!_GENERIC__)
887_include__(gdbinv-s.m4)
888_fi__(!_GENERIC__)
889
890@node Leaving _GDBN__, Shell Commands, Starting _GDBN__, Invocation
891@section Leaving _GDBN__
892@cindex exiting _GDBN__
893@table @code
894@item quit
895@kindex quit
896@kindex q
897To exit _GDBN__, use the @code{quit} command (abbreviated @code{q}), or type
898an end-of-file character (usually @kbd{C-d}).
899@end table
900
901@cindex interrupt
902An interrupt (often @kbd{C-c}) will not exit from _GDBN__, but rather
903will terminate the action of any _GDBN__ command that is in progress and
904return to _GDBN__ command level. It is safe to type the interrupt
905character at any time because _GDBN__ does not allow it to take effect
906until a time when it is safe.
907
908If you've been using _GDBN__ to control an attached process or device,
909you can release it with the @code{detach} command; @pxref{Attach}.
910
911@node Shell Commands, , Leaving _GDBN__, Invocation
912@section Shell Commands
913If you need to execute occasional shell commands during your
914debugging session, there's no need to leave or suspend _GDBN__; you can
915just use the @code{shell} command.
916
917@table @code
918@item shell @var{command string}
919@kindex shell
920@cindex shell escape
921Directs _GDBN__ to invoke an inferior shell to execute @var{command
922string}. If it exists, the environment variable @code{SHELL} is used
923for the name of the shell to run. Otherwise _GDBN__ uses
924@code{/bin/sh}.
925@end table
926
927The utility @code{make} is often needed in development environments.
928You don't have to use the @code{shell} command for this purpose in _GDBN__:
929
930@table @code
931@item make @var{make-args}
932@kindex make
933@cindex calling make
934Causes _GDBN__ to execute an inferior @code{make} program with the specified
935arguments. This is equivalent to @samp{shell make @var{make-args}}.
936@end table
937
938@node Commands, Running, Invocation, Top
939@chapter _GDBN__ Commands
940
941@menu
942* Command Syntax:: Command Syntax
943* Help:: Getting Help
944@end menu
945
946@node Command Syntax, Help, Commands, Commands
947@section Command Syntax
948A _GDBN__ command is a single line of input. There is no limit on how long
949it can be. It starts with a command name, which is followed by arguments
950whose meaning depends on the command name. For example, the command
951@code{step} accepts an argument which is the number of times to step,
952as in @samp{step 5}. You can also use the @code{step} command with
953no arguments. Some command names do not allow any arguments.
954
955@cindex abbreviation
956_GDBN__ command names may always be truncated if that abbreviation is
957unambiguous. Other possible command abbreviations are listed in the
958documentation for individual commands. In some cases, even ambiguous
959abbreviations are allowed; for example, @code{s} is specially defined as
960equivalent to @code{step} even though there are other commands whose
961names start with @code{s}. You can test abbreviations by using them as
7463aadd 962arguments to the @code{help} command.
70b88761
RP
963
964@cindex repeating commands
965@kindex RET
966A blank line as input to _GDBN__ (typing just @key{RET}) means to
967repeat the previous command. Certain commands (for example, @code{run})
968will not repeat this way; these are commands for which unintentional
969repetition might cause trouble and which you are unlikely to want to
970repeat.
971
972The @code{list} and @code{x} commands, when you repeat them with
973@key{RET}, construct new arguments rather than repeating
974exactly as typed. This permits easy scanning of source or memory.
975
976@kindex #
977@cindex comment
978A line of input starting with @kbd{#} is a comment; it does nothing.
979This is useful mainly in command files (@xref{Command Files}).
980
981@node Help, , Command Syntax, Commands
982@section Getting Help
983@cindex online documentation
984@kindex help
985You can always ask _GDBN__ itself for information on its commands, using the
986command @code{help}.
987
988@table @code
989@item help
990@itemx h
991@kindex h
992You can use @code{help} (abbreviated @code{h}) with no arguments to
993display a short list of named classes of commands:
994@smallexample
995(_GDBP__) help
996List of classes of commands:
997
998running -- Running the program
999stack -- Examining the stack
1000data -- Examining data
1001breakpoints -- Making program stop at certain points
1002files -- Specifying and examining files
1003status -- Status inquiries
1004support -- Support facilities
1005user-defined -- User-defined commands
1006aliases -- Aliases of other commands
1007obscure -- Obscure features
1008
1009Type "help" followed by a class name for a list of commands in that class.
1010Type "help" followed by command name for full documentation.
1011Command name abbreviations are allowed if unambiguous.
1012(_GDBP__)
1013@end smallexample
1014
1015@item help @var{class}
1016Using one of the general help classes as an argument, you can get a
1017list of the individual commands in that class. For example, here is the
1018help display for the class @code{status}:
1019@smallexample
1020(_GDBP__) help status
1021Status inquiries.
1022
1023List of commands:
1024
1025show -- Generic command for showing things set with "set"
1026info -- Generic command for printing status
1027
1028Type "help" followed by command name for full documentation.
1029Command name abbreviations are allowed if unambiguous.
1030(_GDBP__)
1031@end smallexample
1032
1033@item help @var{command}
1034With a command name as @code{help} argument, _GDBN__ will display a
1035short paragraph on how to use that command.
1036@end table
1037
1038In addition to @code{help}, you can use the _GDBN__ commands @code{info}
1039and @code{show} to inquire about the state of your program, or the state
1040of _GDBN__ itself. Each command supports many topics of inquiry; this
1041manual introduces each of them in the appropriate context. The listings
1042under @code{info} and under @code{show} in the Index point to
1043all the sub-commands.
1044@c FIXME: @pxref{Index} used to be here, but even though it shows up in
1045@c FIXME...the 'aux' file with a pageno the xref can't find it.
1046
1047@c @group
1048@table @code
1049@item info
1050@kindex info
1051@kindex i
1052This command (abbreviated @code{i}) is for describing the state of your
1053program; for example, it can list the arguments given to your program
1054(@code{info args}), the registers currently in use (@code{info
1055registers}), or the breakpoints you've set (@code{info breakpoints}).
1056You can get a complete list of the @code{info} sub-commands with
1057@w{@code{help info}}.
1058
1059@kindex show
1060@item show
1061In contrast, @code{show} is for describing the state of _GDBN__ itself.
1062You can change most of the things you can @code{show}, by using the
1063related command @code{set}; for example, you can control what number
1064system is used for displays with @code{set radix}, or simply inquire
1065which is currently in use with @code{show radix}.
1066
1067@kindex info set
1068To display all the settable parameters and their current
1069values, you can use @code{show} with no arguments; you may also use
1070@code{info set}. Both commands produce the same display.
1071@c FIXME: "info set" violates the rule that "info" is for state of
1072@c FIXME...program. Ck w/ GNU: "info set" to be called something else,
1073@c FIXME...or change desc of rule---eg "state of prog and debugging session"?
1074@end table
1075@c @end group
1076
1077Here are three miscellaneous @code{show} subcommands, all of which are
1078exceptional in lacking corresponding @code{set} commands:
1079
1080@table @code
1081@kindex show version
3d3ab540 1082@cindex version number
70b88761
RP
1083@item show version
1084Show what version of _GDBN__ is running. You should include this
1085information in _GDBN__ bug-reports. If multiple versions of _GDBN__ are
1086in use at your site, you may occasionally want to make sure what version
1087of _GDBN__ you're running; as _GDBN__ evolves, new commands are
1088introduced, and old ones may wither away. The version number is also
1089announced when you start _GDBN__ with no arguments.
1090
1091@kindex show copying
1092@item show copying
1093Display information about permission for copying _GDBN__.
1094
1095@kindex show warranty
1096@item show warranty
1097Display the GNU ``NO WARRANTY'' statement.
1098@end table
1099
1100@node Running, Stopping, Commands, Top
1101@chapter Running Programs Under _GDBN__
1102
1103@menu
1104* Compilation:: Compiling for Debugging
1105* Starting:: Starting your Program
1106* Arguments:: Your Program's Arguments
1107* Environment:: Your Program's Environment
1108* Working Directory:: Your Program's Working Directory
1109* Input/Output:: Your Program's Input and Output
1110* Attach:: Debugging an Already-Running Process
1111* Kill Process:: Killing the Child Process
1112@end menu
1113
1114@node Compilation, Starting, Running, Running
1115@section Compiling for Debugging
1116
1117In order to debug a program effectively, you need to generate
1118debugging information when you compile it. This debugging information
1119is stored in the object file; it describes the data type of each
1120variable or function and the correspondence between source line numbers
1121and addresses in the executable code.
1122
1123To request debugging information, specify the @samp{-g} option when you run
1124the compiler.
1125
1126Many C compilers are unable to handle the @samp{-g} and @samp{-O}
1127options together. Using those compilers, you cannot generate optimized
1128executables containing debugging information.
1129
1130The GNU C compiler supports @samp{-g} with or without @samp{-O}, making it
1131possible to debug optimized code. We recommend that you @emph{always} use
1132@samp{-g} whenever you compile a program. You may think the program is
1133correct, but there's no sense in pushing your luck.
1134
1135Some things do not work as well with @samp{-g -O} as with just
1136@samp{-g}, particularly on machines with instruction scheduling. If in
1137doubt, recompile with @samp{-g} alone, and if this fixes the problem,
1138please report it as a bug (including a test case!).
1139
1140Older versions of the GNU C compiler permitted a variant option
1141@samp{-gg} for debugging information. _GDBN__ no longer supports this
1142format; if your GNU C compiler has this option, do not use it.
1143
1144@ignore
1145@comment As far as I know, there are no cases in which _GDBN__ will
1146@comment produce strange output in this case. (but no promises).
1147If your program includes archives made with the @code{ar} program, and
1148if the object files used as input to @code{ar} were compiled without the
1149@samp{-g} option and have names longer than 15 characters, _GDBN__ will get
1150confused reading the program's symbol table. No error message will be
1151given, but _GDBN__ may behave strangely. The reason for this problem is a
1152deficiency in the Unix archive file format, which cannot represent file
1153names longer than 15 characters.
1154
1155To avoid this problem, compile the archive members with the @samp{-g}
1156option or use shorter file names. Alternatively, use a version of GNU
1157@code{ar} dated more recently than August 1989.
1158@end ignore
1159
1160
1161@node Starting, Arguments, Compilation, Running
1162@section Starting your Program
1163@cindex starting
1164@cindex running
1165@table @code
1166@item run
1167@itemx r
1168@kindex run
7463aadd
RP
1169Use the @code{run} command to start your program under _GDBN__. You
1170must first specify the program name
1171_if__(_VXWORKS__)
1172(except on VxWorks)
70b88761 1173_fi__(_VXWORKS__)
7463aadd 1174with an argument to _GDBN__
70b88761 1175(@pxref{Invocation}), or using the @code{file} or @code{exec-file}
7463aadd
RP
1176command (@pxref{Files}).
1177@refill
70b88761
RP
1178@end table
1179
1180On targets that support processes, @code{run} creates an inferior
1181process and makes that process run your program. On other targets,
1182@code{run} jumps to the start of the program.
1183
1184The execution of a program is affected by certain information it
1185receives from its superior. _GDBN__ provides ways to specify this
1186information, which you must do @i{before} starting the program. (You
1187can change it after starting the program, but such changes will only affect
1188the program the next time you start it.) This information may be
1189divided into four categories:
1190
1191@table @asis
1192@item The @i{arguments.}
1193You specify the arguments to give your program as the arguments of the
1194@code{run} command. If a shell is available on your target, the shell
1195is used to pass the arguments, so that you may use normal conventions
1196(such as wildcard expansion or variable substitution) in
1197describing the arguments. In Unix systems, you can control which shell
1198is used with the @code{SHELL} environment variable. @xref{Arguments}.@refill
1199
1200@item The @i{environment.}
1201Your program normally inherits its environment from _GDBN__, but you can
1202use the _GDBN__ commands @code{set environment} and @code{unset
1203environment} to change parts of the environment that will be given to
1204the program. @xref{Environment}.@refill
1205
1206@item The @i{working directory.}
1207Your program inherits its working directory from _GDBN__. You can set
1208_GDBN__'s working directory with the @code{cd} command in _GDBN__.
1209@xref{Working Directory}.
1210
1211@item The @i{standard input and output.}
1212Your program normally uses the same device for standard input and
1213standard output as _GDBN__ is using. You can redirect input and output
1214in the @code{run} command line, or you can use the @code{tty} command to
1215set a different device for your program.
1216@xref{Input/Output}.
3d3ab540
RP
1217
1218@cindex pipes
1219@emph{Warning:} While input and output redirection work, you can't use
1220pipes to pass the output of the program you're debugging to another
1221program; if you attempt this, _GDBN__ is likely to wind up debugging the
1222wrong program.
70b88761
RP
1223@end table
1224
1225When you issue the @code{run} command, your program begins to execute
1226immediately. @xref{Stopping}, for discussion of how to arrange for your
1227program to stop. Once your program has been started by the @code{run}
1228command (and then stopped), you may evaluate expressions that involve
1229calls to functions in the inferior, using the @code{print} or
1230@code{call} commands. @xref{Data}.
1231
1232If the modification time of your symbol file has changed since the last
1233time _GDBN__ read its symbols, _GDBN__ will discard its symbol table and re-read
1234it. In this process, it tries to retain your current breakpoints.
1235
1236@node Arguments, Environment, Starting, Running
1237@section Your Program's Arguments
1238
1239@cindex arguments (to your program)
1240The arguments to your program can be specified by the arguments of the
1241@code{run} command. They are passed to a shell, which expands wildcard
1242characters and performs redirection of I/O, and thence to the program.
1243_GDBN__ uses the shell indicated by your environment variable
1244@code{SHELL} if it exists; otherwise, _GDBN__ uses @code{/bin/sh}.
1245
1246@code{run} with no arguments uses the same arguments used by the previous
1247@code{run}, or those set by the @code{set args} command.
1248
1249@kindex set args
1250@table @code
1251@item set args
1252Specify the arguments to be used the next time your program is run. If
1253@code{set args} has no arguments, @code{run} will execute your program
1254with no arguments. Once you have run your program with arguments,
1255using @code{set args} before the next @code{run} is the only way to run
1256it again without arguments.
1257
1258@item show args
1259@kindex show args
1260Show the arguments to give your program when it is started.
1261@end table
1262
1263@node Environment, Working Directory, Arguments, Running
1264@section Your Program's Environment
1265
1266@cindex environment (of your program)
1267The @dfn{environment} consists of a set of environment variables and
1268their values. Environment variables conventionally record such things as
1269your user name, your home directory, your terminal type, and your search
1270path for programs to run. Usually you set up environment variables with
1271the shell and they are inherited by all the other programs you run. When
1272debugging, it can be useful to try running the program with a modified
1273environment without having to start _GDBN__ over again.
1274
1275@table @code
1276@item path @var{directory}
1277@kindex path
1278Add @var{directory} to the front of the @code{PATH} environment variable
1279(the search path for executables), for both _GDBN__ and your program.
1280You may specify several directory names, separated by @samp{:} or
1281whitespace. If @var{directory} is already in the path, it is moved to
7463aadd
RP
1282the front, so it will be searched sooner.
1283
1284You can use the string @samp{$cwd} to refer to whatever is the current
1285working directory at the time _GDBN__ searches the path. If you use
1286@samp{.} instead, it refers to the directory where you executed the
1287@code{path} command. _GDBN__ fills in the current path where needed in
1288the @var{directory} argument, before adding it to the search path.
70b88761
RP
1289@c 'path' is explicitly nonrepeatable, but RMS points out it's silly to
1290@c document that, since repeating it would be a no-op.
1291
1292@item show paths
1293@kindex show paths
1294Display the list of search paths for executables (the @code{PATH}
1295environment variable).
1296
1297@item show environment @r{[}@var{varname}@r{]}
1298@kindex show environment
1299Print the value of environment variable @var{varname} to be given to
1300your program when it starts. If you don't supply @var{varname},
1301print the names and values of all environment variables to be given to
1302your program. You can abbreviate @code{environment} as @code{env}.
1303
7463aadd 1304@item set environment @var{varname} @r{[}=@r{]} @var{value}
70b88761
RP
1305@kindex set environment
1306Sets environment variable @var{varname} to @var{value}. The value
1307changes for your program only, not for _GDBN__ itself. @var{value} may
1308be any string; the values of environment variables are just strings, and
1309any interpretation is supplied by your program itself. The @var{value}
1310parameter is optional; if it is eliminated, the variable is set to a
1311null value.
1312@c "any string" here doesn't include leading, trailing
1313@c blanks. Gnu asks: does anyone care?
1314
1315For example, this command:
1316
1317@example
1318set env USER = foo
1319@end example
1320
1321@noindent
1322tells a Unix program, when subsequently run, that its user is named
1323@samp{foo}. (The spaces around @samp{=} are used for clarity here; they
1324are not actually required.)
1325
1326@item unset environment @var{varname}
1327@kindex unset environment
1328Remove variable @var{varname} from the environment to be passed to your
1329program. This is different from @samp{set env @var{varname} =};
1330@code{unset environment} removes the variable from the environment,
1331rather than assigning it an empty value.
1332@end table
1333
1334@node Working Directory, Input/Output, Environment, Running
1335@section Your Program's Working Directory
1336
1337@cindex working directory (of your program)
1338Each time you start your program with @code{run}, it inherits its
1339working directory from the current working directory of _GDBN__. _GDBN__'s
1340working directory is initially whatever it inherited from its parent
1341process (typically the shell), but you can specify a new working
1342directory in _GDBN__ with the @code{cd} command.
1343
1344The _GDBN__ working directory also serves as a default for the commands
1345that specify files for _GDBN__ to operate on. @xref{Files}.
1346
1347@table @code
1348@item cd @var{directory}
1349@kindex cd
1350Set _GDBN__'s working directory to @var{directory}.
1351
1352@item pwd
1353@kindex pwd
1354Print _GDBN__'s working directory.
1355@end table
1356
1357@node Input/Output, Attach, Working Directory, Running
1358@section Your Program's Input and Output
1359
1360@cindex redirection
1361@cindex i/o
1362@cindex terminal
1363By default, the program you run under _GDBN__ does input and output to
1364the same terminal that _GDBN__ uses. _GDBN__ switches the terminal to
1365its own terminal modes to interact with you, but it records the terminal
1366modes your program was using and switches back to them when you continue
1367running your program.
1368
1369@table @code
1370@item info terminal
1371@kindex info terminal
1372Displays _GDBN__'s recorded information about the terminal modes your
1373program is using.
1374@end table
1375
1376You can redirect the program's input and/or output using shell
1377redirection with the @code{run} command. For example,
1378
1379_0__@example
1380run > outfile
1381_1__@end example
1382
1383@noindent
1384starts the program, diverting its output to the file @file{outfile}.
1385
1386@kindex tty
1387@cindex controlling terminal
1388Another way to specify where the program should do input and output is
1389with the @code{tty} command. This command accepts a file name as
1390argument, and causes this file to be the default for future @code{run}
1391commands. It also resets the controlling terminal for the child
1392process, for future @code{run} commands. For example,
1393
1394@example
1395tty /dev/ttyb
1396@end example
1397
1398@noindent
1399directs that processes started with subsequent @code{run} commands
1400default to do input and output on the terminal @file{/dev/ttyb} and have
1401that as their controlling terminal.
1402
1403An explicit redirection in @code{run} overrides the @code{tty} command's
1404effect on the input/output device, but not its effect on the controlling
1405terminal.
1406
1407When you use the @code{tty} command or redirect input in the @code{run}
1408command, only the input @emph{for your program} is affected. The input
1409for _GDBN__ still comes from your terminal.
1410
1411@node Attach, Kill Process, Input/Output, Running
1412@section Debugging an Already-Running Process
1413@kindex attach
1414@cindex attach
1415
1416@table @code
1417@item attach @var{process-id}
1418This command
1419attaches to a running process---one that was started outside _GDBN__.
1420(@code{info files} will show your active targets.) The command takes as
1421argument a process ID. The usual way to find out the process-id of
1422a Unix process is with the @code{ps} utility, or with the @samp{jobs -l}
1423shell command.
1424
1425@code{attach} will not repeat if you press @key{RET} a second time after
1426executing the command.
1427@end table
1428
1429To use @code{attach}, you must be debugging in an environment which
1430supports processes. You must also have permission to send the process a
1431signal, and it must have the same effective user ID as the _GDBN__
1432process.
1433
1434When using @code{attach}, you should first use the @code{file} command
1435to specify the program running in the process and load its symbol table.
1436@xref{Files}.
1437
1438The first thing _GDBN__ does after arranging to debug the specified
1439process is to stop it. You can examine and modify an attached process
1440with all the _GDBN__ commands that are ordinarily available when you start
1441processes with @code{run}. You can insert breakpoints; you can step and
1442continue; you can modify storage. If you would rather the process
1443continue running, you may use the @code{continue} command after
1444attaching _GDBN__ to the process.
1445
1446@table @code
1447@item detach
1448@kindex detach
1449When you have finished debugging the attached process, you can use the
1450@code{detach} command to release it from _GDBN__'s control. Detaching
1451the process continues its execution. After the @code{detach} command,
1452that process and _GDBN__ become completely independent once more, and you
1453are ready to @code{attach} another process or start one with @code{run}.
1454@code{detach} will not repeat if you press @key{RET} again after
1455executing the command.
1456@end table
1457
1458If you exit _GDBN__ or use the @code{run} command while you have an attached
1459process, you kill that process. By default, you will be asked for
1460confirmation if you try to do either of these things; you can control
1461whether or not you need to confirm by using the @code{set confirm} command
1462(@pxref{Messages/Warnings}).
1463
1464@node Kill Process, , Attach, Running
1465@c @group
1466@section Killing the Child Process
1467
1468@table @code
1469@item kill
1470@kindex kill
1471Kill the child process in which your program is running under _GDBN__.
1472@end table
1473
1474This command is useful if you wish to debug a core dump instead of a
1475running process. _GDBN__ ignores any core dump file while your program
1476is running.
1477@c @end group
1478
1479On some operating systems, a program can't be executed outside _GDBN__
1480while you have breakpoints set on it inside _GDBN__. You can use the
1481@code{kill} command in this situation to permit running the program
1482outside the debugger.
1483
1484The @code{kill} command is also useful if you wish to recompile and
1485relink the program, since on many systems it is impossible to modify an
1486executable file while it is running in a process. In this case, when you
1487next type @code{run}, _GDBN__ will notice that the file has changed, and
1488will re-read the symbol table (while trying to preserve your current
1489breakpoint settings).
1490
1491@node Stopping, Stack, Running, Top
1492@chapter Stopping and Continuing
1493
1494The principal purpose of using a debugger is so that you can stop your
1495program before it terminates; or so that, if the program runs into
1496trouble, you can investigate and find out why.
1497
1498Inside _GDBN__, your program may stop for any of several reasons, such
1499as a signal, a breakpoint, or reaching a new line after a _GDBN__
1500command such as @code{step}. You may then examine and change
1501variables, set new breakpoints or remove old ones, and then continue
1502execution. Usually, the messages shown by _GDBN__ provide ample
1503explanation of the status of your program---but you can also explicitly
1504request this information at any time.
1505
1506@table @code
1507@item info program
1508@kindex info program
1509Display information about the status of your program: whether it is
1510running or not, what process it is, and why it stopped.
1511@end table
1512
1513@menu
1514* Breakpoints:: Breakpoints, Watchpoints, and Exceptions
3d3ab540 1515* Continuing and Stepping:: Resuming Execution
70b88761
RP
1516* Signals:: Signals
1517@end menu
1518
3d3ab540 1519@node Breakpoints, Continuing and Stepping, Stopping, Stopping
70b88761
RP
1520@section Breakpoints, Watchpoints, and Exceptions
1521
1522@cindex breakpoints
1523A @dfn{breakpoint} makes your program stop whenever a certain point in
1524the program is reached. For each breakpoint, you can add various
1525conditions to control in finer detail whether the program will stop.
1526You can set breakpoints with the @code{break} command and its variants
1527(@pxref{Set Breaks}), to specify the place where the program should stop
1528by line number, function name or exact address in the program. In
1529languages with exception handling (such as GNU C++), you can also set
1530breakpoints where an exception is raised (@pxref{Exception Handling}).
1531
1532@cindex watchpoints
1533A @dfn{watchpoint} is a special breakpoint that stops your program when
1534the value of an expression changes. You must use a different command to
1535set watchpoints (@pxref{Set Watchpoints}), but aside from that, you can
1536manage a watchpoint like any other breakpoint: you enable, disable, and
1537delete both breakpoints and watchpoints using the same commands.
1538
1539Each breakpoint or watchpoint is assigned a number when it is created;
1540these numbers are successive integers starting with one. In many of the
1541commands for controlling various features of breakpoints you use the
1542breakpoint number to say which breakpoint you want to change. Each
1543breakpoint may be @dfn{enabled} or @dfn{disabled}; if disabled, it has
1544no effect on the program until you enable it again.
1545
1546@menu
1547* Set Breaks:: Setting Breakpoints
1548* Set Watchpoints:: Setting Watchpoints
1549* Exception Handling:: Breakpoints and Exceptions
1550* Delete Breaks:: Deleting Breakpoints
1551* Disabling:: Disabling Breakpoints
1552* Conditions:: Break Conditions
1553* Break Commands:: Breakpoint Command Lists
1554* Breakpoint Menus:: Breakpoint Menus
1555* Error in Breakpoints::
1556@end menu
1557
1558@node Set Breaks, Set Watchpoints, Breakpoints, Breakpoints
1559@subsection Setting Breakpoints
1560
1561@kindex break
1562@kindex b
1563Breakpoints are set with the @code{break} command (abbreviated @code{b}).
1564
1565You have several ways to say where the breakpoint should go.
1566
1567@table @code
1568@item break @var{function}
1569Set a breakpoint at entry to function @var{function}. When using source
1570languages that permit overloading of symbols, such as C++,
1571@var{function} may refer to more than one possible place to break.
1572@xref{Breakpoint Menus}, for a discussion of that situation.
1573
1574@item break +@var{offset}
1575@itemx break -@var{offset}
1576Set a breakpoint some number of lines forward or back from the position
1577at which execution stopped in the currently selected frame.
1578
1579@item break @var{linenum}
1580Set a breakpoint at line @var{linenum} in the current source file.
1581That file is the last file whose source text was printed. This
1582breakpoint will stop the program just before it executes any of the
1583code on that line.
1584
1585@item break @var{filename}:@var{linenum}
1586Set a breakpoint at line @var{linenum} in source file @var{filename}.
1587
1588@item break @var{filename}:@var{function}
1589Set a breakpoint at entry to function @var{function} found in file
1590@var{filename}. Specifying a file name as well as a function name is
1591superfluous except when multiple files contain similarly named
1592functions.
1593
1594@item break *@var{address}
1595Set a breakpoint at address @var{address}. You can use this to set
1596breakpoints in parts of the program which do not have debugging
1597information or source files.
1598
1599@item break
1600When called without any arguments, @code{break} sets a breakpoint at the
1601next instruction to be executed in the selected stack frame
1602(@pxref{Stack}). In any selected frame but the innermost, this will
1603cause the program to stop as soon as control returns to that frame.
1604This is similar to the effect of a @code{finish} command in the frame
1605inside the selected frame---except that @code{finish} doesn't leave an
1606active breakpoint. If you use @code{break} without an argument in the
1607innermost frame, _GDBN__ will stop the next time it reaches the current
1608location; this may be useful inside loops.
1609
1610_GDBN__ normally ignores breakpoints when it resumes execution, until at
1611least one instruction has been executed. If it did not do this, you
1612would be unable to proceed past a breakpoint without first disabling the
1613breakpoint. This rule applies whether or not the breakpoint already
1614existed when the program stopped.
1615
1616@item break @dots{} if @var{cond}
1617Set a breakpoint with condition @var{cond}; evaluate the expression
1618@var{cond} each time the breakpoint is reached, and stop only if the
3d3ab540
RP
1619value is nonzero---that is, if @var{cond} evaluates as true.
1620@samp{@dots{}} stands for one of the possible arguments described above
1621(or no argument) specifying where to break. @xref{Conditions}, for more
1622information on breakpoint conditions.
70b88761
RP
1623
1624@item tbreak @var{args}
1625@kindex tbreak
1626Set a breakpoint enabled only for one stop. @var{args} are the
1627same as for the @code{break} command, and the breakpoint is set in the same
1628way, but the breakpoint is automatically disabled the first time it
1629is hit. @xref{Disabling}.
1630
1631@item rbreak @var{regex}
1632@kindex rbreak
1633@cindex regular expression
1634@c FIXME: 2nd sentence below C++ only?
1635Set breakpoints on all functions matching the regular expression
1636@var{regex}. This is useful for setting breakpoints on overloaded
1637functions that are not members of any special classes. This command
1638sets an unconditional breakpoint on all matches, printing a list of all
1639breakpoints it set. Once these breakpoints are set, they are treated
1640just like the breakpoints set with the @code{break} command. They can
1641be deleted, disabled, made conditional, etc., in the standard ways.
1642
1643@kindex info breakpoints
1644@kindex $_
1645@item info breakpoints @r{[}@var{n}@r{]}
1646@item info break @r{[}@var{n}@r{]}
1647Print a list of all breakpoints (but not watchpoints) set and not
1648deleted, showing their numbers, where in the program they are, and any
1649special features in use for them. Disabled breakpoints are included in
1650the list, but marked as disabled. @code{info break} with a breakpoint
1651number @var{n} as argument lists only that breakpoint. The convenience
1652variable @code{$_} and the default examining-address for the @code{x}
1653command are set to the address of the last breakpoint listed
1654(@pxref{Memory}). The equivalent command for watchpoints is @code{info
1655watch}. @end table
1656
1657_GDBN__ allows you to set any number of breakpoints at the same place in the
1658program. There is nothing silly or meaningless about this. When the
1659breakpoints are conditional, this is even useful (@pxref{Conditions}).
1660
1661@node Set Watchpoints, Exception Handling, Set Breaks, Breakpoints
1662@subsection Setting Watchpoints
1663@cindex setting watchpoints
1664You can use a watchpoint to stop execution whenever the value of an
1665expression changes, without having to predict a particular place
1666where this may happen.
1667
1668Watchpoints currently execute two orders of magnitude more slowly than
1669other breakpoints, but this can well be worth it to catch errors where
1670you have no clue what part of your program is the culprit. Some
1671processors provide special hardware to support watchpoint evaluation; future
1672releases of _GDBN__ will use such hardware if it is available.
1673
1674@table @code
1675@kindex watch
1676@item watch @var{expr}
1677Set a watchpoint for an expression.
1678
1679@kindex info watchpoints
1680@item info watchpoints
1681This command prints a list of watchpoints; it is otherwise similar to
1682@code{info break}.
1683@end table
1684
1685@node Exception Handling, Delete Breaks, Set Watchpoints, Breakpoints
1686@subsection Breakpoints and Exceptions
1687@cindex exception handlers
1688
1689Some languages, such as GNU C++, implement exception handling. _GDBN__
1690can be used to examine what caused the program to raise an exception
1691and to list the exceptions the program is prepared to handle at a
1692given point in time.
1693
1694@table @code
1695@item catch @var{exceptions}
1696@kindex catch
1697You can set breakpoints at active exception handlers by using the
1698@code{catch} command. @var{exceptions} is a list of names of exceptions
1699to catch.
1700@end table
1701
1702You can use @code{info catch} to list active exception handlers;
1703@pxref{Frame Info}.
1704
1705There are currently some limitations to exception handling in _GDBN__.
1706These will be corrected in a future release.
1707
1708@itemize @bullet
1709@item
1710If you call a function interactively, _GDBN__ normally returns
1711control to you when the function has finished executing. If the call
1712raises an exception, however, the call may bypass the mechanism that
1713returns control to the user and cause the program to simply continue
1714running until it hits a breakpoint, catches a signal that _GDBN__ is
1715listening for, or exits.
1716@item
1717You cannot raise an exception interactively.
1718@item
1719You cannot interactively install an exception handler.
1720@end itemize
1721
1722@cindex raise exceptions
1723Sometimes @code{catch} is not the best way to debug exception handling:
1724if you need to know exactly where an exception is raised, it's better to
1725stop @emph{before} the exception handler is called, since that way you
1726can see the stack before any unwinding takes place. If you set a
1727breakpoint in an exception handler instead, it may not be easy to find
1728out where the exception was raised.
1729
1730To stop just before an exception handler is called, you need some
1731knowledge of the implementation. In the case of GNU C++ exceptions are
1732raised by calling a library function named @code{__raise_exception}
1733which has the following ANSI C interface:
1734
1735@example
1736 /* ADDR is where the exception identifier is stored.
1737 ID is the exception identifier. */
1738 void __raise_exception (void **@var{addr}, void *@var{id});
1739@end example
1740
1741@noindent
1742To make the debugger catch all exceptions before any stack
1743unwinding takes place, set a breakpoint on @code{__raise_exception}
1744(@pxref{Breakpoints}).
1745
1746With a conditional breakpoint (@xref{Conditions}) that depends on the
1747value of @var{id}, you can stop your program when a specific exception
1748is raised. You can use multiple conditional breakpoints to stop the
1749program when any of a number of exceptions are raised.
1750
1751@node Delete Breaks, Disabling, Exception Handling, Breakpoints
1752@subsection Deleting Breakpoints
1753
1754@cindex clearing breakpoints, watchpoints
1755@cindex deleting breakpoints, watchpoints
1756It is often necessary to eliminate a breakpoint or watchpoint once it
1757has done its job and you no longer want the program to stop there. This
1758is called @dfn{deleting} the breakpoint. A breakpoint that has been
1759deleted no longer exists; it is forgotten.
1760
1761With the @code{clear} command you can delete breakpoints according to
1762where they are in the program. With the @code{delete} command you can
1763delete individual breakpoints or watchpoints by specifying their
1764breakpoint numbers.
1765
1766It is not necessary to delete a breakpoint to proceed past it. _GDBN__
1767automatically ignores breakpoints on the first instruction to be executed
1768when you continue execution without changing the execution address.
1769
1770@table @code
1771@item clear
1772@kindex clear
1773Delete any breakpoints at the next instruction to be executed in the
1774selected stack frame (@pxref{Selection}). When the innermost frame
1775is selected, this is a good way to delete a breakpoint that the program
1776just stopped at.
1777
1778@item clear @var{function}
1779@itemx clear @var{filename}:@var{function}
1780Delete any breakpoints set at entry to the function @var{function}.
1781
1782@item clear @var{linenum}
1783@itemx clear @var{filename}:@var{linenum}
1784Delete any breakpoints set at or within the code of the specified line.
1785
1786@item delete @r{[}breakpoints@r{]} @r{[}@var{bnums}@dots{}@r{]}
1787@cindex delete breakpoints
1788@kindex delete
1789@kindex d
1790Delete the breakpoints or watchpoints of the numbers specified as
1791arguments. If no argument is specified, delete all breakpoints (_GDBN__
1792asks confirmation, unless you've @code{set confirm off}). You
1793can abbreviate this command as @code{d}.
1794@end table
1795
1796@node Disabling, Conditions, Delete Breaks, Breakpoints
1797@subsection Disabling Breakpoints
1798
1799@cindex disabled breakpoints
1800@cindex enabled breakpoints
1801Rather than deleting a breakpoint or watchpoint, you might prefer to
1802@dfn{disable} it. This makes the breakpoint inoperative as if it had
1803been deleted, but remembers the information on the breakpoint so that
1804you can @dfn{enable} it again later.
1805
1806You disable and enable breakpoints and watchpoints with the
1807@code{enable} and @code{disable} commands, optionally specifying one or
1808more breakpoint numbers as arguments. Use @code{info break} or
1809@code{info watch} to print a list of breakpoints or watchpoints if you
1810don't know which numbers to use.
1811
1812A breakpoint or watchpoint can have any of four different states of
1813enablement:
1814
1815@itemize @bullet
1816@item
1817Enabled. The breakpoint will stop the program. A breakpoint set
1818with the @code{break} command starts out in this state.
1819@item
1820Disabled. The breakpoint has no effect on the program.
1821@item
1822Enabled once. The breakpoint will stop the program, but
1823when it does so it will become disabled. A breakpoint set
1824with the @code{tbreak} command starts out in this state.
1825@item
1826Enabled for deletion. The breakpoint will stop the program, but
1827immediately after it does so it will be deleted permanently.
1828@end itemize
1829
1830You can use the following commands to enable or disable breakpoints and
1831watchpoints:
1832
1833@table @code
1834@item disable @r{[}breakpoints@r{]} @r{[}@var{bnums}@dots{}@r{]}
1835@kindex disable breakpoints
1836@kindex disable
1837@kindex dis
1838Disable the specified breakpoints---or all breakpoints, if none are
1839listed. A disabled breakpoint has no effect but is not forgotten. All
1840options such as ignore-counts, conditions and commands are remembered in
1841case the breakpoint is enabled again later. You may abbreviate
1842@code{disable} as @code{dis}.
1843
1844@item enable @r{[}breakpoints@r{]} @r{[}@var{bnums}@dots{}@r{]}
1845@kindex enable breakpoints
1846@kindex enable
1847Enable the specified breakpoints (or all defined breakpoints). They
1848become effective once again in stopping the program.
1849
1850@item enable @r{[}breakpoints@r{]} once @var{bnums}@dots{}
1851Enable the specified breakpoints temporarily. Each will be disabled
1852again the next time it stops the program.
1853
1854@item enable @r{[}breakpoints@r{]} delete @var{bnums}@dots{}
1855Enable the specified breakpoints to work once and then die. Each of
1856the breakpoints will be deleted the next time it stops the program.
1857@end table
1858
1859Save for a breakpoint set with @code{tbreak} (@pxref{Set Breaks}),
1860breakpoints that you set are initially enabled; subsequently, they become
1861disabled or enabled only when you use one of the commands above. (The
1862command @code{until} can set and delete a breakpoint of its own, but it
1863will not change the state of your other breakpoints;
3d3ab540 1864@pxref{Continuing and Stepping}.)
70b88761
RP
1865
1866@node Conditions, Break Commands, Disabling, Breakpoints
1867@subsection Break Conditions
1868@cindex conditional breakpoints
1869@cindex breakpoint conditions
1870
1871The simplest sort of breakpoint breaks every time the program reaches a
1872specified place. You can also specify a @dfn{condition} for a
1873breakpoint. A condition is just a Boolean expression in your
1874programming language. (@xref{Expressions}). A breakpoint with a
1875condition evaluates the expression each time the program reaches it, and
3d3ab540
RP
1876the program stops only if the condition is @emph{true}.
1877
1878This is the converse of using assertions for program validation; in that
1879situation, you want to stop when the assertion is violated---that is,
1880when the condition is false. In C, if you want to test an assertion expressed
1881by the condition @var{assert}, you should set the condition
1882@samp{! @var{assert}} on the appropriate breakpoint.
70b88761
RP
1883
1884Conditions are also accepted for watchpoints; you may not need them,
1885since a watchpoint is inspecting the value of an expression anyhow---but
1886it might be simpler, say, to just set a watchpoint on a variable name,
1887and specify a condition that tests whether the new value is an interesting
1888one.
1889
1890Break conditions ca have side effects, and may even call functions in
1891your program. This can be useful, for example, to activate functions
1892that log program progress, or to use your own print functions to format
1893special data structures. The effects are completely predictable unless
1894there is another enabled breakpoint at the same address. (In that
1895case, _GDBN__ might see the other breakpoint first and stop the program
1896without checking the condition of this one.) Note that breakpoint
1897commands are usually more convenient and flexible for the purpose of
1898performing side effects when a breakpoint is reached (@pxref{Break
1899Commands}).
1900
1901Break conditions can be specified when a breakpoint is set, by using
1902@samp{if} in the arguments to the @code{break} command. @xref{Set Breaks}.
1903They can also be changed at any time with the @code{condition} command.
1904The @code{watch} command doesn't recognize the @code{if} keyword;
1905@code{condition} is the only way to impose a further condition on a
1906watchpoint.
1907
1908@table @code
1909@item condition @var{bnum} @var{expression}
1910@kindex condition
1911Specify @var{expression} as the break condition for breakpoint or
1912watchpoint number @var{bnum}. From now on, this breakpoint will stop
1913the program only if the value of @var{expression} is true (nonzero, in
1914C). When you use @code{condition}, _GDBN__ checks @var{expression}
1915immediately for syntactic correctness, and to determine whether symbols
1916in it have referents in the context of your breakpoint. _GDBN__ does
1917not actually evaluate @var{expression} at the time the @code{condition}
1918command is given, however. @xref{Expressions}.
1919
1920@item condition @var{bnum}
1921Remove the condition from breakpoint number @var{bnum}. It becomes
1922an ordinary unconditional breakpoint.
1923@end table
1924
1925@cindex ignore count (of breakpoint)
1926A special case of a breakpoint condition is to stop only when the
1927breakpoint has been reached a certain number of times. This is so
1928useful that there is a special way to do it, using the @dfn{ignore
1929count} of the breakpoint. Every breakpoint has an ignore count, which
1930is an integer. Most of the time, the ignore count is zero, and
1931therefore has no effect. But if the program reaches a breakpoint whose
1932ignore count is positive, then instead of stopping, it just decrements
1933the ignore count by one and continues. As a result, if the ignore count
1934value is @var{n}, the breakpoint will not stop the next @var{n} times it
1935is reached.
1936
1937@table @code
1938@item ignore @var{bnum} @var{count}
1939@kindex ignore
1940Set the ignore count of breakpoint number @var{bnum} to @var{count}.
1941The next @var{count} times the breakpoint is reached, your program's
1942execution will not stop; other than to decrement the ignore count, _GDBN__
1943takes no action.
1944
1945To make the breakpoint stop the next time it is reached, specify
1946a count of zero.
1947
1948@item continue @var{count}
1949@itemx c @var{count}
1950@itemx fg @var{count}
1951@kindex continue @var{count}
1952Continue execution of the program, setting the ignore count of the
1953breakpoint that the program stopped at to @var{count} minus one.
1954Thus, the program will not stop at this breakpoint until the
1955@var{count}'th time it is reached.
1956
1957An argument to this command is meaningful only when the program stopped
1958due to a breakpoint. At other times, the argument to @code{continue} is
1959ignored.
1960
1961The synonym @code{fg} is provided purely for convenience, and has
1962exactly the same behavior as other forms of the command.
1963@end table
1964
1965If a breakpoint has a positive ignore count and a condition, the condition
1966is not checked. Once the ignore count reaches zero, the condition will
1967be checked.
1968
1969You could achieve the effect of the ignore count with a
1970condition such as _0__@w{@samp{$foo-- <= 0}}_1__ using a debugger convenience
1971variable that is decremented each time. @xref{Convenience Vars}.
1972
1973@node Break Commands, Breakpoint Menus, Conditions, Breakpoints
1974@subsection Breakpoint Command Lists
1975
1976@cindex breakpoint commands
1977You can give any breakpoint (or watchpoint) a series of commands to
1978execute when the program stops due to that breakpoint. For example, you
1979might want to print the values of certain expressions, or enable other
1980breakpoints.
1981
1982@table @code
1983@item commands @r{[}@var{bnum}@r{]}
1984@itemx @dots{} @var{command-list} @dots{}
1985@itemx end
1986@kindex commands
1987@kindex end
1988Specify a list of commands for breakpoint number @var{bnum}. The commands
1989themselves appear on the following lines. Type a line containing just
1990@code{end} to terminate the commands.
1991
1992To remove all commands from a breakpoint, type @code{commands} followed
1993immediately by @code{end}; that is, give no commands.
1994
1995With no @var{bnum} argument, @code{commands} refers to the last
1996breakpoint or watchpoint set (not to the breakpoint most recently
1997encountered).
1998@end table
1999
2000Pressing @key{RET} as a means of repeating the last _GDBN__ command is
2001disabled within a @var{command-list}.
2002
2003You can use breakpoint commands to start the program up again. Simply
2004use the @code{continue} command, or @code{step}, or any other command
2005that resumes execution. Subsequent commands in the command list are
2006ignored.
2007
2008@kindex silent
2009If the first command specified is @code{silent}, the usual message about
2010stopping at a breakpoint is not printed. This may be desirable for
2011breakpoints that are to print a specific message and then continue.
2012If the remaining commands too print nothing, you will see no sign that
2013the breakpoint was reached at all. @code{silent} is meaningful only
2014at the beginning of a breakpoint command list.
2015
2016The commands @code{echo} and @code{output} that allow you to print precisely
2017controlled output are often useful in silent breakpoints. @xref{Output}.
2018
2019For example, here is how you could use breakpoint commands to print the
2020value of @code{x} at entry to @code{foo} whenever @code{x} is positive.
2021
2022_0__@example
2023break foo if x>0
2024commands
2025silent
2026echo x is\040
2027output x
2028echo \n
2029cont
2030end
2031_1__@end example
2032
2033One application for breakpoint commands is to compensate for one bug so
2034you can test for another. Put a breakpoint just after the erroneous line
2035of code, give it a condition to detect the case in which something
2036erroneous has been done, and give it commands to assign correct values
2037to any variables that need them. End with the @code{continue} command
2038so that the program does not stop, and start with the @code{silent}
2039command so that no output is produced. Here is an example:
2040
2041@example
2042break 403
2043commands
2044silent
2045set x = y + 4
2046cont
2047end
2048@end example
2049
2050@cindex lost output
2051One deficiency in the operation of automatically continuing breakpoints
2052under Unix appears when your program uses raw mode for the terminal.
2053_GDBN__ switches back to its own terminal modes (not raw) before executing
2054commands, and then must switch back to raw mode when your program is
2055continued. This causes any pending terminal input to be lost.
2056@c FIXME: revisit below when GNU sys avail.
2057@c In the GNU system, this will be fixed by changing the behavior of
2058@c terminal modes.
2059
2060Under Unix, you can get around this problem by writing actions into
2061the breakpoint condition rather than in commands. For example
2062
2063@example
2064condition 5 (x = y + 4), 0
2065@end example
2066
2067@noindent
2068specifies a condition expression (@xref{Expressions}) that will change
2069@code{x} as needed, then always have the value zero so the program will
2070not stop. No input is lost here, because _GDBN__ evaluates break
2071conditions without changing the terminal modes. When you want to have
2072nontrivial conditions for performing the side effects, the operators
2073@samp{&&}, @samp{||} and @samp{?@dots{}:} may be useful.
2074
2075@node Breakpoint Menus, Error in Breakpoints, Break Commands, Breakpoints
2076@subsection Breakpoint Menus
2077@cindex C++ overloading
2078@cindex symbol overloading
2079
2080Some programming languages (notably C++) permit a single function name
2081to be defined several times, for application in different contexts.
2082This is called @dfn{overloading}. When a function name is overloaded,
2083@samp{break @var{function}} is not enough to tell _GDBN__ where you
2084want a breakpoint. _GDBN__ offers you a menu of numbered choices for
2085different possible breakpoints, and waits for your selection with the
2086prompt @samp{>}. The first two options are always @samp{[0] cancel}
2087and @samp{[1] all}. Typing @kbd{1} sets a breakpoint at each
2088definition of @var{function}, and typing @kbd{0} aborts the
2089@code{break} command without setting any new breakpoints.
2090
2091For example, the following session excerpt shows an attempt to set a
2092breakpoint at the overloaded symbol @code{String::after}.
2093We choose three particular definitions of that function name:
2094
2095@example
2096(_GDBP__) b String::after
2097[0] cancel
2098[1] all
2099[2] file:String.cc; line number:867
2100[3] file:String.cc; line number:860
2101[4] file:String.cc; line number:875
2102[5] file:String.cc; line number:853
2103[6] file:String.cc; line number:846
2104[7] file:String.cc; line number:735
2105> 2 4 6
2106Breakpoint 1 at 0xb26c: file String.cc, line 867.
2107Breakpoint 2 at 0xb344: file String.cc, line 875.
2108Breakpoint 3 at 0xafcc: file String.cc, line 846.
2109Multiple breakpoints were set.
2110Use the "delete" command to delete unwanted breakpoints.
2111(_GDBP__)
2112@end example
2113
2114
2115@node Error in Breakpoints, , Breakpoint Menus, Breakpoints
2116@subsection ``Cannot Insert Breakpoints''
2117
2118@c FIXME: "cannot insert breakpoints" error, v unclear.
2119@c Q in pending mail to Gilmore. [email protected], 26mar91
2120Under some operating systems, breakpoints cannot be used in a program if
2121any other process is running that program. In this situation,
2122attempting to run or continue a program with a breakpoint causes _GDBN__
2123to stop the other process.
2124
2125When this happens, you have three ways to proceed:
2126
2127@enumerate
2128@item
2129Remove or disable the breakpoints, then continue.
2130
2131@item
2132Suspend _GDBN__, and copy the file containing the program to a new name.
2133Resume _GDBN__ and use the @code{exec-file} command to specify that _GDBN__
2134should run the program under that name. Then start the program again.
2135
2136@c FIXME: RMS commented here "Show example". Maybe when someone
2137@c explains the first FIXME: in this section...
2138
2139@item
2140Relink the program so that the text segment is nonsharable, using the
2141linker option @samp{-N}. The operating system limitation may not apply
2142to nonsharable executables.
2143@end enumerate
2144
3d3ab540
RP
2145@node Continuing and Stepping, Signals, Breakpoints, Stopping
2146@section Continuing and Stepping
70b88761
RP
2147
2148@cindex stepping
7463aadd
RP
2149@cindex continuing
2150@cindex resuming execution
3d3ab540
RP
2151@dfn{Continuing} means resuming program execution until your program
2152completes normally. In contrast, @dfn{stepping} means resuming program
2153execution for a very limited time: one line of source code, or one
2154machine instruction. Either when continuing or when stepping, the
2155program may stop even sooner, due to a breakpoint or to a signal. (If
2156due to a signal, you may want to use @code{handle}, or use @samp{signal
21570} to resume execution; @pxref{Signals}.)
2158
2159@table @code
2160@item continue @r{[}@var{ignore-count}@r{]}
2161@kindex continue
2162Resume program execution, at the address where the program last stopped;
2163any breakpoints set at that address are bypassed. The optional argument
2164@var{ignore-count} allows you to specify a further number of times to
2165ignore a breakpoint at this location; its effect is like that of
2166@code{ignore} (@pxref{Conditions}).
2167
2168To resume execution at a different place, you can use @code{return}
2169(@pxref{Returning}) to go back to the calling function; or @code{jump}
2170(@pxref{Jumping}) to go to an arbitrary location in your program.
2171
2172@end table
7463aadd
RP
2173
2174A typical technique for using stepping is to set a breakpoint
70b88761
RP
2175(@pxref{Breakpoints}) at the beginning of the function or the section of
2176the program in which a problem is believed to lie, run the program until
2177it stops at that breakpoint, and then step through the suspect area,
2178examining the variables that are interesting, until you see the problem
2179happen.
2180
2181@table @code
2182@item step
2183@kindex step
2184@kindex s
2185Continue running the program until control reaches a different source
7463aadd 2186line, then stop it and return control to _GDBN__. This command is
70b88761
RP
2187abbreviated @code{s}.
2188
3d3ab540
RP
2189@quotation
2190@emph{Warning:} If you use the @code{step} command while control is
2191within a function that was compiled without debugging information,
2192execution will proceed until control reaches another function.
2193@end quotation
70b88761
RP
2194
2195@item step @var{count}
2196Continue running as in @code{step}, but do so @var{count} times. If a
2197breakpoint is reached or a signal not related to stepping occurs before
2198@var{count} steps, stepping stops right away.
2199
7463aadd 2200@item next @r{[}@var{count}@r{]}
70b88761
RP
2201@kindex next
2202@kindex n
7463aadd
RP
2203Continue to the next source line in the current (innermost) stack frame.
2204Similar to @code{step}, but any function calls appearing within the line
2205of code are executed without stopping. Execution stops when control
2206reaches a different line of code at the stack level which was executing
2207when the @code{next} command was given. This command is abbreviated
2208@code{n}.
70b88761 2209
7463aadd 2210An argument @var{count} is a repeat count, as for @code{step}.
70b88761
RP
2211
2212@code{next} within a function that lacks debugging information acts like
2213@code{step}, but any function calls appearing within the code of the
2214function are executed without stopping.
2215
2216@item finish
2217@kindex finish
7463aadd
RP
2218Continue running until just after function in the selected stack frame
2219returns. Print the returned value (if any).
70b88761
RP
2220
2221Contrast this with the @code{return} command (@pxref{Returning}).
2222
2223@item until
2224@kindex until
2225@item u
2226@kindex u
2227Continue running until a source line past the current line, in the
2228current stack frame, is reached. This command is used to avoid single
2229stepping through a loop more than once. It is like the @code{next}
2230command, except that when @code{until} encounters a jump, it
2231automatically continues execution until the program counter is greater
2232than the address of the jump.
2233
2234This means that when you reach the end of a loop after single stepping
2235though it, @code{until} will cause the program to continue execution
2236until the loop is exited. In contrast, a @code{next} command at the end
2237of a loop will simply step back to the beginning of the loop, which
2238would force you to step through the next iteration.
2239
2240@code{until} always stops the program if it attempts to exit the current
2241stack frame.
2242
2243@code{until} may produce somewhat counterintuitive results if the order
7463aadd 2244of machine code does not match the order of the source lines. For
70b88761
RP
2245example, in the following excerpt from a debugging session, the @code{f}
2246(@code{frame}) command shows that execution is stopped at line
2247@code{206}; yet when we use @code{until}, we get to line @code{195}:
2248
2249@example
2250(_GDBP__) f
2251#0 main (argc=4, argv=0xf7fffae8) at m4.c:206
2252206 expand_input();
2253(_GDBP__) until
2254195 for ( ; argc > 0; NEXTARG) @{
2255@end example
2256
7463aadd
RP
2257This happened because, for execution efficiency, the compiler had
2258generated code for the loop closure test at the end, rather than the
2259start, of the loop---even though the test in a C @code{for}-loop is
2260written before the body of the loop. The @code{until} command appeared
2261to step back to the beginning of the loop when it advanced to this
2262expression; however, it has not really gone to an earlier
2263statement---not in terms of the actual machine code.
70b88761
RP
2264
2265@code{until} with no argument works by means of single
2266instruction stepping, and hence is slower than @code{until} with an
2267argument.
2268
2269@item until @var{location}
2270@item u @var{location}
2271Continue running the program until either the specified location is
7463aadd 2272reached, or the current stack frame returns. @var{location}
70b88761
RP
2273is any of the forms of argument acceptable to @code{break} (@pxref{Set
2274Breaks}). This form of the command uses breakpoints, and hence is
2275quicker than @code{until} without an argument.
2276
2277@item stepi
2278@itemx si
2279@kindex stepi
2280@kindex si
2281Execute one machine instruction, then stop and return to the debugger.
2282
2283It is often useful to do @samp{display/i $pc} when stepping by machine
2284instructions. This will cause the next instruction to be executed to
2285be displayed automatically at each stop. @xref{Auto Display}.
2286
2287An argument is a repeat count, as in @code{step}.
2288
2289@item nexti
2290@itemx ni
2291@kindex nexti
2292@kindex ni
2293Execute one machine instruction, but if it is a function call,
2294proceed until the function returns.
2295
2296An argument is a repeat count, as in @code{next}.
70b88761
RP
2297@end table
2298
70b88761 2299
3d3ab540 2300@node Signals, , Continuing and Stepping, Stopping
70b88761
RP
2301@section Signals
2302@cindex signals
2303
2304A signal is an asynchronous event that can happen in a program. The
2305operating system defines the possible kinds of signals, and gives each
2306kind a name and a number. For example, in Unix @code{SIGINT} is the
2307signal a program gets when you type an interrupt (often @kbd{C-c});
2308@code{SIGSEGV} is the signal a program gets from referencing a place in
2309memory far away from all the areas in use; @code{SIGALRM} occurs when
2310the alarm clock timer goes off (which happens only if the program has
2311requested an alarm).
2312
2313@cindex fatal signals
2314Some signals, including @code{SIGALRM}, are a normal part of the
2315functioning of the program. Others, such as @code{SIGSEGV}, indicate
2316errors; these signals are @dfn{fatal} (kill the program immediately) if the
2317program has not specified in advance some other way to handle the signal.
2318@code{SIGINT} does not indicate an error in the program, but it is normally
2319fatal so it can carry out the purpose of the interrupt: to kill the program.
2320
2321_GDBN__ has the ability to detect any occurrence of a signal in the program
2322running under _GDBN__'s control. You can tell _GDBN__ in advance what to do for
2323each kind of signal.
2324
2325@cindex handling signals
2326Normally, _GDBN__ is set up to ignore non-erroneous signals like @code{SIGALRM}
2327(so as not to interfere with their role in the functioning of the program)
2328but to stop the program immediately whenever an error signal happens.
2329You can change these settings with the @code{handle} command.
2330
2331@table @code
2332@item info signals
2333@kindex info signals
2334Print a table of all the kinds of signals and how _GDBN__ has been told to
2335handle each one. You can use this to see the signal numbers of all
2336the defined types of signals.
2337
2338@item handle @var{signal} @var{keywords}@dots{}
2339@kindex handle
2340Change the way _GDBN__ handles signal @var{signal}. @var{signal} can be the
2341number of a signal or its name (with or without the @samp{SIG} at the
2342beginning). The @var{keywords} say what change to make.
2343@end table
2344
2345@c @group
2346The keywords allowed by the @code{handle} command can be abbreviated.
2347Their full names are:
2348
2349@table @code
2350@item nostop
2351_GDBN__ should not stop the program when this signal happens. It may
2352still print a message telling you that the signal has come in.
2353
2354@item stop
2355_GDBN__ should stop the program when this signal happens. This implies
2356the @code{print} keyword as well.
2357
2358@item print
2359_GDBN__ should print a message when this signal happens.
2360
2361@item noprint
2362_GDBN__ should not mention the occurrence of the signal at all. This
2363implies the @code{nostop} keyword as well.
2364
2365@item pass
2366_GDBN__ should allow the program to see this signal; the program will be
2367able to handle the signal, or may be terminated if the signal is fatal
2368and not handled.
2369
2370@item nopass
2371_GDBN__ should not allow the program to see this signal.
2372@end table
2373@c @end group
2374
2375When a signal has been set to stop the program, the program cannot see the
2376signal until you continue. It will see the signal then, if @code{pass} is
2377in effect for the signal in question @i{at that time}. In other words,
2378after _GDBN__ reports a signal, you can use the @code{handle} command with
2379@code{pass} or @code{nopass} to control whether that signal will be seen by
2380the program when you later continue it.
2381
2382You can also use the @code{signal} command to prevent the program from
2383seeing a signal, or cause it to see a signal it normally would not see,
7463aadd
RP
2384or to give it any signal at any time. For example, if the program stopped
2385due to some sort of memory reference error, you might store correct
2386values into the erroneous variables and continue, hoping to see more
2387execution; but the program would probably terminate immediately as
2388a result of the fatal signal once it sees the signal. To prevent this,
2389you can continue with @samp{signal 0}. @xref{Signaling}.
70b88761
RP
2390
2391@node Stack, Source, Stopping, Top
2392@chapter Examining the Stack
2393
2394When your program has stopped, the first thing you need to know is where it
2395stopped and how it got there.
2396
2397@cindex call stack
2398Each time your program performs a function call, the information about
2399where in the program the call was made from is saved in a block of data
2400called a @dfn{stack frame}. The frame also contains the arguments of the
2401call and the local variables of the function that was called. All the
2402stack frames are allocated in a region of memory called the @dfn{call
2403stack}.
2404
2405When your program stops, the _GDBN__ commands for examining the stack allow you
2406to see all of this information.
2407
2408@cindex selected frame
2409One of the stack frames is @dfn{selected} by _GDBN__ and many _GDBN__ commands
2410refer implicitly to the selected frame. In particular, whenever you ask
2411_GDBN__ for the value of a variable in the program, the value is found in the
2412selected frame. There are special _GDBN__ commands to select whichever frame
2413you are interested in.
2414
2415When the program stops, _GDBN__ automatically selects the currently executing
2416frame and describes it briefly as the @code{frame} command does
2417(@pxref{Frame Info, Info}).
2418
2419@menu
2420* Frames:: Stack Frames
2421* Backtrace:: Backtraces
2422* Selection:: Selecting a Frame
2423* Frame Info:: Information on a Frame
2424@end menu
2425
2426@node Frames, Backtrace, Stack, Stack
2427@section Stack Frames
2428
2429@cindex frame
2430@cindex stack frame
2431The call stack is divided up into contiguous pieces called @dfn{stack
2432frames}, or @dfn{frames} for short; each frame is the data associated
2433with one call to one function. The frame contains the arguments given
2434to the function, the function's local variables, and the address at
2435which the function is executing.
2436
2437@cindex initial frame
2438@cindex outermost frame
2439@cindex innermost frame
2440When your program is started, the stack has only one frame, that of the
2441function @code{main}. This is called the @dfn{initial} frame or the
2442@dfn{outermost} frame. Each time a function is called, a new frame is
2443made. Each time a function returns, the frame for that function invocation
2444is eliminated. If a function is recursive, there can be many frames for
2445the same function. The frame for the function in which execution is
2446actually occurring is called the @dfn{innermost} frame. This is the most
2447recently created of all the stack frames that still exist.
2448
2449@cindex frame pointer
2450Inside your program, stack frames are identified by their addresses. A
2451stack frame consists of many bytes, each of which has its own address; each
2452kind of computer has a convention for choosing one of those bytes whose
2453address serves as the address of the frame. Usually this address is kept
2454in a register called the @dfn{frame pointer register} while execution is
2455going on in that frame.
2456
2457@cindex frame number
2458_GDBN__ assigns numbers to all existing stack frames, starting with
2459zero for the innermost frame, one for the frame that called it,
2460and so on upward. These numbers do not really exist in your program;
2461they are assigned by _GDBN__ to give you a way of designating stack
2462frames in _GDBN__ commands.
2463
2464@cindex frameless execution
2465Some compilers allow functions to be compiled so that they operate
2466without stack frames. (For example, the @code{_GCC__} option
2467@samp{-fomit-frame-pointer} will generate functions without a frame.)
2468This is occasionally done with heavily used library functions to save
2469the frame setup time. _GDBN__ has limited facilities for dealing with
2470these function invocations. If the innermost function invocation has no
2471stack frame, _GDBN__ will nevertheless regard it as though it had a
2472separate frame, which is numbered zero as usual, allowing correct
2473tracing of the function call chain. However, _GDBN__ has no provision
2474for frameless functions elsewhere in the stack.
2475
2476@node Backtrace, Selection, Frames, Stack
2477@section Backtraces
2478
2479A backtrace is a summary of how the program got where it is. It shows one
2480line per frame, for many frames, starting with the currently executing
2481frame (frame zero), followed by its caller (frame one), and on up the
2482stack.
2483
2484@table @code
2485@item backtrace
2486@itemx bt
2487@kindex backtrace
2488@kindex bt
2489Print a backtrace of the entire stack: one line per frame for all
2490frames in the stack.
2491
2492You can stop the backtrace at any time by typing the system interrupt
2493character, normally @kbd{C-c}.
2494
2495@item backtrace @var{n}
2496@itemx bt @var{n}
2497Similar, but print only the innermost @var{n} frames.
2498
2499@item backtrace -@var{n}
2500@itemx bt -@var{n}
2501Similar, but print only the outermost @var{n} frames.
2502@end table
2503
2504@kindex where
2505@kindex info stack
2506@kindex info s
2507The names @code{where} and @code{info stack} (abbreviated @code{info s})
2508are additional aliases for @code{backtrace}.
2509
2510Each line in the backtrace shows the frame number and the function name.
2511The program counter value is also shown---unless you use @code{set
2512print address off}. The backtrace also shows the source file name and
2513line number, as well as the arguments to the function. The program
2514counter value is omitted if it is at the beginning of the code for that
2515line number.
2516
2517Here is an example of a backtrace. It was made with the command
2518@samp{bt 3}, so it shows the innermost three frames.
2519
2520@smallexample
2521@group
2522#0 m4_traceon (obs=0x24eb0, argc=1, argv=0x2b8c8) at builtin.c:993
2523#1 0x6e38 in expand_macro (sym=0x2b600) at macro.c:242
2524#2 0x6840 in expand_token (obs=0x0, t=177664, td=0xf7fffb08)
2525 at macro.c:71
2526(More stack frames follow...)
2527@end group
2528@end smallexample
2529
2530@noindent
2531The display for frame zero doesn't begin with a program counter
2532value, indicating that the program has stopped at the beginning of the
2533code for line @code{993} of @code{builtin.c}.
2534
2535@node Selection, Frame Info, Backtrace, Stack
2536@section Selecting a Frame
2537
2538Most commands for examining the stack and other data in the program work on
2539whichever stack frame is selected at the moment. Here are the commands for
2540selecting a stack frame; all of them finish by printing a brief description
2541of the stack frame just selected.
2542
2543@table @code
2544@item frame @var{n}
2545@itemx f @var{n}
2546@kindex frame
2547@kindex f
2548Select frame number @var{n}. Recall that frame zero is the innermost
2549(currently executing) frame, frame one is the frame that called the
2550innermost one, and so on. The highest-numbered frame is @code{main}'s
2551frame.
2552
2553@item frame @var{addr}
2554@itemx f @var{addr}
2555Select the frame at address @var{addr}. This is useful mainly if the
2556chaining of stack frames has been damaged by a bug, making it
2557impossible for _GDBN__ to assign numbers properly to all frames. In
2558addition, this can be useful when the program has multiple stacks and
2559switches between them.
2560
2561_if_(_SPARC__)
2562On the SPARC architecture, @code{frame} needs two addresses to
2563select an arbitrary frame: a frame pointer and a stack pointer.
2564@c note to future updaters: this is conditioned on a flag
2565@c FRAME_SPECIFICATION_DYADIC in the tm-*.h files, currently only used
2566@c by SPARC, hence the specific attribution. Generalize or list all
2567@c possibilities if more supported machines start doing this.
2568_fi_(_SPARC__)
2569
2570@item up @var{n}
2571@kindex up
2572Move @var{n} frames up the stack. For positive numbers @var{n}, this
2573advances toward the outermost frame, to higher frame numbers, to frames
2574that have existed longer. @var{n} defaults to one.
2575
2576@item down @var{n}
2577@kindex down
2578@kindex do
2579Move @var{n} frames down the stack. For positive numbers @var{n}, this
2580advances toward the innermost frame, to lower frame numbers, to frames
2581that were created more recently. @var{n} defaults to one. You may
2582abbreviate @code{down} as @code{do}.
2583@end table
2584
2585All of these commands end by printing two lines of output describing the
2586frame. The first line shows the frame number, the function name, the
2587arguments, and the source file and line number of execution in that
2588frame. The second line shows the text of that source line. For
2589example:
2590
2591@smallexample
2592(_GDBP__) up
2593#1 0x22f0 in main (argc=1, argv=0xf7fffbf4, env=0xf7fffbfc) at env.c:10
259410 read_input_file (argv[i]);
2595@end smallexample
2596
2597After such a printout, the @code{list} command with no arguments will print
2598ten lines centered on the point of execution in the frame. @xref{List}.
2599
2600@table @code
2601@item up-silently @var{n}
2602@itemx down-silently @var{n}
2603@kindex down-silently
2604@kindex up-silently
2605These two commands are variants of @code{up} and @code{down},
2606respectively; they differ in that they do their work silently, without
2607causing display of the new frame. They are intended primarily for use
2608in _GDBN__ command scripts, where the output might be unnecessary and
2609distracting.
2610
2611@end table
2612
2613@node Frame Info, , Selection, Stack
2614@section Information About a Frame
2615
2616There are several other commands to print information about the selected
2617stack frame.
2618
2619@table @code
2620@item frame
2621@itemx f
2622When used without any argument, this command does not change which frame
2623is selected, but prints a brief description of the currently
2624selected stack frame. It can be abbreviated @code{f}. With an
2625argument, this command is used to select a stack frame (@pxref{Selection}).
2626
2627@item info frame
2628@kindex info frame
2629@itemx info f
2630@kindex info f
2631This command prints a verbose description of the selected stack frame,
2632including the address of the frame, the addresses of the next frame down
2633(called by this frame) and the next frame up (caller of this frame),
2634the address of the frame's arguments, the program counter saved in it
2635(the address of execution in the caller frame), and which registers
2636were saved in the frame. The verbose description is useful when
2637something has gone wrong that has made the stack format fail to fit
2638the usual conventions.
2639
2640@item info frame @var{addr}
2641@itemx info f @var{addr}
2642Print a verbose description of the frame at address @var{addr},
2643without selecting that frame. The selected frame remains unchanged by
2644this command.
2645
2646@item info args
2647@kindex info args
2648Print the arguments of the selected frame, each on a separate line.
2649
2650@item info locals
2651@kindex info locals
2652Print the local variables of the selected frame, each on a separate
2653line. These are all variables declared static or automatic within all
2654program blocks that execution in this frame is currently inside of.
2655
2656@item info catch
2657@kindex info catch
2658@cindex catch exceptions
2659@cindex exception handlers
2660Print a list of all the exception handlers that are active in the
2661current stack frame at the current point of execution. To see other
2662exception handlers, visit the associated frame (using the @code{up},
2663@code{down}, or @code{frame} commands); then type @code{info catch}.
2664@xref{Exception Handling}.
2665@end table
2666
2667@node Source, Data, Stack, Top
2668@chapter Examining Source Files
2669
2670_GDBN__ can print parts of your program's source, since the debugging
2671information recorded in your program tells _GDBN__ what source files
2672were used to built it. When your program stops, _GDBN__ spontaneously
2673prints the line where it stopped. Likewise, when you select a stack
2674frame (@pxref{Selection}), _GDBN__ prints the line where execution in
2675that frame has stopped. You can print other portions of source files by
2676explicit command.
2677
2678If you use _GDBN__ through its GNU Emacs interface, you may prefer to
2679use Emacs facilities to view source; @pxref{Emacs}.
2680
2681@menu
2682* List:: Printing Source Lines
2683* Search:: Searching Source Files
2684* Source Path:: Specifying Source Directories
2685* Machine Code:: Source and Machine Code
2686@end menu
2687
2688@node List, Search, Source, Source
2689@section Printing Source Lines
2690
2691@kindex list
2692@kindex l
2693To print lines from a source file, use the @code{list} command
2694(abbreviated @code{l}). There are several ways to specify what part
2695of the file you want to print.
2696
2697Here are the forms of the @code{list} command most commonly used:
2698
2699@table @code
2700@item list @var{linenum}
2701Print ten lines centered around line number @var{linenum} in the
2702current source file.
2703
2704@item list @var{function}
2705Print ten lines centered around the beginning of function
2706@var{function}.
2707
2708@item list
2709Print ten more lines. If the last lines printed were printed with a
2710@code{list} command, this prints ten lines following the last lines
2711printed; however, if the last line printed was a solitary line printed
2712as part of displaying a stack frame (@pxref{Stack}), this prints ten
2713lines centered around that line.
2714
2715@item list -
2716Print ten lines just before the lines last printed.
2717@end table
2718
2719Repeating a @code{list} command with @key{RET} discards the argument,
2720so it is equivalent to typing just @code{list}. This is more useful
2721than listing the same lines again. An exception is made for an
2722argument of @samp{-}; that argument is preserved in repetition so that
2723each repetition moves up in the source file.
2724
2725@cindex linespec
2726In general, the @code{list} command expects you to supply zero, one or two
2727@dfn{linespecs}. Linespecs specify source lines; there are several ways
2728of writing them but the effect is always to specify some source line.
2729Here is a complete description of the possible arguments for @code{list}:
2730
2731@table @code
2732@item list @var{linespec}
2733Print ten lines centered around the line specified by @var{linespec}.
2734
2735@item list @var{first},@var{last}
2736Print lines from @var{first} to @var{last}. Both arguments are
2737linespecs.
2738
2739@item list ,@var{last}
2740Print ten lines ending with @var{last}.
2741
2742@item list @var{first},
2743Print ten lines starting with @var{first}.
2744
2745@item list +
2746Print ten lines just after the lines last printed.
2747
2748@item list -
2749Print ten lines just before the lines last printed.
2750
2751@item list
2752As described in the preceding table.
2753@end table
2754
2755Here are the ways of specifying a single source line---all the
2756kinds of linespec.
2757
2758@table @code
2759@item @var{number}
2760Specifies line @var{number} of the current source file.
2761When a @code{list} command has two linespecs, this refers to
2762the same source file as the first linespec.
2763
2764@item +@var{offset}
2765Specifies the line @var{offset} lines after the last line printed.
2766When used as the second linespec in a @code{list} command that has
2767two, this specifies the line @var{offset} lines down from the
2768first linespec.
2769
2770@item -@var{offset}
2771Specifies the line @var{offset} lines before the last line printed.
2772
2773@item @var{filename}:@var{number}
2774Specifies line @var{number} in the source file @var{filename}.
2775
2776@item @var{function}
2777@c FIXME: "of the open-brace" is C-centric. When we add other langs...
2778Specifies the line of the open-brace that begins the body of the
2779function @var{function}.
2780
2781@item @var{filename}:@var{function}
2782Specifies the line of the open-brace that begins the body of the
2783function @var{function} in the file @var{filename}. You only need the
2784file name with a function name to avoid ambiguity when there are
2785identically named functions in different source files.
2786
2787@item *@var{address}
2788Specifies the line containing the program address @var{address}.
2789@var{address} may be any expression.
2790@end table
2791
2792@node Search, Source Path, List, Source
2793@section Searching Source Files
2794@cindex searching
2795@kindex reverse-search
2796
2797There are two commands for searching through the current source file for a
2798regular expression.
2799
2800@table @code
2801@item forward-search @var{regexp}
2802@itemx search @var{regexp}
2803@kindex search
2804@kindex forward-search
2805The command @samp{forward-search @var{regexp}} checks each line, starting
2806with the one following the last line listed, for a match for @var{regexp}.
2807It lists the line that is found. You can abbreviate the command name
2808as @code{fo}. The synonym @samp{search @var{regexp}} is also supported.
2809
2810@item reverse-search @var{regexp}
2811The command @samp{reverse-search @var{regexp}} checks each line, starting
2812with the one before the last line listed and going backward, for a match
2813for @var{regexp}. It lists the line that is found. You can abbreviate
2814this command as @code{rev}.
2815@end table
2816
2817@node Source Path, Machine Code, Search, Source
2818@section Specifying Source Directories
2819
2820@cindex source path
2821@cindex directories for source files
2822Executable programs sometimes do not record the directories of the source
2823files from which they were compiled, just the names. Even when they do,
2824the directories could be moved between the compilation and your debugging
2825session. _GDBN__ has a list of directories to search for source files;
2826this is called the @dfn{source path}. Each time _GDBN__ wants a source file,
2827it tries all the directories in the list, in the order they are present
2828in the list, until it finds a file with the desired name. Note that
2829the executable search path is @emph{not} used for this purpose. Neither is
2830the current working directory, unless it happens to be in the source
2831path.
2832
2833If _GDBN__ can't find a source file in the source path, and the object
2834program records a directory, _GDBN__ tries that directory too. If the
2835source path is empty, and there is no record of the compilation
2836directory, _GDBN__ will, as a last resort, look in the current
2837directory.
2838
2839Whenever you reset or rearrange the source path, _GDBN__ will clear out
2840any information it has cached about where source files are found, where
2841each line is in the file, etc.
2842
2843@kindex directory
2844When you start _GDBN__, its source path is empty.
2845To add other directories, use the @code{directory} command.
2846
2847@table @code
2848@item directory @var{dirname} @dots{}
2849Add directory @var{dirname} to the front of the source path. Several
2850directory names may be given to this command, separated by @samp{:} or
2851whitespace. You may specify a directory that is already in the source
7463aadd
RP
2852path; this moves it forward, so it will be searched sooner.
2853
2854You can use the string @samp{$cdir} to refer to the compilation
2855directory (if one is recorded), and @samp{$cwd} to refer to the current
2856working directory. @samp{$cwd} is not the same as @samp{.}---the former
2857tracks the current working directory as it changes during your _GDBN__
2858session, while the latter is immediately expanded to the current
2859directory at the time you add an entry to the source path.
70b88761
RP
2860
2861@item directory
2862Reset the source path to empty again. This requires confirmation.
2863
2864@c RET-repeat for @code{directory} is explicitly disabled, but since
2865@c repeating it would be a no-op we don't say that. (thanks to RMS)
2866
2867@item show directories
2868@kindex show directories
2869Print the source path: show which directories it contains.
2870@end table
2871
2872If your source path is cluttered with directories that are no longer of
2873interest, _GDBN__ may sometimes cause confusion by finding the wrong
2874versions of source. You can correct the situation as follows:
2875
2876@enumerate
2877@item
2878Use @code{directory} with no argument to reset the source path to empty.
2879
2880@item
2881Use @code{directory} with suitable arguments to reinstall the
2882directories you want in the source path. You can add all the
2883directories in one command.
2884@end enumerate
2885
2886@node Machine Code, , Source Path, Source
2887@section Source and Machine Code
2888You can use the command @code{info line} to map source lines to program
2889addresses (and viceversa), and the command @code{disassemble} to display
2890a range of addresses as machine instructions.
2891
2892@table @code
2893@item info line @var{linespec}
2894@kindex info line
2895Print the starting and ending addresses of the compiled code for
2896source line @var{linespec}. You can specify source lines in any of the
2897ways understood by the @code{list} command (@pxref{List}).
2898@end table
2899
2900For example, we can use @code{info line} to inquire on where the object
2901code for the first line of function @code{m4_changequote} lies:
2902@smallexample
2903(_GDBP__) info line m4_changecom
2904Line 895 of "builtin.c" starts at pc 0x634c and ends at 0x6350.
2905@end smallexample
2906
2907@noindent
2908We can also inquire (using @code{*@var{addr}} as the form for
2909@var{linespec}) what source line covers a particular address:
2910@smallexample
2911(_GDBP__) info line *0x63ff
2912Line 926 of "builtin.c" starts at pc 0x63e4 and ends at 0x6404.
2913@end smallexample
2914
2915@kindex $_
2916After @code{info line}, the default address for the @code{x}
2917command is changed to the starting address of the line, so that
2918@samp{x/i} is sufficient to begin examining the machine code
2919(@pxref{Memory}). Also, this address is saved as the value of the
2920convenience variable @code{$_} (@pxref{Convenience Vars}).
2921
2922@table @code
2923@kindex disassemble
2924@item disassemble
2925This specialized command is provided to dump a range of memory as
2926machine instructions. The default memory range is the function
2927surrounding the program counter of the selected frame. A single
2928argument to this command is a program counter value; the function
2929surrounding this value will be dumped. Two arguments (separated by one
2930or more spaces) specify a range of addresses (first inclusive, second
2931exclusive) to be dumped.
2932@end table
2933
2934We can use @code{disassemble} to inspect the object code
2935range shown in the last @code{info line} example:
2936
2937@smallexample
2938(_GDBP__) disas 0x63e4 0x6404
2939Dump of assembler code from 0x63e4 to 0x6404:
29400x63e4 <builtin_init+5340>: ble 0x63f8 <builtin_init+5360>
29410x63e8 <builtin_init+5344>: sethi %hi(0x4c00), %o0
29420x63ec <builtin_init+5348>: ld [%i1+4], %o0
29430x63f0 <builtin_init+5352>: b 0x63fc <builtin_init+5364>
29440x63f4 <builtin_init+5356>: ld [%o0+4], %o0
29450x63f8 <builtin_init+5360>: or %o0, 0x1a4, %o0
29460x63fc <builtin_init+5364>: call 0x9288 <path_search>
29470x6400 <builtin_init+5368>: nop
2948End of assembler dump.
2949(_GDBP__)
2950
2951@end smallexample
2952
2953@node Data, Symbols, Source, Top
2954@chapter Examining Data
2955
2956@cindex printing data
2957@cindex examining data
2958@kindex print
2959@kindex inspect
2960@c "inspect" isn't quite a synonym if you're using Epoch, which we don't
2961@c document because it's nonstandard... Under Epoch it displays in a
2962@c different window or something like that.
2963The usual way to examine data in your program is with the @code{print}
2964command (abbreviated @code{p}), or its synonym @code{inspect}. It
2965evaluates and prints the value of any valid expression of the language
2966the program is written in (for now, C or C++). You type
2967
2968@example
2969print @var{exp}
2970@end example
2971
2972@noindent
2973where @var{exp} is any valid expression (in the source language), and
2974the value of @var{exp} is printed in a format appropriate to its data
2975type.
2976
2977A more low-level way of examining data is with the @code{x} command.
2978It examines data in memory at a specified address and prints it in a
2979specified format. @xref{Memory}.
2980
2981@menu
2982* Expressions:: Expressions
2983* Variables:: Program Variables
2984* Arrays:: Artificial Arrays
2985* Output formats:: Output formats
2986* Memory:: Examining Memory
2987* Auto Display:: Automatic Display
2988* Print Settings:: Print Settings
2989* Value History:: Value History
2990* Convenience Vars:: Convenience Variables
2991* Registers:: Registers
2992* Floating Point Hardware:: Floating Point Hardware
2993@end menu
2994
2995@node Expressions, Variables, Data, Data
2996@section Expressions
2997
2998@cindex expressions
2999@code{print} and many other _GDBN__ commands accept an expression and
3000compute its value. Any kind of constant, variable or operator defined
3001by the programming language you are using is legal in an expression in
3002_GDBN__. This includes conditional expressions, function calls, casts
3003and string constants. It unfortunately does not include symbols defined
3004by preprocessor @code{#define} commands, or C++ expressions involving
3005@samp{::}, the name resolution operator.
3006@c FIXME: actually C++ a::b works except in obscure circumstances where it
3007@c FIXME...can conflict with GDB's own name scope resolution.
3008
3009Casts are supported in all languages, not just in C, because it is so
3010useful to cast a number into a pointer so as to examine a structure
3011at that address in memory.
3012
3013_GDBN__ supports three kinds of operator in addition to those of programming
3014languages:
3015
3016@table @code
3017@item @@
3018@samp{@@} is a binary operator for treating parts of memory as arrays.
3019@xref{Arrays}, for more information.
3020
3021@item ::
3022@samp{::} allows you to specify a variable in terms of the file or
3023function where it is defined. @xref{Variables}.
3024
3025@item @{@var{type}@} @var{addr}
3026Refers to an object of type @var{type} stored at address @var{addr} in
3027memory. @var{addr} may be any expression whose value is an integer or
3028pointer (but parentheses are required around binary operators, just as in
3029a cast). This construct is allowed regardless of what kind of data is
3030normally supposed to reside at @var{addr}.@refill
3031@end table
3032
3033@node Variables, Arrays, Expressions, Data
3034@section Program Variables
3035
3036The most common kind of expression to use is the name of a variable
3037in your program.
3038
3039Variables in expressions are understood in the selected stack frame
3040(@pxref{Selection}); they must either be global (or static) or be visible
3041according to the scope rules of the programming language from the point of
3042execution in that frame. This means that in the function
3043
3044@example
3045foo (a)
3046 int a;
3047@{
3048 bar (a);
3049 @{
3050 int b = test ();
3051 bar (b);
3052 @}
3053@}
3054@end example
3055
3056@noindent
3057the variable @code{a} is usable whenever the program is executing
3058within the function @code{foo}, but the variable @code{b} is visible
3059only while the program is executing inside the block in which @code{b}
3060is declared.
3061
3062@cindex variable name conflict
3063There is an exception: you can refer to a variable or function whose
3064scope is a single source file even if the current execution point is not
3065in this file. But it is possible to have more than one such variable or
3066function with the same name (in different source files). If that happens,
3067referring to that name has unpredictable effects. If you wish, you can
3068specify a variable in a particular file, using the colon-colon notation:
3069
3070@cindex colon-colon
3071@kindex ::
3072@example
3073@var{file}::@var{variable}
3074@end example
3075
3076@noindent
3077Here @var{file} is the name of the source file whose variable you want.
3078
3079@cindex C++ name resolution
3080This use of @samp{::} is very rarely in conflict with the very similar
3081use of the same notation in C++. _GDBN__ also supports use of the C++
3082name resolution operator in _GDBN__ expressions.
3083
3d3ab540
RP
3084@cindex wrong values
3085@cindex variable values, wrong
3086@quotation
3087@emph{Warning:} Occasionally, a local variable may appear to have the
3088wrong value at certain points in a function---just after entry to the
3089function, and just before exit. You may see this problem when you're
3090stepping by machine instructions. This is because on most machines, it
3091takes more than one instruction to set up a stack frame (including local
3092variable definitions); if you're stepping by machine instructions,
3093variables may appear to have the wrong values until the stack frame is
3094completely built. On function exit, it usually also takes more than one
3095machine instruction to destroy a stack frame; after you begin stepping
3096through that group of instructions, local variable definitions may be
3097gone.
3098@end quotation
3099
70b88761
RP
3100@node Arrays, Output formats, Variables, Data
3101@section Artificial Arrays
3102
3103@cindex artificial array
3104@kindex @@
3105It is often useful to print out several successive objects of the
3106same type in memory; a section of an array, or an array of
3107dynamically determined size for which only a pointer exists in the
3108program.
3109
3110This can be done by constructing an @dfn{artificial array} with the
3111binary operator @samp{@@}. The left operand of @samp{@@} should be
3112the first element of the desired array, as an individual object.
3113The right operand should be the desired length of the array. The result is
3114an array value whose elements are all of the type of the left argument.
3115The first element is actually the left argument; the second element
3116comes from bytes of memory immediately following those that hold the
3117first element, and so on. Here is an example. If a program says
3118
3119@example
3120int *array = (int *) malloc (len * sizeof (int));
3121@end example
3122
3123@noindent
3124you can print the contents of @code{array} with
3125
3126@example
3127p *array@@len
3128@end example
3129
3130The left operand of @samp{@@} must reside in memory. Array values made
3131with @samp{@@} in this way behave just like other arrays in terms of
3132subscripting, and are coerced to pointers when used in expressions.
3133Artificial arrays most often appear in expressions via the value history
3134(@pxref{Value History}), after printing one out.)
3135
3d3ab540
RP
3136Sometimes the artificial array mechanism isn't quite enough; in
3137moderately complex data structures, the elements of interest may not
3138actually be adjacent---for example, if you're interested in the values
3139of pointers in an array. One useful work-around in this situation is to
3140use a convenience variable (@pxref{Convenience Vars}) as a counter in an
3141expression that prints the first interesting value, and then repeat that
3142expression via @key{RET}. For instance, suppose you have an array
3143@code{dtab} of pointers to structures, and you're interested in the
3144values of a field @code{fv} in each structure. Here's an example of
3145what you might type:
3146@example
3147set $i = 0
3148p dtab[$i++]->fv
3149@key{RET}
3150@key{RET}
3151@dots{}
3152@end example
3153
70b88761
RP
3154@node Output formats, Memory, Arrays, Data
3155@section Output formats
3156
3157@cindex formatted output
3158@cindex output formats
3159By default, _GDBN__ prints a value according to its data type. Sometimes
3160this is not what you want. For example, you might want to print a number
3161in hex, or a pointer in decimal. Or you might want to view data in memory
3162at a certain address as a character string or as an instruction. To do
3163these things, specify an @dfn{output format} when you print a value.
3164
3165The simplest use of output formats is to say how to print a value
3166already computed. This is done by starting the arguments of the
3167@code{print} command with a slash and a format letter. The format
3168letters supported are:
3169
3170@table @code
3171@item x
3172Regard the bits of the value as an integer, and print the integer in
3173hexadecimal.
3174
3175@item d
3176Print as integer in signed decimal.
3177
3178@item u
3179Print as integer in unsigned decimal.
3180
3181@item o
3182Print as integer in octal.
3183
3184@item t
3185Print as integer in binary. The letter @samp{t} stands for ``two''.
3186
3187@item a
3188Print as an address, both absolute in hex and as an offset from the
3189nearest preceding symbol. This format can be used to discover where (in
3190what function) an unknown address is located:
3191@example
3192(_GDBP__) p/a 0x54320
3193_0__$3 = 0x54320 <_initialize_vx+396>_1__
3194@end example
3195
3196
3197@item c
3198Regard as an integer and print it as a character constant.
3199
3200@item f
3201Regard the bits of the value as a floating point number and print
3202using typical floating point syntax.
3203@end table
3204
3205For example, to print the program counter in hex (@pxref{Registers}), type
3206
3207@example
3208p/x $pc
3209@end example
3210
3211@noindent
3212Note that no space is required before the slash; this is because command
3213names in _GDBN__ cannot contain a slash.
3214
3215To reprint the last value in the value history with a different format,
3216you can use the @code{print} command with just a format and no
3217expression. For example, @samp{p/x} reprints the last value in hex.
3218
3219@node Memory, Auto Display, Output formats, Data
3220@section Examining Memory
3221
3222@cindex examining memory
3223@table @code
3224@kindex x
3225@item x/@var{nfu} @var{expr}
3226The command @code{x} (for `examine') can be used to examine memory
3227without being constrained by your program's data types. You can specify
3228the unit size @var{u} of memory to inspect, and a repeat count @var{n} of how
3229many of those units to display. @code{x} understands the formats
3230@var{f} used by @code{print}; two additional formats, @samp{s} (string)
3231and @samp{i} (machine instruction) can be used without specifying a unit
3232size.
3233@end table
3234
3235For example, @samp{x/3uh 0x54320} is a request to display three halfwords
3236(@code{h}) of memory, formatted as unsigned decimal integers (@samp{u}),
3237starting at address @code{0x54320}. @samp{x/4xw $sp} prints the four
3238words (@samp{w}) of memory above the stack pointer (here, @samp{$sp};
3239@pxref{Registers}) in hexadecimal (@samp{x}).
3240
3241Since the letters indicating unit sizes are all distinct from the
3242letters specifying output formats, you don't have to remember whether
3243unit size or format comes first; either order will work. The output
3244specifications @samp{4xw} and @samp{4wx} mean exactly the same thing.
3245
3246After the format specification, you supply an expression for the address
3247where _GDBN__ is to begin reading from memory. The expression need not
3248have a pointer value (though it may); it is always interpreted as an
3249integer address of a byte of memory. @xref{Expressions} for more
3250information on expressions.
3251
3252These are the memory units @var{u} you can specify with the @code{x}
3253command:
3254
3255@table @code
3256@item b
3257Examine individual bytes.
3258
3259@item h
3260Examine halfwords (two bytes each).
3261
3262@item w
3263Examine words (four bytes each).
3264
3265@cindex word
3266Many assemblers and cpu designers still use `word' for a 16-bit quantity,
3267as a holdover from specific predecessor machines of the 1970's that really
3268did use two-byte words. But more generally the term `word' has always
3269referred to the size of quantity that a machine normally operates on and
3270stores in its registers. This is 32 bits for all the machines that _GDBN__
3271runs on.
3272
3273@item g
3274Examine giant words (8 bytes).
3275@end table
3276
3277You can combine these unit specifications with any of the formats
3278described for @code{print}. @xref{Output formats}.
3279
3280@code{x} has two additional output specifications which derive the unit
3281size from the data inspected:
3282
3283@table @code
3284@item s
3285Print a null-terminated string of characters. Any explicitly specified
3286unit size is ignored; instead, the unit is however many bytes it takes
3287to reach a null character (including the null character).
3288
3289@item i
3290Print a machine instruction in assembler syntax (or nearly). Any
3291specified unit size is ignored; the number of bytes in an instruction
3292varies depending on the type of machine, the opcode and the addressing
3293modes used. The command @code{disassemble} gives an alternative way of
3294inspecting machine instructions. @xref{Machine Code}.
3295@end table
3296
3297If you omit either the format @var{f} or the unit size @var{u}, @code{x}
3298will use the same one that was used last. If you don't use any letters
3299or digits after the slash, you can omit the slash as well.
3300
3301You can also omit the address to examine. Then the address used is just
3302after the last unit examined. This is why string and instruction
3303formats actually compute a unit-size based on the data: so that the next
3304string or instruction examined will start in the right place.
3305
3306When the @code{print} command shows a value that resides in memory,
3307@code{print} also sets the default address for the @code{x} command.
3308@code{info line} also sets the default for @code{x}, to the address of
3309the start of the machine code for the specified line (@pxref{Machine
3310Code}), and @code{info breakpoints} sets it to the address of the last
3311breakpoint listed (@pxref{Set Breaks}).
3312
3313When you use @key{RET} to repeat an @code{x} command, the address
3314specified previously (if any) is ignored, so that the repeated command
3315examines the successive locations in memory rather than the same ones.
3316
3317You can examine several consecutive units of memory with one command by
3318writing a repeat-count after the slash (before the format letters, if
3319any). Omitting the repeat count @var{n} displays one unit of the
3320appropriate size. The repeat count must be a decimal integer. It has
3321the same effect as repeating the @code{x} command @var{n} times except
3322that the output may be more compact, with several units per line. For
3323example,
3324
3325@example
3326x/10i $pc
3327@end example
3328
3329@noindent
3330prints ten instructions starting with the one to be executed next in the
3331selected frame. After doing this, you could print a further seven
3332instructions with
3333
3334@example
3335x/7
3336@end example
3337
3338@noindent
3339---where the format and address are allowed to default.
3340
3341@kindex $_
3342@kindex $__
3343The addresses and contents printed by the @code{x} command are not put
3344in the value history because there is often too much of them and they
3345would get in the way. Instead, _GDBN__ makes these values available for
3346subsequent use in expressions as values of the convenience variables
3347@code{$_} and @code{$__}. After an @code{x} command, the last address
3348examined is available for use in expressions in the convenience variable
3349@code{$_}. The contents of that address, as examined, are available in
3350the convenience variable @code{$__}.
3351
3352If the @code{x} command has a repeat count, the address and contents saved
3353are from the last memory unit printed; this is not the same as the last
3354address printed if several units were printed on the last line of output.
3355
3356@node Auto Display, Print Settings, Memory, Data
3357@section Automatic Display
3358@cindex automatic display
3359@cindex display of expressions
3360
3361If you find that you want to print the value of an expression frequently
3362(to see how it changes), you might want to add it to the @dfn{automatic
3363display list} so that _GDBN__ will print its value each time the program stops.
3364Each expression added to the list is given a number to identify it;
3365to remove an expression from the list, you specify that number.
3366The automatic display looks like this:
3367
3368@example
33692: foo = 38
33703: bar[5] = (struct hack *) 0x3804
3371@end example
3372
3373@noindent
3374showing item numbers, expressions and their current values. As with
3375displays you request manually using @code{x} or @code{print}, you can
3376specify the output format you prefer; in fact, @code{display} decides
3377whether to use @code{print} or @code{x} depending on how elaborate your
3378format specification is---it uses @code{x} if you specify a unit size,
3379or one of the two formats (@samp{i} and @samp{s}) that are only
3380supported by @code{x}; otherwise it uses @code{print}.
3381
3382@table @code
3383@item display @var{exp}
3384@kindex display
3385Add the expression @var{exp} to the list of expressions to display
3386each time the program stops. @xref{Expressions}.
3387
3388@code{display} will not repeat if you press @key{RET} again after using it.
3389
3390@item display/@var{fmt} @var{exp}
3391For @var{fmt} specifying only a display format and not a size or
3392count, add the expression @var{exp} to the auto-display list but
3393arranges to display it each time in the specified format @var{fmt}.
3394@xref{Output formats}.
3395
3396@item display/@var{fmt} @var{addr}
3397For @var{fmt} @samp{i} or @samp{s}, or including a unit-size or a
3398number of units, add the expression @var{addr} as a memory address to
3399be examined each time the program stops. Examining means in effect
3400doing @samp{x/@var{fmt} @var{addr}}. @xref{Memory}.
3401@end table
3402
3403For example, @samp{display/i $pc} can be helpful, to see the machine
3404instruction about to be executed each time execution stops (@samp{$pc}
3405is a common name for the program counter; @pxref{Registers}).
3406
3407@table @code
3408@item undisplay @var{dnums}@dots{}
3409@itemx delete display @var{dnums}@dots{}
3410@kindex delete display
3411@kindex undisplay
3412Remove item numbers @var{dnums} from the list of expressions to display.
3413
3414@code{undisplay} will not repeat if you press @key{RET} after using it.
3415(Otherwise you would just get the error @samp{No display number @dots{}}.)
3416
3417@item disable display @var{dnums}@dots{}
3418@kindex disable display
3419Disable the display of item numbers @var{dnums}. A disabled display
3420item is not printed automatically, but is not forgotten. It may be
3421enabled again later.
3422
3423@item enable display @var{dnums}@dots{}
3424@kindex enable display
3425Enable display of item numbers @var{dnums}. It becomes effective once
3426again in auto display of its expression, until you specify otherwise.
3427
3428@item display
3429Display the current values of the expressions on the list, just as is
3430done when the program stops.
3431
3432@item info display
3433@kindex info display
3434Print the list of expressions previously set up to display
3435automatically, each one with its item number, but without showing the
3436values. This includes disabled expressions, which are marked as such.
3437It also includes expressions which would not be displayed right now
3438because they refer to automatic variables not currently available.
3439@end table
3440
3441If a display expression refers to local variables, then it does not make
3442sense outside the lexical context for which it was set up. Such an
3443expression is disabled when execution enters a context where one of its
3444variables is not defined. For example, if you give the command
3445@code{display last_char} while inside a function with an argument
3446@code{last_char}, then this argument will be displayed while the program
3447continues to stop inside that function. When it stops elsewhere---where
3448there is no variable @code{last_char}---display is disabled. The next time
3449your program stops where @code{last_char} is meaningful, you can enable the
3450display expression once again.
3451
3452@node Print Settings, Value History, Auto Display, Data
3453@section Print Settings
3454
3455@cindex format options
3456@cindex print settings
3457_GDBN__ provides the following ways to control how arrays, structures,
3458and symbols are printed.
3459
3460@noindent
3461These settings are useful for debugging programs in any language:
3462
3463@table @code
3464@item set print address
3465@item set print address on
3466@kindex set print address
3467_GDBN__ will print memory addresses showing the location of stack
3468traces, structure values, pointer values, breakpoints, and so forth,
3469even when it also displays the contents of those addresses. The default
3470is on. For example, this is what a stack frame display looks like, with
3471@code{set print address on}:
3472@smallexample
3473(_GDBP__) f
3474#0 set_quotes (lq=0x34c78 "<<", rq=0x34c88 ">>")
3475 at input.c:530
3476530 if (lquote != def_lquote)
3477@end smallexample
3478
3479@item set print address off
3480Do not print addresses when displaying their contents. For example,
3481this is the same stack frame displayed with @code{set print address off}:
3482@example
3483(_GDBP__) set print addr off
3484(_GDBP__) f
3485#0 set_quotes (lq="<<", rq=">>") at input.c:530
3486530 if (lquote != def_lquote)
3487@end example
3488
3489@item show print address
3490@kindex show print address
3491Show whether or not addresses are to be printed.
3492
3493@item set print array
3494@itemx set print array on
3495@kindex set print array
3496_GDBN__ will pretty print arrays. This format is more convenient to read,
3497but uses more space. The default is off.
3498
3499@item set print array off.
3500Return to compressed format for arrays.
3501
3502@item show print array
3503@kindex show print array
3504Show whether compressed or pretty format is selected for displaying
3505arrays.
3506
3507@item set print elements @var{number-of-elements}
3508@kindex set print elements
3509If _GDBN__ is printing a large array, it will stop printing after it has
3510printed the number of elements set by the @code{set print elements} command.
3511This limit also applies to the display of strings.
3512
3513@item show print elements
3514@kindex show print elements
3515Display the number of elements of a large array that _GDBN__ will print
3516before losing patience.
3517
3518@item set print pretty on
3519@kindex set print pretty
3520Cause _GDBN__ to print structures in an indented format with one member per
3521line, like this:
3522
3523@example
3524$1 = @{
3525 next = 0x0,
3526 flags = @{
3527 sweet = 1,
3528 sour = 1
3529 @},
3530 meat = 0x54 "Pork"
3531@}
3532@end example
3533
3534@item set print pretty off
3535Cause _GDBN__ to print structures in a compact format, like this:
3536
3537@smallexample
3538$1 = @{next = 0x0, flags = @{sweet = 1, sour = 1@}, meat \
3539= 0x54 "Pork"@}
3540@end smallexample
3541
3542@noindent
3543This is the default format.
3544
3545@item show print pretty
3546@kindex show print pretty
3547Show which format _GDBN__ will use to print structures.
3548
3549@item set print sevenbit-strings on
3550Print using only seven-bit characters; if this option is set,
3551_GDBN__ will display any eight-bit characters (in strings or character
3552values) using the notation @code{\}@var{nnn}. For example, @kbd{M-a} is
3553displayed as @code{\341}.
3554
3555@item set print sevenbit-strings off
3556Print using either seven-bit or eight-bit characters, as required. This
3557is the default.
3558
3559@item show print sevenbit-strings
3560Show whether or not _GDBN__ will print only seven-bit characters.
3561
3562@item set print union on
3563@kindex set print union
3564Tell _GDBN__ to print unions which are contained in structures. This is the
3565default setting.
3566
3567@item set print union off
3568Tell _GDBN__ not to print unions which are contained in structures.
3569
3570@item show print union
3571@kindex show print union
3572Ask _GDBN__ whether or not it will print unions which are contained in
3573structures.
3574
3575For example, given the declarations
3576
3577@smallexample
3578typedef enum @{Tree, Bug@} Species;
3579typedef enum @{Big_tree, Acorn, Seedling@} Tree_forms;
3580typedef enum @{Caterpillar, Cocoon, Butterfly@} Bug_forms;
3581
3582struct thing @{
3583 Species it;
3584 union @{
3585 Tree_forms tree;
3586 Bug_forms bug;
3587 @} form;
3588@};
3589
3590struct thing foo = @{Tree, @{Acorn@}@};
3591@end smallexample
3592
3593@noindent
3594with @code{set print union on} in effect @samp{p foo} would print
3595
3596@smallexample
3597$1 = @{it = Tree, form = @{tree = Acorn, bug = Cocoon@}@}
3598@end smallexample
3599
3600@noindent
3601and with @code{set print union off} in effect it would print
3602
3603@smallexample
3604$1 = @{it = Tree, form = @{...@}@}
3605@end smallexample
3606@end table
3607
3608@noindent
3609These settings are of interest when debugging C++ programs:
3610
3611@table @code
3612@item set print demangle
3613@itemx set print demangle on
3614@kindex set print demangle
3615Print C++ names in their source form rather than in the mangled form
3616in which they are passed to the assembler and linker for type-safe linkage.
3617The default is on.
3618
3619@item show print demangle
3620@kindex show print demangle
3621Show whether C++ names will be printed in mangled or demangled form.
3622
3623@item set print asm-demangle
3624@itemx set print asm-demangle on
3625@kindex set print asm-demangle
3626Print C++ names in their source form rather than their mangled form, even
3627in assembler code printouts such as instruction disassemblies.
3628The default is off.
3629
3630@item show print asm-demangle
3631@kindex show print asm-demangle
3632Show whether C++ names in assembly listings will be printed in mangled
3633or demangled form.
3634
3635@item set print object
3636@itemx set print object on
3637@kindex set print object
3638When displaying a pointer to an object, identify the @emph{actual}
3639(derived) type of the object rather than the @emph{declared} type, using
3640the virtual function table.
3641
3642@item set print object off
3643Display only the declared type of objects, without reference to the
3644virtual function table. This is the default setting.
3645
3646@item show print object
3647@kindex show print object
3648Show whether actual, or declared, object types will be displayed.
3649
3650@item set print vtbl
3651@itemx set print vtbl on
3652@kindex set print vtbl
3653Pretty print C++ virtual function tables. The default is off.
3654
3655@item set print vtbl off
3656Do not pretty print C++ virtual function tables.
3657
3658@item show print vtbl
3659@kindex show print vtbl
3660Show whether C++ virtual function tables are pretty printed, or not.
3661
3662@end table
3663
3664@node Value History, Convenience Vars, Print Settings, Data
3665@section Value History
3666
3667@cindex value history
3668Values printed by the @code{print} command are saved in _GDBN__'s @dfn{value
3669history} so that you can refer to them in other expressions. Values are
3670kept until the symbol table is re-read or discarded (for example with
3671the @code{file} or @code{symbol-file} commands). When the symbol table
3672changes, the value history is discarded, since the values may contain
3673pointers back to the types defined in the symbol table.
3674
3675@cindex @code{$}
3676@cindex @code{$$}
3677@cindex history number
3678The values printed are given @dfn{history numbers} for you to refer to them
3679by. These are successive integers starting with one. @code{print} shows you
3680the history number assigned to a value by printing @samp{$@var{num} = }
3681before the value; here @var{num} is the history number.
3682
3683To refer to any previous value, use @samp{$} followed by the value's
3684history number. The way @code{print} labels its output is designed to
3685remind you of this. Just @code{$} refers to the most recent value in
3686the history, and @code{$$} refers to the value before that.
3687@code{$$@var{n}} refers to the @var{n}th value from the end; @code{$$2}
3688is the value just prior to @code{$$}, @code{$$1} is equivalent to
3689@code{$$}, and @code{$$0} is equivalent to @code{$}.
3690
3691For example, suppose you have just printed a pointer to a structure and
3692want to see the contents of the structure. It suffices to type
3693
3694@example
3695p *$
3696@end example
3697
3698If you have a chain of structures where the component @code{next} points
3699to the next one, you can print the contents of the next one with this:
3700
3701@example
3702p *$.next
3703@end example
3704
3705@noindent
3706You can print successive links in the chain by repeating this
3707command---which you can do by just typing @key{RET}.
3708
3709Note that the history records values, not expressions. If the value of
3710@code{x} is 4 and you type these commands:
3711
3712@example
3713print x
3714set x=5
3715@end example
3716
3717@noindent
3718then the value recorded in the value history by the @code{print} command
3719remains 4 even though the value of @code{x} has changed.
3720
3721@table @code
3722@kindex show values
3723@item show values
3724Print the last ten values in the value history, with their item numbers.
3725This is like @samp{p@ $$9} repeated ten times, except that @code{show
3726values} does not change the history.
3727
3728@item show values @var{n}
3729Print ten history values centered on history item number @var{n}.
3730
3731@item show values +
3732Print ten history values just after the values last printed. If no more
3733values are available, produces no display.
3734@end table
3735
3736Pressing @key{RET} to repeat @code{show values @var{n}} has exactly the
3737same effect as @samp{show values +}.
3738
3739@node Convenience Vars, Registers, Value History, Data
3740@section Convenience Variables
3741
3742@cindex convenience variables
3743_GDBN__ provides @dfn{convenience variables} that you can use within
3744_GDBN__ to hold on to a value and refer to it later. These variables
3745exist entirely within _GDBN__; they are not part of your program, and
3746setting a convenience variable has no direct effect on further execution
3747of your program. That's why you can use them freely.
3748
3749Convenience variables are prefixed with @samp{$}. Any name preceded by
3750@samp{$} can be used for a convenience variable, unless it is one of
3751the predefined machine-specific register names (@pxref{Registers}).
3752(Value history references, in contrast, are @emph{numbers} preceded
3753by @samp{$}. @xref{Value History}.)
3754
3755You can save a value in a convenience variable with an assignment
3756expression, just as you would set a variable in your program. Example:
3757
3758@example
3759set $foo = *object_ptr
3760@end example
3761
3762@noindent
3763would save in @code{$foo} the value contained in the object pointed to by
3764@code{object_ptr}.
3765
3766Using a convenience variable for the first time creates it; but its value
3767is @code{void} until you assign a new value. You can alter the value with
3768another assignment at any time.
3769
3770Convenience variables have no fixed types. You can assign a convenience
3771variable any type of value, including structures and arrays, even if
3772that variable already has a value of a different type. The convenience
3773variable, when used as an expression, has the type of its current value.
3774
3775@table @code
3776@item show convenience
3777@kindex show convenience
3778Print a list of convenience variables used so far, and their values.
3779Abbreviated @code{show con}.
3780@end table
3781
3782One of the ways to use a convenience variable is as a counter to be
3783incremented or a pointer to be advanced. For example, to print
3784a field from successive elements of an array of structures:
3785
3786_0__@example
3787set $i = 0
3788print bar[$i++]->contents
3789@i{@dots{} repeat that command by typing @key{RET}.}
3790_1__@end example
3791
3792Some convenience variables are created automatically by _GDBN__ and given
3793values likely to be useful.
3794
3795@table @code
3796@item $_
3797The variable @code{$_} is automatically set by the @code{x} command to
3798the last address examined (@pxref{Memory}). Other commands which
3799provide a default address for @code{x} to examine also set @code{$_}
3800to that address; these commands include @code{info line} and @code{info
3801breakpoint}.
3802
3803@item $__
3804The variable @code{$__} is automatically set by the @code{x} command
3805to the value found in the last address examined.
3806@end table
3807
3808@node Registers, Floating Point Hardware, Convenience Vars, Data
3809@section Registers
3810
3811@cindex registers
3812Machine register contents can be referred to in expressions as variables
3813with names starting with @samp{$}. The names of registers are different
3814for each machine; use @code{info registers} to see the names used on
3815your machine.
3816
3817@table @code
3818@item info registers
3819@kindex info registers
3820Print the names and values of all registers (in the selected stack frame).
3821
3822@item info registers @var{regname}
3823Print the relativized value of register @var{regname}. @var{regname}
3824may be any register name valid on the machine you are using, with
3825or without the initial @samp{$}.
3826@end table
3827
3828The register names @code{$pc} and @code{$sp} are used on most machines
3829for the program counter register and the stack pointer. For example,
3830you could print the program counter in hex with
3831@example
3832p/x $pc
3833@end example
3834
3835@noindent
3836or print the instruction to be executed next with
3837@example
3838x/i $pc
3839@end example
3840
3841@noindent
3842or add four to the stack pointer with
3843@example
3844set $sp += 4
3845@end example
3846
3847@noindent
3848The last is a way of removing one word from the stack, on machines where
3849stacks grow downward in memory (most machines, nowadays). This assumes
3850that the innermost stack frame is selected; setting @code{$sp} is
3851not allowed when other stack frames are selected. (To pop entire frames
3852off the stack, regardless of machine architecture, use @code{return};
3853@pxref{Returning}.)
3854
3855Often @code{$fp} is used for a register that contains a pointer to the
3856current stack frame, and @code{$ps} is sometimes used for a register
3857that contains the processor status. These standard register names may
3858be available on your machine even though the @code{info registers}
3859command shows other names. For example, on the SPARC, @code{info
3860registers} displays the processor status register as @code{$psr} but you
3861can also refer to it as @code{$ps}.
3862
3863_GDBN__ always considers the contents of an ordinary register as an
3864integer when the register is examined in this way. Some machines have
3865special registers which can hold nothing but floating point; these
3866registers are considered to have floating point values. There is no way
3867to refer to the contents of an ordinary register as floating point value
3868(although you can @emph{print} it as a floating point value with
3869@samp{print/f $@var{regname}}).
3870
3871Some registers have distinct ``raw'' and ``virtual'' data formats. This
3872means that the data format in which the register contents are saved by
3873the operating system is not the same one that your program normally
3874sees. For example, the registers of the 68881 floating point
3875coprocessor are always saved in ``extended'' (raw) format, but all C
3876programs expect to work with ``double'' (virtual) format. In such
3877cases, _GDBN__ normally works with the virtual format only (the format that
3878makes sense for your program), but the @code{info registers} command
3879prints the data in both formats.
3880
3881Normally, register values are relative to the selected stack frame
3882(@pxref{Selection}). This means that you get the value that the
3883register would contain if all stack frames farther in were exited and
3884their saved registers restored. In order to see the true contents of
3885hardware registers, you must select the innermost frame (with
3886@samp{frame 0}).
3887
3888However, _GDBN__ must deduce where registers are saved, from the machine
3889code generated by your compiler. If some registers are not saved, or if
3890_GDBN__ is unable to locate the saved registers, the selected stack
3891frame will make no difference.
3892
3893@node Floating Point Hardware, , Registers, Data
3894@section Floating Point Hardware
3895@cindex floating point
3896Depending on the host machine architecture, _GDBN__ may be able to give
3897you more information about the status of the floating point hardware.
3898
3899@table @code
3900@item info float
3901@kindex info float
3902If available, provides hardware-dependent information about the floating
3903point unit. The exact contents and layout vary depending on the
3904floating point chip.
3905@end table
3906@c FIXME: this is a cop-out. Try to get examples, explanations. Only
3907@c FIXME...supported currently on arm's and 386's. Mark properly with
3908@c FIXME... m4 macros to isolate general statements from hardware-dep,
3909@c FIXME... at that point.
3910
3911@node Symbols, Altering, Data, Top
3912@chapter Examining the Symbol Table
3913
3914The commands described in this section allow you to inquire about the
3915symbols (names of variables, functions and types) defined in your
3916program. This information is inherent in the text of your program and
3917does not change as the program executes. _GDBN__ finds it in your
3918program's symbol table, in the file indicated when you started _GDBN__
3919(@pxref{File Options}), or by one of the file-management commands
3920(@pxref{Files}).
3921
3922@table @code
3923@item info address @var{symbol}
3924@kindex info address
3925Describe where the data for @var{symbol} is stored. For a register
3926variable, this says which register it is kept in. For a non-register
3927local variable, this prints the stack-frame offset at which the variable
3928is always stored.
3929
3930Note the contrast with @samp{print &@var{symbol}}, which does not work
3931at all for a register variables, and for a stack local variable prints
3932the exact address of the current instantiation of the variable.
3933
3934@item whatis @var{exp}
3935@kindex whatis
3936Print the data type of expression @var{exp}. @var{exp} is not
3937actually evaluated, and any side-effecting operations (such as
3938assignments or function calls) inside it do not take place.
3939@xref{Expressions}.
3940
3941@item whatis
3942Print the data type of @code{$}, the last value in the value history.
3943
3944@item ptype @var{typename}
3945@kindex ptype
3946Print a description of data type @var{typename}. @var{typename} may be
3947the name of a type, or for C code it may have the form
3948@samp{struct @var{struct-tag}}, @samp{union @var{union-tag}} or
3949@samp{enum @var{enum-tag}}.@refill
3950
3951@item ptype @var{exp}
3952Print a description of the type of expression @var{exp}. @code{ptype}
3953differs from @code{whatis} by printing a detailed description, instead of just
3954the name of the type. For example, if your program declares a variable
3955as
3956@example
3957struct complex @{double real; double imag;@} v;
3958@end example
3959@noindent
3960compare the output of the two commands:
3961@example
3962(_GDBP__) whatis v
3963type = struct complex
3964(_GDBP__) ptype v
3965type = struct complex @{
3966 double real;
3967 double imag;
3968@}
3969@end example
3970
3971@item info types @var{regexp}
3972@itemx info types
3973@kindex info types
3974Print a brief description of all types whose name matches @var{regexp}
3975(or all types in your program, if you supply no argument). Each
3976complete typename is matched as though it were a complete line; thus,
3977@samp{i type value} gives information on all types in your program whose
3978name includes the string @code{value}, but @samp{i type ^value$} gives
3979information only on types whose complete name is @code{value}.
3980
3981This command differs from @code{ptype} in two ways: first, like
3982@code{whatis}, it does not print a detailed description; second, it
3983lists all source files where a type is defined.
3984
3985@item info source
3986@kindex info source
3987Show the name of the current source file---that is, the source file for
3988the function containing the current point of execution.
3989
3990@item info sources
3991@kindex info sources
3992Print the names of all source files in the program for which there is
3993debugging information, organized into two lists: those for which symbols
3994have been read in, and those for which symbols will be read in on
3995demand.
3996@c FIXME: above passive AND awkward!
3997
3998@item info functions
3999@kindex info functions
4000Print the names and data types of all defined functions.
4001
4002@item info functions @var{regexp}
4003Print the names and data types of all defined functions
4004whose names contain a match for regular expression @var{regexp}.
4005Thus, @samp{info fun step} finds all functions whose names
4006include @code{step}; @samp{info fun ^step} finds those whose names
4007start with @code{step}.
4008
4009@item info variables
4010@kindex info variables
4011Print the names and data types of all variables that are declared
4012outside of functions (i.e., excluding local variables).
4013
4014@item info variables @var{regexp}
4015Print the names and data types of all variables (except for local
4016variables) whose names contain a match for regular expression
4017@var{regexp}.
4018
4019
4020@ignore
4021This was never implemented.
4022@item info methods
4023@itemx info methods @var{regexp}
4024@kindex info methods
4025The @code{info methods} command permits the user to examine all defined
4026methods within C++ program, or (with the @var{regexp} argument) a
4027specific set of methods found in the various C++ classes. Many
4028C++ classes provide a large number of methods. Thus, the output
4029from the @code{ptype} command can be overwhelming and hard to use. The
4030@code{info-methods} command filters the methods, printing only those
4031which match the regular-expression @var{regexp}.
4032@end ignore
4033
4034@item printsyms @var{filename}
4035@kindex printsyms
4036Write a complete dump of the debugger's symbol data into the
4037file @var{filename}.
4038@end table
4039
4040@node Altering, _GDBN__ Files, Symbols, Top
4041@chapter Altering Execution
4042
4043Once you think you have found an error in the program, you might want to
4044find out for certain whether correcting the apparent error would lead to
4045correct results in the rest of the run. You can find the answer by
4046experiment, using the _GDBN__ features for altering execution of the
4047program.
4048
4049For example, you can store new values into variables or memory
4050locations, give the program a signal, restart it at a different address,
4051or even return prematurely from a function to its caller.
4052
4053@menu
4054* Assignment:: Assignment to Variables
4055* Jumping:: Continuing at a Different Address
4056* Signaling:: Giving the Program a Signal
4057* Returning:: Returning from a Function
4058* Calling:: Calling your Program's Functions
4059@end menu
4060
4061@node Assignment, Jumping, Altering, Altering
4062@section Assignment to Variables
4063
4064@cindex assignment
4065@cindex setting variables
4066To alter the value of a variable, evaluate an assignment expression.
4067@xref{Expressions}. For example,
4068
4069@example
4070print x=4
4071@end example
4072
4073@noindent
4074would store the value 4 into the variable @code{x}, and then print the
4075value of the assignment expression (which is 4). All the assignment
4076operators of C are supported, including the increment operators
4077@samp{++} and @samp{--}, and combining assignments such as @samp{+=} and
4078_0__@samp{<<=}_1__.
4079
4080@kindex set
4081@kindex set variable
4082@cindex variables, setting
4083If you are not interested in seeing the value of the assignment, use the
4084@code{set} command instead of the @code{print} command. @code{set} is
4085really the same as @code{print} except that the expression's value is not
4086printed and is not put in the value history (@pxref{Value History}). The
4087expression is evaluated only for its effects.
4088
4089If the beginning of the argument string of the @code{set} command
4090appears identical to a @code{set} subcommand, use the @code{set
4091variable} command instead of just @code{set}. This command is identical
4092to @code{set} except for its lack of subcommands. For example, a
4093program might well have a variable @code{width}---which leads to
4094an error if we try to set a new value with just @samp{set width=13}, as
4095we might if @code{set width} didn't happen to be a _GDBN__ command:
4096@example
4097(_GDBP__) whatis width
4098type = double
4099(_GDBP__) p width
4100$4 = 13
4101(_GDBP__) set width=47
4102Invalid syntax in expression.
4103@end example
4104@noindent
4105The invalid expression, of course, is @samp{=47}. What we can do in
4106order to actually set our program's variable @code{width} is
4107@example
4108(_GDBP__) set var width=47
4109@end example
4110
4111_GDBN__ allows more implicit conversions in assignments than C does; you can
4112freely store an integer value into a pointer variable or vice versa, and
4113any structure can be converted to any other structure that is the same
4114length or shorter.
4115@comment FIXME: how do structs align/pad in these conversions?
4116@comment /[email protected] 18dec1990
4117
4118To store values into arbitrary places in memory, use the @samp{@{@dots{}@}}
4119construct to generate a value of specified type at a specified address
4120(@pxref{Expressions}). For example, @code{@{int@}0x83040} refers
4121to memory location @code{0x83040} as an integer (which implies a certain size
4122and representation in memory), and
4123
4124@example
4125set @{int@}0x83040 = 4
4126@end example
4127
4128@noindent
4129stores the value 4 into that memory location.
4130
4131@node Jumping, Signaling, Assignment, Altering
4132@section Continuing at a Different Address
4133
4134Ordinarily, when you continue the program, you do so at the place where
4135it stopped, with the @code{continue} command. You can instead continue at
4136an address of your own choosing, with the following commands:
4137
4138@table @code
4139@item jump @var{linespec}
4140@kindex jump
4141Resume execution at line @var{linespec}. Execution will stop
4142immediately if there is a breakpoint there. @xref{List} for a
4143description of the different forms of @var{linespec}.
4144
4145The @code{jump} command does not change the current stack frame, or
4146the stack pointer, or the contents of any memory location or any
4147register other than the program counter. If line @var{linespec} is in
4148a different function from the one currently executing, the results may
4149be bizarre if the two functions expect different patterns of arguments or
4150of local variables. For this reason, the @code{jump} command requests
4151confirmation if the specified line is not in the function currently
4152executing. However, even bizarre results are predictable if you are
4153well acquainted with the machine-language code of the program.
4154
4155@item jump *@var{address}
4156Resume execution at the instruction at address @var{address}.
4157@end table
4158
4159You can get much the same effect as the @code{jump} command by storing a
4160new value into the register @code{$pc}. The difference is that this
4161does not start the program running; it only changes the address where it
4162@emph{will} run when it is continued. For example,
4163
4164@example
4165set $pc = 0x485
4166@end example
4167
4168@noindent
4169causes the next @code{continue} command or stepping command to execute at
4170address 0x485, rather than at the address where the program stopped.
3d3ab540 4171@xref{Continuing and Stepping}.
70b88761
RP
4172
4173The most common occasion to use the @code{jump} command is to back up,
4174perhaps with more breakpoints set, over a portion of a program that has
4175already executed, in order to examine its execution in more detail.
4176
4177@node Signaling, Returning, Jumping, Altering
4178@c @group
4179@section Giving the Program a Signal
4180
4181@table @code
4182@item signal @var{signalnum}
4183@kindex signal
4184Resume execution where the program stopped, but give it immediately the
4185signal number @var{signalnum}.
4186
4187Alternatively, if @var{signalnum} is zero, continue execution without
4188giving a signal. This is useful when the program stopped on account of
4189a signal and would ordinary see the signal when resumed with the
4190@code{continue} command; @samp{signal 0} causes it to resume without a
4191signal.
4192
4193@code{signal} does not repeat when you press @key{RET} a second time
4194after executing the command.
4195@end table
4196@c @end group
4197
4198@node Returning, Calling, Signaling, Altering
4199@section Returning from a Function
4200
4201@table @code
4202@item return
4203@itemx return @var{expression}
4204@cindex returning from a function
4205@kindex return
4206You can cancel execution of a function call with the @code{return}
4207command. If you give an
4208@var{expression} argument, its value is used as the function's return
4209value.
4210@end table
4211
4212When you use @code{return}, _GDBN__ discards the selected stack frame
4213(and all frames within it). You can think of this as making the
4214discarded frame return prematurely. If you wish to specify a value to
4215be returned, give that value as the argument to @code{return}.
4216
4217This pops the selected stack frame (@pxref{Selection}), and any other
4218frames inside of it, leaving its caller as the innermost remaining
4219frame. That frame becomes selected. The specified value is stored in
4220the registers used for returning values of functions.
4221
4222The @code{return} command does not resume execution; it leaves the
4223program stopped in the state that would exist if the function had just
3d3ab540
RP
4224returned. In contrast, the @code{finish} command (@pxref{Continuing and
4225Stepping}) resumes execution until the selected stack frame returns
4226naturally.@refill
70b88761
RP
4227
4228@node Calling, , Returning, Altering
4229@section Calling your Program's Functions
4230
4231@cindex calling functions
4232@kindex call
4233@table @code
4234@item call @var{expr}
4235Evaluate the expression @var{expr} without displaying @code{void}
4236returned values.
4237@end table
4238
4239You can use this variant of the @code{print} command if you want to
4240execute a function from your program, but without cluttering the output
4241with @code{void} returned values. The result is printed and saved in
4242the value history, if it is not void.
4243
4244@node _GDBN__ Files, Targets, Altering, Top
4245@chapter _GDBN__'s Files
4246
4247@menu
4248* Files:: Commands to Specify Files
4249* Symbol Errors:: Errors Reading Symbol Files
4250@end menu
4251
4252@node Files, Symbol Errors, _GDBN__ Files, _GDBN__ Files
4253@section Commands to Specify Files
4254@cindex core dump file
4255@cindex symbol table
4256_GDBN__ needs to know the file name of the program to be debugged, both in
4257order to read its symbol table and in order to start the program. To
4258debug a core dump of a previous run, _GDBN__ must be told the file name of
4259the core dump.
4260
4261The usual way to specify the executable and core dump file names is with
4262the command arguments given when you start _GDBN__, as discussed in
4263@pxref{Invocation}.
4264
4265Occasionally it is necessary to change to a different file during a
4266_GDBN__ session. Or you may run _GDBN__ and forget to specify the files you
4267want to use. In these situations the _GDBN__ commands to specify new files
4268are useful.
4269
4270@table @code
4271@item file @var{filename}
4272@cindex executable file
4273@kindex file
4274Use @var{filename} as the program to be debugged. It is read for its
4275symbols and for the contents of pure memory. It is also the program
4276executed when you use the @code{run} command. If you do not specify a
4277directory and the file is not found in _GDBN__'s working directory,
4278
4279_GDBN__ uses the environment variable @code{PATH} as a list of
4280directories to search, just as the shell does when looking for a program
4281to run. You can change the value of this variable, for both _GDBN__ and
4282your program, using the @code{path} command.
4283
4284@code{file} with no argument makes _GDBN__ discard any information it
4285has on both executable file and the symbol table.
4286
4287@item exec-file @var{filename}
4288@kindex exec-file
4289Specify that the program to be run (but not the symbol table) is found
4290in @var{filename}. _GDBN__ will search the environment variable @code{PATH}
4291if necessary to locate the program.
4292
4293@item symbol-file @var{filename}
4294@kindex symbol-file
4295Read symbol table information from file @var{filename}. @code{PATH} is
4296searched when necessary. Use the @code{file} command to get both symbol
4297table and program to run from the same file.
4298
4299@code{symbol-file} with no argument clears out _GDBN__'s information on your
4300program's symbol table.
4301
4302The @code{symbol-file} command causes _GDBN__ to forget the contents of its
4303convenience variables, the value history, and all breakpoints and
4304auto-display expressions. This is because they may contain pointers to
4305the internal data recording symbols and data types, which are part of
4306the old symbol table data being discarded inside _GDBN__.
4307
4308@code{symbol-file} will not repeat if you press @key{RET} again after
4309executing it once.
4310
4311On some kinds of object files, the @code{symbol-file} command does not
4312actually read the symbol table in full right away. Instead, it scans
4313the symbol table quickly to find which source files and which symbols
4314are present. The details are read later, one source file at a time,
4315when they are needed.
4316
4317The purpose of this two-stage reading strategy is to make _GDBN__ start up
4318faster. For the most part, it is invisible except for occasional pauses
4319while the symbol table details for a particular source file are being
4320read. (The @code{set verbose} command can turn these pauses into
4321messages if desired. @xref{Messages/Warnings}).
4322
4323When the symbol table is stored in COFF format, @code{symbol-file} does
4324read the symbol table data in full right away. We haven't implemented
4325the two-stage strategy for COFF yet.
4326
4327When _GDBN__ is configured for a particular environment, it will
4328understand debugging information in whatever format is the standard
4329generated for that environment; you may use either a GNU compiler, or
4330other compilers that adhere to the local conventions. Best results are
4331usually obtained from GNU compilers; for example, using @code{_GCC__}
4332you can generate debugging information for optimized code.
4333
4334@item core-file @var{filename}
4335@itemx core @var{filename}
4336@kindex core
4337@kindex core-file
4338Specify the whereabouts of a core dump file to be used as the ``contents
4339of memory''. Traditionally, core files contain only some parts of the
4340address space of the process that generated them; _GDBN__ can access the
4341executable file itself for other parts.
4342
4343@code{core-file} with no argument specifies that no core file is
4344to be used.
4345
4346Note that the core file is ignored when your program is actually running
4347under _GDBN__. So, if you have been running the program and you wish to
4348debug a core file instead, you must kill the subprocess in which the
4349program is running. To do this, use the @code{kill} command
4350(@pxref{Kill Process}).
4351
4352@item load @var{filename}
4353@kindex load
4354_if__(_GENERIC__)
4355Depending on what remote debugging facilities are configured into
4356_GDBN__, the @code{load} command may be available. Where it exists, it
4357is meant to make @var{filename} (an executable) available for debugging
4358on the remote system---by downloading, or dynamic linking, for example.
4359@code{load} also records @var{filename}'s symbol table in _GDBN__, like
4360the @code{add-symbol-file} command.
4361
4362If @code{load} is not available on your _GDBN__, attempting to execute
4363it gets the error message ``@code{You can't do that when your target is
4364@dots{}}''
4365_fi__(_GENERIC__)
4366
4367_if__(_VXWORKS__)
4368On VxWorks, @code{load} will dynamically link @var{filename} on the
4369current target system as well as adding its symbols in _GDBN__.
4370_fi__(_VXWORKS__)
4371
4372_if__(_I960__)
4373@cindex download to Nindy-960
4374With the Nindy interface to an Intel 960 board, @code{load} will
4375download @var{filename} to the 960 as well as adding its symbols in
4376_GDBN__.
4377_fi__(_I960__)
4378
4379@code{load} will not repeat if you press @key{RET} again after using it.
4380
4381@item add-symbol-file @var{filename} @var{address}
4382@kindex add-symbol-file
4383@cindex dynamic linking
4384The @code{add-symbol-file} command reads additional symbol table information
4385from the file @var{filename}. You would use this command when that file
4386has been dynamically loaded (by some other means) into the program that
4387is running. @var{address} should be the memory address at which the
4388file has been loaded; _GDBN__ cannot figure this out for itself.
4389
4390The symbol table of the file @var{filename} is added to the symbol table
4391originally read with the @code{symbol-file} command. You can use the
4392@code{add-symbol-file} command any number of times; the new symbol data thus
4393read keeps adding to the old. To discard all old symbol data instead,
4394use the @code{symbol-file} command.
4395
4396@code{add-symbol-file} will not repeat if you press @key{RET} after using it.
4397
4398@item info files
4399@itemx info target
4400@kindex info files
4401@kindex info target
4402@code{info files} and @code{info target} are synonymous; both print the
4403current targets (@pxref{Targets}), including the names of the executable
4404and core dump files currently in use by _GDBN__, and the files from
4405which symbols were loaded. The command @code{help targets} lists all
4406possible targets rather than current ones.
4407
4408@end table
4409
4410All file-specifying commands allow both absolute and relative file names
4411as arguments. _GDBN__ always converts the file name to an absolute path
4412name and remembers it that way.
4413
4414@kindex sharedlibrary
4415@kindex share
4416@cindex shared libraries
4417
4418_GDBN__ supports the SunOS shared library format. Symbols from a shared
4419library cannot be referenced before the shared library has been linked
4420with the program. (That is to say, until after you type @code{run} and
4421the function @code{main} has been entered; or when examining core
4422files.) Once the shared library has been linked in, you can use the
4423following commands:
4424
4425@table @code
4426@item sharedlibrary @var{regex}
4427@itemx share @var{regex}
4428Load shared object library symbols for files matching a UNIX regular
4429expression.
4430
4431@item share
4432@itemx sharedlibrary
4433Load symbols for all shared libraries.
4434
4435@item info share
4436@itemx info sharedlibrary
4437@kindex info sharedlibrary
4438@kindex info share
4439Print the names of the shared libraries which you have loaded with the
4440@code{sharedlibrary} command.
4441@end table
4442
4443@code{sharedlibrary} does not repeat automatically when you press
4444@key{RET} after using it once.
4445
4446@node Symbol Errors, , Files, _GDBN__ Files
4447@section Errors Reading Symbol Files
4448While a symbol file is being read, _GDBN__ will occasionally encounter
4449problems, such as symbol types it does not recognize, or known bugs in
4450compiler output. By default, it prints one message about each such
4451type of problem, no matter how many times the problem occurs. You can
4452ask it to print more messages, to see how many times the problems occur,
4453or can shut the messages off entirely, with the @code{set
4454complaints} command (@xref{Messages/Warnings}).
4455
4456The messages currently printed, and their meanings, are:
4457
4458@table @code
4459@item inner block not inside outer block in @var{symbol}
4460
4461The symbol information shows where symbol scopes begin and end
4462(such as at the start of a function or a block of statements). This
4463error indicates that an inner scope block is not fully contained
4464in its outer scope blocks.
4465
4466_GDBN__ circumvents the problem by treating the inner block as if it had
4467the same scope as the outer block. In the error message, @var{symbol}
4468may be shown as ``@code{(don't know)}'' if the outer block is not a
4469function.
4470
4471@item block at @var{address} out of order
4472
4473The symbol information for symbol scope blocks should occur in
4474order of increasing addresses. This error indicates that it does not
4475do so.
4476
4477_GDBN__ does not circumvent this problem, and will have trouble locating
4478symbols in the source file whose symbols being read. (You can often
4479determine what source file is affected by specifying @code{set verbose
4480on}. @xref{Messages/Warnings}.)
4481
4482@item bad block start address patched
4483
4484The symbol information for a symbol scope block has a start address
4485smaller than the address of the preceding source line. This is known
4486to occur in the SunOS 4.1.1 (and earlier) C compiler.
4487
4488_GDBN__ circumvents the problem by treating the symbol scope block as
4489starting on the previous source line.
4490
4491@c @item{encountered DBX-style class variable debugging information.
4492@c You seem to have compiled your program with "g++ -g0" instead of "g++ -g".
4493@c Therefore _GDBN__ will not know about your class variables}
4494@c
4495@c This error indicates that the symbol information produced for a C++
4496@c program includes zero-size fields, which indicated static fields in
4497@c a previous release of the G++ compiler. This message is probably
4498@c obsolete.
4499@c
4500@item bad string table offset in symbol @var{n}
4501
4502@cindex foo
4503Symbol number @var{n} contains a pointer into the string table which is
4504larger than the size of the string table.
4505
4506_GDBN__ circumvents the problem by considering the symbol to have the
4507name @code{foo}, which may cause other problems if many symbols end up
4508with this name.
4509
4510@item unknown symbol type @code{0x@var{nn}}
4511
4512The symbol information contains new data types that _GDBN__ does not yet
4513know how to read. @code{0x@var{nn}} is the symbol type of the misunderstood
4514information, in hexadecimal.
4515
4516_GDBN__ circumvents the error by ignoring this symbol information. This
4517will usually allow the program to be debugged, though certain symbols
4518will not be accessible. If you encounter such a problem and feel like
4519debugging it, you can debug @code{_GDBP__} with itself, breakpoint on
4520@code{complain}, then go up to the function @code{read_dbx_symtab} and
4521examine @code{*bufp} to see the symbol.
4522
4523@item stub type has NULL name
4524_GDBN__ could not find the full definition for a struct or class.
4525
4526@ignore
4527@c this is #if 0'd in dbxread.c as of (at least!) 17 may 1991
4528@item const/volatile indicator missing, got '@var{X}'
4529
4530The symbol information for a C++ member function is missing some
4531information that the compiler should have output for it.
4532@end ignore
4533
4534@item C++ type mismatch between compiler and debugger
4535
3d3ab540 4536_GDBN__ could not parse a type specification output by the compiler
70b88761
RP
4537for some C++ object.
4538
4539@end table
4540
4541@node Targets, Controlling _GDBN__, _GDBN__ Files, Top
4542@chapter Specifying a Debugging Target
4543@cindex debugging target
4544@kindex target
4545A @dfn{target} is an interface between the debugger and a particular
4546kind of file or process.
4547
4548Often, you will be able to run _GDBN__ in the same host environment as the
4549program you are debugging; in that case, the debugging target can just be
4550specified as a side effect of the @code{file} or @code{core} commands.
4551When you need more flexibility---for example, running _GDBN__ on a
4552physically separate host, controlling standalone systems over a
4553serial port, or realtime systems over a TCP/IP connection---you can use
4554the @code{target} command.
4555
4556@menu
4557* Active Targets:: Active Targets
4558* Target Commands:: Commands for Managing Targets
4559* Remote:: Remote Debugging
4560@end menu
4561
4562@node Active Targets, Target Commands, Targets, Targets
4563@section Active Targets
4564@cindex stacking targets
4565@cindex active targets
4566@cindex multiple targets
4567
4568Targets are managed in three @dfn{strata} that correspond to different
4569classes of target: processes, core files, and executable files. This
4570allows you to (for example) start a process and inspect its activity
4571without abandoning your work on a core file.
4572
4573More than one target can potentially respond to a request. In
4574particular, when you access memory _GDBN__ will examine the three strata of
4575targets until it finds a target that can handle that particular address.
4576Strata are always examined in a fixed order: first a process if there is
4577one, then a core file if there is one, and finally an executable file if
4578there is one of those.
4579
4580When you specify a new target in a given stratum, it replaces any target
4581previously in that stratum.
4582
4583To get rid of a target without replacing it, use the @code{detach}
4584command. The related command @code{attach} provides you with a way of
4585choosing a particular running process as a new target. @xref{Attach}.
4586
4587@node Target Commands, Remote, Active Targets, Targets
4588@section Commands for Managing Targets
4589
4590@table @code
4591@item target @var{type} @var{parameters}
4592Connects the _GDBN__ host environment to a target machine or process. A
4593target is typically a protocol for talking to debugging facilities. You
4594use the argument @var{type} to specify the type or protocol of the
4595target machine.
4596
4597Further @var{parameters} are interpreted by the target protocol, but
4598typically include things like device names or host names to connect
4599with, process numbers, and baud rates.
4600
4601The @code{target} command will not repeat if you press @key{RET} again
4602after executing the command.
4603
4604@item help target
4605@kindex help target
4606Displays the names of all targets available. To display targets
4607currently selected, use either @code{info target} or @code{info files}
4608(@pxref{Files}).
4609
4610@item help target @var{name}
4611Describe a particular target, including any parameters necessary to
4612select it.
4613@end table
4614
4615Here are some common targets (available, or not, depending on the _GDBN__
4616configuration):
4617
4618@table @code
4619@item target exec @var{prog}
4620@kindex target exec
4621An executable file. @samp{target exec @var{prog}} is the same as
4622@samp{exec-file @var{prog}}.
4623
4624@item target core @var{filename}
4625@kindex target core
4626A core dump file. @samp{target core @var{filename}} is the same as
4627@samp{core-file @var{filename}}.
4628
4629@item target remote @var{dev}
4630@kindex target remote
4631Remote serial target in _GDBN__-specific protocol. The argument @var{dev}
4632specifies what serial device to use for the connection (e.g.
4633@file{/dev/ttya}). @xref{Remote}.
4634
4635_if__(_AMD29K__)
4636@item target amd-eb @var{dev} @var{speed} @var{PROG}
4637@kindex target amd-eb
4638@cindex AMD EB29K
4639Remote PC-resident AMD EB29K board, attached over serial lines.
4640@var{dev} is the serial device, as for @code{target remote};
4641@var{speed} allows you to specify the linespeed; and @var{PROG} is the
4642name of the program to be debugged, as it appears to DOS on the PC.
4643@xref{EB29K Remote}.
4644
4645_fi__(_AMD29K__)
4646_if__(_I960__)
4647@item target nindy @var{devicename}
4648@kindex target nindy
4649An Intel 960 board controlled by a Nindy Monitor. @var{devicename} is
4650the name of the serial device to use for the connection, e.g.
4651@file{/dev/ttya}. @xref{i960-Nindy Remote}.
4652
4653_fi__(_I960__)
4654_if__(_VXWORKS__)
4655@item target vxworks @var{machinename}
4656@kindex target vxworks
4657A VxWorks system, attached via TCP/IP. The argument @var{machinename}
4658is the target system's machine name or IP address.
4659@xref{VxWorks Remote}.
4660_fi__(_VXWORKS__)
4661@end table
4662
4663_if__(_GENERIC__)
4664Different targets are available on different configurations of _GDBN__; your
4665configuration may have more or fewer targets.
4666_fi__(_GENERIC__)
4667
4668@node Remote, , Target Commands, Targets
4669@section Remote Debugging
4670@cindex remote debugging
4671
4672_if__(_GENERIC__)
4673@menu
4674_include__(gdbinv-m.m4)<>_dnl__
4675@end menu
4676_fi__(_GENERIC__)
4677
4678If you are trying to debug a program running on a machine that can't run
4679_GDBN__ in the usual way, it is often useful to use remote debugging. For
4680example, you might use remote debugging on an operating system kernel, or on
4681a small system which does not have a general purpose operating system
4682powerful enough to run a full-featured debugger.
4683
4684Some configurations of _GDBN__ have special serial or TCP/IP interfaces
4685to make this work with particular debugging targets. In addition,
4686_GDBN__ comes with a generic serial protocol (specific to _GDBN__, but
4687not specific to any particular target system) which you can use if you
4688write the remote stubs---the code that will run on the remote system to
4689communicate with _GDBN__.
4690
4691To use the _GDBN__ remote serial protocol, the program to be debugged on
4692the remote machine needs to contain a debugging stub which talks to
4693_GDBN__ over the serial line. Several working remote stubs are
4694distributed with _GDBN__; see the @file{README} file in the _GDBN__
4695distribution for more information.
4696
4697For details of this communication protocol, see the comments in the
4698_GDBN__ source file @file{remote.c}.
4699
4700To start remote debugging, first run _GDBN__ and specify as an executable file
4701the program that is running in the remote machine. This tells _GDBN__ how
4702to find the program's symbols and the contents of its pure text. Then
4703establish communication using the @code{target remote} command with a device
4704name as an argument. For example:
4705
4706@example
4707target remote /dev/ttyb
4708@end example
4709
4710@noindent
4711if the serial line is connected to the device named @file{/dev/ttyb}. This
4712will stop the remote machine if it is not already stopped.
4713
4714Now you can use all the usual commands to examine and change data and to
4715step and continue the remote program.
4716
4717To resume the remote program and stop debugging it, use the @code{detach}
4718command.
4719
4720Other remote targets may be available in your
4721configuration of _GDBN__; use @code{help targets} to list them.
4722
4723_if__(_GENERIC__)
4724@c Text on starting up GDB in various specific cases; it goes up front
4725@c in manuals configured for any of those particular situations, here
4726@c otherwise.
4727_include__(gdbinv-s.m4)
4728_fi__(_GENERIC__)
4729
4730@node Controlling _GDBN__, Sequences, Targets, Top
4731@chapter Controlling _GDBN__
4732
4733You can alter many aspects of _GDBN__'s interaction with you by using
4734the @code{set} command. For commands controlling how _GDBN__ displays
4735data, @pxref{Print Settings}; other settings are described here.
4736
4737@menu
4738* Prompt:: Prompt
4739* Editing:: Command Editing
4740* History:: Command History
4741* Screen Size:: Screen Size
4742* Numbers:: Numbers
4743* Messages/Warnings:: Optional Warnings and Messages
4744@end menu
4745
4746@node Prompt, Editing, Controlling _GDBN__, Controlling _GDBN__
4747@section Prompt
4748@cindex prompt
4749_GDBN__ indicates its readiness to read a command by printing a string
4750called the @dfn{prompt}. This string is normally @samp{(_GDBP__)}. You
4751can change the prompt string with the @code{set prompt} command. For
4752instance, when debugging _GDBN__ with _GDBN__, it is useful to change
4753the prompt in one of the _GDBN__<>s so that you can always tell which
4754one you are talking to.
4755
4756@table @code
4757@item set prompt @var{newprompt}
4758@kindex set prompt
4759Directs _GDBN__ to use @var{newprompt} as its prompt string henceforth.
4760@kindex show prompt
4761@item show prompt
4762Prints a line of the form: @samp{Gdb's prompt is: @var{your-prompt}}
4763@end table
4764
4765@node Editing, History, Prompt, Controlling _GDBN__
4766@section Command Editing
4767@cindex readline
4768@cindex command line editing
4769_GDBN__ reads its input commands via the @dfn{readline} interface. This
4770GNU library provides consistent behavior for programs which provide a
4771command line interface to the user. Advantages are @code{emacs}-style
4772or @code{vi}-style inline editing of commands, @code{csh}-like history
4773substitution, and a storage and recall of command history across
4774debugging sessions.
4775
4776You may control the behavior of command line editing in _GDBN__ with the
4777command @code{set}.
4778
4779@table @code
4780@kindex set editing
4781@cindex editing
4782@item set editing
4783@itemx set editing on
4784Enable command line editing (enabled by default).
4785
4786@item set editing off
4787Disable command line editing.
4788
4789@kindex show editing
4790@item show editing
4791Show whether command line editing is enabled.
4792@end table
4793
4794@node History, Screen Size, Editing, Controlling _GDBN__
4795@section Command History
4796@table @code
4797@cindex history substitution
4798@cindex history file
4799@kindex set history filename
4800@item set history filename @var{fname}
4801Set the name of the _GDBN__ command history file to @var{fname}. This is
4802the file from which _GDBN__ will read an initial command history
4803list or to which it will write this list when it exits. This list is
4804accessed through history expansion or through the history
4805command editing characters listed below. This file defaults to the
4806value of the environment variable @code{GDBHISTFILE}, or to
4807@file{./.gdb_history} if this variable is not set.
4808
4809@cindex history save
4810@kindex set history save
4811@item set history save
4812@itemx set history save on
4813Record command history in a file, whose name may be specified with the
4814@code{set history filename} command. By default, this option is disabled.
4815
4816@item set history save off
4817Stop recording command history in a file.
4818
4819@cindex history size
4820@kindex set history size
4821@item set history size @var{size}
4822Set the number of commands which _GDBN__ will keep in its history list.
4823This defaults to the value of the environment variable
4824@code{HISTSIZE}, or to 256 if this variable is not set.
4825@end table
4826
4827@cindex history expansion
4828History expansion assigns special meaning to the character @kbd{!}.
4829@iftex
4830(@xref{Event Designators}.)
4831@end iftex
4832Since @kbd{!} is also the logical not operator in C, history expansion
4833is off by default. If you decide to enable history expansion with the
4834@code{set history expansion on} command, you may sometimes need to
4835follow @kbd{!} (when it is used as logical not, in an expression) with
4836a space or a tab to prevent it from being expanded. The readline
4837history facilities will not attempt substitution on the strings
4838@kbd{!=} and @kbd{!(}, even when history expansion is enabled.
4839
4840The commands to control history expansion are:
4841
4842@table @code
4843
4844@kindex set history expansion
4845@item set history expansion on
4846@itemx set history expansion
4847Enable history expansion. History expansion is off by default.
4848
4849@item set history expansion off
4850Disable history expansion.
4851
4852The readline code comes with more complete documentation of
4853editing and history expansion features. Users unfamiliar with @code{emacs}
4854or @code{vi} may wish to read it.
4855@iftex
4856@xref{Command Line Editing}.
4857@end iftex
4858
4859@c @group
4860@kindex show history
4861@item show history
4862@itemx show history filename
4863@itemx show history save
4864@itemx show history size
4865@itemx show history expansion
4866These commands display the state of the _GDBN__ history parameters.
4867@code{show history} by itself displays all four states.
4868@c @end group
4869
4870@end table
4871
4872@table @code
4873@kindex show commands
4874@item show commands
4875Display the last ten commands in the command history.
4876
4877@item show commands @var{n}
4878Print ten commands centered on command number @var{n}.
4879
4880@item show commands +
4881Print ten commands just after the commands last printed.
4882
4883@end table
4884
4885@node Screen Size, Numbers, History, Controlling _GDBN__
4886@section Screen Size
4887@cindex size of screen
4888@cindex pauses in output
4889Certain commands to _GDBN__ may produce large amounts of information
4890output to the screen. To help you read all of it, _GDBN__ pauses and
4891asks you for input at the end of each page of output. Type @key{RET}
4892when you want to continue the output. _GDBN__ also uses the screen
4893width setting to determine when to wrap lines of output. Depending on
4894what is being printed, it tries to break the line at a readable place,
4895rather than simply letting it overflow onto the following line.
4896
4897Normally _GDBN__ knows the size of the screen from the termcap data base
4898together with the value of the @code{TERM} environment variable and the
4899@code{stty rows} and @code{stty cols} settings. If this is not correct,
4900you can override it with the @code{set height} and @code{set
4901width} commands:
4902
4903@table @code
4904@item set height @var{lpp}
4905@itemx show height
4906@itemx set width @var{cpl}
4907@itemx show width
4908@kindex set height
4909@kindex set width
4910@kindex show width
4911@kindex show height
4912These @code{set} commands specify a screen height of @var{lpp} lines and
4913a screen width of @var{cpl} characters. The associated @code{show}
4914commands display the current settings.
4915
4916If you specify a height of zero lines, _GDBN__ will not pause during output
4917no matter how long the output is. This is useful if output is to a file
4918or to an editor buffer.
4919@end table
4920
4921@node Numbers, Messages/Warnings, Screen Size, Controlling _GDBN__
4922@section Numbers
4923@cindex number representation
4924@cindex entering numbers
4925You can always enter numbers in octal, decimal, or hexadecimal in _GDBN__ by
4926the usual conventions: octal numbers begin with @samp{0}, decimal
4927numbers end with @samp{.}, and hexadecimal numbers begin with @samp{0x}.
4928Numbers that begin with none of these are, by default, entered in base
492910; likewise, the default display for numbers---when no particular
4930format is specified---is base 10. You can change the default base for
4931both input and output with the @code{set radix} command.
4932
4933@table @code
4934@kindex set radix
4935@item set radix @var{base}
4936Set the default base for numeric input and display. Supported choices
4937for @var{base} are decimal 8, 10, 16. @var{base} must itself be
4938specified either unambiguously or using the current default radix; for
4939example, any of
4940
4941@example
4942set radix 012
4943set radix 10.
4944set radix 0xa
4945@end example
4946
4947@noindent
4948will set the base to decimal. On the other hand, @samp{set radix 10}
4949will leave the radix unchanged no matter what it was.
4950
4951@kindex show radix
4952@item show radix
4953Display the current default base for numeric input and display.
4954
4955@end table
4956
4957@node Messages/Warnings, , Numbers, Controlling _GDBN__
4958@section Optional Warnings and Messages
4959By default, _GDBN__ is silent about its inner workings. If you are running
4960on a slow machine, you may want to use the @code{set verbose} command.
4961It will make _GDBN__ tell you when it does a lengthy internal operation, so
4962you won't think it has crashed.
4963
4964Currently, the messages controlled by @code{set verbose} are those which
4965announce that the symbol table for a source file is being read
4966(@pxref{Files}, in the description of the command
4967@code{symbol-file}).
4968@c The following is the right way to do it, but emacs 18.55 doesn't support
4969@c @ref, and neither the emacs lisp manual version of texinfmt or makeinfo
4970@c is released.
4971@ignore
4972see @code{symbol-file} in @ref{Files}).
4973@end ignore
4974
4975@table @code
4976@kindex set verbose
4977@item set verbose on
4978Enables _GDBN__'s output of certain informational messages.
4979
4980@item set verbose off
4981Disables _GDBN__'s output of certain informational messages.
4982
4983@kindex show verbose
4984@item show verbose
4985Displays whether @code{set verbose} is on or off.
4986@end table
4987
4988By default, if _GDBN__ encounters bugs in the symbol table of an object file,
4989it prints a single message about each type of problem it finds, then
4990shuts up (@pxref{Symbol Errors}). You can suppress these messages, or allow more than one such
4991message to be printed if you want to see how frequent the problems are.
4992
4993@table @code
4994@kindex set complaints
4995@item set complaints @var{limit}
4996Permits _GDBN__ to output @var{limit} complaints about each type of unusual
4997symbols before becoming silent about the problem. Set @var{limit} to
4998zero to suppress all complaints; set it to a large number to prevent
4999complaints from being suppressed.
5000
5001@kindex show complaints
5002@item show complaints
5003Displays how many symbol complaints _GDBN__ is permitted to produce.
5004@end table
5005
5006By default, _GDBN__ is cautious, and asks what sometimes seem to be a
5007lot of stupid questions to confirm certain commands. For example, if
5008you try to run a program which is already running:
5009@example
5010(_GDBP__) run
5011The program being debugged has been started already.
5012Start it from the beginning? (y or n)
5013@end example
5014
5015If you're willing to unflinchingly face the consequences of your own
5016commands, you can disable this ``feature'':
5017
5018@table @code
5019@kindex set confirm
5020@cindex flinching
5021@cindex confirmation
5022@cindex stupid questions
5023@item set confirm off
5024Disables confirmation requests.
5025
5026@item set confirm on
5027Enables confirmation requests (the default).
5028
5029@item show confirm
5030@kindex show confirm
5031Displays state of confirmation requests.
5032@end table
5033
5034@node Sequences, Emacs, Controlling _GDBN__, Top
5035@chapter Canned Sequences of Commands
5036
5037Aside from breakpoint commands (@pxref{Break Commands}), _GDBN__ provides two
5038ways to store sequences of commands for execution as a unit:
5039user-defined commands and command files.
5040
5041@menu
5042* Define:: User-Defined Commands
5043* Command Files:: Command Files
5044* Output:: Commands for Controlled Output
5045@end menu
5046
5047@node Define, Command Files, Sequences, Sequences
5048@section User-Defined Commands
5049
5050@cindex user-defined command
5051A @dfn{user-defined command} is a sequence of _GDBN__ commands to which you
5052assign a new name as a command. This is done with the @code{define}
5053command.
5054
5055@table @code
5056@item define @var{commandname}
5057@kindex define
5058Define a command named @var{commandname}. If there is already a command
5059by that name, you are asked to confirm that you want to redefine it.
5060
5061The definition of the command is made up of other _GDBN__ command lines,
5062which are given following the @code{define} command. The end of these
5063commands is marked by a line containing @code{end}.
5064
5065@item document @var{commandname}
5066@kindex document
5067Give documentation to the user-defined command @var{commandname}. The
5068command @var{commandname} must already be defined. This command reads
5069lines of documentation just as @code{define} reads the lines of the
5070command definition, ending with @code{end}. After the @code{document}
5071command is finished, @code{help} on command @var{commandname} will print
5072the documentation you have specified.
5073
5074You may use the @code{document} command again to change the
5075documentation of a command. Redefining the command with @code{define}
5076does not change the documentation.
5077
5078@item help user-defined
5079@kindex help user-defined
5080List all user-defined commands, with the first line of the documentation
5081(if any) for each.
5082
5083@item info user
5084@itemx info user @var{commandname}
5085@kindex info user
5086Display the _GDBN__ commands used to define @var{commandname} (but not its
5087documentation). If no @var{commandname} is given, display the
5088definitions for all user-defined commands.
5089@end table
5090
5091User-defined commands do not take arguments. When they are executed, the
5092commands of the definition are not printed. An error in any command
5093stops execution of the user-defined command.
5094
5095Commands that would ask for confirmation if used interactively proceed
5096without asking when used inside a user-defined command. Many _GDBN__ commands
5097that normally print messages to say what they are doing omit the messages
5098when used in a user-defined command.
5099
5100@node Command Files, Output, Define, Sequences
5101@section Command Files
5102
5103@cindex command files
5104A command file for _GDBN__ is a file of lines that are _GDBN__ commands. Comments
5105(lines starting with @kbd{#}) may also be included. An empty line in a
5106command file does nothing; it does not mean to repeat the last command, as
5107it would from the terminal.
5108
5109@cindex init file
5110@cindex @file{_GDBINIT__}
5111When you start _GDBN__, it automatically executes commands from its
5112@dfn{init files}. These are files named @file{_GDBINIT__}. _GDBN__
5113reads the init file (if any) in your home directory and then the init
5114file (if any) in the current working directory. (The init files are not
5115executed if you use the @samp{-nx} option; @pxref{Mode Options}.) You
5116can also request the execution of a command file with the @code{source}
5117command:
5118
5119@table @code
5120@item source @var{filename}
5121@kindex source
5122Execute the command file @var{filename}.
5123@end table
5124
5125The lines in a command file are executed sequentially. They are not
5126printed as they are executed. An error in any command terminates execution
5127of the command file.
5128
5129Commands that would ask for confirmation if used interactively proceed
5130without asking when used in a command file. Many _GDBN__ commands that
5131normally print messages to say what they are doing omit the messages
5132when called from command files.
5133
5134@node Output, , Command Files, Sequences
5135@section Commands for Controlled Output
5136
5137During the execution of a command file or a user-defined command, normal
5138_GDBN__ output is suppressed; the only output that appears is what is
5139explicitly printed by the commands in the definition. This section
5140describes three commands useful for generating exactly the output you
5141want.
5142
5143@table @code
5144@item echo @var{text}
5145@kindex echo
5146@c I don't consider backslash-space a standard C escape sequence
5147@c because it's not in ANSI.
5148Print @var{text}. Nonprinting characters can be included in @var{text}
5149using C escape sequences, such as @samp{\n} to print a newline. @b{No
5150newline will be printed unless you specify one.} In addition to the
5151standard C escape sequences, a backslash followed by a space stands for a
5152space. This is useful for outputting a string with spaces at the
5153beginning or the end, since leading and trailing spaces are otherwise
5154trimmed from all arguments. Thus, to print @samp{@ and foo =@ }, use the
5155command @samp{echo \@ and foo = \@ }.
5156@c FIXME: verify hard copy actually issues enspaces for '@ '! Will this
5157@c confuse texinfo?
5158
5159A backslash at the end of @var{text} can be used, as in C, to continue
5160the command onto subsequent lines. For example,
5161
5162@example
5163echo This is some text\n\
5164which is continued\n\
5165onto several lines.\n
5166@end example
5167
5168produces the same output as
5169
5170@example
5171echo This is some text\n
5172echo which is continued\n
5173echo onto several lines.\n
5174@end example
5175
5176@item output @var{expression}
5177@kindex output
5178Print the value of @var{expression} and nothing but that value: no
5179newlines, no @samp{$@var{nn} = }. The value is not entered in the
5180value history either. @xref{Expressions} for more information on
5181expressions.
5182
5183@item output/@var{fmt} @var{expression}
5184Print the value of @var{expression} in format @var{fmt}. You can use
5185the same formats as for @code{print}; @pxref{Output formats}, for more
5186information.
5187
5188@item printf @var{string}, @var{expressions}@dots{}
5189@kindex printf
5190Print the values of the @var{expressions} under the control of
5191@var{string}. The @var{expressions} are separated by commas and may
5192be either numbers or pointers. Their values are printed as specified
5193by @var{string}, exactly as if the program were to execute
5194
5195@example
5196printf (@var{string}, @var{expressions}@dots{});
5197@end example
5198
5199For example, you can print two values in hex like this:
5200
5201@example
5202printf "foo, bar-foo = 0x%x, 0x%x\n", foo, bar-foo
5203@end example
5204
5205The only backslash-escape sequences that you can use in the format
5206string are the simple ones that consist of backslash followed by a
5207letter.
5208@end table
5209
5210@node Emacs, _GDBN__ Bugs, Sequences, Top
5211@chapter Using _GDBN__ under GNU Emacs
5212
5213@cindex emacs
5214A special interface allows you to use GNU Emacs to view (and
5215edit) the source files for the program you are debugging with
5216_GDBN__.
5217
5218To use this interface, use the command @kbd{M-x gdb} in Emacs. Give the
5219executable file you want to debug as an argument. This command starts
5220_GDBN__ as a subprocess of Emacs, with input and output through a newly
5221created Emacs buffer.
5222
5223Using _GDBN__ under Emacs is just like using _GDBN__ normally except for two
5224things:
5225
5226@itemize @bullet
5227@item
5228All ``terminal'' input and output goes through the Emacs buffer.
5229@end itemize
5230
5231This applies both to _GDBN__ commands and their output, and to the input
5232and output done by the program you are debugging.
5233
5234This is useful because it means that you can copy the text of previous
5235commands and input them again; you can even use parts of the output
5236in this way.
5237
3d3ab540
RP
5238All the facilities of Emacs' Shell mode are available for interacting
5239with your program. In particular, you can send signals the usual
5240way---for example, @kbd{C-c C-c} for an interrupt, @kbd{C-c C-z} for a
5241stop.
70b88761
RP
5242
5243@itemize @bullet
5244@item
5245_GDBN__ displays source code through Emacs.
5246@end itemize
5247
5248Each time _GDBN__ displays a stack frame, Emacs automatically finds the
5249source file for that frame and puts an arrow (_0__@samp{=>}_1__) at the
5250left margin of the current line. Emacs uses a separate buffer for
5251source display, and splits the window to show both your _GDBN__ session
5252and the source.
5253
5254Explicit _GDBN__ @code{list} or search commands still produce output as
5255usual, but you probably will have no reason to use them.
5256
5257@quotation
5258@emph{Warning:} If the directory where your program resides is not your
5259current directory, it can be easy to confuse Emacs about the location of
5260the source files, in which case the auxiliary display buffer will not
5261appear to show your source. _GDBN__ can find programs by searching your
5262environment's @code{PATH} variable, so the _GDBN__ input and output
5263session will proceed normally; but Emacs doesn't get enough information
5264back from _GDBN__ to locate the source files in this situation. To
5265avoid this problem, either start _GDBN__ mode from the directory where
5266your program resides, or specify a full path name when prompted for the
5267@kbd{M-x gdb} argument.
5268
5269A similar confusion can result if you use the _GDBN__ @code{file} command to
5270switch to debugging a program in some other location, from an existing
5271_GDBN__ buffer in Emacs.
5272@end quotation
5273
5274By default, @kbd{M-x gdb} calls the program called @file{gdb}. If
5275you need to call _GDBN__ by a different name (for example, if you keep
5276several configurations around, with different names) you can set the
5277Emacs variable @code{gdb-command-name}; for example,
5278@example
5279(setq gdb-command-name "mygdb")
5280@end example
5281@noindent
5282(preceded by @kbd{ESC ESC}, or typed in the @code{*scratch*} buffer, or
5283in your @file{.emacs} file) will make Emacs call the program named
5284``@code{mygdb}'' instead.
5285
5286In the _GDBN__ I/O buffer, you can use these special Emacs commands in
5287addition to the standard Shell mode commands:
5288
5289@table @kbd
5290@item C-h m
5291Describe the features of Emacs' _GDBN__ Mode.
5292
5293@item M-s
5294Execute to another source line, like the _GDBN__ @code{step} command; also
5295update the display window to show the current file and location.
5296
5297@item M-n
5298Execute to next source line in this function, skipping all function
5299calls, like the _GDBN__ @code{next} command. Then update the display window
5300to show the current file and location.
5301
5302@item M-i
5303Execute one instruction, like the _GDBN__ @code{stepi} command; update
5304display window accordingly.
5305
5306@item M-x gdb-nexti
5307Execute to next instruction, using the _GDBN__ @code{nexti} command; update
5308display window accordingly.
5309
5310@item C-c C-f
5311Execute until exit from the selected stack frame, like the _GDBN__
5312@code{finish} command.
5313
5314@item M-c
5315Continue execution of the program, like the _GDBN__ @code{continue}
5316command. @emph{Warning:} In Emacs v19, this command is @kbd{C-c C-p}.
5317
5318@item M-u
5319Go up the number of frames indicated by the numeric argument
5320(@pxref{Arguments, , Numeric Arguments, emacs, The GNU Emacs Manual}),
5321like the _GDBN__ @code{up} command. @emph{Warning:} In Emacs v19, this
5322command is @kbd{C-c C-u}.@refill
5323
5324@item M-d
5325Go down the number of frames indicated by the numeric argument, like the
5326_GDBN__ @code{down} command. @emph{Warning:} In Emacs v19, this command
5327is @kbd{C-c C-d}.
5328
5329@item C-x &
5330Read the number where the cursor is positioned, and insert it at the end
5331of the _GDBN__ I/O buffer. For example, if you wish to disassemble code
5332around an address that was displayed earlier, type @kbd{disassemble};
5333then move the cursor to the address display, and pick up the
5334argument for @code{disassemble} by typing @kbd{C-x &}.
5335
5336You can customize this further on the fly by defining elements of the list
5337@code{gdb-print-command}; once it is defined, you can format or
5338otherwise process numbers picked up by @kbd{C-x &} before they are
5339inserted. A numeric argument to @kbd{C-x &} will both flag that you
5340wish special formatting, and act as an index to pick an element of the
5341list. If the list element is a string, the number to be inserted is
5342formatted using the Emacs function @code{format}; otherwise the number
5343is passed as an argument to the corresponding list element.
5344
5345@end table
5346
5347In any source file, the Emacs command @kbd{C-x SPC} (@code{gdb-break})
5348tells _GDBN__ to set a breakpoint on the source line point is on.
5349
5350If you accidentally delete the source-display buffer, an easy way to get
5351it back is to type the command @code{f} in the _GDBN__ buffer, to
5352request a frame display; when you run under Emacs, this will recreate
5353the source buffer if necessary to show you the context of the current
5354frame.
5355
5356The source files displayed in Emacs are in ordinary Emacs buffers
5357which are visiting the source files in the usual way. You can edit
5358the files with these buffers if you wish; but keep in mind that _GDBN__
5359communicates with Emacs in terms of line numbers. If you add or
5360delete lines from the text, the line numbers that _GDBN__ knows will cease
5361to correspond properly to the code.
5362
5363@c The following dropped because Epoch is nonstandard. Reactivate
5364@c if/when v19 does something similar. [email protected] 19dec1990
5365@ignore
5366@kindex emacs epoch environment
5367@kindex epoch
5368@kindex inspect
5369
5370Version 18 of Emacs has a built-in window system called the @code{epoch}
5371environment. Users of this environment can use a new command,
5372@code{inspect} which performs identically to @code{print} except that
5373each value is printed in its own window.
5374@end ignore
5375
5376@node _GDBN__ Bugs, Renamed Commands, Emacs, Top
5377@chapter Reporting Bugs in _GDBN__
5378@cindex Bugs in _GDBN__
5379@cindex Reporting Bugs in _GDBN__
5380
5381Your bug reports play an essential role in making _GDBN__ reliable.
5382
5383Reporting a bug may help you by bringing a solution to your problem, or it
5384may not. But in any case the principal function of a bug report is to help
5385the entire community by making the next version of _GDBN__ work better. Bug
5386reports are your contribution to the maintenance of _GDBN__.
5387
5388In order for a bug report to serve its purpose, you must include the
5389information that enables us to fix the bug.
5390
5391@menu
5392* Bug Criteria:: Have You Found a Bug?
5393* Bug Reporting:: How to Report Bugs
5394@end menu
5395
5396@node Bug Criteria, Bug Reporting, _GDBN__ Bugs, _GDBN__ Bugs
5397@section Have You Found a Bug?
5398@cindex Bug Criteria
5399
5400If you are not sure whether you have found a bug, here are some guidelines:
5401
5402@itemize @bullet
5403@item
5404@cindex Fatal Signal
5405@cindex Core Dump
5406If the debugger gets a fatal signal, for any input whatever, that is a
5407_GDBN__ bug. Reliable debuggers never crash.
5408
5409@item
5410@cindex error on Valid Input
5411If _GDBN__ produces an error message for valid input, that is a bug.
5412
5413@item
5414@cindex Invalid Input
5415If _GDBN__ does not produce an error message for invalid input,
5416that is a bug. However, you should note that your idea of
5417``invalid input'' might be our idea of ``an extension'' or ``support
5418for traditional practice''.
5419
5420@item
5421If you are an experienced user of debugging tools, your suggestions
5422for improvement of _GDBN__ are welcome in any case.
5423@end itemize
5424
5425@node Bug Reporting, , Bug Criteria, _GDBN__ Bugs
5426@section How to Report Bugs
5427@cindex Bug Reports
3d3ab540 5428@cindex _GDBN__ Bugs, Reporting
70b88761
RP
5429
5430A number of companies and individuals offer support for GNU products.
5431If you obtained _GDBN__ from a support organization, we recommend you
5432contact that organization first.
5433
5434Contact information for many support companies and individuals is
5435available in the file @file{etc/SERVICE} in the GNU Emacs distribution.
5436
5437In any event, we also recommend that you send bug reports for _GDBN__ to one
5438of these addresses:
5439
5440@example
5441bug-gdb@@prep.ai.mit.edu
5442@{ucbvax|mit-eddie|uunet@}!prep.ai.mit.edu!bug-gdb
5443@end example
5444
5445@strong{Do not send bug reports to @samp{info-gdb}, or to
5446@samp{help-gdb}, or to any newsgroups.} Most users of _GDBN__ do not want to
5447receive bug reports. Those that do, have arranged to receive @samp{bug-gdb}.
5448
3d3ab540
RP
5449The mailing list @samp{bug-gdb} has a newsgroup @samp{gnu.gdb.bug} which
5450serves as a repeater. The mailing list and the newsgroup carry exactly
5451the same messages. Often people think of posting bug reports to the
5452newsgroup instead of mailing them. This appears to work, but it has one
5453problem which can be crucial: a newsgroup posting often lacks a mail
5454path back to the sender. Thus, if we need to ask for more information,
5455we may be unable to reach you. For this reason, it is better to send
5456bug reports to the mailing list.
70b88761
RP
5457
5458As a last resort, send bug reports on paper to:
5459
5460@example
5461GNU Debugger Bugs
3d3ab540 5462Free Software Foundation
70b88761
RP
5463545 Tech Square
5464Cambridge, MA 02139
5465@end example
5466
5467The fundamental principle of reporting bugs usefully is this:
5468@strong{report all the facts}. If you are not sure whether to state a
5469fact or leave it out, state it!
5470
5471Often people omit facts because they think they know what causes the
5472problem and assume that some details don't matter. Thus, you might
5473assume that the name of the variable you use in an example does not matter.
5474Well, probably it doesn't, but one cannot be sure. Perhaps the bug is a
5475stray memory reference which happens to fetch from the location where that
5476name is stored in memory; perhaps, if the name were different, the contents
5477of that location would fool the debugger into doing the right thing despite
5478the bug. Play it safe and give a specific, complete example. That is the
5479easiest thing for you to do, and the most helpful.
5480
5481Keep in mind that the purpose of a bug report is to enable us to fix
5482the bug if it is new to us. It isn't as important what happens if
5483the bug is already known. Therefore, always write your bug reports on
5484the assumption that the bug has not been reported previously.
5485
5486Sometimes people give a few sketchy facts and ask, ``Does this ring a
5487bell?'' Those bug reports are useless, and we urge everyone to
5488@emph{refuse to respond to them} except to chide the sender to report
5489bugs properly.
5490
5491To enable us to fix the bug, you should include all these things:
5492
5493@itemize @bullet
5494@item
5495The version of _GDBN__. _GDBN__ announces it if you start with no
5496arguments; you can also print it at any time using @code{show version}.
5497
5498Without this, we won't know whether there is any point in looking for
5499the bug in the current version of _GDBN__.
5500
5501@item
5502A complete input script, and all necessary source files, that will
5503reproduce the bug.
5504
5505@item
5506What compiler (and its version) was used to compile _GDBN__---e.g.
5507``_GCC__-1.37.1''.
5508
5509@item
5510The command arguments you gave the compiler to compile your example and
5511observe the bug. For example, did you use @samp{-O}? To guarantee
5512you won't omit something important, list them all.
5513
5514If we were to try to guess the arguments, we would probably guess wrong
5515and then we might not encounter the bug.
5516
5517@item
5518The type of machine you are using, and the operating system name and
5519version number.
5520
5521@item
5522A description of what behavior you observe that you believe is
5523incorrect. For example, ``It gets a fatal signal.''
5524
5525Of course, if the bug is that _GDBN__ gets a fatal signal, then we will
5526certainly notice it. But if the bug is incorrect output, we might not
5527notice unless it is glaringly wrong. We are human, after all. You
5528might as well not give us a chance to make a mistake.
5529
5530Even if the problem you experience is a fatal signal, you should still
5531say so explicitly. Suppose something strange is going on, such as,
5532your copy of _GDBN__ is out of synch, or you have encountered a
5533bug in the C library on your system. (This has happened!) Your copy
5534might crash and ours would not. If you told us to expect a crash,
5535then when ours fails to crash, we would know that the bug was not
5536happening for us. If you had not told us to expect a crash, then we
5537would not be able to draw any conclusion from our observations.
5538
5539@item
5540If you wish to suggest changes to the _GDBN__ source, send us context
5541diffs. If you even discuss something in the _GDBN__ source, refer to
5542it by context, not by line number.
5543
5544The line numbers in our development sources won't match those in your
5545sources. Your line numbers would convey no useful information to us.
5546
5547@end itemize
5548
5549Here are some things that are not necessary:
5550
5551@itemize @bullet
5552@item
5553A description of the envelope of the bug.
5554
5555Often people who encounter a bug spend a lot of time investigating
5556which changes to the input file will make the bug go away and which
5557changes will not affect it.
5558
5559This is often time consuming and not very useful, because the way we
5560will find the bug is by running a single example under the debugger
5561with breakpoints, not by pure deduction from a series of examples.
5562We recommend that you save your time for something else.
5563
5564Of course, if you can find a simpler example to report @emph{instead}
5565of the original one, that is a convenience for us. Errors in the
5566output will be easier to spot, running under the debugger will take
5567less time, etc.
5568
5569However, simplification is not vital; if you don't want to do this,
5570report the bug anyway and send us the entire test case you used.
5571
5572@item
5573A patch for the bug.
5574
5575A patch for the bug does help us if it is a good one. But don't omit
5576the necessary information, such as the test case, on the assumption that
5577a patch is all we need. We might see problems with your patch and decide
5578to fix the problem another way, or we might not understand it at all.
5579
5580Sometimes with a program as complicated as _GDBN__ it is very hard to
5581construct an example that will make the program follow a certain path
5582through the code. If you don't send us the example, we won't be able
5583to construct one, so we won't be able to verify that the bug is fixed.
5584
5585And if we can't understand what bug you are trying to fix, or why your
5586patch should be an improvement, we won't install it. A test case will
5587help us to understand.
5588
5589@item
5590A guess about what the bug is or what it depends on.
5591
5592Such guesses are usually wrong. Even we can't guess right about such
5593things without first using the debugger to find the facts.
5594@end itemize
5595
5596@iftex
5597@include rdl-apps.texinfo
5598@end iftex
5599
5600@node Renamed Commands, Installing _GDBN__, _GDBN__ Bugs, Top
5601@appendix Renamed Commands
5602
5603The following commands were renamed in _GDBN__ 4.0, in order to make the
5604command set as a whole more consistent and easier to use and remember:
5605
5606@kindex add-syms
5607@kindex delete environment
5608@kindex info copying
5609@kindex info convenience
5610@kindex info directories
5611@kindex info editing
5612@kindex info history
5613@kindex info targets
5614@kindex info values
5615@kindex info version
5616@kindex info warranty
5617@kindex set addressprint
5618@kindex set arrayprint
5619@kindex set prettyprint
5620@kindex set screen-height
5621@kindex set screen-width
5622@kindex set unionprint
5623@kindex set vtblprint
5624@kindex set demangle
5625@kindex set asm-demangle
5626@kindex set sevenbit-strings
5627@kindex set array-max
5628@kindex set caution
5629@kindex set history write
5630@kindex show addressprint
5631@kindex show arrayprint
5632@kindex show prettyprint
5633@kindex show screen-height
5634@kindex show screen-width
5635@kindex show unionprint
5636@kindex show vtblprint
5637@kindex show demangle
5638@kindex show asm-demangle
5639@kindex show sevenbit-strings
5640@kindex show array-max
5641@kindex show caution
5642@kindex show history write
5643@kindex unset
5644
5645@ifinfo
cf496415
RP
5646@example
5647OLD COMMAND NEW COMMAND
5648--------------- -------------------------------
5649add-syms add-symbol-file
5650delete environment unset environment
5651info convenience show convenience
5652info copying show copying
5653info directories show directories
5654info editing show commands
5655info history show values
5656info targets help target
5657info values show values
5658info version show version
5659info warranty show warranty
5660set/show addressprint set/show print address
5661set/show array-max set/show print elements
5662set/show arrayprint set/show print array
5663set/show asm-demangle set/show print asm-demangle
5664set/show caution set/show confirm
5665set/show demangle set/show print demangle
5666set/show history write set/show history save
5667set/show prettyprint set/show print pretty
5668set/show screen-height set/show height
5669set/show screen-width set/show width
5670set/show sevenbit-strings set/show print sevenbit-strings
5671set/show unionprint set/show print union
5672set/show vtblprint set/show print vtbl
5673
5674unset [No longer an alias for delete]
5675@end example
70b88761
RP
5676@end ifinfo
5677
5678@tex
5679\vskip \parskip\vskip \baselineskip
5680\halign{\tt #\hfil &\qquad#&\tt #\hfil\cr
5681{\bf Old Command} &&{\bf New Command}\cr
5682add-syms &&add-symbol-file\cr
5683delete environment &&unset environment\cr
5684info convenience &&show convenience\cr
5685info copying &&show copying\cr
5686info directories &&show directories \cr
5687info editing &&show commands\cr
5688info history &&show values\cr
5689info targets &&help target\cr
5690info values &&show values\cr
5691info version &&show version\cr
5692info warranty &&show warranty\cr
5693set{\rm / }show addressprint &&set{\rm / }show print address\cr
5694set{\rm / }show array-max &&set{\rm / }show print elements\cr
5695set{\rm / }show arrayprint &&set{\rm / }show print array\cr
5696set{\rm / }show asm-demangle &&set{\rm / }show print asm-demangle\cr
5697set{\rm / }show caution &&set{\rm / }show confirm\cr
5698set{\rm / }show demangle &&set{\rm / }show print demangle\cr
5699set{\rm / }show history write &&set{\rm / }show history save\cr
5700set{\rm / }show prettyprint &&set{\rm / }show print pretty\cr
5701set{\rm / }show screen-height &&set{\rm / }show height\cr
5702set{\rm / }show screen-width &&set{\rm / }show width\cr
5703set{\rm / }show sevenbit-strings &&set{\rm / }show print sevenbit-strings\cr
5704set{\rm / }show unionprint &&set{\rm / }show print union\cr
5705set{\rm / }show vtblprint &&set{\rm / }show print vtbl\cr
5706\cr
5707unset &&\rm(No longer an alias for delete)\cr
5708}
5709@end tex
5710
5711@node Installing _GDBN__, Copying, Renamed Commands, Top
5712@appendix Installing _GDBN__
5713@cindex configuring _GDBN__
5714@cindex installation
5715
3d3ab540 5716_GDBN__ is distributed with a @code{configure} script that automates the
7463aadd 5717process of preparing _GDBN__ for installation; you can then use
3d3ab540
RP
5718@code{make} to build the @code{_GDBP__} program.
5719
5720The @code{configure} script that's specific to _GDBN__ is distributed in
5721the main _GDBN__ source directory. However, building _GDBN__ also
5722requires several other directories of source common to multiple @sc{gnu}
5723programs. These directories (@sc{gnu} libraries and includes) are
5724distributed separately, but their @code{configure} scripts and
5725@code{Makefile}s are designed to work together. To ensure that
5726_GDBN__'s @code{Makefile} can find all the pieces, you should make a
5727single overall directory to hold the directories of source for @sc{gnu}
5728libraries and includes, and you should install the _GDBN__ source
5729directory there too. In this Appendix, we refer to the directory of
5730@sc{gnu} source directories as @var{gnusrc}.
5731
5732At a minimum, to build _GDBN__ you need the directories
5733@table @code
5734@item @var{gnusrc}/gdb
5735the source specific to _GDBN__ itself
5736
5737@item @var{gnusrc}/bfd
5738source for the Binary File Descriptor Library
5739
5740@item @var{gnusrc}/include
5741@sc{gnu} include files
5742
5743@item @var{gnusrc}/libiberty
5744source for the @samp{-liberty} free software library
5745
5746@item @var{gnusrc}/readline
5747source for the @sc{gnu} command-line interface
5748@end table
7463aadd 5749@noindent
3d3ab540
RP
5750Each of these directories has its own @code{configure} script.
5751@var{gnusrc} has an overall @code{configure} script, which is
5752distributed with the @sc{gnu} libraries and includes.
7463aadd 5753
3d3ab540
RP
5754@code{configure} is designed to be called recursively, so it is most
5755convenient to run @code{configure} from the @var{gnusrc} directory.
7463aadd
RP
5756The simplest way to configure and build _GDBN__ is the following:
5757@example
5758cd @var{gnusrc}
3d3ab540 5759./configure @var{host}
7463aadd
RP
5760make
5761@end example
5762@noindent
3d3ab540
RP
5763where @var{host} is something like @samp{sun4} or @samp{vax}, that
5764identifies the platform where _GDBN__ will run. This builds the three
5765libraries @file{bfd}, @file{readline}, and @file{libiberty}, then
5766@code{gdb} itself. The configured source files, and the binaries, are
5767left in the corresponding source directories.
5768
5769You can install @code{_GDBP__} anywhere; it has no hardwired paths. However,
5770you should make sure that the shell on your path (named by the
5771@samp{SHELL} environment variable) is publicly readable; some systems
5772refuse to let _GDBN__ debug child processes whose programs are not
5773readable, and _GDBN__ uses the shell to start your program.
5774
5775@menu
5776* Subdirectories:: Configuration subdirectories
5777* configure Options:: Summary of options for configure
5778* Formatting Manual:: How to format and print this manual
5779@end menu
5780
5781
5782@node Subdirectories, configure Options, Installing _GDBN__, Installing _GDBN__
5783@section Configuration Subdirectories
5784If you build _GDBN__ for several host or target machines, and if
5785your @code{make} program handles the @samp{VPATH} feature
5786(@sc{gnu} @code{make} does), it is most convenient instead to build
5787the different _GDBN__ configurations in subdirectories (separate from
5788the source). @code{configure} does this for you when you simultaneously
5789specify several configurations; but it's a good habit even for a single
7463aadd 5790configuration. You can specify the use of subdirectories using the
3d3ab540
RP
5791@samp{+forcesubdirs} option (abbreviated @samp{+f}). For example, you
5792can build _GDBN__ on a Sun 4 as follows:
70b88761
RP
5793
5794@example
3d3ab540
RP
5795@group
5796cd @var{gnusrc}
7463aadd
RP
5797./configure +f sun4
5798cd Host-sun4/Target-sun4
70b88761 5799make
3d3ab540 5800@end group
70b88761
RP
5801@end example
5802
3d3ab540
RP
5803When @code{configure} uses subdirectories to build programs or
5804libraries, it creates nested directories
5805@file{Host-@var{host}/Target-@var{machine}}. This is because _GDBN__
5806can be configured for cross-compiling: _GDBN__ can run on one machine
5807(the host) while debugging programs that run on another machine (the
5808target). You specify cross-debugging targets by giving the
5809@samp{+target=@var{machine}} option to @code{configure}. Specifying
5810only hosts still gives you two levels of subdirectory for each host,
5811with the same machine-name suffix on both. On the other hand, whenever
5812you specify both hosts and targets on the same command line,
5813@code{configure} creates all combinations of the hosts and targets you
5814list.@refill
5815
5816When you run @code{make} to build a program or library, you must run it
5817in a configured directory. If you made a single configuration,
5818without subdirectories, run @code{make} in the source directory.
5819If you have @file{Host-@var{host}/Target-@var{machine}} subdirectories,
5820run @code{make} in those subdirectories.
5821
5822Each @code{configure} and @code{Makefile} under each source directory
5823runs recursively, so that typing @code{make} in @var{gnusrc} (or in a
5824@file{@var{gnusrc}/Host-@var{host}/Target-@var{machine}} subdirectory)
5825builds all the required libraries, then _GDBN__.@refill
5826
5827If you run @code{configure} from a directory (such as @var{gnusrc}) that
5828contains source directories for multiple libraries or programs,
5829@code{configure} creates the @file{Host-@var{host}/Target-@var{machine}}
5830subdirectories in each library or program's source directory. For
5831example, typing:
5832@example
5833cd @var{gnusrc}
5834configure sun4 +target=vx960
5835@end example
5836@noindent
5837creates the following directories:
5838@example
5839@var{gnusrc}/Host-sun4/Target-vx960
5840@var{gnusrc}/bfd/Host-sun4/Target-vx960
5841@var{gnusrc}/gdb/Host-sun4/Target-vx960
cf496415 5842@var{gnusrc}/libiberty/Host-sun4/Target-vx960
3d3ab540
RP
5843@var{gnusrc}/readline/Host-sun4/Target-vx960
5844@end example
70b88761 5845@noindent
3d3ab540
RP
5846The @code{Makefile} in @file{@var{gnusrc}/Host-sun4/Target-vx960}
5847will @code{cd} to the appropriate lower-level directories
5848(such as @file{@var{gnusrc}/bfd/Host-sun4/Target-vx960}), building each
5849in turn.
5850
5851When you have multiple hosts or targets configured, you can run
5852@code{make} on them in parallel (for example, if they are NFS-mounted on
5853each of the hosts); they will not interfere with each other.
5854
5855@node configure Options, Formatting Manual, Subdirectories, Installing _GDBN__
5856@section @code{configure} Options
7463aadd
RP
5857
5858Here is a summary of all the @code{configure} options and arguments that
5859you might use for building _GDBN__:
5860
5861@example
54e6b3c3
RP
5862configure @r{[}+destdir=@var{dir}@r{]} @r{[}+forcesubdirs@r{]} @r{[}+norecur@r{]} @r{[}+rm@r{]}
5863 @r{[}+target=@var{machine}@dots{}@r{]} @var{host}@dots{}
7463aadd 5864@end example
3d3ab540 5865@noindent
7463aadd
RP
5866You may introduce options with the character @samp{-} rather than
5867@samp{+} if you prefer; but options introduced with @samp{+} may be truncated.
70b88761
RP
5868
5869@table @code
7463aadd 5870@item +destdir=@var{dir}
3d3ab540
RP
5871@var{dir} is an installation directory @emph{path prefix}. After you
5872configure with this option, @code{make install} will install _GDBN__ as
5873@file{@var{dir}/bin/_GDBP__}, and the libraries in @file{@var{dir}/lib}.
5874If you specify @samp{+destdir=/usr/local}, for example, @code{make
5875install} creates @file{/usr/local/bin/gdb}.@refill
7463aadd
RP
5876
5877@item +forcesubdirs
3d3ab540 5878Write configuration specific files in subdirectories of the form
7463aadd
RP
5879@example
5880Host-@var{machine}/Target-@var{machine}
5881@end example
5882@noindent
3d3ab540 5883(and configure the @code{Makefile} to write binaries there too).
7463aadd
RP
5884Without this option, if you specify only one configuration for _GDBN__,
5885@code{configure} will use the same directory for source, configured
5886files, and binaries. This option is used automatically if you specify
5887more than one @var{host} or more than one @samp{+target=@var{machine}}
5888option on the @code{configure} command line.
5889
5890@item +norecur
5891Configure only the directory where @code{configure} is executed; do not
5892propagate configuration to subdirectories.
5893
5894@item +rm
5895Remove the configuration specified by other arguments.
5896
5897@item +target=@var{machine} @dots{}
3d3ab540
RP
5898Configure _GDBN__ for cross-debugging programs running on each specified
5899@var{machine}. You may specify as many @samp{+target} options as you
7463aadd
RP
5900wish. To see a list of available targets, execute @samp{ls tconfig} in
5901the _GDBN__ source directory. Without this option, _GDBN__ is
5902configured to debug programs that run on the same machine (@var{host})
5903as _GDBN__ itself.
5904
5905@item @var{host} @dots{}
3d3ab540 5906Configure _GDBN__ to run on each specified @var{host}. You may specify as
7463aadd
RP
5907many host names as you wish. To see a list of available hosts, execute
5908@samp{ls xconfig} in the _GDBN__ source directory.
70b88761
RP
5909@end table
5910
3d3ab540
RP
5911@noindent
5912@code{configure} accepts other options, for compatibility with
5913configuring other @sc{gnu} tools recursively; but these are the only
5914options that affect _GDBN__ or its supporting libraries.
5915
5916@node Formatting Manual, , configure Options, Installing _GDBN__
5917@section Formatting this Manual
5918
5919To format the _GDBN__ manual as an Info file, you need the @sc{gnu}
5920@code{makeinfo} program. Once you have it, you can type
5921@example
5922cd @var{gnusrc}/gdb
5923make gdb.info
5924@end example
5925@noindent
5926to make the Info file.
5927
5928If you want to format and print copies of this manual, you need several
5929things:
5930@itemize @bullet
5931@item
5932@TeX{}, the public domain typesetting program written by Donald Knuth,
5933must be installed on your system and available through your execution
5934path.
5935@item
5936@file{@var{gnusrc}/texinfo}: @TeX{} macros defining the @sc{gnu}
5937Documentation Format.
5938@item
5939@emph{A @sc{dvi} output program.} @TeX{} doesn't actually make marks on
5940paper; it produces output files called @sc{dvi} files. If your system
5941has @TeX{} installed, chances are it has a program for printing out
5942these files; one popular example is @code{dvips}, which can print
5943@sc{dvi} files on PostScript printers.
5944@end itemize
5945@noindent
5946Once you have these things, you can type
5947@example
5948cd @var{gnusrc}/gdb
5949make gdb.dvi
5950@end example
5951@noindent
5952to format the text of this manual, and print it with the usual output
5953method for @TeX{} @sc{dvi} files at your site.
5954
70b88761 5955@node Copying, Index, Installing _GDBN__, Top
70b88761 5956@unnumbered GNU GENERAL PUBLIC LICENSE
7463aadd 5957@center Version 2, June 1991
70b88761
RP
5958
5959@display
7463aadd 5960Copyright @copyright{} 1989, 1991 Free Software Foundation, Inc.
70b88761
RP
5961675 Mass Ave, Cambridge, MA 02139, USA
5962
5963Everyone is permitted to copy and distribute verbatim copies
5964of this license document, but changing it is not allowed.
5965@end display
5966
5967@unnumberedsec Preamble
5968
7463aadd
RP
5969 The licenses for most software are designed to take away your
5970freedom to share and change it. By contrast, the GNU General Public
70b88761 5971License is intended to guarantee your freedom to share and change free
7463aadd
RP
5972software---to make sure the software is free for all its users. This
5973General Public License applies to most of the Free Software
5974Foundation's software and to any other program whose authors commit to
5975using it. (Some other Free Software Foundation software is covered by
5976the GNU Library General Public License instead.) You can apply it to
5977your programs, too.
70b88761
RP
5978
5979 When we speak of free software, we are referring to freedom, not
7463aadd
RP
5980price. Our General Public Licenses are designed to make sure that you
5981have the freedom to distribute copies of free software (and charge for
5982this service if you wish), that you receive source code or can get it
5983if you want it, that you can change the software or use pieces of it
5984in new free programs; and that you know you can do these things.
70b88761
RP
5985
5986 To protect your rights, we need to make restrictions that forbid
5987anyone to deny you these rights or to ask you to surrender the rights.
5988These restrictions translate to certain responsibilities for you if you
5989distribute copies of the software, or if you modify it.
5990
7463aadd 5991 For example, if you distribute copies of such a program, whether
70b88761
RP
5992gratis or for a fee, you must give the recipients all the rights that
5993you have. You must make sure that they, too, receive or can get the
7463aadd
RP
5994source code. And you must show them these terms so they know their
5995rights.
70b88761
RP
5996
5997 We protect your rights with two steps: (1) copyright the software, and
5998(2) offer you this license which gives you legal permission to copy,
5999distribute and/or modify the software.
6000
6001 Also, for each author's protection and ours, we want to make certain
6002that everyone understands that there is no warranty for this free
6003software. If the software is modified by someone else and passed on, we
6004want its recipients to know that what they have is not the original, so
6005that any problems introduced by others will not reflect on the original
6006authors' reputations.
6007
7463aadd
RP
6008 Finally, any free program is threatened constantly by software
6009patents. We wish to avoid the danger that redistributors of a free
6010program will individually obtain patent licenses, in effect making the
6011program proprietary. To prevent this, we have made it clear that any
6012patent must be licensed for everyone's free use or not licensed at all.
6013
70b88761
RP
6014 The precise terms and conditions for copying, distribution and
6015modification follow.
6016
6017@iftex
7463aadd 6018@unnumberedsec TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
70b88761
RP
6019@end iftex
6020@ifinfo
7463aadd 6021@center TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
70b88761
RP
6022@end ifinfo
6023
6024@enumerate
6025@item
7463aadd
RP
6026This License applies to any program or other work which contains
6027a notice placed by the copyright holder saying it may be distributed
6028under the terms of this General Public License. The ``Program'', below,
6029refers to any such program or work, and a ``work based on the Program''
6030means either the Program or any derivative work under copyright law:
6031that is to say, a work containing the Program or a portion of it,
6032either verbatim or with modifications and/or translated into another
6033language. (Hereinafter, translation is included without limitation in
6034the term ``modification''.) Each licensee is addressed as ``you''.
6035
6036Activities other than copying, distribution and modification are not
6037covered by this License; they are outside its scope. The act of
6038running the Program is not restricted, and the output from the Program
6039is covered only if its contents constitute a work based on the
6040Program (independent of having been made by running the Program).
6041Whether that is true depends on what the Program does.
70b88761
RP
6042
6043@item
7463aadd
RP
6044You may copy and distribute verbatim copies of the Program's
6045source code as you receive it, in any medium, provided that you
6046conspicuously and appropriately publish on each copy an appropriate
6047copyright notice and disclaimer of warranty; keep intact all the
6048notices that refer to this License and to the absence of any warranty;
6049and give any other recipients of the Program a copy of this License
6050along with the Program.
70b88761 6051
7463aadd
RP
6052You may charge a fee for the physical act of transferring a copy, and
6053you may at your option offer warranty protection in exchange for a fee.
70b88761 6054
70b88761 6055@item
7463aadd
RP
6056You may modify your copy or copies of the Program or any portion
6057of it, thus forming a work based on the Program, and copy and
6058distribute such modifications or work under the terms of Section 1
6059above, provided that you also meet all of these conditions:
70b88761 6060
7463aadd 6061@alphaenumerate
70b88761 6062@item
7463aadd
RP
6063You must cause the modified files to carry prominent notices
6064stating that you changed the files and the date of any change.
70b88761
RP
6065
6066@item
7463aadd
RP
6067You must cause any work that you distribute or publish, that in
6068whole or in part contains or is derived from the Program or any
6069part thereof, to be licensed as a whole at no charge to all third
6070parties under the terms of this License.
70b88761
RP
6071
6072@item
7463aadd
RP
6073If the modified program normally reads commands interactively
6074when run, you must cause it, when started running for such
6075interactive use in the most ordinary way, to print or display an
6076announcement including an appropriate copyright notice and a
6077notice that there is no warranty (or else, saying that you provide
6078a warranty) and that users may redistribute the program under
6079these conditions, and telling the user how to view a copy of this
6080License. (Exception: if the Program itself is interactive but
6081does not normally print such an announcement, your work based on
6082the Program is not required to print an announcement.)
6083@end alphaenumerate
6084
6085These requirements apply to the modified work as a whole. If
6086identifiable sections of that work are not derived from the Program,
6087and can be reasonably considered independent and separate works in
6088themselves, then this License, and its terms, do not apply to those
6089sections when you distribute them as separate works. But when you
6090distribute the same sections as part of a whole which is a work based
6091on the Program, the distribution of the whole must be on the terms of
6092this License, whose permissions for other licensees extend to the
6093entire whole, and thus to each and every part regardless of who wrote it.
6094
6095Thus, it is not the intent of this section to claim rights or contest
6096your rights to work written entirely by you; rather, the intent is to
6097exercise the right to control the distribution of derivative or
6098collective works based on the Program.
6099
6100In addition, mere aggregation of another work not based on the Program
6101with the Program (or with a work based on the Program) on a volume of
6102a storage or distribution medium does not bring the other work under
6103the scope of this License.
70b88761
RP
6104
6105@item
7463aadd
RP
6106You may copy and distribute the Program (or a work based on it,
6107under Section 2) in object code or executable form under the terms of
6108Sections 1 and 2 above provided that you also do one of the following:
70b88761 6109
7463aadd 6110@alphaenumerate
70b88761 6111@item
7463aadd
RP
6112Accompany it with the complete corresponding machine-readable
6113source code, which must be distributed under the terms of Sections
61141 and 2 above on a medium customarily used for software interchange; or,
70b88761
RP
6115
6116@item
7463aadd
RP
6117Accompany it with a written offer, valid for at least three
6118years, to give any third party, for a charge no more than your
6119cost of physically performing source distribution, a complete
6120machine-readable copy of the corresponding source code, to be
6121distributed under the terms of Sections 1 and 2 above on a medium
6122customarily used for software interchange; or,
70b88761
RP
6123
6124@item
7463aadd
RP
6125Accompany it with the information you received as to the offer
6126to distribute corresponding source code. (This alternative is
70b88761 6127allowed only for noncommercial distribution and only if you
7463aadd
RP
6128received the program in object code or executable form with such
6129an offer, in accord with Subsection b above.)
6130@end alphaenumerate
6131
6132The source code for a work means the preferred form of the work for
6133making modifications to it. For an executable work, complete source
6134code means all the source code for all modules it contains, plus any
6135associated interface definition files, plus the scripts used to
6136control compilation and installation of the executable. However, as a
6137special exception, the source code distributed need not include
6138anything that is normally distributed (in either source or binary
6139form) with the major components (compiler, kernel, and so on) of the
6140operating system on which the executable runs, unless that component
6141itself accompanies the executable.
6142
6143If distribution of executable or object code is made by offering
6144access to copy from a designated place, then offering equivalent
6145access to copy the source code from the same place counts as
6146distribution of the source code, even though third parties are not
6147compelled to copy the source along with the object code.
70b88761
RP
6148
6149@item
7463aadd
RP
6150You may not copy, modify, sublicense, or distribute the Program
6151except as expressly provided under this License. Any attempt
6152otherwise to copy, modify, sublicense or distribute the Program is
6153void, and will automatically terminate your rights under this License.
6154However, parties who have received copies, or rights, from you under
6155this License will not have their licenses terminated so long as such
6156parties remain in full compliance.
70b88761
RP
6157
6158@item
7463aadd
RP
6159You are not required to accept this License, since you have not
6160signed it. However, nothing else grants you permission to modify or
6161distribute the Program or its derivative works. These actions are
6162prohibited by law if you do not accept this License. Therefore, by
6163modifying or distributing the Program (or any work based on the
6164Program), you indicate your acceptance of this License to do so, and
6165all its terms and conditions for copying, distributing or modifying
6166the Program or works based on it.
70b88761
RP
6167
6168@item
6169Each time you redistribute the Program (or any work based on the
7463aadd
RP
6170Program), the recipient automatically receives a license from the
6171original licensor to copy, distribute or modify the Program subject to
6172these terms and conditions. You may not impose any further
6173restrictions on the recipients' exercise of the rights granted herein.
6174You are not responsible for enforcing compliance by third parties to
6175this License.
6176
6177@item
6178If, as a consequence of a court judgment or allegation of patent
6179infringement or for any other reason (not limited to patent issues),
6180conditions are imposed on you (whether by court order, agreement or
6181otherwise) that contradict the conditions of this License, they do not
6182excuse you from the conditions of this License. If you cannot
6183distribute so as to satisfy simultaneously your obligations under this
6184License and any other pertinent obligations, then as a consequence you
6185may not distribute the Program at all. For example, if a patent
6186license would not permit royalty-free redistribution of the Program by
6187all those who receive copies directly or indirectly through you, then
6188the only way you could satisfy both it and this License would be to
6189refrain entirely from distribution of the Program.
6190
6191If any portion of this section is held invalid or unenforceable under
6192any particular circumstance, the balance of the section is intended to
6193apply and the section as a whole is intended to apply in other
6194circumstances.
6195
6196It is not the purpose of this section to induce you to infringe any
6197patents or other property right claims or to contest validity of any
6198such claims; this section has the sole purpose of protecting the
6199integrity of the free software distribution system, which is
6200implemented by public license practices. Many people have made
6201generous contributions to the wide range of software distributed
6202through that system in reliance on consistent application of that
6203system; it is up to the author/donor to decide if he or she is willing
6204to distribute software through any other system and a licensee cannot
6205impose that choice.
6206
6207This section is intended to make thoroughly clear what is believed to
6208be a consequence of the rest of this License.
6209
6210@item
6211If the distribution and/or use of the Program is restricted in
6212certain countries either by patents or by copyrighted interfaces, the
6213original copyright holder who places the Program under this License
6214may add an explicit geographical distribution limitation excluding
6215those countries, so that distribution is permitted only in or among
6216countries not thus excluded. In such case, this License incorporates
6217the limitation as if written in the body of this License.
70b88761
RP
6218
6219@item
6220The Free Software Foundation may publish revised and/or new versions
6221of the General Public License from time to time. Such new versions will
6222be similar in spirit to the present version, but may differ in detail to
6223address new problems or concerns.
6224
6225Each version is given a distinguishing version number. If the Program
7463aadd 6226specifies a version number of this License which applies to it and ``any
70b88761
RP
6227later version'', you have the option of following the terms and conditions
6228either of that version or of any later version published by the Free
6229Software Foundation. If the Program does not specify a version number of
7463aadd 6230this License, you may choose any version ever published by the Free Software
70b88761
RP
6231Foundation.
6232
6233@item
6234If you wish to incorporate parts of the Program into other free
6235programs whose distribution conditions are different, write to the author
6236to ask for permission. For software which is copyrighted by the Free
6237Software Foundation, write to the Free Software Foundation; we sometimes
6238make exceptions for this. Our decision will be guided by the two goals
6239of preserving the free status of all derivatives of our free software and
6240of promoting the sharing and reuse of software generally.
6241
6242@iftex
6243@heading NO WARRANTY
6244@end iftex
6245@ifinfo
6246@center NO WARRANTY
6247@end ifinfo
6248
6249@item
6250BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
6251FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN
6252OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
6253PROVIDE THE PROGRAM ``AS IS'' WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED
6254OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
6255MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS
6256TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE
6257PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,
6258REPAIR OR CORRECTION.
6259
6260@item
7463aadd
RP
6261IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
6262WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
70b88761 6263REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,
7463aadd
RP
6264INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING
6265OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED
6266TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY
6267YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER
6268PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE
6269POSSIBILITY OF SUCH DAMAGES.
70b88761
RP
6270@end enumerate
6271
6272@iftex
6273@heading END OF TERMS AND CONDITIONS
6274@end iftex
6275@ifinfo
6276@center END OF TERMS AND CONDITIONS
6277@end ifinfo
6278
6279@page
54e6b3c3 6280@unnumberedsec Applying These Terms to Your New Programs
70b88761
RP
6281
6282 If you develop a new program, and you want it to be of the greatest
7463aadd
RP
6283possible use to the public, the best way to achieve this is to make it
6284free software which everyone can redistribute and change under these terms.
70b88761 6285
7463aadd
RP
6286 To do so, attach the following notices to the program. It is safest
6287to attach them to the start of each source file to most effectively
6288convey the exclusion of warranty; and each file should have at least
6289the ``copyright'' line and a pointer to where the full notice is found.
70b88761
RP
6290
6291@smallexample
6292@var{one line to give the program's name and a brief idea of what it does.}
6293Copyright (C) 19@var{yy} @var{name of author}
6294
6295This program is free software; you can redistribute it and/or modify
6296it under the terms of the GNU General Public License as published by
7463aadd
RP
6297the Free Software Foundation; either version 2 of the License, or
6298(at your option) any later version.
70b88761
RP
6299
6300This program is distributed in the hope that it will be useful,
6301but WITHOUT ANY WARRANTY; without even the implied warranty of
6302MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
6303GNU General Public License for more details.
6304
6305You should have received a copy of the GNU General Public License
6306along with this program; if not, write to the Free Software
6307Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
6308@end smallexample
6309
6310Also add information on how to contact you by electronic and paper mail.
6311
6312If the program is interactive, make it output a short notice like this
6313when it starts in an interactive mode:
6314
6315@smallexample
6316Gnomovision version 69, Copyright (C) 19@var{yy} @var{name of author}
6317Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
6318This is free software, and you are welcome to redistribute it
6319under certain conditions; type `show c' for details.
6320@end smallexample
6321
7463aadd
RP
6322The hypothetical commands @samp{show w} and @samp{show c} should show
6323the appropriate parts of the General Public License. Of course, the
6324commands you use may be called something other than @samp{show w} and
6325@samp{show c}; they could even be mouse-clicks or menu items---whatever
6326suits your program.
70b88761
RP
6327
6328You should also get your employer (if you work as a programmer) or your
6329school, if any, to sign a ``copyright disclaimer'' for the program, if
6330necessary. Here is a sample; alter the names:
6331
7463aadd
RP
6332@example
6333Yoyodyne, Inc., hereby disclaims all copyright interest in the program
6334`Gnomovision' (which makes passes at compilers) written by James Hacker.
70b88761
RP
6335
6336@var{signature of Ty Coon}, 1 April 1989
6337Ty Coon, President of Vice
7463aadd
RP
6338@end example
6339
6340This General Public License does not permit incorporating your program into
6341proprietary programs. If your program is a subroutine library, you may
6342consider it more useful to permit linking proprietary applications with the
6343library. If this is what you want to do, use the GNU Library General
6344Public License instead of this License.
70b88761 6345
d2e08421 6346
9c3ad547 6347@node Index, , Copying, Top
d2e08421 6348@unnumbered Index
e91b87a3 6349
6350@printindex cp
6351
fe3f5fc8
RP
6352@tex
6353% I think something like @colophon should be in texinfo. In the
6354% meantime:
6355\long\def\colophon{\hbox to0pt{}\vfill
6356\centerline{The body of this manual is set in}
6357\centerline{\fontname\tenrm,}
6358\centerline{with headings in {\bf\fontname\tenbf}}
6359\centerline{and examples in {\tt\fontname\tentt}.}
6360\centerline{{\it\fontname\tenit\/} and}
6361\centerline{{\sl\fontname\tensl\/}}
6362\centerline{are used for emphasis.}\vfill}
6363\page\colophon
6364% Blame: [email protected], 28mar91.
6365@end tex
6366
e91b87a3 6367@contents
6368@bye
This page took 0.843895 seconds and 4 git commands to generate.