2 \input texinfo @c -*-texinfo-*-
3 @c Copyright (c) 1988 1989 1990 1991 1992 Free Software Foundation, Inc.
6 @settitle Using GDB (v4)
16 @c Determine the edition number in *three* places by hand:
17 @c 1. First ifinfo section 2. title page 3. top node
18 @c To find the locations, search for !!set
20 @c The following is for Pesch for his RCS system.
21 @c This revision number *not* the same as the Edition number.
23 \def\$#1${{#1}} % Kluge: collect RCS revision info without $...$
24 \xdef\manvers{\$Revision$} % For use in headers, footers too
27 @c FOR UPDATES LEADING TO THIS DRAFT, GDB CHANGELOG CONSULTED BETWEEN:
28 @c Fri Oct 11 23:27:06 1991 John Gilmore (gnu at cygnus.com)
29 @c Sat Dec 22 02:51:40 1990 John Gilmore (gnu at cygint)
31 @c THIS MANUAL REQUIRES TEXINFO-2 macros and info-makers to format properly.
36 * Gdb: (gdb). The GNU debugger.
42 This file documents the GNU debugger GDB.
44 @c !!set edition, date, version
45 This is Edition 4.01, January 1992,
46 of @cite{Using GDB: A Guide to the GNU Source-Level Debugger}
47 for GDB Version 4.4.4.
49 Copyright (C) 1988, 1989, 1990, 1991 1992 Free Software Foundation, Inc.
51 Permission is granted to make and distribute verbatim copies of
52 this manual provided the copyright notice and this permission notice
53 are preserved on all copies.
56 Permission is granted to process this file through TeX and print the
57 results, provided the printed document carries copying permission
58 notice identical to this one except for the removal of this paragraph
59 (this paragraph not being relevant to the printed manual).
62 Permission is granted to copy and distribute modified versions of this
63 manual under the conditions for verbatim copying, provided also that the
64 section entitled ``GNU General Public License'' is included exactly as
65 in the original, and provided that the entire resulting derived work is
66 distributed under the terms of a permission notice identical to this
69 Permission is granted to copy and distribute translations of this manual
70 into another language, under the above conditions for modified versions,
71 except that the section entitled ``GNU General Public License'' may be
72 included in a translation approved by the Free Software Foundation
73 instead of in the original English.
78 @subtitle A Guide to the GNU Source-Level Debugger
80 @c !!set edition, date, version
81 @subtitle Edition 4.01, for GDB version 4.4.4
82 @subtitle January 1992
83 @author by Richard M. Stallman and Roland H. Pesch
87 \hfill rms\@ai.mit.edu, pesch\@cygnus.com\par
88 \hfill {\it Using GDB}, \manvers\par
89 \hfill \TeX{}info \texinfoversion\par
93 @vskip 0pt plus 1filll
94 Copyright @copyright{} 1988, 1989, 1990, 1991, 1992 Free Software Foundation, Inc.
96 Permission is granted to make and distribute verbatim copies of
97 this manual provided the copyright notice and this permission notice
98 are preserved on all copies.
100 Permission is granted to copy and distribute modified versions of this
101 manual under the conditions for verbatim copying, provided also that the
102 section entitled ``GNU General Public License'' is included exactly as
103 in the original, and provided that the entire resulting derived work is
104 distributed under the terms of a permission notice identical to this
107 Permission is granted to copy and distribute translations of this manual
108 into another language, under the above conditions for modified versions,
109 except that the section entitled ``GNU General Public License'' may be
110 included in a translation approved by the Free Software Foundation
111 instead of in the original English.
116 @node Top, Summary, (dir), (dir)
117 @top GDB, the GNU symbolic debugger
119 This file describes GDB, the GNU symbolic debugger.
121 @c !!set edition, date, version
122 This is Edition 4.01, January 1992, for GDB Version 4.4.4.
126 * Summary:: Summary of GDB
127 * New Features:: New features since GDB version 3.5
128 * Sample Session:: A Sample GDB session
129 * Invocation:: Getting in and out of GDB
130 * Commands:: GDB commands
131 * Running:: Running programs under GDB
132 * Stopping:: Stopping and continuing
133 * Stack:: Examining the stack
134 * Source:: Examining source files
135 * Data:: Examining data
136 * Languages:: Using GDB with different languages
137 * Symbols:: Examining the symbol table
138 * Altering:: Altering execution
139 * GDB Files:: GDB's files
140 * Targets:: Specifying a debugging target
141 * Controlling GDB:: Controlling GDB
142 * Sequences:: Canned sequences of commands
143 * Emacs:: Using GDB under GNU Emacs
144 * GDB Bugs:: Reporting bugs in GDB
146 * Installing GDB:: Installing GDB
147 * Copying:: GNU GENERAL PUBLIC LICENSE
150 --- The Detailed Node Listing ---
154 * Free Software:: Free Software
155 * Contributors:: Contributors to GDB
157 Getting In and Out of GDB
159 * Invoking GDB:: Starting GDB
160 * Leaving GDB:: Leaving GDB
161 * Shell Commands:: Shell Commands
165 * File Options:: Choosing Files
166 * Mode Options:: Choosing Modes
170 * Command Syntax:: Command Syntax
171 * Help:: Getting Help
173 Running Programs Under GDB
175 * Compilation:: Compiling for Debugging
176 * Starting:: Starting your Program
177 * Arguments:: Your Program's Arguments
178 * Environment:: Your Program's Environment
179 * Working Directory:: Your Program's Working Directory
180 * Input/Output:: Your Program's Input and Output
181 * Attach:: Debugging an Already-Running Process
182 * Kill Process:: Killing the Child Process
184 Stopping and Continuing
186 * Breakpoints:: Breakpoints, Watchpoints, and Exceptions
187 * Continuing and Stepping:: Resuming Execution
190 Breakpoints, Watchpoints, and Exceptions
192 * Set Breaks:: Setting Breakpoints
193 * Set Watchpoints:: Setting Watchpoints
194 * Exception Handling:: Breakpoints and Exceptions
195 * Delete Breaks:: Deleting Breakpoints
196 * Disabling:: Disabling Breakpoints
197 * Conditions:: Break Conditions
198 * Break Commands:: Breakpoint Command Lists
199 * Breakpoint Menus:: Breakpoint Menus
200 * Error in Breakpoints:: ``Cannot insert breakpoints''
204 * Frames:: Stack Frames
205 * Backtrace:: Backtraces
206 * Selection:: Selecting a Frame
207 * Frame Info:: Information on a Frame
209 Examining Source Files
211 * List:: Printing Source Lines
212 * Search:: Searching Source Files
213 * Source Path:: Specifying Source Directories
214 * Machine Code:: Source and Machine Code
218 * Expressions:: Expressions
219 * Variables:: Program Variables
220 * Arrays:: Artificial Arrays
221 * Output formats:: Output formats
222 * Memory:: Examining Memory
223 * Auto Display:: Automatic Display
224 * Print Settings:: Print Settings
225 * Value History:: Value History
226 * Convenience Vars:: Convenience Variables
227 * Registers:: Registers
228 * Floating Point Hardware:: Floating Point Hardware
230 Using GDB with Different Languages
232 * Setting:: Switching between source languages
233 * Show:: Displaying the language
234 * Checks:: Type and Range checks
235 * Support:: Supported languages
237 Switching between source languages
239 * Manually:: Setting the working language manually
240 * Automatically:: Having GDB infer the source language
242 Type and range Checking
244 * Type Checking:: An overview of type checking
245 * Range Checking:: An overview of range checking
250 * Modula-2:: Modula-2
254 * C Operators:: C and C++ Operators
255 * C Constants:: C and C++ Constants
256 * Cplusplus expressions:: C++ Expressions
257 * C Defaults:: Default settings for C and C++
258 * C Checks:: C and C++ Type and Range Checks
259 * Debugging C:: GDB and C
260 * Debugging C plus plus:: Special features for C++
264 * M2 Operators:: Built-in operators
265 * Built-In Func/Proc:: Built-in Functions and Procedures
266 * M2 Constants:: Modula-2 Constants
267 * M2 Defaults:: Default settings for Modula-2
268 * Deviations:: Deviations from standard Modula-2
269 * M2 Checks:: Modula-2 Type and Range Checks
270 * M2 Scope:: The scope operators @code{::} and @code{.}
271 * GDB/M2:: GDB and Modula-2
275 * Assignment:: Assignment to Variables
276 * Jumping:: Continuing at a Different Address
277 * Signaling:: Giving your program a Signal
278 * Returning:: Returning from a Function
279 * Calling:: Calling your Program's Functions
280 * Patching:: Patching your Program
284 * Files:: Commands to Specify Files
285 * Symbol Errors:: Errors Reading Symbol Files
287 Specifying a Debugging Target
289 * Active Targets:: Active Targets
290 * Target Commands:: Commands for Managing Targets
291 * Remote:: Remote Debugging
295 * i960-Nindy Remote:: GDB with a Remote i960 (Nindy)
296 * EB29K Remote:: GDB with a Remote EB29K
297 * VxWorks Remote:: GDB and VxWorks
299 GDB with a Remote i960 (Nindy)
301 * Nindy Startup:: Startup with Nindy
302 * Nindy Options:: Options for Nindy
303 * Nindy reset:: Nindy Reset Command
305 GDB with a Remote EB29K
307 * Comms (EB29K):: Communications Setup
308 * gdb-EB29K:: EB29K cross-debugging
309 * Remote Log:: Remote Log
313 * VxWorks connection:: Connecting to VxWorks
314 * VxWorks download:: VxWorks Download
315 * VxWorks attach:: Running Tasks
320 * Editing:: Command Editing
321 * History:: Command History
322 * Screen Size:: Screen Size
324 * Messages/Warnings:: Optional Warnings and Messages
326 Canned Sequences of Commands
328 * Define:: User-Defined Commands
329 * Command Files:: Command Files
330 * Output:: Commands for Controlled Output
332 Reporting Bugs in GDB
334 * Bug Criteria:: Have You Found a Bug?
335 * Bug Reporting:: How to Report Bugs
339 * Separate Objdir:: Compiling GDB in another directory
340 * Config Names:: Specifying names for hosts and targets
341 * configure Options:: Summary of options for configure
342 * Formatting Documentation:: How to format and print GDB documentation
345 @node Summary, New Features, Top, Top
346 @unnumbered Summary of GDB
348 The purpose of a debugger such as GDB is to allow you to see what is
349 going on ``inside'' another program while it executes---or what another
350 program was doing at the moment it crashed.
352 GDB can do four main kinds of things (plus other things in support of
353 these) to help you catch bugs in the act:
357 Start your program, specifying anything that might affect its behavior.
360 Make your program stop on specified conditions.
363 Examine what has happened, when your program has stopped.
366 Change things in your program, so you can experiment with correcting the
367 effects of one bug and go on to learn about another.
370 You can use GDB to debug programs written in C, C++, and Modula-2.
371 Fortran support will be added when a GNU Fortran compiler is ready.
374 * Free Software:: Free Software
375 * Contributors:: Contributors to GDB
378 @node Free Software, Contributors, Summary, Summary
379 @unnumberedsec Free Software
381 GDB is @dfn{free software}, protected by the GNU General Public License
382 (GPL). The GPL gives you the freedom to copy or adapt a licensed
383 program---but every person getting a copy also gets with it the
384 freedom to modify that copy (which means that they must get access to
385 the source code), and the freedom to distribute further copies.
386 Typical software companies use copyrights to limit your freedoms; the
387 Free Software Foundation uses the GPL to preserve these freedoms.
389 Fundamentally, the General Public License is a license which says that
390 you have these freedoms and that you cannot take these freedoms away
393 For full details, @pxref{Copying, ,GNU GENERAL PUBLIC LICENSE}.
395 @node Contributors, , Free Software, Summary
396 @unnumberedsec Contributors to GDB
398 Richard Stallman was the original author of GDB, and of many other GNU
399 programs. Many others have contributed to its development. This
400 section attempts to credit major contributors. One of the virtues of
401 free software is that everyone is free to contribute to it; with
402 regret, we cannot actually acknowledge everyone here. The file
403 @file{ChangeLog} in the GDB distribution approximates a blow-by-blow
406 Changes much prior to version 2.0 are lost in the mists of time.
409 @emph{Plea:} Additions to this section are particularly welcome. If you
410 or your friends (or enemies; let's be evenhanded) have been unfairly
411 omitted from this list, we would like to add your names!
414 So that they may not regard their long labor as thankless, we
415 particularly thank those who shepherded GDB through major releases: Stu
416 Grossman and John Gilmore (release 4.4), John Gilmore (releases 4.3, 4.2,
417 4.1, 4.0, and 3.9); Jim Kingdon (releases 3.5, 3.4, 3.3); and Randy
418 Smith (releases 3.2, 3.1, 3.0). As major maintainer of GDB for some
419 period, each contributed significantly to the structure, stability, and
420 capabilities of the entire debugger.
422 Richard Stallman, assisted at various times by Pete TerMaat, Chris
423 Hanson, and Richard Mlynarik, handled releases through 2.8.
425 Michael Tiemann is the author of most of the GNU C++ support in GDB,
426 with significant additional contributions from Per Bothner. James
427 Clark wrote the GNU C++ demangler. Early work on C++ was by Peter
428 TerMaat (who also did much general update work leading to release 3.0).
430 GDB 4 uses the BFD subroutine library to examine multiple
431 object-file formats; BFD was a joint project of David V.
432 Henkel-Wallace, Rich Pixley, Steve Chamberlain, and John Gilmore.
434 David Johnson wrote the original COFF support; Pace Willison did
435 the original support for encapsulated COFF.
437 Adam de Boor and Bradley Davis contributed the ISI Optimum V support.
438 Per Bothner, Noboyuki Hikichi, and Alessandro Forin contributed MIPS
439 support. Jean-Daniel Fekete contributed Sun 386i support. Chris
440 Hanson improved the HP9000 support. Noboyuki Hikichi and Tomoyuki
441 Hasei contributed Sony/News OS 3 support. David Johnson contributed
442 Encore Umax support. Jyrki Kuoppala contributed Altos 3068 support.
443 Keith Packard contributed NS32K support. Doug Rabson contributed
444 Acorn Risc Machine support. Chris Smith contributed Convex support
445 (and Fortran debugging). Jonathan Stone contributed Pyramid support.
446 Michael Tiemann contributed SPARC support. Tim Tucker contributed
447 support for the Gould NP1 and Gould Powernode. Pace Willison
448 contributed Intel 386 support. Jay Vosburgh contributed Symmetry
451 Rich Schaefer and Peter Schauer helped with support of SunOS shared
454 Jay Fenlason and Roland McGrath ensured that GDB and GAS agree about
455 several machine instruction sets.
457 Patrick Duval, Ted Goldstein, Vikram Koka and Glenn Engel helped
458 develop remote debugging. Intel Corporation and Wind River Systems
459 contributed remote debugging modules for their products.
461 Brian Fox is the author of the readline libraries providing
462 command-line editing and command history.
464 Andrew Beers of SUNY Buffalo wrote the language-switching code and
465 the Modula-2 support, and contributed the Languages chapter of this
468 @node New Features, Sample Session, Summary, Top
469 @unnumbered New Features since GDB version 3.5
473 Using the new command @code{target}, you can select at runtime whether
474 you are debugging local files, local processes, standalone systems over
475 a serial port, realtime systems over a TCP/IP connection, etc. The
476 command @code{load} can download programs into a remote system. Serial
477 stubs are available for Motorola 680x0 and Intel 80386 remote systems;
478 GDB also supports debugging realtime processes running under
479 VxWorks, using SunRPC Remote Procedure Calls over TCP/IP to talk to a
480 debugger stub on the target system. Internally, GDB now uses a
481 function vector to mediate access to different targets; if you need to
482 add your own support for a remote protocol, this makes it much easier.
485 GDB now sports watchpoints as well as breakpoints. You can use a
486 watchpoint to stop execution whenever the value of an expression
487 changes, without having to predict a particular place in your program
488 where this may happen.
491 Commands that issue wide output now insert newlines at places designed
492 to make the output more readable.
494 @item Object Code Formats
495 GDB uses a new library called the Binary File Descriptor (BFD)
496 Library to permit it to switch dynamically, without reconfiguration or
497 recompilation, between different object-file formats. Formats currently
498 supported are COFF, a.out, and the Intel 960 b.out; files may be read as
499 .o's, archive libraries, or core dumps. BFD is available as a
500 subroutine library so that other programs may take advantage of it, and
501 the other GNU binary utilities are being converted to use it.
503 @item Configuration and Ports
504 Compile-time configuration (to select a particular architecture and
505 operating system) is much easier. The script @code{configure} now
506 allows you to configure GDB as either a native debugger or a
507 cross-debugger. @xref{Installing GDB}, for details on how to
508 configure and on what architectures are now available.
511 The user interface to GDB's control variables has been simplified
512 and consolidated in two commands, @code{set} and @code{show}. Output
513 lines are now broken at readable places, rather than overflowing onto
514 the next line. You can suppress output of machine-level addresses,
515 displaying only source language information.
518 GDB now supports C++ multiple inheritance (if used with a GCC
519 version 2 compiler), and also has limited support for C++ exception
520 handling, with the commands @code{catch} and @code{info catch}: GDB
521 can break when an exception is raised, before the stack is peeled back
522 to the exception handler's context.
525 GDB now has preliminary support for the GNU Modula-2 compiler,
526 currently under development at the State University of New York at
527 Buffalo. Coordinated development of both GDB and the GNU Modula-2
528 compiler will continue into 1992. Other Modula-2 compilers are
529 currently not supported, and attempting to debug programs compiled with
530 them will likely result in an error as the symbol table of the
531 executable is read in.
533 @item Command Rationalization
534 Many GDB commands have been renamed to make them easier to remember
535 and use. In particular, the subcommands of @code{info} and
536 @code{show}/@code{set} are grouped to make the former refer to the state
537 of your program, and the latter refer to the state of GDB itself.
538 @xref{Renamed Commands}, for details on what commands were renamed.
540 @item Shared Libraries
541 GDB 4 can debug programs and core files that use SunOS shared
545 GDB 4 has a reference card. @xref{Formatting Documentation} for
546 instructions on printing it.
548 @item Work in Progress
549 Kernel debugging for BSD and Mach systems; Tahoe and HPPA architecture
553 @node Sample Session, Invocation, New Features, Top
554 @chapter A Sample GDB Session
556 You can use this manual at your leisure to read all about GDB.
557 However, a handful of commands are enough to get started using the
558 debugger. This chapter illustrates these commands.
561 In this sample session, we emphasize user input like this: @i{input},
562 to make it easier to pick out from the surrounding output.
565 @c FIXME: this example may not be appropriate for some configs, where
566 @c FIXME...primary interest is in remote use.
568 One of the preliminary versions of GNU @code{m4} (a generic macro
569 processor) exhibits the following bug: sometimes, when we change its
570 quote strings from the default, the commands used to capture one macro's
571 definition in another stop working. In the following short @code{m4}
572 session, we define a macro @code{foo} which expands to @code{0000}; we
573 then use the @code{m4} built-in @code{defn} to define @code{bar} as the
574 same thing. However, when we change the open quote string to
575 @code{<QUOTE>} and the close quote string to @code{<UNQUOTE>}, the same
576 procedure fails to define a new synonym @code{baz}:
585 @i{define(bar,defn(`foo'))}
589 @i{changequote(<QUOTE>,<UNQUOTE>)}
591 @i{define(baz,defn(<QUOTE>foo<UNQUOTE>))}
594 m4: End of input: 0: fatal error: EOF in string
598 Let's use GDB to try to see what's going on.
602 @c FIXME: this falsifies the exact text played out, to permit smallbook
603 @c FIXME... format to come out better.
604 GDB is free software and you are welcome to distribute copies
605 of it under certain conditions; type "show copying" to see
607 There is absolutely no warranty for GDB; type "show warranty"
609 GDB 4.4.4, Copyright 1992 Free Software Foundation, Inc...
614 GDB reads only enough symbol data to know where to find the rest when
615 needed; as a result, the first prompt comes up very quickly. We now
616 tell GDB to use a narrower display width than usual, so that examples
617 will fit in this manual.
620 (gdb) @i{set width 70}
624 Let's see how the @code{m4} built-in @code{changequote} works.
625 Having looked at the source, we know the relevant subroutine is
626 @code{m4_changequote}, so we set a breakpoint there with GDB's
627 @code{break} command.
630 (gdb) @i{break m4_changequote}
631 Breakpoint 1 at 0x62f4: file builtin.c, line 879.
635 Using the @code{run} command, we start @code{m4} running under GDB
636 control; as long as control does not reach the @code{m4_changequote}
637 subroutine, the program runs as usual:
641 Starting program: /work/Editorial/gdb/gnu/m4/m4
649 To trigger the breakpoint, we call @code{changequote}. GDB
650 suspends execution of @code{m4}, displaying information about the
651 context where it stops.
654 @i{changequote(<QUOTE>,<UNQUOTE>)}
656 Breakpoint 1, m4_changequote (argc=3, argv=0x33c70)
658 879 if (bad_argc(TOKEN_DATA_TEXT(argv[0]), argc, 1, 3))
662 Now we use the command @code{n} (@code{next}) to advance execution to
663 the next line of the current function.
667 882 set_quotes((argc >= 2) ? TOKEN_DATA_TEXT(argv[1])\
672 @code{set_quotes} looks like a promising subroutine. We can go into it
673 by using the command @code{s} (@code{step}) instead of @code{next}.
674 @code{step} goes to the next line to be executed in @emph{any}
675 subroutine, so it steps into @code{set_quotes}.
679 set_quotes (lq=0x34c78 "<QUOTE>", rq=0x34c88 "<UNQUOTE>")
681 530 if (lquote != def_lquote)
685 The display that shows the subroutine where @code{m4} is now
686 suspended (and its arguments) is called a stack frame display. It
687 shows a summary of the stack. We can use the @code{backtrace}
688 command (which can also be spelled @code{bt}), to see where we are
689 in the stack as a whole: the @code{backtrace} command displays a
690 stack frame for each active subroutine.
694 #0 set_quotes (lq=0x34c78 "<QUOTE>", rq=0x34c88 "<UNQUOTE>")
696 #1 0x6344 in m4_changequote (argc=3, argv=0x33c70)
698 #2 0x8174 in expand_macro (sym=0x33320) at macro.c:242
699 #3 0x7a88 in expand_token (obs=0x0, t=209696, td=0xf7fffa30)
701 #4 0x79dc in expand_input () at macro.c:40
702 #5 0x2930 in main (argc=0, argv=0xf7fffb20) at m4.c:195
706 Let's step through a few more lines to see what happens. The first two
707 times, we can use @samp{s}; the next two times we use @code{n} to avoid
708 falling into the @code{xstrdup} subroutine.
712 0x3b5c 532 if (rquote != def_rquote)
714 0x3b80 535 lquote = (lq == nil || *lq == '\0') ? \
715 def_lquote : xstrdup(lq);
717 536 rquote = (rq == nil || *rq == '\0') ? def_rquote\
720 538 len_lquote = strlen(rquote);
724 The last line displayed looks a little odd; let's examine the variables
725 @code{lquote} and @code{rquote} to see if they are in fact the new left
726 and right quotes we specified. We can use the command @code{p}
727 (@code{print}) to see their values.
731 $1 = 0x35d40 "<QUOTE>"
733 $2 = 0x35d50 "<UNQUOTE>"
737 @code{lquote} and @code{rquote} are indeed the new left and right quotes.
738 Let's look at some context; we can display ten lines of source
739 surrounding the current line, with the @code{l} (@code{list}) command.
745 535 lquote = (lq == nil || *lq == '\0') ? def_lquote\
747 536 rquote = (rq == nil || *rq == '\0') ? def_rquote\
750 538 len_lquote = strlen(rquote);
751 539 len_rquote = strlen(lquote);
758 Let's step past the two lines that set @code{len_lquote} and
759 @code{len_rquote}, and then examine the values of those variables.
763 539 len_rquote = strlen(lquote);
766 (gdb) @i{p len_lquote}
768 (gdb) @i{p len_rquote}
773 That certainly looks wrong, assuming @code{len_lquote} and
774 @code{len_rquote} are meant to be the lengths of @code{lquote} and
775 @code{rquote} respectively. Let's try setting them to better values.
776 We can use the @code{p} command for this, since it'll print the value of
777 any expression---and that expression can include subroutine calls and
781 (gdb) p @i{len_lquote=strlen(lquote)}
783 (gdb) p @i{len_rquote=strlen(rquote)}
788 Let's see if that fixes the problem of using the new quotes with the
789 @code{m4} built-in @code{defn}. We can allow @code{m4} to continue
790 executing with the @code{c} (@code{continue}) command, and then try the
791 example that caused trouble initially:
797 @i{define(baz,defn(<QUOTE>foo<UNQUOTE>))}
804 Success! The new quotes now work just as well as the default ones. The
805 problem seems to have been just the two typos defining the wrong
806 lengths. We'll let @code{m4} exit by giving it an EOF as input.
810 Program exited normally.
814 The message @samp{Program exited normally.} is from GDB; it
815 indicates @code{m4} has finished executing. We can end our GDB
816 session with the GDB @code{quit} command.
822 @node Invocation, Commands, Sample Session, Top
823 @chapter Getting In and Out of GDB
825 This chapter discusses how to start GDB, and how to get out of it.
826 (The essentials: type @samp{gdb} to start GDB, and type @kbd{quit}
827 or @kbd{C-d} to exit.)
830 * Invoking GDB:: Starting GDB
831 * Leaving GDB:: Leaving GDB
832 * Shell Commands:: Shell Commands
835 @node Invoking GDB, Leaving GDB, Invocation, Invocation
836 @section Starting GDB
838 Start GDB with the shell command @code{gdb}. Once it's running,
839 GDB reads commands from the terminal until you tell it to exit.
841 You can also run @code{gdb} with a variety of arguments and options,
842 to specify more of your debugging environment at the outset.
844 The command-line options described here are designed
845 to cover a variety of situations; in some environments, some of these
846 options may effectively be unavailable.
849 The most usual way to start GDB is with one argument or two,
850 specifying an executable program as the argument:
857 You can also start with both an executable program and a core file
861 gdb @var{program} @var{core}
864 You can, instead, specify a process ID as a second argument, if you want
865 to debug a running process:
868 gdb @var{program} 1234
872 would attach GDB to process @code{1234} (unless you also have a file
873 named @file{1234}; GDB does check for a core file first).
875 Taking advantage of the second command-line argument requires a fairly
876 complete operating system; when you use GDB as a remote debugger
877 attached to a bare board, there may not be any notion of ``process'',
878 and there is often no way to get a core dump.
881 You can further control how GDB starts up by using command-line
882 options. GDB itself can remind you of the options available.
892 to display all available options and briefly describe their use
893 (@samp{gdb -h} is a shorter equivalent).
895 All options and command line arguments you give are processed
896 in sequential order. The order makes a difference when the
897 @samp{-x} option is used.
900 * File Options:: Choosing Files
901 * Mode Options:: Choosing Modes
904 @node File Options, Mode Options, Invoking GDB, Invoking GDB
905 @subsection Choosing Files
907 When GDB starts, it reads any arguments other than options as
908 specifying an executable file and core file (or process ID). This is
909 the same as if the arguments were specified by the @samp{-se} and
910 @samp{-c} options respectively. (GDB reads the first argument
911 that does not have an associated option flag as equivalent to the
912 @samp{-se} option followed by that argument; and the second argument
913 that does not have an associated option flag, if any, as equivalent to
914 the @samp{-c} option followed by that argument.)
916 Many options have both long and short forms; both are shown in the
917 following list. GDB also recognizes the long forms if you truncate
918 them, so long as enough of the option is present to be unambiguous.
919 (If you prefer, you can flag option arguments with @samp{--} rather
920 than @samp{-}, though we illustrate the more usual convention.)
923 @item -symbols=@var{file}
925 Read symbol table from file @var{file}.
927 @item -exec=@var{file}
929 Use file @var{file} as the executable file to execute when
930 appropriate, and for examining pure data in conjunction with a core
934 Read symbol table from file @var{file} and use it as the executable
937 @item -core=@var{file}
939 Use file @var{file} as a core dump to examine.
941 @item -command=@var{file}
943 Execute GDB commands from file @var{file}. @xref{Command Files}.
945 @item -directory=@var{directory}
946 @itemx -d @var{directory}
947 Add @var{directory} to the path to search for source files.
950 @node Mode Options, , File Options, Invoking GDB
951 @subsection Choosing Modes
953 You can run GDB in various alternative modes---for example, in
954 batch mode or quiet mode.
959 Do not execute commands from any @file{.gdbinit} initialization files.
960 Normally, the commands in these files are executed after all the
961 command options and arguments have been processed.
962 @xref{Command Files}.
966 ``Quiet''. Do not print the introductory and copyright messages. These
967 messages are also suppressed in batch mode.
970 Run in batch mode. Exit with status @code{0} after processing all the command
971 files specified with @samp{-x} (and @file{.gdbinit}, if not inhibited).
972 Exit with nonzero status if an error occurs in executing the GDB
973 commands in the command files.
975 Batch mode may be useful for running GDB as a filter, for example to
976 download and run a program on another computer; in order to make this
977 more useful, the message
980 Program exited normally.
984 (which is ordinarily issued whenever a program running under GDB control
985 terminates) is not issued when running in batch mode.
987 @item -cd=@var{directory}
988 Run GDB using @var{directory} as its working directory,
989 instead of the current directory.
993 Emacs sets this option when it runs GDB as a subprocess. It tells GDB
994 to output the full file name and line number in a standard,
995 recognizable fashion each time a stack frame is displayed (which
996 includes each time your program stops). This recognizable format looks
997 like two @samp{\032} characters, followed by the file name, line number
998 and character position separated by colons, and a newline. The
999 Emacs-to-GDB interface program uses the two @samp{\032} characters as
1000 a signal to display the source code for the frame.
1003 Set the line speed (baud rate or bits per second) of any serial
1004 interface used by GDB for remote debugging.
1006 @item -tty=@var{device}
1007 Run using @var{device} for your program's standard input and output.
1008 @c FIXME: kingdon thinks there is more to -tty. Investigate.
1011 @node Leaving GDB, Shell Commands, Invoking GDB, Invocation
1012 @section Leaving GDB
1019 To exit GDB, use the @code{quit} command (abbreviated @code{q}), or type
1020 an end-of-file character (usually @kbd{C-d}).
1024 An interrupt (often @kbd{C-c}) will not exit from GDB, but rather
1025 will terminate the action of any GDB command that is in progress and
1026 return to GDB command level. It is safe to type the interrupt
1027 character at any time because GDB does not allow it to take effect
1028 until a time when it is safe.
1030 If you have been using GDB to control an attached process or device, you
1031 can release it with the @code{detach} command; @pxref{Attach,
1032 ,Debugging an Already-Running Process}..
1034 @node Shell Commands, , Leaving GDB, Invocation
1035 @section Shell Commands
1037 If you need to execute occasional shell commands during your
1038 debugging session, there is no need to leave or suspend GDB; you can
1039 just use the @code{shell} command.
1042 @item shell @var{command string}
1044 @cindex shell escape
1045 Directs GDB to invoke an inferior shell to execute @var{command
1046 string}. If it exists, the environment variable @code{SHELL} is used
1047 for the name of the shell to run. Otherwise GDB uses
1051 The utility @code{make} is often needed in development environments.
1052 You do not have to use the @code{shell} command for this purpose in GDB:
1055 @item make @var{make-args}
1057 @cindex calling make
1058 Causes GDB to execute an inferior @code{make} program with the specified
1059 arguments. This is equivalent to @samp{shell make @var{make-args}}.
1062 @node Commands, Running, Invocation, Top
1063 @chapter GDB Commands
1065 You can abbreviate GDB command if that abbreviation is unambiguous;
1066 and you can repeat certain GDB commands by typing just @key{RET}.
1069 * Command Syntax:: Command Syntax
1070 * Help:: Getting Help
1073 @node Command Syntax, Help, Commands, Commands
1074 @section Command Syntax
1076 A GDB command is a single line of input. There is no limit on how long
1077 it can be. It starts with a command name, which is followed by arguments
1078 whose meaning depends on the command name. For example, the command
1079 @code{step} accepts an argument which is the number of times to step,
1080 as in @samp{step 5}. You can also use the @code{step} command with
1081 no arguments. Some command names do not allow any arguments.
1083 @cindex abbreviation
1084 GDB command names may always be truncated if that abbreviation is
1085 unambiguous. Other possible command abbreviations are listed in the
1086 documentation for individual commands. In some cases, even ambiguous
1087 abbreviations are allowed; for example, @code{s} is specially defined as
1088 equivalent to @code{step} even though there are other commands whose
1089 names start with @code{s}. You can test abbreviations by using them as
1090 arguments to the @code{help} command.
1092 @cindex repeating commands
1094 A blank line as input to GDB (typing just @key{RET}) means to
1095 repeat the previous command. Certain commands (for example, @code{run})
1096 will not repeat this way; these are commands for which unintentional
1097 repetition might cause trouble and which you are unlikely to want to
1100 The @code{list} and @code{x} commands, when you repeat them with
1101 @key{RET}, construct new arguments rather than repeating
1102 exactly as typed. This permits easy scanning of source or memory.
1104 GDB can also use @key{RET} in another way: to partition lengthy
1105 output, in a way similar to the common utility @code{more}
1106 (@pxref{Screen Size}). Since it is easy to press one @key{RET} too many
1107 in this situation, GDB disables command repetition after any command
1108 that generates this sort of display.
1112 A line of input starting with @kbd{#} is a comment; it does nothing.
1113 This is useful mainly in command files (@pxref{Command Files}).
1115 @node Help, , Command Syntax, Commands
1116 @section Getting Help
1117 @cindex online documentation
1120 You can always ask GDB itself for information on its commands, using the
1121 command @code{help}.
1127 You can use @code{help} (abbreviated @code{h}) with no arguments to
1128 display a short list of named classes of commands:
1132 List of classes of commands:
1134 running -- Running the program
1135 stack -- Examining the stack
1136 data -- Examining data
1137 breakpoints -- Making program stop at certain points
1138 files -- Specifying and examining files
1139 status -- Status inquiries
1140 support -- Support facilities
1141 user-defined -- User-defined commands
1142 aliases -- Aliases of other commands
1143 obscure -- Obscure features
1145 Type "help" followed by a class name for a list of
1146 commands in that class.
1147 Type "help" followed by command name for full
1149 Command name abbreviations are allowed if unambiguous.
1153 @item help @var{class}
1154 Using one of the general help classes as an argument, you can get a
1155 list of the individual commands in that class. For example, here is the
1156 help display for the class @code{status}:
1164 show -- Generic command for showing things set with "set"
1165 info -- Generic command for printing status
1167 Type "help" followed by command name for full
1169 Command name abbreviations are allowed if unambiguous.
1173 @item help @var{command}
1174 With a command name as @code{help} argument, GDB will display a
1175 short paragraph on how to use that command.
1178 In addition to @code{help}, you can use the GDB commands @code{info}
1179 and @code{show} to inquire about the state of your program, or the state
1180 of GDB itself. Each command supports many topics of inquiry; this
1181 manual introduces each of them in the appropriate context. The listings
1182 under @code{info} and under @code{show} in the Index point to
1183 all the sub-commands. @xref{Index}.
1190 This command (abbreviated @code{i}) is for describing the state of your
1191 program; for example, it can list the arguments given to your program
1192 (@code{info args}), the registers currently in use (@code{info
1193 registers}), or the breakpoints you have set (@code{info breakpoints}).
1194 You can get a complete list of the @code{info} sub-commands with
1195 @w{@code{help info}}.
1199 In contrast, @code{show} is for describing the state of GDB itself.
1200 You can change most of the things you can @code{show}, by using the
1201 related command @code{set}; for example, you can control what number
1202 system is used for displays with @code{set radix}, or simply inquire
1203 which is currently in use with @code{show radix}.
1206 To display all the settable parameters and their current
1207 values, you can use @code{show} with no arguments; you may also use
1208 @code{info set}. Both commands produce the same display.
1209 @c FIXME: "info set" violates the rule that "info" is for state of
1210 @c FIXME...program. Ck w/ GNU: "info set" to be called something else,
1211 @c FIXME...or change desc of rule---eg "state of prog and debugging session"?
1215 Here are three miscellaneous @code{show} subcommands, all of which are
1216 exceptional in lacking corresponding @code{set} commands:
1219 @kindex show version
1220 @cindex version number
1222 Show what version of GDB is running. You should include this
1223 information in GDB bug-reports. If multiple versions of GDB are in
1224 use at your site, you may occasionally want to make sure what version
1225 of GDB you are running; as GDB evolves, new commands are introduced,
1226 and old ones may wither away. The version number is also announced
1227 when you start GDB with no arguments.
1229 @kindex show copying
1231 Display information about permission for copying GDB.
1233 @kindex show warranty
1235 Display the GNU ``NO WARRANTY'' statement.
1238 @node Running, Stopping, Commands, Top
1239 @chapter Running Programs Under GDB
1241 To debug a program, you must run it under GDB.
1244 * Compilation:: Compiling for Debugging
1245 * Starting:: Starting your Program
1246 * Arguments:: Your Program's Arguments
1247 * Environment:: Your Program's Environment
1248 * Working Directory:: Your Program's Working Directory
1249 * Input/Output:: Your Program's Input and Output
1250 * Attach:: Debugging an Already-Running Process
1251 * Kill Process:: Killing the Child Process
1254 @node Compilation, Starting, Running, Running
1255 @section Compiling for Debugging
1257 In order to debug a program effectively, you need to generate
1258 debugging information when you compile it. This debugging information
1259 is stored in the object file; it describes the data type of each
1260 variable or function and the correspondence between source line numbers
1261 and addresses in the executable code.
1263 To request debugging information, specify the @samp{-g} option when you run
1266 Many C compilers are unable to handle the @samp{-g} and @samp{-O}
1267 options together. Using those compilers, you cannot generate optimized
1268 executables containing debugging information.
1270 gcc, the GNU C compiler, supports @samp{-g} with or without
1271 @samp{-O}, making it possible to debug optimized code. We recommend
1272 that you @emph{always} use @samp{-g} whenever you compile a program.
1273 You may think your program is correct, but there is no sense in pushing
1276 Some things do not work as well with @samp{-g -O} as with just
1277 @samp{-g}, particularly on machines with instruction scheduling. If in
1278 doubt, recompile with @samp{-g} alone, and if this fixes the problem,
1279 please report it as a bug (including a test case!).
1281 Older versions of the GNU C compiler permitted a variant option
1282 @w{@samp{-gg}} for debugging information. GDB no longer supports this
1283 format; if your GNU C compiler has this option, do not use it.
1286 @comment As far as I know, there are no cases in which GDB will
1287 @comment produce strange output in this case. (but no promises).
1288 If your program includes archives made with the @code{ar} program, and
1289 if the object files used as input to @code{ar} were compiled without the
1290 @samp{-g} option and have names longer than 15 characters, GDB will get
1291 confused reading your program's symbol table. No error message will be
1292 given, but GDB may behave strangely. The reason for this problem is a
1293 deficiency in the Unix archive file format, which cannot represent file
1294 names longer than 15 characters.
1296 To avoid this problem, compile the archive members with the @samp{-g}
1297 option or use shorter file names. Alternatively, use a version of GNU
1298 @code{ar} dated more recently than August 1989.
1301 @node Starting, Arguments, Compilation, Running
1302 @section Starting your Program
1310 Use the @code{run} command to start your program under GDB. You must
1311 first specify the program name
1314 GDB (@pxref{Invocation, ,Getting In and Out of GDB}), or by using the
1315 @code{file} or @code{exec-file} command (@pxref{Files, ,Commands to
1320 If you are running your program in an execution environment that
1321 supports processes, @code{run} creates an inferior process and makes
1322 that process run your program. (In environments without processes,
1323 @code{run} jumps to the start of your program.)
1325 The execution of a program is affected by certain information it
1326 receives from its superior. GDB provides ways to specify this
1327 information, which you must do @i{before} starting your program. (You
1328 can change it after starting your program, but such changes will only affect
1329 your program the next time you start it.) This information may be
1330 divided into four categories:
1333 @item The @i{arguments.}
1334 Specify the arguments to give your program as the arguments of the
1335 @code{run} command. If a shell is available on your target, the shell
1336 is used to pass the arguments, so that you may use normal conventions
1337 (such as wildcard expansion or variable substitution) in describing
1338 the arguments. In Unix systems, you can control which shell is used
1339 with the @code{SHELL} environment variable. @xref{Arguments, ,Your
1340 Program's Arguments}.
1342 @item The @i{environment.}
1343 Your program normally inherits its environment from GDB, but you can
1344 use the GDB commands @code{set environment} and @code{unset
1345 environment} to change parts of the environment that will be given to
1346 your program. @xref{Environment, ,Your Program's Environment}.
1348 @item The @i{working directory.}
1349 Your program inherits its working directory from GDB. You can set
1350 GDB's working directory with the @code{cd} command in GDB.
1351 @xref{Working Directory, ,Your Program's Working Directory}.
1353 @item The @i{standard input and output.}
1354 Your program normally uses the same device for standard input and
1355 standard output as GDB is using. You can redirect input and output
1356 in the @code{run} command line, or you can use the @code{tty} command to
1357 set a different device for your program.
1358 @xref{Input/Output, ,Your Program's Input and Output}.
1361 @emph{Warning:} While input and output redirection work, you cannot use
1362 pipes to pass the output of the program you are debugging to another
1363 program; if you attempt this, GDB is likely to wind up debugging the
1367 @c FIXME: Rewrite following paragraph, especially its third sentence.
1368 When you issue the @code{run} command, your program begins to execute
1369 immediately. @xref{Stopping, ,Stopping and Continuing}, for
1370 discussion of how to arrange for your program to stop. Once your
1371 program has been started by the @code{run} command (and then stopped),
1372 you may evaluate expressions that involve calls to functions in your
1373 program, using the @code{print} or @code{call} commands. @xref{Data,
1376 If the modification time of your symbol file has changed since the
1377 last time GDB read its symbols, GDB will discard its symbol table and
1378 re-read it. When it does this, GDB tries to retain your current
1381 @node Arguments, Environment, Starting, Running
1382 @section Your Program's Arguments
1384 @cindex arguments (to your program)
1385 The arguments to your program can be specified by the arguments of the
1386 @code{run} command. They are passed to a shell, which expands wildcard
1387 characters and performs redirection of I/O, and thence to your program.
1388 GDB uses the shell indicated by your environment variable
1389 @code{SHELL} if it exists; otherwise, GDB uses @code{/bin/sh}.
1391 @code{run} with no arguments uses the same arguments used by the previous
1392 @code{run}, or those set by the @code{set args} command.
1397 Specify the arguments to be used the next time your program is run. If
1398 @code{set args} has no arguments, @code{run} will execute your program
1399 with no arguments. Once you have run your program with arguments,
1400 using @code{set args} before the next @code{run} is the only way to run
1401 it again without arguments.
1405 Show the arguments to give your program when it is started.
1408 @node Environment, Working Directory, Arguments, Running
1409 @section Your Program's Environment
1411 @cindex environment (of your program)
1412 The @dfn{environment} consists of a set of environment variables and
1413 their values. Environment variables conventionally record such things as
1414 your user name, your home directory, your terminal type, and your search
1415 path for programs to run. Usually you set up environment variables with
1416 the shell and they are inherited by all the other programs you run. When
1417 debugging, it can be useful to try running your program with a modified
1418 environment without having to start GDB over again.
1421 @item path @var{directory}
1423 Add @var{directory} to the front of the @code{PATH} environment variable
1424 (the search path for executables), for both GDB and your program.
1425 You may specify several directory names, separated by @samp{:} or
1426 whitespace. If @var{directory} is already in the path, it is moved to
1427 the front, so it will be searched sooner.
1429 You can use the string @samp{$cwd} to refer to whatever is the current
1430 working directory at the time GDB searches the path. If you use
1431 @samp{.} instead, it refers to the directory where you executed the
1432 @code{path} command. GDB fills in the current path where needed in
1433 the @var{directory} argument, before adding it to the search path.
1434 @c 'path' is explicitly nonrepeatable, but RMS points out it is silly to
1435 @c document that, since repeating it would be a no-op.
1439 Display the list of search paths for executables (the @code{PATH}
1440 environment variable).
1442 @item show environment @r{[}@var{varname}@r{]}
1443 @kindex show environment
1444 Print the value of environment variable @var{varname} to be given to
1445 your program when it starts. If you do not supply @var{varname},
1446 print the names and values of all environment variables to be given to
1447 your program. You can abbreviate @code{environment} as @code{env}.
1449 @item set environment @var{varname} @r{[}=@r{]} @var{value}
1450 @kindex set environment
1451 Sets environment variable @var{varname} to @var{value}. The value
1452 changes for your program only, not for GDB itself. @var{value} may
1453 be any string; the values of environment variables are just strings, and
1454 any interpretation is supplied by your program itself. The @var{value}
1455 parameter is optional; if it is eliminated, the variable is set to a
1457 @c "any string" here does not include leading, trailing
1458 @c blanks. Gnu asks: does anyone care?
1460 For example, this command:
1467 tells a Unix program, when subsequently run, that its user is named
1468 @samp{foo}. (The spaces around @samp{=} are used for clarity here; they
1469 are not actually required.)
1471 @item unset environment @var{varname}
1472 @kindex unset environment
1473 Remove variable @var{varname} from the environment to be passed to your
1474 program. This is different from @samp{set env @var{varname} =};
1475 @code{unset environment} removes the variable from the environment,
1476 rather than assigning it an empty value.
1479 @node Working Directory, Input/Output, Environment, Running
1480 @section Your Program's Working Directory
1482 @cindex working directory (of your program)
1483 Each time you start your program with @code{run}, it inherits its
1484 working directory from the current working directory of GDB. GDB's
1485 working directory is initially whatever it inherited from its parent
1486 process (typically the shell), but you can specify a new working
1487 directory in GDB with the @code{cd} command.
1489 The GDB working directory also serves as a default for the commands
1490 that specify files for GDB to operate on. @xref{Files, ,Commands to
1494 @item cd @var{directory}
1496 Set GDB's working directory to @var{directory}.
1500 Print GDB's working directory.
1503 @node Input/Output, Attach, Working Directory, Running
1504 @section Your Program's Input and Output
1509 By default, the program you run under GDB does input and output to
1510 the same terminal that GDB uses. GDB switches the terminal to
1511 its own terminal modes to interact with you, but it records the terminal
1512 modes your program was using and switches back to them when you continue
1513 running your program.
1517 @kindex info terminal
1518 Displays GDB's recorded information about the terminal modes your
1522 You can redirect your program's input and/or output using shell
1523 redirection with the @code{run} command. For example,
1530 starts your program, diverting its output to the file @file{outfile}.
1533 @cindex controlling terminal
1534 Another way to specify where your program should do input and output is
1535 with the @code{tty} command. This command accepts a file name as
1536 argument, and causes this file to be the default for future @code{run}
1537 commands. It also resets the controlling terminal for the child
1538 process, for future @code{run} commands. For example,
1545 directs that processes started with subsequent @code{run} commands
1546 default to do input and output on the terminal @file{/dev/ttyb} and have
1547 that as their controlling terminal.
1549 An explicit redirection in @code{run} overrides the @code{tty} command's
1550 effect on the input/output device, but not its effect on the controlling
1553 When you use the @code{tty} command or redirect input in the @code{run}
1554 command, only the input @emph{for your program} is affected. The input
1555 for GDB still comes from your terminal.
1557 @node Attach, Kill Process, Input/Output, Running
1558 @section Debugging an Already-Running Process
1563 @item attach @var{process-id}
1565 attaches to a running process---one that was started outside GDB.
1566 (@code{info files} will show your active targets.) The command takes as
1567 argument a process ID. The usual way to find out the process-id of
1568 a Unix process is with the @code{ps} utility, or with the @samp{jobs -l}
1571 @code{attach} will not repeat if you press @key{RET} a second time after
1572 executing the command.
1575 To use @code{attach}, you must be debugging in an environment which
1576 supports processes. You must also have permission to send the process a
1577 signal, and it must have the same effective user ID as the GDB
1580 When using @code{attach}, you should first use the @code{file} command
1581 to specify the program running in the process and load its symbol table.
1582 @xref{Files, ,Commands to Specify Files}.
1584 The first thing GDB does after arranging to debug the specified
1585 process is to stop it. You can examine and modify an attached process
1586 with all the GDB commands that are ordinarily available when you start
1587 processes with @code{run}. You can insert breakpoints; you can step and
1588 continue; you can modify storage. If you would rather the process
1589 continue running, you may use the @code{continue} command after
1590 attaching GDB to the process.
1595 When you have finished debugging the attached process, you can use the
1596 @code{detach} command to release it from GDB's control. Detaching
1597 the process continues its execution. After the @code{detach} command,
1598 that process and GDB become completely independent once more, and you
1599 are ready to @code{attach} another process or start one with @code{run}.
1600 @code{detach} will not repeat if you press @key{RET} again after
1601 executing the command.
1604 If you exit GDB or use the @code{run} command while you have an attached
1605 process, you kill that process. By default, you will be asked for
1606 confirmation if you try to do either of these things; you can control
1607 whether or not you need to confirm by using the @code{set confirm} command
1608 (@pxref{Messages/Warnings, ,Optional Warnings and Messages}).
1610 @node Kill Process, , Attach, Running
1612 @section Killing the Child Process
1617 Kill the child process in which your program is running under GDB.
1620 This command is useful if you wish to debug a core dump instead of a
1621 running process. GDB ignores any core dump file while your program
1625 On some operating systems, a program cannot be executed outside GDB
1626 while you have breakpoints set on it inside GDB. You can use the
1627 @code{kill} command in this situation to permit running your program
1628 outside the debugger.
1630 The @code{kill} command is also useful if you wish to recompile and
1631 relink your program, since on many systems it is impossible to modify an
1632 executable file while it is running in a process. In this case, when you
1633 next type @code{run}, GDB will notice that the file has changed, and
1634 will re-read the symbol table (while trying to preserve your current
1635 breakpoint settings).
1637 @node Stopping, Stack, Running, Top
1638 @chapter Stopping and Continuing
1640 The principal purpose of using a debugger is so that you can stop your
1641 program before it terminates; or so that, if your program runs into
1642 trouble, you can investigate and find out why.
1644 Inside GDB, your program may stop for any of several reasons, such
1645 as a signal, a breakpoint, or reaching a new line after a GDB
1646 command such as @code{step}. You may then examine and change
1647 variables, set new breakpoints or remove old ones, and then continue
1648 execution. Usually, the messages shown by GDB provide ample
1649 explanation of the status of your program---but you can also explicitly
1650 request this information at any time.
1654 @kindex info program
1655 Display information about the status of your program: whether it is
1656 running or not, what process it is, and why it stopped.
1660 * Breakpoints:: Breakpoints, Watchpoints, and Exceptions
1661 * Continuing and Stepping:: Resuming Execution
1665 @node Breakpoints, Continuing and Stepping, Stopping, Stopping
1666 @section Breakpoints, Watchpoints, and Exceptions
1669 A @dfn{breakpoint} makes your program stop whenever a certain point in
1670 the program is reached. For each breakpoint, you can add various
1671 conditions to control in finer detail whether your program will stop.
1672 You can set breakpoints with the @code{break} command and its variants
1673 (@pxref{Set Breaks, ,Setting Breakpoints}), to specify the place where
1674 your program should stop by line number, function name or exact address
1675 in the program. In languages with exception handling (such as GNU
1676 C++), you can also set breakpoints where an exception is raised
1677 (@pxref{Exception Handling, ,Breakpoints and Exceptions}).
1680 A @dfn{watchpoint} is a special breakpoint that stops your program
1681 when the value of an expression changes. You must use a different
1682 command to set watchpoints (@pxref{Set Watchpoints, ,Setting
1683 Watchpoints}), but aside from that, you can manage a watchpoint like
1684 any other breakpoint: you enable, disable, and delete both breakpoints
1685 and watchpoints using the same commands.
1687 Each breakpoint or watchpoint is assigned a number when it is created;
1688 these numbers are successive integers starting with one. In many of the
1689 commands for controlling various features of breakpoints you use the
1690 breakpoint number to say which breakpoint you want to change. Each
1691 breakpoint may be @dfn{enabled} or @dfn{disabled}; if disabled, it has
1692 no effect on your program until you enable it again.
1695 * Set Breaks:: Setting Breakpoints
1696 * Set Watchpoints:: Setting Watchpoints
1697 * Exception Handling:: Breakpoints and Exceptions
1698 * Delete Breaks:: Deleting Breakpoints
1699 * Disabling:: Disabling Breakpoints
1700 * Conditions:: Break Conditions
1701 * Break Commands:: Breakpoint Command Lists
1702 * Breakpoint Menus:: Breakpoint Menus
1703 * Error in Breakpoints::
1706 @node Set Breaks, Set Watchpoints, Breakpoints, Breakpoints
1707 @subsection Setting Breakpoints
1709 @c FIXME LMB what does GDB do if no code on line of breakpt?
1710 @c consider in particular declaration with/without initialization.
1712 @c FIXME 2 is there stuff on this already? break at fun start, already init?
1716 Breakpoints are set with the @code{break} command (abbreviated @code{b}).
1718 You have several ways to say where the breakpoint should go.
1721 @item break @var{function}
1722 Set a breakpoint at entry to function @var{function}. When using source
1723 languages that permit overloading of symbols, such as C++,
1724 @var{function} may refer to more than one possible place to break.
1725 @xref{Breakpoint Menus}, for a discussion of that situation.
1727 @item break +@var{offset}
1728 @itemx break -@var{offset}
1729 Set a breakpoint some number of lines forward or back from the position
1730 at which execution stopped in the currently selected frame.
1732 @item break @var{linenum}
1733 Set a breakpoint at line @var{linenum} in the current source file.
1734 That file is the last file whose source text was printed. This
1735 breakpoint will stop your program just before it executes any of the
1738 @item break @var{filename}:@var{linenum}
1739 Set a breakpoint at line @var{linenum} in source file @var{filename}.
1741 @item break @var{filename}:@var{function}
1742 Set a breakpoint at entry to function @var{function} found in file
1743 @var{filename}. Specifying a file name as well as a function name is
1744 superfluous except when multiple files contain similarly named
1747 @item break *@var{address}
1748 Set a breakpoint at address @var{address}. You can use this to set
1749 breakpoints in parts of your program which do not have debugging
1750 information or source files.
1753 When called without any arguments, @code{break} sets a breakpoint at
1754 the next instruction to be executed in the selected stack frame
1755 (@pxref{Stack, ,Examining the Stack}). In any selected frame but the
1756 innermost, this will cause your program to stop as soon as control
1757 returns to that frame. This is similar to the effect of a
1758 @code{finish} command in the frame inside the selected frame---except
1759 that @code{finish} does not leave an active breakpoint. If you use
1760 @code{break} without an argument in the innermost frame, GDB will stop
1761 the next time it reaches the current location; this may be useful
1764 GDB normally ignores breakpoints when it resumes execution, until at
1765 least one instruction has been executed. If it did not do this, you
1766 would be unable to proceed past a breakpoint without first disabling the
1767 breakpoint. This rule applies whether or not the breakpoint already
1768 existed when your program stopped.
1770 @item break @dots{} if @var{cond}
1771 Set a breakpoint with condition @var{cond}; evaluate the expression
1772 @var{cond} each time the breakpoint is reached, and stop only if the
1773 value is nonzero---that is, if @var{cond} evaluates as true.
1774 @samp{@dots{}} stands for one of the possible arguments described
1775 above (or no argument) specifying where to break. @xref{Conditions,
1776 ,Break Conditions}, for more information on breakpoint conditions.
1778 @item tbreak @var{args}
1780 Set a breakpoint enabled only for one stop. @var{args} are the
1781 same as for the @code{break} command, and the breakpoint is set in the same
1782 way, but the breakpoint is automatically disabled after the first time your
1783 program stops there. @xref{Disabling, ,Disabling Breakpoints}.
1785 @item rbreak @var{regex}
1787 @cindex regular expression
1788 @c FIXME what kind of regexp?
1789 Set breakpoints on all functions matching the regular expression
1790 @var{regex}. This command
1791 sets an unconditional breakpoint on all matches, printing a list of all
1792 breakpoints it set. Once these breakpoints are set, they are treated
1793 just like the breakpoints set with the @code{break} command. They can
1794 be deleted, disabled, made conditional, etc., in the standard ways.
1796 When debugging C++ programs, @code{rbreak} is useful for setting
1797 breakpoints on overloaded functions that are not members of any special
1800 @kindex info breakpoints
1801 @cindex @code{$_} and @code{info breakpoints}
1802 @item info breakpoints @r{[}@var{n}@r{]}
1803 @item info break @r{[}@var{n}@r{]}
1804 Print a list of all breakpoints (but not watchpoints) set and not
1805 deleted, showing their numbers, where in your program they are, and any
1806 special features in use for them. Disabled breakpoints are included in
1807 the list, but marked as disabled. @code{info break} with a breakpoint
1808 number @var{n} as argument lists only that breakpoint. The
1809 convenience variable @code{$_} and the default examining-address for
1810 the @code{x} command are set to the address of the last breakpoint
1811 listed (@pxref{Memory, ,Examining Memory}). The equivalent command
1812 for watchpoints is @code{info watch}.
1815 GDB allows you to set any number of breakpoints at the same place in
1816 your program. There is nothing silly or meaningless about this. When
1817 the breakpoints are conditional, this is even useful
1818 (@pxref{Conditions, ,Break Conditions}).
1820 @node Set Watchpoints, Exception Handling, Set Breaks, Breakpoints
1821 @subsection Setting Watchpoints
1822 @cindex setting watchpoints
1824 You can use a watchpoint to stop execution whenever the value of an
1825 expression changes, without having to predict a particular place
1826 where this may happen.
1828 Watchpoints currently execute two orders of magnitude more slowly than
1829 other breakpoints, but this can well be worth it to catch errors where
1830 you have no clue what part of your program is the culprit. Some
1831 processors provide special hardware to support watchpoint evaluation; future
1832 releases of GDB will use such hardware if it is available.
1836 @item watch @var{expr}
1837 Set a watchpoint for an expression.
1839 @kindex info watchpoints
1840 @item info watchpoints
1841 This command prints a list of watchpoints; it is otherwise similar to
1845 @node Exception Handling, Delete Breaks, Set Watchpoints, Breakpoints
1846 @subsection Breakpoints and Exceptions
1847 @cindex exception handlers
1849 Some languages, such as GNU C++, implement exception handling. You can
1850 use GDB to examine what caused your program to raise an exception,
1851 and to list the exceptions your program is prepared to handle at a
1852 given point in time.
1855 @item catch @var{exceptions}
1857 You can set breakpoints at active exception handlers by using the
1858 @code{catch} command. @var{exceptions} is a list of names of exceptions
1862 You can use @code{info catch} to list active exception handlers.
1863 @xref{Frame Info, ,Information About a Frame}.
1865 There are currently some limitations to exception handling in GDB.
1866 These will be corrected in a future release.
1870 If you call a function interactively, GDB normally returns
1871 control to you when the function has finished executing. If the call
1872 raises an exception, however, the call may bypass the mechanism that
1873 returns control to you and cause your program to simply continue
1874 running until it hits a breakpoint, catches a signal that GDB is
1875 listening for, or exits.
1877 You cannot raise an exception interactively.
1879 You cannot interactively install an exception handler.
1882 @cindex raise exceptions
1883 Sometimes @code{catch} is not the best way to debug exception handling:
1884 if you need to know exactly where an exception is raised, it is better to
1885 stop @emph{before} the exception handler is called, since that way you
1886 can see the stack before any unwinding takes place. If you set a
1887 breakpoint in an exception handler instead, it may not be easy to find
1888 out where the exception was raised.
1890 To stop just before an exception handler is called, you need some
1891 knowledge of the implementation. In the case of GNU C++, exceptions are
1892 raised by calling a library function named @code{__raise_exception}
1893 which has the following ANSI C interface:
1896 /* @var{addr} is where the exception identifier is stored.
1897 ID is the exception identifier. */
1898 void __raise_exception (void **@var{addr}, void *@var{id});
1902 To make the debugger catch all exceptions before any stack
1903 unwinding takes place, set a breakpoint on @code{__raise_exception}
1904 (@pxref{Breakpoints, ,Breakpoints Watchpoints and Exceptions}).
1906 With a conditional breakpoint (@pxref{Conditions, ,Break Conditions})
1907 that depends on the value of @var{id}, you can stop your program when
1908 a specific exception is raised. You can use multiple conditional
1909 breakpoints to stop your program when any of a number of exceptions are
1912 @node Delete Breaks, Disabling, Exception Handling, Breakpoints
1913 @subsection Deleting Breakpoints
1915 @cindex clearing breakpoints, watchpoints
1916 @cindex deleting breakpoints, watchpoints
1917 It is often necessary to eliminate a breakpoint or watchpoint once it
1918 has done its job and you no longer want your program to stop there. This
1919 is called @dfn{deleting} the breakpoint. A breakpoint that has been
1920 deleted no longer exists; it is forgotten.
1922 With the @code{clear} command you can delete breakpoints according to
1923 where they are in your program. With the @code{delete} command you can
1924 delete individual breakpoints or watchpoints by specifying their
1927 It is not necessary to delete a breakpoint to proceed past it. GDB
1928 automatically ignores breakpoints on the first instruction to be executed
1929 when you continue execution without changing the execution address.
1934 Delete any breakpoints at the next instruction to be executed in the
1935 selected stack frame (@pxref{Selection, ,Selecting a Frame}). When
1936 the innermost frame is selected, this is a good way to delete a
1937 breakpoint where your program just stopped.
1939 @item clear @var{function}
1940 @itemx clear @var{filename}:@var{function}
1941 Delete any breakpoints set at entry to the function @var{function}.
1943 @item clear @var{linenum}
1944 @itemx clear @var{filename}:@var{linenum}
1945 Delete any breakpoints set at or within the code of the specified line.
1947 @item delete @r{[}breakpoints@r{]} @r{[}@var{bnums}@dots{}@r{]}
1948 @cindex delete breakpoints
1951 Delete the breakpoints or watchpoints of the numbers specified as
1952 arguments. If no argument is specified, delete all breakpoints (GDB
1953 asks confirmation, unless you have @code{set confirm off}). You
1954 can abbreviate this command as @code{d}.
1957 @node Disabling, Conditions, Delete Breaks, Breakpoints
1958 @subsection Disabling Breakpoints
1960 @cindex disabled breakpoints
1961 @cindex enabled breakpoints
1962 Rather than deleting a breakpoint or watchpoint, you might prefer to
1963 @dfn{disable} it. This makes the breakpoint inoperative as if it had
1964 been deleted, but remembers the information on the breakpoint so that
1965 you can @dfn{enable} it again later.
1967 You disable and enable breakpoints and watchpoints with the
1968 @code{enable} and @code{disable} commands, optionally specifying one or
1969 more breakpoint numbers as arguments. Use @code{info break} or
1970 @code{info watch} to print a list of breakpoints or watchpoints if you
1971 do not know which numbers to use.
1973 A breakpoint or watchpoint can have any of four different states of
1978 Enabled. The breakpoint will stop your program. A breakpoint set
1979 with the @code{break} command starts out in this state.
1981 Disabled. The breakpoint has no effect on your program.
1983 Enabled once. The breakpoint will stop your program, but
1984 when it does so it will become disabled. A breakpoint set
1985 with the @code{tbreak} command starts out in this state.
1987 Enabled for deletion. The breakpoint will stop your program, but
1988 immediately after it does so it will be deleted permanently.
1991 You can use the following commands to enable or disable breakpoints and
1995 @item disable @r{[}breakpoints@r{]} @r{[}@var{bnums}@dots{}@r{]}
1996 @kindex disable breakpoints
1999 Disable the specified breakpoints---or all breakpoints, if none are
2000 listed. A disabled breakpoint has no effect but is not forgotten. All
2001 options such as ignore-counts, conditions and commands are remembered in
2002 case the breakpoint is enabled again later. You may abbreviate
2003 @code{disable} as @code{dis}.
2005 @item enable @r{[}breakpoints@r{]} @r{[}@var{bnums}@dots{}@r{]}
2006 @kindex enable breakpoints
2008 Enable the specified breakpoints (or all defined breakpoints). They
2009 become effective once again in stopping your program.
2011 @item enable @r{[}breakpoints@r{]} once @var{bnums}@dots{}
2012 Enable the specified breakpoints temporarily. Each will be disabled
2013 again the next time it stops your program.
2015 @item enable @r{[}breakpoints@r{]} delete @var{bnums}@dots{}
2016 Enable the specified breakpoints to work once and then die. Each of
2017 the breakpoints will be deleted the next time it stops your program.
2020 Save for a breakpoint set with @code{tbreak} (@pxref{Set Breaks,
2021 ,Setting Breakpoints}), breakpoints that you set are initially
2022 enabled; subsequently, they become disabled or enabled only when you
2023 use one of the commands above. (The command @code{until} can set and
2024 delete a breakpoint of its own, but it will not change the state of
2025 your other breakpoints; see @ref{Continuing and Stepping, ,Continuing and Stepping}.)
2027 @node Conditions, Break Commands, Disabling, Breakpoints
2028 @subsection Break Conditions
2029 @cindex conditional breakpoints
2030 @cindex breakpoint conditions
2032 @c FIXME what is scope of break condition expr? Context where wanted?
2033 @c in particular for a watchpoint?
2034 The simplest sort of breakpoint breaks every time your program reaches a
2035 specified place. You can also specify a @dfn{condition} for a
2036 breakpoint. A condition is just a Boolean expression in your
2037 programming language (@pxref{Expressions, ,Expressions}). A breakpoint with
2038 a condition evaluates the expression each time your program reaches it,
2039 and your program stops only if the condition is @emph{true}.
2041 This is the converse of using assertions for program validation; in that
2042 situation, you want to stop when the assertion is violated---that is,
2043 when the condition is false. In C, if you want to test an assertion expressed
2044 by the condition @var{assert}, you should set the condition
2045 @samp{! @var{assert}} on the appropriate breakpoint.
2047 Conditions are also accepted for watchpoints; you may not need them,
2048 since a watchpoint is inspecting the value of an expression anyhow---but
2049 it might be simpler, say, to just set a watchpoint on a variable name,
2050 and specify a condition that tests whether the new value is an interesting
2053 Break conditions can have side effects, and may even call functions in
2054 your program. This can be useful, for example, to activate functions
2055 that log program progress, or to use your own print functions to
2056 format special data structures. The effects are completely predictable
2057 unless there is another enabled breakpoint at the same address. (In
2058 that case, GDB might see the other breakpoint first and stop your
2059 program without checking the condition of this one.) Note that
2060 breakpoint commands are usually more convenient and flexible for the
2061 purpose of performing side effects when a breakpoint is reached
2062 (@pxref{Break Commands, ,Breakpoint Command Lists}).
2064 Break conditions can be specified when a breakpoint is set, by using
2065 @samp{if} in the arguments to the @code{break} command. @xref{Set
2066 Breaks, ,Setting Breakpoints}. They can also be changed at any time
2067 with the @code{condition} command. The @code{watch} command does not
2068 recognize the @code{if} keyword; @code{condition} is the only way to
2069 impose a further condition on a watchpoint.
2072 @item condition @var{bnum} @var{expression}
2074 Specify @var{expression} as the break condition for breakpoint or
2075 watchpoint number @var{bnum}. From now on, this breakpoint will stop
2076 your program only if the value of @var{expression} is true (nonzero, in
2077 C). When you use @code{condition}, GDB checks @var{expression}
2078 immediately for syntactic correctness, and to determine whether symbols
2079 in it have referents in the context of your breakpoint.
2080 @c FIXME so what does GDB do if there is no referent? Moreover, what
2081 @c about watchpoints?
2083 not actually evaluate @var{expression} at the time the @code{condition}
2084 command is given, however. @xref{Expressions, ,Expressions}.
2086 @item condition @var{bnum}
2087 Remove the condition from breakpoint number @var{bnum}. It becomes
2088 an ordinary unconditional breakpoint.
2091 @cindex ignore count (of breakpoint)
2092 A special case of a breakpoint condition is to stop only when the
2093 breakpoint has been reached a certain number of times. This is so
2094 useful that there is a special way to do it, using the @dfn{ignore
2095 count} of the breakpoint. Every breakpoint has an ignore count, which
2096 is an integer. Most of the time, the ignore count is zero, and
2097 therefore has no effect. But if your program reaches a breakpoint whose
2098 ignore count is positive, then instead of stopping, it just decrements
2099 the ignore count by one and continues. As a result, if the ignore count
2100 value is @var{n}, the breakpoint will not stop the next @var{n} times it
2104 @item ignore @var{bnum} @var{count}
2106 Set the ignore count of breakpoint number @var{bnum} to @var{count}.
2107 The next @var{count} times the breakpoint is reached, your program's
2108 execution will not stop; other than to decrement the ignore count, GDB
2111 To make the breakpoint stop the next time it is reached, specify
2114 @item continue @var{count}
2115 @itemx c @var{count}
2116 @itemx fg @var{count}
2117 @kindex continue @var{count}
2118 Continue execution of your program, setting the ignore count of the
2119 breakpoint where your program stopped to @var{count} minus one.
2120 Thus, your program will not stop at this breakpoint until the
2121 @var{count}'th time it is reached.
2123 An argument to this command is meaningful only when your program stopped
2124 due to a breakpoint. At other times, the argument to @code{continue} is
2127 The synonym @code{fg} is provided purely for convenience, and has
2128 exactly the same behavior as other forms of the command.
2131 If a breakpoint has a positive ignore count and a condition, the condition
2132 is not checked. Once the ignore count reaches zero, the condition will
2135 You could achieve the effect of the ignore count with a condition such
2136 as @w{@samp{$foo-- <= 0}} using a debugger convenience variable that
2137 is decremented each time. @xref{Convenience Vars, ,Convenience
2140 @node Break Commands, Breakpoint Menus, Conditions, Breakpoints
2141 @subsection Breakpoint Command Lists
2143 @cindex breakpoint commands
2144 You can give any breakpoint (or watchpoint) a series of commands to
2145 execute when your program stops due to that breakpoint. For example, you
2146 might want to print the values of certain expressions, or enable other
2150 @item commands @r{[}@var{bnum}@r{]}
2151 @itemx @dots{} @var{command-list} @dots{}
2155 Specify a list of commands for breakpoint number @var{bnum}. The commands
2156 themselves appear on the following lines. Type a line containing just
2157 @code{end} to terminate the commands.
2159 To remove all commands from a breakpoint, type @code{commands} and
2160 follow it immediately with @code{end}; that is, give no commands.
2162 With no @var{bnum} argument, @code{commands} refers to the last
2163 breakpoint or watchpoint set (not to the breakpoint most recently
2167 Pressing @key{RET} as a means of repeating the last GDB command is
2168 disabled within a @var{command-list}.
2170 You can use breakpoint commands to start your program up again. Simply
2171 use the @code{continue} command, or @code{step}, or any other command
2172 that resumes execution. Subsequent commands in the command list are
2176 If the first command specified is @code{silent}, the usual message about
2177 stopping at a breakpoint is not printed. This may be desirable for
2178 breakpoints that are to print a specific message and then continue.
2179 If the remaining commands too print nothing, you will see no sign that
2180 the breakpoint was reached at all. @code{silent} is meaningful only
2181 at the beginning of a breakpoint command list.
2183 The commands @code{echo} and @code{output} that allow you to print
2184 precisely controlled output are often useful in silent breakpoints.
2185 @xref{Output, ,Commands for Controlled Output}.
2187 For example, here is how you could use breakpoint commands to print the
2188 value of @code{x} at entry to @code{foo} whenever @code{x} is positive.
2201 One application for breakpoint commands is to compensate for one bug so
2202 you can test for another. Put a breakpoint just after the erroneous line
2203 of code, give it a condition to detect the case in which something
2204 erroneous has been done, and give it commands to assign correct values
2205 to any variables that need them. End with the @code{continue} command
2206 so that your program does not stop, and start with the @code{silent}
2207 command so that no output is produced. Here is an example:
2219 One deficiency in the operation of automatically continuing breakpoints
2220 under Unix appears when your program uses raw mode for the terminal.
2221 GDB switches back to its own terminal modes (not raw) before executing
2222 commands, and then must switch back to raw mode when your program is
2223 continued. This causes any pending terminal input to be lost.
2224 @c FIXME: revisit below when GNU sys avail.
2225 @c In the GNU system, this will be fixed by changing the behavior of
2228 Under Unix, you can get around this problem by writing actions into
2229 the breakpoint condition rather than in commands. For example
2232 condition 5 (x = y + 4), 0
2236 specifies a condition expression (@pxref{Expressions, ,Expressions}) that will
2237 change @code{x} as needed, then always have the value zero so your
2238 program will not stop. No input is lost here, because GDB evaluates
2239 break conditions without changing the terminal modes. When you want
2240 to have nontrivial conditions for performing the side effects, the
2241 operators @samp{&&}, @samp{||} and @samp{?@dots{}:} may be useful.
2243 @node Breakpoint Menus, Error in Breakpoints, Break Commands, Breakpoints
2244 @subsection Breakpoint Menus
2246 @cindex symbol overloading
2248 Some programming languages (notably C++) permit a single function name
2249 to be defined several times, for application in different contexts.
2250 This is called @dfn{overloading}. When a function name is overloaded,
2251 @samp{break @var{function}} is not enough to tell GDB where you
2252 want a breakpoint. GDB offers you a menu of numbered choices for
2253 different possible breakpoints, and waits for your selection with the
2254 prompt @samp{>}. The first two options are always @samp{[0] cancel}
2255 and @samp{[1] all}. Typing @kbd{1} sets a breakpoint at each
2256 definition of @var{function}, and typing @kbd{0} aborts the
2257 @code{break} command without setting any new breakpoints.
2259 For example, the following session excerpt shows an attempt to set a
2260 breakpoint at the overloaded symbol @code{String::after}.
2261 We choose three particular definitions of that function name:
2264 (gdb) b String::after
2267 [2] file:String.cc; line number:867
2268 [3] file:String.cc; line number:860
2269 [4] file:String.cc; line number:875
2270 [5] file:String.cc; line number:853
2271 [6] file:String.cc; line number:846
2272 [7] file:String.cc; line number:735
2274 Breakpoint 1 at 0xb26c: file String.cc, line 867.
2275 Breakpoint 2 at 0xb344: file String.cc, line 875.
2276 Breakpoint 3 at 0xafcc: file String.cc, line 846.
2277 Multiple breakpoints were set.
2278 Use the "delete" command to delete unwanted breakpoints.
2282 @node Error in Breakpoints, , Breakpoint Menus, Breakpoints
2283 @subsection ``Cannot Insert Breakpoints''
2285 @c FIXME: "cannot insert breakpoints" error, v unclear.
2286 @c Q in pending mail to Gilmore. ---pesch@cygnus.com, 26mar91
2287 @c some light may be shed by looking at instances of
2288 @c ONE_PROCESS_WRITETEXT. But error seems possible otherwise
2289 @c too. pesch, 20sep91
2290 Under some operating systems, breakpoints cannot be used in a program if
2291 any other process is running that program. In this situation,
2292 attempting to run or continue a program with a breakpoint causes GDB
2293 to stop the other process.
2295 When this happens, you have three ways to proceed:
2299 Remove or disable the breakpoints, then continue.
2302 Suspend GDB, and copy the file containing your program to a new name.
2303 Resume GDB and use the @code{exec-file} command to specify that GDB
2304 should run your program under that name. Then start your program again.
2306 @c FIXME: RMS commented here "Show example". Maybe when someone
2307 @c explains the first FIXME: in this section...
2310 Relink your program so that the text segment is nonsharable, using the
2311 linker option @samp{-N}. The operating system limitation may not apply
2312 to nonsharable executables.
2315 @node Continuing and Stepping, Signals, Breakpoints, Stopping
2316 @section Continuing and Stepping
2320 @cindex resuming execution
2321 @dfn{Continuing} means resuming program execution until your program
2322 completes normally. In contrast, @dfn{stepping} means executing just
2323 one more ``step'' of your program, where ``step'' may mean either one
2324 line of source code, or one machine instruction (depending on what
2325 particular command you use). Either when continuing
2326 or when stepping, your program may stop even sooner, due to a breakpoint
2327 or to a signal. (If due to a signal, you may want to use @code{handle},
2328 or use @samp{signal 0} to resume execution. @xref{Signals, ,Signals}.)
2331 @item continue @r{[}@var{ignore-count}@r{]}
2333 Resume program execution, at the address where your program last stopped;
2334 any breakpoints set at that address are bypassed. The optional argument
2335 @var{ignore-count} allows you to specify a further number of times to
2336 ignore a breakpoint at this location; its effect is like that of
2337 @code{ignore} (@pxref{Conditions, ,Break Conditions}).
2339 To resume execution at a different place, you can use @code{return}
2340 (@pxref{Returning, ,Returning from a Function}) to go back to the
2341 calling function; or @code{jump} (@pxref{Jumping, ,Continuing at a
2342 Different Address}) to go to an arbitrary location in your program.
2345 A typical technique for using stepping is to set a breakpoint
2346 (@pxref{Breakpoints, ,Breakpoints Watchpoints and Exceptions}) at the
2347 beginning of the function or the section of your program where a
2348 problem is believed to lie, run your program until it stops at that
2349 breakpoint, and then step through the suspect area, examining the
2350 variables that are interesting, until you see the problem happen.
2356 Continue running your program until control reaches a different source
2357 line, then stop it and return control to GDB. This command is
2358 abbreviated @code{s}.
2361 @emph{Warning:} If you use the @code{step} command while control is
2362 within a function that was compiled without debugging information,
2363 execution will proceed until control reaches another function.
2366 @item step @var{count}
2367 Continue running as in @code{step}, but do so @var{count} times. If a
2368 breakpoint is reached or a signal not related to stepping occurs before
2369 @var{count} steps, stepping stops right away.
2371 @item next @r{[}@var{count}@r{]}
2374 Continue to the next source line in the current (innermost) stack frame.
2375 Similar to @code{step}, but any function calls appearing within the line
2376 of code are executed without stopping. Execution stops when control
2377 reaches a different line of code at the stack level which was executing
2378 when the @code{next} command was given. This command is abbreviated
2381 An argument @var{count} is a repeat count, as for @code{step}.
2383 @code{next} within a function that lacks debugging information acts like
2384 @code{step}, but any function calls appearing within the code of the
2385 function are executed without stopping.
2389 Continue running until just after function in the selected stack frame
2390 returns. Print the returned value (if any).
2392 Contrast this with the @code{return} command (@pxref{Returning,
2393 ,Returning from a Function}).
2399 Continue running until a source line past the current line, in the
2400 current stack frame, is reached. This command is used to avoid single
2401 stepping through a loop more than once. It is like the @code{next}
2402 command, except that when @code{until} encounters a jump, it
2403 automatically continues execution until the program counter is greater
2404 than the address of the jump.
2406 This means that when you reach the end of a loop after single stepping
2407 though it, @code{until} will cause your program to continue execution
2408 until the loop is exited. In contrast, a @code{next} command at the end
2409 of a loop will simply step back to the beginning of the loop, which
2410 would force you to step through the next iteration.
2412 @code{until} always stops your program if it attempts to exit the current
2415 @code{until} may produce somewhat counterintuitive results if the order
2416 of machine code does not match the order of the source lines. For
2417 example, in the following excerpt from a debugging session, the @code{f}
2418 (@code{frame}) command shows that execution is stopped at line
2419 @code{206}; yet when we use @code{until}, we get to line @code{195}:
2423 #0 main (argc=4, argv=0xf7fffae8) at m4.c:206
2426 195 for ( ; argc > 0; NEXTARG) @{
2429 This happened because, for execution efficiency, the compiler had
2430 generated code for the loop closure test at the end, rather than the
2431 start, of the loop---even though the test in a C @code{for}-loop is
2432 written before the body of the loop. The @code{until} command appeared
2433 to step back to the beginning of the loop when it advanced to this
2434 expression; however, it has not really gone to an earlier
2435 statement---not in terms of the actual machine code.
2437 @code{until} with no argument works by means of single
2438 instruction stepping, and hence is slower than @code{until} with an
2441 @item until @var{location}
2442 @item u @var{location}
2443 Continue running your program until either the specified location is
2444 reached, or the current stack frame returns. @var{location} is any of
2445 the forms of argument acceptable to @code{break} (@pxref{Set Breaks,
2446 ,Setting Breakpoints}). This form of the command uses breakpoints,
2447 and hence is quicker than @code{until} without an argument.
2453 Execute one machine instruction, then stop and return to the debugger.
2455 It is often useful to do @samp{display/i $pc} when stepping by machine
2456 instructions. This will cause the next instruction to be executed to
2457 be displayed automatically at each stop. @xref{Auto Display,
2458 ,Automatic Display}.
2460 An argument is a repeat count, as in @code{step}.
2466 Execute one machine instruction, but if it is a function call,
2467 proceed until the function returns.
2469 An argument is a repeat count, as in @code{next}.
2472 @node Signals, , Continuing and Stepping, Stopping
2476 A signal is an asynchronous event that can happen in a program. The
2477 operating system defines the possible kinds of signals, and gives each
2478 kind a name and a number. For example, in Unix @code{SIGINT} is the
2479 signal a program gets when you type an interrupt (often @kbd{C-c});
2480 @code{SIGSEGV} is the signal a program gets from referencing a place in
2481 memory far away from all the areas in use; @code{SIGALRM} occurs when
2482 the alarm clock timer goes off (which happens only if your program has
2483 requested an alarm).
2485 @cindex fatal signals
2486 Some signals, including @code{SIGALRM}, are a normal part of the
2487 functioning of your program. Others, such as @code{SIGSEGV}, indicate
2488 errors; these signals are @dfn{fatal} (kill your program immediately) if the
2489 program has not specified in advance some other way to handle the signal.
2490 @code{SIGINT} does not indicate an error in your program, but it is normally
2491 fatal so it can carry out the purpose of the interrupt: to kill the program.
2493 GDB has the ability to detect any occurrence of a signal in your
2494 program. You can tell GDB in advance what to do for each kind of
2497 @cindex handling signals
2498 Normally, GDB is set up to ignore non-erroneous signals like @code{SIGALRM}
2499 (so as not to interfere with their role in the functioning of your program)
2500 but to stop your program immediately whenever an error signal happens.
2501 You can change these settings with the @code{handle} command.
2505 @kindex info signals
2506 Print a table of all the kinds of signals and how GDB has been told to
2507 handle each one. You can use this to see the signal numbers of all
2508 the defined types of signals.
2510 @item handle @var{signal} @var{keywords}@dots{}
2512 Change the way GDB handles signal @var{signal}. @var{signal} can be the
2513 number of a signal or its name (with or without the @samp{SIG} at the
2514 beginning). The @var{keywords} say what change to make.
2518 The keywords allowed by the @code{handle} command can be abbreviated.
2519 Their full names are:
2523 GDB should not stop your program when this signal happens. It may
2524 still print a message telling you that the signal has come in.
2527 GDB should stop your program when this signal happens. This implies
2528 the @code{print} keyword as well.
2531 GDB should print a message when this signal happens.
2534 GDB should not mention the occurrence of the signal at all. This
2535 implies the @code{nostop} keyword as well.
2538 GDB should allow your program to see this signal; your program will be
2539 able to handle the signal, or may be terminated if the signal is fatal
2543 GDB should not allow your program to see this signal.
2547 When a signal has been set to stop your program, your program cannot see the
2548 signal until you continue. It will see the signal then, if @code{pass} is
2549 in effect for the signal in question @i{at that time}. In other words,
2550 after GDB reports a signal, you can use the @code{handle} command with
2551 @code{pass} or @code{nopass} to control whether that signal will be seen by
2552 your program when you later continue it.
2554 You can also use the @code{signal} command to prevent your program from
2555 seeing a signal, or cause it to see a signal it normally would not see,
2556 or to give it any signal at any time. For example, if your program stopped
2557 due to some sort of memory reference error, you might store correct
2558 values into the erroneous variables and continue, hoping to see more
2559 execution; but your program would probably terminate immediately as
2560 a result of the fatal signal once it saw the signal. To prevent this,
2561 you can continue with @samp{signal 0}. @xref{Signaling, ,Giving your
2564 @node Stack, Source, Stopping, Top
2565 @chapter Examining the Stack
2567 When your program has stopped, the first thing you need to know is where it
2568 stopped and how it got there.
2571 Each time your program performs a function call, the information about
2572 where in your program the call was made from is saved in a block of data
2573 called a @dfn{stack frame}. The frame also contains the arguments of the
2574 call and the local variables of the function that was called. All the
2575 stack frames are allocated in a region of memory called the @dfn{call
2578 When your program stops, the GDB commands for examining the stack allow you
2579 to see all of this information.
2581 @cindex selected frame
2582 One of the stack frames is @dfn{selected} by GDB and many GDB commands
2583 refer implicitly to the selected frame. In particular, whenever you ask
2584 GDB for the value of a variable in your program, the value is found in the
2585 selected frame. There are special GDB commands to select whichever frame
2586 you are interested in.
2588 When your program stops, GDB automatically selects the currently executing
2589 frame and describes it briefly as the @code{frame} command does
2590 (@pxref{Frame Info, ,Information About a Frame}).
2593 * Frames:: Stack Frames
2594 * Backtrace:: Backtraces
2595 * Selection:: Selecting a Frame
2596 * Frame Info:: Information on a Frame
2599 @node Frames, Backtrace, Stack, Stack
2600 @section Stack Frames
2604 The call stack is divided up into contiguous pieces called @dfn{stack
2605 frames}, or @dfn{frames} for short; each frame is the data associated
2606 with one call to one function. The frame contains the arguments given
2607 to the function, the function's local variables, and the address at
2608 which the function is executing.
2610 @cindex initial frame
2611 @cindex outermost frame
2612 @cindex innermost frame
2613 When your program is started, the stack has only one frame, that of the
2614 function @code{main}. This is called the @dfn{initial} frame or the
2615 @dfn{outermost} frame. Each time a function is called, a new frame is
2616 made. Each time a function returns, the frame for that function invocation
2617 is eliminated. If a function is recursive, there can be many frames for
2618 the same function. The frame for the function in which execution is
2619 actually occurring is called the @dfn{innermost} frame. This is the most
2620 recently created of all the stack frames that still exist.
2622 @cindex frame pointer
2623 Inside your program, stack frames are identified by their addresses. A
2624 stack frame consists of many bytes, each of which has its own address; each
2625 kind of computer has a convention for choosing one of those bytes whose
2626 address serves as the address of the frame. Usually this address is kept
2627 in a register called the @dfn{frame pointer register} while execution is
2628 going on in that frame.
2630 @cindex frame number
2631 GDB assigns numbers to all existing stack frames, starting with
2632 zero for the innermost frame, one for the frame that called it,
2633 and so on upward. These numbers do not really exist in your program;
2634 they are assigned by GDB to give you a way of designating stack
2635 frames in GDB commands.
2637 @cindex frameless execution
2638 Some compilers allow functions to be compiled so that they operate
2639 without stack frames. (For example, the @code{gcc} option
2640 @samp{-fomit-frame-pointer} will generate functions without a frame.)
2641 This is occasionally done with heavily used library functions to save
2642 the frame setup time. GDB has limited facilities for dealing with
2643 these function invocations. If the innermost function invocation has no
2644 stack frame, GDB will nevertheless regard it as though it had a
2645 separate frame, which is numbered zero as usual, allowing correct
2646 tracing of the function call chain. However, GDB has no provision
2647 for frameless functions elsewhere in the stack.
2649 @node Backtrace, Selection, Frames, Stack
2652 A backtrace is a summary of how your program got where it is. It shows one
2653 line per frame, for many frames, starting with the currently executing
2654 frame (frame zero), followed by its caller (frame one), and on up the
2662 Print a backtrace of the entire stack: one line per frame for all
2663 frames in the stack.
2665 You can stop the backtrace at any time by typing the system interrupt
2666 character, normally @kbd{C-c}.
2668 @item backtrace @var{n}
2670 Similar, but print only the innermost @var{n} frames.
2672 @item backtrace -@var{n}
2674 Similar, but print only the outermost @var{n} frames.
2680 The names @code{where} and @code{info stack} (abbreviated @code{info s})
2681 are additional aliases for @code{backtrace}.
2683 Each line in the backtrace shows the frame number and the function name.
2684 The program counter value is also shown---unless you use @code{set
2685 print address off}. The backtrace also shows the source file name and
2686 line number, as well as the arguments to the function. The program
2687 counter value is omitted if it is at the beginning of the code for that
2690 Here is an example of a backtrace. It was made with the command
2691 @samp{bt 3}, so it shows the innermost three frames.
2695 #0 m4_traceon (obs=0x24eb0, argc=1, argv=0x2b8c8)
2697 #1 0x6e38 in expand_macro (sym=0x2b600) at macro.c:242
2698 #2 0x6840 in expand_token (obs=0x0, t=177664, td=0xf7fffb08)
2700 (More stack frames follow...)
2705 The display for frame zero does not begin with a program counter
2706 value, indicating that your program has stopped at the beginning of the
2707 code for line @code{993} of @code{builtin.c}.
2709 @node Selection, Frame Info, Backtrace, Stack
2710 @section Selecting a Frame
2712 Most commands for examining the stack and other data in your program work on
2713 whichever stack frame is selected at the moment. Here are the commands for
2714 selecting a stack frame; all of them finish by printing a brief description
2715 of the stack frame just selected.
2722 Select frame number @var{n}. Recall that frame zero is the innermost
2723 (currently executing) frame, frame one is the frame that called the
2724 innermost one, and so on. The highest-numbered frame is @code{main}'s
2727 @item frame @var{addr}
2729 Select the frame at address @var{addr}. This is useful mainly if the
2730 chaining of stack frames has been damaged by a bug, making it
2731 impossible for GDB to assign numbers properly to all frames. In
2732 addition, this can be useful when your program has multiple stacks and
2733 switches between them.
2735 On the SPARC architecture, @code{frame} needs two addresses to
2736 select an arbitrary frame: a frame pointer and a stack pointer.
2737 @c note to future updaters: this is conditioned on a flag
2738 @c FRAME_SPECIFICATION_DYADIC in the tm-*.h files, currently only used
2739 @c by SPARC, hence the specific attribution. Generalize or list all
2740 @c possibilities if more supported machines start doing this.
2744 Move @var{n} frames up the stack. For positive numbers @var{n}, this
2745 advances toward the outermost frame, to higher frame numbers, to frames
2746 that have existed longer. @var{n} defaults to one.
2751 Move @var{n} frames down the stack. For positive numbers @var{n}, this
2752 advances toward the innermost frame, to lower frame numbers, to frames
2753 that were created more recently. @var{n} defaults to one. You may
2754 abbreviate @code{down} as @code{do}.
2757 All of these commands end by printing two lines of output describing the
2758 frame. The first line shows the frame number, the function name, the
2759 arguments, and the source file and line number of execution in that
2760 frame. The second line shows the text of that source line. For
2766 #1 0x22f0 in main (argc=1, argv=0xf7fffbf4, env=0xf7fffbfc)
2768 10 read_input_file (argv[i]);
2772 After such a printout, the @code{list} command with no arguments will
2773 print ten lines centered on the point of execution in the frame.
2774 @xref{List, ,Printing Source Lines}.
2777 @item up-silently @var{n}
2778 @itemx down-silently @var{n}
2779 @kindex down-silently
2781 These two commands are variants of @code{up} and @code{down},
2782 respectively; they differ in that they do their work silently, without
2783 causing display of the new frame. They are intended primarily for use
2784 in GDB command scripts, where the output might be unnecessary and
2788 @node Frame Info, , Selection, Stack
2789 @section Information About a Frame
2791 There are several other commands to print information about the selected
2797 When used without any argument, this command does not change which
2798 frame is selected, but prints a brief description of the currently
2799 selected stack frame. It can be abbreviated @code{f}. With an
2800 argument, this command is used to select a stack frame
2801 (@pxref{Selection, ,Selecting a Frame}).
2807 This command prints a verbose description of the selected stack frame,
2808 including the address of the frame, the addresses of the next frame down
2809 (called by this frame) and the next frame up (caller of this frame), the
2810 language that the source code corresponding to this frame was written in,
2811 the address of the frame's arguments, the program counter saved in it
2812 (the address of execution in the caller frame), and which registers
2813 were saved in the frame. The verbose description is useful when
2814 something has gone wrong that has made the stack format fail to fit
2815 the usual conventions.
2817 @item info frame @var{addr}
2818 @itemx info f @var{addr}
2819 Print a verbose description of the frame at address @var{addr},
2820 without selecting that frame. The selected frame remains unchanged by
2825 Print the arguments of the selected frame, each on a separate line.
2829 Print the local variables of the selected frame, each on a separate
2830 line. These are all variables declared static or automatic within all
2831 program blocks that execution in this frame is currently inside of.
2835 @cindex catch exceptions
2836 @cindex exception handlers
2837 Print a list of all the exception handlers that are active in the
2838 current stack frame at the current point of execution. To see other
2839 exception handlers, visit the associated frame (using the @code{up},
2840 @code{down}, or @code{frame} commands); then type @code{info catch}.
2841 @xref{Exception Handling, ,Breakpoints and Exceptions}.
2844 @node Source, Data, Stack, Top
2845 @chapter Examining Source Files
2847 GDB can print parts of your program's source, since the debugging
2848 information recorded in your program tells GDB what source files were
2849 used to build it. When your program stops, GDB spontaneously prints
2850 the line where it stopped. Likewise, when you select a stack frame
2851 (@pxref{Selection, ,Selecting a Frame}), GDB prints the line where
2852 execution in that frame has stopped. You can print other portions of
2853 source files by explicit command.
2855 If you use GDB through its GNU Emacs interface, you may prefer to use
2856 Emacs facilities to view source; @pxref{Emacs, ,Using GDB under GNU
2860 * List:: Printing Source Lines
2861 * Search:: Searching Source Files
2862 * Source Path:: Specifying Source Directories
2863 * Machine Code:: Source and Machine Code
2866 @node List, Search, Source, Source
2867 @section Printing Source Lines
2871 To print lines from a source file, use the @code{list} command
2872 (abbreviated @code{l}). There are several ways to specify what part
2873 of the file you want to print.
2875 Here are the forms of the @code{list} command most commonly used:
2878 @item list @var{linenum}
2879 Print lines centered around line number @var{linenum} in the
2880 current source file.
2882 @item list @var{function}
2883 Print lines centered around the beginning of function
2887 Print more lines. If the last lines printed were printed with a
2888 @code{list} command, this prints lines following the last lines
2889 printed; however, if the last line printed was a solitary line printed
2890 as part of displaying a stack frame (@pxref{Stack, ,Examining the
2891 Stack}), this prints lines centered around that line.
2894 Print lines just before the lines last printed.
2897 By default, GDB prints ten source lines with any of these forms of
2898 the @code{list} command. You can change this using @code{set listsize}:
2901 @item set listsize @var{count}
2902 @kindex set listsize
2903 Make the @code{list} command display @var{count} source lines (unless
2904 the @code{list} argument explicitly specifies some other number).
2907 @kindex show listsize
2908 Display the number of lines that @code{list} will currently display by
2912 Repeating a @code{list} command with @key{RET} discards the argument,
2913 so it is equivalent to typing just @code{list}. This is more useful
2914 than listing the same lines again. An exception is made for an
2915 argument of @samp{-}; that argument is preserved in repetition so that
2916 each repetition moves up in the source file.
2919 In general, the @code{list} command expects you to supply zero, one or two
2920 @dfn{linespecs}. Linespecs specify source lines; there are several ways
2921 of writing them but the effect is always to specify some source line.
2922 Here is a complete description of the possible arguments for @code{list}:
2925 @item list @var{linespec}
2926 Print lines centered around the line specified by @var{linespec}.
2928 @item list @var{first},@var{last}
2929 Print lines from @var{first} to @var{last}. Both arguments are
2932 @item list ,@var{last}
2933 Print lines ending with @var{last}.
2935 @item list @var{first},
2936 Print lines starting with @var{first}.
2939 Print lines just after the lines last printed.
2942 Print lines just before the lines last printed.
2945 As described in the preceding table.
2948 Here are the ways of specifying a single source line---all the
2953 Specifies line @var{number} of the current source file.
2954 When a @code{list} command has two linespecs, this refers to
2955 the same source file as the first linespec.
2958 Specifies the line @var{offset} lines after the last line printed.
2959 When used as the second linespec in a @code{list} command that has
2960 two, this specifies the line @var{offset} lines down from the
2964 Specifies the line @var{offset} lines before the last line printed.
2966 @item @var{filename}:@var{number}
2967 Specifies line @var{number} in the source file @var{filename}.
2969 @item @var{function}
2970 @c FIXME: "of the open-brace" is C-centric. When we add other langs...
2971 Specifies the line of the open-brace that begins the body of the
2972 function @var{function}.
2974 @item @var{filename}:@var{function}
2975 Specifies the line of the open-brace that begins the body of the
2976 function @var{function} in the file @var{filename}. You only need the
2977 file name with a function name to avoid ambiguity when there are
2978 identically named functions in different source files.
2980 @item *@var{address}
2981 Specifies the line containing the program address @var{address}.
2982 @var{address} may be any expression.
2985 @node Search, Source Path, List, Source
2986 @section Searching Source Files
2988 @kindex reverse-search
2990 There are two commands for searching through the current source file for a
2994 @item forward-search @var{regexp}
2995 @itemx search @var{regexp}
2997 @kindex forward-search
2998 The command @samp{forward-search @var{regexp}} checks each line,
2999 starting with the one following the last line listed, for a match for
3000 @var{regexp}. It lists the line that is found. You can use
3001 synonym @samp{search @var{regexp}} or abbreviate the command name as
3004 @item reverse-search @var{regexp}
3005 The command @samp{reverse-search @var{regexp}} checks each line, starting
3006 with the one before the last line listed and going backward, for a match
3007 for @var{regexp}. It lists the line that is found. You can abbreviate
3008 this command as @code{rev}.
3011 @node Source Path, Machine Code, Search, Source
3012 @section Specifying Source Directories
3015 @cindex directories for source files
3016 Executable programs sometimes do not record the directories of the source
3017 files from which they were compiled, just the names. Even when they do,
3018 the directories could be moved between the compilation and your debugging
3019 session. GDB has a list of directories to search for source files;
3020 this is called the @dfn{source path}. Each time GDB wants a source file,
3021 it tries all the directories in the list, in the order they are present
3022 in the list, until it finds a file with the desired name. Note that
3023 the executable search path is @emph{not} used for this purpose. Neither is
3024 the current working directory, unless it happens to be in the source
3027 If GDB cannot find a source file in the source path, and the object
3028 program records a directory, GDB tries that directory too. If the
3029 source path is empty, and there is no record of the compilation
3030 directory, GDB will, as a last resort, look in the current
3033 Whenever you reset or rearrange the source path, GDB will clear out
3034 any information it has cached about where source files are found, where
3035 each line is in the file, etc.
3038 When you start GDB, its source path is empty.
3039 To add other directories, use the @code{directory} command.
3042 @item directory @var{dirname} @dots{}
3043 Add directory @var{dirname} to the front of the source path. Several
3044 directory names may be given to this command, separated by @samp{:} or
3045 whitespace. You may specify a directory that is already in the source
3046 path; this moves it forward, so it will be searched sooner.
3048 You can use the string @samp{$cdir} to refer to the compilation
3049 directory (if one is recorded), and @samp{$cwd} to refer to the current
3050 working directory. @samp{$cwd} is not the same as @samp{.}---the former
3051 tracks the current working directory as it changes during your GDB
3052 session, while the latter is immediately expanded to the current
3053 directory at the time you add an entry to the source path.
3056 Reset the source path to empty again. This requires confirmation.
3058 @c RET-repeat for @code{directory} is explicitly disabled, but since
3059 @c repeating it would be a no-op we do not say that. (thanks to RMS)
3061 @item show directories
3062 @kindex show directories
3063 Print the source path: show which directories it contains.
3066 If your source path is cluttered with directories that are no longer of
3067 interest, GDB may sometimes cause confusion by finding the wrong
3068 versions of source. You can correct the situation as follows:
3072 Use @code{directory} with no argument to reset the source path to empty.
3075 Use @code{directory} with suitable arguments to reinstall the
3076 directories you want in the source path. You can add all the
3077 directories in one command.
3080 @node Machine Code, , Source Path, Source
3081 @section Source and Machine Code
3083 You can use the command @code{info line} to map source lines to program
3084 addresses (and viceversa), and the command @code{disassemble} to display
3085 a range of addresses as machine instructions.
3088 @item info line @var{linespec}
3090 Print the starting and ending addresses of the compiled code for
3091 source line @var{linespec}. You can specify source lines in any of
3092 the ways understood by the @code{list} command (@pxref{List, ,Printing
3096 For example, we can use @code{info line} to discover the location of
3097 the object code for the first line of function
3098 @code{m4_changequote}:
3101 (gdb) info line m4_changecom
3102 Line 895 of "builtin.c" starts at pc 0x634c and ends at 0x6350.
3106 We can also inquire (using @code{*@var{addr}} as the form for
3107 @var{linespec}) what source line covers a particular address:
3109 (gdb) info line *0x63ff
3110 Line 926 of "builtin.c" starts at pc 0x63e4 and ends at 0x6404.
3113 @cindex @code{$_} and @code{info line}
3114 After @code{info line}, the default address for the @code{x} command
3115 is changed to the starting address of the line, so that @samp{x/i} is
3116 sufficient to begin examining the machine code (@pxref{Memory,
3117 ,Examining Memory}). Also, this address is saved as the value of the
3118 convenience variable @code{$_} (@pxref{Convenience Vars, ,Convenience
3124 This specialized command dumps a range of memory as machine
3125 instructions. The default memory range is the function surrounding the
3126 program counter of the selected frame. A single argument to this
3127 command is a program counter value; the function surrounding this value
3128 will be dumped. Two arguments specify a range of addresses (first
3129 inclusive, second exclusive) to dump.
3132 We can use @code{disassemble} to inspect the object code
3133 range shown in the last @code{info line} example:
3136 (gdb) disas 0x63e4 0x6404
3137 Dump of assembler code from 0x63e4 to 0x6404:
3138 0x63e4 builtin_init+5340: ble 0x63f8 builtin_init+5360
3139 0x63e8 builtin_init+5344: sethi %hi(0x4c00), %o0
3140 0x63ec builtin_init+5348: ld [%i1+4], %o0
3141 0x63f0 builtin_init+5352: b 0x63fc builtin_init+5364
3142 0x63f4 builtin_init+5356: ld [%o0+4], %o0
3143 0x63f8 builtin_init+5360: or %o0, 0x1a4, %o0
3144 0x63fc builtin_init+5364: call 0x9288 path_search
3145 0x6400 builtin_init+5368: nop
3146 End of assembler dump.
3149 @node Data, Languages, Source, Top
3150 @chapter Examining Data
3152 @cindex printing data
3153 @cindex examining data
3156 @c "inspect" is not quite a synonym if you are using Epoch, which we do not
3157 @c document because it is nonstandard... Under Epoch it displays in a
3158 @c different window or something like that.
3159 The usual way to examine data in your program is with the @code{print}
3160 command (abbreviated @code{p}), or its synonym @code{inspect}. It
3161 evaluates and prints the value of an expression of the language your
3162 program is written in (@pxref{Languages, ,Using GDB with Different
3166 @item print @var{exp}
3167 @itemx print /@var{f} @var{exp}
3168 @var{exp} is an expression (in the source language). By default
3169 the value of @var{exp} is printed in a format appropriate to its data
3170 type; you can choose a different format by specifying @samp{/@var{f}},
3171 where @var{f} is a letter specifying the format; @pxref{Output formats}.
3174 @itemx print /@var{f}
3175 If you omit @var{exp}, GDB displays the last value again (from the
3176 @dfn{value history}; @pxref{Value History, ,Value History}). This allows you to
3177 conveniently inspect the same value in an alternative format.
3180 A more low-level way of examining data is with the @code{x} command.
3181 It examines data in memory at a specified address and prints it in a
3182 specified format. @xref{Memory, ,Examining Memory}.
3184 If you are interested in information about types, or about how the fields
3185 of a struct or class are declared, use the @code{ptype @var{exp}}
3186 command rather than @code{print}. @xref{Symbols, ,Examining the Symbol Table}.
3189 * Expressions:: Expressions
3190 * Variables:: Program Variables
3191 * Arrays:: Artificial Arrays
3192 * Output formats:: Output formats
3193 * Memory:: Examining Memory
3194 * Auto Display:: Automatic Display
3195 * Print Settings:: Print Settings
3196 * Value History:: Value History
3197 * Convenience Vars:: Convenience Variables
3198 * Registers:: Registers
3199 * Floating Point Hardware:: Floating Point Hardware
3202 @node Expressions, Variables, Data, Data
3203 @section Expressions
3206 @code{print} and many other GDB commands accept an expression and
3207 compute its value. Any kind of constant, variable or operator defined
3208 by the programming language you are using is legal in an expression in
3209 GDB. This includes conditional expressions, function calls, casts
3210 and string constants. It unfortunately does not include symbols defined
3211 by preprocessor @code{#define} commands.
3213 Because C is so widespread, most of the expressions shown in examples in
3214 this manual are in C. @xref{Languages, , Using GDB with Different
3215 Languages}, for information on how to use expressions in other
3218 In this section, we discuss operators that you can use in GDB
3219 expressions regardless of your programming language.
3221 Casts are supported in all languages, not just in C, because it is so
3222 useful to cast a number into a pointer so as to examine a structure
3223 at that address in memory.
3224 @c FIXME: casts supported---Mod2 true?
3226 GDB supports these operators in addition to those of programming
3231 @samp{@@} is a binary operator for treating parts of memory as arrays.
3232 @xref{Arrays, ,Artificial Arrays}, for more information.
3235 @samp{::} allows you to specify a variable in terms of the file or
3236 function where it is defined. @xref{Variables, ,Program Variables}.
3238 @item @{@var{type}@} @var{addr}
3239 Refers to an object of type @var{type} stored at address @var{addr} in
3240 memory. @var{addr} may be any expression whose value is an integer or
3241 pointer (but parentheses are required around binary operators, just as in
3242 a cast). This construct is allowed regardless of what kind of data is
3243 normally supposed to reside at @var{addr}.
3246 @node Variables, Arrays, Expressions, Data
3247 @section Program Variables
3249 The most common kind of expression to use is the name of a variable
3252 Variables in expressions are understood in the selected stack frame
3253 (@pxref{Selection, ,Selecting a Frame}); they must either be global
3254 (or static) or be visible according to the scope rules of the
3255 programming language from the point of execution in that frame. This
3256 means that in the function
3271 the variable @code{a} is usable whenever your program is executing
3272 within the function @code{foo}, but the variable @code{b} is visible
3273 only while your program is executing inside the block in which @code{b}
3276 @cindex variable name conflict
3277 There is an exception: you can refer to a variable or function whose
3278 scope is a single source file even if the current execution point is not
3279 in this file. But it is possible to have more than one such variable or
3280 function with the same name (in different source files). If that happens,
3281 referring to that name has unpredictable effects. If you wish, you can
3282 specify a variable in a particular file, using the colon-colon notation:
3286 @c info cannot cope with a :: index entry, but why deprive hard copy readers?
3290 @var{file}::@var{variable}
3294 Here @var{file} is the name of the source file whose variable you want.
3296 @cindex C++ scope resolution
3297 This use of @samp{::} is very rarely in conflict with the very similar
3298 use of the same notation in C++. GDB also supports use of the C++
3299 scope resolution operator in GDB expressions.
3301 @cindex wrong values
3302 @cindex variable values, wrong
3304 @emph{Warning:} Occasionally, a local variable may appear to have the
3305 wrong value at certain points in a function---just after entry to the
3306 function, and just before exit. You may see this problem when you are
3307 stepping by machine instructions. This is because on most machines, it
3308 takes more than one instruction to set up a stack frame (including local
3309 variable definitions); if you are stepping by machine instructions,
3310 variables may appear to have the wrong values until the stack frame is
3311 completely built. On function exit, it usually also takes more than one
3312 machine instruction to destroy a stack frame; after you begin stepping
3313 through that group of instructions, local variable definitions may be
3317 @node Arrays, Output formats, Variables, Data
3318 @section Artificial Arrays
3320 @cindex artificial array
3322 It is often useful to print out several successive objects of the
3323 same type in memory; a section of an array, or an array of
3324 dynamically determined size for which only a pointer exists in the
3327 This can be done by constructing an @dfn{artificial array} with the
3328 binary operator @samp{@@}. The left operand of @samp{@@} should be
3329 the first element of the desired array, as an individual object.
3330 The right operand should be the desired length of the array. The result is
3331 an array value whose elements are all of the type of the left argument.
3332 The first element is actually the left argument; the second element
3333 comes from bytes of memory immediately following those that hold the
3334 first element, and so on. Here is an example. If a program says
3337 int *array = (int *) malloc (len * sizeof (int));
3341 you can print the contents of @code{array} with
3347 The left operand of @samp{@@} must reside in memory. Array values made
3348 with @samp{@@} in this way behave just like other arrays in terms of
3349 subscripting, and are coerced to pointers when used in expressions.
3350 Artificial arrays most often appear in expressions via the value history
3351 (@pxref{Value History, ,Value History}), after printing one out.)
3353 Sometimes the artificial array mechanism is not quite enough; in
3354 moderately complex data structures, the elements of interest may not
3355 actually be adjacent---for example, if you are interested in the values
3356 of pointers in an array. One useful work-around in this situation is
3357 to use a convenience variable (@pxref{Convenience Vars, ,Convenience
3358 Variables}) as a counter in an expression that prints the first
3359 interesting value, and then repeat that expression via @key{RET}. For
3360 instance, suppose you have an array @code{dtab} of pointers to
3361 structures, and you are interested in the values of a field @code{fv}
3362 in each structure. Here is an example of what you might type:
3372 @node Output formats, Memory, Arrays, Data
3373 @section Output formats
3375 @cindex formatted output
3376 @cindex output formats
3377 By default, GDB prints a value according to its data type. Sometimes
3378 this is not what you want. For example, you might want to print a number
3379 in hex, or a pointer in decimal. Or you might want to view data in memory
3380 at a certain address as a character string or as an instruction. To do
3381 these things, specify an @dfn{output format} when you print a value.
3383 The simplest use of output formats is to say how to print a value
3384 already computed. This is done by starting the arguments of the
3385 @code{print} command with a slash and a format letter. The format
3386 letters supported are:
3390 Regard the bits of the value as an integer, and print the integer in
3394 Print as integer in signed decimal.
3397 Print as integer in unsigned decimal.
3400 Print as integer in octal.
3403 Print as integer in binary. The letter @samp{t} stands for ``two''.
3406 Print as an address, both absolute in hex and as an offset from the
3407 nearest preceding symbol. This format can be used to discover where (in
3408 what function) an unknown address is located:
3412 $3 = 0x54320 <_initialize_vx+396>
3416 Regard as an integer and print it as a character constant.
3419 Regard the bits of the value as a floating point number and print
3420 using typical floating point syntax.
3423 For example, to print the program counter in hex (@pxref{Registers}), type
3430 Note that no space is required before the slash; this is because command
3431 names in GDB cannot contain a slash.
3433 To reprint the last value in the value history with a different format,
3434 you can use the @code{print} command with just a format and no
3435 expression. For example, @samp{p/x} reprints the last value in hex.
3437 @node Memory, Auto Display, Output formats, Data
3438 @section Examining Memory
3440 You can use the command @code{x} (for ``examine'') to examine memory in
3441 any of several formats, independently of your program's data types.
3443 @cindex examining memory
3446 @item x/@var{nfu} @var{addr}
3449 Use the command @code{x} to examine memory.
3452 @var{n}, @var{f}, and @var{u} are all optional parameters that specify how
3453 much memory to display and how to format it; @var{addr} is an
3454 expression giving the address where you want to start displaying memory.
3455 If you use defaults for @var{nfu}, you need not type the slash @samp{/}.
3456 Several commands set convenient defaults for @var{addr}.
3459 @item @var{n}, the repeat count
3460 The repeat count is a decimal integer; the default is 1. It specifies
3461 how much memory (counting by units @var{u}) to display.
3462 @c This really is **decimal**; unaffected by 'set radix' as of GDB
3465 @item @var{f}, the display format
3466 The display format is one of the formats used by @code{print},
3467 or @samp{s} (null-terminated string) or @samp{i} (machine instruction).
3468 The default is @samp{x} (hexadecimal) initially, or the format from the
3469 last time you used either @code{x} or @code{print}.
3471 @item @var{u}, the unit size
3472 The unit size is any of
3477 Halfwords (two bytes).
3479 Words (four bytes). This is the initial default.
3481 Giant words (eight bytes).
3484 Each time you specify a unit size with @code{x}, that size becomes the
3485 default unit the next time you use @code{x}. (For the @samp{s} and
3486 @samp{i} formats, the unit size is ignored and is normally not written.)
3488 @item @var{addr}, starting display address
3489 @var{addr} is the address where you want GDB to begin displaying
3490 memory. The expression need not have a pointer value (though it may);
3491 it is always interpreted as an integer address of a byte of memory.
3492 @xref{Expressions, ,Expressions}, for more information on expressions. The default for
3493 @var{addr} is usually just after the last address examined---but several
3494 other commands also set the default address: @code{info breakpoints} (to
3495 the address of the last breakpoint listed), @code{info line} (to the
3496 starting address of a line), and @code{print} (if you use it to display
3497 a value from memory).
3500 For example, @samp{x/3uh 0x54320} is a request to display three halfwords
3501 (@code{h}) of memory, formatted as unsigned decimal integers (@samp{u}),
3502 starting at address @code{0x54320}. @samp{x/4xw $sp} prints the four
3503 words (@samp{w}) of memory above the stack pointer (here, @samp{$sp};
3504 @pxref{Registers}) in hexadecimal (@samp{x}).
3506 Since the letters indicating unit sizes are all distinct from the
3507 letters specifying output formats, you do not have to remember whether
3508 unit size or format comes first; either order will work. The output
3509 specifications @samp{4xw} and @samp{4wx} mean exactly the same thing.
3510 (However, the count @var{n} must come first; @samp{wx4} will not work.)
3512 Even though the unit size @var{u} is ignored for the formats @samp{s}
3513 and @samp{i}, you might still want to use a count @var{n}; for example,
3514 @samp{3i} specifies that you want to see three machine instructions,
3515 including any operands. The command @code{disassemble} gives an
3516 alternative way of inspecting machine instructions; @pxref{Machine
3519 All the defaults for the arguments to @code{x} are designed to make it
3520 easy to continue scanning memory with minimal specifications each time
3521 you use @code{x}. For example, after you have inspected three machine
3522 instructions with @samp{x/3i @var{addr}}, you can inspect the next seven
3523 with just @samp{x/7}. If you use @key{RET} to repeat the @code{x} command,
3524 the repeat count @var{n} is used again; the other arguments default as
3525 for successive uses of @code{x}.
3527 @cindex @code{$_}, @code{$__}, and value history
3528 The addresses and contents printed by the @code{x} command are not saved
3529 in the value history because there is often too much of them and they
3530 would get in the way. Instead, GDB makes these values available for
3531 subsequent use in expressions as values of the convenience variables
3532 @code{$_} and @code{$__}. After an @code{x} command, the last address
3533 examined is available for use in expressions in the convenience variable
3534 @code{$_}. The contents of that address, as examined, are available in
3535 the convenience variable @code{$__}.
3537 If the @code{x} command has a repeat count, the address and contents saved
3538 are from the last memory unit printed; this is not the same as the last
3539 address printed if several units were printed on the last line of output.
3541 @node Auto Display, Print Settings, Memory, Data
3542 @section Automatic Display
3543 @cindex automatic display
3544 @cindex display of expressions
3546 If you find that you want to print the value of an expression frequently
3547 (to see how it changes), you might want to add it to the @dfn{automatic
3548 display list} so that GDB will print its value each time your program stops.
3549 Each expression added to the list is given a number to identify it;
3550 to remove an expression from the list, you specify that number.
3551 The automatic display looks like this:
3555 3: bar[5] = (struct hack *) 0x3804
3559 showing item numbers, expressions and their current values. As with
3560 displays you request manually using @code{x} or @code{print}, you can
3561 specify the output format you prefer; in fact, @code{display} decides
3562 whether to use @code{print} or @code{x} depending on how elaborate your
3563 format specification is---it uses @code{x} if you specify a unit size,
3564 or one of the two formats (@samp{i} and @samp{s}) that are only
3565 supported by @code{x}; otherwise it uses @code{print}.
3568 @item display @var{exp}
3570 Add the expression @var{exp} to the list of expressions to display
3571 each time your program stops. @xref{Expressions, ,Expressions}.
3573 @code{display} will not repeat if you press @key{RET} again after using it.
3575 @item display/@var{fmt} @var{exp}
3576 For @var{fmt} specifying only a display format and not a size or
3577 count, add the expression @var{exp} to the auto-display list but
3578 arranges to display it each time in the specified format @var{fmt}.
3579 @xref{Output formats}.
3581 @item display/@var{fmt} @var{addr}
3582 For @var{fmt} @samp{i} or @samp{s}, or including a unit-size or a
3583 number of units, add the expression @var{addr} as a memory address to
3584 be examined each time your program stops. Examining means in effect
3585 doing @samp{x/@var{fmt} @var{addr}}. @xref{Memory, ,Examining Memory}.
3588 For example, @samp{display/i $pc} can be helpful, to see the machine
3589 instruction about to be executed each time execution stops (@samp{$pc}
3590 is a common name for the program counter; @pxref{Registers}).
3593 @item undisplay @var{dnums}@dots{}
3594 @itemx delete display @var{dnums}@dots{}
3595 @kindex delete display
3597 Remove item numbers @var{dnums} from the list of expressions to display.
3599 @code{undisplay} will not repeat if you press @key{RET} after using it.
3600 (Otherwise you would just get the error @samp{No display number @dots{}}.)
3602 @item disable display @var{dnums}@dots{}
3603 @kindex disable display
3604 Disable the display of item numbers @var{dnums}. A disabled display
3605 item is not printed automatically, but is not forgotten. It may be
3606 enabled again later.
3608 @item enable display @var{dnums}@dots{}
3609 @kindex enable display
3610 Enable display of item numbers @var{dnums}. It becomes effective once
3611 again in auto display of its expression, until you specify otherwise.
3614 Display the current values of the expressions on the list, just as is
3615 done when your program stops.
3618 @kindex info display
3619 Print the list of expressions previously set up to display
3620 automatically, each one with its item number, but without showing the
3621 values. This includes disabled expressions, which are marked as such.
3622 It also includes expressions which would not be displayed right now
3623 because they refer to automatic variables not currently available.
3626 If a display expression refers to local variables, then it does not make
3627 sense outside the lexical context for which it was set up. Such an
3628 expression is disabled when execution enters a context where one of its
3629 variables is not defined. For example, if you give the command
3630 @code{display last_char} while inside a function with an argument
3631 @code{last_char}, then this argument will be displayed while your program
3632 continues to stop inside that function. When it stops elsewhere---where
3633 there is no variable @code{last_char}---display is disabled. The next time
3634 your program stops where @code{last_char} is meaningful, you can enable the
3635 display expression once again.
3637 @node Print Settings, Value History, Auto Display, Data
3638 @section Print Settings
3640 @cindex format options
3641 @cindex print settings
3642 GDB provides the following ways to control how arrays, structures,
3643 and symbols are printed.
3646 These settings are useful for debugging programs in any language:
3649 @item set print address
3650 @item set print address on
3651 @kindex set print address
3652 GDB will print memory addresses showing the location of stack
3653 traces, structure values, pointer values, breakpoints, and so forth,
3654 even when it also displays the contents of those addresses. The default
3655 is on. For example, this is what a stack frame display looks like, with
3656 @code{set print address on}:
3661 #0 set_quotes (lq=0x34c78 "<<", rq=0x34c88 ">>")
3663 530 if (lquote != def_lquote)
3667 @item set print address off
3668 Do not print addresses when displaying their contents. For example,
3669 this is the same stack frame displayed with @code{set print address off}:
3673 (gdb) set print addr off
3675 #0 set_quotes (lq="<<", rq=">>") at input.c:530
3676 530 if (lquote != def_lquote)
3680 @item show print address
3681 @kindex show print address
3682 Show whether or not addresses are to be printed.
3684 @item set print array
3685 @itemx set print array on
3686 @kindex set print array
3687 GDB will pretty print arrays. This format is more convenient to read,
3688 but uses more space. The default is off.
3690 @item set print array off.
3691 Return to compressed format for arrays.
3693 @item show print array
3694 @kindex show print array
3695 Show whether compressed or pretty format is selected for displaying
3698 @item set print elements @var{number-of-elements}
3699 @kindex set print elements
3700 If GDB is printing a large array, it will stop printing after it has
3701 printed the number of elements set by the @code{set print elements} command.
3702 This limit also applies to the display of strings.
3704 @item show print elements
3705 @kindex show print elements
3706 Display the number of elements of a large array that GDB will print
3707 before losing patience.
3709 @item set print pretty on
3710 @kindex set print pretty
3711 Cause GDB to print structures in an indented format with one member per
3727 @item set print pretty off
3728 Cause GDB to print structures in a compact format, like this:
3732 $1 = @{next = 0x0, flags = @{sweet = 1, sour = 1@}, meat \
3738 This is the default format.
3740 @item show print pretty
3741 @kindex show print pretty
3742 Show which format GDB will use to print structures.
3744 @item set print sevenbit-strings on
3745 @kindex set print sevenbit-strings
3746 Print using only seven-bit characters; if this option is set,
3747 GDB will display any eight-bit characters (in strings or character
3748 values) using the notation @code{\}@var{nnn}. For example, @kbd{M-a} is
3749 displayed as @code{\341}.
3751 @item set print sevenbit-strings off
3752 Print using either seven-bit or eight-bit characters, as required. This
3755 @item show print sevenbit-strings
3756 @kindex show print sevenbit-strings
3757 Show whether or not GDB will print only seven-bit characters.
3759 @item set print union on
3760 @kindex set print union
3761 Tell GDB to print unions which are contained in structures. This is the
3764 @item set print union off
3765 Tell GDB not to print unions which are contained in structures.
3767 @item show print union
3768 @kindex show print union
3769 Ask GDB whether or not it will print unions which are contained in
3772 For example, given the declarations
3775 typedef enum @{Tree, Bug@} Species;
3776 typedef enum @{Big_tree, Acorn, Seedling@} Tree_forms;
3777 typedef enum @{Caterpillar, Cocoon, Butterfly@}
3788 struct thing foo = @{Tree, @{Acorn@}@};
3792 with @code{set print union on} in effect @samp{p foo} would print
3795 $1 = @{it = Tree, form = @{tree = Acorn, bug = Cocoon@}@}
3799 and with @code{set print union off} in effect it would print
3802 $1 = @{it = Tree, form = @{...@}@}
3807 These settings are of interest when debugging C++ programs:
3810 @item set print demangle
3811 @itemx set print demangle on
3812 @kindex set print demangle
3813 Print C++ names in their source form rather than in the mangled form
3814 in which they are passed to the assembler and linker for type-safe linkage.
3817 @item show print demangle
3818 @kindex show print demangle
3819 Show whether C++ names will be printed in mangled or demangled form.
3821 @item set print asm-demangle
3822 @itemx set print asm-demangle on
3823 @kindex set print asm-demangle
3824 Print C++ names in their source form rather than their mangled form, even
3825 in assembler code printouts such as instruction disassemblies.
3828 @item show print asm-demangle
3829 @kindex show print asm-demangle
3830 Show whether C++ names in assembly listings will be printed in mangled
3833 @item set print object
3834 @itemx set print object on
3835 @kindex set print object
3836 When displaying a pointer to an object, identify the @emph{actual}
3837 (derived) type of the object rather than the @emph{declared} type, using
3838 the virtual function table.
3840 @item set print object off
3841 Display only the declared type of objects, without reference to the
3842 virtual function table. This is the default setting.
3844 @item show print object
3845 @kindex show print object
3846 Show whether actual, or declared, object types will be displayed.
3848 @item set print vtbl
3849 @itemx set print vtbl on
3850 @kindex set print vtbl
3851 Pretty print C++ virtual function tables. The default is off.
3853 @item set print vtbl off
3854 Do not pretty print C++ virtual function tables.
3856 @item show print vtbl
3857 @kindex show print vtbl
3858 Show whether C++ virtual function tables are pretty printed, or not.
3861 @node Value History, Convenience Vars, Print Settings, Data
3862 @section Value History
3864 @cindex value history
3865 Values printed by the @code{print} command are saved in GDB's @dfn{value
3866 history} so that you can refer to them in other expressions. Values are
3867 kept until the symbol table is re-read or discarded (for example with
3868 the @code{file} or @code{symbol-file} commands). When the symbol table
3869 changes, the value history is discarded, since the values may contain
3870 pointers back to the types defined in the symbol table.
3874 @cindex history number
3875 The values printed are given @dfn{history numbers} for you to refer to them
3876 by. These are successive integers starting with one. @code{print} shows you
3877 the history number assigned to a value by printing @samp{$@var{num} = }
3878 before the value; here @var{num} is the history number.
3880 To refer to any previous value, use @samp{$} followed by the value's
3881 history number. The way @code{print} labels its output is designed to
3882 remind you of this. Just @code{$} refers to the most recent value in
3883 the history, and @code{$$} refers to the value before that.
3884 @code{$$@var{n}} refers to the @var{n}th value from the end; @code{$$2}
3885 is the value just prior to @code{$$}, @code{$$1} is equivalent to
3886 @code{$$}, and @code{$$0} is equivalent to @code{$}.
3888 For example, suppose you have just printed a pointer to a structure and
3889 want to see the contents of the structure. It suffices to type
3895 If you have a chain of structures where the component @code{next} points
3896 to the next one, you can print the contents of the next one with this:
3903 You can print successive links in the chain by repeating this
3904 command---which you can do by just typing @key{RET}.
3906 Note that the history records values, not expressions. If the value of
3907 @code{x} is 4 and you type these commands:
3915 then the value recorded in the value history by the @code{print} command
3916 remains 4 even though the value of @code{x} has changed.
3921 Print the last ten values in the value history, with their item numbers.
3922 This is like @samp{p@ $$9} repeated ten times, except that @code{show
3923 values} does not change the history.
3925 @item show values @var{n}
3926 Print ten history values centered on history item number @var{n}.
3929 Print ten history values just after the values last printed. If no more
3930 values are available, produces no display.
3933 Pressing @key{RET} to repeat @code{show values @var{n}} has exactly the
3934 same effect as @samp{show values +}.
3936 @node Convenience Vars, Registers, Value History, Data
3937 @section Convenience Variables
3939 @cindex convenience variables
3940 GDB provides @dfn{convenience variables} that you can use within
3941 GDB to hold on to a value and refer to it later. These variables
3942 exist entirely within GDB; they are not part of your program, and
3943 setting a convenience variable has no direct effect on further execution
3944 of your program. That is why you can use them freely.
3946 Convenience variables are prefixed with @samp{$}. Any name preceded by
3947 @samp{$} can be used for a convenience variable, unless it is one of
3948 the predefined machine-specific register names (@pxref{Registers}).
3949 (Value history references, in contrast, are @emph{numbers} preceded
3950 by @samp{$}. @xref{Value History, ,Value History}.)
3952 You can save a value in a convenience variable with an assignment
3953 expression, just as you would set a variable in your program. Example:
3956 set $foo = *object_ptr
3960 would save in @code{$foo} the value contained in the object pointed to by
3963 Using a convenience variable for the first time creates it; but its value
3964 is @code{void} until you assign a new value. You can alter the value with
3965 another assignment at any time.
3967 Convenience variables have no fixed types. You can assign a convenience
3968 variable any type of value, including structures and arrays, even if
3969 that variable already has a value of a different type. The convenience
3970 variable, when used as an expression, has the type of its current value.
3973 @item show convenience
3974 @kindex show convenience
3975 Print a list of convenience variables used so far, and their values.
3976 Abbreviated @code{show con}.
3979 One of the ways to use a convenience variable is as a counter to be
3980 incremented or a pointer to be advanced. For example, to print
3981 a field from successive elements of an array of structures:
3985 print bar[$i++]->contents
3986 @i{@dots{} repeat that command by typing @key{RET}.}
3989 Some convenience variables are created automatically by GDB and given
3990 values likely to be useful.
3995 The variable @code{$_} is automatically set by the @code{x} command to
3996 the last address examined (@pxref{Memory, ,Examining Memory}). Other
3997 commands which provide a default address for @code{x} to examine also
3998 set @code{$_} to that address; these commands include @code{info line}
3999 and @code{info breakpoint}. The type of @code{$_} is @code{void *}
4000 except when set by the @code{x} command, in which case it is a pointer
4001 to the type of @code{$__}.
4005 The variable @code{$__} is automatically set by the @code{x} command
4006 to the value found in the last address examined. Its type is chosen
4007 to match the format in which the data was printed.
4010 @node Registers, Floating Point Hardware, Convenience Vars, Data
4014 You can refer to machine register contents, in expressions, as variables
4015 with names starting with @samp{$}. The names of registers are different
4016 for each machine; use @code{info registers} to see the names used on
4020 @item info registers
4021 @kindex info registers
4022 Print the names and values of all registers except floating-point
4023 registers (in the selected stack frame).
4025 @item info all-registers
4026 @kindex info all-registers
4027 @cindex floating point registers
4028 Print the names and values of all registers, including floating-point
4031 @item info registers @var{regname}
4032 Print the relativized value of register @var{regname}. @var{regname}
4033 may be any register name valid on the machine you are using, with
4034 or without the initial @samp{$}.
4037 GDB has four ``standard'' register names that are available (in
4038 expressions) on most machines---whenever they do not conflict with an
4039 architecture's canonical mnemonics for registers. The register names
4040 @code{$pc} and @code{$sp} are used for the program counter register and
4041 the stack pointer. @code{$fp} is used for a register that contains a
4042 pointer to the current stack frame, and @code{$ps} is used for a
4043 register that contains the processor status. For example,
4044 you could print the program counter in hex with
4051 or print the instruction to be executed next with
4058 or add four to the stack pointer @footnote{This is a way of removing
4059 one word from the stack, on machines where stacks grow downward in
4060 memory (most machines, nowadays). This assumes that the innermost
4061 stack frame is selected; setting @code{$sp} is not allowed when other
4062 stack frames are selected. To pop entire frames off the stack,
4063 regardless of machine architecture, use @code{return};
4064 @pxref{Returning, ,Returning from a Function}.} with
4070 Whenever possible, these four standard register names are available on
4071 your machine even though the machine has different canonical mnemonics,
4072 so long as there is no conflict. The @code{info registers} command
4073 shows the canonical names. For example, on the SPARC, @code{info
4074 registers} displays the processor status register as @code{$psr} but you
4075 can also refer to it as @code{$ps}.
4077 GDB always considers the contents of an ordinary register as an
4078 integer when the register is examined in this way. Some machines have
4079 special registers which can hold nothing but floating point; these
4080 registers are considered to have floating point values. There is no way
4081 to refer to the contents of an ordinary register as floating point value
4082 (although you can @emph{print} it as a floating point value with
4083 @samp{print/f $@var{regname}}).
4085 Some registers have distinct ``raw'' and ``virtual'' data formats. This
4086 means that the data format in which the register contents are saved by
4087 the operating system is not the same one that your program normally
4088 sees. For example, the registers of the 68881 floating point
4089 coprocessor are always saved in ``extended'' (raw) format, but all C
4090 programs expect to work with ``double'' (virtual) format. In such
4091 cases, GDB normally works with the virtual format only (the format that
4092 makes sense for your program), but the @code{info registers} command
4093 prints the data in both formats.
4095 Normally, register values are relative to the selected stack frame
4096 (@pxref{Selection, ,Selecting a Frame}). This means that you get the
4097 value that the register would contain if all stack frames farther in
4098 were exited and their saved registers restored. In order to see the
4099 true contents of hardware registers, you must select the innermost
4100 frame (with @samp{frame 0}).
4102 However, GDB must deduce where registers are saved, from the machine
4103 code generated by your compiler. If some registers are not saved, or if
4104 GDB is unable to locate the saved registers, the selected stack
4105 frame will make no difference.
4107 @node Floating Point Hardware, , Registers, Data
4108 @section Floating Point Hardware
4109 @cindex floating point
4111 Depending on the host machine architecture, GDB may be able to give
4112 you more information about the status of the floating point hardware.
4117 If available, provides hardware-dependent information about the floating
4118 point unit. The exact contents and layout vary depending on the
4119 floating point chip.
4121 @c FIXME: this is a cop-out. Try to get examples, explanations. Only
4122 @c FIXME...supported currently on arm's and 386's. Mark properly with
4123 @c FIXME... m4 macros to isolate general statements from hardware-dep,
4124 @c FIXME... at that point.
4126 @node Languages, Symbols, Data, Top
4127 @chapter Using GDB with Different Languages
4130 Although programming languages generally have common aspects, they are
4131 rarely expressed in the same manner. For instance, in ANSI C,
4132 dereferencing a pointer @code{p} is accomplished by @code{*p}, but in
4133 Modula-2, it is accomplished by @code{p^}. Values can also be
4134 represented (and displayed) differently. Hex numbers in C are written
4135 like @samp{0x1ae}, while in Modula-2 they appear as @samp{1AEH}.
4137 @cindex working language
4138 Language-specific information is built into GDB for some languages,
4139 allowing you to express operations like the above in your program's
4140 native language, and allowing GDB to output values in a manner
4141 consistent with the syntax of your program's native language. The
4142 language you use to build expressions, called the @dfn{working
4143 language}, can be selected manually, or GDB can set it
4147 * Setting:: Switching between source languages
4148 * Show:: Displaying the language
4149 * Checks:: Type and Range checks
4150 * Support:: Supported languages
4153 @node Setting, Show, Languages, Languages
4154 @section Switching between source languages
4156 There are two ways to control the working language---either have GDB
4157 set it automatically, or select it manually yourself. You can use the
4158 @code{set language} command for either purpose. On startup, GDB
4159 defaults to setting the language automatically.
4162 * Manually:: Setting the working language manually
4163 * Automatically:: Having GDB infer the source language
4166 @node Manually, Automatically, Setting, Setting
4167 @subsection Setting the working language
4169 @kindex set language
4170 To set the language, issue the command @samp{set language @var{lang}},
4171 where @var{lang} is the name of a language: @code{c} or @code{modula-2}.
4172 For a list of the supported languages, type @samp{set language}.
4174 Setting the language manually prevents GDB from updating the working
4175 language automatically. This can lead to confusion if you try
4176 to debug a program when the working language is not the same as the
4177 source language, when an expression is acceptable to both
4178 languages---but means different things. For instance, if the current
4179 source file were written in C, and GDB was parsing Modula-2, a
4187 might not have the effect you intended. In C, this means to add
4188 @code{b} and @code{c} and place the result in @code{a}. The result
4189 printed would be the value of @code{a}. In Modula-2, this means to compare
4190 @code{a} to the result of @code{b+c}, yielding a @code{BOOLEAN} value.
4192 If you allow GDB to set the language automatically, then
4193 you can count on expressions evaluating the same way in your debugging
4194 session and in your program.
4196 @node Automatically, , Manually, Setting
4197 @subsection Having GDB infer the source language
4199 To have GDB set the working language automatically, use @samp{set
4200 language local} or @samp{set language auto}. GDB then infers the
4201 language that a program was written in by looking at the name of its
4202 source files, and examining their extensions:
4206 Modula-2 source file
4210 C or C++ source file.
4213 This information is recorded for each function or procedure in a source
4214 file. When your program stops in a frame (usually by encountering a
4215 breakpoint), GDB sets the working language to the language recorded
4216 for the function in that frame. If the language for a frame is unknown
4217 (that is, if the function or block corresponding to the frame was
4218 defined in a source file that does not have a recognized extension), the
4219 current working language is not changed, and GDB issues a warning.
4221 This may not seem necessary for most programs, which are written
4222 entirely in one source language. However, program modules and libraries
4223 written in one source language can be used by a main program written in
4224 a different source language. Using @samp{set language auto} in this
4225 case frees you from having to set the working language manually.
4227 @node Show, Checks, Setting, Languages
4228 @section Displaying the language
4230 The following commands will help you find out which language is the
4231 working language, and also what language source files were written in.
4233 @kindex show language
4238 Display the current working language. This is the
4239 language you can use with commands such as @code{print} to
4240 build and compute expressions that may involve variables in your program.
4243 Among the other information listed here (@pxref{Frame Info, ,Information
4244 about a Frame}) is the source language for this frame. This is the
4245 language that will become the working language if you ever use an
4246 identifier that is in this frame.
4249 Among the other information listed here (@pxref{Symbols, ,Examining the
4250 Symbol Table}) is the source language of this source file.
4253 @node Checks, Support, Show, Languages
4254 @section Type and range Checking
4257 @emph{Warning:} In this release, the GDB commands for type and range
4258 checking are included, but they do not yet have any effect. This
4259 section documents the intended facilities.
4261 @c FIXME remove warning when type/range code added
4263 Some languages are designed to guard you against making seemingly common
4264 errors through a series of compile- and run-time checks. These include
4265 checking the type of arguments to functions and operators, and making
4266 sure mathematical overflows are caught at run time. Checks such as
4267 these help to ensure a program's correctness once it has been compiled
4268 by eliminating type mismatches, and providing active checks for range
4269 errors when your program is running.
4271 GDB can check for conditions like the above if you wish.
4272 Although GDB will not check the statements in your program, it
4273 can check expressions entered directly into GDB for evaluation via
4274 the @code{print} command, for example. As with the working language,
4275 GDB can also decide whether or not to check automatically based on
4276 your program's source language. @xref{Support, ,Supported Languages},
4277 for the default settings of supported languages.
4280 * Type Checking:: An overview of type checking
4281 * Range Checking:: An overview of range checking
4284 @cindex type checking
4285 @cindex checks, type
4286 @node Type Checking, Range Checking, Checks, Checks
4287 @subsection An overview of type checking
4289 Some languages, such as Modula-2, are strongly typed, meaning that the
4290 arguments to operators and functions have to be of the correct type,
4291 otherwise an error occurs. These checks prevent type mismatch
4292 errors from ever causing any run-time problems. For example,
4300 The second example fails because the @code{CARDINAL} 1 is not
4301 type-compatible with the @code{REAL} 2.3.
4303 For expressions you use in GDB commands, you can tell the GDB
4304 type checker to skip checking; to treat any mismatches as errors and
4305 abandon the expression; or only issue warnings when type mismatches
4306 occur, but evaluate the expression anyway. When you choose the last of
4307 these, GDB evaluates expressions like the second example above, but
4308 also issues a warning.
4310 Even though you may turn type checking off, other type-based reasons may
4311 prevent GDB from evaluating an expression. For instance, GDB does not
4312 know how to add an @code{int} and a @code{struct foo}. These particular
4313 type errors have nothing to do with the language in use, and usually
4314 arise from expressions, such as the one described above, which make
4315 little sense to evaluate anyway.
4317 Each language defines to what degree it is strict about type. For
4318 instance, both Modula-2 and C require the arguments to arithmetical
4319 operators to be numbers. In C, enumerated types and pointers can be
4320 represented as numbers, so that they are valid arguments to mathematical
4321 operators. @xref{Support, ,Supported Languages}, for further
4322 details on specific languages.
4324 GDB provides some additional commands for controlling the type checker:
4327 @kindex set check type
4328 @kindex show check type
4330 @item set check type auto
4331 Set type checking on or off based on the current working language.
4332 @xref{Support, ,Supported Languages}, for the default settings for
4335 @item set check type on
4336 @itemx set check type off
4337 Set type checking on or off, overriding the default setting for the
4338 current working language. Issue a warning if the setting does not
4339 match the language's default. If any type mismatches occur in
4340 evaluating an expression while typechecking is on, GDB prints a
4341 message and aborts evaluation of the expression.
4343 @item set check type warn
4344 Cause the type checker to issue warnings, but to always attempt to
4345 evaluate the expression. Evaluating the expression may still
4346 be impossible for other reasons. For example, GDB cannot add
4347 numbers and structures.
4350 Show the current setting of the type checker, and whether or not GDB is
4351 setting it automatically.
4354 @cindex range checking
4355 @cindex checks, range
4356 @node Range Checking, , Type Checking, Checks
4357 @subsection An overview of Range Checking
4359 In some languages (such as Modula-2), it is an error to exceed the
4360 bounds of a type; this is enforced with run-time checks. Such range
4361 checking is meant to ensure program correctness by making sure
4362 computations do not overflow, or indices on an array element access do
4363 not exceed the bounds of the array.
4365 For expressions you use in GDB commands, you can tell GDB to
4366 ignore range errors; to always treat them as errors and abandon the
4367 expression; or to issue warnings when a range error occurs but evaluate
4368 the expression anyway.
4370 A range error can result from numerical overflow, from exceeding an
4371 array index bound, or when you type in a constant that is not a member
4372 of any type. Some languages, however, do not treat overflows as an
4373 error. In many implementations of C, mathematical overflow causes the
4374 result to ``wrap around'' to lower values---for example, if @var{m} is
4375 the largest integer value, and @var{s} is the smallest, then
4378 @var{m} + 1 @result{} @var{s}
4381 This, too, is specific to individual languages, and in some cases
4382 specific to individual compilers or machines. @xref{Support, ,
4383 Supported Languages}, for further details on specific languages.
4385 GDB provides some additional commands for controlling the range checker:
4388 @kindex set check range
4389 @kindex show check range
4391 @item set check range auto
4392 Set range checking on or off based on the current working language.
4393 @xref{Support, ,Supported Languages}, for the default settings for
4396 @item set check range on
4397 @itemx set check range off
4398 Set range checking on or off, overriding the default setting for the
4399 current working language. A warning is issued if the setting does not
4400 match the language's default. If a range error occurs, then a message
4401 is printed and evaluation of the expression is aborted.
4403 @item set check range warn
4404 Output messages when the GDB range checker detects a range error,
4405 but attempt to evaluate the expression anyway. Evaluating the
4406 expression may still be impossible for other reasons, such as accessing
4407 memory that the process does not own (a typical example from many UNIX
4411 Show the current setting of the range checker, and whether or not it is
4412 being set automatically by GDB.
4415 @node Support, , Checks, Languages
4416 @section Supported Languages
4418 GDB 4 supports C, C++, and Modula-2. The syntax for C and C++ is so
4419 closely related that GDB does not distinguish the two. Some GDB
4420 features may be used in expressions regardless of the language you
4421 use: the GDB @code{@@} and @code{::} operators, and the
4422 @samp{@{type@}addr} construct (@pxref{Expressions, ,Expressions}) can be
4423 used with the constructs of any of the supported languages.
4425 The following sections detail to what degree each of these
4426 source languages is supported by GDB. These sections are
4427 not meant to be language tutorials or references, but serve only as a
4428 reference guide to what the GDB expression parser will accept, and
4429 what input and output formats should look like for different languages.
4430 There are many good books written on each of these languages; please
4431 look to these for a language reference or tutorial.
4435 * Modula-2:: Modula-2
4438 @node C, Modula-2, Support, Support
4439 @subsection C and C++
4442 @cindex expressions in C or C++
4443 Since C and C++ are so closely related, GDB does not distinguish
4444 between them when interpreting the expressions recognized in GDB
4450 The C++ debugging facilities are jointly implemented by the GNU C++
4451 compiler and GDB. Therefore, to debug your C++ code effectively,
4452 you must compile your C++ programs with the GNU C++ compiler,
4456 * C Operators:: C and C++ Operators
4457 * C Constants:: C and C++ Constants
4458 * Cplusplus expressions:: C++ Expressions
4459 * C Defaults:: Default settings for C and C++
4460 * C Checks:: C and C++ Type and Range Checks
4461 * Debugging C:: GDB and C
4462 * Debugging C plus plus:: Special features for C++
4465 @cindex C and C++ operators
4466 @node C Operators, C Constants, C, C
4467 @subsubsection C and C++ Operators
4469 Operators must be defined on values of specific types. For instance,
4470 @code{+} is defined on numbers, but not on structures. Operators are
4471 often defined on groups of types. For the purposes of C and C++, the
4472 following definitions hold:
4476 @emph{Integral types} include @code{int} with any of its storage-class
4477 specifiers, @code{char}, and @code{enum}s.
4480 @emph{Floating-point types} include @code{float} and @code{double}.
4483 @emph{Pointer types} include all types defined as @code{(@var{type}
4487 @emph{Scalar types} include all of the above.
4491 The following operators are supported. They are listed here
4492 in order of increasing precedence:
4496 The comma or sequencing operator. Expressions in a comma-separated list
4497 are evaluated from left to right, with the result of the entire
4498 expression being the last expression evaluated.
4501 Assignment. The value of an assignment expression is the value
4502 assigned. Defined on scalar types.
4505 Used in an expression of the form @w{@code{@var{a} @var{op}= @var{b}}},
4506 and translated to @w{@code{@var{a} = @var{a op b}}}.
4507 @w{@code{@var{op}=}} and @code{=} have the same precendence.
4508 @var{op} is any one of the operators @code{|}, @code{^}, @code{&},
4509 @code{<<}, @code{>>}, @code{+}, @code{-}, @code{*}, @code{/}, @code{%}.
4512 The ternary operator. @code{@var{a} ? @var{b} : @var{c}} can be thought
4513 of as: if @var{a} then @var{b} else @var{c}. @var{a} should be of an
4517 Logical @sc{or}. Defined on integral types.
4520 Logical @sc{and}. Defined on integral types.
4523 Bitwise @sc{or}. Defined on integral types.
4526 Bitwise exclusive-@sc{or}. Defined on integral types.
4529 Bitwise @sc{and}. Defined on integral types.
4532 Equality and inequality. Defined on scalar types. The value of these
4533 expressions is 0 for false and non-zero for true.
4535 @item <@r{, }>@r{, }<=@r{, }>=
4536 Less than, greater than, less than or equal, greater than or equal.
4537 Defined on scalar types. The value of these expressions is 0 for false
4538 and non-zero for true.
4541 left shift, and right shift. Defined on integral types.
4544 The GDB ``artificial array'' operator (@pxref{Expressions, ,Expressions}).
4547 Addition and subtraction. Defined on integral types, floating-point types and
4550 @item *@r{, }/@r{, }%
4551 Multiplication, division, and modulus. Multiplication and division are
4552 defined on integral and floating-point types. Modulus is defined on
4556 Increment and decrement. When appearing before a variable, the
4557 operation is performed before the variable is used in an expression;
4558 when appearing after it, the variable's value is used before the
4559 operation takes place.
4562 Pointer dereferencing. Defined on pointer types. Same precedence as
4566 Address operator. Defined on variables. Same precedence as @code{++}.
4569 Negative. Defined on integral and floating-point types. Same
4570 precedence as @code{++}.
4573 Logical negation. Defined on integral types. Same precedence as
4577 Bitwise complement operator. Defined on integral types. Same precedence as
4581 Structure member, and pointer-to-structure member. For convenience,
4582 GDB regards the two as equivalent, choosing whether to dereference a
4583 pointer based on the stored type information.
4584 Defined on @code{struct}s and @code{union}s.
4587 Array indexing. @code{@var{a}[@var{i}]} is defined as
4588 @code{*(@var{a}+@var{i})}. Same precedence as @code{->}.
4591 Function parameter list. Same precedence as @code{->}.
4594 C++ scope resolution operator. Defined on
4595 @code{struct}, @code{union}, and @code{class} types.
4598 The GDB scope operator (@pxref{Expressions, ,Expressions}). Same precedence as
4602 @cindex C and C++ constants
4603 @node C Constants, Cplusplus expressions, C Operators, C
4604 @subsubsection C and C++ Constants
4606 GDB allows you to express the constants of C and C++ in the
4611 Integer constants are a sequence of digits. Octal constants are
4612 specified by a leading @samp{0} (ie. zero), and hexadecimal constants by
4613 a leading @samp{0x} or @samp{0X}. Constants may also end with a letter
4614 @samp{l}, specifying that the constant should be treated as a
4618 Floating point constants are a sequence of digits, followed by a decimal
4619 point, followed by a sequence of digits, and optionally followed by an
4620 exponent. An exponent is of the form:
4621 @samp{@w{e@r{[[}+@r{]|}-@r{]}@var{nnn}}}, where @var{nnn} is another
4622 sequence of digits. The @samp{+} is optional for positive exponents.
4625 Enumerated constants consist of enumerated identifiers, or their
4626 integral equivalents.
4629 Character constants are a single character surrounded by single quotes
4630 (@code{'}), or a number---the ordinal value of the corresponding character
4631 (usually its @sc{ASCII} value). Within quotes, the single character may
4632 be represented by a letter or by @dfn{escape sequences}, which are of
4633 the form @samp{\@var{nnn}}, where @var{nnn} is the octal representation
4634 of the character's ordinal value; or of the form @samp{\@var{x}}, where
4635 @samp{@var{x}} is a predefined special character---for example,
4636 @samp{\n} for newline.
4639 String constants are a sequence of character constants surrounded
4640 by double quotes (@code{"}).
4643 Pointer constants are an integral value.
4646 @node Cplusplus expressions, C Defaults, C Constants, C
4647 @subsubsection C++ Expressions
4649 @cindex expressions in C++
4650 GDB's expression handling has the following extensions to
4651 interpret a significant subset of C++ expressions:
4655 @cindex member functions
4657 Member function calls are allowed; you can use expressions like
4660 count = aml->GetOriginal(x, y)
4664 @cindex namespace in C++
4666 While a member function is active (in the selected stack frame), your
4667 expressions have the same namespace available as the member function;
4668 that is, GDB allows implicit references to the class instance
4669 pointer @code{this} following the same rules as C++.
4671 @cindex call overloaded functions
4672 @cindex type conversions in C++
4674 You can call overloaded functions; GDB will resolve the function
4675 call to the right definition, with one restriction---you must use
4676 arguments of the type required by the function that you want to call.
4677 GDB will not perform conversions requiring constructors or
4678 user-defined type operators.
4680 @cindex reference declarations
4682 GDB understands variables declared as C++ references; you can use them in
4683 expressions just as you do in C++ source---they are automatically
4686 In the parameter list shown when GDB displays a frame, the values of
4687 reference variables are not displayed (unlike other variables); this
4688 avoids clutter, since references are often used for large structures.
4689 The @emph{address} of a reference variable is always shown, unless
4690 you have specified @samp{set print address off}.
4693 GDB supports the C++ name resolution operator @code{::}---your
4694 expressions can use it just as expressions in your program do. Since
4695 one scope may be defined in another, you can use @code{::} repeatedly if
4696 necessary, for example in an expression like
4697 @samp{@var{scope1}::@var{scope2}::@var{name}}. GDB also allows
4698 resolving name scope by reference to source files, in both C and C++
4699 debugging (@pxref{Variables, ,Program Variables}).
4702 @node C Defaults, C Checks, Cplusplus expressions, C
4703 @subsubsection C and C++ Defaults
4704 @cindex C and C++ defaults
4706 If you allow GDB to set type and range checking automatically, they
4707 both default to @code{off} whenever the working language changes to
4708 C/C++. This happens regardless of whether you, or GDB,
4709 selected the working language.
4711 If you allow GDB to set the language automatically, it sets the
4712 working language to C/C++ on entering code compiled from a source file
4713 whose name ends with @file{.c} or @file{.cc}.
4714 @xref{Automatically, ,Having GDB infer the source language}, for
4717 @node C Checks, Debugging C, C Defaults, C
4718 @subsubsection C and C++ Type and Range Checks
4719 @cindex C and C++ checks
4722 @emph{Warning:} in this release, GDB does not yet perform type or
4725 @c FIXME remove warning when type/range checks added
4727 By default, when GDB parses C or C++ expressions, type checking
4728 is not used. However, if you turn type checking on, GDB will
4729 consider two variables type equivalent if:
4733 The two variables are structured and have the same structure, union, or
4737 Two two variables have the same type name, or types that have been
4738 declared equivalent through @code{typedef}.
4741 @c leaving this out because neither J Gilmore nor R Pesch understand it.
4744 The two @code{struct}, @code{union}, or @code{enum} variables are
4745 declared in the same declaration. (Note: this may not be true for all C
4750 Range checking, if turned on, is done on mathematical operations. Array
4751 indices are not checked, since they are often used to index a pointer
4752 that is not itself an array.
4754 @node Debugging C, Debugging C plus plus, C Checks, C
4755 @subsubsection GDB and C
4757 The @code{set print union} and @code{show print union} commands apply to
4758 the @code{union} type. When set to @samp{on}, any @code{union} that is
4759 inside a @code{struct} or @code{class} will also be printed.
4760 Otherwise, it will appear as @samp{@{...@}}.
4762 The @code{@@} operator aids in the debugging of dynamic arrays, formed
4763 with pointers and a memory allocation function. (@pxref{Expressions, ,Expressions})
4765 @node Debugging C plus plus, , Debugging C, C
4766 @subsubsection GDB Commands for C++
4768 @cindex commands for C++
4769 Some GDB commands are particularly useful with C++, and some are
4770 designed specifically for use with C++. Here is a summary:
4773 @cindex break in overloaded functions
4774 @item @r{breakpoint menus}
4775 When you want a breakpoint in a function whose name is overloaded,
4776 GDB's breakpoint menus help you specify which function definition
4777 you want. @xref{Breakpoint Menus}.
4779 @cindex overloading in C++
4780 @item rbreak @var{regex}
4781 Setting breakpoints using regular expressions is helpful for setting
4782 breakpoints on overloaded functions that are not members of any special
4784 @xref{Set Breaks, ,Setting Breakpoints}.
4786 @cindex C++ exception handling
4787 @item catch @var{exceptions}
4789 Debug C++ exception handling using these commands. @xref{Exception
4790 Handling, ,Breakpoints and Exceptions}.
4793 @item ptype @var{typename}
4794 Print inheritance relationships as well as other information for type
4796 @xref{Symbols, ,Examining the Symbol Table}.
4798 @cindex C++ symbol display
4799 @item set print demangle
4800 @itemx show print demangle
4801 @itemx set print asm-demangle
4802 @itemx show print asm-demangle
4803 Control whether C++ symbols display in their source form, both when
4804 displaying code as C++ source and when displaying disassemblies.
4805 @xref{Print Settings, ,Print Settings}.
4807 @item set print object
4808 @itemx show print object
4809 Choose whether to print derived (actual) or declared types of objects.
4810 @xref{Print Settings, ,Print Settings}.
4812 @item set print vtbl
4813 @itemx show print vtbl
4814 Control the format for printing virtual function tables.
4815 @xref{Print Settings, ,Print Settings}.
4818 @node Modula-2, , C, Support
4819 @subsection Modula-2
4822 The extensions made to GDB to support Modula-2 support output
4823 from the GNU Modula-2 compiler (which is currently being developed).
4824 Other Modula-2 compilers are not currently supported, and attempting to
4825 debug executables produced by them will most likely result in an error
4826 as GDB reads in the executable's symbol table.
4828 @cindex expressions in Modula-2
4830 * M2 Operators:: Built-in operators
4831 * Built-In Func/Proc:: Built-in Functions and Procedures
4832 * M2 Constants:: Modula-2 Constants
4833 * M2 Defaults:: Default settings for Modula-2
4834 * Deviations:: Deviations from standard Modula-2
4835 * M2 Checks:: Modula-2 Type and Range Checks
4836 * M2 Scope:: The scope operators @code{::} and @code{.}
4837 * GDB/M2:: GDB and Modula-2
4840 @node M2 Operators, Built-In Func/Proc, Modula-2, Modula-2
4841 @subsubsection Operators
4842 @cindex Modula-2 operators
4844 Operators must be defined on values of specific types. For instance,
4845 @code{+} is defined on numbers, but not on structures. Operators are
4846 often defined on groups of types. For the purposes of Modula-2, the
4847 following definitions hold:
4852 @emph{Integral types} consist of @code{INTEGER}, @code{CARDINAL}, and
4856 @emph{Character types} consist of @code{CHAR} and its subranges.
4859 @emph{Floating-point types} consist of @code{REAL}.
4862 @emph{Pointer types} consist of anything declared as @code{POINTER TO
4866 @emph{Scalar types} consist of all of the above.
4869 @emph{Set types} consist of @code{SET}s and @code{BITSET}s.
4872 @emph{Boolean types} consist of @code{BOOLEAN}.
4876 The following operators are supported, and appear in order of
4877 increasing precedence:
4881 Function argument or array index separator.
4884 Assignment. The value of @var{var} @code{:=} @var{value} is
4888 Less than, greater than on integral, floating-point, or enumerated
4892 Less than, greater than, less than or equal to, greater than or equal to
4893 on integral, floating-point and enumerated types, or set inclusion on
4894 set types. Same precedence as @code{<}.
4896 @item =@r{, }<>@r{, }#
4897 Equality and two ways of expressing inequality, valid on scalar types.
4898 Same precedence as @code{<}. In GDB scripts, only @code{<>} is
4899 available for inequality, since @code{#} conflicts with the script
4903 Set membership. Defined on set types and the types of their members.
4904 Same precedence as @code{<}.
4907 Boolean disjunction. Defined on boolean types.
4910 Boolean conjuction. Defined on boolean types.
4913 The GDB ``artificial array'' operator (@pxref{Expressions, ,Expressions}).
4916 Addition and subtraction on integral and floating-point types, or union
4917 and difference on set types.
4920 Multiplication on integral and floating-point types, or set intersection
4924 Division on floating-point types, or symmetric set difference on set
4925 types. Same precedence as @code{*}.
4928 Integer division and remainder. Defined on integral types. Same
4929 precedence as @code{*}.
4932 Negative. Defined on @code{INTEGER}s and @code{REAL}s.
4935 Pointer dereferencing. Defined on pointer types.
4938 Boolean negation. Defined on boolean types. Same precedence as
4942 @code{RECORD} field selector. Defined on @code{RECORD}s. Same
4943 precedence as @code{^}.
4946 Array indexing. Defined on @code{ARRAY}s. Same precedence as @code{^}.
4949 Procedure argument list. Defined on @code{PROCEDURE}s. Same precedence
4953 GDB and Modula-2 scope operators.
4957 @emph{Warning:} Sets and their operations are not yet supported, so GDB
4958 will treat the use of the operator @code{IN}, or the use of operators
4959 @code{+}, @code{-}, @code{*}, @code{/}, @code{=}, , @code{<>}, @code{#},
4960 @code{<=}, and @code{>=} on sets as an error.
4963 @cindex Modula-2 built-ins
4964 @node Built-In Func/Proc, M2 Constants, M2 Operators, Modula-2
4965 @subsubsection Built-in Functions and Procedures
4967 Modula-2 also makes available several built-in procedures and functions.
4968 In describing these, the following metavariables are used:
4973 represents an @code{ARRAY} variable.
4976 represents a @code{CHAR} constant or variable.
4979 represents a variable or constant of integral type.
4982 represents an identifier that belongs to a set. Generally used in the
4983 same function with the metavariable @var{s}. The type of @var{s} should
4984 be @code{SET OF @var{mtype}} (where @var{mtype} is the type of @var{m}.
4987 represents a variable or constant of integral or floating-point type.
4990 represents a variable or constant of floating-point type.
4996 represents a variable.
4999 represents a variable or constant of one of many types. See the
5000 explanation of the function for details.
5003 All Modula-2 built-in procedures also return a result, described below.
5007 Returns the absolute value of @var{n}.
5010 If @var{c} is a lower case letter, it returns its upper case
5011 equivalent, otherwise it returns its argument
5014 Returns the character whose ordinal value is @var{i}.
5017 Decrements the value in the variable @var{v}. Returns the new value.
5019 @item DEC(@var{v},@var{i})
5020 Decrements the value in the variable @var{v} by @var{i}. Returns the
5023 @item EXCL(@var{m},@var{s})
5024 Removes the element @var{m} from the set @var{s}. Returns the new
5027 @item FLOAT(@var{i})
5028 Returns the floating point equivalent of the integer @var{i}.
5031 Returns the index of the last member of @var{a}.
5034 Increments the value in the variable @var{v}. Returns the new value.
5036 @item INC(@var{v},@var{i})
5037 Increments the value in the variable @var{v} by @var{i}. Returns the
5040 @item INCL(@var{m},@var{s})
5041 Adds the element @var{m} to the set @var{s} if it is not already
5042 there. Returns the new set.
5045 Returns the maximum value of the type @var{t}.
5048 Returns the minimum value of the type @var{t}.
5051 Returns boolean TRUE if @var{i} is an odd number.
5054 Returns the ordinal value of its argument. For example, the ordinal
5055 value of a character is its ASCII value (on machines supporting the
5056 ASCII character set). @var{x} must be of an ordered type, which include
5057 integral, character and enumerated types.
5060 Returns the size of its argument. @var{x} can be a variable or a type.
5062 @item TRUNC(@var{r})
5063 Returns the integral part of @var{r}.
5065 @item VAL(@var{t},@var{i})
5066 Returns the member of the type @var{t} whose ordinal value is @var{i}.
5070 @emph{Warning:} Sets and their operations are not yet supported, so
5071 GDB will treat the use of procedures @code{INCL} and @code{EXCL} as
5075 @cindex Modula-2 constants
5076 @node M2 Constants, M2 Defaults, Built-In Func/Proc, Modula-2
5077 @subsubsection Constants
5079 GDB allows you to express the constants of Modula-2 in the following
5085 Integer constants are simply a sequence of digits. When used in an
5086 expression, a constant is interpreted to be type-compatible with the
5087 rest of the expression. Hexadecimal integers are specified by a
5088 trailing @samp{H}, and octal integers by a trailing @samp{B}.
5091 Floating point constants appear as a sequence of digits, followed by a
5092 decimal point and another sequence of digits. An optional exponent can
5093 then be specified, in the form @samp{E@r{[}+@r{|}-@r{]}@var{nnn}}, where
5094 @samp{@r{[}+@r{|}-@r{]}@var{nnn}} is the desired exponent. All of the
5095 digits of the floating point constant must be valid decimal (base 10)
5099 Character constants consist of a single character enclosed by a pair of
5100 like quotes, either single (@code{'}) or double (@code{"}). They may
5101 also be expressed by their ordinal value (their ASCII value, usually)
5102 followed by a @samp{C}.
5105 String constants consist of a sequence of characters enclosed by a
5106 pair of like quotes, either single (@code{'}) or double (@code{"}).
5107 Escape sequences in the style of C are also allowed. @xref{C
5108 Constants, ,C and C++ Constants}, for a brief explanation of escape
5112 Enumerated constants consist of an enumerated identifier.
5115 Boolean constants consist of the identifiers @code{TRUE} and
5119 Pointer constants consist of integral values only.
5122 Set constants are not yet supported.
5125 @node M2 Defaults, Deviations, M2 Constants, Modula-2
5126 @subsubsection Modula-2 Defaults
5127 @cindex Modula-2 defaults
5129 If type and range checking are set automatically by GDB, they
5130 both default to @code{on} whenever the working language changes to
5131 Modula-2. This happens regardless of whether you, or GDB,
5132 selected the working language.
5134 If you allow GDB to set the language automatically, then entering
5135 code compiled from a file whose name ends with @file{.mod} will set the
5136 working language to Modula-2. @xref{Automatically, ,Having GDB set
5137 the language automatically}, for further details.
5139 @node Deviations, M2 Checks, M2 Defaults, Modula-2
5140 @subsubsection Deviations from Standard Modula-2
5141 @cindex Modula-2, deviations from
5143 A few changes have been made to make Modula-2 programs easier to debug.
5144 This is done primarily via loosening its type strictness:
5148 Unlike in standard Modula-2, pointer constants can be formed by
5149 integers. This allows you to modify pointer variables during
5150 debugging. (In standard Modula-2, the actual address contained in a
5151 pointer variable is hidden from you; it can only be modified
5152 through direct assignment to another pointer variable or expression that
5153 returned a pointer.)
5156 C escape sequences can be used in strings and characters to represent
5157 non-printable characters. GDB will print out strings with these
5158 escape sequences embedded. Single non-printable characters are
5159 printed using the @samp{CHR(@var{nnn})} format.
5162 The assignment operator (@code{:=}) returns the value of its right-hand
5166 All built-in procedures both modify @emph{and} return their argument.
5169 @node M2 Checks, M2 Scope, Deviations, Modula-2
5170 @subsubsection Modula-2 Type and Range Checks
5171 @cindex Modula-2 checks
5174 @emph{Warning:} in this release, GDB does not yet perform type or
5177 @c FIXME remove warning when type/range checks added
5179 GDB considers two Modula-2 variables type equivalent if:
5183 They are of types that have been declared equivalent via a @code{TYPE
5184 @var{t1} = @var{t2}} statement
5187 They have been declared on the same line. (Note: This is true of the
5188 GNU Modula-2 compiler, but it may not be true of other compilers.)
5191 As long as type checking is enabled, any attempt to combine variables
5192 whose types are not equivalent is an error.
5194 Range checking is done on all mathematical operations, assignment, array
5195 index bounds, and all built-in functions and procedures.
5197 @node M2 Scope, GDB/M2, M2 Checks, Modula-2
5198 @subsubsection The scope operators @code{::} and @code{.}
5201 @cindex colon, doubled as scope operator
5204 @c Info cannot handoe :: but TeX can.
5210 There are a few subtle differences between the Modula-2 scope operator
5211 (@code{.}) and the GDB scope operator (@code{::}). The two have
5216 @var{module} . @var{id}
5217 @var{scope} :: @var{id}
5221 where @var{scope} is the name of a module or a procedure,
5222 @var{module} the name of a module, and @var{id} is any declared
5223 identifier within your program, except another module.
5225 Using the @code{::} operator makes GDB search the scope
5226 specified by @var{scope} for the identifier @var{id}. If it is not
5227 found in the specified scope, then GDB will search all scopes
5228 enclosing the one specified by @var{scope}.
5230 Using the @code{.} operator makes GDB search the current scope for
5231 the identifier specified by @var{id} that was imported from the
5232 definition module specified by @var{module}. With this operator, it is
5233 an error if the identifier @var{id} was not imported from definition
5234 module @var{module}, or if @var{id} is not an identifier in
5237 @node GDB/M2, , M2 Scope, Modula-2
5238 @subsubsection GDB and Modula-2
5240 Some GDB commands have little use when debugging Modula-2 programs.
5241 Five subcommands of @code{set print} and @code{show print} apply
5242 specifically to C and C++: @samp{vtbl}, @samp{demangle},
5243 @samp{asm-demangle}, @samp{object}, and @samp{union}. The first four
5244 apply to C++, and the last to C's @code{union} type, which has no direct
5245 analogue in Modula-2.
5247 The @code{@@} operator (@pxref{Expressions, ,Expressions}), while available
5248 while using any language, is not useful with Modula-2. Its
5249 intent is to aid the debugging of @dfn{dynamic arrays}, which cannot be
5250 created in Modula-2 as they can in C or C++. However, because an
5251 address can be specified by an integral constant, the construct
5252 @samp{@{@var{type}@}@var{adrexp}} is still useful. (@pxref{Expressions, ,Expressions})
5254 @cindex @code{#} in Modula-2
5255 In GDB scripts, the Modula-2 inequality operator @code{#} is
5256 interpreted as the beginning of a comment. Use @code{<>} instead.
5258 @node Symbols, Altering, Languages, Top
5259 @chapter Examining the Symbol Table
5261 The commands described in this section allow you to inquire about the
5262 symbols (names of variables, functions and types) defined in your
5263 program. This information is inherent in the text of your program and
5264 does not change as your program executes. GDB finds it in your
5265 program's symbol table, in the file indicated when you started GDB
5266 (@pxref{File Options, ,Choosing Files}), or by one of the
5267 file-management commands (@pxref{Files, ,Commands to Specify Files}).
5270 @item info address @var{symbol}
5271 @kindex info address
5272 Describe where the data for @var{symbol} is stored. For a register
5273 variable, this says which register it is kept in. For a non-register
5274 local variable, this prints the stack-frame offset at which the variable
5277 Note the contrast with @samp{print &@var{symbol}}, which does not work
5278 at all for a register variables, and for a stack local variable prints
5279 the exact address of the current instantiation of the variable.
5281 @item whatis @var{exp}
5283 Print the data type of expression @var{exp}. @var{exp} is not
5284 actually evaluated, and any side-effecting operations (such as
5285 assignments or function calls) inside it do not take place.
5286 @xref{Expressions, ,Expressions}.
5289 Print the data type of @code{$}, the last value in the value history.
5291 @item ptype @var{typename}
5293 Print a description of data type @var{typename}. @var{typename} may be
5294 the name of a type, or for C code it may have the form
5295 @samp{struct @var{struct-tag}}, @samp{union @var{union-tag}} or
5296 @samp{enum @var{enum-tag}}.
5298 @item ptype @var{exp}
5300 Print a description of the type of expression @var{exp}. @code{ptype}
5301 differs from @code{whatis} by printing a detailed description, instead
5302 of just the name of the type. For example, if your program declares a
5306 struct complex @{double real; double imag;@} v;
5310 compare the output of the two commands:
5315 type = struct complex
5317 type = struct complex @{
5325 As with @code{whatis}, using @code{ptype} without an argument refers to
5326 the type of @code{$}, the last value in the value history.
5328 @item info types @var{regexp}
5331 Print a brief description of all types whose name matches @var{regexp}
5332 (or all types in your program, if you supply no argument). Each
5333 complete typename is matched as though it were a complete line; thus,
5334 @samp{i type value} gives information on all types in your program whose
5335 name includes the string @code{value}, but @samp{i type ^value$} gives
5336 information only on types whose complete name is @code{value}.
5338 This command differs from @code{ptype} in two ways: first, like
5339 @code{whatis}, it does not print a detailed description; second, it
5340 lists all source files where a type is defined.
5344 Show the name of the current source file---that is, the source file for
5345 the function containing the current point of execution---and the language
5349 @kindex info sources
5350 Print the names of all source files in your program for which there is
5351 debugging information, organized into two lists: files whose symbols
5352 have already been read, and files whose symbols will be read when needed.
5354 @item info functions
5355 @kindex info functions
5356 Print the names and data types of all defined functions.
5358 @item info functions @var{regexp}
5359 Print the names and data types of all defined functions
5360 whose names contain a match for regular expression @var{regexp}.
5361 Thus, @samp{info fun step} finds all functions whose names
5362 include @code{step}; @samp{info fun ^step} finds those whose names
5363 start with @code{step}.
5365 @item info variables
5366 @kindex info variables
5367 Print the names and data types of all variables that are declared
5368 outside of functions (i.e., excluding local variables).
5370 @item info variables @var{regexp}
5371 Print the names and data types of all variables (except for local
5372 variables) whose names contain a match for regular expression
5376 This was never implemented.
5378 @itemx info methods @var{regexp}
5379 @kindex info methods
5380 The @code{info methods} command permits the user to examine all defined
5381 methods within C++ program, or (with the @var{regexp} argument) a
5382 specific set of methods found in the various C++ classes. Many
5383 C++ classes provide a large number of methods. Thus, the output
5384 from the @code{ptype} command can be overwhelming and hard to use. The
5385 @code{info-methods} command filters the methods, printing only those
5386 which match the regular-expression @var{regexp}.
5389 @item printsyms @var{filename}
5390 @itemx printpsyms @var{filename}
5394 @cindex partial symbol dump
5395 Write a dump of debugging symbol data into the file @var{filename}.
5396 These commands are used to debug the GDB symbol-reading code. Only
5397 symbols with debugging data are included. If you use @code{printsyms},
5398 GDB includes all the symbols for which it has already collected full
5399 details: that is, @var{filename} reflects symbols for only those files
5400 whose symbols GDB has read. You can use the command @code{info
5401 sources} to find out which files these are. If you use
5402 @code{printpsyms}, the dump also shows information about symbols that
5403 GDB only knows partially---that is, symbols defined in files that
5404 GDB has skimmed, but not yet read completely. The description of
5405 @code{symbol-file} describes how GDB reads symbols; both commands
5406 are described under @ref{Files, ,Commands to Specify Files}.
5409 @node Altering, GDB Files, Symbols, Top
5410 @chapter Altering Execution
5412 Once you think you have found an error in your program, you might want to
5413 find out for certain whether correcting the apparent error would lead to
5414 correct results in the rest of the run. You can find the answer by
5415 experiment, using the GDB features for altering execution of the
5418 For example, you can store new values into variables or memory
5419 locations, give your program a signal, restart it at a different address,
5420 or even return prematurely from a function to its caller.
5423 * Assignment:: Assignment to Variables
5424 * Jumping:: Continuing at a Different Address
5425 * Signaling:: Giving your program a Signal
5426 * Returning:: Returning from a Function
5427 * Calling:: Calling your Program's Functions
5428 * Patching:: Patching your Program
5431 @node Assignment, Jumping, Altering, Altering
5432 @section Assignment to Variables
5435 @cindex setting variables
5436 To alter the value of a variable, evaluate an assignment expression.
5437 @xref{Expressions, ,Expressions}. For example,
5444 stores the value 4 into the variable @code{x}, and then prints the
5445 value of the assignment expression (which is 4). @xref{Languages,
5446 ,Using GDB with Different Languages}, for more information on
5447 operators in supported languages.
5449 @kindex set variable
5450 @cindex variables, setting
5451 If you are not interested in seeing the value of the assignment, use the
5452 @code{set} command instead of the @code{print} command. @code{set} is
5453 really the same as @code{print} except that the expression's value is not
5454 printed and is not put in the value history (@pxref{Value History, ,Value History}). The
5455 expression is evaluated only for its effects.
5457 If the beginning of the argument string of the @code{set} command
5458 appears identical to a @code{set} subcommand, use the @code{set
5459 variable} command instead of just @code{set}. This command is identical
5460 to @code{set} except for its lack of subcommands. For example, a
5461 program might well have a variable @code{width}---which leads to
5462 an error if we try to set a new value with just @samp{set width=13}, as
5463 we might if @code{set width} did not happen to be a GDB command:
5471 Invalid syntax in expression.
5475 The invalid expression, of course, is @samp{=47}. What we can do in
5476 order to actually set our program's variable @code{width} is
5479 (gdb) set var width=47
5482 GDB allows more implicit conversions in assignments than C; you can
5483 freely store an integer value into a pointer variable or vice versa,
5484 and any structure can be converted to any other structure that is the
5485 same length or shorter.
5486 @comment FIXME: how do structs align/pad in these conversions?
5487 @comment /pesch@cygnus.com 18dec1990
5489 To store values into arbitrary places in memory, use the @samp{@{@dots{}@}}
5490 construct to generate a value of specified type at a specified address
5491 (@pxref{Expressions, ,Expressions}). For example, @code{@{int@}0x83040} refers
5492 to memory location @code{0x83040} as an integer (which implies a certain size
5493 and representation in memory), and
5496 set @{int@}0x83040 = 4
5500 stores the value 4 into that memory location.
5502 @node Jumping, Signaling, Assignment, Altering
5503 @section Continuing at a Different Address
5505 Ordinarily, when you continue your program, you do so at the place where
5506 it stopped, with the @code{continue} command. You can instead continue at
5507 an address of your own choosing, with the following commands:
5510 @item jump @var{linespec}
5512 Resume execution at line @var{linespec}. Execution will stop
5513 immediately if there is a breakpoint there. @xref{List, ,Printing
5514 Source Lines}, for a description of the different forms of
5517 The @code{jump} command does not change the current stack frame, or
5518 the stack pointer, or the contents of any memory location or any
5519 register other than the program counter. If line @var{linespec} is in
5520 a different function from the one currently executing, the results may
5521 be bizarre if the two functions expect different patterns of arguments or
5522 of local variables. For this reason, the @code{jump} command requests
5523 confirmation if the specified line is not in the function currently
5524 executing. However, even bizarre results are predictable if you are
5525 well acquainted with the machine-language code of your program.
5527 @item jump *@var{address}
5528 Resume execution at the instruction at address @var{address}.
5531 You can get much the same effect as the @code{jump} command by storing a
5532 new value into the register @code{$pc}. The difference is that this
5533 does not start your program running; it only changes the address where it
5534 @emph{will} run when it is continued. For example,
5541 causes the next @code{continue} command or stepping command to execute at
5542 address @code{0x485}, rather than at the address where your program stopped.
5543 @xref{Continuing and Stepping, ,Continuing and Stepping}.
5545 The most common occasion to use the @code{jump} command is to back up,
5546 perhaps with more breakpoints set, over a portion of a program that has
5547 already executed, in order to examine its execution in more detail.
5549 @node Signaling, Returning, Jumping, Altering
5551 @section Giving your program a Signal
5554 @item signal @var{signalnum}
5556 Resume execution where your program stopped, but give it immediately the
5557 signal number @var{signalnum}.
5559 Alternatively, if @var{signalnum} is zero, continue execution without
5560 giving a signal. This is useful when your program stopped on account of
5561 a signal and would ordinary see the signal when resumed with the
5562 @code{continue} command; @samp{signal 0} causes it to resume without a
5565 @code{signal} does not repeat when you press @key{RET} a second time
5566 after executing the command.
5570 @node Returning, Calling, Signaling, Altering
5571 @section Returning from a Function
5575 @itemx return @var{expression}
5576 @cindex returning from a function
5578 You can cancel execution of a function call with the @code{return}
5579 command. If you give an
5580 @var{expression} argument, its value is used as the function's return
5584 When you use @code{return}, GDB discards the selected stack frame
5585 (and all frames within it). You can think of this as making the
5586 discarded frame return prematurely. If you wish to specify a value to
5587 be returned, give that value as the argument to @code{return}.
5589 This pops the selected stack frame (@pxref{Selection, ,Selecting a
5590 Frame}), and any other frames inside of it, leaving its caller as the
5591 innermost remaining frame. That frame becomes selected. The
5592 specified value is stored in the registers used for returning values
5595 The @code{return} command does not resume execution; it leaves the
5596 program stopped in the state that would exist if the function had just
5597 returned. In contrast, the @code{finish} command (@pxref{Continuing
5598 and Stepping, ,Continuing and Stepping}) resumes execution until the
5599 selected stack frame returns naturally.
5601 @node Calling, Patching, Returning, Altering
5602 @section Calling your Program's Functions
5604 @cindex calling functions
5607 @item call @var{expr}
5608 Evaluate the expression @var{expr} without displaying @code{void}
5612 You can use this variant of the @code{print} command if you want to
5613 execute a function from your program, but without cluttering the output
5614 with @code{void} returned values. The result is printed and saved in
5615 the value history, if it is not void.
5617 @node Patching, , Calling, Altering
5618 @section Patching your Program
5619 @cindex patching binaries
5620 @cindex writing into executables
5621 @cindex writing into corefiles
5623 By default, GDB opens the file containing your program's executable
5624 code (or the corefile) read-only. This prevents accidental alterations
5625 to machine code; but it also prevents you from intentionally patching
5626 your program's binary.
5628 If you'd like to be able to patch the binary, you can specify that
5629 explicitly with the @code{set write} command. For example, you might
5630 want to turn on internal debugging flags, or even to make emergency
5635 @itemx set write off
5637 If you specify @samp{set write on}, GDB will open executable and
5638 core files for both reading and writing; if you specify @samp{set write
5639 off} (the default), GDB will open them read-only.
5641 If you have already loaded a file, you must load it
5642 again (using the @code{exec-file} or @code{core-file} command) after
5643 changing @code{set write}, for your new setting to take effect.
5647 Display whether executable files and core files will be opened for
5648 writing as well as reading.
5651 @node GDB Files, Targets, Altering, Top
5652 @chapter GDB's Files
5654 GDB needs to know the file name of the program to be debugged, both in
5655 order to read its symbol table and in order to start your program. To
5656 debug a core dump of a previous run, GDB must be told the file name of
5660 * Files:: Commands to Specify Files
5661 * Symbol Errors:: Errors Reading Symbol Files
5664 @node Files, Symbol Errors, GDB Files, GDB Files
5665 @section Commands to Specify Files
5666 @cindex core dump file
5667 @cindex symbol table
5669 The usual way to specify executable and core dump file names is with
5670 the command arguments given when you start GDB, (@pxref{Invocation,
5671 ,Getting In and Out of GDB}.
5673 Occasionally it is necessary to change to a different file during a
5674 GDB session. Or you may run GDB and forget to specify the files you
5675 want to use. In these situations the GDB commands to specify new files
5679 @item file @var{filename}
5680 @cindex executable file
5682 Use @var{filename} as the program to be debugged. It is read for its
5683 symbols and for the contents of pure memory. It is also the program
5684 executed when you use the @code{run} command. If you do not specify a
5685 directory and the file is not found in GDB's working directory, GDB
5686 uses the environment variable @code{PATH} as a list of directories to
5687 search, just as the shell does when looking for a program to run. You
5688 can change the value of this variable, for both GDB and your program,
5689 using the @code{path} command.
5692 @code{file} with no argument makes GDB discard any information it
5693 has on both executable file and the symbol table.
5695 @item exec-file @r{[} @var{filename} @r{]}
5697 Specify that the program to be run (but not the symbol table) is found
5698 in @var{filename}. GDB will search the environment variable @code{PATH}
5699 if necessary to locate your program. Omitting @var{filename} means to
5700 discard information on the executable file.
5702 @item symbol-file @r{[} @var{filename} @r{]}
5704 Read symbol table information from file @var{filename}. @code{PATH} is
5705 searched when necessary. Use the @code{file} command to get both symbol
5706 table and program to run from the same file.
5708 @code{symbol-file} with no argument clears out GDB's information on your
5709 program's symbol table.
5711 The @code{symbol-file} command causes GDB to forget the contents of its
5712 convenience variables, the value history, and all breakpoints and
5713 auto-display expressions. This is because they may contain pointers to
5714 the internal data recording symbols and data types, which are part of
5715 the old symbol table data being discarded inside GDB.
5717 @code{symbol-file} will not repeat if you press @key{RET} again after
5720 On some kinds of object files, the @code{symbol-file} command does not
5721 actually read the symbol table in full right away. Instead, it scans
5722 the symbol table quickly to find which source files and which symbols
5723 are present. The details are read later, one source file at a time,
5726 The purpose of this two-stage reading strategy is to make GDB start up
5727 faster. For the most part, it is invisible except for occasional
5728 pauses while the symbol table details for a particular source file are
5729 being read. (The @code{set verbose} command can turn these pauses
5730 into messages if desired. @xref{Messages/Warnings, ,Optional Warnings
5733 When the symbol table is stored in COFF format, @code{symbol-file} does
5734 read the symbol table data in full right away. We have not implemented
5735 the two-stage strategy for COFF yet.
5737 When GDB is configured for a particular environment, it will
5738 understand debugging information in whatever format is the standard
5739 generated for that environment; you may use either a GNU compiler, or
5740 other compilers that adhere to the local conventions. Best results are
5741 usually obtained from GNU compilers; for example, using @code{gcc}
5742 you can generate debugging information for optimized code.
5744 @item core-file @r{[} @var{filename} @r{]}
5747 Specify the whereabouts of a core dump file to be used as the ``contents
5748 of memory''. Traditionally, core files contain only some parts of the
5749 address space of the process that generated them; GDB can access the
5750 executable file itself for other parts.
5752 @code{core-file} with no argument specifies that no core file is
5755 Note that the core file is ignored when your program is actually running
5756 under GDB. So, if you have been running your program and you wish to
5757 debug a core file instead, you must kill the subprocess in which the
5758 program is running. To do this, use the @code{kill} command
5759 (@pxref{Kill Process, ,Killing the Child Process}).
5761 @item load @var{filename}
5763 Depending on what remote debugging facilities are configured into
5764 GDB, the @code{load} command may be available. Where it exists, it
5765 is meant to make @var{filename} (an executable) available for debugging
5766 on the remote system---by downloading, or dynamic linking, for example.
5767 @code{load} also records @var{filename}'s symbol table in GDB, like
5768 the @code{add-symbol-file} command.
5770 If @code{load} is not available on your GDB, attempting to execute
5771 it gets the error message ``@code{You can't do that when your target is
5774 On VxWorks, @code{load} will dynamically link @var{filename} on the
5775 current target system as well as adding its symbols in GDB.
5777 @cindex download to Nindy-960
5778 With the Nindy interface to an Intel 960 board, @code{load} will
5779 download @var{filename} to the 960 as well as adding its symbols in
5783 @code{load} will not repeat if you press @key{RET} again after using it.
5785 @item add-symbol-file @var{filename} @var{address}
5786 @kindex add-symbol-file
5787 @cindex dynamic linking
5788 The @code{add-symbol-file} command reads additional symbol table information
5789 from the file @var{filename}. You would use this command when @var{filename}
5790 has been dynamically loaded (by some other means) into the program that
5791 is running. @var{address} should be the memory address at which the
5792 file has been loaded; GDB cannot figure this out for itself.
5794 The symbol table of the file @var{filename} is added to the symbol table
5795 originally read with the @code{symbol-file} command. You can use the
5796 @code{add-symbol-file} command any number of times; the new symbol data thus
5797 read keeps adding to the old. To discard all old symbol data instead,
5798 use the @code{symbol-file} command.
5800 @code{add-symbol-file} will not repeat if you press @key{RET} after using it.
5806 @code{info files} and @code{info target} are synonymous; both print
5807 the current targets (@pxref{Targets, ,Specifying a Debugging Target}),
5808 including the names of the executable and core dump files currently in
5809 use by GDB, and the files from which symbols were loaded. The command
5810 @code{help targets} lists all possible targets rather than current
5815 All file-specifying commands allow both absolute and relative file names
5816 as arguments. GDB always converts the file name to an absolute path
5817 name and remembers it that way.
5819 @cindex shared libraries
5821 GDB supports the SunOS shared library format. GDB automatically
5822 loads symbol definitions from shared libraries when you use the
5823 @code{run} command, or when you examine a core file. (Before you issue
5824 the @code{run} command, GDB will not understand references to a
5825 function in a shared library, however---unless you are debugging a core
5827 @c FIXME: next GDB release should permit some refs to undef
5828 @c FIXME...symbols---eg in a break cmd---assuming they are from a shared lib
5832 @itemx info sharedlibrary
5833 @kindex info sharedlibrary
5835 Print the names of the shared libraries which are currently loaded.
5837 @item sharedlibrary @var{regex}
5838 @itemx share @var{regex}
5839 @kindex sharedlibrary
5841 This is an obsolescent command; you can use it to explicitly
5842 load shared object library symbols for files matching a UNIX regular
5843 expression, but as with files loaded automatically, it will only load
5844 shared libraries required by your program for a core file or after
5845 typing @code{run}. If @var{regex} is omitted all shared libraries
5846 required by your program are loaded.
5849 @node Symbol Errors, , Files, GDB Files
5850 @section Errors Reading Symbol Files
5852 While reading a symbol file, GDB will occasionally encounter problems,
5853 such as symbol types it does not recognize, or known bugs in compiler
5854 output. By default, GDB does not notify you of such problems, since
5855 they are relatively common and primarily of interest to people
5856 debugging compilers. If you are interested in seeing information
5857 about ill-constructed symbol tables, you can either ask GDB to print
5858 only one message about each such type of problem, no matter how many
5859 times the problem occurs; or you can ask GDB to print more messages,
5860 to see how many times the problems occur, with the @code{set
5861 complaints} command (@pxref{Messages/Warnings, ,Optional Warnings and
5864 The messages currently printed, and their meanings, are:
5867 @item inner block not inside outer block in @var{symbol}
5869 The symbol information shows where symbol scopes begin and end
5870 (such as at the start of a function or a block of statements). This
5871 error indicates that an inner scope block is not fully contained
5872 in its outer scope blocks.
5874 GDB circumvents the problem by treating the inner block as if it had
5875 the same scope as the outer block. In the error message, @var{symbol}
5876 may be shown as ``@code{(don't know)}'' if the outer block is not a
5879 @item block at @var{address} out of order
5881 The symbol information for symbol scope blocks should occur in
5882 order of increasing addresses. This error indicates that it does not
5885 GDB does not circumvent this problem, and will have trouble locating
5886 symbols in the source file whose symbols being read. (You can often
5887 determine what source file is affected by specifying @code{set verbose
5888 on}. @xref{Messages/Warnings, ,Optional Warnings and Messages}.)
5890 @item bad block start address patched
5892 The symbol information for a symbol scope block has a start address
5893 smaller than the address of the preceding source line. This is known
5894 to occur in the SunOS 4.1.1 (and earlier) C compiler.
5896 GDB circumvents the problem by treating the symbol scope block as
5897 starting on the previous source line.
5899 @item bad string table offset in symbol @var{n}
5902 Symbol number @var{n} contains a pointer into the string table which is
5903 larger than the size of the string table.
5905 GDB circumvents the problem by considering the symbol to have the
5906 name @code{foo}, which may cause other problems if many symbols end up
5909 @item unknown symbol type @code{0x@var{nn}}
5911 The symbol information contains new data types that GDB does not yet
5912 know how to read. @code{0x@var{nn}} is the symbol type of the misunderstood
5913 information, in hexadecimal.
5915 GDB circumvents the error by ignoring this symbol information. This
5916 will usually allow your program to be debugged, though certain symbols
5917 will not be accessible. If you encounter such a problem and feel like
5918 debugging it, you can debug @code{gdb} with itself, breakpoint on
5919 @code{complain}, then go up to the function @code{read_dbx_symtab} and
5920 examine @code{*bufp} to see the symbol.
5922 @item stub type has NULL name
5923 GDB could not find the full definition for a struct or class.
5925 @item const/volatile indicator missing (ok if using g++ v1.x), got@dots{}
5927 The symbol information for a C++ member function is missing some
5928 information that recent versions of the compiler should have output
5931 @item info mismatch between compiler and debugger
5933 GDB could not parse a type specification output by the compiler.
5936 @node Targets, Controlling GDB, GDB Files, Top
5937 @chapter Specifying a Debugging Target
5938 @cindex debugging target
5941 A @dfn{target} is the execution environment occupied by your program.
5942 Often, GDB runs in the same host environment as your program; in
5943 that case, the debugging target is specified as a side effect when you
5944 use the @code{file} or @code{core} commands. When you need more
5945 flexibility---for example, running GDB on a physically separate
5946 host, or controlling a standalone system over a serial port or a
5947 realtime system over a TCP/IP connection---you can use the @code{target}
5948 command to specify one of the target types configured for GDB
5949 (@pxref{Target Commands, ,Commands for Managing Targets}).
5952 * Active Targets:: Active Targets
5953 * Target Commands:: Commands for Managing Targets
5954 * Remote:: Remote Debugging
5957 @node Active Targets, Target Commands, Targets, Targets
5958 @section Active Targets
5959 @cindex stacking targets
5960 @cindex active targets
5961 @cindex multiple targets
5963 There are three classes of targets: processes, core files, and
5964 executable files. GDB can work concurrently on up to three active
5965 targets, one in each class. This allows you to (for example) start a
5966 process and inspect its activity without abandoning your work on a core
5969 If, for example, you execute @samp{gdb a.out}, then the executable file
5970 @code{a.out} is the only active target. If you designate a core file as
5971 well---presumably from a prior run that crashed and coredumped---then
5972 GDB has two active targets and will use them in tandem, looking
5973 first in the corefile target, then in the executable file, to satisfy
5974 requests for memory addresses. (Typically, these two classes of target
5975 are complementary, since core files contain only a program's
5976 read-write memory---variables and so on---plus machine status, while
5977 executable files contain only the program text and initialized data.)
5979 When you type @code{run}, your executable file becomes an active process
5980 target as well. When a process target is active, all GDB commands
5981 requesting memory addresses refer to that target; addresses in an active
5982 core file or executable file target are obscured while the process
5985 Use the @code{core-file} and @code{exec-file} commands to select a
5986 new core file or executable target (@pxref{Files, ,Commands to Specify
5987 Files}). To specify as a target a process that is already running, use
5988 the @code{attach} command (@pxref{Attach, ,Debugging an
5989 Already-Running Process}.).
5991 @node Target Commands, Remote, Active Targets, Targets
5992 @section Commands for Managing Targets
5995 @item target @var{type} @var{parameters}
5996 Connects the GDB host environment to a target machine or process. A
5997 target is typically a protocol for talking to debugging facilities. You
5998 use the argument @var{type} to specify the type or protocol of the
6001 Further @var{parameters} are interpreted by the target protocol, but
6002 typically include things like device names or host names to connect
6003 with, process numbers, and baud rates.
6005 The @code{target} command will not repeat if you press @key{RET} again
6006 after executing the command.
6010 Displays the names of all targets available. To display targets
6011 currently selected, use either @code{info target} or @code{info files}
6012 (@pxref{Files, ,Commands to Specify Files}).
6014 @item help target @var{name}
6015 Describe a particular target, including any parameters necessary to
6019 Here are some common targets (available, or not, depending on the GDB
6023 @item target exec @var{prog}
6025 An executable file. @samp{target exec @var{prog}} is the same as
6026 @samp{exec-file @var{prog}}.
6028 @item target core @var{filename}
6030 A core dump file. @samp{target core @var{filename}} is the same as
6031 @samp{core-file @var{filename}}.
6033 @item target remote @var{dev}
6034 @kindex target remote
6035 Remote serial target in GDB-specific protocol. The argument @var{dev}
6036 specifies what serial device to use for the connection (e.g.
6037 @file{/dev/ttya}). @xref{Remote, ,Remote Debugging}.
6039 @item target amd-eb @var{dev} @var{speed} @var{PROG}
6040 @kindex target amd-eb
6042 Remote PC-resident AMD EB29K board, attached over serial lines.
6043 @var{dev} is the serial device, as for @code{target remote};
6044 @var{speed} allows you to specify the linespeed; and @var{PROG} is the
6045 name of the program to be debugged, as it appears to DOS on the PC.
6046 @xref{EB29K Remote, ,GDB with a Remote EB29K}.
6048 @item target nindy @var{devicename}
6049 @kindex target nindy
6050 An Intel 960 board controlled by a Nindy Monitor. @var{devicename} is
6051 the name of the serial device to use for the connection, e.g.
6052 @file{/dev/ttya}. @xref{i960-Nindy Remote, ,GDB with a Remote i960 (Nindy)}.
6054 @item target vxworks @var{machinename}
6055 @kindex target vxworks
6056 A VxWorks system, attached via TCP/IP. The argument @var{machinename}
6057 is the target system's machine name or IP address.
6058 @xref{VxWorks Remote, ,GDB and VxWorks}.
6061 Different targets are available on different configurations of GDB; your
6062 configuration may have more or fewer targets.
6064 @node Remote, , Target Commands, Targets
6065 @section Remote Debugging
6066 @cindex remote debugging
6068 If you are trying to debug a program running on a machine that cannot run
6069 GDB in the usual way, it is often useful to use remote debugging. For
6070 example, you might use remote debugging on an operating system kernel, or on
6071 a small system which does not have a general purpose operating system
6072 powerful enough to run a full-featured debugger.
6074 Some configurations of GDB have special serial or TCP/IP interfaces
6075 to make this work with particular debugging targets. In addition,
6076 GDB comes with a generic serial protocol (specific to GDB, but
6077 not specific to any particular target system) which you can use if you
6078 write the remote stubs---the code that will run on the remote system to
6079 communicate with GDB.
6081 To use the GDB remote serial protocol, the program to be debugged on
6082 the remote machine needs to contain a debugging stub which talks to
6083 GDB over the serial line. Several working remote stubs are
6084 distributed with GDB; see the @file{README} file in the GDB
6085 distribution for more information.
6087 For details of this communication protocol, see the comments in the
6088 GDB source file @file{remote.c}.
6090 To start remote debugging, first run GDB and specify as an executable file
6091 the program that is running in the remote machine. This tells GDB how
6092 to find your program's symbols and the contents of its pure text. Then
6093 establish communication using the @code{target remote} command with a device
6094 name as an argument. For example:
6097 target remote /dev/ttyb
6101 if the serial line is connected to the device named @file{/dev/ttyb}. This
6102 will stop the remote machine if it is not already stopped.
6104 Now you can use all the usual commands to examine and change data and to
6105 step and continue the remote program.
6107 To resume the remote program and stop debugging it, use the @code{detach}
6110 Other remote targets may be available in your
6111 configuration of GDB; use @code{help targets} to list them.
6114 * i960-Nindy Remote:: GDB with a Remote i960 (Nindy)
6115 * EB29K Remote:: GDB with a Remote EB29K
6116 * VxWorks Remote:: GDB and VxWorks
6119 @node i960-Nindy Remote, EB29K Remote, Remote, Remote
6120 @subsection GDB with a Remote i960 (Nindy)
6124 @dfn{Nindy} is a ROM Monitor program for Intel 960 target systems. When
6125 GDB is configured to control a remote Intel 960 using Nindy, you can
6126 tell GDB how to connect to the 960 in several ways:
6130 Through command line options specifying serial port, version of the
6131 Nindy protocol, and communications speed;
6134 By responding to a prompt on startup;
6137 By using the @code{target} command at any point during your GDB
6138 session. @xref{Target Commands, ,Commands for Managing Targets}.
6143 * Nindy Startup:: Startup with Nindy
6144 * Nindy Options:: Options for Nindy
6145 * Nindy reset:: Nindy Reset Command
6148 @node Nindy Startup, Nindy Options, i960-Nindy Remote, i960-Nindy Remote
6149 @subsubsection Startup with Nindy
6151 If you simply start @code{gdb} without using any command-line
6152 options, you are prompted for what serial port to use, @emph{before} you
6153 reach the ordinary GDB prompt:
6156 Attach /dev/ttyNN -- specify NN, or "quit" to quit:
6160 Respond to the prompt with whatever suffix (after @samp{/dev/tty})
6161 identifies the serial port you want to use. You can, if you choose,
6162 simply start up with no Nindy connection by responding to the prompt
6163 with an empty line. If you do this, and later wish to attach to Nindy,
6164 use @code{target} (@pxref{Target Commands, ,Commands for Managing Targets}).
6166 @node Nindy Options, Nindy reset, Nindy Startup, i960-Nindy Remote
6167 @subsubsection Options for Nindy
6169 These are the startup options for beginning your GDB session with a
6170 Nindy-960 board attached:
6174 Specify the serial port name of a serial interface to be used to connect
6175 to the target system. This option is only available when GDB is
6176 configured for the Intel 960 target architecture. You may specify
6177 @var{port} as any of: a full pathname (e.g. @samp{-r /dev/ttya}), a
6178 device name in @file{/dev} (e.g. @samp{-r ttya}), or simply the unique
6179 suffix for a specific @code{tty} (e.g. @samp{-r a}).
6182 (An uppercase letter ``O'', not a zero.) Specify that GDB should use
6183 the ``old'' Nindy monitor protocol to connect to the target system.
6184 This option is only available when GDB is configured for the Intel 960
6185 target architecture.
6188 @emph{Warning:} if you specify @samp{-O}, but are actually trying to
6189 connect to a target system that expects the newer protocol, the connection
6190 will fail, appearing to be a speed mismatch. GDB will repeatedly
6191 attempt to reconnect at several different line speeds. You can abort
6192 this process with an interrupt.
6196 Specify that GDB should first send a @code{BREAK} signal to the target
6197 system, in an attempt to reset it, before connecting to a Nindy target.
6200 @emph{Warning:} Many target systems do not have the hardware that this
6201 requires; it only works with a few boards.
6205 The standard @samp{-b} option controls the line speed used on the serial
6209 @node Nindy reset, , Nindy Options, i960-Nindy Remote
6210 @subsubsection Nindy Reset Command
6215 For a Nindy target, this command sends a ``break'' to the remote target
6216 system; this is only useful if the target has been equipped with a
6217 circuit to perform a hard reset (or some other interesting action) when
6218 a break is detected.
6222 @node EB29K Remote, VxWorks Remote, i960-Nindy Remote, Remote
6223 @subsection GDB with a Remote EB29K
6226 @cindex running 29K programs
6228 To use GDB from a Unix system to run programs on AMD's EB29K
6229 board in a PC, you must first connect a serial cable between the PC
6230 and a serial port on the Unix system. In the following, we assume
6231 you've hooked the cable between the PC's @file{COM1} port and
6232 @file{/dev/ttya} on the Unix system.
6235 * Comms (EB29K):: Communications Setup
6236 * gdb-EB29K:: EB29K cross-debugging
6237 * Remote Log:: Remote Log
6240 @node Comms (EB29K), gdb-EB29K, EB29K Remote, EB29K Remote
6241 @subsubsection Communications Setup
6243 The next step is to set up the PC's port, by doing something like the
6244 following in DOS on the PC:
6247 C:\> MODE com1:9600,n,8,1,none
6251 This example---run on an MS DOS 4.0 system---sets the PC port to 9600
6252 bps, no parity, eight data bits, one stop bit, and no ``retry'' action;
6253 you must match the communications parameters when establishing the Unix
6254 end of the connection as well.
6255 @c FIXME: Who knows what this "no retry action" crud from the DOS manual may
6256 @c mean? It's optional; leave it out? ---pesch@cygnus.com, 25feb91
6258 To give control of the PC to the Unix side of the serial line, type
6259 the following at the DOS console:
6266 (Later, if you wish to return control to the DOS console, you can use
6267 the command @code{CTTY con}---but you must send it over the device that
6268 had control, in our example over the @file{COM1} serial line).
6270 From the Unix host, use a communications program such as @code{tip} or
6271 @code{cu} to communicate with the PC; for example,
6274 cu -s 9600 -l /dev/ttya
6278 The @code{cu} options shown specify, respectively, the linespeed and the
6279 serial port to use. If you use @code{tip} instead, your command line
6280 may look something like the following:
6287 Your system may define a different name where our example uses
6288 @file{/dev/ttya} as the argument to @code{tip}. The communications
6289 parameters, including which port to use, are associated with the
6290 @code{tip} argument in the ``remote'' descriptions file---normally the
6291 system table @file{/etc/remote}.
6292 @c FIXME: What if anything needs doing to match the "n,8,1,none" part of
6293 @c the DOS side's comms setup? cu can support -o (odd
6294 @c parity), -e (even parity)---apparently no settings for no parity or
6295 @c for character size. Taken from stty maybe...? John points out tip
6296 @c can set these as internal variables, eg ~s parity=none; man stty
6297 @c suggests that it *might* work to stty these options with stdin or
6298 @c stdout redirected... ---pesch@cygnus.com, 25feb91
6301 Using the @code{tip} or @code{cu} connection, change the DOS working
6302 directory to the directory containing a copy of your 29K program, then
6303 start the PC program @code{EBMON} (an EB29K control program supplied
6304 with your board by AMD). You should see an initial display from
6305 @code{EBMON} similar to the one that follows, ending with the
6306 @code{EBMON} prompt @samp{#}---
6311 G:\> CD \usr\joe\work29k
6313 G:\USR\JOE\WORK29K> EBMON
6314 Am29000 PC Coprocessor Board Monitor, version 3.0-18
6315 Copyright 1990 Advanced Micro Devices, Inc.
6316 Written by Gibbons and Associates, Inc.
6318 Enter '?' or 'H' for help
6320 PC Coprocessor Type = EB29K
6322 Memory Base = 0xd0000
6324 Data Memory Size = 2048KB
6325 Available I-RAM Range = 0x8000 to 0x1fffff
6326 Available D-RAM Range = 0x80002000 to 0x801fffff
6329 Register Stack Size = 0x800
6330 Memory Stack Size = 0x1800
6333 Am29027 Available = No
6334 Byte Write Available = Yes
6339 Then exit the @code{cu} or @code{tip} program (done in the example by
6340 typing @code{~.} at the @code{EBMON} prompt). @code{EBMON} will keep
6341 running, ready for GDB to take over.
6343 For this example, we've assumed what is probably the most convenient
6344 way to make sure the same 29K program is on both the PC and the Unix
6345 system: a PC/NFS connection that establishes ``drive @code{G:}'' on the
6346 PC as a file system on the Unix host. If you do not have PC/NFS or
6347 something similar connecting the two systems, you must arrange some
6348 other way---perhaps floppy-disk transfer---of getting the 29K program
6349 from the Unix system to the PC; GDB will @emph{not} download it over the
6352 @node gdb-EB29K, Remote Log, Comms (EB29K), EB29K Remote
6353 @subsubsection EB29K cross-debugging
6355 Finally, @code{cd} to the directory containing an image of your 29K
6356 program on the Unix system, and start GDB---specifying as argument the
6357 name of your 29K program:
6364 Now you can use the @code{target} command:
6367 target amd-eb /dev/ttya 9600 MYFOO
6368 @c FIXME: test above 'target amd-eb' as spelled, with caps! caps are meant to
6369 @c emphasize that this is the name as seen by DOS (since I think DOS is
6370 @c single-minded about case of letters). ---pesch@cygnus.com, 25feb91
6374 In this example, we've assumed your program is in a file called
6375 @file{myfoo}. Note that the filename given as the last argument to
6376 @code{target amd-eb} should be the name of the program as it appears to DOS.
6377 In our example this is simply @code{MYFOO}, but in general it can include
6378 a DOS path, and depending on your transfer mechanism may not resemble
6379 the name on the Unix side.
6381 At this point, you can set any breakpoints you wish; when you are ready
6382 to see your program run on the 29K board, use the GDB command
6385 To stop debugging the remote program, use the GDB @code{detach}
6388 To return control of the PC to its console, use @code{tip} or @code{cu}
6389 once again, after your GDB session has concluded, to attach to
6390 @code{EBMON}. You can then type the command @code{q} to shut down
6391 @code{EBMON}, returning control to the DOS command-line interpreter.
6392 Type @code{CTTY con} to return command input to the main DOS console,
6393 and type @kbd{~.} to leave @code{tip} or @code{cu}.
6395 @node Remote Log, , gdb-EB29K, EB29K Remote
6396 @subsubsection Remote Log
6398 @cindex log file for EB29K
6400 The @code{target amd-eb} command creates a file @file{eb.log} in the
6401 current working directory, to help debug problems with the connection.
6402 @file{eb.log} records all the output from @code{EBMON}, including echoes
6403 of the commands sent to it. Running @samp{tail -f} on this file in
6404 another window often helps to understand trouble with @code{EBMON}, or
6405 unexpected events on the PC side of the connection.
6407 @node VxWorks Remote, , EB29K Remote, Remote
6408 @subsection GDB and VxWorks
6411 GDB enables developers to spawn and debug tasks running on networked
6412 VxWorks targets from a Unix host. Already-running tasks spawned from
6413 the VxWorks shell can also be debugged. GDB uses code that runs on
6414 both the UNIX host and on the VxWorks target. The program
6415 @code{gdb} is installed and executed on the UNIX host.
6417 The following information on connecting to VxWorks was current when
6418 this manual was produced; newer releases of VxWorks may use revised
6421 The remote debugging interface (RDB) routines are installed and executed
6422 on the VxWorks target. These routines are included in the VxWorks library
6423 @file{rdb.a} and are incorporated into the system image when source-level
6424 debugging is enabled in the VxWorks configuration.
6427 If you wish, you can define @code{INCLUDE_RDB} in the VxWorks
6428 configuration file @file{configAll.h} to include the RDB interface
6429 routines and spawn the source debugging task @code{tRdbTask} when
6430 VxWorks is booted. For more information on configuring and remaking
6431 VxWorks, see the manufacturer's manual.
6433 Once you have included the RDB interface in your VxWorks system image
6434 and set your Unix execution search path to find GDB, you are ready
6435 to run GDB. From your UNIX host, type:
6441 GDB will come up showing the prompt:
6448 * VxWorks connection:: Connecting to VxWorks
6449 * VxWorks download:: VxWorks Download
6450 * VxWorks attach:: Running Tasks
6453 @node VxWorks connection, VxWorks download, VxWorks Remote, VxWorks Remote
6454 @subsubsection Connecting to VxWorks
6456 The GDB command @code{target} lets you connect to a VxWorks target on the
6457 network. To connect to a target whose host name is ``@code{tt}'', type:
6460 (gdb) target vxworks tt
6463 GDB will display a message similar to the following:
6466 Attaching remote machine across net... Success!
6469 GDB will then attempt to read the symbol tables of any object modules
6470 loaded into the VxWorks target since it was last booted. GDB locates
6471 these files by searching the directories listed in the command search
6472 path (@pxref{Environment, ,Your Program's Environment}); if it fails
6473 to find an object file, it will display a message such as:
6476 prog.o: No such file or directory.
6479 This will cause the @code{target} command to abort. When this happens,
6480 you should add the appropriate directory to the search path, with the
6481 GDB command @code{path}, and execute the @code{target} command
6484 @node VxWorks download, VxWorks attach, VxWorks connection, VxWorks Remote
6485 @subsubsection VxWorks Download
6487 @cindex download to VxWorks
6488 If you have connected to the VxWorks target and you want to debug an
6489 object that has not yet been loaded, you can use the GDB @code{load}
6490 command to download a file from UNIX to VxWorks incrementally. The
6491 object file given as an argument to the @code{load} command is actually
6492 opened twice: first by the VxWorks target in order to download the code,
6493 then by GDB in order to read the symbol table. This can lead to
6494 problems if the current working directories on the two systems differ.
6495 It is simplest to set the working directory on both systems to the
6496 directory in which the object file resides, and then to reference the
6497 file by its name, without any path. Thus, to load a program
6498 @file{prog.o}, residing in @file{wherever/vw/demo/rdb}, on VxWorks type:
6501 -> cd "wherever/vw/demo/rdb"
6507 (gdb) cd wherever/vw/demo/rdb
6511 GDB will display a response similar to the following:
6514 Reading symbol data from wherever/vw/demo/rdb/prog.o... done.
6517 You can also use the @code{load} command to reload an object module
6518 after editing and recompiling the corresponding source file. Note that
6519 this will cause GDB to delete all currently-defined breakpoints,
6520 auto-displays, and convenience variables, and to clear the value
6521 history. (This is necessary in order to preserve the integrity of
6522 debugger data structures that reference the target system's symbol
6525 @node VxWorks attach, , VxWorks download, VxWorks Remote
6526 @subsubsection Running Tasks
6528 @cindex running VxWorks tasks
6529 You can also attach to an existing task using the @code{attach} command as
6533 (gdb) attach @var{task}
6537 where @var{task} is the VxWorks hexadecimal task ID. The task can be running
6538 or suspended when you attach to it. If running, it will be suspended at
6539 the time of attachment.
6542 @node Controlling GDB, Sequences, Targets, Top
6543 @chapter Controlling GDB
6545 You can alter many aspects of GDB's interaction with you by using
6546 the @code{set} command. For commands controlling how GDB displays
6547 data, @pxref{Print Settings, ,Print Settings}; other settings are described here.
6551 * Editing:: Command Editing
6552 * History:: Command History
6553 * Screen Size:: Screen Size
6555 * Messages/Warnings:: Optional Warnings and Messages
6558 @node Prompt, Editing, Controlling GDB, Controlling GDB
6562 GDB indicates its readiness to read a command by printing a string
6563 called the @dfn{prompt}. This string is normally @samp{(gdb)}. You
6564 can change the prompt string with the @code{set prompt} command. For
6565 instance, when debugging GDB with GDB, it is useful to change
6566 the prompt in one of the GDBs so that you can always tell which
6567 one you are talking to.
6570 @item set prompt @var{newprompt}
6572 Directs GDB to use @var{newprompt} as its prompt string henceforth.
6575 Prints a line of the form: @samp{Gdb's prompt is: @var{your-prompt}}
6578 @node Editing, History, Prompt, Controlling GDB
6579 @section Command Editing
6581 @cindex command line editing
6583 GDB reads its input commands via the @dfn{readline} interface. This
6584 GNU library provides consistent behavior for programs which provide a
6585 command line interface to the user. Advantages are @code{emacs}-style
6586 or @code{vi}-style inline editing of commands, @code{csh}-like history
6587 substitution, and a storage and recall of command history across
6590 You may control the behavior of command line editing in GDB with the
6597 @itemx set editing on
6598 Enable command line editing (enabled by default).
6600 @item set editing off
6601 Disable command line editing.
6603 @kindex show editing
6605 Show whether command line editing is enabled.
6608 @node History, Screen Size, Editing, Controlling GDB
6609 @section Command History
6612 @cindex history substitution
6613 @cindex history file
6614 @kindex set history filename
6615 @item set history filename @var{fname}
6616 Set the name of the GDB command history file to @var{fname}. This is
6617 the file from which GDB will read an initial command history
6618 list or to which it will write this list when it exits. This list is
6619 accessed through history expansion or through the history
6620 command editing characters listed below. This file defaults to the
6621 value of the environment variable @code{GDBHISTFILE}, or to
6622 @file{./.gdb_history} if this variable is not set.
6624 @cindex history save
6625 @kindex set history save
6626 @item set history save
6627 @itemx set history save on
6628 Record command history in a file, whose name may be specified with the
6629 @code{set history filename} command. By default, this option is disabled.
6631 @item set history save off
6632 Stop recording command history in a file.
6634 @cindex history size
6635 @kindex set history size
6636 @item set history size @var{size}
6637 Set the number of commands which GDB will keep in its history list.
6638 This defaults to the value of the environment variable
6639 @code{HISTSIZE}, or to 256 if this variable is not set.
6642 @cindex history expansion
6643 History expansion assigns special meaning to the character @kbd{!}.
6645 @xref{Event Designators}.
6647 Since @kbd{!} is also the logical not operator in C, history expansion
6648 is off by default. If you decide to enable history expansion with the
6649 @code{set history expansion on} command, you may sometimes need to
6650 follow @kbd{!} (when it is used as logical not, in an expression) with
6651 a space or a tab to prevent it from being expanded. The readline
6652 history facilities will not attempt substitution on the strings
6653 @kbd{!=} and @kbd{!(}, even when history expansion is enabled.
6655 The commands to control history expansion are:
6659 @kindex set history expansion
6660 @item set history expansion on
6661 @itemx set history expansion
6662 Enable history expansion. History expansion is off by default.
6664 @item set history expansion off
6665 Disable history expansion.
6667 The readline code comes with more complete documentation of
6668 editing and history expansion features. Users unfamiliar with @code{emacs}
6669 or @code{vi} may wish to read it.
6671 @xref{Command Line Editing}.
6675 @kindex show history
6677 @itemx show history filename
6678 @itemx show history save
6679 @itemx show history size
6680 @itemx show history expansion
6681 These commands display the state of the GDB history parameters.
6682 @code{show history} by itself displays all four states.
6687 @kindex show commands
6689 Display the last ten commands in the command history.
6691 @item show commands @var{n}
6692 Print ten commands centered on command number @var{n}.
6694 @item show commands +
6695 Print ten commands just after the commands last printed.
6698 @node Screen Size, Numbers, History, Controlling GDB
6699 @section Screen Size
6700 @cindex size of screen
6701 @cindex pauses in output
6703 Certain commands to GDB may produce large amounts of information
6704 output to the screen. To help you read all of it, GDB pauses and
6705 asks you for input at the end of each page of output. Type @key{RET}
6706 when you want to continue the output. GDB also uses the screen
6707 width setting to determine when to wrap lines of output. Depending on
6708 what is being printed, it tries to break the line at a readable place,
6709 rather than simply letting it overflow onto the following line.
6711 Normally GDB knows the size of the screen from the termcap data base
6712 together with the value of the @code{TERM} environment variable and the
6713 @code{stty rows} and @code{stty cols} settings. If this is not correct,
6714 you can override it with the @code{set height} and @code{set
6718 @item set height @var{lpp}
6720 @itemx set width @var{cpl}
6726 These @code{set} commands specify a screen height of @var{lpp} lines and
6727 a screen width of @var{cpl} characters. The associated @code{show}
6728 commands display the current settings.
6730 If you specify a height of zero lines, GDB will not pause during output
6731 no matter how long the output is. This is useful if output is to a file
6732 or to an editor buffer.
6735 @node Numbers, Messages/Warnings, Screen Size, Controlling GDB
6737 @cindex number representation
6738 @cindex entering numbers
6740 You can always enter numbers in octal, decimal, or hexadecimal in GDB by
6741 the usual conventions: octal numbers begin with @samp{0}, decimal
6742 numbers end with @samp{.}, and hexadecimal numbers begin with @samp{0x}.
6743 Numbers that begin with none of these are, by default, entered in base
6744 10; likewise, the default display for numbers---when no particular
6745 format is specified---is base 10. You can change the default base for
6746 both input and output with the @code{set radix} command.
6750 @item set radix @var{base}
6751 Set the default base for numeric input and display. Supported choices
6752 for @var{base} are decimal 2, 8, 10, 16. @var{base} must itself be
6753 specified either unambiguously or using the current default radix; for
6764 will set the base to decimal. On the other hand, @samp{set radix 10}
6765 will leave the radix unchanged no matter what it was.
6769 Display the current default base for numeric input and display.
6772 @node Messages/Warnings, , Numbers, Controlling GDB
6773 @section Optional Warnings and Messages
6775 By default, GDB is silent about its inner workings. If you are running
6776 on a slow machine, you may want to use the @code{set verbose} command.
6777 It will make GDB tell you when it does a lengthy internal operation, so
6778 you will not think it has crashed.
6780 Currently, the messages controlled by @code{set verbose} are those
6781 which announce that the symbol table for a source file is being read
6782 (@pxref{Files, ,Commands to Specify Files}, in the description of the
6783 command @code{symbol-file}).
6784 @c The following is the right way to do it, but emacs 18.55 does not support
6785 @c @ref, and neither the emacs lisp manual version of texinfmt or makeinfo
6788 see @code{symbol-file} in @ref{Files, ,Commands to Specify Files}).
6793 @item set verbose on
6794 Enables GDB's output of certain informational messages.
6796 @item set verbose off
6797 Disables GDB's output of certain informational messages.
6799 @kindex show verbose
6801 Displays whether @code{set verbose} is on or off.
6804 By default, if GDB encounters bugs in the symbol table of an object
6805 file, it is silent; but if you are debugging a compiler, you may find
6806 this information useful (@pxref{Symbol Errors, ,Errors Reading Symbol Files}).
6809 @kindex set complaints
6810 @item set complaints @var{limit}
6811 Permits GDB to output @var{limit} complaints about each type of unusual
6812 symbols before becoming silent about the problem. Set @var{limit} to
6813 zero to suppress all complaints; set it to a large number to prevent
6814 complaints from being suppressed.
6816 @kindex show complaints
6817 @item show complaints
6818 Displays how many symbol complaints GDB is permitted to produce.
6821 By default, GDB is cautious, and asks what sometimes seem to be a
6822 lot of stupid questions to confirm certain commands. For example, if
6823 you try to run a program which is already running:
6827 The program being debugged has been started already.
6828 Start it from the beginning? (y or n)
6831 If you are willing to unflinchingly face the consequences of your own
6832 commands, you can disable this ``feature'':
6837 @cindex confirmation
6838 @cindex stupid questions
6839 @item set confirm off
6840 Disables confirmation requests.
6842 @item set confirm on
6843 Enables confirmation requests (the default).
6846 @kindex show confirm
6847 Displays state of confirmation requests.
6850 @c FIXME this does not really belong here. But where *does* it belong?
6851 @cindex reloading symbols
6852 Some systems allow individual object files that make up your program to
6853 be replaced without stopping and restarting your program.
6854 For example, in VxWorks you can simply recompile a defective object file
6855 and keep on running.
6856 If you are running on one of these systems, you can allow GDB to
6857 reload the symbols for automatically relinked modules:
6860 @kindex set symbol-reloading
6861 @item set symbol-reloading on
6862 Replace symbol definitions for the corresponding source file when an
6863 object file with a particular name is seen again.
6865 @item set symbol-reloading off
6866 Do not replace symbol definitions when re-encountering object files of
6867 the same name. This is the default state; if you are not running on a
6868 system that permits automatically relinking modules, you should leave
6869 @code{symbol-reloading} off, since otherwise GDB may discard symbols
6870 when linking large programs, that may contain several modules (from
6871 different directories or libraries) with the same name.
6873 @item show symbol-reloading
6874 Show the current @code{on} or @code{off} setting.
6877 @node Sequences, Emacs, Controlling GDB, Top
6878 @chapter Canned Sequences of Commands
6880 Aside from breakpoint commands (@pxref{Break Commands, ,Breakpoint
6881 Command Lists}), GDB provides two ways to store sequences of commands
6882 for execution as a unit: user-defined commands and command files.
6885 * Define:: User-Defined Commands
6886 * Command Files:: Command Files
6887 * Output:: Commands for Controlled Output
6890 @node Define, Command Files, Sequences, Sequences
6891 @section User-Defined Commands
6893 @cindex user-defined command
6894 A @dfn{user-defined command} is a sequence of GDB commands to which you
6895 assign a new name as a command. This is done with the @code{define}
6899 @item define @var{commandname}
6901 Define a command named @var{commandname}. If there is already a command
6902 by that name, you are asked to confirm that you want to redefine it.
6904 The definition of the command is made up of other GDB command lines,
6905 which are given following the @code{define} command. The end of these
6906 commands is marked by a line containing @code{end}.
6908 @item document @var{commandname}
6910 Give documentation to the user-defined command @var{commandname}. The
6911 command @var{commandname} must already be defined. This command reads
6912 lines of documentation just as @code{define} reads the lines of the
6913 command definition, ending with @code{end}. After the @code{document}
6914 command is finished, @code{help} on command @var{commandname} will print
6915 the documentation you have specified.
6917 You may use the @code{document} command again to change the
6918 documentation of a command. Redefining the command with @code{define}
6919 does not change the documentation.
6921 @item help user-defined
6922 @kindex help user-defined
6923 List all user-defined commands, with the first line of the documentation
6927 @itemx info user @var{commandname}
6929 Display the GDB commands used to define @var{commandname} (but not its
6930 documentation). If no @var{commandname} is given, display the
6931 definitions for all user-defined commands.
6934 User-defined commands do not take arguments. When they are executed, the
6935 commands of the definition are not printed. An error in any command
6936 stops execution of the user-defined command.
6938 Commands that would ask for confirmation if used interactively proceed
6939 without asking when used inside a user-defined command. Many GDB commands
6940 that normally print messages to say what they are doing omit the messages
6941 when used in a user-defined command.
6943 @node Command Files, Output, Define, Sequences
6944 @section Command Files
6946 @cindex command files
6947 A command file for GDB is a file of lines that are GDB commands. Comments
6948 (lines starting with @kbd{#}) may also be included. An empty line in a
6949 command file does nothing; it does not mean to repeat the last command, as
6950 it would from the terminal.
6953 @cindex @file{.gdbinit}
6954 When you start GDB, it automatically executes commands from its
6955 @dfn{init files}. These are files named @file{.gdbinit}. GDB reads
6956 the init file (if any) in your home directory and then the init file
6957 (if any) in the current working directory. (The init files are not
6958 executed if you use the @samp{-nx} option; @pxref{Mode Options,
6959 ,Choosing Modes}.) You can also request the execution of a command
6960 file with the @code{source} command:
6963 @item source @var{filename}
6965 Execute the command file @var{filename}.
6968 The lines in a command file are executed sequentially. They are not
6969 printed as they are executed. An error in any command terminates execution
6970 of the command file.
6972 Commands that would ask for confirmation if used interactively proceed
6973 without asking when used in a command file. Many GDB commands that
6974 normally print messages to say what they are doing omit the messages
6975 when called from command files.
6977 @node Output, , Command Files, Sequences
6978 @section Commands for Controlled Output
6980 During the execution of a command file or a user-defined command, normal
6981 GDB output is suppressed; the only output that appears is what is
6982 explicitly printed by the commands in the definition. This section
6983 describes three commands useful for generating exactly the output you
6987 @item echo @var{text}
6989 @c I do not consider backslash-space a standard C escape sequence
6990 @c because it is not in ANSI.
6991 Print @var{text}. Nonprinting characters can be included in
6992 @var{text} using C escape sequences, such as @samp{\n} to print a
6993 newline. @strong{No newline will be printed unless you specify one.}
6994 In addition to the standard C escape sequences, a backslash followed
6995 by a space stands for a space. This is useful for outputting a
6996 string with spaces at the beginning or the end, since leading and
6997 trailing spaces are otherwise trimmed from all arguments.
6998 To print @samp{@w{ }and foo =@w{ }}, use the command
6999 @samp{echo \@w{ }and foo = \@w{ }}.
7001 A backslash at the end of @var{text} can be used, as in C, to continue
7002 the command onto subsequent lines. For example,
7005 echo This is some text\n\
7006 which is continued\n\
7007 onto several lines.\n
7010 produces the same output as
7013 echo This is some text\n
7014 echo which is continued\n
7015 echo onto several lines.\n
7018 @item output @var{expression}
7020 Print the value of @var{expression} and nothing but that value: no
7021 newlines, no @samp{$@var{nn} = }. The value is not entered in the
7022 value history either. @xref{Expressions, ,Expressions}, for more information on
7025 @item output/@var{fmt} @var{expression}
7026 Print the value of @var{expression} in format @var{fmt}. You can use
7027 the same formats as for @code{print}; @pxref{Output formats}, for more
7030 @item printf @var{string}, @var{expressions}@dots{}
7032 Print the values of the @var{expressions} under the control of
7033 @var{string}. The @var{expressions} are separated by commas and may
7034 be either numbers or pointers. Their values are printed as specified
7035 by @var{string}, exactly as if your program were to execute
7038 printf (@var{string}, @var{expressions}@dots{});
7041 For example, you can print two values in hex like this:
7044 printf "foo, bar-foo = 0x%x, 0x%x\n", foo, bar-foo
7047 The only backslash-escape sequences that you can use in the format
7048 string are the simple ones that consist of backslash followed by a
7052 @node Emacs, GDB Bugs, Sequences, Top
7053 @chapter Using GDB under GNU Emacs
7056 A special interface allows you to use GNU Emacs to view (and
7057 edit) the source files for the program you are debugging with
7060 To use this interface, use the command @kbd{M-x gdb} in Emacs. Give the
7061 executable file you want to debug as an argument. This command starts
7062 GDB as a subprocess of Emacs, with input and output through a newly
7063 created Emacs buffer.
7065 Using GDB under Emacs is just like using GDB normally except for two
7070 All ``terminal'' input and output goes through the Emacs buffer.
7073 This applies both to GDB commands and their output, and to the input
7074 and output done by the program you are debugging.
7076 This is useful because it means that you can copy the text of previous
7077 commands and input them again; you can even use parts of the output
7080 All the facilities of Emacs' Shell mode are available for interacting
7081 with your program. In particular, you can send signals the usual
7082 way---for example, @kbd{C-c C-c} for an interrupt, @kbd{C-c C-z} for a
7087 GDB displays source code through Emacs.
7090 Each time GDB displays a stack frame, Emacs automatically finds the
7091 source file for that frame and puts an arrow (@samp{=>}) at the
7092 left margin of the current line. Emacs uses a separate buffer for
7093 source display, and splits the window to show both your GDB session
7096 Explicit GDB @code{list} or search commands still produce output as
7097 usual, but you probably will have no reason to use them.
7100 @emph{Warning:} If the directory where your program resides is not your
7101 current directory, it can be easy to confuse Emacs about the location of
7102 the source files, in which case the auxiliary display buffer will not
7103 appear to show your source. GDB can find programs by searching your
7104 environment's @code{PATH} variable, so the GDB input and output
7105 session will proceed normally; but Emacs does not get enough information
7106 back from GDB to locate the source files in this situation. To
7107 avoid this problem, either start GDB mode from the directory where
7108 your program resides, or specify a full path name when prompted for the
7109 @kbd{M-x gdb} argument.
7111 A similar confusion can result if you use the GDB @code{file} command to
7112 switch to debugging a program in some other location, from an existing
7113 GDB buffer in Emacs.
7116 By default, @kbd{M-x gdb} calls the program called @file{gdb}. If
7117 you need to call GDB by a different name (for example, if you keep
7118 several configurations around, with different names) you can set the
7119 Emacs variable @code{gdb-command-name}; for example,
7122 (setq gdb-command-name "mygdb")
7126 (preceded by @kbd{ESC ESC}, or typed in the @code{*scratch*} buffer, or
7127 in your @file{.emacs} file) will make Emacs call the program named
7128 ``@code{mygdb}'' instead.
7130 In the GDB I/O buffer, you can use these special Emacs commands in
7131 addition to the standard Shell mode commands:
7135 Describe the features of Emacs' GDB Mode.
7138 Execute to another source line, like the GDB @code{step} command; also
7139 update the display window to show the current file and location.
7142 Execute to next source line in this function, skipping all function
7143 calls, like the GDB @code{next} command. Then update the display window
7144 to show the current file and location.
7147 Execute one instruction, like the GDB @code{stepi} command; update
7148 display window accordingly.
7151 Execute to next instruction, using the GDB @code{nexti} command; update
7152 display window accordingly.
7155 Execute until exit from the selected stack frame, like the GDB
7156 @code{finish} command.
7159 Continue execution of your program, like the GDB @code{continue}
7162 @emph{Warning:} In Emacs v19, this command is @kbd{C-c C-p}.
7165 Go up the number of frames indicated by the numeric argument
7166 (@pxref{Arguments, , Numeric Arguments, emacs, The GNU Emacs Manual}),
7167 like the GDB @code{up} command.
7169 @emph{Warning:} In Emacs v19, this command is @kbd{C-c C-u}.
7172 Go down the number of frames indicated by the numeric argument, like the
7173 GDB @code{down} command.
7175 @emph{Warning:} In Emacs v19, this command is @kbd{C-c C-d}.
7178 Read the number where the cursor is positioned, and insert it at the end
7179 of the GDB I/O buffer. For example, if you wish to disassemble code
7180 around an address that was displayed earlier, type @kbd{disassemble};
7181 then move the cursor to the address display, and pick up the
7182 argument for @code{disassemble} by typing @kbd{C-x &}.
7184 You can customize this further on the fly by defining elements of the list
7185 @code{gdb-print-command}; once it is defined, you can format or
7186 otherwise process numbers picked up by @kbd{C-x &} before they are
7187 inserted. A numeric argument to @kbd{C-x &} will both indicate that you
7188 wish special formatting, and act as an index to pick an element of the
7189 list. If the list element is a string, the number to be inserted is
7190 formatted using the Emacs function @code{format}; otherwise the number
7191 is passed as an argument to the corresponding list element.
7194 In any source file, the Emacs command @kbd{C-x SPC} (@code{gdb-break})
7195 tells GDB to set a breakpoint on the source line point is on.
7197 If you accidentally delete the source-display buffer, an easy way to get
7198 it back is to type the command @code{f} in the GDB buffer, to
7199 request a frame display; when you run under Emacs, this will recreate
7200 the source buffer if necessary to show you the context of the current
7203 The source files displayed in Emacs are in ordinary Emacs buffers
7204 which are visiting the source files in the usual way. You can edit
7205 the files with these buffers if you wish; but keep in mind that GDB
7206 communicates with Emacs in terms of line numbers. If you add or
7207 delete lines from the text, the line numbers that GDB knows will cease
7208 to correspond properly to the code.
7210 @c The following dropped because Epoch is nonstandard. Reactivate
7211 @c if/when v19 does something similar. ---pesch@cygnus.com 19dec1990
7213 @kindex emacs epoch environment
7217 Version 18 of Emacs has a built-in window system called the @code{epoch}
7218 environment. Users of this environment can use a new command,
7219 @code{inspect} which performs identically to @code{print} except that
7220 each value is printed in its own window.
7223 @node GDB Bugs, Renamed Commands, Emacs, Top
7224 @chapter Reporting Bugs in GDB
7226 @cindex Reporting Bugs in GDB
7228 Your bug reports play an essential role in making GDB reliable.
7230 Reporting a bug may help you by bringing a solution to your problem, or it
7231 may not. But in any case the principal function of a bug report is to help
7232 the entire community by making the next version of GDB work better. Bug
7233 reports are your contribution to the maintenance of GDB.
7235 In order for a bug report to serve its purpose, you must include the
7236 information that enables us to fix the bug.
7239 * Bug Criteria:: Have You Found a Bug?
7240 * Bug Reporting:: How to Report Bugs
7243 @node Bug Criteria, Bug Reporting, GDB Bugs, GDB Bugs
7244 @section Have You Found a Bug?
7245 @cindex Bug Criteria
7247 If you are not sure whether you have found a bug, here are some guidelines:
7251 @cindex Fatal Signal
7253 If the debugger gets a fatal signal, for any input whatever, that is a
7254 GDB bug. Reliable debuggers never crash.
7257 @cindex error on Valid Input
7258 If GDB produces an error message for valid input, that is a bug.
7261 @cindex Invalid Input
7262 If GDB does not produce an error message for invalid input,
7263 that is a bug. However, you should note that your idea of
7264 ``invalid input'' might be our idea of ``an extension'' or ``support
7265 for traditional practice''.
7268 If you are an experienced user of debugging tools, your suggestions
7269 for improvement of GDB are welcome in any case.
7272 @node Bug Reporting, , Bug Criteria, GDB Bugs
7273 @section How to Report Bugs
7275 @cindex GDB Bugs, Reporting
7277 A number of companies and individuals offer support for GNU products.
7278 If you obtained GDB from a support organization, we recommend you
7279 contact that organization first.
7281 Contact information for many support companies and individuals is
7282 available in the file @file{etc/SERVICE} in the GNU Emacs distribution.
7284 In any event, we also recommend that you send bug reports for GDB to one
7288 bug-gdb@@prep.ai.mit.edu
7289 @{ucbvax|mit-eddie|uunet@}!prep.ai.mit.edu!bug-gdb
7292 @strong{Do not send bug reports to @samp{info-gdb}, or to
7293 @samp{help-gdb}, or to any newsgroups.} Most users of GDB do not want to
7294 receive bug reports. Those that do, have arranged to receive @samp{bug-gdb}.
7296 The mailing list @samp{bug-gdb} has a newsgroup @samp{gnu.gdb.bug} which
7297 serves as a repeater. The mailing list and the newsgroup carry exactly
7298 the same messages. Often people think of posting bug reports to the
7299 newsgroup instead of mailing them. This appears to work, but it has one
7300 problem which can be crucial: a newsgroup posting often lacks a mail
7301 path back to the sender. Thus, if we need to ask for more information,
7302 we may be unable to reach you. For this reason, it is better to send
7303 bug reports to the mailing list.
7305 As a last resort, send bug reports on paper to:
7309 Free Software Foundation
7314 The fundamental principle of reporting bugs usefully is this:
7315 @strong{report all the facts}. If you are not sure whether to state a
7316 fact or leave it out, state it!
7318 Often people omit facts because they think they know what causes the
7319 problem and assume that some details do not matter. Thus, you might
7320 assume that the name of the variable you use in an example does not matter.
7321 Well, probably it does not, but one cannot be sure. Perhaps the bug is a
7322 stray memory reference which happens to fetch from the location where that
7323 name is stored in memory; perhaps, if the name were different, the contents
7324 of that location would fool the debugger into doing the right thing despite
7325 the bug. Play it safe and give a specific, complete example. That is the
7326 easiest thing for you to do, and the most helpful.
7328 Keep in mind that the purpose of a bug report is to enable us to fix
7329 the bug if it is new to us. It is not as important as what happens if
7330 the bug is already known. Therefore, always write your bug reports on
7331 the assumption that the bug has not been reported previously.
7333 Sometimes people give a few sketchy facts and ask, ``Does this ring a
7334 bell?'' Those bug reports are useless, and we urge everyone to
7335 @emph{refuse to respond to them} except to chide the sender to report
7338 To enable us to fix the bug, you should include all these things:
7342 The version of GDB. GDB announces it if you start with no
7343 arguments; you can also print it at any time using @code{show version}.
7345 Without this, we will not know whether there is any point in looking for
7346 the bug in the current version of GDB.
7349 The type of machine you are using, and the operating system name and
7353 What compiler (and its version) was used to compile GDB---e.g.
7357 What compiler (and its version) was used to compile the program you
7358 are debugging---e.g. ``gcc-2.0''.
7361 The command arguments you gave the compiler to compile your example and
7362 observe the bug. For example, did you use @samp{-O}? To guarantee
7363 you will not omit something important, list them all. A copy of the
7364 Makefile (or the output from make) is sufficient.
7366 If we were to try to guess the arguments, we would probably guess wrong
7367 and then we might not encounter the bug.
7370 A complete input script, and all necessary source files, that will
7374 A description of what behavior you observe that you believe is
7375 incorrect. For example, ``It gets a fatal signal.''
7377 Of course, if the bug is that GDB gets a fatal signal, then we will
7378 certainly notice it. But if the bug is incorrect output, we might not
7379 notice unless it is glaringly wrong. We are human, after all. You
7380 might as well not give us a chance to make a mistake.
7382 Even if the problem you experience is a fatal signal, you should still
7383 say so explicitly. Suppose something strange is going on, such as,
7384 your copy of GDB is out of synch, or you have encountered a
7385 bug in the C library on your system. (This has happened!) Your copy
7386 might crash and ours would not. If you told us to expect a crash,
7387 then when ours fails to crash, we would know that the bug was not
7388 happening for us. If you had not told us to expect a crash, then we
7389 would not be able to draw any conclusion from our observations.
7392 If you wish to suggest changes to the GDB source, send us context
7393 diffs. If you even discuss something in the GDB source, refer to
7394 it by context, not by line number.
7396 The line numbers in our development sources will not match those in your
7397 sources. Your line numbers would convey no useful information to us.
7400 Here are some things that are not necessary:
7404 A description of the envelope of the bug.
7406 Often people who encounter a bug spend a lot of time investigating
7407 which changes to the input file will make the bug go away and which
7408 changes will not affect it.
7410 This is often time consuming and not very useful, because the way we
7411 will find the bug is by running a single example under the debugger
7412 with breakpoints, not by pure deduction from a series of examples.
7413 We recommend that you save your time for something else.
7415 Of course, if you can find a simpler example to report @emph{instead}
7416 of the original one, that is a convenience for us. Errors in the
7417 output will be easier to spot, running under the debugger will take
7420 However, simplification is not vital; if you do not want to do this,
7421 report the bug anyway and send us the entire test case you used.
7424 A patch for the bug.
7426 A patch for the bug does help us if it is a good one. But do not omit
7427 the necessary information, such as the test case, on the assumption that
7428 a patch is all we need. We might see problems with your patch and decide
7429 to fix the problem another way, or we might not understand it at all.
7431 Sometimes with a program as complicated as GDB it is very hard to
7432 construct an example that will make the program follow a certain path
7433 through the code. If you do not send us the example, we will not be able
7434 to construct one, so we will not be able to verify that the bug is fixed.
7436 And if we cannot understand what bug you are trying to fix, or why your
7437 patch should be an improvement, we will not install it. A test case will
7438 help us to understand.
7441 A guess about what the bug is or what it depends on.
7443 Such guesses are usually wrong. Even we cannot guess right about such
7444 things without first using the debugger to find the facts.
7447 @c Note: no need to update nodes for rdl-apps.texi since it appears
7448 @c *only* in the TeX version of the manual.
7449 @c Note: eventually, make a cross reference to the readline Info nodes.
7451 @c appendices describing GNU readline. Distributed with readline code.
7452 @include rluser.texinfo
7453 @include inc-hist.texi
7456 @node Renamed Commands, Installing GDB, GDB Bugs, Top
7457 @appendix Renamed Commands
7459 The following commands were renamed in GDB 4, in order to make the
7460 command set as a whole more consistent and easier to use and remember:
7463 @kindex delete environment
7464 @kindex info copying
7465 @kindex info convenience
7466 @kindex info directories
7467 @kindex info editing
7468 @kindex info history
7469 @kindex info targets
7471 @kindex info version
7472 @kindex info warranty
7473 @kindex set addressprint
7474 @kindex set arrayprint
7475 @kindex set prettyprint
7476 @kindex set screen-height
7477 @kindex set screen-width
7478 @kindex set unionprint
7479 @kindex set vtblprint
7480 @kindex set demangle
7481 @kindex set asm-demangle
7482 @kindex set sevenbit-strings
7483 @kindex set array-max
7485 @kindex set history write
7486 @kindex show addressprint
7487 @kindex show arrayprint
7488 @kindex show prettyprint
7489 @kindex show screen-height
7490 @kindex show screen-width
7491 @kindex show unionprint
7492 @kindex show vtblprint
7493 @kindex show demangle
7494 @kindex show asm-demangle
7495 @kindex show sevenbit-strings
7496 @kindex show array-max
7497 @kindex show caution
7498 @kindex show history write
7503 @c END TEXI2ROFF-KILL
7505 OLD COMMAND NEW COMMAND
7507 --------------- -------------------------------
7508 @c END TEXI2ROFF-KILL
7509 add-syms add-symbol-file
7510 delete environment unset environment
7511 info convenience show convenience
7512 info copying show copying
7513 info directories show directories
7514 info editing show commands
7515 info history show values
7516 info targets help target
7517 info values show values
7518 info version show version
7519 info warranty show warranty
7520 set/show addressprint set/show print address
7521 set/show array-max set/show print elements
7522 set/show arrayprint set/show print array
7523 set/show asm-demangle set/show print asm-demangle
7524 set/show caution set/show confirm
7525 set/show demangle set/show print demangle
7526 set/show history write set/show history save
7527 set/show prettyprint set/show print pretty
7528 set/show screen-height set/show height
7529 set/show screen-width set/show width
7530 set/show sevenbit-strings set/show print sevenbit-strings
7531 set/show unionprint set/show print union
7532 set/show vtblprint set/show print vtbl
7534 unset [No longer an alias for delete]
7540 \vskip \parskip\vskip \baselineskip
7541 \halign{\tt #\hfil &\qquad#&\tt #\hfil\cr
7542 {\bf Old Command} &&{\bf New Command}\cr
7543 add-syms &&add-symbol-file\cr
7544 delete environment &&unset environment\cr
7545 info convenience &&show convenience\cr
7546 info copying &&show copying\cr
7547 info directories &&show directories \cr
7548 info editing &&show commands\cr
7549 info history &&show values\cr
7550 info targets &&help target\cr
7551 info values &&show values\cr
7552 info version &&show version\cr
7553 info warranty &&show warranty\cr
7554 set{\rm / }show addressprint &&set{\rm / }show print address\cr
7555 set{\rm / }show array-max &&set{\rm / }show print elements\cr
7556 set{\rm / }show arrayprint &&set{\rm / }show print array\cr
7557 set{\rm / }show asm-demangle &&set{\rm / }show print asm-demangle\cr
7558 set{\rm / }show caution &&set{\rm / }show confirm\cr
7559 set{\rm / }show demangle &&set{\rm / }show print demangle\cr
7560 set{\rm / }show history write &&set{\rm / }show history save\cr
7561 set{\rm / }show prettyprint &&set{\rm / }show print pretty\cr
7562 set{\rm / }show screen-height &&set{\rm / }show height\cr
7563 set{\rm / }show screen-width &&set{\rm / }show width\cr
7564 set{\rm / }show sevenbit-strings &&set{\rm / }show print sevenbit-strings\cr
7565 set{\rm / }show unionprint &&set{\rm / }show print union\cr
7566 set{\rm / }show vtblprint &&set{\rm / }show print vtbl\cr
7568 unset &&\rm(No longer an alias for delete)\cr
7571 @c END TEXI2ROFF-KILL
7573 @node Installing GDB, Copying, Renamed Commands, Top
7574 @appendix Installing GDB
7575 @cindex configuring GDB
7576 @cindex installation
7579 @c irrelevant in info file; it's as current as the code it lives with.
7581 @emph{Warning:} These installation instructions are current as of
7582 GDB version 4.4.4. If you're installing a more recent release
7583 of GDB, we may have improved the installation procedures since
7584 printing this manual; see the @file{README} file included in your
7585 release for the most recent instructions.
7589 GDB comes with a @code{configure} script that automates the process
7590 of preparing GDB for installation; you can then use @code{make} to
7593 The GDB distribution includes all the source code you need for GDB in
7594 a single directory, whose name is usually composed by appending the
7595 version number to @samp{gdb}.
7597 For example, the GDB version 4.4.4 distribution is in the @file{gdb-4.4.4}
7598 directory. That directory contains:
7601 @item gdb-4.4.4/configure @r{(and supporting files)}
7602 script for configuring GDB and all its supporting libraries.
7605 the source specific to GDB itself
7608 source for the Binary File Descriptor Library
7610 @item gdb-4.4.4/include
7613 @item gdb-4.4.4/libiberty
7614 source for the @samp{-liberty} free software library
7616 @item gdb-4.4.4/readline
7617 source for the GNU command-line interface
7620 The simplest way to configure and build GDB is to run @code{configure}
7621 from the @file{gdb-@var{version-number}} source directory, which in
7622 this example is the @file{gdb-4.4.4} directory.
7624 First switch to the @file{gdb-@var{version-number}} source directory
7625 if you are not already in it; then run @code{configure}. Pass the
7626 identifier for the platform on which GDB will run as an
7633 ./configure @var{host}
7638 where @var{host} is an identifier such as @samp{sun4} or
7639 @samp{decstation}, that identifies the platform where GDB will run.
7641 These @code{configure} and @code{make} commands build the three libraries @file{bfd},
7642 @file{readline}, and @file{libiberty}, then @code{gdb} itself. The
7643 configured source files, and the binaries, are left in the
7644 corresponding source directories.
7646 @code{configure} is a Bourne-shell (@code{/bin/sh}) script; if your
7647 system does not recognize this automatically when you run a different
7648 shell, you may need to run @code{sh} on it explicitly:
7651 sh configure @var{host}
7654 If you run @code{configure} from a directory that contains source
7655 directories for multiple libraries or programs, such as the
7656 @file{gdb-4.4.4} source directory for version 4.4.4, @code{configure}
7657 creates configuration files for every directory level underneath (unless
7658 you tell it not to, with the @samp{--norecursion} option).
7660 You can run the @code{configure} script from any of the
7661 subordinate directories in the GDB distribution, if you only want to
7662 configure that subdirectory; but be sure to specify a path to it.
7664 For example, with version 4.4.4, type the following to configure only
7665 the @code{bfd} subdirectory:
7670 ../configure @var{host}
7674 You can install @code{gdb} anywhere; it has no hardwired paths.
7675 However, you should make sure that the shell on your path (named by
7676 the @samp{SHELL} environment variable) is publicly readable. Remember
7677 that GDB uses the shell to start your program---some systems refuse to
7678 let GDB debug child processes whose programs are not readable.
7681 * Separate Objdir:: Compiling GDB in another directory
7682 * Config Names:: Specifying names for hosts and targets
7683 * configure Options:: Summary of options for configure
7684 * Formatting Documentation:: How to format and print GDB documentation
7687 @node Separate Objdir, Config Names, Installing GDB, Installing GDB
7688 @section Compiling GDB in Another Directory
7690 If you want to run GDB versions for several host or target machines,
7691 you'll need a different @code{gdb} compiled for each combination of
7692 host and target. @code{configure} is designed to make this easy by
7693 allowing you to generate each configuration in a separate subdirectory,
7694 rather than in the source directory. If your @code{make} program
7695 handles the @samp{VPATH} feature (GNU @code{make} does), running
7696 @code{make} in each of these directories then builds the @code{gdb}
7697 program specified there.
7699 To build @code{gdb} in a separate directory, run @code{configure}
7700 with the @samp{--srcdir} option to specify where to find the source.
7701 (Remember, you'll also need to specify a path to find @code{configure}
7702 itself from your working directory.)
7704 For example, with version 4.4.4, you can build GDB in a separate
7705 directory for a Sun 4 like this:
7712 ../gdb-4.4.4/configure --srcdir=../gdb-4.4.4 sun4
7717 When @code{configure} builds a configuration using a remote source
7718 directory, it creates a tree for the binaries with the same structure
7719 (and using the same names) as the tree under the source directory. In
7720 the example, you'd find the Sun 4 library @file{libiberty.a} in the
7721 directory @file{gdb-sun4/libiberty}, and GDB itself in
7722 @file{gdb-sun4/gdb}.
7724 One popular use for building several GDB configurations in separate
7725 directories is to configure GDB for cross-compiling (where GDB
7726 runs on one machine---the host---while debugging programs that run on
7727 another machine---the target). You specify a cross-debugging target by
7728 giving the @samp{--target=@var{target}} option to @code{configure}.
7730 When you run @code{make} to build a program or library, you must run
7731 it in a configured directory---whatever directory you were in when you
7732 called @code{configure} (or one of its subdirectories).
7734 The @code{Makefile} generated by @code{configure} for each source
7735 directory also runs recursively. If you type @code{make} in a source
7736 directory such as @file{gdb-4.4.4} (or in a separate configured
7737 directory configured with @samp{--srcdir=@var{path}/gdb-4.4.4}), you
7738 will build all the required libraries, then build GDB.
7740 When you have multiple hosts or targets configured in separate
7741 directories, you can run @code{make} on them in parallel (for example,
7742 if they are NFS-mounted on each of the hosts); they will not interfere
7745 @node Config Names, configure Options, Separate Objdir, Installing GDB
7746 @section Specifying Names for Hosts and Targets
7748 The specifications used for hosts and targets in the @code{configure}
7749 script are based on a three-part naming scheme, but some short predefined
7750 aliases are also supported. The full naming scheme encodes three pieces
7751 of information in the following pattern:
7754 @var{architecture}-@var{vendor}-@var{os}
7757 For example, you can use the alias @code{sun4} as a @var{host} argument
7758 or in a @code{--target=@var{target}} option, but the equivalent full name
7759 is @samp{sparc-sun-sunos4}.
7761 The following table shows all the architectures, hosts, and OS
7762 prefixes that @code{configure} recognizes in GDB version 4.4.4. Entries
7763 in the ``OS prefix'' column ending in a @samp{*} may be followed by a
7766 @c FIXME! Update for gdb 4.4
7769 @c END TEXI2ROFF-KILL
7772 ARCHITECTURE VENDOR OS prefix
7774 ------------+--------------------------+---------------------------
7775 @c END TEXI2ROFF-KILL
7777 580 | altos hp | aix* msdos*
7778 a29k | amd ibm | amigados newsos*
7779 alliant | amdahl intel | aout nindy*
7780 arm | aout isi | bout osf*
7781 c1 | apollo little | bsd* sco*
7782 c2 | att mips | coff sunos*
7783 cray2 | bcs motorola | ctix* svr4
7784 h8300 | bout ncr | dgux* sym*
7785 i386 | bull next | dynix* sysv*
7786 i860 | cbm nyu | ebmon ultrix*
7787 i960 | coff sco | esix* unicos*
7788 m68000 | convergent sequent | hds unos*
7789 m68k | convex sgi | hpux* uts
7790 m88k | cray sony | irix* v88r*
7791 mips | dec sun | isc* vms*
7792 ns32k | encore unicom | kern vxworks*
7793 pyramid | gould utek | mach*
7794 romp | hitachi wrs |
7808 \vskip \baselineskip
7809 \hfil\vbox{\offinterlineskip
7810 \halign{\strut\tt #\hfil\ &\vrule#&\strut\ \tt #\hfil\ &\strut\ \tt #\hfil
7811 \ &\vrule#&\strut\ \tt #\hfil\ &\strut\ \tt #\hfil \cr
7812 {\bf Architecture} &&{\bf Vendor} &&&{\bf OS prefix}\cr
7813 \multispan7\hrulefill\cr
7814 580 && altos & hp && aix* & msdos* \cr
7815 a29k && amd & ibm && amigados & newsos* \cr
7816 alliant && amdahl & intel && aout & nindy* \cr
7817 arm && aout & isi && bout & osf* \cr
7818 c1 && apollo & little && bsd* & sco* \cr
7819 c2 && att & mips && coff & sunos* \cr
7820 cray2 && bcs & motorola && ctix* & svr4 \cr
7821 h8300 && bout & ncr && dgux* & sym* \cr
7822 i386 && bull & next && dynix* & sysv* \cr
7823 i860 && cbm & nyu && ebmon & ultrix* \cr
7824 i960 && coff & sco && esix* & unicos* \cr
7825 m68000 && convergent& sequent && hds & unos* \cr
7826 m68k && convex & sgi && hpux* & uts \cr
7827 m88k && cray & sony && irix* & v88r* \cr
7828 mips && dec & sun && isc* & vms* \cr
7829 ns32k && encore & unicom && kern & vxworks* \cr
7830 pyramid && gould & utek && mach* & \cr
7831 romp && hitachi & wrs && & \cr
7832 rs6000 && & && & \cr
7841 @c END TEXI2ROFF-KILL
7844 @emph{Warning:} @code{configure} can represent a very large number of
7845 combinations of architecture, vendor, and OS. There is by no means
7846 support available for all possible combinations!
7849 The @code{configure} script accompanying GDB does not provide
7850 any query facility to list all supported host and target names or
7851 aliases. @code{configure} calls the Bourne shell script
7852 @code{config.sub} to map abbreviations to full names; you can read the
7853 script, if you wish, or you can use it to test your guesses on
7854 abbreviations---for example:
7857 % sh config.sub sun4
7859 % sh config.sub sun3
7861 % sh config.sub decstation
7863 % sh config.sub hp300bsd
7865 % sh config.sub i386v
7867 % sh config.sub i786v
7868 *** Configuration "i786v" not recognized
7872 @code{config.sub} is also distributed in the GDB source
7873 directory (@file{gdb-4.4.4}, for version 4.4.4).
7875 @node configure Options, Formatting Documentation, Config Names, Installing GDB
7876 @section @code{configure} Options
7878 Here is a summary of all the @code{configure} options and arguments that
7879 you might use for building GDB:
7882 configure @r{[}--destdir=@var{dir}@r{]} @r{[}--srcdir=@var{path}@r{]}
7883 @r{[}--norecursion@r{]} @r{[}--rm@r{]}
7884 @r{[}--target=@var{target}@r{]} @var{host}
7888 You may introduce options with a single @samp{-} rather than
7889 @samp{--} if you prefer; but you may abbreviate option names if you use
7893 @item --destdir=@var{dir}
7894 @var{dir} is an installation directory @emph{path prefix}. After you
7895 configure with this option, @code{make install} will install GDB as
7896 @file{@var{dir}/bin/gdb}, and the libraries in @file{@var{dir}/lib}.
7897 If you specify @samp{--destdir=/usr/local}, for example, @code{make
7898 install} creates @file{/usr/local/bin/gdb}.
7900 @item --srcdir=@var{path}
7901 Use this option to make configurations in directories separate from the
7902 GDB source directories. Among other things, you can use this to
7903 build (or maintain) several configurations simultaneously, in separate
7904 directories. @code{configure} writes configuration specific files in
7905 the current directory, but arranges for them to use the source in the
7906 directory @var{path}. @code{configure} will create directories under
7907 the working directory in parallel to the source directories below
7911 Configure only the directory level where @code{configure} is executed; do not
7912 propagate configuration to subdirectories.
7915 Remove the configuration that the other arguments specify.
7917 @c This does not work (yet if ever). FIXME.
7918 @c @item --parse=@var{lang} @dots{}
7919 @c Configure the GDB expression parser to parse the listed languages.
7920 @c @samp{all} configures GDB for all supported languages. To get a
7921 @c list of all supported languages, omit the argument. Without this
7922 @c option, GDB is configured to parse all supported languages.
7924 @item --target=@var{target}
7925 Configure GDB for cross-debugging programs running on the specified
7926 @var{target}. Without this option, GDB is configured to debug
7927 programs that run on the same machine (@var{host}) as GDB itself.
7929 There is no convenient way to generate a list of all available targets.
7931 @item @var{host} @dots{}
7932 Configure GDB to run on the specified @var{host}.
7934 There is no convenient way to generate a list of all available hosts.
7938 @code{configure} accepts other options, for compatibility with
7939 configuring other GNU tools recursively; but these are the only
7940 options that affect GDB or its supporting libraries.
7942 @node Formatting Documentation, , configure Options, Installing GDB
7943 @section Formatting the Documentation
7945 All the documentation for GDB, including this manual, comes as part of
7946 the distribution. The documentation is written in Texinfo format,
7947 which is a documentation system that uses a single source file to
7948 produce both on-line information and a printed manual. You can use
7949 one of the Info formatting commands to create the on-line version of
7950 the documentation and @TeX{} (or @code{texi2roff}) to typeset the
7953 GDB includes an already formatted copy of the on-line Info version of
7954 this manual in the @file{gdb} subdirectory. The main Info file is
7955 @file{gdb-@var{version-number}/gdb/gdb.info}, and it refers to
7956 subordinate files matching @samp{gdb.info*} in the same directory.
7958 If you want to format these Info files yourself, you need one of the
7959 Info formatting programs, such as @code{texinfo-format-buffer} or
7962 If you have @code{makeinfo} installed, and are in the top level GDB
7963 source directory (@file{gdb-4.4.4}, in the case of version 4.4.4), you can
7964 make the Info file by typing:
7971 If you want to typeset and print copies of this manual, you need
7972 @TeX{}, a printing program such as @code{lpr}, and @file{texinfo.tex},
7973 the Texinfo definitions file.
7975 @TeX{} is typesetting program; it does not print files directly, but
7976 produces output files called @sc{dvi} files. To print a typeset
7977 document, you need a program to print @sc{dvi} files. If your system
7978 has @TeX{} installed, chances are it has such a program. The precise
7979 command to use depends on your system; @kbd{lpr -d} is common; another
7980 is @kbd{dvips}. The @sc{dvi} print command may require a file name
7981 without any extension or a @samp{.dvi} extension.
7983 @TeX{} also requires a macro definitions file called
7984 @file{texinfo.tex}. This file tells @TeX{} how to typeset a document
7985 written in Texinfo format. On its own, @TeX{} cannot read, much less
7986 typeset a Texinfo file. @file{texinfo.tex} is distributed with GDB
7987 and is located in the @file{gdb-@var{version-number}/texinfo}
7990 If you have @TeX{} and a @sc{dvi} printer program installed, you can
7991 typeset and print this manual. First switch to the the @file{gdb}
7992 subdirectory of the main source directory (for example, to
7993 @file{gdb-4.4.4/gdb}) and then type:
7999 @cindex GDB reference card
8000 @cindex reference card
8001 In addition to the manual, the GDB 4 release includes a three-column
8002 reference card. Format the GDB reference card by typing:
8008 The GDB reference card is designed to print in landscape mode on US
8009 ``letter'' size paper; that is, on a sheet 11 inches wide by 8.5 inches
8010 high. You will need to specify this form of printing as an option to
8011 your @sc{dvi} output program.
8013 The GDB 4 release includes an already-formatted reference card, ready
8014 for printing on a PostScript or GhostScript printer, in the @file{gdb}
8015 subdirectory of the main source directory---in
8016 @file{gdb-4.2/gdb/refcard.ps} of the version 4.2 release. If you have
8017 a PostScript or GhostScript printer, you can print the reference card
8018 by just sending @file{refcard.ps} to the printer.
8020 @node Copying, Index, Installing GDB, Top
8021 @unnumbered GNU GENERAL PUBLIC LICENSE
8022 @center Version 2, June 1991
8025 Copyright @copyright{} 1989, 1991 Free Software Foundation, Inc.
8026 675 Mass Ave, Cambridge, MA 02139, USA
8028 Everyone is permitted to copy and distribute verbatim copies
8029 of this license document, but changing it is not allowed.
8032 @unnumberedsec Preamble
8034 The licenses for most software are designed to take away your
8035 freedom to share and change it. By contrast, the GNU General Public
8036 License is intended to guarantee your freedom to share and change free
8037 software---to make sure the software is free for all its users. This
8038 General Public License applies to most of the Free Software
8039 Foundation's software and to any other program whose authors commit to
8040 using it. (Some other Free Software Foundation software is covered by
8041 the GNU Library General Public License instead.) You can apply it to
8044 When we speak of free software, we are referring to freedom, not
8045 price. Our General Public Licenses are designed to make sure that you
8046 have the freedom to distribute copies of free software (and charge for
8047 this service if you wish), that you receive source code or can get it
8048 if you want it, that you can change the software or use pieces of it
8049 in new free programs; and that you know you can do these things.
8051 To protect your rights, we need to make restrictions that forbid
8052 anyone to deny you these rights or to ask you to surrender the rights.
8053 These restrictions translate to certain responsibilities for you if you
8054 distribute copies of the software, or if you modify it.
8056 For example, if you distribute copies of such a program, whether
8057 gratis or for a fee, you must give the recipients all the rights that
8058 you have. You must make sure that they, too, receive or can get the
8059 source code. And you must show them these terms so they know their
8062 We protect your rights with two steps: (1) copyright the software, and
8063 (2) offer you this license which gives you legal permission to copy,
8064 distribute and/or modify the software.
8066 Also, for each author's protection and ours, we want to make certain
8067 that everyone understands that there is no warranty for this free
8068 software. If the software is modified by someone else and passed on, we
8069 want its recipients to know that what they have is not the original, so
8070 that any problems introduced by others will not reflect on the original
8071 authors' reputations.
8073 Finally, any free program is threatened constantly by software
8074 patents. We wish to avoid the danger that redistributors of a free
8075 program will individually obtain patent licenses, in effect making the
8076 program proprietary. To prevent this, we have made it clear that any
8077 patent must be licensed for everyone's free use or not licensed at all.
8079 The precise terms and conditions for copying, distribution and
8080 modification follow.
8083 @unnumberedsec TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
8086 @center TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
8091 This License applies to any program or other work which contains
8092 a notice placed by the copyright holder saying it may be distributed
8093 under the terms of this General Public License. The ``Program'', below,
8094 refers to any such program or work, and a ``work based on the Program''
8095 means either the Program or any derivative work under copyright law:
8096 that is to say, a work containing the Program or a portion of it,
8097 either verbatim or with modifications and/or translated into another
8098 language. (Hereinafter, translation is included without limitation in
8099 the term ``modification''.) Each licensee is addressed as ``you''.
8101 Activities other than copying, distribution and modification are not
8102 covered by this License; they are outside its scope. The act of
8103 running the Program is not restricted, and the output from the Program
8104 is covered only if its contents constitute a work based on the
8105 Program (independent of having been made by running the Program).
8106 Whether that is true depends on what the Program does.
8109 You may copy and distribute verbatim copies of the Program's
8110 source code as you receive it, in any medium, provided that you
8111 conspicuously and appropriately publish on each copy an appropriate
8112 copyright notice and disclaimer of warranty; keep intact all the
8113 notices that refer to this License and to the absence of any warranty;
8114 and give any other recipients of the Program a copy of this License
8115 along with the Program.
8117 You may charge a fee for the physical act of transferring a copy, and
8118 you may at your option offer warranty protection in exchange for a fee.
8121 You may modify your copy or copies of the Program or any portion
8122 of it, thus forming a work based on the Program, and copy and
8123 distribute such modifications or work under the terms of Section 1
8124 above, provided that you also meet all of these conditions:
8128 You must cause the modified files to carry prominent notices
8129 stating that you changed the files and the date of any change.
8132 You must cause any work that you distribute or publish, that in
8133 whole or in part contains or is derived from the Program or any
8134 part thereof, to be licensed as a whole at no charge to all third
8135 parties under the terms of this License.
8138 If the modified program normally reads commands interactively
8139 when run, you must cause it, when started running for such
8140 interactive use in the most ordinary way, to print or display an
8141 announcement including an appropriate copyright notice and a
8142 notice that there is no warranty (or else, saying that you provide
8143 a warranty) and that users may redistribute the program under
8144 these conditions, and telling the user how to view a copy of this
8145 License. (Exception: if the Program itself is interactive but
8146 does not normally print such an announcement, your work based on
8147 the Program is not required to print an announcement.)
8150 These requirements apply to the modified work as a whole. If
8151 identifiable sections of that work are not derived from the Program,
8152 and can be reasonably considered independent and separate works in
8153 themselves, then this License, and its terms, do not apply to those
8154 sections when you distribute them as separate works. But when you
8155 distribute the same sections as part of a whole which is a work based
8156 on the Program, the distribution of the whole must be on the terms of
8157 this License, whose permissions for other licensees extend to the
8158 entire whole, and thus to each and every part regardless of who wrote it.
8160 Thus, it is not the intent of this section to claim rights or contest
8161 your rights to work written entirely by you; rather, the intent is to
8162 exercise the right to control the distribution of derivative or
8163 collective works based on the Program.
8165 In addition, mere aggregation of another work not based on the Program
8166 with the Program (or with a work based on the Program) on a volume of
8167 a storage or distribution medium does not bring the other work under
8168 the scope of this License.
8171 You may copy and distribute the Program (or a work based on it,
8172 under Section 2) in object code or executable form under the terms of
8173 Sections 1 and 2 above provided that you also do one of the following:
8177 Accompany it with the complete corresponding machine-readable
8178 source code, which must be distributed under the terms of Sections
8179 1 and 2 above on a medium customarily used for software interchange; or,
8182 Accompany it with a written offer, valid for at least three
8183 years, to give any third party, for a charge no more than your
8184 cost of physically performing source distribution, a complete
8185 machine-readable copy of the corresponding source code, to be
8186 distributed under the terms of Sections 1 and 2 above on a medium
8187 customarily used for software interchange; or,
8190 Accompany it with the information you received as to the offer
8191 to distribute corresponding source code. (This alternative is
8192 allowed only for noncommercial distribution and only if you
8193 received the program in object code or executable form with such
8194 an offer, in accord with Subsection b above.)
8197 The source code for a work means the preferred form of the work for
8198 making modifications to it. For an executable work, complete source
8199 code means all the source code for all modules it contains, plus any
8200 associated interface definition files, plus the scripts used to
8201 control compilation and installation of the executable. However, as a
8202 special exception, the source code distributed need not include
8203 anything that is normally distributed (in either source or binary
8204 form) with the major components (compiler, kernel, and so on) of the
8205 operating system on which the executable runs, unless that component
8206 itself accompanies the executable.
8208 If distribution of executable or object code is made by offering
8209 access to copy from a designated place, then offering equivalent
8210 access to copy the source code from the same place counts as
8211 distribution of the source code, even though third parties are not
8212 compelled to copy the source along with the object code.
8215 You may not copy, modify, sublicense, or distribute the Program
8216 except as expressly provided under this License. Any attempt
8217 otherwise to copy, modify, sublicense or distribute the Program is
8218 void, and will automatically terminate your rights under this License.
8219 However, parties who have received copies, or rights, from you under
8220 this License will not have their licenses terminated so long as such
8221 parties remain in full compliance.
8224 You are not required to accept this License, since you have not
8225 signed it. However, nothing else grants you permission to modify or
8226 distribute the Program or its derivative works. These actions are
8227 prohibited by law if you do not accept this License. Therefore, by
8228 modifying or distributing the Program (or any work based on the
8229 Program), you indicate your acceptance of this License to do so, and
8230 all its terms and conditions for copying, distributing or modifying
8231 the Program or works based on it.
8234 Each time you redistribute the Program (or any work based on the
8235 Program), the recipient automatically receives a license from the
8236 original licensor to copy, distribute or modify the Program subject to
8237 these terms and conditions. You may not impose any further
8238 restrictions on the recipients' exercise of the rights granted herein.
8239 You are not responsible for enforcing compliance by third parties to
8243 If, as a consequence of a court judgment or allegation of patent
8244 infringement or for any other reason (not limited to patent issues),
8245 conditions are imposed on you (whether by court order, agreement or
8246 otherwise) that contradict the conditions of this License, they do not
8247 excuse you from the conditions of this License. If you cannot
8248 distribute so as to satisfy simultaneously your obligations under this
8249 License and any other pertinent obligations, then as a consequence you
8250 may not distribute the Program at all. For example, if a patent
8251 license would not permit royalty-free redistribution of the Program by
8252 all those who receive copies directly or indirectly through you, then
8253 the only way you could satisfy both it and this License would be to
8254 refrain entirely from distribution of the Program.
8256 If any portion of this section is held invalid or unenforceable under
8257 any particular circumstance, the balance of the section is intended to
8258 apply and the section as a whole is intended to apply in other
8261 It is not the purpose of this section to induce you to infringe any
8262 patents or other property right claims or to contest validity of any
8263 such claims; this section has the sole purpose of protecting the
8264 integrity of the free software distribution system, which is
8265 implemented by public license practices. Many people have made
8266 generous contributions to the wide range of software distributed
8267 through that system in reliance on consistent application of that
8268 system; it is up to the author/donor to decide if he or she is willing
8269 to distribute software through any other system and a licensee cannot
8272 This section is intended to make thoroughly clear what is believed to
8273 be a consequence of the rest of this License.
8276 If the distribution and/or use of the Program is restricted in
8277 certain countries either by patents or by copyrighted interfaces, the
8278 original copyright holder who places the Program under this License
8279 may add an explicit geographical distribution limitation excluding
8280 those countries, so that distribution is permitted only in or among
8281 countries not thus excluded. In such case, this License incorporates
8282 the limitation as if written in the body of this License.
8285 The Free Software Foundation may publish revised and/or new versions
8286 of the General Public License from time to time. Such new versions will
8287 be similar in spirit to the present version, but may differ in detail to
8288 address new problems or concerns.
8290 Each version is given a distinguishing version number. If the Program
8291 specifies a version number of this License which applies to it and ``any
8292 later version'', you have the option of following the terms and conditions
8293 either of that version or of any later version published by the Free
8294 Software Foundation. If the Program does not specify a version number of
8295 this License, you may choose any version ever published by the Free Software
8299 If you wish to incorporate parts of the Program into other free
8300 programs whose distribution conditions are different, write to the author
8301 to ask for permission. For software which is copyrighted by the Free
8302 Software Foundation, write to the Free Software Foundation; we sometimes
8303 make exceptions for this. Our decision will be guided by the two goals
8304 of preserving the free status of all derivatives of our free software and
8305 of promoting the sharing and reuse of software generally.
8308 @heading NO WARRANTY
8315 BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
8316 FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN
8317 OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
8318 PROVIDE THE PROGRAM ``AS IS'' WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED
8319 OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
8320 MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS
8321 TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE
8322 PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,
8323 REPAIR OR CORRECTION.
8326 IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
8327 WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
8328 REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,
8329 INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING
8330 OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED
8331 TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY
8332 YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER
8333 PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE
8334 POSSIBILITY OF SUCH DAMAGES.
8338 @heading END OF TERMS AND CONDITIONS
8341 @center END OF TERMS AND CONDITIONS
8345 @unnumberedsec Applying These Terms to Your New Programs
8347 If you develop a new program, and you want it to be of the greatest
8348 possible use to the public, the best way to achieve this is to make it
8349 free software which everyone can redistribute and change under these terms.
8351 To do so, attach the following notices to the program. It is safest
8352 to attach them to the start of each source file to most effectively
8353 convey the exclusion of warranty; and each file should have at least
8354 the ``copyright'' line and a pointer to where the full notice is found.
8357 @var{one line to give the program's name and an idea of what it does.}
8358 Copyright (C) 19@var{yy} @var{name of author}
8360 This program is free software; you can redistribute it and/or
8361 modify it under the terms of the GNU General Public License
8362 as published by the Free Software Foundation; either version 2
8363 of the License, or (at your option) any later version.
8365 This program is distributed in the hope that it will be useful,
8366 but WITHOUT ANY WARRANTY; without even the implied warranty of
8367 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
8368 GNU General Public License for more details.
8370 You should have received a copy of the GNU General Public License
8371 along with this program; if not, write to the
8372 Free Software Foundation, Inc., 675 Mass Ave,
8373 Cambridge, MA 02139, USA.
8376 Also add information on how to contact you by electronic and paper mail.
8378 If the program is interactive, make it output a short notice like this
8379 when it starts in an interactive mode:
8382 Gnomovision version 69, Copyright (C) 19@var{yy} @var{name of author}
8383 Gnomovision comes with ABSOLUTELY NO WARRANTY; for details
8384 type `show w'. This is free software, and you are welcome
8385 to redistribute it under certain conditions; type `show c'
8389 The hypothetical commands @samp{show w} and @samp{show c} should show
8390 the appropriate parts of the General Public License. Of course, the
8391 commands you use may be called something other than @samp{show w} and
8392 @samp{show c}; they could even be mouse-clicks or menu items---whatever
8395 You should also get your employer (if you work as a programmer) or your
8396 school, if any, to sign a ``copyright disclaimer'' for the program, if
8397 necessary. Here is a sample; alter the names:
8400 Yoyodyne, Inc., hereby disclaims all copyright
8401 interest in the program `Gnomovision'
8402 (which makes passes at compilers) written
8405 @var{signature of Ty Coon}, 1 April 1989
8406 Ty Coon, President of Vice
8409 This General Public License does not permit incorporating your program into
8410 proprietary programs. If your program is a subroutine library, you may
8411 consider it more useful to permit linking proprietary applications with the
8412 library. If this is what you want to do, use the GNU Library General
8413 Public License instead of this License.
8415 @node Index, , Copying, Top
8421 % I think something like @colophon should be in texinfo. In the
8423 \long\def\colophon{\hbox to0pt{}\vfill
8424 \centerline{The body of this manual is set in}
8425 \centerline{\fontname\tenrm,}
8426 \centerline{with headings in {\bf\fontname\tenbf}}
8427 \centerline{and examples in {\tt\fontname\tentt}.}
8428 \centerline{{\it\fontname\tenit\/},}
8429 \centerline{{\bf\fontname\tenbf}, and}
8430 \centerline{{\sl\fontname\tensl\/}}
8431 \centerline{are used for emphasis.}\vfill}
8433 % Blame: pesch@cygnus.com, 1991.