1 \input texinfo @c -*-texinfo-*-
3 @c Free Software Foundation, Inc.
6 @c makeinfo ignores cmds prev to setfilename, so its arg cannot make use
7 @c of @set vars. However, you can override filename with makeinfo -o.
12 @settitle Debugging with @value{GDBN}
13 @setchapternewpage odd
24 @c readline appendices use @vindex
27 @c !!set GDB manual's edition---not the same as GDB version!
30 @c !!set GDB manual's revision date
31 @set DATE February 1999
33 @c THIS MANUAL REQUIRES TEXINFO-2 macros and info-makers to format properly.
36 @c This is a dir.info fragment to support semi-automated addition of
37 @c manuals to an info tree. zoo@cygnus.com is developing this facility.
40 * Gdb: (gdb). The @sc{gnu} debugger.
47 This file documents the @sc{gnu} debugger @value{GDBN}.
50 This is the @value{EDITION} Edition, @value{DATE},
51 of @cite{Debugging with @value{GDBN}: the @sc{gnu} Source-Level Debugger}
52 for @value{GDBN} Version @value{GDBVN}.
54 Copyright (C) 1988-1999 Free Software Foundation, Inc.
56 Permission is granted to make and distribute verbatim copies of
57 this manual provided the copyright notice and this permission notice
58 are preserved on all copies.
61 Permission is granted to process this file through TeX and print the
62 results, provided the printed document carries copying permission
63 notice identical to this one except for the removal of this paragraph
64 (this paragraph not being relevant to the printed manual).
67 Permission is granted to copy and distribute modified versions of this
68 manual under the conditions for verbatim copying, provided also that the
69 entire resulting derived work is distributed under the terms of a
70 permission notice identical to this one.
72 Permission is granted to copy and distribute translations of this manual
73 into another language, under the above conditions for modified versions.
77 @title Debugging with @value{GDBN}
78 @subtitle The @sc{gnu} Source-Level Debugger
80 @subtitle @value{EDITION} Edition, for @value{GDBN} version @value{GDBVN}
81 @subtitle @value{DATE}
82 @author Richard M. Stallman and Roland H. Pesch
86 \hfill (Send bugs and comments on @value{GDBN} to bug-gdb\@gnu.org.)\par
87 \hfill {\it Debugging with @value{GDBN}}\par
88 \hfill \TeX{}info \texinfoversion\par
92 @c ISBN seems to be wrong...
94 @vskip 0pt plus 1filll
95 Copyright @copyright{} 1988-1999 Free Software Foundation, Inc.
97 Published by the Free Software Foundation @*
98 59 Temple Place - Suite 330, @*
99 Boston, MA 02111-1307 USA @*
100 Printed copies are available for $20 each. @*
101 ISBN 1-882114-11-6 @*
103 Permission is granted to make and distribute verbatim copies of
104 this manual provided the copyright notice and this permission notice
105 are preserved on all copies.
107 Permission is granted to copy and distribute modified versions of this
108 manual under the conditions for verbatim copying, provided also that the
109 entire resulting derived work is distributed under the terms of a
110 permission notice identical to this one.
112 Permission is granted to copy and distribute translations of this manual
113 into another language, under the above conditions for modified versions.
119 @top Debugging with @value{GDBN}
121 This file describes @value{GDBN}, the @sc{gnu} symbolic debugger.
123 This is the @value{EDITION} Edition, @value{DATE}, for @value{GDBN} Version
126 Copyright (C) 1988-1999 Free Software Foundation, Inc.
128 * Summary:: Summary of @value{GDBN}
129 * Sample Session:: A sample @value{GDBN} session
131 * Invocation:: Getting in and out of @value{GDBN}
132 * Commands:: @value{GDBN} commands
133 * Running:: Running programs under @value{GDBN}
134 * Stopping:: Stopping and continuing
135 * Stack:: Examining the stack
136 * Source:: Examining source files
137 * Data:: Examining data
139 * Languages:: Using @value{GDBN} with different languages
141 * Symbols:: Examining the symbol table
142 * Altering:: Altering execution
143 * GDB Files:: @value{GDBN} files
144 * Targets:: Specifying a debugging target
145 * Controlling GDB:: Controlling @value{GDBN}
146 * Sequences:: Canned sequences of commands
147 * Emacs:: Using @value{GDBN} under @sc{gnu} Emacs
149 * GDB Bugs:: Reporting bugs in @value{GDBN}
150 * Formatting Documentation:: How to format and print @value{GDBN} documentation
152 * Command Line Editing:: Command Line Editing
153 * Using History Interactively:: Using History Interactively
154 * Installing GDB:: Installing GDB
161 @unnumbered Summary of @value{GDBN}
163 The purpose of a debugger such as @value{GDBN} is to allow you to see what is
164 going on ``inside'' another program while it executes---or what another
165 program was doing at the moment it crashed.
167 @value{GDBN} can do four main kinds of things (plus other things in support of
168 these) to help you catch bugs in the act:
172 Start your program, specifying anything that might affect its behavior.
175 Make your program stop on specified conditions.
178 Examine what has happened, when your program has stopped.
181 Change things in your program, so you can experiment with correcting the
182 effects of one bug and go on to learn about another.
185 You can use @value{GDBN} to debug programs written in C and C++.
186 For more information, see @ref{Support,,Supported languages}.
187 For more information, see @ref{C,,C and C++}.
191 Support for Modula-2 and Chill is partial. For information on Modula-2,
192 see @ref{Modula-2,,Modula-2}. For information on Chill, see @ref{Chill}.
195 Debugging Pascal programs which use sets, subranges, file variables, or
196 nested functions does not currently work. @value{GDBN} does not support
197 entering expressions, printing values, or similar features using Pascal
201 @value{GDBN} can be used to debug programs written in Fortran, although
202 it may be necessary to refer to some variables with a trailing
206 * Free Software:: Freely redistributable software
207 * Contributors:: Contributors to GDB
211 @unnumberedsec Free software
213 @value{GDBN} is @dfn{free software}, protected by the @sc{gnu}
214 General Public License
215 (GPL). The GPL gives you the freedom to copy or adapt a licensed
216 program---but every person getting a copy also gets with it the
217 freedom to modify that copy (which means that they must get access to
218 the source code), and the freedom to distribute further copies.
219 Typical software companies use copyrights to limit your freedoms; the
220 Free Software Foundation uses the GPL to preserve these freedoms.
222 Fundamentally, the General Public License is a license which says that
223 you have these freedoms and that you cannot take these freedoms away
227 @unnumberedsec Contributors to GDB
229 Richard Stallman was the original author of GDB, and of many other
230 @sc{gnu} programs. Many others have contributed to its development.
231 This section attempts to credit major contributors. One of the virtues
232 of free software is that everyone is free to contribute to it; with
233 regret, we cannot actually acknowledge everyone here. The file
234 @file{ChangeLog} in the @value{GDBN} distribution approximates a
235 blow-by-blow account.
237 Changes much prior to version 2.0 are lost in the mists of time.
240 @emph{Plea:} Additions to this section are particularly welcome. If you
241 or your friends (or enemies, to be evenhanded) have been unfairly
242 omitted from this list, we would like to add your names!
245 So that they may not regard their many labors as thankless, we
246 particularly thank those who shepherded @value{GDBN} through major
248 Jim Blandy (release 4.18);
249 Jason Molenda (release 4.17);
250 Stan Shebs (release 4.14);
251 Fred Fish (releases 4.16, 4.15, 4.13, 4.12, 4.11, 4.10, and 4.9);
252 Stu Grossman and John Gilmore (releases 4.8, 4.7, 4.6, 4.5, and 4.4);
253 John Gilmore (releases 4.3, 4.2, 4.1, 4.0, and 3.9);
254 Jim Kingdon (releases 3.5, 3.4, and 3.3);
255 and Randy Smith (releases 3.2, 3.1, and 3.0).
257 Richard Stallman, assisted at various times by Peter TerMaat, Chris
258 Hanson, and Richard Mlynarik, handled releases through 2.8.
260 Michael Tiemann is the author of most of the @sc{gnu} C++ support in GDB,
261 with significant additional contributions from Per Bothner. James
262 Clark wrote the @sc{gnu} C++ demangler. Early work on C++ was by Peter
263 TerMaat (who also did much general update work leading to release 3.0).
265 @value{GDBN} 4 uses the BFD subroutine library to examine multiple
266 object-file formats; BFD was a joint project of David V.
267 Henkel-Wallace, Rich Pixley, Steve Chamberlain, and John Gilmore.
269 David Johnson wrote the original COFF support; Pace Willison did
270 the original support for encapsulated COFF.
272 Brent Benson of Harris Computer Systems contributed DWARF 2 support.
274 Adam de Boor and Bradley Davis contributed the ISI Optimum V support.
275 Per Bothner, Noboyuki Hikichi, and Alessandro Forin contributed MIPS
277 Jean-Daniel Fekete contributed Sun 386i support.
278 Chris Hanson improved the HP9000 support.
279 Noboyuki Hikichi and Tomoyuki Hasei contributed Sony/News OS 3 support.
280 David Johnson contributed Encore Umax support.
281 Jyrki Kuoppala contributed Altos 3068 support.
282 Jeff Law contributed HP PA and SOM support.
283 Keith Packard contributed NS32K support.
284 Doug Rabson contributed Acorn Risc Machine support.
285 Bob Rusk contributed Harris Nighthawk CX-UX support.
286 Chris Smith contributed Convex support (and Fortran debugging).
287 Jonathan Stone contributed Pyramid support.
288 Michael Tiemann contributed SPARC support.
289 Tim Tucker contributed support for the Gould NP1 and Gould Powernode.
290 Pace Willison contributed Intel 386 support.
291 Jay Vosburgh contributed Symmetry support.
293 Andreas Schwab contributed M68K Linux support.
295 Rich Schaefer and Peter Schauer helped with support of SunOS shared
298 Jay Fenlason and Roland McGrath ensured that @value{GDBN} and GAS agree
299 about several machine instruction sets.
301 Patrick Duval, Ted Goldstein, Vikram Koka and Glenn Engel helped develop
302 remote debugging. Intel Corporation, Wind River Systems, AMD, and ARM
303 contributed remote debugging modules for the i960, VxWorks, A29K UDI,
304 and RDI targets, respectively.
306 Brian Fox is the author of the readline libraries providing
307 command-line editing and command history.
309 Andrew Beers of SUNY Buffalo wrote the language-switching code, the
310 Modula-2 support, and contributed the Languages chapter of this manual.
312 Fred Fish wrote most of the support for Unix System Vr4.
313 He also enhanced the command-completion support to cover C++ overloaded
316 Hitachi America, Ltd. sponsored the support for H8/300, H8/500, and
319 NEC sponsored the support for the v850, Vr4xxx, and Vr5xxx processors.
321 Mitsubishi sponsored the support for D10V, D30V, and M32R/D processors.
323 Toshiba sponsored the support for the TX39 Mips processor.
325 Matsushita sponsored the support for the MN10200 and MN10300 processors.
327 Fujitsu sponsored the support for SPARClite and FR30 processors
329 Kung Hsu, Jeff Law, and Rick Sladkey added support for hardware
332 Michael Snyder added support for tracepoints.
334 Stu Grossman wrote gdbserver.
336 Jim Kingdon, Peter Schauer, Ian Taylor, and Stu Grossman made
337 nearly innumerable bug fixes and cleanups throughout GDB.
339 The following people at the Hewlett-Packard Company contributed
340 support for the PA-RISC 2.0 architecture, HP-UX 10.20, 10.30, and 11.0
341 (narrow mode), HP's implementation of kernel threads, HP's aC++
342 compiler, and the terminal user interface: Ben Krepp, Richard Title,
343 John Bishop, Susan Macchia, Kathy Mann, Satish Pai, India Paul, Steve
344 Rehrauer, and Elena Zannoni. Kim Haase provided HP-specific
345 information in this manual.
347 Cygnus Solutions has sponsored GDB maintenance and much of its
348 development since 1991. Cygnus engineers who have worked on GDB
349 fulltime include Mark Alexander, Jim Blandy, Per Bothner, Edith Epstein,
350 Chris Faylor, Fred Fish, Martin Hunt, Jim Ingham, John Gilmore, Stu
351 Grossman, Kung Hsu, Jim Kingdon, John Metzler, Fernando Nasser, Geoffrey
352 Noer, Dawn Perchik, Rich Pixley, Zdenek Radouch, Keith Seitz, Stan
353 Shebs, David Taylor, and Elena Zannoni. In addition, Dave Brolley, Ian
354 Carmichael, Steve Chamberlain, Nick Clifton, JT Conklin, Stan Cox, DJ
355 Delorie, Ulrich Drepper, Frank Eigler, Doug Evans, Sean Fagan, David
356 Henkel-Wallace, Richard Henderson, Jeff Holcomb, Jeff Law, Jim Lemke,
357 Tom Lord, Bob Manson, Michael Meissner, Jason Merrill, Catherine Moore,
358 Drew Moseley, Ken Raeburn, Gavin Romig-Koch, Rob Savoye, Jamie Smith,
359 Mike Stump, Ian Taylor, Angela Thomas, Michael Tiemann, Tom Tromey, Ron
360 Unrau, Jim Wilson, and David Zuhn have made contributions both large
365 @chapter A Sample @value{GDBN} Session
367 You can use this manual at your leisure to read all about @value{GDBN}.
368 However, a handful of commands are enough to get started using the
369 debugger. This chapter illustrates those commands.
372 In this sample session, we emphasize user input like this: @b{input},
373 to make it easier to pick out from the surrounding output.
376 @c FIXME: this example may not be appropriate for some configs, where
377 @c FIXME...primary interest is in remote use.
379 One of the preliminary versions of @sc{gnu} @code{m4} (a generic macro
380 processor) exhibits the following bug: sometimes, when we change its
381 quote strings from the default, the commands used to capture one macro
382 definition within another stop working. In the following short @code{m4}
383 session, we define a macro @code{foo} which expands to @code{0000}; we
384 then use the @code{m4} built-in @code{defn} to define @code{bar} as the
385 same thing. However, when we change the open quote string to
386 @code{<QUOTE>} and the close quote string to @code{<UNQUOTE>}, the same
387 procedure fails to define a new synonym @code{baz}:
396 @b{define(bar,defn(`foo'))}
400 @b{changequote(<QUOTE>,<UNQUOTE>)}
402 @b{define(baz,defn(<QUOTE>foo<UNQUOTE>))}
405 m4: End of input: 0: fatal error: EOF in string
409 Let us use @value{GDBN} to try to see what is going on.
412 $ @b{@value{GDBP} m4}
413 @c FIXME: this falsifies the exact text played out, to permit smallbook
414 @c FIXME... format to come out better.
415 @value{GDBN} is free software and you are welcome to distribute copies
416 of it under certain conditions; type "show copying" to see
418 There is absolutely no warranty for @value{GDBN}; type "show warranty"
421 @value{GDBN} @value{GDBVN}, Copyright 1999 Free Software Foundation, Inc...
426 @value{GDBN} reads only enough symbol data to know where to find the
427 rest when needed; as a result, the first prompt comes up very quickly.
428 We now tell @value{GDBN} to use a narrower display width than usual, so
429 that examples fit in this manual.
432 (@value{GDBP}) @b{set width 70}
436 We need to see how the @code{m4} built-in @code{changequote} works.
437 Having looked at the source, we know the relevant subroutine is
438 @code{m4_changequote}, so we set a breakpoint there with the @value{GDBN}
439 @code{break} command.
442 (@value{GDBP}) @b{break m4_changequote}
443 Breakpoint 1 at 0x62f4: file builtin.c, line 879.
447 Using the @code{run} command, we start @code{m4} running under @value{GDBN}
448 control; as long as control does not reach the @code{m4_changequote}
449 subroutine, the program runs as usual:
452 (@value{GDBP}) @b{run}
453 Starting program: /work/Editorial/gdb/gnu/m4/m4
461 To trigger the breakpoint, we call @code{changequote}. @value{GDBN}
462 suspends execution of @code{m4}, displaying information about the
463 context where it stops.
466 @b{changequote(<QUOTE>,<UNQUOTE>)}
468 Breakpoint 1, m4_changequote (argc=3, argv=0x33c70)
470 879 if (bad_argc(TOKEN_DATA_TEXT(argv[0]),argc,1,3))
474 Now we use the command @code{n} (@code{next}) to advance execution to
475 the next line of the current function.
479 882 set_quotes((argc >= 2) ? TOKEN_DATA_TEXT(argv[1])\
484 @code{set_quotes} looks like a promising subroutine. We can go into it
485 by using the command @code{s} (@code{step}) instead of @code{next}.
486 @code{step} goes to the next line to be executed in @emph{any}
487 subroutine, so it steps into @code{set_quotes}.
491 set_quotes (lq=0x34c78 "<QUOTE>", rq=0x34c88 "<UNQUOTE>")
493 530 if (lquote != def_lquote)
497 The display that shows the subroutine where @code{m4} is now
498 suspended (and its arguments) is called a stack frame display. It
499 shows a summary of the stack. We can use the @code{backtrace}
500 command (which can also be spelled @code{bt}), to see where we are
501 in the stack as a whole: the @code{backtrace} command displays a
502 stack frame for each active subroutine.
505 (@value{GDBP}) @b{bt}
506 #0 set_quotes (lq=0x34c78 "<QUOTE>", rq=0x34c88 "<UNQUOTE>")
508 #1 0x6344 in m4_changequote (argc=3, argv=0x33c70)
510 #2 0x8174 in expand_macro (sym=0x33320) at macro.c:242
511 #3 0x7a88 in expand_token (obs=0x0, t=209696, td=0xf7fffa30)
513 #4 0x79dc in expand_input () at macro.c:40
514 #5 0x2930 in main (argc=0, argv=0xf7fffb20) at m4.c:195
518 We step through a few more lines to see what happens. The first two
519 times, we can use @samp{s}; the next two times we use @code{n} to avoid
520 falling into the @code{xstrdup} subroutine.
524 0x3b5c 532 if (rquote != def_rquote)
526 0x3b80 535 lquote = (lq == nil || *lq == '\0') ? \
527 def_lquote : xstrdup(lq);
529 536 rquote = (rq == nil || *rq == '\0') ? def_rquote\
532 538 len_lquote = strlen(rquote);
536 The last line displayed looks a little odd; we can examine the variables
537 @code{lquote} and @code{rquote} to see if they are in fact the new left
538 and right quotes we specified. We use the command @code{p}
539 (@code{print}) to see their values.
542 (@value{GDBP}) @b{p lquote}
543 $1 = 0x35d40 "<QUOTE>"
544 (@value{GDBP}) @b{p rquote}
545 $2 = 0x35d50 "<UNQUOTE>"
549 @code{lquote} and @code{rquote} are indeed the new left and right quotes.
550 To look at some context, we can display ten lines of source
551 surrounding the current line with the @code{l} (@code{list}) command.
557 535 lquote = (lq == nil || *lq == '\0') ? def_lquote\
559 536 rquote = (rq == nil || *rq == '\0') ? def_rquote\
562 538 len_lquote = strlen(rquote);
563 539 len_rquote = strlen(lquote);
570 Let us step past the two lines that set @code{len_lquote} and
571 @code{len_rquote}, and then examine the values of those variables.
575 539 len_rquote = strlen(lquote);
578 (@value{GDBP}) @b{p len_lquote}
580 (@value{GDBP}) @b{p len_rquote}
585 That certainly looks wrong, assuming @code{len_lquote} and
586 @code{len_rquote} are meant to be the lengths of @code{lquote} and
587 @code{rquote} respectively. We can set them to better values using
588 the @code{p} command, since it can print the value of
589 any expression---and that expression can include subroutine calls and
593 (@value{GDBP}) @b{p len_lquote=strlen(lquote)}
595 (@value{GDBP}) @b{p len_rquote=strlen(rquote)}
600 Is that enough to fix the problem of using the new quotes with the
601 @code{m4} built-in @code{defn}? We can allow @code{m4} to continue
602 executing with the @code{c} (@code{continue}) command, and then try the
603 example that caused trouble initially:
609 @b{define(baz,defn(<QUOTE>foo<UNQUOTE>))}
616 Success! The new quotes now work just as well as the default ones. The
617 problem seems to have been just the two typos defining the wrong
618 lengths. We allow @code{m4} exit by giving it an EOF as input:
622 Program exited normally.
626 The message @samp{Program exited normally.} is from @value{GDBN}; it
627 indicates @code{m4} has finished executing. We can end our @value{GDBN}
628 session with the @value{GDBN} @code{quit} command.
631 (@value{GDBP}) @b{quit}
635 @chapter Getting In and Out of @value{GDBN}
637 This chapter discusses how to start @value{GDBN}, and how to get out of it.
641 type @samp{@value{GDBP}} to start @value{GDBN}.
643 type @kbd{quit} or @kbd{C-d} to exit.
647 * Invoking GDB:: How to start @value{GDBN}
648 * Quitting GDB:: How to quit @value{GDBN}
649 * Shell Commands:: How to use shell commands inside @value{GDBN}
653 @section Invoking @value{GDBN}
655 Invoke @value{GDBN} by running the program @code{@value{GDBP}}. Once started,
656 @value{GDBN} reads commands from the terminal until you tell it to exit.
658 You can also run @code{@value{GDBP}} with a variety of arguments and options,
659 to specify more of your debugging environment at the outset.
661 The command-line options described here are designed
662 to cover a variety of situations; in some environments, some of these
663 options may effectively be unavailable.
665 The most usual way to start @value{GDBN} is with one argument,
666 specifying an executable program:
669 @value{GDBP} @var{program}
673 You can also start with both an executable program and a core file
677 @value{GDBP} @var{program} @var{core}
680 You can, instead, specify a process ID as a second argument, if you want
681 to debug a running process:
684 @value{GDBP} @var{program} 1234
688 would attach @value{GDBN} to process @code{1234} (unless you also have a file
689 named @file{1234}; @value{GDBN} does check for a core file first).
691 Taking advantage of the second command-line argument requires a fairly
692 complete operating system; when you use @value{GDBN} as a remote debugger
693 attached to a bare board, there may not be any notion of ``process'',
694 and there is often no way to get a core dump.
696 You can run @code{gdb} without printing the front material, which describes
697 @value{GDBN}'s non-warranty, by specifying @code{-silent}:
704 You can further control how @value{GDBN} starts up by using command-line
705 options. @value{GDBN} itself can remind you of the options available.
715 to display all available options and briefly describe their use
716 (@samp{@value{GDBP} -h} is a shorter equivalent).
718 All options and command line arguments you give are processed
719 in sequential order. The order makes a difference when the
720 @samp{-x} option is used.
724 * File Options:: Choosing files
725 * Mode Options:: Choosing modes
729 @subsection Choosing files
731 When @value{GDBN} starts
732 specifying an executable file and core file (or process ID). This is
733 the same as if the arguments were specified by the @samp{-se} and
734 @samp{-c} options respectively. (@value{GDBN} reads the first argument
735 that does not have an associated option flag as equivalent to the
736 @samp{-se} option followed by that argument; and the second argument
737 that does not have an associated option flag, if any, as equivalent to
738 the @samp{-c} option followed by that argument.)
740 If @value{GDBN} has not been configured to included core file support,
741 such as for most embedded targets, then it will complain about a second
742 argument and ignore it.
744 Many options have both long and short forms; both are shown in the
745 following list. @value{GDBN} also recognizes the long forms if you truncate
746 them, so long as enough of the option is present to be unambiguous.
747 (If you prefer, you can flag option arguments with @samp{--} rather
748 than @samp{-}, though we illustrate the more usual convention.)
751 @item -symbols @var{file}
753 Read symbol table from file @var{file}.
755 @item -exec @var{file}
757 Use file @var{file} as the executable file to execute when appropriate,
758 and for examining pure data in conjunction with a core dump.
761 Read symbol table from file @var{file} and use it as the executable
764 @item -core @var{file}
766 Use file @var{file} as a core dump to examine.
768 @item -c @var{number}
769 Connect to process ID @var{number}, as with the @code{attach} command
770 (unless there is a file in core-dump format named @var{number}, in which
771 case @samp{-c} specifies that file as a core dump to read).
773 @item -command @var{file}
775 Execute @value{GDBN} commands from file @var{file}. @xref{Command
776 Files,, Command files}.
778 @item -directory @var{directory}
779 @itemx -d @var{directory}
780 Add @var{directory} to the path to search for source files.
784 @emph{Warning: this option depends on operating system facilities that are not
785 supported on all systems.}@*
786 If memory-mapped files are available on your system through the @code{mmap}
787 system call, you can use this option
788 to have @value{GDBN} write the symbols from your
789 program into a reusable file in the current directory. If the program you are debugging is
790 called @file{/tmp/fred}, the mapped symbol file is @file{./fred.syms}.
791 Future @value{GDBN} debugging sessions notice the presence of this file,
792 and can quickly map in symbol information from it, rather than reading
793 the symbol table from the executable program.
795 The @file{.syms} file is specific to the host machine where @value{GDBN}
796 is run. It holds an exact image of the internal @value{GDBN} symbol
797 table. It cannot be shared across multiple host platforms.
801 Read each symbol file's entire symbol table immediately, rather than
802 the default, which is to read it incrementally as it is needed.
803 This makes startup slower, but makes future operations faster.
807 The @code{-mapped} and @code{-readnow} options are typically combined in
808 order to build a @file{.syms} file that contains complete symbol
809 information. (@xref{Files,,Commands to specify files}, for
810 information on @file{.syms} files.) A simple @value{GDBN} invocation to do
811 nothing but build a @file{.syms} file for future use is:
814 gdb -batch -nx -mapped -readnow programname
818 @subsection Choosing modes
820 You can run @value{GDBN} in various alternative modes---for example, in
821 batch mode or quiet mode.
826 Do not execute commands from any initialization files (normally called
827 @file{.gdbinit}, or @file{gdb.ini} on PCs). Normally, the commands in
828 these files are executed after all the command options and arguments
829 have been processed. @xref{Command Files,,Command files}.
833 ``Quiet''. Do not print the introductory and copyright messages. These
834 messages are also suppressed in batch mode.
837 Run in batch mode. Exit with status @code{0} after processing all the
838 command files specified with @samp{-x} (and all commands from
839 initialization files, if not inhibited with @samp{-n}). Exit with
840 nonzero status if an error occurs in executing the @value{GDBN} commands
841 in the command files.
843 Batch mode may be useful for running @value{GDBN} as a filter, for example to
844 download and run a program on another computer; in order to make this
845 more useful, the message
848 Program exited normally.
852 (which is ordinarily issued whenever a program running under @value{GDBN} control
853 terminates) is not issued when running in batch mode.
855 @item -cd @var{directory}
856 Run @value{GDBN} using @var{directory} as its working directory,
857 instead of the current directory.
861 @sc{gnu} Emacs sets this option when it runs @value{GDBN} as a
862 subprocess. It tells @value{GDBN} to output the full file name and line
863 number in a standard, recognizable fashion each time a stack frame is
864 displayed (which includes each time your program stops). This
865 recognizable format looks like two @samp{\032} characters, followed by
866 the file name, line number and character position separated by colons,
867 and a newline. The Emacs-to-@value{GDBN} interface program uses the two
868 @samp{\032} characters as a signal to display the source code for the
872 Set the line speed (baud rate or bits per second) of any serial
873 interface used by @value{GDBN} for remote debugging.
875 @item -tty @var{device}
876 Run using @var{device} for your program's standard input and output.
877 @c FIXME: kingdon thinks there is more to -tty. Investigate.
879 @c resolve the situation of these eventually
881 @c Use a Terminal User Interface. For information, use your Web browser to
882 @c read the file @file{TUI.html}, which is usually installed in the
883 @c directory @code{/opt/langtools/wdb/doc} on HP-UX systems. Do not use
884 @c this option if you run @value{GDBN} from Emacs (see @pxref{Emacs, ,Using
885 @c @value{GDBN} under @sc{gnu} Emacs}).
888 @c Run in XDB compatibility mode, allowing the use of certain XDB commands.
889 @c For information, see the file @file{xdb_trans.html}, which is usually
890 @c installed in the directory @code{/opt/langtools/wdb/doc} on HP-UX
896 @section Quitting @value{GDBN}
897 @cindex exiting @value{GDBN}
898 @cindex leaving @value{GDBN}
901 @kindex quit @r{[}@var{expression}@r{]}
904 To exit @value{GDBN}, use the @code{quit} command (abbreviated @code{q}), or
905 type an end-of-file character (usually @kbd{C-d}). If you do not supply
906 @var{expression}, @value{GDBN} will terminate normally; otherwise it will
907 terminate using the result of @var{expression} as the error code.
911 An interrupt (often @kbd{C-c}) does not exit from @value{GDBN}, but rather
912 terminates the action of any @value{GDBN} command that is in progress and
913 returns to @value{GDBN} command level. It is safe to type the interrupt
914 character at any time because @value{GDBN} does not allow it to take effect
915 until a time when it is safe.
917 If you have been using @value{GDBN} to control an attached process or
918 device, you can release it with the @code{detach} command
919 (@pxref{Attach, ,Debugging an already-running process}).
922 @section Shell commands
924 If you need to execute occasional shell commands during your
925 debugging session, there is no need to leave or suspend @value{GDBN}; you can
926 just use the @code{shell} command.
931 @item shell @var{command string}
932 Invoke a standard shell to execute @var{command string}.
933 If it exists, the environment variable @code{SHELL} determines which
934 shell to run. Otherwise @value{GDBN} uses @code{/bin/sh}.
937 The utility @code{make} is often needed in development environments.
938 You do not have to use the @code{shell} command for this purpose in
944 @item make @var{make-args}
945 Execute the @code{make} program with the specified
946 arguments. This is equivalent to @samp{shell make @var{make-args}}.
950 @chapter @value{GDBN} Commands
952 You can abbreviate a @value{GDBN} command to the first few letters of the command
953 name, if that abbreviation is unambiguous; and you can repeat certain
954 @value{GDBN} commands by typing just @key{RET}. You can also use the @key{TAB}
955 key to get @value{GDBN} to fill out the rest of a word in a command (or to
956 show you the alternatives available, if there is more than one possibility).
959 * Command Syntax:: How to give commands to @value{GDBN}
960 * Completion:: Command completion
961 * Help:: How to ask @value{GDBN} for help
965 @section Command syntax
967 A @value{GDBN} command is a single line of input. There is no limit on
968 how long it can be. It starts with a command name, which is followed by
969 arguments whose meaning depends on the command name. For example, the
970 command @code{step} accepts an argument which is the number of times to
971 step, as in @samp{step 5}. You can also use the @code{step} command
972 with no arguments. Some command names do not allow any arguments.
975 @value{GDBN} command names may always be truncated if that abbreviation is
976 unambiguous. Other possible command abbreviations are listed in the
977 documentation for individual commands. In some cases, even ambiguous
978 abbreviations are allowed; for example, @code{s} is specially defined as
979 equivalent to @code{step} even though there are other commands whose
980 names start with @code{s}. You can test abbreviations by using them as
981 arguments to the @code{help} command.
983 @cindex repeating commands
985 A blank line as input to @value{GDBN} (typing just @key{RET}) means to
986 repeat the previous command. Certain commands (for example, @code{run})
987 will not repeat this way; these are commands whose unintentional
988 repetition might cause trouble and which you are unlikely to want to
991 The @code{list} and @code{x} commands, when you repeat them with
992 @key{RET}, construct new arguments rather than repeating
993 exactly as typed. This permits easy scanning of source or memory.
995 @value{GDBN} can also use @key{RET} in another way: to partition lengthy
996 output, in a way similar to the common utility @code{more}
997 (@pxref{Screen Size,,Screen size}). Since it is easy to press one
998 @key{RET} too many in this situation, @value{GDBN} disables command
999 repetition after any command that generates this sort of display.
1003 Any text from a @kbd{#} to the end of the line is a comment; it does
1004 nothing. This is useful mainly in command files (@pxref{Command
1005 Files,,Command files}).
1008 @section Command completion
1011 @cindex word completion
1012 @value{GDBN} can fill in the rest of a word in a command for you, if there is
1013 only one possibility; it can also show you what the valid possibilities
1014 are for the next word in a command, at any time. This works for @value{GDBN}
1015 commands, @value{GDBN} subcommands, and the names of symbols in your program.
1017 Press the @key{TAB} key whenever you want @value{GDBN} to fill out the rest
1018 of a word. If there is only one possibility, @value{GDBN} fills in the
1019 word, and waits for you to finish the command (or press @key{RET} to
1020 enter it). For example, if you type
1022 @c FIXME "@key" does not distinguish its argument sufficiently to permit
1023 @c complete accuracy in these examples; space introduced for clarity.
1024 @c If texinfo enhancements make it unnecessary, it would be nice to
1025 @c replace " @key" by "@key" in the following...
1027 (@value{GDBP}) info bre @key{TAB}
1031 @value{GDBN} fills in the rest of the word @samp{breakpoints}, since that is
1032 the only @code{info} subcommand beginning with @samp{bre}:
1035 (@value{GDBP}) info breakpoints
1039 You can either press @key{RET} at this point, to run the @code{info
1040 breakpoints} command, or backspace and enter something else, if
1041 @samp{breakpoints} does not look like the command you expected. (If you
1042 were sure you wanted @code{info breakpoints} in the first place, you
1043 might as well just type @key{RET} immediately after @samp{info bre},
1044 to exploit command abbreviations rather than command completion).
1046 If there is more than one possibility for the next word when you press
1047 @key{TAB}, @value{GDBN} sounds a bell. You can either supply more
1048 characters and try again, or just press @key{TAB} a second time;
1049 @value{GDBN} displays all the possible completions for that word. For
1050 example, you might want to set a breakpoint on a subroutine whose name
1051 begins with @samp{make_}, but when you type @kbd{b make_@key{TAB}} @value{GDBN}
1052 just sounds the bell. Typing @key{TAB} again displays all the
1053 function names in your program that begin with those characters, for
1057 (@value{GDBP}) b make_ @key{TAB}
1058 @exdent @value{GDBN} sounds bell; press @key{TAB} again, to see:
1059 make_a_section_from_file make_environ
1060 make_abs_section make_function_type
1061 make_blockvector make_pointer_type
1062 make_cleanup make_reference_type
1063 make_command make_symbol_completion_list
1064 (@value{GDBP}) b make_
1068 After displaying the available possibilities, @value{GDBN} copies your
1069 partial input (@samp{b make_} in the example) so you can finish the
1072 If you just want to see the list of alternatives in the first place, you
1073 can press @kbd{M-?} rather than pressing @key{TAB} twice. @kbd{M-?}
1074 means @kbd{@key{META} ?}. You can type this either by holding down a
1075 key designated as the @key{META} shift on your keyboard (if there is
1076 one) while typing @kbd{?}, or as @key{ESC} followed by @kbd{?}.
1078 @cindex quotes in commands
1079 @cindex completion of quoted strings
1080 Sometimes the string you need, while logically a ``word'', may contain
1081 parentheses or other characters that @value{GDBN} normally excludes from
1082 its notion of a word. To permit word completion to work in this
1083 situation, you may enclose words in @code{'} (single quote marks) in
1084 @value{GDBN} commands.
1086 The most likely situation where you might need this is in typing the
1087 name of a C++ function. This is because C++ allows function overloading
1088 (multiple definitions of the same function, distinguished by argument
1089 type). For example, when you want to set a breakpoint you may need to
1090 distinguish whether you mean the version of @code{name} that takes an
1091 @code{int} parameter, @code{name(int)}, or the version that takes a
1092 @code{float} parameter, @code{name(float)}. To use the word-completion
1093 facilities in this situation, type a single quote @code{'} at the
1094 beginning of the function name. This alerts @value{GDBN} that it may need to
1095 consider more information than usual when you press @key{TAB} or
1096 @kbd{M-?} to request word completion:
1099 (@value{GDBP}) b 'bubble( @key{M-?}
1100 bubble(double,double) bubble(int,int)
1101 (@value{GDBP}) b 'bubble(
1104 In some cases, @value{GDBN} can tell that completing a name requires using
1105 quotes. When this happens, @value{GDBN} inserts the quote for you (while
1106 completing as much as it can) if you do not type the quote in the first
1110 (@value{GDBP}) b bub @key{TAB}
1111 @exdent @value{GDBN} alters your input line to the following, and rings a bell:
1112 (@value{GDBP}) b 'bubble(
1116 In general, @value{GDBN} can tell that a quote is needed (and inserts it) if
1117 you have not yet started typing the argument list when you ask for
1118 completion on an overloaded symbol.
1120 For more information about overloaded functions, @pxref{C plus plus
1121 expressions, ,C++ expressions}. You can use the command @code{set
1122 overload-resolution off} to disable overload resolution;
1123 @pxref{Debugging C plus plus, ,@value{GDBN} features for C++}.
1127 @section Getting help
1128 @cindex online documentation
1131 You can always ask @value{GDBN} itself for information on its commands,
1132 using the command @code{help}.
1138 You can use @code{help} (abbreviated @code{h}) with no arguments to
1139 display a short list of named classes of commands:
1143 List of classes of commands:
1145 running -- Running the program
1146 stack -- Examining the stack
1147 data -- Examining data
1148 breakpoints -- Making program stop at certain points
1149 files -- Specifying and examining files
1150 status -- Status inquiries
1151 support -- Support facilities
1152 user-defined -- User-defined commands
1153 aliases -- Aliases of other commands
1154 obscure -- Obscure features
1156 Type "help" followed by a class name for a list of
1157 commands in that class.
1158 Type "help" followed by command name for full
1160 Command name abbreviations are allowed if unambiguous.
1164 @item help @var{class}
1165 Using one of the general help classes as an argument, you can get a
1166 list of the individual commands in that class. For example, here is the
1167 help display for the class @code{status}:
1170 (@value{GDBP}) help status
1175 @c Line break in "show" line falsifies real output, but needed
1176 @c to fit in smallbook page size.
1177 show -- Generic command for showing things set
1179 info -- Generic command for printing status
1181 Type "help" followed by command name for full
1183 Command name abbreviations are allowed if unambiguous.
1187 @item help @var{command}
1188 With a command name as @code{help} argument, @value{GDBN} displays a
1189 short paragraph on how to use that command.
1192 @item complete @var{args}
1193 The @code{complete @var{args}} command lists all the possible completions
1194 for the beginning of a command. Use @var{args} to specify the beginning of the
1195 command you want completed. For example:
1201 @noindent results in:
1211 @noindent This is intended for use by @sc{gnu} Emacs.
1214 In addition to @code{help}, you can use the @value{GDBN} commands @code{info}
1215 and @code{show} to inquire about the state of your program, or the state
1216 of @value{GDBN} itself. Each command supports many topics of inquiry; this
1217 manual introduces each of them in the appropriate context. The listings
1218 under @code{info} and under @code{show} in the Index point to
1219 all the sub-commands. @xref{Index}.
1226 This command (abbreviated @code{i}) is for describing the state of your
1227 program. For example, you can list the arguments given to your program
1228 with @code{info args}, list the registers currently in use with @code{info
1229 registers}, or list the breakpoints you have set with @code{info breakpoints}.
1230 You can get a complete list of the @code{info} sub-commands with
1231 @w{@code{help info}}.
1235 You can assign the result of an expression to an environment variable with
1236 @code{set}. For example, you can set the @value{GDBN} prompt to a $-sign with
1237 @code{set prompt $}.
1241 In contrast to @code{info}, @code{show} is for describing the state of
1242 @value{GDBN} itself.
1243 You can change most of the things you can @code{show}, by using the
1244 related command @code{set}; for example, you can control what number
1245 system is used for displays with @code{set radix}, or simply inquire
1246 which is currently in use with @code{show radix}.
1249 To display all the settable parameters and their current
1250 values, you can use @code{show} with no arguments; you may also use
1251 @code{info set}. Both commands produce the same display.
1252 @c FIXME: "info set" violates the rule that "info" is for state of
1253 @c FIXME...program. Ck w/ GNU: "info set" to be called something else,
1254 @c FIXME...or change desc of rule---eg "state of prog and debugging session"?
1258 Here are three miscellaneous @code{show} subcommands, all of which are
1259 exceptional in lacking corresponding @code{set} commands:
1262 @kindex show version
1263 @cindex version number
1265 Show what version of @value{GDBN} is running. You should include this
1266 information in @value{GDBN} bug-reports. If multiple versions of @value{GDBN} are in
1267 use at your site, you may occasionally want to determine which version
1268 of @value{GDBN} you are running; as @value{GDBN} evolves, new commands are introduced,
1269 and old ones may wither away. The version number is also announced
1270 when you start @value{GDBN}.
1272 @kindex show copying
1274 Display information about permission for copying @value{GDBN}.
1276 @kindex show warranty
1278 Display the @sc{gnu} ``NO WARRANTY'' statement.
1282 @chapter Running Programs Under @value{GDBN}
1284 When you run a program under @value{GDBN}, you must first generate
1285 debugging information when you compile it.
1287 You may start @value{GDBN} with its arguments, if any, in an environment
1288 of your choice. If you are doing native debugging, you may redirect
1289 your program's input and output, debug an already running process, or
1290 kill a child process.
1293 * Compilation:: Compiling for debugging
1294 * Starting:: Starting your program
1295 * Arguments:: Your program's arguments
1296 * Environment:: Your program's environment
1298 * Working Directory:: Your program's working directory
1299 * Input/Output:: Your program's input and output
1300 * Attach:: Debugging an already-running process
1301 * Kill Process:: Killing the child process
1302 * Process Information:: Additional process information
1304 * Threads:: Debugging programs with multiple threads
1305 * Processes:: Debugging programs with multiple processes
1309 @section Compiling for debugging
1311 In order to debug a program effectively, you need to generate
1312 debugging information when you compile it. This debugging information
1313 is stored in the object file; it describes the data type of each
1314 variable or function and the correspondence between source line numbers
1315 and addresses in the executable code.
1317 To request debugging information, specify the @samp{-g} option when you run
1320 Many C compilers are unable to handle the @samp{-g} and @samp{-O}
1321 options together. Using those compilers, you cannot generate optimized
1322 executables containing debugging information.
1324 @value{NGCC}, the @sc{gnu} C compiler, supports @samp{-g} with or
1325 without @samp{-O}, making it possible to debug optimized code. We
1326 recommend that you @emph{always} use @samp{-g} whenever you compile a
1327 program. You may think your program is correct, but there is no sense
1328 in pushing your luck.
1330 @cindex optimized code, debugging
1331 @cindex debugging optimized code
1332 When you debug a program compiled with @samp{-g -O}, remember that the
1333 optimizer is rearranging your code; the debugger shows you what is
1334 really there. Do not be too surprised when the execution path does not
1335 exactly match your source file! An extreme example: if you define a
1336 variable, but never use it, @value{GDBN} never sees that
1337 variable---because the compiler optimizes it out of existence.
1339 Some things do not work as well with @samp{-g -O} as with just
1340 @samp{-g}, particularly on machines with instruction scheduling. If in
1341 doubt, recompile with @samp{-g} alone, and if this fixes the problem,
1342 please report it to us as a bug (including a test case!).
1344 Older versions of the @sc{gnu} C compiler permitted a variant option
1345 @w{@samp{-gg}} for debugging information. @value{GDBN} no longer supports this
1346 format; if your @sc{gnu} C compiler has this option, do not use it.
1350 @section Starting your program
1358 Use the @code{run} command to start your program under @value{GDBN}.
1359 You must first specify the program name (except on VxWorks) with an
1360 argument to @value{GDBN} (@pxref{Invocation, ,Getting In and Out of
1361 @value{GDBN}}), or by using the @code{file} or @code{exec-file} command
1362 (@pxref{Files, ,Commands to specify files}).
1366 If you are running your program in an execution environment that
1367 supports processes, @code{run} creates an inferior process and makes
1368 that process run your program. (In environments without processes,
1369 @code{run} jumps to the start of your program.)
1371 The execution of a program is affected by certain information it
1372 receives from its superior. @value{GDBN} provides ways to specify this
1373 information, which you must do @emph{before} starting your program. (You
1374 can change it after starting your program, but such changes only affect
1375 your program the next time you start it.) This information may be
1376 divided into four categories:
1379 @item The @emph{arguments.}
1380 Specify the arguments to give your program as the arguments of the
1381 @code{run} command. If a shell is available on your target, the shell
1382 is used to pass the arguments, so that you may use normal conventions
1383 (such as wildcard expansion or variable substitution) in describing
1385 In Unix systems, you can control which shell is used with the
1386 @code{SHELL} environment variable.
1387 @xref{Arguments, ,Your program's arguments}.
1389 @item The @emph{environment.}
1390 Your program normally inherits its environment from @value{GDBN}, but you can
1391 use the @value{GDBN} commands @code{set environment} and @code{unset
1392 environment} to change parts of the environment that affect
1393 your program. @xref{Environment, ,Your program's environment}.
1395 @item The @emph{working directory.}
1396 Your program inherits its working directory from @value{GDBN}. You can set
1397 the @value{GDBN} working directory with the @code{cd} command in @value{GDBN}.
1398 @xref{Working Directory, ,Your program's working directory}.
1400 @item The @emph{standard input and output.}
1401 Your program normally uses the same device for standard input and
1402 standard output as @value{GDBN} is using. You can redirect input and output
1403 in the @code{run} command line, or you can use the @code{tty} command to
1404 set a different device for your program.
1405 @xref{Input/Output, ,Your program's input and output}.
1408 @emph{Warning:} While input and output redirection work, you cannot use
1409 pipes to pass the output of the program you are debugging to another
1410 program; if you attempt this, @value{GDBN} is likely to wind up debugging the
1414 When you issue the @code{run} command, your program begins to execute
1415 immediately. @xref{Stopping, ,Stopping and continuing}, for discussion
1416 of how to arrange for your program to stop. Once your program has
1417 stopped, you may call functions in your program, using the @code{print}
1418 or @code{call} commands. @xref{Data, ,Examining Data}.
1420 If the modification time of your symbol file has changed since the last
1421 time @value{GDBN} read its symbols, @value{GDBN} discards its symbol
1422 table, and reads it again. When it does this, @value{GDBN} tries to retain
1423 your current breakpoints.
1426 @section Your program's arguments
1428 @cindex arguments (to your program)
1429 The arguments to your program can be specified by the arguments of the
1431 They are passed to a shell, which expands wildcard characters and
1432 performs redirection of I/O, and thence to your program. Your
1433 @code{SHELL} environment variable (if it exists) specifies what shell
1434 @value{GDBN} uses. If you do not define @code{SHELL}, @value{GDBN} uses
1437 @code{run} with no arguments uses the same arguments used by the previous
1438 @code{run}, or those set by the @code{set args} command.
1443 Specify the arguments to be used the next time your program is run. If
1444 @code{set args} has no arguments, @code{run} executes your program
1445 with no arguments. Once you have run your program with arguments,
1446 using @code{set args} before the next @code{run} is the only way to run
1447 it again without arguments.
1451 Show the arguments to give your program when it is started.
1455 @section Your program's environment
1457 @cindex environment (of your program)
1458 The @dfn{environment} consists of a set of environment variables and
1459 their values. Environment variables conventionally record such things as
1460 your user name, your home directory, your terminal type, and your search
1461 path for programs to run. Usually you set up environment variables with
1462 the shell and they are inherited by all the other programs you run. When
1463 debugging, it can be useful to try running your program with a modified
1464 environment without having to start @value{GDBN} over again.
1468 @item path @var{directory}
1469 Add @var{directory} to the front of the @code{PATH} environment variable
1470 (the search path for executables), for both @value{GDBN} and your program.
1471 You may specify several directory names, separated by @samp{:} or
1472 whitespace. If @var{directory} is already in the path, it is moved to
1473 the front, so it is searched sooner.
1475 You can use the string @samp{$cwd} to refer to whatever is the current
1476 working directory at the time @value{GDBN} searches the path. If you
1477 use @samp{.} instead, it refers to the directory where you executed the
1478 @code{path} command. @value{GDBN} replaces @samp{.} in the
1479 @var{directory} argument (with the current path) before adding
1480 @var{directory} to the search path.
1481 @c 'path' is explicitly nonrepeatable, but RMS points out it is silly to
1482 @c document that, since repeating it would be a no-op.
1486 Display the list of search paths for executables (the @code{PATH}
1487 environment variable).
1489 @kindex show environment
1490 @item show environment @r{[}@var{varname}@r{]}
1491 Print the value of environment variable @var{varname} to be given to
1492 your program when it starts. If you do not supply @var{varname},
1493 print the names and values of all environment variables to be given to
1494 your program. You can abbreviate @code{environment} as @code{env}.
1496 @kindex set environment
1497 @item set environment @var{varname} @r{[}=@var{value}@r{]}
1498 Set environment variable @var{varname} to @var{value}. The value
1499 changes for your program only, not for @value{GDBN} itself. @var{value} may
1500 be any string; the values of environment variables are just strings, and
1501 any interpretation is supplied by your program itself. The @var{value}
1502 parameter is optional; if it is eliminated, the variable is set to a
1504 @c "any string" here does not include leading, trailing
1505 @c blanks. Gnu asks: does anyone care?
1507 For example, this command:
1514 tells a Unix program, when subsequently run, that its user is named
1515 @samp{foo}. (The spaces around @samp{=} are used for clarity here; they
1516 are not actually required.)
1518 @kindex unset environment
1519 @item unset environment @var{varname}
1520 Remove variable @var{varname} from the environment to be passed to your
1521 program. This is different from @samp{set env @var{varname} =};
1522 @code{unset environment} removes the variable from the environment,
1523 rather than assigning it an empty value.
1526 @emph{Warning:} @value{GDBN} runs your program using the shell indicated
1527 by your @code{SHELL} environment variable if it exists (or
1528 @code{/bin/sh} if not). If your @code{SHELL} variable names a shell
1529 that runs an initialization file---such as @file{.cshrc} for C-shell, or
1530 @file{.bashrc} for BASH---any variables you set in that file affect
1531 your program. You may wish to move setting of environment variables to
1532 files that are only run when you sign on, such as @file{.login} or
1535 @node Working Directory
1536 @section Your program's working directory
1538 @cindex working directory (of your program)
1539 Each time you start your program with @code{run}, it inherits its
1540 working directory from the current working directory of @value{GDBN}.
1541 The @value{GDBN} working directory is initially whatever it inherited
1542 from its parent process (typically the shell), but you can specify a new
1543 working directory in @value{GDBN} with the @code{cd} command.
1545 The @value{GDBN} working directory also serves as a default for the commands
1546 that specify files for @value{GDBN} to operate on. @xref{Files, ,Commands to
1551 @item cd @var{directory}
1552 Set the @value{GDBN} working directory to @var{directory}.
1556 Print the @value{GDBN} working directory.
1560 @section Your program's input and output
1565 By default, the program you run under @value{GDBN} does input and output to
1566 the same terminal that @value{GDBN} uses. @value{GDBN} switches the terminal
1567 to its own terminal modes to interact with you, but it records the terminal
1568 modes your program was using and switches back to them when you continue
1569 running your program.
1572 @kindex info terminal
1574 Displays information recorded by @value{GDBN} about the terminal modes your
1578 You can redirect your program's input and/or output using shell
1579 redirection with the @code{run} command. For example,
1586 starts your program, diverting its output to the file @file{outfile}.
1589 @cindex controlling terminal
1590 Another way to specify where your program should do input and output is
1591 with the @code{tty} command. This command accepts a file name as
1592 argument, and causes this file to be the default for future @code{run}
1593 commands. It also resets the controlling terminal for the child
1594 process, for future @code{run} commands. For example,
1601 directs that processes started with subsequent @code{run} commands
1602 default to do input and output on the terminal @file{/dev/ttyb} and have
1603 that as their controlling terminal.
1605 An explicit redirection in @code{run} overrides the @code{tty} command's
1606 effect on the input/output device, but not its effect on the controlling
1609 When you use the @code{tty} command or redirect input in the @code{run}
1610 command, only the input @emph{for your program} is affected. The input
1611 for @value{GDBN} still comes from your terminal.
1614 @section Debugging an already-running process
1619 @item attach @var{process-id}
1620 This command attaches to a running process---one that was started
1621 outside @value{GDBN}. (@code{info files} shows your active
1622 targets.) The command takes as argument a process ID. The usual way to
1623 find out the process-id of a Unix process is with the @code{ps} utility,
1624 or with the @samp{jobs -l} shell command.
1626 @code{attach} does not repeat if you press @key{RET} a second time after
1627 executing the command.
1630 To use @code{attach}, your program must be running in an environment
1631 which supports processes; for example, @code{attach} does not work for
1632 programs on bare-board targets that lack an operating system. You must
1633 also have permission to send the process a signal.
1635 When you use @code{attach}, the debugger finds the program running in
1636 the process first by looking in the current working directory, then (if
1637 the program is not found) by using the source file search path
1638 (@pxref{Source Path, ,Specifying source directories}). You can also use
1639 the @code{file} command to load the program. @xref{Files, ,Commands to
1642 The first thing @value{GDBN} does after arranging to debug the specified
1643 process is to stop it. You can examine and modify an attached process
1644 with all the @value{GDBN} commands that are ordinarily available when
1645 you start processes with @code{run}. You can insert breakpoints; you
1646 can step and continue; you can modify storage. If you would rather the
1647 process continue running, you may use the @code{continue} command after
1648 attaching @value{GDBN} to the process.
1653 When you have finished debugging the attached process, you can use the
1654 @code{detach} command to release it from @value{GDBN} control. Detaching
1655 the process continues its execution. After the @code{detach} command,
1656 that process and @value{GDBN} become completely independent once more, and you
1657 are ready to @code{attach} another process or start one with @code{run}.
1658 @code{detach} does not repeat if you press @key{RET} again after
1659 executing the command.
1662 If you exit @value{GDBN} or use the @code{run} command while you have an
1663 attached process, you kill that process. By default, @value{GDBN} asks
1664 for confirmation if you try to do either of these things; you can
1665 control whether or not you need to confirm by using the @code{set
1666 confirm} command (@pxref{Messages/Warnings, ,Optional warnings and
1670 @section Killing the child process
1675 Kill the child process in which your program is running under @value{GDBN}.
1678 This command is useful if you wish to debug a core dump instead of a
1679 running process. @value{GDBN} ignores any core dump file while your program
1682 On some operating systems, a program cannot be executed outside @value{GDBN}
1683 while you have breakpoints set on it inside @value{GDBN}. You can use the
1684 @code{kill} command in this situation to permit running your program
1685 outside the debugger.
1687 The @code{kill} command is also useful if you wish to recompile and
1688 relink your program, since on many systems it is impossible to modify an
1689 executable file while it is running in a process. In this case, when you
1690 next type @code{run}, @value{GDBN} notices that the file has changed, and
1691 reads the symbol table again (while trying to preserve your current
1692 breakpoint settings).
1694 @node Process Information
1695 @section Additional process information
1698 @cindex process image
1700 Some operating systems provide a facility called @samp{/proc} that can
1701 be used to examine the image of a running process using file-system
1702 subroutines. If @value{GDBN} is configured for an operating system with this
1703 facility, the command @code{info proc} is available to report on several
1704 kinds of information about the process running your program.
1705 @code{info proc} works only on SVR4 systems that support @code{procfs}.
1706 This includes OSF/1 (Digital Unix), Solaris, Irix, and Unixware,
1707 but not HP-UX or Linux, for example.
1712 Summarize available information about the process.
1714 @kindex info proc mappings
1715 @item info proc mappings
1716 Report on the address ranges accessible in the program, with information
1717 on whether your program may read, write, or execute each range.
1719 @kindex info proc times
1720 @item info proc times
1721 Starting time, user CPU time, and system CPU time for your program and
1724 @kindex info proc id
1726 Report on the process IDs related to your program: its own process ID,
1727 the ID of its parent, the process group ID, and the session ID.
1729 @kindex info proc status
1730 @item info proc status
1731 General information on the state of the process. If the process is
1732 stopped, this report includes the reason for stopping, and any signal
1736 Show all the above information about the process.
1740 @section Debugging programs with multiple threads
1742 @cindex threads of execution
1743 @cindex multiple threads
1744 @cindex switching threads
1745 In some operating systems, such as HP-UX and Solaris, a single program
1746 may have more than one @dfn{thread} of execution. The precise semantics
1747 of threads differ from one operating system to another, but in general
1748 the threads of a single program are akin to multiple processes---except
1749 that they share one address space (that is, they can all examine and
1750 modify the same variables). On the other hand, each thread has its own
1751 registers and execution stack, and perhaps private memory.
1753 @value{GDBN} provides these facilities for debugging multi-thread
1757 @item automatic notification of new threads
1758 @item @samp{thread @var{threadno}}, a command to switch among threads
1759 @item @samp{info threads}, a command to inquire about existing threads
1760 @item @samp{thread apply [@var{threadno}] [@var{all}] @var{args}},
1761 a command to apply a command to a list of threads
1762 @item thread-specific breakpoints
1766 @emph{Warning:} These facilities are not yet available on every
1767 @value{GDBN} configuration where the operating system supports threads.
1768 If your @value{GDBN} does not support threads, these commands have no
1769 effect. For example, a system without thread support shows no output
1770 from @samp{info threads}, and always rejects the @code{thread} command,
1774 (@value{GDBP}) info threads
1775 (@value{GDBP}) thread 1
1776 Thread ID 1 not known. Use the "info threads" command to
1777 see the IDs of currently known threads.
1779 @c FIXME to implementors: how hard would it be to say "sorry, this GDB
1780 @c doesn't support threads"?
1783 @cindex focus of debugging
1784 @cindex current thread
1785 The @value{GDBN} thread debugging facility allows you to observe all
1786 threads while your program runs---but whenever @value{GDBN} takes
1787 control, one thread in particular is always the focus of debugging.
1788 This thread is called the @dfn{current thread}. Debugging commands show
1789 program information from the perspective of the current thread.
1791 @kindex New @var{systag}
1792 @cindex thread identifier (system)
1793 @c FIXME-implementors!! It would be more helpful if the [New...] message
1794 @c included GDB's numeric thread handle, so you could just go to that
1795 @c thread without first checking `info threads'.
1796 Whenever @value{GDBN} detects a new thread in your program, it displays
1797 the target system's identification for the thread with a message in the
1798 form @samp{[New @var{systag}]}. @var{systag} is a thread identifier
1799 whose form varies depending on the particular system. For example, on
1800 LynxOS, you might see
1803 [New process 35 thread 27]
1807 when @value{GDBN} notices a new thread. In contrast, on an SGI system,
1808 the @var{systag} is simply something like @samp{process 368}, with no
1811 @c FIXME!! (1) Does the [New...] message appear even for the very first
1812 @c thread of a program, or does it only appear for the
1813 @c second---i.e., when it becomes obvious we have a multithread
1815 @c (2) *Is* there necessarily a first thread always? Or do some
1816 @c multithread systems permit starting a program with multiple
1817 @c threads ab initio?
1819 @cindex thread number
1820 @cindex thread identifier (GDB)
1821 For debugging purposes, @value{GDBN} associates its own thread
1822 number---always a single integer---with each thread in your program.
1825 @kindex info threads
1827 Display a summary of all threads currently in your
1828 program. @value{GDBN} displays for each thread (in this order):
1831 @item the thread number assigned by @value{GDBN}
1833 @item the target system's thread identifier (@var{systag})
1835 @item the current stack frame summary for that thread
1839 An asterisk @samp{*} to the left of the @value{GDBN} thread number
1840 indicates the current thread.
1844 @c end table here to get a little more width for example
1847 (@value{GDBP}) info threads
1848 3 process 35 thread 27 0x34e5 in sigpause ()
1849 2 process 35 thread 23 0x34e5 in sigpause ()
1850 * 1 process 35 thread 13 main (argc=1, argv=0x7ffffff8)
1856 @cindex thread number
1857 @cindex thread identifier (GDB)
1858 For debugging purposes, @value{GDBN} associates its own thread
1859 number---a small integer assigned in thread-creation order---with each
1860 thread in your program.
1862 @kindex New @var{systag}
1863 @cindex thread identifier (system)
1864 @c FIXME-implementors!! It would be more helpful if the [New...] message
1865 @c included GDB's numeric thread handle, so you could just go to that
1866 @c thread without first checking `info threads'.
1867 Whenever @value{GDBN} detects a new thread in your program, it displays
1868 both @value{GDBN}'s thread number and the target system's identification for the thread with a message in the
1869 form @samp{[New @var{systag}]}. @var{systag} is a thread identifier
1870 whose form varies depending on the particular system. For example, on
1874 [New thread 2 (system thread 26594)]
1878 when @value{GDBN} notices a new thread.
1881 @kindex info threads
1883 Display a summary of all threads currently in your
1884 program. @value{GDBN} displays for each thread (in this order):
1887 @item the thread number assigned by @value{GDBN}
1889 @item the target system's thread identifier (@var{systag})
1891 @item the current stack frame summary for that thread
1895 An asterisk @samp{*} to the left of the @value{GDBN} thread number
1896 indicates the current thread.
1900 @c end table here to get a little more width for example
1903 (@value{GDBP}) info threads
1904 * 3 system thread 26607 worker (wptr=0x7b09c318 "@@") at quicksort.c:137
1905 2 system thread 26606 0x7b0030d8 in __ksleep () from /usr/lib/libc.2
1906 1 system thread 27905 0x7b003498 in _brk () from /usr/lib/libc.2
1910 @kindex thread @var{threadno}
1911 @item thread @var{threadno}
1912 Make thread number @var{threadno} the current thread. The command
1913 argument @var{threadno} is the internal @value{GDBN} thread number, as
1914 shown in the first field of the @samp{info threads} display.
1915 @value{GDBN} responds by displaying the system identifier of the thread
1916 you selected, and its current stack frame summary:
1919 @c FIXME!! This example made up; find a @value{GDBN} w/threads and get real one
1920 (@value{GDBP}) thread 2
1921 [Switching to process 35 thread 23]
1922 0x34e5 in sigpause ()
1926 As with the @samp{[New @dots{}]} message, the form of the text after
1927 @samp{Switching to} depends on your system's conventions for identifying
1930 @kindex thread apply
1931 @item thread apply [@var{threadno}] [@var{all}] @var{args}
1932 The @code{thread apply} command allows you to apply a command to one or
1933 more threads. Specify the numbers of the threads that you want affected
1934 with the command argument @var{threadno}. @var{threadno} is the internal
1935 @value{GDBN} thread number, as shown in the first field of the @samp{info
1936 threads} display. To apply a command to all threads, use
1937 @code{thread apply all} @var{args}.
1940 @cindex automatic thread selection
1941 @cindex switching threads automatically
1942 @cindex threads, automatic switching
1943 Whenever @value{GDBN} stops your program, due to a breakpoint or a
1944 signal, it automatically selects the thread where that breakpoint or
1945 signal happened. @value{GDBN} alerts you to the context switch with a
1946 message of the form @samp{[Switching to @var{systag}]} to identify the
1949 @xref{Thread Stops,,Stopping and starting multi-thread programs}, for
1950 more information about how @value{GDBN} behaves when you stop and start
1951 programs with multiple threads.
1953 @xref{Set Watchpoints,,Setting watchpoints}, for information about
1954 watchpoints in programs with multiple threads.
1957 @section Debugging programs with multiple processes
1959 @cindex fork, debugging programs which call
1960 @cindex multiple processes
1961 @cindex processes, multiple
1962 On most systems, @value{GDBN} has no special support for debugging
1963 programs which create additional processes using the @code{fork}
1964 function. When a program forks, @value{GDBN} will continue to debug the
1965 parent process and the child process will run unimpeded. If you have
1966 set a breakpoint in any code which the child then executes, the child
1967 will get a @code{SIGTRAP} signal which (unless it catches the signal)
1968 will cause it to terminate.
1970 However, if you want to debug the child process there is a workaround
1971 which isn't too painful. Put a call to @code{sleep} in the code which
1972 the child process executes after the fork. It may be useful to sleep
1973 only if a certain environment variable is set, or a certain file exists,
1974 so that the delay need not occur when you don't want to run @value{GDBN}
1975 on the child. While the child is sleeping, use the @code{ps} program to
1976 get its process ID. Then tell @value{GDBN} (a new invocation of
1977 @value{GDBN} if you are also debugging the parent process) to attach to
1978 the child process (see @ref{Attach}). From that point on you can debug
1979 the child process just like any other process which you attached to.
1981 On HP-UX (11.x and later only?), @value{GDBN} provides support for
1982 debugging programs that create additional processes using the
1983 @code{fork} or @code{vfork} function.
1985 By default, when a program forks, @value{GDBN} will continue to debug
1986 the parent process and the child process will run unimpeded.
1988 If you want to follow the child process instead of the parent process,
1989 use the command @w{@code{set follow-fork-mode}}.
1992 @kindex set follow-fork-mode
1993 @item set follow-fork-mode @var{mode}
1994 Set the debugger response to a program call of @code{fork} or
1995 @code{vfork}. A call to @code{fork} or @code{vfork} creates a new
1996 process. The @var{mode} can be:
2000 The original process is debugged after a fork. The child process runs
2004 The new process is debugged after a fork. The parent process runs
2008 The debugger will ask for one of the above choices.
2011 @item show follow-fork-mode
2012 Display the current debugger response to a fork or vfork call.
2015 If you ask to debug a child process and a @code{vfork} is followed by an
2016 @code{exec}, @value{GDBN} executes the new target up to the first
2017 breakpoint in the new target. If you have a breakpoint set on
2018 @code{main} in your original program, the breakpoint will also be set on
2019 the child process's @code{main}.
2021 When a child process is spawned by @code{vfork}, you cannot debug the
2022 child or parent until an @code{exec} call completes.
2024 If you issue a @code{run} command to @value{GDBN} after an @code{exec}
2025 call executes, the new target restarts. To restart the parent process,
2026 use the @code{file} command with the parent executable name as its
2029 You can use the @code{catch} command to make @value{GDBN} stop whenever
2030 a @code{fork}, @code{vfork}, or @code{exec} call is made. @xref{Set
2031 Catchpoints, ,Setting catchpoints}.
2034 @chapter Stopping and Continuing
2036 The principal purposes of using a debugger are so that you can stop your
2037 program before it terminates; or so that, if your program runs into
2038 trouble, you can investigate and find out why.
2040 Inside @value{GDBN}, your program may stop for any of several reasons,
2041 such as a signal, a breakpoint, or reaching a new line after a
2042 @value{GDBN} command such as @code{step}. You may then examine and
2043 change variables, set new breakpoints or remove old ones, and then
2044 continue execution. Usually, the messages shown by @value{GDBN} provide
2045 ample explanation of the status of your program---but you can also
2046 explicitly request this information at any time.
2049 @kindex info program
2051 Display information about the status of your program: whether it is
2052 running or not, what process it is, and why it stopped.
2056 * Breakpoints:: Breakpoints, watchpoints, and catchpoints
2057 * Continuing and Stepping:: Resuming execution
2059 * Thread Stops:: Stopping and starting multi-thread programs
2063 @section Breakpoints, watchpoints, and catchpoints
2066 A @dfn{breakpoint} makes your program stop whenever a certain point in
2067 the program is reached. For each breakpoint, you can add conditions to
2068 control in finer detail whether your program stops. You can set
2069 breakpoints with the @code{break} command and its variants (@pxref{Set
2070 Breaks, ,Setting breakpoints}), to specify the place where your program
2071 should stop by line number, function name or exact address in the
2074 In HP-UX, SunOS 4.x, SVR4, and Alpha OSF/1 configurations, you can set
2075 breakpoints in shared libraries before the executable is run. There is
2076 a minor limitation on HP-UX systems: you must wait until the executable
2077 is run in order to set breakpoints in shared library routines that are
2078 not called directly by the program (for example, routines that are
2079 arguments in a @code{pthread_create} call).
2082 @cindex memory tracing
2083 @cindex breakpoint on memory address
2084 @cindex breakpoint on variable modification
2085 A @dfn{watchpoint} is a special breakpoint that stops your program
2086 when the value of an expression changes. You must use a different
2087 command to set watchpoints (@pxref{Set Watchpoints, ,Setting
2088 watchpoints}), but aside from that, you can manage a watchpoint like
2089 any other breakpoint: you enable, disable, and delete both breakpoints
2090 and watchpoints using the same commands.
2092 You can arrange to have values from your program displayed automatically
2093 whenever @value{GDBN} stops at a breakpoint. @xref{Auto Display,,
2097 @cindex breakpoint on events
2098 A @dfn{catchpoint} is another special breakpoint that stops your program
2099 when a certain kind of event occurs, such as the throwing of a C++
2100 exception or the loading of a library. As with watchpoints, you use a
2101 different command to set a catchpoint (@pxref{Set Catchpoints, ,Setting
2102 catchpoints}), but aside from that, you can manage a catchpoint like any
2103 other breakpoint. (To stop when your program receives a signal, use the
2104 @code{handle} command; @pxref{Signals, ,Signals}.)
2106 @cindex breakpoint numbers
2107 @cindex numbers for breakpoints
2108 @value{GDBN} assigns a number to each breakpoint, watchpoint, or
2109 catchpoint when you create it; these numbers are successive integers
2110 starting with one. In many of the commands for controlling various
2111 features of breakpoints you use the breakpoint number to say which
2112 breakpoint you want to change. Each breakpoint may be @dfn{enabled} or
2113 @dfn{disabled}; if disabled, it has no effect on your program until you
2117 * Set Breaks:: Setting breakpoints
2118 * Set Watchpoints:: Setting watchpoints
2119 * Set Catchpoints:: Setting catchpoints
2120 * Delete Breaks:: Deleting breakpoints
2121 * Disabling:: Disabling breakpoints
2122 * Conditions:: Break conditions
2123 * Break Commands:: Breakpoint command lists
2124 * Breakpoint Menus:: Breakpoint menus
2126 @c * Error in Breakpoints:: ``Cannot insert breakpoints''
2130 @subsection Setting breakpoints
2132 @c FIXME LMB what does GDB do if no code on line of breakpt?
2133 @c consider in particular declaration with/without initialization.
2135 @c FIXME 2 is there stuff on this already? break at fun start, already init?
2140 @cindex latest breakpoint
2141 Breakpoints are set with the @code{break} command (abbreviated
2142 @code{b}). The debugger convenience variable @samp{$bpnum} records the
2143 number of the breakpoints you've set most recently; see @ref{Convenience
2144 Vars,, Convenience variables}, for a discussion of what you can do with
2145 convenience variables.
2147 You have several ways to say where the breakpoint should go.
2150 @item break @var{function}
2151 Set a breakpoint at entry to function @var{function}.
2152 When using source languages that permit overloading of symbols, such as
2153 C++, @var{function} may refer to more than one possible place to break.
2154 @xref{Breakpoint Menus,,Breakpoint menus}, for a discussion of that situation.
2156 @item break +@var{offset}
2157 @itemx break -@var{offset}
2158 Set a breakpoint some number of lines forward or back from the position
2159 at which execution stopped in the currently selected frame.
2161 @item break @var{linenum}
2162 Set a breakpoint at line @var{linenum} in the current source file.
2163 That file is the last file whose source text was printed. This
2164 breakpoint stops your program just before it executes any of the
2167 @item break @var{filename}:@var{linenum}
2168 Set a breakpoint at line @var{linenum} in source file @var{filename}.
2170 @item break @var{filename}:@var{function}
2171 Set a breakpoint at entry to function @var{function} found in file
2172 @var{filename}. Specifying a file name as well as a function name is
2173 superfluous except when multiple files contain similarly named
2176 @item break *@var{address}
2177 Set a breakpoint at address @var{address}. You can use this to set
2178 breakpoints in parts of your program which do not have debugging
2179 information or source files.
2182 When called without any arguments, @code{break} sets a breakpoint at
2183 the next instruction to be executed in the selected stack frame
2184 (@pxref{Stack, ,Examining the Stack}). In any selected frame but the
2185 innermost, this makes your program stop as soon as control
2186 returns to that frame. This is similar to the effect of a
2187 @code{finish} command in the frame inside the selected frame---except
2188 that @code{finish} does not leave an active breakpoint. If you use
2189 @code{break} without an argument in the innermost frame, @value{GDBN} stops
2190 the next time it reaches the current location; this may be useful
2193 @value{GDBN} normally ignores breakpoints when it resumes execution, until at
2194 least one instruction has been executed. If it did not do this, you
2195 would be unable to proceed past a breakpoint without first disabling the
2196 breakpoint. This rule applies whether or not the breakpoint already
2197 existed when your program stopped.
2199 @item break @dots{} if @var{cond}
2200 Set a breakpoint with condition @var{cond}; evaluate the expression
2201 @var{cond} each time the breakpoint is reached, and stop only if the
2202 value is nonzero---that is, if @var{cond} evaluates as true.
2203 @samp{@dots{}} stands for one of the possible arguments described
2204 above (or no argument) specifying where to break. @xref{Conditions,
2205 ,Break conditions}, for more information on breakpoint conditions.
2208 @item tbreak @var{args}
2209 Set a breakpoint enabled only for one stop. @var{args} are the
2210 same as for the @code{break} command, and the breakpoint is set in the same
2211 way, but the breakpoint is automatically deleted after the first time your
2212 program stops there. @xref{Disabling, ,Disabling breakpoints}.
2215 @item hbreak @var{args}
2216 Set a hardware-assisted breakpoint. @var{args} are the same as for the
2217 @code{break} command and the breakpoint is set in the same way, but the
2218 breakpoint requires hardware support and some target hardware may not
2219 have this support. The main purpose of this is EPROM/ROM code
2220 debugging, so you can set a breakpoint at an instruction without
2221 changing the instruction. This can be used with the new trap-generation
2222 provided by SPARClite DSU. DSU will generate traps when a program accesses
2223 some data or instruction address that is assigned to the debug registers.
2224 However the hardware breakpoint registers can only take two data breakpoints,
2225 and @value{GDBN} will reject this command if more than two are used.
2226 Delete or disable unused hardware breakpoints before setting
2227 new ones. @xref{Conditions, ,Break conditions}.
2230 @item thbreak @var{args}
2231 Set a hardware-assisted breakpoint enabled only for one stop. @var{args}
2232 are the same as for the @code{hbreak} command and the breakpoint is set in
2233 the same way. However, like the @code{tbreak} command,
2234 the breakpoint is automatically deleted after the
2235 first time your program stops there. Also, like the @code{hbreak}
2236 command, the breakpoint requires hardware support and some target hardware
2237 may not have this support. @xref{Disabling, ,Disabling breakpoints}.
2238 Also @xref{Conditions, ,Break conditions}.
2241 @cindex regular expression
2242 @item rbreak @var{regex}
2243 @c FIXME what kind of regexp?
2244 Set breakpoints on all functions matching the regular expression
2245 @var{regex}. This command
2246 sets an unconditional breakpoint on all matches, printing a list of all
2247 breakpoints it set. Once these breakpoints are set, they are treated
2248 just like the breakpoints set with the @code{break} command. You can
2249 delete them, disable them, or make them conditional the same way as any
2252 When debugging C++ programs, @code{rbreak} is useful for setting
2253 breakpoints on overloaded functions that are not members of any special
2256 @kindex info breakpoints
2257 @cindex @code{$_} and @code{info breakpoints}
2258 @item info breakpoints @r{[}@var{n}@r{]}
2259 @itemx info break @r{[}@var{n}@r{]}
2260 @itemx info watchpoints @r{[}@var{n}@r{]}
2261 Print a table of all breakpoints, watchpoints, and catchpoints set and
2262 not deleted, with the following columns for each breakpoint:
2265 @item Breakpoint Numbers
2267 Breakpoint, watchpoint, or catchpoint.
2269 Whether the breakpoint is marked to be disabled or deleted when hit.
2270 @item Enabled or Disabled
2271 Enabled breakpoints are marked with @samp{y}. @samp{n} marks breakpoints
2272 that are not enabled.
2274 Where the breakpoint is in your program, as a memory address
2276 Where the breakpoint is in the source for your program, as a file and
2281 If a breakpoint is conditional, @code{info break} shows the condition on
2282 the line following the affected breakpoint; breakpoint commands, if any,
2283 are listed after that.
2286 @code{info break} with a breakpoint
2287 number @var{n} as argument lists only that breakpoint. The
2288 convenience variable @code{$_} and the default examining-address for
2289 the @code{x} command are set to the address of the last breakpoint
2290 listed (@pxref{Memory, ,Examining memory}).
2293 @code{info break} displays a count of the number of times the breakpoint
2294 has been hit. This is especially useful in conjunction with the
2295 @code{ignore} command. You can ignore a large number of breakpoint
2296 hits, look at the breakpoint info to see how many times the breakpoint
2297 was hit, and then run again, ignoring one less than that number. This
2298 will get you quickly to the last hit of that breakpoint.
2301 @value{GDBN} allows you to set any number of breakpoints at the same place in
2302 your program. There is nothing silly or meaningless about this. When
2303 the breakpoints are conditional, this is even useful
2304 (@pxref{Conditions, ,Break conditions}).
2306 @cindex negative breakpoint numbers
2307 @cindex internal @value{GDBN} breakpoints
2308 @value{GDBN} itself sometimes sets breakpoints in your program for special
2309 purposes, such as proper handling of @code{longjmp} (in C programs).
2310 These internal breakpoints are assigned negative numbers, starting with
2311 @code{-1}; @samp{info breakpoints} does not display them.
2313 You can see these breakpoints with the @value{GDBN} maintenance command
2314 @samp{maint info breakpoints}.
2317 @kindex maint info breakpoints
2318 @item maint info breakpoints
2319 Using the same format as @samp{info breakpoints}, display both the
2320 breakpoints you've set explicitly, and those @value{GDBN} is using for
2321 internal purposes. Internal breakpoints are shown with negative
2322 breakpoint numbers. The type column identifies what kind of breakpoint
2327 Normal, explicitly set breakpoint.
2330 Normal, explicitly set watchpoint.
2333 Internal breakpoint, used to handle correctly stepping through
2334 @code{longjmp} calls.
2336 @item longjmp resume
2337 Internal breakpoint at the target of a @code{longjmp}.
2340 Temporary internal breakpoint used by the @value{GDBN} @code{until} command.
2343 Temporary internal breakpoint used by the @value{GDBN} @code{finish} command.
2346 Shared library events.
2353 @node Set Watchpoints
2354 @subsection Setting watchpoints
2356 @cindex setting watchpoints
2357 @cindex software watchpoints
2358 @cindex hardware watchpoints
2359 You can use a watchpoint to stop execution whenever the value of an
2360 expression changes, without having to predict a particular place where
2363 Depending on your system, watchpoints may be implemented in software or
2364 hardware. GDB does software watchpointing by single-stepping your
2365 program and testing the variable's value each time, which is hundreds of
2366 times slower than normal execution. (But this may still be worth it, to
2367 catch errors where you have no clue what part of your program is the
2370 On some systems, such as HP-UX and Linux, GDB includes support for
2371 hardware watchpoints, which do not slow down the running of your
2376 @item watch @var{expr}
2377 Set a watchpoint for an expression. @value{GDBN} will break when @var{expr}
2378 is written into by the program and its value changes.
2381 @item rwatch @var{expr}
2382 Set a watchpoint that will break when watch @var{expr} is read by the program.
2385 @item awatch @var{expr}
2386 Set a watchpoint that will break when @var{args} is read and written into
2389 @kindex info watchpoints
2390 @item info watchpoints
2391 This command prints a list of watchpoints, breakpoints, and catchpoints;
2392 it is the same as @code{info break}.
2395 @value{GDBN} sets a @dfn{hardware watchpoint} if possible. Hardware
2396 watchpoints execute very quickly, and the debugger reports a change in
2397 value at the exact instruction where the change occurs. If @value{GDBN}
2398 cannot set a hardware watchpoint, it sets a software watchpoint, which
2399 executes more slowly and reports the change in value at the next
2400 statement, not the instruction, after the change occurs.
2402 When you issue the @code{watch} command, @value{GDBN} reports
2405 Hardware watchpoint @var{num}: @var{expr}
2409 if it was able to set a hardware watchpoint.
2411 Currently, the @code{awatch} and @code{rwatch} commands can only set
2412 hardware watchpoints, because accesses to data that don't change the
2413 value of the watched expression cannot be detected without examining
2414 every instruction as it is being executed, and @value{GDBN} does not do
2415 that currently. If @value{GDBN} finds that it is unable to set a
2416 hardware breakpoint with the @code{awatch} or @code{rwatch} command, it
2417 will print a message like this:
2420 Expression cannot be implemented with read/access watchpoint.
2423 Sometimes, @value{GDBN} cannot set a hardware watchpoint because the
2424 data type of the watched expression is wider than what a hardware
2425 watchpoint on the target machine can handle. For example, some systems
2426 can only watch regions that are up to 4 bytes wide; on such systems you
2427 cannot set hardware watchpoints for an expression that yields a
2428 double-precision floating-point number (which is typically 8 bytes
2429 wide). As a work-around, it might be possible to break the large region
2430 into a series of smaller ones and watch them with separate watchpoints.
2432 If you set too many hardware watchpoints, @value{GDBN} might be unable
2433 to insert all of them when you resume the execution of your program.
2434 Since the precise number of active watchpoints is unknown until such
2435 time as the program is about to be resumed, @value{GDBN} might not be
2436 able to warn you about this when you set the watchpoints, and the
2437 warning will be printed only when the program is resumed:
2440 Hardware watchpoint @var{num}: Could not insert watchpoint
2444 If this happens, delete or disable some of the watchpoints.
2446 The SPARClite DSU will generate traps when a program accesses some data
2447 or instruction address that is assigned to the debug registers. For the
2448 data addresses, DSU facilitates the @code{watch} command. However the
2449 hardware breakpoint registers can only take two data watchpoints, and
2450 both watchpoints must be the same kind. For example, you can set two
2451 watchpoints with @code{watch} commands, two with @code{rwatch} commands,
2452 @strong{or} two with @code{awatch} commands, but you cannot set one
2453 watchpoint with one command and the other with a different command.
2454 @value{GDBN} will reject the command if you try to mix watchpoints.
2455 Delete or disable unused watchpoint commands before setting new ones.
2457 If you call a function interactively using @code{print} or @code{call},
2458 any watchpoints you have set will be inactive until GDB reaches another
2459 kind of breakpoint or the call completes.
2461 @value{GDBN} automatically deletes watchpoints that watch local
2462 (automatic) variables, or expressions that involve such variables, when
2463 they go out of scope, that is, when the execution leaves the block in
2464 which these variables were defined. In particular, when the program
2465 being debugged terminates, @emph{all} local variables go out of scope,
2466 and so only watchpoints that watch global variables remain set. If you
2467 rerun the program, you will need to set all such watchpoints again. One
2468 way of doing that would be to set a code breakpoint at the entry to the
2469 @code{main} function and when it breaks, set all the watchpoints.
2472 @cindex watchpoints and threads
2473 @cindex threads and watchpoints
2474 @emph{Warning:} In multi-thread programs, watchpoints have only limited
2475 usefulness. With the current watchpoint implementation, @value{GDBN}
2476 can only watch the value of an expression @emph{in a single thread}. If
2477 you are confident that the expression can only change due to the current
2478 thread's activity (and if you are also confident that no other thread
2479 can become current), then you can use watchpoints as usual. However,
2480 @value{GDBN} may not notice when a non-current thread's activity changes
2483 @emph{HP-UX Warning:} In multi-thread programs, software watchpoints
2484 have only limited usefulness. If @value{GDBN} creates a software
2485 watchpoint, it can only watch the value of an expression @emph{in a
2486 single thread}. If you are confident that the expression can only
2487 change due to the current thread's activity (and if you are also
2488 confident that no other thread can become current), then you can use
2489 software watchpoints as usual. However, @value{GDBN} may not notice
2490 when a non-current thread's activity changes the expression. (Hardware
2491 watchpoints, in contrast, watch an expression in all threads.)
2494 @node Set Catchpoints
2495 @subsection Setting catchpoints
2497 @cindex exception handlers
2498 @cindex event handling
2500 You can use @dfn{catchpoints} to cause the debugger to stop for certain
2501 kinds of program events, such as C++ exceptions or the loading of a
2502 shared library. Use the @code{catch} command to set a catchpoint.
2506 @item catch @var{event}
2507 Stop when @var{event} occurs. @var{event} can be any of the following:
2511 The throwing of a C++ exception.
2515 The catching of a C++ exception.
2519 A call to @code{exec}. This is currently only available for HP-UX.
2523 A call to @code{fork}. This is currently only available for HP-UX.
2527 A call to @code{vfork}. This is currently only available for HP-UX.
2530 @itemx load @var{libname}
2532 The dynamic loading of any shared library, or the loading of the library
2533 @var{libname}. This is currently only available for HP-UX.
2536 @itemx unload @var{libname}
2537 @kindex catch unload
2538 The unloading of any dynamically loaded shared library, or the unloading
2539 of the library @var{libname}. This is currently only available for HP-UX.
2542 @item tcatch @var{event}
2543 Set a catchpoint that is enabled only for one stop. The catchpoint is
2544 automatically deleted after the first time the event is caught.
2548 Use the @code{info break} command to list the current catchpoints.
2550 There are currently some limitations to C++ exception handling
2551 (@code{catch throw} and @code{catch catch}) in @value{GDBN}:
2555 If you call a function interactively, @value{GDBN} normally returns
2556 control to you when the function has finished executing. If the call
2557 raises an exception, however, the call may bypass the mechanism that
2558 returns control to you and cause your program either to abort or to
2559 simply continue running until it hits a breakpoint, catches a signal
2560 that @value{GDBN} is listening for, or exits. This is the case even if
2561 you set a catchpoint for the exception; catchpoints on exceptions are
2562 disabled within interactive calls.
2565 You cannot raise an exception interactively.
2568 You cannot install an exception handler interactively.
2571 @cindex raise exceptions
2572 Sometimes @code{catch} is not the best way to debug exception handling:
2573 if you need to know exactly where an exception is raised, it is better to
2574 stop @emph{before} the exception handler is called, since that way you
2575 can see the stack before any unwinding takes place. If you set a
2576 breakpoint in an exception handler instead, it may not be easy to find
2577 out where the exception was raised.
2579 To stop just before an exception handler is called, you need some
2580 knowledge of the implementation. In the case of @sc{gnu} C++, exceptions are
2581 raised by calling a library function named @code{__raise_exception}
2582 which has the following ANSI C interface:
2585 /* @var{addr} is where the exception identifier is stored.
2586 ID is the exception identifier. */
2587 void __raise_exception (void **@var{addr}, void *@var{id});
2591 To make the debugger catch all exceptions before any stack
2592 unwinding takes place, set a breakpoint on @code{__raise_exception}
2593 (@pxref{Breakpoints, ,Breakpoints; watchpoints; and exceptions}).
2595 With a conditional breakpoint (@pxref{Conditions, ,Break conditions})
2596 that depends on the value of @var{id}, you can stop your program when
2597 a specific exception is raised. You can use multiple conditional
2598 breakpoints to stop your program when any of a number of exceptions are
2603 @subsection Deleting breakpoints
2605 @cindex clearing breakpoints, watchpoints, catchpoints
2606 @cindex deleting breakpoints, watchpoints, catchpoints
2607 It is often necessary to eliminate a breakpoint, watchpoint, or
2608 catchpoint once it has done its job and you no longer want your program
2609 to stop there. This is called @dfn{deleting} the breakpoint. A
2610 breakpoint that has been deleted no longer exists; it is forgotten.
2612 With the @code{clear} command you can delete breakpoints according to
2613 where they are in your program. With the @code{delete} command you can
2614 delete individual breakpoints, watchpoints, or catchpoints by specifying
2615 their breakpoint numbers.
2617 It is not necessary to delete a breakpoint to proceed past it. @value{GDBN}
2618 automatically ignores breakpoints on the first instruction to be executed
2619 when you continue execution without changing the execution address.
2624 Delete any breakpoints at the next instruction to be executed in the
2625 selected stack frame (@pxref{Selection, ,Selecting a frame}). When
2626 the innermost frame is selected, this is a good way to delete a
2627 breakpoint where your program just stopped.
2629 @item clear @var{function}
2630 @itemx clear @var{filename}:@var{function}
2631 Delete any breakpoints set at entry to the function @var{function}.
2633 @item clear @var{linenum}
2634 @itemx clear @var{filename}:@var{linenum}
2635 Delete any breakpoints set at or within the code of the specified line.
2637 @cindex delete breakpoints
2640 @item delete @r{[}breakpoints@r{]} @r{[}@var{bnums}@dots{}@r{]}
2641 Delete the breakpoints, watchpoints, or catchpoints of the numbers
2642 specified as arguments. If no argument is specified, delete all
2643 breakpoints (@value{GDBN} asks confirmation, unless you have @code{set
2644 confirm off}). You can abbreviate this command as @code{d}.
2648 @subsection Disabling breakpoints
2650 @kindex disable breakpoints
2651 @kindex enable breakpoints
2652 Rather than deleting a breakpoint, watchpoint, or catchpoint, you might
2653 prefer to @dfn{disable} it. This makes the breakpoint inoperative as if
2654 it had been deleted, but remembers the information on the breakpoint so
2655 that you can @dfn{enable} it again later.
2657 You disable and enable breakpoints, watchpoints, and catchpoints with
2658 the @code{enable} and @code{disable} commands, optionally specifying one
2659 or more breakpoint numbers as arguments. Use @code{info break} or
2660 @code{info watch} to print a list of breakpoints, watchpoints, and
2661 catchpoints if you do not know which numbers to use.
2663 A breakpoint, watchpoint, or catchpoint can have any of four different
2664 states of enablement:
2668 Enabled. The breakpoint stops your program. A breakpoint set
2669 with the @code{break} command starts out in this state.
2671 Disabled. The breakpoint has no effect on your program.
2673 Enabled once. The breakpoint stops your program, but then becomes
2674 disabled. A breakpoint set with the @code{tbreak} command starts out in
2677 Enabled for deletion. The breakpoint stops your program, but
2678 immediately after it does so it is deleted permanently.
2681 You can use the following commands to enable or disable breakpoints,
2682 watchpoints, and catchpoints:
2685 @kindex disable breakpoints
2688 @item disable @r{[}breakpoints@r{]} @r{[}@var{bnums}@dots{}@r{]}
2689 Disable the specified breakpoints---or all breakpoints, if none are
2690 listed. A disabled breakpoint has no effect but is not forgotten. All
2691 options such as ignore-counts, conditions and commands are remembered in
2692 case the breakpoint is enabled again later. You may abbreviate
2693 @code{disable} as @code{dis}.
2695 @kindex enable breakpoints
2697 @item enable @r{[}breakpoints@r{]} @r{[}@var{bnums}@dots{}@r{]}
2698 Enable the specified breakpoints (or all defined breakpoints). They
2699 become effective once again in stopping your program.
2701 @item enable @r{[}breakpoints@r{]} once @var{bnums}@dots{}
2702 Enable the specified breakpoints temporarily. @value{GDBN} disables any
2703 of these breakpoints immediately after stopping your program.
2705 @item enable @r{[}breakpoints@r{]} delete @var{bnums}@dots{}
2706 Enable the specified breakpoints to work once, then die. @value{GDBN}
2707 deletes any of these breakpoints as soon as your program stops there.
2710 Except for a breakpoint set with @code{tbreak} (@pxref{Set Breaks,
2711 ,Setting breakpoints}), breakpoints that you set are initially enabled;
2712 subsequently, they become disabled or enabled only when you use one of
2713 the commands above. (The command @code{until} can set and delete a
2714 breakpoint of its own, but it does not change the state of your other
2715 breakpoints; see @ref{Continuing and Stepping, ,Continuing and
2719 @subsection Break conditions
2720 @cindex conditional breakpoints
2721 @cindex breakpoint conditions
2723 @c FIXME what is scope of break condition expr? Context where wanted?
2724 @c in particular for a watchpoint?
2725 The simplest sort of breakpoint breaks every time your program reaches a
2726 specified place. You can also specify a @dfn{condition} for a
2727 breakpoint. A condition is just a Boolean expression in your
2728 programming language (@pxref{Expressions, ,Expressions}). A breakpoint with
2729 a condition evaluates the expression each time your program reaches it,
2730 and your program stops only if the condition is @emph{true}.
2732 This is the converse of using assertions for program validation; in that
2733 situation, you want to stop when the assertion is violated---that is,
2734 when the condition is false. In C, if you want to test an assertion expressed
2735 by the condition @var{assert}, you should set the condition
2736 @samp{! @var{assert}} on the appropriate breakpoint.
2738 Conditions are also accepted for watchpoints; you may not need them,
2739 since a watchpoint is inspecting the value of an expression anyhow---but
2740 it might be simpler, say, to just set a watchpoint on a variable name,
2741 and specify a condition that tests whether the new value is an interesting
2744 Break conditions can have side effects, and may even call functions in
2745 your program. This can be useful, for example, to activate functions
2746 that log program progress, or to use your own print functions to
2747 format special data structures. The effects are completely predictable
2748 unless there is another enabled breakpoint at the same address. (In
2749 that case, @value{GDBN} might see the other breakpoint first and stop your
2750 program without checking the condition of this one.) Note that
2751 breakpoint commands are usually more convenient and flexible for the
2752 purpose of performing side effects when a breakpoint is reached
2753 (@pxref{Break Commands, ,Breakpoint command lists}).
2755 Break conditions can be specified when a breakpoint is set, by using
2756 @samp{if} in the arguments to the @code{break} command. @xref{Set
2757 Breaks, ,Setting breakpoints}. They can also be changed at any time
2758 with the @code{condition} command.
2760 You can also use the @code{if} keyword with the @code{watch} command.
2761 The @code{catch} command does not recognize the @code{if} keyword;
2762 @code{condition} is the only way to impose a further condition on a
2767 @item condition @var{bnum} @var{expression}
2768 Specify @var{expression} as the break condition for breakpoint,
2769 watchpoint, or catchpoint number @var{bnum}. After you set a condition,
2770 breakpoint @var{bnum} stops your program only if the value of
2771 @var{expression} is true (nonzero, in C). When you use
2772 @code{condition}, @value{GDBN} checks @var{expression} immediately for
2773 syntactic correctness, and to determine whether symbols in it have
2774 referents in the context of your breakpoint.
2775 @c FIXME so what does GDB do if there is no referent? Moreover, what
2776 @c about watchpoints?
2778 not actually evaluate @var{expression} at the time the @code{condition}
2779 command is given, however. @xref{Expressions, ,Expressions}.
2781 @item condition @var{bnum}
2782 Remove the condition from breakpoint number @var{bnum}. It becomes
2783 an ordinary unconditional breakpoint.
2786 @cindex ignore count (of breakpoint)
2787 A special case of a breakpoint condition is to stop only when the
2788 breakpoint has been reached a certain number of times. This is so
2789 useful that there is a special way to do it, using the @dfn{ignore
2790 count} of the breakpoint. Every breakpoint has an ignore count, which
2791 is an integer. Most of the time, the ignore count is zero, and
2792 therefore has no effect. But if your program reaches a breakpoint whose
2793 ignore count is positive, then instead of stopping, it just decrements
2794 the ignore count by one and continues. As a result, if the ignore count
2795 value is @var{n}, the breakpoint does not stop the next @var{n} times
2796 your program reaches it.
2800 @item ignore @var{bnum} @var{count}
2801 Set the ignore count of breakpoint number @var{bnum} to @var{count}.
2802 The next @var{count} times the breakpoint is reached, your program's
2803 execution does not stop; other than to decrement the ignore count, @value{GDBN}
2806 To make the breakpoint stop the next time it is reached, specify
2809 When you use @code{continue} to resume execution of your program from a
2810 breakpoint, you can specify an ignore count directly as an argument to
2811 @code{continue}, rather than using @code{ignore}. @xref{Continuing and
2812 Stepping,,Continuing and stepping}.
2814 If a breakpoint has a positive ignore count and a condition, the
2815 condition is not checked. Once the ignore count reaches zero,
2816 @value{GDBN} resumes checking the condition.
2818 You could achieve the effect of the ignore count with a condition such
2819 as @w{@samp{$foo-- <= 0}} using a debugger convenience variable that
2820 is decremented each time. @xref{Convenience Vars, ,Convenience
2824 Ignore counts apply to breakpoints, watchpoints, and catchpoints.
2827 @node Break Commands
2828 @subsection Breakpoint command lists
2830 @cindex breakpoint commands
2831 You can give any breakpoint (or watchpoint or catchpoint) a series of
2832 commands to execute when your program stops due to that breakpoint. For
2833 example, you might want to print the values of certain expressions, or
2834 enable other breakpoints.
2839 @item commands @r{[}@var{bnum}@r{]}
2840 @itemx @dots{} @var{command-list} @dots{}
2842 Specify a list of commands for breakpoint number @var{bnum}. The commands
2843 themselves appear on the following lines. Type a line containing just
2844 @code{end} to terminate the commands.
2846 To remove all commands from a breakpoint, type @code{commands} and
2847 follow it immediately with @code{end}; that is, give no commands.
2849 With no @var{bnum} argument, @code{commands} refers to the last
2850 breakpoint, watchpoint, or catchpoint set (not to the breakpoint most
2851 recently encountered).
2854 Pressing @key{RET} as a means of repeating the last @value{GDBN} command is
2855 disabled within a @var{command-list}.
2857 You can use breakpoint commands to start your program up again. Simply
2858 use the @code{continue} command, or @code{step}, or any other command
2859 that resumes execution.
2861 Any other commands in the command list, after a command that resumes
2862 execution, are ignored. This is because any time you resume execution
2863 (even with a simple @code{next} or @code{step}), you may encounter
2864 another breakpoint---which could have its own command list, leading to
2865 ambiguities about which list to execute.
2868 If the first command you specify in a command list is @code{silent}, the
2869 usual message about stopping at a breakpoint is not printed. This may
2870 be desirable for breakpoints that are to print a specific message and
2871 then continue. If none of the remaining commands print anything, you
2872 see no sign that the breakpoint was reached. @code{silent} is
2873 meaningful only at the beginning of a breakpoint command list.
2875 The commands @code{echo}, @code{output}, and @code{printf} allow you to
2876 print precisely controlled output, and are often useful in silent
2877 breakpoints. @xref{Output, ,Commands for controlled output}.
2879 For example, here is how you could use breakpoint commands to print the
2880 value of @code{x} at entry to @code{foo} whenever @code{x} is positive.
2886 printf "x is %d\n",x
2891 One application for breakpoint commands is to compensate for one bug so
2892 you can test for another. Put a breakpoint just after the erroneous line
2893 of code, give it a condition to detect the case in which something
2894 erroneous has been done, and give it commands to assign correct values
2895 to any variables that need them. End with the @code{continue} command
2896 so that your program does not stop, and start with the @code{silent}
2897 command so that no output is produced. Here is an example:
2908 @node Breakpoint Menus
2909 @subsection Breakpoint menus
2911 @cindex symbol overloading
2913 Some programming languages (notably C++) permit a single function name
2914 to be defined several times, for application in different contexts.
2915 This is called @dfn{overloading}. When a function name is overloaded,
2916 @samp{break @var{function}} is not enough to tell @value{GDBN} where you want
2917 a breakpoint. If you realize this is a problem, you can use
2918 something like @samp{break @var{function}(@var{types})} to specify which
2919 particular version of the function you want. Otherwise, @value{GDBN} offers
2920 you a menu of numbered choices for different possible breakpoints, and
2921 waits for your selection with the prompt @samp{>}. The first two
2922 options are always @samp{[0] cancel} and @samp{[1] all}. Typing @kbd{1}
2923 sets a breakpoint at each definition of @var{function}, and typing
2924 @kbd{0} aborts the @code{break} command without setting any new
2927 For example, the following session excerpt shows an attempt to set a
2928 breakpoint at the overloaded symbol @code{String::after}.
2929 We choose three particular definitions of that function name:
2931 @c FIXME! This is likely to change to show arg type lists, at least
2934 (@value{GDBP}) b String::after
2937 [2] file:String.cc; line number:867
2938 [3] file:String.cc; line number:860
2939 [4] file:String.cc; line number:875
2940 [5] file:String.cc; line number:853
2941 [6] file:String.cc; line number:846
2942 [7] file:String.cc; line number:735
2944 Breakpoint 1 at 0xb26c: file String.cc, line 867.
2945 Breakpoint 2 at 0xb344: file String.cc, line 875.
2946 Breakpoint 3 at 0xafcc: file String.cc, line 846.
2947 Multiple breakpoints were set.
2948 Use the "delete" command to delete unwanted
2954 @c @ifclear BARETARGET
2955 @c @node Error in Breakpoints
2956 @c @subsection ``Cannot insert breakpoints''
2958 @c FIXME!! 14/6/95 Is there a real example of this? Let's use it.
2960 @c Under some operating systems
2961 @c any other process is running that program. In this situation,
2962 @c attempting to run or continue a program with a breakpoint causes
2963 @c @value{GDBN} to stop the other process.
2965 @c When this happens, you have three ways to proceed:
2969 @c Remove or disable the breakpoints, then continue.
2972 @c Suspend @value{GDBN}, and copy the file containing your program to a new
2973 @c name. Resume @value{GDBN} and use the @code{exec-file} command to specify
2974 @c that @value{GDBN} should run your program under that name.
2975 @c Then start your program again.
2978 @c Relink your program so that the text segment is nonsharable, using the
2979 @c linker option @samp{-N}. The operating system limitation may not apply
2980 @c to nonsharable executables.
2984 @node Continuing and Stepping
2985 @section Continuing and stepping
2989 @cindex resuming execution
2990 @dfn{Continuing} means resuming program execution until your program
2991 completes normally. In contrast, @dfn{stepping} means executing just
2992 one more ``step'' of your program, where ``step'' may mean either one
2993 line of source code, or one machine instruction (depending on what
2994 particular command you use). Either when continuing or when stepping,
2995 your program may stop even sooner, due to a breakpoint or a signal. (If
2996 due to a signal, you may want to use @code{handle}, or use @samp{signal
2997 0} to resume execution. @xref{Signals, ,Signals}.)
3003 @item continue @r{[}@var{ignore-count}@r{]}
3004 @itemx c @r{[}@var{ignore-count}@r{]}
3005 @itemx fg @r{[}@var{ignore-count}@r{]}
3006 Resume program execution, at the address where your program last stopped;
3007 any breakpoints set at that address are bypassed. The optional argument
3008 @var{ignore-count} allows you to specify a further number of times to
3009 ignore a breakpoint at this location; its effect is like that of
3010 @code{ignore} (@pxref{Conditions, ,Break conditions}).
3012 The argument @var{ignore-count} is meaningful only when your program
3013 stopped due to a breakpoint. At other times, the argument to
3014 @code{continue} is ignored.
3016 The synonyms @code{c} and @code{fg} are provided purely for convenience,
3017 and have exactly the same behavior as @code{continue}.
3020 To resume execution at a different place, you can use @code{return}
3021 (@pxref{Returning, ,Returning from a function}) to go back to the
3022 calling function; or @code{jump} (@pxref{Jumping, ,Continuing at a
3023 different address}) to go to an arbitrary location in your program.
3025 A typical technique for using stepping is to set a breakpoint
3026 (@pxref{Breakpoints, ,Breakpoints; watchpoints; and catchpoints}) at the
3027 beginning of the function or the section of your program where a problem
3028 is believed to lie, run your program until it stops at that breakpoint,
3029 and then step through the suspect area, examining the variables that are
3030 interesting, until you see the problem happen.
3036 Continue running your program until control reaches a different source
3037 line, then stop it and return control to @value{GDBN}. This command is
3038 abbreviated @code{s}.
3041 @c "without debugging information" is imprecise; actually "without line
3042 @c numbers in the debugging information". (gcc -g1 has debugging info but
3043 @c not line numbers). But it seems complex to try to make that
3044 @c distinction here.
3045 @emph{Warning:} If you use the @code{step} command while control is
3046 within a function that was compiled without debugging information,
3047 execution proceeds until control reaches a function that does have
3048 debugging information. Likewise, it will not step into a function which
3049 is compiled without debugging information. To step through functions
3050 without debugging information, use the @code{stepi} command, described
3054 The @code{step} command now only stops at the first instruction of a
3055 source line. This prevents the multiple stops that used to occur in
3056 switch statements, for loops, etc. @code{step} continues to stop if a
3057 function that has debugging information is called within the line.
3059 Also, the @code{step} command now only enters a subroutine if there is line
3060 number information for the subroutine. Otherwise it acts like the
3061 @code{next} command. This avoids problems when using @code{cc -gl}
3062 on MIPS machines. Previously, @code{step} entered subroutines if there
3063 was any debugging information about the routine.
3065 @item step @var{count}
3066 Continue running as in @code{step}, but do so @var{count} times. If a
3067 breakpoint is reached, or a signal not related to stepping occurs before
3068 @var{count} steps, stepping stops right away.
3072 @item next @r{[}@var{count}@r{]}
3073 Continue to the next source line in the current (innermost) stack frame.
3074 This is similar to @code{step}, but function calls that appear within
3075 the line of code are executed without stopping. Execution stops when
3076 control reaches a different line of code at the original stack level
3077 that was executing when you gave the @code{next} command. This command
3078 is abbreviated @code{n}.
3080 An argument @var{count} is a repeat count, as for @code{step}.
3083 @c FIX ME!! Do we delete this, or is there a way it fits in with
3084 @c the following paragraph? --- Vctoria
3086 @c @code{next} within a function that lacks debugging information acts like
3087 @c @code{step}, but any function calls appearing within the code of the
3088 @c function are executed without stopping.
3090 The @code{next} command now only stops at the first instruction of a
3091 source line. This prevents the multiple stops that used to occur in
3092 switch statements, for loops, etc.
3096 Continue running until just after function in the selected stack frame
3097 returns. Print the returned value (if any).
3099 Contrast this with the @code{return} command (@pxref{Returning,
3100 ,Returning from a function}).
3106 Continue running until a source line past the current line, in the
3107 current stack frame, is reached. This command is used to avoid single
3108 stepping through a loop more than once. It is like the @code{next}
3109 command, except that when @code{until} encounters a jump, it
3110 automatically continues execution until the program counter is greater
3111 than the address of the jump.
3113 This means that when you reach the end of a loop after single stepping
3114 though it, @code{until} makes your program continue execution until it
3115 exits the loop. In contrast, a @code{next} command at the end of a loop
3116 simply steps back to the beginning of the loop, which forces you to step
3117 through the next iteration.
3119 @code{until} always stops your program if it attempts to exit the current
3122 @code{until} may produce somewhat counterintuitive results if the order
3123 of machine code does not match the order of the source lines. For
3124 example, in the following excerpt from a debugging session, the @code{f}
3125 (@code{frame}) command shows that execution is stopped at line
3126 @code{206}; yet when we use @code{until}, we get to line @code{195}:
3130 #0 main (argc=4, argv=0xf7fffae8) at m4.c:206
3132 (@value{GDBP}) until
3133 195 for ( ; argc > 0; NEXTARG) @{
3136 This happened because, for execution efficiency, the compiler had
3137 generated code for the loop closure test at the end, rather than the
3138 start, of the loop---even though the test in a C @code{for}-loop is
3139 written before the body of the loop. The @code{until} command appeared
3140 to step back to the beginning of the loop when it advanced to this
3141 expression; however, it has not really gone to an earlier
3142 statement---not in terms of the actual machine code.
3144 @code{until} with no argument works by means of single
3145 instruction stepping, and hence is slower than @code{until} with an
3148 @item until @var{location}
3149 @itemx u @var{location}
3150 Continue running your program until either the specified location is
3151 reached, or the current stack frame returns. @var{location} is any of
3152 the forms of argument acceptable to @code{break} (@pxref{Set Breaks,
3153 ,Setting breakpoints}). This form of the command uses breakpoints,
3154 and hence is quicker than @code{until} without an argument.
3160 Execute one machine instruction, then stop and return to the debugger.
3162 It is often useful to do @samp{display/i $pc} when stepping by machine
3163 instructions. This makes @value{GDBN} automatically display the next
3164 instruction to be executed, each time your program stops. @xref{Auto
3165 Display,, Automatic display}.
3167 An argument is a repeat count, as in @code{step}.
3174 Execute one machine instruction, but if it is a function call,
3175 proceed until the function returns.
3177 An argument is a repeat count, as in @code{next}.
3184 A signal is an asynchronous event that can happen in a program. The
3185 operating system defines the possible kinds of signals, and gives each
3186 kind a name and a number. For example, in Unix @code{SIGINT} is the
3187 signal a program gets when you type an interrupt (often @kbd{C-c});
3188 @code{SIGSEGV} is the signal a program gets from referencing a place in
3189 memory far away from all the areas in use; @code{SIGALRM} occurs when
3190 the alarm clock timer goes off (which happens only if your program has
3191 requested an alarm).
3193 @cindex fatal signals
3194 Some signals, including @code{SIGALRM}, are a normal part of the
3195 functioning of your program. Others, such as @code{SIGSEGV}, indicate
3196 errors; these signals are @dfn{fatal} (kill your program immediately) if the
3197 program has not specified in advance some other way to handle the signal.
3198 @code{SIGINT} does not indicate an error in your program, but it is normally
3199 fatal so it can carry out the purpose of the interrupt: to kill the program.
3201 @value{GDBN} has the ability to detect any occurrence of a signal in your
3202 program. You can tell @value{GDBN} in advance what to do for each kind of
3205 @cindex handling signals
3206 Normally, @value{GDBN} is set up to ignore non-erroneous signals like @code{SIGALRM}
3207 (so as not to interfere with their role in the functioning of your program)
3208 but to stop your program immediately whenever an error signal happens.
3209 You can change these settings with the @code{handle} command.
3212 @kindex info signals
3214 Print a table of all the kinds of signals and how @value{GDBN} has been told to
3215 handle each one. You can use this to see the signal numbers of all
3216 the defined types of signals.
3218 @code{info handle} is the new alias for @code{info signals}.
3221 @item handle @var{signal} @var{keywords}@dots{}
3222 Change the way @value{GDBN} handles signal @var{signal}. @var{signal} can
3223 be the number of a signal or its name (with or without the @samp{SIG} at the
3224 beginning). The @var{keywords} say what change to make.
3228 The keywords allowed by the @code{handle} command can be abbreviated.
3229 Their full names are:
3233 @value{GDBN} should not stop your program when this signal happens. It may
3234 still print a message telling you that the signal has come in.
3237 @value{GDBN} should stop your program when this signal happens. This implies
3238 the @code{print} keyword as well.
3241 @value{GDBN} should print a message when this signal happens.
3244 @value{GDBN} should not mention the occurrence of the signal at all. This
3245 implies the @code{nostop} keyword as well.
3248 @value{GDBN} should allow your program to see this signal; your program
3249 can handle the signal, or else it may terminate if the signal is fatal
3253 @value{GDBN} should not allow your program to see this signal.
3257 When a signal stops your program, the signal is not visible until you
3258 continue. Your program sees the signal then, if @code{pass} is in
3259 effect for the signal in question @emph{at that time}. In other words,
3260 after @value{GDBN} reports a signal, you can use the @code{handle}
3261 command with @code{pass} or @code{nopass} to control whether your
3262 program sees that signal when you continue.
3264 You can also use the @code{signal} command to prevent your program from
3265 seeing a signal, or cause it to see a signal it normally would not see,
3266 or to give it any signal at any time. For example, if your program stopped
3267 due to some sort of memory reference error, you might store correct
3268 values into the erroneous variables and continue, hoping to see more
3269 execution; but your program would probably terminate immediately as
3270 a result of the fatal signal once it saw the signal. To prevent this,
3271 you can continue with @samp{signal 0}. @xref{Signaling, ,Giving your
3275 @section Stopping and starting multi-thread programs
3277 When your program has multiple threads (@pxref{Threads,, Debugging
3278 programs with multiple threads}), you can choose whether to set
3279 breakpoints on all threads, or on a particular thread.
3282 @cindex breakpoints and threads
3283 @cindex thread breakpoints
3284 @kindex break @dots{} thread @var{threadno}
3285 @item break @var{linespec} thread @var{threadno}
3286 @itemx break @var{linespec} thread @var{threadno} if @dots{}
3287 @var{linespec} specifies source lines; there are several ways of
3288 writing them, but the effect is always to specify some source line.
3290 Use the qualifier @samp{thread @var{threadno}} with a breakpoint command
3291 to specify that you only want @value{GDBN} to stop the program when a
3292 particular thread reaches this breakpoint. @var{threadno} is one of the
3293 numeric thread identifiers assigned by @value{GDBN}, shown in the first
3294 column of the @samp{info threads} display.
3296 If you do not specify @samp{thread @var{threadno}} when you set a
3297 breakpoint, the breakpoint applies to @emph{all} threads of your
3300 You can use the @code{thread} qualifier on conditional breakpoints as
3301 well; in this case, place @samp{thread @var{threadno}} before the
3302 breakpoint condition, like this:
3305 (gdb) break frik.c:13 thread 28 if bartab > lim
3310 @cindex stopped threads
3311 @cindex threads, stopped
3312 Whenever your program stops under @value{GDBN} for any reason,
3313 @emph{all} threads of execution stop, not just the current thread. This
3314 allows you to examine the overall state of the program, including
3315 switching between threads, without worrying that things may change
3318 @cindex continuing threads
3319 @cindex threads, continuing
3320 Conversely, whenever you restart the program, @emph{all} threads start
3321 executing. @emph{This is true even when single-stepping} with commands
3322 like @code{step} or @code{next}.
3324 In particular, @value{GDBN} cannot single-step all threads in lockstep.
3325 Since thread scheduling is up to your debugging target's operating
3326 system (not controlled by @value{GDBN}), other threads may
3327 execute more than one statement while the current thread completes a
3328 single step. Moreover, in general other threads stop in the middle of a
3329 statement, rather than at a clean statement boundary, when the program
3332 You might even find your program stopped in another thread after
3333 continuing or even single-stepping. This happens whenever some other
3334 thread runs into a breakpoint, a signal, or an exception before the
3335 first thread completes whatever you requested.
3337 On some OSes, you can lock the OS scheduler and thus allow only a single
3341 @item set scheduler-locking @var{mode}
3342 Set the scheduler locking mode. If it is @code{off}, then there is no
3343 locking and any thread may run at any time. If @code{on}, then only the
3344 current thread may run when the inferior is resumed. The @code{step}
3345 mode optimizes for single-stepping. It stops other threads from
3346 ``seizing the prompt'' by preempting the current thread while you are
3347 stepping. Other threads will only rarely (or never) get a chance to run
3348 when you step. They are more likely to run when you ``next'' over a
3349 function call, and they are completely free to run when you use commands
3350 like ``continue'', ``until'', or ``finish''. However, unless another
3351 thread hits a breakpoint during its timeslice, they will never steal the
3352 GDB prompt away from the thread that you are debugging.
3354 @item show scheduler-locking
3355 Display the current scheduler locking mode.
3360 @chapter Examining the Stack
3362 When your program has stopped, the first thing you need to know is where it
3363 stopped and how it got there.
3366 Each time your program performs a function call, information about the call
3368 That information includes the location of the call in your program,
3369 the arguments of the call,
3370 and the local variables of the function being called.
3371 The information is saved in a block of data called a @dfn{stack frame}.
3372 The stack frames are allocated in a region of memory called the @dfn{call
3375 When your program stops, the @value{GDBN} commands for examining the
3376 stack allow you to see all of this information.
3378 @cindex selected frame
3379 One of the stack frames is @dfn{selected} by @value{GDBN} and many
3380 @value{GDBN} commands refer implicitly to the selected frame. In
3381 particular, whenever you ask @value{GDBN} for the value of a variable in
3382 your program, the value is found in the selected frame. There are
3383 special @value{GDBN} commands to select whichever frame you are
3384 interested in. @xref{Selection, ,Selecting a frame}.
3386 When your program stops, @value{GDBN} automatically selects the
3387 currently executing frame and describes it briefly, similar to the
3388 @code{frame} command (@pxref{Frame Info, ,Information about a frame}).
3391 * Frames:: Stack frames
3392 * Backtrace:: Backtraces
3393 * Selection:: Selecting a frame
3394 * Frame Info:: Information on a frame
3395 * Alpha/MIPS Stack:: Alpha and MIPS machines and the function stack
3400 @section Stack frames
3404 The call stack is divided up into contiguous pieces called @dfn{stack
3405 frames}, or @dfn{frames} for short; each frame is the data associated
3406 with one call to one function. The frame contains the arguments given
3407 to the function, the function's local variables, and the address at
3408 which the function is executing.
3410 @cindex initial frame
3411 @cindex outermost frame
3412 @cindex innermost frame
3413 When your program is started, the stack has only one frame, that of the
3414 function @code{main}. This is called the @dfn{initial} frame or the
3415 @dfn{outermost} frame. Each time a function is called, a new frame is
3416 made. Each time a function returns, the frame for that function invocation
3417 is eliminated. If a function is recursive, there can be many frames for
3418 the same function. The frame for the function in which execution is
3419 actually occurring is called the @dfn{innermost} frame. This is the most
3420 recently created of all the stack frames that still exist.
3422 @cindex frame pointer
3423 Inside your program, stack frames are identified by their addresses. A
3424 stack frame consists of many bytes, each of which has its own address; each
3425 kind of computer has a convention for choosing one byte whose
3426 address serves as the address of the frame. Usually this address is kept
3427 in a register called the @dfn{frame pointer register} while execution is
3428 going on in that frame.
3430 @cindex frame number
3431 @value{GDBN} assigns numbers to all existing stack frames, starting with
3432 zero for the innermost frame, one for the frame that called it,
3433 and so on upward. These numbers do not really exist in your program;
3434 they are assigned by @value{GDBN} to give you a way of designating stack
3435 frames in @value{GDBN} commands.
3437 @c below produces an acceptable overful hbox. --mew 13aug1993
3438 @cindex frameless execution
3439 Some compilers provide a way to compile functions so that they operate
3440 without stack frames. (For example, the @code{@value{GCC}} option
3441 @samp{-fomit-frame-pointer} generates functions without a frame.)
3442 This is occasionally done with heavily used library functions to save
3443 the frame setup time. @value{GDBN} has limited facilities for dealing
3444 with these function invocations. If the innermost function invocation
3445 has no stack frame, @value{GDBN} nevertheless regards it as though
3446 it had a separate frame, which is numbered zero as usual, allowing
3447 correct tracing of the function call chain. However, @value{GDBN} has
3448 no provision for frameless functions elsewhere in the stack.
3452 @item frame @var{args}
3453 The @code{frame} command allows you to move from one stack frame to another,
3454 and to print the stack frame you select. @var{args} may be either the
3455 address of the frame or the stack frame number. Without an argument,
3456 @code{frame} prints the current stack frame.
3458 @kindex select-frame
3460 The @code{select-frame} command allows you to move from one stack frame
3461 to another without printing the frame. This is the silent version of
3470 @cindex stack traces
3471 A backtrace is a summary of how your program got where it is. It shows one
3472 line per frame, for many frames, starting with the currently executing
3473 frame (frame zero), followed by its caller (frame one), and on up the
3481 Print a backtrace of the entire stack: one line per frame for all
3482 frames in the stack.
3484 You can stop the backtrace at any time by typing the system interrupt
3485 character, normally @kbd{C-c}.
3487 @item backtrace @var{n}
3489 Similar, but print only the innermost @var{n} frames.
3491 @item backtrace -@var{n}
3493 Similar, but print only the outermost @var{n} frames.
3499 The names @code{where} and @code{info stack} (abbreviated @code{info s})
3500 are additional aliases for @code{backtrace}.
3502 Each line in the backtrace shows the frame number and the function name.
3503 The program counter value is also shown---unless you use @code{set
3504 print address off}. The backtrace also shows the source file name and
3505 line number, as well as the arguments to the function. The program
3506 counter value is omitted if it is at the beginning of the code for that
3509 Here is an example of a backtrace. It was made with the command
3510 @samp{bt 3}, so it shows the innermost three frames.
3514 #0 m4_traceon (obs=0x24eb0, argc=1, argv=0x2b8c8)
3516 #1 0x6e38 in expand_macro (sym=0x2b600) at macro.c:242
3517 #2 0x6840 in expand_token (obs=0x0, t=177664, td=0xf7fffb08)
3519 (More stack frames follow...)
3524 The display for frame zero does not begin with a program counter
3525 value, indicating that your program has stopped at the beginning of the
3526 code for line @code{993} of @code{builtin.c}.
3529 @section Selecting a frame
3531 Most commands for examining the stack and other data in your program work on
3532 whichever stack frame is selected at the moment. Here are the commands for
3533 selecting a stack frame; all of them finish by printing a brief description
3534 of the stack frame just selected.
3541 Select frame number @var{n}. Recall that frame zero is the innermost
3542 (currently executing) frame, frame one is the frame that called the
3543 innermost one, and so on. The highest-numbered frame is the one for
3546 @item frame @var{addr}
3548 Select the frame at address @var{addr}. This is useful mainly if the
3549 chaining of stack frames has been damaged by a bug, making it
3550 impossible for @value{GDBN} to assign numbers properly to all frames. In
3551 addition, this can be useful when your program has multiple stacks and
3552 switches between them.
3554 On the SPARC architecture, @code{frame} needs two addresses to
3555 select an arbitrary frame: a frame pointer and a stack pointer.
3557 On the MIPS and Alpha architecture, it needs two addresses: a stack
3558 pointer and a program counter.
3560 On the 29k architecture, it needs three addresses: a register stack
3561 pointer, a program counter, and a memory stack pointer.
3562 @c note to future updaters: this is conditioned on a flag
3563 @c SETUP_ARBITRARY_FRAME in the tm-*.h files. The above is up to date
3564 @c as of 27 Jan 1994.
3568 Move @var{n} frames up the stack. For positive numbers @var{n}, this
3569 advances toward the outermost frame, to higher frame numbers, to frames
3570 that have existed longer. @var{n} defaults to one.
3575 Move @var{n} frames down the stack. For positive numbers @var{n}, this
3576 advances toward the innermost frame, to lower frame numbers, to frames
3577 that were created more recently. @var{n} defaults to one. You may
3578 abbreviate @code{down} as @code{do}.
3581 All of these commands end by printing two lines of output describing the
3582 frame. The first line shows the frame number, the function name, the
3583 arguments, and the source file and line number of execution in that
3584 frame. The second line shows the text of that source line.
3592 #1 0x22f0 in main (argc=1, argv=0xf7fffbf4, env=0xf7fffbfc)
3594 10 read_input_file (argv[i]);
3598 After such a printout, the @code{list} command with no arguments
3599 prints ten lines centered on the point of execution in the frame.
3600 @xref{List, ,Printing source lines}.
3603 @kindex down-silently
3605 @item up-silently @var{n}
3606 @itemx down-silently @var{n}
3607 These two commands are variants of @code{up} and @code{down},
3608 respectively; they differ in that they do their work silently, without
3609 causing display of the new frame. They are intended primarily for use
3610 in @value{GDBN} command scripts, where the output might be unnecessary and
3615 @section Information about a frame
3617 There are several other commands to print information about the selected
3623 When used without any argument, this command does not change which
3624 frame is selected, but prints a brief description of the currently
3625 selected stack frame. It can be abbreviated @code{f}. With an
3626 argument, this command is used to select a stack frame.
3627 @xref{Selection, ,Selecting a frame}.
3633 This command prints a verbose description of the selected stack frame,
3638 the address of the frame
3640 the address of the next frame down (called by this frame)
3642 the address of the next frame up (caller of this frame)
3644 the language in which the source code corresponding to this frame is written
3646 the address of the frame's arguments
3648 the program counter saved in it (the address of execution in the caller frame)
3650 which registers were saved in the frame
3653 @noindent The verbose description is useful when
3654 something has gone wrong that has made the stack format fail to fit
3655 the usual conventions.
3657 @item info frame @var{addr}
3658 @itemx info f @var{addr}
3659 Print a verbose description of the frame at address @var{addr}, without
3660 selecting that frame. The selected frame remains unchanged by this
3661 command. This requires the same kind of address (more than one for some
3662 architectures) that you specify in the @code{frame} command.
3663 @xref{Selection, ,Selecting a frame}.
3667 Print the arguments of the selected frame, each on a separate line.
3671 Print the local variables of the selected frame, each on a separate
3672 line. These are all variables (declared either static or automatic)
3673 accessible at the point of execution of the selected frame.
3676 @cindex catch exceptions
3677 @cindex exception handlers
3679 Print a list of all the exception handlers that are active in the
3680 current stack frame at the current point of execution. To see other
3681 exception handlers, visit the associated frame (using the @code{up},
3682 @code{down}, or @code{frame} commands); then type @code{info catch}.
3683 @xref{Set Catchpoints, , Setting catchpoints}.
3687 @node Alpha/MIPS Stack
3688 @section MIPS/Alpha machines and the function stack
3690 @cindex stack on Alpha
3691 @cindex stack on MIPS
3694 Alpha- and MIPS-based computers use an unusual stack frame, which
3695 sometimes requires @value{GDBN} to search backward in the object code to
3696 find the beginning of a function.
3698 @cindex response time, MIPS debugging
3699 To improve response time (especially for embedded applications, where
3700 @value{GDBN} may be restricted to a slow serial line for this search)
3701 you may want to limit the size of this search, using one of these
3705 @cindex @code{heuristic-fence-post} (Alpha,MIPS)
3706 @item set heuristic-fence-post @var{limit}
3707 Restrict @value{GDBN} to examining at most @var{limit} bytes in its search
3708 for the beginning of a function. A value of @var{0} (the default)
3709 means there is no limit. However, except for @var{0}, the larger the
3710 limit the more bytes @code{heuristic-fence-post} must search and
3711 therefore the longer it takes to run.
3713 @item show heuristic-fence-post
3714 Display the current limit.
3718 These commands are available @emph{only} when @value{GDBN} is configured
3719 for debugging programs on Alpha or MIPS processors.
3723 @chapter Examining Source Files
3725 @value{GDBN} can print parts of your program's source, since the debugging
3726 information recorded in the program tells @value{GDBN} what source files were
3727 used to build it. When your program stops, @value{GDBN} spontaneously prints
3728 the line where it stopped. Likewise, when you select a stack frame
3729 (@pxref{Selection, ,Selecting a frame}), @value{GDBN} prints the line where
3730 execution in that frame has stopped. You can print other portions of
3731 source files by explicit command.
3733 If you use @value{GDBN} through its @sc{gnu} Emacs interface, you may
3734 prefer to use Emacs facilities to view source; @pxref{Emacs, ,Using
3735 @value{GDBN} under @sc{gnu} Emacs}.
3738 * List:: Printing source lines
3739 * Search:: Searching source files
3740 * Source Path:: Specifying source directories
3741 * Machine Code:: Source and machine code
3745 @section Printing source lines
3749 To print lines from a source file, use the @code{list} command
3750 (abbreviated @code{l}). By default, ten lines are printed.
3751 There are several ways to specify what part of the file you want to print.
3753 Here are the forms of the @code{list} command most commonly used:
3756 @item list @var{linenum}
3757 Print lines centered around line number @var{linenum} in the
3758 current source file.
3760 @item list @var{function}
3761 Print lines centered around the beginning of function
3765 Print more lines. If the last lines printed were printed with a
3766 @code{list} command, this prints lines following the last lines
3767 printed; however, if the last line printed was a solitary line printed
3768 as part of displaying a stack frame (@pxref{Stack, ,Examining the
3769 Stack}), this prints lines centered around that line.
3772 Print lines just before the lines last printed.
3775 By default, @value{GDBN} prints ten source lines with any of these forms of
3776 the @code{list} command. You can change this using @code{set listsize}:
3779 @kindex set listsize
3780 @item set listsize @var{count}
3781 Make the @code{list} command display @var{count} source lines (unless
3782 the @code{list} argument explicitly specifies some other number).
3784 @kindex show listsize
3786 Display the number of lines that @code{list} prints.
3789 Repeating a @code{list} command with @key{RET} discards the argument,
3790 so it is equivalent to typing just @code{list}. This is more useful
3791 than listing the same lines again. An exception is made for an
3792 argument of @samp{-}; that argument is preserved in repetition so that
3793 each repetition moves up in the source file.
3796 In general, the @code{list} command expects you to supply zero, one or two
3797 @dfn{linespecs}. Linespecs specify source lines; there are several ways
3798 of writing them but the effect is always to specify some source line.
3799 Here is a complete description of the possible arguments for @code{list}:
3802 @item list @var{linespec}
3803 Print lines centered around the line specified by @var{linespec}.
3805 @item list @var{first},@var{last}
3806 Print lines from @var{first} to @var{last}. Both arguments are
3809 @item list ,@var{last}
3810 Print lines ending with @var{last}.
3812 @item list @var{first},
3813 Print lines starting with @var{first}.
3816 Print lines just after the lines last printed.
3819 Print lines just before the lines last printed.
3822 As described in the preceding table.
3825 Here are the ways of specifying a single source line---all the
3830 Specifies line @var{number} of the current source file.
3831 When a @code{list} command has two linespecs, this refers to
3832 the same source file as the first linespec.
3835 Specifies the line @var{offset} lines after the last line printed.
3836 When used as the second linespec in a @code{list} command that has
3837 two, this specifies the line @var{offset} lines down from the
3841 Specifies the line @var{offset} lines before the last line printed.
3843 @item @var{filename}:@var{number}
3844 Specifies line @var{number} in the source file @var{filename}.
3846 @item @var{function}
3847 Specifies the line that begins the body of the function @var{function}.
3848 For example: in C, this is the line with the open brace.
3850 @item @var{filename}:@var{function}
3851 Specifies the line of the open-brace that begins the body of the
3852 function @var{function} in the file @var{filename}. You only need the
3853 file name with a function name to avoid ambiguity when there are
3854 identically named functions in different source files.
3856 @item *@var{address}
3857 Specifies the line containing the program address @var{address}.
3858 @var{address} may be any expression.
3862 @section Searching source files
3864 @kindex reverse-search
3866 There are two commands for searching through the current source file for a
3871 @kindex forward-search
3872 @item forward-search @var{regexp}
3873 @itemx search @var{regexp}
3874 The command @samp{forward-search @var{regexp}} checks each line,
3875 starting with the one following the last line listed, for a match for
3876 @var{regexp}. It lists the line that is found. You can use the
3877 synonym @samp{search @var{regexp}} or abbreviate the command name as
3880 @item reverse-search @var{regexp}
3881 The command @samp{reverse-search @var{regexp}} checks each line, starting
3882 with the one before the last line listed and going backward, for a match
3883 for @var{regexp}. It lists the line that is found. You can abbreviate
3884 this command as @code{rev}.
3888 @section Specifying source directories
3891 @cindex directories for source files
3892 Executable programs sometimes do not record the directories of the source
3893 files from which they were compiled, just the names. Even when they do,
3894 the directories could be moved between the compilation and your debugging
3895 session. @value{GDBN} has a list of directories to search for source files;
3896 this is called the @dfn{source path}. Each time @value{GDBN} wants a source file,
3897 it tries all the directories in the list, in the order they are present
3898 in the list, until it finds a file with the desired name. Note that
3899 the executable search path is @emph{not} used for this purpose. Neither is
3900 the current working directory, unless it happens to be in the source
3903 If @value{GDBN} cannot find a source file in the source path, and the
3904 object program records a directory, @value{GDBN} tries that directory
3905 too. If the source path is empty, and there is no record of the
3906 compilation directory, @value{GDBN} looks in the current directory as a
3909 Whenever you reset or rearrange the source path, @value{GDBN} clears out
3910 any information it has cached about where source files are found and where
3911 each line is in the file.
3915 When you start @value{GDBN}, its source path is empty.
3916 To add other directories, use the @code{directory} command.
3919 @item directory @var{dirname} @dots{}
3920 @item dir @var{dirname} @dots{}
3921 Add directory @var{dirname} to the front of the source path. Several
3922 directory names may be given to this command, separated by @samp{:} or
3923 whitespace. You may specify a directory that is already in the source
3924 path; this moves it forward, so @value{GDBN} searches it sooner.
3930 @cindex compilation directory
3931 @cindex current directory
3932 @cindex working directory
3933 @cindex directory, current
3934 @cindex directory, compilation
3935 You can use the string @samp{$cdir} to refer to the compilation
3936 directory (if one is recorded), and @samp{$cwd} to refer to the current
3937 working directory. @samp{$cwd} is not the same as @samp{.}---the former
3938 tracks the current working directory as it changes during your @value{GDBN}
3939 session, while the latter is immediately expanded to the current
3940 directory at the time you add an entry to the source path.
3943 Reset the source path to empty again. This requires confirmation.
3945 @c RET-repeat for @code{directory} is explicitly disabled, but since
3946 @c repeating it would be a no-op we do not say that. (thanks to RMS)
3948 @item show directories
3949 @kindex show directories
3950 Print the source path: show which directories it contains.
3953 If your source path is cluttered with directories that are no longer of
3954 interest, @value{GDBN} may sometimes cause confusion by finding the wrong
3955 versions of source. You can correct the situation as follows:
3959 Use @code{directory} with no argument to reset the source path to empty.
3962 Use @code{directory} with suitable arguments to reinstall the
3963 directories you want in the source path. You can add all the
3964 directories in one command.
3968 @section Source and machine code
3970 You can use the command @code{info line} to map source lines to program
3971 addresses (and vice versa), and the command @code{disassemble} to display
3972 a range of addresses as machine instructions. When run under @sc{gnu} Emacs
3973 mode, the @code{info line} command now causes the arrow to point to the
3974 line specified. Also, @code{info line} prints addresses in symbolic form as
3979 @item info line @var{linespec}
3980 Print the starting and ending addresses of the compiled code for
3981 source line @var{linespec}. You can specify source lines in any of
3982 the ways understood by the @code{list} command (@pxref{List, ,Printing
3986 For example, we can use @code{info line} to discover the location of
3987 the object code for the first line of function
3988 @code{m4_changequote}:
3991 (@value{GDBP}) info line m4_changecom
3992 Line 895 of "builtin.c" starts at pc 0x634c and ends at 0x6350.
3996 We can also inquire (using @code{*@var{addr}} as the form for
3997 @var{linespec}) what source line covers a particular address:
3999 (@value{GDBP}) info line *0x63ff
4000 Line 926 of "builtin.c" starts at pc 0x63e4 and ends at 0x6404.
4003 @cindex @code{$_} and @code{info line}
4004 After @code{info line}, the default address for the @code{x} command
4005 is changed to the starting address of the line, so that @samp{x/i} is
4006 sufficient to begin examining the machine code (@pxref{Memory,
4007 ,Examining memory}). Also, this address is saved as the value of the
4008 convenience variable @code{$_} (@pxref{Convenience Vars, ,Convenience
4013 @cindex assembly instructions
4014 @cindex instructions, assembly
4015 @cindex machine instructions
4016 @cindex listing machine instructions
4018 This specialized command dumps a range of memory as machine
4019 instructions. The default memory range is the function surrounding the
4020 program counter of the selected frame. A single argument to this
4021 command is a program counter value; @value{GDBN} dumps the function
4022 surrounding this value. Two arguments specify a range of addresses
4023 (first inclusive, second exclusive) to dump.
4026 The following example shows the disassembly of a range of addresses of
4027 HP PA-RISC 2.0 code:
4030 (@value{GDBP}) disas 0x32c4 0x32e4
4031 Dump of assembler code from 0x32c4 to 0x32e4:
4032 0x32c4 <main+204>: addil 0,dp
4033 0x32c8 <main+208>: ldw 0x22c(sr0,r1),r26
4034 0x32cc <main+212>: ldil 0x3000,r31
4035 0x32d0 <main+216>: ble 0x3f8(sr4,r31)
4036 0x32d4 <main+220>: ldo 0(r31),rp
4037 0x32d8 <main+224>: addil -0x800,dp
4038 0x32dc <main+228>: ldo 0x588(r1),r26
4039 0x32e0 <main+232>: ldil 0x3000,r31
4040 End of assembler dump.
4043 Some architectures have more than one commonly-used set of instruction
4044 mnemonics or other syntax.
4047 @kindex set assembly-language
4048 @cindex assembly instructions
4049 @cindex instructions, assembly
4050 @cindex machine instructions
4051 @cindex listing machine instructions
4052 @item set assembly-language @var{instruction-set}
4053 Select the instruction set to use when disassembling the
4054 program via the @code{disassemble} or @code{x/i} commands.
4056 Currently this command is only defined for the Intel x86 family. You
4057 can set @var{instruction-set} to either @code{i386} or @code{i8086}.
4058 The default is @code{i386}.
4063 @chapter Examining Data
4065 @cindex printing data
4066 @cindex examining data
4069 @c "inspect" is not quite a synonym if you are using Epoch, which we do not
4070 @c document because it is nonstandard... Under Epoch it displays in a
4071 @c different window or something like that.
4072 The usual way to examine data in your program is with the @code{print}
4073 command (abbreviated @code{p}), or its synonym @code{inspect}. It
4074 evaluates and prints the value of an expression of the language your
4075 program is written in (@pxref{Languages, ,Using @value{GDBN} with
4076 Different Languages}).
4079 @item print @var{exp}
4080 @itemx print /@var{f} @var{exp}
4081 @var{exp} is an expression (in the source language). By default the
4082 value of @var{exp} is printed in a format appropriate to its data type;
4083 you can choose a different format by specifying @samp{/@var{f}}, where
4084 @var{f} is a letter specifying the format; @pxref{Output Formats,,Output
4088 @itemx print /@var{f}
4089 If you omit @var{exp}, @value{GDBN} displays the last value again (from the
4090 @dfn{value history}; @pxref{Value History, ,Value history}). This allows you to
4091 conveniently inspect the same value in an alternative format.
4094 A more low-level way of examining data is with the @code{x} command.
4095 It examines data in memory at a specified address and prints it in a
4096 specified format. @xref{Memory, ,Examining memory}.
4098 If you are interested in information about types, or about how the
4099 fields of a struct or class are declared, use the @code{ptype @var{exp}}
4100 command rather than @code{print}. @xref{Symbols, ,Examining the Symbol
4104 * Expressions:: Expressions
4105 * Variables:: Program variables
4106 * Arrays:: Artificial arrays
4107 * Output Formats:: Output formats
4108 * Memory:: Examining memory
4109 * Auto Display:: Automatic display
4110 * Print Settings:: Print settings
4111 * Value History:: Value history
4112 * Convenience Vars:: Convenience variables
4113 * Registers:: Registers
4114 * Floating Point Hardware:: Floating point hardware
4118 @section Expressions
4121 @code{print} and many other @value{GDBN} commands accept an expression and
4122 compute its value. Any kind of constant, variable or operator defined
4123 by the programming language you are using is valid in an expression in
4124 @value{GDBN}. This includes conditional expressions, function calls, casts
4125 and string constants. It unfortunately does not include symbols defined
4126 by preprocessor @code{#define} commands.
4128 @value{GDBN} now supports array constants in expressions input by
4129 the user. The syntax is @var{@{element, element@dots{}@}}. For example,
4130 you can now use the command @code{print @{1, 2, 3@}} to build up an array in
4131 memory that is malloc'd in the target program.
4133 Because C is so widespread, most of the expressions shown in examples in
4134 this manual are in C. @xref{Languages, , Using @value{GDBN} with Different
4135 Languages}, for information on how to use expressions in other
4138 In this section, we discuss operators that you can use in @value{GDBN}
4139 expressions regardless of your programming language.
4141 Casts are supported in all languages, not just in C, because it is so
4142 useful to cast a number into a pointer in order to examine a structure
4143 at that address in memory.
4144 @c FIXME: casts supported---Mod2 true?
4146 @value{GDBN} supports these operators, in addition to those common
4147 to programming languages:
4151 @samp{@@} is a binary operator for treating parts of memory as arrays.
4152 @xref{Arrays, ,Artificial arrays}, for more information.
4155 @samp{::} allows you to specify a variable in terms of the file or
4156 function where it is defined. @xref{Variables, ,Program variables}.
4158 @cindex @{@var{type}@}
4159 @cindex type casting memory
4160 @cindex memory, viewing as typed object
4161 @cindex casts, to view memory
4162 @item @{@var{type}@} @var{addr}
4163 Refers to an object of type @var{type} stored at address @var{addr} in
4164 memory. @var{addr} may be any expression whose value is an integer or
4165 pointer (but parentheses are required around binary operators, just as in
4166 a cast). This construct is allowed regardless of what kind of data is
4167 normally supposed to reside at @var{addr}.
4171 @section Program variables
4173 The most common kind of expression to use is the name of a variable
4176 Variables in expressions are understood in the selected stack frame
4177 (@pxref{Selection, ,Selecting a frame}); they must be either:
4181 global (or file-static)
4188 visible according to the scope rules of the
4189 programming language from the point of execution in that frame
4192 @noindent This means that in the function
4207 you can examine and use the variable @code{a} whenever your program is
4208 executing within the function @code{foo}, but you can only use or
4209 examine the variable @code{b} while your program is executing inside
4210 the block where @code{b} is declared.
4212 @cindex variable name conflict
4213 There is an exception: you can refer to a variable or function whose
4214 scope is a single source file even if the current execution point is not
4215 in this file. But it is possible to have more than one such variable or
4216 function with the same name (in different source files). If that
4217 happens, referring to that name has unpredictable effects. If you wish,
4218 you can specify a static variable in a particular function or file,
4219 using the colon-colon notation:
4223 @c info cannot cope with a :: index entry, but why deprive hard copy readers?
4227 @var{file}::@var{variable}
4228 @var{function}::@var{variable}
4232 Here @var{file} or @var{function} is the name of the context for the
4233 static @var{variable}. In the case of file names, you can use quotes to
4234 make sure @value{GDBN} parses the file name as a single word---for example,
4235 to print a global value of @code{x} defined in @file{f2.c}:
4238 (@value{GDBP}) p 'f2.c'::x
4241 @cindex C++ scope resolution
4242 This use of @samp{::} is very rarely in conflict with the very similar
4243 use of the same notation in C++. @value{GDBN} also supports use of the C++
4244 scope resolution operator in @value{GDBN} expressions.
4245 @c FIXME: Um, so what happens in one of those rare cases where it's in
4248 @cindex wrong values
4249 @cindex variable values, wrong
4251 @emph{Warning:} Occasionally, a local variable may appear to have the
4252 wrong value at certain points in a function---just after entry to a new
4253 scope, and just before exit.
4255 You may see this problem when you are stepping by machine instructions.
4256 This is because, on most machines, it takes more than one instruction to
4257 set up a stack frame (including local variable definitions); if you are
4258 stepping by machine instructions, variables may appear to have the wrong
4259 values until the stack frame is completely built. On exit, it usually
4260 also takes more than one machine instruction to destroy a stack frame;
4261 after you begin stepping through that group of instructions, local
4262 variable definitions may be gone.
4264 This may also happen when the compiler does significant optimizations.
4265 To be sure of always seeing accurate values, turn off all optimization
4269 @section Artificial arrays
4271 @cindex artificial array
4273 It is often useful to print out several successive objects of the
4274 same type in memory; a section of an array, or an array of
4275 dynamically determined size for which only a pointer exists in the
4278 You can do this by referring to a contiguous span of memory as an
4279 @dfn{artificial array}, using the binary operator @samp{@@}. The left
4280 operand of @samp{@@} should be the first element of the desired array
4281 and be an individual object. The right operand should be the desired length
4282 of the array. The result is an array value whose elements are all of
4283 the type of the left argument. The first element is actually the left
4284 argument; the second element comes from bytes of memory immediately
4285 following those that hold the first element, and so on. Here is an
4286 example. If a program says
4289 int *array = (int *) malloc (len * sizeof (int));
4293 you can print the contents of @code{array} with
4299 The left operand of @samp{@@} must reside in memory. Array values made
4300 with @samp{@@} in this way behave just like other arrays in terms of
4301 subscripting, and are coerced to pointers when used in expressions.
4302 Artificial arrays most often appear in expressions via the value history
4303 (@pxref{Value History, ,Value history}), after printing one out.
4305 Another way to create an artificial array is to use a cast.
4306 This re-interprets a value as if it were an array.
4307 The value need not be in memory:
4309 (@value{GDBP}) p/x (short[2])0x12345678
4310 $1 = @{0x1234, 0x5678@}
4313 As a convenience, if you leave the array length out (as in
4314 @samp{(@var{type})[])@var{value}}) gdb calculates the size to fill
4315 the value (as @samp{sizeof(@var{value})/sizeof(@var{type})}:
4317 (@value{GDBP}) p/x (short[])0x12345678
4318 $2 = @{0x1234, 0x5678@}
4321 Sometimes the artificial array mechanism is not quite enough; in
4322 moderately complex data structures, the elements of interest may not
4323 actually be adjacent---for example, if you are interested in the values
4324 of pointers in an array. One useful work-around in this situation is
4325 to use a convenience variable (@pxref{Convenience Vars, ,Convenience
4326 variables}) as a counter in an expression that prints the first
4327 interesting value, and then repeat that expression via @key{RET}. For
4328 instance, suppose you have an array @code{dtab} of pointers to
4329 structures, and you are interested in the values of a field @code{fv}
4330 in each structure. Here is an example of what you might type:
4340 @node Output Formats
4341 @section Output formats
4343 @cindex formatted output
4344 @cindex output formats
4345 By default, @value{GDBN} prints a value according to its data type. Sometimes
4346 this is not what you want. For example, you might want to print a number
4347 in hex, or a pointer in decimal. Or you might want to view data in memory
4348 at a certain address as a character string or as an instruction. To do
4349 these things, specify an @dfn{output format} when you print a value.
4351 The simplest use of output formats is to say how to print a value
4352 already computed. This is done by starting the arguments of the
4353 @code{print} command with a slash and a format letter. The format
4354 letters supported are:
4358 Regard the bits of the value as an integer, and print the integer in
4362 Print as integer in signed decimal.
4365 Print as integer in unsigned decimal.
4368 Print as integer in octal.
4371 Print as integer in binary. The letter @samp{t} stands for ``two''.
4372 @footnote{@samp{b} cannot be used because these format letters are also
4373 used with the @code{x} command, where @samp{b} stands for ``byte'';
4374 @pxref{Memory,,Examining memory}.}
4377 @cindex unknown address, locating
4378 Print as an address, both absolute in hexadecimal and as an offset from
4379 the nearest preceding symbol. You can use this format used to discover
4380 where (in what function) an unknown address is located:
4383 (@value{GDBP}) p/a 0x54320
4384 $3 = 0x54320 <_initialize_vx+396>
4388 Regard as an integer and print it as a character constant.
4391 Regard the bits of the value as a floating point number and print
4392 using typical floating point syntax.
4395 For example, to print the program counter in hex (@pxref{Registers}), type
4402 Note that no space is required before the slash; this is because command
4403 names in @value{GDBN} cannot contain a slash.
4405 To reprint the last value in the value history with a different format,
4406 you can use the @code{print} command with just a format and no
4407 expression. For example, @samp{p/x} reprints the last value in hex.
4410 @section Examining memory
4412 You can use the command @code{x} (for ``examine'') to examine memory in
4413 any of several formats, independently of your program's data types.
4415 @cindex examining memory
4418 @item x/@var{nfu} @var{addr}
4421 Use the @code{x} command to examine memory.
4424 @var{n}, @var{f}, and @var{u} are all optional parameters that specify how
4425 much memory to display and how to format it; @var{addr} is an
4426 expression giving the address where you want to start displaying memory.
4427 If you use defaults for @var{nfu}, you need not type the slash @samp{/}.
4428 Several commands set convenient defaults for @var{addr}.
4431 @item @var{n}, the repeat count
4432 The repeat count is a decimal integer; the default is 1. It specifies
4433 how much memory (counting by units @var{u}) to display.
4434 @c This really is **decimal**; unaffected by 'set radix' as of GDB
4437 @item @var{f}, the display format
4438 The display format is one of the formats used by @code{print},
4439 @samp{s} (null-terminated string), or @samp{i} (machine instruction).
4440 The default is @samp{x} (hexadecimal) initially.
4441 The default changes each time you use either @code{x} or @code{print}.
4443 @item @var{u}, the unit size
4444 The unit size is any of
4450 Halfwords (two bytes).
4452 Words (four bytes). This is the initial default.
4454 Giant words (eight bytes).
4457 Each time you specify a unit size with @code{x}, that size becomes the
4458 default unit the next time you use @code{x}. (For the @samp{s} and
4459 @samp{i} formats, the unit size is ignored and is normally not written.)
4461 @item @var{addr}, starting display address
4462 @var{addr} is the address where you want @value{GDBN} to begin displaying
4463 memory. The expression need not have a pointer value (though it may);
4464 it is always interpreted as an integer address of a byte of memory.
4465 @xref{Expressions, ,Expressions}, for more information on expressions. The default for
4466 @var{addr} is usually just after the last address examined---but several
4467 other commands also set the default address: @code{info breakpoints} (to
4468 the address of the last breakpoint listed), @code{info line} (to the
4469 starting address of a line), and @code{print} (if you use it to display
4470 a value from memory).
4473 For example, @samp{x/3uh 0x54320} is a request to display three halfwords
4474 (@code{h}) of memory, formatted as unsigned decimal integers (@samp{u}),
4475 starting at address @code{0x54320}. @samp{x/4xw $sp} prints the four
4476 words (@samp{w}) of memory above the stack pointer (here, @samp{$sp};
4477 @pxref{Registers}) in hexadecimal (@samp{x}).
4479 Since the letters indicating unit sizes are all distinct from the
4480 letters specifying output formats, you do not have to remember whether
4481 unit size or format comes first; either order works. The output
4482 specifications @samp{4xw} and @samp{4wx} mean exactly the same thing.
4483 (However, the count @var{n} must come first; @samp{wx4} does not work.)
4485 Even though the unit size @var{u} is ignored for the formats @samp{s}
4486 and @samp{i}, you might still want to use a count @var{n}; for example,
4487 @samp{3i} specifies that you want to see three machine instructions,
4488 including any operands. The command @code{disassemble} gives an
4489 alternative way of inspecting machine instructions; @pxref{Machine
4490 Code,,Source and machine code}.
4492 All the defaults for the arguments to @code{x} are designed to make it
4493 easy to continue scanning memory with minimal specifications each time
4494 you use @code{x}. For example, after you have inspected three machine
4495 instructions with @samp{x/3i @var{addr}}, you can inspect the next seven
4496 with just @samp{x/7}. If you use @key{RET} to repeat the @code{x} command,
4497 the repeat count @var{n} is used again; the other arguments default as
4498 for successive uses of @code{x}.
4500 @cindex @code{$_}, @code{$__}, and value history
4501 The addresses and contents printed by the @code{x} command are not saved
4502 in the value history because there is often too much of them and they
4503 would get in the way. Instead, @value{GDBN} makes these values available for
4504 subsequent use in expressions as values of the convenience variables
4505 @code{$_} and @code{$__}. After an @code{x} command, the last address
4506 examined is available for use in expressions in the convenience variable
4507 @code{$_}. The contents of that address, as examined, are available in
4508 the convenience variable @code{$__}.
4510 If the @code{x} command has a repeat count, the address and contents saved
4511 are from the last memory unit printed; this is not the same as the last
4512 address printed if several units were printed on the last line of output.
4515 @section Automatic display
4516 @cindex automatic display
4517 @cindex display of expressions
4519 If you find that you want to print the value of an expression frequently
4520 (to see how it changes), you might want to add it to the @dfn{automatic
4521 display list} so that @value{GDBN} prints its value each time your program stops.
4522 Each expression added to the list is given a number to identify it;
4523 to remove an expression from the list, you specify that number.
4524 The automatic display looks like this:
4528 3: bar[5] = (struct hack *) 0x3804
4532 This display shows item numbers, expressions and their current values. As with
4533 displays you request manually using @code{x} or @code{print}, you can
4534 specify the output format you prefer; in fact, @code{display} decides
4535 whether to use @code{print} or @code{x} depending on how elaborate your
4536 format specification is---it uses @code{x} if you specify a unit size,
4537 or one of the two formats (@samp{i} and @samp{s}) that are only
4538 supported by @code{x}; otherwise it uses @code{print}.
4542 @item display @var{exp}
4543 Add the expression @var{exp} to the list of expressions to display
4544 each time your program stops. @xref{Expressions, ,Expressions}.
4546 @code{display} does not repeat if you press @key{RET} again after using it.
4548 @item display/@var{fmt} @var{exp}
4549 For @var{fmt} specifying only a display format and not a size or
4550 count, add the expression @var{exp} to the auto-display list but
4551 arrange to display it each time in the specified format @var{fmt}.
4552 @xref{Output Formats,,Output formats}.
4554 @item display/@var{fmt} @var{addr}
4555 For @var{fmt} @samp{i} or @samp{s}, or including a unit-size or a
4556 number of units, add the expression @var{addr} as a memory address to
4557 be examined each time your program stops. Examining means in effect
4558 doing @samp{x/@var{fmt} @var{addr}}. @xref{Memory, ,Examining memory}.
4561 For example, @samp{display/i $pc} can be helpful, to see the machine
4562 instruction about to be executed each time execution stops (@samp{$pc}
4563 is a common name for the program counter; @pxref{Registers}).
4566 @kindex delete display
4568 @item undisplay @var{dnums}@dots{}
4569 @itemx delete display @var{dnums}@dots{}
4570 Remove item numbers @var{dnums} from the list of expressions to display.
4572 @code{undisplay} does not repeat if you press @key{RET} after using it.
4573 (Otherwise you would just get the error @samp{No display number @dots{}}.)
4575 @kindex disable display
4576 @item disable display @var{dnums}@dots{}
4577 Disable the display of item numbers @var{dnums}. A disabled display
4578 item is not printed automatically, but is not forgotten. It may be
4579 enabled again later.
4581 @kindex enable display
4582 @item enable display @var{dnums}@dots{}
4583 Enable display of item numbers @var{dnums}. It becomes effective once
4584 again in auto display of its expression, until you specify otherwise.
4587 Display the current values of the expressions on the list, just as is
4588 done when your program stops.
4590 @kindex info display
4592 Print the list of expressions previously set up to display
4593 automatically, each one with its item number, but without showing the
4594 values. This includes disabled expressions, which are marked as such.
4595 It also includes expressions which would not be displayed right now
4596 because they refer to automatic variables not currently available.
4599 If a display expression refers to local variables, then it does not make
4600 sense outside the lexical context for which it was set up. Such an
4601 expression is disabled when execution enters a context where one of its
4602 variables is not defined. For example, if you give the command
4603 @code{display last_char} while inside a function with an argument
4604 @code{last_char}, @value{GDBN} displays this argument while your program
4605 continues to stop inside that function. When it stops elsewhere---where
4606 there is no variable @code{last_char}---the display is disabled
4607 automatically. The next time your program stops where @code{last_char}
4608 is meaningful, you can enable the display expression once again.
4610 @node Print Settings
4611 @section Print settings
4613 @cindex format options
4614 @cindex print settings
4615 @value{GDBN} provides the following ways to control how arrays, structures,
4616 and symbols are printed.
4619 These settings are useful for debugging programs in any language:
4622 @kindex set print address
4623 @item set print address
4624 @itemx set print address on
4625 @value{GDBN} prints memory addresses showing the location of stack
4626 traces, structure values, pointer values, breakpoints, and so forth,
4627 even when it also displays the contents of those addresses. The default
4628 is @code{on}. For example, this is what a stack frame display looks like with
4629 @code{set print address on}:
4634 #0 set_quotes (lq=0x34c78 "<<", rq=0x34c88 ">>")
4636 530 if (lquote != def_lquote)
4640 @item set print address off
4641 Do not print addresses when displaying their contents. For example,
4642 this is the same stack frame displayed with @code{set print address off}:
4646 (@value{GDBP}) set print addr off
4648 #0 set_quotes (lq="<<", rq=">>") at input.c:530
4649 530 if (lquote != def_lquote)
4653 You can use @samp{set print address off} to eliminate all machine
4654 dependent displays from the @value{GDBN} interface. For example, with
4655 @code{print address off}, you should get the same text for backtraces on
4656 all machines---whether or not they involve pointer arguments.
4658 @kindex show print address
4659 @item show print address
4660 Show whether or not addresses are to be printed.
4663 When @value{GDBN} prints a symbolic address, it normally prints the
4664 closest earlier symbol plus an offset. If that symbol does not uniquely
4665 identify the address (for example, it is a name whose scope is a single
4666 source file), you may need to clarify. One way to do this is with
4667 @code{info line}, for example @samp{info line *0x4537}. Alternately,
4668 you can set @value{GDBN} to print the source file and line number when
4669 it prints a symbolic address:
4672 @kindex set print symbol-filename
4673 @item set print symbol-filename on
4674 Tell @value{GDBN} to print the source file name and line number of a
4675 symbol in the symbolic form of an address.
4677 @item set print symbol-filename off
4678 Do not print source file name and line number of a symbol. This is the
4681 @kindex show print symbol-filename
4682 @item show print symbol-filename
4683 Show whether or not @value{GDBN} will print the source file name and
4684 line number of a symbol in the symbolic form of an address.
4687 Another situation where it is helpful to show symbol filenames and line
4688 numbers is when disassembling code; @value{GDBN} shows you the line
4689 number and source file that corresponds to each instruction.
4691 Also, you may wish to see the symbolic form only if the address being
4692 printed is reasonably close to the closest earlier symbol:
4695 @kindex set print max-symbolic-offset
4696 @item set print max-symbolic-offset @var{max-offset}
4697 Tell @value{GDBN} to only display the symbolic form of an address if the
4698 offset between the closest earlier symbol and the address is less than
4699 @var{max-offset}. The default is 0, which tells @value{GDBN}
4700 to always print the symbolic form of an address if any symbol precedes it.
4702 @kindex show print max-symbolic-offset
4703 @item show print max-symbolic-offset
4704 Ask how large the maximum offset is that @value{GDBN} prints in a
4708 @cindex wild pointer, interpreting
4709 @cindex pointer, finding referent
4710 If you have a pointer and you are not sure where it points, try
4711 @samp{set print symbol-filename on}. Then you can determine the name
4712 and source file location of the variable where it points, using
4713 @samp{p/a @var{pointer}}. This interprets the address in symbolic form.
4714 For example, here @value{GDBN} shows that a variable @code{ptt} points
4715 at another variable @code{t}, defined in @file{hi2.c}:
4718 (@value{GDBP}) set print symbol-filename on
4719 (@value{GDBP}) p/a ptt
4720 $4 = 0xe008 <t in hi2.c>
4724 @emph{Warning:} For pointers that point to a local variable, @samp{p/a}
4725 does not show the symbol name and filename of the referent, even with
4726 the appropriate @code{set print} options turned on.
4729 Other settings control how different kinds of objects are printed:
4732 @kindex set print array
4733 @item set print array
4734 @itemx set print array on
4735 Pretty print arrays. This format is more convenient to read,
4736 but uses more space. The default is off.
4738 @item set print array off
4739 Return to compressed format for arrays.
4741 @kindex show print array
4742 @item show print array
4743 Show whether compressed or pretty format is selected for displaying
4746 @kindex set print elements
4747 @item set print elements @var{number-of-elements}
4748 Set a limit on how many elements of an array @value{GDBN} will print.
4749 If @value{GDBN} is printing a large array, it stops printing after it has
4750 printed the number of elements set by the @code{set print elements} command.
4751 This limit also applies to the display of strings.
4752 Setting @var{number-of-elements} to zero means that the printing is unlimited.
4754 @kindex show print elements
4755 @item show print elements
4756 Display the number of elements of a large array that @value{GDBN} will print.
4757 If the number is 0, then the printing is unlimited.
4759 @kindex set print null-stop
4760 @item set print null-stop
4761 Cause @value{GDBN} to stop printing the characters of an array when the first
4762 @sc{NULL} is encountered. This is useful when large arrays actually
4763 contain only short strings.
4765 @kindex set print pretty
4766 @item set print pretty on
4767 Cause @value{GDBN} to print structures in an indented format with one member
4768 per line, like this:
4783 @item set print pretty off
4784 Cause @value{GDBN} to print structures in a compact format, like this:
4788 $1 = @{next = 0x0, flags = @{sweet = 1, sour = 1@}, \
4789 meat = 0x54 "Pork"@}
4794 This is the default format.
4796 @kindex show print pretty
4797 @item show print pretty
4798 Show which format @value{GDBN} is using to print structures.
4800 @kindex set print sevenbit-strings
4801 @item set print sevenbit-strings on
4802 Print using only seven-bit characters; if this option is set,
4803 @value{GDBN} displays any eight-bit characters (in strings or
4804 character values) using the notation @code{\}@var{nnn}. This setting is
4805 best if you are working in English (@sc{ascii}) and you use the
4806 high-order bit of characters as a marker or ``meta'' bit.
4808 @item set print sevenbit-strings off
4809 Print full eight-bit characters. This allows the use of more
4810 international character sets, and is the default.
4812 @kindex show print sevenbit-strings
4813 @item show print sevenbit-strings
4814 Show whether or not @value{GDBN} is printing only seven-bit characters.
4816 @kindex set print union
4817 @item set print union on
4818 Tell @value{GDBN} to print unions which are contained in structures. This
4819 is the default setting.
4821 @item set print union off
4822 Tell @value{GDBN} not to print unions which are contained in structures.
4824 @kindex show print union
4825 @item show print union
4826 Ask @value{GDBN} whether or not it will print unions which are contained in
4829 For example, given the declarations
4832 typedef enum @{Tree, Bug@} Species;
4833 typedef enum @{Big_tree, Acorn, Seedling@} Tree_forms;
4834 typedef enum @{Caterpillar, Cocoon, Butterfly@}
4845 struct thing foo = @{Tree, @{Acorn@}@};
4849 with @code{set print union on} in effect @samp{p foo} would print
4852 $1 = @{it = Tree, form = @{tree = Acorn, bug = Cocoon@}@}
4856 and with @code{set print union off} in effect it would print
4859 $1 = @{it = Tree, form = @{...@}@}
4865 These settings are of interest when debugging C++ programs:
4869 @kindex set print demangle
4870 @item set print demangle
4871 @itemx set print demangle on
4872 Print C++ names in their source form rather than in the encoded
4873 (``mangled'') form passed to the assembler and linker for type-safe
4874 linkage. The default is @samp{on}.
4876 @kindex show print demangle
4877 @item show print demangle
4878 Show whether C++ names are printed in mangled or demangled form.
4880 @kindex set print asm-demangle
4881 @item set print asm-demangle
4882 @itemx set print asm-demangle on
4883 Print C++ names in their source form rather than their mangled form, even
4884 in assembler code printouts such as instruction disassemblies.
4887 @kindex show print asm-demangle
4888 @item show print asm-demangle
4889 Show whether C++ names in assembly listings are printed in mangled
4892 @kindex set demangle-style
4893 @cindex C++ symbol decoding style
4894 @cindex symbol decoding style, C++
4895 @item set demangle-style @var{style}
4896 Choose among several encoding schemes used by different compilers to
4897 represent C++ names. The choices for @var{style} are currently:
4901 Allow @value{GDBN} to choose a decoding style by inspecting your program.
4904 Decode based on the @sc{gnu} C++ compiler (@code{g++}) encoding algorithm.
4905 This is the default.
4908 Decode based on the HP ANSI C++ (@code{aCC}) encoding algorithm.
4911 Decode based on the Lucid C++ compiler (@code{lcc}) encoding algorithm.
4914 Decode using the algorithm in the @cite{C++ Annotated Reference Manual}.
4915 @strong{Warning:} this setting alone is not sufficient to allow
4916 debugging @code{cfront}-generated executables. @value{GDBN} would
4917 require further enhancement to permit that.
4920 If you omit @var{style}, you will see a list of possible formats.
4922 @kindex show demangle-style
4923 @item show demangle-style
4924 Display the encoding style currently in use for decoding C++ symbols.
4926 @kindex set print object
4927 @item set print object
4928 @itemx set print object on
4929 When displaying a pointer to an object, identify the @emph{actual}
4930 (derived) type of the object rather than the @emph{declared} type, using
4931 the virtual function table.
4933 @item set print object off
4934 Display only the declared type of objects, without reference to the
4935 virtual function table. This is the default setting.
4937 @kindex show print object
4938 @item show print object
4939 Show whether actual, or declared, object types are displayed.
4941 @kindex set print static-members
4942 @item set print static-members
4943 @itemx set print static-members on
4944 Print static members when displaying a C++ object. The default is on.
4946 @item set print static-members off
4947 Do not print static members when displaying a C++ object.
4949 @kindex show print static-members
4950 @item show print static-members
4951 Show whether C++ static members are printed, or not.
4953 @c These don't work with HP ANSI C++ yet.
4954 @kindex set print vtbl
4955 @item set print vtbl
4956 @itemx set print vtbl on
4957 Pretty print C++ virtual function tables. The default is off.
4958 (The @code{vtbl} commands do not work on programs compiled with the HP
4959 ANSI C++ compiler (@code{aCC}).)
4961 @item set print vtbl off
4962 Do not pretty print C++ virtual function tables.
4964 @kindex show print vtbl
4965 @item show print vtbl
4966 Show whether C++ virtual function tables are pretty printed, or not.
4970 @section Value history
4972 @cindex value history
4973 Values printed by the @code{print} command are saved in the @value{GDBN}
4974 @dfn{value history}. This allows you to refer to them in other expressions.
4975 Values are kept until the symbol table is re-read or discarded
4976 (for example with the @code{file} or @code{symbol-file} commands).
4977 When the symbol table changes, the value history is discarded,
4978 since the values may contain pointers back to the types defined in the
4983 @cindex history number
4984 The values printed are given @dfn{history numbers} by which you can
4985 refer to them. These are successive integers starting with one.
4986 @code{print} shows you the history number assigned to a value by
4987 printing @samp{$@var{num} = } before the value; here @var{num} is the
4990 To refer to any previous value, use @samp{$} followed by the value's
4991 history number. The way @code{print} labels its output is designed to
4992 remind you of this. Just @code{$} refers to the most recent value in
4993 the history, and @code{$$} refers to the value before that.
4994 @code{$$@var{n}} refers to the @var{n}th value from the end; @code{$$2}
4995 is the value just prior to @code{$$}, @code{$$1} is equivalent to
4996 @code{$$}, and @code{$$0} is equivalent to @code{$}.
4998 For example, suppose you have just printed a pointer to a structure and
4999 want to see the contents of the structure. It suffices to type
5005 If you have a chain of structures where the component @code{next} points
5006 to the next one, you can print the contents of the next one with this:
5013 You can print successive links in the chain by repeating this
5014 command---which you can do by just typing @key{RET}.
5016 Note that the history records values, not expressions. If the value of
5017 @code{x} is 4 and you type these commands:
5025 then the value recorded in the value history by the @code{print} command
5026 remains 4 even though the value of @code{x} has changed.
5031 Print the last ten values in the value history, with their item numbers.
5032 This is like @samp{p@ $$9} repeated ten times, except that @code{show
5033 values} does not change the history.
5035 @item show values @var{n}
5036 Print ten history values centered on history item number @var{n}.
5039 Print ten history values just after the values last printed. If no more
5040 values are available, @code{show values +} produces no display.
5043 Pressing @key{RET} to repeat @code{show values @var{n}} has exactly the
5044 same effect as @samp{show values +}.
5046 @node Convenience Vars
5047 @section Convenience variables
5049 @cindex convenience variables
5050 @value{GDBN} provides @dfn{convenience variables} that you can use within
5051 @value{GDBN} to hold on to a value and refer to it later. These variables
5052 exist entirely within @value{GDBN}; they are not part of your program, and
5053 setting a convenience variable has no direct effect on further execution
5054 of your program. That is why you can use them freely.
5056 Convenience variables are prefixed with @samp{$}. Any name preceded by
5057 @samp{$} can be used for a convenience variable, unless it is one of
5058 the predefined machine-specific register names (@pxref{Registers}).
5059 (Value history references, in contrast, are @emph{numbers} preceded
5060 by @samp{$}. @xref{Value History, ,Value history}.)
5062 You can save a value in a convenience variable with an assignment
5063 expression, just as you would set a variable in your program.
5067 set $foo = *object_ptr
5071 would save in @code{$foo} the value contained in the object pointed to by
5074 Using a convenience variable for the first time creates it, but its
5075 value is @code{void} until you assign a new value. You can alter the
5076 value with another assignment at any time.
5078 Convenience variables have no fixed types. You can assign a convenience
5079 variable any type of value, including structures and arrays, even if
5080 that variable already has a value of a different type. The convenience
5081 variable, when used as an expression, has the type of its current value.
5084 @kindex show convenience
5085 @item show convenience
5086 Print a list of convenience variables used so far, and their values.
5087 Abbreviated @code{show con}.
5090 One of the ways to use a convenience variable is as a counter to be
5091 incremented or a pointer to be advanced. For example, to print
5092 a field from successive elements of an array of structures:
5096 print bar[$i++]->contents
5099 @noindent Repeat that command by typing @key{RET}.
5101 Some convenience variables are created automatically by @value{GDBN} and given
5102 values likely to be useful.
5107 The variable @code{$_} is automatically set by the @code{x} command to
5108 the last address examined (@pxref{Memory, ,Examining memory}). Other
5109 commands which provide a default address for @code{x} to examine also
5110 set @code{$_} to that address; these commands include @code{info line}
5111 and @code{info breakpoint}. The type of @code{$_} is @code{void *}
5112 except when set by the @code{x} command, in which case it is a pointer
5113 to the type of @code{$__}.
5117 The variable @code{$__} is automatically set by the @code{x} command
5118 to the value found in the last address examined. Its type is chosen
5119 to match the format in which the data was printed.
5123 The variable @code{$_exitcode} is automatically set to the exit code when
5124 the program being debugged terminates.
5127 On HP-UX systems, if you refer to a function or variable name that
5128 begins with a dollar sign, @value{GDBN} searches for a user or system
5129 name first, before it searches for a convenience variable.
5135 You can refer to machine register contents, in expressions, as variables
5136 with names starting with @samp{$}. The names of registers are different
5137 for each machine; use @code{info registers} to see the names used on
5141 @kindex info registers
5142 @item info registers
5143 Print the names and values of all registers except floating-point
5144 registers (in the selected stack frame).
5146 @kindex info all-registers
5147 @cindex floating point registers
5148 @item info all-registers
5149 Print the names and values of all registers, including floating-point
5152 @item info registers @var{regname} @dots{}
5153 Print the @dfn{relativized} value of each specified register @var{regname}.
5154 As discussed in detail below, register values are normally relative to
5155 the selected stack frame. @var{regname} may be any register name valid on
5156 the machine you are using, with or without the initial @samp{$}.
5159 @value{GDBN} has four ``standard'' register names that are available (in
5160 expressions) on most machines---whenever they do not conflict with an
5161 architecture's canonical mnemonics for registers. The register names
5162 @code{$pc} and @code{$sp} are used for the program counter register and
5163 the stack pointer. @code{$fp} is used for a register that contains a
5164 pointer to the current stack frame, and @code{$ps} is used for a
5165 register that contains the processor status. For example,
5166 you could print the program counter in hex with
5173 or print the instruction to be executed next with
5180 or add four to the stack pointer@footnote{This is a way of removing
5181 one word from the stack, on machines where stacks grow downward in
5182 memory (most machines, nowadays). This assumes that the innermost
5183 stack frame is selected; setting @code{$sp} is not allowed when other
5184 stack frames are selected. To pop entire frames off the stack,
5185 regardless of machine architecture, use @code{return};
5186 @pxref{Returning, ,Returning from a function}.} with
5192 Whenever possible, these four standard register names are available on
5193 your machine even though the machine has different canonical mnemonics,
5194 so long as there is no conflict. The @code{info registers} command
5195 shows the canonical names. For example, on the SPARC, @code{info
5196 registers} displays the processor status register as @code{$psr} but you
5197 can also refer to it as @code{$ps}.
5199 @value{GDBN} always considers the contents of an ordinary register as an
5200 integer when the register is examined in this way. Some machines have
5201 special registers which can hold nothing but floating point; these
5202 registers are considered to have floating point values. There is no way
5203 to refer to the contents of an ordinary register as floating point value
5204 (although you can @emph{print} it as a floating point value with
5205 @samp{print/f $@var{regname}}).
5207 Some registers have distinct ``raw'' and ``virtual'' data formats. This
5208 means that the data format in which the register contents are saved by
5209 the operating system is not the same one that your program normally
5210 sees. For example, the registers of the 68881 floating point
5211 coprocessor are always saved in ``extended'' (raw) format, but all C
5212 programs expect to work with ``double'' (virtual) format. In such
5213 cases, @value{GDBN} normally works with the virtual format only (the format
5214 that makes sense for your program), but the @code{info registers} command
5215 prints the data in both formats.
5217 Normally, register values are relative to the selected stack frame
5218 (@pxref{Selection, ,Selecting a frame}). This means that you get the
5219 value that the register would contain if all stack frames farther in
5220 were exited and their saved registers restored. In order to see the
5221 true contents of hardware registers, you must select the innermost
5222 frame (with @samp{frame 0}).
5224 However, @value{GDBN} must deduce where registers are saved, from the machine
5225 code generated by your compiler. If some registers are not saved, or if
5226 @value{GDBN} is unable to locate the saved registers, the selected stack
5227 frame makes no difference.
5230 @kindex set rstack_high_address
5231 @cindex AMD 29K register stack
5232 @cindex register stack, AMD29K
5233 @item set rstack_high_address @var{address}
5234 On AMD 29000 family processors, registers are saved in a separate
5235 ``register stack''. There is no way for @value{GDBN} to determine the extent
5236 of this stack. Normally, @value{GDBN} just assumes that the stack is ``large
5237 enough''. This may result in @value{GDBN} referencing memory locations that
5238 do not exist. If necessary, you can get around this problem by
5239 specifying the ending address of the register stack with the @code{set
5240 rstack_high_address} command. The argument should be an address, which
5241 you probably want to precede with @samp{0x} to specify in
5244 @kindex show rstack_high_address
5245 @item show rstack_high_address
5246 Display the current limit of the register stack, on AMD 29000 family
5250 @node Floating Point Hardware
5251 @section Floating point hardware
5252 @cindex floating point
5254 Depending on the configuration, @value{GDBN} may be able to give
5255 you more information about the status of the floating point hardware.
5260 Display hardware-dependent information about the floating
5261 point unit. The exact contents and layout vary depending on the
5262 floating point chip. Currently, @samp{info float} is supported on
5263 the ARM and x86 machines.
5267 @chapter Using @value{GDBN} with Different Languages
5270 Although programming languages generally have common aspects, they are
5271 rarely expressed in the same manner. For instance, in ANSI C,
5272 dereferencing a pointer @code{p} is accomplished by @code{*p}, but in
5273 Modula-2, it is accomplished by @code{p^}. Values can also be
5274 represented (and displayed) differently. Hex numbers in C appear as
5275 @samp{0x1ae}, while in Modula-2 they appear as @samp{1AEH}.
5277 @cindex working language
5278 Language-specific information is built into @value{GDBN} for some languages,
5279 allowing you to express operations like the above in your program's
5280 native language, and allowing @value{GDBN} to output values in a manner
5281 consistent with the syntax of your program's native language. The
5282 language you use to build expressions is called the @dfn{working
5286 * Setting:: Switching between source languages
5287 * Show:: Displaying the language
5288 * Checks:: Type and range checks
5289 * Support:: Supported languages
5293 @section Switching between source languages
5295 There are two ways to control the working language---either have @value{GDBN}
5296 set it automatically, or select it manually yourself. You can use the
5297 @code{set language} command for either purpose. On startup, @value{GDBN}
5298 defaults to setting the language automatically. The working language is
5299 used to determine how expressions you type are interpreted, how values
5302 In addition to the working language, every source file that
5303 @value{GDBN} knows about has its own working language. For some object
5304 file formats, the compiler might indicate which language a particular
5305 source file is in. However, most of the time @value{GDBN} infers the
5306 language from the name of the file. The language of a source file
5307 controls whether C++ names are demangled---this way @code{backtrace} can
5308 show each frame appropriately for its own language. There is no way to
5309 set the language of a source file from within @value{GDBN}.
5311 This is most commonly a problem when you use a program, such
5312 as @code{cfront} or @code{f2c}, that generates C but is written in
5313 another language. In that case, make the
5314 program use @code{#line} directives in its C output; that way
5315 @value{GDBN} will know the correct language of the source code of the original
5316 program, and will display that source code, not the generated C code.
5319 * Filenames:: Filename extensions and languages.
5320 * Manually:: Setting the working language manually
5321 * Automatically:: Having @value{GDBN} infer the source language
5325 @subsection List of filename extensions and languages
5327 If a source file name ends in one of the following extensions, then
5328 @value{GDBN} infers that its language is the one indicated.
5353 Modula-2 source file
5357 Assembler source file. This actually behaves almost like C, but
5358 @value{GDBN} does not skip over function prologues when stepping.
5361 In addition, you may set the language associated with a filename
5362 extension. @xref{Show, , Displaying the language}.
5365 @subsection Setting the working language
5367 If you allow @value{GDBN} to set the language automatically,
5368 expressions are interpreted the same way in your debugging session and
5371 @kindex set language
5372 If you wish, you may set the language manually. To do this, issue the
5373 command @samp{set language @var{lang}}, where @var{lang} is the name of
5375 @code{c} or @code{modula-2}.
5376 For a list of the supported languages, type @samp{set language}.
5378 Setting the language manually prevents @value{GDBN} from updating the working
5379 language automatically. This can lead to confusion if you try
5380 to debug a program when the working language is not the same as the
5381 source language, when an expression is acceptable to both
5382 languages---but means different things. For instance, if the current
5383 source file were written in C, and @value{GDBN} was parsing Modula-2, a
5391 might not have the effect you intended. In C, this means to add
5392 @code{b} and @code{c} and place the result in @code{a}. The result
5393 printed would be the value of @code{a}. In Modula-2, this means to compare
5394 @code{a} to the result of @code{b+c}, yielding a @code{BOOLEAN} value.
5397 @subsection Having @value{GDBN} infer the source language
5399 To have @value{GDBN} set the working language automatically, use
5400 @samp{set language local} or @samp{set language auto}. @value{GDBN}
5401 then infers the working language. That is, when your program stops in a
5402 frame (usually by encountering a breakpoint), @value{GDBN} sets the
5403 working language to the language recorded for the function in that
5404 frame. If the language for a frame is unknown (that is, if the function
5405 or block corresponding to the frame was defined in a source file that
5406 does not have a recognized extension), the current working language is
5407 not changed, and @value{GDBN} issues a warning.
5409 This may not seem necessary for most programs, which are written
5410 entirely in one source language. However, program modules and libraries
5411 written in one source language can be used by a main program written in
5412 a different source language. Using @samp{set language auto} in this
5413 case frees you from having to set the working language manually.
5416 @section Displaying the language
5418 The following commands help you find out which language is the
5419 working language, and also what language source files were written in.
5421 @kindex show language
5426 Display the current working language. This is the
5427 language you can use with commands such as @code{print} to
5428 build and compute expressions that may involve variables in your program.
5431 Display the source language for this frame. This language becomes the
5432 working language if you use an identifier from this frame.
5433 @xref{Frame Info, ,Information about a frame}, to identify the other
5434 information listed here.
5437 Display the source language of this source file.
5438 @xref{Symbols, ,Examining the Symbol Table}, to identify the other
5439 information listed here.
5442 In unusual circumstances, you may have source files with extensions
5443 not in the standard list. You can then set the extension associated
5444 with a language explicitly:
5446 @kindex set extension-language
5447 @kindex info extensions
5449 @item set extension-language @var{.ext} @var{language}
5450 Set source files with extension @var{.ext} to be assumed to be in
5451 the source language @var{language}.
5453 @item info extensions
5454 List all the filename extensions and the associated languages.
5458 @section Type and range checking
5461 @emph{Warning:} In this release, the @value{GDBN} commands for type and range
5462 checking are included, but they do not yet have any effect. This
5463 section documents the intended facilities.
5465 @c FIXME remove warning when type/range code added
5467 Some languages are designed to guard you against making seemingly common
5468 errors through a series of compile- and run-time checks. These include
5469 checking the type of arguments to functions and operators, and making
5470 sure mathematical overflows are caught at run time. Checks such as
5471 these help to ensure a program's correctness once it has been compiled
5472 by eliminating type mismatches, and providing active checks for range
5473 errors when your program is running.
5475 @value{GDBN} can check for conditions like the above if you wish.
5476 Although @value{GDBN} does not check the statements in your program, it
5477 can check expressions entered directly into @value{GDBN} for evaluation via
5478 the @code{print} command, for example. As with the working language,
5479 @value{GDBN} can also decide whether or not to check automatically based on
5480 your program's source language. @xref{Support, ,Supported languages},
5481 for the default settings of supported languages.
5484 * Type Checking:: An overview of type checking
5485 * Range Checking:: An overview of range checking
5488 @cindex type checking
5489 @cindex checks, type
5491 @subsection An overview of type checking
5493 Some languages, such as Modula-2, are strongly typed, meaning that the
5494 arguments to operators and functions have to be of the correct type,
5495 otherwise an error occurs. These checks prevent type mismatch
5496 errors from ever causing any run-time problems. For example,
5504 The second example fails because the @code{CARDINAL} 1 is not
5505 type-compatible with the @code{REAL} 2.3.
5507 For the expressions you use in @value{GDBN} commands, you can tell the
5508 @value{GDBN} type checker to skip checking;
5509 to treat any mismatches as errors and abandon the expression;
5510 or to only issue warnings when type mismatches occur,
5511 but evaluate the expression anyway. When you choose the last of
5512 these, @value{GDBN} evaluates expressions like the second example above, but
5513 also issues a warning.
5515 Even if you turn type checking off, there may be other reasons
5516 related to type that prevent @value{GDBN} from evaluating an expression.
5517 For instance, @value{GDBN} does not know how to add an @code{int} and
5518 a @code{struct foo}. These particular type errors have nothing to do
5519 with the language in use, and usually arise from expressions, such as
5520 the one described above, which make little sense to evaluate anyway.
5522 Each language defines to what degree it is strict about type. For
5523 instance, both Modula-2 and C require the arguments to arithmetical
5524 operators to be numbers. In C, enumerated types and pointers can be
5525 represented as numbers, so that they are valid arguments to mathematical
5526 operators. @xref{Support, ,Supported languages}, for further
5527 details on specific languages.
5529 @value{GDBN} provides some additional commands for controlling the type checker:
5532 @kindex set check type
5533 @kindex show check type
5535 @item set check type auto
5536 Set type checking on or off based on the current working language.
5537 @xref{Support, ,Supported languages}, for the default settings for
5540 @item set check type on
5541 @itemx set check type off
5542 Set type checking on or off, overriding the default setting for the
5543 current working language. Issue a warning if the setting does not
5544 match the language default. If any type mismatches occur in
5545 evaluating an expression while typechecking is on, @value{GDBN} prints a
5546 message and aborts evaluation of the expression.
5548 @item set check type warn
5549 Cause the type checker to issue warnings, but to always attempt to
5550 evaluate the expression. Evaluating the expression may still
5551 be impossible for other reasons. For example, @value{GDBN} cannot add
5552 numbers and structures.
5555 Show the current setting of the type checker, and whether or not @value{GDBN}
5556 is setting it automatically.
5559 @cindex range checking
5560 @cindex checks, range
5561 @node Range Checking
5562 @subsection An overview of range checking
5564 In some languages (such as Modula-2), it is an error to exceed the
5565 bounds of a type; this is enforced with run-time checks. Such range
5566 checking is meant to ensure program correctness by making sure
5567 computations do not overflow, or indices on an array element access do
5568 not exceed the bounds of the array.
5570 For expressions you use in @value{GDBN} commands, you can tell
5571 @value{GDBN} to treat range errors in one of three ways: ignore them,
5572 always treat them as errors and abandon the expression, or issue
5573 warnings but evaluate the expression anyway.
5575 A range error can result from numerical overflow, from exceeding an
5576 array index bound, or when you type a constant that is not a member
5577 of any type. Some languages, however, do not treat overflows as an
5578 error. In many implementations of C, mathematical overflow causes the
5579 result to ``wrap around'' to lower values---for example, if @var{m} is
5580 the largest integer value, and @var{s} is the smallest, then
5583 @var{m} + 1 @result{} @var{s}
5586 This, too, is specific to individual languages, and in some cases
5587 specific to individual compilers or machines. @xref{Support, ,
5588 Supported languages}, for further details on specific languages.
5590 @value{GDBN} provides some additional commands for controlling the range checker:
5593 @kindex set check range
5594 @kindex show check range
5596 @item set check range auto
5597 Set range checking on or off based on the current working language.
5598 @xref{Support, ,Supported languages}, for the default settings for
5601 @item set check range on
5602 @itemx set check range off
5603 Set range checking on or off, overriding the default setting for the
5604 current working language. A warning is issued if the setting does not
5605 match the language default. If a range error occurs, then a message
5606 is printed and evaluation of the expression is aborted.
5608 @item set check range warn
5609 Output messages when the @value{GDBN} range checker detects a range error,
5610 but attempt to evaluate the expression anyway. Evaluating the
5611 expression may still be impossible for other reasons, such as accessing
5612 memory that the process does not own (a typical example from many Unix
5616 Show the current setting of the range checker, and whether or not it is
5617 being set automatically by @value{GDBN}.
5621 @section Supported languages
5623 @value{GDBN} supports C, C++, Fortran, Java, Chill, assembly, and Modula-2.
5624 @c This is false ...
5625 Some @value{GDBN} features may be used in expressions regardless of the
5626 language you use: the @value{GDBN} @code{@@} and @code{::} operators,
5627 and the @samp{@{type@}addr} construct (@pxref{Expressions,
5628 ,Expressions}) can be used with the constructs of any supported
5631 The following sections detail to what degree each source language is
5632 supported by @value{GDBN}. These sections are not meant to be language
5633 tutorials or references, but serve only as a reference guide to what the
5634 @value{GDBN} expression parser accepts, and what input and output
5635 formats should look like for different languages. There are many good
5636 books written on each of these languages; please look to these for a
5637 language reference or tutorial.
5641 * Modula-2:: Modula-2
5646 @subsection C and C++
5649 @cindex expressions in C or C++
5651 Since C and C++ are so closely related, many features of @value{GDBN} apply
5652 to both languages. Whenever this is the case, we discuss those languages
5657 @cindex @sc{gnu} C++
5658 The C++ debugging facilities are jointly implemented by the C++
5659 compiler and @value{GDBN}. Therefore, to debug your C++ code
5660 effectively, you must compile your C++ programs with a supported
5661 C++ compiler, such as @sc{gnu} @code{g++}, or the HP ANSI C++
5662 compiler (@code{aCC}).
5664 For best results when using @sc{gnu} C++, use the stabs debugging
5665 format. You can select that format explicitly with the @code{g++}
5666 command-line options @samp{-gstabs} or @samp{-gstabs+}. See
5667 @ref{Debugging Options,,Options for Debugging Your Program or @sc{gnu}
5668 CC, gcc.info, Using @sc{gnu} CC}, for more information.
5671 * C Operators:: C and C++ operators
5672 * C Constants:: C and C++ constants
5673 * C plus plus expressions:: C++ expressions
5674 * C Defaults:: Default settings for C and C++
5675 * C Checks:: C and C++ type and range checks
5676 * Debugging C:: @value{GDBN} and C
5677 * Debugging C plus plus:: @value{GDBN} features for C++
5681 @subsubsection C and C++ operators
5683 @cindex C and C++ operators
5685 Operators must be defined on values of specific types. For instance,
5686 @code{+} is defined on numbers, but not on structures. Operators are
5687 often defined on groups of types.
5689 For the purposes of C and C++, the following definitions hold:
5694 @emph{Integral types} include @code{int} with any of its storage-class
5695 specifiers; @code{char}; @code{enum}; and, for C++, @code{bool}.
5698 @emph{Floating-point types} include @code{float} and @code{double}.
5701 @emph{Pointer types} include all types defined as @code{(@var{type} *)}.
5704 @emph{Scalar types} include all of the above.
5709 The following operators are supported. They are listed here
5710 in order of increasing precedence:
5714 The comma or sequencing operator. Expressions in a comma-separated list
5715 are evaluated from left to right, with the result of the entire
5716 expression being the last expression evaluated.
5719 Assignment. The value of an assignment expression is the value
5720 assigned. Defined on scalar types.
5723 Used in an expression of the form @w{@code{@var{a} @var{op}= @var{b}}},
5724 and translated to @w{@code{@var{a} = @var{a op b}}}.
5725 @w{@code{@var{op}=}} and @code{=} have the same precendence.
5726 @var{op} is any one of the operators @code{|}, @code{^}, @code{&},
5727 @code{<<}, @code{>>}, @code{+}, @code{-}, @code{*}, @code{/}, @code{%}.
5730 The ternary operator. @code{@var{a} ? @var{b} : @var{c}} can be thought
5731 of as: if @var{a} then @var{b} else @var{c}. @var{a} should be of an
5735 Logical @sc{or}. Defined on integral types.
5738 Logical @sc{and}. Defined on integral types.
5741 Bitwise @sc{or}. Defined on integral types.
5744 Bitwise exclusive-@sc{or}. Defined on integral types.
5747 Bitwise @sc{and}. Defined on integral types.
5750 Equality and inequality. Defined on scalar types. The value of these
5751 expressions is 0 for false and non-zero for true.
5753 @item <@r{, }>@r{, }<=@r{, }>=
5754 Less than, greater than, less than or equal, greater than or equal.
5755 Defined on scalar types. The value of these expressions is 0 for false
5756 and non-zero for true.
5759 left shift, and right shift. Defined on integral types.
5762 The @value{GDBN} ``artificial array'' operator (@pxref{Expressions, ,Expressions}).
5765 Addition and subtraction. Defined on integral types, floating-point types and
5768 @item *@r{, }/@r{, }%
5769 Multiplication, division, and modulus. Multiplication and division are
5770 defined on integral and floating-point types. Modulus is defined on
5774 Increment and decrement. When appearing before a variable, the
5775 operation is performed before the variable is used in an expression;
5776 when appearing after it, the variable's value is used before the
5777 operation takes place.
5780 Pointer dereferencing. Defined on pointer types. Same precedence as
5784 Address operator. Defined on variables. Same precedence as @code{++}.
5786 For debugging C++, @value{GDBN} implements a use of @samp{&} beyond what is
5787 allowed in the C++ language itself: you can use @samp{&(&@var{ref})}
5788 (or, if you prefer, simply @samp{&&@var{ref}}) to examine the address
5789 where a C++ reference variable (declared with @samp{&@var{ref}}) is
5793 Negative. Defined on integral and floating-point types. Same
5794 precedence as @code{++}.
5797 Logical negation. Defined on integral types. Same precedence as
5801 Bitwise complement operator. Defined on integral types. Same precedence as
5806 Structure member, and pointer-to-structure member. For convenience,
5807 @value{GDBN} regards the two as equivalent, choosing whether to dereference a
5808 pointer based on the stored type information.
5809 Defined on @code{struct} and @code{union} data.
5812 Dereferences of pointers to members.
5815 Array indexing. @code{@var{a}[@var{i}]} is defined as
5816 @code{*(@var{a}+@var{i})}. Same precedence as @code{->}.
5819 Function parameter list. Same precedence as @code{->}.
5822 C++ scope resolution operator. Defined on @code{struct}, @code{union},
5823 and @code{class} types.
5826 Doubled colons also represent the @value{GDBN} scope operator
5827 (@pxref{Expressions, ,Expressions}). Same precedence as @code{::},
5831 If an operator is redefined in the user code, @value{GDBN} usually
5832 attempts to invoke the redefined version instead of using the operator's
5840 @subsubsection C and C++ constants
5842 @cindex C and C++ constants
5844 @value{GDBN} allows you to express the constants of C and C++ in the
5849 Integer constants are a sequence of digits. Octal constants are
5850 specified by a leading @samp{0} (i.e. zero), and hexadecimal constants by
5851 a leading @samp{0x} or @samp{0X}. Constants may also end with a letter
5852 @samp{l}, specifying that the constant should be treated as a
5856 Floating point constants are a sequence of digits, followed by a decimal
5857 point, followed by a sequence of digits, and optionally followed by an
5858 exponent. An exponent is of the form:
5859 @samp{@w{e@r{[[}+@r{]|}-@r{]}@var{nnn}}}, where @var{nnn} is another
5860 sequence of digits. The @samp{+} is optional for positive exponents.
5863 Enumerated constants consist of enumerated identifiers, or their
5864 integral equivalents.
5867 Character constants are a single character surrounded by single quotes
5868 (@code{'}), or a number---the ordinal value of the corresponding character
5869 (usually its @sc{ASCII} value). Within quotes, the single character may
5870 be represented by a letter or by @dfn{escape sequences}, which are of
5871 the form @samp{\@var{nnn}}, where @var{nnn} is the octal representation
5872 of the character's ordinal value; or of the form @samp{\@var{x}}, where
5873 @samp{@var{x}} is a predefined special character---for example,
5874 @samp{\n} for newline.
5877 String constants are a sequence of character constants surrounded
5878 by double quotes (@code{"}).
5881 Pointer constants are an integral value. You can also write pointers
5882 to constants using the C operator @samp{&}.
5885 Array constants are comma-separated lists surrounded by braces @samp{@{}
5886 and @samp{@}}; for example, @samp{@{1,2,3@}} is a three-element array of
5887 integers, @samp{@{@{1,2@}, @{3,4@}, @{5,6@}@}} is a three-by-two array,
5888 and @samp{@{&"hi", &"there", &"fred"@}} is a three-element array of pointers.
5892 * C plus plus expressions::
5899 @node C plus plus expressions
5900 @subsubsection C++ expressions
5902 @cindex expressions in C++
5903 @value{GDBN} expression handling can interpret most C++ expressions.
5905 @cindex C++ support, not in @sc{coff}
5906 @cindex @sc{coff} versus C++
5907 @cindex C++ and object formats
5908 @cindex object formats and C++
5909 @cindex a.out and C++
5910 @cindex @sc{ecoff} and C++
5911 @cindex @sc{xcoff} and C++
5912 @cindex @sc{elf}/stabs and C++
5913 @cindex @sc{elf}/@sc{dwarf} and C++
5914 @c FIXME!! GDB may eventually be able to debug C++ using DWARF; check
5915 @c periodically whether this has happened...
5917 @emph{Warning:} @value{GDBN} can only debug C++ code if you use the
5918 proper compiler. Typically, C++ debugging depends on the use of
5919 additional debugging information in the symbol table, and thus requires
5920 special support. In particular, if your compiler generates a.out, MIPS
5921 @sc{ecoff}, RS/6000 @sc{xcoff}, or @sc{elf} with stabs extensions to the
5922 symbol table, these facilities are all available. (With @sc{gnu} CC,
5923 you can use the @samp{-gstabs} option to request stabs debugging
5924 extensions explicitly.) Where the object code format is standard
5925 @sc{coff} or @sc{dwarf} in @sc{elf}, on the other hand, most of the C++
5926 support in @value{GDBN} does @emph{not} work.
5931 @cindex member functions
5933 Member function calls are allowed; you can use expressions like
5936 count = aml->GetOriginal(x, y)
5940 @cindex namespace in C++
5942 While a member function is active (in the selected stack frame), your
5943 expressions have the same namespace available as the member function;
5944 that is, @value{GDBN} allows implicit references to the class instance
5945 pointer @code{this} following the same rules as C++.
5947 @cindex call overloaded functions
5948 @cindex overloaded functions
5949 @cindex type conversions in C++
5951 You can call overloaded functions; @value{GDBN} resolves the function
5952 call to the right definition, with some restrictions. GDB does not
5953 perform overload resolution involving user-defined type conversions,
5954 calls to constructors, or instantiations of templates that do not exist
5955 in the program. It also cannot handle ellipsis argument lists or
5958 It does perform integral conversions and promotions, floating-point
5959 promotions, arithmetic conversions, pointer conversions, conversions of
5960 class objects to base classes, and standard conversions such as those of
5961 functions or arrays to pointers; it requires an exact match on the
5962 number of function arguments.
5964 Overload resolution is always performed, unless you have specified
5965 @code{set overload-resolution off}. @xref{Debugging C plus plus,
5966 ,@value{GDBN} features for C++}.
5968 You must specify@code{set overload-resolution off} in order to use an
5969 explicit function signature to call an overloaded function, as in
5971 p 'foo(char,int)'('x', 13)
5973 The @value{GDBN} command-completion facility can simplify this;
5974 @pxref{Completion, ,Command completion}.
5976 @cindex reference declarations
5978 @value{GDBN} understands variables declared as C++ references; you can use
5979 them in expressions just as you do in C++ source---they are automatically
5982 In the parameter list shown when @value{GDBN} displays a frame, the values of
5983 reference variables are not displayed (unlike other variables); this
5984 avoids clutter, since references are often used for large structures.
5985 The @emph{address} of a reference variable is always shown, unless
5986 you have specified @samp{set print address off}.
5989 @value{GDBN} supports the C++ name resolution operator @code{::}---your
5990 expressions can use it just as expressions in your program do. Since
5991 one scope may be defined in another, you can use @code{::} repeatedly if
5992 necessary, for example in an expression like
5993 @samp{@var{scope1}::@var{scope2}::@var{name}}. @value{GDBN} also allows
5994 resolving name scope by reference to source files, in both C and C++
5995 debugging (@pxref{Variables, ,Program variables}).
5998 In addition, when used with HP's C++ compiler, @value{GDBN} supports
5999 calling virtual functions correctly, printing out virtual bases of
6000 objects, calling functions in a base subobject, casting objects, and
6001 invoking user-defined operators.
6004 @subsubsection C and C++ defaults
6006 @cindex C and C++ defaults
6008 If you allow @value{GDBN} to set type and range checking automatically, they
6009 both default to @code{off} whenever the working language changes to
6010 C or C++. This happens regardless of whether you or @value{GDBN}
6011 selects the working language.
6013 If you allow @value{GDBN} to set the language automatically, it
6014 recognizes source files whose names end with @file{.c}, @file{.C}, or
6015 @file{.cc}, etc, and when @value{GDBN} enters code compiled from one of
6016 these files, it sets the working language to C or C++.
6017 @xref{Automatically, ,Having @value{GDBN} infer the source language},
6018 for further details.
6020 @c Type checking is (a) primarily motivated by Modula-2, and (b)
6021 @c unimplemented. If (b) changes, it might make sense to let this node
6022 @c appear even if Mod-2 does not, but meanwhile ignore it. roland 16jul93.
6025 @subsubsection C and C++ type and range checks
6027 @cindex C and C++ checks
6029 By default, when @value{GDBN} parses C or C++ expressions, type checking
6030 is not used. However, if you turn type checking on, @value{GDBN}
6031 considers two variables type equivalent if:
6035 The two variables are structured and have the same structure, union, or
6039 The two variables have the same type name, or types that have been
6040 declared equivalent through @code{typedef}.
6043 @c leaving this out because neither J Gilmore nor R Pesch understand it.
6046 The two @code{struct}, @code{union}, or @code{enum} variables are
6047 declared in the same declaration. (Note: this may not be true for all C
6052 Range checking, if turned on, is done on mathematical operations. Array
6053 indices are not checked, since they are often used to index a pointer
6054 that is not itself an array.
6057 @subsubsection @value{GDBN} and C
6059 The @code{set print union} and @code{show print union} commands apply to
6060 the @code{union} type. When set to @samp{on}, any @code{union} that is
6061 inside a @code{struct} or @code{class} is also printed. Otherwise, it
6062 appears as @samp{@{...@}}.
6064 The @code{@@} operator aids in the debugging of dynamic arrays, formed
6065 with pointers and a memory allocation function. @xref{Expressions,
6069 * Debugging C plus plus::
6072 @node Debugging C plus plus
6073 @subsubsection @value{GDBN} features for C++
6075 @cindex commands for C++
6077 Some @value{GDBN} commands are particularly useful with C++, and some are
6078 designed specifically for use with C++. Here is a summary:
6081 @cindex break in overloaded functions
6082 @item @r{breakpoint menus}
6083 When you want a breakpoint in a function whose name is overloaded,
6084 @value{GDBN} breakpoint menus help you specify which function definition
6085 you want. @xref{Breakpoint Menus,,Breakpoint menus}.
6087 @cindex overloading in C++
6088 @item rbreak @var{regex}
6089 Setting breakpoints using regular expressions is helpful for setting
6090 breakpoints on overloaded functions that are not members of any special
6092 @xref{Set Breaks, ,Setting breakpoints}.
6094 @cindex C++ exception handling
6097 Debug C++ exception handling using these commands. @xref{Set
6098 Catchpoints, , Setting catchpoints}.
6101 @item ptype @var{typename}
6102 Print inheritance relationships as well as other information for type
6104 @xref{Symbols, ,Examining the Symbol Table}.
6106 @cindex C++ symbol display
6107 @item set print demangle
6108 @itemx show print demangle
6109 @itemx set print asm-demangle
6110 @itemx show print asm-demangle
6111 Control whether C++ symbols display in their source form, both when
6112 displaying code as C++ source and when displaying disassemblies.
6113 @xref{Print Settings, ,Print settings}.
6115 @item set print object
6116 @itemx show print object
6117 Choose whether to print derived (actual) or declared types of objects.
6118 @xref{Print Settings, ,Print settings}.
6120 @item set print vtbl
6121 @itemx show print vtbl
6122 Control the format for printing virtual function tables.
6123 @xref{Print Settings, ,Print settings}.
6124 (The @code{vtbl} commands do not work on programs compiled with the HP
6125 ANSI C++ compiler (@code{aCC}).)
6127 @kindex set overload-resolution
6128 @cindex overloaded functions
6129 @item set overload-resolution on
6130 Enable overload resolution for C++ expression evaluation. The default
6131 is on. For overloaded functions, @value{GDBN} evaluates the arguments
6132 and searches for a function whose signature matches the argument types,
6133 using the standard C++ conversion rules (@pxref{C plus plus expressions, ,C++
6134 expressions} for details). If it cannot find a match, it emits a
6137 @item set overload-resolution off
6138 Disable overload resolution for C++ expression evaluation. For
6139 overloaded functions that are not class member functions, @value{GDBN}
6140 chooses the first function of the specified name that it finds in the
6141 symbol table, whether or not its arguments are of the correct type. For
6142 overloaded functions that are class member functions, @value{GDBN}
6143 searches for a function whose signature @emph{exactly} matches the
6146 @item @r{Overloaded symbol names}
6147 You can specify a particular definition of an overloaded symbol, using
6148 the same notation that is used to declare such symbols in C++: type
6149 @code{@var{symbol}(@var{types})} rather than just @var{symbol}. You can
6150 also use the @value{GDBN} command-line word completion facilities to list the
6151 available choices, or to finish the type list for you.
6152 @xref{Completion,, Command completion}, for details on how to do this.
6156 @subsection Modula-2
6160 The extensions made to @value{GDBN} to support Modula-2 only support
6161 output from the @sc{gnu} Modula-2 compiler (which is currently being
6162 developed). Other Modula-2 compilers are not currently supported, and
6163 attempting to debug executables produced by them is most likely
6164 to give an error as @value{GDBN} reads in the executable's symbol
6167 @cindex expressions in Modula-2
6169 * M2 Operators:: Built-in operators
6170 * Built-In Func/Proc:: Built-in functions and procedures
6171 * M2 Constants:: Modula-2 constants
6172 * M2 Defaults:: Default settings for Modula-2
6173 * Deviations:: Deviations from standard Modula-2
6174 * M2 Checks:: Modula-2 type and range checks
6175 * M2 Scope:: The scope operators @code{::} and @code{.}
6176 * GDB/M2:: @value{GDBN} and Modula-2
6180 @subsubsection Operators
6181 @cindex Modula-2 operators
6183 Operators must be defined on values of specific types. For instance,
6184 @code{+} is defined on numbers, but not on structures. Operators are
6185 often defined on groups of types. For the purposes of Modula-2, the
6186 following definitions hold:
6191 @emph{Integral types} consist of @code{INTEGER}, @code{CARDINAL}, and
6195 @emph{Character types} consist of @code{CHAR} and its subranges.
6198 @emph{Floating-point types} consist of @code{REAL}.
6201 @emph{Pointer types} consist of anything declared as @code{POINTER TO
6205 @emph{Scalar types} consist of all of the above.
6208 @emph{Set types} consist of @code{SET} and @code{BITSET} types.
6211 @emph{Boolean types} consist of @code{BOOLEAN}.
6215 The following operators are supported, and appear in order of
6216 increasing precedence:
6220 Function argument or array index separator.
6223 Assignment. The value of @var{var} @code{:=} @var{value} is
6227 Less than, greater than on integral, floating-point, or enumerated
6231 Less than, greater than, less than or equal to, greater than or equal to
6232 on integral, floating-point and enumerated types, or set inclusion on
6233 set types. Same precedence as @code{<}.
6235 @item =@r{, }<>@r{, }#
6236 Equality and two ways of expressing inequality, valid on scalar types.
6237 Same precedence as @code{<}. In @value{GDBN} scripts, only @code{<>} is
6238 available for inequality, since @code{#} conflicts with the script
6242 Set membership. Defined on set types and the types of their members.
6243 Same precedence as @code{<}.
6246 Boolean disjunction. Defined on boolean types.
6249 Boolean conjuction. Defined on boolean types.
6252 The @value{GDBN} ``artificial array'' operator (@pxref{Expressions, ,Expressions}).
6255 Addition and subtraction on integral and floating-point types, or union
6256 and difference on set types.
6259 Multiplication on integral and floating-point types, or set intersection
6263 Division on floating-point types, or symmetric set difference on set
6264 types. Same precedence as @code{*}.
6267 Integer division and remainder. Defined on integral types. Same
6268 precedence as @code{*}.
6271 Negative. Defined on @code{INTEGER} and @code{REAL} data.
6274 Pointer dereferencing. Defined on pointer types.
6277 Boolean negation. Defined on boolean types. Same precedence as
6281 @code{RECORD} field selector. Defined on @code{RECORD} data. Same
6282 precedence as @code{^}.
6285 Array indexing. Defined on @code{ARRAY} data. Same precedence as @code{^}.
6288 Procedure argument list. Defined on @code{PROCEDURE} objects. Same precedence
6292 @value{GDBN} and Modula-2 scope operators.
6296 @emph{Warning:} Sets and their operations are not yet supported, so @value{GDBN}
6297 treats the use of the operator @code{IN}, or the use of operators
6298 @code{+}, @code{-}, @code{*}, @code{/}, @code{=}, , @code{<>}, @code{#},
6299 @code{<=}, and @code{>=} on sets as an error.
6302 @cindex Modula-2 built-ins
6303 @node Built-In Func/Proc
6304 @subsubsection Built-in functions and procedures
6306 Modula-2 also makes available several built-in procedures and functions.
6307 In describing these, the following metavariables are used:
6312 represents an @code{ARRAY} variable.
6315 represents a @code{CHAR} constant or variable.
6318 represents a variable or constant of integral type.
6321 represents an identifier that belongs to a set. Generally used in the
6322 same function with the metavariable @var{s}. The type of @var{s} should
6323 be @code{SET OF @var{mtype}} (where @var{mtype} is the type of @var{m}).
6326 represents a variable or constant of integral or floating-point type.
6329 represents a variable or constant of floating-point type.
6335 represents a variable.
6338 represents a variable or constant of one of many types. See the
6339 explanation of the function for details.
6342 All Modula-2 built-in procedures also return a result, described below.
6346 Returns the absolute value of @var{n}.
6349 If @var{c} is a lower case letter, it returns its upper case
6350 equivalent, otherwise it returns its argument
6353 Returns the character whose ordinal value is @var{i}.
6356 Decrements the value in the variable @var{v}. Returns the new value.
6358 @item DEC(@var{v},@var{i})
6359 Decrements the value in the variable @var{v} by @var{i}. Returns the
6362 @item EXCL(@var{m},@var{s})
6363 Removes the element @var{m} from the set @var{s}. Returns the new
6366 @item FLOAT(@var{i})
6367 Returns the floating point equivalent of the integer @var{i}.
6370 Returns the index of the last member of @var{a}.
6373 Increments the value in the variable @var{v}. Returns the new value.
6375 @item INC(@var{v},@var{i})
6376 Increments the value in the variable @var{v} by @var{i}. Returns the
6379 @item INCL(@var{m},@var{s})
6380 Adds the element @var{m} to the set @var{s} if it is not already
6381 there. Returns the new set.
6384 Returns the maximum value of the type @var{t}.
6387 Returns the minimum value of the type @var{t}.
6390 Returns boolean TRUE if @var{i} is an odd number.
6393 Returns the ordinal value of its argument. For example, the ordinal
6394 value of a character is its ASCII value (on machines supporting the
6395 ASCII character set). @var{x} must be of an ordered type, which include
6396 integral, character and enumerated types.
6399 Returns the size of its argument. @var{x} can be a variable or a type.
6401 @item TRUNC(@var{r})
6402 Returns the integral part of @var{r}.
6404 @item VAL(@var{t},@var{i})
6405 Returns the member of the type @var{t} whose ordinal value is @var{i}.
6409 @emph{Warning:} Sets and their operations are not yet supported, so
6410 @value{GDBN} treats the use of procedures @code{INCL} and @code{EXCL} as
6414 @cindex Modula-2 constants
6416 @subsubsection Constants
6418 @value{GDBN} allows you to express the constants of Modula-2 in the following
6424 Integer constants are simply a sequence of digits. When used in an
6425 expression, a constant is interpreted to be type-compatible with the
6426 rest of the expression. Hexadecimal integers are specified by a
6427 trailing @samp{H}, and octal integers by a trailing @samp{B}.
6430 Floating point constants appear as a sequence of digits, followed by a
6431 decimal point and another sequence of digits. An optional exponent can
6432 then be specified, in the form @samp{E@r{[}+@r{|}-@r{]}@var{nnn}}, where
6433 @samp{@r{[}+@r{|}-@r{]}@var{nnn}} is the desired exponent. All of the
6434 digits of the floating point constant must be valid decimal (base 10)
6438 Character constants consist of a single character enclosed by a pair of
6439 like quotes, either single (@code{'}) or double (@code{"}). They may
6440 also be expressed by their ordinal value (their ASCII value, usually)
6441 followed by a @samp{C}.
6444 String constants consist of a sequence of characters enclosed by a
6445 pair of like quotes, either single (@code{'}) or double (@code{"}).
6446 Escape sequences in the style of C are also allowed. @xref{C
6447 Constants, ,C and C++ constants}, for a brief explanation of escape
6451 Enumerated constants consist of an enumerated identifier.
6454 Boolean constants consist of the identifiers @code{TRUE} and
6458 Pointer constants consist of integral values only.
6461 Set constants are not yet supported.
6465 @subsubsection Modula-2 defaults
6466 @cindex Modula-2 defaults
6468 If type and range checking are set automatically by @value{GDBN}, they
6469 both default to @code{on} whenever the working language changes to
6470 Modula-2. This happens regardless of whether you, or @value{GDBN},
6471 selected the working language.
6473 If you allow @value{GDBN} to set the language automatically, then entering
6474 code compiled from a file whose name ends with @file{.mod} sets the
6475 working language to Modula-2. @xref{Automatically, ,Having @value{GDBN} set
6476 the language automatically}, for further details.
6479 @subsubsection Deviations from standard Modula-2
6480 @cindex Modula-2, deviations from
6482 A few changes have been made to make Modula-2 programs easier to debug.
6483 This is done primarily via loosening its type strictness:
6487 Unlike in standard Modula-2, pointer constants can be formed by
6488 integers. This allows you to modify pointer variables during
6489 debugging. (In standard Modula-2, the actual address contained in a
6490 pointer variable is hidden from you; it can only be modified
6491 through direct assignment to another pointer variable or expression that
6492 returned a pointer.)
6495 C escape sequences can be used in strings and characters to represent
6496 non-printable characters. @value{GDBN} prints out strings with these
6497 escape sequences embedded. Single non-printable characters are
6498 printed using the @samp{CHR(@var{nnn})} format.
6501 The assignment operator (@code{:=}) returns the value of its right-hand
6505 All built-in procedures both modify @emph{and} return their argument.
6509 @subsubsection Modula-2 type and range checks
6510 @cindex Modula-2 checks
6513 @emph{Warning:} in this release, @value{GDBN} does not yet perform type or
6516 @c FIXME remove warning when type/range checks added
6518 @value{GDBN} considers two Modula-2 variables type equivalent if:
6522 They are of types that have been declared equivalent via a @code{TYPE
6523 @var{t1} = @var{t2}} statement
6526 They have been declared on the same line. (Note: This is true of the
6527 @sc{gnu} Modula-2 compiler, but it may not be true of other compilers.)
6530 As long as type checking is enabled, any attempt to combine variables
6531 whose types are not equivalent is an error.
6533 Range checking is done on all mathematical operations, assignment, array
6534 index bounds, and all built-in functions and procedures.
6537 @subsubsection The scope operators @code{::} and @code{.}
6540 @cindex colon, doubled as scope operator
6543 @c Info cannot handle :: but TeX can.
6549 There are a few subtle differences between the Modula-2 scope operator
6550 (@code{.}) and the @value{GDBN} scope operator (@code{::}). The two have
6555 @var{module} . @var{id}
6556 @var{scope} :: @var{id}
6560 where @var{scope} is the name of a module or a procedure,
6561 @var{module} the name of a module, and @var{id} is any declared
6562 identifier within your program, except another module.
6564 Using the @code{::} operator makes @value{GDBN} search the scope
6565 specified by @var{scope} for the identifier @var{id}. If it is not
6566 found in the specified scope, then @value{GDBN} searches all scopes
6567 enclosing the one specified by @var{scope}.
6569 Using the @code{.} operator makes @value{GDBN} search the current scope for
6570 the identifier specified by @var{id} that was imported from the
6571 definition module specified by @var{module}. With this operator, it is
6572 an error if the identifier @var{id} was not imported from definition
6573 module @var{module}, or if @var{id} is not an identifier in
6577 @subsubsection @value{GDBN} and Modula-2
6579 Some @value{GDBN} commands have little use when debugging Modula-2 programs.
6580 Five subcommands of @code{set print} and @code{show print} apply
6581 specifically to C and C++: @samp{vtbl}, @samp{demangle},
6582 @samp{asm-demangle}, @samp{object}, and @samp{union}. The first four
6583 apply to C++, and the last to the C @code{union} type, which has no direct
6584 analogue in Modula-2.
6586 The @code{@@} operator (@pxref{Expressions, ,Expressions}), while available
6587 while using any language, is not useful with Modula-2. Its
6588 intent is to aid the debugging of @dfn{dynamic arrays}, which cannot be
6589 created in Modula-2 as they can in C or C++. However, because an
6590 address can be specified by an integral constant, the construct
6591 @samp{@{@var{type}@}@var{adrexp}} is still useful. (@pxref{Expressions, ,Expressions})
6593 @cindex @code{#} in Modula-2
6594 In @value{GDBN} scripts, the Modula-2 inequality operator @code{#} is
6595 interpreted as the beginning of a comment. Use @code{<>} instead.
6600 The extensions made to @value{GDBN} to support Chill only support output
6601 from the GNU Chill compiler. Other Chill compilers are not currently
6602 supported, and attempting to debug executables produced by them is most
6603 likely to give an error as @value{GDBN} reads in the executable's symbol
6606 This section covers the following Chill related topics and the features
6607 of @value{GDBN} which support these topics.
6610 * How modes are displayed:: How modes are displayed
6611 * Locations:: Locations and their accesses
6612 * Values and their Operations:: Values and their Operations
6613 * Chill type and range checks::
6617 @node How modes are displayed
6618 @subsubsection How modes are displayed
6620 The Chill Datatype- (Mode) support of @value{GDBN} is directly related
6621 with the functionality of the GNU Chill compiler, and therefore deviates
6622 slightly from the standard specification of the Chill language. The
6625 @item @r{@emph{Discrete modes:}}
6628 @emph{Integer Modes} which are predefined by @code{BYTE, UBYTE, INT,
6631 @emph{Boolean Mode} which is predefined by @code{BOOL},
6633 @emph{Character Mode} which is predefined by @code{CHAR},
6635 @emph{Set Mode} which is displayed by the keyword @code{SET}.
6637 (@value{GDBP}) ptype x
6638 type = SET (karli = 10, susi = 20, fritzi = 100)
6640 If the type is an unnumbered set the set element values are omitted.
6642 @emph{Range Mode} which is displayed by @code{type = <basemode>
6643 (<lower bound> : <upper bound>)}, where @code{<lower bound>, <upper
6644 bound>} can be of any discrete literal expression (e.g. set element
6648 @item @r{@emph{Powerset Mode:}}
6649 A Powerset Mode is displayed by the keyword @code{POWERSET} followed by
6650 the member mode of the powerset. The member mode can be any discrete mode.
6652 (@value{GDBP}) ptype x
6653 type = POWERSET SET (egon, hugo, otto)
6656 @item @r{@emph{Reference Modes:}}
6659 @emph{Bound Reference Mode} which is diplayed by the keyword @code{REF}
6660 followed by the mode name to which the reference is bound.
6662 @emph{Free Reference Mode} which is displayed by the keyword @code{PTR}.
6665 @item @r{@emph{Procedure mode}}
6666 The procedure mode is displayed by @code{type = PROC(<parameter list>)
6667 <return mode> EXCEPTIONS (<exception list>)}. The @code{<parameter
6668 list>} is a list of the parameter modes. @code{<return mode>} indicates
6669 the mode of the result of the procedure if any. The exceptionlist lists
6670 all possible exceptions which can be raised by the procedure.
6673 @item @r{@emph{Instance mode}}
6674 The instance mode is represented by a structure, which has a static
6675 type, and is therefore not really of interest.
6678 @item @r{@emph{Synchronization Modes:}}
6681 @emph{Event Mode} which is displayed by @code{EVENT (<event length>)},
6682 where @code{(<event length>)} is optional.
6684 @emph{Buffer Mode} which is displayed by @code{BUFFER (<buffer length>)
6685 <buffer element mode>}, where @code{(<buffer length>)} is optional.
6688 @item @r{@emph{Timing Modes:}}
6691 @emph{Duration Mode} which is predefined by @code{DURATION}
6693 @emph{Absolute Time Mode} which is predefined by @code{TIME}
6696 @item @r{@emph{Real Modes:}}
6697 Real Modes are predefined with @code{REAL} and @code{LONG_REAL}.
6699 @item @r{@emph{String Modes:}}
6702 @emph{Character String Mode} which is displayed by @code{CHARS(<string
6703 length>)}, followed by the keyword @code{VARYING} if the String Mode is
6706 @emph{Bit String Mode} which is displayed by @code{BOOLS(<string
6710 @item @r{@emph{Array Mode:}}
6711 The Array Mode is displayed by the keyword @code{ARRAY(<range>)}
6712 followed by the element mode (which may in turn be an array mode).
6714 (@value{GDBP}) ptype x
6717 SET (karli = 10, susi = 20, fritzi = 100)
6720 @item @r{@emph{Structure Mode}}
6721 The Structure mode is displayed by the keyword @code{STRUCT(<field
6722 list>)}. The @code{<field list>} consists of names and modes of fields
6723 of the structure. Variant structures have the keyword @code{CASE <field>
6724 OF <variant fields> ESAC} in their field list. Since the current version
6725 of the GNU Chill compiler doesn't implement tag processing (no runtime
6726 checks of variant fields, and therefore no debugging info), the output
6727 always displays all variant fields.
6729 (@value{GDBP}) ptype str
6744 @subsubsection Locations and their accesses
6746 A location in Chill is an object which can contain values.
6748 A value of a location is generally accessed by the (declared) name of
6749 the location. The output conforms to the specification of values in
6750 Chill programs. How values are specified
6751 is the topic of the next section.
6753 The pseudo-location @code{RESULT} (or @code{result}) can be used to
6754 display or change the result of a currently-active procedure:
6758 - does the same as the Chill action @code{RESULT EXPR} (which
6759 is not available in gdb).
6761 Values of reference mode locations are printed by @code{PTR(<hex
6762 value>)} in case of a free reference mode, and by @code{(REF <reference
6763 mode>) (<hex-value>)} in case of a bound reference. @code{<hex value>}
6764 represents the address where the reference points to. To access the
6765 value of the location referenced by the pointer, use the dereference
6766 operator `@code{->}'.
6768 Values of procedure mode locations are displayed by @code{@{ PROC
6769 (<argument modes> ) <return mode> @} <address> <name of procedure
6770 location>}. @code{<argument modes>} is a list of modes according to the
6771 parameter specification of the procedure and @code{<address>} shows the
6772 address of the entry point.
6775 Locations of instance modes are displayed just like a structure with two
6776 fields specifying the @emph{process type} and the @emph{copy number} of
6777 the investigated instance location@footnote{This comes from the current
6778 implementation of instances. They are implemented as a structure (no
6779 na). The output should be something like @code{[<name of the process>;
6780 <instance number>]}.}. The field names are @code{__proc_type} and
6783 Locations of synchronization modes are displayed like a structure with
6784 the field name @code{__event_data} in case of a event mode location, and
6785 like a structure with the field @code{__buffer_data} in case of a buffer
6786 mode location (refer to previous paragraph).
6788 Structure Mode locations are printed by @code{[.<field name>: <value>,
6789 ...]}. The @code{<field name>} corresponds to the structure mode
6790 definition and the layout of @code{<value>} varies depending of the mode
6791 of the field. If the investigated structure mode location is of variant
6792 structure mode the variant parts of the structure are enclosed in curled
6793 braces (`@code{@{@}}'). Fields enclosed by `@code{@{,@}}' are residing
6794 on the same memory location and represent the current values of the
6795 memory location in their specific modes. Since no tag processing is done
6796 all variants are displayed. A variant field is printed by
6797 @code{(<variant name>) = .<field name>: <value>}. (who implements the
6800 (@value{GDBP}) print str1 $4 = [.as: 0, .bs: karli, .<TAG>: { (karli) =
6801 [.cs: []], (susi) = [.ds: susi]}]
6805 Substructures of string mode-, array mode- or structure mode-values
6806 (e.g. array slices, fields of structure locations) are accessed using
6807 certain operations which are descibed in the next chapter.
6809 A location value may be interpreted as having a different mode using the
6810 location conversion. This mode conversion is written as @code{<mode
6811 name>(<location>)}. The user has to consider that the sizes of the modes
6812 have to be equal otherwise an error message occurs. Further no range
6813 checking of the location against the destination mode is performed and
6814 therefore the result can be quite confusing.
6816 (@value{GDBP}) print int (s(3 up 4)) XXX TO be filled in !! XXX
6819 @node Values and their Operations
6820 @subsubsection Values and their Operations
6822 Values are used to alter locations, to investigate complex structures in
6823 more detail or to filter relevant information out of a large amount of
6824 data. There are several (mode dependent) operations defined which enable
6825 such investigations. These operations are not only applicable to
6826 constant values but also to locations, which can become quite useful
6827 when debugging complex structures. During parsing the command line
6828 (e.g. evaluating an expression) @value{GDBN} treats location names as
6829 the values behind these locations.
6831 This subchapters describes how values have to be specified and which
6832 operations are legal to be used with such values.
6835 @item Literal Values
6836 Literal values are specified in the same manner as in GNU Chill programs.
6837 For detailed specification refer to the GNU Chill implementation Manual
6843 @emph{Integer Literals} are specified in the same manner as in Chill
6844 programs (refer z200/88 chpt 5.2.4.2)
6846 @emph{Boolean Literals} are defined by @code{TRUE} and @code{FALSE}.
6848 @emph{Character Literals} are defined by @code{'<character>'}. (e.g.
6851 @emph{Set Literals} are defined by a name which was specified in a set
6852 mode. The value delivered by a Set Literal is the set value. This is
6853 comparable to an enumaration in C/C++ language.
6855 @emph{Emptiness Literal} is predefined by @code{NULL}. The value of the
6856 emptiness literal delivers either the empty reference value, the empty
6857 procedure value or the empty instance value.
6860 @emph{Character String Literals} are defined by a sequence of characters
6861 enclosed in single- or double quotes. If a single- or double quote has
6862 to be part of the string literal it has to be stuffed (specified twice).
6864 @emph{Bitstring Literals} are specified in the same manner as in Chill
6865 programs (refer z200/88 chpt 5.2.4.8).
6867 @emph{Floating point literals} are specified in the same manner as in
6868 (gnu-)Chill programs (refer GNU Chill implementation Manual chapter 1.5).
6873 A tuple is specified by @code{<mode name>[<tuple>]}, where @code{<mode
6874 name>} can be omitted if the mode of the tuple is unambigous. This
6875 unambiguity is derived from the context of a evaluated expression.
6876 @code{<tuple>} can be one of the following:
6878 @item @emph{Powerset Tuple}
6879 @item @emph{Array Tuple}
6880 @item @emph{Structure Tuple}
6881 Powerset tuples, array tuples and structure tuples are specified in the
6882 same manner as in Chill programs refer z200/88 chpt 5.2.5.
6885 @item String Element Value
6886 A string element value is specified by @code{<string value>(<index>)},
6887 where @code{<index>} is a integer expression. It delivers a character
6888 value which is equivalent to the character indexed by @code{<index>} in
6891 @item String Slice Value
6892 A string slice value is specified by @code{<string value>(<slice
6893 spec>)}, where @code{<slice spec>} can be either a range of integer
6894 expressions or specified by @code{<start expr> up <size>}.
6895 @code{<size>} denotes the number of elements which the slice contains.
6896 The delivered value is a string value, which is part of the specified
6899 @item Array Element Values
6900 An array element value is specified by @code{<array value>(<expr>)} and
6901 delivers a array element value of the mode of the specified array.
6903 @item Array Slice Values
6904 An array slice is specified by @code{<array value>(<slice spec>)}, where
6905 @code{<slice spec>} can be either a range specified by expressions or by
6906 @code{<start expr> up <size>}. @code{<size>} denotes the number of
6907 arrayelements the slice contains. The delivered value is an array value
6908 which is part of the specified array.
6910 @item Structure Field Values
6911 A structure field value is derived by @code{<structure value>.<field
6912 name>}, where @code{<field name>} indcates the name of a field specified
6913 in the mode definition of the structure. The mode of the delivered value
6914 corresponds to this mode definition in the structure definition.
6916 @item Procedure Call Value
6917 The procedure call value is derived from the return value of the
6918 procedure@footnote{If a procedure call is used for instance in an
6919 expression, then this procedure is called with all its side
6920 effects. This can lead to confusing results if used carelessly.}.
6922 Values of duration mode locations are represented by ULONG literals.
6924 Values of time mode locations are represented by TIME(<secs>:<nsecs>).
6927 This is not implemented yet:
6928 @item Built-in Value
6930 The following built in functions are provided:
6941 @item @code{UPPER()}
6942 @item @code{LOWER()}
6943 @item @code{LENGTH()}
6947 @item @code{ARCSIN()}
6948 @item @code{ARCCOS()}
6949 @item @code{ARCTAN()}
6956 For a detailed description refer to the GNU Chill implementation manual
6960 @item Zero-adic Operator Value
6961 The zero-adic operator value is derived from the instance value for the
6962 current active process.
6964 @item Expression Values
6965 The value delivered by an expression is the result of the evaluation of
6966 the specified expression. If there are error conditions (mode
6967 incompatibility, etc.) the evaluation of expressions is aborted with a
6968 corresponding error message. Expressions may be paranthesised which
6969 causes the evaluation of this expression before any other expression
6970 which uses the result of the paranthesised expression. The following
6971 operators are supported by @value{GDBN}:
6973 @item @code{OR, ORIF, XOR}
6974 @item @code{AND, ANDIF}
6976 Logical operators defined over operands of boolean mode.
6978 Equality and inequality operators defined over all modes.
6981 Relational operators defined over predefined modes.
6983 @item @code{*, /, MOD, REM}
6984 Arithmetic operators defined over predefined modes.
6986 Change sign operator.
6988 String concatenation operator.
6990 String repetition operator.
6992 Referenced location operator which can be used either to take the
6993 address of a location (@code{->loc}), or to dereference a reference
6994 location (@code{loc->}).
6995 @item @code{OR, XOR}
6998 Powerset and bitstring operators.
7001 Powerset inclusion operators.
7003 Membership operator.
7007 @node Chill type and range checks
7008 @subsubsection Chill type and range checks
7010 @value{GDBN} considers two Chill variables mode equivalent if the sizes
7011 of the two modes are equal. This rule applies recursively to more
7012 complex datatypes which means that complex modes are treated
7013 eqivalent if all element modes (which also can be complex modes like
7014 structures, arrays, etc.) have the same size.
7016 Range checking is done on all mathematical operations, assignment, array
7017 index bounds and all built in procedures.
7019 Strong type checks are forced using the @value{GDBN} command @code{set
7020 check strong}. This enforces strong type and range checks on all
7021 operations where Chill constructs are used (expressions, built in
7022 functions, etc.) in respect to the semantics as defined in the z.200
7023 language specification.
7026 All checks can be disabled by the @value{GDBN} command @code{set check
7030 @c Deviations from the Chill Standard Z200/88
7031 see last paragraph ?
7034 @node Chill defaults
7035 @subsubsection Chill defaults
7037 If type and range checking are set automatically by @value{GDBN}, they
7038 both default to @code{on} whenever the working language changes to
7039 Chill. This happens regardless of whether you, or @value{GDBN},
7040 selected the working language.
7042 If you allow @value{GDBN} to set the language automatically, then entering
7043 code compiled from a file whose name ends with @file{.ch} sets the
7044 working language to Chill. @xref{Automatically, ,Having @value{GDBN} set
7045 the language automatically}, for further details.
7048 @chapter Examining the Symbol Table
7050 The commands described in this section allow you to inquire about the
7051 symbols (names of variables, functions and types) defined in your
7052 program. This information is inherent in the text of your program and
7053 does not change as your program executes. @value{GDBN} finds it in your
7054 program's symbol table, in the file indicated when you started @value{GDBN}
7055 (@pxref{File Options, ,Choosing files}), or by one of the
7056 file-management commands (@pxref{Files, ,Commands to specify files}).
7058 @cindex symbol names
7059 @cindex names of symbols
7060 @cindex quoting names
7061 Occasionally, you may need to refer to symbols that contain unusual
7062 characters, which @value{GDBN} ordinarily treats as word delimiters. The
7063 most frequent case is in referring to static variables in other
7064 source files (@pxref{Variables,,Program variables}). File names
7065 are recorded in object files as debugging symbols, but @value{GDBN} would
7066 ordinarily parse a typical file name, like @file{foo.c}, as the three words
7067 @samp{foo} @samp{.} @samp{c}. To allow @value{GDBN} to recognize
7068 @samp{foo.c} as a single symbol, enclose it in single quotes; for example,
7075 looks up the value of @code{x} in the scope of the file @file{foo.c}.
7078 @kindex info address
7079 @item info address @var{symbol}
7080 Describe where the data for @var{symbol} is stored. For a register
7081 variable, this says which register it is kept in. For a non-register
7082 local variable, this prints the stack-frame offset at which the variable
7085 Note the contrast with @samp{print &@var{symbol}}, which does not work
7086 at all for a register variable, and for a stack local variable prints
7087 the exact address of the current instantiation of the variable.
7090 @item whatis @var{exp}
7091 Print the data type of expression @var{exp}. @var{exp} is not
7092 actually evaluated, and any side-effecting operations (such as
7093 assignments or function calls) inside it do not take place.
7094 @xref{Expressions, ,Expressions}.
7097 Print the data type of @code{$}, the last value in the value history.
7100 @item ptype @var{typename}
7101 Print a description of data type @var{typename}. @var{typename} may be
7102 the name of a type, or for C code it may have the form @samp{class
7103 @var{class-name}}, @samp{struct @var{struct-tag}}, @samp{union
7104 @var{union-tag}} or @samp{enum @var{enum-tag}}.
7106 @item ptype @var{exp}
7108 Print a description of the type of expression @var{exp}. @code{ptype}
7109 differs from @code{whatis} by printing a detailed description, instead
7110 of just the name of the type.
7112 For example, for this variable declaration:
7115 struct complex @{double real; double imag;@} v;
7119 the two commands give this output:
7123 (@value{GDBP}) whatis v
7124 type = struct complex
7125 (@value{GDBP}) ptype v
7126 type = struct complex @{
7134 As with @code{whatis}, using @code{ptype} without an argument refers to
7135 the type of @code{$}, the last value in the value history.
7138 @item info types @var{regexp}
7140 Print a brief description of all types whose name matches @var{regexp}
7141 (or all types in your program, if you supply no argument). Each
7142 complete typename is matched as though it were a complete line; thus,
7143 @samp{i type value} gives information on all types in your program whose
7144 name includes the string @code{value}, but @samp{i type ^value$} gives
7145 information only on types whose complete name is @code{value}.
7147 This command differs from @code{ptype} in two ways: first, like
7148 @code{whatis}, it does not print a detailed description; second, it
7149 lists all source files where a type is defined.
7153 Show the name of the current source file---that is, the source file for
7154 the function containing the current point of execution---and the language
7157 @kindex info sources
7159 Print the names of all source files in your program for which there is
7160 debugging information, organized into two lists: files whose symbols
7161 have already been read, and files whose symbols will be read when needed.
7163 @kindex info functions
7164 @item info functions
7165 Print the names and data types of all defined functions.
7167 @item info functions @var{regexp}
7168 Print the names and data types of all defined functions
7169 whose names contain a match for regular expression @var{regexp}.
7170 Thus, @samp{info fun step} finds all functions whose names
7171 include @code{step}; @samp{info fun ^step} finds those whose names
7172 start with @code{step}.
7174 @kindex info variables
7175 @item info variables
7176 Print the names and data types of all variables that are declared
7177 outside of functions (i.e., excluding local variables).
7179 @item info variables @var{regexp}
7180 Print the names and data types of all variables (except for local
7181 variables) whose names contain a match for regular expression
7185 This was never implemented.
7186 @kindex info methods
7188 @itemx info methods @var{regexp}
7189 The @code{info methods} command permits the user to examine all defined
7190 methods within C++ program, or (with the @var{regexp} argument) a
7191 specific set of methods found in the various C++ classes. Many
7192 C++ classes provide a large number of methods. Thus, the output
7193 from the @code{ptype} command can be overwhelming and hard to use. The
7194 @code{info-methods} command filters the methods, printing only those
7195 which match the regular-expression @var{regexp}.
7198 @cindex reloading symbols
7199 Some systems allow individual object files that make up your program to
7200 be replaced without stopping and restarting your program. For example,
7201 in VxWorks you can simply recompile a defective object file and keep on
7202 running. If you are running on one of these systems, you can allow
7203 @value{GDBN} to reload the symbols for automatically relinked modules:
7206 @kindex set symbol-reloading
7207 @item set symbol-reloading on
7208 Replace symbol definitions for the corresponding source file when an
7209 object file with a particular name is seen again.
7211 @item set symbol-reloading off
7212 Do not replace symbol definitions when re-encountering object files of
7213 the same name. This is the default state; if you are not running on a
7214 system that permits automatically relinking modules, you should leave
7215 @code{symbol-reloading} off, since otherwise @value{GDBN} may discard symbols
7216 when linking large programs, that may contain several modules (from
7217 different directories or libraries) with the same name.
7219 @kindex show symbol-reloading
7220 @item show symbol-reloading
7221 Show the current @code{on} or @code{off} setting.
7224 @kindex set opaque-type-resolution
7225 @item set opaque-type-resolution on
7226 Tell @value{GDBN} to resolve opaque types. An opaque type is a type
7227 declared as a pointer to a @code{struct}, @code{class}, or
7228 @code{union}---for example, @code{struct MyType *}---that is used in one
7229 source file although the full declaration of @code{struct MyType} is in
7230 another source file. The default is on.
7232 A change in the setting of this subcommand will not take effect until
7233 the next time symbols for a file are loaded.
7235 @item set opaque-type-resolution off
7236 Tell @value{GDBN} not to resolve opaque types. In this case, the type
7237 is printed as follows:
7239 @{<no data fields>@}
7242 @kindex show opaque-type-resolution
7243 @item show opaque-type-resolution
7244 Show whether opaque types are resolved or not.
7246 @kindex maint print symbols
7248 @kindex maint print psymbols
7249 @cindex partial symbol dump
7250 @item maint print symbols @var{filename}
7251 @itemx maint print psymbols @var{filename}
7252 @itemx maint print msymbols @var{filename}
7253 Write a dump of debugging symbol data into the file @var{filename}.
7254 These commands are used to debug the @value{GDBN} symbol-reading code. Only
7255 symbols with debugging data are included. If you use @samp{maint print
7256 symbols}, @value{GDBN} includes all the symbols for which it has already
7257 collected full details: that is, @var{filename} reflects symbols for
7258 only those files whose symbols @value{GDBN} has read. You can use the
7259 command @code{info sources} to find out which files these are. If you
7260 use @samp{maint print psymbols} instead, the dump shows information about
7261 symbols that @value{GDBN} only knows partially---that is, symbols defined in
7262 files that @value{GDBN} has skimmed, but not yet read completely. Finally,
7263 @samp{maint print msymbols} dumps just the minimal symbol information
7264 required for each object file from which @value{GDBN} has read some symbols.
7265 @xref{Files, ,Commands to specify files}, for a discussion of how
7266 @value{GDBN} reads symbols (in the description of @code{symbol-file}).
7270 @chapter Altering Execution
7272 Once you think you have found an error in your program, you might want to
7273 find out for certain whether correcting the apparent error would lead to
7274 correct results in the rest of the run. You can find the answer by
7275 experiment, using the @value{GDBN} features for altering execution of the
7278 For example, you can store new values into variables or memory
7279 locations, give your program a signal, restart it at a different
7280 address, or even return prematurely from a function.
7283 * Assignment:: Assignment to variables
7284 * Jumping:: Continuing at a different address
7285 * Signaling:: Giving your program a signal
7286 * Returning:: Returning from a function
7287 * Calling:: Calling your program's functions
7288 * Patching:: Patching your program
7292 @section Assignment to variables
7295 @cindex setting variables
7296 To alter the value of a variable, evaluate an assignment expression.
7297 @xref{Expressions, ,Expressions}. For example,
7304 stores the value 4 into the variable @code{x}, and then prints the
7305 value of the assignment expression (which is 4).
7306 @xref{Languages, ,Using @value{GDBN} with Different Languages}, for more
7307 information on operators in supported languages.
7309 @kindex set variable
7310 @cindex variables, setting
7311 If you are not interested in seeing the value of the assignment, use the
7312 @code{set} command instead of the @code{print} command. @code{set} is
7313 really the same as @code{print} except that the expression's value is
7314 not printed and is not put in the value history (@pxref{Value History,
7315 ,Value history}). The expression is evaluated only for its effects.
7317 If the beginning of the argument string of the @code{set} command
7318 appears identical to a @code{set} subcommand, use the @code{set
7319 variable} command instead of just @code{set}. This command is identical
7320 to @code{set} except for its lack of subcommands. For example, if your
7321 program has a variable @code{width}, you get an error if you try to set
7322 a new value with just @samp{set width=13}, because @value{GDBN} has the
7323 command @code{set width}:
7326 (@value{GDBP}) whatis width
7328 (@value{GDBP}) p width
7330 (@value{GDBP}) set width=47
7331 Invalid syntax in expression.
7335 The invalid expression, of course, is @samp{=47}. In
7336 order to actually set the program's variable @code{width}, use
7339 (@value{GDBP}) set var width=47
7342 Because the @code{set} command has many subcommands that can conflict
7343 with the names of program variables, it is a good idea to use the
7344 @code{set variable} command instead of just @code{set}. For example, if
7345 your program has a variable @code{g}, you run into problems if you try
7346 to set a new value with just @samp{set g=4}, because @value{GDBN} has
7347 the command @code{set gnutarget}, abbreviated @code{set g}:
7351 (@value{GDBP}) whatis g
7355 (@value{GDBP}) set g=4
7359 The program being debugged has been started already.
7360 Start it from the beginning? (y or n) y
7361 Starting program: /home/smith/cc_progs/a.out
7362 "/home/smith/cc_progs/a.out": can't open to read symbols: Invalid bfd target.
7363 (@value{GDBP}) show g
7364 The current BFD target is "=4".
7369 The program variable @code{g} did not change, and you silently set the
7370 @code{gnutarget} to an invalid value. In order to set the variable
7374 (@value{GDBP}) set var g=4
7377 @value{GDBN} allows more implicit conversions in assignments than C; you can
7378 freely store an integer value into a pointer variable or vice versa,
7379 and you can convert any structure to any other structure that is the
7380 same length or shorter.
7381 @comment FIXME: how do structs align/pad in these conversions?
7382 @comment /doc@cygnus.com 18dec1990
7384 To store values into arbitrary places in memory, use the @samp{@{@dots{}@}}
7385 construct to generate a value of specified type at a specified address
7386 (@pxref{Expressions, ,Expressions}). For example, @code{@{int@}0x83040} refers
7387 to memory location @code{0x83040} as an integer (which implies a certain size
7388 and representation in memory), and
7391 set @{int@}0x83040 = 4
7395 stores the value 4 into that memory location.
7398 @section Continuing at a different address
7400 Ordinarily, when you continue your program, you do so at the place where
7401 it stopped, with the @code{continue} command. You can instead continue at
7402 an address of your own choosing, with the following commands:
7406 @item jump @var{linespec}
7407 Resume execution at line @var{linespec}. Execution stops again
7408 immediately if there is a breakpoint there. @xref{List, ,Printing
7409 source lines}, for a description of the different forms of
7410 @var{linespec}. It is common practice to use the @code{tbreak} command
7411 in conjunction with @code{jump}. @xref{Set Breaks, ,Setting
7414 The @code{jump} command does not change the current stack frame, or
7415 the stack pointer, or the contents of any memory location or any
7416 register other than the program counter. If line @var{linespec} is in
7417 a different function from the one currently executing, the results may
7418 be bizarre if the two functions expect different patterns of arguments or
7419 of local variables. For this reason, the @code{jump} command requests
7420 confirmation if the specified line is not in the function currently
7421 executing. However, even bizarre results are predictable if you are
7422 well acquainted with the machine-language code of your program.
7424 @item jump *@var{address}
7425 Resume execution at the instruction at address @var{address}.
7428 @c Doesn't work on HP-UX; have to set $pcoqh and $pcoqt.
7429 On many systems, you can get much the same effect as the @code{jump}
7430 command by storing a new value into the register @code{$pc}. The
7431 difference is that this does not start your program running; it only
7432 changes the address of where it @emph{will} run when you continue. For
7440 makes the next @code{continue} command or stepping command execute at
7441 address @code{0x485}, rather than at the address where your program stopped.
7442 @xref{Continuing and Stepping, ,Continuing and stepping}.
7444 The most common occasion to use the @code{jump} command is to back
7445 up---perhaps with more breakpoints set---over a portion of a program
7446 that has already executed, in order to examine its execution in more
7451 @section Giving your program a signal
7455 @item signal @var{signal}
7456 Resume execution where your program stopped, but immediately give it the
7457 signal @var{signal}. @var{signal} can be the name or the number of a
7458 signal. For example, on many systems @code{signal 2} and @code{signal
7459 SIGINT} are both ways of sending an interrupt signal.
7461 Alternatively, if @var{signal} is zero, continue execution without
7462 giving a signal. This is useful when your program stopped on account of
7463 a signal and would ordinary see the signal when resumed with the
7464 @code{continue} command; @samp{signal 0} causes it to resume without a
7467 @code{signal} does not repeat when you press @key{RET} a second time
7468 after executing the command.
7472 Invoking the @code{signal} command is not the same as invoking the
7473 @code{kill} utility from the shell. Sending a signal with @code{kill}
7474 causes @value{GDBN} to decide what to do with the signal depending on
7475 the signal handling tables (@pxref{Signals}). The @code{signal} command
7476 passes the signal directly to your program.
7480 @section Returning from a function
7483 @cindex returning from a function
7486 @itemx return @var{expression}
7487 You can cancel execution of a function call with the @code{return}
7488 command. If you give an
7489 @var{expression} argument, its value is used as the function's return
7493 When you use @code{return}, @value{GDBN} discards the selected stack frame
7494 (and all frames within it). You can think of this as making the
7495 discarded frame return prematurely. If you wish to specify a value to
7496 be returned, give that value as the argument to @code{return}.
7498 This pops the selected stack frame (@pxref{Selection, ,Selecting a
7499 frame}), and any other frames inside of it, leaving its caller as the
7500 innermost remaining frame. That frame becomes selected. The
7501 specified value is stored in the registers used for returning values
7504 The @code{return} command does not resume execution; it leaves the
7505 program stopped in the state that would exist if the function had just
7506 returned. In contrast, the @code{finish} command (@pxref{Continuing
7507 and Stepping, ,Continuing and stepping}) resumes execution until the
7508 selected stack frame returns naturally.
7511 @section Calling program functions
7513 @cindex calling functions
7516 @item call @var{expr}
7517 Evaluate the expression @var{expr} without displaying @code{void}
7521 You can use this variant of the @code{print} command if you want to
7522 execute a function from your program, but without cluttering the output
7523 with @code{void} returned values. If the result is not void, it
7524 is printed and saved in the value history.
7526 For the A29K, a user-controlled variable @code{call_scratch_address},
7527 specifies the location of a scratch area to be used when @value{GDBN}
7528 calls a function in the target. This is necessary because the usual
7529 method of putting the scratch area on the stack does not work in systems
7530 that have separate instruction and data spaces.
7533 @section Patching programs
7535 @cindex patching binaries
7536 @cindex writing into executables
7537 @cindex writing into corefiles
7539 By default, @value{GDBN} opens the file containing your program's
7540 executable code (or the corefile) read-only. This prevents accidental
7541 alterations to machine code; but it also prevents you from intentionally
7542 patching your program's binary.
7544 If you'd like to be able to patch the binary, you can specify that
7545 explicitly with the @code{set write} command. For example, you might
7546 want to turn on internal debugging flags, or even to make emergency
7552 @itemx set write off
7553 If you specify @samp{set write on}, @value{GDBN} opens executable and
7554 core files for both reading and writing; if you specify @samp{set write
7555 off} (the default), @value{GDBN} opens them read-only.
7557 If you have already loaded a file, you must load it again (using the
7558 @code{exec-file} or @code{core-file} command) after changing @code{set
7559 write}, for your new setting to take effect.
7563 Display whether executable files and core files are opened for writing
7568 @chapter @value{GDBN} Files
7570 @value{GDBN} needs to know the file name of the program to be debugged,
7571 both in order to read its symbol table and in order to start your
7572 program. To debug a core dump of a previous run, you must also tell
7573 @value{GDBN} the name of the core dump file.
7576 * Files:: Commands to specify files
7577 * Symbol Errors:: Errors reading symbol files
7581 @section Commands to specify files
7583 @cindex symbol table
7584 @cindex core dump file
7586 You may want to specify executable and core dump file names. The usual
7587 way to do this is at start-up time, using the arguments to
7588 @value{GDBN}'s start-up commands (@pxref{Invocation, , Getting In and
7589 Out of @value{GDBN}}).
7591 Occasionally it is necessary to change to a different file during a
7592 @value{GDBN} session. Or you may run @value{GDBN} and forget to specify
7593 a file you want to use. In these situations the @value{GDBN} commands
7594 to specify new files are useful.
7597 @cindex executable file
7599 @item file @var{filename}
7600 Use @var{filename} as the program to be debugged. It is read for its
7601 symbols and for the contents of pure memory. It is also the program
7602 executed when you use the @code{run} command. If you do not specify a
7603 directory and the file is not found in the @value{GDBN} working directory,
7604 @value{GDBN} uses the environment variable @code{PATH} as a list of
7605 directories to search, just as the shell does when looking for a program
7606 to run. You can change the value of this variable, for both @value{GDBN}
7607 and your program, using the @code{path} command.
7609 On systems with memory-mapped files, an auxiliary file
7610 @file{@var{filename}.syms} may hold symbol table information for
7611 @var{filename}. If so, @value{GDBN} maps in the symbol table from
7612 @file{@var{filename}.syms}, starting up more quickly. See the
7613 descriptions of the file options @samp{-mapped} and @samp{-readnow}
7614 (available on the command line, and with the commands @code{file},
7615 @code{symbol-file}, or @code{add-symbol-file}, described below),
7616 for more information.
7619 @code{file} with no argument makes @value{GDBN} discard any information it
7620 has on both executable file and the symbol table.
7623 @item exec-file @r{[} @var{filename} @r{]}
7624 Specify that the program to be run (but not the symbol table) is found
7625 in @var{filename}. @value{GDBN} searches the environment variable @code{PATH}
7626 if necessary to locate your program. Omitting @var{filename} means to
7627 discard information on the executable file.
7630 @item symbol-file @r{[} @var{filename} @r{]}
7631 Read symbol table information from file @var{filename}. @code{PATH} is
7632 searched when necessary. Use the @code{file} command to get both symbol
7633 table and program to run from the same file.
7635 @code{symbol-file} with no argument clears out @value{GDBN} information on your
7636 program's symbol table.
7638 The @code{symbol-file} command causes @value{GDBN} to forget the contents
7639 of its convenience variables, the value history, and all breakpoints and
7640 auto-display expressions. This is because they may contain pointers to
7641 the internal data recording symbols and data types, which are part of
7642 the old symbol table data being discarded inside @value{GDBN}.
7644 @code{symbol-file} does not repeat if you press @key{RET} again after
7647 When @value{GDBN} is configured for a particular environment, it
7648 understands debugging information in whatever format is the standard
7649 generated for that environment; you may use either a @sc{gnu} compiler, or
7650 other compilers that adhere to the local conventions.
7651 Best results are usually obtained from @sc{gnu} compilers; for example,
7652 using @code{@value{GCC}} you can generate debugging information for
7655 For most kinds of object files, with the exception of old SVR3 systems
7656 using COFF, the @code{symbol-file} command does not normally read the
7657 symbol table in full right away. Instead, it scans the symbol table
7658 quickly to find which source files and which symbols are present. The
7659 details are read later, one source file at a time, as they are needed.
7661 The purpose of this two-stage reading strategy is to make @value{GDBN}
7662 start up faster. For the most part, it is invisible except for
7663 occasional pauses while the symbol table details for a particular source
7664 file are being read. (The @code{set verbose} command can turn these
7665 pauses into messages if desired. @xref{Messages/Warnings, ,Optional
7666 warnings and messages}.)
7668 We have not implemented the two-stage strategy for COFF yet. When the
7669 symbol table is stored in COFF format, @code{symbol-file} reads the
7670 symbol table data in full right away. Note that ``stabs-in-COFF''
7671 still does the two-stage strategy, since the debug info is actually
7675 @cindex reading symbols immediately
7676 @cindex symbols, reading immediately
7678 @cindex memory-mapped symbol file
7679 @cindex saving symbol table
7680 @item symbol-file @var{filename} @r{[} -readnow @r{]} @r{[} -mapped @r{]}
7681 @itemx file @var{filename} @r{[} -readnow @r{]} @r{[} -mapped @r{]}
7682 You can override the @value{GDBN} two-stage strategy for reading symbol
7683 tables by using the @samp{-readnow} option with any of the commands that
7684 load symbol table information, if you want to be sure @value{GDBN} has the
7685 entire symbol table available.
7687 If memory-mapped files are available on your system through the
7688 @code{mmap} system call, you can use another option, @samp{-mapped}, to
7689 cause @value{GDBN} to write the symbols for your program into a reusable
7690 file. Future @value{GDBN} debugging sessions map in symbol information
7691 from this auxiliary symbol file (if the program has not changed), rather
7692 than spending time reading the symbol table from the executable
7693 program. Using the @samp{-mapped} option has the same effect as
7694 starting @value{GDBN} with the @samp{-mapped} command-line option.
7696 You can use both options together, to make sure the auxiliary symbol
7697 file has all the symbol information for your program.
7699 The auxiliary symbol file for a program called @var{myprog} is called
7700 @samp{@var{myprog}.syms}. Once this file exists (so long as it is newer
7701 than the corresponding executable), @value{GDBN} always attempts to use
7702 it when you debug @var{myprog}; no special options or commands are
7705 The @file{.syms} file is specific to the host machine where you run
7706 @value{GDBN}. It holds an exact image of the internal @value{GDBN}
7707 symbol table. It cannot be shared across multiple host platforms.
7709 @c FIXME: for now no mention of directories, since this seems to be in
7710 @c flux. 13mar1992 status is that in theory GDB would look either in
7711 @c current dir or in same dir as myprog; but issues like competing
7712 @c GDB's, or clutter in system dirs, mean that in practice right now
7713 @c only current dir is used. FFish says maybe a special GDB hierarchy
7714 @c (eg rooted in val of env var GDBSYMS) could exist for mappable symbol
7719 @item core-file @r{[} @var{filename} @r{]}
7720 Specify the whereabouts of a core dump file to be used as the ``contents
7721 of memory''. Traditionally, core files contain only some parts of the
7722 address space of the process that generated them; @value{GDBN} can access the
7723 executable file itself for other parts.
7725 @code{core-file} with no argument specifies that no core file is
7728 Note that the core file is ignored when your program is actually running
7729 under @value{GDBN}. So, if you have been running your program and you
7730 wish to debug a core file instead, you must kill the subprocess in which
7731 the program is running. To do this, use the @code{kill} command
7732 (@pxref{Kill Process, ,Killing the child process}).
7734 @kindex add-symbol-file
7735 @cindex dynamic linking
7736 @item add-symbol-file @var{filename} @var{address}
7737 @itemx add-symbol-file @var{filename} @var{address} @r{[} -readnow @r{]} @r{[} -mapped @r{]}
7738 The @code{add-symbol-file} command reads additional symbol table information
7739 from the file @var{filename}. You would use this command when @var{filename}
7740 has been dynamically loaded (by some other means) into the program that
7741 is running. @var{address} should be the memory address at which the
7742 file has been loaded; @value{GDBN} cannot figure this out for itself.
7743 You can specify @var{address} as an expression.
7745 The symbol table of the file @var{filename} is added to the symbol table
7746 originally read with the @code{symbol-file} command. You can use the
7747 @code{add-symbol-file} command any number of times; the new symbol data thus
7748 read keeps adding to the old. To discard all old symbol data instead,
7749 use the @code{symbol-file} command.
7751 @code{add-symbol-file} does not repeat if you press @key{RET} after using it.
7753 You can use the @samp{-mapped} and @samp{-readnow} options just as with
7754 the @code{symbol-file} command, to change how @value{GDBN} manages the symbol
7755 table information for @var{filename}.
7757 @kindex add-shared-symbol-file
7758 @item add-shared-symbol-file
7759 The @code{add-shared-symbol-file} command can be used only under Harris' CXUX
7760 operating system for the Motorola 88k. @value{GDBN} automatically looks for
7761 shared libraries, however if @value{GDBN} does not find yours, you can run
7762 @code{add-shared-symbol-file}. It takes no arguments.
7766 The @code{section} command changes the base address of section SECTION of
7767 the exec file to ADDR. This can be used if the exec file does not contain
7768 section addresses, (such as in the a.out format), or when the addresses
7769 specified in the file itself are wrong. Each section must be changed
7770 separately. The ``info files'' command lists all the sections and their
7777 @code{info files} and @code{info target} are synonymous; both print the
7778 current target (@pxref{Targets, ,Specifying a Debugging Target}),
7779 including the names of the executable and core dump files currently in
7780 use by @value{GDBN}, and the files from which symbols were loaded. The
7781 command @code{help target} lists all possible targets rather than
7786 All file-specifying commands allow both absolute and relative file names
7787 as arguments. @value{GDBN} always converts the file name to an absolute file
7788 name and remembers it that way.
7790 @cindex shared libraries
7791 @value{GDBN} supports HP-UX, SunOS, SVr4, Irix 5, and IBM RS/6000 shared
7794 @value{GDBN} automatically loads symbol definitions from shared libraries
7795 when you use the @code{run} command, or when you examine a core file.
7796 (Before you issue the @code{run} command, @value{GDBN} does not understand
7797 references to a function in a shared library, however---unless you are
7798 debugging a core file).
7800 On HP-UX, if the program loads a library explicitly, @value{GDBN}
7801 automatically loads the symbols at the time of the @code{shl_load} call.
7803 @c FIXME: some @value{GDBN} release may permit some refs to undef
7804 @c FIXME...symbols---eg in a break cmd---assuming they are from a shared
7805 @c FIXME...lib; check this from time to time when updating manual
7808 @kindex info sharedlibrary
7811 @itemx info sharedlibrary
7812 Print the names of the shared libraries which are currently loaded.
7814 @kindex sharedlibrary
7816 @item sharedlibrary @var{regex}
7817 @itemx share @var{regex}
7819 Load shared object library symbols for files matching a
7820 Unix regular expression.
7821 As with files loaded automatically, it only loads shared libraries
7822 required by your program for a core file or after typing @code{run}. If
7823 @var{regex} is omitted all shared libraries required by your program are
7827 On HP-UX systems, @value{GDBN} detects the loading of a shared library
7828 and automatically reads in symbols from the newly loaded library, up to
7829 a threshold that is initially set but that you can modify if you wish.
7831 Beyond that threshold, symbols from shared libraries must be explicitly
7832 loaded. To load these symbols, use the command @code{sharedlibrary}
7833 @var{filename}. The base address of the shared library is determined
7834 automatically by @value{GDBN} and need not be specified.
7836 To display or set the threshold, use the commands:
7839 @kindex set auto-solib-add
7840 @item set auto-solib-add @var{threshold}
7841 Set the autoloading size threshold, in megabytes. If @var{threshold} is
7842 nonzero, symbols from all shared object libraries will be loaded
7843 automatically when the inferior begins execution or when the dynamic
7844 linker informs @value{GDBN} that a new library has been loaded, until
7845 the symbol table of the program and libraries exceeds this threshold.
7846 Otherwise, symbols must be loaded manually, using the
7847 @code{sharedlibrary} command. The default threshold is 100 megabytes.
7849 @kindex show auto-solib-add
7850 @item show auto-solib-add
7851 Display the current autoloading size threshold, in megabytes.
7855 @section Errors reading symbol files
7857 While reading a symbol file, @value{GDBN} occasionally encounters problems,
7858 such as symbol types it does not recognize, or known bugs in compiler
7859 output. By default, @value{GDBN} does not notify you of such problems, since
7860 they are relatively common and primarily of interest to people
7861 debugging compilers. If you are interested in seeing information
7862 about ill-constructed symbol tables, you can either ask @value{GDBN} to print
7863 only one message about each such type of problem, no matter how many
7864 times the problem occurs; or you can ask @value{GDBN} to print more messages,
7865 to see how many times the problems occur, with the @code{set
7866 complaints} command (@pxref{Messages/Warnings, ,Optional warnings and
7869 The messages currently printed, and their meanings, include:
7872 @item inner block not inside outer block in @var{symbol}
7874 The symbol information shows where symbol scopes begin and end
7875 (such as at the start of a function or a block of statements). This
7876 error indicates that an inner scope block is not fully contained
7877 in its outer scope blocks.
7879 @value{GDBN} circumvents the problem by treating the inner block as if it had
7880 the same scope as the outer block. In the error message, @var{symbol}
7881 may be shown as ``@code{(don't know)}'' if the outer block is not a
7884 @item block at @var{address} out of order
7886 The symbol information for symbol scope blocks should occur in
7887 order of increasing addresses. This error indicates that it does not
7890 @value{GDBN} does not circumvent this problem, and has trouble
7891 locating symbols in the source file whose symbols it is reading. (You
7892 can often determine what source file is affected by specifying
7893 @code{set verbose on}. @xref{Messages/Warnings, ,Optional warnings and
7896 @item bad block start address patched
7898 The symbol information for a symbol scope block has a start address
7899 smaller than the address of the preceding source line. This is known
7900 to occur in the SunOS 4.1.1 (and earlier) C compiler.
7902 @value{GDBN} circumvents the problem by treating the symbol scope block as
7903 starting on the previous source line.
7905 @item bad string table offset in symbol @var{n}
7908 Symbol number @var{n} contains a pointer into the string table which is
7909 larger than the size of the string table.
7911 @value{GDBN} circumvents the problem by considering the symbol to have the
7912 name @code{foo}, which may cause other problems if many symbols end up
7915 @item unknown symbol type @code{0x@var{nn}}
7917 The symbol information contains new data types that @value{GDBN} does
7918 not yet know how to read. @code{0x@var{nn}} is the symbol type of the
7919 misunderstood information, in hexadecimal.
7921 @value{GDBN} circumvents the error by ignoring this symbol information.
7922 This usually allows you to debug your program, though certain symbols
7923 are not accessible. If you encounter such a problem and feel like
7924 debugging it, you can debug @code{@value{GDBP}} with itself, breakpoint
7925 on @code{complain}, then go up to the function @code{read_dbx_symtab}
7926 and examine @code{*bufp} to see the symbol.
7928 @item stub type has NULL name
7930 @value{GDBN} could not find the full definition for a struct or class.
7932 @item const/volatile indicator missing (ok if using g++ v1.x), got@dots{}
7933 The symbol information for a C++ member function is missing some
7934 information that recent versions of the compiler should have output for
7937 @item info mismatch between compiler and debugger
7939 @value{GDBN} could not parse a type specification output by the compiler.
7944 @chapter Specifying a Debugging Target
7946 @cindex debugging target
7949 A @dfn{target} is the execution environment occupied by your program.
7951 Often, @value{GDBN} runs in the same host environment as your program;
7952 in that case, the debugging target is specified as a side effect when
7953 you use the @code{file} or @code{core} commands. When you need more
7954 flexibility---for example, running @value{GDBN} on a physically separate
7955 host, or controlling a standalone system over a serial port or a
7956 realtime system over a TCP/IP connection---you can use the @code{target}
7957 command to specify one of the target types configured for @value{GDBN}
7958 (@pxref{Target Commands, ,Commands for managing targets}).
7961 * Active Targets:: Active targets
7962 * Target Commands:: Commands for managing targets
7963 * Byte Order:: Choosing target byte order
7964 * Remote:: Remote debugging
7965 * KOD:: Kernel Object Display
7969 @node Active Targets
7970 @section Active targets
7972 @cindex stacking targets
7973 @cindex active targets
7974 @cindex multiple targets
7976 There are three classes of targets: processes, core files, and
7977 executable files. @value{GDBN} can work concurrently on up to three
7978 active targets, one in each class. This allows you to (for example)
7979 start a process and inspect its activity without abandoning your work on
7982 For example, if you execute @samp{gdb a.out}, then the executable file
7983 @code{a.out} is the only active target. If you designate a core file as
7984 well---presumably from a prior run that crashed and coredumped---then
7985 @value{GDBN} has two active targets and uses them in tandem, looking
7986 first in the corefile target, then in the executable file, to satisfy
7987 requests for memory addresses. (Typically, these two classes of target
7988 are complementary, since core files contain only a program's
7989 read-write memory---variables and so on---plus machine status, while
7990 executable files contain only the program text and initialized data.)
7992 When you type @code{run}, your executable file becomes an active process
7993 target as well. When a process target is active, all @value{GDBN}
7994 commands requesting memory addresses refer to that target; addresses in
7995 an active core file or executable file target are obscured while the
7996 process target is active.
7998 Use the @code{core-file} and @code{exec-file} commands to select a new
7999 core file or executable target (@pxref{Files, ,Commands to specify
8000 files}). To specify as a target a process that is already running, use
8001 the @code{attach} command (@pxref{Attach, ,Debugging an already-running
8004 @node Target Commands
8005 @section Commands for managing targets
8008 @item target @var{type} @var{parameters}
8009 Connects the @value{GDBN} host environment to a target machine or
8010 process. A target is typically a protocol for talking to debugging
8011 facilities. You use the argument @var{type} to specify the type or
8012 protocol of the target machine.
8014 Further @var{parameters} are interpreted by the target protocol, but
8015 typically include things like device names or host names to connect
8016 with, process numbers, and baud rates.
8018 The @code{target} command does not repeat if you press @key{RET} again
8019 after executing the command.
8023 Displays the names of all targets available. To display targets
8024 currently selected, use either @code{info target} or @code{info files}
8025 (@pxref{Files, ,Commands to specify files}).
8027 @item help target @var{name}
8028 Describe a particular target, including any parameters necessary to
8031 @kindex set gnutarget
8032 @item set gnutarget @var{args}
8033 @value{GDBN} uses its own library BFD to read your files. @value{GDBN}
8034 knows whether it is reading an @dfn{executable},
8035 a @dfn{core}, or a @dfn{.o} file; however, you can specify the file format
8036 with the @code{set gnutarget} command. Unlike most @code{target} commands,
8037 with @code{gnutarget} the @code{target} refers to a program, not a machine.
8039 @emph{Warning:} To specify a file format with @code{set gnutarget},
8040 you must know the actual BFD name.
8042 @noindent @xref{Files, , Commands to specify files}.
8044 @kindex show gnutarget
8045 @item show gnutarget
8046 Use the @code{show gnutarget} command to display what file format
8047 @code{gnutarget} is set to read. If you have not set @code{gnutarget},
8048 @value{GDBN} will determine the file format for each file automatically,
8049 and @code{show gnutarget} displays @samp{The current BDF target is "auto"}.
8052 Here are some common targets (available, or not, depending on the GDB
8057 @item target exec @var{program}
8058 An executable file. @samp{target exec @var{program}} is the same as
8059 @samp{exec-file @var{program}}.
8062 @item target core @var{filename}
8063 A core dump file. @samp{target core @var{filename}} is the same as
8064 @samp{core-file @var{filename}}.
8066 @kindex target remote
8067 @item target remote @var{dev}
8068 Remote serial target in GDB-specific protocol. The argument @var{dev}
8069 specifies what serial device to use for the connection (e.g.
8070 @file{/dev/ttya}). @xref{Remote, ,Remote debugging}. @code{target remote}
8071 now supports the @code{load} command. This is only useful if you have
8072 some other way of getting the stub to the target system, and you can put
8073 it somewhere in memory where it won't get clobbered by the download.
8077 CPU simulator. @xref{Simulator,,Simulated CPU Target}.
8080 The following targets are all CPU-specific, and only available for
8081 specific configurations.
8082 @c should organize by CPU
8087 @item target abug @var{dev}
8088 ABug ROM monitor for M68K.
8090 @kindex target adapt
8091 @item target adapt @var{dev}
8092 Adapt monitor for A29K.
8094 @kindex target amd-eb
8095 @item target amd-eb @var{dev} @var{speed} @var{PROG}
8097 Remote PC-resident AMD EB29K board, attached over serial lines.
8098 @var{dev} is the serial device, as for @code{target remote};
8099 @var{speed} allows you to specify the linespeed; and @var{PROG} is the
8100 name of the program to be debugged, as it appears to DOS on the PC.
8101 @xref{EB29K Remote, ,The EBMON protocol for AMD29K}.
8103 @kindex target array
8104 @item target array @var{dev}
8105 Array Tech LSI33K RAID controller board.
8108 @item target bug @var{dev}
8109 BUG monitor, running on a MVME187 (m88k) board.
8111 @kindex target cpu32bug
8112 @item target cpu32bug @var{dev}
8113 CPU32BUG monitor, running on a CPU32 (M68K) board.
8116 @item target dbug @var{dev}
8117 dBUG ROM monitor for Motorola ColdFire.
8120 @item target ddb @var{dev}
8121 NEC's DDB monitor for Mips Vr4300.
8123 @kindex target dink32
8124 @item target dink32 @var{dev}
8125 DINK32 ROM monitor for PowerPC.
8127 @kindex target e7000
8128 @item target e7000 @var{dev}
8129 E7000 emulator for Hitachi H8 and SH.
8131 @kindex target es1800
8132 @item target es1800 @var{dev}
8133 ES-1800 emulator for M68K.
8136 @item target est @var{dev}
8137 EST-300 ICE monitor, running on a CPU32 (M68K) board.
8140 @item target hms @var{dev}
8141 A Hitachi SH, H8/300, or H8/500 board, attached via serial line to your host.
8142 Use special commands @code{device} and @code{speed} to control the serial
8143 line and the communications speed used.
8144 @xref{Hitachi Remote,,@value{GDBN} and Hitachi Microprocessors}.
8147 @item target lsi @var{dev}
8148 LSI ROM monitor for Mips.
8151 @item target m32r @var{dev}
8152 Mitsubishi M32R/D ROM monitor.
8155 @item target mips @var{dev}
8156 IDT/SIM ROM monitor for Mips.
8158 @kindex target mon960
8159 @item target mon960 @var{dev}
8160 MON960 monitor for Intel i960.
8162 @kindex target nindy
8163 @item target nindy @var{devicename}
8164 An Intel 960 board controlled by a Nindy Monitor. @var{devicename} is
8165 the name of the serial device to use for the connection, e.g.
8166 @file{/dev/ttya}. @xref{i960-Nindy Remote, ,@value{GDBN} with a remote i960 (Nindy)}.
8169 @item target nrom @var{dev}
8170 NetROM ROM emulator. This target only supports downloading.
8172 @kindex target op50n
8173 @item target op50n @var{dev}
8174 OP50N monitor, running on an OKI HPPA board.
8177 @item target pmon @var{dev}
8178 PMON ROM monitor for Mips.
8180 @kindex target ppcbug
8181 @item target ppcbug @var{dev}
8182 @kindex target ppcbug1
8183 @item target ppcbug1 @var{dev}
8184 PPCBUG ROM monitor for PowerPC.
8186 @kindex target r3900
8187 @item target r3900 @var{dev}
8188 Densan DVE-R3900 ROM monitor for Toshiba R3900 Mips.
8191 @item target rdi @var{dev}
8192 ARM Angel monitor, via RDI library interface.
8195 @item target rdp @var{dev}
8198 @kindex target rom68k
8199 @item target rom68k @var{dev}
8200 ROM 68K monitor, running on an M68K IDP board.
8202 @kindex target rombug
8203 @item target rombug @var{dev}
8204 ROMBUG ROM monitor for OS/9000.
8207 @item target sds @var{dev}
8208 SDS monitor, running on a PowerPC board (such as Motorola's ADS).
8210 @kindex target sparclite
8211 @item target sparclite @var{dev}
8212 Fujitsu sparclite boards, used only for the purpose of loading.
8213 You must use an additional command to debug the program.
8214 For example: target remote @var{dev} using @value{GDBN} standard
8219 @item target sh3 @var{dev}
8220 @item target sh3e @var{dev}
8221 Hitachi SH-3 and SH-3E target systems.
8223 @kindex target st2000
8224 @item target st2000 @var{dev} @var{speed}
8225 A Tandem ST2000 phone switch, running Tandem's STDBUG protocol. @var{dev}
8226 is the name of the device attached to the ST2000 serial line;
8227 @var{speed} is the communication line speed. The arguments are not used
8228 if @value{GDBN} is configured to connect to the ST2000 using TCP or Telnet.
8229 @xref{ST2000 Remote,,@value{GDBN} with a Tandem ST2000}.
8232 @item target udi @var{keyword}
8233 Remote AMD29K target, using the AMD UDI protocol. The @var{keyword}
8234 argument specifies which 29K board or simulator to use. @xref{UDI29K
8235 Remote,,The UDI protocol for AMD29K}.
8237 @kindex target vxworks
8238 @item target vxworks @var{machinename}
8239 A VxWorks system, attached via TCP/IP. The argument @var{machinename}
8240 is the target system's machine name or IP address.
8241 @xref{VxWorks Remote, ,@value{GDBN} and VxWorks}.
8244 @item target w89k @var{dev}
8245 W89K monitor, running on a Winbond HPPA board.
8249 Different targets are available on different configurations of @value{GDBN};
8250 your configuration may have more or fewer targets.
8252 Many remote targets require you to download the executable's code
8253 once you've successfully established a connection.
8257 @kindex load @var{filename}
8258 @item load @var{filename}
8259 Depending on what remote debugging facilities are configured into
8260 @value{GDBN}, the @code{load} command may be available. Where it exists, it
8261 is meant to make @var{filename} (an executable) available for debugging
8262 on the remote system---by downloading, or dynamic linking, for example.
8263 @code{load} also records the @var{filename} symbol table in @value{GDBN}, like
8264 the @code{add-symbol-file} command.
8266 If your @value{GDBN} does not have a @code{load} command, attempting to
8267 execute it gets the error message ``@code{You can't do that when your
8268 target is @dots{}}''
8270 The file is loaded at whatever address is specified in the executable.
8271 For some object file formats, you can specify the load address when you
8272 link the program; for other formats, like a.out, the object file format
8273 specifies a fixed address.
8274 @c FIXME! This would be a good place for an xref to the GNU linker doc.
8276 On VxWorks, @code{load} links @var{filename} dynamically on the
8277 current target system as well as adding its symbols in @value{GDBN}.
8279 @cindex download to Nindy-960
8280 With the Nindy interface to an Intel 960 board, @code{load}
8281 downloads @var{filename} to the 960 as well as adding its symbols in
8284 @cindex download to H8/300 or H8/500
8285 @cindex H8/300 or H8/500 download
8286 @cindex download to Hitachi SH
8287 @cindex Hitachi SH download
8288 When you select remote debugging to a Hitachi SH, H8/300, or H8/500 board
8289 (@pxref{Hitachi Remote,,@value{GDBN} and Hitachi Microprocessors}),
8290 the @code{load} command downloads your program to the Hitachi board and also
8291 opens it as the current executable target for @value{GDBN} on your host
8292 (like the @code{file} command).
8294 @code{load} does not repeat if you press @key{RET} again after using it.
8298 @section Choosing target byte order
8300 @cindex choosing target byte order
8301 @cindex target byte order
8302 @kindex set endian big
8303 @kindex set endian little
8304 @kindex set endian auto
8307 Some types of processors, such as the MIPS, PowerPC, and Hitachi SH,
8308 offer the ability to run either big-endian or little-endian byte
8309 orders. Usually the executable or symbol will include a bit to
8310 designate the endian-ness, and you will not need to worry about
8311 which to use. However, you may still find it useful to adjust
8312 GDB's idea of processor endian-ness manually.
8315 @kindex set endian big
8316 @item set endian big
8317 Instruct @value{GDBN} to assume the target is big-endian.
8319 @kindex set endian little
8320 @item set endian little
8321 Instruct @value{GDBN} to assume the target is little-endian.
8323 @kindex set endian auto
8324 @item set endian auto
8325 Instruct @value{GDBN} to use the byte order associated with the
8329 Display @value{GDBN}'s current idea of the target byte order.
8333 Note that these commands merely adjust interpretation of symbolic
8334 data on the host, and that they have absolutely no effect on the
8338 @section Remote debugging
8339 @cindex remote debugging
8341 If you are trying to debug a program running on a machine that cannot run
8342 @value{GDBN} in the usual way, it is often useful to use remote debugging.
8343 For example, you might use remote debugging on an operating system kernel,
8344 or on a small system which does not have a general purpose operating system
8345 powerful enough to run a full-featured debugger.
8347 Some configurations of @value{GDBN} have special serial or TCP/IP interfaces
8348 to make this work with particular debugging targets. In addition,
8349 @value{GDBN} comes with a generic serial protocol (specific to @value{GDBN},
8350 but not specific to any particular target system) which you can use if you
8351 write the remote stubs---the code that runs on the remote system to
8352 communicate with @value{GDBN}.
8354 Other remote targets may be available in your
8355 configuration of @value{GDBN}; use @code{help target} to list them.
8357 @c Text on starting up GDB in various specific cases; it goes up front
8358 @c in manuals configured for any of those particular situations, here
8361 * Remote Serial:: @value{GDBN} remote serial protocol
8362 * i960-Nindy Remote:: @value{GDBN} with a remote i960 (Nindy)
8363 * UDI29K Remote:: The UDI protocol for AMD29K
8364 * EB29K Remote:: The EBMON protocol for AMD29K
8365 * VxWorks Remote:: @value{GDBN} and VxWorks
8366 * ST2000 Remote:: @value{GDBN} with a Tandem ST2000
8367 * Hitachi Remote:: @value{GDBN} and Hitachi Microprocessors
8368 * MIPS Remote:: @value{GDBN} and MIPS boards
8369 * Sparclet Remote:: @value{GDBN} and Sparclet boards
8370 * Simulator:: Simulated CPU target
8373 @include remote.texi
8377 @section Kernel Object Display
8378 @cindex kernel object display
8379 @cindex kernel object
8382 Some targets support kernel object display. Using this facility,
8383 @value{GDBN} communicates specially with the underlying operating system
8384 and can display information about operating system-level objects such as
8385 mutexes and other synchronization objects. Exactly which objects can be
8386 displayed is determined on a per-OS basis.
8388 Use the @code{set os} command to set the operating system. This tells
8389 @value{GDBN} which kernel object display module to initialize:
8395 If @code{set os} succeeds, @value{GDBN} will display some information
8396 about the operating system, and will create a new @code{info} command
8397 which can be used to query the target. The @code{info} command is named
8398 after the operating system:
8402 List of Cisco Kernel Objects
8404 any Any and all objects
8407 Further subcommands can be used to query about particular objects known
8410 There is currently no way to determine whether a given operating system
8411 is supported other than to try it.
8414 @node Controlling GDB
8415 @chapter Controlling @value{GDBN}
8417 You can alter the way @value{GDBN} interacts with you by using the
8418 @code{set} command. For commands controlling how @value{GDBN} displays
8419 data, @pxref{Print Settings, ,Print settings}; other settings are
8424 * Editing:: Command editing
8425 * History:: Command history
8426 * Screen Size:: Screen size
8428 * Messages/Warnings:: Optional warnings and messages
8436 @value{GDBN} indicates its readiness to read a command by printing a string
8437 called the @dfn{prompt}. This string is normally @samp{(@value{GDBP})}. You
8438 can change the prompt string with the @code{set prompt} command. For
8439 instance, when debugging @value{GDBN} with @value{GDBN}, it is useful to change
8440 the prompt in one of the @value{GDBN} sessions so that you can always tell
8441 which one you are talking to.
8443 @emph{Note:} @code{set prompt} no longer adds a space for you after the
8444 prompt you set. This allows you to set a prompt which ends in a space
8445 or a prompt that does not.
8449 @item set prompt @var{newprompt}
8450 Directs @value{GDBN} to use @var{newprompt} as its prompt string henceforth.
8454 Prints a line of the form: @samp{Gdb's prompt is: @var{your-prompt}}
8458 @section Command editing
8460 @cindex command line editing
8462 @value{GDBN} reads its input commands via the @dfn{readline} interface. This
8463 @sc{gnu} library provides consistent behavior for programs which provide a
8464 command line interface to the user. Advantages are @sc{gnu} Emacs-style
8465 or @dfn{vi}-style inline editing of commands, @code{csh}-like history
8466 substitution, and a storage and recall of command history across
8469 You may control the behavior of command line editing in @value{GDBN} with the
8476 @itemx set editing on
8477 Enable command line editing (enabled by default).
8479 @item set editing off
8480 Disable command line editing.
8482 @kindex show editing
8484 Show whether command line editing is enabled.
8488 @section Command history
8490 @value{GDBN} can keep track of the commands you type during your
8491 debugging sessions, so that you can be certain of precisely what
8492 happened. Use these commands to manage the @value{GDBN} command
8496 @cindex history substitution
8497 @cindex history file
8498 @kindex set history filename
8500 @item set history filename @var{fname}
8501 Set the name of the @value{GDBN} command history file to @var{fname}.
8502 This is the file where @value{GDBN} reads an initial command history
8503 list, and where it writes the command history from this session when it
8504 exits. You can access this list through history expansion or through
8505 the history command editing characters listed below. This file defaults
8506 to the value of the environment variable @code{GDBHISTFILE}, or to
8507 @file{./.gdb_history} if this variable is not set.
8509 @cindex history save
8510 @kindex set history save
8511 @item set history save
8512 @itemx set history save on
8513 Record command history in a file, whose name may be specified with the
8514 @code{set history filename} command. By default, this option is disabled.
8516 @item set history save off
8517 Stop recording command history in a file.
8519 @cindex history size
8520 @kindex set history size
8521 @item set history size @var{size}
8522 Set the number of commands which @value{GDBN} keeps in its history list.
8523 This defaults to the value of the environment variable
8524 @code{HISTSIZE}, or to 256 if this variable is not set.
8527 @cindex history expansion
8528 History expansion assigns special meaning to the character @kbd{!}.
8529 @ifset have-readline-appendices
8530 @xref{Event Designators}.
8533 Since @kbd{!} is also the logical not operator in C, history expansion
8534 is off by default. If you decide to enable history expansion with the
8535 @code{set history expansion on} command, you may sometimes need to
8536 follow @kbd{!} (when it is used as logical not, in an expression) with
8537 a space or a tab to prevent it from being expanded. The readline
8538 history facilities do not attempt substitution on the strings
8539 @kbd{!=} and @kbd{!(}, even when history expansion is enabled.
8541 The commands to control history expansion are:
8544 @kindex set history expansion
8545 @item set history expansion on
8546 @itemx set history expansion
8547 Enable history expansion. History expansion is off by default.
8549 @item set history expansion off
8550 Disable history expansion.
8552 The readline code comes with more complete documentation of
8553 editing and history expansion features. Users unfamiliar with @sc{gnu} Emacs
8554 or @code{vi} may wish to read it.
8555 @ifset have-readline-appendices
8556 @xref{Command Line Editing}.
8560 @kindex show history
8562 @itemx show history filename
8563 @itemx show history save
8564 @itemx show history size
8565 @itemx show history expansion
8566 These commands display the state of the @value{GDBN} history parameters.
8567 @code{show history} by itself displays all four states.
8572 @kindex show commands
8574 Display the last ten commands in the command history.
8576 @item show commands @var{n}
8577 Print ten commands centered on command number @var{n}.
8579 @item show commands +
8580 Print ten commands just after the commands last printed.
8584 @section Screen size
8585 @cindex size of screen
8586 @cindex pauses in output
8588 Certain commands to @value{GDBN} may produce large amounts of
8589 information output to the screen. To help you read all of it,
8590 @value{GDBN} pauses and asks you for input at the end of each page of
8591 output. Type @key{RET} when you want to continue the output, or @kbd{q}
8592 to discard the remaining output. Also, the screen width setting
8593 determines when to wrap lines of output. Depending on what is being
8594 printed, @value{GDBN} tries to break the line at a readable place,
8595 rather than simply letting it overflow onto the following line.
8597 Normally @value{GDBN} knows the size of the screen from the termcap data base
8598 together with the value of the @code{TERM} environment variable and the
8599 @code{stty rows} and @code{stty cols} settings. If this is not correct,
8600 you can override it with the @code{set height} and @code{set
8608 @item set height @var{lpp}
8610 @itemx set width @var{cpl}
8612 These @code{set} commands specify a screen height of @var{lpp} lines and
8613 a screen width of @var{cpl} characters. The associated @code{show}
8614 commands display the current settings.
8616 If you specify a height of zero lines, @value{GDBN} does not pause during
8617 output no matter how long the output is. This is useful if output is to a
8618 file or to an editor buffer.
8620 Likewise, you can specify @samp{set width 0} to prevent @value{GDBN}
8621 from wrapping its output.
8626 @cindex number representation
8627 @cindex entering numbers
8629 You can always enter numbers in octal, decimal, or hexadecimal in @value{GDBN} by
8630 the usual conventions: octal numbers begin with @samp{0}, decimal
8631 numbers end with @samp{.}, and hexadecimal numbers begin with @samp{0x}.
8632 Numbers that begin with none of these are, by default, entered in base
8633 10; likewise, the default display for numbers---when no particular
8634 format is specified---is base 10. You can change the default base for
8635 both input and output with the @code{set radix} command.
8638 @kindex set input-radix
8639 @item set input-radix @var{base}
8640 Set the default base for numeric input. Supported choices
8641 for @var{base} are decimal 8, 10, or 16. @var{base} must itself be
8642 specified either unambiguously or using the current default radix; for
8652 sets the base to decimal. On the other hand, @samp{set radix 10}
8653 leaves the radix unchanged no matter what it was.
8655 @kindex set output-radix
8656 @item set output-radix @var{base}
8657 Set the default base for numeric display. Supported choices
8658 for @var{base} are decimal 8, 10, or 16. @var{base} must itself be
8659 specified either unambiguously or using the current default radix.
8661 @kindex show input-radix
8662 @item show input-radix
8663 Display the current default base for numeric input.
8665 @kindex show output-radix
8666 @item show output-radix
8667 Display the current default base for numeric display.
8670 @node Messages/Warnings
8671 @section Optional warnings and messages
8673 By default, @value{GDBN} is silent about its inner workings. If you are running
8674 on a slow machine, you may want to use the @code{set verbose} command.
8675 This makes @value{GDBN} tell you when it does a lengthy internal operation, so
8676 you will not think it has crashed.
8678 Currently, the messages controlled by @code{set verbose} are those
8679 which announce that the symbol table for a source file is being read;
8680 see @code{symbol-file} in @ref{Files, ,Commands to specify files}.
8684 @item set verbose on
8685 Enables @value{GDBN} output of certain informational messages.
8687 @item set verbose off
8688 Disables @value{GDBN} output of certain informational messages.
8690 @kindex show verbose
8692 Displays whether @code{set verbose} is on or off.
8695 By default, if @value{GDBN} encounters bugs in the symbol table of an object
8696 file, it is silent; but if you are debugging a compiler, you may find
8697 this information useful (@pxref{Symbol Errors, ,Errors reading symbol files}).
8700 @kindex set complaints
8701 @item set complaints @var{limit}
8702 Permits @value{GDBN} to output @var{limit} complaints about each type of unusual
8703 symbols before becoming silent about the problem. Set @var{limit} to
8704 zero to suppress all complaints; set it to a large number to prevent
8705 complaints from being suppressed.
8707 @kindex show complaints
8708 @item show complaints
8709 Displays how many symbol complaints @value{GDBN} is permitted to produce.
8712 By default, @value{GDBN} is cautious, and asks what sometimes seems to be a
8713 lot of stupid questions to confirm certain commands. For example, if
8714 you try to run a program which is already running:
8718 The program being debugged has been started already.
8719 Start it from the beginning? (y or n)
8722 If you are willing to unflinchingly face the consequences of your own
8723 commands, you can disable this ``feature'':
8728 @cindex confirmation
8729 @cindex stupid questions
8730 @item set confirm off
8731 Disables confirmation requests.
8733 @item set confirm on
8734 Enables confirmation requests (the default).
8736 @kindex show confirm
8738 Displays state of confirmation requests.
8742 @chapter Canned Sequences of Commands
8744 Aside from breakpoint commands (@pxref{Break Commands, ,Breakpoint
8745 command lists}), @value{GDBN} provides two ways to store sequences of commands
8746 for execution as a unit: user-defined commands and command files.
8749 * Define:: User-defined commands
8750 * Hooks:: User-defined command hooks
8751 * Command Files:: Command files
8752 * Output:: Commands for controlled output
8756 @section User-defined commands
8758 @cindex user-defined command
8759 A @dfn{user-defined command} is a sequence of @value{GDBN} commands to which
8760 you assign a new name as a command. This is done with the @code{define}
8761 command. User commands may accept up to 10 arguments separated by whitespace.
8762 Arguments are accessed within the user command via @var{$arg0@dots{}$arg9}.
8767 print $arg0 + $arg1 + $arg2
8770 @noindent To execute the command use:
8776 @noindent This defines the command @code{adder}, which prints the sum of
8777 its three arguments. Note the arguments are text substitutions, so they may
8778 reference variables, use complex expressions, or even perform inferior
8783 @item define @var{commandname}
8784 Define a command named @var{commandname}. If there is already a command
8785 by that name, you are asked to confirm that you want to redefine it.
8787 The definition of the command is made up of other @value{GDBN} command lines,
8788 which are given following the @code{define} command. The end of these
8789 commands is marked by a line containing @code{end}.
8794 Takes a single argument, which is an expression to evaluate.
8795 It is followed by a series of commands that are executed
8796 only if the expression is true (nonzero).
8797 There can then optionally be a line @code{else}, followed
8798 by a series of commands that are only executed if the expression
8799 was false. The end of the list is marked by a line containing @code{end}.
8803 The syntax is similar to @code{if}: the command takes a single argument,
8804 which is an expression to evaluate, and must be followed by the commands to
8805 execute, one per line, terminated by an @code{end}.
8806 The commands are executed repeatedly as long as the expression
8810 @item document @var{commandname}
8811 Document the user-defined command @var{commandname}, so that it can be
8812 accessed by @code{help}. The command @var{commandname} must already be
8813 defined. This command reads lines of documentation just as @code{define}
8814 reads the lines of the command definition, ending with @code{end}.
8815 After the @code{document} command is finished, @code{help} on command
8816 @var{commandname} displays the documentation you have written.
8818 You may use the @code{document} command again to change the
8819 documentation of a command. Redefining the command with @code{define}
8820 does not change the documentation.
8822 @kindex help user-defined
8823 @item help user-defined
8824 List all user-defined commands, with the first line of the documentation
8829 @itemx show user @var{commandname}
8830 Display the @value{GDBN} commands used to define @var{commandname} (but not its
8831 documentation). If no @var{commandname} is given, display the
8832 definitions for all user-defined commands.
8835 When user-defined commands are executed, the
8836 commands of the definition are not printed. An error in any command
8837 stops execution of the user-defined command.
8839 If used interactively, commands that would ask for confirmation proceed
8840 without asking when used inside a user-defined command. Many @value{GDBN}
8841 commands that normally print messages to say what they are doing omit the
8842 messages when used in a user-defined command.
8845 @section User-defined command hooks
8846 @cindex command files
8848 You may define @emph{hooks}, which are a special kind of user-defined
8849 command. Whenever you run the command @samp{foo}, if the user-defined
8850 command @samp{hook-foo} exists, it is executed (with no arguments)
8851 before that command.
8853 In addition, a pseudo-command, @samp{stop} exists. Defining
8854 (@samp{hook-stop}) makes the associated commands execute every time
8855 execution stops in your program: before breakpoint commands are run,
8856 displays are printed, or the stack frame is printed.
8858 For example, to ignore @code{SIGALRM} signals while
8859 single-stepping, but treat them normally during normal execution,
8864 handle SIGALRM nopass
8871 define hook-continue
8876 You can define a hook for any single-word command in @value{GDBN}, but
8877 not for command aliases; you should define a hook for the basic command
8878 name, e.g. @code{backtrace} rather than @code{bt}.
8879 @c FIXME! So how does Joe User discover whether a command is an alias
8881 If an error occurs during the execution of your hook, execution of
8882 @value{GDBN} commands stops and @value{GDBN} issues a prompt
8883 (before the command that you actually typed had a chance to run).
8885 If you try to define a hook which does not match any known command, you
8886 get a warning from the @code{define} command.
8889 @section Command files
8891 @cindex command files
8892 A command file for @value{GDBN} is a file of lines that are @value{GDBN}
8893 commands. Comments (lines starting with @kbd{#}) may also be included.
8894 An empty line in a command file does nothing; it does not mean to repeat
8895 the last command, as it would from the terminal.
8898 @cindex @file{.gdbinit}
8899 When you start @value{GDBN}, it automatically executes commands from its
8900 @dfn{init files}. These are files named @file{.gdbinit} on Unix, or
8901 @file{gdb.ini} on DOS/Windows. @value{GDBN} reads the init file (if
8902 any) in your home directory, then processes command line options and
8903 operands, and then reads the init file (if any) in the current working
8904 directory. This is so the init file in your home directory can set
8905 options (such as @code{set complaints}) which affect the processing of
8906 the command line options and operands. The init files are not executed
8907 if you use the @samp{-nx} option; @pxref{Mode Options, ,Choosing modes}.
8909 @cindex init file name
8910 On some configurations of @value{GDBN}, the init file is known by a
8911 different name (these are typically environments where a specialized
8912 form of @value{GDBN} may need to coexist with other forms, hence a
8913 different name for the specialized version's init file). These are the
8914 environments with special init file names:
8919 VxWorks (Wind River Systems real-time OS): @samp{.vxgdbinit}
8921 @kindex .os68gdbinit
8923 OS68K (Enea Data Systems real-time OS): @samp{.os68gdbinit}
8927 ES-1800 (Ericsson Telecom AB M68000 emulator): @samp{.esgdbinit}
8930 You can also request the execution of a command file with the
8931 @code{source} command:
8935 @item source @var{filename}
8936 Execute the command file @var{filename}.
8939 The lines in a command file are executed sequentially. They are not
8940 printed as they are executed. An error in any command terminates execution
8941 of the command file.
8943 Commands that would ask for confirmation if used interactively proceed
8944 without asking when used in a command file. Many @value{GDBN} commands that
8945 normally print messages to say what they are doing omit the messages
8946 when called from command files.
8949 @section Commands for controlled output
8951 During the execution of a command file or a user-defined command, normal
8952 @value{GDBN} output is suppressed; the only output that appears is what is
8953 explicitly printed by the commands in the definition. This section
8954 describes three commands useful for generating exactly the output you
8959 @item echo @var{text}
8960 @c I do not consider backslash-space a standard C escape sequence
8961 @c because it is not in ANSI.
8962 Print @var{text}. Nonprinting characters can be included in
8963 @var{text} using C escape sequences, such as @samp{\n} to print a
8964 newline. @strong{No newline is printed unless you specify one.}
8965 In addition to the standard C escape sequences, a backslash followed
8966 by a space stands for a space. This is useful for displaying a
8967 string with spaces at the beginning or the end, since leading and
8968 trailing spaces are otherwise trimmed from all arguments.
8969 To print @samp{@w{ }and foo =@w{ }}, use the command
8970 @samp{echo \@w{ }and foo = \@w{ }}.
8972 A backslash at the end of @var{text} can be used, as in C, to continue
8973 the command onto subsequent lines. For example,
8976 echo This is some text\n\
8977 which is continued\n\
8978 onto several lines.\n
8981 produces the same output as
8984 echo This is some text\n
8985 echo which is continued\n
8986 echo onto several lines.\n
8990 @item output @var{expression}
8991 Print the value of @var{expression} and nothing but that value: no
8992 newlines, no @samp{$@var{nn} = }. The value is not entered in the
8993 value history either. @xref{Expressions, ,Expressions}, for more information
8996 @item output/@var{fmt} @var{expression}
8997 Print the value of @var{expression} in format @var{fmt}. You can use
8998 the same formats as for @code{print}. @xref{Output Formats,,Output
8999 formats}, for more information.
9002 @item printf @var{string}, @var{expressions}@dots{}
9003 Print the values of the @var{expressions} under the control of
9004 @var{string}. The @var{expressions} are separated by commas and may be
9005 either numbers or pointers. Their values are printed as specified by
9006 @var{string}, exactly as if your program were to execute the C
9010 printf (@var{string}, @var{expressions}@dots{});
9013 For example, you can print two values in hex like this:
9016 printf "foo, bar-foo = 0x%x, 0x%x\n", foo, bar-foo
9019 The only backslash-escape sequences that you can use in the format
9020 string are the simple ones that consist of backslash followed by a
9025 @chapter Using @value{GDBN} under @sc{gnu} Emacs
9028 @cindex @sc{gnu} Emacs
9029 A special interface allows you to use @sc{gnu} Emacs to view (and
9030 edit) the source files for the program you are debugging with
9033 To use this interface, use the command @kbd{M-x gdb} in Emacs. Give the
9034 executable file you want to debug as an argument. This command starts
9035 @value{GDBN} as a subprocess of Emacs, with input and output through a newly
9036 created Emacs buffer.
9037 @c (Do not use the @code{-tui} option to run @value{GDBN} from Emacs.)
9039 Using @value{GDBN} under Emacs is just like using @value{GDBN} normally except for two
9044 All ``terminal'' input and output goes through the Emacs buffer.
9047 This applies both to @value{GDBN} commands and their output, and to the input
9048 and output done by the program you are debugging.
9050 This is useful because it means that you can copy the text of previous
9051 commands and input them again; you can even use parts of the output
9054 All the facilities of Emacs' Shell mode are available for interacting
9055 with your program. In particular, you can send signals the usual
9056 way---for example, @kbd{C-c C-c} for an interrupt, @kbd{C-c C-z} for a
9061 @value{GDBN} displays source code through Emacs.
9064 Each time @value{GDBN} displays a stack frame, Emacs automatically finds the
9065 source file for that frame and puts an arrow (@samp{=>}) at the
9066 left margin of the current line. Emacs uses a separate buffer for
9067 source display, and splits the screen to show both your @value{GDBN} session
9070 Explicit @value{GDBN} @code{list} or search commands still produce output as
9071 usual, but you probably have no reason to use them from Emacs.
9074 @emph{Warning:} If the directory where your program resides is not your
9075 current directory, it can be easy to confuse Emacs about the location of
9076 the source files, in which case the auxiliary display buffer does not
9077 appear to show your source. @value{GDBN} can find programs by searching your
9078 environment's @code{PATH} variable, so the @value{GDBN} input and output
9079 session proceeds normally; but Emacs does not get enough information
9080 back from @value{GDBN} to locate the source files in this situation. To
9081 avoid this problem, either start @value{GDBN} mode from the directory where
9082 your program resides, or specify an absolute file name when prompted for the
9083 @kbd{M-x gdb} argument.
9085 A similar confusion can result if you use the @value{GDBN} @code{file} command to
9086 switch to debugging a program in some other location, from an existing
9087 @value{GDBN} buffer in Emacs.
9090 By default, @kbd{M-x gdb} calls the program called @file{gdb}. If
9091 you need to call @value{GDBN} by a different name (for example, if you keep
9092 several configurations around, with different names) you can set the
9093 Emacs variable @code{gdb-command-name}; for example,
9096 (setq gdb-command-name "mygdb")
9100 (preceded by @kbd{ESC ESC}, or typed in the @code{*scratch*} buffer, or
9101 in your @file{.emacs} file) makes Emacs call the program named
9102 ``@code{mygdb}'' instead.
9104 In the @value{GDBN} I/O buffer, you can use these special Emacs commands in
9105 addition to the standard Shell mode commands:
9109 Describe the features of Emacs' @value{GDBN} Mode.
9112 Execute to another source line, like the @value{GDBN} @code{step} command; also
9113 update the display window to show the current file and location.
9116 Execute to next source line in this function, skipping all function
9117 calls, like the @value{GDBN} @code{next} command. Then update the display window
9118 to show the current file and location.
9121 Execute one instruction, like the @value{GDBN} @code{stepi} command; update
9122 display window accordingly.
9125 Execute to next instruction, using the @value{GDBN} @code{nexti} command; update
9126 display window accordingly.
9129 Execute until exit from the selected stack frame, like the @value{GDBN}
9130 @code{finish} command.
9133 Continue execution of your program, like the @value{GDBN} @code{continue}
9136 @emph{Warning:} In Emacs v19, this command is @kbd{C-c C-p}.
9139 Go up the number of frames indicated by the numeric argument
9140 (@pxref{Arguments, , Numeric Arguments, Emacs, The @sc{gnu} Emacs Manual}),
9141 like the @value{GDBN} @code{up} command.
9143 @emph{Warning:} In Emacs v19, this command is @kbd{C-c C-u}.
9146 Go down the number of frames indicated by the numeric argument, like the
9147 @value{GDBN} @code{down} command.
9149 @emph{Warning:} In Emacs v19, this command is @kbd{C-c C-d}.
9152 Read the number where the cursor is positioned, and insert it at the end
9153 of the @value{GDBN} I/O buffer. For example, if you wish to disassemble code
9154 around an address that was displayed earlier, type @kbd{disassemble};
9155 then move the cursor to the address display, and pick up the
9156 argument for @code{disassemble} by typing @kbd{C-x &}.
9158 You can customize this further by defining elements of the list
9159 @code{gdb-print-command}; once it is defined, you can format or
9160 otherwise process numbers picked up by @kbd{C-x &} before they are
9161 inserted. A numeric argument to @kbd{C-x &} indicates that you
9162 wish special formatting, and also acts as an index to pick an element of the
9163 list. If the list element is a string, the number to be inserted is
9164 formatted using the Emacs function @code{format}; otherwise the number
9165 is passed as an argument to the corresponding list element.
9168 In any source file, the Emacs command @kbd{C-x SPC} (@code{gdb-break})
9169 tells @value{GDBN} to set a breakpoint on the source line point is on.
9171 If you accidentally delete the source-display buffer, an easy way to get
9172 it back is to type the command @code{f} in the @value{GDBN} buffer, to
9173 request a frame display; when you run under Emacs, this recreates
9174 the source buffer if necessary to show you the context of the current
9177 The source files displayed in Emacs are in ordinary Emacs buffers
9178 which are visiting the source files in the usual way. You can edit
9179 the files with these buffers if you wish; but keep in mind that @value{GDBN}
9180 communicates with Emacs in terms of line numbers. If you add or
9181 delete lines from the text, the line numbers that @value{GDBN} knows cease
9182 to correspond properly with the code.
9184 @c The following dropped because Epoch is nonstandard. Reactivate
9185 @c if/when v19 does something similar. ---doc@cygnus.com 19dec1990
9187 @kindex Emacs Epoch environment
9191 Version 18 of @sc{gnu} Emacs has a built-in window system
9192 called the @code{epoch}
9193 environment. Users of this environment can use a new command,
9194 @code{inspect} which performs identically to @code{print} except that
9195 each value is printed in its own window.
9199 @chapter Reporting Bugs in @value{GDBN}
9200 @cindex bugs in @value{GDBN}
9201 @cindex reporting bugs in @value{GDBN}
9203 Your bug reports play an essential role in making @value{GDBN} reliable.
9205 Reporting a bug may help you by bringing a solution to your problem, or it
9206 may not. But in any case the principal function of a bug report is to help
9207 the entire community by making the next version of @value{GDBN} work better. Bug
9208 reports are your contribution to the maintenance of @value{GDBN}.
9210 In order for a bug report to serve its purpose, you must include the
9211 information that enables us to fix the bug.
9214 * Bug Criteria:: Have you found a bug?
9215 * Bug Reporting:: How to report bugs
9219 @section Have you found a bug?
9220 @cindex bug criteria
9222 If you are not sure whether you have found a bug, here are some guidelines:
9225 @cindex fatal signal
9226 @cindex debugger crash
9227 @cindex crash of debugger
9229 If the debugger gets a fatal signal, for any input whatever, that is a
9230 @value{GDBN} bug. Reliable debuggers never crash.
9232 @cindex error on valid input
9234 If @value{GDBN} produces an error message for valid input, that is a
9235 bug. (Note that if you're cross debugging, the problem may also be
9236 somewhere in the connection to the target.)
9238 @cindex invalid input
9240 If @value{GDBN} does not produce an error message for invalid input,
9241 that is a bug. However, you should note that your idea of
9242 ``invalid input'' might be our idea of ``an extension'' or ``support
9243 for traditional practice''.
9246 If you are an experienced user of debugging tools, your suggestions
9247 for improvement of @value{GDBN} are welcome in any case.
9251 @section How to report bugs
9253 @cindex @value{GDBN} bugs, reporting
9255 A number of companies and individuals offer support for @sc{gnu} products.
9256 If you obtained @value{GDBN} from a support organization, we recommend you
9257 contact that organization first.
9259 You can find contact information for many support companies and
9260 individuals in the file @file{etc/SERVICE} in the @sc{gnu} Emacs
9262 @c should add a web page ref...
9264 In any event, we also recommend that you send bug reports for
9265 @value{GDBN} to this addresses:
9268 bug-gdb@@prep.ai.mit.edu
9271 @strong{Do not send bug reports to @samp{info-gdb}, or to
9272 @samp{help-gdb}, or to any newsgroups.} Most users of @value{GDBN} do
9273 not want to receive bug reports. Those that do have arranged to receive
9276 The mailing list @samp{bug-gdb} has a newsgroup @samp{gnu.gdb.bug} which
9277 serves as a repeater. The mailing list and the newsgroup carry exactly
9278 the same messages. Often people think of posting bug reports to the
9279 newsgroup instead of mailing them. This appears to work, but it has one
9280 problem which can be crucial: a newsgroup posting often lacks a mail
9281 path back to the sender. Thus, if we need to ask for more information,
9282 we may be unable to reach you. For this reason, it is better to send
9283 bug reports to the mailing list.
9285 As a last resort, send bug reports on paper to:
9288 @sc{gnu} Debugger Bugs
9289 Free Software Foundation Inc.
9290 59 Temple Place - Suite 330
9291 Boston, MA 02111-1307
9295 The fundamental principle of reporting bugs usefully is this:
9296 @strong{report all the facts}. If you are not sure whether to state a
9297 fact or leave it out, state it!
9299 Often people omit facts because they think they know what causes the
9300 problem and assume that some details do not matter. Thus, you might
9301 assume that the name of the variable you use in an example does not matter.
9302 Well, probably it does not, but one cannot be sure. Perhaps the bug is a
9303 stray memory reference which happens to fetch from the location where that
9304 name is stored in memory; perhaps, if the name were different, the contents
9305 of that location would fool the debugger into doing the right thing despite
9306 the bug. Play it safe and give a specific, complete example. That is the
9307 easiest thing for you to do, and the most helpful.
9309 Keep in mind that the purpose of a bug report is to enable us to fix the
9310 bug. It may be that the bug has been reported previously, but neither
9311 you nor we can know that unless your bug report is complete and
9314 Sometimes people give a few sketchy facts and ask, ``Does this ring a
9315 bell?'' Those bug reports are useless, and we urge everyone to
9316 @emph{refuse to respond to them} except to chide the sender to report
9319 To enable us to fix the bug, you should include all these things:
9323 The version of @value{GDBN}. @value{GDBN} announces it if you start
9324 with no arguments; you can also print it at any time using @code{show
9327 Without this, we will not know whether there is any point in looking for
9328 the bug in the current version of @value{GDBN}.
9331 The type of machine you are using, and the operating system name and
9335 What compiler (and its version) was used to compile @value{GDBN}---e.g.
9336 ``@value{GCC}--2.8.1''.
9339 What compiler (and its version) was used to compile the program you are
9340 debugging---e.g. ``@value{GCC}--2.8.1'', or ``HP92453-01 A.10.32.03 HP
9341 C Compiler''. For GCC, you can say @code{gcc --version} to get this
9342 information; for other compilers, see the documentation for those
9346 The command arguments you gave the compiler to compile your example and
9347 observe the bug. For example, did you use @samp{-O}? To guarantee
9348 you will not omit something important, list them all. A copy of the
9349 Makefile (or the output from make) is sufficient.
9351 If we were to try to guess the arguments, we would probably guess wrong
9352 and then we might not encounter the bug.
9355 A complete input script, and all necessary source files, that will
9359 A description of what behavior you observe that you believe is
9360 incorrect. For example, ``It gets a fatal signal.''
9362 Of course, if the bug is that @value{GDBN} gets a fatal signal, then we
9363 will certainly notice it. But if the bug is incorrect output, we might
9364 not notice unless it is glaringly wrong. You might as well not give us
9365 a chance to make a mistake.
9367 Even if the problem you experience is a fatal signal, you should still
9368 say so explicitly. Suppose something strange is going on, such as, your
9369 copy of @value{GDBN} is out of synch, or you have encountered a bug in
9370 the C library on your system. (This has happened!) Your copy might
9371 crash and ours would not. If you told us to expect a crash, then when
9372 ours fails to crash, we would know that the bug was not happening for
9373 us. If you had not told us to expect a crash, then we would not be able
9374 to draw any conclusion from our observations.
9377 If you wish to suggest changes to the @value{GDBN} source, send us context
9378 diffs. If you even discuss something in the @value{GDBN} source, refer to
9379 it by context, not by line number.
9381 The line numbers in our development sources will not match those in your
9382 sources. Your line numbers would convey no useful information to us.
9386 Here are some things that are not necessary:
9390 A description of the envelope of the bug.
9392 Often people who encounter a bug spend a lot of time investigating
9393 which changes to the input file will make the bug go away and which
9394 changes will not affect it.
9396 This is often time consuming and not very useful, because the way we
9397 will find the bug is by running a single example under the debugger
9398 with breakpoints, not by pure deduction from a series of examples.
9399 We recommend that you save your time for something else.
9401 Of course, if you can find a simpler example to report @emph{instead}
9402 of the original one, that is a convenience for us. Errors in the
9403 output will be easier to spot, running under the debugger will take
9404 less time, and so on.
9406 However, simplification is not vital; if you do not want to do this,
9407 report the bug anyway and send us the entire test case you used.
9410 A patch for the bug.
9412 A patch for the bug does help us if it is a good one. But do not omit
9413 the necessary information, such as the test case, on the assumption that
9414 a patch is all we need. We might see problems with your patch and decide
9415 to fix the problem another way, or we might not understand it at all.
9417 Sometimes with a program as complicated as @value{GDBN} it is very hard to
9418 construct an example that will make the program follow a certain path
9419 through the code. If you do not send us the example, we will not be able
9420 to construct one, so we will not be able to verify that the bug is fixed.
9422 And if we cannot understand what bug you are trying to fix, or why your
9423 patch should be an improvement, we will not install it. A test case will
9424 help us to understand.
9427 A guess about what the bug is or what it depends on.
9429 Such guesses are usually wrong. Even we cannot guess right about such
9430 things without first using the debugger to find the facts.
9433 @c The readline documentation is distributed with the readline code
9434 @c and consists of the two following files:
9437 @c Use -I with makeinfo to point to the appropriate directory,
9438 @c environment var TEXINPUTS with TeX.
9439 @include rluser.texinfo
9440 @include inc-hist.texinfo
9443 @node Formatting Documentation
9444 @appendix Formatting Documentation
9446 @cindex @value{GDBN} reference card
9447 @cindex reference card
9448 The @value{GDBN} 4 release includes an already-formatted reference card, ready
9449 for printing with PostScript or Ghostscript, in the @file{gdb}
9450 subdirectory of the main source directory@footnote{In
9451 @file{gdb-@value{GDBVN}/gdb/refcard.ps} of the version @value{GDBVN}
9452 release.}. If you can use PostScript or Ghostscript with your printer,
9453 you can print the reference card immediately with @file{refcard.ps}.
9455 The release also includes the source for the reference card. You
9456 can format it, using @TeX{}, by typing:
9462 The @value{GDBN} reference card is designed to print in @dfn{landscape}
9463 mode on US ``letter'' size paper;
9464 that is, on a sheet 11 inches wide by 8.5 inches
9465 high. You will need to specify this form of printing as an option to
9466 your @sc{dvi} output program.
9468 @cindex documentation
9470 All the documentation for @value{GDBN} comes as part of the machine-readable
9471 distribution. The documentation is written in Texinfo format, which is
9472 a documentation system that uses a single source file to produce both
9473 on-line information and a printed manual. You can use one of the Info
9474 formatting commands to create the on-line version of the documentation
9475 and @TeX{} (or @code{texi2roff}) to typeset the printed version.
9477 @value{GDBN} includes an already formatted copy of the on-line Info
9478 version of this manual in the @file{gdb} subdirectory. The main Info
9479 file is @file{gdb-@value{GDBVN}/gdb/gdb.info}, and it refers to
9480 subordinate files matching @samp{gdb.info*} in the same directory. If
9481 necessary, you can print out these files, or read them with any editor;
9482 but they are easier to read using the @code{info} subsystem in @sc{gnu}
9483 Emacs or the standalone @code{info} program, available as part of the
9484 @sc{gnu} Texinfo distribution.
9486 If you want to format these Info files yourself, you need one of the
9487 Info formatting programs, such as @code{texinfo-format-buffer} or
9490 If you have @code{makeinfo} installed, and are in the top level
9491 @value{GDBN} source directory (@file{gdb-@value{GDBVN}}, in the case of
9492 version @value{GDBVN}), you can make the Info file by typing:
9499 If you want to typeset and print copies of this manual, you need @TeX{},
9500 a program to print its @sc{dvi} output files, and @file{texinfo.tex}, the
9501 Texinfo definitions file.
9503 @TeX{} is a typesetting program; it does not print files directly, but
9504 produces output files called @sc{dvi} files. To print a typeset
9505 document, you need a program to print @sc{dvi} files. If your system
9506 has @TeX{} installed, chances are it has such a program. The precise
9507 command to use depends on your system; @kbd{lpr -d} is common; another
9508 (for PostScript devices) is @kbd{dvips}. The @sc{dvi} print command may
9509 require a file name without any extension or a @samp{.dvi} extension.
9511 @TeX{} also requires a macro definitions file called
9512 @file{texinfo.tex}. This file tells @TeX{} how to typeset a document
9513 written in Texinfo format. On its own, @TeX{} cannot either read or
9514 typeset a Texinfo file. @file{texinfo.tex} is distributed with GDB
9515 and is located in the @file{gdb-@var{version-number}/texinfo}
9518 If you have @TeX{} and a @sc{dvi} printer program installed, you can
9519 typeset and print this manual. First switch to the the @file{gdb}
9520 subdirectory of the main source directory (for example, to
9521 @file{gdb-@value{GDBVN}/gdb}) and type:
9527 Then give @file{gdb.dvi} to your @sc{dvi} printing program.
9529 @node Installing GDB
9530 @appendix Installing @value{GDBN}
9531 @cindex configuring @value{GDBN}
9532 @cindex installation
9534 @value{GDBN} comes with a @code{configure} script that automates the process
9535 of preparing @value{GDBN} for installation; you can then use @code{make} to
9536 build the @code{gdb} program.
9538 @c irrelevant in info file; it's as current as the code it lives with.
9539 @footnote{If you have a more recent version of @value{GDBN} than @value{GDBVN},
9540 look at the @file{README} file in the sources; we may have improved the
9541 installation procedures since publishing this manual.}
9544 The @value{GDBN} distribution includes all the source code you need for
9545 @value{GDBN} in a single directory, whose name is usually composed by
9546 appending the version number to @samp{gdb}.
9548 For example, the @value{GDBN} version @value{GDBVN} distribution is in the
9549 @file{gdb-@value{GDBVN}} directory. That directory contains:
9552 @item gdb-@value{GDBVN}/configure @r{(and supporting files)}
9553 script for configuring @value{GDBN} and all its supporting libraries
9555 @item gdb-@value{GDBVN}/gdb
9556 the source specific to @value{GDBN} itself
9558 @item gdb-@value{GDBVN}/bfd
9559 source for the Binary File Descriptor library
9561 @item gdb-@value{GDBVN}/include
9562 @sc{gnu} include files
9564 @item gdb-@value{GDBVN}/libiberty
9565 source for the @samp{-liberty} free software library
9567 @item gdb-@value{GDBVN}/opcodes
9568 source for the library of opcode tables and disassemblers
9570 @item gdb-@value{GDBVN}/readline
9571 source for the @sc{gnu} command-line interface
9573 @item gdb-@value{GDBVN}/glob
9574 source for the @sc{gnu} filename pattern-matching subroutine
9576 @item gdb-@value{GDBVN}/mmalloc
9577 source for the @sc{gnu} memory-mapped malloc package
9580 The simplest way to configure and build @value{GDBN} is to run @code{configure}
9581 from the @file{gdb-@var{version-number}} source directory, which in
9582 this example is the @file{gdb-@value{GDBVN}} directory.
9584 First switch to the @file{gdb-@var{version-number}} source directory
9585 if you are not already in it; then run @code{configure}. Pass the
9586 identifier for the platform on which @value{GDBN} will run as an
9592 cd gdb-@value{GDBVN}
9593 ./configure @var{host}
9598 where @var{host} is an identifier such as @samp{sun4} or
9599 @samp{decstation}, that identifies the platform where @value{GDBN} will run.
9600 (You can often leave off @var{host}; @code{configure} tries to guess the
9601 correct value by examining your system.)
9603 Running @samp{configure @var{host}} and then running @code{make} builds the
9604 @file{bfd}, @file{readline}, @file{mmalloc}, and @file{libiberty}
9605 libraries, then @code{gdb} itself. The configured source files, and the
9606 binaries, are left in the corresponding source directories.
9609 @code{configure} is a Bourne-shell (@code{/bin/sh}) script; if your
9610 system does not recognize this automatically when you run a different
9611 shell, you may need to run @code{sh} on it explicitly:
9614 sh configure @var{host}
9617 If you run @code{configure} from a directory that contains source
9618 directories for multiple libraries or programs, such as the
9619 @file{gdb-@value{GDBVN}} source directory for version @value{GDBVN}, @code{configure}
9620 creates configuration files for every directory level underneath (unless
9621 you tell it not to, with the @samp{--norecursion} option).
9623 You can run the @code{configure} script from any of the
9624 subordinate directories in the @value{GDBN} distribution if you only want to
9625 configure that subdirectory, but be sure to specify a path to it.
9627 For example, with version @value{GDBVN}, type the following to configure only
9628 the @code{bfd} subdirectory:
9632 cd gdb-@value{GDBVN}/bfd
9633 ../configure @var{host}
9637 You can install @code{@value{GDBP}} anywhere; it has no hardwired paths.
9638 However, you should make sure that the shell on your path (named by
9639 the @samp{SHELL} environment variable) is publicly readable. Remember
9640 that @value{GDBN} uses the shell to start your program---some systems refuse to
9641 let @value{GDBN} debug child processes whose programs are not readable.
9644 * Separate Objdir:: Compiling @value{GDBN} in another directory
9645 * Config Names:: Specifying names for hosts and targets
9646 * Configure Options:: Summary of options for configure
9649 @node Separate Objdir
9650 @section Compiling @value{GDBN} in another directory
9652 If you want to run @value{GDBN} versions for several host or target machines,
9653 you need a different @code{gdb} compiled for each combination of
9654 host and target. @code{configure} is designed to make this easy by
9655 allowing you to generate each configuration in a separate subdirectory,
9656 rather than in the source directory. If your @code{make} program
9657 handles the @samp{VPATH} feature (@sc{gnu} @code{make} does), running
9658 @code{make} in each of these directories builds the @code{gdb}
9659 program specified there.
9661 To build @code{gdb} in a separate directory, run @code{configure}
9662 with the @samp{--srcdir} option to specify where to find the source.
9663 (You also need to specify a path to find @code{configure}
9664 itself from your working directory. If the path to @code{configure}
9665 would be the same as the argument to @samp{--srcdir}, you can leave out
9666 the @samp{--srcdir} option; it is assumed.)
9668 For example, with version @value{GDBVN}, you can build @value{GDBN} in a
9669 separate directory for a Sun 4 like this:
9673 cd gdb-@value{GDBVN}
9676 ../gdb-@value{GDBVN}/configure sun4
9681 When @code{configure} builds a configuration using a remote source
9682 directory, it creates a tree for the binaries with the same structure
9683 (and using the same names) as the tree under the source directory. In
9684 the example, you'd find the Sun 4 library @file{libiberty.a} in the
9685 directory @file{gdb-sun4/libiberty}, and @value{GDBN} itself in
9686 @file{gdb-sun4/gdb}.
9688 One popular reason to build several @value{GDBN} configurations in separate
9689 directories is to configure @value{GDBN} for cross-compiling (where
9690 @value{GDBN} runs on one machine---the @dfn{host}---while debugging
9691 programs that run on another machine---the @dfn{target}).
9692 You specify a cross-debugging target by
9693 giving the @samp{--target=@var{target}} option to @code{configure}.
9695 When you run @code{make} to build a program or library, you must run
9696 it in a configured directory---whatever directory you were in when you
9697 called @code{configure} (or one of its subdirectories).
9699 The @code{Makefile} that @code{configure} generates in each source
9700 directory also runs recursively. If you type @code{make} in a source
9701 directory such as @file{gdb-@value{GDBVN}} (or in a separate configured
9702 directory configured with @samp{--srcdir=@var{dirname}/gdb-@value{GDBVN}}), you
9703 will build all the required libraries, and then build GDB.
9705 When you have multiple hosts or targets configured in separate
9706 directories, you can run @code{make} on them in parallel (for example,
9707 if they are NFS-mounted on each of the hosts); they will not interfere
9711 @section Specifying names for hosts and targets
9713 The specifications used for hosts and targets in the @code{configure}
9714 script are based on a three-part naming scheme, but some short predefined
9715 aliases are also supported. The full naming scheme encodes three pieces
9716 of information in the following pattern:
9719 @var{architecture}-@var{vendor}-@var{os}
9722 For example, you can use the alias @code{sun4} as a @var{host} argument,
9723 or as the value for @var{target} in a @code{--target=@var{target}}
9724 option. The equivalent full name is @samp{sparc-sun-sunos4}.
9726 The @code{configure} script accompanying @value{GDBN} does not provide
9727 any query facility to list all supported host and target names or
9728 aliases. @code{configure} calls the Bourne shell script
9729 @code{config.sub} to map abbreviations to full names; you can read the
9730 script, if you wish, or you can use it to test your guesses on
9731 abbreviations---for example:
9734 % sh config.sub i386-linux
9736 % sh config.sub alpha-linux
9737 alpha-unknown-linux-gnu
9738 % sh config.sub hp9k700
9740 % sh config.sub sun4
9741 sparc-sun-sunos4.1.1
9742 % sh config.sub sun3
9744 % sh config.sub i986v
9745 Invalid configuration `i986v': machine `i986v' not recognized
9749 @code{config.sub} is also distributed in the @value{GDBN} source
9750 directory (@file{gdb-@value{GDBVN}}, for version @value{GDBVN}).
9752 @node Configure Options
9753 @section @code{configure} options
9755 Here is a summary of the @code{configure} options and arguments that
9756 are most often useful for building @value{GDBN}. @code{configure} also has
9757 several other options not listed here. @inforef{What Configure
9758 Does,,configure.info}, for a full explanation of @code{configure}.
9761 configure @r{[}--help@r{]}
9762 @r{[}--prefix=@var{dir}@r{]}
9763 @r{[}--exec-prefix=@var{dir}@r{]}
9764 @r{[}--srcdir=@var{dirname}@r{]}
9765 @r{[}--norecursion@r{]} @r{[}--rm@r{]}
9766 @r{[}--target=@var{target}@r{]}
9771 You may introduce options with a single @samp{-} rather than
9772 @samp{--} if you prefer; but you may abbreviate option names if you use
9777 Display a quick summary of how to invoke @code{configure}.
9779 @item --prefix=@var{dir}
9780 Configure the source to install programs and files under directory
9783 @item --exec-prefix=@var{dir}
9784 Configure the source to install programs under directory
9787 @c avoid splitting the warning from the explanation:
9789 @item --srcdir=@var{dirname}
9790 @strong{Warning: using this option requires @sc{gnu} @code{make}, or another
9791 @code{make} that implements the @code{VPATH} feature.}@*
9792 Use this option to make configurations in directories separate from the
9793 @value{GDBN} source directories. Among other things, you can use this to
9794 build (or maintain) several configurations simultaneously, in separate
9795 directories. @code{configure} writes configuration specific files in
9796 the current directory, but arranges for them to use the source in the
9797 directory @var{dirname}. @code{configure} creates directories under
9798 the working directory in parallel to the source directories below
9802 Configure only the directory level where @code{configure} is executed; do not
9803 propagate configuration to subdirectories.
9805 @item --target=@var{target}
9806 Configure @value{GDBN} for cross-debugging programs running on the specified
9807 @var{target}. Without this option, @value{GDBN} is configured to debug
9808 programs that run on the same machine (@var{host}) as @value{GDBN} itself.
9810 There is no convenient way to generate a list of all available targets.
9812 @item @var{host} @dots{}
9813 Configure @value{GDBN} to run on the specified @var{host}.
9815 There is no convenient way to generate a list of all available hosts.
9818 There are many other options available as well, but they are generally
9819 needed for special purposes only.
9827 % I think something like @colophon should be in texinfo. In the
9829 \long\def\colophon{\hbox to0pt{}\vfill
9830 \centerline{The body of this manual is set in}
9831 \centerline{\fontname\tenrm,}
9832 \centerline{with headings in {\bf\fontname\tenbf}}
9833 \centerline{and examples in {\tt\fontname\tentt}.}
9834 \centerline{{\it\fontname\tenit\/},}
9835 \centerline{{\bf\fontname\tenbf}, and}
9836 \centerline{{\sl\fontname\tensl\/}}
9837 \centerline{are used for emphasis.}\vfill}
9839 % Blame: doc@cygnus.com, 1991.