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