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