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