* gdb.texinfo (New Features): mention threads.
[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.10
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, etc. 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, etc.
228 using Fortran syntax. It may be necessary to refer to some variables
229 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, realtime systems over a TCP/IP connection, etc. 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:: @value{GDBN} and the UDI protocol for AMD29K
795 * EB29K Remote:: @value{GDBN} with a remote EB29K
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. They can
2182 be deleted, disabled, made conditional, etc., in the standard ways.
2183
2184 @ifclear CONLY
2185 When debugging C++ programs, @code{rbreak} is useful for setting
2186 breakpoints on overloaded functions that are not members of any special
2187 classes.
2188 @end ifclear
2189
2190 @kindex info breakpoints
2191 @cindex @code{$_} and @code{info breakpoints}
2192 @item info breakpoints @r{[}@var{n}@r{]}
2193 @itemx info break @r{[}@var{n}@r{]}
2194 @itemx info watchpoints @r{[}@var{n}@r{]}
2195 Print a table of all breakpoints and watchpoints set and not
2196 deleted, with the following columns for each breakpoint:
2197
2198 @table @emph
2199 @item Breakpoint Numbers
2200 @item Type
2201 Breakpoint or watchpoint.
2202 @item Disposition
2203 Whether the breakpoint is marked to be disabled or deleted when hit.
2204 @item Enabled or Disabled
2205 Enabled breakpoints are marked with @samp{y}. @samp{n} marks breakpoints
2206 that are not enabled.
2207 @item Address
2208 Where the breakpoint is in your program, as a memory address
2209 @item What
2210 Where the breakpoint is in the source for your program, as a file and
2211 line number.
2212 @end table
2213
2214 @noindent
2215 If a breakpoint is conditional, @code{info break} shows the condition on
2216 the line following the affected breakpoint; breakpoint commands, if any,
2217 are listed after that.
2218
2219 @noindent
2220 @code{info break} with a breakpoint
2221 number @var{n} as argument lists only that breakpoint. The
2222 convenience variable @code{$_} and the default examining-address for
2223 the @code{x} command are set to the address of the last breakpoint
2224 listed (@pxref{Memory, ,Examining memory}).
2225 @end table
2226
2227 @value{GDBN} allows you to set any number of breakpoints at the same place in
2228 your program. There is nothing silly or meaningless about this. When
2229 the breakpoints are conditional, this is even useful
2230 (@pxref{Conditions, ,Break conditions}).
2231
2232 @cindex negative breakpoint numbers
2233 @cindex internal @value{GDBN} breakpoints
2234 @value{GDBN} itself sometimes sets breakpoints in your program for special
2235 purposes, such as proper handling of @code{longjmp} (in C programs).
2236 These internal breakpoints are assigned negative numbers, starting with
2237 @code{-1}; @samp{info breakpoints} does not display them.
2238
2239 You can see these breakpoints with the @value{GDBN} maintenance command
2240 @samp{maint info breakpoints}.
2241
2242 @table @code
2243 @kindex maint info breakpoints
2244 @item maint info breakpoints
2245 Using the same format as @samp{info breakpoints}, display both the
2246 breakpoints you've set explicitly, and those @value{GDBN} is using for
2247 internal purposes. Internal breakpoints are shown with negative
2248 breakpoint numbers. The type column identifies what kind of breakpoint
2249 is shown:
2250
2251 @table @code
2252 @item breakpoint
2253 Normal, explicitly set breakpoint.
2254
2255 @item watchpoint
2256 Normal, explicitly set watchpoint.
2257
2258 @item longjmp
2259 Internal breakpoint, used to handle correctly stepping through
2260 @code{longjmp} calls.
2261
2262 @item longjmp resume
2263 Internal breakpoint at the target of a @code{longjmp}.
2264
2265 @item until
2266 Temporary internal breakpoint used by the @value{GDBN} @code{until} command.
2267
2268 @item finish
2269 Temporary internal breakpoint used by the @value{GDBN} @code{finish} command.
2270 @end table
2271
2272 @end table
2273
2274
2275 @node Set Watchpoints
2276 @subsection Setting watchpoints
2277 @cindex setting watchpoints
2278
2279 You can use a watchpoint to stop execution whenever the value of an
2280 expression changes, without having to predict a particular place
2281 where this may happen.
2282
2283 Watchpoints currently execute two orders of magnitude more slowly than
2284 other breakpoints, but this can be well worth it to catch errors where
2285 you have no clue what part of your program is the culprit. Some
2286 processors provide special hardware to support watchpoint evaluation; future
2287 releases of @value{GDBN} will use such hardware if it is available.
2288
2289 @table @code
2290 @kindex watch
2291 @item watch @var{expr}
2292 Set a watchpoint for an expression.
2293
2294 @kindex info watchpoints
2295 @item info watchpoints
2296 This command prints a list of watchpoints and breakpoints; it is the
2297 same as @code{info break}.
2298 @end table
2299
2300 @ifclear BARETARGET
2301 @quotation
2302 @cindex watchpoints and threads
2303 @cindex threads and watchpoints
2304 @emph{Warning:} in multi-thread programs, watchpoints have only limited
2305 usefulness. With the current watchpoint implementation, @value{GDBN}
2306 can only watch the value of an expression @emph{in a single thread}. If
2307 you are confident that the expression can only change due to the current
2308 thread's activity (and if you are also confident that the same thread
2309 will remain current), then you can use watchpoints as usual. However,
2310 @value{GDBN} may not notice when a non-current thread's activity changes
2311 the expression.
2312 @end quotation
2313 @end ifclear
2314
2315 @ifclear CONLY
2316 @node Exception Handling
2317 @subsection Breakpoints and exceptions
2318 @cindex exception handlers
2319
2320 Some languages, such as GNU C++, implement exception handling. You can
2321 use @value{GDBN} to examine what caused your program to raise an exception,
2322 and to list the exceptions your program is prepared to handle at a
2323 given point in time.
2324
2325 @table @code
2326 @item catch @var{exceptions}
2327 @kindex catch
2328 You can set breakpoints at active exception handlers by using the
2329 @code{catch} command. @var{exceptions} is a list of names of exceptions
2330 to catch.
2331 @end table
2332
2333 You can use @code{info catch} to list active exception handlers.
2334 @xref{Frame Info, ,Information about a frame}.
2335
2336 There are currently some limitations to exception handling in @value{GDBN}.
2337 These will be corrected in a future release.
2338
2339 @itemize @bullet
2340 @item
2341 If you call a function interactively, @value{GDBN} normally returns
2342 control to you when the function has finished executing. If the call
2343 raises an exception, however, the call may bypass the mechanism that
2344 returns control to you and cause your program to simply continue
2345 running until it hits a breakpoint, catches a signal that @value{GDBN} is
2346 listening for, or exits.
2347 @item
2348 You cannot raise an exception interactively.
2349 @item
2350 You cannot interactively install an exception handler.
2351 @end itemize
2352
2353 @cindex raise exceptions
2354 Sometimes @code{catch} is not the best way to debug exception handling:
2355 if you need to know exactly where an exception is raised, it is better to
2356 stop @emph{before} the exception handler is called, since that way you
2357 can see the stack before any unwinding takes place. If you set a
2358 breakpoint in an exception handler instead, it may not be easy to find
2359 out where the exception was raised.
2360
2361 To stop just before an exception handler is called, you need some
2362 knowledge of the implementation. In the case of GNU C++, exceptions are
2363 raised by calling a library function named @code{__raise_exception}
2364 which has the following ANSI C interface:
2365
2366 @example
2367 /* @var{addr} is where the exception identifier is stored.
2368 ID is the exception identifier. */
2369 void __raise_exception (void **@var{addr}, void *@var{id});
2370 @end example
2371
2372 @noindent
2373 To make the debugger catch all exceptions before any stack
2374 unwinding takes place, set a breakpoint on @code{__raise_exception}
2375 (@pxref{Breakpoints, ,Breakpoints; watchpoints; and exceptions}).
2376
2377 With a conditional breakpoint (@pxref{Conditions, ,Break conditions})
2378 that depends on the value of @var{id}, you can stop your program when
2379 a specific exception is raised. You can use multiple conditional
2380 breakpoints to stop your program when any of a number of exceptions are
2381 raised.
2382 @end ifclear
2383
2384 @node Delete Breaks
2385 @subsection Deleting breakpoints
2386
2387 @cindex clearing breakpoints, watchpoints
2388 @cindex deleting breakpoints, watchpoints
2389 It is often necessary to eliminate a breakpoint or watchpoint once it
2390 has done its job and you no longer want your program to stop there. This
2391 is called @dfn{deleting} the breakpoint. A breakpoint that has been
2392 deleted no longer exists; it is forgotten.
2393
2394 With the @code{clear} command you can delete breakpoints according to
2395 where they are in your program. With the @code{delete} command you can
2396 delete individual breakpoints or watchpoints by specifying their
2397 breakpoint numbers.
2398
2399 It is not necessary to delete a breakpoint to proceed past it. @value{GDBN}
2400 automatically ignores breakpoints on the first instruction to be executed
2401 when you continue execution without changing the execution address.
2402
2403 @table @code
2404 @item clear
2405 @kindex clear
2406 Delete any breakpoints at the next instruction to be executed in the
2407 selected stack frame (@pxref{Selection, ,Selecting a frame}). When
2408 the innermost frame is selected, this is a good way to delete a
2409 breakpoint where your program just stopped.
2410
2411 @item clear @var{function}
2412 @itemx clear @var{filename}:@var{function}
2413 Delete any breakpoints set at entry to the function @var{function}.
2414
2415 @item clear @var{linenum}
2416 @itemx clear @var{filename}:@var{linenum}
2417 Delete any breakpoints set at or within the code of the specified line.
2418
2419 @item delete @r{[}breakpoints@r{]} @r{[}@var{bnums}@dots{}@r{]}
2420 @cindex delete breakpoints
2421 @kindex delete
2422 @kindex d
2423 Delete the breakpoints or watchpoints of the numbers specified as
2424 arguments. If no argument is specified, delete all breakpoints (@value{GDBN}
2425 asks confirmation, unless you have @code{set confirm off}). You
2426 can abbreviate this command as @code{d}.
2427 @end table
2428
2429 @node Disabling
2430 @subsection Disabling breakpoints
2431
2432 @cindex disabled breakpoints
2433 @cindex enabled breakpoints
2434 Rather than deleting a breakpoint or watchpoint, you might prefer to
2435 @dfn{disable} it. This makes the breakpoint inoperative as if it had
2436 been deleted, but remembers the information on the breakpoint so that
2437 you can @dfn{enable} it again later.
2438
2439 You disable and enable breakpoints and watchpoints with the
2440 @code{enable} and @code{disable} commands, optionally specifying one or
2441 more breakpoint numbers as arguments. Use @code{info break} or
2442 @code{info watch} to print a list of breakpoints or watchpoints if you
2443 do not know which numbers to use.
2444
2445 A breakpoint or watchpoint can have any of four different states of
2446 enablement:
2447
2448 @itemize @bullet
2449 @item
2450 Enabled. The breakpoint will stop your program. A breakpoint set
2451 with the @code{break} command starts out in this state.
2452 @item
2453 Disabled. The breakpoint has no effect on your program.
2454 @item
2455 Enabled once. The breakpoint will stop your program, but
2456 when it does so it will become disabled. A breakpoint set
2457 with the @code{tbreak} command starts out in this state.
2458 @item
2459 Enabled for deletion. The breakpoint will stop your program, but
2460 immediately after it does so it will be deleted permanently.
2461 @end itemize
2462
2463 You can use the following commands to enable or disable breakpoints and
2464 watchpoints:
2465
2466 @table @code
2467 @item disable @r{[}breakpoints@r{]} @r{[}@var{bnums}@dots{}@r{]}
2468 @kindex disable breakpoints
2469 @kindex disable
2470 @kindex dis
2471 Disable the specified breakpoints---or all breakpoints, if none are
2472 listed. A disabled breakpoint has no effect but is not forgotten. All
2473 options such as ignore-counts, conditions and commands are remembered in
2474 case the breakpoint is enabled again later. You may abbreviate
2475 @code{disable} as @code{dis}.
2476
2477 @item enable @r{[}breakpoints@r{]} @r{[}@var{bnums}@dots{}@r{]}
2478 @kindex enable breakpoints
2479 @kindex enable
2480 Enable the specified breakpoints (or all defined breakpoints). They
2481 become effective once again in stopping your program.
2482
2483 @item enable @r{[}breakpoints@r{]} once @var{bnums}@dots{}
2484 Enable the specified breakpoints temporarily. Each will be disabled
2485 again the next time it stops your program.
2486
2487 @item enable @r{[}breakpoints@r{]} delete @var{bnums}@dots{}
2488 Enable the specified breakpoints to work once and then die. Each of
2489 the breakpoints will be deleted the next time it stops your program.
2490 @end table
2491
2492 Save for a breakpoint set with @code{tbreak} (@pxref{Set Breaks,
2493 ,Setting breakpoints}), breakpoints that you set are initially enabled;
2494 subsequently, they become disabled or enabled only when you use one of
2495 the commands above. (The command @code{until} can set and delete a
2496 breakpoint of its own, but it will not change the state of your other
2497 breakpoints; see @ref{Continuing and Stepping, ,Continuing and
2498 stepping}.)
2499
2500 @node Conditions
2501 @subsection Break conditions
2502 @cindex conditional breakpoints
2503 @cindex breakpoint conditions
2504
2505 @c FIXME what is scope of break condition expr? Context where wanted?
2506 @c in particular for a watchpoint?
2507 The simplest sort of breakpoint breaks every time your program reaches a
2508 specified place. You can also specify a @dfn{condition} for a
2509 breakpoint. A condition is just a Boolean expression in your
2510 programming language (@pxref{Expressions, ,Expressions}). A breakpoint with
2511 a condition evaluates the expression each time your program reaches it,
2512 and your program stops only if the condition is @emph{true}.
2513
2514 This is the converse of using assertions for program validation; in that
2515 situation, you want to stop when the assertion is violated---that is,
2516 when the condition is false. In C, if you want to test an assertion expressed
2517 by the condition @var{assert}, you should set the condition
2518 @samp{! @var{assert}} on the appropriate breakpoint.
2519
2520 Conditions are also accepted for watchpoints; you may not need them,
2521 since a watchpoint is inspecting the value of an expression anyhow---but
2522 it might be simpler, say, to just set a watchpoint on a variable name,
2523 and specify a condition that tests whether the new value is an interesting
2524 one.
2525
2526 Break conditions can have side effects, and may even call functions in
2527 your program. This can be useful, for example, to activate functions
2528 that log program progress, or to use your own print functions to
2529 format special data structures. The effects are completely predictable
2530 unless there is another enabled breakpoint at the same address. (In
2531 that case, @value{GDBN} might see the other breakpoint first and stop your
2532 program without checking the condition of this one.) Note that
2533 breakpoint commands are usually more convenient and flexible for the
2534 purpose of performing side effects when a breakpoint is reached
2535 (@pxref{Break Commands, ,Breakpoint command lists}).
2536
2537 Break conditions can be specified when a breakpoint is set, by using
2538 @samp{if} in the arguments to the @code{break} command. @xref{Set
2539 Breaks, ,Setting breakpoints}. They can also be changed at any time
2540 with the @code{condition} command. The @code{watch} command does not
2541 recognize the @code{if} keyword; @code{condition} is the only way to
2542 impose a further condition on a watchpoint.
2543
2544 @table @code
2545 @item condition @var{bnum} @var{expression}
2546 @kindex condition
2547 Specify @var{expression} as the break condition for breakpoint or
2548 watchpoint number @var{bnum}. From now on, this breakpoint will stop
2549 your program only if the value of @var{expression} is true (nonzero, in
2550 C). When you use @code{condition}, @value{GDBN} checks @var{expression}
2551 immediately for syntactic correctness, and to determine whether symbols
2552 in it have referents in the context of your breakpoint.
2553 @c FIXME so what does GDB do if there is no referent? Moreover, what
2554 @c about watchpoints?
2555 @value{GDBN} does
2556 not actually evaluate @var{expression} at the time the @code{condition}
2557 command is given, however. @xref{Expressions, ,Expressions}.
2558
2559 @item condition @var{bnum}
2560 Remove the condition from breakpoint number @var{bnum}. It becomes
2561 an ordinary unconditional breakpoint.
2562 @end table
2563
2564 @cindex ignore count (of breakpoint)
2565 A special case of a breakpoint condition is to stop only when the
2566 breakpoint has been reached a certain number of times. This is so
2567 useful that there is a special way to do it, using the @dfn{ignore
2568 count} of the breakpoint. Every breakpoint has an ignore count, which
2569 is an integer. Most of the time, the ignore count is zero, and
2570 therefore has no effect. But if your program reaches a breakpoint whose
2571 ignore count is positive, then instead of stopping, it just decrements
2572 the ignore count by one and continues. As a result, if the ignore count
2573 value is @var{n}, the breakpoint will not stop the next @var{n} times it
2574 is reached.
2575
2576 @table @code
2577 @item ignore @var{bnum} @var{count}
2578 @kindex ignore
2579 Set the ignore count of breakpoint number @var{bnum} to @var{count}.
2580 The next @var{count} times the breakpoint is reached, your program's
2581 execution will not stop; other than to decrement the ignore count, @value{GDBN}
2582 takes no action.
2583
2584 To make the breakpoint stop the next time it is reached, specify
2585 a count of zero.
2586
2587 When you use @code{continue} to resume execution of your program from a
2588 breakpoint, you can specify an ignore count directly as an argument to
2589 @code{continue}, rather than using @code{ignore}. @xref{Continuing and
2590 Stepping,,Continuing and stepping}.
2591
2592 If a breakpoint has a positive ignore count and a condition, the condition
2593 is not checked. Once the ignore count reaches zero, the condition will
2594 be checked.
2595
2596 You could achieve the effect of the ignore count with a condition such
2597 as @w{@samp{$foo-- <= 0}} using a debugger convenience variable that
2598 is decremented each time. @xref{Convenience Vars, ,Convenience
2599 variables}.
2600 @end table
2601
2602 @node Break Commands
2603 @subsection Breakpoint command lists
2604
2605 @cindex breakpoint commands
2606 You can give any breakpoint (or watchpoint) a series of commands to
2607 execute when your program stops due to that breakpoint. For example, you
2608 might want to print the values of certain expressions, or enable other
2609 breakpoints.
2610
2611 @table @code
2612 @item commands @r{[}@var{bnum}@r{]}
2613 @itemx @dots{} @var{command-list} @dots{}
2614 @itemx end
2615 @kindex commands
2616 @kindex end
2617 Specify a list of commands for breakpoint number @var{bnum}. The commands
2618 themselves appear on the following lines. Type a line containing just
2619 @code{end} to terminate the commands.
2620
2621 To remove all commands from a breakpoint, type @code{commands} and
2622 follow it immediately with @code{end}; that is, give no commands.
2623
2624 With no @var{bnum} argument, @code{commands} refers to the last
2625 breakpoint or watchpoint set (not to the breakpoint most recently
2626 encountered).
2627 @end table
2628
2629 Pressing @key{RET} as a means of repeating the last @value{GDBN} command is
2630 disabled within a @var{command-list}.
2631
2632 You can use breakpoint commands to start your program up again. Simply
2633 use the @code{continue} command, or @code{step}, or any other command
2634 that resumes execution.
2635
2636 Any other commands in the command list, after a command that resumes
2637 execution, are ignored. This is because any time you resume execution
2638 (even with a simple @code{next} or @code{step}), you may encounter
2639 another breakpoint---which could have its own command list, leading to
2640 ambiguities about which list to execute.
2641
2642 @kindex silent
2643 If the first command you specify in a command list is @code{silent}, the
2644 usual message about stopping at a breakpoint is not printed. This may
2645 be desirable for breakpoints that are to print a specific message and
2646 then continue. If none of the remaining commands print anything, you
2647 will see no sign that the breakpoint was reached. @code{silent} is
2648 meaningful only at the beginning of a breakpoint command list.
2649
2650 The commands @code{echo}, @code{output}, and @code{printf} allow you to
2651 print precisely controlled output, and are often useful in silent
2652 breakpoints. @xref{Output, ,Commands for controlled output}.
2653
2654 For example, here is how you could use breakpoint commands to print the
2655 value of @code{x} at entry to @code{foo} whenever @code{x} is positive.
2656
2657 @example
2658 break foo if x>0
2659 commands
2660 silent
2661 printf "x is %d\n",x
2662 cont
2663 end
2664 @end example
2665
2666 One application for breakpoint commands is to compensate for one bug so
2667 you can test for another. Put a breakpoint just after the erroneous line
2668 of code, give it a condition to detect the case in which something
2669 erroneous has been done, and give it commands to assign correct values
2670 to any variables that need them. End with the @code{continue} command
2671 so that your program does not stop, and start with the @code{silent}
2672 command so that no output is produced. Here is an example:
2673
2674 @example
2675 break 403
2676 commands
2677 silent
2678 set x = y + 4
2679 cont
2680 end
2681 @end example
2682
2683 @ifclear CONLY
2684 @node Breakpoint Menus
2685 @subsection Breakpoint menus
2686 @cindex overloading
2687 @cindex symbol overloading
2688
2689 Some programming languages (notably C++) permit a single function name
2690 to be defined several times, for application in different contexts.
2691 This is called @dfn{overloading}. When a function name is overloaded,
2692 @samp{break @var{function}} is not enough to tell @value{GDBN} where you want
2693 a breakpoint. If you realize this will be a problem, you can use
2694 something like @samp{break @var{function}(@var{types})} to specify which
2695 particular version of the function you want. Otherwise, @value{GDBN} offers
2696 you a menu of numbered choices for different possible breakpoints, and
2697 waits for your selection with the prompt @samp{>}. The first two
2698 options are always @samp{[0] cancel} and @samp{[1] all}. Typing @kbd{1}
2699 sets a breakpoint at each definition of @var{function}, and typing
2700 @kbd{0} aborts the @code{break} command without setting any new
2701 breakpoints.
2702
2703 For example, the following session excerpt shows an attempt to set a
2704 breakpoint at the overloaded symbol @code{String::after}.
2705 We choose three particular definitions of that function name:
2706
2707 @c FIXME! This is likely to change to show arg type lists, at least
2708 @smallexample
2709 (@value{GDBP}) b String::after
2710 [0] cancel
2711 [1] all
2712 [2] file:String.cc; line number:867
2713 [3] file:String.cc; line number:860
2714 [4] file:String.cc; line number:875
2715 [5] file:String.cc; line number:853
2716 [6] file:String.cc; line number:846
2717 [7] file:String.cc; line number:735
2718 > 2 4 6
2719 Breakpoint 1 at 0xb26c: file String.cc, line 867.
2720 Breakpoint 2 at 0xb344: file String.cc, line 875.
2721 Breakpoint 3 at 0xafcc: file String.cc, line 846.
2722 Multiple breakpoints were set.
2723 Use the "delete" command to delete unwanted
2724 breakpoints.
2725 (@value{GDBP})
2726 @end smallexample
2727 @end ifclear
2728
2729 @ifclear BARETARGET
2730 @node Error in Breakpoints
2731 @subsection ``Cannot insert breakpoints''
2732
2733 @c FIXME: "cannot insert breakpoints" error, v unclear.
2734 @c Q in pending mail to Gilmore. ---pesch@cygnus.com, 26mar91
2735 @c some light may be shed by looking at instances of
2736 @c ONE_PROCESS_WRITETEXT. But error message seems possible otherwise
2737 @c too. pesch, 20sep91
2738 Under some operating systems, breakpoints cannot be used in a program if
2739 any other process is running that program. In this situation,
2740 attempting to run or continue a program with a breakpoint causes @value{GDBN}
2741 to stop the other process.
2742
2743 When this happens, you have three ways to proceed:
2744
2745 @enumerate
2746 @item
2747 Remove or disable the breakpoints, then continue.
2748
2749 @item
2750 Suspend @value{GDBN}, and copy the file containing your program to a new name.
2751 Resume @value{GDBN} and use the @code{exec-file} command to specify that @value{GDBN}
2752 should run your program under that name. Then start your program again.
2753
2754 @c FIXME: RMS commented here "Show example". Maybe when someone
2755 @c explains the first FIXME: in this section...
2756
2757 @item
2758 Relink your program so that the text segment is nonsharable, using the
2759 linker option @samp{-N}. The operating system limitation may not apply
2760 to nonsharable executables.
2761 @end enumerate
2762 @end ifclear
2763
2764 @node Continuing and Stepping
2765 @section Continuing and stepping
2766
2767 @cindex stepping
2768 @cindex continuing
2769 @cindex resuming execution
2770 @dfn{Continuing} means resuming program execution until your program
2771 completes normally. In contrast, @dfn{stepping} means executing just
2772 one more ``step'' of your program, where ``step'' may mean either one
2773 line of source code, or one machine instruction (depending on what
2774 particular command you use). Either when continuing
2775 or when stepping, your program may stop even sooner, due to
2776 @ifset BARETARGET
2777 a breakpoint.
2778 @end ifset
2779 @ifclear BARETARGET
2780 a breakpoint or a signal. (If due to a signal, you may want to use
2781 @code{handle}, or use @samp{signal 0} to resume execution.
2782 @xref{Signals, ,Signals}.)
2783 @end ifclear
2784
2785 @table @code
2786 @item continue @r{[}@var{ignore-count}@r{]}
2787 @itemx c @r{[}@var{ignore-count}@r{]}
2788 @itemx fg @r{[}@var{ignore-count}@r{]}
2789 @kindex continue
2790 @kindex c
2791 @kindex fg
2792 Resume program execution, at the address where your program last stopped;
2793 any breakpoints set at that address are bypassed. The optional argument
2794 @var{ignore-count} allows you to specify a further number of times to
2795 ignore a breakpoint at this location; its effect is like that of
2796 @code{ignore} (@pxref{Conditions, ,Break conditions}).
2797
2798 The argument @var{ignore-count} is meaningful only when your program
2799 stopped due to a breakpoint. At other times, the argument to
2800 @code{continue} is ignored.
2801
2802 The synonyms @code{c} and @code{fg} are provided purely for convenience,
2803 and have exactly the same behavior as @code{continue}.
2804 @end table
2805
2806 To resume execution at a different place, you can use @code{return}
2807 (@pxref{Returning, ,Returning from a function}) to go back to the
2808 calling function; or @code{jump} (@pxref{Jumping, ,Continuing at a
2809 different address}) to go to an arbitrary location in your program.
2810
2811 A typical technique for using stepping is to set a breakpoint
2812 @ifclear CONLY
2813 (@pxref{Breakpoints, ,Breakpoints; watchpoints; and exceptions})
2814 @end ifclear
2815 @ifset CONLY
2816 (@pxref{Breakpoints, ,Breakpoints and watchpoints})
2817 @end ifset
2818 at the
2819 beginning of the function or the section of your program where a
2820 problem is believed to lie, run your program until it stops at that
2821 breakpoint, and then step through the suspect area, examining the
2822 variables that are interesting, until you see the problem happen.
2823
2824 @table @code
2825 @item step
2826 @kindex step
2827 @kindex s
2828 Continue running your program until control reaches a different source
2829 line, then stop it and return control to @value{GDBN}. This command is
2830 abbreviated @code{s}.
2831
2832 @quotation
2833 @emph{Warning:} If you use the @code{step} command while control is
2834 within a function that was compiled without debugging information,
2835 execution proceeds until control reaches a function that does have
2836 debugging information.
2837 @end quotation
2838
2839 @item step @var{count}
2840 Continue running as in @code{step}, but do so @var{count} times. If a
2841 breakpoint is reached,
2842 @ifclear BARETARGET
2843 or a signal not related to stepping occurs before @var{count} steps,
2844 @end ifclear
2845 stepping stops right away.
2846
2847 @item next @r{[}@var{count}@r{]}
2848 @kindex next
2849 @kindex n
2850 Continue to the next source line in the current (innermost) stack frame.
2851 Similar to @code{step}, but any function calls appearing within the line
2852 of code are executed without stopping. Execution stops when control
2853 reaches a different line of code at the stack level which was executing
2854 when the @code{next} command was given. This command is abbreviated
2855 @code{n}.
2856
2857 An argument @var{count} is a repeat count, as for @code{step}.
2858
2859 @code{next} within a function that lacks debugging information acts like
2860 @code{step}, but any function calls appearing within the code of the
2861 function are executed without stopping.
2862
2863 @item finish
2864 @kindex finish
2865 Continue running until just after function in the selected stack frame
2866 returns. Print the returned value (if any).
2867
2868 Contrast this with the @code{return} command (@pxref{Returning,
2869 ,Returning from a function}).
2870
2871 @item until
2872 @kindex until
2873 @itemx u
2874 @kindex u
2875 Continue running until a source line past the current line, in the
2876 current stack frame, is reached. This command is used to avoid single
2877 stepping through a loop more than once. It is like the @code{next}
2878 command, except that when @code{until} encounters a jump, it
2879 automatically continues execution until the program counter is greater
2880 than the address of the jump.
2881
2882 This means that when you reach the end of a loop after single stepping
2883 though it, @code{until} will cause your program to continue execution
2884 until the loop is exited. In contrast, a @code{next} command at the end
2885 of a loop will simply step back to the beginning of the loop, which
2886 would force you to step through the next iteration.
2887
2888 @code{until} always stops your program if it attempts to exit the current
2889 stack frame.
2890
2891 @code{until} may produce somewhat counterintuitive results if the order
2892 of machine code does not match the order of the source lines. For
2893 example, in the following excerpt from a debugging session, the @code{f}
2894 (@code{frame}) command shows that execution is stopped at line
2895 @code{206}; yet when we use @code{until}, we get to line @code{195}:
2896
2897 @example
2898 (@value{GDBP}) f
2899 #0 main (argc=4, argv=0xf7fffae8) at m4.c:206
2900 206 expand_input();
2901 (@value{GDBP}) until
2902 195 for ( ; argc > 0; NEXTARG) @{
2903 @end example
2904
2905 This happened because, for execution efficiency, the compiler had
2906 generated code for the loop closure test at the end, rather than the
2907 start, of the loop---even though the test in a C @code{for}-loop is
2908 written before the body of the loop. The @code{until} command appeared
2909 to step back to the beginning of the loop when it advanced to this
2910 expression; however, it has not really gone to an earlier
2911 statement---not in terms of the actual machine code.
2912
2913 @code{until} with no argument works by means of single
2914 instruction stepping, and hence is slower than @code{until} with an
2915 argument.
2916
2917 @item until @var{location}
2918 @itemx u @var{location}
2919 Continue running your program until either the specified location is
2920 reached, or the current stack frame returns. @var{location} is any of
2921 the forms of argument acceptable to @code{break} (@pxref{Set Breaks,
2922 ,Setting breakpoints}). This form of the command uses breakpoints,
2923 and hence is quicker than @code{until} without an argument.
2924
2925 @item stepi
2926 @itemx si
2927 @kindex stepi
2928 @kindex si
2929 Execute one machine instruction, then stop and return to the debugger.
2930
2931 It is often useful to do @samp{display/i $pc} when stepping by machine
2932 instructions. This will cause the next instruction to be executed to
2933 be displayed automatically at each stop. @xref{Auto Display,
2934 ,Automatic display}.
2935
2936 An argument is a repeat count, as in @code{step}.
2937
2938 @need 750
2939 @item nexti
2940 @itemx ni
2941 @kindex nexti
2942 @kindex ni
2943 Execute one machine instruction, but if it is a function call,
2944 proceed until the function returns.
2945
2946 An argument is a repeat count, as in @code{next}.
2947 @end table
2948
2949 @ifset POSIX
2950 @node Signals
2951 @section Signals
2952 @cindex signals
2953
2954 A signal is an asynchronous event that can happen in a program. The
2955 operating system defines the possible kinds of signals, and gives each
2956 kind a name and a number. For example, in Unix @code{SIGINT} is the
2957 signal a program gets when you type an interrupt (often @kbd{C-c});
2958 @code{SIGSEGV} is the signal a program gets from referencing a place in
2959 memory far away from all the areas in use; @code{SIGALRM} occurs when
2960 the alarm clock timer goes off (which happens only if your program has
2961 requested an alarm).
2962
2963 @cindex fatal signals
2964 Some signals, including @code{SIGALRM}, are a normal part of the
2965 functioning of your program. Others, such as @code{SIGSEGV}, indicate
2966 errors; these signals are @dfn{fatal} (kill your program immediately) if the
2967 program has not specified in advance some other way to handle the signal.
2968 @code{SIGINT} does not indicate an error in your program, but it is normally
2969 fatal so it can carry out the purpose of the interrupt: to kill the program.
2970
2971 @value{GDBN} has the ability to detect any occurrence of a signal in your
2972 program. You can tell @value{GDBN} in advance what to do for each kind of
2973 signal.
2974
2975 @cindex handling signals
2976 Normally, @value{GDBN} is set up to ignore non-erroneous signals like @code{SIGALRM}
2977 (so as not to interfere with their role in the functioning of your program)
2978 but to stop your program immediately whenever an error signal happens.
2979 You can change these settings with the @code{handle} command.
2980
2981 @table @code
2982 @item info signals
2983 @kindex info signals
2984 Print a table of all the kinds of signals and how @value{GDBN} has been told to
2985 handle each one. You can use this to see the signal numbers of all
2986 the defined types of signals.
2987
2988 @item handle @var{signal} @var{keywords}@dots{}
2989 @kindex handle
2990 Change the way @value{GDBN} handles signal @var{signal}. @var{signal} can be the
2991 number of a signal or its name (with or without the @samp{SIG} at the
2992 beginning). The @var{keywords} say what change to make.
2993 @end table
2994
2995 @c @group
2996 The keywords allowed by the @code{handle} command can be abbreviated.
2997 Their full names are:
2998
2999 @table @code
3000 @item nostop
3001 @value{GDBN} should not stop your program when this signal happens. It may
3002 still print a message telling you that the signal has come in.
3003
3004 @item stop
3005 @value{GDBN} should stop your program when this signal happens. This implies
3006 the @code{print} keyword as well.
3007
3008 @item print
3009 @value{GDBN} should print a message when this signal happens.
3010
3011 @item noprint
3012 @value{GDBN} should not mention the occurrence of the signal at all. This
3013 implies the @code{nostop} keyword as well.
3014
3015 @item pass
3016 @value{GDBN} should allow your program to see this signal; your program will be
3017 able to handle the signal, or may be terminated if the signal is fatal
3018 and not handled.
3019
3020 @item nopass
3021 @value{GDBN} should not allow your program to see this signal.
3022 @end table
3023 @c @end group
3024
3025 When a signal stops your program, the signal is not visible until you
3026 continue. Your program will see the signal then, if @code{pass} is in
3027 effect for the signal in question @emph{at that time}. In other words,
3028 after @value{GDBN} reports a signal, you can use the @code{handle}
3029 command with @code{pass} or @code{nopass} to control whether that
3030 signal will be seen by your program when you later continue it.
3031
3032 You can also use the @code{signal} command to prevent your program from
3033 seeing a signal, or cause it to see a signal it normally would not see,
3034 or to give it any signal at any time. For example, if your program stopped
3035 due to some sort of memory reference error, you might store correct
3036 values into the erroneous variables and continue, hoping to see more
3037 execution; but your program would probably terminate immediately as
3038 a result of the fatal signal once it saw the signal. To prevent this,
3039 you can continue with @samp{signal 0}. @xref{Signaling, ,Giving your
3040 program a signal}.
3041 @end ifset
3042
3043 @ifclear BARETARGET
3044 @node Thread Stops
3045 @section Stopping and starting multi-thread programs
3046
3047 When your program has multiple threads (@pxref{Threads,, Debugging
3048 programs with multiple threads}), you can choose whether to set
3049 breakpoints on all threads, or on a particular thread.
3050
3051 @table @code
3052 @cindex breakpoints and threads
3053 @cindex thread breakpoints
3054 @kindex break @dots{} thread @var{threadno}
3055 @item break @var{linespec} thread @var{threadno}
3056 @itemx break @var{linespec} thread @var{threadno} if @dots{}
3057 Use the qualifier @samp{thread @var{threadno}} with a breakpoint command
3058 to specify that you only want @value{GDBN} to stop the program when a
3059 particular thread reaches this breakpoint. @var{threadno} is one of the
3060 numeric thread identifiers assigned by @value{GDBN}, shown in the first
3061 column of the @samp{info threads} display.
3062
3063 If you do not specify @samp{thread @var{threadno}} when you set a
3064 breakpoint, the breakpoint applies to @emph{all} threads of your
3065 program.
3066
3067 You can use the @code{thread} qualifier on conditional breakpoints as
3068 well; in this case, place @samp{thread @var{threadno}} before the
3069 breakpoint condition, like this:
3070
3071 @smallexample
3072 (gdb) break frik.c:13 thread 28 if bartab > lim
3073 @end smallexample
3074 @end table
3075
3076 @cindex stopped threads
3077 @cindex threads, stopped
3078 Whenever your program stops under @value{GDBN} for any reason,
3079 @emph{all} threads of execution stop, not just the current thread. This
3080 allows you to examine the overall state of the program, including
3081 switching between threads, without worrying that things may change
3082 underfoot.
3083
3084 @cindex continuing threads
3085 @cindex threads, continuing
3086 Conversely, whenever you restart the program, @emph{all} threads start
3087 executing. @emph{This is true even when single-stepping} with commands
3088 like @code{step} or @code{next}.
3089
3090 In particular, @value{GDBN} cannot single-step all threads in lockstep.
3091 Since thread scheduling is up to your debugging target's operating
3092 system (not controlled by @value{GDBN}), other threads may
3093 execute more than one statement while the current thread completes a
3094 single step. Moreover, in general other threads stop in the middle of a
3095 statement, rather than at a clean statement boundary, when the program
3096 stops.
3097
3098 You might even find your program stopped in another thread after
3099 continuing or even single-stepping. This happens whenever some other
3100 thread runs into a breakpoint, a signal, or an exception before the
3101 first thread completes whatever you requested.
3102 @end ifclear
3103
3104 @node Stack
3105 @chapter Examining the Stack
3106
3107 When your program has stopped, the first thing you need to know is where it
3108 stopped and how it got there.
3109
3110 @cindex call stack
3111 Each time your program performs a function call, the information about
3112 where in your program the call was made from is saved in a block of data
3113 called a @dfn{stack frame}. The frame also contains the arguments of the
3114 call and the local variables of the function that was called. All the
3115 stack frames are allocated in a region of memory called the @dfn{call
3116 stack}.
3117
3118 When your program stops, the @value{GDBN} commands for examining the
3119 stack allow you to see all of this information.
3120
3121 @cindex selected frame
3122 One of the stack frames is @dfn{selected} by @value{GDBN} and many
3123 @value{GDBN} commands refer implicitly to the selected frame. In
3124 particular, whenever you ask @value{GDBN} for the value of a variable in
3125 your program, the value is found in the selected frame. There are
3126 special @value{GDBN} commands to select whichever frame you are
3127 interested in.
3128
3129 When your program stops, @value{GDBN} automatically selects the
3130 currently executing frame and describes it briefly as the @code{frame}
3131 command does (@pxref{Frame Info, ,Information about a frame}).
3132
3133 @menu
3134 * Frames:: Stack frames
3135 * Backtrace:: Backtraces
3136 * Selection:: Selecting a frame
3137 * Frame Info:: Information on a frame
3138 @ifset MIPS
3139 * MIPS Stack:: MIPS machines and the function stack
3140 @end ifset
3141 @end menu
3142
3143 @node Frames
3144 @section Stack frames
3145
3146 @cindex frame
3147 @cindex stack frame
3148 The call stack is divided up into contiguous pieces called @dfn{stack
3149 frames}, or @dfn{frames} for short; each frame is the data associated
3150 with one call to one function. The frame contains the arguments given
3151 to the function, the function's local variables, and the address at
3152 which the function is executing.
3153
3154 @cindex initial frame
3155 @cindex outermost frame
3156 @cindex innermost frame
3157 When your program is started, the stack has only one frame, that of the
3158 function @code{main}. This is called the @dfn{initial} frame or the
3159 @dfn{outermost} frame. Each time a function is called, a new frame is
3160 made. Each time a function returns, the frame for that function invocation
3161 is eliminated. If a function is recursive, there can be many frames for
3162 the same function. The frame for the function in which execution is
3163 actually occurring is called the @dfn{innermost} frame. This is the most
3164 recently created of all the stack frames that still exist.
3165
3166 @cindex frame pointer
3167 Inside your program, stack frames are identified by their addresses. A
3168 stack frame consists of many bytes, each of which has its own address; each
3169 kind of computer has a convention for choosing one of those bytes whose
3170 address serves as the address of the frame. Usually this address is kept
3171 in a register called the @dfn{frame pointer register} while execution is
3172 going on in that frame.
3173
3174 @cindex frame number
3175 @value{GDBN} assigns numbers to all existing stack frames, starting with
3176 zero for the innermost frame, one for the frame that called it,
3177 and so on upward. These numbers do not really exist in your program;
3178 they are assigned by @value{GDBN} to give you a way of designating stack
3179 frames in @value{GDBN} commands.
3180
3181 @c below produces an acceptable overful hbox. --mew 13aug1993
3182 @cindex frameless execution
3183 Some compilers provide a way to compile functions so that they operate
3184 without stack frames. (For example, the @code{@value{GCC}} option
3185 @samp{-fomit-frame-pointer} will generate functions without a frame.)
3186 This is occasionally done with heavily used library functions to save
3187 the frame setup time. @value{GDBN} has limited facilities for dealing
3188 with these function invocations. If the innermost function invocation
3189 has no stack frame, @value{GDBN} will nevertheless regard it as though
3190 it had a separate frame, which is numbered zero as usual, allowing
3191 correct tracing of the function call chain. However, @value{GDBN} has
3192 no provision for frameless functions elsewhere in the stack.
3193
3194 @node Backtrace
3195 @section Backtraces
3196
3197 A backtrace is a summary of how your program got where it is. It shows one
3198 line per frame, for many frames, starting with the currently executing
3199 frame (frame zero), followed by its caller (frame one), and on up the
3200 stack.
3201
3202 @table @code
3203 @item backtrace
3204 @itemx bt
3205 @kindex backtrace
3206 @kindex bt
3207 Print a backtrace of the entire stack: one line per frame for all
3208 frames in the stack.
3209
3210 You can stop the backtrace at any time by typing the system interrupt
3211 character, normally @kbd{C-c}.
3212
3213 @item backtrace @var{n}
3214 @itemx bt @var{n}
3215 Similar, but print only the innermost @var{n} frames.
3216
3217 @item backtrace -@var{n}
3218 @itemx bt -@var{n}
3219 Similar, but print only the outermost @var{n} frames.
3220 @end table
3221
3222 @kindex where
3223 @kindex info stack
3224 @kindex info s
3225 The names @code{where} and @code{info stack} (abbreviated @code{info s})
3226 are additional aliases for @code{backtrace}.
3227
3228 Each line in the backtrace shows the frame number and the function name.
3229 The program counter value is also shown---unless you use @code{set
3230 print address off}. The backtrace also shows the source file name and
3231 line number, as well as the arguments to the function. The program
3232 counter value is omitted if it is at the beginning of the code for that
3233 line number.
3234
3235 Here is an example of a backtrace. It was made with the command
3236 @samp{bt 3}, so it shows the innermost three frames.
3237
3238 @smallexample
3239 @group
3240 #0 m4_traceon (obs=0x24eb0, argc=1, argv=0x2b8c8)
3241 at builtin.c:993
3242 #1 0x6e38 in expand_macro (sym=0x2b600) at macro.c:242
3243 #2 0x6840 in expand_token (obs=0x0, t=177664, td=0xf7fffb08)
3244 at macro.c:71
3245 (More stack frames follow...)
3246 @end group
3247 @end smallexample
3248
3249 @noindent
3250 The display for frame zero does not begin with a program counter
3251 value, indicating that your program has stopped at the beginning of the
3252 code for line @code{993} of @code{builtin.c}.
3253
3254 @node Selection
3255 @section Selecting a frame
3256
3257 Most commands for examining the stack and other data in your program work on
3258 whichever stack frame is selected at the moment. Here are the commands for
3259 selecting a stack frame; all of them finish by printing a brief description
3260 of the stack frame just selected.
3261
3262 @table @code
3263 @item frame @var{n}
3264 @itemx f @var{n}
3265 @kindex frame
3266 @kindex f
3267 Select frame number @var{n}. Recall that frame zero is the innermost
3268 (currently executing) frame, frame one is the frame that called the
3269 innermost one, and so on. The highest-numbered frame is the one for
3270 @code{main}.
3271
3272 @item frame @var{addr}
3273 @itemx f @var{addr}
3274 Select the frame at address @var{addr}. This is useful mainly if the
3275 chaining of stack frames has been damaged by a bug, making it
3276 impossible for @value{GDBN} to assign numbers properly to all frames. In
3277 addition, this can be useful when your program has multiple stacks and
3278 switches between them.
3279
3280 @ifset SPARC
3281 On the SPARC architecture, @code{frame} needs two addresses to
3282 select an arbitrary frame: a frame pointer and a stack pointer.
3283 @c note to future updaters: this is conditioned on a flag
3284 @c FRAME_SPECIFICATION_DYADIC in the tm-*.h files, currently only used
3285 @c by SPARC, hence the specific attribution. Generalize or list all
3286 @c possibilities if more supported machines start doing this.
3287 @end ifset
3288
3289 @item up @var{n}
3290 @kindex up
3291 Move @var{n} frames up the stack. For positive numbers @var{n}, this
3292 advances toward the outermost frame, to higher frame numbers, to frames
3293 that have existed longer. @var{n} defaults to one.
3294
3295 @item down @var{n}
3296 @kindex down
3297 @kindex do
3298 Move @var{n} frames down the stack. For positive numbers @var{n}, this
3299 advances toward the innermost frame, to lower frame numbers, to frames
3300 that were created more recently. @var{n} defaults to one. You may
3301 abbreviate @code{down} as @code{do}.
3302 @end table
3303
3304 All of these commands end by printing two lines of output describing the
3305 frame. The first line shows the frame number, the function name, the
3306 arguments, and the source file and line number of execution in that
3307 frame. The second line shows the text of that source line.
3308
3309 For example:
3310 @smallexample
3311 @group
3312 (@value{GDBP}) up
3313 #1 0x22f0 in main (argc=1, argv=0xf7fffbf4, env=0xf7fffbfc)
3314 at env.c:10
3315 10 read_input_file (argv[i]);
3316 @end group
3317 @end smallexample
3318
3319 After such a printout, the @code{list} command with no arguments will
3320 print ten lines centered on the point of execution in the frame.
3321 @xref{List, ,Printing source lines}.
3322
3323 @table @code
3324 @item up-silently @var{n}
3325 @itemx down-silently @var{n}
3326 @kindex down-silently
3327 @kindex up-silently
3328 These two commands are variants of @code{up} and @code{down},
3329 respectively; they differ in that they do their work silently, without
3330 causing display of the new frame. They are intended primarily for use
3331 in @value{GDBN} command scripts, where the output might be unnecessary and
3332 distracting.
3333 @end table
3334
3335 @node Frame Info
3336 @section Information about a frame
3337
3338 There are several other commands to print information about the selected
3339 stack frame.
3340
3341 @table @code
3342 @item frame
3343 @itemx f
3344 When used without any argument, this command does not change which
3345 frame is selected, but prints a brief description of the currently
3346 selected stack frame. It can be abbreviated @code{f}. With an
3347 argument, this command is used to select a stack frame.
3348 @xref{Selection, ,Selecting a frame}.
3349
3350 @item info frame
3351 @itemx info f
3352 @kindex info frame
3353 @kindex info f
3354 This command prints a verbose description of the selected stack frame,
3355 including the address of the frame, the addresses of the next frame down
3356 (called by this frame) and the next frame up (caller of this frame), the
3357 language that the source code corresponding to this frame was written in,
3358 the address of the frame's arguments, the program counter saved in it
3359 (the address of execution in the caller frame), and which registers
3360 were saved in the frame. The verbose description is useful when
3361 something has gone wrong that has made the stack format fail to fit
3362 the usual conventions.
3363
3364 @item info frame @var{addr}
3365 @itemx info f @var{addr}
3366 Print a verbose description of the frame at address @var{addr},
3367 without selecting that frame. The selected frame remains unchanged by
3368 this command.
3369
3370 @item info args
3371 @kindex info args
3372 Print the arguments of the selected frame, each on a separate line.
3373
3374 @item info locals
3375 @kindex info locals
3376 Print the local variables of the selected frame, each on a separate
3377 line. These are all variables (declared either static or automatic)
3378 accessible at the point of execution of the selected frame.
3379
3380 @ifclear CONLY
3381 @item info catch
3382 @kindex info catch
3383 @cindex catch exceptions
3384 @cindex exception handlers
3385 Print a list of all the exception handlers that are active in the
3386 current stack frame at the current point of execution. To see other
3387 exception handlers, visit the associated frame (using the @code{up},
3388 @code{down}, or @code{frame} commands); then type @code{info catch}.
3389 @xref{Exception Handling, ,Breakpoints and exceptions}.
3390 @end ifclear
3391 @end table
3392
3393 @ifset MIPS
3394 @node MIPS Stack
3395 @section MIPS machines and the function stack
3396
3397 @cindex stack on MIPS
3398 @cindex MIPS stack
3399 MIPS based computers use an unusual stack frame, which sometimes
3400 requires @value{GDBN} to search backward in the object code to find the
3401 beginning of a function.
3402
3403 @cindex response time, MIPS debugging
3404 To improve response time (especially for embedded applications, where
3405 @value{GDBN} may be restricted to a slow serial line for this search)
3406 you may want to limit the size of this search, using one of these
3407 commands:
3408 @c FIXME! So what happens when GDB does *not* find the beginning of a
3409 @c function?
3410
3411 @cindex @code{heuristic-fence-post} (MIPS)
3412 @table @code
3413 @item set heuristic-fence-post @var{limit}
3414 Restrict @value{GDBN} to examining at most @var{limit} bytes in its search
3415 for the beginning of a function. A value of @code{0} (the default)
3416 means there is no limit.
3417
3418 @item show heuristic-fence-post
3419 Display the current limit.
3420 @end table
3421
3422 @noindent
3423 These commands are available @emph{only} when @value{GDBN} is configured
3424 for debugging programs on MIPS processors.
3425 @end ifset
3426
3427 @node Source
3428 @chapter Examining Source Files
3429
3430 @value{GDBN} can print parts of your program's source, since the debugging
3431 information recorded in the program tells @value{GDBN} what source files were
3432 used to build it. When your program stops, @value{GDBN} spontaneously prints
3433 the line where it stopped. Likewise, when you select a stack frame
3434 (@pxref{Selection, ,Selecting a frame}), @value{GDBN} prints the line where
3435 execution in that frame has stopped. You can print other portions of
3436 source files by explicit command.
3437
3438 @ifclear DOSHOST
3439 If you use @value{GDBN} through its GNU Emacs interface, you may prefer to use
3440 Emacs facilities to view source; @pxref{Emacs, ,Using @value{GDBN} under GNU
3441 Emacs}.
3442 @end ifclear
3443
3444 @menu
3445 * List:: Printing source lines
3446 @ifclear DOSHOST
3447 * Search:: Searching source files
3448 @end ifclear
3449
3450 * Source Path:: Specifying source directories
3451 * Machine Code:: Source and machine code
3452 @end menu
3453
3454 @node List
3455 @section Printing source lines
3456
3457 @kindex list
3458 @kindex l
3459 To print lines from a source file, use the @code{list} command
3460 (abbreviated @code{l}). There are several ways to specify what part
3461 of the file you want to print.
3462
3463 Here are the forms of the @code{list} command most commonly used:
3464
3465 @table @code
3466 @item list @var{linenum}
3467 Print lines centered around line number @var{linenum} in the
3468 current source file.
3469
3470 @item list @var{function}
3471 Print lines centered around the beginning of function
3472 @var{function}.
3473
3474 @item list
3475 Print more lines. If the last lines printed were printed with a
3476 @code{list} command, this prints lines following the last lines
3477 printed; however, if the last line printed was a solitary line printed
3478 as part of displaying a stack frame (@pxref{Stack, ,Examining the
3479 Stack}), this prints lines centered around that line.
3480
3481 @item list -
3482 Print lines just before the lines last printed.
3483 @end table
3484
3485 By default, @value{GDBN} prints ten source lines with any of these forms of
3486 the @code{list} command. You can change this using @code{set listsize}:
3487
3488 @table @code
3489 @item set listsize @var{count}
3490 @kindex set listsize
3491 Make the @code{list} command display @var{count} source lines (unless
3492 the @code{list} argument explicitly specifies some other number).
3493
3494 @item show listsize
3495 @kindex show listsize
3496 Display the number of lines that @code{list} will currently display by
3497 default.
3498 @end table
3499
3500 Repeating a @code{list} command with @key{RET} discards the argument,
3501 so it is equivalent to typing just @code{list}. This is more useful
3502 than listing the same lines again. An exception is made for an
3503 argument of @samp{-}; that argument is preserved in repetition so that
3504 each repetition moves up in the source file.
3505
3506 @cindex linespec
3507 In general, the @code{list} command expects you to supply zero, one or two
3508 @dfn{linespecs}. Linespecs specify source lines; there are several ways
3509 of writing them but the effect is always to specify some source line.
3510 Here is a complete description of the possible arguments for @code{list}:
3511
3512 @table @code
3513 @item list @var{linespec}
3514 Print lines centered around the line specified by @var{linespec}.
3515
3516 @item list @var{first},@var{last}
3517 Print lines from @var{first} to @var{last}. Both arguments are
3518 linespecs.
3519
3520 @item list ,@var{last}
3521 Print lines ending with @var{last}.
3522
3523 @item list @var{first},
3524 Print lines starting with @var{first}.
3525
3526 @item list +
3527 Print lines just after the lines last printed.
3528
3529 @item list -
3530 Print lines just before the lines last printed.
3531
3532 @item list
3533 As described in the preceding table.
3534 @end table
3535
3536 Here are the ways of specifying a single source line---all the
3537 kinds of linespec.
3538
3539 @table @code
3540 @item @var{number}
3541 Specifies line @var{number} of the current source file.
3542 When a @code{list} command has two linespecs, this refers to
3543 the same source file as the first linespec.
3544
3545 @item +@var{offset}
3546 Specifies the line @var{offset} lines after the last line printed.
3547 When used as the second linespec in a @code{list} command that has
3548 two, this specifies the line @var{offset} lines down from the
3549 first linespec.
3550
3551 @item -@var{offset}
3552 Specifies the line @var{offset} lines before the last line printed.
3553
3554 @item @var{filename}:@var{number}
3555 Specifies line @var{number} in the source file @var{filename}.
3556
3557 @item @var{function}
3558 @c FIXME: "of the open-brace" is C-centric. When we add other langs...
3559 Specifies the line of the open-brace that begins the body of the
3560 function @var{function}.
3561
3562 @item @var{filename}:@var{function}
3563 Specifies the line of the open-brace that begins the body of the
3564 function @var{function} in the file @var{filename}. You only need the
3565 file name with a function name to avoid ambiguity when there are
3566 identically named functions in different source files.
3567
3568 @item *@var{address}
3569 Specifies the line containing the program address @var{address}.
3570 @var{address} may be any expression.
3571 @end table
3572
3573 @ifclear DOSHOST
3574 @node Search
3575 @section Searching source files
3576 @cindex searching
3577 @kindex reverse-search
3578
3579 There are two commands for searching through the current source file for a
3580 regular expression.
3581
3582 @table @code
3583 @item forward-search @var{regexp}
3584 @itemx search @var{regexp}
3585 @kindex search
3586 @kindex forward-search
3587 The command @samp{forward-search @var{regexp}} checks each line,
3588 starting with the one following the last line listed, for a match for
3589 @var{regexp}. It lists the line that is found. You can use
3590 synonym @samp{search @var{regexp}} or abbreviate the command name as
3591 @code{fo}.
3592
3593 @item reverse-search @var{regexp}
3594 The command @samp{reverse-search @var{regexp}} checks each line, starting
3595 with the one before the last line listed and going backward, for a match
3596 for @var{regexp}. It lists the line that is found. You can abbreviate
3597 this command as @code{rev}.
3598 @end table
3599 @end ifclear
3600
3601 @node Source Path
3602 @section Specifying source directories
3603
3604 @cindex source path
3605 @cindex directories for source files
3606 Executable programs sometimes do not record the directories of the source
3607 files from which they were compiled, just the names. Even when they do,
3608 the directories could be moved between the compilation and your debugging
3609 session. @value{GDBN} has a list of directories to search for source files;
3610 this is called the @dfn{source path}. Each time @value{GDBN} wants a source file,
3611 it tries all the directories in the list, in the order they are present
3612 in the list, until it finds a file with the desired name. Note that
3613 the executable search path is @emph{not} used for this purpose. Neither is
3614 the current working directory, unless it happens to be in the source
3615 path.
3616
3617 If @value{GDBN} cannot find a source file in the source path, and the object
3618 program records a directory, @value{GDBN} tries that directory too. If the
3619 source path is empty, and there is no record of the compilation
3620 directory, @value{GDBN} will, as a last resort, look in the current
3621 directory.
3622
3623 Whenever you reset or rearrange the source path, @value{GDBN} will clear out
3624 any information it has cached about where source files are found, where
3625 each line is in the file, etc.
3626
3627 @kindex directory
3628 When you start @value{GDBN}, its source path is empty.
3629 To add other directories, use the @code{directory} command.
3630
3631 @table @code
3632 @item directory @var{dirname} @dots{}
3633 Add directory @var{dirname} to the front of the source path. Several
3634 directory names may be given to this command, separated by @samp{:} or
3635 whitespace. You may specify a directory that is already in the source
3636 path; this moves it forward, so it will be searched sooner.
3637
3638 @kindex cdir
3639 @kindex cwd
3640 @kindex $cdir
3641 @kindex $cwd
3642 @cindex compilation directory
3643 @cindex current directory
3644 @cindex working directory
3645 @cindex directory, current
3646 @cindex directory, compilation
3647 You can use the string @samp{$cdir} to refer to the compilation
3648 directory (if one is recorded), and @samp{$cwd} to refer to the current
3649 working directory. @samp{$cwd} is not the same as @samp{.}---the former
3650 tracks the current working directory as it changes during your @value{GDBN}
3651 session, while the latter is immediately expanded to the current
3652 directory at the time you add an entry to the source path.
3653
3654 @item directory
3655 Reset the source path to empty again. This requires confirmation.
3656
3657 @c RET-repeat for @code{directory} is explicitly disabled, but since
3658 @c repeating it would be a no-op we do not say that. (thanks to RMS)
3659
3660 @item show directories
3661 @kindex show directories
3662 Print the source path: show which directories it contains.
3663 @end table
3664
3665 If your source path is cluttered with directories that are no longer of
3666 interest, @value{GDBN} may sometimes cause confusion by finding the wrong
3667 versions of source. You can correct the situation as follows:
3668
3669 @enumerate
3670 @item
3671 Use @code{directory} with no argument to reset the source path to empty.
3672
3673 @item
3674 Use @code{directory} with suitable arguments to reinstall the
3675 directories you want in the source path. You can add all the
3676 directories in one command.
3677 @end enumerate
3678
3679 @node Machine Code
3680 @section Source and machine code
3681
3682 You can use the command @code{info line} to map source lines to program
3683 addresses (and vice versa), and the command @code{disassemble} to display
3684 a range of addresses as machine instructions.
3685
3686 @table @code
3687 @item info line @var{linespec}
3688 @kindex info line
3689 Print the starting and ending addresses of the compiled code for
3690 source line @var{linespec}. You can specify source lines in any of
3691 the ways understood by the @code{list} command (@pxref{List, ,Printing
3692 source lines}).
3693 @end table
3694
3695 For example, we can use @code{info line} to discover the location of
3696 the object code for the first line of function
3697 @code{m4_changequote}:
3698
3699 @smallexample
3700 (@value{GDBP}) info line m4_changecom
3701 Line 895 of "builtin.c" starts at pc 0x634c and ends at 0x6350.
3702 @end smallexample
3703
3704 @noindent
3705 We can also inquire (using @code{*@var{addr}} as the form for
3706 @var{linespec}) what source line covers a particular address:
3707 @smallexample
3708 (@value{GDBP}) info line *0x63ff
3709 Line 926 of "builtin.c" starts at pc 0x63e4 and ends at 0x6404.
3710 @end smallexample
3711
3712 @cindex @code{$_} and @code{info line}
3713 After @code{info line}, the default address for the @code{x} command
3714 is changed to the starting address of the line, so that @samp{x/i} is
3715 sufficient to begin examining the machine code (@pxref{Memory,
3716 ,Examining memory}). Also, this address is saved as the value of the
3717 convenience variable @code{$_} (@pxref{Convenience Vars, ,Convenience
3718 variables}).
3719
3720 @table @code
3721 @kindex disassemble
3722 @item disassemble
3723 @cindex assembly instructions
3724 @cindex instructions, assembly
3725 @cindex machine instructions
3726 @cindex listing machine instructions
3727 This specialized command dumps a range of memory as machine
3728 instructions. The default memory range is the function surrounding the
3729 program counter of the selected frame. A single argument to this
3730 command is a program counter value; the function surrounding this value
3731 will be dumped. Two arguments specify a range of addresses (first
3732 inclusive, second exclusive) to dump.
3733 @end table
3734
3735 @ifclear H8EXCLUSIVE
3736 We can use @code{disassemble} to inspect the object code
3737 range shown in the last @code{info line} example (the example
3738 shows SPARC machine instructions):
3739
3740
3741 @smallexample
3742 (@value{GDBP}) disas 0x63e4 0x6404
3743 Dump of assembler code from 0x63e4 to 0x6404:
3744 0x63e4 <builtin_init+5340>: ble 0x63f8 <builtin_init+5360>
3745 0x63e8 <builtin_init+5344>: sethi %hi(0x4c00), %o0
3746 0x63ec <builtin_init+5348>: ld [%i1+4], %o0
3747 0x63f0 <builtin_init+5352>: b 0x63fc <builtin_init+5364>
3748 0x63f4 <builtin_init+5356>: ld [%o0+4], %o0
3749 0x63f8 <builtin_init+5360>: or %o0, 0x1a4, %o0
3750 0x63fc <builtin_init+5364>: call 0x9288 <path_search>
3751 0x6400 <builtin_init+5368>: nop
3752 End of assembler dump.
3753 @end smallexample
3754 @end ifclear
3755
3756 @ifset H8EXCLUSIVE
3757 For example, here is the beginning of the output for the
3758 disassembly of a function @code{fact}:
3759
3760
3761 @smallexample
3762 (@value{GDBP}) disas fact
3763 Dump of assembler code for function fact:
3764 to 0x808c:
3765 0x802c <fact>: 6d f2 mov.w r2,@@-r7
3766 0x802e <fact+2>: 6d f3 mov.w r3,@@-r7
3767 0x8030 <fact+4>: 6d f6 mov.w r6,@@-r7
3768 0x8032 <fact+6>: 0d 76 mov.w r7,r6
3769 0x8034 <fact+8>: 6f 70 00 08 mov.w @@(0x8,r7),r0
3770 0x8038 <fact+12> 19 11 sub.w r1,r1
3771 .
3772 .
3773 .
3774 @end smallexample
3775 @end ifset
3776
3777 @node Data
3778 @chapter Examining Data
3779
3780 @cindex printing data
3781 @cindex examining data
3782 @kindex print
3783 @kindex inspect
3784 @c "inspect" is not quite a synonym if you are using Epoch, which we do not
3785 @c document because it is nonstandard... Under Epoch it displays in a
3786 @c different window or something like that.
3787 The usual way to examine data in your program is with the @code{print}
3788 command (abbreviated @code{p}), or its synonym @code{inspect}.
3789 @ifclear CONLY
3790 It evaluates and prints the value of an expression of the language your
3791 program is written in (@pxref{Languages, ,Using @value{GDBN} with Different
3792 Languages}).
3793 @end ifclear
3794
3795 @table @code
3796 @item print @var{exp}
3797 @itemx print /@var{f} @var{exp}
3798 @var{exp} is an expression (in the source language). By default the
3799 value of @var{exp} is printed in a format appropriate to its data type;
3800 you can choose a different format by specifying @samp{/@var{f}}, where
3801 @var{f} is a letter specifying the format; @pxref{Output Formats,,Output
3802 formats}.
3803
3804 @item print
3805 @itemx print /@var{f}
3806 If you omit @var{exp}, @value{GDBN} displays the last value again (from the
3807 @dfn{value history}; @pxref{Value History, ,Value history}). This allows you to
3808 conveniently inspect the same value in an alternative format.
3809 @end table
3810
3811 A more low-level way of examining data is with the @code{x} command.
3812 It examines data in memory at a specified address and prints it in a
3813 specified format. @xref{Memory, ,Examining memory}.
3814
3815 If you are interested in information about types, or about how the fields
3816 of a struct
3817 @ifclear CONLY
3818 or class
3819 @end ifclear
3820 are declared, use the @code{ptype @var{exp}}
3821 command rather than @code{print}. @xref{Symbols, ,Examining the Symbol Table}.
3822
3823 @menu
3824 * Expressions:: Expressions
3825 * Variables:: Program variables
3826 * Arrays:: Artificial arrays
3827 * Output Formats:: Output formats
3828 * Memory:: Examining memory
3829 * Auto Display:: Automatic display
3830 * Print Settings:: Print settings
3831 * Value History:: Value history
3832 * Convenience Vars:: Convenience variables
3833 * Registers:: Registers
3834 @ifclear HAVE-FLOAT
3835 * Floating Point Hardware:: Floating point hardware
3836 @end ifclear
3837 @end menu
3838
3839 @node Expressions
3840 @section Expressions
3841
3842 @cindex expressions
3843 @code{print} and many other @value{GDBN} commands accept an expression and
3844 compute its value. Any kind of constant, variable or operator defined
3845 by the programming language you are using is valid in an expression in
3846 @value{GDBN}. This includes conditional expressions, function calls, casts
3847 and string constants. It unfortunately does not include symbols defined
3848 by preprocessor @code{#define} commands.
3849
3850 @ifclear CONLY
3851 Because C is so widespread, most of the expressions shown in examples in
3852 this manual are in C. @xref{Languages, , Using @value{GDBN} with Different
3853 Languages}, for information on how to use expressions in other
3854 languages.
3855
3856 In this section, we discuss operators that you can use in @value{GDBN}
3857 expressions regardless of your programming language.
3858
3859 Casts are supported in all languages, not just in C, because it is so
3860 useful to cast a number into a pointer so as to examine a structure
3861 at that address in memory.
3862 @c FIXME: casts supported---Mod2 true?
3863 @end ifclear
3864
3865 @value{GDBN} supports these operators in addition to those of programming
3866 languages:
3867
3868 @table @code
3869 @item @@
3870 @samp{@@} is a binary operator for treating parts of memory as arrays.
3871 @xref{Arrays, ,Artificial arrays}, for more information.
3872
3873 @item ::
3874 @samp{::} allows you to specify a variable in terms of the file or
3875 function where it is defined. @xref{Variables, ,Program variables}.
3876
3877 @item @{@var{type}@} @var{addr}
3878 @cindex @{@var{type}@}
3879 @cindex type casting memory
3880 @cindex memory, viewing as typed object
3881 @cindex casts, to view memory
3882 Refers to an object of type @var{type} stored at address @var{addr} in
3883 memory. @var{addr} may be any expression whose value is an integer or
3884 pointer (but parentheses are required around binary operators, just as in
3885 a cast). This construct is allowed regardless of what kind of data is
3886 normally supposed to reside at @var{addr}.
3887 @end table
3888
3889 @node Variables
3890 @section Program variables
3891
3892 The most common kind of expression to use is the name of a variable
3893 in your program.
3894
3895 Variables in expressions are understood in the selected stack frame
3896 (@pxref{Selection, ,Selecting a frame}); they must either be global
3897 (or static) or be visible according to the scope rules of the
3898 programming language from the point of execution in that frame. This
3899 means that in the function
3900
3901 @example
3902 foo (a)
3903 int a;
3904 @{
3905 bar (a);
3906 @{
3907 int b = test ();
3908 bar (b);
3909 @}
3910 @}
3911 @end example
3912
3913 @noindent
3914 you can examine and use the variable @code{a} whenever your program is
3915 executing within the function @code{foo}, but you can only use or
3916 examine the variable @code{b} while your program is executing inside
3917 the block where @code{b} is declared.
3918
3919 @cindex variable name conflict
3920 There is an exception: you can refer to a variable or function whose
3921 scope is a single source file even if the current execution point is not
3922 in this file. But it is possible to have more than one such variable or
3923 function with the same name (in different source files). If that
3924 happens, referring to that name has unpredictable effects. If you wish,
3925 you can specify a static variable in a particular function or file,
3926 using the colon-colon notation:
3927
3928 @cindex colon-colon
3929 @iftex
3930 @c info cannot cope with a :: index entry, but why deprive hard copy readers?
3931 @kindex ::
3932 @end iftex
3933 @example
3934 @var{file}::@var{variable}
3935 @var{function}::@var{variable}
3936 @end example
3937
3938 @noindent
3939 Here @var{file} or @var{function} is the name of the context for the
3940 static @var{variable}. In the case of file names, you can use quotes to
3941 make sure @value{GDBN} parses the file name as a single word---for example,
3942 to print a global value of @code{x} defined in @file{f2.c}:
3943
3944 @example
3945 (@value{GDBP}) p 'f2.c'::x
3946 @end example
3947
3948 @ifclear CONLY
3949 @cindex C++ scope resolution
3950 This use of @samp{::} is very rarely in conflict with the very similar
3951 use of the same notation in C++. @value{GDBN} also supports use of the C++
3952 scope resolution operator in @value{GDBN} expressions.
3953 @c FIXME: Um, so what happens in one of those rare cases where it's in
3954 @c conflict?? --mew
3955 @end ifclear
3956
3957 @cindex wrong values
3958 @cindex variable values, wrong
3959 @quotation
3960 @emph{Warning:} Occasionally, a local variable may appear to have the
3961 wrong value at certain points in a function---just after entry to a new
3962 scope, and just before exit.
3963 @end quotation
3964 You may see this problem when you are stepping by machine instructions.
3965 This is because on most machines, it takes more than one instruction to
3966 set up a stack frame (including local variable definitions); if you are
3967 stepping by machine instructions, variables may appear to have the wrong
3968 values until the stack frame is completely built. On exit, it usually
3969 also takes more than one machine instruction to destroy a stack frame;
3970 after you begin stepping through that group of instructions, local
3971 variable definitions may be gone.
3972
3973 @node Arrays
3974 @section Artificial arrays
3975
3976 @cindex artificial array
3977 @kindex @@
3978 It is often useful to print out several successive objects of the
3979 same type in memory; a section of an array, or an array of
3980 dynamically determined size for which only a pointer exists in the
3981 program.
3982
3983 You can do this by referring to a contiguous span of memory as an
3984 @dfn{artificial array}, using the binary operator @samp{@@}. The left
3985 operand of @samp{@@} should be the first element of the desired array,
3986 as an individual object. The right operand should be the desired length
3987 of the array. The result is an array value whose elements are all of
3988 the type of the left argument. The first element is actually the left
3989 argument; the second element comes from bytes of memory immediately
3990 following those that hold the first element, and so on. Here is an
3991 example. If a program says
3992
3993 @example
3994 int *array = (int *) malloc (len * sizeof (int));
3995 @end example
3996
3997 @noindent
3998 you can print the contents of @code{array} with
3999
4000 @example
4001 p *array@@len
4002 @end example
4003
4004 The left operand of @samp{@@} must reside in memory. Array values made
4005 with @samp{@@} in this way behave just like other arrays in terms of
4006 subscripting, and are coerced to pointers when used in expressions.
4007 Artificial arrays most often appear in expressions via the value history
4008 (@pxref{Value History, ,Value history}), after printing one out.
4009
4010 Sometimes the artificial array mechanism is not quite enough; in
4011 moderately complex data structures, the elements of interest may not
4012 actually be adjacent---for example, if you are interested in the values
4013 of pointers in an array. One useful work-around in this situation is
4014 to use a convenience variable (@pxref{Convenience Vars, ,Convenience
4015 variables}) as a counter in an expression that prints the first
4016 interesting value, and then repeat that expression via @key{RET}. For
4017 instance, suppose you have an array @code{dtab} of pointers to
4018 structures, and you are interested in the values of a field @code{fv}
4019 in each structure. Here is an example of what you might type:
4020
4021 @example
4022 set $i = 0
4023 p dtab[$i++]->fv
4024 @key{RET}
4025 @key{RET}
4026 @dots{}
4027 @end example
4028
4029 @node Output Formats
4030 @section Output formats
4031
4032 @cindex formatted output
4033 @cindex output formats
4034 By default, @value{GDBN} prints a value according to its data type. Sometimes
4035 this is not what you want. For example, you might want to print a number
4036 in hex, or a pointer in decimal. Or you might want to view data in memory
4037 at a certain address as a character string or as an instruction. To do
4038 these things, specify an @dfn{output format} when you print a value.
4039
4040 The simplest use of output formats is to say how to print a value
4041 already computed. This is done by starting the arguments of the
4042 @code{print} command with a slash and a format letter. The format
4043 letters supported are:
4044
4045 @table @code
4046 @item x
4047 Regard the bits of the value as an integer, and print the integer in
4048 hexadecimal.
4049
4050 @item d
4051 Print as integer in signed decimal.
4052
4053 @item u
4054 Print as integer in unsigned decimal.
4055
4056 @item o
4057 Print as integer in octal.
4058
4059 @item t
4060 Print as integer in binary. The letter @samp{t} stands for ``two''.
4061 @footnote{@samp{b} cannot be used because these format letters are also
4062 used with the @code{x} command, where @samp{b} stands for ``byte'';
4063 @pxref{Memory,,Examining memory}.}
4064
4065 @item a
4066 Print as an address, both absolute in hex and as an offset from the
4067 nearest preceding symbol. This format can be used to discover where (in
4068 what function) an unknown address is located:
4069
4070 @example
4071 (@value{GDBP}) p/a 0x54320
4072 $3 = 0x54320 <_initialize_vx+396>
4073 @end example
4074
4075 @item c
4076 Regard as an integer and print it as a character constant.
4077
4078 @item f
4079 Regard the bits of the value as a floating point number and print
4080 using typical floating point syntax.
4081 @end table
4082
4083 For example, to print the program counter in hex (@pxref{Registers}), type
4084
4085 @example
4086 p/x $pc
4087 @end example
4088
4089 @noindent
4090 Note that no space is required before the slash; this is because command
4091 names in @value{GDBN} cannot contain a slash.
4092
4093 To reprint the last value in the value history with a different format,
4094 you can use the @code{print} command with just a format and no
4095 expression. For example, @samp{p/x} reprints the last value in hex.
4096
4097 @node Memory
4098 @section Examining memory
4099
4100 You can use the command @code{x} (for ``examine'') to examine memory in
4101 any of several formats, independently of your program's data types.
4102
4103 @cindex examining memory
4104 @table @code
4105 @kindex x
4106 @item x/@var{nfu} @var{addr}
4107 @itemx x @var{addr}
4108 @itemx x
4109 Use the @code{x} command to examine memory.
4110 @end table
4111
4112 @var{n}, @var{f}, and @var{u} are all optional parameters that specify how
4113 much memory to display and how to format it; @var{addr} is an
4114 expression giving the address where you want to start displaying memory.
4115 If you use defaults for @var{nfu}, you need not type the slash @samp{/}.
4116 Several commands set convenient defaults for @var{addr}.
4117
4118 @table @r
4119 @item @var{n}, the repeat count
4120 The repeat count is a decimal integer; the default is 1. It specifies
4121 how much memory (counting by units @var{u}) to display.
4122 @c This really is **decimal**; unaffected by 'set radix' as of GDB
4123 @c 4.1.2.
4124
4125 @item @var{f}, the display format
4126 The display format is one of the formats used by @code{print},
4127 or @samp{s} (null-terminated string) or @samp{i} (machine instruction).
4128 The default is @samp{x} (hexadecimal) initially, or the format from the
4129 last time you used either @code{x} or @code{print}.
4130
4131 @item @var{u}, the unit size
4132 The unit size is any of
4133
4134 @table @code
4135 @item b
4136 Bytes.
4137 @item h
4138 Halfwords (two bytes).
4139 @item w
4140 Words (four bytes). This is the initial default.
4141 @item g
4142 Giant words (eight bytes).
4143 @end table
4144
4145 Each time you specify a unit size with @code{x}, that size becomes the
4146 default unit the next time you use @code{x}. (For the @samp{s} and
4147 @samp{i} formats, the unit size is ignored and is normally not written.)
4148
4149 @item @var{addr}, starting display address
4150 @var{addr} is the address where you want @value{GDBN} to begin displaying
4151 memory. The expression need not have a pointer value (though it may);
4152 it is always interpreted as an integer address of a byte of memory.
4153 @xref{Expressions, ,Expressions}, for more information on expressions. The default for
4154 @var{addr} is usually just after the last address examined---but several
4155 other commands also set the default address: @code{info breakpoints} (to
4156 the address of the last breakpoint listed), @code{info line} (to the
4157 starting address of a line), and @code{print} (if you use it to display
4158 a value from memory).
4159 @end table
4160
4161 For example, @samp{x/3uh 0x54320} is a request to display three halfwords
4162 (@code{h}) of memory, formatted as unsigned decimal integers (@samp{u}),
4163 starting at address @code{0x54320}. @samp{x/4xw $sp} prints the four
4164 words (@samp{w}) of memory above the stack pointer (here, @samp{$sp};
4165 @pxref{Registers}) in hexadecimal (@samp{x}).
4166
4167 Since the letters indicating unit sizes are all distinct from the
4168 letters specifying output formats, you do not have to remember whether
4169 unit size or format comes first; either order will work. The output
4170 specifications @samp{4xw} and @samp{4wx} mean exactly the same thing.
4171 (However, the count @var{n} must come first; @samp{wx4} will not work.)
4172
4173 Even though the unit size @var{u} is ignored for the formats @samp{s}
4174 and @samp{i}, you might still want to use a count @var{n}; for example,
4175 @samp{3i} specifies that you want to see three machine instructions,
4176 including any operands. The command @code{disassemble} gives an
4177 alternative way of inspecting machine instructions; @pxref{Machine
4178 Code,,Source and machine code}.
4179
4180 All the defaults for the arguments to @code{x} are designed to make it
4181 easy to continue scanning memory with minimal specifications each time
4182 you use @code{x}. For example, after you have inspected three machine
4183 instructions with @samp{x/3i @var{addr}}, you can inspect the next seven
4184 with just @samp{x/7}. If you use @key{RET} to repeat the @code{x} command,
4185 the repeat count @var{n} is used again; the other arguments default as
4186 for successive uses of @code{x}.
4187
4188 @cindex @code{$_}, @code{$__}, and value history
4189 The addresses and contents printed by the @code{x} command are not saved
4190 in the value history because there is often too much of them and they
4191 would get in the way. Instead, @value{GDBN} makes these values available for
4192 subsequent use in expressions as values of the convenience variables
4193 @code{$_} and @code{$__}. After an @code{x} command, the last address
4194 examined is available for use in expressions in the convenience variable
4195 @code{$_}. The contents of that address, as examined, are available in
4196 the convenience variable @code{$__}.
4197
4198 If the @code{x} command has a repeat count, the address and contents saved
4199 are from the last memory unit printed; this is not the same as the last
4200 address printed if several units were printed on the last line of output.
4201
4202 @node Auto Display
4203 @section Automatic display
4204 @cindex automatic display
4205 @cindex display of expressions
4206
4207 If you find that you want to print the value of an expression frequently
4208 (to see how it changes), you might want to add it to the @dfn{automatic
4209 display list} so that @value{GDBN} will print its value each time your program stops.
4210 Each expression added to the list is given a number to identify it;
4211 to remove an expression from the list, you specify that number.
4212 The automatic display looks like this:
4213
4214 @example
4215 2: foo = 38
4216 3: bar[5] = (struct hack *) 0x3804
4217 @end example
4218
4219 @noindent
4220 This display shows item numbers, expressions and their current values. As with
4221 displays you request manually using @code{x} or @code{print}, you can
4222 specify the output format you prefer; in fact, @code{display} decides
4223 whether to use @code{print} or @code{x} depending on how elaborate your
4224 format specification is---it uses @code{x} if you specify a unit size,
4225 or one of the two formats (@samp{i} and @samp{s}) that are only
4226 supported by @code{x}; otherwise it uses @code{print}.
4227
4228 @table @code
4229 @item display @var{exp}
4230 @kindex display
4231 Add the expression @var{exp} to the list of expressions to display
4232 each time your program stops. @xref{Expressions, ,Expressions}.
4233
4234 @code{display} will not repeat if you press @key{RET} again after using it.
4235
4236 @item display/@var{fmt} @var{exp}
4237 For @var{fmt} specifying only a display format and not a size or
4238 count, add the expression @var{exp} to the auto-display list but
4239 arrange to display it each time in the specified format @var{fmt}.
4240 @xref{Output Formats,,Output formats}.
4241
4242 @item display/@var{fmt} @var{addr}
4243 For @var{fmt} @samp{i} or @samp{s}, or including a unit-size or a
4244 number of units, add the expression @var{addr} as a memory address to
4245 be examined each time your program stops. Examining means in effect
4246 doing @samp{x/@var{fmt} @var{addr}}. @xref{Memory, ,Examining memory}.
4247 @end table
4248
4249 For example, @samp{display/i $pc} can be helpful, to see the machine
4250 instruction about to be executed each time execution stops (@samp{$pc}
4251 is a common name for the program counter; @pxref{Registers}).
4252
4253 @table @code
4254 @item undisplay @var{dnums}@dots{}
4255 @itemx delete display @var{dnums}@dots{}
4256 @kindex delete display
4257 @kindex undisplay
4258 Remove item numbers @var{dnums} from the list of expressions to display.
4259
4260 @code{undisplay} will not repeat if you press @key{RET} after using it.
4261 (Otherwise you would just get the error @samp{No display number @dots{}}.)
4262
4263 @item disable display @var{dnums}@dots{}
4264 @kindex disable display
4265 Disable the display of item numbers @var{dnums}. A disabled display
4266 item is not printed automatically, but is not forgotten. It may be
4267 enabled again later.
4268
4269 @item enable display @var{dnums}@dots{}
4270 @kindex enable display
4271 Enable display of item numbers @var{dnums}. It becomes effective once
4272 again in auto display of its expression, until you specify otherwise.
4273
4274 @item display
4275 Display the current values of the expressions on the list, just as is
4276 done when your program stops.
4277
4278 @item info display
4279 @kindex info display
4280 Print the list of expressions previously set up to display
4281 automatically, each one with its item number, but without showing the
4282 values. This includes disabled expressions, which are marked as such.
4283 It also includes expressions which would not be displayed right now
4284 because they refer to automatic variables not currently available.
4285 @end table
4286
4287 If a display expression refers to local variables, then it does not make
4288 sense outside the lexical context for which it was set up. Such an
4289 expression is disabled when execution enters a context where one of its
4290 variables is not defined. For example, if you give the command
4291 @code{display last_char} while inside a function with an argument
4292 @code{last_char}, then this argument will be displayed while your program
4293 continues to stop inside that function. When it stops elsewhere---where
4294 there is no variable @code{last_char}---display is disabled. The next time
4295 your program stops where @code{last_char} is meaningful, you can enable the
4296 display expression once again.
4297
4298 @node Print Settings
4299 @section Print settings
4300
4301 @cindex format options
4302 @cindex print settings
4303 @value{GDBN} provides the following ways to control how arrays, structures,
4304 and symbols are printed.
4305
4306 @noindent
4307 These settings are useful for debugging programs in any language:
4308
4309 @table @code
4310 @item set print address
4311 @itemx set print address on
4312 @kindex set print address
4313 @value{GDBN} will print memory addresses showing the location of stack
4314 traces, structure values, pointer values, breakpoints, and so forth,
4315 even when it also displays the contents of those addresses. The default
4316 is on. For example, this is what a stack frame display looks like, with
4317 @code{set print address on}:
4318
4319 @smallexample
4320 @group
4321 (@value{GDBP}) f
4322 #0 set_quotes (lq=0x34c78 "<<", rq=0x34c88 ">>")
4323 at input.c:530
4324 530 if (lquote != def_lquote)
4325 @end group
4326 @end smallexample
4327
4328 @item set print address off
4329 Do not print addresses when displaying their contents. For example,
4330 this is the same stack frame displayed with @code{set print address off}:
4331
4332 @smallexample
4333 @group
4334 (@value{GDBP}) set print addr off
4335 (@value{GDBP}) f
4336 #0 set_quotes (lq="<<", rq=">>") at input.c:530
4337 530 if (lquote != def_lquote)
4338 @end group
4339 @end smallexample
4340
4341 You can use @samp{set print address off} to eliminate all machine
4342 dependent displays from the @value{GDBN} interface. For example, with
4343 @code{print address off}, you should get the same text for backtraces on
4344 all machines---whether or not they involve pointer arguments.
4345
4346 @item show print address
4347 @kindex show print address
4348 Show whether or not addresses are to be printed.
4349 @end table
4350
4351 When @value{GDBN} prints a symbolic address, it normally prints the
4352 closest earlier symbol plus an offset. If that symbol does not uniquely
4353 identify the address (for example, it is a name whose scope is a single
4354 source file), you may need to disambiguate. One way to do this is with
4355 @code{info line}, for example @code{info line *0x4537}. Alternately,
4356 you can set @value{GDBN} to print the source file and line number when
4357 it prints a symbolic address:
4358
4359 @table @code
4360 @item set print symbol-filename on
4361 @kindex set print symbol-filename
4362 Tell @value{GDBN} to print the source file name and line number of a
4363 symbol in the symbolic form of an address.
4364
4365 @item set print symbol-filename off
4366 Do not print source file name and line number of a symbol. This is the
4367 default.
4368
4369 @item show print symbol-filename
4370 @kindex show print symbol-filename
4371 Show whether or not @value{GDBN} will print the source file name and
4372 line number of a symbol in the symbolic form of an address.
4373 @end table
4374
4375 Also, you may wish to see the symbolic form only if the address being
4376 printed is reasonably close to the closest earlier symbol:
4377
4378 @table @code
4379 @item set print max-symbolic-offset @var{max-offset}
4380 @kindex set print max-symbolic-offset
4381 Tell @value{GDBN} to only display the symbolic form of an address if the
4382 offset between the closest earlier symbol and the address is less than
4383 @var{max-offset}. The default is 0, which means to always print the
4384 symbolic form of an address, if any symbol precedes it.
4385
4386 @item show print max-symbolic-offset
4387 @kindex show print max-symbolic-offset
4388 Ask how large the maximum offset is that @value{GDBN} will print in a
4389 symbolic address.
4390 @end table
4391
4392 @table @code
4393 @item set print array
4394 @itemx set print array on
4395 @kindex set print array
4396 @value{GDBN} will pretty-print arrays. This format is more convenient to read,
4397 but uses more space. The default is off.
4398
4399 @item set print array off
4400 Return to compressed format for arrays.
4401
4402 @item show print array
4403 @kindex show print array
4404 Show whether compressed or pretty format is selected for displaying
4405 arrays.
4406
4407 @item set print elements @var{number-of-elements}
4408 @kindex set print elements
4409 If @value{GDBN} is printing a large array, it will stop printing after it has
4410 printed the number of elements set by the @code{set print elements} command.
4411 This limit also applies to the display of strings.
4412 Setting the number of elements to zero means that the printing is unlimited.
4413
4414 @item show print elements
4415 @kindex show print elements
4416 Display the number of elements of a large array that @value{GDBN} will print
4417 before losing patience.
4418
4419 @item set print pretty on
4420 @kindex set print pretty
4421 Cause @value{GDBN} to print structures in an indented format with one member per
4422 line, like this:
4423
4424 @smallexample
4425 @group
4426 $1 = @{
4427 next = 0x0,
4428 flags = @{
4429 sweet = 1,
4430 sour = 1
4431 @},
4432 meat = 0x54 "Pork"
4433 @}
4434 @end group
4435 @end smallexample
4436
4437 @item set print pretty off
4438 Cause @value{GDBN} to print structures in a compact format, like this:
4439
4440 @smallexample
4441 @group
4442 $1 = @{next = 0x0, flags = @{sweet = 1, sour = 1@}, \
4443 meat = 0x54 "Pork"@}
4444 @end group
4445 @end smallexample
4446
4447 @noindent
4448 This is the default format.
4449
4450 @item show print pretty
4451 @kindex show print pretty
4452 Show which format @value{GDBN} will use to print structures.
4453
4454 @item set print sevenbit-strings on
4455 @kindex set print sevenbit-strings
4456 Print using only seven-bit characters; if this option is set,
4457 @value{GDBN} will display any eight-bit characters (in strings or character
4458 values) using the notation @code{\}@var{nnn}. For example, @kbd{M-a} is
4459 displayed as @code{\341}.
4460
4461 @item set print sevenbit-strings off
4462 Print using either seven-bit or eight-bit characters, as required. This
4463 is the default.
4464
4465 @item show print sevenbit-strings
4466 @kindex show print sevenbit-strings
4467 Show whether or not @value{GDBN} will print only seven-bit characters.
4468
4469 @item set print union on
4470 @kindex set print union
4471 Tell @value{GDBN} to print unions which are contained in structures. This is the
4472 default setting.
4473
4474 @item set print union off
4475 Tell @value{GDBN} not to print unions which are contained in structures.
4476
4477 @item show print union
4478 @kindex show print union
4479 Ask @value{GDBN} whether or not it will print unions which are contained in
4480 structures.
4481
4482 For example, given the declarations
4483
4484 @smallexample
4485 typedef enum @{Tree, Bug@} Species;
4486 typedef enum @{Big_tree, Acorn, Seedling@} Tree_forms;
4487 typedef enum @{Caterpillar, Cocoon, Butterfly@}
4488 Bug_forms;
4489
4490 struct thing @{
4491 Species it;
4492 union @{
4493 Tree_forms tree;
4494 Bug_forms bug;
4495 @} form;
4496 @};
4497
4498 struct thing foo = @{Tree, @{Acorn@}@};
4499 @end smallexample
4500
4501 @noindent
4502 with @code{set print union on} in effect @samp{p foo} would print
4503
4504 @smallexample
4505 $1 = @{it = Tree, form = @{tree = Acorn, bug = Cocoon@}@}
4506 @end smallexample
4507
4508 @noindent
4509 and with @code{set print union off} in effect it would print
4510
4511 @smallexample
4512 $1 = @{it = Tree, form = @{...@}@}
4513 @end smallexample
4514 @end table
4515
4516 @ifclear CONLY
4517 @need 1000
4518 @noindent
4519 These settings are of interest when debugging C++ programs:
4520
4521 @table @code
4522 @item set print demangle
4523 @itemx set print demangle on
4524 @kindex set print demangle
4525 Print C++ names in their source form rather than in the encoded
4526 (``mangled'') form passed to the assembler and linker for type-safe
4527 linkage. The default is @samp{on}.
4528
4529 @item show print demangle
4530 @kindex show print demangle
4531 Show whether C++ names will be printed in mangled or demangled form.
4532
4533 @item set print asm-demangle
4534 @itemx set print asm-demangle on
4535 @kindex set print asm-demangle
4536 Print C++ names in their source form rather than their mangled form, even
4537 in assembler code printouts such as instruction disassemblies.
4538 The default is off.
4539
4540 @item show print asm-demangle
4541 @kindex show print asm-demangle
4542 Show whether C++ names in assembly listings will be printed in mangled
4543 or demangled form.
4544
4545 @item set demangle-style @var{style}
4546 @kindex set demangle-style
4547 @cindex C++ symbol decoding style
4548 @cindex symbol decoding style, C++
4549 Choose among several encoding schemes used by different compilers to
4550 represent C++ names. The choices for @var{style} are currently:
4551
4552 @table @code
4553 @item auto
4554 Allow @value{GDBN} to choose a decoding style by inspecting your program.
4555
4556 @item gnu
4557 Decode based on the GNU C++ compiler (@code{g++}) encoding algorithm.
4558
4559 @item lucid
4560 Decode based on the Lucid C++ compiler (@code{lcc}) encoding algorithm.
4561
4562 @item arm
4563 Decode using the algorithm in the @cite{C++ Annotated Reference Manual}.
4564 @strong{Warning:} this setting alone is not sufficient to allow
4565 debugging @code{cfront}-generated executables. @value{GDBN} would
4566 require further enhancement to permit that.
4567 @end table
4568
4569 @item show demangle-style
4570 @kindex show demangle-style
4571 Display the encoding style currently in use for decoding C++ symbols.
4572
4573 @item set print object
4574 @itemx set print object on
4575 @kindex set print object
4576 When displaying a pointer to an object, identify the @emph{actual}
4577 (derived) type of the object rather than the @emph{declared} type, using
4578 the virtual function table.
4579
4580 @item set print object off
4581 Display only the declared type of objects, without reference to the
4582 virtual function table. This is the default setting.
4583
4584 @item show print object
4585 @kindex show print object
4586 Show whether actual, or declared, object types will be displayed.
4587
4588 @item set print vtbl
4589 @itemx set print vtbl on
4590 @kindex set print vtbl
4591 Pretty print C++ virtual function tables. The default is off.
4592
4593 @item set print vtbl off
4594 Do not pretty print C++ virtual function tables.
4595
4596 @item show print vtbl
4597 @kindex show print vtbl
4598 Show whether C++ virtual function tables are pretty printed, or not.
4599 @end table
4600 @end ifclear
4601
4602 @node Value History
4603 @section Value history
4604
4605 @cindex value history
4606 Values printed by the @code{print} command are saved in the @value{GDBN} @dfn{value
4607 history} so that you can refer to them in other expressions. Values are
4608 kept until the symbol table is re-read or discarded (for example with
4609 the @code{file} or @code{symbol-file} commands). When the symbol table
4610 changes, the value history is discarded, since the values may contain
4611 pointers back to the types defined in the symbol table.
4612
4613 @cindex @code{$}
4614 @cindex @code{$$}
4615 @cindex history number
4616 The values printed are given @dfn{history numbers} by which you can
4617 refer to them. These are successive integers starting with one.
4618 @code{print} shows you the history number assigned to a value by
4619 printing @samp{$@var{num} = } before the value; here @var{num} is the
4620 history number.
4621
4622 To refer to any previous value, use @samp{$} followed by the value's
4623 history number. The way @code{print} labels its output is designed to
4624 remind you of this. Just @code{$} refers to the most recent value in
4625 the history, and @code{$$} refers to the value before that.
4626 @code{$$@var{n}} refers to the @var{n}th value from the end; @code{$$2}
4627 is the value just prior to @code{$$}, @code{$$1} is equivalent to
4628 @code{$$}, and @code{$$0} is equivalent to @code{$}.
4629
4630 For example, suppose you have just printed a pointer to a structure and
4631 want to see the contents of the structure. It suffices to type
4632
4633 @example
4634 p *$
4635 @end example
4636
4637 If you have a chain of structures where the component @code{next} points
4638 to the next one, you can print the contents of the next one with this:
4639
4640 @example
4641 p *$.next
4642 @end example
4643
4644 @noindent
4645 You can print successive links in the chain by repeating this
4646 command---which you can do by just typing @key{RET}.
4647
4648 Note that the history records values, not expressions. If the value of
4649 @code{x} is 4 and you type these commands:
4650
4651 @example
4652 print x
4653 set x=5
4654 @end example
4655
4656 @noindent
4657 then the value recorded in the value history by the @code{print} command
4658 remains 4 even though the value of @code{x} has changed.
4659
4660 @table @code
4661 @kindex show values
4662 @item show values
4663 Print the last ten values in the value history, with their item numbers.
4664 This is like @samp{p@ $$9} repeated ten times, except that @code{show
4665 values} does not change the history.
4666
4667 @item show values @var{n}
4668 Print ten history values centered on history item number @var{n}.
4669
4670 @item show values +
4671 Print ten history values just after the values last printed. If no more
4672 values are available, produces no display.
4673 @end table
4674
4675 Pressing @key{RET} to repeat @code{show values @var{n}} has exactly the
4676 same effect as @samp{show values +}.
4677
4678 @node Convenience Vars
4679 @section Convenience variables
4680
4681 @cindex convenience variables
4682 @value{GDBN} provides @dfn{convenience variables} that you can use within
4683 @value{GDBN} to hold on to a value and refer to it later. These variables
4684 exist entirely within @value{GDBN}; they are not part of your program, and
4685 setting a convenience variable has no direct effect on further execution
4686 of your program. That is why you can use them freely.
4687
4688 Convenience variables are prefixed with @samp{$}. Any name preceded by
4689 @samp{$} can be used for a convenience variable, unless it is one of
4690 the predefined machine-specific register names (@pxref{Registers}).
4691 (Value history references, in contrast, are @emph{numbers} preceded
4692 by @samp{$}. @xref{Value History, ,Value history}.)
4693
4694 You can save a value in a convenience variable with an assignment
4695 expression, just as you would set a variable in your program.
4696 For example:
4697
4698 @example
4699 set $foo = *object_ptr
4700 @end example
4701
4702 @noindent
4703 would save in @code{$foo} the value contained in the object pointed to by
4704 @code{object_ptr}.
4705
4706 Using a convenience variable for the first time creates it, but its
4707 value is @code{void} until you assign a new value. You can alter the
4708 value with another assignment at any time.
4709
4710 Convenience variables have no fixed types. You can assign a convenience
4711 variable any type of value, including structures and arrays, even if
4712 that variable already has a value of a different type. The convenience
4713 variable, when used as an expression, has the type of its current value.
4714
4715 @table @code
4716 @item show convenience
4717 @kindex show convenience
4718 Print a list of convenience variables used so far, and their values.
4719 Abbreviated @code{show con}.
4720 @end table
4721
4722 One of the ways to use a convenience variable is as a counter to be
4723 incremented or a pointer to be advanced. For example, to print
4724 a field from successive elements of an array of structures:
4725
4726 @example
4727 set $i = 0
4728 print bar[$i++]->contents
4729 @i{@dots{} repeat that command by typing @key{RET}.}
4730 @end example
4731
4732 Some convenience variables are created automatically by @value{GDBN} and given
4733 values likely to be useful.
4734
4735 @table @code
4736 @item $_
4737 @kindex $_
4738 The variable @code{$_} is automatically set by the @code{x} command to
4739 the last address examined (@pxref{Memory, ,Examining memory}). Other
4740 commands which provide a default address for @code{x} to examine also
4741 set @code{$_} to that address; these commands include @code{info line}
4742 and @code{info breakpoint}. The type of @code{$_} is @code{void *}
4743 except when set by the @code{x} command, in which case it is a pointer
4744 to the type of @code{$__}.
4745
4746 @item $__
4747 @kindex $__
4748 The variable @code{$__} is automatically set by the @code{x} command
4749 to the value found in the last address examined. Its type is chosen
4750 to match the format in which the data was printed.
4751 @end table
4752
4753 @node Registers
4754 @section Registers
4755
4756 @cindex registers
4757 You can refer to machine register contents, in expressions, as variables
4758 with names starting with @samp{$}. The names of registers are different
4759 for each machine; use @code{info registers} to see the names used on
4760 your machine.
4761
4762 @table @code
4763 @item info registers
4764 @kindex info registers
4765 Print the names and values of all registers except floating-point
4766 registers (in the selected stack frame).
4767
4768 @item info all-registers
4769 @kindex info all-registers
4770 @cindex floating point registers
4771 Print the names and values of all registers, including floating-point
4772 registers.
4773
4774 @item info registers @var{regname} @dots{}
4775 Print the relativized value of each specified register @var{regname}.
4776 @var{regname} may be any register name valid on the machine you are using, with
4777 or without the initial @samp{$}.
4778 @end table
4779
4780 @value{GDBN} has four ``standard'' register names that are available (in
4781 expressions) on most machines---whenever they do not conflict with an
4782 architecture's canonical mnemonics for registers. The register names
4783 @code{$pc} and @code{$sp} are used for the program counter register and
4784 the stack pointer. @code{$fp} is used for a register that contains a
4785 pointer to the current stack frame, and @code{$ps} is used for a
4786 register that contains the processor status. For example,
4787 you could print the program counter in hex with
4788
4789 @example
4790 p/x $pc
4791 @end example
4792
4793 @noindent
4794 or print the instruction to be executed next with
4795
4796 @example
4797 x/i $pc
4798 @end example
4799
4800 @noindent
4801 or add four to the stack pointer@footnote{This is a way of removing
4802 one word from the stack, on machines where stacks grow downward in
4803 memory (most machines, nowadays). This assumes that the innermost
4804 stack frame is selected; setting @code{$sp} is not allowed when other
4805 stack frames are selected. To pop entire frames off the stack,
4806 regardless of machine architecture, use @code{return};
4807 @pxref{Returning, ,Returning from a function}.} with
4808
4809 @example
4810 set $sp += 4
4811 @end example
4812
4813 Whenever possible, these four standard register names are available on
4814 your machine even though the machine has different canonical mnemonics,
4815 so long as there is no conflict. The @code{info registers} command
4816 shows the canonical names. For example, on the SPARC, @code{info
4817 registers} displays the processor status register as @code{$psr} but you
4818 can also refer to it as @code{$ps}.
4819
4820 @value{GDBN} always considers the contents of an ordinary register as an
4821 integer when the register is examined in this way. Some machines have
4822 special registers which can hold nothing but floating point; these
4823 registers are considered to have floating point values. There is no way
4824 to refer to the contents of an ordinary register as floating point value
4825 (although you can @emph{print} it as a floating point value with
4826 @samp{print/f $@var{regname}}).
4827
4828 Some registers have distinct ``raw'' and ``virtual'' data formats. This
4829 means that the data format in which the register contents are saved by
4830 the operating system is not the same one that your program normally
4831 sees. For example, the registers of the 68881 floating point
4832 coprocessor are always saved in ``extended'' (raw) format, but all C
4833 programs expect to work with ``double'' (virtual) format. In such
4834 cases, @value{GDBN} normally works with the virtual format only (the format that
4835 makes sense for your program), but the @code{info registers} command
4836 prints the data in both formats.
4837
4838 Normally, register values are relative to the selected stack frame
4839 (@pxref{Selection, ,Selecting a frame}). This means that you get the
4840 value that the register would contain if all stack frames farther in
4841 were exited and their saved registers restored. In order to see the
4842 true contents of hardware registers, you must select the innermost
4843 frame (with @samp{frame 0}).
4844
4845 However, @value{GDBN} must deduce where registers are saved, from the machine
4846 code generated by your compiler. If some registers are not saved, or if
4847 @value{GDBN} is unable to locate the saved registers, the selected stack
4848 frame will make no difference.
4849
4850 @ifset AMD29K
4851 @table @code
4852 @item set rstack_high_address @var{address}
4853 @kindex set rstack_high_address
4854 @cindex AMD 29K register stack
4855 @cindex register stack, AMD29K
4856 On AMD 29000 family processors, registers are saved in a separate
4857 ``register stack''. There is no way for @value{GDBN} to determine the extent
4858 of this stack. Normally, @value{GDBN} just assumes that the stack is ``large
4859 enough''. This may result in @value{GDBN} referencing memory locations that
4860 do not exist. If necessary, you can get around this problem by
4861 specifying the ending address of the register stack with the @code{set
4862 rstack_high_address} command. The argument should be an address, which
4863 you will probably want to precede with @samp{0x} to specify in
4864 hexadecimal.
4865
4866 @item show rstack_high_address
4867 @kindex show rstack_high_address
4868 Display the current limit of the register stack, on AMD 29000 family
4869 processors.
4870 @end table
4871 @end ifset
4872
4873 @ifclear HAVE-FLOAT
4874 @node Floating Point Hardware
4875 @section Floating point hardware
4876 @cindex floating point
4877
4878 @c FIXME! Really host, not target?
4879 Depending on the host machine architecture, @value{GDBN} may be able to give
4880 you more information about the status of the floating point hardware.
4881
4882 @table @code
4883 @item info float
4884 @kindex info float
4885 Display hardware-dependent information about the floating
4886 point unit. The exact contents and layout vary depending on the
4887 floating point chip; on some platforms, @samp{info float} is not
4888 available at all.
4889 @end table
4890 @c FIXME: this is a cop-out. Try to get examples, explanations. Only
4891 @c FIXME...supported currently on arm's and 386's. Mark properly with
4892 @c FIXME... m4 macros to isolate general statements from hardware-dep,
4893 @c FIXME... at that point.
4894 @end ifclear
4895
4896 @ifclear CONLY
4897 @node Languages
4898 @chapter Using @value{GDBN} with Different Languages
4899 @cindex languages
4900
4901 @ifset MOD2
4902 Although programming languages generally have common aspects, they are
4903 rarely expressed in the same manner. For instance, in ANSI C,
4904 dereferencing a pointer @code{p} is accomplished by @code{*p}, but in
4905 Modula-2, it is accomplished by @code{p^}. Values can also be
4906 represented (and displayed) differently. Hex numbers in C are written
4907 like @samp{0x1ae}, while in Modula-2 they appear as @samp{1AEH}.
4908 @end ifset
4909
4910 @cindex working language
4911 Language-specific information is built into @value{GDBN} for some languages,
4912 allowing you to express operations like the above in your program's
4913 native language, and allowing @value{GDBN} to output values in a manner
4914 consistent with the syntax of your program's native language. The
4915 language you use to build expressions, called the @dfn{working
4916 language}, can be selected manually, or @value{GDBN} can set it
4917 automatically.
4918
4919 @menu
4920 * Setting:: Switching between source languages
4921 * Show:: Displaying the language
4922 @ifset MOD2
4923 * Checks:: Type and range checks
4924 @end ifset
4925
4926 * Support:: Supported languages
4927 @end menu
4928
4929 @node Setting
4930 @section Switching between source languages
4931
4932 There are two ways to control the working language---either have @value{GDBN}
4933 set it automatically, or select it manually yourself. You can use the
4934 @code{set language} command for either purpose. On startup, @value{GDBN}
4935 defaults to setting the language automatically.
4936
4937 @menu
4938 * Manually:: Setting the working language manually
4939 * Automatically:: Having @value{GDBN} infer the source language
4940 @end menu
4941
4942 @node Manually
4943 @subsection Setting the working language
4944
4945 If you allow @value{GDBN} to set the language automatically,
4946 expressions are interpreted the same way in your debugging session and
4947 your program.
4948
4949 @kindex set language
4950 If you wish, you may set the language manually. To do this, issue the
4951 command @samp{set language @var{lang}}, where @var{lang} is the name of
4952 a language, such as
4953 @ifclear MOD2
4954 @code{c}.
4955 @end ifclear
4956 @ifset MOD2
4957 @code{c} or @code{modula-2}.
4958 @end ifset
4959 For a list of the supported languages, type @samp{set language}.
4960 @c FIXME: rms: eventually this command should be "help set language".
4961
4962 @ifset MOD2
4963 Setting the language manually prevents @value{GDBN} from updating the working
4964 language automatically. This can lead to confusion if you try
4965 to debug a program when the working language is not the same as the
4966 source language, when an expression is acceptable to both
4967 languages---but means different things. For instance, if the current
4968 source file were written in C, and @value{GDBN} was parsing Modula-2, a
4969 command such as:
4970
4971 @example
4972 print a = b + c
4973 @end example
4974
4975 @noindent
4976 might not have the effect you intended. In C, this means to add
4977 @code{b} and @code{c} and place the result in @code{a}. The result
4978 printed would be the value of @code{a}. In Modula-2, this means to compare
4979 @code{a} to the result of @code{b+c}, yielding a @code{BOOLEAN} value.
4980 @end ifset
4981
4982 @node Automatically
4983 @subsection Having @value{GDBN} infer the source language
4984
4985 To have @value{GDBN} set the working language automatically, use @samp{set
4986 language local} or @samp{set language auto}. @value{GDBN} then infers the
4987 language that a program was written in by looking at the name of its
4988 source files, and examining their extensions:
4989
4990 @table @file
4991 @ifset MOD2
4992 @item *.mod
4993 Modula-2 source file
4994 @end ifset
4995
4996 @item *.c
4997 C source file
4998
4999 @item *.C
5000 @itemx *.cc
5001 C++ source file
5002 @end table
5003
5004 This information is recorded for each function or procedure in a source
5005 file. When your program stops in a frame (usually by encountering a
5006 breakpoint), @value{GDBN} sets the working language to the language recorded
5007 for the function in that frame. If the language for a frame is unknown
5008 (that is, if the function or block corresponding to the frame was
5009 defined in a source file that does not have a recognized extension), the
5010 current working language is not changed, and @value{GDBN} issues a warning.
5011
5012 This may not seem necessary for most programs, which are written
5013 entirely in one source language. However, program modules and libraries
5014 written in one source language can be used by a main program written in
5015 a different source language. Using @samp{set language auto} in this
5016 case frees you from having to set the working language manually.
5017
5018 @node Show
5019 @section Displaying the language
5020
5021 The following commands will help you find out which language is the
5022 working language, and also what language source files were written in.
5023
5024 @kindex show language
5025 @kindex info frame
5026 @kindex info source
5027 @table @code
5028 @item show language
5029 Display the current working language. This is the
5030 language you can use with commands such as @code{print} to
5031 build and compute expressions that may involve variables in your program.
5032
5033 @item info frame
5034 Among the other information listed here (@pxref{Frame Info, ,Information
5035 about a frame}) is the source language for this frame. This is the
5036 language that will become the working language if you ever use an
5037 identifier that is in this frame.
5038
5039 @item info source
5040 Among the other information listed here (@pxref{Symbols, ,Examining the
5041 Symbol Table}) is the source language of this source file.
5042 @end table
5043
5044 @ifset MOD2
5045 @node Checks
5046 @section Type and range checking
5047
5048 @quotation
5049 @emph{Warning:} In this release, the @value{GDBN} commands for type and range
5050 checking are included, but they do not yet have any effect. This
5051 section documents the intended facilities.
5052 @end quotation
5053 @c FIXME remove warning when type/range code added
5054
5055 Some languages are designed to guard you against making seemingly common
5056 errors through a series of compile- and run-time checks. These include
5057 checking the type of arguments to functions and operators, and making
5058 sure mathematical overflows are caught at run time. Checks such as
5059 these help to ensure a program's correctness once it has been compiled
5060 by eliminating type mismatches, and providing active checks for range
5061 errors when your program is running.
5062
5063 @value{GDBN} can check for conditions like the above if you wish.
5064 Although @value{GDBN} will not check the statements in your program, it
5065 can check expressions entered directly into @value{GDBN} for evaluation via
5066 the @code{print} command, for example. As with the working language,
5067 @value{GDBN} can also decide whether or not to check automatically based on
5068 your program's source language. @xref{Support, ,Supported languages},
5069 for the default settings of supported languages.
5070
5071 @menu
5072 * Type Checking:: An overview of type checking
5073 * Range Checking:: An overview of range checking
5074 @end menu
5075
5076 @cindex type checking
5077 @cindex checks, type
5078 @node Type Checking
5079 @subsection An overview of type checking
5080
5081 Some languages, such as Modula-2, are strongly typed, meaning that the
5082 arguments to operators and functions have to be of the correct type,
5083 otherwise an error occurs. These checks prevent type mismatch
5084 errors from ever causing any run-time problems. For example,
5085
5086 @example
5087 1 + 2 @result{} 3
5088 @exdent but
5089 @error{} 1 + 2.3
5090 @end example
5091
5092 The second example fails because the @code{CARDINAL} 1 is not
5093 type-compatible with the @code{REAL} 2.3.
5094
5095 For expressions you use in @value{GDBN} commands, you can tell the @value{GDBN}
5096 type checker to skip checking; to treat any mismatches as errors and
5097 abandon the expression; or only issue warnings when type mismatches
5098 occur, but evaluate the expression anyway. When you choose the last of
5099 these, @value{GDBN} evaluates expressions like the second example above, but
5100 also issues a warning.
5101
5102 Even though you may turn type checking off, other type-based reasons may
5103 prevent @value{GDBN} from evaluating an expression. For instance, @value{GDBN} does not
5104 know how to add an @code{int} and a @code{struct foo}. These particular
5105 type errors have nothing to do with the language in use, and usually
5106 arise from expressions, such as the one described above, which make
5107 little sense to evaluate anyway.
5108
5109 Each language defines to what degree it is strict about type. For
5110 instance, both Modula-2 and C require the arguments to arithmetical
5111 operators to be numbers. In C, enumerated types and pointers can be
5112 represented as numbers, so that they are valid arguments to mathematical
5113 operators. @xref{Support, ,Supported languages}, for further
5114 details on specific languages.
5115
5116 @value{GDBN} provides some additional commands for controlling the type checker:
5117
5118 @kindex set check
5119 @kindex set check type
5120 @kindex show check type
5121 @table @code
5122 @item set check type auto
5123 Set type checking on or off based on the current working language.
5124 @xref{Support, ,Supported languages}, for the default settings for
5125 each language.
5126
5127 @item set check type on
5128 @itemx set check type off
5129 Set type checking on or off, overriding the default setting for the
5130 current working language. Issue a warning if the setting does not
5131 match the language default. If any type mismatches occur in
5132 evaluating an expression while typechecking is on, @value{GDBN} prints a
5133 message and aborts evaluation of the expression.
5134
5135 @item set check type warn
5136 Cause the type checker to issue warnings, but to always attempt to
5137 evaluate the expression. Evaluating the expression may still
5138 be impossible for other reasons. For example, @value{GDBN} cannot add
5139 numbers and structures.
5140
5141 @item show type
5142 Show the current setting of the type checker, and whether or not @value{GDBN} is
5143 setting it automatically.
5144 @end table
5145
5146 @cindex range checking
5147 @cindex checks, range
5148 @node Range Checking
5149 @subsection An overview of range checking
5150
5151 In some languages (such as Modula-2), it is an error to exceed the
5152 bounds of a type; this is enforced with run-time checks. Such range
5153 checking is meant to ensure program correctness by making sure
5154 computations do not overflow, or indices on an array element access do
5155 not exceed the bounds of the array.
5156
5157 For expressions you use in @value{GDBN} commands, you can tell
5158 @value{GDBN} to treat range errors in one of three ways: ignore them,
5159 always treat them as errors and abandon the expression, or issue
5160 warnings but evaluate the expression anyway.
5161
5162 A range error can result from numerical overflow, from exceeding an
5163 array index bound, or when you type a constant that is not a member
5164 of any type. Some languages, however, do not treat overflows as an
5165 error. In many implementations of C, mathematical overflow causes the
5166 result to ``wrap around'' to lower values---for example, if @var{m} is
5167 the largest integer value, and @var{s} is the smallest, then
5168
5169 @example
5170 @var{m} + 1 @result{} @var{s}
5171 @end example
5172
5173 This, too, is specific to individual languages, and in some cases
5174 specific to individual compilers or machines. @xref{Support, ,
5175 Supported languages}, for further details on specific languages.
5176
5177 @value{GDBN} provides some additional commands for controlling the range checker:
5178
5179 @kindex set check
5180 @kindex set check range
5181 @kindex show check range
5182 @table @code
5183 @item set check range auto
5184 Set range checking on or off based on the current working language.
5185 @xref{Support, ,Supported languages}, for the default settings for
5186 each language.
5187
5188 @item set check range on
5189 @itemx set check range off
5190 Set range checking on or off, overriding the default setting for the
5191 current working language. A warning is issued if the setting does not
5192 match the language default. If a range error occurs, then a message
5193 is printed and evaluation of the expression is aborted.
5194
5195 @item set check range warn
5196 Output messages when the @value{GDBN} range checker detects a range error,
5197 but attempt to evaluate the expression anyway. Evaluating the
5198 expression may still be impossible for other reasons, such as accessing
5199 memory that the process does not own (a typical example from many Unix
5200 systems).
5201
5202 @item show range
5203 Show the current setting of the range checker, and whether or not it is
5204 being set automatically by @value{GDBN}.
5205 @end table
5206 @end ifset
5207
5208 @node Support
5209 @section Supported languages
5210
5211 @ifset MOD2
5212 @value{GDBN} 4 supports C, C++, and Modula-2.
5213 @end ifset
5214 @ifclear MOD2
5215 @value{GDBN} 4 supports C, and C++.
5216 @end ifclear
5217 Some @value{GDBN} features may be used in expressions regardless of the
5218 language you use: the @value{GDBN} @code{@@} and @code{::} operators,
5219 and the @samp{@{type@}addr} construct (@pxref{Expressions,
5220 ,Expressions}) can be used with the constructs of any supported
5221 language.
5222
5223 The following sections detail to what degree each source language is
5224 supported by @value{GDBN}. These sections are not meant to be language
5225 tutorials or references, but serve only as a reference guide to what the
5226 @value{GDBN} expression parser will accept, and what input and output
5227 formats should look like for different languages. There are many good
5228 books written on each of these languages; please look to these for a
5229 language reference or tutorial.
5230
5231 @ifset MOD2
5232 @menu
5233 * C:: C and C++
5234 * Modula-2:: Modula-2
5235 @end menu
5236
5237 @node C
5238 @subsection C and C++
5239 @cindex C and C++
5240 @cindex expressions in C or C++
5241
5242 Since C and C++ are so closely related, many features of @value{GDBN} apply
5243 to both languages. Whenever this is the case, we discuss both languages
5244 together.
5245 @end ifset
5246 @ifclear MOD2
5247 @c Cancel this below, under same condition, at end of this chapter!
5248 @raisesections
5249 @end ifclear
5250
5251 @cindex C++
5252 @kindex g++
5253 @cindex GNU C++
5254 The C++ debugging facilities are jointly implemented by the GNU C++
5255 compiler and @value{GDBN}. Therefore, to debug your C++ code
5256 effectively, you must compile your C++ programs with the GNU C++
5257 compiler, @code{g++}.
5258
5259 For best results when debugging C++ programs, use the stabs debugging
5260 format. You can select that format explicitly with the @code{g++}
5261 command-line options @samp{-gstabs} or @samp{-gstabs+}. See
5262 @ref{Debugging Options,,Options for Debugging Your Program or GNU CC,
5263 gcc.info, Using GNU CC}, for more information.
5264 @end ifclear
5265 @ifset CONLY
5266 @node C
5267 @chapter C Language Support
5268 @cindex C language
5269 @cindex expressions in C
5270
5271 Information specific to the C language is built into @value{GDBN} so that you
5272 can use C expressions while degugging. This also permits @value{GDBN} to
5273 output values in a manner consistent with C conventions.
5274
5275 @menu
5276 * C Operators:: C operators
5277 * C Constants:: C constants
5278 * Debugging C:: @value{GDBN} and C
5279 @end menu
5280 @end ifset
5281 @ifclear CONLY
5282 @menu
5283 * C Operators:: C and C++ operators
5284 * C Constants:: C and C++ constants
5285 * Cplus expressions:: C++ expressions
5286 * C Defaults:: Default settings for C and C++
5287 @ifset MOD2
5288 * C Checks:: C and C++ type and range checks
5289 @end ifset
5290
5291 * Debugging C:: @value{GDBN} and C
5292 * Debugging C plus plus:: Special features for C++
5293 @end menu
5294 @end ifclear
5295
5296 @ifclear CONLY
5297 @cindex C and C++ operators
5298 @node C Operators
5299 @subsubsection C and C++ operators
5300 @end ifclear
5301 @ifset CONLY
5302 @cindex C operators
5303 @node C Operators
5304 @section C operators
5305 @end ifset
5306
5307 Operators must be defined on values of specific types. For instance,
5308 @code{+} is defined on numbers, but not on structures. Operators are
5309 often defined on groups of types.
5310
5311 @ifclear CONLY
5312 For the purposes of C and C++, the following definitions hold:
5313 @end ifclear
5314
5315 @itemize @bullet
5316 @item
5317 @emph{Integral types} include @code{int} with any of its storage-class
5318 specifiers; @code{char}; and @code{enum}.
5319
5320 @item
5321 @emph{Floating-point types} include @code{float} and @code{double}.
5322
5323 @item
5324 @emph{Pointer types} include all types defined as @code{(@var{type}
5325 *)}.
5326
5327 @item
5328 @emph{Scalar types} include all of the above.
5329 @end itemize
5330
5331 @noindent
5332 The following operators are supported. They are listed here
5333 in order of increasing precedence:
5334
5335 @table @code
5336 @item ,
5337 The comma or sequencing operator. Expressions in a comma-separated list
5338 are evaluated from left to right, with the result of the entire
5339 expression being the last expression evaluated.
5340
5341 @item =
5342 Assignment. The value of an assignment expression is the value
5343 assigned. Defined on scalar types.
5344
5345 @item @var{op}=
5346 Used in an expression of the form @w{@code{@var{a} @var{op}= @var{b}}},
5347 and translated to @w{@code{@var{a} = @var{a op b}}}.
5348 @w{@code{@var{op}=}} and @code{=} have the same precendence.
5349 @var{op} is any one of the operators @code{|}, @code{^}, @code{&},
5350 @code{<<}, @code{>>}, @code{+}, @code{-}, @code{*}, @code{/}, @code{%}.
5351
5352 @item ?:
5353 The ternary operator. @code{@var{a} ? @var{b} : @var{c}} can be thought
5354 of as: if @var{a} then @var{b} else @var{c}. @var{a} should be of an
5355 integral type.
5356
5357 @item ||
5358 Logical @sc{or}. Defined on integral types.
5359
5360 @item &&
5361 Logical @sc{and}. Defined on integral types.
5362
5363 @item |
5364 Bitwise @sc{or}. Defined on integral types.
5365
5366 @item ^
5367 Bitwise exclusive-@sc{or}. Defined on integral types.
5368
5369 @item &
5370 Bitwise @sc{and}. Defined on integral types.
5371
5372 @item ==@r{, }!=
5373 Equality and inequality. Defined on scalar types. The value of these
5374 expressions is 0 for false and non-zero for true.
5375
5376 @item <@r{, }>@r{, }<=@r{, }>=
5377 Less than, greater than, less than or equal, greater than or equal.
5378 Defined on scalar types. The value of these expressions is 0 for false
5379 and non-zero for true.
5380
5381 @item <<@r{, }>>
5382 left shift, and right shift. Defined on integral types.
5383
5384 @item @@
5385 The @value{GDBN} ``artificial array'' operator (@pxref{Expressions, ,Expressions}).
5386
5387 @item +@r{, }-
5388 Addition and subtraction. Defined on integral types, floating-point types and
5389 pointer types.
5390
5391 @item *@r{, }/@r{, }%
5392 Multiplication, division, and modulus. Multiplication and division are
5393 defined on integral and floating-point types. Modulus is defined on
5394 integral types.
5395
5396 @item ++@r{, }--
5397 Increment and decrement. When appearing before a variable, the
5398 operation is performed before the variable is used in an expression;
5399 when appearing after it, the variable's value is used before the
5400 operation takes place.
5401
5402 @item *
5403 Pointer dereferencing. Defined on pointer types. Same precedence as
5404 @code{++}.
5405
5406 @item &
5407 Address operator. Defined on variables. Same precedence as @code{++}.
5408
5409 @ifclear CONLY
5410 For debugging C++, @value{GDBN} implements a use of @samp{&} beyond what is
5411 allowed in the C++ language itself: you can use @samp{&(&@var{ref})}
5412 (or, if you prefer, simply @samp{&&@var{ref}}) to examine the address
5413 where a C++ reference variable (declared with @samp{&@var{ref}}) is
5414 stored.
5415 @end ifclear
5416
5417 @item -
5418 Negative. Defined on integral and floating-point types. Same
5419 precedence as @code{++}.
5420
5421 @item !
5422 Logical negation. Defined on integral types. Same precedence as
5423 @code{++}.
5424
5425 @item ~
5426 Bitwise complement operator. Defined on integral types. Same precedence as
5427 @code{++}.
5428
5429
5430 @item .@r{, }->
5431 Structure member, and pointer-to-structure member. For convenience,
5432 @value{GDBN} regards the two as equivalent, choosing whether to dereference a
5433 pointer based on the stored type information.
5434 Defined on @code{struct} and @code{union} data.
5435
5436 @item []
5437 Array indexing. @code{@var{a}[@var{i}]} is defined as
5438 @code{*(@var{a}+@var{i})}. Same precedence as @code{->}.
5439
5440 @item ()
5441 Function parameter list. Same precedence as @code{->}.
5442
5443 @ifclear CONLY
5444 @item ::
5445 C++ scope resolution operator. Defined on
5446 @code{struct}, @code{union}, and @code{class} types.
5447 @end ifclear
5448
5449 @item ::
5450 Doubled colons
5451 @ifclear CONLY
5452 also
5453 @end ifclear
5454 represent the @value{GDBN} scope operator (@pxref{Expressions,
5455 ,Expressions}).
5456 @ifclear CONLY
5457 Same precedence as @code{::}, above.
5458 @end ifclear
5459 @end table
5460
5461 @ifclear CONLY
5462 @cindex C and C++ constants
5463 @node C Constants
5464 @subsubsection C and C++ constants
5465
5466 @value{GDBN} allows you to express the constants of C and C++ in the
5467 following ways:
5468 @end ifclear
5469 @ifset CONLY
5470 @cindex C constants
5471 @node C Constants
5472 @section C constants
5473
5474 @value{GDBN} allows you to express the constants of C in the
5475 following ways:
5476 @end ifset
5477
5478 @itemize @bullet
5479 @item
5480 Integer constants are a sequence of digits. Octal constants are
5481 specified by a leading @samp{0} (ie. zero), and hexadecimal constants by
5482 a leading @samp{0x} or @samp{0X}. Constants may also end with a letter
5483 @samp{l}, specifying that the constant should be treated as a
5484 @code{long} value.
5485
5486 @item
5487 Floating point constants are a sequence of digits, followed by a decimal
5488 point, followed by a sequence of digits, and optionally followed by an
5489 exponent. An exponent is of the form:
5490 @samp{@w{e@r{[[}+@r{]|}-@r{]}@var{nnn}}}, where @var{nnn} is another
5491 sequence of digits. The @samp{+} is optional for positive exponents.
5492
5493 @item
5494 Enumerated constants consist of enumerated identifiers, or their
5495 integral equivalents.
5496
5497 @item
5498 Character constants are a single character surrounded by single quotes
5499 (@code{'}), or a number---the ordinal value of the corresponding character
5500 (usually its @sc{ASCII} value). Within quotes, the single character may
5501 be represented by a letter or by @dfn{escape sequences}, which are of
5502 the form @samp{\@var{nnn}}, where @var{nnn} is the octal representation
5503 of the character's ordinal value; or of the form @samp{\@var{x}}, where
5504 @samp{@var{x}} is a predefined special character---for example,
5505 @samp{\n} for newline.
5506
5507 @item
5508 String constants are a sequence of character constants surrounded
5509 by double quotes (@code{"}).
5510
5511 @item
5512 Pointer constants are an integral value. You can also write pointers
5513 to constants using the C operator @samp{&}.
5514
5515 @item
5516 Array constants are comma-separated lists surrounded by braces @samp{@{}
5517 and @samp{@}}; for example, @samp{@{1,2,3@}} is a three-element array of
5518 integers, @samp{@{@{1,2@}, @{3,4@}, @{5,6@}@}} is a three-by-two array,
5519 and @samp{@{&"hi", &"there", &"fred"@}} is a three-element array of pointers.
5520 @end itemize
5521
5522 @ifclear CONLY
5523 @node Cplus expressions
5524 @subsubsection C++ expressions
5525
5526 @cindex expressions in C++
5527 @value{GDBN} expression handling has a number of extensions to
5528 interpret a significant subset of C++ expressions.
5529
5530 @cindex C++ support, not in @sc{coff}
5531 @cindex @sc{coff} versus C++
5532 @cindex C++ and object formats
5533 @cindex object formats and C++
5534 @cindex a.out and C++
5535 @cindex @sc{ecoff} and C++
5536 @cindex @sc{xcoff} and C++
5537 @cindex @sc{elf}/stabs and C++
5538 @cindex @sc{elf}/@sc{dwarf} and C++
5539 @quotation
5540 @emph{Warning:} Most of these extensions depend on the use of additional
5541 debugging information in the symbol table, and thus require a rich,
5542 extendable object code format. In particular, if your system uses
5543 a.out, MIPS @sc{ecoff}, RS/6000 @sc{xcoff}, or Sun @sc{elf} with stabs
5544 extensions to the symbol table, these facilities are all available.
5545 Where the object code format is standard @sc{coff}, on the other hand,
5546 most of the C++ support in @value{GDBN} will @emph{not} work, nor can it.
5547 For the standard SVr4 debugging format, @sc{dwarf} in @sc{elf}, the
5548 standard is still evolving, so the C++ support in @value{GDBN} is still
5549 fragile; when this debugging format stabilizes, however, C++ support
5550 will also be available on systems that use it.
5551 @end quotation
5552
5553 @enumerate
5554
5555 @cindex member functions
5556 @item
5557 Member function calls are allowed; you can use expressions like
5558
5559 @example
5560 count = aml->GetOriginal(x, y)
5561 @end example
5562
5563 @kindex this
5564 @cindex namespace in C++
5565 @item
5566 While a member function is active (in the selected stack frame), your
5567 expressions have the same namespace available as the member function;
5568 that is, @value{GDBN} allows implicit references to the class instance
5569 pointer @code{this} following the same rules as C++.
5570
5571 @cindex call overloaded functions
5572 @cindex type conversions in C++
5573 @item
5574 You can call overloaded functions; @value{GDBN} will resolve the function
5575 call to the right definition, with one restriction---you must use
5576 arguments of the type required by the function that you want to call.
5577 @value{GDBN} will not perform conversions requiring constructors or
5578 user-defined type operators.
5579
5580 @cindex reference declarations
5581 @item
5582 @value{GDBN} understands variables declared as C++ references; you can use them in
5583 expressions just as you do in C++ source---they are automatically
5584 dereferenced.
5585
5586 In the parameter list shown when @value{GDBN} displays a frame, the values of
5587 reference variables are not displayed (unlike other variables); this
5588 avoids clutter, since references are often used for large structures.
5589 The @emph{address} of a reference variable is always shown, unless
5590 you have specified @samp{set print address off}.
5591
5592 @item
5593 @value{GDBN} supports the C++ name resolution operator @code{::}---your
5594 expressions can use it just as expressions in your program do. Since
5595 one scope may be defined in another, you can use @code{::} repeatedly if
5596 necessary, for example in an expression like
5597 @samp{@var{scope1}::@var{scope2}::@var{name}}. @value{GDBN} also allows
5598 resolving name scope by reference to source files, in both C and C++
5599 debugging (@pxref{Variables, ,Program variables}).
5600 @end enumerate
5601
5602 @node C Defaults
5603 @subsubsection C and C++ defaults
5604 @cindex C and C++ defaults
5605
5606 If you allow @value{GDBN} to set type and range checking automatically, they
5607 both default to @code{off} whenever the working language changes to
5608 C or C++. This happens regardless of whether you, or @value{GDBN},
5609 selected the working language.
5610
5611 If you allow @value{GDBN} to set the language automatically, it sets the
5612 working language to C or C++ on entering code compiled from a source file
5613 whose name ends with @file{.c}, @file{.C}, or @file{.cc}.
5614 @xref{Automatically, ,Having @value{GDBN} infer the source language}, for
5615 further details.
5616
5617 @ifset MOD2
5618 @c Type checking is (a) primarily motivated by Modula-2, and (b)
5619 @c unimplemented. If (b) changes, it might make sense to let this node
5620 @c appear even if Mod-2 does not, but meanwhile ignore it. pesch 16jul93.
5621 @node C Checks
5622 @subsubsection C and C++ type and range checks
5623 @cindex C and C++ checks
5624
5625 By default, when @value{GDBN} parses C or C++ expressions, type checking
5626 is not used. However, if you turn type checking on, @value{GDBN} will
5627 consider two variables type equivalent if:
5628
5629 @itemize @bullet
5630 @item
5631 The two variables are structured and have the same structure, union, or
5632 enumerated tag.
5633
5634 @item
5635 Two two variables have the same type name, or types that have been
5636 declared equivalent through @code{typedef}.
5637
5638 @ignore
5639 @c leaving this out because neither J Gilmore nor R Pesch understand it.
5640 @c FIXME--beers?
5641 @item
5642 The two @code{struct}, @code{union}, or @code{enum} variables are
5643 declared in the same declaration. (Note: this may not be true for all C
5644 compilers.)
5645 @end ignore
5646 @end itemize
5647
5648 Range checking, if turned on, is done on mathematical operations. Array
5649 indices are not checked, since they are often used to index a pointer
5650 that is not itself an array.
5651 @end ifset
5652 @end ifclear
5653
5654 @ifclear CONLY
5655 @node Debugging C
5656 @subsubsection @value{GDBN} and C
5657 @end ifclear
5658 @ifset CONLY
5659 @node Debugging C
5660 @section @value{GDBN} and C
5661 @end ifset
5662
5663 The @code{set print union} and @code{show print union} commands apply to
5664 the @code{union} type. When set to @samp{on}, any @code{union} that is
5665 inside a @code{struct}
5666 @ifclear CONLY
5667 or @code{class}
5668 @end ifclear
5669 will also be printed.
5670 Otherwise, it will appear as @samp{@{...@}}.
5671
5672 The @code{@@} operator aids in the debugging of dynamic arrays, formed
5673 with pointers and a memory allocation function. @xref{Expressions,
5674 ,Expressions}.
5675
5676 @ifclear CONLY
5677 @node Debugging C plus plus
5678 @subsubsection @value{GDBN} features for C++
5679
5680 @cindex commands for C++
5681 Some @value{GDBN} commands are particularly useful with C++, and some are
5682 designed specifically for use with C++. Here is a summary:
5683
5684 @table @code
5685 @cindex break in overloaded functions
5686 @item @r{breakpoint menus}
5687 When you want a breakpoint in a function whose name is overloaded,
5688 @value{GDBN} breakpoint menus help you specify which function definition
5689 you want. @xref{Breakpoint Menus,,Breakpoint menus}.
5690
5691 @cindex overloading in C++
5692 @item rbreak @var{regex}
5693 Setting breakpoints using regular expressions is helpful for setting
5694 breakpoints on overloaded functions that are not members of any special
5695 classes.
5696 @xref{Set Breaks, ,Setting breakpoints}.
5697
5698 @cindex C++ exception handling
5699 @item catch @var{exceptions}
5700 @itemx info catch
5701 Debug C++ exception handling using these commands. @xref{Exception
5702 Handling, ,Breakpoints and exceptions}.
5703
5704 @cindex inheritance
5705 @item ptype @var{typename}
5706 Print inheritance relationships as well as other information for type
5707 @var{typename}.
5708 @xref{Symbols, ,Examining the Symbol Table}.
5709
5710 @cindex C++ symbol display
5711 @item set print demangle
5712 @itemx show print demangle
5713 @itemx set print asm-demangle
5714 @itemx show print asm-demangle
5715 Control whether C++ symbols display in their source form, both when
5716 displaying code as C++ source and when displaying disassemblies.
5717 @xref{Print Settings, ,Print settings}.
5718
5719 @item set print object
5720 @itemx show print object
5721 Choose whether to print derived (actual) or declared types of objects.
5722 @xref{Print Settings, ,Print settings}.
5723
5724 @item set print vtbl
5725 @itemx show print vtbl
5726 Control the format for printing virtual function tables.
5727 @xref{Print Settings, ,Print settings}.
5728
5729 @item @r{Overloaded symbol names}
5730 You can specify a particular definition of an overloaded symbol, using
5731 the same notation that is used to declare such symbols in C++: type
5732 @code{@var{symbol}(@var{types})} rather than just @var{symbol}. You can
5733 also use the @value{GDBN} command-line word completion facilities to list the
5734 available choices, or to finish the type list for you.
5735 @xref{Completion,, Command completion}, for details on how to do this.
5736 @end table
5737 @ifclear MOD2
5738 @c cancels "raisesections" under same conditions near bgn of chapter
5739 @lowersections
5740 @end ifclear
5741
5742 @ifset MOD2
5743 @node Modula-2
5744 @subsection Modula-2
5745 @cindex Modula-2
5746
5747 The extensions made to @value{GDBN} to support Modula-2 only support
5748 output from the GNU Modula-2 compiler (which is currently being
5749 developed). Other Modula-2 compilers are not currently supported, and
5750 attempting to debug executables produced by them will most likely
5751 result in an error as @value{GDBN} reads in the executable's symbol
5752 table.
5753
5754 @cindex expressions in Modula-2
5755 @menu
5756 * M2 Operators:: Built-in operators
5757 * Built-In Func/Proc:: Built-in functions and procedures
5758 * M2 Constants:: Modula-2 constants
5759 * M2 Defaults:: Default settings for Modula-2
5760 * Deviations:: Deviations from standard Modula-2
5761 * M2 Checks:: Modula-2 type and range checks
5762 * M2 Scope:: The scope operators @code{::} and @code{.}
5763 * GDB/M2:: @value{GDBN} and Modula-2
5764 @end menu
5765
5766 @node M2 Operators
5767 @subsubsection Operators
5768 @cindex Modula-2 operators
5769
5770 Operators must be defined on values of specific types. For instance,
5771 @code{+} is defined on numbers, but not on structures. Operators are
5772 often defined on groups of types. For the purposes of Modula-2, the
5773 following definitions hold:
5774
5775 @itemize @bullet
5776
5777 @item
5778 @emph{Integral types} consist of @code{INTEGER}, @code{CARDINAL}, and
5779 their subranges.
5780
5781 @item
5782 @emph{Character types} consist of @code{CHAR} and its subranges.
5783
5784 @item
5785 @emph{Floating-point types} consist of @code{REAL}.
5786
5787 @item
5788 @emph{Pointer types} consist of anything declared as @code{POINTER TO
5789 @var{type}}.
5790
5791 @item
5792 @emph{Scalar types} consist of all of the above.
5793
5794 @item
5795 @emph{Set types} consist of @code{SET} and @code{BITSET} types.
5796
5797 @item
5798 @emph{Boolean types} consist of @code{BOOLEAN}.
5799 @end itemize
5800
5801 @noindent
5802 The following operators are supported, and appear in order of
5803 increasing precedence:
5804
5805 @table @code
5806 @item ,
5807 Function argument or array index separator.
5808
5809 @item :=
5810 Assignment. The value of @var{var} @code{:=} @var{value} is
5811 @var{value}.
5812
5813 @item <@r{, }>
5814 Less than, greater than on integral, floating-point, or enumerated
5815 types.
5816
5817 @item <=@r{, }>=
5818 Less than, greater than, less than or equal to, greater than or equal to
5819 on integral, floating-point and enumerated types, or set inclusion on
5820 set types. Same precedence as @code{<}.
5821
5822 @item =@r{, }<>@r{, }#
5823 Equality and two ways of expressing inequality, valid on scalar types.
5824 Same precedence as @code{<}. In @value{GDBN} scripts, only @code{<>} is
5825 available for inequality, since @code{#} conflicts with the script
5826 comment character.
5827
5828 @item IN
5829 Set membership. Defined on set types and the types of their members.
5830 Same precedence as @code{<}.
5831
5832 @item OR
5833 Boolean disjunction. Defined on boolean types.
5834
5835 @item AND@r{, }&
5836 Boolean conjuction. Defined on boolean types.
5837
5838 @item @@
5839 The @value{GDBN} ``artificial array'' operator (@pxref{Expressions, ,Expressions}).
5840
5841 @item +@r{, }-
5842 Addition and subtraction on integral and floating-point types, or union
5843 and difference on set types.
5844
5845 @item *
5846 Multiplication on integral and floating-point types, or set intersection
5847 on set types.
5848
5849 @item /
5850 Division on floating-point types, or symmetric set difference on set
5851 types. Same precedence as @code{*}.
5852
5853 @item DIV@r{, }MOD
5854 Integer division and remainder. Defined on integral types. Same
5855 precedence as @code{*}.
5856
5857 @item -
5858 Negative. Defined on @code{INTEGER} and @code{REAL} data.
5859
5860 @item ^
5861 Pointer dereferencing. Defined on pointer types.
5862
5863 @item NOT
5864 Boolean negation. Defined on boolean types. Same precedence as
5865 @code{^}.
5866
5867 @item .
5868 @code{RECORD} field selector. Defined on @code{RECORD} data. Same
5869 precedence as @code{^}.
5870
5871 @item []
5872 Array indexing. Defined on @code{ARRAY} data. Same precedence as @code{^}.
5873
5874 @item ()
5875 Procedure argument list. Defined on @code{PROCEDURE} objects. Same precedence
5876 as @code{^}.
5877
5878 @item ::@r{, }.
5879 @value{GDBN} and Modula-2 scope operators.
5880 @end table
5881
5882 @quotation
5883 @emph{Warning:} Sets and their operations are not yet supported, so @value{GDBN}
5884 will treat the use of the operator @code{IN}, or the use of operators
5885 @code{+}, @code{-}, @code{*}, @code{/}, @code{=}, , @code{<>}, @code{#},
5886 @code{<=}, and @code{>=} on sets as an error.
5887 @end quotation
5888
5889 @cindex Modula-2 built-ins
5890 @node Built-In Func/Proc
5891 @subsubsection Built-in functions and procedures
5892
5893 Modula-2 also makes available several built-in procedures and functions.
5894 In describing these, the following metavariables are used:
5895
5896 @table @var
5897
5898 @item a
5899 represents an @code{ARRAY} variable.
5900
5901 @item c
5902 represents a @code{CHAR} constant or variable.
5903
5904 @item i
5905 represents a variable or constant of integral type.
5906
5907 @item m
5908 represents an identifier that belongs to a set. Generally used in the
5909 same function with the metavariable @var{s}. The type of @var{s} should
5910 be @code{SET OF @var{mtype}} (where @var{mtype} is the type of @var{m}).
5911
5912 @item n
5913 represents a variable or constant of integral or floating-point type.
5914
5915 @item r
5916 represents a variable or constant of floating-point type.
5917
5918 @item t
5919 represents a type.
5920
5921 @item v
5922 represents a variable.
5923
5924 @item x
5925 represents a variable or constant of one of many types. See the
5926 explanation of the function for details.
5927 @end table
5928
5929 All Modula-2 built-in procedures also return a result, described below.
5930
5931 @table @code
5932 @item ABS(@var{n})
5933 Returns the absolute value of @var{n}.
5934
5935 @item CAP(@var{c})
5936 If @var{c} is a lower case letter, it returns its upper case
5937 equivalent, otherwise it returns its argument
5938
5939 @item CHR(@var{i})
5940 Returns the character whose ordinal value is @var{i}.
5941
5942 @item DEC(@var{v})
5943 Decrements the value in the variable @var{v}. Returns the new value.
5944
5945 @item DEC(@var{v},@var{i})
5946 Decrements the value in the variable @var{v} by @var{i}. Returns the
5947 new value.
5948
5949 @item EXCL(@var{m},@var{s})
5950 Removes the element @var{m} from the set @var{s}. Returns the new
5951 set.
5952
5953 @item FLOAT(@var{i})
5954 Returns the floating point equivalent of the integer @var{i}.
5955
5956 @item HIGH(@var{a})
5957 Returns the index of the last member of @var{a}.
5958
5959 @item INC(@var{v})
5960 Increments the value in the variable @var{v}. Returns the new value.
5961
5962 @item INC(@var{v},@var{i})
5963 Increments the value in the variable @var{v} by @var{i}. Returns the
5964 new value.
5965
5966 @item INCL(@var{m},@var{s})
5967 Adds the element @var{m} to the set @var{s} if it is not already
5968 there. Returns the new set.
5969
5970 @item MAX(@var{t})
5971 Returns the maximum value of the type @var{t}.
5972
5973 @item MIN(@var{t})
5974 Returns the minimum value of the type @var{t}.
5975
5976 @item ODD(@var{i})
5977 Returns boolean TRUE if @var{i} is an odd number.
5978
5979 @item ORD(@var{x})
5980 Returns the ordinal value of its argument. For example, the ordinal
5981 value of a character is its ASCII value (on machines supporting the
5982 ASCII character set). @var{x} must be of an ordered type, which include
5983 integral, character and enumerated types.
5984
5985 @item SIZE(@var{x})
5986 Returns the size of its argument. @var{x} can be a variable or a type.
5987
5988 @item TRUNC(@var{r})
5989 Returns the integral part of @var{r}.
5990
5991 @item VAL(@var{t},@var{i})
5992 Returns the member of the type @var{t} whose ordinal value is @var{i}.
5993 @end table
5994
5995 @quotation
5996 @emph{Warning:} Sets and their operations are not yet supported, so
5997 @value{GDBN} will treat the use of procedures @code{INCL} and @code{EXCL} as
5998 an error.
5999 @end quotation
6000
6001 @cindex Modula-2 constants
6002 @node M2 Constants
6003 @subsubsection Constants
6004
6005 @value{GDBN} allows you to express the constants of Modula-2 in the following
6006 ways:
6007
6008 @itemize @bullet
6009
6010 @item
6011 Integer constants are simply a sequence of digits. When used in an
6012 expression, a constant is interpreted to be type-compatible with the
6013 rest of the expression. Hexadecimal integers are specified by a
6014 trailing @samp{H}, and octal integers by a trailing @samp{B}.
6015
6016 @item
6017 Floating point constants appear as a sequence of digits, followed by a
6018 decimal point and another sequence of digits. An optional exponent can
6019 then be specified, in the form @samp{E@r{[}+@r{|}-@r{]}@var{nnn}}, where
6020 @samp{@r{[}+@r{|}-@r{]}@var{nnn}} is the desired exponent. All of the
6021 digits of the floating point constant must be valid decimal (base 10)
6022 digits.
6023
6024 @item
6025 Character constants consist of a single character enclosed by a pair of
6026 like quotes, either single (@code{'}) or double (@code{"}). They may
6027 also be expressed by their ordinal value (their ASCII value, usually)
6028 followed by a @samp{C}.
6029
6030 @item
6031 String constants consist of a sequence of characters enclosed by a
6032 pair of like quotes, either single (@code{'}) or double (@code{"}).
6033 Escape sequences in the style of C are also allowed. @xref{C
6034 Constants, ,C and C++ constants}, for a brief explanation of escape
6035 sequences.
6036
6037 @item
6038 Enumerated constants consist of an enumerated identifier.
6039
6040 @item
6041 Boolean constants consist of the identifiers @code{TRUE} and
6042 @code{FALSE}.
6043
6044 @item
6045 Pointer constants consist of integral values only.
6046
6047 @item
6048 Set constants are not yet supported.
6049 @end itemize
6050
6051 @node M2 Defaults
6052 @subsubsection Modula-2 defaults
6053 @cindex Modula-2 defaults
6054
6055 If type and range checking are set automatically by @value{GDBN}, they
6056 both default to @code{on} whenever the working language changes to
6057 Modula-2. This happens regardless of whether you, or @value{GDBN},
6058 selected the working language.
6059
6060 If you allow @value{GDBN} to set the language automatically, then entering
6061 code compiled from a file whose name ends with @file{.mod} will set the
6062 working language to Modula-2. @xref{Automatically, ,Having @value{GDBN} set
6063 the language automatically}, for further details.
6064
6065 @node Deviations
6066 @subsubsection Deviations from standard Modula-2
6067 @cindex Modula-2, deviations from
6068
6069 A few changes have been made to make Modula-2 programs easier to debug.
6070 This is done primarily via loosening its type strictness:
6071
6072 @itemize @bullet
6073 @item
6074 Unlike in standard Modula-2, pointer constants can be formed by
6075 integers. This allows you to modify pointer variables during
6076 debugging. (In standard Modula-2, the actual address contained in a
6077 pointer variable is hidden from you; it can only be modified
6078 through direct assignment to another pointer variable or expression that
6079 returned a pointer.)
6080
6081 @item
6082 C escape sequences can be used in strings and characters to represent
6083 non-printable characters. @value{GDBN} will print out strings with these
6084 escape sequences embedded. Single non-printable characters are
6085 printed using the @samp{CHR(@var{nnn})} format.
6086
6087 @item
6088 The assignment operator (@code{:=}) returns the value of its right-hand
6089 argument.
6090
6091 @item
6092 All built-in procedures both modify @emph{and} return their argument.
6093 @end itemize
6094
6095 @node M2 Checks
6096 @subsubsection Modula-2 type and range checks
6097 @cindex Modula-2 checks
6098
6099 @quotation
6100 @emph{Warning:} in this release, @value{GDBN} does not yet perform type or
6101 range checking.
6102 @end quotation
6103 @c FIXME remove warning when type/range checks added
6104
6105 @value{GDBN} considers two Modula-2 variables type equivalent if:
6106
6107 @itemize @bullet
6108 @item
6109 They are of types that have been declared equivalent via a @code{TYPE
6110 @var{t1} = @var{t2}} statement
6111
6112 @item
6113 They have been declared on the same line. (Note: This is true of the
6114 GNU Modula-2 compiler, but it may not be true of other compilers.)
6115 @end itemize
6116
6117 As long as type checking is enabled, any attempt to combine variables
6118 whose types are not equivalent is an error.
6119
6120 Range checking is done on all mathematical operations, assignment, array
6121 index bounds, and all built-in functions and procedures.
6122
6123 @node M2 Scope
6124 @subsubsection The scope operators @code{::} and @code{.}
6125 @cindex scope
6126 @kindex .
6127 @cindex colon, doubled as scope operator
6128 @ifinfo
6129 @kindex colon-colon
6130 @c Info cannot handle :: but TeX can.
6131 @end ifinfo
6132 @iftex
6133 @kindex ::
6134 @end iftex
6135
6136 There are a few subtle differences between the Modula-2 scope operator
6137 (@code{.}) and the @value{GDBN} scope operator (@code{::}). The two have
6138 similar syntax:
6139
6140 @example
6141
6142 @var{module} . @var{id}
6143 @var{scope} :: @var{id}
6144 @end example
6145
6146 @noindent
6147 where @var{scope} is the name of a module or a procedure,
6148 @var{module} the name of a module, and @var{id} is any declared
6149 identifier within your program, except another module.
6150
6151 Using the @code{::} operator makes @value{GDBN} search the scope
6152 specified by @var{scope} for the identifier @var{id}. If it is not
6153 found in the specified scope, then @value{GDBN} will search all scopes
6154 enclosing the one specified by @var{scope}.
6155
6156 Using the @code{.} operator makes @value{GDBN} search the current scope for
6157 the identifier specified by @var{id} that was imported from the
6158 definition module specified by @var{module}. With this operator, it is
6159 an error if the identifier @var{id} was not imported from definition
6160 module @var{module}, or if @var{id} is not an identifier in
6161 @var{module}.
6162
6163 @node GDB/M2
6164 @subsubsection @value{GDBN} and Modula-2
6165
6166 Some @value{GDBN} commands have little use when debugging Modula-2 programs.
6167 Five subcommands of @code{set print} and @code{show print} apply
6168 specifically to C and C++: @samp{vtbl}, @samp{demangle},
6169 @samp{asm-demangle}, @samp{object}, and @samp{union}. The first four
6170 apply to C++, and the last to the C @code{union} type, which has no direct
6171 analogue in Modula-2.
6172
6173 The @code{@@} operator (@pxref{Expressions, ,Expressions}), while available
6174 while using any language, is not useful with Modula-2. Its
6175 intent is to aid the debugging of @dfn{dynamic arrays}, which cannot be
6176 created in Modula-2 as they can in C or C++. However, because an
6177 address can be specified by an integral constant, the construct
6178 @samp{@{@var{type}@}@var{adrexp}} is still useful. (@pxref{Expressions, ,Expressions})
6179
6180 @cindex @code{#} in Modula-2
6181 In @value{GDBN} scripts, the Modula-2 inequality operator @code{#} is
6182 interpreted as the beginning of a comment. Use @code{<>} instead.
6183
6184 @end ifset
6185 @end ifclear
6186
6187 @node Symbols
6188 @chapter Examining the Symbol Table
6189
6190 The commands described in this section allow you to inquire about the
6191 symbols (names of variables, functions and types) defined in your
6192 program. This information is inherent in the text of your program and
6193 does not change as your program executes. @value{GDBN} finds it in your
6194 program's symbol table, in the file indicated when you started @value{GDBN}
6195 (@pxref{File Options, ,Choosing files}), or by one of the
6196 file-management commands (@pxref{Files, ,Commands to specify files}).
6197
6198 @c FIXME! This might be intentionally specific to C and C++; if so, move
6199 @c to someplace in C section of lang chapter.
6200 @cindex symbol names
6201 @cindex names of symbols
6202 @cindex quoting names
6203 Occasionally, you may need to refer to symbols that contain unusual
6204 characters, which @value{GDBN} ordinarily treats as word delimiters. The
6205 most frequent case is in referring to static variables in other
6206 source files (@pxref{Variables,,Program variables}). File names
6207 are recorded in object files as debugging symbols, but @value{GDBN} would
6208 ordinarily parse a typical file name, like @file{foo.c}, as the three words
6209 @samp{foo} @samp{.} @samp{c}. To allow @value{GDBN} to recognize
6210 @samp{foo.c} as a single symbol, enclose it in single quotes; for example,
6211
6212 @example
6213 p 'foo.c'::x
6214 @end example
6215
6216 @noindent
6217 looks up the value of @code{x} in the scope of the file @file{foo.c}.
6218
6219 @table @code
6220 @item info address @var{symbol}
6221 @kindex info address
6222 Describe where the data for @var{symbol} is stored. For a register
6223 variable, this says which register it is kept in. For a non-register
6224 local variable, this prints the stack-frame offset at which the variable
6225 is always stored.
6226
6227 Note the contrast with @samp{print &@var{symbol}}, which does not work
6228 at all for a register variable, and for a stack local variable prints
6229 the exact address of the current instantiation of the variable.
6230
6231 @item whatis @var{exp}
6232 @kindex whatis
6233 Print the data type of expression @var{exp}. @var{exp} is not
6234 actually evaluated, and any side-effecting operations (such as
6235 assignments or function calls) inside it do not take place.
6236 @xref{Expressions, ,Expressions}.
6237
6238 @item whatis
6239 Print the data type of @code{$}, the last value in the value history.
6240
6241 @item ptype @var{typename}
6242 @kindex ptype
6243 Print a description of data type @var{typename}. @var{typename} may be
6244 the name of a type, or for C code it may have the form
6245 @ifclear CONLY
6246 @samp{class @var{class-name}},
6247 @end ifclear
6248 @samp{struct @var{struct-tag}}, @samp{union @var{union-tag}} or
6249 @samp{enum @var{enum-tag}}.
6250
6251 @item ptype @var{exp}
6252 @itemx ptype
6253 Print a description of the type of expression @var{exp}. @code{ptype}
6254 differs from @code{whatis} by printing a detailed description, instead
6255 of just the name of the type.
6256
6257 For example, for this variable declaration:
6258
6259 @example
6260 struct complex @{double real; double imag;@} v;
6261 @end example
6262
6263 @noindent
6264 the two commands give this output:
6265
6266 @example
6267 @group
6268 (@value{GDBP}) whatis v
6269 type = struct complex
6270 (@value{GDBP}) ptype v
6271 type = struct complex @{
6272 double real;
6273 double imag;
6274 @}
6275 @end group
6276 @end example
6277
6278 @noindent
6279 As with @code{whatis}, using @code{ptype} without an argument refers to
6280 the type of @code{$}, the last value in the value history.
6281
6282 @item info types @var{regexp}
6283 @itemx info types
6284 @kindex info types
6285 Print a brief description of all types whose name matches @var{regexp}
6286 (or all types in your program, if you supply no argument). Each
6287 complete typename is matched as though it were a complete line; thus,
6288 @samp{i type value} gives information on all types in your program whose
6289 name includes the string @code{value}, but @samp{i type ^value$} gives
6290 information only on types whose complete name is @code{value}.
6291
6292 This command differs from @code{ptype} in two ways: first, like
6293 @code{whatis}, it does not print a detailed description; second, it
6294 lists all source files where a type is defined.
6295
6296 @item info source
6297 @kindex info source
6298 Show the name of the current source file---that is, the source file for
6299 the function containing the current point of execution---and the language
6300 it was written in.
6301
6302 @item info sources
6303 @kindex info sources
6304 Print the names of all source files in your program for which there is
6305 debugging information, organized into two lists: files whose symbols
6306 have already been read, and files whose symbols will be read when needed.
6307
6308 @item info functions
6309 @kindex info functions
6310 Print the names and data types of all defined functions.
6311
6312 @item info functions @var{regexp}
6313 Print the names and data types of all defined functions
6314 whose names contain a match for regular expression @var{regexp}.
6315 Thus, @samp{info fun step} finds all functions whose names
6316 include @code{step}; @samp{info fun ^step} finds those whose names
6317 start with @code{step}.
6318
6319 @item info variables
6320 @kindex info variables
6321 Print the names and data types of all variables that are declared
6322 outside of functions (i.e., excluding local variables).
6323
6324 @item info variables @var{regexp}
6325 Print the names and data types of all variables (except for local
6326 variables) whose names contain a match for regular expression
6327 @var{regexp}.
6328
6329 @ignore
6330 This was never implemented.
6331 @item info methods
6332 @itemx info methods @var{regexp}
6333 @kindex info methods
6334 The @code{info methods} command permits the user to examine all defined
6335 methods within C++ program, or (with the @var{regexp} argument) a
6336 specific set of methods found in the various C++ classes. Many
6337 C++ classes provide a large number of methods. Thus, the output
6338 from the @code{ptype} command can be overwhelming and hard to use. The
6339 @code{info-methods} command filters the methods, printing only those
6340 which match the regular-expression @var{regexp}.
6341 @end ignore
6342
6343 @item maint print symbols @var{filename}
6344 @itemx maint print psymbols @var{filename}
6345 @itemx maint print msymbols @var{filename}
6346 @kindex maint print symbols
6347 @cindex symbol dump
6348 @kindex maint print psymbols
6349 @cindex partial symbol dump
6350 Write a dump of debugging symbol data into the file @var{filename}.
6351 These commands are used to debug the @value{GDBN} symbol-reading code. Only
6352 symbols with debugging data are included. If you use @samp{maint print
6353 symbols}, @value{GDBN} includes all the symbols for which it has already
6354 collected full details: that is, @var{filename} reflects symbols for
6355 only those files whose symbols @value{GDBN} has read. You can use the
6356 command @code{info sources} to find out which files these are. If you
6357 use @samp{maint print psymbols} instead, the dump shows information about
6358 symbols that @value{GDBN} only knows partially---that is, symbols defined in
6359 files that @value{GDBN} has skimmed, but not yet read completely. Finally,
6360 @samp{maint print msymbols} dumps just the minimal symbol information
6361 required for each object file from which @value{GDBN} has read some symbols.
6362 @xref{Files, ,Commands to specify files}, for a discussion of how
6363 @value{GDBN} reads symbols (in the description of @code{symbol-file}).
6364 @end table
6365
6366 @node Altering
6367 @chapter Altering Execution
6368
6369 Once you think you have found an error in your program, you might want to
6370 find out for certain whether correcting the apparent error would lead to
6371 correct results in the rest of the run. You can find the answer by
6372 experiment, using the @value{GDBN} features for altering execution of the
6373 program.
6374
6375 For example, you can store new values into variables or memory
6376 locations,
6377 @ifclear BARETARGET
6378 give your program a signal, restart it
6379 @end ifclear
6380 @ifset BARETARGET
6381 restart your program
6382 @end ifset
6383 at a different address, or even return prematurely from a function to
6384 its caller.
6385
6386 @menu
6387 * Assignment:: Assignment to variables
6388 * Jumping:: Continuing at a different address
6389 @ifclear BARETARGET
6390 * Signaling:: Giving your program a signal
6391 @end ifclear
6392
6393 * Returning:: Returning from a function
6394 * Calling:: Calling your program's functions
6395 * Patching:: Patching your program
6396 @end menu
6397
6398 @node Assignment
6399 @section Assignment to variables
6400
6401 @cindex assignment
6402 @cindex setting variables
6403 To alter the value of a variable, evaluate an assignment expression.
6404 @xref{Expressions, ,Expressions}. For example,
6405
6406 @example
6407 print x=4
6408 @end example
6409
6410 @noindent
6411 stores the value 4 into the variable @code{x}, and then prints the
6412 value of the assignment expression (which is 4).
6413 @ifclear CONLY
6414 @xref{Languages, ,Using @value{GDBN} with Different Languages}, for more
6415 information on operators in supported languages.
6416 @end ifclear
6417
6418 @kindex set variable
6419 @cindex variables, setting
6420 If you are not interested in seeing the value of the assignment, use the
6421 @code{set} command instead of the @code{print} command. @code{set} is
6422 really the same as @code{print} except that the expression's value is
6423 not printed and is not put in the value history (@pxref{Value History,
6424 ,Value history}). The expression is evaluated only for its effects.
6425
6426 If the beginning of the argument string of the @code{set} command
6427 appears identical to a @code{set} subcommand, use the @code{set
6428 variable} command instead of just @code{set}. This command is identical
6429 to @code{set} except for its lack of subcommands. For example, if
6430 your program has a variable @code{width}, you get
6431 an error if you try to set a new value with just @samp{set width=13},
6432 because @value{GDBN} has the command @code{set width}:
6433
6434 @example
6435 (@value{GDBP}) whatis width
6436 type = double
6437 (@value{GDBP}) p width
6438 $4 = 13
6439 (@value{GDBP}) set width=47
6440 Invalid syntax in expression.
6441 @end example
6442
6443 @noindent
6444 The invalid expression, of course, is @samp{=47}. In
6445 order to actually set the program's variable @code{width}, use
6446
6447 @example
6448 (@value{GDBP}) set var width=47
6449 @end example
6450
6451 @value{GDBN} allows more implicit conversions in assignments than C; you can
6452 freely store an integer value into a pointer variable or vice versa,
6453 and you can convert any structure to any other structure that is the
6454 same length or shorter.
6455 @comment FIXME: how do structs align/pad in these conversions?
6456 @comment /pesch@cygnus.com 18dec1990
6457
6458 To store values into arbitrary places in memory, use the @samp{@{@dots{}@}}
6459 construct to generate a value of specified type at a specified address
6460 (@pxref{Expressions, ,Expressions}). For example, @code{@{int@}0x83040} refers
6461 to memory location @code{0x83040} as an integer (which implies a certain size
6462 and representation in memory), and
6463
6464 @example
6465 set @{int@}0x83040 = 4
6466 @end example
6467
6468 @noindent
6469 stores the value 4 into that memory location.
6470
6471 @node Jumping
6472 @section Continuing at a different address
6473
6474 Ordinarily, when you continue your program, you do so at the place where
6475 it stopped, with the @code{continue} command. You can instead continue at
6476 an address of your own choosing, with the following commands:
6477
6478 @table @code
6479 @item jump @var{linespec}
6480 @kindex jump
6481 Resume execution at line @var{linespec}. Execution will stop
6482 immediately if there is a breakpoint there. @xref{List, ,Printing
6483 source lines}, for a description of the different forms of
6484 @var{linespec}.
6485
6486 The @code{jump} command does not change the current stack frame, or
6487 the stack pointer, or the contents of any memory location or any
6488 register other than the program counter. If line @var{linespec} is in
6489 a different function from the one currently executing, the results may
6490 be bizarre if the two functions expect different patterns of arguments or
6491 of local variables. For this reason, the @code{jump} command requests
6492 confirmation if the specified line is not in the function currently
6493 executing. However, even bizarre results are predictable if you are
6494 well acquainted with the machine-language code of your program.
6495
6496 @item jump *@var{address}
6497 Resume execution at the instruction at address @var{address}.
6498 @end table
6499
6500 You can get much the same effect as the @code{jump} command by storing a
6501 new value into the register @code{$pc}. The difference is that this
6502 does not start your program running; it only changes the address where it
6503 @emph{will} run when it is continued. For example,
6504
6505 @example
6506 set $pc = 0x485
6507 @end example
6508
6509 @noindent
6510 causes the next @code{continue} command or stepping command to execute at
6511 address @code{0x485}, rather than at the address where your program stopped.
6512 @xref{Continuing and Stepping, ,Continuing and stepping}.
6513
6514 The most common occasion to use the @code{jump} command is to back up,
6515 perhaps with more breakpoints set, over a portion of a program that has
6516 already executed, in order to examine its execution in more detail.
6517
6518 @ifclear BARETARGET
6519 @c @group
6520 @node Signaling
6521 @section Giving your program a signal
6522
6523 @table @code
6524 @item signal @var{signal}
6525 @kindex signal
6526 Resume execution where your program stopped, but immediately give it the
6527 signal @var{signal}. @var{signal} can be the name or the number of a
6528 signal. For example, on many systems @code{signal 2} and @code{signal
6529 SIGINT} are both ways of sending an interrupt signal.
6530
6531 Alternatively, if @var{signal} is zero, continue execution without
6532 giving a signal. This is useful when your program stopped on account of
6533 a signal and would ordinary see the signal when resumed with the
6534 @code{continue} command; @samp{signal 0} causes it to resume without a
6535 signal.
6536
6537 @code{signal} does not repeat when you press @key{RET} a second time
6538 after executing the command.
6539 @end table
6540 @c @end group
6541
6542 Invoking the @code{signal} command is not the same as invoking the
6543 @code{kill} utility from the shell. Sending a signal with @code{kill}
6544 causes @value{GDBN} to decide what to do with the signal depending on
6545 the signal handling tables (@pxref{Signals}). The @code{signal} command
6546 passes the signal directly to your program.
6547
6548 @end ifclear
6549
6550 @node Returning
6551 @section Returning from a function
6552
6553 @table @code
6554 @item return
6555 @itemx return @var{expression}
6556 @cindex returning from a function
6557 @kindex return
6558 You can cancel execution of a function call with the @code{return}
6559 command. If you give an
6560 @var{expression} argument, its value is used as the function's return
6561 value.
6562 @end table
6563
6564 When you use @code{return}, @value{GDBN} discards the selected stack frame
6565 (and all frames within it). You can think of this as making the
6566 discarded frame return prematurely. If you wish to specify a value to
6567 be returned, give that value as the argument to @code{return}.
6568
6569 This pops the selected stack frame (@pxref{Selection, ,Selecting a
6570 frame}), and any other frames inside of it, leaving its caller as the
6571 innermost remaining frame. That frame becomes selected. The
6572 specified value is stored in the registers used for returning values
6573 of functions.
6574
6575 The @code{return} command does not resume execution; it leaves the
6576 program stopped in the state that would exist if the function had just
6577 returned. In contrast, the @code{finish} command (@pxref{Continuing
6578 and Stepping, ,Continuing and stepping}) resumes execution until the
6579 selected stack frame returns naturally.
6580
6581 @node Calling
6582 @section Calling program functions
6583
6584 @cindex calling functions
6585 @kindex call
6586 @table @code
6587 @item call @var{expr}
6588 Evaluate the expression @var{expr} without displaying @code{void}
6589 returned values.
6590 @end table
6591
6592 You can use this variant of the @code{print} command if you want to
6593 execute a function from your program, but without cluttering the output
6594 with @code{void} returned values. The result is printed and saved in
6595 the value history, if it is not void.
6596
6597 @node Patching
6598 @section Patching programs
6599 @cindex patching binaries
6600 @cindex writing into executables
6601 @ifclear BARETARGET
6602 @cindex writing into corefiles
6603 @end ifclear
6604
6605 By default, @value{GDBN} opens the file containing your program's executable
6606 code
6607 @ifclear BARETARGET
6608 (or the corefile)
6609 @end ifclear
6610 read-only. This prevents accidental alterations
6611 to machine code; but it also prevents you from intentionally patching
6612 your program's binary.
6613
6614 If you'd like to be able to patch the binary, you can specify that
6615 explicitly with the @code{set write} command. For example, you might
6616 want to turn on internal debugging flags, or even to make emergency
6617 repairs.
6618
6619 @table @code
6620 @item set write on
6621 @itemx set write off
6622 @kindex set write
6623 If you specify @samp{set write on}, @value{GDBN} will open executable
6624 @ifclear BARETARGET
6625 and core
6626 @end ifclear
6627 files for both reading and writing; if you specify @samp{set write
6628 off} (the default), @value{GDBN} will open them read-only.
6629
6630 If you have already loaded a file, you must load it again (using the
6631 @code{exec-file}
6632 @ifclear BARETARGET
6633 or @code{core-file}
6634 @end ifclear
6635 command) after changing @code{set write}, for your new setting to take
6636 effect.
6637
6638 @item show write
6639 @kindex show write
6640 Display whether executable files
6641 @ifclear BARETARGET
6642 and core files
6643 @end ifclear
6644 will be opened for writing as well as reading.
6645 @end table
6646
6647 @node GDB Files
6648 @chapter @value{GDBN} Files
6649
6650 @value{GDBN} needs to know the file name of the program to be debugged, both in
6651 order to read its symbol table and in order to start your program.
6652 @ifclear BARETARGET
6653 To debug a core dump of a previous run, you must also tell @value{GDBN}
6654 the name of the core dump file.
6655 @end ifclear
6656
6657 @menu
6658 * Files:: Commands to specify files
6659 * Symbol Errors:: Errors reading symbol files
6660 @end menu
6661
6662 @node Files
6663 @section Commands to specify files
6664 @cindex symbol table
6665
6666 @ifclear BARETARGET
6667 @cindex core dump file
6668 The usual way to specify executable and core dump file names is with
6669 the command arguments given when you start @value{GDBN} (@pxref{Invocation,
6670 ,Getting In and Out of @value{GDBN}}.
6671 @end ifclear
6672 @ifset BARETARGET
6673 The usual way to specify an executable file name is with
6674 the command argument given when you start @value{GDBN}, (@pxref{Invocation,
6675 ,Getting In and Out of @value{GDBN}}.
6676 @end ifset
6677
6678 Occasionally it is necessary to change to a different file during a
6679 @value{GDBN} session. Or you may run @value{GDBN} and forget to specify
6680 a file you want to use. In these situations the @value{GDBN} commands
6681 to specify new files are useful.
6682
6683 @table @code
6684 @item file @var{filename}
6685 @cindex executable file
6686 @kindex file
6687 Use @var{filename} as the program to be debugged. It is read for its
6688 symbols and for the contents of pure memory. It is also the program
6689 executed when you use the @code{run} command. If you do not specify a
6690 directory and the file is not found in the @value{GDBN} working directory, @value{GDBN}
6691 uses the environment variable @code{PATH} as a list of directories to
6692 search, just as the shell does when looking for a program to run. You
6693 can change the value of this variable, for both @value{GDBN} and your program,
6694 using the @code{path} command.
6695
6696 On systems with memory-mapped files, an auxiliary symbol table file
6697 @file{@var{filename}.syms} may be available for @var{filename}. If it
6698 is, @value{GDBN} will map in the symbol table from
6699 @file{@var{filename}.syms}, starting up more quickly. See the
6700 descriptions of the options @samp{-mapped} and @samp{-readnow} (available
6701 on the command line, and with the commands @code{file}, @code{symbol-file},
6702 or @code{add-symbol-file}), for more information.
6703
6704 @item file
6705 @code{file} with no argument makes @value{GDBN} discard any information it
6706 has on both executable file and the symbol table.
6707
6708 @item exec-file @r{[} @var{filename} @r{]}
6709 @kindex exec-file
6710 Specify that the program to be run (but not the symbol table) is found
6711 in @var{filename}. @value{GDBN} will search the environment variable @code{PATH}
6712 if necessary to locate your program. Omitting @var{filename} means to
6713 discard information on the executable file.
6714
6715 @item symbol-file @r{[} @var{filename} @r{]}
6716 @kindex symbol-file
6717 Read symbol table information from file @var{filename}. @code{PATH} is
6718 searched when necessary. Use the @code{file} command to get both symbol
6719 table and program to run from the same file.
6720
6721 @code{symbol-file} with no argument clears out @value{GDBN} information on your
6722 program's symbol table.
6723
6724 The @code{symbol-file} command causes @value{GDBN} to forget the contents of its
6725 convenience variables, the value history, and all breakpoints and
6726 auto-display expressions. This is because they may contain pointers to
6727 the internal data recording symbols and data types, which are part of
6728 the old symbol table data being discarded inside @value{GDBN}.
6729
6730 @code{symbol-file} will not repeat if you press @key{RET} again after
6731 executing it once.
6732
6733 When @value{GDBN} is configured for a particular environment, it will
6734 understand debugging information in whatever format is the standard
6735 generated for that environment; you may use either a GNU compiler, or
6736 other compilers that adhere to the local conventions. Best results are
6737 usually obtained from GNU compilers; for example, using @code{@value{GCC}}
6738 you can generate debugging information for optimized code.
6739
6740 On some kinds of object files, the @code{symbol-file} command does not
6741 normally read the symbol table in full right away. Instead, it scans
6742 the symbol table quickly to find which source files and which symbols
6743 are present. The details are read later, one source file at a time,
6744 as they are needed.
6745
6746 The purpose of this two-stage reading strategy is to make @value{GDBN} start up
6747 faster. For the most part, it is invisible except for occasional
6748 pauses while the symbol table details for a particular source file are
6749 being read. (The @code{set verbose} command can turn these pauses
6750 into messages if desired. @xref{Messages/Warnings, ,Optional warnings
6751 and messages}.)
6752
6753 We have not implemented the two-stage strategy for COFF yet. When the
6754 symbol table is stored in COFF format, @code{symbol-file} reads the
6755 symbol table data in full right away.
6756
6757 @item symbol-file @var{filename} @r{[} -readnow @r{]} @r{[} -mapped @r{]}
6758 @itemx file @var{filename} @r{[} -readnow @r{]} @r{[} -mapped @r{]}
6759 @kindex readnow
6760 @cindex reading symbols immediately
6761 @cindex symbols, reading immediately
6762 @kindex mapped
6763 @cindex memory-mapped symbol file
6764 @cindex saving symbol table
6765 You can override the @value{GDBN} two-stage strategy for reading symbol
6766 tables by using the @samp{-readnow} option with any of the commands that
6767 load symbol table information, if you want to be sure @value{GDBN} has the
6768 entire symbol table available.
6769
6770 @ifclear BARETARGET
6771 If memory-mapped files are available on your system through the
6772 @code{mmap} system call, you can use another option, @samp{-mapped}, to
6773 cause @value{GDBN} to write the symbols for your program into a reusable
6774 file. Future @value{GDBN} debugging sessions will map in symbol information
6775 from this auxiliary symbol file (if the program has not changed), rather
6776 than spending time reading the symbol table from the executable
6777 program. Using the @samp{-mapped} option has the same effect as
6778 starting @value{GDBN} with the @samp{-mapped} command-line option.
6779
6780 You can use both options together, to make sure the auxiliary symbol
6781 file has all the symbol information for your program.
6782
6783 The auxiliary symbol file for a program called @var{myprog} is called
6784 @samp{@var{myprog}.syms}. Once this file exists (so long as it is newer
6785 than the corresponding executable), @value{GDBN} will always attempt to use
6786 it when you debug @var{myprog}; no special options or commands are
6787 needed.
6788
6789 The @file{.syms} file is specific to the host machine where you run
6790 @value{GDBN}. It holds an exact image of the internal @value{GDBN}
6791 symbol table. It cannot be shared across multiple host platforms.
6792
6793 @c FIXME: for now no mention of directories, since this seems to be in
6794 @c flux. 13mar1992 status is that in theory GDB would look either in
6795 @c current dir or in same dir as myprog; but issues like competing
6796 @c GDB's, or clutter in system dirs, mean that in practice right now
6797 @c only current dir is used. FFish says maybe a special GDB hierarchy
6798 @c (eg rooted in val of env var GDBSYMS) could exist for mappable symbol
6799 @c files.
6800
6801 @item core-file @r{[} @var{filename} @r{]}
6802 @kindex core
6803 @kindex core-file
6804 Specify the whereabouts of a core dump file to be used as the ``contents
6805 of memory''. Traditionally, core files contain only some parts of the
6806 address space of the process that generated them; @value{GDBN} can access the
6807 executable file itself for other parts.
6808
6809 @code{core-file} with no argument specifies that no core file is
6810 to be used.
6811
6812 Note that the core file is ignored when your program is actually running
6813 under @value{GDBN}. So, if you have been running your program and you wish to
6814 debug a core file instead, you must kill the subprocess in which the
6815 program is running. To do this, use the @code{kill} command
6816 (@pxref{Kill Process, ,Killing the child process}).
6817 @end ifclear
6818
6819 @item load @var{filename}
6820 @kindex load
6821 @ifset GENERIC
6822 Depending on what remote debugging facilities are configured into
6823 @value{GDBN}, the @code{load} command may be available. Where it exists, it
6824 is meant to make @var{filename} (an executable) available for debugging
6825 on the remote system---by downloading, or dynamic linking, for example.
6826 @code{load} also records the @var{filename} symbol table in @value{GDBN}, like
6827 the @code{add-symbol-file} command.
6828
6829 If your @value{GDBN} does not have a @code{load} command, attempting to
6830 execute it gets the error message ``@code{You can't do that when your
6831 target is @dots{}}''
6832 @end ifset
6833
6834 The file is loaded at whatever address is specified in the executable.
6835 For some object file formats, you can specify the load address when you
6836 link the program; for other formats, like a.out, the object file format
6837 specifies a fixed address.
6838 @c FIXME! This would be a good place for an xref to the GNU linker doc.
6839
6840 @ifset VXWORKS
6841 On VxWorks, @code{load} will dynamically link @var{filename} on the
6842 current target system as well as adding its symbols in @value{GDBN}.
6843 @end ifset
6844
6845 @ifset I960
6846 @cindex download to Nindy-960
6847 With the Nindy interface to an Intel 960 board, @code{load} will
6848 download @var{filename} to the 960 as well as adding its symbols in
6849 @value{GDBN}.
6850 @end ifset
6851
6852 @ifset H8
6853 @cindex download to H8/300 or H8/500
6854 @cindex H8/300 or H8/500 download
6855 @cindex download to Hitachi SH
6856 @cindex Hitachi SH download
6857 When you select remote debugging to a Hitachi SH, H8/300, or H8/500 board
6858 (@pxref{Hitachi Remote,,@value{GDBN} and Hitachi Microprocessors}),
6859 the @code{load} command downloads your program to the Hitachi board and also
6860 opens it as the current executable target for @value{GDBN} on your host
6861 (like the @code{file} command).
6862 @end ifset
6863
6864 @code{load} will not repeat if you press @key{RET} again after using it.
6865
6866 @ifclear BARETARGET
6867 @item add-symbol-file @var{filename} @var{address}
6868 @itemx add-symbol-file @var{filename} @var{address} @r{[} -readnow @r{]} @r{[} -mapped @r{]}
6869 @kindex add-symbol-file
6870 @cindex dynamic linking
6871 The @code{add-symbol-file} command reads additional symbol table information
6872 from the file @var{filename}. You would use this command when @var{filename}
6873 has been dynamically loaded (by some other means) into the program that
6874 is running. @var{address} should be the memory address at which the
6875 file has been loaded; @value{GDBN} cannot figure this out for itself.
6876 You can specify @var{address} as an expression.
6877
6878 The symbol table of the file @var{filename} is added to the symbol table
6879 originally read with the @code{symbol-file} command. You can use the
6880 @code{add-symbol-file} command any number of times; the new symbol data thus
6881 read keeps adding to the old. To discard all old symbol data instead,
6882 use the @code{symbol-file} command.
6883
6884 @code{add-symbol-file} will not repeat if you press @key{RET} after using it.
6885
6886 You can use the @samp{-mapped} and @samp{-readnow} options just as with
6887 the @code{symbol-file} command, to change how @value{GDBN} manages the symbol
6888 table information for @var{filename}.
6889 @end ifclear
6890
6891 @item info files
6892 @itemx info target
6893 @kindex info files
6894 @kindex info target
6895 @code{info files} and @code{info target} are synonymous; both print
6896 the current target (@pxref{Targets, ,Specifying a Debugging Target}),
6897 including the
6898 @ifclear BARETARGET
6899 names of the executable and core dump files
6900 @end ifclear
6901 @ifset BARETARGET
6902 name of the executable file
6903 @end ifset
6904 currently in use by @value{GDBN}, and the files from which symbols were
6905 loaded. The command @code{help targets} lists all possible targets
6906 rather than current ones.
6907 @end table
6908
6909 All file-specifying commands allow both absolute and relative file names
6910 as arguments. @value{GDBN} always converts the file name to an absolute path
6911 name and remembers it that way.
6912
6913 @ifclear BARETARGET
6914 @cindex shared libraries
6915 @value{GDBN} supports SunOS, SVR4, and IBM RS/6000 shared libraries.
6916 @value{GDBN} automatically loads symbol definitions from shared libraries
6917 when you use the @code{run} command, or when you examine a core file.
6918 (Before you issue the @code{run} command, @value{GDBN} will not understand
6919 references to a function in a shared library, however---unless you are
6920 debugging a core file).
6921 @c FIXME: next @value{GDBN} release should permit some refs to undef
6922 @c FIXME...symbols---eg in a break cmd---assuming they are from a shared lib
6923
6924 @table @code
6925 @item info share
6926 @itemx info sharedlibrary
6927 @kindex info sharedlibrary
6928 @kindex info share
6929 Print the names of the shared libraries which are currently loaded.
6930
6931 @item sharedlibrary @var{regex}
6932 @itemx share @var{regex}
6933 @kindex sharedlibrary
6934 @kindex share
6935 This is an obsolescent command; you can use it to explicitly load shared
6936 object library symbols for files matching a Unix regular expression, but
6937 as with files loaded automatically, it will only load shared libraries
6938 required by your program for a core file or after typing @code{run}. If
6939 @var{regex} is omitted all shared libraries required by your program are
6940 loaded.
6941 @end table
6942 @end ifclear
6943
6944 @node Symbol Errors
6945 @section Errors reading symbol files
6946
6947 While reading a symbol file, @value{GDBN} will occasionally encounter problems,
6948 such as symbol types it does not recognize, or known bugs in compiler
6949 output. By default, @value{GDBN} does not notify you of such problems, since
6950 they are relatively common and primarily of interest to people
6951 debugging compilers. If you are interested in seeing information
6952 about ill-constructed symbol tables, you can either ask @value{GDBN} to print
6953 only one message about each such type of problem, no matter how many
6954 times the problem occurs; or you can ask @value{GDBN} to print more messages,
6955 to see how many times the problems occur, with the @code{set
6956 complaints} command (@pxref{Messages/Warnings, ,Optional warnings and
6957 messages}).
6958
6959 The messages currently printed, and their meanings, include:
6960
6961 @table @code
6962 @item inner block not inside outer block in @var{symbol}
6963
6964 The symbol information shows where symbol scopes begin and end
6965 (such as at the start of a function or a block of statements). This
6966 error indicates that an inner scope block is not fully contained
6967 in its outer scope blocks.
6968
6969 @value{GDBN} circumvents the problem by treating the inner block as if it had
6970 the same scope as the outer block. In the error message, @var{symbol}
6971 may be shown as ``@code{(don't know)}'' if the outer block is not a
6972 function.
6973
6974 @item block at @var{address} out of order
6975
6976 The symbol information for symbol scope blocks should occur in
6977 order of increasing addresses. This error indicates that it does not
6978 do so.
6979
6980 @value{GDBN} does not circumvent this problem, and will have trouble
6981 locating symbols in the source file whose symbols it is reading. (You
6982 can often determine what source file is affected by specifying
6983 @code{set verbose on}. @xref{Messages/Warnings, ,Optional warnings and
6984 messages}.)
6985
6986 @item bad block start address patched
6987
6988 The symbol information for a symbol scope block has a start address
6989 smaller than the address of the preceding source line. This is known
6990 to occur in the SunOS 4.1.1 (and earlier) C compiler.
6991
6992 @value{GDBN} circumvents the problem by treating the symbol scope block as
6993 starting on the previous source line.
6994
6995 @item bad string table offset in symbol @var{n}
6996
6997 @cindex foo
6998 Symbol number @var{n} contains a pointer into the string table which is
6999 larger than the size of the string table.
7000
7001 @value{GDBN} circumvents the problem by considering the symbol to have the
7002 name @code{foo}, which may cause other problems if many symbols end up
7003 with this name.
7004
7005 @item unknown symbol type @code{0x@var{nn}}
7006
7007 The symbol information contains new data types that @value{GDBN} does not yet
7008 know how to read. @code{0x@var{nn}} is the symbol type of the misunderstood
7009 information, in hexadecimal.
7010
7011 @value{GDBN} circumvents the error by ignoring this symbol information. This
7012 will usually allow your program to be debugged, though certain symbols
7013 will not be accessible. If you encounter such a problem and feel like
7014 debugging it, you can debug @code{@value{GDBP}} with itself, breakpoint on
7015 @code{complain}, then go up to the function @code{read_dbx_symtab} and
7016 examine @code{*bufp} to see the symbol.
7017
7018 @item stub type has NULL name
7019 @value{GDBN} could not find the full definition for
7020 @ifclear CONLY
7021 a struct or class.
7022 @end ifclear
7023 @ifset CONLY
7024 a struct.
7025 @end ifset
7026
7027 @ifclear CONLY
7028 @item const/volatile indicator missing (ok if using g++ v1.x), got@dots{}
7029
7030 The symbol information for a C++ member function is missing some
7031 information that recent versions of the compiler should have output
7032 for it.
7033 @end ifclear
7034
7035 @item info mismatch between compiler and debugger
7036
7037 @value{GDBN} could not parse a type specification output by the compiler.
7038 @end table
7039
7040 @node Targets
7041 @chapter Specifying a Debugging Target
7042 @cindex debugging target
7043 @kindex target
7044
7045 A @dfn{target} is the execution environment occupied by your program.
7046 @ifclear BARETARGET
7047 Often, @value{GDBN} runs in the same host environment as your program; in
7048 that case, the debugging target is specified as a side effect when you
7049 use the @code{file} or @code{core} commands. When you need more
7050 flexibility---for example, running @value{GDBN} on a physically separate
7051 host, or controlling a standalone system over a serial port or a
7052 realtime system over a TCP/IP connection---you
7053 @end ifclear
7054 @ifset BARETARGET
7055 You
7056 @end ifset
7057 can use the @code{target} command to specify one of the target types
7058 configured for @value{GDBN} (@pxref{Target Commands, ,Commands for managing
7059 targets}).
7060
7061 @menu
7062 * Active Targets:: Active targets
7063 * Target Commands:: Commands for managing targets
7064 * Remote:: Remote debugging
7065 @end menu
7066
7067 @node Active Targets
7068 @section Active targets
7069 @cindex stacking targets
7070 @cindex active targets
7071 @cindex multiple targets
7072
7073 @ifclear BARETARGET
7074 There are three classes of targets: processes, core files, and
7075 executable files. @value{GDBN} can work concurrently on up to three active
7076 targets, one in each class. This allows you to (for example) start a
7077 process and inspect its activity without abandoning your work on a core
7078 file.
7079
7080 For example, if you execute @samp{gdb a.out}, then the executable file
7081 @code{a.out} is the only active target. If you designate a core file as
7082 well---presumably from a prior run that crashed and coredumped---then
7083 @value{GDBN} has two active targets and will use them in tandem, looking
7084 first in the corefile target, then in the executable file, to satisfy
7085 requests for memory addresses. (Typically, these two classes of target
7086 are complementary, since core files contain only a program's
7087 read-write memory---variables and so on---plus machine status, while
7088 executable files contain only the program text and initialized data.)
7089 @end ifclear
7090
7091 When you type @code{run}, your executable file becomes an active process
7092 target as well. When a process target is active, all @value{GDBN} commands
7093 requesting memory addresses refer to that target; addresses in an
7094 @ifclear BARETARGET
7095 active core file or
7096 @end ifclear
7097 executable file target are obscured while the process
7098 target is active.
7099
7100 @ifset BARETARGET
7101 Use the @code{exec-file} command to select a
7102 new executable target (@pxref{Files, ,Commands to specify
7103 files}).
7104 @end ifset
7105 @ifclear BARETARGET
7106 Use the @code{core-file} and @code{exec-file} commands to select a
7107 new core file or executable target (@pxref{Files, ,Commands to specify
7108 files}). To specify as a target a process that is already running, use
7109 the @code{attach} command (@pxref{Attach, ,Debugging an
7110 already-running process}).
7111 @end ifclear
7112
7113 @node Target Commands
7114 @section Commands for managing targets
7115
7116 @table @code
7117 @item target @var{type} @var{parameters}
7118 Connects the @value{GDBN} host environment to a target
7119 @ifset BARETARGET
7120 machine.
7121 @end ifset
7122 @ifclear BARETARGET
7123 machine or process. A target is typically a protocol for talking to
7124 debugging facilities. You use the argument @var{type} to specify the
7125 type or protocol of the target machine.
7126
7127 Further @var{parameters} are interpreted by the target protocol, but
7128 typically include things like device names or host names to connect
7129 with, process numbers, and baud rates.
7130 @end ifclear
7131
7132 The @code{target} command will not repeat if you press @key{RET} again
7133 after executing the command.
7134
7135 @item help target
7136 @kindex help target
7137 Displays the names of all targets available. To display targets
7138 currently selected, use either @code{info target} or @code{info files}
7139 (@pxref{Files, ,Commands to specify files}).
7140
7141 @item help target @var{name}
7142 Describe a particular target, including any parameters necessary to
7143 select it.
7144 @end table
7145
7146 Here are some common targets (available, or not, depending on the GDB
7147 configuration):
7148
7149 @table @code
7150 @item target exec @var{program}
7151 @kindex target exec
7152 An executable file. @samp{target exec @var{program}} is the same as
7153 @samp{exec-file @var{program}}.
7154
7155 @ifclear BARETARGET
7156 @item target core @var{filename}
7157 @kindex target core
7158 A core dump file. @samp{target core @var{filename}} is the same as
7159 @samp{core-file @var{filename}}.
7160 @end ifclear
7161
7162 @ifset REMOTESTUB
7163 @item target remote @var{dev}
7164 @kindex target remote
7165 Remote serial target in GDB-specific protocol. The argument @var{dev}
7166 specifies what serial device to use for the connection (e.g.
7167 @file{/dev/ttya}). @xref{Remote, ,Remote debugging}.
7168 @end ifset
7169
7170 @ifset SIMS
7171 @item target sim
7172 @kindex target sim
7173 CPU simulator. @xref{Simulator,,Simulated CPU Target}.
7174 @end ifset
7175
7176 @ifset AMD29K
7177 @item target udi @var{keyword}
7178 @kindex target udi
7179 Remote AMD29K target, using the AMD UDI protocol. The @var{keyword}
7180 argument specifies which 29K board or simulator to use. @xref{UDI29K
7181 Remote,,@value{GDBN} and the UDI protocol for AMD29K}.
7182
7183 @item target amd-eb @var{dev} @var{speed} @var{PROG}
7184 @kindex target amd-eb
7185 @cindex AMD EB29K
7186 Remote PC-resident AMD EB29K board, attached over serial lines.
7187 @var{dev} is the serial device, as for @code{target remote};
7188 @var{speed} allows you to specify the linespeed; and @var{PROG} is the
7189 name of the program to be debugged, as it appears to DOS on the PC.
7190 @xref{EB29K Remote, ,@value{GDBN} with a remote EB29K}.
7191
7192 @end ifset
7193 @ifset H8
7194 @item target hms
7195 @kindex target hms
7196 A Hitachi SH, H8/300, or H8/500 board, attached via serial line to your host.
7197 @ifclear H8EXCLUSIVE
7198 @c Unix only, not currently of interest for H8-only manual
7199 Use special commands @code{device} and @code{speed} to control the serial
7200 line and the communications speed used.
7201 @end ifclear
7202 @xref{Hitachi Remote,,@value{GDBN} and Hitachi Microprocessors}.
7203
7204 @end ifset
7205 @ifset I960
7206 @item target nindy @var{devicename}
7207 @kindex target nindy
7208 An Intel 960 board controlled by a Nindy Monitor. @var{devicename} is
7209 the name of the serial device to use for the connection, e.g.
7210 @file{/dev/ttya}. @xref{i960-Nindy Remote, ,@value{GDBN} with a remote i960 (Nindy)}.
7211
7212 @end ifset
7213 @ifset ST2000
7214 @item target st2000 @var{dev} @var{speed}
7215 @kindex target st2000
7216 A Tandem ST2000 phone switch, running Tandem's STDBUG protocol. @var{dev}
7217 is the name of the device attached to the ST2000 serial line;
7218 @var{speed} is the communication line speed. The arguments are not used
7219 if @value{GDBN} is configured to connect to the ST2000 using TCP or Telnet.
7220 @xref{ST2000 Remote,,@value{GDBN} with a Tandem ST2000}.
7221
7222 @end ifset
7223 @ifset VXWORKS
7224 @item target vxworks @var{machinename}
7225 @kindex target vxworks
7226 A VxWorks system, attached via TCP/IP. The argument @var{machinename}
7227 is the target system's machine name or IP address.
7228 @xref{VxWorks Remote, ,@value{GDBN} and VxWorks}.
7229 @end ifset
7230 @end table
7231
7232 @ifset GENERIC
7233 Different targets are available on different configurations of @value{GDBN}; your
7234 configuration may have more or fewer targets.
7235 @end ifset
7236
7237 @node Remote
7238 @section Remote debugging
7239 @cindex remote debugging
7240
7241 If you are trying to debug a program running on a machine that cannot run
7242 GDB in the usual way, it is often useful to use remote debugging. For
7243 example, you might use remote debugging on an operating system kernel, or on
7244 a small system which does not have a general purpose operating system
7245 powerful enough to run a full-featured debugger.
7246
7247 Some configurations of GDB have special serial or TCP/IP interfaces
7248 to make this work with particular debugging targets. In addition,
7249 GDB comes with a generic serial protocol (specific to GDB, but
7250 not specific to any particular target system) which you can use if you
7251 write the remote stubs---the code that will run on the remote system to
7252 communicate with GDB.
7253
7254 Other remote targets may be available in your
7255 configuration of GDB; use @code{help targets} to list them.
7256
7257 @ifset GENERIC
7258 @c Text on starting up GDB in various specific cases; it goes up front
7259 @c in manuals configured for any of those particular situations, here
7260 @c otherwise.
7261 @menu
7262 @ifset REMOTESTUB
7263 * Remote Serial:: @value{GDBN} remote serial protocol
7264 @end ifset
7265 @ifset I960
7266 * i960-Nindy Remote:: @value{GDBN} with a remote i960 (Nindy)
7267 @end ifset
7268 @ifset AMD29K
7269 * UDI29K Remote:: @value{GDBN} and the UDI protocol for AMD29K
7270 * EB29K Remote:: @value{GDBN} with a remote EB29K
7271 @end ifset
7272 @ifset VXWORKS
7273 * VxWorks Remote:: @value{GDBN} and VxWorks
7274 @end ifset
7275 @ifset ST2000
7276 * ST2000 Remote:: @value{GDBN} with a Tandem ST2000
7277 @end ifset
7278 @ifset H8
7279 * Hitachi Remote:: @value{GDBN} and Hitachi Microprocessors
7280 @end ifset
7281 @ifset MIPS
7282 * MIPS Remote:: @value{GDBN} and MIPS boards
7283 @end ifset
7284 @ifset SIMS
7285 * Simulator:: Simulated CPU target
7286 @end ifset
7287 @end menu
7288
7289 @include remote.texi
7290 @end ifset
7291
7292 @node Controlling GDB
7293 @chapter Controlling @value{GDBN}
7294
7295 You can alter the way @value{GDBN} interacts with you by using
7296 the @code{set} command. For commands controlling how @value{GDBN} displays
7297 data, @pxref{Print Settings, ,Print settings}; other settings are described here.
7298
7299 @menu
7300 * Prompt:: Prompt
7301 * Editing:: Command editing
7302 * History:: Command history
7303 * Screen Size:: Screen size
7304 * Numbers:: Numbers
7305 * Messages/Warnings:: Optional warnings and messages
7306 @end menu
7307
7308 @node Prompt
7309 @section Prompt
7310 @cindex prompt
7311
7312 @value{GDBN} indicates its readiness to read a command by printing a string
7313 called the @dfn{prompt}. This string is normally @samp{(@value{GDBP})}. You
7314 can change the prompt string with the @code{set prompt} command. For
7315 instance, when debugging @value{GDBN} with @value{GDBN}, it is useful to change
7316 the prompt in one of the @value{GDBN} sessions so that you can always tell which
7317 one you are talking to.
7318
7319 @table @code
7320 @item set prompt @var{newprompt}
7321 @kindex set prompt
7322 Directs @value{GDBN} to use @var{newprompt} as its prompt string henceforth.
7323 @kindex show prompt
7324 @item show prompt
7325 Prints a line of the form: @samp{Gdb's prompt is: @var{your-prompt}}
7326 @end table
7327
7328 @node Editing
7329 @section Command editing
7330 @cindex readline
7331 @cindex command line editing
7332
7333 @value{GDBN} reads its input commands via the @dfn{readline} interface. This
7334 GNU library provides consistent behavior for programs which provide a
7335 command line interface to the user. Advantages are @code{emacs}-style
7336 or @code{vi}-style inline editing of commands, @code{csh}-like history
7337 substitution, and a storage and recall of command history across
7338 debugging sessions.
7339
7340 You may control the behavior of command line editing in @value{GDBN} with the
7341 command @code{set}.
7342
7343 @table @code
7344 @kindex set editing
7345 @cindex editing
7346 @item set editing
7347 @itemx set editing on
7348 Enable command line editing (enabled by default).
7349
7350 @item set editing off
7351 Disable command line editing.
7352
7353 @kindex show editing
7354 @item show editing
7355 Show whether command line editing is enabled.
7356 @end table
7357
7358 @node History
7359 @section Command history
7360
7361 @value{GDBN} can keep track of the commands you type during your
7362 debugging sessions, so that you can be certain of precisely what
7363 happened. Use these commands to manage the @value{GDBN} command
7364 history facility.
7365
7366 @table @code
7367 @cindex history substitution
7368 @cindex history file
7369 @kindex set history filename
7370 @item set history filename @var{fname}
7371 Set the name of the @value{GDBN} command history file to @var{fname}. This is
7372 the file from which @value{GDBN} will read an initial command history
7373 list or to which it will write this list when it exits. This list is
7374 accessed through history expansion or through the history
7375 command editing characters listed below. This file defaults to the
7376 value of the environment variable @code{GDBHISTFILE}, or to
7377 @file{./.gdb_history} if this variable is not set.
7378
7379 @cindex history save
7380 @kindex set history save
7381 @item set history save
7382 @itemx set history save on
7383 Record command history in a file, whose name may be specified with the
7384 @code{set history filename} command. By default, this option is disabled.
7385
7386 @item set history save off
7387 Stop recording command history in a file.
7388
7389 @cindex history size
7390 @kindex set history size
7391 @item set history size @var{size}
7392 Set the number of commands which @value{GDBN} will keep in its history list.
7393 This defaults to the value of the environment variable
7394 @code{HISTSIZE}, or to 256 if this variable is not set.
7395 @end table
7396
7397 @cindex history expansion
7398 History expansion assigns special meaning to the character @kbd{!}.
7399 @ifset have-readline-appendices
7400 @xref{Event Designators}.
7401 @end ifset
7402
7403 Since @kbd{!} is also the logical not operator in C, history expansion
7404 is off by default. If you decide to enable history expansion with the
7405 @code{set history expansion on} command, you may sometimes need to
7406 follow @kbd{!} (when it is used as logical not, in an expression) with
7407 a space or a tab to prevent it from being expanded. The readline
7408 history facilities will not attempt substitution on the strings
7409 @kbd{!=} and @kbd{!(}, even when history expansion is enabled.
7410
7411 The commands to control history expansion are:
7412
7413 @table @code
7414
7415 @kindex set history expansion
7416 @item set history expansion on
7417 @itemx set history expansion
7418 Enable history expansion. History expansion is off by default.
7419
7420 @item set history expansion off
7421 Disable history expansion.
7422
7423 The readline code comes with more complete documentation of
7424 editing and history expansion features. Users unfamiliar with @code{emacs}
7425 or @code{vi} may wish to read it.
7426 @ifset have-readline-appendices
7427 @xref{Command Line Editing}.
7428 @end ifset
7429
7430 @c @group
7431 @kindex show history
7432 @item show history
7433 @itemx show history filename
7434 @itemx show history save
7435 @itemx show history size
7436 @itemx show history expansion
7437 These commands display the state of the @value{GDBN} history parameters.
7438 @code{show history} by itself displays all four states.
7439 @c @end group
7440 @end table
7441
7442 @table @code
7443 @kindex show commands
7444 @item show commands
7445 Display the last ten commands in the command history.
7446
7447 @item show commands @var{n}
7448 Print ten commands centered on command number @var{n}.
7449
7450 @item show commands +
7451 Print ten commands just after the commands last printed.
7452 @end table
7453
7454 @node Screen Size
7455 @section Screen size
7456 @cindex size of screen
7457 @cindex pauses in output
7458
7459 Certain commands to @value{GDBN} may produce large amounts of
7460 information output to the screen. To help you read all of it,
7461 @value{GDBN} pauses and asks you for input at the end of each page of
7462 output. Type @key{RET} when you want to continue the output, or @kbd{q}
7463 to discard the remaining output. Also, the screen width setting
7464 determines when to wrap lines of output. Depending on what is being
7465 printed, @value{GDBN} tries to break the line at a readable place,
7466 rather than simply letting it overflow onto the following line.
7467
7468 Normally @value{GDBN} knows the size of the screen from the termcap data base
7469 together with the value of the @code{TERM} environment variable and the
7470 @code{stty rows} and @code{stty cols} settings. If this is not correct,
7471 you can override it with the @code{set height} and @code{set
7472 width} commands:
7473
7474 @table @code
7475 @item set height @var{lpp}
7476 @itemx show height
7477 @itemx set width @var{cpl}
7478 @itemx show width
7479 @kindex set height
7480 @kindex set width
7481 @kindex show width
7482 @kindex show height
7483 These @code{set} commands specify a screen height of @var{lpp} lines and
7484 a screen width of @var{cpl} characters. The associated @code{show}
7485 commands display the current settings.
7486
7487 If you specify a height of zero lines, @value{GDBN} will not pause during output
7488 no matter how long the output is. This is useful if output is to a file
7489 or to an editor buffer.
7490
7491 Likewise, you can specify @samp{set width 0} to prevent @value{GDBN}
7492 from wrapping its output.
7493 @end table
7494
7495 @node Numbers
7496 @section Numbers
7497 @cindex number representation
7498 @cindex entering numbers
7499
7500 You can always enter numbers in octal, decimal, or hexadecimal in @value{GDBN} by
7501 the usual conventions: octal numbers begin with @samp{0}, decimal
7502 numbers end with @samp{.}, and hexadecimal numbers begin with @samp{0x}.
7503 Numbers that begin with none of these are, by default, entered in base
7504 10; likewise, the default display for numbers---when no particular
7505 format is specified---is base 10. You can change the default base for
7506 both input and output with the @code{set radix} command.
7507
7508 @table @code
7509 @kindex set radix
7510 @item set radix @var{base}
7511 Set the default base for numeric input and display. Supported choices
7512 for @var{base} are decimal 8, 10, or 16. @var{base} must itself be
7513 specified either unambiguously or using the current default radix; for
7514 example, any of
7515
7516 @example
7517 set radix 012
7518 set radix 10.
7519 set radix 0xa
7520 @end example
7521
7522 @noindent
7523 will set the base to decimal. On the other hand, @samp{set radix 10}
7524 will leave the radix unchanged no matter what it was.
7525
7526 @kindex show radix
7527 @item show radix
7528 Display the current default base for numeric input and display.
7529 @end table
7530
7531 @node Messages/Warnings
7532 @section Optional warnings and messages
7533
7534 By default, @value{GDBN} is silent about its inner workings. If you are running
7535 on a slow machine, you may want to use the @code{set verbose} command.
7536 It will make @value{GDBN} tell you when it does a lengthy internal operation, so
7537 you will not think it has crashed.
7538
7539 Currently, the messages controlled by @code{set verbose} are those
7540 which announce that the symbol table for a source file is being read;
7541 see @code{symbol-file} in @ref{Files, ,Commands to specify files}.
7542
7543 @table @code
7544 @kindex set verbose
7545 @item set verbose on
7546 Enables @value{GDBN} output of certain informational messages.
7547
7548 @item set verbose off
7549 Disables @value{GDBN} output of certain informational messages.
7550
7551 @kindex show verbose
7552 @item show verbose
7553 Displays whether @code{set verbose} is on or off.
7554 @end table
7555
7556 By default, if @value{GDBN} encounters bugs in the symbol table of an object
7557 file, it is silent; but if you are debugging a compiler, you may find
7558 this information useful (@pxref{Symbol Errors, ,Errors reading symbol files}).
7559
7560 @table @code
7561 @kindex set complaints
7562 @item set complaints @var{limit}
7563 Permits @value{GDBN} to output @var{limit} complaints about each type of unusual
7564 symbols before becoming silent about the problem. Set @var{limit} to
7565 zero to suppress all complaints; set it to a large number to prevent
7566 complaints from being suppressed.
7567
7568 @kindex show complaints
7569 @item show complaints
7570 Displays how many symbol complaints @value{GDBN} is permitted to produce.
7571 @end table
7572
7573 By default, @value{GDBN} is cautious, and asks what sometimes seems to be a
7574 lot of stupid questions to confirm certain commands. For example, if
7575 you try to run a program which is already running:
7576
7577 @example
7578 (@value{GDBP}) run
7579 The program being debugged has been started already.
7580 Start it from the beginning? (y or n)
7581 @end example
7582
7583 If you are willing to unflinchingly face the consequences of your own
7584 commands, you can disable this ``feature'':
7585
7586 @table @code
7587 @kindex set confirm
7588 @cindex flinching
7589 @cindex confirmation
7590 @cindex stupid questions
7591 @item set confirm off
7592 Disables confirmation requests.
7593
7594 @item set confirm on
7595 Enables confirmation requests (the default).
7596
7597 @item show confirm
7598 @kindex show confirm
7599 Displays state of confirmation requests.
7600 @end table
7601
7602 @c FIXME this does not really belong here. But where *does* it belong?
7603 @cindex reloading symbols
7604 Some systems allow individual object files that make up your program to
7605 be replaced without stopping and restarting your program.
7606 @ifset VXWORKS
7607 For example, in VxWorks you can simply recompile a defective object file
7608 and keep on running.
7609 @end ifset
7610 If you are running on one of these systems, you can allow @value{GDBN} to
7611 reload the symbols for automatically relinked modules:
7612
7613 @table @code
7614 @kindex set symbol-reloading
7615 @item set symbol-reloading on
7616 Replace symbol definitions for the corresponding source file when an
7617 object file with a particular name is seen again.
7618
7619 @item set symbol-reloading off
7620 Do not replace symbol definitions when re-encountering object files of
7621 the same name. This is the default state; if you are not running on a
7622 system that permits automatically relinking modules, you should leave
7623 @code{symbol-reloading} off, since otherwise @value{GDBN} may discard symbols
7624 when linking large programs, that may contain several modules (from
7625 different directories or libraries) with the same name.
7626
7627 @item show symbol-reloading
7628 Show the current @code{on} or @code{off} setting.
7629 @end table
7630
7631 @node Sequences
7632 @chapter Canned Sequences of Commands
7633
7634 Aside from breakpoint commands (@pxref{Break Commands, ,Breakpoint
7635 command lists}), @value{GDBN} provides two ways to store sequences of commands
7636 for execution as a unit: user-defined commands and command files.
7637
7638 @menu
7639 * Define:: User-defined commands
7640 * Hooks:: User-defined command hooks
7641 * Command Files:: Command files
7642 * Output:: Commands for controlled output
7643 @end menu
7644
7645 @node Define
7646 @section User-defined commands
7647
7648 @cindex user-defined command
7649 A @dfn{user-defined command} is a sequence of @value{GDBN} commands to which you
7650 assign a new name as a command. This is done with the @code{define}
7651 command.
7652
7653 @table @code
7654 @item define @var{commandname}
7655 @kindex define
7656 Define a command named @var{commandname}. If there is already a command
7657 by that name, you are asked to confirm that you want to redefine it.
7658
7659 The definition of the command is made up of other @value{GDBN} command lines,
7660 which are given following the @code{define} command. The end of these
7661 commands is marked by a line containing @code{end}.
7662
7663 @item document @var{commandname}
7664 @kindex document
7665 Give documentation to the user-defined command @var{commandname}. The
7666 command @var{commandname} must already be defined. This command reads
7667 lines of documentation just as @code{define} reads the lines of the
7668 command definition, ending with @code{end}. After the @code{document}
7669 command is finished, @code{help} on command @var{commandname} will print
7670 the documentation you have specified.
7671
7672 You may use the @code{document} command again to change the
7673 documentation of a command. Redefining the command with @code{define}
7674 does not change the documentation.
7675
7676 @item help user-defined
7677 @kindex help user-defined
7678 List all user-defined commands, with the first line of the documentation
7679 (if any) for each.
7680
7681 @item show user
7682 @itemx show user @var{commandname}
7683 @kindex show user
7684 Display the @value{GDBN} commands used to define @var{commandname} (but not its
7685 documentation). If no @var{commandname} is given, display the
7686 definitions for all user-defined commands.
7687 @end table
7688
7689 User-defined commands do not take arguments. When they are executed, the
7690 commands of the definition are not printed. An error in any command
7691 stops execution of the user-defined command.
7692
7693 Commands that would ask for confirmation if used interactively proceed
7694 without asking when used inside a user-defined command. Many @value{GDBN} commands
7695 that normally print messages to say what they are doing omit the messages
7696 when used in a user-defined command.
7697
7698 @node Hooks
7699 @section User-defined command hooks
7700 @cindex command files
7701
7702 You may define @emph{hooks}, which are a special kind of user-defined
7703 command. Whenever you run the command @samp{foo}, if the user-defined
7704 command @samp{hook-foo} exists, it is executed (with no arguments)
7705 before that command.
7706
7707 In addition, a pseudo-command, @samp{stop} exists. Defining
7708 (@samp{hook-stop}) makes the associated commands execute every time
7709 execution stops in your program: before breakpoint commands are run,
7710 displays are printed, or the stack frame is printed.
7711
7712 @ifclear BARETARGET
7713 For example, to ignore @code{SIGALRM} signals while
7714 single-stepping, but treat them normally during normal execution,
7715 you could define:
7716
7717 @example
7718 define hook-stop
7719 handle SIGALRM nopass
7720 end
7721
7722 define hook-run
7723 handle SIGALRM pass
7724 end
7725
7726 define hook-continue
7727 handle SIGLARM pass
7728 end
7729 @end example
7730 @end ifclear
7731
7732 You can define a hook for any single-word command in @value{GDBN}, but
7733 not for command aliases; you should define a hook for the basic command
7734 name, e.g. @code{backtrace} rather than @code{bt}.
7735 @c FIXME! So how does Joe User discover whether a command is an alias
7736 @c or not?
7737 If an error occurs during the execution of your hook, execution of
7738 @value{GDBN} commands stops and @value{GDBN} issues a prompt
7739 (before the command that you actually typed had a chance to run).
7740
7741 If you try to define a hook which does not match any known command, you
7742 will get a warning from the @code{define} command.
7743
7744 @node Command Files
7745 @section Command files
7746
7747 @cindex command files
7748 A command file for @value{GDBN} is a file of lines that are @value{GDBN} commands. Comments
7749 (lines starting with @kbd{#}) may also be included. An empty line in a
7750 command file does nothing; it does not mean to repeat the last command, as
7751 it would from the terminal.
7752
7753 @cindex init file
7754 @cindex @file{@value{GDBINIT}}
7755 When you start @value{GDBN}, it automatically executes commands from its
7756 @dfn{init files}. These are files named @file{@value{GDBINIT}}.
7757 @value{GDBN} reads the init file (if any) in your home directory, then
7758 processes command line options and operands, and then reads the init
7759 file (if any) in the current working directory. This is so the init
7760 file in your home directory can set options (such as @code{set
7761 complaints}) which affect the processing of the command line options and
7762 operands. The init files are not executed if you use the @samp{-nx}
7763 option; @pxref{Mode Options, ,Choosing modes}.
7764
7765 @ifset GENERIC
7766 @cindex init file name
7767 On some configurations of @value{GDBN}, the init file is known by a
7768 different name (these are typically environments where a specialized
7769 form of GDB may need to coexist with other forms, hence a different name
7770 for the specialized version's init file). These are the environments
7771 with special init file names:
7772
7773 @itemize @bullet
7774 @kindex .vxgdbinit
7775 @item
7776 VxWorks (Wind River Systems real-time OS): @samp{.vxgdbinit}
7777
7778 @kindex .os68gdbinit
7779 @item
7780 OS68K (Enea Data Systems real-time OS): @samp{.os68gdbinit}
7781
7782 @kindex .esgdbinit
7783 @item
7784 ES-1800 (Ericsson Telecom AB M68000 emulator): @samp{.esgdbinit}
7785 @end itemize
7786 @end ifset
7787
7788 You can also request the execution of a command file with the
7789 @code{source} command:
7790
7791 @table @code
7792 @item source @var{filename}
7793 @kindex source
7794 Execute the command file @var{filename}.
7795 @end table
7796
7797 The lines in a command file are executed sequentially. They are not
7798 printed as they are executed. An error in any command terminates execution
7799 of the command file.
7800
7801 Commands that would ask for confirmation if used interactively proceed
7802 without asking when used in a command file. Many @value{GDBN} commands that
7803 normally print messages to say what they are doing omit the messages
7804 when called from command files.
7805
7806 @node Output
7807 @section Commands for controlled output
7808
7809 During the execution of a command file or a user-defined command, normal
7810 @value{GDBN} output is suppressed; the only output that appears is what is
7811 explicitly printed by the commands in the definition. This section
7812 describes three commands useful for generating exactly the output you
7813 want.
7814
7815 @table @code
7816 @item echo @var{text}
7817 @kindex echo
7818 @c I do not consider backslash-space a standard C escape sequence
7819 @c because it is not in ANSI.
7820 Print @var{text}. Nonprinting characters can be included in
7821 @var{text} using C escape sequences, such as @samp{\n} to print a
7822 newline. @strong{No newline will be printed unless you specify one.}
7823 In addition to the standard C escape sequences, a backslash followed
7824 by a space stands for a space. This is useful for displaying a
7825 string with spaces at the beginning or the end, since leading and
7826 trailing spaces are otherwise trimmed from all arguments.
7827 To print @samp{@w{ }and foo =@w{ }}, use the command
7828 @samp{echo \@w{ }and foo = \@w{ }}.
7829
7830 A backslash at the end of @var{text} can be used, as in C, to continue
7831 the command onto subsequent lines. For example,
7832
7833 @example
7834 echo This is some text\n\
7835 which is continued\n\
7836 onto several lines.\n
7837 @end example
7838
7839 produces the same output as
7840
7841 @example
7842 echo This is some text\n
7843 echo which is continued\n
7844 echo onto several lines.\n
7845 @end example
7846
7847 @item output @var{expression}
7848 @kindex output
7849 Print the value of @var{expression} and nothing but that value: no
7850 newlines, no @samp{$@var{nn} = }. The value is not entered in the
7851 value history either. @xref{Expressions, ,Expressions}, for more information on
7852 expressions.
7853
7854 @item output/@var{fmt} @var{expression}
7855 Print the value of @var{expression} in format @var{fmt}. You can use
7856 the same formats as for @code{print}. @xref{Output Formats,,Output
7857 formats}, for more information.
7858
7859 @item printf @var{string}, @var{expressions}@dots{}
7860 @kindex printf
7861 Print the values of the @var{expressions} under the control of
7862 @var{string}. The @var{expressions} are separated by commas and may be
7863 either numbers or pointers. Their values are printed as specified by
7864 @var{string}, exactly as if your program were to execute the C
7865 subroutine
7866
7867 @example
7868 printf (@var{string}, @var{expressions}@dots{});
7869 @end example
7870
7871 For example, you can print two values in hex like this:
7872
7873 @smallexample
7874 printf "foo, bar-foo = 0x%x, 0x%x\n", foo, bar-foo
7875 @end smallexample
7876
7877 The only backslash-escape sequences that you can use in the format
7878 string are the simple ones that consist of backslash followed by a
7879 letter.
7880 @end table
7881
7882 @ifclear DOSHOST
7883 @node Emacs
7884 @chapter Using @value{GDBN} under GNU Emacs
7885
7886 @cindex emacs
7887 A special interface allows you to use GNU Emacs to view (and
7888 edit) the source files for the program you are debugging with
7889 @value{GDBN}.
7890
7891 To use this interface, use the command @kbd{M-x gdb} in Emacs. Give the
7892 executable file you want to debug as an argument. This command starts
7893 @value{GDBN} as a subprocess of Emacs, with input and output through a newly
7894 created Emacs buffer.
7895
7896 Using @value{GDBN} under Emacs is just like using @value{GDBN} normally except for two
7897 things:
7898
7899 @itemize @bullet
7900 @item
7901 All ``terminal'' input and output goes through the Emacs buffer.
7902 @end itemize
7903
7904 This applies both to @value{GDBN} commands and their output, and to the input
7905 and output done by the program you are debugging.
7906
7907 This is useful because it means that you can copy the text of previous
7908 commands and input them again; you can even use parts of the output
7909 in this way.
7910
7911 All the facilities of Emacs' Shell mode are available for interacting
7912 with your program. In particular, you can send signals the usual
7913 way---for example, @kbd{C-c C-c} for an interrupt, @kbd{C-c C-z} for a
7914 stop.
7915
7916 @itemize @bullet
7917 @item
7918 @value{GDBN} displays source code through Emacs.
7919 @end itemize
7920
7921 Each time @value{GDBN} displays a stack frame, Emacs automatically finds the
7922 source file for that frame and puts an arrow (@samp{=>}) at the
7923 left margin of the current line. Emacs uses a separate buffer for
7924 source display, and splits the screen to show both your @value{GDBN} session
7925 and the source.
7926
7927 Explicit @value{GDBN} @code{list} or search commands still produce output as
7928 usual, but you probably will have no reason to use them.
7929
7930 @quotation
7931 @emph{Warning:} If the directory where your program resides is not your
7932 current directory, it can be easy to confuse Emacs about the location of
7933 the source files, in which case the auxiliary display buffer will not
7934 appear to show your source. @value{GDBN} can find programs by searching your
7935 environment's @code{PATH} variable, so the @value{GDBN} input and output
7936 session will proceed normally; but Emacs does not get enough information
7937 back from @value{GDBN} to locate the source files in this situation. To
7938 avoid this problem, either start @value{GDBN} mode from the directory where
7939 your program resides, or specify a full path name when prompted for the
7940 @kbd{M-x gdb} argument.
7941
7942 A similar confusion can result if you use the @value{GDBN} @code{file} command to
7943 switch to debugging a program in some other location, from an existing
7944 @value{GDBN} buffer in Emacs.
7945 @end quotation
7946
7947 By default, @kbd{M-x gdb} calls the program called @file{gdb}. If
7948 you need to call @value{GDBN} by a different name (for example, if you keep
7949 several configurations around, with different names) you can set the
7950 Emacs variable @code{gdb-command-name}; for example,
7951
7952 @example
7953 (setq gdb-command-name "mygdb")
7954 @end example
7955
7956 @noindent
7957 (preceded by @kbd{ESC ESC}, or typed in the @code{*scratch*} buffer, or
7958 in your @file{.emacs} file) will make Emacs call the program named
7959 ``@code{mygdb}'' instead.
7960
7961 In the @value{GDBN} I/O buffer, you can use these special Emacs commands in
7962 addition to the standard Shell mode commands:
7963
7964 @table @kbd
7965 @item C-h m
7966 Describe the features of Emacs' @value{GDBN} Mode.
7967
7968 @item M-s
7969 Execute to another source line, like the @value{GDBN} @code{step} command; also
7970 update the display window to show the current file and location.
7971
7972 @item M-n
7973 Execute to next source line in this function, skipping all function
7974 calls, like the @value{GDBN} @code{next} command. Then update the display window
7975 to show the current file and location.
7976
7977 @item M-i
7978 Execute one instruction, like the @value{GDBN} @code{stepi} command; update
7979 display window accordingly.
7980
7981 @item M-x gdb-nexti
7982 Execute to next instruction, using the @value{GDBN} @code{nexti} command; update
7983 display window accordingly.
7984
7985 @item C-c C-f
7986 Execute until exit from the selected stack frame, like the @value{GDBN}
7987 @code{finish} command.
7988
7989 @item M-c
7990 Continue execution of your program, like the @value{GDBN} @code{continue}
7991 command.
7992
7993 @emph{Warning:} In Emacs v19, this command is @kbd{C-c C-p}.
7994
7995 @item M-u
7996 Go up the number of frames indicated by the numeric argument
7997 (@pxref{Arguments, , Numeric Arguments, emacs, The GNU Emacs Manual}),
7998 like the @value{GDBN} @code{up} command.
7999
8000 @emph{Warning:} In Emacs v19, this command is @kbd{C-c C-u}.
8001
8002 @item M-d
8003 Go down the number of frames indicated by the numeric argument, like the
8004 @value{GDBN} @code{down} command.
8005
8006 @emph{Warning:} In Emacs v19, this command is @kbd{C-c C-d}.
8007
8008 @item C-x &
8009 Read the number where the cursor is positioned, and insert it at the end
8010 of the @value{GDBN} I/O buffer. For example, if you wish to disassemble code
8011 around an address that was displayed earlier, type @kbd{disassemble};
8012 then move the cursor to the address display, and pick up the
8013 argument for @code{disassemble} by typing @kbd{C-x &}.
8014
8015 You can customize this further by defining elements of the list
8016 @code{gdb-print-command}; once it is defined, you can format or
8017 otherwise process numbers picked up by @kbd{C-x &} before they are
8018 inserted. A numeric argument to @kbd{C-x &} will both indicate that you
8019 wish special formatting, and act as an index to pick an element of the
8020 list. If the list element is a string, the number to be inserted is
8021 formatted using the Emacs function @code{format}; otherwise the number
8022 is passed as an argument to the corresponding list element.
8023 @end table
8024
8025 In any source file, the Emacs command @kbd{C-x SPC} (@code{gdb-break})
8026 tells @value{GDBN} to set a breakpoint on the source line point is on.
8027
8028 If you accidentally delete the source-display buffer, an easy way to get
8029 it back is to type the command @code{f} in the @value{GDBN} buffer, to
8030 request a frame display; when you run under Emacs, this will recreate
8031 the source buffer if necessary to show you the context of the current
8032 frame.
8033
8034 The source files displayed in Emacs are in ordinary Emacs buffers
8035 which are visiting the source files in the usual way. You can edit
8036 the files with these buffers if you wish; but keep in mind that @value{GDBN}
8037 communicates with Emacs in terms of line numbers. If you add or
8038 delete lines from the text, the line numbers that @value{GDBN} knows will cease
8039 to correspond properly with the code.
8040
8041 @c The following dropped because Epoch is nonstandard. Reactivate
8042 @c if/when v19 does something similar. ---pesch@cygnus.com 19dec1990
8043 @ignore
8044 @kindex emacs epoch environment
8045 @kindex epoch
8046 @kindex inspect
8047
8048 Version 18 of Emacs has a built-in window system called the @code{epoch}
8049 environment. Users of this environment can use a new command,
8050 @code{inspect} which performs identically to @code{print} except that
8051 each value is printed in its own window.
8052 @end ignore
8053 @end ifclear
8054
8055 @ifset LUCID
8056 @node Energize
8057 @chapter Using @value{GDBN} with Energize
8058
8059 @cindex Energize
8060 The Energize Programming System is an integrated development environment
8061 that includes a point-and-click interface to many programming tools.
8062 When you use @value{GDBN} in this environment, you can use the standard
8063 Energize graphical interface to drive @value{GDBN}; you can also, if you
8064 choose, type @value{GDBN} commands as usual in a debugging window. Even if
8065 you use the graphical interface, the debugging window (which uses Emacs,
8066 and resembles the standard Emacs interface to @value{GDBN}) displays the
8067 equivalent commands, so that the history of your debugging session is
8068 properly reflected.
8069
8070 When Energize starts up a @value{GDBN} session, it uses one of the
8071 command-line options @samp{-energize} or @samp{-cadillac} (``cadillac''
8072 is the name of the communications protocol used by the Energize system).
8073 This option makes @value{GDBN} run as one of the tools in the Energize Tool
8074 Set: it sends all output to the Energize kernel, and accept input from
8075 it as well.
8076
8077 See the user manual for the Energize Programming System for
8078 information on how to use the Energize graphical interface and the other
8079 development tools that Energize integrates with @value{GDBN}.
8080
8081 @end ifset
8082
8083 @node GDB Bugs
8084 @chapter Reporting Bugs in @value{GDBN}
8085 @cindex bugs in @value{GDBN}
8086 @cindex reporting bugs in @value{GDBN}
8087
8088 Your bug reports play an essential role in making @value{GDBN} reliable.
8089
8090 Reporting a bug may help you by bringing a solution to your problem, or it
8091 may not. But in any case the principal function of a bug report is to help
8092 the entire community by making the next version of @value{GDBN} work better. Bug
8093 reports are your contribution to the maintenance of @value{GDBN}.
8094
8095 In order for a bug report to serve its purpose, you must include the
8096 information that enables us to fix the bug.
8097
8098 @menu
8099 * Bug Criteria:: Have you found a bug?
8100 * Bug Reporting:: How to report bugs
8101 @end menu
8102
8103 @node Bug Criteria
8104 @section Have you found a bug?
8105 @cindex bug criteria
8106
8107 If you are not sure whether you have found a bug, here are some guidelines:
8108
8109 @itemize @bullet
8110 @item
8111 @cindex fatal signal
8112 @cindex debugger crash
8113 @cindex crash of debugger
8114 If the debugger gets a fatal signal, for any input whatever, that is a
8115 @value{GDBN} bug. Reliable debuggers never crash.
8116
8117 @item
8118 @cindex error on valid input
8119 If @value{GDBN} produces an error message for valid input, that is a bug.
8120
8121 @item
8122 @cindex invalid input
8123 If @value{GDBN} does not produce an error message for invalid input,
8124 that is a bug. However, you should note that your idea of
8125 ``invalid input'' might be our idea of ``an extension'' or ``support
8126 for traditional practice''.
8127
8128 @item
8129 If you are an experienced user of debugging tools, your suggestions
8130 for improvement of @value{GDBN} are welcome in any case.
8131 @end itemize
8132
8133 @node Bug Reporting
8134 @section How to report bugs
8135 @cindex bug reports
8136 @cindex @value{GDBN} bugs, reporting
8137
8138 A number of companies and individuals offer support for GNU products.
8139 If you obtained @value{GDBN} from a support organization, we recommend you
8140 contact that organization first.
8141
8142 You can find contact information for many support companies and
8143 individuals in the file @file{etc/SERVICE} in the GNU Emacs
8144 distribution.
8145
8146 In any event, we also recommend that you send bug reports for @value{GDBN} to one
8147 of these addresses:
8148
8149 @example
8150 bug-gdb@@prep.ai.mit.edu
8151 @{ucbvax|mit-eddie|uunet@}!prep.ai.mit.edu!bug-gdb
8152 @end example
8153
8154 @strong{Do not send bug reports to @samp{info-gdb}, or to
8155 @samp{help-gdb}, or to any newsgroups.} Most users of @value{GDBN} do not want to
8156 receive bug reports. Those that do, have arranged to receive @samp{bug-gdb}.
8157
8158 The mailing list @samp{bug-gdb} has a newsgroup @samp{gnu.gdb.bug} which
8159 serves as a repeater. The mailing list and the newsgroup carry exactly
8160 the same messages. Often people think of posting bug reports to the
8161 newsgroup instead of mailing them. This appears to work, but it has one
8162 problem which can be crucial: a newsgroup posting often lacks a mail
8163 path back to the sender. Thus, if we need to ask for more information,
8164 we may be unable to reach you. For this reason, it is better to send
8165 bug reports to the mailing list.
8166
8167 As a last resort, send bug reports on paper to:
8168
8169 @example
8170 GNU Debugger Bugs
8171 Free Software Foundation
8172 545 Tech Square
8173 Cambridge, MA 02139
8174 @end example
8175
8176 The fundamental principle of reporting bugs usefully is this:
8177 @strong{report all the facts}. If you are not sure whether to state a
8178 fact or leave it out, state it!
8179
8180 Often people omit facts because they think they know what causes the
8181 problem and assume that some details do not matter. Thus, you might
8182 assume that the name of the variable you use in an example does not matter.
8183 Well, probably it does not, but one cannot be sure. Perhaps the bug is a
8184 stray memory reference which happens to fetch from the location where that
8185 name is stored in memory; perhaps, if the name were different, the contents
8186 of that location would fool the debugger into doing the right thing despite
8187 the bug. Play it safe and give a specific, complete example. That is the
8188 easiest thing for you to do, and the most helpful.
8189
8190 Keep in mind that the purpose of a bug report is to enable us to fix
8191 the bug if it is new to us. It is not as important as what happens if
8192 the bug is already known. Therefore, always write your bug reports on
8193 the assumption that the bug has not been reported previously.
8194
8195 Sometimes people give a few sketchy facts and ask, ``Does this ring a
8196 bell?'' Those bug reports are useless, and we urge everyone to
8197 @emph{refuse to respond to them} except to chide the sender to report
8198 bugs properly.
8199
8200 To enable us to fix the bug, you should include all these things:
8201
8202 @itemize @bullet
8203 @item
8204 The version of @value{GDBN}. @value{GDBN} announces it if you start with no
8205 arguments; you can also print it at any time using @code{show version}.
8206
8207 Without this, we will not know whether there is any point in looking for
8208 the bug in the current version of @value{GDBN}.
8209
8210 @item
8211 The type of machine you are using, and the operating system name and
8212 version number.
8213
8214 @item
8215 What compiler (and its version) was used to compile @value{GDBN}---e.g.
8216 ``@value{GCC}--2.0''.
8217
8218 @item
8219 What compiler (and its version) was used to compile the program you
8220 are debugging---e.g. ``@value{GCC}--2.0''.
8221
8222 @item
8223 The command arguments you gave the compiler to compile your example and
8224 observe the bug. For example, did you use @samp{-O}? To guarantee
8225 you will not omit something important, list them all. A copy of the
8226 Makefile (or the output from make) is sufficient.
8227
8228 If we were to try to guess the arguments, we would probably guess wrong
8229 and then we might not encounter the bug.
8230
8231 @item
8232 A complete input script, and all necessary source files, that will
8233 reproduce the bug.
8234
8235 @item
8236 A description of what behavior you observe that you believe is
8237 incorrect. For example, ``It gets a fatal signal.''
8238
8239 Of course, if the bug is that @value{GDBN} gets a fatal signal, then we will
8240 certainly notice it. But if the bug is incorrect output, we might not
8241 notice unless it is glaringly wrong. We are human, after all. You
8242 might as well not give us a chance to make a mistake.
8243
8244 Even if the problem you experience is a fatal signal, you should still
8245 say so explicitly. Suppose something strange is going on, such as,
8246 your copy of @value{GDBN} is out of synch, or you have encountered a
8247 bug in the C library on your system. (This has happened!) Your copy
8248 might crash and ours would not. If you told us to expect a crash,
8249 then when ours fails to crash, we would know that the bug was not
8250 happening for us. If you had not told us to expect a crash, then we
8251 would not be able to draw any conclusion from our observations.
8252
8253 @item
8254 If you wish to suggest changes to the @value{GDBN} source, send us context
8255 diffs. If you even discuss something in the @value{GDBN} source, refer to
8256 it by context, not by line number.
8257
8258 The line numbers in our development sources will not match those in your
8259 sources. Your line numbers would convey no useful information to us.
8260 @end itemize
8261
8262 Here are some things that are not necessary:
8263
8264 @itemize @bullet
8265 @item
8266 A description of the envelope of the bug.
8267
8268 Often people who encounter a bug spend a lot of time investigating
8269 which changes to the input file will make the bug go away and which
8270 changes will not affect it.
8271
8272 This is often time consuming and not very useful, because the way we
8273 will find the bug is by running a single example under the debugger
8274 with breakpoints, not by pure deduction from a series of examples.
8275 We recommend that you save your time for something else.
8276
8277 Of course, if you can find a simpler example to report @emph{instead}
8278 of the original one, that is a convenience for us. Errors in the
8279 output will be easier to spot, running under the debugger will take
8280 less time, etc.
8281
8282 However, simplification is not vital; if you do not want to do this,
8283 report the bug anyway and send us the entire test case you used.
8284
8285 @item
8286 A patch for the bug.
8287
8288 A patch for the bug does help us if it is a good one. But do not omit
8289 the necessary information, such as the test case, on the assumption that
8290 a patch is all we need. We might see problems with your patch and decide
8291 to fix the problem another way, or we might not understand it at all.
8292
8293 Sometimes with a program as complicated as @value{GDBN} it is very hard to
8294 construct an example that will make the program follow a certain path
8295 through the code. If you do not send us the example, we will not be able
8296 to construct one, so we will not be able to verify that the bug is fixed.
8297
8298 And if we cannot understand what bug you are trying to fix, or why your
8299 patch should be an improvement, we will not install it. A test case will
8300 help us to understand.
8301
8302 @item
8303 A guess about what the bug is or what it depends on.
8304
8305 Such guesses are usually wrong. Even we cannot guess right about such
8306 things without first using the debugger to find the facts.
8307 @end itemize
8308
8309 @c The readline documentation is distributed with the readline code
8310 @c and consists of the two following files:
8311 @c rluser.texinfo
8312 @c inc-hist.texi
8313 @c Use -I with makeinfo to point to the appropriate directory,
8314 @c environment var TEXINPUTS with TeX.
8315 @include rluser.texinfo
8316 @include inc-hist.texi
8317
8318 @ifset NOVEL
8319 @node Renamed Commands
8320 @appendix Renamed Commands
8321
8322 The following commands were renamed in GDB 4, in order to make the
8323 command set as a whole more consistent and easier to use and remember:
8324
8325 @kindex add-syms
8326 @kindex delete environment
8327 @kindex info copying
8328 @kindex info convenience
8329 @kindex info directories
8330 @kindex info editing
8331 @kindex info history
8332 @kindex info targets
8333 @kindex info values
8334 @kindex info version
8335 @kindex info warranty
8336 @kindex set addressprint
8337 @kindex set arrayprint
8338 @kindex set prettyprint
8339 @kindex set screen-height
8340 @kindex set screen-width
8341 @kindex set unionprint
8342 @kindex set vtblprint
8343 @kindex set demangle
8344 @kindex set asm-demangle
8345 @kindex set sevenbit-strings
8346 @kindex set array-max
8347 @kindex set caution
8348 @kindex set history write
8349 @kindex show addressprint
8350 @kindex show arrayprint
8351 @kindex show prettyprint
8352 @kindex show screen-height
8353 @kindex show screen-width
8354 @kindex show unionprint
8355 @kindex show vtblprint
8356 @kindex show demangle
8357 @kindex show asm-demangle
8358 @kindex show sevenbit-strings
8359 @kindex show array-max
8360 @kindex show caution
8361 @kindex show history write
8362 @kindex unset
8363
8364 @c TEXI2ROFF-KILL
8365 @ifinfo
8366 @c END TEXI2ROFF-KILL
8367 @example
8368 OLD COMMAND NEW COMMAND
8369 @c TEXI2ROFF-KILL
8370 --------------- -------------------------------
8371 @c END TEXI2ROFF-KILL
8372 add-syms add-symbol-file
8373 delete environment unset environment
8374 info convenience show convenience
8375 info copying show copying
8376 info directories show directories
8377 info editing show commands
8378 info history show values
8379 info targets help target
8380 info values show values
8381 info version show version
8382 info warranty show warranty
8383 set/show addressprint set/show print address
8384 set/show array-max set/show print elements
8385 set/show arrayprint set/show print array
8386 set/show asm-demangle set/show print asm-demangle
8387 set/show caution set/show confirm
8388 set/show demangle set/show print demangle
8389 set/show history write set/show history save
8390 set/show prettyprint set/show print pretty
8391 set/show screen-height set/show height
8392 set/show screen-width set/show width
8393 set/show sevenbit-strings set/show print sevenbit-strings
8394 set/show unionprint set/show print union
8395 set/show vtblprint set/show print vtbl
8396
8397 unset [No longer an alias for delete]
8398 @end example
8399 @c TEXI2ROFF-KILL
8400 @end ifinfo
8401
8402 @tex
8403 \vskip \parskip\vskip \baselineskip
8404 \halign{\tt #\hfil &\qquad#&\tt #\hfil\cr
8405 {\bf Old Command} &&{\bf New Command}\cr
8406 add-syms &&add-symbol-file\cr
8407 delete environment &&unset environment\cr
8408 info convenience &&show convenience\cr
8409 info copying &&show copying\cr
8410 info directories &&show directories \cr
8411 info editing &&show commands\cr
8412 info history &&show values\cr
8413 info targets &&help target\cr
8414 info values &&show values\cr
8415 info version &&show version\cr
8416 info warranty &&show warranty\cr
8417 set{\rm / }show addressprint &&set{\rm / }show print address\cr
8418 set{\rm / }show array-max &&set{\rm / }show print elements\cr
8419 set{\rm / }show arrayprint &&set{\rm / }show print array\cr
8420 set{\rm / }show asm-demangle &&set{\rm / }show print asm-demangle\cr
8421 set{\rm / }show caution &&set{\rm / }show confirm\cr
8422 set{\rm / }show demangle &&set{\rm / }show print demangle\cr
8423 set{\rm / }show history write &&set{\rm / }show history save\cr
8424 set{\rm / }show prettyprint &&set{\rm / }show print pretty\cr
8425 set{\rm / }show screen-height &&set{\rm / }show height\cr
8426 set{\rm / }show screen-width &&set{\rm / }show width\cr
8427 set{\rm / }show sevenbit-strings &&set{\rm / }show print sevenbit-strings\cr
8428 set{\rm / }show unionprint &&set{\rm / }show print union\cr
8429 set{\rm / }show vtblprint &&set{\rm / }show print vtbl\cr
8430 \cr
8431 unset &&\rm(No longer an alias for delete)\cr
8432 }
8433 @end tex
8434 @c END TEXI2ROFF-KILL
8435 @end ifset
8436
8437 @ifclear PRECONFIGURED
8438 @node Formatting Documentation
8439 @appendix Formatting Documentation
8440
8441 @cindex GDB reference card
8442 @cindex reference card
8443 The GDB 4 release includes an already-formatted reference card, ready
8444 for printing with PostScript or GhostScript, in the @file{gdb}
8445 subdirectory of the main source directory@footnote{In
8446 @file{gdb-@value{GDBVN}/gdb/refcard.ps} of the version @value{GDBVN}
8447 release.}. If you can use PostScript or GhostScript with your printer,
8448 you can print the reference card immediately with @file{refcard.ps}.
8449
8450 The release also includes the source for the reference card. You
8451 can format it, using @TeX{}, by typing:
8452
8453 @example
8454 make refcard.dvi
8455 @end example
8456
8457 The GDB reference card is designed to print in landscape mode on US
8458 ``letter'' size paper; that is, on a sheet 11 inches wide by 8.5 inches
8459 high. You will need to specify this form of printing as an option to
8460 your @sc{dvi} output program.
8461
8462 @cindex documentation
8463
8464 All the documentation for GDB comes as part of the machine-readable
8465 distribution. The documentation is written in Texinfo format, which is
8466 a documentation system that uses a single source file to produce both
8467 on-line information and a printed manual. You can use one of the Info
8468 formatting commands to create the on-line version of the documentation
8469 and @TeX{} (or @code{texi2roff}) to typeset the printed version.
8470
8471 GDB includes an already formatted copy of the on-line Info version of
8472 this manual in the @file{gdb} subdirectory. The main Info file is
8473 @file{gdb-@var{version-number}/gdb/gdb.info}, and it refers to
8474 subordinate files matching @samp{gdb.info*} in the same directory. If
8475 necessary, you can print out these files, or read them with any editor;
8476 but they are easier to read using the @code{info} subsystem in GNU Emacs
8477 or the standalone @code{info} program, available as part of the GNU
8478 Texinfo distribution.
8479
8480 If you want to format these Info files yourself, you need one of the
8481 Info formatting programs, such as @code{texinfo-format-buffer} or
8482 @code{makeinfo}.
8483
8484 If you have @code{makeinfo} installed, and are in the top level GDB
8485 source directory (@file{gdb-@value{GDBVN}}, in the case of version @value{GDBVN}), you can
8486 make the Info file by typing:
8487
8488 @example
8489 cd gdb
8490 make gdb.info
8491 @end example
8492
8493 If you want to typeset and print copies of this manual, you need @TeX{},
8494 a program to print its @sc{dvi} output files, and @file{texinfo.tex}, the
8495 Texinfo definitions file.
8496
8497 @TeX{} is a typesetting program; it does not print files directly, but
8498 produces output files called @sc{dvi} files. To print a typeset
8499 document, you need a program to print @sc{dvi} files. If your system
8500 has @TeX{} installed, chances are it has such a program. The precise
8501 command to use depends on your system; @kbd{lpr -d} is common; another
8502 (for PostScript devices) is @kbd{dvips}. The @sc{dvi} print command may
8503 require a file name without any extension or a @samp{.dvi} extension.
8504
8505 @TeX{} also requires a macro definitions file called
8506 @file{texinfo.tex}. This file tells @TeX{} how to typeset a document
8507 written in Texinfo format. On its own, @TeX{} cannot read, much less
8508 typeset a Texinfo file. @file{texinfo.tex} is distributed with GDB
8509 and is located in the @file{gdb-@var{version-number}/texinfo}
8510 directory.
8511
8512 If you have @TeX{} and a @sc{dvi} printer program installed, you can
8513 typeset and print this manual. First switch to the the @file{gdb}
8514 subdirectory of the main source directory (for example, to
8515 @file{gdb-@value{GDBVN}/gdb}) and then type:
8516
8517 @example
8518 make gdb.dvi
8519 @end example
8520
8521 @node Installing GDB
8522 @appendix Installing GDB
8523 @cindex configuring GDB
8524 @cindex installation
8525
8526 GDB comes with a @code{configure} script that automates the process
8527 of preparing GDB for installation; you can then use @code{make} to
8528 build the @code{gdb} program.
8529 @iftex
8530 @c irrelevant in info file; it's as current as the code it lives with.
8531 @footnote{If you have a more recent version of GDB than @value{GDBVN},
8532 look at the @file{README} file in the sources; we may have improved the
8533 installation procedures since publishing this manual.}
8534 @end iftex
8535
8536 The GDB distribution includes all the source code you need for GDB in
8537 a single directory, whose name is usually composed by appending the
8538 version number to @samp{gdb}.
8539
8540 For example, the GDB version @value{GDBVN} distribution is in the
8541 @file{gdb-@value{GDBVN}} directory. That directory contains:
8542
8543 @table @code
8544 @item gdb-@value{GDBVN}/configure @r{(and supporting files)}
8545 script for configuring GDB and all its supporting libraries.
8546
8547 @item gdb-@value{GDBVN}/gdb
8548 the source specific to GDB itself
8549
8550 @item gdb-@value{GDBVN}/bfd
8551 source for the Binary File Descriptor library
8552
8553 @item gdb-@value{GDBVN}/include
8554 GNU include files
8555
8556 @item gdb-@value{GDBVN}/libiberty
8557 source for the @samp{-liberty} free software library
8558
8559 @item gdb-@value{GDBVN}/opcodes
8560 source for the library of opcode tables and disassemblers
8561
8562 @item gdb-@value{GDBVN}/readline
8563 source for the GNU command-line interface
8564
8565 @item gdb-@value{GDBVN}/glob
8566 source for the GNU filename pattern-matching subroutine
8567
8568 @item gdb-@value{GDBVN}/mmalloc
8569 source for the GNU memory-mapped malloc package
8570 @end table
8571
8572 The simplest way to configure and build GDB is to run @code{configure}
8573 from the @file{gdb-@var{version-number}} source directory, which in
8574 this example is the @file{gdb-@value{GDBVN}} directory.
8575
8576 First switch to the @file{gdb-@var{version-number}} source directory
8577 if you are not already in it; then run @code{configure}. Pass the
8578 identifier for the platform on which GDB will run as an
8579 argument.
8580
8581 For example:
8582
8583 @example
8584 cd gdb-@value{GDBVN}
8585 ./configure @var{host}
8586 make
8587 @end example
8588
8589 @noindent
8590 where @var{host} is an identifier such as @samp{sun4} or
8591 @samp{decstation}, that identifies the platform where GDB will run.
8592 (You can often leave off @var{host}; @code{configure} tries to guess the
8593 correct value by examining your system.)
8594
8595 Running @samp{configure @var{host}} and then running @code{make} builds the
8596 @file{bfd}, @file{readline}, @file{mmalloc}, and @file{libiberty}
8597 libraries, then @code{gdb} itself. The configured source files, and the
8598 binaries, are left in the corresponding source directories.
8599
8600 @code{configure} is a Bourne-shell (@code{/bin/sh}) script; if your
8601 system does not recognize this automatically when you run a different
8602 shell, you may need to run @code{sh} on it explicitly:
8603
8604 @example
8605 sh configure @var{host}
8606 @end example
8607
8608 If you run @code{configure} from a directory that contains source
8609 directories for multiple libraries or programs, such as the
8610 @file{gdb-@value{GDBVN}} source directory for version @value{GDBVN}, @code{configure}
8611 creates configuration files for every directory level underneath (unless
8612 you tell it not to, with the @samp{--norecursion} option).
8613
8614 You can run the @code{configure} script from any of the
8615 subordinate directories in the GDB distribution if you only want to
8616 configure that subdirectory, but be sure to specify a path to it.
8617
8618 For example, with version @value{GDBVN}, type the following to configure only
8619 the @code{bfd} subdirectory:
8620
8621 @example
8622 @group
8623 cd gdb-@value{GDBVN}/bfd
8624 ../configure @var{host}
8625 @end group
8626 @end example
8627
8628 You can install @code{@value{GDBP}} anywhere; it has no hardwired paths.
8629 However, you should make sure that the shell on your path (named by
8630 the @samp{SHELL} environment variable) is publicly readable. Remember
8631 that GDB uses the shell to start your program---some systems refuse to
8632 let GDB debug child processes whose programs are not readable.
8633
8634 @menu
8635 * Separate Objdir:: Compiling GDB in another directory
8636 * Config Names:: Specifying names for hosts and targets
8637 * configure Options:: Summary of options for configure
8638 @end menu
8639
8640 @node Separate Objdir
8641 @section Compiling GDB in another directory
8642
8643 If you want to run GDB versions for several host or target machines,
8644 you need a different @code{gdb} compiled for each combination of
8645 host and target. @code{configure} is designed to make this easy by
8646 allowing you to generate each configuration in a separate subdirectory,
8647 rather than in the source directory. If your @code{make} program
8648 handles the @samp{VPATH} feature (GNU @code{make} does), running
8649 @code{make} in each of these directories builds the @code{gdb}
8650 program specified there.
8651
8652 To build @code{gdb} in a separate directory, run @code{configure}
8653 with the @samp{--srcdir} option to specify where to find the source.
8654 (You also need to specify a path to find @code{configure}
8655 itself from your working directory. If the path to @code{configure}
8656 would be the same as the argument to @samp{--srcdir}, you can leave out
8657 the @samp{--srcdir} option; it will be assumed.)
8658
8659 For example, with version @value{GDBVN}, you can build GDB in a separate
8660 directory for a Sun 4 like this:
8661
8662 @example
8663 @group
8664 cd gdb-@value{GDBVN}
8665 mkdir ../gdb-sun4
8666 cd ../gdb-sun4
8667 ../gdb-@value{GDBVN}/configure sun4
8668 make
8669 @end group
8670 @end example
8671
8672 When @code{configure} builds a configuration using a remote source
8673 directory, it creates a tree for the binaries with the same structure
8674 (and using the same names) as the tree under the source directory. In
8675 the example, you'd find the Sun 4 library @file{libiberty.a} in the
8676 directory @file{gdb-sun4/libiberty}, and GDB itself in
8677 @file{gdb-sun4/gdb}.
8678
8679 One popular reason to build several GDB configurations in separate
8680 directories is to configure GDB for cross-compiling (where GDB
8681 runs on one machine---the host---while debugging programs that run on
8682 another machine---the target). You specify a cross-debugging target by
8683 giving the @samp{--target=@var{target}} option to @code{configure}.
8684
8685 When you run @code{make} to build a program or library, you must run
8686 it in a configured directory---whatever directory you were in when you
8687 called @code{configure} (or one of its subdirectories).
8688
8689 The @code{Makefile} that @code{configure} generates in each source
8690 directory also runs recursively. If you type @code{make} in a source
8691 directory such as @file{gdb-@value{GDBVN}} (or in a separate configured
8692 directory configured with @samp{--srcdir=@var{path}/gdb-@value{GDBVN}}), you
8693 will build all the required libraries, and then build GDB.
8694
8695 When you have multiple hosts or targets configured in separate
8696 directories, you can run @code{make} on them in parallel (for example,
8697 if they are NFS-mounted on each of the hosts); they will not interfere
8698 with each other.
8699
8700 @node Config Names
8701 @section Specifying names for hosts and targets
8702
8703 The specifications used for hosts and targets in the @code{configure}
8704 script are based on a three-part naming scheme, but some short predefined
8705 aliases are also supported. The full naming scheme encodes three pieces
8706 of information in the following pattern:
8707
8708 @example
8709 @var{architecture}-@var{vendor}-@var{os}
8710 @end example
8711
8712 For example, you can use the alias @code{sun4} as a @var{host} argument,
8713 or as the value for @var{target} in a @code{--target=@var{target}}
8714 option. The equivalent full name is @samp{sparc-sun-sunos4}.
8715
8716 The @code{configure} script accompanying GDB does not provide
8717 any query facility to list all supported host and target names or
8718 aliases. @code{configure} calls the Bourne shell script
8719 @code{config.sub} to map abbreviations to full names; you can read the
8720 script, if you wish, or you can use it to test your guesses on
8721 abbreviations---for example:
8722
8723 @smallexample
8724 % sh config.sub sun4
8725 sparc-sun-sunos4.1.1
8726 % sh config.sub sun3
8727 m68k-sun-sunos4.1.1
8728 % sh config.sub decstation
8729 mips-dec-ultrix4.2
8730 % sh config.sub hp300bsd
8731 m68k-hp-bsd
8732 % sh config.sub i386v
8733 i386-unknown-sysv
8734 % sh config.sub i786v
8735 Invalid configuration `i786v': machine `i786v' not recognized
8736 @end smallexample
8737
8738 @noindent
8739 @code{config.sub} is also distributed in the GDB source
8740 directory (@file{gdb-@value{GDBVN}}, for version @value{GDBVN}).
8741
8742 @node configure Options
8743 @section @code{configure} options
8744
8745 Here is a summary of the @code{configure} options and arguments that
8746 are most often useful for building @value{GDBN}. @code{configure} also has
8747 several other options not listed here. @inforef{What Configure
8748 Does,,configure.info}, for a full explanation of @code{configure}.
8749 @c FIXME: Would this be more, or less, useful as an xref (ref to printed
8750 @c manual in the printed manual, ref to info file only from the info file)?
8751
8752 @example
8753 configure @r{[}--help@r{]}
8754 @r{[}--prefix=@var{dir}@r{]}
8755 @r{[}--srcdir=@var{path}@r{]}
8756 @r{[}--norecursion@r{]} @r{[}--rm@r{]}
8757 @r{[}--target=@var{target}@r{]} @var{host}
8758 @end example
8759
8760 @noindent
8761 You may introduce options with a single @samp{-} rather than
8762 @samp{--} if you prefer; but you may abbreviate option names if you use
8763 @samp{--}.
8764
8765 @table @code
8766 @item --help
8767 Display a quick summary of how to invoke @code{configure}.
8768
8769 @item -prefix=@var{dir}
8770 Configure the source to install programs and files under directory
8771 @file{@var{dir}}.
8772
8773 @item --srcdir=@var{path}
8774 @strong{Warning: using this option requires GNU @code{make}, or another
8775 @code{make} that implements the @code{VPATH} feature.}@*
8776 Use this option to make configurations in directories separate from the
8777 GDB source directories. Among other things, you can use this to
8778 build (or maintain) several configurations simultaneously, in separate
8779 directories. @code{configure} writes configuration specific files in
8780 the current directory, but arranges for them to use the source in the
8781 directory @var{path}. @code{configure} will create directories under
8782 the working directory in parallel to the source directories below
8783 @var{path}.
8784
8785 @item --norecursion
8786 Configure only the directory level where @code{configure} is executed; do not
8787 propagate configuration to subdirectories.
8788
8789 @item --rm
8790 @emph{Remove} files otherwise built during configuration.
8791
8792 @c This does not work (yet if ever). FIXME.
8793 @c @item --parse=@var{lang} @dots{}
8794 @c Configure the GDB expression parser to parse the listed languages.
8795 @c @samp{all} configures GDB for all supported languages. To get a
8796 @c list of all supported languages, omit the argument. Without this
8797 @c option, GDB is configured to parse all supported languages.
8798
8799 @item --target=@var{target}
8800 Configure GDB for cross-debugging programs running on the specified
8801 @var{target}. Without this option, GDB is configured to debug
8802 programs that run on the same machine (@var{host}) as GDB itself.
8803
8804 There is no convenient way to generate a list of all available targets.
8805
8806 @item @var{host} @dots{}
8807 Configure GDB to run on the specified @var{host}.
8808
8809 There is no convenient way to generate a list of all available hosts.
8810 @end table
8811
8812 @noindent
8813 @code{configure} accepts other options, for compatibility with
8814 configuring other GNU tools recursively; but these are the only
8815 options that affect GDB or its supporting libraries.
8816 @end ifclear
8817
8818 @node Index
8819 @unnumbered Index
8820
8821 @printindex cp
8822
8823 @tex
8824 % I think something like @colophon should be in texinfo. In the
8825 % meantime:
8826 \long\def\colophon{\hbox to0pt{}\vfill
8827 \centerline{The body of this manual is set in}
8828 \centerline{\fontname\tenrm,}
8829 \centerline{with headings in {\bf\fontname\tenbf}}
8830 \centerline{and examples in {\tt\fontname\tentt}.}
8831 \centerline{{\it\fontname\tenit\/},}
8832 \centerline{{\bf\fontname\tenbf}, and}
8833 \centerline{{\sl\fontname\tensl\/}}
8834 \centerline{are used for emphasis.}\vfill}
8835 \page\colophon
8836 % Blame: pesch@cygnus.com, 1991.
8837 @end tex
8838
8839 @contents
8840 @bye