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