2000-03-29 J.T. Conklin <jtc@redback.com>
[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
27@c !!set GDB manual's edition---not the same as GDB version!
6d2ebf8b 28@set EDITION Eighth
c906108c
SS
29
30@c !!set GDB manual's revision date
6d2ebf8b 31@set DATE March 2000
c906108c 32
6d2ebf8b 33@c THIS MANUAL REQUIRES TEXINFO 3.12 OR LATER.
c906108c 34
c906108c 35@c This is a dir.info fragment to support semi-automated addition of
6d2ebf8b 36@c manuals to an info tree.
96a2c332
SS
37@dircategory Programming & development tools.
38@direntry
c906108c 39* Gdb: (gdb). The @sc{gnu} debugger.
96a2c332
SS
40@end direntry
41
c906108c
SS
42@ifinfo
43This file documents the @sc{gnu} debugger @value{GDBN}.
44
45
5d161b24 46This is the @value{EDITION} Edition, @value{DATE},
c906108c
SS
47of @cite{Debugging with @value{GDBN}: the @sc{gnu} Source-Level Debugger}
48for @value{GDBN} Version @value{GDBVN}.
49
6d2ebf8b 50Copyright (C) 1988-2000 Free Software Foundation, Inc.
c906108c
SS
51
52Permission is granted to make and distribute verbatim copies of
53this manual provided the copyright notice and this permission notice
54are preserved on all copies.
55
56@ignore
57Permission is granted to process this file through TeX and print the
58results, provided the printed document carries copying permission
59notice identical to this one except for the removal of this paragraph
60(this paragraph not being relevant to the printed manual).
61
62@end ignore
63Permission is granted to copy and distribute modified versions of this
64manual under the conditions for verbatim copying, provided also that the
65entire resulting derived work is distributed under the terms of a
66permission notice identical to this one.
67
68Permission is granted to copy and distribute translations of this manual
69into another language, under the above conditions for modified versions.
70@end ifinfo
71
72@titlepage
73@title Debugging with @value{GDBN}
74@subtitle The @sc{gnu} Source-Level Debugger
c906108c 75@sp 1
c906108c
SS
76@subtitle @value{EDITION} Edition, for @value{GDBN} version @value{GDBVN}
77@subtitle @value{DATE}
78@author Richard M. Stallman and Roland H. Pesch
c906108c 79@page
c906108c
SS
80@tex
81{\parskip=0pt
53a5351d 82\hfill (Send bugs and comments on @value{GDBN} to bug-gdb\@gnu.org.)\par
c906108c
SS
83\hfill {\it Debugging with @value{GDBN}}\par
84\hfill \TeX{}info \texinfoversion\par
85}
86@end tex
53a5351d 87
c906108c 88@vskip 0pt plus 1filll
6d2ebf8b 89Copyright @copyright{} 1988-2000 Free Software Foundation, Inc.
c906108c 90@sp 2
c906108c
SS
91Published by the Free Software Foundation @*
9259 Temple Place - Suite 330, @*
93Boston, MA 02111-1307 USA @*
6d2ebf8b
SS
94ISBN 1-882114-77-9 @*
95
c906108c
SS
96Permission is granted to make and distribute verbatim copies of
97this manual provided the copyright notice and this permission notice
98are preserved on all copies.
99
100Permission is granted to copy and distribute modified versions of this
101manual under the conditions for verbatim copying, provided also that the
102entire resulting derived work is distributed under the terms of a
103permission notice identical to this one.
104
105Permission is granted to copy and distribute translations of this manual
106into another language, under the above conditions for modified versions.
107@end titlepage
108@page
109
b9deaee7 110@ifinfo
6d2ebf8b
SS
111@node Top, Summary, (dir), (dir)
112
c906108c
SS
113@top Debugging with @value{GDBN}
114
115This file describes @value{GDBN}, the @sc{gnu} symbolic debugger.
116
5d161b24 117This is the @value{EDITION} Edition, @value{DATE}, for @value{GDBN} Version
c906108c
SS
118@value{GDBVN}.
119
6d2ebf8b
SS
120Copyright (C) 1988-2000 Free Software Foundation, Inc.
121
122@menu
123* Summary:: Summary of @value{GDBN}
124* Sample Session:: A sample @value{GDBN} session
125
126* Invocation:: Getting in and out of @value{GDBN}
127* Commands:: @value{GDBN} commands
128* Running:: Running programs under @value{GDBN}
129* Stopping:: Stopping and continuing
130* Stack:: Examining the stack
131* Source:: Examining source files
132* Data:: Examining data
133
134* Languages:: Using @value{GDBN} with different languages
135
136* Symbols:: Examining the symbol table
137* Altering:: Altering execution
138* GDB Files:: @value{GDBN} files
139* Targets:: Specifying a debugging target
140* Configurations:: Configuration-specific information
141* Controlling GDB:: Controlling @value{GDBN}
142* Sequences:: Canned sequences of commands
143* Emacs:: Using @value{GDBN} under @sc{gnu} Emacs
144* Annotations:: @value{GDBN}'s annotation interface.
145
146* GDB Bugs:: Reporting bugs in @value{GDBN}
147* Formatting Documentation:: How to format and print @value{GDBN} documentation
148
149* Command Line Editing:: Command Line Editing
150* Using History Interactively:: Using History Interactively
151* Installing GDB:: Installing GDB
152* Index:: Index
153@end menu
154
b9deaee7 155@end ifinfo
6d2ebf8b
SS
156
157@c the replication sucks, but this avoids a texinfo 3.12 lameness
158
159@ifhtml
160@node Top
161
162@top Debugging with @value{GDBN}
163
164This file describes @value{GDBN}, the @sc{gnu} symbolic debugger.
165
166This is the @value{EDITION} Edition, @value{DATE}, for @value{GDBN} Version
167@value{GDBVN}.
168
169Copyright (C) 1988-2000 Free Software Foundation, Inc.
170
c906108c
SS
171@menu
172* Summary:: Summary of @value{GDBN}
c906108c 173* Sample Session:: A sample @value{GDBN} session
c906108c
SS
174
175* Invocation:: Getting in and out of @value{GDBN}
176* Commands:: @value{GDBN} commands
177* Running:: Running programs under @value{GDBN}
178* Stopping:: Stopping and continuing
179* Stack:: Examining the stack
180* Source:: Examining source files
181* Data:: Examining data
c906108c 182
7a292a7a 183* Languages:: Using @value{GDBN} with different languages
c906108c
SS
184
185* Symbols:: Examining the symbol table
186* Altering:: Altering execution
187* GDB Files:: @value{GDBN} files
188* Targets:: Specifying a debugging target
104c1213 189* Configurations:: Configuration-specific information
c906108c
SS
190* Controlling GDB:: Controlling @value{GDBN}
191* Sequences:: Canned sequences of commands
c906108c 192* Emacs:: Using @value{GDBN} under @sc{gnu} Emacs
6d2ebf8b 193* Annotations:: @value{GDBN}'s annotation interface.
c906108c
SS
194
195* GDB Bugs:: Reporting bugs in @value{GDBN}
c906108c 196* Formatting Documentation:: How to format and print @value{GDBN} documentation
c906108c
SS
197
198* Command Line Editing:: Command Line Editing
199* Using History Interactively:: Using History Interactively
200* Installing GDB:: Installing GDB
201* Index:: Index
c906108c
SS
202@end menu
203
6d2ebf8b
SS
204@end ifhtml
205
206@node Summary
c906108c
SS
207@unnumbered Summary of @value{GDBN}
208
209The purpose of a debugger such as @value{GDBN} is to allow you to see what is
210going on ``inside'' another program while it executes---or what another
211program was doing at the moment it crashed.
212
213@value{GDBN} can do four main kinds of things (plus other things in support of
214these) to help you catch bugs in the act:
215
216@itemize @bullet
217@item
218Start your program, specifying anything that might affect its behavior.
219
220@item
221Make your program stop on specified conditions.
222
223@item
224Examine what has happened, when your program has stopped.
225
226@item
227Change things in your program, so you can experiment with correcting the
228effects of one bug and go on to learn about another.
229@end itemize
230
cce74817 231You can use @value{GDBN} to debug programs written in C and C++.
c906108c 232For more information, see @ref{Support,,Supported languages}.
c906108c
SS
233For more information, see @ref{C,,C and C++}.
234
cce74817
JM
235@cindex Chill
236@cindex Modula-2
c906108c 237Support for Modula-2 and Chill is partial. For information on Modula-2,
cce74817 238see @ref{Modula-2,,Modula-2}. For information on Chill, see @ref{Chill}.
c906108c 239
cce74817
JM
240@cindex Pascal
241Debugging Pascal programs which use sets, subranges, file variables, or
242nested functions does not currently work. @value{GDBN} does not support
243entering expressions, printing values, or similar features using Pascal
244syntax.
c906108c 245
c906108c
SS
246@cindex Fortran
247@value{GDBN} can be used to debug programs written in Fortran, although
53a5351d 248it may be necessary to refer to some variables with a trailing
cce74817 249underscore.
c906108c 250
c906108c
SS
251@menu
252* Free Software:: Freely redistributable software
253* Contributors:: Contributors to GDB
254@end menu
255
6d2ebf8b 256@node Free Software
c906108c
SS
257@unnumberedsec Free software
258
5d161b24 259@value{GDBN} is @dfn{free software}, protected by the @sc{gnu}
c906108c
SS
260General Public License
261(GPL). The GPL gives you the freedom to copy or adapt a licensed
262program---but every person getting a copy also gets with it the
263freedom to modify that copy (which means that they must get access to
264the source code), and the freedom to distribute further copies.
265Typical software companies use copyrights to limit your freedoms; the
266Free Software Foundation uses the GPL to preserve these freedoms.
267
268Fundamentally, the General Public License is a license which says that
269you have these freedoms and that you cannot take these freedoms away
270from anyone else.
271
6d2ebf8b 272@node Contributors
96a2c332
SS
273@unnumberedsec Contributors to @value{GDBN}
274
275Richard Stallman was the original author of @value{GDBN}, and of many
276other @sc{gnu} programs. Many others have contributed to its
277development. This section attempts to credit major contributors. One
278of the virtues of free software is that everyone is free to contribute
279to it; with regret, we cannot actually acknowledge everyone here. The
280file @file{ChangeLog} in the @value{GDBN} distribution approximates a
c906108c
SS
281blow-by-blow account.
282
283Changes much prior to version 2.0 are lost in the mists of time.
284
285@quotation
286@emph{Plea:} Additions to this section are particularly welcome. If you
287or your friends (or enemies, to be evenhanded) have been unfairly
288omitted from this list, we would like to add your names!
289@end quotation
290
291So that they may not regard their many labors as thankless, we
292particularly thank those who shepherded @value{GDBN} through major
293releases:
294Jim Blandy (release 4.18);
295Jason Molenda (release 4.17);
296Stan Shebs (release 4.14);
297Fred Fish (releases 4.16, 4.15, 4.13, 4.12, 4.11, 4.10, and 4.9);
298Stu Grossman and John Gilmore (releases 4.8, 4.7, 4.6, 4.5, and 4.4);
299John Gilmore (releases 4.3, 4.2, 4.1, 4.0, and 3.9);
300Jim Kingdon (releases 3.5, 3.4, and 3.3);
301and Randy Smith (releases 3.2, 3.1, and 3.0).
302
303Richard Stallman, assisted at various times by Peter TerMaat, Chris
304Hanson, and Richard Mlynarik, handled releases through 2.8.
305
96a2c332
SS
306Michael Tiemann is the author of most of the @sc{gnu} C++ support in
307@value{GDBN}, with significant additional contributions from Per
308Bothner. James Clark wrote the @sc{gnu} C++ demangler. Early work on
309C++ was by Peter TerMaat (who also did much general update work leading
310to release 3.0).
c906108c
SS
311
312@value{GDBN} 4 uses the BFD subroutine library to examine multiple
313object-file formats; BFD was a joint project of David V.
314Henkel-Wallace, Rich Pixley, Steve Chamberlain, and John Gilmore.
315
316David Johnson wrote the original COFF support; Pace Willison did
317the original support for encapsulated COFF.
318
319Brent Benson of Harris Computer Systems contributed DWARF 2 support.
320
321Adam de Boor and Bradley Davis contributed the ISI Optimum V support.
322Per Bothner, Noboyuki Hikichi, and Alessandro Forin contributed MIPS
323support.
324Jean-Daniel Fekete contributed Sun 386i support.
325Chris Hanson improved the HP9000 support.
326Noboyuki Hikichi and Tomoyuki Hasei contributed Sony/News OS 3 support.
327David Johnson contributed Encore Umax support.
328Jyrki Kuoppala contributed Altos 3068 support.
329Jeff Law contributed HP PA and SOM support.
330Keith Packard contributed NS32K support.
331Doug Rabson contributed Acorn Risc Machine support.
332Bob Rusk contributed Harris Nighthawk CX-UX support.
333Chris Smith contributed Convex support (and Fortran debugging).
334Jonathan Stone contributed Pyramid support.
335Michael Tiemann contributed SPARC support.
336Tim Tucker contributed support for the Gould NP1 and Gould Powernode.
337Pace Willison contributed Intel 386 support.
338Jay Vosburgh contributed Symmetry support.
339
340Andreas Schwab contributed M68K Linux support.
341
342Rich Schaefer and Peter Schauer helped with support of SunOS shared
343libraries.
344
345Jay Fenlason and Roland McGrath ensured that @value{GDBN} and GAS agree
346about several machine instruction sets.
347
348Patrick Duval, Ted Goldstein, Vikram Koka and Glenn Engel helped develop
349remote debugging. Intel Corporation, Wind River Systems, AMD, and ARM
350contributed remote debugging modules for the i960, VxWorks, A29K UDI,
351and RDI targets, respectively.
352
353Brian Fox is the author of the readline libraries providing
354command-line editing and command history.
355
7a292a7a
SS
356Andrew Beers of SUNY Buffalo wrote the language-switching code, the
357Modula-2 support, and contributed the Languages chapter of this manual.
c906108c 358
5d161b24 359Fred Fish wrote most of the support for Unix System Vr4.
c906108c
SS
360He also enhanced the command-completion support to cover C++ overloaded
361symbols.
c906108c
SS
362
363Hitachi America, Ltd. sponsored the support for H8/300, H8/500, and
364Super-H processors.
365
366NEC sponsored the support for the v850, Vr4xxx, and Vr5xxx processors.
367
368Mitsubishi sponsored the support for D10V, D30V, and M32R/D processors.
369
370Toshiba sponsored the support for the TX39 Mips processor.
371
372Matsushita sponsored the support for the MN10200 and MN10300 processors.
373
96a2c332 374Fujitsu sponsored the support for SPARClite and FR30 processors.
c906108c
SS
375
376Kung Hsu, Jeff Law, and Rick Sladkey added support for hardware
377watchpoints.
378
379Michael Snyder added support for tracepoints.
380
381Stu Grossman wrote gdbserver.
382
383Jim Kingdon, Peter Schauer, Ian Taylor, and Stu Grossman made
96a2c332 384nearly innumerable bug fixes and cleanups throughout @value{GDBN}.
c906108c
SS
385
386The following people at the Hewlett-Packard Company contributed
387support for the PA-RISC 2.0 architecture, HP-UX 10.20, 10.30, and 11.0
388(narrow mode), HP's implementation of kernel threads, HP's aC++
389compiler, and the terminal user interface: Ben Krepp, Richard Title,
390John Bishop, Susan Macchia, Kathy Mann, Satish Pai, India Paul, Steve
391Rehrauer, and Elena Zannoni. Kim Haase provided HP-specific
392information in this manual.
393
96a2c332
SS
394Cygnus Solutions has sponsored @value{GDBN} maintenance and much of its
395development since 1991. Cygnus engineers who have worked on @value{GDBN}
2df3850c
JM
396fulltime include Mark Alexander, Jim Blandy, Per Bothner, Kevin
397Buettner, Edith Epstein, Chris Faylor, Fred Fish, Martin Hunt, Jim
398Ingham, John Gilmore, Stu Grossman, Kung Hsu, Jim Kingdon, John Metzler,
399Fernando Nasser, Geoffrey Noer, Dawn Perchik, Rich Pixley, Zdenek
400Radouch, Keith Seitz, Stan Shebs, David Taylor, and Elena Zannoni. In
401addition, Dave Brolley, Ian Carmichael, Steve Chamberlain, Nick Clifton,
402JT Conklin, Stan Cox, DJ Delorie, Ulrich Drepper, Frank Eigler, Doug
403Evans, Sean Fagan, David Henkel-Wallace, Richard Henderson, Jeff
404Holcomb, Jeff Law, Jim Lemke, Tom Lord, Bob Manson, Michael Meissner,
405Jason Merrill, Catherine Moore, Drew Moseley, Ken Raeburn, Gavin
406Romig-Koch, Rob Savoye, Jamie Smith, Mike Stump, Ian Taylor, Angela
407Thomas, Michael Tiemann, Tom Tromey, Ron Unrau, Jim Wilson, and David
408Zuhn have made contributions both large and small.
c906108c
SS
409
410
6d2ebf8b 411@node Sample Session
c906108c
SS
412@chapter A Sample @value{GDBN} Session
413
414You can use this manual at your leisure to read all about @value{GDBN}.
415However, a handful of commands are enough to get started using the
416debugger. This chapter illustrates those commands.
417
418@iftex
419In this sample session, we emphasize user input like this: @b{input},
420to make it easier to pick out from the surrounding output.
421@end iftex
422
423@c FIXME: this example may not be appropriate for some configs, where
424@c FIXME...primary interest is in remote use.
425
426One of the preliminary versions of @sc{gnu} @code{m4} (a generic macro
427processor) exhibits the following bug: sometimes, when we change its
428quote strings from the default, the commands used to capture one macro
429definition within another stop working. In the following short @code{m4}
430session, we define a macro @code{foo} which expands to @code{0000}; we
431then use the @code{m4} built-in @code{defn} to define @code{bar} as the
432same thing. However, when we change the open quote string to
433@code{<QUOTE>} and the close quote string to @code{<UNQUOTE>}, the same
434procedure fails to define a new synonym @code{baz}:
435
436@smallexample
437$ @b{cd gnu/m4}
438$ @b{./m4}
439@b{define(foo,0000)}
440
441@b{foo}
4420000
443@b{define(bar,defn(`foo'))}
444
445@b{bar}
4460000
447@b{changequote(<QUOTE>,<UNQUOTE>)}
448
449@b{define(baz,defn(<QUOTE>foo<UNQUOTE>))}
450@b{baz}
451@b{C-d}
452m4: End of input: 0: fatal error: EOF in string
453@end smallexample
454
455@noindent
456Let us use @value{GDBN} to try to see what is going on.
457
c906108c
SS
458@smallexample
459$ @b{@value{GDBP} m4}
460@c FIXME: this falsifies the exact text played out, to permit smallbook
461@c FIXME... format to come out better.
462@value{GDBN} is free software and you are welcome to distribute copies
5d161b24 463 of it under certain conditions; type "show copying" to see
c906108c 464 the conditions.
5d161b24 465There is absolutely no warranty for @value{GDBN}; type "show warranty"
c906108c
SS
466 for details.
467
468@value{GDBN} @value{GDBVN}, Copyright 1999 Free Software Foundation, Inc...
469(@value{GDBP})
470@end smallexample
c906108c
SS
471
472@noindent
473@value{GDBN} reads only enough symbol data to know where to find the
474rest when needed; as a result, the first prompt comes up very quickly.
475We now tell @value{GDBN} to use a narrower display width than usual, so
476that examples fit in this manual.
477
478@smallexample
479(@value{GDBP}) @b{set width 70}
480@end smallexample
481
482@noindent
483We need to see how the @code{m4} built-in @code{changequote} works.
484Having looked at the source, we know the relevant subroutine is
485@code{m4_changequote}, so we set a breakpoint there with the @value{GDBN}
486@code{break} command.
487
488@smallexample
489(@value{GDBP}) @b{break m4_changequote}
490Breakpoint 1 at 0x62f4: file builtin.c, line 879.
491@end smallexample
492
493@noindent
494Using the @code{run} command, we start @code{m4} running under @value{GDBN}
495control; as long as control does not reach the @code{m4_changequote}
496subroutine, the program runs as usual:
497
498@smallexample
499(@value{GDBP}) @b{run}
500Starting program: /work/Editorial/gdb/gnu/m4/m4
501@b{define(foo,0000)}
502
503@b{foo}
5040000
505@end smallexample
506
507@noindent
508To trigger the breakpoint, we call @code{changequote}. @value{GDBN}
509suspends execution of @code{m4}, displaying information about the
510context where it stops.
511
512@smallexample
513@b{changequote(<QUOTE>,<UNQUOTE>)}
514
5d161b24 515Breakpoint 1, m4_changequote (argc=3, argv=0x33c70)
c906108c
SS
516 at builtin.c:879
517879 if (bad_argc(TOKEN_DATA_TEXT(argv[0]),argc,1,3))
518@end smallexample
519
520@noindent
521Now we use the command @code{n} (@code{next}) to advance execution to
522the next line of the current function.
523
524@smallexample
525(@value{GDBP}) @b{n}
526882 set_quotes((argc >= 2) ? TOKEN_DATA_TEXT(argv[1])\
527 : nil,
528@end smallexample
529
530@noindent
531@code{set_quotes} looks like a promising subroutine. We can go into it
532by using the command @code{s} (@code{step}) instead of @code{next}.
533@code{step} goes to the next line to be executed in @emph{any}
534subroutine, so it steps into @code{set_quotes}.
535
536@smallexample
537(@value{GDBP}) @b{s}
538set_quotes (lq=0x34c78 "<QUOTE>", rq=0x34c88 "<UNQUOTE>")
539 at input.c:530
540530 if (lquote != def_lquote)
541@end smallexample
542
543@noindent
544The display that shows the subroutine where @code{m4} is now
545suspended (and its arguments) is called a stack frame display. It
546shows a summary of the stack. We can use the @code{backtrace}
547command (which can also be spelled @code{bt}), to see where we are
548in the stack as a whole: the @code{backtrace} command displays a
549stack frame for each active subroutine.
550
551@smallexample
552(@value{GDBP}) @b{bt}
553#0 set_quotes (lq=0x34c78 "<QUOTE>", rq=0x34c88 "<UNQUOTE>")
554 at input.c:530
5d161b24 555#1 0x6344 in m4_changequote (argc=3, argv=0x33c70)
c906108c
SS
556 at builtin.c:882
557#2 0x8174 in expand_macro (sym=0x33320) at macro.c:242
558#3 0x7a88 in expand_token (obs=0x0, t=209696, td=0xf7fffa30)
559 at macro.c:71
560#4 0x79dc in expand_input () at macro.c:40
561#5 0x2930 in main (argc=0, argv=0xf7fffb20) at m4.c:195
562@end smallexample
563
564@noindent
565We step through a few more lines to see what happens. The first two
566times, we can use @samp{s}; the next two times we use @code{n} to avoid
567falling into the @code{xstrdup} subroutine.
568
569@smallexample
570(@value{GDBP}) @b{s}
5710x3b5c 532 if (rquote != def_rquote)
572(@value{GDBP}) @b{s}
5730x3b80 535 lquote = (lq == nil || *lq == '\0') ? \
574def_lquote : xstrdup(lq);
575(@value{GDBP}) @b{n}
576536 rquote = (rq == nil || *rq == '\0') ? def_rquote\
577 : xstrdup(rq);
578(@value{GDBP}) @b{n}
579538 len_lquote = strlen(rquote);
580@end smallexample
581
582@noindent
583The last line displayed looks a little odd; we can examine the variables
584@code{lquote} and @code{rquote} to see if they are in fact the new left
585and right quotes we specified. We use the command @code{p}
586(@code{print}) to see their values.
587
588@smallexample
589(@value{GDBP}) @b{p lquote}
590$1 = 0x35d40 "<QUOTE>"
591(@value{GDBP}) @b{p rquote}
592$2 = 0x35d50 "<UNQUOTE>"
593@end smallexample
594
595@noindent
596@code{lquote} and @code{rquote} are indeed the new left and right quotes.
597To look at some context, we can display ten lines of source
598surrounding the current line with the @code{l} (@code{list}) command.
599
600@smallexample
601(@value{GDBP}) @b{l}
602533 xfree(rquote);
603534
604535 lquote = (lq == nil || *lq == '\0') ? def_lquote\
605 : xstrdup (lq);
606536 rquote = (rq == nil || *rq == '\0') ? def_rquote\
607 : xstrdup (rq);
608537
609538 len_lquote = strlen(rquote);
610539 len_rquote = strlen(lquote);
611540 @}
612541
613542 void
614@end smallexample
615
616@noindent
617Let us step past the two lines that set @code{len_lquote} and
618@code{len_rquote}, and then examine the values of those variables.
619
620@smallexample
621(@value{GDBP}) @b{n}
622539 len_rquote = strlen(lquote);
623(@value{GDBP}) @b{n}
624540 @}
625(@value{GDBP}) @b{p len_lquote}
626$3 = 9
627(@value{GDBP}) @b{p len_rquote}
628$4 = 7
629@end smallexample
630
631@noindent
632That certainly looks wrong, assuming @code{len_lquote} and
633@code{len_rquote} are meant to be the lengths of @code{lquote} and
634@code{rquote} respectively. We can set them to better values using
635the @code{p} command, since it can print the value of
636any expression---and that expression can include subroutine calls and
637assignments.
638
639@smallexample
640(@value{GDBP}) @b{p len_lquote=strlen(lquote)}
641$5 = 7
642(@value{GDBP}) @b{p len_rquote=strlen(rquote)}
643$6 = 9
644@end smallexample
645
646@noindent
647Is that enough to fix the problem of using the new quotes with the
648@code{m4} built-in @code{defn}? We can allow @code{m4} to continue
649executing with the @code{c} (@code{continue}) command, and then try the
650example that caused trouble initially:
651
652@smallexample
653(@value{GDBP}) @b{c}
654Continuing.
655
656@b{define(baz,defn(<QUOTE>foo<UNQUOTE>))}
657
658baz
6590000
660@end smallexample
661
662@noindent
663Success! The new quotes now work just as well as the default ones. The
664problem seems to have been just the two typos defining the wrong
665lengths. We allow @code{m4} exit by giving it an EOF as input:
666
667@smallexample
668@b{C-d}
669Program exited normally.
670@end smallexample
671
672@noindent
673The message @samp{Program exited normally.} is from @value{GDBN}; it
674indicates @code{m4} has finished executing. We can end our @value{GDBN}
675session with the @value{GDBN} @code{quit} command.
676
677@smallexample
678(@value{GDBP}) @b{quit}
679@end smallexample
c906108c 680
6d2ebf8b 681@node Invocation
c906108c
SS
682@chapter Getting In and Out of @value{GDBN}
683
684This chapter discusses how to start @value{GDBN}, and how to get out of it.
5d161b24 685The essentials are:
c906108c 686@itemize @bullet
5d161b24 687@item
53a5351d 688type @samp{@value{GDBP}} to start @value{GDBN}.
5d161b24 689@item
c906108c
SS
690type @kbd{quit} or @kbd{C-d} to exit.
691@end itemize
692
693@menu
694* Invoking GDB:: How to start @value{GDBN}
695* Quitting GDB:: How to quit @value{GDBN}
696* Shell Commands:: How to use shell commands inside @value{GDBN}
697@end menu
698
6d2ebf8b 699@node Invoking GDB
c906108c
SS
700@section Invoking @value{GDBN}
701
c906108c
SS
702Invoke @value{GDBN} by running the program @code{@value{GDBP}}. Once started,
703@value{GDBN} reads commands from the terminal until you tell it to exit.
704
705You can also run @code{@value{GDBP}} with a variety of arguments and options,
706to specify more of your debugging environment at the outset.
707
c906108c
SS
708The command-line options described here are designed
709to cover a variety of situations; in some environments, some of these
5d161b24 710options may effectively be unavailable.
c906108c
SS
711
712The most usual way to start @value{GDBN} is with one argument,
713specifying an executable program:
714
715@example
716@value{GDBP} @var{program}
717@end example
718
c906108c
SS
719@noindent
720You can also start with both an executable program and a core file
721specified:
722
723@example
724@value{GDBP} @var{program} @var{core}
725@end example
726
727You can, instead, specify a process ID as a second argument, if you want
728to debug a running process:
729
730@example
731@value{GDBP} @var{program} 1234
732@end example
733
734@noindent
735would attach @value{GDBN} to process @code{1234} (unless you also have a file
736named @file{1234}; @value{GDBN} does check for a core file first).
737
c906108c 738Taking advantage of the second command-line argument requires a fairly
2df3850c
JM
739complete operating system; when you use @value{GDBN} as a remote
740debugger attached to a bare board, there may not be any notion of
741``process'', and there is often no way to get a core dump. @value{GDBN}
742will warn you if it is unable to attach or to read core dumps.
c906108c 743
96a2c332 744You can run @code{@value{GDBP}} without printing the front material, which describes
c906108c
SS
745@value{GDBN}'s non-warranty, by specifying @code{-silent}:
746
747@smallexample
748@value{GDBP} -silent
749@end smallexample
750
751@noindent
752You can further control how @value{GDBN} starts up by using command-line
753options. @value{GDBN} itself can remind you of the options available.
754
755@noindent
756Type
757
758@example
759@value{GDBP} -help
760@end example
761
762@noindent
763to display all available options and briefly describe their use
764(@samp{@value{GDBP} -h} is a shorter equivalent).
765
766All options and command line arguments you give are processed
767in sequential order. The order makes a difference when the
768@samp{-x} option is used.
769
770
771@menu
c906108c
SS
772* File Options:: Choosing files
773* Mode Options:: Choosing modes
774@end menu
775
6d2ebf8b 776@node File Options
c906108c
SS
777@subsection Choosing files
778
2df3850c 779When @value{GDBN} starts, it reads any arguments other than options as
c906108c
SS
780specifying an executable file and core file (or process ID). This is
781the same as if the arguments were specified by the @samp{-se} and
782@samp{-c} options respectively. (@value{GDBN} reads the first argument
783that does not have an associated option flag as equivalent to the
784@samp{-se} option followed by that argument; and the second argument
785that does not have an associated option flag, if any, as equivalent to
786the @samp{-c} option followed by that argument.)
7a292a7a
SS
787
788If @value{GDBN} has not been configured to included core file support,
789such as for most embedded targets, then it will complain about a second
790argument and ignore it.
c906108c
SS
791
792Many options have both long and short forms; both are shown in the
793following list. @value{GDBN} also recognizes the long forms if you truncate
794them, so long as enough of the option is present to be unambiguous.
795(If you prefer, you can flag option arguments with @samp{--} rather
796than @samp{-}, though we illustrate the more usual convention.)
797
d700128c
EZ
798@c NOTE: the @cindex entries here use double dashes ON PURPOSE. This
799@c way, both those who look for -foo and --foo in the index, will find
800@c it.
801
c906108c
SS
802@table @code
803@item -symbols @var{file}
804@itemx -s @var{file}
d700128c
EZ
805@cindex @code{--symbols}
806@cindex @code{-s}
c906108c
SS
807Read symbol table from file @var{file}.
808
809@item -exec @var{file}
810@itemx -e @var{file}
d700128c
EZ
811@cindex @code{--exec}
812@cindex @code{-e}
7a292a7a
SS
813Use file @var{file} as the executable file to execute when appropriate,
814and for examining pure data in conjunction with a core dump.
c906108c
SS
815
816@item -se @var{file}
d700128c 817@cindex @code{--se}
c906108c
SS
818Read symbol table from file @var{file} and use it as the executable
819file.
820
c906108c
SS
821@item -core @var{file}
822@itemx -c @var{file}
d700128c
EZ
823@cindex @code{--core}
824@cindex @code{-c}
c906108c
SS
825Use file @var{file} as a core dump to examine.
826
827@item -c @var{number}
828Connect to process ID @var{number}, as with the @code{attach} command
829(unless there is a file in core-dump format named @var{number}, in which
830case @samp{-c} specifies that file as a core dump to read).
c906108c
SS
831
832@item -command @var{file}
833@itemx -x @var{file}
d700128c
EZ
834@cindex @code{--command}
835@cindex @code{-x}
c906108c
SS
836Execute @value{GDBN} commands from file @var{file}. @xref{Command
837Files,, Command files}.
838
839@item -directory @var{directory}
840@itemx -d @var{directory}
d700128c
EZ
841@cindex @code{--directory}
842@cindex @code{-d}
c906108c
SS
843Add @var{directory} to the path to search for source files.
844
c906108c
SS
845@item -m
846@itemx -mapped
d700128c
EZ
847@cindex @code{--mapped}
848@cindex @code{-m}
c906108c
SS
849@emph{Warning: this option depends on operating system facilities that are not
850supported on all systems.}@*
851If memory-mapped files are available on your system through the @code{mmap}
5d161b24 852system call, you can use this option
c906108c
SS
853to have @value{GDBN} write the symbols from your
854program into a reusable file in the current directory. If the program you are debugging is
96a2c332 855called @file{/tmp/fred}, the mapped symbol file is @file{/tmp/fred.syms}.
c906108c
SS
856Future @value{GDBN} debugging sessions notice the presence of this file,
857and can quickly map in symbol information from it, rather than reading
858the symbol table from the executable program.
859
860The @file{.syms} file is specific to the host machine where @value{GDBN}
861is run. It holds an exact image of the internal @value{GDBN} symbol
862table. It cannot be shared across multiple host platforms.
c906108c 863
c906108c
SS
864@item -r
865@itemx -readnow
d700128c
EZ
866@cindex @code{--readnow}
867@cindex @code{-r}
c906108c
SS
868Read each symbol file's entire symbol table immediately, rather than
869the default, which is to read it incrementally as it is needed.
870This makes startup slower, but makes future operations faster.
53a5351d 871
c906108c
SS
872@end table
873
2df3850c 874You typically combine the @code{-mapped} and @code{-readnow} options in
c906108c 875order to build a @file{.syms} file that contains complete symbol
2df3850c
JM
876information. (@xref{Files,,Commands to specify files}, for information
877on @file{.syms} files.) A simple @value{GDBN} invocation to do nothing
878but build a @file{.syms} file for future use is:
c906108c
SS
879
880@example
2df3850c 881gdb -batch -nx -mapped -readnow programname
c906108c 882@end example
c906108c 883
6d2ebf8b 884@node Mode Options
c906108c
SS
885@subsection Choosing modes
886
887You can run @value{GDBN} in various alternative modes---for example, in
888batch mode or quiet mode.
889
890@table @code
891@item -nx
892@itemx -n
d700128c
EZ
893@cindex @code{--nx}
894@cindex @code{-n}
2df3850c
JM
895Do not execute commands found in any initialization files (normally
896called @file{.gdbinit}, or @file{gdb.ini} on PCs). Normally,
897@value{GDBN} executes the commands in these files after all the command
898options and arguments have been processed. @xref{Command Files,,Command
899files}.
c906108c
SS
900
901@item -quiet
d700128c 902@itemx -silent
c906108c 903@itemx -q
d700128c
EZ
904@cindex @code{--quiet}
905@cindex @code{--silent}
906@cindex @code{-q}
c906108c
SS
907``Quiet''. Do not print the introductory and copyright messages. These
908messages are also suppressed in batch mode.
909
910@item -batch
d700128c 911@cindex @code{--batch}
c906108c
SS
912Run in batch mode. Exit with status @code{0} after processing all the
913command files specified with @samp{-x} (and all commands from
914initialization files, if not inhibited with @samp{-n}). Exit with
915nonzero status if an error occurs in executing the @value{GDBN} commands
916in the command files.
917
2df3850c
JM
918Batch mode may be useful for running @value{GDBN} as a filter, for
919example to download and run a program on another computer; in order to
920make this more useful, the message
c906108c
SS
921
922@example
923Program exited normally.
924@end example
925
926@noindent
2df3850c
JM
927(which is ordinarily issued whenever a program running under
928@value{GDBN} control terminates) is not issued when running in batch
929mode.
930
931@item -nowindows
932@itemx -nw
d700128c
EZ
933@cindex @code{--nowindows}
934@cindex @code{-nw}
2df3850c 935``No windows''. If @value{GDBN} comes with a graphical user interface
96a2c332 936(GUI) built in, then this option tells @value{GDBN} to only use the command-line
2df3850c
JM
937interface. If no GUI is available, this option has no effect.
938
939@item -windows
940@itemx -w
d700128c
EZ
941@cindex @code{--windows}
942@cindex @code{-w}
2df3850c
JM
943If @value{GDBN} includes a GUI, then this option requires it to be
944used if possible.
c906108c
SS
945
946@item -cd @var{directory}
d700128c 947@cindex @code{--cd}
c906108c
SS
948Run @value{GDBN} using @var{directory} as its working directory,
949instead of the current directory.
950
c906108c
SS
951@item -fullname
952@itemx -f
d700128c
EZ
953@cindex @code{--fullname}
954@cindex @code{-f}
7a292a7a
SS
955@sc{gnu} Emacs sets this option when it runs @value{GDBN} as a
956subprocess. It tells @value{GDBN} to output the full file name and line
957number in a standard, recognizable fashion each time a stack frame is
958displayed (which includes each time your program stops). This
959recognizable format looks like two @samp{\032} characters, followed by
960the file name, line number and character position separated by colons,
961and a newline. The Emacs-to-@value{GDBN} interface program uses the two
962@samp{\032} characters as a signal to display the source code for the
963frame.
c906108c 964
d700128c
EZ
965@item -epoch
966@cindex @code{--epoch}
967The Epoch Emacs-@value{GDBN} interface sets this option when it runs
968@value{GDBN} as a subprocess. It tells @value{GDBN} to modify its print
969routines so as to allow Epoch to display values of expressions in a
970separate window.
971
972@item -annotate @var{level}
973@cindex @code{--annotate}
974This option sets the @dfn{annotation level} inside @value{GDBN}. Its
975effect is identical to using @samp{set annotate @var{level}}
976(@pxref{Annotations}).
977Annotation level controls how much information does @value{GDBN} print
978together with its prompt, values of expressions, source lines, and other
979types of output. Level 0 is the normal, level 1 is for use when
980@value{GDBN} is run as a subprocess of @sc{gnu} Emacs, level 2 is the
981maximum annotation suitable for programs that control @value{GDBN}.
982
983@item -async
984@cindex @code{--async}
985Use the asynchronous event loop for the command-line interface.
986@value{GDBN} processes all events, such as user keyboard input, via a
987special event loop. This allows @value{GDBN} to accept and process user
988commands in parallel with the debugged process being
989run@footnote{@value{GDBN} built with @sc{djgpp} tools for
990MS-DOS/MS-Windows supports this mode of operation, but the event loop is
991suspended when the debuggee runs.}, so you don't need to wait for
992control to return to @value{GDBN} before you type the next command.
993(@emph{Note:} as of version 5.0, the target side of the asynchronous
994operation is not yet in place, so @samp{-async} does not work fully
995yet.)
996@c FIXME: when the target side of the event loop is done, the above NOTE
997@c should be removed.
998
999When the standard input is connected to a terminal device, @value{GDBN}
1000uses the asynchronous event loop by default, unless disabled by the
1001@samp{-noasync} option.
1002
1003@item -noasync
1004@cindex @code{--noasync}
1005Disable the asynchronous event loop for the command-line interface.
1006
2df3850c
JM
1007@item -baud @var{bps}
1008@itemx -b @var{bps}
d700128c
EZ
1009@cindex @code{--baud}
1010@cindex @code{-b}
c906108c
SS
1011Set the line speed (baud rate or bits per second) of any serial
1012interface used by @value{GDBN} for remote debugging.
c906108c
SS
1013
1014@item -tty @var{device}
d700128c
EZ
1015@itemx -t @var{device}
1016@cindex @code{--tty}
1017@cindex @code{-t}
c906108c
SS
1018Run using @var{device} for your program's standard input and output.
1019@c FIXME: kingdon thinks there is more to -tty. Investigate.
c906108c 1020
53a5351d
JM
1021@c resolve the situation of these eventually
1022@c @item -tui
d700128c 1023@c @cindex @code{--tui}
53a5351d
JM
1024@c Use a Terminal User Interface. For information, use your Web browser to
1025@c read the file @file{TUI.html}, which is usually installed in the
1026@c directory @code{/opt/langtools/wdb/doc} on HP-UX systems. Do not use
1027@c this option if you run @value{GDBN} from Emacs (see @pxref{Emacs, ,Using
1028@c @value{GDBN} under @sc{gnu} Emacs}).
1029
1030@c @item -xdb
d700128c 1031@c @cindex @code{--xdb}
53a5351d
JM
1032@c Run in XDB compatibility mode, allowing the use of certain XDB commands.
1033@c For information, see the file @file{xdb_trans.html}, which is usually
1034@c installed in the directory @code{/opt/langtools/wdb/doc} on HP-UX
1035@c systems.
1036
d700128c
EZ
1037@item -interpreter @var{interp}
1038@cindex @code{--interpreter}
1039Use the interpreter @var{interp} for interface with the controlling
1040program or device. This option is meant to be set by programs which
1041communicate with @value{GDBN} using it as a back end. For example,
1042@samp{--interpreter=mi} causes @value{GDBN} to use the @dfn{gdbmi
1043interface}.
1044@c FIXME: There should be an @xref here to the GDB/MI docs, but
1045@c gdbmi.texi doesn't have a single node to reference!
1046
1047@item -write
1048@cindex @code{--write}
1049Open the executable and core files for both reading and writing. This
1050is equivalent to the @samp{set write on} command inside @value{GDBN}
1051(@pxref{Patching}).
1052
1053@item -statistics
1054@cindex @code{--statistics}
1055This option causes @value{GDBN} to print statistics about time and
1056memory usage after it completes each command and returns to the prompt.
1057
1058@item -version
1059@cindex @code{--version}
1060This option causes @value{GDBN} to print its version number and
1061no-warranty blurb, and exit.
1062
c906108c
SS
1063@end table
1064
6d2ebf8b 1065@node Quitting GDB
c906108c
SS
1066@section Quitting @value{GDBN}
1067@cindex exiting @value{GDBN}
1068@cindex leaving @value{GDBN}
1069
1070@table @code
1071@kindex quit @r{[}@var{expression}@r{]}
1072@kindex q
96a2c332
SS
1073@item quit @r{[}@var{expression}@r{]}
1074@itemx q
1075To exit @value{GDBN}, use the @code{quit} command (abbreviated
1076@code{q}), or type an end-of-file character (usually @kbd{C-d}). If you
1077do not supply @var{expression}, @value{GDBN} will terminate normally;
1078otherwise it will terminate using the result of @var{expression} as the
1079error code.
c906108c
SS
1080@end table
1081
1082@cindex interrupt
1083An interrupt (often @kbd{C-c}) does not exit from @value{GDBN}, but rather
1084terminates the action of any @value{GDBN} command that is in progress and
1085returns to @value{GDBN} command level. It is safe to type the interrupt
1086character at any time because @value{GDBN} does not allow it to take effect
1087until a time when it is safe.
1088
c906108c
SS
1089If you have been using @value{GDBN} to control an attached process or
1090device, you can release it with the @code{detach} command
1091(@pxref{Attach, ,Debugging an already-running process}).
c906108c 1092
6d2ebf8b 1093@node Shell Commands
c906108c
SS
1094@section Shell commands
1095
1096If you need to execute occasional shell commands during your
1097debugging session, there is no need to leave or suspend @value{GDBN}; you can
1098just use the @code{shell} command.
1099
1100@table @code
1101@kindex shell
1102@cindex shell escape
1103@item shell @var{command string}
1104Invoke a standard shell to execute @var{command string}.
c906108c 1105If it exists, the environment variable @code{SHELL} determines which
d4f3574e
SS
1106shell to run. Otherwise @value{GDBN} uses the default shell
1107(@file{/bin/sh} on Unix systems, @file{COMMAND.COM} on MS-DOS, etc.).
c906108c
SS
1108@end table
1109
1110The utility @code{make} is often needed in development environments.
1111You do not have to use the @code{shell} command for this purpose in
1112@value{GDBN}:
1113
1114@table @code
1115@kindex make
1116@cindex calling make
1117@item make @var{make-args}
1118Execute the @code{make} program with the specified
1119arguments. This is equivalent to @samp{shell make @var{make-args}}.
1120@end table
1121
6d2ebf8b 1122@node Commands
c906108c
SS
1123@chapter @value{GDBN} Commands
1124
1125You can abbreviate a @value{GDBN} command to the first few letters of the command
1126name, if that abbreviation is unambiguous; and you can repeat certain
1127@value{GDBN} commands by typing just @key{RET}. You can also use the @key{TAB}
1128key to get @value{GDBN} to fill out the rest of a word in a command (or to
1129show you the alternatives available, if there is more than one possibility).
1130
1131@menu
1132* Command Syntax:: How to give commands to @value{GDBN}
1133* Completion:: Command completion
1134* Help:: How to ask @value{GDBN} for help
1135@end menu
1136
6d2ebf8b 1137@node Command Syntax
c906108c
SS
1138@section Command syntax
1139
1140A @value{GDBN} command is a single line of input. There is no limit on
1141how long it can be. It starts with a command name, which is followed by
1142arguments whose meaning depends on the command name. For example, the
1143command @code{step} accepts an argument which is the number of times to
1144step, as in @samp{step 5}. You can also use the @code{step} command
96a2c332 1145with no arguments. Some commands do not allow any arguments.
c906108c
SS
1146
1147@cindex abbreviation
1148@value{GDBN} command names may always be truncated if that abbreviation is
1149unambiguous. Other possible command abbreviations are listed in the
1150documentation for individual commands. In some cases, even ambiguous
1151abbreviations are allowed; for example, @code{s} is specially defined as
1152equivalent to @code{step} even though there are other commands whose
1153names start with @code{s}. You can test abbreviations by using them as
1154arguments to the @code{help} command.
1155
1156@cindex repeating commands
1157@kindex RET
1158A blank line as input to @value{GDBN} (typing just @key{RET}) means to
96a2c332 1159repeat the previous command. Certain commands (for example, @code{run})
c906108c
SS
1160will not repeat this way; these are commands whose unintentional
1161repetition might cause trouble and which you are unlikely to want to
1162repeat.
1163
1164The @code{list} and @code{x} commands, when you repeat them with
1165@key{RET}, construct new arguments rather than repeating
1166exactly as typed. This permits easy scanning of source or memory.
1167
1168@value{GDBN} can also use @key{RET} in another way: to partition lengthy
1169output, in a way similar to the common utility @code{more}
1170(@pxref{Screen Size,,Screen size}). Since it is easy to press one
1171@key{RET} too many in this situation, @value{GDBN} disables command
1172repetition after any command that generates this sort of display.
1173
1174@kindex #
1175@cindex comment
1176Any text from a @kbd{#} to the end of the line is a comment; it does
1177nothing. This is useful mainly in command files (@pxref{Command
1178Files,,Command files}).
1179
6d2ebf8b 1180@node Completion
c906108c
SS
1181@section Command completion
1182
1183@cindex completion
1184@cindex word completion
1185@value{GDBN} can fill in the rest of a word in a command for you, if there is
1186only one possibility; it can also show you what the valid possibilities
1187are for the next word in a command, at any time. This works for @value{GDBN}
1188commands, @value{GDBN} subcommands, and the names of symbols in your program.
1189
1190Press the @key{TAB} key whenever you want @value{GDBN} to fill out the rest
1191of a word. If there is only one possibility, @value{GDBN} fills in the
1192word, and waits for you to finish the command (or press @key{RET} to
1193enter it). For example, if you type
1194
1195@c FIXME "@key" does not distinguish its argument sufficiently to permit
1196@c complete accuracy in these examples; space introduced for clarity.
1197@c If texinfo enhancements make it unnecessary, it would be nice to
1198@c replace " @key" by "@key" in the following...
1199@example
1200(@value{GDBP}) info bre @key{TAB}
1201@end example
1202
1203@noindent
1204@value{GDBN} fills in the rest of the word @samp{breakpoints}, since that is
1205the only @code{info} subcommand beginning with @samp{bre}:
1206
1207@example
1208(@value{GDBP}) info breakpoints
1209@end example
1210
1211@noindent
1212You can either press @key{RET} at this point, to run the @code{info
1213breakpoints} command, or backspace and enter something else, if
1214@samp{breakpoints} does not look like the command you expected. (If you
1215were sure you wanted @code{info breakpoints} in the first place, you
1216might as well just type @key{RET} immediately after @samp{info bre},
1217to exploit command abbreviations rather than command completion).
1218
1219If there is more than one possibility for the next word when you press
1220@key{TAB}, @value{GDBN} sounds a bell. You can either supply more
1221characters and try again, or just press @key{TAB} a second time;
1222@value{GDBN} displays all the possible completions for that word. For
1223example, you might want to set a breakpoint on a subroutine whose name
1224begins with @samp{make_}, but when you type @kbd{b make_@key{TAB}} @value{GDBN}
1225just sounds the bell. Typing @key{TAB} again displays all the
1226function names in your program that begin with those characters, for
1227example:
1228
1229@example
1230(@value{GDBP}) b make_ @key{TAB}
1231@exdent @value{GDBN} sounds bell; press @key{TAB} again, to see:
5d161b24
DB
1232make_a_section_from_file make_environ
1233make_abs_section make_function_type
1234make_blockvector make_pointer_type
1235make_cleanup make_reference_type
c906108c
SS
1236make_command make_symbol_completion_list
1237(@value{GDBP}) b make_
1238@end example
1239
1240@noindent
1241After displaying the available possibilities, @value{GDBN} copies your
1242partial input (@samp{b make_} in the example) so you can finish the
1243command.
1244
1245If you just want to see the list of alternatives in the first place, you
1246can press @kbd{M-?} rather than pressing @key{TAB} twice. @kbd{M-?}
7a292a7a 1247means @kbd{@key{META} ?}. You can type this either by holding down a
c906108c 1248key designated as the @key{META} shift on your keyboard (if there is
7a292a7a 1249one) while typing @kbd{?}, or as @key{ESC} followed by @kbd{?}.
c906108c
SS
1250
1251@cindex quotes in commands
1252@cindex completion of quoted strings
1253Sometimes the string you need, while logically a ``word'', may contain
7a292a7a
SS
1254parentheses or other characters that @value{GDBN} normally excludes from
1255its notion of a word. To permit word completion to work in this
1256situation, you may enclose words in @code{'} (single quote marks) in
1257@value{GDBN} commands.
c906108c 1258
c906108c
SS
1259The most likely situation where you might need this is in typing the
1260name of a C++ function. This is because C++ allows function overloading
1261(multiple definitions of the same function, distinguished by argument
1262type). For example, when you want to set a breakpoint you may need to
1263distinguish whether you mean the version of @code{name} that takes an
1264@code{int} parameter, @code{name(int)}, or the version that takes a
1265@code{float} parameter, @code{name(float)}. To use the word-completion
1266facilities in this situation, type a single quote @code{'} at the
1267beginning of the function name. This alerts @value{GDBN} that it may need to
1268consider more information than usual when you press @key{TAB} or
1269@kbd{M-?} to request word completion:
1270
1271@example
96a2c332 1272(@value{GDBP}) b 'bubble( @kbd{M-?}
c906108c
SS
1273bubble(double,double) bubble(int,int)
1274(@value{GDBP}) b 'bubble(
1275@end example
1276
1277In some cases, @value{GDBN} can tell that completing a name requires using
1278quotes. When this happens, @value{GDBN} inserts the quote for you (while
1279completing as much as it can) if you do not type the quote in the first
1280place:
1281
1282@example
1283(@value{GDBP}) b bub @key{TAB}
1284@exdent @value{GDBN} alters your input line to the following, and rings a bell:
1285(@value{GDBP}) b 'bubble(
1286@end example
1287
1288@noindent
1289In general, @value{GDBN} can tell that a quote is needed (and inserts it) if
1290you have not yet started typing the argument list when you ask for
1291completion on an overloaded symbol.
1292
d4f3574e 1293For more information about overloaded functions, see @ref{C plus plus
c906108c
SS
1294expressions, ,C++ expressions}. You can use the command @code{set
1295overload-resolution off} to disable overload resolution;
d4f3574e 1296see @ref{Debugging C plus plus, ,@value{GDBN} features for C++}.
c906108c
SS
1297
1298
6d2ebf8b 1299@node Help
c906108c
SS
1300@section Getting help
1301@cindex online documentation
1302@kindex help
1303
5d161b24 1304You can always ask @value{GDBN} itself for information on its commands,
c906108c
SS
1305using the command @code{help}.
1306
1307@table @code
1308@kindex h
1309@item help
1310@itemx h
1311You can use @code{help} (abbreviated @code{h}) with no arguments to
1312display a short list of named classes of commands:
1313
1314@smallexample
1315(@value{GDBP}) help
1316List of classes of commands:
1317
2df3850c 1318aliases -- Aliases of other commands
c906108c 1319breakpoints -- Making program stop at certain points
2df3850c 1320data -- Examining data
c906108c 1321files -- Specifying and examining files
2df3850c
JM
1322internals -- Maintenance commands
1323obscure -- Obscure features
1324running -- Running the program
1325stack -- Examining the stack
c906108c
SS
1326status -- Status inquiries
1327support -- Support facilities
96a2c332
SS
1328tracepoints -- Tracing of program execution without@*
1329 stopping the program
c906108c 1330user-defined -- User-defined commands
c906108c 1331
5d161b24 1332Type "help" followed by a class name for a list of
c906108c 1333commands in that class.
5d161b24 1334Type "help" followed by command name for full
c906108c
SS
1335documentation.
1336Command name abbreviations are allowed if unambiguous.
1337(@value{GDBP})
1338@end smallexample
96a2c332 1339@c the above line break eliminates huge line overfull...
c906108c
SS
1340
1341@item help @var{class}
1342Using one of the general help classes as an argument, you can get a
1343list of the individual commands in that class. For example, here is the
1344help display for the class @code{status}:
1345
1346@smallexample
1347(@value{GDBP}) help status
1348Status inquiries.
1349
1350List of commands:
1351
1352@c Line break in "show" line falsifies real output, but needed
1353@c to fit in smallbook page size.
2df3850c
JM
1354info -- Generic command for showing things
1355 about the program being debugged
1356show -- Generic command for showing things
1357 about the debugger
c906108c 1358
5d161b24 1359Type "help" followed by command name for full
c906108c
SS
1360documentation.
1361Command name abbreviations are allowed if unambiguous.
1362(@value{GDBP})
1363@end smallexample
1364
1365@item help @var{command}
1366With a command name as @code{help} argument, @value{GDBN} displays a
1367short paragraph on how to use that command.
1368
6837a0a2
DB
1369@kindex apropos
1370@item apropos @var{args}
1371The @code{apropos @var{args}} command searches through all of the @value{GDBN}
1372commands, and their documentation, for the regular expression specified in
1373@var{args}. It prints out all matches found. For example:
1374
1375@smallexample
1376apropos reload
1377@end smallexample
1378
1379@noindent results in:
1380
1381@smallexample
6d2ebf8b
SS
1382@c @group
1383set symbol-reloading -- Set dynamic symbol table reloading
1384 multiple times in one run
1385show symbol-reloading -- Show dynamic symbol table reloading
1386 multiple times in one run
1387@c @end group
6837a0a2
DB
1388@end smallexample
1389
c906108c
SS
1390@kindex complete
1391@item complete @var{args}
1392The @code{complete @var{args}} command lists all the possible completions
1393for the beginning of a command. Use @var{args} to specify the beginning of the
1394command you want completed. For example:
1395
1396@smallexample
1397complete i
1398@end smallexample
1399
1400@noindent results in:
1401
1402@smallexample
1403@group
2df3850c
JM
1404if
1405ignore
c906108c
SS
1406info
1407inspect
c906108c
SS
1408@end group
1409@end smallexample
1410
1411@noindent This is intended for use by @sc{gnu} Emacs.
1412@end table
1413
1414In addition to @code{help}, you can use the @value{GDBN} commands @code{info}
1415and @code{show} to inquire about the state of your program, or the state
1416of @value{GDBN} itself. Each command supports many topics of inquiry; this
1417manual introduces each of them in the appropriate context. The listings
1418under @code{info} and under @code{show} in the Index point to
1419all the sub-commands. @xref{Index}.
1420
1421@c @group
1422@table @code
1423@kindex info
1424@kindex i
1425@item info
1426This command (abbreviated @code{i}) is for describing the state of your
1427program. For example, you can list the arguments given to your program
1428with @code{info args}, list the registers currently in use with @code{info
1429registers}, or list the breakpoints you have set with @code{info breakpoints}.
1430You can get a complete list of the @code{info} sub-commands with
1431@w{@code{help info}}.
1432
1433@kindex set
1434@item set
5d161b24 1435You can assign the result of an expression to an environment variable with
c906108c
SS
1436@code{set}. For example, you can set the @value{GDBN} prompt to a $-sign with
1437@code{set prompt $}.
1438
1439@kindex show
1440@item show
5d161b24 1441In contrast to @code{info}, @code{show} is for describing the state of
c906108c
SS
1442@value{GDBN} itself.
1443You can change most of the things you can @code{show}, by using the
1444related command @code{set}; for example, you can control what number
1445system is used for displays with @code{set radix}, or simply inquire
1446which is currently in use with @code{show radix}.
1447
1448@kindex info set
1449To display all the settable parameters and their current
1450values, you can use @code{show} with no arguments; you may also use
1451@code{info set}. Both commands produce the same display.
1452@c FIXME: "info set" violates the rule that "info" is for state of
1453@c FIXME...program. Ck w/ GNU: "info set" to be called something else,
1454@c FIXME...or change desc of rule---eg "state of prog and debugging session"?
1455@end table
1456@c @end group
1457
1458Here are three miscellaneous @code{show} subcommands, all of which are
1459exceptional in lacking corresponding @code{set} commands:
1460
1461@table @code
1462@kindex show version
1463@cindex version number
1464@item show version
1465Show what version of @value{GDBN} is running. You should include this
2df3850c
JM
1466information in @value{GDBN} bug-reports. If multiple versions of
1467@value{GDBN} are in use at your site, you may need to determine which
1468version of @value{GDBN} you are running; as @value{GDBN} evolves, new
1469commands are introduced, and old ones may wither away. Also, many
1470system vendors ship variant versions of @value{GDBN}, and there are
96a2c332 1471variant versions of @value{GDBN} in @sc{gnu}/Linux distributions as well.
2df3850c
JM
1472The version number is the same as the one announced when you start
1473@value{GDBN}.
c906108c
SS
1474
1475@kindex show copying
1476@item show copying
1477Display information about permission for copying @value{GDBN}.
1478
1479@kindex show warranty
1480@item show warranty
2df3850c 1481Display the @sc{gnu} ``NO WARRANTY'' statement, or a warranty,
96a2c332 1482if your version of @value{GDBN} comes with one.
2df3850c 1483
c906108c
SS
1484@end table
1485
6d2ebf8b 1486@node Running
c906108c
SS
1487@chapter Running Programs Under @value{GDBN}
1488
1489When you run a program under @value{GDBN}, you must first generate
1490debugging information when you compile it.
7a292a7a
SS
1491
1492You may start @value{GDBN} with its arguments, if any, in an environment
1493of your choice. If you are doing native debugging, you may redirect
1494your program's input and output, debug an already running process, or
1495kill a child process.
c906108c
SS
1496
1497@menu
1498* Compilation:: Compiling for debugging
1499* Starting:: Starting your program
c906108c
SS
1500* Arguments:: Your program's arguments
1501* Environment:: Your program's environment
c906108c
SS
1502
1503* Working Directory:: Your program's working directory
1504* Input/Output:: Your program's input and output
1505* Attach:: Debugging an already-running process
1506* Kill Process:: Killing the child process
c906108c
SS
1507
1508* Threads:: Debugging programs with multiple threads
1509* Processes:: Debugging programs with multiple processes
1510@end menu
1511
6d2ebf8b 1512@node Compilation
c906108c
SS
1513@section Compiling for debugging
1514
1515In order to debug a program effectively, you need to generate
1516debugging information when you compile it. This debugging information
1517is stored in the object file; it describes the data type of each
1518variable or function and the correspondence between source line numbers
1519and addresses in the executable code.
1520
1521To request debugging information, specify the @samp{-g} option when you run
1522the compiler.
1523
1524Many C compilers are unable to handle the @samp{-g} and @samp{-O}
1525options together. Using those compilers, you cannot generate optimized
1526executables containing debugging information.
1527
53a5351d
JM
1528@value{NGCC}, the @sc{gnu} C compiler, supports @samp{-g} with or
1529without @samp{-O}, making it possible to debug optimized code. We
1530recommend that you @emph{always} use @samp{-g} whenever you compile a
1531program. You may think your program is correct, but there is no sense
1532in pushing your luck.
c906108c
SS
1533
1534@cindex optimized code, debugging
1535@cindex debugging optimized code
1536When you debug a program compiled with @samp{-g -O}, remember that the
1537optimizer is rearranging your code; the debugger shows you what is
1538really there. Do not be too surprised when the execution path does not
1539exactly match your source file! An extreme example: if you define a
1540variable, but never use it, @value{GDBN} never sees that
1541variable---because the compiler optimizes it out of existence.
1542
1543Some things do not work as well with @samp{-g -O} as with just
1544@samp{-g}, particularly on machines with instruction scheduling. If in
1545doubt, recompile with @samp{-g} alone, and if this fixes the problem,
1546please report it to us as a bug (including a test case!).
1547
1548Older versions of the @sc{gnu} C compiler permitted a variant option
1549@w{@samp{-gg}} for debugging information. @value{GDBN} no longer supports this
1550format; if your @sc{gnu} C compiler has this option, do not use it.
1551
1552@need 2000
6d2ebf8b 1553@node Starting
c906108c
SS
1554@section Starting your program
1555@cindex starting
1556@cindex running
1557
1558@table @code
1559@kindex run
1560@item run
1561@itemx r
7a292a7a
SS
1562Use the @code{run} command to start your program under @value{GDBN}.
1563You must first specify the program name (except on VxWorks) with an
1564argument to @value{GDBN} (@pxref{Invocation, ,Getting In and Out of
1565@value{GDBN}}), or by using the @code{file} or @code{exec-file} command
1566(@pxref{Files, ,Commands to specify files}).
c906108c
SS
1567
1568@end table
1569
c906108c
SS
1570If you are running your program in an execution environment that
1571supports processes, @code{run} creates an inferior process and makes
1572that process run your program. (In environments without processes,
1573@code{run} jumps to the start of your program.)
1574
1575The execution of a program is affected by certain information it
1576receives from its superior. @value{GDBN} provides ways to specify this
1577information, which you must do @emph{before} starting your program. (You
1578can change it after starting your program, but such changes only affect
1579your program the next time you start it.) This information may be
1580divided into four categories:
1581
1582@table @asis
1583@item The @emph{arguments.}
1584Specify the arguments to give your program as the arguments of the
1585@code{run} command. If a shell is available on your target, the shell
1586is used to pass the arguments, so that you may use normal conventions
1587(such as wildcard expansion or variable substitution) in describing
1588the arguments.
1589In Unix systems, you can control which shell is used with the
1590@code{SHELL} environment variable.
1591@xref{Arguments, ,Your program's arguments}.
1592
1593@item The @emph{environment.}
1594Your program normally inherits its environment from @value{GDBN}, but you can
1595use the @value{GDBN} commands @code{set environment} and @code{unset
1596environment} to change parts of the environment that affect
1597your program. @xref{Environment, ,Your program's environment}.
1598
1599@item The @emph{working directory.}
1600Your program inherits its working directory from @value{GDBN}. You can set
1601the @value{GDBN} working directory with the @code{cd} command in @value{GDBN}.
1602@xref{Working Directory, ,Your program's working directory}.
1603
1604@item The @emph{standard input and output.}
1605Your program normally uses the same device for standard input and
1606standard output as @value{GDBN} is using. You can redirect input and output
1607in the @code{run} command line, or you can use the @code{tty} command to
1608set a different device for your program.
1609@xref{Input/Output, ,Your program's input and output}.
1610
1611@cindex pipes
1612@emph{Warning:} While input and output redirection work, you cannot use
1613pipes to pass the output of the program you are debugging to another
1614program; if you attempt this, @value{GDBN} is likely to wind up debugging the
1615wrong program.
1616@end table
c906108c
SS
1617
1618When you issue the @code{run} command, your program begins to execute
1619immediately. @xref{Stopping, ,Stopping and continuing}, for discussion
1620of how to arrange for your program to stop. Once your program has
1621stopped, you may call functions in your program, using the @code{print}
1622or @code{call} commands. @xref{Data, ,Examining Data}.
1623
1624If the modification time of your symbol file has changed since the last
1625time @value{GDBN} read its symbols, @value{GDBN} discards its symbol
1626table, and reads it again. When it does this, @value{GDBN} tries to retain
1627your current breakpoints.
1628
6d2ebf8b 1629@node Arguments
c906108c
SS
1630@section Your program's arguments
1631
1632@cindex arguments (to your program)
1633The arguments to your program can be specified by the arguments of the
5d161b24 1634@code{run} command.
c906108c
SS
1635They are passed to a shell, which expands wildcard characters and
1636performs redirection of I/O, and thence to your program. Your
1637@code{SHELL} environment variable (if it exists) specifies what shell
1638@value{GDBN} uses. If you do not define @code{SHELL}, @value{GDBN} uses
d4f3574e
SS
1639the default shell (@file{/bin/sh} on Unix).
1640
1641On non-Unix systems, the program is usually invoked directly by
1642@value{GDBN}, which emulates I/O redirection via the appropriate system
1643calls, and the wildcard characters are expanded by the startup code of
1644the program, not by the shell.
c906108c
SS
1645
1646@code{run} with no arguments uses the same arguments used by the previous
1647@code{run}, or those set by the @code{set args} command.
1648
1649@kindex set args
1650@table @code
1651@item set args
1652Specify the arguments to be used the next time your program is run. If
1653@code{set args} has no arguments, @code{run} executes your program
1654with no arguments. Once you have run your program with arguments,
1655using @code{set args} before the next @code{run} is the only way to run
1656it again without arguments.
1657
1658@kindex show args
1659@item show args
1660Show the arguments to give your program when it is started.
1661@end table
1662
6d2ebf8b 1663@node Environment
c906108c
SS
1664@section Your program's environment
1665
1666@cindex environment (of your program)
1667The @dfn{environment} consists of a set of environment variables and
1668their values. Environment variables conventionally record such things as
1669your user name, your home directory, your terminal type, and your search
1670path for programs to run. Usually you set up environment variables with
1671the shell and they are inherited by all the other programs you run. When
1672debugging, it can be useful to try running your program with a modified
1673environment without having to start @value{GDBN} over again.
1674
1675@table @code
1676@kindex path
1677@item path @var{directory}
1678Add @var{directory} to the front of the @code{PATH} environment variable
1679(the search path for executables), for both @value{GDBN} and your program.
d4f3574e
SS
1680You may specify several directory names, separated by whitespace or by a
1681system-dependent separator character (@samp{:} on Unix, @samp{;} on
1682MS-DOS and MS-Windows). If @var{directory} is already in the path, it
1683is moved to the front, so it is searched sooner.
c906108c
SS
1684
1685You can use the string @samp{$cwd} to refer to whatever is the current
1686working directory at the time @value{GDBN} searches the path. If you
1687use @samp{.} instead, it refers to the directory where you executed the
1688@code{path} command. @value{GDBN} replaces @samp{.} in the
1689@var{directory} argument (with the current path) before adding
1690@var{directory} to the search path.
1691@c 'path' is explicitly nonrepeatable, but RMS points out it is silly to
1692@c document that, since repeating it would be a no-op.
1693
1694@kindex show paths
1695@item show paths
1696Display the list of search paths for executables (the @code{PATH}
1697environment variable).
1698
1699@kindex show environment
1700@item show environment @r{[}@var{varname}@r{]}
1701Print the value of environment variable @var{varname} to be given to
1702your program when it starts. If you do not supply @var{varname},
1703print the names and values of all environment variables to be given to
1704your program. You can abbreviate @code{environment} as @code{env}.
1705
1706@kindex set environment
53a5351d 1707@item set environment @var{varname} @r{[}=@var{value}@r{]}
c906108c
SS
1708Set environment variable @var{varname} to @var{value}. The value
1709changes for your program only, not for @value{GDBN} itself. @var{value} may
1710be any string; the values of environment variables are just strings, and
1711any interpretation is supplied by your program itself. The @var{value}
1712parameter is optional; if it is eliminated, the variable is set to a
1713null value.
1714@c "any string" here does not include leading, trailing
1715@c blanks. Gnu asks: does anyone care?
1716
1717For example, this command:
1718
1719@example
1720set env USER = foo
1721@end example
1722
1723@noindent
d4f3574e 1724tells the debugged program, when subsequently run, that its user is named
c906108c
SS
1725@samp{foo}. (The spaces around @samp{=} are used for clarity here; they
1726are not actually required.)
1727
1728@kindex unset environment
1729@item unset environment @var{varname}
1730Remove variable @var{varname} from the environment to be passed to your
1731program. This is different from @samp{set env @var{varname} =};
1732@code{unset environment} removes the variable from the environment,
1733rather than assigning it an empty value.
1734@end table
1735
d4f3574e
SS
1736@emph{Warning:} On Unix systems, @value{GDBN} runs your program using
1737the shell indicated
c906108c
SS
1738by your @code{SHELL} environment variable if it exists (or
1739@code{/bin/sh} if not). If your @code{SHELL} variable names a shell
1740that runs an initialization file---such as @file{.cshrc} for C-shell, or
1741@file{.bashrc} for BASH---any variables you set in that file affect
1742your program. You may wish to move setting of environment variables to
1743files that are only run when you sign on, such as @file{.login} or
1744@file{.profile}.
1745
6d2ebf8b 1746@node Working Directory
c906108c
SS
1747@section Your program's working directory
1748
1749@cindex working directory (of your program)
1750Each time you start your program with @code{run}, it inherits its
1751working directory from the current working directory of @value{GDBN}.
1752The @value{GDBN} working directory is initially whatever it inherited
1753from its parent process (typically the shell), but you can specify a new
1754working directory in @value{GDBN} with the @code{cd} command.
1755
1756The @value{GDBN} working directory also serves as a default for the commands
1757that specify files for @value{GDBN} to operate on. @xref{Files, ,Commands to
1758specify files}.
1759
1760@table @code
1761@kindex cd
1762@item cd @var{directory}
1763Set the @value{GDBN} working directory to @var{directory}.
1764
1765@kindex pwd
1766@item pwd
1767Print the @value{GDBN} working directory.
1768@end table
1769
6d2ebf8b 1770@node Input/Output
c906108c
SS
1771@section Your program's input and output
1772
1773@cindex redirection
1774@cindex i/o
1775@cindex terminal
1776By default, the program you run under @value{GDBN} does input and output to
5d161b24 1777the same terminal that @value{GDBN} uses. @value{GDBN} switches the terminal
c906108c
SS
1778to its own terminal modes to interact with you, but it records the terminal
1779modes your program was using and switches back to them when you continue
1780running your program.
1781
1782@table @code
1783@kindex info terminal
1784@item info terminal
1785Displays information recorded by @value{GDBN} about the terminal modes your
1786program is using.
1787@end table
1788
1789You can redirect your program's input and/or output using shell
1790redirection with the @code{run} command. For example,
1791
1792@example
1793run > outfile
1794@end example
1795
1796@noindent
1797starts your program, diverting its output to the file @file{outfile}.
1798
1799@kindex tty
1800@cindex controlling terminal
1801Another way to specify where your program should do input and output is
1802with the @code{tty} command. This command accepts a file name as
1803argument, and causes this file to be the default for future @code{run}
1804commands. It also resets the controlling terminal for the child
1805process, for future @code{run} commands. For example,
1806
1807@example
1808tty /dev/ttyb
1809@end example
1810
1811@noindent
1812directs that processes started with subsequent @code{run} commands
1813default to do input and output on the terminal @file{/dev/ttyb} and have
1814that as their controlling terminal.
1815
1816An explicit redirection in @code{run} overrides the @code{tty} command's
1817effect on the input/output device, but not its effect on the controlling
1818terminal.
1819
1820When you use the @code{tty} command or redirect input in the @code{run}
1821command, only the input @emph{for your program} is affected. The input
1822for @value{GDBN} still comes from your terminal.
1823
6d2ebf8b 1824@node Attach
c906108c
SS
1825@section Debugging an already-running process
1826@kindex attach
1827@cindex attach
1828
1829@table @code
1830@item attach @var{process-id}
1831This command attaches to a running process---one that was started
1832outside @value{GDBN}. (@code{info files} shows your active
1833targets.) The command takes as argument a process ID. The usual way to
1834find out the process-id of a Unix process is with the @code{ps} utility,
1835or with the @samp{jobs -l} shell command.
1836
1837@code{attach} does not repeat if you press @key{RET} a second time after
1838executing the command.
1839@end table
1840
1841To use @code{attach}, your program must be running in an environment
1842which supports processes; for example, @code{attach} does not work for
1843programs on bare-board targets that lack an operating system. You must
1844also have permission to send the process a signal.
1845
1846When you use @code{attach}, the debugger finds the program running in
1847the process first by looking in the current working directory, then (if
1848the program is not found) by using the source file search path
1849(@pxref{Source Path, ,Specifying source directories}). You can also use
1850the @code{file} command to load the program. @xref{Files, ,Commands to
1851Specify Files}.
1852
1853The first thing @value{GDBN} does after arranging to debug the specified
1854process is to stop it. You can examine and modify an attached process
53a5351d
JM
1855with all the @value{GDBN} commands that are ordinarily available when
1856you start processes with @code{run}. You can insert breakpoints; you
1857can step and continue; you can modify storage. If you would rather the
1858process continue running, you may use the @code{continue} command after
c906108c
SS
1859attaching @value{GDBN} to the process.
1860
1861@table @code
1862@kindex detach
1863@item detach
1864When you have finished debugging the attached process, you can use the
1865@code{detach} command to release it from @value{GDBN} control. Detaching
1866the process continues its execution. After the @code{detach} command,
1867that process and @value{GDBN} become completely independent once more, and you
1868are ready to @code{attach} another process or start one with @code{run}.
1869@code{detach} does not repeat if you press @key{RET} again after
1870executing the command.
1871@end table
1872
1873If you exit @value{GDBN} or use the @code{run} command while you have an
1874attached process, you kill that process. By default, @value{GDBN} asks
1875for confirmation if you try to do either of these things; you can
1876control whether or not you need to confirm by using the @code{set
1877confirm} command (@pxref{Messages/Warnings, ,Optional warnings and
1878messages}).
1879
6d2ebf8b 1880@node Kill Process
c906108c 1881@section Killing the child process
c906108c
SS
1882
1883@table @code
1884@kindex kill
1885@item kill
1886Kill the child process in which your program is running under @value{GDBN}.
1887@end table
1888
1889This command is useful if you wish to debug a core dump instead of a
1890running process. @value{GDBN} ignores any core dump file while your program
1891is running.
1892
1893On some operating systems, a program cannot be executed outside @value{GDBN}
1894while you have breakpoints set on it inside @value{GDBN}. You can use the
1895@code{kill} command in this situation to permit running your program
1896outside the debugger.
1897
1898The @code{kill} command is also useful if you wish to recompile and
1899relink your program, since on many systems it is impossible to modify an
1900executable file while it is running in a process. In this case, when you
1901next type @code{run}, @value{GDBN} notices that the file has changed, and
1902reads the symbol table again (while trying to preserve your current
1903breakpoint settings).
1904
6d2ebf8b 1905@node Threads
c906108c 1906@section Debugging programs with multiple threads
c906108c
SS
1907
1908@cindex threads of execution
1909@cindex multiple threads
1910@cindex switching threads
1911In some operating systems, such as HP-UX and Solaris, a single program
1912may have more than one @dfn{thread} of execution. The precise semantics
1913of threads differ from one operating system to another, but in general
1914the threads of a single program are akin to multiple processes---except
1915that they share one address space (that is, they can all examine and
1916modify the same variables). On the other hand, each thread has its own
1917registers and execution stack, and perhaps private memory.
1918
1919@value{GDBN} provides these facilities for debugging multi-thread
1920programs:
1921
1922@itemize @bullet
1923@item automatic notification of new threads
1924@item @samp{thread @var{threadno}}, a command to switch among threads
1925@item @samp{info threads}, a command to inquire about existing threads
5d161b24 1926@item @samp{thread apply [@var{threadno}] [@var{all}] @var{args}},
c906108c
SS
1927a command to apply a command to a list of threads
1928@item thread-specific breakpoints
1929@end itemize
1930
c906108c
SS
1931@quotation
1932@emph{Warning:} These facilities are not yet available on every
1933@value{GDBN} configuration where the operating system supports threads.
1934If your @value{GDBN} does not support threads, these commands have no
1935effect. For example, a system without thread support shows no output
1936from @samp{info threads}, and always rejects the @code{thread} command,
1937like this:
1938
1939@smallexample
1940(@value{GDBP}) info threads
1941(@value{GDBP}) thread 1
1942Thread ID 1 not known. Use the "info threads" command to
1943see the IDs of currently known threads.
1944@end smallexample
1945@c FIXME to implementors: how hard would it be to say "sorry, this GDB
1946@c doesn't support threads"?
1947@end quotation
c906108c
SS
1948
1949@cindex focus of debugging
1950@cindex current thread
1951The @value{GDBN} thread debugging facility allows you to observe all
1952threads while your program runs---but whenever @value{GDBN} takes
1953control, one thread in particular is always the focus of debugging.
1954This thread is called the @dfn{current thread}. Debugging commands show
1955program information from the perspective of the current thread.
1956
c906108c
SS
1957@kindex New @var{systag}
1958@cindex thread identifier (system)
1959@c FIXME-implementors!! It would be more helpful if the [New...] message
1960@c included GDB's numeric thread handle, so you could just go to that
1961@c thread without first checking `info threads'.
1962Whenever @value{GDBN} detects a new thread in your program, it displays
1963the target system's identification for the thread with a message in the
1964form @samp{[New @var{systag}]}. @var{systag} is a thread identifier
1965whose form varies depending on the particular system. For example, on
1966LynxOS, you might see
1967
1968@example
1969[New process 35 thread 27]
1970@end example
1971
1972@noindent
1973when @value{GDBN} notices a new thread. In contrast, on an SGI system,
1974the @var{systag} is simply something like @samp{process 368}, with no
1975further qualifier.
1976
1977@c FIXME!! (1) Does the [New...] message appear even for the very first
1978@c thread of a program, or does it only appear for the
1979@c second---i.e., when it becomes obvious we have a multithread
1980@c program?
1981@c (2) *Is* there necessarily a first thread always? Or do some
1982@c multithread systems permit starting a program with multiple
5d161b24 1983@c threads ab initio?
c906108c
SS
1984
1985@cindex thread number
1986@cindex thread identifier (GDB)
1987For debugging purposes, @value{GDBN} associates its own thread
1988number---always a single integer---with each thread in your program.
1989
1990@table @code
1991@kindex info threads
1992@item info threads
1993Display a summary of all threads currently in your
1994program. @value{GDBN} displays for each thread (in this order):
1995
1996@enumerate
1997@item the thread number assigned by @value{GDBN}
1998
1999@item the target system's thread identifier (@var{systag})
2000
2001@item the current stack frame summary for that thread
2002@end enumerate
2003
2004@noindent
2005An asterisk @samp{*} to the left of the @value{GDBN} thread number
2006indicates the current thread.
2007
5d161b24 2008For example,
c906108c
SS
2009@end table
2010@c end table here to get a little more width for example
2011
2012@smallexample
2013(@value{GDBP}) info threads
2014 3 process 35 thread 27 0x34e5 in sigpause ()
2015 2 process 35 thread 23 0x34e5 in sigpause ()
2016* 1 process 35 thread 13 main (argc=1, argv=0x7ffffff8)
2017 at threadtest.c:68
2018@end smallexample
53a5351d
JM
2019
2020On HP-UX systems:
c906108c
SS
2021
2022@cindex thread number
2023@cindex thread identifier (GDB)
2024For debugging purposes, @value{GDBN} associates its own thread
2025number---a small integer assigned in thread-creation order---with each
2026thread in your program.
2027
2028@kindex New @var{systag}
2029@cindex thread identifier (system)
2030@c FIXME-implementors!! It would be more helpful if the [New...] message
2031@c included GDB's numeric thread handle, so you could just go to that
2032@c thread without first checking `info threads'.
2033Whenever @value{GDBN} detects a new thread in your program, it displays
2034both @value{GDBN}'s thread number and the target system's identification for the thread with a message in the
2035form @samp{[New @var{systag}]}. @var{systag} is a thread identifier
2036whose form varies depending on the particular system. For example, on
2037HP-UX, you see
2038
2039@example
2040[New thread 2 (system thread 26594)]
2041@end example
2042
2043@noindent
5d161b24 2044when @value{GDBN} notices a new thread.
c906108c
SS
2045
2046@table @code
2047@kindex info threads
2048@item info threads
2049Display a summary of all threads currently in your
2050program. @value{GDBN} displays for each thread (in this order):
2051
2052@enumerate
2053@item the thread number assigned by @value{GDBN}
2054
2055@item the target system's thread identifier (@var{systag})
2056
2057@item the current stack frame summary for that thread
2058@end enumerate
2059
2060@noindent
2061An asterisk @samp{*} to the left of the @value{GDBN} thread number
2062indicates the current thread.
2063
5d161b24 2064For example,
c906108c
SS
2065@end table
2066@c end table here to get a little more width for example
2067
2068@example
2069(@value{GDBP}) info threads
6d2ebf8b
SS
2070 * 3 system thread 26607 worker (wptr=0x7b09c318 "@@") \@*
2071 at quicksort.c:137
2072 2 system thread 26606 0x7b0030d8 in __ksleep () \@*
2073 from /usr/lib/libc.2
2074 1 system thread 27905 0x7b003498 in _brk () \@*
2075 from /usr/lib/libc.2
c906108c 2076@end example
c906108c
SS
2077
2078@table @code
2079@kindex thread @var{threadno}
2080@item thread @var{threadno}
2081Make thread number @var{threadno} the current thread. The command
2082argument @var{threadno} is the internal @value{GDBN} thread number, as
2083shown in the first field of the @samp{info threads} display.
2084@value{GDBN} responds by displaying the system identifier of the thread
2085you selected, and its current stack frame summary:
2086
2087@smallexample
2088@c FIXME!! This example made up; find a @value{GDBN} w/threads and get real one
2089(@value{GDBP}) thread 2
c906108c 2090[Switching to process 35 thread 23]
c906108c
SS
20910x34e5 in sigpause ()
2092@end smallexample
2093
2094@noindent
2095As with the @samp{[New @dots{}]} message, the form of the text after
2096@samp{Switching to} depends on your system's conventions for identifying
5d161b24 2097threads.
c906108c
SS
2098
2099@kindex thread apply
2100@item thread apply [@var{threadno}] [@var{all}] @var{args}
2101The @code{thread apply} command allows you to apply a command to one or
2102more threads. Specify the numbers of the threads that you want affected
2103with the command argument @var{threadno}. @var{threadno} is the internal
2104@value{GDBN} thread number, as shown in the first field of the @samp{info
5d161b24
DB
2105threads} display. To apply a command to all threads, use
2106@code{thread apply all} @var{args}.
c906108c
SS
2107@end table
2108
2109@cindex automatic thread selection
2110@cindex switching threads automatically
2111@cindex threads, automatic switching
2112Whenever @value{GDBN} stops your program, due to a breakpoint or a
2113signal, it automatically selects the thread where that breakpoint or
2114signal happened. @value{GDBN} alerts you to the context switch with a
2115message of the form @samp{[Switching to @var{systag}]} to identify the
2116thread.
2117
2118@xref{Thread Stops,,Stopping and starting multi-thread programs}, for
2119more information about how @value{GDBN} behaves when you stop and start
2120programs with multiple threads.
2121
2122@xref{Set Watchpoints,,Setting watchpoints}, for information about
2123watchpoints in programs with multiple threads.
c906108c 2124
6d2ebf8b 2125@node Processes
c906108c
SS
2126@section Debugging programs with multiple processes
2127
2128@cindex fork, debugging programs which call
2129@cindex multiple processes
2130@cindex processes, multiple
53a5351d
JM
2131On most systems, @value{GDBN} has no special support for debugging
2132programs which create additional processes using the @code{fork}
2133function. When a program forks, @value{GDBN} will continue to debug the
2134parent process and the child process will run unimpeded. If you have
2135set a breakpoint in any code which the child then executes, the child
2136will get a @code{SIGTRAP} signal which (unless it catches the signal)
2137will cause it to terminate.
c906108c
SS
2138
2139However, if you want to debug the child process there is a workaround
2140which isn't too painful. Put a call to @code{sleep} in the code which
2141the child process executes after the fork. It may be useful to sleep
2142only if a certain environment variable is set, or a certain file exists,
2143so that the delay need not occur when you don't want to run @value{GDBN}
2144on the child. While the child is sleeping, use the @code{ps} program to
2145get its process ID. Then tell @value{GDBN} (a new invocation of
2146@value{GDBN} if you are also debugging the parent process) to attach to
d4f3574e 2147the child process (@pxref{Attach}). From that point on you can debug
c906108c 2148the child process just like any other process which you attached to.
c906108c 2149
53a5351d
JM
2150On HP-UX (11.x and later only?), @value{GDBN} provides support for
2151debugging programs that create additional processes using the
2152@code{fork} or @code{vfork} function.
c906108c
SS
2153
2154By default, when a program forks, @value{GDBN} will continue to debug
2155the parent process and the child process will run unimpeded.
2156
2157If you want to follow the child process instead of the parent process,
2158use the command @w{@code{set follow-fork-mode}}.
2159
2160@table @code
2161@kindex set follow-fork-mode
2162@item set follow-fork-mode @var{mode}
2163Set the debugger response to a program call of @code{fork} or
2164@code{vfork}. A call to @code{fork} or @code{vfork} creates a new
2165process. The @var{mode} can be:
2166
2167@table @code
2168@item parent
2169The original process is debugged after a fork. The child process runs
2df3850c 2170unimpeded. This is the default.
c906108c
SS
2171
2172@item child
2173The new process is debugged after a fork. The parent process runs
2174unimpeded.
2175
2176@item ask
2177The debugger will ask for one of the above choices.
2178@end table
2179
2180@item show follow-fork-mode
2df3850c 2181Display the current debugger response to a @code{fork} or @code{vfork} call.
c906108c
SS
2182@end table
2183
2184If you ask to debug a child process and a @code{vfork} is followed by an
2185@code{exec}, @value{GDBN} executes the new target up to the first
2186breakpoint in the new target. If you have a breakpoint set on
2187@code{main} in your original program, the breakpoint will also be set on
2188the child process's @code{main}.
2189
2190When a child process is spawned by @code{vfork}, you cannot debug the
2191child or parent until an @code{exec} call completes.
2192
2193If you issue a @code{run} command to @value{GDBN} after an @code{exec}
2194call executes, the new target restarts. To restart the parent process,
2195use the @code{file} command with the parent executable name as its
2196argument.
2197
2198You can use the @code{catch} command to make @value{GDBN} stop whenever
2199a @code{fork}, @code{vfork}, or @code{exec} call is made. @xref{Set
2200Catchpoints, ,Setting catchpoints}.
c906108c 2201
6d2ebf8b 2202@node Stopping
c906108c
SS
2203@chapter Stopping and Continuing
2204
2205The principal purposes of using a debugger are so that you can stop your
2206program before it terminates; or so that, if your program runs into
2207trouble, you can investigate and find out why.
2208
7a292a7a
SS
2209Inside @value{GDBN}, your program may stop for any of several reasons,
2210such as a signal, a breakpoint, or reaching a new line after a
2211@value{GDBN} command such as @code{step}. You may then examine and
2212change variables, set new breakpoints or remove old ones, and then
2213continue execution. Usually, the messages shown by @value{GDBN} provide
2214ample explanation of the status of your program---but you can also
2215explicitly request this information at any time.
c906108c
SS
2216
2217@table @code
2218@kindex info program
2219@item info program
2220Display information about the status of your program: whether it is
7a292a7a 2221running or not, what process it is, and why it stopped.
c906108c
SS
2222@end table
2223
2224@menu
2225* Breakpoints:: Breakpoints, watchpoints, and catchpoints
2226* Continuing and Stepping:: Resuming execution
c906108c 2227* Signals:: Signals
c906108c 2228* Thread Stops:: Stopping and starting multi-thread programs
c906108c
SS
2229@end menu
2230
6d2ebf8b 2231@node Breakpoints
c906108c
SS
2232@section Breakpoints, watchpoints, and catchpoints
2233
2234@cindex breakpoints
2235A @dfn{breakpoint} makes your program stop whenever a certain point in
2236the program is reached. For each breakpoint, you can add conditions to
2237control in finer detail whether your program stops. You can set
2238breakpoints with the @code{break} command and its variants (@pxref{Set
2239Breaks, ,Setting breakpoints}), to specify the place where your program
2240should stop by line number, function name or exact address in the
2241program.
2242
2243In HP-UX, SunOS 4.x, SVR4, and Alpha OSF/1 configurations, you can set
2244breakpoints in shared libraries before the executable is run. There is
2245a minor limitation on HP-UX systems: you must wait until the executable
2246is run in order to set breakpoints in shared library routines that are
2247not called directly by the program (for example, routines that are
2248arguments in a @code{pthread_create} call).
2249
2250@cindex watchpoints
2251@cindex memory tracing
2252@cindex breakpoint on memory address
2253@cindex breakpoint on variable modification
2254A @dfn{watchpoint} is a special breakpoint that stops your program
2255when the value of an expression changes. You must use a different
2256command to set watchpoints (@pxref{Set Watchpoints, ,Setting
2257watchpoints}), but aside from that, you can manage a watchpoint like
2258any other breakpoint: you enable, disable, and delete both breakpoints
2259and watchpoints using the same commands.
2260
2261You can arrange to have values from your program displayed automatically
2262whenever @value{GDBN} stops at a breakpoint. @xref{Auto Display,,
2263Automatic display}.
2264
2265@cindex catchpoints
2266@cindex breakpoint on events
2267A @dfn{catchpoint} is another special breakpoint that stops your program
2268when a certain kind of event occurs, such as the throwing of a C++
2269exception or the loading of a library. As with watchpoints, you use a
2270different command to set a catchpoint (@pxref{Set Catchpoints, ,Setting
2271catchpoints}), but aside from that, you can manage a catchpoint like any
2272other breakpoint. (To stop when your program receives a signal, use the
d4f3574e 2273@code{handle} command; see @ref{Signals, ,Signals}.)
c906108c
SS
2274
2275@cindex breakpoint numbers
2276@cindex numbers for breakpoints
2277@value{GDBN} assigns a number to each breakpoint, watchpoint, or
2278catchpoint when you create it; these numbers are successive integers
2279starting with one. In many of the commands for controlling various
2280features of breakpoints you use the breakpoint number to say which
2281breakpoint you want to change. Each breakpoint may be @dfn{enabled} or
2282@dfn{disabled}; if disabled, it has no effect on your program until you
2283enable it again.
2284
c5394b80
JM
2285@cindex breakpoint ranges
2286@cindex ranges of breakpoints
2287Some @value{GDBN} commands accept a range of breakpoints on which to
2288operate. A breakpoint range is either a single breakpoint number, like
2289@samp{5}, or two such numbers, in increasing order, separated by a
2290hyphen, like @samp{5-7}. When a breakpoint range is given to a command,
2291all breakpoint in that range are operated on.
2292
c906108c
SS
2293@menu
2294* Set Breaks:: Setting breakpoints
2295* Set Watchpoints:: Setting watchpoints
2296* Set Catchpoints:: Setting catchpoints
2297* Delete Breaks:: Deleting breakpoints
2298* Disabling:: Disabling breakpoints
2299* Conditions:: Break conditions
2300* Break Commands:: Breakpoint command lists
c906108c 2301* Breakpoint Menus:: Breakpoint menus
d4f3574e 2302* Error in Breakpoints:: ``Cannot insert breakpoints''
c906108c
SS
2303@end menu
2304
6d2ebf8b 2305@node Set Breaks
c906108c
SS
2306@subsection Setting breakpoints
2307
5d161b24 2308@c FIXME LMB what does GDB do if no code on line of breakpt?
c906108c
SS
2309@c consider in particular declaration with/without initialization.
2310@c
2311@c FIXME 2 is there stuff on this already? break at fun start, already init?
2312
2313@kindex break
2314@kindex b
2315@kindex $bpnum
2316@cindex latest breakpoint
2317Breakpoints are set with the @code{break} command (abbreviated
5d161b24 2318@code{b}). The debugger convenience variable @samp{$bpnum} records the
c906108c
SS
2319number of the breakpoints you've set most recently; see @ref{Convenience
2320Vars,, Convenience variables}, for a discussion of what you can do with
2321convenience variables.
2322
2323You have several ways to say where the breakpoint should go.
2324
2325@table @code
2326@item break @var{function}
5d161b24 2327Set a breakpoint at entry to function @var{function}.
c906108c
SS
2328When using source languages that permit overloading of symbols, such as
2329C++, @var{function} may refer to more than one possible place to break.
2330@xref{Breakpoint Menus,,Breakpoint menus}, for a discussion of that situation.
c906108c
SS
2331
2332@item break +@var{offset}
2333@itemx break -@var{offset}
2334Set a breakpoint some number of lines forward or back from the position
d4f3574e 2335at which execution stopped in the currently selected @dfn{stack frame}.
2df3850c 2336(@xref{Frames, ,Frames}, for a description of stack frames.)
c906108c
SS
2337
2338@item break @var{linenum}
2339Set a breakpoint at line @var{linenum} in the current source file.
d4f3574e
SS
2340The current source file is the last file whose source text was printed.
2341The breakpoint will stop your program just before it executes any of the
c906108c
SS
2342code on that line.
2343
2344@item break @var{filename}:@var{linenum}
2345Set a breakpoint at line @var{linenum} in source file @var{filename}.
2346
2347@item break @var{filename}:@var{function}
2348Set a breakpoint at entry to function @var{function} found in file
2349@var{filename}. Specifying a file name as well as a function name is
2350superfluous except when multiple files contain similarly named
2351functions.
2352
2353@item break *@var{address}
2354Set a breakpoint at address @var{address}. You can use this to set
2355breakpoints in parts of your program which do not have debugging
2356information or source files.
2357
2358@item break
2359When called without any arguments, @code{break} sets a breakpoint at
2360the next instruction to be executed in the selected stack frame
2361(@pxref{Stack, ,Examining the Stack}). In any selected frame but the
2362innermost, this makes your program stop as soon as control
2363returns to that frame. This is similar to the effect of a
2364@code{finish} command in the frame inside the selected frame---except
2365that @code{finish} does not leave an active breakpoint. If you use
2366@code{break} without an argument in the innermost frame, @value{GDBN} stops
2367the next time it reaches the current location; this may be useful
2368inside loops.
2369
2370@value{GDBN} normally ignores breakpoints when it resumes execution, until at
2371least one instruction has been executed. If it did not do this, you
2372would be unable to proceed past a breakpoint without first disabling the
2373breakpoint. This rule applies whether or not the breakpoint already
2374existed when your program stopped.
2375
2376@item break @dots{} if @var{cond}
2377Set a breakpoint with condition @var{cond}; evaluate the expression
2378@var{cond} each time the breakpoint is reached, and stop only if the
2379value is nonzero---that is, if @var{cond} evaluates as true.
2380@samp{@dots{}} stands for one of the possible arguments described
2381above (or no argument) specifying where to break. @xref{Conditions,
2382,Break conditions}, for more information on breakpoint conditions.
2383
2384@kindex tbreak
2385@item tbreak @var{args}
2386Set a breakpoint enabled only for one stop. @var{args} are the
2387same as for the @code{break} command, and the breakpoint is set in the same
2388way, but the breakpoint is automatically deleted after the first time your
2389program stops there. @xref{Disabling, ,Disabling breakpoints}.
2390
c906108c
SS
2391@kindex hbreak
2392@item hbreak @var{args}
d4f3574e
SS
2393Set a hardware-assisted breakpoint. @var{args} are the same as for the
2394@code{break} command and the breakpoint is set in the same way, but the
c906108c
SS
2395breakpoint requires hardware support and some target hardware may not
2396have this support. The main purpose of this is EPROM/ROM code
d4f3574e
SS
2397debugging, so you can set a breakpoint at an instruction without
2398changing the instruction. This can be used with the new trap-generation
2399provided by SPARClite DSU and some x86-based targets. These targets
2400will generate traps when a program accesses some data or instruction
2401address that is assigned to the debug registers. However the hardware
2402breakpoint registers can take a limited number of breakpoints. For
2403example, on the DSU, only two data breakpoints can be set at a time, and
2404@value{GDBN} will reject this command if more than two are used. Delete
2405or disable unused hardware breakpoints before setting new ones
2406(@pxref{Disabling, ,Disabling}). @xref{Conditions, ,Break conditions}.
c906108c
SS
2407
2408@kindex thbreak
2409@item thbreak @var{args}
2410Set a hardware-assisted breakpoint enabled only for one stop. @var{args}
2411are the same as for the @code{hbreak} command and the breakpoint is set in
5d161b24 2412the same way. However, like the @code{tbreak} command,
c906108c
SS
2413the breakpoint is automatically deleted after the
2414first time your program stops there. Also, like the @code{hbreak}
5d161b24
DB
2415command, the breakpoint requires hardware support and some target hardware
2416may not have this support. @xref{Disabling, ,Disabling breakpoints}.
d4f3574e 2417See also @ref{Conditions, ,Break conditions}.
c906108c
SS
2418
2419@kindex rbreak
2420@cindex regular expression
2421@item rbreak @var{regex}
c906108c 2422Set breakpoints on all functions matching the regular expression
11cf8741
JM
2423@var{regex}. This command sets an unconditional breakpoint on all
2424matches, printing a list of all breakpoints it set. Once these
2425breakpoints are set, they are treated just like the breakpoints set with
2426the @code{break} command. You can delete them, disable them, or make
2427them conditional the same way as any other breakpoint.
2428
2429The syntax of the regular expression is the standard one used with tools
2430like @file{grep}. Note that this is different from the syntax used by
2431shells, so for instance @code{foo*} matches all functions that include
2432an @code{fo} followed by zero or more @code{o}s. There is an implicit
2433@code{.*} leading and trailing the regular expression you supply, so to
2434match only functions that begin with @code{foo}, use @code{^foo}.
c906108c 2435
c906108c
SS
2436When debugging C++ programs, @code{rbreak} is useful for setting
2437breakpoints on overloaded functions that are not members of any special
2438classes.
c906108c
SS
2439
2440@kindex info breakpoints
2441@cindex @code{$_} and @code{info breakpoints}
2442@item info breakpoints @r{[}@var{n}@r{]}
2443@itemx info break @r{[}@var{n}@r{]}
2444@itemx info watchpoints @r{[}@var{n}@r{]}
2445Print a table of all breakpoints, watchpoints, and catchpoints set and
2446not deleted, with the following columns for each breakpoint:
2447
2448@table @emph
2449@item Breakpoint Numbers
2450@item Type
2451Breakpoint, watchpoint, or catchpoint.
2452@item Disposition
2453Whether the breakpoint is marked to be disabled or deleted when hit.
2454@item Enabled or Disabled
2455Enabled breakpoints are marked with @samp{y}. @samp{n} marks breakpoints
2456that are not enabled.
2457@item Address
2df3850c 2458Where the breakpoint is in your program, as a memory address.
c906108c
SS
2459@item What
2460Where the breakpoint is in the source for your program, as a file and
2461line number.
2462@end table
2463
2464@noindent
2465If a breakpoint is conditional, @code{info break} shows the condition on
2466the line following the affected breakpoint; breakpoint commands, if any,
2467are listed after that.
2468
2469@noindent
2470@code{info break} with a breakpoint
2471number @var{n} as argument lists only that breakpoint. The
2472convenience variable @code{$_} and the default examining-address for
2473the @code{x} command are set to the address of the last breakpoint
5d161b24 2474listed (@pxref{Memory, ,Examining memory}).
c906108c
SS
2475
2476@noindent
2477@code{info break} displays a count of the number of times the breakpoint
2478has been hit. This is especially useful in conjunction with the
2479@code{ignore} command. You can ignore a large number of breakpoint
2480hits, look at the breakpoint info to see how many times the breakpoint
2481was hit, and then run again, ignoring one less than that number. This
2482will get you quickly to the last hit of that breakpoint.
2483@end table
2484
2485@value{GDBN} allows you to set any number of breakpoints at the same place in
2486your program. There is nothing silly or meaningless about this. When
2487the breakpoints are conditional, this is even useful
2488(@pxref{Conditions, ,Break conditions}).
2489
2490@cindex negative breakpoint numbers
2491@cindex internal @value{GDBN} breakpoints
2492@value{GDBN} itself sometimes sets breakpoints in your program for special
2493purposes, such as proper handling of @code{longjmp} (in C programs).
2494These internal breakpoints are assigned negative numbers, starting with
2495@code{-1}; @samp{info breakpoints} does not display them.
2496
2497You can see these breakpoints with the @value{GDBN} maintenance command
2498@samp{maint info breakpoints}.
2499
2500@table @code
2501@kindex maint info breakpoints
2502@item maint info breakpoints
2503Using the same format as @samp{info breakpoints}, display both the
2504breakpoints you've set explicitly, and those @value{GDBN} is using for
2505internal purposes. Internal breakpoints are shown with negative
2506breakpoint numbers. The type column identifies what kind of breakpoint
2507is shown:
2508
2509@table @code
2510@item breakpoint
2511Normal, explicitly set breakpoint.
2512
2513@item watchpoint
2514Normal, explicitly set watchpoint.
2515
2516@item longjmp
2517Internal breakpoint, used to handle correctly stepping through
2518@code{longjmp} calls.
2519
2520@item longjmp resume
2521Internal breakpoint at the target of a @code{longjmp}.
2522
2523@item until
2524Temporary internal breakpoint used by the @value{GDBN} @code{until} command.
2525
2526@item finish
2527Temporary internal breakpoint used by the @value{GDBN} @code{finish} command.
2528
c906108c
SS
2529@item shlib events
2530Shared library events.
53a5351d 2531
c906108c 2532@end table
53a5351d 2533
c906108c
SS
2534@end table
2535
2536
6d2ebf8b 2537@node Set Watchpoints
c906108c
SS
2538@subsection Setting watchpoints
2539
2540@cindex setting watchpoints
2541@cindex software watchpoints
2542@cindex hardware watchpoints
2543You can use a watchpoint to stop execution whenever the value of an
2544expression changes, without having to predict a particular place where
2545this may happen.
2546
2547Depending on your system, watchpoints may be implemented in software or
2df3850c 2548hardware. @value{GDBN} does software watchpointing by single-stepping your
c906108c
SS
2549program and testing the variable's value each time, which is hundreds of
2550times slower than normal execution. (But this may still be worth it, to
2551catch errors where you have no clue what part of your program is the
2552culprit.)
2553
d4f3574e 2554On some systems, such as HP-UX, Linux and some other x86-based targets,
2df3850c 2555@value{GDBN} includes support for
c906108c
SS
2556hardware watchpoints, which do not slow down the running of your
2557program.
2558
2559@table @code
2560@kindex watch
2561@item watch @var{expr}
2562Set a watchpoint for an expression. @value{GDBN} will break when @var{expr}
2563is written into by the program and its value changes.
2564
2565@kindex rwatch
2566@item rwatch @var{expr}
2567Set a watchpoint that will break when watch @var{expr} is read by the program.
c906108c
SS
2568
2569@kindex awatch
2570@item awatch @var{expr}
2df3850c 2571Set a watchpoint that will break when @var{expr} is either read or written into
7be570e7 2572by the program.
c906108c
SS
2573
2574@kindex info watchpoints
2575@item info watchpoints
2576This command prints a list of watchpoints, breakpoints, and catchpoints;
2577it is the same as @code{info break}.
2578@end table
2579
2580@value{GDBN} sets a @dfn{hardware watchpoint} if possible. Hardware
2581watchpoints execute very quickly, and the debugger reports a change in
2582value at the exact instruction where the change occurs. If @value{GDBN}
2583cannot set a hardware watchpoint, it sets a software watchpoint, which
2584executes more slowly and reports the change in value at the next
2585statement, not the instruction, after the change occurs.
2586
2587When you issue the @code{watch} command, @value{GDBN} reports
2588
2589@example
2590Hardware watchpoint @var{num}: @var{expr}
2591@end example
2592
2593@noindent
2594if it was able to set a hardware watchpoint.
2595
7be570e7
JM
2596Currently, the @code{awatch} and @code{rwatch} commands can only set
2597hardware watchpoints, because accesses to data that don't change the
2598value of the watched expression cannot be detected without examining
2599every instruction as it is being executed, and @value{GDBN} does not do
2600that currently. If @value{GDBN} finds that it is unable to set a
2601hardware breakpoint with the @code{awatch} or @code{rwatch} command, it
2602will print a message like this:
2603
2604@smallexample
2605Expression cannot be implemented with read/access watchpoint.
2606@end smallexample
2607
2608Sometimes, @value{GDBN} cannot set a hardware watchpoint because the
2609data type of the watched expression is wider than what a hardware
2610watchpoint on the target machine can handle. For example, some systems
2611can only watch regions that are up to 4 bytes wide; on such systems you
2612cannot set hardware watchpoints for an expression that yields a
2613double-precision floating-point number (which is typically 8 bytes
2614wide). As a work-around, it might be possible to break the large region
2615into a series of smaller ones and watch them with separate watchpoints.
2616
2617If you set too many hardware watchpoints, @value{GDBN} might be unable
2618to insert all of them when you resume the execution of your program.
2619Since the precise number of active watchpoints is unknown until such
2620time as the program is about to be resumed, @value{GDBN} might not be
2621able to warn you about this when you set the watchpoints, and the
2622warning will be printed only when the program is resumed:
2623
2624@smallexample
2625Hardware watchpoint @var{num}: Could not insert watchpoint
2626@end smallexample
2627
2628@noindent
2629If this happens, delete or disable some of the watchpoints.
2630
2631The SPARClite DSU will generate traps when a program accesses some data
2632or instruction address that is assigned to the debug registers. For the
2633data addresses, DSU facilitates the @code{watch} command. However the
2634hardware breakpoint registers can only take two data watchpoints, and
2635both watchpoints must be the same kind. For example, you can set two
2636watchpoints with @code{watch} commands, two with @code{rwatch} commands,
2637@strong{or} two with @code{awatch} commands, but you cannot set one
2638watchpoint with one command and the other with a different command.
c906108c
SS
2639@value{GDBN} will reject the command if you try to mix watchpoints.
2640Delete or disable unused watchpoint commands before setting new ones.
2641
2642If you call a function interactively using @code{print} or @code{call},
2df3850c 2643any watchpoints you have set will be inactive until @value{GDBN} reaches another
c906108c
SS
2644kind of breakpoint or the call completes.
2645
7be570e7
JM
2646@value{GDBN} automatically deletes watchpoints that watch local
2647(automatic) variables, or expressions that involve such variables, when
2648they go out of scope, that is, when the execution leaves the block in
2649which these variables were defined. In particular, when the program
2650being debugged terminates, @emph{all} local variables go out of scope,
2651and so only watchpoints that watch global variables remain set. If you
2652rerun the program, you will need to set all such watchpoints again. One
2653way of doing that would be to set a code breakpoint at the entry to the
2654@code{main} function and when it breaks, set all the watchpoints.
2655
c906108c
SS
2656@quotation
2657@cindex watchpoints and threads
2658@cindex threads and watchpoints
c906108c
SS
2659@emph{Warning:} In multi-thread programs, watchpoints have only limited
2660usefulness. With the current watchpoint implementation, @value{GDBN}
2661can only watch the value of an expression @emph{in a single thread}. If
2662you are confident that the expression can only change due to the current
2663thread's activity (and if you are also confident that no other thread
2664can become current), then you can use watchpoints as usual. However,
2665@value{GDBN} may not notice when a non-current thread's activity changes
2666the expression.
53a5351d 2667
d4f3574e 2668@c FIXME: this is almost identical to the previous paragraph.
53a5351d
JM
2669@emph{HP-UX Warning:} In multi-thread programs, software watchpoints
2670have only limited usefulness. If @value{GDBN} creates a software
2671watchpoint, it can only watch the value of an expression @emph{in a
2672single thread}. If you are confident that the expression can only
2673change due to the current thread's activity (and if you are also
2674confident that no other thread can become current), then you can use
2675software watchpoints as usual. However, @value{GDBN} may not notice
2676when a non-current thread's activity changes the expression. (Hardware
2677watchpoints, in contrast, watch an expression in all threads.)
c906108c 2678@end quotation
c906108c 2679
6d2ebf8b 2680@node Set Catchpoints
c906108c 2681@subsection Setting catchpoints
d4f3574e 2682@cindex catchpoints, setting
c906108c
SS
2683@cindex exception handlers
2684@cindex event handling
2685
2686You can use @dfn{catchpoints} to cause the debugger to stop for certain
2687kinds of program events, such as C++ exceptions or the loading of a
2688shared library. Use the @code{catch} command to set a catchpoint.
2689
2690@table @code
2691@kindex catch
2692@item catch @var{event}
2693Stop when @var{event} occurs. @var{event} can be any of the following:
2694@table @code
2695@item throw
2696@kindex catch throw
2697The throwing of a C++ exception.
2698
2699@item catch
2700@kindex catch catch
2701The catching of a C++ exception.
2702
2703@item exec
2704@kindex catch exec
2705A call to @code{exec}. This is currently only available for HP-UX.
2706
2707@item fork
2708@kindex catch fork
2709A call to @code{fork}. This is currently only available for HP-UX.
2710
2711@item vfork
2712@kindex catch vfork
2713A call to @code{vfork}. This is currently only available for HP-UX.
2714
2715@item load
2716@itemx load @var{libname}
2717@kindex catch load
2718The dynamic loading of any shared library, or the loading of the library
2719@var{libname}. This is currently only available for HP-UX.
2720
2721@item unload
2722@itemx unload @var{libname}
2723@kindex catch unload
2724The unloading of any dynamically loaded shared library, or the unloading
2725of the library @var{libname}. This is currently only available for HP-UX.
2726@end table
2727
2728@item tcatch @var{event}
2729Set a catchpoint that is enabled only for one stop. The catchpoint is
2730automatically deleted after the first time the event is caught.
2731
2732@end table
2733
2734Use the @code{info break} command to list the current catchpoints.
2735
2736There are currently some limitations to C++ exception handling
2737(@code{catch throw} and @code{catch catch}) in @value{GDBN}:
2738
2739@itemize @bullet
2740@item
2741If you call a function interactively, @value{GDBN} normally returns
2742control to you when the function has finished executing. If the call
2743raises an exception, however, the call may bypass the mechanism that
2744returns control to you and cause your program either to abort or to
2745simply continue running until it hits a breakpoint, catches a signal
2746that @value{GDBN} is listening for, or exits. This is the case even if
2747you set a catchpoint for the exception; catchpoints on exceptions are
2748disabled within interactive calls.
2749
2750@item
2751You cannot raise an exception interactively.
2752
2753@item
2754You cannot install an exception handler interactively.
2755@end itemize
2756
2757@cindex raise exceptions
2758Sometimes @code{catch} is not the best way to debug exception handling:
2759if you need to know exactly where an exception is raised, it is better to
2760stop @emph{before} the exception handler is called, since that way you
2761can see the stack before any unwinding takes place. If you set a
2762breakpoint in an exception handler instead, it may not be easy to find
2763out where the exception was raised.
2764
2765To stop just before an exception handler is called, you need some
2766knowledge of the implementation. In the case of @sc{gnu} C++, exceptions are
2767raised by calling a library function named @code{__raise_exception}
2768which has the following ANSI C interface:
2769
2770@example
2771 /* @var{addr} is where the exception identifier is stored.
d4f3574e
SS
2772 @var{id} is the exception identifier. */
2773 void __raise_exception (void **addr, void *id);
c906108c
SS
2774@end example
2775
2776@noindent
2777To make the debugger catch all exceptions before any stack
2778unwinding takes place, set a breakpoint on @code{__raise_exception}
2779(@pxref{Breakpoints, ,Breakpoints; watchpoints; and exceptions}).
2780
2781With a conditional breakpoint (@pxref{Conditions, ,Break conditions})
2782that depends on the value of @var{id}, you can stop your program when
2783a specific exception is raised. You can use multiple conditional
2784breakpoints to stop your program when any of a number of exceptions are
2785raised.
2786
2787
6d2ebf8b 2788@node Delete Breaks
c906108c
SS
2789@subsection Deleting breakpoints
2790
2791@cindex clearing breakpoints, watchpoints, catchpoints
2792@cindex deleting breakpoints, watchpoints, catchpoints
2793It is often necessary to eliminate a breakpoint, watchpoint, or
2794catchpoint once it has done its job and you no longer want your program
2795to stop there. This is called @dfn{deleting} the breakpoint. A
2796breakpoint that has been deleted no longer exists; it is forgotten.
2797
2798With the @code{clear} command you can delete breakpoints according to
2799where they are in your program. With the @code{delete} command you can
2800delete individual breakpoints, watchpoints, or catchpoints by specifying
2801their breakpoint numbers.
2802
2803It is not necessary to delete a breakpoint to proceed past it. @value{GDBN}
2804automatically ignores breakpoints on the first instruction to be executed
2805when you continue execution without changing the execution address.
2806
2807@table @code
2808@kindex clear
2809@item clear
2810Delete any breakpoints at the next instruction to be executed in the
2811selected stack frame (@pxref{Selection, ,Selecting a frame}). When
2812the innermost frame is selected, this is a good way to delete a
2813breakpoint where your program just stopped.
2814
2815@item clear @var{function}
2816@itemx clear @var{filename}:@var{function}
2817Delete any breakpoints set at entry to the function @var{function}.
2818
2819@item clear @var{linenum}
2820@itemx clear @var{filename}:@var{linenum}
2821Delete any breakpoints set at or within the code of the specified line.
2822
2823@cindex delete breakpoints
2824@kindex delete
2825@kindex d
c5394b80
JM
2826@item delete @r{[}breakpoints@r{]} @r{[}@var{range}@dots{}@r{]}
2827Delete the breakpoints, watchpoints, or catchpoints of the breakpoint
2828ranges specified as arguments. If no argument is specified, delete all
c906108c
SS
2829breakpoints (@value{GDBN} asks confirmation, unless you have @code{set
2830confirm off}). You can abbreviate this command as @code{d}.
2831@end table
2832
6d2ebf8b 2833@node Disabling
c906108c
SS
2834@subsection Disabling breakpoints
2835
2836@kindex disable breakpoints
2837@kindex enable breakpoints
2838Rather than deleting a breakpoint, watchpoint, or catchpoint, you might
2839prefer to @dfn{disable} it. This makes the breakpoint inoperative as if
2840it had been deleted, but remembers the information on the breakpoint so
2841that you can @dfn{enable} it again later.
2842
2843You disable and enable breakpoints, watchpoints, and catchpoints with
2844the @code{enable} and @code{disable} commands, optionally specifying one
2845or more breakpoint numbers as arguments. Use @code{info break} or
2846@code{info watch} to print a list of breakpoints, watchpoints, and
2847catchpoints if you do not know which numbers to use.
2848
2849A breakpoint, watchpoint, or catchpoint can have any of four different
2850states of enablement:
2851
2852@itemize @bullet
2853@item
2854Enabled. The breakpoint stops your program. A breakpoint set
2855with the @code{break} command starts out in this state.
2856@item
2857Disabled. The breakpoint has no effect on your program.
2858@item
2859Enabled once. The breakpoint stops your program, but then becomes
d4f3574e 2860disabled.
c906108c
SS
2861@item
2862Enabled for deletion. The breakpoint stops your program, but
d4f3574e
SS
2863immediately after it does so it is deleted permanently. A breakpoint
2864set with the @code{tbreak} command starts out in this state.
c906108c
SS
2865@end itemize
2866
2867You can use the following commands to enable or disable breakpoints,
2868watchpoints, and catchpoints:
2869
2870@table @code
2871@kindex disable breakpoints
2872@kindex disable
2873@kindex dis
c5394b80 2874@item disable @r{[}breakpoints@r{]} @r{[}@var{range}@dots{}@r{]}
c906108c
SS
2875Disable the specified breakpoints---or all breakpoints, if none are
2876listed. A disabled breakpoint has no effect but is not forgotten. All
2877options such as ignore-counts, conditions and commands are remembered in
2878case the breakpoint is enabled again later. You may abbreviate
2879@code{disable} as @code{dis}.
2880
2881@kindex enable breakpoints
2882@kindex enable
c5394b80 2883@item enable @r{[}breakpoints@r{]} @r{[}@var{range}@dots{}@r{]}
c906108c
SS
2884Enable the specified breakpoints (or all defined breakpoints). They
2885become effective once again in stopping your program.
2886
c5394b80 2887@item enable @r{[}breakpoints@r{]} once @var{range}@dots{}
c906108c
SS
2888Enable the specified breakpoints temporarily. @value{GDBN} disables any
2889of these breakpoints immediately after stopping your program.
2890
c5394b80 2891@item enable @r{[}breakpoints@r{]} delete @var{range}@dots{}
c906108c
SS
2892Enable the specified breakpoints to work once, then die. @value{GDBN}
2893deletes any of these breakpoints as soon as your program stops there.
2894@end table
2895
d4f3574e
SS
2896@c FIXME: I think the following ``Except for [...] @code{tbreak}'' is
2897@c confusing: tbreak is also initially enabled.
c906108c
SS
2898Except for a breakpoint set with @code{tbreak} (@pxref{Set Breaks,
2899,Setting breakpoints}), breakpoints that you set are initially enabled;
2900subsequently, they become disabled or enabled only when you use one of
2901the commands above. (The command @code{until} can set and delete a
2902breakpoint of its own, but it does not change the state of your other
2903breakpoints; see @ref{Continuing and Stepping, ,Continuing and
2904stepping}.)
2905
6d2ebf8b 2906@node Conditions
c906108c
SS
2907@subsection Break conditions
2908@cindex conditional breakpoints
2909@cindex breakpoint conditions
2910
2911@c FIXME what is scope of break condition expr? Context where wanted?
5d161b24 2912@c in particular for a watchpoint?
c906108c
SS
2913The simplest sort of breakpoint breaks every time your program reaches a
2914specified place. You can also specify a @dfn{condition} for a
2915breakpoint. A condition is just a Boolean expression in your
2916programming language (@pxref{Expressions, ,Expressions}). A breakpoint with
2917a condition evaluates the expression each time your program reaches it,
2918and your program stops only if the condition is @emph{true}.
2919
2920This is the converse of using assertions for program validation; in that
2921situation, you want to stop when the assertion is violated---that is,
2922when the condition is false. In C, if you want to test an assertion expressed
2923by the condition @var{assert}, you should set the condition
2924@samp{! @var{assert}} on the appropriate breakpoint.
2925
2926Conditions are also accepted for watchpoints; you may not need them,
2927since a watchpoint is inspecting the value of an expression anyhow---but
2928it might be simpler, say, to just set a watchpoint on a variable name,
2929and specify a condition that tests whether the new value is an interesting
2930one.
2931
2932Break conditions can have side effects, and may even call functions in
2933your program. This can be useful, for example, to activate functions
2934that log program progress, or to use your own print functions to
2935format special data structures. The effects are completely predictable
2936unless there is another enabled breakpoint at the same address. (In
2937that case, @value{GDBN} might see the other breakpoint first and stop your
2938program without checking the condition of this one.) Note that
d4f3574e
SS
2939breakpoint commands are usually more convenient and flexible than break
2940conditions for the
c906108c
SS
2941purpose of performing side effects when a breakpoint is reached
2942(@pxref{Break Commands, ,Breakpoint command lists}).
2943
2944Break conditions can be specified when a breakpoint is set, by using
2945@samp{if} in the arguments to the @code{break} command. @xref{Set
2946Breaks, ,Setting breakpoints}. They can also be changed at any time
2947with the @code{condition} command.
53a5351d 2948
c906108c
SS
2949You can also use the @code{if} keyword with the @code{watch} command.
2950The @code{catch} command does not recognize the @code{if} keyword;
2951@code{condition} is the only way to impose a further condition on a
2952catchpoint.
c906108c
SS
2953
2954@table @code
2955@kindex condition
2956@item condition @var{bnum} @var{expression}
2957Specify @var{expression} as the break condition for breakpoint,
2958watchpoint, or catchpoint number @var{bnum}. After you set a condition,
2959breakpoint @var{bnum} stops your program only if the value of
2960@var{expression} is true (nonzero, in C). When you use
2961@code{condition}, @value{GDBN} checks @var{expression} immediately for
2962syntactic correctness, and to determine whether symbols in it have
d4f3574e
SS
2963referents in the context of your breakpoint. If @var{expression} uses
2964symbols not referenced in the context of the breakpoint, @value{GDBN}
2965prints an error message:
2966
2967@example
2968No symbol "foo" in current context.
2969@end example
2970
2971@noindent
c906108c
SS
2972@value{GDBN} does
2973not actually evaluate @var{expression} at the time the @code{condition}
d4f3574e
SS
2974command (or a command that sets a breakpoint with a condition, like
2975@code{break if @dots{}}) is given, however. @xref{Expressions, ,Expressions}.
c906108c
SS
2976
2977@item condition @var{bnum}
2978Remove the condition from breakpoint number @var{bnum}. It becomes
2979an ordinary unconditional breakpoint.
2980@end table
2981
2982@cindex ignore count (of breakpoint)
2983A special case of a breakpoint condition is to stop only when the
2984breakpoint has been reached a certain number of times. This is so
2985useful that there is a special way to do it, using the @dfn{ignore
2986count} of the breakpoint. Every breakpoint has an ignore count, which
2987is an integer. Most of the time, the ignore count is zero, and
2988therefore has no effect. But if your program reaches a breakpoint whose
2989ignore count is positive, then instead of stopping, it just decrements
2990the ignore count by one and continues. As a result, if the ignore count
2991value is @var{n}, the breakpoint does not stop the next @var{n} times
2992your program reaches it.
2993
2994@table @code
2995@kindex ignore
2996@item ignore @var{bnum} @var{count}
2997Set the ignore count of breakpoint number @var{bnum} to @var{count}.
2998The next @var{count} times the breakpoint is reached, your program's
2999execution does not stop; other than to decrement the ignore count, @value{GDBN}
3000takes no action.
3001
3002To make the breakpoint stop the next time it is reached, specify
3003a count of zero.
3004
3005When you use @code{continue} to resume execution of your program from a
3006breakpoint, you can specify an ignore count directly as an argument to
3007@code{continue}, rather than using @code{ignore}. @xref{Continuing and
3008Stepping,,Continuing and stepping}.
3009
3010If a breakpoint has a positive ignore count and a condition, the
3011condition is not checked. Once the ignore count reaches zero,
3012@value{GDBN} resumes checking the condition.
3013
3014You could achieve the effect of the ignore count with a condition such
3015as @w{@samp{$foo-- <= 0}} using a debugger convenience variable that
3016is decremented each time. @xref{Convenience Vars, ,Convenience
3017variables}.
3018@end table
3019
3020Ignore counts apply to breakpoints, watchpoints, and catchpoints.
3021
3022
6d2ebf8b 3023@node Break Commands
c906108c
SS
3024@subsection Breakpoint command lists
3025
3026@cindex breakpoint commands
3027You can give any breakpoint (or watchpoint or catchpoint) a series of
3028commands to execute when your program stops due to that breakpoint. For
3029example, you might want to print the values of certain expressions, or
3030enable other breakpoints.
3031
3032@table @code
3033@kindex commands
3034@kindex end
3035@item commands @r{[}@var{bnum}@r{]}
3036@itemx @dots{} @var{command-list} @dots{}
3037@itemx end
3038Specify a list of commands for breakpoint number @var{bnum}. The commands
3039themselves appear on the following lines. Type a line containing just
3040@code{end} to terminate the commands.
3041
3042To remove all commands from a breakpoint, type @code{commands} and
3043follow it immediately with @code{end}; that is, give no commands.
3044
3045With no @var{bnum} argument, @code{commands} refers to the last
3046breakpoint, watchpoint, or catchpoint set (not to the breakpoint most
3047recently encountered).
3048@end table
3049
3050Pressing @key{RET} as a means of repeating the last @value{GDBN} command is
3051disabled within a @var{command-list}.
3052
3053You can use breakpoint commands to start your program up again. Simply
3054use the @code{continue} command, or @code{step}, or any other command
3055that resumes execution.
3056
3057Any other commands in the command list, after a command that resumes
3058execution, are ignored. This is because any time you resume execution
3059(even with a simple @code{next} or @code{step}), you may encounter
3060another breakpoint---which could have its own command list, leading to
3061ambiguities about which list to execute.
3062
3063@kindex silent
3064If the first command you specify in a command list is @code{silent}, the
3065usual message about stopping at a breakpoint is not printed. This may
3066be desirable for breakpoints that are to print a specific message and
3067then continue. If none of the remaining commands print anything, you
3068see no sign that the breakpoint was reached. @code{silent} is
3069meaningful only at the beginning of a breakpoint command list.
3070
3071The commands @code{echo}, @code{output}, and @code{printf} allow you to
3072print precisely controlled output, and are often useful in silent
3073breakpoints. @xref{Output, ,Commands for controlled output}.
3074
3075For example, here is how you could use breakpoint commands to print the
3076value of @code{x} at entry to @code{foo} whenever @code{x} is positive.
3077
3078@example
3079break foo if x>0
3080commands
3081silent
3082printf "x is %d\n",x
3083cont
3084end
3085@end example
3086
3087One application for breakpoint commands is to compensate for one bug so
3088you can test for another. Put a breakpoint just after the erroneous line
3089of code, give it a condition to detect the case in which something
3090erroneous has been done, and give it commands to assign correct values
3091to any variables that need them. End with the @code{continue} command
3092so that your program does not stop, and start with the @code{silent}
3093command so that no output is produced. Here is an example:
3094
3095@example
3096break 403
3097commands
3098silent
3099set x = y + 4
3100cont
3101end
3102@end example
3103
6d2ebf8b 3104@node Breakpoint Menus
c906108c
SS
3105@subsection Breakpoint menus
3106@cindex overloading
3107@cindex symbol overloading
3108
3109Some programming languages (notably C++) permit a single function name
3110to be defined several times, for application in different contexts.
3111This is called @dfn{overloading}. When a function name is overloaded,
3112@samp{break @var{function}} is not enough to tell @value{GDBN} where you want
3113a breakpoint. If you realize this is a problem, you can use
3114something like @samp{break @var{function}(@var{types})} to specify which
3115particular version of the function you want. Otherwise, @value{GDBN} offers
3116you a menu of numbered choices for different possible breakpoints, and
3117waits for your selection with the prompt @samp{>}. The first two
3118options are always @samp{[0] cancel} and @samp{[1] all}. Typing @kbd{1}
3119sets a breakpoint at each definition of @var{function}, and typing
3120@kbd{0} aborts the @code{break} command without setting any new
3121breakpoints.
3122
3123For example, the following session excerpt shows an attempt to set a
3124breakpoint at the overloaded symbol @code{String::after}.
3125We choose three particular definitions of that function name:
3126
3127@c FIXME! This is likely to change to show arg type lists, at least
3128@smallexample
3129@group
3130(@value{GDBP}) b String::after
3131[0] cancel
3132[1] all
3133[2] file:String.cc; line number:867
3134[3] file:String.cc; line number:860
3135[4] file:String.cc; line number:875
3136[5] file:String.cc; line number:853
3137[6] file:String.cc; line number:846
3138[7] file:String.cc; line number:735
3139> 2 4 6
3140Breakpoint 1 at 0xb26c: file String.cc, line 867.
3141Breakpoint 2 at 0xb344: file String.cc, line 875.
3142Breakpoint 3 at 0xafcc: file String.cc, line 846.
3143Multiple breakpoints were set.
3144Use the "delete" command to delete unwanted
3145 breakpoints.
3146(@value{GDBP})
3147@end group
3148@end smallexample
c906108c
SS
3149
3150@c @ifclear BARETARGET
6d2ebf8b 3151@node Error in Breakpoints
d4f3574e 3152@subsection ``Cannot insert breakpoints''
c906108c
SS
3153@c
3154@c FIXME!! 14/6/95 Is there a real example of this? Let's use it.
3155@c
d4f3574e
SS
3156Under some operating systems, breakpoints cannot be used in a program if
3157any other process is running that program. In this situation,
5d161b24 3158attempting to run or continue a program with a breakpoint causes
d4f3574e
SS
3159@value{GDBN} to print an error message:
3160
3161@example
3162Cannot insert breakpoints.
3163The same program may be running in another process.
3164@end example
3165
3166When this happens, you have three ways to proceed:
3167
3168@enumerate
3169@item
3170Remove or disable the breakpoints, then continue.
3171
3172@item
5d161b24 3173Suspend @value{GDBN}, and copy the file containing your program to a new
d4f3574e 3174name. Resume @value{GDBN} and use the @code{exec-file} command to specify
5d161b24 3175that @value{GDBN} should run your program under that name.
d4f3574e
SS
3176Then start your program again.
3177
3178@item
3179Relink your program so that the text segment is nonsharable, using the
3180linker option @samp{-N}. The operating system limitation may not apply
3181to nonsharable executables.
3182@end enumerate
c906108c
SS
3183@c @end ifclear
3184
d4f3574e
SS
3185A similar message can be printed if you request too many active
3186hardware-assisted breakpoints and watchpoints:
3187
3188@c FIXME: the precise wording of this message may change; the relevant
3189@c source change is not committed yet (Sep 3, 1999).
3190@smallexample
3191Stopped; cannot insert breakpoints.
3192You may have requested too many hardware breakpoints and watchpoints.
3193@end smallexample
3194
3195@noindent
3196This message is printed when you attempt to resume the program, since
3197only then @value{GDBN} knows exactly how many hardware breakpoints and
3198watchpoints it needs to insert.
3199
3200When this message is printed, you need to disable or remove some of the
3201hardware-assisted breakpoints and watchpoints, and then continue.
3202
3203
6d2ebf8b 3204@node Continuing and Stepping
c906108c
SS
3205@section Continuing and stepping
3206
3207@cindex stepping
3208@cindex continuing
3209@cindex resuming execution
3210@dfn{Continuing} means resuming program execution until your program
3211completes normally. In contrast, @dfn{stepping} means executing just
3212one more ``step'' of your program, where ``step'' may mean either one
3213line of source code, or one machine instruction (depending on what
7a292a7a
SS
3214particular command you use). Either when continuing or when stepping,
3215your program may stop even sooner, due to a breakpoint or a signal. (If
d4f3574e
SS
3216it stops due to a signal, you may want to use @code{handle}, or use
3217@samp{signal 0} to resume execution. @xref{Signals, ,Signals}.)
c906108c
SS
3218
3219@table @code
3220@kindex continue
3221@kindex c
3222@kindex fg
3223@item continue @r{[}@var{ignore-count}@r{]}
3224@itemx c @r{[}@var{ignore-count}@r{]}
3225@itemx fg @r{[}@var{ignore-count}@r{]}
3226Resume program execution, at the address where your program last stopped;
3227any breakpoints set at that address are bypassed. The optional argument
3228@var{ignore-count} allows you to specify a further number of times to
3229ignore a breakpoint at this location; its effect is like that of
3230@code{ignore} (@pxref{Conditions, ,Break conditions}).
3231
3232The argument @var{ignore-count} is meaningful only when your program
3233stopped due to a breakpoint. At other times, the argument to
3234@code{continue} is ignored.
3235
d4f3574e
SS
3236The synonyms @code{c} and @code{fg} (for @dfn{foreground}, as the
3237debugged program is deemed to be the foreground program) are provided
3238purely for convenience, and have exactly the same behavior as
3239@code{continue}.
c906108c
SS
3240@end table
3241
3242To resume execution at a different place, you can use @code{return}
3243(@pxref{Returning, ,Returning from a function}) to go back to the
3244calling function; or @code{jump} (@pxref{Jumping, ,Continuing at a
3245different address}) to go to an arbitrary location in your program.
3246
3247A typical technique for using stepping is to set a breakpoint
3248(@pxref{Breakpoints, ,Breakpoints; watchpoints; and catchpoints}) at the
3249beginning of the function or the section of your program where a problem
3250is believed to lie, run your program until it stops at that breakpoint,
3251and then step through the suspect area, examining the variables that are
3252interesting, until you see the problem happen.
3253
3254@table @code
3255@kindex step
3256@kindex s
3257@item step
3258Continue running your program until control reaches a different source
3259line, then stop it and return control to @value{GDBN}. This command is
3260abbreviated @code{s}.
3261
3262@quotation
3263@c "without debugging information" is imprecise; actually "without line
3264@c numbers in the debugging information". (gcc -g1 has debugging info but
3265@c not line numbers). But it seems complex to try to make that
3266@c distinction here.
3267@emph{Warning:} If you use the @code{step} command while control is
3268within a function that was compiled without debugging information,
3269execution proceeds until control reaches a function that does have
3270debugging information. Likewise, it will not step into a function which
3271is compiled without debugging information. To step through functions
3272without debugging information, use the @code{stepi} command, described
3273below.
3274@end quotation
3275
d4f3574e
SS
3276The @code{step} command only stops at the first instruction of a
3277source line. This prevents the multiple stops that could otherwise occur in
c906108c
SS
3278switch statements, for loops, etc. @code{step} continues to stop if a
3279function that has debugging information is called within the line.
d4f3574e
SS
3280In other words, @code{step} @emph{steps inside} any functions called
3281within the line.
c906108c 3282
d4f3574e
SS
3283Also, the @code{step} command only enters a function if there is line
3284number information for the function. Otherwise it acts like the
5d161b24 3285@code{next} command. This avoids problems when using @code{cc -gl}
c906108c 3286on MIPS machines. Previously, @code{step} entered subroutines if there
5d161b24 3287was any debugging information about the routine.
c906108c
SS
3288
3289@item step @var{count}
3290Continue running as in @code{step}, but do so @var{count} times. If a
7a292a7a
SS
3291breakpoint is reached, or a signal not related to stepping occurs before
3292@var{count} steps, stepping stops right away.
c906108c
SS
3293
3294@kindex next
3295@kindex n
3296@item next @r{[}@var{count}@r{]}
3297Continue to the next source line in the current (innermost) stack frame.
7a292a7a
SS
3298This is similar to @code{step}, but function calls that appear within
3299the line of code are executed without stopping. Execution stops when
3300control reaches a different line of code at the original stack level
3301that was executing when you gave the @code{next} command. This command
3302is abbreviated @code{n}.
c906108c
SS
3303
3304An argument @var{count} is a repeat count, as for @code{step}.
3305
3306
3307@c FIX ME!! Do we delete this, or is there a way it fits in with
3308@c the following paragraph? --- Vctoria
3309@c
3310@c @code{next} within a function that lacks debugging information acts like
3311@c @code{step}, but any function calls appearing within the code of the
3312@c function are executed without stopping.
3313
d4f3574e
SS
3314The @code{next} command only stops at the first instruction of a
3315source line. This prevents multiple stops that could otherwise occur in
5d161b24 3316switch statements, for loops, etc.
c906108c
SS
3317
3318@kindex finish
3319@item finish
3320Continue running until just after function in the selected stack frame
3321returns. Print the returned value (if any).
3322
3323Contrast this with the @code{return} command (@pxref{Returning,
3324,Returning from a function}).
3325
3326@kindex until
3327@kindex u
3328@item until
3329@itemx u
3330Continue running until a source line past the current line, in the
3331current stack frame, is reached. This command is used to avoid single
3332stepping through a loop more than once. It is like the @code{next}
3333command, except that when @code{until} encounters a jump, it
3334automatically continues execution until the program counter is greater
3335than the address of the jump.
3336
3337This means that when you reach the end of a loop after single stepping
3338though it, @code{until} makes your program continue execution until it
3339exits the loop. In contrast, a @code{next} command at the end of a loop
3340simply steps back to the beginning of the loop, which forces you to step
3341through the next iteration.
3342
3343@code{until} always stops your program if it attempts to exit the current
3344stack frame.
3345
3346@code{until} may produce somewhat counterintuitive results if the order
3347of machine code does not match the order of the source lines. For
3348example, in the following excerpt from a debugging session, the @code{f}
3349(@code{frame}) command shows that execution is stopped at line
3350@code{206}; yet when we use @code{until}, we get to line @code{195}:
3351
3352@example
3353(@value{GDBP}) f
3354#0 main (argc=4, argv=0xf7fffae8) at m4.c:206
3355206 expand_input();
3356(@value{GDBP}) until
3357195 for ( ; argc > 0; NEXTARG) @{
3358@end example
3359
3360This happened because, for execution efficiency, the compiler had
3361generated code for the loop closure test at the end, rather than the
3362start, of the loop---even though the test in a C @code{for}-loop is
3363written before the body of the loop. The @code{until} command appeared
3364to step back to the beginning of the loop when it advanced to this
3365expression; however, it has not really gone to an earlier
3366statement---not in terms of the actual machine code.
3367
3368@code{until} with no argument works by means of single
3369instruction stepping, and hence is slower than @code{until} with an
3370argument.
3371
3372@item until @var{location}
3373@itemx u @var{location}
3374Continue running your program until either the specified location is
3375reached, or the current stack frame returns. @var{location} is any of
3376the forms of argument acceptable to @code{break} (@pxref{Set Breaks,
3377,Setting breakpoints}). This form of the command uses breakpoints,
3378and hence is quicker than @code{until} without an argument.
3379
3380@kindex stepi
3381@kindex si
3382@item stepi
96a2c332 3383@itemx stepi @var{arg}
c906108c
SS
3384@itemx si
3385Execute one machine instruction, then stop and return to the debugger.
3386
3387It is often useful to do @samp{display/i $pc} when stepping by machine
3388instructions. This makes @value{GDBN} automatically display the next
3389instruction to be executed, each time your program stops. @xref{Auto
3390Display,, Automatic display}.
3391
3392An argument is a repeat count, as in @code{step}.
3393
3394@need 750
3395@kindex nexti
3396@kindex ni
3397@item nexti
96a2c332 3398@itemx nexti @var{arg}
c906108c
SS
3399@itemx ni
3400Execute one machine instruction, but if it is a function call,
3401proceed until the function returns.
3402
3403An argument is a repeat count, as in @code{next}.
3404@end table
3405
6d2ebf8b 3406@node Signals
c906108c
SS
3407@section Signals
3408@cindex signals
3409
3410A signal is an asynchronous event that can happen in a program. The
3411operating system defines the possible kinds of signals, and gives each
3412kind a name and a number. For example, in Unix @code{SIGINT} is the
d4f3574e 3413signal a program gets when you type an interrupt character (often @kbd{C-c});
c906108c
SS
3414@code{SIGSEGV} is the signal a program gets from referencing a place in
3415memory far away from all the areas in use; @code{SIGALRM} occurs when
3416the alarm clock timer goes off (which happens only if your program has
3417requested an alarm).
3418
3419@cindex fatal signals
3420Some signals, including @code{SIGALRM}, are a normal part of the
3421functioning of your program. Others, such as @code{SIGSEGV}, indicate
d4f3574e 3422errors; these signals are @dfn{fatal} (they kill your program immediately) if the
c906108c
SS
3423program has not specified in advance some other way to handle the signal.
3424@code{SIGINT} does not indicate an error in your program, but it is normally
3425fatal so it can carry out the purpose of the interrupt: to kill the program.
3426
3427@value{GDBN} has the ability to detect any occurrence of a signal in your
3428program. You can tell @value{GDBN} in advance what to do for each kind of
3429signal.
3430
3431@cindex handling signals
3432Normally, @value{GDBN} is set up to ignore non-erroneous signals like @code{SIGALRM}
3433(so as not to interfere with their role in the functioning of your program)
3434but to stop your program immediately whenever an error signal happens.
3435You can change these settings with the @code{handle} command.
3436
3437@table @code
3438@kindex info signals
3439@item info signals
96a2c332 3440@itemx info handle
c906108c
SS
3441Print a table of all the kinds of signals and how @value{GDBN} has been told to
3442handle each one. You can use this to see the signal numbers of all
3443the defined types of signals.
3444
d4f3574e 3445@code{info handle} is an alias for @code{info signals}.
c906108c
SS
3446
3447@kindex handle
3448@item handle @var{signal} @var{keywords}@dots{}
5d161b24 3449Change the way @value{GDBN} handles signal @var{signal}. @var{signal} can
c906108c
SS
3450be the number of a signal or its name (with or without the @samp{SIG} at the
3451beginning). The @var{keywords} say what change to make.
3452@end table
3453
3454@c @group
3455The keywords allowed by the @code{handle} command can be abbreviated.
3456Their full names are:
3457
3458@table @code
3459@item nostop
3460@value{GDBN} should not stop your program when this signal happens. It may
3461still print a message telling you that the signal has come in.
3462
3463@item stop
3464@value{GDBN} should stop your program when this signal happens. This implies
3465the @code{print} keyword as well.
3466
3467@item print
3468@value{GDBN} should print a message when this signal happens.
3469
3470@item noprint
3471@value{GDBN} should not mention the occurrence of the signal at all. This
3472implies the @code{nostop} keyword as well.
3473
3474@item pass
3475@value{GDBN} should allow your program to see this signal; your program
3476can handle the signal, or else it may terminate if the signal is fatal
3477and not handled.
3478
3479@item nopass
3480@value{GDBN} should not allow your program to see this signal.
3481@end table
3482@c @end group
3483
d4f3574e
SS
3484When a signal stops your program, the signal is not visible to the
3485program until you
c906108c
SS
3486continue. Your program sees the signal then, if @code{pass} is in
3487effect for the signal in question @emph{at that time}. In other words,
3488after @value{GDBN} reports a signal, you can use the @code{handle}
3489command with @code{pass} or @code{nopass} to control whether your
3490program sees that signal when you continue.
3491
3492You can also use the @code{signal} command to prevent your program from
3493seeing a signal, or cause it to see a signal it normally would not see,
3494or to give it any signal at any time. For example, if your program stopped
3495due to some sort of memory reference error, you might store correct
3496values into the erroneous variables and continue, hoping to see more
3497execution; but your program would probably terminate immediately as
3498a result of the fatal signal once it saw the signal. To prevent this,
3499you can continue with @samp{signal 0}. @xref{Signaling, ,Giving your
5d161b24 3500program a signal}.
c906108c 3501
6d2ebf8b 3502@node Thread Stops
c906108c
SS
3503@section Stopping and starting multi-thread programs
3504
3505When your program has multiple threads (@pxref{Threads,, Debugging
3506programs with multiple threads}), you can choose whether to set
3507breakpoints on all threads, or on a particular thread.
3508
3509@table @code
3510@cindex breakpoints and threads
3511@cindex thread breakpoints
3512@kindex break @dots{} thread @var{threadno}
3513@item break @var{linespec} thread @var{threadno}
3514@itemx break @var{linespec} thread @var{threadno} if @dots{}
3515@var{linespec} specifies source lines; there are several ways of
3516writing them, but the effect is always to specify some source line.
3517
3518Use the qualifier @samp{thread @var{threadno}} with a breakpoint command
3519to specify that you only want @value{GDBN} to stop the program when a
3520particular thread reaches this breakpoint. @var{threadno} is one of the
3521numeric thread identifiers assigned by @value{GDBN}, shown in the first
3522column of the @samp{info threads} display.
3523
3524If you do not specify @samp{thread @var{threadno}} when you set a
3525breakpoint, the breakpoint applies to @emph{all} threads of your
3526program.
3527
3528You can use the @code{thread} qualifier on conditional breakpoints as
3529well; in this case, place @samp{thread @var{threadno}} before the
3530breakpoint condition, like this:
3531
3532@smallexample
2df3850c 3533(@value{GDBP}) break frik.c:13 thread 28 if bartab > lim
c906108c
SS
3534@end smallexample
3535
3536@end table
3537
3538@cindex stopped threads
3539@cindex threads, stopped
3540Whenever your program stops under @value{GDBN} for any reason,
3541@emph{all} threads of execution stop, not just the current thread. This
3542allows you to examine the overall state of the program, including
3543switching between threads, without worrying that things may change
3544underfoot.
3545
3546@cindex continuing threads
3547@cindex threads, continuing
3548Conversely, whenever you restart the program, @emph{all} threads start
3549executing. @emph{This is true even when single-stepping} with commands
5d161b24 3550like @code{step} or @code{next}.
c906108c
SS
3551
3552In particular, @value{GDBN} cannot single-step all threads in lockstep.
3553Since thread scheduling is up to your debugging target's operating
3554system (not controlled by @value{GDBN}), other threads may
3555execute more than one statement while the current thread completes a
3556single step. Moreover, in general other threads stop in the middle of a
3557statement, rather than at a clean statement boundary, when the program
3558stops.
3559
3560You might even find your program stopped in another thread after
3561continuing or even single-stepping. This happens whenever some other
3562thread runs into a breakpoint, a signal, or an exception before the
3563first thread completes whatever you requested.
3564
3565On some OSes, you can lock the OS scheduler and thus allow only a single
3566thread to run.
3567
3568@table @code
3569@item set scheduler-locking @var{mode}
3570Set the scheduler locking mode. If it is @code{off}, then there is no
3571locking and any thread may run at any time. If @code{on}, then only the
3572current thread may run when the inferior is resumed. The @code{step}
3573mode optimizes for single-stepping. It stops other threads from
3574``seizing the prompt'' by preempting the current thread while you are
3575stepping. Other threads will only rarely (or never) get a chance to run
d4f3574e 3576when you step. They are more likely to run when you @samp{next} over a
c906108c 3577function call, and they are completely free to run when you use commands
d4f3574e 3578like @samp{continue}, @samp{until}, or @samp{finish}. However, unless another
c906108c 3579thread hits a breakpoint during its timeslice, they will never steal the
2df3850c 3580@value{GDBN} prompt away from the thread that you are debugging.
c906108c
SS
3581
3582@item show scheduler-locking
3583Display the current scheduler locking mode.
3584@end table
3585
c906108c 3586
6d2ebf8b 3587@node Stack
c906108c
SS
3588@chapter Examining the Stack
3589
3590When your program has stopped, the first thing you need to know is where it
3591stopped and how it got there.
3592
3593@cindex call stack
5d161b24
DB
3594Each time your program performs a function call, information about the call
3595is generated.
3596That information includes the location of the call in your program,
3597the arguments of the call,
c906108c 3598and the local variables of the function being called.
5d161b24 3599The information is saved in a block of data called a @dfn{stack frame}.
c906108c
SS
3600The stack frames are allocated in a region of memory called the @dfn{call
3601stack}.
3602
3603When your program stops, the @value{GDBN} commands for examining the
3604stack allow you to see all of this information.
3605
3606@cindex selected frame
3607One of the stack frames is @dfn{selected} by @value{GDBN} and many
3608@value{GDBN} commands refer implicitly to the selected frame. In
3609particular, whenever you ask @value{GDBN} for the value of a variable in
3610your program, the value is found in the selected frame. There are
3611special @value{GDBN} commands to select whichever frame you are
3612interested in. @xref{Selection, ,Selecting a frame}.
3613
3614When your program stops, @value{GDBN} automatically selects the
5d161b24 3615currently executing frame and describes it briefly, similar to the
c906108c
SS
3616@code{frame} command (@pxref{Frame Info, ,Information about a frame}).
3617
3618@menu
3619* Frames:: Stack frames
3620* Backtrace:: Backtraces
3621* Selection:: Selecting a frame
3622* Frame Info:: Information on a frame
c906108c
SS
3623
3624@end menu
3625
6d2ebf8b 3626@node Frames
c906108c
SS
3627@section Stack frames
3628
d4f3574e 3629@cindex frame, definition
c906108c
SS
3630@cindex stack frame
3631The call stack is divided up into contiguous pieces called @dfn{stack
3632frames}, or @dfn{frames} for short; each frame is the data associated
3633with one call to one function. The frame contains the arguments given
3634to the function, the function's local variables, and the address at
3635which the function is executing.
3636
3637@cindex initial frame
3638@cindex outermost frame
3639@cindex innermost frame
3640When your program is started, the stack has only one frame, that of the
3641function @code{main}. This is called the @dfn{initial} frame or the
3642@dfn{outermost} frame. Each time a function is called, a new frame is
3643made. Each time a function returns, the frame for that function invocation
3644is eliminated. If a function is recursive, there can be many frames for
3645the same function. The frame for the function in which execution is
3646actually occurring is called the @dfn{innermost} frame. This is the most
3647recently created of all the stack frames that still exist.
3648
3649@cindex frame pointer
3650Inside your program, stack frames are identified by their addresses. A
3651stack frame consists of many bytes, each of which has its own address; each
3652kind of computer has a convention for choosing one byte whose
3653address serves as the address of the frame. Usually this address is kept
3654in a register called the @dfn{frame pointer register} while execution is
3655going on in that frame.
3656
3657@cindex frame number
3658@value{GDBN} assigns numbers to all existing stack frames, starting with
3659zero for the innermost frame, one for the frame that called it,
3660and so on upward. These numbers do not really exist in your program;
3661they are assigned by @value{GDBN} to give you a way of designating stack
3662frames in @value{GDBN} commands.
3663
6d2ebf8b
SS
3664@c The -fomit-frame-pointer below perennially causes hbox overflow
3665@c underflow problems.
c906108c
SS
3666@cindex frameless execution
3667Some compilers provide a way to compile functions so that they operate
6d2ebf8b
SS
3668without stack frames. (For example, the @value{GCC} option
3669@example
3670@samp{-fomit-frame-pointer}
3671@end example
3672generates functions without a frame.)
c906108c
SS
3673This is occasionally done with heavily used library functions to save
3674the frame setup time. @value{GDBN} has limited facilities for dealing
3675with these function invocations. If the innermost function invocation
3676has no stack frame, @value{GDBN} nevertheless regards it as though
3677it had a separate frame, which is numbered zero as usual, allowing
3678correct tracing of the function call chain. However, @value{GDBN} has
3679no provision for frameless functions elsewhere in the stack.
3680
3681@table @code
d4f3574e 3682@kindex frame@r{, command}
c906108c 3683@item frame @var{args}
5d161b24 3684The @code{frame} command allows you to move from one stack frame to another,
c906108c 3685and to print the stack frame you select. @var{args} may be either the
5d161b24
DB
3686address of the frame or the stack frame number. Without an argument,
3687@code{frame} prints the current stack frame.
c906108c
SS
3688
3689@kindex select-frame
3690@item select-frame
3691The @code{select-frame} command allows you to move from one stack frame
3692to another without printing the frame. This is the silent version of
3693@code{frame}.
3694@end table
3695
6d2ebf8b 3696@node Backtrace
c906108c
SS
3697@section Backtraces
3698
3699@cindex backtraces
3700@cindex tracebacks
3701@cindex stack traces
3702A backtrace is a summary of how your program got where it is. It shows one
3703line per frame, for many frames, starting with the currently executing
3704frame (frame zero), followed by its caller (frame one), and on up the
3705stack.
3706
3707@table @code
3708@kindex backtrace
3709@kindex bt
3710@item backtrace
3711@itemx bt
3712Print a backtrace of the entire stack: one line per frame for all
3713frames in the stack.
3714
3715You can stop the backtrace at any time by typing the system interrupt
3716character, normally @kbd{C-c}.
3717
3718@item backtrace @var{n}
3719@itemx bt @var{n}
3720Similar, but print only the innermost @var{n} frames.
3721
3722@item backtrace -@var{n}
3723@itemx bt -@var{n}
3724Similar, but print only the outermost @var{n} frames.
3725@end table
3726
3727@kindex where
3728@kindex info stack
3729@kindex info s
3730The names @code{where} and @code{info stack} (abbreviated @code{info s})
3731are additional aliases for @code{backtrace}.
3732
3733Each line in the backtrace shows the frame number and the function name.
3734The program counter value is also shown---unless you use @code{set
3735print address off}. The backtrace also shows the source file name and
3736line number, as well as the arguments to the function. The program
3737counter value is omitted if it is at the beginning of the code for that
3738line number.
3739
3740Here is an example of a backtrace. It was made with the command
3741@samp{bt 3}, so it shows the innermost three frames.
3742
3743@smallexample
3744@group
5d161b24 3745#0 m4_traceon (obs=0x24eb0, argc=1, argv=0x2b8c8)
c906108c
SS
3746 at builtin.c:993
3747#1 0x6e38 in expand_macro (sym=0x2b600) at macro.c:242
3748#2 0x6840 in expand_token (obs=0x0, t=177664, td=0xf7fffb08)
3749 at macro.c:71
3750(More stack frames follow...)
3751@end group
3752@end smallexample
3753
3754@noindent
3755The display for frame zero does not begin with a program counter
3756value, indicating that your program has stopped at the beginning of the
3757code for line @code{993} of @code{builtin.c}.
3758
6d2ebf8b 3759@node Selection
c906108c
SS
3760@section Selecting a frame
3761
3762Most commands for examining the stack and other data in your program work on
3763whichever stack frame is selected at the moment. Here are the commands for
3764selecting a stack frame; all of them finish by printing a brief description
3765of the stack frame just selected.
3766
3767@table @code
d4f3574e 3768@kindex frame@r{, selecting}
c906108c
SS
3769@kindex f
3770@item frame @var{n}
3771@itemx f @var{n}
3772Select frame number @var{n}. Recall that frame zero is the innermost
3773(currently executing) frame, frame one is the frame that called the
3774innermost one, and so on. The highest-numbered frame is the one for
3775@code{main}.
3776
3777@item frame @var{addr}
3778@itemx f @var{addr}
3779Select the frame at address @var{addr}. This is useful mainly if the
3780chaining of stack frames has been damaged by a bug, making it
3781impossible for @value{GDBN} to assign numbers properly to all frames. In
3782addition, this can be useful when your program has multiple stacks and
3783switches between them.
3784
c906108c
SS
3785On the SPARC architecture, @code{frame} needs two addresses to
3786select an arbitrary frame: a frame pointer and a stack pointer.
3787
3788On the MIPS and Alpha architecture, it needs two addresses: a stack
3789pointer and a program counter.
3790
3791On the 29k architecture, it needs three addresses: a register stack
3792pointer, a program counter, and a memory stack pointer.
3793@c note to future updaters: this is conditioned on a flag
3794@c SETUP_ARBITRARY_FRAME in the tm-*.h files. The above is up to date
3795@c as of 27 Jan 1994.
c906108c
SS
3796
3797@kindex up
3798@item up @var{n}
3799Move @var{n} frames up the stack. For positive numbers @var{n}, this
3800advances toward the outermost frame, to higher frame numbers, to frames
3801that have existed longer. @var{n} defaults to one.
3802
3803@kindex down
3804@kindex do
3805@item down @var{n}
3806Move @var{n} frames down the stack. For positive numbers @var{n}, this
3807advances toward the innermost frame, to lower frame numbers, to frames
3808that were created more recently. @var{n} defaults to one. You may
3809abbreviate @code{down} as @code{do}.
3810@end table
3811
3812All of these commands end by printing two lines of output describing the
3813frame. The first line shows the frame number, the function name, the
3814arguments, and the source file and line number of execution in that
5d161b24 3815frame. The second line shows the text of that source line.
c906108c
SS
3816
3817@need 1000
3818For example:
3819
3820@smallexample
3821@group
3822(@value{GDBP}) up
3823#1 0x22f0 in main (argc=1, argv=0xf7fffbf4, env=0xf7fffbfc)
3824 at env.c:10
382510 read_input_file (argv[i]);
3826@end group
3827@end smallexample
3828
3829After such a printout, the @code{list} command with no arguments
3830prints ten lines centered on the point of execution in the frame.
3831@xref{List, ,Printing source lines}.
3832
3833@table @code
3834@kindex down-silently
3835@kindex up-silently
3836@item up-silently @var{n}
3837@itemx down-silently @var{n}
3838These two commands are variants of @code{up} and @code{down},
3839respectively; they differ in that they do their work silently, without
3840causing display of the new frame. They are intended primarily for use
3841in @value{GDBN} command scripts, where the output might be unnecessary and
3842distracting.
3843@end table
3844
6d2ebf8b 3845@node Frame Info
c906108c
SS
3846@section Information about a frame
3847
3848There are several other commands to print information about the selected
3849stack frame.
3850
3851@table @code
3852@item frame
3853@itemx f
3854When used without any argument, this command does not change which
3855frame is selected, but prints a brief description of the currently
3856selected stack frame. It can be abbreviated @code{f}. With an
3857argument, this command is used to select a stack frame.
3858@xref{Selection, ,Selecting a frame}.
3859
3860@kindex info frame
3861@kindex info f
3862@item info frame
3863@itemx info f
3864This command prints a verbose description of the selected stack frame,
3865including:
3866
3867@itemize @bullet
5d161b24
DB
3868@item
3869the address of the frame
c906108c
SS
3870@item
3871the address of the next frame down (called by this frame)
3872@item
3873the address of the next frame up (caller of this frame)
3874@item
3875the language in which the source code corresponding to this frame is written
3876@item
3877the address of the frame's arguments
3878@item
d4f3574e
SS
3879the address of the frame's local variables
3880@item
c906108c
SS
3881the program counter saved in it (the address of execution in the caller frame)
3882@item
3883which registers were saved in the frame
3884@end itemize
3885
3886@noindent The verbose description is useful when
3887something has gone wrong that has made the stack format fail to fit
3888the usual conventions.
3889
3890@item info frame @var{addr}
3891@itemx info f @var{addr}
3892Print a verbose description of the frame at address @var{addr}, without
3893selecting that frame. The selected frame remains unchanged by this
3894command. This requires the same kind of address (more than one for some
3895architectures) that you specify in the @code{frame} command.
3896@xref{Selection, ,Selecting a frame}.
3897
3898@kindex info args
3899@item info args
3900Print the arguments of the selected frame, each on a separate line.
3901
3902@item info locals
3903@kindex info locals
3904Print the local variables of the selected frame, each on a separate
3905line. These are all variables (declared either static or automatic)
3906accessible at the point of execution of the selected frame.
3907
c906108c 3908@kindex info catch
d4f3574e
SS
3909@cindex catch exceptions, list active handlers
3910@cindex exception handlers, how to list
c906108c
SS
3911@item info catch
3912Print a list of all the exception handlers that are active in the
3913current stack frame at the current point of execution. To see other
3914exception handlers, visit the associated frame (using the @code{up},
3915@code{down}, or @code{frame} commands); then type @code{info catch}.
3916@xref{Set Catchpoints, , Setting catchpoints}.
53a5351d 3917
c906108c
SS
3918@end table
3919
c906108c 3920
6d2ebf8b 3921@node Source
c906108c
SS
3922@chapter Examining Source Files
3923
3924@value{GDBN} can print parts of your program's source, since the debugging
3925information recorded in the program tells @value{GDBN} what source files were
3926used to build it. When your program stops, @value{GDBN} spontaneously prints
3927the line where it stopped. Likewise, when you select a stack frame
3928(@pxref{Selection, ,Selecting a frame}), @value{GDBN} prints the line where
3929execution in that frame has stopped. You can print other portions of
3930source files by explicit command.
3931
7a292a7a 3932If you use @value{GDBN} through its @sc{gnu} Emacs interface, you may
d4f3574e 3933prefer to use Emacs facilities to view source; see @ref{Emacs, ,Using
7a292a7a 3934@value{GDBN} under @sc{gnu} Emacs}.
c906108c
SS
3935
3936@menu
3937* List:: Printing source lines
c906108c 3938* Search:: Searching source files
c906108c
SS
3939* Source Path:: Specifying source directories
3940* Machine Code:: Source and machine code
3941@end menu
3942
6d2ebf8b 3943@node List
c906108c
SS
3944@section Printing source lines
3945
3946@kindex list
3947@kindex l
3948To print lines from a source file, use the @code{list} command
5d161b24 3949(abbreviated @code{l}). By default, ten lines are printed.
c906108c
SS
3950There are several ways to specify what part of the file you want to print.
3951
3952Here are the forms of the @code{list} command most commonly used:
3953
3954@table @code
3955@item list @var{linenum}
3956Print lines centered around line number @var{linenum} in the
3957current source file.
3958
3959@item list @var{function}
3960Print lines centered around the beginning of function
3961@var{function}.
3962
3963@item list
3964Print more lines. If the last lines printed were printed with a
3965@code{list} command, this prints lines following the last lines
3966printed; however, if the last line printed was a solitary line printed
3967as part of displaying a stack frame (@pxref{Stack, ,Examining the
3968Stack}), this prints lines centered around that line.
3969
3970@item list -
3971Print lines just before the lines last printed.
3972@end table
3973
3974By default, @value{GDBN} prints ten source lines with any of these forms of
3975the @code{list} command. You can change this using @code{set listsize}:
3976
3977@table @code
3978@kindex set listsize
3979@item set listsize @var{count}
3980Make the @code{list} command display @var{count} source lines (unless
3981the @code{list} argument explicitly specifies some other number).
3982
3983@kindex show listsize
3984@item show listsize
3985Display the number of lines that @code{list} prints.
3986@end table
3987
3988Repeating a @code{list} command with @key{RET} discards the argument,
3989so it is equivalent to typing just @code{list}. This is more useful
3990than listing the same lines again. An exception is made for an
3991argument of @samp{-}; that argument is preserved in repetition so that
3992each repetition moves up in the source file.
3993
3994@cindex linespec
3995In general, the @code{list} command expects you to supply zero, one or two
3996@dfn{linespecs}. Linespecs specify source lines; there are several ways
d4f3574e 3997of writing them, but the effect is always to specify some source line.
c906108c
SS
3998Here is a complete description of the possible arguments for @code{list}:
3999
4000@table @code
4001@item list @var{linespec}
4002Print lines centered around the line specified by @var{linespec}.
4003
4004@item list @var{first},@var{last}
4005Print lines from @var{first} to @var{last}. Both arguments are
4006linespecs.
4007
4008@item list ,@var{last}
4009Print lines ending with @var{last}.
4010
4011@item list @var{first},
4012Print lines starting with @var{first}.
4013
4014@item list +
4015Print lines just after the lines last printed.
4016
4017@item list -
4018Print lines just before the lines last printed.
4019
4020@item list
4021As described in the preceding table.
4022@end table
4023
4024Here are the ways of specifying a single source line---all the
4025kinds of linespec.
4026
4027@table @code
4028@item @var{number}
4029Specifies line @var{number} of the current source file.
4030When a @code{list} command has two linespecs, this refers to
4031the same source file as the first linespec.
4032
4033@item +@var{offset}
4034Specifies the line @var{offset} lines after the last line printed.
4035When used as the second linespec in a @code{list} command that has
4036two, this specifies the line @var{offset} lines down from the
4037first linespec.
4038
4039@item -@var{offset}
4040Specifies the line @var{offset} lines before the last line printed.
4041
4042@item @var{filename}:@var{number}
4043Specifies line @var{number} in the source file @var{filename}.
4044
4045@item @var{function}
4046Specifies the line that begins the body of the function @var{function}.
4047For example: in C, this is the line with the open brace.
4048
4049@item @var{filename}:@var{function}
4050Specifies the line of the open-brace that begins the body of the
4051function @var{function} in the file @var{filename}. You only need the
4052file name with a function name to avoid ambiguity when there are
4053identically named functions in different source files.
4054
4055@item *@var{address}
4056Specifies the line containing the program address @var{address}.
4057@var{address} may be any expression.
4058@end table
4059
6d2ebf8b 4060@node Search
c906108c
SS
4061@section Searching source files
4062@cindex searching
4063@kindex reverse-search
4064
4065There are two commands for searching through the current source file for a
4066regular expression.
4067
4068@table @code
4069@kindex search
4070@kindex forward-search
4071@item forward-search @var{regexp}
4072@itemx search @var{regexp}
4073The command @samp{forward-search @var{regexp}} checks each line,
4074starting with the one following the last line listed, for a match for
5d161b24 4075@var{regexp}. It lists the line that is found. You can use the
c906108c
SS
4076synonym @samp{search @var{regexp}} or abbreviate the command name as
4077@code{fo}.
4078
4079@item reverse-search @var{regexp}
4080The command @samp{reverse-search @var{regexp}} checks each line, starting
4081with the one before the last line listed and going backward, for a match
4082for @var{regexp}. It lists the line that is found. You can abbreviate
4083this command as @code{rev}.
4084@end table
c906108c 4085
6d2ebf8b 4086@node Source Path
c906108c
SS
4087@section Specifying source directories
4088
4089@cindex source path
4090@cindex directories for source files
4091Executable programs sometimes do not record the directories of the source
4092files from which they were compiled, just the names. Even when they do,
4093the directories could be moved between the compilation and your debugging
4094session. @value{GDBN} has a list of directories to search for source files;
4095this is called the @dfn{source path}. Each time @value{GDBN} wants a source file,
4096it tries all the directories in the list, in the order they are present
4097in the list, until it finds a file with the desired name. Note that
4098the executable search path is @emph{not} used for this purpose. Neither is
4099the current working directory, unless it happens to be in the source
4100path.
4101
4102If @value{GDBN} cannot find a source file in the source path, and the
4103object program records a directory, @value{GDBN} tries that directory
4104too. If the source path is empty, and there is no record of the
4105compilation directory, @value{GDBN} looks in the current directory as a
4106last resort.
4107
4108Whenever you reset or rearrange the source path, @value{GDBN} clears out
4109any information it has cached about where source files are found and where
4110each line is in the file.
4111
4112@kindex directory
4113@kindex dir
d4f3574e
SS
4114When you start @value{GDBN}, its source path includes only @samp{cdir}
4115and @samp{cwd}, in that order.
c906108c
SS
4116To add other directories, use the @code{directory} command.
4117
4118@table @code
4119@item directory @var{dirname} @dots{}
4120@item dir @var{dirname} @dots{}
4121Add directory @var{dirname} to the front of the source path. Several
d4f3574e
SS
4122directory names may be given to this command, separated by @samp{:}
4123(@samp{;} on MS-DOS and MS-Windows, where @samp{:} usually appears as
4124part of absolute file names) or
c906108c
SS
4125whitespace. You may specify a directory that is already in the source
4126path; this moves it forward, so @value{GDBN} searches it sooner.
4127
4128@kindex cdir
4129@kindex cwd
4130@kindex $cdir
4131@kindex $cwd
4132@cindex compilation directory
4133@cindex current directory
4134@cindex working directory
4135@cindex directory, current
4136@cindex directory, compilation
4137You can use the string @samp{$cdir} to refer to the compilation
4138directory (if one is recorded), and @samp{$cwd} to refer to the current
4139working directory. @samp{$cwd} is not the same as @samp{.}---the former
4140tracks the current working directory as it changes during your @value{GDBN}
4141session, while the latter is immediately expanded to the current
4142directory at the time you add an entry to the source path.
4143
4144@item directory
4145Reset the source path to empty again. This requires confirmation.
4146
4147@c RET-repeat for @code{directory} is explicitly disabled, but since
4148@c repeating it would be a no-op we do not say that. (thanks to RMS)
4149
4150@item show directories
4151@kindex show directories
4152Print the source path: show which directories it contains.
4153@end table
4154
4155If your source path is cluttered with directories that are no longer of
4156interest, @value{GDBN} may sometimes cause confusion by finding the wrong
4157versions of source. You can correct the situation as follows:
4158
4159@enumerate
4160@item
4161Use @code{directory} with no argument to reset the source path to empty.
4162
4163@item
4164Use @code{directory} with suitable arguments to reinstall the
4165directories you want in the source path. You can add all the
4166directories in one command.
4167@end enumerate
4168
6d2ebf8b 4169@node Machine Code
c906108c
SS
4170@section Source and machine code
4171
4172You can use the command @code{info line} to map source lines to program
4173addresses (and vice versa), and the command @code{disassemble} to display
4174a range of addresses as machine instructions. When run under @sc{gnu} Emacs
d4f3574e 4175mode, the @code{info line} command causes the arrow to point to the
5d161b24 4176line specified. Also, @code{info line} prints addresses in symbolic form as
c906108c
SS
4177well as hex.
4178
4179@table @code
4180@kindex info line
4181@item info line @var{linespec}
4182Print the starting and ending addresses of the compiled code for
4183source line @var{linespec}. You can specify source lines in any of
4184the ways understood by the @code{list} command (@pxref{List, ,Printing
4185source lines}).
4186@end table
4187
4188For example, we can use @code{info line} to discover the location of
4189the object code for the first line of function
4190@code{m4_changequote}:
4191
d4f3574e
SS
4192@c FIXME: I think this example should also show the addresses in
4193@c symbolic form, as they usually would be displayed.
c906108c 4194@smallexample
96a2c332 4195(@value{GDBP}) info line m4_changequote
c906108c
SS
4196Line 895 of "builtin.c" starts at pc 0x634c and ends at 0x6350.
4197@end smallexample
4198
4199@noindent
4200We can also inquire (using @code{*@var{addr}} as the form for
4201@var{linespec}) what source line covers a particular address:
4202@smallexample
4203(@value{GDBP}) info line *0x63ff
4204Line 926 of "builtin.c" starts at pc 0x63e4 and ends at 0x6404.
4205@end smallexample
4206
4207@cindex @code{$_} and @code{info line}
d4f3574e 4208@kindex x@r{, and }@code{info line}
c906108c
SS
4209After @code{info line}, the default address for the @code{x} command
4210is changed to the starting address of the line, so that @samp{x/i} is
4211sufficient to begin examining the machine code (@pxref{Memory,
4212,Examining memory}). Also, this address is saved as the value of the
4213convenience variable @code{$_} (@pxref{Convenience Vars, ,Convenience
4214variables}).
4215
4216@table @code
4217@kindex disassemble
4218@cindex assembly instructions
4219@cindex instructions, assembly
4220@cindex machine instructions
4221@cindex listing machine instructions
4222@item disassemble
4223This specialized command dumps a range of memory as machine
4224instructions. The default memory range is the function surrounding the
4225program counter of the selected frame. A single argument to this
4226command is a program counter value; @value{GDBN} dumps the function
4227surrounding this value. Two arguments specify a range of addresses
4228(first inclusive, second exclusive) to dump.
4229@end table
4230
c906108c
SS
4231The following example shows the disassembly of a range of addresses of
4232HP PA-RISC 2.0 code:
4233
4234@smallexample
4235(@value{GDBP}) disas 0x32c4 0x32e4
4236Dump of assembler code from 0x32c4 to 0x32e4:
42370x32c4 <main+204>: addil 0,dp
42380x32c8 <main+208>: ldw 0x22c(sr0,r1),r26
42390x32cc <main+212>: ldil 0x3000,r31
42400x32d0 <main+216>: ble 0x3f8(sr4,r31)
42410x32d4 <main+220>: ldo 0(r31),rp
42420x32d8 <main+224>: addil -0x800,dp
42430x32dc <main+228>: ldo 0x588(r1),r26
42440x32e0 <main+232>: ldil 0x3000,r31
4245End of assembler dump.
4246@end smallexample
c906108c
SS
4247
4248Some architectures have more than one commonly-used set of instruction
4249mnemonics or other syntax.
4250
4251@table @code
d4f3574e 4252@kindex set disassembly-flavor
c906108c
SS
4253@cindex assembly instructions
4254@cindex instructions, assembly
4255@cindex machine instructions
4256@cindex listing machine instructions
d4f3574e
SS
4257@cindex Intel disassembly flavor
4258@cindex AT&T disassembly flavor
4259@item set disassembly-flavor @var{instruction-set}
c906108c
SS
4260Select the instruction set to use when disassembling the
4261program via the @code{disassemble} or @code{x/i} commands.
4262
4263Currently this command is only defined for the Intel x86 family. You
d4f3574e
SS
4264can set @var{instruction-set} to either @code{intel} or @code{att}.
4265The default is @code{att}, the AT&T flavor used by default by Unix
4266assemblers for x86-based targets.
c906108c
SS
4267@end table
4268
4269
6d2ebf8b 4270@node Data
c906108c
SS
4271@chapter Examining Data
4272
4273@cindex printing data
4274@cindex examining data
4275@kindex print
4276@kindex inspect
4277@c "inspect" is not quite a synonym if you are using Epoch, which we do not
4278@c document because it is nonstandard... Under Epoch it displays in a
4279@c different window or something like that.
4280The usual way to examine data in your program is with the @code{print}
7a292a7a
SS
4281command (abbreviated @code{p}), or its synonym @code{inspect}. It
4282evaluates and prints the value of an expression of the language your
4283program is written in (@pxref{Languages, ,Using @value{GDBN} with
4284Different Languages}).
c906108c
SS
4285
4286@table @code
d4f3574e
SS
4287@item print @var{expr}
4288@itemx print /@var{f} @var{expr}
4289@var{expr} is an expression (in the source language). By default the
4290value of @var{expr} is printed in a format appropriate to its data type;
c906108c 4291you can choose a different format by specifying @samp{/@var{f}}, where
d4f3574e 4292@var{f} is a letter specifying the format; see @ref{Output Formats,,Output
c906108c
SS
4293formats}.
4294
4295@item print
4296@itemx print /@var{f}
d4f3574e 4297If you omit @var{expr}, @value{GDBN} displays the last value again (from the
c906108c
SS
4298@dfn{value history}; @pxref{Value History, ,Value history}). This allows you to
4299conveniently inspect the same value in an alternative format.
4300@end table
4301
4302A more low-level way of examining data is with the @code{x} command.
4303It examines data in memory at a specified address and prints it in a
4304specified format. @xref{Memory, ,Examining memory}.
4305
7a292a7a 4306If you are interested in information about types, or about how the
d4f3574e
SS
4307fields of a struct or a class are declared, use the @code{ptype @var{exp}}
4308command rather than @code{print}. @xref{Symbols, ,Examining the Symbol
7a292a7a 4309Table}.
c906108c
SS
4310
4311@menu
4312* Expressions:: Expressions
4313* Variables:: Program variables
4314* Arrays:: Artificial arrays
4315* Output Formats:: Output formats
4316* Memory:: Examining memory
4317* Auto Display:: Automatic display
4318* Print Settings:: Print settings
4319* Value History:: Value history
4320* Convenience Vars:: Convenience variables
4321* Registers:: Registers
c906108c 4322* Floating Point Hardware:: Floating point hardware
c906108c
SS
4323@end menu
4324
6d2ebf8b 4325@node Expressions
c906108c
SS
4326@section Expressions
4327
4328@cindex expressions
4329@code{print} and many other @value{GDBN} commands accept an expression and
4330compute its value. Any kind of constant, variable or operator defined
4331by the programming language you are using is valid in an expression in
4332@value{GDBN}. This includes conditional expressions, function calls, casts
4333and string constants. It unfortunately does not include symbols defined
4334by preprocessor @code{#define} commands.
4335
d4f3574e
SS
4336@value{GDBN} supports array constants in expressions input by
4337the user. The syntax is @{@var{element}, @var{element}@dots{}@}. For example,
5d161b24 4338you can use the command @code{print @{1, 2, 3@}} to build up an array in
d4f3574e 4339memory that is @code{malloc}ed in the target program.
c906108c 4340
c906108c
SS
4341Because C is so widespread, most of the expressions shown in examples in
4342this manual are in C. @xref{Languages, , Using @value{GDBN} with Different
4343Languages}, for information on how to use expressions in other
4344languages.
4345
4346In this section, we discuss operators that you can use in @value{GDBN}
4347expressions regardless of your programming language.
4348
4349Casts are supported in all languages, not just in C, because it is so
4350useful to cast a number into a pointer in order to examine a structure
4351at that address in memory.
4352@c FIXME: casts supported---Mod2 true?
c906108c
SS
4353
4354@value{GDBN} supports these operators, in addition to those common
4355to programming languages:
4356
4357@table @code
4358@item @@
4359@samp{@@} is a binary operator for treating parts of memory as arrays.
4360@xref{Arrays, ,Artificial arrays}, for more information.
4361
4362@item ::
4363@samp{::} allows you to specify a variable in terms of the file or
4364function where it is defined. @xref{Variables, ,Program variables}.
4365
4366@cindex @{@var{type}@}
4367@cindex type casting memory
4368@cindex memory, viewing as typed object
4369@cindex casts, to view memory
4370@item @{@var{type}@} @var{addr}
4371Refers to an object of type @var{type} stored at address @var{addr} in
4372memory. @var{addr} may be any expression whose value is an integer or
4373pointer (but parentheses are required around binary operators, just as in
4374a cast). This construct is allowed regardless of what kind of data is
4375normally supposed to reside at @var{addr}.
4376@end table
4377
6d2ebf8b 4378@node Variables
c906108c
SS
4379@section Program variables
4380
4381The most common kind of expression to use is the name of a variable
4382in your program.
4383
4384Variables in expressions are understood in the selected stack frame
4385(@pxref{Selection, ,Selecting a frame}); they must be either:
4386
4387@itemize @bullet
4388@item
4389global (or file-static)
4390@end itemize
4391
5d161b24 4392@noindent or
c906108c
SS
4393
4394@itemize @bullet
4395@item
4396visible according to the scope rules of the
4397programming language from the point of execution in that frame
5d161b24 4398@end itemize
c906108c
SS
4399
4400@noindent This means that in the function
4401
4402@example
4403foo (a)
4404 int a;
4405@{
4406 bar (a);
4407 @{
4408 int b = test ();
4409 bar (b);
4410 @}
4411@}
4412@end example
4413
4414@noindent
4415you can examine and use the variable @code{a} whenever your program is
4416executing within the function @code{foo}, but you can only use or
4417examine the variable @code{b} while your program is executing inside
4418the block where @code{b} is declared.
4419
4420@cindex variable name conflict
4421There is an exception: you can refer to a variable or function whose
4422scope is a single source file even if the current execution point is not
4423in this file. But it is possible to have more than one such variable or
4424function with the same name (in different source files). If that
4425happens, referring to that name has unpredictable effects. If you wish,
4426you can specify a static variable in a particular function or file,
4427using the colon-colon notation:
4428
d4f3574e 4429@cindex colon-colon, context for variables/functions
c906108c
SS
4430@iftex
4431@c info cannot cope with a :: index entry, but why deprive hard copy readers?
4432@kindex ::
4433@end iftex
4434@example
4435@var{file}::@var{variable}
4436@var{function}::@var{variable}
4437@end example
4438
4439@noindent
4440Here @var{file} or @var{function} is the name of the context for the
4441static @var{variable}. In the case of file names, you can use quotes to
4442make sure @value{GDBN} parses the file name as a single word---for example,
4443to print a global value of @code{x} defined in @file{f2.c}:
4444
4445@example
4446(@value{GDBP}) p 'f2.c'::x
4447@end example
4448
c906108c
SS
4449@cindex C++ scope resolution
4450This use of @samp{::} is very rarely in conflict with the very similar
4451use of the same notation in C++. @value{GDBN} also supports use of the C++
4452scope resolution operator in @value{GDBN} expressions.
4453@c FIXME: Um, so what happens in one of those rare cases where it's in
4454@c conflict?? --mew
c906108c
SS
4455
4456@cindex wrong values
4457@cindex variable values, wrong
4458@quotation
4459@emph{Warning:} Occasionally, a local variable may appear to have the
4460wrong value at certain points in a function---just after entry to a new
4461scope, and just before exit.
4462@end quotation
4463You may see this problem when you are stepping by machine instructions.
4464This is because, on most machines, it takes more than one instruction to
4465set up a stack frame (including local variable definitions); if you are
4466stepping by machine instructions, variables may appear to have the wrong
4467values until the stack frame is completely built. On exit, it usually
4468also takes more than one machine instruction to destroy a stack frame;
4469after you begin stepping through that group of instructions, local
4470variable definitions may be gone.
4471
4472This may also happen when the compiler does significant optimizations.
4473To be sure of always seeing accurate values, turn off all optimization
4474when compiling.
4475
d4f3574e
SS
4476@cindex ``No symbol "foo" in current context''
4477Another possible effect of compiler optimizations is to optimize
4478unused variables out of existence, or assign variables to registers (as
4479opposed to memory addresses). Depending on the support for such cases
4480offered by the debug info format used by the compiler, @value{GDBN}
4481might not be able to display values for such local variables. If that
4482happens, @value{GDBN} will print a message like this:
4483
4484@example
4485No symbol "foo" in current context.
4486@end example
4487
4488To solve such problems, either recompile without optimizations, or use a
4489different debug info format, if the compiler supports several such
4490formats. For example, @value{NGCC}, the @sc{gnu} C/C++ compiler usually
4491supports the @samp{-gstabs} option. @samp{-gstabs} produces debug info
4492in a format that is superior to formats such as COFF. You may be able
4493to use DWARF-2 (@samp{-gdwarf-2}), which is also an effective form for
4494debug info. See @ref{Debugging Options,,Options for Debugging Your
4495Program or @sc{gnu} CC, gcc.info, Using @sc{gnu} CC}, for more
4496information.
4497
4498
6d2ebf8b 4499@node Arrays
c906108c
SS
4500@section Artificial arrays
4501
4502@cindex artificial array
4503@kindex @@
4504It is often useful to print out several successive objects of the
4505same type in memory; a section of an array, or an array of
4506dynamically determined size for which only a pointer exists in the
4507program.
4508
4509You can do this by referring to a contiguous span of memory as an
4510@dfn{artificial array}, using the binary operator @samp{@@}. The left
4511operand of @samp{@@} should be the first element of the desired array
4512and be an individual object. The right operand should be the desired length
4513of the array. The result is an array value whose elements are all of
4514the type of the left argument. The first element is actually the left
4515argument; the second element comes from bytes of memory immediately
4516following those that hold the first element, and so on. Here is an
4517example. If a program says
4518
4519@example
4520int *array = (int *) malloc (len * sizeof (int));
4521@end example
4522
4523@noindent
4524you can print the contents of @code{array} with
4525
4526@example
4527p *array@@len
4528@end example
4529
4530The left operand of @samp{@@} must reside in memory. Array values made
4531with @samp{@@} in this way behave just like other arrays in terms of
4532subscripting, and are coerced to pointers when used in expressions.
4533Artificial arrays most often appear in expressions via the value history
4534(@pxref{Value History, ,Value history}), after printing one out.
4535
4536Another way to create an artificial array is to use a cast.
4537This re-interprets a value as if it were an array.
4538The value need not be in memory:
4539@example
4540(@value{GDBP}) p/x (short[2])0x12345678
4541$1 = @{0x1234, 0x5678@}
4542@end example
4543
4544As a convenience, if you leave the array length out (as in
c3f6f71d 4545@samp{(@var{type}[])@var{value}}) @value{GDBN} calculates the size to fill
c906108c
SS
4546the value (as @samp{sizeof(@var{value})/sizeof(@var{type})}:
4547@example
4548(@value{GDBP}) p/x (short[])0x12345678
4549$2 = @{0x1234, 0x5678@}
4550@end example
4551
4552Sometimes the artificial array mechanism is not quite enough; in
4553moderately complex data structures, the elements of interest may not
4554actually be adjacent---for example, if you are interested in the values
4555of pointers in an array. One useful work-around in this situation is
4556to use a convenience variable (@pxref{Convenience Vars, ,Convenience
4557variables}) as a counter in an expression that prints the first
4558interesting value, and then repeat that expression via @key{RET}. For
4559instance, suppose you have an array @code{dtab} of pointers to
4560structures, and you are interested in the values of a field @code{fv}
4561in each structure. Here is an example of what you might type:
4562
4563@example
4564set $i = 0
4565p dtab[$i++]->fv
4566@key{RET}
4567@key{RET}
4568@dots{}
4569@end example
4570
6d2ebf8b 4571@node Output Formats
c906108c
SS
4572@section Output formats
4573
4574@cindex formatted output
4575@cindex output formats
4576By default, @value{GDBN} prints a value according to its data type. Sometimes
4577this is not what you want. For example, you might want to print a number
4578in hex, or a pointer in decimal. Or you might want to view data in memory
4579at a certain address as a character string or as an instruction. To do
4580these things, specify an @dfn{output format} when you print a value.
4581
4582The simplest use of output formats is to say how to print a value
4583already computed. This is done by starting the arguments of the
4584@code{print} command with a slash and a format letter. The format
4585letters supported are:
4586
4587@table @code
4588@item x
4589Regard the bits of the value as an integer, and print the integer in
4590hexadecimal.
4591
4592@item d
4593Print as integer in signed decimal.
4594
4595@item u
4596Print as integer in unsigned decimal.
4597
4598@item o
4599Print as integer in octal.
4600
4601@item t
4602Print as integer in binary. The letter @samp{t} stands for ``two''.
4603@footnote{@samp{b} cannot be used because these format letters are also
4604used with the @code{x} command, where @samp{b} stands for ``byte'';
d4f3574e 4605see @ref{Memory,,Examining memory}.}
c906108c
SS
4606
4607@item a
4608@cindex unknown address, locating
4609Print as an address, both absolute in hexadecimal and as an offset from
4610the nearest preceding symbol. You can use this format used to discover
4611where (in what function) an unknown address is located:
4612
4613@example
4614(@value{GDBP}) p/a 0x54320
4615$3 = 0x54320 <_initialize_vx+396>
4616@end example
4617
4618@item c
4619Regard as an integer and print it as a character constant.
4620
4621@item f
4622Regard the bits of the value as a floating point number and print
4623using typical floating point syntax.
4624@end table
4625
4626For example, to print the program counter in hex (@pxref{Registers}), type
4627
4628@example
4629p/x $pc
4630@end example
4631
4632@noindent
4633Note that no space is required before the slash; this is because command
4634names in @value{GDBN} cannot contain a slash.
4635
4636To reprint the last value in the value history with a different format,
4637you can use the @code{print} command with just a format and no
4638expression. For example, @samp{p/x} reprints the last value in hex.
4639
6d2ebf8b 4640@node Memory
c906108c
SS
4641@section Examining memory
4642
4643You can use the command @code{x} (for ``examine'') to examine memory in
4644any of several formats, independently of your program's data types.
4645
4646@cindex examining memory
4647@table @code
4648@kindex x
4649@item x/@var{nfu} @var{addr}
4650@itemx x @var{addr}
4651@itemx x
4652Use the @code{x} command to examine memory.
4653@end table
4654
4655@var{n}, @var{f}, and @var{u} are all optional parameters that specify how
4656much memory to display and how to format it; @var{addr} is an
4657expression giving the address where you want to start displaying memory.
4658If you use defaults for @var{nfu}, you need not type the slash @samp{/}.
4659Several commands set convenient defaults for @var{addr}.
4660
4661@table @r
4662@item @var{n}, the repeat count
4663The repeat count is a decimal integer; the default is 1. It specifies
4664how much memory (counting by units @var{u}) to display.
4665@c This really is **decimal**; unaffected by 'set radix' as of GDB
4666@c 4.1.2.
4667
4668@item @var{f}, the display format
4669The display format is one of the formats used by @code{print},
4670@samp{s} (null-terminated string), or @samp{i} (machine instruction).
4671The default is @samp{x} (hexadecimal) initially.
4672The default changes each time you use either @code{x} or @code{print}.
4673
4674@item @var{u}, the unit size
4675The unit size is any of
4676
4677@table @code
4678@item b
4679Bytes.
4680@item h
4681Halfwords (two bytes).
4682@item w
4683Words (four bytes). This is the initial default.
4684@item g
4685Giant words (eight bytes).
4686@end table
4687
4688Each time you specify a unit size with @code{x}, that size becomes the
4689default unit the next time you use @code{x}. (For the @samp{s} and
4690@samp{i} formats, the unit size is ignored and is normally not written.)
4691
4692@item @var{addr}, starting display address
4693@var{addr} is the address where you want @value{GDBN} to begin displaying
4694memory. The expression need not have a pointer value (though it may);
4695it is always interpreted as an integer address of a byte of memory.
4696@xref{Expressions, ,Expressions}, for more information on expressions. The default for
4697@var{addr} is usually just after the last address examined---but several
4698other commands also set the default address: @code{info breakpoints} (to
4699the address of the last breakpoint listed), @code{info line} (to the
4700starting address of a line), and @code{print} (if you use it to display
4701a value from memory).
4702@end table
4703
4704For example, @samp{x/3uh 0x54320} is a request to display three halfwords
4705(@code{h}) of memory, formatted as unsigned decimal integers (@samp{u}),
4706starting at address @code{0x54320}. @samp{x/4xw $sp} prints the four
4707words (@samp{w}) of memory above the stack pointer (here, @samp{$sp};
d4f3574e 4708@pxref{Registers, ,Registers}) in hexadecimal (@samp{x}).
c906108c
SS
4709
4710Since the letters indicating unit sizes are all distinct from the
4711letters specifying output formats, you do not have to remember whether
4712unit size or format comes first; either order works. The output
4713specifications @samp{4xw} and @samp{4wx} mean exactly the same thing.
4714(However, the count @var{n} must come first; @samp{wx4} does not work.)
4715
4716Even though the unit size @var{u} is ignored for the formats @samp{s}
4717and @samp{i}, you might still want to use a count @var{n}; for example,
4718@samp{3i} specifies that you want to see three machine instructions,
4719including any operands. The command @code{disassemble} gives an
d4f3574e 4720alternative way of inspecting machine instructions; see @ref{Machine
c906108c
SS
4721Code,,Source and machine code}.
4722
4723All the defaults for the arguments to @code{x} are designed to make it
4724easy to continue scanning memory with minimal specifications each time
4725you use @code{x}. For example, after you have inspected three machine
4726instructions with @samp{x/3i @var{addr}}, you can inspect the next seven
4727with just @samp{x/7}. If you use @key{RET} to repeat the @code{x} command,
4728the repeat count @var{n} is used again; the other arguments default as
4729for successive uses of @code{x}.
4730
4731@cindex @code{$_}, @code{$__}, and value history
4732The addresses and contents printed by the @code{x} command are not saved
4733in the value history because there is often too much of them and they
4734would get in the way. Instead, @value{GDBN} makes these values available for
4735subsequent use in expressions as values of the convenience variables
4736@code{$_} and @code{$__}. After an @code{x} command, the last address
4737examined is available for use in expressions in the convenience variable
4738@code{$_}. The contents of that address, as examined, are available in
4739the convenience variable @code{$__}.
4740
4741If the @code{x} command has a repeat count, the address and contents saved
4742are from the last memory unit printed; this is not the same as the last
4743address printed if several units were printed on the last line of output.
4744
6d2ebf8b 4745@node Auto Display
c906108c
SS
4746@section Automatic display
4747@cindex automatic display
4748@cindex display of expressions
4749
4750If you find that you want to print the value of an expression frequently
4751(to see how it changes), you might want to add it to the @dfn{automatic
4752display list} so that @value{GDBN} prints its value each time your program stops.
4753Each expression added to the list is given a number to identify it;
4754to remove an expression from the list, you specify that number.
4755The automatic display looks like this:
4756
4757@example
47582: foo = 38
47593: bar[5] = (struct hack *) 0x3804
4760@end example
4761
4762@noindent
4763This display shows item numbers, expressions and their current values. As with
4764displays you request manually using @code{x} or @code{print}, you can
4765specify the output format you prefer; in fact, @code{display} decides
4766whether to use @code{print} or @code{x} depending on how elaborate your
4767format specification is---it uses @code{x} if you specify a unit size,
4768or one of the two formats (@samp{i} and @samp{s}) that are only
4769supported by @code{x}; otherwise it uses @code{print}.
4770
4771@table @code
4772@kindex display
d4f3574e
SS
4773@item display @var{expr}
4774Add the expression @var{expr} to the list of expressions to display
c906108c
SS
4775each time your program stops. @xref{Expressions, ,Expressions}.
4776
4777@code{display} does not repeat if you press @key{RET} again after using it.
4778
d4f3574e 4779@item display/@var{fmt} @var{expr}
c906108c 4780For @var{fmt} specifying only a display format and not a size or
d4f3574e 4781count, add the expression @var{expr} to the auto-display list but
c906108c
SS
4782arrange to display it each time in the specified format @var{fmt}.
4783@xref{Output Formats,,Output formats}.
4784
4785@item display/@var{fmt} @var{addr}
4786For @var{fmt} @samp{i} or @samp{s}, or including a unit-size or a
4787number of units, add the expression @var{addr} as a memory address to
4788be examined each time your program stops. Examining means in effect
4789doing @samp{x/@var{fmt} @var{addr}}. @xref{Memory, ,Examining memory}.
4790@end table
4791
4792For example, @samp{display/i $pc} can be helpful, to see the machine
4793instruction about to be executed each time execution stops (@samp{$pc}
d4f3574e 4794is a common name for the program counter; @pxref{Registers, ,Registers}).
c906108c
SS
4795
4796@table @code
4797@kindex delete display
4798@kindex undisplay
4799@item undisplay @var{dnums}@dots{}
4800@itemx delete display @var{dnums}@dots{}
4801Remove item numbers @var{dnums} from the list of expressions to display.
4802
4803@code{undisplay} does not repeat if you press @key{RET} after using it.
4804(Otherwise you would just get the error @samp{No display number @dots{}}.)
4805
4806@kindex disable display
4807@item disable display @var{dnums}@dots{}
4808Disable the display of item numbers @var{dnums}. A disabled display
4809item is not printed automatically, but is not forgotten. It may be
4810enabled again later.
4811
4812@kindex enable display
4813@item enable display @var{dnums}@dots{}
4814Enable display of item numbers @var{dnums}. It becomes effective once
4815again in auto display of its expression, until you specify otherwise.
4816
4817@item display
4818Display the current values of the expressions on the list, just as is
4819done when your program stops.
4820
4821@kindex info display
4822@item info display
4823Print the list of expressions previously set up to display
4824automatically, each one with its item number, but without showing the
4825values. This includes disabled expressions, which are marked as such.
4826It also includes expressions which would not be displayed right now
4827because they refer to automatic variables not currently available.
4828@end table
4829
4830If a display expression refers to local variables, then it does not make
4831sense outside the lexical context for which it was set up. Such an
4832expression is disabled when execution enters a context where one of its
4833variables is not defined. For example, if you give the command
4834@code{display last_char} while inside a function with an argument
4835@code{last_char}, @value{GDBN} displays this argument while your program
4836continues to stop inside that function. When it stops elsewhere---where
4837there is no variable @code{last_char}---the display is disabled
4838automatically. The next time your program stops where @code{last_char}
4839is meaningful, you can enable the display expression once again.
4840
6d2ebf8b 4841@node Print Settings
c906108c
SS
4842@section Print settings
4843
4844@cindex format options
4845@cindex print settings
4846@value{GDBN} provides the following ways to control how arrays, structures,
4847and symbols are printed.
4848
4849@noindent
4850These settings are useful for debugging programs in any language:
4851
4852@table @code
4853@kindex set print address
4854@item set print address
4855@itemx set print address on
4856@value{GDBN} prints memory addresses showing the location of stack
4857traces, structure values, pointer values, breakpoints, and so forth,
4858even when it also displays the contents of those addresses. The default
4859is @code{on}. For example, this is what a stack frame display looks like with
4860@code{set print address on}:
4861
4862@smallexample
4863@group
4864(@value{GDBP}) f
4865#0 set_quotes (lq=0x34c78 "<<", rq=0x34c88 ">>")
4866 at input.c:530
4867530 if (lquote != def_lquote)
4868@end group
4869@end smallexample
4870
4871@item set print address off
4872Do not print addresses when displaying their contents. For example,
4873this is the same stack frame displayed with @code{set print address off}:
4874
4875@smallexample
4876@group
4877(@value{GDBP}) set print addr off
4878(@value{GDBP}) f
4879#0 set_quotes (lq="<<", rq=">>") at input.c:530
4880530 if (lquote != def_lquote)
4881@end group
4882@end smallexample
4883
4884You can use @samp{set print address off} to eliminate all machine
4885dependent displays from the @value{GDBN} interface. For example, with
4886@code{print address off}, you should get the same text for backtraces on
4887all machines---whether or not they involve pointer arguments.
4888
4889@kindex show print address
4890@item show print address
4891Show whether or not addresses are to be printed.
4892@end table
4893
4894When @value{GDBN} prints a symbolic address, it normally prints the
4895closest earlier symbol plus an offset. If that symbol does not uniquely
4896identify the address (for example, it is a name whose scope is a single
4897source file), you may need to clarify. One way to do this is with
4898@code{info line}, for example @samp{info line *0x4537}. Alternately,
4899you can set @value{GDBN} to print the source file and line number when
4900it prints a symbolic address:
4901
4902@table @code
4903@kindex set print symbol-filename
4904@item set print symbol-filename on
4905Tell @value{GDBN} to print the source file name and line number of a
4906symbol in the symbolic form of an address.
4907
4908@item set print symbol-filename off
4909Do not print source file name and line number of a symbol. This is the
4910default.
4911
4912@kindex show print symbol-filename
4913@item show print symbol-filename
4914Show whether or not @value{GDBN} will print the source file name and
4915line number of a symbol in the symbolic form of an address.
4916@end table
4917
4918Another situation where it is helpful to show symbol filenames and line
4919numbers is when disassembling code; @value{GDBN} shows you the line
4920number and source file that corresponds to each instruction.
4921
4922Also, you may wish to see the symbolic form only if the address being
4923printed is reasonably close to the closest earlier symbol:
4924
4925@table @code
4926@kindex set print max-symbolic-offset
4927@item set print max-symbolic-offset @var{max-offset}
4928Tell @value{GDBN} to only display the symbolic form of an address if the
4929offset between the closest earlier symbol and the address is less than
5d161b24 4930@var{max-offset}. The default is 0, which tells @value{GDBN}
c906108c
SS
4931to always print the symbolic form of an address if any symbol precedes it.
4932
4933@kindex show print max-symbolic-offset
4934@item show print max-symbolic-offset
4935Ask how large the maximum offset is that @value{GDBN} prints in a
4936symbolic address.
4937@end table
4938
4939@cindex wild pointer, interpreting
4940@cindex pointer, finding referent
4941If you have a pointer and you are not sure where it points, try
4942@samp{set print symbol-filename on}. Then you can determine the name
4943and source file location of the variable where it points, using
4944@samp{p/a @var{pointer}}. This interprets the address in symbolic form.
4945For example, here @value{GDBN} shows that a variable @code{ptt} points
4946at another variable @code{t}, defined in @file{hi2.c}:
4947
4948@example
4949(@value{GDBP}) set print symbol-filename on
4950(@value{GDBP}) p/a ptt
4951$4 = 0xe008 <t in hi2.c>
4952@end example
4953
4954@quotation
4955@emph{Warning:} For pointers that point to a local variable, @samp{p/a}
4956does not show the symbol name and filename of the referent, even with
4957the appropriate @code{set print} options turned on.
4958@end quotation
4959
4960Other settings control how different kinds of objects are printed:
4961
4962@table @code
4963@kindex set print array
4964@item set print array
4965@itemx set print array on
4966Pretty print arrays. This format is more convenient to read,
4967but uses more space. The default is off.
4968
4969@item set print array off
4970Return to compressed format for arrays.
4971
4972@kindex show print array
4973@item show print array
4974Show whether compressed or pretty format is selected for displaying
4975arrays.
4976
4977@kindex set print elements
4978@item set print elements @var{number-of-elements}
4979Set a limit on how many elements of an array @value{GDBN} will print.
4980If @value{GDBN} is printing a large array, it stops printing after it has
4981printed the number of elements set by the @code{set print elements} command.
4982This limit also applies to the display of strings.
d4f3574e 4983When @value{GDBN} starts, this limit is set to 200.
c906108c
SS
4984Setting @var{number-of-elements} to zero means that the printing is unlimited.
4985
4986@kindex show print elements
4987@item show print elements
4988Display the number of elements of a large array that @value{GDBN} will print.
4989If the number is 0, then the printing is unlimited.
4990
4991@kindex set print null-stop
4992@item set print null-stop
4993Cause @value{GDBN} to stop printing the characters of an array when the first
d4f3574e 4994@sc{null} is encountered. This is useful when large arrays actually
c906108c 4995contain only short strings.
d4f3574e 4996The default is off.
c906108c
SS
4997
4998@kindex set print pretty
4999@item set print pretty on
5d161b24 5000Cause @value{GDBN} to print structures in an indented format with one member
c906108c
SS
5001per line, like this:
5002
5003@smallexample
5004@group
5005$1 = @{
5006 next = 0x0,
5007 flags = @{
5008 sweet = 1,
5009 sour = 1
5010 @},
5011 meat = 0x54 "Pork"
5012@}
5013@end group
5014@end smallexample
5015
5016@item set print pretty off
5017Cause @value{GDBN} to print structures in a compact format, like this:
5018
5019@smallexample
5020@group
5021$1 = @{next = 0x0, flags = @{sweet = 1, sour = 1@}, \
5022meat = 0x54 "Pork"@}
5023@end group
5024@end smallexample
5025
5026@noindent
5027This is the default format.
5028
5029@kindex show print pretty
5030@item show print pretty
5031Show which format @value{GDBN} is using to print structures.
5032
5033@kindex set print sevenbit-strings
5034@item set print sevenbit-strings on
5035Print using only seven-bit characters; if this option is set,
5036@value{GDBN} displays any eight-bit characters (in strings or
5037character values) using the notation @code{\}@var{nnn}. This setting is
5038best if you are working in English (@sc{ascii}) and you use the
5039high-order bit of characters as a marker or ``meta'' bit.
5040
5041@item set print sevenbit-strings off
5042Print full eight-bit characters. This allows the use of more
5043international character sets, and is the default.
5044
5045@kindex show print sevenbit-strings
5046@item show print sevenbit-strings
5047Show whether or not @value{GDBN} is printing only seven-bit characters.
5048
5049@kindex set print union
5050@item set print union on
5d161b24 5051Tell @value{GDBN} to print unions which are contained in structures. This
c906108c
SS
5052is the default setting.
5053
5054@item set print union off
5055Tell @value{GDBN} not to print unions which are contained in structures.
5056
5057@kindex show print union
5058@item show print union
5059Ask @value{GDBN} whether or not it will print unions which are contained in
5060structures.
5061
5062For example, given the declarations
5063
5064@smallexample
5065typedef enum @{Tree, Bug@} Species;
5066typedef enum @{Big_tree, Acorn, Seedling@} Tree_forms;
5d161b24 5067typedef enum @{Caterpillar, Cocoon, Butterfly@}
c906108c
SS
5068 Bug_forms;
5069
5070struct thing @{
5071 Species it;
5072 union @{
5073 Tree_forms tree;
5074 Bug_forms bug;
5075 @} form;
5076@};
5077
5078struct thing foo = @{Tree, @{Acorn@}@};
5079@end smallexample
5080
5081@noindent
5082with @code{set print union on} in effect @samp{p foo} would print
5083
5084@smallexample
5085$1 = @{it = Tree, form = @{tree = Acorn, bug = Cocoon@}@}
5086@end smallexample
5087
5088@noindent
5089and with @code{set print union off} in effect it would print
5090
5091@smallexample
5092$1 = @{it = Tree, form = @{...@}@}
5093@end smallexample
5094@end table
5095
c906108c
SS
5096@need 1000
5097@noindent
5098These settings are of interest when debugging C++ programs:
5099
5100@table @code
5101@cindex demangling
5102@kindex set print demangle
5103@item set print demangle
5104@itemx set print demangle on
5105Print C++ names in their source form rather than in the encoded
5106(``mangled'') form passed to the assembler and linker for type-safe
d4f3574e 5107linkage. The default is on.
c906108c
SS
5108
5109@kindex show print demangle
5110@item show print demangle
5111Show whether C++ names are printed in mangled or demangled form.
5112
5113@kindex set print asm-demangle
5114@item set print asm-demangle
5115@itemx set print asm-demangle on
5116Print C++ names in their source form rather than their mangled form, even
5117in assembler code printouts such as instruction disassemblies.
5118The default is off.
5119
5120@kindex show print asm-demangle
5121@item show print asm-demangle
5122Show whether C++ names in assembly listings are printed in mangled
5123or demangled form.
5124
5125@kindex set demangle-style
5126@cindex C++ symbol decoding style
5127@cindex symbol decoding style, C++
5128@item set demangle-style @var{style}
5129Choose among several encoding schemes used by different compilers to
5130represent C++ names. The choices for @var{style} are currently:
5131
5132@table @code
5133@item auto
5134Allow @value{GDBN} to choose a decoding style by inspecting your program.
5135
5136@item gnu
5d161b24 5137Decode based on the @sc{gnu} C++ compiler (@code{g++}) encoding algorithm.
c906108c 5138This is the default.
c906108c
SS
5139
5140@item hp
5141Decode based on the HP ANSI C++ (@code{aCC}) encoding algorithm.
5142
5143@item lucid
5144Decode based on the Lucid C++ compiler (@code{lcc}) encoding algorithm.
5145
5146@item arm
5147Decode using the algorithm in the @cite{C++ Annotated Reference Manual}.
5148@strong{Warning:} this setting alone is not sufficient to allow
5149debugging @code{cfront}-generated executables. @value{GDBN} would
5150require further enhancement to permit that.
5151
5152@end table
5153If you omit @var{style}, you will see a list of possible formats.
5154
5155@kindex show demangle-style
5156@item show demangle-style
5157Display the encoding style currently in use for decoding C++ symbols.
5158
5159@kindex set print object
5160@item set print object
5161@itemx set print object on
5162When displaying a pointer to an object, identify the @emph{actual}
5163(derived) type of the object rather than the @emph{declared} type, using
5164the virtual function table.
5165
5166@item set print object off
5167Display only the declared type of objects, without reference to the
5168virtual function table. This is the default setting.
5169
5170@kindex show print object
5171@item show print object
5172Show whether actual, or declared, object types are displayed.
5173
5174@kindex set print static-members
5175@item set print static-members
5176@itemx set print static-members on
5177Print static members when displaying a C++ object. The default is on.
5178
5179@item set print static-members off
5180Do not print static members when displaying a C++ object.
5181
5182@kindex show print static-members
5183@item show print static-members
5184Show whether C++ static members are printed, or not.
5185
5186@c These don't work with HP ANSI C++ yet.
5187@kindex set print vtbl
5188@item set print vtbl
5189@itemx set print vtbl on
5190Pretty print C++ virtual function tables. The default is off.
c906108c
SS
5191(The @code{vtbl} commands do not work on programs compiled with the HP
5192ANSI C++ compiler (@code{aCC}).)
c906108c
SS
5193
5194@item set print vtbl off
5195Do not pretty print C++ virtual function tables.
5196
5197@kindex show print vtbl
5198@item show print vtbl
5199Show whether C++ virtual function tables are pretty printed, or not.
5200@end table
c906108c 5201
6d2ebf8b 5202@node Value History
c906108c
SS
5203@section Value history
5204
5205@cindex value history
5d161b24
DB
5206Values printed by the @code{print} command are saved in the @value{GDBN}
5207@dfn{value history}. This allows you to refer to them in other expressions.
5208Values are kept until the symbol table is re-read or discarded
5209(for example with the @code{file} or @code{symbol-file} commands).
5210When the symbol table changes, the value history is discarded,
5211since the values may contain pointers back to the types defined in the
c906108c
SS
5212symbol table.
5213
5214@cindex @code{$}
5215@cindex @code{$$}
5216@cindex history number
5217The values printed are given @dfn{history numbers} by which you can
5218refer to them. These are successive integers starting with one.
5219@code{print} shows you the history number assigned to a value by
5220printing @samp{$@var{num} = } before the value; here @var{num} is the
5221history number.
5222
5223To refer to any previous value, use @samp{$} followed by the value's
5224history number. The way @code{print} labels its output is designed to
5225remind you of this. Just @code{$} refers to the most recent value in
5226the history, and @code{$$} refers to the value before that.
5227@code{$$@var{n}} refers to the @var{n}th value from the end; @code{$$2}
5228is the value just prior to @code{$$}, @code{$$1} is equivalent to
5229@code{$$}, and @code{$$0} is equivalent to @code{$}.
5230
5231For example, suppose you have just printed a pointer to a structure and
5232want to see the contents of the structure. It suffices to type
5233
5234@example
5235p *$
5236@end example
5237
5238If you have a chain of structures where the component @code{next} points
5239to the next one, you can print the contents of the next one with this:
5240
5241@example
5242p *$.next
5243@end example
5244
5245@noindent
5246You can print successive links in the chain by repeating this
5247command---which you can do by just typing @key{RET}.
5248
5249Note that the history records values, not expressions. If the value of
5250@code{x} is 4 and you type these commands:
5251
5252@example
5253print x
5254set x=5
5255@end example
5256
5257@noindent
5258then the value recorded in the value history by the @code{print} command
5259remains 4 even though the value of @code{x} has changed.
5260
5261@table @code
5262@kindex show values
5263@item show values
5264Print the last ten values in the value history, with their item numbers.
5265This is like @samp{p@ $$9} repeated ten times, except that @code{show
5266values} does not change the history.
5267
5268@item show values @var{n}
5269Print ten history values centered on history item number @var{n}.
5270
5271@item show values +
5272Print ten history values just after the values last printed. If no more
5273values are available, @code{show values +} produces no display.
5274@end table
5275
5276Pressing @key{RET} to repeat @code{show values @var{n}} has exactly the
5277same effect as @samp{show values +}.
5278
6d2ebf8b 5279@node Convenience Vars
c906108c
SS
5280@section Convenience variables
5281
5282@cindex convenience variables
5283@value{GDBN} provides @dfn{convenience variables} that you can use within
5284@value{GDBN} to hold on to a value and refer to it later. These variables
5285exist entirely within @value{GDBN}; they are not part of your program, and
5286setting a convenience variable has no direct effect on further execution
5287of your program. That is why you can use them freely.
5288
5289Convenience variables are prefixed with @samp{$}. Any name preceded by
5290@samp{$} can be used for a convenience variable, unless it is one of
d4f3574e 5291the predefined machine-specific register names (@pxref{Registers, ,Registers}).
c906108c
SS
5292(Value history references, in contrast, are @emph{numbers} preceded
5293by @samp{$}. @xref{Value History, ,Value history}.)
5294
5295You can save a value in a convenience variable with an assignment
5296expression, just as you would set a variable in your program.
5297For example:
5298
5299@example
5300set $foo = *object_ptr
5301@end example
5302
5303@noindent
5304would save in @code{$foo} the value contained in the object pointed to by
5305@code{object_ptr}.
5306
5307Using a convenience variable for the first time creates it, but its
5308value is @code{void} until you assign a new value. You can alter the
5309value with another assignment at any time.
5310
5311Convenience variables have no fixed types. You can assign a convenience
5312variable any type of value, including structures and arrays, even if
5313that variable already has a value of a different type. The convenience
5314variable, when used as an expression, has the type of its current value.
5315
5316@table @code
5317@kindex show convenience
5318@item show convenience
5319Print a list of convenience variables used so far, and their values.
d4f3574e 5320Abbreviated @code{show conv}.
c906108c
SS
5321@end table
5322
5323One of the ways to use a convenience variable is as a counter to be
5324incremented or a pointer to be advanced. For example, to print
5325a field from successive elements of an array of structures:
5326
5327@example
5328set $i = 0
5329print bar[$i++]->contents
5330@end example
5331
d4f3574e
SS
5332@noindent
5333Repeat that command by typing @key{RET}.
c906108c
SS
5334
5335Some convenience variables are created automatically by @value{GDBN} and given
5336values likely to be useful.
5337
5338@table @code
5339@kindex $_
5340@item $_
5341The variable @code{$_} is automatically set by the @code{x} command to
5342the last address examined (@pxref{Memory, ,Examining memory}). Other
5343commands which provide a default address for @code{x} to examine also
5344set @code{$_} to that address; these commands include @code{info line}
5345and @code{info breakpoint}. The type of @code{$_} is @code{void *}
5346except when set by the @code{x} command, in which case it is a pointer
5347to the type of @code{$__}.
5348
5349@kindex $__
5350@item $__
5351The variable @code{$__} is automatically set by the @code{x} command
5352to the value found in the last address examined. Its type is chosen
5353to match the format in which the data was printed.
5354
5355@item $_exitcode
5356@kindex $_exitcode
5357The variable @code{$_exitcode} is automatically set to the exit code when
5358the program being debugged terminates.
5359@end table
5360
53a5351d
JM
5361On HP-UX systems, if you refer to a function or variable name that
5362begins with a dollar sign, @value{GDBN} searches for a user or system
5363name first, before it searches for a convenience variable.
c906108c 5364
6d2ebf8b 5365@node Registers
c906108c
SS
5366@section Registers
5367
5368@cindex registers
5369You can refer to machine register contents, in expressions, as variables
5370with names starting with @samp{$}. The names of registers are different
5371for each machine; use @code{info registers} to see the names used on
5372your machine.
5373
5374@table @code
5375@kindex info registers
5376@item info registers
5377Print the names and values of all registers except floating-point
5378registers (in the selected stack frame).
5379
5380@kindex info all-registers
5381@cindex floating point registers
5382@item info all-registers
5383Print the names and values of all registers, including floating-point
5384registers.
5385
5386@item info registers @var{regname} @dots{}
5387Print the @dfn{relativized} value of each specified register @var{regname}.
5d161b24
DB
5388As discussed in detail below, register values are normally relative to
5389the selected stack frame. @var{regname} may be any register name valid on
c906108c
SS
5390the machine you are using, with or without the initial @samp{$}.
5391@end table
5392
5393@value{GDBN} has four ``standard'' register names that are available (in
5394expressions) on most machines---whenever they do not conflict with an
5395architecture's canonical mnemonics for registers. The register names
5396@code{$pc} and @code{$sp} are used for the program counter register and
5397the stack pointer. @code{$fp} is used for a register that contains a
5398pointer to the current stack frame, and @code{$ps} is used for a
5399register that contains the processor status. For example,
5400you could print the program counter in hex with
5401
5402@example
5403p/x $pc
5404@end example
5405
5406@noindent
5407or print the instruction to be executed next with
5408
5409@example
5410x/i $pc
5411@end example
5412
5413@noindent
5414or add four to the stack pointer@footnote{This is a way of removing
5415one word from the stack, on machines where stacks grow downward in
5416memory (most machines, nowadays). This assumes that the innermost
5417stack frame is selected; setting @code{$sp} is not allowed when other
5418stack frames are selected. To pop entire frames off the stack,
5419regardless of machine architecture, use @code{return};
d4f3574e 5420see @ref{Returning, ,Returning from a function}.} with
c906108c
SS
5421
5422@example
5423set $sp += 4
5424@end example
5425
5426Whenever possible, these four standard register names are available on
5427your machine even though the machine has different canonical mnemonics,
5428so long as there is no conflict. The @code{info registers} command
5429shows the canonical names. For example, on the SPARC, @code{info
5430registers} displays the processor status register as @code{$psr} but you
d4f3574e
SS
5431can also refer to it as @code{$ps}; and on x86-based machines @code{$ps}
5432is an alias for the @sc{eflags} register.
c906108c
SS
5433
5434@value{GDBN} always considers the contents of an ordinary register as an
5435integer when the register is examined in this way. Some machines have
5436special registers which can hold nothing but floating point; these
5437registers are considered to have floating point values. There is no way
5438to refer to the contents of an ordinary register as floating point value
5439(although you can @emph{print} it as a floating point value with
5440@samp{print/f $@var{regname}}).
5441
5442Some registers have distinct ``raw'' and ``virtual'' data formats. This
5443means that the data format in which the register contents are saved by
5444the operating system is not the same one that your program normally
5445sees. For example, the registers of the 68881 floating point
5446coprocessor are always saved in ``extended'' (raw) format, but all C
5447programs expect to work with ``double'' (virtual) format. In such
5d161b24 5448cases, @value{GDBN} normally works with the virtual format only (the format
c906108c
SS
5449that makes sense for your program), but the @code{info registers} command
5450prints the data in both formats.
5451
5452Normally, register values are relative to the selected stack frame
5453(@pxref{Selection, ,Selecting a frame}). This means that you get the
5454value that the register would contain if all stack frames farther in
5455were exited and their saved registers restored. In order to see the
5456true contents of hardware registers, you must select the innermost
5457frame (with @samp{frame 0}).
5458
5459However, @value{GDBN} must deduce where registers are saved, from the machine
5460code generated by your compiler. If some registers are not saved, or if
5461@value{GDBN} is unable to locate the saved registers, the selected stack
5462frame makes no difference.
5463
6d2ebf8b 5464@node Floating Point Hardware
c906108c
SS
5465@section Floating point hardware
5466@cindex floating point
5467
5468Depending on the configuration, @value{GDBN} may be able to give
5469you more information about the status of the floating point hardware.
5470
5471@table @code
5472@kindex info float
5473@item info float
5474Display hardware-dependent information about the floating
5475point unit. The exact contents and layout vary depending on the
5476floating point chip. Currently, @samp{info float} is supported on
5477the ARM and x86 machines.
5478@end table
c906108c 5479
6d2ebf8b 5480@node Languages
c906108c
SS
5481@chapter Using @value{GDBN} with Different Languages
5482@cindex languages
5483
c906108c
SS
5484Although programming languages generally have common aspects, they are
5485rarely expressed in the same manner. For instance, in ANSI C,
5486dereferencing a pointer @code{p} is accomplished by @code{*p}, but in
5487Modula-2, it is accomplished by @code{p^}. Values can also be
5d161b24 5488represented (and displayed) differently. Hex numbers in C appear as
c906108c 5489@samp{0x1ae}, while in Modula-2 they appear as @samp{1AEH}.
c906108c
SS
5490
5491@cindex working language
5492Language-specific information is built into @value{GDBN} for some languages,
5493allowing you to express operations like the above in your program's
5494native language, and allowing @value{GDBN} to output values in a manner
5495consistent with the syntax of your program's native language. The
5496language you use to build expressions is called the @dfn{working
5497language}.
5498
5499@menu
5500* Setting:: Switching between source languages
5501* Show:: Displaying the language
c906108c 5502* Checks:: Type and range checks
c906108c
SS
5503* Support:: Supported languages
5504@end menu
5505
6d2ebf8b 5506@node Setting
c906108c
SS
5507@section Switching between source languages
5508
5509There are two ways to control the working language---either have @value{GDBN}
5510set it automatically, or select it manually yourself. You can use the
5511@code{set language} command for either purpose. On startup, @value{GDBN}
5512defaults to setting the language automatically. The working language is
5513used to determine how expressions you type are interpreted, how values
5514are printed, etc.
5515
5516In addition to the working language, every source file that
5517@value{GDBN} knows about has its own working language. For some object
5518file formats, the compiler might indicate which language a particular
5519source file is in. However, most of the time @value{GDBN} infers the
5520language from the name of the file. The language of a source file
5521controls whether C++ names are demangled---this way @code{backtrace} can
5522show each frame appropriately for its own language. There is no way to
d4f3574e
SS
5523set the language of a source file from within @value{GDBN}, but you can
5524set the language associated with a filename extension. @xref{Show, ,
5525Displaying the language}.
c906108c
SS
5526
5527This is most commonly a problem when you use a program, such
5d161b24 5528as @code{cfront} or @code{f2c}, that generates C but is written in
c906108c
SS
5529another language. In that case, make the
5530program use @code{#line} directives in its C output; that way
5531@value{GDBN} will know the correct language of the source code of the original
5532program, and will display that source code, not the generated C code.
5533
5534@menu
5535* Filenames:: Filename extensions and languages.
5536* Manually:: Setting the working language manually
5537* Automatically:: Having @value{GDBN} infer the source language
5538@end menu
5539
6d2ebf8b 5540@node Filenames
c906108c
SS
5541@subsection List of filename extensions and languages
5542
5543If a source file name ends in one of the following extensions, then
5544@value{GDBN} infers that its language is the one indicated.
5545
5546@table @file
5547
5548@item .c
5549C source file
5550
5551@item .C
5552@itemx .cc
5553@itemx .cp
5554@itemx .cpp
5555@itemx .cxx
5556@itemx .c++
5557C++ source file
5558
5559@item .f
5560@itemx .F
5561Fortran source file
5562
c906108c
SS
5563@item .ch
5564@itemx .c186
5565@itemx .c286
96a2c332 5566CHILL source file
c906108c 5567
c906108c
SS
5568@item .mod
5569Modula-2 source file
c906108c
SS
5570
5571@item .s
5572@itemx .S
5573Assembler source file. This actually behaves almost like C, but
5574@value{GDBN} does not skip over function prologues when stepping.
5575@end table
5576
5577In addition, you may set the language associated with a filename
5578extension. @xref{Show, , Displaying the language}.
5579
6d2ebf8b 5580@node Manually
c906108c
SS
5581@subsection Setting the working language
5582
5583If you allow @value{GDBN} to set the language automatically,
5584expressions are interpreted the same way in your debugging session and
5585your program.
5586
5587@kindex set language
5588If you wish, you may set the language manually. To do this, issue the
5589command @samp{set language @var{lang}}, where @var{lang} is the name of
5d161b24 5590a language, such as
c906108c 5591@code{c} or @code{modula-2}.
c906108c
SS
5592For a list of the supported languages, type @samp{set language}.
5593
c906108c
SS
5594Setting the language manually prevents @value{GDBN} from updating the working
5595language automatically. This can lead to confusion if you try
5596to debug a program when the working language is not the same as the
5597source language, when an expression is acceptable to both
5598languages---but means different things. For instance, if the current
5599source file were written in C, and @value{GDBN} was parsing Modula-2, a
5600command such as:
5601
5602@example
5603print a = b + c
5604@end example
5605
5606@noindent
5607might not have the effect you intended. In C, this means to add
5608@code{b} and @code{c} and place the result in @code{a}. The result
5609printed would be the value of @code{a}. In Modula-2, this means to compare
5610@code{a} to the result of @code{b+c}, yielding a @code{BOOLEAN} value.
c906108c 5611
6d2ebf8b 5612@node Automatically
c906108c
SS
5613@subsection Having @value{GDBN} infer the source language
5614
5615To have @value{GDBN} set the working language automatically, use
5616@samp{set language local} or @samp{set language auto}. @value{GDBN}
5617then infers the working language. That is, when your program stops in a
5618frame (usually by encountering a breakpoint), @value{GDBN} sets the
5619working language to the language recorded for the function in that
5620frame. If the language for a frame is unknown (that is, if the function
5621or block corresponding to the frame was defined in a source file that
5622does not have a recognized extension), the current working language is
5623not changed, and @value{GDBN} issues a warning.
5624
5625This may not seem necessary for most programs, which are written
5626entirely in one source language. However, program modules and libraries
5627written in one source language can be used by a main program written in
5628a different source language. Using @samp{set language auto} in this
5629case frees you from having to set the working language manually.
5630
6d2ebf8b 5631@node Show
c906108c 5632@section Displaying the language
c906108c
SS
5633
5634The following commands help you find out which language is the
5635working language, and also what language source files were written in.
5636
5637@kindex show language
d4f3574e
SS
5638@kindex info frame@r{, show the source language}
5639@kindex info source@r{, show the source language}
c906108c
SS
5640@table @code
5641@item show language
5642Display the current working language. This is the
5643language you can use with commands such as @code{print} to
5644build and compute expressions that may involve variables in your program.
5645
5646@item info frame
5d161b24 5647Display the source language for this frame. This language becomes the
c906108c 5648working language if you use an identifier from this frame.
5d161b24 5649@xref{Frame Info, ,Information about a frame}, to identify the other
c906108c
SS
5650information listed here.
5651
5652@item info source
5653Display the source language of this source file.
5d161b24 5654@xref{Symbols, ,Examining the Symbol Table}, to identify the other
c906108c
SS
5655information listed here.
5656@end table
5657
5658In unusual circumstances, you may have source files with extensions
5659not in the standard list. You can then set the extension associated
5660with a language explicitly:
5661
5662@kindex set extension-language
5663@kindex info extensions
5664@table @code
5665@item set extension-language @var{.ext} @var{language}
5666Set source files with extension @var{.ext} to be assumed to be in
5667the source language @var{language}.
5668
5669@item info extensions
5670List all the filename extensions and the associated languages.
5671@end table
5672
6d2ebf8b 5673@node Checks
c906108c
SS
5674@section Type and range checking
5675
5676@quotation
5677@emph{Warning:} In this release, the @value{GDBN} commands for type and range
5678checking are included, but they do not yet have any effect. This
5679section documents the intended facilities.
5680@end quotation
5681@c FIXME remove warning when type/range code added
5682
5683Some languages are designed to guard you against making seemingly common
5684errors through a series of compile- and run-time checks. These include
5685checking the type of arguments to functions and operators, and making
5686sure mathematical overflows are caught at run time. Checks such as
5687these help to ensure a program's correctness once it has been compiled
5688by eliminating type mismatches, and providing active checks for range
5689errors when your program is running.
5690
5691@value{GDBN} can check for conditions like the above if you wish.
5692Although @value{GDBN} does not check the statements in your program, it
5693can check expressions entered directly into @value{GDBN} for evaluation via
5694the @code{print} command, for example. As with the working language,
5695@value{GDBN} can also decide whether or not to check automatically based on
5696your program's source language. @xref{Support, ,Supported languages},
5697for the default settings of supported languages.
5698
5699@menu
5700* Type Checking:: An overview of type checking
5701* Range Checking:: An overview of range checking
5702@end menu
5703
5704@cindex type checking
5705@cindex checks, type
6d2ebf8b 5706@node Type Checking
c906108c
SS
5707@subsection An overview of type checking
5708
5709Some languages, such as Modula-2, are strongly typed, meaning that the
5710arguments to operators and functions have to be of the correct type,
5711otherwise an error occurs. These checks prevent type mismatch
5712errors from ever causing any run-time problems. For example,
5713
5714@smallexample
57151 + 2 @result{} 3
5716@exdent but
5717@error{} 1 + 2.3
5718@end smallexample
5719
5720The second example fails because the @code{CARDINAL} 1 is not
5721type-compatible with the @code{REAL} 2.3.
5722
5d161b24
DB
5723For the expressions you use in @value{GDBN} commands, you can tell the
5724@value{GDBN} type checker to skip checking;
5725to treat any mismatches as errors and abandon the expression;
5726or to only issue warnings when type mismatches occur,
c906108c
SS
5727but evaluate the expression anyway. When you choose the last of
5728these, @value{GDBN} evaluates expressions like the second example above, but
5729also issues a warning.
5730
5d161b24
DB
5731Even if you turn type checking off, there may be other reasons
5732related to type that prevent @value{GDBN} from evaluating an expression.
5733For instance, @value{GDBN} does not know how to add an @code{int} and
5734a @code{struct foo}. These particular type errors have nothing to do
5735with the language in use, and usually arise from expressions, such as
c906108c
SS
5736the one described above, which make little sense to evaluate anyway.
5737
5738Each language defines to what degree it is strict about type. For
5739instance, both Modula-2 and C require the arguments to arithmetical
5740operators to be numbers. In C, enumerated types and pointers can be
5741represented as numbers, so that they are valid arguments to mathematical
5742operators. @xref{Support, ,Supported languages}, for further
5743details on specific languages.
5744
5745@value{GDBN} provides some additional commands for controlling the type checker:
5746
d4f3574e 5747@kindex set check@r{, type}
c906108c
SS
5748@kindex set check type
5749@kindex show check type
5750@table @code
5751@item set check type auto
5752Set type checking on or off based on the current working language.
5753@xref{Support, ,Supported languages}, for the default settings for
5754each language.
5755
5756@item set check type on
5757@itemx set check type off
5758Set type checking on or off, overriding the default setting for the
5759current working language. Issue a warning if the setting does not
5760match the language default. If any type mismatches occur in
d4f3574e 5761evaluating an expression while type checking is on, @value{GDBN} prints a
c906108c
SS
5762message and aborts evaluation of the expression.
5763
5764@item set check type warn
5765Cause the type checker to issue warnings, but to always attempt to
5766evaluate the expression. Evaluating the expression may still
5767be impossible for other reasons. For example, @value{GDBN} cannot add
5768numbers and structures.
5769
5770@item show type
5d161b24 5771Show the current setting of the type checker, and whether or not @value{GDBN}
c906108c
SS
5772is setting it automatically.
5773@end table
5774
5775@cindex range checking
5776@cindex checks, range
6d2ebf8b 5777@node Range Checking
c906108c
SS
5778@subsection An overview of range checking
5779
5780In some languages (such as Modula-2), it is an error to exceed the
5781bounds of a type; this is enforced with run-time checks. Such range
5782checking is meant to ensure program correctness by making sure
5783computations do not overflow, or indices on an array element access do
5784not exceed the bounds of the array.
5785
5786For expressions you use in @value{GDBN} commands, you can tell
5787@value{GDBN} to treat range errors in one of three ways: ignore them,
5788always treat them as errors and abandon the expression, or issue
5789warnings but evaluate the expression anyway.
5790
5791A range error can result from numerical overflow, from exceeding an
5792array index bound, or when you type a constant that is not a member
5793of any type. Some languages, however, do not treat overflows as an
5794error. In many implementations of C, mathematical overflow causes the
5795result to ``wrap around'' to lower values---for example, if @var{m} is
5796the largest integer value, and @var{s} is the smallest, then
5797
5798@example
5799@var{m} + 1 @result{} @var{s}
5800@end example
5801
5802This, too, is specific to individual languages, and in some cases
5803specific to individual compilers or machines. @xref{Support, ,
5804Supported languages}, for further details on specific languages.
5805
5806@value{GDBN} provides some additional commands for controlling the range checker:
5807
d4f3574e 5808@kindex set check@r{, range}
c906108c
SS
5809@kindex set check range
5810@kindex show check range
5811@table @code
5812@item set check range auto
5813Set range checking on or off based on the current working language.
5814@xref{Support, ,Supported languages}, for the default settings for
5815each language.
5816
5817@item set check range on
5818@itemx set check range off
5819Set range checking on or off, overriding the default setting for the
5820current working language. A warning is issued if the setting does not
c3f6f71d
JM
5821match the language default. If a range error occurs and range checking is on,
5822then a message is printed and evaluation of the expression is aborted.
c906108c
SS
5823
5824@item set check range warn
5825Output messages when the @value{GDBN} range checker detects a range error,
5826but attempt to evaluate the expression anyway. Evaluating the
5827expression may still be impossible for other reasons, such as accessing
5828memory that the process does not own (a typical example from many Unix
5829systems).
5830
5831@item show range
5832Show the current setting of the range checker, and whether or not it is
5833being set automatically by @value{GDBN}.
5834@end table
c906108c 5835
6d2ebf8b 5836@node Support
c906108c 5837@section Supported languages
c906108c 5838
cce74817
JM
5839@value{GDBN} supports C, C++, Fortran, Java, Chill, assembly, and Modula-2.
5840@c This is false ...
c906108c
SS
5841Some @value{GDBN} features may be used in expressions regardless of the
5842language you use: the @value{GDBN} @code{@@} and @code{::} operators,
5843and the @samp{@{type@}addr} construct (@pxref{Expressions,
5844,Expressions}) can be used with the constructs of any supported
5845language.
5846
5847The following sections detail to what degree each source language is
5848supported by @value{GDBN}. These sections are not meant to be language
5849tutorials or references, but serve only as a reference guide to what the
5850@value{GDBN} expression parser accepts, and what input and output
5851formats should look like for different languages. There are many good
5852books written on each of these languages; please look to these for a
5853language reference or tutorial.
5854
c906108c 5855@menu
7a292a7a 5856* C:: C and C++
cce74817 5857* Modula-2:: Modula-2
104c1213 5858* Chill:: Chill
c906108c
SS
5859@end menu
5860
6d2ebf8b 5861@node C
c906108c 5862@subsection C and C++
7a292a7a 5863
c906108c
SS
5864@cindex C and C++
5865@cindex expressions in C or C++
c906108c
SS
5866
5867Since C and C++ are so closely related, many features of @value{GDBN} apply
5868to both languages. Whenever this is the case, we discuss those languages
5869together.
5870
c906108c
SS
5871@cindex C++
5872@kindex g++
5873@cindex @sc{gnu} C++
5874The C++ debugging facilities are jointly implemented by the C++
5875compiler and @value{GDBN}. Therefore, to debug your C++ code
5876effectively, you must compile your C++ programs with a supported
5877C++ compiler, such as @sc{gnu} @code{g++}, or the HP ANSI C++
5878compiler (@code{aCC}).
5879
5880For best results when using @sc{gnu} C++, use the stabs debugging
5881format. You can select that format explicitly with the @code{g++}
5882command-line options @samp{-gstabs} or @samp{-gstabs+}. See
5883@ref{Debugging Options,,Options for Debugging Your Program or @sc{gnu}
5884CC, gcc.info, Using @sc{gnu} CC}, for more information.
c906108c 5885
c906108c
SS
5886@menu
5887* C Operators:: C and C++ operators
5888* C Constants:: C and C++ constants
7a292a7a 5889* C plus plus expressions:: C++ expressions
c906108c 5890* C Defaults:: Default settings for C and C++
c906108c 5891* C Checks:: C and C++ type and range checks
c906108c
SS
5892* Debugging C:: @value{GDBN} and C
5893* Debugging C plus plus:: @value{GDBN} features for C++
5894@end menu
c906108c 5895
6d2ebf8b 5896@node C Operators
c906108c 5897@subsubsection C and C++ operators
7a292a7a
SS
5898
5899@cindex C and C++ operators
c906108c
SS
5900
5901Operators must be defined on values of specific types. For instance,
5902@code{+} is defined on numbers, but not on structures. Operators are
5d161b24 5903often defined on groups of types.
c906108c 5904
c906108c 5905For the purposes of C and C++, the following definitions hold:
c906108c
SS
5906
5907@itemize @bullet
53a5351d 5908
c906108c 5909@item
c906108c
SS
5910@emph{Integral types} include @code{int} with any of its storage-class
5911specifiers; @code{char}; @code{enum}; and, for C++, @code{bool}.
c906108c
SS
5912
5913@item
d4f3574e
SS
5914@emph{Floating-point types} include @code{float}, @code{double}, and
5915@code{long double} (if supported by the target platform).
c906108c
SS
5916
5917@item
53a5351d 5918@emph{Pointer types} include all types defined as @code{(@var{type} *)}.
c906108c
SS
5919
5920@item
5921@emph{Scalar types} include all of the above.
53a5351d 5922
c906108c
SS
5923@end itemize
5924
5925@noindent
5926The following operators are supported. They are listed here
5927in order of increasing precedence:
5928
5929@table @code
5930@item ,
5931The comma or sequencing operator. Expressions in a comma-separated list
5932are evaluated from left to right, with the result of the entire
5933expression being the last expression evaluated.
5934
5935@item =
5936Assignment. The value of an assignment expression is the value
5937assigned. Defined on scalar types.
5938
5939@item @var{op}=
5940Used in an expression of the form @w{@code{@var{a} @var{op}= @var{b}}},
5941and translated to @w{@code{@var{a} = @var{a op b}}}.
d4f3574e 5942@w{@code{@var{op}=}} and @code{=} have the same precedence.
c906108c
SS
5943@var{op} is any one of the operators @code{|}, @code{^}, @code{&},
5944@code{<<}, @code{>>}, @code{+}, @code{-}, @code{*}, @code{/}, @code{%}.
5945
5946@item ?:
5947The ternary operator. @code{@var{a} ? @var{b} : @var{c}} can be thought
5948of as: if @var{a} then @var{b} else @var{c}. @var{a} should be of an
5949integral type.
5950
5951@item ||
5952Logical @sc{or}. Defined on integral types.
5953
5954@item &&
5955Logical @sc{and}. Defined on integral types.
5956
5957@item |
5958Bitwise @sc{or}. Defined on integral types.
5959
5960@item ^
5961Bitwise exclusive-@sc{or}. Defined on integral types.
5962
5963@item &
5964Bitwise @sc{and}. Defined on integral types.
5965
5966@item ==@r{, }!=
5967Equality and inequality. Defined on scalar types. The value of these
5968expressions is 0 for false and non-zero for true.
5969
5970@item <@r{, }>@r{, }<=@r{, }>=
5971Less than, greater than, less than or equal, greater than or equal.
5972Defined on scalar types. The value of these expressions is 0 for false
5973and non-zero for true.
5974
5975@item <<@r{, }>>
5976left shift, and right shift. Defined on integral types.
5977
5978@item @@
5979The @value{GDBN} ``artificial array'' operator (@pxref{Expressions, ,Expressions}).
5980
5981@item +@r{, }-
5982Addition and subtraction. Defined on integral types, floating-point types and
5983pointer types.
5984
5985@item *@r{, }/@r{, }%
5986Multiplication, division, and modulus. Multiplication and division are
5987defined on integral and floating-point types. Modulus is defined on
5988integral types.
5989
5990@item ++@r{, }--
5991Increment and decrement. When appearing before a variable, the
5992operation is performed before the variable is used in an expression;
5993when appearing after it, the variable's value is used before the
5994operation takes place.
5995
5996@item *
5997Pointer dereferencing. Defined on pointer types. Same precedence as
5998@code{++}.
5999
6000@item &
6001Address operator. Defined on variables. Same precedence as @code{++}.
6002
c906108c
SS
6003For debugging C++, @value{GDBN} implements a use of @samp{&} beyond what is
6004allowed in the C++ language itself: you can use @samp{&(&@var{ref})}
6005(or, if you prefer, simply @samp{&&@var{ref}}) to examine the address
6006where a C++ reference variable (declared with @samp{&@var{ref}}) is
6007stored.
c906108c
SS
6008
6009@item -
6010Negative. Defined on integral and floating-point types. Same
6011precedence as @code{++}.
6012
6013@item !
6014Logical negation. Defined on integral types. Same precedence as
6015@code{++}.
6016
6017@item ~
6018Bitwise complement operator. Defined on integral types. Same precedence as
6019@code{++}.
6020
6021
6022@item .@r{, }->
6023Structure member, and pointer-to-structure member. For convenience,
6024@value{GDBN} regards the two as equivalent, choosing whether to dereference a
6025pointer based on the stored type information.
6026Defined on @code{struct} and @code{union} data.
6027
c906108c
SS
6028@item .*@r{, }->*
6029Dereferences of pointers to members.
c906108c
SS
6030
6031@item []
6032Array indexing. @code{@var{a}[@var{i}]} is defined as
6033@code{*(@var{a}+@var{i})}. Same precedence as @code{->}.
6034
6035@item ()
6036Function parameter list. Same precedence as @code{->}.
6037
c906108c 6038@item ::
7a292a7a
SS
6039C++ scope resolution operator. Defined on @code{struct}, @code{union},
6040and @code{class} types.
c906108c
SS
6041
6042@item ::
7a292a7a
SS
6043Doubled colons also represent the @value{GDBN} scope operator
6044(@pxref{Expressions, ,Expressions}). Same precedence as @code{::},
6045above.
c906108c
SS
6046@end table
6047
c906108c
SS
6048If an operator is redefined in the user code, @value{GDBN} usually
6049attempts to invoke the redefined version instead of using the operator's
6050predefined meaning.
c906108c 6051
c906108c 6052@menu
5d161b24 6053* C Constants::
c906108c
SS
6054@end menu
6055
6d2ebf8b 6056@node C Constants
c906108c 6057@subsubsection C and C++ constants
c906108c
SS
6058
6059@cindex C and C++ constants
c906108c 6060
7a292a7a 6061@value{GDBN} allows you to express the constants of C and C++ in the
c906108c 6062following ways:
c906108c
SS
6063
6064@itemize @bullet
6065@item
6066Integer constants are a sequence of digits. Octal constants are
6067specified by a leading @samp{0} (i.e. zero), and hexadecimal constants by
6068a leading @samp{0x} or @samp{0X}. Constants may also end with a letter
6069@samp{l}, specifying that the constant should be treated as a
6070@code{long} value.
6071
6072@item
6073Floating point constants are a sequence of digits, followed by a decimal
6074point, followed by a sequence of digits, and optionally followed by an
6075exponent. An exponent is of the form:
6076@samp{@w{e@r{[[}+@r{]|}-@r{]}@var{nnn}}}, where @var{nnn} is another
6077sequence of digits. The @samp{+} is optional for positive exponents.
d4f3574e
SS
6078A floating-point constant may also end with a letter @samp{f} or
6079@samp{F}, specifying that the constant should be treated as being of
6080the @code{float} (as opposed to the default @code{double}) type; or with
6081a letter @samp{l} or @samp{L}, which specifies a @code{long double}
6082constant.
c906108c
SS
6083
6084@item
6085Enumerated constants consist of enumerated identifiers, or their
6086integral equivalents.
6087
6088@item
6089Character constants are a single character surrounded by single quotes
6090(@code{'}), or a number---the ordinal value of the corresponding character
d4f3574e 6091(usually its @sc{ascii} value). Within quotes, the single character may
c906108c
SS
6092be represented by a letter or by @dfn{escape sequences}, which are of
6093the form @samp{\@var{nnn}}, where @var{nnn} is the octal representation
6094of the character's ordinal value; or of the form @samp{\@var{x}}, where
6095@samp{@var{x}} is a predefined special character---for example,
6096@samp{\n} for newline.
6097
6098@item
96a2c332
SS
6099String constants are a sequence of character constants surrounded by
6100double quotes (@code{"}). Any valid character constant (as described
6101above) may appear. Double quotes within the string must be preceded by
6102a backslash, so for instance @samp{"a\"b'c"} is a string of five
6103characters.
c906108c
SS
6104
6105@item
6106Pointer constants are an integral value. You can also write pointers
6107to constants using the C operator @samp{&}.
6108
6109@item
6110Array constants are comma-separated lists surrounded by braces @samp{@{}
6111and @samp{@}}; for example, @samp{@{1,2,3@}} is a three-element array of
6112integers, @samp{@{@{1,2@}, @{3,4@}, @{5,6@}@}} is a three-by-two array,
6113and @samp{@{&"hi", &"there", &"fred"@}} is a three-element array of pointers.
6114@end itemize
6115
c906108c 6116@menu
5d161b24
DB
6117* C plus plus expressions::
6118* C Defaults::
6119* C Checks::
c906108c 6120
5d161b24 6121* Debugging C::
c906108c
SS
6122@end menu
6123
6d2ebf8b 6124@node C plus plus expressions
c906108c 6125@subsubsection C++ expressions
c906108c
SS
6126
6127@cindex expressions in C++
6128@value{GDBN} expression handling can interpret most C++ expressions.
6129
c906108c
SS
6130@cindex C++ support, not in @sc{coff}
6131@cindex @sc{coff} versus C++
6132@cindex C++ and object formats
6133@cindex object formats and C++
6134@cindex a.out and C++
6135@cindex @sc{ecoff} and C++
6136@cindex @sc{xcoff} and C++
6137@cindex @sc{elf}/stabs and C++
6138@cindex @sc{elf}/@sc{dwarf} and C++
6139@c FIXME!! GDB may eventually be able to debug C++ using DWARF; check
6140@c periodically whether this has happened...
6141@quotation
6142@emph{Warning:} @value{GDBN} can only debug C++ code if you use the
6143proper compiler. Typically, C++ debugging depends on the use of
6144additional debugging information in the symbol table, and thus requires
6145special support. In particular, if your compiler generates a.out, MIPS
6146@sc{ecoff}, RS/6000 @sc{xcoff}, or @sc{elf} with stabs extensions to the
6147symbol table, these facilities are all available. (With @sc{gnu} CC,
6148you can use the @samp{-gstabs} option to request stabs debugging
6149extensions explicitly.) Where the object code format is standard
6150@sc{coff} or @sc{dwarf} in @sc{elf}, on the other hand, most of the C++
6151support in @value{GDBN} does @emph{not} work.
6152@end quotation
c906108c
SS
6153
6154@enumerate
6155
6156@cindex member functions
6157@item
6158Member function calls are allowed; you can use expressions like
6159
6160@example
6161count = aml->GetOriginal(x, y)
6162@end example
6163
6164@kindex this
6165@cindex namespace in C++
6166@item
6167While a member function is active (in the selected stack frame), your
6168expressions have the same namespace available as the member function;
6169that is, @value{GDBN} allows implicit references to the class instance
6170pointer @code{this} following the same rules as C++.
6171
c906108c 6172@cindex call overloaded functions
d4f3574e 6173@cindex overloaded functions, calling
c906108c
SS
6174@cindex type conversions in C++
6175@item
6176You can call overloaded functions; @value{GDBN} resolves the function
d4f3574e 6177call to the right definition, with some restrictions. @value{GDBN} does not
c906108c
SS
6178perform overload resolution involving user-defined type conversions,
6179calls to constructors, or instantiations of templates that do not exist
6180in the program. It also cannot handle ellipsis argument lists or
6181default arguments.
6182
6183It does perform integral conversions and promotions, floating-point
6184promotions, arithmetic conversions, pointer conversions, conversions of
6185class objects to base classes, and standard conversions such as those of
6186functions or arrays to pointers; it requires an exact match on the
6187number of function arguments.
6188
6189Overload resolution is always performed, unless you have specified
6190@code{set overload-resolution off}. @xref{Debugging C plus plus,
6191,@value{GDBN} features for C++}.
6192
d4f3574e 6193You must specify @code{set overload-resolution off} in order to use an
c906108c
SS
6194explicit function signature to call an overloaded function, as in
6195@smallexample
6196p 'foo(char,int)'('x', 13)
6197@end smallexample
d4f3574e 6198
c906108c 6199The @value{GDBN} command-completion facility can simplify this;
d4f3574e 6200see @ref{Completion, ,Command completion}.
c906108c 6201
c906108c
SS
6202@cindex reference declarations
6203@item
5d161b24 6204@value{GDBN} understands variables declared as C++ references; you can use
c906108c
SS
6205them in expressions just as you do in C++ source---they are automatically
6206dereferenced.
6207
6208In the parameter list shown when @value{GDBN} displays a frame, the values of
6209reference variables are not displayed (unlike other variables); this
6210avoids clutter, since references are often used for large structures.
6211The @emph{address} of a reference variable is always shown, unless
6212you have specified @samp{set print address off}.
6213
6214@item
6215@value{GDBN} supports the C++ name resolution operator @code{::}---your
6216expressions can use it just as expressions in your program do. Since
6217one scope may be defined in another, you can use @code{::} repeatedly if
6218necessary, for example in an expression like
6219@samp{@var{scope1}::@var{scope2}::@var{name}}. @value{GDBN} also allows
6220resolving name scope by reference to source files, in both C and C++
6221debugging (@pxref{Variables, ,Program variables}).
6222@end enumerate
6223
53a5351d
JM
6224In addition, when used with HP's C++ compiler, @value{GDBN} supports
6225calling virtual functions correctly, printing out virtual bases of
6226objects, calling functions in a base subobject, casting objects, and
6227invoking user-defined operators.
c906108c 6228
6d2ebf8b 6229@node C Defaults
c906108c 6230@subsubsection C and C++ defaults
7a292a7a 6231
c906108c
SS
6232@cindex C and C++ defaults
6233
c906108c
SS
6234If you allow @value{GDBN} to set type and range checking automatically, they
6235both default to @code{off} whenever the working language changes to
6236C or C++. This happens regardless of whether you or @value{GDBN}
6237selects the working language.
c906108c
SS
6238
6239If you allow @value{GDBN} to set the language automatically, it
6240recognizes source files whose names end with @file{.c}, @file{.C}, or
6241@file{.cc}, etc, and when @value{GDBN} enters code compiled from one of
6242these files, it sets the working language to C or C++.
6243@xref{Automatically, ,Having @value{GDBN} infer the source language},
6244for further details.
6245
c906108c
SS
6246@c Type checking is (a) primarily motivated by Modula-2, and (b)
6247@c unimplemented. If (b) changes, it might make sense to let this node
6248@c appear even if Mod-2 does not, but meanwhile ignore it. roland 16jul93.
7a292a7a 6249
6d2ebf8b 6250@node C Checks
c906108c 6251@subsubsection C and C++ type and range checks
7a292a7a 6252
c906108c
SS
6253@cindex C and C++ checks
6254
6255By default, when @value{GDBN} parses C or C++ expressions, type checking
6256is not used. However, if you turn type checking on, @value{GDBN}
6257considers two variables type equivalent if:
6258
6259@itemize @bullet
6260@item
6261The two variables are structured and have the same structure, union, or
6262enumerated tag.
6263
6264@item
6265The two variables have the same type name, or types that have been
6266declared equivalent through @code{typedef}.
6267
6268@ignore
6269@c leaving this out because neither J Gilmore nor R Pesch understand it.
6270@c FIXME--beers?
6271@item
6272The two @code{struct}, @code{union}, or @code{enum} variables are
6273declared in the same declaration. (Note: this may not be true for all C
6274compilers.)
6275@end ignore
6276@end itemize
6277
6278Range checking, if turned on, is done on mathematical operations. Array
6279indices are not checked, since they are often used to index a pointer
6280that is not itself an array.
c906108c 6281
6d2ebf8b 6282@node Debugging C
c906108c 6283@subsubsection @value{GDBN} and C
c906108c
SS
6284
6285The @code{set print union} and @code{show print union} commands apply to
6286the @code{union} type. When set to @samp{on}, any @code{union} that is
7a292a7a
SS
6287inside a @code{struct} or @code{class} is also printed. Otherwise, it
6288appears as @samp{@{...@}}.
c906108c
SS
6289
6290The @code{@@} operator aids in the debugging of dynamic arrays, formed
6291with pointers and a memory allocation function. @xref{Expressions,
6292,Expressions}.
6293
c906108c 6294@menu
5d161b24 6295* Debugging C plus plus::
c906108c
SS
6296@end menu
6297
6d2ebf8b 6298@node Debugging C plus plus
c906108c 6299@subsubsection @value{GDBN} features for C++
c906108c
SS
6300
6301@cindex commands for C++
7a292a7a 6302
c906108c
SS
6303Some @value{GDBN} commands are particularly useful with C++, and some are
6304designed specifically for use with C++. Here is a summary:
6305
6306@table @code
6307@cindex break in overloaded functions
6308@item @r{breakpoint menus}
6309When you want a breakpoint in a function whose name is overloaded,
6310@value{GDBN} breakpoint menus help you specify which function definition
6311you want. @xref{Breakpoint Menus,,Breakpoint menus}.
6312
6313@cindex overloading in C++
6314@item rbreak @var{regex}
6315Setting breakpoints using regular expressions is helpful for setting
6316breakpoints on overloaded functions that are not members of any special
6317classes.
6318@xref{Set Breaks, ,Setting breakpoints}.
6319
6320@cindex C++ exception handling
6321@item catch throw
6322@itemx catch catch
6323Debug C++ exception handling using these commands. @xref{Set
6324Catchpoints, , Setting catchpoints}.
6325
6326@cindex inheritance
6327@item ptype @var{typename}
6328Print inheritance relationships as well as other information for type
6329@var{typename}.
6330@xref{Symbols, ,Examining the Symbol Table}.
6331
6332@cindex C++ symbol display
6333@item set print demangle
6334@itemx show print demangle
6335@itemx set print asm-demangle
6336@itemx show print asm-demangle
6337Control whether C++ symbols display in their source form, both when
6338displaying code as C++ source and when displaying disassemblies.
6339@xref{Print Settings, ,Print settings}.
6340
6341@item set print object
6342@itemx show print object
6343Choose whether to print derived (actual) or declared types of objects.
6344@xref{Print Settings, ,Print settings}.
6345
6346@item set print vtbl
6347@itemx show print vtbl
6348Control the format for printing virtual function tables.
6349@xref{Print Settings, ,Print settings}.
c906108c
SS
6350(The @code{vtbl} commands do not work on programs compiled with the HP
6351ANSI C++ compiler (@code{aCC}).)
6352
6353@kindex set overload-resolution
d4f3574e 6354@cindex overloaded functions, overload resolution
c906108c
SS
6355@item set overload-resolution on
6356Enable overload resolution for C++ expression evaluation. The default
6357is on. For overloaded functions, @value{GDBN} evaluates the arguments
6358and searches for a function whose signature matches the argument types,
d4f3574e
SS
6359using the standard C++ conversion rules (see @ref{C plus plus expressions, ,C++
6360expressions}, for details). If it cannot find a match, it emits a
c906108c
SS
6361message.
6362
6363@item set overload-resolution off
6364Disable overload resolution for C++ expression evaluation. For
6365overloaded functions that are not class member functions, @value{GDBN}
6366chooses the first function of the specified name that it finds in the
6367symbol table, whether or not its arguments are of the correct type. For
6368overloaded functions that are class member functions, @value{GDBN}
6369searches for a function whose signature @emph{exactly} matches the
6370argument types.
c906108c
SS
6371
6372@item @r{Overloaded symbol names}
6373You can specify a particular definition of an overloaded symbol, using
6374the same notation that is used to declare such symbols in C++: type
6375@code{@var{symbol}(@var{types})} rather than just @var{symbol}. You can
6376also use the @value{GDBN} command-line word completion facilities to list the
6377available choices, or to finish the type list for you.
6378@xref{Completion,, Command completion}, for details on how to do this.
6379@end table
c906108c 6380
6d2ebf8b 6381@node Modula-2
c906108c 6382@subsection Modula-2
7a292a7a 6383
d4f3574e 6384@cindex Modula-2, @value{GDBN} support
c906108c
SS
6385
6386The extensions made to @value{GDBN} to support Modula-2 only support
6387output from the @sc{gnu} Modula-2 compiler (which is currently being
6388developed). Other Modula-2 compilers are not currently supported, and
6389attempting to debug executables produced by them is most likely
6390to give an error as @value{GDBN} reads in the executable's symbol
6391table.
6392
6393@cindex expressions in Modula-2
6394@menu
6395* M2 Operators:: Built-in operators
6396* Built-In Func/Proc:: Built-in functions and procedures
6397* M2 Constants:: Modula-2 constants
6398* M2 Defaults:: Default settings for Modula-2
6399* Deviations:: Deviations from standard Modula-2
6400* M2 Checks:: Modula-2 type and range checks
6401* M2 Scope:: The scope operators @code{::} and @code{.}
6402* GDB/M2:: @value{GDBN} and Modula-2
6403@end menu
6404
6d2ebf8b 6405@node M2 Operators
c906108c
SS
6406@subsubsection Operators
6407@cindex Modula-2 operators
6408
6409Operators must be defined on values of specific types. For instance,
6410@code{+} is defined on numbers, but not on structures. Operators are
6411often defined on groups of types. For the purposes of Modula-2, the
6412following definitions hold:
6413
6414@itemize @bullet
6415
6416@item
6417@emph{Integral types} consist of @code{INTEGER}, @code{CARDINAL}, and
6418their subranges.
6419
6420@item
6421@emph{Character types} consist of @code{CHAR} and its subranges.
6422
6423@item
6424@emph{Floating-point types} consist of @code{REAL}.
6425
6426@item
6427@emph{Pointer types} consist of anything declared as @code{POINTER TO
6428@var{type}}.
6429
6430@item
6431@emph{Scalar types} consist of all of the above.
6432
6433@item
6434@emph{Set types} consist of @code{SET} and @code{BITSET} types.
6435
6436@item
6437@emph{Boolean types} consist of @code{BOOLEAN}.
6438@end itemize
6439
6440@noindent
6441The following operators are supported, and appear in order of
6442increasing precedence:
6443
6444@table @code
6445@item ,
6446Function argument or array index separator.
6447
6448@item :=
6449Assignment. The value of @var{var} @code{:=} @var{value} is
6450@var{value}.
6451
6452@item <@r{, }>
6453Less than, greater than on integral, floating-point, or enumerated
6454types.
6455
6456@item <=@r{, }>=
96a2c332 6457Less than or equal to, greater than or equal to
c906108c
SS
6458on integral, floating-point and enumerated types, or set inclusion on
6459set types. Same precedence as @code{<}.
6460
6461@item =@r{, }<>@r{, }#
6462Equality and two ways of expressing inequality, valid on scalar types.
6463Same precedence as @code{<}. In @value{GDBN} scripts, only @code{<>} is
6464available for inequality, since @code{#} conflicts with the script
6465comment character.
6466
6467@item IN
6468Set membership. Defined on set types and the types of their members.
6469Same precedence as @code{<}.
6470
6471@item OR
6472Boolean disjunction. Defined on boolean types.
6473
6474@item AND@r{, }&
d4f3574e 6475Boolean conjunction. Defined on boolean types.
c906108c
SS
6476
6477@item @@
6478The @value{GDBN} ``artificial array'' operator (@pxref{Expressions, ,Expressions}).
6479
6480@item +@r{, }-
6481Addition and subtraction on integral and floating-point types, or union
6482and difference on set types.
6483
6484@item *
6485Multiplication on integral and floating-point types, or set intersection
6486on set types.
6487
6488@item /
6489Division on floating-point types, or symmetric set difference on set
6490types. Same precedence as @code{*}.
6491
6492@item DIV@r{, }MOD
6493Integer division and remainder. Defined on integral types. Same
6494precedence as @code{*}.
6495
6496@item -
6497Negative. Defined on @code{INTEGER} and @code{REAL} data.
6498
6499@item ^
6500Pointer dereferencing. Defined on pointer types.
6501
6502@item NOT
6503Boolean negation. Defined on boolean types. Same precedence as
6504@code{^}.
6505
6506@item .
6507@code{RECORD} field selector. Defined on @code{RECORD} data. Same
6508precedence as @code{^}.
6509
6510@item []
6511Array indexing. Defined on @code{ARRAY} data. Same precedence as @code{^}.
6512
6513@item ()
6514Procedure argument list. Defined on @code{PROCEDURE} objects. Same precedence
6515as @code{^}.
6516
6517@item ::@r{, }.
6518@value{GDBN} and Modula-2 scope operators.
6519@end table
6520
6521@quotation
6522@emph{Warning:} Sets and their operations are not yet supported, so @value{GDBN}
6523treats the use of the operator @code{IN}, or the use of operators
6524@code{+}, @code{-}, @code{*}, @code{/}, @code{=}, , @code{<>}, @code{#},
6525@code{<=}, and @code{>=} on sets as an error.
6526@end quotation
6527
6528@cindex Modula-2 built-ins
6d2ebf8b 6529@node Built-In Func/Proc
c906108c
SS
6530@subsubsection Built-in functions and procedures
6531
6532Modula-2 also makes available several built-in procedures and functions.
6533In describing these, the following metavariables are used:
6534
6535@table @var
6536
6537@item a
6538represents an @code{ARRAY} variable.
6539
6540@item c
6541represents a @code{CHAR} constant or variable.
6542
6543@item i
6544represents a variable or constant of integral type.
6545
6546@item m
6547represents an identifier that belongs to a set. Generally used in the
6548same function with the metavariable @var{s}. The type of @var{s} should
6549be @code{SET OF @var{mtype}} (where @var{mtype} is the type of @var{m}).
6550
6551@item n
6552represents a variable or constant of integral or floating-point type.
6553
6554@item r
6555represents a variable or constant of floating-point type.
6556
6557@item t
6558represents a type.
6559
6560@item v
6561represents a variable.
6562
6563@item x
6564represents a variable or constant of one of many types. See the
6565explanation of the function for details.
6566@end table
6567
6568All Modula-2 built-in procedures also return a result, described below.
6569
6570@table @code
6571@item ABS(@var{n})
6572Returns the absolute value of @var{n}.
6573
6574@item CAP(@var{c})
6575If @var{c} is a lower case letter, it returns its upper case
c3f6f71d 6576equivalent, otherwise it returns its argument.
c906108c
SS
6577
6578@item CHR(@var{i})
6579Returns the character whose ordinal value is @var{i}.
6580
6581@item DEC(@var{v})
c3f6f71d 6582Decrements the value in the variable @var{v} by one. Returns the new value.
c906108c
SS
6583
6584@item DEC(@var{v},@var{i})
6585Decrements the value in the variable @var{v} by @var{i}. Returns the
6586new value.
6587
6588@item EXCL(@var{m},@var{s})
6589Removes the element @var{m} from the set @var{s}. Returns the new
6590set.
6591
6592@item FLOAT(@var{i})
6593Returns the floating point equivalent of the integer @var{i}.
6594
6595@item HIGH(@var{a})
6596Returns the index of the last member of @var{a}.
6597
6598@item INC(@var{v})
c3f6f71d 6599Increments the value in the variable @var{v} by one. Returns the new value.
c906108c
SS
6600
6601@item INC(@var{v},@var{i})
6602Increments the value in the variable @var{v} by @var{i}. Returns the
6603new value.
6604
6605@item INCL(@var{m},@var{s})
6606Adds the element @var{m} to the set @var{s} if it is not already
6607there. Returns the new set.
6608
6609@item MAX(@var{t})
6610Returns the maximum value of the type @var{t}.
6611
6612@item MIN(@var{t})
6613Returns the minimum value of the type @var{t}.
6614
6615@item ODD(@var{i})
6616Returns boolean TRUE if @var{i} is an odd number.
6617
6618@item ORD(@var{x})
6619Returns the ordinal value of its argument. For example, the ordinal
c3f6f71d
JM
6620value of a character is its @sc{ascii} value (on machines supporting the
6621@sc{ascii} character set). @var{x} must be of an ordered type, which include
c906108c
SS
6622integral, character and enumerated types.
6623
6624@item SIZE(@var{x})
6625Returns the size of its argument. @var{x} can be a variable or a type.
6626
6627@item TRUNC(@var{r})
6628Returns the integral part of @var{r}.
6629
6630@item VAL(@var{t},@var{i})
6631Returns the member of the type @var{t} whose ordinal value is @var{i}.
6632@end table
6633
6634@quotation
6635@emph{Warning:} Sets and their operations are not yet supported, so
6636@value{GDBN} treats the use of procedures @code{INCL} and @code{EXCL} as
6637an error.
6638@end quotation
6639
6640@cindex Modula-2 constants
6d2ebf8b 6641@node M2 Constants
c906108c
SS
6642@subsubsection Constants
6643
6644@value{GDBN} allows you to express the constants of Modula-2 in the following
6645ways:
6646
6647@itemize @bullet
6648
6649@item
6650Integer constants are simply a sequence of digits. When used in an
6651expression, a constant is interpreted to be type-compatible with the
6652rest of the expression. Hexadecimal integers are specified by a
6653trailing @samp{H}, and octal integers by a trailing @samp{B}.
6654
6655@item
6656Floating point constants appear as a sequence of digits, followed by a
6657decimal point and another sequence of digits. An optional exponent can
6658then be specified, in the form @samp{E@r{[}+@r{|}-@r{]}@var{nnn}}, where
6659@samp{@r{[}+@r{|}-@r{]}@var{nnn}} is the desired exponent. All of the
6660digits of the floating point constant must be valid decimal (base 10)
6661digits.
6662
6663@item
6664Character constants consist of a single character enclosed by a pair of
6665like quotes, either single (@code{'}) or double (@code{"}). They may
c3f6f71d 6666also be expressed by their ordinal value (their @sc{ascii} value, usually)
c906108c
SS
6667followed by a @samp{C}.
6668
6669@item
6670String constants consist of a sequence of characters enclosed by a
6671pair of like quotes, either single (@code{'}) or double (@code{"}).
6672Escape sequences in the style of C are also allowed. @xref{C
6673Constants, ,C and C++ constants}, for a brief explanation of escape
6674sequences.
6675
6676@item
6677Enumerated constants consist of an enumerated identifier.
6678
6679@item
6680Boolean constants consist of the identifiers @code{TRUE} and
6681@code{FALSE}.
6682
6683@item
6684Pointer constants consist of integral values only.
6685
6686@item
6687Set constants are not yet supported.
6688@end itemize
6689
6d2ebf8b 6690@node M2 Defaults
c906108c
SS
6691@subsubsection Modula-2 defaults
6692@cindex Modula-2 defaults
6693
6694If type and range checking are set automatically by @value{GDBN}, they
6695both default to @code{on} whenever the working language changes to
d4f3574e 6696Modula-2. This happens regardless of whether you or @value{GDBN}
c906108c
SS
6697selected the working language.
6698
6699If you allow @value{GDBN} to set the language automatically, then entering
6700code compiled from a file whose name ends with @file{.mod} sets the
d4f3574e 6701working language to Modula-2. @xref{Automatically, ,Having @value{GDBN} set
c906108c
SS
6702the language automatically}, for further details.
6703
6d2ebf8b 6704@node Deviations
c906108c
SS
6705@subsubsection Deviations from standard Modula-2
6706@cindex Modula-2, deviations from
6707
6708A few changes have been made to make Modula-2 programs easier to debug.
6709This is done primarily via loosening its type strictness:
6710
6711@itemize @bullet
6712@item
6713Unlike in standard Modula-2, pointer constants can be formed by
6714integers. This allows you to modify pointer variables during
6715debugging. (In standard Modula-2, the actual address contained in a
6716pointer variable is hidden from you; it can only be modified
6717through direct assignment to another pointer variable or expression that
6718returned a pointer.)
6719
6720@item
6721C escape sequences can be used in strings and characters to represent
6722non-printable characters. @value{GDBN} prints out strings with these
6723escape sequences embedded. Single non-printable characters are
6724printed using the @samp{CHR(@var{nnn})} format.
6725
6726@item
6727The assignment operator (@code{:=}) returns the value of its right-hand
6728argument.
6729
6730@item
6731All built-in procedures both modify @emph{and} return their argument.
6732@end itemize
6733
6d2ebf8b 6734@node M2 Checks
c906108c
SS
6735@subsubsection Modula-2 type and range checks
6736@cindex Modula-2 checks
6737
6738@quotation
6739@emph{Warning:} in this release, @value{GDBN} does not yet perform type or
6740range checking.
6741@end quotation
6742@c FIXME remove warning when type/range checks added
6743
6744@value{GDBN} considers two Modula-2 variables type equivalent if:
6745
6746@itemize @bullet
6747@item
6748They are of types that have been declared equivalent via a @code{TYPE
6749@var{t1} = @var{t2}} statement
6750
6751@item
6752They have been declared on the same line. (Note: This is true of the
6753@sc{gnu} Modula-2 compiler, but it may not be true of other compilers.)
6754@end itemize
6755
6756As long as type checking is enabled, any attempt to combine variables
6757whose types are not equivalent is an error.
6758
6759Range checking is done on all mathematical operations, assignment, array
6760index bounds, and all built-in functions and procedures.
6761
6d2ebf8b 6762@node M2 Scope
c906108c
SS
6763@subsubsection The scope operators @code{::} and @code{.}
6764@cindex scope
6765@kindex .
6766@cindex colon, doubled as scope operator
6767@ifinfo
d4f3574e 6768@kindex colon-colon@r{, in Modula-2}
c906108c
SS
6769@c Info cannot handle :: but TeX can.
6770@end ifinfo
6771@iftex
6772@kindex ::
6773@end iftex
6774
6775There are a few subtle differences between the Modula-2 scope operator
6776(@code{.}) and the @value{GDBN} scope operator (@code{::}). The two have
6777similar syntax:
6778
6779@example
6780
6781@var{module} . @var{id}
6782@var{scope} :: @var{id}
6783@end example
6784
6785@noindent
6786where @var{scope} is the name of a module or a procedure,
6787@var{module} the name of a module, and @var{id} is any declared
6788identifier within your program, except another module.
6789
6790Using the @code{::} operator makes @value{GDBN} search the scope
6791specified by @var{scope} for the identifier @var{id}. If it is not
6792found in the specified scope, then @value{GDBN} searches all scopes
6793enclosing the one specified by @var{scope}.
6794
6795Using the @code{.} operator makes @value{GDBN} search the current scope for
6796the identifier specified by @var{id} that was imported from the
6797definition module specified by @var{module}. With this operator, it is
6798an error if the identifier @var{id} was not imported from definition
6799module @var{module}, or if @var{id} is not an identifier in
6800@var{module}.
6801
6d2ebf8b 6802@node GDB/M2
c906108c
SS
6803@subsubsection @value{GDBN} and Modula-2
6804
6805Some @value{GDBN} commands have little use when debugging Modula-2 programs.
6806Five subcommands of @code{set print} and @code{show print} apply
6807specifically to C and C++: @samp{vtbl}, @samp{demangle},
6808@samp{asm-demangle}, @samp{object}, and @samp{union}. The first four
6809apply to C++, and the last to the C @code{union} type, which has no direct
6810analogue in Modula-2.
6811
6812The @code{@@} operator (@pxref{Expressions, ,Expressions}), while available
d4f3574e 6813with any language, is not useful with Modula-2. Its
c906108c
SS
6814intent is to aid the debugging of @dfn{dynamic arrays}, which cannot be
6815created in Modula-2 as they can in C or C++. However, because an
6816address can be specified by an integral constant, the construct
d4f3574e 6817@samp{@{@var{type}@}@var{adrexp}} is still useful.
c906108c
SS
6818
6819@cindex @code{#} in Modula-2
6820In @value{GDBN} scripts, the Modula-2 inequality operator @code{#} is
6821interpreted as the beginning of a comment. Use @code{<>} instead.
c906108c 6822
6d2ebf8b 6823@node Chill
cce74817
JM
6824@subsection Chill
6825
6826The extensions made to @value{GDBN} to support Chill only support output
d4f3574e 6827from the @sc{gnu} Chill compiler. Other Chill compilers are not currently
cce74817
JM
6828supported, and attempting to debug executables produced by them is most
6829likely to give an error as @value{GDBN} reads in the executable's symbol
6830table.
6831
d4f3574e
SS
6832@c This used to say "... following Chill related topics ...", but since
6833@c menus are not shown in the printed manual, it would look awkward.
6834This section covers the Chill related topics and the features
cce74817
JM
6835of @value{GDBN} which support these topics.
6836
6837@menu
104c1213
JM
6838* How modes are displayed:: How modes are displayed
6839* Locations:: Locations and their accesses
cce74817 6840* Values and their Operations:: Values and their Operations
5d161b24 6841* Chill type and range checks::
53a5351d 6842* Chill defaults::
cce74817
JM
6843@end menu
6844
6d2ebf8b 6845@node How modes are displayed
cce74817
JM
6846@subsubsection How modes are displayed
6847
6848The Chill Datatype- (Mode) support of @value{GDBN} is directly related
d4f3574e 6849with the functionality of the @sc{gnu} Chill compiler, and therefore deviates
cce74817
JM
6850slightly from the standard specification of the Chill language. The
6851provided modes are:
d4f3574e
SS
6852
6853@c FIXME: this @table's contents effectively disable @code by using @r
6854@c on every @item. So why does it need @code?
cce74817
JM
6855@table @code
6856@item @r{@emph{Discrete modes:}}
6857@itemize @bullet
6858@item
6859@emph{Integer Modes} which are predefined by @code{BYTE, UBYTE, INT,
6860UINT, LONG, ULONG},
6861@item
5d161b24 6862@emph{Boolean Mode} which is predefined by @code{BOOL},
cce74817 6863@item
5d161b24 6864@emph{Character Mode} which is predefined by @code{CHAR},
cce74817
JM
6865@item
6866@emph{Set Mode} which is displayed by the keyword @code{SET}.
6867@smallexample
6868(@value{GDBP}) ptype x
6869type = SET (karli = 10, susi = 20, fritzi = 100)
6870@end smallexample
6871If the type is an unnumbered set the set element values are omitted.
6872@item
6d2ebf8b
SS
6873@emph{Range Mode} which is displayed by
6874@smallexample
6875@code{type = <basemode>(<lower bound> : <upper bound>)}
6876@end smallexample
6877where @code{<lower bound>, <upper bound>} can be of any discrete literal
6878expression (e.g. set element names).
cce74817
JM
6879@end itemize
6880
6881@item @r{@emph{Powerset Mode:}}
6882A Powerset Mode is displayed by the keyword @code{POWERSET} followed by
d4f3574e 6883the member mode of the powerset. The member mode can be any discrete mode.
cce74817
JM
6884@smallexample
6885(@value{GDBP}) ptype x
6886type = POWERSET SET (egon, hugo, otto)
6887@end smallexample
6888
6889@item @r{@emph{Reference Modes:}}
6890@itemize @bullet
6891@item
d4f3574e 6892@emph{Bound Reference Mode} which is displayed by the keyword @code{REF}
cce74817
JM
6893followed by the mode name to which the reference is bound.
6894@item
6895@emph{Free Reference Mode} which is displayed by the keyword @code{PTR}.
6896@end itemize
6897
6898@item @r{@emph{Procedure mode}}
6899The procedure mode is displayed by @code{type = PROC(<parameter list>)
6900<return mode> EXCEPTIONS (<exception list>)}. The @code{<parameter
d4f3574e
SS
6901list>} is a list of the parameter modes. @code{<return mode>} indicates
6902the mode of the result of the procedure if any. The exceptionlist lists
cce74817
JM
6903all possible exceptions which can be raised by the procedure.
6904
6905@ignore
6906@item @r{@emph{Instance mode}}
6907The instance mode is represented by a structure, which has a static
5d161b24 6908type, and is therefore not really of interest.
cce74817
JM
6909@end ignore
6910
5d161b24 6911@item @r{@emph{Synchronization Modes:}}
cce74817
JM
6912@itemize @bullet
6913@item
6d2ebf8b
SS
6914@emph{Event Mode} which is displayed by
6915@smallexample
6916@code{EVENT (<event length>)}
6917@end smallexample
cce74817
JM
6918where @code{(<event length>)} is optional.
6919@item
6d2ebf8b
SS
6920@emph{Buffer Mode} which is displayed by
6921@smallexample
6922@code{BUFFER (<buffer length>)<buffer element mode>}
6923@end smallexample
6924where @code{(<buffer length>)} is optional.
cce74817
JM
6925@end itemize
6926
5d161b24 6927@item @r{@emph{Timing Modes:}}
cce74817
JM
6928@itemize @bullet
6929@item
6930@emph{Duration Mode} which is predefined by @code{DURATION}
6931@item
6932@emph{Absolute Time Mode} which is predefined by @code{TIME}
6933@end itemize
6934
6935@item @r{@emph{Real Modes:}}
6936Real Modes are predefined with @code{REAL} and @code{LONG_REAL}.
6937
6938@item @r{@emph{String Modes:}}
6939@itemize @bullet
6940@item
6d2ebf8b
SS
6941@emph{Character String Mode} which is displayed by
6942@smallexample
6943@code{CHARS(<string length>)}
6944@end smallexample
6945followed by the keyword @code{VARYING} if the String Mode is a varying
6946mode
cce74817 6947@item
6d2ebf8b
SS
6948@emph{Bit String Mode} which is displayed by
6949@smallexample
6950@code{BOOLS(<string
6951length>)}
6952@end smallexample
cce74817
JM
6953@end itemize
6954
6955@item @r{@emph{Array Mode:}}
6956The Array Mode is displayed by the keyword @code{ARRAY(<range>)}
6957followed by the element mode (which may in turn be an array mode).
6958@smallexample
6959(@value{GDBP}) ptype x
5d161b24
DB
6960type = ARRAY (1:42)
6961 ARRAY (1:20)
cce74817
JM
6962 SET (karli = 10, susi = 20, fritzi = 100)
6963@end smallexample
6964
5d161b24 6965@item @r{@emph{Structure Mode}}
cce74817 6966The Structure mode is displayed by the keyword @code{STRUCT(<field
d4f3574e
SS
6967list>)}. The @code{<field list>} consists of names and modes of fields
6968of the structure. Variant structures have the keyword @code{CASE <field>
6969OF <variant fields> ESAC} in their field list. Since the current version
cce74817
JM
6970of the GNU Chill compiler doesn't implement tag processing (no runtime
6971checks of variant fields, and therefore no debugging info), the output
6972always displays all variant fields.
6973@smallexample
6974(@value{GDBP}) ptype str
6975type = STRUCT (
6976 as x,
6977 bs x,
6978 CASE bs OF
6979 (karli):
6980 cs a
6981 (ott):
6982 ds x
6983 ESAC
6984)
6985@end smallexample
6986@end table
6987
6d2ebf8b 6988@node Locations
cce74817
JM
6989@subsubsection Locations and their accesses
6990
6991A location in Chill is an object which can contain values.
6992
6993A value of a location is generally accessed by the (declared) name of
d4f3574e
SS
6994the location. The output conforms to the specification of values in
6995Chill programs. How values are specified
6996is the topic of the next section, @ref{Values and their Operations}.
cce74817
JM
6997
6998The pseudo-location @code{RESULT} (or @code{result}) can be used to
6999display or change the result of a currently-active procedure:
d4f3574e 7000
cce74817
JM
7001@smallexample
7002set result := EXPR
7003@end smallexample
d4f3574e
SS
7004
7005@noindent
7006This does the same as the Chill action @code{RESULT EXPR} (which
c3f6f71d 7007is not available in @value{GDBN}).
cce74817
JM
7008
7009Values of reference mode locations are printed by @code{PTR(<hex
7010value>)} in case of a free reference mode, and by @code{(REF <reference
d4f3574e 7011mode>) (<hex-value>)} in case of a bound reference. @code{<hex value>}
cce74817
JM
7012represents the address where the reference points to. To access the
7013value of the location referenced by the pointer, use the dereference
d4f3574e 7014operator @samp{->}.
cce74817 7015
6d2ebf8b
SS
7016Values of procedure mode locations are displayed by
7017@smallexample
7018@code{@{ PROC
cce74817 7019(<argument modes> ) <return mode> @} <address> <name of procedure
6d2ebf8b
SS
7020location>}
7021@end smallexample
7022@code{<argument modes>} is a list of modes according to the parameter
7023specification of the procedure and @code{<address>} shows the address of
7024the entry point.
cce74817
JM
7025
7026@ignore
7027Locations of instance modes are displayed just like a structure with two
7028fields specifying the @emph{process type} and the @emph{copy number} of
7029the investigated instance location@footnote{This comes from the current
d4f3574e
SS
7030implementation of instances. They are implemented as a structure (no
7031na). The output should be something like @code{[<name of the process>;
7032<instance number>]}.}. The field names are @code{__proc_type} and
cce74817
JM
7033@code{__proc_copy}.
7034
7035Locations of synchronization modes are displayed like a structure with
7036the field name @code{__event_data} in case of a event mode location, and
7037like a structure with the field @code{__buffer_data} in case of a buffer
7038mode location (refer to previous paragraph).
7039
7040Structure Mode locations are printed by @code{[.<field name>: <value>,
d4f3574e 7041...]}. The @code{<field name>} corresponds to the structure mode
cce74817 7042definition and the layout of @code{<value>} varies depending of the mode
d4f3574e
SS
7043of the field. If the investigated structure mode location is of variant
7044structure mode, the variant parts of the structure are enclosed in curled
7045braces (@samp{@{@}}). Fields enclosed by @samp{@{,@}} are residing
cce74817 7046on the same memory location and represent the current values of the
d4f3574e 7047memory location in their specific modes. Since no tag processing is done
cce74817 7048all variants are displayed. A variant field is printed by
d4f3574e 7049@code{(<variant name>) = .<field name>: <value>}. (who implements the
cce74817
JM
7050stuff ???)
7051@smallexample
7052(@value{GDBP}) print str1 $4 = [.as: 0, .bs: karli, .<TAG>: { (karli) =
7053[.cs: []], (susi) = [.ds: susi]}]
7054@end smallexample
7055@end ignore
7056
7057Substructures of string mode-, array mode- or structure mode-values
7058(e.g. array slices, fields of structure locations) are accessed using
d4f3574e
SS
7059certain operations which are described in the next section, @ref{Values
7060and their Operations}.
cce74817
JM
7061
7062A location value may be interpreted as having a different mode using the
d4f3574e
SS
7063location conversion. This mode conversion is written as @code{<mode
7064name>(<location>)}. The user has to consider that the sizes of the modes
7065have to be equal otherwise an error occurs. Furthermore, no range
7066checking of the location against the destination mode is performed, and
cce74817 7067therefore the result can be quite confusing.
d4f3574e 7068
cce74817
JM
7069@smallexample
7070(@value{GDBP}) print int (s(3 up 4)) XXX TO be filled in !! XXX
7071@end smallexample
7072
6d2ebf8b 7073@node Values and their Operations
cce74817
JM
7074@subsubsection Values and their Operations
7075
7076Values are used to alter locations, to investigate complex structures in
7077more detail or to filter relevant information out of a large amount of
d4f3574e
SS
7078data. There are several (mode dependent) operations defined which enable
7079such investigations. These operations are not only applicable to
cce74817 7080constant values but also to locations, which can become quite useful
d4f3574e 7081when debugging complex structures. During parsing the command line
cce74817
JM
7082(e.g. evaluating an expression) @value{GDBN} treats location names as
7083the values behind these locations.
7084
d4f3574e 7085This section describes how values have to be specified and which
cce74817
JM
7086operations are legal to be used with such values.
7087
7088@table @code
7089@item Literal Values
d4f3574e
SS
7090Literal values are specified in the same manner as in @sc{gnu} Chill programs.
7091For detailed specification refer to the @sc{gnu} Chill implementation Manual
cce74817 7092chapter 1.5.
d4f3574e
SS
7093@c FIXME: if the Chill Manual is a Texinfo documents, the above should
7094@c be converted to a @ref.
cce74817 7095
5d161b24 7096@ignore
cce74817
JM
7097@itemize @bullet
7098@item
7099@emph{Integer Literals} are specified in the same manner as in Chill
d4f3574e 7100programs (refer to the Chill Standard z200/88 chpt 5.2.4.2)
cce74817
JM
7101@item
7102@emph{Boolean Literals} are defined by @code{TRUE} and @code{FALSE}.
7103@item
7104@emph{Character Literals} are defined by @code{'<character>'}. (e.g.
7105@code{'M'})
7106@item
7107@emph{Set Literals} are defined by a name which was specified in a set
d4f3574e
SS
7108mode. The value delivered by a Set Literal is the set value. This is
7109comparable to an enumeration in C/C++ language.
cce74817 7110@item
d4f3574e 7111@emph{Emptiness Literal} is predefined by @code{NULL}. The value of the
cce74817 7112emptiness literal delivers either the empty reference value, the empty
5d161b24 7113procedure value or the empty instance value.
cce74817
JM
7114
7115@item
7116@emph{Character String Literals} are defined by a sequence of characters
d4f3574e 7117enclosed in single- or double quotes. If a single- or double quote has
cce74817
JM
7118to be part of the string literal it has to be stuffed (specified twice).
7119@item
7120@emph{Bitstring Literals} are specified in the same manner as in Chill
7121programs (refer z200/88 chpt 5.2.4.8).
7122@item
7123@emph{Floating point literals} are specified in the same manner as in
d4f3574e 7124(gnu-)Chill programs (refer @sc{gnu} Chill implementation Manual chapter 1.5).
cce74817
JM
7125@end itemize
7126@end ignore
7127
7128@item Tuple Values
7129A tuple is specified by @code{<mode name>[<tuple>]}, where @code{<mode
d4f3574e 7130name>} can be omitted if the mode of the tuple is unambiguous. This
cce74817
JM
7131unambiguity is derived from the context of a evaluated expression.
7132@code{<tuple>} can be one of the following:
d4f3574e 7133
cce74817
JM
7134@itemize @bullet
7135@item @emph{Powerset Tuple}
7136@item @emph{Array Tuple}
7137@item @emph{Structure Tuple}
7138Powerset tuples, array tuples and structure tuples are specified in the
d4f3574e 7139same manner as in Chill programs refer to z200/88 chpt 5.2.5.
cce74817
JM
7140@end itemize
7141
7142@item String Element Value
6d2ebf8b
SS
7143A string element value is specified by
7144@smallexample
7145@code{<string value>(<index>)}
7146@end smallexample
d4f3574e 7147where @code{<index>} is a integer expression. It delivers a character
cce74817
JM
7148value which is equivalent to the character indexed by @code{<index>} in
7149the string.
7150
7151@item String Slice Value
7152A string slice value is specified by @code{<string value>(<slice
7153spec>)}, where @code{<slice spec>} can be either a range of integer
7154expressions or specified by @code{<start expr> up <size>}.
7155@code{<size>} denotes the number of elements which the slice contains.
7156The delivered value is a string value, which is part of the specified
7157string.
7158
7159@item Array Element Values
7160An array element value is specified by @code{<array value>(<expr>)} and
7161delivers a array element value of the mode of the specified array.
7162
7163@item Array Slice Values
7164An array slice is specified by @code{<array value>(<slice spec>)}, where
7165@code{<slice spec>} can be either a range specified by expressions or by
d4f3574e
SS
7166@code{<start expr> up <size>}. @code{<size>} denotes the number of
7167arrayelements the slice contains. The delivered value is an array value
cce74817
JM
7168which is part of the specified array.
7169
7170@item Structure Field Values
7171A structure field value is derived by @code{<structure value>.<field
d4f3574e
SS
7172name>}, where @code{<field name>} indicates the name of a field specified
7173in the mode definition of the structure. The mode of the delivered value
cce74817
JM
7174corresponds to this mode definition in the structure definition.
7175
7176@item Procedure Call Value
7177The procedure call value is derived from the return value of the
7178procedure@footnote{If a procedure call is used for instance in an
7179expression, then this procedure is called with all its side
d4f3574e 7180effects. This can lead to confusing results if used carelessly.}.
cce74817 7181
d4f3574e 7182Values of duration mode locations are represented by @code{ULONG} literals.
cce74817 7183
6d2ebf8b
SS
7184Values of time mode locations appear as
7185@smallexample
7186@code{TIME(<secs>:<nsecs>)}
7187@end smallexample
7188
cce74817
JM
7189
7190@ignore
7191This is not implemented yet:
7192@item Built-in Value
7193@noindent
7194The following built in functions are provided:
d4f3574e 7195
cce74817
JM
7196@table @code
7197@item @code{ADDR()}
7198@item @code{NUM()}
7199@item @code{PRED()}
7200@item @code{SUCC()}
7201@item @code{ABS()}
7202@item @code{CARD()}
7203@item @code{MAX()}
7204@item @code{MIN()}
7205@item @code{SIZE()}
7206@item @code{UPPER()}
7207@item @code{LOWER()}
7208@item @code{LENGTH()}
7209@item @code{SIN()}
7210@item @code{COS()}
7211@item @code{TAN()}
7212@item @code{ARCSIN()}
7213@item @code{ARCCOS()}
7214@item @code{ARCTAN()}
7215@item @code{EXP()}
7216@item @code{LN()}
7217@item @code{LOG()}
7218@item @code{SQRT()}
7219@end table
7220
7221For a detailed description refer to the GNU Chill implementation manual
7222chapter 1.6.
7223@end ignore
7224
7225@item Zero-adic Operator Value
7226The zero-adic operator value is derived from the instance value for the
7227current active process.
7228
7229@item Expression Values
7230The value delivered by an expression is the result of the evaluation of
d4f3574e 7231the specified expression. If there are error conditions (mode
cce74817 7232incompatibility, etc.) the evaluation of expressions is aborted with a
d4f3574e 7233corresponding error message. Expressions may be parenthesised which
cce74817 7234causes the evaluation of this expression before any other expression
d4f3574e 7235which uses the result of the parenthesised expression. The following
cce74817 7236operators are supported by @value{GDBN}:
d4f3574e 7237
cce74817
JM
7238@table @code
7239@item @code{OR, ORIF, XOR}
d4f3574e
SS
7240@itemx @code{AND, ANDIF}
7241@itemx @code{NOT}
cce74817 7242Logical operators defined over operands of boolean mode.
d4f3574e 7243
cce74817
JM
7244@item @code{=, /=}
7245Equality and inequality operators defined over all modes.
d4f3574e 7246
cce74817 7247@item @code{>, >=}
d4f3574e 7248@itemx @code{<, <=}
cce74817 7249Relational operators defined over predefined modes.
d4f3574e 7250
cce74817 7251@item @code{+, -}
d4f3574e 7252@itemx @code{*, /, MOD, REM}
cce74817 7253Arithmetic operators defined over predefined modes.
d4f3574e 7254
cce74817
JM
7255@item @code{-}
7256Change sign operator.
d4f3574e 7257
cce74817
JM
7258@item @code{//}
7259String concatenation operator.
d4f3574e 7260
cce74817
JM
7261@item @code{()}
7262String repetition operator.
d4f3574e 7263
cce74817
JM
7264@item @code{->}
7265Referenced location operator which can be used either to take the
7266address of a location (@code{->loc}), or to dereference a reference
7267location (@code{loc->}).
d4f3574e 7268
cce74817 7269@item @code{OR, XOR}
d4f3574e
SS
7270@itemx @code{AND}
7271@itemx @code{NOT}
cce74817 7272Powerset and bitstring operators.
d4f3574e 7273
cce74817 7274@item @code{>, >=}
d4f3574e 7275@itemx @code{<, <=}
cce74817 7276Powerset inclusion operators.
d4f3574e 7277
cce74817
JM
7278@item @code{IN}
7279Membership operator.
7280@end table
7281@end table
7282
6d2ebf8b 7283@node Chill type and range checks
cce74817
JM
7284@subsubsection Chill type and range checks
7285
7286@value{GDBN} considers two Chill variables mode equivalent if the sizes
d4f3574e 7287of the two modes are equal. This rule applies recursively to more
cce74817 7288complex datatypes which means that complex modes are treated
d4f3574e 7289equivalent if all element modes (which also can be complex modes like
cce74817
JM
7290structures, arrays, etc.) have the same size.
7291
7292Range checking is done on all mathematical operations, assignment, array
7293index bounds and all built in procedures.
7294
7295Strong type checks are forced using the @value{GDBN} command @code{set
d4f3574e 7296check strong}. This enforces strong type and range checks on all
cce74817
JM
7297operations where Chill constructs are used (expressions, built in
7298functions, etc.) in respect to the semantics as defined in the z.200
7299language specification.
7300
cce74817
JM
7301All checks can be disabled by the @value{GDBN} command @code{set check
7302off}.
7303
5d161b24 7304@ignore
53a5351d 7305@c Deviations from the Chill Standard Z200/88
cce74817
JM
7306see last paragraph ?
7307@end ignore
7308
6d2ebf8b 7309@node Chill defaults
cce74817
JM
7310@subsubsection Chill defaults
7311
7312If type and range checking are set automatically by @value{GDBN}, they
7313both default to @code{on} whenever the working language changes to
d4f3574e 7314Chill. This happens regardless of whether you or @value{GDBN}
cce74817
JM
7315selected the working language.
7316
7317If you allow @value{GDBN} to set the language automatically, then entering
7318code compiled from a file whose name ends with @file{.ch} sets the
d4f3574e 7319working language to Chill. @xref{Automatically, ,Having @value{GDBN} set
cce74817
JM
7320the language automatically}, for further details.
7321
6d2ebf8b 7322@node Symbols
c906108c
SS
7323@chapter Examining the Symbol Table
7324
d4f3574e 7325The commands described in this chapter allow you to inquire about the
c906108c
SS
7326symbols (names of variables, functions and types) defined in your
7327program. This information is inherent in the text of your program and
7328does not change as your program executes. @value{GDBN} finds it in your
7329program's symbol table, in the file indicated when you started @value{GDBN}
7330(@pxref{File Options, ,Choosing files}), or by one of the
7331file-management commands (@pxref{Files, ,Commands to specify files}).
7332
7333@cindex symbol names
7334@cindex names of symbols
7335@cindex quoting names
7336Occasionally, you may need to refer to symbols that contain unusual
7337characters, which @value{GDBN} ordinarily treats as word delimiters. The
7338most frequent case is in referring to static variables in other
7339source files (@pxref{Variables,,Program variables}). File names
7340are recorded in object files as debugging symbols, but @value{GDBN} would
7341ordinarily parse a typical file name, like @file{foo.c}, as the three words
7342@samp{foo} @samp{.} @samp{c}. To allow @value{GDBN} to recognize
7343@samp{foo.c} as a single symbol, enclose it in single quotes; for example,
7344
7345@example
7346p 'foo.c'::x
7347@end example
7348
7349@noindent
7350looks up the value of @code{x} in the scope of the file @file{foo.c}.
7351
7352@table @code
7353@kindex info address
7354@item info address @var{symbol}
7355Describe where the data for @var{symbol} is stored. For a register
7356variable, this says which register it is kept in. For a non-register
7357local variable, this prints the stack-frame offset at which the variable
7358is always stored.
7359
7360Note the contrast with @samp{print &@var{symbol}}, which does not work
7361at all for a register variable, and for a stack local variable prints
7362the exact address of the current instantiation of the variable.
7363
7364@kindex whatis
d4f3574e
SS
7365@item whatis @var{expr}
7366Print the data type of expression @var{expr}. @var{expr} is not
c906108c
SS
7367actually evaluated, and any side-effecting operations (such as
7368assignments or function calls) inside it do not take place.
7369@xref{Expressions, ,Expressions}.
7370
7371@item whatis
7372Print the data type of @code{$}, the last value in the value history.
7373
7374@kindex ptype
7375@item ptype @var{typename}
7376Print a description of data type @var{typename}. @var{typename} may be
7a292a7a
SS
7377the name of a type, or for C code it may have the form @samp{class
7378@var{class-name}}, @samp{struct @var{struct-tag}}, @samp{union
7379@var{union-tag}} or @samp{enum @var{enum-tag}}.
c906108c 7380
d4f3574e 7381@item ptype @var{expr}
c906108c 7382@itemx ptype
d4f3574e 7383Print a description of the type of expression @var{expr}. @code{ptype}
c906108c
SS
7384differs from @code{whatis} by printing a detailed description, instead
7385of just the name of the type.
7386
7387For example, for this variable declaration:
7388
7389@example
7390struct complex @{double real; double imag;@} v;
7391@end example
7392
7393@noindent
7394the two commands give this output:
7395
7396@example
7397@group
7398(@value{GDBP}) whatis v
7399type = struct complex
7400(@value{GDBP}) ptype v
7401type = struct complex @{
7402 double real;
7403 double imag;
7404@}
7405@end group
7406@end example
7407
7408@noindent
7409As with @code{whatis}, using @code{ptype} without an argument refers to
7410the type of @code{$}, the last value in the value history.
7411
7412@kindex info types
7413@item info types @var{regexp}
7414@itemx info types
d4f3574e 7415Print a brief description of all types whose names match @var{regexp}
c906108c
SS
7416(or all types in your program, if you supply no argument). Each
7417complete typename is matched as though it were a complete line; thus,
7418@samp{i type value} gives information on all types in your program whose
d4f3574e 7419names include the string @code{value}, but @samp{i type ^value$} gives
c906108c
SS
7420information only on types whose complete name is @code{value}.
7421
7422This command differs from @code{ptype} in two ways: first, like
7423@code{whatis}, it does not print a detailed description; second, it
7424lists all source files where a type is defined.
7425
7426@kindex info source
7427@item info source
7428Show the name of the current source file---that is, the source file for
7429the function containing the current point of execution---and the language
7430it was written in.
7431
7432@kindex info sources
7433@item info sources
7434Print the names of all source files in your program for which there is
7435debugging information, organized into two lists: files whose symbols
7436have already been read, and files whose symbols will be read when needed.
7437
7438@kindex info functions
7439@item info functions
7440Print the names and data types of all defined functions.
7441
7442@item info functions @var{regexp}
7443Print the names and data types of all defined functions
7444whose names contain a match for regular expression @var{regexp}.
7445Thus, @samp{info fun step} finds all functions whose names
7446include @code{step}; @samp{info fun ^step} finds those whose names
7447start with @code{step}.
7448
7449@kindex info variables
7450@item info variables
7451Print the names and data types of all variables that are declared
7452outside of functions (i.e., excluding local variables).
7453
7454@item info variables @var{regexp}
7455Print the names and data types of all variables (except for local
7456variables) whose names contain a match for regular expression
7457@var{regexp}.
7458
7459@ignore
7460This was never implemented.
7461@kindex info methods
7462@item info methods
7463@itemx info methods @var{regexp}
7464The @code{info methods} command permits the user to examine all defined
7465methods within C++ program, or (with the @var{regexp} argument) a
7466specific set of methods found in the various C++ classes. Many
7467C++ classes provide a large number of methods. Thus, the output
7468from the @code{ptype} command can be overwhelming and hard to use. The
7469@code{info-methods} command filters the methods, printing only those
7470which match the regular-expression @var{regexp}.
7471@end ignore
7472
c906108c
SS
7473@cindex reloading symbols
7474Some systems allow individual object files that make up your program to
7a292a7a
SS
7475be replaced without stopping and restarting your program. For example,
7476in VxWorks you can simply recompile a defective object file and keep on
7477running. If you are running on one of these systems, you can allow
7478@value{GDBN} to reload the symbols for automatically relinked modules:
c906108c
SS
7479
7480@table @code
7481@kindex set symbol-reloading
7482@item set symbol-reloading on
7483Replace symbol definitions for the corresponding source file when an
7484object file with a particular name is seen again.
7485
7486@item set symbol-reloading off
6d2ebf8b
SS
7487Do not replace symbol definitions when encountering object files of the
7488same name more than once. This is the default state; if you are not
7489running on a system that permits automatic relinking of modules, you
7490should leave @code{symbol-reloading} off, since otherwise @value{GDBN}
7491may discard symbols when linking large programs, that may contain
7492several modules (from different directories or libraries) with the same
7493name.
c906108c
SS
7494
7495@kindex show symbol-reloading
7496@item show symbol-reloading
7497Show the current @code{on} or @code{off} setting.
7498@end table
c906108c 7499
c906108c
SS
7500@kindex set opaque-type-resolution
7501@item set opaque-type-resolution on
7502Tell @value{GDBN} to resolve opaque types. An opaque type is a type
7503declared as a pointer to a @code{struct}, @code{class}, or
7504@code{union}---for example, @code{struct MyType *}---that is used in one
7505source file although the full declaration of @code{struct MyType} is in
7506another source file. The default is on.
7507
7508A change in the setting of this subcommand will not take effect until
7509the next time symbols for a file are loaded.
7510
7511@item set opaque-type-resolution off
7512Tell @value{GDBN} not to resolve opaque types. In this case, the type
7513is printed as follows:
7514@smallexample
7515@{<no data fields>@}
7516@end smallexample
7517
7518@kindex show opaque-type-resolution
7519@item show opaque-type-resolution
7520Show whether opaque types are resolved or not.
c906108c
SS
7521
7522@kindex maint print symbols
7523@cindex symbol dump
7524@kindex maint print psymbols
7525@cindex partial symbol dump
7526@item maint print symbols @var{filename}
7527@itemx maint print psymbols @var{filename}
7528@itemx maint print msymbols @var{filename}
7529Write a dump of debugging symbol data into the file @var{filename}.
7530These commands are used to debug the @value{GDBN} symbol-reading code. Only
7531symbols with debugging data are included. If you use @samp{maint print
7532symbols}, @value{GDBN} includes all the symbols for which it has already
7533collected full details: that is, @var{filename} reflects symbols for
7534only those files whose symbols @value{GDBN} has read. You can use the
7535command @code{info sources} to find out which files these are. If you
7536use @samp{maint print psymbols} instead, the dump shows information about
7537symbols that @value{GDBN} only knows partially---that is, symbols defined in
7538files that @value{GDBN} has skimmed, but not yet read completely. Finally,
7539@samp{maint print msymbols} dumps just the minimal symbol information
7540required for each object file from which @value{GDBN} has read some symbols.
7541@xref{Files, ,Commands to specify files}, for a discussion of how
7542@value{GDBN} reads symbols (in the description of @code{symbol-file}).
7543@end table
7544
6d2ebf8b 7545@node Altering
c906108c
SS
7546@chapter Altering Execution
7547
7548Once you think you have found an error in your program, you might want to
7549find out for certain whether correcting the apparent error would lead to
7550correct results in the rest of the run. You can find the answer by
7551experiment, using the @value{GDBN} features for altering execution of the
7552program.
7553
7554For example, you can store new values into variables or memory
7a292a7a
SS
7555locations, give your program a signal, restart it at a different
7556address, or even return prematurely from a function.
c906108c
SS
7557
7558@menu
7559* Assignment:: Assignment to variables
7560* Jumping:: Continuing at a different address
c906108c 7561* Signaling:: Giving your program a signal
c906108c
SS
7562* Returning:: Returning from a function
7563* Calling:: Calling your program's functions
7564* Patching:: Patching your program
7565@end menu
7566
6d2ebf8b 7567@node Assignment
c906108c
SS
7568@section Assignment to variables
7569
7570@cindex assignment
7571@cindex setting variables
7572To alter the value of a variable, evaluate an assignment expression.
7573@xref{Expressions, ,Expressions}. For example,
7574
7575@example
7576print x=4
7577@end example
7578
7579@noindent
7580stores the value 4 into the variable @code{x}, and then prints the
5d161b24 7581value of the assignment expression (which is 4).
c906108c
SS
7582@xref{Languages, ,Using @value{GDBN} with Different Languages}, for more
7583information on operators in supported languages.
c906108c
SS
7584
7585@kindex set variable
7586@cindex variables, setting
7587If you are not interested in seeing the value of the assignment, use the
7588@code{set} command instead of the @code{print} command. @code{set} is
7589really the same as @code{print} except that the expression's value is
7590not printed and is not put in the value history (@pxref{Value History,
7591,Value history}). The expression is evaluated only for its effects.
7592
c906108c
SS
7593If the beginning of the argument string of the @code{set} command
7594appears identical to a @code{set} subcommand, use the @code{set
7595variable} command instead of just @code{set}. This command is identical
7596to @code{set} except for its lack of subcommands. For example, if your
7597program has a variable @code{width}, you get an error if you try to set
7598a new value with just @samp{set width=13}, because @value{GDBN} has the
7599command @code{set width}:
7600
7601@example
7602(@value{GDBP}) whatis width
7603type = double
7604(@value{GDBP}) p width
7605$4 = 13
7606(@value{GDBP}) set width=47
7607Invalid syntax in expression.
7608@end example
7609
7610@noindent
7611The invalid expression, of course, is @samp{=47}. In
7612order to actually set the program's variable @code{width}, use
7613
7614@example
7615(@value{GDBP}) set var width=47
7616@end example
53a5351d 7617
c906108c
SS
7618Because the @code{set} command has many subcommands that can conflict
7619with the names of program variables, it is a good idea to use the
7620@code{set variable} command instead of just @code{set}. For example, if
7621your program has a variable @code{g}, you run into problems if you try
7622to set a new value with just @samp{set g=4}, because @value{GDBN} has
7623the command @code{set gnutarget}, abbreviated @code{set g}:
7624
7625@example
7626@group
7627(@value{GDBP}) whatis g
7628type = double
7629(@value{GDBP}) p g
7630$1 = 1
7631(@value{GDBP}) set g=4
2df3850c 7632(@value{GDBP}) p g
c906108c
SS
7633$2 = 1
7634(@value{GDBP}) r
7635The program being debugged has been started already.
7636Start it from the beginning? (y or n) y
7637Starting program: /home/smith/cc_progs/a.out
6d2ebf8b
SS
7638"/home/smith/cc_progs/a.out": can't open to read symbols:
7639 Invalid bfd target.
c906108c
SS
7640(@value{GDBP}) show g
7641The current BFD target is "=4".
7642@end group
7643@end example
7644
7645@noindent
7646The program variable @code{g} did not change, and you silently set the
7647@code{gnutarget} to an invalid value. In order to set the variable
7648@code{g}, use
7649
7650@example
7651(@value{GDBP}) set var g=4
7652@end example
c906108c
SS
7653
7654@value{GDBN} allows more implicit conversions in assignments than C; you can
7655freely store an integer value into a pointer variable or vice versa,
7656and you can convert any structure to any other structure that is the
7657same length or shorter.
7658@comment FIXME: how do structs align/pad in these conversions?
7659@comment /doc@cygnus.com 18dec1990
7660
7661To store values into arbitrary places in memory, use the @samp{@{@dots{}@}}
7662construct to generate a value of specified type at a specified address
7663(@pxref{Expressions, ,Expressions}). For example, @code{@{int@}0x83040} refers
7664to memory location @code{0x83040} as an integer (which implies a certain size
7665and representation in memory), and
7666
7667@example
7668set @{int@}0x83040 = 4
7669@end example
7670
7671@noindent
7672stores the value 4 into that memory location.
7673
6d2ebf8b 7674@node Jumping
c906108c
SS
7675@section Continuing at a different address
7676
7677Ordinarily, when you continue your program, you do so at the place where
7678it stopped, with the @code{continue} command. You can instead continue at
7679an address of your own choosing, with the following commands:
7680
7681@table @code
7682@kindex jump
7683@item jump @var{linespec}
7684Resume execution at line @var{linespec}. Execution stops again
7685immediately if there is a breakpoint there. @xref{List, ,Printing
7686source lines}, for a description of the different forms of
7687@var{linespec}. It is common practice to use the @code{tbreak} command
7688in conjunction with @code{jump}. @xref{Set Breaks, ,Setting
7689breakpoints}.
7690
7691The @code{jump} command does not change the current stack frame, or
7692the stack pointer, or the contents of any memory location or any
7693register other than the program counter. If line @var{linespec} is in
7694a different function from the one currently executing, the results may
7695be bizarre if the two functions expect different patterns of arguments or
7696of local variables. For this reason, the @code{jump} command requests
7697confirmation if the specified line is not in the function currently
7698executing. However, even bizarre results are predictable if you are
7699well acquainted with the machine-language code of your program.
7700
7701@item jump *@var{address}
7702Resume execution at the instruction at address @var{address}.
7703@end table
7704
c906108c 7705@c Doesn't work on HP-UX; have to set $pcoqh and $pcoqt.
53a5351d
JM
7706On many systems, you can get much the same effect as the @code{jump}
7707command by storing a new value into the register @code{$pc}. The
7708difference is that this does not start your program running; it only
7709changes the address of where it @emph{will} run when you continue. For
7710example,
c906108c
SS
7711
7712@example
7713set $pc = 0x485
7714@end example
7715
7716@noindent
7717makes the next @code{continue} command or stepping command execute at
7718address @code{0x485}, rather than at the address where your program stopped.
7719@xref{Continuing and Stepping, ,Continuing and stepping}.
c906108c
SS
7720
7721The most common occasion to use the @code{jump} command is to back
7722up---perhaps with more breakpoints set---over a portion of a program
7723that has already executed, in order to examine its execution in more
7724detail.
7725
c906108c 7726@c @group
6d2ebf8b 7727@node Signaling
c906108c
SS
7728@section Giving your program a signal
7729
7730@table @code
7731@kindex signal
7732@item signal @var{signal}
7733Resume execution where your program stopped, but immediately give it the
7734signal @var{signal}. @var{signal} can be the name or the number of a
7735signal. For example, on many systems @code{signal 2} and @code{signal
7736SIGINT} are both ways of sending an interrupt signal.
7737
7738Alternatively, if @var{signal} is zero, continue execution without
7739giving a signal. This is useful when your program stopped on account of
7740a signal and would ordinary see the signal when resumed with the
7741@code{continue} command; @samp{signal 0} causes it to resume without a
7742signal.
7743
7744@code{signal} does not repeat when you press @key{RET} a second time
7745after executing the command.
7746@end table
7747@c @end group
7748
7749Invoking the @code{signal} command is not the same as invoking the
7750@code{kill} utility from the shell. Sending a signal with @code{kill}
7751causes @value{GDBN} to decide what to do with the signal depending on
7752the signal handling tables (@pxref{Signals}). The @code{signal} command
7753passes the signal directly to your program.
7754
c906108c 7755
6d2ebf8b 7756@node Returning
c906108c
SS
7757@section Returning from a function
7758
7759@table @code
7760@cindex returning from a function
7761@kindex return
7762@item return
7763@itemx return @var{expression}
7764You can cancel execution of a function call with the @code{return}
7765command. If you give an
7766@var{expression} argument, its value is used as the function's return
7767value.
7768@end table
7769
7770When you use @code{return}, @value{GDBN} discards the selected stack frame
7771(and all frames within it). You can think of this as making the
7772discarded frame return prematurely. If you wish to specify a value to
7773be returned, give that value as the argument to @code{return}.
7774
7775This pops the selected stack frame (@pxref{Selection, ,Selecting a
7776frame}), and any other frames inside of it, leaving its caller as the
7777innermost remaining frame. That frame becomes selected. The
7778specified value is stored in the registers used for returning values
7779of functions.
7780
7781The @code{return} command does not resume execution; it leaves the
7782program stopped in the state that would exist if the function had just
7783returned. In contrast, the @code{finish} command (@pxref{Continuing
7784and Stepping, ,Continuing and stepping}) resumes execution until the
7785selected stack frame returns naturally.
7786
6d2ebf8b 7787@node Calling
c906108c
SS
7788@section Calling program functions
7789
7790@cindex calling functions
7791@kindex call
7792@table @code
7793@item call @var{expr}
7794Evaluate the expression @var{expr} without displaying @code{void}
7795returned values.
7796@end table
7797
7798You can use this variant of the @code{print} command if you want to
7799execute a function from your program, but without cluttering the output
5d161b24
DB
7800with @code{void} returned values. If the result is not void, it
7801is printed and saved in the value history.
c906108c 7802
c906108c
SS
7803For the A29K, a user-controlled variable @code{call_scratch_address},
7804specifies the location of a scratch area to be used when @value{GDBN}
7805calls a function in the target. This is necessary because the usual
7806method of putting the scratch area on the stack does not work in systems
7807that have separate instruction and data spaces.
c906108c 7808
6d2ebf8b 7809@node Patching
c906108c 7810@section Patching programs
7a292a7a 7811
c906108c
SS
7812@cindex patching binaries
7813@cindex writing into executables
c906108c 7814@cindex writing into corefiles
c906108c 7815
7a292a7a
SS
7816By default, @value{GDBN} opens the file containing your program's
7817executable code (or the corefile) read-only. This prevents accidental
7818alterations to machine code; but it also prevents you from intentionally
7819patching your program's binary.
c906108c
SS
7820
7821If you'd like to be able to patch the binary, you can specify that
7822explicitly with the @code{set write} command. For example, you might
7823want to turn on internal debugging flags, or even to make emergency
7824repairs.
7825
7826@table @code
7827@kindex set write
7828@item set write on
7829@itemx set write off
7a292a7a
SS
7830If you specify @samp{set write on}, @value{GDBN} opens executable and
7831core files for both reading and writing; if you specify @samp{set write
c906108c
SS
7832off} (the default), @value{GDBN} opens them read-only.
7833
7834If you have already loaded a file, you must load it again (using the
7a292a7a
SS
7835@code{exec-file} or @code{core-file} command) after changing @code{set
7836write}, for your new setting to take effect.
c906108c
SS
7837
7838@item show write
7839@kindex show write
7a292a7a
SS
7840Display whether executable files and core files are opened for writing
7841as well as reading.
c906108c
SS
7842@end table
7843
6d2ebf8b 7844@node GDB Files
c906108c
SS
7845@chapter @value{GDBN} Files
7846
7a292a7a
SS
7847@value{GDBN} needs to know the file name of the program to be debugged,
7848both in order to read its symbol table and in order to start your
7849program. To debug a core dump of a previous run, you must also tell
7850@value{GDBN} the name of the core dump file.
c906108c
SS
7851
7852@menu
7853* Files:: Commands to specify files
7854* Symbol Errors:: Errors reading symbol files
7855@end menu
7856
6d2ebf8b 7857@node Files
c906108c 7858@section Commands to specify files
c906108c 7859
7a292a7a 7860@cindex symbol table
c906108c 7861@cindex core dump file
7a292a7a
SS
7862
7863You may want to specify executable and core dump file names. The usual
7864way to do this is at start-up time, using the arguments to
7865@value{GDBN}'s start-up commands (@pxref{Invocation, , Getting In and
7866Out of @value{GDBN}}).
c906108c
SS
7867
7868Occasionally it is necessary to change to a different file during a
7869@value{GDBN} session. Or you may run @value{GDBN} and forget to specify
7870a file you want to use. In these situations the @value{GDBN} commands
7871to specify new files are useful.
7872
7873@table @code
7874@cindex executable file
7875@kindex file
7876@item file @var{filename}
7877Use @var{filename} as the program to be debugged. It is read for its
7878symbols and for the contents of pure memory. It is also the program
7879executed when you use the @code{run} command. If you do not specify a
5d161b24
DB
7880directory and the file is not found in the @value{GDBN} working directory,
7881@value{GDBN} uses the environment variable @code{PATH} as a list of
7882directories to search, just as the shell does when looking for a program
7883to run. You can change the value of this variable, for both @value{GDBN}
c906108c
SS
7884and your program, using the @code{path} command.
7885
6d2ebf8b 7886On systems with memory-mapped files, an auxiliary file named
c906108c
SS
7887@file{@var{filename}.syms} may hold symbol table information for
7888@var{filename}. If so, @value{GDBN} maps in the symbol table from
7889@file{@var{filename}.syms}, starting up more quickly. See the
7890descriptions of the file options @samp{-mapped} and @samp{-readnow}
7891(available on the command line, and with the commands @code{file},
5d161b24 7892@code{symbol-file}, or @code{add-symbol-file}, described below),
c906108c 7893for more information.
c906108c
SS
7894
7895@item file
7896@code{file} with no argument makes @value{GDBN} discard any information it
7897has on both executable file and the symbol table.
7898
7899@kindex exec-file
7900@item exec-file @r{[} @var{filename} @r{]}
7901Specify that the program to be run (but not the symbol table) is found
7902in @var{filename}. @value{GDBN} searches the environment variable @code{PATH}
7903if necessary to locate your program. Omitting @var{filename} means to
7904discard information on the executable file.
7905
7906@kindex symbol-file
7907@item symbol-file @r{[} @var{filename} @r{]}
7908Read symbol table information from file @var{filename}. @code{PATH} is
7909searched when necessary. Use the @code{file} command to get both symbol
7910table and program to run from the same file.
7911
7912@code{symbol-file} with no argument clears out @value{GDBN} information on your
7913program's symbol table.
7914
5d161b24 7915The @code{symbol-file} command causes @value{GDBN} to forget the contents
c906108c
SS
7916of its convenience variables, the value history, and all breakpoints and
7917auto-display expressions. This is because they may contain pointers to
7918the internal data recording symbols and data types, which are part of
7919the old symbol table data being discarded inside @value{GDBN}.
7920
7921@code{symbol-file} does not repeat if you press @key{RET} again after
7922executing it once.
7923
7924When @value{GDBN} is configured for a particular environment, it
7925understands debugging information in whatever format is the standard
7926generated for that environment; you may use either a @sc{gnu} compiler, or
7927other compilers that adhere to the local conventions.
c906108c
SS
7928Best results are usually obtained from @sc{gnu} compilers; for example,
7929using @code{@value{GCC}} you can generate debugging information for
7930optimized code.
c906108c
SS
7931
7932For most kinds of object files, with the exception of old SVR3 systems
7933using COFF, the @code{symbol-file} command does not normally read the
7934symbol table in full right away. Instead, it scans the symbol table
7935quickly to find which source files and which symbols are present. The
7936details are read later, one source file at a time, as they are needed.
7937
7938The purpose of this two-stage reading strategy is to make @value{GDBN}
7939start up faster. For the most part, it is invisible except for
7940occasional pauses while the symbol table details for a particular source
7941file are being read. (The @code{set verbose} command can turn these
7942pauses into messages if desired. @xref{Messages/Warnings, ,Optional
7943warnings and messages}.)
7944
c906108c
SS
7945We have not implemented the two-stage strategy for COFF yet. When the
7946symbol table is stored in COFF format, @code{symbol-file} reads the
7947symbol table data in full right away. Note that ``stabs-in-COFF''
7948still does the two-stage strategy, since the debug info is actually
7949in stabs format.
7950
7951@kindex readnow
7952@cindex reading symbols immediately
7953@cindex symbols, reading immediately
7954@kindex mapped
7955@cindex memory-mapped symbol file
7956@cindex saving symbol table
7957@item symbol-file @var{filename} @r{[} -readnow @r{]} @r{[} -mapped @r{]}
7958@itemx file @var{filename} @r{[} -readnow @r{]} @r{[} -mapped @r{]}
7959You can override the @value{GDBN} two-stage strategy for reading symbol
7960tables by using the @samp{-readnow} option with any of the commands that
7961load symbol table information, if you want to be sure @value{GDBN} has the
5d161b24 7962entire symbol table available.
c906108c 7963
c906108c
SS
7964If memory-mapped files are available on your system through the
7965@code{mmap} system call, you can use another option, @samp{-mapped}, to
7966cause @value{GDBN} to write the symbols for your program into a reusable
7967file. Future @value{GDBN} debugging sessions map in symbol information
7968from this auxiliary symbol file (if the program has not changed), rather
7969than spending time reading the symbol table from the executable
7970program. Using the @samp{-mapped} option has the same effect as
7971starting @value{GDBN} with the @samp{-mapped} command-line option.
7972
7973You can use both options together, to make sure the auxiliary symbol
7974file has all the symbol information for your program.
7975
7976The auxiliary symbol file for a program called @var{myprog} is called
7977@samp{@var{myprog}.syms}. Once this file exists (so long as it is newer
7978than the corresponding executable), @value{GDBN} always attempts to use
7979it when you debug @var{myprog}; no special options or commands are
7980needed.
7981
7982The @file{.syms} file is specific to the host machine where you run
7983@value{GDBN}. It holds an exact image of the internal @value{GDBN}
7984symbol table. It cannot be shared across multiple host platforms.
c906108c
SS
7985
7986@c FIXME: for now no mention of directories, since this seems to be in
7987@c flux. 13mar1992 status is that in theory GDB would look either in
7988@c current dir or in same dir as myprog; but issues like competing
7989@c GDB's, or clutter in system dirs, mean that in practice right now
7990@c only current dir is used. FFish says maybe a special GDB hierarchy
7991@c (eg rooted in val of env var GDBSYMS) could exist for mappable symbol
7992@c files.
7993
7994@kindex core
7995@kindex core-file
7996@item core-file @r{[} @var{filename} @r{]}
7997Specify the whereabouts of a core dump file to be used as the ``contents
7998of memory''. Traditionally, core files contain only some parts of the
7999address space of the process that generated them; @value{GDBN} can access the
8000executable file itself for other parts.
8001
8002@code{core-file} with no argument specifies that no core file is
8003to be used.
8004
8005Note that the core file is ignored when your program is actually running
7a292a7a
SS
8006under @value{GDBN}. So, if you have been running your program and you
8007wish to debug a core file instead, you must kill the subprocess in which
8008the program is running. To do this, use the @code{kill} command
c906108c 8009(@pxref{Kill Process, ,Killing the child process}).
c906108c 8010
c906108c
SS
8011@kindex add-symbol-file
8012@cindex dynamic linking
8013@item add-symbol-file @var{filename} @var{address}
8014@itemx add-symbol-file @var{filename} @var{address} @r{[} -readnow @r{]} @r{[} -mapped @r{]}
2acceee2
JM
8015@itemx add-symbol-file @var{filename} @var{address} @var{data_address} @var{bss_address}
8016@itemx add-symbol-file @var{filename} @r{-T}@var{section} @var{address}
96a2c332
SS
8017The @code{add-symbol-file} command reads additional symbol table
8018information from the file @var{filename}. You would use this command
8019when @var{filename} has been dynamically loaded (by some other means)
8020into the program that is running. @var{address} should be the memory
8021address at which the file has been loaded; @value{GDBN} cannot figure
8022this out for itself. You can specify up to three addresses, in which
8023case they are taken to be the addresses of the text, data, and bss
8024segments respectively. For complicated cases, you can specify an
8025arbitrary number of @samp{@r{-T}@var{section} @var{address}} pairs, to
8026give an explicit section name and base address for that section. You
8027can specify any @var{address} as an expression.
c906108c
SS
8028
8029The symbol table of the file @var{filename} is added to the symbol table
8030originally read with the @code{symbol-file} command. You can use the
96a2c332
SS
8031@code{add-symbol-file} command any number of times; the new symbol data
8032thus read keeps adding to the old. To discard all old symbol data
8033instead, use the @code{symbol-file} command without any arguments.
c906108c
SS
8034
8035@code{add-symbol-file} does not repeat if you press @key{RET} after using it.
8036
8037You can use the @samp{-mapped} and @samp{-readnow} options just as with
8038the @code{symbol-file} command, to change how @value{GDBN} manages the symbol
8039table information for @var{filename}.
8040
8041@kindex add-shared-symbol-file
8042@item add-shared-symbol-file
8043The @code{add-shared-symbol-file} command can be used only under Harris' CXUX
5d161b24
DB
8044operating system for the Motorola 88k. @value{GDBN} automatically looks for
8045shared libraries, however if @value{GDBN} does not find yours, you can run
c906108c 8046@code{add-shared-symbol-file}. It takes no arguments.
c906108c 8047
c906108c
SS
8048@kindex section
8049@item section
5d161b24
DB
8050The @code{section} command changes the base address of section SECTION of
8051the exec file to ADDR. This can be used if the exec file does not contain
8052section addresses, (such as in the a.out format), or when the addresses
8053specified in the file itself are wrong. Each section must be changed
d4f3574e
SS
8054separately. The @code{info files} command, described below, lists all
8055the sections and their addresses.
c906108c
SS
8056
8057@kindex info files
8058@kindex info target
8059@item info files
8060@itemx info target
7a292a7a
SS
8061@code{info files} and @code{info target} are synonymous; both print the
8062current target (@pxref{Targets, ,Specifying a Debugging Target}),
8063including the names of the executable and core dump files currently in
8064use by @value{GDBN}, and the files from which symbols were loaded. The
8065command @code{help target} lists all possible targets rather than
8066current ones.
8067
c906108c
SS
8068@end table
8069
8070All file-specifying commands allow both absolute and relative file names
8071as arguments. @value{GDBN} always converts the file name to an absolute file
8072name and remembers it that way.
8073
c906108c 8074@cindex shared libraries
c906108c
SS
8075@value{GDBN} supports HP-UX, SunOS, SVr4, Irix 5, and IBM RS/6000 shared
8076libraries.
53a5351d 8077
c906108c
SS
8078@value{GDBN} automatically loads symbol definitions from shared libraries
8079when you use the @code{run} command, or when you examine a core file.
8080(Before you issue the @code{run} command, @value{GDBN} does not understand
8081references to a function in a shared library, however---unless you are
8082debugging a core file).
53a5351d
JM
8083
8084On HP-UX, if the program loads a library explicitly, @value{GDBN}
8085automatically loads the symbols at the time of the @code{shl_load} call.
8086
c906108c
SS
8087@c FIXME: some @value{GDBN} release may permit some refs to undef
8088@c FIXME...symbols---eg in a break cmd---assuming they are from a shared
8089@c FIXME...lib; check this from time to time when updating manual
8090
8091@table @code
8092@kindex info sharedlibrary
8093@kindex info share
8094@item info share
8095@itemx info sharedlibrary
8096Print the names of the shared libraries which are currently loaded.
8097
8098@kindex sharedlibrary
8099@kindex share
8100@item sharedlibrary @var{regex}
8101@itemx share @var{regex}
c906108c
SS
8102Load shared object library symbols for files matching a
8103Unix regular expression.
8104As with files loaded automatically, it only loads shared libraries
8105required by your program for a core file or after typing @code{run}. If
8106@var{regex} is omitted all shared libraries required by your program are
8107loaded.
8108@end table
8109
53a5351d
JM
8110On HP-UX systems, @value{GDBN} detects the loading of a shared library
8111and automatically reads in symbols from the newly loaded library, up to
8112a threshold that is initially set but that you can modify if you wish.
c906108c
SS
8113
8114Beyond that threshold, symbols from shared libraries must be explicitly
d4f3574e
SS
8115loaded. To load these symbols, use the command @code{sharedlibrary
8116@var{filename}}. The base address of the shared library is determined
c906108c
SS
8117automatically by @value{GDBN} and need not be specified.
8118
8119To display or set the threshold, use the commands:
8120
8121@table @code
8122@kindex set auto-solib-add
8123@item set auto-solib-add @var{threshold}
8124Set the autoloading size threshold, in megabytes. If @var{threshold} is
8125nonzero, symbols from all shared object libraries will be loaded
8126automatically when the inferior begins execution or when the dynamic
8127linker informs @value{GDBN} that a new library has been loaded, until
8128the symbol table of the program and libraries exceeds this threshold.
8129Otherwise, symbols must be loaded manually, using the
8130@code{sharedlibrary} command. The default threshold is 100 megabytes.
8131
8132@kindex show auto-solib-add
8133@item show auto-solib-add
8134Display the current autoloading size threshold, in megabytes.
8135@end table
c906108c 8136
6d2ebf8b 8137@node Symbol Errors
c906108c
SS
8138@section Errors reading symbol files
8139
8140While reading a symbol file, @value{GDBN} occasionally encounters problems,
8141such as symbol types it does not recognize, or known bugs in compiler
8142output. By default, @value{GDBN} does not notify you of such problems, since
8143they are relatively common and primarily of interest to people
8144debugging compilers. If you are interested in seeing information
8145about ill-constructed symbol tables, you can either ask @value{GDBN} to print
8146only one message about each such type of problem, no matter how many
8147times the problem occurs; or you can ask @value{GDBN} to print more messages,
8148to see how many times the problems occur, with the @code{set
8149complaints} command (@pxref{Messages/Warnings, ,Optional warnings and
8150messages}).
8151
8152The messages currently printed, and their meanings, include:
8153
8154@table @code
8155@item inner block not inside outer block in @var{symbol}
8156
8157The symbol information shows where symbol scopes begin and end
8158(such as at the start of a function or a block of statements). This
8159error indicates that an inner scope block is not fully contained
8160in its outer scope blocks.
8161
8162@value{GDBN} circumvents the problem by treating the inner block as if it had
8163the same scope as the outer block. In the error message, @var{symbol}
8164may be shown as ``@code{(don't know)}'' if the outer block is not a
8165function.
8166
8167@item block at @var{address} out of order
8168
8169The symbol information for symbol scope blocks should occur in
8170order of increasing addresses. This error indicates that it does not
8171do so.
8172
8173@value{GDBN} does not circumvent this problem, and has trouble
8174locating symbols in the source file whose symbols it is reading. (You
8175can often determine what source file is affected by specifying
8176@code{set verbose on}. @xref{Messages/Warnings, ,Optional warnings and
8177messages}.)
8178
8179@item bad block start address patched
8180
8181The symbol information for a symbol scope block has a start address
8182smaller than the address of the preceding source line. This is known
8183to occur in the SunOS 4.1.1 (and earlier) C compiler.
8184
8185@value{GDBN} circumvents the problem by treating the symbol scope block as
8186starting on the previous source line.
8187
8188@item bad string table offset in symbol @var{n}
8189
8190@cindex foo
8191Symbol number @var{n} contains a pointer into the string table which is
8192larger than the size of the string table.
8193
8194@value{GDBN} circumvents the problem by considering the symbol to have the
8195name @code{foo}, which may cause other problems if many symbols end up
8196with this name.
8197
8198@item unknown symbol type @code{0x@var{nn}}
8199
7a292a7a
SS
8200The symbol information contains new data types that @value{GDBN} does
8201not yet know how to read. @code{0x@var{nn}} is the symbol type of the
d4f3574e 8202uncomprehended information, in hexadecimal.
c906108c 8203
7a292a7a
SS
8204@value{GDBN} circumvents the error by ignoring this symbol information.
8205This usually allows you to debug your program, though certain symbols
c906108c 8206are not accessible. If you encounter such a problem and feel like
7a292a7a
SS
8207debugging it, you can debug @code{@value{GDBP}} with itself, breakpoint
8208on @code{complain}, then go up to the function @code{read_dbx_symtab}
8209and examine @code{*bufp} to see the symbol.
c906108c
SS
8210
8211@item stub type has NULL name
c906108c 8212
7a292a7a 8213@value{GDBN} could not find the full definition for a struct or class.
c906108c 8214
7a292a7a 8215@item const/volatile indicator missing (ok if using g++ v1.x), got@dots{}
c906108c 8216The symbol information for a C++ member function is missing some
7a292a7a
SS
8217information that recent versions of the compiler should have output for
8218it.
c906108c
SS
8219
8220@item info mismatch between compiler and debugger
8221
8222@value{GDBN} could not parse a type specification output by the compiler.
7a292a7a 8223
c906108c
SS
8224@end table
8225
6d2ebf8b 8226@node Targets
c906108c 8227@chapter Specifying a Debugging Target
7a292a7a 8228
c906108c
SS
8229@cindex debugging target
8230@kindex target
8231
8232A @dfn{target} is the execution environment occupied by your program.
53a5351d
JM
8233
8234Often, @value{GDBN} runs in the same host environment as your program;
8235in that case, the debugging target is specified as a side effect when
8236you use the @code{file} or @code{core} commands. When you need more
c906108c
SS
8237flexibility---for example, running @value{GDBN} on a physically separate
8238host, or controlling a standalone system over a serial port or a
53a5351d
JM
8239realtime system over a TCP/IP connection---you can use the @code{target}
8240command to specify one of the target types configured for @value{GDBN}
8241(@pxref{Target Commands, ,Commands for managing targets}).
c906108c
SS
8242
8243@menu
8244* Active Targets:: Active targets
8245* Target Commands:: Commands for managing targets
c906108c
SS
8246* Byte Order:: Choosing target byte order
8247* Remote:: Remote debugging
96baa820 8248* KOD:: Kernel Object Display
c906108c
SS
8249
8250@end menu
8251
6d2ebf8b 8252@node Active Targets
c906108c 8253@section Active targets
7a292a7a 8254
c906108c
SS
8255@cindex stacking targets
8256@cindex active targets
8257@cindex multiple targets
8258
c906108c 8259There are three classes of targets: processes, core files, and
7a292a7a
SS
8260executable files. @value{GDBN} can work concurrently on up to three
8261active targets, one in each class. This allows you to (for example)
8262start a process and inspect its activity without abandoning your work on
8263a core file.
c906108c
SS
8264
8265For example, if you execute @samp{gdb a.out}, then the executable file
8266@code{a.out} is the only active target. If you designate a core file as
8267well---presumably from a prior run that crashed and coredumped---then
8268@value{GDBN} has two active targets and uses them in tandem, looking
8269first in the corefile target, then in the executable file, to satisfy
8270requests for memory addresses. (Typically, these two classes of target
8271are complementary, since core files contain only a program's
8272read-write memory---variables and so on---plus machine status, while
8273executable files contain only the program text and initialized data.)
c906108c
SS
8274
8275When you type @code{run}, your executable file becomes an active process
7a292a7a
SS
8276target as well. When a process target is active, all @value{GDBN}
8277commands requesting memory addresses refer to that target; addresses in
8278an active core file or executable file target are obscured while the
8279process target is active.
c906108c 8280
7a292a7a
SS
8281Use the @code{core-file} and @code{exec-file} commands to select a new
8282core file or executable target (@pxref{Files, ,Commands to specify
c906108c 8283files}). To specify as a target a process that is already running, use
7a292a7a
SS
8284the @code{attach} command (@pxref{Attach, ,Debugging an already-running
8285process}).
c906108c 8286
6d2ebf8b 8287@node Target Commands
c906108c
SS
8288@section Commands for managing targets
8289
8290@table @code
8291@item target @var{type} @var{parameters}
7a292a7a
SS
8292Connects the @value{GDBN} host environment to a target machine or
8293process. A target is typically a protocol for talking to debugging
8294facilities. You use the argument @var{type} to specify the type or
8295protocol of the target machine.
c906108c
SS
8296
8297Further @var{parameters} are interpreted by the target protocol, but
8298typically include things like device names or host names to connect
8299with, process numbers, and baud rates.
c906108c
SS
8300
8301The @code{target} command does not repeat if you press @key{RET} again
8302after executing the command.
8303
8304@kindex help target
8305@item help target
8306Displays the names of all targets available. To display targets
8307currently selected, use either @code{info target} or @code{info files}
8308(@pxref{Files, ,Commands to specify files}).
8309
8310@item help target @var{name}
8311Describe a particular target, including any parameters necessary to
8312select it.
8313
8314@kindex set gnutarget
8315@item set gnutarget @var{args}
5d161b24 8316@value{GDBN} uses its own library BFD to read your files. @value{GDBN}
c906108c 8317knows whether it is reading an @dfn{executable},
5d161b24
DB
8318a @dfn{core}, or a @dfn{.o} file; however, you can specify the file format
8319with the @code{set gnutarget} command. Unlike most @code{target} commands,
c906108c
SS
8320with @code{gnutarget} the @code{target} refers to a program, not a machine.
8321
d4f3574e 8322@quotation
c906108c
SS
8323@emph{Warning:} To specify a file format with @code{set gnutarget},
8324you must know the actual BFD name.
d4f3574e 8325@end quotation
c906108c 8326
d4f3574e
SS
8327@noindent
8328@xref{Files, , Commands to specify files}.
c906108c 8329
5d161b24 8330@kindex show gnutarget
c906108c
SS
8331@item show gnutarget
8332Use the @code{show gnutarget} command to display what file format
8333@code{gnutarget} is set to read. If you have not set @code{gnutarget},
8334@value{GDBN} will determine the file format for each file automatically,
8335and @code{show gnutarget} displays @samp{The current BDF target is "auto"}.
8336@end table
8337
c906108c
SS
8338Here are some common targets (available, or not, depending on the GDB
8339configuration):
c906108c
SS
8340
8341@table @code
8342@kindex target exec
8343@item target exec @var{program}
8344An executable file. @samp{target exec @var{program}} is the same as
8345@samp{exec-file @var{program}}.
8346
c906108c
SS
8347@kindex target core
8348@item target core @var{filename}
8349A core dump file. @samp{target core @var{filename}} is the same as
8350@samp{core-file @var{filename}}.
c906108c
SS
8351
8352@kindex target remote
8353@item target remote @var{dev}
8354Remote serial target in GDB-specific protocol. The argument @var{dev}
8355specifies what serial device to use for the connection (e.g.
8356@file{/dev/ttya}). @xref{Remote, ,Remote debugging}. @code{target remote}
d4f3574e 8357supports the @code{load} command. This is only useful if you have
c906108c
SS
8358some other way of getting the stub to the target system, and you can put
8359it somewhere in memory where it won't get clobbered by the download.
8360
c906108c
SS
8361@kindex target sim
8362@item target sim
2df3850c 8363Builtin CPU simulator. @value{GDBN} includes simulators for most architectures.
104c1213
JM
8364In general,
8365@example
8366 target sim
8367 load
8368 run
8369@end example
d4f3574e 8370@noindent
104c1213 8371works; however, you cannot assume that a specific memory map, device
d4f3574e 8372drivers, or even basic I/O is available, although some simulators do
104c1213
JM
8373provide these. For info about any processor-specific simulator details,
8374see the appropriate section in @ref{Embedded Processors, ,Embedded
8375Processors}.
8376
c906108c
SS
8377@end table
8378
104c1213 8379Some configurations may include these targets as well:
c906108c
SS
8380
8381@table @code
8382
c906108c
SS
8383@kindex target nrom
8384@item target nrom @var{dev}
8385NetROM ROM emulator. This target only supports downloading.
8386
c906108c
SS
8387@end table
8388
5d161b24 8389Different targets are available on different configurations of @value{GDBN};
c906108c 8390your configuration may have more or fewer targets.
c906108c
SS
8391
8392Many remote targets require you to download the executable's code
8393once you've successfully established a connection.
8394
8395@table @code
8396
8397@kindex load @var{filename}
8398@item load @var{filename}
c906108c
SS
8399Depending on what remote debugging facilities are configured into
8400@value{GDBN}, the @code{load} command may be available. Where it exists, it
8401is meant to make @var{filename} (an executable) available for debugging
8402on the remote system---by downloading, or dynamic linking, for example.
8403@code{load} also records the @var{filename} symbol table in @value{GDBN}, like
8404the @code{add-symbol-file} command.
8405
8406If your @value{GDBN} does not have a @code{load} command, attempting to
8407execute it gets the error message ``@code{You can't do that when your
8408target is @dots{}}''
c906108c
SS
8409
8410The file is loaded at whatever address is specified in the executable.
8411For some object file formats, you can specify the load address when you
8412link the program; for other formats, like a.out, the object file format
8413specifies a fixed address.
8414@c FIXME! This would be a good place for an xref to the GNU linker doc.
8415
c906108c
SS
8416@code{load} does not repeat if you press @key{RET} again after using it.
8417@end table
8418
6d2ebf8b 8419@node Byte Order
c906108c 8420@section Choosing target byte order
7a292a7a 8421
c906108c
SS
8422@cindex choosing target byte order
8423@cindex target byte order
8424@kindex set endian big
8425@kindex set endian little
8426@kindex set endian auto
8427@kindex show endian
8428
8429Some types of processors, such as the MIPS, PowerPC, and Hitachi SH,
8430offer the ability to run either big-endian or little-endian byte
8431orders. Usually the executable or symbol will include a bit to
8432designate the endian-ness, and you will not need to worry about
8433which to use. However, you may still find it useful to adjust
d4f3574e 8434@value{GDBN}'s idea of processor endian-ness manually.
c906108c
SS
8435
8436@table @code
8437@kindex set endian big
8438@item set endian big
8439Instruct @value{GDBN} to assume the target is big-endian.
8440
8441@kindex set endian little
8442@item set endian little
8443Instruct @value{GDBN} to assume the target is little-endian.
8444
8445@kindex set endian auto
8446@item set endian auto
8447Instruct @value{GDBN} to use the byte order associated with the
8448executable.
8449
8450@item show endian
8451Display @value{GDBN}'s current idea of the target byte order.
8452
8453@end table
8454
8455Note that these commands merely adjust interpretation of symbolic
8456data on the host, and that they have absolutely no effect on the
8457target system.
8458
6d2ebf8b 8459@node Remote
c906108c
SS
8460@section Remote debugging
8461@cindex remote debugging
8462
8463If you are trying to debug a program running on a machine that cannot run
5d161b24
DB
8464@value{GDBN} in the usual way, it is often useful to use remote debugging.
8465For example, you might use remote debugging on an operating system kernel,
c906108c
SS
8466or on a small system which does not have a general purpose operating system
8467powerful enough to run a full-featured debugger.
8468
8469Some configurations of @value{GDBN} have special serial or TCP/IP interfaces
8470to make this work with particular debugging targets. In addition,
5d161b24 8471@value{GDBN} comes with a generic serial protocol (specific to @value{GDBN},
c906108c
SS
8472but not specific to any particular target system) which you can use if you
8473write the remote stubs---the code that runs on the remote system to
8474communicate with @value{GDBN}.
8475
8476Other remote targets may be available in your
8477configuration of @value{GDBN}; use @code{help target} to list them.
c906108c 8478
c906108c 8479@menu
c906108c 8480* Remote Serial:: @value{GDBN} remote serial protocol
c906108c
SS
8481@end menu
8482
6d2ebf8b 8483@node Remote Serial
104c1213 8484@subsection The @value{GDBN} remote serial protocol
7a292a7a 8485
104c1213
JM
8486@cindex remote serial debugging, overview
8487To debug a program running on another machine (the debugging
8488@dfn{target} machine), you must first arrange for all the usual
8489prerequisites for the program to run by itself. For example, for a C
8490program, you need:
c906108c 8491
104c1213
JM
8492@enumerate
8493@item
8494A startup routine to set up the C runtime environment; these usually
8495have a name like @file{crt0}. The startup routine may be supplied by
8496your hardware supplier, or you may have to write your own.
96baa820 8497
5d161b24 8498@item
d4f3574e 8499A C subroutine library to support your program's
104c1213 8500subroutine calls, notably managing input and output.
96baa820 8501
104c1213
JM
8502@item
8503A way of getting your program to the other machine---for example, a
8504download program. These are often supplied by the hardware
8505manufacturer, but you may have to write your own from hardware
8506documentation.
8507@end enumerate
96baa820 8508
104c1213
JM
8509The next step is to arrange for your program to use a serial port to
8510communicate with the machine where @value{GDBN} is running (the @dfn{host}
8511machine). In general terms, the scheme looks like this:
96baa820 8512
104c1213
JM
8513@table @emph
8514@item On the host,
8515@value{GDBN} already understands how to use this protocol; when everything
8516else is set up, you can simply use the @samp{target remote} command
8517(@pxref{Targets,,Specifying a Debugging Target}).
8518
8519@item On the target,
8520you must link with your program a few special-purpose subroutines that
8521implement the @value{GDBN} remote serial protocol. The file containing these
8522subroutines is called a @dfn{debugging stub}.
8523
8524On certain remote targets, you can use an auxiliary program
8525@code{gdbserver} instead of linking a stub into your program.
8526@xref{Server,,Using the @code{gdbserver} program}, for details.
8527@end table
96baa820 8528
104c1213
JM
8529The debugging stub is specific to the architecture of the remote
8530machine; for example, use @file{sparc-stub.c} to debug programs on
8531@sc{sparc} boards.
96baa820 8532
104c1213
JM
8533@cindex remote serial stub list
8534These working remote stubs are distributed with @value{GDBN}:
96baa820 8535
104c1213
JM
8536@table @code
8537
8538@item i386-stub.c
8539@kindex i386-stub.c
8540@cindex Intel
8541@cindex i386
8542For Intel 386 and compatible architectures.
8543
8544@item m68k-stub.c
8545@kindex m68k-stub.c
8546@cindex Motorola 680x0
8547@cindex m680x0
8548For Motorola 680x0 architectures.
8549
8550@item sh-stub.c
8551@kindex sh-stub.c
8552@cindex Hitachi
8553@cindex SH
8554For Hitachi SH architectures.
8555
8556@item sparc-stub.c
8557@kindex sparc-stub.c
8558@cindex Sparc
8559For @sc{sparc} architectures.
8560
8561@item sparcl-stub.c
8562@kindex sparcl-stub.c
8563@cindex Fujitsu
8564@cindex SparcLite
8565For Fujitsu @sc{sparclite} architectures.
8566
8567@end table
8568
8569The @file{README} file in the @value{GDBN} distribution may list other
8570recently added stubs.
8571
8572@menu
8573* Stub Contents:: What the stub can do for you
8574* Bootstrapping:: What you must do for the stub
8575* Debug Session:: Putting it all together
8576* Protocol:: Definition of the communication protocol
8577* Server:: Using the `gdbserver' program
8578* NetWare:: Using the `gdbserve.nlm' program
8579@end menu
8580
6d2ebf8b 8581@node Stub Contents
104c1213
JM
8582@subsubsection What the stub can do for you
8583
8584@cindex remote serial stub
8585The debugging stub for your architecture supplies these three
8586subroutines:
8587
8588@table @code
8589@item set_debug_traps
8590@kindex set_debug_traps
8591@cindex remote serial stub, initialization
8592This routine arranges for @code{handle_exception} to run when your
8593program stops. You must call this subroutine explicitly near the
8594beginning of your program.
8595
8596@item handle_exception
8597@kindex handle_exception
8598@cindex remote serial stub, main routine
8599This is the central workhorse, but your program never calls it
8600explicitly---the setup code arranges for @code{handle_exception} to
8601run when a trap is triggered.
8602
8603@code{handle_exception} takes control when your program stops during
8604execution (for example, on a breakpoint), and mediates communications
8605with @value{GDBN} on the host machine. This is where the communications
8606protocol is implemented; @code{handle_exception} acts as the @value{GDBN}
d4f3574e 8607representative on the target machine. It begins by sending summary
104c1213
JM
8608information on the state of your program, then continues to execute,
8609retrieving and transmitting any information @value{GDBN} needs, until you
8610execute a @value{GDBN} command that makes your program resume; at that point,
8611@code{handle_exception} returns control to your own code on the target
5d161b24 8612machine.
104c1213
JM
8613
8614@item breakpoint
8615@cindex @code{breakpoint} subroutine, remote
8616Use this auxiliary subroutine to make your program contain a
8617breakpoint. Depending on the particular situation, this may be the only
8618way for @value{GDBN} to get control. For instance, if your target
8619machine has some sort of interrupt button, you won't need to call this;
8620pressing the interrupt button transfers control to
8621@code{handle_exception}---in effect, to @value{GDBN}. On some machines,
8622simply receiving characters on the serial port may also trigger a trap;
8623again, in that situation, you don't need to call @code{breakpoint} from
8624your own program---simply running @samp{target remote} from the host
5d161b24 8625@value{GDBN} session gets control.
104c1213
JM
8626
8627Call @code{breakpoint} if none of these is true, or if you simply want
8628to make certain your program stops at a predetermined point for the
8629start of your debugging session.
8630@end table
8631
6d2ebf8b 8632@node Bootstrapping
104c1213
JM
8633@subsubsection What you must do for the stub
8634
8635@cindex remote stub, support routines
8636The debugging stubs that come with @value{GDBN} are set up for a particular
8637chip architecture, but they have no information about the rest of your
8638debugging target machine.
8639
8640First of all you need to tell the stub how to communicate with the
8641serial port.
8642
8643@table @code
8644@item int getDebugChar()
8645@kindex getDebugChar
8646Write this subroutine to read a single character from the serial port.
8647It may be identical to @code{getchar} for your target system; a
8648different name is used to allow you to distinguish the two if you wish.
8649
8650@item void putDebugChar(int)
8651@kindex putDebugChar
8652Write this subroutine to write a single character to the serial port.
5d161b24 8653It may be identical to @code{putchar} for your target system; a
104c1213
JM
8654different name is used to allow you to distinguish the two if you wish.
8655@end table
8656
8657@cindex control C, and remote debugging
8658@cindex interrupting remote targets
8659If you want @value{GDBN} to be able to stop your program while it is
8660running, you need to use an interrupt-driven serial driver, and arrange
8661for it to stop when it receives a @code{^C} (@samp{\003}, the control-C
8662character). That is the character which @value{GDBN} uses to tell the
8663remote system to stop.
8664
8665Getting the debugging target to return the proper status to @value{GDBN}
8666probably requires changes to the standard stub; one quick and dirty way
8667is to just execute a breakpoint instruction (the ``dirty'' part is that
8668@value{GDBN} reports a @code{SIGTRAP} instead of a @code{SIGINT}).
8669
8670Other routines you need to supply are:
8671
8672@table @code
8673@item void exceptionHandler (int @var{exception_number}, void *@var{exception_address})
8674@kindex exceptionHandler
8675Write this function to install @var{exception_address} in the exception
8676handling tables. You need to do this because the stub does not have any
8677way of knowing what the exception handling tables on your target system
8678are like (for example, the processor's table might be in @sc{rom},
8679containing entries which point to a table in @sc{ram}).
8680@var{exception_number} is the exception number which should be changed;
8681its meaning is architecture-dependent (for example, different numbers
8682might represent divide by zero, misaligned access, etc). When this
8683exception occurs, control should be transferred directly to
8684@var{exception_address}, and the processor state (stack, registers,
8685and so on) should be just as it is when a processor exception occurs. So if
8686you want to use a jump instruction to reach @var{exception_address}, it
8687should be a simple jump, not a jump to subroutine.
8688
8689For the 386, @var{exception_address} should be installed as an interrupt
8690gate so that interrupts are masked while the handler runs. The gate
8691should be at privilege level 0 (the most privileged level). The
8692@sc{sparc} and 68k stubs are able to mask interrupts themselves without
8693help from @code{exceptionHandler}.
8694
8695@item void flush_i_cache()
8696@kindex flush_i_cache
d4f3574e 8697On @sc{sparc} and @sc{sparclite} only, write this subroutine to flush the
104c1213
JM
8698instruction cache, if any, on your target machine. If there is no
8699instruction cache, this subroutine may be a no-op.
8700
8701On target machines that have instruction caches, @value{GDBN} requires this
8702function to make certain that the state of your program is stable.
8703@end table
8704
8705@noindent
8706You must also make sure this library routine is available:
8707
8708@table @code
8709@item void *memset(void *, int, int)
8710@kindex memset
8711This is the standard library function @code{memset} that sets an area of
8712memory to a known value. If you have one of the free versions of
8713@code{libc.a}, @code{memset} can be found there; otherwise, you must
8714either obtain it from your hardware manufacturer, or write your own.
8715@end table
8716
8717If you do not use the GNU C compiler, you may need other standard
8718library subroutines as well; this varies from one stub to another,
8719but in general the stubs are likely to use any of the common library
d4f3574e 8720subroutines which @code{@value{GCC}} generates as inline code.
104c1213
JM
8721
8722
6d2ebf8b 8723@node Debug Session
104c1213
JM
8724@subsubsection Putting it all together
8725
8726@cindex remote serial debugging summary
8727In summary, when your program is ready to debug, you must follow these
8728steps.
8729
8730@enumerate
8731@item
6d2ebf8b 8732Make sure you have defined the supporting low-level routines
104c1213
JM
8733(@pxref{Bootstrapping,,What you must do for the stub}):
8734@display
8735@code{getDebugChar}, @code{putDebugChar},
8736@code{flush_i_cache}, @code{memset}, @code{exceptionHandler}.
8737@end display
8738
8739@item
8740Insert these lines near the top of your program:
8741
8742@example
8743set_debug_traps();
8744breakpoint();
8745@end example
8746
8747@item
8748For the 680x0 stub only, you need to provide a variable called
8749@code{exceptionHook}. Normally you just use:
8750
8751@example
8752void (*exceptionHook)() = 0;
8753@end example
8754
d4f3574e 8755@noindent
104c1213 8756but if before calling @code{set_debug_traps}, you set it to point to a
d4f3574e 8757function in your program; that function is called when
104c1213
JM
8758@code{@value{GDBN}} continues after stopping on a trap (for example, bus
8759error). The function indicated by @code{exceptionHook} is called with
8760one parameter: an @code{int} which is the exception number.
8761
8762@item
8763Compile and link together: your program, the @value{GDBN} debugging stub for
8764your target architecture, and the supporting subroutines.
8765
8766@item
8767Make sure you have a serial connection between your target machine and
8768the @value{GDBN} host, and identify the serial port on the host.
8769
8770@item
8771@c The "remote" target now provides a `load' command, so we should
8772@c document that. FIXME.
8773Download your program to your target machine (or get it there by
8774whatever means the manufacturer provides), and start it.
8775
8776@item
8777To start remote debugging, run @value{GDBN} on the host machine, and specify
8778as an executable file the program that is running in the remote machine.
8779This tells @value{GDBN} how to find your program's symbols and the contents
8780of its pure text.
8781
d4f3574e 8782@item
104c1213 8783@cindex serial line, @code{target remote}
d4f3574e 8784Establish communication using the @code{target remote} command.
104c1213
JM
8785Its argument specifies how to communicate with the target
8786machine---either via a devicename attached to a direct serial line, or a
8787TCP port (usually to a terminal server which in turn has a serial line
8788to the target). For example, to use a serial line connected to the
8789device named @file{/dev/ttyb}:
8790
8791@example
8792target remote /dev/ttyb
8793@end example
8794
8795@cindex TCP port, @code{target remote}
8796To use a TCP connection, use an argument of the form
8797@code{@var{host}:port}. For example, to connect to port 2828 on a
8798terminal server named @code{manyfarms}:
8799
8800@example
8801target remote manyfarms:2828
8802@end example
8803@end enumerate
8804
8805Now you can use all the usual commands to examine and change data and to
8806step and continue the remote program.
8807
8808To resume the remote program and stop debugging it, use the @code{detach}
8809command.
8810
8811@cindex interrupting remote programs
8812@cindex remote programs, interrupting
8813Whenever @value{GDBN} is waiting for the remote program, if you type the
8814interrupt character (often @key{C-C}), @value{GDBN} attempts to stop the
8815program. This may or may not succeed, depending in part on the hardware
8816and the serial drivers the remote system uses. If you type the
8817interrupt character once again, @value{GDBN} displays this prompt:
8818
8819@example
8820Interrupted while waiting for the program.
8821Give up (and stop debugging it)? (y or n)
8822@end example
8823
8824If you type @kbd{y}, @value{GDBN} abandons the remote debugging session.
8825(If you decide you want to try again later, you can use @samp{target
8826remote} again to connect once more.) If you type @kbd{n}, @value{GDBN}
8827goes back to waiting.
8828
6d2ebf8b 8829@node Protocol
104c1213
JM
8830@subsubsection Communication protocol
8831
8832@cindex debugging stub, example
8833@cindex remote stub, example
8834@cindex stub example, remote debugging
8835The stub files provided with @value{GDBN} implement the target side of the
8836communication protocol, and the @value{GDBN} side is implemented in the
8837@value{GDBN} source file @file{remote.c}. Normally, you can simply allow
8838these subroutines to communicate, and ignore the details. (If you're
8839implementing your own stub file, you can still ignore the details: start
8840with one of the existing stub files. @file{sparc-stub.c} is the best
8841organized, and therefore the easiest to read.)
8842
8843However, there may be occasions when you need to know something about
8844the protocol---for example, if there is only one serial port to your
8845target machine, you might want your program to do something special if
8846it recognizes a packet meant for @value{GDBN}.
8847
8848In the examples below, @samp{<-} and @samp{->} are used to indicate
8849transmitted and received data respectfully.
8850
8851@cindex protocol, @value{GDBN} remote serial
8852@cindex serial protocol, @value{GDBN} remote
8853@cindex remote serial protocol
8854All @value{GDBN} commands and responses (other than acknowledgments)
8855are sent as a @var{packet}. A @var{packet} is introduced with the
8856character @samp{$}, this is followed by an optional two-digit
8857@var{sequence-id} and the character @samp{:}, the actual
8858@var{packet-data}, and the terminating character @samp{#} followed by a
8859two-digit @var{checksum}:
8860
8861@example
8862@code{$}@var{packet-data}@code{#}@var{checksum}
8863@end example
8864@noindent
8865or, with the optional @var{sequence-id}:
8866@example
8867@code{$}@var{sequence-id}@code{:}@var{packet-data}@code{#}@var{checksum}
8868@end example
8869
8870@cindex checksum, for @value{GDBN} remote
8871@noindent
8872The two-digit @var{checksum} is computed as the modulo 256 sum of all
8873characters between the leading @samp{$} and the trailing @samp{#} (that
8874consisting of both the optional @var{sequence-id}@code{:} and the actual
d4f3574e 8875@var{packet-data}) (an eight bit unsigned checksum).
104c1213
JM
8876
8877@cindex sequence-id, for @value{GDBN} remote
8878@noindent
8879The two-digit @var{sequence-id}, when present, is returned with the
8880acknowledgment. Beyond that its meaning is poorly defined.
8881@value{GDBN} is not known to output @var{sequence-id}s.
8882
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
8893If the received packet included a @var{sequence-id} than that is
8894appended to a positive acknowledgment:
8895
8896@example
8897<- @code{$}@var{sequence-id}@code{:}@var{packet-data}@code{#}@var{checksum}
8898-> @code{+}@var{sequence-id}
8899@end example
8900
8901The host (@value{GDBN}) sends @var{command}s, and the target (the
8902debugging stub incorporated in your program) sends a @var{response}. In
8903the case of step and continue @var{command}s, the response is only sent
8904when the operation has completed (the target has again stopped).
8905
8906@var{packet-data} consists of a sequence of characters with the
8907exception of @samp{#} and @samp{$} (see @samp{X} packet for an
8908exception). @samp{:} can not appear as the third character in a packet.
8909Fields within the packet should be separated using @samp{,} and @samp{;}
8910(unfortunately some packets chose to use @samp{:}). Except where
8911otherwise noted all numbers are represented in HEX with leading zeros
8912suppressed.
8913
8914Response @var{data} can be run-length encoded to save space. A @samp{*}
c3f6f71d 8915means that the next character is an @sc{ascii} encoding giving a repeat count
104c1213
JM
8916which stands for that many repetitions of the character preceding the
8917@samp{*}. The encoding is @code{n+29}, yielding a printable character
d4f3574e
SS
8918where @code{n >=3} (which is where rle starts to win). The printable
8919characters @samp{$}, @samp{#}, @samp{+} and @samp{-} or with a numeric
8920value greater than 126 should not be used.
8921
8922Some remote systems have used a different run-length encoding mechanism
8923loosely refered to as the cisco encoding. Following the @samp{*}
8924character are two hex digits that indicate the size of the packet.
104c1213
JM
8925
8926So:
8927@example
8928"@code{0* }"
8929@end example
8930@noindent
8931means the same as "0000".
8932
8933The error response, returned for some packets includes a two character
8934error number. That number is not well defined.
8935
8936For any @var{command} not supported by the stub, an empty response
8937(@samp{$#00}) should be returned. That way it is possible to extend the
8938protocol. A newer @value{GDBN} can tell if a packet is supported based
d4f3574e 8939on that response.
104c1213
JM
8940
8941Below is a complete list of all currently defined @var{command}s and
8942their corresponding response @var{data}:
8943
8944@multitable @columnfractions .30 .30 .40
8945@item Packet
8946@tab Request
8947@tab Description
8948
8949@item extended ops @emph{(optional)}
8950@tab @code{!}
8951@tab
d4f3574e 8952Use the extended remote protocol. Sticky---only needs to be set once.
104c1213
JM
8953The extended remote protocol support the @samp{R} packet.
8954@item
8955@tab reply @samp{}
8956@tab
8957Stubs that support the extended remote protocol return @samp{} which,
8958unfortunately, is identical to the response returned by stubs that do not
8959support protocol extensions.
8960
8961@item last signal
8962@tab @code{?}
8963@tab
d4f3574e
SS
8964Indicate the reason the target halted. The reply is the same as for step
8965and continue.
8966@item
8967@tab reply
8968@tab see below
8969
104c1213
JM
8970
8971@item reserved
8972@tab @code{a}
5d161b24 8973@tab Reserved for future use
104c1213
JM
8974
8975@item set program arguments @strong{(reserved)} @emph{(optional)}
8976@tab @code{A}@var{arglen}@code{,}@var{argnum}@code{,}@var{arg}@code{,...}
8977@tab
8978Initialized @samp{argv[]} array passed into program. @var{arglen}
8979specifies the number of bytes in the hex encoded byte stream @var{arg}.
d4f3574e 8980See @file{gdbserver} for more details.
104c1213
JM
8981@item
8982@tab reply @code{OK}
8983@item
8984@tab reply @code{E}@var{NN}
8985
8986@item set baud @strong{(deprecated)}
8987@tab @code{b}@var{baud}
8988@tab
8989Change the serial line speed to @var{baud}. JTC: @emph{When does the
8990transport layer state change? When it's received, or after the ACK is
8991transmitted. In either case, there are problems if the command or the
8992acknowledgment packet is dropped.} Stan: @emph{If people really wanted
8993to add something like this, and get it working for the first time, they
8994ought to modify ser-unix.c to send some kind of out-of-band message to a
8995specially-setup stub and have the switch happen "in between" packets, so
8996that from remote protocol's point of view, nothing actually
8997happened.}
8998
8999@item set breakpoint @strong{(deprecated)}
9000@tab @code{B}@var{addr},@var{mode}
9001@tab
9002Set (@var{mode} is @samp{S}) or clear (@var{mode} is @samp{C}) a
9003breakpoint at @var{addr}. @emph{This has been replaced by the @samp{Z} and
9004@samp{z} packets.}
9005
9006@item continue
9007@tab @code{c}@var{addr}
9008@tab
9009@var{addr} is address to resume. If @var{addr} is omitted, resume at
9010current address.
9011@item
9012@tab reply
9013@tab see below
9014
9015@item continue with signal @emph{(optional)}
9016@tab @code{C}@var{sig}@code{;}@var{addr}
9017@tab
9018Continue with signal @var{sig} (hex signal number). If
9019@code{;}@var{addr} is omitted, resume at same address.
9020@item
9021@tab reply
9022@tab see below
9023
d4f3574e 9024@item toggle debug @emph{(deprecated)}
104c1213
JM
9025@tab @code{d}
9026@tab
d4f3574e 9027toggle debug flag.
104c1213
JM
9028
9029@item detach @emph{(optional)}
9030@tab @code{D}
d4f3574e 9031@tab
2df3850c
JM
9032Detach @value{GDBN} from the remote system. Sent to the remote target before
9033@value{GDBN} disconnects.
d4f3574e
SS
9034@item
9035@tab reply @emph{no response}
9036@tab
2df3850c 9037@value{GDBN} does not check for any response after sending this packet
104c1213
JM
9038
9039@item reserved
9040@tab @code{e}
5d161b24 9041@tab Reserved for future use
104c1213
JM
9042
9043@item reserved
9044@tab @code{E}
5d161b24 9045@tab Reserved for future use
104c1213
JM
9046
9047@item reserved
9048@tab @code{f}
5d161b24 9049@tab Reserved for future use
104c1213
JM
9050
9051@item reserved
9052@tab @code{F}
5d161b24 9053@tab Reserved for future use
104c1213
JM
9054
9055@item read registers
9056@tab @code{g}
9057@tab Read general registers.
9058@item
9059@tab reply @var{XX...}
9060@tab
9061Each byte of register data is described by two hex digits. The bytes
9062with the register are transmitted in target byte order. The size of
d4f3574e 9063each register and their position within the @samp{g} @var{packet} are
2df3850c 9064determined by the @value{GDBN} internal macros @var{REGISTER_RAW_SIZE} and
d4f3574e
SS
9065@var{REGISTER_NAME} macros. The specification of several standard
9066@code{g} packets is specified below.
104c1213
JM
9067@item
9068@tab @code{E}@var{NN}
9069@tab for an error.
9070
9071@item write regs
9072@tab @code{G}@var{XX...}
9073@tab
9074See @samp{g} for a description of the @var{XX...} data.
9075@item
9076@tab reply @code{OK}
9077@tab for success
9078@item
9079@tab reply @code{E}@var{NN}
9080@tab for an error
9081
9082@item reserved
9083@tab @code{h}
5d161b24 9084@tab Reserved for future use
104c1213
JM
9085
9086@item set thread @emph{(optional)}
9087@tab @code{H}@var{c}@var{t...}
9088@tab
d4f3574e
SS
9089Set thread for subsequent operations (@samp{m}, @samp{M}, @samp{g},
9090@samp{G}, et.al.). @var{c} = @samp{c} for thread used in step and
9091continue; @var{t...} can be -1 for all threads. @var{c} = @samp{g} for
9092thread used in other operations. If zero, pick a thread, any thread.
104c1213
JM
9093@item
9094@tab reply @code{OK}
9095@tab for success
9096@item
9097@tab reply @code{E}@var{NN}
9098@tab for an error
9099
d4f3574e
SS
9100@c FIXME: JTC:
9101@c 'H': How restrictive (or permissive) is the thread model. If a
5d161b24 9102@c thread is selected and stopped, are other threads allowed
d4f3574e
SS
9103@c to continue to execute? As I mentioned above, I think the
9104@c semantics of each command when a thread is selected must be
9105@c described. For example:
9106@c
9107@c 'g': If the stub supports threads and a specific thread is
9108@c selected, returns the register block from that thread;
9109@c otherwise returns current registers.
9110@c
9111@c 'G' If the stub supports threads and a specific thread is
9112@c selected, sets the registers of the register block of
9113@c that thread; otherwise sets current registers.
9114
104c1213
JM
9115@item cycle step @strong{(draft)} @emph{(optional)}
9116@tab @code{i}@var{addr}@code{,}@var{nnn}
9117@tab
9118Step the remote target by a single clock cycle. If @code{,}@var{nnn} is
9119present, cycle step @var{nnn} cycles. If @var{addr} is present, cycle
9120step starting at that address.
9121
9122@item signal then cycle step @strong{(reserved)} @emph{(optional)}
9123@tab @code{I}
9124@tab
9125See @samp{i} and @samp{S} for likely syntax and semantics.
9126
9127@item reserved
9128@tab @code{j}
9129@tab Reserved for future use
9130
9131@item reserved
9132@tab @code{J}
5d161b24 9133@tab Reserved for future use
104c1213
JM
9134
9135@item kill request @emph{(optional)}
9136@tab @code{k}
9137@tab
d4f3574e
SS
9138FIXME: @emph{There is no description of how operate when a specific
9139thread context has been selected (ie. does 'k' kill only that thread?)}.
104c1213
JM
9140
9141@item reserved
9142@tab @code{l}
5d161b24 9143@tab Reserved for future use
104c1213
JM
9144
9145@item reserved
9146@tab @code{L}
5d161b24 9147@tab Reserved for future use
104c1213
JM
9148
9149@item read memory
9150@tab @code{m}@var{addr}@code{,}@var{length}
9151@tab
9152Read @var{length} bytes of memory starting at address @var{addr}.
2df3850c 9153Neither @value{GDBN} nor the stub assume that sized memory transfers are assumed
d4f3574e
SS
9154using word alligned accesses. FIXME: @emph{A word aligned memory
9155transfer mechanism is needed.}
104c1213
JM
9156@item
9157@tab reply @var{XX...}
9158@tab
d4f3574e 9159@var{XX...} is mem contents. Can be fewer bytes than requested if able
2df3850c 9160to read only part of the data. Neither @value{GDBN} nor the stub assume that
d4f3574e
SS
9161sized memory transfers are assumed using word alligned accesses. FIXME:
9162@emph{A word aligned memory transfer mechanism is needed.}
104c1213
JM
9163@item
9164@tab reply @code{E}@var{NN}
9165@tab @var{NN} is errno
9166
9167@item write mem
9168@tab @code{M}@var{addr},@var{length}@code{:}@var{XX...}
9169@tab
9170Write @var{length} bytes of memory starting at address @var{addr}.
9171@var{XX...} is the data.
9172@item
9173@tab reply @code{OK}
9174@tab for success
9175@item
9176@tab reply @code{E}@var{NN}
9177@tab
9178for an error (this includes the case where only part of the data was
9179written).
9180
9181@item reserved
9182@tab @code{n}
5d161b24 9183@tab Reserved for future use
104c1213
JM
9184
9185@item reserved
9186@tab @code{N}
5d161b24 9187@tab Reserved for future use
104c1213
JM
9188
9189@item reserved
9190@tab @code{o}
5d161b24 9191@tab Reserved for future use
104c1213
JM
9192
9193@item reserved
9194@tab @code{O}
5d161b24 9195@tab Reserved for future use
104c1213
JM
9196
9197@item read reg @strong{(reserved)}
9198@tab @code{p}@var{n...}
9199@tab
9200See write register.
9201@item
9202@tab return @var{r....}
9203@tab The hex encoded value of the register in target byte order.
9204
9205@item write reg @emph{(optional)}
9206@tab @code{P}@var{n...}@code{=}@var{r...}
9207@tab
9208Write register @var{n...} with value @var{r...}, which contains two hex
9209digits for each byte in the register (target byte order).
9210@item
9211@tab reply @code{OK}
9212@tab for success
9213@item
9214@tab reply @code{E}@var{NN}
9215@tab for an error
9216
9217@item general query @emph{(optional)}
9218@tab @code{q}@var{query}
9219@tab
d4f3574e 9220Request info about @var{query}. In general @value{GDBN} @var{query}'s
104c1213 9221have a leading upper case letter. Custom vendor queries should use a
d4f3574e
SS
9222company prefix (in lower case) ex: @samp{qfsf.var}. @var{query} may
9223optionally be followed by a @samp{,} or @samp{;} separated list. Stubs
9224must ensure that they match the full @var{query} name.
104c1213
JM
9225@item
9226@tab reply @code{XX...}
d4f3574e 9227@tab Hex encoded data from query. The reply can not be empty.
104c1213
JM
9228@item
9229@tab reply @code{E}@var{NN}
9230@tab error reply
9231@item
9232@tab reply @samp{}
9233@tab Indicating an unrecognized @var{query}.
9234
104c1213
JM
9235@item general set @emph{(optional)}
9236@tab @code{Q}@var{var}@code{=}@var{val}
9237@tab
9238Set value of @var{var} to @var{val}. See @samp{q} for a discussing of
9239naming conventions.
9240
d4f3574e
SS
9241@item reset @emph{(deprecated)}
9242@tab @code{r}
9243@tab
9244Reset the entire system.
104c1213
JM
9245
9246@item remote restart @emph{(optional)}
9247@tab @code{R}@var{XX}
9248@tab
d4f3574e
SS
9249Restart the remote server. @var{XX} while needed has no clear
9250definition. FIXME: @emph{An example interaction explaining how this
9251packet is used in extended-remote mode is needed}.
104c1213
JM
9252
9253@item step @emph{(optional)}
9254@tab @code{s}@var{addr}
9255@tab
9256@var{addr} is address to resume. If @var{addr} is omitted, resume at
9257same address.
9258@item
9259@tab reply
9260@tab see below
9261
9262@item step with signal @emph{(optional)}
9263@tab @code{S}@var{sig}@code{;}@var{addr}
9264@tab
9265Like @samp{C} but step not continue.
9266@item
9267@tab reply
9268@tab see below
9269
9270@item search @emph{(optional)}
9271@tab @code{t}@var{addr}@code{:}@var{PP}@code{,}@var{MM}
9272@tab
9273Search backwards starting at address @var{addr} for a match with pattern
9274@var{PP} and mask @var{MM}. @var{PP} and @var{MM} are 4
d4f3574e 9275bytes. @var{addr} must be at least 3 digits.
104c1213
JM
9276
9277@item thread alive @emph{(optional)}
9278@tab @code{T}@var{XX}
9279@tab Find out if the thread XX is alive.
9280@item
9281@tab reply @code{OK}
9282@tab thread is still alive
9283@item
9284@tab reply @code{E}@var{NN}
9285@tab thread is dead
5d161b24 9286
104c1213
JM
9287@item reserved
9288@tab @code{u}
5d161b24 9289@tab Reserved for future use
104c1213
JM
9290
9291@item reserved
9292@tab @code{U}
5d161b24 9293@tab Reserved for future use
104c1213
JM
9294
9295@item reserved
9296@tab @code{v}
5d161b24 9297@tab Reserved for future use
104c1213
JM
9298
9299@item reserved
9300@tab @code{V}
5d161b24 9301@tab Reserved for future use
104c1213
JM
9302
9303@item reserved
9304@tab @code{w}
5d161b24 9305@tab Reserved for future use
104c1213
JM
9306
9307@item reserved
9308@tab @code{W}
5d161b24 9309@tab Reserved for future use
104c1213
JM
9310
9311@item reserved
9312@tab @code{x}
5d161b24 9313@tab Reserved for future use
104c1213
JM
9314
9315@item write mem (binary) @emph{(optional)}
9316@tab @code{X}@var{addr}@code{,}@var{length}@var{:}@var{XX...}
9317@tab
9318@var{addr} is address, @var{length} is number of bytes, @var{XX...} is
d4f3574e
SS
9319binary data. The characters @code{$}, @code{#}, and @code{0x7d} are
9320escaped using @code{0x7d}.
104c1213
JM
9321@item
9322@tab reply @code{OK}
9323@tab for success
9324@item
9325@tab reply @code{E}@var{NN}
9326@tab for an error
9327
9328@item reserved
9329@tab @code{y}
5d161b24 9330@tab Reserved for future use
104c1213
JM
9331
9332@item reserved
9333@tab @code{Y}
5d161b24 9334@tab Reserved for future use
104c1213
JM
9335
9336@item remove break or watchpoint @strong{(draft)} @emph{(optional)}
9337@tab @code{z}@var{t}@code{,}@var{addr}@code{,}@var{length}
9338@tab
9339See @samp{Z}.
9340
9341@item insert break or watchpoint @strong{(draft)} @emph{(optional)}
9342@tab @code{Z}@var{t}@code{,}@var{addr}@code{,}@var{length}
9343@tab
9344@var{t} is type: @samp{0} - software breakpoint, @samp{1} - hardware
9345breakpoint, @samp{2} - write watchpoint, @samp{3} - read watchpoint,
9346@samp{4} - access watchpoint; @var{addr} is address; @var{length} is in
9347bytes. For a software breakpoint, @var{length} specifies the size of
9348the instruction to be patched. For hardware breakpoints and watchpoints
d4f3574e
SS
9349@var{length} specifies the memory region to be monitored. To avoid
9350potential problems with duplicate packets, the operations should be
6d2ebf8b 9351implemented in an idempotent way.
104c1213
JM
9352@item
9353@tab reply @code{E}@var{NN}
9354@tab for an error
9355@item
9356@tab reply @code{OK}
9357@tab for success
9358@item
9359@tab @samp{}
9360@tab If not supported.
9361
9362@item reserved
9363@tab <other>
5d161b24 9364@tab Reserved for future use
104c1213
JM
9365
9366@end multitable
9367
d4f3574e
SS
9368The @samp{C}, @samp{c}, @samp{S}, @samp{s} and @samp{?} packets can
9369receive any of the below as a reply. In the case of the @samp{C},
9370@samp{c}, @samp{S} and @samp{s} packets, that reply is only returned
9371when the target halts. In the below the exact meaning of @samp{signal
9372number} is poorly defined. In general one of the UNIX signal numbering
9373conventions is used.
104c1213
JM
9374
9375@multitable @columnfractions .4 .6
9376
9377@item @code{S}@var{AA}
9378@tab @var{AA} is the signal number
9379
9380@item @code{T}@var{AA}@var{n...}@code{:}@var{r...}@code{;}@var{n...}@code{:}@var{r...}@code{;}@var{n...}@code{:}@var{r...}@code{;}
9381@tab
9382@var{AA} = two hex digit signal number; @var{n...} = register number
9383(hex), @var{r...} = target byte ordered register contents, size defined
9384by @code{REGISTER_RAW_SIZE}; @var{n...} = @samp{thread}, @var{r...} =
9385thread process ID, this is a hex integer; @var{n...} = other string not
d4f3574e 9386starting with valid hex digit. @value{GDBN} should ignore this
104c1213
JM
9387@var{n...}, @var{r...} pair and go on to the next. This way we can
9388extend the protocol.
9389
9390@item @code{W}@var{AA}
9391@tab
9392The process exited, and @var{AA} is the exit status. This is only
9393applicable for certains sorts of targets.
9394
9395@item @code{X}@var{AA}
9396@tab
9397The process terminated with signal @var{AA}.
9398
6d2ebf8b 9399@item @code{N}@var{AA}@code{;}@var{t...}@code{;}@var{d...}@code{;}@var{b...} @strong{(obsolete)}
104c1213 9400@tab
6d2ebf8b
SS
9401@var{AA} = signal number; @var{t...} = address of symbol "_start";
9402@var{d...} = base of data section; @var{b...} = base of bss section.
9403@emph{Note: only used by Cisco Systems targets. The difference between
9404this reply and the "qOffsets" query is that the 'N' packet may arrive
9405spontaneously whereas the 'qOffsets' is a query initiated by the host
9406debugger.}
104c1213
JM
9407
9408@item @code{O}@var{XX...}
9409@tab
c3f6f71d 9410@var{XX...} is hex encoding of @sc{ascii} data. This can happen at any time
104c1213
JM
9411while the program is running and the debugger should continue to wait
9412for 'W', 'T', etc.
9413
9414@end multitable
9415
d4f3574e
SS
9416The following set and query packets have already been defined.
9417
9418@multitable @columnfractions .2 .2 .6
9419
9420@item current thread
9421@tab @code{q}@code{C}
9422@tab Return the current thread id.
9423@item
9424@tab reply @code{QC}@var{pid}
9425@tab
9426Where @var{pid} is a HEX encoded 16 bit process id.
9427@item
9428@tab reply *
9429@tab Any other reply implies the old pid.
9430
bba2971c
MS
9431@item all thread ids
9432@tab @code{q}@code{fThreadInfo}
9433@item
9434@tab @code{q}@code{sThreadInfo}
d4f3574e 9435@tab
bba2971c
MS
9436Obtain a list of active thread ids from the target (OS). Since there
9437may be too many active threads to fit into one reply packet, this query
9438works iteratively: it may require more than one query/reply sequence to
9439obtain the entire list of threads. The first query of the sequence will
5d161b24 9440be the @code{qf}@code{ThreadInfo} query; subsequent queries in the
bba2971c 9441sequence will be the @code{qs}@code{ThreadInfo} query.
d4f3574e 9442@item
bba2971c
MS
9443@tab
9444@tab NOTE: replaces the @code{qL} query (see below).
d4f3574e 9445@item
5d161b24 9446@tab reply @code{m}@var{<id>}
bba2971c
MS
9447@tab A single thread id
9448@item
5d161b24 9449@tab reply @code{m}@var{<id>,}@var{<id>...}
bba2971c
MS
9450@tab a comma-separated list of thread ids
9451@item
9452@tab reply @code{l}
9453@tab (lower case 'el') denotes end of list.
9454@item
9455@tab
9456@tab
9457In response to each query, the target will reply with a list of one
9458or more thread ids, in big-endian hex, separated by commas. GDB will
9459respond to each reply with a request for more thread ids (using the
9460@code{qs} form of the query), until the target responds with @code{l}
9461(lower-case el, for @code{'last'}).
9462
9463@item extra thread info
9464@tab @code{qfThreadExtraInfo,}@var{<id>}
9465@tab
9466@item
9467@tab
9468@tab
9469Where @var{<id>} is a thread-id in big-endian hex.
9470Obtain a printable string description of a thread's attributes from
9471the target OS. This string may contain anything that the target OS
9472thinks is interesting for @value{GDBN} to tell the user about the thread.
9473The string is displayed in @value{GDBN}'s @samp{info threads} display.
5d161b24 9474Some examples of possible thread extra info strings are "Runnable", or
bba2971c
MS
9475"Blocked on Mutex".
9476@item
9477@tab reply @var{XX...}
9478@tab
9479Where @var{XX...} is a hex encoding of @sc{ascii} data, comprising the
9480printable string containing the extra information about the thread's
9481attributes.
d4f3574e
SS
9482
9483@item query @var{LIST} or @var{threadLIST} @strong{(deprecated)}
9484@tab @code{q}@code{L}@var{startflag}@var{threadcount}@var{nextthread}
9485@tab
2b628194
MS
9486@item
9487@tab
9488@tab
d4f3574e
SS
9489Obtain thread information from RTOS. Where: @var{startflag} (one hex
9490digit) is one to indicate the first query and zero to indicate a
9491subsequent query; @var{threadcount} (two hex digits) is the maximum
9492number of threads the response packet can contain; and @var{nextthread}
9493(eight hex digits), for subsequent queries (@var{startflag} is zero), is
9494returned in the response as @var{argthread}.
9495@item
bba2971c
MS
9496@tab
9497@tab NOTE: this query is replaced by the @code{q}@code{fThreadInfo}
9498query (see above).
9499@item
d4f3574e
SS
9500@tab reply @code{q}@code{M}@var{count}@var{done}@var{argthread}@var{thread...}
9501@tab
2b628194
MS
9502@item
9503@tab
9504@tab
d4f3574e
SS
9505Where: @var{count} (two hex digits) is the number of threads being
9506returned; @var{done} (one hex digit) is zero to indicate more threads
9507and one indicates no further threads; @var{argthreadid} (eight hex
9508digits) is @var{nextthread} from the request packet; @var{thread...} is
9509a sequence of thread IDs from the target. @var{threadid} (eight hex
9510digits). See @code{remote.c:parse_threadlist_response()}.
9511
bba2971c
MS
9512@item compute CRC of memory block
9513@tab @code{q}@code{CRC:}@var{addr}@code{,}@var{length}
9514@tab
9515@item
9516@tab reply @code{E}@var{NN}
9517@tab An error (such as memory fault)
9518@item
9519@tab reply @code{C}@var{CRC32}
9520@tab A 32 bit cyclic redundancy check of the specified memory region.
9521
d4f3574e
SS
9522@item query sect offs
9523@tab @code{q}@code{Offsets}
917317f4
JM
9524@tab
9525Get section offsets that the target used when re-locating the downloaded
9526image. @emph{Note: while a @code{Bss} offset is included in the
9527response, @value{GDBN} ignores this and instead applies the @code{Data}
9528offset to the @code{Bss} section.}
d4f3574e
SS
9529@item
9530@tab reply @code{Text=}@var{xxx}@code{;Data=}@var{yyy}@code{;Bss=}@var{zzz}
9531
9532@item thread info request
9533@tab @code{q}@code{P}@var{mode}@var{threadid}
9534@tab
9535Returns information on @var{threadid}. Where: @var{mode} is a hex
9536encoded 32 bit mode; @var{threadid} is a hex encoded 64 bit thread ID.
9537@item
9538@tab reply *
9539@tab
9540See @code{remote.c:remote_unpack_thread_info_response()}.
9541
9542@item remote command
9543@tab @code{q}@code{Rcmd,}@var{COMMAND}
9544@tab
9545@var{COMMAND} (hex encoded) is passed to the local interpreter for
9546execution. Invalid commands should be reported using the output string.
9547Before the final result packet, the target may also respond with a
9548number of intermediate @code{O}@var{OUTPUT} console output
9549packets. @emph{Implementors should note that providing access to a
9550stubs's interpreter may have security implications}.
9551@item
9552@tab reply @code{OK}
9553@tab
9554A command response with no output.
9555@item
9556@tab reply @var{OUTPUT}
9557@tab
9558A command response with the hex encoded output string @var{OUTPUT}.
9559@item
9560@tab reply @code{E}@var{NN}
9561@tab
9562Indicate a badly formed request.
9563
9564@item
9565@tab reply @samp{}
9566@tab
9567When @samp{q}@samp{Rcmd} is not recognized.
9568
9569@end multitable
9570
9571The following @samp{g}/@samp{G} packets have previously been defined.
9572In the below, some thirty-two bit registers are transferred as sixty-four
9573bits. Those registers should be zero/sign extended (which?) to fill the
9574space allocated. Register bytes are transfered in target byte order.
9575The two nibbles within a register byte are transfered most-significant -
9576least-significant.
9577
9578@multitable @columnfractions .5 .5
9579
9580@item MIPS32
9581@tab
9582All registers are transfered as thirty-two bit quantities in the order:
958332 general-purpose; sr; lo; hi; bad; cause; pc; 32 floating-point
9584registers; fsr; fir; fp.
9585
9586@item MIPS64
9587@tab
9588All registers are transfered as sixty-four bit quantities (including
9589thirty-two bit registers such as @code{sr}). The ordering is the same
9590as @code{MIPS32}.
9591
9592@end multitable
9593
104c1213
JM
9594Example sequence of a target being re-started. Notice how the restart
9595does not get any direct output:
9596
9597@example
9598<- @code{R00}
9599-> @code{+}
9600@emph{target restarts}
9601<- @code{?}
9602-> @code{+}
9603-> @code{T001:1234123412341234}
9604<- @code{+}
9605@end example
9606
9607Example sequence of a target being stepped by a single instruction:
9608
9609@example
9610<- @code{G1445...}
9611-> @code{+}
9612<- @code{s}
9613-> @code{+}
9614@emph{time passes}
9615-> @code{T001:1234123412341234}
9616<- @code{+}
9617<- @code{g}
9618-> @code{+}
9619-> @code{1455...}
9620<- @code{+}
9621@end example
9622
6d2ebf8b 9623@node Server
104c1213
JM
9624@subsubsection Using the @code{gdbserver} program
9625
9626@kindex gdbserver
9627@cindex remote connection without stubs
9628@code{gdbserver} is a control program for Unix-like systems, which
9629allows you to connect your program with a remote @value{GDBN} via
9630@code{target remote}---but without linking in the usual debugging stub.
9631
9632@code{gdbserver} is not a complete replacement for the debugging stubs,
9633because it requires essentially the same operating-system facilities
9634that @value{GDBN} itself does. In fact, a system that can run
9635@code{gdbserver} to connect to a remote @value{GDBN} could also run
9636@value{GDBN} locally! @code{gdbserver} is sometimes useful nevertheless,
9637because it is a much smaller program than @value{GDBN} itself. It is
9638also easier to port than all of @value{GDBN}, so you may be able to get
9639started more quickly on a new system by using @code{gdbserver}.
9640Finally, if you develop code for real-time systems, you may find that
9641the tradeoffs involved in real-time operation make it more convenient to
9642do as much development work as possible on another system, for example
9643by cross-compiling. You can use @code{gdbserver} to make a similar
9644choice for debugging.
9645
9646@value{GDBN} and @code{gdbserver} communicate via either a serial line
9647or a TCP connection, using the standard @value{GDBN} remote serial
9648protocol.
9649
9650@table @emph
9651@item On the target machine,
9652you need to have a copy of the program you want to debug.
9653@code{gdbserver} does not need your program's symbol table, so you can
9654strip the program if necessary to save space. @value{GDBN} on the host
9655system does all the symbol handling.
9656
9657To use the server, you must tell it how to communicate with @value{GDBN};
9658the name of your program; and the arguments for your program. The
9659syntax is:
9660
9661@smallexample
9662target> gdbserver @var{comm} @var{program} [ @var{args} @dots{} ]
9663@end smallexample
9664
9665@var{comm} is either a device name (to use a serial line) or a TCP
9666hostname and portnumber. For example, to debug Emacs with the argument
9667@samp{foo.txt} and communicate with @value{GDBN} over the serial port
9668@file{/dev/com1}:
9669
9670@smallexample
9671target> gdbserver /dev/com1 emacs foo.txt
9672@end smallexample
9673
9674@code{gdbserver} waits passively for the host @value{GDBN} to communicate
9675with it.
9676
9677To use a TCP connection instead of a serial line:
9678
9679@smallexample
9680target> gdbserver host:2345 emacs foo.txt
9681@end smallexample
9682
9683The only difference from the previous example is the first argument,
9684specifying that you are communicating with the host @value{GDBN} via
9685TCP. The @samp{host:2345} argument means that @code{gdbserver} is to
9686expect a TCP connection from machine @samp{host} to local TCP port 2345.
9687(Currently, the @samp{host} part is ignored.) You can choose any number
9688you want for the port number as long as it does not conflict with any
9689TCP ports already in use on the target system (for example, @code{23} is
9690reserved for @code{telnet}).@footnote{If you choose a port number that
9691conflicts with another service, @code{gdbserver} prints an error message
d4f3574e 9692and exits.} You must use the same port number with the host @value{GDBN}
104c1213
JM
9693@code{target remote} command.
9694
9695@item On the @value{GDBN} host machine,
9696you need an unstripped copy of your program, since @value{GDBN} needs
9697symbols and debugging information. Start up @value{GDBN} as usual,
9698using the name of the local copy of your program as the first argument.
9699(You may also need the @w{@samp{--baud}} option if the serial line is
d4f3574e 9700running at anything other than 9600@dmn{bps}.) After that, use @code{target
104c1213
JM
9701remote} to establish communications with @code{gdbserver}. Its argument
9702is either a device name (usually a serial device, like
9703@file{/dev/ttyb}), or a TCP port descriptor in the form
9704@code{@var{host}:@var{PORT}}. For example:
9705
9706@smallexample
9707(@value{GDBP}) target remote /dev/ttyb
9708@end smallexample
9709
9710@noindent
9711communicates with the server via serial line @file{/dev/ttyb}, and
9712
9713@smallexample
9714(@value{GDBP}) target remote the-target:2345
9715@end smallexample
9716
9717@noindent
9718communicates via a TCP connection to port 2345 on host @w{@file{the-target}}.
9719For TCP connections, you must start up @code{gdbserver} prior to using
9720the @code{target remote} command. Otherwise you may get an error whose
9721text depends on the host system, but which usually looks something like
9722@samp{Connection refused}.
9723@end table
9724
6d2ebf8b 9725@node NetWare
104c1213
JM
9726@subsubsection Using the @code{gdbserve.nlm} program
9727
9728@kindex gdbserve.nlm
9729@code{gdbserve.nlm} is a control program for NetWare systems, which
9730allows you to connect your program with a remote @value{GDBN} via
9731@code{target remote}.
9732
9733@value{GDBN} and @code{gdbserve.nlm} communicate via a serial line,
9734using the standard @value{GDBN} remote serial protocol.
9735
9736@table @emph
9737@item On the target machine,
9738you need to have a copy of the program you want to debug.
9739@code{gdbserve.nlm} does not need your program's symbol table, so you
9740can strip the program if necessary to save space. @value{GDBN} on the
9741host system does all the symbol handling.
9742
9743To use the server, you must tell it how to communicate with
9744@value{GDBN}; the name of your program; and the arguments for your
9745program. The syntax is:
9746
5d161b24 9747@smallexample
104c1213
JM
9748load gdbserve [ BOARD=@var{board} ] [ PORT=@var{port} ]
9749 [ BAUD=@var{baud} ] @var{program} [ @var{args} @dots{} ]
9750@end smallexample
9751
9752@var{board} and @var{port} specify the serial line; @var{baud} specifies
9753the baud rate used by the connection. @var{port} and @var{node} default
d4f3574e 9754to 0, @var{baud} defaults to 9600@dmn{bps}.
104c1213
JM
9755
9756For example, to debug Emacs with the argument @samp{foo.txt}and
5d161b24 9757communicate with @value{GDBN} over serial port number 2 or board 1
d4f3574e 9758using a 19200@dmn{bps} connection:
104c1213
JM
9759
9760@smallexample
9761load gdbserve BOARD=1 PORT=2 BAUD=19200 emacs foo.txt
9762@end smallexample
9763
9764@item On the @value{GDBN} host machine,
9765you need an unstripped copy of your program, since @value{GDBN} needs
9766symbols and debugging information. Start up @value{GDBN} as usual,
9767using the name of the local copy of your program as the first argument.
9768(You may also need the @w{@samp{--baud}} option if the serial line is
d4f3574e 9769running at anything other than 9600@dmn{bps}. After that, use @code{target
104c1213
JM
9770remote} to establish communications with @code{gdbserve.nlm}. Its
9771argument is a device name (usually a serial device, like
9772@file{/dev/ttyb}). For example:
9773
9774@smallexample
9775(@value{GDBP}) target remote /dev/ttyb
9776@end smallexample
9777
9778@noindent
9779communications with the server via serial line @file{/dev/ttyb}.
9780@end table
9781
6d2ebf8b 9782@node KOD
104c1213
JM
9783@section Kernel Object Display
9784
9785@cindex kernel object display
9786@cindex kernel object
9787@cindex KOD
9788
9789Some targets support kernel object display. Using this facility,
9790@value{GDBN} communicates specially with the underlying operating system
9791and can display information about operating system-level objects such as
9792mutexes and other synchronization objects. Exactly which objects can be
9793displayed is determined on a per-OS basis.
9794
9795Use the @code{set os} command to set the operating system. This tells
9796@value{GDBN} which kernel object display module to initialize:
9797
9798@example
2df3850c 9799(@value{GDBP}) set os cisco
104c1213
JM
9800@end example
9801
9802If @code{set os} succeeds, @value{GDBN} will display some information
9803about the operating system, and will create a new @code{info} command
9804which can be used to query the target. The @code{info} command is named
9805after the operating system:
9806
9807@example
2df3850c 9808(@value{GDBP}) info cisco
104c1213
JM
9809List of Cisco Kernel Objects
9810Object Description
9811any Any and all objects
9812@end example
9813
9814Further subcommands can be used to query about particular objects known
9815by the kernel.
9816
9817There is currently no way to determine whether a given operating system
96baa820
JM
9818is supported other than to try it.
9819
9820
6d2ebf8b 9821@node Configurations
104c1213
JM
9822@chapter Configuration-Specific Information
9823
9824While nearly all @value{GDBN} commands are available for all native and
9825cross versions of the debugger, there are some exceptions. This chapter
9826describes things that are only available in certain configurations.
9827
9828There are three major categories of configurations: native
9829configurations, where the host and target are the same, embedded
9830operating system configurations, which are usually the same for several
9831different processor architectures, and bare embedded processors, which
9832are quite different from each other.
9833
9834@menu
9835* Native::
9836* Embedded OS::
9837* Embedded Processors::
9838* Architectures::
9839@end menu
9840
6d2ebf8b 9841@node Native
104c1213
JM
9842@section Native
9843
9844This section describes details specific to particular native
9845configurations.
9846
9847@menu
9848* HP-UX:: HP-UX
9849* SVR4 Process Information:: SVR4 process information
9850@end menu
9851
6d2ebf8b 9852@node HP-UX
104c1213
JM
9853@subsection HP-UX
9854
9855On HP-UX systems, if you refer to a function or variable name that
9856begins with a dollar sign, @value{GDBN} searches for a user or system
9857name first, before it searches for a convenience variable.
9858
6d2ebf8b 9859@node SVR4 Process Information
104c1213
JM
9860@subsection SVR4 process information
9861
9862@kindex /proc
9863@cindex process image
9864
9865Many versions of SVR4 provide a facility called @samp{/proc} that can be
9866used to examine the image of a running process using file-system
9867subroutines. If @value{GDBN} is configured for an operating system with
9868this facility, the command @code{info proc} is available to report on
9869several kinds of information about the process running your program.
9870@code{info proc} works only on SVR4 systems that include the
9871@code{procfs} code. This includes OSF/1 (Digital Unix), Solaris, Irix,
9872and Unixware, but not HP-UX or Linux, for example.
9873
9874@table @code
9875@kindex info proc
9876@item info proc
9877Summarize available information about the process.
9878
9879@kindex info proc mappings
9880@item info proc mappings
9881Report on the address ranges accessible in the program, with information
9882on whether your program may read, write, or execute each range.
9883
9884@kindex info proc times
9885@item info proc times
9886Starting time, user CPU time, and system CPU time for your program and
9887its children.
9888
9889@kindex info proc id
9890@item info proc id
9891Report on the process IDs related to your program: its own process ID,
9892the ID of its parent, the process group ID, and the session ID.
9893
9894@kindex info proc status
9895@item info proc status
9896General information on the state of the process. If the process is
9897stopped, this report includes the reason for stopping, and any signal
9898received.
9899
9900@item info proc all
9901Show all the above information about the process.
9902@end table
9903
6d2ebf8b 9904@node Embedded OS
104c1213
JM
9905@section Embedded Operating Systems
9906
9907This section describes configurations involving the debugging of
9908embedded operating systems that are available for several different
9909architectures.
9910
9911@menu
9912* VxWorks:: Using @value{GDBN} with VxWorks
9913@end menu
9914
9915@value{GDBN} includes the ability to debug programs running on
9916various real-time operating systems.
9917
6d2ebf8b 9918@node VxWorks
104c1213
JM
9919@subsection Using @value{GDBN} with VxWorks
9920
9921@cindex VxWorks
9922
9923@table @code
9924
9925@kindex target vxworks
9926@item target vxworks @var{machinename}
9927A VxWorks system, attached via TCP/IP. The argument @var{machinename}
9928is the target system's machine name or IP address.
9929
9930@end table
9931
9932On VxWorks, @code{load} links @var{filename} dynamically on the
9933current target system as well as adding its symbols in @value{GDBN}.
9934
9935@value{GDBN} enables developers to spawn and debug tasks running on networked
9936VxWorks targets from a Unix host. Already-running tasks spawned from
9937the VxWorks shell can also be debugged. @value{GDBN} uses code that runs on
9938both the Unix host and on the VxWorks target. The program
d4f3574e 9939@code{@value{GDBP}} is installed and executed on the Unix host. (It may be
104c1213 9940installed with the name @code{vxgdb}, to distinguish it from a
96a2c332 9941@value{GDBN} for debugging programs on the host itself.)
104c1213
JM
9942
9943@table @code
9944@item VxWorks-timeout @var{args}
9945@kindex vxworks-timeout
5d161b24
DB
9946All VxWorks-based targets now support the option @code{vxworks-timeout}.
9947This option is set by the user, and @var{args} represents the number of
9948seconds @value{GDBN} waits for responses to rpc's. You might use this if
9949your VxWorks target is a slow software simulator or is on the far side
104c1213
JM
9950of a thin network line.
9951@end table
9952
9953The following information on connecting to VxWorks was current when
9954this manual was produced; newer releases of VxWorks may use revised
9955procedures.
9956
9957@kindex INCLUDE_RDB
9958To use @value{GDBN} with VxWorks, you must rebuild your VxWorks kernel
9959to include the remote debugging interface routines in the VxWorks
9960library @file{rdb.a}. To do this, define @code{INCLUDE_RDB} in the
9961VxWorks configuration file @file{configAll.h} and rebuild your VxWorks
9962kernel. The resulting kernel contains @file{rdb.a}, and spawns the
9963source debugging task @code{tRdbTask} when VxWorks is booted. For more
9964information on configuring and remaking VxWorks, see the manufacturer's
9965manual.
9966@c VxWorks, see the @cite{VxWorks Programmer's Guide}.
9967
9968Once you have included @file{rdb.a} in your VxWorks system image and set
9969your Unix execution search path to find @value{GDBN}, you are ready to
96a2c332
SS
9970run @value{GDBN}. From your Unix host, run @code{@value{GDBP}} (or
9971@code{vxgdb}, depending on your installation).
104c1213
JM
9972
9973@value{GDBN} comes up showing the prompt:
9974
9975@example
9976(vxgdb)
9977@end example
9978
9979@menu
9980* VxWorks Connection:: Connecting to VxWorks
9981* VxWorks Download:: VxWorks download
9982* VxWorks Attach:: Running tasks
9983@end menu
9984
6d2ebf8b 9985@node VxWorks Connection
104c1213
JM
9986@subsubsection Connecting to VxWorks
9987
9988The @value{GDBN} command @code{target} lets you connect to a VxWorks target on the
9989network. To connect to a target whose host name is ``@code{tt}'', type:
9990
9991@example
9992(vxgdb) target vxworks tt
9993@end example
9994
9995@need 750
9996@value{GDBN} displays messages like these:
9997
9998@smallexample
5d161b24 9999Attaching remote machine across net...
104c1213
JM
10000Connected to tt.
10001@end smallexample
10002
10003@need 1000
10004@value{GDBN} then attempts to read the symbol tables of any object modules
10005loaded into the VxWorks target since it was last booted. @value{GDBN} locates
10006these files by searching the directories listed in the command search
10007path (@pxref{Environment, ,Your program's environment}); if it fails
10008to find an object file, it displays a message such as:
10009
10010@example
10011prog.o: No such file or directory.
10012@end example
10013
10014When this happens, add the appropriate directory to the search path with
10015the @value{GDBN} command @code{path}, and execute the @code{target}
10016command again.
10017
6d2ebf8b 10018@node VxWorks Download
104c1213
JM
10019@subsubsection VxWorks download
10020
10021@cindex download to VxWorks
10022If you have connected to the VxWorks target and you want to debug an
10023object that has not yet been loaded, you can use the @value{GDBN}
10024@code{load} command to download a file from Unix to VxWorks
10025incrementally. The object file given as an argument to the @code{load}
10026command is actually opened twice: first by the VxWorks target in order
10027to download the code, then by @value{GDBN} in order to read the symbol
10028table. This can lead to problems if the current working directories on
10029the two systems differ. If both systems have NFS mounted the same
10030filesystems, you can avoid these problems by using absolute paths.
10031Otherwise, it is simplest to set the working directory on both systems
10032to the directory in which the object file resides, and then to reference
10033the file by its name, without any path. For instance, a program
10034@file{prog.o} may reside in @file{@var{vxpath}/vw/demo/rdb} in VxWorks
10035and in @file{@var{hostpath}/vw/demo/rdb} on the host. To load this
10036program, type this on VxWorks:
10037
10038@example
10039-> cd "@var{vxpath}/vw/demo/rdb"
10040@end example
d4f3574e
SS
10041
10042@noindent
104c1213
JM
10043Then, in @value{GDBN}, type:
10044
10045@example
5d161b24 10046(vxgdb) cd @var{hostpath}/vw/demo/rdb
104c1213
JM
10047(vxgdb) load prog.o
10048@end example
10049
10050@value{GDBN} displays a response similar to this:
10051
10052@smallexample
10053Reading symbol data from wherever/vw/demo/rdb/prog.o... done.
10054@end smallexample
10055
10056You can also use the @code{load} command to reload an object module
10057after editing and recompiling the corresponding source file. Note that
10058this makes @value{GDBN} delete all currently-defined breakpoints,
10059auto-displays, and convenience variables, and to clear the value
10060history. (This is necessary in order to preserve the integrity of
d4f3574e 10061debugger's data structures that reference the target system's symbol
104c1213
JM
10062table.)
10063
6d2ebf8b 10064@node VxWorks Attach
104c1213
JM
10065@subsubsection Running tasks
10066
10067@cindex running VxWorks tasks
10068You can also attach to an existing task using the @code{attach} command as
10069follows:
10070
10071@example
10072(vxgdb) attach @var{task}
10073@end example
10074
10075@noindent
10076where @var{task} is the VxWorks hexadecimal task ID. The task can be running
10077or suspended when you attach to it. Running tasks are suspended at
10078the time of attachment.
10079
6d2ebf8b 10080@node Embedded Processors
104c1213
JM
10081@section Embedded Processors
10082
10083This section goes into details specific to particular embedded
10084configurations.
10085
10086@menu
10087* A29K Embedded:: AMD A29K Embedded
10088* ARM:: ARM
10089* H8/300:: Hitachi H8/300
10090* H8/500:: Hitachi H8/500
10091* i960:: Intel i960
10092* M32R/D:: Mitsubishi M32R/D
10093* M68K:: Motorola M68K
10094* M88K:: Motorola M88K
10095* MIPS Embedded:: MIPS Embedded
10096* PA:: HP PA Embedded
10097* PowerPC: PowerPC
10098* SH:: Hitachi SH
10099* Sparclet:: Tsqware Sparclet
10100* Sparclite:: Fujitsu Sparclite
10101* ST2000:: Tandem ST2000
10102* Z8000:: Zilog Z8000
10103@end menu
10104
6d2ebf8b 10105@node A29K Embedded
104c1213
JM
10106@subsection AMD A29K Embedded
10107
10108@menu
10109* A29K UDI::
10110* A29K EB29K::
10111* Comms (EB29K):: Communications setup
10112* gdb-EB29K:: EB29K cross-debugging
10113* Remote Log:: Remote log
10114@end menu
10115
10116@table @code
10117
10118@kindex target adapt
10119@item target adapt @var{dev}
10120Adapt monitor for A29K.
10121
10122@kindex target amd-eb
10123@item target amd-eb @var{dev} @var{speed} @var{PROG}
10124@cindex AMD EB29K
10125Remote PC-resident AMD EB29K board, attached over serial lines.
10126@var{dev} is the serial device, as for @code{target remote};
10127@var{speed} allows you to specify the linespeed; and @var{PROG} is the
10128name of the program to be debugged, as it appears to DOS on the PC.
10129@xref{A29K EB29K, ,EBMON protocol for AMD29K}.
10130
10131@end table
10132
6d2ebf8b 10133@node A29K UDI
104c1213
JM
10134@subsubsection A29K UDI
10135
10136@cindex UDI
10137@cindex AMD29K via UDI
10138
10139@value{GDBN} supports AMD's UDI (``Universal Debugger Interface'')
10140protocol for debugging the a29k processor family. To use this
10141configuration with AMD targets running the MiniMON monitor, you need the
10142program @code{MONTIP}, available from AMD at no charge. You can also
10143use @value{GDBN} with the UDI-conformant a29k simulator program
10144@code{ISSTIP}, also available from AMD.
10145
10146@table @code
10147@item target udi @var{keyword}
10148@kindex udi
10149Select the UDI interface to a remote a29k board or simulator, where
10150@var{keyword} is an entry in the AMD configuration file @file{udi_soc}.
10151This file contains keyword entries which specify parameters used to
10152connect to a29k targets. If the @file{udi_soc} file is not in your
10153working directory, you must set the environment variable @samp{UDICONF}
10154to its pathname.
10155@end table
10156
6d2ebf8b 10157@node A29K EB29K
104c1213
JM
10158@subsubsection EBMON protocol for AMD29K
10159
10160@cindex EB29K board
10161@cindex running 29K programs
10162
10163AMD distributes a 29K development board meant to fit in a PC, together
10164with a DOS-hosted monitor program called @code{EBMON}. As a shorthand
10165term, this development system is called the ``EB29K''. To use
10166@value{GDBN} from a Unix system to run programs on the EB29K board, you
10167must first connect a serial cable between the PC (which hosts the EB29K
10168board) and a serial port on the Unix system. In the following, we
10169assume you've hooked the cable between the PC's @file{COM1} port and
10170@file{/dev/ttya} on the Unix system.
10171
6d2ebf8b 10172@node Comms (EB29K)
104c1213
JM
10173@subsubsection Communications setup
10174
10175The next step is to set up the PC's port, by doing something like this
10176in DOS on the PC:
10177
10178@example
10179C:\> MODE com1:9600,n,8,1,none
10180@end example
10181
10182@noindent
10183This example---run on an MS DOS 4.0 system---sets the PC port to 9600
10184bps, no parity, eight data bits, one stop bit, and no ``retry'' action;
10185you must match the communications parameters when establishing the Unix
10186end of the connection as well.
10187@c FIXME: Who knows what this "no retry action" crud from the DOS manual may
5d161b24 10188@c mean? It's optional; leave it out? ---doc@cygnus.com, 25feb91
d4f3574e
SS
10189@c
10190@c It's optional, but it's unwise to omit it: who knows what is the
10191@c default value set when the DOS machines boots? "No retry" means that
10192@c the DOS serial device driver won't retry the operation if it fails;
10193@c I understand that this is needed because the GDB serial protocol
10194@c handles any errors and retransmissions itself. ---Eli Zaretskii, 3sep99
104c1213
JM
10195
10196To give control of the PC to the Unix side of the serial line, type
10197the following at the DOS console:
10198
10199@example
10200C:\> CTTY com1
10201@end example
10202
10203@noindent
10204(Later, if you wish to return control to the DOS console, you can use
10205the command @code{CTTY con}---but you must send it over the device that
96a2c332 10206had control, in our example over the @file{COM1} serial line.)
104c1213
JM
10207
10208From the Unix host, use a communications program such as @code{tip} or
10209@code{cu} to communicate with the PC; for example,
10210
10211@example
10212cu -s 9600 -l /dev/ttya
10213@end example
10214
10215@noindent
10216The @code{cu} options shown specify, respectively, the linespeed and the
10217serial port to use. If you use @code{tip} instead, your command line
10218may look something like the following:
10219
10220@example
10221tip -9600 /dev/ttya
10222@end example
10223
10224@noindent
10225Your system may require a different name where we show
10226@file{/dev/ttya} as the argument to @code{tip}. The communications
10227parameters, including which port to use, are associated with the
10228@code{tip} argument in the ``remote'' descriptions file---normally the
10229system table @file{/etc/remote}.
10230@c FIXME: What if anything needs doing to match the "n,8,1,none" part of
10231@c the DOS side's comms setup? cu can support -o (odd
10232@c parity), -e (even parity)---apparently no settings for no parity or
10233@c for character size. Taken from stty maybe...? John points out tip
10234@c can set these as internal variables, eg ~s parity=none; man stty
10235@c suggests that it *might* work to stty these options with stdin or
10236@c stdout redirected... ---doc@cygnus.com, 25feb91
d4f3574e
SS
10237@c
10238@c There's nothing to be done for the "none" part of the DOS MODE
10239@c command. The rest of the parameters should be matched by the
10240@c baudrate, bits, and parity used by the Unix side. ---Eli Zaretskii, 3Sep99
104c1213
JM
10241
10242@kindex EBMON
10243Using the @code{tip} or @code{cu} connection, change the DOS working
10244directory to the directory containing a copy of your 29K program, then
10245start the PC program @code{EBMON} (an EB29K control program supplied
10246with your board by AMD). You should see an initial display from
10247@code{EBMON} similar to the one that follows, ending with the
10248@code{EBMON} prompt @samp{#}---
10249
10250@example
10251C:\> G:
10252
10253G:\> CD \usr\joe\work29k
10254
10255G:\USR\JOE\WORK29K> EBMON
10256Am29000 PC Coprocessor Board Monitor, version 3.0-18
10257Copyright 1990 Advanced Micro Devices, Inc.
10258Written by Gibbons and Associates, Inc.
10259
10260Enter '?' or 'H' for help
10261
10262PC Coprocessor Type = EB29K
10263I/O Base = 0x208
10264Memory Base = 0xd0000
10265
10266Data Memory Size = 2048KB
10267Available I-RAM Range = 0x8000 to 0x1fffff
10268Available D-RAM Range = 0x80002000 to 0x801fffff
10269
10270PageSize = 0x400
10271Register Stack Size = 0x800
10272Memory Stack Size = 0x1800
10273
10274CPU PRL = 0x3
10275Am29027 Available = No
10276Byte Write Available = Yes
10277
10278# ~.
10279@end example
10280
10281Then exit the @code{cu} or @code{tip} program (done in the example by
10282typing @code{~.} at the @code{EBMON} prompt). @code{EBMON} keeps
10283running, ready for @value{GDBN} to take over.
10284
10285For this example, we've assumed what is probably the most convenient
10286way to make sure the same 29K program is on both the PC and the Unix
d4f3574e 10287system: a PC/NFS connection that establishes ``drive @file{G:}'' on the
104c1213
JM
10288PC as a file system on the Unix host. If you do not have PC/NFS or
10289something similar connecting the two systems, you must arrange some
10290other way---perhaps floppy-disk transfer---of getting the 29K program
10291from the Unix system to the PC; @value{GDBN} does @emph{not} download it over the
10292serial line.
10293
6d2ebf8b 10294@node gdb-EB29K
104c1213
JM
10295@subsubsection EB29K cross-debugging
10296
10297Finally, @code{cd} to the directory containing an image of your 29K
10298program on the Unix system, and start @value{GDBN}---specifying as argument the
10299name of your 29K program:
10300
10301@example
10302cd /usr/joe/work29k
10303@value{GDBP} myfoo
10304@end example
10305
10306@need 500
10307Now you can use the @code{target} command:
10308
10309@example
10310target amd-eb /dev/ttya 9600 MYFOO
10311@c FIXME: test above 'target amd-eb' as spelled, with caps! caps are meant to
10312@c emphasize that this is the name as seen by DOS (since I think DOS is
10313@c single-minded about case of letters). ---doc@cygnus.com, 25feb91
10314@end example
10315
10316@noindent
10317In this example, we've assumed your program is in a file called
10318@file{myfoo}. Note that the filename given as the last argument to
10319@code{target amd-eb} should be the name of the program as it appears to DOS.
10320In our example this is simply @code{MYFOO}, but in general it can include
10321a DOS path, and depending on your transfer mechanism may not resemble
10322the name on the Unix side.
10323
10324At this point, you can set any breakpoints you wish; when you are ready
10325to see your program run on the 29K board, use the @value{GDBN} command
10326@code{run}.
10327
10328To stop debugging the remote program, use the @value{GDBN} @code{detach}
10329command.
10330
10331To return control of the PC to its console, use @code{tip} or @code{cu}
10332once again, after your @value{GDBN} session has concluded, to attach to
10333@code{EBMON}. You can then type the command @code{q} to shut down
10334@code{EBMON}, returning control to the DOS command-line interpreter.
d4f3574e 10335Type @kbd{CTTY con} to return command input to the main DOS console,
104c1213
JM
10336and type @kbd{~.} to leave @code{tip} or @code{cu}.
10337
6d2ebf8b 10338@node Remote Log
104c1213
JM
10339@subsubsection Remote log
10340@kindex eb.log
10341@cindex log file for EB29K
10342
10343The @code{target amd-eb} command creates a file @file{eb.log} in the
10344current working directory, to help debug problems with the connection.
10345@file{eb.log} records all the output from @code{EBMON}, including echoes
10346of the commands sent to it. Running @samp{tail -f} on this file in
10347another window often helps to understand trouble with @code{EBMON}, or
10348unexpected events on the PC side of the connection.
10349
6d2ebf8b 10350@node ARM
104c1213
JM
10351@subsection ARM
10352
10353@table @code
10354
10355@kindex target rdi
10356@item target rdi @var{dev}
10357ARM Angel monitor, via RDI library interface to ADP protocol. You may
10358use this target to communicate with both boards running the Angel
10359monitor, or with the EmbeddedICE JTAG debug device.
5d161b24 10360
104c1213
JM
10361@kindex target rdp
10362@item target rdp @var{dev}
10363ARM Demon monitor.
10364
10365@end table
10366
6d2ebf8b 10367@node H8/300
104c1213
JM
10368@subsection Hitachi H8/300
10369
10370@table @code
10371
d4f3574e 10372@kindex target hms@r{, with H8/300}
104c1213
JM
10373@item target hms @var{dev}
10374A Hitachi SH, H8/300, or H8/500 board, attached via serial line to your host.
10375Use special commands @code{device} and @code{speed} to control the serial
10376line and the communications speed used.
10377
d4f3574e 10378@kindex target e7000@r{, with H8/300}
104c1213
JM
10379@item target e7000 @var{dev}
10380E7000 emulator for Hitachi H8 and SH.
10381
d4f3574e
SS
10382@kindex target sh3@r{, with H8/300}
10383@kindex target sh3e@r{, with H8/300}
104c1213 10384@item target sh3 @var{dev}
96a2c332 10385@itemx target sh3e @var{dev}
104c1213
JM
10386Hitachi SH-3 and SH-3E target systems.
10387
10388@end table
10389
10390@cindex download to H8/300 or H8/500
10391@cindex H8/300 or H8/500 download
10392@cindex download to Hitachi SH
10393@cindex Hitachi SH download
10394When you select remote debugging to a Hitachi SH, H8/300, or H8/500
10395board, the @code{load} command downloads your program to the Hitachi
10396board and also opens it as the current executable target for
10397@value{GDBN} on your host (like the @code{file} command).
10398
10399@value{GDBN} needs to know these things to talk to your
5d161b24 10400Hitachi SH, H8/300, or H8/500:
104c1213
JM
10401
10402@enumerate
10403@item
10404that you want to use @samp{target hms}, the remote debugging interface
10405for Hitachi microprocessors, or @samp{target e7000}, the in-circuit
10406emulator for the Hitachi SH and the Hitachi 300H. (@samp{target hms} is
2df3850c 10407the default when @value{GDBN} is configured specifically for the Hitachi SH,
104c1213
JM
10408H8/300, or H8/500.)
10409
10410@item
10411what serial device connects your host to your Hitachi board (the first
10412serial device available on your host is the default).
10413
10414@item
10415what speed to use over the serial device.
10416@end enumerate
10417
10418@menu
10419* Hitachi Boards:: Connecting to Hitachi boards.
10420* Hitachi ICE:: Using the E7000 In-Circuit Emulator.
10421* Hitachi Special:: Special @value{GDBN} commands for Hitachi micros.
10422@end menu
10423
6d2ebf8b 10424@node Hitachi Boards
104c1213
JM
10425@subsubsection Connecting to Hitachi boards
10426
10427@c only for Unix hosts
10428@kindex device
10429@cindex serial device, Hitachi micros
96a2c332 10430Use the special @code{@value{GDBN}} command @samp{device @var{port}} if you
104c1213
JM
10431need to explicitly set the serial device. The default @var{port} is the
10432first available port on your host. This is only necessary on Unix
10433hosts, where it is typically something like @file{/dev/ttya}.
10434
10435@kindex speed
10436@cindex serial line speed, Hitachi micros
96a2c332 10437@code{@value{GDBN}} has another special command to set the communications
104c1213 10438speed: @samp{speed @var{bps}}. This command also is only used from Unix
2df3850c 10439hosts; on DOS hosts, set the line speed as usual from outside @value{GDBN} with
d4f3574e
SS
10440the DOS @code{mode} command (for instance,
10441@w{@kbd{mode com2:9600,n,8,1,p}} for a 9600@dmn{bps} connection).
104c1213
JM
10442
10443The @samp{device} and @samp{speed} commands are available only when you
10444use a Unix host to debug your Hitachi microprocessor programs. If you
10445use a DOS host,
10446@value{GDBN} depends on an auxiliary terminate-and-stay-resident program
10447called @code{asynctsr} to communicate with the development board
10448through a PC serial port. You must also use the DOS @code{mode} command
10449to set up the serial port on the DOS side.
10450
10451The following sample session illustrates the steps needed to start a
10452program under @value{GDBN} control on an H8/300. The example uses a
10453sample H8/300 program called @file{t.x}. The procedure is the same for
10454the Hitachi SH and the H8/500.
10455
10456First hook up your development board. In this example, we use a
10457board attached to serial port @code{COM2}; if you use a different serial
10458port, substitute its name in the argument of the @code{mode} command.
10459When you call @code{asynctsr}, the auxiliary comms program used by the
d4f3574e 10460debugger, you give it just the numeric part of the serial port's name;
104c1213
JM
10461for example, @samp{asyncstr 2} below runs @code{asyncstr} on
10462@code{COM2}.
10463
10464@example
10465C:\H8300\TEST> asynctsr 2
10466C:\H8300\TEST> mode com2:9600,n,8,1,p
10467
10468Resident portion of MODE loaded
10469
10470COM2: 9600, n, 8, 1, p
10471
10472@end example
10473
10474@quotation
10475@emph{Warning:} We have noticed a bug in PC-NFS that conflicts with
10476@code{asynctsr}. If you also run PC-NFS on your DOS host, you may need to
10477disable it, or even boot without it, to use @code{asynctsr} to control
10478your development board.
10479@end quotation
10480
d4f3574e 10481@kindex target hms@r{, and serial protocol}
104c1213
JM
10482Now that serial communications are set up, and the development board is
10483connected, you can start up @value{GDBN}. Call @code{@value{GDBP}} with
96a2c332 10484the name of your program as the argument. @code{@value{GDBN}} prompts
104c1213
JM
10485you, as usual, with the prompt @samp{(@value{GDBP})}. Use two special
10486commands to begin your debugging session: @samp{target hms} to specify
10487cross-debugging to the Hitachi board, and the @code{load} command to
10488download your program to the board. @code{load} displays the names of
10489the program's sections, and a @samp{*} for each 2K of data downloaded.
10490(If you want to refresh @value{GDBN} data on symbols or on the
10491executable file without downloading, use the @value{GDBN} commands
10492@code{file} or @code{symbol-file}. These commands, and @code{load}
10493itself, are described in @ref{Files,,Commands to specify files}.)
10494
10495@smallexample
10496(eg-C:\H8300\TEST) @value{GDBP} t.x
2df3850c 10497@value{GDBN} is free software and you are welcome to distribute copies
5d161b24 10498 of it under certain conditions; type "show copying" to see
104c1213 10499 the conditions.
5d161b24 10500There is absolutely no warranty for @value{GDBN}; type "show warranty"
104c1213 10501for details.
2df3850c
JM
10502@value{GDBN} @value{GDBVN}, Copyright 1992 Free Software Foundation, Inc...
10503(@value{GDBP}) target hms
104c1213 10504Connected to remote H8/300 HMS system.
2df3850c 10505(@value{GDBP}) load t.x
104c1213
JM
10506.text : 0x8000 .. 0xabde ***********
10507.data : 0xabde .. 0xad30 *
10508.stack : 0xf000 .. 0xf014 *
10509@end smallexample
10510
10511At this point, you're ready to run or debug your program. From here on,
10512you can use all the usual @value{GDBN} commands. The @code{break} command
10513sets breakpoints; the @code{run} command starts your program;
10514@code{print} or @code{x} display data; the @code{continue} command
10515resumes execution after stopping at a breakpoint. You can use the
10516@code{help} command at any time to find out more about @value{GDBN} commands.
10517
10518Remember, however, that @emph{operating system} facilities aren't
10519available on your development board; for example, if your program hangs,
10520you can't send an interrupt---but you can press the @sc{reset} switch!
10521
10522Use the @sc{reset} button on the development board
10523@itemize @bullet
10524@item
10525to interrupt your program (don't use @kbd{ctl-C} on the DOS host---it has
10526no way to pass an interrupt signal to the development board); and
10527
10528@item
10529to return to the @value{GDBN} command prompt after your program finishes
10530normally. The communications protocol provides no other way for @value{GDBN}
10531to detect program completion.
10532@end itemize
10533
10534In either case, @value{GDBN} sees the effect of a @sc{reset} on the
10535development board as a ``normal exit'' of your program.
10536
6d2ebf8b 10537@node Hitachi ICE
104c1213
JM
10538@subsubsection Using the E7000 in-circuit emulator
10539
d4f3574e 10540@kindex target e7000@r{, with Hitachi ICE}
104c1213
JM
10541You can use the E7000 in-circuit emulator to develop code for either the
10542Hitachi SH or the H8/300H. Use one of these forms of the @samp{target
10543e7000} command to connect @value{GDBN} to your E7000:
10544
10545@table @code
10546@item target e7000 @var{port} @var{speed}
10547Use this form if your E7000 is connected to a serial port. The
10548@var{port} argument identifies what serial port to use (for example,
10549@samp{com2}). The third argument is the line speed in bits per second
10550(for example, @samp{9600}).
10551
10552@item target e7000 @var{hostname}
10553If your E7000 is installed as a host on a TCP/IP network, you can just
10554specify its hostname; @value{GDBN} uses @code{telnet} to connect.
10555@end table
10556
6d2ebf8b 10557@node Hitachi Special
104c1213
JM
10558@subsubsection Special @value{GDBN} commands for Hitachi micros
10559
10560Some @value{GDBN} commands are available only for the H8/300:
10561
10562@table @code
10563
10564@kindex set machine
10565@kindex show machine
10566@item set machine h8300
10567@itemx set machine h8300h
10568Condition @value{GDBN} for one of the two variants of the H8/300
10569architecture with @samp{set machine}. You can use @samp{show machine}
10570to check which variant is currently in effect.
10571
10572@end table
10573
6d2ebf8b 10574@node H8/500
104c1213
JM
10575@subsection H8/500
10576
10577@table @code
10578
10579@kindex set memory @var{mod}
10580@cindex memory models, H8/500
10581@item set memory @var{mod}
10582@itemx show memory
10583Specify which H8/500 memory model (@var{mod}) you are using with
10584@samp{set memory}; check which memory model is in effect with @samp{show
10585memory}. The accepted values for @var{mod} are @code{small},
10586@code{big}, @code{medium}, and @code{compact}.
10587
10588@end table
10589
6d2ebf8b 10590@node i960
104c1213
JM
10591@subsection Intel i960
10592
10593@table @code
10594
10595@kindex target mon960
10596@item target mon960 @var{dev}
10597MON960 monitor for Intel i960.
10598
10599@item target nindy @var{devicename}
10600An Intel 960 board controlled by a Nindy Monitor. @var{devicename} is
10601the name of the serial device to use for the connection, e.g.
10602@file{/dev/ttya}.
10603
10604@end table
10605
10606@cindex Nindy
10607@cindex i960
10608@dfn{Nindy} is a ROM Monitor program for Intel 960 target systems. When
10609@value{GDBN} is configured to control a remote Intel 960 using Nindy, you can
10610tell @value{GDBN} how to connect to the 960 in several ways:
10611
10612@itemize @bullet
10613@item
10614Through command line options specifying serial port, version of the
10615Nindy protocol, and communications speed;
10616
10617@item
10618By responding to a prompt on startup;
10619
10620@item
10621By using the @code{target} command at any point during your @value{GDBN}
10622session. @xref{Target Commands, ,Commands for managing targets}.
10623
10624@kindex target nindy
10625@item target nindy @var{devicename}
10626An Intel 960 board controlled by a Nindy Monitor. @var{devicename} is
10627the name of the serial device to use for the connection, e.g.
10628@file{/dev/ttya}.
10629
10630@end itemize
10631
10632@cindex download to Nindy-960
10633With the Nindy interface to an Intel 960 board, @code{load}
10634downloads @var{filename} to the 960 as well as adding its symbols in
10635@value{GDBN}.
10636
10637@menu
10638* Nindy Startup:: Startup with Nindy
10639* Nindy Options:: Options for Nindy
10640* Nindy Reset:: Nindy reset command
10641@end menu
10642
6d2ebf8b 10643@node Nindy Startup
104c1213
JM
10644@subsubsection Startup with Nindy
10645
10646If you simply start @code{@value{GDBP}} without using any command-line
10647options, you are prompted for what serial port to use, @emph{before} you
10648reach the ordinary @value{GDBN} prompt:
10649
10650@example
5d161b24 10651Attach /dev/ttyNN -- specify NN, or "quit" to quit:
104c1213
JM
10652@end example
10653
10654@noindent
10655Respond to the prompt with whatever suffix (after @samp{/dev/tty})
10656identifies the serial port you want to use. You can, if you choose,
10657simply start up with no Nindy connection by responding to the prompt
10658with an empty line. If you do this and later wish to attach to Nindy,
10659use @code{target} (@pxref{Target Commands, ,Commands for managing targets}).
10660
6d2ebf8b 10661@node Nindy Options
104c1213
JM
10662@subsubsection Options for Nindy
10663
10664These are the startup options for beginning your @value{GDBN} session with a
10665Nindy-960 board attached:
10666
10667@table @code
10668@item -r @var{port}
10669Specify the serial port name of a serial interface to be used to connect
10670to the target system. This option is only available when @value{GDBN} is
10671configured for the Intel 960 target architecture. You may specify
10672@var{port} as any of: a full pathname (e.g. @samp{-r /dev/ttya}), a
10673device name in @file{/dev} (e.g. @samp{-r ttya}), or simply the unique
10674suffix for a specific @code{tty} (e.g. @samp{-r a}).
10675
10676@item -O
10677(An uppercase letter ``O'', not a zero.) Specify that @value{GDBN} should use
10678the ``old'' Nindy monitor protocol to connect to the target system.
10679This option is only available when @value{GDBN} is configured for the Intel 960
10680target architecture.
10681
10682@quotation
10683@emph{Warning:} if you specify @samp{-O}, but are actually trying to
10684connect to a target system that expects the newer protocol, the connection
10685fails, appearing to be a speed mismatch. @value{GDBN} repeatedly
10686attempts to reconnect at several different line speeds. You can abort
10687this process with an interrupt.
10688@end quotation
10689
10690@item -brk
10691Specify that @value{GDBN} should first send a @code{BREAK} signal to the target
10692system, in an attempt to reset it, before connecting to a Nindy target.
10693
10694@quotation
10695@emph{Warning:} Many target systems do not have the hardware that this
10696requires; it only works with a few boards.
10697@end quotation
10698@end table
10699
10700The standard @samp{-b} option controls the line speed used on the serial
10701port.
10702
10703@c @group
6d2ebf8b 10704@node Nindy Reset
104c1213
JM
10705@subsubsection Nindy reset command
10706
10707@table @code
10708@item reset
10709@kindex reset
10710For a Nindy target, this command sends a ``break'' to the remote target
10711system; this is only useful if the target has been equipped with a
10712circuit to perform a hard reset (or some other interesting action) when
10713a break is detected.
10714@end table
10715@c @end group
10716
6d2ebf8b 10717@node M32R/D
104c1213
JM
10718@subsection Mitsubishi M32R/D
10719
10720@table @code
10721
10722@kindex target m32r
10723@item target m32r @var{dev}
10724Mitsubishi M32R/D ROM monitor.
10725
10726@end table
10727
6d2ebf8b 10728@node M68K
104c1213
JM
10729@subsection M68k
10730
10731The Motorola m68k configuration includes ColdFire support, and
10732target command for the following ROM monitors.
10733
10734@table @code
10735
10736@kindex target abug
10737@item target abug @var{dev}
10738ABug ROM monitor for M68K.
10739
10740@kindex target cpu32bug
10741@item target cpu32bug @var{dev}
10742CPU32BUG monitor, running on a CPU32 (M68K) board.
10743
10744@kindex target dbug
10745@item target dbug @var{dev}
10746dBUG ROM monitor for Motorola ColdFire.
10747
10748@kindex target est
10749@item target est @var{dev}
10750EST-300 ICE monitor, running on a CPU32 (M68K) board.
10751
10752@kindex target rom68k
10753@item target rom68k @var{dev}
10754ROM 68K monitor, running on an M68K IDP board.
10755
10756@end table
10757
10758If @value{GDBN} is configured with @code{m68*-ericsson-*}, it will
10759instead have only a single special target command:
10760
10761@table @code
10762
10763@kindex target es1800
10764@item target es1800 @var{dev}
10765ES-1800 emulator for M68K.
10766
10767@end table
10768
10769[context?]
10770
10771@table @code
10772
10773@kindex target rombug
10774@item target rombug @var{dev}
10775ROMBUG ROM monitor for OS/9000.
10776
10777@end table
10778
6d2ebf8b 10779@node M88K
104c1213
JM
10780@subsection M88K
10781
10782@table @code
10783
10784@kindex target bug
10785@item target bug @var{dev}
10786BUG monitor, running on a MVME187 (m88k) board.
10787
10788@end table
10789
6d2ebf8b 10790@node MIPS Embedded
104c1213
JM
10791@subsection MIPS Embedded
10792
10793@cindex MIPS boards
10794@value{GDBN} can use the MIPS remote debugging protocol to talk to a
10795MIPS board attached to a serial line. This is available when
10796you configure @value{GDBN} with @samp{--target=mips-idt-ecoff}.
10797
10798@need 1000
10799Use these @value{GDBN} commands to specify the connection to your target board:
10800
10801@table @code
10802@item target mips @var{port}
10803@kindex target mips @var{port}
10804To run a program on the board, start up @code{@value{GDBP}} with the
10805name of your program as the argument. To connect to the board, use the
10806command @samp{target mips @var{port}}, where @var{port} is the name of
10807the serial port connected to the board. If the program has not already
10808been downloaded to the board, you may use the @code{load} command to
10809download it. You can then use all the usual @value{GDBN} commands.
10810
10811For example, this sequence connects to the target board through a serial
10812port, and loads and runs a program called @var{prog} through the
10813debugger:
10814
10815@example
10816host$ @value{GDBP} @var{prog}
2df3850c
JM
10817@value{GDBN} is free software and @dots{}
10818(@value{GDBP}) target mips /dev/ttyb
10819(@value{GDBP}) load @var{prog}
10820(@value{GDBP}) run
104c1213
JM
10821@end example
10822
10823@item target mips @var{hostname}:@var{portnumber}
10824On some @value{GDBN} host configurations, you can specify a TCP
10825connection (for instance, to a serial line managed by a terminal
10826concentrator) instead of a serial port, using the syntax
10827@samp{@var{hostname}:@var{portnumber}}.
10828
10829@item target pmon @var{port}
10830@kindex target pmon @var{port}
10831PMON ROM monitor.
10832
10833@item target ddb @var{port}
10834@kindex target ddb @var{port}
10835NEC's DDB variant of PMON for Vr4300.
10836
10837@item target lsi @var{port}
10838@kindex target lsi @var{port}
10839LSI variant of PMON.
10840
10841@kindex target r3900
10842@item target r3900 @var{dev}
10843Densan DVE-R3900 ROM monitor for Toshiba R3900 Mips.
10844
10845@kindex target array
10846@item target array @var{dev}
10847Array Tech LSI33K RAID controller board.
10848
10849@end table
10850
10851
10852@noindent
10853@value{GDBN} also supports these special commands for MIPS targets:
10854
10855@table @code
10856@item set processor @var{args}
10857@itemx show processor
10858@kindex set processor @var{args}
10859@kindex show processor
10860Use the @code{set processor} command to set the type of MIPS
10861processor when you want to access processor-type-specific registers.
5d161b24 10862For example, @code{set processor @var{r3041}} tells @value{GDBN}
104c1213 10863to use the CPO registers appropriate for the 3041 chip.
5d161b24 10864Use the @code{show processor} command to see what MIPS processor @value{GDBN}
104c1213 10865is using. Use the @code{info reg} command to see what registers
5d161b24 10866@value{GDBN} is using.
104c1213
JM
10867
10868@item set mipsfpu double
10869@itemx set mipsfpu single
10870@itemx set mipsfpu none
10871@itemx show mipsfpu
10872@kindex set mipsfpu
10873@kindex show mipsfpu
10874@cindex MIPS remote floating point
10875@cindex floating point, MIPS remote
10876If your target board does not support the MIPS floating point
10877coprocessor, you should use the command @samp{set mipsfpu none} (if you
96a2c332 10878need this, you may wish to put the command in your @value{GDBN} init
104c1213
JM
10879file). This tells @value{GDBN} how to find the return value of
10880functions which return floating point values. It also allows
10881@value{GDBN} to avoid saving the floating point registers when calling
10882functions on the board. If you are using a floating point coprocessor
10883with only single precision floating point support, as on the @sc{r4650}
10884processor, use the command @samp{set mipsfpu single}. The default
10885double precision floating point coprocessor may be selected using
10886@samp{set mipsfpu double}.
10887
10888In previous versions the only choices were double precision or no
10889floating point, so @samp{set mipsfpu on} will select double precision
10890and @samp{set mipsfpu off} will select no floating point.
10891
10892As usual, you can inquire about the @code{mipsfpu} variable with
10893@samp{show mipsfpu}.
10894
10895@item set remotedebug @var{n}
10896@itemx show remotedebug
d4f3574e
SS
10897@kindex set remotedebug@r{, MIPS protocol}
10898@kindex show remotedebug@r{, MIPS protocol}
104c1213
JM
10899@cindex @code{remotedebug}, MIPS protocol
10900@cindex MIPS @code{remotedebug} protocol
10901@c FIXME! For this to be useful, you must know something about the MIPS
10902@c FIXME...protocol. Where is it described?
10903You can see some debugging information about communications with the board
10904by setting the @code{remotedebug} variable. If you set it to @code{1} using
10905@samp{set remotedebug 1}, every packet is displayed. If you set it
10906to @code{2}, every character is displayed. You can check the current value
10907at any time with the command @samp{show remotedebug}.
10908
10909@item set timeout @var{seconds}
10910@itemx set retransmit-timeout @var{seconds}
10911@itemx show timeout
10912@itemx show retransmit-timeout
10913@cindex @code{timeout}, MIPS protocol
10914@cindex @code{retransmit-timeout}, MIPS protocol
10915@kindex set timeout
10916@kindex show timeout
10917@kindex set retransmit-timeout
10918@kindex show retransmit-timeout
10919You can control the timeout used while waiting for a packet, in the MIPS
10920remote protocol, with the @code{set timeout @var{seconds}} command. The
10921default is 5 seconds. Similarly, you can control the timeout used while
10922waiting for an acknowledgement of a packet with the @code{set
10923retransmit-timeout @var{seconds}} command. The default is 3 seconds.
10924You can inspect both values with @code{show timeout} and @code{show
10925retransmit-timeout}. (These commands are @emph{only} available when
10926@value{GDBN} is configured for @samp{--target=mips-idt-ecoff}.)
10927
10928The timeout set by @code{set timeout} does not apply when @value{GDBN}
10929is waiting for your program to stop. In that case, @value{GDBN} waits
10930forever because it has no way of knowing how long the program is going
10931to run before stopping.
10932@end table
10933
6d2ebf8b 10934@node PowerPC
104c1213
JM
10935@subsection PowerPC
10936
10937@table @code
10938
10939@kindex target dink32
10940@item target dink32 @var{dev}
10941DINK32 ROM monitor.
10942
10943@kindex target ppcbug
10944@item target ppcbug @var{dev}
10945@kindex target ppcbug1
10946@item target ppcbug1 @var{dev}
10947PPCBUG ROM monitor for PowerPC.
10948
10949@kindex target sds
10950@item target sds @var{dev}
10951SDS monitor, running on a PowerPC board (such as Motorola's ADS).
10952
10953@end table
10954
6d2ebf8b 10955@node PA
104c1213
JM
10956@subsection HP PA Embedded
10957
10958@table @code
10959
10960@kindex target op50n
10961@item target op50n @var{dev}
10962OP50N monitor, running on an OKI HPPA board.
10963
10964@kindex target w89k
10965@item target w89k @var{dev}
10966W89K monitor, running on a Winbond HPPA board.
10967
10968@end table
10969
6d2ebf8b 10970@node SH
104c1213
JM
10971@subsection Hitachi SH
10972
10973@table @code
10974
d4f3574e 10975@kindex target hms@r{, with Hitachi SH}
104c1213
JM
10976@item target hms @var{dev}
10977A Hitachi SH board attached via serial line to your host. Use special
10978commands @code{device} and @code{speed} to control the serial line and
10979the communications speed used.
10980
d4f3574e 10981@kindex target e7000@r{, with Hitachi SH}
104c1213
JM
10982@item target e7000 @var{dev}
10983E7000 emulator for Hitachi SH.
10984
d4f3574e
SS
10985@kindex target sh3@r{, with SH}
10986@kindex target sh3e@r{, with SH}
104c1213
JM
10987@item target sh3 @var{dev}
10988@item target sh3e @var{dev}
10989Hitachi SH-3 and SH-3E target systems.
10990
10991@end table
10992
6d2ebf8b 10993@node Sparclet
104c1213
JM
10994@subsection Tsqware Sparclet
10995
10996@cindex Sparclet
10997
5d161b24
DB
10998@value{GDBN} enables developers to debug tasks running on
10999Sparclet targets from a Unix host.
104c1213
JM
11000@value{GDBN} uses code that runs on
11001both the Unix host and on the Sparclet target. The program
5d161b24 11002@code{@value{GDBP}} is installed and executed on the Unix host.
104c1213
JM
11003
11004@table @code
11005@item timeout @var{args}
11006@kindex remotetimeout
5d161b24
DB
11007@value{GDBN} supports the option @code{remotetimeout}.
11008This option is set by the user, and @var{args} represents the number of
11009seconds @value{GDBN} waits for responses.
104c1213
JM
11010@end table
11011
11012@kindex Compiling
5d161b24 11013When compiling for debugging, include the options @samp{-g} to get debug
d4f3574e 11014information and @samp{-Ttext} to relocate the program to where you wish to
5d161b24 11015load it on the target. You may also want to add the options @samp{-n} or
d4f3574e 11016@samp{-N} in order to reduce the size of the sections. Example:
104c1213
JM
11017
11018@example
11019sparclet-aout-gcc prog.c -Ttext 0x12010000 -g -o prog -N
11020@end example
11021
d4f3574e 11022You can use @code{objdump} to verify that the addresses are what you intended:
104c1213
JM
11023
11024@example
11025sparclet-aout-objdump --headers --syms prog
11026@end example
11027
11028@kindex Running
11029Once you have set
11030your Unix execution search path to find @value{GDBN}, you are ready to
5d161b24 11031run @value{GDBN}. From your Unix host, run @code{@value{GDBP}}
104c1213
JM
11032(or @code{sparclet-aout-gdb}, depending on your installation).
11033
11034@value{GDBN} comes up showing the prompt:
11035
11036@example
11037(gdbslet)
11038@end example
11039
11040@menu
11041* Sparclet File:: Setting the file to debug
11042* Sparclet Connection:: Connecting to Sparclet
11043* Sparclet Download:: Sparclet download
5d161b24 11044* Sparclet Execution:: Running and debugging
104c1213
JM
11045@end menu
11046
6d2ebf8b 11047@node Sparclet File
104c1213
JM
11048@subsubsection Setting file to debug
11049
11050The @value{GDBN} command @code{file} lets you choose with program to debug.
11051
11052@example
11053(gdbslet) file prog
11054@end example
11055
11056@need 1000
11057@value{GDBN} then attempts to read the symbol table of @file{prog}.
11058@value{GDBN} locates
11059the file by searching the directories listed in the command search
11060path.
11061If the file was compiled with debug information (option "-g"), source
11062files will be searched as well.
11063@value{GDBN} locates
11064the source files by searching the directories listed in the directory search
11065path (@pxref{Environment, ,Your program's environment}).
11066If it fails
11067to find a file, it displays a message such as:
11068
11069@example
11070prog: No such file or directory.
11071@end example
11072
11073When this happens, add the appropriate directories to the search paths with
5d161b24 11074the @value{GDBN} commands @code{path} and @code{dir}, and execute the
104c1213
JM
11075@code{target} command again.
11076
6d2ebf8b 11077@node Sparclet Connection
104c1213
JM
11078@subsubsection Connecting to Sparclet
11079
11080The @value{GDBN} command @code{target} lets you connect to a Sparclet target.
11081To connect to a target on serial port ``@code{ttya}'', type:
11082
11083@example
11084(gdbslet) target sparclet /dev/ttya
11085Remote target sparclet connected to /dev/ttya
5d161b24 11086main () at ../prog.c:3
104c1213
JM
11087@end example
11088
11089@need 750
11090@value{GDBN} displays messages like these:
11091
d4f3574e 11092@example
104c1213 11093Connected to ttya.
d4f3574e 11094@end example
104c1213 11095
6d2ebf8b 11096@node Sparclet Download
104c1213
JM
11097@subsubsection Sparclet download
11098
11099@cindex download to Sparclet
5d161b24 11100Once connected to the Sparclet target,
104c1213
JM
11101you can use the @value{GDBN}
11102@code{load} command to download the file from the host to the target.
11103The file name and load offset should be given as arguments to the @code{load}
11104command.
5d161b24 11105Since the file format is aout, the program must be loaded to the starting
d4f3574e 11106address. You can use @code{objdump} to find out what this value is. The load
104c1213
JM
11107offset is an offset which is added to the VMA (virtual memory address)
11108of each of the file's sections.
11109For instance, if the program
11110@file{prog} was linked to text address 0x1201000, with data at 0x12010160
11111and bss at 0x12010170, in @value{GDBN}, type:
11112
11113@example
11114(gdbslet) load prog 0x12010000
11115Loading section .text, size 0xdb0 vma 0x12010000
11116@end example
11117
5d161b24
DB
11118If the code is loaded at a different address then what the program was linked
11119to, you may need to use the @code{section} and @code{add-symbol-file} commands
104c1213
JM
11120to tell @value{GDBN} where to map the symbol table.
11121
6d2ebf8b 11122@node Sparclet Execution
104c1213
JM
11123@subsubsection Running and debugging
11124
11125@cindex running and debugging Sparclet programs
11126You can now begin debugging the task using @value{GDBN}'s execution control
5d161b24 11127commands, @code{b}, @code{step}, @code{run}, etc. See the @value{GDBN}
104c1213
JM
11128manual for the list of commands.
11129
11130@example
11131(gdbslet) b main
11132Breakpoint 1 at 0x12010000: file prog.c, line 3.
5d161b24 11133(gdbslet) run
104c1213
JM
11134Starting program: prog
11135Breakpoint 1, main (argc=1, argv=0xeffff21c) at prog.c:3
111363 char *symarg = 0;
11137(gdbslet) step
111384 char *execarg = "hello!";
5d161b24 11139(gdbslet)
104c1213
JM
11140@end example
11141
6d2ebf8b 11142@node Sparclite
104c1213
JM
11143@subsection Fujitsu Sparclite
11144
11145@table @code
11146
11147@kindex target sparclite
11148@item target sparclite @var{dev}
5d161b24
DB
11149Fujitsu sparclite boards, used only for the purpose of loading.
11150You must use an additional command to debug the program.
11151For example: target remote @var{dev} using @value{GDBN} standard
104c1213
JM
11152remote protocol.
11153
11154@end table
11155
6d2ebf8b 11156@node ST2000
104c1213
JM
11157@subsection Tandem ST2000
11158
2df3850c 11159@value{GDBN} may be used with a Tandem ST2000 phone switch, running Tandem's
104c1213
JM
11160STDBUG protocol.
11161
11162To connect your ST2000 to the host system, see the manufacturer's
11163manual. Once the ST2000 is physically attached, you can run:
11164
11165@example
11166target st2000 @var{dev} @var{speed}
11167@end example
11168
11169@noindent
11170to establish it as your debugging environment. @var{dev} is normally
11171the name of a serial device, such as @file{/dev/ttya}, connected to the
11172ST2000 via a serial line. You can instead specify @var{dev} as a TCP
11173connection (for example, to a serial line attached via a terminal
11174concentrator) using the syntax @code{@var{hostname}:@var{portnumber}}.
11175
11176The @code{load} and @code{attach} commands are @emph{not} defined for
11177this target; you must load your program into the ST2000 as you normally
11178would for standalone operation. @value{GDBN} reads debugging information
11179(such as symbols) from a separate, debugging version of the program
11180available on your host computer.
11181@c FIXME!! This is terribly vague; what little content is here is
11182@c basically hearsay.
11183
11184@cindex ST2000 auxiliary commands
11185These auxiliary @value{GDBN} commands are available to help you with the ST2000
11186environment:
11187
11188@table @code
11189@item st2000 @var{command}
11190@kindex st2000 @var{cmd}
11191@cindex STDBUG commands (ST2000)
11192@cindex commands to STDBUG (ST2000)
11193Send a @var{command} to the STDBUG monitor. See the manufacturer's
11194manual for available commands.
11195
11196@item connect
11197@cindex connect (to STDBUG)
11198Connect the controlling terminal to the STDBUG command monitor. When
11199you are done interacting with STDBUG, typing either of two character
11200sequences gets you back to the @value{GDBN} command prompt:
11201@kbd{@key{RET}~.} (Return, followed by tilde and period) or
11202@kbd{@key{RET}~@key{C-d}} (Return, followed by tilde and control-D).
11203@end table
11204
6d2ebf8b 11205@node Z8000
104c1213
JM
11206@subsection Zilog Z8000
11207
11208@cindex Z8000
11209@cindex simulator, Z8000
11210@cindex Zilog Z8000 simulator
11211
11212When configured for debugging Zilog Z8000 targets, @value{GDBN} includes
11213a Z8000 simulator.
11214
11215For the Z8000 family, @samp{target sim} simulates either the Z8002 (the
11216unsegmented variant of the Z8000 architecture) or the Z8001 (the
11217segmented variant). The simulator recognizes which architecture is
11218appropriate by inspecting the object code.
11219
11220@table @code
11221@item target sim @var{args}
11222@kindex sim
d4f3574e 11223@kindex target sim@r{, with Z8000}
104c1213
JM
11224Debug programs on a simulated CPU. If the simulator supports setup
11225options, specify them via @var{args}.
11226@end table
11227
11228@noindent
11229After specifying this target, you can debug programs for the simulated
11230CPU in the same style as programs for your host computer; use the
11231@code{file} command to load a new program image, the @code{run} command
11232to run your program, and so on.
11233
d4f3574e
SS
11234As well as making available all the usual machine registers
11235(@pxref{Registers, ,Registers}), the Z8000 simulator provides three
11236additional items of information as specially named registers:
104c1213
JM
11237
11238@table @code
11239
11240@item cycles
11241Counts clock-ticks in the simulator.
11242
11243@item insts
11244Counts instructions run in the simulator.
11245
11246@item time
11247Execution time in 60ths of a second.
11248
11249@end table
11250
11251You can refer to these values in @value{GDBN} expressions with the usual
11252conventions; for example, @w{@samp{b fputc if $cycles>5000}} sets a
11253conditional breakpoint that suspends only after at least 5000
11254simulated clock ticks.
11255
6d2ebf8b 11256@node Architectures
104c1213
JM
11257@section Architectures
11258
11259This section describes characteristics of architectures that affect
2df3850c 11260all uses of @value{GDBN} with the architecture, both native and cross.
104c1213
JM
11261
11262@menu
11263* A29K::
11264* Alpha::
11265* MIPS::
11266@end menu
11267
6d2ebf8b 11268@node A29K
104c1213
JM
11269@subsection A29K
11270
11271@table @code
11272
11273@kindex set rstack_high_address
11274@cindex AMD 29K register stack
11275@cindex register stack, AMD29K
11276@item set rstack_high_address @var{address}
11277On AMD 29000 family processors, registers are saved in a separate
d4f3574e 11278@dfn{register stack}. There is no way for @value{GDBN} to determine the
104c1213
JM
11279extent of this stack. Normally, @value{GDBN} just assumes that the
11280stack is ``large enough''. This may result in @value{GDBN} referencing
11281memory locations that do not exist. If necessary, you can get around
11282this problem by specifying the ending address of the register stack with
11283the @code{set rstack_high_address} command. The argument should be an
11284address, which you probably want to precede with @samp{0x} to specify in
11285hexadecimal.
11286
11287@kindex show rstack_high_address
11288@item show rstack_high_address
11289Display the current limit of the register stack, on AMD 29000 family
11290processors.
11291
11292@end table
11293
6d2ebf8b 11294@node Alpha
104c1213
JM
11295@subsection Alpha
11296
11297See the following section.
11298
6d2ebf8b 11299@node MIPS
104c1213
JM
11300@subsection MIPS
11301
11302@cindex stack on Alpha
11303@cindex stack on MIPS
11304@cindex Alpha stack
11305@cindex MIPS stack
11306Alpha- and MIPS-based computers use an unusual stack frame, which
11307sometimes requires @value{GDBN} to search backward in the object code to
11308find the beginning of a function.
11309
11310@cindex response time, MIPS debugging
11311To improve response time (especially for embedded applications, where
11312@value{GDBN} may be restricted to a slow serial line for this search)
11313you may want to limit the size of this search, using one of these
11314commands:
11315
11316@table @code
11317@cindex @code{heuristic-fence-post} (Alpha,MIPS)
11318@item set heuristic-fence-post @var{limit}
11319Restrict @value{GDBN} to examining at most @var{limit} bytes in its
11320search for the beginning of a function. A value of @var{0} (the
11321default) means there is no limit. However, except for @var{0}, the
11322larger the limit the more bytes @code{heuristic-fence-post} must search
11323and therefore the longer it takes to run.
11324
11325@item show heuristic-fence-post
11326Display the current limit.
11327@end table
11328
11329@noindent
11330These commands are available @emph{only} when @value{GDBN} is configured
11331for debugging programs on Alpha or MIPS processors.
11332
11333
6d2ebf8b 11334@node Controlling GDB
c906108c
SS
11335@chapter Controlling @value{GDBN}
11336
53a5351d
JM
11337You can alter the way @value{GDBN} interacts with you by using the
11338@code{set} command. For commands controlling how @value{GDBN} displays
d4f3574e 11339data, see @ref{Print Settings, ,Print settings}. Other settings are
53a5351d 11340described here.
c906108c
SS
11341
11342@menu
11343* Prompt:: Prompt
11344* Editing:: Command editing
11345* History:: Command history
11346* Screen Size:: Screen size
11347* Numbers:: Numbers
11348* Messages/Warnings:: Optional warnings and messages
5d161b24 11349* Debugging Output:: Optional messages about internal happenings
c906108c
SS
11350@end menu
11351
6d2ebf8b 11352@node Prompt
c906108c
SS
11353@section Prompt
11354
11355@cindex prompt
11356
11357@value{GDBN} indicates its readiness to read a command by printing a string
11358called the @dfn{prompt}. This string is normally @samp{(@value{GDBP})}. You
11359can change the prompt string with the @code{set prompt} command. For
11360instance, when debugging @value{GDBN} with @value{GDBN}, it is useful to change
5d161b24 11361the prompt in one of the @value{GDBN} sessions so that you can always tell
c906108c
SS
11362which one you are talking to.
11363
d4f3574e 11364@emph{Note:} @code{set prompt} does not add a space for you after the
c906108c
SS
11365prompt you set. This allows you to set a prompt which ends in a space
11366or a prompt that does not.
11367
11368@table @code
11369@kindex set prompt
11370@item set prompt @var{newprompt}
11371Directs @value{GDBN} to use @var{newprompt} as its prompt string henceforth.
11372
11373@kindex show prompt
11374@item show prompt
11375Prints a line of the form: @samp{Gdb's prompt is: @var{your-prompt}}
11376@end table
11377
6d2ebf8b 11378@node Editing
c906108c
SS
11379@section Command editing
11380@cindex readline
11381@cindex command line editing
11382
11383@value{GDBN} reads its input commands via the @dfn{readline} interface. This
11384@sc{gnu} library provides consistent behavior for programs which provide a
11385command line interface to the user. Advantages are @sc{gnu} Emacs-style
11386or @dfn{vi}-style inline editing of commands, @code{csh}-like history
11387substitution, and a storage and recall of command history across
11388debugging sessions.
11389
11390You may control the behavior of command line editing in @value{GDBN} with the
11391command @code{set}.
11392
11393@table @code
11394@kindex set editing
11395@cindex editing
11396@item set editing
11397@itemx set editing on
11398Enable command line editing (enabled by default).
11399
11400@item set editing off
11401Disable command line editing.
11402
11403@kindex show editing
11404@item show editing
11405Show whether command line editing is enabled.
11406@end table
11407
6d2ebf8b 11408@node History
c906108c
SS
11409@section Command history
11410
11411@value{GDBN} can keep track of the commands you type during your
11412debugging sessions, so that you can be certain of precisely what
11413happened. Use these commands to manage the @value{GDBN} command
11414history facility.
11415
11416@table @code
11417@cindex history substitution
11418@cindex history file
11419@kindex set history filename
11420@kindex GDBHISTFILE
11421@item set history filename @var{fname}
11422Set the name of the @value{GDBN} command history file to @var{fname}.
11423This is the file where @value{GDBN} reads an initial command history
11424list, and where it writes the command history from this session when it
11425exits. You can access this list through history expansion or through
11426the history command editing characters listed below. This file defaults
11427to the value of the environment variable @code{GDBHISTFILE}, or to
d4f3574e
SS
11428@file{./.gdb_history} (@file{./_gdb_history} on MS-DOS) if this variable
11429is not set.
c906108c
SS
11430
11431@cindex history save
11432@kindex set history save
11433@item set history save
11434@itemx set history save on
11435Record command history in a file, whose name may be specified with the
11436@code{set history filename} command. By default, this option is disabled.
11437
11438@item set history save off
11439Stop recording command history in a file.
11440
11441@cindex history size
11442@kindex set history size
11443@item set history size @var{size}
11444Set the number of commands which @value{GDBN} keeps in its history list.
11445This defaults to the value of the environment variable
11446@code{HISTSIZE}, or to 256 if this variable is not set.
11447@end table
11448
11449@cindex history expansion
11450History expansion assigns special meaning to the character @kbd{!}.
11451@ifset have-readline-appendices
11452@xref{Event Designators}.
11453@end ifset
11454
11455Since @kbd{!} is also the logical not operator in C, history expansion
11456is off by default. If you decide to enable history expansion with the
11457@code{set history expansion on} command, you may sometimes need to
11458follow @kbd{!} (when it is used as logical not, in an expression) with
11459a space or a tab to prevent it from being expanded. The readline
11460history facilities do not attempt substitution on the strings
11461@kbd{!=} and @kbd{!(}, even when history expansion is enabled.
11462
11463The commands to control history expansion are:
11464
11465@table @code
11466@kindex set history expansion
11467@item set history expansion on
11468@itemx set history expansion
11469Enable history expansion. History expansion is off by default.
11470
11471@item set history expansion off
11472Disable history expansion.
11473
11474The readline code comes with more complete documentation of
11475editing and history expansion features. Users unfamiliar with @sc{gnu} Emacs
11476or @code{vi} may wish to read it.
11477@ifset have-readline-appendices
11478@xref{Command Line Editing}.
11479@end ifset
11480
11481@c @group
11482@kindex show history
11483@item show history
11484@itemx show history filename
11485@itemx show history save
11486@itemx show history size
11487@itemx show history expansion
11488These commands display the state of the @value{GDBN} history parameters.
11489@code{show history} by itself displays all four states.
11490@c @end group
11491@end table
11492
11493@table @code
11494@kindex show commands
11495@item show commands
11496Display the last ten commands in the command history.
11497
11498@item show commands @var{n}
11499Print ten commands centered on command number @var{n}.
11500
11501@item show commands +
11502Print ten commands just after the commands last printed.
11503@end table
11504
6d2ebf8b 11505@node Screen Size
c906108c
SS
11506@section Screen size
11507@cindex size of screen
11508@cindex pauses in output
11509
11510Certain commands to @value{GDBN} may produce large amounts of
11511information output to the screen. To help you read all of it,
11512@value{GDBN} pauses and asks you for input at the end of each page of
11513output. Type @key{RET} when you want to continue the output, or @kbd{q}
11514to discard the remaining output. Also, the screen width setting
11515determines when to wrap lines of output. Depending on what is being
11516printed, @value{GDBN} tries to break the line at a readable place,
11517rather than simply letting it overflow onto the following line.
11518
d4f3574e
SS
11519Normally @value{GDBN} knows the size of the screen from the terminal
11520driver software. For example, on Unix @value{GDBN} uses the termcap data base
c906108c 11521together with the value of the @code{TERM} environment variable and the
d4f3574e 11522@code{stty rows} and @code{stty cols} settings. If this is not correct,
c906108c
SS
11523you can override it with the @code{set height} and @code{set
11524width} commands:
11525
11526@table @code
11527@kindex set height
11528@kindex set width
11529@kindex show width
11530@kindex show height
11531@item set height @var{lpp}
11532@itemx show height
11533@itemx set width @var{cpl}
11534@itemx show width
11535These @code{set} commands specify a screen height of @var{lpp} lines and
11536a screen width of @var{cpl} characters. The associated @code{show}
11537commands display the current settings.
11538
5d161b24
DB
11539If you specify a height of zero lines, @value{GDBN} does not pause during
11540output no matter how long the output is. This is useful if output is to a
c906108c
SS
11541file or to an editor buffer.
11542
11543Likewise, you can specify @samp{set width 0} to prevent @value{GDBN}
11544from wrapping its output.
11545@end table
11546
6d2ebf8b 11547@node Numbers
c906108c
SS
11548@section Numbers
11549@cindex number representation
11550@cindex entering numbers
11551
2df3850c
JM
11552You can always enter numbers in octal, decimal, or hexadecimal in
11553@value{GDBN} by the usual conventions: octal numbers begin with
11554@samp{0}, decimal numbers end with @samp{.}, and hexadecimal numbers
11555begin with @samp{0x}. Numbers that begin with none of these are, by
11556default, entered in base 10; likewise, the default display for
11557numbers---when no particular format is specified---is base 10. You can
11558change the default base for both input and output with the @code{set
11559radix} command.
c906108c
SS
11560
11561@table @code
11562@kindex set input-radix
11563@item set input-radix @var{base}
11564Set the default base for numeric input. Supported choices
11565for @var{base} are decimal 8, 10, or 16. @var{base} must itself be
11566specified either unambiguously or using the current default radix; for
11567example, any of
11568
11569@smallexample
11570set radix 012
11571set radix 10.
11572set radix 0xa
11573@end smallexample
11574
11575@noindent
11576sets the base to decimal. On the other hand, @samp{set radix 10}
11577leaves the radix unchanged no matter what it was.
11578
11579@kindex set output-radix
11580@item set output-radix @var{base}
11581Set the default base for numeric display. Supported choices
11582for @var{base} are decimal 8, 10, or 16. @var{base} must itself be
11583specified either unambiguously or using the current default radix.
11584
11585@kindex show input-radix
11586@item show input-radix
11587Display the current default base for numeric input.
11588
11589@kindex show output-radix
11590@item show output-radix
11591Display the current default base for numeric display.
11592@end table
11593
6d2ebf8b 11594@node Messages/Warnings
c906108c
SS
11595@section Optional warnings and messages
11596
2df3850c
JM
11597By default, @value{GDBN} is silent about its inner workings. If you are
11598running on a slow machine, you may want to use the @code{set verbose}
11599command. This makes @value{GDBN} tell you when it does a lengthy
11600internal operation, so you will not think it has crashed.
c906108c
SS
11601
11602Currently, the messages controlled by @code{set verbose} are those
11603which announce that the symbol table for a source file is being read;
11604see @code{symbol-file} in @ref{Files, ,Commands to specify files}.
11605
11606@table @code
11607@kindex set verbose
11608@item set verbose on
11609Enables @value{GDBN} output of certain informational messages.
11610
11611@item set verbose off
11612Disables @value{GDBN} output of certain informational messages.
11613
11614@kindex show verbose
11615@item show verbose
11616Displays whether @code{set verbose} is on or off.
11617@end table
11618
2df3850c
JM
11619By default, if @value{GDBN} encounters bugs in the symbol table of an
11620object file, it is silent; but if you are debugging a compiler, you may
11621find this information useful (@pxref{Symbol Errors, ,Errors reading
11622symbol files}).
c906108c
SS
11623
11624@table @code
2df3850c 11625
c906108c
SS
11626@kindex set complaints
11627@item set complaints @var{limit}
2df3850c
JM
11628Permits @value{GDBN} to output @var{limit} complaints about each type of
11629unusual symbols before becoming silent about the problem. Set
11630@var{limit} to zero to suppress all complaints; set it to a large number
11631to prevent complaints from being suppressed.
c906108c
SS
11632
11633@kindex show complaints
11634@item show complaints
11635Displays how many symbol complaints @value{GDBN} is permitted to produce.
2df3850c 11636
c906108c
SS
11637@end table
11638
11639By default, @value{GDBN} is cautious, and asks what sometimes seems to be a
11640lot of stupid questions to confirm certain commands. For example, if
11641you try to run a program which is already running:
11642
11643@example
11644(@value{GDBP}) run
11645The program being debugged has been started already.
11646Start it from the beginning? (y or n)
11647@end example
11648
11649If you are willing to unflinchingly face the consequences of your own
11650commands, you can disable this ``feature'':
11651
11652@table @code
2df3850c 11653
c906108c
SS
11654@kindex set confirm
11655@cindex flinching
11656@cindex confirmation
11657@cindex stupid questions
11658@item set confirm off
11659Disables confirmation requests.
11660
11661@item set confirm on
11662Enables confirmation requests (the default).
11663
11664@kindex show confirm
11665@item show confirm
11666Displays state of confirmation requests.
2df3850c 11667
c906108c
SS
11668@end table
11669
6d2ebf8b 11670@node Debugging Output
5d161b24
DB
11671@section Optional messages about internal happenings
11672@table @code
11673@kindex set debug arch
11674@item set debug arch
11675Turns on or off display of gdbarch debugging info. The default is off
11676@kindex show debug arch
11677@item show debug arch
11678Displays the current state of displaying gdbarch debugging info.
11679@kindex set debug event
11680@item set debug event
11681Turns on or off display of @value{GDBN} event debugging info. The
11682default is off.
11683@kindex show debug event
11684@item show debug event
11685Displays the current state of displaying @value{GDBN} event debugging
11686info.
11687@kindex set debug expression
11688@item set debug expression
11689Turns on or off display of @value{GDBN} expression debugging info. The
11690default is off.
11691@kindex show debug expression
11692@item show debug expression
11693Displays the current state of displaying @value{GDBN} expression
11694debugging info.
11695@kindex set debug overload
11696@item set debug overload
11697Turns on or off display of @value{GDBN} C++ overload debugging
11698info. This includes info such as ranking of functions, etc. The default
11699is off.
11700@kindex show debug overload
11701@item show debug overload
11702Displays the current state of displaying @value{GDBN} C++ overload
11703debugging info.
11704@kindex set debug remote
11705@cindex packets, reporting on stdout
11706@cindex serial connections, debugging
11707@item set debug remote
11708Turns on or off display of reports on all packets sent back and forth across
11709the serial line to the remote machine. The info is printed on the
11710@value{GDBN} standard output stream. The default is off.
11711@kindex show debug remote
11712@item show debug remote
11713Displays the state of display of remote packets.
11714@kindex set debug serial
11715@item set debug serial
11716Turns on or off display of @value{GDBN} serial debugging info. The
11717default is off.
11718@kindex show debug serial
11719@item show debug serial
11720Displays the current state of displaying @value{GDBN} serial debugging
11721info.
11722@kindex set debug target
11723@item set debug target
11724Turns on or off display of @value{GDBN} target debugging info. This info
11725includes what is going on at the target level of GDB, as it happens. The
11726default is off.
11727@kindex show debug target
11728@item show debug target
11729Displays the current state of displaying @value{GDBN} target debugging
11730info.
11731@kindex set debug varobj
11732@item set debug varobj
11733Turns on or off display of @value{GDBN} variable object debugging
11734info. The default is off.
11735@kindex show debug varobj
11736@item show debug varobj
11737Displays the current state of displaying @value{GDBN} variable object
11738debugging info.
11739@end table
11740
6d2ebf8b 11741@node Sequences
c906108c
SS
11742@chapter Canned Sequences of Commands
11743
11744Aside from breakpoint commands (@pxref{Break Commands, ,Breakpoint
2df3850c
JM
11745command lists}), @value{GDBN} provides two ways to store sequences of
11746commands for execution as a unit: user-defined commands and command
11747files.
c906108c
SS
11748
11749@menu
11750* Define:: User-defined commands
11751* Hooks:: User-defined command hooks
11752* Command Files:: Command files
11753* Output:: Commands for controlled output
11754@end menu
11755
6d2ebf8b 11756@node Define
c906108c
SS
11757@section User-defined commands
11758
11759@cindex user-defined command
2df3850c
JM
11760A @dfn{user-defined command} is a sequence of @value{GDBN} commands to
11761which you assign a new name as a command. This is done with the
11762@code{define} command. User commands may accept up to 10 arguments
11763separated by whitespace. Arguments are accessed within the user command
11764via @var{$arg0@dots{}$arg9}. A trivial example:
c906108c
SS
11765
11766@smallexample
11767define adder
11768 print $arg0 + $arg1 + $arg2
11769@end smallexample
11770
d4f3574e
SS
11771@noindent
11772To execute the command use:
c906108c
SS
11773
11774@smallexample
11775adder 1 2 3
11776@end smallexample
11777
d4f3574e
SS
11778@noindent
11779This defines the command @code{adder}, which prints the sum of
5d161b24 11780its three arguments. Note the arguments are text substitutions, so they may
c906108c
SS
11781reference variables, use complex expressions, or even perform inferior
11782functions calls.
11783
11784@table @code
2df3850c 11785
c906108c
SS
11786@kindex define
11787@item define @var{commandname}
11788Define a command named @var{commandname}. If there is already a command
11789by that name, you are asked to confirm that you want to redefine it.
11790
11791The definition of the command is made up of other @value{GDBN} command lines,
11792which are given following the @code{define} command. The end of these
11793commands is marked by a line containing @code{end}.
11794
11795@kindex if
11796@kindex else
11797@item if
11798Takes a single argument, which is an expression to evaluate.
11799It is followed by a series of commands that are executed
11800only if the expression is true (nonzero).
11801There can then optionally be a line @code{else}, followed
11802by a series of commands that are only executed if the expression
11803was false. The end of the list is marked by a line containing @code{end}.
11804
11805@kindex while
11806@item while
11807The syntax is similar to @code{if}: the command takes a single argument,
11808which is an expression to evaluate, and must be followed by the commands to
11809execute, one per line, terminated by an @code{end}.
11810The commands are executed repeatedly as long as the expression
11811evaluates to true.
11812
11813@kindex document
11814@item document @var{commandname}
11815Document the user-defined command @var{commandname}, so that it can be
5d161b24
DB
11816accessed by @code{help}. The command @var{commandname} must already be
11817defined. This command reads lines of documentation just as @code{define}
11818reads the lines of the command definition, ending with @code{end}.
11819After the @code{document} command is finished, @code{help} on command
c906108c
SS
11820@var{commandname} displays the documentation you have written.
11821
11822You may use the @code{document} command again to change the
11823documentation of a command. Redefining the command with @code{define}
11824does not change the documentation.
11825
11826@kindex help user-defined
11827@item help user-defined
11828List all user-defined commands, with the first line of the documentation
11829(if any) for each.
11830
11831@kindex show user
11832@item show user
11833@itemx show user @var{commandname}
2df3850c
JM
11834Display the @value{GDBN} commands used to define @var{commandname} (but
11835not its documentation). If no @var{commandname} is given, display the
c906108c 11836definitions for all user-defined commands.
2df3850c 11837
c906108c
SS
11838@end table
11839
11840When user-defined commands are executed, the
11841commands of the definition are not printed. An error in any command
11842stops execution of the user-defined command.
11843
11844If used interactively, commands that would ask for confirmation proceed
5d161b24
DB
11845without asking when used inside a user-defined command. Many @value{GDBN}
11846commands that normally print messages to say what they are doing omit the
c906108c
SS
11847messages when used in a user-defined command.
11848
6d2ebf8b 11849@node Hooks
c906108c 11850@section User-defined command hooks
d4f3574e
SS
11851@cindex command hooks
11852@cindex hooks, for commands
c906108c
SS
11853
11854You may define @emph{hooks}, which are a special kind of user-defined
11855command. Whenever you run the command @samp{foo}, if the user-defined
11856command @samp{hook-foo} exists, it is executed (with no arguments)
11857before that command.
11858
d4f3574e 11859@kindex stop@r{, a pseudo-command}
c906108c
SS
11860In addition, a pseudo-command, @samp{stop} exists. Defining
11861(@samp{hook-stop}) makes the associated commands execute every time
11862execution stops in your program: before breakpoint commands are run,
11863displays are printed, or the stack frame is printed.
11864
c906108c
SS
11865For example, to ignore @code{SIGALRM} signals while
11866single-stepping, but treat them normally during normal execution,
11867you could define:
11868
11869@example
11870define hook-stop
11871handle SIGALRM nopass
11872end
11873
11874define hook-run
11875handle SIGALRM pass
11876end
11877
11878define hook-continue
11879handle SIGLARM pass
11880end
11881@end example
c906108c
SS
11882
11883You can define a hook for any single-word command in @value{GDBN}, but
11884not for command aliases; you should define a hook for the basic command
11885name, e.g. @code{backtrace} rather than @code{bt}.
11886@c FIXME! So how does Joe User discover whether a command is an alias
11887@c or not?
11888If an error occurs during the execution of your hook, execution of
11889@value{GDBN} commands stops and @value{GDBN} issues a prompt
11890(before the command that you actually typed had a chance to run).
11891
11892If you try to define a hook which does not match any known command, you
11893get a warning from the @code{define} command.
11894
6d2ebf8b 11895@node Command Files
c906108c
SS
11896@section Command files
11897
11898@cindex command files
5d161b24
DB
11899A command file for @value{GDBN} is a file of lines that are @value{GDBN}
11900commands. Comments (lines starting with @kbd{#}) may also be included.
11901An empty line in a command file does nothing; it does not mean to repeat
c906108c
SS
11902the last command, as it would from the terminal.
11903
11904@cindex init file
11905@cindex @file{.gdbinit}
d4f3574e 11906@cindex @file{gdb.ini}
c906108c
SS
11907When you start @value{GDBN}, it automatically executes commands from its
11908@dfn{init files}. These are files named @file{.gdbinit} on Unix, or
11909@file{gdb.ini} on DOS/Windows. @value{GDBN} reads the init file (if
d4f3574e 11910any) in your home directory@footnote{On DOS/Windows systems, the home
2df3850c
JM
11911directory is the one pointed to by the @code{HOME} environment
11912variable.}, then processes command line options and operands, and then
11913reads the init file (if any) in the current working directory. This is
11914so the init file in your home directory can set options (such as
11915@code{set complaints}) which affect the processing of the command line
11916options and operands. The init files are not executed if you use the
11917@samp{-nx} option; @pxref{Mode Options, ,Choosing modes}.
c906108c 11918
c906108c
SS
11919@cindex init file name
11920On some configurations of @value{GDBN}, the init file is known by a
11921different name (these are typically environments where a specialized
11922form of @value{GDBN} may need to coexist with other forms, hence a
11923different name for the specialized version's init file). These are the
11924environments with special init file names:
11925
11926@kindex .vxgdbinit
11927@itemize @bullet
11928@item
11929VxWorks (Wind River Systems real-time OS): @samp{.vxgdbinit}
11930
11931@kindex .os68gdbinit
11932@item
11933OS68K (Enea Data Systems real-time OS): @samp{.os68gdbinit}
11934
11935@kindex .esgdbinit
11936@item
11937ES-1800 (Ericsson Telecom AB M68000 emulator): @samp{.esgdbinit}
11938@end itemize
c906108c
SS
11939
11940You can also request the execution of a command file with the
11941@code{source} command:
11942
11943@table @code
11944@kindex source
11945@item source @var{filename}
11946Execute the command file @var{filename}.
11947@end table
11948
11949The lines in a command file are executed sequentially. They are not
11950printed as they are executed. An error in any command terminates execution
11951of the command file.
11952
11953Commands that would ask for confirmation if used interactively proceed
11954without asking when used in a command file. Many @value{GDBN} commands that
11955normally print messages to say what they are doing omit the messages
11956when called from command files.
11957
6d2ebf8b 11958@node Output
c906108c
SS
11959@section Commands for controlled output
11960
11961During the execution of a command file or a user-defined command, normal
11962@value{GDBN} output is suppressed; the only output that appears is what is
11963explicitly printed by the commands in the definition. This section
11964describes three commands useful for generating exactly the output you
11965want.
11966
11967@table @code
11968@kindex echo
11969@item echo @var{text}
11970@c I do not consider backslash-space a standard C escape sequence
11971@c because it is not in ANSI.
11972Print @var{text}. Nonprinting characters can be included in
11973@var{text} using C escape sequences, such as @samp{\n} to print a
11974newline. @strong{No newline is printed unless you specify one.}
11975In addition to the standard C escape sequences, a backslash followed
11976by a space stands for a space. This is useful for displaying a
11977string with spaces at the beginning or the end, since leading and
5d161b24 11978trailing spaces are otherwise trimmed from all arguments.
c906108c
SS
11979To print @samp{@w{ }and foo =@w{ }}, use the command
11980@samp{echo \@w{ }and foo = \@w{ }}.
11981
11982A backslash at the end of @var{text} can be used, as in C, to continue
11983the command onto subsequent lines. For example,
11984
11985@example
11986echo This is some text\n\
11987which is continued\n\
11988onto several lines.\n
11989@end example
11990
11991produces the same output as
11992
11993@example
11994echo This is some text\n
11995echo which is continued\n
11996echo onto several lines.\n
11997@end example
11998
11999@kindex output
12000@item output @var{expression}
12001Print the value of @var{expression} and nothing but that value: no
12002newlines, no @samp{$@var{nn} = }. The value is not entered in the
5d161b24 12003value history either. @xref{Expressions, ,Expressions}, for more information
c906108c
SS
12004on expressions.
12005
12006@item output/@var{fmt} @var{expression}
12007Print the value of @var{expression} in format @var{fmt}. You can use
12008the same formats as for @code{print}. @xref{Output Formats,,Output
12009formats}, for more information.
12010
12011@kindex printf
12012@item printf @var{string}, @var{expressions}@dots{}
12013Print the values of the @var{expressions} under the control of
12014@var{string}. The @var{expressions} are separated by commas and may be
12015either numbers or pointers. Their values are printed as specified by
12016@var{string}, exactly as if your program were to execute the C
12017subroutine
d4f3574e
SS
12018@c FIXME: the above implies that at least all ANSI C formats are
12019@c supported, but it isn't true: %E and %G don't work (or so it seems).
12020@c Either this is a bug, or the manual should document what formats are
12021@c supported.
c906108c
SS
12022
12023@example
12024printf (@var{string}, @var{expressions}@dots{});
12025@end example
12026
12027For example, you can print two values in hex like this:
12028
12029@smallexample
12030printf "foo, bar-foo = 0x%x, 0x%x\n", foo, bar-foo
12031@end smallexample
12032
12033The only backslash-escape sequences that you can use in the format
12034string are the simple ones that consist of backslash followed by a
12035letter.
12036@end table
12037
6d2ebf8b 12038@node Emacs
c906108c
SS
12039@chapter Using @value{GDBN} under @sc{gnu} Emacs
12040
12041@cindex Emacs
12042@cindex @sc{gnu} Emacs
12043A special interface allows you to use @sc{gnu} Emacs to view (and
12044edit) the source files for the program you are debugging with
12045@value{GDBN}.
12046
12047To use this interface, use the command @kbd{M-x gdb} in Emacs. Give the
12048executable file you want to debug as an argument. This command starts
12049@value{GDBN} as a subprocess of Emacs, with input and output through a newly
12050created Emacs buffer.
53a5351d 12051@c (Do not use the @code{-tui} option to run @value{GDBN} from Emacs.)
c906108c
SS
12052
12053Using @value{GDBN} under Emacs is just like using @value{GDBN} normally except for two
12054things:
12055
12056@itemize @bullet
12057@item
12058All ``terminal'' input and output goes through the Emacs buffer.
12059@end itemize
12060
12061This applies both to @value{GDBN} commands and their output, and to the input
12062and output done by the program you are debugging.
12063
12064This is useful because it means that you can copy the text of previous
12065commands and input them again; you can even use parts of the output
12066in this way.
12067
12068All the facilities of Emacs' Shell mode are available for interacting
12069with your program. In particular, you can send signals the usual
12070way---for example, @kbd{C-c C-c} for an interrupt, @kbd{C-c C-z} for a
12071stop.
12072
12073@itemize @bullet
12074@item
12075@value{GDBN} displays source code through Emacs.
12076@end itemize
12077
12078Each time @value{GDBN} displays a stack frame, Emacs automatically finds the
12079source file for that frame and puts an arrow (@samp{=>}) at the
12080left margin of the current line. Emacs uses a separate buffer for
12081source display, and splits the screen to show both your @value{GDBN} session
12082and the source.
12083
12084Explicit @value{GDBN} @code{list} or search commands still produce output as
12085usual, but you probably have no reason to use them from Emacs.
12086
12087@quotation
12088@emph{Warning:} If the directory where your program resides is not your
12089current directory, it can be easy to confuse Emacs about the location of
12090the source files, in which case the auxiliary display buffer does not
12091appear to show your source. @value{GDBN} can find programs by searching your
12092environment's @code{PATH} variable, so the @value{GDBN} input and output
12093session proceeds normally; but Emacs does not get enough information
12094back from @value{GDBN} to locate the source files in this situation. To
12095avoid this problem, either start @value{GDBN} mode from the directory where
12096your program resides, or specify an absolute file name when prompted for the
12097@kbd{M-x gdb} argument.
12098
12099A similar confusion can result if you use the @value{GDBN} @code{file} command to
12100switch to debugging a program in some other location, from an existing
12101@value{GDBN} buffer in Emacs.
12102@end quotation
12103
12104By default, @kbd{M-x gdb} calls the program called @file{gdb}. If
12105you need to call @value{GDBN} by a different name (for example, if you keep
12106several configurations around, with different names) you can set the
12107Emacs variable @code{gdb-command-name}; for example,
12108
12109@example
12110(setq gdb-command-name "mygdb")
12111@end example
12112
12113@noindent
d4f3574e 12114(preceded by @kbd{M-:} or @kbd{ESC :}, or typed in the @code{*scratch*} buffer, or
c906108c
SS
12115in your @file{.emacs} file) makes Emacs call the program named
12116``@code{mygdb}'' instead.
12117
12118In the @value{GDBN} I/O buffer, you can use these special Emacs commands in
12119addition to the standard Shell mode commands:
12120
12121@table @kbd
12122@item C-h m
12123Describe the features of Emacs' @value{GDBN} Mode.
12124
12125@item M-s
12126Execute to another source line, like the @value{GDBN} @code{step} command; also
12127update the display window to show the current file and location.
12128
12129@item M-n
12130Execute to next source line in this function, skipping all function
12131calls, like the @value{GDBN} @code{next} command. Then update the display window
12132to show the current file and location.
12133
12134@item M-i
12135Execute one instruction, like the @value{GDBN} @code{stepi} command; update
12136display window accordingly.
12137
12138@item M-x gdb-nexti
12139Execute to next instruction, using the @value{GDBN} @code{nexti} command; update
12140display window accordingly.
12141
12142@item C-c C-f
12143Execute until exit from the selected stack frame, like the @value{GDBN}
12144@code{finish} command.
12145
12146@item M-c
12147Continue execution of your program, like the @value{GDBN} @code{continue}
12148command.
12149
12150@emph{Warning:} In Emacs v19, this command is @kbd{C-c C-p}.
12151
12152@item M-u
12153Go up the number of frames indicated by the numeric argument
12154(@pxref{Arguments, , Numeric Arguments, Emacs, The @sc{gnu} Emacs Manual}),
12155like the @value{GDBN} @code{up} command.
12156
12157@emph{Warning:} In Emacs v19, this command is @kbd{C-c C-u}.
12158
12159@item M-d
12160Go down the number of frames indicated by the numeric argument, like the
12161@value{GDBN} @code{down} command.
12162
12163@emph{Warning:} In Emacs v19, this command is @kbd{C-c C-d}.
12164
12165@item C-x &
12166Read the number where the cursor is positioned, and insert it at the end
12167of the @value{GDBN} I/O buffer. For example, if you wish to disassemble code
12168around an address that was displayed earlier, type @kbd{disassemble};
12169then move the cursor to the address display, and pick up the
12170argument for @code{disassemble} by typing @kbd{C-x &}.
12171
12172You can customize this further by defining elements of the list
12173@code{gdb-print-command}; once it is defined, you can format or
12174otherwise process numbers picked up by @kbd{C-x &} before they are
12175inserted. A numeric argument to @kbd{C-x &} indicates that you
12176wish special formatting, and also acts as an index to pick an element of the
12177list. If the list element is a string, the number to be inserted is
12178formatted using the Emacs function @code{format}; otherwise the number
12179is passed as an argument to the corresponding list element.
12180@end table
12181
12182In any source file, the Emacs command @kbd{C-x SPC} (@code{gdb-break})
12183tells @value{GDBN} to set a breakpoint on the source line point is on.
12184
12185If you accidentally delete the source-display buffer, an easy way to get
12186it back is to type the command @code{f} in the @value{GDBN} buffer, to
12187request a frame display; when you run under Emacs, this recreates
12188the source buffer if necessary to show you the context of the current
12189frame.
12190
12191The source files displayed in Emacs are in ordinary Emacs buffers
12192which are visiting the source files in the usual way. You can edit
12193the files with these buffers if you wish; but keep in mind that @value{GDBN}
12194communicates with Emacs in terms of line numbers. If you add or
12195delete lines from the text, the line numbers that @value{GDBN} knows cease
12196to correspond properly with the code.
12197
12198@c The following dropped because Epoch is nonstandard. Reactivate
12199@c if/when v19 does something similar. ---doc@cygnus.com 19dec1990
12200@ignore
12201@kindex Emacs Epoch environment
12202@kindex Epoch
12203@kindex inspect
12204
5d161b24 12205Version 18 of @sc{gnu} Emacs has a built-in window system
c906108c
SS
12206called the @code{epoch}
12207environment. Users of this environment can use a new command,
12208@code{inspect} which performs identically to @code{print} except that
12209each value is printed in its own window.
12210@end ignore
c906108c 12211
d700128c
EZ
12212@include annotate.texi
12213
6d2ebf8b 12214@node GDB Bugs
c906108c
SS
12215@chapter Reporting Bugs in @value{GDBN}
12216@cindex bugs in @value{GDBN}
12217@cindex reporting bugs in @value{GDBN}
12218
12219Your bug reports play an essential role in making @value{GDBN} reliable.
12220
12221Reporting a bug may help you by bringing a solution to your problem, or it
12222may not. But in any case the principal function of a bug report is to help
12223the entire community by making the next version of @value{GDBN} work better. Bug
12224reports are your contribution to the maintenance of @value{GDBN}.
12225
12226In order for a bug report to serve its purpose, you must include the
12227information that enables us to fix the bug.
12228
12229@menu
12230* Bug Criteria:: Have you found a bug?
12231* Bug Reporting:: How to report bugs
12232@end menu
12233
6d2ebf8b 12234@node Bug Criteria
c906108c
SS
12235@section Have you found a bug?
12236@cindex bug criteria
12237
12238If you are not sure whether you have found a bug, here are some guidelines:
12239
12240@itemize @bullet
12241@cindex fatal signal
12242@cindex debugger crash
12243@cindex crash of debugger
12244@item
12245If the debugger gets a fatal signal, for any input whatever, that is a
12246@value{GDBN} bug. Reliable debuggers never crash.
12247
12248@cindex error on valid input
12249@item
12250If @value{GDBN} produces an error message for valid input, that is a
12251bug. (Note that if you're cross debugging, the problem may also be
12252somewhere in the connection to the target.)
12253
12254@cindex invalid input
12255@item
12256If @value{GDBN} does not produce an error message for invalid input,
12257that is a bug. However, you should note that your idea of
12258``invalid input'' might be our idea of ``an extension'' or ``support
12259for traditional practice''.
12260
12261@item
12262If you are an experienced user of debugging tools, your suggestions
12263for improvement of @value{GDBN} are welcome in any case.
12264@end itemize
12265
6d2ebf8b 12266@node Bug Reporting
c906108c
SS
12267@section How to report bugs
12268@cindex bug reports
12269@cindex @value{GDBN} bugs, reporting
12270
c906108c
SS
12271A number of companies and individuals offer support for @sc{gnu} products.
12272If you obtained @value{GDBN} from a support organization, we recommend you
12273contact that organization first.
12274
12275You can find contact information for many support companies and
12276individuals in the file @file{etc/SERVICE} in the @sc{gnu} Emacs
12277distribution.
12278@c should add a web page ref...
12279
12280In any event, we also recommend that you send bug reports for
12281@value{GDBN} to this addresses:
12282
12283@example
d4f3574e 12284bug-gdb@@gnu.org
c906108c
SS
12285@end example
12286
12287@strong{Do not send bug reports to @samp{info-gdb}, or to
d4f3574e 12288@samp{help-gdb}, or to any newsgroups.} Most users of @value{GDBN} do
c906108c
SS
12289not want to receive bug reports. Those that do have arranged to receive
12290@samp{bug-gdb}.
12291
12292The mailing list @samp{bug-gdb} has a newsgroup @samp{gnu.gdb.bug} which
12293serves as a repeater. The mailing list and the newsgroup carry exactly
12294the same messages. Often people think of posting bug reports to the
12295newsgroup instead of mailing them. This appears to work, but it has one
12296problem which can be crucial: a newsgroup posting often lacks a mail
12297path back to the sender. Thus, if we need to ask for more information,
12298we may be unable to reach you. For this reason, it is better to send
12299bug reports to the mailing list.
12300
12301As a last resort, send bug reports on paper to:
12302
12303@example
12304@sc{gnu} Debugger Bugs
12305Free Software Foundation Inc.
1230659 Temple Place - Suite 330
12307Boston, MA 02111-1307
12308USA
12309@end example
c906108c
SS
12310
12311The fundamental principle of reporting bugs usefully is this:
12312@strong{report all the facts}. If you are not sure whether to state a
12313fact or leave it out, state it!
12314
12315Often people omit facts because they think they know what causes the
12316problem and assume that some details do not matter. Thus, you might
12317assume that the name of the variable you use in an example does not matter.
12318Well, probably it does not, but one cannot be sure. Perhaps the bug is a
12319stray memory reference which happens to fetch from the location where that
12320name is stored in memory; perhaps, if the name were different, the contents
12321of that location would fool the debugger into doing the right thing despite
12322the bug. Play it safe and give a specific, complete example. That is the
12323easiest thing for you to do, and the most helpful.
12324
12325Keep in mind that the purpose of a bug report is to enable us to fix the
12326bug. It may be that the bug has been reported previously, but neither
12327you nor we can know that unless your bug report is complete and
12328self-contained.
12329
12330Sometimes people give a few sketchy facts and ask, ``Does this ring a
12331bell?'' Those bug reports are useless, and we urge everyone to
12332@emph{refuse to respond to them} except to chide the sender to report
12333bugs properly.
12334
12335To enable us to fix the bug, you should include all these things:
12336
12337@itemize @bullet
12338@item
12339The version of @value{GDBN}. @value{GDBN} announces it if you start
12340with no arguments; you can also print it at any time using @code{show
12341version}.
12342
12343Without this, we will not know whether there is any point in looking for
12344the bug in the current version of @value{GDBN}.
12345
12346@item
12347The type of machine you are using, and the operating system name and
12348version number.
12349
c906108c
SS
12350@item
12351What compiler (and its version) was used to compile @value{GDBN}---e.g.
12352``@value{GCC}--2.8.1''.
c906108c
SS
12353
12354@item
12355What compiler (and its version) was used to compile the program you are
12356debugging---e.g. ``@value{GCC}--2.8.1'', or ``HP92453-01 A.10.32.03 HP
12357C Compiler''. For GCC, you can say @code{gcc --version} to get this
12358information; for other compilers, see the documentation for those
12359compilers.
12360
12361@item
12362The command arguments you gave the compiler to compile your example and
12363observe the bug. For example, did you use @samp{-O}? To guarantee
12364you will not omit something important, list them all. A copy of the
12365Makefile (or the output from make) is sufficient.
12366
12367If we were to try to guess the arguments, we would probably guess wrong
12368and then we might not encounter the bug.
12369
12370@item
12371A complete input script, and all necessary source files, that will
12372reproduce the bug.
12373
12374@item
12375A description of what behavior you observe that you believe is
12376incorrect. For example, ``It gets a fatal signal.''
12377
12378Of course, if the bug is that @value{GDBN} gets a fatal signal, then we
12379will certainly notice it. But if the bug is incorrect output, we might
12380not notice unless it is glaringly wrong. You might as well not give us
12381a chance to make a mistake.
12382
12383Even if the problem you experience is a fatal signal, you should still
12384say so explicitly. Suppose something strange is going on, such as, your
12385copy of @value{GDBN} is out of synch, or you have encountered a bug in
12386the C library on your system. (This has happened!) Your copy might
12387crash and ours would not. If you told us to expect a crash, then when
12388ours fails to crash, we would know that the bug was not happening for
12389us. If you had not told us to expect a crash, then we would not be able
12390to draw any conclusion from our observations.
12391
c906108c
SS
12392@item
12393If you wish to suggest changes to the @value{GDBN} source, send us context
12394diffs. If you even discuss something in the @value{GDBN} source, refer to
12395it by context, not by line number.
12396
12397The line numbers in our development sources will not match those in your
12398sources. Your line numbers would convey no useful information to us.
53a5351d 12399
c906108c
SS
12400@end itemize
12401
12402Here are some things that are not necessary:
12403
12404@itemize @bullet
12405@item
12406A description of the envelope of the bug.
12407
12408Often people who encounter a bug spend a lot of time investigating
12409which changes to the input file will make the bug go away and which
12410changes will not affect it.
12411
12412This is often time consuming and not very useful, because the way we
12413will find the bug is by running a single example under the debugger
12414with breakpoints, not by pure deduction from a series of examples.
12415We recommend that you save your time for something else.
12416
12417Of course, if you can find a simpler example to report @emph{instead}
12418of the original one, that is a convenience for us. Errors in the
12419output will be easier to spot, running under the debugger will take
12420less time, and so on.
12421
12422However, simplification is not vital; if you do not want to do this,
12423report the bug anyway and send us the entire test case you used.
12424
12425@item
12426A patch for the bug.
12427
12428A patch for the bug does help us if it is a good one. But do not omit
12429the necessary information, such as the test case, on the assumption that
12430a patch is all we need. We might see problems with your patch and decide
12431to fix the problem another way, or we might not understand it at all.
12432
12433Sometimes with a program as complicated as @value{GDBN} it is very hard to
12434construct an example that will make the program follow a certain path
12435through the code. If you do not send us the example, we will not be able
12436to construct one, so we will not be able to verify that the bug is fixed.
12437
12438And if we cannot understand what bug you are trying to fix, or why your
12439patch should be an improvement, we will not install it. A test case will
12440help us to understand.
12441
12442@item
12443A guess about what the bug is or what it depends on.
12444
12445Such guesses are usually wrong. Even we cannot guess right about such
12446things without first using the debugger to find the facts.
12447@end itemize
12448
5d161b24 12449@c The readline documentation is distributed with the readline code
c906108c
SS
12450@c and consists of the two following files:
12451@c rluser.texinfo
7be570e7 12452@c inc-hist.texinfo
c906108c
SS
12453@c Use -I with makeinfo to point to the appropriate directory,
12454@c environment var TEXINPUTS with TeX.
12455@include rluser.texinfo
7be570e7 12456@include inc-hist.texinfo
c906108c
SS
12457
12458
6d2ebf8b 12459@node Formatting Documentation
c906108c
SS
12460@appendix Formatting Documentation
12461
12462@cindex @value{GDBN} reference card
12463@cindex reference card
12464The @value{GDBN} 4 release includes an already-formatted reference card, ready
12465for printing with PostScript or Ghostscript, in the @file{gdb}
12466subdirectory of the main source directory@footnote{In
12467@file{gdb-@value{GDBVN}/gdb/refcard.ps} of the version @value{GDBVN}
12468release.}. If you can use PostScript or Ghostscript with your printer,
12469you can print the reference card immediately with @file{refcard.ps}.
12470
12471The release also includes the source for the reference card. You
12472can format it, using @TeX{}, by typing:
12473
12474@example
12475make refcard.dvi
12476@end example
12477
5d161b24
DB
12478The @value{GDBN} reference card is designed to print in @dfn{landscape}
12479mode on US ``letter'' size paper;
c906108c
SS
12480that is, on a sheet 11 inches wide by 8.5 inches
12481high. You will need to specify this form of printing as an option to
12482your @sc{dvi} output program.
12483
12484@cindex documentation
12485
12486All the documentation for @value{GDBN} comes as part of the machine-readable
12487distribution. The documentation is written in Texinfo format, which is
12488a documentation system that uses a single source file to produce both
12489on-line information and a printed manual. You can use one of the Info
12490formatting commands to create the on-line version of the documentation
12491and @TeX{} (or @code{texi2roff}) to typeset the printed version.
12492
12493@value{GDBN} includes an already formatted copy of the on-line Info
12494version of this manual in the @file{gdb} subdirectory. The main Info
12495file is @file{gdb-@value{GDBVN}/gdb/gdb.info}, and it refers to
12496subordinate files matching @samp{gdb.info*} in the same directory. If
12497necessary, you can print out these files, or read them with any editor;
12498but they are easier to read using the @code{info} subsystem in @sc{gnu}
12499Emacs or the standalone @code{info} program, available as part of the
12500@sc{gnu} Texinfo distribution.
12501
12502If you want to format these Info files yourself, you need one of the
12503Info formatting programs, such as @code{texinfo-format-buffer} or
12504@code{makeinfo}.
12505
12506If you have @code{makeinfo} installed, and are in the top level
12507@value{GDBN} source directory (@file{gdb-@value{GDBVN}}, in the case of
12508version @value{GDBVN}), you can make the Info file by typing:
12509
12510@example
12511cd gdb
12512make gdb.info
12513@end example
12514
12515If you want to typeset and print copies of this manual, you need @TeX{},
12516a program to print its @sc{dvi} output files, and @file{texinfo.tex}, the
12517Texinfo definitions file.
12518
12519@TeX{} is a typesetting program; it does not print files directly, but
12520produces output files called @sc{dvi} files. To print a typeset
12521document, you need a program to print @sc{dvi} files. If your system
12522has @TeX{} installed, chances are it has such a program. The precise
12523command to use depends on your system; @kbd{lpr -d} is common; another
12524(for PostScript devices) is @kbd{dvips}. The @sc{dvi} print command may
12525require a file name without any extension or a @samp{.dvi} extension.
12526
12527@TeX{} also requires a macro definitions file called
12528@file{texinfo.tex}. This file tells @TeX{} how to typeset a document
12529written in Texinfo format. On its own, @TeX{} cannot either read or
12530typeset a Texinfo file. @file{texinfo.tex} is distributed with GDB
12531and is located in the @file{gdb-@var{version-number}/texinfo}
12532directory.
12533
12534If you have @TeX{} and a @sc{dvi} printer program installed, you can
12535typeset and print this manual. First switch to the the @file{gdb}
12536subdirectory of the main source directory (for example, to
12537@file{gdb-@value{GDBVN}/gdb}) and type:
12538
12539@example
12540make gdb.dvi
12541@end example
12542
12543Then give @file{gdb.dvi} to your @sc{dvi} printing program.
c906108c 12544
6d2ebf8b 12545@node Installing GDB
c906108c
SS
12546@appendix Installing @value{GDBN}
12547@cindex configuring @value{GDBN}
12548@cindex installation
12549
c906108c
SS
12550@value{GDBN} comes with a @code{configure} script that automates the process
12551of preparing @value{GDBN} for installation; you can then use @code{make} to
12552build the @code{gdb} program.
12553@iftex
12554@c irrelevant in info file; it's as current as the code it lives with.
12555@footnote{If you have a more recent version of @value{GDBN} than @value{GDBVN},
12556look at the @file{README} file in the sources; we may have improved the
12557installation procedures since publishing this manual.}
12558@end iftex
12559
5d161b24
DB
12560The @value{GDBN} distribution includes all the source code you need for
12561@value{GDBN} in a single directory, whose name is usually composed by
c906108c
SS
12562appending the version number to @samp{gdb}.
12563
12564For example, the @value{GDBN} version @value{GDBVN} distribution is in the
12565@file{gdb-@value{GDBVN}} directory. That directory contains:
12566
12567@table @code
12568@item gdb-@value{GDBVN}/configure @r{(and supporting files)}
12569script for configuring @value{GDBN} and all its supporting libraries
12570
12571@item gdb-@value{GDBVN}/gdb
12572the source specific to @value{GDBN} itself
12573
12574@item gdb-@value{GDBVN}/bfd
12575source for the Binary File Descriptor library
12576
12577@item gdb-@value{GDBVN}/include
12578@sc{gnu} include files
12579
12580@item gdb-@value{GDBVN}/libiberty
12581source for the @samp{-liberty} free software library
12582
12583@item gdb-@value{GDBVN}/opcodes
12584source for the library of opcode tables and disassemblers
12585
12586@item gdb-@value{GDBVN}/readline
12587source for the @sc{gnu} command-line interface
12588
12589@item gdb-@value{GDBVN}/glob
12590source for the @sc{gnu} filename pattern-matching subroutine
12591
12592@item gdb-@value{GDBVN}/mmalloc
12593source for the @sc{gnu} memory-mapped malloc package
12594@end table
12595
12596The simplest way to configure and build @value{GDBN} is to run @code{configure}
12597from the @file{gdb-@var{version-number}} source directory, which in
12598this example is the @file{gdb-@value{GDBVN}} directory.
12599
12600First switch to the @file{gdb-@var{version-number}} source directory
12601if you are not already in it; then run @code{configure}. Pass the
12602identifier for the platform on which @value{GDBN} will run as an
12603argument.
12604
12605For example:
12606
12607@example
12608cd gdb-@value{GDBVN}
12609./configure @var{host}
12610make
12611@end example
12612
12613@noindent
12614where @var{host} is an identifier such as @samp{sun4} or
12615@samp{decstation}, that identifies the platform where @value{GDBN} will run.
12616(You can often leave off @var{host}; @code{configure} tries to guess the
12617correct value by examining your system.)
12618
12619Running @samp{configure @var{host}} and then running @code{make} builds the
12620@file{bfd}, @file{readline}, @file{mmalloc}, and @file{libiberty}
12621libraries, then @code{gdb} itself. The configured source files, and the
12622binaries, are left in the corresponding source directories.
12623
12624@need 750
12625@code{configure} is a Bourne-shell (@code{/bin/sh}) script; if your
12626system does not recognize this automatically when you run a different
12627shell, you may need to run @code{sh} on it explicitly:
12628
12629@example
12630sh configure @var{host}
12631@end example
12632
12633If you run @code{configure} from a directory that contains source
12634directories for multiple libraries or programs, such as the
12635@file{gdb-@value{GDBVN}} source directory for version @value{GDBVN}, @code{configure}
12636creates configuration files for every directory level underneath (unless
12637you tell it not to, with the @samp{--norecursion} option).
12638
12639You can run the @code{configure} script from any of the
12640subordinate directories in the @value{GDBN} distribution if you only want to
12641configure that subdirectory, but be sure to specify a path to it.
12642
12643For example, with version @value{GDBVN}, type the following to configure only
12644the @code{bfd} subdirectory:
12645
12646@example
12647@group
12648cd gdb-@value{GDBVN}/bfd
12649../configure @var{host}
12650@end group
12651@end example
12652
12653You can install @code{@value{GDBP}} anywhere; it has no hardwired paths.
12654However, you should make sure that the shell on your path (named by
12655the @samp{SHELL} environment variable) is publicly readable. Remember
12656that @value{GDBN} uses the shell to start your program---some systems refuse to
12657let @value{GDBN} debug child processes whose programs are not readable.
12658
12659@menu
12660* Separate Objdir:: Compiling @value{GDBN} in another directory
12661* Config Names:: Specifying names for hosts and targets
12662* Configure Options:: Summary of options for configure
12663@end menu
12664
6d2ebf8b 12665@node Separate Objdir
c906108c
SS
12666@section Compiling @value{GDBN} in another directory
12667
12668If you want to run @value{GDBN} versions for several host or target machines,
12669you need a different @code{gdb} compiled for each combination of
12670host and target. @code{configure} is designed to make this easy by
12671allowing you to generate each configuration in a separate subdirectory,
12672rather than in the source directory. If your @code{make} program
12673handles the @samp{VPATH} feature (@sc{gnu} @code{make} does), running
12674@code{make} in each of these directories builds the @code{gdb}
12675program specified there.
12676
12677To build @code{gdb} in a separate directory, run @code{configure}
12678with the @samp{--srcdir} option to specify where to find the source.
12679(You also need to specify a path to find @code{configure}
12680itself from your working directory. If the path to @code{configure}
12681would be the same as the argument to @samp{--srcdir}, you can leave out
12682the @samp{--srcdir} option; it is assumed.)
12683
5d161b24 12684For example, with version @value{GDBVN}, you can build @value{GDBN} in a
c906108c
SS
12685separate directory for a Sun 4 like this:
12686
12687@example
12688@group
12689cd gdb-@value{GDBVN}
12690mkdir ../gdb-sun4
12691cd ../gdb-sun4
12692../gdb-@value{GDBVN}/configure sun4
12693make
12694@end group
12695@end example
12696
12697When @code{configure} builds a configuration using a remote source
12698directory, it creates a tree for the binaries with the same structure
12699(and using the same names) as the tree under the source directory. In
12700the example, you'd find the Sun 4 library @file{libiberty.a} in the
12701directory @file{gdb-sun4/libiberty}, and @value{GDBN} itself in
12702@file{gdb-sun4/gdb}.
12703
12704One popular reason to build several @value{GDBN} configurations in separate
5d161b24
DB
12705directories is to configure @value{GDBN} for cross-compiling (where
12706@value{GDBN} runs on one machine---the @dfn{host}---while debugging
12707programs that run on another machine---the @dfn{target}).
c906108c
SS
12708You specify a cross-debugging target by
12709giving the @samp{--target=@var{target}} option to @code{configure}.
12710
12711When you run @code{make} to build a program or library, you must run
12712it in a configured directory---whatever directory you were in when you
12713called @code{configure} (or one of its subdirectories).
12714
12715The @code{Makefile} that @code{configure} generates in each source
12716directory also runs recursively. If you type @code{make} in a source
12717directory such as @file{gdb-@value{GDBVN}} (or in a separate configured
12718directory configured with @samp{--srcdir=@var{dirname}/gdb-@value{GDBVN}}), you
12719will build all the required libraries, and then build GDB.
12720
12721When you have multiple hosts or targets configured in separate
12722directories, you can run @code{make} on them in parallel (for example,
12723if they are NFS-mounted on each of the hosts); they will not interfere
12724with each other.
12725
6d2ebf8b 12726@node Config Names
c906108c
SS
12727@section Specifying names for hosts and targets
12728
12729The specifications used for hosts and targets in the @code{configure}
12730script are based on a three-part naming scheme, but some short predefined
12731aliases are also supported. The full naming scheme encodes three pieces
12732of information in the following pattern:
12733
12734@example
12735@var{architecture}-@var{vendor}-@var{os}
12736@end example
12737
12738For example, you can use the alias @code{sun4} as a @var{host} argument,
12739or as the value for @var{target} in a @code{--target=@var{target}}
12740option. The equivalent full name is @samp{sparc-sun-sunos4}.
12741
12742The @code{configure} script accompanying @value{GDBN} does not provide
12743any query facility to list all supported host and target names or
12744aliases. @code{configure} calls the Bourne shell script
12745@code{config.sub} to map abbreviations to full names; you can read the
12746script, if you wish, or you can use it to test your guesses on
12747abbreviations---for example:
12748
12749@smallexample
12750% sh config.sub i386-linux
12751i386-pc-linux-gnu
12752% sh config.sub alpha-linux
12753alpha-unknown-linux-gnu
12754% sh config.sub hp9k700
12755hppa1.1-hp-hpux
12756% sh config.sub sun4
12757sparc-sun-sunos4.1.1
12758% sh config.sub sun3
12759m68k-sun-sunos4.1.1
12760% sh config.sub i986v
12761Invalid configuration `i986v': machine `i986v' not recognized
12762@end smallexample
12763
12764@noindent
12765@code{config.sub} is also distributed in the @value{GDBN} source
12766directory (@file{gdb-@value{GDBVN}}, for version @value{GDBVN}).
12767
6d2ebf8b 12768@node Configure Options
c906108c
SS
12769@section @code{configure} options
12770
12771Here is a summary of the @code{configure} options and arguments that
12772are most often useful for building @value{GDBN}. @code{configure} also has
12773several other options not listed here. @inforef{What Configure
12774Does,,configure.info}, for a full explanation of @code{configure}.
12775
12776@example
12777configure @r{[}--help@r{]}
12778 @r{[}--prefix=@var{dir}@r{]}
12779 @r{[}--exec-prefix=@var{dir}@r{]}
12780 @r{[}--srcdir=@var{dirname}@r{]}
12781 @r{[}--norecursion@r{]} @r{[}--rm@r{]}
12782 @r{[}--target=@var{target}@r{]}
12783 @var{host}
12784@end example
12785
12786@noindent
12787You may introduce options with a single @samp{-} rather than
12788@samp{--} if you prefer; but you may abbreviate option names if you use
12789@samp{--}.
12790
12791@table @code
12792@item --help
12793Display a quick summary of how to invoke @code{configure}.
12794
12795@item --prefix=@var{dir}
12796Configure the source to install programs and files under directory
12797@file{@var{dir}}.
12798
12799@item --exec-prefix=@var{dir}
12800Configure the source to install programs under directory
12801@file{@var{dir}}.
12802
12803@c avoid splitting the warning from the explanation:
12804@need 2000
12805@item --srcdir=@var{dirname}
12806@strong{Warning: using this option requires @sc{gnu} @code{make}, or another
12807@code{make} that implements the @code{VPATH} feature.}@*
12808Use this option to make configurations in directories separate from the
12809@value{GDBN} source directories. Among other things, you can use this to
12810build (or maintain) several configurations simultaneously, in separate
12811directories. @code{configure} writes configuration specific files in
12812the current directory, but arranges for them to use the source in the
12813directory @var{dirname}. @code{configure} creates directories under
12814the working directory in parallel to the source directories below
12815@var{dirname}.
12816
12817@item --norecursion
12818Configure only the directory level where @code{configure} is executed; do not
12819propagate configuration to subdirectories.
12820
12821@item --target=@var{target}
12822Configure @value{GDBN} for cross-debugging programs running on the specified
12823@var{target}. Without this option, @value{GDBN} is configured to debug
12824programs that run on the same machine (@var{host}) as @value{GDBN} itself.
12825
12826There is no convenient way to generate a list of all available targets.
12827
12828@item @var{host} @dots{}
12829Configure @value{GDBN} to run on the specified @var{host}.
12830
12831There is no convenient way to generate a list of all available hosts.
12832@end table
12833
12834There are many other options available as well, but they are generally
12835needed for special purposes only.
5d161b24 12836
6d2ebf8b 12837@node Index
c906108c
SS
12838@unnumbered Index
12839
12840@printindex cp
12841
12842@tex
12843% I think something like @colophon should be in texinfo. In the
12844% meantime:
12845\long\def\colophon{\hbox to0pt{}\vfill
12846\centerline{The body of this manual is set in}
12847\centerline{\fontname\tenrm,}
12848\centerline{with headings in {\bf\fontname\tenbf}}
12849\centerline{and examples in {\tt\fontname\tentt}.}
12850\centerline{{\it\fontname\tenit\/},}
12851\centerline{{\bf\fontname\tenbf}, and}
12852\centerline{{\sl\fontname\tensl\/}}
12853\centerline{are used for emphasis.}\vfill}
12854\page\colophon
12855% Blame: doc@cygnus.com, 1991.
12856@end tex
12857
12858@contents
12859@bye
This page took 1.05483 seconds and 4 git commands to generate.