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