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