* Makefile.in (GDBMI_DIR): New variable.
[deliverable/binutils-gdb.git] / gdb / doc / gdb.texinfo
CommitLineData
c906108c 1\input texinfo @c -*-texinfo-*-
6d2ebf8b 2@c Copyright 1988-2000
c906108c
SS
3@c Free Software Foundation, Inc.
4@c
5d161b24 5@c %**start of header
c906108c
SS
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
7162c0ca
EZ
27@c gdbmi uses @findex
28@syncodeindex fn cp
29
c906108c 30@c !!set GDB manual's edition---not the same as GDB version!
6d2ebf8b 31@set EDITION Eighth
c906108c
SS
32
33@c !!set GDB manual's revision date
6d2ebf8b 34@set DATE March 2000
c906108c 35
6d2ebf8b 36@c THIS MANUAL REQUIRES TEXINFO 3.12 OR LATER.
c906108c 37
c906108c 38@c This is a dir.info fragment to support semi-automated addition of
6d2ebf8b 39@c manuals to an info tree.
96a2c332
SS
40@dircategory Programming & development tools.
41@direntry
c906108c 42* Gdb: (gdb). The @sc{gnu} debugger.
96a2c332
SS
43@end direntry
44
c906108c
SS
45@ifinfo
46This file documents the @sc{gnu} debugger @value{GDBN}.
47
48
5d161b24 49This is the @value{EDITION} Edition, @value{DATE},
c906108c
SS
50of @cite{Debugging with @value{GDBN}: the @sc{gnu} Source-Level Debugger}
51for @value{GDBN} Version @value{GDBVN}.
52
6d2ebf8b 53Copyright (C) 1988-2000 Free Software Foundation, Inc.
c906108c
SS
54
55Permission is granted to make and distribute verbatim copies of
56this manual provided the copyright notice and this permission notice
57are preserved on all copies.
58
59@ignore
60Permission is granted to process this file through TeX and print the
61results, provided the printed document carries copying permission
62notice identical to this one except for the removal of this paragraph
63(this paragraph not being relevant to the printed manual).
64
65@end ignore
66Permission is granted to copy and distribute modified versions of this
67manual under the conditions for verbatim copying, provided also that the
68entire resulting derived work is distributed under the terms of a
69permission notice identical to this one.
70
71Permission is granted to copy and distribute translations of this manual
72into another language, under the above conditions for modified versions.
73@end ifinfo
74
75@titlepage
76@title Debugging with @value{GDBN}
77@subtitle The @sc{gnu} Source-Level Debugger
c906108c 78@sp 1
c906108c
SS
79@subtitle @value{EDITION} Edition, for @value{GDBN} version @value{GDBVN}
80@subtitle @value{DATE}
81@author Richard M. Stallman and Roland H. Pesch
c906108c 82@page
c906108c
SS
83@tex
84{\parskip=0pt
53a5351d 85\hfill (Send bugs and comments on @value{GDBN} to bug-gdb\@gnu.org.)\par
c906108c
SS
86\hfill {\it Debugging with @value{GDBN}}\par
87\hfill \TeX{}info \texinfoversion\par
88}
89@end tex
53a5351d 90
c906108c 91@vskip 0pt plus 1filll
6d2ebf8b 92Copyright @copyright{} 1988-2000 Free Software Foundation, Inc.
c906108c 93@sp 2
c906108c
SS
94Published by the Free Software Foundation @*
9559 Temple Place - Suite 330, @*
96Boston, MA 02111-1307 USA @*
6d2ebf8b
SS
97ISBN 1-882114-77-9 @*
98
c906108c
SS
99Permission is granted to make and distribute verbatim copies of
100this manual provided the copyright notice and this permission notice
101are preserved on all copies.
102
103Permission is granted to copy and distribute modified versions of this
104manual under the conditions for verbatim copying, provided also that the
105entire resulting derived work is distributed under the terms of a
106permission notice identical to this one.
107
108Permission is granted to copy and distribute translations of this manual
109into another language, under the above conditions for modified versions.
110@end titlepage
111@page
112
b9deaee7 113@ifinfo
6d2ebf8b
SS
114@node Top, Summary, (dir), (dir)
115
c906108c
SS
116@top Debugging with @value{GDBN}
117
118This file describes @value{GDBN}, the @sc{gnu} symbolic debugger.
119
5d161b24 120This is the @value{EDITION} Edition, @value{DATE}, for @value{GDBN} Version
c906108c
SS
121@value{GDBVN}.
122
6d2ebf8b
SS
123Copyright (C) 1988-2000 Free Software Foundation, Inc.
124
125@menu
126* Summary:: Summary of @value{GDBN}
127* Sample Session:: A sample @value{GDBN} session
128
129* Invocation:: Getting in and out of @value{GDBN}
130* Commands:: @value{GDBN} commands
131* Running:: Running programs under @value{GDBN}
132* Stopping:: Stopping and continuing
133* Stack:: Examining the stack
134* Source:: Examining source files
135* Data:: Examining data
136
137* Languages:: Using @value{GDBN} with different languages
138
139* Symbols:: Examining the symbol table
140* Altering:: Altering execution
141* GDB Files:: @value{GDBN} files
142* Targets:: Specifying a debugging target
143* Configurations:: Configuration-specific information
144* Controlling GDB:: Controlling @value{GDBN}
145* Sequences:: Canned sequences of commands
146* Emacs:: Using @value{GDBN} under @sc{gnu} Emacs
147* Annotations:: @value{GDBN}'s annotation interface.
7162c0ca 148* GDB/MI:: @value{GDBN}'s Machine Interface.
6d2ebf8b
SS
149
150* GDB Bugs:: Reporting bugs in @value{GDBN}
151* Formatting Documentation:: How to format and print @value{GDBN} documentation
152
153* Command Line Editing:: Command Line Editing
154* Using History Interactively:: Using History Interactively
155* Installing GDB:: Installing GDB
156* Index:: Index
157@end menu
158
b9deaee7 159@end ifinfo
6d2ebf8b
SS
160
161@c the replication sucks, but this avoids a texinfo 3.12 lameness
162
163@ifhtml
164@node Top
165
166@top Debugging with @value{GDBN}
167
168This file describes @value{GDBN}, the @sc{gnu} symbolic debugger.
169
170This is the @value{EDITION} Edition, @value{DATE}, for @value{GDBN} Version
171@value{GDBVN}.
172
173Copyright (C) 1988-2000 Free Software Foundation, Inc.
174
c906108c
SS
175@menu
176* Summary:: Summary of @value{GDBN}
c906108c 177* Sample Session:: A sample @value{GDBN} session
c906108c
SS
178
179* Invocation:: Getting in and out of @value{GDBN}
180* Commands:: @value{GDBN} commands
181* Running:: Running programs under @value{GDBN}
182* Stopping:: Stopping and continuing
183* Stack:: Examining the stack
184* Source:: Examining source files
185* Data:: Examining data
c906108c 186
7a292a7a 187* Languages:: Using @value{GDBN} with different languages
c906108c
SS
188
189* Symbols:: Examining the symbol table
190* Altering:: Altering execution
191* GDB Files:: @value{GDBN} files
192* Targets:: Specifying a debugging target
104c1213 193* Configurations:: Configuration-specific information
c906108c
SS
194* Controlling GDB:: Controlling @value{GDBN}
195* Sequences:: Canned sequences of commands
c906108c 196* Emacs:: Using @value{GDBN} under @sc{gnu} Emacs
6d2ebf8b 197* Annotations:: @value{GDBN}'s annotation interface.
c906108c
SS
198
199* GDB Bugs:: Reporting bugs in @value{GDBN}
c906108c 200* Formatting Documentation:: How to format and print @value{GDBN} documentation
c906108c
SS
201
202* Command Line Editing:: Command Line Editing
203* Using History Interactively:: Using History Interactively
204* Installing GDB:: Installing GDB
205* Index:: Index
c906108c
SS
206@end menu
207
6d2ebf8b
SS
208@end ifhtml
209
210@node Summary
c906108c
SS
211@unnumbered Summary of @value{GDBN}
212
213The purpose of a debugger such as @value{GDBN} is to allow you to see what is
214going on ``inside'' another program while it executes---or what another
215program was doing at the moment it crashed.
216
217@value{GDBN} can do four main kinds of things (plus other things in support of
218these) to help you catch bugs in the act:
219
220@itemize @bullet
221@item
222Start your program, specifying anything that might affect its behavior.
223
224@item
225Make your program stop on specified conditions.
226
227@item
228Examine what has happened, when your program has stopped.
229
230@item
231Change things in your program, so you can experiment with correcting the
232effects of one bug and go on to learn about another.
233@end itemize
234
cce74817 235You can use @value{GDBN} to debug programs written in C and C++.
c906108c 236For more information, see @ref{Support,,Supported languages}.
c906108c
SS
237For more information, see @ref{C,,C and C++}.
238
cce74817
JM
239@cindex Chill
240@cindex Modula-2
c906108c 241Support for Modula-2 and Chill is partial. For information on Modula-2,
cce74817 242see @ref{Modula-2,,Modula-2}. For information on Chill, see @ref{Chill}.
c906108c 243
cce74817
JM
244@cindex Pascal
245Debugging Pascal programs which use sets, subranges, file variables, or
246nested functions does not currently work. @value{GDBN} does not support
247entering expressions, printing values, or similar features using Pascal
248syntax.
c906108c 249
c906108c
SS
250@cindex Fortran
251@value{GDBN} can be used to debug programs written in Fortran, although
53a5351d 252it may be necessary to refer to some variables with a trailing
cce74817 253underscore.
c906108c 254
c906108c
SS
255@menu
256* Free Software:: Freely redistributable software
257* Contributors:: Contributors to GDB
258@end menu
259
6d2ebf8b 260@node Free Software
c906108c
SS
261@unnumberedsec Free software
262
5d161b24 263@value{GDBN} is @dfn{free software}, protected by the @sc{gnu}
c906108c
SS
264General Public License
265(GPL). The GPL gives you the freedom to copy or adapt a licensed
266program---but every person getting a copy also gets with it the
267freedom to modify that copy (which means that they must get access to
268the source code), and the freedom to distribute further copies.
269Typical software companies use copyrights to limit your freedoms; the
270Free Software Foundation uses the GPL to preserve these freedoms.
271
272Fundamentally, the General Public License is a license which says that
273you have these freedoms and that you cannot take these freedoms away
274from anyone else.
275
6d2ebf8b 276@node Contributors
96a2c332
SS
277@unnumberedsec Contributors to @value{GDBN}
278
279Richard Stallman was the original author of @value{GDBN}, and of many
280other @sc{gnu} programs. Many others have contributed to its
281development. This section attempts to credit major contributors. One
282of the virtues of free software is that everyone is free to contribute
283to it; with regret, we cannot actually acknowledge everyone here. The
284file @file{ChangeLog} in the @value{GDBN} distribution approximates a
c906108c
SS
285blow-by-blow account.
286
287Changes much prior to version 2.0 are lost in the mists of time.
288
289@quotation
290@emph{Plea:} Additions to this section are particularly welcome. If you
291or your friends (or enemies, to be evenhanded) have been unfairly
292omitted from this list, we would like to add your names!
293@end quotation
294
295So that they may not regard their many labors as thankless, we
296particularly thank those who shepherded @value{GDBN} through major
297releases:
298Jim Blandy (release 4.18);
299Jason Molenda (release 4.17);
300Stan Shebs (release 4.14);
301Fred Fish (releases 4.16, 4.15, 4.13, 4.12, 4.11, 4.10, and 4.9);
302Stu Grossman and John Gilmore (releases 4.8, 4.7, 4.6, 4.5, and 4.4);
303John Gilmore (releases 4.3, 4.2, 4.1, 4.0, and 3.9);
304Jim Kingdon (releases 3.5, 3.4, and 3.3);
305and Randy Smith (releases 3.2, 3.1, and 3.0).
306
307Richard Stallman, assisted at various times by Peter TerMaat, Chris
308Hanson, and Richard Mlynarik, handled releases through 2.8.
309
96a2c332
SS
310Michael Tiemann is the author of most of the @sc{gnu} C++ support in
311@value{GDBN}, with significant additional contributions from Per
312Bothner. James Clark wrote the @sc{gnu} C++ demangler. Early work on
313C++ was by Peter TerMaat (who also did much general update work leading
314to release 3.0).
c906108c
SS
315
316@value{GDBN} 4 uses the BFD subroutine library to examine multiple
317object-file formats; BFD was a joint project of David V.
318Henkel-Wallace, Rich Pixley, Steve Chamberlain, and John Gilmore.
319
320David Johnson wrote the original COFF support; Pace Willison did
321the original support for encapsulated COFF.
322
323Brent Benson of Harris Computer Systems contributed DWARF 2 support.
324
325Adam de Boor and Bradley Davis contributed the ISI Optimum V support.
326Per Bothner, Noboyuki Hikichi, and Alessandro Forin contributed MIPS
327support.
328Jean-Daniel Fekete contributed Sun 386i support.
329Chris Hanson improved the HP9000 support.
330Noboyuki Hikichi and Tomoyuki Hasei contributed Sony/News OS 3 support.
331David Johnson contributed Encore Umax support.
332Jyrki Kuoppala contributed Altos 3068 support.
333Jeff Law contributed HP PA and SOM support.
334Keith Packard contributed NS32K support.
335Doug Rabson contributed Acorn Risc Machine support.
336Bob Rusk contributed Harris Nighthawk CX-UX support.
337Chris Smith contributed Convex support (and Fortran debugging).
338Jonathan Stone contributed Pyramid support.
339Michael Tiemann contributed SPARC support.
340Tim Tucker contributed support for the Gould NP1 and Gould Powernode.
341Pace Willison contributed Intel 386 support.
342Jay Vosburgh contributed Symmetry support.
343
344Andreas Schwab contributed M68K Linux support.
345
346Rich Schaefer and Peter Schauer helped with support of SunOS shared
347libraries.
348
349Jay Fenlason and Roland McGrath ensured that @value{GDBN} and GAS agree
350about several machine instruction sets.
351
352Patrick Duval, Ted Goldstein, Vikram Koka and Glenn Engel helped develop
353remote debugging. Intel Corporation, Wind River Systems, AMD, and ARM
354contributed remote debugging modules for the i960, VxWorks, A29K UDI,
355and RDI targets, respectively.
356
357Brian Fox is the author of the readline libraries providing
358command-line editing and command history.
359
7a292a7a
SS
360Andrew Beers of SUNY Buffalo wrote the language-switching code, the
361Modula-2 support, and contributed the Languages chapter of this manual.
c906108c 362
5d161b24 363Fred Fish wrote most of the support for Unix System Vr4.
c906108c
SS
364He also enhanced the command-completion support to cover C++ overloaded
365symbols.
c906108c
SS
366
367Hitachi America, Ltd. sponsored the support for H8/300, H8/500, and
368Super-H processors.
369
370NEC sponsored the support for the v850, Vr4xxx, and Vr5xxx processors.
371
372Mitsubishi sponsored the support for D10V, D30V, and M32R/D processors.
373
374Toshiba sponsored the support for the TX39 Mips processor.
375
376Matsushita sponsored the support for the MN10200 and MN10300 processors.
377
96a2c332 378Fujitsu sponsored the support for SPARClite and FR30 processors.
c906108c
SS
379
380Kung Hsu, Jeff Law, and Rick Sladkey added support for hardware
381watchpoints.
382
383Michael Snyder added support for tracepoints.
384
385Stu Grossman wrote gdbserver.
386
387Jim Kingdon, Peter Schauer, Ian Taylor, and Stu Grossman made
96a2c332 388nearly innumerable bug fixes and cleanups throughout @value{GDBN}.
c906108c
SS
389
390The following people at the Hewlett-Packard Company contributed
391support for the PA-RISC 2.0 architecture, HP-UX 10.20, 10.30, and 11.0
392(narrow mode), HP's implementation of kernel threads, HP's aC++
393compiler, and the terminal user interface: Ben Krepp, Richard Title,
394John Bishop, Susan Macchia, Kathy Mann, Satish Pai, India Paul, Steve
395Rehrauer, and Elena Zannoni. Kim Haase provided HP-specific
396information in this manual.
397
96a2c332
SS
398Cygnus Solutions has sponsored @value{GDBN} maintenance and much of its
399development since 1991. Cygnus engineers who have worked on @value{GDBN}
2df3850c
JM
400fulltime include Mark Alexander, Jim Blandy, Per Bothner, Kevin
401Buettner, Edith Epstein, Chris Faylor, Fred Fish, Martin Hunt, Jim
402Ingham, John Gilmore, Stu Grossman, Kung Hsu, Jim Kingdon, John Metzler,
403Fernando Nasser, Geoffrey Noer, Dawn Perchik, Rich Pixley, Zdenek
404Radouch, Keith Seitz, Stan Shebs, David Taylor, and Elena Zannoni. In
405addition, Dave Brolley, Ian Carmichael, Steve Chamberlain, Nick Clifton,
406JT Conklin, Stan Cox, DJ Delorie, Ulrich Drepper, Frank Eigler, Doug
407Evans, Sean Fagan, David Henkel-Wallace, Richard Henderson, Jeff
408Holcomb, Jeff Law, Jim Lemke, Tom Lord, Bob Manson, Michael Meissner,
409Jason Merrill, Catherine Moore, Drew Moseley, Ken Raeburn, Gavin
410Romig-Koch, Rob Savoye, Jamie Smith, Mike Stump, Ian Taylor, Angela
411Thomas, Michael Tiemann, Tom Tromey, Ron Unrau, Jim Wilson, and David
412Zuhn have made contributions both large and small.
c906108c
SS
413
414
6d2ebf8b 415@node Sample Session
c906108c
SS
416@chapter A Sample @value{GDBN} Session
417
418You can use this manual at your leisure to read all about @value{GDBN}.
419However, a handful of commands are enough to get started using the
420debugger. This chapter illustrates those commands.
421
422@iftex
423In this sample session, we emphasize user input like this: @b{input},
424to make it easier to pick out from the surrounding output.
425@end iftex
426
427@c FIXME: this example may not be appropriate for some configs, where
428@c FIXME...primary interest is in remote use.
429
430One of the preliminary versions of @sc{gnu} @code{m4} (a generic macro
431processor) exhibits the following bug: sometimes, when we change its
432quote strings from the default, the commands used to capture one macro
433definition within another stop working. In the following short @code{m4}
434session, we define a macro @code{foo} which expands to @code{0000}; we
435then use the @code{m4} built-in @code{defn} to define @code{bar} as the
436same thing. However, when we change the open quote string to
437@code{<QUOTE>} and the close quote string to @code{<UNQUOTE>}, the same
438procedure fails to define a new synonym @code{baz}:
439
440@smallexample
441$ @b{cd gnu/m4}
442$ @b{./m4}
443@b{define(foo,0000)}
444
445@b{foo}
4460000
447@b{define(bar,defn(`foo'))}
448
449@b{bar}
4500000
451@b{changequote(<QUOTE>,<UNQUOTE>)}
452
453@b{define(baz,defn(<QUOTE>foo<UNQUOTE>))}
454@b{baz}
455@b{C-d}
456m4: End of input: 0: fatal error: EOF in string
457@end smallexample
458
459@noindent
460Let us use @value{GDBN} to try to see what is going on.
461
c906108c
SS
462@smallexample
463$ @b{@value{GDBP} m4}
464@c FIXME: this falsifies the exact text played out, to permit smallbook
465@c FIXME... format to come out better.
466@value{GDBN} is free software and you are welcome to distribute copies
5d161b24 467 of it under certain conditions; type "show copying" to see
c906108c 468 the conditions.
5d161b24 469There is absolutely no warranty for @value{GDBN}; type "show warranty"
c906108c
SS
470 for details.
471
472@value{GDBN} @value{GDBVN}, Copyright 1999 Free Software Foundation, Inc...
473(@value{GDBP})
474@end smallexample
c906108c
SS
475
476@noindent
477@value{GDBN} reads only enough symbol data to know where to find the
478rest when needed; as a result, the first prompt comes up very quickly.
479We now tell @value{GDBN} to use a narrower display width than usual, so
480that examples fit in this manual.
481
482@smallexample
483(@value{GDBP}) @b{set width 70}
484@end smallexample
485
486@noindent
487We need to see how the @code{m4} built-in @code{changequote} works.
488Having looked at the source, we know the relevant subroutine is
489@code{m4_changequote}, so we set a breakpoint there with the @value{GDBN}
490@code{break} command.
491
492@smallexample
493(@value{GDBP}) @b{break m4_changequote}
494Breakpoint 1 at 0x62f4: file builtin.c, line 879.
495@end smallexample
496
497@noindent
498Using the @code{run} command, we start @code{m4} running under @value{GDBN}
499control; as long as control does not reach the @code{m4_changequote}
500subroutine, the program runs as usual:
501
502@smallexample
503(@value{GDBP}) @b{run}
504Starting program: /work/Editorial/gdb/gnu/m4/m4
505@b{define(foo,0000)}
506
507@b{foo}
5080000
509@end smallexample
510
511@noindent
512To trigger the breakpoint, we call @code{changequote}. @value{GDBN}
513suspends execution of @code{m4}, displaying information about the
514context where it stops.
515
516@smallexample
517@b{changequote(<QUOTE>,<UNQUOTE>)}
518
5d161b24 519Breakpoint 1, m4_changequote (argc=3, argv=0x33c70)
c906108c
SS
520 at builtin.c:879
521879 if (bad_argc(TOKEN_DATA_TEXT(argv[0]),argc,1,3))
522@end smallexample
523
524@noindent
525Now we use the command @code{n} (@code{next}) to advance execution to
526the next line of the current function.
527
528@smallexample
529(@value{GDBP}) @b{n}
530882 set_quotes((argc >= 2) ? TOKEN_DATA_TEXT(argv[1])\
531 : nil,
532@end smallexample
533
534@noindent
535@code{set_quotes} looks like a promising subroutine. We can go into it
536by using the command @code{s} (@code{step}) instead of @code{next}.
537@code{step} goes to the next line to be executed in @emph{any}
538subroutine, so it steps into @code{set_quotes}.
539
540@smallexample
541(@value{GDBP}) @b{s}
542set_quotes (lq=0x34c78 "<QUOTE>", rq=0x34c88 "<UNQUOTE>")
543 at input.c:530
544530 if (lquote != def_lquote)
545@end smallexample
546
547@noindent
548The display that shows the subroutine where @code{m4} is now
549suspended (and its arguments) is called a stack frame display. It
550shows a summary of the stack. We can use the @code{backtrace}
551command (which can also be spelled @code{bt}), to see where we are
552in the stack as a whole: the @code{backtrace} command displays a
553stack frame for each active subroutine.
554
555@smallexample
556(@value{GDBP}) @b{bt}
557#0 set_quotes (lq=0x34c78 "<QUOTE>", rq=0x34c88 "<UNQUOTE>")
558 at input.c:530
5d161b24 559#1 0x6344 in m4_changequote (argc=3, argv=0x33c70)
c906108c
SS
560 at builtin.c:882
561#2 0x8174 in expand_macro (sym=0x33320) at macro.c:242
562#3 0x7a88 in expand_token (obs=0x0, t=209696, td=0xf7fffa30)
563 at macro.c:71
564#4 0x79dc in expand_input () at macro.c:40
565#5 0x2930 in main (argc=0, argv=0xf7fffb20) at m4.c:195
566@end smallexample
567
568@noindent
569We step through a few more lines to see what happens. The first two
570times, we can use @samp{s}; the next two times we use @code{n} to avoid
571falling into the @code{xstrdup} subroutine.
572
573@smallexample
574(@value{GDBP}) @b{s}
5750x3b5c 532 if (rquote != def_rquote)
576(@value{GDBP}) @b{s}
5770x3b80 535 lquote = (lq == nil || *lq == '\0') ? \
578def_lquote : xstrdup(lq);
579(@value{GDBP}) @b{n}
580536 rquote = (rq == nil || *rq == '\0') ? def_rquote\
581 : xstrdup(rq);
582(@value{GDBP}) @b{n}
583538 len_lquote = strlen(rquote);
584@end smallexample
585
586@noindent
587The last line displayed looks a little odd; we can examine the variables
588@code{lquote} and @code{rquote} to see if they are in fact the new left
589and right quotes we specified. We use the command @code{p}
590(@code{print}) to see their values.
591
592@smallexample
593(@value{GDBP}) @b{p lquote}
594$1 = 0x35d40 "<QUOTE>"
595(@value{GDBP}) @b{p rquote}
596$2 = 0x35d50 "<UNQUOTE>"
597@end smallexample
598
599@noindent
600@code{lquote} and @code{rquote} are indeed the new left and right quotes.
601To look at some context, we can display ten lines of source
602surrounding the current line with the @code{l} (@code{list}) command.
603
604@smallexample
605(@value{GDBP}) @b{l}
606533 xfree(rquote);
607534
608535 lquote = (lq == nil || *lq == '\0') ? def_lquote\
609 : xstrdup (lq);
610536 rquote = (rq == nil || *rq == '\0') ? def_rquote\
611 : xstrdup (rq);
612537
613538 len_lquote = strlen(rquote);
614539 len_rquote = strlen(lquote);
615540 @}
616541
617542 void
618@end smallexample
619
620@noindent
621Let us step past the two lines that set @code{len_lquote} and
622@code{len_rquote}, and then examine the values of those variables.
623
624@smallexample
625(@value{GDBP}) @b{n}
626539 len_rquote = strlen(lquote);
627(@value{GDBP}) @b{n}
628540 @}
629(@value{GDBP}) @b{p len_lquote}
630$3 = 9
631(@value{GDBP}) @b{p len_rquote}
632$4 = 7
633@end smallexample
634
635@noindent
636That certainly looks wrong, assuming @code{len_lquote} and
637@code{len_rquote} are meant to be the lengths of @code{lquote} and
638@code{rquote} respectively. We can set them to better values using
639the @code{p} command, since it can print the value of
640any expression---and that expression can include subroutine calls and
641assignments.
642
643@smallexample
644(@value{GDBP}) @b{p len_lquote=strlen(lquote)}
645$5 = 7
646(@value{GDBP}) @b{p len_rquote=strlen(rquote)}
647$6 = 9
648@end smallexample
649
650@noindent
651Is that enough to fix the problem of using the new quotes with the
652@code{m4} built-in @code{defn}? We can allow @code{m4} to continue
653executing with the @code{c} (@code{continue}) command, and then try the
654example that caused trouble initially:
655
656@smallexample
657(@value{GDBP}) @b{c}
658Continuing.
659
660@b{define(baz,defn(<QUOTE>foo<UNQUOTE>))}
661
662baz
6630000
664@end smallexample
665
666@noindent
667Success! The new quotes now work just as well as the default ones. The
668problem seems to have been just the two typos defining the wrong
669lengths. We allow @code{m4} exit by giving it an EOF as input:
670
671@smallexample
672@b{C-d}
673Program exited normally.
674@end smallexample
675
676@noindent
677The message @samp{Program exited normally.} is from @value{GDBN}; it
678indicates @code{m4} has finished executing. We can end our @value{GDBN}
679session with the @value{GDBN} @code{quit} command.
680
681@smallexample
682(@value{GDBP}) @b{quit}
683@end smallexample
c906108c 684
6d2ebf8b 685@node Invocation
c906108c
SS
686@chapter Getting In and Out of @value{GDBN}
687
688This chapter discusses how to start @value{GDBN}, and how to get out of it.
5d161b24 689The essentials are:
c906108c 690@itemize @bullet
5d161b24 691@item
53a5351d 692type @samp{@value{GDBP}} to start @value{GDBN}.
5d161b24 693@item
c906108c
SS
694type @kbd{quit} or @kbd{C-d} to exit.
695@end itemize
696
697@menu
698* Invoking GDB:: How to start @value{GDBN}
699* Quitting GDB:: How to quit @value{GDBN}
700* Shell Commands:: How to use shell commands inside @value{GDBN}
701@end menu
702
6d2ebf8b 703@node Invoking GDB
c906108c
SS
704@section Invoking @value{GDBN}
705
c906108c
SS
706Invoke @value{GDBN} by running the program @code{@value{GDBP}}. Once started,
707@value{GDBN} reads commands from the terminal until you tell it to exit.
708
709You can also run @code{@value{GDBP}} with a variety of arguments and options,
710to specify more of your debugging environment at the outset.
711
c906108c
SS
712The command-line options described here are designed
713to cover a variety of situations; in some environments, some of these
5d161b24 714options may effectively be unavailable.
c906108c
SS
715
716The most usual way to start @value{GDBN} is with one argument,
717specifying an executable program:
718
719@example
720@value{GDBP} @var{program}
721@end example
722
c906108c
SS
723@noindent
724You can also start with both an executable program and a core file
725specified:
726
727@example
728@value{GDBP} @var{program} @var{core}
729@end example
730
731You can, instead, specify a process ID as a second argument, if you want
732to debug a running process:
733
734@example
735@value{GDBP} @var{program} 1234
736@end example
737
738@noindent
739would attach @value{GDBN} to process @code{1234} (unless you also have a file
740named @file{1234}; @value{GDBN} does check for a core file first).
741
c906108c 742Taking advantage of the second command-line argument requires a fairly
2df3850c
JM
743complete operating system; when you use @value{GDBN} as a remote
744debugger attached to a bare board, there may not be any notion of
745``process'', and there is often no way to get a core dump. @value{GDBN}
746will warn you if it is unable to attach or to read core dumps.
c906108c 747
96a2c332 748You can run @code{@value{GDBP}} without printing the front material, which describes
c906108c
SS
749@value{GDBN}'s non-warranty, by specifying @code{-silent}:
750
751@smallexample
752@value{GDBP} -silent
753@end smallexample
754
755@noindent
756You can further control how @value{GDBN} starts up by using command-line
757options. @value{GDBN} itself can remind you of the options available.
758
759@noindent
760Type
761
762@example
763@value{GDBP} -help
764@end example
765
766@noindent
767to display all available options and briefly describe their use
768(@samp{@value{GDBP} -h} is a shorter equivalent).
769
770All options and command line arguments you give are processed
771in sequential order. The order makes a difference when the
772@samp{-x} option is used.
773
774
775@menu
c906108c
SS
776* File Options:: Choosing files
777* Mode Options:: Choosing modes
778@end menu
779
6d2ebf8b 780@node File Options
c906108c
SS
781@subsection Choosing files
782
2df3850c 783When @value{GDBN} starts, it reads any arguments other than options as
c906108c
SS
784specifying an executable file and core file (or process ID). This is
785the same as if the arguments were specified by the @samp{-se} and
786@samp{-c} options respectively. (@value{GDBN} reads the first argument
787that does not have an associated option flag as equivalent to the
788@samp{-se} option followed by that argument; and the second argument
789that does not have an associated option flag, if any, as equivalent to
790the @samp{-c} option followed by that argument.)
7a292a7a
SS
791
792If @value{GDBN} has not been configured to included core file support,
793such as for most embedded targets, then it will complain about a second
794argument and ignore it.
c906108c
SS
795
796Many options have both long and short forms; both are shown in the
797following list. @value{GDBN} also recognizes the long forms if you truncate
798them, so long as enough of the option is present to be unambiguous.
799(If you prefer, you can flag option arguments with @samp{--} rather
800than @samp{-}, though we illustrate the more usual convention.)
801
d700128c
EZ
802@c NOTE: the @cindex entries here use double dashes ON PURPOSE. This
803@c way, both those who look for -foo and --foo in the index, will find
804@c it.
805
c906108c
SS
806@table @code
807@item -symbols @var{file}
808@itemx -s @var{file}
d700128c
EZ
809@cindex @code{--symbols}
810@cindex @code{-s}
c906108c
SS
811Read symbol table from file @var{file}.
812
813@item -exec @var{file}
814@itemx -e @var{file}
d700128c
EZ
815@cindex @code{--exec}
816@cindex @code{-e}
7a292a7a
SS
817Use file @var{file} as the executable file to execute when appropriate,
818and for examining pure data in conjunction with a core dump.
c906108c
SS
819
820@item -se @var{file}
d700128c 821@cindex @code{--se}
c906108c
SS
822Read symbol table from file @var{file} and use it as the executable
823file.
824
c906108c
SS
825@item -core @var{file}
826@itemx -c @var{file}
d700128c
EZ
827@cindex @code{--core}
828@cindex @code{-c}
c906108c
SS
829Use file @var{file} as a core dump to examine.
830
831@item -c @var{number}
832Connect to process ID @var{number}, as with the @code{attach} command
833(unless there is a file in core-dump format named @var{number}, in which
834case @samp{-c} specifies that file as a core dump to read).
c906108c
SS
835
836@item -command @var{file}
837@itemx -x @var{file}
d700128c
EZ
838@cindex @code{--command}
839@cindex @code{-x}
c906108c
SS
840Execute @value{GDBN} commands from file @var{file}. @xref{Command
841Files,, Command files}.
842
843@item -directory @var{directory}
844@itemx -d @var{directory}
d700128c
EZ
845@cindex @code{--directory}
846@cindex @code{-d}
c906108c
SS
847Add @var{directory} to the path to search for source files.
848
c906108c
SS
849@item -m
850@itemx -mapped
d700128c
EZ
851@cindex @code{--mapped}
852@cindex @code{-m}
c906108c
SS
853@emph{Warning: this option depends on operating system facilities that are not
854supported on all systems.}@*
855If memory-mapped files are available on your system through the @code{mmap}
5d161b24 856system call, you can use this option
c906108c
SS
857to have @value{GDBN} write the symbols from your
858program into a reusable file in the current directory. If the program you are debugging is
96a2c332 859called @file{/tmp/fred}, the mapped symbol file is @file{/tmp/fred.syms}.
c906108c
SS
860Future @value{GDBN} debugging sessions notice the presence of this file,
861and can quickly map in symbol information from it, rather than reading
862the symbol table from the executable program.
863
864The @file{.syms} file is specific to the host machine where @value{GDBN}
865is run. It holds an exact image of the internal @value{GDBN} symbol
866table. It cannot be shared across multiple host platforms.
c906108c 867
c906108c
SS
868@item -r
869@itemx -readnow
d700128c
EZ
870@cindex @code{--readnow}
871@cindex @code{-r}
c906108c
SS
872Read each symbol file's entire symbol table immediately, rather than
873the default, which is to read it incrementally as it is needed.
874This makes startup slower, but makes future operations faster.
53a5351d 875
c906108c
SS
876@end table
877
2df3850c 878You typically combine the @code{-mapped} and @code{-readnow} options in
c906108c 879order to build a @file{.syms} file that contains complete symbol
2df3850c
JM
880information. (@xref{Files,,Commands to specify files}, for information
881on @file{.syms} files.) A simple @value{GDBN} invocation to do nothing
882but build a @file{.syms} file for future use is:
c906108c
SS
883
884@example
2df3850c 885gdb -batch -nx -mapped -readnow programname
c906108c 886@end example
c906108c 887
6d2ebf8b 888@node Mode Options
c906108c
SS
889@subsection Choosing modes
890
891You can run @value{GDBN} in various alternative modes---for example, in
892batch mode or quiet mode.
893
894@table @code
895@item -nx
896@itemx -n
d700128c
EZ
897@cindex @code{--nx}
898@cindex @code{-n}
2df3850c
JM
899Do not execute commands found in any initialization files (normally
900called @file{.gdbinit}, or @file{gdb.ini} on PCs). Normally,
901@value{GDBN} executes the commands in these files after all the command
902options and arguments have been processed. @xref{Command Files,,Command
903files}.
c906108c
SS
904
905@item -quiet
d700128c 906@itemx -silent
c906108c 907@itemx -q
d700128c
EZ
908@cindex @code{--quiet}
909@cindex @code{--silent}
910@cindex @code{-q}
c906108c
SS
911``Quiet''. Do not print the introductory and copyright messages. These
912messages are also suppressed in batch mode.
913
914@item -batch
d700128c 915@cindex @code{--batch}
c906108c
SS
916Run in batch mode. Exit with status @code{0} after processing all the
917command files specified with @samp{-x} (and all commands from
918initialization files, if not inhibited with @samp{-n}). Exit with
919nonzero status if an error occurs in executing the @value{GDBN} commands
920in the command files.
921
2df3850c
JM
922Batch mode may be useful for running @value{GDBN} as a filter, for
923example to download and run a program on another computer; in order to
924make this more useful, the message
c906108c
SS
925
926@example
927Program exited normally.
928@end example
929
930@noindent
2df3850c
JM
931(which is ordinarily issued whenever a program running under
932@value{GDBN} control terminates) is not issued when running in batch
933mode.
934
935@item -nowindows
936@itemx -nw
d700128c
EZ
937@cindex @code{--nowindows}
938@cindex @code{-nw}
2df3850c 939``No windows''. If @value{GDBN} comes with a graphical user interface
96a2c332 940(GUI) built in, then this option tells @value{GDBN} to only use the command-line
2df3850c
JM
941interface. If no GUI is available, this option has no effect.
942
943@item -windows
944@itemx -w
d700128c
EZ
945@cindex @code{--windows}
946@cindex @code{-w}
2df3850c
JM
947If @value{GDBN} includes a GUI, then this option requires it to be
948used if possible.
c906108c
SS
949
950@item -cd @var{directory}
d700128c 951@cindex @code{--cd}
c906108c
SS
952Run @value{GDBN} using @var{directory} as its working directory,
953instead of the current directory.
954
c906108c
SS
955@item -fullname
956@itemx -f
d700128c
EZ
957@cindex @code{--fullname}
958@cindex @code{-f}
7a292a7a
SS
959@sc{gnu} Emacs sets this option when it runs @value{GDBN} as a
960subprocess. It tells @value{GDBN} to output the full file name and line
961number in a standard, recognizable fashion each time a stack frame is
962displayed (which includes each time your program stops). This
963recognizable format looks like two @samp{\032} characters, followed by
964the file name, line number and character position separated by colons,
965and a newline. The Emacs-to-@value{GDBN} interface program uses the two
966@samp{\032} characters as a signal to display the source code for the
967frame.
c906108c 968
d700128c
EZ
969@item -epoch
970@cindex @code{--epoch}
971The Epoch Emacs-@value{GDBN} interface sets this option when it runs
972@value{GDBN} as a subprocess. It tells @value{GDBN} to modify its print
973routines so as to allow Epoch to display values of expressions in a
974separate window.
975
976@item -annotate @var{level}
977@cindex @code{--annotate}
978This option sets the @dfn{annotation level} inside @value{GDBN}. Its
979effect is identical to using @samp{set annotate @var{level}}
980(@pxref{Annotations}).
981Annotation level controls how much information does @value{GDBN} print
982together with its prompt, values of expressions, source lines, and other
983types of output. Level 0 is the normal, level 1 is for use when
984@value{GDBN} is run as a subprocess of @sc{gnu} Emacs, level 2 is the
985maximum annotation suitable for programs that control @value{GDBN}.
986
987@item -async
988@cindex @code{--async}
989Use the asynchronous event loop for the command-line interface.
990@value{GDBN} processes all events, such as user keyboard input, via a
991special event loop. This allows @value{GDBN} to accept and process user
992commands in parallel with the debugged process being
993run@footnote{@value{GDBN} built with @sc{djgpp} tools for
994MS-DOS/MS-Windows supports this mode of operation, but the event loop is
995suspended when the debuggee runs.}, so you don't need to wait for
996control to return to @value{GDBN} before you type the next command.
997(@emph{Note:} as of version 5.0, the target side of the asynchronous
998operation is not yet in place, so @samp{-async} does not work fully
999yet.)
1000@c FIXME: when the target side of the event loop is done, the above NOTE
1001@c should be removed.
1002
1003When the standard input is connected to a terminal device, @value{GDBN}
1004uses the asynchronous event loop by default, unless disabled by the
1005@samp{-noasync} option.
1006
1007@item -noasync
1008@cindex @code{--noasync}
1009Disable the asynchronous event loop for the command-line interface.
1010
2df3850c
JM
1011@item -baud @var{bps}
1012@itemx -b @var{bps}
d700128c
EZ
1013@cindex @code{--baud}
1014@cindex @code{-b}
c906108c
SS
1015Set the line speed (baud rate or bits per second) of any serial
1016interface used by @value{GDBN} for remote debugging.
c906108c
SS
1017
1018@item -tty @var{device}
d700128c
EZ
1019@itemx -t @var{device}
1020@cindex @code{--tty}
1021@cindex @code{-t}
c906108c
SS
1022Run using @var{device} for your program's standard input and output.
1023@c FIXME: kingdon thinks there is more to -tty. Investigate.
c906108c 1024
53a5351d
JM
1025@c resolve the situation of these eventually
1026@c @item -tui
d700128c 1027@c @cindex @code{--tui}
53a5351d
JM
1028@c Use a Terminal User Interface. For information, use your Web browser to
1029@c read the file @file{TUI.html}, which is usually installed in the
1030@c directory @code{/opt/langtools/wdb/doc} on HP-UX systems. Do not use
1031@c this option if you run @value{GDBN} from Emacs (see @pxref{Emacs, ,Using
1032@c @value{GDBN} under @sc{gnu} Emacs}).
1033
1034@c @item -xdb
d700128c 1035@c @cindex @code{--xdb}
53a5351d
JM
1036@c Run in XDB compatibility mode, allowing the use of certain XDB commands.
1037@c For information, see the file @file{xdb_trans.html}, which is usually
1038@c installed in the directory @code{/opt/langtools/wdb/doc} on HP-UX
1039@c systems.
1040
d700128c
EZ
1041@item -interpreter @var{interp}
1042@cindex @code{--interpreter}
1043Use the interpreter @var{interp} for interface with the controlling
1044program or device. This option is meant to be set by programs which
1045communicate with @value{GDBN} using it as a back end. For example,
1046@samp{--interpreter=mi} causes @value{GDBN} to use the @dfn{gdbmi
7162c0ca 1047interface} (@pxref{GDB/MI, , The @sc{gdb/mi} Interface}).
d700128c
EZ
1048
1049@item -write
1050@cindex @code{--write}
1051Open the executable and core files for both reading and writing. This
1052is equivalent to the @samp{set write on} command inside @value{GDBN}
1053(@pxref{Patching}).
1054
1055@item -statistics
1056@cindex @code{--statistics}
1057This option causes @value{GDBN} to print statistics about time and
1058memory usage after it completes each command and returns to the prompt.
1059
1060@item -version
1061@cindex @code{--version}
1062This option causes @value{GDBN} to print its version number and
1063no-warranty blurb, and exit.
1064
c906108c
SS
1065@end table
1066
6d2ebf8b 1067@node Quitting GDB
c906108c
SS
1068@section Quitting @value{GDBN}
1069@cindex exiting @value{GDBN}
1070@cindex leaving @value{GDBN}
1071
1072@table @code
1073@kindex quit @r{[}@var{expression}@r{]}
1074@kindex q
96a2c332
SS
1075@item quit @r{[}@var{expression}@r{]}
1076@itemx q
1077To exit @value{GDBN}, use the @code{quit} command (abbreviated
1078@code{q}), or type an end-of-file character (usually @kbd{C-d}). If you
1079do not supply @var{expression}, @value{GDBN} will terminate normally;
1080otherwise it will terminate using the result of @var{expression} as the
1081error code.
c906108c
SS
1082@end table
1083
1084@cindex interrupt
1085An interrupt (often @kbd{C-c}) does not exit from @value{GDBN}, but rather
1086terminates the action of any @value{GDBN} command that is in progress and
1087returns to @value{GDBN} command level. It is safe to type the interrupt
1088character at any time because @value{GDBN} does not allow it to take effect
1089until a time when it is safe.
1090
c906108c
SS
1091If you have been using @value{GDBN} to control an attached process or
1092device, you can release it with the @code{detach} command
1093(@pxref{Attach, ,Debugging an already-running process}).
c906108c 1094
6d2ebf8b 1095@node Shell Commands
c906108c
SS
1096@section Shell commands
1097
1098If you need to execute occasional shell commands during your
1099debugging session, there is no need to leave or suspend @value{GDBN}; you can
1100just use the @code{shell} command.
1101
1102@table @code
1103@kindex shell
1104@cindex shell escape
1105@item shell @var{command string}
1106Invoke a standard shell to execute @var{command string}.
c906108c 1107If it exists, the environment variable @code{SHELL} determines which
d4f3574e
SS
1108shell to run. Otherwise @value{GDBN} uses the default shell
1109(@file{/bin/sh} on Unix systems, @file{COMMAND.COM} on MS-DOS, etc.).
c906108c
SS
1110@end table
1111
1112The utility @code{make} is often needed in development environments.
1113You do not have to use the @code{shell} command for this purpose in
1114@value{GDBN}:
1115
1116@table @code
1117@kindex make
1118@cindex calling make
1119@item make @var{make-args}
1120Execute the @code{make} program with the specified
1121arguments. This is equivalent to @samp{shell make @var{make-args}}.
1122@end table
1123
6d2ebf8b 1124@node Commands
c906108c
SS
1125@chapter @value{GDBN} Commands
1126
1127You can abbreviate a @value{GDBN} command to the first few letters of the command
1128name, if that abbreviation is unambiguous; and you can repeat certain
1129@value{GDBN} commands by typing just @key{RET}. You can also use the @key{TAB}
1130key to get @value{GDBN} to fill out the rest of a word in a command (or to
1131show you the alternatives available, if there is more than one possibility).
1132
1133@menu
1134* Command Syntax:: How to give commands to @value{GDBN}
1135* Completion:: Command completion
1136* Help:: How to ask @value{GDBN} for help
1137@end menu
1138
6d2ebf8b 1139@node Command Syntax
c906108c
SS
1140@section Command syntax
1141
1142A @value{GDBN} command is a single line of input. There is no limit on
1143how long it can be. It starts with a command name, which is followed by
1144arguments whose meaning depends on the command name. For example, the
1145command @code{step} accepts an argument which is the number of times to
1146step, as in @samp{step 5}. You can also use the @code{step} command
96a2c332 1147with no arguments. Some commands do not allow any arguments.
c906108c
SS
1148
1149@cindex abbreviation
1150@value{GDBN} command names may always be truncated if that abbreviation is
1151unambiguous. Other possible command abbreviations are listed in the
1152documentation for individual commands. In some cases, even ambiguous
1153abbreviations are allowed; for example, @code{s} is specially defined as
1154equivalent to @code{step} even though there are other commands whose
1155names start with @code{s}. You can test abbreviations by using them as
1156arguments to the @code{help} command.
1157
1158@cindex repeating commands
1159@kindex RET
1160A blank line as input to @value{GDBN} (typing just @key{RET}) means to
96a2c332 1161repeat the previous command. Certain commands (for example, @code{run})
c906108c
SS
1162will not repeat this way; these are commands whose unintentional
1163repetition might cause trouble and which you are unlikely to want to
1164repeat.
1165
1166The @code{list} and @code{x} commands, when you repeat them with
1167@key{RET}, construct new arguments rather than repeating
1168exactly as typed. This permits easy scanning of source or memory.
1169
1170@value{GDBN} can also use @key{RET} in another way: to partition lengthy
1171output, in a way similar to the common utility @code{more}
1172(@pxref{Screen Size,,Screen size}). Since it is easy to press one
1173@key{RET} too many in this situation, @value{GDBN} disables command
1174repetition after any command that generates this sort of display.
1175
1176@kindex #
1177@cindex comment
1178Any text from a @kbd{#} to the end of the line is a comment; it does
1179nothing. This is useful mainly in command files (@pxref{Command
1180Files,,Command files}).
1181
6d2ebf8b 1182@node Completion
c906108c
SS
1183@section Command completion
1184
1185@cindex completion
1186@cindex word completion
1187@value{GDBN} can fill in the rest of a word in a command for you, if there is
1188only one possibility; it can also show you what the valid possibilities
1189are for the next word in a command, at any time. This works for @value{GDBN}
1190commands, @value{GDBN} subcommands, and the names of symbols in your program.
1191
1192Press the @key{TAB} key whenever you want @value{GDBN} to fill out the rest
1193of a word. If there is only one possibility, @value{GDBN} fills in the
1194word, and waits for you to finish the command (or press @key{RET} to
1195enter it). For example, if you type
1196
1197@c FIXME "@key" does not distinguish its argument sufficiently to permit
1198@c complete accuracy in these examples; space introduced for clarity.
1199@c If texinfo enhancements make it unnecessary, it would be nice to
1200@c replace " @key" by "@key" in the following...
1201@example
1202(@value{GDBP}) info bre @key{TAB}
1203@end example
1204
1205@noindent
1206@value{GDBN} fills in the rest of the word @samp{breakpoints}, since that is
1207the only @code{info} subcommand beginning with @samp{bre}:
1208
1209@example
1210(@value{GDBP}) info breakpoints
1211@end example
1212
1213@noindent
1214You can either press @key{RET} at this point, to run the @code{info
1215breakpoints} command, or backspace and enter something else, if
1216@samp{breakpoints} does not look like the command you expected. (If you
1217were sure you wanted @code{info breakpoints} in the first place, you
1218might as well just type @key{RET} immediately after @samp{info bre},
1219to exploit command abbreviations rather than command completion).
1220
1221If there is more than one possibility for the next word when you press
1222@key{TAB}, @value{GDBN} sounds a bell. You can either supply more
1223characters and try again, or just press @key{TAB} a second time;
1224@value{GDBN} displays all the possible completions for that word. For
1225example, you might want to set a breakpoint on a subroutine whose name
1226begins with @samp{make_}, but when you type @kbd{b make_@key{TAB}} @value{GDBN}
1227just sounds the bell. Typing @key{TAB} again displays all the
1228function names in your program that begin with those characters, for
1229example:
1230
1231@example
1232(@value{GDBP}) b make_ @key{TAB}
1233@exdent @value{GDBN} sounds bell; press @key{TAB} again, to see:
5d161b24
DB
1234make_a_section_from_file make_environ
1235make_abs_section make_function_type
1236make_blockvector make_pointer_type
1237make_cleanup make_reference_type
c906108c
SS
1238make_command make_symbol_completion_list
1239(@value{GDBP}) b make_
1240@end example
1241
1242@noindent
1243After displaying the available possibilities, @value{GDBN} copies your
1244partial input (@samp{b make_} in the example) so you can finish the
1245command.
1246
1247If you just want to see the list of alternatives in the first place, you
1248can press @kbd{M-?} rather than pressing @key{TAB} twice. @kbd{M-?}
7a292a7a 1249means @kbd{@key{META} ?}. You can type this either by holding down a
c906108c 1250key designated as the @key{META} shift on your keyboard (if there is
7a292a7a 1251one) while typing @kbd{?}, or as @key{ESC} followed by @kbd{?}.
c906108c
SS
1252
1253@cindex quotes in commands
1254@cindex completion of quoted strings
1255Sometimes the string you need, while logically a ``word'', may contain
7a292a7a
SS
1256parentheses or other characters that @value{GDBN} normally excludes from
1257its notion of a word. To permit word completion to work in this
1258situation, you may enclose words in @code{'} (single quote marks) in
1259@value{GDBN} commands.
c906108c 1260
c906108c
SS
1261The most likely situation where you might need this is in typing the
1262name of a C++ function. This is because C++ allows function overloading
1263(multiple definitions of the same function, distinguished by argument
1264type). For example, when you want to set a breakpoint you may need to
1265distinguish whether you mean the version of @code{name} that takes an
1266@code{int} parameter, @code{name(int)}, or the version that takes a
1267@code{float} parameter, @code{name(float)}. To use the word-completion
1268facilities in this situation, type a single quote @code{'} at the
1269beginning of the function name. This alerts @value{GDBN} that it may need to
1270consider more information than usual when you press @key{TAB} or
1271@kbd{M-?} to request word completion:
1272
1273@example
96a2c332 1274(@value{GDBP}) b 'bubble( @kbd{M-?}
c906108c
SS
1275bubble(double,double) bubble(int,int)
1276(@value{GDBP}) b 'bubble(
1277@end example
1278
1279In some cases, @value{GDBN} can tell that completing a name requires using
1280quotes. When this happens, @value{GDBN} inserts the quote for you (while
1281completing as much as it can) if you do not type the quote in the first
1282place:
1283
1284@example
1285(@value{GDBP}) b bub @key{TAB}
1286@exdent @value{GDBN} alters your input line to the following, and rings a bell:
1287(@value{GDBP}) b 'bubble(
1288@end example
1289
1290@noindent
1291In general, @value{GDBN} can tell that a quote is needed (and inserts it) if
1292you have not yet started typing the argument list when you ask for
1293completion on an overloaded symbol.
1294
d4f3574e 1295For more information about overloaded functions, see @ref{C plus plus
c906108c
SS
1296expressions, ,C++ expressions}. You can use the command @code{set
1297overload-resolution off} to disable overload resolution;
d4f3574e 1298see @ref{Debugging C plus plus, ,@value{GDBN} features for C++}.
c906108c
SS
1299
1300
6d2ebf8b 1301@node Help
c906108c
SS
1302@section Getting help
1303@cindex online documentation
1304@kindex help
1305
5d161b24 1306You can always ask @value{GDBN} itself for information on its commands,
c906108c
SS
1307using the command @code{help}.
1308
1309@table @code
1310@kindex h
1311@item help
1312@itemx h
1313You can use @code{help} (abbreviated @code{h}) with no arguments to
1314display a short list of named classes of commands:
1315
1316@smallexample
1317(@value{GDBP}) help
1318List of classes of commands:
1319
2df3850c 1320aliases -- Aliases of other commands
c906108c 1321breakpoints -- Making program stop at certain points
2df3850c 1322data -- Examining data
c906108c 1323files -- Specifying and examining files
2df3850c
JM
1324internals -- Maintenance commands
1325obscure -- Obscure features
1326running -- Running the program
1327stack -- Examining the stack
c906108c
SS
1328status -- Status inquiries
1329support -- Support facilities
96a2c332
SS
1330tracepoints -- Tracing of program execution without@*
1331 stopping the program
c906108c 1332user-defined -- User-defined commands
c906108c 1333
5d161b24 1334Type "help" followed by a class name for a list of
c906108c 1335commands in that class.
5d161b24 1336Type "help" followed by command name for full
c906108c
SS
1337documentation.
1338Command name abbreviations are allowed if unambiguous.
1339(@value{GDBP})
1340@end smallexample
96a2c332 1341@c the above line break eliminates huge line overfull...
c906108c
SS
1342
1343@item help @var{class}
1344Using one of the general help classes as an argument, you can get a
1345list of the individual commands in that class. For example, here is the
1346help display for the class @code{status}:
1347
1348@smallexample
1349(@value{GDBP}) help status
1350Status inquiries.
1351
1352List of commands:
1353
1354@c Line break in "show" line falsifies real output, but needed
1355@c to fit in smallbook page size.
2df3850c
JM
1356info -- Generic command for showing things
1357 about the program being debugged
1358show -- Generic command for showing things
1359 about the debugger
c906108c 1360
5d161b24 1361Type "help" followed by command name for full
c906108c
SS
1362documentation.
1363Command name abbreviations are allowed if unambiguous.
1364(@value{GDBP})
1365@end smallexample
1366
1367@item help @var{command}
1368With a command name as @code{help} argument, @value{GDBN} displays a
1369short paragraph on how to use that command.
1370
6837a0a2
DB
1371@kindex apropos
1372@item apropos @var{args}
1373The @code{apropos @var{args}} command searches through all of the @value{GDBN}
1374commands, and their documentation, for the regular expression specified in
1375@var{args}. It prints out all matches found. For example:
1376
1377@smallexample
1378apropos reload
1379@end smallexample
1380
1381@noindent results in:
1382
1383@smallexample
6d2ebf8b
SS
1384@c @group
1385set symbol-reloading -- Set dynamic symbol table reloading
1386 multiple times in one run
1387show symbol-reloading -- Show dynamic symbol table reloading
1388 multiple times in one run
1389@c @end group
6837a0a2
DB
1390@end smallexample
1391
c906108c
SS
1392@kindex complete
1393@item complete @var{args}
1394The @code{complete @var{args}} command lists all the possible completions
1395for the beginning of a command. Use @var{args} to specify the beginning of the
1396command you want completed. For example:
1397
1398@smallexample
1399complete i
1400@end smallexample
1401
1402@noindent results in:
1403
1404@smallexample
1405@group
2df3850c
JM
1406if
1407ignore
c906108c
SS
1408info
1409inspect
c906108c
SS
1410@end group
1411@end smallexample
1412
1413@noindent This is intended for use by @sc{gnu} Emacs.
1414@end table
1415
1416In addition to @code{help}, you can use the @value{GDBN} commands @code{info}
1417and @code{show} to inquire about the state of your program, or the state
1418of @value{GDBN} itself. Each command supports many topics of inquiry; this
1419manual introduces each of them in the appropriate context. The listings
1420under @code{info} and under @code{show} in the Index point to
1421all the sub-commands. @xref{Index}.
1422
1423@c @group
1424@table @code
1425@kindex info
1426@kindex i
1427@item info
1428This command (abbreviated @code{i}) is for describing the state of your
1429program. For example, you can list the arguments given to your program
1430with @code{info args}, list the registers currently in use with @code{info
1431registers}, or list the breakpoints you have set with @code{info breakpoints}.
1432You can get a complete list of the @code{info} sub-commands with
1433@w{@code{help info}}.
1434
1435@kindex set
1436@item set
5d161b24 1437You can assign the result of an expression to an environment variable with
c906108c
SS
1438@code{set}. For example, you can set the @value{GDBN} prompt to a $-sign with
1439@code{set prompt $}.
1440
1441@kindex show
1442@item show
5d161b24 1443In contrast to @code{info}, @code{show} is for describing the state of
c906108c
SS
1444@value{GDBN} itself.
1445You can change most of the things you can @code{show}, by using the
1446related command @code{set}; for example, you can control what number
1447system is used for displays with @code{set radix}, or simply inquire
1448which is currently in use with @code{show radix}.
1449
1450@kindex info set
1451To display all the settable parameters and their current
1452values, you can use @code{show} with no arguments; you may also use
1453@code{info set}. Both commands produce the same display.
1454@c FIXME: "info set" violates the rule that "info" is for state of
1455@c FIXME...program. Ck w/ GNU: "info set" to be called something else,
1456@c FIXME...or change desc of rule---eg "state of prog and debugging session"?
1457@end table
1458@c @end group
1459
1460Here are three miscellaneous @code{show} subcommands, all of which are
1461exceptional in lacking corresponding @code{set} commands:
1462
1463@table @code
1464@kindex show version
1465@cindex version number
1466@item show version
1467Show what version of @value{GDBN} is running. You should include this
2df3850c
JM
1468information in @value{GDBN} bug-reports. If multiple versions of
1469@value{GDBN} are in use at your site, you may need to determine which
1470version of @value{GDBN} you are running; as @value{GDBN} evolves, new
1471commands are introduced, and old ones may wither away. Also, many
1472system vendors ship variant versions of @value{GDBN}, and there are
96a2c332 1473variant versions of @value{GDBN} in @sc{gnu}/Linux distributions as well.
2df3850c
JM
1474The version number is the same as the one announced when you start
1475@value{GDBN}.
c906108c
SS
1476
1477@kindex show copying
1478@item show copying
1479Display information about permission for copying @value{GDBN}.
1480
1481@kindex show warranty
1482@item show warranty
2df3850c 1483Display the @sc{gnu} ``NO WARRANTY'' statement, or a warranty,
96a2c332 1484if your version of @value{GDBN} comes with one.
2df3850c 1485
c906108c
SS
1486@end table
1487
6d2ebf8b 1488@node Running
c906108c
SS
1489@chapter Running Programs Under @value{GDBN}
1490
1491When you run a program under @value{GDBN}, you must first generate
1492debugging information when you compile it.
7a292a7a
SS
1493
1494You may start @value{GDBN} with its arguments, if any, in an environment
1495of your choice. If you are doing native debugging, you may redirect
1496your program's input and output, debug an already running process, or
1497kill a child process.
c906108c
SS
1498
1499@menu
1500* Compilation:: Compiling for debugging
1501* Starting:: Starting your program
c906108c
SS
1502* Arguments:: Your program's arguments
1503* Environment:: Your program's environment
c906108c
SS
1504
1505* Working Directory:: Your program's working directory
1506* Input/Output:: Your program's input and output
1507* Attach:: Debugging an already-running process
1508* Kill Process:: Killing the child process
c906108c
SS
1509
1510* Threads:: Debugging programs with multiple threads
1511* Processes:: Debugging programs with multiple processes
1512@end menu
1513
6d2ebf8b 1514@node Compilation
c906108c
SS
1515@section Compiling for debugging
1516
1517In order to debug a program effectively, you need to generate
1518debugging information when you compile it. This debugging information
1519is stored in the object file; it describes the data type of each
1520variable or function and the correspondence between source line numbers
1521and addresses in the executable code.
1522
1523To request debugging information, specify the @samp{-g} option when you run
1524the compiler.
1525
1526Many C compilers are unable to handle the @samp{-g} and @samp{-O}
1527options together. Using those compilers, you cannot generate optimized
1528executables containing debugging information.
1529
53a5351d
JM
1530@value{NGCC}, the @sc{gnu} C compiler, supports @samp{-g} with or
1531without @samp{-O}, making it possible to debug optimized code. We
1532recommend that you @emph{always} use @samp{-g} whenever you compile a
1533program. You may think your program is correct, but there is no sense
1534in pushing your luck.
c906108c
SS
1535
1536@cindex optimized code, debugging
1537@cindex debugging optimized code
1538When you debug a program compiled with @samp{-g -O}, remember that the
1539optimizer is rearranging your code; the debugger shows you what is
1540really there. Do not be too surprised when the execution path does not
1541exactly match your source file! An extreme example: if you define a
1542variable, but never use it, @value{GDBN} never sees that
1543variable---because the compiler optimizes it out of existence.
1544
1545Some things do not work as well with @samp{-g -O} as with just
1546@samp{-g}, particularly on machines with instruction scheduling. If in
1547doubt, recompile with @samp{-g} alone, and if this fixes the problem,
1548please report it to us as a bug (including a test case!).
1549
1550Older versions of the @sc{gnu} C compiler permitted a variant option
1551@w{@samp{-gg}} for debugging information. @value{GDBN} no longer supports this
1552format; if your @sc{gnu} C compiler has this option, do not use it.
1553
1554@need 2000
6d2ebf8b 1555@node Starting
c906108c
SS
1556@section Starting your program
1557@cindex starting
1558@cindex running
1559
1560@table @code
1561@kindex run
1562@item run
1563@itemx r
7a292a7a
SS
1564Use the @code{run} command to start your program under @value{GDBN}.
1565You must first specify the program name (except on VxWorks) with an
1566argument to @value{GDBN} (@pxref{Invocation, ,Getting In and Out of
1567@value{GDBN}}), or by using the @code{file} or @code{exec-file} command
1568(@pxref{Files, ,Commands to specify files}).
c906108c
SS
1569
1570@end table
1571
c906108c
SS
1572If you are running your program in an execution environment that
1573supports processes, @code{run} creates an inferior process and makes
1574that process run your program. (In environments without processes,
1575@code{run} jumps to the start of your program.)
1576
1577The execution of a program is affected by certain information it
1578receives from its superior. @value{GDBN} provides ways to specify this
1579information, which you must do @emph{before} starting your program. (You
1580can change it after starting your program, but such changes only affect
1581your program the next time you start it.) This information may be
1582divided into four categories:
1583
1584@table @asis
1585@item The @emph{arguments.}
1586Specify the arguments to give your program as the arguments of the
1587@code{run} command. If a shell is available on your target, the shell
1588is used to pass the arguments, so that you may use normal conventions
1589(such as wildcard expansion or variable substitution) in describing
1590the arguments.
1591In Unix systems, you can control which shell is used with the
1592@code{SHELL} environment variable.
1593@xref{Arguments, ,Your program's arguments}.
1594
1595@item The @emph{environment.}
1596Your program normally inherits its environment from @value{GDBN}, but you can
1597use the @value{GDBN} commands @code{set environment} and @code{unset
1598environment} to change parts of the environment that affect
1599your program. @xref{Environment, ,Your program's environment}.
1600
1601@item The @emph{working directory.}
1602Your program inherits its working directory from @value{GDBN}. You can set
1603the @value{GDBN} working directory with the @code{cd} command in @value{GDBN}.
1604@xref{Working Directory, ,Your program's working directory}.
1605
1606@item The @emph{standard input and output.}
1607Your program normally uses the same device for standard input and
1608standard output as @value{GDBN} is using. You can redirect input and output
1609in the @code{run} command line, or you can use the @code{tty} command to
1610set a different device for your program.
1611@xref{Input/Output, ,Your program's input and output}.
1612
1613@cindex pipes
1614@emph{Warning:} While input and output redirection work, you cannot use
1615pipes to pass the output of the program you are debugging to another
1616program; if you attempt this, @value{GDBN} is likely to wind up debugging the
1617wrong program.
1618@end table
c906108c
SS
1619
1620When you issue the @code{run} command, your program begins to execute
1621immediately. @xref{Stopping, ,Stopping and continuing}, for discussion
1622of how to arrange for your program to stop. Once your program has
1623stopped, you may call functions in your program, using the @code{print}
1624or @code{call} commands. @xref{Data, ,Examining Data}.
1625
1626If the modification time of your symbol file has changed since the last
1627time @value{GDBN} read its symbols, @value{GDBN} discards its symbol
1628table, and reads it again. When it does this, @value{GDBN} tries to retain
1629your current breakpoints.
1630
6d2ebf8b 1631@node Arguments
c906108c
SS
1632@section Your program's arguments
1633
1634@cindex arguments (to your program)
1635The arguments to your program can be specified by the arguments of the
5d161b24 1636@code{run} command.
c906108c
SS
1637They are passed to a shell, which expands wildcard characters and
1638performs redirection of I/O, and thence to your program. Your
1639@code{SHELL} environment variable (if it exists) specifies what shell
1640@value{GDBN} uses. If you do not define @code{SHELL}, @value{GDBN} uses
d4f3574e
SS
1641the default shell (@file{/bin/sh} on Unix).
1642
1643On non-Unix systems, the program is usually invoked directly by
1644@value{GDBN}, which emulates I/O redirection via the appropriate system
1645calls, and the wildcard characters are expanded by the startup code of
1646the program, not by the shell.
c906108c
SS
1647
1648@code{run} with no arguments uses the same arguments used by the previous
1649@code{run}, or those set by the @code{set args} command.
1650
1651@kindex set args
1652@table @code
1653@item set args
1654Specify the arguments to be used the next time your program is run. If
1655@code{set args} has no arguments, @code{run} executes your program
1656with no arguments. Once you have run your program with arguments,
1657using @code{set args} before the next @code{run} is the only way to run
1658it again without arguments.
1659
1660@kindex show args
1661@item show args
1662Show the arguments to give your program when it is started.
1663@end table
1664
6d2ebf8b 1665@node Environment
c906108c
SS
1666@section Your program's environment
1667
1668@cindex environment (of your program)
1669The @dfn{environment} consists of a set of environment variables and
1670their values. Environment variables conventionally record such things as
1671your user name, your home directory, your terminal type, and your search
1672path for programs to run. Usually you set up environment variables with
1673the shell and they are inherited by all the other programs you run. When
1674debugging, it can be useful to try running your program with a modified
1675environment without having to start @value{GDBN} over again.
1676
1677@table @code
1678@kindex path
1679@item path @var{directory}
1680Add @var{directory} to the front of the @code{PATH} environment variable
1681(the search path for executables), for both @value{GDBN} and your program.
d4f3574e
SS
1682You may specify several directory names, separated by whitespace or by a
1683system-dependent separator character (@samp{:} on Unix, @samp{;} on
1684MS-DOS and MS-Windows). If @var{directory} is already in the path, it
1685is moved to the front, so it is searched sooner.
c906108c
SS
1686
1687You can use the string @samp{$cwd} to refer to whatever is the current
1688working directory at the time @value{GDBN} searches the path. If you
1689use @samp{.} instead, it refers to the directory where you executed the
1690@code{path} command. @value{GDBN} replaces @samp{.} in the
1691@var{directory} argument (with the current path) before adding
1692@var{directory} to the search path.
1693@c 'path' is explicitly nonrepeatable, but RMS points out it is silly to
1694@c document that, since repeating it would be a no-op.
1695
1696@kindex show paths
1697@item show paths
1698Display the list of search paths for executables (the @code{PATH}
1699environment variable).
1700
1701@kindex show environment
1702@item show environment @r{[}@var{varname}@r{]}
1703Print the value of environment variable @var{varname} to be given to
1704your program when it starts. If you do not supply @var{varname},
1705print the names and values of all environment variables to be given to
1706your program. You can abbreviate @code{environment} as @code{env}.
1707
1708@kindex set environment
53a5351d 1709@item set environment @var{varname} @r{[}=@var{value}@r{]}
c906108c
SS
1710Set environment variable @var{varname} to @var{value}. The value
1711changes for your program only, not for @value{GDBN} itself. @var{value} may
1712be any string; the values of environment variables are just strings, and
1713any interpretation is supplied by your program itself. The @var{value}
1714parameter is optional; if it is eliminated, the variable is set to a
1715null value.
1716@c "any string" here does not include leading, trailing
1717@c blanks. Gnu asks: does anyone care?
1718
1719For example, this command:
1720
1721@example
1722set env USER = foo
1723@end example
1724
1725@noindent
d4f3574e 1726tells the debugged program, when subsequently run, that its user is named
c906108c
SS
1727@samp{foo}. (The spaces around @samp{=} are used for clarity here; they
1728are not actually required.)
1729
1730@kindex unset environment
1731@item unset environment @var{varname}
1732Remove variable @var{varname} from the environment to be passed to your
1733program. This is different from @samp{set env @var{varname} =};
1734@code{unset environment} removes the variable from the environment,
1735rather than assigning it an empty value.
1736@end table
1737
d4f3574e
SS
1738@emph{Warning:} On Unix systems, @value{GDBN} runs your program using
1739the shell indicated
c906108c
SS
1740by your @code{SHELL} environment variable if it exists (or
1741@code{/bin/sh} if not). If your @code{SHELL} variable names a shell
1742that runs an initialization file---such as @file{.cshrc} for C-shell, or
1743@file{.bashrc} for BASH---any variables you set in that file affect
1744your program. You may wish to move setting of environment variables to
1745files that are only run when you sign on, such as @file{.login} or
1746@file{.profile}.
1747
6d2ebf8b 1748@node Working Directory
c906108c
SS
1749@section Your program's working directory
1750
1751@cindex working directory (of your program)
1752Each time you start your program with @code{run}, it inherits its
1753working directory from the current working directory of @value{GDBN}.
1754The @value{GDBN} working directory is initially whatever it inherited
1755from its parent process (typically the shell), but you can specify a new
1756working directory in @value{GDBN} with the @code{cd} command.
1757
1758The @value{GDBN} working directory also serves as a default for the commands
1759that specify files for @value{GDBN} to operate on. @xref{Files, ,Commands to
1760specify files}.
1761
1762@table @code
1763@kindex cd
1764@item cd @var{directory}
1765Set the @value{GDBN} working directory to @var{directory}.
1766
1767@kindex pwd
1768@item pwd
1769Print the @value{GDBN} working directory.
1770@end table
1771
6d2ebf8b 1772@node Input/Output
c906108c
SS
1773@section Your program's input and output
1774
1775@cindex redirection
1776@cindex i/o
1777@cindex terminal
1778By default, the program you run under @value{GDBN} does input and output to
5d161b24 1779the same terminal that @value{GDBN} uses. @value{GDBN} switches the terminal
c906108c
SS
1780to its own terminal modes to interact with you, but it records the terminal
1781modes your program was using and switches back to them when you continue
1782running your program.
1783
1784@table @code
1785@kindex info terminal
1786@item info terminal
1787Displays information recorded by @value{GDBN} about the terminal modes your
1788program is using.
1789@end table
1790
1791You can redirect your program's input and/or output using shell
1792redirection with the @code{run} command. For example,
1793
1794@example
1795run > outfile
1796@end example
1797
1798@noindent
1799starts your program, diverting its output to the file @file{outfile}.
1800
1801@kindex tty
1802@cindex controlling terminal
1803Another way to specify where your program should do input and output is
1804with the @code{tty} command. This command accepts a file name as
1805argument, and causes this file to be the default for future @code{run}
1806commands. It also resets the controlling terminal for the child
1807process, for future @code{run} commands. For example,
1808
1809@example
1810tty /dev/ttyb
1811@end example
1812
1813@noindent
1814directs that processes started with subsequent @code{run} commands
1815default to do input and output on the terminal @file{/dev/ttyb} and have
1816that as their controlling terminal.
1817
1818An explicit redirection in @code{run} overrides the @code{tty} command's
1819effect on the input/output device, but not its effect on the controlling
1820terminal.
1821
1822When you use the @code{tty} command or redirect input in the @code{run}
1823command, only the input @emph{for your program} is affected. The input
1824for @value{GDBN} still comes from your terminal.
1825
6d2ebf8b 1826@node Attach
c906108c
SS
1827@section Debugging an already-running process
1828@kindex attach
1829@cindex attach
1830
1831@table @code
1832@item attach @var{process-id}
1833This command attaches to a running process---one that was started
1834outside @value{GDBN}. (@code{info files} shows your active
1835targets.) The command takes as argument a process ID. The usual way to
1836find out the process-id of a Unix process is with the @code{ps} utility,
1837or with the @samp{jobs -l} shell command.
1838
1839@code{attach} does not repeat if you press @key{RET} a second time after
1840executing the command.
1841@end table
1842
1843To use @code{attach}, your program must be running in an environment
1844which supports processes; for example, @code{attach} does not work for
1845programs on bare-board targets that lack an operating system. You must
1846also have permission to send the process a signal.
1847
1848When you use @code{attach}, the debugger finds the program running in
1849the process first by looking in the current working directory, then (if
1850the program is not found) by using the source file search path
1851(@pxref{Source Path, ,Specifying source directories}). You can also use
1852the @code{file} command to load the program. @xref{Files, ,Commands to
1853Specify Files}.
1854
1855The first thing @value{GDBN} does after arranging to debug the specified
1856process is to stop it. You can examine and modify an attached process
53a5351d
JM
1857with all the @value{GDBN} commands that are ordinarily available when
1858you start processes with @code{run}. You can insert breakpoints; you
1859can step and continue; you can modify storage. If you would rather the
1860process continue running, you may use the @code{continue} command after
c906108c
SS
1861attaching @value{GDBN} to the process.
1862
1863@table @code
1864@kindex detach
1865@item detach
1866When you have finished debugging the attached process, you can use the
1867@code{detach} command to release it from @value{GDBN} control. Detaching
1868the process continues its execution. After the @code{detach} command,
1869that process and @value{GDBN} become completely independent once more, and you
1870are ready to @code{attach} another process or start one with @code{run}.
1871@code{detach} does not repeat if you press @key{RET} again after
1872executing the command.
1873@end table
1874
1875If you exit @value{GDBN} or use the @code{run} command while you have an
1876attached process, you kill that process. By default, @value{GDBN} asks
1877for confirmation if you try to do either of these things; you can
1878control whether or not you need to confirm by using the @code{set
1879confirm} command (@pxref{Messages/Warnings, ,Optional warnings and
1880messages}).
1881
6d2ebf8b 1882@node Kill Process
c906108c 1883@section Killing the child process
c906108c
SS
1884
1885@table @code
1886@kindex kill
1887@item kill
1888Kill the child process in which your program is running under @value{GDBN}.
1889@end table
1890
1891This command is useful if you wish to debug a core dump instead of a
1892running process. @value{GDBN} ignores any core dump file while your program
1893is running.
1894
1895On some operating systems, a program cannot be executed outside @value{GDBN}
1896while you have breakpoints set on it inside @value{GDBN}. You can use the
1897@code{kill} command in this situation to permit running your program
1898outside the debugger.
1899
1900The @code{kill} command is also useful if you wish to recompile and
1901relink your program, since on many systems it is impossible to modify an
1902executable file while it is running in a process. In this case, when you
1903next type @code{run}, @value{GDBN} notices that the file has changed, and
1904reads the symbol table again (while trying to preserve your current
1905breakpoint settings).
1906
6d2ebf8b 1907@node Threads
c906108c 1908@section Debugging programs with multiple threads
c906108c
SS
1909
1910@cindex threads of execution
1911@cindex multiple threads
1912@cindex switching threads
1913In some operating systems, such as HP-UX and Solaris, a single program
1914may have more than one @dfn{thread} of execution. The precise semantics
1915of threads differ from one operating system to another, but in general
1916the threads of a single program are akin to multiple processes---except
1917that they share one address space (that is, they can all examine and
1918modify the same variables). On the other hand, each thread has its own
1919registers and execution stack, and perhaps private memory.
1920
1921@value{GDBN} provides these facilities for debugging multi-thread
1922programs:
1923
1924@itemize @bullet
1925@item automatic notification of new threads
1926@item @samp{thread @var{threadno}}, a command to switch among threads
1927@item @samp{info threads}, a command to inquire about existing threads
5d161b24 1928@item @samp{thread apply [@var{threadno}] [@var{all}] @var{args}},
c906108c
SS
1929a command to apply a command to a list of threads
1930@item thread-specific breakpoints
1931@end itemize
1932
c906108c
SS
1933@quotation
1934@emph{Warning:} These facilities are not yet available on every
1935@value{GDBN} configuration where the operating system supports threads.
1936If your @value{GDBN} does not support threads, these commands have no
1937effect. For example, a system without thread support shows no output
1938from @samp{info threads}, and always rejects the @code{thread} command,
1939like this:
1940
1941@smallexample
1942(@value{GDBP}) info threads
1943(@value{GDBP}) thread 1
1944Thread ID 1 not known. Use the "info threads" command to
1945see the IDs of currently known threads.
1946@end smallexample
1947@c FIXME to implementors: how hard would it be to say "sorry, this GDB
1948@c doesn't support threads"?
1949@end quotation
c906108c
SS
1950
1951@cindex focus of debugging
1952@cindex current thread
1953The @value{GDBN} thread debugging facility allows you to observe all
1954threads while your program runs---but whenever @value{GDBN} takes
1955control, one thread in particular is always the focus of debugging.
1956This thread is called the @dfn{current thread}. Debugging commands show
1957program information from the perspective of the current thread.
1958
c906108c
SS
1959@kindex New @var{systag}
1960@cindex thread identifier (system)
1961@c FIXME-implementors!! It would be more helpful if the [New...] message
1962@c included GDB's numeric thread handle, so you could just go to that
1963@c thread without first checking `info threads'.
1964Whenever @value{GDBN} detects a new thread in your program, it displays
1965the target system's identification for the thread with a message in the
1966form @samp{[New @var{systag}]}. @var{systag} is a thread identifier
1967whose form varies depending on the particular system. For example, on
1968LynxOS, you might see
1969
1970@example
1971[New process 35 thread 27]
1972@end example
1973
1974@noindent
1975when @value{GDBN} notices a new thread. In contrast, on an SGI system,
1976the @var{systag} is simply something like @samp{process 368}, with no
1977further qualifier.
1978
1979@c FIXME!! (1) Does the [New...] message appear even for the very first
1980@c thread of a program, or does it only appear for the
1981@c second---i.e., when it becomes obvious we have a multithread
1982@c program?
1983@c (2) *Is* there necessarily a first thread always? Or do some
1984@c multithread systems permit starting a program with multiple
5d161b24 1985@c threads ab initio?
c906108c
SS
1986
1987@cindex thread number
1988@cindex thread identifier (GDB)
1989For debugging purposes, @value{GDBN} associates its own thread
1990number---always a single integer---with each thread in your program.
1991
1992@table @code
1993@kindex info threads
1994@item info threads
1995Display a summary of all threads currently in your
1996program. @value{GDBN} displays for each thread (in this order):
1997
1998@enumerate
1999@item the thread number assigned by @value{GDBN}
2000
2001@item the target system's thread identifier (@var{systag})
2002
2003@item the current stack frame summary for that thread
2004@end enumerate
2005
2006@noindent
2007An asterisk @samp{*} to the left of the @value{GDBN} thread number
2008indicates the current thread.
2009
5d161b24 2010For example,
c906108c
SS
2011@end table
2012@c end table here to get a little more width for example
2013
2014@smallexample
2015(@value{GDBP}) info threads
2016 3 process 35 thread 27 0x34e5 in sigpause ()
2017 2 process 35 thread 23 0x34e5 in sigpause ()
2018* 1 process 35 thread 13 main (argc=1, argv=0x7ffffff8)
2019 at threadtest.c:68
2020@end smallexample
53a5351d
JM
2021
2022On HP-UX systems:
c906108c
SS
2023
2024@cindex thread number
2025@cindex thread identifier (GDB)
2026For debugging purposes, @value{GDBN} associates its own thread
2027number---a small integer assigned in thread-creation order---with each
2028thread in your program.
2029
2030@kindex New @var{systag}
2031@cindex thread identifier (system)
2032@c FIXME-implementors!! It would be more helpful if the [New...] message
2033@c included GDB's numeric thread handle, so you could just go to that
2034@c thread without first checking `info threads'.
2035Whenever @value{GDBN} detects a new thread in your program, it displays
2036both @value{GDBN}'s thread number and the target system's identification for the thread with a message in the
2037form @samp{[New @var{systag}]}. @var{systag} is a thread identifier
2038whose form varies depending on the particular system. For example, on
2039HP-UX, you see
2040
2041@example
2042[New thread 2 (system thread 26594)]
2043@end example
2044
2045@noindent
5d161b24 2046when @value{GDBN} notices a new thread.
c906108c
SS
2047
2048@table @code
2049@kindex info threads
2050@item info threads
2051Display a summary of all threads currently in your
2052program. @value{GDBN} displays for each thread (in this order):
2053
2054@enumerate
2055@item the thread number assigned by @value{GDBN}
2056
2057@item the target system's thread identifier (@var{systag})
2058
2059@item the current stack frame summary for that thread
2060@end enumerate
2061
2062@noindent
2063An asterisk @samp{*} to the left of the @value{GDBN} thread number
2064indicates the current thread.
2065
5d161b24 2066For example,
c906108c
SS
2067@end table
2068@c end table here to get a little more width for example
2069
2070@example
2071(@value{GDBP}) info threads
6d2ebf8b
SS
2072 * 3 system thread 26607 worker (wptr=0x7b09c318 "@@") \@*
2073 at quicksort.c:137
2074 2 system thread 26606 0x7b0030d8 in __ksleep () \@*
2075 from /usr/lib/libc.2
2076 1 system thread 27905 0x7b003498 in _brk () \@*
2077 from /usr/lib/libc.2
c906108c 2078@end example
c906108c
SS
2079
2080@table @code
2081@kindex thread @var{threadno}
2082@item thread @var{threadno}
2083Make thread number @var{threadno} the current thread. The command
2084argument @var{threadno} is the internal @value{GDBN} thread number, as
2085shown in the first field of the @samp{info threads} display.
2086@value{GDBN} responds by displaying the system identifier of the thread
2087you selected, and its current stack frame summary:
2088
2089@smallexample
2090@c FIXME!! This example made up; find a @value{GDBN} w/threads and get real one
2091(@value{GDBP}) thread 2
c906108c 2092[Switching to process 35 thread 23]
c906108c
SS
20930x34e5 in sigpause ()
2094@end smallexample
2095
2096@noindent
2097As with the @samp{[New @dots{}]} message, the form of the text after
2098@samp{Switching to} depends on your system's conventions for identifying
5d161b24 2099threads.
c906108c
SS
2100
2101@kindex thread apply
2102@item thread apply [@var{threadno}] [@var{all}] @var{args}
2103The @code{thread apply} command allows you to apply a command to one or
2104more threads. Specify the numbers of the threads that you want affected
2105with the command argument @var{threadno}. @var{threadno} is the internal
2106@value{GDBN} thread number, as shown in the first field of the @samp{info
5d161b24
DB
2107threads} display. To apply a command to all threads, use
2108@code{thread apply all} @var{args}.
c906108c
SS
2109@end table
2110
2111@cindex automatic thread selection
2112@cindex switching threads automatically
2113@cindex threads, automatic switching
2114Whenever @value{GDBN} stops your program, due to a breakpoint or a
2115signal, it automatically selects the thread where that breakpoint or
2116signal happened. @value{GDBN} alerts you to the context switch with a
2117message of the form @samp{[Switching to @var{systag}]} to identify the
2118thread.
2119
2120@xref{Thread Stops,,Stopping and starting multi-thread programs}, for
2121more information about how @value{GDBN} behaves when you stop and start
2122programs with multiple threads.
2123
2124@xref{Set Watchpoints,,Setting watchpoints}, for information about
2125watchpoints in programs with multiple threads.
c906108c 2126
6d2ebf8b 2127@node Processes
c906108c
SS
2128@section Debugging programs with multiple processes
2129
2130@cindex fork, debugging programs which call
2131@cindex multiple processes
2132@cindex processes, multiple
53a5351d
JM
2133On most systems, @value{GDBN} has no special support for debugging
2134programs which create additional processes using the @code{fork}
2135function. When a program forks, @value{GDBN} will continue to debug the
2136parent process and the child process will run unimpeded. If you have
2137set a breakpoint in any code which the child then executes, the child
2138will get a @code{SIGTRAP} signal which (unless it catches the signal)
2139will cause it to terminate.
c906108c
SS
2140
2141However, if you want to debug the child process there is a workaround
2142which isn't too painful. Put a call to @code{sleep} in the code which
2143the child process executes after the fork. It may be useful to sleep
2144only if a certain environment variable is set, or a certain file exists,
2145so that the delay need not occur when you don't want to run @value{GDBN}
2146on the child. While the child is sleeping, use the @code{ps} program to
2147get its process ID. Then tell @value{GDBN} (a new invocation of
2148@value{GDBN} if you are also debugging the parent process) to attach to
d4f3574e 2149the child process (@pxref{Attach}). From that point on you can debug
c906108c 2150the child process just like any other process which you attached to.
c906108c 2151
53a5351d
JM
2152On HP-UX (11.x and later only?), @value{GDBN} provides support for
2153debugging programs that create additional processes using the
2154@code{fork} or @code{vfork} function.
c906108c
SS
2155
2156By default, when a program forks, @value{GDBN} will continue to debug
2157the parent process and the child process will run unimpeded.
2158
2159If you want to follow the child process instead of the parent process,
2160use the command @w{@code{set follow-fork-mode}}.
2161
2162@table @code
2163@kindex set follow-fork-mode
2164@item set follow-fork-mode @var{mode}
2165Set the debugger response to a program call of @code{fork} or
2166@code{vfork}. A call to @code{fork} or @code{vfork} creates a new
2167process. The @var{mode} can be:
2168
2169@table @code
2170@item parent
2171The original process is debugged after a fork. The child process runs
2df3850c 2172unimpeded. This is the default.
c906108c
SS
2173
2174@item child
2175The new process is debugged after a fork. The parent process runs
2176unimpeded.
2177
2178@item ask
2179The debugger will ask for one of the above choices.
2180@end table
2181
2182@item show follow-fork-mode
2df3850c 2183Display the current debugger response to a @code{fork} or @code{vfork} call.
c906108c
SS
2184@end table
2185
2186If you ask to debug a child process and a @code{vfork} is followed by an
2187@code{exec}, @value{GDBN} executes the new target up to the first
2188breakpoint in the new target. If you have a breakpoint set on
2189@code{main} in your original program, the breakpoint will also be set on
2190the child process's @code{main}.
2191
2192When a child process is spawned by @code{vfork}, you cannot debug the
2193child or parent until an @code{exec} call completes.
2194
2195If you issue a @code{run} command to @value{GDBN} after an @code{exec}
2196call executes, the new target restarts. To restart the parent process,
2197use the @code{file} command with the parent executable name as its
2198argument.
2199
2200You can use the @code{catch} command to make @value{GDBN} stop whenever
2201a @code{fork}, @code{vfork}, or @code{exec} call is made. @xref{Set
2202Catchpoints, ,Setting catchpoints}.
c906108c 2203
6d2ebf8b 2204@node Stopping
c906108c
SS
2205@chapter Stopping and Continuing
2206
2207The principal purposes of using a debugger are so that you can stop your
2208program before it terminates; or so that, if your program runs into
2209trouble, you can investigate and find out why.
2210
7a292a7a
SS
2211Inside @value{GDBN}, your program may stop for any of several reasons,
2212such as a signal, a breakpoint, or reaching a new line after a
2213@value{GDBN} command such as @code{step}. You may then examine and
2214change variables, set new breakpoints or remove old ones, and then
2215continue execution. Usually, the messages shown by @value{GDBN} provide
2216ample explanation of the status of your program---but you can also
2217explicitly request this information at any time.
c906108c
SS
2218
2219@table @code
2220@kindex info program
2221@item info program
2222Display information about the status of your program: whether it is
7a292a7a 2223running or not, what process it is, and why it stopped.
c906108c
SS
2224@end table
2225
2226@menu
2227* Breakpoints:: Breakpoints, watchpoints, and catchpoints
2228* Continuing and Stepping:: Resuming execution
c906108c 2229* Signals:: Signals
c906108c 2230* Thread Stops:: Stopping and starting multi-thread programs
c906108c
SS
2231@end menu
2232
6d2ebf8b 2233@node Breakpoints
c906108c
SS
2234@section Breakpoints, watchpoints, and catchpoints
2235
2236@cindex breakpoints
2237A @dfn{breakpoint} makes your program stop whenever a certain point in
2238the program is reached. For each breakpoint, you can add conditions to
2239control in finer detail whether your program stops. You can set
2240breakpoints with the @code{break} command and its variants (@pxref{Set
2241Breaks, ,Setting breakpoints}), to specify the place where your program
2242should stop by line number, function name or exact address in the
2243program.
2244
2245In HP-UX, SunOS 4.x, SVR4, and Alpha OSF/1 configurations, you can set
2246breakpoints in shared libraries before the executable is run. There is
2247a minor limitation on HP-UX systems: you must wait until the executable
2248is run in order to set breakpoints in shared library routines that are
2249not called directly by the program (for example, routines that are
2250arguments in a @code{pthread_create} call).
2251
2252@cindex watchpoints
2253@cindex memory tracing
2254@cindex breakpoint on memory address
2255@cindex breakpoint on variable modification
2256A @dfn{watchpoint} is a special breakpoint that stops your program
2257when the value of an expression changes. You must use a different
2258command to set watchpoints (@pxref{Set Watchpoints, ,Setting
2259watchpoints}), but aside from that, you can manage a watchpoint like
2260any other breakpoint: you enable, disable, and delete both breakpoints
2261and watchpoints using the same commands.
2262
2263You can arrange to have values from your program displayed automatically
2264whenever @value{GDBN} stops at a breakpoint. @xref{Auto Display,,
2265Automatic display}.
2266
2267@cindex catchpoints
2268@cindex breakpoint on events
2269A @dfn{catchpoint} is another special breakpoint that stops your program
2270when a certain kind of event occurs, such as the throwing of a C++
2271exception or the loading of a library. As with watchpoints, you use a
2272different command to set a catchpoint (@pxref{Set Catchpoints, ,Setting
2273catchpoints}), but aside from that, you can manage a catchpoint like any
2274other breakpoint. (To stop when your program receives a signal, use the
d4f3574e 2275@code{handle} command; see @ref{Signals, ,Signals}.)
c906108c
SS
2276
2277@cindex breakpoint numbers
2278@cindex numbers for breakpoints
2279@value{GDBN} assigns a number to each breakpoint, watchpoint, or
2280catchpoint when you create it; these numbers are successive integers
2281starting with one. In many of the commands for controlling various
2282features of breakpoints you use the breakpoint number to say which
2283breakpoint you want to change. Each breakpoint may be @dfn{enabled} or
2284@dfn{disabled}; if disabled, it has no effect on your program until you
2285enable it again.
2286
c5394b80
JM
2287@cindex breakpoint ranges
2288@cindex ranges of breakpoints
2289Some @value{GDBN} commands accept a range of breakpoints on which to
2290operate. A breakpoint range is either a single breakpoint number, like
2291@samp{5}, or two such numbers, in increasing order, separated by a
2292hyphen, like @samp{5-7}. When a breakpoint range is given to a command,
2293all breakpoint in that range are operated on.
2294
c906108c
SS
2295@menu
2296* Set Breaks:: Setting breakpoints
2297* Set Watchpoints:: Setting watchpoints
2298* Set Catchpoints:: Setting catchpoints
2299* Delete Breaks:: Deleting breakpoints
2300* Disabling:: Disabling breakpoints
2301* Conditions:: Break conditions
2302* Break Commands:: Breakpoint command lists
c906108c 2303* Breakpoint Menus:: Breakpoint menus
d4f3574e 2304* Error in Breakpoints:: ``Cannot insert breakpoints''
c906108c
SS
2305@end menu
2306
6d2ebf8b 2307@node Set Breaks
c906108c
SS
2308@subsection Setting breakpoints
2309
5d161b24 2310@c FIXME LMB what does GDB do if no code on line of breakpt?
c906108c
SS
2311@c consider in particular declaration with/without initialization.
2312@c
2313@c FIXME 2 is there stuff on this already? break at fun start, already init?
2314
2315@kindex break
2316@kindex b
2317@kindex $bpnum
2318@cindex latest breakpoint
2319Breakpoints are set with the @code{break} command (abbreviated
5d161b24 2320@code{b}). The debugger convenience variable @samp{$bpnum} records the
c906108c
SS
2321number of the breakpoints you've set most recently; see @ref{Convenience
2322Vars,, Convenience variables}, for a discussion of what you can do with
2323convenience variables.
2324
2325You have several ways to say where the breakpoint should go.
2326
2327@table @code
2328@item break @var{function}
5d161b24 2329Set a breakpoint at entry to function @var{function}.
c906108c
SS
2330When using source languages that permit overloading of symbols, such as
2331C++, @var{function} may refer to more than one possible place to break.
2332@xref{Breakpoint Menus,,Breakpoint menus}, for a discussion of that situation.
c906108c
SS
2333
2334@item break +@var{offset}
2335@itemx break -@var{offset}
2336Set a breakpoint some number of lines forward or back from the position
d4f3574e 2337at which execution stopped in the currently selected @dfn{stack frame}.
2df3850c 2338(@xref{Frames, ,Frames}, for a description of stack frames.)
c906108c
SS
2339
2340@item break @var{linenum}
2341Set a breakpoint at line @var{linenum} in the current source file.
d4f3574e
SS
2342The current source file is the last file whose source text was printed.
2343The breakpoint will stop your program just before it executes any of the
c906108c
SS
2344code on that line.
2345
2346@item break @var{filename}:@var{linenum}
2347Set a breakpoint at line @var{linenum} in source file @var{filename}.
2348
2349@item break @var{filename}:@var{function}
2350Set a breakpoint at entry to function @var{function} found in file
2351@var{filename}. Specifying a file name as well as a function name is
2352superfluous except when multiple files contain similarly named
2353functions.
2354
2355@item break *@var{address}
2356Set a breakpoint at address @var{address}. You can use this to set
2357breakpoints in parts of your program which do not have debugging
2358information or source files.
2359
2360@item break
2361When called without any arguments, @code{break} sets a breakpoint at
2362the next instruction to be executed in the selected stack frame
2363(@pxref{Stack, ,Examining the Stack}). In any selected frame but the
2364innermost, this makes your program stop as soon as control
2365returns to that frame. This is similar to the effect of a
2366@code{finish} command in the frame inside the selected frame---except
2367that @code{finish} does not leave an active breakpoint. If you use
2368@code{break} without an argument in the innermost frame, @value{GDBN} stops
2369the next time it reaches the current location; this may be useful
2370inside loops.
2371
2372@value{GDBN} normally ignores breakpoints when it resumes execution, until at
2373least one instruction has been executed. If it did not do this, you
2374would be unable to proceed past a breakpoint without first disabling the
2375breakpoint. This rule applies whether or not the breakpoint already
2376existed when your program stopped.
2377
2378@item break @dots{} if @var{cond}
2379Set a breakpoint with condition @var{cond}; evaluate the expression
2380@var{cond} each time the breakpoint is reached, and stop only if the
2381value is nonzero---that is, if @var{cond} evaluates as true.
2382@samp{@dots{}} stands for one of the possible arguments described
2383above (or no argument) specifying where to break. @xref{Conditions,
2384,Break conditions}, for more information on breakpoint conditions.
2385
2386@kindex tbreak
2387@item tbreak @var{args}
2388Set a breakpoint enabled only for one stop. @var{args} are the
2389same as for the @code{break} command, and the breakpoint is set in the same
2390way, but the breakpoint is automatically deleted after the first time your
2391program stops there. @xref{Disabling, ,Disabling breakpoints}.
2392
c906108c
SS
2393@kindex hbreak
2394@item hbreak @var{args}
d4f3574e
SS
2395Set a hardware-assisted breakpoint. @var{args} are the same as for the
2396@code{break} command and the breakpoint is set in the same way, but the
c906108c
SS
2397breakpoint requires hardware support and some target hardware may not
2398have this support. The main purpose of this is EPROM/ROM code
d4f3574e
SS
2399debugging, so you can set a breakpoint at an instruction without
2400changing the instruction. This can be used with the new trap-generation
2401provided by SPARClite DSU and some x86-based targets. These targets
2402will generate traps when a program accesses some data or instruction
2403address that is assigned to the debug registers. However the hardware
2404breakpoint registers can take a limited number of breakpoints. For
2405example, on the DSU, only two data breakpoints can be set at a time, and
2406@value{GDBN} will reject this command if more than two are used. Delete
2407or disable unused hardware breakpoints before setting new ones
2408(@pxref{Disabling, ,Disabling}). @xref{Conditions, ,Break conditions}.
c906108c
SS
2409
2410@kindex thbreak
2411@item thbreak @var{args}
2412Set a hardware-assisted breakpoint enabled only for one stop. @var{args}
2413are the same as for the @code{hbreak} command and the breakpoint is set in
5d161b24 2414the same way. However, like the @code{tbreak} command,
c906108c
SS
2415the breakpoint is automatically deleted after the
2416first time your program stops there. Also, like the @code{hbreak}
5d161b24
DB
2417command, the breakpoint requires hardware support and some target hardware
2418may not have this support. @xref{Disabling, ,Disabling breakpoints}.
d4f3574e 2419See also @ref{Conditions, ,Break conditions}.
c906108c
SS
2420
2421@kindex rbreak
2422@cindex regular expression
2423@item rbreak @var{regex}
c906108c 2424Set breakpoints on all functions matching the regular expression
11cf8741
JM
2425@var{regex}. This command sets an unconditional breakpoint on all
2426matches, printing a list of all breakpoints it set. Once these
2427breakpoints are set, they are treated just like the breakpoints set with
2428the @code{break} command. You can delete them, disable them, or make
2429them conditional the same way as any other breakpoint.
2430
2431The syntax of the regular expression is the standard one used with tools
2432like @file{grep}. Note that this is different from the syntax used by
2433shells, so for instance @code{foo*} matches all functions that include
2434an @code{fo} followed by zero or more @code{o}s. There is an implicit
2435@code{.*} leading and trailing the regular expression you supply, so to
2436match only functions that begin with @code{foo}, use @code{^foo}.
c906108c 2437
c906108c
SS
2438When debugging C++ programs, @code{rbreak} is useful for setting
2439breakpoints on overloaded functions that are not members of any special
2440classes.
c906108c
SS
2441
2442@kindex info breakpoints
2443@cindex @code{$_} and @code{info breakpoints}
2444@item info breakpoints @r{[}@var{n}@r{]}
2445@itemx info break @r{[}@var{n}@r{]}
2446@itemx info watchpoints @r{[}@var{n}@r{]}
2447Print a table of all breakpoints, watchpoints, and catchpoints set and
2448not deleted, with the following columns for each breakpoint:
2449
2450@table @emph
2451@item Breakpoint Numbers
2452@item Type
2453Breakpoint, watchpoint, or catchpoint.
2454@item Disposition
2455Whether the breakpoint is marked to be disabled or deleted when hit.
2456@item Enabled or Disabled
2457Enabled breakpoints are marked with @samp{y}. @samp{n} marks breakpoints
2458that are not enabled.
2459@item Address
2df3850c 2460Where the breakpoint is in your program, as a memory address.
c906108c
SS
2461@item What
2462Where the breakpoint is in the source for your program, as a file and
2463line number.
2464@end table
2465
2466@noindent
2467If a breakpoint is conditional, @code{info break} shows the condition on
2468the line following the affected breakpoint; breakpoint commands, if any,
2469are listed after that.
2470
2471@noindent
2472@code{info break} with a breakpoint
2473number @var{n} as argument lists only that breakpoint. The
2474convenience variable @code{$_} and the default examining-address for
2475the @code{x} command are set to the address of the last breakpoint
5d161b24 2476listed (@pxref{Memory, ,Examining memory}).
c906108c
SS
2477
2478@noindent
2479@code{info break} displays a count of the number of times the breakpoint
2480has been hit. This is especially useful in conjunction with the
2481@code{ignore} command. You can ignore a large number of breakpoint
2482hits, look at the breakpoint info to see how many times the breakpoint
2483was hit, and then run again, ignoring one less than that number. This
2484will get you quickly to the last hit of that breakpoint.
2485@end table
2486
2487@value{GDBN} allows you to set any number of breakpoints at the same place in
2488your program. There is nothing silly or meaningless about this. When
2489the breakpoints are conditional, this is even useful
2490(@pxref{Conditions, ,Break conditions}).
2491
2492@cindex negative breakpoint numbers
2493@cindex internal @value{GDBN} breakpoints
2494@value{GDBN} itself sometimes sets breakpoints in your program for special
2495purposes, such as proper handling of @code{longjmp} (in C programs).
2496These internal breakpoints are assigned negative numbers, starting with
2497@code{-1}; @samp{info breakpoints} does not display them.
2498
2499You can see these breakpoints with the @value{GDBN} maintenance command
2500@samp{maint info breakpoints}.
2501
2502@table @code
2503@kindex maint info breakpoints
2504@item maint info breakpoints
2505Using the same format as @samp{info breakpoints}, display both the
2506breakpoints you've set explicitly, and those @value{GDBN} is using for
2507internal purposes. Internal breakpoints are shown with negative
2508breakpoint numbers. The type column identifies what kind of breakpoint
2509is shown:
2510
2511@table @code
2512@item breakpoint
2513Normal, explicitly set breakpoint.
2514
2515@item watchpoint
2516Normal, explicitly set watchpoint.
2517
2518@item longjmp
2519Internal breakpoint, used to handle correctly stepping through
2520@code{longjmp} calls.
2521
2522@item longjmp resume
2523Internal breakpoint at the target of a @code{longjmp}.
2524
2525@item until
2526Temporary internal breakpoint used by the @value{GDBN} @code{until} command.
2527
2528@item finish
2529Temporary internal breakpoint used by the @value{GDBN} @code{finish} command.
2530
c906108c
SS
2531@item shlib events
2532Shared library events.
53a5351d 2533
c906108c 2534@end table
53a5351d 2535
c906108c
SS
2536@end table
2537
2538
6d2ebf8b 2539@node Set Watchpoints
c906108c
SS
2540@subsection Setting watchpoints
2541
2542@cindex setting watchpoints
2543@cindex software watchpoints
2544@cindex hardware watchpoints
2545You can use a watchpoint to stop execution whenever the value of an
2546expression changes, without having to predict a particular place where
2547this may happen.
2548
2549Depending on your system, watchpoints may be implemented in software or
2df3850c 2550hardware. @value{GDBN} does software watchpointing by single-stepping your
c906108c
SS
2551program and testing the variable's value each time, which is hundreds of
2552times slower than normal execution. (But this may still be worth it, to
2553catch errors where you have no clue what part of your program is the
2554culprit.)
2555
d4f3574e 2556On some systems, such as HP-UX, Linux and some other x86-based targets,
2df3850c 2557@value{GDBN} includes support for
c906108c
SS
2558hardware watchpoints, which do not slow down the running of your
2559program.
2560
2561@table @code
2562@kindex watch
2563@item watch @var{expr}
2564Set a watchpoint for an expression. @value{GDBN} will break when @var{expr}
2565is written into by the program and its value changes.
2566
2567@kindex rwatch
2568@item rwatch @var{expr}
2569Set a watchpoint that will break when watch @var{expr} is read by the program.
c906108c
SS
2570
2571@kindex awatch
2572@item awatch @var{expr}
2df3850c 2573Set a watchpoint that will break when @var{expr} is either read or written into
7be570e7 2574by the program.
c906108c
SS
2575
2576@kindex info watchpoints
2577@item info watchpoints
2578This command prints a list of watchpoints, breakpoints, and catchpoints;
2579it is the same as @code{info break}.
2580@end table
2581
2582@value{GDBN} sets a @dfn{hardware watchpoint} if possible. Hardware
2583watchpoints execute very quickly, and the debugger reports a change in
2584value at the exact instruction where the change occurs. If @value{GDBN}
2585cannot set a hardware watchpoint, it sets a software watchpoint, which
2586executes more slowly and reports the change in value at the next
2587statement, not the instruction, after the change occurs.
2588
2589When you issue the @code{watch} command, @value{GDBN} reports
2590
2591@example
2592Hardware watchpoint @var{num}: @var{expr}
2593@end example
2594
2595@noindent
2596if it was able to set a hardware watchpoint.
2597
7be570e7
JM
2598Currently, the @code{awatch} and @code{rwatch} commands can only set
2599hardware watchpoints, because accesses to data that don't change the
2600value of the watched expression cannot be detected without examining
2601every instruction as it is being executed, and @value{GDBN} does not do
2602that currently. If @value{GDBN} finds that it is unable to set a
2603hardware breakpoint with the @code{awatch} or @code{rwatch} command, it
2604will print a message like this:
2605
2606@smallexample
2607Expression cannot be implemented with read/access watchpoint.
2608@end smallexample
2609
2610Sometimes, @value{GDBN} cannot set a hardware watchpoint because the
2611data type of the watched expression is wider than what a hardware
2612watchpoint on the target machine can handle. For example, some systems
2613can only watch regions that are up to 4 bytes wide; on such systems you
2614cannot set hardware watchpoints for an expression that yields a
2615double-precision floating-point number (which is typically 8 bytes
2616wide). As a work-around, it might be possible to break the large region
2617into a series of smaller ones and watch them with separate watchpoints.
2618
2619If you set too many hardware watchpoints, @value{GDBN} might be unable
2620to insert all of them when you resume the execution of your program.
2621Since the precise number of active watchpoints is unknown until such
2622time as the program is about to be resumed, @value{GDBN} might not be
2623able to warn you about this when you set the watchpoints, and the
2624warning will be printed only when the program is resumed:
2625
2626@smallexample
2627Hardware watchpoint @var{num}: Could not insert watchpoint
2628@end smallexample
2629
2630@noindent
2631If this happens, delete or disable some of the watchpoints.
2632
2633The SPARClite DSU will generate traps when a program accesses some data
2634or instruction address that is assigned to the debug registers. For the
2635data addresses, DSU facilitates the @code{watch} command. However the
2636hardware breakpoint registers can only take two data watchpoints, and
2637both watchpoints must be the same kind. For example, you can set two
2638watchpoints with @code{watch} commands, two with @code{rwatch} commands,
2639@strong{or} two with @code{awatch} commands, but you cannot set one
2640watchpoint with one command and the other with a different command.
c906108c
SS
2641@value{GDBN} will reject the command if you try to mix watchpoints.
2642Delete or disable unused watchpoint commands before setting new ones.
2643
2644If you call a function interactively using @code{print} or @code{call},
2df3850c 2645any watchpoints you have set will be inactive until @value{GDBN} reaches another
c906108c
SS
2646kind of breakpoint or the call completes.
2647
7be570e7
JM
2648@value{GDBN} automatically deletes watchpoints that watch local
2649(automatic) variables, or expressions that involve such variables, when
2650they go out of scope, that is, when the execution leaves the block in
2651which these variables were defined. In particular, when the program
2652being debugged terminates, @emph{all} local variables go out of scope,
2653and so only watchpoints that watch global variables remain set. If you
2654rerun the program, you will need to set all such watchpoints again. One
2655way of doing that would be to set a code breakpoint at the entry to the
2656@code{main} function and when it breaks, set all the watchpoints.
2657
c906108c
SS
2658@quotation
2659@cindex watchpoints and threads
2660@cindex threads and watchpoints
c906108c
SS
2661@emph{Warning:} In multi-thread programs, watchpoints have only limited
2662usefulness. With the current watchpoint implementation, @value{GDBN}
2663can only watch the value of an expression @emph{in a single thread}. If
2664you are confident that the expression can only change due to the current
2665thread's activity (and if you are also confident that no other thread
2666can become current), then you can use watchpoints as usual. However,
2667@value{GDBN} may not notice when a non-current thread's activity changes
2668the expression.
53a5351d 2669
d4f3574e 2670@c FIXME: this is almost identical to the previous paragraph.
53a5351d
JM
2671@emph{HP-UX Warning:} In multi-thread programs, software watchpoints
2672have only limited usefulness. If @value{GDBN} creates a software
2673watchpoint, it can only watch the value of an expression @emph{in a
2674single thread}. If you are confident that the expression can only
2675change due to the current thread's activity (and if you are also
2676confident that no other thread can become current), then you can use
2677software watchpoints as usual. However, @value{GDBN} may not notice
2678when a non-current thread's activity changes the expression. (Hardware
2679watchpoints, in contrast, watch an expression in all threads.)
c906108c 2680@end quotation
c906108c 2681
6d2ebf8b 2682@node Set Catchpoints
c906108c 2683@subsection Setting catchpoints
d4f3574e 2684@cindex catchpoints, setting
c906108c
SS
2685@cindex exception handlers
2686@cindex event handling
2687
2688You can use @dfn{catchpoints} to cause the debugger to stop for certain
2689kinds of program events, such as C++ exceptions or the loading of a
2690shared library. Use the @code{catch} command to set a catchpoint.
2691
2692@table @code
2693@kindex catch
2694@item catch @var{event}
2695Stop when @var{event} occurs. @var{event} can be any of the following:
2696@table @code
2697@item throw
2698@kindex catch throw
2699The throwing of a C++ exception.
2700
2701@item catch
2702@kindex catch catch
2703The catching of a C++ exception.
2704
2705@item exec
2706@kindex catch exec
2707A call to @code{exec}. This is currently only available for HP-UX.
2708
2709@item fork
2710@kindex catch fork
2711A call to @code{fork}. This is currently only available for HP-UX.
2712
2713@item vfork
2714@kindex catch vfork
2715A call to @code{vfork}. This is currently only available for HP-UX.
2716
2717@item load
2718@itemx load @var{libname}
2719@kindex catch load
2720The dynamic loading of any shared library, or the loading of the library
2721@var{libname}. This is currently only available for HP-UX.
2722
2723@item unload
2724@itemx unload @var{libname}
2725@kindex catch unload
2726The unloading of any dynamically loaded shared library, or the unloading
2727of the library @var{libname}. This is currently only available for HP-UX.
2728@end table
2729
2730@item tcatch @var{event}
2731Set a catchpoint that is enabled only for one stop. The catchpoint is
2732automatically deleted after the first time the event is caught.
2733
2734@end table
2735
2736Use the @code{info break} command to list the current catchpoints.
2737
2738There are currently some limitations to C++ exception handling
2739(@code{catch throw} and @code{catch catch}) in @value{GDBN}:
2740
2741@itemize @bullet
2742@item
2743If you call a function interactively, @value{GDBN} normally returns
2744control to you when the function has finished executing. If the call
2745raises an exception, however, the call may bypass the mechanism that
2746returns control to you and cause your program either to abort or to
2747simply continue running until it hits a breakpoint, catches a signal
2748that @value{GDBN} is listening for, or exits. This is the case even if
2749you set a catchpoint for the exception; catchpoints on exceptions are
2750disabled within interactive calls.
2751
2752@item
2753You cannot raise an exception interactively.
2754
2755@item
2756You cannot install an exception handler interactively.
2757@end itemize
2758
2759@cindex raise exceptions
2760Sometimes @code{catch} is not the best way to debug exception handling:
2761if you need to know exactly where an exception is raised, it is better to
2762stop @emph{before} the exception handler is called, since that way you
2763can see the stack before any unwinding takes place. If you set a
2764breakpoint in an exception handler instead, it may not be easy to find
2765out where the exception was raised.
2766
2767To stop just before an exception handler is called, you need some
2768knowledge of the implementation. In the case of @sc{gnu} C++, exceptions are
2769raised by calling a library function named @code{__raise_exception}
2770which has the following ANSI C interface:
2771
2772@example
2773 /* @var{addr} is where the exception identifier is stored.
d4f3574e
SS
2774 @var{id} is the exception identifier. */
2775 void __raise_exception (void **addr, void *id);
c906108c
SS
2776@end example
2777
2778@noindent
2779To make the debugger catch all exceptions before any stack
2780unwinding takes place, set a breakpoint on @code{__raise_exception}
2781(@pxref{Breakpoints, ,Breakpoints; watchpoints; and exceptions}).
2782
2783With a conditional breakpoint (@pxref{Conditions, ,Break conditions})
2784that depends on the value of @var{id}, you can stop your program when
2785a specific exception is raised. You can use multiple conditional
2786breakpoints to stop your program when any of a number of exceptions are
2787raised.
2788
2789
6d2ebf8b 2790@node Delete Breaks
c906108c
SS
2791@subsection Deleting breakpoints
2792
2793@cindex clearing breakpoints, watchpoints, catchpoints
2794@cindex deleting breakpoints, watchpoints, catchpoints
2795It is often necessary to eliminate a breakpoint, watchpoint, or
2796catchpoint once it has done its job and you no longer want your program
2797to stop there. This is called @dfn{deleting} the breakpoint. A
2798breakpoint that has been deleted no longer exists; it is forgotten.
2799
2800With the @code{clear} command you can delete breakpoints according to
2801where they are in your program. With the @code{delete} command you can
2802delete individual breakpoints, watchpoints, or catchpoints by specifying
2803their breakpoint numbers.
2804
2805It is not necessary to delete a breakpoint to proceed past it. @value{GDBN}
2806automatically ignores breakpoints on the first instruction to be executed
2807when you continue execution without changing the execution address.
2808
2809@table @code
2810@kindex clear
2811@item clear
2812Delete any breakpoints at the next instruction to be executed in the
2813selected stack frame (@pxref{Selection, ,Selecting a frame}). When
2814the innermost frame is selected, this is a good way to delete a
2815breakpoint where your program just stopped.
2816
2817@item clear @var{function}
2818@itemx clear @var{filename}:@var{function}
2819Delete any breakpoints set at entry to the function @var{function}.
2820
2821@item clear @var{linenum}
2822@itemx clear @var{filename}:@var{linenum}
2823Delete any breakpoints set at or within the code of the specified line.
2824
2825@cindex delete breakpoints
2826@kindex delete
2827@kindex d
c5394b80
JM
2828@item delete @r{[}breakpoints@r{]} @r{[}@var{range}@dots{}@r{]}
2829Delete the breakpoints, watchpoints, or catchpoints of the breakpoint
2830ranges specified as arguments. If no argument is specified, delete all
c906108c
SS
2831breakpoints (@value{GDBN} asks confirmation, unless you have @code{set
2832confirm off}). You can abbreviate this command as @code{d}.
2833@end table
2834
6d2ebf8b 2835@node Disabling
c906108c
SS
2836@subsection Disabling breakpoints
2837
2838@kindex disable breakpoints
2839@kindex enable breakpoints
2840Rather than deleting a breakpoint, watchpoint, or catchpoint, you might
2841prefer to @dfn{disable} it. This makes the breakpoint inoperative as if
2842it had been deleted, but remembers the information on the breakpoint so
2843that you can @dfn{enable} it again later.
2844
2845You disable and enable breakpoints, watchpoints, and catchpoints with
2846the @code{enable} and @code{disable} commands, optionally specifying one
2847or more breakpoint numbers as arguments. Use @code{info break} or
2848@code{info watch} to print a list of breakpoints, watchpoints, and
2849catchpoints if you do not know which numbers to use.
2850
2851A breakpoint, watchpoint, or catchpoint can have any of four different
2852states of enablement:
2853
2854@itemize @bullet
2855@item
2856Enabled. The breakpoint stops your program. A breakpoint set
2857with the @code{break} command starts out in this state.
2858@item
2859Disabled. The breakpoint has no effect on your program.
2860@item
2861Enabled once. The breakpoint stops your program, but then becomes
d4f3574e 2862disabled.
c906108c
SS
2863@item
2864Enabled for deletion. The breakpoint stops your program, but
d4f3574e
SS
2865immediately after it does so it is deleted permanently. A breakpoint
2866set with the @code{tbreak} command starts out in this state.
c906108c
SS
2867@end itemize
2868
2869You can use the following commands to enable or disable breakpoints,
2870watchpoints, and catchpoints:
2871
2872@table @code
2873@kindex disable breakpoints
2874@kindex disable
2875@kindex dis
c5394b80 2876@item disable @r{[}breakpoints@r{]} @r{[}@var{range}@dots{}@r{]}
c906108c
SS
2877Disable the specified breakpoints---or all breakpoints, if none are
2878listed. A disabled breakpoint has no effect but is not forgotten. All
2879options such as ignore-counts, conditions and commands are remembered in
2880case the breakpoint is enabled again later. You may abbreviate
2881@code{disable} as @code{dis}.
2882
2883@kindex enable breakpoints
2884@kindex enable
c5394b80 2885@item enable @r{[}breakpoints@r{]} @r{[}@var{range}@dots{}@r{]}
c906108c
SS
2886Enable the specified breakpoints (or all defined breakpoints). They
2887become effective once again in stopping your program.
2888
c5394b80 2889@item enable @r{[}breakpoints@r{]} once @var{range}@dots{}
c906108c
SS
2890Enable the specified breakpoints temporarily. @value{GDBN} disables any
2891of these breakpoints immediately after stopping your program.
2892
c5394b80 2893@item enable @r{[}breakpoints@r{]} delete @var{range}@dots{}
c906108c
SS
2894Enable the specified breakpoints to work once, then die. @value{GDBN}
2895deletes any of these breakpoints as soon as your program stops there.
2896@end table
2897
d4f3574e
SS
2898@c FIXME: I think the following ``Except for [...] @code{tbreak}'' is
2899@c confusing: tbreak is also initially enabled.
c906108c
SS
2900Except for a breakpoint set with @code{tbreak} (@pxref{Set Breaks,
2901,Setting breakpoints}), breakpoints that you set are initially enabled;
2902subsequently, they become disabled or enabled only when you use one of
2903the commands above. (The command @code{until} can set and delete a
2904breakpoint of its own, but it does not change the state of your other
2905breakpoints; see @ref{Continuing and Stepping, ,Continuing and
2906stepping}.)
2907
6d2ebf8b 2908@node Conditions
c906108c
SS
2909@subsection Break conditions
2910@cindex conditional breakpoints
2911@cindex breakpoint conditions
2912
2913@c FIXME what is scope of break condition expr? Context where wanted?
5d161b24 2914@c in particular for a watchpoint?
c906108c
SS
2915The simplest sort of breakpoint breaks every time your program reaches a
2916specified place. You can also specify a @dfn{condition} for a
2917breakpoint. A condition is just a Boolean expression in your
2918programming language (@pxref{Expressions, ,Expressions}). A breakpoint with
2919a condition evaluates the expression each time your program reaches it,
2920and your program stops only if the condition is @emph{true}.
2921
2922This is the converse of using assertions for program validation; in that
2923situation, you want to stop when the assertion is violated---that is,
2924when the condition is false. In C, if you want to test an assertion expressed
2925by the condition @var{assert}, you should set the condition
2926@samp{! @var{assert}} on the appropriate breakpoint.
2927
2928Conditions are also accepted for watchpoints; you may not need them,
2929since a watchpoint is inspecting the value of an expression anyhow---but
2930it might be simpler, say, to just set a watchpoint on a variable name,
2931and specify a condition that tests whether the new value is an interesting
2932one.
2933
2934Break conditions can have side effects, and may even call functions in
2935your program. This can be useful, for example, to activate functions
2936that log program progress, or to use your own print functions to
2937format special data structures. The effects are completely predictable
2938unless there is another enabled breakpoint at the same address. (In
2939that case, @value{GDBN} might see the other breakpoint first and stop your
2940program without checking the condition of this one.) Note that
d4f3574e
SS
2941breakpoint commands are usually more convenient and flexible than break
2942conditions for the
c906108c
SS
2943purpose of performing side effects when a breakpoint is reached
2944(@pxref{Break Commands, ,Breakpoint command lists}).
2945
2946Break conditions can be specified when a breakpoint is set, by using
2947@samp{if} in the arguments to the @code{break} command. @xref{Set
2948Breaks, ,Setting breakpoints}. They can also be changed at any time
2949with the @code{condition} command.
53a5351d 2950
c906108c
SS
2951You can also use the @code{if} keyword with the @code{watch} command.
2952The @code{catch} command does not recognize the @code{if} keyword;
2953@code{condition} is the only way to impose a further condition on a
2954catchpoint.
c906108c
SS
2955
2956@table @code
2957@kindex condition
2958@item condition @var{bnum} @var{expression}
2959Specify @var{expression} as the break condition for breakpoint,
2960watchpoint, or catchpoint number @var{bnum}. After you set a condition,
2961breakpoint @var{bnum} stops your program only if the value of
2962@var{expression} is true (nonzero, in C). When you use
2963@code{condition}, @value{GDBN} checks @var{expression} immediately for
2964syntactic correctness, and to determine whether symbols in it have
d4f3574e
SS
2965referents in the context of your breakpoint. If @var{expression} uses
2966symbols not referenced in the context of the breakpoint, @value{GDBN}
2967prints an error message:
2968
2969@example
2970No symbol "foo" in current context.
2971@end example
2972
2973@noindent
c906108c
SS
2974@value{GDBN} does
2975not actually evaluate @var{expression} at the time the @code{condition}
d4f3574e
SS
2976command (or a command that sets a breakpoint with a condition, like
2977@code{break if @dots{}}) is given, however. @xref{Expressions, ,Expressions}.
c906108c
SS
2978
2979@item condition @var{bnum}
2980Remove the condition from breakpoint number @var{bnum}. It becomes
2981an ordinary unconditional breakpoint.
2982@end table
2983
2984@cindex ignore count (of breakpoint)
2985A special case of a breakpoint condition is to stop only when the
2986breakpoint has been reached a certain number of times. This is so
2987useful that there is a special way to do it, using the @dfn{ignore
2988count} of the breakpoint. Every breakpoint has an ignore count, which
2989is an integer. Most of the time, the ignore count is zero, and
2990therefore has no effect. But if your program reaches a breakpoint whose
2991ignore count is positive, then instead of stopping, it just decrements
2992the ignore count by one and continues. As a result, if the ignore count
2993value is @var{n}, the breakpoint does not stop the next @var{n} times
2994your program reaches it.
2995
2996@table @code
2997@kindex ignore
2998@item ignore @var{bnum} @var{count}
2999Set the ignore count of breakpoint number @var{bnum} to @var{count}.
3000The next @var{count} times the breakpoint is reached, your program's
3001execution does not stop; other than to decrement the ignore count, @value{GDBN}
3002takes no action.
3003
3004To make the breakpoint stop the next time it is reached, specify
3005a count of zero.
3006
3007When you use @code{continue} to resume execution of your program from a
3008breakpoint, you can specify an ignore count directly as an argument to
3009@code{continue}, rather than using @code{ignore}. @xref{Continuing and
3010Stepping,,Continuing and stepping}.
3011
3012If a breakpoint has a positive ignore count and a condition, the
3013condition is not checked. Once the ignore count reaches zero,
3014@value{GDBN} resumes checking the condition.
3015
3016You could achieve the effect of the ignore count with a condition such
3017as @w{@samp{$foo-- <= 0}} using a debugger convenience variable that
3018is decremented each time. @xref{Convenience Vars, ,Convenience
3019variables}.
3020@end table
3021
3022Ignore counts apply to breakpoints, watchpoints, and catchpoints.
3023
3024
6d2ebf8b 3025@node Break Commands
c906108c
SS
3026@subsection Breakpoint command lists
3027
3028@cindex breakpoint commands
3029You can give any breakpoint (or watchpoint or catchpoint) a series of
3030commands to execute when your program stops due to that breakpoint. For
3031example, you might want to print the values of certain expressions, or
3032enable other breakpoints.
3033
3034@table @code
3035@kindex commands
3036@kindex end
3037@item commands @r{[}@var{bnum}@r{]}
3038@itemx @dots{} @var{command-list} @dots{}
3039@itemx end
3040Specify a list of commands for breakpoint number @var{bnum}. The commands
3041themselves appear on the following lines. Type a line containing just
3042@code{end} to terminate the commands.
3043
3044To remove all commands from a breakpoint, type @code{commands} and
3045follow it immediately with @code{end}; that is, give no commands.
3046
3047With no @var{bnum} argument, @code{commands} refers to the last
3048breakpoint, watchpoint, or catchpoint set (not to the breakpoint most
3049recently encountered).
3050@end table
3051
3052Pressing @key{RET} as a means of repeating the last @value{GDBN} command is
3053disabled within a @var{command-list}.
3054
3055You can use breakpoint commands to start your program up again. Simply
3056use the @code{continue} command, or @code{step}, or any other command
3057that resumes execution.
3058
3059Any other commands in the command list, after a command that resumes
3060execution, are ignored. This is because any time you resume execution
3061(even with a simple @code{next} or @code{step}), you may encounter
3062another breakpoint---which could have its own command list, leading to
3063ambiguities about which list to execute.
3064
3065@kindex silent
3066If the first command you specify in a command list is @code{silent}, the
3067usual message about stopping at a breakpoint is not printed. This may
3068be desirable for breakpoints that are to print a specific message and
3069then continue. If none of the remaining commands print anything, you
3070see no sign that the breakpoint was reached. @code{silent} is
3071meaningful only at the beginning of a breakpoint command list.
3072
3073The commands @code{echo}, @code{output}, and @code{printf} allow you to
3074print precisely controlled output, and are often useful in silent
3075breakpoints. @xref{Output, ,Commands for controlled output}.
3076
3077For example, here is how you could use breakpoint commands to print the
3078value of @code{x} at entry to @code{foo} whenever @code{x} is positive.
3079
3080@example
3081break foo if x>0
3082commands
3083silent
3084printf "x is %d\n",x
3085cont
3086end
3087@end example
3088
3089One application for breakpoint commands is to compensate for one bug so
3090you can test for another. Put a breakpoint just after the erroneous line
3091of code, give it a condition to detect the case in which something
3092erroneous has been done, and give it commands to assign correct values
3093to any variables that need them. End with the @code{continue} command
3094so that your program does not stop, and start with the @code{silent}
3095command so that no output is produced. Here is an example:
3096
3097@example
3098break 403
3099commands
3100silent
3101set x = y + 4
3102cont
3103end
3104@end example
3105
6d2ebf8b 3106@node Breakpoint Menus
c906108c
SS
3107@subsection Breakpoint menus
3108@cindex overloading
3109@cindex symbol overloading
3110
3111Some programming languages (notably C++) permit a single function name
3112to be defined several times, for application in different contexts.
3113This is called @dfn{overloading}. When a function name is overloaded,
3114@samp{break @var{function}} is not enough to tell @value{GDBN} where you want
3115a breakpoint. If you realize this is a problem, you can use
3116something like @samp{break @var{function}(@var{types})} to specify which
3117particular version of the function you want. Otherwise, @value{GDBN} offers
3118you a menu of numbered choices for different possible breakpoints, and
3119waits for your selection with the prompt @samp{>}. The first two
3120options are always @samp{[0] cancel} and @samp{[1] all}. Typing @kbd{1}
3121sets a breakpoint at each definition of @var{function}, and typing
3122@kbd{0} aborts the @code{break} command without setting any new
3123breakpoints.
3124
3125For example, the following session excerpt shows an attempt to set a
3126breakpoint at the overloaded symbol @code{String::after}.
3127We choose three particular definitions of that function name:
3128
3129@c FIXME! This is likely to change to show arg type lists, at least
3130@smallexample
3131@group
3132(@value{GDBP}) b String::after
3133[0] cancel
3134[1] all
3135[2] file:String.cc; line number:867
3136[3] file:String.cc; line number:860
3137[4] file:String.cc; line number:875
3138[5] file:String.cc; line number:853
3139[6] file:String.cc; line number:846
3140[7] file:String.cc; line number:735
3141> 2 4 6
3142Breakpoint 1 at 0xb26c: file String.cc, line 867.
3143Breakpoint 2 at 0xb344: file String.cc, line 875.
3144Breakpoint 3 at 0xafcc: file String.cc, line 846.
3145Multiple breakpoints were set.
3146Use the "delete" command to delete unwanted
3147 breakpoints.
3148(@value{GDBP})
3149@end group
3150@end smallexample
c906108c
SS
3151
3152@c @ifclear BARETARGET
6d2ebf8b 3153@node Error in Breakpoints
d4f3574e 3154@subsection ``Cannot insert breakpoints''
c906108c
SS
3155@c
3156@c FIXME!! 14/6/95 Is there a real example of this? Let's use it.
3157@c
d4f3574e
SS
3158Under some operating systems, breakpoints cannot be used in a program if
3159any other process is running that program. In this situation,
5d161b24 3160attempting to run or continue a program with a breakpoint causes
d4f3574e
SS
3161@value{GDBN} to print an error message:
3162
3163@example
3164Cannot insert breakpoints.
3165The same program may be running in another process.
3166@end example
3167
3168When this happens, you have three ways to proceed:
3169
3170@enumerate
3171@item
3172Remove or disable the breakpoints, then continue.
3173
3174@item
5d161b24 3175Suspend @value{GDBN}, and copy the file containing your program to a new
d4f3574e 3176name. Resume @value{GDBN} and use the @code{exec-file} command to specify
5d161b24 3177that @value{GDBN} should run your program under that name.
d4f3574e
SS
3178Then start your program again.
3179
3180@item
3181Relink your program so that the text segment is nonsharable, using the
3182linker option @samp{-N}. The operating system limitation may not apply
3183to nonsharable executables.
3184@end enumerate
c906108c
SS
3185@c @end ifclear
3186
d4f3574e
SS
3187A similar message can be printed if you request too many active
3188hardware-assisted breakpoints and watchpoints:
3189
3190@c FIXME: the precise wording of this message may change; the relevant
3191@c source change is not committed yet (Sep 3, 1999).
3192@smallexample
3193Stopped; cannot insert breakpoints.
3194You may have requested too many hardware breakpoints and watchpoints.
3195@end smallexample
3196
3197@noindent
3198This message is printed when you attempt to resume the program, since
3199only then @value{GDBN} knows exactly how many hardware breakpoints and
3200watchpoints it needs to insert.
3201
3202When this message is printed, you need to disable or remove some of the
3203hardware-assisted breakpoints and watchpoints, and then continue.
3204
3205
6d2ebf8b 3206@node Continuing and Stepping
c906108c
SS
3207@section Continuing and stepping
3208
3209@cindex stepping
3210@cindex continuing
3211@cindex resuming execution
3212@dfn{Continuing} means resuming program execution until your program
3213completes normally. In contrast, @dfn{stepping} means executing just
3214one more ``step'' of your program, where ``step'' may mean either one
3215line of source code, or one machine instruction (depending on what
7a292a7a
SS
3216particular command you use). Either when continuing or when stepping,
3217your program may stop even sooner, due to a breakpoint or a signal. (If
d4f3574e
SS
3218it stops due to a signal, you may want to use @code{handle}, or use
3219@samp{signal 0} to resume execution. @xref{Signals, ,Signals}.)
c906108c
SS
3220
3221@table @code
3222@kindex continue
3223@kindex c
3224@kindex fg
3225@item continue @r{[}@var{ignore-count}@r{]}
3226@itemx c @r{[}@var{ignore-count}@r{]}
3227@itemx fg @r{[}@var{ignore-count}@r{]}
3228Resume program execution, at the address where your program last stopped;
3229any breakpoints set at that address are bypassed. The optional argument
3230@var{ignore-count} allows you to specify a further number of times to
3231ignore a breakpoint at this location; its effect is like that of
3232@code{ignore} (@pxref{Conditions, ,Break conditions}).
3233
3234The argument @var{ignore-count} is meaningful only when your program
3235stopped due to a breakpoint. At other times, the argument to
3236@code{continue} is ignored.
3237
d4f3574e
SS
3238The synonyms @code{c} and @code{fg} (for @dfn{foreground}, as the
3239debugged program is deemed to be the foreground program) are provided
3240purely for convenience, and have exactly the same behavior as
3241@code{continue}.
c906108c
SS
3242@end table
3243
3244To resume execution at a different place, you can use @code{return}
3245(@pxref{Returning, ,Returning from a function}) to go back to the
3246calling function; or @code{jump} (@pxref{Jumping, ,Continuing at a
3247different address}) to go to an arbitrary location in your program.
3248
3249A typical technique for using stepping is to set a breakpoint
3250(@pxref{Breakpoints, ,Breakpoints; watchpoints; and catchpoints}) at the
3251beginning of the function or the section of your program where a problem
3252is believed to lie, run your program until it stops at that breakpoint,
3253and then step through the suspect area, examining the variables that are
3254interesting, until you see the problem happen.
3255
3256@table @code
3257@kindex step
3258@kindex s
3259@item step
3260Continue running your program until control reaches a different source
3261line, then stop it and return control to @value{GDBN}. This command is
3262abbreviated @code{s}.
3263
3264@quotation
3265@c "without debugging information" is imprecise; actually "without line
3266@c numbers in the debugging information". (gcc -g1 has debugging info but
3267@c not line numbers). But it seems complex to try to make that
3268@c distinction here.
3269@emph{Warning:} If you use the @code{step} command while control is
3270within a function that was compiled without debugging information,
3271execution proceeds until control reaches a function that does have
3272debugging information. Likewise, it will not step into a function which
3273is compiled without debugging information. To step through functions
3274without debugging information, use the @code{stepi} command, described
3275below.
3276@end quotation
3277
d4f3574e
SS
3278The @code{step} command only stops at the first instruction of a
3279source line. This prevents the multiple stops that could otherwise occur in
c906108c
SS
3280switch statements, for loops, etc. @code{step} continues to stop if a
3281function that has debugging information is called within the line.
d4f3574e
SS
3282In other words, @code{step} @emph{steps inside} any functions called
3283within the line.
c906108c 3284
d4f3574e
SS
3285Also, the @code{step} command only enters a function if there is line
3286number information for the function. Otherwise it acts like the
5d161b24 3287@code{next} command. This avoids problems when using @code{cc -gl}
c906108c 3288on MIPS machines. Previously, @code{step} entered subroutines if there
5d161b24 3289was any debugging information about the routine.
c906108c
SS
3290
3291@item step @var{count}
3292Continue running as in @code{step}, but do so @var{count} times. If a
7a292a7a
SS
3293breakpoint is reached, or a signal not related to stepping occurs before
3294@var{count} steps, stepping stops right away.
c906108c
SS
3295
3296@kindex next
3297@kindex n
3298@item next @r{[}@var{count}@r{]}
3299Continue to the next source line in the current (innermost) stack frame.
7a292a7a
SS
3300This is similar to @code{step}, but function calls that appear within
3301the line of code are executed without stopping. Execution stops when
3302control reaches a different line of code at the original stack level
3303that was executing when you gave the @code{next} command. This command
3304is abbreviated @code{n}.
c906108c
SS
3305
3306An argument @var{count} is a repeat count, as for @code{step}.
3307
3308
3309@c FIX ME!! Do we delete this, or is there a way it fits in with
3310@c the following paragraph? --- Vctoria
3311@c
3312@c @code{next} within a function that lacks debugging information acts like
3313@c @code{step}, but any function calls appearing within the code of the
3314@c function are executed without stopping.
3315
d4f3574e
SS
3316The @code{next} command only stops at the first instruction of a
3317source line. This prevents multiple stops that could otherwise occur in
5d161b24 3318switch statements, for loops, etc.
c906108c
SS
3319
3320@kindex finish
3321@item finish
3322Continue running until just after function in the selected stack frame
3323returns. Print the returned value (if any).
3324
3325Contrast this with the @code{return} command (@pxref{Returning,
3326,Returning from a function}).
3327
3328@kindex until
3329@kindex u
3330@item until
3331@itemx u
3332Continue running until a source line past the current line, in the
3333current stack frame, is reached. This command is used to avoid single
3334stepping through a loop more than once. It is like the @code{next}
3335command, except that when @code{until} encounters a jump, it
3336automatically continues execution until the program counter is greater
3337than the address of the jump.
3338
3339This means that when you reach the end of a loop after single stepping
3340though it, @code{until} makes your program continue execution until it
3341exits the loop. In contrast, a @code{next} command at the end of a loop
3342simply steps back to the beginning of the loop, which forces you to step
3343through the next iteration.
3344
3345@code{until} always stops your program if it attempts to exit the current
3346stack frame.
3347
3348@code{until} may produce somewhat counterintuitive results if the order
3349of machine code does not match the order of the source lines. For
3350example, in the following excerpt from a debugging session, the @code{f}
3351(@code{frame}) command shows that execution is stopped at line
3352@code{206}; yet when we use @code{until}, we get to line @code{195}:
3353
3354@example
3355(@value{GDBP}) f
3356#0 main (argc=4, argv=0xf7fffae8) at m4.c:206
3357206 expand_input();
3358(@value{GDBP}) until
3359195 for ( ; argc > 0; NEXTARG) @{
3360@end example
3361
3362This happened because, for execution efficiency, the compiler had
3363generated code for the loop closure test at the end, rather than the
3364start, of the loop---even though the test in a C @code{for}-loop is
3365written before the body of the loop. The @code{until} command appeared
3366to step back to the beginning of the loop when it advanced to this
3367expression; however, it has not really gone to an earlier
3368statement---not in terms of the actual machine code.
3369
3370@code{until} with no argument works by means of single
3371instruction stepping, and hence is slower than @code{until} with an
3372argument.
3373
3374@item until @var{location}
3375@itemx u @var{location}
3376Continue running your program until either the specified location is
3377reached, or the current stack frame returns. @var{location} is any of
3378the forms of argument acceptable to @code{break} (@pxref{Set Breaks,
3379,Setting breakpoints}). This form of the command uses breakpoints,
3380and hence is quicker than @code{until} without an argument.
3381
3382@kindex stepi
3383@kindex si
3384@item stepi
96a2c332 3385@itemx stepi @var{arg}
c906108c
SS
3386@itemx si
3387Execute one machine instruction, then stop and return to the debugger.
3388
3389It is often useful to do @samp{display/i $pc} when stepping by machine
3390instructions. This makes @value{GDBN} automatically display the next
3391instruction to be executed, each time your program stops. @xref{Auto
3392Display,, Automatic display}.
3393
3394An argument is a repeat count, as in @code{step}.
3395
3396@need 750
3397@kindex nexti
3398@kindex ni
3399@item nexti
96a2c332 3400@itemx nexti @var{arg}
c906108c
SS
3401@itemx ni
3402Execute one machine instruction, but if it is a function call,
3403proceed until the function returns.
3404
3405An argument is a repeat count, as in @code{next}.
3406@end table
3407
6d2ebf8b 3408@node Signals
c906108c
SS
3409@section Signals
3410@cindex signals
3411
3412A signal is an asynchronous event that can happen in a program. The
3413operating system defines the possible kinds of signals, and gives each
3414kind a name and a number. For example, in Unix @code{SIGINT} is the
d4f3574e 3415signal a program gets when you type an interrupt character (often @kbd{C-c});
c906108c
SS
3416@code{SIGSEGV} is the signal a program gets from referencing a place in
3417memory far away from all the areas in use; @code{SIGALRM} occurs when
3418the alarm clock timer goes off (which happens only if your program has
3419requested an alarm).
3420
3421@cindex fatal signals
3422Some signals, including @code{SIGALRM}, are a normal part of the
3423functioning of your program. Others, such as @code{SIGSEGV}, indicate
d4f3574e 3424errors; these signals are @dfn{fatal} (they kill your program immediately) if the
c906108c
SS
3425program has not specified in advance some other way to handle the signal.
3426@code{SIGINT} does not indicate an error in your program, but it is normally
3427fatal so it can carry out the purpose of the interrupt: to kill the program.
3428
3429@value{GDBN} has the ability to detect any occurrence of a signal in your
3430program. You can tell @value{GDBN} in advance what to do for each kind of
3431signal.
3432
3433@cindex handling signals
3434Normally, @value{GDBN} is set up to ignore non-erroneous signals like @code{SIGALRM}
3435(so as not to interfere with their role in the functioning of your program)
3436but to stop your program immediately whenever an error signal happens.
3437You can change these settings with the @code{handle} command.
3438
3439@table @code
3440@kindex info signals
3441@item info signals
96a2c332 3442@itemx info handle
c906108c
SS
3443Print a table of all the kinds of signals and how @value{GDBN} has been told to
3444handle each one. You can use this to see the signal numbers of all
3445the defined types of signals.
3446
d4f3574e 3447@code{info handle} is an alias for @code{info signals}.
c906108c
SS
3448
3449@kindex handle
3450@item handle @var{signal} @var{keywords}@dots{}
5d161b24 3451Change the way @value{GDBN} handles signal @var{signal}. @var{signal} can
c906108c
SS
3452be the number of a signal or its name (with or without the @samp{SIG} at the
3453beginning). The @var{keywords} say what change to make.
3454@end table
3455
3456@c @group
3457The keywords allowed by the @code{handle} command can be abbreviated.
3458Their full names are:
3459
3460@table @code
3461@item nostop
3462@value{GDBN} should not stop your program when this signal happens. It may
3463still print a message telling you that the signal has come in.
3464
3465@item stop
3466@value{GDBN} should stop your program when this signal happens. This implies
3467the @code{print} keyword as well.
3468
3469@item print
3470@value{GDBN} should print a message when this signal happens.
3471
3472@item noprint
3473@value{GDBN} should not mention the occurrence of the signal at all. This
3474implies the @code{nostop} keyword as well.
3475
3476@item pass
3477@value{GDBN} should allow your program to see this signal; your program
3478can handle the signal, or else it may terminate if the signal is fatal
3479and not handled.
3480
3481@item nopass
3482@value{GDBN} should not allow your program to see this signal.
3483@end table
3484@c @end group
3485
d4f3574e
SS
3486When a signal stops your program, the signal is not visible to the
3487program until you
c906108c
SS
3488continue. Your program sees the signal then, if @code{pass} is in
3489effect for the signal in question @emph{at that time}. In other words,
3490after @value{GDBN} reports a signal, you can use the @code{handle}
3491command with @code{pass} or @code{nopass} to control whether your
3492program sees that signal when you continue.
3493
3494You can also use the @code{signal} command to prevent your program from
3495seeing a signal, or cause it to see a signal it normally would not see,
3496or to give it any signal at any time. For example, if your program stopped
3497due to some sort of memory reference error, you might store correct
3498values into the erroneous variables and continue, hoping to see more
3499execution; but your program would probably terminate immediately as
3500a result of the fatal signal once it saw the signal. To prevent this,
3501you can continue with @samp{signal 0}. @xref{Signaling, ,Giving your
5d161b24 3502program a signal}.
c906108c 3503
6d2ebf8b 3504@node Thread Stops
c906108c
SS
3505@section Stopping and starting multi-thread programs
3506
3507When your program has multiple threads (@pxref{Threads,, Debugging
3508programs with multiple threads}), you can choose whether to set
3509breakpoints on all threads, or on a particular thread.
3510
3511@table @code
3512@cindex breakpoints and threads
3513@cindex thread breakpoints
3514@kindex break @dots{} thread @var{threadno}
3515@item break @var{linespec} thread @var{threadno}
3516@itemx break @var{linespec} thread @var{threadno} if @dots{}
3517@var{linespec} specifies source lines; there are several ways of
3518writing them, but the effect is always to specify some source line.
3519
3520Use the qualifier @samp{thread @var{threadno}} with a breakpoint command
3521to specify that you only want @value{GDBN} to stop the program when a
3522particular thread reaches this breakpoint. @var{threadno} is one of the
3523numeric thread identifiers assigned by @value{GDBN}, shown in the first
3524column of the @samp{info threads} display.
3525
3526If you do not specify @samp{thread @var{threadno}} when you set a
3527breakpoint, the breakpoint applies to @emph{all} threads of your
3528program.
3529
3530You can use the @code{thread} qualifier on conditional breakpoints as
3531well; in this case, place @samp{thread @var{threadno}} before the
3532breakpoint condition, like this:
3533
3534@smallexample
2df3850c 3535(@value{GDBP}) break frik.c:13 thread 28 if bartab > lim
c906108c
SS
3536@end smallexample
3537
3538@end table
3539
3540@cindex stopped threads
3541@cindex threads, stopped
3542Whenever your program stops under @value{GDBN} for any reason,
3543@emph{all} threads of execution stop, not just the current thread. This
3544allows you to examine the overall state of the program, including
3545switching between threads, without worrying that things may change
3546underfoot.
3547
3548@cindex continuing threads
3549@cindex threads, continuing
3550Conversely, whenever you restart the program, @emph{all} threads start
3551executing. @emph{This is true even when single-stepping} with commands
5d161b24 3552like @code{step} or @code{next}.
c906108c
SS
3553
3554In particular, @value{GDBN} cannot single-step all threads in lockstep.
3555Since thread scheduling is up to your debugging target's operating
3556system (not controlled by @value{GDBN}), other threads may
3557execute more than one statement while the current thread completes a
3558single step. Moreover, in general other threads stop in the middle of a
3559statement, rather than at a clean statement boundary, when the program
3560stops.
3561
3562You might even find your program stopped in another thread after
3563continuing or even single-stepping. This happens whenever some other
3564thread runs into a breakpoint, a signal, or an exception before the
3565first thread completes whatever you requested.
3566
3567On some OSes, you can lock the OS scheduler and thus allow only a single
3568thread to run.
3569
3570@table @code
3571@item set scheduler-locking @var{mode}
3572Set the scheduler locking mode. If it is @code{off}, then there is no
3573locking and any thread may run at any time. If @code{on}, then only the
3574current thread may run when the inferior is resumed. The @code{step}
3575mode optimizes for single-stepping. It stops other threads from
3576``seizing the prompt'' by preempting the current thread while you are
3577stepping. Other threads will only rarely (or never) get a chance to run
d4f3574e 3578when you step. They are more likely to run when you @samp{next} over a
c906108c 3579function call, and they are completely free to run when you use commands
d4f3574e 3580like @samp{continue}, @samp{until}, or @samp{finish}. However, unless another
c906108c 3581thread hits a breakpoint during its timeslice, they will never steal the
2df3850c 3582@value{GDBN} prompt away from the thread that you are debugging.
c906108c
SS
3583
3584@item show scheduler-locking
3585Display the current scheduler locking mode.
3586@end table
3587
c906108c 3588
6d2ebf8b 3589@node Stack
c906108c
SS
3590@chapter Examining the Stack
3591
3592When your program has stopped, the first thing you need to know is where it
3593stopped and how it got there.
3594
3595@cindex call stack
5d161b24
DB
3596Each time your program performs a function call, information about the call
3597is generated.
3598That information includes the location of the call in your program,
3599the arguments of the call,
c906108c 3600and the local variables of the function being called.
5d161b24 3601The information is saved in a block of data called a @dfn{stack frame}.
c906108c
SS
3602The stack frames are allocated in a region of memory called the @dfn{call
3603stack}.
3604
3605When your program stops, the @value{GDBN} commands for examining the
3606stack allow you to see all of this information.
3607
3608@cindex selected frame
3609One of the stack frames is @dfn{selected} by @value{GDBN} and many
3610@value{GDBN} commands refer implicitly to the selected frame. In
3611particular, whenever you ask @value{GDBN} for the value of a variable in
3612your program, the value is found in the selected frame. There are
3613special @value{GDBN} commands to select whichever frame you are
3614interested in. @xref{Selection, ,Selecting a frame}.
3615
3616When your program stops, @value{GDBN} automatically selects the
5d161b24 3617currently executing frame and describes it briefly, similar to the
c906108c
SS
3618@code{frame} command (@pxref{Frame Info, ,Information about a frame}).
3619
3620@menu
3621* Frames:: Stack frames
3622* Backtrace:: Backtraces
3623* Selection:: Selecting a frame
3624* Frame Info:: Information on a frame
c906108c
SS
3625
3626@end menu
3627
6d2ebf8b 3628@node Frames
c906108c
SS
3629@section Stack frames
3630
d4f3574e 3631@cindex frame, definition
c906108c
SS
3632@cindex stack frame
3633The call stack is divided up into contiguous pieces called @dfn{stack
3634frames}, or @dfn{frames} for short; each frame is the data associated
3635with one call to one function. The frame contains the arguments given
3636to the function, the function's local variables, and the address at
3637which the function is executing.
3638
3639@cindex initial frame
3640@cindex outermost frame
3641@cindex innermost frame
3642When your program is started, the stack has only one frame, that of the
3643function @code{main}. This is called the @dfn{initial} frame or the
3644@dfn{outermost} frame. Each time a function is called, a new frame is
3645made. Each time a function returns, the frame for that function invocation
3646is eliminated. If a function is recursive, there can be many frames for
3647the same function. The frame for the function in which execution is
3648actually occurring is called the @dfn{innermost} frame. This is the most
3649recently created of all the stack frames that still exist.
3650
3651@cindex frame pointer
3652Inside your program, stack frames are identified by their addresses. A
3653stack frame consists of many bytes, each of which has its own address; each
3654kind of computer has a convention for choosing one byte whose
3655address serves as the address of the frame. Usually this address is kept
3656in a register called the @dfn{frame pointer register} while execution is
3657going on in that frame.
3658
3659@cindex frame number
3660@value{GDBN} assigns numbers to all existing stack frames, starting with
3661zero for the innermost frame, one for the frame that called it,
3662and so on upward. These numbers do not really exist in your program;
3663they are assigned by @value{GDBN} to give you a way of designating stack
3664frames in @value{GDBN} commands.
3665
6d2ebf8b
SS
3666@c The -fomit-frame-pointer below perennially causes hbox overflow
3667@c underflow problems.
c906108c
SS
3668@cindex frameless execution
3669Some compilers provide a way to compile functions so that they operate
6d2ebf8b
SS
3670without stack frames. (For example, the @value{GCC} option
3671@example
3672@samp{-fomit-frame-pointer}
3673@end example
3674generates functions without a frame.)
c906108c
SS
3675This is occasionally done with heavily used library functions to save
3676the frame setup time. @value{GDBN} has limited facilities for dealing
3677with these function invocations. If the innermost function invocation
3678has no stack frame, @value{GDBN} nevertheless regards it as though
3679it had a separate frame, which is numbered zero as usual, allowing
3680correct tracing of the function call chain. However, @value{GDBN} has
3681no provision for frameless functions elsewhere in the stack.
3682
3683@table @code
d4f3574e 3684@kindex frame@r{, command}
c906108c 3685@item frame @var{args}
5d161b24 3686The @code{frame} command allows you to move from one stack frame to another,
c906108c 3687and to print the stack frame you select. @var{args} may be either the
5d161b24
DB
3688address of the frame or the stack frame number. Without an argument,
3689@code{frame} prints the current stack frame.
c906108c
SS
3690
3691@kindex select-frame
3692@item select-frame
3693The @code{select-frame} command allows you to move from one stack frame
3694to another without printing the frame. This is the silent version of
3695@code{frame}.
3696@end table
3697
6d2ebf8b 3698@node Backtrace
c906108c
SS
3699@section Backtraces
3700
3701@cindex backtraces
3702@cindex tracebacks
3703@cindex stack traces
3704A backtrace is a summary of how your program got where it is. It shows one
3705line per frame, for many frames, starting with the currently executing
3706frame (frame zero), followed by its caller (frame one), and on up the
3707stack.
3708
3709@table @code
3710@kindex backtrace
3711@kindex bt
3712@item backtrace
3713@itemx bt
3714Print a backtrace of the entire stack: one line per frame for all
3715frames in the stack.
3716
3717You can stop the backtrace at any time by typing the system interrupt
3718character, normally @kbd{C-c}.
3719
3720@item backtrace @var{n}
3721@itemx bt @var{n}
3722Similar, but print only the innermost @var{n} frames.
3723
3724@item backtrace -@var{n}
3725@itemx bt -@var{n}
3726Similar, but print only the outermost @var{n} frames.
3727@end table
3728
3729@kindex where
3730@kindex info stack
3731@kindex info s
3732The names @code{where} and @code{info stack} (abbreviated @code{info s})
3733are additional aliases for @code{backtrace}.
3734
3735Each line in the backtrace shows the frame number and the function name.
3736The program counter value is also shown---unless you use @code{set
3737print address off}. The backtrace also shows the source file name and
3738line number, as well as the arguments to the function. The program
3739counter value is omitted if it is at the beginning of the code for that
3740line number.
3741
3742Here is an example of a backtrace. It was made with the command
3743@samp{bt 3}, so it shows the innermost three frames.
3744
3745@smallexample
3746@group
5d161b24 3747#0 m4_traceon (obs=0x24eb0, argc=1, argv=0x2b8c8)
c906108c
SS
3748 at builtin.c:993
3749#1 0x6e38 in expand_macro (sym=0x2b600) at macro.c:242
3750#2 0x6840 in expand_token (obs=0x0, t=177664, td=0xf7fffb08)
3751 at macro.c:71
3752(More stack frames follow...)
3753@end group
3754@end smallexample
3755
3756@noindent
3757The display for frame zero does not begin with a program counter
3758value, indicating that your program has stopped at the beginning of the
3759code for line @code{993} of @code{builtin.c}.
3760
6d2ebf8b 3761@node Selection
c906108c
SS
3762@section Selecting a frame
3763
3764Most commands for examining the stack and other data in your program work on
3765whichever stack frame is selected at the moment. Here are the commands for
3766selecting a stack frame; all of them finish by printing a brief description
3767of the stack frame just selected.
3768
3769@table @code
d4f3574e 3770@kindex frame@r{, selecting}
c906108c
SS
3771@kindex f
3772@item frame @var{n}
3773@itemx f @var{n}
3774Select frame number @var{n}. Recall that frame zero is the innermost
3775(currently executing) frame, frame one is the frame that called the
3776innermost one, and so on. The highest-numbered frame is the one for
3777@code{main}.
3778
3779@item frame @var{addr}
3780@itemx f @var{addr}
3781Select the frame at address @var{addr}. This is useful mainly if the
3782chaining of stack frames has been damaged by a bug, making it
3783impossible for @value{GDBN} to assign numbers properly to all frames. In
3784addition, this can be useful when your program has multiple stacks and
3785switches between them.
3786
c906108c
SS
3787On the SPARC architecture, @code{frame} needs two addresses to
3788select an arbitrary frame: a frame pointer and a stack pointer.
3789
3790On the MIPS and Alpha architecture, it needs two addresses: a stack
3791pointer and a program counter.
3792
3793On the 29k architecture, it needs three addresses: a register stack
3794pointer, a program counter, and a memory stack pointer.
3795@c note to future updaters: this is conditioned on a flag
3796@c SETUP_ARBITRARY_FRAME in the tm-*.h files. The above is up to date
3797@c as of 27 Jan 1994.
c906108c
SS
3798
3799@kindex up
3800@item up @var{n}
3801Move @var{n} frames up the stack. For positive numbers @var{n}, this
3802advances toward the outermost frame, to higher frame numbers, to frames
3803that have existed longer. @var{n} defaults to one.
3804
3805@kindex down
3806@kindex do
3807@item down @var{n}
3808Move @var{n} frames down the stack. For positive numbers @var{n}, this
3809advances toward the innermost frame, to lower frame numbers, to frames
3810that were created more recently. @var{n} defaults to one. You may
3811abbreviate @code{down} as @code{do}.
3812@end table
3813
3814All of these commands end by printing two lines of output describing the
3815frame. The first line shows the frame number, the function name, the
3816arguments, and the source file and line number of execution in that
5d161b24 3817frame. The second line shows the text of that source line.
c906108c
SS
3818
3819@need 1000
3820For example:
3821
3822@smallexample
3823@group
3824(@value{GDBP}) up
3825#1 0x22f0 in main (argc=1, argv=0xf7fffbf4, env=0xf7fffbfc)
3826 at env.c:10
382710 read_input_file (argv[i]);
3828@end group
3829@end smallexample
3830
3831After such a printout, the @code{list} command with no arguments
3832prints ten lines centered on the point of execution in the frame.
3833@xref{List, ,Printing source lines}.
3834
3835@table @code
3836@kindex down-silently
3837@kindex up-silently
3838@item up-silently @var{n}
3839@itemx down-silently @var{n}
3840These two commands are variants of @code{up} and @code{down},
3841respectively; they differ in that they do their work silently, without
3842causing display of the new frame. They are intended primarily for use
3843in @value{GDBN} command scripts, where the output might be unnecessary and
3844distracting.
3845@end table
3846
6d2ebf8b 3847@node Frame Info
c906108c
SS
3848@section Information about a frame
3849
3850There are several other commands to print information about the selected
3851stack frame.
3852
3853@table @code
3854@item frame
3855@itemx f
3856When used without any argument, this command does not change which
3857frame is selected, but prints a brief description of the currently
3858selected stack frame. It can be abbreviated @code{f}. With an
3859argument, this command is used to select a stack frame.
3860@xref{Selection, ,Selecting a frame}.
3861
3862@kindex info frame
3863@kindex info f
3864@item info frame
3865@itemx info f
3866This command prints a verbose description of the selected stack frame,
3867including:
3868
3869@itemize @bullet
5d161b24
DB
3870@item
3871the address of the frame
c906108c
SS
3872@item
3873the address of the next frame down (called by this frame)
3874@item
3875the address of the next frame up (caller of this frame)
3876@item
3877the language in which the source code corresponding to this frame is written
3878@item
3879the address of the frame's arguments
3880@item
d4f3574e
SS
3881the address of the frame's local variables
3882@item
c906108c
SS
3883the program counter saved in it (the address of execution in the caller frame)
3884@item
3885which registers were saved in the frame
3886@end itemize
3887
3888@noindent The verbose description is useful when
3889something has gone wrong that has made the stack format fail to fit
3890the usual conventions.
3891
3892@item info frame @var{addr}
3893@itemx info f @var{addr}
3894Print a verbose description of the frame at address @var{addr}, without
3895selecting that frame. The selected frame remains unchanged by this
3896command. This requires the same kind of address (more than one for some
3897architectures) that you specify in the @code{frame} command.
3898@xref{Selection, ,Selecting a frame}.
3899
3900@kindex info args
3901@item info args
3902Print the arguments of the selected frame, each on a separate line.
3903
3904@item info locals
3905@kindex info locals
3906Print the local variables of the selected frame, each on a separate
3907line. These are all variables (declared either static or automatic)
3908accessible at the point of execution of the selected frame.
3909
c906108c 3910@kindex info catch
d4f3574e
SS
3911@cindex catch exceptions, list active handlers
3912@cindex exception handlers, how to list
c906108c
SS
3913@item info catch
3914Print a list of all the exception handlers that are active in the
3915current stack frame at the current point of execution. To see other
3916exception handlers, visit the associated frame (using the @code{up},
3917@code{down}, or @code{frame} commands); then type @code{info catch}.
3918@xref{Set Catchpoints, , Setting catchpoints}.
53a5351d 3919
c906108c
SS
3920@end table
3921
c906108c 3922
6d2ebf8b 3923@node Source
c906108c
SS
3924@chapter Examining Source Files
3925
3926@value{GDBN} can print parts of your program's source, since the debugging
3927information recorded in the program tells @value{GDBN} what source files were
3928used to build it. When your program stops, @value{GDBN} spontaneously prints
3929the line where it stopped. Likewise, when you select a stack frame
3930(@pxref{Selection, ,Selecting a frame}), @value{GDBN} prints the line where
3931execution in that frame has stopped. You can print other portions of
3932source files by explicit command.
3933
7a292a7a 3934If you use @value{GDBN} through its @sc{gnu} Emacs interface, you may
d4f3574e 3935prefer to use Emacs facilities to view source; see @ref{Emacs, ,Using
7a292a7a 3936@value{GDBN} under @sc{gnu} Emacs}.
c906108c
SS
3937
3938@menu
3939* List:: Printing source lines
c906108c 3940* Search:: Searching source files
c906108c
SS
3941* Source Path:: Specifying source directories
3942* Machine Code:: Source and machine code
3943@end menu
3944
6d2ebf8b 3945@node List
c906108c
SS
3946@section Printing source lines
3947
3948@kindex list
3949@kindex l
3950To print lines from a source file, use the @code{list} command
5d161b24 3951(abbreviated @code{l}). By default, ten lines are printed.
c906108c
SS
3952There are several ways to specify what part of the file you want to print.
3953
3954Here are the forms of the @code{list} command most commonly used:
3955
3956@table @code
3957@item list @var{linenum}
3958Print lines centered around line number @var{linenum} in the
3959current source file.
3960
3961@item list @var{function}
3962Print lines centered around the beginning of function
3963@var{function}.
3964
3965@item list
3966Print more lines. If the last lines printed were printed with a
3967@code{list} command, this prints lines following the last lines
3968printed; however, if the last line printed was a solitary line printed
3969as part of displaying a stack frame (@pxref{Stack, ,Examining the
3970Stack}), this prints lines centered around that line.
3971
3972@item list -
3973Print lines just before the lines last printed.
3974@end table
3975
3976By default, @value{GDBN} prints ten source lines with any of these forms of
3977the @code{list} command. You can change this using @code{set listsize}:
3978
3979@table @code
3980@kindex set listsize
3981@item set listsize @var{count}
3982Make the @code{list} command display @var{count} source lines (unless
3983the @code{list} argument explicitly specifies some other number).
3984
3985@kindex show listsize
3986@item show listsize
3987Display the number of lines that @code{list} prints.
3988@end table
3989
3990Repeating a @code{list} command with @key{RET} discards the argument,
3991so it is equivalent to typing just @code{list}. This is more useful
3992than listing the same lines again. An exception is made for an
3993argument of @samp{-}; that argument is preserved in repetition so that
3994each repetition moves up in the source file.
3995
3996@cindex linespec
3997In general, the @code{list} command expects you to supply zero, one or two
3998@dfn{linespecs}. Linespecs specify source lines; there are several ways
d4f3574e 3999of writing them, but the effect is always to specify some source line.
c906108c
SS
4000Here is a complete description of the possible arguments for @code{list}:
4001
4002@table @code
4003@item list @var{linespec}
4004Print lines centered around the line specified by @var{linespec}.
4005
4006@item list @var{first},@var{last}
4007Print lines from @var{first} to @var{last}. Both arguments are
4008linespecs.
4009
4010@item list ,@var{last}
4011Print lines ending with @var{last}.
4012
4013@item list @var{first},
4014Print lines starting with @var{first}.
4015
4016@item list +
4017Print lines just after the lines last printed.
4018
4019@item list -
4020Print lines just before the lines last printed.
4021
4022@item list
4023As described in the preceding table.
4024@end table
4025
4026Here are the ways of specifying a single source line---all the
4027kinds of linespec.
4028
4029@table @code
4030@item @var{number}
4031Specifies line @var{number} of the current source file.
4032When a @code{list} command has two linespecs, this refers to
4033the same source file as the first linespec.
4034
4035@item +@var{offset}
4036Specifies the line @var{offset} lines after the last line printed.
4037When used as the second linespec in a @code{list} command that has
4038two, this specifies the line @var{offset} lines down from the
4039first linespec.
4040
4041@item -@var{offset}
4042Specifies the line @var{offset} lines before the last line printed.
4043
4044@item @var{filename}:@var{number}
4045Specifies line @var{number} in the source file @var{filename}.
4046
4047@item @var{function}
4048Specifies the line that begins the body of the function @var{function}.
4049For example: in C, this is the line with the open brace.
4050
4051@item @var{filename}:@var{function}
4052Specifies the line of the open-brace that begins the body of the
4053function @var{function} in the file @var{filename}. You only need the
4054file name with a function name to avoid ambiguity when there are
4055identically named functions in different source files.
4056
4057@item *@var{address}
4058Specifies the line containing the program address @var{address}.
4059@var{address} may be any expression.
4060@end table
4061
6d2ebf8b 4062@node Search
c906108c
SS
4063@section Searching source files
4064@cindex searching
4065@kindex reverse-search
4066
4067There are two commands for searching through the current source file for a
4068regular expression.
4069
4070@table @code
4071@kindex search
4072@kindex forward-search
4073@item forward-search @var{regexp}
4074@itemx search @var{regexp}
4075The command @samp{forward-search @var{regexp}} checks each line,
4076starting with the one following the last line listed, for a match for
5d161b24 4077@var{regexp}. It lists the line that is found. You can use the
c906108c
SS
4078synonym @samp{search @var{regexp}} or abbreviate the command name as
4079@code{fo}.
4080
4081@item reverse-search @var{regexp}
4082The command @samp{reverse-search @var{regexp}} checks each line, starting
4083with the one before the last line listed and going backward, for a match
4084for @var{regexp}. It lists the line that is found. You can abbreviate
4085this command as @code{rev}.
4086@end table
c906108c 4087
6d2ebf8b 4088@node Source Path
c906108c
SS
4089@section Specifying source directories
4090
4091@cindex source path
4092@cindex directories for source files
4093Executable programs sometimes do not record the directories of the source
4094files from which they were compiled, just the names. Even when they do,
4095the directories could be moved between the compilation and your debugging
4096session. @value{GDBN} has a list of directories to search for source files;
4097this is called the @dfn{source path}. Each time @value{GDBN} wants a source file,
4098it tries all the directories in the list, in the order they are present
4099in the list, until it finds a file with the desired name. Note that
4100the executable search path is @emph{not} used for this purpose. Neither is
4101the current working directory, unless it happens to be in the source
4102path.
4103
4104If @value{GDBN} cannot find a source file in the source path, and the
4105object program records a directory, @value{GDBN} tries that directory
4106too. If the source path is empty, and there is no record of the
4107compilation directory, @value{GDBN} looks in the current directory as a
4108last resort.
4109
4110Whenever you reset or rearrange the source path, @value{GDBN} clears out
4111any information it has cached about where source files are found and where
4112each line is in the file.
4113
4114@kindex directory
4115@kindex dir
d4f3574e
SS
4116When you start @value{GDBN}, its source path includes only @samp{cdir}
4117and @samp{cwd}, in that order.
c906108c
SS
4118To add other directories, use the @code{directory} command.
4119
4120@table @code
4121@item directory @var{dirname} @dots{}
4122@item dir @var{dirname} @dots{}
4123Add directory @var{dirname} to the front of the source path. Several
d4f3574e
SS
4124directory names may be given to this command, separated by @samp{:}
4125(@samp{;} on MS-DOS and MS-Windows, where @samp{:} usually appears as
4126part of absolute file names) or
c906108c
SS
4127whitespace. You may specify a directory that is already in the source
4128path; this moves it forward, so @value{GDBN} searches it sooner.
4129
4130@kindex cdir
4131@kindex cwd
4132@kindex $cdir
4133@kindex $cwd
4134@cindex compilation directory
4135@cindex current directory
4136@cindex working directory
4137@cindex directory, current
4138@cindex directory, compilation
4139You can use the string @samp{$cdir} to refer to the compilation
4140directory (if one is recorded), and @samp{$cwd} to refer to the current
4141working directory. @samp{$cwd} is not the same as @samp{.}---the former
4142tracks the current working directory as it changes during your @value{GDBN}
4143session, while the latter is immediately expanded to the current
4144directory at the time you add an entry to the source path.
4145
4146@item directory
4147Reset the source path to empty again. This requires confirmation.
4148
4149@c RET-repeat for @code{directory} is explicitly disabled, but since
4150@c repeating it would be a no-op we do not say that. (thanks to RMS)
4151
4152@item show directories
4153@kindex show directories
4154Print the source path: show which directories it contains.
4155@end table
4156
4157If your source path is cluttered with directories that are no longer of
4158interest, @value{GDBN} may sometimes cause confusion by finding the wrong
4159versions of source. You can correct the situation as follows:
4160
4161@enumerate
4162@item
4163Use @code{directory} with no argument to reset the source path to empty.
4164
4165@item
4166Use @code{directory} with suitable arguments to reinstall the
4167directories you want in the source path. You can add all the
4168directories in one command.
4169@end enumerate
4170
6d2ebf8b 4171@node Machine Code
c906108c
SS
4172@section Source and machine code
4173
4174You can use the command @code{info line} to map source lines to program
4175addresses (and vice versa), and the command @code{disassemble} to display
4176a range of addresses as machine instructions. When run under @sc{gnu} Emacs
d4f3574e 4177mode, the @code{info line} command causes the arrow to point to the
5d161b24 4178line specified. Also, @code{info line} prints addresses in symbolic form as
c906108c
SS
4179well as hex.
4180
4181@table @code
4182@kindex info line
4183@item info line @var{linespec}
4184Print the starting and ending addresses of the compiled code for
4185source line @var{linespec}. You can specify source lines in any of
4186the ways understood by the @code{list} command (@pxref{List, ,Printing
4187source lines}).
4188@end table
4189
4190For example, we can use @code{info line} to discover the location of
4191the object code for the first line of function
4192@code{m4_changequote}:
4193
d4f3574e
SS
4194@c FIXME: I think this example should also show the addresses in
4195@c symbolic form, as they usually would be displayed.
c906108c 4196@smallexample
96a2c332 4197(@value{GDBP}) info line m4_changequote
c906108c
SS
4198Line 895 of "builtin.c" starts at pc 0x634c and ends at 0x6350.
4199@end smallexample
4200
4201@noindent
4202We can also inquire (using @code{*@var{addr}} as the form for
4203@var{linespec}) what source line covers a particular address:
4204@smallexample
4205(@value{GDBP}) info line *0x63ff
4206Line 926 of "builtin.c" starts at pc 0x63e4 and ends at 0x6404.
4207@end smallexample
4208
4209@cindex @code{$_} and @code{info line}
d4f3574e 4210@kindex x@r{, and }@code{info line}
c906108c
SS
4211After @code{info line}, the default address for the @code{x} command
4212is changed to the starting address of the line, so that @samp{x/i} is
4213sufficient to begin examining the machine code (@pxref{Memory,
4214,Examining memory}). Also, this address is saved as the value of the
4215convenience variable @code{$_} (@pxref{Convenience Vars, ,Convenience
4216variables}).
4217
4218@table @code
4219@kindex disassemble
4220@cindex assembly instructions
4221@cindex instructions, assembly
4222@cindex machine instructions
4223@cindex listing machine instructions
4224@item disassemble
4225This specialized command dumps a range of memory as machine
4226instructions. The default memory range is the function surrounding the
4227program counter of the selected frame. A single argument to this
4228command is a program counter value; @value{GDBN} dumps the function
4229surrounding this value. Two arguments specify a range of addresses
4230(first inclusive, second exclusive) to dump.
4231@end table
4232
c906108c
SS
4233The following example shows the disassembly of a range of addresses of
4234HP PA-RISC 2.0 code:
4235
4236@smallexample
4237(@value{GDBP}) disas 0x32c4 0x32e4
4238Dump of assembler code from 0x32c4 to 0x32e4:
42390x32c4 <main+204>: addil 0,dp
42400x32c8 <main+208>: ldw 0x22c(sr0,r1),r26
42410x32cc <main+212>: ldil 0x3000,r31
42420x32d0 <main+216>: ble 0x3f8(sr4,r31)
42430x32d4 <main+220>: ldo 0(r31),rp
42440x32d8 <main+224>: addil -0x800,dp
42450x32dc <main+228>: ldo 0x588(r1),r26
42460x32e0 <main+232>: ldil 0x3000,r31
4247End of assembler dump.
4248@end smallexample
c906108c
SS
4249
4250Some architectures have more than one commonly-used set of instruction
4251mnemonics or other syntax.
4252
4253@table @code
d4f3574e 4254@kindex set disassembly-flavor
c906108c
SS
4255@cindex assembly instructions
4256@cindex instructions, assembly
4257@cindex machine instructions
4258@cindex listing machine instructions
d4f3574e
SS
4259@cindex Intel disassembly flavor
4260@cindex AT&T disassembly flavor
4261@item set disassembly-flavor @var{instruction-set}
c906108c
SS
4262Select the instruction set to use when disassembling the
4263program via the @code{disassemble} or @code{x/i} commands.
4264
4265Currently this command is only defined for the Intel x86 family. You
d4f3574e
SS
4266can set @var{instruction-set} to either @code{intel} or @code{att}.
4267The default is @code{att}, the AT&T flavor used by default by Unix
4268assemblers for x86-based targets.
c906108c
SS
4269@end table
4270
4271
6d2ebf8b 4272@node Data
c906108c
SS
4273@chapter Examining Data
4274
4275@cindex printing data
4276@cindex examining data
4277@kindex print
4278@kindex inspect
4279@c "inspect" is not quite a synonym if you are using Epoch, which we do not
4280@c document because it is nonstandard... Under Epoch it displays in a
4281@c different window or something like that.
4282The usual way to examine data in your program is with the @code{print}
7a292a7a
SS
4283command (abbreviated @code{p}), or its synonym @code{inspect}. It
4284evaluates and prints the value of an expression of the language your
4285program is written in (@pxref{Languages, ,Using @value{GDBN} with
4286Different Languages}).
c906108c
SS
4287
4288@table @code
d4f3574e
SS
4289@item print @var{expr}
4290@itemx print /@var{f} @var{expr}
4291@var{expr} is an expression (in the source language). By default the
4292value of @var{expr} is printed in a format appropriate to its data type;
c906108c 4293you can choose a different format by specifying @samp{/@var{f}}, where
d4f3574e 4294@var{f} is a letter specifying the format; see @ref{Output Formats,,Output
c906108c
SS
4295formats}.
4296
4297@item print
4298@itemx print /@var{f}
d4f3574e 4299If you omit @var{expr}, @value{GDBN} displays the last value again (from the
c906108c
SS
4300@dfn{value history}; @pxref{Value History, ,Value history}). This allows you to
4301conveniently inspect the same value in an alternative format.
4302@end table
4303
4304A more low-level way of examining data is with the @code{x} command.
4305It examines data in memory at a specified address and prints it in a
4306specified format. @xref{Memory, ,Examining memory}.
4307
7a292a7a 4308If you are interested in information about types, or about how the
d4f3574e
SS
4309fields of a struct or a class are declared, use the @code{ptype @var{exp}}
4310command rather than @code{print}. @xref{Symbols, ,Examining the Symbol
7a292a7a 4311Table}.
c906108c
SS
4312
4313@menu
4314* Expressions:: Expressions
4315* Variables:: Program variables
4316* Arrays:: Artificial arrays
4317* Output Formats:: Output formats
4318* Memory:: Examining memory
4319* Auto Display:: Automatic display
4320* Print Settings:: Print settings
4321* Value History:: Value history
4322* Convenience Vars:: Convenience variables
4323* Registers:: Registers
c906108c 4324* Floating Point Hardware:: Floating point hardware
c906108c
SS
4325@end menu
4326
6d2ebf8b 4327@node Expressions
c906108c
SS
4328@section Expressions
4329
4330@cindex expressions
4331@code{print} and many other @value{GDBN} commands accept an expression and
4332compute its value. Any kind of constant, variable or operator defined
4333by the programming language you are using is valid in an expression in
4334@value{GDBN}. This includes conditional expressions, function calls, casts
4335and string constants. It unfortunately does not include symbols defined
4336by preprocessor @code{#define} commands.
4337
d4f3574e
SS
4338@value{GDBN} supports array constants in expressions input by
4339the user. The syntax is @{@var{element}, @var{element}@dots{}@}. For example,
5d161b24 4340you can use the command @code{print @{1, 2, 3@}} to build up an array in
d4f3574e 4341memory that is @code{malloc}ed in the target program.
c906108c 4342
c906108c
SS
4343Because C is so widespread, most of the expressions shown in examples in
4344this manual are in C. @xref{Languages, , Using @value{GDBN} with Different
4345Languages}, for information on how to use expressions in other
4346languages.
4347
4348In this section, we discuss operators that you can use in @value{GDBN}
4349expressions regardless of your programming language.
4350
4351Casts are supported in all languages, not just in C, because it is so
4352useful to cast a number into a pointer in order to examine a structure
4353at that address in memory.
4354@c FIXME: casts supported---Mod2 true?
c906108c
SS
4355
4356@value{GDBN} supports these operators, in addition to those common
4357to programming languages:
4358
4359@table @code
4360@item @@
4361@samp{@@} is a binary operator for treating parts of memory as arrays.
4362@xref{Arrays, ,Artificial arrays}, for more information.
4363
4364@item ::
4365@samp{::} allows you to specify a variable in terms of the file or
4366function where it is defined. @xref{Variables, ,Program variables}.
4367
4368@cindex @{@var{type}@}
4369@cindex type casting memory
4370@cindex memory, viewing as typed object
4371@cindex casts, to view memory
4372@item @{@var{type}@} @var{addr}
4373Refers to an object of type @var{type} stored at address @var{addr} in
4374memory. @var{addr} may be any expression whose value is an integer or
4375pointer (but parentheses are required around binary operators, just as in
4376a cast). This construct is allowed regardless of what kind of data is
4377normally supposed to reside at @var{addr}.
4378@end table
4379
6d2ebf8b 4380@node Variables
c906108c
SS
4381@section Program variables
4382
4383The most common kind of expression to use is the name of a variable
4384in your program.
4385
4386Variables in expressions are understood in the selected stack frame
4387(@pxref{Selection, ,Selecting a frame}); they must be either:
4388
4389@itemize @bullet
4390@item
4391global (or file-static)
4392@end itemize
4393
5d161b24 4394@noindent or
c906108c
SS
4395
4396@itemize @bullet
4397@item
4398visible according to the scope rules of the
4399programming language from the point of execution in that frame
5d161b24 4400@end itemize
c906108c
SS
4401
4402@noindent This means that in the function
4403
4404@example
4405foo (a)
4406 int a;
4407@{
4408 bar (a);
4409 @{
4410 int b = test ();
4411 bar (b);
4412 @}
4413@}
4414@end example
4415
4416@noindent
4417you can examine and use the variable @code{a} whenever your program is
4418executing within the function @code{foo}, but you can only use or
4419examine the variable @code{b} while your program is executing inside
4420the block where @code{b} is declared.
4421
4422@cindex variable name conflict
4423There is an exception: you can refer to a variable or function whose
4424scope is a single source file even if the current execution point is not
4425in this file. But it is possible to have more than one such variable or
4426function with the same name (in different source files). If that
4427happens, referring to that name has unpredictable effects. If you wish,
4428you can specify a static variable in a particular function or file,
4429using the colon-colon notation:
4430
d4f3574e 4431@cindex colon-colon, context for variables/functions
c906108c
SS
4432@iftex
4433@c info cannot cope with a :: index entry, but why deprive hard copy readers?
4434@kindex ::
4435@end iftex
4436@example
4437@var{file}::@var{variable}
4438@var{function}::@var{variable}
4439@end example
4440
4441@noindent
4442Here @var{file} or @var{function} is the name of the context for the
4443static @var{variable}. In the case of file names, you can use quotes to
4444make sure @value{GDBN} parses the file name as a single word---for example,
4445to print a global value of @code{x} defined in @file{f2.c}:
4446
4447@example
4448(@value{GDBP}) p 'f2.c'::x
4449@end example
4450
c906108c
SS
4451@cindex C++ scope resolution
4452This use of @samp{::} is very rarely in conflict with the very similar
4453use of the same notation in C++. @value{GDBN} also supports use of the C++
4454scope resolution operator in @value{GDBN} expressions.
4455@c FIXME: Um, so what happens in one of those rare cases where it's in
4456@c conflict?? --mew
c906108c
SS
4457
4458@cindex wrong values
4459@cindex variable values, wrong
4460@quotation
4461@emph{Warning:} Occasionally, a local variable may appear to have the
4462wrong value at certain points in a function---just after entry to a new
4463scope, and just before exit.
4464@end quotation
4465You may see this problem when you are stepping by machine instructions.
4466This is because, on most machines, it takes more than one instruction to
4467set up a stack frame (including local variable definitions); if you are
4468stepping by machine instructions, variables may appear to have the wrong
4469values until the stack frame is completely built. On exit, it usually
4470also takes more than one machine instruction to destroy a stack frame;
4471after you begin stepping through that group of instructions, local
4472variable definitions may be gone.
4473
4474This may also happen when the compiler does significant optimizations.
4475To be sure of always seeing accurate values, turn off all optimization
4476when compiling.
4477
d4f3574e
SS
4478@cindex ``No symbol "foo" in current context''
4479Another possible effect of compiler optimizations is to optimize
4480unused variables out of existence, or assign variables to registers (as
4481opposed to memory addresses). Depending on the support for such cases
4482offered by the debug info format used by the compiler, @value{GDBN}
4483might not be able to display values for such local variables. If that
4484happens, @value{GDBN} will print a message like this:
4485
4486@example
4487No symbol "foo" in current context.
4488@end example
4489
4490To solve such problems, either recompile without optimizations, or use a
4491different debug info format, if the compiler supports several such
4492formats. For example, @value{NGCC}, the @sc{gnu} C/C++ compiler usually
4493supports the @samp{-gstabs} option. @samp{-gstabs} produces debug info
4494in a format that is superior to formats such as COFF. You may be able
4495to use DWARF-2 (@samp{-gdwarf-2}), which is also an effective form for
4496debug info. See @ref{Debugging Options,,Options for Debugging Your
4497Program or @sc{gnu} CC, gcc.info, Using @sc{gnu} CC}, for more
4498information.
4499
4500
6d2ebf8b 4501@node Arrays
c906108c
SS
4502@section Artificial arrays
4503
4504@cindex artificial array
4505@kindex @@
4506It is often useful to print out several successive objects of the
4507same type in memory; a section of an array, or an array of
4508dynamically determined size for which only a pointer exists in the
4509program.
4510
4511You can do this by referring to a contiguous span of memory as an
4512@dfn{artificial array}, using the binary operator @samp{@@}. The left
4513operand of @samp{@@} should be the first element of the desired array
4514and be an individual object. The right operand should be the desired length
4515of the array. The result is an array value whose elements are all of
4516the type of the left argument. The first element is actually the left
4517argument; the second element comes from bytes of memory immediately
4518following those that hold the first element, and so on. Here is an
4519example. If a program says
4520
4521@example
4522int *array = (int *) malloc (len * sizeof (int));
4523@end example
4524
4525@noindent
4526you can print the contents of @code{array} with
4527
4528@example
4529p *array@@len
4530@end example
4531
4532The left operand of @samp{@@} must reside in memory. Array values made
4533with @samp{@@} in this way behave just like other arrays in terms of
4534subscripting, and are coerced to pointers when used in expressions.
4535Artificial arrays most often appear in expressions via the value history
4536(@pxref{Value History, ,Value history}), after printing one out.
4537
4538Another way to create an artificial array is to use a cast.
4539This re-interprets a value as if it were an array.
4540The value need not be in memory:
4541@example
4542(@value{GDBP}) p/x (short[2])0x12345678
4543$1 = @{0x1234, 0x5678@}
4544@end example
4545
4546As a convenience, if you leave the array length out (as in
c3f6f71d 4547@samp{(@var{type}[])@var{value}}) @value{GDBN} calculates the size to fill
c906108c
SS
4548the value (as @samp{sizeof(@var{value})/sizeof(@var{type})}:
4549@example
4550(@value{GDBP}) p/x (short[])0x12345678
4551$2 = @{0x1234, 0x5678@}
4552@end example
4553
4554Sometimes the artificial array mechanism is not quite enough; in
4555moderately complex data structures, the elements of interest may not
4556actually be adjacent---for example, if you are interested in the values
4557of pointers in an array. One useful work-around in this situation is
4558to use a convenience variable (@pxref{Convenience Vars, ,Convenience
4559variables}) as a counter in an expression that prints the first
4560interesting value, and then repeat that expression via @key{RET}. For
4561instance, suppose you have an array @code{dtab} of pointers to
4562structures, and you are interested in the values of a field @code{fv}
4563in each structure. Here is an example of what you might type:
4564
4565@example
4566set $i = 0
4567p dtab[$i++]->fv
4568@key{RET}
4569@key{RET}
4570@dots{}
4571@end example
4572
6d2ebf8b 4573@node Output Formats
c906108c
SS
4574@section Output formats
4575
4576@cindex formatted output
4577@cindex output formats
4578By default, @value{GDBN} prints a value according to its data type. Sometimes
4579this is not what you want. For example, you might want to print a number
4580in hex, or a pointer in decimal. Or you might want to view data in memory
4581at a certain address as a character string or as an instruction. To do
4582these things, specify an @dfn{output format} when you print a value.
4583
4584The simplest use of output formats is to say how to print a value
4585already computed. This is done by starting the arguments of the
4586@code{print} command with a slash and a format letter. The format
4587letters supported are:
4588
4589@table @code
4590@item x
4591Regard the bits of the value as an integer, and print the integer in
4592hexadecimal.
4593
4594@item d
4595Print as integer in signed decimal.
4596
4597@item u
4598Print as integer in unsigned decimal.
4599
4600@item o
4601Print as integer in octal.
4602
4603@item t
4604Print as integer in binary. The letter @samp{t} stands for ``two''.
4605@footnote{@samp{b} cannot be used because these format letters are also
4606used with the @code{x} command, where @samp{b} stands for ``byte'';
d4f3574e 4607see @ref{Memory,,Examining memory}.}
c906108c
SS
4608
4609@item a
4610@cindex unknown address, locating
4611Print as an address, both absolute in hexadecimal and as an offset from
4612the nearest preceding symbol. You can use this format used to discover
4613where (in what function) an unknown address is located:
4614
4615@example
4616(@value{GDBP}) p/a 0x54320
4617$3 = 0x54320 <_initialize_vx+396>
4618@end example
4619
4620@item c
4621Regard as an integer and print it as a character constant.
4622
4623@item f
4624Regard the bits of the value as a floating point number and print
4625using typical floating point syntax.
4626@end table
4627
4628For example, to print the program counter in hex (@pxref{Registers}), type
4629
4630@example
4631p/x $pc
4632@end example
4633
4634@noindent
4635Note that no space is required before the slash; this is because command
4636names in @value{GDBN} cannot contain a slash.
4637
4638To reprint the last value in the value history with a different format,
4639you can use the @code{print} command with just a format and no
4640expression. For example, @samp{p/x} reprints the last value in hex.
4641
6d2ebf8b 4642@node Memory
c906108c
SS
4643@section Examining memory
4644
4645You can use the command @code{x} (for ``examine'') to examine memory in
4646any of several formats, independently of your program's data types.
4647
4648@cindex examining memory
4649@table @code
4650@kindex x
4651@item x/@var{nfu} @var{addr}
4652@itemx x @var{addr}
4653@itemx x
4654Use the @code{x} command to examine memory.
4655@end table
4656
4657@var{n}, @var{f}, and @var{u} are all optional parameters that specify how
4658much memory to display and how to format it; @var{addr} is an
4659expression giving the address where you want to start displaying memory.
4660If you use defaults for @var{nfu}, you need not type the slash @samp{/}.
4661Several commands set convenient defaults for @var{addr}.
4662
4663@table @r
4664@item @var{n}, the repeat count
4665The repeat count is a decimal integer; the default is 1. It specifies
4666how much memory (counting by units @var{u}) to display.
4667@c This really is **decimal**; unaffected by 'set radix' as of GDB
4668@c 4.1.2.
4669
4670@item @var{f}, the display format
4671The display format is one of the formats used by @code{print},
4672@samp{s} (null-terminated string), or @samp{i} (machine instruction).
4673The default is @samp{x} (hexadecimal) initially.
4674The default changes each time you use either @code{x} or @code{print}.
4675
4676@item @var{u}, the unit size
4677The unit size is any of
4678
4679@table @code
4680@item b
4681Bytes.
4682@item h
4683Halfwords (two bytes).
4684@item w
4685Words (four bytes). This is the initial default.
4686@item g
4687Giant words (eight bytes).
4688@end table
4689
4690Each time you specify a unit size with @code{x}, that size becomes the
4691default unit the next time you use @code{x}. (For the @samp{s} and
4692@samp{i} formats, the unit size is ignored and is normally not written.)
4693
4694@item @var{addr}, starting display address
4695@var{addr} is the address where you want @value{GDBN} to begin displaying
4696memory. The expression need not have a pointer value (though it may);
4697it is always interpreted as an integer address of a byte of memory.
4698@xref{Expressions, ,Expressions}, for more information on expressions. The default for
4699@var{addr} is usually just after the last address examined---but several
4700other commands also set the default address: @code{info breakpoints} (to
4701the address of the last breakpoint listed), @code{info line} (to the
4702starting address of a line), and @code{print} (if you use it to display
4703a value from memory).
4704@end table
4705
4706For example, @samp{x/3uh 0x54320} is a request to display three halfwords
4707(@code{h}) of memory, formatted as unsigned decimal integers (@samp{u}),
4708starting at address @code{0x54320}. @samp{x/4xw $sp} prints the four
4709words (@samp{w}) of memory above the stack pointer (here, @samp{$sp};
d4f3574e 4710@pxref{Registers, ,Registers}) in hexadecimal (@samp{x}).
c906108c
SS
4711
4712Since the letters indicating unit sizes are all distinct from the
4713letters specifying output formats, you do not have to remember whether
4714unit size or format comes first; either order works. The output
4715specifications @samp{4xw} and @samp{4wx} mean exactly the same thing.
4716(However, the count @var{n} must come first; @samp{wx4} does not work.)
4717
4718Even though the unit size @var{u} is ignored for the formats @samp{s}
4719and @samp{i}, you might still want to use a count @var{n}; for example,
4720@samp{3i} specifies that you want to see three machine instructions,
4721including any operands. The command @code{disassemble} gives an
d4f3574e 4722alternative way of inspecting machine instructions; see @ref{Machine
c906108c
SS
4723Code,,Source and machine code}.
4724
4725All the defaults for the arguments to @code{x} are designed to make it
4726easy to continue scanning memory with minimal specifications each time
4727you use @code{x}. For example, after you have inspected three machine
4728instructions with @samp{x/3i @var{addr}}, you can inspect the next seven
4729with just @samp{x/7}. If you use @key{RET} to repeat the @code{x} command,
4730the repeat count @var{n} is used again; the other arguments default as
4731for successive uses of @code{x}.
4732
4733@cindex @code{$_}, @code{$__}, and value history
4734The addresses and contents printed by the @code{x} command are not saved
4735in the value history because there is often too much of them and they
4736would get in the way. Instead, @value{GDBN} makes these values available for
4737subsequent use in expressions as values of the convenience variables
4738@code{$_} and @code{$__}. After an @code{x} command, the last address
4739examined is available for use in expressions in the convenience variable
4740@code{$_}. The contents of that address, as examined, are available in
4741the convenience variable @code{$__}.
4742
4743If the @code{x} command has a repeat count, the address and contents saved
4744are from the last memory unit printed; this is not the same as the last
4745address printed if several units were printed on the last line of output.
4746
6d2ebf8b 4747@node Auto Display
c906108c
SS
4748@section Automatic display
4749@cindex automatic display
4750@cindex display of expressions
4751
4752If you find that you want to print the value of an expression frequently
4753(to see how it changes), you might want to add it to the @dfn{automatic
4754display list} so that @value{GDBN} prints its value each time your program stops.
4755Each expression added to the list is given a number to identify it;
4756to remove an expression from the list, you specify that number.
4757The automatic display looks like this:
4758
4759@example
47602: foo = 38
47613: bar[5] = (struct hack *) 0x3804
4762@end example
4763
4764@noindent
4765This display shows item numbers, expressions and their current values. As with
4766displays you request manually using @code{x} or @code{print}, you can
4767specify the output format you prefer; in fact, @code{display} decides
4768whether to use @code{print} or @code{x} depending on how elaborate your
4769format specification is---it uses @code{x} if you specify a unit size,
4770or one of the two formats (@samp{i} and @samp{s}) that are only
4771supported by @code{x}; otherwise it uses @code{print}.
4772
4773@table @code
4774@kindex display
d4f3574e
SS
4775@item display @var{expr}
4776Add the expression @var{expr} to the list of expressions to display
c906108c
SS
4777each time your program stops. @xref{Expressions, ,Expressions}.
4778
4779@code{display} does not repeat if you press @key{RET} again after using it.
4780
d4f3574e 4781@item display/@var{fmt} @var{expr}
c906108c 4782For @var{fmt} specifying only a display format and not a size or
d4f3574e 4783count, add the expression @var{expr} to the auto-display list but
c906108c
SS
4784arrange to display it each time in the specified format @var{fmt}.
4785@xref{Output Formats,,Output formats}.
4786
4787@item display/@var{fmt} @var{addr}
4788For @var{fmt} @samp{i} or @samp{s}, or including a unit-size or a
4789number of units, add the expression @var{addr} as a memory address to
4790be examined each time your program stops. Examining means in effect
4791doing @samp{x/@var{fmt} @var{addr}}. @xref{Memory, ,Examining memory}.
4792@end table
4793
4794For example, @samp{display/i $pc} can be helpful, to see the machine
4795instruction about to be executed each time execution stops (@samp{$pc}
d4f3574e 4796is a common name for the program counter; @pxref{Registers, ,Registers}).
c906108c
SS
4797
4798@table @code
4799@kindex delete display
4800@kindex undisplay
4801@item undisplay @var{dnums}@dots{}
4802@itemx delete display @var{dnums}@dots{}
4803Remove item numbers @var{dnums} from the list of expressions to display.
4804
4805@code{undisplay} does not repeat if you press @key{RET} after using it.
4806(Otherwise you would just get the error @samp{No display number @dots{}}.)
4807
4808@kindex disable display
4809@item disable display @var{dnums}@dots{}
4810Disable the display of item numbers @var{dnums}. A disabled display
4811item is not printed automatically, but is not forgotten. It may be
4812enabled again later.
4813
4814@kindex enable display
4815@item enable display @var{dnums}@dots{}
4816Enable display of item numbers @var{dnums}. It becomes effective once
4817again in auto display of its expression, until you specify otherwise.
4818
4819@item display
4820Display the current values of the expressions on the list, just as is
4821done when your program stops.
4822
4823@kindex info display
4824@item info display
4825Print the list of expressions previously set up to display
4826automatically, each one with its item number, but without showing the
4827values. This includes disabled expressions, which are marked as such.
4828It also includes expressions which would not be displayed right now
4829because they refer to automatic variables not currently available.
4830@end table
4831
4832If a display expression refers to local variables, then it does not make
4833sense outside the lexical context for which it was set up. Such an
4834expression is disabled when execution enters a context where one of its
4835variables is not defined. For example, if you give the command
4836@code{display last_char} while inside a function with an argument
4837@code{last_char}, @value{GDBN} displays this argument while your program
4838continues to stop inside that function. When it stops elsewhere---where
4839there is no variable @code{last_char}---the display is disabled
4840automatically. The next time your program stops where @code{last_char}
4841is meaningful, you can enable the display expression once again.
4842
6d2ebf8b 4843@node Print Settings
c906108c
SS
4844@section Print settings
4845
4846@cindex format options
4847@cindex print settings
4848@value{GDBN} provides the following ways to control how arrays, structures,
4849and symbols are printed.
4850
4851@noindent
4852These settings are useful for debugging programs in any language:
4853
4854@table @code
4855@kindex set print address
4856@item set print address
4857@itemx set print address on
4858@value{GDBN} prints memory addresses showing the location of stack
4859traces, structure values, pointer values, breakpoints, and so forth,
4860even when it also displays the contents of those addresses. The default
4861is @code{on}. For example, this is what a stack frame display looks like with
4862@code{set print address on}:
4863
4864@smallexample
4865@group
4866(@value{GDBP}) f
4867#0 set_quotes (lq=0x34c78 "<<", rq=0x34c88 ">>")
4868 at input.c:530
4869530 if (lquote != def_lquote)
4870@end group
4871@end smallexample
4872
4873@item set print address off
4874Do not print addresses when displaying their contents. For example,
4875this is the same stack frame displayed with @code{set print address off}:
4876
4877@smallexample
4878@group
4879(@value{GDBP}) set print addr off
4880(@value{GDBP}) f
4881#0 set_quotes (lq="<<", rq=">>") at input.c:530
4882530 if (lquote != def_lquote)
4883@end group
4884@end smallexample
4885
4886You can use @samp{set print address off} to eliminate all machine
4887dependent displays from the @value{GDBN} interface. For example, with
4888@code{print address off}, you should get the same text for backtraces on
4889all machines---whether or not they involve pointer arguments.
4890
4891@kindex show print address
4892@item show print address
4893Show whether or not addresses are to be printed.
4894@end table
4895
4896When @value{GDBN} prints a symbolic address, it normally prints the
4897closest earlier symbol plus an offset. If that symbol does not uniquely
4898identify the address (for example, it is a name whose scope is a single
4899source file), you may need to clarify. One way to do this is with
4900@code{info line}, for example @samp{info line *0x4537}. Alternately,
4901you can set @value{GDBN} to print the source file and line number when
4902it prints a symbolic address:
4903
4904@table @code
4905@kindex set print symbol-filename
4906@item set print symbol-filename on
4907Tell @value{GDBN} to print the source file name and line number of a
4908symbol in the symbolic form of an address.
4909
4910@item set print symbol-filename off
4911Do not print source file name and line number of a symbol. This is the
4912default.
4913
4914@kindex show print symbol-filename
4915@item show print symbol-filename
4916Show whether or not @value{GDBN} will print the source file name and
4917line number of a symbol in the symbolic form of an address.
4918@end table
4919
4920Another situation where it is helpful to show symbol filenames and line
4921numbers is when disassembling code; @value{GDBN} shows you the line
4922number and source file that corresponds to each instruction.
4923
4924Also, you may wish to see the symbolic form only if the address being
4925printed is reasonably close to the closest earlier symbol:
4926
4927@table @code
4928@kindex set print max-symbolic-offset
4929@item set print max-symbolic-offset @var{max-offset}
4930Tell @value{GDBN} to only display the symbolic form of an address if the
4931offset between the closest earlier symbol and the address is less than
5d161b24 4932@var{max-offset}. The default is 0, which tells @value{GDBN}
c906108c
SS
4933to always print the symbolic form of an address if any symbol precedes it.
4934
4935@kindex show print max-symbolic-offset
4936@item show print max-symbolic-offset
4937Ask how large the maximum offset is that @value{GDBN} prints in a
4938symbolic address.
4939@end table
4940
4941@cindex wild pointer, interpreting
4942@cindex pointer, finding referent
4943If you have a pointer and you are not sure where it points, try
4944@samp{set print symbol-filename on}. Then you can determine the name
4945and source file location of the variable where it points, using
4946@samp{p/a @var{pointer}}. This interprets the address in symbolic form.
4947For example, here @value{GDBN} shows that a variable @code{ptt} points
4948at another variable @code{t}, defined in @file{hi2.c}:
4949
4950@example
4951(@value{GDBP}) set print symbol-filename on
4952(@value{GDBP}) p/a ptt
4953$4 = 0xe008 <t in hi2.c>
4954@end example
4955
4956@quotation
4957@emph{Warning:} For pointers that point to a local variable, @samp{p/a}
4958does not show the symbol name and filename of the referent, even with
4959the appropriate @code{set print} options turned on.
4960@end quotation
4961
4962Other settings control how different kinds of objects are printed:
4963
4964@table @code
4965@kindex set print array
4966@item set print array
4967@itemx set print array on
4968Pretty print arrays. This format is more convenient to read,
4969but uses more space. The default is off.
4970
4971@item set print array off
4972Return to compressed format for arrays.
4973
4974@kindex show print array
4975@item show print array
4976Show whether compressed or pretty format is selected for displaying
4977arrays.
4978
4979@kindex set print elements
4980@item set print elements @var{number-of-elements}
4981Set a limit on how many elements of an array @value{GDBN} will print.
4982If @value{GDBN} is printing a large array, it stops printing after it has
4983printed the number of elements set by the @code{set print elements} command.
4984This limit also applies to the display of strings.
d4f3574e 4985When @value{GDBN} starts, this limit is set to 200.
c906108c
SS
4986Setting @var{number-of-elements} to zero means that the printing is unlimited.
4987
4988@kindex show print elements
4989@item show print elements
4990Display the number of elements of a large array that @value{GDBN} will print.
4991If the number is 0, then the printing is unlimited.
4992
4993@kindex set print null-stop
4994@item set print null-stop
4995Cause @value{GDBN} to stop printing the characters of an array when the first
d4f3574e 4996@sc{null} is encountered. This is useful when large arrays actually
c906108c 4997contain only short strings.
d4f3574e 4998The default is off.
c906108c
SS
4999
5000@kindex set print pretty
5001@item set print pretty on
5d161b24 5002Cause @value{GDBN} to print structures in an indented format with one member
c906108c
SS
5003per line, like this:
5004
5005@smallexample
5006@group
5007$1 = @{
5008 next = 0x0,
5009 flags = @{
5010 sweet = 1,
5011 sour = 1
5012 @},
5013 meat = 0x54 "Pork"
5014@}
5015@end group
5016@end smallexample
5017
5018@item set print pretty off
5019Cause @value{GDBN} to print structures in a compact format, like this:
5020
5021@smallexample
5022@group
5023$1 = @{next = 0x0, flags = @{sweet = 1, sour = 1@}, \
5024meat = 0x54 "Pork"@}
5025@end group
5026@end smallexample
5027
5028@noindent
5029This is the default format.
5030
5031@kindex show print pretty
5032@item show print pretty
5033Show which format @value{GDBN} is using to print structures.
5034
5035@kindex set print sevenbit-strings
5036@item set print sevenbit-strings on
5037Print using only seven-bit characters; if this option is set,
5038@value{GDBN} displays any eight-bit characters (in strings or
5039character values) using the notation @code{\}@var{nnn}. This setting is
5040best if you are working in English (@sc{ascii}) and you use the
5041high-order bit of characters as a marker or ``meta'' bit.
5042
5043@item set print sevenbit-strings off
5044Print full eight-bit characters. This allows the use of more
5045international character sets, and is the default.
5046
5047@kindex show print sevenbit-strings
5048@item show print sevenbit-strings
5049Show whether or not @value{GDBN} is printing only seven-bit characters.
5050
5051@kindex set print union
5052@item set print union on
5d161b24 5053Tell @value{GDBN} to print unions which are contained in structures. This
c906108c
SS
5054is the default setting.
5055
5056@item set print union off
5057Tell @value{GDBN} not to print unions which are contained in structures.
5058
5059@kindex show print union
5060@item show print union
5061Ask @value{GDBN} whether or not it will print unions which are contained in
5062structures.
5063
5064For example, given the declarations
5065
5066@smallexample
5067typedef enum @{Tree, Bug@} Species;
5068typedef enum @{Big_tree, Acorn, Seedling@} Tree_forms;
5d161b24 5069typedef enum @{Caterpillar, Cocoon, Butterfly@}
c906108c
SS
5070 Bug_forms;
5071
5072struct thing @{
5073 Species it;
5074 union @{
5075 Tree_forms tree;
5076 Bug_forms bug;
5077 @} form;
5078@};
5079
5080struct thing foo = @{Tree, @{Acorn@}@};
5081@end smallexample
5082
5083@noindent
5084with @code{set print union on} in effect @samp{p foo} would print
5085
5086@smallexample
5087$1 = @{it = Tree, form = @{tree = Acorn, bug = Cocoon@}@}
5088@end smallexample
5089
5090@noindent
5091and with @code{set print union off} in effect it would print
5092
5093@smallexample
5094$1 = @{it = Tree, form = @{...@}@}
5095@end smallexample
5096@end table
5097
c906108c
SS
5098@need 1000
5099@noindent
5100These settings are of interest when debugging C++ programs:
5101
5102@table @code
5103@cindex demangling
5104@kindex set print demangle
5105@item set print demangle
5106@itemx set print demangle on
5107Print C++ names in their source form rather than in the encoded
5108(``mangled'') form passed to the assembler and linker for type-safe
d4f3574e 5109linkage. The default is on.
c906108c
SS
5110
5111@kindex show print demangle
5112@item show print demangle
5113Show whether C++ names are printed in mangled or demangled form.
5114
5115@kindex set print asm-demangle
5116@item set print asm-demangle
5117@itemx set print asm-demangle on
5118Print C++ names in their source form rather than their mangled form, even
5119in assembler code printouts such as instruction disassemblies.
5120The default is off.
5121
5122@kindex show print asm-demangle
5123@item show print asm-demangle
5124Show whether C++ names in assembly listings are printed in mangled
5125or demangled form.
5126
5127@kindex set demangle-style
5128@cindex C++ symbol decoding style
5129@cindex symbol decoding style, C++
5130@item set demangle-style @var{style}
5131Choose among several encoding schemes used by different compilers to
5132represent C++ names. The choices for @var{style} are currently:
5133
5134@table @code
5135@item auto
5136Allow @value{GDBN} to choose a decoding style by inspecting your program.
5137
5138@item gnu
5d161b24 5139Decode based on the @sc{gnu} C++ compiler (@code{g++}) encoding algorithm.
c906108c 5140This is the default.
c906108c
SS
5141
5142@item hp
5143Decode based on the HP ANSI C++ (@code{aCC}) encoding algorithm.
5144
5145@item lucid
5146Decode based on the Lucid C++ compiler (@code{lcc}) encoding algorithm.
5147
5148@item arm
5149Decode using the algorithm in the @cite{C++ Annotated Reference Manual}.
5150@strong{Warning:} this setting alone is not sufficient to allow
5151debugging @code{cfront}-generated executables. @value{GDBN} would
5152require further enhancement to permit that.
5153
5154@end table
5155If you omit @var{style}, you will see a list of possible formats.
5156
5157@kindex show demangle-style
5158@item show demangle-style
5159Display the encoding style currently in use for decoding C++ symbols.
5160
5161@kindex set print object
5162@item set print object
5163@itemx set print object on
5164When displaying a pointer to an object, identify the @emph{actual}
5165(derived) type of the object rather than the @emph{declared} type, using
5166the virtual function table.
5167
5168@item set print object off
5169Display only the declared type of objects, without reference to the
5170virtual function table. This is the default setting.
5171
5172@kindex show print object
5173@item show print object
5174Show whether actual, or declared, object types are displayed.
5175
5176@kindex set print static-members
5177@item set print static-members
5178@itemx set print static-members on
5179Print static members when displaying a C++ object. The default is on.
5180
5181@item set print static-members off
5182Do not print static members when displaying a C++ object.
5183
5184@kindex show print static-members
5185@item show print static-members
5186Show whether C++ static members are printed, or not.
5187
5188@c These don't work with HP ANSI C++ yet.
5189@kindex set print vtbl
5190@item set print vtbl
5191@itemx set print vtbl on
5192Pretty print C++ virtual function tables. The default is off.
c906108c
SS
5193(The @code{vtbl} commands do not work on programs compiled with the HP
5194ANSI C++ compiler (@code{aCC}).)
c906108c
SS
5195
5196@item set print vtbl off
5197Do not pretty print C++ virtual function tables.
5198
5199@kindex show print vtbl
5200@item show print vtbl
5201Show whether C++ virtual function tables are pretty printed, or not.
5202@end table
c906108c 5203
6d2ebf8b 5204@node Value History
c906108c
SS
5205@section Value history
5206
5207@cindex value history
5d161b24
DB
5208Values printed by the @code{print} command are saved in the @value{GDBN}
5209@dfn{value history}. This allows you to refer to them in other expressions.
5210Values are kept until the symbol table is re-read or discarded
5211(for example with the @code{file} or @code{symbol-file} commands).
5212When the symbol table changes, the value history is discarded,
5213since the values may contain pointers back to the types defined in the
c906108c
SS
5214symbol table.
5215
5216@cindex @code{$}
5217@cindex @code{$$}
5218@cindex history number
5219The values printed are given @dfn{history numbers} by which you can
5220refer to them. These are successive integers starting with one.
5221@code{print} shows you the history number assigned to a value by
5222printing @samp{$@var{num} = } before the value; here @var{num} is the
5223history number.
5224
5225To refer to any previous value, use @samp{$} followed by the value's
5226history number. The way @code{print} labels its output is designed to
5227remind you of this. Just @code{$} refers to the most recent value in
5228the history, and @code{$$} refers to the value before that.
5229@code{$$@var{n}} refers to the @var{n}th value from the end; @code{$$2}
5230is the value just prior to @code{$$}, @code{$$1} is equivalent to
5231@code{$$}, and @code{$$0} is equivalent to @code{$}.
5232
5233For example, suppose you have just printed a pointer to a structure and
5234want to see the contents of the structure. It suffices to type
5235
5236@example
5237p *$
5238@end example
5239
5240If you have a chain of structures where the component @code{next} points
5241to the next one, you can print the contents of the next one with this:
5242
5243@example
5244p *$.next
5245@end example
5246
5247@noindent
5248You can print successive links in the chain by repeating this
5249command---which you can do by just typing @key{RET}.
5250
5251Note that the history records values, not expressions. If the value of
5252@code{x} is 4 and you type these commands:
5253
5254@example
5255print x
5256set x=5
5257@end example
5258
5259@noindent
5260then the value recorded in the value history by the @code{print} command
5261remains 4 even though the value of @code{x} has changed.
5262
5263@table @code
5264@kindex show values
5265@item show values
5266Print the last ten values in the value history, with their item numbers.
5267This is like @samp{p@ $$9} repeated ten times, except that @code{show
5268values} does not change the history.
5269
5270@item show values @var{n}
5271Print ten history values centered on history item number @var{n}.
5272
5273@item show values +
5274Print ten history values just after the values last printed. If no more
5275values are available, @code{show values +} produces no display.
5276@end table
5277
5278Pressing @key{RET} to repeat @code{show values @var{n}} has exactly the
5279same effect as @samp{show values +}.
5280
6d2ebf8b 5281@node Convenience Vars
c906108c
SS
5282@section Convenience variables
5283
5284@cindex convenience variables
5285@value{GDBN} provides @dfn{convenience variables} that you can use within
5286@value{GDBN} to hold on to a value and refer to it later. These variables
5287exist entirely within @value{GDBN}; they are not part of your program, and
5288setting a convenience variable has no direct effect on further execution
5289of your program. That is why you can use them freely.
5290
5291Convenience variables are prefixed with @samp{$}. Any name preceded by
5292@samp{$} can be used for a convenience variable, unless it is one of
d4f3574e 5293the predefined machine-specific register names (@pxref{Registers, ,Registers}).
c906108c
SS
5294(Value history references, in contrast, are @emph{numbers} preceded
5295by @samp{$}. @xref{Value History, ,Value history}.)
5296
5297You can save a value in a convenience variable with an assignment
5298expression, just as you would set a variable in your program.
5299For example:
5300
5301@example
5302set $foo = *object_ptr
5303@end example
5304
5305@noindent
5306would save in @code{$foo} the value contained in the object pointed to by
5307@code{object_ptr}.
5308
5309Using a convenience variable for the first time creates it, but its
5310value is @code{void} until you assign a new value. You can alter the
5311value with another assignment at any time.
5312
5313Convenience variables have no fixed types. You can assign a convenience
5314variable any type of value, including structures and arrays, even if
5315that variable already has a value of a different type. The convenience
5316variable, when used as an expression, has the type of its current value.
5317
5318@table @code
5319@kindex show convenience
5320@item show convenience
5321Print a list of convenience variables used so far, and their values.
d4f3574e 5322Abbreviated @code{show conv}.
c906108c
SS
5323@end table
5324
5325One of the ways to use a convenience variable is as a counter to be
5326incremented or a pointer to be advanced. For example, to print
5327a field from successive elements of an array of structures:
5328
5329@example
5330set $i = 0
5331print bar[$i++]->contents
5332@end example
5333
d4f3574e
SS
5334@noindent
5335Repeat that command by typing @key{RET}.
c906108c
SS
5336
5337Some convenience variables are created automatically by @value{GDBN} and given
5338values likely to be useful.
5339
5340@table @code
5341@kindex $_
5342@item $_
5343The variable @code{$_} is automatically set by the @code{x} command to
5344the last address examined (@pxref{Memory, ,Examining memory}). Other
5345commands which provide a default address for @code{x} to examine also
5346set @code{$_} to that address; these commands include @code{info line}
5347and @code{info breakpoint}. The type of @code{$_} is @code{void *}
5348except when set by the @code{x} command, in which case it is a pointer
5349to the type of @code{$__}.
5350
5351@kindex $__
5352@item $__
5353The variable @code{$__} is automatically set by the @code{x} command
5354to the value found in the last address examined. Its type is chosen
5355to match the format in which the data was printed.
5356
5357@item $_exitcode
5358@kindex $_exitcode
5359The variable @code{$_exitcode} is automatically set to the exit code when
5360the program being debugged terminates.
5361@end table
5362
53a5351d
JM
5363On HP-UX systems, if you refer to a function or variable name that
5364begins with a dollar sign, @value{GDBN} searches for a user or system
5365name first, before it searches for a convenience variable.
c906108c 5366
6d2ebf8b 5367@node Registers
c906108c
SS
5368@section Registers
5369
5370@cindex registers
5371You can refer to machine register contents, in expressions, as variables
5372with names starting with @samp{$}. The names of registers are different
5373for each machine; use @code{info registers} to see the names used on
5374your machine.
5375
5376@table @code
5377@kindex info registers
5378@item info registers
5379Print the names and values of all registers except floating-point
5380registers (in the selected stack frame).
5381
5382@kindex info all-registers
5383@cindex floating point registers
5384@item info all-registers
5385Print the names and values of all registers, including floating-point
5386registers.
5387
5388@item info registers @var{regname} @dots{}
5389Print the @dfn{relativized} value of each specified register @var{regname}.
5d161b24
DB
5390As discussed in detail below, register values are normally relative to
5391the selected stack frame. @var{regname} may be any register name valid on
c906108c
SS
5392the machine you are using, with or without the initial @samp{$}.
5393@end table
5394
5395@value{GDBN} has four ``standard'' register names that are available (in
5396expressions) on most machines---whenever they do not conflict with an
5397architecture's canonical mnemonics for registers. The register names
5398@code{$pc} and @code{$sp} are used for the program counter register and
5399the stack pointer. @code{$fp} is used for a register that contains a
5400pointer to the current stack frame, and @code{$ps} is used for a
5401register that contains the processor status. For example,
5402you could print the program counter in hex with
5403
5404@example
5405p/x $pc
5406@end example
5407
5408@noindent
5409or print the instruction to be executed next with
5410
5411@example
5412x/i $pc
5413@end example
5414
5415@noindent
5416or add four to the stack pointer@footnote{This is a way of removing
5417one word from the stack, on machines where stacks grow downward in
5418memory (most machines, nowadays). This assumes that the innermost
5419stack frame is selected; setting @code{$sp} is not allowed when other
5420stack frames are selected. To pop entire frames off the stack,
5421regardless of machine architecture, use @code{return};
d4f3574e 5422see @ref{Returning, ,Returning from a function}.} with
c906108c
SS
5423
5424@example
5425set $sp += 4
5426@end example
5427
5428Whenever possible, these four standard register names are available on
5429your machine even though the machine has different canonical mnemonics,
5430so long as there is no conflict. The @code{info registers} command
5431shows the canonical names. For example, on the SPARC, @code{info
5432registers} displays the processor status register as @code{$psr} but you
d4f3574e
SS
5433can also refer to it as @code{$ps}; and on x86-based machines @code{$ps}
5434is an alias for the @sc{eflags} register.
c906108c
SS
5435
5436@value{GDBN} always considers the contents of an ordinary register as an
5437integer when the register is examined in this way. Some machines have
5438special registers which can hold nothing but floating point; these
5439registers are considered to have floating point values. There is no way
5440to refer to the contents of an ordinary register as floating point value
5441(although you can @emph{print} it as a floating point value with
5442@samp{print/f $@var{regname}}).
5443
5444Some registers have distinct ``raw'' and ``virtual'' data formats. This
5445means that the data format in which the register contents are saved by
5446the operating system is not the same one that your program normally
5447sees. For example, the registers of the 68881 floating point
5448coprocessor are always saved in ``extended'' (raw) format, but all C
5449programs expect to work with ``double'' (virtual) format. In such
5d161b24 5450cases, @value{GDBN} normally works with the virtual format only (the format
c906108c
SS
5451that makes sense for your program), but the @code{info registers} command
5452prints the data in both formats.
5453
5454Normally, register values are relative to the selected stack frame
5455(@pxref{Selection, ,Selecting a frame}). This means that you get the
5456value that the register would contain if all stack frames farther in
5457were exited and their saved registers restored. In order to see the
5458true contents of hardware registers, you must select the innermost
5459frame (with @samp{frame 0}).
5460
5461However, @value{GDBN} must deduce where registers are saved, from the machine
5462code generated by your compiler. If some registers are not saved, or if
5463@value{GDBN} is unable to locate the saved registers, the selected stack
5464frame makes no difference.
5465
6d2ebf8b 5466@node Floating Point Hardware
c906108c
SS
5467@section Floating point hardware
5468@cindex floating point
5469
5470Depending on the configuration, @value{GDBN} may be able to give
5471you more information about the status of the floating point hardware.
5472
5473@table @code
5474@kindex info float
5475@item info float
5476Display hardware-dependent information about the floating
5477point unit. The exact contents and layout vary depending on the
5478floating point chip. Currently, @samp{info float} is supported on
5479the ARM and x86 machines.
5480@end table
c906108c 5481
6d2ebf8b 5482@node Languages
c906108c
SS
5483@chapter Using @value{GDBN} with Different Languages
5484@cindex languages
5485
c906108c
SS
5486Although programming languages generally have common aspects, they are
5487rarely expressed in the same manner. For instance, in ANSI C,
5488dereferencing a pointer @code{p} is accomplished by @code{*p}, but in
5489Modula-2, it is accomplished by @code{p^}. Values can also be
5d161b24 5490represented (and displayed) differently. Hex numbers in C appear as
c906108c 5491@samp{0x1ae}, while in Modula-2 they appear as @samp{1AEH}.
c906108c
SS
5492
5493@cindex working language
5494Language-specific information is built into @value{GDBN} for some languages,
5495allowing you to express operations like the above in your program's
5496native language, and allowing @value{GDBN} to output values in a manner
5497consistent with the syntax of your program's native language. The
5498language you use to build expressions is called the @dfn{working
5499language}.
5500
5501@menu
5502* Setting:: Switching between source languages
5503* Show:: Displaying the language
c906108c 5504* Checks:: Type and range checks
c906108c
SS
5505* Support:: Supported languages
5506@end menu
5507
6d2ebf8b 5508@node Setting
c906108c
SS
5509@section Switching between source languages
5510
5511There are two ways to control the working language---either have @value{GDBN}
5512set it automatically, or select it manually yourself. You can use the
5513@code{set language} command for either purpose. On startup, @value{GDBN}
5514defaults to setting the language automatically. The working language is
5515used to determine how expressions you type are interpreted, how values
5516are printed, etc.
5517
5518In addition to the working language, every source file that
5519@value{GDBN} knows about has its own working language. For some object
5520file formats, the compiler might indicate which language a particular
5521source file is in. However, most of the time @value{GDBN} infers the
5522language from the name of the file. The language of a source file
5523controls whether C++ names are demangled---this way @code{backtrace} can
5524show each frame appropriately for its own language. There is no way to
d4f3574e
SS
5525set the language of a source file from within @value{GDBN}, but you can
5526set the language associated with a filename extension. @xref{Show, ,
5527Displaying the language}.
c906108c
SS
5528
5529This is most commonly a problem when you use a program, such
5d161b24 5530as @code{cfront} or @code{f2c}, that generates C but is written in
c906108c
SS
5531another language. In that case, make the
5532program use @code{#line} directives in its C output; that way
5533@value{GDBN} will know the correct language of the source code of the original
5534program, and will display that source code, not the generated C code.
5535
5536@menu
5537* Filenames:: Filename extensions and languages.
5538* Manually:: Setting the working language manually
5539* Automatically:: Having @value{GDBN} infer the source language
5540@end menu
5541
6d2ebf8b 5542@node Filenames
c906108c
SS
5543@subsection List of filename extensions and languages
5544
5545If a source file name ends in one of the following extensions, then
5546@value{GDBN} infers that its language is the one indicated.
5547
5548@table @file
5549
5550@item .c
5551C source file
5552
5553@item .C
5554@itemx .cc
5555@itemx .cp
5556@itemx .cpp
5557@itemx .cxx
5558@itemx .c++
5559C++ source file
5560
5561@item .f
5562@itemx .F
5563Fortran source file
5564
c906108c
SS
5565@item .ch
5566@itemx .c186
5567@itemx .c286
96a2c332 5568CHILL source file
c906108c 5569
c906108c
SS
5570@item .mod
5571Modula-2 source file
c906108c
SS
5572
5573@item .s
5574@itemx .S
5575Assembler source file. This actually behaves almost like C, but
5576@value{GDBN} does not skip over function prologues when stepping.
5577@end table
5578
5579In addition, you may set the language associated with a filename
5580extension. @xref{Show, , Displaying the language}.
5581
6d2ebf8b 5582@node Manually
c906108c
SS
5583@subsection Setting the working language
5584
5585If you allow @value{GDBN} to set the language automatically,
5586expressions are interpreted the same way in your debugging session and
5587your program.
5588
5589@kindex set language
5590If you wish, you may set the language manually. To do this, issue the
5591command @samp{set language @var{lang}}, where @var{lang} is the name of
5d161b24 5592a language, such as
c906108c 5593@code{c} or @code{modula-2}.
c906108c
SS
5594For a list of the supported languages, type @samp{set language}.
5595
c906108c
SS
5596Setting the language manually prevents @value{GDBN} from updating the working
5597language automatically. This can lead to confusion if you try
5598to debug a program when the working language is not the same as the
5599source language, when an expression is acceptable to both
5600languages---but means different things. For instance, if the current
5601source file were written in C, and @value{GDBN} was parsing Modula-2, a
5602command such as:
5603
5604@example
5605print a = b + c
5606@end example
5607
5608@noindent
5609might not have the effect you intended. In C, this means to add
5610@code{b} and @code{c} and place the result in @code{a}. The result
5611printed would be the value of @code{a}. In Modula-2, this means to compare
5612@code{a} to the result of @code{b+c}, yielding a @code{BOOLEAN} value.
c906108c 5613
6d2ebf8b 5614@node Automatically
c906108c
SS
5615@subsection Having @value{GDBN} infer the source language
5616
5617To have @value{GDBN} set the working language automatically, use
5618@samp{set language local} or @samp{set language auto}. @value{GDBN}
5619then infers the working language. That is, when your program stops in a
5620frame (usually by encountering a breakpoint), @value{GDBN} sets the
5621working language to the language recorded for the function in that
5622frame. If the language for a frame is unknown (that is, if the function
5623or block corresponding to the frame was defined in a source file that
5624does not have a recognized extension), the current working language is
5625not changed, and @value{GDBN} issues a warning.
5626
5627This may not seem necessary for most programs, which are written
5628entirely in one source language. However, program modules and libraries
5629written in one source language can be used by a main program written in
5630a different source language. Using @samp{set language auto} in this
5631case frees you from having to set the working language manually.
5632
6d2ebf8b 5633@node Show
c906108c 5634@section Displaying the language
c906108c
SS
5635
5636The following commands help you find out which language is the
5637working language, and also what language source files were written in.
5638
5639@kindex show language
d4f3574e
SS
5640@kindex info frame@r{, show the source language}
5641@kindex info source@r{, show the source language}
c906108c
SS
5642@table @code
5643@item show language
5644Display the current working language. This is the
5645language you can use with commands such as @code{print} to
5646build and compute expressions that may involve variables in your program.
5647
5648@item info frame
5d161b24 5649Display the source language for this frame. This language becomes the
c906108c 5650working language if you use an identifier from this frame.
5d161b24 5651@xref{Frame Info, ,Information about a frame}, to identify the other
c906108c
SS
5652information listed here.
5653
5654@item info source
5655Display the source language of this source file.
5d161b24 5656@xref{Symbols, ,Examining the Symbol Table}, to identify the other
c906108c
SS
5657information listed here.
5658@end table
5659
5660In unusual circumstances, you may have source files with extensions
5661not in the standard list. You can then set the extension associated
5662with a language explicitly:
5663
5664@kindex set extension-language
5665@kindex info extensions
5666@table @code
5667@item set extension-language @var{.ext} @var{language}
5668Set source files with extension @var{.ext} to be assumed to be in
5669the source language @var{language}.
5670
5671@item info extensions
5672List all the filename extensions and the associated languages.
5673@end table
5674
6d2ebf8b 5675@node Checks
c906108c
SS
5676@section Type and range checking
5677
5678@quotation
5679@emph{Warning:} In this release, the @value{GDBN} commands for type and range
5680checking are included, but they do not yet have any effect. This
5681section documents the intended facilities.
5682@end quotation
5683@c FIXME remove warning when type/range code added
5684
5685Some languages are designed to guard you against making seemingly common
5686errors through a series of compile- and run-time checks. These include
5687checking the type of arguments to functions and operators, and making
5688sure mathematical overflows are caught at run time. Checks such as
5689these help to ensure a program's correctness once it has been compiled
5690by eliminating type mismatches, and providing active checks for range
5691errors when your program is running.
5692
5693@value{GDBN} can check for conditions like the above if you wish.
5694Although @value{GDBN} does not check the statements in your program, it
5695can check expressions entered directly into @value{GDBN} for evaluation via
5696the @code{print} command, for example. As with the working language,
5697@value{GDBN} can also decide whether or not to check automatically based on
5698your program's source language. @xref{Support, ,Supported languages},
5699for the default settings of supported languages.
5700
5701@menu
5702* Type Checking:: An overview of type checking
5703* Range Checking:: An overview of range checking
5704@end menu
5705
5706@cindex type checking
5707@cindex checks, type
6d2ebf8b 5708@node Type Checking
c906108c
SS
5709@subsection An overview of type checking
5710
5711Some languages, such as Modula-2, are strongly typed, meaning that the
5712arguments to operators and functions have to be of the correct type,
5713otherwise an error occurs. These checks prevent type mismatch
5714errors from ever causing any run-time problems. For example,
5715
5716@smallexample
57171 + 2 @result{} 3
5718@exdent but
5719@error{} 1 + 2.3
5720@end smallexample
5721
5722The second example fails because the @code{CARDINAL} 1 is not
5723type-compatible with the @code{REAL} 2.3.
5724
5d161b24
DB
5725For the expressions you use in @value{GDBN} commands, you can tell the
5726@value{GDBN} type checker to skip checking;
5727to treat any mismatches as errors and abandon the expression;
5728or to only issue warnings when type mismatches occur,
c906108c
SS
5729but evaluate the expression anyway. When you choose the last of
5730these, @value{GDBN} evaluates expressions like the second example above, but
5731also issues a warning.
5732
5d161b24
DB
5733Even if you turn type checking off, there may be other reasons
5734related to type that prevent @value{GDBN} from evaluating an expression.
5735For instance, @value{GDBN} does not know how to add an @code{int} and
5736a @code{struct foo}. These particular type errors have nothing to do
5737with the language in use, and usually arise from expressions, such as
c906108c
SS
5738the one described above, which make little sense to evaluate anyway.
5739
5740Each language defines to what degree it is strict about type. For
5741instance, both Modula-2 and C require the arguments to arithmetical
5742operators to be numbers. In C, enumerated types and pointers can be
5743represented as numbers, so that they are valid arguments to mathematical
5744operators. @xref{Support, ,Supported languages}, for further
5745details on specific languages.
5746
5747@value{GDBN} provides some additional commands for controlling the type checker:
5748
d4f3574e 5749@kindex set check@r{, type}
c906108c
SS
5750@kindex set check type
5751@kindex show check type
5752@table @code
5753@item set check type auto
5754Set type checking on or off based on the current working language.
5755@xref{Support, ,Supported languages}, for the default settings for
5756each language.
5757
5758@item set check type on
5759@itemx set check type off
5760Set type checking on or off, overriding the default setting for the
5761current working language. Issue a warning if the setting does not
5762match the language default. If any type mismatches occur in
d4f3574e 5763evaluating an expression while type checking is on, @value{GDBN} prints a
c906108c
SS
5764message and aborts evaluation of the expression.
5765
5766@item set check type warn
5767Cause the type checker to issue warnings, but to always attempt to
5768evaluate the expression. Evaluating the expression may still
5769be impossible for other reasons. For example, @value{GDBN} cannot add
5770numbers and structures.
5771
5772@item show type
5d161b24 5773Show the current setting of the type checker, and whether or not @value{GDBN}
c906108c
SS
5774is setting it automatically.
5775@end table
5776
5777@cindex range checking
5778@cindex checks, range
6d2ebf8b 5779@node Range Checking
c906108c
SS
5780@subsection An overview of range checking
5781
5782In some languages (such as Modula-2), it is an error to exceed the
5783bounds of a type; this is enforced with run-time checks. Such range
5784checking is meant to ensure program correctness by making sure
5785computations do not overflow, or indices on an array element access do
5786not exceed the bounds of the array.
5787
5788For expressions you use in @value{GDBN} commands, you can tell
5789@value{GDBN} to treat range errors in one of three ways: ignore them,
5790always treat them as errors and abandon the expression, or issue
5791warnings but evaluate the expression anyway.
5792
5793A range error can result from numerical overflow, from exceeding an
5794array index bound, or when you type a constant that is not a member
5795of any type. Some languages, however, do not treat overflows as an
5796error. In many implementations of C, mathematical overflow causes the
5797result to ``wrap around'' to lower values---for example, if @var{m} is
5798the largest integer value, and @var{s} is the smallest, then
5799
5800@example
5801@var{m} + 1 @result{} @var{s}
5802@end example
5803
5804This, too, is specific to individual languages, and in some cases
5805specific to individual compilers or machines. @xref{Support, ,
5806Supported languages}, for further details on specific languages.
5807
5808@value{GDBN} provides some additional commands for controlling the range checker:
5809
d4f3574e 5810@kindex set check@r{, range}
c906108c
SS
5811@kindex set check range
5812@kindex show check range
5813@table @code
5814@item set check range auto
5815Set range checking on or off based on the current working language.
5816@xref{Support, ,Supported languages}, for the default settings for
5817each language.
5818
5819@item set check range on
5820@itemx set check range off
5821Set range checking on or off, overriding the default setting for the
5822current working language. A warning is issued if the setting does not
c3f6f71d
JM
5823match the language default. If a range error occurs and range checking is on,
5824then a message is printed and evaluation of the expression is aborted.
c906108c
SS
5825
5826@item set check range warn
5827Output messages when the @value{GDBN} range checker detects a range error,
5828but attempt to evaluate the expression anyway. Evaluating the
5829expression may still be impossible for other reasons, such as accessing
5830memory that the process does not own (a typical example from many Unix
5831systems).
5832
5833@item show range
5834Show the current setting of the range checker, and whether or not it is
5835being set automatically by @value{GDBN}.
5836@end table
c906108c 5837
6d2ebf8b 5838@node Support
c906108c 5839@section Supported languages
c906108c 5840
cce74817
JM
5841@value{GDBN} supports C, C++, Fortran, Java, Chill, assembly, and Modula-2.
5842@c This is false ...
c906108c
SS
5843Some @value{GDBN} features may be used in expressions regardless of the
5844language you use: the @value{GDBN} @code{@@} and @code{::} operators,
5845and the @samp{@{type@}addr} construct (@pxref{Expressions,
5846,Expressions}) can be used with the constructs of any supported
5847language.
5848
5849The following sections detail to what degree each source language is
5850supported by @value{GDBN}. These sections are not meant to be language
5851tutorials or references, but serve only as a reference guide to what the
5852@value{GDBN} expression parser accepts, and what input and output
5853formats should look like for different languages. There are many good
5854books written on each of these languages; please look to these for a
5855language reference or tutorial.
5856
c906108c 5857@menu
7a292a7a 5858* C:: C and C++
cce74817 5859* Modula-2:: Modula-2
104c1213 5860* Chill:: Chill
c906108c
SS
5861@end menu
5862
6d2ebf8b 5863@node C
c906108c 5864@subsection C and C++
7a292a7a 5865
c906108c
SS
5866@cindex C and C++
5867@cindex expressions in C or C++
c906108c
SS
5868
5869Since C and C++ are so closely related, many features of @value{GDBN} apply
5870to both languages. Whenever this is the case, we discuss those languages
5871together.
5872
c906108c
SS
5873@cindex C++
5874@kindex g++
5875@cindex @sc{gnu} C++
5876The C++ debugging facilities are jointly implemented by the C++
5877compiler and @value{GDBN}. Therefore, to debug your C++ code
5878effectively, you must compile your C++ programs with a supported
5879C++ compiler, such as @sc{gnu} @code{g++}, or the HP ANSI C++
5880compiler (@code{aCC}).
5881
5882For best results when using @sc{gnu} C++, use the stabs debugging
5883format. You can select that format explicitly with the @code{g++}
5884command-line options @samp{-gstabs} or @samp{-gstabs+}. See
5885@ref{Debugging Options,,Options for Debugging Your Program or @sc{gnu}
5886CC, gcc.info, Using @sc{gnu} CC}, for more information.
c906108c 5887
c906108c
SS
5888@menu
5889* C Operators:: C and C++ operators
5890* C Constants:: C and C++ constants
7a292a7a 5891* C plus plus expressions:: C++ expressions
c906108c 5892* C Defaults:: Default settings for C and C++
c906108c 5893* C Checks:: C and C++ type and range checks
c906108c
SS
5894* Debugging C:: @value{GDBN} and C
5895* Debugging C plus plus:: @value{GDBN} features for C++
5896@end menu
c906108c 5897
6d2ebf8b 5898@node C Operators
c906108c 5899@subsubsection C and C++ operators
7a292a7a
SS
5900
5901@cindex C and C++ operators
c906108c
SS
5902
5903Operators must be defined on values of specific types. For instance,
5904@code{+} is defined on numbers, but not on structures. Operators are
5d161b24 5905often defined on groups of types.
c906108c 5906
c906108c 5907For the purposes of C and C++, the following definitions hold:
c906108c
SS
5908
5909@itemize @bullet
53a5351d 5910
c906108c 5911@item
c906108c
SS
5912@emph{Integral types} include @code{int} with any of its storage-class
5913specifiers; @code{char}; @code{enum}; and, for C++, @code{bool}.
c906108c
SS
5914
5915@item
d4f3574e
SS
5916@emph{Floating-point types} include @code{float}, @code{double}, and
5917@code{long double} (if supported by the target platform).
c906108c
SS
5918
5919@item
53a5351d 5920@emph{Pointer types} include all types defined as @code{(@var{type} *)}.
c906108c
SS
5921
5922@item
5923@emph{Scalar types} include all of the above.
53a5351d 5924
c906108c
SS
5925@end itemize
5926
5927@noindent
5928The following operators are supported. They are listed here
5929in order of increasing precedence:
5930
5931@table @code
5932@item ,
5933The comma or sequencing operator. Expressions in a comma-separated list
5934are evaluated from left to right, with the result of the entire
5935expression being the last expression evaluated.
5936
5937@item =
5938Assignment. The value of an assignment expression is the value
5939assigned. Defined on scalar types.
5940
5941@item @var{op}=
5942Used in an expression of the form @w{@code{@var{a} @var{op}= @var{b}}},
5943and translated to @w{@code{@var{a} = @var{a op b}}}.
d4f3574e 5944@w{@code{@var{op}=}} and @code{=} have the same precedence.
c906108c
SS
5945@var{op} is any one of the operators @code{|}, @code{^}, @code{&},
5946@code{<<}, @code{>>}, @code{+}, @code{-}, @code{*}, @code{/}, @code{%}.
5947
5948@item ?:
5949The ternary operator. @code{@var{a} ? @var{b} : @var{c}} can be thought
5950of as: if @var{a} then @var{b} else @var{c}. @var{a} should be of an
5951integral type.
5952
5953@item ||
5954Logical @sc{or}. Defined on integral types.
5955
5956@item &&
5957Logical @sc{and}. Defined on integral types.
5958
5959@item |
5960Bitwise @sc{or}. Defined on integral types.
5961
5962@item ^
5963Bitwise exclusive-@sc{or}. Defined on integral types.
5964
5965@item &
5966Bitwise @sc{and}. Defined on integral types.
5967
5968@item ==@r{, }!=
5969Equality and inequality. Defined on scalar types. The value of these
5970expressions is 0 for false and non-zero for true.
5971
5972@item <@r{, }>@r{, }<=@r{, }>=
5973Less than, greater than, less than or equal, greater than or equal.
5974Defined on scalar types. The value of these expressions is 0 for false
5975and non-zero for true.
5976
5977@item <<@r{, }>>
5978left shift, and right shift. Defined on integral types.
5979
5980@item @@
5981The @value{GDBN} ``artificial array'' operator (@pxref{Expressions, ,Expressions}).
5982
5983@item +@r{, }-
5984Addition and subtraction. Defined on integral types, floating-point types and
5985pointer types.
5986
5987@item *@r{, }/@r{, }%
5988Multiplication, division, and modulus. Multiplication and division are
5989defined on integral and floating-point types. Modulus is defined on
5990integral types.
5991
5992@item ++@r{, }--
5993Increment and decrement. When appearing before a variable, the
5994operation is performed before the variable is used in an expression;
5995when appearing after it, the variable's value is used before the
5996operation takes place.
5997
5998@item *
5999Pointer dereferencing. Defined on pointer types. Same precedence as
6000@code{++}.
6001
6002@item &
6003Address operator. Defined on variables. Same precedence as @code{++}.
6004
c906108c
SS
6005For debugging C++, @value{GDBN} implements a use of @samp{&} beyond what is
6006allowed in the C++ language itself: you can use @samp{&(&@var{ref})}
6007(or, if you prefer, simply @samp{&&@var{ref}}) to examine the address
6008where a C++ reference variable (declared with @samp{&@var{ref}}) is
6009stored.
c906108c
SS
6010
6011@item -
6012Negative. Defined on integral and floating-point types. Same
6013precedence as @code{++}.
6014
6015@item !
6016Logical negation. Defined on integral types. Same precedence as
6017@code{++}.
6018
6019@item ~
6020Bitwise complement operator. Defined on integral types. Same precedence as
6021@code{++}.
6022
6023
6024@item .@r{, }->
6025Structure member, and pointer-to-structure member. For convenience,
6026@value{GDBN} regards the two as equivalent, choosing whether to dereference a
6027pointer based on the stored type information.
6028Defined on @code{struct} and @code{union} data.
6029
c906108c
SS
6030@item .*@r{, }->*
6031Dereferences of pointers to members.
c906108c
SS
6032
6033@item []
6034Array indexing. @code{@var{a}[@var{i}]} is defined as
6035@code{*(@var{a}+@var{i})}. Same precedence as @code{->}.
6036
6037@item ()
6038Function parameter list. Same precedence as @code{->}.
6039
c906108c 6040@item ::
7a292a7a
SS
6041C++ scope resolution operator. Defined on @code{struct}, @code{union},
6042and @code{class} types.
c906108c
SS
6043
6044@item ::
7a292a7a
SS
6045Doubled colons also represent the @value{GDBN} scope operator
6046(@pxref{Expressions, ,Expressions}). Same precedence as @code{::},
6047above.
c906108c
SS
6048@end table
6049
c906108c
SS
6050If an operator is redefined in the user code, @value{GDBN} usually
6051attempts to invoke the redefined version instead of using the operator's
6052predefined meaning.
c906108c 6053
c906108c 6054@menu
5d161b24 6055* C Constants::
c906108c
SS
6056@end menu
6057
6d2ebf8b 6058@node C Constants
c906108c 6059@subsubsection C and C++ constants
c906108c
SS
6060
6061@cindex C and C++ constants
c906108c 6062
7a292a7a 6063@value{GDBN} allows you to express the constants of C and C++ in the
c906108c 6064following ways:
c906108c
SS
6065
6066@itemize @bullet
6067@item
6068Integer constants are a sequence of digits. Octal constants are
6069specified by a leading @samp{0} (i.e. zero), and hexadecimal constants by
6070a leading @samp{0x} or @samp{0X}. Constants may also end with a letter
6071@samp{l}, specifying that the constant should be treated as a
6072@code{long} value.
6073
6074@item
6075Floating point constants are a sequence of digits, followed by a decimal
6076point, followed by a sequence of digits, and optionally followed by an
6077exponent. An exponent is of the form:
6078@samp{@w{e@r{[[}+@r{]|}-@r{]}@var{nnn}}}, where @var{nnn} is another
6079sequence of digits. The @samp{+} is optional for positive exponents.
d4f3574e
SS
6080A floating-point constant may also end with a letter @samp{f} or
6081@samp{F}, specifying that the constant should be treated as being of
6082the @code{float} (as opposed to the default @code{double}) type; or with
6083a letter @samp{l} or @samp{L}, which specifies a @code{long double}
6084constant.
c906108c
SS
6085
6086@item
6087Enumerated constants consist of enumerated identifiers, or their
6088integral equivalents.
6089
6090@item
6091Character constants are a single character surrounded by single quotes
6092(@code{'}), or a number---the ordinal value of the corresponding character
d4f3574e 6093(usually its @sc{ascii} value). Within quotes, the single character may
c906108c
SS
6094be represented by a letter or by @dfn{escape sequences}, which are of
6095the form @samp{\@var{nnn}}, where @var{nnn} is the octal representation
6096of the character's ordinal value; or of the form @samp{\@var{x}}, where
6097@samp{@var{x}} is a predefined special character---for example,
6098@samp{\n} for newline.
6099
6100@item
96a2c332
SS
6101String constants are a sequence of character constants surrounded by
6102double quotes (@code{"}). Any valid character constant (as described
6103above) may appear. Double quotes within the string must be preceded by
6104a backslash, so for instance @samp{"a\"b'c"} is a string of five
6105characters.
c906108c
SS
6106
6107@item
6108Pointer constants are an integral value. You can also write pointers
6109to constants using the C operator @samp{&}.
6110
6111@item
6112Array constants are comma-separated lists surrounded by braces @samp{@{}
6113and @samp{@}}; for example, @samp{@{1,2,3@}} is a three-element array of
6114integers, @samp{@{@{1,2@}, @{3,4@}, @{5,6@}@}} is a three-by-two array,
6115and @samp{@{&"hi", &"there", &"fred"@}} is a three-element array of pointers.
6116@end itemize
6117
c906108c 6118@menu
5d161b24
DB
6119* C plus plus expressions::
6120* C Defaults::
6121* C Checks::
c906108c 6122
5d161b24 6123* Debugging C::
c906108c
SS
6124@end menu
6125
6d2ebf8b 6126@node C plus plus expressions
c906108c 6127@subsubsection C++ expressions
c906108c
SS
6128
6129@cindex expressions in C++
6130@value{GDBN} expression handling can interpret most C++ expressions.
6131
c906108c
SS
6132@cindex C++ support, not in @sc{coff}
6133@cindex @sc{coff} versus C++
6134@cindex C++ and object formats
6135@cindex object formats and C++
6136@cindex a.out and C++
6137@cindex @sc{ecoff} and C++
6138@cindex @sc{xcoff} and C++
6139@cindex @sc{elf}/stabs and C++
6140@cindex @sc{elf}/@sc{dwarf} and C++
6141@c FIXME!! GDB may eventually be able to debug C++ using DWARF; check
6142@c periodically whether this has happened...
6143@quotation
6144@emph{Warning:} @value{GDBN} can only debug C++ code if you use the
6145proper compiler. Typically, C++ debugging depends on the use of
6146additional debugging information in the symbol table, and thus requires
6147special support. In particular, if your compiler generates a.out, MIPS
6148@sc{ecoff}, RS/6000 @sc{xcoff}, or @sc{elf} with stabs extensions to the
6149symbol table, these facilities are all available. (With @sc{gnu} CC,
6150you can use the @samp{-gstabs} option to request stabs debugging
6151extensions explicitly.) Where the object code format is standard
6152@sc{coff} or @sc{dwarf} in @sc{elf}, on the other hand, most of the C++
6153support in @value{GDBN} does @emph{not} work.
6154@end quotation
c906108c
SS
6155
6156@enumerate
6157
6158@cindex member functions
6159@item
6160Member function calls are allowed; you can use expressions like
6161
6162@example
6163count = aml->GetOriginal(x, y)
6164@end example
6165
6166@kindex this
6167@cindex namespace in C++
6168@item
6169While a member function is active (in the selected stack frame), your
6170expressions have the same namespace available as the member function;
6171that is, @value{GDBN} allows implicit references to the class instance
6172pointer @code{this} following the same rules as C++.
6173
c906108c 6174@cindex call overloaded functions
d4f3574e 6175@cindex overloaded functions, calling
c906108c
SS
6176@cindex type conversions in C++
6177@item
6178You can call overloaded functions; @value{GDBN} resolves the function
d4f3574e 6179call to the right definition, with some restrictions. @value{GDBN} does not
c906108c
SS
6180perform overload resolution involving user-defined type conversions,
6181calls to constructors, or instantiations of templates that do not exist
6182in the program. It also cannot handle ellipsis argument lists or
6183default arguments.
6184
6185It does perform integral conversions and promotions, floating-point
6186promotions, arithmetic conversions, pointer conversions, conversions of
6187class objects to base classes, and standard conversions such as those of
6188functions or arrays to pointers; it requires an exact match on the
6189number of function arguments.
6190
6191Overload resolution is always performed, unless you have specified
6192@code{set overload-resolution off}. @xref{Debugging C plus plus,
6193,@value{GDBN} features for C++}.
6194
d4f3574e 6195You must specify @code{set overload-resolution off} in order to use an
c906108c
SS
6196explicit function signature to call an overloaded function, as in
6197@smallexample
6198p 'foo(char,int)'('x', 13)
6199@end smallexample
d4f3574e 6200
c906108c 6201The @value{GDBN} command-completion facility can simplify this;
d4f3574e 6202see @ref{Completion, ,Command completion}.
c906108c 6203
c906108c
SS
6204@cindex reference declarations
6205@item
5d161b24 6206@value{GDBN} understands variables declared as C++ references; you can use
c906108c
SS
6207them in expressions just as you do in C++ source---they are automatically
6208dereferenced.
6209
6210In the parameter list shown when @value{GDBN} displays a frame, the values of
6211reference variables are not displayed (unlike other variables); this
6212avoids clutter, since references are often used for large structures.
6213The @emph{address} of a reference variable is always shown, unless
6214you have specified @samp{set print address off}.
6215
6216@item
6217@value{GDBN} supports the C++ name resolution operator @code{::}---your
6218expressions can use it just as expressions in your program do. Since
6219one scope may be defined in another, you can use @code{::} repeatedly if
6220necessary, for example in an expression like
6221@samp{@var{scope1}::@var{scope2}::@var{name}}. @value{GDBN} also allows
6222resolving name scope by reference to source files, in both C and C++
6223debugging (@pxref{Variables, ,Program variables}).
6224@end enumerate
6225
53a5351d
JM
6226In addition, when used with HP's C++ compiler, @value{GDBN} supports
6227calling virtual functions correctly, printing out virtual bases of
6228objects, calling functions in a base subobject, casting objects, and
6229invoking user-defined operators.
c906108c 6230
6d2ebf8b 6231@node C Defaults
c906108c 6232@subsubsection C and C++ defaults
7a292a7a 6233
c906108c
SS
6234@cindex C and C++ defaults
6235
c906108c
SS
6236If you allow @value{GDBN} to set type and range checking automatically, they
6237both default to @code{off} whenever the working language changes to
6238C or C++. This happens regardless of whether you or @value{GDBN}
6239selects the working language.
c906108c
SS
6240
6241If you allow @value{GDBN} to set the language automatically, it
6242recognizes source files whose names end with @file{.c}, @file{.C}, or
6243@file{.cc}, etc, and when @value{GDBN} enters code compiled from one of
6244these files, it sets the working language to C or C++.
6245@xref{Automatically, ,Having @value{GDBN} infer the source language},
6246for further details.
6247
c906108c
SS
6248@c Type checking is (a) primarily motivated by Modula-2, and (b)
6249@c unimplemented. If (b) changes, it might make sense to let this node
6250@c appear even if Mod-2 does not, but meanwhile ignore it. roland 16jul93.
7a292a7a 6251
6d2ebf8b 6252@node C Checks
c906108c 6253@subsubsection C and C++ type and range checks
7a292a7a 6254
c906108c
SS
6255@cindex C and C++ checks
6256
6257By default, when @value{GDBN} parses C or C++ expressions, type checking
6258is not used. However, if you turn type checking on, @value{GDBN}
6259considers two variables type equivalent if:
6260
6261@itemize @bullet
6262@item
6263The two variables are structured and have the same structure, union, or
6264enumerated tag.
6265
6266@item
6267The two variables have the same type name, or types that have been
6268declared equivalent through @code{typedef}.
6269
6270@ignore
6271@c leaving this out because neither J Gilmore nor R Pesch understand it.
6272@c FIXME--beers?
6273@item
6274The two @code{struct}, @code{union}, or @code{enum} variables are
6275declared in the same declaration. (Note: this may not be true for all C
6276compilers.)
6277@end ignore
6278@end itemize
6279
6280Range checking, if turned on, is done on mathematical operations. Array
6281indices are not checked, since they are often used to index a pointer
6282that is not itself an array.
c906108c 6283
6d2ebf8b 6284@node Debugging C
c906108c 6285@subsubsection @value{GDBN} and C
c906108c
SS
6286
6287The @code{set print union} and @code{show print union} commands apply to
6288the @code{union} type. When set to @samp{on}, any @code{union} that is
7a292a7a
SS
6289inside a @code{struct} or @code{class} is also printed. Otherwise, it
6290appears as @samp{@{...@}}.
c906108c
SS
6291
6292The @code{@@} operator aids in the debugging of dynamic arrays, formed
6293with pointers and a memory allocation function. @xref{Expressions,
6294,Expressions}.
6295
c906108c 6296@menu
5d161b24 6297* Debugging C plus plus::
c906108c
SS
6298@end menu
6299
6d2ebf8b 6300@node Debugging C plus plus
c906108c 6301@subsubsection @value{GDBN} features for C++
c906108c
SS
6302
6303@cindex commands for C++
7a292a7a 6304
c906108c
SS
6305Some @value{GDBN} commands are particularly useful with C++, and some are
6306designed specifically for use with C++. Here is a summary:
6307
6308@table @code
6309@cindex break in overloaded functions
6310@item @r{breakpoint menus}
6311When you want a breakpoint in a function whose name is overloaded,
6312@value{GDBN} breakpoint menus help you specify which function definition
6313you want. @xref{Breakpoint Menus,,Breakpoint menus}.
6314
6315@cindex overloading in C++
6316@item rbreak @var{regex}
6317Setting breakpoints using regular expressions is helpful for setting
6318breakpoints on overloaded functions that are not members of any special
6319classes.
6320@xref{Set Breaks, ,Setting breakpoints}.
6321
6322@cindex C++ exception handling
6323@item catch throw
6324@itemx catch catch
6325Debug C++ exception handling using these commands. @xref{Set
6326Catchpoints, , Setting catchpoints}.
6327
6328@cindex inheritance
6329@item ptype @var{typename}
6330Print inheritance relationships as well as other information for type
6331@var{typename}.
6332@xref{Symbols, ,Examining the Symbol Table}.
6333
6334@cindex C++ symbol display
6335@item set print demangle
6336@itemx show print demangle
6337@itemx set print asm-demangle
6338@itemx show print asm-demangle
6339Control whether C++ symbols display in their source form, both when
6340displaying code as C++ source and when displaying disassemblies.
6341@xref{Print Settings, ,Print settings}.
6342
6343@item set print object
6344@itemx show print object
6345Choose whether to print derived (actual) or declared types of objects.
6346@xref{Print Settings, ,Print settings}.
6347
6348@item set print vtbl
6349@itemx show print vtbl
6350Control the format for printing virtual function tables.
6351@xref{Print Settings, ,Print settings}.
c906108c
SS
6352(The @code{vtbl} commands do not work on programs compiled with the HP
6353ANSI C++ compiler (@code{aCC}).)
6354
6355@kindex set overload-resolution
d4f3574e 6356@cindex overloaded functions, overload resolution
c906108c
SS
6357@item set overload-resolution on
6358Enable overload resolution for C++ expression evaluation. The default
6359is on. For overloaded functions, @value{GDBN} evaluates the arguments
6360and searches for a function whose signature matches the argument types,
d4f3574e
SS
6361using the standard C++ conversion rules (see @ref{C plus plus expressions, ,C++
6362expressions}, for details). If it cannot find a match, it emits a
c906108c
SS
6363message.
6364
6365@item set overload-resolution off
6366Disable overload resolution for C++ expression evaluation. For
6367overloaded functions that are not class member functions, @value{GDBN}
6368chooses the first function of the specified name that it finds in the
6369symbol table, whether or not its arguments are of the correct type. For
6370overloaded functions that are class member functions, @value{GDBN}
6371searches for a function whose signature @emph{exactly} matches the
6372argument types.
c906108c
SS
6373
6374@item @r{Overloaded symbol names}
6375You can specify a particular definition of an overloaded symbol, using
6376the same notation that is used to declare such symbols in C++: type
6377@code{@var{symbol}(@var{types})} rather than just @var{symbol}. You can
6378also use the @value{GDBN} command-line word completion facilities to list the
6379available choices, or to finish the type list for you.
6380@xref{Completion,, Command completion}, for details on how to do this.
6381@end table
c906108c 6382
6d2ebf8b 6383@node Modula-2
c906108c 6384@subsection Modula-2
7a292a7a 6385
d4f3574e 6386@cindex Modula-2, @value{GDBN} support
c906108c
SS
6387
6388The extensions made to @value{GDBN} to support Modula-2 only support
6389output from the @sc{gnu} Modula-2 compiler (which is currently being
6390developed). Other Modula-2 compilers are not currently supported, and
6391attempting to debug executables produced by them is most likely
6392to give an error as @value{GDBN} reads in the executable's symbol
6393table.
6394
6395@cindex expressions in Modula-2
6396@menu
6397* M2 Operators:: Built-in operators
6398* Built-In Func/Proc:: Built-in functions and procedures
6399* M2 Constants:: Modula-2 constants
6400* M2 Defaults:: Default settings for Modula-2
6401* Deviations:: Deviations from standard Modula-2
6402* M2 Checks:: Modula-2 type and range checks
6403* M2 Scope:: The scope operators @code{::} and @code{.}
6404* GDB/M2:: @value{GDBN} and Modula-2
6405@end menu
6406
6d2ebf8b 6407@node M2 Operators
c906108c
SS
6408@subsubsection Operators
6409@cindex Modula-2 operators
6410
6411Operators must be defined on values of specific types. For instance,
6412@code{+} is defined on numbers, but not on structures. Operators are
6413often defined on groups of types. For the purposes of Modula-2, the
6414following definitions hold:
6415
6416@itemize @bullet
6417
6418@item
6419@emph{Integral types} consist of @code{INTEGER}, @code{CARDINAL}, and
6420their subranges.
6421
6422@item
6423@emph{Character types} consist of @code{CHAR} and its subranges.
6424
6425@item
6426@emph{Floating-point types} consist of @code{REAL}.
6427
6428@item
6429@emph{Pointer types} consist of anything declared as @code{POINTER TO
6430@var{type}}.
6431
6432@item
6433@emph{Scalar types} consist of all of the above.
6434
6435@item
6436@emph{Set types} consist of @code{SET} and @code{BITSET} types.
6437
6438@item
6439@emph{Boolean types} consist of @code{BOOLEAN}.
6440@end itemize
6441
6442@noindent
6443The following operators are supported, and appear in order of
6444increasing precedence:
6445
6446@table @code
6447@item ,
6448Function argument or array index separator.
6449
6450@item :=
6451Assignment. The value of @var{var} @code{:=} @var{value} is
6452@var{value}.
6453
6454@item <@r{, }>
6455Less than, greater than on integral, floating-point, or enumerated
6456types.
6457
6458@item <=@r{, }>=
96a2c332 6459Less than or equal to, greater than or equal to
c906108c
SS
6460on integral, floating-point and enumerated types, or set inclusion on
6461set types. Same precedence as @code{<}.
6462
6463@item =@r{, }<>@r{, }#
6464Equality and two ways of expressing inequality, valid on scalar types.
6465Same precedence as @code{<}. In @value{GDBN} scripts, only @code{<>} is
6466available for inequality, since @code{#} conflicts with the script
6467comment character.
6468
6469@item IN
6470Set membership. Defined on set types and the types of their members.
6471Same precedence as @code{<}.
6472
6473@item OR
6474Boolean disjunction. Defined on boolean types.
6475
6476@item AND@r{, }&
d4f3574e 6477Boolean conjunction. Defined on boolean types.
c906108c
SS
6478
6479@item @@
6480The @value{GDBN} ``artificial array'' operator (@pxref{Expressions, ,Expressions}).
6481
6482@item +@r{, }-
6483Addition and subtraction on integral and floating-point types, or union
6484and difference on set types.
6485
6486@item *
6487Multiplication on integral and floating-point types, or set intersection
6488on set types.
6489
6490@item /
6491Division on floating-point types, or symmetric set difference on set
6492types. Same precedence as @code{*}.
6493
6494@item DIV@r{, }MOD
6495Integer division and remainder. Defined on integral types. Same
6496precedence as @code{*}.
6497
6498@item -
6499Negative. Defined on @code{INTEGER} and @code{REAL} data.
6500
6501@item ^
6502Pointer dereferencing. Defined on pointer types.
6503
6504@item NOT
6505Boolean negation. Defined on boolean types. Same precedence as
6506@code{^}.
6507
6508@item .
6509@code{RECORD} field selector. Defined on @code{RECORD} data. Same
6510precedence as @code{^}.
6511
6512@item []
6513Array indexing. Defined on @code{ARRAY} data. Same precedence as @code{^}.
6514
6515@item ()
6516Procedure argument list. Defined on @code{PROCEDURE} objects. Same precedence
6517as @code{^}.
6518
6519@item ::@r{, }.
6520@value{GDBN} and Modula-2 scope operators.
6521@end table
6522
6523@quotation
6524@emph{Warning:} Sets and their operations are not yet supported, so @value{GDBN}
6525treats the use of the operator @code{IN}, or the use of operators
6526@code{+}, @code{-}, @code{*}, @code{/}, @code{=}, , @code{<>}, @code{#},
6527@code{<=}, and @code{>=} on sets as an error.
6528@end quotation
6529
6530@cindex Modula-2 built-ins
6d2ebf8b 6531@node Built-In Func/Proc
c906108c
SS
6532@subsubsection Built-in functions and procedures
6533
6534Modula-2 also makes available several built-in procedures and functions.
6535In describing these, the following metavariables are used:
6536
6537@table @var
6538
6539@item a
6540represents an @code{ARRAY} variable.
6541
6542@item c
6543represents a @code{CHAR} constant or variable.
6544
6545@item i
6546represents a variable or constant of integral type.
6547
6548@item m
6549represents an identifier that belongs to a set. Generally used in the
6550same function with the metavariable @var{s}. The type of @var{s} should
6551be @code{SET OF @var{mtype}} (where @var{mtype} is the type of @var{m}).
6552
6553@item n
6554represents a variable or constant of integral or floating-point type.
6555
6556@item r
6557represents a variable or constant of floating-point type.
6558
6559@item t
6560represents a type.
6561
6562@item v
6563represents a variable.
6564
6565@item x
6566represents a variable or constant of one of many types. See the
6567explanation of the function for details.
6568@end table
6569
6570All Modula-2 built-in procedures also return a result, described below.
6571
6572@table @code
6573@item ABS(@var{n})
6574Returns the absolute value of @var{n}.
6575
6576@item CAP(@var{c})
6577If @var{c} is a lower case letter, it returns its upper case
c3f6f71d 6578equivalent, otherwise it returns its argument.
c906108c
SS
6579
6580@item CHR(@var{i})
6581Returns the character whose ordinal value is @var{i}.
6582
6583@item DEC(@var{v})
c3f6f71d 6584Decrements the value in the variable @var{v} by one. Returns the new value.
c906108c
SS
6585
6586@item DEC(@var{v},@var{i})
6587Decrements the value in the variable @var{v} by @var{i}. Returns the
6588new value.
6589
6590@item EXCL(@var{m},@var{s})
6591Removes the element @var{m} from the set @var{s}. Returns the new
6592set.
6593
6594@item FLOAT(@var{i})
6595Returns the floating point equivalent of the integer @var{i}.
6596
6597@item HIGH(@var{a})
6598Returns the index of the last member of @var{a}.
6599
6600@item INC(@var{v})
c3f6f71d 6601Increments the value in the variable @var{v} by one. Returns the new value.
c906108c
SS
6602
6603@item INC(@var{v},@var{i})
6604Increments the value in the variable @var{v} by @var{i}. Returns the
6605new value.
6606
6607@item INCL(@var{m},@var{s})
6608Adds the element @var{m} to the set @var{s} if it is not already
6609there. Returns the new set.
6610
6611@item MAX(@var{t})
6612Returns the maximum value of the type @var{t}.
6613
6614@item MIN(@var{t})
6615Returns the minimum value of the type @var{t}.
6616
6617@item ODD(@var{i})
6618Returns boolean TRUE if @var{i} is an odd number.
6619
6620@item ORD(@var{x})
6621Returns the ordinal value of its argument. For example, the ordinal
c3f6f71d
JM
6622value of a character is its @sc{ascii} value (on machines supporting the
6623@sc{ascii} character set). @var{x} must be of an ordered type, which include
c906108c
SS
6624integral, character and enumerated types.
6625
6626@item SIZE(@var{x})
6627Returns the size of its argument. @var{x} can be a variable or a type.
6628
6629@item TRUNC(@var{r})
6630Returns the integral part of @var{r}.
6631
6632@item VAL(@var{t},@var{i})
6633Returns the member of the type @var{t} whose ordinal value is @var{i}.
6634@end table
6635
6636@quotation
6637@emph{Warning:} Sets and their operations are not yet supported, so
6638@value{GDBN} treats the use of procedures @code{INCL} and @code{EXCL} as
6639an error.
6640@end quotation
6641
6642@cindex Modula-2 constants
6d2ebf8b 6643@node M2 Constants
c906108c
SS
6644@subsubsection Constants
6645
6646@value{GDBN} allows you to express the constants of Modula-2 in the following
6647ways:
6648
6649@itemize @bullet
6650
6651@item
6652Integer constants are simply a sequence of digits. When used in an
6653expression, a constant is interpreted to be type-compatible with the
6654rest of the expression. Hexadecimal integers are specified by a
6655trailing @samp{H}, and octal integers by a trailing @samp{B}.
6656
6657@item
6658Floating point constants appear as a sequence of digits, followed by a
6659decimal point and another sequence of digits. An optional exponent can
6660then be specified, in the form @samp{E@r{[}+@r{|}-@r{]}@var{nnn}}, where
6661@samp{@r{[}+@r{|}-@r{]}@var{nnn}} is the desired exponent. All of the
6662digits of the floating point constant must be valid decimal (base 10)
6663digits.
6664
6665@item
6666Character constants consist of a single character enclosed by a pair of
6667like quotes, either single (@code{'}) or double (@code{"}). They may
c3f6f71d 6668also be expressed by their ordinal value (their @sc{ascii} value, usually)
c906108c
SS
6669followed by a @samp{C}.
6670
6671@item
6672String constants consist of a sequence of characters enclosed by a
6673pair of like quotes, either single (@code{'}) or double (@code{"}).
6674Escape sequences in the style of C are also allowed. @xref{C
6675Constants, ,C and C++ constants}, for a brief explanation of escape
6676sequences.
6677
6678@item
6679Enumerated constants consist of an enumerated identifier.
6680
6681@item
6682Boolean constants consist of the identifiers @code{TRUE} and
6683@code{FALSE}.
6684
6685@item
6686Pointer constants consist of integral values only.
6687
6688@item
6689Set constants are not yet supported.
6690@end itemize
6691
6d2ebf8b 6692@node M2 Defaults
c906108c
SS
6693@subsubsection Modula-2 defaults
6694@cindex Modula-2 defaults
6695
6696If type and range checking are set automatically by @value{GDBN}, they
6697both default to @code{on} whenever the working language changes to
d4f3574e 6698Modula-2. This happens regardless of whether you or @value{GDBN}
c906108c
SS
6699selected the working language.
6700
6701If you allow @value{GDBN} to set the language automatically, then entering
6702code compiled from a file whose name ends with @file{.mod} sets the
d4f3574e 6703working language to Modula-2. @xref{Automatically, ,Having @value{GDBN} set
c906108c
SS
6704the language automatically}, for further details.
6705
6d2ebf8b 6706@node Deviations
c906108c
SS
6707@subsubsection Deviations from standard Modula-2
6708@cindex Modula-2, deviations from
6709
6710A few changes have been made to make Modula-2 programs easier to debug.
6711This is done primarily via loosening its type strictness:
6712
6713@itemize @bullet
6714@item
6715Unlike in standard Modula-2, pointer constants can be formed by
6716integers. This allows you to modify pointer variables during
6717debugging. (In standard Modula-2, the actual address contained in a
6718pointer variable is hidden from you; it can only be modified
6719through direct assignment to another pointer variable or expression that
6720returned a pointer.)
6721
6722@item
6723C escape sequences can be used in strings and characters to represent
6724non-printable characters. @value{GDBN} prints out strings with these
6725escape sequences embedded. Single non-printable characters are
6726printed using the @samp{CHR(@var{nnn})} format.
6727
6728@item
6729The assignment operator (@code{:=}) returns the value of its right-hand
6730argument.
6731
6732@item
6733All built-in procedures both modify @emph{and} return their argument.
6734@end itemize
6735
6d2ebf8b 6736@node M2 Checks
c906108c
SS
6737@subsubsection Modula-2 type and range checks
6738@cindex Modula-2 checks
6739
6740@quotation
6741@emph{Warning:} in this release, @value{GDBN} does not yet perform type or
6742range checking.
6743@end quotation
6744@c FIXME remove warning when type/range checks added
6745
6746@value{GDBN} considers two Modula-2 variables type equivalent if:
6747
6748@itemize @bullet
6749@item
6750They are of types that have been declared equivalent via a @code{TYPE
6751@var{t1} = @var{t2}} statement
6752
6753@item
6754They have been declared on the same line. (Note: This is true of the
6755@sc{gnu} Modula-2 compiler, but it may not be true of other compilers.)
6756@end itemize
6757
6758As long as type checking is enabled, any attempt to combine variables
6759whose types are not equivalent is an error.
6760
6761Range checking is done on all mathematical operations, assignment, array
6762index bounds, and all built-in functions and procedures.
6763
6d2ebf8b 6764@node M2 Scope
c906108c
SS
6765@subsubsection The scope operators @code{::} and @code{.}
6766@cindex scope
6767@kindex .
6768@cindex colon, doubled as scope operator
6769@ifinfo
d4f3574e 6770@kindex colon-colon@r{, in Modula-2}
c906108c
SS
6771@c Info cannot handle :: but TeX can.
6772@end ifinfo
6773@iftex
6774@kindex ::
6775@end iftex
6776
6777There are a few subtle differences between the Modula-2 scope operator
6778(@code{.}) and the @value{GDBN} scope operator (@code{::}). The two have
6779similar syntax:
6780
6781@example
6782
6783@var{module} . @var{id}
6784@var{scope} :: @var{id}
6785@end example
6786
6787@noindent
6788where @var{scope} is the name of a module or a procedure,
6789@var{module} the name of a module, and @var{id} is any declared
6790identifier within your program, except another module.
6791
6792Using the @code{::} operator makes @value{GDBN} search the scope
6793specified by @var{scope} for the identifier @var{id}. If it is not
6794found in the specified scope, then @value{GDBN} searches all scopes
6795enclosing the one specified by @var{scope}.
6796
6797Using the @code{.} operator makes @value{GDBN} search the current scope for
6798the identifier specified by @var{id} that was imported from the
6799definition module specified by @var{module}. With this operator, it is
6800an error if the identifier @var{id} was not imported from definition
6801module @var{module}, or if @var{id} is not an identifier in
6802@var{module}.
6803
6d2ebf8b 6804@node GDB/M2
c906108c
SS
6805@subsubsection @value{GDBN} and Modula-2
6806
6807Some @value{GDBN} commands have little use when debugging Modula-2 programs.
6808Five subcommands of @code{set print} and @code{show print} apply
6809specifically to C and C++: @samp{vtbl}, @samp{demangle},
6810@samp{asm-demangle}, @samp{object}, and @samp{union}. The first four
6811apply to C++, and the last to the C @code{union} type, which has no direct
6812analogue in Modula-2.
6813
6814The @code{@@} operator (@pxref{Expressions, ,Expressions}), while available
d4f3574e 6815with any language, is not useful with Modula-2. Its
c906108c
SS
6816intent is to aid the debugging of @dfn{dynamic arrays}, which cannot be
6817created in Modula-2 as they can in C or C++. However, because an
6818address can be specified by an integral constant, the construct
d4f3574e 6819@samp{@{@var{type}@}@var{adrexp}} is still useful.
c906108c
SS
6820
6821@cindex @code{#} in Modula-2
6822In @value{GDBN} scripts, the Modula-2 inequality operator @code{#} is
6823interpreted as the beginning of a comment. Use @code{<>} instead.
c906108c 6824
6d2ebf8b 6825@node Chill
cce74817
JM
6826@subsection Chill
6827
6828The extensions made to @value{GDBN} to support Chill only support output
d4f3574e 6829from the @sc{gnu} Chill compiler. Other Chill compilers are not currently
cce74817
JM
6830supported, and attempting to debug executables produced by them is most
6831likely to give an error as @value{GDBN} reads in the executable's symbol
6832table.
6833
d4f3574e
SS
6834@c This used to say "... following Chill related topics ...", but since
6835@c menus are not shown in the printed manual, it would look awkward.
6836This section covers the Chill related topics and the features
cce74817
JM
6837of @value{GDBN} which support these topics.
6838
6839@menu
104c1213
JM
6840* How modes are displayed:: How modes are displayed
6841* Locations:: Locations and their accesses
cce74817 6842* Values and their Operations:: Values and their Operations
5d161b24 6843* Chill type and range checks::
53a5351d 6844* Chill defaults::
cce74817
JM
6845@end menu
6846
6d2ebf8b 6847@node How modes are displayed
cce74817
JM
6848@subsubsection How modes are displayed
6849
6850The Chill Datatype- (Mode) support of @value{GDBN} is directly related
d4f3574e 6851with the functionality of the @sc{gnu} Chill compiler, and therefore deviates
cce74817
JM
6852slightly from the standard specification of the Chill language. The
6853provided modes are:
d4f3574e
SS
6854
6855@c FIXME: this @table's contents effectively disable @code by using @r
6856@c on every @item. So why does it need @code?
cce74817
JM
6857@table @code
6858@item @r{@emph{Discrete modes:}}
6859@itemize @bullet
6860@item
6861@emph{Integer Modes} which are predefined by @code{BYTE, UBYTE, INT,
6862UINT, LONG, ULONG},
6863@item
5d161b24 6864@emph{Boolean Mode} which is predefined by @code{BOOL},
cce74817 6865@item
5d161b24 6866@emph{Character Mode} which is predefined by @code{CHAR},
cce74817
JM
6867@item
6868@emph{Set Mode} which is displayed by the keyword @code{SET}.
6869@smallexample
6870(@value{GDBP}) ptype x
6871type = SET (karli = 10, susi = 20, fritzi = 100)
6872@end smallexample
6873If the type is an unnumbered set the set element values are omitted.
6874@item
6d2ebf8b
SS
6875@emph{Range Mode} which is displayed by
6876@smallexample
6877@code{type = <basemode>(<lower bound> : <upper bound>)}
6878@end smallexample
6879where @code{<lower bound>, <upper bound>} can be of any discrete literal
6880expression (e.g. set element names).
cce74817
JM
6881@end itemize
6882
6883@item @r{@emph{Powerset Mode:}}
6884A Powerset Mode is displayed by the keyword @code{POWERSET} followed by
d4f3574e 6885the member mode of the powerset. The member mode can be any discrete mode.
cce74817
JM
6886@smallexample
6887(@value{GDBP}) ptype x
6888type = POWERSET SET (egon, hugo, otto)
6889@end smallexample
6890
6891@item @r{@emph{Reference Modes:}}
6892@itemize @bullet
6893@item
d4f3574e 6894@emph{Bound Reference Mode} which is displayed by the keyword @code{REF}
cce74817
JM
6895followed by the mode name to which the reference is bound.
6896@item
6897@emph{Free Reference Mode} which is displayed by the keyword @code{PTR}.
6898@end itemize
6899
6900@item @r{@emph{Procedure mode}}
6901The procedure mode is displayed by @code{type = PROC(<parameter list>)
6902<return mode> EXCEPTIONS (<exception list>)}. The @code{<parameter
d4f3574e
SS
6903list>} is a list of the parameter modes. @code{<return mode>} indicates
6904the mode of the result of the procedure if any. The exceptionlist lists
cce74817
JM
6905all possible exceptions which can be raised by the procedure.
6906
6907@ignore
6908@item @r{@emph{Instance mode}}
6909The instance mode is represented by a structure, which has a static
5d161b24 6910type, and is therefore not really of interest.
cce74817
JM
6911@end ignore
6912
5d161b24 6913@item @r{@emph{Synchronization Modes:}}
cce74817
JM
6914@itemize @bullet
6915@item
6d2ebf8b
SS
6916@emph{Event Mode} which is displayed by
6917@smallexample
6918@code{EVENT (<event length>)}
6919@end smallexample
cce74817
JM
6920where @code{(<event length>)} is optional.
6921@item
6d2ebf8b
SS
6922@emph{Buffer Mode} which is displayed by
6923@smallexample
6924@code{BUFFER (<buffer length>)<buffer element mode>}
6925@end smallexample
6926where @code{(<buffer length>)} is optional.
cce74817
JM
6927@end itemize
6928
5d161b24 6929@item @r{@emph{Timing Modes:}}
cce74817
JM
6930@itemize @bullet
6931@item
6932@emph{Duration Mode} which is predefined by @code{DURATION}
6933@item
6934@emph{Absolute Time Mode} which is predefined by @code{TIME}
6935@end itemize
6936
6937@item @r{@emph{Real Modes:}}
6938Real Modes are predefined with @code{REAL} and @code{LONG_REAL}.
6939
6940@item @r{@emph{String Modes:}}
6941@itemize @bullet
6942@item
6d2ebf8b
SS
6943@emph{Character String Mode} which is displayed by
6944@smallexample
6945@code{CHARS(<string length>)}
6946@end smallexample
6947followed by the keyword @code{VARYING} if the String Mode is a varying
6948mode
cce74817 6949@item
6d2ebf8b
SS
6950@emph{Bit String Mode} which is displayed by
6951@smallexample
6952@code{BOOLS(<string
6953length>)}
6954@end smallexample
cce74817
JM
6955@end itemize
6956
6957@item @r{@emph{Array Mode:}}
6958The Array Mode is displayed by the keyword @code{ARRAY(<range>)}
6959followed by the element mode (which may in turn be an array mode).
6960@smallexample
6961(@value{GDBP}) ptype x
5d161b24
DB
6962type = ARRAY (1:42)
6963 ARRAY (1:20)
cce74817
JM
6964 SET (karli = 10, susi = 20, fritzi = 100)
6965@end smallexample
6966
5d161b24 6967@item @r{@emph{Structure Mode}}
cce74817 6968The Structure mode is displayed by the keyword @code{STRUCT(<field
d4f3574e
SS
6969list>)}. The @code{<field list>} consists of names and modes of fields
6970of the structure. Variant structures have the keyword @code{CASE <field>
6971OF <variant fields> ESAC} in their field list. Since the current version
cce74817
JM
6972of the GNU Chill compiler doesn't implement tag processing (no runtime
6973checks of variant fields, and therefore no debugging info), the output
6974always displays all variant fields.
6975@smallexample
6976(@value{GDBP}) ptype str
6977type = STRUCT (
6978 as x,
6979 bs x,
6980 CASE bs OF
6981 (karli):
6982 cs a
6983 (ott):
6984 ds x
6985 ESAC
6986)
6987@end smallexample
6988@end table
6989
6d2ebf8b 6990@node Locations
cce74817
JM
6991@subsubsection Locations and their accesses
6992
6993A location in Chill is an object which can contain values.
6994
6995A value of a location is generally accessed by the (declared) name of
d4f3574e
SS
6996the location. The output conforms to the specification of values in
6997Chill programs. How values are specified
6998is the topic of the next section, @ref{Values and their Operations}.
cce74817
JM
6999
7000The pseudo-location @code{RESULT} (or @code{result}) can be used to
7001display or change the result of a currently-active procedure:
d4f3574e 7002
cce74817
JM
7003@smallexample
7004set result := EXPR
7005@end smallexample
d4f3574e
SS
7006
7007@noindent
7008This does the same as the Chill action @code{RESULT EXPR} (which
c3f6f71d 7009is not available in @value{GDBN}).
cce74817
JM
7010
7011Values of reference mode locations are printed by @code{PTR(<hex
7012value>)} in case of a free reference mode, and by @code{(REF <reference
d4f3574e 7013mode>) (<hex-value>)} in case of a bound reference. @code{<hex value>}
cce74817
JM
7014represents the address where the reference points to. To access the
7015value of the location referenced by the pointer, use the dereference
d4f3574e 7016operator @samp{->}.
cce74817 7017
6d2ebf8b
SS
7018Values of procedure mode locations are displayed by
7019@smallexample
7020@code{@{ PROC
cce74817 7021(<argument modes> ) <return mode> @} <address> <name of procedure
6d2ebf8b
SS
7022location>}
7023@end smallexample
7024@code{<argument modes>} is a list of modes according to the parameter
7025specification of the procedure and @code{<address>} shows the address of
7026the entry point.
cce74817
JM
7027
7028@ignore
7029Locations of instance modes are displayed just like a structure with two
7030fields specifying the @emph{process type} and the @emph{copy number} of
7031the investigated instance location@footnote{This comes from the current
d4f3574e
SS
7032implementation of instances. They are implemented as a structure (no
7033na). The output should be something like @code{[<name of the process>;
7034<instance number>]}.}. The field names are @code{__proc_type} and
cce74817
JM
7035@code{__proc_copy}.
7036
7037Locations of synchronization modes are displayed like a structure with
7038the field name @code{__event_data} in case of a event mode location, and
7039like a structure with the field @code{__buffer_data} in case of a buffer
7040mode location (refer to previous paragraph).
7041
7042Structure Mode locations are printed by @code{[.<field name>: <value>,
d4f3574e 7043...]}. The @code{<field name>} corresponds to the structure mode
cce74817 7044definition and the layout of @code{<value>} varies depending of the mode
d4f3574e
SS
7045of the field. If the investigated structure mode location is of variant
7046structure mode, the variant parts of the structure are enclosed in curled
7047braces (@samp{@{@}}). Fields enclosed by @samp{@{,@}} are residing
cce74817 7048on the same memory location and represent the current values of the
d4f3574e 7049memory location in their specific modes. Since no tag processing is done
cce74817 7050all variants are displayed. A variant field is printed by
d4f3574e 7051@code{(<variant name>) = .<field name>: <value>}. (who implements the
cce74817
JM
7052stuff ???)
7053@smallexample
7054(@value{GDBP}) print str1 $4 = [.as: 0, .bs: karli, .<TAG>: { (karli) =
7055[.cs: []], (susi) = [.ds: susi]}]
7056@end smallexample
7057@end ignore
7058
7059Substructures of string mode-, array mode- or structure mode-values
7060(e.g. array slices, fields of structure locations) are accessed using
d4f3574e
SS
7061certain operations which are described in the next section, @ref{Values
7062and their Operations}.
cce74817
JM
7063
7064A location value may be interpreted as having a different mode using the
d4f3574e
SS
7065location conversion. This mode conversion is written as @code{<mode
7066name>(<location>)}. The user has to consider that the sizes of the modes
7067have to be equal otherwise an error occurs. Furthermore, no range
7068checking of the location against the destination mode is performed, and
cce74817 7069therefore the result can be quite confusing.
d4f3574e 7070
cce74817
JM
7071@smallexample
7072(@value{GDBP}) print int (s(3 up 4)) XXX TO be filled in !! XXX
7073@end smallexample
7074
6d2ebf8b 7075@node Values and their Operations
cce74817
JM
7076@subsubsection Values and their Operations
7077
7078Values are used to alter locations, to investigate complex structures in
7079more detail or to filter relevant information out of a large amount of
d4f3574e
SS
7080data. There are several (mode dependent) operations defined which enable
7081such investigations. These operations are not only applicable to
cce74817 7082constant values but also to locations, which can become quite useful
d4f3574e 7083when debugging complex structures. During parsing the command line
cce74817
JM
7084(e.g. evaluating an expression) @value{GDBN} treats location names as
7085the values behind these locations.
7086
d4f3574e 7087This section describes how values have to be specified and which
cce74817
JM
7088operations are legal to be used with such values.
7089
7090@table @code
7091@item Literal Values
d4f3574e
SS
7092Literal values are specified in the same manner as in @sc{gnu} Chill programs.
7093For detailed specification refer to the @sc{gnu} Chill implementation Manual
cce74817 7094chapter 1.5.
d4f3574e
SS
7095@c FIXME: if the Chill Manual is a Texinfo documents, the above should
7096@c be converted to a @ref.
cce74817 7097
5d161b24 7098@ignore
cce74817
JM
7099@itemize @bullet
7100@item
7101@emph{Integer Literals} are specified in the same manner as in Chill
d4f3574e 7102programs (refer to the Chill Standard z200/88 chpt 5.2.4.2)
cce74817
JM
7103@item
7104@emph{Boolean Literals} are defined by @code{TRUE} and @code{FALSE}.
7105@item
7106@emph{Character Literals} are defined by @code{'<character>'}. (e.g.
7107@code{'M'})
7108@item
7109@emph{Set Literals} are defined by a name which was specified in a set
d4f3574e
SS
7110mode. The value delivered by a Set Literal is the set value. This is
7111comparable to an enumeration in C/C++ language.
cce74817 7112@item
d4f3574e 7113@emph{Emptiness Literal} is predefined by @code{NULL}. The value of the
cce74817 7114emptiness literal delivers either the empty reference value, the empty
5d161b24 7115procedure value or the empty instance value.
cce74817
JM
7116
7117@item
7118@emph{Character String Literals} are defined by a sequence of characters
d4f3574e 7119enclosed in single- or double quotes. If a single- or double quote has
cce74817
JM
7120to be part of the string literal it has to be stuffed (specified twice).
7121@item
7122@emph{Bitstring Literals} are specified in the same manner as in Chill
7123programs (refer z200/88 chpt 5.2.4.8).
7124@item
7125@emph{Floating point literals} are specified in the same manner as in
d4f3574e 7126(gnu-)Chill programs (refer @sc{gnu} Chill implementation Manual chapter 1.5).
cce74817
JM
7127@end itemize
7128@end ignore
7129
7130@item Tuple Values
7131A tuple is specified by @code{<mode name>[<tuple>]}, where @code{<mode
d4f3574e 7132name>} can be omitted if the mode of the tuple is unambiguous. This
cce74817
JM
7133unambiguity is derived from the context of a evaluated expression.
7134@code{<tuple>} can be one of the following:
d4f3574e 7135
cce74817
JM
7136@itemize @bullet
7137@item @emph{Powerset Tuple}
7138@item @emph{Array Tuple}
7139@item @emph{Structure Tuple}
7140Powerset tuples, array tuples and structure tuples are specified in the
d4f3574e 7141same manner as in Chill programs refer to z200/88 chpt 5.2.5.
cce74817
JM
7142@end itemize
7143
7144@item String Element Value
6d2ebf8b
SS
7145A string element value is specified by
7146@smallexample
7147@code{<string value>(<index>)}
7148@end smallexample
d4f3574e 7149where @code{<index>} is a integer expression. It delivers a character
cce74817
JM
7150value which is equivalent to the character indexed by @code{<index>} in
7151the string.
7152
7153@item String Slice Value
7154A string slice value is specified by @code{<string value>(<slice
7155spec>)}, where @code{<slice spec>} can be either a range of integer
7156expressions or specified by @code{<start expr> up <size>}.
7157@code{<size>} denotes the number of elements which the slice contains.
7158The delivered value is a string value, which is part of the specified
7159string.
7160
7161@item Array Element Values
7162An array element value is specified by @code{<array value>(<expr>)} and
7163delivers a array element value of the mode of the specified array.
7164
7165@item Array Slice Values
7166An array slice is specified by @code{<array value>(<slice spec>)}, where
7167@code{<slice spec>} can be either a range specified by expressions or by
d4f3574e
SS
7168@code{<start expr> up <size>}. @code{<size>} denotes the number of
7169arrayelements the slice contains. The delivered value is an array value
cce74817
JM
7170which is part of the specified array.
7171
7172@item Structure Field Values
7173A structure field value is derived by @code{<structure value>.<field
d4f3574e
SS
7174name>}, where @code{<field name>} indicates the name of a field specified
7175in the mode definition of the structure. The mode of the delivered value
cce74817
JM
7176corresponds to this mode definition in the structure definition.
7177
7178@item Procedure Call Value
7179The procedure call value is derived from the return value of the
7180procedure@footnote{If a procedure call is used for instance in an
7181expression, then this procedure is called with all its side
d4f3574e 7182effects. This can lead to confusing results if used carelessly.}.
cce74817 7183
d4f3574e 7184Values of duration mode locations are represented by @code{ULONG} literals.
cce74817 7185
6d2ebf8b
SS
7186Values of time mode locations appear as
7187@smallexample
7188@code{TIME(<secs>:<nsecs>)}
7189@end smallexample
7190
cce74817
JM
7191
7192@ignore
7193This is not implemented yet:
7194@item Built-in Value
7195@noindent
7196The following built in functions are provided:
d4f3574e 7197
cce74817
JM
7198@table @code
7199@item @code{ADDR()}
7200@item @code{NUM()}
7201@item @code{PRED()}
7202@item @code{SUCC()}
7203@item @code{ABS()}
7204@item @code{CARD()}
7205@item @code{MAX()}
7206@item @code{MIN()}
7207@item @code{SIZE()}
7208@item @code{UPPER()}
7209@item @code{LOWER()}
7210@item @code{LENGTH()}
7211@item @code{SIN()}
7212@item @code{COS()}
7213@item @code{TAN()}
7214@item @code{ARCSIN()}
7215@item @code{ARCCOS()}
7216@item @code{ARCTAN()}
7217@item @code{EXP()}
7218@item @code{LN()}
7219@item @code{LOG()}
7220@item @code{SQRT()}
7221@end table
7222
7223For a detailed description refer to the GNU Chill implementation manual
7224chapter 1.6.
7225@end ignore
7226
7227@item Zero-adic Operator Value
7228The zero-adic operator value is derived from the instance value for the
7229current active process.
7230
7231@item Expression Values
7232The value delivered by an expression is the result of the evaluation of
d4f3574e 7233the specified expression. If there are error conditions (mode
cce74817 7234incompatibility, etc.) the evaluation of expressions is aborted with a
d4f3574e 7235corresponding error message. Expressions may be parenthesised which
cce74817 7236causes the evaluation of this expression before any other expression
d4f3574e 7237which uses the result of the parenthesised expression. The following
cce74817 7238operators are supported by @value{GDBN}:
d4f3574e 7239
cce74817
JM
7240@table @code
7241@item @code{OR, ORIF, XOR}
d4f3574e
SS
7242@itemx @code{AND, ANDIF}
7243@itemx @code{NOT}
cce74817 7244Logical operators defined over operands of boolean mode.
d4f3574e 7245
cce74817
JM
7246@item @code{=, /=}
7247Equality and inequality operators defined over all modes.
d4f3574e 7248
cce74817 7249@item @code{>, >=}
d4f3574e 7250@itemx @code{<, <=}
cce74817 7251Relational operators defined over predefined modes.
d4f3574e 7252
cce74817 7253@item @code{+, -}
d4f3574e 7254@itemx @code{*, /, MOD, REM}
cce74817 7255Arithmetic operators defined over predefined modes.
d4f3574e 7256
cce74817
JM
7257@item @code{-}
7258Change sign operator.
d4f3574e 7259
cce74817
JM
7260@item @code{//}
7261String concatenation operator.
d4f3574e 7262
cce74817
JM
7263@item @code{()}
7264String repetition operator.
d4f3574e 7265
cce74817
JM
7266@item @code{->}
7267Referenced location operator which can be used either to take the
7268address of a location (@code{->loc}), or to dereference a reference
7269location (@code{loc->}).
d4f3574e 7270
cce74817 7271@item @code{OR, XOR}
d4f3574e
SS
7272@itemx @code{AND}
7273@itemx @code{NOT}
cce74817 7274Powerset and bitstring operators.
d4f3574e 7275
cce74817 7276@item @code{>, >=}
d4f3574e 7277@itemx @code{<, <=}
cce74817 7278Powerset inclusion operators.
d4f3574e 7279
cce74817
JM
7280@item @code{IN}
7281Membership operator.
7282@end table
7283@end table
7284
6d2ebf8b 7285@node Chill type and range checks
cce74817
JM
7286@subsubsection Chill type and range checks
7287
7288@value{GDBN} considers two Chill variables mode equivalent if the sizes
d4f3574e 7289of the two modes are equal. This rule applies recursively to more
cce74817 7290complex datatypes which means that complex modes are treated
d4f3574e 7291equivalent if all element modes (which also can be complex modes like
cce74817
JM
7292structures, arrays, etc.) have the same size.
7293
7294Range checking is done on all mathematical operations, assignment, array
7295index bounds and all built in procedures.
7296
7297Strong type checks are forced using the @value{GDBN} command @code{set
d4f3574e 7298check strong}. This enforces strong type and range checks on all
cce74817
JM
7299operations where Chill constructs are used (expressions, built in
7300functions, etc.) in respect to the semantics as defined in the z.200
7301language specification.
7302
cce74817
JM
7303All checks can be disabled by the @value{GDBN} command @code{set check
7304off}.
7305
5d161b24 7306@ignore
53a5351d 7307@c Deviations from the Chill Standard Z200/88
cce74817
JM
7308see last paragraph ?
7309@end ignore
7310
6d2ebf8b 7311@node Chill defaults
cce74817
JM
7312@subsubsection Chill defaults
7313
7314If type and range checking are set automatically by @value{GDBN}, they
7315both default to @code{on} whenever the working language changes to
d4f3574e 7316Chill. This happens regardless of whether you or @value{GDBN}
cce74817
JM
7317selected the working language.
7318
7319If you allow @value{GDBN} to set the language automatically, then entering
7320code compiled from a file whose name ends with @file{.ch} sets the
d4f3574e 7321working language to Chill. @xref{Automatically, ,Having @value{GDBN} set
cce74817
JM
7322the language automatically}, for further details.
7323
6d2ebf8b 7324@node Symbols
c906108c
SS
7325@chapter Examining the Symbol Table
7326
d4f3574e 7327The commands described in this chapter allow you to inquire about the
c906108c
SS
7328symbols (names of variables, functions and types) defined in your
7329program. This information is inherent in the text of your program and
7330does not change as your program executes. @value{GDBN} finds it in your
7331program's symbol table, in the file indicated when you started @value{GDBN}
7332(@pxref{File Options, ,Choosing files}), or by one of the
7333file-management commands (@pxref{Files, ,Commands to specify files}).
7334
7335@cindex symbol names
7336@cindex names of symbols
7337@cindex quoting names
7338Occasionally, you may need to refer to symbols that contain unusual
7339characters, which @value{GDBN} ordinarily treats as word delimiters. The
7340most frequent case is in referring to static variables in other
7341source files (@pxref{Variables,,Program variables}). File names
7342are recorded in object files as debugging symbols, but @value{GDBN} would
7343ordinarily parse a typical file name, like @file{foo.c}, as the three words
7344@samp{foo} @samp{.} @samp{c}. To allow @value{GDBN} to recognize
7345@samp{foo.c} as a single symbol, enclose it in single quotes; for example,
7346
7347@example
7348p 'foo.c'::x
7349@end example
7350
7351@noindent
7352looks up the value of @code{x} in the scope of the file @file{foo.c}.
7353
7354@table @code
7355@kindex info address
7356@item info address @var{symbol}
7357Describe where the data for @var{symbol} is stored. For a register
7358variable, this says which register it is kept in. For a non-register
7359local variable, this prints the stack-frame offset at which the variable
7360is always stored.
7361
7362Note the contrast with @samp{print &@var{symbol}}, which does not work
7363at all for a register variable, and for a stack local variable prints
7364the exact address of the current instantiation of the variable.
7365
7366@kindex whatis
d4f3574e
SS
7367@item whatis @var{expr}
7368Print the data type of expression @var{expr}. @var{expr} is not
c906108c
SS
7369actually evaluated, and any side-effecting operations (such as
7370assignments or function calls) inside it do not take place.
7371@xref{Expressions, ,Expressions}.
7372
7373@item whatis
7374Print the data type of @code{$}, the last value in the value history.
7375
7376@kindex ptype
7377@item ptype @var{typename}
7378Print a description of data type @var{typename}. @var{typename} may be
7a292a7a
SS
7379the name of a type, or for C code it may have the form @samp{class
7380@var{class-name}}, @samp{struct @var{struct-tag}}, @samp{union
7381@var{union-tag}} or @samp{enum @var{enum-tag}}.
c906108c 7382
d4f3574e 7383@item ptype @var{expr}
c906108c 7384@itemx ptype
d4f3574e 7385Print a description of the type of expression @var{expr}. @code{ptype}
c906108c
SS
7386differs from @code{whatis} by printing a detailed description, instead
7387of just the name of the type.
7388
7389For example, for this variable declaration:
7390
7391@example
7392struct complex @{double real; double imag;@} v;
7393@end example
7394
7395@noindent
7396the two commands give this output:
7397
7398@example
7399@group
7400(@value{GDBP}) whatis v
7401type = struct complex
7402(@value{GDBP}) ptype v
7403type = struct complex @{
7404 double real;
7405 double imag;
7406@}
7407@end group
7408@end example
7409
7410@noindent
7411As with @code{whatis}, using @code{ptype} without an argument refers to
7412the type of @code{$}, the last value in the value history.
7413
7414@kindex info types
7415@item info types @var{regexp}
7416@itemx info types
d4f3574e 7417Print a brief description of all types whose names match @var{regexp}
c906108c
SS
7418(or all types in your program, if you supply no argument). Each
7419complete typename is matched as though it were a complete line; thus,
7420@samp{i type value} gives information on all types in your program whose
d4f3574e 7421names include the string @code{value}, but @samp{i type ^value$} gives
c906108c
SS
7422information only on types whose complete name is @code{value}.
7423
7424This command differs from @code{ptype} in two ways: first, like
7425@code{whatis}, it does not print a detailed description; second, it
7426lists all source files where a type is defined.
7427
7428@kindex info source
7429@item info source
7430Show the name of the current source file---that is, the source file for
7431the function containing the current point of execution---and the language
7432it was written in.
7433
7434@kindex info sources
7435@item info sources
7436Print the names of all source files in your program for which there is
7437debugging information, organized into two lists: files whose symbols
7438have already been read, and files whose symbols will be read when needed.
7439
7440@kindex info functions
7441@item info functions
7442Print the names and data types of all defined functions.
7443
7444@item info functions @var{regexp}
7445Print the names and data types of all defined functions
7446whose names contain a match for regular expression @var{regexp}.
7447Thus, @samp{info fun step} finds all functions whose names
7448include @code{step}; @samp{info fun ^step} finds those whose names
7449start with @code{step}.
7450
7451@kindex info variables
7452@item info variables
7453Print the names and data types of all variables that are declared
7454outside of functions (i.e., excluding local variables).
7455
7456@item info variables @var{regexp}
7457Print the names and data types of all variables (except for local
7458variables) whose names contain a match for regular expression
7459@var{regexp}.
7460
7461@ignore
7462This was never implemented.
7463@kindex info methods
7464@item info methods
7465@itemx info methods @var{regexp}
7466The @code{info methods} command permits the user to examine all defined
7467methods within C++ program, or (with the @var{regexp} argument) a
7468specific set of methods found in the various C++ classes. Many
7469C++ classes provide a large number of methods. Thus, the output
7470from the @code{ptype} command can be overwhelming and hard to use. The
7471@code{info-methods} command filters the methods, printing only those
7472which match the regular-expression @var{regexp}.
7473@end ignore
7474
c906108c
SS
7475@cindex reloading symbols
7476Some systems allow individual object files that make up your program to
7a292a7a
SS
7477be replaced without stopping and restarting your program. For example,
7478in VxWorks you can simply recompile a defective object file and keep on
7479running. If you are running on one of these systems, you can allow
7480@value{GDBN} to reload the symbols for automatically relinked modules:
c906108c
SS
7481
7482@table @code
7483@kindex set symbol-reloading
7484@item set symbol-reloading on
7485Replace symbol definitions for the corresponding source file when an
7486object file with a particular name is seen again.
7487
7488@item set symbol-reloading off
6d2ebf8b
SS
7489Do not replace symbol definitions when encountering object files of the
7490same name more than once. This is the default state; if you are not
7491running on a system that permits automatic relinking of modules, you
7492should leave @code{symbol-reloading} off, since otherwise @value{GDBN}
7493may discard symbols when linking large programs, that may contain
7494several modules (from different directories or libraries) with the same
7495name.
c906108c
SS
7496
7497@kindex show symbol-reloading
7498@item show symbol-reloading
7499Show the current @code{on} or @code{off} setting.
7500@end table
c906108c 7501
c906108c
SS
7502@kindex set opaque-type-resolution
7503@item set opaque-type-resolution on
7504Tell @value{GDBN} to resolve opaque types. An opaque type is a type
7505declared as a pointer to a @code{struct}, @code{class}, or
7506@code{union}---for example, @code{struct MyType *}---that is used in one
7507source file although the full declaration of @code{struct MyType} is in
7508another source file. The default is on.
7509
7510A change in the setting of this subcommand will not take effect until
7511the next time symbols for a file are loaded.
7512
7513@item set opaque-type-resolution off
7514Tell @value{GDBN} not to resolve opaque types. In this case, the type
7515is printed as follows:
7516@smallexample
7517@{<no data fields>@}
7518@end smallexample
7519
7520@kindex show opaque-type-resolution
7521@item show opaque-type-resolution
7522Show whether opaque types are resolved or not.
c906108c
SS
7523
7524@kindex maint print symbols
7525@cindex symbol dump
7526@kindex maint print psymbols
7527@cindex partial symbol dump
7528@item maint print symbols @var{filename}
7529@itemx maint print psymbols @var{filename}
7530@itemx maint print msymbols @var{filename}
7531Write a dump of debugging symbol data into the file @var{filename}.
7532These commands are used to debug the @value{GDBN} symbol-reading code. Only
7533symbols with debugging data are included. If you use @samp{maint print
7534symbols}, @value{GDBN} includes all the symbols for which it has already
7535collected full details: that is, @var{filename} reflects symbols for
7536only those files whose symbols @value{GDBN} has read. You can use the
7537command @code{info sources} to find out which files these are. If you
7538use @samp{maint print psymbols} instead, the dump shows information about
7539symbols that @value{GDBN} only knows partially---that is, symbols defined in
7540files that @value{GDBN} has skimmed, but not yet read completely. Finally,
7541@samp{maint print msymbols} dumps just the minimal symbol information
7542required for each object file from which @value{GDBN} has read some symbols.
7543@xref{Files, ,Commands to specify files}, for a discussion of how
7544@value{GDBN} reads symbols (in the description of @code{symbol-file}).
7545@end table
7546
6d2ebf8b 7547@node Altering
c906108c
SS
7548@chapter Altering Execution
7549
7550Once you think you have found an error in your program, you might want to
7551find out for certain whether correcting the apparent error would lead to
7552correct results in the rest of the run. You can find the answer by
7553experiment, using the @value{GDBN} features for altering execution of the
7554program.
7555
7556For example, you can store new values into variables or memory
7a292a7a
SS
7557locations, give your program a signal, restart it at a different
7558address, or even return prematurely from a function.
c906108c
SS
7559
7560@menu
7561* Assignment:: Assignment to variables
7562* Jumping:: Continuing at a different address
c906108c 7563* Signaling:: Giving your program a signal
c906108c
SS
7564* Returning:: Returning from a function
7565* Calling:: Calling your program's functions
7566* Patching:: Patching your program
7567@end menu
7568
6d2ebf8b 7569@node Assignment
c906108c
SS
7570@section Assignment to variables
7571
7572@cindex assignment
7573@cindex setting variables
7574To alter the value of a variable, evaluate an assignment expression.
7575@xref{Expressions, ,Expressions}. For example,
7576
7577@example
7578print x=4
7579@end example
7580
7581@noindent
7582stores the value 4 into the variable @code{x}, and then prints the
5d161b24 7583value of the assignment expression (which is 4).
c906108c
SS
7584@xref{Languages, ,Using @value{GDBN} with Different Languages}, for more
7585information on operators in supported languages.
c906108c
SS
7586
7587@kindex set variable
7588@cindex variables, setting
7589If you are not interested in seeing the value of the assignment, use the
7590@code{set} command instead of the @code{print} command. @code{set} is
7591really the same as @code{print} except that the expression's value is
7592not printed and is not put in the value history (@pxref{Value History,
7593,Value history}). The expression is evaluated only for its effects.
7594
c906108c
SS
7595If the beginning of the argument string of the @code{set} command
7596appears identical to a @code{set} subcommand, use the @code{set
7597variable} command instead of just @code{set}. This command is identical
7598to @code{set} except for its lack of subcommands. For example, if your
7599program has a variable @code{width}, you get an error if you try to set
7600a new value with just @samp{set width=13}, because @value{GDBN} has the
7601command @code{set width}:
7602
7603@example
7604(@value{GDBP}) whatis width
7605type = double
7606(@value{GDBP}) p width
7607$4 = 13
7608(@value{GDBP}) set width=47
7609Invalid syntax in expression.
7610@end example
7611
7612@noindent
7613The invalid expression, of course, is @samp{=47}. In
7614order to actually set the program's variable @code{width}, use
7615
7616@example
7617(@value{GDBP}) set var width=47
7618@end example
53a5351d 7619
c906108c
SS
7620Because the @code{set} command has many subcommands that can conflict
7621with the names of program variables, it is a good idea to use the
7622@code{set variable} command instead of just @code{set}. For example, if
7623your program has a variable @code{g}, you run into problems if you try
7624to set a new value with just @samp{set g=4}, because @value{GDBN} has
7625the command @code{set gnutarget}, abbreviated @code{set g}:
7626
7627@example
7628@group
7629(@value{GDBP}) whatis g
7630type = double
7631(@value{GDBP}) p g
7632$1 = 1
7633(@value{GDBP}) set g=4
2df3850c 7634(@value{GDBP}) p g
c906108c
SS
7635$2 = 1
7636(@value{GDBP}) r
7637The program being debugged has been started already.
7638Start it from the beginning? (y or n) y
7639Starting program: /home/smith/cc_progs/a.out
6d2ebf8b
SS
7640"/home/smith/cc_progs/a.out": can't open to read symbols:
7641 Invalid bfd target.
c906108c
SS
7642(@value{GDBP}) show g
7643The current BFD target is "=4".
7644@end group
7645@end example
7646
7647@noindent
7648The program variable @code{g} did not change, and you silently set the
7649@code{gnutarget} to an invalid value. In order to set the variable
7650@code{g}, use
7651
7652@example
7653(@value{GDBP}) set var g=4
7654@end example
c906108c
SS
7655
7656@value{GDBN} allows more implicit conversions in assignments than C; you can
7657freely store an integer value into a pointer variable or vice versa,
7658and you can convert any structure to any other structure that is the
7659same length or shorter.
7660@comment FIXME: how do structs align/pad in these conversions?
7661@comment /doc@cygnus.com 18dec1990
7662
7663To store values into arbitrary places in memory, use the @samp{@{@dots{}@}}
7664construct to generate a value of specified type at a specified address
7665(@pxref{Expressions, ,Expressions}). For example, @code{@{int@}0x83040} refers
7666to memory location @code{0x83040} as an integer (which implies a certain size
7667and representation in memory), and
7668
7669@example
7670set @{int@}0x83040 = 4
7671@end example
7672
7673@noindent
7674stores the value 4 into that memory location.
7675
6d2ebf8b 7676@node Jumping
c906108c
SS
7677@section Continuing at a different address
7678
7679Ordinarily, when you continue your program, you do so at the place where
7680it stopped, with the @code{continue} command. You can instead continue at
7681an address of your own choosing, with the following commands:
7682
7683@table @code
7684@kindex jump
7685@item jump @var{linespec}
7686Resume execution at line @var{linespec}. Execution stops again
7687immediately if there is a breakpoint there. @xref{List, ,Printing
7688source lines}, for a description of the different forms of
7689@var{linespec}. It is common practice to use the @code{tbreak} command
7690in conjunction with @code{jump}. @xref{Set Breaks, ,Setting
7691breakpoints}.
7692
7693The @code{jump} command does not change the current stack frame, or
7694the stack pointer, or the contents of any memory location or any
7695register other than the program counter. If line @var{linespec} is in
7696a different function from the one currently executing, the results may
7697be bizarre if the two functions expect different patterns of arguments or
7698of local variables. For this reason, the @code{jump} command requests
7699confirmation if the specified line is not in the function currently
7700executing. However, even bizarre results are predictable if you are
7701well acquainted with the machine-language code of your program.
7702
7703@item jump *@var{address}
7704Resume execution at the instruction at address @var{address}.
7705@end table
7706
c906108c 7707@c Doesn't work on HP-UX; have to set $pcoqh and $pcoqt.
53a5351d
JM
7708On many systems, you can get much the same effect as the @code{jump}
7709command by storing a new value into the register @code{$pc}. The
7710difference is that this does not start your program running; it only
7711changes the address of where it @emph{will} run when you continue. For
7712example,
c906108c
SS
7713
7714@example
7715set $pc = 0x485
7716@end example
7717
7718@noindent
7719makes the next @code{continue} command or stepping command execute at
7720address @code{0x485}, rather than at the address where your program stopped.
7721@xref{Continuing and Stepping, ,Continuing and stepping}.
c906108c
SS
7722
7723The most common occasion to use the @code{jump} command is to back
7724up---perhaps with more breakpoints set---over a portion of a program
7725that has already executed, in order to examine its execution in more
7726detail.
7727
c906108c 7728@c @group
6d2ebf8b 7729@node Signaling
c906108c
SS
7730@section Giving your program a signal
7731
7732@table @code
7733@kindex signal
7734@item signal @var{signal}
7735Resume execution where your program stopped, but immediately give it the
7736signal @var{signal}. @var{signal} can be the name or the number of a
7737signal. For example, on many systems @code{signal 2} and @code{signal
7738SIGINT} are both ways of sending an interrupt signal.
7739
7740Alternatively, if @var{signal} is zero, continue execution without
7741giving a signal. This is useful when your program stopped on account of
7742a signal and would ordinary see the signal when resumed with the
7743@code{continue} command; @samp{signal 0} causes it to resume without a
7744signal.
7745
7746@code{signal} does not repeat when you press @key{RET} a second time
7747after executing the command.
7748@end table
7749@c @end group
7750
7751Invoking the @code{signal} command is not the same as invoking the
7752@code{kill} utility from the shell. Sending a signal with @code{kill}
7753causes @value{GDBN} to decide what to do with the signal depending on
7754the signal handling tables (@pxref{Signals}). The @code{signal} command
7755passes the signal directly to your program.
7756
c906108c 7757
6d2ebf8b 7758@node Returning
c906108c
SS
7759@section Returning from a function
7760
7761@table @code
7762@cindex returning from a function
7763@kindex return
7764@item return
7765@itemx return @var{expression}
7766You can cancel execution of a function call with the @code{return}
7767command. If you give an
7768@var{expression} argument, its value is used as the function's return
7769value.
7770@end table
7771
7772When you use @code{return}, @value{GDBN} discards the selected stack frame
7773(and all frames within it). You can think of this as making the
7774discarded frame return prematurely. If you wish to specify a value to
7775be returned, give that value as the argument to @code{return}.
7776
7777This pops the selected stack frame (@pxref{Selection, ,Selecting a
7778frame}), and any other frames inside of it, leaving its caller as the
7779innermost remaining frame. That frame becomes selected. The
7780specified value is stored in the registers used for returning values
7781of functions.
7782
7783The @code{return} command does not resume execution; it leaves the
7784program stopped in the state that would exist if the function had just
7785returned. In contrast, the @code{finish} command (@pxref{Continuing
7786and Stepping, ,Continuing and stepping}) resumes execution until the
7787selected stack frame returns naturally.
7788
6d2ebf8b 7789@node Calling
c906108c
SS
7790@section Calling program functions
7791
7792@cindex calling functions
7793@kindex call
7794@table @code
7795@item call @var{expr}
7796Evaluate the expression @var{expr} without displaying @code{void}
7797returned values.
7798@end table
7799
7800You can use this variant of the @code{print} command if you want to
7801execute a function from your program, but without cluttering the output
5d161b24
DB
7802with @code{void} returned values. If the result is not void, it
7803is printed and saved in the value history.
c906108c 7804
c906108c
SS
7805For the A29K, a user-controlled variable @code{call_scratch_address},
7806specifies the location of a scratch area to be used when @value{GDBN}
7807calls a function in the target. This is necessary because the usual
7808method of putting the scratch area on the stack does not work in systems
7809that have separate instruction and data spaces.
c906108c 7810
6d2ebf8b 7811@node Patching
c906108c 7812@section Patching programs
7a292a7a 7813
c906108c
SS
7814@cindex patching binaries
7815@cindex writing into executables
c906108c 7816@cindex writing into corefiles
c906108c 7817
7a292a7a
SS
7818By default, @value{GDBN} opens the file containing your program's
7819executable code (or the corefile) read-only. This prevents accidental
7820alterations to machine code; but it also prevents you from intentionally
7821patching your program's binary.
c906108c
SS
7822
7823If you'd like to be able to patch the binary, you can specify that
7824explicitly with the @code{set write} command. For example, you might
7825want to turn on internal debugging flags, or even to make emergency
7826repairs.
7827
7828@table @code
7829@kindex set write
7830@item set write on
7831@itemx set write off
7a292a7a
SS
7832If you specify @samp{set write on}, @value{GDBN} opens executable and
7833core files for both reading and writing; if you specify @samp{set write
c906108c
SS
7834off} (the default), @value{GDBN} opens them read-only.
7835
7836If you have already loaded a file, you must load it again (using the
7a292a7a
SS
7837@code{exec-file} or @code{core-file} command) after changing @code{set
7838write}, for your new setting to take effect.
c906108c
SS
7839
7840@item show write
7841@kindex show write
7a292a7a
SS
7842Display whether executable files and core files are opened for writing
7843as well as reading.
c906108c
SS
7844@end table
7845
6d2ebf8b 7846@node GDB Files
c906108c
SS
7847@chapter @value{GDBN} Files
7848
7a292a7a
SS
7849@value{GDBN} needs to know the file name of the program to be debugged,
7850both in order to read its symbol table and in order to start your
7851program. To debug a core dump of a previous run, you must also tell
7852@value{GDBN} the name of the core dump file.
c906108c
SS
7853
7854@menu
7855* Files:: Commands to specify files
7856* Symbol Errors:: Errors reading symbol files
7857@end menu
7858
6d2ebf8b 7859@node Files
c906108c 7860@section Commands to specify files
c906108c 7861
7a292a7a 7862@cindex symbol table
c906108c 7863@cindex core dump file
7a292a7a
SS
7864
7865You may want to specify executable and core dump file names. The usual
7866way to do this is at start-up time, using the arguments to
7867@value{GDBN}'s start-up commands (@pxref{Invocation, , Getting In and
7868Out of @value{GDBN}}).
c906108c
SS
7869
7870Occasionally it is necessary to change to a different file during a
7871@value{GDBN} session. Or you may run @value{GDBN} and forget to specify
7872a file you want to use. In these situations the @value{GDBN} commands
7873to specify new files are useful.
7874
7875@table @code
7876@cindex executable file
7877@kindex file
7878@item file @var{filename}
7879Use @var{filename} as the program to be debugged. It is read for its
7880symbols and for the contents of pure memory. It is also the program
7881executed when you use the @code{run} command. If you do not specify a
5d161b24
DB
7882directory and the file is not found in the @value{GDBN} working directory,
7883@value{GDBN} uses the environment variable @code{PATH} as a list of
7884directories to search, just as the shell does when looking for a program
7885to run. You can change the value of this variable, for both @value{GDBN}
c906108c
SS
7886and your program, using the @code{path} command.
7887
6d2ebf8b 7888On systems with memory-mapped files, an auxiliary file named
c906108c
SS
7889@file{@var{filename}.syms} may hold symbol table information for
7890@var{filename}. If so, @value{GDBN} maps in the symbol table from
7891@file{@var{filename}.syms}, starting up more quickly. See the
7892descriptions of the file options @samp{-mapped} and @samp{-readnow}
7893(available on the command line, and with the commands @code{file},
5d161b24 7894@code{symbol-file}, or @code{add-symbol-file}, described below),
c906108c 7895for more information.
c906108c
SS
7896
7897@item file
7898@code{file} with no argument makes @value{GDBN} discard any information it
7899has on both executable file and the symbol table.
7900
7901@kindex exec-file
7902@item exec-file @r{[} @var{filename} @r{]}
7903Specify that the program to be run (but not the symbol table) is found
7904in @var{filename}. @value{GDBN} searches the environment variable @code{PATH}
7905if necessary to locate your program. Omitting @var{filename} means to
7906discard information on the executable file.
7907
7908@kindex symbol-file
7909@item symbol-file @r{[} @var{filename} @r{]}
7910Read symbol table information from file @var{filename}. @code{PATH} is
7911searched when necessary. Use the @code{file} command to get both symbol
7912table and program to run from the same file.
7913
7914@code{symbol-file} with no argument clears out @value{GDBN} information on your
7915program's symbol table.
7916
5d161b24 7917The @code{symbol-file} command causes @value{GDBN} to forget the contents
c906108c
SS
7918of its convenience variables, the value history, and all breakpoints and
7919auto-display expressions. This is because they may contain pointers to
7920the internal data recording symbols and data types, which are part of
7921the old symbol table data being discarded inside @value{GDBN}.
7922
7923@code{symbol-file} does not repeat if you press @key{RET} again after
7924executing it once.
7925
7926When @value{GDBN} is configured for a particular environment, it
7927understands debugging information in whatever format is the standard
7928generated for that environment; you may use either a @sc{gnu} compiler, or
7929other compilers that adhere to the local conventions.
c906108c
SS
7930Best results are usually obtained from @sc{gnu} compilers; for example,
7931using @code{@value{GCC}} you can generate debugging information for
7932optimized code.
c906108c
SS
7933
7934For most kinds of object files, with the exception of old SVR3 systems
7935using COFF, the @code{symbol-file} command does not normally read the
7936symbol table in full right away. Instead, it scans the symbol table
7937quickly to find which source files and which symbols are present. The
7938details are read later, one source file at a time, as they are needed.
7939
7940The purpose of this two-stage reading strategy is to make @value{GDBN}
7941start up faster. For the most part, it is invisible except for
7942occasional pauses while the symbol table details for a particular source
7943file are being read. (The @code{set verbose} command can turn these
7944pauses into messages if desired. @xref{Messages/Warnings, ,Optional
7945warnings and messages}.)
7946
c906108c
SS
7947We have not implemented the two-stage strategy for COFF yet. When the
7948symbol table is stored in COFF format, @code{symbol-file} reads the
7949symbol table data in full right away. Note that ``stabs-in-COFF''
7950still does the two-stage strategy, since the debug info is actually
7951in stabs format.
7952
7953@kindex readnow
7954@cindex reading symbols immediately
7955@cindex symbols, reading immediately
7956@kindex mapped
7957@cindex memory-mapped symbol file
7958@cindex saving symbol table
7959@item symbol-file @var{filename} @r{[} -readnow @r{]} @r{[} -mapped @r{]}
7960@itemx file @var{filename} @r{[} -readnow @r{]} @r{[} -mapped @r{]}
7961You can override the @value{GDBN} two-stage strategy for reading symbol
7962tables by using the @samp{-readnow} option with any of the commands that
7963load symbol table information, if you want to be sure @value{GDBN} has the
5d161b24 7964entire symbol table available.
c906108c 7965
c906108c
SS
7966If memory-mapped files are available on your system through the
7967@code{mmap} system call, you can use another option, @samp{-mapped}, to
7968cause @value{GDBN} to write the symbols for your program into a reusable
7969file. Future @value{GDBN} debugging sessions map in symbol information
7970from this auxiliary symbol file (if the program has not changed), rather
7971than spending time reading the symbol table from the executable
7972program. Using the @samp{-mapped} option has the same effect as
7973starting @value{GDBN} with the @samp{-mapped} command-line option.
7974
7975You can use both options together, to make sure the auxiliary symbol
7976file has all the symbol information for your program.
7977
7978The auxiliary symbol file for a program called @var{myprog} is called
7979@samp{@var{myprog}.syms}. Once this file exists (so long as it is newer
7980than the corresponding executable), @value{GDBN} always attempts to use
7981it when you debug @var{myprog}; no special options or commands are
7982needed.
7983
7984The @file{.syms} file is specific to the host machine where you run
7985@value{GDBN}. It holds an exact image of the internal @value{GDBN}
7986symbol table. It cannot be shared across multiple host platforms.
c906108c
SS
7987
7988@c FIXME: for now no mention of directories, since this seems to be in
7989@c flux. 13mar1992 status is that in theory GDB would look either in
7990@c current dir or in same dir as myprog; but issues like competing
7991@c GDB's, or clutter in system dirs, mean that in practice right now
7992@c only current dir is used. FFish says maybe a special GDB hierarchy
7993@c (eg rooted in val of env var GDBSYMS) could exist for mappable symbol
7994@c files.
7995
7996@kindex core
7997@kindex core-file
7998@item core-file @r{[} @var{filename} @r{]}
7999Specify the whereabouts of a core dump file to be used as the ``contents
8000of memory''. Traditionally, core files contain only some parts of the
8001address space of the process that generated them; @value{GDBN} can access the
8002executable file itself for other parts.
8003
8004@code{core-file} with no argument specifies that no core file is
8005to be used.
8006
8007Note that the core file is ignored when your program is actually running
7a292a7a
SS
8008under @value{GDBN}. So, if you have been running your program and you
8009wish to debug a core file instead, you must kill the subprocess in which
8010the program is running. To do this, use the @code{kill} command
c906108c 8011(@pxref{Kill Process, ,Killing the child process}).
c906108c 8012
c906108c
SS
8013@kindex add-symbol-file
8014@cindex dynamic linking
8015@item add-symbol-file @var{filename} @var{address}
8016@itemx add-symbol-file @var{filename} @var{address} @r{[} -readnow @r{]} @r{[} -mapped @r{]}
d167840f 8017@itemx add-symbol-file @var{filename} @r{-s}@var{section} @var{address}
96a2c332
SS
8018The @code{add-symbol-file} command reads additional symbol table
8019information from the file @var{filename}. You would use this command
8020when @var{filename} has been dynamically loaded (by some other means)
8021into the program that is running. @var{address} should be the memory
8022address at which the file has been loaded; @value{GDBN} cannot figure
d167840f
EZ
8023this out for itself. You can additionally specify an arbitrary number
8024of @samp{@r{-s}@var{section} @var{address}} pairs, to give an explicit
8025section name and base address for that section. You can specify any
8026@var{address} as an expression.
c906108c
SS
8027
8028The symbol table of the file @var{filename} is added to the symbol table
8029originally read with the @code{symbol-file} command. You can use the
96a2c332
SS
8030@code{add-symbol-file} command any number of times; the new symbol data
8031thus read keeps adding to the old. To discard all old symbol data
8032instead, use the @code{symbol-file} command without any arguments.
c906108c
SS
8033
8034@code{add-symbol-file} does not repeat if you press @key{RET} after using it.
8035
8036You can use the @samp{-mapped} and @samp{-readnow} options just as with
8037the @code{symbol-file} command, to change how @value{GDBN} manages the symbol
8038table information for @var{filename}.
8039
8040@kindex add-shared-symbol-file
8041@item add-shared-symbol-file
8042The @code{add-shared-symbol-file} command can be used only under Harris' CXUX
5d161b24
DB
8043operating system for the Motorola 88k. @value{GDBN} automatically looks for
8044shared libraries, however if @value{GDBN} does not find yours, you can run
c906108c 8045@code{add-shared-symbol-file}. It takes no arguments.
c906108c 8046
c906108c
SS
8047@kindex section
8048@item section
5d161b24
DB
8049The @code{section} command changes the base address of section SECTION of
8050the exec file to ADDR. This can be used if the exec file does not contain
8051section addresses, (such as in the a.out format), or when the addresses
8052specified in the file itself are wrong. Each section must be changed
d4f3574e
SS
8053separately. The @code{info files} command, described below, lists all
8054the sections and their addresses.
c906108c
SS
8055
8056@kindex info files
8057@kindex info target
8058@item info files
8059@itemx info target
7a292a7a
SS
8060@code{info files} and @code{info target} are synonymous; both print the
8061current target (@pxref{Targets, ,Specifying a Debugging Target}),
8062including the names of the executable and core dump files currently in
8063use by @value{GDBN}, and the files from which symbols were loaded. The
8064command @code{help target} lists all possible targets rather than
8065current ones.
8066
c906108c
SS
8067@end table
8068
8069All file-specifying commands allow both absolute and relative file names
8070as arguments. @value{GDBN} always converts the file name to an absolute file
8071name and remembers it that way.
8072
c906108c 8073@cindex shared libraries
c906108c
SS
8074@value{GDBN} supports HP-UX, SunOS, SVr4, Irix 5, and IBM RS/6000 shared
8075libraries.
53a5351d 8076
c906108c
SS
8077@value{GDBN} automatically loads symbol definitions from shared libraries
8078when you use the @code{run} command, or when you examine a core file.
8079(Before you issue the @code{run} command, @value{GDBN} does not understand
8080references to a function in a shared library, however---unless you are
8081debugging a core file).
53a5351d
JM
8082
8083On HP-UX, if the program loads a library explicitly, @value{GDBN}
8084automatically loads the symbols at the time of the @code{shl_load} call.
8085
c906108c
SS
8086@c FIXME: some @value{GDBN} release may permit some refs to undef
8087@c FIXME...symbols---eg in a break cmd---assuming they are from a shared
8088@c FIXME...lib; check this from time to time when updating manual
8089
8090@table @code
8091@kindex info sharedlibrary
8092@kindex info share
8093@item info share
8094@itemx info sharedlibrary
8095Print the names of the shared libraries which are currently loaded.
8096
8097@kindex sharedlibrary
8098@kindex share
8099@item sharedlibrary @var{regex}
8100@itemx share @var{regex}
c906108c
SS
8101Load shared object library symbols for files matching a
8102Unix regular expression.
8103As with files loaded automatically, it only loads shared libraries
8104required by your program for a core file or after typing @code{run}. If
8105@var{regex} is omitted all shared libraries required by your program are
8106loaded.
8107@end table
8108
53a5351d
JM
8109On HP-UX systems, @value{GDBN} detects the loading of a shared library
8110and automatically reads in symbols from the newly loaded library, up to
8111a threshold that is initially set but that you can modify if you wish.
c906108c
SS
8112
8113Beyond that threshold, symbols from shared libraries must be explicitly
d4f3574e
SS
8114loaded. To load these symbols, use the command @code{sharedlibrary
8115@var{filename}}. The base address of the shared library is determined
c906108c
SS
8116automatically by @value{GDBN} and need not be specified.
8117
8118To display or set the threshold, use the commands:
8119
8120@table @code
8121@kindex set auto-solib-add
8122@item set auto-solib-add @var{threshold}
8123Set the autoloading size threshold, in megabytes. If @var{threshold} is
8124nonzero, symbols from all shared object libraries will be loaded
8125automatically when the inferior begins execution or when the dynamic
8126linker informs @value{GDBN} that a new library has been loaded, until
8127the symbol table of the program and libraries exceeds this threshold.
8128Otherwise, symbols must be loaded manually, using the
8129@code{sharedlibrary} command. The default threshold is 100 megabytes.
8130
8131@kindex show auto-solib-add
8132@item show auto-solib-add
8133Display the current autoloading size threshold, in megabytes.
8134@end table
c906108c 8135
6d2ebf8b 8136@node Symbol Errors
c906108c
SS
8137@section Errors reading symbol files
8138
8139While reading a symbol file, @value{GDBN} occasionally encounters problems,
8140such as symbol types it does not recognize, or known bugs in compiler
8141output. By default, @value{GDBN} does not notify you of such problems, since
8142they are relatively common and primarily of interest to people
8143debugging compilers. If you are interested in seeing information
8144about ill-constructed symbol tables, you can either ask @value{GDBN} to print
8145only one message about each such type of problem, no matter how many
8146times the problem occurs; or you can ask @value{GDBN} to print more messages,
8147to see how many times the problems occur, with the @code{set
8148complaints} command (@pxref{Messages/Warnings, ,Optional warnings and
8149messages}).
8150
8151The messages currently printed, and their meanings, include:
8152
8153@table @code
8154@item inner block not inside outer block in @var{symbol}
8155
8156The symbol information shows where symbol scopes begin and end
8157(such as at the start of a function or a block of statements). This
8158error indicates that an inner scope block is not fully contained
8159in its outer scope blocks.
8160
8161@value{GDBN} circumvents the problem by treating the inner block as if it had
8162the same scope as the outer block. In the error message, @var{symbol}
8163may be shown as ``@code{(don't know)}'' if the outer block is not a
8164function.
8165
8166@item block at @var{address} out of order
8167
8168The symbol information for symbol scope blocks should occur in
8169order of increasing addresses. This error indicates that it does not
8170do so.
8171
8172@value{GDBN} does not circumvent this problem, and has trouble
8173locating symbols in the source file whose symbols it is reading. (You
8174can often determine what source file is affected by specifying
8175@code{set verbose on}. @xref{Messages/Warnings, ,Optional warnings and
8176messages}.)
8177
8178@item bad block start address patched
8179
8180The symbol information for a symbol scope block has a start address
8181smaller than the address of the preceding source line. This is known
8182to occur in the SunOS 4.1.1 (and earlier) C compiler.
8183
8184@value{GDBN} circumvents the problem by treating the symbol scope block as
8185starting on the previous source line.
8186
8187@item bad string table offset in symbol @var{n}
8188
8189@cindex foo
8190Symbol number @var{n} contains a pointer into the string table which is
8191larger than the size of the string table.
8192
8193@value{GDBN} circumvents the problem by considering the symbol to have the
8194name @code{foo}, which may cause other problems if many symbols end up
8195with this name.
8196
8197@item unknown symbol type @code{0x@var{nn}}
8198
7a292a7a
SS
8199The symbol information contains new data types that @value{GDBN} does
8200not yet know how to read. @code{0x@var{nn}} is the symbol type of the
d4f3574e 8201uncomprehended information, in hexadecimal.
c906108c 8202
7a292a7a
SS
8203@value{GDBN} circumvents the error by ignoring this symbol information.
8204This usually allows you to debug your program, though certain symbols
c906108c 8205are not accessible. If you encounter such a problem and feel like
7a292a7a
SS
8206debugging it, you can debug @code{@value{GDBP}} with itself, breakpoint
8207on @code{complain}, then go up to the function @code{read_dbx_symtab}
8208and examine @code{*bufp} to see the symbol.
c906108c
SS
8209
8210@item stub type has NULL name
c906108c 8211
7a292a7a 8212@value{GDBN} could not find the full definition for a struct or class.
c906108c 8213
7a292a7a 8214@item const/volatile indicator missing (ok if using g++ v1.x), got@dots{}
c906108c 8215The symbol information for a C++ member function is missing some
7a292a7a
SS
8216information that recent versions of the compiler should have output for
8217it.
c906108c
SS
8218
8219@item info mismatch between compiler and debugger
8220
8221@value{GDBN} could not parse a type specification output by the compiler.
7a292a7a 8222
c906108c
SS
8223@end table
8224
6d2ebf8b 8225@node Targets
c906108c 8226@chapter Specifying a Debugging Target
7a292a7a 8227
c906108c
SS
8228@cindex debugging target
8229@kindex target
8230
8231A @dfn{target} is the execution environment occupied by your program.
53a5351d
JM
8232
8233Often, @value{GDBN} runs in the same host environment as your program;
8234in that case, the debugging target is specified as a side effect when
8235you use the @code{file} or @code{core} commands. When you need more
c906108c
SS
8236flexibility---for example, running @value{GDBN} on a physically separate
8237host, or controlling a standalone system over a serial port or a
53a5351d
JM
8238realtime system over a TCP/IP connection---you can use the @code{target}
8239command to specify one of the target types configured for @value{GDBN}
8240(@pxref{Target Commands, ,Commands for managing targets}).
c906108c
SS
8241
8242@menu
8243* Active Targets:: Active targets
8244* Target Commands:: Commands for managing targets
c906108c
SS
8245* Byte Order:: Choosing target byte order
8246* Remote:: Remote debugging
96baa820 8247* KOD:: Kernel Object Display
c906108c
SS
8248
8249@end menu
8250
6d2ebf8b 8251@node Active Targets
c906108c 8252@section Active targets
7a292a7a 8253
c906108c
SS
8254@cindex stacking targets
8255@cindex active targets
8256@cindex multiple targets
8257
c906108c 8258There are three classes of targets: processes, core files, and
7a292a7a
SS
8259executable files. @value{GDBN} can work concurrently on up to three
8260active targets, one in each class. This allows you to (for example)
8261start a process and inspect its activity without abandoning your work on
8262a core file.
c906108c
SS
8263
8264For example, if you execute @samp{gdb a.out}, then the executable file
8265@code{a.out} is the only active target. If you designate a core file as
8266well---presumably from a prior run that crashed and coredumped---then
8267@value{GDBN} has two active targets and uses them in tandem, looking
8268first in the corefile target, then in the executable file, to satisfy
8269requests for memory addresses. (Typically, these two classes of target
8270are complementary, since core files contain only a program's
8271read-write memory---variables and so on---plus machine status, while
8272executable files contain only the program text and initialized data.)
c906108c
SS
8273
8274When you type @code{run}, your executable file becomes an active process
7a292a7a
SS
8275target as well. When a process target is active, all @value{GDBN}
8276commands requesting memory addresses refer to that target; addresses in
8277an active core file or executable file target are obscured while the
8278process target is active.
c906108c 8279
7a292a7a
SS
8280Use the @code{core-file} and @code{exec-file} commands to select a new
8281core file or executable target (@pxref{Files, ,Commands to specify
c906108c 8282files}). To specify as a target a process that is already running, use
7a292a7a
SS
8283the @code{attach} command (@pxref{Attach, ,Debugging an already-running
8284process}).
c906108c 8285
6d2ebf8b 8286@node Target Commands
c906108c
SS
8287@section Commands for managing targets
8288
8289@table @code
8290@item target @var{type} @var{parameters}
7a292a7a
SS
8291Connects the @value{GDBN} host environment to a target machine or
8292process. A target is typically a protocol for talking to debugging
8293facilities. You use the argument @var{type} to specify the type or
8294protocol of the target machine.
c906108c
SS
8295
8296Further @var{parameters} are interpreted by the target protocol, but
8297typically include things like device names or host names to connect
8298with, process numbers, and baud rates.
c906108c
SS
8299
8300The @code{target} command does not repeat if you press @key{RET} again
8301after executing the command.
8302
8303@kindex help target
8304@item help target
8305Displays the names of all targets available. To display targets
8306currently selected, use either @code{info target} or @code{info files}
8307(@pxref{Files, ,Commands to specify files}).
8308
8309@item help target @var{name}
8310Describe a particular target, including any parameters necessary to
8311select it.
8312
8313@kindex set gnutarget
8314@item set gnutarget @var{args}
5d161b24 8315@value{GDBN} uses its own library BFD to read your files. @value{GDBN}
c906108c 8316knows whether it is reading an @dfn{executable},
5d161b24
DB
8317a @dfn{core}, or a @dfn{.o} file; however, you can specify the file format
8318with the @code{set gnutarget} command. Unlike most @code{target} commands,
c906108c
SS
8319with @code{gnutarget} the @code{target} refers to a program, not a machine.
8320
d4f3574e 8321@quotation
c906108c
SS
8322@emph{Warning:} To specify a file format with @code{set gnutarget},
8323you must know the actual BFD name.
d4f3574e 8324@end quotation
c906108c 8325
d4f3574e
SS
8326@noindent
8327@xref{Files, , Commands to specify files}.
c906108c 8328
5d161b24 8329@kindex show gnutarget
c906108c
SS
8330@item show gnutarget
8331Use the @code{show gnutarget} command to display what file format
8332@code{gnutarget} is set to read. If you have not set @code{gnutarget},
8333@value{GDBN} will determine the file format for each file automatically,
8334and @code{show gnutarget} displays @samp{The current BDF target is "auto"}.
8335@end table
8336
c906108c
SS
8337Here are some common targets (available, or not, depending on the GDB
8338configuration):
c906108c
SS
8339
8340@table @code
8341@kindex target exec
8342@item target exec @var{program}
8343An executable file. @samp{target exec @var{program}} is the same as
8344@samp{exec-file @var{program}}.
8345
c906108c
SS
8346@kindex target core
8347@item target core @var{filename}
8348A core dump file. @samp{target core @var{filename}} is the same as
8349@samp{core-file @var{filename}}.
c906108c
SS
8350
8351@kindex target remote
8352@item target remote @var{dev}
8353Remote serial target in GDB-specific protocol. The argument @var{dev}
8354specifies what serial device to use for the connection (e.g.
8355@file{/dev/ttya}). @xref{Remote, ,Remote debugging}. @code{target remote}
d4f3574e 8356supports the @code{load} command. This is only useful if you have
c906108c
SS
8357some other way of getting the stub to the target system, and you can put
8358it somewhere in memory where it won't get clobbered by the download.
8359
c906108c
SS
8360@kindex target sim
8361@item target sim
2df3850c 8362Builtin CPU simulator. @value{GDBN} includes simulators for most architectures.
104c1213
JM
8363In general,
8364@example
8365 target sim
8366 load
8367 run
8368@end example
d4f3574e 8369@noindent
104c1213 8370works; however, you cannot assume that a specific memory map, device
d4f3574e 8371drivers, or even basic I/O is available, although some simulators do
104c1213
JM
8372provide these. For info about any processor-specific simulator details,
8373see the appropriate section in @ref{Embedded Processors, ,Embedded
8374Processors}.
8375
c906108c
SS
8376@end table
8377
104c1213 8378Some configurations may include these targets as well:
c906108c
SS
8379
8380@table @code
8381
c906108c
SS
8382@kindex target nrom
8383@item target nrom @var{dev}
8384NetROM ROM emulator. This target only supports downloading.
8385
c906108c
SS
8386@end table
8387
5d161b24 8388Different targets are available on different configurations of @value{GDBN};
c906108c 8389your configuration may have more or fewer targets.
c906108c
SS
8390
8391Many remote targets require you to download the executable's code
8392once you've successfully established a connection.
8393
8394@table @code
8395
8396@kindex load @var{filename}
8397@item load @var{filename}
c906108c
SS
8398Depending on what remote debugging facilities are configured into
8399@value{GDBN}, the @code{load} command may be available. Where it exists, it
8400is meant to make @var{filename} (an executable) available for debugging
8401on the remote system---by downloading, or dynamic linking, for example.
8402@code{load} also records the @var{filename} symbol table in @value{GDBN}, like
8403the @code{add-symbol-file} command.
8404
8405If your @value{GDBN} does not have a @code{load} command, attempting to
8406execute it gets the error message ``@code{You can't do that when your
8407target is @dots{}}''
c906108c
SS
8408
8409The file is loaded at whatever address is specified in the executable.
8410For some object file formats, you can specify the load address when you
8411link the program; for other formats, like a.out, the object file format
8412specifies a fixed address.
8413@c FIXME! This would be a good place for an xref to the GNU linker doc.
8414
c906108c
SS
8415@code{load} does not repeat if you press @key{RET} again after using it.
8416@end table
8417
6d2ebf8b 8418@node Byte Order
c906108c 8419@section Choosing target byte order
7a292a7a 8420
c906108c
SS
8421@cindex choosing target byte order
8422@cindex target byte order
8423@kindex set endian big
8424@kindex set endian little
8425@kindex set endian auto
8426@kindex show endian
8427
8428Some types of processors, such as the MIPS, PowerPC, and Hitachi SH,
8429offer the ability to run either big-endian or little-endian byte
8430orders. Usually the executable or symbol will include a bit to
8431designate the endian-ness, and you will not need to worry about
8432which to use. However, you may still find it useful to adjust
d4f3574e 8433@value{GDBN}'s idea of processor endian-ness manually.
c906108c
SS
8434
8435@table @code
8436@kindex set endian big
8437@item set endian big
8438Instruct @value{GDBN} to assume the target is big-endian.
8439
8440@kindex set endian little
8441@item set endian little
8442Instruct @value{GDBN} to assume the target is little-endian.
8443
8444@kindex set endian auto
8445@item set endian auto
8446Instruct @value{GDBN} to use the byte order associated with the
8447executable.
8448
8449@item show endian
8450Display @value{GDBN}'s current idea of the target byte order.
8451
8452@end table
8453
8454Note that these commands merely adjust interpretation of symbolic
8455data on the host, and that they have absolutely no effect on the
8456target system.
8457
6d2ebf8b 8458@node Remote
c906108c
SS
8459@section Remote debugging
8460@cindex remote debugging
8461
8462If you are trying to debug a program running on a machine that cannot run
5d161b24
DB
8463@value{GDBN} in the usual way, it is often useful to use remote debugging.
8464For example, you might use remote debugging on an operating system kernel,
c906108c
SS
8465or on a small system which does not have a general purpose operating system
8466powerful enough to run a full-featured debugger.
8467
8468Some configurations of @value{GDBN} have special serial or TCP/IP interfaces
8469to make this work with particular debugging targets. In addition,
5d161b24 8470@value{GDBN} comes with a generic serial protocol (specific to @value{GDBN},
c906108c
SS
8471but not specific to any particular target system) which you can use if you
8472write the remote stubs---the code that runs on the remote system to
8473communicate with @value{GDBN}.
8474
8475Other remote targets may be available in your
8476configuration of @value{GDBN}; use @code{help target} to list them.
c906108c 8477
c906108c 8478@menu
c906108c 8479* Remote Serial:: @value{GDBN} remote serial protocol
c906108c
SS
8480@end menu
8481
6d2ebf8b 8482@node Remote Serial
104c1213 8483@subsection The @value{GDBN} remote serial protocol
7a292a7a 8484
104c1213
JM
8485@cindex remote serial debugging, overview
8486To debug a program running on another machine (the debugging
8487@dfn{target} machine), you must first arrange for all the usual
8488prerequisites for the program to run by itself. For example, for a C
8489program, you need:
c906108c 8490
104c1213
JM
8491@enumerate
8492@item
8493A startup routine to set up the C runtime environment; these usually
8494have a name like @file{crt0}. The startup routine may be supplied by
8495your hardware supplier, or you may have to write your own.
96baa820 8496
5d161b24 8497@item
d4f3574e 8498A C subroutine library to support your program's
104c1213 8499subroutine calls, notably managing input and output.
96baa820 8500
104c1213
JM
8501@item
8502A way of getting your program to the other machine---for example, a
8503download program. These are often supplied by the hardware
8504manufacturer, but you may have to write your own from hardware
8505documentation.
8506@end enumerate
96baa820 8507
104c1213
JM
8508The next step is to arrange for your program to use a serial port to
8509communicate with the machine where @value{GDBN} is running (the @dfn{host}
8510machine). In general terms, the scheme looks like this:
96baa820 8511
104c1213
JM
8512@table @emph
8513@item On the host,
8514@value{GDBN} already understands how to use this protocol; when everything
8515else is set up, you can simply use the @samp{target remote} command
8516(@pxref{Targets,,Specifying a Debugging Target}).
8517
8518@item On the target,
8519you must link with your program a few special-purpose subroutines that
8520implement the @value{GDBN} remote serial protocol. The file containing these
8521subroutines is called a @dfn{debugging stub}.
8522
8523On certain remote targets, you can use an auxiliary program
8524@code{gdbserver} instead of linking a stub into your program.
8525@xref{Server,,Using the @code{gdbserver} program}, for details.
8526@end table
96baa820 8527
104c1213
JM
8528The debugging stub is specific to the architecture of the remote
8529machine; for example, use @file{sparc-stub.c} to debug programs on
8530@sc{sparc} boards.
96baa820 8531
104c1213
JM
8532@cindex remote serial stub list
8533These working remote stubs are distributed with @value{GDBN}:
96baa820 8534
104c1213
JM
8535@table @code
8536
8537@item i386-stub.c
8538@kindex i386-stub.c
8539@cindex Intel
8540@cindex i386
8541For Intel 386 and compatible architectures.
8542
8543@item m68k-stub.c
8544@kindex m68k-stub.c
8545@cindex Motorola 680x0
8546@cindex m680x0
8547For Motorola 680x0 architectures.
8548
8549@item sh-stub.c
8550@kindex sh-stub.c
8551@cindex Hitachi
8552@cindex SH
8553For Hitachi SH architectures.
8554
8555@item sparc-stub.c
8556@kindex sparc-stub.c
8557@cindex Sparc
8558For @sc{sparc} architectures.
8559
8560@item sparcl-stub.c
8561@kindex sparcl-stub.c
8562@cindex Fujitsu
8563@cindex SparcLite
8564For Fujitsu @sc{sparclite} architectures.
8565
8566@end table
8567
8568The @file{README} file in the @value{GDBN} distribution may list other
8569recently added stubs.
8570
8571@menu
8572* Stub Contents:: What the stub can do for you
8573* Bootstrapping:: What you must do for the stub
8574* Debug Session:: Putting it all together
8575* Protocol:: Definition of the communication protocol
8576* Server:: Using the `gdbserver' program
8577* NetWare:: Using the `gdbserve.nlm' program
8578@end menu
8579
6d2ebf8b 8580@node Stub Contents
104c1213
JM
8581@subsubsection What the stub can do for you
8582
8583@cindex remote serial stub
8584The debugging stub for your architecture supplies these three
8585subroutines:
8586
8587@table @code
8588@item set_debug_traps
8589@kindex set_debug_traps
8590@cindex remote serial stub, initialization
8591This routine arranges for @code{handle_exception} to run when your
8592program stops. You must call this subroutine explicitly near the
8593beginning of your program.
8594
8595@item handle_exception
8596@kindex handle_exception
8597@cindex remote serial stub, main routine
8598This is the central workhorse, but your program never calls it
8599explicitly---the setup code arranges for @code{handle_exception} to
8600run when a trap is triggered.
8601
8602@code{handle_exception} takes control when your program stops during
8603execution (for example, on a breakpoint), and mediates communications
8604with @value{GDBN} on the host machine. This is where the communications
8605protocol is implemented; @code{handle_exception} acts as the @value{GDBN}
d4f3574e 8606representative on the target machine. It begins by sending summary
104c1213
JM
8607information on the state of your program, then continues to execute,
8608retrieving and transmitting any information @value{GDBN} needs, until you
8609execute a @value{GDBN} command that makes your program resume; at that point,
8610@code{handle_exception} returns control to your own code on the target
5d161b24 8611machine.
104c1213
JM
8612
8613@item breakpoint
8614@cindex @code{breakpoint} subroutine, remote
8615Use this auxiliary subroutine to make your program contain a
8616breakpoint. Depending on the particular situation, this may be the only
8617way for @value{GDBN} to get control. For instance, if your target
8618machine has some sort of interrupt button, you won't need to call this;
8619pressing the interrupt button transfers control to
8620@code{handle_exception}---in effect, to @value{GDBN}. On some machines,
8621simply receiving characters on the serial port may also trigger a trap;
8622again, in that situation, you don't need to call @code{breakpoint} from
8623your own program---simply running @samp{target remote} from the host
5d161b24 8624@value{GDBN} session gets control.
104c1213
JM
8625
8626Call @code{breakpoint} if none of these is true, or if you simply want
8627to make certain your program stops at a predetermined point for the
8628start of your debugging session.
8629@end table
8630
6d2ebf8b 8631@node Bootstrapping
104c1213
JM
8632@subsubsection What you must do for the stub
8633
8634@cindex remote stub, support routines
8635The debugging stubs that come with @value{GDBN} are set up for a particular
8636chip architecture, but they have no information about the rest of your
8637debugging target machine.
8638
8639First of all you need to tell the stub how to communicate with the
8640serial port.
8641
8642@table @code
8643@item int getDebugChar()
8644@kindex getDebugChar
8645Write this subroutine to read a single character from the serial port.
8646It may be identical to @code{getchar} for your target system; a
8647different name is used to allow you to distinguish the two if you wish.
8648
8649@item void putDebugChar(int)
8650@kindex putDebugChar
8651Write this subroutine to write a single character to the serial port.
5d161b24 8652It may be identical to @code{putchar} for your target system; a
104c1213
JM
8653different name is used to allow you to distinguish the two if you wish.
8654@end table
8655
8656@cindex control C, and remote debugging
8657@cindex interrupting remote targets
8658If you want @value{GDBN} to be able to stop your program while it is
8659running, you need to use an interrupt-driven serial driver, and arrange
8660for it to stop when it receives a @code{^C} (@samp{\003}, the control-C
8661character). That is the character which @value{GDBN} uses to tell the
8662remote system to stop.
8663
8664Getting the debugging target to return the proper status to @value{GDBN}
8665probably requires changes to the standard stub; one quick and dirty way
8666is to just execute a breakpoint instruction (the ``dirty'' part is that
8667@value{GDBN} reports a @code{SIGTRAP} instead of a @code{SIGINT}).
8668
8669Other routines you need to supply are:
8670
8671@table @code
8672@item void exceptionHandler (int @var{exception_number}, void *@var{exception_address})
8673@kindex exceptionHandler
8674Write this function to install @var{exception_address} in the exception
8675handling tables. You need to do this because the stub does not have any
8676way of knowing what the exception handling tables on your target system
8677are like (for example, the processor's table might be in @sc{rom},
8678containing entries which point to a table in @sc{ram}).
8679@var{exception_number} is the exception number which should be changed;
8680its meaning is architecture-dependent (for example, different numbers
8681might represent divide by zero, misaligned access, etc). When this
8682exception occurs, control should be transferred directly to
8683@var{exception_address}, and the processor state (stack, registers,
8684and so on) should be just as it is when a processor exception occurs. So if
8685you want to use a jump instruction to reach @var{exception_address}, it
8686should be a simple jump, not a jump to subroutine.
8687
8688For the 386, @var{exception_address} should be installed as an interrupt
8689gate so that interrupts are masked while the handler runs. The gate
8690should be at privilege level 0 (the most privileged level). The
8691@sc{sparc} and 68k stubs are able to mask interrupts themselves without
8692help from @code{exceptionHandler}.
8693
8694@item void flush_i_cache()
8695@kindex flush_i_cache
d4f3574e 8696On @sc{sparc} and @sc{sparclite} only, write this subroutine to flush the
104c1213
JM
8697instruction cache, if any, on your target machine. If there is no
8698instruction cache, this subroutine may be a no-op.
8699
8700On target machines that have instruction caches, @value{GDBN} requires this
8701function to make certain that the state of your program is stable.
8702@end table
8703
8704@noindent
8705You must also make sure this library routine is available:
8706
8707@table @code
8708@item void *memset(void *, int, int)
8709@kindex memset
8710This is the standard library function @code{memset} that sets an area of
8711memory to a known value. If you have one of the free versions of
8712@code{libc.a}, @code{memset} can be found there; otherwise, you must
8713either obtain it from your hardware manufacturer, or write your own.
8714@end table
8715
8716If you do not use the GNU C compiler, you may need other standard
8717library subroutines as well; this varies from one stub to another,
8718but in general the stubs are likely to use any of the common library
d4f3574e 8719subroutines which @code{@value{GCC}} generates as inline code.
104c1213
JM
8720
8721
6d2ebf8b 8722@node Debug Session
104c1213
JM
8723@subsubsection Putting it all together
8724
8725@cindex remote serial debugging summary
8726In summary, when your program is ready to debug, you must follow these
8727steps.
8728
8729@enumerate
8730@item
6d2ebf8b 8731Make sure you have defined the supporting low-level routines
104c1213
JM
8732(@pxref{Bootstrapping,,What you must do for the stub}):
8733@display
8734@code{getDebugChar}, @code{putDebugChar},
8735@code{flush_i_cache}, @code{memset}, @code{exceptionHandler}.
8736@end display
8737
8738@item
8739Insert these lines near the top of your program:
8740
8741@example
8742set_debug_traps();
8743breakpoint();
8744@end example
8745
8746@item
8747For the 680x0 stub only, you need to provide a variable called
8748@code{exceptionHook}. Normally you just use:
8749
8750@example
8751void (*exceptionHook)() = 0;
8752@end example
8753
d4f3574e 8754@noindent
104c1213 8755but if before calling @code{set_debug_traps}, you set it to point to a
d4f3574e 8756function in your program; that function is called when
104c1213
JM
8757@code{@value{GDBN}} continues after stopping on a trap (for example, bus
8758error). The function indicated by @code{exceptionHook} is called with
8759one parameter: an @code{int} which is the exception number.
8760
8761@item
8762Compile and link together: your program, the @value{GDBN} debugging stub for
8763your target architecture, and the supporting subroutines.
8764
8765@item
8766Make sure you have a serial connection between your target machine and
8767the @value{GDBN} host, and identify the serial port on the host.
8768
8769@item
8770@c The "remote" target now provides a `load' command, so we should
8771@c document that. FIXME.
8772Download your program to your target machine (or get it there by
8773whatever means the manufacturer provides), and start it.
8774
8775@item
8776To start remote debugging, run @value{GDBN} on the host machine, and specify
8777as an executable file the program that is running in the remote machine.
8778This tells @value{GDBN} how to find your program's symbols and the contents
8779of its pure text.
8780
d4f3574e 8781@item
104c1213 8782@cindex serial line, @code{target remote}
d4f3574e 8783Establish communication using the @code{target remote} command.
104c1213
JM
8784Its argument specifies how to communicate with the target
8785machine---either via a devicename attached to a direct serial line, or a
8786TCP port (usually to a terminal server which in turn has a serial line
8787to the target). For example, to use a serial line connected to the
8788device named @file{/dev/ttyb}:
8789
8790@example
8791target remote /dev/ttyb
8792@end example
8793
8794@cindex TCP port, @code{target remote}
8795To use a TCP connection, use an argument of the form
8796@code{@var{host}:port}. For example, to connect to port 2828 on a
8797terminal server named @code{manyfarms}:
8798
8799@example
8800target remote manyfarms:2828
8801@end example
8802@end enumerate
8803
8804Now you can use all the usual commands to examine and change data and to
8805step and continue the remote program.
8806
8807To resume the remote program and stop debugging it, use the @code{detach}
8808command.
8809
8810@cindex interrupting remote programs
8811@cindex remote programs, interrupting
8812Whenever @value{GDBN} is waiting for the remote program, if you type the
8813interrupt character (often @key{C-C}), @value{GDBN} attempts to stop the
8814program. This may or may not succeed, depending in part on the hardware
8815and the serial drivers the remote system uses. If you type the
8816interrupt character once again, @value{GDBN} displays this prompt:
8817
8818@example
8819Interrupted while waiting for the program.
8820Give up (and stop debugging it)? (y or n)
8821@end example
8822
8823If you type @kbd{y}, @value{GDBN} abandons the remote debugging session.
8824(If you decide you want to try again later, you can use @samp{target
8825remote} again to connect once more.) If you type @kbd{n}, @value{GDBN}
8826goes back to waiting.
8827
6d2ebf8b 8828@node Protocol
104c1213
JM
8829@subsubsection Communication protocol
8830
8831@cindex debugging stub, example
8832@cindex remote stub, example
8833@cindex stub example, remote debugging
8834The stub files provided with @value{GDBN} implement the target side of the
8835communication protocol, and the @value{GDBN} side is implemented in the
8836@value{GDBN} source file @file{remote.c}. Normally, you can simply allow
8837these subroutines to communicate, and ignore the details. (If you're
8838implementing your own stub file, you can still ignore the details: start
8839with one of the existing stub files. @file{sparc-stub.c} is the best
8840organized, and therefore the easiest to read.)
8841
8842However, there may be occasions when you need to know something about
8843the protocol---for example, if there is only one serial port to your
8844target machine, you might want your program to do something special if
8845it recognizes a packet meant for @value{GDBN}.
8846
8847In the examples below, @samp{<-} and @samp{->} are used to indicate
8848transmitted and received data respectfully.
8849
8850@cindex protocol, @value{GDBN} remote serial
8851@cindex serial protocol, @value{GDBN} remote
8852@cindex remote serial protocol
6cf7e474
AC
8853All @value{GDBN} commands and responses (other than acknowledgments) are
8854sent as a @var{packet}. A @var{packet} is introduced with the character
8855@samp{$}, the actual @var{packet-data}, and the terminating character
8856@samp{#} followed by a two-digit @var{checksum}:
104c1213
JM
8857
8858@example
8859@code{$}@var{packet-data}@code{#}@var{checksum}
8860@end example
8861@noindent
104c1213
JM
8862
8863@cindex checksum, for @value{GDBN} remote
8864@noindent
8865The two-digit @var{checksum} is computed as the modulo 256 sum of all
6cf7e474
AC
8866characters between the leading @samp{$} and the trailing @samp{#} (an
8867eight bit unsigned checksum).
8868
8869Implementors should note that prior to @value{GDBN} 5.0 the protocol
8870specification also included an optional two-digit @var{sequence-id}:
8871
8872@example
8873@code{$}@var{sequence-id}@code{:}@var{packet-data}@code{#}@var{checksum}
8874@end example
104c1213
JM
8875
8876@cindex sequence-id, for @value{GDBN} remote
8877@noindent
6cf7e474
AC
8878That @var{sequence-id} was appended to the acknowledgment. @value{GDBN}
8879has never output @var{sequence-id}s. Stubs that handle packets added
8880since @value{GDBN} 5.0 must not accept @var{sequence-id}.
104c1213 8881
6cf7e474 8882@cindex acknowledgment, for @value{GDBN} remote
104c1213
JM
8883When either the host or the target machine receives a packet, the first
8884response expected is an acknowledgment: either @samp{+} (to indicate
8885the package was received correctly) or @samp{-} (to request
8886retransmission):
8887
8888@example
8889<- @code{$}@var{packet-data}@code{#}@var{checksum}
8890-> @code{+}
8891@end example
8892@noindent
104c1213
JM
8893
8894The host (@value{GDBN}) sends @var{command}s, and the target (the
8895debugging stub incorporated in your program) sends a @var{response}. In
8896the case of step and continue @var{command}s, the response is only sent
8897when the operation has completed (the target has again stopped).
8898
8899@var{packet-data} consists of a sequence of characters with the
6cf7e474
AC
8900exception of @samp{#} and @samp{$} (see @samp{X} packet for additional
8901exceptions).
8902
8903Fields within the packet should be separated using @samp{,} @samp{;} or
8904@samp{:}. Except where otherwise noted all numbers are represented in
8905HEX with leading zeros suppressed.
8906
8907Implementors should note that prior to @value{GDBN} 5.0, the character
8908@samp{:} could not appear as the third character in a packet (as it
8909would potentially conflict with the @var{sequence-id}).
104c1213
JM
8910
8911Response @var{data} can be run-length encoded to save space. A @samp{*}
c3f6f71d 8912means that the next character is an @sc{ascii} encoding giving a repeat count
104c1213
JM
8913which stands for that many repetitions of the character preceding the
8914@samp{*}. The encoding is @code{n+29}, yielding a printable character
d4f3574e
SS
8915where @code{n >=3} (which is where rle starts to win). The printable
8916characters @samp{$}, @samp{#}, @samp{+} and @samp{-} or with a numeric
8917value greater than 126 should not be used.
8918
8919Some remote systems have used a different run-length encoding mechanism
8920loosely refered to as the cisco encoding. Following the @samp{*}
8921character are two hex digits that indicate the size of the packet.
104c1213
JM
8922
8923So:
8924@example
8925"@code{0* }"
8926@end example
8927@noindent
8928means the same as "0000".
8929
8930The error response, returned for some packets includes a two character
8931error number. That number is not well defined.
8932
8933For any @var{command} not supported by the stub, an empty response
8934(@samp{$#00}) should be returned. That way it is possible to extend the
8935protocol. A newer @value{GDBN} can tell if a packet is supported based
d4f3574e 8936on that response.
104c1213 8937
f1251bdd
C
8938A stub is required to support the @samp{g}, @samp{G}, @samp{m}, @samp{M},
8939@samp{c}, and @samp{s} @var{command}s. All other @var{command}s are
8940optional.
8941
104c1213
JM
8942Below is a complete list of all currently defined @var{command}s and
8943their corresponding response @var{data}:
8944
8945@multitable @columnfractions .30 .30 .40
8946@item Packet
8947@tab Request
8948@tab Description
8949
f1251bdd 8950@item extended ops
104c1213
JM
8951@tab @code{!}
8952@tab
d4f3574e 8953Use the extended remote protocol. Sticky---only needs to be set once.
104c1213
JM
8954The extended remote protocol support the @samp{R} packet.
8955@item
8956@tab reply @samp{}
8957@tab
8958Stubs that support the extended remote protocol return @samp{} which,
8959unfortunately, is identical to the response returned by stubs that do not
8960support protocol extensions.
8961
8962@item last signal
8963@tab @code{?}
8964@tab
d4f3574e
SS
8965Indicate the reason the target halted. The reply is the same as for step
8966and continue.
8967@item
8968@tab reply
8969@tab see below
8970
104c1213
JM
8971
8972@item reserved
8973@tab @code{a}
5d161b24 8974@tab Reserved for future use
104c1213 8975
f1251bdd 8976@item set program arguments @strong{(reserved)}
104c1213
JM
8977@tab @code{A}@var{arglen}@code{,}@var{argnum}@code{,}@var{arg}@code{,...}
8978@tab
8979Initialized @samp{argv[]} array passed into program. @var{arglen}
8980specifies the number of bytes in the hex encoded byte stream @var{arg}.
d4f3574e 8981See @file{gdbserver} for more details.
104c1213
JM
8982@item
8983@tab reply @code{OK}
8984@item
8985@tab reply @code{E}@var{NN}
8986
8987@item set baud @strong{(deprecated)}
8988@tab @code{b}@var{baud}
8989@tab
8990Change the serial line speed to @var{baud}. JTC: @emph{When does the
8991transport layer state change? When it's received, or after the ACK is
8992transmitted. In either case, there are problems if the command or the
8993acknowledgment packet is dropped.} Stan: @emph{If people really wanted
8994to add something like this, and get it working for the first time, they
8995ought to modify ser-unix.c to send some kind of out-of-band message to a
8996specially-setup stub and have the switch happen "in between" packets, so
8997that from remote protocol's point of view, nothing actually
8998happened.}
8999
9000@item set breakpoint @strong{(deprecated)}
9001@tab @code{B}@var{addr},@var{mode}
9002@tab
9003Set (@var{mode} is @samp{S}) or clear (@var{mode} is @samp{C}) a
9004breakpoint at @var{addr}. @emph{This has been replaced by the @samp{Z} and
9005@samp{z} packets.}
9006
9007@item continue
9008@tab @code{c}@var{addr}
9009@tab
9010@var{addr} is address to resume. If @var{addr} is omitted, resume at
9011current address.
9012@item
9013@tab reply
9014@tab see below
9015
f1251bdd 9016@item continue with signal
104c1213
JM
9017@tab @code{C}@var{sig}@code{;}@var{addr}
9018@tab
9019Continue with signal @var{sig} (hex signal number). If
9020@code{;}@var{addr} is omitted, resume at same address.
9021@item
9022@tab reply
9023@tab see below
9024
d4f3574e 9025@item toggle debug @emph{(deprecated)}
104c1213
JM
9026@tab @code{d}
9027@tab
d4f3574e 9028toggle debug flag.
104c1213 9029
f1251bdd 9030@item detach
104c1213 9031@tab @code{D}
d4f3574e 9032@tab
2df3850c
JM
9033Detach @value{GDBN} from the remote system. Sent to the remote target before
9034@value{GDBN} disconnects.
d4f3574e
SS
9035@item
9036@tab reply @emph{no response}
9037@tab
2df3850c 9038@value{GDBN} does not check for any response after sending this packet
104c1213
JM
9039
9040@item reserved
9041@tab @code{e}
5d161b24 9042@tab Reserved for future use
104c1213
JM
9043
9044@item reserved
9045@tab @code{E}
5d161b24 9046@tab Reserved for future use
104c1213
JM
9047
9048@item reserved
9049@tab @code{f}
5d161b24 9050@tab Reserved for future use
104c1213
JM
9051
9052@item reserved
9053@tab @code{F}
5d161b24 9054@tab Reserved for future use
104c1213
JM
9055
9056@item read registers
9057@tab @code{g}
9058@tab Read general registers.
9059@item
9060@tab reply @var{XX...}
9061@tab
9062Each byte of register data is described by two hex digits. The bytes
9063with the register are transmitted in target byte order. The size of
d4f3574e 9064each register and their position within the @samp{g} @var{packet} are
2df3850c 9065determined by the @value{GDBN} internal macros @var{REGISTER_RAW_SIZE} and
d4f3574e
SS
9066@var{REGISTER_NAME} macros. The specification of several standard
9067@code{g} packets is specified below.
104c1213
JM
9068@item
9069@tab @code{E}@var{NN}
9070@tab for an error.
9071
9072@item write regs
9073@tab @code{G}@var{XX...}
9074@tab
9075See @samp{g} for a description of the @var{XX...} data.
9076@item
9077@tab reply @code{OK}
9078@tab for success
9079@item
9080@tab reply @code{E}@var{NN}
9081@tab for an error
9082
9083@item reserved
9084@tab @code{h}
5d161b24 9085@tab Reserved for future use
104c1213 9086
f1251bdd 9087@item set thread
104c1213
JM
9088@tab @code{H}@var{c}@var{t...}
9089@tab
d4f3574e
SS
9090Set thread for subsequent operations (@samp{m}, @samp{M}, @samp{g},
9091@samp{G}, et.al.). @var{c} = @samp{c} for thread used in step and
9092continue; @var{t...} can be -1 for all threads. @var{c} = @samp{g} for
9093thread used in other operations. If zero, pick a thread, any thread.
104c1213
JM
9094@item
9095@tab reply @code{OK}
9096@tab for success
9097@item
9098@tab reply @code{E}@var{NN}
9099@tab for an error
9100
d4f3574e
SS
9101@c FIXME: JTC:
9102@c 'H': How restrictive (or permissive) is the thread model. If a
5d161b24 9103@c thread is selected and stopped, are other threads allowed
d4f3574e
SS
9104@c to continue to execute? As I mentioned above, I think the
9105@c semantics of each command when a thread is selected must be
9106@c described. For example:
9107@c
9108@c 'g': If the stub supports threads and a specific thread is
9109@c selected, returns the register block from that thread;
9110@c otherwise returns current registers.
9111@c
9112@c 'G' If the stub supports threads and a specific thread is
9113@c selected, sets the registers of the register block of
9114@c that thread; otherwise sets current registers.
9115
f1251bdd 9116@item cycle step @strong{(draft)}
104c1213
JM
9117@tab @code{i}@var{addr}@code{,}@var{nnn}
9118@tab
9119Step the remote target by a single clock cycle. If @code{,}@var{nnn} is
9120present, cycle step @var{nnn} cycles. If @var{addr} is present, cycle
9121step starting at that address.
9122
f1251bdd 9123@item signal then cycle step @strong{(reserved)}
104c1213
JM
9124@tab @code{I}
9125@tab
9126See @samp{i} and @samp{S} for likely syntax and semantics.
9127
9128@item reserved
9129@tab @code{j}
9130@tab Reserved for future use
9131
9132@item reserved
9133@tab @code{J}
5d161b24 9134@tab Reserved for future use
104c1213 9135
f1251bdd 9136@item kill request
104c1213
JM
9137@tab @code{k}
9138@tab
d4f3574e
SS
9139FIXME: @emph{There is no description of how operate when a specific
9140thread context has been selected (ie. does 'k' kill only that thread?)}.
104c1213
JM
9141
9142@item reserved
9143@tab @code{l}
5d161b24 9144@tab Reserved for future use
104c1213
JM
9145
9146@item reserved
9147@tab @code{L}
5d161b24 9148@tab Reserved for future use
104c1213
JM
9149
9150@item read memory
9151@tab @code{m}@var{addr}@code{,}@var{length}
9152@tab
9153Read @var{length} bytes of memory starting at address @var{addr}.
2df3850c 9154Neither @value{GDBN} nor the stub assume that sized memory transfers are assumed
d4f3574e
SS
9155using word alligned accesses. FIXME: @emph{A word aligned memory
9156transfer mechanism is needed.}
104c1213
JM
9157@item
9158@tab reply @var{XX...}
9159@tab
d4f3574e 9160@var{XX...} is mem contents. Can be fewer bytes than requested if able
2df3850c 9161to read only part of the data. Neither @value{GDBN} nor the stub assume that
d4f3574e
SS
9162sized memory transfers are assumed using word alligned accesses. FIXME:
9163@emph{A word aligned memory transfer mechanism is needed.}
104c1213
JM
9164@item
9165@tab reply @code{E}@var{NN}
9166@tab @var{NN} is errno
9167
9168@item write mem
9169@tab @code{M}@var{addr},@var{length}@code{:}@var{XX...}
9170@tab
9171Write @var{length} bytes of memory starting at address @var{addr}.
9172@var{XX...} is the data.
9173@item
9174@tab reply @code{OK}
9175@tab for success
9176@item
9177@tab reply @code{E}@var{NN}
9178@tab
9179for an error (this includes the case where only part of the data was
9180written).
9181
9182@item reserved
9183@tab @code{n}
5d161b24 9184@tab Reserved for future use
104c1213
JM
9185
9186@item reserved
9187@tab @code{N}
5d161b24 9188@tab Reserved for future use
104c1213
JM
9189
9190@item reserved
9191@tab @code{o}
5d161b24 9192@tab Reserved for future use
104c1213
JM
9193
9194@item reserved
9195@tab @code{O}
5d161b24 9196@tab Reserved for future use
104c1213
JM
9197
9198@item read reg @strong{(reserved)}
9199@tab @code{p}@var{n...}
9200@tab
9201See write register.
9202@item
9203@tab return @var{r....}
9204@tab The hex encoded value of the register in target byte order.
9205
f1251bdd 9206@item write reg
104c1213
JM
9207@tab @code{P}@var{n...}@code{=}@var{r...}
9208@tab
9209Write register @var{n...} with value @var{r...}, which contains two hex
9210digits for each byte in the register (target byte order).
9211@item
9212@tab reply @code{OK}
9213@tab for success
9214@item
9215@tab reply @code{E}@var{NN}
9216@tab for an error
9217
f1251bdd 9218@item general query
104c1213
JM
9219@tab @code{q}@var{query}
9220@tab
d4f3574e 9221Request info about @var{query}. In general @value{GDBN} @var{query}'s
104c1213 9222have a leading upper case letter. Custom vendor queries should use a
d4f3574e
SS
9223company prefix (in lower case) ex: @samp{qfsf.var}. @var{query} may
9224optionally be followed by a @samp{,} or @samp{;} separated list. Stubs
9225must ensure that they match the full @var{query} name.
104c1213
JM
9226@item
9227@tab reply @code{XX...}
d4f3574e 9228@tab Hex encoded data from query. The reply can not be empty.
104c1213
JM
9229@item
9230@tab reply @code{E}@var{NN}
9231@tab error reply
9232@item
9233@tab reply @samp{}
9234@tab Indicating an unrecognized @var{query}.
9235
f1251bdd 9236@item general set
104c1213
JM
9237@tab @code{Q}@var{var}@code{=}@var{val}
9238@tab
9239Set value of @var{var} to @var{val}. See @samp{q} for a discussing of
9240naming conventions.
9241
d4f3574e
SS
9242@item reset @emph{(deprecated)}
9243@tab @code{r}
9244@tab
9245Reset the entire system.
104c1213 9246
f1251bdd 9247@item remote restart
104c1213
JM
9248@tab @code{R}@var{XX}
9249@tab
d4f3574e
SS
9250Restart the remote server. @var{XX} while needed has no clear
9251definition. FIXME: @emph{An example interaction explaining how this
9252packet is used in extended-remote mode is needed}.
104c1213 9253
f1251bdd 9254@item step
104c1213
JM
9255@tab @code{s}@var{addr}
9256@tab
9257@var{addr} is address to resume. If @var{addr} is omitted, resume at
9258same address.
9259@item
9260@tab reply
9261@tab see below
9262
f1251bdd 9263@item step with signal
104c1213
JM
9264@tab @code{S}@var{sig}@code{;}@var{addr}
9265@tab
9266Like @samp{C} but step not continue.
9267@item
9268@tab reply
9269@tab see below
9270
f1251bdd 9271@item search
104c1213
JM
9272@tab @code{t}@var{addr}@code{:}@var{PP}@code{,}@var{MM}
9273@tab
9274Search backwards starting at address @var{addr} for a match with pattern
9275@var{PP} and mask @var{MM}. @var{PP} and @var{MM} are 4
d4f3574e 9276bytes. @var{addr} must be at least 3 digits.
104c1213 9277
f1251bdd 9278@item thread alive
104c1213
JM
9279@tab @code{T}@var{XX}
9280@tab Find out if the thread XX is alive.
9281@item
9282@tab reply @code{OK}
9283@tab thread is still alive
9284@item
9285@tab reply @code{E}@var{NN}
9286@tab thread is dead
5d161b24 9287
104c1213
JM
9288@item reserved
9289@tab @code{u}
5d161b24 9290@tab Reserved for future use
104c1213
JM
9291
9292@item reserved
9293@tab @code{U}
5d161b24 9294@tab Reserved for future use
104c1213
JM
9295
9296@item reserved
9297@tab @code{v}
5d161b24 9298@tab Reserved for future use
104c1213
JM
9299
9300@item reserved
9301@tab @code{V}
5d161b24 9302@tab Reserved for future use
104c1213
JM
9303
9304@item reserved
9305@tab @code{w}
5d161b24 9306@tab Reserved for future use
104c1213
JM
9307
9308@item reserved
9309@tab @code{W}
5d161b24 9310@tab Reserved for future use
104c1213
JM
9311
9312@item reserved
9313@tab @code{x}
5d161b24 9314@tab Reserved for future use
104c1213 9315
f1251bdd 9316@item write mem (binary)
104c1213
JM
9317@tab @code{X}@var{addr}@code{,}@var{length}@var{:}@var{XX...}
9318@tab
9319@var{addr} is address, @var{length} is number of bytes, @var{XX...} is
d4f3574e
SS
9320binary data. The characters @code{$}, @code{#}, and @code{0x7d} are
9321escaped using @code{0x7d}.
104c1213
JM
9322@item
9323@tab reply @code{OK}
9324@tab for success
9325@item
9326@tab reply @code{E}@var{NN}
9327@tab for an error
9328
9329@item reserved
9330@tab @code{y}
5d161b24 9331@tab Reserved for future use
104c1213
JM
9332
9333@item reserved
9334@tab @code{Y}
5d161b24 9335@tab Reserved for future use
104c1213 9336
f1251bdd 9337@item remove break or watchpoint @strong{(draft)}
104c1213
JM
9338@tab @code{z}@var{t}@code{,}@var{addr}@code{,}@var{length}
9339@tab
9340See @samp{Z}.
9341
f1251bdd 9342@item insert break or watchpoint @strong{(draft)}
104c1213
JM
9343@tab @code{Z}@var{t}@code{,}@var{addr}@code{,}@var{length}
9344@tab
9345@var{t} is type: @samp{0} - software breakpoint, @samp{1} - hardware
9346breakpoint, @samp{2} - write watchpoint, @samp{3} - read watchpoint,
9347@samp{4} - access watchpoint; @var{addr} is address; @var{length} is in
9348bytes. For a software breakpoint, @var{length} specifies the size of
9349the instruction to be patched. For hardware breakpoints and watchpoints
d4f3574e
SS
9350@var{length} specifies the memory region to be monitored. To avoid
9351potential problems with duplicate packets, the operations should be
6d2ebf8b 9352implemented in an idempotent way.
104c1213
JM
9353@item
9354@tab reply @code{E}@var{NN}
9355@tab for an error
9356@item
9357@tab reply @code{OK}
9358@tab for success
9359@item
9360@tab @samp{}
9361@tab If not supported.
9362
9363@item reserved
9364@tab <other>
5d161b24 9365@tab Reserved for future use
104c1213
JM
9366
9367@end multitable
9368
d4f3574e
SS
9369The @samp{C}, @samp{c}, @samp{S}, @samp{s} and @samp{?} packets can
9370receive any of the below as a reply. In the case of the @samp{C},
9371@samp{c}, @samp{S} and @samp{s} packets, that reply is only returned
9372when the target halts. In the below the exact meaning of @samp{signal
9373number} is poorly defined. In general one of the UNIX signal numbering
9374conventions is used.
104c1213
JM
9375
9376@multitable @columnfractions .4 .6
9377
9378@item @code{S}@var{AA}
9379@tab @var{AA} is the signal number
9380
9381@item @code{T}@var{AA}@var{n...}@code{:}@var{r...}@code{;}@var{n...}@code{:}@var{r...}@code{;}@var{n...}@code{:}@var{r...}@code{;}
9382@tab
9383@var{AA} = two hex digit signal number; @var{n...} = register number
9384(hex), @var{r...} = target byte ordered register contents, size defined
9385by @code{REGISTER_RAW_SIZE}; @var{n...} = @samp{thread}, @var{r...} =
9386thread process ID, this is a hex integer; @var{n...} = other string not
d4f3574e 9387starting with valid hex digit. @value{GDBN} should ignore this
104c1213
JM
9388@var{n...}, @var{r...} pair and go on to the next. This way we can
9389extend the protocol.
9390
9391@item @code{W}@var{AA}
9392@tab
9393The process exited, and @var{AA} is the exit status. This is only
9394applicable for certains sorts of targets.
9395
9396@item @code{X}@var{AA}
9397@tab
9398The process terminated with signal @var{AA}.
9399
6d2ebf8b 9400@item @code{N}@var{AA}@code{;}@var{t...}@code{;}@var{d...}@code{;}@var{b...} @strong{(obsolete)}
104c1213 9401@tab
6d2ebf8b
SS
9402@var{AA} = signal number; @var{t...} = address of symbol "_start";
9403@var{d...} = base of data section; @var{b...} = base of bss section.
9404@emph{Note: only used by Cisco Systems targets. The difference between
9405this reply and the "qOffsets" query is that the 'N' packet may arrive
9406spontaneously whereas the 'qOffsets' is a query initiated by the host
9407debugger.}
104c1213
JM
9408
9409@item @code{O}@var{XX...}
9410@tab
c3f6f71d 9411@var{XX...} is hex encoding of @sc{ascii} data. This can happen at any time
104c1213
JM
9412while the program is running and the debugger should continue to wait
9413for 'W', 'T', etc.
9414
9415@end multitable
9416
d4f3574e
SS
9417The following set and query packets have already been defined.
9418
9419@multitable @columnfractions .2 .2 .6
9420
9421@item current thread
9422@tab @code{q}@code{C}
9423@tab Return the current thread id.
9424@item
9425@tab reply @code{QC}@var{pid}
9426@tab
9427Where @var{pid} is a HEX encoded 16 bit process id.
9428@item
9429@tab reply *
9430@tab Any other reply implies the old pid.
9431
bba2971c
MS
9432@item all thread ids
9433@tab @code{q}@code{fThreadInfo}
9434@item
9435@tab @code{q}@code{sThreadInfo}
d4f3574e 9436@tab
bba2971c
MS
9437Obtain a list of active thread ids from the target (OS). Since there
9438may be too many active threads to fit into one reply packet, this query
9439works iteratively: it may require more than one query/reply sequence to
9440obtain the entire list of threads. The first query of the sequence will
5d161b24 9441be the @code{qf}@code{ThreadInfo} query; subsequent queries in the
bba2971c 9442sequence will be the @code{qs}@code{ThreadInfo} query.
d4f3574e 9443@item
bba2971c
MS
9444@tab
9445@tab NOTE: replaces the @code{qL} query (see below).
d4f3574e 9446@item
5d161b24 9447@tab reply @code{m}@var{<id>}
bba2971c
MS
9448@tab A single thread id
9449@item
00e4a2e4 9450@tab reply @code{m}@var{<id>},@var{<id>...}
bba2971c
MS
9451@tab a comma-separated list of thread ids
9452@item
9453@tab reply @code{l}
9454@tab (lower case 'el') denotes end of list.
9455@item
9456@tab
9457@tab
9458In response to each query, the target will reply with a list of one
9459or more thread ids, in big-endian hex, separated by commas. GDB will
9460respond to each reply with a request for more thread ids (using the
9461@code{qs} form of the query), until the target responds with @code{l}
9462(lower-case el, for @code{'last'}).
9463
9464@item extra thread info
480ff1fb 9465@tab @code{q}@code{ThreadExtraInfo}@code{,}@var{id}
bba2971c
MS
9466@tab
9467@item
9468@tab
9469@tab
9470Where @var{<id>} is a thread-id in big-endian hex.
9471Obtain a printable string description of a thread's attributes from
9472the target OS. This string may contain anything that the target OS
9473thinks is interesting for @value{GDBN} to tell the user about the thread.
9474The string is displayed in @value{GDBN}'s @samp{info threads} display.
5d161b24 9475Some examples of possible thread extra info strings are "Runnable", or
bba2971c
MS
9476"Blocked on Mutex".
9477@item
9478@tab reply @var{XX...}
9479@tab
9480Where @var{XX...} is a hex encoding of @sc{ascii} data, comprising the
9481printable string containing the extra information about the thread's
9482attributes.
d4f3574e
SS
9483
9484@item query @var{LIST} or @var{threadLIST} @strong{(deprecated)}
9485@tab @code{q}@code{L}@var{startflag}@var{threadcount}@var{nextthread}
9486@tab
2b628194
MS
9487@item
9488@tab
9489@tab
d4f3574e
SS
9490Obtain thread information from RTOS. Where: @var{startflag} (one hex
9491digit) is one to indicate the first query and zero to indicate a
9492subsequent query; @var{threadcount} (two hex digits) is the maximum
9493number of threads the response packet can contain; and @var{nextthread}
9494(eight hex digits), for subsequent queries (@var{startflag} is zero), is
9495returned in the response as @var{argthread}.
9496@item
bba2971c
MS
9497@tab
9498@tab NOTE: this query is replaced by the @code{q}@code{fThreadInfo}
9499query (see above).
9500@item
d4f3574e
SS
9501@tab reply @code{q}@code{M}@var{count}@var{done}@var{argthread}@var{thread...}
9502@tab
2b628194
MS
9503@item
9504@tab
9505@tab
d4f3574e
SS
9506Where: @var{count} (two hex digits) is the number of threads being
9507returned; @var{done} (one hex digit) is zero to indicate more threads
9508and one indicates no further threads; @var{argthreadid} (eight hex
9509digits) is @var{nextthread} from the request packet; @var{thread...} is
9510a sequence of thread IDs from the target. @var{threadid} (eight hex
9511digits). See @code{remote.c:parse_threadlist_response()}.
9512
bba2971c
MS
9513@item compute CRC of memory block
9514@tab @code{q}@code{CRC:}@var{addr}@code{,}@var{length}
9515@tab
9516@item
9517@tab reply @code{E}@var{NN}
9518@tab An error (such as memory fault)
9519@item
9520@tab reply @code{C}@var{CRC32}
9521@tab A 32 bit cyclic redundancy check of the specified memory region.
9522
d4f3574e
SS
9523@item query sect offs
9524@tab @code{q}@code{Offsets}
917317f4
JM
9525@tab
9526Get section offsets that the target used when re-locating the downloaded
9527image. @emph{Note: while a @code{Bss} offset is included in the
9528response, @value{GDBN} ignores this and instead applies the @code{Data}
9529offset to the @code{Bss} section.}
d4f3574e
SS
9530@item
9531@tab reply @code{Text=}@var{xxx}@code{;Data=}@var{yyy}@code{;Bss=}@var{zzz}
9532
9533@item thread info request
9534@tab @code{q}@code{P}@var{mode}@var{threadid}
9535@tab
9536Returns information on @var{threadid}. Where: @var{mode} is a hex
9537encoded 32 bit mode; @var{threadid} is a hex encoded 64 bit thread ID.
9538@item
9539@tab reply *
9540@tab
9541See @code{remote.c:remote_unpack_thread_info_response()}.
9542
9543@item remote command
9544@tab @code{q}@code{Rcmd,}@var{COMMAND}
9545@tab
9546@var{COMMAND} (hex encoded) is passed to the local interpreter for
9547execution. Invalid commands should be reported using the output string.
9548Before the final result packet, the target may also respond with a
9549number of intermediate @code{O}@var{OUTPUT} console output
9550packets. @emph{Implementors should note that providing access to a
9551stubs's interpreter may have security implications}.
9552@item
9553@tab reply @code{OK}
9554@tab
9555A command response with no output.
9556@item
9557@tab reply @var{OUTPUT}
9558@tab
9559A command response with the hex encoded output string @var{OUTPUT}.
9560@item
9561@tab reply @code{E}@var{NN}
9562@tab
9563Indicate a badly formed request.
9564
9565@item
9566@tab reply @samp{}
9567@tab
9568When @samp{q}@samp{Rcmd} is not recognized.
9569
9570@end multitable
9571
9572The following @samp{g}/@samp{G} packets have previously been defined.
9573In the below, some thirty-two bit registers are transferred as sixty-four
9574bits. Those registers should be zero/sign extended (which?) to fill the
9575space allocated. Register bytes are transfered in target byte order.
9576The two nibbles within a register byte are transfered most-significant -
9577least-significant.
9578
9579@multitable @columnfractions .5 .5
9580
9581@item MIPS32
9582@tab
9583All registers are transfered as thirty-two bit quantities in the order:
958432 general-purpose; sr; lo; hi; bad; cause; pc; 32 floating-point
9585registers; fsr; fir; fp.
9586
9587@item MIPS64
9588@tab
9589All registers are transfered as sixty-four bit quantities (including
9590thirty-two bit registers such as @code{sr}). The ordering is the same
9591as @code{MIPS32}.
9592
9593@end multitable
9594
104c1213
JM
9595Example sequence of a target being re-started. Notice how the restart
9596does not get any direct output:
9597
9598@example
9599<- @code{R00}
9600-> @code{+}
9601@emph{target restarts}
9602<- @code{?}
9603-> @code{+}
9604-> @code{T001:1234123412341234}
9605<- @code{+}
9606@end example
9607
9608Example sequence of a target being stepped by a single instruction:
9609
9610@example
9611<- @code{G1445...}
9612-> @code{+}
9613<- @code{s}
9614-> @code{+}
9615@emph{time passes}
9616-> @code{T001:1234123412341234}
9617<- @code{+}
9618<- @code{g}
9619-> @code{+}
9620-> @code{1455...}
9621<- @code{+}
9622@end example
9623
6d2ebf8b 9624@node Server
104c1213
JM
9625@subsubsection Using the @code{gdbserver} program
9626
9627@kindex gdbserver
9628@cindex remote connection without stubs
9629@code{gdbserver} is a control program for Unix-like systems, which
9630allows you to connect your program with a remote @value{GDBN} via
9631@code{target remote}---but without linking in the usual debugging stub.
9632
9633@code{gdbserver} is not a complete replacement for the debugging stubs,
9634because it requires essentially the same operating-system facilities
9635that @value{GDBN} itself does. In fact, a system that can run
9636@code{gdbserver} to connect to a remote @value{GDBN} could also run
9637@value{GDBN} locally! @code{gdbserver} is sometimes useful nevertheless,
9638because it is a much smaller program than @value{GDBN} itself. It is
9639also easier to port than all of @value{GDBN}, so you may be able to get
9640started more quickly on a new system by using @code{gdbserver}.
9641Finally, if you develop code for real-time systems, you may find that
9642the tradeoffs involved in real-time operation make it more convenient to
9643do as much development work as possible on another system, for example
9644by cross-compiling. You can use @code{gdbserver} to make a similar
9645choice for debugging.
9646
9647@value{GDBN} and @code{gdbserver} communicate via either a serial line
9648or a TCP connection, using the standard @value{GDBN} remote serial
9649protocol.
9650
9651@table @emph
9652@item On the target machine,
9653you need to have a copy of the program you want to debug.
9654@code{gdbserver} does not need your program's symbol table, so you can
9655strip the program if necessary to save space. @value{GDBN} on the host
9656system does all the symbol handling.
9657
9658To use the server, you must tell it how to communicate with @value{GDBN};
9659the name of your program; and the arguments for your program. The
9660syntax is:
9661
9662@smallexample
9663target> gdbserver @var{comm} @var{program} [ @var{args} @dots{} ]
9664@end smallexample
9665
9666@var{comm} is either a device name (to use a serial line) or a TCP
9667hostname and portnumber. For example, to debug Emacs with the argument
9668@samp{foo.txt} and communicate with @value{GDBN} over the serial port
9669@file{/dev/com1}:
9670
9671@smallexample
9672target> gdbserver /dev/com1 emacs foo.txt
9673@end smallexample
9674
9675@code{gdbserver} waits passively for the host @value{GDBN} to communicate
9676with it.
9677
9678To use a TCP connection instead of a serial line:
9679
9680@smallexample
9681target> gdbserver host:2345 emacs foo.txt
9682@end smallexample
9683
9684The only difference from the previous example is the first argument,
9685specifying that you are communicating with the host @value{GDBN} via
9686TCP. The @samp{host:2345} argument means that @code{gdbserver} is to
9687expect a TCP connection from machine @samp{host} to local TCP port 2345.
9688(Currently, the @samp{host} part is ignored.) You can choose any number
9689you want for the port number as long as it does not conflict with any
9690TCP ports already in use on the target system (for example, @code{23} is
9691reserved for @code{telnet}).@footnote{If you choose a port number that
9692conflicts with another service, @code{gdbserver} prints an error message
d4f3574e 9693and exits.} You must use the same port number with the host @value{GDBN}
104c1213
JM
9694@code{target remote} command.
9695
9696@item On the @value{GDBN} host machine,
9697you need an unstripped copy of your program, since @value{GDBN} needs
9698symbols and debugging information. Start up @value{GDBN} as usual,
9699using the name of the local copy of your program as the first argument.
9700(You may also need the @w{@samp{--baud}} option if the serial line is
d4f3574e 9701running at anything other than 9600@dmn{bps}.) After that, use @code{target
104c1213
JM
9702remote} to establish communications with @code{gdbserver}. Its argument
9703is either a device name (usually a serial device, like
9704@file{/dev/ttyb}), or a TCP port descriptor in the form
9705@code{@var{host}:@var{PORT}}. For example:
9706
9707@smallexample
9708(@value{GDBP}) target remote /dev/ttyb
9709@end smallexample
9710
9711@noindent
9712communicates with the server via serial line @file{/dev/ttyb}, and
9713
9714@smallexample
9715(@value{GDBP}) target remote the-target:2345
9716@end smallexample
9717
9718@noindent
9719communicates via a TCP connection to port 2345 on host @w{@file{the-target}}.
9720For TCP connections, you must start up @code{gdbserver} prior to using
9721the @code{target remote} command. Otherwise you may get an error whose
9722text depends on the host system, but which usually looks something like
9723@samp{Connection refused}.
9724@end table
9725
6d2ebf8b 9726@node NetWare
104c1213
JM
9727@subsubsection Using the @code{gdbserve.nlm} program
9728
9729@kindex gdbserve.nlm
9730@code{gdbserve.nlm} is a control program for NetWare systems, which
9731allows you to connect your program with a remote @value{GDBN} via
9732@code{target remote}.
9733
9734@value{GDBN} and @code{gdbserve.nlm} communicate via a serial line,
9735using the standard @value{GDBN} remote serial protocol.
9736
9737@table @emph
9738@item On the target machine,
9739you need to have a copy of the program you want to debug.
9740@code{gdbserve.nlm} does not need your program's symbol table, so you
9741can strip the program if necessary to save space. @value{GDBN} on the
9742host system does all the symbol handling.
9743
9744To use the server, you must tell it how to communicate with
9745@value{GDBN}; the name of your program; and the arguments for your
9746program. The syntax is:
9747
5d161b24 9748@smallexample
104c1213
JM
9749load gdbserve [ BOARD=@var{board} ] [ PORT=@var{port} ]
9750 [ BAUD=@var{baud} ] @var{program} [ @var{args} @dots{} ]
9751@end smallexample
9752
9753@var{board} and @var{port} specify the serial line; @var{baud} specifies
9754the baud rate used by the connection. @var{port} and @var{node} default
d4f3574e 9755to 0, @var{baud} defaults to 9600@dmn{bps}.
104c1213
JM
9756
9757For example, to debug Emacs with the argument @samp{foo.txt}and
5d161b24 9758communicate with @value{GDBN} over serial port number 2 or board 1
d4f3574e 9759using a 19200@dmn{bps} connection:
104c1213
JM
9760
9761@smallexample
9762load gdbserve BOARD=1 PORT=2 BAUD=19200 emacs foo.txt
9763@end smallexample
9764
9765@item On the @value{GDBN} host machine,
9766you need an unstripped copy of your program, since @value{GDBN} needs
9767symbols and debugging information. Start up @value{GDBN} as usual,
9768using the name of the local copy of your program as the first argument.
9769(You may also need the @w{@samp{--baud}} option if the serial line is
d4f3574e 9770running at anything other than 9600@dmn{bps}. After that, use @code{target
104c1213
JM
9771remote} to establish communications with @code{gdbserve.nlm}. Its
9772argument is a device name (usually a serial device, like
9773@file{/dev/ttyb}). For example:
9774
9775@smallexample
9776(@value{GDBP}) target remote /dev/ttyb
9777@end smallexample
9778
9779@noindent
9780communications with the server via serial line @file{/dev/ttyb}.
9781@end table
9782
6d2ebf8b 9783@node KOD
104c1213
JM
9784@section Kernel Object Display
9785
9786@cindex kernel object display
9787@cindex kernel object
9788@cindex KOD
9789
9790Some targets support kernel object display. Using this facility,
9791@value{GDBN} communicates specially with the underlying operating system
9792and can display information about operating system-level objects such as
9793mutexes and other synchronization objects. Exactly which objects can be
9794displayed is determined on a per-OS basis.
9795
9796Use the @code{set os} command to set the operating system. This tells
9797@value{GDBN} which kernel object display module to initialize:
9798
9799@example
2df3850c 9800(@value{GDBP}) set os cisco
104c1213
JM
9801@end example
9802
9803If @code{set os} succeeds, @value{GDBN} will display some information
9804about the operating system, and will create a new @code{info} command
9805which can be used to query the target. The @code{info} command is named
9806after the operating system:
9807
9808@example
2df3850c 9809(@value{GDBP}) info cisco
104c1213
JM
9810List of Cisco Kernel Objects
9811Object Description
9812any Any and all objects
9813@end example
9814
9815Further subcommands can be used to query about particular objects known
9816by the kernel.
9817
9818There is currently no way to determine whether a given operating system
96baa820
JM
9819is supported other than to try it.
9820
9821
6d2ebf8b 9822@node Configurations
104c1213
JM
9823@chapter Configuration-Specific Information
9824
9825While nearly all @value{GDBN} commands are available for all native and
9826cross versions of the debugger, there are some exceptions. This chapter
9827describes things that are only available in certain configurations.
9828
9829There are three major categories of configurations: native
9830configurations, where the host and target are the same, embedded
9831operating system configurations, which are usually the same for several
9832different processor architectures, and bare embedded processors, which
9833are quite different from each other.
9834
9835@menu
9836* Native::
9837* Embedded OS::
9838* Embedded Processors::
9839* Architectures::
9840@end menu
9841
6d2ebf8b 9842@node Native
104c1213
JM
9843@section Native
9844
9845This section describes details specific to particular native
9846configurations.
9847
9848@menu
9849* HP-UX:: HP-UX
9850* SVR4 Process Information:: SVR4 process information
9851@end menu
9852
6d2ebf8b 9853@node HP-UX
104c1213
JM
9854@subsection HP-UX
9855
9856On HP-UX systems, if you refer to a function or variable name that
9857begins with a dollar sign, @value{GDBN} searches for a user or system
9858name first, before it searches for a convenience variable.
9859
6d2ebf8b 9860@node SVR4 Process Information
104c1213
JM
9861@subsection SVR4 process information
9862
9863@kindex /proc
9864@cindex process image
9865
9866Many versions of SVR4 provide a facility called @samp{/proc} that can be
9867used to examine the image of a running process using file-system
9868subroutines. If @value{GDBN} is configured for an operating system with
9869this facility, the command @code{info proc} is available to report on
9870several kinds of information about the process running your program.
9871@code{info proc} works only on SVR4 systems that include the
9872@code{procfs} code. This includes OSF/1 (Digital Unix), Solaris, Irix,
9873and Unixware, but not HP-UX or Linux, for example.
9874
9875@table @code
9876@kindex info proc
9877@item info proc
9878Summarize available information about the process.
9879
9880@kindex info proc mappings
9881@item info proc mappings
9882Report on the address ranges accessible in the program, with information
9883on whether your program may read, write, or execute each range.
9884
9885@kindex info proc times
9886@item info proc times
9887Starting time, user CPU time, and system CPU time for your program and
9888its children.
9889
9890@kindex info proc id
9891@item info proc id
9892Report on the process IDs related to your program: its own process ID,
9893the ID of its parent, the process group ID, and the session ID.
9894
9895@kindex info proc status
9896@item info proc status
9897General information on the state of the process. If the process is
9898stopped, this report includes the reason for stopping, and any signal
9899received.
9900
9901@item info proc all
9902Show all the above information about the process.
9903@end table
9904
6d2ebf8b 9905@node Embedded OS
104c1213
JM
9906@section Embedded Operating Systems
9907
9908This section describes configurations involving the debugging of
9909embedded operating systems that are available for several different
9910architectures.
9911
9912@menu
9913* VxWorks:: Using @value{GDBN} with VxWorks
9914@end menu
9915
9916@value{GDBN} includes the ability to debug programs running on
9917various real-time operating systems.
9918
6d2ebf8b 9919@node VxWorks
104c1213
JM
9920@subsection Using @value{GDBN} with VxWorks
9921
9922@cindex VxWorks
9923
9924@table @code
9925
9926@kindex target vxworks
9927@item target vxworks @var{machinename}
9928A VxWorks system, attached via TCP/IP. The argument @var{machinename}
9929is the target system's machine name or IP address.
9930
9931@end table
9932
9933On VxWorks, @code{load} links @var{filename} dynamically on the
9934current target system as well as adding its symbols in @value{GDBN}.
9935
9936@value{GDBN} enables developers to spawn and debug tasks running on networked
9937VxWorks targets from a Unix host. Already-running tasks spawned from
9938the VxWorks shell can also be debugged. @value{GDBN} uses code that runs on
9939both the Unix host and on the VxWorks target. The program
d4f3574e 9940@code{@value{GDBP}} is installed and executed on the Unix host. (It may be
104c1213 9941installed with the name @code{vxgdb}, to distinguish it from a
96a2c332 9942@value{GDBN} for debugging programs on the host itself.)
104c1213
JM
9943
9944@table @code
9945@item VxWorks-timeout @var{args}
9946@kindex vxworks-timeout
5d161b24
DB
9947All VxWorks-based targets now support the option @code{vxworks-timeout}.
9948This option is set by the user, and @var{args} represents the number of
9949seconds @value{GDBN} waits for responses to rpc's. You might use this if
9950your VxWorks target is a slow software simulator or is on the far side
104c1213
JM
9951of a thin network line.
9952@end table
9953
9954The following information on connecting to VxWorks was current when
9955this manual was produced; newer releases of VxWorks may use revised
9956procedures.
9957
9958@kindex INCLUDE_RDB
9959To use @value{GDBN} with VxWorks, you must rebuild your VxWorks kernel
9960to include the remote debugging interface routines in the VxWorks
9961library @file{rdb.a}. To do this, define @code{INCLUDE_RDB} in the
9962VxWorks configuration file @file{configAll.h} and rebuild your VxWorks
9963kernel. The resulting kernel contains @file{rdb.a}, and spawns the
9964source debugging task @code{tRdbTask} when VxWorks is booted. For more
9965information on configuring and remaking VxWorks, see the manufacturer's
9966manual.
9967@c VxWorks, see the @cite{VxWorks Programmer's Guide}.
9968
9969Once you have included @file{rdb.a} in your VxWorks system image and set
9970your Unix execution search path to find @value{GDBN}, you are ready to
96a2c332
SS
9971run @value{GDBN}. From your Unix host, run @code{@value{GDBP}} (or
9972@code{vxgdb}, depending on your installation).
104c1213
JM
9973
9974@value{GDBN} comes up showing the prompt:
9975
9976@example
9977(vxgdb)
9978@end example
9979
9980@menu
9981* VxWorks Connection:: Connecting to VxWorks
9982* VxWorks Download:: VxWorks download
9983* VxWorks Attach:: Running tasks
9984@end menu
9985
6d2ebf8b 9986@node VxWorks Connection
104c1213
JM
9987@subsubsection Connecting to VxWorks
9988
9989The @value{GDBN} command @code{target} lets you connect to a VxWorks target on the
9990network. To connect to a target whose host name is ``@code{tt}'', type:
9991
9992@example
9993(vxgdb) target vxworks tt
9994@end example
9995
9996@need 750
9997@value{GDBN} displays messages like these:
9998
9999@smallexample
5d161b24 10000Attaching remote machine across net...
104c1213
JM
10001Connected to tt.
10002@end smallexample
10003
10004@need 1000
10005@value{GDBN} then attempts to read the symbol tables of any object modules
10006loaded into the VxWorks target since it was last booted. @value{GDBN} locates
10007these files by searching the directories listed in the command search
10008path (@pxref{Environment, ,Your program's environment}); if it fails
10009to find an object file, it displays a message such as:
10010
10011@example
10012prog.o: No such file or directory.
10013@end example
10014
10015When this happens, add the appropriate directory to the search path with
10016the @value{GDBN} command @code{path}, and execute the @code{target}
10017command again.
10018
6d2ebf8b 10019@node VxWorks Download
104c1213
JM
10020@subsubsection VxWorks download
10021
10022@cindex download to VxWorks
10023If you have connected to the VxWorks target and you want to debug an
10024object that has not yet been loaded, you can use the @value{GDBN}
10025@code{load} command to download a file from Unix to VxWorks
10026incrementally. The object file given as an argument to the @code{load}
10027command is actually opened twice: first by the VxWorks target in order
10028to download the code, then by @value{GDBN} in order to read the symbol
10029table. This can lead to problems if the current working directories on
10030the two systems differ. If both systems have NFS mounted the same
10031filesystems, you can avoid these problems by using absolute paths.
10032Otherwise, it is simplest to set the working directory on both systems
10033to the directory in which the object file resides, and then to reference
10034the file by its name, without any path. For instance, a program
10035@file{prog.o} may reside in @file{@var{vxpath}/vw/demo/rdb} in VxWorks
10036and in @file{@var{hostpath}/vw/demo/rdb} on the host. To load this
10037program, type this on VxWorks:
10038
10039@example
10040-> cd "@var{vxpath}/vw/demo/rdb"
10041@end example
d4f3574e
SS
10042
10043@noindent
104c1213
JM
10044Then, in @value{GDBN}, type:
10045
10046@example
5d161b24 10047(vxgdb) cd @var{hostpath}/vw/demo/rdb
104c1213
JM
10048(vxgdb) load prog.o
10049@end example
10050
10051@value{GDBN} displays a response similar to this:
10052
10053@smallexample
10054Reading symbol data from wherever/vw/demo/rdb/prog.o... done.
10055@end smallexample
10056
10057You can also use the @code{load} command to reload an object module
10058after editing and recompiling the corresponding source file. Note that
10059this makes @value{GDBN} delete all currently-defined breakpoints,
10060auto-displays, and convenience variables, and to clear the value
10061history. (This is necessary in order to preserve the integrity of
d4f3574e 10062debugger's data structures that reference the target system's symbol
104c1213
JM
10063table.)
10064
6d2ebf8b 10065@node VxWorks Attach
104c1213
JM
10066@subsubsection Running tasks
10067
10068@cindex running VxWorks tasks
10069You can also attach to an existing task using the @code{attach} command as
10070follows:
10071
10072@example
10073(vxgdb) attach @var{task}
10074@end example
10075
10076@noindent
10077where @var{task} is the VxWorks hexadecimal task ID. The task can be running
10078or suspended when you attach to it. Running tasks are suspended at
10079the time of attachment.
10080
6d2ebf8b 10081@node Embedded Processors
104c1213
JM
10082@section Embedded Processors
10083
10084This section goes into details specific to particular embedded
10085configurations.
10086
10087@menu
10088* A29K Embedded:: AMD A29K Embedded
10089* ARM:: ARM
10090* H8/300:: Hitachi H8/300
10091* H8/500:: Hitachi H8/500
10092* i960:: Intel i960
10093* M32R/D:: Mitsubishi M32R/D
10094* M68K:: Motorola M68K
10095* M88K:: Motorola M88K
10096* MIPS Embedded:: MIPS Embedded
10097* PA:: HP PA Embedded
10098* PowerPC: PowerPC
10099* SH:: Hitachi SH
10100* Sparclet:: Tsqware Sparclet
10101* Sparclite:: Fujitsu Sparclite
10102* ST2000:: Tandem ST2000
10103* Z8000:: Zilog Z8000
10104@end menu
10105
6d2ebf8b 10106@node A29K Embedded
104c1213
JM
10107@subsection AMD A29K Embedded
10108
10109@menu
10110* A29K UDI::
10111* A29K EB29K::
10112* Comms (EB29K):: Communications setup
10113* gdb-EB29K:: EB29K cross-debugging
10114* Remote Log:: Remote log
10115@end menu
10116
10117@table @code
10118
10119@kindex target adapt
10120@item target adapt @var{dev}
10121Adapt monitor for A29K.
10122
10123@kindex target amd-eb
10124@item target amd-eb @var{dev} @var{speed} @var{PROG}
10125@cindex AMD EB29K
10126Remote PC-resident AMD EB29K board, attached over serial lines.
10127@var{dev} is the serial device, as for @code{target remote};
10128@var{speed} allows you to specify the linespeed; and @var{PROG} is the
10129name of the program to be debugged, as it appears to DOS on the PC.
10130@xref{A29K EB29K, ,EBMON protocol for AMD29K}.
10131
10132@end table
10133
6d2ebf8b 10134@node A29K UDI
104c1213
JM
10135@subsubsection A29K UDI
10136
10137@cindex UDI
10138@cindex AMD29K via UDI
10139
10140@value{GDBN} supports AMD's UDI (``Universal Debugger Interface'')
10141protocol for debugging the a29k processor family. To use this
10142configuration with AMD targets running the MiniMON monitor, you need the
10143program @code{MONTIP}, available from AMD at no charge. You can also
10144use @value{GDBN} with the UDI-conformant a29k simulator program
10145@code{ISSTIP}, also available from AMD.
10146
10147@table @code
10148@item target udi @var{keyword}
10149@kindex udi
10150Select the UDI interface to a remote a29k board or simulator, where
10151@var{keyword} is an entry in the AMD configuration file @file{udi_soc}.
10152This file contains keyword entries which specify parameters used to
10153connect to a29k targets. If the @file{udi_soc} file is not in your
10154working directory, you must set the environment variable @samp{UDICONF}
10155to its pathname.
10156@end table
10157
6d2ebf8b 10158@node A29K EB29K
104c1213
JM
10159@subsubsection EBMON protocol for AMD29K
10160
10161@cindex EB29K board
10162@cindex running 29K programs
10163
10164AMD distributes a 29K development board meant to fit in a PC, together
10165with a DOS-hosted monitor program called @code{EBMON}. As a shorthand
10166term, this development system is called the ``EB29K''. To use
10167@value{GDBN} from a Unix system to run programs on the EB29K board, you
10168must first connect a serial cable between the PC (which hosts the EB29K
10169board) and a serial port on the Unix system. In the following, we
10170assume you've hooked the cable between the PC's @file{COM1} port and
10171@file{/dev/ttya} on the Unix system.
10172
6d2ebf8b 10173@node Comms (EB29K)
104c1213
JM
10174@subsubsection Communications setup
10175
10176The next step is to set up the PC's port, by doing something like this
10177in DOS on the PC:
10178
10179@example
10180C:\> MODE com1:9600,n,8,1,none
10181@end example
10182
10183@noindent
10184This example---run on an MS DOS 4.0 system---sets the PC port to 9600
10185bps, no parity, eight data bits, one stop bit, and no ``retry'' action;
10186you must match the communications parameters when establishing the Unix
10187end of the connection as well.
10188@c FIXME: Who knows what this "no retry action" crud from the DOS manual may
5d161b24 10189@c mean? It's optional; leave it out? ---doc@cygnus.com, 25feb91
d4f3574e
SS
10190@c
10191@c It's optional, but it's unwise to omit it: who knows what is the
10192@c default value set when the DOS machines boots? "No retry" means that
10193@c the DOS serial device driver won't retry the operation if it fails;
10194@c I understand that this is needed because the GDB serial protocol
10195@c handles any errors and retransmissions itself. ---Eli Zaretskii, 3sep99
104c1213
JM
10196
10197To give control of the PC to the Unix side of the serial line, type
10198the following at the DOS console:
10199
10200@example
10201C:\> CTTY com1
10202@end example
10203
10204@noindent
10205(Later, if you wish to return control to the DOS console, you can use
10206the command @code{CTTY con}---but you must send it over the device that
96a2c332 10207had control, in our example over the @file{COM1} serial line.)
104c1213
JM
10208
10209From the Unix host, use a communications program such as @code{tip} or
10210@code{cu} to communicate with the PC; for example,
10211
10212@example
10213cu -s 9600 -l /dev/ttya
10214@end example
10215
10216@noindent
10217The @code{cu} options shown specify, respectively, the linespeed and the
10218serial port to use. If you use @code{tip} instead, your command line
10219may look something like the following:
10220
10221@example
10222tip -9600 /dev/ttya
10223@end example
10224
10225@noindent
10226Your system may require a different name where we show
10227@file{/dev/ttya} as the argument to @code{tip}. The communications
10228parameters, including which port to use, are associated with the
10229@code{tip} argument in the ``remote'' descriptions file---normally the
10230system table @file{/etc/remote}.
10231@c FIXME: What if anything needs doing to match the "n,8,1,none" part of
10232@c the DOS side's comms setup? cu can support -o (odd
10233@c parity), -e (even parity)---apparently no settings for no parity or
10234@c for character size. Taken from stty maybe...? John points out tip
10235@c can set these as internal variables, eg ~s parity=none; man stty
10236@c suggests that it *might* work to stty these options with stdin or
10237@c stdout redirected... ---doc@cygnus.com, 25feb91
d4f3574e
SS
10238@c
10239@c There's nothing to be done for the "none" part of the DOS MODE
10240@c command. The rest of the parameters should be matched by the
10241@c baudrate, bits, and parity used by the Unix side. ---Eli Zaretskii, 3Sep99
104c1213
JM
10242
10243@kindex EBMON
10244Using the @code{tip} or @code{cu} connection, change the DOS working
10245directory to the directory containing a copy of your 29K program, then
10246start the PC program @code{EBMON} (an EB29K control program supplied
10247with your board by AMD). You should see an initial display from
10248@code{EBMON} similar to the one that follows, ending with the
10249@code{EBMON} prompt @samp{#}---
10250
10251@example
10252C:\> G:
10253
10254G:\> CD \usr\joe\work29k
10255
10256G:\USR\JOE\WORK29K> EBMON
10257Am29000 PC Coprocessor Board Monitor, version 3.0-18
10258Copyright 1990 Advanced Micro Devices, Inc.
10259Written by Gibbons and Associates, Inc.
10260
10261Enter '?' or 'H' for help
10262
10263PC Coprocessor Type = EB29K
10264I/O Base = 0x208
10265Memory Base = 0xd0000
10266
10267Data Memory Size = 2048KB
10268Available I-RAM Range = 0x8000 to 0x1fffff
10269Available D-RAM Range = 0x80002000 to 0x801fffff
10270
10271PageSize = 0x400
10272Register Stack Size = 0x800
10273Memory Stack Size = 0x1800
10274
10275CPU PRL = 0x3
10276Am29027 Available = No
10277Byte Write Available = Yes
10278
10279# ~.
10280@end example
10281
10282Then exit the @code{cu} or @code{tip} program (done in the example by
10283typing @code{~.} at the @code{EBMON} prompt). @code{EBMON} keeps
10284running, ready for @value{GDBN} to take over.
10285
10286For this example, we've assumed what is probably the most convenient
10287way to make sure the same 29K program is on both the PC and the Unix
d4f3574e 10288system: a PC/NFS connection that establishes ``drive @file{G:}'' on the
104c1213
JM
10289PC as a file system on the Unix host. If you do not have PC/NFS or
10290something similar connecting the two systems, you must arrange some
10291other way---perhaps floppy-disk transfer---of getting the 29K program
10292from the Unix system to the PC; @value{GDBN} does @emph{not} download it over the
10293serial line.
10294
6d2ebf8b 10295@node gdb-EB29K
104c1213
JM
10296@subsubsection EB29K cross-debugging
10297
10298Finally, @code{cd} to the directory containing an image of your 29K
10299program on the Unix system, and start @value{GDBN}---specifying as argument the
10300name of your 29K program:
10301
10302@example
10303cd /usr/joe/work29k
10304@value{GDBP} myfoo
10305@end example
10306
10307@need 500
10308Now you can use the @code{target} command:
10309
10310@example
10311target amd-eb /dev/ttya 9600 MYFOO
10312@c FIXME: test above 'target amd-eb' as spelled, with caps! caps are meant to
10313@c emphasize that this is the name as seen by DOS (since I think DOS is
10314@c single-minded about case of letters). ---doc@cygnus.com, 25feb91
10315@end example
10316
10317@noindent
10318In this example, we've assumed your program is in a file called
10319@file{myfoo}. Note that the filename given as the last argument to
10320@code{target amd-eb} should be the name of the program as it appears to DOS.
10321In our example this is simply @code{MYFOO}, but in general it can include
10322a DOS path, and depending on your transfer mechanism may not resemble
10323the name on the Unix side.
10324
10325At this point, you can set any breakpoints you wish; when you are ready
10326to see your program run on the 29K board, use the @value{GDBN} command
10327@code{run}.
10328
10329To stop debugging the remote program, use the @value{GDBN} @code{detach}
10330command.
10331
10332To return control of the PC to its console, use @code{tip} or @code{cu}
10333once again, after your @value{GDBN} session has concluded, to attach to
10334@code{EBMON}. You can then type the command @code{q} to shut down
10335@code{EBMON}, returning control to the DOS command-line interpreter.
d4f3574e 10336Type @kbd{CTTY con} to return command input to the main DOS console,
104c1213
JM
10337and type @kbd{~.} to leave @code{tip} or @code{cu}.
10338
6d2ebf8b 10339@node Remote Log
104c1213
JM
10340@subsubsection Remote log
10341@kindex eb.log
10342@cindex log file for EB29K
10343
10344The @code{target amd-eb} command creates a file @file{eb.log} in the
10345current working directory, to help debug problems with the connection.
10346@file{eb.log} records all the output from @code{EBMON}, including echoes
10347of the commands sent to it. Running @samp{tail -f} on this file in
10348another window often helps to understand trouble with @code{EBMON}, or
10349unexpected events on the PC side of the connection.
10350
6d2ebf8b 10351@node ARM
104c1213
JM
10352@subsection ARM
10353
10354@table @code
10355
10356@kindex target rdi
10357@item target rdi @var{dev}
10358ARM Angel monitor, via RDI library interface to ADP protocol. You may
10359use this target to communicate with both boards running the Angel
10360monitor, or with the EmbeddedICE JTAG debug device.
5d161b24 10361
104c1213
JM
10362@kindex target rdp
10363@item target rdp @var{dev}
10364ARM Demon monitor.
10365
10366@end table
10367
6d2ebf8b 10368@node H8/300
104c1213
JM
10369@subsection Hitachi H8/300
10370
10371@table @code
10372
d4f3574e 10373@kindex target hms@r{, with H8/300}
104c1213
JM
10374@item target hms @var{dev}
10375A Hitachi SH, H8/300, or H8/500 board, attached via serial line to your host.
10376Use special commands @code{device} and @code{speed} to control the serial
10377line and the communications speed used.
10378
d4f3574e 10379@kindex target e7000@r{, with H8/300}
104c1213
JM
10380@item target e7000 @var{dev}
10381E7000 emulator for Hitachi H8 and SH.
10382
d4f3574e
SS
10383@kindex target sh3@r{, with H8/300}
10384@kindex target sh3e@r{, with H8/300}
104c1213 10385@item target sh3 @var{dev}
96a2c332 10386@itemx target sh3e @var{dev}
104c1213
JM
10387Hitachi SH-3 and SH-3E target systems.
10388
10389@end table
10390
10391@cindex download to H8/300 or H8/500
10392@cindex H8/300 or H8/500 download
10393@cindex download to Hitachi SH
10394@cindex Hitachi SH download
10395When you select remote debugging to a Hitachi SH, H8/300, or H8/500
10396board, the @code{load} command downloads your program to the Hitachi
10397board and also opens it as the current executable target for
10398@value{GDBN} on your host (like the @code{file} command).
10399
10400@value{GDBN} needs to know these things to talk to your
5d161b24 10401Hitachi SH, H8/300, or H8/500:
104c1213
JM
10402
10403@enumerate
10404@item
10405that you want to use @samp{target hms}, the remote debugging interface
10406for Hitachi microprocessors, or @samp{target e7000}, the in-circuit
10407emulator for the Hitachi SH and the Hitachi 300H. (@samp{target hms} is
2df3850c 10408the default when @value{GDBN} is configured specifically for the Hitachi SH,
104c1213
JM
10409H8/300, or H8/500.)
10410
10411@item
10412what serial device connects your host to your Hitachi board (the first
10413serial device available on your host is the default).
10414
10415@item
10416what speed to use over the serial device.
10417@end enumerate
10418
10419@menu
10420* Hitachi Boards:: Connecting to Hitachi boards.
10421* Hitachi ICE:: Using the E7000 In-Circuit Emulator.
10422* Hitachi Special:: Special @value{GDBN} commands for Hitachi micros.
10423@end menu
10424
6d2ebf8b 10425@node Hitachi Boards
104c1213
JM
10426@subsubsection Connecting to Hitachi boards
10427
10428@c only for Unix hosts
10429@kindex device
10430@cindex serial device, Hitachi micros
96a2c332 10431Use the special @code{@value{GDBN}} command @samp{device @var{port}} if you
104c1213
JM
10432need to explicitly set the serial device. The default @var{port} is the
10433first available port on your host. This is only necessary on Unix
10434hosts, where it is typically something like @file{/dev/ttya}.
10435
10436@kindex speed
10437@cindex serial line speed, Hitachi micros
96a2c332 10438@code{@value{GDBN}} has another special command to set the communications
104c1213 10439speed: @samp{speed @var{bps}}. This command also is only used from Unix
2df3850c 10440hosts; on DOS hosts, set the line speed as usual from outside @value{GDBN} with
d4f3574e
SS
10441the DOS @code{mode} command (for instance,
10442@w{@kbd{mode com2:9600,n,8,1,p}} for a 9600@dmn{bps} connection).
104c1213
JM
10443
10444The @samp{device} and @samp{speed} commands are available only when you
10445use a Unix host to debug your Hitachi microprocessor programs. If you
10446use a DOS host,
10447@value{GDBN} depends on an auxiliary terminate-and-stay-resident program
10448called @code{asynctsr} to communicate with the development board
10449through a PC serial port. You must also use the DOS @code{mode} command
10450to set up the serial port on the DOS side.
10451
10452The following sample session illustrates the steps needed to start a
10453program under @value{GDBN} control on an H8/300. The example uses a
10454sample H8/300 program called @file{t.x}. The procedure is the same for
10455the Hitachi SH and the H8/500.
10456
10457First hook up your development board. In this example, we use a
10458board attached to serial port @code{COM2}; if you use a different serial
10459port, substitute its name in the argument of the @code{mode} command.
10460When you call @code{asynctsr}, the auxiliary comms program used by the
d4f3574e 10461debugger, you give it just the numeric part of the serial port's name;
104c1213
JM
10462for example, @samp{asyncstr 2} below runs @code{asyncstr} on
10463@code{COM2}.
10464
10465@example
10466C:\H8300\TEST> asynctsr 2
10467C:\H8300\TEST> mode com2:9600,n,8,1,p
10468
10469Resident portion of MODE loaded
10470
10471COM2: 9600, n, 8, 1, p
10472
10473@end example
10474
10475@quotation
10476@emph{Warning:} We have noticed a bug in PC-NFS that conflicts with
10477@code{asynctsr}. If you also run PC-NFS on your DOS host, you may need to
10478disable it, or even boot without it, to use @code{asynctsr} to control
10479your development board.
10480@end quotation
10481
d4f3574e 10482@kindex target hms@r{, and serial protocol}
104c1213
JM
10483Now that serial communications are set up, and the development board is
10484connected, you can start up @value{GDBN}. Call @code{@value{GDBP}} with
96a2c332 10485the name of your program as the argument. @code{@value{GDBN}} prompts
104c1213
JM
10486you, as usual, with the prompt @samp{(@value{GDBP})}. Use two special
10487commands to begin your debugging session: @samp{target hms} to specify
10488cross-debugging to the Hitachi board, and the @code{load} command to
10489download your program to the board. @code{load} displays the names of
10490the program's sections, and a @samp{*} for each 2K of data downloaded.
10491(If you want to refresh @value{GDBN} data on symbols or on the
10492executable file without downloading, use the @value{GDBN} commands
10493@code{file} or @code{symbol-file}. These commands, and @code{load}
10494itself, are described in @ref{Files,,Commands to specify files}.)
10495
10496@smallexample
10497(eg-C:\H8300\TEST) @value{GDBP} t.x
2df3850c 10498@value{GDBN} is free software and you are welcome to distribute copies
5d161b24 10499 of it under certain conditions; type "show copying" to see
104c1213 10500 the conditions.
5d161b24 10501There is absolutely no warranty for @value{GDBN}; type "show warranty"
104c1213 10502for details.
2df3850c
JM
10503@value{GDBN} @value{GDBVN}, Copyright 1992 Free Software Foundation, Inc...
10504(@value{GDBP}) target hms
104c1213 10505Connected to remote H8/300 HMS system.
2df3850c 10506(@value{GDBP}) load t.x
104c1213
JM
10507.text : 0x8000 .. 0xabde ***********
10508.data : 0xabde .. 0xad30 *
10509.stack : 0xf000 .. 0xf014 *
10510@end smallexample
10511
10512At this point, you're ready to run or debug your program. From here on,
10513you can use all the usual @value{GDBN} commands. The @code{break} command
10514sets breakpoints; the @code{run} command starts your program;
10515@code{print} or @code{x} display data; the @code{continue} command
10516resumes execution after stopping at a breakpoint. You can use the
10517@code{help} command at any time to find out more about @value{GDBN} commands.
10518
10519Remember, however, that @emph{operating system} facilities aren't
10520available on your development board; for example, if your program hangs,
10521you can't send an interrupt---but you can press the @sc{reset} switch!
10522
10523Use the @sc{reset} button on the development board
10524@itemize @bullet
10525@item
10526to interrupt your program (don't use @kbd{ctl-C} on the DOS host---it has
10527no way to pass an interrupt signal to the development board); and
10528
10529@item
10530to return to the @value{GDBN} command prompt after your program finishes
10531normally. The communications protocol provides no other way for @value{GDBN}
10532to detect program completion.
10533@end itemize
10534
10535In either case, @value{GDBN} sees the effect of a @sc{reset} on the
10536development board as a ``normal exit'' of your program.
10537
6d2ebf8b 10538@node Hitachi ICE
104c1213
JM
10539@subsubsection Using the E7000 in-circuit emulator
10540
d4f3574e 10541@kindex target e7000@r{, with Hitachi ICE}
104c1213
JM
10542You can use the E7000 in-circuit emulator to develop code for either the
10543Hitachi SH or the H8/300H. Use one of these forms of the @samp{target
10544e7000} command to connect @value{GDBN} to your E7000:
10545
10546@table @code
10547@item target e7000 @var{port} @var{speed}
10548Use this form if your E7000 is connected to a serial port. The
10549@var{port} argument identifies what serial port to use (for example,
10550@samp{com2}). The third argument is the line speed in bits per second
10551(for example, @samp{9600}).
10552
10553@item target e7000 @var{hostname}
10554If your E7000 is installed as a host on a TCP/IP network, you can just
10555specify its hostname; @value{GDBN} uses @code{telnet} to connect.
10556@end table
10557
6d2ebf8b 10558@node Hitachi Special
104c1213
JM
10559@subsubsection Special @value{GDBN} commands for Hitachi micros
10560
10561Some @value{GDBN} commands are available only for the H8/300:
10562
10563@table @code
10564
10565@kindex set machine
10566@kindex show machine
10567@item set machine h8300
10568@itemx set machine h8300h
10569Condition @value{GDBN} for one of the two variants of the H8/300
10570architecture with @samp{set machine}. You can use @samp{show machine}
10571to check which variant is currently in effect.
10572
10573@end table
10574
6d2ebf8b 10575@node H8/500
104c1213
JM
10576@subsection H8/500
10577
10578@table @code
10579
10580@kindex set memory @var{mod}
10581@cindex memory models, H8/500
10582@item set memory @var{mod}
10583@itemx show memory
10584Specify which H8/500 memory model (@var{mod}) you are using with
10585@samp{set memory}; check which memory model is in effect with @samp{show
10586memory}. The accepted values for @var{mod} are @code{small},
10587@code{big}, @code{medium}, and @code{compact}.
10588
10589@end table
10590
6d2ebf8b 10591@node i960
104c1213
JM
10592@subsection Intel i960
10593
10594@table @code
10595
10596@kindex target mon960
10597@item target mon960 @var{dev}
10598MON960 monitor for Intel i960.
10599
f0ca3dce 10600@kindex target nindy
104c1213
JM
10601@item target nindy @var{devicename}
10602An Intel 960 board controlled by a Nindy Monitor. @var{devicename} is
10603the name of the serial device to use for the connection, e.g.
10604@file{/dev/ttya}.
10605
10606@end table
10607
10608@cindex Nindy
10609@cindex i960
10610@dfn{Nindy} is a ROM Monitor program for Intel 960 target systems. When
10611@value{GDBN} is configured to control a remote Intel 960 using Nindy, you can
10612tell @value{GDBN} how to connect to the 960 in several ways:
10613
10614@itemize @bullet
10615@item
10616Through command line options specifying serial port, version of the
10617Nindy protocol, and communications speed;
10618
10619@item
10620By responding to a prompt on startup;
10621
10622@item
10623By using the @code{target} command at any point during your @value{GDBN}
10624session. @xref{Target Commands, ,Commands for managing targets}.
10625
104c1213
JM
10626@end itemize
10627
10628@cindex download to Nindy-960
10629With the Nindy interface to an Intel 960 board, @code{load}
10630downloads @var{filename} to the 960 as well as adding its symbols in
10631@value{GDBN}.
10632
10633@menu
10634* Nindy Startup:: Startup with Nindy
10635* Nindy Options:: Options for Nindy
10636* Nindy Reset:: Nindy reset command
10637@end menu
10638
6d2ebf8b 10639@node Nindy Startup
104c1213
JM
10640@subsubsection Startup with Nindy
10641
10642If you simply start @code{@value{GDBP}} without using any command-line
10643options, you are prompted for what serial port to use, @emph{before} you
10644reach the ordinary @value{GDBN} prompt:
10645
10646@example
5d161b24 10647Attach /dev/ttyNN -- specify NN, or "quit" to quit:
104c1213
JM
10648@end example
10649
10650@noindent
10651Respond to the prompt with whatever suffix (after @samp{/dev/tty})
10652identifies the serial port you want to use. You can, if you choose,
10653simply start up with no Nindy connection by responding to the prompt
10654with an empty line. If you do this and later wish to attach to Nindy,
10655use @code{target} (@pxref{Target Commands, ,Commands for managing targets}).
10656
6d2ebf8b 10657@node Nindy Options
104c1213
JM
10658@subsubsection Options for Nindy
10659
10660These are the startup options for beginning your @value{GDBN} session with a
10661Nindy-960 board attached:
10662
10663@table @code
10664@item -r @var{port}
10665Specify the serial port name of a serial interface to be used to connect
10666to the target system. This option is only available when @value{GDBN} is
10667configured for the Intel 960 target architecture. You may specify
10668@var{port} as any of: a full pathname (e.g. @samp{-r /dev/ttya}), a
10669device name in @file{/dev} (e.g. @samp{-r ttya}), or simply the unique
10670suffix for a specific @code{tty} (e.g. @samp{-r a}).
10671
10672@item -O
10673(An uppercase letter ``O'', not a zero.) Specify that @value{GDBN} should use
10674the ``old'' Nindy monitor protocol to connect to the target system.
10675This option is only available when @value{GDBN} is configured for the Intel 960
10676target architecture.
10677
10678@quotation
10679@emph{Warning:} if you specify @samp{-O}, but are actually trying to
10680connect to a target system that expects the newer protocol, the connection
10681fails, appearing to be a speed mismatch. @value{GDBN} repeatedly
10682attempts to reconnect at several different line speeds. You can abort
10683this process with an interrupt.
10684@end quotation
10685
10686@item -brk
10687Specify that @value{GDBN} should first send a @code{BREAK} signal to the target
10688system, in an attempt to reset it, before connecting to a Nindy target.
10689
10690@quotation
10691@emph{Warning:} Many target systems do not have the hardware that this
10692requires; it only works with a few boards.
10693@end quotation
10694@end table
10695
10696The standard @samp{-b} option controls the line speed used on the serial
10697port.
10698
10699@c @group
6d2ebf8b 10700@node Nindy Reset
104c1213
JM
10701@subsubsection Nindy reset command
10702
10703@table @code
10704@item reset
10705@kindex reset
10706For a Nindy target, this command sends a ``break'' to the remote target
10707system; this is only useful if the target has been equipped with a
10708circuit to perform a hard reset (or some other interesting action) when
10709a break is detected.
10710@end table
10711@c @end group
10712
6d2ebf8b 10713@node M32R/D
104c1213
JM
10714@subsection Mitsubishi M32R/D
10715
10716@table @code
10717
10718@kindex target m32r
10719@item target m32r @var{dev}
10720Mitsubishi M32R/D ROM monitor.
10721
10722@end table
10723
6d2ebf8b 10724@node M68K
104c1213
JM
10725@subsection M68k
10726
10727The Motorola m68k configuration includes ColdFire support, and
10728target command for the following ROM monitors.
10729
10730@table @code
10731
10732@kindex target abug
10733@item target abug @var{dev}
10734ABug ROM monitor for M68K.
10735
10736@kindex target cpu32bug
10737@item target cpu32bug @var{dev}
10738CPU32BUG monitor, running on a CPU32 (M68K) board.
10739
10740@kindex target dbug
10741@item target dbug @var{dev}
10742dBUG ROM monitor for Motorola ColdFire.
10743
10744@kindex target est
10745@item target est @var{dev}
10746EST-300 ICE monitor, running on a CPU32 (M68K) board.
10747
10748@kindex target rom68k
10749@item target rom68k @var{dev}
10750ROM 68K monitor, running on an M68K IDP board.
10751
10752@end table
10753
10754If @value{GDBN} is configured with @code{m68*-ericsson-*}, it will
10755instead have only a single special target command:
10756
10757@table @code
10758
10759@kindex target es1800
10760@item target es1800 @var{dev}
10761ES-1800 emulator for M68K.
10762
10763@end table
10764
10765[context?]
10766
10767@table @code
10768
10769@kindex target rombug
10770@item target rombug @var{dev}
10771ROMBUG ROM monitor for OS/9000.
10772
10773@end table
10774
6d2ebf8b 10775@node M88K
104c1213
JM
10776@subsection M88K
10777
10778@table @code
10779
10780@kindex target bug
10781@item target bug @var{dev}
10782BUG monitor, running on a MVME187 (m88k) board.
10783
10784@end table
10785
6d2ebf8b 10786@node MIPS Embedded
104c1213
JM
10787@subsection MIPS Embedded
10788
10789@cindex MIPS boards
10790@value{GDBN} can use the MIPS remote debugging protocol to talk to a
10791MIPS board attached to a serial line. This is available when
10792you configure @value{GDBN} with @samp{--target=mips-idt-ecoff}.
10793
10794@need 1000
10795Use these @value{GDBN} commands to specify the connection to your target board:
10796
10797@table @code
10798@item target mips @var{port}
10799@kindex target mips @var{port}
10800To run a program on the board, start up @code{@value{GDBP}} with the
10801name of your program as the argument. To connect to the board, use the
10802command @samp{target mips @var{port}}, where @var{port} is the name of
10803the serial port connected to the board. If the program has not already
10804been downloaded to the board, you may use the @code{load} command to
10805download it. You can then use all the usual @value{GDBN} commands.
10806
10807For example, this sequence connects to the target board through a serial
10808port, and loads and runs a program called @var{prog} through the
10809debugger:
10810
10811@example
10812host$ @value{GDBP} @var{prog}
2df3850c
JM
10813@value{GDBN} is free software and @dots{}
10814(@value{GDBP}) target mips /dev/ttyb
10815(@value{GDBP}) load @var{prog}
10816(@value{GDBP}) run
104c1213
JM
10817@end example
10818
10819@item target mips @var{hostname}:@var{portnumber}
10820On some @value{GDBN} host configurations, you can specify a TCP
10821connection (for instance, to a serial line managed by a terminal
10822concentrator) instead of a serial port, using the syntax
10823@samp{@var{hostname}:@var{portnumber}}.
10824
10825@item target pmon @var{port}
10826@kindex target pmon @var{port}
10827PMON ROM monitor.
10828
10829@item target ddb @var{port}
10830@kindex target ddb @var{port}
10831NEC's DDB variant of PMON for Vr4300.
10832
10833@item target lsi @var{port}
10834@kindex target lsi @var{port}
10835LSI variant of PMON.
10836
10837@kindex target r3900
10838@item target r3900 @var{dev}
10839Densan DVE-R3900 ROM monitor for Toshiba R3900 Mips.
10840
10841@kindex target array
10842@item target array @var{dev}
10843Array Tech LSI33K RAID controller board.
10844
10845@end table
10846
10847
10848@noindent
10849@value{GDBN} also supports these special commands for MIPS targets:
10850
10851@table @code
10852@item set processor @var{args}
10853@itemx show processor
10854@kindex set processor @var{args}
10855@kindex show processor
10856Use the @code{set processor} command to set the type of MIPS
10857processor when you want to access processor-type-specific registers.
5d161b24 10858For example, @code{set processor @var{r3041}} tells @value{GDBN}
104c1213 10859to use the CPO registers appropriate for the 3041 chip.
5d161b24 10860Use the @code{show processor} command to see what MIPS processor @value{GDBN}
104c1213 10861is using. Use the @code{info reg} command to see what registers
5d161b24 10862@value{GDBN} is using.
104c1213
JM
10863
10864@item set mipsfpu double
10865@itemx set mipsfpu single
10866@itemx set mipsfpu none
10867@itemx show mipsfpu
10868@kindex set mipsfpu
10869@kindex show mipsfpu
10870@cindex MIPS remote floating point
10871@cindex floating point, MIPS remote
10872If your target board does not support the MIPS floating point
10873coprocessor, you should use the command @samp{set mipsfpu none} (if you
96a2c332 10874need this, you may wish to put the command in your @value{GDBN} init
104c1213
JM
10875file). This tells @value{GDBN} how to find the return value of
10876functions which return floating point values. It also allows
10877@value{GDBN} to avoid saving the floating point registers when calling
10878functions on the board. If you are using a floating point coprocessor
10879with only single precision floating point support, as on the @sc{r4650}
10880processor, use the command @samp{set mipsfpu single}. The default
10881double precision floating point coprocessor may be selected using
10882@samp{set mipsfpu double}.
10883
10884In previous versions the only choices were double precision or no
10885floating point, so @samp{set mipsfpu on} will select double precision
10886and @samp{set mipsfpu off} will select no floating point.
10887
10888As usual, you can inquire about the @code{mipsfpu} variable with
10889@samp{show mipsfpu}.
10890
10891@item set remotedebug @var{n}
10892@itemx show remotedebug
d4f3574e
SS
10893@kindex set remotedebug@r{, MIPS protocol}
10894@kindex show remotedebug@r{, MIPS protocol}
104c1213
JM
10895@cindex @code{remotedebug}, MIPS protocol
10896@cindex MIPS @code{remotedebug} protocol
10897@c FIXME! For this to be useful, you must know something about the MIPS
10898@c FIXME...protocol. Where is it described?
10899You can see some debugging information about communications with the board
10900by setting the @code{remotedebug} variable. If you set it to @code{1} using
10901@samp{set remotedebug 1}, every packet is displayed. If you set it
10902to @code{2}, every character is displayed. You can check the current value
10903at any time with the command @samp{show remotedebug}.
10904
10905@item set timeout @var{seconds}
10906@itemx set retransmit-timeout @var{seconds}
10907@itemx show timeout
10908@itemx show retransmit-timeout
10909@cindex @code{timeout}, MIPS protocol
10910@cindex @code{retransmit-timeout}, MIPS protocol
10911@kindex set timeout
10912@kindex show timeout
10913@kindex set retransmit-timeout
10914@kindex show retransmit-timeout
10915You can control the timeout used while waiting for a packet, in the MIPS
10916remote protocol, with the @code{set timeout @var{seconds}} command. The
10917default is 5 seconds. Similarly, you can control the timeout used while
10918waiting for an acknowledgement of a packet with the @code{set
10919retransmit-timeout @var{seconds}} command. The default is 3 seconds.
10920You can inspect both values with @code{show timeout} and @code{show
10921retransmit-timeout}. (These commands are @emph{only} available when
10922@value{GDBN} is configured for @samp{--target=mips-idt-ecoff}.)
10923
10924The timeout set by @code{set timeout} does not apply when @value{GDBN}
10925is waiting for your program to stop. In that case, @value{GDBN} waits
10926forever because it has no way of knowing how long the program is going
10927to run before stopping.
10928@end table
10929
6d2ebf8b 10930@node PowerPC
104c1213
JM
10931@subsection PowerPC
10932
10933@table @code
10934
10935@kindex target dink32
10936@item target dink32 @var{dev}
10937DINK32 ROM monitor.
10938
10939@kindex target ppcbug
10940@item target ppcbug @var{dev}
10941@kindex target ppcbug1
10942@item target ppcbug1 @var{dev}
10943PPCBUG ROM monitor for PowerPC.
10944
10945@kindex target sds
10946@item target sds @var{dev}
10947SDS monitor, running on a PowerPC board (such as Motorola's ADS).
10948
10949@end table
10950
6d2ebf8b 10951@node PA
104c1213
JM
10952@subsection HP PA Embedded
10953
10954@table @code
10955
10956@kindex target op50n
10957@item target op50n @var{dev}
10958OP50N monitor, running on an OKI HPPA board.
10959
10960@kindex target w89k
10961@item target w89k @var{dev}
10962W89K monitor, running on a Winbond HPPA board.
10963
10964@end table
10965
6d2ebf8b 10966@node SH
104c1213
JM
10967@subsection Hitachi SH
10968
10969@table @code
10970
d4f3574e 10971@kindex target hms@r{, with Hitachi SH}
104c1213
JM
10972@item target hms @var{dev}
10973A Hitachi SH board attached via serial line to your host. Use special
10974commands @code{device} and @code{speed} to control the serial line and
10975the communications speed used.
10976
d4f3574e 10977@kindex target e7000@r{, with Hitachi SH}
104c1213
JM
10978@item target e7000 @var{dev}
10979E7000 emulator for Hitachi SH.
10980
d4f3574e
SS
10981@kindex target sh3@r{, with SH}
10982@kindex target sh3e@r{, with SH}
104c1213
JM
10983@item target sh3 @var{dev}
10984@item target sh3e @var{dev}
10985Hitachi SH-3 and SH-3E target systems.
10986
10987@end table
10988
6d2ebf8b 10989@node Sparclet
104c1213
JM
10990@subsection Tsqware Sparclet
10991
10992@cindex Sparclet
10993
5d161b24
DB
10994@value{GDBN} enables developers to debug tasks running on
10995Sparclet targets from a Unix host.
104c1213
JM
10996@value{GDBN} uses code that runs on
10997both the Unix host and on the Sparclet target. The program
5d161b24 10998@code{@value{GDBP}} is installed and executed on the Unix host.
104c1213
JM
10999
11000@table @code
f0ca3dce 11001@item remotetimeout @var{args}
104c1213 11002@kindex remotetimeout
5d161b24
DB
11003@value{GDBN} supports the option @code{remotetimeout}.
11004This option is set by the user, and @var{args} represents the number of
11005seconds @value{GDBN} waits for responses.
104c1213
JM
11006@end table
11007
11008@kindex Compiling
5d161b24 11009When compiling for debugging, include the options @samp{-g} to get debug
d4f3574e 11010information and @samp{-Ttext} to relocate the program to where you wish to
5d161b24 11011load it on the target. You may also want to add the options @samp{-n} or
d4f3574e 11012@samp{-N} in order to reduce the size of the sections. Example:
104c1213
JM
11013
11014@example
11015sparclet-aout-gcc prog.c -Ttext 0x12010000 -g -o prog -N
11016@end example
11017
d4f3574e 11018You can use @code{objdump} to verify that the addresses are what you intended:
104c1213
JM
11019
11020@example
11021sparclet-aout-objdump --headers --syms prog
11022@end example
11023
11024@kindex Running
11025Once you have set
11026your Unix execution search path to find @value{GDBN}, you are ready to
5d161b24 11027run @value{GDBN}. From your Unix host, run @code{@value{GDBP}}
104c1213
JM
11028(or @code{sparclet-aout-gdb}, depending on your installation).
11029
11030@value{GDBN} comes up showing the prompt:
11031
11032@example
11033(gdbslet)
11034@end example
11035
11036@menu
11037* Sparclet File:: Setting the file to debug
11038* Sparclet Connection:: Connecting to Sparclet
11039* Sparclet Download:: Sparclet download
5d161b24 11040* Sparclet Execution:: Running and debugging
104c1213
JM
11041@end menu
11042
6d2ebf8b 11043@node Sparclet File
104c1213
JM
11044@subsubsection Setting file to debug
11045
11046The @value{GDBN} command @code{file} lets you choose with program to debug.
11047
11048@example
11049(gdbslet) file prog
11050@end example
11051
11052@need 1000
11053@value{GDBN} then attempts to read the symbol table of @file{prog}.
11054@value{GDBN} locates
11055the file by searching the directories listed in the command search
11056path.
11057If the file was compiled with debug information (option "-g"), source
11058files will be searched as well.
11059@value{GDBN} locates
11060the source files by searching the directories listed in the directory search
11061path (@pxref{Environment, ,Your program's environment}).
11062If it fails
11063to find a file, it displays a message such as:
11064
11065@example
11066prog: No such file or directory.
11067@end example
11068
11069When this happens, add the appropriate directories to the search paths with
5d161b24 11070the @value{GDBN} commands @code{path} and @code{dir}, and execute the
104c1213
JM
11071@code{target} command again.
11072
6d2ebf8b 11073@node Sparclet Connection
104c1213
JM
11074@subsubsection Connecting to Sparclet
11075
11076The @value{GDBN} command @code{target} lets you connect to a Sparclet target.
11077To connect to a target on serial port ``@code{ttya}'', type:
11078
11079@example
11080(gdbslet) target sparclet /dev/ttya
11081Remote target sparclet connected to /dev/ttya
5d161b24 11082main () at ../prog.c:3
104c1213
JM
11083@end example
11084
11085@need 750
11086@value{GDBN} displays messages like these:
11087
d4f3574e 11088@example
104c1213 11089Connected to ttya.
d4f3574e 11090@end example
104c1213 11091
6d2ebf8b 11092@node Sparclet Download
104c1213
JM
11093@subsubsection Sparclet download
11094
11095@cindex download to Sparclet
5d161b24 11096Once connected to the Sparclet target,
104c1213
JM
11097you can use the @value{GDBN}
11098@code{load} command to download the file from the host to the target.
11099The file name and load offset should be given as arguments to the @code{load}
11100command.
5d161b24 11101Since the file format is aout, the program must be loaded to the starting
d4f3574e 11102address. You can use @code{objdump} to find out what this value is. The load
104c1213
JM
11103offset is an offset which is added to the VMA (virtual memory address)
11104of each of the file's sections.
11105For instance, if the program
11106@file{prog} was linked to text address 0x1201000, with data at 0x12010160
11107and bss at 0x12010170, in @value{GDBN}, type:
11108
11109@example
11110(gdbslet) load prog 0x12010000
11111Loading section .text, size 0xdb0 vma 0x12010000
11112@end example
11113
5d161b24
DB
11114If the code is loaded at a different address then what the program was linked
11115to, you may need to use the @code{section} and @code{add-symbol-file} commands
104c1213
JM
11116to tell @value{GDBN} where to map the symbol table.
11117
6d2ebf8b 11118@node Sparclet Execution
104c1213
JM
11119@subsubsection Running and debugging
11120
11121@cindex running and debugging Sparclet programs
11122You can now begin debugging the task using @value{GDBN}'s execution control
5d161b24 11123commands, @code{b}, @code{step}, @code{run}, etc. See the @value{GDBN}
104c1213
JM
11124manual for the list of commands.
11125
11126@example
11127(gdbslet) b main
11128Breakpoint 1 at 0x12010000: file prog.c, line 3.
5d161b24 11129(gdbslet) run
104c1213
JM
11130Starting program: prog
11131Breakpoint 1, main (argc=1, argv=0xeffff21c) at prog.c:3
111323 char *symarg = 0;
11133(gdbslet) step
111344 char *execarg = "hello!";
5d161b24 11135(gdbslet)
104c1213
JM
11136@end example
11137
6d2ebf8b 11138@node Sparclite
104c1213
JM
11139@subsection Fujitsu Sparclite
11140
11141@table @code
11142
11143@kindex target sparclite
11144@item target sparclite @var{dev}
5d161b24
DB
11145Fujitsu sparclite boards, used only for the purpose of loading.
11146You must use an additional command to debug the program.
11147For example: target remote @var{dev} using @value{GDBN} standard
104c1213
JM
11148remote protocol.
11149
11150@end table
11151
6d2ebf8b 11152@node ST2000
104c1213
JM
11153@subsection Tandem ST2000
11154
2df3850c 11155@value{GDBN} may be used with a Tandem ST2000 phone switch, running Tandem's
104c1213
JM
11156STDBUG protocol.
11157
11158To connect your ST2000 to the host system, see the manufacturer's
11159manual. Once the ST2000 is physically attached, you can run:
11160
11161@example
11162target st2000 @var{dev} @var{speed}
11163@end example
11164
11165@noindent
11166to establish it as your debugging environment. @var{dev} is normally
11167the name of a serial device, such as @file{/dev/ttya}, connected to the
11168ST2000 via a serial line. You can instead specify @var{dev} as a TCP
11169connection (for example, to a serial line attached via a terminal
11170concentrator) using the syntax @code{@var{hostname}:@var{portnumber}}.
11171
11172The @code{load} and @code{attach} commands are @emph{not} defined for
11173this target; you must load your program into the ST2000 as you normally
11174would for standalone operation. @value{GDBN} reads debugging information
11175(such as symbols) from a separate, debugging version of the program
11176available on your host computer.
11177@c FIXME!! This is terribly vague; what little content is here is
11178@c basically hearsay.
11179
11180@cindex ST2000 auxiliary commands
11181These auxiliary @value{GDBN} commands are available to help you with the ST2000
11182environment:
11183
11184@table @code
11185@item st2000 @var{command}
11186@kindex st2000 @var{cmd}
11187@cindex STDBUG commands (ST2000)
11188@cindex commands to STDBUG (ST2000)
11189Send a @var{command} to the STDBUG monitor. See the manufacturer's
11190manual for available commands.
11191
11192@item connect
11193@cindex connect (to STDBUG)
11194Connect the controlling terminal to the STDBUG command monitor. When
11195you are done interacting with STDBUG, typing either of two character
11196sequences gets you back to the @value{GDBN} command prompt:
11197@kbd{@key{RET}~.} (Return, followed by tilde and period) or
11198@kbd{@key{RET}~@key{C-d}} (Return, followed by tilde and control-D).
11199@end table
11200
6d2ebf8b 11201@node Z8000
104c1213
JM
11202@subsection Zilog Z8000
11203
11204@cindex Z8000
11205@cindex simulator, Z8000
11206@cindex Zilog Z8000 simulator
11207
11208When configured for debugging Zilog Z8000 targets, @value{GDBN} includes
11209a Z8000 simulator.
11210
11211For the Z8000 family, @samp{target sim} simulates either the Z8002 (the
11212unsegmented variant of the Z8000 architecture) or the Z8001 (the
11213segmented variant). The simulator recognizes which architecture is
11214appropriate by inspecting the object code.
11215
11216@table @code
11217@item target sim @var{args}
11218@kindex sim
d4f3574e 11219@kindex target sim@r{, with Z8000}
104c1213
JM
11220Debug programs on a simulated CPU. If the simulator supports setup
11221options, specify them via @var{args}.
11222@end table
11223
11224@noindent
11225After specifying this target, you can debug programs for the simulated
11226CPU in the same style as programs for your host computer; use the
11227@code{file} command to load a new program image, the @code{run} command
11228to run your program, and so on.
11229
d4f3574e
SS
11230As well as making available all the usual machine registers
11231(@pxref{Registers, ,Registers}), the Z8000 simulator provides three
11232additional items of information as specially named registers:
104c1213
JM
11233
11234@table @code
11235
11236@item cycles
11237Counts clock-ticks in the simulator.
11238
11239@item insts
11240Counts instructions run in the simulator.
11241
11242@item time
11243Execution time in 60ths of a second.
11244
11245@end table
11246
11247You can refer to these values in @value{GDBN} expressions with the usual
11248conventions; for example, @w{@samp{b fputc if $cycles>5000}} sets a
11249conditional breakpoint that suspends only after at least 5000
11250simulated clock ticks.
11251
6d2ebf8b 11252@node Architectures
104c1213
JM
11253@section Architectures
11254
11255This section describes characteristics of architectures that affect
2df3850c 11256all uses of @value{GDBN} with the architecture, both native and cross.
104c1213
JM
11257
11258@menu
11259* A29K::
11260* Alpha::
11261* MIPS::
11262@end menu
11263
6d2ebf8b 11264@node A29K
104c1213
JM
11265@subsection A29K
11266
11267@table @code
11268
11269@kindex set rstack_high_address
11270@cindex AMD 29K register stack
11271@cindex register stack, AMD29K
11272@item set rstack_high_address @var{address}
11273On AMD 29000 family processors, registers are saved in a separate
d4f3574e 11274@dfn{register stack}. There is no way for @value{GDBN} to determine the
104c1213
JM
11275extent of this stack. Normally, @value{GDBN} just assumes that the
11276stack is ``large enough''. This may result in @value{GDBN} referencing
11277memory locations that do not exist. If necessary, you can get around
11278this problem by specifying the ending address of the register stack with
11279the @code{set rstack_high_address} command. The argument should be an
11280address, which you probably want to precede with @samp{0x} to specify in
11281hexadecimal.
11282
11283@kindex show rstack_high_address
11284@item show rstack_high_address
11285Display the current limit of the register stack, on AMD 29000 family
11286processors.
11287
11288@end table
11289
6d2ebf8b 11290@node Alpha
104c1213
JM
11291@subsection Alpha
11292
11293See the following section.
11294
6d2ebf8b 11295@node MIPS
104c1213
JM
11296@subsection MIPS
11297
11298@cindex stack on Alpha
11299@cindex stack on MIPS
11300@cindex Alpha stack
11301@cindex MIPS stack
11302Alpha- and MIPS-based computers use an unusual stack frame, which
11303sometimes requires @value{GDBN} to search backward in the object code to
11304find the beginning of a function.
11305
11306@cindex response time, MIPS debugging
11307To improve response time (especially for embedded applications, where
11308@value{GDBN} may be restricted to a slow serial line for this search)
11309you may want to limit the size of this search, using one of these
11310commands:
11311
11312@table @code
00e4a2e4 11313@cindex @code{heuristic-fence-post} (Alpha, MIPS)
104c1213
JM
11314@item set heuristic-fence-post @var{limit}
11315Restrict @value{GDBN} to examining at most @var{limit} bytes in its
11316search for the beginning of a function. A value of @var{0} (the
11317default) means there is no limit. However, except for @var{0}, the
11318larger the limit the more bytes @code{heuristic-fence-post} must search
11319and therefore the longer it takes to run.
11320
11321@item show heuristic-fence-post
11322Display the current limit.
11323@end table
11324
11325@noindent
11326These commands are available @emph{only} when @value{GDBN} is configured
11327for debugging programs on Alpha or MIPS processors.
11328
11329
6d2ebf8b 11330@node Controlling GDB
c906108c
SS
11331@chapter Controlling @value{GDBN}
11332
53a5351d
JM
11333You can alter the way @value{GDBN} interacts with you by using the
11334@code{set} command. For commands controlling how @value{GDBN} displays
d4f3574e 11335data, see @ref{Print Settings, ,Print settings}. Other settings are
53a5351d 11336described here.
c906108c
SS
11337
11338@menu
11339* Prompt:: Prompt
11340* Editing:: Command editing
11341* History:: Command history
11342* Screen Size:: Screen size
11343* Numbers:: Numbers
11344* Messages/Warnings:: Optional warnings and messages
5d161b24 11345* Debugging Output:: Optional messages about internal happenings
c906108c
SS
11346@end menu
11347
6d2ebf8b 11348@node Prompt
c906108c
SS
11349@section Prompt
11350
11351@cindex prompt
11352
11353@value{GDBN} indicates its readiness to read a command by printing a string
11354called the @dfn{prompt}. This string is normally @samp{(@value{GDBP})}. You
11355can change the prompt string with the @code{set prompt} command. For
11356instance, when debugging @value{GDBN} with @value{GDBN}, it is useful to change
5d161b24 11357the prompt in one of the @value{GDBN} sessions so that you can always tell
c906108c
SS
11358which one you are talking to.
11359
d4f3574e 11360@emph{Note:} @code{set prompt} does not add a space for you after the
c906108c
SS
11361prompt you set. This allows you to set a prompt which ends in a space
11362or a prompt that does not.
11363
11364@table @code
11365@kindex set prompt
11366@item set prompt @var{newprompt}
11367Directs @value{GDBN} to use @var{newprompt} as its prompt string henceforth.
11368
11369@kindex show prompt
11370@item show prompt
11371Prints a line of the form: @samp{Gdb's prompt is: @var{your-prompt}}
11372@end table
11373
6d2ebf8b 11374@node Editing
c906108c
SS
11375@section Command editing
11376@cindex readline
11377@cindex command line editing
11378
11379@value{GDBN} reads its input commands via the @dfn{readline} interface. This
11380@sc{gnu} library provides consistent behavior for programs which provide a
11381command line interface to the user. Advantages are @sc{gnu} Emacs-style
11382or @dfn{vi}-style inline editing of commands, @code{csh}-like history
11383substitution, and a storage and recall of command history across
11384debugging sessions.
11385
11386You may control the behavior of command line editing in @value{GDBN} with the
11387command @code{set}.
11388
11389@table @code
11390@kindex set editing
11391@cindex editing
11392@item set editing
11393@itemx set editing on
11394Enable command line editing (enabled by default).
11395
11396@item set editing off
11397Disable command line editing.
11398
11399@kindex show editing
11400@item show editing
11401Show whether command line editing is enabled.
11402@end table
11403
6d2ebf8b 11404@node History
c906108c
SS
11405@section Command history
11406
11407@value{GDBN} can keep track of the commands you type during your
11408debugging sessions, so that you can be certain of precisely what
11409happened. Use these commands to manage the @value{GDBN} command
11410history facility.
11411
11412@table @code
11413@cindex history substitution
11414@cindex history file
11415@kindex set history filename
11416@kindex GDBHISTFILE
11417@item set history filename @var{fname}
11418Set the name of the @value{GDBN} command history file to @var{fname}.
11419This is the file where @value{GDBN} reads an initial command history
11420list, and where it writes the command history from this session when it
11421exits. You can access this list through history expansion or through
11422the history command editing characters listed below. This file defaults
11423to the value of the environment variable @code{GDBHISTFILE}, or to
d4f3574e
SS
11424@file{./.gdb_history} (@file{./_gdb_history} on MS-DOS) if this variable
11425is not set.
c906108c
SS
11426
11427@cindex history save
11428@kindex set history save
11429@item set history save
11430@itemx set history save on
11431Record command history in a file, whose name may be specified with the
11432@code{set history filename} command. By default, this option is disabled.
11433
11434@item set history save off
11435Stop recording command history in a file.
11436
11437@cindex history size
11438@kindex set history size
11439@item set history size @var{size}
11440Set the number of commands which @value{GDBN} keeps in its history list.
11441This defaults to the value of the environment variable
11442@code{HISTSIZE}, or to 256 if this variable is not set.
11443@end table
11444
11445@cindex history expansion
11446History expansion assigns special meaning to the character @kbd{!}.
11447@ifset have-readline-appendices
11448@xref{Event Designators}.
11449@end ifset
11450
11451Since @kbd{!} is also the logical not operator in C, history expansion
11452is off by default. If you decide to enable history expansion with the
11453@code{set history expansion on} command, you may sometimes need to
11454follow @kbd{!} (when it is used as logical not, in an expression) with
11455a space or a tab to prevent it from being expanded. The readline
11456history facilities do not attempt substitution on the strings
11457@kbd{!=} and @kbd{!(}, even when history expansion is enabled.
11458
11459The commands to control history expansion are:
11460
11461@table @code
11462@kindex set history expansion
11463@item set history expansion on
11464@itemx set history expansion
11465Enable history expansion. History expansion is off by default.
11466
11467@item set history expansion off
11468Disable history expansion.
11469
11470The readline code comes with more complete documentation of
11471editing and history expansion features. Users unfamiliar with @sc{gnu} Emacs
11472or @code{vi} may wish to read it.
11473@ifset have-readline-appendices
11474@xref{Command Line Editing}.
11475@end ifset
11476
11477@c @group
11478@kindex show history
11479@item show history
11480@itemx show history filename
11481@itemx show history save
11482@itemx show history size
11483@itemx show history expansion
11484These commands display the state of the @value{GDBN} history parameters.
11485@code{show history} by itself displays all four states.
11486@c @end group
11487@end table
11488
11489@table @code
11490@kindex show commands
11491@item show commands
11492Display the last ten commands in the command history.
11493
11494@item show commands @var{n}
11495Print ten commands centered on command number @var{n}.
11496
11497@item show commands +
11498Print ten commands just after the commands last printed.
11499@end table
11500
6d2ebf8b 11501@node Screen Size
c906108c
SS
11502@section Screen size
11503@cindex size of screen
11504@cindex pauses in output
11505
11506Certain commands to @value{GDBN} may produce large amounts of
11507information output to the screen. To help you read all of it,
11508@value{GDBN} pauses and asks you for input at the end of each page of
11509output. Type @key{RET} when you want to continue the output, or @kbd{q}
11510to discard the remaining output. Also, the screen width setting
11511determines when to wrap lines of output. Depending on what is being
11512printed, @value{GDBN} tries to break the line at a readable place,
11513rather than simply letting it overflow onto the following line.
11514
d4f3574e
SS
11515Normally @value{GDBN} knows the size of the screen from the terminal
11516driver software. For example, on Unix @value{GDBN} uses the termcap data base
c906108c 11517together with the value of the @code{TERM} environment variable and the
d4f3574e 11518@code{stty rows} and @code{stty cols} settings. If this is not correct,
c906108c
SS
11519you can override it with the @code{set height} and @code{set
11520width} commands:
11521
11522@table @code
11523@kindex set height
11524@kindex set width
11525@kindex show width
11526@kindex show height
11527@item set height @var{lpp}
11528@itemx show height
11529@itemx set width @var{cpl}
11530@itemx show width
11531These @code{set} commands specify a screen height of @var{lpp} lines and
11532a screen width of @var{cpl} characters. The associated @code{show}
11533commands display the current settings.
11534
5d161b24
DB
11535If you specify a height of zero lines, @value{GDBN} does not pause during
11536output no matter how long the output is. This is useful if output is to a
c906108c
SS
11537file or to an editor buffer.
11538
11539Likewise, you can specify @samp{set width 0} to prevent @value{GDBN}
11540from wrapping its output.
11541@end table
11542
6d2ebf8b 11543@node Numbers
c906108c
SS
11544@section Numbers
11545@cindex number representation
11546@cindex entering numbers
11547
2df3850c
JM
11548You can always enter numbers in octal, decimal, or hexadecimal in
11549@value{GDBN} by the usual conventions: octal numbers begin with
11550@samp{0}, decimal numbers end with @samp{.}, and hexadecimal numbers
11551begin with @samp{0x}. Numbers that begin with none of these are, by
11552default, entered in base 10; likewise, the default display for
11553numbers---when no particular format is specified---is base 10. You can
11554change the default base for both input and output with the @code{set
11555radix} command.
c906108c
SS
11556
11557@table @code
11558@kindex set input-radix
11559@item set input-radix @var{base}
11560Set the default base for numeric input. Supported choices
11561for @var{base} are decimal 8, 10, or 16. @var{base} must itself be
11562specified either unambiguously or using the current default radix; for
11563example, any of
11564
11565@smallexample
11566set radix 012
11567set radix 10.
11568set radix 0xa
11569@end smallexample
11570
11571@noindent
11572sets the base to decimal. On the other hand, @samp{set radix 10}
11573leaves the radix unchanged no matter what it was.
11574
11575@kindex set output-radix
11576@item set output-radix @var{base}
11577Set the default base for numeric display. Supported choices
11578for @var{base} are decimal 8, 10, or 16. @var{base} must itself be
11579specified either unambiguously or using the current default radix.
11580
11581@kindex show input-radix
11582@item show input-radix
11583Display the current default base for numeric input.
11584
11585@kindex show output-radix
11586@item show output-radix
11587Display the current default base for numeric display.
11588@end table
11589
6d2ebf8b 11590@node Messages/Warnings
c906108c
SS
11591@section Optional warnings and messages
11592
2df3850c
JM
11593By default, @value{GDBN} is silent about its inner workings. If you are
11594running on a slow machine, you may want to use the @code{set verbose}
11595command. This makes @value{GDBN} tell you when it does a lengthy
11596internal operation, so you will not think it has crashed.
c906108c
SS
11597
11598Currently, the messages controlled by @code{set verbose} are those
11599which announce that the symbol table for a source file is being read;
11600see @code{symbol-file} in @ref{Files, ,Commands to specify files}.
11601
11602@table @code
11603@kindex set verbose
11604@item set verbose on
11605Enables @value{GDBN} output of certain informational messages.
11606
11607@item set verbose off
11608Disables @value{GDBN} output of certain informational messages.
11609
11610@kindex show verbose
11611@item show verbose
11612Displays whether @code{set verbose} is on or off.
11613@end table
11614
2df3850c
JM
11615By default, if @value{GDBN} encounters bugs in the symbol table of an
11616object file, it is silent; but if you are debugging a compiler, you may
11617find this information useful (@pxref{Symbol Errors, ,Errors reading
11618symbol files}).
c906108c
SS
11619
11620@table @code
2df3850c 11621
c906108c
SS
11622@kindex set complaints
11623@item set complaints @var{limit}
2df3850c
JM
11624Permits @value{GDBN} to output @var{limit} complaints about each type of
11625unusual symbols before becoming silent about the problem. Set
11626@var{limit} to zero to suppress all complaints; set it to a large number
11627to prevent complaints from being suppressed.
c906108c
SS
11628
11629@kindex show complaints
11630@item show complaints
11631Displays how many symbol complaints @value{GDBN} is permitted to produce.
2df3850c 11632
c906108c
SS
11633@end table
11634
11635By default, @value{GDBN} is cautious, and asks what sometimes seems to be a
11636lot of stupid questions to confirm certain commands. For example, if
11637you try to run a program which is already running:
11638
11639@example
11640(@value{GDBP}) run
11641The program being debugged has been started already.
11642Start it from the beginning? (y or n)
11643@end example
11644
11645If you are willing to unflinchingly face the consequences of your own
11646commands, you can disable this ``feature'':
11647
11648@table @code
2df3850c 11649
c906108c
SS
11650@kindex set confirm
11651@cindex flinching
11652@cindex confirmation
11653@cindex stupid questions
11654@item set confirm off
11655Disables confirmation requests.
11656
11657@item set confirm on
11658Enables confirmation requests (the default).
11659
11660@kindex show confirm
11661@item show confirm
11662Displays state of confirmation requests.
2df3850c 11663
c906108c
SS
11664@end table
11665
6d2ebf8b 11666@node Debugging Output
5d161b24
DB
11667@section Optional messages about internal happenings
11668@table @code
11669@kindex set debug arch
11670@item set debug arch
11671Turns on or off display of gdbarch debugging info. The default is off
11672@kindex show debug arch
11673@item show debug arch
11674Displays the current state of displaying gdbarch debugging info.
11675@kindex set debug event
11676@item set debug event
11677Turns on or off display of @value{GDBN} event debugging info. The
11678default is off.
11679@kindex show debug event
11680@item show debug event
11681Displays the current state of displaying @value{GDBN} event debugging
11682info.
11683@kindex set debug expression
11684@item set debug expression
11685Turns on or off display of @value{GDBN} expression debugging info. The
11686default is off.
11687@kindex show debug expression
11688@item show debug expression
11689Displays the current state of displaying @value{GDBN} expression
11690debugging info.
11691@kindex set debug overload
11692@item set debug overload
11693Turns on or off display of @value{GDBN} C++ overload debugging
11694info. This includes info such as ranking of functions, etc. The default
11695is off.
11696@kindex show debug overload
11697@item show debug overload
11698Displays the current state of displaying @value{GDBN} C++ overload
11699debugging info.
11700@kindex set debug remote
11701@cindex packets, reporting on stdout
11702@cindex serial connections, debugging
11703@item set debug remote
11704Turns on or off display of reports on all packets sent back and forth across
11705the serial line to the remote machine. The info is printed on the
11706@value{GDBN} standard output stream. The default is off.
11707@kindex show debug remote
11708@item show debug remote
11709Displays the state of display of remote packets.
11710@kindex set debug serial
11711@item set debug serial
11712Turns on or off display of @value{GDBN} serial debugging info. The
11713default is off.
11714@kindex show debug serial
11715@item show debug serial
11716Displays the current state of displaying @value{GDBN} serial debugging
11717info.
11718@kindex set debug target
11719@item set debug target
11720Turns on or off display of @value{GDBN} target debugging info. This info
11721includes what is going on at the target level of GDB, as it happens. The
11722default is off.
11723@kindex show debug target
11724@item show debug target
11725Displays the current state of displaying @value{GDBN} target debugging
11726info.
11727@kindex set debug varobj
11728@item set debug varobj
11729Turns on or off display of @value{GDBN} variable object debugging
11730info. The default is off.
11731@kindex show debug varobj
11732@item show debug varobj
11733Displays the current state of displaying @value{GDBN} variable object
11734debugging info.
11735@end table
11736
6d2ebf8b 11737@node Sequences
c906108c
SS
11738@chapter Canned Sequences of Commands
11739
11740Aside from breakpoint commands (@pxref{Break Commands, ,Breakpoint
2df3850c
JM
11741command lists}), @value{GDBN} provides two ways to store sequences of
11742commands for execution as a unit: user-defined commands and command
11743files.
c906108c
SS
11744
11745@menu
11746* Define:: User-defined commands
11747* Hooks:: User-defined command hooks
11748* Command Files:: Command files
11749* Output:: Commands for controlled output
11750@end menu
11751
6d2ebf8b 11752@node Define
c906108c
SS
11753@section User-defined commands
11754
11755@cindex user-defined command
2df3850c
JM
11756A @dfn{user-defined command} is a sequence of @value{GDBN} commands to
11757which you assign a new name as a command. This is done with the
11758@code{define} command. User commands may accept up to 10 arguments
11759separated by whitespace. Arguments are accessed within the user command
11760via @var{$arg0@dots{}$arg9}. A trivial example:
c906108c
SS
11761
11762@smallexample
11763define adder
11764 print $arg0 + $arg1 + $arg2
11765@end smallexample
11766
d4f3574e
SS
11767@noindent
11768To execute the command use:
c906108c
SS
11769
11770@smallexample
11771adder 1 2 3
11772@end smallexample
11773
d4f3574e
SS
11774@noindent
11775This defines the command @code{adder}, which prints the sum of
5d161b24 11776its three arguments. Note the arguments are text substitutions, so they may
c906108c
SS
11777reference variables, use complex expressions, or even perform inferior
11778functions calls.
11779
11780@table @code
2df3850c 11781
c906108c
SS
11782@kindex define
11783@item define @var{commandname}
11784Define a command named @var{commandname}. If there is already a command
11785by that name, you are asked to confirm that you want to redefine it.
11786
11787The definition of the command is made up of other @value{GDBN} command lines,
11788which are given following the @code{define} command. The end of these
11789commands is marked by a line containing @code{end}.
11790
11791@kindex if
11792@kindex else
11793@item if
11794Takes a single argument, which is an expression to evaluate.
11795It is followed by a series of commands that are executed
11796only if the expression is true (nonzero).
11797There can then optionally be a line @code{else}, followed
11798by a series of commands that are only executed if the expression
11799was false. The end of the list is marked by a line containing @code{end}.
11800
11801@kindex while
11802@item while
11803The syntax is similar to @code{if}: the command takes a single argument,
11804which is an expression to evaluate, and must be followed by the commands to
11805execute, one per line, terminated by an @code{end}.
11806The commands are executed repeatedly as long as the expression
11807evaluates to true.
11808
11809@kindex document
11810@item document @var{commandname}
11811Document the user-defined command @var{commandname}, so that it can be
5d161b24
DB
11812accessed by @code{help}. The command @var{commandname} must already be
11813defined. This command reads lines of documentation just as @code{define}
11814reads the lines of the command definition, ending with @code{end}.
11815After the @code{document} command is finished, @code{help} on command
c906108c
SS
11816@var{commandname} displays the documentation you have written.
11817
11818You may use the @code{document} command again to change the
11819documentation of a command. Redefining the command with @code{define}
11820does not change the documentation.
11821
11822@kindex help user-defined
11823@item help user-defined
11824List all user-defined commands, with the first line of the documentation
11825(if any) for each.
11826
11827@kindex show user
11828@item show user
11829@itemx show user @var{commandname}
2df3850c
JM
11830Display the @value{GDBN} commands used to define @var{commandname} (but
11831not its documentation). If no @var{commandname} is given, display the
c906108c 11832definitions for all user-defined commands.
2df3850c 11833
c906108c
SS
11834@end table
11835
11836When user-defined commands are executed, the
11837commands of the definition are not printed. An error in any command
11838stops execution of the user-defined command.
11839
11840If used interactively, commands that would ask for confirmation proceed
5d161b24
DB
11841without asking when used inside a user-defined command. Many @value{GDBN}
11842commands that normally print messages to say what they are doing omit the
c906108c
SS
11843messages when used in a user-defined command.
11844
6d2ebf8b 11845@node Hooks
c906108c 11846@section User-defined command hooks
d4f3574e
SS
11847@cindex command hooks
11848@cindex hooks, for commands
c906108c
SS
11849
11850You may define @emph{hooks}, which are a special kind of user-defined
11851command. Whenever you run the command @samp{foo}, if the user-defined
11852command @samp{hook-foo} exists, it is executed (with no arguments)
11853before that command.
11854
d4f3574e 11855@kindex stop@r{, a pseudo-command}
c906108c
SS
11856In addition, a pseudo-command, @samp{stop} exists. Defining
11857(@samp{hook-stop}) makes the associated commands execute every time
11858execution stops in your program: before breakpoint commands are run,
11859displays are printed, or the stack frame is printed.
11860
c906108c
SS
11861For example, to ignore @code{SIGALRM} signals while
11862single-stepping, but treat them normally during normal execution,
11863you could define:
11864
11865@example
11866define hook-stop
11867handle SIGALRM nopass
11868end
11869
11870define hook-run
11871handle SIGALRM pass
11872end
11873
11874define hook-continue
11875handle SIGLARM pass
11876end
11877@end example
c906108c
SS
11878
11879You can define a hook for any single-word command in @value{GDBN}, but
11880not for command aliases; you should define a hook for the basic command
11881name, e.g. @code{backtrace} rather than @code{bt}.
11882@c FIXME! So how does Joe User discover whether a command is an alias
11883@c or not?
11884If an error occurs during the execution of your hook, execution of
11885@value{GDBN} commands stops and @value{GDBN} issues a prompt
11886(before the command that you actually typed had a chance to run).
11887
11888If you try to define a hook which does not match any known command, you
11889get a warning from the @code{define} command.
11890
6d2ebf8b 11891@node Command Files
c906108c
SS
11892@section Command files
11893
11894@cindex command files
5d161b24
DB
11895A command file for @value{GDBN} is a file of lines that are @value{GDBN}
11896commands. Comments (lines starting with @kbd{#}) may also be included.
11897An empty line in a command file does nothing; it does not mean to repeat
c906108c
SS
11898the last command, as it would from the terminal.
11899
11900@cindex init file
11901@cindex @file{.gdbinit}
d4f3574e 11902@cindex @file{gdb.ini}
c906108c
SS
11903When you start @value{GDBN}, it automatically executes commands from its
11904@dfn{init files}. These are files named @file{.gdbinit} on Unix, or
11905@file{gdb.ini} on DOS/Windows. @value{GDBN} reads the init file (if
d4f3574e 11906any) in your home directory@footnote{On DOS/Windows systems, the home
2df3850c
JM
11907directory is the one pointed to by the @code{HOME} environment
11908variable.}, then processes command line options and operands, and then
11909reads the init file (if any) in the current working directory. This is
11910so the init file in your home directory can set options (such as
11911@code{set complaints}) which affect the processing of the command line
11912options and operands. The init files are not executed if you use the
11913@samp{-nx} option; @pxref{Mode Options, ,Choosing modes}.
c906108c 11914
c906108c
SS
11915@cindex init file name
11916On some configurations of @value{GDBN}, the init file is known by a
11917different name (these are typically environments where a specialized
11918form of @value{GDBN} may need to coexist with other forms, hence a
11919different name for the specialized version's init file). These are the
11920environments with special init file names:
11921
00e4a2e4 11922@cindex @file{.vxgdbinit}
c906108c
SS
11923@itemize @bullet
11924@item
00e4a2e4 11925VxWorks (Wind River Systems real-time OS): @file{.vxgdbinit}
c906108c 11926
00e4a2e4 11927@cindex @file{.os68gdbinit}
c906108c 11928@item
00e4a2e4 11929OS68K (Enea Data Systems real-time OS): @file{.os68gdbinit}
c906108c 11930
00e4a2e4 11931@cindex @file{.esgdbinit}
c906108c 11932@item
00e4a2e4 11933ES-1800 (Ericsson Telecom AB M68000 emulator): @file{.esgdbinit}
c906108c 11934@end itemize
c906108c
SS
11935
11936You can also request the execution of a command file with the
11937@code{source} command:
11938
11939@table @code
11940@kindex source
11941@item source @var{filename}
11942Execute the command file @var{filename}.
11943@end table
11944
11945The lines in a command file are executed sequentially. They are not
11946printed as they are executed. An error in any command terminates execution
11947of the command file.
11948
11949Commands that would ask for confirmation if used interactively proceed
11950without asking when used in a command file. Many @value{GDBN} commands that
11951normally print messages to say what they are doing omit the messages
11952when called from command files.
11953
6d2ebf8b 11954@node Output
c906108c
SS
11955@section Commands for controlled output
11956
11957During the execution of a command file or a user-defined command, normal
11958@value{GDBN} output is suppressed; the only output that appears is what is
11959explicitly printed by the commands in the definition. This section
11960describes three commands useful for generating exactly the output you
11961want.
11962
11963@table @code
11964@kindex echo
11965@item echo @var{text}
11966@c I do not consider backslash-space a standard C escape sequence
11967@c because it is not in ANSI.
11968Print @var{text}. Nonprinting characters can be included in
11969@var{text} using C escape sequences, such as @samp{\n} to print a
11970newline. @strong{No newline is printed unless you specify one.}
11971In addition to the standard C escape sequences, a backslash followed
11972by a space stands for a space. This is useful for displaying a
11973string with spaces at the beginning or the end, since leading and
5d161b24 11974trailing spaces are otherwise trimmed from all arguments.
c906108c
SS
11975To print @samp{@w{ }and foo =@w{ }}, use the command
11976@samp{echo \@w{ }and foo = \@w{ }}.
11977
11978A backslash at the end of @var{text} can be used, as in C, to continue
11979the command onto subsequent lines. For example,
11980
11981@example
11982echo This is some text\n\
11983which is continued\n\
11984onto several lines.\n
11985@end example
11986
11987produces the same output as
11988
11989@example
11990echo This is some text\n
11991echo which is continued\n
11992echo onto several lines.\n
11993@end example
11994
11995@kindex output
11996@item output @var{expression}
11997Print the value of @var{expression} and nothing but that value: no
11998newlines, no @samp{$@var{nn} = }. The value is not entered in the
5d161b24 11999value history either. @xref{Expressions, ,Expressions}, for more information
c906108c
SS
12000on expressions.
12001
12002@item output/@var{fmt} @var{expression}
12003Print the value of @var{expression} in format @var{fmt}. You can use
12004the same formats as for @code{print}. @xref{Output Formats,,Output
12005formats}, for more information.
12006
12007@kindex printf
12008@item printf @var{string}, @var{expressions}@dots{}
12009Print the values of the @var{expressions} under the control of
12010@var{string}. The @var{expressions} are separated by commas and may be
12011either numbers or pointers. Their values are printed as specified by
12012@var{string}, exactly as if your program were to execute the C
12013subroutine
d4f3574e
SS
12014@c FIXME: the above implies that at least all ANSI C formats are
12015@c supported, but it isn't true: %E and %G don't work (or so it seems).
12016@c Either this is a bug, or the manual should document what formats are
12017@c supported.
c906108c
SS
12018
12019@example
12020printf (@var{string}, @var{expressions}@dots{});
12021@end example
12022
12023For example, you can print two values in hex like this:
12024
12025@smallexample
12026printf "foo, bar-foo = 0x%x, 0x%x\n", foo, bar-foo
12027@end smallexample
12028
12029The only backslash-escape sequences that you can use in the format
12030string are the simple ones that consist of backslash followed by a
12031letter.
12032@end table
12033
6d2ebf8b 12034@node Emacs
c906108c
SS
12035@chapter Using @value{GDBN} under @sc{gnu} Emacs
12036
12037@cindex Emacs
12038@cindex @sc{gnu} Emacs
12039A special interface allows you to use @sc{gnu} Emacs to view (and
12040edit) the source files for the program you are debugging with
12041@value{GDBN}.
12042
12043To use this interface, use the command @kbd{M-x gdb} in Emacs. Give the
12044executable file you want to debug as an argument. This command starts
12045@value{GDBN} as a subprocess of Emacs, with input and output through a newly
12046created Emacs buffer.
53a5351d 12047@c (Do not use the @code{-tui} option to run @value{GDBN} from Emacs.)
c906108c
SS
12048
12049Using @value{GDBN} under Emacs is just like using @value{GDBN} normally except for two
12050things:
12051
12052@itemize @bullet
12053@item
12054All ``terminal'' input and output goes through the Emacs buffer.
12055@end itemize
12056
12057This applies both to @value{GDBN} commands and their output, and to the input
12058and output done by the program you are debugging.
12059
12060This is useful because it means that you can copy the text of previous
12061commands and input them again; you can even use parts of the output
12062in this way.
12063
12064All the facilities of Emacs' Shell mode are available for interacting
12065with your program. In particular, you can send signals the usual
12066way---for example, @kbd{C-c C-c} for an interrupt, @kbd{C-c C-z} for a
12067stop.
12068
12069@itemize @bullet
12070@item
12071@value{GDBN} displays source code through Emacs.
12072@end itemize
12073
12074Each time @value{GDBN} displays a stack frame, Emacs automatically finds the
12075source file for that frame and puts an arrow (@samp{=>}) at the
12076left margin of the current line. Emacs uses a separate buffer for
12077source display, and splits the screen to show both your @value{GDBN} session
12078and the source.
12079
12080Explicit @value{GDBN} @code{list} or search commands still produce output as
12081usual, but you probably have no reason to use them from Emacs.
12082
12083@quotation
12084@emph{Warning:} If the directory where your program resides is not your
12085current directory, it can be easy to confuse Emacs about the location of
12086the source files, in which case the auxiliary display buffer does not
12087appear to show your source. @value{GDBN} can find programs by searching your
12088environment's @code{PATH} variable, so the @value{GDBN} input and output
12089session proceeds normally; but Emacs does not get enough information
12090back from @value{GDBN} to locate the source files in this situation. To
12091avoid this problem, either start @value{GDBN} mode from the directory where
12092your program resides, or specify an absolute file name when prompted for the
12093@kbd{M-x gdb} argument.
12094
12095A similar confusion can result if you use the @value{GDBN} @code{file} command to
12096switch to debugging a program in some other location, from an existing
12097@value{GDBN} buffer in Emacs.
12098@end quotation
12099
12100By default, @kbd{M-x gdb} calls the program called @file{gdb}. If
12101you need to call @value{GDBN} by a different name (for example, if you keep
12102several configurations around, with different names) you can set the
12103Emacs variable @code{gdb-command-name}; for example,
12104
12105@example
12106(setq gdb-command-name "mygdb")
12107@end example
12108
12109@noindent
d4f3574e 12110(preceded by @kbd{M-:} or @kbd{ESC :}, or typed in the @code{*scratch*} buffer, or
c906108c
SS
12111in your @file{.emacs} file) makes Emacs call the program named
12112``@code{mygdb}'' instead.
12113
12114In the @value{GDBN} I/O buffer, you can use these special Emacs commands in
12115addition to the standard Shell mode commands:
12116
12117@table @kbd
12118@item C-h m
12119Describe the features of Emacs' @value{GDBN} Mode.
12120
12121@item M-s
12122Execute to another source line, like the @value{GDBN} @code{step} command; also
12123update the display window to show the current file and location.
12124
12125@item M-n
12126Execute to next source line in this function, skipping all function
12127calls, like the @value{GDBN} @code{next} command. Then update the display window
12128to show the current file and location.
12129
12130@item M-i
12131Execute one instruction, like the @value{GDBN} @code{stepi} command; update
12132display window accordingly.
12133
12134@item M-x gdb-nexti
12135Execute to next instruction, using the @value{GDBN} @code{nexti} command; update
12136display window accordingly.
12137
12138@item C-c C-f
12139Execute until exit from the selected stack frame, like the @value{GDBN}
12140@code{finish} command.
12141
12142@item M-c
12143Continue execution of your program, like the @value{GDBN} @code{continue}
12144command.
12145
12146@emph{Warning:} In Emacs v19, this command is @kbd{C-c C-p}.
12147
12148@item M-u
12149Go up the number of frames indicated by the numeric argument
12150(@pxref{Arguments, , Numeric Arguments, Emacs, The @sc{gnu} Emacs Manual}),
12151like the @value{GDBN} @code{up} command.
12152
12153@emph{Warning:} In Emacs v19, this command is @kbd{C-c C-u}.
12154
12155@item M-d
12156Go down the number of frames indicated by the numeric argument, like the
12157@value{GDBN} @code{down} command.
12158
12159@emph{Warning:} In Emacs v19, this command is @kbd{C-c C-d}.
12160
12161@item C-x &
12162Read the number where the cursor is positioned, and insert it at the end
12163of the @value{GDBN} I/O buffer. For example, if you wish to disassemble code
12164around an address that was displayed earlier, type @kbd{disassemble};
12165then move the cursor to the address display, and pick up the
12166argument for @code{disassemble} by typing @kbd{C-x &}.
12167
12168You can customize this further by defining elements of the list
12169@code{gdb-print-command}; once it is defined, you can format or
12170otherwise process numbers picked up by @kbd{C-x &} before they are
12171inserted. A numeric argument to @kbd{C-x &} indicates that you
12172wish special formatting, and also acts as an index to pick an element of the
12173list. If the list element is a string, the number to be inserted is
12174formatted using the Emacs function @code{format}; otherwise the number
12175is passed as an argument to the corresponding list element.
12176@end table
12177
12178In any source file, the Emacs command @kbd{C-x SPC} (@code{gdb-break})
12179tells @value{GDBN} to set a breakpoint on the source line point is on.
12180
12181If you accidentally delete the source-display buffer, an easy way to get
12182it back is to type the command @code{f} in the @value{GDBN} buffer, to
12183request a frame display; when you run under Emacs, this recreates
12184the source buffer if necessary to show you the context of the current
12185frame.
12186
12187The source files displayed in Emacs are in ordinary Emacs buffers
12188which are visiting the source files in the usual way. You can edit
12189the files with these buffers if you wish; but keep in mind that @value{GDBN}
12190communicates with Emacs in terms of line numbers. If you add or
12191delete lines from the text, the line numbers that @value{GDBN} knows cease
12192to correspond properly with the code.
12193
12194@c The following dropped because Epoch is nonstandard. Reactivate
12195@c if/when v19 does something similar. ---doc@cygnus.com 19dec1990
12196@ignore
12197@kindex Emacs Epoch environment
12198@kindex Epoch
12199@kindex inspect
12200
5d161b24 12201Version 18 of @sc{gnu} Emacs has a built-in window system
c906108c
SS
12202called the @code{epoch}
12203environment. Users of this environment can use a new command,
12204@code{inspect} which performs identically to @code{print} except that
12205each value is printed in its own window.
12206@end ignore
c906108c 12207
d700128c 12208@include annotate.texi
7162c0ca 12209@include gdbmi.texinfo
d700128c 12210
6d2ebf8b 12211@node GDB Bugs
c906108c
SS
12212@chapter Reporting Bugs in @value{GDBN}
12213@cindex bugs in @value{GDBN}
12214@cindex reporting bugs in @value{GDBN}
12215
12216Your bug reports play an essential role in making @value{GDBN} reliable.
12217
12218Reporting a bug may help you by bringing a solution to your problem, or it
12219may not. But in any case the principal function of a bug report is to help
12220the entire community by making the next version of @value{GDBN} work better. Bug
12221reports are your contribution to the maintenance of @value{GDBN}.
12222
12223In order for a bug report to serve its purpose, you must include the
12224information that enables us to fix the bug.
12225
12226@menu
12227* Bug Criteria:: Have you found a bug?
12228* Bug Reporting:: How to report bugs
12229@end menu
12230
6d2ebf8b 12231@node Bug Criteria
c906108c
SS
12232@section Have you found a bug?
12233@cindex bug criteria
12234
12235If you are not sure whether you have found a bug, here are some guidelines:
12236
12237@itemize @bullet
12238@cindex fatal signal
12239@cindex debugger crash
12240@cindex crash of debugger
12241@item
12242If the debugger gets a fatal signal, for any input whatever, that is a
12243@value{GDBN} bug. Reliable debuggers never crash.
12244
12245@cindex error on valid input
12246@item
12247If @value{GDBN} produces an error message for valid input, that is a
12248bug. (Note that if you're cross debugging, the problem may also be
12249somewhere in the connection to the target.)
12250
12251@cindex invalid input
12252@item
12253If @value{GDBN} does not produce an error message for invalid input,
12254that is a bug. However, you should note that your idea of
12255``invalid input'' might be our idea of ``an extension'' or ``support
12256for traditional practice''.
12257
12258@item
12259If you are an experienced user of debugging tools, your suggestions
12260for improvement of @value{GDBN} are welcome in any case.
12261@end itemize
12262
6d2ebf8b 12263@node Bug Reporting
c906108c
SS
12264@section How to report bugs
12265@cindex bug reports
12266@cindex @value{GDBN} bugs, reporting
12267
c906108c
SS
12268A number of companies and individuals offer support for @sc{gnu} products.
12269If you obtained @value{GDBN} from a support organization, we recommend you
12270contact that organization first.
12271
12272You can find contact information for many support companies and
12273individuals in the file @file{etc/SERVICE} in the @sc{gnu} Emacs
12274distribution.
12275@c should add a web page ref...
12276
12277In any event, we also recommend that you send bug reports for
12278@value{GDBN} to this addresses:
12279
12280@example
d4f3574e 12281bug-gdb@@gnu.org
c906108c
SS
12282@end example
12283
12284@strong{Do not send bug reports to @samp{info-gdb}, or to
d4f3574e 12285@samp{help-gdb}, or to any newsgroups.} Most users of @value{GDBN} do
c906108c
SS
12286not want to receive bug reports. Those that do have arranged to receive
12287@samp{bug-gdb}.
12288
12289The mailing list @samp{bug-gdb} has a newsgroup @samp{gnu.gdb.bug} which
12290serves as a repeater. The mailing list and the newsgroup carry exactly
12291the same messages. Often people think of posting bug reports to the
12292newsgroup instead of mailing them. This appears to work, but it has one
12293problem which can be crucial: a newsgroup posting often lacks a mail
12294path back to the sender. Thus, if we need to ask for more information,
12295we may be unable to reach you. For this reason, it is better to send
12296bug reports to the mailing list.
12297
12298As a last resort, send bug reports on paper to:
12299
12300@example
12301@sc{gnu} Debugger Bugs
12302Free Software Foundation Inc.
1230359 Temple Place - Suite 330
12304Boston, MA 02111-1307
12305USA
12306@end example
c906108c
SS
12307
12308The fundamental principle of reporting bugs usefully is this:
12309@strong{report all the facts}. If you are not sure whether to state a
12310fact or leave it out, state it!
12311
12312Often people omit facts because they think they know what causes the
12313problem and assume that some details do not matter. Thus, you might
12314assume that the name of the variable you use in an example does not matter.
12315Well, probably it does not, but one cannot be sure. Perhaps the bug is a
12316stray memory reference which happens to fetch from the location where that
12317name is stored in memory; perhaps, if the name were different, the contents
12318of that location would fool the debugger into doing the right thing despite
12319the bug. Play it safe and give a specific, complete example. That is the
12320easiest thing for you to do, and the most helpful.
12321
12322Keep in mind that the purpose of a bug report is to enable us to fix the
12323bug. It may be that the bug has been reported previously, but neither
12324you nor we can know that unless your bug report is complete and
12325self-contained.
12326
12327Sometimes people give a few sketchy facts and ask, ``Does this ring a
12328bell?'' Those bug reports are useless, and we urge everyone to
12329@emph{refuse to respond to them} except to chide the sender to report
12330bugs properly.
12331
12332To enable us to fix the bug, you should include all these things:
12333
12334@itemize @bullet
12335@item
12336The version of @value{GDBN}. @value{GDBN} announces it if you start
12337with no arguments; you can also print it at any time using @code{show
12338version}.
12339
12340Without this, we will not know whether there is any point in looking for
12341the bug in the current version of @value{GDBN}.
12342
12343@item
12344The type of machine you are using, and the operating system name and
12345version number.
12346
c906108c
SS
12347@item
12348What compiler (and its version) was used to compile @value{GDBN}---e.g.
12349``@value{GCC}--2.8.1''.
c906108c
SS
12350
12351@item
12352What compiler (and its version) was used to compile the program you are
12353debugging---e.g. ``@value{GCC}--2.8.1'', or ``HP92453-01 A.10.32.03 HP
12354C Compiler''. For GCC, you can say @code{gcc --version} to get this
12355information; for other compilers, see the documentation for those
12356compilers.
12357
12358@item
12359The command arguments you gave the compiler to compile your example and
12360observe the bug. For example, did you use @samp{-O}? To guarantee
12361you will not omit something important, list them all. A copy of the
12362Makefile (or the output from make) is sufficient.
12363
12364If we were to try to guess the arguments, we would probably guess wrong
12365and then we might not encounter the bug.
12366
12367@item
12368A complete input script, and all necessary source files, that will
12369reproduce the bug.
12370
12371@item
12372A description of what behavior you observe that you believe is
12373incorrect. For example, ``It gets a fatal signal.''
12374
12375Of course, if the bug is that @value{GDBN} gets a fatal signal, then we
12376will certainly notice it. But if the bug is incorrect output, we might
12377not notice unless it is glaringly wrong. You might as well not give us
12378a chance to make a mistake.
12379
12380Even if the problem you experience is a fatal signal, you should still
12381say so explicitly. Suppose something strange is going on, such as, your
12382copy of @value{GDBN} is out of synch, or you have encountered a bug in
12383the C library on your system. (This has happened!) Your copy might
12384crash and ours would not. If you told us to expect a crash, then when
12385ours fails to crash, we would know that the bug was not happening for
12386us. If you had not told us to expect a crash, then we would not be able
12387to draw any conclusion from our observations.
12388
c906108c
SS
12389@item
12390If you wish to suggest changes to the @value{GDBN} source, send us context
12391diffs. If you even discuss something in the @value{GDBN} source, refer to
12392it by context, not by line number.
12393
12394The line numbers in our development sources will not match those in your
12395sources. Your line numbers would convey no useful information to us.
53a5351d 12396
c906108c
SS
12397@end itemize
12398
12399Here are some things that are not necessary:
12400
12401@itemize @bullet
12402@item
12403A description of the envelope of the bug.
12404
12405Often people who encounter a bug spend a lot of time investigating
12406which changes to the input file will make the bug go away and which
12407changes will not affect it.
12408
12409This is often time consuming and not very useful, because the way we
12410will find the bug is by running a single example under the debugger
12411with breakpoints, not by pure deduction from a series of examples.
12412We recommend that you save your time for something else.
12413
12414Of course, if you can find a simpler example to report @emph{instead}
12415of the original one, that is a convenience for us. Errors in the
12416output will be easier to spot, running under the debugger will take
12417less time, and so on.
12418
12419However, simplification is not vital; if you do not want to do this,
12420report the bug anyway and send us the entire test case you used.
12421
12422@item
12423A patch for the bug.
12424
12425A patch for the bug does help us if it is a good one. But do not omit
12426the necessary information, such as the test case, on the assumption that
12427a patch is all we need. We might see problems with your patch and decide
12428to fix the problem another way, or we might not understand it at all.
12429
12430Sometimes with a program as complicated as @value{GDBN} it is very hard to
12431construct an example that will make the program follow a certain path
12432through the code. If you do not send us the example, we will not be able
12433to construct one, so we will not be able to verify that the bug is fixed.
12434
12435And if we cannot understand what bug you are trying to fix, or why your
12436patch should be an improvement, we will not install it. A test case will
12437help us to understand.
12438
12439@item
12440A guess about what the bug is or what it depends on.
12441
12442Such guesses are usually wrong. Even we cannot guess right about such
12443things without first using the debugger to find the facts.
12444@end itemize
12445
5d161b24 12446@c The readline documentation is distributed with the readline code
c906108c
SS
12447@c and consists of the two following files:
12448@c rluser.texinfo
7be570e7 12449@c inc-hist.texinfo
c906108c
SS
12450@c Use -I with makeinfo to point to the appropriate directory,
12451@c environment var TEXINPUTS with TeX.
12452@include rluser.texinfo
7be570e7 12453@include inc-hist.texinfo
c906108c
SS
12454
12455
6d2ebf8b 12456@node Formatting Documentation
c906108c
SS
12457@appendix Formatting Documentation
12458
12459@cindex @value{GDBN} reference card
12460@cindex reference card
12461The @value{GDBN} 4 release includes an already-formatted reference card, ready
12462for printing with PostScript or Ghostscript, in the @file{gdb}
12463subdirectory of the main source directory@footnote{In
12464@file{gdb-@value{GDBVN}/gdb/refcard.ps} of the version @value{GDBVN}
12465release.}. If you can use PostScript or Ghostscript with your printer,
12466you can print the reference card immediately with @file{refcard.ps}.
12467
12468The release also includes the source for the reference card. You
12469can format it, using @TeX{}, by typing:
12470
12471@example
12472make refcard.dvi
12473@end example
12474
5d161b24
DB
12475The @value{GDBN} reference card is designed to print in @dfn{landscape}
12476mode on US ``letter'' size paper;
c906108c
SS
12477that is, on a sheet 11 inches wide by 8.5 inches
12478high. You will need to specify this form of printing as an option to
12479your @sc{dvi} output program.
12480
12481@cindex documentation
12482
12483All the documentation for @value{GDBN} comes as part of the machine-readable
12484distribution. The documentation is written in Texinfo format, which is
12485a documentation system that uses a single source file to produce both
12486on-line information and a printed manual. You can use one of the Info
12487formatting commands to create the on-line version of the documentation
12488and @TeX{} (or @code{texi2roff}) to typeset the printed version.
12489
12490@value{GDBN} includes an already formatted copy of the on-line Info
12491version of this manual in the @file{gdb} subdirectory. The main Info
12492file is @file{gdb-@value{GDBVN}/gdb/gdb.info}, and it refers to
12493subordinate files matching @samp{gdb.info*} in the same directory. If
12494necessary, you can print out these files, or read them with any editor;
12495but they are easier to read using the @code{info} subsystem in @sc{gnu}
12496Emacs or the standalone @code{info} program, available as part of the
12497@sc{gnu} Texinfo distribution.
12498
12499If you want to format these Info files yourself, you need one of the
12500Info formatting programs, such as @code{texinfo-format-buffer} or
12501@code{makeinfo}.
12502
12503If you have @code{makeinfo} installed, and are in the top level
12504@value{GDBN} source directory (@file{gdb-@value{GDBVN}}, in the case of
12505version @value{GDBVN}), you can make the Info file by typing:
12506
12507@example
12508cd gdb
12509make gdb.info
12510@end example
12511
12512If you want to typeset and print copies of this manual, you need @TeX{},
12513a program to print its @sc{dvi} output files, and @file{texinfo.tex}, the
12514Texinfo definitions file.
12515
12516@TeX{} is a typesetting program; it does not print files directly, but
12517produces output files called @sc{dvi} files. To print a typeset
12518document, you need a program to print @sc{dvi} files. If your system
12519has @TeX{} installed, chances are it has such a program. The precise
12520command to use depends on your system; @kbd{lpr -d} is common; another
12521(for PostScript devices) is @kbd{dvips}. The @sc{dvi} print command may
12522require a file name without any extension or a @samp{.dvi} extension.
12523
12524@TeX{} also requires a macro definitions file called
12525@file{texinfo.tex}. This file tells @TeX{} how to typeset a document
12526written in Texinfo format. On its own, @TeX{} cannot either read or
12527typeset a Texinfo file. @file{texinfo.tex} is distributed with GDB
12528and is located in the @file{gdb-@var{version-number}/texinfo}
12529directory.
12530
12531If you have @TeX{} and a @sc{dvi} printer program installed, you can
12532typeset and print this manual. First switch to the the @file{gdb}
12533subdirectory of the main source directory (for example, to
12534@file{gdb-@value{GDBVN}/gdb}) and type:
12535
12536@example
12537make gdb.dvi
12538@end example
12539
12540Then give @file{gdb.dvi} to your @sc{dvi} printing program.
c906108c 12541
6d2ebf8b 12542@node Installing GDB
c906108c
SS
12543@appendix Installing @value{GDBN}
12544@cindex configuring @value{GDBN}
12545@cindex installation
12546
c906108c
SS
12547@value{GDBN} comes with a @code{configure} script that automates the process
12548of preparing @value{GDBN} for installation; you can then use @code{make} to
12549build the @code{gdb} program.
12550@iftex
12551@c irrelevant in info file; it's as current as the code it lives with.
12552@footnote{If you have a more recent version of @value{GDBN} than @value{GDBVN},
12553look at the @file{README} file in the sources; we may have improved the
12554installation procedures since publishing this manual.}
12555@end iftex
12556
5d161b24
DB
12557The @value{GDBN} distribution includes all the source code you need for
12558@value{GDBN} in a single directory, whose name is usually composed by
c906108c
SS
12559appending the version number to @samp{gdb}.
12560
12561For example, the @value{GDBN} version @value{GDBVN} distribution is in the
12562@file{gdb-@value{GDBVN}} directory. That directory contains:
12563
12564@table @code
12565@item gdb-@value{GDBVN}/configure @r{(and supporting files)}
12566script for configuring @value{GDBN} and all its supporting libraries
12567
12568@item gdb-@value{GDBVN}/gdb
12569the source specific to @value{GDBN} itself
12570
12571@item gdb-@value{GDBVN}/bfd
12572source for the Binary File Descriptor library
12573
12574@item gdb-@value{GDBVN}/include
12575@sc{gnu} include files
12576
12577@item gdb-@value{GDBVN}/libiberty
12578source for the @samp{-liberty} free software library
12579
12580@item gdb-@value{GDBVN}/opcodes
12581source for the library of opcode tables and disassemblers
12582
12583@item gdb-@value{GDBVN}/readline
12584source for the @sc{gnu} command-line interface
12585
12586@item gdb-@value{GDBVN}/glob
12587source for the @sc{gnu} filename pattern-matching subroutine
12588
12589@item gdb-@value{GDBVN}/mmalloc
12590source for the @sc{gnu} memory-mapped malloc package
12591@end table
12592
12593The simplest way to configure and build @value{GDBN} is to run @code{configure}
12594from the @file{gdb-@var{version-number}} source directory, which in
12595this example is the @file{gdb-@value{GDBVN}} directory.
12596
12597First switch to the @file{gdb-@var{version-number}} source directory
12598if you are not already in it; then run @code{configure}. Pass the
12599identifier for the platform on which @value{GDBN} will run as an
12600argument.
12601
12602For example:
12603
12604@example
12605cd gdb-@value{GDBVN}
12606./configure @var{host}
12607make
12608@end example
12609
12610@noindent
12611where @var{host} is an identifier such as @samp{sun4} or
12612@samp{decstation}, that identifies the platform where @value{GDBN} will run.
12613(You can often leave off @var{host}; @code{configure} tries to guess the
12614correct value by examining your system.)
12615
12616Running @samp{configure @var{host}} and then running @code{make} builds the
12617@file{bfd}, @file{readline}, @file{mmalloc}, and @file{libiberty}
12618libraries, then @code{gdb} itself. The configured source files, and the
12619binaries, are left in the corresponding source directories.
12620
12621@need 750
12622@code{configure} is a Bourne-shell (@code{/bin/sh}) script; if your
12623system does not recognize this automatically when you run a different
12624shell, you may need to run @code{sh} on it explicitly:
12625
12626@example
12627sh configure @var{host}
12628@end example
12629
12630If you run @code{configure} from a directory that contains source
12631directories for multiple libraries or programs, such as the
12632@file{gdb-@value{GDBVN}} source directory for version @value{GDBVN}, @code{configure}
12633creates configuration files for every directory level underneath (unless
12634you tell it not to, with the @samp{--norecursion} option).
12635
12636You can run the @code{configure} script from any of the
12637subordinate directories in the @value{GDBN} distribution if you only want to
12638configure that subdirectory, but be sure to specify a path to it.
12639
12640For example, with version @value{GDBVN}, type the following to configure only
12641the @code{bfd} subdirectory:
12642
12643@example
12644@group
12645cd gdb-@value{GDBVN}/bfd
12646../configure @var{host}
12647@end group
12648@end example
12649
12650You can install @code{@value{GDBP}} anywhere; it has no hardwired paths.
12651However, you should make sure that the shell on your path (named by
12652the @samp{SHELL} environment variable) is publicly readable. Remember
12653that @value{GDBN} uses the shell to start your program---some systems refuse to
12654let @value{GDBN} debug child processes whose programs are not readable.
12655
12656@menu
12657* Separate Objdir:: Compiling @value{GDBN} in another directory
12658* Config Names:: Specifying names for hosts and targets
12659* Configure Options:: Summary of options for configure
12660@end menu
12661
6d2ebf8b 12662@node Separate Objdir
c906108c
SS
12663@section Compiling @value{GDBN} in another directory
12664
12665If you want to run @value{GDBN} versions for several host or target machines,
12666you need a different @code{gdb} compiled for each combination of
12667host and target. @code{configure} is designed to make this easy by
12668allowing you to generate each configuration in a separate subdirectory,
12669rather than in the source directory. If your @code{make} program
12670handles the @samp{VPATH} feature (@sc{gnu} @code{make} does), running
12671@code{make} in each of these directories builds the @code{gdb}
12672program specified there.
12673
12674To build @code{gdb} in a separate directory, run @code{configure}
12675with the @samp{--srcdir} option to specify where to find the source.
12676(You also need to specify a path to find @code{configure}
12677itself from your working directory. If the path to @code{configure}
12678would be the same as the argument to @samp{--srcdir}, you can leave out
12679the @samp{--srcdir} option; it is assumed.)
12680
5d161b24 12681For example, with version @value{GDBVN}, you can build @value{GDBN} in a
c906108c
SS
12682separate directory for a Sun 4 like this:
12683
12684@example
12685@group
12686cd gdb-@value{GDBVN}
12687mkdir ../gdb-sun4
12688cd ../gdb-sun4
12689../gdb-@value{GDBVN}/configure sun4
12690make
12691@end group
12692@end example
12693
12694When @code{configure} builds a configuration using a remote source
12695directory, it creates a tree for the binaries with the same structure
12696(and using the same names) as the tree under the source directory. In
12697the example, you'd find the Sun 4 library @file{libiberty.a} in the
12698directory @file{gdb-sun4/libiberty}, and @value{GDBN} itself in
12699@file{gdb-sun4/gdb}.
12700
12701One popular reason to build several @value{GDBN} configurations in separate
5d161b24
DB
12702directories is to configure @value{GDBN} for cross-compiling (where
12703@value{GDBN} runs on one machine---the @dfn{host}---while debugging
12704programs that run on another machine---the @dfn{target}).
c906108c
SS
12705You specify a cross-debugging target by
12706giving the @samp{--target=@var{target}} option to @code{configure}.
12707
12708When you run @code{make} to build a program or library, you must run
12709it in a configured directory---whatever directory you were in when you
12710called @code{configure} (or one of its subdirectories).
12711
12712The @code{Makefile} that @code{configure} generates in each source
12713directory also runs recursively. If you type @code{make} in a source
12714directory such as @file{gdb-@value{GDBVN}} (or in a separate configured
12715directory configured with @samp{--srcdir=@var{dirname}/gdb-@value{GDBVN}}), you
12716will build all the required libraries, and then build GDB.
12717
12718When you have multiple hosts or targets configured in separate
12719directories, you can run @code{make} on them in parallel (for example,
12720if they are NFS-mounted on each of the hosts); they will not interfere
12721with each other.
12722
6d2ebf8b 12723@node Config Names
c906108c
SS
12724@section Specifying names for hosts and targets
12725
12726The specifications used for hosts and targets in the @code{configure}
12727script are based on a three-part naming scheme, but some short predefined
12728aliases are also supported. The full naming scheme encodes three pieces
12729of information in the following pattern:
12730
12731@example
12732@var{architecture}-@var{vendor}-@var{os}
12733@end example
12734
12735For example, you can use the alias @code{sun4} as a @var{host} argument,
12736or as the value for @var{target} in a @code{--target=@var{target}}
12737option. The equivalent full name is @samp{sparc-sun-sunos4}.
12738
12739The @code{configure} script accompanying @value{GDBN} does not provide
12740any query facility to list all supported host and target names or
12741aliases. @code{configure} calls the Bourne shell script
12742@code{config.sub} to map abbreviations to full names; you can read the
12743script, if you wish, or you can use it to test your guesses on
12744abbreviations---for example:
12745
12746@smallexample
12747% sh config.sub i386-linux
12748i386-pc-linux-gnu
12749% sh config.sub alpha-linux
12750alpha-unknown-linux-gnu
12751% sh config.sub hp9k700
12752hppa1.1-hp-hpux
12753% sh config.sub sun4
12754sparc-sun-sunos4.1.1
12755% sh config.sub sun3
12756m68k-sun-sunos4.1.1
12757% sh config.sub i986v
12758Invalid configuration `i986v': machine `i986v' not recognized
12759@end smallexample
12760
12761@noindent
12762@code{config.sub} is also distributed in the @value{GDBN} source
12763directory (@file{gdb-@value{GDBVN}}, for version @value{GDBVN}).
12764
6d2ebf8b 12765@node Configure Options
c906108c
SS
12766@section @code{configure} options
12767
12768Here is a summary of the @code{configure} options and arguments that
12769are most often useful for building @value{GDBN}. @code{configure} also has
12770several other options not listed here. @inforef{What Configure
12771Does,,configure.info}, for a full explanation of @code{configure}.
12772
12773@example
12774configure @r{[}--help@r{]}
12775 @r{[}--prefix=@var{dir}@r{]}
12776 @r{[}--exec-prefix=@var{dir}@r{]}
12777 @r{[}--srcdir=@var{dirname}@r{]}
12778 @r{[}--norecursion@r{]} @r{[}--rm@r{]}
12779 @r{[}--target=@var{target}@r{]}
12780 @var{host}
12781@end example
12782
12783@noindent
12784You may introduce options with a single @samp{-} rather than
12785@samp{--} if you prefer; but you may abbreviate option names if you use
12786@samp{--}.
12787
12788@table @code
12789@item --help
12790Display a quick summary of how to invoke @code{configure}.
12791
12792@item --prefix=@var{dir}
12793Configure the source to install programs and files under directory
12794@file{@var{dir}}.
12795
12796@item --exec-prefix=@var{dir}
12797Configure the source to install programs under directory
12798@file{@var{dir}}.
12799
12800@c avoid splitting the warning from the explanation:
12801@need 2000
12802@item --srcdir=@var{dirname}
12803@strong{Warning: using this option requires @sc{gnu} @code{make}, or another
12804@code{make} that implements the @code{VPATH} feature.}@*
12805Use this option to make configurations in directories separate from the
12806@value{GDBN} source directories. Among other things, you can use this to
12807build (or maintain) several configurations simultaneously, in separate
12808directories. @code{configure} writes configuration specific files in
12809the current directory, but arranges for them to use the source in the
12810directory @var{dirname}. @code{configure} creates directories under
12811the working directory in parallel to the source directories below
12812@var{dirname}.
12813
12814@item --norecursion
12815Configure only the directory level where @code{configure} is executed; do not
12816propagate configuration to subdirectories.
12817
12818@item --target=@var{target}
12819Configure @value{GDBN} for cross-debugging programs running on the specified
12820@var{target}. Without this option, @value{GDBN} is configured to debug
12821programs that run on the same machine (@var{host}) as @value{GDBN} itself.
12822
12823There is no convenient way to generate a list of all available targets.
12824
12825@item @var{host} @dots{}
12826Configure @value{GDBN} to run on the specified @var{host}.
12827
12828There is no convenient way to generate a list of all available hosts.
12829@end table
12830
12831There are many other options available as well, but they are generally
12832needed for special purposes only.
5d161b24 12833
6d2ebf8b 12834@node Index
c906108c
SS
12835@unnumbered Index
12836
12837@printindex cp
12838
12839@tex
12840% I think something like @colophon should be in texinfo. In the
12841% meantime:
12842\long\def\colophon{\hbox to0pt{}\vfill
12843\centerline{The body of this manual is set in}
12844\centerline{\fontname\tenrm,}
12845\centerline{with headings in {\bf\fontname\tenbf}}
12846\centerline{and examples in {\tt\fontname\tentt}.}
12847\centerline{{\it\fontname\tenit\/},}
12848\centerline{{\bf\fontname\tenbf}, and}
12849\centerline{{\sl\fontname\tensl\/}}
12850\centerline{are used for emphasis.}\vfill}
12851\page\colophon
12852% Blame: doc@cygnus.com, 1991.
12853@end tex
12854
12855@contents
12856@bye
This page took 0.712358 seconds and 4 git commands to generate.