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