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