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