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