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