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