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