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