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