]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blame - gdb/doc/gdb.texinfo
import gdb-2000-01-05 snapshot
[thirdparty/binutils-gdb.git] / gdb / doc / gdb.texinfo
CommitLineData
c906108c
SS
1\input texinfo @c -*-texinfo-*-
2@c Copyright 1988-1999
3@c Free Software Foundation, Inc.
4@c
5@c %**start of header
6@c makeinfo ignores cmds prev to setfilename, so its arg cannot make use
7@c of @set vars. However, you can override filename with makeinfo -o.
8@setfilename gdb.info
9@c
10@include gdb-cfg.texi
11@c
c906108c 12@settitle Debugging with @value{GDBN}
c906108c
SS
13@setchapternewpage odd
14@c %**end of header
15
16@iftex
17@c @smallbook
18@c @cropmarks
19@end iftex
20
21@finalout
22@syncodeindex ky cp
23
24@c readline appendices use @vindex
25@syncodeindex vr cp
26
27@c !!set GDB manual's edition---not the same as GDB version!
28@set EDITION Seventh
29
30@c !!set GDB manual's revision date
31@set DATE February 1999
32
33@c THIS MANUAL REQUIRES TEXINFO-2 macros and info-makers to format properly.
34
35@ifinfo
36@c This is a dir.info fragment to support semi-automated addition of
37@c manuals to an info tree. zoo@cygnus.com is developing this facility.
38@format
39START-INFO-DIR-ENTRY
40* Gdb: (gdb). The @sc{gnu} debugger.
41END-INFO-DIR-ENTRY
42@end format
43@end ifinfo
44@c
45@c
46@ifinfo
47This file documents the @sc{gnu} debugger @value{GDBN}.
48
49
50This is the @value{EDITION} Edition, @value{DATE},
51of @cite{Debugging with @value{GDBN}: the @sc{gnu} Source-Level Debugger}
52for @value{GDBN} Version @value{GDBVN}.
53
54Copyright (C) 1988-1999 Free Software Foundation, Inc.
55
56Permission is granted to make and distribute verbatim copies of
57this manual provided the copyright notice and this permission notice
58are preserved on all copies.
59
60@ignore
61Permission is granted to process this file through TeX and print the
62results, provided the printed document carries copying permission
63notice identical to this one except for the removal of this paragraph
64(this paragraph not being relevant to the printed manual).
65
66@end ignore
67Permission is granted to copy and distribute modified versions of this
68manual under the conditions for verbatim copying, provided also that the
69entire resulting derived work is distributed under the terms of a
70permission notice identical to this one.
71
72Permission is granted to copy and distribute translations of this manual
73into another language, under the above conditions for modified versions.
74@end ifinfo
75
76@titlepage
77@title Debugging with @value{GDBN}
78@subtitle The @sc{gnu} Source-Level Debugger
c906108c 79@sp 1
c906108c
SS
80@subtitle @value{EDITION} Edition, for @value{GDBN} version @value{GDBVN}
81@subtitle @value{DATE}
82@author Richard M. Stallman and Roland H. Pesch
c906108c 83@page
c906108c
SS
84@tex
85{\parskip=0pt
53a5351d 86\hfill (Send bugs and comments on @value{GDBN} to bug-gdb\@gnu.org.)\par
c906108c
SS
87\hfill {\it Debugging with @value{GDBN}}\par
88\hfill \TeX{}info \texinfoversion\par
89}
90@end tex
53a5351d
JM
91
92@c ISBN seems to be wrong...
c906108c
SS
93
94@vskip 0pt plus 1filll
95Copyright @copyright{} 1988-1999 Free Software Foundation, Inc.
96@sp 2
c906108c
SS
97Published by the Free Software Foundation @*
9859 Temple Place - Suite 330, @*
99Boston, MA 02111-1307 USA @*
100Printed copies are available for $20 each. @*
101ISBN 1-882114-11-6 @*
c906108c
SS
102
103Permission is granted to make and distribute verbatim copies of
104this manual provided the copyright notice and this permission notice
105are preserved on all copies.
106
107Permission is granted to copy and distribute modified versions of this
108manual under the conditions for verbatim copying, provided also that the
109entire resulting derived work is distributed under the terms of a
110permission notice identical to this one.
111
112Permission is granted to copy and distribute translations of this manual
113into another language, under the above conditions for modified versions.
114@end titlepage
115@page
116
117@ifinfo
53a5351d 118@node Top
c906108c
SS
119@top Debugging with @value{GDBN}
120
121This file describes @value{GDBN}, the @sc{gnu} symbolic debugger.
122
123This is the @value{EDITION} Edition, @value{DATE}, for @value{GDBN} Version
124@value{GDBVN}.
125
126Copyright (C) 1988-1999 Free Software Foundation, Inc.
127@menu
128* Summary:: Summary of @value{GDBN}
c906108c 129* Sample Session:: A sample @value{GDBN} session
c906108c
SS
130
131* Invocation:: Getting in and out of @value{GDBN}
132* Commands:: @value{GDBN} commands
133* Running:: Running programs under @value{GDBN}
134* Stopping:: Stopping and continuing
135* Stack:: Examining the stack
136* Source:: Examining source files
137* Data:: Examining data
c906108c 138
7a292a7a 139* Languages:: Using @value{GDBN} with different languages
c906108c
SS
140
141* Symbols:: Examining the symbol table
142* Altering:: Altering execution
143* GDB Files:: @value{GDBN} files
144* Targets:: Specifying a debugging target
104c1213 145* Configurations:: Configuration-specific information
c906108c
SS
146* Controlling GDB:: Controlling @value{GDBN}
147* Sequences:: Canned sequences of commands
c906108c 148* Emacs:: Using @value{GDBN} under @sc{gnu} Emacs
c906108c
SS
149
150* GDB Bugs:: Reporting bugs in @value{GDBN}
c906108c 151* Formatting Documentation:: How to format and print @value{GDBN} documentation
c906108c
SS
152
153* Command Line Editing:: Command Line Editing
154* Using History Interactively:: Using History Interactively
155* Installing GDB:: Installing GDB
156* Index:: Index
c906108c
SS
157@end menu
158
159@end ifinfo
160
53a5351d 161@node Summary
c906108c
SS
162@unnumbered Summary of @value{GDBN}
163
164The purpose of a debugger such as @value{GDBN} is to allow you to see what is
165going on ``inside'' another program while it executes---or what another
166program was doing at the moment it crashed.
167
168@value{GDBN} can do four main kinds of things (plus other things in support of
169these) to help you catch bugs in the act:
170
171@itemize @bullet
172@item
173Start your program, specifying anything that might affect its behavior.
174
175@item
176Make your program stop on specified conditions.
177
178@item
179Examine what has happened, when your program has stopped.
180
181@item
182Change things in your program, so you can experiment with correcting the
183effects of one bug and go on to learn about another.
184@end itemize
185
cce74817 186You can use @value{GDBN} to debug programs written in C and C++.
c906108c 187For more information, see @ref{Support,,Supported languages}.
c906108c
SS
188For more information, see @ref{C,,C and C++}.
189
cce74817
JM
190@cindex Chill
191@cindex Modula-2
c906108c 192Support for Modula-2 and Chill is partial. For information on Modula-2,
cce74817 193see @ref{Modula-2,,Modula-2}. For information on Chill, see @ref{Chill}.
c906108c 194
cce74817
JM
195@cindex Pascal
196Debugging Pascal programs which use sets, subranges, file variables, or
197nested functions does not currently work. @value{GDBN} does not support
198entering expressions, printing values, or similar features using Pascal
199syntax.
c906108c 200
c906108c
SS
201@cindex Fortran
202@value{GDBN} can be used to debug programs written in Fortran, although
53a5351d 203it may be necessary to refer to some variables with a trailing
cce74817 204underscore.
c906108c 205
c906108c
SS
206@menu
207* Free Software:: Freely redistributable software
208* Contributors:: Contributors to GDB
209@end menu
210
53a5351d 211@node Free Software
c906108c
SS
212@unnumberedsec Free software
213
214@value{GDBN} is @dfn{free software}, protected by the @sc{gnu}
215General Public License
216(GPL). The GPL gives you the freedom to copy or adapt a licensed
217program---but every person getting a copy also gets with it the
218freedom to modify that copy (which means that they must get access to
219the source code), and the freedom to distribute further copies.
220Typical software companies use copyrights to limit your freedoms; the
221Free Software Foundation uses the GPL to preserve these freedoms.
222
223Fundamentally, the General Public License is a license which says that
224you have these freedoms and that you cannot take these freedoms away
225from anyone else.
226
53a5351d 227@node Contributors
c906108c
SS
228@unnumberedsec Contributors to GDB
229
230Richard Stallman was the original author of GDB, and of many other
231@sc{gnu} programs. Many others have contributed to its development.
232This section attempts to credit major contributors. One of the virtues
233of free software is that everyone is free to contribute to it; with
234regret, we cannot actually acknowledge everyone here. The file
235@file{ChangeLog} in the @value{GDBN} distribution approximates a
236blow-by-blow account.
237
238Changes much prior to version 2.0 are lost in the mists of time.
239
240@quotation
241@emph{Plea:} Additions to this section are particularly welcome. If you
242or your friends (or enemies, to be evenhanded) have been unfairly
243omitted from this list, we would like to add your names!
244@end quotation
245
246So that they may not regard their many labors as thankless, we
247particularly thank those who shepherded @value{GDBN} through major
248releases:
249Jim Blandy (release 4.18);
250Jason Molenda (release 4.17);
251Stan Shebs (release 4.14);
252Fred Fish (releases 4.16, 4.15, 4.13, 4.12, 4.11, 4.10, and 4.9);
253Stu Grossman and John Gilmore (releases 4.8, 4.7, 4.6, 4.5, and 4.4);
254John Gilmore (releases 4.3, 4.2, 4.1, 4.0, and 3.9);
255Jim Kingdon (releases 3.5, 3.4, and 3.3);
256and Randy Smith (releases 3.2, 3.1, and 3.0).
257
258Richard Stallman, assisted at various times by Peter TerMaat, Chris
259Hanson, and Richard Mlynarik, handled releases through 2.8.
260
c906108c
SS
261Michael Tiemann is the author of most of the @sc{gnu} C++ support in GDB,
262with significant additional contributions from Per Bothner. James
263Clark wrote the @sc{gnu} C++ demangler. Early work on C++ was by Peter
264TerMaat (who also did much general update work leading to release 3.0).
c906108c
SS
265
266@value{GDBN} 4 uses the BFD subroutine library to examine multiple
267object-file formats; BFD was a joint project of David V.
268Henkel-Wallace, Rich Pixley, Steve Chamberlain, and John Gilmore.
269
270David Johnson wrote the original COFF support; Pace Willison did
271the original support for encapsulated COFF.
272
273Brent Benson of Harris Computer Systems contributed DWARF 2 support.
274
275Adam de Boor and Bradley Davis contributed the ISI Optimum V support.
276Per Bothner, Noboyuki Hikichi, and Alessandro Forin contributed MIPS
277support.
278Jean-Daniel Fekete contributed Sun 386i support.
279Chris Hanson improved the HP9000 support.
280Noboyuki Hikichi and Tomoyuki Hasei contributed Sony/News OS 3 support.
281David Johnson contributed Encore Umax support.
282Jyrki Kuoppala contributed Altos 3068 support.
283Jeff Law contributed HP PA and SOM support.
284Keith Packard contributed NS32K support.
285Doug Rabson contributed Acorn Risc Machine support.
286Bob Rusk contributed Harris Nighthawk CX-UX support.
287Chris Smith contributed Convex support (and Fortran debugging).
288Jonathan Stone contributed Pyramid support.
289Michael Tiemann contributed SPARC support.
290Tim Tucker contributed support for the Gould NP1 and Gould Powernode.
291Pace Willison contributed Intel 386 support.
292Jay Vosburgh contributed Symmetry support.
293
294Andreas Schwab contributed M68K Linux support.
295
296Rich Schaefer and Peter Schauer helped with support of SunOS shared
297libraries.
298
299Jay Fenlason and Roland McGrath ensured that @value{GDBN} and GAS agree
300about several machine instruction sets.
301
302Patrick Duval, Ted Goldstein, Vikram Koka and Glenn Engel helped develop
303remote debugging. Intel Corporation, Wind River Systems, AMD, and ARM
304contributed remote debugging modules for the i960, VxWorks, A29K UDI,
305and RDI targets, respectively.
306
307Brian Fox is the author of the readline libraries providing
308command-line editing and command history.
309
7a292a7a
SS
310Andrew Beers of SUNY Buffalo wrote the language-switching code, the
311Modula-2 support, and contributed the Languages chapter of this manual.
c906108c
SS
312
313Fred Fish wrote most of the support for Unix System Vr4.
c906108c
SS
314He also enhanced the command-completion support to cover C++ overloaded
315symbols.
c906108c
SS
316
317Hitachi America, Ltd. sponsored the support for H8/300, H8/500, and
318Super-H processors.
319
320NEC sponsored the support for the v850, Vr4xxx, and Vr5xxx processors.
321
322Mitsubishi sponsored the support for D10V, D30V, and M32R/D processors.
323
324Toshiba sponsored the support for the TX39 Mips processor.
325
326Matsushita sponsored the support for the MN10200 and MN10300 processors.
327
328Fujitsu sponsored the support for SPARClite and FR30 processors
329
330Kung Hsu, Jeff Law, and Rick Sladkey added support for hardware
331watchpoints.
332
333Michael Snyder added support for tracepoints.
334
335Stu Grossman wrote gdbserver.
336
337Jim Kingdon, Peter Schauer, Ian Taylor, and Stu Grossman made
338nearly innumerable bug fixes and cleanups throughout GDB.
339
340The following people at the Hewlett-Packard Company contributed
341support for the PA-RISC 2.0 architecture, HP-UX 10.20, 10.30, and 11.0
342(narrow mode), HP's implementation of kernel threads, HP's aC++
343compiler, and the terminal user interface: Ben Krepp, Richard Title,
344John Bishop, Susan Macchia, Kathy Mann, Satish Pai, India Paul, Steve
345Rehrauer, and Elena Zannoni. Kim Haase provided HP-specific
346information in this manual.
347
348Cygnus Solutions has sponsored GDB maintenance and much of its
349development since 1991. Cygnus engineers who have worked on GDB
2df3850c
JM
350fulltime include Mark Alexander, Jim Blandy, Per Bothner, Kevin
351Buettner, Edith Epstein, Chris Faylor, Fred Fish, Martin Hunt, Jim
352Ingham, John Gilmore, Stu Grossman, Kung Hsu, Jim Kingdon, John Metzler,
353Fernando Nasser, Geoffrey Noer, Dawn Perchik, Rich Pixley, Zdenek
354Radouch, Keith Seitz, Stan Shebs, David Taylor, and Elena Zannoni. In
355addition, Dave Brolley, Ian Carmichael, Steve Chamberlain, Nick Clifton,
356JT Conklin, Stan Cox, DJ Delorie, Ulrich Drepper, Frank Eigler, Doug
357Evans, Sean Fagan, David Henkel-Wallace, Richard Henderson, Jeff
358Holcomb, Jeff Law, Jim Lemke, Tom Lord, Bob Manson, Michael Meissner,
359Jason Merrill, Catherine Moore, Drew Moseley, Ken Raeburn, Gavin
360Romig-Koch, Rob Savoye, Jamie Smith, Mike Stump, Ian Taylor, Angela
361Thomas, Michael Tiemann, Tom Tromey, Ron Unrau, Jim Wilson, and David
362Zuhn have made contributions both large and small.
c906108c
SS
363
364
53a5351d 365@node Sample Session
c906108c
SS
366@chapter A Sample @value{GDBN} Session
367
368You can use this manual at your leisure to read all about @value{GDBN}.
369However, a handful of commands are enough to get started using the
370debugger. This chapter illustrates those commands.
371
372@iftex
373In this sample session, we emphasize user input like this: @b{input},
374to make it easier to pick out from the surrounding output.
375@end iftex
376
377@c FIXME: this example may not be appropriate for some configs, where
378@c FIXME...primary interest is in remote use.
379
380One of the preliminary versions of @sc{gnu} @code{m4} (a generic macro
381processor) exhibits the following bug: sometimes, when we change its
382quote strings from the default, the commands used to capture one macro
383definition within another stop working. In the following short @code{m4}
384session, we define a macro @code{foo} which expands to @code{0000}; we
385then use the @code{m4} built-in @code{defn} to define @code{bar} as the
386same thing. However, when we change the open quote string to
387@code{<QUOTE>} and the close quote string to @code{<UNQUOTE>}, the same
388procedure fails to define a new synonym @code{baz}:
389
390@smallexample
391$ @b{cd gnu/m4}
392$ @b{./m4}
393@b{define(foo,0000)}
394
395@b{foo}
3960000
397@b{define(bar,defn(`foo'))}
398
399@b{bar}
4000000
401@b{changequote(<QUOTE>,<UNQUOTE>)}
402
403@b{define(baz,defn(<QUOTE>foo<UNQUOTE>))}
404@b{baz}
405@b{C-d}
406m4: End of input: 0: fatal error: EOF in string
407@end smallexample
408
409@noindent
410Let us use @value{GDBN} to try to see what is going on.
411
c906108c
SS
412@smallexample
413$ @b{@value{GDBP} m4}
414@c FIXME: this falsifies the exact text played out, to permit smallbook
415@c FIXME... format to come out better.
416@value{GDBN} is free software and you are welcome to distribute copies
417 of it under certain conditions; type "show copying" to see
418 the conditions.
419There is absolutely no warranty for @value{GDBN}; type "show warranty"
420 for details.
421
422@value{GDBN} @value{GDBVN}, Copyright 1999 Free Software Foundation, Inc...
423(@value{GDBP})
424@end smallexample
c906108c
SS
425
426@noindent
427@value{GDBN} reads only enough symbol data to know where to find the
428rest when needed; as a result, the first prompt comes up very quickly.
429We now tell @value{GDBN} to use a narrower display width than usual, so
430that examples fit in this manual.
431
432@smallexample
433(@value{GDBP}) @b{set width 70}
434@end smallexample
435
436@noindent
437We need to see how the @code{m4} built-in @code{changequote} works.
438Having looked at the source, we know the relevant subroutine is
439@code{m4_changequote}, so we set a breakpoint there with the @value{GDBN}
440@code{break} command.
441
442@smallexample
443(@value{GDBP}) @b{break m4_changequote}
444Breakpoint 1 at 0x62f4: file builtin.c, line 879.
445@end smallexample
446
447@noindent
448Using the @code{run} command, we start @code{m4} running under @value{GDBN}
449control; as long as control does not reach the @code{m4_changequote}
450subroutine, the program runs as usual:
451
452@smallexample
453(@value{GDBP}) @b{run}
454Starting program: /work/Editorial/gdb/gnu/m4/m4
455@b{define(foo,0000)}
456
457@b{foo}
4580000
459@end smallexample
460
461@noindent
462To trigger the breakpoint, we call @code{changequote}. @value{GDBN}
463suspends execution of @code{m4}, displaying information about the
464context where it stops.
465
466@smallexample
467@b{changequote(<QUOTE>,<UNQUOTE>)}
468
469Breakpoint 1, m4_changequote (argc=3, argv=0x33c70)
470 at builtin.c:879
471879 if (bad_argc(TOKEN_DATA_TEXT(argv[0]),argc,1,3))
472@end smallexample
473
474@noindent
475Now we use the command @code{n} (@code{next}) to advance execution to
476the next line of the current function.
477
478@smallexample
479(@value{GDBP}) @b{n}
480882 set_quotes((argc >= 2) ? TOKEN_DATA_TEXT(argv[1])\
481 : nil,
482@end smallexample
483
484@noindent
485@code{set_quotes} looks like a promising subroutine. We can go into it
486by using the command @code{s} (@code{step}) instead of @code{next}.
487@code{step} goes to the next line to be executed in @emph{any}
488subroutine, so it steps into @code{set_quotes}.
489
490@smallexample
491(@value{GDBP}) @b{s}
492set_quotes (lq=0x34c78 "<QUOTE>", rq=0x34c88 "<UNQUOTE>")
493 at input.c:530
494530 if (lquote != def_lquote)
495@end smallexample
496
497@noindent
498The display that shows the subroutine where @code{m4} is now
499suspended (and its arguments) is called a stack frame display. It
500shows a summary of the stack. We can use the @code{backtrace}
501command (which can also be spelled @code{bt}), to see where we are
502in the stack as a whole: the @code{backtrace} command displays a
503stack frame for each active subroutine.
504
505@smallexample
506(@value{GDBP}) @b{bt}
507#0 set_quotes (lq=0x34c78 "<QUOTE>", rq=0x34c88 "<UNQUOTE>")
508 at input.c:530
509#1 0x6344 in m4_changequote (argc=3, argv=0x33c70)
510 at builtin.c:882
511#2 0x8174 in expand_macro (sym=0x33320) at macro.c:242
512#3 0x7a88 in expand_token (obs=0x0, t=209696, td=0xf7fffa30)
513 at macro.c:71
514#4 0x79dc in expand_input () at macro.c:40
515#5 0x2930 in main (argc=0, argv=0xf7fffb20) at m4.c:195
516@end smallexample
517
518@noindent
519We step through a few more lines to see what happens. The first two
520times, we can use @samp{s}; the next two times we use @code{n} to avoid
521falling into the @code{xstrdup} subroutine.
522
523@smallexample
524(@value{GDBP}) @b{s}
5250x3b5c 532 if (rquote != def_rquote)
526(@value{GDBP}) @b{s}
5270x3b80 535 lquote = (lq == nil || *lq == '\0') ? \
528def_lquote : xstrdup(lq);
529(@value{GDBP}) @b{n}
530536 rquote = (rq == nil || *rq == '\0') ? def_rquote\
531 : xstrdup(rq);
532(@value{GDBP}) @b{n}
533538 len_lquote = strlen(rquote);
534@end smallexample
535
536@noindent
537The last line displayed looks a little odd; we can examine the variables
538@code{lquote} and @code{rquote} to see if they are in fact the new left
539and right quotes we specified. We use the command @code{p}
540(@code{print}) to see their values.
541
542@smallexample
543(@value{GDBP}) @b{p lquote}
544$1 = 0x35d40 "<QUOTE>"
545(@value{GDBP}) @b{p rquote}
546$2 = 0x35d50 "<UNQUOTE>"
547@end smallexample
548
549@noindent
550@code{lquote} and @code{rquote} are indeed the new left and right quotes.
551To look at some context, we can display ten lines of source
552surrounding the current line with the @code{l} (@code{list}) command.
553
554@smallexample
555(@value{GDBP}) @b{l}
556533 xfree(rquote);
557534
558535 lquote = (lq == nil || *lq == '\0') ? def_lquote\
559 : xstrdup (lq);
560536 rquote = (rq == nil || *rq == '\0') ? def_rquote\
561 : xstrdup (rq);
562537
563538 len_lquote = strlen(rquote);
564539 len_rquote = strlen(lquote);
565540 @}
566541
567542 void
568@end smallexample
569
570@noindent
571Let us step past the two lines that set @code{len_lquote} and
572@code{len_rquote}, and then examine the values of those variables.
573
574@smallexample
575(@value{GDBP}) @b{n}
576539 len_rquote = strlen(lquote);
577(@value{GDBP}) @b{n}
578540 @}
579(@value{GDBP}) @b{p len_lquote}
580$3 = 9
581(@value{GDBP}) @b{p len_rquote}
582$4 = 7
583@end smallexample
584
585@noindent
586That certainly looks wrong, assuming @code{len_lquote} and
587@code{len_rquote} are meant to be the lengths of @code{lquote} and
588@code{rquote} respectively. We can set them to better values using
589the @code{p} command, since it can print the value of
590any expression---and that expression can include subroutine calls and
591assignments.
592
593@smallexample
594(@value{GDBP}) @b{p len_lquote=strlen(lquote)}
595$5 = 7
596(@value{GDBP}) @b{p len_rquote=strlen(rquote)}
597$6 = 9
598@end smallexample
599
600@noindent
601Is that enough to fix the problem of using the new quotes with the
602@code{m4} built-in @code{defn}? We can allow @code{m4} to continue
603executing with the @code{c} (@code{continue}) command, and then try the
604example that caused trouble initially:
605
606@smallexample
607(@value{GDBP}) @b{c}
608Continuing.
609
610@b{define(baz,defn(<QUOTE>foo<UNQUOTE>))}
611
612baz
6130000
614@end smallexample
615
616@noindent
617Success! The new quotes now work just as well as the default ones. The
618problem seems to have been just the two typos defining the wrong
619lengths. We allow @code{m4} exit by giving it an EOF as input:
620
621@smallexample
622@b{C-d}
623Program exited normally.
624@end smallexample
625
626@noindent
627The message @samp{Program exited normally.} is from @value{GDBN}; it
628indicates @code{m4} has finished executing. We can end our @value{GDBN}
629session with the @value{GDBN} @code{quit} command.
630
631@smallexample
632(@value{GDBP}) @b{quit}
633@end smallexample
c906108c 634
53a5351d 635@node Invocation
c906108c
SS
636@chapter Getting In and Out of @value{GDBN}
637
638This chapter discusses how to start @value{GDBN}, and how to get out of it.
639The essentials are:
640@itemize @bullet
641@item
53a5351d 642type @samp{@value{GDBP}} to start @value{GDBN}.
c906108c
SS
643@item
644type @kbd{quit} or @kbd{C-d} to exit.
645@end itemize
646
647@menu
648* Invoking GDB:: How to start @value{GDBN}
649* Quitting GDB:: How to quit @value{GDBN}
650* Shell Commands:: How to use shell commands inside @value{GDBN}
651@end menu
652
53a5351d 653@node Invoking GDB
c906108c
SS
654@section Invoking @value{GDBN}
655
c906108c
SS
656Invoke @value{GDBN} by running the program @code{@value{GDBP}}. Once started,
657@value{GDBN} reads commands from the terminal until you tell it to exit.
658
659You can also run @code{@value{GDBP}} with a variety of arguments and options,
660to specify more of your debugging environment at the outset.
661
c906108c
SS
662The command-line options described here are designed
663to cover a variety of situations; in some environments, some of these
664options may effectively be unavailable.
c906108c
SS
665
666The most usual way to start @value{GDBN} is with one argument,
667specifying an executable program:
668
669@example
670@value{GDBP} @var{program}
671@end example
672
c906108c
SS
673@noindent
674You can also start with both an executable program and a core file
675specified:
676
677@example
678@value{GDBP} @var{program} @var{core}
679@end example
680
681You can, instead, specify a process ID as a second argument, if you want
682to debug a running process:
683
684@example
685@value{GDBP} @var{program} 1234
686@end example
687
688@noindent
689would attach @value{GDBN} to process @code{1234} (unless you also have a file
690named @file{1234}; @value{GDBN} does check for a core file first).
691
c906108c 692Taking advantage of the second command-line argument requires a fairly
2df3850c
JM
693complete operating system; when you use @value{GDBN} as a remote
694debugger attached to a bare board, there may not be any notion of
695``process'', and there is often no way to get a core dump. @value{GDBN}
696will warn you if it is unable to attach or to read core dumps.
c906108c
SS
697
698You can run @code{gdb} without printing the front material, which describes
699@value{GDBN}'s non-warranty, by specifying @code{-silent}:
700
701@smallexample
702@value{GDBP} -silent
703@end smallexample
704
705@noindent
706You can further control how @value{GDBN} starts up by using command-line
707options. @value{GDBN} itself can remind you of the options available.
708
709@noindent
710Type
711
712@example
713@value{GDBP} -help
714@end example
715
716@noindent
717to display all available options and briefly describe their use
718(@samp{@value{GDBP} -h} is a shorter equivalent).
719
720All options and command line arguments you give are processed
721in sequential order. The order makes a difference when the
722@samp{-x} option is used.
723
724
725@menu
c906108c
SS
726* File Options:: Choosing files
727* Mode Options:: Choosing modes
728@end menu
729
c906108c
SS
730@node File Options
731@subsection Choosing files
732
2df3850c 733When @value{GDBN} starts, it reads any arguments other than options as
c906108c
SS
734specifying an executable file and core file (or process ID). This is
735the same as if the arguments were specified by the @samp{-se} and
736@samp{-c} options respectively. (@value{GDBN} reads the first argument
737that does not have an associated option flag as equivalent to the
738@samp{-se} option followed by that argument; and the second argument
739that does not have an associated option flag, if any, as equivalent to
740the @samp{-c} option followed by that argument.)
7a292a7a
SS
741
742If @value{GDBN} has not been configured to included core file support,
743such as for most embedded targets, then it will complain about a second
744argument and ignore it.
c906108c
SS
745
746Many options have both long and short forms; both are shown in the
747following list. @value{GDBN} also recognizes the long forms if you truncate
748them, so long as enough of the option is present to be unambiguous.
749(If you prefer, you can flag option arguments with @samp{--} rather
750than @samp{-}, though we illustrate the more usual convention.)
751
752@table @code
753@item -symbols @var{file}
754@itemx -s @var{file}
755Read symbol table from file @var{file}.
756
757@item -exec @var{file}
758@itemx -e @var{file}
7a292a7a
SS
759Use file @var{file} as the executable file to execute when appropriate,
760and for examining pure data in conjunction with a core dump.
c906108c
SS
761
762@item -se @var{file}
763Read symbol table from file @var{file} and use it as the executable
764file.
765
c906108c
SS
766@item -core @var{file}
767@itemx -c @var{file}
768Use file @var{file} as a core dump to examine.
769
770@item -c @var{number}
771Connect to process ID @var{number}, as with the @code{attach} command
772(unless there is a file in core-dump format named @var{number}, in which
773case @samp{-c} specifies that file as a core dump to read).
c906108c
SS
774
775@item -command @var{file}
776@itemx -x @var{file}
777Execute @value{GDBN} commands from file @var{file}. @xref{Command
778Files,, Command files}.
779
780@item -directory @var{directory}
781@itemx -d @var{directory}
782Add @var{directory} to the path to search for source files.
783
c906108c
SS
784@item -m
785@itemx -mapped
786@emph{Warning: this option depends on operating system facilities that are not
787supported on all systems.}@*
788If memory-mapped files are available on your system through the @code{mmap}
789system call, you can use this option
790to have @value{GDBN} write the symbols from your
791program into a reusable file in the current directory. If the program you are debugging is
792called @file{/tmp/fred}, the mapped symbol file is @file{./fred.syms}.
793Future @value{GDBN} debugging sessions notice the presence of this file,
794and can quickly map in symbol information from it, rather than reading
795the symbol table from the executable program.
796
797The @file{.syms} file is specific to the host machine where @value{GDBN}
798is run. It holds an exact image of the internal @value{GDBN} symbol
799table. It cannot be shared across multiple host platforms.
c906108c 800
c906108c
SS
801@item -r
802@itemx -readnow
803Read each symbol file's entire symbol table immediately, rather than
804the default, which is to read it incrementally as it is needed.
805This makes startup slower, but makes future operations faster.
53a5351d 806
c906108c
SS
807@end table
808
2df3850c 809You typically combine the @code{-mapped} and @code{-readnow} options in
c906108c 810order to build a @file{.syms} file that contains complete symbol
2df3850c
JM
811information. (@xref{Files,,Commands to specify files}, for information
812on @file{.syms} files.) A simple @value{GDBN} invocation to do nothing
813but build a @file{.syms} file for future use is:
c906108c
SS
814
815@example
2df3850c 816gdb -batch -nx -mapped -readnow programname
c906108c 817@end example
c906108c 818
53a5351d 819@node Mode Options
c906108c
SS
820@subsection Choosing modes
821
822You can run @value{GDBN} in various alternative modes---for example, in
823batch mode or quiet mode.
824
825@table @code
826@item -nx
827@itemx -n
2df3850c
JM
828Do not execute commands found in any initialization files (normally
829called @file{.gdbinit}, or @file{gdb.ini} on PCs). Normally,
830@value{GDBN} executes the commands in these files after all the command
831options and arguments have been processed. @xref{Command Files,,Command
832files}.
c906108c
SS
833
834@item -quiet
835@itemx -q
836``Quiet''. Do not print the introductory and copyright messages. These
837messages are also suppressed in batch mode.
838
839@item -batch
840Run in batch mode. Exit with status @code{0} after processing all the
841command files specified with @samp{-x} (and all commands from
842initialization files, if not inhibited with @samp{-n}). Exit with
843nonzero status if an error occurs in executing the @value{GDBN} commands
844in the command files.
845
2df3850c
JM
846Batch mode may be useful for running @value{GDBN} as a filter, for
847example to download and run a program on another computer; in order to
848make this more useful, the message
c906108c
SS
849
850@example
851Program exited normally.
852@end example
853
854@noindent
2df3850c
JM
855(which is ordinarily issued whenever a program running under
856@value{GDBN} control terminates) is not issued when running in batch
857mode.
858
859@item -nowindows
860@itemx -nw
861``No windows''. If @value{GDBN} comes with a graphical user interface
862(GUI) built in, then this option tells GDB to only use the command-line
863interface. If no GUI is available, this option has no effect.
864
865@item -windows
866@itemx -w
867If @value{GDBN} includes a GUI, then this option requires it to be
868used if possible.
c906108c
SS
869
870@item -cd @var{directory}
871Run @value{GDBN} using @var{directory} as its working directory,
872instead of the current directory.
873
c906108c
SS
874@item -fullname
875@itemx -f
7a292a7a
SS
876@sc{gnu} Emacs sets this option when it runs @value{GDBN} as a
877subprocess. It tells @value{GDBN} to output the full file name and line
878number in a standard, recognizable fashion each time a stack frame is
879displayed (which includes each time your program stops). This
880recognizable format looks like two @samp{\032} characters, followed by
881the file name, line number and character position separated by colons,
882and a newline. The Emacs-to-@value{GDBN} interface program uses the two
883@samp{\032} characters as a signal to display the source code for the
884frame.
c906108c 885
2df3850c
JM
886@item -baud @var{bps}
887@itemx -b @var{bps}
c906108c
SS
888Set the line speed (baud rate or bits per second) of any serial
889interface used by @value{GDBN} for remote debugging.
c906108c
SS
890
891@item -tty @var{device}
892Run using @var{device} for your program's standard input and output.
893@c FIXME: kingdon thinks there is more to -tty. Investigate.
c906108c 894
53a5351d
JM
895@c resolve the situation of these eventually
896@c @item -tui
897@c Use a Terminal User Interface. For information, use your Web browser to
898@c read the file @file{TUI.html}, which is usually installed in the
899@c directory @code{/opt/langtools/wdb/doc} on HP-UX systems. Do not use
900@c this option if you run @value{GDBN} from Emacs (see @pxref{Emacs, ,Using
901@c @value{GDBN} under @sc{gnu} Emacs}).
902
903@c @item -xdb
904@c Run in XDB compatibility mode, allowing the use of certain XDB commands.
905@c For information, see the file @file{xdb_trans.html}, which is usually
906@c installed in the directory @code{/opt/langtools/wdb/doc} on HP-UX
907@c systems.
908
c906108c
SS
909@end table
910
53a5351d 911@node Quitting GDB
c906108c
SS
912@section Quitting @value{GDBN}
913@cindex exiting @value{GDBN}
914@cindex leaving @value{GDBN}
915
916@table @code
917@kindex quit @r{[}@var{expression}@r{]}
918@kindex q
919@item quit
920To exit @value{GDBN}, use the @code{quit} command (abbreviated @code{q}), or
921type an end-of-file character (usually @kbd{C-d}). If you do not supply
922@var{expression}, @value{GDBN} will terminate normally; otherwise it will
923terminate using the result of @var{expression} as the error code.
924@end table
925
926@cindex interrupt
927An interrupt (often @kbd{C-c}) does not exit from @value{GDBN}, but rather
928terminates the action of any @value{GDBN} command that is in progress and
929returns to @value{GDBN} command level. It is safe to type the interrupt
930character at any time because @value{GDBN} does not allow it to take effect
931until a time when it is safe.
932
c906108c
SS
933If you have been using @value{GDBN} to control an attached process or
934device, you can release it with the @code{detach} command
935(@pxref{Attach, ,Debugging an already-running process}).
c906108c 936
53a5351d 937@node Shell Commands
c906108c
SS
938@section Shell commands
939
940If you need to execute occasional shell commands during your
941debugging session, there is no need to leave or suspend @value{GDBN}; you can
942just use the @code{shell} command.
943
944@table @code
945@kindex shell
946@cindex shell escape
947@item shell @var{command string}
948Invoke a standard shell to execute @var{command string}.
c906108c 949If it exists, the environment variable @code{SHELL} determines which
d4f3574e
SS
950shell to run. Otherwise @value{GDBN} uses the default shell
951(@file{/bin/sh} on Unix systems, @file{COMMAND.COM} on MS-DOS, etc.).
c906108c
SS
952@end table
953
954The utility @code{make} is often needed in development environments.
955You do not have to use the @code{shell} command for this purpose in
956@value{GDBN}:
957
958@table @code
959@kindex make
960@cindex calling make
961@item make @var{make-args}
962Execute the @code{make} program with the specified
963arguments. This is equivalent to @samp{shell make @var{make-args}}.
964@end table
965
53a5351d 966@node Commands
c906108c
SS
967@chapter @value{GDBN} Commands
968
969You can abbreviate a @value{GDBN} command to the first few letters of the command
970name, if that abbreviation is unambiguous; and you can repeat certain
971@value{GDBN} commands by typing just @key{RET}. You can also use the @key{TAB}
972key to get @value{GDBN} to fill out the rest of a word in a command (or to
973show you the alternatives available, if there is more than one possibility).
974
975@menu
976* Command Syntax:: How to give commands to @value{GDBN}
977* Completion:: Command completion
978* Help:: How to ask @value{GDBN} for help
979@end menu
980
53a5351d 981@node Command Syntax
c906108c
SS
982@section Command syntax
983
984A @value{GDBN} command is a single line of input. There is no limit on
985how long it can be. It starts with a command name, which is followed by
986arguments whose meaning depends on the command name. For example, the
987command @code{step} accepts an argument which is the number of times to
988step, as in @samp{step 5}. You can also use the @code{step} command
989with no arguments. Some command names do not allow any arguments.
990
991@cindex abbreviation
992@value{GDBN} command names may always be truncated if that abbreviation is
993unambiguous. Other possible command abbreviations are listed in the
994documentation for individual commands. In some cases, even ambiguous
995abbreviations are allowed; for example, @code{s} is specially defined as
996equivalent to @code{step} even though there are other commands whose
997names start with @code{s}. You can test abbreviations by using them as
998arguments to the @code{help} command.
999
1000@cindex repeating commands
1001@kindex RET
1002A blank line as input to @value{GDBN} (typing just @key{RET}) means to
1003repeat the previous command. Certain commands (for example, @code{run})
1004will not repeat this way; these are commands whose unintentional
1005repetition might cause trouble and which you are unlikely to want to
1006repeat.
1007
1008The @code{list} and @code{x} commands, when you repeat them with
1009@key{RET}, construct new arguments rather than repeating
1010exactly as typed. This permits easy scanning of source or memory.
1011
1012@value{GDBN} can also use @key{RET} in another way: to partition lengthy
1013output, in a way similar to the common utility @code{more}
1014(@pxref{Screen Size,,Screen size}). Since it is easy to press one
1015@key{RET} too many in this situation, @value{GDBN} disables command
1016repetition after any command that generates this sort of display.
1017
1018@kindex #
1019@cindex comment
1020Any text from a @kbd{#} to the end of the line is a comment; it does
1021nothing. This is useful mainly in command files (@pxref{Command
1022Files,,Command files}).
1023
53a5351d 1024@node Completion
c906108c
SS
1025@section Command completion
1026
1027@cindex completion
1028@cindex word completion
1029@value{GDBN} can fill in the rest of a word in a command for you, if there is
1030only one possibility; it can also show you what the valid possibilities
1031are for the next word in a command, at any time. This works for @value{GDBN}
1032commands, @value{GDBN} subcommands, and the names of symbols in your program.
1033
1034Press the @key{TAB} key whenever you want @value{GDBN} to fill out the rest
1035of a word. If there is only one possibility, @value{GDBN} fills in the
1036word, and waits for you to finish the command (or press @key{RET} to
1037enter it). For example, if you type
1038
1039@c FIXME "@key" does not distinguish its argument sufficiently to permit
1040@c complete accuracy in these examples; space introduced for clarity.
1041@c If texinfo enhancements make it unnecessary, it would be nice to
1042@c replace " @key" by "@key" in the following...
1043@example
1044(@value{GDBP}) info bre @key{TAB}
1045@end example
1046
1047@noindent
1048@value{GDBN} fills in the rest of the word @samp{breakpoints}, since that is
1049the only @code{info} subcommand beginning with @samp{bre}:
1050
1051@example
1052(@value{GDBP}) info breakpoints
1053@end example
1054
1055@noindent
1056You can either press @key{RET} at this point, to run the @code{info
1057breakpoints} command, or backspace and enter something else, if
1058@samp{breakpoints} does not look like the command you expected. (If you
1059were sure you wanted @code{info breakpoints} in the first place, you
1060might as well just type @key{RET} immediately after @samp{info bre},
1061to exploit command abbreviations rather than command completion).
1062
1063If there is more than one possibility for the next word when you press
1064@key{TAB}, @value{GDBN} sounds a bell. You can either supply more
1065characters and try again, or just press @key{TAB} a second time;
1066@value{GDBN} displays all the possible completions for that word. For
1067example, you might want to set a breakpoint on a subroutine whose name
1068begins with @samp{make_}, but when you type @kbd{b make_@key{TAB}} @value{GDBN}
1069just sounds the bell. Typing @key{TAB} again displays all the
1070function names in your program that begin with those characters, for
1071example:
1072
1073@example
1074(@value{GDBP}) b make_ @key{TAB}
1075@exdent @value{GDBN} sounds bell; press @key{TAB} again, to see:
1076make_a_section_from_file make_environ
1077make_abs_section make_function_type
1078make_blockvector make_pointer_type
1079make_cleanup make_reference_type
1080make_command make_symbol_completion_list
1081(@value{GDBP}) b make_
1082@end example
1083
1084@noindent
1085After displaying the available possibilities, @value{GDBN} copies your
1086partial input (@samp{b make_} in the example) so you can finish the
1087command.
1088
1089If you just want to see the list of alternatives in the first place, you
1090can press @kbd{M-?} rather than pressing @key{TAB} twice. @kbd{M-?}
7a292a7a 1091means @kbd{@key{META} ?}. You can type this either by holding down a
c906108c 1092key designated as the @key{META} shift on your keyboard (if there is
7a292a7a 1093one) while typing @kbd{?}, or as @key{ESC} followed by @kbd{?}.
c906108c
SS
1094
1095@cindex quotes in commands
1096@cindex completion of quoted strings
1097Sometimes the string you need, while logically a ``word'', may contain
7a292a7a
SS
1098parentheses or other characters that @value{GDBN} normally excludes from
1099its notion of a word. To permit word completion to work in this
1100situation, you may enclose words in @code{'} (single quote marks) in
1101@value{GDBN} commands.
c906108c 1102
c906108c
SS
1103The most likely situation where you might need this is in typing the
1104name of a C++ function. This is because C++ allows function overloading
1105(multiple definitions of the same function, distinguished by argument
1106type). For example, when you want to set a breakpoint you may need to
1107distinguish whether you mean the version of @code{name} that takes an
1108@code{int} parameter, @code{name(int)}, or the version that takes a
1109@code{float} parameter, @code{name(float)}. To use the word-completion
1110facilities in this situation, type a single quote @code{'} at the
1111beginning of the function name. This alerts @value{GDBN} that it may need to
1112consider more information than usual when you press @key{TAB} or
1113@kbd{M-?} to request word completion:
1114
1115@example
1116(@value{GDBP}) b 'bubble( @key{M-?}
1117bubble(double,double) bubble(int,int)
1118(@value{GDBP}) b 'bubble(
1119@end example
1120
1121In some cases, @value{GDBN} can tell that completing a name requires using
1122quotes. When this happens, @value{GDBN} inserts the quote for you (while
1123completing as much as it can) if you do not type the quote in the first
1124place:
1125
1126@example
1127(@value{GDBP}) b bub @key{TAB}
1128@exdent @value{GDBN} alters your input line to the following, and rings a bell:
1129(@value{GDBP}) b 'bubble(
1130@end example
1131
1132@noindent
1133In general, @value{GDBN} can tell that a quote is needed (and inserts it) if
1134you have not yet started typing the argument list when you ask for
1135completion on an overloaded symbol.
1136
d4f3574e 1137For more information about overloaded functions, see @ref{C plus plus
c906108c
SS
1138expressions, ,C++ expressions}. You can use the command @code{set
1139overload-resolution off} to disable overload resolution;
d4f3574e 1140see @ref{Debugging C plus plus, ,@value{GDBN} features for C++}.
c906108c
SS
1141
1142
53a5351d 1143@node Help
c906108c
SS
1144@section Getting help
1145@cindex online documentation
1146@kindex help
1147
1148You can always ask @value{GDBN} itself for information on its commands,
1149using the command @code{help}.
1150
1151@table @code
1152@kindex h
1153@item help
1154@itemx h
1155You can use @code{help} (abbreviated @code{h}) with no arguments to
1156display a short list of named classes of commands:
1157
1158@smallexample
1159(@value{GDBP}) help
1160List of classes of commands:
1161
2df3850c 1162aliases -- Aliases of other commands
c906108c 1163breakpoints -- Making program stop at certain points
2df3850c 1164data -- Examining data
c906108c 1165files -- Specifying and examining files
2df3850c
JM
1166internals -- Maintenance commands
1167obscure -- Obscure features
1168running -- Running the program
1169stack -- Examining the stack
c906108c
SS
1170status -- Status inquiries
1171support -- Support facilities
2df3850c 1172tracepoints -- Tracing of program execution without stopping the program
c906108c 1173user-defined -- User-defined commands
c906108c
SS
1174
1175Type "help" followed by a class name for a list of
1176commands in that class.
1177Type "help" followed by command name for full
1178documentation.
1179Command name abbreviations are allowed if unambiguous.
1180(@value{GDBP})
1181@end smallexample
1182
1183@item help @var{class}
1184Using one of the general help classes as an argument, you can get a
1185list of the individual commands in that class. For example, here is the
1186help display for the class @code{status}:
1187
1188@smallexample
1189(@value{GDBP}) help status
1190Status inquiries.
1191
1192List of commands:
1193
1194@c Line break in "show" line falsifies real output, but needed
1195@c to fit in smallbook page size.
2df3850c
JM
1196info -- Generic command for showing things
1197 about the program being debugged
1198show -- Generic command for showing things
1199 about the debugger
c906108c
SS
1200
1201Type "help" followed by command name for full
1202documentation.
1203Command name abbreviations are allowed if unambiguous.
1204(@value{GDBP})
1205@end smallexample
1206
1207@item help @var{command}
1208With a command name as @code{help} argument, @value{GDBN} displays a
1209short paragraph on how to use that command.
1210
1211@kindex complete
1212@item complete @var{args}
1213The @code{complete @var{args}} command lists all the possible completions
1214for the beginning of a command. Use @var{args} to specify the beginning of the
1215command you want completed. For example:
1216
1217@smallexample
1218complete i
1219@end smallexample
1220
1221@noindent results in:
1222
1223@smallexample
1224@group
2df3850c
JM
1225if
1226ignore
c906108c
SS
1227info
1228inspect
c906108c
SS
1229@end group
1230@end smallexample
1231
1232@noindent This is intended for use by @sc{gnu} Emacs.
1233@end table
1234
1235In addition to @code{help}, you can use the @value{GDBN} commands @code{info}
1236and @code{show} to inquire about the state of your program, or the state
1237of @value{GDBN} itself. Each command supports many topics of inquiry; this
1238manual introduces each of them in the appropriate context. The listings
1239under @code{info} and under @code{show} in the Index point to
1240all the sub-commands. @xref{Index}.
1241
1242@c @group
1243@table @code
1244@kindex info
1245@kindex i
1246@item info
1247This command (abbreviated @code{i}) is for describing the state of your
1248program. For example, you can list the arguments given to your program
1249with @code{info args}, list the registers currently in use with @code{info
1250registers}, or list the breakpoints you have set with @code{info breakpoints}.
1251You can get a complete list of the @code{info} sub-commands with
1252@w{@code{help info}}.
1253
1254@kindex set
1255@item set
1256You can assign the result of an expression to an environment variable with
1257@code{set}. For example, you can set the @value{GDBN} prompt to a $-sign with
1258@code{set prompt $}.
1259
1260@kindex show
1261@item show
1262In contrast to @code{info}, @code{show} is for describing the state of
1263@value{GDBN} itself.
1264You can change most of the things you can @code{show}, by using the
1265related command @code{set}; for example, you can control what number
1266system is used for displays with @code{set radix}, or simply inquire
1267which is currently in use with @code{show radix}.
1268
1269@kindex info set
1270To display all the settable parameters and their current
1271values, you can use @code{show} with no arguments; you may also use
1272@code{info set}. Both commands produce the same display.
1273@c FIXME: "info set" violates the rule that "info" is for state of
1274@c FIXME...program. Ck w/ GNU: "info set" to be called something else,
1275@c FIXME...or change desc of rule---eg "state of prog and debugging session"?
1276@end table
1277@c @end group
1278
1279Here are three miscellaneous @code{show} subcommands, all of which are
1280exceptional in lacking corresponding @code{set} commands:
1281
1282@table @code
1283@kindex show version
1284@cindex version number
1285@item show version
1286Show what version of @value{GDBN} is running. You should include this
2df3850c
JM
1287information in @value{GDBN} bug-reports. If multiple versions of
1288@value{GDBN} are in use at your site, you may need to determine which
1289version of @value{GDBN} you are running; as @value{GDBN} evolves, new
1290commands are introduced, and old ones may wither away. Also, many
1291system vendors ship variant versions of @value{GDBN}, and there are
1292variant versions of @value{GDBN} in GNU/Linux distributions as well.
1293The version number is the same as the one announced when you start
1294@value{GDBN}.
c906108c
SS
1295
1296@kindex show copying
1297@item show copying
1298Display information about permission for copying @value{GDBN}.
1299
1300@kindex show warranty
1301@item show warranty
2df3850c
JM
1302Display the @sc{gnu} ``NO WARRANTY'' statement, or a warranty,
1303if your version of @value{GDB} comes with one.
1304
c906108c
SS
1305@end table
1306
53a5351d 1307@node Running
c906108c
SS
1308@chapter Running Programs Under @value{GDBN}
1309
1310When you run a program under @value{GDBN}, you must first generate
1311debugging information when you compile it.
7a292a7a
SS
1312
1313You may start @value{GDBN} with its arguments, if any, in an environment
1314of your choice. If you are doing native debugging, you may redirect
1315your program's input and output, debug an already running process, or
1316kill a child process.
c906108c
SS
1317
1318@menu
1319* Compilation:: Compiling for debugging
1320* Starting:: Starting your program
c906108c
SS
1321* Arguments:: Your program's arguments
1322* Environment:: Your program's environment
c906108c
SS
1323
1324* Working Directory:: Your program's working directory
1325* Input/Output:: Your program's input and output
1326* Attach:: Debugging an already-running process
1327* Kill Process:: Killing the child process
c906108c
SS
1328
1329* Threads:: Debugging programs with multiple threads
1330* Processes:: Debugging programs with multiple processes
1331@end menu
1332
53a5351d 1333@node Compilation
c906108c
SS
1334@section Compiling for debugging
1335
1336In order to debug a program effectively, you need to generate
1337debugging information when you compile it. This debugging information
1338is stored in the object file; it describes the data type of each
1339variable or function and the correspondence between source line numbers
1340and addresses in the executable code.
1341
1342To request debugging information, specify the @samp{-g} option when you run
1343the compiler.
1344
1345Many C compilers are unable to handle the @samp{-g} and @samp{-O}
1346options together. Using those compilers, you cannot generate optimized
1347executables containing debugging information.
1348
53a5351d
JM
1349@value{NGCC}, the @sc{gnu} C compiler, supports @samp{-g} with or
1350without @samp{-O}, making it possible to debug optimized code. We
1351recommend that you @emph{always} use @samp{-g} whenever you compile a
1352program. You may think your program is correct, but there is no sense
1353in pushing your luck.
c906108c
SS
1354
1355@cindex optimized code, debugging
1356@cindex debugging optimized code
1357When you debug a program compiled with @samp{-g -O}, remember that the
1358optimizer is rearranging your code; the debugger shows you what is
1359really there. Do not be too surprised when the execution path does not
1360exactly match your source file! An extreme example: if you define a
1361variable, but never use it, @value{GDBN} never sees that
1362variable---because the compiler optimizes it out of existence.
1363
1364Some things do not work as well with @samp{-g -O} as with just
1365@samp{-g}, particularly on machines with instruction scheduling. If in
1366doubt, recompile with @samp{-g} alone, and if this fixes the problem,
1367please report it to us as a bug (including a test case!).
1368
1369Older versions of the @sc{gnu} C compiler permitted a variant option
1370@w{@samp{-gg}} for debugging information. @value{GDBN} no longer supports this
1371format; if your @sc{gnu} C compiler has this option, do not use it.
1372
1373@need 2000
53a5351d 1374@node Starting
c906108c
SS
1375@section Starting your program
1376@cindex starting
1377@cindex running
1378
1379@table @code
1380@kindex run
1381@item run
1382@itemx r
7a292a7a
SS
1383Use the @code{run} command to start your program under @value{GDBN}.
1384You must first specify the program name (except on VxWorks) with an
1385argument to @value{GDBN} (@pxref{Invocation, ,Getting In and Out of
1386@value{GDBN}}), or by using the @code{file} or @code{exec-file} command
1387(@pxref{Files, ,Commands to specify files}).
c906108c
SS
1388
1389@end table
1390
c906108c
SS
1391If you are running your program in an execution environment that
1392supports processes, @code{run} creates an inferior process and makes
1393that process run your program. (In environments without processes,
1394@code{run} jumps to the start of your program.)
1395
1396The execution of a program is affected by certain information it
1397receives from its superior. @value{GDBN} provides ways to specify this
1398information, which you must do @emph{before} starting your program. (You
1399can change it after starting your program, but such changes only affect
1400your program the next time you start it.) This information may be
1401divided into four categories:
1402
1403@table @asis
1404@item The @emph{arguments.}
1405Specify the arguments to give your program as the arguments of the
1406@code{run} command. If a shell is available on your target, the shell
1407is used to pass the arguments, so that you may use normal conventions
1408(such as wildcard expansion or variable substitution) in describing
1409the arguments.
1410In Unix systems, you can control which shell is used with the
1411@code{SHELL} environment variable.
1412@xref{Arguments, ,Your program's arguments}.
1413
1414@item The @emph{environment.}
1415Your program normally inherits its environment from @value{GDBN}, but you can
1416use the @value{GDBN} commands @code{set environment} and @code{unset
1417environment} to change parts of the environment that affect
1418your program. @xref{Environment, ,Your program's environment}.
1419
1420@item The @emph{working directory.}
1421Your program inherits its working directory from @value{GDBN}. You can set
1422the @value{GDBN} working directory with the @code{cd} command in @value{GDBN}.
1423@xref{Working Directory, ,Your program's working directory}.
1424
1425@item The @emph{standard input and output.}
1426Your program normally uses the same device for standard input and
1427standard output as @value{GDBN} is using. You can redirect input and output
1428in the @code{run} command line, or you can use the @code{tty} command to
1429set a different device for your program.
1430@xref{Input/Output, ,Your program's input and output}.
1431
1432@cindex pipes
1433@emph{Warning:} While input and output redirection work, you cannot use
1434pipes to pass the output of the program you are debugging to another
1435program; if you attempt this, @value{GDBN} is likely to wind up debugging the
1436wrong program.
1437@end table
c906108c
SS
1438
1439When you issue the @code{run} command, your program begins to execute
1440immediately. @xref{Stopping, ,Stopping and continuing}, for discussion
1441of how to arrange for your program to stop. Once your program has
1442stopped, you may call functions in your program, using the @code{print}
1443or @code{call} commands. @xref{Data, ,Examining Data}.
1444
1445If the modification time of your symbol file has changed since the last
1446time @value{GDBN} read its symbols, @value{GDBN} discards its symbol
1447table, and reads it again. When it does this, @value{GDBN} tries to retain
1448your current breakpoints.
1449
53a5351d 1450@node Arguments
c906108c
SS
1451@section Your program's arguments
1452
1453@cindex arguments (to your program)
1454The arguments to your program can be specified by the arguments of the
1455@code{run} command.
1456They are passed to a shell, which expands wildcard characters and
1457performs redirection of I/O, and thence to your program. Your
1458@code{SHELL} environment variable (if it exists) specifies what shell
1459@value{GDBN} uses. If you do not define @code{SHELL}, @value{GDBN} uses
d4f3574e
SS
1460the default shell (@file{/bin/sh} on Unix).
1461
1462On non-Unix systems, the program is usually invoked directly by
1463@value{GDBN}, which emulates I/O redirection via the appropriate system
1464calls, and the wildcard characters are expanded by the startup code of
1465the program, not by the shell.
c906108c
SS
1466
1467@code{run} with no arguments uses the same arguments used by the previous
1468@code{run}, or those set by the @code{set args} command.
1469
1470@kindex set args
1471@table @code
1472@item set args
1473Specify the arguments to be used the next time your program is run. If
1474@code{set args} has no arguments, @code{run} executes your program
1475with no arguments. Once you have run your program with arguments,
1476using @code{set args} before the next @code{run} is the only way to run
1477it again without arguments.
1478
1479@kindex show args
1480@item show args
1481Show the arguments to give your program when it is started.
1482@end table
1483
53a5351d 1484@node Environment
c906108c
SS
1485@section Your program's environment
1486
1487@cindex environment (of your program)
1488The @dfn{environment} consists of a set of environment variables and
1489their values. Environment variables conventionally record such things as
1490your user name, your home directory, your terminal type, and your search
1491path for programs to run. Usually you set up environment variables with
1492the shell and they are inherited by all the other programs you run. When
1493debugging, it can be useful to try running your program with a modified
1494environment without having to start @value{GDBN} over again.
1495
1496@table @code
1497@kindex path
1498@item path @var{directory}
1499Add @var{directory} to the front of the @code{PATH} environment variable
1500(the search path for executables), for both @value{GDBN} and your program.
d4f3574e
SS
1501You may specify several directory names, separated by whitespace or by a
1502system-dependent separator character (@samp{:} on Unix, @samp{;} on
1503MS-DOS and MS-Windows). If @var{directory} is already in the path, it
1504is moved to the front, so it is searched sooner.
c906108c
SS
1505
1506You can use the string @samp{$cwd} to refer to whatever is the current
1507working directory at the time @value{GDBN} searches the path. If you
1508use @samp{.} instead, it refers to the directory where you executed the
1509@code{path} command. @value{GDBN} replaces @samp{.} in the
1510@var{directory} argument (with the current path) before adding
1511@var{directory} to the search path.
1512@c 'path' is explicitly nonrepeatable, but RMS points out it is silly to
1513@c document that, since repeating it would be a no-op.
1514
1515@kindex show paths
1516@item show paths
1517Display the list of search paths for executables (the @code{PATH}
1518environment variable).
1519
1520@kindex show environment
1521@item show environment @r{[}@var{varname}@r{]}
1522Print the value of environment variable @var{varname} to be given to
1523your program when it starts. If you do not supply @var{varname},
1524print the names and values of all environment variables to be given to
1525your program. You can abbreviate @code{environment} as @code{env}.
1526
1527@kindex set environment
53a5351d 1528@item set environment @var{varname} @r{[}=@var{value}@r{]}
c906108c
SS
1529Set environment variable @var{varname} to @var{value}. The value
1530changes for your program only, not for @value{GDBN} itself. @var{value} may
1531be any string; the values of environment variables are just strings, and
1532any interpretation is supplied by your program itself. The @var{value}
1533parameter is optional; if it is eliminated, the variable is set to a
1534null value.
1535@c "any string" here does not include leading, trailing
1536@c blanks. Gnu asks: does anyone care?
1537
1538For example, this command:
1539
1540@example
1541set env USER = foo
1542@end example
1543
1544@noindent
d4f3574e 1545tells the debugged program, when subsequently run, that its user is named
c906108c
SS
1546@samp{foo}. (The spaces around @samp{=} are used for clarity here; they
1547are not actually required.)
1548
1549@kindex unset environment
1550@item unset environment @var{varname}
1551Remove variable @var{varname} from the environment to be passed to your
1552program. This is different from @samp{set env @var{varname} =};
1553@code{unset environment} removes the variable from the environment,
1554rather than assigning it an empty value.
1555@end table
1556
d4f3574e
SS
1557@emph{Warning:} On Unix systems, @value{GDBN} runs your program using
1558the shell indicated
c906108c
SS
1559by your @code{SHELL} environment variable if it exists (or
1560@code{/bin/sh} if not). If your @code{SHELL} variable names a shell
1561that runs an initialization file---such as @file{.cshrc} for C-shell, or
1562@file{.bashrc} for BASH---any variables you set in that file affect
1563your program. You may wish to move setting of environment variables to
1564files that are only run when you sign on, such as @file{.login} or
1565@file{.profile}.
1566
53a5351d 1567@node Working Directory
c906108c
SS
1568@section Your program's working directory
1569
1570@cindex working directory (of your program)
1571Each time you start your program with @code{run}, it inherits its
1572working directory from the current working directory of @value{GDBN}.
1573The @value{GDBN} working directory is initially whatever it inherited
1574from its parent process (typically the shell), but you can specify a new
1575working directory in @value{GDBN} with the @code{cd} command.
1576
1577The @value{GDBN} working directory also serves as a default for the commands
1578that specify files for @value{GDBN} to operate on. @xref{Files, ,Commands to
1579specify files}.
1580
1581@table @code
1582@kindex cd
1583@item cd @var{directory}
1584Set the @value{GDBN} working directory to @var{directory}.
1585
1586@kindex pwd
1587@item pwd
1588Print the @value{GDBN} working directory.
1589@end table
1590
53a5351d 1591@node Input/Output
c906108c
SS
1592@section Your program's input and output
1593
1594@cindex redirection
1595@cindex i/o
1596@cindex terminal
1597By default, the program you run under @value{GDBN} does input and output to
1598the same terminal that @value{GDBN} uses. @value{GDBN} switches the terminal
1599to its own terminal modes to interact with you, but it records the terminal
1600modes your program was using and switches back to them when you continue
1601running your program.
1602
1603@table @code
1604@kindex info terminal
1605@item info terminal
1606Displays information recorded by @value{GDBN} about the terminal modes your
1607program is using.
1608@end table
1609
1610You can redirect your program's input and/or output using shell
1611redirection with the @code{run} command. For example,
1612
1613@example
1614run > outfile
1615@end example
1616
1617@noindent
1618starts your program, diverting its output to the file @file{outfile}.
1619
1620@kindex tty
1621@cindex controlling terminal
1622Another way to specify where your program should do input and output is
1623with the @code{tty} command. This command accepts a file name as
1624argument, and causes this file to be the default for future @code{run}
1625commands. It also resets the controlling terminal for the child
1626process, for future @code{run} commands. For example,
1627
1628@example
1629tty /dev/ttyb
1630@end example
1631
1632@noindent
1633directs that processes started with subsequent @code{run} commands
1634default to do input and output on the terminal @file{/dev/ttyb} and have
1635that as their controlling terminal.
1636
1637An explicit redirection in @code{run} overrides the @code{tty} command's
1638effect on the input/output device, but not its effect on the controlling
1639terminal.
1640
1641When you use the @code{tty} command or redirect input in the @code{run}
1642command, only the input @emph{for your program} is affected. The input
1643for @value{GDBN} still comes from your terminal.
1644
53a5351d 1645@node Attach
c906108c
SS
1646@section Debugging an already-running process
1647@kindex attach
1648@cindex attach
1649
1650@table @code
1651@item attach @var{process-id}
1652This command attaches to a running process---one that was started
1653outside @value{GDBN}. (@code{info files} shows your active
1654targets.) The command takes as argument a process ID. The usual way to
1655find out the process-id of a Unix process is with the @code{ps} utility,
1656or with the @samp{jobs -l} shell command.
1657
1658@code{attach} does not repeat if you press @key{RET} a second time after
1659executing the command.
1660@end table
1661
1662To use @code{attach}, your program must be running in an environment
1663which supports processes; for example, @code{attach} does not work for
1664programs on bare-board targets that lack an operating system. You must
1665also have permission to send the process a signal.
1666
1667When you use @code{attach}, the debugger finds the program running in
1668the process first by looking in the current working directory, then (if
1669the program is not found) by using the source file search path
1670(@pxref{Source Path, ,Specifying source directories}). You can also use
1671the @code{file} command to load the program. @xref{Files, ,Commands to
1672Specify Files}.
1673
1674The first thing @value{GDBN} does after arranging to debug the specified
1675process is to stop it. You can examine and modify an attached process
53a5351d
JM
1676with all the @value{GDBN} commands that are ordinarily available when
1677you start processes with @code{run}. You can insert breakpoints; you
1678can step and continue; you can modify storage. If you would rather the
1679process continue running, you may use the @code{continue} command after
c906108c
SS
1680attaching @value{GDBN} to the process.
1681
1682@table @code
1683@kindex detach
1684@item detach
1685When you have finished debugging the attached process, you can use the
1686@code{detach} command to release it from @value{GDBN} control. Detaching
1687the process continues its execution. After the @code{detach} command,
1688that process and @value{GDBN} become completely independent once more, and you
1689are ready to @code{attach} another process or start one with @code{run}.
1690@code{detach} does not repeat if you press @key{RET} again after
1691executing the command.
1692@end table
1693
1694If you exit @value{GDBN} or use the @code{run} command while you have an
1695attached process, you kill that process. By default, @value{GDBN} asks
1696for confirmation if you try to do either of these things; you can
1697control whether or not you need to confirm by using the @code{set
1698confirm} command (@pxref{Messages/Warnings, ,Optional warnings and
1699messages}).
1700
53a5351d 1701@node Kill Process
c906108c 1702@section Killing the child process
c906108c
SS
1703
1704@table @code
1705@kindex kill
1706@item kill
1707Kill the child process in which your program is running under @value{GDBN}.
1708@end table
1709
1710This command is useful if you wish to debug a core dump instead of a
1711running process. @value{GDBN} ignores any core dump file while your program
1712is running.
1713
1714On some operating systems, a program cannot be executed outside @value{GDBN}
1715while you have breakpoints set on it inside @value{GDBN}. You can use the
1716@code{kill} command in this situation to permit running your program
1717outside the debugger.
1718
1719The @code{kill} command is also useful if you wish to recompile and
1720relink your program, since on many systems it is impossible to modify an
1721executable file while it is running in a process. In this case, when you
1722next type @code{run}, @value{GDBN} notices that the file has changed, and
1723reads the symbol table again (while trying to preserve your current
1724breakpoint settings).
1725
53a5351d 1726@node Threads
c906108c 1727@section Debugging programs with multiple threads
c906108c
SS
1728
1729@cindex threads of execution
1730@cindex multiple threads
1731@cindex switching threads
1732In some operating systems, such as HP-UX and Solaris, a single program
1733may have more than one @dfn{thread} of execution. The precise semantics
1734of threads differ from one operating system to another, but in general
1735the threads of a single program are akin to multiple processes---except
1736that they share one address space (that is, they can all examine and
1737modify the same variables). On the other hand, each thread has its own
1738registers and execution stack, and perhaps private memory.
1739
1740@value{GDBN} provides these facilities for debugging multi-thread
1741programs:
1742
1743@itemize @bullet
1744@item automatic notification of new threads
1745@item @samp{thread @var{threadno}}, a command to switch among threads
1746@item @samp{info threads}, a command to inquire about existing threads
1747@item @samp{thread apply [@var{threadno}] [@var{all}] @var{args}},
1748a command to apply a command to a list of threads
1749@item thread-specific breakpoints
1750@end itemize
1751
c906108c
SS
1752@quotation
1753@emph{Warning:} These facilities are not yet available on every
1754@value{GDBN} configuration where the operating system supports threads.
1755If your @value{GDBN} does not support threads, these commands have no
1756effect. For example, a system without thread support shows no output
1757from @samp{info threads}, and always rejects the @code{thread} command,
1758like this:
1759
1760@smallexample
1761(@value{GDBP}) info threads
1762(@value{GDBP}) thread 1
1763Thread ID 1 not known. Use the "info threads" command to
1764see the IDs of currently known threads.
1765@end smallexample
1766@c FIXME to implementors: how hard would it be to say "sorry, this GDB
1767@c doesn't support threads"?
1768@end quotation
c906108c
SS
1769
1770@cindex focus of debugging
1771@cindex current thread
1772The @value{GDBN} thread debugging facility allows you to observe all
1773threads while your program runs---but whenever @value{GDBN} takes
1774control, one thread in particular is always the focus of debugging.
1775This thread is called the @dfn{current thread}. Debugging commands show
1776program information from the perspective of the current thread.
1777
c906108c
SS
1778@kindex New @var{systag}
1779@cindex thread identifier (system)
1780@c FIXME-implementors!! It would be more helpful if the [New...] message
1781@c included GDB's numeric thread handle, so you could just go to that
1782@c thread without first checking `info threads'.
1783Whenever @value{GDBN} detects a new thread in your program, it displays
1784the target system's identification for the thread with a message in the
1785form @samp{[New @var{systag}]}. @var{systag} is a thread identifier
1786whose form varies depending on the particular system. For example, on
1787LynxOS, you might see
1788
1789@example
1790[New process 35 thread 27]
1791@end example
1792
1793@noindent
1794when @value{GDBN} notices a new thread. In contrast, on an SGI system,
1795the @var{systag} is simply something like @samp{process 368}, with no
1796further qualifier.
1797
1798@c FIXME!! (1) Does the [New...] message appear even for the very first
1799@c thread of a program, or does it only appear for the
1800@c second---i.e., when it becomes obvious we have a multithread
1801@c program?
1802@c (2) *Is* there necessarily a first thread always? Or do some
1803@c multithread systems permit starting a program with multiple
1804@c threads ab initio?
1805
1806@cindex thread number
1807@cindex thread identifier (GDB)
1808For debugging purposes, @value{GDBN} associates its own thread
1809number---always a single integer---with each thread in your program.
1810
1811@table @code
1812@kindex info threads
1813@item info threads
1814Display a summary of all threads currently in your
1815program. @value{GDBN} displays for each thread (in this order):
1816
1817@enumerate
1818@item the thread number assigned by @value{GDBN}
1819
1820@item the target system's thread identifier (@var{systag})
1821
1822@item the current stack frame summary for that thread
1823@end enumerate
1824
1825@noindent
1826An asterisk @samp{*} to the left of the @value{GDBN} thread number
1827indicates the current thread.
1828
1829For example,
1830@end table
1831@c end table here to get a little more width for example
1832
1833@smallexample
1834(@value{GDBP}) info threads
1835 3 process 35 thread 27 0x34e5 in sigpause ()
1836 2 process 35 thread 23 0x34e5 in sigpause ()
1837* 1 process 35 thread 13 main (argc=1, argv=0x7ffffff8)
1838 at threadtest.c:68
1839@end smallexample
53a5351d
JM
1840
1841On HP-UX systems:
c906108c
SS
1842
1843@cindex thread number
1844@cindex thread identifier (GDB)
1845For debugging purposes, @value{GDBN} associates its own thread
1846number---a small integer assigned in thread-creation order---with each
1847thread in your program.
1848
1849@kindex New @var{systag}
1850@cindex thread identifier (system)
1851@c FIXME-implementors!! It would be more helpful if the [New...] message
1852@c included GDB's numeric thread handle, so you could just go to that
1853@c thread without first checking `info threads'.
1854Whenever @value{GDBN} detects a new thread in your program, it displays
1855both @value{GDBN}'s thread number and the target system's identification for the thread with a message in the
1856form @samp{[New @var{systag}]}. @var{systag} is a thread identifier
1857whose form varies depending on the particular system. For example, on
1858HP-UX, you see
1859
1860@example
1861[New thread 2 (system thread 26594)]
1862@end example
1863
1864@noindent
1865when @value{GDBN} notices a new thread.
1866
1867@table @code
1868@kindex info threads
1869@item info threads
1870Display a summary of all threads currently in your
1871program. @value{GDBN} displays for each thread (in this order):
1872
1873@enumerate
1874@item the thread number assigned by @value{GDBN}
1875
1876@item the target system's thread identifier (@var{systag})
1877
1878@item the current stack frame summary for that thread
1879@end enumerate
1880
1881@noindent
1882An asterisk @samp{*} to the left of the @value{GDBN} thread number
1883indicates the current thread.
1884
1885For example,
1886@end table
1887@c end table here to get a little more width for example
1888
1889@example
1890(@value{GDBP}) info threads
1891 * 3 system thread 26607 worker (wptr=0x7b09c318 "@@") at quicksort.c:137
1892 2 system thread 26606 0x7b0030d8 in __ksleep () from /usr/lib/libc.2
1893 1 system thread 27905 0x7b003498 in _brk () from /usr/lib/libc.2
1894@end example
c906108c
SS
1895
1896@table @code
1897@kindex thread @var{threadno}
1898@item thread @var{threadno}
1899Make thread number @var{threadno} the current thread. The command
1900argument @var{threadno} is the internal @value{GDBN} thread number, as
1901shown in the first field of the @samp{info threads} display.
1902@value{GDBN} responds by displaying the system identifier of the thread
1903you selected, and its current stack frame summary:
1904
1905@smallexample
1906@c FIXME!! This example made up; find a @value{GDBN} w/threads and get real one
1907(@value{GDBP}) thread 2
c906108c 1908[Switching to process 35 thread 23]
c906108c
SS
19090x34e5 in sigpause ()
1910@end smallexample
1911
1912@noindent
1913As with the @samp{[New @dots{}]} message, the form of the text after
1914@samp{Switching to} depends on your system's conventions for identifying
1915threads.
1916
1917@kindex thread apply
1918@item thread apply [@var{threadno}] [@var{all}] @var{args}
1919The @code{thread apply} command allows you to apply a command to one or
1920more threads. Specify the numbers of the threads that you want affected
1921with the command argument @var{threadno}. @var{threadno} is the internal
1922@value{GDBN} thread number, as shown in the first field of the @samp{info
1923threads} display. To apply a command to all threads, use
1924@code{thread apply all} @var{args}.
1925@end table
1926
1927@cindex automatic thread selection
1928@cindex switching threads automatically
1929@cindex threads, automatic switching
1930Whenever @value{GDBN} stops your program, due to a breakpoint or a
1931signal, it automatically selects the thread where that breakpoint or
1932signal happened. @value{GDBN} alerts you to the context switch with a
1933message of the form @samp{[Switching to @var{systag}]} to identify the
1934thread.
1935
1936@xref{Thread Stops,,Stopping and starting multi-thread programs}, for
1937more information about how @value{GDBN} behaves when you stop and start
1938programs with multiple threads.
1939
1940@xref{Set Watchpoints,,Setting watchpoints}, for information about
1941watchpoints in programs with multiple threads.
c906108c 1942
53a5351d 1943@node Processes
c906108c
SS
1944@section Debugging programs with multiple processes
1945
1946@cindex fork, debugging programs which call
1947@cindex multiple processes
1948@cindex processes, multiple
53a5351d
JM
1949On most systems, @value{GDBN} has no special support for debugging
1950programs which create additional processes using the @code{fork}
1951function. When a program forks, @value{GDBN} will continue to debug the
1952parent process and the child process will run unimpeded. If you have
1953set a breakpoint in any code which the child then executes, the child
1954will get a @code{SIGTRAP} signal which (unless it catches the signal)
1955will cause it to terminate.
c906108c
SS
1956
1957However, if you want to debug the child process there is a workaround
1958which isn't too painful. Put a call to @code{sleep} in the code which
1959the child process executes after the fork. It may be useful to sleep
1960only if a certain environment variable is set, or a certain file exists,
1961so that the delay need not occur when you don't want to run @value{GDBN}
1962on the child. While the child is sleeping, use the @code{ps} program to
1963get its process ID. Then tell @value{GDBN} (a new invocation of
1964@value{GDBN} if you are also debugging the parent process) to attach to
d4f3574e 1965the child process (@pxref{Attach}). From that point on you can debug
c906108c 1966the child process just like any other process which you attached to.
c906108c 1967
53a5351d
JM
1968On HP-UX (11.x and later only?), @value{GDBN} provides support for
1969debugging programs that create additional processes using the
1970@code{fork} or @code{vfork} function.
c906108c
SS
1971
1972By default, when a program forks, @value{GDBN} will continue to debug
1973the parent process and the child process will run unimpeded.
1974
1975If you want to follow the child process instead of the parent process,
1976use the command @w{@code{set follow-fork-mode}}.
1977
1978@table @code
1979@kindex set follow-fork-mode
1980@item set follow-fork-mode @var{mode}
1981Set the debugger response to a program call of @code{fork} or
1982@code{vfork}. A call to @code{fork} or @code{vfork} creates a new
1983process. The @var{mode} can be:
1984
1985@table @code
1986@item parent
1987The original process is debugged after a fork. The child process runs
2df3850c 1988unimpeded. This is the default.
c906108c
SS
1989
1990@item child
1991The new process is debugged after a fork. The parent process runs
1992unimpeded.
1993
1994@item ask
1995The debugger will ask for one of the above choices.
1996@end table
1997
1998@item show follow-fork-mode
2df3850c 1999Display the current debugger response to a @code{fork} or @code{vfork} call.
c906108c
SS
2000@end table
2001
2002If you ask to debug a child process and a @code{vfork} is followed by an
2003@code{exec}, @value{GDBN} executes the new target up to the first
2004breakpoint in the new target. If you have a breakpoint set on
2005@code{main} in your original program, the breakpoint will also be set on
2006the child process's @code{main}.
2007
2008When a child process is spawned by @code{vfork}, you cannot debug the
2009child or parent until an @code{exec} call completes.
2010
2011If you issue a @code{run} command to @value{GDBN} after an @code{exec}
2012call executes, the new target restarts. To restart the parent process,
2013use the @code{file} command with the parent executable name as its
2014argument.
2015
2016You can use the @code{catch} command to make @value{GDBN} stop whenever
2017a @code{fork}, @code{vfork}, or @code{exec} call is made. @xref{Set
2018Catchpoints, ,Setting catchpoints}.
c906108c 2019
53a5351d 2020@node Stopping
c906108c
SS
2021@chapter Stopping and Continuing
2022
2023The principal purposes of using a debugger are so that you can stop your
2024program before it terminates; or so that, if your program runs into
2025trouble, you can investigate and find out why.
2026
7a292a7a
SS
2027Inside @value{GDBN}, your program may stop for any of several reasons,
2028such as a signal, a breakpoint, or reaching a new line after a
2029@value{GDBN} command such as @code{step}. You may then examine and
2030change variables, set new breakpoints or remove old ones, and then
2031continue execution. Usually, the messages shown by @value{GDBN} provide
2032ample explanation of the status of your program---but you can also
2033explicitly request this information at any time.
c906108c
SS
2034
2035@table @code
2036@kindex info program
2037@item info program
2038Display information about the status of your program: whether it is
7a292a7a 2039running or not, what process it is, and why it stopped.
c906108c
SS
2040@end table
2041
2042@menu
2043* Breakpoints:: Breakpoints, watchpoints, and catchpoints
2044* Continuing and Stepping:: Resuming execution
c906108c 2045* Signals:: Signals
c906108c 2046* Thread Stops:: Stopping and starting multi-thread programs
c906108c
SS
2047@end menu
2048
53a5351d 2049@node Breakpoints
c906108c
SS
2050@section Breakpoints, watchpoints, and catchpoints
2051
2052@cindex breakpoints
2053A @dfn{breakpoint} makes your program stop whenever a certain point in
2054the program is reached. For each breakpoint, you can add conditions to
2055control in finer detail whether your program stops. You can set
2056breakpoints with the @code{break} command and its variants (@pxref{Set
2057Breaks, ,Setting breakpoints}), to specify the place where your program
2058should stop by line number, function name or exact address in the
2059program.
2060
2061In HP-UX, SunOS 4.x, SVR4, and Alpha OSF/1 configurations, you can set
2062breakpoints in shared libraries before the executable is run. There is
2063a minor limitation on HP-UX systems: you must wait until the executable
2064is run in order to set breakpoints in shared library routines that are
2065not called directly by the program (for example, routines that are
2066arguments in a @code{pthread_create} call).
2067
2068@cindex watchpoints
2069@cindex memory tracing
2070@cindex breakpoint on memory address
2071@cindex breakpoint on variable modification
2072A @dfn{watchpoint} is a special breakpoint that stops your program
2073when the value of an expression changes. You must use a different
2074command to set watchpoints (@pxref{Set Watchpoints, ,Setting
2075watchpoints}), but aside from that, you can manage a watchpoint like
2076any other breakpoint: you enable, disable, and delete both breakpoints
2077and watchpoints using the same commands.
2078
2079You can arrange to have values from your program displayed automatically
2080whenever @value{GDBN} stops at a breakpoint. @xref{Auto Display,,
2081Automatic display}.
2082
2083@cindex catchpoints
2084@cindex breakpoint on events
2085A @dfn{catchpoint} is another special breakpoint that stops your program
2086when a certain kind of event occurs, such as the throwing of a C++
2087exception or the loading of a library. As with watchpoints, you use a
2088different command to set a catchpoint (@pxref{Set Catchpoints, ,Setting
2089catchpoints}), but aside from that, you can manage a catchpoint like any
2090other breakpoint. (To stop when your program receives a signal, use the
d4f3574e 2091@code{handle} command; see @ref{Signals, ,Signals}.)
c906108c
SS
2092
2093@cindex breakpoint numbers
2094@cindex numbers for breakpoints
2095@value{GDBN} assigns a number to each breakpoint, watchpoint, or
2096catchpoint when you create it; these numbers are successive integers
2097starting with one. In many of the commands for controlling various
2098features of breakpoints you use the breakpoint number to say which
2099breakpoint you want to change. Each breakpoint may be @dfn{enabled} or
2100@dfn{disabled}; if disabled, it has no effect on your program until you
2101enable it again.
2102
2103@menu
2104* Set Breaks:: Setting breakpoints
2105* Set Watchpoints:: Setting watchpoints
2106* Set Catchpoints:: Setting catchpoints
2107* Delete Breaks:: Deleting breakpoints
2108* Disabling:: Disabling breakpoints
2109* Conditions:: Break conditions
2110* Break Commands:: Breakpoint command lists
c906108c 2111* Breakpoint Menus:: Breakpoint menus
d4f3574e 2112* Error in Breakpoints:: ``Cannot insert breakpoints''
c906108c
SS
2113@end menu
2114
53a5351d 2115@node Set Breaks
c906108c
SS
2116@subsection Setting breakpoints
2117
2118@c FIXME LMB what does GDB do if no code on line of breakpt?
2119@c consider in particular declaration with/without initialization.
2120@c
2121@c FIXME 2 is there stuff on this already? break at fun start, already init?
2122
2123@kindex break
2124@kindex b
2125@kindex $bpnum
2126@cindex latest breakpoint
2127Breakpoints are set with the @code{break} command (abbreviated
2128@code{b}). The debugger convenience variable @samp{$bpnum} records the
2129number of the breakpoints you've set most recently; see @ref{Convenience
2130Vars,, Convenience variables}, for a discussion of what you can do with
2131convenience variables.
2132
2133You have several ways to say where the breakpoint should go.
2134
2135@table @code
2136@item break @var{function}
2137Set a breakpoint at entry to function @var{function}.
c906108c
SS
2138When using source languages that permit overloading of symbols, such as
2139C++, @var{function} may refer to more than one possible place to break.
2140@xref{Breakpoint Menus,,Breakpoint menus}, for a discussion of that situation.
c906108c
SS
2141
2142@item break +@var{offset}
2143@itemx break -@var{offset}
2144Set a breakpoint some number of lines forward or back from the position
d4f3574e 2145at which execution stopped in the currently selected @dfn{stack frame}.
2df3850c 2146(@xref{Frames, ,Frames}, for a description of stack frames.)
c906108c
SS
2147
2148@item break @var{linenum}
2149Set a breakpoint at line @var{linenum} in the current source file.
d4f3574e
SS
2150The current source file is the last file whose source text was printed.
2151The breakpoint will stop your program just before it executes any of the
c906108c
SS
2152code on that line.
2153
2154@item break @var{filename}:@var{linenum}
2155Set a breakpoint at line @var{linenum} in source file @var{filename}.
2156
2157@item break @var{filename}:@var{function}
2158Set a breakpoint at entry to function @var{function} found in file
2159@var{filename}. Specifying a file name as well as a function name is
2160superfluous except when multiple files contain similarly named
2161functions.
2162
2163@item break *@var{address}
2164Set a breakpoint at address @var{address}. You can use this to set
2165breakpoints in parts of your program which do not have debugging
2166information or source files.
2167
2168@item break
2169When called without any arguments, @code{break} sets a breakpoint at
2170the next instruction to be executed in the selected stack frame
2171(@pxref{Stack, ,Examining the Stack}). In any selected frame but the
2172innermost, this makes your program stop as soon as control
2173returns to that frame. This is similar to the effect of a
2174@code{finish} command in the frame inside the selected frame---except
2175that @code{finish} does not leave an active breakpoint. If you use
2176@code{break} without an argument in the innermost frame, @value{GDBN} stops
2177the next time it reaches the current location; this may be useful
2178inside loops.
2179
2180@value{GDBN} normally ignores breakpoints when it resumes execution, until at
2181least one instruction has been executed. If it did not do this, you
2182would be unable to proceed past a breakpoint without first disabling the
2183breakpoint. This rule applies whether or not the breakpoint already
2184existed when your program stopped.
2185
2186@item break @dots{} if @var{cond}
2187Set a breakpoint with condition @var{cond}; evaluate the expression
2188@var{cond} each time the breakpoint is reached, and stop only if the
2189value is nonzero---that is, if @var{cond} evaluates as true.
2190@samp{@dots{}} stands for one of the possible arguments described
2191above (or no argument) specifying where to break. @xref{Conditions,
2192,Break conditions}, for more information on breakpoint conditions.
2193
2194@kindex tbreak
2195@item tbreak @var{args}
2196Set a breakpoint enabled only for one stop. @var{args} are the
2197same as for the @code{break} command, and the breakpoint is set in the same
2198way, but the breakpoint is automatically deleted after the first time your
2199program stops there. @xref{Disabling, ,Disabling breakpoints}.
2200
c906108c
SS
2201@kindex hbreak
2202@item hbreak @var{args}
d4f3574e
SS
2203Set a hardware-assisted breakpoint. @var{args} are the same as for the
2204@code{break} command and the breakpoint is set in the same way, but the
c906108c
SS
2205breakpoint requires hardware support and some target hardware may not
2206have this support. The main purpose of this is EPROM/ROM code
d4f3574e
SS
2207debugging, so you can set a breakpoint at an instruction without
2208changing the instruction. This can be used with the new trap-generation
2209provided by SPARClite DSU and some x86-based targets. These targets
2210will generate traps when a program accesses some data or instruction
2211address that is assigned to the debug registers. However the hardware
2212breakpoint registers can take a limited number of breakpoints. For
2213example, on the DSU, only two data breakpoints can be set at a time, and
2214@value{GDBN} will reject this command if more than two are used. Delete
2215or disable unused hardware breakpoints before setting new ones
2216(@pxref{Disabling, ,Disabling}). @xref{Conditions, ,Break conditions}.
c906108c
SS
2217
2218@kindex thbreak
2219@item thbreak @var{args}
2220Set a hardware-assisted breakpoint enabled only for one stop. @var{args}
2221are the same as for the @code{hbreak} command and the breakpoint is set in
2222the same way. However, like the @code{tbreak} command,
2223the breakpoint is automatically deleted after the
2224first time your program stops there. Also, like the @code{hbreak}
2225command, the breakpoint requires hardware support and some target hardware
2226may not have this support. @xref{Disabling, ,Disabling breakpoints}.
d4f3574e 2227See also @ref{Conditions, ,Break conditions}.
c906108c
SS
2228
2229@kindex rbreak
2230@cindex regular expression
2231@item rbreak @var{regex}
c906108c 2232Set breakpoints on all functions matching the regular expression
11cf8741
JM
2233@var{regex}. This command sets an unconditional breakpoint on all
2234matches, printing a list of all breakpoints it set. Once these
2235breakpoints are set, they are treated just like the breakpoints set with
2236the @code{break} command. You can delete them, disable them, or make
2237them conditional the same way as any other breakpoint.
2238
2239The syntax of the regular expression is the standard one used with tools
2240like @file{grep}. Note that this is different from the syntax used by
2241shells, so for instance @code{foo*} matches all functions that include
2242an @code{fo} followed by zero or more @code{o}s. There is an implicit
2243@code{.*} leading and trailing the regular expression you supply, so to
2244match only functions that begin with @code{foo}, use @code{^foo}.
c906108c 2245
c906108c
SS
2246When debugging C++ programs, @code{rbreak} is useful for setting
2247breakpoints on overloaded functions that are not members of any special
2248classes.
c906108c
SS
2249
2250@kindex info breakpoints
2251@cindex @code{$_} and @code{info breakpoints}
2252@item info breakpoints @r{[}@var{n}@r{]}
2253@itemx info break @r{[}@var{n}@r{]}
2254@itemx info watchpoints @r{[}@var{n}@r{]}
2255Print a table of all breakpoints, watchpoints, and catchpoints set and
2256not deleted, with the following columns for each breakpoint:
2257
2258@table @emph
2259@item Breakpoint Numbers
2260@item Type
2261Breakpoint, watchpoint, or catchpoint.
2262@item Disposition
2263Whether the breakpoint is marked to be disabled or deleted when hit.
2264@item Enabled or Disabled
2265Enabled breakpoints are marked with @samp{y}. @samp{n} marks breakpoints
2266that are not enabled.
2267@item Address
2df3850c 2268Where the breakpoint is in your program, as a memory address.
c906108c
SS
2269@item What
2270Where the breakpoint is in the source for your program, as a file and
2271line number.
2272@end table
2273
2274@noindent
2275If a breakpoint is conditional, @code{info break} shows the condition on
2276the line following the affected breakpoint; breakpoint commands, if any,
2277are listed after that.
2278
2279@noindent
2280@code{info break} with a breakpoint
2281number @var{n} as argument lists only that breakpoint. The
2282convenience variable @code{$_} and the default examining-address for
2283the @code{x} command are set to the address of the last breakpoint
2284listed (@pxref{Memory, ,Examining memory}).
2285
2286@noindent
2287@code{info break} displays a count of the number of times the breakpoint
2288has been hit. This is especially useful in conjunction with the
2289@code{ignore} command. You can ignore a large number of breakpoint
2290hits, look at the breakpoint info to see how many times the breakpoint
2291was hit, and then run again, ignoring one less than that number. This
2292will get you quickly to the last hit of that breakpoint.
2293@end table
2294
2295@value{GDBN} allows you to set any number of breakpoints at the same place in
2296your program. There is nothing silly or meaningless about this. When
2297the breakpoints are conditional, this is even useful
2298(@pxref{Conditions, ,Break conditions}).
2299
2300@cindex negative breakpoint numbers
2301@cindex internal @value{GDBN} breakpoints
2302@value{GDBN} itself sometimes sets breakpoints in your program for special
2303purposes, such as proper handling of @code{longjmp} (in C programs).
2304These internal breakpoints are assigned negative numbers, starting with
2305@code{-1}; @samp{info breakpoints} does not display them.
2306
2307You can see these breakpoints with the @value{GDBN} maintenance command
2308@samp{maint info breakpoints}.
2309
2310@table @code
2311@kindex maint info breakpoints
2312@item maint info breakpoints
2313Using the same format as @samp{info breakpoints}, display both the
2314breakpoints you've set explicitly, and those @value{GDBN} is using for
2315internal purposes. Internal breakpoints are shown with negative
2316breakpoint numbers. The type column identifies what kind of breakpoint
2317is shown:
2318
2319@table @code
2320@item breakpoint
2321Normal, explicitly set breakpoint.
2322
2323@item watchpoint
2324Normal, explicitly set watchpoint.
2325
2326@item longjmp
2327Internal breakpoint, used to handle correctly stepping through
2328@code{longjmp} calls.
2329
2330@item longjmp resume
2331Internal breakpoint at the target of a @code{longjmp}.
2332
2333@item until
2334Temporary internal breakpoint used by the @value{GDBN} @code{until} command.
2335
2336@item finish
2337Temporary internal breakpoint used by the @value{GDBN} @code{finish} command.
2338
c906108c
SS
2339@item shlib events
2340Shared library events.
53a5351d 2341
c906108c 2342@end table
53a5351d 2343
c906108c
SS
2344@end table
2345
2346
53a5351d 2347@node Set Watchpoints
c906108c
SS
2348@subsection Setting watchpoints
2349
2350@cindex setting watchpoints
2351@cindex software watchpoints
2352@cindex hardware watchpoints
2353You can use a watchpoint to stop execution whenever the value of an
2354expression changes, without having to predict a particular place where
2355this may happen.
2356
2357Depending on your system, watchpoints may be implemented in software or
2df3850c 2358hardware. @value{GDBN} does software watchpointing by single-stepping your
c906108c
SS
2359program and testing the variable's value each time, which is hundreds of
2360times slower than normal execution. (But this may still be worth it, to
2361catch errors where you have no clue what part of your program is the
2362culprit.)
2363
d4f3574e 2364On some systems, such as HP-UX, Linux and some other x86-based targets,
2df3850c 2365@value{GDBN} includes support for
c906108c
SS
2366hardware watchpoints, which do not slow down the running of your
2367program.
2368
2369@table @code
2370@kindex watch
2371@item watch @var{expr}
2372Set a watchpoint for an expression. @value{GDBN} will break when @var{expr}
2373is written into by the program and its value changes.
2374
2375@kindex rwatch
2376@item rwatch @var{expr}
2377Set a watchpoint that will break when watch @var{expr} is read by the program.
c906108c
SS
2378
2379@kindex awatch
2380@item awatch @var{expr}
2df3850c 2381Set a watchpoint that will break when @var{expr} is either read or written into
7be570e7 2382by the program.
c906108c
SS
2383
2384@kindex info watchpoints
2385@item info watchpoints
2386This command prints a list of watchpoints, breakpoints, and catchpoints;
2387it is the same as @code{info break}.
2388@end table
2389
2390@value{GDBN} sets a @dfn{hardware watchpoint} if possible. Hardware
2391watchpoints execute very quickly, and the debugger reports a change in
2392value at the exact instruction where the change occurs. If @value{GDBN}
2393cannot set a hardware watchpoint, it sets a software watchpoint, which
2394executes more slowly and reports the change in value at the next
2395statement, not the instruction, after the change occurs.
2396
2397When you issue the @code{watch} command, @value{GDBN} reports
2398
2399@example
2400Hardware watchpoint @var{num}: @var{expr}
2401@end example
2402
2403@noindent
2404if it was able to set a hardware watchpoint.
2405
7be570e7
JM
2406Currently, the @code{awatch} and @code{rwatch} commands can only set
2407hardware watchpoints, because accesses to data that don't change the
2408value of the watched expression cannot be detected without examining
2409every instruction as it is being executed, and @value{GDBN} does not do
2410that currently. If @value{GDBN} finds that it is unable to set a
2411hardware breakpoint with the @code{awatch} or @code{rwatch} command, it
2412will print a message like this:
2413
2414@smallexample
2415Expression cannot be implemented with read/access watchpoint.
2416@end smallexample
2417
2418Sometimes, @value{GDBN} cannot set a hardware watchpoint because the
2419data type of the watched expression is wider than what a hardware
2420watchpoint on the target machine can handle. For example, some systems
2421can only watch regions that are up to 4 bytes wide; on such systems you
2422cannot set hardware watchpoints for an expression that yields a
2423double-precision floating-point number (which is typically 8 bytes
2424wide). As a work-around, it might be possible to break the large region
2425into a series of smaller ones and watch them with separate watchpoints.
2426
2427If you set too many hardware watchpoints, @value{GDBN} might be unable
2428to insert all of them when you resume the execution of your program.
2429Since the precise number of active watchpoints is unknown until such
2430time as the program is about to be resumed, @value{GDBN} might not be
2431able to warn you about this when you set the watchpoints, and the
2432warning will be printed only when the program is resumed:
2433
2434@smallexample
2435Hardware watchpoint @var{num}: Could not insert watchpoint
2436@end smallexample
2437
2438@noindent
2439If this happens, delete or disable some of the watchpoints.
2440
2441The SPARClite DSU will generate traps when a program accesses some data
2442or instruction address that is assigned to the debug registers. For the
2443data addresses, DSU facilitates the @code{watch} command. However the
2444hardware breakpoint registers can only take two data watchpoints, and
2445both watchpoints must be the same kind. For example, you can set two
2446watchpoints with @code{watch} commands, two with @code{rwatch} commands,
2447@strong{or} two with @code{awatch} commands, but you cannot set one
2448watchpoint with one command and the other with a different command.
c906108c
SS
2449@value{GDBN} will reject the command if you try to mix watchpoints.
2450Delete or disable unused watchpoint commands before setting new ones.
2451
2452If you call a function interactively using @code{print} or @code{call},
2df3850c 2453any watchpoints you have set will be inactive until @value{GDBN} reaches another
c906108c
SS
2454kind of breakpoint or the call completes.
2455
7be570e7
JM
2456@value{GDBN} automatically deletes watchpoints that watch local
2457(automatic) variables, or expressions that involve such variables, when
2458they go out of scope, that is, when the execution leaves the block in
2459which these variables were defined. In particular, when the program
2460being debugged terminates, @emph{all} local variables go out of scope,
2461and so only watchpoints that watch global variables remain set. If you
2462rerun the program, you will need to set all such watchpoints again. One
2463way of doing that would be to set a code breakpoint at the entry to the
2464@code{main} function and when it breaks, set all the watchpoints.
2465
c906108c
SS
2466@quotation
2467@cindex watchpoints and threads
2468@cindex threads and watchpoints
c906108c
SS
2469@emph{Warning:} In multi-thread programs, watchpoints have only limited
2470usefulness. With the current watchpoint implementation, @value{GDBN}
2471can only watch the value of an expression @emph{in a single thread}. If
2472you are confident that the expression can only change due to the current
2473thread's activity (and if you are also confident that no other thread
2474can become current), then you can use watchpoints as usual. However,
2475@value{GDBN} may not notice when a non-current thread's activity changes
2476the expression.
53a5351d 2477
d4f3574e 2478@c FIXME: this is almost identical to the previous paragraph.
53a5351d
JM
2479@emph{HP-UX Warning:} In multi-thread programs, software watchpoints
2480have only limited usefulness. If @value{GDBN} creates a software
2481watchpoint, it can only watch the value of an expression @emph{in a
2482single thread}. If you are confident that the expression can only
2483change due to the current thread's activity (and if you are also
2484confident that no other thread can become current), then you can use
2485software watchpoints as usual. However, @value{GDBN} may not notice
2486when a non-current thread's activity changes the expression. (Hardware
2487watchpoints, in contrast, watch an expression in all threads.)
c906108c 2488@end quotation
c906108c 2489
53a5351d 2490@node Set Catchpoints
c906108c 2491@subsection Setting catchpoints
d4f3574e 2492@cindex catchpoints, setting
c906108c
SS
2493@cindex exception handlers
2494@cindex event handling
2495
2496You can use @dfn{catchpoints} to cause the debugger to stop for certain
2497kinds of program events, such as C++ exceptions or the loading of a
2498shared library. Use the @code{catch} command to set a catchpoint.
2499
2500@table @code
2501@kindex catch
2502@item catch @var{event}
2503Stop when @var{event} occurs. @var{event} can be any of the following:
2504@table @code
2505@item throw
2506@kindex catch throw
2507The throwing of a C++ exception.
2508
2509@item catch
2510@kindex catch catch
2511The catching of a C++ exception.
2512
2513@item exec
2514@kindex catch exec
2515A call to @code{exec}. This is currently only available for HP-UX.
2516
2517@item fork
2518@kindex catch fork
2519A call to @code{fork}. This is currently only available for HP-UX.
2520
2521@item vfork
2522@kindex catch vfork
2523A call to @code{vfork}. This is currently only available for HP-UX.
2524
2525@item load
2526@itemx load @var{libname}
2527@kindex catch load
2528The dynamic loading of any shared library, or the loading of the library
2529@var{libname}. This is currently only available for HP-UX.
2530
2531@item unload
2532@itemx unload @var{libname}
2533@kindex catch unload
2534The unloading of any dynamically loaded shared library, or the unloading
2535of the library @var{libname}. This is currently only available for HP-UX.
2536@end table
2537
2538@item tcatch @var{event}
2539Set a catchpoint that is enabled only for one stop. The catchpoint is
2540automatically deleted after the first time the event is caught.
2541
2542@end table
2543
2544Use the @code{info break} command to list the current catchpoints.
2545
2546There are currently some limitations to C++ exception handling
2547(@code{catch throw} and @code{catch catch}) in @value{GDBN}:
2548
2549@itemize @bullet
2550@item
2551If you call a function interactively, @value{GDBN} normally returns
2552control to you when the function has finished executing. If the call
2553raises an exception, however, the call may bypass the mechanism that
2554returns control to you and cause your program either to abort or to
2555simply continue running until it hits a breakpoint, catches a signal
2556that @value{GDBN} is listening for, or exits. This is the case even if
2557you set a catchpoint for the exception; catchpoints on exceptions are
2558disabled within interactive calls.
2559
2560@item
2561You cannot raise an exception interactively.
2562
2563@item
2564You cannot install an exception handler interactively.
2565@end itemize
2566
2567@cindex raise exceptions
2568Sometimes @code{catch} is not the best way to debug exception handling:
2569if you need to know exactly where an exception is raised, it is better to
2570stop @emph{before} the exception handler is called, since that way you
2571can see the stack before any unwinding takes place. If you set a
2572breakpoint in an exception handler instead, it may not be easy to find
2573out where the exception was raised.
2574
2575To stop just before an exception handler is called, you need some
2576knowledge of the implementation. In the case of @sc{gnu} C++, exceptions are
2577raised by calling a library function named @code{__raise_exception}
2578which has the following ANSI C interface:
2579
2580@example
2581 /* @var{addr} is where the exception identifier is stored.
d4f3574e
SS
2582 @var{id} is the exception identifier. */
2583 void __raise_exception (void **addr, void *id);
c906108c
SS
2584@end example
2585
2586@noindent
2587To make the debugger catch all exceptions before any stack
2588unwinding takes place, set a breakpoint on @code{__raise_exception}
2589(@pxref{Breakpoints, ,Breakpoints; watchpoints; and exceptions}).
2590
2591With a conditional breakpoint (@pxref{Conditions, ,Break conditions})
2592that depends on the value of @var{id}, you can stop your program when
2593a specific exception is raised. You can use multiple conditional
2594breakpoints to stop your program when any of a number of exceptions are
2595raised.
2596
2597
53a5351d 2598@node Delete Breaks
c906108c
SS
2599@subsection Deleting breakpoints
2600
2601@cindex clearing breakpoints, watchpoints, catchpoints
2602@cindex deleting breakpoints, watchpoints, catchpoints
2603It is often necessary to eliminate a breakpoint, watchpoint, or
2604catchpoint once it has done its job and you no longer want your program
2605to stop there. This is called @dfn{deleting} the breakpoint. A
2606breakpoint that has been deleted no longer exists; it is forgotten.
2607
2608With the @code{clear} command you can delete breakpoints according to
2609where they are in your program. With the @code{delete} command you can
2610delete individual breakpoints, watchpoints, or catchpoints by specifying
2611their breakpoint numbers.
2612
2613It is not necessary to delete a breakpoint to proceed past it. @value{GDBN}
2614automatically ignores breakpoints on the first instruction to be executed
2615when you continue execution without changing the execution address.
2616
2617@table @code
2618@kindex clear
2619@item clear
2620Delete any breakpoints at the next instruction to be executed in the
2621selected stack frame (@pxref{Selection, ,Selecting a frame}). When
2622the innermost frame is selected, this is a good way to delete a
2623breakpoint where your program just stopped.
2624
2625@item clear @var{function}
2626@itemx clear @var{filename}:@var{function}
2627Delete any breakpoints set at entry to the function @var{function}.
2628
2629@item clear @var{linenum}
2630@itemx clear @var{filename}:@var{linenum}
2631Delete any breakpoints set at or within the code of the specified line.
2632
2633@cindex delete breakpoints
2634@kindex delete
2635@kindex d
2636@item delete @r{[}breakpoints@r{]} @r{[}@var{bnums}@dots{}@r{]}
2637Delete the breakpoints, watchpoints, or catchpoints of the numbers
2638specified as arguments. If no argument is specified, delete all
2639breakpoints (@value{GDBN} asks confirmation, unless you have @code{set
2640confirm off}). You can abbreviate this command as @code{d}.
2641@end table
2642
53a5351d 2643@node Disabling
c906108c
SS
2644@subsection Disabling breakpoints
2645
2646@kindex disable breakpoints
2647@kindex enable breakpoints
2648Rather than deleting a breakpoint, watchpoint, or catchpoint, you might
2649prefer to @dfn{disable} it. This makes the breakpoint inoperative as if
2650it had been deleted, but remembers the information on the breakpoint so
2651that you can @dfn{enable} it again later.
2652
2653You disable and enable breakpoints, watchpoints, and catchpoints with
2654the @code{enable} and @code{disable} commands, optionally specifying one
2655or more breakpoint numbers as arguments. Use @code{info break} or
2656@code{info watch} to print a list of breakpoints, watchpoints, and
2657catchpoints if you do not know which numbers to use.
2658
2659A breakpoint, watchpoint, or catchpoint can have any of four different
2660states of enablement:
2661
2662@itemize @bullet
2663@item
2664Enabled. The breakpoint stops your program. A breakpoint set
2665with the @code{break} command starts out in this state.
2666@item
2667Disabled. The breakpoint has no effect on your program.
2668@item
2669Enabled once. The breakpoint stops your program, but then becomes
d4f3574e 2670disabled.
c906108c
SS
2671@item
2672Enabled for deletion. The breakpoint stops your program, but
d4f3574e
SS
2673immediately after it does so it is deleted permanently. A breakpoint
2674set with the @code{tbreak} command starts out in this state.
c906108c
SS
2675@end itemize
2676
2677You can use the following commands to enable or disable breakpoints,
2678watchpoints, and catchpoints:
2679
2680@table @code
2681@kindex disable breakpoints
2682@kindex disable
2683@kindex dis
2684@item disable @r{[}breakpoints@r{]} @r{[}@var{bnums}@dots{}@r{]}
2685Disable the specified breakpoints---or all breakpoints, if none are
2686listed. A disabled breakpoint has no effect but is not forgotten. All
2687options such as ignore-counts, conditions and commands are remembered in
2688case the breakpoint is enabled again later. You may abbreviate
2689@code{disable} as @code{dis}.
2690
2691@kindex enable breakpoints
2692@kindex enable
2693@item enable @r{[}breakpoints@r{]} @r{[}@var{bnums}@dots{}@r{]}
2694Enable the specified breakpoints (or all defined breakpoints). They
2695become effective once again in stopping your program.
2696
2697@item enable @r{[}breakpoints@r{]} once @var{bnums}@dots{}
2698Enable the specified breakpoints temporarily. @value{GDBN} disables any
2699of these breakpoints immediately after stopping your program.
2700
2701@item enable @r{[}breakpoints@r{]} delete @var{bnums}@dots{}
2702Enable the specified breakpoints to work once, then die. @value{GDBN}
2703deletes any of these breakpoints as soon as your program stops there.
2704@end table
2705
d4f3574e
SS
2706@c FIXME: I think the following ``Except for [...] @code{tbreak}'' is
2707@c confusing: tbreak is also initially enabled.
c906108c
SS
2708Except for a breakpoint set with @code{tbreak} (@pxref{Set Breaks,
2709,Setting breakpoints}), breakpoints that you set are initially enabled;
2710subsequently, they become disabled or enabled only when you use one of
2711the commands above. (The command @code{until} can set and delete a
2712breakpoint of its own, but it does not change the state of your other
2713breakpoints; see @ref{Continuing and Stepping, ,Continuing and
2714stepping}.)
2715
53a5351d 2716@node Conditions
c906108c
SS
2717@subsection Break conditions
2718@cindex conditional breakpoints
2719@cindex breakpoint conditions
2720
2721@c FIXME what is scope of break condition expr? Context where wanted?
2722@c in particular for a watchpoint?
2723The simplest sort of breakpoint breaks every time your program reaches a
2724specified place. You can also specify a @dfn{condition} for a
2725breakpoint. A condition is just a Boolean expression in your
2726programming language (@pxref{Expressions, ,Expressions}). A breakpoint with
2727a condition evaluates the expression each time your program reaches it,
2728and your program stops only if the condition is @emph{true}.
2729
2730This is the converse of using assertions for program validation; in that
2731situation, you want to stop when the assertion is violated---that is,
2732when the condition is false. In C, if you want to test an assertion expressed
2733by the condition @var{assert}, you should set the condition
2734@samp{! @var{assert}} on the appropriate breakpoint.
2735
2736Conditions are also accepted for watchpoints; you may not need them,
2737since a watchpoint is inspecting the value of an expression anyhow---but
2738it might be simpler, say, to just set a watchpoint on a variable name,
2739and specify a condition that tests whether the new value is an interesting
2740one.
2741
2742Break conditions can have side effects, and may even call functions in
2743your program. This can be useful, for example, to activate functions
2744that log program progress, or to use your own print functions to
2745format special data structures. The effects are completely predictable
2746unless there is another enabled breakpoint at the same address. (In
2747that case, @value{GDBN} might see the other breakpoint first and stop your
2748program without checking the condition of this one.) Note that
d4f3574e
SS
2749breakpoint commands are usually more convenient and flexible than break
2750conditions for the
c906108c
SS
2751purpose of performing side effects when a breakpoint is reached
2752(@pxref{Break Commands, ,Breakpoint command lists}).
2753
2754Break conditions can be specified when a breakpoint is set, by using
2755@samp{if} in the arguments to the @code{break} command. @xref{Set
2756Breaks, ,Setting breakpoints}. They can also be changed at any time
2757with the @code{condition} command.
53a5351d 2758
c906108c
SS
2759You can also use the @code{if} keyword with the @code{watch} command.
2760The @code{catch} command does not recognize the @code{if} keyword;
2761@code{condition} is the only way to impose a further condition on a
2762catchpoint.
c906108c
SS
2763
2764@table @code
2765@kindex condition
2766@item condition @var{bnum} @var{expression}
2767Specify @var{expression} as the break condition for breakpoint,
2768watchpoint, or catchpoint number @var{bnum}. After you set a condition,
2769breakpoint @var{bnum} stops your program only if the value of
2770@var{expression} is true (nonzero, in C). When you use
2771@code{condition}, @value{GDBN} checks @var{expression} immediately for
2772syntactic correctness, and to determine whether symbols in it have
d4f3574e
SS
2773referents in the context of your breakpoint. If @var{expression} uses
2774symbols not referenced in the context of the breakpoint, @value{GDBN}
2775prints an error message:
2776
2777@example
2778No symbol "foo" in current context.
2779@end example
2780
2781@noindent
c906108c
SS
2782@value{GDBN} does
2783not actually evaluate @var{expression} at the time the @code{condition}
d4f3574e
SS
2784command (or a command that sets a breakpoint with a condition, like
2785@code{break if @dots{}}) is given, however. @xref{Expressions, ,Expressions}.
c906108c
SS
2786
2787@item condition @var{bnum}
2788Remove the condition from breakpoint number @var{bnum}. It becomes
2789an ordinary unconditional breakpoint.
2790@end table
2791
2792@cindex ignore count (of breakpoint)
2793A special case of a breakpoint condition is to stop only when the
2794breakpoint has been reached a certain number of times. This is so
2795useful that there is a special way to do it, using the @dfn{ignore
2796count} of the breakpoint. Every breakpoint has an ignore count, which
2797is an integer. Most of the time, the ignore count is zero, and
2798therefore has no effect. But if your program reaches a breakpoint whose
2799ignore count is positive, then instead of stopping, it just decrements
2800the ignore count by one and continues. As a result, if the ignore count
2801value is @var{n}, the breakpoint does not stop the next @var{n} times
2802your program reaches it.
2803
2804@table @code
2805@kindex ignore
2806@item ignore @var{bnum} @var{count}
2807Set the ignore count of breakpoint number @var{bnum} to @var{count}.
2808The next @var{count} times the breakpoint is reached, your program's
2809execution does not stop; other than to decrement the ignore count, @value{GDBN}
2810takes no action.
2811
2812To make the breakpoint stop the next time it is reached, specify
2813a count of zero.
2814
2815When you use @code{continue} to resume execution of your program from a
2816breakpoint, you can specify an ignore count directly as an argument to
2817@code{continue}, rather than using @code{ignore}. @xref{Continuing and
2818Stepping,,Continuing and stepping}.
2819
2820If a breakpoint has a positive ignore count and a condition, the
2821condition is not checked. Once the ignore count reaches zero,
2822@value{GDBN} resumes checking the condition.
2823
2824You could achieve the effect of the ignore count with a condition such
2825as @w{@samp{$foo-- <= 0}} using a debugger convenience variable that
2826is decremented each time. @xref{Convenience Vars, ,Convenience
2827variables}.
2828@end table
2829
2830Ignore counts apply to breakpoints, watchpoints, and catchpoints.
2831
2832
53a5351d 2833@node Break Commands
c906108c
SS
2834@subsection Breakpoint command lists
2835
2836@cindex breakpoint commands
2837You can give any breakpoint (or watchpoint or catchpoint) a series of
2838commands to execute when your program stops due to that breakpoint. For
2839example, you might want to print the values of certain expressions, or
2840enable other breakpoints.
2841
2842@table @code
2843@kindex commands
2844@kindex end
2845@item commands @r{[}@var{bnum}@r{]}
2846@itemx @dots{} @var{command-list} @dots{}
2847@itemx end
2848Specify a list of commands for breakpoint number @var{bnum}. The commands
2849themselves appear on the following lines. Type a line containing just
2850@code{end} to terminate the commands.
2851
2852To remove all commands from a breakpoint, type @code{commands} and
2853follow it immediately with @code{end}; that is, give no commands.
2854
2855With no @var{bnum} argument, @code{commands} refers to the last
2856breakpoint, watchpoint, or catchpoint set (not to the breakpoint most
2857recently encountered).
2858@end table
2859
2860Pressing @key{RET} as a means of repeating the last @value{GDBN} command is
2861disabled within a @var{command-list}.
2862
2863You can use breakpoint commands to start your program up again. Simply
2864use the @code{continue} command, or @code{step}, or any other command
2865that resumes execution.
2866
2867Any other commands in the command list, after a command that resumes
2868execution, are ignored. This is because any time you resume execution
2869(even with a simple @code{next} or @code{step}), you may encounter
2870another breakpoint---which could have its own command list, leading to
2871ambiguities about which list to execute.
2872
2873@kindex silent
2874If the first command you specify in a command list is @code{silent}, the
2875usual message about stopping at a breakpoint is not printed. This may
2876be desirable for breakpoints that are to print a specific message and
2877then continue. If none of the remaining commands print anything, you
2878see no sign that the breakpoint was reached. @code{silent} is
2879meaningful only at the beginning of a breakpoint command list.
2880
2881The commands @code{echo}, @code{output}, and @code{printf} allow you to
2882print precisely controlled output, and are often useful in silent
2883breakpoints. @xref{Output, ,Commands for controlled output}.
2884
2885For example, here is how you could use breakpoint commands to print the
2886value of @code{x} at entry to @code{foo} whenever @code{x} is positive.
2887
2888@example
2889break foo if x>0
2890commands
2891silent
2892printf "x is %d\n",x
2893cont
2894end
2895@end example
2896
2897One application for breakpoint commands is to compensate for one bug so
2898you can test for another. Put a breakpoint just after the erroneous line
2899of code, give it a condition to detect the case in which something
2900erroneous has been done, and give it commands to assign correct values
2901to any variables that need them. End with the @code{continue} command
2902so that your program does not stop, and start with the @code{silent}
2903command so that no output is produced. Here is an example:
2904
2905@example
2906break 403
2907commands
2908silent
2909set x = y + 4
2910cont
2911end
2912@end example
2913
53a5351d 2914@node Breakpoint Menus
c906108c
SS
2915@subsection Breakpoint menus
2916@cindex overloading
2917@cindex symbol overloading
2918
2919Some programming languages (notably C++) permit a single function name
2920to be defined several times, for application in different contexts.
2921This is called @dfn{overloading}. When a function name is overloaded,
2922@samp{break @var{function}} is not enough to tell @value{GDBN} where you want
2923a breakpoint. If you realize this is a problem, you can use
2924something like @samp{break @var{function}(@var{types})} to specify which
2925particular version of the function you want. Otherwise, @value{GDBN} offers
2926you a menu of numbered choices for different possible breakpoints, and
2927waits for your selection with the prompt @samp{>}. The first two
2928options are always @samp{[0] cancel} and @samp{[1] all}. Typing @kbd{1}
2929sets a breakpoint at each definition of @var{function}, and typing
2930@kbd{0} aborts the @code{break} command without setting any new
2931breakpoints.
2932
2933For example, the following session excerpt shows an attempt to set a
2934breakpoint at the overloaded symbol @code{String::after}.
2935We choose three particular definitions of that function name:
2936
2937@c FIXME! This is likely to change to show arg type lists, at least
2938@smallexample
2939@group
2940(@value{GDBP}) b String::after
2941[0] cancel
2942[1] all
2943[2] file:String.cc; line number:867
2944[3] file:String.cc; line number:860
2945[4] file:String.cc; line number:875
2946[5] file:String.cc; line number:853
2947[6] file:String.cc; line number:846
2948[7] file:String.cc; line number:735
2949> 2 4 6
2950Breakpoint 1 at 0xb26c: file String.cc, line 867.
2951Breakpoint 2 at 0xb344: file String.cc, line 875.
2952Breakpoint 3 at 0xafcc: file String.cc, line 846.
2953Multiple breakpoints were set.
2954Use the "delete" command to delete unwanted
2955 breakpoints.
2956(@value{GDBP})
2957@end group
2958@end smallexample
c906108c
SS
2959
2960@c @ifclear BARETARGET
d4f3574e
SS
2961@node Error in Breakpoints
2962@subsection ``Cannot insert breakpoints''
c906108c
SS
2963@c
2964@c FIXME!! 14/6/95 Is there a real example of this? Let's use it.
2965@c
d4f3574e
SS
2966Under some operating systems, breakpoints cannot be used in a program if
2967any other process is running that program. In this situation,
2968attempting to run or continue a program with a breakpoint causes
2969@value{GDBN} to print an error message:
2970
2971@example
2972Cannot insert breakpoints.
2973The same program may be running in another process.
2974@end example
2975
2976When this happens, you have three ways to proceed:
2977
2978@enumerate
2979@item
2980Remove or disable the breakpoints, then continue.
2981
2982@item
2983Suspend @value{GDBN}, and copy the file containing your program to a new
2984name. Resume @value{GDBN} and use the @code{exec-file} command to specify
2985that @value{GDBN} should run your program under that name.
2986Then start your program again.
2987
2988@item
2989Relink your program so that the text segment is nonsharable, using the
2990linker option @samp{-N}. The operating system limitation may not apply
2991to nonsharable executables.
2992@end enumerate
c906108c
SS
2993@c @end ifclear
2994
d4f3574e
SS
2995A similar message can be printed if you request too many active
2996hardware-assisted breakpoints and watchpoints:
2997
2998@c FIXME: the precise wording of this message may change; the relevant
2999@c source change is not committed yet (Sep 3, 1999).
3000@smallexample
3001Stopped; cannot insert breakpoints.
3002You may have requested too many hardware breakpoints and watchpoints.
3003@end smallexample
3004
3005@noindent
3006This message is printed when you attempt to resume the program, since
3007only then @value{GDBN} knows exactly how many hardware breakpoints and
3008watchpoints it needs to insert.
3009
3010When this message is printed, you need to disable or remove some of the
3011hardware-assisted breakpoints and watchpoints, and then continue.
3012
3013
53a5351d 3014@node Continuing and Stepping
c906108c
SS
3015@section Continuing and stepping
3016
3017@cindex stepping
3018@cindex continuing
3019@cindex resuming execution
3020@dfn{Continuing} means resuming program execution until your program
3021completes normally. In contrast, @dfn{stepping} means executing just
3022one more ``step'' of your program, where ``step'' may mean either one
3023line of source code, or one machine instruction (depending on what
7a292a7a
SS
3024particular command you use). Either when continuing or when stepping,
3025your program may stop even sooner, due to a breakpoint or a signal. (If
d4f3574e
SS
3026it stops due to a signal, you may want to use @code{handle}, or use
3027@samp{signal 0} to resume execution. @xref{Signals, ,Signals}.)
c906108c
SS
3028
3029@table @code
3030@kindex continue
3031@kindex c
3032@kindex fg
3033@item continue @r{[}@var{ignore-count}@r{]}
3034@itemx c @r{[}@var{ignore-count}@r{]}
3035@itemx fg @r{[}@var{ignore-count}@r{]}
3036Resume program execution, at the address where your program last stopped;
3037any breakpoints set at that address are bypassed. The optional argument
3038@var{ignore-count} allows you to specify a further number of times to
3039ignore a breakpoint at this location; its effect is like that of
3040@code{ignore} (@pxref{Conditions, ,Break conditions}).
3041
3042The argument @var{ignore-count} is meaningful only when your program
3043stopped due to a breakpoint. At other times, the argument to
3044@code{continue} is ignored.
3045
d4f3574e
SS
3046The synonyms @code{c} and @code{fg} (for @dfn{foreground}, as the
3047debugged program is deemed to be the foreground program) are provided
3048purely for convenience, and have exactly the same behavior as
3049@code{continue}.
c906108c
SS
3050@end table
3051
3052To resume execution at a different place, you can use @code{return}
3053(@pxref{Returning, ,Returning from a function}) to go back to the
3054calling function; or @code{jump} (@pxref{Jumping, ,Continuing at a
3055different address}) to go to an arbitrary location in your program.
3056
3057A typical technique for using stepping is to set a breakpoint
3058(@pxref{Breakpoints, ,Breakpoints; watchpoints; and catchpoints}) at the
3059beginning of the function or the section of your program where a problem
3060is believed to lie, run your program until it stops at that breakpoint,
3061and then step through the suspect area, examining the variables that are
3062interesting, until you see the problem happen.
3063
3064@table @code
3065@kindex step
3066@kindex s
3067@item step
3068Continue running your program until control reaches a different source
3069line, then stop it and return control to @value{GDBN}. This command is
3070abbreviated @code{s}.
3071
3072@quotation
3073@c "without debugging information" is imprecise; actually "without line
3074@c numbers in the debugging information". (gcc -g1 has debugging info but
3075@c not line numbers). But it seems complex to try to make that
3076@c distinction here.
3077@emph{Warning:} If you use the @code{step} command while control is
3078within a function that was compiled without debugging information,
3079execution proceeds until control reaches a function that does have
3080debugging information. Likewise, it will not step into a function which
3081is compiled without debugging information. To step through functions
3082without debugging information, use the @code{stepi} command, described
3083below.
3084@end quotation
3085
d4f3574e
SS
3086The @code{step} command only stops at the first instruction of a
3087source line. This prevents the multiple stops that could otherwise occur in
c906108c
SS
3088switch statements, for loops, etc. @code{step} continues to stop if a
3089function that has debugging information is called within the line.
d4f3574e
SS
3090In other words, @code{step} @emph{steps inside} any functions called
3091within the line.
c906108c 3092
d4f3574e
SS
3093Also, the @code{step} command only enters a function if there is line
3094number information for the function. Otherwise it acts like the
c906108c
SS
3095@code{next} command. This avoids problems when using @code{cc -gl}
3096on MIPS machines. Previously, @code{step} entered subroutines if there
3097was any debugging information about the routine.
3098
3099@item step @var{count}
3100Continue running as in @code{step}, but do so @var{count} times. If a
7a292a7a
SS
3101breakpoint is reached, or a signal not related to stepping occurs before
3102@var{count} steps, stepping stops right away.
c906108c
SS
3103
3104@kindex next
3105@kindex n
3106@item next @r{[}@var{count}@r{]}
3107Continue to the next source line in the current (innermost) stack frame.
7a292a7a
SS
3108This is similar to @code{step}, but function calls that appear within
3109the line of code are executed without stopping. Execution stops when
3110control reaches a different line of code at the original stack level
3111that was executing when you gave the @code{next} command. This command
3112is abbreviated @code{n}.
c906108c
SS
3113
3114An argument @var{count} is a repeat count, as for @code{step}.
3115
3116
3117@c FIX ME!! Do we delete this, or is there a way it fits in with
3118@c the following paragraph? --- Vctoria
3119@c
3120@c @code{next} within a function that lacks debugging information acts like
3121@c @code{step}, but any function calls appearing within the code of the
3122@c function are executed without stopping.
3123
d4f3574e
SS
3124The @code{next} command only stops at the first instruction of a
3125source line. This prevents multiple stops that could otherwise occur in
c906108c
SS
3126switch statements, for loops, etc.
3127
3128@kindex finish
3129@item finish
3130Continue running until just after function in the selected stack frame
3131returns. Print the returned value (if any).
3132
3133Contrast this with the @code{return} command (@pxref{Returning,
3134,Returning from a function}).
3135
3136@kindex until
3137@kindex u
3138@item until
3139@itemx u
3140Continue running until a source line past the current line, in the
3141current stack frame, is reached. This command is used to avoid single
3142stepping through a loop more than once. It is like the @code{next}
3143command, except that when @code{until} encounters a jump, it
3144automatically continues execution until the program counter is greater
3145than the address of the jump.
3146
3147This means that when you reach the end of a loop after single stepping
3148though it, @code{until} makes your program continue execution until it
3149exits the loop. In contrast, a @code{next} command at the end of a loop
3150simply steps back to the beginning of the loop, which forces you to step
3151through the next iteration.
3152
3153@code{until} always stops your program if it attempts to exit the current
3154stack frame.
3155
3156@code{until} may produce somewhat counterintuitive results if the order
3157of machine code does not match the order of the source lines. For
3158example, in the following excerpt from a debugging session, the @code{f}
3159(@code{frame}) command shows that execution is stopped at line
3160@code{206}; yet when we use @code{until}, we get to line @code{195}:
3161
3162@example
3163(@value{GDBP}) f
3164#0 main (argc=4, argv=0xf7fffae8) at m4.c:206
3165206 expand_input();
3166(@value{GDBP}) until
3167195 for ( ; argc > 0; NEXTARG) @{
3168@end example
3169
3170This happened because, for execution efficiency, the compiler had
3171generated code for the loop closure test at the end, rather than the
3172start, of the loop---even though the test in a C @code{for}-loop is
3173written before the body of the loop. The @code{until} command appeared
3174to step back to the beginning of the loop when it advanced to this
3175expression; however, it has not really gone to an earlier
3176statement---not in terms of the actual machine code.
3177
3178@code{until} with no argument works by means of single
3179instruction stepping, and hence is slower than @code{until} with an
3180argument.
3181
3182@item until @var{location}
3183@itemx u @var{location}
3184Continue running your program until either the specified location is
3185reached, or the current stack frame returns. @var{location} is any of
3186the forms of argument acceptable to @code{break} (@pxref{Set Breaks,
3187,Setting breakpoints}). This form of the command uses breakpoints,
3188and hence is quicker than @code{until} without an argument.
3189
3190@kindex stepi
3191@kindex si
3192@item stepi
3193@itemx si
3194Execute one machine instruction, then stop and return to the debugger.
3195
3196It is often useful to do @samp{display/i $pc} when stepping by machine
3197instructions. This makes @value{GDBN} automatically display the next
3198instruction to be executed, each time your program stops. @xref{Auto
3199Display,, Automatic display}.
3200
3201An argument is a repeat count, as in @code{step}.
3202
3203@need 750
3204@kindex nexti
3205@kindex ni
3206@item nexti
3207@itemx ni
3208Execute one machine instruction, but if it is a function call,
3209proceed until the function returns.
3210
3211An argument is a repeat count, as in @code{next}.
3212@end table
3213
53a5351d 3214@node Signals
c906108c
SS
3215@section Signals
3216@cindex signals
3217
3218A signal is an asynchronous event that can happen in a program. The
3219operating system defines the possible kinds of signals, and gives each
3220kind a name and a number. For example, in Unix @code{SIGINT} is the
d4f3574e 3221signal a program gets when you type an interrupt character (often @kbd{C-c});
c906108c
SS
3222@code{SIGSEGV} is the signal a program gets from referencing a place in
3223memory far away from all the areas in use; @code{SIGALRM} occurs when
3224the alarm clock timer goes off (which happens only if your program has
3225requested an alarm).
3226
3227@cindex fatal signals
3228Some signals, including @code{SIGALRM}, are a normal part of the
3229functioning of your program. Others, such as @code{SIGSEGV}, indicate
d4f3574e 3230errors; these signals are @dfn{fatal} (they kill your program immediately) if the
c906108c
SS
3231program has not specified in advance some other way to handle the signal.
3232@code{SIGINT} does not indicate an error in your program, but it is normally
3233fatal so it can carry out the purpose of the interrupt: to kill the program.
3234
3235@value{GDBN} has the ability to detect any occurrence of a signal in your
3236program. You can tell @value{GDBN} in advance what to do for each kind of
3237signal.
3238
3239@cindex handling signals
3240Normally, @value{GDBN} is set up to ignore non-erroneous signals like @code{SIGALRM}
3241(so as not to interfere with their role in the functioning of your program)
3242but to stop your program immediately whenever an error signal happens.
3243You can change these settings with the @code{handle} command.
3244
3245@table @code
3246@kindex info signals
3247@item info signals
3248Print a table of all the kinds of signals and how @value{GDBN} has been told to
3249handle each one. You can use this to see the signal numbers of all
3250the defined types of signals.
3251
d4f3574e 3252@code{info handle} is an alias for @code{info signals}.
c906108c
SS
3253
3254@kindex handle
3255@item handle @var{signal} @var{keywords}@dots{}
3256Change the way @value{GDBN} handles signal @var{signal}. @var{signal} can
3257be the number of a signal or its name (with or without the @samp{SIG} at the
3258beginning). The @var{keywords} say what change to make.
3259@end table
3260
3261@c @group
3262The keywords allowed by the @code{handle} command can be abbreviated.
3263Their full names are:
3264
3265@table @code
3266@item nostop
3267@value{GDBN} should not stop your program when this signal happens. It may
3268still print a message telling you that the signal has come in.
3269
3270@item stop
3271@value{GDBN} should stop your program when this signal happens. This implies
3272the @code{print} keyword as well.
3273
3274@item print
3275@value{GDBN} should print a message when this signal happens.
3276
3277@item noprint
3278@value{GDBN} should not mention the occurrence of the signal at all. This
3279implies the @code{nostop} keyword as well.
3280
3281@item pass
3282@value{GDBN} should allow your program to see this signal; your program
3283can handle the signal, or else it may terminate if the signal is fatal
3284and not handled.
3285
3286@item nopass
3287@value{GDBN} should not allow your program to see this signal.
3288@end table
3289@c @end group
3290
d4f3574e
SS
3291When a signal stops your program, the signal is not visible to the
3292program until you
c906108c
SS
3293continue. Your program sees the signal then, if @code{pass} is in
3294effect for the signal in question @emph{at that time}. In other words,
3295after @value{GDBN} reports a signal, you can use the @code{handle}
3296command with @code{pass} or @code{nopass} to control whether your
3297program sees that signal when you continue.
3298
3299You can also use the @code{signal} command to prevent your program from
3300seeing a signal, or cause it to see a signal it normally would not see,
3301or to give it any signal at any time. For example, if your program stopped
3302due to some sort of memory reference error, you might store correct
3303values into the erroneous variables and continue, hoping to see more
3304execution; but your program would probably terminate immediately as
3305a result of the fatal signal once it saw the signal. To prevent this,
3306you can continue with @samp{signal 0}. @xref{Signaling, ,Giving your
3307program a signal}.
c906108c 3308
53a5351d 3309@node Thread Stops
c906108c
SS
3310@section Stopping and starting multi-thread programs
3311
3312When your program has multiple threads (@pxref{Threads,, Debugging
3313programs with multiple threads}), you can choose whether to set
3314breakpoints on all threads, or on a particular thread.
3315
3316@table @code
3317@cindex breakpoints and threads
3318@cindex thread breakpoints
3319@kindex break @dots{} thread @var{threadno}
3320@item break @var{linespec} thread @var{threadno}
3321@itemx break @var{linespec} thread @var{threadno} if @dots{}
3322@var{linespec} specifies source lines; there are several ways of
3323writing them, but the effect is always to specify some source line.
3324
3325Use the qualifier @samp{thread @var{threadno}} with a breakpoint command
3326to specify that you only want @value{GDBN} to stop the program when a
3327particular thread reaches this breakpoint. @var{threadno} is one of the
3328numeric thread identifiers assigned by @value{GDBN}, shown in the first
3329column of the @samp{info threads} display.
3330
3331If you do not specify @samp{thread @var{threadno}} when you set a
3332breakpoint, the breakpoint applies to @emph{all} threads of your
3333program.
3334
3335You can use the @code{thread} qualifier on conditional breakpoints as
3336well; in this case, place @samp{thread @var{threadno}} before the
3337breakpoint condition, like this:
3338
3339@smallexample
2df3850c 3340(@value{GDBP}) break frik.c:13 thread 28 if bartab > lim
c906108c
SS
3341@end smallexample
3342
3343@end table
3344
3345@cindex stopped threads
3346@cindex threads, stopped
3347Whenever your program stops under @value{GDBN} for any reason,
3348@emph{all} threads of execution stop, not just the current thread. This
3349allows you to examine the overall state of the program, including
3350switching between threads, without worrying that things may change
3351underfoot.
3352
3353@cindex continuing threads
3354@cindex threads, continuing
3355Conversely, whenever you restart the program, @emph{all} threads start
3356executing. @emph{This is true even when single-stepping} with commands
3357like @code{step} or @code{next}.
3358
3359In particular, @value{GDBN} cannot single-step all threads in lockstep.
3360Since thread scheduling is up to your debugging target's operating
3361system (not controlled by @value{GDBN}), other threads may
3362execute more than one statement while the current thread completes a
3363single step. Moreover, in general other threads stop in the middle of a
3364statement, rather than at a clean statement boundary, when the program
3365stops.
3366
3367You might even find your program stopped in another thread after
3368continuing or even single-stepping. This happens whenever some other
3369thread runs into a breakpoint, a signal, or an exception before the
3370first thread completes whatever you requested.
3371
3372On some OSes, you can lock the OS scheduler and thus allow only a single
3373thread to run.
3374
3375@table @code
3376@item set scheduler-locking @var{mode}
3377Set the scheduler locking mode. If it is @code{off}, then there is no
3378locking and any thread may run at any time. If @code{on}, then only the
3379current thread may run when the inferior is resumed. The @code{step}
3380mode optimizes for single-stepping. It stops other threads from
3381``seizing the prompt'' by preempting the current thread while you are
3382stepping. Other threads will only rarely (or never) get a chance to run
d4f3574e 3383when you step. They are more likely to run when you @samp{next} over a
c906108c 3384function call, and they are completely free to run when you use commands
d4f3574e 3385like @samp{continue}, @samp{until}, or @samp{finish}. However, unless another
c906108c 3386thread hits a breakpoint during its timeslice, they will never steal the
2df3850c 3387@value{GDBN} prompt away from the thread that you are debugging.
c906108c
SS
3388
3389@item show scheduler-locking
3390Display the current scheduler locking mode.
3391@end table
3392
c906108c 3393
53a5351d 3394@node Stack
c906108c
SS
3395@chapter Examining the Stack
3396
3397When your program has stopped, the first thing you need to know is where it
3398stopped and how it got there.
3399
3400@cindex call stack
3401Each time your program performs a function call, information about the call
3402is generated.
3403That information includes the location of the call in your program,
3404the arguments of the call,
3405and the local variables of the function being called.
3406The information is saved in a block of data called a @dfn{stack frame}.
3407The stack frames are allocated in a region of memory called the @dfn{call
3408stack}.
3409
3410When your program stops, the @value{GDBN} commands for examining the
3411stack allow you to see all of this information.
3412
3413@cindex selected frame
3414One of the stack frames is @dfn{selected} by @value{GDBN} and many
3415@value{GDBN} commands refer implicitly to the selected frame. In
3416particular, whenever you ask @value{GDBN} for the value of a variable in
3417your program, the value is found in the selected frame. There are
3418special @value{GDBN} commands to select whichever frame you are
3419interested in. @xref{Selection, ,Selecting a frame}.
3420
3421When your program stops, @value{GDBN} automatically selects the
3422currently executing frame and describes it briefly, similar to the
3423@code{frame} command (@pxref{Frame Info, ,Information about a frame}).
3424
3425@menu
3426* Frames:: Stack frames
3427* Backtrace:: Backtraces
3428* Selection:: Selecting a frame
3429* Frame Info:: Information on a frame
c906108c
SS
3430
3431@end menu
3432
53a5351d 3433@node Frames
c906108c
SS
3434@section Stack frames
3435
d4f3574e 3436@cindex frame, definition
c906108c
SS
3437@cindex stack frame
3438The call stack is divided up into contiguous pieces called @dfn{stack
3439frames}, or @dfn{frames} for short; each frame is the data associated
3440with one call to one function. The frame contains the arguments given
3441to the function, the function's local variables, and the address at
3442which the function is executing.
3443
3444@cindex initial frame
3445@cindex outermost frame
3446@cindex innermost frame
3447When your program is started, the stack has only one frame, that of the
3448function @code{main}. This is called the @dfn{initial} frame or the
3449@dfn{outermost} frame. Each time a function is called, a new frame is
3450made. Each time a function returns, the frame for that function invocation
3451is eliminated. If a function is recursive, there can be many frames for
3452the same function. The frame for the function in which execution is
3453actually occurring is called the @dfn{innermost} frame. This is the most
3454recently created of all the stack frames that still exist.
3455
3456@cindex frame pointer
3457Inside your program, stack frames are identified by their addresses. A
3458stack frame consists of many bytes, each of which has its own address; each
3459kind of computer has a convention for choosing one byte whose
3460address serves as the address of the frame. Usually this address is kept
3461in a register called the @dfn{frame pointer register} while execution is
3462going on in that frame.
3463
3464@cindex frame number
3465@value{GDBN} assigns numbers to all existing stack frames, starting with
3466zero for the innermost frame, one for the frame that called it,
3467and so on upward. These numbers do not really exist in your program;
3468they are assigned by @value{GDBN} to give you a way of designating stack
3469frames in @value{GDBN} commands.
3470
3471@c below produces an acceptable overful hbox. --mew 13aug1993
3472@cindex frameless execution
3473Some compilers provide a way to compile functions so that they operate
3474without stack frames. (For example, the @code{@value{GCC}} option
3475@samp{-fomit-frame-pointer} generates functions without a frame.)
3476This is occasionally done with heavily used library functions to save
3477the frame setup time. @value{GDBN} has limited facilities for dealing
3478with these function invocations. If the innermost function invocation
3479has no stack frame, @value{GDBN} nevertheless regards it as though
3480it had a separate frame, which is numbered zero as usual, allowing
3481correct tracing of the function call chain. However, @value{GDBN} has
3482no provision for frameless functions elsewhere in the stack.
3483
3484@table @code
d4f3574e 3485@kindex frame@r{, command}
c906108c
SS
3486@item frame @var{args}
3487The @code{frame} command allows you to move from one stack frame to another,
3488and to print the stack frame you select. @var{args} may be either the
3489address of the frame or the stack frame number. Without an argument,
3490@code{frame} prints the current stack frame.
3491
3492@kindex select-frame
3493@item select-frame
3494The @code{select-frame} command allows you to move from one stack frame
3495to another without printing the frame. This is the silent version of
3496@code{frame}.
3497@end table
3498
53a5351d 3499@node Backtrace
c906108c
SS
3500@section Backtraces
3501
3502@cindex backtraces
3503@cindex tracebacks
3504@cindex stack traces
3505A backtrace is a summary of how your program got where it is. It shows one
3506line per frame, for many frames, starting with the currently executing
3507frame (frame zero), followed by its caller (frame one), and on up the
3508stack.
3509
3510@table @code
3511@kindex backtrace
3512@kindex bt
3513@item backtrace
3514@itemx bt
3515Print a backtrace of the entire stack: one line per frame for all
3516frames in the stack.
3517
3518You can stop the backtrace at any time by typing the system interrupt
3519character, normally @kbd{C-c}.
3520
3521@item backtrace @var{n}
3522@itemx bt @var{n}
3523Similar, but print only the innermost @var{n} frames.
3524
3525@item backtrace -@var{n}
3526@itemx bt -@var{n}
3527Similar, but print only the outermost @var{n} frames.
3528@end table
3529
3530@kindex where
3531@kindex info stack
3532@kindex info s
3533The names @code{where} and @code{info stack} (abbreviated @code{info s})
3534are additional aliases for @code{backtrace}.
3535
3536Each line in the backtrace shows the frame number and the function name.
3537The program counter value is also shown---unless you use @code{set
3538print address off}. The backtrace also shows the source file name and
3539line number, as well as the arguments to the function. The program
3540counter value is omitted if it is at the beginning of the code for that
3541line number.
3542
3543Here is an example of a backtrace. It was made with the command
3544@samp{bt 3}, so it shows the innermost three frames.
3545
3546@smallexample
3547@group
3548#0 m4_traceon (obs=0x24eb0, argc=1, argv=0x2b8c8)
3549 at builtin.c:993
3550#1 0x6e38 in expand_macro (sym=0x2b600) at macro.c:242
3551#2 0x6840 in expand_token (obs=0x0, t=177664, td=0xf7fffb08)
3552 at macro.c:71
3553(More stack frames follow...)
3554@end group
3555@end smallexample
3556
3557@noindent
3558The display for frame zero does not begin with a program counter
3559value, indicating that your program has stopped at the beginning of the
3560code for line @code{993} of @code{builtin.c}.
3561
53a5351d 3562@node Selection
c906108c
SS
3563@section Selecting a frame
3564
3565Most commands for examining the stack and other data in your program work on
3566whichever stack frame is selected at the moment. Here are the commands for
3567selecting a stack frame; all of them finish by printing a brief description
3568of the stack frame just selected.
3569
3570@table @code
d4f3574e 3571@kindex frame@r{, selecting}
c906108c
SS
3572@kindex f
3573@item frame @var{n}
3574@itemx f @var{n}
3575Select frame number @var{n}. Recall that frame zero is the innermost
3576(currently executing) frame, frame one is the frame that called the
3577innermost one, and so on. The highest-numbered frame is the one for
3578@code{main}.
3579
3580@item frame @var{addr}
3581@itemx f @var{addr}
3582Select the frame at address @var{addr}. This is useful mainly if the
3583chaining of stack frames has been damaged by a bug, making it
3584impossible for @value{GDBN} to assign numbers properly to all frames. In
3585addition, this can be useful when your program has multiple stacks and
3586switches between them.
3587
c906108c
SS
3588On the SPARC architecture, @code{frame} needs two addresses to
3589select an arbitrary frame: a frame pointer and a stack pointer.
3590
3591On the MIPS and Alpha architecture, it needs two addresses: a stack
3592pointer and a program counter.
3593
3594On the 29k architecture, it needs three addresses: a register stack
3595pointer, a program counter, and a memory stack pointer.
3596@c note to future updaters: this is conditioned on a flag
3597@c SETUP_ARBITRARY_FRAME in the tm-*.h files. The above is up to date
3598@c as of 27 Jan 1994.
c906108c
SS
3599
3600@kindex up
3601@item up @var{n}
3602Move @var{n} frames up the stack. For positive numbers @var{n}, this
3603advances toward the outermost frame, to higher frame numbers, to frames
3604that have existed longer. @var{n} defaults to one.
3605
3606@kindex down
3607@kindex do
3608@item down @var{n}
3609Move @var{n} frames down the stack. For positive numbers @var{n}, this
3610advances toward the innermost frame, to lower frame numbers, to frames
3611that were created more recently. @var{n} defaults to one. You may
3612abbreviate @code{down} as @code{do}.
3613@end table
3614
3615All of these commands end by printing two lines of output describing the
3616frame. The first line shows the frame number, the function name, the
3617arguments, and the source file and line number of execution in that
3618frame. The second line shows the text of that source line.
3619
3620@need 1000
3621For example:
3622
3623@smallexample
3624@group
3625(@value{GDBP}) up
3626#1 0x22f0 in main (argc=1, argv=0xf7fffbf4, env=0xf7fffbfc)
3627 at env.c:10
362810 read_input_file (argv[i]);
3629@end group
3630@end smallexample
3631
3632After such a printout, the @code{list} command with no arguments
3633prints ten lines centered on the point of execution in the frame.
3634@xref{List, ,Printing source lines}.
3635
3636@table @code
3637@kindex down-silently
3638@kindex up-silently
3639@item up-silently @var{n}
3640@itemx down-silently @var{n}
3641These two commands are variants of @code{up} and @code{down},
3642respectively; they differ in that they do their work silently, without
3643causing display of the new frame. They are intended primarily for use
3644in @value{GDBN} command scripts, where the output might be unnecessary and
3645distracting.
3646@end table
3647
53a5351d 3648@node Frame Info
c906108c
SS
3649@section Information about a frame
3650
3651There are several other commands to print information about the selected
3652stack frame.
3653
3654@table @code
3655@item frame
3656@itemx f
3657When used without any argument, this command does not change which
3658frame is selected, but prints a brief description of the currently
3659selected stack frame. It can be abbreviated @code{f}. With an
3660argument, this command is used to select a stack frame.
3661@xref{Selection, ,Selecting a frame}.
3662
3663@kindex info frame
3664@kindex info f
3665@item info frame
3666@itemx info f
3667This command prints a verbose description of the selected stack frame,
3668including:
3669
3670@itemize @bullet
3671@item
3672the address of the frame
3673@item
3674the address of the next frame down (called by this frame)
3675@item
3676the address of the next frame up (caller of this frame)
3677@item
3678the language in which the source code corresponding to this frame is written
3679@item
3680the address of the frame's arguments
3681@item
d4f3574e
SS
3682the address of the frame's local variables
3683@item
c906108c
SS
3684the program counter saved in it (the address of execution in the caller frame)
3685@item
3686which registers were saved in the frame
3687@end itemize
3688
3689@noindent The verbose description is useful when
3690something has gone wrong that has made the stack format fail to fit
3691the usual conventions.
3692
3693@item info frame @var{addr}
3694@itemx info f @var{addr}
3695Print a verbose description of the frame at address @var{addr}, without
3696selecting that frame. The selected frame remains unchanged by this
3697command. This requires the same kind of address (more than one for some
3698architectures) that you specify in the @code{frame} command.
3699@xref{Selection, ,Selecting a frame}.
3700
3701@kindex info args
3702@item info args
3703Print the arguments of the selected frame, each on a separate line.
3704
3705@item info locals
3706@kindex info locals
3707Print the local variables of the selected frame, each on a separate
3708line. These are all variables (declared either static or automatic)
3709accessible at the point of execution of the selected frame.
3710
c906108c 3711@kindex info catch
d4f3574e
SS
3712@cindex catch exceptions, list active handlers
3713@cindex exception handlers, how to list
c906108c
SS
3714@item info catch
3715Print a list of all the exception handlers that are active in the
3716current stack frame at the current point of execution. To see other
3717exception handlers, visit the associated frame (using the @code{up},
3718@code{down}, or @code{frame} commands); then type @code{info catch}.
3719@xref{Set Catchpoints, , Setting catchpoints}.
53a5351d 3720
c906108c
SS
3721@end table
3722
c906108c 3723
53a5351d 3724@node Source
c906108c
SS
3725@chapter Examining Source Files
3726
3727@value{GDBN} can print parts of your program's source, since the debugging
3728information recorded in the program tells @value{GDBN} what source files were
3729used to build it. When your program stops, @value{GDBN} spontaneously prints
3730the line where it stopped. Likewise, when you select a stack frame
3731(@pxref{Selection, ,Selecting a frame}), @value{GDBN} prints the line where
3732execution in that frame has stopped. You can print other portions of
3733source files by explicit command.
3734
7a292a7a 3735If you use @value{GDBN} through its @sc{gnu} Emacs interface, you may
d4f3574e 3736prefer to use Emacs facilities to view source; see @ref{Emacs, ,Using
7a292a7a 3737@value{GDBN} under @sc{gnu} Emacs}.
c906108c
SS
3738
3739@menu
3740* List:: Printing source lines
c906108c 3741* Search:: Searching source files
c906108c
SS
3742* Source Path:: Specifying source directories
3743* Machine Code:: Source and machine code
3744@end menu
3745
53a5351d 3746@node List
c906108c
SS
3747@section Printing source lines
3748
3749@kindex list
3750@kindex l
3751To print lines from a source file, use the @code{list} command
3752(abbreviated @code{l}). By default, ten lines are printed.
3753There are several ways to specify what part of the file you want to print.
3754
3755Here are the forms of the @code{list} command most commonly used:
3756
3757@table @code
3758@item list @var{linenum}
3759Print lines centered around line number @var{linenum} in the
3760current source file.
3761
3762@item list @var{function}
3763Print lines centered around the beginning of function
3764@var{function}.
3765
3766@item list
3767Print more lines. If the last lines printed were printed with a
3768@code{list} command, this prints lines following the last lines
3769printed; however, if the last line printed was a solitary line printed
3770as part of displaying a stack frame (@pxref{Stack, ,Examining the
3771Stack}), this prints lines centered around that line.
3772
3773@item list -
3774Print lines just before the lines last printed.
3775@end table
3776
3777By default, @value{GDBN} prints ten source lines with any of these forms of
3778the @code{list} command. You can change this using @code{set listsize}:
3779
3780@table @code
3781@kindex set listsize
3782@item set listsize @var{count}
3783Make the @code{list} command display @var{count} source lines (unless
3784the @code{list} argument explicitly specifies some other number).
3785
3786@kindex show listsize
3787@item show listsize
3788Display the number of lines that @code{list} prints.
3789@end table
3790
3791Repeating a @code{list} command with @key{RET} discards the argument,
3792so it is equivalent to typing just @code{list}. This is more useful
3793than listing the same lines again. An exception is made for an
3794argument of @samp{-}; that argument is preserved in repetition so that
3795each repetition moves up in the source file.
3796
3797@cindex linespec
3798In general, the @code{list} command expects you to supply zero, one or two
3799@dfn{linespecs}. Linespecs specify source lines; there are several ways
d4f3574e 3800of writing them, but the effect is always to specify some source line.
c906108c
SS
3801Here is a complete description of the possible arguments for @code{list}:
3802
3803@table @code
3804@item list @var{linespec}
3805Print lines centered around the line specified by @var{linespec}.
3806
3807@item list @var{first},@var{last}
3808Print lines from @var{first} to @var{last}. Both arguments are
3809linespecs.
3810
3811@item list ,@var{last}
3812Print lines ending with @var{last}.
3813
3814@item list @var{first},
3815Print lines starting with @var{first}.
3816
3817@item list +
3818Print lines just after the lines last printed.
3819
3820@item list -
3821Print lines just before the lines last printed.
3822
3823@item list
3824As described in the preceding table.
3825@end table
3826
3827Here are the ways of specifying a single source line---all the
3828kinds of linespec.
3829
3830@table @code
3831@item @var{number}
3832Specifies line @var{number} of the current source file.
3833When a @code{list} command has two linespecs, this refers to
3834the same source file as the first linespec.
3835
3836@item +@var{offset}
3837Specifies the line @var{offset} lines after the last line printed.
3838When used as the second linespec in a @code{list} command that has
3839two, this specifies the line @var{offset} lines down from the
3840first linespec.
3841
3842@item -@var{offset}
3843Specifies the line @var{offset} lines before the last line printed.
3844
3845@item @var{filename}:@var{number}
3846Specifies line @var{number} in the source file @var{filename}.
3847
3848@item @var{function}
3849Specifies the line that begins the body of the function @var{function}.
3850For example: in C, this is the line with the open brace.
3851
3852@item @var{filename}:@var{function}
3853Specifies the line of the open-brace that begins the body of the
3854function @var{function} in the file @var{filename}. You only need the
3855file name with a function name to avoid ambiguity when there are
3856identically named functions in different source files.
3857
3858@item *@var{address}
3859Specifies the line containing the program address @var{address}.
3860@var{address} may be any expression.
3861@end table
3862
53a5351d 3863@node Search
c906108c
SS
3864@section Searching source files
3865@cindex searching
3866@kindex reverse-search
3867
3868There are two commands for searching through the current source file for a
3869regular expression.
3870
3871@table @code
3872@kindex search
3873@kindex forward-search
3874@item forward-search @var{regexp}
3875@itemx search @var{regexp}
3876The command @samp{forward-search @var{regexp}} checks each line,
3877starting with the one following the last line listed, for a match for
3878@var{regexp}. It lists the line that is found. You can use the
3879synonym @samp{search @var{regexp}} or abbreviate the command name as
3880@code{fo}.
3881
3882@item reverse-search @var{regexp}
3883The command @samp{reverse-search @var{regexp}} checks each line, starting
3884with the one before the last line listed and going backward, for a match
3885for @var{regexp}. It lists the line that is found. You can abbreviate
3886this command as @code{rev}.
3887@end table
c906108c 3888
53a5351d 3889@node Source Path
c906108c
SS
3890@section Specifying source directories
3891
3892@cindex source path
3893@cindex directories for source files
3894Executable programs sometimes do not record the directories of the source
3895files from which they were compiled, just the names. Even when they do,
3896the directories could be moved between the compilation and your debugging
3897session. @value{GDBN} has a list of directories to search for source files;
3898this is called the @dfn{source path}. Each time @value{GDBN} wants a source file,
3899it tries all the directories in the list, in the order they are present
3900in the list, until it finds a file with the desired name. Note that
3901the executable search path is @emph{not} used for this purpose. Neither is
3902the current working directory, unless it happens to be in the source
3903path.
3904
3905If @value{GDBN} cannot find a source file in the source path, and the
3906object program records a directory, @value{GDBN} tries that directory
3907too. If the source path is empty, and there is no record of the
3908compilation directory, @value{GDBN} looks in the current directory as a
3909last resort.
3910
3911Whenever you reset or rearrange the source path, @value{GDBN} clears out
3912any information it has cached about where source files are found and where
3913each line is in the file.
3914
3915@kindex directory
3916@kindex dir
d4f3574e
SS
3917When you start @value{GDBN}, its source path includes only @samp{cdir}
3918and @samp{cwd}, in that order.
c906108c
SS
3919To add other directories, use the @code{directory} command.
3920
3921@table @code
3922@item directory @var{dirname} @dots{}
3923@item dir @var{dirname} @dots{}
3924Add directory @var{dirname} to the front of the source path. Several
d4f3574e
SS
3925directory names may be given to this command, separated by @samp{:}
3926(@samp{;} on MS-DOS and MS-Windows, where @samp{:} usually appears as
3927part of absolute file names) or
c906108c
SS
3928whitespace. You may specify a directory that is already in the source
3929path; this moves it forward, so @value{GDBN} searches it sooner.
3930
3931@kindex cdir
3932@kindex cwd
3933@kindex $cdir
3934@kindex $cwd
3935@cindex compilation directory
3936@cindex current directory
3937@cindex working directory
3938@cindex directory, current
3939@cindex directory, compilation
3940You can use the string @samp{$cdir} to refer to the compilation
3941directory (if one is recorded), and @samp{$cwd} to refer to the current
3942working directory. @samp{$cwd} is not the same as @samp{.}---the former
3943tracks the current working directory as it changes during your @value{GDBN}
3944session, while the latter is immediately expanded to the current
3945directory at the time you add an entry to the source path.
3946
3947@item directory
3948Reset the source path to empty again. This requires confirmation.
3949
3950@c RET-repeat for @code{directory} is explicitly disabled, but since
3951@c repeating it would be a no-op we do not say that. (thanks to RMS)
3952
3953@item show directories
3954@kindex show directories
3955Print the source path: show which directories it contains.
3956@end table
3957
3958If your source path is cluttered with directories that are no longer of
3959interest, @value{GDBN} may sometimes cause confusion by finding the wrong
3960versions of source. You can correct the situation as follows:
3961
3962@enumerate
3963@item
3964Use @code{directory} with no argument to reset the source path to empty.
3965
3966@item
3967Use @code{directory} with suitable arguments to reinstall the
3968directories you want in the source path. You can add all the
3969directories in one command.
3970@end enumerate
3971
53a5351d 3972@node Machine Code
c906108c
SS
3973@section Source and machine code
3974
3975You can use the command @code{info line} to map source lines to program
3976addresses (and vice versa), and the command @code{disassemble} to display
3977a range of addresses as machine instructions. When run under @sc{gnu} Emacs
d4f3574e 3978mode, the @code{info line} command causes the arrow to point to the
c906108c
SS
3979line specified. Also, @code{info line} prints addresses in symbolic form as
3980well as hex.
3981
3982@table @code
3983@kindex info line
3984@item info line @var{linespec}
3985Print the starting and ending addresses of the compiled code for
3986source line @var{linespec}. You can specify source lines in any of
3987the ways understood by the @code{list} command (@pxref{List, ,Printing
3988source lines}).
3989@end table
3990
3991For example, we can use @code{info line} to discover the location of
3992the object code for the first line of function
3993@code{m4_changequote}:
3994
d4f3574e
SS
3995@c FIXME: I think this example should also show the addresses in
3996@c symbolic form, as they usually would be displayed.
c906108c
SS
3997@smallexample
3998(@value{GDBP}) info line m4_changecom
3999Line 895 of "builtin.c" starts at pc 0x634c and ends at 0x6350.
4000@end smallexample
4001
4002@noindent
4003We can also inquire (using @code{*@var{addr}} as the form for
4004@var{linespec}) what source line covers a particular address:
4005@smallexample
4006(@value{GDBP}) info line *0x63ff
4007Line 926 of "builtin.c" starts at pc 0x63e4 and ends at 0x6404.
4008@end smallexample
4009
4010@cindex @code{$_} and @code{info line}
d4f3574e 4011@kindex x@r{, and }@code{info line}
c906108c
SS
4012After @code{info line}, the default address for the @code{x} command
4013is changed to the starting address of the line, so that @samp{x/i} is
4014sufficient to begin examining the machine code (@pxref{Memory,
4015,Examining memory}). Also, this address is saved as the value of the
4016convenience variable @code{$_} (@pxref{Convenience Vars, ,Convenience
4017variables}).
4018
4019@table @code
4020@kindex disassemble
4021@cindex assembly instructions
4022@cindex instructions, assembly
4023@cindex machine instructions
4024@cindex listing machine instructions
4025@item disassemble
4026This specialized command dumps a range of memory as machine
4027instructions. The default memory range is the function surrounding the
4028program counter of the selected frame. A single argument to this
4029command is a program counter value; @value{GDBN} dumps the function
4030surrounding this value. Two arguments specify a range of addresses
4031(first inclusive, second exclusive) to dump.
4032@end table
4033
c906108c
SS
4034The following example shows the disassembly of a range of addresses of
4035HP PA-RISC 2.0 code:
4036
4037@smallexample
4038(@value{GDBP}) disas 0x32c4 0x32e4
4039Dump of assembler code from 0x32c4 to 0x32e4:
40400x32c4 <main+204>: addil 0,dp
40410x32c8 <main+208>: ldw 0x22c(sr0,r1),r26
40420x32cc <main+212>: ldil 0x3000,r31
40430x32d0 <main+216>: ble 0x3f8(sr4,r31)
40440x32d4 <main+220>: ldo 0(r31),rp
40450x32d8 <main+224>: addil -0x800,dp
40460x32dc <main+228>: ldo 0x588(r1),r26
40470x32e0 <main+232>: ldil 0x3000,r31
4048End of assembler dump.
4049@end smallexample
c906108c
SS
4050
4051Some architectures have more than one commonly-used set of instruction
4052mnemonics or other syntax.
4053
4054@table @code
d4f3574e 4055@kindex set disassembly-flavor
c906108c
SS
4056@cindex assembly instructions
4057@cindex instructions, assembly
4058@cindex machine instructions
4059@cindex listing machine instructions
d4f3574e
SS
4060@cindex Intel disassembly flavor
4061@cindex AT&T disassembly flavor
4062@item set disassembly-flavor @var{instruction-set}
c906108c
SS
4063Select the instruction set to use when disassembling the
4064program via the @code{disassemble} or @code{x/i} commands.
4065
4066Currently this command is only defined for the Intel x86 family. You
d4f3574e
SS
4067can set @var{instruction-set} to either @code{intel} or @code{att}.
4068The default is @code{att}, the AT&T flavor used by default by Unix
4069assemblers for x86-based targets.
c906108c
SS
4070@end table
4071
4072
53a5351d 4073@node Data
c906108c
SS
4074@chapter Examining Data
4075
4076@cindex printing data
4077@cindex examining data
4078@kindex print
4079@kindex inspect
4080@c "inspect" is not quite a synonym if you are using Epoch, which we do not
4081@c document because it is nonstandard... Under Epoch it displays in a
4082@c different window or something like that.
4083The usual way to examine data in your program is with the @code{print}
7a292a7a
SS
4084command (abbreviated @code{p}), or its synonym @code{inspect}. It
4085evaluates and prints the value of an expression of the language your
4086program is written in (@pxref{Languages, ,Using @value{GDBN} with
4087Different Languages}).
c906108c
SS
4088
4089@table @code
d4f3574e
SS
4090@item print @var{expr}
4091@itemx print /@var{f} @var{expr}
4092@var{expr} is an expression (in the source language). By default the
4093value of @var{expr} is printed in a format appropriate to its data type;
c906108c 4094you can choose a different format by specifying @samp{/@var{f}}, where
d4f3574e 4095@var{f} is a letter specifying the format; see @ref{Output Formats,,Output
c906108c
SS
4096formats}.
4097
4098@item print
4099@itemx print /@var{f}
d4f3574e 4100If you omit @var{expr}, @value{GDBN} displays the last value again (from the
c906108c
SS
4101@dfn{value history}; @pxref{Value History, ,Value history}). This allows you to
4102conveniently inspect the same value in an alternative format.
4103@end table
4104
4105A more low-level way of examining data is with the @code{x} command.
4106It examines data in memory at a specified address and prints it in a
4107specified format. @xref{Memory, ,Examining memory}.
4108
7a292a7a 4109If you are interested in information about types, or about how the
d4f3574e
SS
4110fields of a struct or a class are declared, use the @code{ptype @var{exp}}
4111command rather than @code{print}. @xref{Symbols, ,Examining the Symbol
7a292a7a 4112Table}.
c906108c
SS
4113
4114@menu
4115* Expressions:: Expressions
4116* Variables:: Program variables
4117* Arrays:: Artificial arrays
4118* Output Formats:: Output formats
4119* Memory:: Examining memory
4120* Auto Display:: Automatic display
4121* Print Settings:: Print settings
4122* Value History:: Value history
4123* Convenience Vars:: Convenience variables
4124* Registers:: Registers
c906108c 4125* Floating Point Hardware:: Floating point hardware
c906108c
SS
4126@end menu
4127
53a5351d 4128@node Expressions
c906108c
SS
4129@section Expressions
4130
4131@cindex expressions
4132@code{print} and many other @value{GDBN} commands accept an expression and
4133compute its value. Any kind of constant, variable or operator defined
4134by the programming language you are using is valid in an expression in
4135@value{GDBN}. This includes conditional expressions, function calls, casts
4136and string constants. It unfortunately does not include symbols defined
4137by preprocessor @code{#define} commands.
4138
d4f3574e
SS
4139@value{GDBN} supports array constants in expressions input by
4140the user. The syntax is @{@var{element}, @var{element}@dots{}@}. For example,
4141you can use the command @code{print @{1, 2, 3@}} to build up an array in
4142memory that is @code{malloc}ed in the target program.
c906108c 4143
c906108c
SS
4144Because C is so widespread, most of the expressions shown in examples in
4145this manual are in C. @xref{Languages, , Using @value{GDBN} with Different
4146Languages}, for information on how to use expressions in other
4147languages.
4148
4149In this section, we discuss operators that you can use in @value{GDBN}
4150expressions regardless of your programming language.
4151
4152Casts are supported in all languages, not just in C, because it is so
4153useful to cast a number into a pointer in order to examine a structure
4154at that address in memory.
4155@c FIXME: casts supported---Mod2 true?
c906108c
SS
4156
4157@value{GDBN} supports these operators, in addition to those common
4158to programming languages:
4159
4160@table @code
4161@item @@
4162@samp{@@} is a binary operator for treating parts of memory as arrays.
4163@xref{Arrays, ,Artificial arrays}, for more information.
4164
4165@item ::
4166@samp{::} allows you to specify a variable in terms of the file or
4167function where it is defined. @xref{Variables, ,Program variables}.
4168
4169@cindex @{@var{type}@}
4170@cindex type casting memory
4171@cindex memory, viewing as typed object
4172@cindex casts, to view memory
4173@item @{@var{type}@} @var{addr}
4174Refers to an object of type @var{type} stored at address @var{addr} in
4175memory. @var{addr} may be any expression whose value is an integer or
4176pointer (but parentheses are required around binary operators, just as in
4177a cast). This construct is allowed regardless of what kind of data is
4178normally supposed to reside at @var{addr}.
4179@end table
4180
53a5351d 4181@node Variables
c906108c
SS
4182@section Program variables
4183
4184The most common kind of expression to use is the name of a variable
4185in your program.
4186
4187Variables in expressions are understood in the selected stack frame
4188(@pxref{Selection, ,Selecting a frame}); they must be either:
4189
4190@itemize @bullet
4191@item
4192global (or file-static)
4193@end itemize
4194
4195@noindent or
4196
4197@itemize @bullet
4198@item
4199visible according to the scope rules of the
4200programming language from the point of execution in that frame
4201@end itemize
4202
4203@noindent This means that in the function
4204
4205@example
4206foo (a)
4207 int a;
4208@{
4209 bar (a);
4210 @{
4211 int b = test ();
4212 bar (b);
4213 @}
4214@}
4215@end example
4216
4217@noindent
4218you can examine and use the variable @code{a} whenever your program is
4219executing within the function @code{foo}, but you can only use or
4220examine the variable @code{b} while your program is executing inside
4221the block where @code{b} is declared.
4222
4223@cindex variable name conflict
4224There is an exception: you can refer to a variable or function whose
4225scope is a single source file even if the current execution point is not
4226in this file. But it is possible to have more than one such variable or
4227function with the same name (in different source files). If that
4228happens, referring to that name has unpredictable effects. If you wish,
4229you can specify a static variable in a particular function or file,
4230using the colon-colon notation:
4231
d4f3574e 4232@cindex colon-colon, context for variables/functions
c906108c
SS
4233@iftex
4234@c info cannot cope with a :: index entry, but why deprive hard copy readers?
4235@kindex ::
4236@end iftex
4237@example
4238@var{file}::@var{variable}
4239@var{function}::@var{variable}
4240@end example
4241
4242@noindent
4243Here @var{file} or @var{function} is the name of the context for the
4244static @var{variable}. In the case of file names, you can use quotes to
4245make sure @value{GDBN} parses the file name as a single word---for example,
4246to print a global value of @code{x} defined in @file{f2.c}:
4247
4248@example
4249(@value{GDBP}) p 'f2.c'::x
4250@end example
4251
c906108c
SS
4252@cindex C++ scope resolution
4253This use of @samp{::} is very rarely in conflict with the very similar
4254use of the same notation in C++. @value{GDBN} also supports use of the C++
4255scope resolution operator in @value{GDBN} expressions.
4256@c FIXME: Um, so what happens in one of those rare cases where it's in
4257@c conflict?? --mew
c906108c
SS
4258
4259@cindex wrong values
4260@cindex variable values, wrong
4261@quotation
4262@emph{Warning:} Occasionally, a local variable may appear to have the
4263wrong value at certain points in a function---just after entry to a new
4264scope, and just before exit.
4265@end quotation
4266You may see this problem when you are stepping by machine instructions.
4267This is because, on most machines, it takes more than one instruction to
4268set up a stack frame (including local variable definitions); if you are
4269stepping by machine instructions, variables may appear to have the wrong
4270values until the stack frame is completely built. On exit, it usually
4271also takes more than one machine instruction to destroy a stack frame;
4272after you begin stepping through that group of instructions, local
4273variable definitions may be gone.
4274
4275This may also happen when the compiler does significant optimizations.
4276To be sure of always seeing accurate values, turn off all optimization
4277when compiling.
4278
d4f3574e
SS
4279@cindex ``No symbol "foo" in current context''
4280Another possible effect of compiler optimizations is to optimize
4281unused variables out of existence, or assign variables to registers (as
4282opposed to memory addresses). Depending on the support for such cases
4283offered by the debug info format used by the compiler, @value{GDBN}
4284might not be able to display values for such local variables. If that
4285happens, @value{GDBN} will print a message like this:
4286
4287@example
4288No symbol "foo" in current context.
4289@end example
4290
4291To solve such problems, either recompile without optimizations, or use a
4292different debug info format, if the compiler supports several such
4293formats. For example, @value{NGCC}, the @sc{gnu} C/C++ compiler usually
4294supports the @samp{-gstabs} option. @samp{-gstabs} produces debug info
4295in a format that is superior to formats such as COFF. You may be able
4296to use DWARF-2 (@samp{-gdwarf-2}), which is also an effective form for
4297debug info. See @ref{Debugging Options,,Options for Debugging Your
4298Program or @sc{gnu} CC, gcc.info, Using @sc{gnu} CC}, for more
4299information.
4300
4301
53a5351d 4302@node Arrays
c906108c
SS
4303@section Artificial arrays
4304
4305@cindex artificial array
4306@kindex @@
4307It is often useful to print out several successive objects of the
4308same type in memory; a section of an array, or an array of
4309dynamically determined size for which only a pointer exists in the
4310program.
4311
4312You can do this by referring to a contiguous span of memory as an
4313@dfn{artificial array}, using the binary operator @samp{@@}. The left
4314operand of @samp{@@} should be the first element of the desired array
4315and be an individual object. The right operand should be the desired length
4316of the array. The result is an array value whose elements are all of
4317the type of the left argument. The first element is actually the left
4318argument; the second element comes from bytes of memory immediately
4319following those that hold the first element, and so on. Here is an
4320example. If a program says
4321
4322@example
4323int *array = (int *) malloc (len * sizeof (int));
4324@end example
4325
4326@noindent
4327you can print the contents of @code{array} with
4328
4329@example
4330p *array@@len
4331@end example
4332
4333The left operand of @samp{@@} must reside in memory. Array values made
4334with @samp{@@} in this way behave just like other arrays in terms of
4335subscripting, and are coerced to pointers when used in expressions.
4336Artificial arrays most often appear in expressions via the value history
4337(@pxref{Value History, ,Value history}), after printing one out.
4338
4339Another way to create an artificial array is to use a cast.
4340This re-interprets a value as if it were an array.
4341The value need not be in memory:
4342@example
4343(@value{GDBP}) p/x (short[2])0x12345678
4344$1 = @{0x1234, 0x5678@}
4345@end example
4346
4347As a convenience, if you leave the array length out (as in
c3f6f71d 4348@samp{(@var{type}[])@var{value}}) @value{GDBN} calculates the size to fill
c906108c
SS
4349the value (as @samp{sizeof(@var{value})/sizeof(@var{type})}:
4350@example
4351(@value{GDBP}) p/x (short[])0x12345678
4352$2 = @{0x1234, 0x5678@}
4353@end example
4354
4355Sometimes the artificial array mechanism is not quite enough; in
4356moderately complex data structures, the elements of interest may not
4357actually be adjacent---for example, if you are interested in the values
4358of pointers in an array. One useful work-around in this situation is
4359to use a convenience variable (@pxref{Convenience Vars, ,Convenience
4360variables}) as a counter in an expression that prints the first
4361interesting value, and then repeat that expression via @key{RET}. For
4362instance, suppose you have an array @code{dtab} of pointers to
4363structures, and you are interested in the values of a field @code{fv}
4364in each structure. Here is an example of what you might type:
4365
4366@example
4367set $i = 0
4368p dtab[$i++]->fv
4369@key{RET}
4370@key{RET}
4371@dots{}
4372@end example
4373
53a5351d 4374@node Output Formats
c906108c
SS
4375@section Output formats
4376
4377@cindex formatted output
4378@cindex output formats
4379By default, @value{GDBN} prints a value according to its data type. Sometimes
4380this is not what you want. For example, you might want to print a number
4381in hex, or a pointer in decimal. Or you might want to view data in memory
4382at a certain address as a character string or as an instruction. To do
4383these things, specify an @dfn{output format} when you print a value.
4384
4385The simplest use of output formats is to say how to print a value
4386already computed. This is done by starting the arguments of the
4387@code{print} command with a slash and a format letter. The format
4388letters supported are:
4389
4390@table @code
4391@item x
4392Regard the bits of the value as an integer, and print the integer in
4393hexadecimal.
4394
4395@item d
4396Print as integer in signed decimal.
4397
4398@item u
4399Print as integer in unsigned decimal.
4400
4401@item o
4402Print as integer in octal.
4403
4404@item t
4405Print as integer in binary. The letter @samp{t} stands for ``two''.
4406@footnote{@samp{b} cannot be used because these format letters are also
4407used with the @code{x} command, where @samp{b} stands for ``byte'';
d4f3574e 4408see @ref{Memory,,Examining memory}.}
c906108c
SS
4409
4410@item a
4411@cindex unknown address, locating
4412Print as an address, both absolute in hexadecimal and as an offset from
4413the nearest preceding symbol. You can use this format used to discover
4414where (in what function) an unknown address is located:
4415
4416@example
4417(@value{GDBP}) p/a 0x54320
4418$3 = 0x54320 <_initialize_vx+396>
4419@end example
4420
4421@item c
4422Regard as an integer and print it as a character constant.
4423
4424@item f
4425Regard the bits of the value as a floating point number and print
4426using typical floating point syntax.
4427@end table
4428
4429For example, to print the program counter in hex (@pxref{Registers}), type
4430
4431@example
4432p/x $pc
4433@end example
4434
4435@noindent
4436Note that no space is required before the slash; this is because command
4437names in @value{GDBN} cannot contain a slash.
4438
4439To reprint the last value in the value history with a different format,
4440you can use the @code{print} command with just a format and no
4441expression. For example, @samp{p/x} reprints the last value in hex.
4442
53a5351d 4443@node Memory
c906108c
SS
4444@section Examining memory
4445
4446You can use the command @code{x} (for ``examine'') to examine memory in
4447any of several formats, independently of your program's data types.
4448
4449@cindex examining memory
4450@table @code
4451@kindex x
4452@item x/@var{nfu} @var{addr}
4453@itemx x @var{addr}
4454@itemx x
4455Use the @code{x} command to examine memory.
4456@end table
4457
4458@var{n}, @var{f}, and @var{u} are all optional parameters that specify how
4459much memory to display and how to format it; @var{addr} is an
4460expression giving the address where you want to start displaying memory.
4461If you use defaults for @var{nfu}, you need not type the slash @samp{/}.
4462Several commands set convenient defaults for @var{addr}.
4463
4464@table @r
4465@item @var{n}, the repeat count
4466The repeat count is a decimal integer; the default is 1. It specifies
4467how much memory (counting by units @var{u}) to display.
4468@c This really is **decimal**; unaffected by 'set radix' as of GDB
4469@c 4.1.2.
4470
4471@item @var{f}, the display format
4472The display format is one of the formats used by @code{print},
4473@samp{s} (null-terminated string), or @samp{i} (machine instruction).
4474The default is @samp{x} (hexadecimal) initially.
4475The default changes each time you use either @code{x} or @code{print}.
4476
4477@item @var{u}, the unit size
4478The unit size is any of
4479
4480@table @code
4481@item b
4482Bytes.
4483@item h
4484Halfwords (two bytes).
4485@item w
4486Words (four bytes). This is the initial default.
4487@item g
4488Giant words (eight bytes).
4489@end table
4490
4491Each time you specify a unit size with @code{x}, that size becomes the
4492default unit the next time you use @code{x}. (For the @samp{s} and
4493@samp{i} formats, the unit size is ignored and is normally not written.)
4494
4495@item @var{addr}, starting display address
4496@var{addr} is the address where you want @value{GDBN} to begin displaying
4497memory. The expression need not have a pointer value (though it may);
4498it is always interpreted as an integer address of a byte of memory.
4499@xref{Expressions, ,Expressions}, for more information on expressions. The default for
4500@var{addr} is usually just after the last address examined---but several
4501other commands also set the default address: @code{info breakpoints} (to
4502the address of the last breakpoint listed), @code{info line} (to the
4503starting address of a line), and @code{print} (if you use it to display
4504a value from memory).
4505@end table
4506
4507For example, @samp{x/3uh 0x54320} is a request to display three halfwords
4508(@code{h}) of memory, formatted as unsigned decimal integers (@samp{u}),
4509starting at address @code{0x54320}. @samp{x/4xw $sp} prints the four
4510words (@samp{w}) of memory above the stack pointer (here, @samp{$sp};
d4f3574e 4511@pxref{Registers, ,Registers}) in hexadecimal (@samp{x}).
c906108c
SS
4512
4513Since the letters indicating unit sizes are all distinct from the
4514letters specifying output formats, you do not have to remember whether
4515unit size or format comes first; either order works. The output
4516specifications @samp{4xw} and @samp{4wx} mean exactly the same thing.
4517(However, the count @var{n} must come first; @samp{wx4} does not work.)
4518
4519Even though the unit size @var{u} is ignored for the formats @samp{s}
4520and @samp{i}, you might still want to use a count @var{n}; for example,
4521@samp{3i} specifies that you want to see three machine instructions,
4522including any operands. The command @code{disassemble} gives an
d4f3574e 4523alternative way of inspecting machine instructions; see @ref{Machine
c906108c
SS
4524Code,,Source and machine code}.
4525
4526All the defaults for the arguments to @code{x} are designed to make it
4527easy to continue scanning memory with minimal specifications each time
4528you use @code{x}. For example, after you have inspected three machine
4529instructions with @samp{x/3i @var{addr}}, you can inspect the next seven
4530with just @samp{x/7}. If you use @key{RET} to repeat the @code{x} command,
4531the repeat count @var{n} is used again; the other arguments default as
4532for successive uses of @code{x}.
4533
4534@cindex @code{$_}, @code{$__}, and value history
4535The addresses and contents printed by the @code{x} command are not saved
4536in the value history because there is often too much of them and they
4537would get in the way. Instead, @value{GDBN} makes these values available for
4538subsequent use in expressions as values of the convenience variables
4539@code{$_} and @code{$__}. After an @code{x} command, the last address
4540examined is available for use in expressions in the convenience variable
4541@code{$_}. The contents of that address, as examined, are available in
4542the convenience variable @code{$__}.
4543
4544If the @code{x} command has a repeat count, the address and contents saved
4545are from the last memory unit printed; this is not the same as the last
4546address printed if several units were printed on the last line of output.
4547
53a5351d 4548@node Auto Display
c906108c
SS
4549@section Automatic display
4550@cindex automatic display
4551@cindex display of expressions
4552
4553If you find that you want to print the value of an expression frequently
4554(to see how it changes), you might want to add it to the @dfn{automatic
4555display list} so that @value{GDBN} prints its value each time your program stops.
4556Each expression added to the list is given a number to identify it;
4557to remove an expression from the list, you specify that number.
4558The automatic display looks like this:
4559
4560@example
45612: foo = 38
45623: bar[5] = (struct hack *) 0x3804
4563@end example
4564
4565@noindent
4566This display shows item numbers, expressions and their current values. As with
4567displays you request manually using @code{x} or @code{print}, you can
4568specify the output format you prefer; in fact, @code{display} decides
4569whether to use @code{print} or @code{x} depending on how elaborate your
4570format specification is---it uses @code{x} if you specify a unit size,
4571or one of the two formats (@samp{i} and @samp{s}) that are only
4572supported by @code{x}; otherwise it uses @code{print}.
4573
4574@table @code
4575@kindex display
d4f3574e
SS
4576@item display @var{expr}
4577Add the expression @var{expr} to the list of expressions to display
c906108c
SS
4578each time your program stops. @xref{Expressions, ,Expressions}.
4579
4580@code{display} does not repeat if you press @key{RET} again after using it.
4581
d4f3574e 4582@item display/@var{fmt} @var{expr}
c906108c 4583For @var{fmt} specifying only a display format and not a size or
d4f3574e 4584count, add the expression @var{expr} to the auto-display list but
c906108c
SS
4585arrange to display it each time in the specified format @var{fmt}.
4586@xref{Output Formats,,Output formats}.
4587
4588@item display/@var{fmt} @var{addr}
4589For @var{fmt} @samp{i} or @samp{s}, or including a unit-size or a
4590number of units, add the expression @var{addr} as a memory address to
4591be examined each time your program stops. Examining means in effect
4592doing @samp{x/@var{fmt} @var{addr}}. @xref{Memory, ,Examining memory}.
4593@end table
4594
4595For example, @samp{display/i $pc} can be helpful, to see the machine
4596instruction about to be executed each time execution stops (@samp{$pc}
d4f3574e 4597is a common name for the program counter; @pxref{Registers, ,Registers}).
c906108c
SS
4598
4599@table @code
4600@kindex delete display
4601@kindex undisplay
4602@item undisplay @var{dnums}@dots{}
4603@itemx delete display @var{dnums}@dots{}
4604Remove item numbers @var{dnums} from the list of expressions to display.
4605
4606@code{undisplay} does not repeat if you press @key{RET} after using it.
4607(Otherwise you would just get the error @samp{No display number @dots{}}.)
4608
4609@kindex disable display
4610@item disable display @var{dnums}@dots{}
4611Disable the display of item numbers @var{dnums}. A disabled display
4612item is not printed automatically, but is not forgotten. It may be
4613enabled again later.
4614
4615@kindex enable display
4616@item enable display @var{dnums}@dots{}
4617Enable display of item numbers @var{dnums}. It becomes effective once
4618again in auto display of its expression, until you specify otherwise.
4619
4620@item display
4621Display the current values of the expressions on the list, just as is
4622done when your program stops.
4623
4624@kindex info display
4625@item info display
4626Print the list of expressions previously set up to display
4627automatically, each one with its item number, but without showing the
4628values. This includes disabled expressions, which are marked as such.
4629It also includes expressions which would not be displayed right now
4630because they refer to automatic variables not currently available.
4631@end table
4632
4633If a display expression refers to local variables, then it does not make
4634sense outside the lexical context for which it was set up. Such an
4635expression is disabled when execution enters a context where one of its
4636variables is not defined. For example, if you give the command
4637@code{display last_char} while inside a function with an argument
4638@code{last_char}, @value{GDBN} displays this argument while your program
4639continues to stop inside that function. When it stops elsewhere---where
4640there is no variable @code{last_char}---the display is disabled
4641automatically. The next time your program stops where @code{last_char}
4642is meaningful, you can enable the display expression once again.
4643
53a5351d 4644@node Print Settings
c906108c
SS
4645@section Print settings
4646
4647@cindex format options
4648@cindex print settings
4649@value{GDBN} provides the following ways to control how arrays, structures,
4650and symbols are printed.
4651
4652@noindent
4653These settings are useful for debugging programs in any language:
4654
4655@table @code
4656@kindex set print address
4657@item set print address
4658@itemx set print address on
4659@value{GDBN} prints memory addresses showing the location of stack
4660traces, structure values, pointer values, breakpoints, and so forth,
4661even when it also displays the contents of those addresses. The default
4662is @code{on}. For example, this is what a stack frame display looks like with
4663@code{set print address on}:
4664
4665@smallexample
4666@group
4667(@value{GDBP}) f
4668#0 set_quotes (lq=0x34c78 "<<", rq=0x34c88 ">>")
4669 at input.c:530
4670530 if (lquote != def_lquote)
4671@end group
4672@end smallexample
4673
4674@item set print address off
4675Do not print addresses when displaying their contents. For example,
4676this is the same stack frame displayed with @code{set print address off}:
4677
4678@smallexample
4679@group
4680(@value{GDBP}) set print addr off
4681(@value{GDBP}) f
4682#0 set_quotes (lq="<<", rq=">>") at input.c:530
4683530 if (lquote != def_lquote)
4684@end group
4685@end smallexample
4686
4687You can use @samp{set print address off} to eliminate all machine
4688dependent displays from the @value{GDBN} interface. For example, with
4689@code{print address off}, you should get the same text for backtraces on
4690all machines---whether or not they involve pointer arguments.
4691
4692@kindex show print address
4693@item show print address
4694Show whether or not addresses are to be printed.
4695@end table
4696
4697When @value{GDBN} prints a symbolic address, it normally prints the
4698closest earlier symbol plus an offset. If that symbol does not uniquely
4699identify the address (for example, it is a name whose scope is a single
4700source file), you may need to clarify. One way to do this is with
4701@code{info line}, for example @samp{info line *0x4537}. Alternately,
4702you can set @value{GDBN} to print the source file and line number when
4703it prints a symbolic address:
4704
4705@table @code
4706@kindex set print symbol-filename
4707@item set print symbol-filename on
4708Tell @value{GDBN} to print the source file name and line number of a
4709symbol in the symbolic form of an address.
4710
4711@item set print symbol-filename off
4712Do not print source file name and line number of a symbol. This is the
4713default.
4714
4715@kindex show print symbol-filename
4716@item show print symbol-filename
4717Show whether or not @value{GDBN} will print the source file name and
4718line number of a symbol in the symbolic form of an address.
4719@end table
4720
4721Another situation where it is helpful to show symbol filenames and line
4722numbers is when disassembling code; @value{GDBN} shows you the line
4723number and source file that corresponds to each instruction.
4724
4725Also, you may wish to see the symbolic form only if the address being
4726printed is reasonably close to the closest earlier symbol:
4727
4728@table @code
4729@kindex set print max-symbolic-offset
4730@item set print max-symbolic-offset @var{max-offset}
4731Tell @value{GDBN} to only display the symbolic form of an address if the
4732offset between the closest earlier symbol and the address is less than
4733@var{max-offset}. The default is 0, which tells @value{GDBN}
4734to always print the symbolic form of an address if any symbol precedes it.
4735
4736@kindex show print max-symbolic-offset
4737@item show print max-symbolic-offset
4738Ask how large the maximum offset is that @value{GDBN} prints in a
4739symbolic address.
4740@end table
4741
4742@cindex wild pointer, interpreting
4743@cindex pointer, finding referent
4744If you have a pointer and you are not sure where it points, try
4745@samp{set print symbol-filename on}. Then you can determine the name
4746and source file location of the variable where it points, using
4747@samp{p/a @var{pointer}}. This interprets the address in symbolic form.
4748For example, here @value{GDBN} shows that a variable @code{ptt} points
4749at another variable @code{t}, defined in @file{hi2.c}:
4750
4751@example
4752(@value{GDBP}) set print symbol-filename on
4753(@value{GDBP}) p/a ptt
4754$4 = 0xe008 <t in hi2.c>
4755@end example
4756
4757@quotation
4758@emph{Warning:} For pointers that point to a local variable, @samp{p/a}
4759does not show the symbol name and filename of the referent, even with
4760the appropriate @code{set print} options turned on.
4761@end quotation
4762
4763Other settings control how different kinds of objects are printed:
4764
4765@table @code
4766@kindex set print array
4767@item set print array
4768@itemx set print array on
4769Pretty print arrays. This format is more convenient to read,
4770but uses more space. The default is off.
4771
4772@item set print array off
4773Return to compressed format for arrays.
4774
4775@kindex show print array
4776@item show print array
4777Show whether compressed or pretty format is selected for displaying
4778arrays.
4779
4780@kindex set print elements
4781@item set print elements @var{number-of-elements}
4782Set a limit on how many elements of an array @value{GDBN} will print.
4783If @value{GDBN} is printing a large array, it stops printing after it has
4784printed the number of elements set by the @code{set print elements} command.
4785This limit also applies to the display of strings.
d4f3574e 4786When @value{GDBN} starts, this limit is set to 200.
c906108c
SS
4787Setting @var{number-of-elements} to zero means that the printing is unlimited.
4788
4789@kindex show print elements
4790@item show print elements
4791Display the number of elements of a large array that @value{GDBN} will print.
4792If the number is 0, then the printing is unlimited.
4793
4794@kindex set print null-stop
4795@item set print null-stop
4796Cause @value{GDBN} to stop printing the characters of an array when the first
d4f3574e 4797@sc{null} is encountered. This is useful when large arrays actually
c906108c 4798contain only short strings.
d4f3574e 4799The default is off.
c906108c
SS
4800
4801@kindex set print pretty
4802@item set print pretty on
4803Cause @value{GDBN} to print structures in an indented format with one member
4804per line, like this:
4805
4806@smallexample
4807@group
4808$1 = @{
4809 next = 0x0,
4810 flags = @{
4811 sweet = 1,
4812 sour = 1
4813 @},
4814 meat = 0x54 "Pork"
4815@}
4816@end group
4817@end smallexample
4818
4819@item set print pretty off
4820Cause @value{GDBN} to print structures in a compact format, like this:
4821
4822@smallexample
4823@group
4824$1 = @{next = 0x0, flags = @{sweet = 1, sour = 1@}, \
4825meat = 0x54 "Pork"@}
4826@end group
4827@end smallexample
4828
4829@noindent
4830This is the default format.
4831
4832@kindex show print pretty
4833@item show print pretty
4834Show which format @value{GDBN} is using to print structures.
4835
4836@kindex set print sevenbit-strings
4837@item set print sevenbit-strings on
4838Print using only seven-bit characters; if this option is set,
4839@value{GDBN} displays any eight-bit characters (in strings or
4840character values) using the notation @code{\}@var{nnn}. This setting is
4841best if you are working in English (@sc{ascii}) and you use the
4842high-order bit of characters as a marker or ``meta'' bit.
4843
4844@item set print sevenbit-strings off
4845Print full eight-bit characters. This allows the use of more
4846international character sets, and is the default.
4847
4848@kindex show print sevenbit-strings
4849@item show print sevenbit-strings
4850Show whether or not @value{GDBN} is printing only seven-bit characters.
4851
4852@kindex set print union
4853@item set print union on
4854Tell @value{GDBN} to print unions which are contained in structures. This
4855is the default setting.
4856
4857@item set print union off
4858Tell @value{GDBN} not to print unions which are contained in structures.
4859
4860@kindex show print union
4861@item show print union
4862Ask @value{GDBN} whether or not it will print unions which are contained in
4863structures.
4864
4865For example, given the declarations
4866
4867@smallexample
4868typedef enum @{Tree, Bug@} Species;
4869typedef enum @{Big_tree, Acorn, Seedling@} Tree_forms;
4870typedef enum @{Caterpillar, Cocoon, Butterfly@}
4871 Bug_forms;
4872
4873struct thing @{
4874 Species it;
4875 union @{
4876 Tree_forms tree;
4877 Bug_forms bug;
4878 @} form;
4879@};
4880
4881struct thing foo = @{Tree, @{Acorn@}@};
4882@end smallexample
4883
4884@noindent
4885with @code{set print union on} in effect @samp{p foo} would print
4886
4887@smallexample
4888$1 = @{it = Tree, form = @{tree = Acorn, bug = Cocoon@}@}
4889@end smallexample
4890
4891@noindent
4892and with @code{set print union off} in effect it would print
4893
4894@smallexample
4895$1 = @{it = Tree, form = @{...@}@}
4896@end smallexample
4897@end table
4898
c906108c
SS
4899@need 1000
4900@noindent
4901These settings are of interest when debugging C++ programs:
4902
4903@table @code
4904@cindex demangling
4905@kindex set print demangle
4906@item set print demangle
4907@itemx set print demangle on
4908Print C++ names in their source form rather than in the encoded
4909(``mangled'') form passed to the assembler and linker for type-safe
d4f3574e 4910linkage. The default is on.
c906108c
SS
4911
4912@kindex show print demangle
4913@item show print demangle
4914Show whether C++ names are printed in mangled or demangled form.
4915
4916@kindex set print asm-demangle
4917@item set print asm-demangle
4918@itemx set print asm-demangle on
4919Print C++ names in their source form rather than their mangled form, even
4920in assembler code printouts such as instruction disassemblies.
4921The default is off.
4922
4923@kindex show print asm-demangle
4924@item show print asm-demangle
4925Show whether C++ names in assembly listings are printed in mangled
4926or demangled form.
4927
4928@kindex set demangle-style
4929@cindex C++ symbol decoding style
4930@cindex symbol decoding style, C++
4931@item set demangle-style @var{style}
4932Choose among several encoding schemes used by different compilers to
4933represent C++ names. The choices for @var{style} are currently:
4934
4935@table @code
4936@item auto
4937Allow @value{GDBN} to choose a decoding style by inspecting your program.
4938
4939@item gnu
4940Decode based on the @sc{gnu} C++ compiler (@code{g++}) encoding algorithm.
c906108c 4941This is the default.
c906108c
SS
4942
4943@item hp
4944Decode based on the HP ANSI C++ (@code{aCC}) encoding algorithm.
4945
4946@item lucid
4947Decode based on the Lucid C++ compiler (@code{lcc}) encoding algorithm.
4948
4949@item arm
4950Decode using the algorithm in the @cite{C++ Annotated Reference Manual}.
4951@strong{Warning:} this setting alone is not sufficient to allow
4952debugging @code{cfront}-generated executables. @value{GDBN} would
4953require further enhancement to permit that.
4954
4955@end table
4956If you omit @var{style}, you will see a list of possible formats.
4957
4958@kindex show demangle-style
4959@item show demangle-style
4960Display the encoding style currently in use for decoding C++ symbols.
4961
4962@kindex set print object
4963@item set print object
4964@itemx set print object on
4965When displaying a pointer to an object, identify the @emph{actual}
4966(derived) type of the object rather than the @emph{declared} type, using
4967the virtual function table.
4968
4969@item set print object off
4970Display only the declared type of objects, without reference to the
4971virtual function table. This is the default setting.
4972
4973@kindex show print object
4974@item show print object
4975Show whether actual, or declared, object types are displayed.
4976
4977@kindex set print static-members
4978@item set print static-members
4979@itemx set print static-members on
4980Print static members when displaying a C++ object. The default is on.
4981
4982@item set print static-members off
4983Do not print static members when displaying a C++ object.
4984
4985@kindex show print static-members
4986@item show print static-members
4987Show whether C++ static members are printed, or not.
4988
4989@c These don't work with HP ANSI C++ yet.
4990@kindex set print vtbl
4991@item set print vtbl
4992@itemx set print vtbl on
4993Pretty print C++ virtual function tables. The default is off.
c906108c
SS
4994(The @code{vtbl} commands do not work on programs compiled with the HP
4995ANSI C++ compiler (@code{aCC}).)
c906108c
SS
4996
4997@item set print vtbl off
4998Do not pretty print C++ virtual function tables.
4999
5000@kindex show print vtbl
5001@item show print vtbl
5002Show whether C++ virtual function tables are pretty printed, or not.
5003@end table
c906108c 5004
53a5351d 5005@node Value History
c906108c
SS
5006@section Value history
5007
5008@cindex value history
5009Values printed by the @code{print} command are saved in the @value{GDBN}
5010@dfn{value history}. This allows you to refer to them in other expressions.
5011Values are kept until the symbol table is re-read or discarded
5012(for example with the @code{file} or @code{symbol-file} commands).
5013When the symbol table changes, the value history is discarded,
5014since the values may contain pointers back to the types defined in the
5015symbol table.
5016
5017@cindex @code{$}
5018@cindex @code{$$}
5019@cindex history number
5020The values printed are given @dfn{history numbers} by which you can
5021refer to them. These are successive integers starting with one.
5022@code{print} shows you the history number assigned to a value by
5023printing @samp{$@var{num} = } before the value; here @var{num} is the
5024history number.
5025
5026To refer to any previous value, use @samp{$} followed by the value's
5027history number. The way @code{print} labels its output is designed to
5028remind you of this. Just @code{$} refers to the most recent value in
5029the history, and @code{$$} refers to the value before that.
5030@code{$$@var{n}} refers to the @var{n}th value from the end; @code{$$2}
5031is the value just prior to @code{$$}, @code{$$1} is equivalent to
5032@code{$$}, and @code{$$0} is equivalent to @code{$}.
5033
5034For example, suppose you have just printed a pointer to a structure and
5035want to see the contents of the structure. It suffices to type
5036
5037@example
5038p *$
5039@end example
5040
5041If you have a chain of structures where the component @code{next} points
5042to the next one, you can print the contents of the next one with this:
5043
5044@example
5045p *$.next
5046@end example
5047
5048@noindent
5049You can print successive links in the chain by repeating this
5050command---which you can do by just typing @key{RET}.
5051
5052Note that the history records values, not expressions. If the value of
5053@code{x} is 4 and you type these commands:
5054
5055@example
5056print x
5057set x=5
5058@end example
5059
5060@noindent
5061then the value recorded in the value history by the @code{print} command
5062remains 4 even though the value of @code{x} has changed.
5063
5064@table @code
5065@kindex show values
5066@item show values
5067Print the last ten values in the value history, with their item numbers.
5068This is like @samp{p@ $$9} repeated ten times, except that @code{show
5069values} does not change the history.
5070
5071@item show values @var{n}
5072Print ten history values centered on history item number @var{n}.
5073
5074@item show values +
5075Print ten history values just after the values last printed. If no more
5076values are available, @code{show values +} produces no display.
5077@end table
5078
5079Pressing @key{RET} to repeat @code{show values @var{n}} has exactly the
5080same effect as @samp{show values +}.
5081
53a5351d 5082@node Convenience Vars
c906108c
SS
5083@section Convenience variables
5084
5085@cindex convenience variables
5086@value{GDBN} provides @dfn{convenience variables} that you can use within
5087@value{GDBN} to hold on to a value and refer to it later. These variables
5088exist entirely within @value{GDBN}; they are not part of your program, and
5089setting a convenience variable has no direct effect on further execution
5090of your program. That is why you can use them freely.
5091
5092Convenience variables are prefixed with @samp{$}. Any name preceded by
5093@samp{$} can be used for a convenience variable, unless it is one of
d4f3574e 5094the predefined machine-specific register names (@pxref{Registers, ,Registers}).
c906108c
SS
5095(Value history references, in contrast, are @emph{numbers} preceded
5096by @samp{$}. @xref{Value History, ,Value history}.)
5097
5098You can save a value in a convenience variable with an assignment
5099expression, just as you would set a variable in your program.
5100For example:
5101
5102@example
5103set $foo = *object_ptr
5104@end example
5105
5106@noindent
5107would save in @code{$foo} the value contained in the object pointed to by
5108@code{object_ptr}.
5109
5110Using a convenience variable for the first time creates it, but its
5111value is @code{void} until you assign a new value. You can alter the
5112value with another assignment at any time.
5113
5114Convenience variables have no fixed types. You can assign a convenience
5115variable any type of value, including structures and arrays, even if
5116that variable already has a value of a different type. The convenience
5117variable, when used as an expression, has the type of its current value.
5118
5119@table @code
5120@kindex show convenience
5121@item show convenience
5122Print a list of convenience variables used so far, and their values.
d4f3574e 5123Abbreviated @code{show conv}.
c906108c
SS
5124@end table
5125
5126One of the ways to use a convenience variable is as a counter to be
5127incremented or a pointer to be advanced. For example, to print
5128a field from successive elements of an array of structures:
5129
5130@example
5131set $i = 0
5132print bar[$i++]->contents
5133@end example
5134
d4f3574e
SS
5135@noindent
5136Repeat that command by typing @key{RET}.
c906108c
SS
5137
5138Some convenience variables are created automatically by @value{GDBN} and given
5139values likely to be useful.
5140
5141@table @code
5142@kindex $_
5143@item $_
5144The variable @code{$_} is automatically set by the @code{x} command to
5145the last address examined (@pxref{Memory, ,Examining memory}). Other
5146commands which provide a default address for @code{x} to examine also
5147set @code{$_} to that address; these commands include @code{info line}
5148and @code{info breakpoint}. The type of @code{$_} is @code{void *}
5149except when set by the @code{x} command, in which case it is a pointer
5150to the type of @code{$__}.
5151
5152@kindex $__
5153@item $__
5154The variable @code{$__} is automatically set by the @code{x} command
5155to the value found in the last address examined. Its type is chosen
5156to match the format in which the data was printed.
5157
5158@item $_exitcode
5159@kindex $_exitcode
5160The variable @code{$_exitcode} is automatically set to the exit code when
5161the program being debugged terminates.
5162@end table
5163
53a5351d
JM
5164On HP-UX systems, if you refer to a function or variable name that
5165begins with a dollar sign, @value{GDBN} searches for a user or system
5166name first, before it searches for a convenience variable.
c906108c 5167
53a5351d 5168@node Registers
c906108c
SS
5169@section Registers
5170
5171@cindex registers
5172You can refer to machine register contents, in expressions, as variables
5173with names starting with @samp{$}. The names of registers are different
5174for each machine; use @code{info registers} to see the names used on
5175your machine.
5176
5177@table @code
5178@kindex info registers
5179@item info registers
5180Print the names and values of all registers except floating-point
5181registers (in the selected stack frame).
5182
5183@kindex info all-registers
5184@cindex floating point registers
5185@item info all-registers
5186Print the names and values of all registers, including floating-point
5187registers.
5188
5189@item info registers @var{regname} @dots{}
5190Print the @dfn{relativized} value of each specified register @var{regname}.
5191As discussed in detail below, register values are normally relative to
5192the selected stack frame. @var{regname} may be any register name valid on
5193the machine you are using, with or without the initial @samp{$}.
5194@end table
5195
5196@value{GDBN} has four ``standard'' register names that are available (in
5197expressions) on most machines---whenever they do not conflict with an
5198architecture's canonical mnemonics for registers. The register names
5199@code{$pc} and @code{$sp} are used for the program counter register and
5200the stack pointer. @code{$fp} is used for a register that contains a
5201pointer to the current stack frame, and @code{$ps} is used for a
5202register that contains the processor status. For example,
5203you could print the program counter in hex with
5204
5205@example
5206p/x $pc
5207@end example
5208
5209@noindent
5210or print the instruction to be executed next with
5211
5212@example
5213x/i $pc
5214@end example
5215
5216@noindent
5217or add four to the stack pointer@footnote{This is a way of removing
5218one word from the stack, on machines where stacks grow downward in
5219memory (most machines, nowadays). This assumes that the innermost
5220stack frame is selected; setting @code{$sp} is not allowed when other
5221stack frames are selected. To pop entire frames off the stack,
5222regardless of machine architecture, use @code{return};
d4f3574e 5223see @ref{Returning, ,Returning from a function}.} with
c906108c
SS
5224
5225@example
5226set $sp += 4
5227@end example
5228
5229Whenever possible, these four standard register names are available on
5230your machine even though the machine has different canonical mnemonics,
5231so long as there is no conflict. The @code{info registers} command
5232shows the canonical names. For example, on the SPARC, @code{info
5233registers} displays the processor status register as @code{$psr} but you
d4f3574e
SS
5234can also refer to it as @code{$ps}; and on x86-based machines @code{$ps}
5235is an alias for the @sc{eflags} register.
c906108c
SS
5236
5237@value{GDBN} always considers the contents of an ordinary register as an
5238integer when the register is examined in this way. Some machines have
5239special registers which can hold nothing but floating point; these
5240registers are considered to have floating point values. There is no way
5241to refer to the contents of an ordinary register as floating point value
5242(although you can @emph{print} it as a floating point value with
5243@samp{print/f $@var{regname}}).
5244
5245Some registers have distinct ``raw'' and ``virtual'' data formats. This
5246means that the data format in which the register contents are saved by
5247the operating system is not the same one that your program normally
5248sees. For example, the registers of the 68881 floating point
5249coprocessor are always saved in ``extended'' (raw) format, but all C
5250programs expect to work with ``double'' (virtual) format. In such
5251cases, @value{GDBN} normally works with the virtual format only (the format
5252that makes sense for your program), but the @code{info registers} command
5253prints the data in both formats.
5254
5255Normally, register values are relative to the selected stack frame
5256(@pxref{Selection, ,Selecting a frame}). This means that you get the
5257value that the register would contain if all stack frames farther in
5258were exited and their saved registers restored. In order to see the
5259true contents of hardware registers, you must select the innermost
5260frame (with @samp{frame 0}).
5261
5262However, @value{GDBN} must deduce where registers are saved, from the machine
5263code generated by your compiler. If some registers are not saved, or if
5264@value{GDBN} is unable to locate the saved registers, the selected stack
5265frame makes no difference.
5266
53a5351d 5267@node Floating Point Hardware
c906108c
SS
5268@section Floating point hardware
5269@cindex floating point
5270
5271Depending on the configuration, @value{GDBN} may be able to give
5272you more information about the status of the floating point hardware.
5273
5274@table @code
5275@kindex info float
5276@item info float
5277Display hardware-dependent information about the floating
5278point unit. The exact contents and layout vary depending on the
5279floating point chip. Currently, @samp{info float} is supported on
5280the ARM and x86 machines.
5281@end table
c906108c 5282
53a5351d 5283@node Languages
c906108c
SS
5284@chapter Using @value{GDBN} with Different Languages
5285@cindex languages
5286
c906108c
SS
5287Although programming languages generally have common aspects, they are
5288rarely expressed in the same manner. For instance, in ANSI C,
5289dereferencing a pointer @code{p} is accomplished by @code{*p}, but in
5290Modula-2, it is accomplished by @code{p^}. Values can also be
5291represented (and displayed) differently. Hex numbers in C appear as
5292@samp{0x1ae}, while in Modula-2 they appear as @samp{1AEH}.
c906108c
SS
5293
5294@cindex working language
5295Language-specific information is built into @value{GDBN} for some languages,
5296allowing you to express operations like the above in your program's
5297native language, and allowing @value{GDBN} to output values in a manner
5298consistent with the syntax of your program's native language. The
5299language you use to build expressions is called the @dfn{working
5300language}.
5301
5302@menu
5303* Setting:: Switching between source languages
5304* Show:: Displaying the language
c906108c 5305* Checks:: Type and range checks
c906108c
SS
5306* Support:: Supported languages
5307@end menu
5308
53a5351d 5309@node Setting
c906108c
SS
5310@section Switching between source languages
5311
5312There are two ways to control the working language---either have @value{GDBN}
5313set it automatically, or select it manually yourself. You can use the
5314@code{set language} command for either purpose. On startup, @value{GDBN}
5315defaults to setting the language automatically. The working language is
5316used to determine how expressions you type are interpreted, how values
5317are printed, etc.
5318
5319In addition to the working language, every source file that
5320@value{GDBN} knows about has its own working language. For some object
5321file formats, the compiler might indicate which language a particular
5322source file is in. However, most of the time @value{GDBN} infers the
5323language from the name of the file. The language of a source file
5324controls whether C++ names are demangled---this way @code{backtrace} can
5325show each frame appropriately for its own language. There is no way to
d4f3574e
SS
5326set the language of a source file from within @value{GDBN}, but you can
5327set the language associated with a filename extension. @xref{Show, ,
5328Displaying the language}.
c906108c
SS
5329
5330This is most commonly a problem when you use a program, such
5331as @code{cfront} or @code{f2c}, that generates C but is written in
5332another language. In that case, make the
5333program use @code{#line} directives in its C output; that way
5334@value{GDBN} will know the correct language of the source code of the original
5335program, and will display that source code, not the generated C code.
5336
5337@menu
5338* Filenames:: Filename extensions and languages.
5339* Manually:: Setting the working language manually
5340* Automatically:: Having @value{GDBN} infer the source language
5341@end menu
5342
53a5351d 5343@node Filenames
c906108c
SS
5344@subsection List of filename extensions and languages
5345
5346If a source file name ends in one of the following extensions, then
5347@value{GDBN} infers that its language is the one indicated.
5348
5349@table @file
5350
5351@item .c
5352C source file
5353
5354@item .C
5355@itemx .cc
5356@itemx .cp
5357@itemx .cpp
5358@itemx .cxx
5359@itemx .c++
5360C++ source file
5361
5362@item .f
5363@itemx .F
5364Fortran source file
5365
c906108c
SS
5366@item .ch
5367@itemx .c186
5368@itemx .c286
5369CHILL source file.
c906108c 5370
c906108c
SS
5371@item .mod
5372Modula-2 source file
c906108c
SS
5373
5374@item .s
5375@itemx .S
5376Assembler source file. This actually behaves almost like C, but
5377@value{GDBN} does not skip over function prologues when stepping.
5378@end table
5379
5380In addition, you may set the language associated with a filename
5381extension. @xref{Show, , Displaying the language}.
5382
53a5351d 5383@node Manually
c906108c
SS
5384@subsection Setting the working language
5385
5386If you allow @value{GDBN} to set the language automatically,
5387expressions are interpreted the same way in your debugging session and
5388your program.
5389
5390@kindex set language
5391If you wish, you may set the language manually. To do this, issue the
5392command @samp{set language @var{lang}}, where @var{lang} is the name of
5393a language, such as
c906108c 5394@code{c} or @code{modula-2}.
c906108c
SS
5395For a list of the supported languages, type @samp{set language}.
5396
c906108c
SS
5397Setting the language manually prevents @value{GDBN} from updating the working
5398language automatically. This can lead to confusion if you try
5399to debug a program when the working language is not the same as the
5400source language, when an expression is acceptable to both
5401languages---but means different things. For instance, if the current
5402source file were written in C, and @value{GDBN} was parsing Modula-2, a
5403command such as:
5404
5405@example
5406print a = b + c
5407@end example
5408
5409@noindent
5410might not have the effect you intended. In C, this means to add
5411@code{b} and @code{c} and place the result in @code{a}. The result
5412printed would be the value of @code{a}. In Modula-2, this means to compare
5413@code{a} to the result of @code{b+c}, yielding a @code{BOOLEAN} value.
c906108c 5414
53a5351d 5415@node Automatically
c906108c
SS
5416@subsection Having @value{GDBN} infer the source language
5417
5418To have @value{GDBN} set the working language automatically, use
5419@samp{set language local} or @samp{set language auto}. @value{GDBN}
5420then infers the working language. That is, when your program stops in a
5421frame (usually by encountering a breakpoint), @value{GDBN} sets the
5422working language to the language recorded for the function in that
5423frame. If the language for a frame is unknown (that is, if the function
5424or block corresponding to the frame was defined in a source file that
5425does not have a recognized extension), the current working language is
5426not changed, and @value{GDBN} issues a warning.
5427
5428This may not seem necessary for most programs, which are written
5429entirely in one source language. However, program modules and libraries
5430written in one source language can be used by a main program written in
5431a different source language. Using @samp{set language auto} in this
5432case frees you from having to set the working language manually.
5433
53a5351d 5434@node Show
c906108c 5435@section Displaying the language
c906108c
SS
5436
5437The following commands help you find out which language is the
5438working language, and also what language source files were written in.
5439
5440@kindex show language
d4f3574e
SS
5441@kindex info frame@r{, show the source language}
5442@kindex info source@r{, show the source language}
c906108c
SS
5443@table @code
5444@item show language
5445Display the current working language. This is the
5446language you can use with commands such as @code{print} to
5447build and compute expressions that may involve variables in your program.
5448
5449@item info frame
5450Display the source language for this frame. This language becomes the
5451working language if you use an identifier from this frame.
5452@xref{Frame Info, ,Information about a frame}, to identify the other
5453information listed here.
5454
5455@item info source
5456Display the source language of this source file.
5457@xref{Symbols, ,Examining the Symbol Table}, to identify the other
5458information listed here.
5459@end table
5460
5461In unusual circumstances, you may have source files with extensions
5462not in the standard list. You can then set the extension associated
5463with a language explicitly:
5464
5465@kindex set extension-language
5466@kindex info extensions
5467@table @code
5468@item set extension-language @var{.ext} @var{language}
5469Set source files with extension @var{.ext} to be assumed to be in
5470the source language @var{language}.
5471
5472@item info extensions
5473List all the filename extensions and the associated languages.
5474@end table
5475
53a5351d 5476@node Checks
c906108c
SS
5477@section Type and range checking
5478
5479@quotation
5480@emph{Warning:} In this release, the @value{GDBN} commands for type and range
5481checking are included, but they do not yet have any effect. This
5482section documents the intended facilities.
5483@end quotation
5484@c FIXME remove warning when type/range code added
5485
5486Some languages are designed to guard you against making seemingly common
5487errors through a series of compile- and run-time checks. These include
5488checking the type of arguments to functions and operators, and making
5489sure mathematical overflows are caught at run time. Checks such as
5490these help to ensure a program's correctness once it has been compiled
5491by eliminating type mismatches, and providing active checks for range
5492errors when your program is running.
5493
5494@value{GDBN} can check for conditions like the above if you wish.
5495Although @value{GDBN} does not check the statements in your program, it
5496can check expressions entered directly into @value{GDBN} for evaluation via
5497the @code{print} command, for example. As with the working language,
5498@value{GDBN} can also decide whether or not to check automatically based on
5499your program's source language. @xref{Support, ,Supported languages},
5500for the default settings of supported languages.
5501
5502@menu
5503* Type Checking:: An overview of type checking
5504* Range Checking:: An overview of range checking
5505@end menu
5506
5507@cindex type checking
5508@cindex checks, type
53a5351d 5509@node Type Checking
c906108c
SS
5510@subsection An overview of type checking
5511
5512Some languages, such as Modula-2, are strongly typed, meaning that the
5513arguments to operators and functions have to be of the correct type,
5514otherwise an error occurs. These checks prevent type mismatch
5515errors from ever causing any run-time problems. For example,
5516
5517@smallexample
55181 + 2 @result{} 3
5519@exdent but
5520@error{} 1 + 2.3
5521@end smallexample
5522
5523The second example fails because the @code{CARDINAL} 1 is not
5524type-compatible with the @code{REAL} 2.3.
5525
5526For the expressions you use in @value{GDBN} commands, you can tell the
5527@value{GDBN} type checker to skip checking;
5528to treat any mismatches as errors and abandon the expression;
5529or to only issue warnings when type mismatches occur,
5530but evaluate the expression anyway. When you choose the last of
5531these, @value{GDBN} evaluates expressions like the second example above, but
5532also issues a warning.
5533
5534Even if you turn type checking off, there may be other reasons
5535related to type that prevent @value{GDBN} from evaluating an expression.
5536For instance, @value{GDBN} does not know how to add an @code{int} and
5537a @code{struct foo}. These particular type errors have nothing to do
5538with the language in use, and usually arise from expressions, such as
5539the one described above, which make little sense to evaluate anyway.
5540
5541Each language defines to what degree it is strict about type. For
5542instance, both Modula-2 and C require the arguments to arithmetical
5543operators to be numbers. In C, enumerated types and pointers can be
5544represented as numbers, so that they are valid arguments to mathematical
5545operators. @xref{Support, ,Supported languages}, for further
5546details on specific languages.
5547
5548@value{GDBN} provides some additional commands for controlling the type checker:
5549
d4f3574e 5550@kindex set check@r{, type}
c906108c
SS
5551@kindex set check type
5552@kindex show check type
5553@table @code
5554@item set check type auto
5555Set type checking on or off based on the current working language.
5556@xref{Support, ,Supported languages}, for the default settings for
5557each language.
5558
5559@item set check type on
5560@itemx set check type off
5561Set type checking on or off, overriding the default setting for the
5562current working language. Issue a warning if the setting does not
5563match the language default. If any type mismatches occur in
d4f3574e 5564evaluating an expression while type checking is on, @value{GDBN} prints a
c906108c
SS
5565message and aborts evaluation of the expression.
5566
5567@item set check type warn
5568Cause the type checker to issue warnings, but to always attempt to
5569evaluate the expression. Evaluating the expression may still
5570be impossible for other reasons. For example, @value{GDBN} cannot add
5571numbers and structures.
5572
5573@item show type
5574Show the current setting of the type checker, and whether or not @value{GDBN}
5575is setting it automatically.
5576@end table
5577
5578@cindex range checking
5579@cindex checks, range
53a5351d 5580@node Range Checking
c906108c
SS
5581@subsection An overview of range checking
5582
5583In some languages (such as Modula-2), it is an error to exceed the
5584bounds of a type; this is enforced with run-time checks. Such range
5585checking is meant to ensure program correctness by making sure
5586computations do not overflow, or indices on an array element access do
5587not exceed the bounds of the array.
5588
5589For expressions you use in @value{GDBN} commands, you can tell
5590@value{GDBN} to treat range errors in one of three ways: ignore them,
5591always treat them as errors and abandon the expression, or issue
5592warnings but evaluate the expression anyway.
5593
5594A range error can result from numerical overflow, from exceeding an
5595array index bound, or when you type a constant that is not a member
5596of any type. Some languages, however, do not treat overflows as an
5597error. In many implementations of C, mathematical overflow causes the
5598result to ``wrap around'' to lower values---for example, if @var{m} is
5599the largest integer value, and @var{s} is the smallest, then
5600
5601@example
5602@var{m} + 1 @result{} @var{s}
5603@end example
5604
5605This, too, is specific to individual languages, and in some cases
5606specific to individual compilers or machines. @xref{Support, ,
5607Supported languages}, for further details on specific languages.
5608
5609@value{GDBN} provides some additional commands for controlling the range checker:
5610
d4f3574e 5611@kindex set check@r{, range}
c906108c
SS
5612@kindex set check range
5613@kindex show check range
5614@table @code
5615@item set check range auto
5616Set range checking on or off based on the current working language.
5617@xref{Support, ,Supported languages}, for the default settings for
5618each language.
5619
5620@item set check range on
5621@itemx set check range off
5622Set range checking on or off, overriding the default setting for the
5623current working language. A warning is issued if the setting does not
c3f6f71d
JM
5624match the language default. If a range error occurs and range checking is on,
5625then a message is printed and evaluation of the expression is aborted.
c906108c
SS
5626
5627@item set check range warn
5628Output messages when the @value{GDBN} range checker detects a range error,
5629but attempt to evaluate the expression anyway. Evaluating the
5630expression may still be impossible for other reasons, such as accessing
5631memory that the process does not own (a typical example from many Unix
5632systems).
5633
5634@item show range
5635Show the current setting of the range checker, and whether or not it is
5636being set automatically by @value{GDBN}.
5637@end table
c906108c 5638
53a5351d 5639@node Support
c906108c 5640@section Supported languages
c906108c 5641
cce74817
JM
5642@value{GDBN} supports C, C++, Fortran, Java, Chill, assembly, and Modula-2.
5643@c This is false ...
c906108c
SS
5644Some @value{GDBN} features may be used in expressions regardless of the
5645language you use: the @value{GDBN} @code{@@} and @code{::} operators,
5646and the @samp{@{type@}addr} construct (@pxref{Expressions,
5647,Expressions}) can be used with the constructs of any supported
5648language.
5649
5650The following sections detail to what degree each source language is
5651supported by @value{GDBN}. These sections are not meant to be language
5652tutorials or references, but serve only as a reference guide to what the
5653@value{GDBN} expression parser accepts, and what input and output
5654formats should look like for different languages. There are many good
5655books written on each of these languages; please look to these for a
5656language reference or tutorial.
5657
c906108c 5658@menu
7a292a7a 5659* C:: C and C++
cce74817 5660* Modula-2:: Modula-2
104c1213 5661* Chill:: Chill
c906108c
SS
5662@end menu
5663
53a5351d 5664@node C
c906108c 5665@subsection C and C++
7a292a7a 5666
c906108c
SS
5667@cindex C and C++
5668@cindex expressions in C or C++
c906108c
SS
5669
5670Since C and C++ are so closely related, many features of @value{GDBN} apply
5671to both languages. Whenever this is the case, we discuss those languages
5672together.
5673
c906108c
SS
5674@cindex C++
5675@kindex g++
5676@cindex @sc{gnu} C++
5677The C++ debugging facilities are jointly implemented by the C++
5678compiler and @value{GDBN}. Therefore, to debug your C++ code
5679effectively, you must compile your C++ programs with a supported
5680C++ compiler, such as @sc{gnu} @code{g++}, or the HP ANSI C++
5681compiler (@code{aCC}).
5682
5683For best results when using @sc{gnu} C++, use the stabs debugging
5684format. You can select that format explicitly with the @code{g++}
5685command-line options @samp{-gstabs} or @samp{-gstabs+}. See
5686@ref{Debugging Options,,Options for Debugging Your Program or @sc{gnu}
5687CC, gcc.info, Using @sc{gnu} CC}, for more information.
c906108c 5688
c906108c
SS
5689@menu
5690* C Operators:: C and C++ operators
5691* C Constants:: C and C++ constants
7a292a7a 5692* C plus plus expressions:: C++ expressions
c906108c 5693* C Defaults:: Default settings for C and C++
c906108c 5694* C Checks:: C and C++ type and range checks
c906108c
SS
5695* Debugging C:: @value{GDBN} and C
5696* Debugging C plus plus:: @value{GDBN} features for C++
5697@end menu
c906108c 5698
53a5351d 5699@node C Operators
c906108c 5700@subsubsection C and C++ operators
7a292a7a
SS
5701
5702@cindex C and C++ operators
c906108c
SS
5703
5704Operators must be defined on values of specific types. For instance,
5705@code{+} is defined on numbers, but not on structures. Operators are
5706often defined on groups of types.
5707
c906108c 5708For the purposes of C and C++, the following definitions hold:
c906108c
SS
5709
5710@itemize @bullet
53a5351d 5711
c906108c 5712@item
c906108c
SS
5713@emph{Integral types} include @code{int} with any of its storage-class
5714specifiers; @code{char}; @code{enum}; and, for C++, @code{bool}.
c906108c
SS
5715
5716@item
d4f3574e
SS
5717@emph{Floating-point types} include @code{float}, @code{double}, and
5718@code{long double} (if supported by the target platform).
c906108c
SS
5719
5720@item
53a5351d 5721@emph{Pointer types} include all types defined as @code{(@var{type} *)}.
c906108c
SS
5722
5723@item
5724@emph{Scalar types} include all of the above.
53a5351d 5725
c906108c
SS
5726@end itemize
5727
5728@noindent
5729The following operators are supported. They are listed here
5730in order of increasing precedence:
5731
5732@table @code
5733@item ,
5734The comma or sequencing operator. Expressions in a comma-separated list
5735are evaluated from left to right, with the result of the entire
5736expression being the last expression evaluated.
5737
5738@item =
5739Assignment. The value of an assignment expression is the value
5740assigned. Defined on scalar types.
5741
5742@item @var{op}=
5743Used in an expression of the form @w{@code{@var{a} @var{op}= @var{b}}},
5744and translated to @w{@code{@var{a} = @var{a op b}}}.
d4f3574e 5745@w{@code{@var{op}=}} and @code{=} have the same precedence.
c906108c
SS
5746@var{op} is any one of the operators @code{|}, @code{^}, @code{&},
5747@code{<<}, @code{>>}, @code{+}, @code{-}, @code{*}, @code{/}, @code{%}.
5748
5749@item ?:
5750The ternary operator. @code{@var{a} ? @var{b} : @var{c}} can be thought
5751of as: if @var{a} then @var{b} else @var{c}. @var{a} should be of an
5752integral type.
5753
5754@item ||
5755Logical @sc{or}. Defined on integral types.
5756
5757@item &&
5758Logical @sc{and}. Defined on integral types.
5759
5760@item |
5761Bitwise @sc{or}. Defined on integral types.
5762
5763@item ^
5764Bitwise exclusive-@sc{or}. Defined on integral types.
5765
5766@item &
5767Bitwise @sc{and}. Defined on integral types.
5768
5769@item ==@r{, }!=
5770Equality and inequality. Defined on scalar types. The value of these
5771expressions is 0 for false and non-zero for true.
5772
5773@item <@r{, }>@r{, }<=@r{, }>=
5774Less than, greater than, less than or equal, greater than or equal.
5775Defined on scalar types. The value of these expressions is 0 for false
5776and non-zero for true.
5777
5778@item <<@r{, }>>
5779left shift, and right shift. Defined on integral types.
5780
5781@item @@
5782The @value{GDBN} ``artificial array'' operator (@pxref{Expressions, ,Expressions}).
5783
5784@item +@r{, }-
5785Addition and subtraction. Defined on integral types, floating-point types and
5786pointer types.
5787
5788@item *@r{, }/@r{, }%
5789Multiplication, division, and modulus. Multiplication and division are
5790defined on integral and floating-point types. Modulus is defined on
5791integral types.
5792
5793@item ++@r{, }--
5794Increment and decrement. When appearing before a variable, the
5795operation is performed before the variable is used in an expression;
5796when appearing after it, the variable's value is used before the
5797operation takes place.
5798
5799@item *
5800Pointer dereferencing. Defined on pointer types. Same precedence as
5801@code{++}.
5802
5803@item &
5804Address operator. Defined on variables. Same precedence as @code{++}.
5805
c906108c
SS
5806For debugging C++, @value{GDBN} implements a use of @samp{&} beyond what is
5807allowed in the C++ language itself: you can use @samp{&(&@var{ref})}
5808(or, if you prefer, simply @samp{&&@var{ref}}) to examine the address
5809where a C++ reference variable (declared with @samp{&@var{ref}}) is
5810stored.
c906108c
SS
5811
5812@item -
5813Negative. Defined on integral and floating-point types. Same
5814precedence as @code{++}.
5815
5816@item !
5817Logical negation. Defined on integral types. Same precedence as
5818@code{++}.
5819
5820@item ~
5821Bitwise complement operator. Defined on integral types. Same precedence as
5822@code{++}.
5823
5824
5825@item .@r{, }->
5826Structure member, and pointer-to-structure member. For convenience,
5827@value{GDBN} regards the two as equivalent, choosing whether to dereference a
5828pointer based on the stored type information.
5829Defined on @code{struct} and @code{union} data.
5830
c906108c
SS
5831@item .*@r{, }->*
5832Dereferences of pointers to members.
c906108c
SS
5833
5834@item []
5835Array indexing. @code{@var{a}[@var{i}]} is defined as
5836@code{*(@var{a}+@var{i})}. Same precedence as @code{->}.
5837
5838@item ()
5839Function parameter list. Same precedence as @code{->}.
5840
c906108c 5841@item ::
7a292a7a
SS
5842C++ scope resolution operator. Defined on @code{struct}, @code{union},
5843and @code{class} types.
c906108c
SS
5844
5845@item ::
7a292a7a
SS
5846Doubled colons also represent the @value{GDBN} scope operator
5847(@pxref{Expressions, ,Expressions}). Same precedence as @code{::},
5848above.
c906108c
SS
5849@end table
5850
c906108c
SS
5851If an operator is redefined in the user code, @value{GDBN} usually
5852attempts to invoke the redefined version instead of using the operator's
5853predefined meaning.
c906108c 5854
c906108c
SS
5855@menu
5856* C Constants::
5857@end menu
5858
53a5351d 5859@node C Constants
c906108c 5860@subsubsection C and C++ constants
c906108c
SS
5861
5862@cindex C and C++ constants
c906108c 5863
7a292a7a 5864@value{GDBN} allows you to express the constants of C and C++ in the
c906108c 5865following ways:
c906108c
SS
5866
5867@itemize @bullet
5868@item
5869Integer constants are a sequence of digits. Octal constants are
5870specified by a leading @samp{0} (i.e. zero), and hexadecimal constants by
5871a leading @samp{0x} or @samp{0X}. Constants may also end with a letter
5872@samp{l}, specifying that the constant should be treated as a
5873@code{long} value.
5874
5875@item
5876Floating point constants are a sequence of digits, followed by a decimal
5877point, followed by a sequence of digits, and optionally followed by an
5878exponent. An exponent is of the form:
5879@samp{@w{e@r{[[}+@r{]|}-@r{]}@var{nnn}}}, where @var{nnn} is another
5880sequence of digits. The @samp{+} is optional for positive exponents.
d4f3574e
SS
5881A floating-point constant may also end with a letter @samp{f} or
5882@samp{F}, specifying that the constant should be treated as being of
5883the @code{float} (as opposed to the default @code{double}) type; or with
5884a letter @samp{l} or @samp{L}, which specifies a @code{long double}
5885constant.
c906108c
SS
5886
5887@item
5888Enumerated constants consist of enumerated identifiers, or their
5889integral equivalents.
5890
5891@item
5892Character constants are a single character surrounded by single quotes
5893(@code{'}), or a number---the ordinal value of the corresponding character
d4f3574e 5894(usually its @sc{ascii} value). Within quotes, the single character may
c906108c
SS
5895be represented by a letter or by @dfn{escape sequences}, which are of
5896the form @samp{\@var{nnn}}, where @var{nnn} is the octal representation
5897of the character's ordinal value; or of the form @samp{\@var{x}}, where
5898@samp{@var{x}} is a predefined special character---for example,
5899@samp{\n} for newline.
5900
5901@item
5902String constants are a sequence of character constants surrounded
5903by double quotes (@code{"}).
5904
5905@item
5906Pointer constants are an integral value. You can also write pointers
5907to constants using the C operator @samp{&}.
5908
5909@item
5910Array constants are comma-separated lists surrounded by braces @samp{@{}
5911and @samp{@}}; for example, @samp{@{1,2,3@}} is a three-element array of
5912integers, @samp{@{@{1,2@}, @{3,4@}, @{5,6@}@}} is a three-by-two array,
5913and @samp{@{&"hi", &"there", &"fred"@}} is a three-element array of pointers.
5914@end itemize
5915
c906108c 5916@menu
7a292a7a 5917* C plus plus expressions::
c906108c 5918* C Defaults::
c906108c 5919* C Checks::
c906108c
SS
5920
5921* Debugging C::
5922@end menu
5923
53a5351d 5924@node C plus plus expressions
c906108c 5925@subsubsection C++ expressions
c906108c
SS
5926
5927@cindex expressions in C++
5928@value{GDBN} expression handling can interpret most C++ expressions.
5929
c906108c
SS
5930@cindex C++ support, not in @sc{coff}
5931@cindex @sc{coff} versus C++
5932@cindex C++ and object formats
5933@cindex object formats and C++
5934@cindex a.out and C++
5935@cindex @sc{ecoff} and C++
5936@cindex @sc{xcoff} and C++
5937@cindex @sc{elf}/stabs and C++
5938@cindex @sc{elf}/@sc{dwarf} and C++
5939@c FIXME!! GDB may eventually be able to debug C++ using DWARF; check
5940@c periodically whether this has happened...
5941@quotation
5942@emph{Warning:} @value{GDBN} can only debug C++ code if you use the
5943proper compiler. Typically, C++ debugging depends on the use of
5944additional debugging information in the symbol table, and thus requires
5945special support. In particular, if your compiler generates a.out, MIPS
5946@sc{ecoff}, RS/6000 @sc{xcoff}, or @sc{elf} with stabs extensions to the
5947symbol table, these facilities are all available. (With @sc{gnu} CC,
5948you can use the @samp{-gstabs} option to request stabs debugging
5949extensions explicitly.) Where the object code format is standard
5950@sc{coff} or @sc{dwarf} in @sc{elf}, on the other hand, most of the C++
5951support in @value{GDBN} does @emph{not} work.
5952@end quotation
c906108c
SS
5953
5954@enumerate
5955
5956@cindex member functions
5957@item
5958Member function calls are allowed; you can use expressions like
5959
5960@example
5961count = aml->GetOriginal(x, y)
5962@end example
5963
5964@kindex this
5965@cindex namespace in C++
5966@item
5967While a member function is active (in the selected stack frame), your
5968expressions have the same namespace available as the member function;
5969that is, @value{GDBN} allows implicit references to the class instance
5970pointer @code{this} following the same rules as C++.
5971
c906108c 5972@cindex call overloaded functions
d4f3574e 5973@cindex overloaded functions, calling
c906108c
SS
5974@cindex type conversions in C++
5975@item
5976You can call overloaded functions; @value{GDBN} resolves the function
d4f3574e 5977call to the right definition, with some restrictions. @value{GDBN} does not
c906108c
SS
5978perform overload resolution involving user-defined type conversions,
5979calls to constructors, or instantiations of templates that do not exist
5980in the program. It also cannot handle ellipsis argument lists or
5981default arguments.
5982
5983It does perform integral conversions and promotions, floating-point
5984promotions, arithmetic conversions, pointer conversions, conversions of
5985class objects to base classes, and standard conversions such as those of
5986functions or arrays to pointers; it requires an exact match on the
5987number of function arguments.
5988
5989Overload resolution is always performed, unless you have specified
5990@code{set overload-resolution off}. @xref{Debugging C plus plus,
5991,@value{GDBN} features for C++}.
5992
d4f3574e 5993You must specify @code{set overload-resolution off} in order to use an
c906108c
SS
5994explicit function signature to call an overloaded function, as in
5995@smallexample
5996p 'foo(char,int)'('x', 13)
5997@end smallexample
d4f3574e 5998
c906108c 5999The @value{GDBN} command-completion facility can simplify this;
d4f3574e 6000see @ref{Completion, ,Command completion}.
c906108c 6001
c906108c
SS
6002@cindex reference declarations
6003@item
6004@value{GDBN} understands variables declared as C++ references; you can use
6005them in expressions just as you do in C++ source---they are automatically
6006dereferenced.
6007
6008In the parameter list shown when @value{GDBN} displays a frame, the values of
6009reference variables are not displayed (unlike other variables); this
6010avoids clutter, since references are often used for large structures.
6011The @emph{address} of a reference variable is always shown, unless
6012you have specified @samp{set print address off}.
6013
6014@item
6015@value{GDBN} supports the C++ name resolution operator @code{::}---your
6016expressions can use it just as expressions in your program do. Since
6017one scope may be defined in another, you can use @code{::} repeatedly if
6018necessary, for example in an expression like
6019@samp{@var{scope1}::@var{scope2}::@var{name}}. @value{GDBN} also allows
6020resolving name scope by reference to source files, in both C and C++
6021debugging (@pxref{Variables, ,Program variables}).
6022@end enumerate
6023
53a5351d
JM
6024In addition, when used with HP's C++ compiler, @value{GDBN} supports
6025calling virtual functions correctly, printing out virtual bases of
6026objects, calling functions in a base subobject, casting objects, and
6027invoking user-defined operators.
c906108c 6028
53a5351d 6029@node C Defaults
c906108c 6030@subsubsection C and C++ defaults
7a292a7a 6031
c906108c
SS
6032@cindex C and C++ defaults
6033
c906108c
SS
6034If you allow @value{GDBN} to set type and range checking automatically, they
6035both default to @code{off} whenever the working language changes to
6036C or C++. This happens regardless of whether you or @value{GDBN}
6037selects the working language.
c906108c
SS
6038
6039If you allow @value{GDBN} to set the language automatically, it
6040recognizes source files whose names end with @file{.c}, @file{.C}, or
6041@file{.cc}, etc, and when @value{GDBN} enters code compiled from one of
6042these files, it sets the working language to C or C++.
6043@xref{Automatically, ,Having @value{GDBN} infer the source language},
6044for further details.
6045
c906108c
SS
6046@c Type checking is (a) primarily motivated by Modula-2, and (b)
6047@c unimplemented. If (b) changes, it might make sense to let this node
6048@c appear even if Mod-2 does not, but meanwhile ignore it. roland 16jul93.
7a292a7a 6049
53a5351d 6050@node C Checks
c906108c 6051@subsubsection C and C++ type and range checks
7a292a7a 6052
c906108c
SS
6053@cindex C and C++ checks
6054
6055By default, when @value{GDBN} parses C or C++ expressions, type checking
6056is not used. However, if you turn type checking on, @value{GDBN}
6057considers two variables type equivalent if:
6058
6059@itemize @bullet
6060@item
6061The two variables are structured and have the same structure, union, or
6062enumerated tag.
6063
6064@item
6065The two variables have the same type name, or types that have been
6066declared equivalent through @code{typedef}.
6067
6068@ignore
6069@c leaving this out because neither J Gilmore nor R Pesch understand it.
6070@c FIXME--beers?
6071@item
6072The two @code{struct}, @code{union}, or @code{enum} variables are
6073declared in the same declaration. (Note: this may not be true for all C
6074compilers.)
6075@end ignore
6076@end itemize
6077
6078Range checking, if turned on, is done on mathematical operations. Array
6079indices are not checked, since they are often used to index a pointer
6080that is not itself an array.
c906108c 6081
53a5351d 6082@node Debugging C
c906108c 6083@subsubsection @value{GDBN} and C
c906108c
SS
6084
6085The @code{set print union} and @code{show print union} commands apply to
6086the @code{union} type. When set to @samp{on}, any @code{union} that is
7a292a7a
SS
6087inside a @code{struct} or @code{class} is also printed. Otherwise, it
6088appears as @samp{@{...@}}.
c906108c
SS
6089
6090The @code{@@} operator aids in the debugging of dynamic arrays, formed
6091with pointers and a memory allocation function. @xref{Expressions,
6092,Expressions}.
6093
c906108c
SS
6094@menu
6095* Debugging C plus plus::
6096@end menu
6097
53a5351d 6098@node Debugging C plus plus
c906108c 6099@subsubsection @value{GDBN} features for C++
c906108c
SS
6100
6101@cindex commands for C++
7a292a7a 6102
c906108c
SS
6103Some @value{GDBN} commands are particularly useful with C++, and some are
6104designed specifically for use with C++. Here is a summary:
6105
6106@table @code
6107@cindex break in overloaded functions
6108@item @r{breakpoint menus}
6109When you want a breakpoint in a function whose name is overloaded,
6110@value{GDBN} breakpoint menus help you specify which function definition
6111you want. @xref{Breakpoint Menus,,Breakpoint menus}.
6112
6113@cindex overloading in C++
6114@item rbreak @var{regex}
6115Setting breakpoints using regular expressions is helpful for setting
6116breakpoints on overloaded functions that are not members of any special
6117classes.
6118@xref{Set Breaks, ,Setting breakpoints}.
6119
6120@cindex C++ exception handling
6121@item catch throw
6122@itemx catch catch
6123Debug C++ exception handling using these commands. @xref{Set
6124Catchpoints, , Setting catchpoints}.
6125
6126@cindex inheritance
6127@item ptype @var{typename}
6128Print inheritance relationships as well as other information for type
6129@var{typename}.
6130@xref{Symbols, ,Examining the Symbol Table}.
6131
6132@cindex C++ symbol display
6133@item set print demangle
6134@itemx show print demangle
6135@itemx set print asm-demangle
6136@itemx show print asm-demangle
6137Control whether C++ symbols display in their source form, both when
6138displaying code as C++ source and when displaying disassemblies.
6139@xref{Print Settings, ,Print settings}.
6140
6141@item set print object
6142@itemx show print object
6143Choose whether to print derived (actual) or declared types of objects.
6144@xref{Print Settings, ,Print settings}.
6145
6146@item set print vtbl
6147@itemx show print vtbl
6148Control the format for printing virtual function tables.
6149@xref{Print Settings, ,Print settings}.
c906108c
SS
6150(The @code{vtbl} commands do not work on programs compiled with the HP
6151ANSI C++ compiler (@code{aCC}).)
6152
6153@kindex set overload-resolution
d4f3574e 6154@cindex overloaded functions, overload resolution
c906108c
SS
6155@item set overload-resolution on
6156Enable overload resolution for C++ expression evaluation. The default
6157is on. For overloaded functions, @value{GDBN} evaluates the arguments
6158and searches for a function whose signature matches the argument types,
d4f3574e
SS
6159using the standard C++ conversion rules (see @ref{C plus plus expressions, ,C++
6160expressions}, for details). If it cannot find a match, it emits a
c906108c
SS
6161message.
6162
6163@item set overload-resolution off
6164Disable overload resolution for C++ expression evaluation. For
6165overloaded functions that are not class member functions, @value{GDBN}
6166chooses the first function of the specified name that it finds in the
6167symbol table, whether or not its arguments are of the correct type. For
6168overloaded functions that are class member functions, @value{GDBN}
6169searches for a function whose signature @emph{exactly} matches the
6170argument types.
c906108c
SS
6171
6172@item @r{Overloaded symbol names}
6173You can specify a particular definition of an overloaded symbol, using
6174the same notation that is used to declare such symbols in C++: type
6175@code{@var{symbol}(@var{types})} rather than just @var{symbol}. You can
6176also use the @value{GDBN} command-line word completion facilities to list the
6177available choices, or to finish the type list for you.
6178@xref{Completion,, Command completion}, for details on how to do this.
6179@end table
c906108c 6180
53a5351d 6181@node Modula-2
c906108c 6182@subsection Modula-2
7a292a7a 6183
d4f3574e 6184@cindex Modula-2, @value{GDBN} support
c906108c
SS
6185
6186The extensions made to @value{GDBN} to support Modula-2 only support
6187output from the @sc{gnu} Modula-2 compiler (which is currently being
6188developed). Other Modula-2 compilers are not currently supported, and
6189attempting to debug executables produced by them is most likely
6190to give an error as @value{GDBN} reads in the executable's symbol
6191table.
6192
6193@cindex expressions in Modula-2
6194@menu
6195* M2 Operators:: Built-in operators
6196* Built-In Func/Proc:: Built-in functions and procedures
6197* M2 Constants:: Modula-2 constants
6198* M2 Defaults:: Default settings for Modula-2
6199* Deviations:: Deviations from standard Modula-2
6200* M2 Checks:: Modula-2 type and range checks
6201* M2 Scope:: The scope operators @code{::} and @code{.}
6202* GDB/M2:: @value{GDBN} and Modula-2
6203@end menu
6204
53a5351d 6205@node M2 Operators
c906108c
SS
6206@subsubsection Operators
6207@cindex Modula-2 operators
6208
6209Operators must be defined on values of specific types. For instance,
6210@code{+} is defined on numbers, but not on structures. Operators are
6211often defined on groups of types. For the purposes of Modula-2, the
6212following definitions hold:
6213
6214@itemize @bullet
6215
6216@item
6217@emph{Integral types} consist of @code{INTEGER}, @code{CARDINAL}, and
6218their subranges.
6219
6220@item
6221@emph{Character types} consist of @code{CHAR} and its subranges.
6222
6223@item
6224@emph{Floating-point types} consist of @code{REAL}.
6225
6226@item
6227@emph{Pointer types} consist of anything declared as @code{POINTER TO
6228@var{type}}.
6229
6230@item
6231@emph{Scalar types} consist of all of the above.
6232
6233@item
6234@emph{Set types} consist of @code{SET} and @code{BITSET} types.
6235
6236@item
6237@emph{Boolean types} consist of @code{BOOLEAN}.
6238@end itemize
6239
6240@noindent
6241The following operators are supported, and appear in order of
6242increasing precedence:
6243
6244@table @code
6245@item ,
6246Function argument or array index separator.
6247
6248@item :=
6249Assignment. The value of @var{var} @code{:=} @var{value} is
6250@var{value}.
6251
6252@item <@r{, }>
6253Less than, greater than on integral, floating-point, or enumerated
6254types.
6255
6256@item <=@r{, }>=
6257Less than, greater than, less than or equal to, greater than or equal to
6258on integral, floating-point and enumerated types, or set inclusion on
6259set types. Same precedence as @code{<}.
6260
6261@item =@r{, }<>@r{, }#
6262Equality and two ways of expressing inequality, valid on scalar types.
6263Same precedence as @code{<}. In @value{GDBN} scripts, only @code{<>} is
6264available for inequality, since @code{#} conflicts with the script
6265comment character.
6266
6267@item IN
6268Set membership. Defined on set types and the types of their members.
6269Same precedence as @code{<}.
6270
6271@item OR
6272Boolean disjunction. Defined on boolean types.
6273
6274@item AND@r{, }&
d4f3574e 6275Boolean conjunction. Defined on boolean types.
c906108c
SS
6276
6277@item @@
6278The @value{GDBN} ``artificial array'' operator (@pxref{Expressions, ,Expressions}).
6279
6280@item +@r{, }-
6281Addition and subtraction on integral and floating-point types, or union
6282and difference on set types.
6283
6284@item *
6285Multiplication on integral and floating-point types, or set intersection
6286on set types.
6287
6288@item /
6289Division on floating-point types, or symmetric set difference on set
6290types. Same precedence as @code{*}.
6291
6292@item DIV@r{, }MOD
6293Integer division and remainder. Defined on integral types. Same
6294precedence as @code{*}.
6295
6296@item -
6297Negative. Defined on @code{INTEGER} and @code{REAL} data.
6298
6299@item ^
6300Pointer dereferencing. Defined on pointer types.
6301
6302@item NOT
6303Boolean negation. Defined on boolean types. Same precedence as
6304@code{^}.
6305
6306@item .
6307@code{RECORD} field selector. Defined on @code{RECORD} data. Same
6308precedence as @code{^}.
6309
6310@item []
6311Array indexing. Defined on @code{ARRAY} data. Same precedence as @code{^}.
6312
6313@item ()
6314Procedure argument list. Defined on @code{PROCEDURE} objects. Same precedence
6315as @code{^}.
6316
6317@item ::@r{, }.
6318@value{GDBN} and Modula-2 scope operators.
6319@end table
6320
6321@quotation
6322@emph{Warning:} Sets and their operations are not yet supported, so @value{GDBN}
6323treats the use of the operator @code{IN}, or the use of operators
6324@code{+}, @code{-}, @code{*}, @code{/}, @code{=}, , @code{<>}, @code{#},
6325@code{<=}, and @code{>=} on sets as an error.
6326@end quotation
6327
6328@cindex Modula-2 built-ins
53a5351d 6329@node Built-In Func/Proc
c906108c
SS
6330@subsubsection Built-in functions and procedures
6331
6332Modula-2 also makes available several built-in procedures and functions.
6333In describing these, the following metavariables are used:
6334
6335@table @var
6336
6337@item a
6338represents an @code{ARRAY} variable.
6339
6340@item c
6341represents a @code{CHAR} constant or variable.
6342
6343@item i
6344represents a variable or constant of integral type.
6345
6346@item m
6347represents an identifier that belongs to a set. Generally used in the
6348same function with the metavariable @var{s}. The type of @var{s} should
6349be @code{SET OF @var{mtype}} (where @var{mtype} is the type of @var{m}).
6350
6351@item n
6352represents a variable or constant of integral or floating-point type.
6353
6354@item r
6355represents a variable or constant of floating-point type.
6356
6357@item t
6358represents a type.
6359
6360@item v
6361represents a variable.
6362
6363@item x
6364represents a variable or constant of one of many types. See the
6365explanation of the function for details.
6366@end table
6367
6368All Modula-2 built-in procedures also return a result, described below.
6369
6370@table @code
6371@item ABS(@var{n})
6372Returns the absolute value of @var{n}.
6373
6374@item CAP(@var{c})
6375If @var{c} is a lower case letter, it returns its upper case
c3f6f71d 6376equivalent, otherwise it returns its argument.
c906108c
SS
6377
6378@item CHR(@var{i})
6379Returns the character whose ordinal value is @var{i}.
6380
6381@item DEC(@var{v})
c3f6f71d 6382Decrements the value in the variable @var{v} by one. Returns the new value.
c906108c
SS
6383
6384@item DEC(@var{v},@var{i})
6385Decrements the value in the variable @var{v} by @var{i}. Returns the
6386new value.
6387
6388@item EXCL(@var{m},@var{s})
6389Removes the element @var{m} from the set @var{s}. Returns the new
6390set.
6391
6392@item FLOAT(@var{i})
6393Returns the floating point equivalent of the integer @var{i}.
6394
6395@item HIGH(@var{a})
6396Returns the index of the last member of @var{a}.
6397
6398@item INC(@var{v})
c3f6f71d 6399Increments the value in the variable @var{v} by one. Returns the new value.
c906108c
SS
6400
6401@item INC(@var{v},@var{i})
6402Increments the value in the variable @var{v} by @var{i}. Returns the
6403new value.
6404
6405@item INCL(@var{m},@var{s})
6406Adds the element @var{m} to the set @var{s} if it is not already
6407there. Returns the new set.
6408
6409@item MAX(@var{t})
6410Returns the maximum value of the type @var{t}.
6411
6412@item MIN(@var{t})
6413Returns the minimum value of the type @var{t}.
6414
6415@item ODD(@var{i})
6416Returns boolean TRUE if @var{i} is an odd number.
6417
6418@item ORD(@var{x})
6419Returns the ordinal value of its argument. For example, the ordinal
c3f6f71d
JM
6420value of a character is its @sc{ascii} value (on machines supporting the
6421@sc{ascii} character set). @var{x} must be of an ordered type, which include
c906108c
SS
6422integral, character and enumerated types.
6423
6424@item SIZE(@var{x})
6425Returns the size of its argument. @var{x} can be a variable or a type.
6426
6427@item TRUNC(@var{r})
6428Returns the integral part of @var{r}.
6429
6430@item VAL(@var{t},@var{i})
6431Returns the member of the type @var{t} whose ordinal value is @var{i}.
6432@end table
6433
6434@quotation
6435@emph{Warning:} Sets and their operations are not yet supported, so
6436@value{GDBN} treats the use of procedures @code{INCL} and @code{EXCL} as
6437an error.
6438@end quotation
6439
6440@cindex Modula-2 constants
53a5351d 6441@node M2 Constants
c906108c
SS
6442@subsubsection Constants
6443
6444@value{GDBN} allows you to express the constants of Modula-2 in the following
6445ways:
6446
6447@itemize @bullet
6448
6449@item
6450Integer constants are simply a sequence of digits. When used in an
6451expression, a constant is interpreted to be type-compatible with the
6452rest of the expression. Hexadecimal integers are specified by a
6453trailing @samp{H}, and octal integers by a trailing @samp{B}.
6454
6455@item
6456Floating point constants appear as a sequence of digits, followed by a
6457decimal point and another sequence of digits. An optional exponent can
6458then be specified, in the form @samp{E@r{[}+@r{|}-@r{]}@var{nnn}}, where
6459@samp{@r{[}+@r{|}-@r{]}@var{nnn}} is the desired exponent. All of the
6460digits of the floating point constant must be valid decimal (base 10)
6461digits.
6462
6463@item
6464Character constants consist of a single character enclosed by a pair of
6465like quotes, either single (@code{'}) or double (@code{"}). They may
c3f6f71d 6466also be expressed by their ordinal value (their @sc{ascii} value, usually)
c906108c
SS
6467followed by a @samp{C}.
6468
6469@item
6470String constants consist of a sequence of characters enclosed by a
6471pair of like quotes, either single (@code{'}) or double (@code{"}).
6472Escape sequences in the style of C are also allowed. @xref{C
6473Constants, ,C and C++ constants}, for a brief explanation of escape
6474sequences.
6475
6476@item
6477Enumerated constants consist of an enumerated identifier.
6478
6479@item
6480Boolean constants consist of the identifiers @code{TRUE} and
6481@code{FALSE}.
6482
6483@item
6484Pointer constants consist of integral values only.
6485
6486@item
6487Set constants are not yet supported.
6488@end itemize
6489
53a5351d 6490@node M2 Defaults
c906108c
SS
6491@subsubsection Modula-2 defaults
6492@cindex Modula-2 defaults
6493
6494If type and range checking are set automatically by @value{GDBN}, they
6495both default to @code{on} whenever the working language changes to
d4f3574e 6496Modula-2. This happens regardless of whether you or @value{GDBN}
c906108c
SS
6497selected the working language.
6498
6499If you allow @value{GDBN} to set the language automatically, then entering
6500code compiled from a file whose name ends with @file{.mod} sets the
d4f3574e 6501working language to Modula-2. @xref{Automatically, ,Having @value{GDBN} set
c906108c
SS
6502the language automatically}, for further details.
6503
53a5351d 6504@node Deviations
c906108c
SS
6505@subsubsection Deviations from standard Modula-2
6506@cindex Modula-2, deviations from
6507
6508A few changes have been made to make Modula-2 programs easier to debug.
6509This is done primarily via loosening its type strictness:
6510
6511@itemize @bullet
6512@item
6513Unlike in standard Modula-2, pointer constants can be formed by
6514integers. This allows you to modify pointer variables during
6515debugging. (In standard Modula-2, the actual address contained in a
6516pointer variable is hidden from you; it can only be modified
6517through direct assignment to another pointer variable or expression that
6518returned a pointer.)
6519
6520@item
6521C escape sequences can be used in strings and characters to represent
6522non-printable characters. @value{GDBN} prints out strings with these
6523escape sequences embedded. Single non-printable characters are
6524printed using the @samp{CHR(@var{nnn})} format.
6525
6526@item
6527The assignment operator (@code{:=}) returns the value of its right-hand
6528argument.
6529
6530@item
6531All built-in procedures both modify @emph{and} return their argument.
6532@end itemize
6533
53a5351d 6534@node M2 Checks
c906108c
SS
6535@subsubsection Modula-2 type and range checks
6536@cindex Modula-2 checks
6537
6538@quotation
6539@emph{Warning:} in this release, @value{GDBN} does not yet perform type or
6540range checking.
6541@end quotation
6542@c FIXME remove warning when type/range checks added
6543
6544@value{GDBN} considers two Modula-2 variables type equivalent if:
6545
6546@itemize @bullet
6547@item
6548They are of types that have been declared equivalent via a @code{TYPE
6549@var{t1} = @var{t2}} statement
6550
6551@item
6552They have been declared on the same line. (Note: This is true of the
6553@sc{gnu} Modula-2 compiler, but it may not be true of other compilers.)
6554@end itemize
6555
6556As long as type checking is enabled, any attempt to combine variables
6557whose types are not equivalent is an error.
6558
6559Range checking is done on all mathematical operations, assignment, array
6560index bounds, and all built-in functions and procedures.
6561
53a5351d 6562@node M2 Scope
c906108c
SS
6563@subsubsection The scope operators @code{::} and @code{.}
6564@cindex scope
6565@kindex .
6566@cindex colon, doubled as scope operator
6567@ifinfo
d4f3574e 6568@kindex colon-colon@r{, in Modula-2}
c906108c
SS
6569@c Info cannot handle :: but TeX can.
6570@end ifinfo
6571@iftex
6572@kindex ::
6573@end iftex
6574
6575There are a few subtle differences between the Modula-2 scope operator
6576(@code{.}) and the @value{GDBN} scope operator (@code{::}). The two have
6577similar syntax:
6578
6579@example
6580
6581@var{module} . @var{id}
6582@var{scope} :: @var{id}
6583@end example
6584
6585@noindent
6586where @var{scope} is the name of a module or a procedure,
6587@var{module} the name of a module, and @var{id} is any declared
6588identifier within your program, except another module.
6589
6590Using the @code{::} operator makes @value{GDBN} search the scope
6591specified by @var{scope} for the identifier @var{id}. If it is not
6592found in the specified scope, then @value{GDBN} searches all scopes
6593enclosing the one specified by @var{scope}.
6594
6595Using the @code{.} operator makes @value{GDBN} search the current scope for
6596the identifier specified by @var{id} that was imported from the
6597definition module specified by @var{module}. With this operator, it is
6598an error if the identifier @var{id} was not imported from definition
6599module @var{module}, or if @var{id} is not an identifier in
6600@var{module}.
6601
53a5351d 6602@node GDB/M2
c906108c
SS
6603@subsubsection @value{GDBN} and Modula-2
6604
6605Some @value{GDBN} commands have little use when debugging Modula-2 programs.
6606Five subcommands of @code{set print} and @code{show print} apply
6607specifically to C and C++: @samp{vtbl}, @samp{demangle},
6608@samp{asm-demangle}, @samp{object}, and @samp{union}. The first four
6609apply to C++, and the last to the C @code{union} type, which has no direct
6610analogue in Modula-2.
6611
6612The @code{@@} operator (@pxref{Expressions, ,Expressions}), while available
d4f3574e 6613with any language, is not useful with Modula-2. Its
c906108c
SS
6614intent is to aid the debugging of @dfn{dynamic arrays}, which cannot be
6615created in Modula-2 as they can in C or C++. However, because an
6616address can be specified by an integral constant, the construct
d4f3574e 6617@samp{@{@var{type}@}@var{adrexp}} is still useful.
c906108c
SS
6618
6619@cindex @code{#} in Modula-2
6620In @value{GDBN} scripts, the Modula-2 inequality operator @code{#} is
6621interpreted as the beginning of a comment. Use @code{<>} instead.
c906108c 6622
53a5351d 6623@node Chill
cce74817
JM
6624@subsection Chill
6625
6626The extensions made to @value{GDBN} to support Chill only support output
d4f3574e 6627from the @sc{gnu} Chill compiler. Other Chill compilers are not currently
cce74817
JM
6628supported, and attempting to debug executables produced by them is most
6629likely to give an error as @value{GDBN} reads in the executable's symbol
6630table.
6631
d4f3574e
SS
6632@c This used to say "... following Chill related topics ...", but since
6633@c menus are not shown in the printed manual, it would look awkward.
6634This section covers the Chill related topics and the features
cce74817
JM
6635of @value{GDBN} which support these topics.
6636
6637@menu
104c1213
JM
6638* How modes are displayed:: How modes are displayed
6639* Locations:: Locations and their accesses
cce74817 6640* Values and their Operations:: Values and their Operations
53a5351d
JM
6641* Chill type and range checks::
6642* Chill defaults::
cce74817
JM
6643@end menu
6644
6645@node How modes are displayed
6646@subsubsection How modes are displayed
6647
6648The Chill Datatype- (Mode) support of @value{GDBN} is directly related
d4f3574e 6649with the functionality of the @sc{gnu} Chill compiler, and therefore deviates
cce74817
JM
6650slightly from the standard specification of the Chill language. The
6651provided modes are:
d4f3574e
SS
6652
6653@c FIXME: this @table's contents effectively disable @code by using @r
6654@c on every @item. So why does it need @code?
cce74817
JM
6655@table @code
6656@item @r{@emph{Discrete modes:}}
6657@itemize @bullet
6658@item
6659@emph{Integer Modes} which are predefined by @code{BYTE, UBYTE, INT,
6660UINT, LONG, ULONG},
6661@item
6662@emph{Boolean Mode} which is predefined by @code{BOOL},
6663@item
6664@emph{Character Mode} which is predefined by @code{CHAR},
6665@item
6666@emph{Set Mode} which is displayed by the keyword @code{SET}.
6667@smallexample
6668(@value{GDBP}) ptype x
6669type = SET (karli = 10, susi = 20, fritzi = 100)
6670@end smallexample
6671If the type is an unnumbered set the set element values are omitted.
6672@item
6673@emph{Range Mode} which is displayed by @code{type = <basemode>
6674(<lower bound> : <upper bound>)}, where @code{<lower bound>, <upper
6675bound>} can be of any discrete literal expression (e.g. set element
6676names).
6677@end itemize
6678
6679@item @r{@emph{Powerset Mode:}}
6680A Powerset Mode is displayed by the keyword @code{POWERSET} followed by
d4f3574e 6681the member mode of the powerset. The member mode can be any discrete mode.
cce74817
JM
6682@smallexample
6683(@value{GDBP}) ptype x
6684type = POWERSET SET (egon, hugo, otto)
6685@end smallexample
6686
6687@item @r{@emph{Reference Modes:}}
6688@itemize @bullet
6689@item
d4f3574e 6690@emph{Bound Reference Mode} which is displayed by the keyword @code{REF}
cce74817
JM
6691followed by the mode name to which the reference is bound.
6692@item
6693@emph{Free Reference Mode} which is displayed by the keyword @code{PTR}.
6694@end itemize
6695
6696@item @r{@emph{Procedure mode}}
6697The procedure mode is displayed by @code{type = PROC(<parameter list>)
6698<return mode> EXCEPTIONS (<exception list>)}. The @code{<parameter
d4f3574e
SS
6699list>} is a list of the parameter modes. @code{<return mode>} indicates
6700the mode of the result of the procedure if any. The exceptionlist lists
cce74817
JM
6701all possible exceptions which can be raised by the procedure.
6702
6703@ignore
6704@item @r{@emph{Instance mode}}
6705The instance mode is represented by a structure, which has a static
6706type, and is therefore not really of interest.
6707@end ignore
6708
6709@item @r{@emph{Synchronization Modes:}}
6710@itemize @bullet
6711@item
6712@emph{Event Mode} which is displayed by @code{EVENT (<event length>)},
6713where @code{(<event length>)} is optional.
6714@item
6715@emph{Buffer Mode} which is displayed by @code{BUFFER (<buffer length>)
6716<buffer element mode>}, where @code{(<buffer length>)} is optional.
6717@end itemize
6718
6719@item @r{@emph{Timing Modes:}}
6720@itemize @bullet
6721@item
6722@emph{Duration Mode} which is predefined by @code{DURATION}
6723@item
6724@emph{Absolute Time Mode} which is predefined by @code{TIME}
6725@end itemize
6726
6727@item @r{@emph{Real Modes:}}
6728Real Modes are predefined with @code{REAL} and @code{LONG_REAL}.
6729
6730@item @r{@emph{String Modes:}}
6731@itemize @bullet
6732@item
6733@emph{Character String Mode} which is displayed by @code{CHARS(<string
6734length>)}, followed by the keyword @code{VARYING} if the String Mode is
6735a varying mode
6736@item
6737@emph{Bit String Mode} which is displayed by @code{BOOLS(<string
6738length>)}.
6739@end itemize
6740
6741@item @r{@emph{Array Mode:}}
6742The Array Mode is displayed by the keyword @code{ARRAY(<range>)}
6743followed by the element mode (which may in turn be an array mode).
6744@smallexample
6745(@value{GDBP}) ptype x
6746type = ARRAY (1:42)
6747 ARRAY (1:20)
6748 SET (karli = 10, susi = 20, fritzi = 100)
6749@end smallexample
6750
6751@item @r{@emph{Structure Mode}}
6752The Structure mode is displayed by the keyword @code{STRUCT(<field
d4f3574e
SS
6753list>)}. The @code{<field list>} consists of names and modes of fields
6754of the structure. Variant structures have the keyword @code{CASE <field>
6755OF <variant fields> ESAC} in their field list. Since the current version
cce74817
JM
6756of the GNU Chill compiler doesn't implement tag processing (no runtime
6757checks of variant fields, and therefore no debugging info), the output
6758always displays all variant fields.
6759@smallexample
6760(@value{GDBP}) ptype str
6761type = STRUCT (
6762 as x,
6763 bs x,
6764 CASE bs OF
6765 (karli):
6766 cs a
6767 (ott):
6768 ds x
6769 ESAC
6770)
6771@end smallexample
6772@end table
6773
6774@node Locations
6775@subsubsection Locations and their accesses
6776
6777A location in Chill is an object which can contain values.
6778
6779A value of a location is generally accessed by the (declared) name of
d4f3574e
SS
6780the location. The output conforms to the specification of values in
6781Chill programs. How values are specified
6782is the topic of the next section, @ref{Values and their Operations}.
cce74817
JM
6783
6784The pseudo-location @code{RESULT} (or @code{result}) can be used to
6785display or change the result of a currently-active procedure:
d4f3574e 6786
cce74817
JM
6787@smallexample
6788set result := EXPR
6789@end smallexample
d4f3574e
SS
6790
6791@noindent
6792This does the same as the Chill action @code{RESULT EXPR} (which
c3f6f71d 6793is not available in @value{GDBN}).
cce74817
JM
6794
6795Values of reference mode locations are printed by @code{PTR(<hex
6796value>)} in case of a free reference mode, and by @code{(REF <reference
d4f3574e 6797mode>) (<hex-value>)} in case of a bound reference. @code{<hex value>}
cce74817
JM
6798represents the address where the reference points to. To access the
6799value of the location referenced by the pointer, use the dereference
d4f3574e 6800operator @samp{->}.
cce74817
JM
6801
6802Values of procedure mode locations are displayed by @code{@{ PROC
6803(<argument modes> ) <return mode> @} <address> <name of procedure
d4f3574e 6804location>}. @code{<argument modes>} is a list of modes according to the
cce74817
JM
6805parameter specification of the procedure and @code{<address>} shows the
6806address of the entry point.
6807
6808@ignore
6809Locations of instance modes are displayed just like a structure with two
6810fields specifying the @emph{process type} and the @emph{copy number} of
6811the investigated instance location@footnote{This comes from the current
d4f3574e
SS
6812implementation of instances. They are implemented as a structure (no
6813na). The output should be something like @code{[<name of the process>;
6814<instance number>]}.}. The field names are @code{__proc_type} and
cce74817
JM
6815@code{__proc_copy}.
6816
6817Locations of synchronization modes are displayed like a structure with
6818the field name @code{__event_data} in case of a event mode location, and
6819like a structure with the field @code{__buffer_data} in case of a buffer
6820mode location (refer to previous paragraph).
6821
6822Structure Mode locations are printed by @code{[.<field name>: <value>,
d4f3574e 6823...]}. The @code{<field name>} corresponds to the structure mode
cce74817 6824definition and the layout of @code{<value>} varies depending of the mode
d4f3574e
SS
6825of the field. If the investigated structure mode location is of variant
6826structure mode, the variant parts of the structure are enclosed in curled
6827braces (@samp{@{@}}). Fields enclosed by @samp{@{,@}} are residing
cce74817 6828on the same memory location and represent the current values of the
d4f3574e 6829memory location in their specific modes. Since no tag processing is done
cce74817 6830all variants are displayed. A variant field is printed by
d4f3574e 6831@code{(<variant name>) = .<field name>: <value>}. (who implements the
cce74817
JM
6832stuff ???)
6833@smallexample
6834(@value{GDBP}) print str1 $4 = [.as: 0, .bs: karli, .<TAG>: { (karli) =
6835[.cs: []], (susi) = [.ds: susi]}]
6836@end smallexample
6837@end ignore
6838
6839Substructures of string mode-, array mode- or structure mode-values
6840(e.g. array slices, fields of structure locations) are accessed using
d4f3574e
SS
6841certain operations which are described in the next section, @ref{Values
6842and their Operations}.
cce74817
JM
6843
6844A location value may be interpreted as having a different mode using the
d4f3574e
SS
6845location conversion. This mode conversion is written as @code{<mode
6846name>(<location>)}. The user has to consider that the sizes of the modes
6847have to be equal otherwise an error occurs. Furthermore, no range
6848checking of the location against the destination mode is performed, and
cce74817 6849therefore the result can be quite confusing.
d4f3574e 6850
cce74817
JM
6851@smallexample
6852(@value{GDBP}) print int (s(3 up 4)) XXX TO be filled in !! XXX
6853@end smallexample
6854
6855@node Values and their Operations
6856@subsubsection Values and their Operations
6857
6858Values are used to alter locations, to investigate complex structures in
6859more detail or to filter relevant information out of a large amount of
d4f3574e
SS
6860data. There are several (mode dependent) operations defined which enable
6861such investigations. These operations are not only applicable to
cce74817 6862constant values but also to locations, which can become quite useful
d4f3574e 6863when debugging complex structures. During parsing the command line
cce74817
JM
6864(e.g. evaluating an expression) @value{GDBN} treats location names as
6865the values behind these locations.
6866
d4f3574e 6867This section describes how values have to be specified and which
cce74817
JM
6868operations are legal to be used with such values.
6869
6870@table @code
6871@item Literal Values
d4f3574e
SS
6872Literal values are specified in the same manner as in @sc{gnu} Chill programs.
6873For detailed specification refer to the @sc{gnu} Chill implementation Manual
cce74817 6874chapter 1.5.
d4f3574e
SS
6875@c FIXME: if the Chill Manual is a Texinfo documents, the above should
6876@c be converted to a @ref.
cce74817
JM
6877
6878@ignore
6879@itemize @bullet
6880@item
6881@emph{Integer Literals} are specified in the same manner as in Chill
d4f3574e 6882programs (refer to the Chill Standard z200/88 chpt 5.2.4.2)
cce74817
JM
6883@item
6884@emph{Boolean Literals} are defined by @code{TRUE} and @code{FALSE}.
6885@item
6886@emph{Character Literals} are defined by @code{'<character>'}. (e.g.
6887@code{'M'})
6888@item
6889@emph{Set Literals} are defined by a name which was specified in a set
d4f3574e
SS
6890mode. The value delivered by a Set Literal is the set value. This is
6891comparable to an enumeration in C/C++ language.
cce74817 6892@item
d4f3574e 6893@emph{Emptiness Literal} is predefined by @code{NULL}. The value of the
cce74817
JM
6894emptiness literal delivers either the empty reference value, the empty
6895procedure value or the empty instance value.
6896
6897@item
6898@emph{Character String Literals} are defined by a sequence of characters
d4f3574e 6899enclosed in single- or double quotes. If a single- or double quote has
cce74817
JM
6900to be part of the string literal it has to be stuffed (specified twice).
6901@item
6902@emph{Bitstring Literals} are specified in the same manner as in Chill
6903programs (refer z200/88 chpt 5.2.4.8).
6904@item
6905@emph{Floating point literals} are specified in the same manner as in
d4f3574e 6906(gnu-)Chill programs (refer @sc{gnu} Chill implementation Manual chapter 1.5).
cce74817
JM
6907@end itemize
6908@end ignore
6909
6910@item Tuple Values
6911A tuple is specified by @code{<mode name>[<tuple>]}, where @code{<mode
d4f3574e 6912name>} can be omitted if the mode of the tuple is unambiguous. This
cce74817
JM
6913unambiguity is derived from the context of a evaluated expression.
6914@code{<tuple>} can be one of the following:
d4f3574e 6915
cce74817
JM
6916@itemize @bullet
6917@item @emph{Powerset Tuple}
6918@item @emph{Array Tuple}
6919@item @emph{Structure Tuple}
6920Powerset tuples, array tuples and structure tuples are specified in the
d4f3574e 6921same manner as in Chill programs refer to z200/88 chpt 5.2.5.
cce74817
JM
6922@end itemize
6923
6924@item String Element Value
6925A string element value is specified by @code{<string value>(<index>)},
d4f3574e 6926where @code{<index>} is a integer expression. It delivers a character
cce74817
JM
6927value which is equivalent to the character indexed by @code{<index>} in
6928the string.
6929
6930@item String Slice Value
6931A string slice value is specified by @code{<string value>(<slice
6932spec>)}, where @code{<slice spec>} can be either a range of integer
6933expressions or specified by @code{<start expr> up <size>}.
6934@code{<size>} denotes the number of elements which the slice contains.
6935The delivered value is a string value, which is part of the specified
6936string.
6937
6938@item Array Element Values
6939An array element value is specified by @code{<array value>(<expr>)} and
6940delivers a array element value of the mode of the specified array.
6941
6942@item Array Slice Values
6943An array slice is specified by @code{<array value>(<slice spec>)}, where
6944@code{<slice spec>} can be either a range specified by expressions or by
d4f3574e
SS
6945@code{<start expr> up <size>}. @code{<size>} denotes the number of
6946arrayelements the slice contains. The delivered value is an array value
cce74817
JM
6947which is part of the specified array.
6948
6949@item Structure Field Values
6950A structure field value is derived by @code{<structure value>.<field
d4f3574e
SS
6951name>}, where @code{<field name>} indicates the name of a field specified
6952in the mode definition of the structure. The mode of the delivered value
cce74817
JM
6953corresponds to this mode definition in the structure definition.
6954
6955@item Procedure Call Value
6956The procedure call value is derived from the return value of the
6957procedure@footnote{If a procedure call is used for instance in an
6958expression, then this procedure is called with all its side
d4f3574e 6959effects. This can lead to confusing results if used carelessly.}.
cce74817 6960
d4f3574e 6961Values of duration mode locations are represented by @code{ULONG} literals.
cce74817 6962
d4f3574e 6963Values of time mode locations are represented by @code{TIME(<secs>:<nsecs>)}.
cce74817
JM
6964
6965@ignore
6966This is not implemented yet:
6967@item Built-in Value
6968@noindent
6969The following built in functions are provided:
d4f3574e 6970
cce74817
JM
6971@table @code
6972@item @code{ADDR()}
6973@item @code{NUM()}
6974@item @code{PRED()}
6975@item @code{SUCC()}
6976@item @code{ABS()}
6977@item @code{CARD()}
6978@item @code{MAX()}
6979@item @code{MIN()}
6980@item @code{SIZE()}
6981@item @code{UPPER()}
6982@item @code{LOWER()}
6983@item @code{LENGTH()}
6984@item @code{SIN()}
6985@item @code{COS()}
6986@item @code{TAN()}
6987@item @code{ARCSIN()}
6988@item @code{ARCCOS()}
6989@item @code{ARCTAN()}
6990@item @code{EXP()}
6991@item @code{LN()}
6992@item @code{LOG()}
6993@item @code{SQRT()}
6994@end table
6995
6996For a detailed description refer to the GNU Chill implementation manual
6997chapter 1.6.
6998@end ignore
6999
7000@item Zero-adic Operator Value
7001The zero-adic operator value is derived from the instance value for the
7002current active process.
7003
7004@item Expression Values
7005The value delivered by an expression is the result of the evaluation of
d4f3574e 7006the specified expression. If there are error conditions (mode
cce74817 7007incompatibility, etc.) the evaluation of expressions is aborted with a
d4f3574e 7008corresponding error message. Expressions may be parenthesised which
cce74817 7009causes the evaluation of this expression before any other expression
d4f3574e 7010which uses the result of the parenthesised expression. The following
cce74817 7011operators are supported by @value{GDBN}:
d4f3574e 7012
cce74817
JM
7013@table @code
7014@item @code{OR, ORIF, XOR}
d4f3574e
SS
7015@itemx @code{AND, ANDIF}
7016@itemx @code{NOT}
cce74817 7017Logical operators defined over operands of boolean mode.
d4f3574e 7018
cce74817
JM
7019@item @code{=, /=}
7020Equality and inequality operators defined over all modes.
d4f3574e 7021
cce74817 7022@item @code{>, >=}
d4f3574e 7023@itemx @code{<, <=}
cce74817 7024Relational operators defined over predefined modes.
d4f3574e 7025
cce74817 7026@item @code{+, -}
d4f3574e 7027@itemx @code{*, /, MOD, REM}
cce74817 7028Arithmetic operators defined over predefined modes.
d4f3574e 7029
cce74817
JM
7030@item @code{-}
7031Change sign operator.
d4f3574e 7032
cce74817
JM
7033@item @code{//}
7034String concatenation operator.
d4f3574e 7035
cce74817
JM
7036@item @code{()}
7037String repetition operator.
d4f3574e 7038
cce74817
JM
7039@item @code{->}
7040Referenced location operator which can be used either to take the
7041address of a location (@code{->loc}), or to dereference a reference
7042location (@code{loc->}).
d4f3574e 7043
cce74817 7044@item @code{OR, XOR}
d4f3574e
SS
7045@itemx @code{AND}
7046@itemx @code{NOT}
cce74817 7047Powerset and bitstring operators.
d4f3574e 7048
cce74817 7049@item @code{>, >=}
d4f3574e 7050@itemx @code{<, <=}
cce74817 7051Powerset inclusion operators.
d4f3574e 7052
cce74817
JM
7053@item @code{IN}
7054Membership operator.
7055@end table
7056@end table
7057
53a5351d 7058@node Chill type and range checks
cce74817
JM
7059@subsubsection Chill type and range checks
7060
7061@value{GDBN} considers two Chill variables mode equivalent if the sizes
d4f3574e 7062of the two modes are equal. This rule applies recursively to more
cce74817 7063complex datatypes which means that complex modes are treated
d4f3574e 7064equivalent if all element modes (which also can be complex modes like
cce74817
JM
7065structures, arrays, etc.) have the same size.
7066
7067Range checking is done on all mathematical operations, assignment, array
7068index bounds and all built in procedures.
7069
7070Strong type checks are forced using the @value{GDBN} command @code{set
d4f3574e 7071check strong}. This enforces strong type and range checks on all
cce74817
JM
7072operations where Chill constructs are used (expressions, built in
7073functions, etc.) in respect to the semantics as defined in the z.200
7074language specification.
7075
cce74817
JM
7076All checks can be disabled by the @value{GDBN} command @code{set check
7077off}.
7078
7079@ignore
53a5351d 7080@c Deviations from the Chill Standard Z200/88
cce74817
JM
7081see last paragraph ?
7082@end ignore
7083
53a5351d 7084@node Chill defaults
cce74817
JM
7085@subsubsection Chill defaults
7086
7087If type and range checking are set automatically by @value{GDBN}, they
7088both default to @code{on} whenever the working language changes to
d4f3574e 7089Chill. This happens regardless of whether you or @value{GDBN}
cce74817
JM
7090selected the working language.
7091
7092If you allow @value{GDBN} to set the language automatically, then entering
7093code compiled from a file whose name ends with @file{.ch} sets the
d4f3574e 7094working language to Chill. @xref{Automatically, ,Having @value{GDBN} set
cce74817
JM
7095the language automatically}, for further details.
7096
53a5351d 7097@node Symbols
c906108c
SS
7098@chapter Examining the Symbol Table
7099
d4f3574e 7100The commands described in this chapter allow you to inquire about the
c906108c
SS
7101symbols (names of variables, functions and types) defined in your
7102program. This information is inherent in the text of your program and
7103does not change as your program executes. @value{GDBN} finds it in your
7104program's symbol table, in the file indicated when you started @value{GDBN}
7105(@pxref{File Options, ,Choosing files}), or by one of the
7106file-management commands (@pxref{Files, ,Commands to specify files}).
7107
7108@cindex symbol names
7109@cindex names of symbols
7110@cindex quoting names
7111Occasionally, you may need to refer to symbols that contain unusual
7112characters, which @value{GDBN} ordinarily treats as word delimiters. The
7113most frequent case is in referring to static variables in other
7114source files (@pxref{Variables,,Program variables}). File names
7115are recorded in object files as debugging symbols, but @value{GDBN} would
7116ordinarily parse a typical file name, like @file{foo.c}, as the three words
7117@samp{foo} @samp{.} @samp{c}. To allow @value{GDBN} to recognize
7118@samp{foo.c} as a single symbol, enclose it in single quotes; for example,
7119
7120@example
7121p 'foo.c'::x
7122@end example
7123
7124@noindent
7125looks up the value of @code{x} in the scope of the file @file{foo.c}.
7126
7127@table @code
7128@kindex info address
7129@item info address @var{symbol}
7130Describe where the data for @var{symbol} is stored. For a register
7131variable, this says which register it is kept in. For a non-register
7132local variable, this prints the stack-frame offset at which the variable
7133is always stored.
7134
7135Note the contrast with @samp{print &@var{symbol}}, which does not work
7136at all for a register variable, and for a stack local variable prints
7137the exact address of the current instantiation of the variable.
7138
7139@kindex whatis
d4f3574e
SS
7140@item whatis @var{expr}
7141Print the data type of expression @var{expr}. @var{expr} is not
c906108c
SS
7142actually evaluated, and any side-effecting operations (such as
7143assignments or function calls) inside it do not take place.
7144@xref{Expressions, ,Expressions}.
7145
7146@item whatis
7147Print the data type of @code{$}, the last value in the value history.
7148
7149@kindex ptype
7150@item ptype @var{typename}
7151Print a description of data type @var{typename}. @var{typename} may be
7a292a7a
SS
7152the name of a type, or for C code it may have the form @samp{class
7153@var{class-name}}, @samp{struct @var{struct-tag}}, @samp{union
7154@var{union-tag}} or @samp{enum @var{enum-tag}}.
c906108c 7155
d4f3574e 7156@item ptype @var{expr}
c906108c 7157@itemx ptype
d4f3574e 7158Print a description of the type of expression @var{expr}. @code{ptype}
c906108c
SS
7159differs from @code{whatis} by printing a detailed description, instead
7160of just the name of the type.
7161
7162For example, for this variable declaration:
7163
7164@example
7165struct complex @{double real; double imag;@} v;
7166@end example
7167
7168@noindent
7169the two commands give this output:
7170
7171@example
7172@group
7173(@value{GDBP}) whatis v
7174type = struct complex
7175(@value{GDBP}) ptype v
7176type = struct complex @{
7177 double real;
7178 double imag;
7179@}
7180@end group
7181@end example
7182
7183@noindent
7184As with @code{whatis}, using @code{ptype} without an argument refers to
7185the type of @code{$}, the last value in the value history.
7186
7187@kindex info types
7188@item info types @var{regexp}
7189@itemx info types
d4f3574e 7190Print a brief description of all types whose names match @var{regexp}
c906108c
SS
7191(or all types in your program, if you supply no argument). Each
7192complete typename is matched as though it were a complete line; thus,
7193@samp{i type value} gives information on all types in your program whose
d4f3574e 7194names include the string @code{value}, but @samp{i type ^value$} gives
c906108c
SS
7195information only on types whose complete name is @code{value}.
7196
7197This command differs from @code{ptype} in two ways: first, like
7198@code{whatis}, it does not print a detailed description; second, it
7199lists all source files where a type is defined.
7200
7201@kindex info source
7202@item info source
7203Show the name of the current source file---that is, the source file for
7204the function containing the current point of execution---and the language
7205it was written in.
7206
7207@kindex info sources
7208@item info sources
7209Print the names of all source files in your program for which there is
7210debugging information, organized into two lists: files whose symbols
7211have already been read, and files whose symbols will be read when needed.
7212
7213@kindex info functions
7214@item info functions
7215Print the names and data types of all defined functions.
7216
7217@item info functions @var{regexp}
7218Print the names and data types of all defined functions
7219whose names contain a match for regular expression @var{regexp}.
7220Thus, @samp{info fun step} finds all functions whose names
7221include @code{step}; @samp{info fun ^step} finds those whose names
7222start with @code{step}.
7223
7224@kindex info variables
7225@item info variables
7226Print the names and data types of all variables that are declared
7227outside of functions (i.e., excluding local variables).
7228
7229@item info variables @var{regexp}
7230Print the names and data types of all variables (except for local
7231variables) whose names contain a match for regular expression
7232@var{regexp}.
7233
7234@ignore
7235This was never implemented.
7236@kindex info methods
7237@item info methods
7238@itemx info methods @var{regexp}
7239The @code{info methods} command permits the user to examine all defined
7240methods within C++ program, or (with the @var{regexp} argument) a
7241specific set of methods found in the various C++ classes. Many
7242C++ classes provide a large number of methods. Thus, the output
7243from the @code{ptype} command can be overwhelming and hard to use. The
7244@code{info-methods} command filters the methods, printing only those
7245which match the regular-expression @var{regexp}.
7246@end ignore
7247
c906108c
SS
7248@cindex reloading symbols
7249Some systems allow individual object files that make up your program to
7a292a7a
SS
7250be replaced without stopping and restarting your program. For example,
7251in VxWorks you can simply recompile a defective object file and keep on
7252running. If you are running on one of these systems, you can allow
7253@value{GDBN} to reload the symbols for automatically relinked modules:
c906108c
SS
7254
7255@table @code
7256@kindex set symbol-reloading
7257@item set symbol-reloading on
7258Replace symbol definitions for the corresponding source file when an
7259object file with a particular name is seen again.
7260
7261@item set symbol-reloading off
7262Do not replace symbol definitions when re-encountering object files of
7263the same name. This is the default state; if you are not running on a
7264system that permits automatically relinking modules, you should leave
7265@code{symbol-reloading} off, since otherwise @value{GDBN} may discard symbols
7266when linking large programs, that may contain several modules (from
7267different directories or libraries) with the same name.
7268
7269@kindex show symbol-reloading
7270@item show symbol-reloading
7271Show the current @code{on} or @code{off} setting.
7272@end table
c906108c 7273
c906108c
SS
7274@kindex set opaque-type-resolution
7275@item set opaque-type-resolution on
7276Tell @value{GDBN} to resolve opaque types. An opaque type is a type
7277declared as a pointer to a @code{struct}, @code{class}, or
7278@code{union}---for example, @code{struct MyType *}---that is used in one
7279source file although the full declaration of @code{struct MyType} is in
7280another source file. The default is on.
7281
7282A change in the setting of this subcommand will not take effect until
7283the next time symbols for a file are loaded.
7284
7285@item set opaque-type-resolution off
7286Tell @value{GDBN} not to resolve opaque types. In this case, the type
7287is printed as follows:
7288@smallexample
7289@{<no data fields>@}
7290@end smallexample
7291
7292@kindex show opaque-type-resolution
7293@item show opaque-type-resolution
7294Show whether opaque types are resolved or not.
c906108c
SS
7295
7296@kindex maint print symbols
7297@cindex symbol dump
7298@kindex maint print psymbols
7299@cindex partial symbol dump
7300@item maint print symbols @var{filename}
7301@itemx maint print psymbols @var{filename}
7302@itemx maint print msymbols @var{filename}
7303Write a dump of debugging symbol data into the file @var{filename}.
7304These commands are used to debug the @value{GDBN} symbol-reading code. Only
7305symbols with debugging data are included. If you use @samp{maint print
7306symbols}, @value{GDBN} includes all the symbols for which it has already
7307collected full details: that is, @var{filename} reflects symbols for
7308only those files whose symbols @value{GDBN} has read. You can use the
7309command @code{info sources} to find out which files these are. If you
7310use @samp{maint print psymbols} instead, the dump shows information about
7311symbols that @value{GDBN} only knows partially---that is, symbols defined in
7312files that @value{GDBN} has skimmed, but not yet read completely. Finally,
7313@samp{maint print msymbols} dumps just the minimal symbol information
7314required for each object file from which @value{GDBN} has read some symbols.
7315@xref{Files, ,Commands to specify files}, for a discussion of how
7316@value{GDBN} reads symbols (in the description of @code{symbol-file}).
7317@end table
7318
53a5351d 7319@node Altering
c906108c
SS
7320@chapter Altering Execution
7321
7322Once you think you have found an error in your program, you might want to
7323find out for certain whether correcting the apparent error would lead to
7324correct results in the rest of the run. You can find the answer by
7325experiment, using the @value{GDBN} features for altering execution of the
7326program.
7327
7328For example, you can store new values into variables or memory
7a292a7a
SS
7329locations, give your program a signal, restart it at a different
7330address, or even return prematurely from a function.
c906108c
SS
7331
7332@menu
7333* Assignment:: Assignment to variables
7334* Jumping:: Continuing at a different address
c906108c 7335* Signaling:: Giving your program a signal
c906108c
SS
7336* Returning:: Returning from a function
7337* Calling:: Calling your program's functions
7338* Patching:: Patching your program
7339@end menu
7340
53a5351d 7341@node Assignment
c906108c
SS
7342@section Assignment to variables
7343
7344@cindex assignment
7345@cindex setting variables
7346To alter the value of a variable, evaluate an assignment expression.
7347@xref{Expressions, ,Expressions}. For example,
7348
7349@example
7350print x=4
7351@end example
7352
7353@noindent
7354stores the value 4 into the variable @code{x}, and then prints the
7355value of the assignment expression (which is 4).
c906108c
SS
7356@xref{Languages, ,Using @value{GDBN} with Different Languages}, for more
7357information on operators in supported languages.
c906108c
SS
7358
7359@kindex set variable
7360@cindex variables, setting
7361If you are not interested in seeing the value of the assignment, use the
7362@code{set} command instead of the @code{print} command. @code{set} is
7363really the same as @code{print} except that the expression's value is
7364not printed and is not put in the value history (@pxref{Value History,
7365,Value history}). The expression is evaluated only for its effects.
7366
c906108c
SS
7367If the beginning of the argument string of the @code{set} command
7368appears identical to a @code{set} subcommand, use the @code{set
7369variable} command instead of just @code{set}. This command is identical
7370to @code{set} except for its lack of subcommands. For example, if your
7371program has a variable @code{width}, you get an error if you try to set
7372a new value with just @samp{set width=13}, because @value{GDBN} has the
7373command @code{set width}:
7374
7375@example
7376(@value{GDBP}) whatis width
7377type = double
7378(@value{GDBP}) p width
7379$4 = 13
7380(@value{GDBP}) set width=47
7381Invalid syntax in expression.
7382@end example
7383
7384@noindent
7385The invalid expression, of course, is @samp{=47}. In
7386order to actually set the program's variable @code{width}, use
7387
7388@example
7389(@value{GDBP}) set var width=47
7390@end example
53a5351d 7391
c906108c
SS
7392Because the @code{set} command has many subcommands that can conflict
7393with the names of program variables, it is a good idea to use the
7394@code{set variable} command instead of just @code{set}. For example, if
7395your program has a variable @code{g}, you run into problems if you try
7396to set a new value with just @samp{set g=4}, because @value{GDBN} has
7397the command @code{set gnutarget}, abbreviated @code{set g}:
7398
7399@example
7400@group
7401(@value{GDBP}) whatis g
7402type = double
7403(@value{GDBP}) p g
7404$1 = 1
7405(@value{GDBP}) set g=4
2df3850c 7406(@value{GDBP}) p g
c906108c
SS
7407$2 = 1
7408(@value{GDBP}) r
7409The program being debugged has been started already.
7410Start it from the beginning? (y or n) y
7411Starting program: /home/smith/cc_progs/a.out
7412"/home/smith/cc_progs/a.out": can't open to read symbols: Invalid bfd target.
7413(@value{GDBP}) show g
7414The current BFD target is "=4".
7415@end group
7416@end example
7417
7418@noindent
7419The program variable @code{g} did not change, and you silently set the
7420@code{gnutarget} to an invalid value. In order to set the variable
7421@code{g}, use
7422
7423@example
7424(@value{GDBP}) set var g=4
7425@end example
c906108c
SS
7426
7427@value{GDBN} allows more implicit conversions in assignments than C; you can
7428freely store an integer value into a pointer variable or vice versa,
7429and you can convert any structure to any other structure that is the
7430same length or shorter.
7431@comment FIXME: how do structs align/pad in these conversions?
7432@comment /doc@cygnus.com 18dec1990
7433
7434To store values into arbitrary places in memory, use the @samp{@{@dots{}@}}
7435construct to generate a value of specified type at a specified address
7436(@pxref{Expressions, ,Expressions}). For example, @code{@{int@}0x83040} refers
7437to memory location @code{0x83040} as an integer (which implies a certain size
7438and representation in memory), and
7439
7440@example
7441set @{int@}0x83040 = 4
7442@end example
7443
7444@noindent
7445stores the value 4 into that memory location.
7446
53a5351d 7447@node Jumping
c906108c
SS
7448@section Continuing at a different address
7449
7450Ordinarily, when you continue your program, you do so at the place where
7451it stopped, with the @code{continue} command. You can instead continue at
7452an address of your own choosing, with the following commands:
7453
7454@table @code
7455@kindex jump
7456@item jump @var{linespec}
7457Resume execution at line @var{linespec}. Execution stops again
7458immediately if there is a breakpoint there. @xref{List, ,Printing
7459source lines}, for a description of the different forms of
7460@var{linespec}. It is common practice to use the @code{tbreak} command
7461in conjunction with @code{jump}. @xref{Set Breaks, ,Setting
7462breakpoints}.
7463
7464The @code{jump} command does not change the current stack frame, or
7465the stack pointer, or the contents of any memory location or any
7466register other than the program counter. If line @var{linespec} is in
7467a different function from the one currently executing, the results may
7468be bizarre if the two functions expect different patterns of arguments or
7469of local variables. For this reason, the @code{jump} command requests
7470confirmation if the specified line is not in the function currently
7471executing. However, even bizarre results are predictable if you are
7472well acquainted with the machine-language code of your program.
7473
7474@item jump *@var{address}
7475Resume execution at the instruction at address @var{address}.
7476@end table
7477
c906108c 7478@c Doesn't work on HP-UX; have to set $pcoqh and $pcoqt.
53a5351d
JM
7479On many systems, you can get much the same effect as the @code{jump}
7480command by storing a new value into the register @code{$pc}. The
7481difference is that this does not start your program running; it only
7482changes the address of where it @emph{will} run when you continue. For
7483example,
c906108c
SS
7484
7485@example
7486set $pc = 0x485
7487@end example
7488
7489@noindent
7490makes the next @code{continue} command or stepping command execute at
7491address @code{0x485}, rather than at the address where your program stopped.
7492@xref{Continuing and Stepping, ,Continuing and stepping}.
c906108c
SS
7493
7494The most common occasion to use the @code{jump} command is to back
7495up---perhaps with more breakpoints set---over a portion of a program
7496that has already executed, in order to examine its execution in more
7497detail.
7498
c906108c 7499@c @group
53a5351d 7500@node Signaling
c906108c
SS
7501@section Giving your program a signal
7502
7503@table @code
7504@kindex signal
7505@item signal @var{signal}
7506Resume execution where your program stopped, but immediately give it the
7507signal @var{signal}. @var{signal} can be the name or the number of a
7508signal. For example, on many systems @code{signal 2} and @code{signal
7509SIGINT} are both ways of sending an interrupt signal.
7510
7511Alternatively, if @var{signal} is zero, continue execution without
7512giving a signal. This is useful when your program stopped on account of
7513a signal and would ordinary see the signal when resumed with the
7514@code{continue} command; @samp{signal 0} causes it to resume without a
7515signal.
7516
7517@code{signal} does not repeat when you press @key{RET} a second time
7518after executing the command.
7519@end table
7520@c @end group
7521
7522Invoking the @code{signal} command is not the same as invoking the
7523@code{kill} utility from the shell. Sending a signal with @code{kill}
7524causes @value{GDBN} to decide what to do with the signal depending on
7525the signal handling tables (@pxref{Signals}). The @code{signal} command
7526passes the signal directly to your program.
7527
c906108c 7528
53a5351d 7529@node Returning
c906108c
SS
7530@section Returning from a function
7531
7532@table @code
7533@cindex returning from a function
7534@kindex return
7535@item return
7536@itemx return @var{expression}
7537You can cancel execution of a function call with the @code{return}
7538command. If you give an
7539@var{expression} argument, its value is used as the function's return
7540value.
7541@end table
7542
7543When you use @code{return}, @value{GDBN} discards the selected stack frame
7544(and all frames within it). You can think of this as making the
7545discarded frame return prematurely. If you wish to specify a value to
7546be returned, give that value as the argument to @code{return}.
7547
7548This pops the selected stack frame (@pxref{Selection, ,Selecting a
7549frame}), and any other frames inside of it, leaving its caller as the
7550innermost remaining frame. That frame becomes selected. The
7551specified value is stored in the registers used for returning values
7552of functions.
7553
7554The @code{return} command does not resume execution; it leaves the
7555program stopped in the state that would exist if the function had just
7556returned. In contrast, the @code{finish} command (@pxref{Continuing
7557and Stepping, ,Continuing and stepping}) resumes execution until the
7558selected stack frame returns naturally.
7559
53a5351d 7560@node Calling
c906108c
SS
7561@section Calling program functions
7562
7563@cindex calling functions
7564@kindex call
7565@table @code
7566@item call @var{expr}
7567Evaluate the expression @var{expr} without displaying @code{void}
7568returned values.
7569@end table
7570
7571You can use this variant of the @code{print} command if you want to
7572execute a function from your program, but without cluttering the output
7573with @code{void} returned values. If the result is not void, it
7574is printed and saved in the value history.
7575
c906108c
SS
7576For the A29K, a user-controlled variable @code{call_scratch_address},
7577specifies the location of a scratch area to be used when @value{GDBN}
7578calls a function in the target. This is necessary because the usual
7579method of putting the scratch area on the stack does not work in systems
7580that have separate instruction and data spaces.
c906108c 7581
53a5351d 7582@node Patching
c906108c 7583@section Patching programs
7a292a7a 7584
c906108c
SS
7585@cindex patching binaries
7586@cindex writing into executables
c906108c 7587@cindex writing into corefiles
c906108c 7588
7a292a7a
SS
7589By default, @value{GDBN} opens the file containing your program's
7590executable code (or the corefile) read-only. This prevents accidental
7591alterations to machine code; but it also prevents you from intentionally
7592patching your program's binary.
c906108c
SS
7593
7594If you'd like to be able to patch the binary, you can specify that
7595explicitly with the @code{set write} command. For example, you might
7596want to turn on internal debugging flags, or even to make emergency
7597repairs.
7598
7599@table @code
7600@kindex set write
7601@item set write on
7602@itemx set write off
7a292a7a
SS
7603If you specify @samp{set write on}, @value{GDBN} opens executable and
7604core files for both reading and writing; if you specify @samp{set write
c906108c
SS
7605off} (the default), @value{GDBN} opens them read-only.
7606
7607If you have already loaded a file, you must load it again (using the
7a292a7a
SS
7608@code{exec-file} or @code{core-file} command) after changing @code{set
7609write}, for your new setting to take effect.
c906108c
SS
7610
7611@item show write
7612@kindex show write
7a292a7a
SS
7613Display whether executable files and core files are opened for writing
7614as well as reading.
c906108c
SS
7615@end table
7616
53a5351d 7617@node GDB Files
c906108c
SS
7618@chapter @value{GDBN} Files
7619
7a292a7a
SS
7620@value{GDBN} needs to know the file name of the program to be debugged,
7621both in order to read its symbol table and in order to start your
7622program. To debug a core dump of a previous run, you must also tell
7623@value{GDBN} the name of the core dump file.
c906108c
SS
7624
7625@menu
7626* Files:: Commands to specify files
7627* Symbol Errors:: Errors reading symbol files
7628@end menu
7629
53a5351d 7630@node Files
c906108c 7631@section Commands to specify files
c906108c 7632
7a292a7a 7633@cindex symbol table
c906108c 7634@cindex core dump file
7a292a7a
SS
7635
7636You may want to specify executable and core dump file names. The usual
7637way to do this is at start-up time, using the arguments to
7638@value{GDBN}'s start-up commands (@pxref{Invocation, , Getting In and
7639Out of @value{GDBN}}).
c906108c
SS
7640
7641Occasionally it is necessary to change to a different file during a
7642@value{GDBN} session. Or you may run @value{GDBN} and forget to specify
7643a file you want to use. In these situations the @value{GDBN} commands
7644to specify new files are useful.
7645
7646@table @code
7647@cindex executable file
7648@kindex file
7649@item file @var{filename}
7650Use @var{filename} as the program to be debugged. It is read for its
7651symbols and for the contents of pure memory. It is also the program
7652executed when you use the @code{run} command. If you do not specify a
7653directory and the file is not found in the @value{GDBN} working directory,
7654@value{GDBN} uses the environment variable @code{PATH} as a list of
7655directories to search, just as the shell does when looking for a program
7656to run. You can change the value of this variable, for both @value{GDBN}
7657and your program, using the @code{path} command.
7658
c906108c
SS
7659On systems with memory-mapped files, an auxiliary file
7660@file{@var{filename}.syms} may hold symbol table information for
7661@var{filename}. If so, @value{GDBN} maps in the symbol table from
7662@file{@var{filename}.syms}, starting up more quickly. See the
7663descriptions of the file options @samp{-mapped} and @samp{-readnow}
7664(available on the command line, and with the commands @code{file},
7665@code{symbol-file}, or @code{add-symbol-file}, described below),
7666for more information.
c906108c
SS
7667
7668@item file
7669@code{file} with no argument makes @value{GDBN} discard any information it
7670has on both executable file and the symbol table.
7671
7672@kindex exec-file
7673@item exec-file @r{[} @var{filename} @r{]}
7674Specify that the program to be run (but not the symbol table) is found
7675in @var{filename}. @value{GDBN} searches the environment variable @code{PATH}
7676if necessary to locate your program. Omitting @var{filename} means to
7677discard information on the executable file.
7678
7679@kindex symbol-file
7680@item symbol-file @r{[} @var{filename} @r{]}
7681Read symbol table information from file @var{filename}. @code{PATH} is
7682searched when necessary. Use the @code{file} command to get both symbol
7683table and program to run from the same file.
7684
7685@code{symbol-file} with no argument clears out @value{GDBN} information on your
7686program's symbol table.
7687
7688The @code{symbol-file} command causes @value{GDBN} to forget the contents
7689of its convenience variables, the value history, and all breakpoints and
7690auto-display expressions. This is because they may contain pointers to
7691the internal data recording symbols and data types, which are part of
7692the old symbol table data being discarded inside @value{GDBN}.
7693
7694@code{symbol-file} does not repeat if you press @key{RET} again after
7695executing it once.
7696
7697When @value{GDBN} is configured for a particular environment, it
7698understands debugging information in whatever format is the standard
7699generated for that environment; you may use either a @sc{gnu} compiler, or
7700other compilers that adhere to the local conventions.
c906108c
SS
7701Best results are usually obtained from @sc{gnu} compilers; for example,
7702using @code{@value{GCC}} you can generate debugging information for
7703optimized code.
c906108c
SS
7704
7705For most kinds of object files, with the exception of old SVR3 systems
7706using COFF, the @code{symbol-file} command does not normally read the
7707symbol table in full right away. Instead, it scans the symbol table
7708quickly to find which source files and which symbols are present. The
7709details are read later, one source file at a time, as they are needed.
7710
7711The purpose of this two-stage reading strategy is to make @value{GDBN}
7712start up faster. For the most part, it is invisible except for
7713occasional pauses while the symbol table details for a particular source
7714file are being read. (The @code{set verbose} command can turn these
7715pauses into messages if desired. @xref{Messages/Warnings, ,Optional
7716warnings and messages}.)
7717
c906108c
SS
7718We have not implemented the two-stage strategy for COFF yet. When the
7719symbol table is stored in COFF format, @code{symbol-file} reads the
7720symbol table data in full right away. Note that ``stabs-in-COFF''
7721still does the two-stage strategy, since the debug info is actually
7722in stabs format.
7723
7724@kindex readnow
7725@cindex reading symbols immediately
7726@cindex symbols, reading immediately
7727@kindex mapped
7728@cindex memory-mapped symbol file
7729@cindex saving symbol table
7730@item symbol-file @var{filename} @r{[} -readnow @r{]} @r{[} -mapped @r{]}
7731@itemx file @var{filename} @r{[} -readnow @r{]} @r{[} -mapped @r{]}
7732You can override the @value{GDBN} two-stage strategy for reading symbol
7733tables by using the @samp{-readnow} option with any of the commands that
7734load symbol table information, if you want to be sure @value{GDBN} has the
7735entire symbol table available.
c906108c 7736
c906108c
SS
7737If memory-mapped files are available on your system through the
7738@code{mmap} system call, you can use another option, @samp{-mapped}, to
7739cause @value{GDBN} to write the symbols for your program into a reusable
7740file. Future @value{GDBN} debugging sessions map in symbol information
7741from this auxiliary symbol file (if the program has not changed), rather
7742than spending time reading the symbol table from the executable
7743program. Using the @samp{-mapped} option has the same effect as
7744starting @value{GDBN} with the @samp{-mapped} command-line option.
7745
7746You can use both options together, to make sure the auxiliary symbol
7747file has all the symbol information for your program.
7748
7749The auxiliary symbol file for a program called @var{myprog} is called
7750@samp{@var{myprog}.syms}. Once this file exists (so long as it is newer
7751than the corresponding executable), @value{GDBN} always attempts to use
7752it when you debug @var{myprog}; no special options or commands are
7753needed.
7754
7755The @file{.syms} file is specific to the host machine where you run
7756@value{GDBN}. It holds an exact image of the internal @value{GDBN}
7757symbol table. It cannot be shared across multiple host platforms.
c906108c
SS
7758
7759@c FIXME: for now no mention of directories, since this seems to be in
7760@c flux. 13mar1992 status is that in theory GDB would look either in
7761@c current dir or in same dir as myprog; but issues like competing
7762@c GDB's, or clutter in system dirs, mean that in practice right now
7763@c only current dir is used. FFish says maybe a special GDB hierarchy
7764@c (eg rooted in val of env var GDBSYMS) could exist for mappable symbol
7765@c files.
7766
7767@kindex core
7768@kindex core-file
7769@item core-file @r{[} @var{filename} @r{]}
7770Specify the whereabouts of a core dump file to be used as the ``contents
7771of memory''. Traditionally, core files contain only some parts of the
7772address space of the process that generated them; @value{GDBN} can access the
7773executable file itself for other parts.
7774
7775@code{core-file} with no argument specifies that no core file is
7776to be used.
7777
7778Note that the core file is ignored when your program is actually running
7a292a7a
SS
7779under @value{GDBN}. So, if you have been running your program and you
7780wish to debug a core file instead, you must kill the subprocess in which
7781the program is running. To do this, use the @code{kill} command
c906108c 7782(@pxref{Kill Process, ,Killing the child process}).
c906108c 7783
c906108c
SS
7784@kindex add-symbol-file
7785@cindex dynamic linking
7786@item add-symbol-file @var{filename} @var{address}
7787@itemx add-symbol-file @var{filename} @var{address} @r{[} -readnow @r{]} @r{[} -mapped @r{]}
2acceee2
JM
7788@itemx add-symbol-file @var{filename} @var{address} @var{data_address} @var{bss_address}
7789@itemx add-symbol-file @var{filename} @r{-T}@var{section} @var{address}
c906108c
SS
7790The @code{add-symbol-file} command reads additional symbol table information
7791from the file @var{filename}. You would use this command when @var{filename}
7792has been dynamically loaded (by some other means) into the program that
7793is running. @var{address} should be the memory address at which the
7794file has been loaded; @value{GDBN} cannot figure this out for itself.
2acceee2
JM
7795You can specify up to three addresses, in which case they are taken to be
7796the addresses of the text, data, and bss segments respectively.
7797For complicated cases, you can specify an arbitrary number of @r{-T}@var{section} @var{address}
7798pairs, to give an explicit section name and base address for that section.
7799You can specify any @var{address} as an expression.
c906108c
SS
7800
7801The symbol table of the file @var{filename} is added to the symbol table
7802originally read with the @code{symbol-file} command. You can use the
7803@code{add-symbol-file} command any number of times; the new symbol data thus
7804read keeps adding to the old. To discard all old symbol data instead,
7805use the @code{symbol-file} command.
7806
7807@code{add-symbol-file} does not repeat if you press @key{RET} after using it.
7808
7809You can use the @samp{-mapped} and @samp{-readnow} options just as with
7810the @code{symbol-file} command, to change how @value{GDBN} manages the symbol
7811table information for @var{filename}.
7812
7813@kindex add-shared-symbol-file
7814@item add-shared-symbol-file
7815The @code{add-shared-symbol-file} command can be used only under Harris' CXUX
7816operating system for the Motorola 88k. @value{GDBN} automatically looks for
7817shared libraries, however if @value{GDBN} does not find yours, you can run
7818@code{add-shared-symbol-file}. It takes no arguments.
c906108c 7819
c906108c
SS
7820@kindex section
7821@item section
7822The @code{section} command changes the base address of section SECTION of
7823the exec file to ADDR. This can be used if the exec file does not contain
7824section addresses, (such as in the a.out format), or when the addresses
7825specified in the file itself are wrong. Each section must be changed
d4f3574e
SS
7826separately. The @code{info files} command, described below, lists all
7827the sections and their addresses.
c906108c
SS
7828
7829@kindex info files
7830@kindex info target
7831@item info files
7832@itemx info target
7a292a7a
SS
7833@code{info files} and @code{info target} are synonymous; both print the
7834current target (@pxref{Targets, ,Specifying a Debugging Target}),
7835including the names of the executable and core dump files currently in
7836use by @value{GDBN}, and the files from which symbols were loaded. The
7837command @code{help target} lists all possible targets rather than
7838current ones.
7839
c906108c
SS
7840@end table
7841
7842All file-specifying commands allow both absolute and relative file names
7843as arguments. @value{GDBN} always converts the file name to an absolute file
7844name and remembers it that way.
7845
c906108c 7846@cindex shared libraries
c906108c
SS
7847@value{GDBN} supports HP-UX, SunOS, SVr4, Irix 5, and IBM RS/6000 shared
7848libraries.
53a5351d 7849
c906108c
SS
7850@value{GDBN} automatically loads symbol definitions from shared libraries
7851when you use the @code{run} command, or when you examine a core file.
7852(Before you issue the @code{run} command, @value{GDBN} does not understand
7853references to a function in a shared library, however---unless you are
7854debugging a core file).
53a5351d
JM
7855
7856On HP-UX, if the program loads a library explicitly, @value{GDBN}
7857automatically loads the symbols at the time of the @code{shl_load} call.
7858
c906108c
SS
7859@c FIXME: some @value{GDBN} release may permit some refs to undef
7860@c FIXME...symbols---eg in a break cmd---assuming they are from a shared
7861@c FIXME...lib; check this from time to time when updating manual
7862
7863@table @code
7864@kindex info sharedlibrary
7865@kindex info share
7866@item info share
7867@itemx info sharedlibrary
7868Print the names of the shared libraries which are currently loaded.
7869
7870@kindex sharedlibrary
7871@kindex share
7872@item sharedlibrary @var{regex}
7873@itemx share @var{regex}
c906108c
SS
7874Load shared object library symbols for files matching a
7875Unix regular expression.
7876As with files loaded automatically, it only loads shared libraries
7877required by your program for a core file or after typing @code{run}. If
7878@var{regex} is omitted all shared libraries required by your program are
7879loaded.
7880@end table
7881
53a5351d
JM
7882On HP-UX systems, @value{GDBN} detects the loading of a shared library
7883and automatically reads in symbols from the newly loaded library, up to
7884a threshold that is initially set but that you can modify if you wish.
c906108c
SS
7885
7886Beyond that threshold, symbols from shared libraries must be explicitly
d4f3574e
SS
7887loaded. To load these symbols, use the command @code{sharedlibrary
7888@var{filename}}. The base address of the shared library is determined
c906108c
SS
7889automatically by @value{GDBN} and need not be specified.
7890
7891To display or set the threshold, use the commands:
7892
7893@table @code
7894@kindex set auto-solib-add
7895@item set auto-solib-add @var{threshold}
7896Set the autoloading size threshold, in megabytes. If @var{threshold} is
7897nonzero, symbols from all shared object libraries will be loaded
7898automatically when the inferior begins execution or when the dynamic
7899linker informs @value{GDBN} that a new library has been loaded, until
7900the symbol table of the program and libraries exceeds this threshold.
7901Otherwise, symbols must be loaded manually, using the
7902@code{sharedlibrary} command. The default threshold is 100 megabytes.
7903
7904@kindex show auto-solib-add
7905@item show auto-solib-add
7906Display the current autoloading size threshold, in megabytes.
7907@end table
c906108c 7908
53a5351d 7909@node Symbol Errors
c906108c
SS
7910@section Errors reading symbol files
7911
7912While reading a symbol file, @value{GDBN} occasionally encounters problems,
7913such as symbol types it does not recognize, or known bugs in compiler
7914output. By default, @value{GDBN} does not notify you of such problems, since
7915they are relatively common and primarily of interest to people
7916debugging compilers. If you are interested in seeing information
7917about ill-constructed symbol tables, you can either ask @value{GDBN} to print
7918only one message about each such type of problem, no matter how many
7919times the problem occurs; or you can ask @value{GDBN} to print more messages,
7920to see how many times the problems occur, with the @code{set
7921complaints} command (@pxref{Messages/Warnings, ,Optional warnings and
7922messages}).
7923
7924The messages currently printed, and their meanings, include:
7925
7926@table @code
7927@item inner block not inside outer block in @var{symbol}
7928
7929The symbol information shows where symbol scopes begin and end
7930(such as at the start of a function or a block of statements). This
7931error indicates that an inner scope block is not fully contained
7932in its outer scope blocks.
7933
7934@value{GDBN} circumvents the problem by treating the inner block as if it had
7935the same scope as the outer block. In the error message, @var{symbol}
7936may be shown as ``@code{(don't know)}'' if the outer block is not a
7937function.
7938
7939@item block at @var{address} out of order
7940
7941The symbol information for symbol scope blocks should occur in
7942order of increasing addresses. This error indicates that it does not
7943do so.
7944
7945@value{GDBN} does not circumvent this problem, and has trouble
7946locating symbols in the source file whose symbols it is reading. (You
7947can often determine what source file is affected by specifying
7948@code{set verbose on}. @xref{Messages/Warnings, ,Optional warnings and
7949messages}.)
7950
7951@item bad block start address patched
7952
7953The symbol information for a symbol scope block has a start address
7954smaller than the address of the preceding source line. This is known
7955to occur in the SunOS 4.1.1 (and earlier) C compiler.
7956
7957@value{GDBN} circumvents the problem by treating the symbol scope block as
7958starting on the previous source line.
7959
7960@item bad string table offset in symbol @var{n}
7961
7962@cindex foo
7963Symbol number @var{n} contains a pointer into the string table which is
7964larger than the size of the string table.
7965
7966@value{GDBN} circumvents the problem by considering the symbol to have the
7967name @code{foo}, which may cause other problems if many symbols end up
7968with this name.
7969
7970@item unknown symbol type @code{0x@var{nn}}
7971
7a292a7a
SS
7972The symbol information contains new data types that @value{GDBN} does
7973not yet know how to read. @code{0x@var{nn}} is the symbol type of the
d4f3574e 7974uncomprehended information, in hexadecimal.
c906108c 7975
7a292a7a
SS
7976@value{GDBN} circumvents the error by ignoring this symbol information.
7977This usually allows you to debug your program, though certain symbols
c906108c 7978are not accessible. If you encounter such a problem and feel like
7a292a7a
SS
7979debugging it, you can debug @code{@value{GDBP}} with itself, breakpoint
7980on @code{complain}, then go up to the function @code{read_dbx_symtab}
7981and examine @code{*bufp} to see the symbol.
c906108c
SS
7982
7983@item stub type has NULL name
c906108c 7984
7a292a7a 7985@value{GDBN} could not find the full definition for a struct or class.
c906108c 7986
7a292a7a 7987@item const/volatile indicator missing (ok if using g++ v1.x), got@dots{}
c906108c 7988The symbol information for a C++ member function is missing some
7a292a7a
SS
7989information that recent versions of the compiler should have output for
7990it.
c906108c
SS
7991
7992@item info mismatch between compiler and debugger
7993
7994@value{GDBN} could not parse a type specification output by the compiler.
7a292a7a 7995
c906108c
SS
7996@end table
7997
53a5351d 7998@node Targets
c906108c 7999@chapter Specifying a Debugging Target
7a292a7a 8000
c906108c
SS
8001@cindex debugging target
8002@kindex target
8003
8004A @dfn{target} is the execution environment occupied by your program.
53a5351d
JM
8005
8006Often, @value{GDBN} runs in the same host environment as your program;
8007in that case, the debugging target is specified as a side effect when
8008you use the @code{file} or @code{core} commands. When you need more
c906108c
SS
8009flexibility---for example, running @value{GDBN} on a physically separate
8010host, or controlling a standalone system over a serial port or a
53a5351d
JM
8011realtime system over a TCP/IP connection---you can use the @code{target}
8012command to specify one of the target types configured for @value{GDBN}
8013(@pxref{Target Commands, ,Commands for managing targets}).
c906108c
SS
8014
8015@menu
8016* Active Targets:: Active targets
8017* Target Commands:: Commands for managing targets
c906108c
SS
8018* Byte Order:: Choosing target byte order
8019* Remote:: Remote debugging
96baa820 8020* KOD:: Kernel Object Display
c906108c
SS
8021
8022@end menu
8023
53a5351d 8024@node Active Targets
c906108c 8025@section Active targets
7a292a7a 8026
c906108c
SS
8027@cindex stacking targets
8028@cindex active targets
8029@cindex multiple targets
8030
c906108c 8031There are three classes of targets: processes, core files, and
7a292a7a
SS
8032executable files. @value{GDBN} can work concurrently on up to three
8033active targets, one in each class. This allows you to (for example)
8034start a process and inspect its activity without abandoning your work on
8035a core file.
c906108c
SS
8036
8037For example, if you execute @samp{gdb a.out}, then the executable file
8038@code{a.out} is the only active target. If you designate a core file as
8039well---presumably from a prior run that crashed and coredumped---then
8040@value{GDBN} has two active targets and uses them in tandem, looking
8041first in the corefile target, then in the executable file, to satisfy
8042requests for memory addresses. (Typically, these two classes of target
8043are complementary, since core files contain only a program's
8044read-write memory---variables and so on---plus machine status, while
8045executable files contain only the program text and initialized data.)
c906108c
SS
8046
8047When you type @code{run}, your executable file becomes an active process
7a292a7a
SS
8048target as well. When a process target is active, all @value{GDBN}
8049commands requesting memory addresses refer to that target; addresses in
8050an active core file or executable file target are obscured while the
8051process target is active.
c906108c 8052
7a292a7a
SS
8053Use the @code{core-file} and @code{exec-file} commands to select a new
8054core file or executable target (@pxref{Files, ,Commands to specify
c906108c 8055files}). To specify as a target a process that is already running, use
7a292a7a
SS
8056the @code{attach} command (@pxref{Attach, ,Debugging an already-running
8057process}).
c906108c 8058
53a5351d 8059@node Target Commands
c906108c
SS
8060@section Commands for managing targets
8061
8062@table @code
8063@item target @var{type} @var{parameters}
7a292a7a
SS
8064Connects the @value{GDBN} host environment to a target machine or
8065process. A target is typically a protocol for talking to debugging
8066facilities. You use the argument @var{type} to specify the type or
8067protocol of the target machine.
c906108c
SS
8068
8069Further @var{parameters} are interpreted by the target protocol, but
8070typically include things like device names or host names to connect
8071with, process numbers, and baud rates.
c906108c
SS
8072
8073The @code{target} command does not repeat if you press @key{RET} again
8074after executing the command.
8075
8076@kindex help target
8077@item help target
8078Displays the names of all targets available. To display targets
8079currently selected, use either @code{info target} or @code{info files}
8080(@pxref{Files, ,Commands to specify files}).
8081
8082@item help target @var{name}
8083Describe a particular target, including any parameters necessary to
8084select it.
8085
8086@kindex set gnutarget
8087@item set gnutarget @var{args}
8088@value{GDBN} uses its own library BFD to read your files. @value{GDBN}
8089knows whether it is reading an @dfn{executable},
8090a @dfn{core}, or a @dfn{.o} file; however, you can specify the file format
8091with the @code{set gnutarget} command. Unlike most @code{target} commands,
8092with @code{gnutarget} the @code{target} refers to a program, not a machine.
8093
d4f3574e 8094@quotation
c906108c
SS
8095@emph{Warning:} To specify a file format with @code{set gnutarget},
8096you must know the actual BFD name.
d4f3574e 8097@end quotation
c906108c 8098
d4f3574e
SS
8099@noindent
8100@xref{Files, , Commands to specify files}.
c906108c
SS
8101
8102@kindex show gnutarget
8103@item show gnutarget
8104Use the @code{show gnutarget} command to display what file format
8105@code{gnutarget} is set to read. If you have not set @code{gnutarget},
8106@value{GDBN} will determine the file format for each file automatically,
8107and @code{show gnutarget} displays @samp{The current BDF target is "auto"}.
8108@end table
8109
c906108c
SS
8110Here are some common targets (available, or not, depending on the GDB
8111configuration):
c906108c
SS
8112
8113@table @code
8114@kindex target exec
8115@item target exec @var{program}
8116An executable file. @samp{target exec @var{program}} is the same as
8117@samp{exec-file @var{program}}.
8118
c906108c
SS
8119@kindex target core
8120@item target core @var{filename}
8121A core dump file. @samp{target core @var{filename}} is the same as
8122@samp{core-file @var{filename}}.
c906108c
SS
8123
8124@kindex target remote
8125@item target remote @var{dev}
8126Remote serial target in GDB-specific protocol. The argument @var{dev}
8127specifies what serial device to use for the connection (e.g.
8128@file{/dev/ttya}). @xref{Remote, ,Remote debugging}. @code{target remote}
d4f3574e 8129supports the @code{load} command. This is only useful if you have
c906108c
SS
8130some other way of getting the stub to the target system, and you can put
8131it somewhere in memory where it won't get clobbered by the download.
8132
c906108c
SS
8133@kindex target sim
8134@item target sim
2df3850c 8135Builtin CPU simulator. @value{GDBN} includes simulators for most architectures.
104c1213
JM
8136In general,
8137@example
8138 target sim
8139 load
8140 run
8141@end example
d4f3574e 8142@noindent
104c1213 8143works; however, you cannot assume that a specific memory map, device
d4f3574e 8144drivers, or even basic I/O is available, although some simulators do
104c1213
JM
8145provide these. For info about any processor-specific simulator details,
8146see the appropriate section in @ref{Embedded Processors, ,Embedded
8147Processors}.
8148
c906108c
SS
8149@end table
8150
104c1213 8151Some configurations may include these targets as well:
c906108c
SS
8152
8153@table @code
8154
c906108c
SS
8155@kindex target nrom
8156@item target nrom @var{dev}
8157NetROM ROM emulator. This target only supports downloading.
8158
c906108c
SS
8159@end table
8160
c906108c
SS
8161Different targets are available on different configurations of @value{GDBN};
8162your configuration may have more or fewer targets.
c906108c
SS
8163
8164Many remote targets require you to download the executable's code
8165once you've successfully established a connection.
8166
8167@table @code
8168
8169@kindex load @var{filename}
8170@item load @var{filename}
c906108c
SS
8171Depending on what remote debugging facilities are configured into
8172@value{GDBN}, the @code{load} command may be available. Where it exists, it
8173is meant to make @var{filename} (an executable) available for debugging
8174on the remote system---by downloading, or dynamic linking, for example.
8175@code{load} also records the @var{filename} symbol table in @value{GDBN}, like
8176the @code{add-symbol-file} command.
8177
8178If your @value{GDBN} does not have a @code{load} command, attempting to
8179execute it gets the error message ``@code{You can't do that when your
8180target is @dots{}}''
c906108c
SS
8181
8182The file is loaded at whatever address is specified in the executable.
8183For some object file formats, you can specify the load address when you
8184link the program; for other formats, like a.out, the object file format
8185specifies a fixed address.
8186@c FIXME! This would be a good place for an xref to the GNU linker doc.
8187
c906108c
SS
8188@code{load} does not repeat if you press @key{RET} again after using it.
8189@end table
8190
53a5351d 8191@node Byte Order
c906108c 8192@section Choosing target byte order
7a292a7a 8193
c906108c
SS
8194@cindex choosing target byte order
8195@cindex target byte order
8196@kindex set endian big
8197@kindex set endian little
8198@kindex set endian auto
8199@kindex show endian
8200
8201Some types of processors, such as the MIPS, PowerPC, and Hitachi SH,
8202offer the ability to run either big-endian or little-endian byte
8203orders. Usually the executable or symbol will include a bit to
8204designate the endian-ness, and you will not need to worry about
8205which to use. However, you may still find it useful to adjust
d4f3574e 8206@value{GDBN}'s idea of processor endian-ness manually.
c906108c
SS
8207
8208@table @code
8209@kindex set endian big
8210@item set endian big
8211Instruct @value{GDBN} to assume the target is big-endian.
8212
8213@kindex set endian little
8214@item set endian little
8215Instruct @value{GDBN} to assume the target is little-endian.
8216
8217@kindex set endian auto
8218@item set endian auto
8219Instruct @value{GDBN} to use the byte order associated with the
8220executable.
8221
8222@item show endian
8223Display @value{GDBN}'s current idea of the target byte order.
8224
8225@end table
8226
8227Note that these commands merely adjust interpretation of symbolic
8228data on the host, and that they have absolutely no effect on the
8229target system.
8230
53a5351d 8231@node Remote
c906108c
SS
8232@section Remote debugging
8233@cindex remote debugging
8234
8235If you are trying to debug a program running on a machine that cannot run
8236@value{GDBN} in the usual way, it is often useful to use remote debugging.
8237For example, you might use remote debugging on an operating system kernel,
8238or on a small system which does not have a general purpose operating system
8239powerful enough to run a full-featured debugger.
8240
8241Some configurations of @value{GDBN} have special serial or TCP/IP interfaces
8242to make this work with particular debugging targets. In addition,
8243@value{GDBN} comes with a generic serial protocol (specific to @value{GDBN},
8244but not specific to any particular target system) which you can use if you
8245write the remote stubs---the code that runs on the remote system to
8246communicate with @value{GDBN}.
8247
8248Other remote targets may be available in your
8249configuration of @value{GDBN}; use @code{help target} to list them.
c906108c 8250
c906108c 8251@menu
c906108c 8252* Remote Serial:: @value{GDBN} remote serial protocol
c906108c
SS
8253@end menu
8254
104c1213
JM
8255@node Remote Serial
8256@subsection The @value{GDBN} remote serial protocol
7a292a7a 8257
104c1213
JM
8258@cindex remote serial debugging, overview
8259To debug a program running on another machine (the debugging
8260@dfn{target} machine), you must first arrange for all the usual
8261prerequisites for the program to run by itself. For example, for a C
8262program, you need:
c906108c 8263
104c1213
JM
8264@enumerate
8265@item
8266A startup routine to set up the C runtime environment; these usually
8267have a name like @file{crt0}. The startup routine may be supplied by
8268your hardware supplier, or you may have to write your own.
96baa820 8269
104c1213 8270@item
d4f3574e 8271A C subroutine library to support your program's
104c1213 8272subroutine calls, notably managing input and output.
96baa820 8273
104c1213
JM
8274@item
8275A way of getting your program to the other machine---for example, a
8276download program. These are often supplied by the hardware
8277manufacturer, but you may have to write your own from hardware
8278documentation.
8279@end enumerate
96baa820 8280
104c1213
JM
8281The next step is to arrange for your program to use a serial port to
8282communicate with the machine where @value{GDBN} is running (the @dfn{host}
8283machine). In general terms, the scheme looks like this:
96baa820 8284
104c1213
JM
8285@table @emph
8286@item On the host,
8287@value{GDBN} already understands how to use this protocol; when everything
8288else is set up, you can simply use the @samp{target remote} command
8289(@pxref{Targets,,Specifying a Debugging Target}).
8290
8291@item On the target,
8292you must link with your program a few special-purpose subroutines that
8293implement the @value{GDBN} remote serial protocol. The file containing these
8294subroutines is called a @dfn{debugging stub}.
8295
8296On certain remote targets, you can use an auxiliary program
8297@code{gdbserver} instead of linking a stub into your program.
8298@xref{Server,,Using the @code{gdbserver} program}, for details.
8299@end table
96baa820 8300
104c1213
JM
8301The debugging stub is specific to the architecture of the remote
8302machine; for example, use @file{sparc-stub.c} to debug programs on
8303@sc{sparc} boards.
96baa820 8304
104c1213
JM
8305@cindex remote serial stub list
8306These working remote stubs are distributed with @value{GDBN}:
96baa820 8307
104c1213
JM
8308@table @code
8309
8310@item i386-stub.c
8311@kindex i386-stub.c
8312@cindex Intel
8313@cindex i386
8314For Intel 386 and compatible architectures.
8315
8316@item m68k-stub.c
8317@kindex m68k-stub.c
8318@cindex Motorola 680x0
8319@cindex m680x0
8320For Motorola 680x0 architectures.
8321
8322@item sh-stub.c
8323@kindex sh-stub.c
8324@cindex Hitachi
8325@cindex SH
8326For Hitachi SH architectures.
8327
8328@item sparc-stub.c
8329@kindex sparc-stub.c
8330@cindex Sparc
8331For @sc{sparc} architectures.
8332
8333@item sparcl-stub.c
8334@kindex sparcl-stub.c
8335@cindex Fujitsu
8336@cindex SparcLite
8337For Fujitsu @sc{sparclite} architectures.
8338
8339@end table
8340
8341The @file{README} file in the @value{GDBN} distribution may list other
8342recently added stubs.
8343
8344@menu
8345* Stub Contents:: What the stub can do for you
8346* Bootstrapping:: What you must do for the stub
8347* Debug Session:: Putting it all together
8348* Protocol:: Definition of the communication protocol
8349* Server:: Using the `gdbserver' program
8350* NetWare:: Using the `gdbserve.nlm' program
8351@end menu
8352
8353@node Stub Contents
8354@subsubsection What the stub can do for you
8355
8356@cindex remote serial stub
8357The debugging stub for your architecture supplies these three
8358subroutines:
8359
8360@table @code
8361@item set_debug_traps
8362@kindex set_debug_traps
8363@cindex remote serial stub, initialization
8364This routine arranges for @code{handle_exception} to run when your
8365program stops. You must call this subroutine explicitly near the
8366beginning of your program.
8367
8368@item handle_exception
8369@kindex handle_exception
8370@cindex remote serial stub, main routine
8371This is the central workhorse, but your program never calls it
8372explicitly---the setup code arranges for @code{handle_exception} to
8373run when a trap is triggered.
8374
8375@code{handle_exception} takes control when your program stops during
8376execution (for example, on a breakpoint), and mediates communications
8377with @value{GDBN} on the host machine. This is where the communications
8378protocol is implemented; @code{handle_exception} acts as the @value{GDBN}
d4f3574e 8379representative on the target machine. It begins by sending summary
104c1213
JM
8380information on the state of your program, then continues to execute,
8381retrieving and transmitting any information @value{GDBN} needs, until you
8382execute a @value{GDBN} command that makes your program resume; at that point,
8383@code{handle_exception} returns control to your own code on the target
8384machine.
8385
8386@item breakpoint
8387@cindex @code{breakpoint} subroutine, remote
8388Use this auxiliary subroutine to make your program contain a
8389breakpoint. Depending on the particular situation, this may be the only
8390way for @value{GDBN} to get control. For instance, if your target
8391machine has some sort of interrupt button, you won't need to call this;
8392pressing the interrupt button transfers control to
8393@code{handle_exception}---in effect, to @value{GDBN}. On some machines,
8394simply receiving characters on the serial port may also trigger a trap;
8395again, in that situation, you don't need to call @code{breakpoint} from
8396your own program---simply running @samp{target remote} from the host
8397@value{GDBN} session gets control.
8398
8399Call @code{breakpoint} if none of these is true, or if you simply want
8400to make certain your program stops at a predetermined point for the
8401start of your debugging session.
8402@end table
8403
8404@node Bootstrapping
8405@subsubsection What you must do for the stub
8406
8407@cindex remote stub, support routines
8408The debugging stubs that come with @value{GDBN} are set up for a particular
8409chip architecture, but they have no information about the rest of your
8410debugging target machine.
8411
8412First of all you need to tell the stub how to communicate with the
8413serial port.
8414
8415@table @code
8416@item int getDebugChar()
8417@kindex getDebugChar
8418Write this subroutine to read a single character from the serial port.
8419It may be identical to @code{getchar} for your target system; a
8420different name is used to allow you to distinguish the two if you wish.
8421
8422@item void putDebugChar(int)
8423@kindex putDebugChar
8424Write this subroutine to write a single character to the serial port.
8425It may be identical to @code{putchar} for your target system; a
8426different name is used to allow you to distinguish the two if you wish.
8427@end table
8428
8429@cindex control C, and remote debugging
8430@cindex interrupting remote targets
8431If you want @value{GDBN} to be able to stop your program while it is
8432running, you need to use an interrupt-driven serial driver, and arrange
8433for it to stop when it receives a @code{^C} (@samp{\003}, the control-C
8434character). That is the character which @value{GDBN} uses to tell the
8435remote system to stop.
8436
8437Getting the debugging target to return the proper status to @value{GDBN}
8438probably requires changes to the standard stub; one quick and dirty way
8439is to just execute a breakpoint instruction (the ``dirty'' part is that
8440@value{GDBN} reports a @code{SIGTRAP} instead of a @code{SIGINT}).
8441
8442Other routines you need to supply are:
8443
8444@table @code
8445@item void exceptionHandler (int @var{exception_number}, void *@var{exception_address})
8446@kindex exceptionHandler
8447Write this function to install @var{exception_address} in the exception
8448handling tables. You need to do this because the stub does not have any
8449way of knowing what the exception handling tables on your target system
8450are like (for example, the processor's table might be in @sc{rom},
8451containing entries which point to a table in @sc{ram}).
8452@var{exception_number} is the exception number which should be changed;
8453its meaning is architecture-dependent (for example, different numbers
8454might represent divide by zero, misaligned access, etc). When this
8455exception occurs, control should be transferred directly to
8456@var{exception_address}, and the processor state (stack, registers,
8457and so on) should be just as it is when a processor exception occurs. So if
8458you want to use a jump instruction to reach @var{exception_address}, it
8459should be a simple jump, not a jump to subroutine.
8460
8461For the 386, @var{exception_address} should be installed as an interrupt
8462gate so that interrupts are masked while the handler runs. The gate
8463should be at privilege level 0 (the most privileged level). The
8464@sc{sparc} and 68k stubs are able to mask interrupts themselves without
8465help from @code{exceptionHandler}.
8466
8467@item void flush_i_cache()
8468@kindex flush_i_cache
d4f3574e 8469On @sc{sparc} and @sc{sparclite} only, write this subroutine to flush the
104c1213
JM
8470instruction cache, if any, on your target machine. If there is no
8471instruction cache, this subroutine may be a no-op.
8472
8473On target machines that have instruction caches, @value{GDBN} requires this
8474function to make certain that the state of your program is stable.
8475@end table
8476
8477@noindent
8478You must also make sure this library routine is available:
8479
8480@table @code
8481@item void *memset(void *, int, int)
8482@kindex memset
8483This is the standard library function @code{memset} that sets an area of
8484memory to a known value. If you have one of the free versions of
8485@code{libc.a}, @code{memset} can be found there; otherwise, you must
8486either obtain it from your hardware manufacturer, or write your own.
8487@end table
8488
8489If you do not use the GNU C compiler, you may need other standard
8490library subroutines as well; this varies from one stub to another,
8491but in general the stubs are likely to use any of the common library
d4f3574e 8492subroutines which @code{@value{GCC}} generates as inline code.
104c1213
JM
8493
8494
8495@node Debug Session
8496@subsubsection Putting it all together
8497
8498@cindex remote serial debugging summary
8499In summary, when your program is ready to debug, you must follow these
8500steps.
8501
8502@enumerate
8503@item
8504Make sure you have the supporting low-level routines
8505(@pxref{Bootstrapping,,What you must do for the stub}):
8506@display
8507@code{getDebugChar}, @code{putDebugChar},
8508@code{flush_i_cache}, @code{memset}, @code{exceptionHandler}.
8509@end display
8510
8511@item
8512Insert these lines near the top of your program:
8513
8514@example
8515set_debug_traps();
8516breakpoint();
8517@end example
8518
8519@item
8520For the 680x0 stub only, you need to provide a variable called
8521@code{exceptionHook}. Normally you just use:
8522
8523@example
8524void (*exceptionHook)() = 0;
8525@end example
8526
d4f3574e 8527@noindent
104c1213 8528but if before calling @code{set_debug_traps}, you set it to point to a
d4f3574e 8529function in your program; that function is called when
104c1213
JM
8530@code{@value{GDBN}} continues after stopping on a trap (for example, bus
8531error). The function indicated by @code{exceptionHook} is called with
8532one parameter: an @code{int} which is the exception number.
8533
8534@item
8535Compile and link together: your program, the @value{GDBN} debugging stub for
8536your target architecture, and the supporting subroutines.
8537
8538@item
8539Make sure you have a serial connection between your target machine and
8540the @value{GDBN} host, and identify the serial port on the host.
8541
8542@item
8543@c The "remote" target now provides a `load' command, so we should
8544@c document that. FIXME.
8545Download your program to your target machine (or get it there by
8546whatever means the manufacturer provides), and start it.
8547
8548@item
8549To start remote debugging, run @value{GDBN} on the host machine, and specify
8550as an executable file the program that is running in the remote machine.
8551This tells @value{GDBN} how to find your program's symbols and the contents
8552of its pure text.
8553
d4f3574e 8554@item
104c1213 8555@cindex serial line, @code{target remote}
d4f3574e 8556Establish communication using the @code{target remote} command.
104c1213
JM
8557Its argument specifies how to communicate with the target
8558machine---either via a devicename attached to a direct serial line, or a
8559TCP port (usually to a terminal server which in turn has a serial line
8560to the target). For example, to use a serial line connected to the
8561device named @file{/dev/ttyb}:
8562
8563@example
8564target remote /dev/ttyb
8565@end example
8566
8567@cindex TCP port, @code{target remote}
8568To use a TCP connection, use an argument of the form
8569@code{@var{host}:port}. For example, to connect to port 2828 on a
8570terminal server named @code{manyfarms}:
8571
8572@example
8573target remote manyfarms:2828
8574@end example
8575@end enumerate
8576
8577Now you can use all the usual commands to examine and change data and to
8578step and continue the remote program.
8579
8580To resume the remote program and stop debugging it, use the @code{detach}
8581command.
8582
8583@cindex interrupting remote programs
8584@cindex remote programs, interrupting
8585Whenever @value{GDBN} is waiting for the remote program, if you type the
8586interrupt character (often @key{C-C}), @value{GDBN} attempts to stop the
8587program. This may or may not succeed, depending in part on the hardware
8588and the serial drivers the remote system uses. If you type the
8589interrupt character once again, @value{GDBN} displays this prompt:
8590
8591@example
8592Interrupted while waiting for the program.
8593Give up (and stop debugging it)? (y or n)
8594@end example
8595
8596If you type @kbd{y}, @value{GDBN} abandons the remote debugging session.
8597(If you decide you want to try again later, you can use @samp{target
8598remote} again to connect once more.) If you type @kbd{n}, @value{GDBN}
8599goes back to waiting.
8600
8601@node Protocol
8602@subsubsection Communication protocol
8603
8604@cindex debugging stub, example
8605@cindex remote stub, example
8606@cindex stub example, remote debugging
8607The stub files provided with @value{GDBN} implement the target side of the
8608communication protocol, and the @value{GDBN} side is implemented in the
8609@value{GDBN} source file @file{remote.c}. Normally, you can simply allow
8610these subroutines to communicate, and ignore the details. (If you're
8611implementing your own stub file, you can still ignore the details: start
8612with one of the existing stub files. @file{sparc-stub.c} is the best
8613organized, and therefore the easiest to read.)
8614
8615However, there may be occasions when you need to know something about
8616the protocol---for example, if there is only one serial port to your
8617target machine, you might want your program to do something special if
8618it recognizes a packet meant for @value{GDBN}.
8619
8620In the examples below, @samp{<-} and @samp{->} are used to indicate
8621transmitted and received data respectfully.
8622
8623@cindex protocol, @value{GDBN} remote serial
8624@cindex serial protocol, @value{GDBN} remote
8625@cindex remote serial protocol
8626All @value{GDBN} commands and responses (other than acknowledgments)
8627are sent as a @var{packet}. A @var{packet} is introduced with the
8628character @samp{$}, this is followed by an optional two-digit
8629@var{sequence-id} and the character @samp{:}, the actual
8630@var{packet-data}, and the terminating character @samp{#} followed by a
8631two-digit @var{checksum}:
8632
8633@example
8634@code{$}@var{packet-data}@code{#}@var{checksum}
8635@end example
8636@noindent
8637or, with the optional @var{sequence-id}:
8638@example
8639@code{$}@var{sequence-id}@code{:}@var{packet-data}@code{#}@var{checksum}
8640@end example
8641
8642@cindex checksum, for @value{GDBN} remote
8643@noindent
8644The two-digit @var{checksum} is computed as the modulo 256 sum of all
8645characters between the leading @samp{$} and the trailing @samp{#} (that
8646consisting of both the optional @var{sequence-id}@code{:} and the actual
d4f3574e 8647@var{packet-data}) (an eight bit unsigned checksum).
104c1213
JM
8648
8649@cindex sequence-id, for @value{GDBN} remote
8650@noindent
8651The two-digit @var{sequence-id}, when present, is returned with the
8652acknowledgment. Beyond that its meaning is poorly defined.
8653@value{GDBN} is not known to output @var{sequence-id}s.
8654
8655When either the host or the target machine receives a packet, the first
8656response expected is an acknowledgment: either @samp{+} (to indicate
8657the package was received correctly) or @samp{-} (to request
8658retransmission):
8659
8660@example
8661<- @code{$}@var{packet-data}@code{#}@var{checksum}
8662-> @code{+}
8663@end example
8664@noindent
8665If the received packet included a @var{sequence-id} than that is
8666appended to a positive acknowledgment:
8667
8668@example
8669<- @code{$}@var{sequence-id}@code{:}@var{packet-data}@code{#}@var{checksum}
8670-> @code{+}@var{sequence-id}
8671@end example
8672
8673The host (@value{GDBN}) sends @var{command}s, and the target (the
8674debugging stub incorporated in your program) sends a @var{response}. In
8675the case of step and continue @var{command}s, the response is only sent
8676when the operation has completed (the target has again stopped).
8677
8678@var{packet-data} consists of a sequence of characters with the
8679exception of @samp{#} and @samp{$} (see @samp{X} packet for an
8680exception). @samp{:} can not appear as the third character in a packet.
8681Fields within the packet should be separated using @samp{,} and @samp{;}
8682(unfortunately some packets chose to use @samp{:}). Except where
8683otherwise noted all numbers are represented in HEX with leading zeros
8684suppressed.
8685
8686Response @var{data} can be run-length encoded to save space. A @samp{*}
c3f6f71d 8687means that the next character is an @sc{ascii} encoding giving a repeat count
104c1213
JM
8688which stands for that many repetitions of the character preceding the
8689@samp{*}. The encoding is @code{n+29}, yielding a printable character
d4f3574e
SS
8690where @code{n >=3} (which is where rle starts to win). The printable
8691characters @samp{$}, @samp{#}, @samp{+} and @samp{-} or with a numeric
8692value greater than 126 should not be used.
8693
8694Some remote systems have used a different run-length encoding mechanism
8695loosely refered to as the cisco encoding. Following the @samp{*}
8696character are two hex digits that indicate the size of the packet.
104c1213
JM
8697
8698So:
8699@example
8700"@code{0* }"
8701@end example
8702@noindent
8703means the same as "0000".
8704
8705The error response, returned for some packets includes a two character
8706error number. That number is not well defined.
8707
8708For any @var{command} not supported by the stub, an empty response
8709(@samp{$#00}) should be returned. That way it is possible to extend the
8710protocol. A newer @value{GDBN} can tell if a packet is supported based
d4f3574e 8711on that response.
104c1213
JM
8712
8713Below is a complete list of all currently defined @var{command}s and
8714their corresponding response @var{data}:
8715
8716@multitable @columnfractions .30 .30 .40
8717@item Packet
8718@tab Request
8719@tab Description
8720
8721@item extended ops @emph{(optional)}
8722@tab @code{!}
8723@tab
d4f3574e 8724Use the extended remote protocol. Sticky---only needs to be set once.
104c1213
JM
8725The extended remote protocol support the @samp{R} packet.
8726@item
8727@tab reply @samp{}
8728@tab
8729Stubs that support the extended remote protocol return @samp{} which,
8730unfortunately, is identical to the response returned by stubs that do not
8731support protocol extensions.
8732
8733@item last signal
8734@tab @code{?}
8735@tab
d4f3574e
SS
8736Indicate the reason the target halted. The reply is the same as for step
8737and continue.
8738@item
8739@tab reply
8740@tab see below
8741
104c1213
JM
8742
8743@item reserved
8744@tab @code{a}
8745@tab Reserved for future use
8746
8747@item set program arguments @strong{(reserved)} @emph{(optional)}
8748@tab @code{A}@var{arglen}@code{,}@var{argnum}@code{,}@var{arg}@code{,...}
8749@tab
8750Initialized @samp{argv[]} array passed into program. @var{arglen}
8751specifies the number of bytes in the hex encoded byte stream @var{arg}.
d4f3574e 8752See @file{gdbserver} for more details.
104c1213
JM
8753@item
8754@tab reply @code{OK}
8755@item
8756@tab reply @code{E}@var{NN}
8757
8758@item set baud @strong{(deprecated)}
8759@tab @code{b}@var{baud}
8760@tab
8761Change the serial line speed to @var{baud}. JTC: @emph{When does the
8762transport layer state change? When it's received, or after the ACK is
8763transmitted. In either case, there are problems if the command or the
8764acknowledgment packet is dropped.} Stan: @emph{If people really wanted
8765to add something like this, and get it working for the first time, they
8766ought to modify ser-unix.c to send some kind of out-of-band message to a
8767specially-setup stub and have the switch happen "in between" packets, so
8768that from remote protocol's point of view, nothing actually
8769happened.}
8770
8771@item set breakpoint @strong{(deprecated)}
8772@tab @code{B}@var{addr},@var{mode}
8773@tab
8774Set (@var{mode} is @samp{S}) or clear (@var{mode} is @samp{C}) a
8775breakpoint at @var{addr}. @emph{This has been replaced by the @samp{Z} and
8776@samp{z} packets.}
8777
8778@item continue
8779@tab @code{c}@var{addr}
8780@tab
8781@var{addr} is address to resume. If @var{addr} is omitted, resume at
8782current address.
8783@item
8784@tab reply
8785@tab see below
8786
8787@item continue with signal @emph{(optional)}
8788@tab @code{C}@var{sig}@code{;}@var{addr}
8789@tab
8790Continue with signal @var{sig} (hex signal number). If
8791@code{;}@var{addr} is omitted, resume at same address.
8792@item
8793@tab reply
8794@tab see below
8795
d4f3574e 8796@item toggle debug @emph{(deprecated)}
104c1213
JM
8797@tab @code{d}
8798@tab
d4f3574e 8799toggle debug flag.
104c1213
JM
8800
8801@item detach @emph{(optional)}
8802@tab @code{D}
d4f3574e 8803@tab
2df3850c
JM
8804Detach @value{GDBN} from the remote system. Sent to the remote target before
8805@value{GDBN} disconnects.
d4f3574e
SS
8806@item
8807@tab reply @emph{no response}
8808@tab
2df3850c 8809@value{GDBN} does not check for any response after sending this packet
104c1213
JM
8810
8811@item reserved
8812@tab @code{e}
8813@tab Reserved for future use
8814
8815@item reserved
8816@tab @code{E}
8817@tab Reserved for future use
8818
8819@item reserved
8820@tab @code{f}
8821@tab Reserved for future use
8822
8823@item reserved
8824@tab @code{F}
8825@tab Reserved for future use
8826
8827@item read registers
8828@tab @code{g}
8829@tab Read general registers.
8830@item
8831@tab reply @var{XX...}
8832@tab
8833Each byte of register data is described by two hex digits. The bytes
8834with the register are transmitted in target byte order. The size of
d4f3574e 8835each register and their position within the @samp{g} @var{packet} are
2df3850c 8836determined by the @value{GDBN} internal macros @var{REGISTER_RAW_SIZE} and
d4f3574e
SS
8837@var{REGISTER_NAME} macros. The specification of several standard
8838@code{g} packets is specified below.
104c1213
JM
8839@item
8840@tab @code{E}@var{NN}
8841@tab for an error.
8842
8843@item write regs
8844@tab @code{G}@var{XX...}
8845@tab
8846See @samp{g} for a description of the @var{XX...} data.
8847@item
8848@tab reply @code{OK}
8849@tab for success
8850@item
8851@tab reply @code{E}@var{NN}
8852@tab for an error
8853
8854@item reserved
8855@tab @code{h}
8856@tab Reserved for future use
8857
8858@item set thread @emph{(optional)}
8859@tab @code{H}@var{c}@var{t...}
8860@tab
d4f3574e
SS
8861Set thread for subsequent operations (@samp{m}, @samp{M}, @samp{g},
8862@samp{G}, et.al.). @var{c} = @samp{c} for thread used in step and
8863continue; @var{t...} can be -1 for all threads. @var{c} = @samp{g} for
8864thread used in other operations. If zero, pick a thread, any thread.
104c1213
JM
8865@item
8866@tab reply @code{OK}
8867@tab for success
8868@item
8869@tab reply @code{E}@var{NN}
8870@tab for an error
8871
d4f3574e
SS
8872@c FIXME: JTC:
8873@c 'H': How restrictive (or permissive) is the thread model. If a
8874@c thread is selected and stopped, are other threads allowed
8875@c to continue to execute? As I mentioned above, I think the
8876@c semantics of each command when a thread is selected must be
8877@c described. For example:
8878@c
8879@c 'g': If the stub supports threads and a specific thread is
8880@c selected, returns the register block from that thread;
8881@c otherwise returns current registers.
8882@c
8883@c 'G' If the stub supports threads and a specific thread is
8884@c selected, sets the registers of the register block of
8885@c that thread; otherwise sets current registers.
8886
104c1213
JM
8887@item cycle step @strong{(draft)} @emph{(optional)}
8888@tab @code{i}@var{addr}@code{,}@var{nnn}
8889@tab
8890Step the remote target by a single clock cycle. If @code{,}@var{nnn} is
8891present, cycle step @var{nnn} cycles. If @var{addr} is present, cycle
8892step starting at that address.
8893
8894@item signal then cycle step @strong{(reserved)} @emph{(optional)}
8895@tab @code{I}
8896@tab
8897See @samp{i} and @samp{S} for likely syntax and semantics.
8898
8899@item reserved
8900@tab @code{j}
8901@tab Reserved for future use
8902
8903@item reserved
8904@tab @code{J}
8905@tab Reserved for future use
8906
8907@item kill request @emph{(optional)}
8908@tab @code{k}
8909@tab
d4f3574e
SS
8910FIXME: @emph{There is no description of how operate when a specific
8911thread context has been selected (ie. does 'k' kill only that thread?)}.
104c1213
JM
8912
8913@item reserved
8914@tab @code{l}
8915@tab Reserved for future use
8916
8917@item reserved
8918@tab @code{L}
8919@tab Reserved for future use
8920
8921@item read memory
8922@tab @code{m}@var{addr}@code{,}@var{length}
8923@tab
8924Read @var{length} bytes of memory starting at address @var{addr}.
2df3850c 8925Neither @value{GDBN} nor the stub assume that sized memory transfers are assumed
d4f3574e
SS
8926using word alligned accesses. FIXME: @emph{A word aligned memory
8927transfer mechanism is needed.}
104c1213
JM
8928@item
8929@tab reply @var{XX...}
8930@tab
d4f3574e 8931@var{XX...} is mem contents. Can be fewer bytes than requested if able
2df3850c 8932to read only part of the data. Neither @value{GDBN} nor the stub assume that
d4f3574e
SS
8933sized memory transfers are assumed using word alligned accesses. FIXME:
8934@emph{A word aligned memory transfer mechanism is needed.}
104c1213
JM
8935@item
8936@tab reply @code{E}@var{NN}
8937@tab @var{NN} is errno
8938
8939@item write mem
8940@tab @code{M}@var{addr},@var{length}@code{:}@var{XX...}
8941@tab
8942Write @var{length} bytes of memory starting at address @var{addr}.
8943@var{XX...} is the data.
8944@item
8945@tab reply @code{OK}
8946@tab for success
8947@item
8948@tab reply @code{E}@var{NN}
8949@tab
8950for an error (this includes the case where only part of the data was
8951written).
8952
8953@item reserved
8954@tab @code{n}
8955@tab Reserved for future use
8956
8957@item reserved
8958@tab @code{N}
8959@tab Reserved for future use
8960
8961@item reserved
8962@tab @code{o}
8963@tab Reserved for future use
8964
8965@item reserved
8966@tab @code{O}
8967@tab Reserved for future use
8968
8969@item read reg @strong{(reserved)}
8970@tab @code{p}@var{n...}
8971@tab
8972See write register.
8973@item
8974@tab return @var{r....}
8975@tab The hex encoded value of the register in target byte order.
8976
8977@item write reg @emph{(optional)}
8978@tab @code{P}@var{n...}@code{=}@var{r...}
8979@tab
8980Write register @var{n...} with value @var{r...}, which contains two hex
8981digits for each byte in the register (target byte order).
8982@item
8983@tab reply @code{OK}
8984@tab for success
8985@item
8986@tab reply @code{E}@var{NN}
8987@tab for an error
8988
8989@item general query @emph{(optional)}
8990@tab @code{q}@var{query}
8991@tab
d4f3574e 8992Request info about @var{query}. In general @value{GDBN} @var{query}'s
104c1213 8993have a leading upper case letter. Custom vendor queries should use a
d4f3574e
SS
8994company prefix (in lower case) ex: @samp{qfsf.var}. @var{query} may
8995optionally be followed by a @samp{,} or @samp{;} separated list. Stubs
8996must ensure that they match the full @var{query} name.
104c1213
JM
8997@item
8998@tab reply @code{XX...}
d4f3574e 8999@tab Hex encoded data from query. The reply can not be empty.
104c1213
JM
9000@item
9001@tab reply @code{E}@var{NN}
9002@tab error reply
9003@item
9004@tab reply @samp{}
9005@tab Indicating an unrecognized @var{query}.
9006
104c1213
JM
9007@item general set @emph{(optional)}
9008@tab @code{Q}@var{var}@code{=}@var{val}
9009@tab
9010Set value of @var{var} to @var{val}. See @samp{q} for a discussing of
9011naming conventions.
9012
d4f3574e
SS
9013@item reset @emph{(deprecated)}
9014@tab @code{r}
9015@tab
9016Reset the entire system.
104c1213
JM
9017
9018@item remote restart @emph{(optional)}
9019@tab @code{R}@var{XX}
9020@tab
d4f3574e
SS
9021Restart the remote server. @var{XX} while needed has no clear
9022definition. FIXME: @emph{An example interaction explaining how this
9023packet is used in extended-remote mode is needed}.
104c1213
JM
9024
9025@item step @emph{(optional)}
9026@tab @code{s}@var{addr}
9027@tab
9028@var{addr} is address to resume. If @var{addr} is omitted, resume at
9029same address.
9030@item
9031@tab reply
9032@tab see below
9033
9034@item step with signal @emph{(optional)}
9035@tab @code{S}@var{sig}@code{;}@var{addr}
9036@tab
9037Like @samp{C} but step not continue.
9038@item
9039@tab reply
9040@tab see below
9041
9042@item search @emph{(optional)}
9043@tab @code{t}@var{addr}@code{:}@var{PP}@code{,}@var{MM}
9044@tab
9045Search backwards starting at address @var{addr} for a match with pattern
9046@var{PP} and mask @var{MM}. @var{PP} and @var{MM} are 4
d4f3574e 9047bytes. @var{addr} must be at least 3 digits.
104c1213
JM
9048
9049@item thread alive @emph{(optional)}
9050@tab @code{T}@var{XX}
9051@tab Find out if the thread XX is alive.
9052@item
9053@tab reply @code{OK}
9054@tab thread is still alive
9055@item
9056@tab reply @code{E}@var{NN}
9057@tab thread is dead
9058
9059@item reserved
9060@tab @code{u}
9061@tab Reserved for future use
9062
9063@item reserved
9064@tab @code{U}
9065@tab Reserved for future use
9066
9067@item reserved
9068@tab @code{v}
9069@tab Reserved for future use
9070
9071@item reserved
9072@tab @code{V}
9073@tab Reserved for future use
9074
9075@item reserved
9076@tab @code{w}
9077@tab Reserved for future use
9078
9079@item reserved
9080@tab @code{W}
9081@tab Reserved for future use
9082
9083@item reserved
9084@tab @code{x}
9085@tab Reserved for future use
9086
9087@item write mem (binary) @emph{(optional)}
9088@tab @code{X}@var{addr}@code{,}@var{length}@var{:}@var{XX...}
9089@tab
9090@var{addr} is address, @var{length} is number of bytes, @var{XX...} is
d4f3574e
SS
9091binary data. The characters @code{$}, @code{#}, and @code{0x7d} are
9092escaped using @code{0x7d}.
104c1213
JM
9093@item
9094@tab reply @code{OK}
9095@tab for success
9096@item
9097@tab reply @code{E}@var{NN}
9098@tab for an error
9099
9100@item reserved
9101@tab @code{y}
9102@tab Reserved for future use
9103
9104@item reserved
9105@tab @code{Y}
9106@tab Reserved for future use
9107
9108@item remove break or watchpoint @strong{(draft)} @emph{(optional)}
9109@tab @code{z}@var{t}@code{,}@var{addr}@code{,}@var{length}
9110@tab
9111See @samp{Z}.
9112
9113@item insert break or watchpoint @strong{(draft)} @emph{(optional)}
9114@tab @code{Z}@var{t}@code{,}@var{addr}@code{,}@var{length}
9115@tab
9116@var{t} is type: @samp{0} - software breakpoint, @samp{1} - hardware
9117breakpoint, @samp{2} - write watchpoint, @samp{3} - read watchpoint,
9118@samp{4} - access watchpoint; @var{addr} is address; @var{length} is in
9119bytes. For a software breakpoint, @var{length} specifies the size of
9120the instruction to be patched. For hardware breakpoints and watchpoints
d4f3574e
SS
9121@var{length} specifies the memory region to be monitored. To avoid
9122potential problems with duplicate packets, the operations should be
9123implemented in an ident-potentent way.
104c1213
JM
9124@item
9125@tab reply @code{E}@var{NN}
9126@tab for an error
9127@item
9128@tab reply @code{OK}
9129@tab for success
9130@item
9131@tab @samp{}
9132@tab If not supported.
9133
9134@item reserved
9135@tab <other>
9136@tab Reserved for future use
9137
9138@end multitable
9139
d4f3574e
SS
9140The @samp{C}, @samp{c}, @samp{S}, @samp{s} and @samp{?} packets can
9141receive any of the below as a reply. In the case of the @samp{C},
9142@samp{c}, @samp{S} and @samp{s} packets, that reply is only returned
9143when the target halts. In the below the exact meaning of @samp{signal
9144number} is poorly defined. In general one of the UNIX signal numbering
9145conventions is used.
104c1213
JM
9146
9147@multitable @columnfractions .4 .6
9148
9149@item @code{S}@var{AA}
9150@tab @var{AA} is the signal number
9151
9152@item @code{T}@var{AA}@var{n...}@code{:}@var{r...}@code{;}@var{n...}@code{:}@var{r...}@code{;}@var{n...}@code{:}@var{r...}@code{;}
9153@tab
9154@var{AA} = two hex digit signal number; @var{n...} = register number
9155(hex), @var{r...} = target byte ordered register contents, size defined
9156by @code{REGISTER_RAW_SIZE}; @var{n...} = @samp{thread}, @var{r...} =
9157thread process ID, this is a hex integer; @var{n...} = other string not
d4f3574e 9158starting with valid hex digit. @value{GDBN} should ignore this
104c1213
JM
9159@var{n...}, @var{r...} pair and go on to the next. This way we can
9160extend the protocol.
9161
9162@item @code{W}@var{AA}
9163@tab
9164The process exited, and @var{AA} is the exit status. This is only
9165applicable for certains sorts of targets.
9166
9167@item @code{X}@var{AA}
9168@tab
9169The process terminated with signal @var{AA}.
9170
9171@item @code{N}@var{AA}@code{;}@var{tttttttt}@code{;}@var{dddddddd}@code{;}@var{bbbbbbbb} @strong{(obsolete)}
9172@tab
9173@var{AA} = signal number; @var{tttttttt} = address of symbol "_start";
9174@var{dddddddd} = base of data section; @var{bbbbbbbb} = base of bss
d4f3574e 9175section. @emph{Note: only used by Cisco Systems targets. The difference
104c1213
JM
9176between this reply and the "qOffsets" query is that the 'N' packet may
9177arrive spontaneously whereas the 'qOffsets' is a query initiated by the
9178host debugger.}
9179
9180@item @code{O}@var{XX...}
9181@tab
c3f6f71d 9182@var{XX...} is hex encoding of @sc{ascii} data. This can happen at any time
104c1213
JM
9183while the program is running and the debugger should continue to wait
9184for 'W', 'T', etc.
9185
9186@end multitable
9187
d4f3574e
SS
9188The following set and query packets have already been defined.
9189
9190@multitable @columnfractions .2 .2 .6
9191
9192@item current thread
9193@tab @code{q}@code{C}
9194@tab Return the current thread id.
9195@item
9196@tab reply @code{QC}@var{pid}
9197@tab
9198Where @var{pid} is a HEX encoded 16 bit process id.
9199@item
9200@tab reply *
9201@tab Any other reply implies the old pid.
9202
9203@item compute CRC of memory block
9204@tab @code{q}@code{CRC:}@var{addr}@code{,}@var{length}
9205@tab
9206@item
9207@tab reply @code{E}@var{NN}
9208@tab An error (such as memory fault)
9209@item
9210@tab reply @code{C}@var{CRC32}
9211@tab A 32 bit cyclic redundancy check of the specified memory region.
9212
9213@item query @var{LIST} or @var{threadLIST} @strong{(deprecated)}
9214@tab @code{q}@code{L}@var{startflag}@var{threadcount}@var{nextthread}
9215@tab
9216Obtain thread information from RTOS. Where: @var{startflag} (one hex
9217digit) is one to indicate the first query and zero to indicate a
9218subsequent query; @var{threadcount} (two hex digits) is the maximum
9219number of threads the response packet can contain; and @var{nextthread}
9220(eight hex digits), for subsequent queries (@var{startflag} is zero), is
9221returned in the response as @var{argthread}.
9222@item
9223@tab reply @code{q}@code{M}@var{count}@var{done}@var{argthread}@var{thread...}
9224@tab
9225Where: @var{count} (two hex digits) is the number of threads being
9226returned; @var{done} (one hex digit) is zero to indicate more threads
9227and one indicates no further threads; @var{argthreadid} (eight hex
9228digits) is @var{nextthread} from the request packet; @var{thread...} is
9229a sequence of thread IDs from the target. @var{threadid} (eight hex
9230digits). See @code{remote.c:parse_threadlist_response()}.
9231
9232@item query sect offs
9233@tab @code{q}@code{Offsets}
917317f4
JM
9234@tab
9235Get section offsets that the target used when re-locating the downloaded
9236image. @emph{Note: while a @code{Bss} offset is included in the
9237response, @value{GDBN} ignores this and instead applies the @code{Data}
9238offset to the @code{Bss} section.}
d4f3574e
SS
9239@item
9240@tab reply @code{Text=}@var{xxx}@code{;Data=}@var{yyy}@code{;Bss=}@var{zzz}
9241
9242@item thread info request
9243@tab @code{q}@code{P}@var{mode}@var{threadid}
9244@tab
9245Returns information on @var{threadid}. Where: @var{mode} is a hex
9246encoded 32 bit mode; @var{threadid} is a hex encoded 64 bit thread ID.
9247@item
9248@tab reply *
9249@tab
9250See @code{remote.c:remote_unpack_thread_info_response()}.
9251
9252@item remote command
9253@tab @code{q}@code{Rcmd,}@var{COMMAND}
9254@tab
9255@var{COMMAND} (hex encoded) is passed to the local interpreter for
9256execution. Invalid commands should be reported using the output string.
9257Before the final result packet, the target may also respond with a
9258number of intermediate @code{O}@var{OUTPUT} console output
9259packets. @emph{Implementors should note that providing access to a
9260stubs's interpreter may have security implications}.
9261@item
9262@tab reply @code{OK}
9263@tab
9264A command response with no output.
9265@item
9266@tab reply @var{OUTPUT}
9267@tab
9268A command response with the hex encoded output string @var{OUTPUT}.
9269@item
9270@tab reply @code{E}@var{NN}
9271@tab
9272Indicate a badly formed request.
9273
9274@item
9275@tab reply @samp{}
9276@tab
9277When @samp{q}@samp{Rcmd} is not recognized.
9278
9279@end multitable
9280
9281The following @samp{g}/@samp{G} packets have previously been defined.
9282In the below, some thirty-two bit registers are transferred as sixty-four
9283bits. Those registers should be zero/sign extended (which?) to fill the
9284space allocated. Register bytes are transfered in target byte order.
9285The two nibbles within a register byte are transfered most-significant -
9286least-significant.
9287
9288@multitable @columnfractions .5 .5
9289
9290@item MIPS32
9291@tab
9292All registers are transfered as thirty-two bit quantities in the order:
929332 general-purpose; sr; lo; hi; bad; cause; pc; 32 floating-point
9294registers; fsr; fir; fp.
9295
9296@item MIPS64
9297@tab
9298All registers are transfered as sixty-four bit quantities (including
9299thirty-two bit registers such as @code{sr}). The ordering is the same
9300as @code{MIPS32}.
9301
9302@end multitable
9303
104c1213
JM
9304Example sequence of a target being re-started. Notice how the restart
9305does not get any direct output:
9306
9307@example
9308<- @code{R00}
9309-> @code{+}
9310@emph{target restarts}
9311<- @code{?}
9312-> @code{+}
9313-> @code{T001:1234123412341234}
9314<- @code{+}
9315@end example
9316
9317Example sequence of a target being stepped by a single instruction:
9318
9319@example
9320<- @code{G1445...}
9321-> @code{+}
9322<- @code{s}
9323-> @code{+}
9324@emph{time passes}
9325-> @code{T001:1234123412341234}
9326<- @code{+}
9327<- @code{g}
9328-> @code{+}
9329-> @code{1455...}
9330<- @code{+}
9331@end example
9332
d4f3574e
SS
9333@kindex set remotedebug@r{, serial protocol}
9334@kindex show remotedebug@r{, serial protocol}
104c1213
JM
9335@cindex packets, reporting on stdout
9336@cindex serial connections, debugging
9337If you have trouble with the serial connection, you can use the command
9338@code{set remotedebug}. This makes @value{GDBN} report on all packets sent
9339back and forth across the serial line to the remote machine. The
9340packet-debugging information is printed on the @value{GDBN} standard output
9341stream. @code{set remotedebug off} turns it off, and @code{show
9342remotedebug} shows you its current state.
9343
9344@node Server
9345@subsubsection Using the @code{gdbserver} program
9346
9347@kindex gdbserver
9348@cindex remote connection without stubs
9349@code{gdbserver} is a control program for Unix-like systems, which
9350allows you to connect your program with a remote @value{GDBN} via
9351@code{target remote}---but without linking in the usual debugging stub.
9352
9353@code{gdbserver} is not a complete replacement for the debugging stubs,
9354because it requires essentially the same operating-system facilities
9355that @value{GDBN} itself does. In fact, a system that can run
9356@code{gdbserver} to connect to a remote @value{GDBN} could also run
9357@value{GDBN} locally! @code{gdbserver} is sometimes useful nevertheless,
9358because it is a much smaller program than @value{GDBN} itself. It is
9359also easier to port than all of @value{GDBN}, so you may be able to get
9360started more quickly on a new system by using @code{gdbserver}.
9361Finally, if you develop code for real-time systems, you may find that
9362the tradeoffs involved in real-time operation make it more convenient to
9363do as much development work as possible on another system, for example
9364by cross-compiling. You can use @code{gdbserver} to make a similar
9365choice for debugging.
9366
9367@value{GDBN} and @code{gdbserver} communicate via either a serial line
9368or a TCP connection, using the standard @value{GDBN} remote serial
9369protocol.
9370
9371@table @emph
9372@item On the target machine,
9373you need to have a copy of the program you want to debug.
9374@code{gdbserver} does not need your program's symbol table, so you can
9375strip the program if necessary to save space. @value{GDBN} on the host
9376system does all the symbol handling.
9377
9378To use the server, you must tell it how to communicate with @value{GDBN};
9379the name of your program; and the arguments for your program. The
9380syntax is:
9381
9382@smallexample
9383target> gdbserver @var{comm} @var{program} [ @var{args} @dots{} ]
9384@end smallexample
9385
9386@var{comm} is either a device name (to use a serial line) or a TCP
9387hostname and portnumber. For example, to debug Emacs with the argument
9388@samp{foo.txt} and communicate with @value{GDBN} over the serial port
9389@file{/dev/com1}:
9390
9391@smallexample
9392target> gdbserver /dev/com1 emacs foo.txt
9393@end smallexample
9394
9395@code{gdbserver} waits passively for the host @value{GDBN} to communicate
9396with it.
9397
9398To use a TCP connection instead of a serial line:
9399
9400@smallexample
9401target> gdbserver host:2345 emacs foo.txt
9402@end smallexample
9403
9404The only difference from the previous example is the first argument,
9405specifying that you are communicating with the host @value{GDBN} via
9406TCP. The @samp{host:2345} argument means that @code{gdbserver} is to
9407expect a TCP connection from machine @samp{host} to local TCP port 2345.
9408(Currently, the @samp{host} part is ignored.) You can choose any number
9409you want for the port number as long as it does not conflict with any
9410TCP ports already in use on the target system (for example, @code{23} is
9411reserved for @code{telnet}).@footnote{If you choose a port number that
9412conflicts with another service, @code{gdbserver} prints an error message
d4f3574e 9413and exits.} You must use the same port number with the host @value{GDBN}
104c1213
JM
9414@code{target remote} command.
9415
9416@item On the @value{GDBN} host machine,
9417you need an unstripped copy of your program, since @value{GDBN} needs
9418symbols and debugging information. Start up @value{GDBN} as usual,
9419using the name of the local copy of your program as the first argument.
9420(You may also need the @w{@samp{--baud}} option if the serial line is
d4f3574e 9421running at anything other than 9600@dmn{bps}.) After that, use @code{target
104c1213
JM
9422remote} to establish communications with @code{gdbserver}. Its argument
9423is either a device name (usually a serial device, like
9424@file{/dev/ttyb}), or a TCP port descriptor in the form
9425@code{@var{host}:@var{PORT}}. For example:
9426
9427@smallexample
9428(@value{GDBP}) target remote /dev/ttyb
9429@end smallexample
9430
9431@noindent
9432communicates with the server via serial line @file{/dev/ttyb}, and
9433
9434@smallexample
9435(@value{GDBP}) target remote the-target:2345
9436@end smallexample
9437
9438@noindent
9439communicates via a TCP connection to port 2345 on host @w{@file{the-target}}.
9440For TCP connections, you must start up @code{gdbserver} prior to using
9441the @code{target remote} command. Otherwise you may get an error whose
9442text depends on the host system, but which usually looks something like
9443@samp{Connection refused}.
9444@end table
9445
9446@node NetWare
9447@subsubsection Using the @code{gdbserve.nlm} program
9448
9449@kindex gdbserve.nlm
9450@code{gdbserve.nlm} is a control program for NetWare systems, which
9451allows you to connect your program with a remote @value{GDBN} via
9452@code{target remote}.
9453
9454@value{GDBN} and @code{gdbserve.nlm} communicate via a serial line,
9455using the standard @value{GDBN} remote serial protocol.
9456
9457@table @emph
9458@item On the target machine,
9459you need to have a copy of the program you want to debug.
9460@code{gdbserve.nlm} does not need your program's symbol table, so you
9461can strip the program if necessary to save space. @value{GDBN} on the
9462host system does all the symbol handling.
9463
9464To use the server, you must tell it how to communicate with
9465@value{GDBN}; the name of your program; and the arguments for your
9466program. The syntax is:
9467
9468@smallexample
9469load gdbserve [ BOARD=@var{board} ] [ PORT=@var{port} ]
9470 [ BAUD=@var{baud} ] @var{program} [ @var{args} @dots{} ]
9471@end smallexample
9472
9473@var{board} and @var{port} specify the serial line; @var{baud} specifies
9474the baud rate used by the connection. @var{port} and @var{node} default
d4f3574e 9475to 0, @var{baud} defaults to 9600@dmn{bps}.
104c1213
JM
9476
9477For example, to debug Emacs with the argument @samp{foo.txt}and
9478communicate with @value{GDBN} over serial port number 2 or board 1
d4f3574e 9479using a 19200@dmn{bps} connection:
104c1213
JM
9480
9481@smallexample
9482load gdbserve BOARD=1 PORT=2 BAUD=19200 emacs foo.txt
9483@end smallexample
9484
9485@item On the @value{GDBN} host machine,
9486you need an unstripped copy of your program, since @value{GDBN} needs
9487symbols and debugging information. Start up @value{GDBN} as usual,
9488using the name of the local copy of your program as the first argument.
9489(You may also need the @w{@samp{--baud}} option if the serial line is
d4f3574e 9490running at anything other than 9600@dmn{bps}. After that, use @code{target
104c1213
JM
9491remote} to establish communications with @code{gdbserve.nlm}. Its
9492argument is a device name (usually a serial device, like
9493@file{/dev/ttyb}). For example:
9494
9495@smallexample
9496(@value{GDBP}) target remote /dev/ttyb
9497@end smallexample
9498
9499@noindent
9500communications with the server via serial line @file{/dev/ttyb}.
9501@end table
9502
9503@node KOD
9504@section Kernel Object Display
9505
9506@cindex kernel object display
9507@cindex kernel object
9508@cindex KOD
9509
9510Some targets support kernel object display. Using this facility,
9511@value{GDBN} communicates specially with the underlying operating system
9512and can display information about operating system-level objects such as
9513mutexes and other synchronization objects. Exactly which objects can be
9514displayed is determined on a per-OS basis.
9515
9516Use the @code{set os} command to set the operating system. This tells
9517@value{GDBN} which kernel object display module to initialize:
9518
9519@example
2df3850c 9520(@value{GDBP}) set os cisco
104c1213
JM
9521@end example
9522
9523If @code{set os} succeeds, @value{GDBN} will display some information
9524about the operating system, and will create a new @code{info} command
9525which can be used to query the target. The @code{info} command is named
9526after the operating system:
9527
9528@example
2df3850c 9529(@value{GDBP}) info cisco
104c1213
JM
9530List of Cisco Kernel Objects
9531Object Description
9532any Any and all objects
9533@end example
9534
9535Further subcommands can be used to query about particular objects known
9536by the kernel.
9537
9538There is currently no way to determine whether a given operating system
96baa820
JM
9539is supported other than to try it.
9540
9541
104c1213
JM
9542@node Configurations
9543@chapter Configuration-Specific Information
9544
9545While nearly all @value{GDBN} commands are available for all native and
9546cross versions of the debugger, there are some exceptions. This chapter
9547describes things that are only available in certain configurations.
9548
9549There are three major categories of configurations: native
9550configurations, where the host and target are the same, embedded
9551operating system configurations, which are usually the same for several
9552different processor architectures, and bare embedded processors, which
9553are quite different from each other.
9554
9555@menu
9556* Native::
9557* Embedded OS::
9558* Embedded Processors::
9559* Architectures::
9560@end menu
9561
9562@node Native
9563@section Native
9564
9565This section describes details specific to particular native
9566configurations.
9567
9568@menu
9569* HP-UX:: HP-UX
9570* SVR4 Process Information:: SVR4 process information
9571@end menu
9572
9573@node HP-UX
9574@subsection HP-UX
9575
9576On HP-UX systems, if you refer to a function or variable name that
9577begins with a dollar sign, @value{GDBN} searches for a user or system
9578name first, before it searches for a convenience variable.
9579
9580@node SVR4 Process Information
9581@subsection SVR4 process information
9582
9583@kindex /proc
9584@cindex process image
9585
9586Many versions of SVR4 provide a facility called @samp{/proc} that can be
9587used to examine the image of a running process using file-system
9588subroutines. If @value{GDBN} is configured for an operating system with
9589this facility, the command @code{info proc} is available to report on
9590several kinds of information about the process running your program.
9591@code{info proc} works only on SVR4 systems that include the
9592@code{procfs} code. This includes OSF/1 (Digital Unix), Solaris, Irix,
9593and Unixware, but not HP-UX or Linux, for example.
9594
9595@table @code
9596@kindex info proc
9597@item info proc
9598Summarize available information about the process.
9599
9600@kindex info proc mappings
9601@item info proc mappings
9602Report on the address ranges accessible in the program, with information
9603on whether your program may read, write, or execute each range.
9604
9605@kindex info proc times
9606@item info proc times
9607Starting time, user CPU time, and system CPU time for your program and
9608its children.
9609
9610@kindex info proc id
9611@item info proc id
9612Report on the process IDs related to your program: its own process ID,
9613the ID of its parent, the process group ID, and the session ID.
9614
9615@kindex info proc status
9616@item info proc status
9617General information on the state of the process. If the process is
9618stopped, this report includes the reason for stopping, and any signal
9619received.
9620
9621@item info proc all
9622Show all the above information about the process.
9623@end table
9624
9625@node Embedded OS
9626@section Embedded Operating Systems
9627
9628This section describes configurations involving the debugging of
9629embedded operating systems that are available for several different
9630architectures.
9631
9632@menu
9633* VxWorks:: Using @value{GDBN} with VxWorks
9634@end menu
9635
9636@value{GDBN} includes the ability to debug programs running on
9637various real-time operating systems.
9638
9639@node VxWorks
9640@subsection Using @value{GDBN} with VxWorks
9641
9642@cindex VxWorks
9643
9644@table @code
9645
9646@kindex target vxworks
9647@item target vxworks @var{machinename}
9648A VxWorks system, attached via TCP/IP. The argument @var{machinename}
9649is the target system's machine name or IP address.
9650
9651@end table
9652
9653On VxWorks, @code{load} links @var{filename} dynamically on the
9654current target system as well as adding its symbols in @value{GDBN}.
9655
9656@value{GDBN} enables developers to spawn and debug tasks running on networked
9657VxWorks targets from a Unix host. Already-running tasks spawned from
9658the VxWorks shell can also be debugged. @value{GDBN} uses code that runs on
9659both the Unix host and on the VxWorks target. The program
d4f3574e 9660@code{@value{GDBP}} is installed and executed on the Unix host. (It may be
104c1213 9661installed with the name @code{vxgdb}, to distinguish it from a
d4f3574e 9662@value{GDB} for debugging programs on the host itself.)
104c1213
JM
9663
9664@table @code
9665@item VxWorks-timeout @var{args}
9666@kindex vxworks-timeout
9667All VxWorks-based targets now support the option @code{vxworks-timeout}.
9668This option is set by the user, and @var{args} represents the number of
9669seconds @value{GDBN} waits for responses to rpc's. You might use this if
9670your VxWorks target is a slow software simulator or is on the far side
9671of a thin network line.
9672@end table
9673
9674The following information on connecting to VxWorks was current when
9675this manual was produced; newer releases of VxWorks may use revised
9676procedures.
9677
9678@kindex INCLUDE_RDB
9679To use @value{GDBN} with VxWorks, you must rebuild your VxWorks kernel
9680to include the remote debugging interface routines in the VxWorks
9681library @file{rdb.a}. To do this, define @code{INCLUDE_RDB} in the
9682VxWorks configuration file @file{configAll.h} and rebuild your VxWorks
9683kernel. The resulting kernel contains @file{rdb.a}, and spawns the
9684source debugging task @code{tRdbTask} when VxWorks is booted. For more
9685information on configuring and remaking VxWorks, see the manufacturer's
9686manual.
9687@c VxWorks, see the @cite{VxWorks Programmer's Guide}.
9688
9689Once you have included @file{rdb.a} in your VxWorks system image and set
9690your Unix execution search path to find @value{GDBN}, you are ready to
d4f3574e 9691run @value{GDBN}. From your Unix host, run @code{@value{GDBP}} (or @code{vxgdb},
104c1213
JM
9692depending on your installation).
9693
9694@value{GDBN} comes up showing the prompt:
9695
9696@example
9697(vxgdb)
9698@end example
9699
9700@menu
9701* VxWorks Connection:: Connecting to VxWorks
9702* VxWorks Download:: VxWorks download
9703* VxWorks Attach:: Running tasks
9704@end menu
9705
9706@node VxWorks Connection
9707@subsubsection Connecting to VxWorks
9708
9709The @value{GDBN} command @code{target} lets you connect to a VxWorks target on the
9710network. To connect to a target whose host name is ``@code{tt}'', type:
9711
9712@example
9713(vxgdb) target vxworks tt
9714@end example
9715
9716@need 750
9717@value{GDBN} displays messages like these:
9718
9719@smallexample
9720Attaching remote machine across net...
9721Connected to tt.
9722@end smallexample
9723
9724@need 1000
9725@value{GDBN} then attempts to read the symbol tables of any object modules
9726loaded into the VxWorks target since it was last booted. @value{GDBN} locates
9727these files by searching the directories listed in the command search
9728path (@pxref{Environment, ,Your program's environment}); if it fails
9729to find an object file, it displays a message such as:
9730
9731@example
9732prog.o: No such file or directory.
9733@end example
9734
9735When this happens, add the appropriate directory to the search path with
9736the @value{GDBN} command @code{path}, and execute the @code{target}
9737command again.
9738
9739@node VxWorks Download
9740@subsubsection VxWorks download
9741
9742@cindex download to VxWorks
9743If you have connected to the VxWorks target and you want to debug an
9744object that has not yet been loaded, you can use the @value{GDBN}
9745@code{load} command to download a file from Unix to VxWorks
9746incrementally. The object file given as an argument to the @code{load}
9747command is actually opened twice: first by the VxWorks target in order
9748to download the code, then by @value{GDBN} in order to read the symbol
9749table. This can lead to problems if the current working directories on
9750the two systems differ. If both systems have NFS mounted the same
9751filesystems, you can avoid these problems by using absolute paths.
9752Otherwise, it is simplest to set the working directory on both systems
9753to the directory in which the object file resides, and then to reference
9754the file by its name, without any path. For instance, a program
9755@file{prog.o} may reside in @file{@var{vxpath}/vw/demo/rdb} in VxWorks
9756and in @file{@var{hostpath}/vw/demo/rdb} on the host. To load this
9757program, type this on VxWorks:
9758
9759@example
9760-> cd "@var{vxpath}/vw/demo/rdb"
9761@end example
d4f3574e
SS
9762
9763@noindent
104c1213
JM
9764Then, in @value{GDBN}, type:
9765
9766@example
9767(vxgdb) cd @var{hostpath}/vw/demo/rdb
9768(vxgdb) load prog.o
9769@end example
9770
9771@value{GDBN} displays a response similar to this:
9772
9773@smallexample
9774Reading symbol data from wherever/vw/demo/rdb/prog.o... done.
9775@end smallexample
9776
9777You can also use the @code{load} command to reload an object module
9778after editing and recompiling the corresponding source file. Note that
9779this makes @value{GDBN} delete all currently-defined breakpoints,
9780auto-displays, and convenience variables, and to clear the value
9781history. (This is necessary in order to preserve the integrity of
d4f3574e 9782debugger's data structures that reference the target system's symbol
104c1213
JM
9783table.)
9784
9785@node VxWorks Attach
9786@subsubsection Running tasks
9787
9788@cindex running VxWorks tasks
9789You can also attach to an existing task using the @code{attach} command as
9790follows:
9791
9792@example
9793(vxgdb) attach @var{task}
9794@end example
9795
9796@noindent
9797where @var{task} is the VxWorks hexadecimal task ID. The task can be running
9798or suspended when you attach to it. Running tasks are suspended at
9799the time of attachment.
9800
9801@node Embedded Processors
9802@section Embedded Processors
9803
9804This section goes into details specific to particular embedded
9805configurations.
9806
9807@menu
9808* A29K Embedded:: AMD A29K Embedded
9809* ARM:: ARM
9810* H8/300:: Hitachi H8/300
9811* H8/500:: Hitachi H8/500
9812* i960:: Intel i960
9813* M32R/D:: Mitsubishi M32R/D
9814* M68K:: Motorola M68K
9815* M88K:: Motorola M88K
9816* MIPS Embedded:: MIPS Embedded
9817* PA:: HP PA Embedded
9818* PowerPC: PowerPC
9819* SH:: Hitachi SH
9820* Sparclet:: Tsqware Sparclet
9821* Sparclite:: Fujitsu Sparclite
9822* ST2000:: Tandem ST2000
9823* Z8000:: Zilog Z8000
9824@end menu
9825
9826@node A29K Embedded
9827@subsection AMD A29K Embedded
9828
9829@menu
9830* A29K UDI::
9831* A29K EB29K::
9832* Comms (EB29K):: Communications setup
9833* gdb-EB29K:: EB29K cross-debugging
9834* Remote Log:: Remote log
9835@end menu
9836
9837@table @code
9838
9839@kindex target adapt
9840@item target adapt @var{dev}
9841Adapt monitor for A29K.
9842
9843@kindex target amd-eb
9844@item target amd-eb @var{dev} @var{speed} @var{PROG}
9845@cindex AMD EB29K
9846Remote PC-resident AMD EB29K board, attached over serial lines.
9847@var{dev} is the serial device, as for @code{target remote};
9848@var{speed} allows you to specify the linespeed; and @var{PROG} is the
9849name of the program to be debugged, as it appears to DOS on the PC.
9850@xref{A29K EB29K, ,EBMON protocol for AMD29K}.
9851
9852@end table
9853
9854@node A29K UDI
9855@subsubsection A29K UDI
9856
9857@cindex UDI
9858@cindex AMD29K via UDI
9859
9860@value{GDBN} supports AMD's UDI (``Universal Debugger Interface'')
9861protocol for debugging the a29k processor family. To use this
9862configuration with AMD targets running the MiniMON monitor, you need the
9863program @code{MONTIP}, available from AMD at no charge. You can also
9864use @value{GDBN} with the UDI-conformant a29k simulator program
9865@code{ISSTIP}, also available from AMD.
9866
9867@table @code
9868@item target udi @var{keyword}
9869@kindex udi
9870Select the UDI interface to a remote a29k board or simulator, where
9871@var{keyword} is an entry in the AMD configuration file @file{udi_soc}.
9872This file contains keyword entries which specify parameters used to
9873connect to a29k targets. If the @file{udi_soc} file is not in your
9874working directory, you must set the environment variable @samp{UDICONF}
9875to its pathname.
9876@end table
9877
9878@node A29K EB29K
9879@subsubsection EBMON protocol for AMD29K
9880
9881@cindex EB29K board
9882@cindex running 29K programs
9883
9884AMD distributes a 29K development board meant to fit in a PC, together
9885with a DOS-hosted monitor program called @code{EBMON}. As a shorthand
9886term, this development system is called the ``EB29K''. To use
9887@value{GDBN} from a Unix system to run programs on the EB29K board, you
9888must first connect a serial cable between the PC (which hosts the EB29K
9889board) and a serial port on the Unix system. In the following, we
9890assume you've hooked the cable between the PC's @file{COM1} port and
9891@file{/dev/ttya} on the Unix system.
9892
9893@node Comms (EB29K)
9894@subsubsection Communications setup
9895
9896The next step is to set up the PC's port, by doing something like this
9897in DOS on the PC:
9898
9899@example
9900C:\> MODE com1:9600,n,8,1,none
9901@end example
9902
9903@noindent
9904This example---run on an MS DOS 4.0 system---sets the PC port to 9600
9905bps, no parity, eight data bits, one stop bit, and no ``retry'' action;
9906you must match the communications parameters when establishing the Unix
9907end of the connection as well.
9908@c FIXME: Who knows what this "no retry action" crud from the DOS manual may
9909@c mean? It's optional; leave it out? ---doc@cygnus.com, 25feb91
d4f3574e
SS
9910@c
9911@c It's optional, but it's unwise to omit it: who knows what is the
9912@c default value set when the DOS machines boots? "No retry" means that
9913@c the DOS serial device driver won't retry the operation if it fails;
9914@c I understand that this is needed because the GDB serial protocol
9915@c handles any errors and retransmissions itself. ---Eli Zaretskii, 3sep99
104c1213
JM
9916
9917To give control of the PC to the Unix side of the serial line, type
9918the following at the DOS console:
9919
9920@example
9921C:\> CTTY com1
9922@end example
9923
9924@noindent
9925(Later, if you wish to return control to the DOS console, you can use
9926the command @code{CTTY con}---but you must send it over the device that
9927had control, in our example over the @file{COM1} serial line).
9928
9929From the Unix host, use a communications program such as @code{tip} or
9930@code{cu} to communicate with the PC; for example,
9931
9932@example
9933cu -s 9600 -l /dev/ttya
9934@end example
9935
9936@noindent
9937The @code{cu} options shown specify, respectively, the linespeed and the
9938serial port to use. If you use @code{tip} instead, your command line
9939may look something like the following:
9940
9941@example
9942tip -9600 /dev/ttya
9943@end example
9944
9945@noindent
9946Your system may require a different name where we show
9947@file{/dev/ttya} as the argument to @code{tip}. The communications
9948parameters, including which port to use, are associated with the
9949@code{tip} argument in the ``remote'' descriptions file---normally the
9950system table @file{/etc/remote}.
9951@c FIXME: What if anything needs doing to match the "n,8,1,none" part of
9952@c the DOS side's comms setup? cu can support -o (odd
9953@c parity), -e (even parity)---apparently no settings for no parity or
9954@c for character size. Taken from stty maybe...? John points out tip
9955@c can set these as internal variables, eg ~s parity=none; man stty
9956@c suggests that it *might* work to stty these options with stdin or
9957@c stdout redirected... ---doc@cygnus.com, 25feb91
d4f3574e
SS
9958@c
9959@c There's nothing to be done for the "none" part of the DOS MODE
9960@c command. The rest of the parameters should be matched by the
9961@c baudrate, bits, and parity used by the Unix side. ---Eli Zaretskii, 3Sep99
104c1213
JM
9962
9963@kindex EBMON
9964Using the @code{tip} or @code{cu} connection, change the DOS working
9965directory to the directory containing a copy of your 29K program, then
9966start the PC program @code{EBMON} (an EB29K control program supplied
9967with your board by AMD). You should see an initial display from
9968@code{EBMON} similar to the one that follows, ending with the
9969@code{EBMON} prompt @samp{#}---
9970
9971@example
9972C:\> G:
9973
9974G:\> CD \usr\joe\work29k
9975
9976G:\USR\JOE\WORK29K> EBMON
9977Am29000 PC Coprocessor Board Monitor, version 3.0-18
9978Copyright 1990 Advanced Micro Devices, Inc.
9979Written by Gibbons and Associates, Inc.
9980
9981Enter '?' or 'H' for help
9982
9983PC Coprocessor Type = EB29K
9984I/O Base = 0x208
9985Memory Base = 0xd0000
9986
9987Data Memory Size = 2048KB
9988Available I-RAM Range = 0x8000 to 0x1fffff
9989Available D-RAM Range = 0x80002000 to 0x801fffff
9990
9991PageSize = 0x400
9992Register Stack Size = 0x800
9993Memory Stack Size = 0x1800
9994
9995CPU PRL = 0x3
9996Am29027 Available = No
9997Byte Write Available = Yes
9998
9999# ~.
10000@end example
10001
10002Then exit the @code{cu} or @code{tip} program (done in the example by
10003typing @code{~.} at the @code{EBMON} prompt). @code{EBMON} keeps
10004running, ready for @value{GDBN} to take over.
10005
10006For this example, we've assumed what is probably the most convenient
10007way to make sure the same 29K program is on both the PC and the Unix
d4f3574e 10008system: a PC/NFS connection that establishes ``drive @file{G:}'' on the
104c1213
JM
10009PC as a file system on the Unix host. If you do not have PC/NFS or
10010something similar connecting the two systems, you must arrange some
10011other way---perhaps floppy-disk transfer---of getting the 29K program
10012from the Unix system to the PC; @value{GDBN} does @emph{not} download it over the
10013serial line.
10014
10015@node gdb-EB29K
10016@subsubsection EB29K cross-debugging
10017
10018Finally, @code{cd} to the directory containing an image of your 29K
10019program on the Unix system, and start @value{GDBN}---specifying as argument the
10020name of your 29K program:
10021
10022@example
10023cd /usr/joe/work29k
10024@value{GDBP} myfoo
10025@end example
10026
10027@need 500
10028Now you can use the @code{target} command:
10029
10030@example
10031target amd-eb /dev/ttya 9600 MYFOO
10032@c FIXME: test above 'target amd-eb' as spelled, with caps! caps are meant to
10033@c emphasize that this is the name as seen by DOS (since I think DOS is
10034@c single-minded about case of letters). ---doc@cygnus.com, 25feb91
10035@end example
10036
10037@noindent
10038In this example, we've assumed your program is in a file called
10039@file{myfoo}. Note that the filename given as the last argument to
10040@code{target amd-eb} should be the name of the program as it appears to DOS.
10041In our example this is simply @code{MYFOO}, but in general it can include
10042a DOS path, and depending on your transfer mechanism may not resemble
10043the name on the Unix side.
10044
10045At this point, you can set any breakpoints you wish; when you are ready
10046to see your program run on the 29K board, use the @value{GDBN} command
10047@code{run}.
10048
10049To stop debugging the remote program, use the @value{GDBN} @code{detach}
10050command.
10051
10052To return control of the PC to its console, use @code{tip} or @code{cu}
10053once again, after your @value{GDBN} session has concluded, to attach to
10054@code{EBMON}. You can then type the command @code{q} to shut down
10055@code{EBMON}, returning control to the DOS command-line interpreter.
d4f3574e 10056Type @kbd{CTTY con} to return command input to the main DOS console,
104c1213
JM
10057and type @kbd{~.} to leave @code{tip} or @code{cu}.
10058
10059@node Remote Log
10060@subsubsection Remote log
10061@kindex eb.log
10062@cindex log file for EB29K
10063
10064The @code{target amd-eb} command creates a file @file{eb.log} in the
10065current working directory, to help debug problems with the connection.
10066@file{eb.log} records all the output from @code{EBMON}, including echoes
10067of the commands sent to it. Running @samp{tail -f} on this file in
10068another window often helps to understand trouble with @code{EBMON}, or
10069unexpected events on the PC side of the connection.
10070
10071@node ARM
10072@subsection ARM
10073
10074@table @code
10075
10076@kindex target rdi
10077@item target rdi @var{dev}
10078ARM Angel monitor, via RDI library interface to ADP protocol. You may
10079use this target to communicate with both boards running the Angel
10080monitor, or with the EmbeddedICE JTAG debug device.
10081
10082@kindex target rdp
10083@item target rdp @var{dev}
10084ARM Demon monitor.
10085
10086@end table
10087
10088@node H8/300
10089@subsection Hitachi H8/300
10090
10091@table @code
10092
d4f3574e 10093@kindex target hms@r{, with H8/300}
104c1213
JM
10094@item target hms @var{dev}
10095A Hitachi SH, H8/300, or H8/500 board, attached via serial line to your host.
10096Use special commands @code{device} and @code{speed} to control the serial
10097line and the communications speed used.
10098
d4f3574e 10099@kindex target e7000@r{, with H8/300}
104c1213
JM
10100@item target e7000 @var{dev}
10101E7000 emulator for Hitachi H8 and SH.
10102
d4f3574e
SS
10103@kindex target sh3@r{, with H8/300}
10104@kindex target sh3e@r{, with H8/300}
104c1213
JM
10105@item target sh3 @var{dev}
10106@item target sh3e @var{dev}
10107Hitachi SH-3 and SH-3E target systems.
10108
10109@end table
10110
10111@cindex download to H8/300 or H8/500
10112@cindex H8/300 or H8/500 download
10113@cindex download to Hitachi SH
10114@cindex Hitachi SH download
10115When you select remote debugging to a Hitachi SH, H8/300, or H8/500
10116board, the @code{load} command downloads your program to the Hitachi
10117board and also opens it as the current executable target for
10118@value{GDBN} on your host (like the @code{file} command).
10119
10120@value{GDBN} needs to know these things to talk to your
10121Hitachi SH, H8/300, or H8/500:
10122
10123@enumerate
10124@item
10125that you want to use @samp{target hms}, the remote debugging interface
10126for Hitachi microprocessors, or @samp{target e7000}, the in-circuit
10127emulator for the Hitachi SH and the Hitachi 300H. (@samp{target hms} is
2df3850c 10128the default when @value{GDBN} is configured specifically for the Hitachi SH,
104c1213
JM
10129H8/300, or H8/500.)
10130
10131@item
10132what serial device connects your host to your Hitachi board (the first
10133serial device available on your host is the default).
10134
10135@item
10136what speed to use over the serial device.
10137@end enumerate
10138
10139@menu
10140* Hitachi Boards:: Connecting to Hitachi boards.
10141* Hitachi ICE:: Using the E7000 In-Circuit Emulator.
10142* Hitachi Special:: Special @value{GDBN} commands for Hitachi micros.
10143@end menu
10144
10145@node Hitachi Boards
10146@subsubsection Connecting to Hitachi boards
10147
10148@c only for Unix hosts
10149@kindex device
10150@cindex serial device, Hitachi micros
10151Use the special @code{@value{GDBP}} command @samp{device @var{port}} if you
10152need to explicitly set the serial device. The default @var{port} is the
10153first available port on your host. This is only necessary on Unix
10154hosts, where it is typically something like @file{/dev/ttya}.
10155
10156@kindex speed
10157@cindex serial line speed, Hitachi micros
10158@code{@value{GDBP}} has another special command to set the communications
10159speed: @samp{speed @var{bps}}. This command also is only used from Unix
2df3850c 10160hosts; on DOS hosts, set the line speed as usual from outside @value{GDBN} with
d4f3574e
SS
10161the DOS @code{mode} command (for instance,
10162@w{@kbd{mode com2:9600,n,8,1,p}} for a 9600@dmn{bps} connection).
104c1213
JM
10163
10164The @samp{device} and @samp{speed} commands are available only when you
10165use a Unix host to debug your Hitachi microprocessor programs. If you
10166use a DOS host,
10167@value{GDBN} depends on an auxiliary terminate-and-stay-resident program
10168called @code{asynctsr} to communicate with the development board
10169through a PC serial port. You must also use the DOS @code{mode} command
10170to set up the serial port on the DOS side.
10171
10172The following sample session illustrates the steps needed to start a
10173program under @value{GDBN} control on an H8/300. The example uses a
10174sample H8/300 program called @file{t.x}. The procedure is the same for
10175the Hitachi SH and the H8/500.
10176
10177First hook up your development board. In this example, we use a
10178board attached to serial port @code{COM2}; if you use a different serial
10179port, substitute its name in the argument of the @code{mode} command.
10180When you call @code{asynctsr}, the auxiliary comms program used by the
d4f3574e 10181debugger, you give it just the numeric part of the serial port's name;
104c1213
JM
10182for example, @samp{asyncstr 2} below runs @code{asyncstr} on
10183@code{COM2}.
10184
10185@example
10186C:\H8300\TEST> asynctsr 2
10187C:\H8300\TEST> mode com2:9600,n,8,1,p
10188
10189Resident portion of MODE loaded
10190
10191COM2: 9600, n, 8, 1, p
10192
10193@end example
10194
10195@quotation
10196@emph{Warning:} We have noticed a bug in PC-NFS that conflicts with
10197@code{asynctsr}. If you also run PC-NFS on your DOS host, you may need to
10198disable it, or even boot without it, to use @code{asynctsr} to control
10199your development board.
10200@end quotation
10201
d4f3574e 10202@kindex target hms@r{, and serial protocol}
104c1213
JM
10203Now that serial communications are set up, and the development board is
10204connected, you can start up @value{GDBN}. Call @code{@value{GDBP}} with
10205the name of your program as the argument. @code{@value{GDBP}} prompts
10206you, as usual, with the prompt @samp{(@value{GDBP})}. Use two special
10207commands to begin your debugging session: @samp{target hms} to specify
10208cross-debugging to the Hitachi board, and the @code{load} command to
10209download your program to the board. @code{load} displays the names of
10210the program's sections, and a @samp{*} for each 2K of data downloaded.
10211(If you want to refresh @value{GDBN} data on symbols or on the
10212executable file without downloading, use the @value{GDBN} commands
10213@code{file} or @code{symbol-file}. These commands, and @code{load}
10214itself, are described in @ref{Files,,Commands to specify files}.)
10215
10216@smallexample
10217(eg-C:\H8300\TEST) @value{GDBP} t.x
2df3850c 10218@value{GDBN} is free software and you are welcome to distribute copies
104c1213
JM
10219 of it under certain conditions; type "show copying" to see
10220 the conditions.
2df3850c 10221There is absolutely no warranty for @value{GDBN}; type "show warranty"
104c1213 10222for details.
2df3850c
JM
10223@value{GDBN} @value{GDBVN}, Copyright 1992 Free Software Foundation, Inc...
10224(@value{GDBP}) target hms
104c1213 10225Connected to remote H8/300 HMS system.
2df3850c 10226(@value{GDBP}) load t.x
104c1213
JM
10227.text : 0x8000 .. 0xabde ***********
10228.data : 0xabde .. 0xad30 *
10229.stack : 0xf000 .. 0xf014 *
10230@end smallexample
10231
10232At this point, you're ready to run or debug your program. From here on,
10233you can use all the usual @value{GDBN} commands. The @code{break} command
10234sets breakpoints; the @code{run} command starts your program;
10235@code{print} or @code{x} display data; the @code{continue} command
10236resumes execution after stopping at a breakpoint. You can use the
10237@code{help} command at any time to find out more about @value{GDBN} commands.
10238
10239Remember, however, that @emph{operating system} facilities aren't
10240available on your development board; for example, if your program hangs,
10241you can't send an interrupt---but you can press the @sc{reset} switch!
10242
10243Use the @sc{reset} button on the development board
10244@itemize @bullet
10245@item
10246to interrupt your program (don't use @kbd{ctl-C} on the DOS host---it has
10247no way to pass an interrupt signal to the development board); and
10248
10249@item
10250to return to the @value{GDBN} command prompt after your program finishes
10251normally. The communications protocol provides no other way for @value{GDBN}
10252to detect program completion.
10253@end itemize
10254
10255In either case, @value{GDBN} sees the effect of a @sc{reset} on the
10256development board as a ``normal exit'' of your program.
10257
10258@node Hitachi ICE
10259@subsubsection Using the E7000 in-circuit emulator
10260
d4f3574e 10261@kindex target e7000@r{, with Hitachi ICE}
104c1213
JM
10262You can use the E7000 in-circuit emulator to develop code for either the
10263Hitachi SH or the H8/300H. Use one of these forms of the @samp{target
10264e7000} command to connect @value{GDBN} to your E7000:
10265
10266@table @code
10267@item target e7000 @var{port} @var{speed}
10268Use this form if your E7000 is connected to a serial port. The
10269@var{port} argument identifies what serial port to use (for example,
10270@samp{com2}). The third argument is the line speed in bits per second
10271(for example, @samp{9600}).
10272
10273@item target e7000 @var{hostname}
10274If your E7000 is installed as a host on a TCP/IP network, you can just
10275specify its hostname; @value{GDBN} uses @code{telnet} to connect.
10276@end table
10277
10278@node Hitachi Special
10279@subsubsection Special @value{GDBN} commands for Hitachi micros
10280
10281Some @value{GDBN} commands are available only for the H8/300:
10282
10283@table @code
10284
10285@kindex set machine
10286@kindex show machine
10287@item set machine h8300
10288@itemx set machine h8300h
10289Condition @value{GDBN} for one of the two variants of the H8/300
10290architecture with @samp{set machine}. You can use @samp{show machine}
10291to check which variant is currently in effect.
10292
10293@end table
10294
10295@node H8/500
10296@subsection H8/500
10297
10298@table @code
10299
10300@kindex set memory @var{mod}
10301@cindex memory models, H8/500
10302@item set memory @var{mod}
10303@itemx show memory
10304Specify which H8/500 memory model (@var{mod}) you are using with
10305@samp{set memory}; check which memory model is in effect with @samp{show
10306memory}. The accepted values for @var{mod} are @code{small},
10307@code{big}, @code{medium}, and @code{compact}.
10308
10309@end table
10310
10311@node i960
10312@subsection Intel i960
10313
10314@table @code
10315
10316@kindex target mon960
10317@item target mon960 @var{dev}
10318MON960 monitor for Intel i960.
10319
10320@item target nindy @var{devicename}
10321An Intel 960 board controlled by a Nindy Monitor. @var{devicename} is
10322the name of the serial device to use for the connection, e.g.
10323@file{/dev/ttya}.
10324
10325@end table
10326
10327@cindex Nindy
10328@cindex i960
10329@dfn{Nindy} is a ROM Monitor program for Intel 960 target systems. When
10330@value{GDBN} is configured to control a remote Intel 960 using Nindy, you can
10331tell @value{GDBN} how to connect to the 960 in several ways:
10332
10333@itemize @bullet
10334@item
10335Through command line options specifying serial port, version of the
10336Nindy protocol, and communications speed;
10337
10338@item
10339By responding to a prompt on startup;
10340
10341@item
10342By using the @code{target} command at any point during your @value{GDBN}
10343session. @xref{Target Commands, ,Commands for managing targets}.
10344
10345@kindex target nindy
10346@item target nindy @var{devicename}
10347An Intel 960 board controlled by a Nindy Monitor. @var{devicename} is
10348the name of the serial device to use for the connection, e.g.
10349@file{/dev/ttya}.
10350
10351@end itemize
10352
10353@cindex download to Nindy-960
10354With the Nindy interface to an Intel 960 board, @code{load}
10355downloads @var{filename} to the 960 as well as adding its symbols in
10356@value{GDBN}.
10357
10358@menu
10359* Nindy Startup:: Startup with Nindy
10360* Nindy Options:: Options for Nindy
10361* Nindy Reset:: Nindy reset command
10362@end menu
10363
10364@node Nindy Startup
10365@subsubsection Startup with Nindy
10366
10367If you simply start @code{@value{GDBP}} without using any command-line
10368options, you are prompted for what serial port to use, @emph{before} you
10369reach the ordinary @value{GDBN} prompt:
10370
10371@example
10372Attach /dev/ttyNN -- specify NN, or "quit" to quit:
10373@end example
10374
10375@noindent
10376Respond to the prompt with whatever suffix (after @samp{/dev/tty})
10377identifies the serial port you want to use. You can, if you choose,
10378simply start up with no Nindy connection by responding to the prompt
10379with an empty line. If you do this and later wish to attach to Nindy,
10380use @code{target} (@pxref{Target Commands, ,Commands for managing targets}).
10381
10382@node Nindy Options
10383@subsubsection Options for Nindy
10384
10385These are the startup options for beginning your @value{GDBN} session with a
10386Nindy-960 board attached:
10387
10388@table @code
10389@item -r @var{port}
10390Specify the serial port name of a serial interface to be used to connect
10391to the target system. This option is only available when @value{GDBN} is
10392configured for the Intel 960 target architecture. You may specify
10393@var{port} as any of: a full pathname (e.g. @samp{-r /dev/ttya}), a
10394device name in @file{/dev} (e.g. @samp{-r ttya}), or simply the unique
10395suffix for a specific @code{tty} (e.g. @samp{-r a}).
10396
10397@item -O
10398(An uppercase letter ``O'', not a zero.) Specify that @value{GDBN} should use
10399the ``old'' Nindy monitor protocol to connect to the target system.
10400This option is only available when @value{GDBN} is configured for the Intel 960
10401target architecture.
10402
10403@quotation
10404@emph{Warning:} if you specify @samp{-O}, but are actually trying to
10405connect to a target system that expects the newer protocol, the connection
10406fails, appearing to be a speed mismatch. @value{GDBN} repeatedly
10407attempts to reconnect at several different line speeds. You can abort
10408this process with an interrupt.
10409@end quotation
10410
10411@item -brk
10412Specify that @value{GDBN} should first send a @code{BREAK} signal to the target
10413system, in an attempt to reset it, before connecting to a Nindy target.
10414
10415@quotation
10416@emph{Warning:} Many target systems do not have the hardware that this
10417requires; it only works with a few boards.
10418@end quotation
10419@end table
10420
10421The standard @samp{-b} option controls the line speed used on the serial
10422port.
10423
10424@c @group
10425@node Nindy Reset
10426@subsubsection Nindy reset command
10427
10428@table @code
10429@item reset
10430@kindex reset
10431For a Nindy target, this command sends a ``break'' to the remote target
10432system; this is only useful if the target has been equipped with a
10433circuit to perform a hard reset (or some other interesting action) when
10434a break is detected.
10435@end table
10436@c @end group
10437
10438@node M32R/D
10439@subsection Mitsubishi M32R/D
10440
10441@table @code
10442
10443@kindex target m32r
10444@item target m32r @var{dev}
10445Mitsubishi M32R/D ROM monitor.
10446
10447@end table
10448
10449@node M68K
10450@subsection M68k
10451
10452The Motorola m68k configuration includes ColdFire support, and
10453target command for the following ROM monitors.
10454
10455@table @code
10456
10457@kindex target abug
10458@item target abug @var{dev}
10459ABug ROM monitor for M68K.
10460
10461@kindex target cpu32bug
10462@item target cpu32bug @var{dev}
10463CPU32BUG monitor, running on a CPU32 (M68K) board.
10464
10465@kindex target dbug
10466@item target dbug @var{dev}
10467dBUG ROM monitor for Motorola ColdFire.
10468
10469@kindex target est
10470@item target est @var{dev}
10471EST-300 ICE monitor, running on a CPU32 (M68K) board.
10472
10473@kindex target rom68k
10474@item target rom68k @var{dev}
10475ROM 68K monitor, running on an M68K IDP board.
10476
10477@end table
10478
10479If @value{GDBN} is configured with @code{m68*-ericsson-*}, it will
10480instead have only a single special target command:
10481
10482@table @code
10483
10484@kindex target es1800
10485@item target es1800 @var{dev}
10486ES-1800 emulator for M68K.
10487
10488@end table
10489
10490[context?]
10491
10492@table @code
10493
10494@kindex target rombug
10495@item target rombug @var{dev}
10496ROMBUG ROM monitor for OS/9000.
10497
10498@end table
10499
10500@node M88K
10501@subsection M88K
10502
10503@table @code
10504
10505@kindex target bug
10506@item target bug @var{dev}
10507BUG monitor, running on a MVME187 (m88k) board.
10508
10509@end table
10510
10511@node MIPS Embedded
10512@subsection MIPS Embedded
10513
10514@cindex MIPS boards
10515@value{GDBN} can use the MIPS remote debugging protocol to talk to a
10516MIPS board attached to a serial line. This is available when
10517you configure @value{GDBN} with @samp{--target=mips-idt-ecoff}.
10518
10519@need 1000
10520Use these @value{GDBN} commands to specify the connection to your target board:
10521
10522@table @code
10523@item target mips @var{port}
10524@kindex target mips @var{port}
10525To run a program on the board, start up @code{@value{GDBP}} with the
10526name of your program as the argument. To connect to the board, use the
10527command @samp{target mips @var{port}}, where @var{port} is the name of
10528the serial port connected to the board. If the program has not already
10529been downloaded to the board, you may use the @code{load} command to
10530download it. You can then use all the usual @value{GDBN} commands.
10531
10532For example, this sequence connects to the target board through a serial
10533port, and loads and runs a program called @var{prog} through the
10534debugger:
10535
10536@example
10537host$ @value{GDBP} @var{prog}
2df3850c
JM
10538@value{GDBN} is free software and @dots{}
10539(@value{GDBP}) target mips /dev/ttyb
10540(@value{GDBP}) load @var{prog}
10541(@value{GDBP}) run
104c1213
JM
10542@end example
10543
10544@item target mips @var{hostname}:@var{portnumber}
10545On some @value{GDBN} host configurations, you can specify a TCP
10546connection (for instance, to a serial line managed by a terminal
10547concentrator) instead of a serial port, using the syntax
10548@samp{@var{hostname}:@var{portnumber}}.
10549
10550@item target pmon @var{port}
10551@kindex target pmon @var{port}
10552PMON ROM monitor.
10553
10554@item target ddb @var{port}
10555@kindex target ddb @var{port}
10556NEC's DDB variant of PMON for Vr4300.
10557
10558@item target lsi @var{port}
10559@kindex target lsi @var{port}
10560LSI variant of PMON.
10561
10562@kindex target r3900
10563@item target r3900 @var{dev}
10564Densan DVE-R3900 ROM monitor for Toshiba R3900 Mips.
10565
10566@kindex target array
10567@item target array @var{dev}
10568Array Tech LSI33K RAID controller board.
10569
10570@end table
10571
10572
10573@noindent
10574@value{GDBN} also supports these special commands for MIPS targets:
10575
10576@table @code
10577@item set processor @var{args}
10578@itemx show processor
10579@kindex set processor @var{args}
10580@kindex show processor
10581Use the @code{set processor} command to set the type of MIPS
10582processor when you want to access processor-type-specific registers.
10583For example, @code{set processor @var{r3041}} tells @value{GDBN}
10584to use the CPO registers appropriate for the 3041 chip.
10585Use the @code{show processor} command to see what MIPS processor @value{GDBN}
10586is using. Use the @code{info reg} command to see what registers
10587@value{GDBN} is using.
10588
10589@item set mipsfpu double
10590@itemx set mipsfpu single
10591@itemx set mipsfpu none
10592@itemx show mipsfpu
10593@kindex set mipsfpu
10594@kindex show mipsfpu
10595@cindex MIPS remote floating point
10596@cindex floating point, MIPS remote
10597If your target board does not support the MIPS floating point
10598coprocessor, you should use the command @samp{set mipsfpu none} (if you
10599need this, you may wish to put the command in your @value{GDBINIT}
10600file). This tells @value{GDBN} how to find the return value of
10601functions which return floating point values. It also allows
10602@value{GDBN} to avoid saving the floating point registers when calling
10603functions on the board. If you are using a floating point coprocessor
10604with only single precision floating point support, as on the @sc{r4650}
10605processor, use the command @samp{set mipsfpu single}. The default
10606double precision floating point coprocessor may be selected using
10607@samp{set mipsfpu double}.
10608
10609In previous versions the only choices were double precision or no
10610floating point, so @samp{set mipsfpu on} will select double precision
10611and @samp{set mipsfpu off} will select no floating point.
10612
10613As usual, you can inquire about the @code{mipsfpu} variable with
10614@samp{show mipsfpu}.
10615
10616@item set remotedebug @var{n}
10617@itemx show remotedebug
d4f3574e
SS
10618@kindex set remotedebug@r{, MIPS protocol}
10619@kindex show remotedebug@r{, MIPS protocol}
104c1213
JM
10620@cindex @code{remotedebug}, MIPS protocol
10621@cindex MIPS @code{remotedebug} protocol
10622@c FIXME! For this to be useful, you must know something about the MIPS
10623@c FIXME...protocol. Where is it described?
10624You can see some debugging information about communications with the board
10625by setting the @code{remotedebug} variable. If you set it to @code{1} using
10626@samp{set remotedebug 1}, every packet is displayed. If you set it
10627to @code{2}, every character is displayed. You can check the current value
10628at any time with the command @samp{show remotedebug}.
10629
10630@item set timeout @var{seconds}
10631@itemx set retransmit-timeout @var{seconds}
10632@itemx show timeout
10633@itemx show retransmit-timeout
10634@cindex @code{timeout}, MIPS protocol
10635@cindex @code{retransmit-timeout}, MIPS protocol
10636@kindex set timeout
10637@kindex show timeout
10638@kindex set retransmit-timeout
10639@kindex show retransmit-timeout
10640You can control the timeout used while waiting for a packet, in the MIPS
10641remote protocol, with the @code{set timeout @var{seconds}} command. The
10642default is 5 seconds. Similarly, you can control the timeout used while
10643waiting for an acknowledgement of a packet with the @code{set
10644retransmit-timeout @var{seconds}} command. The default is 3 seconds.
10645You can inspect both values with @code{show timeout} and @code{show
10646retransmit-timeout}. (These commands are @emph{only} available when
10647@value{GDBN} is configured for @samp{--target=mips-idt-ecoff}.)
10648
10649The timeout set by @code{set timeout} does not apply when @value{GDBN}
10650is waiting for your program to stop. In that case, @value{GDBN} waits
10651forever because it has no way of knowing how long the program is going
10652to run before stopping.
10653@end table
10654
10655@node PowerPC
10656@subsection PowerPC
10657
10658@table @code
10659
10660@kindex target dink32
10661@item target dink32 @var{dev}
10662DINK32 ROM monitor.
10663
10664@kindex target ppcbug
10665@item target ppcbug @var{dev}
10666@kindex target ppcbug1
10667@item target ppcbug1 @var{dev}
10668PPCBUG ROM monitor for PowerPC.
10669
10670@kindex target sds
10671@item target sds @var{dev}
10672SDS monitor, running on a PowerPC board (such as Motorola's ADS).
10673
10674@end table
10675
10676@node PA
10677@subsection HP PA Embedded
10678
10679@table @code
10680
10681@kindex target op50n
10682@item target op50n @var{dev}
10683OP50N monitor, running on an OKI HPPA board.
10684
10685@kindex target w89k
10686@item target w89k @var{dev}
10687W89K monitor, running on a Winbond HPPA board.
10688
10689@end table
10690
10691@node SH
10692@subsection Hitachi SH
10693
10694@table @code
10695
d4f3574e 10696@kindex target hms@r{, with Hitachi SH}
104c1213
JM
10697@item target hms @var{dev}
10698A Hitachi SH board attached via serial line to your host. Use special
10699commands @code{device} and @code{speed} to control the serial line and
10700the communications speed used.
10701
d4f3574e 10702@kindex target e7000@r{, with Hitachi SH}
104c1213
JM
10703@item target e7000 @var{dev}
10704E7000 emulator for Hitachi SH.
10705
d4f3574e
SS
10706@kindex target sh3@r{, with SH}
10707@kindex target sh3e@r{, with SH}
104c1213
JM
10708@item target sh3 @var{dev}
10709@item target sh3e @var{dev}
10710Hitachi SH-3 and SH-3E target systems.
10711
10712@end table
10713
10714@node Sparclet
10715@subsection Tsqware Sparclet
10716
10717@cindex Sparclet
10718
10719@value{GDBN} enables developers to debug tasks running on
10720Sparclet targets from a Unix host.
10721@value{GDBN} uses code that runs on
10722both the Unix host and on the Sparclet target. The program
d4f3574e 10723@code{@value{GDBP}} is installed and executed on the Unix host.
104c1213
JM
10724
10725@table @code
10726@item timeout @var{args}
10727@kindex remotetimeout
d4f3574e 10728@value{GDBN} supports the option @code{remotetimeout}.
104c1213
JM
10729This option is set by the user, and @var{args} represents the number of
10730seconds @value{GDBN} waits for responses.
10731@end table
10732
10733@kindex Compiling
d4f3574e
SS
10734When compiling for debugging, include the options @samp{-g} to get debug
10735information and @samp{-Ttext} to relocate the program to where you wish to
10736load it on the target. You may also want to add the options @samp{-n} or
10737@samp{-N} in order to reduce the size of the sections. Example:
104c1213
JM
10738
10739@example
10740sparclet-aout-gcc prog.c -Ttext 0x12010000 -g -o prog -N
10741@end example
10742
d4f3574e 10743You can use @code{objdump} to verify that the addresses are what you intended:
104c1213
JM
10744
10745@example
10746sparclet-aout-objdump --headers --syms prog
10747@end example
10748
10749@kindex Running
10750Once you have set
10751your Unix execution search path to find @value{GDBN}, you are ready to
d4f3574e 10752run @value{GDBN}. From your Unix host, run @code{@value{GDBP}}
104c1213
JM
10753(or @code{sparclet-aout-gdb}, depending on your installation).
10754
10755@value{GDBN} comes up showing the prompt:
10756
10757@example
10758(gdbslet)
10759@end example
10760
10761@menu
10762* Sparclet File:: Setting the file to debug
10763* Sparclet Connection:: Connecting to Sparclet
10764* Sparclet Download:: Sparclet download
10765* Sparclet Execution:: Running and debugging
10766@end menu
10767
10768@node Sparclet File
10769@subsubsection Setting file to debug
10770
10771The @value{GDBN} command @code{file} lets you choose with program to debug.
10772
10773@example
10774(gdbslet) file prog
10775@end example
10776
10777@need 1000
10778@value{GDBN} then attempts to read the symbol table of @file{prog}.
10779@value{GDBN} locates
10780the file by searching the directories listed in the command search
10781path.
10782If the file was compiled with debug information (option "-g"), source
10783files will be searched as well.
10784@value{GDBN} locates
10785the source files by searching the directories listed in the directory search
10786path (@pxref{Environment, ,Your program's environment}).
10787If it fails
10788to find a file, it displays a message such as:
10789
10790@example
10791prog: No such file or directory.
10792@end example
10793
10794When this happens, add the appropriate directories to the search paths with
10795the @value{GDBN} commands @code{path} and @code{dir}, and execute the
10796@code{target} command again.
10797
10798@node Sparclet Connection
10799@subsubsection Connecting to Sparclet
10800
10801The @value{GDBN} command @code{target} lets you connect to a Sparclet target.
10802To connect to a target on serial port ``@code{ttya}'', type:
10803
10804@example
10805(gdbslet) target sparclet /dev/ttya
10806Remote target sparclet connected to /dev/ttya
10807main () at ../prog.c:3
10808@end example
10809
10810@need 750
10811@value{GDBN} displays messages like these:
10812
d4f3574e 10813@example
104c1213 10814Connected to ttya.
d4f3574e 10815@end example
104c1213
JM
10816
10817@node Sparclet Download
10818@subsubsection Sparclet download
10819
10820@cindex download to Sparclet
10821Once connected to the Sparclet target,
10822you can use the @value{GDBN}
10823@code{load} command to download the file from the host to the target.
10824The file name and load offset should be given as arguments to the @code{load}
10825command.
10826Since the file format is aout, the program must be loaded to the starting
d4f3574e 10827address. You can use @code{objdump} to find out what this value is. The load
104c1213
JM
10828offset is an offset which is added to the VMA (virtual memory address)
10829of each of the file's sections.
10830For instance, if the program
10831@file{prog} was linked to text address 0x1201000, with data at 0x12010160
10832and bss at 0x12010170, in @value{GDBN}, type:
10833
10834@example
10835(gdbslet) load prog 0x12010000
10836Loading section .text, size 0xdb0 vma 0x12010000
10837@end example
10838
10839If the code is loaded at a different address then what the program was linked
10840to, you may need to use the @code{section} and @code{add-symbol-file} commands
10841to tell @value{GDBN} where to map the symbol table.
10842
10843@node Sparclet Execution
10844@subsubsection Running and debugging
10845
10846@cindex running and debugging Sparclet programs
10847You can now begin debugging the task using @value{GDBN}'s execution control
10848commands, @code{b}, @code{step}, @code{run}, etc. See the @value{GDBN}
10849manual for the list of commands.
10850
10851@example
10852(gdbslet) b main
10853Breakpoint 1 at 0x12010000: file prog.c, line 3.
10854(gdbslet) run
10855Starting program: prog
10856Breakpoint 1, main (argc=1, argv=0xeffff21c) at prog.c:3
108573 char *symarg = 0;
10858(gdbslet) step
108594 char *execarg = "hello!";
10860(gdbslet)
10861@end example
10862
10863@node Sparclite
10864@subsection Fujitsu Sparclite
10865
10866@table @code
10867
10868@kindex target sparclite
10869@item target sparclite @var{dev}
10870Fujitsu sparclite boards, used only for the purpose of loading.
10871You must use an additional command to debug the program.
10872For example: target remote @var{dev} using @value{GDBN} standard
10873remote protocol.
10874
10875@end table
10876
10877@node ST2000
10878@subsection Tandem ST2000
10879
2df3850c 10880@value{GDBN} may be used with a Tandem ST2000 phone switch, running Tandem's
104c1213
JM
10881STDBUG protocol.
10882
10883To connect your ST2000 to the host system, see the manufacturer's
10884manual. Once the ST2000 is physically attached, you can run:
10885
10886@example
10887target st2000 @var{dev} @var{speed}
10888@end example
10889
10890@noindent
10891to establish it as your debugging environment. @var{dev} is normally
10892the name of a serial device, such as @file{/dev/ttya}, connected to the
10893ST2000 via a serial line. You can instead specify @var{dev} as a TCP
10894connection (for example, to a serial line attached via a terminal
10895concentrator) using the syntax @code{@var{hostname}:@var{portnumber}}.
10896
10897The @code{load} and @code{attach} commands are @emph{not} defined for
10898this target; you must load your program into the ST2000 as you normally
10899would for standalone operation. @value{GDBN} reads debugging information
10900(such as symbols) from a separate, debugging version of the program
10901available on your host computer.
10902@c FIXME!! This is terribly vague; what little content is here is
10903@c basically hearsay.
10904
10905@cindex ST2000 auxiliary commands
10906These auxiliary @value{GDBN} commands are available to help you with the ST2000
10907environment:
10908
10909@table @code
10910@item st2000 @var{command}
10911@kindex st2000 @var{cmd}
10912@cindex STDBUG commands (ST2000)
10913@cindex commands to STDBUG (ST2000)
10914Send a @var{command} to the STDBUG monitor. See the manufacturer's
10915manual for available commands.
10916
10917@item connect
10918@cindex connect (to STDBUG)
10919Connect the controlling terminal to the STDBUG command monitor. When
10920you are done interacting with STDBUG, typing either of two character
10921sequences gets you back to the @value{GDBN} command prompt:
10922@kbd{@key{RET}~.} (Return, followed by tilde and period) or
10923@kbd{@key{RET}~@key{C-d}} (Return, followed by tilde and control-D).
10924@end table
10925
10926@node Z8000
10927@subsection Zilog Z8000
10928
10929@cindex Z8000
10930@cindex simulator, Z8000
10931@cindex Zilog Z8000 simulator
10932
10933When configured for debugging Zilog Z8000 targets, @value{GDBN} includes
10934a Z8000 simulator.
10935
10936For the Z8000 family, @samp{target sim} simulates either the Z8002 (the
10937unsegmented variant of the Z8000 architecture) or the Z8001 (the
10938segmented variant). The simulator recognizes which architecture is
10939appropriate by inspecting the object code.
10940
10941@table @code
10942@item target sim @var{args}
10943@kindex sim
d4f3574e 10944@kindex target sim@r{, with Z8000}
104c1213
JM
10945Debug programs on a simulated CPU. If the simulator supports setup
10946options, specify them via @var{args}.
10947@end table
10948
10949@noindent
10950After specifying this target, you can debug programs for the simulated
10951CPU in the same style as programs for your host computer; use the
10952@code{file} command to load a new program image, the @code{run} command
10953to run your program, and so on.
10954
d4f3574e
SS
10955As well as making available all the usual machine registers
10956(@pxref{Registers, ,Registers}), the Z8000 simulator provides three
10957additional items of information as specially named registers:
104c1213
JM
10958
10959@table @code
10960
10961@item cycles
10962Counts clock-ticks in the simulator.
10963
10964@item insts
10965Counts instructions run in the simulator.
10966
10967@item time
10968Execution time in 60ths of a second.
10969
10970@end table
10971
10972You can refer to these values in @value{GDBN} expressions with the usual
10973conventions; for example, @w{@samp{b fputc if $cycles>5000}} sets a
10974conditional breakpoint that suspends only after at least 5000
10975simulated clock ticks.
10976
10977@node Architectures
10978@section Architectures
10979
10980This section describes characteristics of architectures that affect
2df3850c 10981all uses of @value{GDBN} with the architecture, both native and cross.
104c1213
JM
10982
10983@menu
10984* A29K::
10985* Alpha::
10986* MIPS::
10987@end menu
10988
10989@node A29K
10990@subsection A29K
10991
10992@table @code
10993
10994@kindex set rstack_high_address
10995@cindex AMD 29K register stack
10996@cindex register stack, AMD29K
10997@item set rstack_high_address @var{address}
10998On AMD 29000 family processors, registers are saved in a separate
d4f3574e 10999@dfn{register stack}. There is no way for @value{GDBN} to determine the
104c1213
JM
11000extent of this stack. Normally, @value{GDBN} just assumes that the
11001stack is ``large enough''. This may result in @value{GDBN} referencing
11002memory locations that do not exist. If necessary, you can get around
11003this problem by specifying the ending address of the register stack with
11004the @code{set rstack_high_address} command. The argument should be an
11005address, which you probably want to precede with @samp{0x} to specify in
11006hexadecimal.
11007
11008@kindex show rstack_high_address
11009@item show rstack_high_address
11010Display the current limit of the register stack, on AMD 29000 family
11011processors.
11012
11013@end table
11014
11015@node Alpha
11016@subsection Alpha
11017
11018See the following section.
11019
11020@node MIPS
11021@subsection MIPS
11022
11023@cindex stack on Alpha
11024@cindex stack on MIPS
11025@cindex Alpha stack
11026@cindex MIPS stack
11027Alpha- and MIPS-based computers use an unusual stack frame, which
11028sometimes requires @value{GDBN} to search backward in the object code to
11029find the beginning of a function.
11030
11031@cindex response time, MIPS debugging
11032To improve response time (especially for embedded applications, where
11033@value{GDBN} may be restricted to a slow serial line for this search)
11034you may want to limit the size of this search, using one of these
11035commands:
11036
11037@table @code
11038@cindex @code{heuristic-fence-post} (Alpha,MIPS)
11039@item set heuristic-fence-post @var{limit}
11040Restrict @value{GDBN} to examining at most @var{limit} bytes in its
11041search for the beginning of a function. A value of @var{0} (the
11042default) means there is no limit. However, except for @var{0}, the
11043larger the limit the more bytes @code{heuristic-fence-post} must search
11044and therefore the longer it takes to run.
11045
11046@item show heuristic-fence-post
11047Display the current limit.
11048@end table
11049
11050@noindent
11051These commands are available @emph{only} when @value{GDBN} is configured
11052for debugging programs on Alpha or MIPS processors.
11053
11054
c906108c
SS
11055@node Controlling GDB
11056@chapter Controlling @value{GDBN}
11057
53a5351d
JM
11058You can alter the way @value{GDBN} interacts with you by using the
11059@code{set} command. For commands controlling how @value{GDBN} displays
d4f3574e 11060data, see @ref{Print Settings, ,Print settings}. Other settings are
53a5351d 11061described here.
c906108c
SS
11062
11063@menu
11064* Prompt:: Prompt
11065* Editing:: Command editing
11066* History:: Command history
11067* Screen Size:: Screen size
11068* Numbers:: Numbers
11069* Messages/Warnings:: Optional warnings and messages
11070@end menu
11071
53a5351d 11072@node Prompt
c906108c
SS
11073@section Prompt
11074
11075@cindex prompt
11076
11077@value{GDBN} indicates its readiness to read a command by printing a string
11078called the @dfn{prompt}. This string is normally @samp{(@value{GDBP})}. You
11079can change the prompt string with the @code{set prompt} command. For
11080instance, when debugging @value{GDBN} with @value{GDBN}, it is useful to change
11081the prompt in one of the @value{GDBN} sessions so that you can always tell
11082which one you are talking to.
11083
d4f3574e 11084@emph{Note:} @code{set prompt} does not add a space for you after the
c906108c
SS
11085prompt you set. This allows you to set a prompt which ends in a space
11086or a prompt that does not.
11087
11088@table @code
11089@kindex set prompt
11090@item set prompt @var{newprompt}
11091Directs @value{GDBN} to use @var{newprompt} as its prompt string henceforth.
11092
11093@kindex show prompt
11094@item show prompt
11095Prints a line of the form: @samp{Gdb's prompt is: @var{your-prompt}}
11096@end table
11097
53a5351d 11098@node Editing
c906108c
SS
11099@section Command editing
11100@cindex readline
11101@cindex command line editing
11102
11103@value{GDBN} reads its input commands via the @dfn{readline} interface. This
11104@sc{gnu} library provides consistent behavior for programs which provide a
11105command line interface to the user. Advantages are @sc{gnu} Emacs-style
11106or @dfn{vi}-style inline editing of commands, @code{csh}-like history
11107substitution, and a storage and recall of command history across
11108debugging sessions.
11109
11110You may control the behavior of command line editing in @value{GDBN} with the
11111command @code{set}.
11112
11113@table @code
11114@kindex set editing
11115@cindex editing
11116@item set editing
11117@itemx set editing on
11118Enable command line editing (enabled by default).
11119
11120@item set editing off
11121Disable command line editing.
11122
11123@kindex show editing
11124@item show editing
11125Show whether command line editing is enabled.
11126@end table
11127
53a5351d 11128@node History
c906108c
SS
11129@section Command history
11130
11131@value{GDBN} can keep track of the commands you type during your
11132debugging sessions, so that you can be certain of precisely what
11133happened. Use these commands to manage the @value{GDBN} command
11134history facility.
11135
11136@table @code
11137@cindex history substitution
11138@cindex history file
11139@kindex set history filename
11140@kindex GDBHISTFILE
11141@item set history filename @var{fname}
11142Set the name of the @value{GDBN} command history file to @var{fname}.
11143This is the file where @value{GDBN} reads an initial command history
11144list, and where it writes the command history from this session when it
11145exits. You can access this list through history expansion or through
11146the history command editing characters listed below. This file defaults
11147to the value of the environment variable @code{GDBHISTFILE}, or to
d4f3574e
SS
11148@file{./.gdb_history} (@file{./_gdb_history} on MS-DOS) if this variable
11149is not set.
c906108c
SS
11150
11151@cindex history save
11152@kindex set history save
11153@item set history save
11154@itemx set history save on
11155Record command history in a file, whose name may be specified with the
11156@code{set history filename} command. By default, this option is disabled.
11157
11158@item set history save off
11159Stop recording command history in a file.
11160
11161@cindex history size
11162@kindex set history size
11163@item set history size @var{size}
11164Set the number of commands which @value{GDBN} keeps in its history list.
11165This defaults to the value of the environment variable
11166@code{HISTSIZE}, or to 256 if this variable is not set.
11167@end table
11168
11169@cindex history expansion
11170History expansion assigns special meaning to the character @kbd{!}.
11171@ifset have-readline-appendices
11172@xref{Event Designators}.
11173@end ifset
11174
11175Since @kbd{!} is also the logical not operator in C, history expansion
11176is off by default. If you decide to enable history expansion with the
11177@code{set history expansion on} command, you may sometimes need to
11178follow @kbd{!} (when it is used as logical not, in an expression) with
11179a space or a tab to prevent it from being expanded. The readline
11180history facilities do not attempt substitution on the strings
11181@kbd{!=} and @kbd{!(}, even when history expansion is enabled.
11182
11183The commands to control history expansion are:
11184
11185@table @code
11186@kindex set history expansion
11187@item set history expansion on
11188@itemx set history expansion
11189Enable history expansion. History expansion is off by default.
11190
11191@item set history expansion off
11192Disable history expansion.
11193
11194The readline code comes with more complete documentation of
11195editing and history expansion features. Users unfamiliar with @sc{gnu} Emacs
11196or @code{vi} may wish to read it.
11197@ifset have-readline-appendices
11198@xref{Command Line Editing}.
11199@end ifset
11200
11201@c @group
11202@kindex show history
11203@item show history
11204@itemx show history filename
11205@itemx show history save
11206@itemx show history size
11207@itemx show history expansion
11208These commands display the state of the @value{GDBN} history parameters.
11209@code{show history} by itself displays all four states.
11210@c @end group
11211@end table
11212
11213@table @code
11214@kindex show commands
11215@item show commands
11216Display the last ten commands in the command history.
11217
11218@item show commands @var{n}
11219Print ten commands centered on command number @var{n}.
11220
11221@item show commands +
11222Print ten commands just after the commands last printed.
11223@end table
11224
53a5351d 11225@node Screen Size
c906108c
SS
11226@section Screen size
11227@cindex size of screen
11228@cindex pauses in output
11229
11230Certain commands to @value{GDBN} may produce large amounts of
11231information output to the screen. To help you read all of it,
11232@value{GDBN} pauses and asks you for input at the end of each page of
11233output. Type @key{RET} when you want to continue the output, or @kbd{q}
11234to discard the remaining output. Also, the screen width setting
11235determines when to wrap lines of output. Depending on what is being
11236printed, @value{GDBN} tries to break the line at a readable place,
11237rather than simply letting it overflow onto the following line.
11238
d4f3574e
SS
11239Normally @value{GDBN} knows the size of the screen from the terminal
11240driver software. For example, on Unix @value{GDBN} uses the termcap data base
c906108c 11241together with the value of the @code{TERM} environment variable and the
d4f3574e 11242@code{stty rows} and @code{stty cols} settings. If this is not correct,
c906108c
SS
11243you can override it with the @code{set height} and @code{set
11244width} commands:
11245
11246@table @code
11247@kindex set height
11248@kindex set width
11249@kindex show width
11250@kindex show height
11251@item set height @var{lpp}
11252@itemx show height
11253@itemx set width @var{cpl}
11254@itemx show width
11255These @code{set} commands specify a screen height of @var{lpp} lines and
11256a screen width of @var{cpl} characters. The associated @code{show}
11257commands display the current settings.
11258
11259If you specify a height of zero lines, @value{GDBN} does not pause during
11260output no matter how long the output is. This is useful if output is to a
11261file or to an editor buffer.
11262
11263Likewise, you can specify @samp{set width 0} to prevent @value{GDBN}
11264from wrapping its output.
11265@end table
11266
53a5351d 11267@node Numbers
c906108c
SS
11268@section Numbers
11269@cindex number representation
11270@cindex entering numbers
11271
2df3850c
JM
11272You can always enter numbers in octal, decimal, or hexadecimal in
11273@value{GDBN} by the usual conventions: octal numbers begin with
11274@samp{0}, decimal numbers end with @samp{.}, and hexadecimal numbers
11275begin with @samp{0x}. Numbers that begin with none of these are, by
11276default, entered in base 10; likewise, the default display for
11277numbers---when no particular format is specified---is base 10. You can
11278change the default base for both input and output with the @code{set
11279radix} command.
c906108c
SS
11280
11281@table @code
11282@kindex set input-radix
11283@item set input-radix @var{base}
11284Set the default base for numeric input. Supported choices
11285for @var{base} are decimal 8, 10, or 16. @var{base} must itself be
11286specified either unambiguously or using the current default radix; for
11287example, any of
11288
11289@smallexample
11290set radix 012
11291set radix 10.
11292set radix 0xa
11293@end smallexample
11294
11295@noindent
11296sets the base to decimal. On the other hand, @samp{set radix 10}
11297leaves the radix unchanged no matter what it was.
11298
11299@kindex set output-radix
11300@item set output-radix @var{base}
11301Set the default base for numeric display. Supported choices
11302for @var{base} are decimal 8, 10, or 16. @var{base} must itself be
11303specified either unambiguously or using the current default radix.
11304
11305@kindex show input-radix
11306@item show input-radix
11307Display the current default base for numeric input.
11308
11309@kindex show output-radix
11310@item show output-radix
11311Display the current default base for numeric display.
11312@end table
11313
53a5351d 11314@node Messages/Warnings
c906108c
SS
11315@section Optional warnings and messages
11316
2df3850c
JM
11317By default, @value{GDBN} is silent about its inner workings. If you are
11318running on a slow machine, you may want to use the @code{set verbose}
11319command. This makes @value{GDBN} tell you when it does a lengthy
11320internal operation, so you will not think it has crashed.
c906108c
SS
11321
11322Currently, the messages controlled by @code{set verbose} are those
11323which announce that the symbol table for a source file is being read;
11324see @code{symbol-file} in @ref{Files, ,Commands to specify files}.
11325
11326@table @code
11327@kindex set verbose
11328@item set verbose on
11329Enables @value{GDBN} output of certain informational messages.
11330
11331@item set verbose off
11332Disables @value{GDBN} output of certain informational messages.
11333
11334@kindex show verbose
11335@item show verbose
11336Displays whether @code{set verbose} is on or off.
11337@end table
11338
2df3850c
JM
11339By default, if @value{GDBN} encounters bugs in the symbol table of an
11340object file, it is silent; but if you are debugging a compiler, you may
11341find this information useful (@pxref{Symbol Errors, ,Errors reading
11342symbol files}).
c906108c
SS
11343
11344@table @code
2df3850c 11345
c906108c
SS
11346@kindex set complaints
11347@item set complaints @var{limit}
2df3850c
JM
11348Permits @value{GDBN} to output @var{limit} complaints about each type of
11349unusual symbols before becoming silent about the problem. Set
11350@var{limit} to zero to suppress all complaints; set it to a large number
11351to prevent complaints from being suppressed.
c906108c
SS
11352
11353@kindex show complaints
11354@item show complaints
11355Displays how many symbol complaints @value{GDBN} is permitted to produce.
2df3850c 11356
c906108c
SS
11357@end table
11358
11359By default, @value{GDBN} is cautious, and asks what sometimes seems to be a
11360lot of stupid questions to confirm certain commands. For example, if
11361you try to run a program which is already running:
11362
11363@example
11364(@value{GDBP}) run
11365The program being debugged has been started already.
11366Start it from the beginning? (y or n)
11367@end example
11368
11369If you are willing to unflinchingly face the consequences of your own
11370commands, you can disable this ``feature'':
11371
11372@table @code
2df3850c 11373
c906108c
SS
11374@kindex set confirm
11375@cindex flinching
11376@cindex confirmation
11377@cindex stupid questions
11378@item set confirm off
11379Disables confirmation requests.
11380
11381@item set confirm on
11382Enables confirmation requests (the default).
11383
11384@kindex show confirm
11385@item show confirm
11386Displays state of confirmation requests.
2df3850c 11387
c906108c
SS
11388@end table
11389
53a5351d 11390@node Sequences
c906108c
SS
11391@chapter Canned Sequences of Commands
11392
11393Aside from breakpoint commands (@pxref{Break Commands, ,Breakpoint
2df3850c
JM
11394command lists}), @value{GDBN} provides two ways to store sequences of
11395commands for execution as a unit: user-defined commands and command
11396files.
c906108c
SS
11397
11398@menu
11399* Define:: User-defined commands
11400* Hooks:: User-defined command hooks
11401* Command Files:: Command files
11402* Output:: Commands for controlled output
11403@end menu
11404
53a5351d 11405@node Define
c906108c
SS
11406@section User-defined commands
11407
11408@cindex user-defined command
2df3850c
JM
11409A @dfn{user-defined command} is a sequence of @value{GDBN} commands to
11410which you assign a new name as a command. This is done with the
11411@code{define} command. User commands may accept up to 10 arguments
11412separated by whitespace. Arguments are accessed within the user command
11413via @var{$arg0@dots{}$arg9}. A trivial example:
c906108c
SS
11414
11415@smallexample
11416define adder
11417 print $arg0 + $arg1 + $arg2
11418@end smallexample
11419
d4f3574e
SS
11420@noindent
11421To execute the command use:
c906108c
SS
11422
11423@smallexample
11424adder 1 2 3
11425@end smallexample
11426
d4f3574e
SS
11427@noindent
11428This defines the command @code{adder}, which prints the sum of
c906108c
SS
11429its three arguments. Note the arguments are text substitutions, so they may
11430reference variables, use complex expressions, or even perform inferior
11431functions calls.
11432
11433@table @code
2df3850c 11434
c906108c
SS
11435@kindex define
11436@item define @var{commandname}
11437Define a command named @var{commandname}. If there is already a command
11438by that name, you are asked to confirm that you want to redefine it.
11439
11440The definition of the command is made up of other @value{GDBN} command lines,
11441which are given following the @code{define} command. The end of these
11442commands is marked by a line containing @code{end}.
11443
11444@kindex if
11445@kindex else
11446@item if
11447Takes a single argument, which is an expression to evaluate.
11448It is followed by a series of commands that are executed
11449only if the expression is true (nonzero).
11450There can then optionally be a line @code{else}, followed
11451by a series of commands that are only executed if the expression
11452was false. The end of the list is marked by a line containing @code{end}.
11453
11454@kindex while
11455@item while
11456The syntax is similar to @code{if}: the command takes a single argument,
11457which is an expression to evaluate, and must be followed by the commands to
11458execute, one per line, terminated by an @code{end}.
11459The commands are executed repeatedly as long as the expression
11460evaluates to true.
11461
11462@kindex document
11463@item document @var{commandname}
11464Document the user-defined command @var{commandname}, so that it can be
11465accessed by @code{help}. The command @var{commandname} must already be
11466defined. This command reads lines of documentation just as @code{define}
11467reads the lines of the command definition, ending with @code{end}.
11468After the @code{document} command is finished, @code{help} on command
11469@var{commandname} displays the documentation you have written.
11470
11471You may use the @code{document} command again to change the
11472documentation of a command. Redefining the command with @code{define}
11473does not change the documentation.
11474
11475@kindex help user-defined
11476@item help user-defined
11477List all user-defined commands, with the first line of the documentation
11478(if any) for each.
11479
11480@kindex show user
11481@item show user
11482@itemx show user @var{commandname}
2df3850c
JM
11483Display the @value{GDBN} commands used to define @var{commandname} (but
11484not its documentation). If no @var{commandname} is given, display the
c906108c 11485definitions for all user-defined commands.
2df3850c 11486
c906108c
SS
11487@end table
11488
11489When user-defined commands are executed, the
11490commands of the definition are not printed. An error in any command
11491stops execution of the user-defined command.
11492
11493If used interactively, commands that would ask for confirmation proceed
11494without asking when used inside a user-defined command. Many @value{GDBN}
11495commands that normally print messages to say what they are doing omit the
11496messages when used in a user-defined command.
11497
53a5351d 11498@node Hooks
c906108c 11499@section User-defined command hooks
d4f3574e
SS
11500@cindex command hooks
11501@cindex hooks, for commands
c906108c
SS
11502
11503You may define @emph{hooks}, which are a special kind of user-defined
11504command. Whenever you run the command @samp{foo}, if the user-defined
11505command @samp{hook-foo} exists, it is executed (with no arguments)
11506before that command.
11507
d4f3574e 11508@kindex stop@r{, a pseudo-command}
c906108c
SS
11509In addition, a pseudo-command, @samp{stop} exists. Defining
11510(@samp{hook-stop}) makes the associated commands execute every time
11511execution stops in your program: before breakpoint commands are run,
11512displays are printed, or the stack frame is printed.
11513
c906108c
SS
11514For example, to ignore @code{SIGALRM} signals while
11515single-stepping, but treat them normally during normal execution,
11516you could define:
11517
11518@example
11519define hook-stop
11520handle SIGALRM nopass
11521end
11522
11523define hook-run
11524handle SIGALRM pass
11525end
11526
11527define hook-continue
11528handle SIGLARM pass
11529end
11530@end example
c906108c
SS
11531
11532You can define a hook for any single-word command in @value{GDBN}, but
11533not for command aliases; you should define a hook for the basic command
11534name, e.g. @code{backtrace} rather than @code{bt}.
11535@c FIXME! So how does Joe User discover whether a command is an alias
11536@c or not?
11537If an error occurs during the execution of your hook, execution of
11538@value{GDBN} commands stops and @value{GDBN} issues a prompt
11539(before the command that you actually typed had a chance to run).
11540
11541If you try to define a hook which does not match any known command, you
11542get a warning from the @code{define} command.
11543
53a5351d 11544@node Command Files
c906108c
SS
11545@section Command files
11546
11547@cindex command files
11548A command file for @value{GDBN} is a file of lines that are @value{GDBN}
11549commands. Comments (lines starting with @kbd{#}) may also be included.
11550An empty line in a command file does nothing; it does not mean to repeat
11551the last command, as it would from the terminal.
11552
11553@cindex init file
11554@cindex @file{.gdbinit}
d4f3574e 11555@cindex @file{gdb.ini}
c906108c
SS
11556When you start @value{GDBN}, it automatically executes commands from its
11557@dfn{init files}. These are files named @file{.gdbinit} on Unix, or
11558@file{gdb.ini} on DOS/Windows. @value{GDBN} reads the init file (if
d4f3574e 11559any) in your home directory@footnote{On DOS/Windows systems, the home
2df3850c
JM
11560directory is the one pointed to by the @code{HOME} environment
11561variable.}, then processes command line options and operands, and then
11562reads the init file (if any) in the current working directory. This is
11563so the init file in your home directory can set options (such as
11564@code{set complaints}) which affect the processing of the command line
11565options and operands. The init files are not executed if you use the
11566@samp{-nx} option; @pxref{Mode Options, ,Choosing modes}.
c906108c 11567
c906108c
SS
11568@cindex init file name
11569On some configurations of @value{GDBN}, the init file is known by a
11570different name (these are typically environments where a specialized
11571form of @value{GDBN} may need to coexist with other forms, hence a
11572different name for the specialized version's init file). These are the
11573environments with special init file names:
11574
11575@kindex .vxgdbinit
11576@itemize @bullet
11577@item
11578VxWorks (Wind River Systems real-time OS): @samp{.vxgdbinit}
11579
11580@kindex .os68gdbinit
11581@item
11582OS68K (Enea Data Systems real-time OS): @samp{.os68gdbinit}
11583
11584@kindex .esgdbinit
11585@item
11586ES-1800 (Ericsson Telecom AB M68000 emulator): @samp{.esgdbinit}
11587@end itemize
c906108c
SS
11588
11589You can also request the execution of a command file with the
11590@code{source} command:
11591
11592@table @code
11593@kindex source
11594@item source @var{filename}
11595Execute the command file @var{filename}.
11596@end table
11597
11598The lines in a command file are executed sequentially. They are not
11599printed as they are executed. An error in any command terminates execution
11600of the command file.
11601
11602Commands that would ask for confirmation if used interactively proceed
11603without asking when used in a command file. Many @value{GDBN} commands that
11604normally print messages to say what they are doing omit the messages
11605when called from command files.
11606
53a5351d 11607@node Output
c906108c
SS
11608@section Commands for controlled output
11609
11610During the execution of a command file or a user-defined command, normal
11611@value{GDBN} output is suppressed; the only output that appears is what is
11612explicitly printed by the commands in the definition. This section
11613describes three commands useful for generating exactly the output you
11614want.
11615
11616@table @code
11617@kindex echo
11618@item echo @var{text}
11619@c I do not consider backslash-space a standard C escape sequence
11620@c because it is not in ANSI.
11621Print @var{text}. Nonprinting characters can be included in
11622@var{text} using C escape sequences, such as @samp{\n} to print a
11623newline. @strong{No newline is printed unless you specify one.}
11624In addition to the standard C escape sequences, a backslash followed
11625by a space stands for a space. This is useful for displaying a
11626string with spaces at the beginning or the end, since leading and
11627trailing spaces are otherwise trimmed from all arguments.
11628To print @samp{@w{ }and foo =@w{ }}, use the command
11629@samp{echo \@w{ }and foo = \@w{ }}.
11630
11631A backslash at the end of @var{text} can be used, as in C, to continue
11632the command onto subsequent lines. For example,
11633
11634@example
11635echo This is some text\n\
11636which is continued\n\
11637onto several lines.\n
11638@end example
11639
11640produces the same output as
11641
11642@example
11643echo This is some text\n
11644echo which is continued\n
11645echo onto several lines.\n
11646@end example
11647
11648@kindex output
11649@item output @var{expression}
11650Print the value of @var{expression} and nothing but that value: no
11651newlines, no @samp{$@var{nn} = }. The value is not entered in the
11652value history either. @xref{Expressions, ,Expressions}, for more information
11653on expressions.
11654
11655@item output/@var{fmt} @var{expression}
11656Print the value of @var{expression} in format @var{fmt}. You can use
11657the same formats as for @code{print}. @xref{Output Formats,,Output
11658formats}, for more information.
11659
11660@kindex printf
11661@item printf @var{string}, @var{expressions}@dots{}
11662Print the values of the @var{expressions} under the control of
11663@var{string}. The @var{expressions} are separated by commas and may be
11664either numbers or pointers. Their values are printed as specified by
11665@var{string}, exactly as if your program were to execute the C
11666subroutine
d4f3574e
SS
11667@c FIXME: the above implies that at least all ANSI C formats are
11668@c supported, but it isn't true: %E and %G don't work (or so it seems).
11669@c Either this is a bug, or the manual should document what formats are
11670@c supported.
c906108c
SS
11671
11672@example
11673printf (@var{string}, @var{expressions}@dots{});
11674@end example
11675
11676For example, you can print two values in hex like this:
11677
11678@smallexample
11679printf "foo, bar-foo = 0x%x, 0x%x\n", foo, bar-foo
11680@end smallexample
11681
11682The only backslash-escape sequences that you can use in the format
11683string are the simple ones that consist of backslash followed by a
11684letter.
11685@end table
11686
53a5351d 11687@node Emacs
c906108c
SS
11688@chapter Using @value{GDBN} under @sc{gnu} Emacs
11689
11690@cindex Emacs
11691@cindex @sc{gnu} Emacs
11692A special interface allows you to use @sc{gnu} Emacs to view (and
11693edit) the source files for the program you are debugging with
11694@value{GDBN}.
11695
11696To use this interface, use the command @kbd{M-x gdb} in Emacs. Give the
11697executable file you want to debug as an argument. This command starts
11698@value{GDBN} as a subprocess of Emacs, with input and output through a newly
11699created Emacs buffer.
53a5351d 11700@c (Do not use the @code{-tui} option to run @value{GDBN} from Emacs.)
c906108c
SS
11701
11702Using @value{GDBN} under Emacs is just like using @value{GDBN} normally except for two
11703things:
11704
11705@itemize @bullet
11706@item
11707All ``terminal'' input and output goes through the Emacs buffer.
11708@end itemize
11709
11710This applies both to @value{GDBN} commands and their output, and to the input
11711and output done by the program you are debugging.
11712
11713This is useful because it means that you can copy the text of previous
11714commands and input them again; you can even use parts of the output
11715in this way.
11716
11717All the facilities of Emacs' Shell mode are available for interacting
11718with your program. In particular, you can send signals the usual
11719way---for example, @kbd{C-c C-c} for an interrupt, @kbd{C-c C-z} for a
11720stop.
11721
11722@itemize @bullet
11723@item
11724@value{GDBN} displays source code through Emacs.
11725@end itemize
11726
11727Each time @value{GDBN} displays a stack frame, Emacs automatically finds the
11728source file for that frame and puts an arrow (@samp{=>}) at the
11729left margin of the current line. Emacs uses a separate buffer for
11730source display, and splits the screen to show both your @value{GDBN} session
11731and the source.
11732
11733Explicit @value{GDBN} @code{list} or search commands still produce output as
11734usual, but you probably have no reason to use them from Emacs.
11735
11736@quotation
11737@emph{Warning:} If the directory where your program resides is not your
11738current directory, it can be easy to confuse Emacs about the location of
11739the source files, in which case the auxiliary display buffer does not
11740appear to show your source. @value{GDBN} can find programs by searching your
11741environment's @code{PATH} variable, so the @value{GDBN} input and output
11742session proceeds normally; but Emacs does not get enough information
11743back from @value{GDBN} to locate the source files in this situation. To
11744avoid this problem, either start @value{GDBN} mode from the directory where
11745your program resides, or specify an absolute file name when prompted for the
11746@kbd{M-x gdb} argument.
11747
11748A similar confusion can result if you use the @value{GDBN} @code{file} command to
11749switch to debugging a program in some other location, from an existing
11750@value{GDBN} buffer in Emacs.
11751@end quotation
11752
11753By default, @kbd{M-x gdb} calls the program called @file{gdb}. If
11754you need to call @value{GDBN} by a different name (for example, if you keep
11755several configurations around, with different names) you can set the
11756Emacs variable @code{gdb-command-name}; for example,
11757
11758@example
11759(setq gdb-command-name "mygdb")
11760@end example
11761
11762@noindent
d4f3574e 11763(preceded by @kbd{M-:} or @kbd{ESC :}, or typed in the @code{*scratch*} buffer, or
c906108c
SS
11764in your @file{.emacs} file) makes Emacs call the program named
11765``@code{mygdb}'' instead.
11766
11767In the @value{GDBN} I/O buffer, you can use these special Emacs commands in
11768addition to the standard Shell mode commands:
11769
11770@table @kbd
11771@item C-h m
11772Describe the features of Emacs' @value{GDBN} Mode.
11773
11774@item M-s
11775Execute to another source line, like the @value{GDBN} @code{step} command; also
11776update the display window to show the current file and location.
11777
11778@item M-n
11779Execute to next source line in this function, skipping all function
11780calls, like the @value{GDBN} @code{next} command. Then update the display window
11781to show the current file and location.
11782
11783@item M-i
11784Execute one instruction, like the @value{GDBN} @code{stepi} command; update
11785display window accordingly.
11786
11787@item M-x gdb-nexti
11788Execute to next instruction, using the @value{GDBN} @code{nexti} command; update
11789display window accordingly.
11790
11791@item C-c C-f
11792Execute until exit from the selected stack frame, like the @value{GDBN}
11793@code{finish} command.
11794
11795@item M-c
11796Continue execution of your program, like the @value{GDBN} @code{continue}
11797command.
11798
11799@emph{Warning:} In Emacs v19, this command is @kbd{C-c C-p}.
11800
11801@item M-u
11802Go up the number of frames indicated by the numeric argument
11803(@pxref{Arguments, , Numeric Arguments, Emacs, The @sc{gnu} Emacs Manual}),
11804like the @value{GDBN} @code{up} command.
11805
11806@emph{Warning:} In Emacs v19, this command is @kbd{C-c C-u}.
11807
11808@item M-d
11809Go down the number of frames indicated by the numeric argument, like the
11810@value{GDBN} @code{down} command.
11811
11812@emph{Warning:} In Emacs v19, this command is @kbd{C-c C-d}.
11813
11814@item C-x &
11815Read the number where the cursor is positioned, and insert it at the end
11816of the @value{GDBN} I/O buffer. For example, if you wish to disassemble code
11817around an address that was displayed earlier, type @kbd{disassemble};
11818then move the cursor to the address display, and pick up the
11819argument for @code{disassemble} by typing @kbd{C-x &}.
11820
11821You can customize this further by defining elements of the list
11822@code{gdb-print-command}; once it is defined, you can format or
11823otherwise process numbers picked up by @kbd{C-x &} before they are
11824inserted. A numeric argument to @kbd{C-x &} indicates that you
11825wish special formatting, and also acts as an index to pick an element of the
11826list. If the list element is a string, the number to be inserted is
11827formatted using the Emacs function @code{format}; otherwise the number
11828is passed as an argument to the corresponding list element.
11829@end table
11830
11831In any source file, the Emacs command @kbd{C-x SPC} (@code{gdb-break})
11832tells @value{GDBN} to set a breakpoint on the source line point is on.
11833
11834If you accidentally delete the source-display buffer, an easy way to get
11835it back is to type the command @code{f} in the @value{GDBN} buffer, to
11836request a frame display; when you run under Emacs, this recreates
11837the source buffer if necessary to show you the context of the current
11838frame.
11839
11840The source files displayed in Emacs are in ordinary Emacs buffers
11841which are visiting the source files in the usual way. You can edit
11842the files with these buffers if you wish; but keep in mind that @value{GDBN}
11843communicates with Emacs in terms of line numbers. If you add or
11844delete lines from the text, the line numbers that @value{GDBN} knows cease
11845to correspond properly with the code.
11846
11847@c The following dropped because Epoch is nonstandard. Reactivate
11848@c if/when v19 does something similar. ---doc@cygnus.com 19dec1990
11849@ignore
11850@kindex Emacs Epoch environment
11851@kindex Epoch
11852@kindex inspect
11853
11854Version 18 of @sc{gnu} Emacs has a built-in window system
11855called the @code{epoch}
11856environment. Users of this environment can use a new command,
11857@code{inspect} which performs identically to @code{print} except that
11858each value is printed in its own window.
11859@end ignore
c906108c
SS
11860
11861@node GDB Bugs
c906108c
SS
11862@chapter Reporting Bugs in @value{GDBN}
11863@cindex bugs in @value{GDBN}
11864@cindex reporting bugs in @value{GDBN}
11865
11866Your bug reports play an essential role in making @value{GDBN} reliable.
11867
11868Reporting a bug may help you by bringing a solution to your problem, or it
11869may not. But in any case the principal function of a bug report is to help
11870the entire community by making the next version of @value{GDBN} work better. Bug
11871reports are your contribution to the maintenance of @value{GDBN}.
11872
11873In order for a bug report to serve its purpose, you must include the
11874information that enables us to fix the bug.
11875
11876@menu
11877* Bug Criteria:: Have you found a bug?
11878* Bug Reporting:: How to report bugs
11879@end menu
11880
53a5351d 11881@node Bug Criteria
c906108c
SS
11882@section Have you found a bug?
11883@cindex bug criteria
11884
11885If you are not sure whether you have found a bug, here are some guidelines:
11886
11887@itemize @bullet
11888@cindex fatal signal
11889@cindex debugger crash
11890@cindex crash of debugger
11891@item
11892If the debugger gets a fatal signal, for any input whatever, that is a
11893@value{GDBN} bug. Reliable debuggers never crash.
11894
11895@cindex error on valid input
11896@item
11897If @value{GDBN} produces an error message for valid input, that is a
11898bug. (Note that if you're cross debugging, the problem may also be
11899somewhere in the connection to the target.)
11900
11901@cindex invalid input
11902@item
11903If @value{GDBN} does not produce an error message for invalid input,
11904that is a bug. However, you should note that your idea of
11905``invalid input'' might be our idea of ``an extension'' or ``support
11906for traditional practice''.
11907
11908@item
11909If you are an experienced user of debugging tools, your suggestions
11910for improvement of @value{GDBN} are welcome in any case.
11911@end itemize
11912
53a5351d 11913@node Bug Reporting
c906108c
SS
11914@section How to report bugs
11915@cindex bug reports
11916@cindex @value{GDBN} bugs, reporting
11917
c906108c
SS
11918A number of companies and individuals offer support for @sc{gnu} products.
11919If you obtained @value{GDBN} from a support organization, we recommend you
11920contact that organization first.
11921
11922You can find contact information for many support companies and
11923individuals in the file @file{etc/SERVICE} in the @sc{gnu} Emacs
11924distribution.
11925@c should add a web page ref...
11926
11927In any event, we also recommend that you send bug reports for
11928@value{GDBN} to this addresses:
11929
11930@example
d4f3574e 11931bug-gdb@@gnu.org
c906108c
SS
11932@end example
11933
11934@strong{Do not send bug reports to @samp{info-gdb}, or to
d4f3574e 11935@samp{help-gdb}, or to any newsgroups.} Most users of @value{GDBN} do
c906108c
SS
11936not want to receive bug reports. Those that do have arranged to receive
11937@samp{bug-gdb}.
11938
11939The mailing list @samp{bug-gdb} has a newsgroup @samp{gnu.gdb.bug} which
11940serves as a repeater. The mailing list and the newsgroup carry exactly
11941the same messages. Often people think of posting bug reports to the
11942newsgroup instead of mailing them. This appears to work, but it has one
11943problem which can be crucial: a newsgroup posting often lacks a mail
11944path back to the sender. Thus, if we need to ask for more information,
11945we may be unable to reach you. For this reason, it is better to send
11946bug reports to the mailing list.
11947
11948As a last resort, send bug reports on paper to:
11949
11950@example
11951@sc{gnu} Debugger Bugs
11952Free Software Foundation Inc.
1195359 Temple Place - Suite 330
11954Boston, MA 02111-1307
11955USA
11956@end example
c906108c
SS
11957
11958The fundamental principle of reporting bugs usefully is this:
11959@strong{report all the facts}. If you are not sure whether to state a
11960fact or leave it out, state it!
11961
11962Often people omit facts because they think they know what causes the
11963problem and assume that some details do not matter. Thus, you might
11964assume that the name of the variable you use in an example does not matter.
11965Well, probably it does not, but one cannot be sure. Perhaps the bug is a
11966stray memory reference which happens to fetch from the location where that
11967name is stored in memory; perhaps, if the name were different, the contents
11968of that location would fool the debugger into doing the right thing despite
11969the bug. Play it safe and give a specific, complete example. That is the
11970easiest thing for you to do, and the most helpful.
11971
11972Keep in mind that the purpose of a bug report is to enable us to fix the
11973bug. It may be that the bug has been reported previously, but neither
11974you nor we can know that unless your bug report is complete and
11975self-contained.
11976
11977Sometimes people give a few sketchy facts and ask, ``Does this ring a
11978bell?'' Those bug reports are useless, and we urge everyone to
11979@emph{refuse to respond to them} except to chide the sender to report
11980bugs properly.
11981
11982To enable us to fix the bug, you should include all these things:
11983
11984@itemize @bullet
11985@item
11986The version of @value{GDBN}. @value{GDBN} announces it if you start
11987with no arguments; you can also print it at any time using @code{show
11988version}.
11989
11990Without this, we will not know whether there is any point in looking for
11991the bug in the current version of @value{GDBN}.
11992
11993@item
11994The type of machine you are using, and the operating system name and
11995version number.
11996
c906108c
SS
11997@item
11998What compiler (and its version) was used to compile @value{GDBN}---e.g.
11999``@value{GCC}--2.8.1''.
c906108c
SS
12000
12001@item
12002What compiler (and its version) was used to compile the program you are
12003debugging---e.g. ``@value{GCC}--2.8.1'', or ``HP92453-01 A.10.32.03 HP
12004C Compiler''. For GCC, you can say @code{gcc --version} to get this
12005information; for other compilers, see the documentation for those
12006compilers.
12007
12008@item
12009The command arguments you gave the compiler to compile your example and
12010observe the bug. For example, did you use @samp{-O}? To guarantee
12011you will not omit something important, list them all. A copy of the
12012Makefile (or the output from make) is sufficient.
12013
12014If we were to try to guess the arguments, we would probably guess wrong
12015and then we might not encounter the bug.
12016
12017@item
12018A complete input script, and all necessary source files, that will
12019reproduce the bug.
12020
12021@item
12022A description of what behavior you observe that you believe is
12023incorrect. For example, ``It gets a fatal signal.''
12024
12025Of course, if the bug is that @value{GDBN} gets a fatal signal, then we
12026will certainly notice it. But if the bug is incorrect output, we might
12027not notice unless it is glaringly wrong. You might as well not give us
12028a chance to make a mistake.
12029
12030Even if the problem you experience is a fatal signal, you should still
12031say so explicitly. Suppose something strange is going on, such as, your
12032copy of @value{GDBN} is out of synch, or you have encountered a bug in
12033the C library on your system. (This has happened!) Your copy might
12034crash and ours would not. If you told us to expect a crash, then when
12035ours fails to crash, we would know that the bug was not happening for
12036us. If you had not told us to expect a crash, then we would not be able
12037to draw any conclusion from our observations.
12038
c906108c
SS
12039@item
12040If you wish to suggest changes to the @value{GDBN} source, send us context
12041diffs. If you even discuss something in the @value{GDBN} source, refer to
12042it by context, not by line number.
12043
12044The line numbers in our development sources will not match those in your
12045sources. Your line numbers would convey no useful information to us.
53a5351d 12046
c906108c
SS
12047@end itemize
12048
12049Here are some things that are not necessary:
12050
12051@itemize @bullet
12052@item
12053A description of the envelope of the bug.
12054
12055Often people who encounter a bug spend a lot of time investigating
12056which changes to the input file will make the bug go away and which
12057changes will not affect it.
12058
12059This is often time consuming and not very useful, because the way we
12060will find the bug is by running a single example under the debugger
12061with breakpoints, not by pure deduction from a series of examples.
12062We recommend that you save your time for something else.
12063
12064Of course, if you can find a simpler example to report @emph{instead}
12065of the original one, that is a convenience for us. Errors in the
12066output will be easier to spot, running under the debugger will take
12067less time, and so on.
12068
12069However, simplification is not vital; if you do not want to do this,
12070report the bug anyway and send us the entire test case you used.
12071
12072@item
12073A patch for the bug.
12074
12075A patch for the bug does help us if it is a good one. But do not omit
12076the necessary information, such as the test case, on the assumption that
12077a patch is all we need. We might see problems with your patch and decide
12078to fix the problem another way, or we might not understand it at all.
12079
12080Sometimes with a program as complicated as @value{GDBN} it is very hard to
12081construct an example that will make the program follow a certain path
12082through the code. If you do not send us the example, we will not be able
12083to construct one, so we will not be able to verify that the bug is fixed.
12084
12085And if we cannot understand what bug you are trying to fix, or why your
12086patch should be an improvement, we will not install it. A test case will
12087help us to understand.
12088
12089@item
12090A guess about what the bug is or what it depends on.
12091
12092Such guesses are usually wrong. Even we cannot guess right about such
12093things without first using the debugger to find the facts.
12094@end itemize
12095
12096@c The readline documentation is distributed with the readline code
12097@c and consists of the two following files:
12098@c rluser.texinfo
7be570e7 12099@c inc-hist.texinfo
c906108c
SS
12100@c Use -I with makeinfo to point to the appropriate directory,
12101@c environment var TEXINPUTS with TeX.
12102@include rluser.texinfo
7be570e7 12103@include inc-hist.texinfo
c906108c
SS
12104
12105
c906108c 12106@node Formatting Documentation
c906108c
SS
12107@appendix Formatting Documentation
12108
12109@cindex @value{GDBN} reference card
12110@cindex reference card
12111The @value{GDBN} 4 release includes an already-formatted reference card, ready
12112for printing with PostScript or Ghostscript, in the @file{gdb}
12113subdirectory of the main source directory@footnote{In
12114@file{gdb-@value{GDBVN}/gdb/refcard.ps} of the version @value{GDBVN}
12115release.}. If you can use PostScript or Ghostscript with your printer,
12116you can print the reference card immediately with @file{refcard.ps}.
12117
12118The release also includes the source for the reference card. You
12119can format it, using @TeX{}, by typing:
12120
12121@example
12122make refcard.dvi
12123@end example
12124
12125The @value{GDBN} reference card is designed to print in @dfn{landscape}
12126mode on US ``letter'' size paper;
12127that is, on a sheet 11 inches wide by 8.5 inches
12128high. You will need to specify this form of printing as an option to
12129your @sc{dvi} output program.
12130
12131@cindex documentation
12132
12133All the documentation for @value{GDBN} comes as part of the machine-readable
12134distribution. The documentation is written in Texinfo format, which is
12135a documentation system that uses a single source file to produce both
12136on-line information and a printed manual. You can use one of the Info
12137formatting commands to create the on-line version of the documentation
12138and @TeX{} (or @code{texi2roff}) to typeset the printed version.
12139
12140@value{GDBN} includes an already formatted copy of the on-line Info
12141version of this manual in the @file{gdb} subdirectory. The main Info
12142file is @file{gdb-@value{GDBVN}/gdb/gdb.info}, and it refers to
12143subordinate files matching @samp{gdb.info*} in the same directory. If
12144necessary, you can print out these files, or read them with any editor;
12145but they are easier to read using the @code{info} subsystem in @sc{gnu}
12146Emacs or the standalone @code{info} program, available as part of the
12147@sc{gnu} Texinfo distribution.
12148
12149If you want to format these Info files yourself, you need one of the
12150Info formatting programs, such as @code{texinfo-format-buffer} or
12151@code{makeinfo}.
12152
12153If you have @code{makeinfo} installed, and are in the top level
12154@value{GDBN} source directory (@file{gdb-@value{GDBVN}}, in the case of
12155version @value{GDBVN}), you can make the Info file by typing:
12156
12157@example
12158cd gdb
12159make gdb.info
12160@end example
12161
12162If you want to typeset and print copies of this manual, you need @TeX{},
12163a program to print its @sc{dvi} output files, and @file{texinfo.tex}, the
12164Texinfo definitions file.
12165
12166@TeX{} is a typesetting program; it does not print files directly, but
12167produces output files called @sc{dvi} files. To print a typeset
12168document, you need a program to print @sc{dvi} files. If your system
12169has @TeX{} installed, chances are it has such a program. The precise
12170command to use depends on your system; @kbd{lpr -d} is common; another
12171(for PostScript devices) is @kbd{dvips}. The @sc{dvi} print command may
12172require a file name without any extension or a @samp{.dvi} extension.
12173
12174@TeX{} also requires a macro definitions file called
12175@file{texinfo.tex}. This file tells @TeX{} how to typeset a document
12176written in Texinfo format. On its own, @TeX{} cannot either read or
12177typeset a Texinfo file. @file{texinfo.tex} is distributed with GDB
12178and is located in the @file{gdb-@var{version-number}/texinfo}
12179directory.
12180
12181If you have @TeX{} and a @sc{dvi} printer program installed, you can
12182typeset and print this manual. First switch to the the @file{gdb}
12183subdirectory of the main source directory (for example, to
12184@file{gdb-@value{GDBVN}/gdb}) and type:
12185
12186@example
12187make gdb.dvi
12188@end example
12189
12190Then give @file{gdb.dvi} to your @sc{dvi} printing program.
c906108c 12191
53a5351d 12192@node Installing GDB
c906108c
SS
12193@appendix Installing @value{GDBN}
12194@cindex configuring @value{GDBN}
12195@cindex installation
12196
c906108c
SS
12197@value{GDBN} comes with a @code{configure} script that automates the process
12198of preparing @value{GDBN} for installation; you can then use @code{make} to
12199build the @code{gdb} program.
12200@iftex
12201@c irrelevant in info file; it's as current as the code it lives with.
12202@footnote{If you have a more recent version of @value{GDBN} than @value{GDBVN},
12203look at the @file{README} file in the sources; we may have improved the
12204installation procedures since publishing this manual.}
12205@end iftex
12206
12207The @value{GDBN} distribution includes all the source code you need for
12208@value{GDBN} in a single directory, whose name is usually composed by
12209appending the version number to @samp{gdb}.
12210
12211For example, the @value{GDBN} version @value{GDBVN} distribution is in the
12212@file{gdb-@value{GDBVN}} directory. That directory contains:
12213
12214@table @code
12215@item gdb-@value{GDBVN}/configure @r{(and supporting files)}
12216script for configuring @value{GDBN} and all its supporting libraries
12217
12218@item gdb-@value{GDBVN}/gdb
12219the source specific to @value{GDBN} itself
12220
12221@item gdb-@value{GDBVN}/bfd
12222source for the Binary File Descriptor library
12223
12224@item gdb-@value{GDBVN}/include
12225@sc{gnu} include files
12226
12227@item gdb-@value{GDBVN}/libiberty
12228source for the @samp{-liberty} free software library
12229
12230@item gdb-@value{GDBVN}/opcodes
12231source for the library of opcode tables and disassemblers
12232
12233@item gdb-@value{GDBVN}/readline
12234source for the @sc{gnu} command-line interface
12235
12236@item gdb-@value{GDBVN}/glob
12237source for the @sc{gnu} filename pattern-matching subroutine
12238
12239@item gdb-@value{GDBVN}/mmalloc
12240source for the @sc{gnu} memory-mapped malloc package
12241@end table
12242
12243The simplest way to configure and build @value{GDBN} is to run @code{configure}
12244from the @file{gdb-@var{version-number}} source directory, which in
12245this example is the @file{gdb-@value{GDBVN}} directory.
12246
12247First switch to the @file{gdb-@var{version-number}} source directory
12248if you are not already in it; then run @code{configure}. Pass the
12249identifier for the platform on which @value{GDBN} will run as an
12250argument.
12251
12252For example:
12253
12254@example
12255cd gdb-@value{GDBVN}
12256./configure @var{host}
12257make
12258@end example
12259
12260@noindent
12261where @var{host} is an identifier such as @samp{sun4} or
12262@samp{decstation}, that identifies the platform where @value{GDBN} will run.
12263(You can often leave off @var{host}; @code{configure} tries to guess the
12264correct value by examining your system.)
12265
12266Running @samp{configure @var{host}} and then running @code{make} builds the
12267@file{bfd}, @file{readline}, @file{mmalloc}, and @file{libiberty}
12268libraries, then @code{gdb} itself. The configured source files, and the
12269binaries, are left in the corresponding source directories.
12270
12271@need 750
12272@code{configure} is a Bourne-shell (@code{/bin/sh}) script; if your
12273system does not recognize this automatically when you run a different
12274shell, you may need to run @code{sh} on it explicitly:
12275
12276@example
12277sh configure @var{host}
12278@end example
12279
12280If you run @code{configure} from a directory that contains source
12281directories for multiple libraries or programs, such as the
12282@file{gdb-@value{GDBVN}} source directory for version @value{GDBVN}, @code{configure}
12283creates configuration files for every directory level underneath (unless
12284you tell it not to, with the @samp{--norecursion} option).
12285
12286You can run the @code{configure} script from any of the
12287subordinate directories in the @value{GDBN} distribution if you only want to
12288configure that subdirectory, but be sure to specify a path to it.
12289
12290For example, with version @value{GDBVN}, type the following to configure only
12291the @code{bfd} subdirectory:
12292
12293@example
12294@group
12295cd gdb-@value{GDBVN}/bfd
12296../configure @var{host}
12297@end group
12298@end example
12299
12300You can install @code{@value{GDBP}} anywhere; it has no hardwired paths.
12301However, you should make sure that the shell on your path (named by
12302the @samp{SHELL} environment variable) is publicly readable. Remember
12303that @value{GDBN} uses the shell to start your program---some systems refuse to
12304let @value{GDBN} debug child processes whose programs are not readable.
12305
12306@menu
12307* Separate Objdir:: Compiling @value{GDBN} in another directory
12308* Config Names:: Specifying names for hosts and targets
12309* Configure Options:: Summary of options for configure
12310@end menu
12311
53a5351d 12312@node Separate Objdir
c906108c
SS
12313@section Compiling @value{GDBN} in another directory
12314
12315If you want to run @value{GDBN} versions for several host or target machines,
12316you need a different @code{gdb} compiled for each combination of
12317host and target. @code{configure} is designed to make this easy by
12318allowing you to generate each configuration in a separate subdirectory,
12319rather than in the source directory. If your @code{make} program
12320handles the @samp{VPATH} feature (@sc{gnu} @code{make} does), running
12321@code{make} in each of these directories builds the @code{gdb}
12322program specified there.
12323
12324To build @code{gdb} in a separate directory, run @code{configure}
12325with the @samp{--srcdir} option to specify where to find the source.
12326(You also need to specify a path to find @code{configure}
12327itself from your working directory. If the path to @code{configure}
12328would be the same as the argument to @samp{--srcdir}, you can leave out
12329the @samp{--srcdir} option; it is assumed.)
12330
12331For example, with version @value{GDBVN}, you can build @value{GDBN} in a
12332separate directory for a Sun 4 like this:
12333
12334@example
12335@group
12336cd gdb-@value{GDBVN}
12337mkdir ../gdb-sun4
12338cd ../gdb-sun4
12339../gdb-@value{GDBVN}/configure sun4
12340make
12341@end group
12342@end example
12343
12344When @code{configure} builds a configuration using a remote source
12345directory, it creates a tree for the binaries with the same structure
12346(and using the same names) as the tree under the source directory. In
12347the example, you'd find the Sun 4 library @file{libiberty.a} in the
12348directory @file{gdb-sun4/libiberty}, and @value{GDBN} itself in
12349@file{gdb-sun4/gdb}.
12350
12351One popular reason to build several @value{GDBN} configurations in separate
12352directories is to configure @value{GDBN} for cross-compiling (where
12353@value{GDBN} runs on one machine---the @dfn{host}---while debugging
12354programs that run on another machine---the @dfn{target}).
12355You specify a cross-debugging target by
12356giving the @samp{--target=@var{target}} option to @code{configure}.
12357
12358When you run @code{make} to build a program or library, you must run
12359it in a configured directory---whatever directory you were in when you
12360called @code{configure} (or one of its subdirectories).
12361
12362The @code{Makefile} that @code{configure} generates in each source
12363directory also runs recursively. If you type @code{make} in a source
12364directory such as @file{gdb-@value{GDBVN}} (or in a separate configured
12365directory configured with @samp{--srcdir=@var{dirname}/gdb-@value{GDBVN}}), you
12366will build all the required libraries, and then build GDB.
12367
12368When you have multiple hosts or targets configured in separate
12369directories, you can run @code{make} on them in parallel (for example,
12370if they are NFS-mounted on each of the hosts); they will not interfere
12371with each other.
12372
53a5351d 12373@node Config Names
c906108c
SS
12374@section Specifying names for hosts and targets
12375
12376The specifications used for hosts and targets in the @code{configure}
12377script are based on a three-part naming scheme, but some short predefined
12378aliases are also supported. The full naming scheme encodes three pieces
12379of information in the following pattern:
12380
12381@example
12382@var{architecture}-@var{vendor}-@var{os}
12383@end example
12384
12385For example, you can use the alias @code{sun4} as a @var{host} argument,
12386or as the value for @var{target} in a @code{--target=@var{target}}
12387option. The equivalent full name is @samp{sparc-sun-sunos4}.
12388
12389The @code{configure} script accompanying @value{GDBN} does not provide
12390any query facility to list all supported host and target names or
12391aliases. @code{configure} calls the Bourne shell script
12392@code{config.sub} to map abbreviations to full names; you can read the
12393script, if you wish, or you can use it to test your guesses on
12394abbreviations---for example:
12395
12396@smallexample
12397% sh config.sub i386-linux
12398i386-pc-linux-gnu
12399% sh config.sub alpha-linux
12400alpha-unknown-linux-gnu
12401% sh config.sub hp9k700
12402hppa1.1-hp-hpux
12403% sh config.sub sun4
12404sparc-sun-sunos4.1.1
12405% sh config.sub sun3
12406m68k-sun-sunos4.1.1
12407% sh config.sub i986v
12408Invalid configuration `i986v': machine `i986v' not recognized
12409@end smallexample
12410
12411@noindent
12412@code{config.sub} is also distributed in the @value{GDBN} source
12413directory (@file{gdb-@value{GDBVN}}, for version @value{GDBVN}).
12414
53a5351d 12415@node Configure Options
c906108c
SS
12416@section @code{configure} options
12417
12418Here is a summary of the @code{configure} options and arguments that
12419are most often useful for building @value{GDBN}. @code{configure} also has
12420several other options not listed here. @inforef{What Configure
12421Does,,configure.info}, for a full explanation of @code{configure}.
12422
12423@example
12424configure @r{[}--help@r{]}
12425 @r{[}--prefix=@var{dir}@r{]}
12426 @r{[}--exec-prefix=@var{dir}@r{]}
12427 @r{[}--srcdir=@var{dirname}@r{]}
12428 @r{[}--norecursion@r{]} @r{[}--rm@r{]}
12429 @r{[}--target=@var{target}@r{]}
12430 @var{host}
12431@end example
12432
12433@noindent
12434You may introduce options with a single @samp{-} rather than
12435@samp{--} if you prefer; but you may abbreviate option names if you use
12436@samp{--}.
12437
12438@table @code
12439@item --help
12440Display a quick summary of how to invoke @code{configure}.
12441
12442@item --prefix=@var{dir}
12443Configure the source to install programs and files under directory
12444@file{@var{dir}}.
12445
12446@item --exec-prefix=@var{dir}
12447Configure the source to install programs under directory
12448@file{@var{dir}}.
12449
12450@c avoid splitting the warning from the explanation:
12451@need 2000
12452@item --srcdir=@var{dirname}
12453@strong{Warning: using this option requires @sc{gnu} @code{make}, or another
12454@code{make} that implements the @code{VPATH} feature.}@*
12455Use this option to make configurations in directories separate from the
12456@value{GDBN} source directories. Among other things, you can use this to
12457build (or maintain) several configurations simultaneously, in separate
12458directories. @code{configure} writes configuration specific files in
12459the current directory, but arranges for them to use the source in the
12460directory @var{dirname}. @code{configure} creates directories under
12461the working directory in parallel to the source directories below
12462@var{dirname}.
12463
12464@item --norecursion
12465Configure only the directory level where @code{configure} is executed; do not
12466propagate configuration to subdirectories.
12467
12468@item --target=@var{target}
12469Configure @value{GDBN} for cross-debugging programs running on the specified
12470@var{target}. Without this option, @value{GDBN} is configured to debug
12471programs that run on the same machine (@var{host}) as @value{GDBN} itself.
12472
12473There is no convenient way to generate a list of all available targets.
12474
12475@item @var{host} @dots{}
12476Configure @value{GDBN} to run on the specified @var{host}.
12477
12478There is no convenient way to generate a list of all available hosts.
12479@end table
12480
12481There are many other options available as well, but they are generally
12482needed for special purposes only.
c906108c 12483
53a5351d 12484@node Index
c906108c
SS
12485@unnumbered Index
12486
12487@printindex cp
12488
12489@tex
12490% I think something like @colophon should be in texinfo. In the
12491% meantime:
12492\long\def\colophon{\hbox to0pt{}\vfill
12493\centerline{The body of this manual is set in}
12494\centerline{\fontname\tenrm,}
12495\centerline{with headings in {\bf\fontname\tenbf}}
12496\centerline{and examples in {\tt\fontname\tentt}.}
12497\centerline{{\it\fontname\tenit\/},}
12498\centerline{{\bf\fontname\tenbf}, and}
12499\centerline{{\sl\fontname\tensl\/}}
12500\centerline{are used for emphasis.}\vfill}
12501\page\colophon
12502% Blame: doc@cygnus.com, 1991.
12503@end tex
12504
12505@contents
12506@bye