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