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