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