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