From 2001-07-23 Andreas Schwab <schwab@suse.de>:
[deliverable/binutils-gdb.git] / gdb / doc / gdb.texinfo
CommitLineData
c906108c 1\input texinfo @c -*-texinfo-*-
b6ba6518
KB
2@c Copyright 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1998,
3@c 1999, 2000, 2001
c906108c
SS
4@c Free Software Foundation, Inc.
5@c
5d161b24 6@c %**start of header
c906108c
SS
7@c makeinfo ignores cmds prev to setfilename, so its arg cannot make use
8@c of @set vars. However, you can override filename with makeinfo -o.
9@setfilename gdb.info
10@c
11@include gdb-cfg.texi
12@c
c906108c 13@settitle Debugging with @value{GDBN}
c906108c
SS
14@setchapternewpage odd
15@c %**end of header
16
17@iftex
18@c @smallbook
19@c @cropmarks
20@end iftex
21
22@finalout
23@syncodeindex ky cp
24
41afff9a 25@c readline appendices use @vindex, @findex and @ftable,
48e934c6 26@c annotate.texi and gdbmi use @findex.
c906108c 27@syncodeindex vr cp
41afff9a 28@syncodeindex fn cp
c906108c
SS
29
30@c !!set GDB manual's edition---not the same as GDB version!
e9c75b65 31@set EDITION Ninth
c906108c
SS
32
33@c !!set GDB manual's revision date
e9c75b65 34@set DATE April 2001
c906108c 35
6d2ebf8b 36@c THIS MANUAL REQUIRES TEXINFO 3.12 OR LATER.
c906108c 37
c906108c 38@c This is a dir.info fragment to support semi-automated addition of
6d2ebf8b 39@c manuals to an info tree.
96a2c332
SS
40@dircategory Programming & development tools.
41@direntry
c906108c 42* Gdb: (gdb). The @sc{gnu} debugger.
96a2c332
SS
43@end direntry
44
c906108c
SS
45@ifinfo
46This file documents the @sc{gnu} debugger @value{GDBN}.
47
48
5d161b24 49This is the @value{EDITION} Edition, @value{DATE},
c906108c
SS
50of @cite{Debugging with @value{GDBN}: the @sc{gnu} Source-Level Debugger}
51for @value{GDBN} Version @value{GDBVN}.
52
e9c75b65
EZ
53Copyright (C) 1988,1989,1990,1991,1992,1993,1994,1995,1996,1998,1999,2000,2001
54 Free Software Foundation, Inc.
c906108c 55
e9c75b65
EZ
56Permission is granted to copy, distribute and/or modify this document
57under the terms of the GNU Free Documentation License, Version 1.1 or
58any later version published by the Free Software Foundation; with the
59Invariant Sections being ``A Sample GDB Session'' and ``Free
60Software'', with the Front-Cover texts being ``A GNU Manual,'' and
61with the Back-Cover Texts as in (a) below.
c906108c 62
e9c75b65
EZ
63(a) The FSF's Back-Cover Text is: ``You have freedom to copy and modify
64this GNU Manual, like GNU software. Copies published by the Free
65Software Foundation raise funds for GNU development.''
c906108c
SS
66@end ifinfo
67
68@titlepage
69@title Debugging with @value{GDBN}
70@subtitle The @sc{gnu} Source-Level Debugger
c906108c 71@sp 1
c906108c
SS
72@subtitle @value{EDITION} Edition, for @value{GDBN} version @value{GDBVN}
73@subtitle @value{DATE}
9e9c5ae7 74@author Richard Stallman, Roland Pesch, Stan Shebs, et al.
c906108c 75@page
c906108c
SS
76@tex
77{\parskip=0pt
53a5351d 78\hfill (Send bugs and comments on @value{GDBN} to bug-gdb\@gnu.org.)\par
c906108c
SS
79\hfill {\it Debugging with @value{GDBN}}\par
80\hfill \TeX{}info \texinfoversion\par
81}
82@end tex
53a5351d 83
c906108c 84@vskip 0pt plus 1filll
e9c75b65
EZ
85Copyright @copyright{} 1988,1989,1990,1991,1992,1993,1994,1995,1996,1998,1999,2000,2001
86 Free Software Foundation, Inc.
c906108c 87@sp 2
c906108c
SS
88Published by the Free Software Foundation @*
8959 Temple Place - Suite 330, @*
90Boston, MA 02111-1307 USA @*
6d2ebf8b 91ISBN 1-882114-77-9 @*
e9c75b65
EZ
92
93Permission is granted to copy, distribute and/or modify this document
94under the terms of the GNU Free Documentation License, Version 1.1 or
95any later version published by the Free Software Foundation; with the
96Invariant Sections being ``A Sample GDB Session'' and ``Free
97Software'', with the Front-Cover texts being ``A GNU Manual,'' and
98with the Back-Cover Texts as in (a) below.
99
100(a) The FSF's Back-Cover Text is: ``You have freedom to copy and modify
101this GNU Manual, like GNU software. Copies published by the Free
102Software Foundation raise funds for GNU development.''
c906108c
SS
103@end titlepage
104@page
105
b9deaee7 106@ifinfo
6d2ebf8b
SS
107@node Top, Summary, (dir), (dir)
108
c906108c
SS
109@top Debugging with @value{GDBN}
110
111This file describes @value{GDBN}, the @sc{gnu} symbolic debugger.
112
5d161b24 113This is the @value{EDITION} Edition, @value{DATE}, for @value{GDBN} Version
c906108c
SS
114@value{GDBVN}.
115
e9c75b65 116Copyright (C) 1988-2001 Free Software Foundation, Inc.
6d2ebf8b
SS
117
118@menu
119* Summary:: Summary of @value{GDBN}
120* Sample Session:: A sample @value{GDBN} session
121
122* Invocation:: Getting in and out of @value{GDBN}
123* Commands:: @value{GDBN} commands
124* Running:: Running programs under @value{GDBN}
125* Stopping:: Stopping and continuing
126* Stack:: Examining the stack
127* Source:: Examining source files
128* Data:: Examining data
b37052ae 129* Tracepoints:: Debugging remote targets non-intrusively
6d2ebf8b
SS
130
131* Languages:: Using @value{GDBN} with different languages
132
133* Symbols:: Examining the symbol table
134* Altering:: Altering execution
135* GDB Files:: @value{GDBN} files
136* Targets:: Specifying a debugging target
137* Configurations:: Configuration-specific information
138* Controlling GDB:: Controlling @value{GDBN}
139* Sequences:: Canned sequences of commands
c4555f82 140* TUI:: @value{GDBN} Text User Interface
6d2ebf8b
SS
141* Emacs:: Using @value{GDBN} under @sc{gnu} Emacs
142* Annotations:: @value{GDBN}'s annotation interface.
7162c0ca 143* GDB/MI:: @value{GDBN}'s Machine Interface.
6d2ebf8b
SS
144
145* GDB Bugs:: Reporting bugs in @value{GDBN}
146* Formatting Documentation:: How to format and print @value{GDBN} documentation
147
148* Command Line Editing:: Command Line Editing
149* Using History Interactively:: Using History Interactively
150* Installing GDB:: Installing GDB
151* Index:: Index
152@end menu
153
b9deaee7 154@end ifinfo
6d2ebf8b
SS
155
156@c the replication sucks, but this avoids a texinfo 3.12 lameness
157
158@ifhtml
159@node Top
160
161@top Debugging with @value{GDBN}
162
163This file describes @value{GDBN}, the @sc{gnu} symbolic debugger.
164
b37052ae 165This is the @value{EDITION} Edition, @value{DATE}, for @value{GDBN} Version
6d2ebf8b
SS
166@value{GDBVN}.
167
168Copyright (C) 1988-2000 Free Software Foundation, Inc.
169
c906108c
SS
170@menu
171* Summary:: Summary of @value{GDBN}
c906108c 172* Sample Session:: A sample @value{GDBN} session
c906108c
SS
173
174* Invocation:: Getting in and out of @value{GDBN}
175* Commands:: @value{GDBN} commands
176* Running:: Running programs under @value{GDBN}
177* Stopping:: Stopping and continuing
178* Stack:: Examining the stack
179* Source:: Examining source files
180* Data:: Examining data
c906108c 181
7a292a7a 182* Languages:: Using @value{GDBN} with different languages
c906108c
SS
183
184* Symbols:: Examining the symbol table
185* Altering:: Altering execution
186* GDB Files:: @value{GDBN} files
187* Targets:: Specifying a debugging target
104c1213 188* Configurations:: Configuration-specific information
c906108c
SS
189* Controlling GDB:: Controlling @value{GDBN}
190* Sequences:: Canned sequences of commands
c906108c 191* Emacs:: Using @value{GDBN} under @sc{gnu} Emacs
6d2ebf8b 192* Annotations:: @value{GDBN}'s annotation interface.
c906108c
SS
193
194* GDB Bugs:: Reporting bugs in @value{GDBN}
c906108c 195* Formatting Documentation:: How to format and print @value{GDBN} documentation
c906108c
SS
196
197* Command Line Editing:: Command Line Editing
198* Using History Interactively:: Using History Interactively
199* Installing GDB:: Installing GDB
200* Index:: Index
c906108c
SS
201@end menu
202
6d2ebf8b
SS
203@end ifhtml
204
449f3b6c
AC
205@c TeX can handle the contents at the start but makeinfo 3.12 can not
206@iftex
207@contents
208@end iftex
209
6d2ebf8b 210@node Summary
c906108c
SS
211@unnumbered Summary of @value{GDBN}
212
213The purpose of a debugger such as @value{GDBN} is to allow you to see what is
214going on ``inside'' another program while it executes---or what another
215program was doing at the moment it crashed.
216
217@value{GDBN} can do four main kinds of things (plus other things in support of
218these) to help you catch bugs in the act:
219
220@itemize @bullet
221@item
222Start your program, specifying anything that might affect its behavior.
223
224@item
225Make your program stop on specified conditions.
226
227@item
228Examine what has happened, when your program has stopped.
229
230@item
231Change things in your program, so you can experiment with correcting the
232effects of one bug and go on to learn about another.
233@end itemize
234
cce74817 235You can use @value{GDBN} to debug programs written in C and C++.
c906108c 236For more information, see @ref{Support,,Supported languages}.
c906108c
SS
237For more information, see @ref{C,,C and C++}.
238
cce74817
JM
239@cindex Chill
240@cindex Modula-2
c906108c 241Support for Modula-2 and Chill is partial. For information on Modula-2,
cce74817 242see @ref{Modula-2,,Modula-2}. For information on Chill, see @ref{Chill}.
c906108c 243
cce74817
JM
244@cindex Pascal
245Debugging Pascal programs which use sets, subranges, file variables, or
246nested functions does not currently work. @value{GDBN} does not support
247entering expressions, printing values, or similar features using Pascal
248syntax.
c906108c 249
c906108c
SS
250@cindex Fortran
251@value{GDBN} can be used to debug programs written in Fortran, although
53a5351d 252it may be necessary to refer to some variables with a trailing
cce74817 253underscore.
c906108c 254
c906108c
SS
255@menu
256* Free Software:: Freely redistributable software
257* Contributors:: Contributors to GDB
258@end menu
259
6d2ebf8b 260@node Free Software
c906108c
SS
261@unnumberedsec Free software
262
5d161b24 263@value{GDBN} is @dfn{free software}, protected by the @sc{gnu}
c906108c
SS
264General Public License
265(GPL). The GPL gives you the freedom to copy or adapt a licensed
266program---but every person getting a copy also gets with it the
267freedom to modify that copy (which means that they must get access to
268the source code), and the freedom to distribute further copies.
269Typical software companies use copyrights to limit your freedoms; the
270Free Software Foundation uses the GPL to preserve these freedoms.
271
272Fundamentally, the General Public License is a license which says that
273you have these freedoms and that you cannot take these freedoms away
274from anyone else.
275
6d2ebf8b 276@node Contributors
96a2c332
SS
277@unnumberedsec Contributors to @value{GDBN}
278
279Richard Stallman was the original author of @value{GDBN}, and of many
280other @sc{gnu} programs. Many others have contributed to its
281development. This section attempts to credit major contributors. One
282of the virtues of free software is that everyone is free to contribute
283to it; with regret, we cannot actually acknowledge everyone here. The
284file @file{ChangeLog} in the @value{GDBN} distribution approximates a
c906108c
SS
285blow-by-blow account.
286
287Changes much prior to version 2.0 are lost in the mists of time.
288
289@quotation
290@emph{Plea:} Additions to this section are particularly welcome. If you
291or your friends (or enemies, to be evenhanded) have been unfairly
292omitted from this list, we would like to add your names!
293@end quotation
294
295So that they may not regard their many labors as thankless, we
296particularly thank those who shepherded @value{GDBN} through major
297releases:
b37052ae 298Andrew Cagney (releases 5.0 and 5.1);
c906108c
SS
299Jim Blandy (release 4.18);
300Jason Molenda (release 4.17);
301Stan Shebs (release 4.14);
302Fred Fish (releases 4.16, 4.15, 4.13, 4.12, 4.11, 4.10, and 4.9);
303Stu Grossman and John Gilmore (releases 4.8, 4.7, 4.6, 4.5, and 4.4);
304John Gilmore (releases 4.3, 4.2, 4.1, 4.0, and 3.9);
305Jim Kingdon (releases 3.5, 3.4, and 3.3);
306and Randy Smith (releases 3.2, 3.1, and 3.0).
307
308Richard Stallman, assisted at various times by Peter TerMaat, Chris
309Hanson, and Richard Mlynarik, handled releases through 2.8.
310
b37052ae
EZ
311Michael Tiemann is the author of most of the @sc{gnu} C@t{++} support
312in @value{GDBN}, with significant additional contributions from Per
313Bothner and Daniel Berlin. James Clark wrote the @sc{gnu} C@t{++}
314demangler. Early work on C@t{++} was by Peter TerMaat (who also did
315much general update work leading to release 3.0).
c906108c 316
b37052ae 317@value{GDBN} uses the BFD subroutine library to examine multiple
c906108c
SS
318object-file formats; BFD was a joint project of David V.
319Henkel-Wallace, Rich Pixley, Steve Chamberlain, and John Gilmore.
320
321David Johnson wrote the original COFF support; Pace Willison did
322the original support for encapsulated COFF.
323
96c405b3 324Brent Benson of Harris Computer Systems contributed DWARF2 support.
c906108c
SS
325
326Adam de Boor and Bradley Davis contributed the ISI Optimum V support.
327Per Bothner, Noboyuki Hikichi, and Alessandro Forin contributed MIPS
328support.
329Jean-Daniel Fekete contributed Sun 386i support.
330Chris Hanson improved the HP9000 support.
331Noboyuki Hikichi and Tomoyuki Hasei contributed Sony/News OS 3 support.
332David Johnson contributed Encore Umax support.
333Jyrki Kuoppala contributed Altos 3068 support.
334Jeff Law contributed HP PA and SOM support.
335Keith Packard contributed NS32K support.
336Doug Rabson contributed Acorn Risc Machine support.
337Bob Rusk contributed Harris Nighthawk CX-UX support.
338Chris Smith contributed Convex support (and Fortran debugging).
339Jonathan Stone contributed Pyramid support.
340Michael Tiemann contributed SPARC support.
341Tim Tucker contributed support for the Gould NP1 and Gould Powernode.
342Pace Willison contributed Intel 386 support.
343Jay Vosburgh contributed Symmetry support.
344
345Andreas Schwab contributed M68K Linux support.
346
347Rich Schaefer and Peter Schauer helped with support of SunOS shared
348libraries.
349
350Jay Fenlason and Roland McGrath ensured that @value{GDBN} and GAS agree
351about several machine instruction sets.
352
353Patrick Duval, Ted Goldstein, Vikram Koka and Glenn Engel helped develop
354remote debugging. Intel Corporation, Wind River Systems, AMD, and ARM
355contributed remote debugging modules for the i960, VxWorks, A29K UDI,
356and RDI targets, respectively.
357
358Brian Fox is the author of the readline libraries providing
359command-line editing and command history.
360
7a292a7a
SS
361Andrew Beers of SUNY Buffalo wrote the language-switching code, the
362Modula-2 support, and contributed the Languages chapter of this manual.
c906108c 363
5d161b24 364Fred Fish wrote most of the support for Unix System Vr4.
b37052ae 365He also enhanced the command-completion support to cover C@t{++} overloaded
c906108c 366symbols.
c906108c
SS
367
368Hitachi America, Ltd. sponsored the support for H8/300, H8/500, and
369Super-H processors.
370
371NEC sponsored the support for the v850, Vr4xxx, and Vr5xxx processors.
372
373Mitsubishi sponsored the support for D10V, D30V, and M32R/D processors.
374
375Toshiba sponsored the support for the TX39 Mips processor.
376
377Matsushita sponsored the support for the MN10200 and MN10300 processors.
378
96a2c332 379Fujitsu sponsored the support for SPARClite and FR30 processors.
c906108c
SS
380
381Kung Hsu, Jeff Law, and Rick Sladkey added support for hardware
382watchpoints.
383
384Michael Snyder added support for tracepoints.
385
386Stu Grossman wrote gdbserver.
387
388Jim Kingdon, Peter Schauer, Ian Taylor, and Stu Grossman made
96a2c332 389nearly innumerable bug fixes and cleanups throughout @value{GDBN}.
c906108c
SS
390
391The following people at the Hewlett-Packard Company contributed
392support for the PA-RISC 2.0 architecture, HP-UX 10.20, 10.30, and 11.0
b37052ae 393(narrow mode), HP's implementation of kernel threads, HP's aC@t{++}
c906108c
SS
394compiler, and the terminal user interface: Ben Krepp, Richard Title,
395John Bishop, Susan Macchia, Kathy Mann, Satish Pai, India Paul, Steve
396Rehrauer, and Elena Zannoni. Kim Haase provided HP-specific
397information in this manual.
398
b37052ae
EZ
399DJ Delorie ported @value{GDBN} to MS-DOS, for the DJGPP project.
400Robert Hoehne made significant contributions to the DJGPP port.
401
96a2c332
SS
402Cygnus Solutions has sponsored @value{GDBN} maintenance and much of its
403development since 1991. Cygnus engineers who have worked on @value{GDBN}
2df3850c
JM
404fulltime include Mark Alexander, Jim Blandy, Per Bothner, Kevin
405Buettner, Edith Epstein, Chris Faylor, Fred Fish, Martin Hunt, Jim
406Ingham, John Gilmore, Stu Grossman, Kung Hsu, Jim Kingdon, John Metzler,
407Fernando Nasser, Geoffrey Noer, Dawn Perchik, Rich Pixley, Zdenek
408Radouch, Keith Seitz, Stan Shebs, David Taylor, and Elena Zannoni. In
409addition, Dave Brolley, Ian Carmichael, Steve Chamberlain, Nick Clifton,
410JT Conklin, Stan Cox, DJ Delorie, Ulrich Drepper, Frank Eigler, Doug
411Evans, Sean Fagan, David Henkel-Wallace, Richard Henderson, Jeff
412Holcomb, Jeff Law, Jim Lemke, Tom Lord, Bob Manson, Michael Meissner,
413Jason Merrill, Catherine Moore, Drew Moseley, Ken Raeburn, Gavin
414Romig-Koch, Rob Savoye, Jamie Smith, Mike Stump, Ian Taylor, Angela
415Thomas, Michael Tiemann, Tom Tromey, Ron Unrau, Jim Wilson, and David
416Zuhn have made contributions both large and small.
c906108c
SS
417
418
6d2ebf8b 419@node Sample Session
c906108c
SS
420@chapter A Sample @value{GDBN} Session
421
422You can use this manual at your leisure to read all about @value{GDBN}.
423However, a handful of commands are enough to get started using the
424debugger. This chapter illustrates those commands.
425
426@iftex
427In this sample session, we emphasize user input like this: @b{input},
428to make it easier to pick out from the surrounding output.
429@end iftex
430
431@c FIXME: this example may not be appropriate for some configs, where
432@c FIXME...primary interest is in remote use.
433
434One of the preliminary versions of @sc{gnu} @code{m4} (a generic macro
435processor) exhibits the following bug: sometimes, when we change its
436quote strings from the default, the commands used to capture one macro
437definition within another stop working. In the following short @code{m4}
438session, we define a macro @code{foo} which expands to @code{0000}; we
439then use the @code{m4} built-in @code{defn} to define @code{bar} as the
440same thing. However, when we change the open quote string to
441@code{<QUOTE>} and the close quote string to @code{<UNQUOTE>}, the same
442procedure fails to define a new synonym @code{baz}:
443
444@smallexample
445$ @b{cd gnu/m4}
446$ @b{./m4}
447@b{define(foo,0000)}
448
449@b{foo}
4500000
451@b{define(bar,defn(`foo'))}
452
453@b{bar}
4540000
455@b{changequote(<QUOTE>,<UNQUOTE>)}
456
457@b{define(baz,defn(<QUOTE>foo<UNQUOTE>))}
458@b{baz}
459@b{C-d}
460m4: End of input: 0: fatal error: EOF in string
461@end smallexample
462
463@noindent
464Let us use @value{GDBN} to try to see what is going on.
465
c906108c
SS
466@smallexample
467$ @b{@value{GDBP} m4}
468@c FIXME: this falsifies the exact text played out, to permit smallbook
469@c FIXME... format to come out better.
470@value{GDBN} is free software and you are welcome to distribute copies
5d161b24 471 of it under certain conditions; type "show copying" to see
c906108c 472 the conditions.
5d161b24 473There is absolutely no warranty for @value{GDBN}; type "show warranty"
c906108c
SS
474 for details.
475
476@value{GDBN} @value{GDBVN}, Copyright 1999 Free Software Foundation, Inc...
477(@value{GDBP})
478@end smallexample
c906108c
SS
479
480@noindent
481@value{GDBN} reads only enough symbol data to know where to find the
482rest when needed; as a result, the first prompt comes up very quickly.
483We now tell @value{GDBN} to use a narrower display width than usual, so
484that examples fit in this manual.
485
486@smallexample
487(@value{GDBP}) @b{set width 70}
488@end smallexample
489
490@noindent
491We need to see how the @code{m4} built-in @code{changequote} works.
492Having looked at the source, we know the relevant subroutine is
493@code{m4_changequote}, so we set a breakpoint there with the @value{GDBN}
494@code{break} command.
495
496@smallexample
497(@value{GDBP}) @b{break m4_changequote}
498Breakpoint 1 at 0x62f4: file builtin.c, line 879.
499@end smallexample
500
501@noindent
502Using the @code{run} command, we start @code{m4} running under @value{GDBN}
503control; as long as control does not reach the @code{m4_changequote}
504subroutine, the program runs as usual:
505
506@smallexample
507(@value{GDBP}) @b{run}
508Starting program: /work/Editorial/gdb/gnu/m4/m4
509@b{define(foo,0000)}
510
511@b{foo}
5120000
513@end smallexample
514
515@noindent
516To trigger the breakpoint, we call @code{changequote}. @value{GDBN}
517suspends execution of @code{m4}, displaying information about the
518context where it stops.
519
520@smallexample
521@b{changequote(<QUOTE>,<UNQUOTE>)}
522
5d161b24 523Breakpoint 1, m4_changequote (argc=3, argv=0x33c70)
c906108c
SS
524 at builtin.c:879
525879 if (bad_argc(TOKEN_DATA_TEXT(argv[0]),argc,1,3))
526@end smallexample
527
528@noindent
529Now we use the command @code{n} (@code{next}) to advance execution to
530the next line of the current function.
531
532@smallexample
533(@value{GDBP}) @b{n}
534882 set_quotes((argc >= 2) ? TOKEN_DATA_TEXT(argv[1])\
535 : nil,
536@end smallexample
537
538@noindent
539@code{set_quotes} looks like a promising subroutine. We can go into it
540by using the command @code{s} (@code{step}) instead of @code{next}.
541@code{step} goes to the next line to be executed in @emph{any}
542subroutine, so it steps into @code{set_quotes}.
543
544@smallexample
545(@value{GDBP}) @b{s}
546set_quotes (lq=0x34c78 "<QUOTE>", rq=0x34c88 "<UNQUOTE>")
547 at input.c:530
548530 if (lquote != def_lquote)
549@end smallexample
550
551@noindent
552The display that shows the subroutine where @code{m4} is now
553suspended (and its arguments) is called a stack frame display. It
554shows a summary of the stack. We can use the @code{backtrace}
555command (which can also be spelled @code{bt}), to see where we are
556in the stack as a whole: the @code{backtrace} command displays a
557stack frame for each active subroutine.
558
559@smallexample
560(@value{GDBP}) @b{bt}
561#0 set_quotes (lq=0x34c78 "<QUOTE>", rq=0x34c88 "<UNQUOTE>")
562 at input.c:530
5d161b24 563#1 0x6344 in m4_changequote (argc=3, argv=0x33c70)
c906108c
SS
564 at builtin.c:882
565#2 0x8174 in expand_macro (sym=0x33320) at macro.c:242
566#3 0x7a88 in expand_token (obs=0x0, t=209696, td=0xf7fffa30)
567 at macro.c:71
568#4 0x79dc in expand_input () at macro.c:40
569#5 0x2930 in main (argc=0, argv=0xf7fffb20) at m4.c:195
570@end smallexample
571
572@noindent
573We step through a few more lines to see what happens. The first two
574times, we can use @samp{s}; the next two times we use @code{n} to avoid
575falling into the @code{xstrdup} subroutine.
576
577@smallexample
578(@value{GDBP}) @b{s}
5790x3b5c 532 if (rquote != def_rquote)
580(@value{GDBP}) @b{s}
5810x3b80 535 lquote = (lq == nil || *lq == '\0') ? \
582def_lquote : xstrdup(lq);
583(@value{GDBP}) @b{n}
584536 rquote = (rq == nil || *rq == '\0') ? def_rquote\
585 : xstrdup(rq);
586(@value{GDBP}) @b{n}
587538 len_lquote = strlen(rquote);
588@end smallexample
589
590@noindent
591The last line displayed looks a little odd; we can examine the variables
592@code{lquote} and @code{rquote} to see if they are in fact the new left
593and right quotes we specified. We use the command @code{p}
594(@code{print}) to see their values.
595
596@smallexample
597(@value{GDBP}) @b{p lquote}
598$1 = 0x35d40 "<QUOTE>"
599(@value{GDBP}) @b{p rquote}
600$2 = 0x35d50 "<UNQUOTE>"
601@end smallexample
602
603@noindent
604@code{lquote} and @code{rquote} are indeed the new left and right quotes.
605To look at some context, we can display ten lines of source
606surrounding the current line with the @code{l} (@code{list}) command.
607
608@smallexample
609(@value{GDBP}) @b{l}
610533 xfree(rquote);
611534
612535 lquote = (lq == nil || *lq == '\0') ? def_lquote\
613 : xstrdup (lq);
614536 rquote = (rq == nil || *rq == '\0') ? def_rquote\
615 : xstrdup (rq);
616537
617538 len_lquote = strlen(rquote);
618539 len_rquote = strlen(lquote);
619540 @}
620541
621542 void
622@end smallexample
623
624@noindent
625Let us step past the two lines that set @code{len_lquote} and
626@code{len_rquote}, and then examine the values of those variables.
627
628@smallexample
629(@value{GDBP}) @b{n}
630539 len_rquote = strlen(lquote);
631(@value{GDBP}) @b{n}
632540 @}
633(@value{GDBP}) @b{p len_lquote}
634$3 = 9
635(@value{GDBP}) @b{p len_rquote}
636$4 = 7
637@end smallexample
638
639@noindent
640That certainly looks wrong, assuming @code{len_lquote} and
641@code{len_rquote} are meant to be the lengths of @code{lquote} and
642@code{rquote} respectively. We can set them to better values using
643the @code{p} command, since it can print the value of
644any expression---and that expression can include subroutine calls and
645assignments.
646
647@smallexample
648(@value{GDBP}) @b{p len_lquote=strlen(lquote)}
649$5 = 7
650(@value{GDBP}) @b{p len_rquote=strlen(rquote)}
651$6 = 9
652@end smallexample
653
654@noindent
655Is that enough to fix the problem of using the new quotes with the
656@code{m4} built-in @code{defn}? We can allow @code{m4} to continue
657executing with the @code{c} (@code{continue}) command, and then try the
658example that caused trouble initially:
659
660@smallexample
661(@value{GDBP}) @b{c}
662Continuing.
663
664@b{define(baz,defn(<QUOTE>foo<UNQUOTE>))}
665
666baz
6670000
668@end smallexample
669
670@noindent
671Success! The new quotes now work just as well as the default ones. The
672problem seems to have been just the two typos defining the wrong
673lengths. We allow @code{m4} exit by giving it an EOF as input:
674
675@smallexample
676@b{C-d}
677Program exited normally.
678@end smallexample
679
680@noindent
681The message @samp{Program exited normally.} is from @value{GDBN}; it
682indicates @code{m4} has finished executing. We can end our @value{GDBN}
683session with the @value{GDBN} @code{quit} command.
684
685@smallexample
686(@value{GDBP}) @b{quit}
687@end smallexample
c906108c 688
6d2ebf8b 689@node Invocation
c906108c
SS
690@chapter Getting In and Out of @value{GDBN}
691
692This chapter discusses how to start @value{GDBN}, and how to get out of it.
5d161b24 693The essentials are:
c906108c 694@itemize @bullet
5d161b24 695@item
53a5351d 696type @samp{@value{GDBP}} to start @value{GDBN}.
5d161b24 697@item
c906108c
SS
698type @kbd{quit} or @kbd{C-d} to exit.
699@end itemize
700
701@menu
702* Invoking GDB:: How to start @value{GDBN}
703* Quitting GDB:: How to quit @value{GDBN}
704* Shell Commands:: How to use shell commands inside @value{GDBN}
705@end menu
706
6d2ebf8b 707@node Invoking GDB
c906108c
SS
708@section Invoking @value{GDBN}
709
c906108c
SS
710Invoke @value{GDBN} by running the program @code{@value{GDBP}}. Once started,
711@value{GDBN} reads commands from the terminal until you tell it to exit.
712
713You can also run @code{@value{GDBP}} with a variety of arguments and options,
714to specify more of your debugging environment at the outset.
715
c906108c
SS
716The command-line options described here are designed
717to cover a variety of situations; in some environments, some of these
5d161b24 718options may effectively be unavailable.
c906108c
SS
719
720The most usual way to start @value{GDBN} is with one argument,
721specifying an executable program:
722
723@example
724@value{GDBP} @var{program}
725@end example
726
c906108c
SS
727@noindent
728You can also start with both an executable program and a core file
729specified:
730
731@example
732@value{GDBP} @var{program} @var{core}
733@end example
734
735You can, instead, specify a process ID as a second argument, if you want
736to debug a running process:
737
738@example
739@value{GDBP} @var{program} 1234
740@end example
741
742@noindent
743would attach @value{GDBN} to process @code{1234} (unless you also have a file
744named @file{1234}; @value{GDBN} does check for a core file first).
745
c906108c 746Taking advantage of the second command-line argument requires a fairly
2df3850c
JM
747complete operating system; when you use @value{GDBN} as a remote
748debugger attached to a bare board, there may not be any notion of
749``process'', and there is often no way to get a core dump. @value{GDBN}
750will warn you if it is unable to attach or to read core dumps.
c906108c 751
96a2c332 752You can run @code{@value{GDBP}} without printing the front material, which describes
c906108c
SS
753@value{GDBN}'s non-warranty, by specifying @code{-silent}:
754
755@smallexample
756@value{GDBP} -silent
757@end smallexample
758
759@noindent
760You can further control how @value{GDBN} starts up by using command-line
761options. @value{GDBN} itself can remind you of the options available.
762
763@noindent
764Type
765
766@example
767@value{GDBP} -help
768@end example
769
770@noindent
771to display all available options and briefly describe their use
772(@samp{@value{GDBP} -h} is a shorter equivalent).
773
774All options and command line arguments you give are processed
775in sequential order. The order makes a difference when the
776@samp{-x} option is used.
777
778
779@menu
c906108c
SS
780* File Options:: Choosing files
781* Mode Options:: Choosing modes
782@end menu
783
6d2ebf8b 784@node File Options
c906108c
SS
785@subsection Choosing files
786
2df3850c 787When @value{GDBN} starts, it reads any arguments other than options as
c906108c
SS
788specifying an executable file and core file (or process ID). This is
789the same as if the arguments were specified by the @samp{-se} and
790@samp{-c} options respectively. (@value{GDBN} reads the first argument
791that does not have an associated option flag as equivalent to the
792@samp{-se} option followed by that argument; and the second argument
793that does not have an associated option flag, if any, as equivalent to
794the @samp{-c} option followed by that argument.)
7a292a7a
SS
795
796If @value{GDBN} has not been configured to included core file support,
797such as for most embedded targets, then it will complain about a second
798argument and ignore it.
c906108c
SS
799
800Many options have both long and short forms; both are shown in the
801following list. @value{GDBN} also recognizes the long forms if you truncate
802them, so long as enough of the option is present to be unambiguous.
803(If you prefer, you can flag option arguments with @samp{--} rather
804than @samp{-}, though we illustrate the more usual convention.)
805
d700128c
EZ
806@c NOTE: the @cindex entries here use double dashes ON PURPOSE. This
807@c way, both those who look for -foo and --foo in the index, will find
808@c it.
809
c906108c
SS
810@table @code
811@item -symbols @var{file}
812@itemx -s @var{file}
d700128c
EZ
813@cindex @code{--symbols}
814@cindex @code{-s}
c906108c
SS
815Read symbol table from file @var{file}.
816
817@item -exec @var{file}
818@itemx -e @var{file}
d700128c
EZ
819@cindex @code{--exec}
820@cindex @code{-e}
7a292a7a
SS
821Use file @var{file} as the executable file to execute when appropriate,
822and for examining pure data in conjunction with a core dump.
c906108c
SS
823
824@item -se @var{file}
d700128c 825@cindex @code{--se}
c906108c
SS
826Read symbol table from file @var{file} and use it as the executable
827file.
828
c906108c
SS
829@item -core @var{file}
830@itemx -c @var{file}
d700128c
EZ
831@cindex @code{--core}
832@cindex @code{-c}
c906108c
SS
833Use file @var{file} as a core dump to examine.
834
835@item -c @var{number}
836Connect to process ID @var{number}, as with the @code{attach} command
837(unless there is a file in core-dump format named @var{number}, in which
838case @samp{-c} specifies that file as a core dump to read).
c906108c
SS
839
840@item -command @var{file}
841@itemx -x @var{file}
d700128c
EZ
842@cindex @code{--command}
843@cindex @code{-x}
c906108c
SS
844Execute @value{GDBN} commands from file @var{file}. @xref{Command
845Files,, Command files}.
846
847@item -directory @var{directory}
848@itemx -d @var{directory}
d700128c
EZ
849@cindex @code{--directory}
850@cindex @code{-d}
c906108c
SS
851Add @var{directory} to the path to search for source files.
852
c906108c
SS
853@item -m
854@itemx -mapped
d700128c
EZ
855@cindex @code{--mapped}
856@cindex @code{-m}
c906108c
SS
857@emph{Warning: this option depends on operating system facilities that are not
858supported on all systems.}@*
859If memory-mapped files are available on your system through the @code{mmap}
5d161b24 860system call, you can use this option
c906108c
SS
861to have @value{GDBN} write the symbols from your
862program into a reusable file in the current directory. If the program you are debugging is
96a2c332 863called @file{/tmp/fred}, the mapped symbol file is @file{/tmp/fred.syms}.
c906108c
SS
864Future @value{GDBN} debugging sessions notice the presence of this file,
865and can quickly map in symbol information from it, rather than reading
866the symbol table from the executable program.
867
868The @file{.syms} file is specific to the host machine where @value{GDBN}
869is run. It holds an exact image of the internal @value{GDBN} symbol
870table. It cannot be shared across multiple host platforms.
c906108c 871
c906108c
SS
872@item -r
873@itemx -readnow
d700128c
EZ
874@cindex @code{--readnow}
875@cindex @code{-r}
c906108c
SS
876Read each symbol file's entire symbol table immediately, rather than
877the default, which is to read it incrementally as it is needed.
878This makes startup slower, but makes future operations faster.
53a5351d 879
c906108c
SS
880@end table
881
2df3850c 882You typically combine the @code{-mapped} and @code{-readnow} options in
c906108c 883order to build a @file{.syms} file that contains complete symbol
2df3850c
JM
884information. (@xref{Files,,Commands to specify files}, for information
885on @file{.syms} files.) A simple @value{GDBN} invocation to do nothing
886but build a @file{.syms} file for future use is:
c906108c
SS
887
888@example
2df3850c 889gdb -batch -nx -mapped -readnow programname
c906108c 890@end example
c906108c 891
6d2ebf8b 892@node Mode Options
c906108c
SS
893@subsection Choosing modes
894
895You can run @value{GDBN} in various alternative modes---for example, in
896batch mode or quiet mode.
897
898@table @code
899@item -nx
900@itemx -n
d700128c
EZ
901@cindex @code{--nx}
902@cindex @code{-n}
2df3850c
JM
903Do not execute commands found in any initialization files (normally
904called @file{.gdbinit}, or @file{gdb.ini} on PCs). Normally,
905@value{GDBN} executes the commands in these files after all the command
906options and arguments have been processed. @xref{Command Files,,Command
907files}.
c906108c
SS
908
909@item -quiet
d700128c 910@itemx -silent
c906108c 911@itemx -q
d700128c
EZ
912@cindex @code{--quiet}
913@cindex @code{--silent}
914@cindex @code{-q}
c906108c
SS
915``Quiet''. Do not print the introductory and copyright messages. These
916messages are also suppressed in batch mode.
917
918@item -batch
d700128c 919@cindex @code{--batch}
c906108c
SS
920Run in batch mode. Exit with status @code{0} after processing all the
921command files specified with @samp{-x} (and all commands from
922initialization files, if not inhibited with @samp{-n}). Exit with
923nonzero status if an error occurs in executing the @value{GDBN} commands
924in the command files.
925
2df3850c
JM
926Batch mode may be useful for running @value{GDBN} as a filter, for
927example to download and run a program on another computer; in order to
928make this more useful, the message
c906108c
SS
929
930@example
931Program exited normally.
932@end example
933
934@noindent
2df3850c
JM
935(which is ordinarily issued whenever a program running under
936@value{GDBN} control terminates) is not issued when running in batch
937mode.
938
939@item -nowindows
940@itemx -nw
d700128c
EZ
941@cindex @code{--nowindows}
942@cindex @code{-nw}
2df3850c 943``No windows''. If @value{GDBN} comes with a graphical user interface
96a2c332 944(GUI) built in, then this option tells @value{GDBN} to only use the command-line
2df3850c
JM
945interface. If no GUI is available, this option has no effect.
946
947@item -windows
948@itemx -w
d700128c
EZ
949@cindex @code{--windows}
950@cindex @code{-w}
2df3850c
JM
951If @value{GDBN} includes a GUI, then this option requires it to be
952used if possible.
c906108c
SS
953
954@item -cd @var{directory}
d700128c 955@cindex @code{--cd}
c906108c
SS
956Run @value{GDBN} using @var{directory} as its working directory,
957instead of the current directory.
958
c906108c
SS
959@item -fullname
960@itemx -f
d700128c
EZ
961@cindex @code{--fullname}
962@cindex @code{-f}
7a292a7a
SS
963@sc{gnu} Emacs sets this option when it runs @value{GDBN} as a
964subprocess. It tells @value{GDBN} to output the full file name and line
965number in a standard, recognizable fashion each time a stack frame is
966displayed (which includes each time your program stops). This
967recognizable format looks like two @samp{\032} characters, followed by
968the file name, line number and character position separated by colons,
969and a newline. The Emacs-to-@value{GDBN} interface program uses the two
970@samp{\032} characters as a signal to display the source code for the
971frame.
c906108c 972
d700128c
EZ
973@item -epoch
974@cindex @code{--epoch}
975The Epoch Emacs-@value{GDBN} interface sets this option when it runs
976@value{GDBN} as a subprocess. It tells @value{GDBN} to modify its print
977routines so as to allow Epoch to display values of expressions in a
978separate window.
979
980@item -annotate @var{level}
981@cindex @code{--annotate}
982This option sets the @dfn{annotation level} inside @value{GDBN}. Its
983effect is identical to using @samp{set annotate @var{level}}
984(@pxref{Annotations}).
985Annotation level controls how much information does @value{GDBN} print
986together with its prompt, values of expressions, source lines, and other
987types of output. Level 0 is the normal, level 1 is for use when
988@value{GDBN} is run as a subprocess of @sc{gnu} Emacs, level 2 is the
989maximum annotation suitable for programs that control @value{GDBN}.
990
991@item -async
992@cindex @code{--async}
993Use the asynchronous event loop for the command-line interface.
994@value{GDBN} processes all events, such as user keyboard input, via a
995special event loop. This allows @value{GDBN} to accept and process user
996commands in parallel with the debugged process being
997run@footnote{@value{GDBN} built with @sc{djgpp} tools for
998MS-DOS/MS-Windows supports this mode of operation, but the event loop is
999suspended when the debuggee runs.}, so you don't need to wait for
1000control to return to @value{GDBN} before you type the next command.
b37052ae 1001(@emph{Note:} as of version 5.1, the target side of the asynchronous
d700128c
EZ
1002operation is not yet in place, so @samp{-async} does not work fully
1003yet.)
1004@c FIXME: when the target side of the event loop is done, the above NOTE
1005@c should be removed.
1006
1007When the standard input is connected to a terminal device, @value{GDBN}
1008uses the asynchronous event loop by default, unless disabled by the
1009@samp{-noasync} option.
1010
1011@item -noasync
1012@cindex @code{--noasync}
1013Disable the asynchronous event loop for the command-line interface.
1014
2df3850c
JM
1015@item -baud @var{bps}
1016@itemx -b @var{bps}
d700128c
EZ
1017@cindex @code{--baud}
1018@cindex @code{-b}
c906108c
SS
1019Set the line speed (baud rate or bits per second) of any serial
1020interface used by @value{GDBN} for remote debugging.
c906108c
SS
1021
1022@item -tty @var{device}
d700128c
EZ
1023@itemx -t @var{device}
1024@cindex @code{--tty}
1025@cindex @code{-t}
c906108c
SS
1026Run using @var{device} for your program's standard input and output.
1027@c FIXME: kingdon thinks there is more to -tty. Investigate.
c906108c 1028
53a5351d 1029@c resolve the situation of these eventually
c4555f82
SC
1030@item -tui
1031@cindex @code{--tui}
1032Activate the Terminal User Interface when starting.
1033The Terminal User Interface manages several text windows on the terminal,
1034showing source, assembly, registers and @value{GDBN} command outputs
1035(@pxref{TUI, ,@value{GDBN} Text User Interface}).
1036Do not use this option if you run @value{GDBN} from Emacs
1037(@pxref{Emacs, ,Using @value{GDBN} under @sc{gnu} Emacs}).
53a5351d
JM
1038
1039@c @item -xdb
d700128c 1040@c @cindex @code{--xdb}
53a5351d
JM
1041@c Run in XDB compatibility mode, allowing the use of certain XDB commands.
1042@c For information, see the file @file{xdb_trans.html}, which is usually
1043@c installed in the directory @code{/opt/langtools/wdb/doc} on HP-UX
1044@c systems.
1045
d700128c
EZ
1046@item -interpreter @var{interp}
1047@cindex @code{--interpreter}
1048Use the interpreter @var{interp} for interface with the controlling
1049program or device. This option is meant to be set by programs which
94bbb2c0
AC
1050communicate with @value{GDBN} using it as a back end.
1051
1052@samp{--interpreter=mi} (or @samp{--interpreter=mi1}) causes
1053@value{GDBN} to use the @dfn{gdb/mi interface} (@pxref{GDB/MI, , The
1054@sc{gdb/mi} Interface}). The older @sc{gdb/mi} interface, included in
1055@value{GDBN} version 5.0 can be selected with @samp{--interpreter=mi0}.
d700128c
EZ
1056
1057@item -write
1058@cindex @code{--write}
1059Open the executable and core files for both reading and writing. This
1060is equivalent to the @samp{set write on} command inside @value{GDBN}
1061(@pxref{Patching}).
1062
1063@item -statistics
1064@cindex @code{--statistics}
1065This option causes @value{GDBN} to print statistics about time and
1066memory usage after it completes each command and returns to the prompt.
1067
1068@item -version
1069@cindex @code{--version}
1070This option causes @value{GDBN} to print its version number and
1071no-warranty blurb, and exit.
1072
c906108c
SS
1073@end table
1074
6d2ebf8b 1075@node Quitting GDB
c906108c
SS
1076@section Quitting @value{GDBN}
1077@cindex exiting @value{GDBN}
1078@cindex leaving @value{GDBN}
1079
1080@table @code
1081@kindex quit @r{[}@var{expression}@r{]}
41afff9a 1082@kindex q @r{(@code{quit})}
96a2c332
SS
1083@item quit @r{[}@var{expression}@r{]}
1084@itemx q
1085To exit @value{GDBN}, use the @code{quit} command (abbreviated
1086@code{q}), or type an end-of-file character (usually @kbd{C-d}). If you
1087do not supply @var{expression}, @value{GDBN} will terminate normally;
1088otherwise it will terminate using the result of @var{expression} as the
1089error code.
c906108c
SS
1090@end table
1091
1092@cindex interrupt
1093An interrupt (often @kbd{C-c}) does not exit from @value{GDBN}, but rather
1094terminates the action of any @value{GDBN} command that is in progress and
1095returns to @value{GDBN} command level. It is safe to type the interrupt
1096character at any time because @value{GDBN} does not allow it to take effect
1097until a time when it is safe.
1098
c906108c
SS
1099If you have been using @value{GDBN} to control an attached process or
1100device, you can release it with the @code{detach} command
1101(@pxref{Attach, ,Debugging an already-running process}).
c906108c 1102
6d2ebf8b 1103@node Shell Commands
c906108c
SS
1104@section Shell commands
1105
1106If you need to execute occasional shell commands during your
1107debugging session, there is no need to leave or suspend @value{GDBN}; you can
1108just use the @code{shell} command.
1109
1110@table @code
1111@kindex shell
1112@cindex shell escape
1113@item shell @var{command string}
1114Invoke a standard shell to execute @var{command string}.
c906108c 1115If it exists, the environment variable @code{SHELL} determines which
d4f3574e
SS
1116shell to run. Otherwise @value{GDBN} uses the default shell
1117(@file{/bin/sh} on Unix systems, @file{COMMAND.COM} on MS-DOS, etc.).
c906108c
SS
1118@end table
1119
1120The utility @code{make} is often needed in development environments.
1121You do not have to use the @code{shell} command for this purpose in
1122@value{GDBN}:
1123
1124@table @code
1125@kindex make
1126@cindex calling make
1127@item make @var{make-args}
1128Execute the @code{make} program with the specified
1129arguments. This is equivalent to @samp{shell make @var{make-args}}.
1130@end table
1131
6d2ebf8b 1132@node Commands
c906108c
SS
1133@chapter @value{GDBN} Commands
1134
1135You can abbreviate a @value{GDBN} command to the first few letters of the command
1136name, if that abbreviation is unambiguous; and you can repeat certain
1137@value{GDBN} commands by typing just @key{RET}. You can also use the @key{TAB}
1138key to get @value{GDBN} to fill out the rest of a word in a command (or to
1139show you the alternatives available, if there is more than one possibility).
1140
1141@menu
1142* Command Syntax:: How to give commands to @value{GDBN}
1143* Completion:: Command completion
1144* Help:: How to ask @value{GDBN} for help
1145@end menu
1146
6d2ebf8b 1147@node Command Syntax
c906108c
SS
1148@section Command syntax
1149
1150A @value{GDBN} command is a single line of input. There is no limit on
1151how long it can be. It starts with a command name, which is followed by
1152arguments whose meaning depends on the command name. For example, the
1153command @code{step} accepts an argument which is the number of times to
1154step, as in @samp{step 5}. You can also use the @code{step} command
96a2c332 1155with no arguments. Some commands do not allow any arguments.
c906108c
SS
1156
1157@cindex abbreviation
1158@value{GDBN} command names may always be truncated if that abbreviation is
1159unambiguous. Other possible command abbreviations are listed in the
1160documentation for individual commands. In some cases, even ambiguous
1161abbreviations are allowed; for example, @code{s} is specially defined as
1162equivalent to @code{step} even though there are other commands whose
1163names start with @code{s}. You can test abbreviations by using them as
1164arguments to the @code{help} command.
1165
1166@cindex repeating commands
41afff9a 1167@kindex RET @r{(repeat last command)}
c906108c 1168A blank line as input to @value{GDBN} (typing just @key{RET}) means to
96a2c332 1169repeat the previous command. Certain commands (for example, @code{run})
c906108c
SS
1170will not repeat this way; these are commands whose unintentional
1171repetition might cause trouble and which you are unlikely to want to
1172repeat.
1173
1174The @code{list} and @code{x} commands, when you repeat them with
1175@key{RET}, construct new arguments rather than repeating
1176exactly as typed. This permits easy scanning of source or memory.
1177
1178@value{GDBN} can also use @key{RET} in another way: to partition lengthy
1179output, in a way similar to the common utility @code{more}
1180(@pxref{Screen Size,,Screen size}). Since it is easy to press one
1181@key{RET} too many in this situation, @value{GDBN} disables command
1182repetition after any command that generates this sort of display.
1183
41afff9a 1184@kindex # @r{(a comment)}
c906108c
SS
1185@cindex comment
1186Any text from a @kbd{#} to the end of the line is a comment; it does
1187nothing. This is useful mainly in command files (@pxref{Command
1188Files,,Command files}).
1189
6d2ebf8b 1190@node Completion
c906108c
SS
1191@section Command completion
1192
1193@cindex completion
1194@cindex word completion
1195@value{GDBN} can fill in the rest of a word in a command for you, if there is
1196only one possibility; it can also show you what the valid possibilities
1197are for the next word in a command, at any time. This works for @value{GDBN}
1198commands, @value{GDBN} subcommands, and the names of symbols in your program.
1199
1200Press the @key{TAB} key whenever you want @value{GDBN} to fill out the rest
1201of a word. If there is only one possibility, @value{GDBN} fills in the
1202word, and waits for you to finish the command (or press @key{RET} to
1203enter it). For example, if you type
1204
1205@c FIXME "@key" does not distinguish its argument sufficiently to permit
1206@c complete accuracy in these examples; space introduced for clarity.
1207@c If texinfo enhancements make it unnecessary, it would be nice to
1208@c replace " @key" by "@key" in the following...
1209@example
1210(@value{GDBP}) info bre @key{TAB}
1211@end example
1212
1213@noindent
1214@value{GDBN} fills in the rest of the word @samp{breakpoints}, since that is
1215the only @code{info} subcommand beginning with @samp{bre}:
1216
1217@example
1218(@value{GDBP}) info breakpoints
1219@end example
1220
1221@noindent
1222You can either press @key{RET} at this point, to run the @code{info
1223breakpoints} command, or backspace and enter something else, if
1224@samp{breakpoints} does not look like the command you expected. (If you
1225were sure you wanted @code{info breakpoints} in the first place, you
1226might as well just type @key{RET} immediately after @samp{info bre},
1227to exploit command abbreviations rather than command completion).
1228
1229If there is more than one possibility for the next word when you press
1230@key{TAB}, @value{GDBN} sounds a bell. You can either supply more
1231characters and try again, or just press @key{TAB} a second time;
1232@value{GDBN} displays all the possible completions for that word. For
1233example, you might want to set a breakpoint on a subroutine whose name
1234begins with @samp{make_}, but when you type @kbd{b make_@key{TAB}} @value{GDBN}
1235just sounds the bell. Typing @key{TAB} again displays all the
1236function names in your program that begin with those characters, for
1237example:
1238
1239@example
1240(@value{GDBP}) b make_ @key{TAB}
1241@exdent @value{GDBN} sounds bell; press @key{TAB} again, to see:
5d161b24
DB
1242make_a_section_from_file make_environ
1243make_abs_section make_function_type
1244make_blockvector make_pointer_type
1245make_cleanup make_reference_type
c906108c
SS
1246make_command make_symbol_completion_list
1247(@value{GDBP}) b make_
1248@end example
1249
1250@noindent
1251After displaying the available possibilities, @value{GDBN} copies your
1252partial input (@samp{b make_} in the example) so you can finish the
1253command.
1254
1255If you just want to see the list of alternatives in the first place, you
b37052ae 1256can press @kbd{M-?} rather than pressing @key{TAB} twice. @kbd{M-?}
7a292a7a 1257means @kbd{@key{META} ?}. You can type this either by holding down a
c906108c 1258key designated as the @key{META} shift on your keyboard (if there is
7a292a7a 1259one) while typing @kbd{?}, or as @key{ESC} followed by @kbd{?}.
c906108c
SS
1260
1261@cindex quotes in commands
1262@cindex completion of quoted strings
1263Sometimes the string you need, while logically a ``word'', may contain
7a292a7a
SS
1264parentheses or other characters that @value{GDBN} normally excludes from
1265its notion of a word. To permit word completion to work in this
1266situation, you may enclose words in @code{'} (single quote marks) in
1267@value{GDBN} commands.
c906108c 1268
c906108c 1269The most likely situation where you might need this is in typing the
b37052ae
EZ
1270name of a C@t{++} function. This is because C@t{++} allows function
1271overloading (multiple definitions of the same function, distinguished
1272by argument type). For example, when you want to set a breakpoint you
1273may need to distinguish whether you mean the version of @code{name}
1274that takes an @code{int} parameter, @code{name(int)}, or the version
1275that takes a @code{float} parameter, @code{name(float)}. To use the
1276word-completion facilities in this situation, type a single quote
1277@code{'} at the beginning of the function name. This alerts
1278@value{GDBN} that it may need to consider more information than usual
1279when you press @key{TAB} or @kbd{M-?} to request word completion:
c906108c
SS
1280
1281@example
96a2c332 1282(@value{GDBP}) b 'bubble( @kbd{M-?}
c906108c
SS
1283bubble(double,double) bubble(int,int)
1284(@value{GDBP}) b 'bubble(
1285@end example
1286
1287In some cases, @value{GDBN} can tell that completing a name requires using
1288quotes. When this happens, @value{GDBN} inserts the quote for you (while
1289completing as much as it can) if you do not type the quote in the first
1290place:
1291
1292@example
1293(@value{GDBP}) b bub @key{TAB}
1294@exdent @value{GDBN} alters your input line to the following, and rings a bell:
1295(@value{GDBP}) b 'bubble(
1296@end example
1297
1298@noindent
1299In general, @value{GDBN} can tell that a quote is needed (and inserts it) if
1300you have not yet started typing the argument list when you ask for
1301completion on an overloaded symbol.
1302
d4f3574e 1303For more information about overloaded functions, see @ref{C plus plus
b37052ae 1304expressions, ,C@t{++} expressions}. You can use the command @code{set
c906108c 1305overload-resolution off} to disable overload resolution;
b37052ae 1306see @ref{Debugging C plus plus, ,@value{GDBN} features for C@t{++}}.
c906108c
SS
1307
1308
6d2ebf8b 1309@node Help
c906108c
SS
1310@section Getting help
1311@cindex online documentation
1312@kindex help
1313
5d161b24 1314You can always ask @value{GDBN} itself for information on its commands,
c906108c
SS
1315using the command @code{help}.
1316
1317@table @code
41afff9a 1318@kindex h @r{(@code{help})}
c906108c
SS
1319@item help
1320@itemx h
1321You can use @code{help} (abbreviated @code{h}) with no arguments to
1322display a short list of named classes of commands:
1323
1324@smallexample
1325(@value{GDBP}) help
1326List of classes of commands:
1327
2df3850c 1328aliases -- Aliases of other commands
c906108c 1329breakpoints -- Making program stop at certain points
2df3850c 1330data -- Examining data
c906108c 1331files -- Specifying and examining files
2df3850c
JM
1332internals -- Maintenance commands
1333obscure -- Obscure features
1334running -- Running the program
1335stack -- Examining the stack
c906108c
SS
1336status -- Status inquiries
1337support -- Support facilities
96a2c332
SS
1338tracepoints -- Tracing of program execution without@*
1339 stopping the program
c906108c 1340user-defined -- User-defined commands
c906108c 1341
5d161b24 1342Type "help" followed by a class name for a list of
c906108c 1343commands in that class.
5d161b24 1344Type "help" followed by command name for full
c906108c
SS
1345documentation.
1346Command name abbreviations are allowed if unambiguous.
1347(@value{GDBP})
1348@end smallexample
96a2c332 1349@c the above line break eliminates huge line overfull...
c906108c
SS
1350
1351@item help @var{class}
1352Using one of the general help classes as an argument, you can get a
1353list of the individual commands in that class. For example, here is the
1354help display for the class @code{status}:
1355
1356@smallexample
1357(@value{GDBP}) help status
1358Status inquiries.
1359
1360List of commands:
1361
1362@c Line break in "show" line falsifies real output, but needed
1363@c to fit in smallbook page size.
2df3850c
JM
1364info -- Generic command for showing things
1365 about the program being debugged
1366show -- Generic command for showing things
1367 about the debugger
c906108c 1368
5d161b24 1369Type "help" followed by command name for full
c906108c
SS
1370documentation.
1371Command name abbreviations are allowed if unambiguous.
1372(@value{GDBP})
1373@end smallexample
1374
1375@item help @var{command}
1376With a command name as @code{help} argument, @value{GDBN} displays a
1377short paragraph on how to use that command.
1378
6837a0a2
DB
1379@kindex apropos
1380@item apropos @var{args}
1381The @code{apropos @var{args}} command searches through all of the @value{GDBN}
1382commands, and their documentation, for the regular expression specified in
1383@var{args}. It prints out all matches found. For example:
1384
1385@smallexample
1386apropos reload
1387@end smallexample
1388
b37052ae
EZ
1389@noindent
1390results in:
6837a0a2
DB
1391
1392@smallexample
6d2ebf8b
SS
1393@c @group
1394set symbol-reloading -- Set dynamic symbol table reloading
1395 multiple times in one run
1396show symbol-reloading -- Show dynamic symbol table reloading
1397 multiple times in one run
1398@c @end group
6837a0a2
DB
1399@end smallexample
1400
c906108c
SS
1401@kindex complete
1402@item complete @var{args}
1403The @code{complete @var{args}} command lists all the possible completions
1404for the beginning of a command. Use @var{args} to specify the beginning of the
1405command you want completed. For example:
1406
1407@smallexample
1408complete i
1409@end smallexample
1410
1411@noindent results in:
1412
1413@smallexample
1414@group
2df3850c
JM
1415if
1416ignore
c906108c
SS
1417info
1418inspect
c906108c
SS
1419@end group
1420@end smallexample
1421
1422@noindent This is intended for use by @sc{gnu} Emacs.
1423@end table
1424
1425In addition to @code{help}, you can use the @value{GDBN} commands @code{info}
1426and @code{show} to inquire about the state of your program, or the state
1427of @value{GDBN} itself. Each command supports many topics of inquiry; this
1428manual introduces each of them in the appropriate context. The listings
1429under @code{info} and under @code{show} in the Index point to
1430all the sub-commands. @xref{Index}.
1431
1432@c @group
1433@table @code
1434@kindex info
41afff9a 1435@kindex i @r{(@code{info})}
c906108c
SS
1436@item info
1437This command (abbreviated @code{i}) is for describing the state of your
1438program. For example, you can list the arguments given to your program
1439with @code{info args}, list the registers currently in use with @code{info
1440registers}, or list the breakpoints you have set with @code{info breakpoints}.
1441You can get a complete list of the @code{info} sub-commands with
1442@w{@code{help info}}.
1443
1444@kindex set
1445@item set
5d161b24 1446You can assign the result of an expression to an environment variable with
c906108c
SS
1447@code{set}. For example, you can set the @value{GDBN} prompt to a $-sign with
1448@code{set prompt $}.
1449
1450@kindex show
1451@item show
5d161b24 1452In contrast to @code{info}, @code{show} is for describing the state of
c906108c
SS
1453@value{GDBN} itself.
1454You can change most of the things you can @code{show}, by using the
1455related command @code{set}; for example, you can control what number
1456system is used for displays with @code{set radix}, or simply inquire
1457which is currently in use with @code{show radix}.
1458
1459@kindex info set
1460To display all the settable parameters and their current
1461values, you can use @code{show} with no arguments; you may also use
1462@code{info set}. Both commands produce the same display.
1463@c FIXME: "info set" violates the rule that "info" is for state of
1464@c FIXME...program. Ck w/ GNU: "info set" to be called something else,
1465@c FIXME...or change desc of rule---eg "state of prog and debugging session"?
1466@end table
1467@c @end group
1468
1469Here are three miscellaneous @code{show} subcommands, all of which are
1470exceptional in lacking corresponding @code{set} commands:
1471
1472@table @code
1473@kindex show version
1474@cindex version number
1475@item show version
1476Show what version of @value{GDBN} is running. You should include this
2df3850c
JM
1477information in @value{GDBN} bug-reports. If multiple versions of
1478@value{GDBN} are in use at your site, you may need to determine which
1479version of @value{GDBN} you are running; as @value{GDBN} evolves, new
1480commands are introduced, and old ones may wither away. Also, many
1481system vendors ship variant versions of @value{GDBN}, and there are
96a2c332 1482variant versions of @value{GDBN} in @sc{gnu}/Linux distributions as well.
2df3850c
JM
1483The version number is the same as the one announced when you start
1484@value{GDBN}.
c906108c
SS
1485
1486@kindex show copying
1487@item show copying
1488Display information about permission for copying @value{GDBN}.
1489
1490@kindex show warranty
1491@item show warranty
2df3850c 1492Display the @sc{gnu} ``NO WARRANTY'' statement, or a warranty,
96a2c332 1493if your version of @value{GDBN} comes with one.
2df3850c 1494
c906108c
SS
1495@end table
1496
6d2ebf8b 1497@node Running
c906108c
SS
1498@chapter Running Programs Under @value{GDBN}
1499
1500When you run a program under @value{GDBN}, you must first generate
1501debugging information when you compile it.
7a292a7a
SS
1502
1503You may start @value{GDBN} with its arguments, if any, in an environment
1504of your choice. If you are doing native debugging, you may redirect
1505your program's input and output, debug an already running process, or
1506kill a child process.
c906108c
SS
1507
1508@menu
1509* Compilation:: Compiling for debugging
1510* Starting:: Starting your program
c906108c
SS
1511* Arguments:: Your program's arguments
1512* Environment:: Your program's environment
c906108c
SS
1513
1514* Working Directory:: Your program's working directory
1515* Input/Output:: Your program's input and output
1516* Attach:: Debugging an already-running process
1517* Kill Process:: Killing the child process
c906108c
SS
1518
1519* Threads:: Debugging programs with multiple threads
1520* Processes:: Debugging programs with multiple processes
1521@end menu
1522
6d2ebf8b 1523@node Compilation
c906108c
SS
1524@section Compiling for debugging
1525
1526In order to debug a program effectively, you need to generate
1527debugging information when you compile it. This debugging information
1528is stored in the object file; it describes the data type of each
1529variable or function and the correspondence between source line numbers
1530and addresses in the executable code.
1531
1532To request debugging information, specify the @samp{-g} option when you run
1533the compiler.
1534
1535Many C compilers are unable to handle the @samp{-g} and @samp{-O}
1536options together. Using those compilers, you cannot generate optimized
1537executables containing debugging information.
1538
53a5351d
JM
1539@value{NGCC}, the @sc{gnu} C compiler, supports @samp{-g} with or
1540without @samp{-O}, making it possible to debug optimized code. We
1541recommend that you @emph{always} use @samp{-g} whenever you compile a
1542program. You may think your program is correct, but there is no sense
1543in pushing your luck.
c906108c
SS
1544
1545@cindex optimized code, debugging
1546@cindex debugging optimized code
1547When you debug a program compiled with @samp{-g -O}, remember that the
1548optimizer is rearranging your code; the debugger shows you what is
1549really there. Do not be too surprised when the execution path does not
1550exactly match your source file! An extreme example: if you define a
1551variable, but never use it, @value{GDBN} never sees that
1552variable---because the compiler optimizes it out of existence.
1553
1554Some things do not work as well with @samp{-g -O} as with just
1555@samp{-g}, particularly on machines with instruction scheduling. If in
1556doubt, recompile with @samp{-g} alone, and if this fixes the problem,
1557please report it to us as a bug (including a test case!).
1558
1559Older versions of the @sc{gnu} C compiler permitted a variant option
1560@w{@samp{-gg}} for debugging information. @value{GDBN} no longer supports this
1561format; if your @sc{gnu} C compiler has this option, do not use it.
1562
1563@need 2000
6d2ebf8b 1564@node Starting
c906108c
SS
1565@section Starting your program
1566@cindex starting
1567@cindex running
1568
1569@table @code
1570@kindex run
41afff9a 1571@kindex r @r{(@code{run})}
c906108c
SS
1572@item run
1573@itemx r
7a292a7a
SS
1574Use the @code{run} command to start your program under @value{GDBN}.
1575You must first specify the program name (except on VxWorks) with an
1576argument to @value{GDBN} (@pxref{Invocation, ,Getting In and Out of
1577@value{GDBN}}), or by using the @code{file} or @code{exec-file} command
1578(@pxref{Files, ,Commands to specify files}).
c906108c
SS
1579
1580@end table
1581
c906108c
SS
1582If you are running your program in an execution environment that
1583supports processes, @code{run} creates an inferior process and makes
1584that process run your program. (In environments without processes,
1585@code{run} jumps to the start of your program.)
1586
1587The execution of a program is affected by certain information it
1588receives from its superior. @value{GDBN} provides ways to specify this
1589information, which you must do @emph{before} starting your program. (You
1590can change it after starting your program, but such changes only affect
1591your program the next time you start it.) This information may be
1592divided into four categories:
1593
1594@table @asis
1595@item The @emph{arguments.}
1596Specify the arguments to give your program as the arguments of the
1597@code{run} command. If a shell is available on your target, the shell
1598is used to pass the arguments, so that you may use normal conventions
1599(such as wildcard expansion or variable substitution) in describing
1600the arguments.
1601In Unix systems, you can control which shell is used with the
1602@code{SHELL} environment variable.
1603@xref{Arguments, ,Your program's arguments}.
1604
1605@item The @emph{environment.}
1606Your program normally inherits its environment from @value{GDBN}, but you can
1607use the @value{GDBN} commands @code{set environment} and @code{unset
1608environment} to change parts of the environment that affect
1609your program. @xref{Environment, ,Your program's environment}.
1610
1611@item The @emph{working directory.}
1612Your program inherits its working directory from @value{GDBN}. You can set
1613the @value{GDBN} working directory with the @code{cd} command in @value{GDBN}.
1614@xref{Working Directory, ,Your program's working directory}.
1615
1616@item The @emph{standard input and output.}
1617Your program normally uses the same device for standard input and
1618standard output as @value{GDBN} is using. You can redirect input and output
1619in the @code{run} command line, or you can use the @code{tty} command to
1620set a different device for your program.
1621@xref{Input/Output, ,Your program's input and output}.
1622
1623@cindex pipes
1624@emph{Warning:} While input and output redirection work, you cannot use
1625pipes to pass the output of the program you are debugging to another
1626program; if you attempt this, @value{GDBN} is likely to wind up debugging the
1627wrong program.
1628@end table
c906108c
SS
1629
1630When you issue the @code{run} command, your program begins to execute
1631immediately. @xref{Stopping, ,Stopping and continuing}, for discussion
1632of how to arrange for your program to stop. Once your program has
1633stopped, you may call functions in your program, using the @code{print}
1634or @code{call} commands. @xref{Data, ,Examining Data}.
1635
1636If the modification time of your symbol file has changed since the last
1637time @value{GDBN} read its symbols, @value{GDBN} discards its symbol
1638table, and reads it again. When it does this, @value{GDBN} tries to retain
1639your current breakpoints.
1640
6d2ebf8b 1641@node Arguments
c906108c
SS
1642@section Your program's arguments
1643
1644@cindex arguments (to your program)
1645The arguments to your program can be specified by the arguments of the
5d161b24 1646@code{run} command.
c906108c
SS
1647They are passed to a shell, which expands wildcard characters and
1648performs redirection of I/O, and thence to your program. Your
1649@code{SHELL} environment variable (if it exists) specifies what shell
1650@value{GDBN} uses. If you do not define @code{SHELL}, @value{GDBN} uses
d4f3574e
SS
1651the default shell (@file{/bin/sh} on Unix).
1652
1653On non-Unix systems, the program is usually invoked directly by
1654@value{GDBN}, which emulates I/O redirection via the appropriate system
1655calls, and the wildcard characters are expanded by the startup code of
1656the program, not by the shell.
c906108c
SS
1657
1658@code{run} with no arguments uses the same arguments used by the previous
1659@code{run}, or those set by the @code{set args} command.
1660
c906108c 1661@table @code
41afff9a 1662@kindex set args
c906108c
SS
1663@item set args
1664Specify the arguments to be used the next time your program is run. If
1665@code{set args} has no arguments, @code{run} executes your program
1666with no arguments. Once you have run your program with arguments,
1667using @code{set args} before the next @code{run} is the only way to run
1668it again without arguments.
1669
1670@kindex show args
1671@item show args
1672Show the arguments to give your program when it is started.
1673@end table
1674
6d2ebf8b 1675@node Environment
c906108c
SS
1676@section Your program's environment
1677
1678@cindex environment (of your program)
1679The @dfn{environment} consists of a set of environment variables and
1680their values. Environment variables conventionally record such things as
1681your user name, your home directory, your terminal type, and your search
1682path for programs to run. Usually you set up environment variables with
1683the shell and they are inherited by all the other programs you run. When
1684debugging, it can be useful to try running your program with a modified
1685environment without having to start @value{GDBN} over again.
1686
1687@table @code
1688@kindex path
1689@item path @var{directory}
1690Add @var{directory} to the front of the @code{PATH} environment variable
17cc6a06
EZ
1691(the search path for executables) that will be passed to your program.
1692The value of @code{PATH} used by @value{GDBN} does not change.
d4f3574e
SS
1693You may specify several directory names, separated by whitespace or by a
1694system-dependent separator character (@samp{:} on Unix, @samp{;} on
1695MS-DOS and MS-Windows). If @var{directory} is already in the path, it
1696is moved to the front, so it is searched sooner.
c906108c
SS
1697
1698You can use the string @samp{$cwd} to refer to whatever is the current
1699working directory at the time @value{GDBN} searches the path. If you
1700use @samp{.} instead, it refers to the directory where you executed the
1701@code{path} command. @value{GDBN} replaces @samp{.} in the
1702@var{directory} argument (with the current path) before adding
1703@var{directory} to the search path.
1704@c 'path' is explicitly nonrepeatable, but RMS points out it is silly to
1705@c document that, since repeating it would be a no-op.
1706
1707@kindex show paths
1708@item show paths
1709Display the list of search paths for executables (the @code{PATH}
1710environment variable).
1711
1712@kindex show environment
1713@item show environment @r{[}@var{varname}@r{]}
1714Print the value of environment variable @var{varname} to be given to
1715your program when it starts. If you do not supply @var{varname},
1716print the names and values of all environment variables to be given to
1717your program. You can abbreviate @code{environment} as @code{env}.
1718
1719@kindex set environment
53a5351d 1720@item set environment @var{varname} @r{[}=@var{value}@r{]}
c906108c
SS
1721Set environment variable @var{varname} to @var{value}. The value
1722changes for your program only, not for @value{GDBN} itself. @var{value} may
1723be any string; the values of environment variables are just strings, and
1724any interpretation is supplied by your program itself. The @var{value}
1725parameter is optional; if it is eliminated, the variable is set to a
1726null value.
1727@c "any string" here does not include leading, trailing
1728@c blanks. Gnu asks: does anyone care?
1729
1730For example, this command:
1731
1732@example
1733set env USER = foo
1734@end example
1735
1736@noindent
d4f3574e 1737tells the debugged program, when subsequently run, that its user is named
c906108c
SS
1738@samp{foo}. (The spaces around @samp{=} are used for clarity here; they
1739are not actually required.)
1740
1741@kindex unset environment
1742@item unset environment @var{varname}
1743Remove variable @var{varname} from the environment to be passed to your
1744program. This is different from @samp{set env @var{varname} =};
1745@code{unset environment} removes the variable from the environment,
1746rather than assigning it an empty value.
1747@end table
1748
d4f3574e
SS
1749@emph{Warning:} On Unix systems, @value{GDBN} runs your program using
1750the shell indicated
c906108c
SS
1751by your @code{SHELL} environment variable if it exists (or
1752@code{/bin/sh} if not). If your @code{SHELL} variable names a shell
1753that runs an initialization file---such as @file{.cshrc} for C-shell, or
1754@file{.bashrc} for BASH---any variables you set in that file affect
1755your program. You may wish to move setting of environment variables to
1756files that are only run when you sign on, such as @file{.login} or
1757@file{.profile}.
1758
6d2ebf8b 1759@node Working Directory
c906108c
SS
1760@section Your program's working directory
1761
1762@cindex working directory (of your program)
1763Each time you start your program with @code{run}, it inherits its
1764working directory from the current working directory of @value{GDBN}.
1765The @value{GDBN} working directory is initially whatever it inherited
1766from its parent process (typically the shell), but you can specify a new
1767working directory in @value{GDBN} with the @code{cd} command.
1768
1769The @value{GDBN} working directory also serves as a default for the commands
1770that specify files for @value{GDBN} to operate on. @xref{Files, ,Commands to
1771specify files}.
1772
1773@table @code
1774@kindex cd
1775@item cd @var{directory}
1776Set the @value{GDBN} working directory to @var{directory}.
1777
1778@kindex pwd
1779@item pwd
1780Print the @value{GDBN} working directory.
1781@end table
1782
6d2ebf8b 1783@node Input/Output
c906108c
SS
1784@section Your program's input and output
1785
1786@cindex redirection
1787@cindex i/o
1788@cindex terminal
1789By default, the program you run under @value{GDBN} does input and output to
5d161b24 1790the same terminal that @value{GDBN} uses. @value{GDBN} switches the terminal
c906108c
SS
1791to its own terminal modes to interact with you, but it records the terminal
1792modes your program was using and switches back to them when you continue
1793running your program.
1794
1795@table @code
1796@kindex info terminal
1797@item info terminal
1798Displays information recorded by @value{GDBN} about the terminal modes your
1799program is using.
1800@end table
1801
1802You can redirect your program's input and/or output using shell
1803redirection with the @code{run} command. For example,
1804
1805@example
1806run > outfile
1807@end example
1808
1809@noindent
1810starts your program, diverting its output to the file @file{outfile}.
1811
1812@kindex tty
1813@cindex controlling terminal
1814Another way to specify where your program should do input and output is
1815with the @code{tty} command. This command accepts a file name as
1816argument, and causes this file to be the default for future @code{run}
1817commands. It also resets the controlling terminal for the child
1818process, for future @code{run} commands. For example,
1819
1820@example
1821tty /dev/ttyb
1822@end example
1823
1824@noindent
1825directs that processes started with subsequent @code{run} commands
1826default to do input and output on the terminal @file{/dev/ttyb} and have
1827that as their controlling terminal.
1828
1829An explicit redirection in @code{run} overrides the @code{tty} command's
1830effect on the input/output device, but not its effect on the controlling
1831terminal.
1832
1833When you use the @code{tty} command or redirect input in the @code{run}
1834command, only the input @emph{for your program} is affected. The input
1835for @value{GDBN} still comes from your terminal.
1836
6d2ebf8b 1837@node Attach
c906108c
SS
1838@section Debugging an already-running process
1839@kindex attach
1840@cindex attach
1841
1842@table @code
1843@item attach @var{process-id}
1844This command attaches to a running process---one that was started
1845outside @value{GDBN}. (@code{info files} shows your active
1846targets.) The command takes as argument a process ID. The usual way to
1847find out the process-id of a Unix process is with the @code{ps} utility,
1848or with the @samp{jobs -l} shell command.
1849
1850@code{attach} does not repeat if you press @key{RET} a second time after
1851executing the command.
1852@end table
1853
1854To use @code{attach}, your program must be running in an environment
1855which supports processes; for example, @code{attach} does not work for
1856programs on bare-board targets that lack an operating system. You must
1857also have permission to send the process a signal.
1858
1859When you use @code{attach}, the debugger finds the program running in
1860the process first by looking in the current working directory, then (if
1861the program is not found) by using the source file search path
1862(@pxref{Source Path, ,Specifying source directories}). You can also use
1863the @code{file} command to load the program. @xref{Files, ,Commands to
1864Specify Files}.
1865
1866The first thing @value{GDBN} does after arranging to debug the specified
1867process is to stop it. You can examine and modify an attached process
53a5351d
JM
1868with all the @value{GDBN} commands that are ordinarily available when
1869you start processes with @code{run}. You can insert breakpoints; you
1870can step and continue; you can modify storage. If you would rather the
1871process continue running, you may use the @code{continue} command after
c906108c
SS
1872attaching @value{GDBN} to the process.
1873
1874@table @code
1875@kindex detach
1876@item detach
1877When you have finished debugging the attached process, you can use the
1878@code{detach} command to release it from @value{GDBN} control. Detaching
1879the process continues its execution. After the @code{detach} command,
1880that process and @value{GDBN} become completely independent once more, and you
1881are ready to @code{attach} another process or start one with @code{run}.
1882@code{detach} does not repeat if you press @key{RET} again after
1883executing the command.
1884@end table
1885
1886If you exit @value{GDBN} or use the @code{run} command while you have an
1887attached process, you kill that process. By default, @value{GDBN} asks
1888for confirmation if you try to do either of these things; you can
1889control whether or not you need to confirm by using the @code{set
1890confirm} command (@pxref{Messages/Warnings, ,Optional warnings and
1891messages}).
1892
6d2ebf8b 1893@node Kill Process
c906108c 1894@section Killing the child process
c906108c
SS
1895
1896@table @code
1897@kindex kill
1898@item kill
1899Kill the child process in which your program is running under @value{GDBN}.
1900@end table
1901
1902This command is useful if you wish to debug a core dump instead of a
1903running process. @value{GDBN} ignores any core dump file while your program
1904is running.
1905
1906On some operating systems, a program cannot be executed outside @value{GDBN}
1907while you have breakpoints set on it inside @value{GDBN}. You can use the
1908@code{kill} command in this situation to permit running your program
1909outside the debugger.
1910
1911The @code{kill} command is also useful if you wish to recompile and
1912relink your program, since on many systems it is impossible to modify an
1913executable file while it is running in a process. In this case, when you
1914next type @code{run}, @value{GDBN} notices that the file has changed, and
1915reads the symbol table again (while trying to preserve your current
1916breakpoint settings).
1917
6d2ebf8b 1918@node Threads
c906108c 1919@section Debugging programs with multiple threads
c906108c
SS
1920
1921@cindex threads of execution
1922@cindex multiple threads
1923@cindex switching threads
1924In some operating systems, such as HP-UX and Solaris, a single program
1925may have more than one @dfn{thread} of execution. The precise semantics
1926of threads differ from one operating system to another, but in general
1927the threads of a single program are akin to multiple processes---except
1928that they share one address space (that is, they can all examine and
1929modify the same variables). On the other hand, each thread has its own
1930registers and execution stack, and perhaps private memory.
1931
1932@value{GDBN} provides these facilities for debugging multi-thread
1933programs:
1934
1935@itemize @bullet
1936@item automatic notification of new threads
1937@item @samp{thread @var{threadno}}, a command to switch among threads
1938@item @samp{info threads}, a command to inquire about existing threads
5d161b24 1939@item @samp{thread apply [@var{threadno}] [@var{all}] @var{args}},
c906108c
SS
1940a command to apply a command to a list of threads
1941@item thread-specific breakpoints
1942@end itemize
1943
c906108c
SS
1944@quotation
1945@emph{Warning:} These facilities are not yet available on every
1946@value{GDBN} configuration where the operating system supports threads.
1947If your @value{GDBN} does not support threads, these commands have no
1948effect. For example, a system without thread support shows no output
1949from @samp{info threads}, and always rejects the @code{thread} command,
1950like this:
1951
1952@smallexample
1953(@value{GDBP}) info threads
1954(@value{GDBP}) thread 1
1955Thread ID 1 not known. Use the "info threads" command to
1956see the IDs of currently known threads.
1957@end smallexample
1958@c FIXME to implementors: how hard would it be to say "sorry, this GDB
1959@c doesn't support threads"?
1960@end quotation
c906108c
SS
1961
1962@cindex focus of debugging
1963@cindex current thread
1964The @value{GDBN} thread debugging facility allows you to observe all
1965threads while your program runs---but whenever @value{GDBN} takes
1966control, one thread in particular is always the focus of debugging.
1967This thread is called the @dfn{current thread}. Debugging commands show
1968program information from the perspective of the current thread.
1969
41afff9a 1970@cindex @code{New} @var{systag} message
c906108c
SS
1971@cindex thread identifier (system)
1972@c FIXME-implementors!! It would be more helpful if the [New...] message
1973@c included GDB's numeric thread handle, so you could just go to that
1974@c thread without first checking `info threads'.
1975Whenever @value{GDBN} detects a new thread in your program, it displays
1976the target system's identification for the thread with a message in the
1977form @samp{[New @var{systag}]}. @var{systag} is a thread identifier
1978whose form varies depending on the particular system. For example, on
1979LynxOS, you might see
1980
1981@example
1982[New process 35 thread 27]
1983@end example
1984
1985@noindent
1986when @value{GDBN} notices a new thread. In contrast, on an SGI system,
1987the @var{systag} is simply something like @samp{process 368}, with no
1988further qualifier.
1989
1990@c FIXME!! (1) Does the [New...] message appear even for the very first
1991@c thread of a program, or does it only appear for the
1992@c second---i.e., when it becomes obvious we have a multithread
1993@c program?
1994@c (2) *Is* there necessarily a first thread always? Or do some
1995@c multithread systems permit starting a program with multiple
5d161b24 1996@c threads ab initio?
c906108c
SS
1997
1998@cindex thread number
1999@cindex thread identifier (GDB)
2000For debugging purposes, @value{GDBN} associates its own thread
2001number---always a single integer---with each thread in your program.
2002
2003@table @code
2004@kindex info threads
2005@item info threads
2006Display a summary of all threads currently in your
2007program. @value{GDBN} displays for each thread (in this order):
2008
2009@enumerate
2010@item the thread number assigned by @value{GDBN}
2011
2012@item the target system's thread identifier (@var{systag})
2013
2014@item the current stack frame summary for that thread
2015@end enumerate
2016
2017@noindent
2018An asterisk @samp{*} to the left of the @value{GDBN} thread number
2019indicates the current thread.
2020
5d161b24 2021For example,
c906108c
SS
2022@end table
2023@c end table here to get a little more width for example
2024
2025@smallexample
2026(@value{GDBP}) info threads
2027 3 process 35 thread 27 0x34e5 in sigpause ()
2028 2 process 35 thread 23 0x34e5 in sigpause ()
2029* 1 process 35 thread 13 main (argc=1, argv=0x7ffffff8)
2030 at threadtest.c:68
2031@end smallexample
53a5351d
JM
2032
2033On HP-UX systems:
c906108c
SS
2034
2035@cindex thread number
2036@cindex thread identifier (GDB)
2037For debugging purposes, @value{GDBN} associates its own thread
2038number---a small integer assigned in thread-creation order---with each
2039thread in your program.
2040
41afff9a
EZ
2041@cindex @code{New} @var{systag} message, on HP-UX
2042@cindex thread identifier (system), on HP-UX
c906108c
SS
2043@c FIXME-implementors!! It would be more helpful if the [New...] message
2044@c included GDB's numeric thread handle, so you could just go to that
2045@c thread without first checking `info threads'.
2046Whenever @value{GDBN} detects a new thread in your program, it displays
2047both @value{GDBN}'s thread number and the target system's identification for the thread with a message in the
2048form @samp{[New @var{systag}]}. @var{systag} is a thread identifier
2049whose form varies depending on the particular system. For example, on
2050HP-UX, you see
2051
2052@example
2053[New thread 2 (system thread 26594)]
2054@end example
2055
2056@noindent
5d161b24 2057when @value{GDBN} notices a new thread.
c906108c
SS
2058
2059@table @code
2060@kindex info threads
2061@item info threads
2062Display a summary of all threads currently in your
2063program. @value{GDBN} displays for each thread (in this order):
2064
2065@enumerate
2066@item the thread number assigned by @value{GDBN}
2067
2068@item the target system's thread identifier (@var{systag})
2069
2070@item the current stack frame summary for that thread
2071@end enumerate
2072
2073@noindent
2074An asterisk @samp{*} to the left of the @value{GDBN} thread number
2075indicates the current thread.
2076
5d161b24 2077For example,
c906108c
SS
2078@end table
2079@c end table here to get a little more width for example
2080
2081@example
2082(@value{GDBP}) info threads
6d2ebf8b
SS
2083 * 3 system thread 26607 worker (wptr=0x7b09c318 "@@") \@*
2084 at quicksort.c:137
2085 2 system thread 26606 0x7b0030d8 in __ksleep () \@*
2086 from /usr/lib/libc.2
2087 1 system thread 27905 0x7b003498 in _brk () \@*
2088 from /usr/lib/libc.2
c906108c 2089@end example
c906108c
SS
2090
2091@table @code
2092@kindex thread @var{threadno}
2093@item thread @var{threadno}
2094Make thread number @var{threadno} the current thread. The command
2095argument @var{threadno} is the internal @value{GDBN} thread number, as
2096shown in the first field of the @samp{info threads} display.
2097@value{GDBN} responds by displaying the system identifier of the thread
2098you selected, and its current stack frame summary:
2099
2100@smallexample
2101@c FIXME!! This example made up; find a @value{GDBN} w/threads and get real one
2102(@value{GDBP}) thread 2
c906108c 2103[Switching to process 35 thread 23]
c906108c
SS
21040x34e5 in sigpause ()
2105@end smallexample
2106
2107@noindent
2108As with the @samp{[New @dots{}]} message, the form of the text after
2109@samp{Switching to} depends on your system's conventions for identifying
5d161b24 2110threads.
c906108c
SS
2111
2112@kindex thread apply
2113@item thread apply [@var{threadno}] [@var{all}] @var{args}
2114The @code{thread apply} command allows you to apply a command to one or
2115more threads. Specify the numbers of the threads that you want affected
2116with the command argument @var{threadno}. @var{threadno} is the internal
2117@value{GDBN} thread number, as shown in the first field of the @samp{info
5d161b24
DB
2118threads} display. To apply a command to all threads, use
2119@code{thread apply all} @var{args}.
c906108c
SS
2120@end table
2121
2122@cindex automatic thread selection
2123@cindex switching threads automatically
2124@cindex threads, automatic switching
2125Whenever @value{GDBN} stops your program, due to a breakpoint or a
2126signal, it automatically selects the thread where that breakpoint or
2127signal happened. @value{GDBN} alerts you to the context switch with a
2128message of the form @samp{[Switching to @var{systag}]} to identify the
2129thread.
2130
2131@xref{Thread Stops,,Stopping and starting multi-thread programs}, for
2132more information about how @value{GDBN} behaves when you stop and start
2133programs with multiple threads.
2134
2135@xref{Set Watchpoints,,Setting watchpoints}, for information about
2136watchpoints in programs with multiple threads.
c906108c 2137
6d2ebf8b 2138@node Processes
c906108c
SS
2139@section Debugging programs with multiple processes
2140
2141@cindex fork, debugging programs which call
2142@cindex multiple processes
2143@cindex processes, multiple
53a5351d
JM
2144On most systems, @value{GDBN} has no special support for debugging
2145programs which create additional processes using the @code{fork}
2146function. When a program forks, @value{GDBN} will continue to debug the
2147parent process and the child process will run unimpeded. If you have
2148set a breakpoint in any code which the child then executes, the child
2149will get a @code{SIGTRAP} signal which (unless it catches the signal)
2150will cause it to terminate.
c906108c
SS
2151
2152However, if you want to debug the child process there is a workaround
2153which isn't too painful. Put a call to @code{sleep} in the code which
2154the child process executes after the fork. It may be useful to sleep
2155only if a certain environment variable is set, or a certain file exists,
2156so that the delay need not occur when you don't want to run @value{GDBN}
2157on the child. While the child is sleeping, use the @code{ps} program to
2158get its process ID. Then tell @value{GDBN} (a new invocation of
2159@value{GDBN} if you are also debugging the parent process) to attach to
d4f3574e 2160the child process (@pxref{Attach}). From that point on you can debug
c906108c 2161the child process just like any other process which you attached to.
c906108c 2162
53a5351d
JM
2163On HP-UX (11.x and later only?), @value{GDBN} provides support for
2164debugging programs that create additional processes using the
2165@code{fork} or @code{vfork} function.
c906108c
SS
2166
2167By default, when a program forks, @value{GDBN} will continue to debug
2168the parent process and the child process will run unimpeded.
2169
2170If you want to follow the child process instead of the parent process,
2171use the command @w{@code{set follow-fork-mode}}.
2172
2173@table @code
2174@kindex set follow-fork-mode
2175@item set follow-fork-mode @var{mode}
2176Set the debugger response to a program call of @code{fork} or
2177@code{vfork}. A call to @code{fork} or @code{vfork} creates a new
2178process. The @var{mode} can be:
2179
2180@table @code
2181@item parent
2182The original process is debugged after a fork. The child process runs
2df3850c 2183unimpeded. This is the default.
c906108c
SS
2184
2185@item child
2186The new process is debugged after a fork. The parent process runs
2187unimpeded.
2188
2189@item ask
2190The debugger will ask for one of the above choices.
2191@end table
2192
2193@item show follow-fork-mode
2df3850c 2194Display the current debugger response to a @code{fork} or @code{vfork} call.
c906108c
SS
2195@end table
2196
2197If you ask to debug a child process and a @code{vfork} is followed by an
2198@code{exec}, @value{GDBN} executes the new target up to the first
2199breakpoint in the new target. If you have a breakpoint set on
2200@code{main} in your original program, the breakpoint will also be set on
2201the child process's @code{main}.
2202
2203When a child process is spawned by @code{vfork}, you cannot debug the
2204child or parent until an @code{exec} call completes.
2205
2206If you issue a @code{run} command to @value{GDBN} after an @code{exec}
2207call executes, the new target restarts. To restart the parent process,
2208use the @code{file} command with the parent executable name as its
2209argument.
2210
2211You can use the @code{catch} command to make @value{GDBN} stop whenever
2212a @code{fork}, @code{vfork}, or @code{exec} call is made. @xref{Set
2213Catchpoints, ,Setting catchpoints}.
c906108c 2214
6d2ebf8b 2215@node Stopping
c906108c
SS
2216@chapter Stopping and Continuing
2217
2218The principal purposes of using a debugger are so that you can stop your
2219program before it terminates; or so that, if your program runs into
2220trouble, you can investigate and find out why.
2221
7a292a7a
SS
2222Inside @value{GDBN}, your program may stop for any of several reasons,
2223such as a signal, a breakpoint, or reaching a new line after a
2224@value{GDBN} command such as @code{step}. You may then examine and
2225change variables, set new breakpoints or remove old ones, and then
2226continue execution. Usually, the messages shown by @value{GDBN} provide
2227ample explanation of the status of your program---but you can also
2228explicitly request this information at any time.
c906108c
SS
2229
2230@table @code
2231@kindex info program
2232@item info program
2233Display information about the status of your program: whether it is
7a292a7a 2234running or not, what process it is, and why it stopped.
c906108c
SS
2235@end table
2236
2237@menu
2238* Breakpoints:: Breakpoints, watchpoints, and catchpoints
2239* Continuing and Stepping:: Resuming execution
c906108c 2240* Signals:: Signals
c906108c 2241* Thread Stops:: Stopping and starting multi-thread programs
c906108c
SS
2242@end menu
2243
6d2ebf8b 2244@node Breakpoints
c906108c
SS
2245@section Breakpoints, watchpoints, and catchpoints
2246
2247@cindex breakpoints
2248A @dfn{breakpoint} makes your program stop whenever a certain point in
2249the program is reached. For each breakpoint, you can add conditions to
2250control in finer detail whether your program stops. You can set
2251breakpoints with the @code{break} command and its variants (@pxref{Set
2252Breaks, ,Setting breakpoints}), to specify the place where your program
2253should stop by line number, function name or exact address in the
2254program.
2255
2256In HP-UX, SunOS 4.x, SVR4, and Alpha OSF/1 configurations, you can set
2257breakpoints in shared libraries before the executable is run. There is
2258a minor limitation on HP-UX systems: you must wait until the executable
2259is run in order to set breakpoints in shared library routines that are
2260not called directly by the program (for example, routines that are
2261arguments in a @code{pthread_create} call).
2262
2263@cindex watchpoints
2264@cindex memory tracing
2265@cindex breakpoint on memory address
2266@cindex breakpoint on variable modification
2267A @dfn{watchpoint} is a special breakpoint that stops your program
2268when the value of an expression changes. You must use a different
2269command to set watchpoints (@pxref{Set Watchpoints, ,Setting
2270watchpoints}), but aside from that, you can manage a watchpoint like
2271any other breakpoint: you enable, disable, and delete both breakpoints
2272and watchpoints using the same commands.
2273
2274You can arrange to have values from your program displayed automatically
2275whenever @value{GDBN} stops at a breakpoint. @xref{Auto Display,,
2276Automatic display}.
2277
2278@cindex catchpoints
2279@cindex breakpoint on events
2280A @dfn{catchpoint} is another special breakpoint that stops your program
b37052ae 2281when a certain kind of event occurs, such as the throwing of a C@t{++}
c906108c
SS
2282exception or the loading of a library. As with watchpoints, you use a
2283different command to set a catchpoint (@pxref{Set Catchpoints, ,Setting
2284catchpoints}), but aside from that, you can manage a catchpoint like any
2285other breakpoint. (To stop when your program receives a signal, use the
d4f3574e 2286@code{handle} command; see @ref{Signals, ,Signals}.)
c906108c
SS
2287
2288@cindex breakpoint numbers
2289@cindex numbers for breakpoints
2290@value{GDBN} assigns a number to each breakpoint, watchpoint, or
2291catchpoint when you create it; these numbers are successive integers
2292starting with one. In many of the commands for controlling various
2293features of breakpoints you use the breakpoint number to say which
2294breakpoint you want to change. Each breakpoint may be @dfn{enabled} or
2295@dfn{disabled}; if disabled, it has no effect on your program until you
2296enable it again.
2297
c5394b80
JM
2298@cindex breakpoint ranges
2299@cindex ranges of breakpoints
2300Some @value{GDBN} commands accept a range of breakpoints on which to
2301operate. A breakpoint range is either a single breakpoint number, like
2302@samp{5}, or two such numbers, in increasing order, separated by a
2303hyphen, like @samp{5-7}. When a breakpoint range is given to a command,
2304all breakpoint in that range are operated on.
2305
c906108c
SS
2306@menu
2307* Set Breaks:: Setting breakpoints
2308* Set Watchpoints:: Setting watchpoints
2309* Set Catchpoints:: Setting catchpoints
2310* Delete Breaks:: Deleting breakpoints
2311* Disabling:: Disabling breakpoints
2312* Conditions:: Break conditions
2313* Break Commands:: Breakpoint command lists
c906108c 2314* Breakpoint Menus:: Breakpoint menus
d4f3574e 2315* Error in Breakpoints:: ``Cannot insert breakpoints''
c906108c
SS
2316@end menu
2317
6d2ebf8b 2318@node Set Breaks
c906108c
SS
2319@subsection Setting breakpoints
2320
5d161b24 2321@c FIXME LMB what does GDB do if no code on line of breakpt?
c906108c
SS
2322@c consider in particular declaration with/without initialization.
2323@c
2324@c FIXME 2 is there stuff on this already? break at fun start, already init?
2325
2326@kindex break
41afff9a
EZ
2327@kindex b @r{(@code{break})}
2328@vindex $bpnum@r{, convenience variable}
c906108c
SS
2329@cindex latest breakpoint
2330Breakpoints are set with the @code{break} command (abbreviated
5d161b24 2331@code{b}). The debugger convenience variable @samp{$bpnum} records the
f3b28801 2332number of the breakpoint you've set most recently; see @ref{Convenience
c906108c
SS
2333Vars,, Convenience variables}, for a discussion of what you can do with
2334convenience variables.
2335
2336You have several ways to say where the breakpoint should go.
2337
2338@table @code
2339@item break @var{function}
5d161b24 2340Set a breakpoint at entry to function @var{function}.
c906108c 2341When using source languages that permit overloading of symbols, such as
b37052ae 2342C@t{++}, @var{function} may refer to more than one possible place to break.
c906108c 2343@xref{Breakpoint Menus,,Breakpoint menus}, for a discussion of that situation.
c906108c
SS
2344
2345@item break +@var{offset}
2346@itemx break -@var{offset}
2347Set a breakpoint some number of lines forward or back from the position
d4f3574e 2348at which execution stopped in the currently selected @dfn{stack frame}.
2df3850c 2349(@xref{Frames, ,Frames}, for a description of stack frames.)
c906108c
SS
2350
2351@item break @var{linenum}
2352Set a breakpoint at line @var{linenum} in the current source file.
d4f3574e
SS
2353The current source file is the last file whose source text was printed.
2354The breakpoint will stop your program just before it executes any of the
c906108c
SS
2355code on that line.
2356
2357@item break @var{filename}:@var{linenum}
2358Set a breakpoint at line @var{linenum} in source file @var{filename}.
2359
2360@item break @var{filename}:@var{function}
2361Set a breakpoint at entry to function @var{function} found in file
2362@var{filename}. Specifying a file name as well as a function name is
2363superfluous except when multiple files contain similarly named
2364functions.
2365
2366@item break *@var{address}
2367Set a breakpoint at address @var{address}. You can use this to set
2368breakpoints in parts of your program which do not have debugging
2369information or source files.
2370
2371@item break
2372When called without any arguments, @code{break} sets a breakpoint at
2373the next instruction to be executed in the selected stack frame
2374(@pxref{Stack, ,Examining the Stack}). In any selected frame but the
2375innermost, this makes your program stop as soon as control
2376returns to that frame. This is similar to the effect of a
2377@code{finish} command in the frame inside the selected frame---except
2378that @code{finish} does not leave an active breakpoint. If you use
2379@code{break} without an argument in the innermost frame, @value{GDBN} stops
2380the next time it reaches the current location; this may be useful
2381inside loops.
2382
2383@value{GDBN} normally ignores breakpoints when it resumes execution, until at
2384least one instruction has been executed. If it did not do this, you
2385would be unable to proceed past a breakpoint without first disabling the
2386breakpoint. This rule applies whether or not the breakpoint already
2387existed when your program stopped.
2388
2389@item break @dots{} if @var{cond}
2390Set a breakpoint with condition @var{cond}; evaluate the expression
2391@var{cond} each time the breakpoint is reached, and stop only if the
2392value is nonzero---that is, if @var{cond} evaluates as true.
2393@samp{@dots{}} stands for one of the possible arguments described
2394above (or no argument) specifying where to break. @xref{Conditions,
2395,Break conditions}, for more information on breakpoint conditions.
2396
2397@kindex tbreak
2398@item tbreak @var{args}
2399Set a breakpoint enabled only for one stop. @var{args} are the
2400same as for the @code{break} command, and the breakpoint is set in the same
2401way, but the breakpoint is automatically deleted after the first time your
2402program stops there. @xref{Disabling, ,Disabling breakpoints}.
2403
c906108c
SS
2404@kindex hbreak
2405@item hbreak @var{args}
d4f3574e
SS
2406Set a hardware-assisted breakpoint. @var{args} are the same as for the
2407@code{break} command and the breakpoint is set in the same way, but the
c906108c
SS
2408breakpoint requires hardware support and some target hardware may not
2409have this support. The main purpose of this is EPROM/ROM code
d4f3574e
SS
2410debugging, so you can set a breakpoint at an instruction without
2411changing the instruction. This can be used with the new trap-generation
2412provided by SPARClite DSU and some x86-based targets. These targets
2413will generate traps when a program accesses some data or instruction
2414address that is assigned to the debug registers. However the hardware
2415breakpoint registers can take a limited number of breakpoints. For
2416example, on the DSU, only two data breakpoints can be set at a time, and
2417@value{GDBN} will reject this command if more than two are used. Delete
2418or disable unused hardware breakpoints before setting new ones
2419(@pxref{Disabling, ,Disabling}). @xref{Conditions, ,Break conditions}.
c906108c
SS
2420
2421@kindex thbreak
2422@item thbreak @var{args}
2423Set a hardware-assisted breakpoint enabled only for one stop. @var{args}
2424are the same as for the @code{hbreak} command and the breakpoint is set in
5d161b24 2425the same way. However, like the @code{tbreak} command,
c906108c
SS
2426the breakpoint is automatically deleted after the
2427first time your program stops there. Also, like the @code{hbreak}
5d161b24
DB
2428command, the breakpoint requires hardware support and some target hardware
2429may not have this support. @xref{Disabling, ,Disabling breakpoints}.
d4f3574e 2430See also @ref{Conditions, ,Break conditions}.
c906108c
SS
2431
2432@kindex rbreak
2433@cindex regular expression
2434@item rbreak @var{regex}
c906108c 2435Set breakpoints on all functions matching the regular expression
11cf8741
JM
2436@var{regex}. This command sets an unconditional breakpoint on all
2437matches, printing a list of all breakpoints it set. Once these
2438breakpoints are set, they are treated just like the breakpoints set with
2439the @code{break} command. You can delete them, disable them, or make
2440them conditional the same way as any other breakpoint.
2441
2442The syntax of the regular expression is the standard one used with tools
2443like @file{grep}. Note that this is different from the syntax used by
2444shells, so for instance @code{foo*} matches all functions that include
2445an @code{fo} followed by zero or more @code{o}s. There is an implicit
2446@code{.*} leading and trailing the regular expression you supply, so to
2447match only functions that begin with @code{foo}, use @code{^foo}.
c906108c 2448
b37052ae 2449When debugging C@t{++} programs, @code{rbreak} is useful for setting
c906108c
SS
2450breakpoints on overloaded functions that are not members of any special
2451classes.
c906108c
SS
2452
2453@kindex info breakpoints
2454@cindex @code{$_} and @code{info breakpoints}
2455@item info breakpoints @r{[}@var{n}@r{]}
2456@itemx info break @r{[}@var{n}@r{]}
2457@itemx info watchpoints @r{[}@var{n}@r{]}
2458Print a table of all breakpoints, watchpoints, and catchpoints set and
2459not deleted, with the following columns for each breakpoint:
2460
2461@table @emph
2462@item Breakpoint Numbers
2463@item Type
2464Breakpoint, watchpoint, or catchpoint.
2465@item Disposition
2466Whether the breakpoint is marked to be disabled or deleted when hit.
2467@item Enabled or Disabled
2468Enabled breakpoints are marked with @samp{y}. @samp{n} marks breakpoints
2469that are not enabled.
2470@item Address
2df3850c 2471Where the breakpoint is in your program, as a memory address.
c906108c
SS
2472@item What
2473Where the breakpoint is in the source for your program, as a file and
2474line number.
2475@end table
2476
2477@noindent
2478If a breakpoint is conditional, @code{info break} shows the condition on
2479the line following the affected breakpoint; breakpoint commands, if any,
2480are listed after that.
2481
2482@noindent
2483@code{info break} with a breakpoint
2484number @var{n} as argument lists only that breakpoint. The
2485convenience variable @code{$_} and the default examining-address for
2486the @code{x} command are set to the address of the last breakpoint
5d161b24 2487listed (@pxref{Memory, ,Examining memory}).
c906108c
SS
2488
2489@noindent
2490@code{info break} displays a count of the number of times the breakpoint
2491has been hit. This is especially useful in conjunction with the
2492@code{ignore} command. You can ignore a large number of breakpoint
2493hits, look at the breakpoint info to see how many times the breakpoint
2494was hit, and then run again, ignoring one less than that number. This
2495will get you quickly to the last hit of that breakpoint.
2496@end table
2497
2498@value{GDBN} allows you to set any number of breakpoints at the same place in
2499your program. There is nothing silly or meaningless about this. When
2500the breakpoints are conditional, this is even useful
2501(@pxref{Conditions, ,Break conditions}).
2502
2503@cindex negative breakpoint numbers
2504@cindex internal @value{GDBN} breakpoints
2505@value{GDBN} itself sometimes sets breakpoints in your program for special
2506purposes, such as proper handling of @code{longjmp} (in C programs).
2507These internal breakpoints are assigned negative numbers, starting with
2508@code{-1}; @samp{info breakpoints} does not display them.
2509
2510You can see these breakpoints with the @value{GDBN} maintenance command
2511@samp{maint info breakpoints}.
2512
2513@table @code
2514@kindex maint info breakpoints
2515@item maint info breakpoints
2516Using the same format as @samp{info breakpoints}, display both the
2517breakpoints you've set explicitly, and those @value{GDBN} is using for
2518internal purposes. Internal breakpoints are shown with negative
2519breakpoint numbers. The type column identifies what kind of breakpoint
2520is shown:
2521
2522@table @code
2523@item breakpoint
2524Normal, explicitly set breakpoint.
2525
2526@item watchpoint
2527Normal, explicitly set watchpoint.
2528
2529@item longjmp
2530Internal breakpoint, used to handle correctly stepping through
2531@code{longjmp} calls.
2532
2533@item longjmp resume
2534Internal breakpoint at the target of a @code{longjmp}.
2535
2536@item until
2537Temporary internal breakpoint used by the @value{GDBN} @code{until} command.
2538
2539@item finish
2540Temporary internal breakpoint used by the @value{GDBN} @code{finish} command.
2541
c906108c
SS
2542@item shlib events
2543Shared library events.
53a5351d 2544
c906108c 2545@end table
53a5351d 2546
c906108c
SS
2547@end table
2548
2549
6d2ebf8b 2550@node Set Watchpoints
c906108c
SS
2551@subsection Setting watchpoints
2552
2553@cindex setting watchpoints
2554@cindex software watchpoints
2555@cindex hardware watchpoints
2556You can use a watchpoint to stop execution whenever the value of an
2557expression changes, without having to predict a particular place where
2558this may happen.
2559
2560Depending on your system, watchpoints may be implemented in software or
2df3850c 2561hardware. @value{GDBN} does software watchpointing by single-stepping your
c906108c
SS
2562program and testing the variable's value each time, which is hundreds of
2563times slower than normal execution. (But this may still be worth it, to
2564catch errors where you have no clue what part of your program is the
2565culprit.)
2566
d4f3574e 2567On some systems, such as HP-UX, Linux and some other x86-based targets,
2df3850c 2568@value{GDBN} includes support for
c906108c
SS
2569hardware watchpoints, which do not slow down the running of your
2570program.
2571
2572@table @code
2573@kindex watch
2574@item watch @var{expr}
2575Set a watchpoint for an expression. @value{GDBN} will break when @var{expr}
2576is written into by the program and its value changes.
2577
2578@kindex rwatch
2579@item rwatch @var{expr}
2580Set a watchpoint that will break when watch @var{expr} is read by the program.
c906108c
SS
2581
2582@kindex awatch
2583@item awatch @var{expr}
2df3850c 2584Set a watchpoint that will break when @var{expr} is either read or written into
7be570e7 2585by the program.
c906108c
SS
2586
2587@kindex info watchpoints
2588@item info watchpoints
2589This command prints a list of watchpoints, breakpoints, and catchpoints;
2590it is the same as @code{info break}.
2591@end table
2592
2593@value{GDBN} sets a @dfn{hardware watchpoint} if possible. Hardware
2594watchpoints execute very quickly, and the debugger reports a change in
2595value at the exact instruction where the change occurs. If @value{GDBN}
2596cannot set a hardware watchpoint, it sets a software watchpoint, which
2597executes more slowly and reports the change in value at the next
2598statement, not the instruction, after the change occurs.
2599
2600When you issue the @code{watch} command, @value{GDBN} reports
2601
2602@example
2603Hardware watchpoint @var{num}: @var{expr}
2604@end example
2605
2606@noindent
2607if it was able to set a hardware watchpoint.
2608
7be570e7
JM
2609Currently, the @code{awatch} and @code{rwatch} commands can only set
2610hardware watchpoints, because accesses to data that don't change the
2611value of the watched expression cannot be detected without examining
2612every instruction as it is being executed, and @value{GDBN} does not do
2613that currently. If @value{GDBN} finds that it is unable to set a
2614hardware breakpoint with the @code{awatch} or @code{rwatch} command, it
2615will print a message like this:
2616
2617@smallexample
2618Expression cannot be implemented with read/access watchpoint.
2619@end smallexample
2620
2621Sometimes, @value{GDBN} cannot set a hardware watchpoint because the
2622data type of the watched expression is wider than what a hardware
2623watchpoint on the target machine can handle. For example, some systems
2624can only watch regions that are up to 4 bytes wide; on such systems you
2625cannot set hardware watchpoints for an expression that yields a
2626double-precision floating-point number (which is typically 8 bytes
2627wide). As a work-around, it might be possible to break the large region
2628into a series of smaller ones and watch them with separate watchpoints.
2629
2630If you set too many hardware watchpoints, @value{GDBN} might be unable
2631to insert all of them when you resume the execution of your program.
2632Since the precise number of active watchpoints is unknown until such
2633time as the program is about to be resumed, @value{GDBN} might not be
2634able to warn you about this when you set the watchpoints, and the
2635warning will be printed only when the program is resumed:
2636
2637@smallexample
2638Hardware watchpoint @var{num}: Could not insert watchpoint
2639@end smallexample
2640
2641@noindent
2642If this happens, delete or disable some of the watchpoints.
2643
2644The SPARClite DSU will generate traps when a program accesses some data
2645or instruction address that is assigned to the debug registers. For the
2646data addresses, DSU facilitates the @code{watch} command. However the
2647hardware breakpoint registers can only take two data watchpoints, and
2648both watchpoints must be the same kind. For example, you can set two
2649watchpoints with @code{watch} commands, two with @code{rwatch} commands,
2650@strong{or} two with @code{awatch} commands, but you cannot set one
2651watchpoint with one command and the other with a different command.
c906108c
SS
2652@value{GDBN} will reject the command if you try to mix watchpoints.
2653Delete or disable unused watchpoint commands before setting new ones.
2654
2655If you call a function interactively using @code{print} or @code{call},
2df3850c 2656any watchpoints you have set will be inactive until @value{GDBN} reaches another
c906108c
SS
2657kind of breakpoint or the call completes.
2658
7be570e7
JM
2659@value{GDBN} automatically deletes watchpoints that watch local
2660(automatic) variables, or expressions that involve such variables, when
2661they go out of scope, that is, when the execution leaves the block in
2662which these variables were defined. In particular, when the program
2663being debugged terminates, @emph{all} local variables go out of scope,
2664and so only watchpoints that watch global variables remain set. If you
2665rerun the program, you will need to set all such watchpoints again. One
2666way of doing that would be to set a code breakpoint at the entry to the
2667@code{main} function and when it breaks, set all the watchpoints.
2668
c906108c
SS
2669@quotation
2670@cindex watchpoints and threads
2671@cindex threads and watchpoints
c906108c
SS
2672@emph{Warning:} In multi-thread programs, watchpoints have only limited
2673usefulness. With the current watchpoint implementation, @value{GDBN}
2674can only watch the value of an expression @emph{in a single thread}. If
2675you are confident that the expression can only change due to the current
2676thread's activity (and if you are also confident that no other thread
2677can become current), then you can use watchpoints as usual. However,
2678@value{GDBN} may not notice when a non-current thread's activity changes
2679the expression.
53a5351d 2680
d4f3574e 2681@c FIXME: this is almost identical to the previous paragraph.
53a5351d
JM
2682@emph{HP-UX Warning:} In multi-thread programs, software watchpoints
2683have only limited usefulness. If @value{GDBN} creates a software
2684watchpoint, it can only watch the value of an expression @emph{in a
2685single thread}. If you are confident that the expression can only
2686change due to the current thread's activity (and if you are also
2687confident that no other thread can become current), then you can use
2688software watchpoints as usual. However, @value{GDBN} may not notice
2689when a non-current thread's activity changes the expression. (Hardware
2690watchpoints, in contrast, watch an expression in all threads.)
c906108c 2691@end quotation
c906108c 2692
6d2ebf8b 2693@node Set Catchpoints
c906108c 2694@subsection Setting catchpoints
d4f3574e 2695@cindex catchpoints, setting
c906108c
SS
2696@cindex exception handlers
2697@cindex event handling
2698
2699You can use @dfn{catchpoints} to cause the debugger to stop for certain
b37052ae 2700kinds of program events, such as C@t{++} exceptions or the loading of a
c906108c
SS
2701shared library. Use the @code{catch} command to set a catchpoint.
2702
2703@table @code
2704@kindex catch
2705@item catch @var{event}
2706Stop when @var{event} occurs. @var{event} can be any of the following:
2707@table @code
2708@item throw
2709@kindex catch throw
b37052ae 2710The throwing of a C@t{++} exception.
c906108c
SS
2711
2712@item catch
2713@kindex catch catch
b37052ae 2714The catching of a C@t{++} exception.
c906108c
SS
2715
2716@item exec
2717@kindex catch exec
2718A call to @code{exec}. This is currently only available for HP-UX.
2719
2720@item fork
2721@kindex catch fork
2722A call to @code{fork}. This is currently only available for HP-UX.
2723
2724@item vfork
2725@kindex catch vfork
2726A call to @code{vfork}. This is currently only available for HP-UX.
2727
2728@item load
2729@itemx load @var{libname}
2730@kindex catch load
2731The dynamic loading of any shared library, or the loading of the library
2732@var{libname}. This is currently only available for HP-UX.
2733
2734@item unload
2735@itemx unload @var{libname}
2736@kindex catch unload
2737The unloading of any dynamically loaded shared library, or the unloading
2738of the library @var{libname}. This is currently only available for HP-UX.
2739@end table
2740
2741@item tcatch @var{event}
2742Set a catchpoint that is enabled only for one stop. The catchpoint is
2743automatically deleted after the first time the event is caught.
2744
2745@end table
2746
2747Use the @code{info break} command to list the current catchpoints.
2748
b37052ae 2749There are currently some limitations to C@t{++} exception handling
c906108c
SS
2750(@code{catch throw} and @code{catch catch}) in @value{GDBN}:
2751
2752@itemize @bullet
2753@item
2754If you call a function interactively, @value{GDBN} normally returns
2755control to you when the function has finished executing. If the call
2756raises an exception, however, the call may bypass the mechanism that
2757returns control to you and cause your program either to abort or to
2758simply continue running until it hits a breakpoint, catches a signal
2759that @value{GDBN} is listening for, or exits. This is the case even if
2760you set a catchpoint for the exception; catchpoints on exceptions are
2761disabled within interactive calls.
2762
2763@item
2764You cannot raise an exception interactively.
2765
2766@item
2767You cannot install an exception handler interactively.
2768@end itemize
2769
2770@cindex raise exceptions
2771Sometimes @code{catch} is not the best way to debug exception handling:
2772if you need to know exactly where an exception is raised, it is better to
2773stop @emph{before} the exception handler is called, since that way you
2774can see the stack before any unwinding takes place. If you set a
2775breakpoint in an exception handler instead, it may not be easy to find
2776out where the exception was raised.
2777
2778To stop just before an exception handler is called, you need some
b37052ae 2779knowledge of the implementation. In the case of @sc{gnu} C@t{++}, exceptions are
c906108c
SS
2780raised by calling a library function named @code{__raise_exception}
2781which has the following ANSI C interface:
2782
2783@example
2784 /* @var{addr} is where the exception identifier is stored.
d4f3574e
SS
2785 @var{id} is the exception identifier. */
2786 void __raise_exception (void **addr, void *id);
c906108c
SS
2787@end example
2788
2789@noindent
2790To make the debugger catch all exceptions before any stack
2791unwinding takes place, set a breakpoint on @code{__raise_exception}
2792(@pxref{Breakpoints, ,Breakpoints; watchpoints; and exceptions}).
2793
2794With a conditional breakpoint (@pxref{Conditions, ,Break conditions})
2795that depends on the value of @var{id}, you can stop your program when
2796a specific exception is raised. You can use multiple conditional
2797breakpoints to stop your program when any of a number of exceptions are
2798raised.
2799
2800
6d2ebf8b 2801@node Delete Breaks
c906108c
SS
2802@subsection Deleting breakpoints
2803
2804@cindex clearing breakpoints, watchpoints, catchpoints
2805@cindex deleting breakpoints, watchpoints, catchpoints
2806It is often necessary to eliminate a breakpoint, watchpoint, or
2807catchpoint once it has done its job and you no longer want your program
2808to stop there. This is called @dfn{deleting} the breakpoint. A
2809breakpoint that has been deleted no longer exists; it is forgotten.
2810
2811With the @code{clear} command you can delete breakpoints according to
2812where they are in your program. With the @code{delete} command you can
2813delete individual breakpoints, watchpoints, or catchpoints by specifying
2814their breakpoint numbers.
2815
2816It is not necessary to delete a breakpoint to proceed past it. @value{GDBN}
2817automatically ignores breakpoints on the first instruction to be executed
2818when you continue execution without changing the execution address.
2819
2820@table @code
2821@kindex clear
2822@item clear
2823Delete any breakpoints at the next instruction to be executed in the
2824selected stack frame (@pxref{Selection, ,Selecting a frame}). When
2825the innermost frame is selected, this is a good way to delete a
2826breakpoint where your program just stopped.
2827
2828@item clear @var{function}
2829@itemx clear @var{filename}:@var{function}
2830Delete any breakpoints set at entry to the function @var{function}.
2831
2832@item clear @var{linenum}
2833@itemx clear @var{filename}:@var{linenum}
2834Delete any breakpoints set at or within the code of the specified line.
2835
2836@cindex delete breakpoints
2837@kindex delete
41afff9a 2838@kindex d @r{(@code{delete})}
c5394b80
JM
2839@item delete @r{[}breakpoints@r{]} @r{[}@var{range}@dots{}@r{]}
2840Delete the breakpoints, watchpoints, or catchpoints of the breakpoint
2841ranges specified as arguments. If no argument is specified, delete all
c906108c
SS
2842breakpoints (@value{GDBN} asks confirmation, unless you have @code{set
2843confirm off}). You can abbreviate this command as @code{d}.
2844@end table
2845
6d2ebf8b 2846@node Disabling
c906108c
SS
2847@subsection Disabling breakpoints
2848
2849@kindex disable breakpoints
2850@kindex enable breakpoints
2851Rather than deleting a breakpoint, watchpoint, or catchpoint, you might
2852prefer to @dfn{disable} it. This makes the breakpoint inoperative as if
2853it had been deleted, but remembers the information on the breakpoint so
2854that you can @dfn{enable} it again later.
2855
2856You disable and enable breakpoints, watchpoints, and catchpoints with
2857the @code{enable} and @code{disable} commands, optionally specifying one
2858or more breakpoint numbers as arguments. Use @code{info break} or
2859@code{info watch} to print a list of breakpoints, watchpoints, and
2860catchpoints if you do not know which numbers to use.
2861
2862A breakpoint, watchpoint, or catchpoint can have any of four different
2863states of enablement:
2864
2865@itemize @bullet
2866@item
2867Enabled. The breakpoint stops your program. A breakpoint set
2868with the @code{break} command starts out in this state.
2869@item
2870Disabled. The breakpoint has no effect on your program.
2871@item
2872Enabled once. The breakpoint stops your program, but then becomes
d4f3574e 2873disabled.
c906108c
SS
2874@item
2875Enabled for deletion. The breakpoint stops your program, but
d4f3574e
SS
2876immediately after it does so it is deleted permanently. A breakpoint
2877set with the @code{tbreak} command starts out in this state.
c906108c
SS
2878@end itemize
2879
2880You can use the following commands to enable or disable breakpoints,
2881watchpoints, and catchpoints:
2882
2883@table @code
2884@kindex disable breakpoints
2885@kindex disable
41afff9a 2886@kindex dis @r{(@code{disable})}
c5394b80 2887@item disable @r{[}breakpoints@r{]} @r{[}@var{range}@dots{}@r{]}
c906108c
SS
2888Disable the specified breakpoints---or all breakpoints, if none are
2889listed. A disabled breakpoint has no effect but is not forgotten. All
2890options such as ignore-counts, conditions and commands are remembered in
2891case the breakpoint is enabled again later. You may abbreviate
2892@code{disable} as @code{dis}.
2893
2894@kindex enable breakpoints
2895@kindex enable
c5394b80 2896@item enable @r{[}breakpoints@r{]} @r{[}@var{range}@dots{}@r{]}
c906108c
SS
2897Enable the specified breakpoints (or all defined breakpoints). They
2898become effective once again in stopping your program.
2899
c5394b80 2900@item enable @r{[}breakpoints@r{]} once @var{range}@dots{}
c906108c
SS
2901Enable the specified breakpoints temporarily. @value{GDBN} disables any
2902of these breakpoints immediately after stopping your program.
2903
c5394b80 2904@item enable @r{[}breakpoints@r{]} delete @var{range}@dots{}
c906108c
SS
2905Enable the specified breakpoints to work once, then die. @value{GDBN}
2906deletes any of these breakpoints as soon as your program stops there.
2907@end table
2908
d4f3574e
SS
2909@c FIXME: I think the following ``Except for [...] @code{tbreak}'' is
2910@c confusing: tbreak is also initially enabled.
c906108c
SS
2911Except for a breakpoint set with @code{tbreak} (@pxref{Set Breaks,
2912,Setting breakpoints}), breakpoints that you set are initially enabled;
2913subsequently, they become disabled or enabled only when you use one of
2914the commands above. (The command @code{until} can set and delete a
2915breakpoint of its own, but it does not change the state of your other
2916breakpoints; see @ref{Continuing and Stepping, ,Continuing and
2917stepping}.)
2918
6d2ebf8b 2919@node Conditions
c906108c
SS
2920@subsection Break conditions
2921@cindex conditional breakpoints
2922@cindex breakpoint conditions
2923
2924@c FIXME what is scope of break condition expr? Context where wanted?
5d161b24 2925@c in particular for a watchpoint?
c906108c
SS
2926The simplest sort of breakpoint breaks every time your program reaches a
2927specified place. You can also specify a @dfn{condition} for a
2928breakpoint. A condition is just a Boolean expression in your
2929programming language (@pxref{Expressions, ,Expressions}). A breakpoint with
2930a condition evaluates the expression each time your program reaches it,
2931and your program stops only if the condition is @emph{true}.
2932
2933This is the converse of using assertions for program validation; in that
2934situation, you want to stop when the assertion is violated---that is,
2935when the condition is false. In C, if you want to test an assertion expressed
2936by the condition @var{assert}, you should set the condition
2937@samp{! @var{assert}} on the appropriate breakpoint.
2938
2939Conditions are also accepted for watchpoints; you may not need them,
2940since a watchpoint is inspecting the value of an expression anyhow---but
2941it might be simpler, say, to just set a watchpoint on a variable name,
2942and specify a condition that tests whether the new value is an interesting
2943one.
2944
2945Break conditions can have side effects, and may even call functions in
2946your program. This can be useful, for example, to activate functions
2947that log program progress, or to use your own print functions to
2948format special data structures. The effects are completely predictable
2949unless there is another enabled breakpoint at the same address. (In
2950that case, @value{GDBN} might see the other breakpoint first and stop your
2951program without checking the condition of this one.) Note that
d4f3574e
SS
2952breakpoint commands are usually more convenient and flexible than break
2953conditions for the
c906108c
SS
2954purpose of performing side effects when a breakpoint is reached
2955(@pxref{Break Commands, ,Breakpoint command lists}).
2956
2957Break conditions can be specified when a breakpoint is set, by using
2958@samp{if} in the arguments to the @code{break} command. @xref{Set
2959Breaks, ,Setting breakpoints}. They can also be changed at any time
2960with the @code{condition} command.
53a5351d 2961
c906108c
SS
2962You can also use the @code{if} keyword with the @code{watch} command.
2963The @code{catch} command does not recognize the @code{if} keyword;
2964@code{condition} is the only way to impose a further condition on a
2965catchpoint.
c906108c
SS
2966
2967@table @code
2968@kindex condition
2969@item condition @var{bnum} @var{expression}
2970Specify @var{expression} as the break condition for breakpoint,
2971watchpoint, or catchpoint number @var{bnum}. After you set a condition,
2972breakpoint @var{bnum} stops your program only if the value of
2973@var{expression} is true (nonzero, in C). When you use
2974@code{condition}, @value{GDBN} checks @var{expression} immediately for
2975syntactic correctness, and to determine whether symbols in it have
d4f3574e
SS
2976referents in the context of your breakpoint. If @var{expression} uses
2977symbols not referenced in the context of the breakpoint, @value{GDBN}
2978prints an error message:
2979
2980@example
2981No symbol "foo" in current context.
2982@end example
2983
2984@noindent
c906108c
SS
2985@value{GDBN} does
2986not actually evaluate @var{expression} at the time the @code{condition}
d4f3574e
SS
2987command (or a command that sets a breakpoint with a condition, like
2988@code{break if @dots{}}) is given, however. @xref{Expressions, ,Expressions}.
c906108c
SS
2989
2990@item condition @var{bnum}
2991Remove the condition from breakpoint number @var{bnum}. It becomes
2992an ordinary unconditional breakpoint.
2993@end table
2994
2995@cindex ignore count (of breakpoint)
2996A special case of a breakpoint condition is to stop only when the
2997breakpoint has been reached a certain number of times. This is so
2998useful that there is a special way to do it, using the @dfn{ignore
2999count} of the breakpoint. Every breakpoint has an ignore count, which
3000is an integer. Most of the time, the ignore count is zero, and
3001therefore has no effect. But if your program reaches a breakpoint whose
3002ignore count is positive, then instead of stopping, it just decrements
3003the ignore count by one and continues. As a result, if the ignore count
3004value is @var{n}, the breakpoint does not stop the next @var{n} times
3005your program reaches it.
3006
3007@table @code
3008@kindex ignore
3009@item ignore @var{bnum} @var{count}
3010Set the ignore count of breakpoint number @var{bnum} to @var{count}.
3011The next @var{count} times the breakpoint is reached, your program's
3012execution does not stop; other than to decrement the ignore count, @value{GDBN}
3013takes no action.
3014
3015To make the breakpoint stop the next time it is reached, specify
3016a count of zero.
3017
3018When you use @code{continue} to resume execution of your program from a
3019breakpoint, you can specify an ignore count directly as an argument to
3020@code{continue}, rather than using @code{ignore}. @xref{Continuing and
3021Stepping,,Continuing and stepping}.
3022
3023If a breakpoint has a positive ignore count and a condition, the
3024condition is not checked. Once the ignore count reaches zero,
3025@value{GDBN} resumes checking the condition.
3026
3027You could achieve the effect of the ignore count with a condition such
3028as @w{@samp{$foo-- <= 0}} using a debugger convenience variable that
3029is decremented each time. @xref{Convenience Vars, ,Convenience
3030variables}.
3031@end table
3032
3033Ignore counts apply to breakpoints, watchpoints, and catchpoints.
3034
3035
6d2ebf8b 3036@node Break Commands
c906108c
SS
3037@subsection Breakpoint command lists
3038
3039@cindex breakpoint commands
3040You can give any breakpoint (or watchpoint or catchpoint) a series of
3041commands to execute when your program stops due to that breakpoint. For
3042example, you might want to print the values of certain expressions, or
3043enable other breakpoints.
3044
3045@table @code
3046@kindex commands
3047@kindex end
3048@item commands @r{[}@var{bnum}@r{]}
3049@itemx @dots{} @var{command-list} @dots{}
3050@itemx end
3051Specify a list of commands for breakpoint number @var{bnum}. The commands
3052themselves appear on the following lines. Type a line containing just
3053@code{end} to terminate the commands.
3054
3055To remove all commands from a breakpoint, type @code{commands} and
3056follow it immediately with @code{end}; that is, give no commands.
3057
3058With no @var{bnum} argument, @code{commands} refers to the last
3059breakpoint, watchpoint, or catchpoint set (not to the breakpoint most
3060recently encountered).
3061@end table
3062
3063Pressing @key{RET} as a means of repeating the last @value{GDBN} command is
3064disabled within a @var{command-list}.
3065
3066You can use breakpoint commands to start your program up again. Simply
3067use the @code{continue} command, or @code{step}, or any other command
3068that resumes execution.
3069
3070Any other commands in the command list, after a command that resumes
3071execution, are ignored. This is because any time you resume execution
3072(even with a simple @code{next} or @code{step}), you may encounter
3073another breakpoint---which could have its own command list, leading to
3074ambiguities about which list to execute.
3075
3076@kindex silent
3077If the first command you specify in a command list is @code{silent}, the
3078usual message about stopping at a breakpoint is not printed. This may
3079be desirable for breakpoints that are to print a specific message and
3080then continue. If none of the remaining commands print anything, you
3081see no sign that the breakpoint was reached. @code{silent} is
3082meaningful only at the beginning of a breakpoint command list.
3083
3084The commands @code{echo}, @code{output}, and @code{printf} allow you to
3085print precisely controlled output, and are often useful in silent
3086breakpoints. @xref{Output, ,Commands for controlled output}.
3087
3088For example, here is how you could use breakpoint commands to print the
3089value of @code{x} at entry to @code{foo} whenever @code{x} is positive.
3090
3091@example
3092break foo if x>0
3093commands
3094silent
3095printf "x is %d\n",x
3096cont
3097end
3098@end example
3099
3100One application for breakpoint commands is to compensate for one bug so
3101you can test for another. Put a breakpoint just after the erroneous line
3102of code, give it a condition to detect the case in which something
3103erroneous has been done, and give it commands to assign correct values
3104to any variables that need them. End with the @code{continue} command
3105so that your program does not stop, and start with the @code{silent}
3106command so that no output is produced. Here is an example:
3107
3108@example
3109break 403
3110commands
3111silent
3112set x = y + 4
3113cont
3114end
3115@end example
3116
6d2ebf8b 3117@node Breakpoint Menus
c906108c
SS
3118@subsection Breakpoint menus
3119@cindex overloading
3120@cindex symbol overloading
3121
b37052ae 3122Some programming languages (notably C@t{++}) permit a single function name
c906108c
SS
3123to be defined several times, for application in different contexts.
3124This is called @dfn{overloading}. When a function name is overloaded,
3125@samp{break @var{function}} is not enough to tell @value{GDBN} where you want
3126a breakpoint. If you realize this is a problem, you can use
3127something like @samp{break @var{function}(@var{types})} to specify which
3128particular version of the function you want. Otherwise, @value{GDBN} offers
3129you a menu of numbered choices for different possible breakpoints, and
3130waits for your selection with the prompt @samp{>}. The first two
3131options are always @samp{[0] cancel} and @samp{[1] all}. Typing @kbd{1}
3132sets a breakpoint at each definition of @var{function}, and typing
3133@kbd{0} aborts the @code{break} command without setting any new
3134breakpoints.
3135
3136For example, the following session excerpt shows an attempt to set a
3137breakpoint at the overloaded symbol @code{String::after}.
3138We choose three particular definitions of that function name:
3139
3140@c FIXME! This is likely to change to show arg type lists, at least
3141@smallexample
3142@group
3143(@value{GDBP}) b String::after
3144[0] cancel
3145[1] all
3146[2] file:String.cc; line number:867
3147[3] file:String.cc; line number:860
3148[4] file:String.cc; line number:875
3149[5] file:String.cc; line number:853
3150[6] file:String.cc; line number:846
3151[7] file:String.cc; line number:735
3152> 2 4 6
3153Breakpoint 1 at 0xb26c: file String.cc, line 867.
3154Breakpoint 2 at 0xb344: file String.cc, line 875.
3155Breakpoint 3 at 0xafcc: file String.cc, line 846.
3156Multiple breakpoints were set.
3157Use the "delete" command to delete unwanted
3158 breakpoints.
3159(@value{GDBP})
3160@end group
3161@end smallexample
c906108c
SS
3162
3163@c @ifclear BARETARGET
6d2ebf8b 3164@node Error in Breakpoints
d4f3574e 3165@subsection ``Cannot insert breakpoints''
c906108c
SS
3166@c
3167@c FIXME!! 14/6/95 Is there a real example of this? Let's use it.
3168@c
d4f3574e
SS
3169Under some operating systems, breakpoints cannot be used in a program if
3170any other process is running that program. In this situation,
5d161b24 3171attempting to run or continue a program with a breakpoint causes
d4f3574e
SS
3172@value{GDBN} to print an error message:
3173
3174@example
3175Cannot insert breakpoints.
3176The same program may be running in another process.
3177@end example
3178
3179When this happens, you have three ways to proceed:
3180
3181@enumerate
3182@item
3183Remove or disable the breakpoints, then continue.
3184
3185@item
5d161b24 3186Suspend @value{GDBN}, and copy the file containing your program to a new
d4f3574e 3187name. Resume @value{GDBN} and use the @code{exec-file} command to specify
5d161b24 3188that @value{GDBN} should run your program under that name.
d4f3574e
SS
3189Then start your program again.
3190
3191@item
3192Relink your program so that the text segment is nonsharable, using the
3193linker option @samp{-N}. The operating system limitation may not apply
3194to nonsharable executables.
3195@end enumerate
c906108c
SS
3196@c @end ifclear
3197
d4f3574e
SS
3198A similar message can be printed if you request too many active
3199hardware-assisted breakpoints and watchpoints:
3200
3201@c FIXME: the precise wording of this message may change; the relevant
3202@c source change is not committed yet (Sep 3, 1999).
3203@smallexample
3204Stopped; cannot insert breakpoints.
3205You may have requested too many hardware breakpoints and watchpoints.
3206@end smallexample
3207
3208@noindent
3209This message is printed when you attempt to resume the program, since
3210only then @value{GDBN} knows exactly how many hardware breakpoints and
3211watchpoints it needs to insert.
3212
3213When this message is printed, you need to disable or remove some of the
3214hardware-assisted breakpoints and watchpoints, and then continue.
3215
3216
6d2ebf8b 3217@node Continuing and Stepping
c906108c
SS
3218@section Continuing and stepping
3219
3220@cindex stepping
3221@cindex continuing
3222@cindex resuming execution
3223@dfn{Continuing} means resuming program execution until your program
3224completes normally. In contrast, @dfn{stepping} means executing just
3225one more ``step'' of your program, where ``step'' may mean either one
3226line of source code, or one machine instruction (depending on what
7a292a7a
SS
3227particular command you use). Either when continuing or when stepping,
3228your program may stop even sooner, due to a breakpoint or a signal. (If
d4f3574e
SS
3229it stops due to a signal, you may want to use @code{handle}, or use
3230@samp{signal 0} to resume execution. @xref{Signals, ,Signals}.)
c906108c
SS
3231
3232@table @code
3233@kindex continue
41afff9a
EZ
3234@kindex c @r{(@code{continue})}
3235@kindex fg @r{(resume foreground execution)}
c906108c
SS
3236@item continue @r{[}@var{ignore-count}@r{]}
3237@itemx c @r{[}@var{ignore-count}@r{]}
3238@itemx fg @r{[}@var{ignore-count}@r{]}
3239Resume program execution, at the address where your program last stopped;
3240any breakpoints set at that address are bypassed. The optional argument
3241@var{ignore-count} allows you to specify a further number of times to
3242ignore a breakpoint at this location; its effect is like that of
3243@code{ignore} (@pxref{Conditions, ,Break conditions}).
3244
3245The argument @var{ignore-count} is meaningful only when your program
3246stopped due to a breakpoint. At other times, the argument to
3247@code{continue} is ignored.
3248
d4f3574e
SS
3249The synonyms @code{c} and @code{fg} (for @dfn{foreground}, as the
3250debugged program is deemed to be the foreground program) are provided
3251purely for convenience, and have exactly the same behavior as
3252@code{continue}.
c906108c
SS
3253@end table
3254
3255To resume execution at a different place, you can use @code{return}
3256(@pxref{Returning, ,Returning from a function}) to go back to the
3257calling function; or @code{jump} (@pxref{Jumping, ,Continuing at a
3258different address}) to go to an arbitrary location in your program.
3259
3260A typical technique for using stepping is to set a breakpoint
3261(@pxref{Breakpoints, ,Breakpoints; watchpoints; and catchpoints}) at the
3262beginning of the function or the section of your program where a problem
3263is believed to lie, run your program until it stops at that breakpoint,
3264and then step through the suspect area, examining the variables that are
3265interesting, until you see the problem happen.
3266
3267@table @code
3268@kindex step
41afff9a 3269@kindex s @r{(@code{step})}
c906108c
SS
3270@item step
3271Continue running your program until control reaches a different source
3272line, then stop it and return control to @value{GDBN}. This command is
3273abbreviated @code{s}.
3274
3275@quotation
3276@c "without debugging information" is imprecise; actually "without line
3277@c numbers in the debugging information". (gcc -g1 has debugging info but
3278@c not line numbers). But it seems complex to try to make that
3279@c distinction here.
3280@emph{Warning:} If you use the @code{step} command while control is
3281within a function that was compiled without debugging information,
3282execution proceeds until control reaches a function that does have
3283debugging information. Likewise, it will not step into a function which
3284is compiled without debugging information. To step through functions
3285without debugging information, use the @code{stepi} command, described
3286below.
3287@end quotation
3288
4a92d011
EZ
3289The @code{step} command only stops at the first instruction of a source
3290line. This prevents the multiple stops that could otherwise occur in
3291@code{switch} statements, @code{for} loops, etc. @code{step} continues
3292to stop if a function that has debugging information is called within
3293the line. In other words, @code{step} @emph{steps inside} any functions
3294called within the line.
c906108c 3295
d4f3574e
SS
3296Also, the @code{step} command only enters a function if there is line
3297number information for the function. Otherwise it acts like the
5d161b24 3298@code{next} command. This avoids problems when using @code{cc -gl}
c906108c 3299on MIPS machines. Previously, @code{step} entered subroutines if there
5d161b24 3300was any debugging information about the routine.
c906108c
SS
3301
3302@item step @var{count}
3303Continue running as in @code{step}, but do so @var{count} times. If a
7a292a7a
SS
3304breakpoint is reached, or a signal not related to stepping occurs before
3305@var{count} steps, stepping stops right away.
c906108c
SS
3306
3307@kindex next
41afff9a 3308@kindex n @r{(@code{next})}
c906108c
SS
3309@item next @r{[}@var{count}@r{]}
3310Continue to the next source line in the current (innermost) stack frame.
7a292a7a
SS
3311This is similar to @code{step}, but function calls that appear within
3312the line of code are executed without stopping. Execution stops when
3313control reaches a different line of code at the original stack level
3314that was executing when you gave the @code{next} command. This command
3315is abbreviated @code{n}.
c906108c
SS
3316
3317An argument @var{count} is a repeat count, as for @code{step}.
3318
3319
3320@c FIX ME!! Do we delete this, or is there a way it fits in with
3321@c the following paragraph? --- Vctoria
3322@c
3323@c @code{next} within a function that lacks debugging information acts like
3324@c @code{step}, but any function calls appearing within the code of the
3325@c function are executed without stopping.
3326
d4f3574e
SS
3327The @code{next} command only stops at the first instruction of a
3328source line. This prevents multiple stops that could otherwise occur in
4a92d011 3329@code{switch} statements, @code{for} loops, etc.
c906108c 3330
b90a5f51
CF
3331@kindex set step-mode
3332@item set step-mode
3333@cindex functions without line info, and stepping
3334@cindex stepping into functions with no line info
3335@itemx set step-mode on
4a92d011 3336The @code{set step-mode on} command causes the @code{step} command to
b90a5f51
CF
3337stop at the first instruction of a function which contains no debug line
3338information rather than stepping over it.
3339
4a92d011
EZ
3340This is useful in cases where you may be interested in inspecting the
3341machine instructions of a function which has no symbolic info and do not
3342want @value{GDBN} to automatically skip over this function.
b90a5f51
CF
3343
3344@item set step-mode off
4a92d011 3345Causes the @code{step} command to step over any functions which contains no
b90a5f51
CF
3346debug information. This is the default.
3347
c906108c
SS
3348@kindex finish
3349@item finish
3350Continue running until just after function in the selected stack frame
3351returns. Print the returned value (if any).
3352
3353Contrast this with the @code{return} command (@pxref{Returning,
3354,Returning from a function}).
3355
3356@kindex until
41afff9a 3357@kindex u @r{(@code{until})}
c906108c
SS
3358@item until
3359@itemx u
3360Continue running until a source line past the current line, in the
3361current stack frame, is reached. This command is used to avoid single
3362stepping through a loop more than once. It is like the @code{next}
3363command, except that when @code{until} encounters a jump, it
3364automatically continues execution until the program counter is greater
3365than the address of the jump.
3366
3367This means that when you reach the end of a loop after single stepping
3368though it, @code{until} makes your program continue execution until it
3369exits the loop. In contrast, a @code{next} command at the end of a loop
3370simply steps back to the beginning of the loop, which forces you to step
3371through the next iteration.
3372
3373@code{until} always stops your program if it attempts to exit the current
3374stack frame.
3375
3376@code{until} may produce somewhat counterintuitive results if the order
3377of machine code does not match the order of the source lines. For
3378example, in the following excerpt from a debugging session, the @code{f}
3379(@code{frame}) command shows that execution is stopped at line
3380@code{206}; yet when we use @code{until}, we get to line @code{195}:
3381
3382@example
3383(@value{GDBP}) f
3384#0 main (argc=4, argv=0xf7fffae8) at m4.c:206
3385206 expand_input();
3386(@value{GDBP}) until
3387195 for ( ; argc > 0; NEXTARG) @{
3388@end example
3389
3390This happened because, for execution efficiency, the compiler had
3391generated code for the loop closure test at the end, rather than the
3392start, of the loop---even though the test in a C @code{for}-loop is
3393written before the body of the loop. The @code{until} command appeared
3394to step back to the beginning of the loop when it advanced to this
3395expression; however, it has not really gone to an earlier
3396statement---not in terms of the actual machine code.
3397
3398@code{until} with no argument works by means of single
3399instruction stepping, and hence is slower than @code{until} with an
3400argument.
3401
3402@item until @var{location}
3403@itemx u @var{location}
3404Continue running your program until either the specified location is
3405reached, or the current stack frame returns. @var{location} is any of
3406the forms of argument acceptable to @code{break} (@pxref{Set Breaks,
3407,Setting breakpoints}). This form of the command uses breakpoints,
3408and hence is quicker than @code{until} without an argument.
3409
3410@kindex stepi
41afff9a 3411@kindex si @r{(@code{stepi})}
c906108c 3412@item stepi
96a2c332 3413@itemx stepi @var{arg}
c906108c
SS
3414@itemx si
3415Execute one machine instruction, then stop and return to the debugger.
3416
3417It is often useful to do @samp{display/i $pc} when stepping by machine
3418instructions. This makes @value{GDBN} automatically display the next
3419instruction to be executed, each time your program stops. @xref{Auto
3420Display,, Automatic display}.
3421
3422An argument is a repeat count, as in @code{step}.
3423
3424@need 750
3425@kindex nexti
41afff9a 3426@kindex ni @r{(@code{nexti})}
c906108c 3427@item nexti
96a2c332 3428@itemx nexti @var{arg}
c906108c
SS
3429@itemx ni
3430Execute one machine instruction, but if it is a function call,
3431proceed until the function returns.
3432
3433An argument is a repeat count, as in @code{next}.
3434@end table
3435
6d2ebf8b 3436@node Signals
c906108c
SS
3437@section Signals
3438@cindex signals
3439
3440A signal is an asynchronous event that can happen in a program. The
3441operating system defines the possible kinds of signals, and gives each
3442kind a name and a number. For example, in Unix @code{SIGINT} is the
d4f3574e 3443signal a program gets when you type an interrupt character (often @kbd{C-c});
c906108c
SS
3444@code{SIGSEGV} is the signal a program gets from referencing a place in
3445memory far away from all the areas in use; @code{SIGALRM} occurs when
3446the alarm clock timer goes off (which happens only if your program has
3447requested an alarm).
3448
3449@cindex fatal signals
3450Some signals, including @code{SIGALRM}, are a normal part of the
3451functioning of your program. Others, such as @code{SIGSEGV}, indicate
d4f3574e 3452errors; these signals are @dfn{fatal} (they kill your program immediately) if the
c906108c
SS
3453program has not specified in advance some other way to handle the signal.
3454@code{SIGINT} does not indicate an error in your program, but it is normally
3455fatal so it can carry out the purpose of the interrupt: to kill the program.
3456
3457@value{GDBN} has the ability to detect any occurrence of a signal in your
3458program. You can tell @value{GDBN} in advance what to do for each kind of
3459signal.
3460
3461@cindex handling signals
24f93129
EZ
3462Normally, @value{GDBN} is set up to let the non-erroneous signals like
3463@code{SIGALRM} be silently passed to your program
3464(so as not to interfere with their role in the program's functioning)
c906108c
SS
3465but to stop your program immediately whenever an error signal happens.
3466You can change these settings with the @code{handle} command.
3467
3468@table @code
3469@kindex info signals
3470@item info signals
96a2c332 3471@itemx info handle
c906108c
SS
3472Print a table of all the kinds of signals and how @value{GDBN} has been told to
3473handle each one. You can use this to see the signal numbers of all
3474the defined types of signals.
3475
d4f3574e 3476@code{info handle} is an alias for @code{info signals}.
c906108c
SS
3477
3478@kindex handle
3479@item handle @var{signal} @var{keywords}@dots{}
5ece1a18
EZ
3480Change the way @value{GDBN} handles signal @var{signal}. @var{signal}
3481can be the number of a signal or its name (with or without the
24f93129 3482@samp{SIG} at the beginning); a list of signal numbers of the form
5ece1a18
EZ
3483@samp{@var{low}-@var{high}}; or the word @samp{all}, meaning all the
3484known signals. The @var{keywords} say what change to make.
c906108c
SS
3485@end table
3486
3487@c @group
3488The keywords allowed by the @code{handle} command can be abbreviated.
3489Their full names are:
3490
3491@table @code
3492@item nostop
3493@value{GDBN} should not stop your program when this signal happens. It may
3494still print a message telling you that the signal has come in.
3495
3496@item stop
3497@value{GDBN} should stop your program when this signal happens. This implies
3498the @code{print} keyword as well.
3499
3500@item print
3501@value{GDBN} should print a message when this signal happens.
3502
3503@item noprint
3504@value{GDBN} should not mention the occurrence of the signal at all. This
3505implies the @code{nostop} keyword as well.
3506
3507@item pass
5ece1a18 3508@itemx noignore
c906108c
SS
3509@value{GDBN} should allow your program to see this signal; your program
3510can handle the signal, or else it may terminate if the signal is fatal
5ece1a18 3511and not handled. @code{pass} and @code{noignore} are synonyms.
c906108c
SS
3512
3513@item nopass
5ece1a18 3514@itemx ignore
c906108c 3515@value{GDBN} should not allow your program to see this signal.
5ece1a18 3516@code{nopass} and @code{ignore} are synonyms.
c906108c
SS
3517@end table
3518@c @end group
3519
d4f3574e
SS
3520When a signal stops your program, the signal is not visible to the
3521program until you
c906108c
SS
3522continue. Your program sees the signal then, if @code{pass} is in
3523effect for the signal in question @emph{at that time}. In other words,
3524after @value{GDBN} reports a signal, you can use the @code{handle}
3525command with @code{pass} or @code{nopass} to control whether your
3526program sees that signal when you continue.
3527
24f93129
EZ
3528The default is set to @code{nostop}, @code{noprint}, @code{pass} for
3529non-erroneous signals such as @code{SIGALRM}, @code{SIGWINCH} and
3530@code{SIGCHLD}, and to @code{stop}, @code{print}, @code{pass} for the
3531erroneous signals.
3532
c906108c
SS
3533You can also use the @code{signal} command to prevent your program from
3534seeing a signal, or cause it to see a signal it normally would not see,
3535or to give it any signal at any time. For example, if your program stopped
3536due to some sort of memory reference error, you might store correct
3537values into the erroneous variables and continue, hoping to see more
3538execution; but your program would probably terminate immediately as
3539a result of the fatal signal once it saw the signal. To prevent this,
3540you can continue with @samp{signal 0}. @xref{Signaling, ,Giving your
5d161b24 3541program a signal}.
c906108c 3542
6d2ebf8b 3543@node Thread Stops
c906108c
SS
3544@section Stopping and starting multi-thread programs
3545
3546When your program has multiple threads (@pxref{Threads,, Debugging
3547programs with multiple threads}), you can choose whether to set
3548breakpoints on all threads, or on a particular thread.
3549
3550@table @code
3551@cindex breakpoints and threads
3552@cindex thread breakpoints
3553@kindex break @dots{} thread @var{threadno}
3554@item break @var{linespec} thread @var{threadno}
3555@itemx break @var{linespec} thread @var{threadno} if @dots{}
3556@var{linespec} specifies source lines; there are several ways of
3557writing them, but the effect is always to specify some source line.
3558
3559Use the qualifier @samp{thread @var{threadno}} with a breakpoint command
3560to specify that you only want @value{GDBN} to stop the program when a
3561particular thread reaches this breakpoint. @var{threadno} is one of the
3562numeric thread identifiers assigned by @value{GDBN}, shown in the first
3563column of the @samp{info threads} display.
3564
3565If you do not specify @samp{thread @var{threadno}} when you set a
3566breakpoint, the breakpoint applies to @emph{all} threads of your
3567program.
3568
3569You can use the @code{thread} qualifier on conditional breakpoints as
3570well; in this case, place @samp{thread @var{threadno}} before the
3571breakpoint condition, like this:
3572
3573@smallexample
2df3850c 3574(@value{GDBP}) break frik.c:13 thread 28 if bartab > lim
c906108c
SS
3575@end smallexample
3576
3577@end table
3578
3579@cindex stopped threads
3580@cindex threads, stopped
3581Whenever your program stops under @value{GDBN} for any reason,
3582@emph{all} threads of execution stop, not just the current thread. This
3583allows you to examine the overall state of the program, including
3584switching between threads, without worrying that things may change
3585underfoot.
3586
3587@cindex continuing threads
3588@cindex threads, continuing
3589Conversely, whenever you restart the program, @emph{all} threads start
3590executing. @emph{This is true even when single-stepping} with commands
5d161b24 3591like @code{step} or @code{next}.
c906108c
SS
3592
3593In particular, @value{GDBN} cannot single-step all threads in lockstep.
3594Since thread scheduling is up to your debugging target's operating
3595system (not controlled by @value{GDBN}), other threads may
3596execute more than one statement while the current thread completes a
3597single step. Moreover, in general other threads stop in the middle of a
3598statement, rather than at a clean statement boundary, when the program
3599stops.
3600
3601You might even find your program stopped in another thread after
3602continuing or even single-stepping. This happens whenever some other
3603thread runs into a breakpoint, a signal, or an exception before the
3604first thread completes whatever you requested.
3605
3606On some OSes, you can lock the OS scheduler and thus allow only a single
3607thread to run.
3608
3609@table @code
3610@item set scheduler-locking @var{mode}
3611Set the scheduler locking mode. If it is @code{off}, then there is no
3612locking and any thread may run at any time. If @code{on}, then only the
3613current thread may run when the inferior is resumed. The @code{step}
3614mode optimizes for single-stepping. It stops other threads from
3615``seizing the prompt'' by preempting the current thread while you are
3616stepping. Other threads will only rarely (or never) get a chance to run
d4f3574e 3617when you step. They are more likely to run when you @samp{next} over a
c906108c 3618function call, and they are completely free to run when you use commands
d4f3574e 3619like @samp{continue}, @samp{until}, or @samp{finish}. However, unless another
c906108c 3620thread hits a breakpoint during its timeslice, they will never steal the
2df3850c 3621@value{GDBN} prompt away from the thread that you are debugging.
c906108c
SS
3622
3623@item show scheduler-locking
3624Display the current scheduler locking mode.
3625@end table
3626
c906108c 3627
6d2ebf8b 3628@node Stack
c906108c
SS
3629@chapter Examining the Stack
3630
3631When your program has stopped, the first thing you need to know is where it
3632stopped and how it got there.
3633
3634@cindex call stack
5d161b24
DB
3635Each time your program performs a function call, information about the call
3636is generated.
3637That information includes the location of the call in your program,
3638the arguments of the call,
c906108c 3639and the local variables of the function being called.
5d161b24 3640The information is saved in a block of data called a @dfn{stack frame}.
c906108c
SS
3641The stack frames are allocated in a region of memory called the @dfn{call
3642stack}.
3643
3644When your program stops, the @value{GDBN} commands for examining the
3645stack allow you to see all of this information.
3646
3647@cindex selected frame
3648One of the stack frames is @dfn{selected} by @value{GDBN} and many
3649@value{GDBN} commands refer implicitly to the selected frame. In
3650particular, whenever you ask @value{GDBN} for the value of a variable in
3651your program, the value is found in the selected frame. There are
3652special @value{GDBN} commands to select whichever frame you are
3653interested in. @xref{Selection, ,Selecting a frame}.
3654
3655When your program stops, @value{GDBN} automatically selects the
5d161b24 3656currently executing frame and describes it briefly, similar to the
c906108c
SS
3657@code{frame} command (@pxref{Frame Info, ,Information about a frame}).
3658
3659@menu
3660* Frames:: Stack frames
3661* Backtrace:: Backtraces
3662* Selection:: Selecting a frame
3663* Frame Info:: Information on a frame
c906108c
SS
3664
3665@end menu
3666
6d2ebf8b 3667@node Frames
c906108c
SS
3668@section Stack frames
3669
d4f3574e 3670@cindex frame, definition
c906108c
SS
3671@cindex stack frame
3672The call stack is divided up into contiguous pieces called @dfn{stack
3673frames}, or @dfn{frames} for short; each frame is the data associated
3674with one call to one function. The frame contains the arguments given
3675to the function, the function's local variables, and the address at
3676which the function is executing.
3677
3678@cindex initial frame
3679@cindex outermost frame
3680@cindex innermost frame
3681When your program is started, the stack has only one frame, that of the
3682function @code{main}. This is called the @dfn{initial} frame or the
3683@dfn{outermost} frame. Each time a function is called, a new frame is
3684made. Each time a function returns, the frame for that function invocation
3685is eliminated. If a function is recursive, there can be many frames for
3686the same function. The frame for the function in which execution is
3687actually occurring is called the @dfn{innermost} frame. This is the most
3688recently created of all the stack frames that still exist.
3689
3690@cindex frame pointer
3691Inside your program, stack frames are identified by their addresses. A
3692stack frame consists of many bytes, each of which has its own address; each
3693kind of computer has a convention for choosing one byte whose
3694address serves as the address of the frame. Usually this address is kept
3695in a register called the @dfn{frame pointer register} while execution is
3696going on in that frame.
3697
3698@cindex frame number
3699@value{GDBN} assigns numbers to all existing stack frames, starting with
3700zero for the innermost frame, one for the frame that called it,
3701and so on upward. These numbers do not really exist in your program;
3702they are assigned by @value{GDBN} to give you a way of designating stack
3703frames in @value{GDBN} commands.
3704
6d2ebf8b
SS
3705@c The -fomit-frame-pointer below perennially causes hbox overflow
3706@c underflow problems.
c906108c
SS
3707@cindex frameless execution
3708Some compilers provide a way to compile functions so that they operate
6d2ebf8b
SS
3709without stack frames. (For example, the @value{GCC} option
3710@example
3711@samp{-fomit-frame-pointer}
3712@end example
3713generates functions without a frame.)
c906108c
SS
3714This is occasionally done with heavily used library functions to save
3715the frame setup time. @value{GDBN} has limited facilities for dealing
3716with these function invocations. If the innermost function invocation
3717has no stack frame, @value{GDBN} nevertheless regards it as though
3718it had a separate frame, which is numbered zero as usual, allowing
3719correct tracing of the function call chain. However, @value{GDBN} has
3720no provision for frameless functions elsewhere in the stack.
3721
3722@table @code
d4f3574e 3723@kindex frame@r{, command}
41afff9a 3724@cindex current stack frame
c906108c 3725@item frame @var{args}
5d161b24 3726The @code{frame} command allows you to move from one stack frame to another,
c906108c 3727and to print the stack frame you select. @var{args} may be either the
5d161b24
DB
3728address of the frame or the stack frame number. Without an argument,
3729@code{frame} prints the current stack frame.
c906108c
SS
3730
3731@kindex select-frame
41afff9a 3732@cindex selecting frame silently
c906108c
SS
3733@item select-frame
3734The @code{select-frame} command allows you to move from one stack frame
3735to another without printing the frame. This is the silent version of
3736@code{frame}.
3737@end table
3738
6d2ebf8b 3739@node Backtrace
c906108c
SS
3740@section Backtraces
3741
3742@cindex backtraces
3743@cindex tracebacks
3744@cindex stack traces
3745A backtrace is a summary of how your program got where it is. It shows one
3746line per frame, for many frames, starting with the currently executing
3747frame (frame zero), followed by its caller (frame one), and on up the
3748stack.
3749
3750@table @code
3751@kindex backtrace
41afff9a 3752@kindex bt @r{(@code{backtrace})}
c906108c
SS
3753@item backtrace
3754@itemx bt
3755Print a backtrace of the entire stack: one line per frame for all
3756frames in the stack.
3757
3758You can stop the backtrace at any time by typing the system interrupt
3759character, normally @kbd{C-c}.
3760
3761@item backtrace @var{n}
3762@itemx bt @var{n}
3763Similar, but print only the innermost @var{n} frames.
3764
3765@item backtrace -@var{n}
3766@itemx bt -@var{n}
3767Similar, but print only the outermost @var{n} frames.
3768@end table
3769
3770@kindex where
3771@kindex info stack
41afff9a 3772@kindex info s @r{(@code{info stack})}
c906108c
SS
3773The names @code{where} and @code{info stack} (abbreviated @code{info s})
3774are additional aliases for @code{backtrace}.
3775
3776Each line in the backtrace shows the frame number and the function name.
3777The program counter value is also shown---unless you use @code{set
3778print address off}. The backtrace also shows the source file name and
3779line number, as well as the arguments to the function. The program
3780counter value is omitted if it is at the beginning of the code for that
3781line number.
3782
3783Here is an example of a backtrace. It was made with the command
3784@samp{bt 3}, so it shows the innermost three frames.
3785
3786@smallexample
3787@group
5d161b24 3788#0 m4_traceon (obs=0x24eb0, argc=1, argv=0x2b8c8)
c906108c
SS
3789 at builtin.c:993
3790#1 0x6e38 in expand_macro (sym=0x2b600) at macro.c:242
3791#2 0x6840 in expand_token (obs=0x0, t=177664, td=0xf7fffb08)
3792 at macro.c:71
3793(More stack frames follow...)
3794@end group
3795@end smallexample
3796
3797@noindent
3798The display for frame zero does not begin with a program counter
3799value, indicating that your program has stopped at the beginning of the
3800code for line @code{993} of @code{builtin.c}.
3801
6d2ebf8b 3802@node Selection
c906108c
SS
3803@section Selecting a frame
3804
3805Most commands for examining the stack and other data in your program work on
3806whichever stack frame is selected at the moment. Here are the commands for
3807selecting a stack frame; all of them finish by printing a brief description
3808of the stack frame just selected.
3809
3810@table @code
d4f3574e 3811@kindex frame@r{, selecting}
41afff9a 3812@kindex f @r{(@code{frame})}
c906108c
SS
3813@item frame @var{n}
3814@itemx f @var{n}
3815Select frame number @var{n}. Recall that frame zero is the innermost
3816(currently executing) frame, frame one is the frame that called the
3817innermost one, and so on. The highest-numbered frame is the one for
3818@code{main}.
3819
3820@item frame @var{addr}
3821@itemx f @var{addr}
3822Select the frame at address @var{addr}. This is useful mainly if the
3823chaining of stack frames has been damaged by a bug, making it
3824impossible for @value{GDBN} to assign numbers properly to all frames. In
3825addition, this can be useful when your program has multiple stacks and
3826switches between them.
3827
c906108c
SS
3828On the SPARC architecture, @code{frame} needs two addresses to
3829select an arbitrary frame: a frame pointer and a stack pointer.
3830
3831On the MIPS and Alpha architecture, it needs two addresses: a stack
3832pointer and a program counter.
3833
3834On the 29k architecture, it needs three addresses: a register stack
3835pointer, a program counter, and a memory stack pointer.
3836@c note to future updaters: this is conditioned on a flag
3837@c SETUP_ARBITRARY_FRAME in the tm-*.h files. The above is up to date
3838@c as of 27 Jan 1994.
c906108c
SS
3839
3840@kindex up
3841@item up @var{n}
3842Move @var{n} frames up the stack. For positive numbers @var{n}, this
3843advances toward the outermost frame, to higher frame numbers, to frames
3844that have existed longer. @var{n} defaults to one.
3845
3846@kindex down
41afff9a 3847@kindex do @r{(@code{down})}
c906108c
SS
3848@item down @var{n}
3849Move @var{n} frames down the stack. For positive numbers @var{n}, this
3850advances toward the innermost frame, to lower frame numbers, to frames
3851that were created more recently. @var{n} defaults to one. You may
3852abbreviate @code{down} as @code{do}.
3853@end table
3854
3855All of these commands end by printing two lines of output describing the
3856frame. The first line shows the frame number, the function name, the
3857arguments, and the source file and line number of execution in that
5d161b24 3858frame. The second line shows the text of that source line.
c906108c
SS
3859
3860@need 1000
3861For example:
3862
3863@smallexample
3864@group
3865(@value{GDBP}) up
3866#1 0x22f0 in main (argc=1, argv=0xf7fffbf4, env=0xf7fffbfc)
3867 at env.c:10
386810 read_input_file (argv[i]);
3869@end group
3870@end smallexample
3871
3872After such a printout, the @code{list} command with no arguments
3873prints ten lines centered on the point of execution in the frame.
3874@xref{List, ,Printing source lines}.
3875
3876@table @code
3877@kindex down-silently
3878@kindex up-silently
3879@item up-silently @var{n}
3880@itemx down-silently @var{n}
3881These two commands are variants of @code{up} and @code{down},
3882respectively; they differ in that they do their work silently, without
3883causing display of the new frame. They are intended primarily for use
3884in @value{GDBN} command scripts, where the output might be unnecessary and
3885distracting.
3886@end table
3887
6d2ebf8b 3888@node Frame Info
c906108c
SS
3889@section Information about a frame
3890
3891There are several other commands to print information about the selected
3892stack frame.
3893
3894@table @code
3895@item frame
3896@itemx f
3897When used without any argument, this command does not change which
3898frame is selected, but prints a brief description of the currently
3899selected stack frame. It can be abbreviated @code{f}. With an
3900argument, this command is used to select a stack frame.
3901@xref{Selection, ,Selecting a frame}.
3902
3903@kindex info frame
41afff9a 3904@kindex info f @r{(@code{info frame})}
c906108c
SS
3905@item info frame
3906@itemx info f
3907This command prints a verbose description of the selected stack frame,
3908including:
3909
3910@itemize @bullet
5d161b24
DB
3911@item
3912the address of the frame
c906108c
SS
3913@item
3914the address of the next frame down (called by this frame)
3915@item
3916the address of the next frame up (caller of this frame)
3917@item
3918the language in which the source code corresponding to this frame is written
3919@item
3920the address of the frame's arguments
3921@item
d4f3574e
SS
3922the address of the frame's local variables
3923@item
c906108c
SS
3924the program counter saved in it (the address of execution in the caller frame)
3925@item
3926which registers were saved in the frame
3927@end itemize
3928
3929@noindent The verbose description is useful when
3930something has gone wrong that has made the stack format fail to fit
3931the usual conventions.
3932
3933@item info frame @var{addr}
3934@itemx info f @var{addr}
3935Print a verbose description of the frame at address @var{addr}, without
3936selecting that frame. The selected frame remains unchanged by this
3937command. This requires the same kind of address (more than one for some
3938architectures) that you specify in the @code{frame} command.
3939@xref{Selection, ,Selecting a frame}.
3940
3941@kindex info args
3942@item info args
3943Print the arguments of the selected frame, each on a separate line.
3944
3945@item info locals
3946@kindex info locals
3947Print the local variables of the selected frame, each on a separate
3948line. These are all variables (declared either static or automatic)
3949accessible at the point of execution of the selected frame.
3950
c906108c 3951@kindex info catch
d4f3574e
SS
3952@cindex catch exceptions, list active handlers
3953@cindex exception handlers, how to list
c906108c
SS
3954@item info catch
3955Print a list of all the exception handlers that are active in the
3956current stack frame at the current point of execution. To see other
3957exception handlers, visit the associated frame (using the @code{up},
3958@code{down}, or @code{frame} commands); then type @code{info catch}.
3959@xref{Set Catchpoints, , Setting catchpoints}.
53a5351d 3960
c906108c
SS
3961@end table
3962
c906108c 3963
6d2ebf8b 3964@node Source
c906108c
SS
3965@chapter Examining Source Files
3966
3967@value{GDBN} can print parts of your program's source, since the debugging
3968information recorded in the program tells @value{GDBN} what source files were
3969used to build it. When your program stops, @value{GDBN} spontaneously prints
3970the line where it stopped. Likewise, when you select a stack frame
3971(@pxref{Selection, ,Selecting a frame}), @value{GDBN} prints the line where
3972execution in that frame has stopped. You can print other portions of
3973source files by explicit command.
3974
7a292a7a 3975If you use @value{GDBN} through its @sc{gnu} Emacs interface, you may
d4f3574e 3976prefer to use Emacs facilities to view source; see @ref{Emacs, ,Using
7a292a7a 3977@value{GDBN} under @sc{gnu} Emacs}.
c906108c
SS
3978
3979@menu
3980* List:: Printing source lines
c906108c 3981* Search:: Searching source files
c906108c
SS
3982* Source Path:: Specifying source directories
3983* Machine Code:: Source and machine code
3984@end menu
3985
6d2ebf8b 3986@node List
c906108c
SS
3987@section Printing source lines
3988
3989@kindex list
41afff9a 3990@kindex l @r{(@code{list})}
c906108c 3991To print lines from a source file, use the @code{list} command
5d161b24 3992(abbreviated @code{l}). By default, ten lines are printed.
c906108c
SS
3993There are several ways to specify what part of the file you want to print.
3994
3995Here are the forms of the @code{list} command most commonly used:
3996
3997@table @code
3998@item list @var{linenum}
3999Print lines centered around line number @var{linenum} in the
4000current source file.
4001
4002@item list @var{function}
4003Print lines centered around the beginning of function
4004@var{function}.
4005
4006@item list
4007Print more lines. If the last lines printed were printed with a
4008@code{list} command, this prints lines following the last lines
4009printed; however, if the last line printed was a solitary line printed
4010as part of displaying a stack frame (@pxref{Stack, ,Examining the
4011Stack}), this prints lines centered around that line.
4012
4013@item list -
4014Print lines just before the lines last printed.
4015@end table
4016
4017By default, @value{GDBN} prints ten source lines with any of these forms of
4018the @code{list} command. You can change this using @code{set listsize}:
4019
4020@table @code
4021@kindex set listsize
4022@item set listsize @var{count}
4023Make the @code{list} command display @var{count} source lines (unless
4024the @code{list} argument explicitly specifies some other number).
4025
4026@kindex show listsize
4027@item show listsize
4028Display the number of lines that @code{list} prints.
4029@end table
4030
4031Repeating a @code{list} command with @key{RET} discards the argument,
4032so it is equivalent to typing just @code{list}. This is more useful
4033than listing the same lines again. An exception is made for an
4034argument of @samp{-}; that argument is preserved in repetition so that
4035each repetition moves up in the source file.
4036
4037@cindex linespec
4038In general, the @code{list} command expects you to supply zero, one or two
4039@dfn{linespecs}. Linespecs specify source lines; there are several ways
d4f3574e 4040of writing them, but the effect is always to specify some source line.
c906108c
SS
4041Here is a complete description of the possible arguments for @code{list}:
4042
4043@table @code
4044@item list @var{linespec}
4045Print lines centered around the line specified by @var{linespec}.
4046
4047@item list @var{first},@var{last}
4048Print lines from @var{first} to @var{last}. Both arguments are
4049linespecs.
4050
4051@item list ,@var{last}
4052Print lines ending with @var{last}.
4053
4054@item list @var{first},
4055Print lines starting with @var{first}.
4056
4057@item list +
4058Print lines just after the lines last printed.
4059
4060@item list -
4061Print lines just before the lines last printed.
4062
4063@item list
4064As described in the preceding table.
4065@end table
4066
4067Here are the ways of specifying a single source line---all the
4068kinds of linespec.
4069
4070@table @code
4071@item @var{number}
4072Specifies line @var{number} of the current source file.
4073When a @code{list} command has two linespecs, this refers to
4074the same source file as the first linespec.
4075
4076@item +@var{offset}
4077Specifies the line @var{offset} lines after the last line printed.
4078When used as the second linespec in a @code{list} command that has
4079two, this specifies the line @var{offset} lines down from the
4080first linespec.
4081
4082@item -@var{offset}
4083Specifies the line @var{offset} lines before the last line printed.
4084
4085@item @var{filename}:@var{number}
4086Specifies line @var{number} in the source file @var{filename}.
4087
4088@item @var{function}
4089Specifies the line that begins the body of the function @var{function}.
4090For example: in C, this is the line with the open brace.
4091
4092@item @var{filename}:@var{function}
4093Specifies the line of the open-brace that begins the body of the
4094function @var{function} in the file @var{filename}. You only need the
4095file name with a function name to avoid ambiguity when there are
4096identically named functions in different source files.
4097
4098@item *@var{address}
4099Specifies the line containing the program address @var{address}.
4100@var{address} may be any expression.
4101@end table
4102
6d2ebf8b 4103@node Search
c906108c
SS
4104@section Searching source files
4105@cindex searching
4106@kindex reverse-search
4107
4108There are two commands for searching through the current source file for a
4109regular expression.
4110
4111@table @code
4112@kindex search
4113@kindex forward-search
4114@item forward-search @var{regexp}
4115@itemx search @var{regexp}
4116The command @samp{forward-search @var{regexp}} checks each line,
4117starting with the one following the last line listed, for a match for
5d161b24 4118@var{regexp}. It lists the line that is found. You can use the
c906108c
SS
4119synonym @samp{search @var{regexp}} or abbreviate the command name as
4120@code{fo}.
4121
4122@item reverse-search @var{regexp}
4123The command @samp{reverse-search @var{regexp}} checks each line, starting
4124with the one before the last line listed and going backward, for a match
4125for @var{regexp}. It lists the line that is found. You can abbreviate
4126this command as @code{rev}.
4127@end table
c906108c 4128
6d2ebf8b 4129@node Source Path
c906108c
SS
4130@section Specifying source directories
4131
4132@cindex source path
4133@cindex directories for source files
4134Executable programs sometimes do not record the directories of the source
4135files from which they were compiled, just the names. Even when they do,
4136the directories could be moved between the compilation and your debugging
4137session. @value{GDBN} has a list of directories to search for source files;
4138this is called the @dfn{source path}. Each time @value{GDBN} wants a source file,
4139it tries all the directories in the list, in the order they are present
4140in the list, until it finds a file with the desired name. Note that
4141the executable search path is @emph{not} used for this purpose. Neither is
4142the current working directory, unless it happens to be in the source
4143path.
4144
4145If @value{GDBN} cannot find a source file in the source path, and the
4146object program records a directory, @value{GDBN} tries that directory
4147too. If the source path is empty, and there is no record of the
4148compilation directory, @value{GDBN} looks in the current directory as a
4149last resort.
4150
4151Whenever you reset or rearrange the source path, @value{GDBN} clears out
4152any information it has cached about where source files are found and where
4153each line is in the file.
4154
4155@kindex directory
4156@kindex dir
d4f3574e
SS
4157When you start @value{GDBN}, its source path includes only @samp{cdir}
4158and @samp{cwd}, in that order.
c906108c
SS
4159To add other directories, use the @code{directory} command.
4160
4161@table @code
4162@item directory @var{dirname} @dots{}
4163@item dir @var{dirname} @dots{}
4164Add directory @var{dirname} to the front of the source path. Several
d4f3574e
SS
4165directory names may be given to this command, separated by @samp{:}
4166(@samp{;} on MS-DOS and MS-Windows, where @samp{:} usually appears as
4167part of absolute file names) or
c906108c
SS
4168whitespace. You may specify a directory that is already in the source
4169path; this moves it forward, so @value{GDBN} searches it sooner.
4170
4171@kindex cdir
4172@kindex cwd
41afff9a
EZ
4173@vindex $cdir@r{, convenience variable}
4174@vindex $cwdr@r{, convenience variable}
c906108c
SS
4175@cindex compilation directory
4176@cindex current directory
4177@cindex working directory
4178@cindex directory, current
4179@cindex directory, compilation
4180You can use the string @samp{$cdir} to refer to the compilation
4181directory (if one is recorded), and @samp{$cwd} to refer to the current
4182working directory. @samp{$cwd} is not the same as @samp{.}---the former
4183tracks the current working directory as it changes during your @value{GDBN}
4184session, while the latter is immediately expanded to the current
4185directory at the time you add an entry to the source path.
4186
4187@item directory
4188Reset the source path to empty again. This requires confirmation.
4189
4190@c RET-repeat for @code{directory} is explicitly disabled, but since
4191@c repeating it would be a no-op we do not say that. (thanks to RMS)
4192
4193@item show directories
4194@kindex show directories
4195Print the source path: show which directories it contains.
4196@end table
4197
4198If your source path is cluttered with directories that are no longer of
4199interest, @value{GDBN} may sometimes cause confusion by finding the wrong
4200versions of source. You can correct the situation as follows:
4201
4202@enumerate
4203@item
4204Use @code{directory} with no argument to reset the source path to empty.
4205
4206@item
4207Use @code{directory} with suitable arguments to reinstall the
4208directories you want in the source path. You can add all the
4209directories in one command.
4210@end enumerate
4211
6d2ebf8b 4212@node Machine Code
c906108c
SS
4213@section Source and machine code
4214
4215You can use the command @code{info line} to map source lines to program
4216addresses (and vice versa), and the command @code{disassemble} to display
4217a range of addresses as machine instructions. When run under @sc{gnu} Emacs
d4f3574e 4218mode, the @code{info line} command causes the arrow to point to the
5d161b24 4219line specified. Also, @code{info line} prints addresses in symbolic form as
c906108c
SS
4220well as hex.
4221
4222@table @code
4223@kindex info line
4224@item info line @var{linespec}
4225Print the starting and ending addresses of the compiled code for
4226source line @var{linespec}. You can specify source lines in any of
4227the ways understood by the @code{list} command (@pxref{List, ,Printing
4228source lines}).
4229@end table
4230
4231For example, we can use @code{info line} to discover the location of
4232the object code for the first line of function
4233@code{m4_changequote}:
4234
d4f3574e
SS
4235@c FIXME: I think this example should also show the addresses in
4236@c symbolic form, as they usually would be displayed.
c906108c 4237@smallexample
96a2c332 4238(@value{GDBP}) info line m4_changequote
c906108c
SS
4239Line 895 of "builtin.c" starts at pc 0x634c and ends at 0x6350.
4240@end smallexample
4241
4242@noindent
4243We can also inquire (using @code{*@var{addr}} as the form for
4244@var{linespec}) what source line covers a particular address:
4245@smallexample
4246(@value{GDBP}) info line *0x63ff
4247Line 926 of "builtin.c" starts at pc 0x63e4 and ends at 0x6404.
4248@end smallexample
4249
4250@cindex @code{$_} and @code{info line}
41afff9a 4251@kindex x@r{(examine), and} info line
c906108c
SS
4252After @code{info line}, the default address for the @code{x} command
4253is changed to the starting address of the line, so that @samp{x/i} is
4254sufficient to begin examining the machine code (@pxref{Memory,
4255,Examining memory}). Also, this address is saved as the value of the
4256convenience variable @code{$_} (@pxref{Convenience Vars, ,Convenience
4257variables}).
4258
4259@table @code
4260@kindex disassemble
4261@cindex assembly instructions
4262@cindex instructions, assembly
4263@cindex machine instructions
4264@cindex listing machine instructions
4265@item disassemble
4266This specialized command dumps a range of memory as machine
4267instructions. The default memory range is the function surrounding the
4268program counter of the selected frame. A single argument to this
4269command is a program counter value; @value{GDBN} dumps the function
4270surrounding this value. Two arguments specify a range of addresses
4271(first inclusive, second exclusive) to dump.
4272@end table
4273
c906108c
SS
4274The following example shows the disassembly of a range of addresses of
4275HP PA-RISC 2.0 code:
4276
4277@smallexample
4278(@value{GDBP}) disas 0x32c4 0x32e4
4279Dump of assembler code from 0x32c4 to 0x32e4:
42800x32c4 <main+204>: addil 0,dp
42810x32c8 <main+208>: ldw 0x22c(sr0,r1),r26
42820x32cc <main+212>: ldil 0x3000,r31
42830x32d0 <main+216>: ble 0x3f8(sr4,r31)
42840x32d4 <main+220>: ldo 0(r31),rp
42850x32d8 <main+224>: addil -0x800,dp
42860x32dc <main+228>: ldo 0x588(r1),r26
42870x32e0 <main+232>: ldil 0x3000,r31
4288End of assembler dump.
4289@end smallexample
c906108c
SS
4290
4291Some architectures have more than one commonly-used set of instruction
4292mnemonics or other syntax.
4293
4294@table @code
d4f3574e 4295@kindex set disassembly-flavor
c906108c
SS
4296@cindex assembly instructions
4297@cindex instructions, assembly
4298@cindex machine instructions
4299@cindex listing machine instructions
d4f3574e
SS
4300@cindex Intel disassembly flavor
4301@cindex AT&T disassembly flavor
4302@item set disassembly-flavor @var{instruction-set}
c906108c
SS
4303Select the instruction set to use when disassembling the
4304program via the @code{disassemble} or @code{x/i} commands.
4305
4306Currently this command is only defined for the Intel x86 family. You
d4f3574e
SS
4307can set @var{instruction-set} to either @code{intel} or @code{att}.
4308The default is @code{att}, the AT&T flavor used by default by Unix
4309assemblers for x86-based targets.
c906108c
SS
4310@end table
4311
4312
6d2ebf8b 4313@node Data
c906108c
SS
4314@chapter Examining Data
4315
4316@cindex printing data
4317@cindex examining data
4318@kindex print
4319@kindex inspect
4320@c "inspect" is not quite a synonym if you are using Epoch, which we do not
4321@c document because it is nonstandard... Under Epoch it displays in a
4322@c different window or something like that.
4323The usual way to examine data in your program is with the @code{print}
7a292a7a
SS
4324command (abbreviated @code{p}), or its synonym @code{inspect}. It
4325evaluates and prints the value of an expression of the language your
4326program is written in (@pxref{Languages, ,Using @value{GDBN} with
4327Different Languages}).
c906108c
SS
4328
4329@table @code
d4f3574e
SS
4330@item print @var{expr}
4331@itemx print /@var{f} @var{expr}
4332@var{expr} is an expression (in the source language). By default the
4333value of @var{expr} is printed in a format appropriate to its data type;
c906108c 4334you can choose a different format by specifying @samp{/@var{f}}, where
d4f3574e 4335@var{f} is a letter specifying the format; see @ref{Output Formats,,Output
c906108c
SS
4336formats}.
4337
4338@item print
4339@itemx print /@var{f}
d4f3574e 4340If you omit @var{expr}, @value{GDBN} displays the last value again (from the
c906108c
SS
4341@dfn{value history}; @pxref{Value History, ,Value history}). This allows you to
4342conveniently inspect the same value in an alternative format.
4343@end table
4344
4345A more low-level way of examining data is with the @code{x} command.
4346It examines data in memory at a specified address and prints it in a
4347specified format. @xref{Memory, ,Examining memory}.
4348
7a292a7a 4349If you are interested in information about types, or about how the
d4f3574e
SS
4350fields of a struct or a class are declared, use the @code{ptype @var{exp}}
4351command rather than @code{print}. @xref{Symbols, ,Examining the Symbol
7a292a7a 4352Table}.
c906108c
SS
4353
4354@menu
4355* Expressions:: Expressions
4356* Variables:: Program variables
4357* Arrays:: Artificial arrays
4358* Output Formats:: Output formats
4359* Memory:: Examining memory
4360* Auto Display:: Automatic display
4361* Print Settings:: Print settings
4362* Value History:: Value history
4363* Convenience Vars:: Convenience variables
4364* Registers:: Registers
c906108c 4365* Floating Point Hardware:: Floating point hardware
29e57380 4366* Memory Region Attributes:: Memory region attributes
c906108c
SS
4367@end menu
4368
6d2ebf8b 4369@node Expressions
c906108c
SS
4370@section Expressions
4371
4372@cindex expressions
4373@code{print} and many other @value{GDBN} commands accept an expression and
4374compute its value. Any kind of constant, variable or operator defined
4375by the programming language you are using is valid in an expression in
4376@value{GDBN}. This includes conditional expressions, function calls, casts
4377and string constants. It unfortunately does not include symbols defined
4378by preprocessor @code{#define} commands.
4379
d4f3574e
SS
4380@value{GDBN} supports array constants in expressions input by
4381the user. The syntax is @{@var{element}, @var{element}@dots{}@}. For example,
5d161b24 4382you can use the command @code{print @{1, 2, 3@}} to build up an array in
d4f3574e 4383memory that is @code{malloc}ed in the target program.
c906108c 4384
c906108c
SS
4385Because C is so widespread, most of the expressions shown in examples in
4386this manual are in C. @xref{Languages, , Using @value{GDBN} with Different
4387Languages}, for information on how to use expressions in other
4388languages.
4389
4390In this section, we discuss operators that you can use in @value{GDBN}
4391expressions regardless of your programming language.
4392
4393Casts are supported in all languages, not just in C, because it is so
4394useful to cast a number into a pointer in order to examine a structure
4395at that address in memory.
4396@c FIXME: casts supported---Mod2 true?
c906108c
SS
4397
4398@value{GDBN} supports these operators, in addition to those common
4399to programming languages:
4400
4401@table @code
4402@item @@
4403@samp{@@} is a binary operator for treating parts of memory as arrays.
4404@xref{Arrays, ,Artificial arrays}, for more information.
4405
4406@item ::
4407@samp{::} allows you to specify a variable in terms of the file or
4408function where it is defined. @xref{Variables, ,Program variables}.
4409
4410@cindex @{@var{type}@}
4411@cindex type casting memory
4412@cindex memory, viewing as typed object
4413@cindex casts, to view memory
4414@item @{@var{type}@} @var{addr}
4415Refers to an object of type @var{type} stored at address @var{addr} in
4416memory. @var{addr} may be any expression whose value is an integer or
4417pointer (but parentheses are required around binary operators, just as in
4418a cast). This construct is allowed regardless of what kind of data is
4419normally supposed to reside at @var{addr}.
4420@end table
4421
6d2ebf8b 4422@node Variables
c906108c
SS
4423@section Program variables
4424
4425The most common kind of expression to use is the name of a variable
4426in your program.
4427
4428Variables in expressions are understood in the selected stack frame
4429(@pxref{Selection, ,Selecting a frame}); they must be either:
4430
4431@itemize @bullet
4432@item
4433global (or file-static)
4434@end itemize
4435
5d161b24 4436@noindent or
c906108c
SS
4437
4438@itemize @bullet
4439@item
4440visible according to the scope rules of the
4441programming language from the point of execution in that frame
5d161b24 4442@end itemize
c906108c
SS
4443
4444@noindent This means that in the function
4445
4446@example
4447foo (a)
4448 int a;
4449@{
4450 bar (a);
4451 @{
4452 int b = test ();
4453 bar (b);
4454 @}
4455@}
4456@end example
4457
4458@noindent
4459you can examine and use the variable @code{a} whenever your program is
4460executing within the function @code{foo}, but you can only use or
4461examine the variable @code{b} while your program is executing inside
4462the block where @code{b} is declared.
4463
4464@cindex variable name conflict
4465There is an exception: you can refer to a variable or function whose
4466scope is a single source file even if the current execution point is not
4467in this file. But it is possible to have more than one such variable or
4468function with the same name (in different source files). If that
4469happens, referring to that name has unpredictable effects. If you wish,
4470you can specify a static variable in a particular function or file,
4471using the colon-colon notation:
4472
d4f3574e 4473@cindex colon-colon, context for variables/functions
c906108c
SS
4474@iftex
4475@c info cannot cope with a :: index entry, but why deprive hard copy readers?
41afff9a 4476@cindex @code{::}, context for variables/functions
c906108c
SS
4477@end iftex
4478@example
4479@var{file}::@var{variable}
4480@var{function}::@var{variable}
4481@end example
4482
4483@noindent
4484Here @var{file} or @var{function} is the name of the context for the
4485static @var{variable}. In the case of file names, you can use quotes to
4486make sure @value{GDBN} parses the file name as a single word---for example,
4487to print a global value of @code{x} defined in @file{f2.c}:
4488
4489@example
4490(@value{GDBP}) p 'f2.c'::x
4491@end example
4492
b37052ae 4493@cindex C@t{++} scope resolution
c906108c 4494This use of @samp{::} is very rarely in conflict with the very similar
b37052ae 4495use of the same notation in C@t{++}. @value{GDBN} also supports use of the C@t{++}
c906108c
SS
4496scope resolution operator in @value{GDBN} expressions.
4497@c FIXME: Um, so what happens in one of those rare cases where it's in
4498@c conflict?? --mew
c906108c
SS
4499
4500@cindex wrong values
4501@cindex variable values, wrong
4502@quotation
4503@emph{Warning:} Occasionally, a local variable may appear to have the
4504wrong value at certain points in a function---just after entry to a new
4505scope, and just before exit.
4506@end quotation
4507You may see this problem when you are stepping by machine instructions.
4508This is because, on most machines, it takes more than one instruction to
4509set up a stack frame (including local variable definitions); if you are
4510stepping by machine instructions, variables may appear to have the wrong
4511values until the stack frame is completely built. On exit, it usually
4512also takes more than one machine instruction to destroy a stack frame;
4513after you begin stepping through that group of instructions, local
4514variable definitions may be gone.
4515
4516This may also happen when the compiler does significant optimizations.
4517To be sure of always seeing accurate values, turn off all optimization
4518when compiling.
4519
d4f3574e
SS
4520@cindex ``No symbol "foo" in current context''
4521Another possible effect of compiler optimizations is to optimize
4522unused variables out of existence, or assign variables to registers (as
4523opposed to memory addresses). Depending on the support for such cases
4524offered by the debug info format used by the compiler, @value{GDBN}
4525might not be able to display values for such local variables. If that
4526happens, @value{GDBN} will print a message like this:
4527
4528@example
4529No symbol "foo" in current context.
4530@end example
4531
4532To solve such problems, either recompile without optimizations, or use a
4533different debug info format, if the compiler supports several such
b37052ae 4534formats. For example, @value{NGCC}, the @sc{gnu} C/C@t{++} compiler usually
d4f3574e
SS
4535supports the @samp{-gstabs} option. @samp{-gstabs} produces debug info
4536in a format that is superior to formats such as COFF. You may be able
96c405b3 4537to use DWARF2 (@samp{-gdwarf-2}), which is also an effective form for
d4f3574e
SS
4538debug info. See @ref{Debugging Options,,Options for Debugging Your
4539Program or @sc{gnu} CC, gcc.info, Using @sc{gnu} CC}, for more
4540information.
4541
4542
6d2ebf8b 4543@node Arrays
c906108c
SS
4544@section Artificial arrays
4545
4546@cindex artificial array
41afff9a 4547@kindex @@@r{, referencing memory as an array}
c906108c
SS
4548It is often useful to print out several successive objects of the
4549same type in memory; a section of an array, or an array of
4550dynamically determined size for which only a pointer exists in the
4551program.
4552
4553You can do this by referring to a contiguous span of memory as an
4554@dfn{artificial array}, using the binary operator @samp{@@}. The left
4555operand of @samp{@@} should be the first element of the desired array
4556and be an individual object. The right operand should be the desired length
4557of the array. The result is an array value whose elements are all of
4558the type of the left argument. The first element is actually the left
4559argument; the second element comes from bytes of memory immediately
4560following those that hold the first element, and so on. Here is an
4561example. If a program says
4562
4563@example
4564int *array = (int *) malloc (len * sizeof (int));
4565@end example
4566
4567@noindent
4568you can print the contents of @code{array} with
4569
4570@example
4571p *array@@len
4572@end example
4573
4574The left operand of @samp{@@} must reside in memory. Array values made
4575with @samp{@@} in this way behave just like other arrays in terms of
4576subscripting, and are coerced to pointers when used in expressions.
4577Artificial arrays most often appear in expressions via the value history
4578(@pxref{Value History, ,Value history}), after printing one out.
4579
4580Another way to create an artificial array is to use a cast.
4581This re-interprets a value as if it were an array.
4582The value need not be in memory:
4583@example
4584(@value{GDBP}) p/x (short[2])0x12345678
4585$1 = @{0x1234, 0x5678@}
4586@end example
4587
4588As a convenience, if you leave the array length out (as in
c3f6f71d 4589@samp{(@var{type}[])@var{value}}) @value{GDBN} calculates the size to fill
c906108c
SS
4590the value (as @samp{sizeof(@var{value})/sizeof(@var{type})}:
4591@example
4592(@value{GDBP}) p/x (short[])0x12345678
4593$2 = @{0x1234, 0x5678@}
4594@end example
4595
4596Sometimes the artificial array mechanism is not quite enough; in
4597moderately complex data structures, the elements of interest may not
4598actually be adjacent---for example, if you are interested in the values
4599of pointers in an array. One useful work-around in this situation is
4600to use a convenience variable (@pxref{Convenience Vars, ,Convenience
4601variables}) as a counter in an expression that prints the first
4602interesting value, and then repeat that expression via @key{RET}. For
4603instance, suppose you have an array @code{dtab} of pointers to
4604structures, and you are interested in the values of a field @code{fv}
4605in each structure. Here is an example of what you might type:
4606
4607@example
4608set $i = 0
4609p dtab[$i++]->fv
4610@key{RET}
4611@key{RET}
4612@dots{}
4613@end example
4614
6d2ebf8b 4615@node Output Formats
c906108c
SS
4616@section Output formats
4617
4618@cindex formatted output
4619@cindex output formats
4620By default, @value{GDBN} prints a value according to its data type. Sometimes
4621this is not what you want. For example, you might want to print a number
4622in hex, or a pointer in decimal. Or you might want to view data in memory
4623at a certain address as a character string or as an instruction. To do
4624these things, specify an @dfn{output format} when you print a value.
4625
4626The simplest use of output formats is to say how to print a value
4627already computed. This is done by starting the arguments of the
4628@code{print} command with a slash and a format letter. The format
4629letters supported are:
4630
4631@table @code
4632@item x
4633Regard the bits of the value as an integer, and print the integer in
4634hexadecimal.
4635
4636@item d
4637Print as integer in signed decimal.
4638
4639@item u
4640Print as integer in unsigned decimal.
4641
4642@item o
4643Print as integer in octal.
4644
4645@item t
4646Print as integer in binary. The letter @samp{t} stands for ``two''.
4647@footnote{@samp{b} cannot be used because these format letters are also
4648used with the @code{x} command, where @samp{b} stands for ``byte'';
d4f3574e 4649see @ref{Memory,,Examining memory}.}
c906108c
SS
4650
4651@item a
4652@cindex unknown address, locating
3d67e040 4653@cindex locate address
c906108c
SS
4654Print as an address, both absolute in hexadecimal and as an offset from
4655the nearest preceding symbol. You can use this format used to discover
4656where (in what function) an unknown address is located:
4657
4658@example
4659(@value{GDBP}) p/a 0x54320
4660$3 = 0x54320 <_initialize_vx+396>
4661@end example
4662
3d67e040
EZ
4663@noindent
4664The command @code{info symbol 0x54320} yields similar results.
4665@xref{Symbols, info symbol}.
4666
c906108c
SS
4667@item c
4668Regard as an integer and print it as a character constant.
4669
4670@item f
4671Regard the bits of the value as a floating point number and print
4672using typical floating point syntax.
4673@end table
4674
4675For example, to print the program counter in hex (@pxref{Registers}), type
4676
4677@example
4678p/x $pc
4679@end example
4680
4681@noindent
4682Note that no space is required before the slash; this is because command
4683names in @value{GDBN} cannot contain a slash.
4684
4685To reprint the last value in the value history with a different format,
4686you can use the @code{print} command with just a format and no
4687expression. For example, @samp{p/x} reprints the last value in hex.
4688
6d2ebf8b 4689@node Memory
c906108c
SS
4690@section Examining memory
4691
4692You can use the command @code{x} (for ``examine'') to examine memory in
4693any of several formats, independently of your program's data types.
4694
4695@cindex examining memory
4696@table @code
41afff9a 4697@kindex x @r{(examine memory)}
c906108c
SS
4698@item x/@var{nfu} @var{addr}
4699@itemx x @var{addr}
4700@itemx x
4701Use the @code{x} command to examine memory.
4702@end table
4703
4704@var{n}, @var{f}, and @var{u} are all optional parameters that specify how
4705much memory to display and how to format it; @var{addr} is an
4706expression giving the address where you want to start displaying memory.
4707If you use defaults for @var{nfu}, you need not type the slash @samp{/}.
4708Several commands set convenient defaults for @var{addr}.
4709
4710@table @r
4711@item @var{n}, the repeat count
4712The repeat count is a decimal integer; the default is 1. It specifies
4713how much memory (counting by units @var{u}) to display.
4714@c This really is **decimal**; unaffected by 'set radix' as of GDB
4715@c 4.1.2.
4716
4717@item @var{f}, the display format
4718The display format is one of the formats used by @code{print},
4719@samp{s} (null-terminated string), or @samp{i} (machine instruction).
4720The default is @samp{x} (hexadecimal) initially.
4721The default changes each time you use either @code{x} or @code{print}.
4722
4723@item @var{u}, the unit size
4724The unit size is any of
4725
4726@table @code
4727@item b
4728Bytes.
4729@item h
4730Halfwords (two bytes).
4731@item w
4732Words (four bytes). This is the initial default.
4733@item g
4734Giant words (eight bytes).
4735@end table
4736
4737Each time you specify a unit size with @code{x}, that size becomes the
4738default unit the next time you use @code{x}. (For the @samp{s} and
4739@samp{i} formats, the unit size is ignored and is normally not written.)
4740
4741@item @var{addr}, starting display address
4742@var{addr} is the address where you want @value{GDBN} to begin displaying
4743memory. The expression need not have a pointer value (though it may);
4744it is always interpreted as an integer address of a byte of memory.
4745@xref{Expressions, ,Expressions}, for more information on expressions. The default for
4746@var{addr} is usually just after the last address examined---but several
4747other commands also set the default address: @code{info breakpoints} (to
4748the address of the last breakpoint listed), @code{info line} (to the
4749starting address of a line), and @code{print} (if you use it to display
4750a value from memory).
4751@end table
4752
4753For example, @samp{x/3uh 0x54320} is a request to display three halfwords
4754(@code{h}) of memory, formatted as unsigned decimal integers (@samp{u}),
4755starting at address @code{0x54320}. @samp{x/4xw $sp} prints the four
4756words (@samp{w}) of memory above the stack pointer (here, @samp{$sp};
d4f3574e 4757@pxref{Registers, ,Registers}) in hexadecimal (@samp{x}).
c906108c
SS
4758
4759Since the letters indicating unit sizes are all distinct from the
4760letters specifying output formats, you do not have to remember whether
4761unit size or format comes first; either order works. The output
4762specifications @samp{4xw} and @samp{4wx} mean exactly the same thing.
4763(However, the count @var{n} must come first; @samp{wx4} does not work.)
4764
4765Even though the unit size @var{u} is ignored for the formats @samp{s}
4766and @samp{i}, you might still want to use a count @var{n}; for example,
4767@samp{3i} specifies that you want to see three machine instructions,
4768including any operands. The command @code{disassemble} gives an
d4f3574e 4769alternative way of inspecting machine instructions; see @ref{Machine
c906108c
SS
4770Code,,Source and machine code}.
4771
4772All the defaults for the arguments to @code{x} are designed to make it
4773easy to continue scanning memory with minimal specifications each time
4774you use @code{x}. For example, after you have inspected three machine
4775instructions with @samp{x/3i @var{addr}}, you can inspect the next seven
4776with just @samp{x/7}. If you use @key{RET} to repeat the @code{x} command,
4777the repeat count @var{n} is used again; the other arguments default as
4778for successive uses of @code{x}.
4779
4780@cindex @code{$_}, @code{$__}, and value history
4781The addresses and contents printed by the @code{x} command are not saved
4782in the value history because there is often too much of them and they
4783would get in the way. Instead, @value{GDBN} makes these values available for
4784subsequent use in expressions as values of the convenience variables
4785@code{$_} and @code{$__}. After an @code{x} command, the last address
4786examined is available for use in expressions in the convenience variable
4787@code{$_}. The contents of that address, as examined, are available in
4788the convenience variable @code{$__}.
4789
4790If the @code{x} command has a repeat count, the address and contents saved
4791are from the last memory unit printed; this is not the same as the last
4792address printed if several units were printed on the last line of output.
4793
6d2ebf8b 4794@node Auto Display
c906108c
SS
4795@section Automatic display
4796@cindex automatic display
4797@cindex display of expressions
4798
4799If you find that you want to print the value of an expression frequently
4800(to see how it changes), you might want to add it to the @dfn{automatic
4801display list} so that @value{GDBN} prints its value each time your program stops.
4802Each expression added to the list is given a number to identify it;
4803to remove an expression from the list, you specify that number.
4804The automatic display looks like this:
4805
4806@example
48072: foo = 38
48083: bar[5] = (struct hack *) 0x3804
4809@end example
4810
4811@noindent
4812This display shows item numbers, expressions and their current values. As with
4813displays you request manually using @code{x} or @code{print}, you can
4814specify the output format you prefer; in fact, @code{display} decides
4815whether to use @code{print} or @code{x} depending on how elaborate your
4816format specification is---it uses @code{x} if you specify a unit size,
4817or one of the two formats (@samp{i} and @samp{s}) that are only
4818supported by @code{x}; otherwise it uses @code{print}.
4819
4820@table @code
4821@kindex display
d4f3574e
SS
4822@item display @var{expr}
4823Add the expression @var{expr} to the list of expressions to display
c906108c
SS
4824each time your program stops. @xref{Expressions, ,Expressions}.
4825
4826@code{display} does not repeat if you press @key{RET} again after using it.
4827
d4f3574e 4828@item display/@var{fmt} @var{expr}
c906108c 4829For @var{fmt} specifying only a display format and not a size or
d4f3574e 4830count, add the expression @var{expr} to the auto-display list but
c906108c
SS
4831arrange to display it each time in the specified format @var{fmt}.
4832@xref{Output Formats,,Output formats}.
4833
4834@item display/@var{fmt} @var{addr}
4835For @var{fmt} @samp{i} or @samp{s}, or including a unit-size or a
4836number of units, add the expression @var{addr} as a memory address to
4837be examined each time your program stops. Examining means in effect
4838doing @samp{x/@var{fmt} @var{addr}}. @xref{Memory, ,Examining memory}.
4839@end table
4840
4841For example, @samp{display/i $pc} can be helpful, to see the machine
4842instruction about to be executed each time execution stops (@samp{$pc}
d4f3574e 4843is a common name for the program counter; @pxref{Registers, ,Registers}).
c906108c
SS
4844
4845@table @code
4846@kindex delete display
4847@kindex undisplay
4848@item undisplay @var{dnums}@dots{}
4849@itemx delete display @var{dnums}@dots{}
4850Remove item numbers @var{dnums} from the list of expressions to display.
4851
4852@code{undisplay} does not repeat if you press @key{RET} after using it.
4853(Otherwise you would just get the error @samp{No display number @dots{}}.)
4854
4855@kindex disable display
4856@item disable display @var{dnums}@dots{}
4857Disable the display of item numbers @var{dnums}. A disabled display
4858item is not printed automatically, but is not forgotten. It may be
4859enabled again later.
4860
4861@kindex enable display
4862@item enable display @var{dnums}@dots{}
4863Enable display of item numbers @var{dnums}. It becomes effective once
4864again in auto display of its expression, until you specify otherwise.
4865
4866@item display
4867Display the current values of the expressions on the list, just as is
4868done when your program stops.
4869
4870@kindex info display
4871@item info display
4872Print the list of expressions previously set up to display
4873automatically, each one with its item number, but without showing the
4874values. This includes disabled expressions, which are marked as such.
4875It also includes expressions which would not be displayed right now
4876because they refer to automatic variables not currently available.
4877@end table
4878
4879If a display expression refers to local variables, then it does not make
4880sense outside the lexical context for which it was set up. Such an
4881expression is disabled when execution enters a context where one of its
4882variables is not defined. For example, if you give the command
4883@code{display last_char} while inside a function with an argument
4884@code{last_char}, @value{GDBN} displays this argument while your program
4885continues to stop inside that function. When it stops elsewhere---where
4886there is no variable @code{last_char}---the display is disabled
4887automatically. The next time your program stops where @code{last_char}
4888is meaningful, you can enable the display expression once again.
4889
6d2ebf8b 4890@node Print Settings
c906108c
SS
4891@section Print settings
4892
4893@cindex format options
4894@cindex print settings
4895@value{GDBN} provides the following ways to control how arrays, structures,
4896and symbols are printed.
4897
4898@noindent
4899These settings are useful for debugging programs in any language:
4900
4901@table @code
4902@kindex set print address
4903@item set print address
4904@itemx set print address on
4905@value{GDBN} prints memory addresses showing the location of stack
4906traces, structure values, pointer values, breakpoints, and so forth,
4907even when it also displays the contents of those addresses. The default
4908is @code{on}. For example, this is what a stack frame display looks like with
4909@code{set print address on}:
4910
4911@smallexample
4912@group
4913(@value{GDBP}) f
4914#0 set_quotes (lq=0x34c78 "<<", rq=0x34c88 ">>")
4915 at input.c:530
4916530 if (lquote != def_lquote)
4917@end group
4918@end smallexample
4919
4920@item set print address off
4921Do not print addresses when displaying their contents. For example,
4922this is the same stack frame displayed with @code{set print address off}:
4923
4924@smallexample
4925@group
4926(@value{GDBP}) set print addr off
4927(@value{GDBP}) f
4928#0 set_quotes (lq="<<", rq=">>") at input.c:530
4929530 if (lquote != def_lquote)
4930@end group
4931@end smallexample
4932
4933You can use @samp{set print address off} to eliminate all machine
4934dependent displays from the @value{GDBN} interface. For example, with
4935@code{print address off}, you should get the same text for backtraces on
4936all machines---whether or not they involve pointer arguments.
4937
4938@kindex show print address
4939@item show print address
4940Show whether or not addresses are to be printed.
4941@end table
4942
4943When @value{GDBN} prints a symbolic address, it normally prints the
4944closest earlier symbol plus an offset. If that symbol does not uniquely
4945identify the address (for example, it is a name whose scope is a single
4946source file), you may need to clarify. One way to do this is with
4947@code{info line}, for example @samp{info line *0x4537}. Alternately,
4948you can set @value{GDBN} to print the source file and line number when
4949it prints a symbolic address:
4950
4951@table @code
4952@kindex set print symbol-filename
4953@item set print symbol-filename on
4954Tell @value{GDBN} to print the source file name and line number of a
4955symbol in the symbolic form of an address.
4956
4957@item set print symbol-filename off
4958Do not print source file name and line number of a symbol. This is the
4959default.
4960
4961@kindex show print symbol-filename
4962@item show print symbol-filename
4963Show whether or not @value{GDBN} will print the source file name and
4964line number of a symbol in the symbolic form of an address.
4965@end table
4966
4967Another situation where it is helpful to show symbol filenames and line
4968numbers is when disassembling code; @value{GDBN} shows you the line
4969number and source file that corresponds to each instruction.
4970
4971Also, you may wish to see the symbolic form only if the address being
4972printed is reasonably close to the closest earlier symbol:
4973
4974@table @code
4975@kindex set print max-symbolic-offset
4976@item set print max-symbolic-offset @var{max-offset}
4977Tell @value{GDBN} to only display the symbolic form of an address if the
4978offset between the closest earlier symbol and the address is less than
5d161b24 4979@var{max-offset}. The default is 0, which tells @value{GDBN}
c906108c
SS
4980to always print the symbolic form of an address if any symbol precedes it.
4981
4982@kindex show print max-symbolic-offset
4983@item show print max-symbolic-offset
4984Ask how large the maximum offset is that @value{GDBN} prints in a
4985symbolic address.
4986@end table
4987
4988@cindex wild pointer, interpreting
4989@cindex pointer, finding referent
4990If you have a pointer and you are not sure where it points, try
4991@samp{set print symbol-filename on}. Then you can determine the name
4992and source file location of the variable where it points, using
4993@samp{p/a @var{pointer}}. This interprets the address in symbolic form.
4994For example, here @value{GDBN} shows that a variable @code{ptt} points
4995at another variable @code{t}, defined in @file{hi2.c}:
4996
4997@example
4998(@value{GDBP}) set print symbol-filename on
4999(@value{GDBP}) p/a ptt
5000$4 = 0xe008 <t in hi2.c>
5001@end example
5002
5003@quotation
5004@emph{Warning:} For pointers that point to a local variable, @samp{p/a}
5005does not show the symbol name and filename of the referent, even with
5006the appropriate @code{set print} options turned on.
5007@end quotation
5008
5009Other settings control how different kinds of objects are printed:
5010
5011@table @code
5012@kindex set print array
5013@item set print array
5014@itemx set print array on
5015Pretty print arrays. This format is more convenient to read,
5016but uses more space. The default is off.
5017
5018@item set print array off
5019Return to compressed format for arrays.
5020
5021@kindex show print array
5022@item show print array
5023Show whether compressed or pretty format is selected for displaying
5024arrays.
5025
5026@kindex set print elements
5027@item set print elements @var{number-of-elements}
5028Set a limit on how many elements of an array @value{GDBN} will print.
5029If @value{GDBN} is printing a large array, it stops printing after it has
5030printed the number of elements set by the @code{set print elements} command.
5031This limit also applies to the display of strings.
d4f3574e 5032When @value{GDBN} starts, this limit is set to 200.
c906108c
SS
5033Setting @var{number-of-elements} to zero means that the printing is unlimited.
5034
5035@kindex show print elements
5036@item show print elements
5037Display the number of elements of a large array that @value{GDBN} will print.
5038If the number is 0, then the printing is unlimited.
5039
5040@kindex set print null-stop
5041@item set print null-stop
5042Cause @value{GDBN} to stop printing the characters of an array when the first
d4f3574e 5043@sc{null} is encountered. This is useful when large arrays actually
c906108c 5044contain only short strings.
d4f3574e 5045The default is off.
c906108c
SS
5046
5047@kindex set print pretty
5048@item set print pretty on
5d161b24 5049Cause @value{GDBN} to print structures in an indented format with one member
c906108c
SS
5050per line, like this:
5051
5052@smallexample
5053@group
5054$1 = @{
5055 next = 0x0,
5056 flags = @{
5057 sweet = 1,
5058 sour = 1
5059 @},
5060 meat = 0x54 "Pork"
5061@}
5062@end group
5063@end smallexample
5064
5065@item set print pretty off
5066Cause @value{GDBN} to print structures in a compact format, like this:
5067
5068@smallexample
5069@group
5070$1 = @{next = 0x0, flags = @{sweet = 1, sour = 1@}, \
5071meat = 0x54 "Pork"@}
5072@end group
5073@end smallexample
5074
5075@noindent
5076This is the default format.
5077
5078@kindex show print pretty
5079@item show print pretty
5080Show which format @value{GDBN} is using to print structures.
5081
5082@kindex set print sevenbit-strings
5083@item set print sevenbit-strings on
5084Print using only seven-bit characters; if this option is set,
5085@value{GDBN} displays any eight-bit characters (in strings or
5086character values) using the notation @code{\}@var{nnn}. This setting is
5087best if you are working in English (@sc{ascii}) and you use the
5088high-order bit of characters as a marker or ``meta'' bit.
5089
5090@item set print sevenbit-strings off
5091Print full eight-bit characters. This allows the use of more
5092international character sets, and is the default.
5093
5094@kindex show print sevenbit-strings
5095@item show print sevenbit-strings
5096Show whether or not @value{GDBN} is printing only seven-bit characters.
5097
5098@kindex set print union
5099@item set print union on
5d161b24 5100Tell @value{GDBN} to print unions which are contained in structures. This
c906108c
SS
5101is the default setting.
5102
5103@item set print union off
5104Tell @value{GDBN} not to print unions which are contained in structures.
5105
5106@kindex show print union
5107@item show print union
5108Ask @value{GDBN} whether or not it will print unions which are contained in
5109structures.
5110
5111For example, given the declarations
5112
5113@smallexample
5114typedef enum @{Tree, Bug@} Species;
5115typedef enum @{Big_tree, Acorn, Seedling@} Tree_forms;
5d161b24 5116typedef enum @{Caterpillar, Cocoon, Butterfly@}
c906108c
SS
5117 Bug_forms;
5118
5119struct thing @{
5120 Species it;
5121 union @{
5122 Tree_forms tree;
5123 Bug_forms bug;
5124 @} form;
5125@};
5126
5127struct thing foo = @{Tree, @{Acorn@}@};
5128@end smallexample
5129
5130@noindent
5131with @code{set print union on} in effect @samp{p foo} would print
5132
5133@smallexample
5134$1 = @{it = Tree, form = @{tree = Acorn, bug = Cocoon@}@}
5135@end smallexample
5136
5137@noindent
5138and with @code{set print union off} in effect it would print
5139
5140@smallexample
5141$1 = @{it = Tree, form = @{...@}@}
5142@end smallexample
5143@end table
5144
c906108c
SS
5145@need 1000
5146@noindent
b37052ae 5147These settings are of interest when debugging C@t{++} programs:
c906108c
SS
5148
5149@table @code
5150@cindex demangling
5151@kindex set print demangle
5152@item set print demangle
5153@itemx set print demangle on
b37052ae 5154Print C@t{++} names in their source form rather than in the encoded
c906108c 5155(``mangled'') form passed to the assembler and linker for type-safe
d4f3574e 5156linkage. The default is on.
c906108c
SS
5157
5158@kindex show print demangle
5159@item show print demangle
b37052ae 5160Show whether C@t{++} names are printed in mangled or demangled form.
c906108c
SS
5161
5162@kindex set print asm-demangle
5163@item set print asm-demangle
5164@itemx set print asm-demangle on
b37052ae 5165Print C@t{++} names in their source form rather than their mangled form, even
c906108c
SS
5166in assembler code printouts such as instruction disassemblies.
5167The default is off.
5168
5169@kindex show print asm-demangle
5170@item show print asm-demangle
b37052ae 5171Show whether C@t{++} names in assembly listings are printed in mangled
c906108c
SS
5172or demangled form.
5173
5174@kindex set demangle-style
b37052ae
EZ
5175@cindex C@t{++} symbol decoding style
5176@cindex symbol decoding style, C@t{++}
c906108c
SS
5177@item set demangle-style @var{style}
5178Choose among several encoding schemes used by different compilers to
b37052ae 5179represent C@t{++} names. The choices for @var{style} are currently:
c906108c
SS
5180
5181@table @code
5182@item auto
5183Allow @value{GDBN} to choose a decoding style by inspecting your program.
5184
5185@item gnu
b37052ae 5186Decode based on the @sc{gnu} C@t{++} compiler (@code{g++}) encoding algorithm.
c906108c 5187This is the default.
c906108c
SS
5188
5189@item hp
b37052ae 5190Decode based on the HP ANSI C@t{++} (@code{aCC}) encoding algorithm.
c906108c
SS
5191
5192@item lucid
b37052ae 5193Decode based on the Lucid C@t{++} compiler (@code{lcc}) encoding algorithm.
c906108c
SS
5194
5195@item arm
b37052ae 5196Decode using the algorithm in the @cite{C@t{++} Annotated Reference Manual}.
c906108c
SS
5197@strong{Warning:} this setting alone is not sufficient to allow
5198debugging @code{cfront}-generated executables. @value{GDBN} would
5199require further enhancement to permit that.
5200
5201@end table
5202If you omit @var{style}, you will see a list of possible formats.
5203
5204@kindex show demangle-style
5205@item show demangle-style
b37052ae 5206Display the encoding style currently in use for decoding C@t{++} symbols.
c906108c
SS
5207
5208@kindex set print object
5209@item set print object
5210@itemx set print object on
5211When displaying a pointer to an object, identify the @emph{actual}
5212(derived) type of the object rather than the @emph{declared} type, using
5213the virtual function table.
5214
5215@item set print object off
5216Display only the declared type of objects, without reference to the
5217virtual function table. This is the default setting.
5218
5219@kindex show print object
5220@item show print object
5221Show whether actual, or declared, object types are displayed.
5222
5223@kindex set print static-members
5224@item set print static-members
5225@itemx set print static-members on
b37052ae 5226Print static members when displaying a C@t{++} object. The default is on.
c906108c
SS
5227
5228@item set print static-members off
b37052ae 5229Do not print static members when displaying a C@t{++} object.
c906108c
SS
5230
5231@kindex show print static-members
5232@item show print static-members
b37052ae 5233Show whether C@t{++} static members are printed, or not.
c906108c
SS
5234
5235@c These don't work with HP ANSI C++ yet.
5236@kindex set print vtbl
5237@item set print vtbl
5238@itemx set print vtbl on
b37052ae 5239Pretty print C@t{++} virtual function tables. The default is off.
c906108c 5240(The @code{vtbl} commands do not work on programs compiled with the HP
b37052ae 5241ANSI C@t{++} compiler (@code{aCC}).)
c906108c
SS
5242
5243@item set print vtbl off
b37052ae 5244Do not pretty print C@t{++} virtual function tables.
c906108c
SS
5245
5246@kindex show print vtbl
5247@item show print vtbl
b37052ae 5248Show whether C@t{++} virtual function tables are pretty printed, or not.
c906108c 5249@end table
c906108c 5250
6d2ebf8b 5251@node Value History
c906108c
SS
5252@section Value history
5253
5254@cindex value history
5d161b24
DB
5255Values printed by the @code{print} command are saved in the @value{GDBN}
5256@dfn{value history}. This allows you to refer to them in other expressions.
5257Values are kept until the symbol table is re-read or discarded
5258(for example with the @code{file} or @code{symbol-file} commands).
5259When the symbol table changes, the value history is discarded,
5260since the values may contain pointers back to the types defined in the
c906108c
SS
5261symbol table.
5262
5263@cindex @code{$}
5264@cindex @code{$$}
5265@cindex history number
5266The values printed are given @dfn{history numbers} by which you can
5267refer to them. These are successive integers starting with one.
5268@code{print} shows you the history number assigned to a value by
5269printing @samp{$@var{num} = } before the value; here @var{num} is the
5270history number.
5271
5272To refer to any previous value, use @samp{$} followed by the value's
5273history number. The way @code{print} labels its output is designed to
5274remind you of this. Just @code{$} refers to the most recent value in
5275the history, and @code{$$} refers to the value before that.
5276@code{$$@var{n}} refers to the @var{n}th value from the end; @code{$$2}
5277is the value just prior to @code{$$}, @code{$$1} is equivalent to
5278@code{$$}, and @code{$$0} is equivalent to @code{$}.
5279
5280For example, suppose you have just printed a pointer to a structure and
5281want to see the contents of the structure. It suffices to type
5282
5283@example
5284p *$
5285@end example
5286
5287If you have a chain of structures where the component @code{next} points
5288to the next one, you can print the contents of the next one with this:
5289
5290@example
5291p *$.next
5292@end example
5293
5294@noindent
5295You can print successive links in the chain by repeating this
5296command---which you can do by just typing @key{RET}.
5297
5298Note that the history records values, not expressions. If the value of
5299@code{x} is 4 and you type these commands:
5300
5301@example
5302print x
5303set x=5
5304@end example
5305
5306@noindent
5307then the value recorded in the value history by the @code{print} command
5308remains 4 even though the value of @code{x} has changed.
5309
5310@table @code
5311@kindex show values
5312@item show values
5313Print the last ten values in the value history, with their item numbers.
5314This is like @samp{p@ $$9} repeated ten times, except that @code{show
5315values} does not change the history.
5316
5317@item show values @var{n}
5318Print ten history values centered on history item number @var{n}.
5319
5320@item show values +
5321Print ten history values just after the values last printed. If no more
5322values are available, @code{show values +} produces no display.
5323@end table
5324
5325Pressing @key{RET} to repeat @code{show values @var{n}} has exactly the
5326same effect as @samp{show values +}.
5327
6d2ebf8b 5328@node Convenience Vars
c906108c
SS
5329@section Convenience variables
5330
5331@cindex convenience variables
5332@value{GDBN} provides @dfn{convenience variables} that you can use within
5333@value{GDBN} to hold on to a value and refer to it later. These variables
5334exist entirely within @value{GDBN}; they are not part of your program, and
5335setting a convenience variable has no direct effect on further execution
5336of your program. That is why you can use them freely.
5337
5338Convenience variables are prefixed with @samp{$}. Any name preceded by
5339@samp{$} can be used for a convenience variable, unless it is one of
d4f3574e 5340the predefined machine-specific register names (@pxref{Registers, ,Registers}).
c906108c
SS
5341(Value history references, in contrast, are @emph{numbers} preceded
5342by @samp{$}. @xref{Value History, ,Value history}.)
5343
5344You can save a value in a convenience variable with an assignment
5345expression, just as you would set a variable in your program.
5346For example:
5347
5348@example
5349set $foo = *object_ptr
5350@end example
5351
5352@noindent
5353would save in @code{$foo} the value contained in the object pointed to by
5354@code{object_ptr}.
5355
5356Using a convenience variable for the first time creates it, but its
5357value is @code{void} until you assign a new value. You can alter the
5358value with another assignment at any time.
5359
5360Convenience variables have no fixed types. You can assign a convenience
5361variable any type of value, including structures and arrays, even if
5362that variable already has a value of a different type. The convenience
5363variable, when used as an expression, has the type of its current value.
5364
5365@table @code
5366@kindex show convenience
5367@item show convenience
5368Print a list of convenience variables used so far, and their values.
d4f3574e 5369Abbreviated @code{show conv}.
c906108c
SS
5370@end table
5371
5372One of the ways to use a convenience variable is as a counter to be
5373incremented or a pointer to be advanced. For example, to print
5374a field from successive elements of an array of structures:
5375
5376@example
5377set $i = 0
5378print bar[$i++]->contents
5379@end example
5380
d4f3574e
SS
5381@noindent
5382Repeat that command by typing @key{RET}.
c906108c
SS
5383
5384Some convenience variables are created automatically by @value{GDBN} and given
5385values likely to be useful.
5386
5387@table @code
41afff9a 5388@vindex $_@r{, convenience variable}
c906108c
SS
5389@item $_
5390The variable @code{$_} is automatically set by the @code{x} command to
5391the last address examined (@pxref{Memory, ,Examining memory}). Other
5392commands which provide a default address for @code{x} to examine also
5393set @code{$_} to that address; these commands include @code{info line}
5394and @code{info breakpoint}. The type of @code{$_} is @code{void *}
5395except when set by the @code{x} command, in which case it is a pointer
5396to the type of @code{$__}.
5397
41afff9a 5398@vindex $__@r{, convenience variable}
c906108c
SS
5399@item $__
5400The variable @code{$__} is automatically set by the @code{x} command
5401to the value found in the last address examined. Its type is chosen
5402to match the format in which the data was printed.
5403
5404@item $_exitcode
41afff9a 5405@vindex $_exitcode@r{, convenience variable}
c906108c
SS
5406The variable @code{$_exitcode} is automatically set to the exit code when
5407the program being debugged terminates.
5408@end table
5409
53a5351d
JM
5410On HP-UX systems, if you refer to a function or variable name that
5411begins with a dollar sign, @value{GDBN} searches for a user or system
5412name first, before it searches for a convenience variable.
c906108c 5413
6d2ebf8b 5414@node Registers
c906108c
SS
5415@section Registers
5416
5417@cindex registers
5418You can refer to machine register contents, in expressions, as variables
5419with names starting with @samp{$}. The names of registers are different
5420for each machine; use @code{info registers} to see the names used on
5421your machine.
5422
5423@table @code
5424@kindex info registers
5425@item info registers
5426Print the names and values of all registers except floating-point
5427registers (in the selected stack frame).
5428
5429@kindex info all-registers
5430@cindex floating point registers
5431@item info all-registers
5432Print the names and values of all registers, including floating-point
5433registers.
5434
5435@item info registers @var{regname} @dots{}
5436Print the @dfn{relativized} value of each specified register @var{regname}.
5d161b24
DB
5437As discussed in detail below, register values are normally relative to
5438the selected stack frame. @var{regname} may be any register name valid on
c906108c
SS
5439the machine you are using, with or without the initial @samp{$}.
5440@end table
5441
5442@value{GDBN} has four ``standard'' register names that are available (in
5443expressions) on most machines---whenever they do not conflict with an
5444architecture's canonical mnemonics for registers. The register names
5445@code{$pc} and @code{$sp} are used for the program counter register and
5446the stack pointer. @code{$fp} is used for a register that contains a
5447pointer to the current stack frame, and @code{$ps} is used for a
5448register that contains the processor status. For example,
5449you could print the program counter in hex with
5450
5451@example
5452p/x $pc
5453@end example
5454
5455@noindent
5456or print the instruction to be executed next with
5457
5458@example
5459x/i $pc
5460@end example
5461
5462@noindent
5463or add four to the stack pointer@footnote{This is a way of removing
5464one word from the stack, on machines where stacks grow downward in
5465memory (most machines, nowadays). This assumes that the innermost
5466stack frame is selected; setting @code{$sp} is not allowed when other
5467stack frames are selected. To pop entire frames off the stack,
5468regardless of machine architecture, use @code{return};
d4f3574e 5469see @ref{Returning, ,Returning from a function}.} with
c906108c
SS
5470
5471@example
5472set $sp += 4
5473@end example
5474
5475Whenever possible, these four standard register names are available on
5476your machine even though the machine has different canonical mnemonics,
5477so long as there is no conflict. The @code{info registers} command
5478shows the canonical names. For example, on the SPARC, @code{info
5479registers} displays the processor status register as @code{$psr} but you
d4f3574e
SS
5480can also refer to it as @code{$ps}; and on x86-based machines @code{$ps}
5481is an alias for the @sc{eflags} register.
c906108c
SS
5482
5483@value{GDBN} always considers the contents of an ordinary register as an
5484integer when the register is examined in this way. Some machines have
5485special registers which can hold nothing but floating point; these
5486registers are considered to have floating point values. There is no way
5487to refer to the contents of an ordinary register as floating point value
5488(although you can @emph{print} it as a floating point value with
5489@samp{print/f $@var{regname}}).
5490
5491Some registers have distinct ``raw'' and ``virtual'' data formats. This
5492means that the data format in which the register contents are saved by
5493the operating system is not the same one that your program normally
5494sees. For example, the registers of the 68881 floating point
5495coprocessor are always saved in ``extended'' (raw) format, but all C
5496programs expect to work with ``double'' (virtual) format. In such
5d161b24 5497cases, @value{GDBN} normally works with the virtual format only (the format
c906108c
SS
5498that makes sense for your program), but the @code{info registers} command
5499prints the data in both formats.
5500
5501Normally, register values are relative to the selected stack frame
5502(@pxref{Selection, ,Selecting a frame}). This means that you get the
5503value that the register would contain if all stack frames farther in
5504were exited and their saved registers restored. In order to see the
5505true contents of hardware registers, you must select the innermost
5506frame (with @samp{frame 0}).
5507
5508However, @value{GDBN} must deduce where registers are saved, from the machine
5509code generated by your compiler. If some registers are not saved, or if
5510@value{GDBN} is unable to locate the saved registers, the selected stack
5511frame makes no difference.
5512
6d2ebf8b 5513@node Floating Point Hardware
c906108c
SS
5514@section Floating point hardware
5515@cindex floating point
5516
5517Depending on the configuration, @value{GDBN} may be able to give
5518you more information about the status of the floating point hardware.
5519
5520@table @code
5521@kindex info float
5522@item info float
5523Display hardware-dependent information about the floating
5524point unit. The exact contents and layout vary depending on the
5525floating point chip. Currently, @samp{info float} is supported on
5526the ARM and x86 machines.
5527@end table
c906108c 5528
29e57380
C
5529@node Memory Region Attributes
5530@section Memory Region Attributes
5531@cindex memory region attributes
5532
5533@dfn{Memory region attributes} allow you to describe special handling
5534required by regions of your target's memory. @value{GDBN} uses attributes
5535to determine whether to allow certain types of memory accesses; whether to
5536use specific width accesses; and whether to cache target memory.
5537
5538Defined memory regions can be individually enabled and disabled. When a
5539memory region is disabled, @value{GDBN} uses the default attributes when
5540accessing memory in that region. Similarly, if no memory regions have
5541been defined, @value{GDBN} uses the default attributes when accessing
5542all memory.
5543
5544When a memory region is defined, it is given a number to identify it;
5545to enable, disable, or remove a memory region, you specify that number.
5546
5547@table @code
5548@kindex mem
5549@item mem @var{address1} @var{address1} @var{attributes}@dots{}
5550Define memory region bounded by @var{address1} and @var{address2}
5551with attributes @var{attributes}@dots{}.
5552
5553@kindex delete mem
5554@item delete mem @var{nums}@dots{}
5555Remove memory region numbers @var{nums}.
5556
5557@kindex disable mem
5558@item disable mem @var{nums}@dots{}
5559Disable memory region numbers @var{nums}.
5560A disabled memory region is not forgotten.
5561It may be enabled again later.
5562
5563@kindex enable mem
5564@item enable mem @var{nums}@dots{}
5565Enable memory region numbers @var{nums}.
5566
5567@kindex info mem
5568@item info mem
5569Print a table of all defined memory regions, with the following columns
5570for each region.
5571
5572@table @emph
5573@item Memory Region Number
5574@item Enabled or Disabled.
5575Enabled memory regions are marked with @samp{y}.
5576Disabled memory regions are marked with @samp{n}.
5577
5578@item Lo Address
5579The address defining the inclusive lower bound of the memory region.
5580
5581@item Hi Address
5582The address defining the exclusive upper bound of the memory region.
5583
5584@item Attributes
5585The list of attributes set for this memory region.
5586@end table
5587@end table
5588
5589
5590@subsection Attributes
5591
5592@subsubsection Memory Access Mode
5593The access mode attributes set whether @value{GDBN} may make read or
5594write accesses to a memory region.
5595
5596While these attributes prevent @value{GDBN} from performing invalid
5597memory accesses, they do nothing to prevent the target system, I/O DMA,
5598etc. from accessing memory.
5599
5600@table @code
5601@item ro
5602Memory is read only.
5603@item wo
5604Memory is write only.
5605@item rw
5606Memory is read/write (default).
5607@end table
5608
5609@subsubsection Memory Access Size
5610The acccess size attributes tells @value{GDBN} to use specific sized
5611accesses in the memory region. Often memory mapped device registers
5612require specific sized accesses. If no access size attribute is
5613specified, @value{GDBN} may use accesses of any size.
5614
5615@table @code
5616@item 8
5617Use 8 bit memory accesses.
5618@item 16
5619Use 16 bit memory accesses.
5620@item 32
5621Use 32 bit memory accesses.
5622@item 64
5623Use 64 bit memory accesses.
5624@end table
5625
5626@c @subsubsection Hardware/Software Breakpoints
5627@c The hardware/software breakpoint attributes set whether @value{GDBN}
5628@c will use hardware or software breakpoints for the internal breakpoints
5629@c used by the step, next, finish, until, etc. commands.
5630@c
5631@c @table @code
5632@c @item hwbreak
5633@c Always use hardware breakpoints
5634@c @item swbreak (default)
5635@c @end table
5636
5637@subsubsection Data Cache
5638The data cache attributes set whether @value{GDBN} will cache target
5639memory. While this generally improves performance by reducing debug
5640protocol overhead, it can lead to incorrect results because @value{GDBN}
5641does not know about volatile variables or memory mapped device
5642registers.
5643
5644@table @code
5645@item cache
5646Enable @value{GDBN} to cache target memory.
5647@item nocache (default)
5648Disable @value{GDBN} from caching target memory.
5649@end table
5650
5651@c @subsubsection Memory Write Verification
5652@c The memory write verification attributes set whether @value{GDBN}
5653@c will re-reads data after each write to verify the write was successful.
5654@c
5655@c @table @code
5656@c @item verify
5657@c @item noverify (default)
5658@c @end table
5659
b37052ae
EZ
5660@node Tracepoints
5661@chapter Tracepoints
5662@c This chapter is based on the documentation written by Michael
5663@c Snyder, David Taylor, Jim Blandy, and Elena Zannoni.
5664
5665@cindex tracepoints
5666In some applications, it is not feasible for the debugger to interrupt
5667the program's execution long enough for the developer to learn
5668anything helpful about its behavior. If the program's correctness
5669depends on its real-time behavior, delays introduced by a debugger
5670might cause the program to change its behavior drastically, or perhaps
5671fail, even when the code itself is correct. It is useful to be able
5672to observe the program's behavior without interrupting it.
5673
5674Using @value{GDBN}'s @code{trace} and @code{collect} commands, you can
5675specify locations in the program, called @dfn{tracepoints}, and
5676arbitrary expressions to evaluate when those tracepoints are reached.
5677Later, using the @code{tfind} command, you can examine the values
5678those expressions had when the program hit the tracepoints. The
5679expressions may also denote objects in memory---structures or arrays,
5680for example---whose values @value{GDBN} should record; while visiting
5681a particular tracepoint, you may inspect those objects as if they were
5682in memory at that moment. However, because @value{GDBN} records these
5683values without interacting with you, it can do so quickly and
5684unobtrusively, hopefully not disturbing the program's behavior.
5685
5686The tracepoint facility is currently available only for remote
5687targets. @xref{Targets}.
5688
5689This chapter describes the tracepoint commands and features.
5690
5691@menu
5692* Set Tracepoints::
5693* Analyze Collected Data::
5694* Tracepoint Variables::
5695@end menu
5696
5697@node Set Tracepoints
5698@section Commands to Set Tracepoints
5699
5700Before running such a @dfn{trace experiment}, an arbitrary number of
5701tracepoints can be set. Like a breakpoint (@pxref{Set Breaks}), a
5702tracepoint has a number assigned to it by @value{GDBN}. Like with
5703breakpoints, tracepoint numbers are successive integers starting from
5704one. Many of the commands associated with tracepoints take the
5705tracepoint number as their argument, to identify which tracepoint to
5706work on.
5707
5708For each tracepoint, you can specify, in advance, some arbitrary set
5709of data that you want the target to collect in the trace buffer when
5710it hits that tracepoint. The collected data can include registers,
5711local variables, or global data. Later, you can use @value{GDBN}
5712commands to examine the values these data had at the time the
5713tracepoint was hit.
5714
5715This section describes commands to set tracepoints and associated
5716conditions and actions.
5717
5718@menu
5719* Create and Delete Tracepoints::
5720* Enable and Disable Tracepoints::
5721* Tracepoint Passcounts::
5722* Tracepoint Actions::
5723* Listing Tracepoints::
5724* Starting and Stopping Trace Experiment::
5725@end menu
5726
5727@node Create and Delete Tracepoints
5728@subsection Create and Delete Tracepoints
5729
5730@table @code
5731@cindex set tracepoint
5732@kindex trace
5733@item trace
5734The @code{trace} command is very similar to the @code{break} command.
5735Its argument can be a source line, a function name, or an address in
5736the target program. @xref{Set Breaks}. The @code{trace} command
5737defines a tracepoint, which is a point in the target program where the
5738debugger will briefly stop, collect some data, and then allow the
5739program to continue. Setting a tracepoint or changing its commands
5740doesn't take effect until the next @code{tstart} command; thus, you
5741cannot change the tracepoint attributes once a trace experiment is
5742running.
5743
5744Here are some examples of using the @code{trace} command:
5745
5746@smallexample
5747(@value{GDBP}) @b{trace foo.c:121} // a source file and line number
5748
5749(@value{GDBP}) @b{trace +2} // 2 lines forward
5750
5751(@value{GDBP}) @b{trace my_function} // first source line of function
5752
5753(@value{GDBP}) @b{trace *my_function} // EXACT start address of function
5754
5755(@value{GDBP}) @b{trace *0x2117c4} // an address
5756@end smallexample
5757
5758@noindent
5759You can abbreviate @code{trace} as @code{tr}.
5760
5761@vindex $tpnum
5762@cindex last tracepoint number
5763@cindex recent tracepoint number
5764@cindex tracepoint number
5765The convenience variable @code{$tpnum} records the tracepoint number
5766of the most recently set tracepoint.
5767
5768@kindex delete tracepoint
5769@cindex tracepoint deletion
5770@item delete tracepoint @r{[}@var{num}@r{]}
5771Permanently delete one or more tracepoints. With no argument, the
5772default is to delete all tracepoints.
5773
5774Examples:
5775
5776@smallexample
5777(@value{GDBP}) @b{delete trace 1 2 3} // remove three tracepoints
5778
5779(@value{GDBP}) @b{delete trace} // remove all tracepoints
5780@end smallexample
5781
5782@noindent
5783You can abbreviate this command as @code{del tr}.
5784@end table
5785
5786@node Enable and Disable Tracepoints
5787@subsection Enable and Disable Tracepoints
5788
5789@table @code
5790@kindex disable tracepoint
5791@item disable tracepoint @r{[}@var{num}@r{]}
5792Disable tracepoint @var{num}, or all tracepoints if no argument
5793@var{num} is given. A disabled tracepoint will have no effect during
5794the next trace experiment, but it is not forgotten. You can re-enable
5795a disabled tracepoint using the @code{enable tracepoint} command.
5796
5797@kindex enable tracepoint
5798@item enable tracepoint @r{[}@var{num}@r{]}
5799Enable tracepoint @var{num}, or all tracepoints. The enabled
5800tracepoints will become effective the next time a trace experiment is
5801run.
5802@end table
5803
5804@node Tracepoint Passcounts
5805@subsection Tracepoint Passcounts
5806
5807@table @code
5808@kindex passcount
5809@cindex tracepoint pass count
5810@item passcount @r{[}@var{n} @r{[}@var{num}@r{]]}
5811Set the @dfn{passcount} of a tracepoint. The passcount is a way to
5812automatically stop a trace experiment. If a tracepoint's passcount is
5813@var{n}, then the trace experiment will be automatically stopped on
5814the @var{n}'th time that tracepoint is hit. If the tracepoint number
5815@var{num} is not specified, the @code{passcount} command sets the
5816passcount of the most recently defined tracepoint. If no passcount is
5817given, the trace experiment will run until stopped explicitly by the
5818user.
5819
5820Examples:
5821
5822@smallexample
5823(@value{GDBP}) @b{passcount 5 2} // Stop on the 5th execution of tracepoint 2
5824
5825(@value{GDBP}) @b{passcount 12} // Stop on the 12th execution of the
5826 // most recently defined tracepoint.
5827(@value{GDBP}) @b{trace foo}
5828(@value{GDBP}) @b{pass 3}
5829(@value{GDBP}) @b{trace bar}
5830(@value{GDBP}) @b{pass 2}
5831(@value{GDBP}) @b{trace baz}
5832(@value{GDBP}) @b{pass 1} // Stop tracing when foo has been
5833 // executed 3 times OR when bar has
5834 // been executed 2 times
5835 // OR when baz has been executed 1 time.
5836@end smallexample
5837@end table
5838
5839@node Tracepoint Actions
5840@subsection Tracepoint Action Lists
5841
5842@table @code
5843@kindex actions
5844@cindex tracepoint actions
5845@item actions @r{[}@var{num}@r{]}
5846This command will prompt for a list of actions to be taken when the
5847tracepoint is hit. If the tracepoint number @var{num} is not
5848specified, this command sets the actions for the one that was most
5849recently defined (so that you can define a tracepoint and then say
5850@code{actions} without bothering about its number). You specify the
5851actions themselves on the following lines, one action at a time, and
5852terminate the actions list with a line containing just @code{end}. So
5853far, the only defined actions are @code{collect} and
5854@code{while-stepping}.
5855
5856@cindex remove actions from a tracepoint
5857To remove all actions from a tracepoint, type @samp{actions @var{num}}
5858and follow it immediately with @samp{end}.
5859
5860@smallexample
5861(@value{GDBP}) @b{collect @var{data}} // collect some data
5862
5863(@value{GDBP}) @b{while-stepping 5} // single-step 5 times and collect data
5864
5865(@value{GDBP}) @b{end} // signals the end of actions.
5866@end smallexample
5867
5868In the following example, the action list begins with @code{collect}
5869commands indicating the things to be collected when the tracepoint is
5870hit. Then, in order to single-step and collect additional data
5871following the tracepoint, a @code{while-stepping} command is used,
5872followed by the list of things to be collected while stepping. The
5873@code{while-stepping} command is terminated by its own separate
5874@code{end} command. Lastly, the action list is terminated by an
5875@code{end} command.
5876
5877@smallexample
5878(@value{GDBP}) @b{trace foo}
5879(@value{GDBP}) @b{actions}
5880Enter actions for tracepoint 1, one per line:
5881> collect bar,baz
5882> collect $regs
5883> while-stepping 12
5884 > collect $fp, $sp
5885 > end
5886end
5887@end smallexample
5888
5889@kindex collect @r{(tracepoints)}
5890@item collect @var{expr1}, @var{expr2}, @dots{}
5891Collect values of the given expressions when the tracepoint is hit.
5892This command accepts a comma-separated list of any valid expressions.
5893In addition to global, static, or local variables, the following
5894special arguments are supported:
5895
5896@table @code
5897@item $regs
5898collect all registers
5899
5900@item $args
5901collect all function arguments
5902
5903@item $locals
5904collect all local variables.
5905@end table
5906
5907You can give several consecutive @code{collect} commands, each one
5908with a single argument, or one @code{collect} command with several
5909arguments separated by commas: the effect is the same.
5910
f5c37c66
EZ
5911The command @code{info scope} (@pxref{Symbols, info scope}) is
5912particularly useful for figuring out what data to collect.
5913
b37052ae
EZ
5914@kindex while-stepping @r{(tracepoints)}
5915@item while-stepping @var{n}
5916Perform @var{n} single-step traces after the tracepoint, collecting
5917new data at each step. The @code{while-stepping} command is
5918followed by the list of what to collect while stepping (followed by
5919its own @code{end} command):
5920
5921@smallexample
5922> while-stepping 12
5923 > collect $regs, myglobal
5924 > end
5925>
5926@end smallexample
5927
5928@noindent
5929You may abbreviate @code{while-stepping} as @code{ws} or
5930@code{stepping}.
5931@end table
5932
5933@node Listing Tracepoints
5934@subsection Listing Tracepoints
5935
5936@table @code
5937@kindex info tracepoints
5938@cindex information about tracepoints
5939@item info tracepoints @r{[}@var{num}@r{]}
5940Display information the tracepoint @var{num}. If you don't specify a
5941tracepoint number displays information about all the tracepoints
5942defined so far. For each tracepoint, the following information is
5943shown:
5944
5945@itemize @bullet
5946@item
5947its number
5948@item
5949whether it is enabled or disabled
5950@item
5951its address
5952@item
5953its passcount as given by the @code{passcount @var{n}} command
5954@item
5955its step count as given by the @code{while-stepping @var{n}} command
5956@item
5957where in the source files is the tracepoint set
5958@item
5959its action list as given by the @code{actions} command
5960@end itemize
5961
5962@smallexample
5963(@value{GDBP}) @b{info trace}
5964Num Enb Address PassC StepC What
59651 y 0x002117c4 0 0 <gdb_asm>
59662 y 0x0020dc64 0 0 in gdb_test at gdb_test.c:375
59673 y 0x0020b1f4 0 0 in collect_data at ../foo.c:1741
5968(@value{GDBP})
5969@end smallexample
5970
5971@noindent
5972This command can be abbreviated @code{info tp}.
5973@end table
5974
5975@node Starting and Stopping Trace Experiment
5976@subsection Starting and Stopping Trace Experiment
5977
5978@table @code
5979@kindex tstart
5980@cindex start a new trace experiment
5981@cindex collected data discarded
5982@item tstart
5983This command takes no arguments. It starts the trace experiment, and
5984begins collecting data. This has the side effect of discarding all
5985the data collected in the trace buffer during the previous trace
5986experiment.
5987
5988@kindex tstop
5989@cindex stop a running trace experiment
5990@item tstop
5991This command takes no arguments. It ends the trace experiment, and
5992stops collecting data.
5993
5994@strong{Note:} a trace experiment and data collection may stop
5995automatically if any tracepoint's passcount is reached
5996(@pxref{Tracepoint Passcounts}), or if the trace buffer becomes full.
5997
5998@kindex tstatus
5999@cindex status of trace data collection
6000@cindex trace experiment, status of
6001@item tstatus
6002This command displays the status of the current trace data
6003collection.
6004@end table
6005
6006Here is an example of the commands we described so far:
6007
6008@smallexample
6009(@value{GDBP}) @b{trace gdb_c_test}
6010(@value{GDBP}) @b{actions}
6011Enter actions for tracepoint #1, one per line.
6012> collect $regs,$locals,$args
6013> while-stepping 11
6014 > collect $regs
6015 > end
6016> end
6017(@value{GDBP}) @b{tstart}
6018 [time passes @dots{}]
6019(@value{GDBP}) @b{tstop}
6020@end smallexample
6021
6022
6023@node Analyze Collected Data
6024@section Using the collected data
6025
6026After the tracepoint experiment ends, you use @value{GDBN} commands
6027for examining the trace data. The basic idea is that each tracepoint
6028collects a trace @dfn{snapshot} every time it is hit and another
6029snapshot every time it single-steps. All these snapshots are
6030consecutively numbered from zero and go into a buffer, and you can
6031examine them later. The way you examine them is to @dfn{focus} on a
6032specific trace snapshot. When the remote stub is focused on a trace
6033snapshot, it will respond to all @value{GDBN} requests for memory and
6034registers by reading from the buffer which belongs to that snapshot,
6035rather than from @emph{real} memory or registers of the program being
6036debugged. This means that @strong{all} @value{GDBN} commands
6037(@code{print}, @code{info registers}, @code{backtrace}, etc.) will
6038behave as if we were currently debugging the program state as it was
6039when the tracepoint occurred. Any requests for data that are not in
6040the buffer will fail.
6041
6042@menu
6043* tfind:: How to select a trace snapshot
6044* tdump:: How to display all data for a snapshot
6045* save-tracepoints:: How to save tracepoints for a future run
6046@end menu
6047
6048@node tfind
6049@subsection @code{tfind @var{n}}
6050
6051@kindex tfind
6052@cindex select trace snapshot
6053@cindex find trace snapshot
6054The basic command for selecting a trace snapshot from the buffer is
6055@code{tfind @var{n}}, which finds trace snapshot number @var{n},
6056counting from zero. If no argument @var{n} is given, the next
6057snapshot is selected.
6058
6059Here are the various forms of using the @code{tfind} command.
6060
6061@table @code
6062@item tfind start
6063Find the first snapshot in the buffer. This is a synonym for
6064@code{tfind 0} (since 0 is the number of the first snapshot).
6065
6066@item tfind none
6067Stop debugging trace snapshots, resume @emph{live} debugging.
6068
6069@item tfind end
6070Same as @samp{tfind none}.
6071
6072@item tfind
6073No argument means find the next trace snapshot.
6074
6075@item tfind -
6076Find the previous trace snapshot before the current one. This permits
6077retracing earlier steps.
6078
6079@item tfind tracepoint @var{num}
6080Find the next snapshot associated with tracepoint @var{num}. Search
6081proceeds forward from the last examined trace snapshot. If no
6082argument @var{num} is given, it means find the next snapshot collected
6083for the same tracepoint as the current snapshot.
6084
6085@item tfind pc @var{addr}
6086Find the next snapshot associated with the value @var{addr} of the
6087program counter. Search proceeds forward from the last examined trace
6088snapshot. If no argument @var{addr} is given, it means find the next
6089snapshot with the same value of PC as the current snapshot.
6090
6091@item tfind outside @var{addr1}, @var{addr2}
6092Find the next snapshot whose PC is outside the given range of
6093addresses.
6094
6095@item tfind range @var{addr1}, @var{addr2}
6096Find the next snapshot whose PC is between @var{addr1} and
6097@var{addr2}. @c FIXME: Is the range inclusive or exclusive?
6098
6099@item tfind line @r{[}@var{file}:@r{]}@var{n}
6100Find the next snapshot associated with the source line @var{n}. If
6101the optional argument @var{file} is given, refer to line @var{n} in
6102that source file. Search proceeds forward from the last examined
6103trace snapshot. If no argument @var{n} is given, it means find the
6104next line other than the one currently being examined; thus saying
6105@code{tfind line} repeatedly can appear to have the same effect as
6106stepping from line to line in a @emph{live} debugging session.
6107@end table
6108
6109The default arguments for the @code{tfind} commands are specifically
6110designed to make it easy to scan through the trace buffer. For
6111instance, @code{tfind} with no argument selects the next trace
6112snapshot, and @code{tfind -} with no argument selects the previous
6113trace snapshot. So, by giving one @code{tfind} command, and then
6114simply hitting @key{RET} repeatedly you can examine all the trace
6115snapshots in order. Or, by saying @code{tfind -} and then hitting
6116@key{RET} repeatedly you can examine the snapshots in reverse order.
6117The @code{tfind line} command with no argument selects the snapshot
6118for the next source line executed. The @code{tfind pc} command with
6119no argument selects the next snapshot with the same program counter
6120(PC) as the current frame. The @code{tfind tracepoint} command with
6121no argument selects the next trace snapshot collected by the same
6122tracepoint as the current one.
6123
6124In addition to letting you scan through the trace buffer manually,
6125these commands make it easy to construct @value{GDBN} scripts that
6126scan through the trace buffer and print out whatever collected data
6127you are interested in. Thus, if we want to examine the PC, FP, and SP
6128registers from each trace frame in the buffer, we can say this:
6129
6130@smallexample
6131(@value{GDBP}) @b{tfind start}
6132(@value{GDBP}) @b{while ($trace_frame != -1)}
6133> printf "Frame %d, PC = %08X, SP = %08X, FP = %08X\n", \
6134 $trace_frame, $pc, $sp, $fp
6135> tfind
6136> end
6137
6138Frame 0, PC = 0020DC64, SP = 0030BF3C, FP = 0030BF44
6139Frame 1, PC = 0020DC6C, SP = 0030BF38, FP = 0030BF44
6140Frame 2, PC = 0020DC70, SP = 0030BF34, FP = 0030BF44
6141Frame 3, PC = 0020DC74, SP = 0030BF30, FP = 0030BF44
6142Frame 4, PC = 0020DC78, SP = 0030BF2C, FP = 0030BF44
6143Frame 5, PC = 0020DC7C, SP = 0030BF28, FP = 0030BF44
6144Frame 6, PC = 0020DC80, SP = 0030BF24, FP = 0030BF44
6145Frame 7, PC = 0020DC84, SP = 0030BF20, FP = 0030BF44
6146Frame 8, PC = 0020DC88, SP = 0030BF1C, FP = 0030BF44
6147Frame 9, PC = 0020DC8E, SP = 0030BF18, FP = 0030BF44
6148Frame 10, PC = 00203F6C, SP = 0030BE3C, FP = 0030BF14
6149@end smallexample
6150
6151Or, if we want to examine the variable @code{X} at each source line in
6152the buffer:
6153
6154@smallexample
6155(@value{GDBP}) @b{tfind start}
6156(@value{GDBP}) @b{while ($trace_frame != -1)}
6157> printf "Frame %d, X == %d\n", $trace_frame, X
6158> tfind line
6159> end
6160
6161Frame 0, X = 1
6162Frame 7, X = 2
6163Frame 13, X = 255
6164@end smallexample
6165
6166@node tdump
6167@subsection @code{tdump}
6168@kindex tdump
6169@cindex dump all data collected at tracepoint
6170@cindex tracepoint data, display
6171
6172This command takes no arguments. It prints all the data collected at
6173the current trace snapshot.
6174
6175@smallexample
6176(@value{GDBP}) @b{trace 444}
6177(@value{GDBP}) @b{actions}
6178Enter actions for tracepoint #2, one per line:
6179> collect $regs, $locals, $args, gdb_long_test
6180> end
6181
6182(@value{GDBP}) @b{tstart}
6183
6184(@value{GDBP}) @b{tfind line 444}
6185#0 gdb_test (p1=0x11, p2=0x22, p3=0x33, p4=0x44, p5=0x55, p6=0x66)
6186at gdb_test.c:444
6187444 printp( "%s: arguments = 0x%X 0x%X 0x%X 0x%X 0x%X 0x%X\n", )
6188
6189(@value{GDBP}) @b{tdump}
6190Data collected at tracepoint 2, trace frame 1:
6191d0 0xc4aa0085 -995491707
6192d1 0x18 24
6193d2 0x80 128
6194d3 0x33 51
6195d4 0x71aea3d 119204413
6196d5 0x22 34
6197d6 0xe0 224
6198d7 0x380035 3670069
6199a0 0x19e24a 1696330
6200a1 0x3000668 50333288
6201a2 0x100 256
6202a3 0x322000 3284992
6203a4 0x3000698 50333336
6204a5 0x1ad3cc 1758156
6205fp 0x30bf3c 0x30bf3c
6206sp 0x30bf34 0x30bf34
6207ps 0x0 0
6208pc 0x20b2c8 0x20b2c8
6209fpcontrol 0x0 0
6210fpstatus 0x0 0
6211fpiaddr 0x0 0
6212p = 0x20e5b4 "gdb-test"
6213p1 = (void *) 0x11
6214p2 = (void *) 0x22
6215p3 = (void *) 0x33
6216p4 = (void *) 0x44
6217p5 = (void *) 0x55
6218p6 = (void *) 0x66
6219gdb_long_test = 17 '\021'
6220
6221(@value{GDBP})
6222@end smallexample
6223
6224@node save-tracepoints
6225@subsection @code{save-tracepoints @var{filename}}
6226@kindex save-tracepoints
6227@cindex save tracepoints for future sessions
6228
6229This command saves all current tracepoint definitions together with
6230their actions and passcounts, into a file @file{@var{filename}}
6231suitable for use in a later debugging session. To read the saved
6232tracepoint definitions, use the @code{source} command (@pxref{Command
6233Files}).
6234
6235@node Tracepoint Variables
6236@section Convenience Variables for Tracepoints
6237@cindex tracepoint variables
6238@cindex convenience variables for tracepoints
6239
6240@table @code
6241@vindex $trace_frame
6242@item (int) $trace_frame
6243The current trace snapshot (a.k.a.@: @dfn{frame}) number, or -1 if no
6244snapshot is selected.
6245
6246@vindex $tracepoint
6247@item (int) $tracepoint
6248The tracepoint for the current trace snapshot.
6249
6250@vindex $trace_line
6251@item (int) $trace_line
6252The line number for the current trace snapshot.
6253
6254@vindex $trace_file
6255@item (char []) $trace_file
6256The source file for the current trace snapshot.
6257
6258@vindex $trace_func
6259@item (char []) $trace_func
6260The name of the function containing @code{$tracepoint}.
6261@end table
6262
6263Note: @code{$trace_file} is not suitable for use in @code{printf},
6264use @code{output} instead.
6265
6266Here's a simple example of using these convenience variables for
6267stepping through all the trace snapshots and printing some of their
6268data.
6269
6270@smallexample
6271(@value{GDBP}) @b{tfind start}
6272
6273(@value{GDBP}) @b{while $trace_frame != -1}
6274> output $trace_file
6275> printf ", line %d (tracepoint #%d)\n", $trace_line, $tracepoint
6276> tfind
6277> end
6278@end smallexample
6279
6d2ebf8b 6280@node Languages
c906108c
SS
6281@chapter Using @value{GDBN} with Different Languages
6282@cindex languages
6283
c906108c
SS
6284Although programming languages generally have common aspects, they are
6285rarely expressed in the same manner. For instance, in ANSI C,
6286dereferencing a pointer @code{p} is accomplished by @code{*p}, but in
6287Modula-2, it is accomplished by @code{p^}. Values can also be
5d161b24 6288represented (and displayed) differently. Hex numbers in C appear as
c906108c 6289@samp{0x1ae}, while in Modula-2 they appear as @samp{1AEH}.
c906108c
SS
6290
6291@cindex working language
6292Language-specific information is built into @value{GDBN} for some languages,
6293allowing you to express operations like the above in your program's
6294native language, and allowing @value{GDBN} to output values in a manner
6295consistent with the syntax of your program's native language. The
6296language you use to build expressions is called the @dfn{working
6297language}.
6298
6299@menu
6300* Setting:: Switching between source languages
6301* Show:: Displaying the language
c906108c 6302* Checks:: Type and range checks
c906108c
SS
6303* Support:: Supported languages
6304@end menu
6305
6d2ebf8b 6306@node Setting
c906108c
SS
6307@section Switching between source languages
6308
6309There are two ways to control the working language---either have @value{GDBN}
6310set it automatically, or select it manually yourself. You can use the
6311@code{set language} command for either purpose. On startup, @value{GDBN}
6312defaults to setting the language automatically. The working language is
6313used to determine how expressions you type are interpreted, how values
6314are printed, etc.
6315
6316In addition to the working language, every source file that
6317@value{GDBN} knows about has its own working language. For some object
6318file formats, the compiler might indicate which language a particular
6319source file is in. However, most of the time @value{GDBN} infers the
6320language from the name of the file. The language of a source file
b37052ae 6321controls whether C@t{++} names are demangled---this way @code{backtrace} can
c906108c 6322show each frame appropriately for its own language. There is no way to
d4f3574e
SS
6323set the language of a source file from within @value{GDBN}, but you can
6324set the language associated with a filename extension. @xref{Show, ,
6325Displaying the language}.
c906108c
SS
6326
6327This is most commonly a problem when you use a program, such
5d161b24 6328as @code{cfront} or @code{f2c}, that generates C but is written in
c906108c
SS
6329another language. In that case, make the
6330program use @code{#line} directives in its C output; that way
6331@value{GDBN} will know the correct language of the source code of the original
6332program, and will display that source code, not the generated C code.
6333
6334@menu
6335* Filenames:: Filename extensions and languages.
6336* Manually:: Setting the working language manually
6337* Automatically:: Having @value{GDBN} infer the source language
6338@end menu
6339
6d2ebf8b 6340@node Filenames
c906108c
SS
6341@subsection List of filename extensions and languages
6342
6343If a source file name ends in one of the following extensions, then
6344@value{GDBN} infers that its language is the one indicated.
6345
6346@table @file
6347
6348@item .c
6349C source file
6350
6351@item .C
6352@itemx .cc
6353@itemx .cp
6354@itemx .cpp
6355@itemx .cxx
6356@itemx .c++
b37052ae 6357C@t{++} source file
c906108c
SS
6358
6359@item .f
6360@itemx .F
6361Fortran source file
6362
c906108c
SS
6363@item .ch
6364@itemx .c186
6365@itemx .c286
96a2c332 6366CHILL source file
c906108c 6367
c906108c
SS
6368@item .mod
6369Modula-2 source file
c906108c
SS
6370
6371@item .s
6372@itemx .S
6373Assembler source file. This actually behaves almost like C, but
6374@value{GDBN} does not skip over function prologues when stepping.
6375@end table
6376
6377In addition, you may set the language associated with a filename
6378extension. @xref{Show, , Displaying the language}.
6379
6d2ebf8b 6380@node Manually
c906108c
SS
6381@subsection Setting the working language
6382
6383If you allow @value{GDBN} to set the language automatically,
6384expressions are interpreted the same way in your debugging session and
6385your program.
6386
6387@kindex set language
6388If you wish, you may set the language manually. To do this, issue the
6389command @samp{set language @var{lang}}, where @var{lang} is the name of
5d161b24 6390a language, such as
c906108c 6391@code{c} or @code{modula-2}.
c906108c
SS
6392For a list of the supported languages, type @samp{set language}.
6393
c906108c
SS
6394Setting the language manually prevents @value{GDBN} from updating the working
6395language automatically. This can lead to confusion if you try
6396to debug a program when the working language is not the same as the
6397source language, when an expression is acceptable to both
6398languages---but means different things. For instance, if the current
6399source file were written in C, and @value{GDBN} was parsing Modula-2, a
6400command such as:
6401
6402@example
6403print a = b + c
6404@end example
6405
6406@noindent
6407might not have the effect you intended. In C, this means to add
6408@code{b} and @code{c} and place the result in @code{a}. The result
6409printed would be the value of @code{a}. In Modula-2, this means to compare
6410@code{a} to the result of @code{b+c}, yielding a @code{BOOLEAN} value.
c906108c 6411
6d2ebf8b 6412@node Automatically
c906108c
SS
6413@subsection Having @value{GDBN} infer the source language
6414
6415To have @value{GDBN} set the working language automatically, use
6416@samp{set language local} or @samp{set language auto}. @value{GDBN}
6417then infers the working language. That is, when your program stops in a
6418frame (usually by encountering a breakpoint), @value{GDBN} sets the
6419working language to the language recorded for the function in that
6420frame. If the language for a frame is unknown (that is, if the function
6421or block corresponding to the frame was defined in a source file that
6422does not have a recognized extension), the current working language is
6423not changed, and @value{GDBN} issues a warning.
6424
6425This may not seem necessary for most programs, which are written
6426entirely in one source language. However, program modules and libraries
6427written in one source language can be used by a main program written in
6428a different source language. Using @samp{set language auto} in this
6429case frees you from having to set the working language manually.
6430
6d2ebf8b 6431@node Show
c906108c 6432@section Displaying the language
c906108c
SS
6433
6434The following commands help you find out which language is the
6435working language, and also what language source files were written in.
6436
6437@kindex show language
d4f3574e
SS
6438@kindex info frame@r{, show the source language}
6439@kindex info source@r{, show the source language}
c906108c
SS
6440@table @code
6441@item show language
6442Display the current working language. This is the
6443language you can use with commands such as @code{print} to
6444build and compute expressions that may involve variables in your program.
6445
6446@item info frame
5d161b24 6447Display the source language for this frame. This language becomes the
c906108c 6448working language if you use an identifier from this frame.
5d161b24 6449@xref{Frame Info, ,Information about a frame}, to identify the other
c906108c
SS
6450information listed here.
6451
6452@item info source
6453Display the source language of this source file.
5d161b24 6454@xref{Symbols, ,Examining the Symbol Table}, to identify the other
c906108c
SS
6455information listed here.
6456@end table
6457
6458In unusual circumstances, you may have source files with extensions
6459not in the standard list. You can then set the extension associated
6460with a language explicitly:
6461
6462@kindex set extension-language
6463@kindex info extensions
6464@table @code
6465@item set extension-language @var{.ext} @var{language}
6466Set source files with extension @var{.ext} to be assumed to be in
6467the source language @var{language}.
6468
6469@item info extensions
6470List all the filename extensions and the associated languages.
6471@end table
6472
6d2ebf8b 6473@node Checks
c906108c
SS
6474@section Type and range checking
6475
6476@quotation
6477@emph{Warning:} In this release, the @value{GDBN} commands for type and range
6478checking are included, but they do not yet have any effect. This
6479section documents the intended facilities.
6480@end quotation
6481@c FIXME remove warning when type/range code added
6482
6483Some languages are designed to guard you against making seemingly common
6484errors through a series of compile- and run-time checks. These include
6485checking the type of arguments to functions and operators, and making
6486sure mathematical overflows are caught at run time. Checks such as
6487these help to ensure a program's correctness once it has been compiled
6488by eliminating type mismatches, and providing active checks for range
6489errors when your program is running.
6490
6491@value{GDBN} can check for conditions like the above if you wish.
6492Although @value{GDBN} does not check the statements in your program, it
6493can check expressions entered directly into @value{GDBN} for evaluation via
6494the @code{print} command, for example. As with the working language,
6495@value{GDBN} can also decide whether or not to check automatically based on
6496your program's source language. @xref{Support, ,Supported languages},
6497for the default settings of supported languages.
6498
6499@menu
6500* Type Checking:: An overview of type checking
6501* Range Checking:: An overview of range checking
6502@end menu
6503
6504@cindex type checking
6505@cindex checks, type
6d2ebf8b 6506@node Type Checking
c906108c
SS
6507@subsection An overview of type checking
6508
6509Some languages, such as Modula-2, are strongly typed, meaning that the
6510arguments to operators and functions have to be of the correct type,
6511otherwise an error occurs. These checks prevent type mismatch
6512errors from ever causing any run-time problems. For example,
6513
6514@smallexample
65151 + 2 @result{} 3
6516@exdent but
6517@error{} 1 + 2.3
6518@end smallexample
6519
6520The second example fails because the @code{CARDINAL} 1 is not
6521type-compatible with the @code{REAL} 2.3.
6522
5d161b24
DB
6523For the expressions you use in @value{GDBN} commands, you can tell the
6524@value{GDBN} type checker to skip checking;
6525to treat any mismatches as errors and abandon the expression;
6526or to only issue warnings when type mismatches occur,
c906108c
SS
6527but evaluate the expression anyway. When you choose the last of
6528these, @value{GDBN} evaluates expressions like the second example above, but
6529also issues a warning.
6530
5d161b24
DB
6531Even if you turn type checking off, there may be other reasons
6532related to type that prevent @value{GDBN} from evaluating an expression.
6533For instance, @value{GDBN} does not know how to add an @code{int} and
6534a @code{struct foo}. These particular type errors have nothing to do
6535with the language in use, and usually arise from expressions, such as
c906108c
SS
6536the one described above, which make little sense to evaluate anyway.
6537
6538Each language defines to what degree it is strict about type. For
6539instance, both Modula-2 and C require the arguments to arithmetical
6540operators to be numbers. In C, enumerated types and pointers can be
6541represented as numbers, so that they are valid arguments to mathematical
6542operators. @xref{Support, ,Supported languages}, for further
6543details on specific languages.
6544
6545@value{GDBN} provides some additional commands for controlling the type checker:
6546
d4f3574e 6547@kindex set check@r{, type}
c906108c
SS
6548@kindex set check type
6549@kindex show check type
6550@table @code
6551@item set check type auto
6552Set type checking on or off based on the current working language.
6553@xref{Support, ,Supported languages}, for the default settings for
6554each language.
6555
6556@item set check type on
6557@itemx set check type off
6558Set type checking on or off, overriding the default setting for the
6559current working language. Issue a warning if the setting does not
6560match the language default. If any type mismatches occur in
d4f3574e 6561evaluating an expression while type checking is on, @value{GDBN} prints a
c906108c
SS
6562message and aborts evaluation of the expression.
6563
6564@item set check type warn
6565Cause the type checker to issue warnings, but to always attempt to
6566evaluate the expression. Evaluating the expression may still
6567be impossible for other reasons. For example, @value{GDBN} cannot add
6568numbers and structures.
6569
6570@item show type
5d161b24 6571Show the current setting of the type checker, and whether or not @value{GDBN}
c906108c
SS
6572is setting it automatically.
6573@end table
6574
6575@cindex range checking
6576@cindex checks, range
6d2ebf8b 6577@node Range Checking
c906108c
SS
6578@subsection An overview of range checking
6579
6580In some languages (such as Modula-2), it is an error to exceed the
6581bounds of a type; this is enforced with run-time checks. Such range
6582checking is meant to ensure program correctness by making sure
6583computations do not overflow, or indices on an array element access do
6584not exceed the bounds of the array.
6585
6586For expressions you use in @value{GDBN} commands, you can tell
6587@value{GDBN} to treat range errors in one of three ways: ignore them,
6588always treat them as errors and abandon the expression, or issue
6589warnings but evaluate the expression anyway.
6590
6591A range error can result from numerical overflow, from exceeding an
6592array index bound, or when you type a constant that is not a member
6593of any type. Some languages, however, do not treat overflows as an
6594error. In many implementations of C, mathematical overflow causes the
6595result to ``wrap around'' to lower values---for example, if @var{m} is
6596the largest integer value, and @var{s} is the smallest, then
6597
6598@example
6599@var{m} + 1 @result{} @var{s}
6600@end example
6601
6602This, too, is specific to individual languages, and in some cases
6603specific to individual compilers or machines. @xref{Support, ,
6604Supported languages}, for further details on specific languages.
6605
6606@value{GDBN} provides some additional commands for controlling the range checker:
6607
d4f3574e 6608@kindex set check@r{, range}
c906108c
SS
6609@kindex set check range
6610@kindex show check range
6611@table @code
6612@item set check range auto
6613Set range checking on or off based on the current working language.
6614@xref{Support, ,Supported languages}, for the default settings for
6615each language.
6616
6617@item set check range on
6618@itemx set check range off
6619Set range checking on or off, overriding the default setting for the
6620current working language. A warning is issued if the setting does not
c3f6f71d
JM
6621match the language default. If a range error occurs and range checking is on,
6622then a message is printed and evaluation of the expression is aborted.
c906108c
SS
6623
6624@item set check range warn
6625Output messages when the @value{GDBN} range checker detects a range error,
6626but attempt to evaluate the expression anyway. Evaluating the
6627expression may still be impossible for other reasons, such as accessing
6628memory that the process does not own (a typical example from many Unix
6629systems).
6630
6631@item show range
6632Show the current setting of the range checker, and whether or not it is
6633being set automatically by @value{GDBN}.
6634@end table
c906108c 6635
6d2ebf8b 6636@node Support
c906108c 6637@section Supported languages
c906108c 6638
b37052ae 6639@value{GDBN} supports C, C@t{++}, Fortran, Java, Chill, assembly, and Modula-2.
cce74817 6640@c This is false ...
c906108c
SS
6641Some @value{GDBN} features may be used in expressions regardless of the
6642language you use: the @value{GDBN} @code{@@} and @code{::} operators,
6643and the @samp{@{type@}addr} construct (@pxref{Expressions,
6644,Expressions}) can be used with the constructs of any supported
6645language.
6646
6647The following sections detail to what degree each source language is
6648supported by @value{GDBN}. These sections are not meant to be language
6649tutorials or references, but serve only as a reference guide to what the
6650@value{GDBN} expression parser accepts, and what input and output
6651formats should look like for different languages. There are many good
6652books written on each of these languages; please look to these for a
6653language reference or tutorial.
6654
c906108c 6655@menu
b37052ae 6656* C:: C and C@t{++}
cce74817 6657* Modula-2:: Modula-2
104c1213 6658* Chill:: Chill
c906108c
SS
6659@end menu
6660
6d2ebf8b 6661@node C
b37052ae 6662@subsection C and C@t{++}
7a292a7a 6663
b37052ae
EZ
6664@cindex C and C@t{++}
6665@cindex expressions in C or C@t{++}
c906108c 6666
b37052ae 6667Since C and C@t{++} are so closely related, many features of @value{GDBN} apply
c906108c
SS
6668to both languages. Whenever this is the case, we discuss those languages
6669together.
6670
41afff9a
EZ
6671@cindex C@t{++}
6672@cindex @code{g++}, @sc{gnu} C@t{++} compiler
b37052ae
EZ
6673@cindex @sc{gnu} C@t{++}
6674The C@t{++} debugging facilities are jointly implemented by the C@t{++}
6675compiler and @value{GDBN}. Therefore, to debug your C@t{++} code
6676effectively, you must compile your C@t{++} programs with a supported
6677C@t{++} compiler, such as @sc{gnu} @code{g++}, or the HP ANSI C@t{++}
c906108c
SS
6678compiler (@code{aCC}).
6679
b37052ae 6680For best results when using @sc{gnu} C@t{++}, use the stabs debugging
c906108c
SS
6681format. You can select that format explicitly with the @code{g++}
6682command-line options @samp{-gstabs} or @samp{-gstabs+}. See
6683@ref{Debugging Options,,Options for Debugging Your Program or @sc{gnu}
6684CC, gcc.info, Using @sc{gnu} CC}, for more information.
c906108c 6685
c906108c 6686@menu
b37052ae
EZ
6687* C Operators:: C and C@t{++} operators
6688* C Constants:: C and C@t{++} constants
6689* C plus plus expressions:: C@t{++} expressions
6690* C Defaults:: Default settings for C and C@t{++}
6691* C Checks:: C and C@t{++} type and range checks
c906108c 6692* Debugging C:: @value{GDBN} and C
b37052ae 6693* Debugging C plus plus:: @value{GDBN} features for C@t{++}
c906108c 6694@end menu
c906108c 6695
6d2ebf8b 6696@node C Operators
b37052ae 6697@subsubsection C and C@t{++} operators
7a292a7a 6698
b37052ae 6699@cindex C and C@t{++} operators
c906108c
SS
6700
6701Operators must be defined on values of specific types. For instance,
6702@code{+} is defined on numbers, but not on structures. Operators are
5d161b24 6703often defined on groups of types.
c906108c 6704
b37052ae 6705For the purposes of C and C@t{++}, the following definitions hold:
c906108c
SS
6706
6707@itemize @bullet
53a5351d 6708
c906108c 6709@item
c906108c 6710@emph{Integral types} include @code{int} with any of its storage-class
b37052ae 6711specifiers; @code{char}; @code{enum}; and, for C@t{++}, @code{bool}.
c906108c
SS
6712
6713@item
d4f3574e
SS
6714@emph{Floating-point types} include @code{float}, @code{double}, and
6715@code{long double} (if supported by the target platform).
c906108c
SS
6716
6717@item
53a5351d 6718@emph{Pointer types} include all types defined as @code{(@var{type} *)}.
c906108c
SS
6719
6720@item
6721@emph{Scalar types} include all of the above.
53a5351d 6722
c906108c
SS
6723@end itemize
6724
6725@noindent
6726The following operators are supported. They are listed here
6727in order of increasing precedence:
6728
6729@table @code
6730@item ,
6731The comma or sequencing operator. Expressions in a comma-separated list
6732are evaluated from left to right, with the result of the entire
6733expression being the last expression evaluated.
6734
6735@item =
6736Assignment. The value of an assignment expression is the value
6737assigned. Defined on scalar types.
6738
6739@item @var{op}=
6740Used in an expression of the form @w{@code{@var{a} @var{op}= @var{b}}},
6741and translated to @w{@code{@var{a} = @var{a op b}}}.
d4f3574e 6742@w{@code{@var{op}=}} and @code{=} have the same precedence.
c906108c
SS
6743@var{op} is any one of the operators @code{|}, @code{^}, @code{&},
6744@code{<<}, @code{>>}, @code{+}, @code{-}, @code{*}, @code{/}, @code{%}.
6745
6746@item ?:
6747The ternary operator. @code{@var{a} ? @var{b} : @var{c}} can be thought
6748of as: if @var{a} then @var{b} else @var{c}. @var{a} should be of an
6749integral type.
6750
6751@item ||
6752Logical @sc{or}. Defined on integral types.
6753
6754@item &&
6755Logical @sc{and}. Defined on integral types.
6756
6757@item |
6758Bitwise @sc{or}. Defined on integral types.
6759
6760@item ^
6761Bitwise exclusive-@sc{or}. Defined on integral types.
6762
6763@item &
6764Bitwise @sc{and}. Defined on integral types.
6765
6766@item ==@r{, }!=
6767Equality and inequality. Defined on scalar types. The value of these
6768expressions is 0 for false and non-zero for true.
6769
6770@item <@r{, }>@r{, }<=@r{, }>=
6771Less than, greater than, less than or equal, greater than or equal.
6772Defined on scalar types. The value of these expressions is 0 for false
6773and non-zero for true.
6774
6775@item <<@r{, }>>
6776left shift, and right shift. Defined on integral types.
6777
6778@item @@
6779The @value{GDBN} ``artificial array'' operator (@pxref{Expressions, ,Expressions}).
6780
6781@item +@r{, }-
6782Addition and subtraction. Defined on integral types, floating-point types and
6783pointer types.
6784
6785@item *@r{, }/@r{, }%
6786Multiplication, division, and modulus. Multiplication and division are
6787defined on integral and floating-point types. Modulus is defined on
6788integral types.
6789
6790@item ++@r{, }--
6791Increment and decrement. When appearing before a variable, the
6792operation is performed before the variable is used in an expression;
6793when appearing after it, the variable's value is used before the
6794operation takes place.
6795
6796@item *
6797Pointer dereferencing. Defined on pointer types. Same precedence as
6798@code{++}.
6799
6800@item &
6801Address operator. Defined on variables. Same precedence as @code{++}.
6802
b37052ae
EZ
6803For debugging C@t{++}, @value{GDBN} implements a use of @samp{&} beyond what is
6804allowed in the C@t{++} language itself: you can use @samp{&(&@var{ref})}
c906108c 6805(or, if you prefer, simply @samp{&&@var{ref}}) to examine the address
b37052ae 6806where a C@t{++} reference variable (declared with @samp{&@var{ref}}) is
c906108c 6807stored.
c906108c
SS
6808
6809@item -
6810Negative. Defined on integral and floating-point types. Same
6811precedence as @code{++}.
6812
6813@item !
6814Logical negation. Defined on integral types. Same precedence as
6815@code{++}.
6816
6817@item ~
6818Bitwise complement operator. Defined on integral types. Same precedence as
6819@code{++}.
6820
6821
6822@item .@r{, }->
6823Structure member, and pointer-to-structure member. For convenience,
6824@value{GDBN} regards the two as equivalent, choosing whether to dereference a
6825pointer based on the stored type information.
6826Defined on @code{struct} and @code{union} data.
6827
c906108c
SS
6828@item .*@r{, }->*
6829Dereferences of pointers to members.
c906108c
SS
6830
6831@item []
6832Array indexing. @code{@var{a}[@var{i}]} is defined as
6833@code{*(@var{a}+@var{i})}. Same precedence as @code{->}.
6834
6835@item ()
6836Function parameter list. Same precedence as @code{->}.
6837
c906108c 6838@item ::
b37052ae 6839C@t{++} scope resolution operator. Defined on @code{struct}, @code{union},
7a292a7a 6840and @code{class} types.
c906108c
SS
6841
6842@item ::
7a292a7a
SS
6843Doubled colons also represent the @value{GDBN} scope operator
6844(@pxref{Expressions, ,Expressions}). Same precedence as @code{::},
6845above.
c906108c
SS
6846@end table
6847
c906108c
SS
6848If an operator is redefined in the user code, @value{GDBN} usually
6849attempts to invoke the redefined version instead of using the operator's
6850predefined meaning.
c906108c 6851
c906108c 6852@menu
5d161b24 6853* C Constants::
c906108c
SS
6854@end menu
6855
6d2ebf8b 6856@node C Constants
b37052ae 6857@subsubsection C and C@t{++} constants
c906108c 6858
b37052ae 6859@cindex C and C@t{++} constants
c906108c 6860
b37052ae 6861@value{GDBN} allows you to express the constants of C and C@t{++} in the
c906108c 6862following ways:
c906108c
SS
6863
6864@itemize @bullet
6865@item
6866Integer constants are a sequence of digits. Octal constants are
6867specified by a leading @samp{0} (i.e. zero), and hexadecimal constants by
6868a leading @samp{0x} or @samp{0X}. Constants may also end with a letter
6869@samp{l}, specifying that the constant should be treated as a
6870@code{long} value.
6871
6872@item
6873Floating point constants are a sequence of digits, followed by a decimal
6874point, followed by a sequence of digits, and optionally followed by an
6875exponent. An exponent is of the form:
6876@samp{@w{e@r{[[}+@r{]|}-@r{]}@var{nnn}}}, where @var{nnn} is another
6877sequence of digits. The @samp{+} is optional for positive exponents.
d4f3574e
SS
6878A floating-point constant may also end with a letter @samp{f} or
6879@samp{F}, specifying that the constant should be treated as being of
6880the @code{float} (as opposed to the default @code{double}) type; or with
6881a letter @samp{l} or @samp{L}, which specifies a @code{long double}
6882constant.
c906108c
SS
6883
6884@item
6885Enumerated constants consist of enumerated identifiers, or their
6886integral equivalents.
6887
6888@item
6889Character constants are a single character surrounded by single quotes
6890(@code{'}), or a number---the ordinal value of the corresponding character
d4f3574e 6891(usually its @sc{ascii} value). Within quotes, the single character may
c906108c
SS
6892be represented by a letter or by @dfn{escape sequences}, which are of
6893the form @samp{\@var{nnn}}, where @var{nnn} is the octal representation
6894of the character's ordinal value; or of the form @samp{\@var{x}}, where
6895@samp{@var{x}} is a predefined special character---for example,
6896@samp{\n} for newline.
6897
6898@item
96a2c332
SS
6899String constants are a sequence of character constants surrounded by
6900double quotes (@code{"}). Any valid character constant (as described
6901above) may appear. Double quotes within the string must be preceded by
6902a backslash, so for instance @samp{"a\"b'c"} is a string of five
6903characters.
c906108c
SS
6904
6905@item
6906Pointer constants are an integral value. You can also write pointers
6907to constants using the C operator @samp{&}.
6908
6909@item
6910Array constants are comma-separated lists surrounded by braces @samp{@{}
6911and @samp{@}}; for example, @samp{@{1,2,3@}} is a three-element array of
6912integers, @samp{@{@{1,2@}, @{3,4@}, @{5,6@}@}} is a three-by-two array,
6913and @samp{@{&"hi", &"there", &"fred"@}} is a three-element array of pointers.
6914@end itemize
6915
c906108c 6916@menu
5d161b24
DB
6917* C plus plus expressions::
6918* C Defaults::
6919* C Checks::
c906108c 6920
5d161b24 6921* Debugging C::
c906108c
SS
6922@end menu
6923
6d2ebf8b 6924@node C plus plus expressions
b37052ae
EZ
6925@subsubsection C@t{++} expressions
6926
6927@cindex expressions in C@t{++}
6928@value{GDBN} expression handling can interpret most C@t{++} expressions.
6929
6930@cindex C@t{++} support, not in @sc{coff}
6931@cindex @sc{coff} versus C@t{++}
6932@cindex C@t{++} and object formats
6933@cindex object formats and C@t{++}
6934@cindex a.out and C@t{++}
6935@cindex @sc{ecoff} and C@t{++}
6936@cindex @sc{xcoff} and C@t{++}
6937@cindex @sc{elf}/stabs and C@t{++}
6938@cindex @sc{elf}/@sc{dwarf} and C@t{++}
c906108c
SS
6939@c FIXME!! GDB may eventually be able to debug C++ using DWARF; check
6940@c periodically whether this has happened...
6941@quotation
b37052ae
EZ
6942@emph{Warning:} @value{GDBN} can only debug C@t{++} code if you use the
6943proper compiler. Typically, C@t{++} debugging depends on the use of
c906108c
SS
6944additional debugging information in the symbol table, and thus requires
6945special support. In particular, if your compiler generates a.out, MIPS
6946@sc{ecoff}, RS/6000 @sc{xcoff}, or @sc{elf} with stabs extensions to the
6947symbol table, these facilities are all available. (With @sc{gnu} CC,
6948you can use the @samp{-gstabs} option to request stabs debugging
6949extensions explicitly.) Where the object code format is standard
b37052ae 6950@sc{coff} or @sc{dwarf} in @sc{elf}, on the other hand, most of the C@t{++}
c906108c
SS
6951support in @value{GDBN} does @emph{not} work.
6952@end quotation
c906108c
SS
6953
6954@enumerate
6955
6956@cindex member functions
6957@item
6958Member function calls are allowed; you can use expressions like
6959
6960@example
6961count = aml->GetOriginal(x, y)
6962@end example
6963
41afff9a 6964@vindex this@r{, inside C@t{++} member functions}
b37052ae 6965@cindex namespace in C@t{++}
c906108c
SS
6966@item
6967While a member function is active (in the selected stack frame), your
6968expressions have the same namespace available as the member function;
6969that is, @value{GDBN} allows implicit references to the class instance
b37052ae 6970pointer @code{this} following the same rules as C@t{++}.
c906108c 6971
c906108c 6972@cindex call overloaded functions
d4f3574e 6973@cindex overloaded functions, calling
b37052ae 6974@cindex type conversions in C@t{++}
c906108c
SS
6975@item
6976You can call overloaded functions; @value{GDBN} resolves the function
d4f3574e 6977call to the right definition, with some restrictions. @value{GDBN} does not
c906108c
SS
6978perform overload resolution involving user-defined type conversions,
6979calls to constructors, or instantiations of templates that do not exist
6980in the program. It also cannot handle ellipsis argument lists or
6981default arguments.
6982
6983It does perform integral conversions and promotions, floating-point
6984promotions, arithmetic conversions, pointer conversions, conversions of
6985class objects to base classes, and standard conversions such as those of
6986functions or arrays to pointers; it requires an exact match on the
6987number of function arguments.
6988
6989Overload resolution is always performed, unless you have specified
6990@code{set overload-resolution off}. @xref{Debugging C plus plus,
b37052ae 6991,@value{GDBN} features for C@t{++}}.
c906108c 6992
d4f3574e 6993You must specify @code{set overload-resolution off} in order to use an
c906108c
SS
6994explicit function signature to call an overloaded function, as in
6995@smallexample
6996p 'foo(char,int)'('x', 13)
6997@end smallexample
d4f3574e 6998
c906108c 6999The @value{GDBN} command-completion facility can simplify this;
d4f3574e 7000see @ref{Completion, ,Command completion}.
c906108c 7001
c906108c
SS
7002@cindex reference declarations
7003@item
b37052ae
EZ
7004@value{GDBN} understands variables declared as C@t{++} references; you can use
7005them in expressions just as you do in C@t{++} source---they are automatically
c906108c
SS
7006dereferenced.
7007
7008In the parameter list shown when @value{GDBN} displays a frame, the values of
7009reference variables are not displayed (unlike other variables); this
7010avoids clutter, since references are often used for large structures.
7011The @emph{address} of a reference variable is always shown, unless
7012you have specified @samp{set print address off}.
7013
7014@item
b37052ae 7015@value{GDBN} supports the C@t{++} name resolution operator @code{::}---your
c906108c
SS
7016expressions can use it just as expressions in your program do. Since
7017one scope may be defined in another, you can use @code{::} repeatedly if
7018necessary, for example in an expression like
7019@samp{@var{scope1}::@var{scope2}::@var{name}}. @value{GDBN} also allows
b37052ae 7020resolving name scope by reference to source files, in both C and C@t{++}
c906108c
SS
7021debugging (@pxref{Variables, ,Program variables}).
7022@end enumerate
7023
b37052ae 7024In addition, when used with HP's C@t{++} compiler, @value{GDBN} supports
53a5351d
JM
7025calling virtual functions correctly, printing out virtual bases of
7026objects, calling functions in a base subobject, casting objects, and
7027invoking user-defined operators.
c906108c 7028
6d2ebf8b 7029@node C Defaults
b37052ae 7030@subsubsection C and C@t{++} defaults
7a292a7a 7031
b37052ae 7032@cindex C and C@t{++} defaults
c906108c 7033
c906108c
SS
7034If you allow @value{GDBN} to set type and range checking automatically, they
7035both default to @code{off} whenever the working language changes to
b37052ae 7036C or C@t{++}. This happens regardless of whether you or @value{GDBN}
c906108c 7037selects the working language.
c906108c
SS
7038
7039If you allow @value{GDBN} to set the language automatically, it
7040recognizes source files whose names end with @file{.c}, @file{.C}, or
7041@file{.cc}, etc, and when @value{GDBN} enters code compiled from one of
b37052ae 7042these files, it sets the working language to C or C@t{++}.
c906108c
SS
7043@xref{Automatically, ,Having @value{GDBN} infer the source language},
7044for further details.
7045
c906108c
SS
7046@c Type checking is (a) primarily motivated by Modula-2, and (b)
7047@c unimplemented. If (b) changes, it might make sense to let this node
7048@c appear even if Mod-2 does not, but meanwhile ignore it. roland 16jul93.
7a292a7a 7049
6d2ebf8b 7050@node C Checks
b37052ae 7051@subsubsection C and C@t{++} type and range checks
7a292a7a 7052
b37052ae 7053@cindex C and C@t{++} checks
c906108c 7054
b37052ae 7055By default, when @value{GDBN} parses C or C@t{++} expressions, type checking
c906108c
SS
7056is not used. However, if you turn type checking on, @value{GDBN}
7057considers two variables type equivalent if:
7058
7059@itemize @bullet
7060@item
7061The two variables are structured and have the same structure, union, or
7062enumerated tag.
7063
7064@item
7065The two variables have the same type name, or types that have been
7066declared equivalent through @code{typedef}.
7067
7068@ignore
7069@c leaving this out because neither J Gilmore nor R Pesch understand it.
7070@c FIXME--beers?
7071@item
7072The two @code{struct}, @code{union}, or @code{enum} variables are
7073declared in the same declaration. (Note: this may not be true for all C
7074compilers.)
7075@end ignore
7076@end itemize
7077
7078Range checking, if turned on, is done on mathematical operations. Array
7079indices are not checked, since they are often used to index a pointer
7080that is not itself an array.
c906108c 7081
6d2ebf8b 7082@node Debugging C
c906108c 7083@subsubsection @value{GDBN} and C
c906108c
SS
7084
7085The @code{set print union} and @code{show print union} commands apply to
7086the @code{union} type. When set to @samp{on}, any @code{union} that is
7a292a7a
SS
7087inside a @code{struct} or @code{class} is also printed. Otherwise, it
7088appears as @samp{@{...@}}.
c906108c
SS
7089
7090The @code{@@} operator aids in the debugging of dynamic arrays, formed
7091with pointers and a memory allocation function. @xref{Expressions,
7092,Expressions}.
7093
c906108c 7094@menu
5d161b24 7095* Debugging C plus plus::
c906108c
SS
7096@end menu
7097
6d2ebf8b 7098@node Debugging C plus plus
b37052ae 7099@subsubsection @value{GDBN} features for C@t{++}
c906108c 7100
b37052ae 7101@cindex commands for C@t{++}
7a292a7a 7102
b37052ae
EZ
7103Some @value{GDBN} commands are particularly useful with C@t{++}, and some are
7104designed specifically for use with C@t{++}. Here is a summary:
c906108c
SS
7105
7106@table @code
7107@cindex break in overloaded functions
7108@item @r{breakpoint menus}
7109When you want a breakpoint in a function whose name is overloaded,
7110@value{GDBN} breakpoint menus help you specify which function definition
7111you want. @xref{Breakpoint Menus,,Breakpoint menus}.
7112
b37052ae 7113@cindex overloading in C@t{++}
c906108c
SS
7114@item rbreak @var{regex}
7115Setting breakpoints using regular expressions is helpful for setting
7116breakpoints on overloaded functions that are not members of any special
7117classes.
7118@xref{Set Breaks, ,Setting breakpoints}.
7119
b37052ae 7120@cindex C@t{++} exception handling
c906108c
SS
7121@item catch throw
7122@itemx catch catch
b37052ae 7123Debug C@t{++} exception handling using these commands. @xref{Set
c906108c
SS
7124Catchpoints, , Setting catchpoints}.
7125
7126@cindex inheritance
7127@item ptype @var{typename}
7128Print inheritance relationships as well as other information for type
7129@var{typename}.
7130@xref{Symbols, ,Examining the Symbol Table}.
7131
b37052ae 7132@cindex C@t{++} symbol display
c906108c
SS
7133@item set print demangle
7134@itemx show print demangle
7135@itemx set print asm-demangle
7136@itemx show print asm-demangle
b37052ae
EZ
7137Control whether C@t{++} symbols display in their source form, both when
7138displaying code as C@t{++} source and when displaying disassemblies.
c906108c
SS
7139@xref{Print Settings, ,Print settings}.
7140
7141@item set print object
7142@itemx show print object
7143Choose whether to print derived (actual) or declared types of objects.
7144@xref{Print Settings, ,Print settings}.
7145
7146@item set print vtbl
7147@itemx show print vtbl
7148Control the format for printing virtual function tables.
7149@xref{Print Settings, ,Print settings}.
c906108c 7150(The @code{vtbl} commands do not work on programs compiled with the HP
b37052ae 7151ANSI C@t{++} compiler (@code{aCC}).)
c906108c
SS
7152
7153@kindex set overload-resolution
d4f3574e 7154@cindex overloaded functions, overload resolution
c906108c 7155@item set overload-resolution on
b37052ae 7156Enable overload resolution for C@t{++} expression evaluation. The default
c906108c
SS
7157is on. For overloaded functions, @value{GDBN} evaluates the arguments
7158and searches for a function whose signature matches the argument types,
b37052ae 7159using the standard C@t{++} conversion rules (see @ref{C plus plus expressions, ,C@t{++}
d4f3574e 7160expressions}, for details). If it cannot find a match, it emits a
c906108c
SS
7161message.
7162
7163@item set overload-resolution off
b37052ae 7164Disable overload resolution for C@t{++} expression evaluation. For
c906108c
SS
7165overloaded functions that are not class member functions, @value{GDBN}
7166chooses the first function of the specified name that it finds in the
7167symbol table, whether or not its arguments are of the correct type. For
7168overloaded functions that are class member functions, @value{GDBN}
7169searches for a function whose signature @emph{exactly} matches the
7170argument types.
c906108c
SS
7171
7172@item @r{Overloaded symbol names}
7173You can specify a particular definition of an overloaded symbol, using
b37052ae 7174the same notation that is used to declare such symbols in C@t{++}: type
c906108c
SS
7175@code{@var{symbol}(@var{types})} rather than just @var{symbol}. You can
7176also use the @value{GDBN} command-line word completion facilities to list the
7177available choices, or to finish the type list for you.
7178@xref{Completion,, Command completion}, for details on how to do this.
7179@end table
c906108c 7180
6d2ebf8b 7181@node Modula-2
c906108c 7182@subsection Modula-2
7a292a7a 7183
d4f3574e 7184@cindex Modula-2, @value{GDBN} support
c906108c
SS
7185
7186The extensions made to @value{GDBN} to support Modula-2 only support
7187output from the @sc{gnu} Modula-2 compiler (which is currently being
7188developed). Other Modula-2 compilers are not currently supported, and
7189attempting to debug executables produced by them is most likely
7190to give an error as @value{GDBN} reads in the executable's symbol
7191table.
7192
7193@cindex expressions in Modula-2
7194@menu
7195* M2 Operators:: Built-in operators
7196* Built-In Func/Proc:: Built-in functions and procedures
7197* M2 Constants:: Modula-2 constants
7198* M2 Defaults:: Default settings for Modula-2
7199* Deviations:: Deviations from standard Modula-2
7200* M2 Checks:: Modula-2 type and range checks
7201* M2 Scope:: The scope operators @code{::} and @code{.}
7202* GDB/M2:: @value{GDBN} and Modula-2
7203@end menu
7204
6d2ebf8b 7205@node M2 Operators
c906108c
SS
7206@subsubsection Operators
7207@cindex Modula-2 operators
7208
7209Operators must be defined on values of specific types. For instance,
7210@code{+} is defined on numbers, but not on structures. Operators are
7211often defined on groups of types. For the purposes of Modula-2, the
7212following definitions hold:
7213
7214@itemize @bullet
7215
7216@item
7217@emph{Integral types} consist of @code{INTEGER}, @code{CARDINAL}, and
7218their subranges.
7219
7220@item
7221@emph{Character types} consist of @code{CHAR} and its subranges.
7222
7223@item
7224@emph{Floating-point types} consist of @code{REAL}.
7225
7226@item
7227@emph{Pointer types} consist of anything declared as @code{POINTER TO
7228@var{type}}.
7229
7230@item
7231@emph{Scalar types} consist of all of the above.
7232
7233@item
7234@emph{Set types} consist of @code{SET} and @code{BITSET} types.
7235
7236@item
7237@emph{Boolean types} consist of @code{BOOLEAN}.
7238@end itemize
7239
7240@noindent
7241The following operators are supported, and appear in order of
7242increasing precedence:
7243
7244@table @code
7245@item ,
7246Function argument or array index separator.
7247
7248@item :=
7249Assignment. The value of @var{var} @code{:=} @var{value} is
7250@var{value}.
7251
7252@item <@r{, }>
7253Less than, greater than on integral, floating-point, or enumerated
7254types.
7255
7256@item <=@r{, }>=
96a2c332 7257Less than or equal to, greater than or equal to
c906108c
SS
7258on integral, floating-point and enumerated types, or set inclusion on
7259set types. Same precedence as @code{<}.
7260
7261@item =@r{, }<>@r{, }#
7262Equality and two ways of expressing inequality, valid on scalar types.
7263Same precedence as @code{<}. In @value{GDBN} scripts, only @code{<>} is
7264available for inequality, since @code{#} conflicts with the script
7265comment character.
7266
7267@item IN
7268Set membership. Defined on set types and the types of their members.
7269Same precedence as @code{<}.
7270
7271@item OR
7272Boolean disjunction. Defined on boolean types.
7273
7274@item AND@r{, }&
d4f3574e 7275Boolean conjunction. Defined on boolean types.
c906108c
SS
7276
7277@item @@
7278The @value{GDBN} ``artificial array'' operator (@pxref{Expressions, ,Expressions}).
7279
7280@item +@r{, }-
7281Addition and subtraction on integral and floating-point types, or union
7282and difference on set types.
7283
7284@item *
7285Multiplication on integral and floating-point types, or set intersection
7286on set types.
7287
7288@item /
7289Division on floating-point types, or symmetric set difference on set
7290types. Same precedence as @code{*}.
7291
7292@item DIV@r{, }MOD
7293Integer division and remainder. Defined on integral types. Same
7294precedence as @code{*}.
7295
7296@item -
7297Negative. Defined on @code{INTEGER} and @code{REAL} data.
7298
7299@item ^
7300Pointer dereferencing. Defined on pointer types.
7301
7302@item NOT
7303Boolean negation. Defined on boolean types. Same precedence as
7304@code{^}.
7305
7306@item .
7307@code{RECORD} field selector. Defined on @code{RECORD} data. Same
7308precedence as @code{^}.
7309
7310@item []
7311Array indexing. Defined on @code{ARRAY} data. Same precedence as @code{^}.
7312
7313@item ()
7314Procedure argument list. Defined on @code{PROCEDURE} objects. Same precedence
7315as @code{^}.
7316
7317@item ::@r{, }.
7318@value{GDBN} and Modula-2 scope operators.
7319@end table
7320
7321@quotation
7322@emph{Warning:} Sets and their operations are not yet supported, so @value{GDBN}
7323treats the use of the operator @code{IN}, or the use of operators
7324@code{+}, @code{-}, @code{*}, @code{/}, @code{=}, , @code{<>}, @code{#},
7325@code{<=}, and @code{>=} on sets as an error.
7326@end quotation
7327
cb51c4e0 7328
6d2ebf8b 7329@node Built-In Func/Proc
c906108c 7330@subsubsection Built-in functions and procedures
cb51c4e0 7331@cindex Modula-2 built-ins
c906108c
SS
7332
7333Modula-2 also makes available several built-in procedures and functions.
7334In describing these, the following metavariables are used:
7335
7336@table @var
7337
7338@item a
7339represents an @code{ARRAY} variable.
7340
7341@item c
7342represents a @code{CHAR} constant or variable.
7343
7344@item i
7345represents a variable or constant of integral type.
7346
7347@item m
7348represents an identifier that belongs to a set. Generally used in the
7349same function with the metavariable @var{s}. The type of @var{s} should
7350be @code{SET OF @var{mtype}} (where @var{mtype} is the type of @var{m}).
7351
7352@item n
7353represents a variable or constant of integral or floating-point type.
7354
7355@item r
7356represents a variable or constant of floating-point type.
7357
7358@item t
7359represents a type.
7360
7361@item v
7362represents a variable.
7363
7364@item x
7365represents a variable or constant of one of many types. See the
7366explanation of the function for details.
7367@end table
7368
7369All Modula-2 built-in procedures also return a result, described below.
7370
7371@table @code
7372@item ABS(@var{n})
7373Returns the absolute value of @var{n}.
7374
7375@item CAP(@var{c})
7376If @var{c} is a lower case letter, it returns its upper case
c3f6f71d 7377equivalent, otherwise it returns its argument.
c906108c
SS
7378
7379@item CHR(@var{i})
7380Returns the character whose ordinal value is @var{i}.
7381
7382@item DEC(@var{v})
c3f6f71d 7383Decrements the value in the variable @var{v} by one. Returns the new value.
c906108c
SS
7384
7385@item DEC(@var{v},@var{i})
7386Decrements the value in the variable @var{v} by @var{i}. Returns the
7387new value.
7388
7389@item EXCL(@var{m},@var{s})
7390Removes the element @var{m} from the set @var{s}. Returns the new
7391set.
7392
7393@item FLOAT(@var{i})
7394Returns the floating point equivalent of the integer @var{i}.
7395
7396@item HIGH(@var{a})
7397Returns the index of the last member of @var{a}.
7398
7399@item INC(@var{v})
c3f6f71d 7400Increments the value in the variable @var{v} by one. Returns the new value.
c906108c
SS
7401
7402@item INC(@var{v},@var{i})
7403Increments the value in the variable @var{v} by @var{i}. Returns the
7404new value.
7405
7406@item INCL(@var{m},@var{s})
7407Adds the element @var{m} to the set @var{s} if it is not already
7408there. Returns the new set.
7409
7410@item MAX(@var{t})
7411Returns the maximum value of the type @var{t}.
7412
7413@item MIN(@var{t})
7414Returns the minimum value of the type @var{t}.
7415
7416@item ODD(@var{i})
7417Returns boolean TRUE if @var{i} is an odd number.
7418
7419@item ORD(@var{x})
7420Returns the ordinal value of its argument. For example, the ordinal
c3f6f71d
JM
7421value of a character is its @sc{ascii} value (on machines supporting the
7422@sc{ascii} character set). @var{x} must be of an ordered type, which include
c906108c
SS
7423integral, character and enumerated types.
7424
7425@item SIZE(@var{x})
7426Returns the size of its argument. @var{x} can be a variable or a type.
7427
7428@item TRUNC(@var{r})
7429Returns the integral part of @var{r}.
7430
7431@item VAL(@var{t},@var{i})
7432Returns the member of the type @var{t} whose ordinal value is @var{i}.
7433@end table
7434
7435@quotation
7436@emph{Warning:} Sets and their operations are not yet supported, so
7437@value{GDBN} treats the use of procedures @code{INCL} and @code{EXCL} as
7438an error.
7439@end quotation
7440
7441@cindex Modula-2 constants
6d2ebf8b 7442@node M2 Constants
c906108c
SS
7443@subsubsection Constants
7444
7445@value{GDBN} allows you to express the constants of Modula-2 in the following
7446ways:
7447
7448@itemize @bullet
7449
7450@item
7451Integer constants are simply a sequence of digits. When used in an
7452expression, a constant is interpreted to be type-compatible with the
7453rest of the expression. Hexadecimal integers are specified by a
7454trailing @samp{H}, and octal integers by a trailing @samp{B}.
7455
7456@item
7457Floating point constants appear as a sequence of digits, followed by a
7458decimal point and another sequence of digits. An optional exponent can
7459then be specified, in the form @samp{E@r{[}+@r{|}-@r{]}@var{nnn}}, where
7460@samp{@r{[}+@r{|}-@r{]}@var{nnn}} is the desired exponent. All of the
7461digits of the floating point constant must be valid decimal (base 10)
7462digits.
7463
7464@item
7465Character constants consist of a single character enclosed by a pair of
7466like quotes, either single (@code{'}) or double (@code{"}). They may
c3f6f71d 7467also be expressed by their ordinal value (their @sc{ascii} value, usually)
c906108c
SS
7468followed by a @samp{C}.
7469
7470@item
7471String constants consist of a sequence of characters enclosed by a
7472pair of like quotes, either single (@code{'}) or double (@code{"}).
7473Escape sequences in the style of C are also allowed. @xref{C
b37052ae 7474Constants, ,C and C@t{++} constants}, for a brief explanation of escape
c906108c
SS
7475sequences.
7476
7477@item
7478Enumerated constants consist of an enumerated identifier.
7479
7480@item
7481Boolean constants consist of the identifiers @code{TRUE} and
7482@code{FALSE}.
7483
7484@item
7485Pointer constants consist of integral values only.
7486
7487@item
7488Set constants are not yet supported.
7489@end itemize
7490
6d2ebf8b 7491@node M2 Defaults
c906108c
SS
7492@subsubsection Modula-2 defaults
7493@cindex Modula-2 defaults
7494
7495If type and range checking are set automatically by @value{GDBN}, they
7496both default to @code{on} whenever the working language changes to
d4f3574e 7497Modula-2. This happens regardless of whether you or @value{GDBN}
c906108c
SS
7498selected the working language.
7499
7500If you allow @value{GDBN} to set the language automatically, then entering
7501code compiled from a file whose name ends with @file{.mod} sets the
d4f3574e 7502working language to Modula-2. @xref{Automatically, ,Having @value{GDBN} set
c906108c
SS
7503the language automatically}, for further details.
7504
6d2ebf8b 7505@node Deviations
c906108c
SS
7506@subsubsection Deviations from standard Modula-2
7507@cindex Modula-2, deviations from
7508
7509A few changes have been made to make Modula-2 programs easier to debug.
7510This is done primarily via loosening its type strictness:
7511
7512@itemize @bullet
7513@item
7514Unlike in standard Modula-2, pointer constants can be formed by
7515integers. This allows you to modify pointer variables during
7516debugging. (In standard Modula-2, the actual address contained in a
7517pointer variable is hidden from you; it can only be modified
7518through direct assignment to another pointer variable or expression that
7519returned a pointer.)
7520
7521@item
7522C escape sequences can be used in strings and characters to represent
7523non-printable characters. @value{GDBN} prints out strings with these
7524escape sequences embedded. Single non-printable characters are
7525printed using the @samp{CHR(@var{nnn})} format.
7526
7527@item
7528The assignment operator (@code{:=}) returns the value of its right-hand
7529argument.
7530
7531@item
7532All built-in procedures both modify @emph{and} return their argument.
7533@end itemize
7534
6d2ebf8b 7535@node M2 Checks
c906108c
SS
7536@subsubsection Modula-2 type and range checks
7537@cindex Modula-2 checks
7538
7539@quotation
7540@emph{Warning:} in this release, @value{GDBN} does not yet perform type or
7541range checking.
7542@end quotation
7543@c FIXME remove warning when type/range checks added
7544
7545@value{GDBN} considers two Modula-2 variables type equivalent if:
7546
7547@itemize @bullet
7548@item
7549They are of types that have been declared equivalent via a @code{TYPE
7550@var{t1} = @var{t2}} statement
7551
7552@item
7553They have been declared on the same line. (Note: This is true of the
7554@sc{gnu} Modula-2 compiler, but it may not be true of other compilers.)
7555@end itemize
7556
7557As long as type checking is enabled, any attempt to combine variables
7558whose types are not equivalent is an error.
7559
7560Range checking is done on all mathematical operations, assignment, array
7561index bounds, and all built-in functions and procedures.
7562
6d2ebf8b 7563@node M2 Scope
c906108c
SS
7564@subsubsection The scope operators @code{::} and @code{.}
7565@cindex scope
41afff9a 7566@cindex @code{.}, Modula-2 scope operator
c906108c
SS
7567@cindex colon, doubled as scope operator
7568@ifinfo
41afff9a 7569@vindex colon-colon@r{, in Modula-2}
c906108c
SS
7570@c Info cannot handle :: but TeX can.
7571@end ifinfo
7572@iftex
41afff9a 7573@vindex ::@r{, in Modula-2}
c906108c
SS
7574@end iftex
7575
7576There are a few subtle differences between the Modula-2 scope operator
7577(@code{.}) and the @value{GDBN} scope operator (@code{::}). The two have
7578similar syntax:
7579
7580@example
7581
7582@var{module} . @var{id}
7583@var{scope} :: @var{id}
7584@end example
7585
7586@noindent
7587where @var{scope} is the name of a module or a procedure,
7588@var{module} the name of a module, and @var{id} is any declared
7589identifier within your program, except another module.
7590
7591Using the @code{::} operator makes @value{GDBN} search the scope
7592specified by @var{scope} for the identifier @var{id}. If it is not
7593found in the specified scope, then @value{GDBN} searches all scopes
7594enclosing the one specified by @var{scope}.
7595
7596Using the @code{.} operator makes @value{GDBN} search the current scope for
7597the identifier specified by @var{id} that was imported from the
7598definition module specified by @var{module}. With this operator, it is
7599an error if the identifier @var{id} was not imported from definition
7600module @var{module}, or if @var{id} is not an identifier in
7601@var{module}.
7602
6d2ebf8b 7603@node GDB/M2
c906108c
SS
7604@subsubsection @value{GDBN} and Modula-2
7605
7606Some @value{GDBN} commands have little use when debugging Modula-2 programs.
7607Five subcommands of @code{set print} and @code{show print} apply
b37052ae 7608specifically to C and C@t{++}: @samp{vtbl}, @samp{demangle},
c906108c 7609@samp{asm-demangle}, @samp{object}, and @samp{union}. The first four
b37052ae 7610apply to C@t{++}, and the last to the C @code{union} type, which has no direct
c906108c
SS
7611analogue in Modula-2.
7612
7613The @code{@@} operator (@pxref{Expressions, ,Expressions}), while available
d4f3574e 7614with any language, is not useful with Modula-2. Its
c906108c 7615intent is to aid the debugging of @dfn{dynamic arrays}, which cannot be
b37052ae 7616created in Modula-2 as they can in C or C@t{++}. However, because an
c906108c 7617address can be specified by an integral constant, the construct
d4f3574e 7618@samp{@{@var{type}@}@var{adrexp}} is still useful.
c906108c
SS
7619
7620@cindex @code{#} in Modula-2
7621In @value{GDBN} scripts, the Modula-2 inequality operator @code{#} is
7622interpreted as the beginning of a comment. Use @code{<>} instead.
c906108c 7623
6d2ebf8b 7624@node Chill
cce74817
JM
7625@subsection Chill
7626
7627The extensions made to @value{GDBN} to support Chill only support output
d4f3574e 7628from the @sc{gnu} Chill compiler. Other Chill compilers are not currently
cce74817
JM
7629supported, and attempting to debug executables produced by them is most
7630likely to give an error as @value{GDBN} reads in the executable's symbol
7631table.
7632
d4f3574e
SS
7633@c This used to say "... following Chill related topics ...", but since
7634@c menus are not shown in the printed manual, it would look awkward.
7635This section covers the Chill related topics and the features
cce74817
JM
7636of @value{GDBN} which support these topics.
7637
7638@menu
104c1213
JM
7639* How modes are displayed:: How modes are displayed
7640* Locations:: Locations and their accesses
cce74817 7641* Values and their Operations:: Values and their Operations
5d161b24 7642* Chill type and range checks::
53a5351d 7643* Chill defaults::
cce74817
JM
7644@end menu
7645
6d2ebf8b 7646@node How modes are displayed
cce74817
JM
7647@subsubsection How modes are displayed
7648
7649The Chill Datatype- (Mode) support of @value{GDBN} is directly related
d4f3574e 7650with the functionality of the @sc{gnu} Chill compiler, and therefore deviates
cce74817
JM
7651slightly from the standard specification of the Chill language. The
7652provided modes are:
d4f3574e
SS
7653
7654@c FIXME: this @table's contents effectively disable @code by using @r
7655@c on every @item. So why does it need @code?
cce74817
JM
7656@table @code
7657@item @r{@emph{Discrete modes:}}
7658@itemize @bullet
7659@item
7660@emph{Integer Modes} which are predefined by @code{BYTE, UBYTE, INT,
7661UINT, LONG, ULONG},
7662@item
5d161b24 7663@emph{Boolean Mode} which is predefined by @code{BOOL},
cce74817 7664@item
5d161b24 7665@emph{Character Mode} which is predefined by @code{CHAR},
cce74817
JM
7666@item
7667@emph{Set Mode} which is displayed by the keyword @code{SET}.
7668@smallexample
7669(@value{GDBP}) ptype x
7670type = SET (karli = 10, susi = 20, fritzi = 100)
7671@end smallexample
7672If the type is an unnumbered set the set element values are omitted.
7673@item
6d2ebf8b
SS
7674@emph{Range Mode} which is displayed by
7675@smallexample
7676@code{type = <basemode>(<lower bound> : <upper bound>)}
7677@end smallexample
7678where @code{<lower bound>, <upper bound>} can be of any discrete literal
7679expression (e.g. set element names).
cce74817
JM
7680@end itemize
7681
7682@item @r{@emph{Powerset Mode:}}
7683A Powerset Mode is displayed by the keyword @code{POWERSET} followed by
d4f3574e 7684the member mode of the powerset. The member mode can be any discrete mode.
cce74817
JM
7685@smallexample
7686(@value{GDBP}) ptype x
7687type = POWERSET SET (egon, hugo, otto)
7688@end smallexample
7689
7690@item @r{@emph{Reference Modes:}}
7691@itemize @bullet
7692@item
d4f3574e 7693@emph{Bound Reference Mode} which is displayed by the keyword @code{REF}
cce74817
JM
7694followed by the mode name to which the reference is bound.
7695@item
7696@emph{Free Reference Mode} which is displayed by the keyword @code{PTR}.
7697@end itemize
7698
7699@item @r{@emph{Procedure mode}}
7700The procedure mode is displayed by @code{type = PROC(<parameter list>)
7701<return mode> EXCEPTIONS (<exception list>)}. The @code{<parameter
d4f3574e
SS
7702list>} is a list of the parameter modes. @code{<return mode>} indicates
7703the mode of the result of the procedure if any. The exceptionlist lists
cce74817
JM
7704all possible exceptions which can be raised by the procedure.
7705
7706@ignore
7707@item @r{@emph{Instance mode}}
7708The instance mode is represented by a structure, which has a static
5d161b24 7709type, and is therefore not really of interest.
cce74817
JM
7710@end ignore
7711
5d161b24 7712@item @r{@emph{Synchronization Modes:}}
cce74817
JM
7713@itemize @bullet
7714@item
6d2ebf8b
SS
7715@emph{Event Mode} which is displayed by
7716@smallexample
7717@code{EVENT (<event length>)}
7718@end smallexample
cce74817
JM
7719where @code{(<event length>)} is optional.
7720@item
6d2ebf8b
SS
7721@emph{Buffer Mode} which is displayed by
7722@smallexample
7723@code{BUFFER (<buffer length>)<buffer element mode>}
7724@end smallexample
7725where @code{(<buffer length>)} is optional.
cce74817
JM
7726@end itemize
7727
5d161b24 7728@item @r{@emph{Timing Modes:}}
cce74817
JM
7729@itemize @bullet
7730@item
7731@emph{Duration Mode} which is predefined by @code{DURATION}
7732@item
7733@emph{Absolute Time Mode} which is predefined by @code{TIME}
7734@end itemize
7735
7736@item @r{@emph{Real Modes:}}
7737Real Modes are predefined with @code{REAL} and @code{LONG_REAL}.
7738
7739@item @r{@emph{String Modes:}}
7740@itemize @bullet
7741@item
6d2ebf8b
SS
7742@emph{Character String Mode} which is displayed by
7743@smallexample
7744@code{CHARS(<string length>)}
7745@end smallexample
7746followed by the keyword @code{VARYING} if the String Mode is a varying
7747mode
cce74817 7748@item
6d2ebf8b
SS
7749@emph{Bit String Mode} which is displayed by
7750@smallexample
7751@code{BOOLS(<string
7752length>)}
7753@end smallexample
cce74817
JM
7754@end itemize
7755
7756@item @r{@emph{Array Mode:}}
7757The Array Mode is displayed by the keyword @code{ARRAY(<range>)}
7758followed by the element mode (which may in turn be an array mode).
7759@smallexample
7760(@value{GDBP}) ptype x
5d161b24
DB
7761type = ARRAY (1:42)
7762 ARRAY (1:20)
cce74817
JM
7763 SET (karli = 10, susi = 20, fritzi = 100)
7764@end smallexample
7765
5d161b24 7766@item @r{@emph{Structure Mode}}
cce74817 7767The Structure mode is displayed by the keyword @code{STRUCT(<field
d4f3574e
SS
7768list>)}. The @code{<field list>} consists of names and modes of fields
7769of the structure. Variant structures have the keyword @code{CASE <field>
7770OF <variant fields> ESAC} in their field list. Since the current version
cce74817
JM
7771of the GNU Chill compiler doesn't implement tag processing (no runtime
7772checks of variant fields, and therefore no debugging info), the output
7773always displays all variant fields.
7774@smallexample
7775(@value{GDBP}) ptype str
7776type = STRUCT (
7777 as x,
7778 bs x,
7779 CASE bs OF
7780 (karli):
7781 cs a
7782 (ott):
7783 ds x
7784 ESAC
7785)
7786@end smallexample
7787@end table
7788
6d2ebf8b 7789@node Locations
cce74817
JM
7790@subsubsection Locations and their accesses
7791
7792A location in Chill is an object which can contain values.
7793
7794A value of a location is generally accessed by the (declared) name of
d4f3574e
SS
7795the location. The output conforms to the specification of values in
7796Chill programs. How values are specified
7797is the topic of the next section, @ref{Values and their Operations}.
cce74817
JM
7798
7799The pseudo-location @code{RESULT} (or @code{result}) can be used to
7800display or change the result of a currently-active procedure:
d4f3574e 7801
cce74817
JM
7802@smallexample
7803set result := EXPR
7804@end smallexample
d4f3574e
SS
7805
7806@noindent
7807This does the same as the Chill action @code{RESULT EXPR} (which
c3f6f71d 7808is not available in @value{GDBN}).
cce74817
JM
7809
7810Values of reference mode locations are printed by @code{PTR(<hex
7811value>)} in case of a free reference mode, and by @code{(REF <reference
d4f3574e 7812mode>) (<hex-value>)} in case of a bound reference. @code{<hex value>}
cce74817
JM
7813represents the address where the reference points to. To access the
7814value of the location referenced by the pointer, use the dereference
d4f3574e 7815operator @samp{->}.
cce74817 7816
6d2ebf8b
SS
7817Values of procedure mode locations are displayed by
7818@smallexample
7819@code{@{ PROC
cce74817 7820(<argument modes> ) <return mode> @} <address> <name of procedure
6d2ebf8b
SS
7821location>}
7822@end smallexample
7823@code{<argument modes>} is a list of modes according to the parameter
7824specification of the procedure and @code{<address>} shows the address of
7825the entry point.
cce74817
JM
7826
7827@ignore
7828Locations of instance modes are displayed just like a structure with two
7829fields specifying the @emph{process type} and the @emph{copy number} of
7830the investigated instance location@footnote{This comes from the current
d4f3574e
SS
7831implementation of instances. They are implemented as a structure (no
7832na). The output should be something like @code{[<name of the process>;
7833<instance number>]}.}. The field names are @code{__proc_type} and
cce74817
JM
7834@code{__proc_copy}.
7835
7836Locations of synchronization modes are displayed like a structure with
7837the field name @code{__event_data} in case of a event mode location, and
7838like a structure with the field @code{__buffer_data} in case of a buffer
7839mode location (refer to previous paragraph).
7840
7841Structure Mode locations are printed by @code{[.<field name>: <value>,
d4f3574e 7842...]}. The @code{<field name>} corresponds to the structure mode
cce74817 7843definition and the layout of @code{<value>} varies depending of the mode
d4f3574e
SS
7844of the field. If the investigated structure mode location is of variant
7845structure mode, the variant parts of the structure are enclosed in curled
7846braces (@samp{@{@}}). Fields enclosed by @samp{@{,@}} are residing
cce74817 7847on the same memory location and represent the current values of the
d4f3574e 7848memory location in their specific modes. Since no tag processing is done
cce74817 7849all variants are displayed. A variant field is printed by
d4f3574e 7850@code{(<variant name>) = .<field name>: <value>}. (who implements the
cce74817
JM
7851stuff ???)
7852@smallexample
7853(@value{GDBP}) print str1 $4 = [.as: 0, .bs: karli, .<TAG>: { (karli) =
7854[.cs: []], (susi) = [.ds: susi]}]
7855@end smallexample
7856@end ignore
7857
7858Substructures of string mode-, array mode- or structure mode-values
7859(e.g. array slices, fields of structure locations) are accessed using
d4f3574e
SS
7860certain operations which are described in the next section, @ref{Values
7861and their Operations}.
cce74817
JM
7862
7863A location value may be interpreted as having a different mode using the
d4f3574e
SS
7864location conversion. This mode conversion is written as @code{<mode
7865name>(<location>)}. The user has to consider that the sizes of the modes
7866have to be equal otherwise an error occurs. Furthermore, no range
7867checking of the location against the destination mode is performed, and
cce74817 7868therefore the result can be quite confusing.
d4f3574e 7869
cce74817
JM
7870@smallexample
7871(@value{GDBP}) print int (s(3 up 4)) XXX TO be filled in !! XXX
7872@end smallexample
7873
6d2ebf8b 7874@node Values and their Operations
cce74817
JM
7875@subsubsection Values and their Operations
7876
7877Values are used to alter locations, to investigate complex structures in
7878more detail or to filter relevant information out of a large amount of
d4f3574e
SS
7879data. There are several (mode dependent) operations defined which enable
7880such investigations. These operations are not only applicable to
cce74817 7881constant values but also to locations, which can become quite useful
d4f3574e 7882when debugging complex structures. During parsing the command line
cce74817
JM
7883(e.g. evaluating an expression) @value{GDBN} treats location names as
7884the values behind these locations.
7885
d4f3574e 7886This section describes how values have to be specified and which
cce74817
JM
7887operations are legal to be used with such values.
7888
7889@table @code
7890@item Literal Values
d4f3574e
SS
7891Literal values are specified in the same manner as in @sc{gnu} Chill programs.
7892For detailed specification refer to the @sc{gnu} Chill implementation Manual
cce74817 7893chapter 1.5.
d4f3574e
SS
7894@c FIXME: if the Chill Manual is a Texinfo documents, the above should
7895@c be converted to a @ref.
cce74817 7896
5d161b24 7897@ignore
cce74817
JM
7898@itemize @bullet
7899@item
7900@emph{Integer Literals} are specified in the same manner as in Chill
d4f3574e 7901programs (refer to the Chill Standard z200/88 chpt 5.2.4.2)
cce74817
JM
7902@item
7903@emph{Boolean Literals} are defined by @code{TRUE} and @code{FALSE}.
7904@item
7905@emph{Character Literals} are defined by @code{'<character>'}. (e.g.
7906@code{'M'})
7907@item
7908@emph{Set Literals} are defined by a name which was specified in a set
d4f3574e 7909mode. The value delivered by a Set Literal is the set value. This is
b37052ae 7910comparable to an enumeration in C/C@t{++} language.
cce74817 7911@item
d4f3574e 7912@emph{Emptiness Literal} is predefined by @code{NULL}. The value of the
cce74817 7913emptiness literal delivers either the empty reference value, the empty
5d161b24 7914procedure value or the empty instance value.
cce74817
JM
7915
7916@item
7917@emph{Character String Literals} are defined by a sequence of characters
d4f3574e 7918enclosed in single- or double quotes. If a single- or double quote has
cce74817
JM
7919to be part of the string literal it has to be stuffed (specified twice).
7920@item
7921@emph{Bitstring Literals} are specified in the same manner as in Chill
7922programs (refer z200/88 chpt 5.2.4.8).
7923@item
7924@emph{Floating point literals} are specified in the same manner as in
d4f3574e 7925(gnu-)Chill programs (refer @sc{gnu} Chill implementation Manual chapter 1.5).
cce74817
JM
7926@end itemize
7927@end ignore
7928
7929@item Tuple Values
7930A tuple is specified by @code{<mode name>[<tuple>]}, where @code{<mode
d4f3574e 7931name>} can be omitted if the mode of the tuple is unambiguous. This
cce74817
JM
7932unambiguity is derived from the context of a evaluated expression.
7933@code{<tuple>} can be one of the following:
d4f3574e 7934
cce74817
JM
7935@itemize @bullet
7936@item @emph{Powerset Tuple}
7937@item @emph{Array Tuple}
7938@item @emph{Structure Tuple}
7939Powerset tuples, array tuples and structure tuples are specified in the
d4f3574e 7940same manner as in Chill programs refer to z200/88 chpt 5.2.5.
cce74817
JM
7941@end itemize
7942
7943@item String Element Value
6d2ebf8b
SS
7944A string element value is specified by
7945@smallexample
7946@code{<string value>(<index>)}
7947@end smallexample
d4f3574e 7948where @code{<index>} is a integer expression. It delivers a character
cce74817
JM
7949value which is equivalent to the character indexed by @code{<index>} in
7950the string.
7951
7952@item String Slice Value
7953A string slice value is specified by @code{<string value>(<slice
7954spec>)}, where @code{<slice spec>} can be either a range of integer
7955expressions or specified by @code{<start expr> up <size>}.
7956@code{<size>} denotes the number of elements which the slice contains.
7957The delivered value is a string value, which is part of the specified
7958string.
7959
7960@item Array Element Values
7961An array element value is specified by @code{<array value>(<expr>)} and
7962delivers a array element value of the mode of the specified array.
7963
7964@item Array Slice Values
7965An array slice is specified by @code{<array value>(<slice spec>)}, where
7966@code{<slice spec>} can be either a range specified by expressions or by
d4f3574e
SS
7967@code{<start expr> up <size>}. @code{<size>} denotes the number of
7968arrayelements the slice contains. The delivered value is an array value
cce74817
JM
7969which is part of the specified array.
7970
7971@item Structure Field Values
7972A structure field value is derived by @code{<structure value>.<field
d4f3574e
SS
7973name>}, where @code{<field name>} indicates the name of a field specified
7974in the mode definition of the structure. The mode of the delivered value
cce74817
JM
7975corresponds to this mode definition in the structure definition.
7976
7977@item Procedure Call Value
7978The procedure call value is derived from the return value of the
7979procedure@footnote{If a procedure call is used for instance in an
7980expression, then this procedure is called with all its side
d4f3574e 7981effects. This can lead to confusing results if used carelessly.}.
cce74817 7982
d4f3574e 7983Values of duration mode locations are represented by @code{ULONG} literals.
cce74817 7984
6d2ebf8b
SS
7985Values of time mode locations appear as
7986@smallexample
7987@code{TIME(<secs>:<nsecs>)}
7988@end smallexample
7989
cce74817
JM
7990
7991@ignore
7992This is not implemented yet:
7993@item Built-in Value
7994@noindent
7995The following built in functions are provided:
d4f3574e 7996
cce74817
JM
7997@table @code
7998@item @code{ADDR()}
7999@item @code{NUM()}
8000@item @code{PRED()}
8001@item @code{SUCC()}
8002@item @code{ABS()}
8003@item @code{CARD()}
8004@item @code{MAX()}
8005@item @code{MIN()}
8006@item @code{SIZE()}
8007@item @code{UPPER()}
8008@item @code{LOWER()}
8009@item @code{LENGTH()}
8010@item @code{SIN()}
8011@item @code{COS()}
8012@item @code{TAN()}
8013@item @code{ARCSIN()}
8014@item @code{ARCCOS()}
8015@item @code{ARCTAN()}
8016@item @code{EXP()}
8017@item @code{LN()}
8018@item @code{LOG()}
8019@item @code{SQRT()}
8020@end table
8021
8022For a detailed description refer to the GNU Chill implementation manual
8023chapter 1.6.
8024@end ignore
8025
8026@item Zero-adic Operator Value
8027The zero-adic operator value is derived from the instance value for the
8028current active process.
8029
8030@item Expression Values
8031The value delivered by an expression is the result of the evaluation of
d4f3574e 8032the specified expression. If there are error conditions (mode
cce74817 8033incompatibility, etc.) the evaluation of expressions is aborted with a
d4f3574e 8034corresponding error message. Expressions may be parenthesised which
cce74817 8035causes the evaluation of this expression before any other expression
d4f3574e 8036which uses the result of the parenthesised expression. The following
cce74817 8037operators are supported by @value{GDBN}:
d4f3574e 8038
cce74817
JM
8039@table @code
8040@item @code{OR, ORIF, XOR}
d4f3574e
SS
8041@itemx @code{AND, ANDIF}
8042@itemx @code{NOT}
cce74817 8043Logical operators defined over operands of boolean mode.
d4f3574e 8044
cce74817
JM
8045@item @code{=, /=}
8046Equality and inequality operators defined over all modes.
d4f3574e 8047
cce74817 8048@item @code{>, >=}
d4f3574e 8049@itemx @code{<, <=}
cce74817 8050Relational operators defined over predefined modes.
d4f3574e 8051
cce74817 8052@item @code{+, -}
d4f3574e 8053@itemx @code{*, /, MOD, REM}
cce74817 8054Arithmetic operators defined over predefined modes.
d4f3574e 8055
cce74817
JM
8056@item @code{-}
8057Change sign operator.
d4f3574e 8058
cce74817
JM
8059@item @code{//}
8060String concatenation operator.
d4f3574e 8061
cce74817
JM
8062@item @code{()}
8063String repetition operator.
d4f3574e 8064
cce74817
JM
8065@item @code{->}
8066Referenced location operator which can be used either to take the
8067address of a location (@code{->loc}), or to dereference a reference
8068location (@code{loc->}).
d4f3574e 8069
cce74817 8070@item @code{OR, XOR}
d4f3574e
SS
8071@itemx @code{AND}
8072@itemx @code{NOT}
cce74817 8073Powerset and bitstring operators.
d4f3574e 8074
cce74817 8075@item @code{>, >=}
d4f3574e 8076@itemx @code{<, <=}
cce74817 8077Powerset inclusion operators.
d4f3574e 8078
cce74817
JM
8079@item @code{IN}
8080Membership operator.
8081@end table
8082@end table
8083
6d2ebf8b 8084@node Chill type and range checks
cce74817
JM
8085@subsubsection Chill type and range checks
8086
8087@value{GDBN} considers two Chill variables mode equivalent if the sizes
d4f3574e 8088of the two modes are equal. This rule applies recursively to more
cce74817 8089complex datatypes which means that complex modes are treated
d4f3574e 8090equivalent if all element modes (which also can be complex modes like
cce74817
JM
8091structures, arrays, etc.) have the same size.
8092
8093Range checking is done on all mathematical operations, assignment, array
8094index bounds and all built in procedures.
8095
8096Strong type checks are forced using the @value{GDBN} command @code{set
d4f3574e 8097check strong}. This enforces strong type and range checks on all
cce74817
JM
8098operations where Chill constructs are used (expressions, built in
8099functions, etc.) in respect to the semantics as defined in the z.200
8100language specification.
8101
cce74817
JM
8102All checks can be disabled by the @value{GDBN} command @code{set check
8103off}.
8104
5d161b24 8105@ignore
53a5351d 8106@c Deviations from the Chill Standard Z200/88
cce74817
JM
8107see last paragraph ?
8108@end ignore
8109
6d2ebf8b 8110@node Chill defaults
cce74817
JM
8111@subsubsection Chill defaults
8112
8113If type and range checking are set automatically by @value{GDBN}, they
8114both default to @code{on} whenever the working language changes to
d4f3574e 8115Chill. This happens regardless of whether you or @value{GDBN}
cce74817
JM
8116selected the working language.
8117
8118If you allow @value{GDBN} to set the language automatically, then entering
8119code compiled from a file whose name ends with @file{.ch} sets the
d4f3574e 8120working language to Chill. @xref{Automatically, ,Having @value{GDBN} set
cce74817
JM
8121the language automatically}, for further details.
8122
6d2ebf8b 8123@node Symbols
c906108c
SS
8124@chapter Examining the Symbol Table
8125
d4f3574e 8126The commands described in this chapter allow you to inquire about the
c906108c
SS
8127symbols (names of variables, functions and types) defined in your
8128program. This information is inherent in the text of your program and
8129does not change as your program executes. @value{GDBN} finds it in your
8130program's symbol table, in the file indicated when you started @value{GDBN}
8131(@pxref{File Options, ,Choosing files}), or by one of the
8132file-management commands (@pxref{Files, ,Commands to specify files}).
8133
8134@cindex symbol names
8135@cindex names of symbols
8136@cindex quoting names
8137Occasionally, you may need to refer to symbols that contain unusual
8138characters, which @value{GDBN} ordinarily treats as word delimiters. The
8139most frequent case is in referring to static variables in other
8140source files (@pxref{Variables,,Program variables}). File names
8141are recorded in object files as debugging symbols, but @value{GDBN} would
8142ordinarily parse a typical file name, like @file{foo.c}, as the three words
8143@samp{foo} @samp{.} @samp{c}. To allow @value{GDBN} to recognize
8144@samp{foo.c} as a single symbol, enclose it in single quotes; for example,
8145
8146@example
8147p 'foo.c'::x
8148@end example
8149
8150@noindent
8151looks up the value of @code{x} in the scope of the file @file{foo.c}.
8152
8153@table @code
8154@kindex info address
b37052ae 8155@cindex address of a symbol
c906108c
SS
8156@item info address @var{symbol}
8157Describe where the data for @var{symbol} is stored. For a register
8158variable, this says which register it is kept in. For a non-register
8159local variable, this prints the stack-frame offset at which the variable
8160is always stored.
8161
8162Note the contrast with @samp{print &@var{symbol}}, which does not work
8163at all for a register variable, and for a stack local variable prints
8164the exact address of the current instantiation of the variable.
8165
3d67e040 8166@kindex info symbol
b37052ae 8167@cindex symbol from address
3d67e040
EZ
8168@item info symbol @var{addr}
8169Print the name of a symbol which is stored at the address @var{addr}.
8170If no symbol is stored exactly at @var{addr}, @value{GDBN} prints the
8171nearest symbol and an offset from it:
8172
8173@example
8174(@value{GDBP}) info symbol 0x54320
8175_initialize_vx + 396 in section .text
8176@end example
8177
8178@noindent
8179This is the opposite of the @code{info address} command. You can use
8180it to find out the name of a variable or a function given its address.
8181
c906108c 8182@kindex whatis
d4f3574e
SS
8183@item whatis @var{expr}
8184Print the data type of expression @var{expr}. @var{expr} is not
c906108c
SS
8185actually evaluated, and any side-effecting operations (such as
8186assignments or function calls) inside it do not take place.
8187@xref{Expressions, ,Expressions}.
8188
8189@item whatis
8190Print the data type of @code{$}, the last value in the value history.
8191
8192@kindex ptype
8193@item ptype @var{typename}
8194Print a description of data type @var{typename}. @var{typename} may be
7a292a7a
SS
8195the name of a type, or for C code it may have the form @samp{class
8196@var{class-name}}, @samp{struct @var{struct-tag}}, @samp{union
8197@var{union-tag}} or @samp{enum @var{enum-tag}}.
c906108c 8198
d4f3574e 8199@item ptype @var{expr}
c906108c 8200@itemx ptype
d4f3574e 8201Print a description of the type of expression @var{expr}. @code{ptype}
c906108c
SS
8202differs from @code{whatis} by printing a detailed description, instead
8203of just the name of the type.
8204
8205For example, for this variable declaration:
8206
8207@example
8208struct complex @{double real; double imag;@} v;
8209@end example
8210
8211@noindent
8212the two commands give this output:
8213
8214@example
8215@group
8216(@value{GDBP}) whatis v
8217type = struct complex
8218(@value{GDBP}) ptype v
8219type = struct complex @{
8220 double real;
8221 double imag;
8222@}
8223@end group
8224@end example
8225
8226@noindent
8227As with @code{whatis}, using @code{ptype} without an argument refers to
8228the type of @code{$}, the last value in the value history.
8229
8230@kindex info types
8231@item info types @var{regexp}
8232@itemx info types
d4f3574e 8233Print a brief description of all types whose names match @var{regexp}
c906108c
SS
8234(or all types in your program, if you supply no argument). Each
8235complete typename is matched as though it were a complete line; thus,
8236@samp{i type value} gives information on all types in your program whose
d4f3574e 8237names include the string @code{value}, but @samp{i type ^value$} gives
c906108c
SS
8238information only on types whose complete name is @code{value}.
8239
8240This command differs from @code{ptype} in two ways: first, like
8241@code{whatis}, it does not print a detailed description; second, it
8242lists all source files where a type is defined.
8243
b37052ae
EZ
8244@kindex info scope
8245@cindex local variables
8246@item info scope @var{addr}
8247List all the variables local to a particular scope. This command
8248accepts a location---a function name, a source line, or an address
8249preceded by a @samp{*}, and prints all the variables local to the
8250scope defined by that location. For example:
8251
8252@smallexample
8253(@value{GDBP}) @b{info scope command_line_handler}
8254Scope for command_line_handler:
8255Symbol rl is an argument at stack/frame offset 8, length 4.
8256Symbol linebuffer is in static storage at address 0x150a18, length 4.
8257Symbol linelength is in static storage at address 0x150a1c, length 4.
8258Symbol p is a local variable in register $esi, length 4.
8259Symbol p1 is a local variable in register $ebx, length 4.
8260Symbol nline is a local variable in register $edx, length 4.
8261Symbol repeat is a local variable at frame offset -8, length 4.
8262@end smallexample
8263
f5c37c66
EZ
8264@noindent
8265This command is especially useful for determining what data to collect
8266during a @dfn{trace experiment}, see @ref{Tracepoint Actions,
8267collect}.
8268
c906108c
SS
8269@kindex info source
8270@item info source
8271Show the name of the current source file---that is, the source file for
8272the function containing the current point of execution---and the language
8273it was written in.
8274
8275@kindex info sources
8276@item info sources
8277Print the names of all source files in your program for which there is
8278debugging information, organized into two lists: files whose symbols
8279have already been read, and files whose symbols will be read when needed.
8280
8281@kindex info functions
8282@item info functions
8283Print the names and data types of all defined functions.
8284
8285@item info functions @var{regexp}
8286Print the names and data types of all defined functions
8287whose names contain a match for regular expression @var{regexp}.
8288Thus, @samp{info fun step} finds all functions whose names
8289include @code{step}; @samp{info fun ^step} finds those whose names
8290start with @code{step}.
8291
8292@kindex info variables
8293@item info variables
8294Print the names and data types of all variables that are declared
8295outside of functions (i.e., excluding local variables).
8296
8297@item info variables @var{regexp}
8298Print the names and data types of all variables (except for local
8299variables) whose names contain a match for regular expression
8300@var{regexp}.
8301
8302@ignore
8303This was never implemented.
8304@kindex info methods
8305@item info methods
8306@itemx info methods @var{regexp}
8307The @code{info methods} command permits the user to examine all defined
b37052ae
EZ
8308methods within C@t{++} program, or (with the @var{regexp} argument) a
8309specific set of methods found in the various C@t{++} classes. Many
8310C@t{++} classes provide a large number of methods. Thus, the output
c906108c
SS
8311from the @code{ptype} command can be overwhelming and hard to use. The
8312@code{info-methods} command filters the methods, printing only those
8313which match the regular-expression @var{regexp}.
8314@end ignore
8315
c906108c
SS
8316@cindex reloading symbols
8317Some systems allow individual object files that make up your program to
7a292a7a
SS
8318be replaced without stopping and restarting your program. For example,
8319in VxWorks you can simply recompile a defective object file and keep on
8320running. If you are running on one of these systems, you can allow
8321@value{GDBN} to reload the symbols for automatically relinked modules:
c906108c
SS
8322
8323@table @code
8324@kindex set symbol-reloading
8325@item set symbol-reloading on
8326Replace symbol definitions for the corresponding source file when an
8327object file with a particular name is seen again.
8328
8329@item set symbol-reloading off
6d2ebf8b
SS
8330Do not replace symbol definitions when encountering object files of the
8331same name more than once. This is the default state; if you are not
8332running on a system that permits automatic relinking of modules, you
8333should leave @code{symbol-reloading} off, since otherwise @value{GDBN}
8334may discard symbols when linking large programs, that may contain
8335several modules (from different directories or libraries) with the same
8336name.
c906108c
SS
8337
8338@kindex show symbol-reloading
8339@item show symbol-reloading
8340Show the current @code{on} or @code{off} setting.
8341@end table
c906108c 8342
c906108c
SS
8343@kindex set opaque-type-resolution
8344@item set opaque-type-resolution on
8345Tell @value{GDBN} to resolve opaque types. An opaque type is a type
8346declared as a pointer to a @code{struct}, @code{class}, or
8347@code{union}---for example, @code{struct MyType *}---that is used in one
8348source file although the full declaration of @code{struct MyType} is in
8349another source file. The default is on.
8350
8351A change in the setting of this subcommand will not take effect until
8352the next time symbols for a file are loaded.
8353
8354@item set opaque-type-resolution off
8355Tell @value{GDBN} not to resolve opaque types. In this case, the type
8356is printed as follows:
8357@smallexample
8358@{<no data fields>@}
8359@end smallexample
8360
8361@kindex show opaque-type-resolution
8362@item show opaque-type-resolution
8363Show whether opaque types are resolved or not.
c906108c
SS
8364
8365@kindex maint print symbols
8366@cindex symbol dump
8367@kindex maint print psymbols
8368@cindex partial symbol dump
8369@item maint print symbols @var{filename}
8370@itemx maint print psymbols @var{filename}
8371@itemx maint print msymbols @var{filename}
8372Write a dump of debugging symbol data into the file @var{filename}.
8373These commands are used to debug the @value{GDBN} symbol-reading code. Only
8374symbols with debugging data are included. If you use @samp{maint print
8375symbols}, @value{GDBN} includes all the symbols for which it has already
8376collected full details: that is, @var{filename} reflects symbols for
8377only those files whose symbols @value{GDBN} has read. You can use the
8378command @code{info sources} to find out which files these are. If you
8379use @samp{maint print psymbols} instead, the dump shows information about
8380symbols that @value{GDBN} only knows partially---that is, symbols defined in
8381files that @value{GDBN} has skimmed, but not yet read completely. Finally,
8382@samp{maint print msymbols} dumps just the minimal symbol information
8383required for each object file from which @value{GDBN} has read some symbols.
8384@xref{Files, ,Commands to specify files}, for a discussion of how
8385@value{GDBN} reads symbols (in the description of @code{symbol-file}).
8386@end table
8387
6d2ebf8b 8388@node Altering
c906108c
SS
8389@chapter Altering Execution
8390
8391Once you think you have found an error in your program, you might want to
8392find out for certain whether correcting the apparent error would lead to
8393correct results in the rest of the run. You can find the answer by
8394experiment, using the @value{GDBN} features for altering execution of the
8395program.
8396
8397For example, you can store new values into variables or memory
7a292a7a
SS
8398locations, give your program a signal, restart it at a different
8399address, or even return prematurely from a function.
c906108c
SS
8400
8401@menu
8402* Assignment:: Assignment to variables
8403* Jumping:: Continuing at a different address
c906108c 8404* Signaling:: Giving your program a signal
c906108c
SS
8405* Returning:: Returning from a function
8406* Calling:: Calling your program's functions
8407* Patching:: Patching your program
8408@end menu
8409
6d2ebf8b 8410@node Assignment
c906108c
SS
8411@section Assignment to variables
8412
8413@cindex assignment
8414@cindex setting variables
8415To alter the value of a variable, evaluate an assignment expression.
8416@xref{Expressions, ,Expressions}. For example,
8417
8418@example
8419print x=4
8420@end example
8421
8422@noindent
8423stores the value 4 into the variable @code{x}, and then prints the
5d161b24 8424value of the assignment expression (which is 4).
c906108c
SS
8425@xref{Languages, ,Using @value{GDBN} with Different Languages}, for more
8426information on operators in supported languages.
c906108c
SS
8427
8428@kindex set variable
8429@cindex variables, setting
8430If you are not interested in seeing the value of the assignment, use the
8431@code{set} command instead of the @code{print} command. @code{set} is
8432really the same as @code{print} except that the expression's value is
8433not printed and is not put in the value history (@pxref{Value History,
8434,Value history}). The expression is evaluated only for its effects.
8435
c906108c
SS
8436If the beginning of the argument string of the @code{set} command
8437appears identical to a @code{set} subcommand, use the @code{set
8438variable} command instead of just @code{set}. This command is identical
8439to @code{set} except for its lack of subcommands. For example, if your
8440program has a variable @code{width}, you get an error if you try to set
8441a new value with just @samp{set width=13}, because @value{GDBN} has the
8442command @code{set width}:
8443
8444@example
8445(@value{GDBP}) whatis width
8446type = double
8447(@value{GDBP}) p width
8448$4 = 13
8449(@value{GDBP}) set width=47
8450Invalid syntax in expression.
8451@end example
8452
8453@noindent
8454The invalid expression, of course, is @samp{=47}. In
8455order to actually set the program's variable @code{width}, use
8456
8457@example
8458(@value{GDBP}) set var width=47
8459@end example
53a5351d 8460
c906108c
SS
8461Because the @code{set} command has many subcommands that can conflict
8462with the names of program variables, it is a good idea to use the
8463@code{set variable} command instead of just @code{set}. For example, if
8464your program has a variable @code{g}, you run into problems if you try
8465to set a new value with just @samp{set g=4}, because @value{GDBN} has
8466the command @code{set gnutarget}, abbreviated @code{set g}:
8467
8468@example
8469@group
8470(@value{GDBP}) whatis g
8471type = double
8472(@value{GDBP}) p g
8473$1 = 1
8474(@value{GDBP}) set g=4
2df3850c 8475(@value{GDBP}) p g
c906108c
SS
8476$2 = 1
8477(@value{GDBP}) r
8478The program being debugged has been started already.
8479Start it from the beginning? (y or n) y
8480Starting program: /home/smith/cc_progs/a.out
6d2ebf8b
SS
8481"/home/smith/cc_progs/a.out": can't open to read symbols:
8482 Invalid bfd target.
c906108c
SS
8483(@value{GDBP}) show g
8484The current BFD target is "=4".
8485@end group
8486@end example
8487
8488@noindent
8489The program variable @code{g} did not change, and you silently set the
8490@code{gnutarget} to an invalid value. In order to set the variable
8491@code{g}, use
8492
8493@example
8494(@value{GDBP}) set var g=4
8495@end example
c906108c
SS
8496
8497@value{GDBN} allows more implicit conversions in assignments than C; you can
8498freely store an integer value into a pointer variable or vice versa,
8499and you can convert any structure to any other structure that is the
8500same length or shorter.
8501@comment FIXME: how do structs align/pad in these conversions?
8502@comment /doc@cygnus.com 18dec1990
8503
8504To store values into arbitrary places in memory, use the @samp{@{@dots{}@}}
8505construct to generate a value of specified type at a specified address
8506(@pxref{Expressions, ,Expressions}). For example, @code{@{int@}0x83040} refers
8507to memory location @code{0x83040} as an integer (which implies a certain size
8508and representation in memory), and
8509
8510@example
8511set @{int@}0x83040 = 4
8512@end example
8513
8514@noindent
8515stores the value 4 into that memory location.
8516
6d2ebf8b 8517@node Jumping
c906108c
SS
8518@section Continuing at a different address
8519
8520Ordinarily, when you continue your program, you do so at the place where
8521it stopped, with the @code{continue} command. You can instead continue at
8522an address of your own choosing, with the following commands:
8523
8524@table @code
8525@kindex jump
8526@item jump @var{linespec}
8527Resume execution at line @var{linespec}. Execution stops again
8528immediately if there is a breakpoint there. @xref{List, ,Printing
8529source lines}, for a description of the different forms of
8530@var{linespec}. It is common practice to use the @code{tbreak} command
8531in conjunction with @code{jump}. @xref{Set Breaks, ,Setting
8532breakpoints}.
8533
8534The @code{jump} command does not change the current stack frame, or
8535the stack pointer, or the contents of any memory location or any
8536register other than the program counter. If line @var{linespec} is in
8537a different function from the one currently executing, the results may
8538be bizarre if the two functions expect different patterns of arguments or
8539of local variables. For this reason, the @code{jump} command requests
8540confirmation if the specified line is not in the function currently
8541executing. However, even bizarre results are predictable if you are
8542well acquainted with the machine-language code of your program.
8543
8544@item jump *@var{address}
8545Resume execution at the instruction at address @var{address}.
8546@end table
8547
c906108c 8548@c Doesn't work on HP-UX; have to set $pcoqh and $pcoqt.
53a5351d
JM
8549On many systems, you can get much the same effect as the @code{jump}
8550command by storing a new value into the register @code{$pc}. The
8551difference is that this does not start your program running; it only
8552changes the address of where it @emph{will} run when you continue. For
8553example,
c906108c
SS
8554
8555@example
8556set $pc = 0x485
8557@end example
8558
8559@noindent
8560makes the next @code{continue} command or stepping command execute at
8561address @code{0x485}, rather than at the address where your program stopped.
8562@xref{Continuing and Stepping, ,Continuing and stepping}.
c906108c
SS
8563
8564The most common occasion to use the @code{jump} command is to back
8565up---perhaps with more breakpoints set---over a portion of a program
8566that has already executed, in order to examine its execution in more
8567detail.
8568
c906108c 8569@c @group
6d2ebf8b 8570@node Signaling
c906108c
SS
8571@section Giving your program a signal
8572
8573@table @code
8574@kindex signal
8575@item signal @var{signal}
8576Resume execution where your program stopped, but immediately give it the
8577signal @var{signal}. @var{signal} can be the name or the number of a
8578signal. For example, on many systems @code{signal 2} and @code{signal
8579SIGINT} are both ways of sending an interrupt signal.
8580
8581Alternatively, if @var{signal} is zero, continue execution without
8582giving a signal. This is useful when your program stopped on account of
8583a signal and would ordinary see the signal when resumed with the
8584@code{continue} command; @samp{signal 0} causes it to resume without a
8585signal.
8586
8587@code{signal} does not repeat when you press @key{RET} a second time
8588after executing the command.
8589@end table
8590@c @end group
8591
8592Invoking the @code{signal} command is not the same as invoking the
8593@code{kill} utility from the shell. Sending a signal with @code{kill}
8594causes @value{GDBN} to decide what to do with the signal depending on
8595the signal handling tables (@pxref{Signals}). The @code{signal} command
8596passes the signal directly to your program.
8597
c906108c 8598
6d2ebf8b 8599@node Returning
c906108c
SS
8600@section Returning from a function
8601
8602@table @code
8603@cindex returning from a function
8604@kindex return
8605@item return
8606@itemx return @var{expression}
8607You can cancel execution of a function call with the @code{return}
8608command. If you give an
8609@var{expression} argument, its value is used as the function's return
8610value.
8611@end table
8612
8613When you use @code{return}, @value{GDBN} discards the selected stack frame
8614(and all frames within it). You can think of this as making the
8615discarded frame return prematurely. If you wish to specify a value to
8616be returned, give that value as the argument to @code{return}.
8617
8618This pops the selected stack frame (@pxref{Selection, ,Selecting a
8619frame}), and any other frames inside of it, leaving its caller as the
8620innermost remaining frame. That frame becomes selected. The
8621specified value is stored in the registers used for returning values
8622of functions.
8623
8624The @code{return} command does not resume execution; it leaves the
8625program stopped in the state that would exist if the function had just
8626returned. In contrast, the @code{finish} command (@pxref{Continuing
8627and Stepping, ,Continuing and stepping}) resumes execution until the
8628selected stack frame returns naturally.
8629
6d2ebf8b 8630@node Calling
c906108c
SS
8631@section Calling program functions
8632
8633@cindex calling functions
8634@kindex call
8635@table @code
8636@item call @var{expr}
8637Evaluate the expression @var{expr} without displaying @code{void}
8638returned values.
8639@end table
8640
8641You can use this variant of the @code{print} command if you want to
8642execute a function from your program, but without cluttering the output
5d161b24
DB
8643with @code{void} returned values. If the result is not void, it
8644is printed and saved in the value history.
c906108c 8645
c906108c
SS
8646For the A29K, a user-controlled variable @code{call_scratch_address},
8647specifies the location of a scratch area to be used when @value{GDBN}
8648calls a function in the target. This is necessary because the usual
8649method of putting the scratch area on the stack does not work in systems
8650that have separate instruction and data spaces.
c906108c 8651
6d2ebf8b 8652@node Patching
c906108c 8653@section Patching programs
7a292a7a 8654
c906108c
SS
8655@cindex patching binaries
8656@cindex writing into executables
c906108c 8657@cindex writing into corefiles
c906108c 8658
7a292a7a
SS
8659By default, @value{GDBN} opens the file containing your program's
8660executable code (or the corefile) read-only. This prevents accidental
8661alterations to machine code; but it also prevents you from intentionally
8662patching your program's binary.
c906108c
SS
8663
8664If you'd like to be able to patch the binary, you can specify that
8665explicitly with the @code{set write} command. For example, you might
8666want to turn on internal debugging flags, or even to make emergency
8667repairs.
8668
8669@table @code
8670@kindex set write
8671@item set write on
8672@itemx set write off
7a292a7a
SS
8673If you specify @samp{set write on}, @value{GDBN} opens executable and
8674core files for both reading and writing; if you specify @samp{set write
c906108c
SS
8675off} (the default), @value{GDBN} opens them read-only.
8676
8677If you have already loaded a file, you must load it again (using the
7a292a7a
SS
8678@code{exec-file} or @code{core-file} command) after changing @code{set
8679write}, for your new setting to take effect.
c906108c
SS
8680
8681@item show write
8682@kindex show write
7a292a7a
SS
8683Display whether executable files and core files are opened for writing
8684as well as reading.
c906108c
SS
8685@end table
8686
6d2ebf8b 8687@node GDB Files
c906108c
SS
8688@chapter @value{GDBN} Files
8689
7a292a7a
SS
8690@value{GDBN} needs to know the file name of the program to be debugged,
8691both in order to read its symbol table and in order to start your
8692program. To debug a core dump of a previous run, you must also tell
8693@value{GDBN} the name of the core dump file.
c906108c
SS
8694
8695@menu
8696* Files:: Commands to specify files
8697* Symbol Errors:: Errors reading symbol files
8698@end menu
8699
6d2ebf8b 8700@node Files
c906108c 8701@section Commands to specify files
c906108c 8702
7a292a7a 8703@cindex symbol table
c906108c 8704@cindex core dump file
7a292a7a
SS
8705
8706You may want to specify executable and core dump file names. The usual
8707way to do this is at start-up time, using the arguments to
8708@value{GDBN}'s start-up commands (@pxref{Invocation, , Getting In and
8709Out of @value{GDBN}}).
c906108c
SS
8710
8711Occasionally it is necessary to change to a different file during a
8712@value{GDBN} session. Or you may run @value{GDBN} and forget to specify
8713a file you want to use. In these situations the @value{GDBN} commands
8714to specify new files are useful.
8715
8716@table @code
8717@cindex executable file
8718@kindex file
8719@item file @var{filename}
8720Use @var{filename} as the program to be debugged. It is read for its
8721symbols and for the contents of pure memory. It is also the program
8722executed when you use the @code{run} command. If you do not specify a
5d161b24
DB
8723directory and the file is not found in the @value{GDBN} working directory,
8724@value{GDBN} uses the environment variable @code{PATH} as a list of
8725directories to search, just as the shell does when looking for a program
8726to run. You can change the value of this variable, for both @value{GDBN}
c906108c
SS
8727and your program, using the @code{path} command.
8728
6d2ebf8b 8729On systems with memory-mapped files, an auxiliary file named
c906108c
SS
8730@file{@var{filename}.syms} may hold symbol table information for
8731@var{filename}. If so, @value{GDBN} maps in the symbol table from
8732@file{@var{filename}.syms}, starting up more quickly. See the
8733descriptions of the file options @samp{-mapped} and @samp{-readnow}
8734(available on the command line, and with the commands @code{file},
5d161b24 8735@code{symbol-file}, or @code{add-symbol-file}, described below),
c906108c 8736for more information.
c906108c
SS
8737
8738@item file
8739@code{file} with no argument makes @value{GDBN} discard any information it
8740has on both executable file and the symbol table.
8741
8742@kindex exec-file
8743@item exec-file @r{[} @var{filename} @r{]}
8744Specify that the program to be run (but not the symbol table) is found
8745in @var{filename}. @value{GDBN} searches the environment variable @code{PATH}
8746if necessary to locate your program. Omitting @var{filename} means to
8747discard information on the executable file.
8748
8749@kindex symbol-file
8750@item symbol-file @r{[} @var{filename} @r{]}
8751Read symbol table information from file @var{filename}. @code{PATH} is
8752searched when necessary. Use the @code{file} command to get both symbol
8753table and program to run from the same file.
8754
8755@code{symbol-file} with no argument clears out @value{GDBN} information on your
8756program's symbol table.
8757
5d161b24 8758The @code{symbol-file} command causes @value{GDBN} to forget the contents
c906108c
SS
8759of its convenience variables, the value history, and all breakpoints and
8760auto-display expressions. This is because they may contain pointers to
8761the internal data recording symbols and data types, which are part of
8762the old symbol table data being discarded inside @value{GDBN}.
8763
8764@code{symbol-file} does not repeat if you press @key{RET} again after
8765executing it once.
8766
8767When @value{GDBN} is configured for a particular environment, it
8768understands debugging information in whatever format is the standard
8769generated for that environment; you may use either a @sc{gnu} compiler, or
8770other compilers that adhere to the local conventions.
c906108c
SS
8771Best results are usually obtained from @sc{gnu} compilers; for example,
8772using @code{@value{GCC}} you can generate debugging information for
8773optimized code.
c906108c
SS
8774
8775For most kinds of object files, with the exception of old SVR3 systems
8776using COFF, the @code{symbol-file} command does not normally read the
8777symbol table in full right away. Instead, it scans the symbol table
8778quickly to find which source files and which symbols are present. The
8779details are read later, one source file at a time, as they are needed.
8780
8781The purpose of this two-stage reading strategy is to make @value{GDBN}
8782start up faster. For the most part, it is invisible except for
8783occasional pauses while the symbol table details for a particular source
8784file are being read. (The @code{set verbose} command can turn these
8785pauses into messages if desired. @xref{Messages/Warnings, ,Optional
8786warnings and messages}.)
8787
c906108c
SS
8788We have not implemented the two-stage strategy for COFF yet. When the
8789symbol table is stored in COFF format, @code{symbol-file} reads the
8790symbol table data in full right away. Note that ``stabs-in-COFF''
8791still does the two-stage strategy, since the debug info is actually
8792in stabs format.
8793
8794@kindex readnow
8795@cindex reading symbols immediately
8796@cindex symbols, reading immediately
8797@kindex mapped
8798@cindex memory-mapped symbol file
8799@cindex saving symbol table
8800@item symbol-file @var{filename} @r{[} -readnow @r{]} @r{[} -mapped @r{]}
8801@itemx file @var{filename} @r{[} -readnow @r{]} @r{[} -mapped @r{]}
8802You can override the @value{GDBN} two-stage strategy for reading symbol
8803tables by using the @samp{-readnow} option with any of the commands that
8804load symbol table information, if you want to be sure @value{GDBN} has the
5d161b24 8805entire symbol table available.
c906108c 8806
c906108c
SS
8807If memory-mapped files are available on your system through the
8808@code{mmap} system call, you can use another option, @samp{-mapped}, to
8809cause @value{GDBN} to write the symbols for your program into a reusable
8810file. Future @value{GDBN} debugging sessions map in symbol information
8811from this auxiliary symbol file (if the program has not changed), rather
8812than spending time reading the symbol table from the executable
8813program. Using the @samp{-mapped} option has the same effect as
8814starting @value{GDBN} with the @samp{-mapped} command-line option.
8815
8816You can use both options together, to make sure the auxiliary symbol
8817file has all the symbol information for your program.
8818
8819The auxiliary symbol file for a program called @var{myprog} is called
8820@samp{@var{myprog}.syms}. Once this file exists (so long as it is newer
8821than the corresponding executable), @value{GDBN} always attempts to use
8822it when you debug @var{myprog}; no special options or commands are
8823needed.
8824
8825The @file{.syms} file is specific to the host machine where you run
8826@value{GDBN}. It holds an exact image of the internal @value{GDBN}
8827symbol table. It cannot be shared across multiple host platforms.
c906108c
SS
8828
8829@c FIXME: for now no mention of directories, since this seems to be in
8830@c flux. 13mar1992 status is that in theory GDB would look either in
8831@c current dir or in same dir as myprog; but issues like competing
8832@c GDB's, or clutter in system dirs, mean that in practice right now
8833@c only current dir is used. FFish says maybe a special GDB hierarchy
8834@c (eg rooted in val of env var GDBSYMS) could exist for mappable symbol
8835@c files.
8836
8837@kindex core
8838@kindex core-file
8839@item core-file @r{[} @var{filename} @r{]}
8840Specify the whereabouts of a core dump file to be used as the ``contents
8841of memory''. Traditionally, core files contain only some parts of the
8842address space of the process that generated them; @value{GDBN} can access the
8843executable file itself for other parts.
8844
8845@code{core-file} with no argument specifies that no core file is
8846to be used.
8847
8848Note that the core file is ignored when your program is actually running
7a292a7a
SS
8849under @value{GDBN}. So, if you have been running your program and you
8850wish to debug a core file instead, you must kill the subprocess in which
8851the program is running. To do this, use the @code{kill} command
c906108c 8852(@pxref{Kill Process, ,Killing the child process}).
c906108c 8853
c906108c
SS
8854@kindex add-symbol-file
8855@cindex dynamic linking
8856@item add-symbol-file @var{filename} @var{address}
8857@itemx add-symbol-file @var{filename} @var{address} @r{[} -readnow @r{]} @r{[} -mapped @r{]}
d167840f 8858@itemx add-symbol-file @var{filename} @r{-s}@var{section} @var{address}
96a2c332
SS
8859The @code{add-symbol-file} command reads additional symbol table
8860information from the file @var{filename}. You would use this command
8861when @var{filename} has been dynamically loaded (by some other means)
8862into the program that is running. @var{address} should be the memory
8863address at which the file has been loaded; @value{GDBN} cannot figure
d167840f
EZ
8864this out for itself. You can additionally specify an arbitrary number
8865of @samp{@r{-s}@var{section} @var{address}} pairs, to give an explicit
8866section name and base address for that section. You can specify any
8867@var{address} as an expression.
c906108c
SS
8868
8869The symbol table of the file @var{filename} is added to the symbol table
8870originally read with the @code{symbol-file} command. You can use the
96a2c332
SS
8871@code{add-symbol-file} command any number of times; the new symbol data
8872thus read keeps adding to the old. To discard all old symbol data
8873instead, use the @code{symbol-file} command without any arguments.
c906108c
SS
8874
8875@code{add-symbol-file} does not repeat if you press @key{RET} after using it.
8876
8877You can use the @samp{-mapped} and @samp{-readnow} options just as with
8878the @code{symbol-file} command, to change how @value{GDBN} manages the symbol
8879table information for @var{filename}.
8880
8881@kindex add-shared-symbol-file
8882@item add-shared-symbol-file
8883The @code{add-shared-symbol-file} command can be used only under Harris' CXUX
5d161b24
DB
8884operating system for the Motorola 88k. @value{GDBN} automatically looks for
8885shared libraries, however if @value{GDBN} does not find yours, you can run
c906108c 8886@code{add-shared-symbol-file}. It takes no arguments.
c906108c 8887
c906108c
SS
8888@kindex section
8889@item section
5d161b24
DB
8890The @code{section} command changes the base address of section SECTION of
8891the exec file to ADDR. This can be used if the exec file does not contain
8892section addresses, (such as in the a.out format), or when the addresses
8893specified in the file itself are wrong. Each section must be changed
d4f3574e
SS
8894separately. The @code{info files} command, described below, lists all
8895the sections and their addresses.
c906108c
SS
8896
8897@kindex info files
8898@kindex info target
8899@item info files
8900@itemx info target
7a292a7a
SS
8901@code{info files} and @code{info target} are synonymous; both print the
8902current target (@pxref{Targets, ,Specifying a Debugging Target}),
8903including the names of the executable and core dump files currently in
8904use by @value{GDBN}, and the files from which symbols were loaded. The
8905command @code{help target} lists all possible targets rather than
8906current ones.
8907
c906108c
SS
8908@end table
8909
8910All file-specifying commands allow both absolute and relative file names
8911as arguments. @value{GDBN} always converts the file name to an absolute file
8912name and remembers it that way.
8913
c906108c 8914@cindex shared libraries
c906108c
SS
8915@value{GDBN} supports HP-UX, SunOS, SVr4, Irix 5, and IBM RS/6000 shared
8916libraries.
53a5351d 8917
c906108c
SS
8918@value{GDBN} automatically loads symbol definitions from shared libraries
8919when you use the @code{run} command, or when you examine a core file.
8920(Before you issue the @code{run} command, @value{GDBN} does not understand
8921references to a function in a shared library, however---unless you are
8922debugging a core file).
53a5351d
JM
8923
8924On HP-UX, if the program loads a library explicitly, @value{GDBN}
8925automatically loads the symbols at the time of the @code{shl_load} call.
8926
c906108c
SS
8927@c FIXME: some @value{GDBN} release may permit some refs to undef
8928@c FIXME...symbols---eg in a break cmd---assuming they are from a shared
8929@c FIXME...lib; check this from time to time when updating manual
8930
8931@table @code
8932@kindex info sharedlibrary
8933@kindex info share
8934@item info share
8935@itemx info sharedlibrary
8936Print the names of the shared libraries which are currently loaded.
8937
8938@kindex sharedlibrary
8939@kindex share
8940@item sharedlibrary @var{regex}
8941@itemx share @var{regex}
c906108c
SS
8942Load shared object library symbols for files matching a
8943Unix regular expression.
8944As with files loaded automatically, it only loads shared libraries
8945required by your program for a core file or after typing @code{run}. If
8946@var{regex} is omitted all shared libraries required by your program are
8947loaded.
8948@end table
8949
53a5351d
JM
8950On HP-UX systems, @value{GDBN} detects the loading of a shared library
8951and automatically reads in symbols from the newly loaded library, up to
8952a threshold that is initially set but that you can modify if you wish.
c906108c
SS
8953
8954Beyond that threshold, symbols from shared libraries must be explicitly
d4f3574e
SS
8955loaded. To load these symbols, use the command @code{sharedlibrary
8956@var{filename}}. The base address of the shared library is determined
c906108c
SS
8957automatically by @value{GDBN} and need not be specified.
8958
8959To display or set the threshold, use the commands:
8960
8961@table @code
8962@kindex set auto-solib-add
8963@item set auto-solib-add @var{threshold}
8964Set the autoloading size threshold, in megabytes. If @var{threshold} is
8965nonzero, symbols from all shared object libraries will be loaded
8966automatically when the inferior begins execution or when the dynamic
8967linker informs @value{GDBN} that a new library has been loaded, until
8968the symbol table of the program and libraries exceeds this threshold.
8969Otherwise, symbols must be loaded manually, using the
8970@code{sharedlibrary} command. The default threshold is 100 megabytes.
8971
8972@kindex show auto-solib-add
8973@item show auto-solib-add
8974Display the current autoloading size threshold, in megabytes.
8975@end table
c906108c 8976
6d2ebf8b 8977@node Symbol Errors
c906108c
SS
8978@section Errors reading symbol files
8979
8980While reading a symbol file, @value{GDBN} occasionally encounters problems,
8981such as symbol types it does not recognize, or known bugs in compiler
8982output. By default, @value{GDBN} does not notify you of such problems, since
8983they are relatively common and primarily of interest to people
8984debugging compilers. If you are interested in seeing information
8985about ill-constructed symbol tables, you can either ask @value{GDBN} to print
8986only one message about each such type of problem, no matter how many
8987times the problem occurs; or you can ask @value{GDBN} to print more messages,
8988to see how many times the problems occur, with the @code{set
8989complaints} command (@pxref{Messages/Warnings, ,Optional warnings and
8990messages}).
8991
8992The messages currently printed, and their meanings, include:
8993
8994@table @code
8995@item inner block not inside outer block in @var{symbol}
8996
8997The symbol information shows where symbol scopes begin and end
8998(such as at the start of a function or a block of statements). This
8999error indicates that an inner scope block is not fully contained
9000in its outer scope blocks.
9001
9002@value{GDBN} circumvents the problem by treating the inner block as if it had
9003the same scope as the outer block. In the error message, @var{symbol}
9004may be shown as ``@code{(don't know)}'' if the outer block is not a
9005function.
9006
9007@item block at @var{address} out of order
9008
9009The symbol information for symbol scope blocks should occur in
9010order of increasing addresses. This error indicates that it does not
9011do so.
9012
9013@value{GDBN} does not circumvent this problem, and has trouble
9014locating symbols in the source file whose symbols it is reading. (You
9015can often determine what source file is affected by specifying
9016@code{set verbose on}. @xref{Messages/Warnings, ,Optional warnings and
9017messages}.)
9018
9019@item bad block start address patched
9020
9021The symbol information for a symbol scope block has a start address
9022smaller than the address of the preceding source line. This is known
9023to occur in the SunOS 4.1.1 (and earlier) C compiler.
9024
9025@value{GDBN} circumvents the problem by treating the symbol scope block as
9026starting on the previous source line.
9027
9028@item bad string table offset in symbol @var{n}
9029
9030@cindex foo
9031Symbol number @var{n} contains a pointer into the string table which is
9032larger than the size of the string table.
9033
9034@value{GDBN} circumvents the problem by considering the symbol to have the
9035name @code{foo}, which may cause other problems if many symbols end up
9036with this name.
9037
9038@item unknown symbol type @code{0x@var{nn}}
9039
7a292a7a
SS
9040The symbol information contains new data types that @value{GDBN} does
9041not yet know how to read. @code{0x@var{nn}} is the symbol type of the
d4f3574e 9042uncomprehended information, in hexadecimal.
c906108c 9043
7a292a7a
SS
9044@value{GDBN} circumvents the error by ignoring this symbol information.
9045This usually allows you to debug your program, though certain symbols
c906108c 9046are not accessible. If you encounter such a problem and feel like
7a292a7a
SS
9047debugging it, you can debug @code{@value{GDBP}} with itself, breakpoint
9048on @code{complain}, then go up to the function @code{read_dbx_symtab}
9049and examine @code{*bufp} to see the symbol.
c906108c
SS
9050
9051@item stub type has NULL name
c906108c 9052
7a292a7a 9053@value{GDBN} could not find the full definition for a struct or class.
c906108c 9054
7a292a7a 9055@item const/volatile indicator missing (ok if using g++ v1.x), got@dots{}
b37052ae 9056The symbol information for a C@t{++} member function is missing some
7a292a7a
SS
9057information that recent versions of the compiler should have output for
9058it.
c906108c
SS
9059
9060@item info mismatch between compiler and debugger
9061
9062@value{GDBN} could not parse a type specification output by the compiler.
7a292a7a 9063
c906108c
SS
9064@end table
9065
6d2ebf8b 9066@node Targets
c906108c 9067@chapter Specifying a Debugging Target
7a292a7a 9068
c906108c
SS
9069@cindex debugging target
9070@kindex target
9071
9072A @dfn{target} is the execution environment occupied by your program.
53a5351d
JM
9073
9074Often, @value{GDBN} runs in the same host environment as your program;
9075in that case, the debugging target is specified as a side effect when
9076you use the @code{file} or @code{core} commands. When you need more
c906108c
SS
9077flexibility---for example, running @value{GDBN} on a physically separate
9078host, or controlling a standalone system over a serial port or a
53a5351d
JM
9079realtime system over a TCP/IP connection---you can use the @code{target}
9080command to specify one of the target types configured for @value{GDBN}
9081(@pxref{Target Commands, ,Commands for managing targets}).
c906108c
SS
9082
9083@menu
9084* Active Targets:: Active targets
9085* Target Commands:: Commands for managing targets
c906108c
SS
9086* Byte Order:: Choosing target byte order
9087* Remote:: Remote debugging
96baa820 9088* KOD:: Kernel Object Display
c906108c
SS
9089
9090@end menu
9091
6d2ebf8b 9092@node Active Targets
c906108c 9093@section Active targets
7a292a7a 9094
c906108c
SS
9095@cindex stacking targets
9096@cindex active targets
9097@cindex multiple targets
9098
c906108c 9099There are three classes of targets: processes, core files, and
7a292a7a
SS
9100executable files. @value{GDBN} can work concurrently on up to three
9101active targets, one in each class. This allows you to (for example)
9102start a process and inspect its activity without abandoning your work on
9103a core file.
c906108c
SS
9104
9105For example, if you execute @samp{gdb a.out}, then the executable file
9106@code{a.out} is the only active target. If you designate a core file as
9107well---presumably from a prior run that crashed and coredumped---then
9108@value{GDBN} has two active targets and uses them in tandem, looking
9109first in the corefile target, then in the executable file, to satisfy
9110requests for memory addresses. (Typically, these two classes of target
9111are complementary, since core files contain only a program's
9112read-write memory---variables and so on---plus machine status, while
9113executable files contain only the program text and initialized data.)
c906108c
SS
9114
9115When you type @code{run}, your executable file becomes an active process
7a292a7a
SS
9116target as well. When a process target is active, all @value{GDBN}
9117commands requesting memory addresses refer to that target; addresses in
9118an active core file or executable file target are obscured while the
9119process target is active.
c906108c 9120
7a292a7a
SS
9121Use the @code{core-file} and @code{exec-file} commands to select a new
9122core file or executable target (@pxref{Files, ,Commands to specify
c906108c 9123files}). To specify as a target a process that is already running, use
7a292a7a
SS
9124the @code{attach} command (@pxref{Attach, ,Debugging an already-running
9125process}).
c906108c 9126
6d2ebf8b 9127@node Target Commands
c906108c
SS
9128@section Commands for managing targets
9129
9130@table @code
9131@item target @var{type} @var{parameters}
7a292a7a
SS
9132Connects the @value{GDBN} host environment to a target machine or
9133process. A target is typically a protocol for talking to debugging
9134facilities. You use the argument @var{type} to specify the type or
9135protocol of the target machine.
c906108c
SS
9136
9137Further @var{parameters} are interpreted by the target protocol, but
9138typically include things like device names or host names to connect
9139with, process numbers, and baud rates.
c906108c
SS
9140
9141The @code{target} command does not repeat if you press @key{RET} again
9142after executing the command.
9143
9144@kindex help target
9145@item help target
9146Displays the names of all targets available. To display targets
9147currently selected, use either @code{info target} or @code{info files}
9148(@pxref{Files, ,Commands to specify files}).
9149
9150@item help target @var{name}
9151Describe a particular target, including any parameters necessary to
9152select it.
9153
9154@kindex set gnutarget
9155@item set gnutarget @var{args}
5d161b24 9156@value{GDBN} uses its own library BFD to read your files. @value{GDBN}
c906108c 9157knows whether it is reading an @dfn{executable},
5d161b24
DB
9158a @dfn{core}, or a @dfn{.o} file; however, you can specify the file format
9159with the @code{set gnutarget} command. Unlike most @code{target} commands,
c906108c
SS
9160with @code{gnutarget} the @code{target} refers to a program, not a machine.
9161
d4f3574e 9162@quotation
c906108c
SS
9163@emph{Warning:} To specify a file format with @code{set gnutarget},
9164you must know the actual BFD name.
d4f3574e 9165@end quotation
c906108c 9166
d4f3574e
SS
9167@noindent
9168@xref{Files, , Commands to specify files}.
c906108c 9169
5d161b24 9170@kindex show gnutarget
c906108c
SS
9171@item show gnutarget
9172Use the @code{show gnutarget} command to display what file format
9173@code{gnutarget} is set to read. If you have not set @code{gnutarget},
9174@value{GDBN} will determine the file format for each file automatically,
9175and @code{show gnutarget} displays @samp{The current BDF target is "auto"}.
9176@end table
9177
c906108c
SS
9178Here are some common targets (available, or not, depending on the GDB
9179configuration):
c906108c
SS
9180
9181@table @code
9182@kindex target exec
9183@item target exec @var{program}
9184An executable file. @samp{target exec @var{program}} is the same as
9185@samp{exec-file @var{program}}.
9186
c906108c
SS
9187@kindex target core
9188@item target core @var{filename}
9189A core dump file. @samp{target core @var{filename}} is the same as
9190@samp{core-file @var{filename}}.
c906108c
SS
9191
9192@kindex target remote
9193@item target remote @var{dev}
9194Remote serial target in GDB-specific protocol. The argument @var{dev}
9195specifies what serial device to use for the connection (e.g.
9196@file{/dev/ttya}). @xref{Remote, ,Remote debugging}. @code{target remote}
d4f3574e 9197supports the @code{load} command. This is only useful if you have
c906108c
SS
9198some other way of getting the stub to the target system, and you can put
9199it somewhere in memory where it won't get clobbered by the download.
9200
c906108c
SS
9201@kindex target sim
9202@item target sim
2df3850c 9203Builtin CPU simulator. @value{GDBN} includes simulators for most architectures.
104c1213
JM
9204In general,
9205@example
9206 target sim
9207 load
9208 run
9209@end example
d4f3574e 9210@noindent
104c1213 9211works; however, you cannot assume that a specific memory map, device
d4f3574e 9212drivers, or even basic I/O is available, although some simulators do
104c1213
JM
9213provide these. For info about any processor-specific simulator details,
9214see the appropriate section in @ref{Embedded Processors, ,Embedded
9215Processors}.
9216
c906108c
SS
9217@end table
9218
104c1213 9219Some configurations may include these targets as well:
c906108c
SS
9220
9221@table @code
9222
c906108c
SS
9223@kindex target nrom
9224@item target nrom @var{dev}
9225NetROM ROM emulator. This target only supports downloading.
9226
c906108c
SS
9227@end table
9228
5d161b24 9229Different targets are available on different configurations of @value{GDBN};
c906108c 9230your configuration may have more or fewer targets.
c906108c
SS
9231
9232Many remote targets require you to download the executable's code
9233once you've successfully established a connection.
9234
9235@table @code
9236
9237@kindex load @var{filename}
9238@item load @var{filename}
c906108c
SS
9239Depending on what remote debugging facilities are configured into
9240@value{GDBN}, the @code{load} command may be available. Where it exists, it
9241is meant to make @var{filename} (an executable) available for debugging
9242on the remote system---by downloading, or dynamic linking, for example.
9243@code{load} also records the @var{filename} symbol table in @value{GDBN}, like
9244the @code{add-symbol-file} command.
9245
9246If your @value{GDBN} does not have a @code{load} command, attempting to
9247execute it gets the error message ``@code{You can't do that when your
9248target is @dots{}}''
c906108c
SS
9249
9250The file is loaded at whatever address is specified in the executable.
9251For some object file formats, you can specify the load address when you
9252link the program; for other formats, like a.out, the object file format
9253specifies a fixed address.
9254@c FIXME! This would be a good place for an xref to the GNU linker doc.
9255
c906108c
SS
9256@code{load} does not repeat if you press @key{RET} again after using it.
9257@end table
9258
6d2ebf8b 9259@node Byte Order
c906108c 9260@section Choosing target byte order
7a292a7a 9261
c906108c
SS
9262@cindex choosing target byte order
9263@cindex target byte order
c906108c
SS
9264
9265Some types of processors, such as the MIPS, PowerPC, and Hitachi SH,
9266offer the ability to run either big-endian or little-endian byte
9267orders. Usually the executable or symbol will include a bit to
9268designate the endian-ness, and you will not need to worry about
9269which to use. However, you may still find it useful to adjust
d4f3574e 9270@value{GDBN}'s idea of processor endian-ness manually.
c906108c
SS
9271
9272@table @code
9273@kindex set endian big
9274@item set endian big
9275Instruct @value{GDBN} to assume the target is big-endian.
9276
9277@kindex set endian little
9278@item set endian little
9279Instruct @value{GDBN} to assume the target is little-endian.
9280
9281@kindex set endian auto
9282@item set endian auto
9283Instruct @value{GDBN} to use the byte order associated with the
9284executable.
9285
9286@item show endian
9287Display @value{GDBN}'s current idea of the target byte order.
9288
9289@end table
9290
9291Note that these commands merely adjust interpretation of symbolic
9292data on the host, and that they have absolutely no effect on the
9293target system.
9294
6d2ebf8b 9295@node Remote
c906108c
SS
9296@section Remote debugging
9297@cindex remote debugging
9298
9299If you are trying to debug a program running on a machine that cannot run
5d161b24
DB
9300@value{GDBN} in the usual way, it is often useful to use remote debugging.
9301For example, you might use remote debugging on an operating system kernel,
c906108c
SS
9302or on a small system which does not have a general purpose operating system
9303powerful enough to run a full-featured debugger.
9304
9305Some configurations of @value{GDBN} have special serial or TCP/IP interfaces
9306to make this work with particular debugging targets. In addition,
5d161b24 9307@value{GDBN} comes with a generic serial protocol (specific to @value{GDBN},
c906108c
SS
9308but not specific to any particular target system) which you can use if you
9309write the remote stubs---the code that runs on the remote system to
9310communicate with @value{GDBN}.
9311
9312Other remote targets may be available in your
9313configuration of @value{GDBN}; use @code{help target} to list them.
c906108c 9314
c906108c 9315@menu
c906108c 9316* Remote Serial:: @value{GDBN} remote serial protocol
c906108c
SS
9317@end menu
9318
6d2ebf8b 9319@node Remote Serial
104c1213 9320@subsection The @value{GDBN} remote serial protocol
7a292a7a 9321
104c1213
JM
9322@cindex remote serial debugging, overview
9323To debug a program running on another machine (the debugging
9324@dfn{target} machine), you must first arrange for all the usual
9325prerequisites for the program to run by itself. For example, for a C
9326program, you need:
c906108c 9327
104c1213
JM
9328@enumerate
9329@item
9330A startup routine to set up the C runtime environment; these usually
9331have a name like @file{crt0}. The startup routine may be supplied by
9332your hardware supplier, or you may have to write your own.
96baa820 9333
5d161b24 9334@item
d4f3574e 9335A C subroutine library to support your program's
104c1213 9336subroutine calls, notably managing input and output.
96baa820 9337
104c1213
JM
9338@item
9339A way of getting your program to the other machine---for example, a
9340download program. These are often supplied by the hardware
9341manufacturer, but you may have to write your own from hardware
9342documentation.
9343@end enumerate
96baa820 9344
104c1213
JM
9345The next step is to arrange for your program to use a serial port to
9346communicate with the machine where @value{GDBN} is running (the @dfn{host}
9347machine). In general terms, the scheme looks like this:
96baa820 9348
104c1213
JM
9349@table @emph
9350@item On the host,
9351@value{GDBN} already understands how to use this protocol; when everything
9352else is set up, you can simply use the @samp{target remote} command
9353(@pxref{Targets,,Specifying a Debugging Target}).
9354
9355@item On the target,
9356you must link with your program a few special-purpose subroutines that
9357implement the @value{GDBN} remote serial protocol. The file containing these
9358subroutines is called a @dfn{debugging stub}.
9359
9360On certain remote targets, you can use an auxiliary program
9361@code{gdbserver} instead of linking a stub into your program.
9362@xref{Server,,Using the @code{gdbserver} program}, for details.
9363@end table
96baa820 9364
104c1213
JM
9365The debugging stub is specific to the architecture of the remote
9366machine; for example, use @file{sparc-stub.c} to debug programs on
9367@sc{sparc} boards.
96baa820 9368
104c1213
JM
9369@cindex remote serial stub list
9370These working remote stubs are distributed with @value{GDBN}:
96baa820 9371
104c1213
JM
9372@table @code
9373
9374@item i386-stub.c
41afff9a 9375@cindex @file{i386-stub.c}
104c1213
JM
9376@cindex Intel
9377@cindex i386
9378For Intel 386 and compatible architectures.
9379
9380@item m68k-stub.c
41afff9a 9381@cindex @file{m68k-stub.c}
104c1213
JM
9382@cindex Motorola 680x0
9383@cindex m680x0
9384For Motorola 680x0 architectures.
9385
9386@item sh-stub.c
41afff9a 9387@cindex @file{sh-stub.c}
104c1213
JM
9388@cindex Hitachi
9389@cindex SH
9390For Hitachi SH architectures.
9391
9392@item sparc-stub.c
41afff9a 9393@cindex @file{sparc-stub.c}
104c1213
JM
9394@cindex Sparc
9395For @sc{sparc} architectures.
9396
9397@item sparcl-stub.c
41afff9a 9398@cindex @file{sparcl-stub.c}
104c1213
JM
9399@cindex Fujitsu
9400@cindex SparcLite
9401For Fujitsu @sc{sparclite} architectures.
9402
9403@end table
9404
9405The @file{README} file in the @value{GDBN} distribution may list other
9406recently added stubs.
9407
9408@menu
9409* Stub Contents:: What the stub can do for you
9410* Bootstrapping:: What you must do for the stub
9411* Debug Session:: Putting it all together
9412* Protocol:: Definition of the communication protocol
9413* Server:: Using the `gdbserver' program
9414* NetWare:: Using the `gdbserve.nlm' program
9415@end menu
9416
6d2ebf8b 9417@node Stub Contents
104c1213
JM
9418@subsubsection What the stub can do for you
9419
9420@cindex remote serial stub
9421The debugging stub for your architecture supplies these three
9422subroutines:
9423
9424@table @code
9425@item set_debug_traps
9426@kindex set_debug_traps
9427@cindex remote serial stub, initialization
9428This routine arranges for @code{handle_exception} to run when your
9429program stops. You must call this subroutine explicitly near the
9430beginning of your program.
9431
9432@item handle_exception
9433@kindex handle_exception
9434@cindex remote serial stub, main routine
9435This is the central workhorse, but your program never calls it
9436explicitly---the setup code arranges for @code{handle_exception} to
9437run when a trap is triggered.
9438
9439@code{handle_exception} takes control when your program stops during
9440execution (for example, on a breakpoint), and mediates communications
9441with @value{GDBN} on the host machine. This is where the communications
9442protocol is implemented; @code{handle_exception} acts as the @value{GDBN}
d4f3574e 9443representative on the target machine. It begins by sending summary
104c1213
JM
9444information on the state of your program, then continues to execute,
9445retrieving and transmitting any information @value{GDBN} needs, until you
9446execute a @value{GDBN} command that makes your program resume; at that point,
9447@code{handle_exception} returns control to your own code on the target
5d161b24 9448machine.
104c1213
JM
9449
9450@item breakpoint
9451@cindex @code{breakpoint} subroutine, remote
9452Use this auxiliary subroutine to make your program contain a
9453breakpoint. Depending on the particular situation, this may be the only
9454way for @value{GDBN} to get control. For instance, if your target
9455machine has some sort of interrupt button, you won't need to call this;
9456pressing the interrupt button transfers control to
9457@code{handle_exception}---in effect, to @value{GDBN}. On some machines,
9458simply receiving characters on the serial port may also trigger a trap;
9459again, in that situation, you don't need to call @code{breakpoint} from
9460your own program---simply running @samp{target remote} from the host
5d161b24 9461@value{GDBN} session gets control.
104c1213
JM
9462
9463Call @code{breakpoint} if none of these is true, or if you simply want
9464to make certain your program stops at a predetermined point for the
9465start of your debugging session.
9466@end table
9467
6d2ebf8b 9468@node Bootstrapping
104c1213
JM
9469@subsubsection What you must do for the stub
9470
9471@cindex remote stub, support routines
9472The debugging stubs that come with @value{GDBN} are set up for a particular
9473chip architecture, but they have no information about the rest of your
9474debugging target machine.
9475
9476First of all you need to tell the stub how to communicate with the
9477serial port.
9478
9479@table @code
9480@item int getDebugChar()
9481@kindex getDebugChar
9482Write this subroutine to read a single character from the serial port.
9483It may be identical to @code{getchar} for your target system; a
9484different name is used to allow you to distinguish the two if you wish.
9485
9486@item void putDebugChar(int)
9487@kindex putDebugChar
9488Write this subroutine to write a single character to the serial port.
5d161b24 9489It may be identical to @code{putchar} for your target system; a
104c1213
JM
9490different name is used to allow you to distinguish the two if you wish.
9491@end table
9492
9493@cindex control C, and remote debugging
9494@cindex interrupting remote targets
9495If you want @value{GDBN} to be able to stop your program while it is
9496running, you need to use an interrupt-driven serial driver, and arrange
9497for it to stop when it receives a @code{^C} (@samp{\003}, the control-C
9498character). That is the character which @value{GDBN} uses to tell the
9499remote system to stop.
9500
9501Getting the debugging target to return the proper status to @value{GDBN}
9502probably requires changes to the standard stub; one quick and dirty way
9503is to just execute a breakpoint instruction (the ``dirty'' part is that
9504@value{GDBN} reports a @code{SIGTRAP} instead of a @code{SIGINT}).
9505
9506Other routines you need to supply are:
9507
9508@table @code
9509@item void exceptionHandler (int @var{exception_number}, void *@var{exception_address})
9510@kindex exceptionHandler
9511Write this function to install @var{exception_address} in the exception
9512handling tables. You need to do this because the stub does not have any
9513way of knowing what the exception handling tables on your target system
9514are like (for example, the processor's table might be in @sc{rom},
9515containing entries which point to a table in @sc{ram}).
9516@var{exception_number} is the exception number which should be changed;
9517its meaning is architecture-dependent (for example, different numbers
9518might represent divide by zero, misaligned access, etc). When this
9519exception occurs, control should be transferred directly to
9520@var{exception_address}, and the processor state (stack, registers,
9521and so on) should be just as it is when a processor exception occurs. So if
9522you want to use a jump instruction to reach @var{exception_address}, it
9523should be a simple jump, not a jump to subroutine.
9524
9525For the 386, @var{exception_address} should be installed as an interrupt
9526gate so that interrupts are masked while the handler runs. The gate
9527should be at privilege level 0 (the most privileged level). The
9528@sc{sparc} and 68k stubs are able to mask interrupts themselves without
9529help from @code{exceptionHandler}.
9530
9531@item void flush_i_cache()
9532@kindex flush_i_cache
d4f3574e 9533On @sc{sparc} and @sc{sparclite} only, write this subroutine to flush the
104c1213
JM
9534instruction cache, if any, on your target machine. If there is no
9535instruction cache, this subroutine may be a no-op.
9536
9537On target machines that have instruction caches, @value{GDBN} requires this
9538function to make certain that the state of your program is stable.
9539@end table
9540
9541@noindent
9542You must also make sure this library routine is available:
9543
9544@table @code
9545@item void *memset(void *, int, int)
9546@kindex memset
9547This is the standard library function @code{memset} that sets an area of
9548memory to a known value. If you have one of the free versions of
9549@code{libc.a}, @code{memset} can be found there; otherwise, you must
9550either obtain it from your hardware manufacturer, or write your own.
9551@end table
9552
9553If you do not use the GNU C compiler, you may need other standard
9554library subroutines as well; this varies from one stub to another,
9555but in general the stubs are likely to use any of the common library
d4f3574e 9556subroutines which @code{@value{GCC}} generates as inline code.
104c1213
JM
9557
9558
6d2ebf8b 9559@node Debug Session
104c1213
JM
9560@subsubsection Putting it all together
9561
9562@cindex remote serial debugging summary
9563In summary, when your program is ready to debug, you must follow these
9564steps.
9565
9566@enumerate
9567@item
6d2ebf8b 9568Make sure you have defined the supporting low-level routines
104c1213
JM
9569(@pxref{Bootstrapping,,What you must do for the stub}):
9570@display
9571@code{getDebugChar}, @code{putDebugChar},
9572@code{flush_i_cache}, @code{memset}, @code{exceptionHandler}.
9573@end display
9574
9575@item
9576Insert these lines near the top of your program:
9577
9578@example
9579set_debug_traps();
9580breakpoint();
9581@end example
9582
9583@item
9584For the 680x0 stub only, you need to provide a variable called
9585@code{exceptionHook}. Normally you just use:
9586
9587@example
9588void (*exceptionHook)() = 0;
9589@end example
9590
d4f3574e 9591@noindent
104c1213 9592but if before calling @code{set_debug_traps}, you set it to point to a
598ca718 9593function in your program, that function is called when
104c1213
JM
9594@code{@value{GDBN}} continues after stopping on a trap (for example, bus
9595error). The function indicated by @code{exceptionHook} is called with
9596one parameter: an @code{int} which is the exception number.
9597
9598@item
9599Compile and link together: your program, the @value{GDBN} debugging stub for
9600your target architecture, and the supporting subroutines.
9601
9602@item
9603Make sure you have a serial connection between your target machine and
9604the @value{GDBN} host, and identify the serial port on the host.
9605
9606@item
9607@c The "remote" target now provides a `load' command, so we should
9608@c document that. FIXME.
9609Download your program to your target machine (or get it there by
9610whatever means the manufacturer provides), and start it.
9611
9612@item
9613To start remote debugging, run @value{GDBN} on the host machine, and specify
9614as an executable file the program that is running in the remote machine.
9615This tells @value{GDBN} how to find your program's symbols and the contents
9616of its pure text.
9617
d4f3574e 9618@item
104c1213 9619@cindex serial line, @code{target remote}
d4f3574e 9620Establish communication using the @code{target remote} command.
104c1213
JM
9621Its argument specifies how to communicate with the target
9622machine---either via a devicename attached to a direct serial line, or a
9623TCP port (usually to a terminal server which in turn has a serial line
9624to the target). For example, to use a serial line connected to the
9625device named @file{/dev/ttyb}:
9626
9627@example
9628target remote /dev/ttyb
9629@end example
9630
9631@cindex TCP port, @code{target remote}
9632To use a TCP connection, use an argument of the form
9633@code{@var{host}:port}. For example, to connect to port 2828 on a
9634terminal server named @code{manyfarms}:
9635
9636@example
9637target remote manyfarms:2828
9638@end example
9639@end enumerate
9640
9641Now you can use all the usual commands to examine and change data and to
9642step and continue the remote program.
9643
9644To resume the remote program and stop debugging it, use the @code{detach}
9645command.
9646
9647@cindex interrupting remote programs
9648@cindex remote programs, interrupting
9649Whenever @value{GDBN} is waiting for the remote program, if you type the
9650interrupt character (often @key{C-C}), @value{GDBN} attempts to stop the
9651program. This may or may not succeed, depending in part on the hardware
9652and the serial drivers the remote system uses. If you type the
9653interrupt character once again, @value{GDBN} displays this prompt:
9654
9655@example
9656Interrupted while waiting for the program.
9657Give up (and stop debugging it)? (y or n)
9658@end example
9659
9660If you type @kbd{y}, @value{GDBN} abandons the remote debugging session.
9661(If you decide you want to try again later, you can use @samp{target
9662remote} again to connect once more.) If you type @kbd{n}, @value{GDBN}
9663goes back to waiting.
9664
6d2ebf8b 9665@node Protocol
104c1213
JM
9666@subsubsection Communication protocol
9667
9668@cindex debugging stub, example
9669@cindex remote stub, example
9670@cindex stub example, remote debugging
9671The stub files provided with @value{GDBN} implement the target side of the
9672communication protocol, and the @value{GDBN} side is implemented in the
9673@value{GDBN} source file @file{remote.c}. Normally, you can simply allow
9674these subroutines to communicate, and ignore the details. (If you're
9675implementing your own stub file, you can still ignore the details: start
9676with one of the existing stub files. @file{sparc-stub.c} is the best
9677organized, and therefore the easiest to read.)
9678
9679However, there may be occasions when you need to know something about
9680the protocol---for example, if there is only one serial port to your
9681target machine, you might want your program to do something special if
9682it recognizes a packet meant for @value{GDBN}.
9683
9684In the examples below, @samp{<-} and @samp{->} are used to indicate
9685transmitted and received data respectfully.
9686
9687@cindex protocol, @value{GDBN} remote serial
9688@cindex serial protocol, @value{GDBN} remote
9689@cindex remote serial protocol
6cf7e474
AC
9690All @value{GDBN} commands and responses (other than acknowledgments) are
9691sent as a @var{packet}. A @var{packet} is introduced with the character
9692@samp{$}, the actual @var{packet-data}, and the terminating character
9693@samp{#} followed by a two-digit @var{checksum}:
104c1213
JM
9694
9695@example
9696@code{$}@var{packet-data}@code{#}@var{checksum}
9697@end example
9698@noindent
104c1213
JM
9699
9700@cindex checksum, for @value{GDBN} remote
9701@noindent
9702The two-digit @var{checksum} is computed as the modulo 256 sum of all
6cf7e474
AC
9703characters between the leading @samp{$} and the trailing @samp{#} (an
9704eight bit unsigned checksum).
9705
9706Implementors should note that prior to @value{GDBN} 5.0 the protocol
9707specification also included an optional two-digit @var{sequence-id}:
9708
9709@example
9710@code{$}@var{sequence-id}@code{:}@var{packet-data}@code{#}@var{checksum}
9711@end example
104c1213
JM
9712
9713@cindex sequence-id, for @value{GDBN} remote
9714@noindent
6cf7e474
AC
9715That @var{sequence-id} was appended to the acknowledgment. @value{GDBN}
9716has never output @var{sequence-id}s. Stubs that handle packets added
9717since @value{GDBN} 5.0 must not accept @var{sequence-id}.
104c1213 9718
6cf7e474 9719@cindex acknowledgment, for @value{GDBN} remote
104c1213
JM
9720When either the host or the target machine receives a packet, the first
9721response expected is an acknowledgment: either @samp{+} (to indicate
9722the package was received correctly) or @samp{-} (to request
9723retransmission):
9724
9725@example
9726<- @code{$}@var{packet-data}@code{#}@var{checksum}
9727-> @code{+}
9728@end example
9729@noindent
104c1213
JM
9730
9731The host (@value{GDBN}) sends @var{command}s, and the target (the
9732debugging stub incorporated in your program) sends a @var{response}. In
9733the case of step and continue @var{command}s, the response is only sent
9734when the operation has completed (the target has again stopped).
9735
9736@var{packet-data} consists of a sequence of characters with the
6cf7e474
AC
9737exception of @samp{#} and @samp{$} (see @samp{X} packet for additional
9738exceptions).
9739
9740Fields within the packet should be separated using @samp{,} @samp{;} or
9741@samp{:}. Except where otherwise noted all numbers are represented in
9742HEX with leading zeros suppressed.
9743
9744Implementors should note that prior to @value{GDBN} 5.0, the character
9745@samp{:} could not appear as the third character in a packet (as it
9746would potentially conflict with the @var{sequence-id}).
104c1213
JM
9747
9748Response @var{data} can be run-length encoded to save space. A @samp{*}
c3f6f71d 9749means that the next character is an @sc{ascii} encoding giving a repeat count
104c1213
JM
9750which stands for that many repetitions of the character preceding the
9751@samp{*}. The encoding is @code{n+29}, yielding a printable character
d4f3574e
SS
9752where @code{n >=3} (which is where rle starts to win). The printable
9753characters @samp{$}, @samp{#}, @samp{+} and @samp{-} or with a numeric
9754value greater than 126 should not be used.
9755
9756Some remote systems have used a different run-length encoding mechanism
9757loosely refered to as the cisco encoding. Following the @samp{*}
9758character are two hex digits that indicate the size of the packet.
104c1213
JM
9759
9760So:
9761@example
9762"@code{0* }"
9763@end example
9764@noindent
9765means the same as "0000".
9766
598ca718 9767The error response returned for some packets includes a two character
104c1213
JM
9768error number. That number is not well defined.
9769
9770For any @var{command} not supported by the stub, an empty response
9771(@samp{$#00}) should be returned. That way it is possible to extend the
9772protocol. A newer @value{GDBN} can tell if a packet is supported based
d4f3574e 9773on that response.
104c1213 9774
f1251bdd
C
9775A stub is required to support the @samp{g}, @samp{G}, @samp{m}, @samp{M},
9776@samp{c}, and @samp{s} @var{command}s. All other @var{command}s are
9777optional.
9778
104c1213
JM
9779Below is a complete list of all currently defined @var{command}s and
9780their corresponding response @var{data}:
598ca718 9781@page
104c1213
JM
9782@multitable @columnfractions .30 .30 .40
9783@item Packet
9784@tab Request
9785@tab Description
9786
df2396a1 9787@item extended mode
104c1213
JM
9788@tab @code{!}
9789@tab
df2396a1 9790Enable extended mode. In extended mode, the remote server is made
656db9b0 9791persistent. The @samp{R} packet is used to restart the program being
df2396a1 9792debugged.
104c1213 9793@item
df2396a1 9794@tab reply @samp{OK}
104c1213 9795@tab
df2396a1 9796The remote target both supports and has enabled extended mode.
104c1213
JM
9797
9798@item last signal
9799@tab @code{?}
9800@tab
d4f3574e
SS
9801Indicate the reason the target halted. The reply is the same as for step
9802and continue.
9803@item
9804@tab reply
9805@tab see below
9806
104c1213
JM
9807
9808@item reserved
9809@tab @code{a}
5d161b24 9810@tab Reserved for future use
104c1213 9811
f1251bdd 9812@item set program arguments @strong{(reserved)}
104c1213
JM
9813@tab @code{A}@var{arglen}@code{,}@var{argnum}@code{,}@var{arg}@code{,...}
9814@tab
598ca718
EZ
9815@item
9816@tab
9817@tab
104c1213
JM
9818Initialized @samp{argv[]} array passed into program. @var{arglen}
9819specifies the number of bytes in the hex encoded byte stream @var{arg}.
d4f3574e 9820See @file{gdbserver} for more details.
104c1213
JM
9821@item
9822@tab reply @code{OK}
9823@item
9824@tab reply @code{E}@var{NN}
9825
9826@item set baud @strong{(deprecated)}
9827@tab @code{b}@var{baud}
9828@tab
9829Change the serial line speed to @var{baud}. JTC: @emph{When does the
9830transport layer state change? When it's received, or after the ACK is
9831transmitted. In either case, there are problems if the command or the
9832acknowledgment packet is dropped.} Stan: @emph{If people really wanted
9833to add something like this, and get it working for the first time, they
9834ought to modify ser-unix.c to send some kind of out-of-band message to a
9835specially-setup stub and have the switch happen "in between" packets, so
9836that from remote protocol's point of view, nothing actually
9837happened.}
9838
9839@item set breakpoint @strong{(deprecated)}
9840@tab @code{B}@var{addr},@var{mode}
9841@tab
9842Set (@var{mode} is @samp{S}) or clear (@var{mode} is @samp{C}) a
9843breakpoint at @var{addr}. @emph{This has been replaced by the @samp{Z} and
9844@samp{z} packets.}
9845
9846@item continue
9847@tab @code{c}@var{addr}
9848@tab
9849@var{addr} is address to resume. If @var{addr} is omitted, resume at
9850current address.
9851@item
9852@tab reply
9853@tab see below
9854
f1251bdd 9855@item continue with signal
104c1213
JM
9856@tab @code{C}@var{sig}@code{;}@var{addr}
9857@tab
9858Continue with signal @var{sig} (hex signal number). If
9859@code{;}@var{addr} is omitted, resume at same address.
9860@item
9861@tab reply
9862@tab see below
9863
598ca718 9864@item toggle debug @strong{(deprecated)}
104c1213
JM
9865@tab @code{d}
9866@tab
d4f3574e 9867toggle debug flag.
104c1213 9868
f1251bdd 9869@item detach
104c1213 9870@tab @code{D}
d4f3574e 9871@tab
2df3850c
JM
9872Detach @value{GDBN} from the remote system. Sent to the remote target before
9873@value{GDBN} disconnects.
d4f3574e
SS
9874@item
9875@tab reply @emph{no response}
9876@tab
598ca718 9877@value{GDBN} does not check for any response after sending this packet.
104c1213
JM
9878
9879@item reserved
9880@tab @code{e}
5d161b24 9881@tab Reserved for future use
104c1213
JM
9882
9883@item reserved
9884@tab @code{E}
5d161b24 9885@tab Reserved for future use
104c1213
JM
9886
9887@item reserved
9888@tab @code{f}
5d161b24 9889@tab Reserved for future use
104c1213
JM
9890
9891@item reserved
9892@tab @code{F}
5d161b24 9893@tab Reserved for future use
104c1213
JM
9894
9895@item read registers
9896@tab @code{g}
9897@tab Read general registers.
9898@item
9899@tab reply @var{XX...}
9900@tab
9901Each byte of register data is described by two hex digits. The bytes
9902with the register are transmitted in target byte order. The size of
d4f3574e 9903each register and their position within the @samp{g} @var{packet} are
2df3850c 9904determined by the @value{GDBN} internal macros @var{REGISTER_RAW_SIZE} and
d4f3574e
SS
9905@var{REGISTER_NAME} macros. The specification of several standard
9906@code{g} packets is specified below.
104c1213
JM
9907@item
9908@tab @code{E}@var{NN}
9909@tab for an error.
9910
9911@item write regs
9912@tab @code{G}@var{XX...}
9913@tab
9914See @samp{g} for a description of the @var{XX...} data.
9915@item
9916@tab reply @code{OK}
9917@tab for success
9918@item
9919@tab reply @code{E}@var{NN}
9920@tab for an error
9921
9922@item reserved
9923@tab @code{h}
5d161b24 9924@tab Reserved for future use
104c1213 9925
f1251bdd 9926@item set thread
104c1213
JM
9927@tab @code{H}@var{c}@var{t...}
9928@tab
d4f3574e
SS
9929Set thread for subsequent operations (@samp{m}, @samp{M}, @samp{g},
9930@samp{G}, et.al.). @var{c} = @samp{c} for thread used in step and
9931continue; @var{t...} can be -1 for all threads. @var{c} = @samp{g} for
9932thread used in other operations. If zero, pick a thread, any thread.
104c1213
JM
9933@item
9934@tab reply @code{OK}
9935@tab for success
9936@item
9937@tab reply @code{E}@var{NN}
9938@tab for an error
9939
d4f3574e
SS
9940@c FIXME: JTC:
9941@c 'H': How restrictive (or permissive) is the thread model. If a
5d161b24 9942@c thread is selected and stopped, are other threads allowed
d4f3574e
SS
9943@c to continue to execute? As I mentioned above, I think the
9944@c semantics of each command when a thread is selected must be
9945@c described. For example:
9946@c
9947@c 'g': If the stub supports threads and a specific thread is
9948@c selected, returns the register block from that thread;
9949@c otherwise returns current registers.
9950@c
9951@c 'G' If the stub supports threads and a specific thread is
9952@c selected, sets the registers of the register block of
9953@c that thread; otherwise sets current registers.
9954
f1251bdd 9955@item cycle step @strong{(draft)}
104c1213
JM
9956@tab @code{i}@var{addr}@code{,}@var{nnn}
9957@tab
9958Step the remote target by a single clock cycle. If @code{,}@var{nnn} is
9959present, cycle step @var{nnn} cycles. If @var{addr} is present, cycle
9960step starting at that address.
9961
f1251bdd 9962@item signal then cycle step @strong{(reserved)}
104c1213
JM
9963@tab @code{I}
9964@tab
9965See @samp{i} and @samp{S} for likely syntax and semantics.
9966
9967@item reserved
9968@tab @code{j}
9969@tab Reserved for future use
9970
9971@item reserved
9972@tab @code{J}
5d161b24 9973@tab Reserved for future use
104c1213 9974
f1251bdd 9975@item kill request
104c1213
JM
9976@tab @code{k}
9977@tab
d4f3574e
SS
9978FIXME: @emph{There is no description of how operate when a specific
9979thread context has been selected (ie. does 'k' kill only that thread?)}.
104c1213
JM
9980
9981@item reserved
9982@tab @code{l}
5d161b24 9983@tab Reserved for future use
104c1213
JM
9984
9985@item reserved
9986@tab @code{L}
5d161b24 9987@tab Reserved for future use
104c1213
JM
9988
9989@item read memory
9990@tab @code{m}@var{addr}@code{,}@var{length}
9991@tab
9992Read @var{length} bytes of memory starting at address @var{addr}.
2df3850c 9993Neither @value{GDBN} nor the stub assume that sized memory transfers are assumed
d4f3574e
SS
9994using word alligned accesses. FIXME: @emph{A word aligned memory
9995transfer mechanism is needed.}
104c1213
JM
9996@item
9997@tab reply @var{XX...}
9998@tab
d4f3574e 9999@var{XX...} is mem contents. Can be fewer bytes than requested if able
2df3850c 10000to read only part of the data. Neither @value{GDBN} nor the stub assume that
d4f3574e
SS
10001sized memory transfers are assumed using word alligned accesses. FIXME:
10002@emph{A word aligned memory transfer mechanism is needed.}
104c1213
JM
10003@item
10004@tab reply @code{E}@var{NN}
10005@tab @var{NN} is errno
10006
10007@item write mem
10008@tab @code{M}@var{addr},@var{length}@code{:}@var{XX...}
10009@tab
10010Write @var{length} bytes of memory starting at address @var{addr}.
10011@var{XX...} is the data.
10012@item
10013@tab reply @code{OK}
10014@tab for success
10015@item
10016@tab reply @code{E}@var{NN}
10017@tab
10018for an error (this includes the case where only part of the data was
10019written).
10020
10021@item reserved
10022@tab @code{n}
5d161b24 10023@tab Reserved for future use
104c1213
JM
10024
10025@item reserved
10026@tab @code{N}
5d161b24 10027@tab Reserved for future use
104c1213
JM
10028
10029@item reserved
10030@tab @code{o}
5d161b24 10031@tab Reserved for future use
104c1213
JM
10032
10033@item reserved
10034@tab @code{O}
5d161b24 10035@tab Reserved for future use
104c1213
JM
10036
10037@item read reg @strong{(reserved)}
10038@tab @code{p}@var{n...}
10039@tab
10040See write register.
10041@item
10042@tab return @var{r....}
10043@tab The hex encoded value of the register in target byte order.
10044
f1251bdd 10045@item write reg
104c1213
JM
10046@tab @code{P}@var{n...}@code{=}@var{r...}
10047@tab
10048Write register @var{n...} with value @var{r...}, which contains two hex
10049digits for each byte in the register (target byte order).
10050@item
10051@tab reply @code{OK}
10052@tab for success
10053@item
10054@tab reply @code{E}@var{NN}
10055@tab for an error
10056
f1251bdd 10057@item general query
104c1213
JM
10058@tab @code{q}@var{query}
10059@tab
598ca718 10060Request info about @var{query}. In general @value{GDBN} queries
104c1213 10061have a leading upper case letter. Custom vendor queries should use a
d4f3574e
SS
10062company prefix (in lower case) ex: @samp{qfsf.var}. @var{query} may
10063optionally be followed by a @samp{,} or @samp{;} separated list. Stubs
10064must ensure that they match the full @var{query} name.
104c1213
JM
10065@item
10066@tab reply @code{XX...}
d4f3574e 10067@tab Hex encoded data from query. The reply can not be empty.
104c1213
JM
10068@item
10069@tab reply @code{E}@var{NN}
10070@tab error reply
10071@item
10072@tab reply @samp{}
10073@tab Indicating an unrecognized @var{query}.
10074
f1251bdd 10075@item general set
104c1213
JM
10076@tab @code{Q}@var{var}@code{=}@var{val}
10077@tab
10078Set value of @var{var} to @var{val}. See @samp{q} for a discussing of
10079naming conventions.
10080
598ca718 10081@item reset @strong{(deprecated)}
d4f3574e
SS
10082@tab @code{r}
10083@tab
10084Reset the entire system.
104c1213 10085
f1251bdd 10086@item remote restart
104c1213
JM
10087@tab @code{R}@var{XX}
10088@tab
df2396a1
AC
10089Restart the program being debugged. @var{XX}, while needed, is ignored.
10090This packet is only available in extended mode.
10091@item
10092@tab
10093no reply
10094@tab
10095The @samp{R} packet has no reply.
104c1213 10096
f1251bdd 10097@item step
104c1213
JM
10098@tab @code{s}@var{addr}
10099@tab
10100@var{addr} is address to resume. If @var{addr} is omitted, resume at
10101same address.
10102@item
10103@tab reply
10104@tab see below
10105
f1251bdd 10106@item step with signal
104c1213
JM
10107@tab @code{S}@var{sig}@code{;}@var{addr}
10108@tab
10109Like @samp{C} but step not continue.
10110@item
10111@tab reply
10112@tab see below
10113
f1251bdd 10114@item search
104c1213
JM
10115@tab @code{t}@var{addr}@code{:}@var{PP}@code{,}@var{MM}
10116@tab
10117Search backwards starting at address @var{addr} for a match with pattern
10118@var{PP} and mask @var{MM}. @var{PP} and @var{MM} are 4
d4f3574e 10119bytes. @var{addr} must be at least 3 digits.
104c1213 10120
f1251bdd 10121@item thread alive
104c1213
JM
10122@tab @code{T}@var{XX}
10123@tab Find out if the thread XX is alive.
10124@item
10125@tab reply @code{OK}
10126@tab thread is still alive
10127@item
10128@tab reply @code{E}@var{NN}
10129@tab thread is dead
5d161b24 10130
104c1213
JM
10131@item reserved
10132@tab @code{u}
5d161b24 10133@tab Reserved for future use
104c1213
JM
10134
10135@item reserved
10136@tab @code{U}
5d161b24 10137@tab Reserved for future use
104c1213
JM
10138
10139@item reserved
10140@tab @code{v}
5d161b24 10141@tab Reserved for future use
104c1213
JM
10142
10143@item reserved
10144@tab @code{V}
5d161b24 10145@tab Reserved for future use
104c1213
JM
10146
10147@item reserved
10148@tab @code{w}
5d161b24 10149@tab Reserved for future use
104c1213
JM
10150
10151@item reserved
10152@tab @code{W}
5d161b24 10153@tab Reserved for future use
104c1213
JM
10154
10155@item reserved
10156@tab @code{x}
5d161b24 10157@tab Reserved for future use
104c1213 10158
f1251bdd 10159@item write mem (binary)
104c1213
JM
10160@tab @code{X}@var{addr}@code{,}@var{length}@var{:}@var{XX...}
10161@tab
10162@var{addr} is address, @var{length} is number of bytes, @var{XX...} is
d4f3574e
SS
10163binary data. The characters @code{$}, @code{#}, and @code{0x7d} are
10164escaped using @code{0x7d}.
104c1213
JM
10165@item
10166@tab reply @code{OK}
10167@tab for success
10168@item
10169@tab reply @code{E}@var{NN}
10170@tab for an error
10171
10172@item reserved
10173@tab @code{y}
5d161b24 10174@tab Reserved for future use
104c1213
JM
10175
10176@item reserved
10177@tab @code{Y}
5d161b24 10178@tab Reserved for future use
104c1213 10179
f1251bdd 10180@item remove break or watchpoint @strong{(draft)}
104c1213
JM
10181@tab @code{z}@var{t}@code{,}@var{addr}@code{,}@var{length}
10182@tab
10183See @samp{Z}.
10184
f1251bdd 10185@item insert break or watchpoint @strong{(draft)}
104c1213
JM
10186@tab @code{Z}@var{t}@code{,}@var{addr}@code{,}@var{length}
10187@tab
10188@var{t} is type: @samp{0} - software breakpoint, @samp{1} - hardware
10189breakpoint, @samp{2} - write watchpoint, @samp{3} - read watchpoint,
10190@samp{4} - access watchpoint; @var{addr} is address; @var{length} is in
10191bytes. For a software breakpoint, @var{length} specifies the size of
10192the instruction to be patched. For hardware breakpoints and watchpoints
d4f3574e
SS
10193@var{length} specifies the memory region to be monitored. To avoid
10194potential problems with duplicate packets, the operations should be
6d2ebf8b 10195implemented in an idempotent way.
104c1213
JM
10196@item
10197@tab reply @code{E}@var{NN}
10198@tab for an error
10199@item
10200@tab reply @code{OK}
10201@tab for success
10202@item
10203@tab @samp{}
10204@tab If not supported.
10205
10206@item reserved
10207@tab <other>
5d161b24 10208@tab Reserved for future use
104c1213
JM
10209
10210@end multitable
10211
d4f3574e
SS
10212The @samp{C}, @samp{c}, @samp{S}, @samp{s} and @samp{?} packets can
10213receive any of the below as a reply. In the case of the @samp{C},
10214@samp{c}, @samp{S} and @samp{s} packets, that reply is only returned
10215when the target halts. In the below the exact meaning of @samp{signal
10216number} is poorly defined. In general one of the UNIX signal numbering
10217conventions is used.
104c1213
JM
10218
10219@multitable @columnfractions .4 .6
10220
10221@item @code{S}@var{AA}
10222@tab @var{AA} is the signal number
10223
10224@item @code{T}@var{AA}@var{n...}@code{:}@var{r...}@code{;}@var{n...}@code{:}@var{r...}@code{;}@var{n...}@code{:}@var{r...}@code{;}
10225@tab
10226@var{AA} = two hex digit signal number; @var{n...} = register number
10227(hex), @var{r...} = target byte ordered register contents, size defined
10228by @code{REGISTER_RAW_SIZE}; @var{n...} = @samp{thread}, @var{r...} =
10229thread process ID, this is a hex integer; @var{n...} = other string not
d4f3574e 10230starting with valid hex digit. @value{GDBN} should ignore this
104c1213
JM
10231@var{n...}, @var{r...} pair and go on to the next. This way we can
10232extend the protocol.
10233
10234@item @code{W}@var{AA}
10235@tab
10236The process exited, and @var{AA} is the exit status. This is only
10237applicable for certains sorts of targets.
10238
10239@item @code{X}@var{AA}
10240@tab
10241The process terminated with signal @var{AA}.
10242
6d2ebf8b 10243@item @code{N}@var{AA}@code{;}@var{t...}@code{;}@var{d...}@code{;}@var{b...} @strong{(obsolete)}
104c1213 10244@tab
6d2ebf8b
SS
10245@var{AA} = signal number; @var{t...} = address of symbol "_start";
10246@var{d...} = base of data section; @var{b...} = base of bss section.
10247@emph{Note: only used by Cisco Systems targets. The difference between
10248this reply and the "qOffsets" query is that the 'N' packet may arrive
10249spontaneously whereas the 'qOffsets' is a query initiated by the host
10250debugger.}
104c1213
JM
10251
10252@item @code{O}@var{XX...}
10253@tab
c3f6f71d 10254@var{XX...} is hex encoding of @sc{ascii} data. This can happen at any time
104c1213
JM
10255while the program is running and the debugger should continue to wait
10256for 'W', 'T', etc.
10257
10258@end multitable
10259
d4f3574e
SS
10260The following set and query packets have already been defined.
10261
10262@multitable @columnfractions .2 .2 .6
10263
10264@item current thread
10265@tab @code{q}@code{C}
10266@tab Return the current thread id.
10267@item
10268@tab reply @code{QC}@var{pid}
10269@tab
10270Where @var{pid} is a HEX encoded 16 bit process id.
10271@item
10272@tab reply *
10273@tab Any other reply implies the old pid.
10274
bba2971c
MS
10275@item all thread ids
10276@tab @code{q}@code{fThreadInfo}
10277@item
10278@tab @code{q}@code{sThreadInfo}
d4f3574e 10279@tab
bba2971c
MS
10280Obtain a list of active thread ids from the target (OS). Since there
10281may be too many active threads to fit into one reply packet, this query
10282works iteratively: it may require more than one query/reply sequence to
10283obtain the entire list of threads. The first query of the sequence will
5d161b24 10284be the @code{qf}@code{ThreadInfo} query; subsequent queries in the
bba2971c 10285sequence will be the @code{qs}@code{ThreadInfo} query.
d4f3574e 10286@item
bba2971c
MS
10287@tab
10288@tab NOTE: replaces the @code{qL} query (see below).
d4f3574e 10289@item
5d161b24 10290@tab reply @code{m}@var{<id>}
bba2971c
MS
10291@tab A single thread id
10292@item
00e4a2e4 10293@tab reply @code{m}@var{<id>},@var{<id>...}
bba2971c
MS
10294@tab a comma-separated list of thread ids
10295@item
10296@tab reply @code{l}
10297@tab (lower case 'el') denotes end of list.
10298@item
10299@tab
10300@tab
10301In response to each query, the target will reply with a list of one
10302or more thread ids, in big-endian hex, separated by commas. GDB will
10303respond to each reply with a request for more thread ids (using the
10304@code{qs} form of the query), until the target responds with @code{l}
10305(lower-case el, for @code{'last'}).
10306
10307@item extra thread info
480ff1fb 10308@tab @code{q}@code{ThreadExtraInfo}@code{,}@var{id}
bba2971c
MS
10309@tab
10310@item
10311@tab
10312@tab
10313Where @var{<id>} is a thread-id in big-endian hex.
10314Obtain a printable string description of a thread's attributes from
10315the target OS. This string may contain anything that the target OS
10316thinks is interesting for @value{GDBN} to tell the user about the thread.
10317The string is displayed in @value{GDBN}'s @samp{info threads} display.
5d161b24 10318Some examples of possible thread extra info strings are "Runnable", or
bba2971c
MS
10319"Blocked on Mutex".
10320@item
10321@tab reply @var{XX...}
10322@tab
10323Where @var{XX...} is a hex encoding of @sc{ascii} data, comprising the
10324printable string containing the extra information about the thread's
10325attributes.
d4f3574e
SS
10326
10327@item query @var{LIST} or @var{threadLIST} @strong{(deprecated)}
10328@tab @code{q}@code{L}@var{startflag}@var{threadcount}@var{nextthread}
10329@tab
2b628194
MS
10330@item
10331@tab
10332@tab
d4f3574e
SS
10333Obtain thread information from RTOS. Where: @var{startflag} (one hex
10334digit) is one to indicate the first query and zero to indicate a
10335subsequent query; @var{threadcount} (two hex digits) is the maximum
10336number of threads the response packet can contain; and @var{nextthread}
10337(eight hex digits), for subsequent queries (@var{startflag} is zero), is
10338returned in the response as @var{argthread}.
10339@item
bba2971c
MS
10340@tab
10341@tab NOTE: this query is replaced by the @code{q}@code{fThreadInfo}
10342query (see above).
10343@item
d4f3574e
SS
10344@tab reply @code{q}@code{M}@var{count}@var{done}@var{argthread}@var{thread...}
10345@tab
2b628194
MS
10346@item
10347@tab
10348@tab
d4f3574e
SS
10349Where: @var{count} (two hex digits) is the number of threads being
10350returned; @var{done} (one hex digit) is zero to indicate more threads
10351and one indicates no further threads; @var{argthreadid} (eight hex
10352digits) is @var{nextthread} from the request packet; @var{thread...} is
10353a sequence of thread IDs from the target. @var{threadid} (eight hex
10354digits). See @code{remote.c:parse_threadlist_response()}.
10355
bba2971c
MS
10356@item compute CRC of memory block
10357@tab @code{q}@code{CRC:}@var{addr}@code{,}@var{length}
10358@tab
10359@item
10360@tab reply @code{E}@var{NN}
10361@tab An error (such as memory fault)
10362@item
10363@tab reply @code{C}@var{CRC32}
10364@tab A 32 bit cyclic redundancy check of the specified memory region.
10365
d4f3574e
SS
10366@item query sect offs
10367@tab @code{q}@code{Offsets}
917317f4
JM
10368@tab
10369Get section offsets that the target used when re-locating the downloaded
10370image. @emph{Note: while a @code{Bss} offset is included in the
10371response, @value{GDBN} ignores this and instead applies the @code{Data}
10372offset to the @code{Bss} section.}
d4f3574e
SS
10373@item
10374@tab reply @code{Text=}@var{xxx}@code{;Data=}@var{yyy}@code{;Bss=}@var{zzz}
10375
10376@item thread info request
10377@tab @code{q}@code{P}@var{mode}@var{threadid}
10378@tab
598ca718
EZ
10379@item
10380@tab
10381@tab
d4f3574e
SS
10382Returns information on @var{threadid}. Where: @var{mode} is a hex
10383encoded 32 bit mode; @var{threadid} is a hex encoded 64 bit thread ID.
10384@item
10385@tab reply *
10386@tab
10387See @code{remote.c:remote_unpack_thread_info_response()}.
10388
10389@item remote command
10390@tab @code{q}@code{Rcmd,}@var{COMMAND}
10391@tab
598ca718
EZ
10392@item
10393@tab
10394@tab
d4f3574e
SS
10395@var{COMMAND} (hex encoded) is passed to the local interpreter for
10396execution. Invalid commands should be reported using the output string.
10397Before the final result packet, the target may also respond with a
10398number of intermediate @code{O}@var{OUTPUT} console output
10399packets. @emph{Implementors should note that providing access to a
10400stubs's interpreter may have security implications}.
10401@item
10402@tab reply @code{OK}
10403@tab
10404A command response with no output.
10405@item
10406@tab reply @var{OUTPUT}
10407@tab
10408A command response with the hex encoded output string @var{OUTPUT}.
10409@item
10410@tab reply @code{E}@var{NN}
10411@tab
10412Indicate a badly formed request.
10413
10414@item
10415@tab reply @samp{}
10416@tab
10417When @samp{q}@samp{Rcmd} is not recognized.
10418
0f1f2b0a
MS
10419@item symbol lookup
10420@tab @code{qSymbol::}
10421@tab
10422Notify the target that @value{GDBN} is prepared to serve symbol lookup
10423requests. Accept requests from the target for the values of symbols.
10424@item
10425@tab
10426@tab
10427@item
10428@tab reply @code{OK}
10429@tab
10430The target does not need to look up any (more) symbols.
10431@item
10432@tab reply @code{qSymbol:}@var{sym_name}
10433@tab
10434The target requests the value of symbol @var{sym_name} (hex encoded).
10435@value{GDBN} may provide the value by using the
10436@code{qSymbol:}@var{sym_value}:@var{sym_name}
10437message, described below.
10438
10439@item symbol value
10440@tab @code{qSymbol:}@var{sym_value}:@var{sym_name}
10441@tab
10442Set the value of SYM_NAME to SYM_VALUE.
10443@item
10444@tab
10445@tab
10446@var{sym_name} (hex encoded) is the name of a symbol whose value
10447the target has previously requested.
10448@item
10449@tab
10450@tab
10451@var{sym_value} (hex) is the value for symbol @var{sym_name}.
10452If @value{GDBN} cannot supply a value for @var{sym_name}, then this
10453field will be empty.
10454@item
10455@tab reply @code{OK}
10456@tab
10457The target does not need to look up any (more) symbols.
10458@item
10459@tab reply @code{qSymbol:}@var{sym_name}
10460@tab
10461The target requests the value of a new symbol @var{sym_name} (hex encoded).
10462@value{GDBN} will continue to supply the values of symbols (if available),
10463until the target ceases to request them.
10464
d4f3574e
SS
10465@end multitable
10466
10467The following @samp{g}/@samp{G} packets have previously been defined.
10468In the below, some thirty-two bit registers are transferred as sixty-four
10469bits. Those registers should be zero/sign extended (which?) to fill the
10470space allocated. Register bytes are transfered in target byte order.
10471The two nibbles within a register byte are transfered most-significant -
10472least-significant.
10473
10474@multitable @columnfractions .5 .5
10475
10476@item MIPS32
10477@tab
10478All registers are transfered as thirty-two bit quantities in the order:
1047932 general-purpose; sr; lo; hi; bad; cause; pc; 32 floating-point
10480registers; fsr; fir; fp.
10481
10482@item MIPS64
10483@tab
10484All registers are transfered as sixty-four bit quantities (including
10485thirty-two bit registers such as @code{sr}). The ordering is the same
10486as @code{MIPS32}.
10487
10488@end multitable
10489
104c1213
JM
10490Example sequence of a target being re-started. Notice how the restart
10491does not get any direct output:
10492
10493@example
10494<- @code{R00}
10495-> @code{+}
10496@emph{target restarts}
10497<- @code{?}
10498-> @code{+}
10499-> @code{T001:1234123412341234}
10500<- @code{+}
10501@end example
10502
10503Example sequence of a target being stepped by a single instruction:
10504
10505@example
10506<- @code{G1445...}
10507-> @code{+}
10508<- @code{s}
10509-> @code{+}
10510@emph{time passes}
10511-> @code{T001:1234123412341234}
10512<- @code{+}
10513<- @code{g}
10514-> @code{+}
10515-> @code{1455...}
10516<- @code{+}
10517@end example
10518
6d2ebf8b 10519@node Server
104c1213
JM
10520@subsubsection Using the @code{gdbserver} program
10521
10522@kindex gdbserver
10523@cindex remote connection without stubs
10524@code{gdbserver} is a control program for Unix-like systems, which
10525allows you to connect your program with a remote @value{GDBN} via
10526@code{target remote}---but without linking in the usual debugging stub.
10527
10528@code{gdbserver} is not a complete replacement for the debugging stubs,
10529because it requires essentially the same operating-system facilities
10530that @value{GDBN} itself does. In fact, a system that can run
10531@code{gdbserver} to connect to a remote @value{GDBN} could also run
10532@value{GDBN} locally! @code{gdbserver} is sometimes useful nevertheless,
10533because it is a much smaller program than @value{GDBN} itself. It is
10534also easier to port than all of @value{GDBN}, so you may be able to get
10535started more quickly on a new system by using @code{gdbserver}.
10536Finally, if you develop code for real-time systems, you may find that
10537the tradeoffs involved in real-time operation make it more convenient to
10538do as much development work as possible on another system, for example
10539by cross-compiling. You can use @code{gdbserver} to make a similar
10540choice for debugging.
10541
10542@value{GDBN} and @code{gdbserver} communicate via either a serial line
10543or a TCP connection, using the standard @value{GDBN} remote serial
10544protocol.
10545
10546@table @emph
10547@item On the target machine,
10548you need to have a copy of the program you want to debug.
10549@code{gdbserver} does not need your program's symbol table, so you can
10550strip the program if necessary to save space. @value{GDBN} on the host
10551system does all the symbol handling.
10552
10553To use the server, you must tell it how to communicate with @value{GDBN};
10554the name of your program; and the arguments for your program. The
10555syntax is:
10556
10557@smallexample
10558target> gdbserver @var{comm} @var{program} [ @var{args} @dots{} ]
10559@end smallexample
10560
10561@var{comm} is either a device name (to use a serial line) or a TCP
10562hostname and portnumber. For example, to debug Emacs with the argument
10563@samp{foo.txt} and communicate with @value{GDBN} over the serial port
10564@file{/dev/com1}:
10565
10566@smallexample
10567target> gdbserver /dev/com1 emacs foo.txt
10568@end smallexample
10569
10570@code{gdbserver} waits passively for the host @value{GDBN} to communicate
10571with it.
10572
10573To use a TCP connection instead of a serial line:
10574
10575@smallexample
10576target> gdbserver host:2345 emacs foo.txt
10577@end smallexample
10578
10579The only difference from the previous example is the first argument,
10580specifying that you are communicating with the host @value{GDBN} via
10581TCP. The @samp{host:2345} argument means that @code{gdbserver} is to
10582expect a TCP connection from machine @samp{host} to local TCP port 2345.
10583(Currently, the @samp{host} part is ignored.) You can choose any number
10584you want for the port number as long as it does not conflict with any
10585TCP ports already in use on the target system (for example, @code{23} is
10586reserved for @code{telnet}).@footnote{If you choose a port number that
10587conflicts with another service, @code{gdbserver} prints an error message
d4f3574e 10588and exits.} You must use the same port number with the host @value{GDBN}
104c1213
JM
10589@code{target remote} command.
10590
10591@item On the @value{GDBN} host machine,
10592you need an unstripped copy of your program, since @value{GDBN} needs
10593symbols and debugging information. Start up @value{GDBN} as usual,
10594using the name of the local copy of your program as the first argument.
10595(You may also need the @w{@samp{--baud}} option if the serial line is
d4f3574e 10596running at anything other than 9600@dmn{bps}.) After that, use @code{target
104c1213
JM
10597remote} to establish communications with @code{gdbserver}. Its argument
10598is either a device name (usually a serial device, like
10599@file{/dev/ttyb}), or a TCP port descriptor in the form
10600@code{@var{host}:@var{PORT}}. For example:
10601
10602@smallexample
10603(@value{GDBP}) target remote /dev/ttyb
10604@end smallexample
10605
10606@noindent
10607communicates with the server via serial line @file{/dev/ttyb}, and
10608
10609@smallexample
10610(@value{GDBP}) target remote the-target:2345
10611@end smallexample
10612
10613@noindent
10614communicates via a TCP connection to port 2345 on host @w{@file{the-target}}.
10615For TCP connections, you must start up @code{gdbserver} prior to using
10616the @code{target remote} command. Otherwise you may get an error whose
10617text depends on the host system, but which usually looks something like
10618@samp{Connection refused}.
10619@end table
10620
6d2ebf8b 10621@node NetWare
104c1213
JM
10622@subsubsection Using the @code{gdbserve.nlm} program
10623
10624@kindex gdbserve.nlm
10625@code{gdbserve.nlm} is a control program for NetWare systems, which
10626allows you to connect your program with a remote @value{GDBN} via
10627@code{target remote}.
10628
10629@value{GDBN} and @code{gdbserve.nlm} communicate via a serial line,
10630using the standard @value{GDBN} remote serial protocol.
10631
10632@table @emph
10633@item On the target machine,
10634you need to have a copy of the program you want to debug.
10635@code{gdbserve.nlm} does not need your program's symbol table, so you
10636can strip the program if necessary to save space. @value{GDBN} on the
10637host system does all the symbol handling.
10638
10639To use the server, you must tell it how to communicate with
10640@value{GDBN}; the name of your program; and the arguments for your
10641program. The syntax is:
10642
5d161b24 10643@smallexample
104c1213
JM
10644load gdbserve [ BOARD=@var{board} ] [ PORT=@var{port} ]
10645 [ BAUD=@var{baud} ] @var{program} [ @var{args} @dots{} ]
10646@end smallexample
10647
10648@var{board} and @var{port} specify the serial line; @var{baud} specifies
10649the baud rate used by the connection. @var{port} and @var{node} default
d4f3574e 10650to 0, @var{baud} defaults to 9600@dmn{bps}.
104c1213
JM
10651
10652For example, to debug Emacs with the argument @samp{foo.txt}and
5d161b24 10653communicate with @value{GDBN} over serial port number 2 or board 1
d4f3574e 10654using a 19200@dmn{bps} connection:
104c1213
JM
10655
10656@smallexample
10657load gdbserve BOARD=1 PORT=2 BAUD=19200 emacs foo.txt
10658@end smallexample
10659
10660@item On the @value{GDBN} host machine,
10661you need an unstripped copy of your program, since @value{GDBN} needs
10662symbols and debugging information. Start up @value{GDBN} as usual,
10663using the name of the local copy of your program as the first argument.
10664(You may also need the @w{@samp{--baud}} option if the serial line is
d4f3574e 10665running at anything other than 9600@dmn{bps}. After that, use @code{target
104c1213
JM
10666remote} to establish communications with @code{gdbserve.nlm}. Its
10667argument is a device name (usually a serial device, like
10668@file{/dev/ttyb}). For example:
10669
10670@smallexample
10671(@value{GDBP}) target remote /dev/ttyb
10672@end smallexample
10673
10674@noindent
10675communications with the server via serial line @file{/dev/ttyb}.
10676@end table
10677
6d2ebf8b 10678@node KOD
104c1213
JM
10679@section Kernel Object Display
10680
10681@cindex kernel object display
10682@cindex kernel object
10683@cindex KOD
10684
10685Some targets support kernel object display. Using this facility,
10686@value{GDBN} communicates specially with the underlying operating system
10687and can display information about operating system-level objects such as
10688mutexes and other synchronization objects. Exactly which objects can be
10689displayed is determined on a per-OS basis.
10690
10691Use the @code{set os} command to set the operating system. This tells
10692@value{GDBN} which kernel object display module to initialize:
10693
10694@example
2df3850c 10695(@value{GDBP}) set os cisco
104c1213
JM
10696@end example
10697
10698If @code{set os} succeeds, @value{GDBN} will display some information
10699about the operating system, and will create a new @code{info} command
10700which can be used to query the target. The @code{info} command is named
10701after the operating system:
10702
10703@example
2df3850c 10704(@value{GDBP}) info cisco
104c1213
JM
10705List of Cisco Kernel Objects
10706Object Description
10707any Any and all objects
10708@end example
10709
10710Further subcommands can be used to query about particular objects known
10711by the kernel.
10712
10713There is currently no way to determine whether a given operating system
96baa820
JM
10714is supported other than to try it.
10715
10716
6d2ebf8b 10717@node Configurations
104c1213
JM
10718@chapter Configuration-Specific Information
10719
10720While nearly all @value{GDBN} commands are available for all native and
10721cross versions of the debugger, there are some exceptions. This chapter
10722describes things that are only available in certain configurations.
10723
10724There are three major categories of configurations: native
10725configurations, where the host and target are the same, embedded
10726operating system configurations, which are usually the same for several
10727different processor architectures, and bare embedded processors, which
10728are quite different from each other.
10729
10730@menu
10731* Native::
10732* Embedded OS::
10733* Embedded Processors::
10734* Architectures::
10735@end menu
10736
6d2ebf8b 10737@node Native
104c1213
JM
10738@section Native
10739
10740This section describes details specific to particular native
10741configurations.
10742
10743@menu
10744* HP-UX:: HP-UX
10745* SVR4 Process Information:: SVR4 process information
9f20bf26 10746* DJGPP Native:: Features specific to the DJGPP port
104c1213
JM
10747@end menu
10748
6d2ebf8b 10749@node HP-UX
104c1213
JM
10750@subsection HP-UX
10751
10752On HP-UX systems, if you refer to a function or variable name that
10753begins with a dollar sign, @value{GDBN} searches for a user or system
10754name first, before it searches for a convenience variable.
10755
6d2ebf8b 10756@node SVR4 Process Information
104c1213
JM
10757@subsection SVR4 process information
10758
10759@kindex /proc
10760@cindex process image
10761
10762Many versions of SVR4 provide a facility called @samp{/proc} that can be
10763used to examine the image of a running process using file-system
10764subroutines. If @value{GDBN} is configured for an operating system with
10765this facility, the command @code{info proc} is available to report on
10766several kinds of information about the process running your program.
10767@code{info proc} works only on SVR4 systems that include the
10768@code{procfs} code. This includes OSF/1 (Digital Unix), Solaris, Irix,
10769and Unixware, but not HP-UX or Linux, for example.
10770
10771@table @code
10772@kindex info proc
10773@item info proc
10774Summarize available information about the process.
10775
10776@kindex info proc mappings
10777@item info proc mappings
10778Report on the address ranges accessible in the program, with information
10779on whether your program may read, write, or execute each range.
10780
10781@kindex info proc times
10782@item info proc times
10783Starting time, user CPU time, and system CPU time for your program and
10784its children.
10785
10786@kindex info proc id
10787@item info proc id
10788Report on the process IDs related to your program: its own process ID,
10789the ID of its parent, the process group ID, and the session ID.
10790
10791@kindex info proc status
10792@item info proc status
10793General information on the state of the process. If the process is
10794stopped, this report includes the reason for stopping, and any signal
10795received.
10796
10797@item info proc all
10798Show all the above information about the process.
10799@end table
10800
9f20bf26
EZ
10801@node DJGPP Native
10802@subsection Features for Debugging @sc{djgpp} Programs
10803@cindex @sc{djgpp} debugging
10804@cindex native @sc{djgpp} debugging
10805@cindex MS-DOS-specific commands
10806
10807@sc{djgpp} is the port of @sc{gnu} development tools to MS-DOS and
10808MS-Windows. @sc{djgpp} programs are 32-bit protected-mode programs
10809that use the @dfn{DPMI} (DOS Protected-Mode Interface) API to run on
10810top of real-mode DOS systems and their emulations.
10811
10812@value{GDBN} supports native debugging of @sc{djgpp} programs, and
10813defines a few commands specific to the @sc{djgpp} port. This
10814subsection describes those commands.
10815
10816@table @code
10817@kindex info dos
10818@item info dos
10819This is a prefix of @sc{djgpp}-specific commands which print
10820information about the target system and important OS structures.
10821
10822@kindex sysinfo
10823@cindex MS-DOS system info
10824@cindex free memory information (MS-DOS)
10825@item info dos sysinfo
10826This command displays assorted information about the underlying
10827platform: the CPU type and features, the OS version and flavor, the
10828DPMI version, and the available conventional and DPMI memory.
10829
10830@cindex GDT
10831@cindex LDT
10832@cindex IDT
10833@cindex segment descriptor tables
10834@cindex descriptor tables display
10835@item info dos gdt
10836@itemx info dos ldt
10837@itemx info dos idt
10838These 3 commands display entries from, respectively, Global, Local,
10839and Interrupt Descriptor Tables (GDT, LDT, and IDT). The descriptor
10840tables are data structures which store a descriptor for each segment
10841that is currently in use. The segment's selector is an index into a
10842descriptor table; the table entry for that index holds the
10843descriptor's base address and limit, and its attributes and access
10844rights.
10845
10846A typical @sc{djgpp} program uses 3 segments: a code segment, a data
10847segment (used for both data and the stack), and a DOS segment (which
10848allows access to DOS/BIOS data structures and absolute addresses in
10849conventional memory). However, the DPMI host will usually define
10850additional segments in order to support the DPMI environment.
10851
10852@cindex garbled pointers
10853These commands allow to display entries from the descriptor tables.
10854Without an argument, all entries from the specified table are
10855displayed. An argument, which should be an integer expression, means
10856display a single entry whose index is given by the argument. For
10857example, here's a convenient way to display information about the
10858debugged program's data segment:
10859
10860@smallexample
10861(@value{GDBP}) info dos ldt $ds
108620x13f: base=0x11970000 limit=0x0009ffff 32-Bit Data (Read/Write, Exp-up)
10863@end smallexample
10864
10865@noindent
10866This comes in handy when you want to see whether a pointer is outside
10867the data segment's limit (i.e.@: @dfn{garbled}).
10868
10869@cindex page tables display (MS-DOS)
10870@item info dos pde
10871@itemx info dos pte
10872These two commands display entries from, respectively, the Page
10873Directory and the Page Tables. Page Directories and Page Tables are
10874data structures which control how virtual memory addresses are mapped
10875into physical addresses. A Page Table includes an entry for every
10876page of memory that is mapped into the program's address space; there
10877may be several Page Tables, each one holding up to 4096 entries. A
10878Page Directory has up to 4096 entries, one each for every Page Table
10879that is currently in use.
10880
10881Without an argument, @kbd{info dos pde} displays the entire Page
10882Directory, and @kbd{info dos pte} displays all the entries in all of
10883the Page Tables. An argument, an integer expression, given to the
10884@kbd{info dos pde} command means display only that entry from the Page
10885Directory table. An argument given to the @kbd{info dos pte} command
10886means display entries from a single Page Table, the one pointed to by
10887the specified entry in the Page Directory.
10888
10889These commands are useful when your program uses @dfn{DMA} (Direct
10890Memory Access), which needs physical addresses to program the DMA
10891controller.
10892
10893These commands are supported only with some DPMI servers.
10894
10895@cindex physical address from linear address
10896@item info dos address-pte
10897This command displays the Page Table entry for a specified linear
10898address. The argument linear address should already have the
10899appropriate segment's base address added to it, because this command
10900accepts addresses which may belong to @emph{any} segment. For
10901example, here's how to display the Page Table entry for the page where
10902the variable @code{i} is stored:
10903
10904@smallexample
10905(@value{GDBP}) info dos address-pte __djgpp_base_address + (char *)&i
10906Page Table entry for address 0x11a00d30:
10907Base=0x02698000 Dirty Acc. Not-Cached Write-Back Usr Read-Write +0xd30
10908@end smallexample
10909
10910@noindent
10911This says that @code{i} is stored at offset @code{0xd30} from the page
10912whose physical base address is @code{0x02698000}, and prints all the
10913attributes of that page.
10914
10915Note that you must cast the addresses of variables to a @code{char *},
10916since otherwise the value of @code{__djgpp_base_address}, the base
10917address of all variables and functions in a @sc{djgpp} program, will
10918be added using the rules of C pointer arithmetics: if @code{i} is
10919declared an @code{int}, @value{GDBN} will add 4 times the value of
10920@code{__djgpp_base_address} to the address of @code{i}.
10921
10922Here's another example, it displays the Page Table entry for the
10923transfer buffer:
10924
10925@smallexample
10926(@value{GDBP}) info dos address-pte *((unsigned *)&_go32_info_block + 3)
10927Page Table entry for address 0x29110:
10928Base=0x00029000 Dirty Acc. Not-Cached Write-Back Usr Read-Write +0x110
10929@end smallexample
10930
10931@noindent
10932(The @code{+ 3} offset is because the transfer buffer's address is the
109333rd member of the @code{_go32_info_block} structure.) The output of
10934this command clearly shows that addresses in conventional memory are
10935mapped 1:1, i.e.@: the physical and linear addresses are identical.
10936
10937This command is supported only with some DPMI servers.
10938@end table
10939
6d2ebf8b 10940@node Embedded OS
104c1213
JM
10941@section Embedded Operating Systems
10942
10943This section describes configurations involving the debugging of
10944embedded operating systems that are available for several different
10945architectures.
10946
10947@menu
10948* VxWorks:: Using @value{GDBN} with VxWorks
10949@end menu
10950
10951@value{GDBN} includes the ability to debug programs running on
10952various real-time operating systems.
10953
6d2ebf8b 10954@node VxWorks
104c1213
JM
10955@subsection Using @value{GDBN} with VxWorks
10956
10957@cindex VxWorks
10958
10959@table @code
10960
10961@kindex target vxworks
10962@item target vxworks @var{machinename}
10963A VxWorks system, attached via TCP/IP. The argument @var{machinename}
10964is the target system's machine name or IP address.
10965
10966@end table
10967
10968On VxWorks, @code{load} links @var{filename} dynamically on the
10969current target system as well as adding its symbols in @value{GDBN}.
10970
10971@value{GDBN} enables developers to spawn and debug tasks running on networked
10972VxWorks targets from a Unix host. Already-running tasks spawned from
10973the VxWorks shell can also be debugged. @value{GDBN} uses code that runs on
10974both the Unix host and on the VxWorks target. The program
d4f3574e 10975@code{@value{GDBP}} is installed and executed on the Unix host. (It may be
104c1213 10976installed with the name @code{vxgdb}, to distinguish it from a
96a2c332 10977@value{GDBN} for debugging programs on the host itself.)
104c1213
JM
10978
10979@table @code
10980@item VxWorks-timeout @var{args}
10981@kindex vxworks-timeout
5d161b24
DB
10982All VxWorks-based targets now support the option @code{vxworks-timeout}.
10983This option is set by the user, and @var{args} represents the number of
10984seconds @value{GDBN} waits for responses to rpc's. You might use this if
10985your VxWorks target is a slow software simulator or is on the far side
104c1213
JM
10986of a thin network line.
10987@end table
10988
10989The following information on connecting to VxWorks was current when
10990this manual was produced; newer releases of VxWorks may use revised
10991procedures.
10992
10993@kindex INCLUDE_RDB
10994To use @value{GDBN} with VxWorks, you must rebuild your VxWorks kernel
10995to include the remote debugging interface routines in the VxWorks
10996library @file{rdb.a}. To do this, define @code{INCLUDE_RDB} in the
10997VxWorks configuration file @file{configAll.h} and rebuild your VxWorks
10998kernel. The resulting kernel contains @file{rdb.a}, and spawns the
10999source debugging task @code{tRdbTask} when VxWorks is booted. For more
11000information on configuring and remaking VxWorks, see the manufacturer's
11001manual.
11002@c VxWorks, see the @cite{VxWorks Programmer's Guide}.
11003
11004Once you have included @file{rdb.a} in your VxWorks system image and set
11005your Unix execution search path to find @value{GDBN}, you are ready to
96a2c332
SS
11006run @value{GDBN}. From your Unix host, run @code{@value{GDBP}} (or
11007@code{vxgdb}, depending on your installation).
104c1213
JM
11008
11009@value{GDBN} comes up showing the prompt:
11010
11011@example
11012(vxgdb)
11013@end example
11014
11015@menu
11016* VxWorks Connection:: Connecting to VxWorks
11017* VxWorks Download:: VxWorks download
11018* VxWorks Attach:: Running tasks
11019@end menu
11020
6d2ebf8b 11021@node VxWorks Connection
104c1213
JM
11022@subsubsection Connecting to VxWorks
11023
11024The @value{GDBN} command @code{target} lets you connect to a VxWorks target on the
11025network. To connect to a target whose host name is ``@code{tt}'', type:
11026
11027@example
11028(vxgdb) target vxworks tt
11029@end example
11030
11031@need 750
11032@value{GDBN} displays messages like these:
11033
11034@smallexample
5d161b24 11035Attaching remote machine across net...
104c1213
JM
11036Connected to tt.
11037@end smallexample
11038
11039@need 1000
11040@value{GDBN} then attempts to read the symbol tables of any object modules
11041loaded into the VxWorks target since it was last booted. @value{GDBN} locates
11042these files by searching the directories listed in the command search
11043path (@pxref{Environment, ,Your program's environment}); if it fails
11044to find an object file, it displays a message such as:
11045
11046@example
11047prog.o: No such file or directory.
11048@end example
11049
11050When this happens, add the appropriate directory to the search path with
11051the @value{GDBN} command @code{path}, and execute the @code{target}
11052command again.
11053
6d2ebf8b 11054@node VxWorks Download
104c1213
JM
11055@subsubsection VxWorks download
11056
11057@cindex download to VxWorks
11058If you have connected to the VxWorks target and you want to debug an
11059object that has not yet been loaded, you can use the @value{GDBN}
11060@code{load} command to download a file from Unix to VxWorks
11061incrementally. The object file given as an argument to the @code{load}
11062command is actually opened twice: first by the VxWorks target in order
11063to download the code, then by @value{GDBN} in order to read the symbol
11064table. This can lead to problems if the current working directories on
11065the two systems differ. If both systems have NFS mounted the same
11066filesystems, you can avoid these problems by using absolute paths.
11067Otherwise, it is simplest to set the working directory on both systems
11068to the directory in which the object file resides, and then to reference
11069the file by its name, without any path. For instance, a program
11070@file{prog.o} may reside in @file{@var{vxpath}/vw/demo/rdb} in VxWorks
11071and in @file{@var{hostpath}/vw/demo/rdb} on the host. To load this
11072program, type this on VxWorks:
11073
11074@example
11075-> cd "@var{vxpath}/vw/demo/rdb"
11076@end example
d4f3574e
SS
11077
11078@noindent
104c1213
JM
11079Then, in @value{GDBN}, type:
11080
11081@example
5d161b24 11082(vxgdb) cd @var{hostpath}/vw/demo/rdb
104c1213
JM
11083(vxgdb) load prog.o
11084@end example
11085
11086@value{GDBN} displays a response similar to this:
11087
11088@smallexample
11089Reading symbol data from wherever/vw/demo/rdb/prog.o... done.
11090@end smallexample
11091
11092You can also use the @code{load} command to reload an object module
11093after editing and recompiling the corresponding source file. Note that
11094this makes @value{GDBN} delete all currently-defined breakpoints,
11095auto-displays, and convenience variables, and to clear the value
11096history. (This is necessary in order to preserve the integrity of
d4f3574e 11097debugger's data structures that reference the target system's symbol
104c1213
JM
11098table.)
11099
6d2ebf8b 11100@node VxWorks Attach
104c1213
JM
11101@subsubsection Running tasks
11102
11103@cindex running VxWorks tasks
11104You can also attach to an existing task using the @code{attach} command as
11105follows:
11106
11107@example
11108(vxgdb) attach @var{task}
11109@end example
11110
11111@noindent
11112where @var{task} is the VxWorks hexadecimal task ID. The task can be running
11113or suspended when you attach to it. Running tasks are suspended at
11114the time of attachment.
11115
6d2ebf8b 11116@node Embedded Processors
104c1213
JM
11117@section Embedded Processors
11118
11119This section goes into details specific to particular embedded
11120configurations.
11121
11122@menu
11123* A29K Embedded:: AMD A29K Embedded
11124* ARM:: ARM
11125* H8/300:: Hitachi H8/300
11126* H8/500:: Hitachi H8/500
11127* i960:: Intel i960
11128* M32R/D:: Mitsubishi M32R/D
11129* M68K:: Motorola M68K
11130* M88K:: Motorola M88K
11131* MIPS Embedded:: MIPS Embedded
11132* PA:: HP PA Embedded
11133* PowerPC: PowerPC
11134* SH:: Hitachi SH
11135* Sparclet:: Tsqware Sparclet
11136* Sparclite:: Fujitsu Sparclite
11137* ST2000:: Tandem ST2000
11138* Z8000:: Zilog Z8000
11139@end menu
11140
6d2ebf8b 11141@node A29K Embedded
104c1213
JM
11142@subsection AMD A29K Embedded
11143
11144@menu
11145* A29K UDI::
11146* A29K EB29K::
11147* Comms (EB29K):: Communications setup
11148* gdb-EB29K:: EB29K cross-debugging
11149* Remote Log:: Remote log
11150@end menu
11151
11152@table @code
11153
11154@kindex target adapt
11155@item target adapt @var{dev}
11156Adapt monitor for A29K.
11157
11158@kindex target amd-eb
11159@item target amd-eb @var{dev} @var{speed} @var{PROG}
11160@cindex AMD EB29K
11161Remote PC-resident AMD EB29K board, attached over serial lines.
11162@var{dev} is the serial device, as for @code{target remote};
11163@var{speed} allows you to specify the linespeed; and @var{PROG} is the
11164name of the program to be debugged, as it appears to DOS on the PC.
11165@xref{A29K EB29K, ,EBMON protocol for AMD29K}.
11166
11167@end table
11168
6d2ebf8b 11169@node A29K UDI
104c1213
JM
11170@subsubsection A29K UDI
11171
11172@cindex UDI
11173@cindex AMD29K via UDI
11174
11175@value{GDBN} supports AMD's UDI (``Universal Debugger Interface'')
11176protocol for debugging the a29k processor family. To use this
11177configuration with AMD targets running the MiniMON monitor, you need the
11178program @code{MONTIP}, available from AMD at no charge. You can also
11179use @value{GDBN} with the UDI-conformant a29k simulator program
11180@code{ISSTIP}, also available from AMD.
11181
11182@table @code
11183@item target udi @var{keyword}
11184@kindex udi
11185Select the UDI interface to a remote a29k board or simulator, where
11186@var{keyword} is an entry in the AMD configuration file @file{udi_soc}.
11187This file contains keyword entries which specify parameters used to
11188connect to a29k targets. If the @file{udi_soc} file is not in your
11189working directory, you must set the environment variable @samp{UDICONF}
11190to its pathname.
11191@end table
11192
6d2ebf8b 11193@node A29K EB29K
104c1213
JM
11194@subsubsection EBMON protocol for AMD29K
11195
11196@cindex EB29K board
11197@cindex running 29K programs
11198
11199AMD distributes a 29K development board meant to fit in a PC, together
11200with a DOS-hosted monitor program called @code{EBMON}. As a shorthand
11201term, this development system is called the ``EB29K''. To use
11202@value{GDBN} from a Unix system to run programs on the EB29K board, you
11203must first connect a serial cable between the PC (which hosts the EB29K
11204board) and a serial port on the Unix system. In the following, we
11205assume you've hooked the cable between the PC's @file{COM1} port and
11206@file{/dev/ttya} on the Unix system.
11207
6d2ebf8b 11208@node Comms (EB29K)
104c1213
JM
11209@subsubsection Communications setup
11210
11211The next step is to set up the PC's port, by doing something like this
11212in DOS on the PC:
11213
11214@example
11215C:\> MODE com1:9600,n,8,1,none
11216@end example
11217
11218@noindent
11219This example---run on an MS DOS 4.0 system---sets the PC port to 9600
11220bps, no parity, eight data bits, one stop bit, and no ``retry'' action;
11221you must match the communications parameters when establishing the Unix
11222end of the connection as well.
11223@c FIXME: Who knows what this "no retry action" crud from the DOS manual may
5d161b24 11224@c mean? It's optional; leave it out? ---doc@cygnus.com, 25feb91
d4f3574e
SS
11225@c
11226@c It's optional, but it's unwise to omit it: who knows what is the
11227@c default value set when the DOS machines boots? "No retry" means that
11228@c the DOS serial device driver won't retry the operation if it fails;
11229@c I understand that this is needed because the GDB serial protocol
11230@c handles any errors and retransmissions itself. ---Eli Zaretskii, 3sep99
104c1213
JM
11231
11232To give control of the PC to the Unix side of the serial line, type
11233the following at the DOS console:
11234
11235@example
11236C:\> CTTY com1
11237@end example
11238
11239@noindent
11240(Later, if you wish to return control to the DOS console, you can use
11241the command @code{CTTY con}---but you must send it over the device that
96a2c332 11242had control, in our example over the @file{COM1} serial line.)
104c1213
JM
11243
11244From the Unix host, use a communications program such as @code{tip} or
11245@code{cu} to communicate with the PC; for example,
11246
11247@example
11248cu -s 9600 -l /dev/ttya
11249@end example
11250
11251@noindent
11252The @code{cu} options shown specify, respectively, the linespeed and the
11253serial port to use. If you use @code{tip} instead, your command line
11254may look something like the following:
11255
11256@example
11257tip -9600 /dev/ttya
11258@end example
11259
11260@noindent
11261Your system may require a different name where we show
11262@file{/dev/ttya} as the argument to @code{tip}. The communications
11263parameters, including which port to use, are associated with the
11264@code{tip} argument in the ``remote'' descriptions file---normally the
11265system table @file{/etc/remote}.
11266@c FIXME: What if anything needs doing to match the "n,8,1,none" part of
11267@c the DOS side's comms setup? cu can support -o (odd
11268@c parity), -e (even parity)---apparently no settings for no parity or
11269@c for character size. Taken from stty maybe...? John points out tip
11270@c can set these as internal variables, eg ~s parity=none; man stty
11271@c suggests that it *might* work to stty these options with stdin or
11272@c stdout redirected... ---doc@cygnus.com, 25feb91
d4f3574e
SS
11273@c
11274@c There's nothing to be done for the "none" part of the DOS MODE
11275@c command. The rest of the parameters should be matched by the
11276@c baudrate, bits, and parity used by the Unix side. ---Eli Zaretskii, 3Sep99
104c1213
JM
11277
11278@kindex EBMON
11279Using the @code{tip} or @code{cu} connection, change the DOS working
11280directory to the directory containing a copy of your 29K program, then
11281start the PC program @code{EBMON} (an EB29K control program supplied
11282with your board by AMD). You should see an initial display from
11283@code{EBMON} similar to the one that follows, ending with the
11284@code{EBMON} prompt @samp{#}---
11285
11286@example
11287C:\> G:
11288
11289G:\> CD \usr\joe\work29k
11290
11291G:\USR\JOE\WORK29K> EBMON
11292Am29000 PC Coprocessor Board Monitor, version 3.0-18
11293Copyright 1990 Advanced Micro Devices, Inc.
11294Written by Gibbons and Associates, Inc.
11295
11296Enter '?' or 'H' for help
11297
11298PC Coprocessor Type = EB29K
11299I/O Base = 0x208
11300Memory Base = 0xd0000
11301
11302Data Memory Size = 2048KB
11303Available I-RAM Range = 0x8000 to 0x1fffff
11304Available D-RAM Range = 0x80002000 to 0x801fffff
11305
11306PageSize = 0x400
11307Register Stack Size = 0x800
11308Memory Stack Size = 0x1800
11309
11310CPU PRL = 0x3
11311Am29027 Available = No
11312Byte Write Available = Yes
11313
11314# ~.
11315@end example
11316
11317Then exit the @code{cu} or @code{tip} program (done in the example by
11318typing @code{~.} at the @code{EBMON} prompt). @code{EBMON} keeps
11319running, ready for @value{GDBN} to take over.
11320
11321For this example, we've assumed what is probably the most convenient
11322way to make sure the same 29K program is on both the PC and the Unix
d4f3574e 11323system: a PC/NFS connection that establishes ``drive @file{G:}'' on the
104c1213
JM
11324PC as a file system on the Unix host. If you do not have PC/NFS or
11325something similar connecting the two systems, you must arrange some
11326other way---perhaps floppy-disk transfer---of getting the 29K program
11327from the Unix system to the PC; @value{GDBN} does @emph{not} download it over the
11328serial line.
11329
6d2ebf8b 11330@node gdb-EB29K
104c1213
JM
11331@subsubsection EB29K cross-debugging
11332
11333Finally, @code{cd} to the directory containing an image of your 29K
11334program on the Unix system, and start @value{GDBN}---specifying as argument the
11335name of your 29K program:
11336
11337@example
11338cd /usr/joe/work29k
11339@value{GDBP} myfoo
11340@end example
11341
11342@need 500
11343Now you can use the @code{target} command:
11344
11345@example
11346target amd-eb /dev/ttya 9600 MYFOO
11347@c FIXME: test above 'target amd-eb' as spelled, with caps! caps are meant to
11348@c emphasize that this is the name as seen by DOS (since I think DOS is
11349@c single-minded about case of letters). ---doc@cygnus.com, 25feb91
11350@end example
11351
11352@noindent
11353In this example, we've assumed your program is in a file called
11354@file{myfoo}. Note that the filename given as the last argument to
11355@code{target amd-eb} should be the name of the program as it appears to DOS.
11356In our example this is simply @code{MYFOO}, but in general it can include
11357a DOS path, and depending on your transfer mechanism may not resemble
11358the name on the Unix side.
11359
11360At this point, you can set any breakpoints you wish; when you are ready
11361to see your program run on the 29K board, use the @value{GDBN} command
11362@code{run}.
11363
11364To stop debugging the remote program, use the @value{GDBN} @code{detach}
11365command.
11366
11367To return control of the PC to its console, use @code{tip} or @code{cu}
11368once again, after your @value{GDBN} session has concluded, to attach to
11369@code{EBMON}. You can then type the command @code{q} to shut down
11370@code{EBMON}, returning control to the DOS command-line interpreter.
d4f3574e 11371Type @kbd{CTTY con} to return command input to the main DOS console,
104c1213
JM
11372and type @kbd{~.} to leave @code{tip} or @code{cu}.
11373
6d2ebf8b 11374@node Remote Log
104c1213 11375@subsubsection Remote log
41afff9a 11376@cindex @file{eb.log}, a log file for EB29K
104c1213
JM
11377@cindex log file for EB29K
11378
11379The @code{target amd-eb} command creates a file @file{eb.log} in the
11380current working directory, to help debug problems with the connection.
11381@file{eb.log} records all the output from @code{EBMON}, including echoes
11382of the commands sent to it. Running @samp{tail -f} on this file in
11383another window often helps to understand trouble with @code{EBMON}, or
11384unexpected events on the PC side of the connection.
11385
6d2ebf8b 11386@node ARM
104c1213
JM
11387@subsection ARM
11388
11389@table @code
11390
11391@kindex target rdi
11392@item target rdi @var{dev}
11393ARM Angel monitor, via RDI library interface to ADP protocol. You may
11394use this target to communicate with both boards running the Angel
11395monitor, or with the EmbeddedICE JTAG debug device.
5d161b24 11396
104c1213
JM
11397@kindex target rdp
11398@item target rdp @var{dev}
11399ARM Demon monitor.
11400
11401@end table
11402
6d2ebf8b 11403@node H8/300
104c1213
JM
11404@subsection Hitachi H8/300
11405
11406@table @code
11407
d4f3574e 11408@kindex target hms@r{, with H8/300}
104c1213
JM
11409@item target hms @var{dev}
11410A Hitachi SH, H8/300, or H8/500 board, attached via serial line to your host.
11411Use special commands @code{device} and @code{speed} to control the serial
11412line and the communications speed used.
11413
d4f3574e 11414@kindex target e7000@r{, with H8/300}
104c1213
JM
11415@item target e7000 @var{dev}
11416E7000 emulator for Hitachi H8 and SH.
11417
d4f3574e
SS
11418@kindex target sh3@r{, with H8/300}
11419@kindex target sh3e@r{, with H8/300}
104c1213 11420@item target sh3 @var{dev}
96a2c332 11421@itemx target sh3e @var{dev}
104c1213
JM
11422Hitachi SH-3 and SH-3E target systems.
11423
11424@end table
11425
11426@cindex download to H8/300 or H8/500
11427@cindex H8/300 or H8/500 download
11428@cindex download to Hitachi SH
11429@cindex Hitachi SH download
11430When you select remote debugging to a Hitachi SH, H8/300, or H8/500
11431board, the @code{load} command downloads your program to the Hitachi
11432board and also opens it as the current executable target for
11433@value{GDBN} on your host (like the @code{file} command).
11434
11435@value{GDBN} needs to know these things to talk to your
5d161b24 11436Hitachi SH, H8/300, or H8/500:
104c1213
JM
11437
11438@enumerate
11439@item
11440that you want to use @samp{target hms}, the remote debugging interface
11441for Hitachi microprocessors, or @samp{target e7000}, the in-circuit
11442emulator for the Hitachi SH and the Hitachi 300H. (@samp{target hms} is
2df3850c 11443the default when @value{GDBN} is configured specifically for the Hitachi SH,
104c1213
JM
11444H8/300, or H8/500.)
11445
11446@item
11447what serial device connects your host to your Hitachi board (the first
11448serial device available on your host is the default).
11449
11450@item
11451what speed to use over the serial device.
11452@end enumerate
11453
11454@menu
11455* Hitachi Boards:: Connecting to Hitachi boards.
11456* Hitachi ICE:: Using the E7000 In-Circuit Emulator.
11457* Hitachi Special:: Special @value{GDBN} commands for Hitachi micros.
11458@end menu
11459
6d2ebf8b 11460@node Hitachi Boards
104c1213
JM
11461@subsubsection Connecting to Hitachi boards
11462
11463@c only for Unix hosts
11464@kindex device
11465@cindex serial device, Hitachi micros
96a2c332 11466Use the special @code{@value{GDBN}} command @samp{device @var{port}} if you
104c1213
JM
11467need to explicitly set the serial device. The default @var{port} is the
11468first available port on your host. This is only necessary on Unix
11469hosts, where it is typically something like @file{/dev/ttya}.
11470
11471@kindex speed
11472@cindex serial line speed, Hitachi micros
96a2c332 11473@code{@value{GDBN}} has another special command to set the communications
104c1213 11474speed: @samp{speed @var{bps}}. This command also is only used from Unix
2df3850c 11475hosts; on DOS hosts, set the line speed as usual from outside @value{GDBN} with
d4f3574e
SS
11476the DOS @code{mode} command (for instance,
11477@w{@kbd{mode com2:9600,n,8,1,p}} for a 9600@dmn{bps} connection).
104c1213
JM
11478
11479The @samp{device} and @samp{speed} commands are available only when you
11480use a Unix host to debug your Hitachi microprocessor programs. If you
11481use a DOS host,
11482@value{GDBN} depends on an auxiliary terminate-and-stay-resident program
11483called @code{asynctsr} to communicate with the development board
11484through a PC serial port. You must also use the DOS @code{mode} command
11485to set up the serial port on the DOS side.
11486
11487The following sample session illustrates the steps needed to start a
11488program under @value{GDBN} control on an H8/300. The example uses a
11489sample H8/300 program called @file{t.x}. The procedure is the same for
11490the Hitachi SH and the H8/500.
11491
11492First hook up your development board. In this example, we use a
11493board attached to serial port @code{COM2}; if you use a different serial
11494port, substitute its name in the argument of the @code{mode} command.
11495When you call @code{asynctsr}, the auxiliary comms program used by the
d4f3574e 11496debugger, you give it just the numeric part of the serial port's name;
104c1213
JM
11497for example, @samp{asyncstr 2} below runs @code{asyncstr} on
11498@code{COM2}.
11499
11500@example
11501C:\H8300\TEST> asynctsr 2
11502C:\H8300\TEST> mode com2:9600,n,8,1,p
11503
11504Resident portion of MODE loaded
11505
11506COM2: 9600, n, 8, 1, p
11507
11508@end example
11509
11510@quotation
11511@emph{Warning:} We have noticed a bug in PC-NFS that conflicts with
11512@code{asynctsr}. If you also run PC-NFS on your DOS host, you may need to
11513disable it, or even boot without it, to use @code{asynctsr} to control
11514your development board.
11515@end quotation
11516
d4f3574e 11517@kindex target hms@r{, and serial protocol}
104c1213
JM
11518Now that serial communications are set up, and the development board is
11519connected, you can start up @value{GDBN}. Call @code{@value{GDBP}} with
96a2c332 11520the name of your program as the argument. @code{@value{GDBN}} prompts
104c1213
JM
11521you, as usual, with the prompt @samp{(@value{GDBP})}. Use two special
11522commands to begin your debugging session: @samp{target hms} to specify
11523cross-debugging to the Hitachi board, and the @code{load} command to
11524download your program to the board. @code{load} displays the names of
11525the program's sections, and a @samp{*} for each 2K of data downloaded.
11526(If you want to refresh @value{GDBN} data on symbols or on the
11527executable file without downloading, use the @value{GDBN} commands
11528@code{file} or @code{symbol-file}. These commands, and @code{load}
11529itself, are described in @ref{Files,,Commands to specify files}.)
11530
11531@smallexample
11532(eg-C:\H8300\TEST) @value{GDBP} t.x
2df3850c 11533@value{GDBN} is free software and you are welcome to distribute copies
5d161b24 11534 of it under certain conditions; type "show copying" to see
104c1213 11535 the conditions.
5d161b24 11536There is absolutely no warranty for @value{GDBN}; type "show warranty"
104c1213 11537for details.
2df3850c
JM
11538@value{GDBN} @value{GDBVN}, Copyright 1992 Free Software Foundation, Inc...
11539(@value{GDBP}) target hms
104c1213 11540Connected to remote H8/300 HMS system.
2df3850c 11541(@value{GDBP}) load t.x
104c1213
JM
11542.text : 0x8000 .. 0xabde ***********
11543.data : 0xabde .. 0xad30 *
11544.stack : 0xf000 .. 0xf014 *
11545@end smallexample
11546
11547At this point, you're ready to run or debug your program. From here on,
11548you can use all the usual @value{GDBN} commands. The @code{break} command
11549sets breakpoints; the @code{run} command starts your program;
11550@code{print} or @code{x} display data; the @code{continue} command
11551resumes execution after stopping at a breakpoint. You can use the
11552@code{help} command at any time to find out more about @value{GDBN} commands.
11553
11554Remember, however, that @emph{operating system} facilities aren't
11555available on your development board; for example, if your program hangs,
11556you can't send an interrupt---but you can press the @sc{reset} switch!
11557
11558Use the @sc{reset} button on the development board
11559@itemize @bullet
11560@item
11561to interrupt your program (don't use @kbd{ctl-C} on the DOS host---it has
11562no way to pass an interrupt signal to the development board); and
11563
11564@item
11565to return to the @value{GDBN} command prompt after your program finishes
11566normally. The communications protocol provides no other way for @value{GDBN}
11567to detect program completion.
11568@end itemize
11569
11570In either case, @value{GDBN} sees the effect of a @sc{reset} on the
11571development board as a ``normal exit'' of your program.
11572
6d2ebf8b 11573@node Hitachi ICE
104c1213
JM
11574@subsubsection Using the E7000 in-circuit emulator
11575
d4f3574e 11576@kindex target e7000@r{, with Hitachi ICE}
104c1213
JM
11577You can use the E7000 in-circuit emulator to develop code for either the
11578Hitachi SH or the H8/300H. Use one of these forms of the @samp{target
11579e7000} command to connect @value{GDBN} to your E7000:
11580
11581@table @code
11582@item target e7000 @var{port} @var{speed}
11583Use this form if your E7000 is connected to a serial port. The
11584@var{port} argument identifies what serial port to use (for example,
11585@samp{com2}). The third argument is the line speed in bits per second
11586(for example, @samp{9600}).
11587
11588@item target e7000 @var{hostname}
11589If your E7000 is installed as a host on a TCP/IP network, you can just
11590specify its hostname; @value{GDBN} uses @code{telnet} to connect.
11591@end table
11592
6d2ebf8b 11593@node Hitachi Special
104c1213
JM
11594@subsubsection Special @value{GDBN} commands for Hitachi micros
11595
11596Some @value{GDBN} commands are available only for the H8/300:
11597
11598@table @code
11599
11600@kindex set machine
11601@kindex show machine
11602@item set machine h8300
11603@itemx set machine h8300h
11604Condition @value{GDBN} for one of the two variants of the H8/300
11605architecture with @samp{set machine}. You can use @samp{show machine}
11606to check which variant is currently in effect.
11607
11608@end table
11609
6d2ebf8b 11610@node H8/500
104c1213
JM
11611@subsection H8/500
11612
11613@table @code
11614
11615@kindex set memory @var{mod}
11616@cindex memory models, H8/500
11617@item set memory @var{mod}
11618@itemx show memory
11619Specify which H8/500 memory model (@var{mod}) you are using with
11620@samp{set memory}; check which memory model is in effect with @samp{show
11621memory}. The accepted values for @var{mod} are @code{small},
11622@code{big}, @code{medium}, and @code{compact}.
11623
11624@end table
11625
6d2ebf8b 11626@node i960
104c1213
JM
11627@subsection Intel i960
11628
11629@table @code
11630
11631@kindex target mon960
11632@item target mon960 @var{dev}
11633MON960 monitor for Intel i960.
11634
f0ca3dce 11635@kindex target nindy
104c1213
JM
11636@item target nindy @var{devicename}
11637An Intel 960 board controlled by a Nindy Monitor. @var{devicename} is
11638the name of the serial device to use for the connection, e.g.
11639@file{/dev/ttya}.
11640
11641@end table
11642
11643@cindex Nindy
11644@cindex i960
11645@dfn{Nindy} is a ROM Monitor program for Intel 960 target systems. When
11646@value{GDBN} is configured to control a remote Intel 960 using Nindy, you can
11647tell @value{GDBN} how to connect to the 960 in several ways:
11648
11649@itemize @bullet
11650@item
11651Through command line options specifying serial port, version of the
11652Nindy protocol, and communications speed;
11653
11654@item
11655By responding to a prompt on startup;
11656
11657@item
11658By using the @code{target} command at any point during your @value{GDBN}
11659session. @xref{Target Commands, ,Commands for managing targets}.
11660
104c1213
JM
11661@end itemize
11662
11663@cindex download to Nindy-960
11664With the Nindy interface to an Intel 960 board, @code{load}
11665downloads @var{filename} to the 960 as well as adding its symbols in
11666@value{GDBN}.
11667
11668@menu
11669* Nindy Startup:: Startup with Nindy
11670* Nindy Options:: Options for Nindy
11671* Nindy Reset:: Nindy reset command
11672@end menu
11673
6d2ebf8b 11674@node Nindy Startup
104c1213
JM
11675@subsubsection Startup with Nindy
11676
11677If you simply start @code{@value{GDBP}} without using any command-line
11678options, you are prompted for what serial port to use, @emph{before} you
11679reach the ordinary @value{GDBN} prompt:
11680
11681@example
5d161b24 11682Attach /dev/ttyNN -- specify NN, or "quit" to quit:
104c1213
JM
11683@end example
11684
11685@noindent
11686Respond to the prompt with whatever suffix (after @samp{/dev/tty})
11687identifies the serial port you want to use. You can, if you choose,
11688simply start up with no Nindy connection by responding to the prompt
11689with an empty line. If you do this and later wish to attach to Nindy,
11690use @code{target} (@pxref{Target Commands, ,Commands for managing targets}).
11691
6d2ebf8b 11692@node Nindy Options
104c1213
JM
11693@subsubsection Options for Nindy
11694
11695These are the startup options for beginning your @value{GDBN} session with a
11696Nindy-960 board attached:
11697
11698@table @code
11699@item -r @var{port}
11700Specify the serial port name of a serial interface to be used to connect
11701to the target system. This option is only available when @value{GDBN} is
11702configured for the Intel 960 target architecture. You may specify
11703@var{port} as any of: a full pathname (e.g. @samp{-r /dev/ttya}), a
11704device name in @file{/dev} (e.g. @samp{-r ttya}), or simply the unique
11705suffix for a specific @code{tty} (e.g. @samp{-r a}).
11706
11707@item -O
11708(An uppercase letter ``O'', not a zero.) Specify that @value{GDBN} should use
11709the ``old'' Nindy monitor protocol to connect to the target system.
11710This option is only available when @value{GDBN} is configured for the Intel 960
11711target architecture.
11712
11713@quotation
11714@emph{Warning:} if you specify @samp{-O}, but are actually trying to
11715connect to a target system that expects the newer protocol, the connection
11716fails, appearing to be a speed mismatch. @value{GDBN} repeatedly
11717attempts to reconnect at several different line speeds. You can abort
11718this process with an interrupt.
11719@end quotation
11720
11721@item -brk
11722Specify that @value{GDBN} should first send a @code{BREAK} signal to the target
11723system, in an attempt to reset it, before connecting to a Nindy target.
11724
11725@quotation
11726@emph{Warning:} Many target systems do not have the hardware that this
11727requires; it only works with a few boards.
11728@end quotation
11729@end table
11730
11731The standard @samp{-b} option controls the line speed used on the serial
11732port.
11733
11734@c @group
6d2ebf8b 11735@node Nindy Reset
104c1213
JM
11736@subsubsection Nindy reset command
11737
11738@table @code
11739@item reset
11740@kindex reset
11741For a Nindy target, this command sends a ``break'' to the remote target
11742system; this is only useful if the target has been equipped with a
11743circuit to perform a hard reset (or some other interesting action) when
11744a break is detected.
11745@end table
11746@c @end group
11747
6d2ebf8b 11748@node M32R/D
104c1213
JM
11749@subsection Mitsubishi M32R/D
11750
11751@table @code
11752
11753@kindex target m32r
11754@item target m32r @var{dev}
11755Mitsubishi M32R/D ROM monitor.
11756
11757@end table
11758
6d2ebf8b 11759@node M68K
104c1213
JM
11760@subsection M68k
11761
11762The Motorola m68k configuration includes ColdFire support, and
11763target command for the following ROM monitors.
11764
11765@table @code
11766
11767@kindex target abug
11768@item target abug @var{dev}
11769ABug ROM monitor for M68K.
11770
11771@kindex target cpu32bug
11772@item target cpu32bug @var{dev}
11773CPU32BUG monitor, running on a CPU32 (M68K) board.
11774
11775@kindex target dbug
11776@item target dbug @var{dev}
11777dBUG ROM monitor for Motorola ColdFire.
11778
11779@kindex target est
11780@item target est @var{dev}
11781EST-300 ICE monitor, running on a CPU32 (M68K) board.
11782
11783@kindex target rom68k
11784@item target rom68k @var{dev}
11785ROM 68K monitor, running on an M68K IDP board.
11786
11787@end table
11788
11789If @value{GDBN} is configured with @code{m68*-ericsson-*}, it will
11790instead have only a single special target command:
11791
11792@table @code
11793
11794@kindex target es1800
11795@item target es1800 @var{dev}
11796ES-1800 emulator for M68K.
11797
11798@end table
11799
11800[context?]
11801
11802@table @code
11803
11804@kindex target rombug
11805@item target rombug @var{dev}
11806ROMBUG ROM monitor for OS/9000.
11807
11808@end table
11809
6d2ebf8b 11810@node M88K
104c1213
JM
11811@subsection M88K
11812
11813@table @code
11814
11815@kindex target bug
11816@item target bug @var{dev}
11817BUG monitor, running on a MVME187 (m88k) board.
11818
11819@end table
11820
6d2ebf8b 11821@node MIPS Embedded
104c1213
JM
11822@subsection MIPS Embedded
11823
11824@cindex MIPS boards
11825@value{GDBN} can use the MIPS remote debugging protocol to talk to a
11826MIPS board attached to a serial line. This is available when
11827you configure @value{GDBN} with @samp{--target=mips-idt-ecoff}.
11828
11829@need 1000
11830Use these @value{GDBN} commands to specify the connection to your target board:
11831
11832@table @code
11833@item target mips @var{port}
11834@kindex target mips @var{port}
11835To run a program on the board, start up @code{@value{GDBP}} with the
11836name of your program as the argument. To connect to the board, use the
11837command @samp{target mips @var{port}}, where @var{port} is the name of
11838the serial port connected to the board. If the program has not already
11839been downloaded to the board, you may use the @code{load} command to
11840download it. You can then use all the usual @value{GDBN} commands.
11841
11842For example, this sequence connects to the target board through a serial
11843port, and loads and runs a program called @var{prog} through the
11844debugger:
11845
11846@example
11847host$ @value{GDBP} @var{prog}
2df3850c
JM
11848@value{GDBN} is free software and @dots{}
11849(@value{GDBP}) target mips /dev/ttyb
11850(@value{GDBP}) load @var{prog}
11851(@value{GDBP}) run
104c1213
JM
11852@end example
11853
11854@item target mips @var{hostname}:@var{portnumber}
11855On some @value{GDBN} host configurations, you can specify a TCP
11856connection (for instance, to a serial line managed by a terminal
11857concentrator) instead of a serial port, using the syntax
11858@samp{@var{hostname}:@var{portnumber}}.
11859
11860@item target pmon @var{port}
11861@kindex target pmon @var{port}
11862PMON ROM monitor.
11863
11864@item target ddb @var{port}
11865@kindex target ddb @var{port}
11866NEC's DDB variant of PMON for Vr4300.
11867
11868@item target lsi @var{port}
11869@kindex target lsi @var{port}
11870LSI variant of PMON.
11871
11872@kindex target r3900
11873@item target r3900 @var{dev}
11874Densan DVE-R3900 ROM monitor for Toshiba R3900 Mips.
11875
11876@kindex target array
11877@item target array @var{dev}
11878Array Tech LSI33K RAID controller board.
11879
11880@end table
11881
11882
11883@noindent
11884@value{GDBN} also supports these special commands for MIPS targets:
11885
11886@table @code
11887@item set processor @var{args}
11888@itemx show processor
11889@kindex set processor @var{args}
11890@kindex show processor
11891Use the @code{set processor} command to set the type of MIPS
11892processor when you want to access processor-type-specific registers.
5d161b24 11893For example, @code{set processor @var{r3041}} tells @value{GDBN}
96c405b3 11894to use the CPU registers appropriate for the 3041 chip.
5d161b24 11895Use the @code{show processor} command to see what MIPS processor @value{GDBN}
104c1213 11896is using. Use the @code{info reg} command to see what registers
5d161b24 11897@value{GDBN} is using.
104c1213
JM
11898
11899@item set mipsfpu double
11900@itemx set mipsfpu single
11901@itemx set mipsfpu none
11902@itemx show mipsfpu
11903@kindex set mipsfpu
11904@kindex show mipsfpu
11905@cindex MIPS remote floating point
11906@cindex floating point, MIPS remote
11907If your target board does not support the MIPS floating point
11908coprocessor, you should use the command @samp{set mipsfpu none} (if you
96a2c332 11909need this, you may wish to put the command in your @value{GDBN} init
104c1213
JM
11910file). This tells @value{GDBN} how to find the return value of
11911functions which return floating point values. It also allows
11912@value{GDBN} to avoid saving the floating point registers when calling
11913functions on the board. If you are using a floating point coprocessor
11914with only single precision floating point support, as on the @sc{r4650}
11915processor, use the command @samp{set mipsfpu single}. The default
11916double precision floating point coprocessor may be selected using
11917@samp{set mipsfpu double}.
11918
11919In previous versions the only choices were double precision or no
11920floating point, so @samp{set mipsfpu on} will select double precision
11921and @samp{set mipsfpu off} will select no floating point.
11922
11923As usual, you can inquire about the @code{mipsfpu} variable with
11924@samp{show mipsfpu}.
11925
11926@item set remotedebug @var{n}
11927@itemx show remotedebug
d4f3574e
SS
11928@kindex set remotedebug@r{, MIPS protocol}
11929@kindex show remotedebug@r{, MIPS protocol}
104c1213
JM
11930@cindex @code{remotedebug}, MIPS protocol
11931@cindex MIPS @code{remotedebug} protocol
11932@c FIXME! For this to be useful, you must know something about the MIPS
11933@c FIXME...protocol. Where is it described?
11934You can see some debugging information about communications with the board
11935by setting the @code{remotedebug} variable. If you set it to @code{1} using
11936@samp{set remotedebug 1}, every packet is displayed. If you set it
11937to @code{2}, every character is displayed. You can check the current value
11938at any time with the command @samp{show remotedebug}.
11939
11940@item set timeout @var{seconds}
11941@itemx set retransmit-timeout @var{seconds}
11942@itemx show timeout
11943@itemx show retransmit-timeout
11944@cindex @code{timeout}, MIPS protocol
11945@cindex @code{retransmit-timeout}, MIPS protocol
11946@kindex set timeout
11947@kindex show timeout
11948@kindex set retransmit-timeout
11949@kindex show retransmit-timeout
11950You can control the timeout used while waiting for a packet, in the MIPS
11951remote protocol, with the @code{set timeout @var{seconds}} command. The
11952default is 5 seconds. Similarly, you can control the timeout used while
11953waiting for an acknowledgement of a packet with the @code{set
11954retransmit-timeout @var{seconds}} command. The default is 3 seconds.
11955You can inspect both values with @code{show timeout} and @code{show
11956retransmit-timeout}. (These commands are @emph{only} available when
11957@value{GDBN} is configured for @samp{--target=mips-idt-ecoff}.)
11958
11959The timeout set by @code{set timeout} does not apply when @value{GDBN}
11960is waiting for your program to stop. In that case, @value{GDBN} waits
11961forever because it has no way of knowing how long the program is going
11962to run before stopping.
11963@end table
11964
6d2ebf8b 11965@node PowerPC
104c1213
JM
11966@subsection PowerPC
11967
11968@table @code
11969
11970@kindex target dink32
11971@item target dink32 @var{dev}
11972DINK32 ROM monitor.
11973
11974@kindex target ppcbug
11975@item target ppcbug @var{dev}
11976@kindex target ppcbug1
11977@item target ppcbug1 @var{dev}
11978PPCBUG ROM monitor for PowerPC.
11979
11980@kindex target sds
11981@item target sds @var{dev}
11982SDS monitor, running on a PowerPC board (such as Motorola's ADS).
11983
11984@end table
11985
6d2ebf8b 11986@node PA
104c1213
JM
11987@subsection HP PA Embedded
11988
11989@table @code
11990
11991@kindex target op50n
11992@item target op50n @var{dev}
11993OP50N monitor, running on an OKI HPPA board.
11994
11995@kindex target w89k
11996@item target w89k @var{dev}
11997W89K monitor, running on a Winbond HPPA board.
11998
11999@end table
12000
6d2ebf8b 12001@node SH
104c1213
JM
12002@subsection Hitachi SH
12003
12004@table @code
12005
d4f3574e 12006@kindex target hms@r{, with Hitachi SH}
104c1213
JM
12007@item target hms @var{dev}
12008A Hitachi SH board attached via serial line to your host. Use special
12009commands @code{device} and @code{speed} to control the serial line and
12010the communications speed used.
12011
d4f3574e 12012@kindex target e7000@r{, with Hitachi SH}
104c1213
JM
12013@item target e7000 @var{dev}
12014E7000 emulator for Hitachi SH.
12015
d4f3574e
SS
12016@kindex target sh3@r{, with SH}
12017@kindex target sh3e@r{, with SH}
104c1213
JM
12018@item target sh3 @var{dev}
12019@item target sh3e @var{dev}
12020Hitachi SH-3 and SH-3E target systems.
12021
12022@end table
12023
6d2ebf8b 12024@node Sparclet
104c1213
JM
12025@subsection Tsqware Sparclet
12026
12027@cindex Sparclet
12028
5d161b24
DB
12029@value{GDBN} enables developers to debug tasks running on
12030Sparclet targets from a Unix host.
104c1213
JM
12031@value{GDBN} uses code that runs on
12032both the Unix host and on the Sparclet target. The program
5d161b24 12033@code{@value{GDBP}} is installed and executed on the Unix host.
104c1213
JM
12034
12035@table @code
f0ca3dce 12036@item remotetimeout @var{args}
104c1213 12037@kindex remotetimeout
5d161b24
DB
12038@value{GDBN} supports the option @code{remotetimeout}.
12039This option is set by the user, and @var{args} represents the number of
12040seconds @value{GDBN} waits for responses.
104c1213
JM
12041@end table
12042
41afff9a 12043@cindex compiling, on Sparclet
5d161b24 12044When compiling for debugging, include the options @samp{-g} to get debug
d4f3574e 12045information and @samp{-Ttext} to relocate the program to where you wish to
5d161b24 12046load it on the target. You may also want to add the options @samp{-n} or
d4f3574e 12047@samp{-N} in order to reduce the size of the sections. Example:
104c1213
JM
12048
12049@example
12050sparclet-aout-gcc prog.c -Ttext 0x12010000 -g -o prog -N
12051@end example
12052
d4f3574e 12053You can use @code{objdump} to verify that the addresses are what you intended:
104c1213
JM
12054
12055@example
12056sparclet-aout-objdump --headers --syms prog
12057@end example
12058
41afff9a 12059@cindex running, on Sparclet
104c1213
JM
12060Once you have set
12061your Unix execution search path to find @value{GDBN}, you are ready to
5d161b24 12062run @value{GDBN}. From your Unix host, run @code{@value{GDBP}}
104c1213
JM
12063(or @code{sparclet-aout-gdb}, depending on your installation).
12064
12065@value{GDBN} comes up showing the prompt:
12066
12067@example
12068(gdbslet)
12069@end example
12070
12071@menu
12072* Sparclet File:: Setting the file to debug
12073* Sparclet Connection:: Connecting to Sparclet
12074* Sparclet Download:: Sparclet download
5d161b24 12075* Sparclet Execution:: Running and debugging
104c1213
JM
12076@end menu
12077
6d2ebf8b 12078@node Sparclet File
104c1213
JM
12079@subsubsection Setting file to debug
12080
12081The @value{GDBN} command @code{file} lets you choose with program to debug.
12082
12083@example
12084(gdbslet) file prog
12085@end example
12086
12087@need 1000
12088@value{GDBN} then attempts to read the symbol table of @file{prog}.
12089@value{GDBN} locates
12090the file by searching the directories listed in the command search
12091path.
12092If the file was compiled with debug information (option "-g"), source
12093files will be searched as well.
12094@value{GDBN} locates
12095the source files by searching the directories listed in the directory search
12096path (@pxref{Environment, ,Your program's environment}).
12097If it fails
12098to find a file, it displays a message such as:
12099
12100@example
12101prog: No such file or directory.
12102@end example
12103
12104When this happens, add the appropriate directories to the search paths with
5d161b24 12105the @value{GDBN} commands @code{path} and @code{dir}, and execute the
104c1213
JM
12106@code{target} command again.
12107
6d2ebf8b 12108@node Sparclet Connection
104c1213
JM
12109@subsubsection Connecting to Sparclet
12110
12111The @value{GDBN} command @code{target} lets you connect to a Sparclet target.
12112To connect to a target on serial port ``@code{ttya}'', type:
12113
12114@example
12115(gdbslet) target sparclet /dev/ttya
12116Remote target sparclet connected to /dev/ttya
5d161b24 12117main () at ../prog.c:3
104c1213
JM
12118@end example
12119
12120@need 750
12121@value{GDBN} displays messages like these:
12122
d4f3574e 12123@example
104c1213 12124Connected to ttya.
d4f3574e 12125@end example
104c1213 12126
6d2ebf8b 12127@node Sparclet Download
104c1213
JM
12128@subsubsection Sparclet download
12129
12130@cindex download to Sparclet
5d161b24 12131Once connected to the Sparclet target,
104c1213
JM
12132you can use the @value{GDBN}
12133@code{load} command to download the file from the host to the target.
12134The file name and load offset should be given as arguments to the @code{load}
12135command.
5d161b24 12136Since the file format is aout, the program must be loaded to the starting
d4f3574e 12137address. You can use @code{objdump} to find out what this value is. The load
104c1213
JM
12138offset is an offset which is added to the VMA (virtual memory address)
12139of each of the file's sections.
12140For instance, if the program
12141@file{prog} was linked to text address 0x1201000, with data at 0x12010160
12142and bss at 0x12010170, in @value{GDBN}, type:
12143
12144@example
12145(gdbslet) load prog 0x12010000
12146Loading section .text, size 0xdb0 vma 0x12010000
12147@end example
12148
5d161b24
DB
12149If the code is loaded at a different address then what the program was linked
12150to, you may need to use the @code{section} and @code{add-symbol-file} commands
104c1213
JM
12151to tell @value{GDBN} where to map the symbol table.
12152
6d2ebf8b 12153@node Sparclet Execution
104c1213
JM
12154@subsubsection Running and debugging
12155
12156@cindex running and debugging Sparclet programs
12157You can now begin debugging the task using @value{GDBN}'s execution control
5d161b24 12158commands, @code{b}, @code{step}, @code{run}, etc. See the @value{GDBN}
104c1213
JM
12159manual for the list of commands.
12160
12161@example
12162(gdbslet) b main
12163Breakpoint 1 at 0x12010000: file prog.c, line 3.
5d161b24 12164(gdbslet) run
104c1213
JM
12165Starting program: prog
12166Breakpoint 1, main (argc=1, argv=0xeffff21c) at prog.c:3
121673 char *symarg = 0;
12168(gdbslet) step
121694 char *execarg = "hello!";
5d161b24 12170(gdbslet)
104c1213
JM
12171@end example
12172
6d2ebf8b 12173@node Sparclite
104c1213
JM
12174@subsection Fujitsu Sparclite
12175
12176@table @code
12177
12178@kindex target sparclite
12179@item target sparclite @var{dev}
5d161b24
DB
12180Fujitsu sparclite boards, used only for the purpose of loading.
12181You must use an additional command to debug the program.
12182For example: target remote @var{dev} using @value{GDBN} standard
104c1213
JM
12183remote protocol.
12184
12185@end table
12186
6d2ebf8b 12187@node ST2000
104c1213
JM
12188@subsection Tandem ST2000
12189
2df3850c 12190@value{GDBN} may be used with a Tandem ST2000 phone switch, running Tandem's
104c1213
JM
12191STDBUG protocol.
12192
12193To connect your ST2000 to the host system, see the manufacturer's
12194manual. Once the ST2000 is physically attached, you can run:
12195
12196@example
12197target st2000 @var{dev} @var{speed}
12198@end example
12199
12200@noindent
12201to establish it as your debugging environment. @var{dev} is normally
12202the name of a serial device, such as @file{/dev/ttya}, connected to the
12203ST2000 via a serial line. You can instead specify @var{dev} as a TCP
12204connection (for example, to a serial line attached via a terminal
12205concentrator) using the syntax @code{@var{hostname}:@var{portnumber}}.
12206
12207The @code{load} and @code{attach} commands are @emph{not} defined for
12208this target; you must load your program into the ST2000 as you normally
12209would for standalone operation. @value{GDBN} reads debugging information
12210(such as symbols) from a separate, debugging version of the program
12211available on your host computer.
12212@c FIXME!! This is terribly vague; what little content is here is
12213@c basically hearsay.
12214
12215@cindex ST2000 auxiliary commands
12216These auxiliary @value{GDBN} commands are available to help you with the ST2000
12217environment:
12218
12219@table @code
12220@item st2000 @var{command}
12221@kindex st2000 @var{cmd}
12222@cindex STDBUG commands (ST2000)
12223@cindex commands to STDBUG (ST2000)
12224Send a @var{command} to the STDBUG monitor. See the manufacturer's
12225manual for available commands.
12226
12227@item connect
12228@cindex connect (to STDBUG)
12229Connect the controlling terminal to the STDBUG command monitor. When
12230you are done interacting with STDBUG, typing either of two character
12231sequences gets you back to the @value{GDBN} command prompt:
12232@kbd{@key{RET}~.} (Return, followed by tilde and period) or
12233@kbd{@key{RET}~@key{C-d}} (Return, followed by tilde and control-D).
12234@end table
12235
6d2ebf8b 12236@node Z8000
104c1213
JM
12237@subsection Zilog Z8000
12238
12239@cindex Z8000
12240@cindex simulator, Z8000
12241@cindex Zilog Z8000 simulator
12242
12243When configured for debugging Zilog Z8000 targets, @value{GDBN} includes
12244a Z8000 simulator.
12245
12246For the Z8000 family, @samp{target sim} simulates either the Z8002 (the
12247unsegmented variant of the Z8000 architecture) or the Z8001 (the
12248segmented variant). The simulator recognizes which architecture is
12249appropriate by inspecting the object code.
12250
12251@table @code
12252@item target sim @var{args}
12253@kindex sim
d4f3574e 12254@kindex target sim@r{, with Z8000}
104c1213
JM
12255Debug programs on a simulated CPU. If the simulator supports setup
12256options, specify them via @var{args}.
12257@end table
12258
12259@noindent
12260After specifying this target, you can debug programs for the simulated
12261CPU in the same style as programs for your host computer; use the
12262@code{file} command to load a new program image, the @code{run} command
12263to run your program, and so on.
12264
d4f3574e
SS
12265As well as making available all the usual machine registers
12266(@pxref{Registers, ,Registers}), the Z8000 simulator provides three
12267additional items of information as specially named registers:
104c1213
JM
12268
12269@table @code
12270
12271@item cycles
12272Counts clock-ticks in the simulator.
12273
12274@item insts
12275Counts instructions run in the simulator.
12276
12277@item time
12278Execution time in 60ths of a second.
12279
12280@end table
12281
12282You can refer to these values in @value{GDBN} expressions with the usual
12283conventions; for example, @w{@samp{b fputc if $cycles>5000}} sets a
12284conditional breakpoint that suspends only after at least 5000
12285simulated clock ticks.
12286
6d2ebf8b 12287@node Architectures
104c1213
JM
12288@section Architectures
12289
12290This section describes characteristics of architectures that affect
2df3850c 12291all uses of @value{GDBN} with the architecture, both native and cross.
104c1213
JM
12292
12293@menu
12294* A29K::
12295* Alpha::
12296* MIPS::
12297@end menu
12298
6d2ebf8b 12299@node A29K
104c1213
JM
12300@subsection A29K
12301
12302@table @code
12303
12304@kindex set rstack_high_address
12305@cindex AMD 29K register stack
12306@cindex register stack, AMD29K
12307@item set rstack_high_address @var{address}
12308On AMD 29000 family processors, registers are saved in a separate
d4f3574e 12309@dfn{register stack}. There is no way for @value{GDBN} to determine the
104c1213
JM
12310extent of this stack. Normally, @value{GDBN} just assumes that the
12311stack is ``large enough''. This may result in @value{GDBN} referencing
12312memory locations that do not exist. If necessary, you can get around
12313this problem by specifying the ending address of the register stack with
12314the @code{set rstack_high_address} command. The argument should be an
12315address, which you probably want to precede with @samp{0x} to specify in
12316hexadecimal.
12317
12318@kindex show rstack_high_address
12319@item show rstack_high_address
12320Display the current limit of the register stack, on AMD 29000 family
12321processors.
12322
12323@end table
12324
6d2ebf8b 12325@node Alpha
104c1213
JM
12326@subsection Alpha
12327
12328See the following section.
12329
6d2ebf8b 12330@node MIPS
104c1213
JM
12331@subsection MIPS
12332
12333@cindex stack on Alpha
12334@cindex stack on MIPS
12335@cindex Alpha stack
12336@cindex MIPS stack
12337Alpha- and MIPS-based computers use an unusual stack frame, which
12338sometimes requires @value{GDBN} to search backward in the object code to
12339find the beginning of a function.
12340
12341@cindex response time, MIPS debugging
12342To improve response time (especially for embedded applications, where
12343@value{GDBN} may be restricted to a slow serial line for this search)
12344you may want to limit the size of this search, using one of these
12345commands:
12346
12347@table @code
00e4a2e4 12348@cindex @code{heuristic-fence-post} (Alpha, MIPS)
104c1213
JM
12349@item set heuristic-fence-post @var{limit}
12350Restrict @value{GDBN} to examining at most @var{limit} bytes in its
12351search for the beginning of a function. A value of @var{0} (the
12352default) means there is no limit. However, except for @var{0}, the
12353larger the limit the more bytes @code{heuristic-fence-post} must search
12354and therefore the longer it takes to run.
12355
12356@item show heuristic-fence-post
12357Display the current limit.
12358@end table
12359
12360@noindent
12361These commands are available @emph{only} when @value{GDBN} is configured
12362for debugging programs on Alpha or MIPS processors.
12363
12364
6d2ebf8b 12365@node Controlling GDB
c906108c
SS
12366@chapter Controlling @value{GDBN}
12367
53a5351d
JM
12368You can alter the way @value{GDBN} interacts with you by using the
12369@code{set} command. For commands controlling how @value{GDBN} displays
d4f3574e 12370data, see @ref{Print Settings, ,Print settings}. Other settings are
53a5351d 12371described here.
c906108c
SS
12372
12373@menu
12374* Prompt:: Prompt
12375* Editing:: Command editing
12376* History:: Command history
12377* Screen Size:: Screen size
12378* Numbers:: Numbers
12379* Messages/Warnings:: Optional warnings and messages
5d161b24 12380* Debugging Output:: Optional messages about internal happenings
c906108c
SS
12381@end menu
12382
6d2ebf8b 12383@node Prompt
c906108c
SS
12384@section Prompt
12385
12386@cindex prompt
12387
12388@value{GDBN} indicates its readiness to read a command by printing a string
12389called the @dfn{prompt}. This string is normally @samp{(@value{GDBP})}. You
12390can change the prompt string with the @code{set prompt} command. For
12391instance, when debugging @value{GDBN} with @value{GDBN}, it is useful to change
5d161b24 12392the prompt in one of the @value{GDBN} sessions so that you can always tell
c906108c
SS
12393which one you are talking to.
12394
d4f3574e 12395@emph{Note:} @code{set prompt} does not add a space for you after the
c906108c
SS
12396prompt you set. This allows you to set a prompt which ends in a space
12397or a prompt that does not.
12398
12399@table @code
12400@kindex set prompt
12401@item set prompt @var{newprompt}
12402Directs @value{GDBN} to use @var{newprompt} as its prompt string henceforth.
12403
12404@kindex show prompt
12405@item show prompt
12406Prints a line of the form: @samp{Gdb's prompt is: @var{your-prompt}}
12407@end table
12408
6d2ebf8b 12409@node Editing
c906108c
SS
12410@section Command editing
12411@cindex readline
12412@cindex command line editing
12413
12414@value{GDBN} reads its input commands via the @dfn{readline} interface. This
12415@sc{gnu} library provides consistent behavior for programs which provide a
12416command line interface to the user. Advantages are @sc{gnu} Emacs-style
12417or @dfn{vi}-style inline editing of commands, @code{csh}-like history
12418substitution, and a storage and recall of command history across
12419debugging sessions.
12420
12421You may control the behavior of command line editing in @value{GDBN} with the
12422command @code{set}.
12423
12424@table @code
12425@kindex set editing
12426@cindex editing
12427@item set editing
12428@itemx set editing on
12429Enable command line editing (enabled by default).
12430
12431@item set editing off
12432Disable command line editing.
12433
12434@kindex show editing
12435@item show editing
12436Show whether command line editing is enabled.
12437@end table
12438
6d2ebf8b 12439@node History
c906108c
SS
12440@section Command history
12441
12442@value{GDBN} can keep track of the commands you type during your
12443debugging sessions, so that you can be certain of precisely what
12444happened. Use these commands to manage the @value{GDBN} command
12445history facility.
12446
12447@table @code
12448@cindex history substitution
12449@cindex history file
12450@kindex set history filename
12451@kindex GDBHISTFILE
12452@item set history filename @var{fname}
12453Set the name of the @value{GDBN} command history file to @var{fname}.
12454This is the file where @value{GDBN} reads an initial command history
12455list, and where it writes the command history from this session when it
12456exits. You can access this list through history expansion or through
12457the history command editing characters listed below. This file defaults
12458to the value of the environment variable @code{GDBHISTFILE}, or to
d4f3574e
SS
12459@file{./.gdb_history} (@file{./_gdb_history} on MS-DOS) if this variable
12460is not set.
c906108c
SS
12461
12462@cindex history save
12463@kindex set history save
12464@item set history save
12465@itemx set history save on
12466Record command history in a file, whose name may be specified with the
12467@code{set history filename} command. By default, this option is disabled.
12468
12469@item set history save off
12470Stop recording command history in a file.
12471
12472@cindex history size
12473@kindex set history size
12474@item set history size @var{size}
12475Set the number of commands which @value{GDBN} keeps in its history list.
12476This defaults to the value of the environment variable
12477@code{HISTSIZE}, or to 256 if this variable is not set.
12478@end table
12479
12480@cindex history expansion
12481History expansion assigns special meaning to the character @kbd{!}.
12482@ifset have-readline-appendices
12483@xref{Event Designators}.
12484@end ifset
12485
12486Since @kbd{!} is also the logical not operator in C, history expansion
12487is off by default. If you decide to enable history expansion with the
12488@code{set history expansion on} command, you may sometimes need to
12489follow @kbd{!} (when it is used as logical not, in an expression) with
12490a space or a tab to prevent it from being expanded. The readline
12491history facilities do not attempt substitution on the strings
12492@kbd{!=} and @kbd{!(}, even when history expansion is enabled.
12493
12494The commands to control history expansion are:
12495
12496@table @code
12497@kindex set history expansion
12498@item set history expansion on
12499@itemx set history expansion
12500Enable history expansion. History expansion is off by default.
12501
12502@item set history expansion off
12503Disable history expansion.
12504
12505The readline code comes with more complete documentation of
12506editing and history expansion features. Users unfamiliar with @sc{gnu} Emacs
12507or @code{vi} may wish to read it.
12508@ifset have-readline-appendices
12509@xref{Command Line Editing}.
12510@end ifset
12511
12512@c @group
12513@kindex show history
12514@item show history
12515@itemx show history filename
12516@itemx show history save
12517@itemx show history size
12518@itemx show history expansion
12519These commands display the state of the @value{GDBN} history parameters.
12520@code{show history} by itself displays all four states.
12521@c @end group
12522@end table
12523
12524@table @code
41afff9a 12525@kindex shows
c906108c
SS
12526@item show commands
12527Display the last ten commands in the command history.
12528
12529@item show commands @var{n}
12530Print ten commands centered on command number @var{n}.
12531
12532@item show commands +
12533Print ten commands just after the commands last printed.
12534@end table
12535
6d2ebf8b 12536@node Screen Size
c906108c
SS
12537@section Screen size
12538@cindex size of screen
12539@cindex pauses in output
12540
12541Certain commands to @value{GDBN} may produce large amounts of
12542information output to the screen. To help you read all of it,
12543@value{GDBN} pauses and asks you for input at the end of each page of
12544output. Type @key{RET} when you want to continue the output, or @kbd{q}
12545to discard the remaining output. Also, the screen width setting
12546determines when to wrap lines of output. Depending on what is being
12547printed, @value{GDBN} tries to break the line at a readable place,
12548rather than simply letting it overflow onto the following line.
12549
d4f3574e
SS
12550Normally @value{GDBN} knows the size of the screen from the terminal
12551driver software. For example, on Unix @value{GDBN} uses the termcap data base
c906108c 12552together with the value of the @code{TERM} environment variable and the
d4f3574e 12553@code{stty rows} and @code{stty cols} settings. If this is not correct,
c906108c
SS
12554you can override it with the @code{set height} and @code{set
12555width} commands:
12556
12557@table @code
12558@kindex set height
12559@kindex set width
12560@kindex show width
12561@kindex show height
12562@item set height @var{lpp}
12563@itemx show height
12564@itemx set width @var{cpl}
12565@itemx show width
12566These @code{set} commands specify a screen height of @var{lpp} lines and
12567a screen width of @var{cpl} characters. The associated @code{show}
12568commands display the current settings.
12569
5d161b24
DB
12570If you specify a height of zero lines, @value{GDBN} does not pause during
12571output no matter how long the output is. This is useful if output is to a
c906108c
SS
12572file or to an editor buffer.
12573
12574Likewise, you can specify @samp{set width 0} to prevent @value{GDBN}
12575from wrapping its output.
12576@end table
12577
6d2ebf8b 12578@node Numbers
c906108c
SS
12579@section Numbers
12580@cindex number representation
12581@cindex entering numbers
12582
2df3850c
JM
12583You can always enter numbers in octal, decimal, or hexadecimal in
12584@value{GDBN} by the usual conventions: octal numbers begin with
12585@samp{0}, decimal numbers end with @samp{.}, and hexadecimal numbers
12586begin with @samp{0x}. Numbers that begin with none of these are, by
12587default, entered in base 10; likewise, the default display for
12588numbers---when no particular format is specified---is base 10. You can
12589change the default base for both input and output with the @code{set
12590radix} command.
c906108c
SS
12591
12592@table @code
12593@kindex set input-radix
12594@item set input-radix @var{base}
12595Set the default base for numeric input. Supported choices
12596for @var{base} are decimal 8, 10, or 16. @var{base} must itself be
12597specified either unambiguously or using the current default radix; for
12598example, any of
12599
12600@smallexample
12601set radix 012
12602set radix 10.
12603set radix 0xa
12604@end smallexample
12605
12606@noindent
12607sets the base to decimal. On the other hand, @samp{set radix 10}
12608leaves the radix unchanged no matter what it was.
12609
12610@kindex set output-radix
12611@item set output-radix @var{base}
12612Set the default base for numeric display. Supported choices
12613for @var{base} are decimal 8, 10, or 16. @var{base} must itself be
12614specified either unambiguously or using the current default radix.
12615
12616@kindex show input-radix
12617@item show input-radix
12618Display the current default base for numeric input.
12619
12620@kindex show output-radix
12621@item show output-radix
12622Display the current default base for numeric display.
12623@end table
12624
6d2ebf8b 12625@node Messages/Warnings
c906108c
SS
12626@section Optional warnings and messages
12627
2df3850c
JM
12628By default, @value{GDBN} is silent about its inner workings. If you are
12629running on a slow machine, you may want to use the @code{set verbose}
12630command. This makes @value{GDBN} tell you when it does a lengthy
12631internal operation, so you will not think it has crashed.
c906108c
SS
12632
12633Currently, the messages controlled by @code{set verbose} are those
12634which announce that the symbol table for a source file is being read;
12635see @code{symbol-file} in @ref{Files, ,Commands to specify files}.
12636
12637@table @code
12638@kindex set verbose
12639@item set verbose on
12640Enables @value{GDBN} output of certain informational messages.
12641
12642@item set verbose off
12643Disables @value{GDBN} output of certain informational messages.
12644
12645@kindex show verbose
12646@item show verbose
12647Displays whether @code{set verbose} is on or off.
12648@end table
12649
2df3850c
JM
12650By default, if @value{GDBN} encounters bugs in the symbol table of an
12651object file, it is silent; but if you are debugging a compiler, you may
12652find this information useful (@pxref{Symbol Errors, ,Errors reading
12653symbol files}).
c906108c
SS
12654
12655@table @code
2df3850c 12656
c906108c
SS
12657@kindex set complaints
12658@item set complaints @var{limit}
2df3850c
JM
12659Permits @value{GDBN} to output @var{limit} complaints about each type of
12660unusual symbols before becoming silent about the problem. Set
12661@var{limit} to zero to suppress all complaints; set it to a large number
12662to prevent complaints from being suppressed.
c906108c
SS
12663
12664@kindex show complaints
12665@item show complaints
12666Displays how many symbol complaints @value{GDBN} is permitted to produce.
2df3850c 12667
c906108c
SS
12668@end table
12669
12670By default, @value{GDBN} is cautious, and asks what sometimes seems to be a
12671lot of stupid questions to confirm certain commands. For example, if
12672you try to run a program which is already running:
12673
12674@example
12675(@value{GDBP}) run
12676The program being debugged has been started already.
12677Start it from the beginning? (y or n)
12678@end example
12679
12680If you are willing to unflinchingly face the consequences of your own
12681commands, you can disable this ``feature'':
12682
12683@table @code
2df3850c 12684
c906108c
SS
12685@kindex set confirm
12686@cindex flinching
12687@cindex confirmation
12688@cindex stupid questions
12689@item set confirm off
12690Disables confirmation requests.
12691
12692@item set confirm on
12693Enables confirmation requests (the default).
12694
12695@kindex show confirm
12696@item show confirm
12697Displays state of confirmation requests.
2df3850c 12698
c906108c
SS
12699@end table
12700
6d2ebf8b 12701@node Debugging Output
5d161b24
DB
12702@section Optional messages about internal happenings
12703@table @code
12704@kindex set debug arch
12705@item set debug arch
12706Turns on or off display of gdbarch debugging info. The default is off
12707@kindex show debug arch
12708@item show debug arch
12709Displays the current state of displaying gdbarch debugging info.
12710@kindex set debug event
12711@item set debug event
12712Turns on or off display of @value{GDBN} event debugging info. The
12713default is off.
12714@kindex show debug event
12715@item show debug event
12716Displays the current state of displaying @value{GDBN} event debugging
12717info.
12718@kindex set debug expression
12719@item set debug expression
12720Turns on or off display of @value{GDBN} expression debugging info. The
12721default is off.
12722@kindex show debug expression
12723@item show debug expression
12724Displays the current state of displaying @value{GDBN} expression
12725debugging info.
12726@kindex set debug overload
12727@item set debug overload
b37052ae 12728Turns on or off display of @value{GDBN} C@t{++} overload debugging
5d161b24
DB
12729info. This includes info such as ranking of functions, etc. The default
12730is off.
12731@kindex show debug overload
12732@item show debug overload
b37052ae 12733Displays the current state of displaying @value{GDBN} C@t{++} overload
5d161b24
DB
12734debugging info.
12735@kindex set debug remote
12736@cindex packets, reporting on stdout
12737@cindex serial connections, debugging
12738@item set debug remote
12739Turns on or off display of reports on all packets sent back and forth across
12740the serial line to the remote machine. The info is printed on the
12741@value{GDBN} standard output stream. The default is off.
12742@kindex show debug remote
12743@item show debug remote
12744Displays the state of display of remote packets.
12745@kindex set debug serial
12746@item set debug serial
12747Turns on or off display of @value{GDBN} serial debugging info. The
12748default is off.
12749@kindex show debug serial
12750@item show debug serial
12751Displays the current state of displaying @value{GDBN} serial debugging
12752info.
12753@kindex set debug target
12754@item set debug target
12755Turns on or off display of @value{GDBN} target debugging info. This info
12756includes what is going on at the target level of GDB, as it happens. The
12757default is off.
12758@kindex show debug target
12759@item show debug target
12760Displays the current state of displaying @value{GDBN} target debugging
12761info.
12762@kindex set debug varobj
12763@item set debug varobj
12764Turns on or off display of @value{GDBN} variable object debugging
12765info. The default is off.
12766@kindex show debug varobj
12767@item show debug varobj
12768Displays the current state of displaying @value{GDBN} variable object
12769debugging info.
12770@end table
12771
6d2ebf8b 12772@node Sequences
c906108c
SS
12773@chapter Canned Sequences of Commands
12774
12775Aside from breakpoint commands (@pxref{Break Commands, ,Breakpoint
2df3850c
JM
12776command lists}), @value{GDBN} provides two ways to store sequences of
12777commands for execution as a unit: user-defined commands and command
12778files.
c906108c
SS
12779
12780@menu
12781* Define:: User-defined commands
12782* Hooks:: User-defined command hooks
12783* Command Files:: Command files
12784* Output:: Commands for controlled output
12785@end menu
12786
6d2ebf8b 12787@node Define
c906108c
SS
12788@section User-defined commands
12789
12790@cindex user-defined command
2df3850c
JM
12791A @dfn{user-defined command} is a sequence of @value{GDBN} commands to
12792which you assign a new name as a command. This is done with the
12793@code{define} command. User commands may accept up to 10 arguments
12794separated by whitespace. Arguments are accessed within the user command
12795via @var{$arg0@dots{}$arg9}. A trivial example:
c906108c
SS
12796
12797@smallexample
12798define adder
12799 print $arg0 + $arg1 + $arg2
12800@end smallexample
12801
d4f3574e
SS
12802@noindent
12803To execute the command use:
c906108c
SS
12804
12805@smallexample
12806adder 1 2 3
12807@end smallexample
12808
d4f3574e
SS
12809@noindent
12810This defines the command @code{adder}, which prints the sum of
5d161b24 12811its three arguments. Note the arguments are text substitutions, so they may
c906108c
SS
12812reference variables, use complex expressions, or even perform inferior
12813functions calls.
12814
12815@table @code
2df3850c 12816
c906108c
SS
12817@kindex define
12818@item define @var{commandname}
12819Define a command named @var{commandname}. If there is already a command
12820by that name, you are asked to confirm that you want to redefine it.
12821
12822The definition of the command is made up of other @value{GDBN} command lines,
12823which are given following the @code{define} command. The end of these
12824commands is marked by a line containing @code{end}.
12825
12826@kindex if
12827@kindex else
12828@item if
12829Takes a single argument, which is an expression to evaluate.
12830It is followed by a series of commands that are executed
12831only if the expression is true (nonzero).
12832There can then optionally be a line @code{else}, followed
12833by a series of commands that are only executed if the expression
12834was false. The end of the list is marked by a line containing @code{end}.
12835
12836@kindex while
12837@item while
12838The syntax is similar to @code{if}: the command takes a single argument,
12839which is an expression to evaluate, and must be followed by the commands to
12840execute, one per line, terminated by an @code{end}.
12841The commands are executed repeatedly as long as the expression
12842evaluates to true.
12843
12844@kindex document
12845@item document @var{commandname}
12846Document the user-defined command @var{commandname}, so that it can be
5d161b24
DB
12847accessed by @code{help}. The command @var{commandname} must already be
12848defined. This command reads lines of documentation just as @code{define}
12849reads the lines of the command definition, ending with @code{end}.
12850After the @code{document} command is finished, @code{help} on command
c906108c
SS
12851@var{commandname} displays the documentation you have written.
12852
12853You may use the @code{document} command again to change the
12854documentation of a command. Redefining the command with @code{define}
12855does not change the documentation.
12856
12857@kindex help user-defined
12858@item help user-defined
12859List all user-defined commands, with the first line of the documentation
12860(if any) for each.
12861
12862@kindex show user
12863@item show user
12864@itemx show user @var{commandname}
2df3850c
JM
12865Display the @value{GDBN} commands used to define @var{commandname} (but
12866not its documentation). If no @var{commandname} is given, display the
c906108c 12867definitions for all user-defined commands.
2df3850c 12868
c906108c
SS
12869@end table
12870
12871When user-defined commands are executed, the
12872commands of the definition are not printed. An error in any command
12873stops execution of the user-defined command.
12874
12875If used interactively, commands that would ask for confirmation proceed
5d161b24
DB
12876without asking when used inside a user-defined command. Many @value{GDBN}
12877commands that normally print messages to say what they are doing omit the
c906108c
SS
12878messages when used in a user-defined command.
12879
6d2ebf8b 12880@node Hooks
c906108c 12881@section User-defined command hooks
d4f3574e
SS
12882@cindex command hooks
12883@cindex hooks, for commands
c78b4128 12884@cindex hooks, pre-command
c906108c 12885
c78b4128
EZ
12886@kindex hook
12887@kindex hook-
12888You may define @dfn{hooks}, which are a special kind of user-defined
c906108c
SS
12889command. Whenever you run the command @samp{foo}, if the user-defined
12890command @samp{hook-foo} exists, it is executed (with no arguments)
12891before that command.
12892
c78b4128
EZ
12893@cindex hooks, post-command
12894@kindex hookpost
12895@kindex hookpost-
12896A hook may also be defined which is run after the command you executed.
12897Whenever you run the command @samp{foo}, if the user-defined command
12898@samp{hookpost-foo} exists, it is executed (with no arguments) after
12899that command. Post-execution hooks may exist simultaneously with
12900pre-execution hooks, for the same command.
12901
12902It is valid for a hook to call the command which it hooks. If this
12903occurs, the hook is not re-executed, thereby avoiding infinte recursion.
12904
12905@c It would be nice if hookpost could be passed a parameter indicating
12906@c if the command it hooks executed properly or not. FIXME!
12907
d4f3574e 12908@kindex stop@r{, a pseudo-command}
c906108c
SS
12909In addition, a pseudo-command, @samp{stop} exists. Defining
12910(@samp{hook-stop}) makes the associated commands execute every time
12911execution stops in your program: before breakpoint commands are run,
12912displays are printed, or the stack frame is printed.
12913
c906108c
SS
12914For example, to ignore @code{SIGALRM} signals while
12915single-stepping, but treat them normally during normal execution,
12916you could define:
12917
12918@example
12919define hook-stop
12920handle SIGALRM nopass
12921end
12922
12923define hook-run
12924handle SIGALRM pass
12925end
12926
12927define hook-continue
12928handle SIGLARM pass
12929end
12930@end example
c906108c 12931
c78b4128
EZ
12932As a further example, to hook at the begining and end of the @code{echo}
12933command, and to add extra text to the beginning and end of the message,
12934you could define:
12935
12936@example
12937define hook-echo
12938echo <<<---
12939end
12940
12941define hookpost-echo
12942echo --->>>\n
12943end
12944
12945(@value{GDBP}) echo Hello World
12946<<<---Hello World--->>>
12947(@value{GDBP})
12948
12949@end example
12950
c906108c
SS
12951You can define a hook for any single-word command in @value{GDBN}, but
12952not for command aliases; you should define a hook for the basic command
12953name, e.g. @code{backtrace} rather than @code{bt}.
12954@c FIXME! So how does Joe User discover whether a command is an alias
12955@c or not?
12956If an error occurs during the execution of your hook, execution of
12957@value{GDBN} commands stops and @value{GDBN} issues a prompt
12958(before the command that you actually typed had a chance to run).
12959
12960If you try to define a hook which does not match any known command, you
12961get a warning from the @code{define} command.
12962
6d2ebf8b 12963@node Command Files
c906108c
SS
12964@section Command files
12965
12966@cindex command files
5d161b24
DB
12967A command file for @value{GDBN} is a file of lines that are @value{GDBN}
12968commands. Comments (lines starting with @kbd{#}) may also be included.
12969An empty line in a command file does nothing; it does not mean to repeat
c906108c
SS
12970the last command, as it would from the terminal.
12971
12972@cindex init file
12973@cindex @file{.gdbinit}
d4f3574e 12974@cindex @file{gdb.ini}
c906108c 12975When you start @value{GDBN}, it automatically executes commands from its
bf0184be
ND
12976@dfn{init files}. These are files named @file{.gdbinit} on Unix and
12977@file{gdb.ini} on DOS/Windows. During startup, @value{GDBN} does the
12978following:
12979
12980@enumerate
12981@item
12982Reads the init file (if any) in your home directory@footnote{On
12983DOS/Windows systems, the home directory is the one pointed to by the
12984@code{HOME} environment variable.}.
12985
12986@item
12987Processes command line options and operands.
12988
12989@item
12990Reads the init file (if any) in the current working directory.
12991
12992@item
12993Reads command files specified by the @samp{-x} option.
12994@end enumerate
12995
12996The init file in your home directory can set options (such as @samp{set
12997complaints}) that affect subsequent processing of command line options
12998and operands. Init files are not executed if you use the @samp{-nx}
12999option (@pxref{Mode Options, ,Choosing modes}).
c906108c 13000
c906108c
SS
13001@cindex init file name
13002On some configurations of @value{GDBN}, the init file is known by a
13003different name (these are typically environments where a specialized
13004form of @value{GDBN} may need to coexist with other forms, hence a
13005different name for the specialized version's init file). These are the
13006environments with special init file names:
13007
00e4a2e4 13008@cindex @file{.vxgdbinit}
c906108c
SS
13009@itemize @bullet
13010@item
00e4a2e4 13011VxWorks (Wind River Systems real-time OS): @file{.vxgdbinit}
c906108c 13012
00e4a2e4 13013@cindex @file{.os68gdbinit}
c906108c 13014@item
00e4a2e4 13015OS68K (Enea Data Systems real-time OS): @file{.os68gdbinit}
c906108c 13016
00e4a2e4 13017@cindex @file{.esgdbinit}
c906108c 13018@item
00e4a2e4 13019ES-1800 (Ericsson Telecom AB M68000 emulator): @file{.esgdbinit}
c906108c 13020@end itemize
c906108c
SS
13021
13022You can also request the execution of a command file with the
13023@code{source} command:
13024
13025@table @code
13026@kindex source
13027@item source @var{filename}
13028Execute the command file @var{filename}.
13029@end table
13030
13031The lines in a command file are executed sequentially. They are not
13032printed as they are executed. An error in any command terminates execution
13033of the command file.
13034
13035Commands that would ask for confirmation if used interactively proceed
13036without asking when used in a command file. Many @value{GDBN} commands that
13037normally print messages to say what they are doing omit the messages
13038when called from command files.
13039
6d2ebf8b 13040@node Output
c906108c
SS
13041@section Commands for controlled output
13042
13043During the execution of a command file or a user-defined command, normal
13044@value{GDBN} output is suppressed; the only output that appears is what is
13045explicitly printed by the commands in the definition. This section
13046describes three commands useful for generating exactly the output you
13047want.
13048
13049@table @code
13050@kindex echo
13051@item echo @var{text}
13052@c I do not consider backslash-space a standard C escape sequence
13053@c because it is not in ANSI.
13054Print @var{text}. Nonprinting characters can be included in
13055@var{text} using C escape sequences, such as @samp{\n} to print a
13056newline. @strong{No newline is printed unless you specify one.}
13057In addition to the standard C escape sequences, a backslash followed
13058by a space stands for a space. This is useful for displaying a
13059string with spaces at the beginning or the end, since leading and
5d161b24 13060trailing spaces are otherwise trimmed from all arguments.
c906108c
SS
13061To print @samp{@w{ }and foo =@w{ }}, use the command
13062@samp{echo \@w{ }and foo = \@w{ }}.
13063
13064A backslash at the end of @var{text} can be used, as in C, to continue
13065the command onto subsequent lines. For example,
13066
13067@example
13068echo This is some text\n\
13069which is continued\n\
13070onto several lines.\n
13071@end example
13072
13073produces the same output as
13074
13075@example
13076echo This is some text\n
13077echo which is continued\n
13078echo onto several lines.\n
13079@end example
13080
13081@kindex output
13082@item output @var{expression}
13083Print the value of @var{expression} and nothing but that value: no
13084newlines, no @samp{$@var{nn} = }. The value is not entered in the
5d161b24 13085value history either. @xref{Expressions, ,Expressions}, for more information
c906108c
SS
13086on expressions.
13087
13088@item output/@var{fmt} @var{expression}
13089Print the value of @var{expression} in format @var{fmt}. You can use
13090the same formats as for @code{print}. @xref{Output Formats,,Output
13091formats}, for more information.
13092
13093@kindex printf
13094@item printf @var{string}, @var{expressions}@dots{}
13095Print the values of the @var{expressions} under the control of
13096@var{string}. The @var{expressions} are separated by commas and may be
13097either numbers or pointers. Their values are printed as specified by
13098@var{string}, exactly as if your program were to execute the C
13099subroutine
d4f3574e
SS
13100@c FIXME: the above implies that at least all ANSI C formats are
13101@c supported, but it isn't true: %E and %G don't work (or so it seems).
13102@c Either this is a bug, or the manual should document what formats are
13103@c supported.
c906108c
SS
13104
13105@example
13106printf (@var{string}, @var{expressions}@dots{});
13107@end example
13108
13109For example, you can print two values in hex like this:
13110
13111@smallexample
13112printf "foo, bar-foo = 0x%x, 0x%x\n", foo, bar-foo
13113@end smallexample
13114
13115The only backslash-escape sequences that you can use in the format
13116string are the simple ones that consist of backslash followed by a
13117letter.
13118@end table
13119
c4555f82
SC
13120@node TUI
13121@chapter @value{GDBN} Text User Interface
13122@cindex TUI
13123
13124@menu
13125* TUI Overview:: TUI overview
13126* TUI Keys:: TUI key bindings
13127* TUI Commands:: TUI specific commands
13128* TUI Configuration:: TUI configuration variables
13129@end menu
13130
13131The @value{GDBN} Text User Interface, TUI in short,
13132is a terminal interface which uses the @code{curses} library
13133to show the source file, the assembly output, the program registers
13134and @value{GDBN} commands in separate text windows.
13135The TUI is available only when @value{GDBN} is configured
13136with the @code{--enable-tui} configure option (@pxref{Configure Options}).
13137
13138@node TUI Overview
13139@section TUI overview
13140
13141The TUI has two display modes that can be switched while
13142@value{GDBN} runs:
13143
13144@itemize @bullet
13145@item
13146A curses (or TUI) mode in which it displays several text
13147windows on the terminal.
13148
13149@item
13150A standard mode which corresponds to the @value{GDBN} configured without
13151the TUI.
13152@end itemize
13153
13154In the TUI mode, @value{GDBN} can display several text window
13155on the terminal:
13156
13157@table @emph
13158@item command
13159This window is the @value{GDBN} command window with the @value{GDBN}
13160prompt and the @value{GDBN} outputs. The @value{GDBN} input is still
13161managed using readline but through the TUI. The @emph{command}
13162window is always visible.
13163
13164@item source
13165The source window shows the source file of the program. The current
13166line as well as active breakpoints are displayed in this window.
13167The current program position is shown with the @samp{>} marker and
13168active breakpoints are shown with @samp{*} markers.
13169
13170@item assembly
13171The assembly window shows the disassembly output of the program.
13172
13173@item register
13174This window shows the processor registers. It detects when
13175a register is changed and when this is the case, registers that have
13176changed are highlighted.
13177
13178@end table
13179
13180The source, assembly and register windows are attached to the thread
13181and the frame position. They are updated when the current thread
13182changes, when the frame changes or when the program counter changes.
13183These three windows are arranged by the TUI according to several
13184layouts. The layout defines which of these three windows are visible.
13185The following layouts are available:
13186
13187@itemize @bullet
13188@item
13189source
13190
13191@item
13192assembly
13193
13194@item
13195source and assembly
13196
13197@item
13198source and registers
13199
13200@item
13201assembly and registers
13202
13203@end itemize
13204
13205@node TUI Keys
13206@section TUI Key Bindings
13207@cindex TUI key bindings
13208
13209The TUI installs several key bindings in the readline keymaps
13210(@pxref{Command Line Editing}).
13211They allow to leave or enter in the TUI mode or they operate
13212directly on the TUI layout and windows. The following key bindings
13213are installed for both TUI mode and the @value{GDBN} standard mode.
13214
13215@table @kbd
13216@kindex C-x C-a
13217@item C-x C-a
13218@kindex C-x a
13219@itemx C-x a
13220@kindex C-x A
13221@itemx C-x A
13222Enter or leave the TUI mode. When the TUI mode is left,
13223the curses window management is left and @value{GDBN} operates using
13224its standard mode writing on the terminal directly. When the TUI
13225mode is entered, the control is given back to the curses windows.
13226The screen is then refreshed.
13227
13228@kindex C-x 1
13229@item C-x 1
13230Use a TUI layout with only one window. The layout will
13231either be @samp{source} or @samp{assembly}. When the TUI mode
13232is not active, it will switch to the TUI mode.
13233
13234Think of this key binding as the Emacs @kbd{C-x 1} binding.
13235
13236@kindex C-x 2
13237@item C-x 2
13238Use a TUI layout with at least two windows. When the current
13239layout shows already two windows, a next layout with two windows is used.
13240When a new layout is chosen, one window will always be common to the
13241previous layout and the new one.
13242
13243Think of it as the Emacs @kbd{C-x 2} binding.
13244
13245@end table
13246
13247The following key bindings are handled only by the TUI mode:
13248
13249@table @key
13250@kindex PgUp
13251@item PgUp
13252Scroll the active window one page up.
13253
13254@kindex PgDn
13255@item PgDn
13256Scroll the active window one page down.
13257
13258@kindex Up
13259@item Up
13260Scroll the active window one line up.
13261
13262@kindex Down
13263@item Down
13264Scroll the active window one line down.
13265
13266@kindex Left
13267@item Left
13268Scroll the active window one column left.
13269
13270@kindex Right
13271@item Right
13272Scroll the active window one column right.
13273
13274@kindex C-L
13275@item C-L
13276Refresh the screen.
13277
13278@end table
13279
13280In the TUI mode, the arrow keys are used by the active window
13281for scrolling. This means they are not available for readline. It is
13282necessary to use other readline key bindings such as @key{C-p}, @key{C-n},
13283@key{C-b} and @key{C-f}.
13284
13285@node TUI Commands
13286@section TUI specific commands
13287@cindex TUI commands
13288
13289The TUI has specific commands to control the text windows.
13290These commands are always available, that is they do not depend on
13291the current terminal mode in which @value{GDBN} runs. When @value{GDBN}
13292is in the standard mode, using these commands will automatically switch
13293in the TUI mode.
13294
13295@table @code
13296@item layout next
13297@kindex layout next
13298Display the next layout.
13299
13300@item layout prev
13301@kindex layout prev
13302Display the previous layout.
13303
13304@item layout src
13305@kindex layout src
13306Display the source window only.
13307
13308@item layout asm
13309@kindex layout asm
13310Display the assembly window only.
13311
13312@item layout split
13313@kindex layout split
13314Display the source and assembly window.
13315
13316@item layout regs
13317@kindex layout regs
13318Display the register window together with the source or assembly window.
13319
13320@item focus next | prev | src | asm | regs | split
13321@kindex focus
13322Set the focus to the named window.
13323This command allows to change the active window so that scrolling keys
13324can be affected to another window.
13325
13326@item refresh
13327@kindex refresh
13328Refresh the screen. This is similar to using @key{C-L} key.
13329
13330@item update
13331@kindex update
13332Update the source window and the current execution point.
13333
13334@item winheight @var{name} +@var{count}
13335@itemx winheight @var{name} -@var{count}
13336@kindex winheight
13337Change the height of the window @var{name} by @var{count}
13338lines. Positive counts increase the height, while negative counts
13339decrease it.
13340
13341@end table
13342
13343@node TUI Configuration
13344@section TUI configuration variables
13345@cindex TUI configuration variables
13346
13347The TUI has several configuration variables that control the
13348appearance of windows on the terminal.
13349
13350@table @code
732b3002
SC
13351@item set tui border-kind @var{kind}
13352@kindex set tui border-kind
c4555f82
SC
13353Select the border appearance for the source, assembly and register windows.
13354The possible values are the following:
13355@table @code
13356@item space
13357Use a space character to draw the border.
13358
13359@item ascii
13360Use ascii characters + - and | to draw the border.
13361
13362@item acs
13363Use the Alternate Character Set to draw the border. The border is
13364drawn using character line graphics if the terminal supports them.
13365
13366@end table
13367
732b3002
SC
13368@item set tui active-border-mode @var{mode}
13369@kindex set tui active-border-mode
c4555f82
SC
13370Select the attributes to display the border of the active window.
13371The possible values are @code{normal}, @code{standout}, @code{reverse},
13372@code{half}, @code{half-standout}, @code{bold} and @code{bold-standout}.
13373
732b3002
SC
13374@item set tui border-mode @var{mode}
13375@kindex set tui border-mode
c4555f82
SC
13376Select the attributes to display the border of other windows.
13377The @var{mode} can be one of the following:
13378@table @code
13379@item normal
13380Use normal attributes to display the border.
13381
13382@item standout
13383Use standout mode.
13384
13385@item reverse
13386Use reverse video mode.
13387
13388@item half
13389Use half bright mode.
13390
13391@item half-standout
13392Use half bright and standout mode.
13393
13394@item bold
13395Use extra bright or bold mode.
13396
13397@item bold-standout
13398Use extra bright or bold and standout mode.
13399
13400@end table
13401
13402@end table
13403
6d2ebf8b 13404@node Emacs
c906108c
SS
13405@chapter Using @value{GDBN} under @sc{gnu} Emacs
13406
13407@cindex Emacs
13408@cindex @sc{gnu} Emacs
13409A special interface allows you to use @sc{gnu} Emacs to view (and
13410edit) the source files for the program you are debugging with
13411@value{GDBN}.
13412
13413To use this interface, use the command @kbd{M-x gdb} in Emacs. Give the
13414executable file you want to debug as an argument. This command starts
13415@value{GDBN} as a subprocess of Emacs, with input and output through a newly
13416created Emacs buffer.
53a5351d 13417@c (Do not use the @code{-tui} option to run @value{GDBN} from Emacs.)
c906108c
SS
13418
13419Using @value{GDBN} under Emacs is just like using @value{GDBN} normally except for two
13420things:
13421
13422@itemize @bullet
13423@item
13424All ``terminal'' input and output goes through the Emacs buffer.
13425@end itemize
13426
13427This applies both to @value{GDBN} commands and their output, and to the input
13428and output done by the program you are debugging.
13429
13430This is useful because it means that you can copy the text of previous
13431commands and input them again; you can even use parts of the output
13432in this way.
13433
13434All the facilities of Emacs' Shell mode are available for interacting
13435with your program. In particular, you can send signals the usual
13436way---for example, @kbd{C-c C-c} for an interrupt, @kbd{C-c C-z} for a
13437stop.
13438
13439@itemize @bullet
13440@item
13441@value{GDBN} displays source code through Emacs.
13442@end itemize
13443
13444Each time @value{GDBN} displays a stack frame, Emacs automatically finds the
13445source file for that frame and puts an arrow (@samp{=>}) at the
13446left margin of the current line. Emacs uses a separate buffer for
13447source display, and splits the screen to show both your @value{GDBN} session
13448and the source.
13449
13450Explicit @value{GDBN} @code{list} or search commands still produce output as
13451usual, but you probably have no reason to use them from Emacs.
13452
13453@quotation
13454@emph{Warning:} If the directory where your program resides is not your
13455current directory, it can be easy to confuse Emacs about the location of
13456the source files, in which case the auxiliary display buffer does not
13457appear to show your source. @value{GDBN} can find programs by searching your
13458environment's @code{PATH} variable, so the @value{GDBN} input and output
13459session proceeds normally; but Emacs does not get enough information
13460back from @value{GDBN} to locate the source files in this situation. To
13461avoid this problem, either start @value{GDBN} mode from the directory where
13462your program resides, or specify an absolute file name when prompted for the
13463@kbd{M-x gdb} argument.
13464
13465A similar confusion can result if you use the @value{GDBN} @code{file} command to
13466switch to debugging a program in some other location, from an existing
13467@value{GDBN} buffer in Emacs.
13468@end quotation
13469
13470By default, @kbd{M-x gdb} calls the program called @file{gdb}. If
13471you need to call @value{GDBN} by a different name (for example, if you keep
13472several configurations around, with different names) you can set the
13473Emacs variable @code{gdb-command-name}; for example,
13474
13475@example
13476(setq gdb-command-name "mygdb")
13477@end example
13478
13479@noindent
d4f3574e 13480(preceded by @kbd{M-:} or @kbd{ESC :}, or typed in the @code{*scratch*} buffer, or
c906108c
SS
13481in your @file{.emacs} file) makes Emacs call the program named
13482``@code{mygdb}'' instead.
13483
13484In the @value{GDBN} I/O buffer, you can use these special Emacs commands in
13485addition to the standard Shell mode commands:
13486
13487@table @kbd
13488@item C-h m
13489Describe the features of Emacs' @value{GDBN} Mode.
13490
13491@item M-s
13492Execute to another source line, like the @value{GDBN} @code{step} command; also
13493update the display window to show the current file and location.
13494
13495@item M-n
13496Execute to next source line in this function, skipping all function
13497calls, like the @value{GDBN} @code{next} command. Then update the display window
13498to show the current file and location.
13499
13500@item M-i
13501Execute one instruction, like the @value{GDBN} @code{stepi} command; update
13502display window accordingly.
13503
13504@item M-x gdb-nexti
13505Execute to next instruction, using the @value{GDBN} @code{nexti} command; update
13506display window accordingly.
13507
13508@item C-c C-f
13509Execute until exit from the selected stack frame, like the @value{GDBN}
13510@code{finish} command.
13511
13512@item M-c
13513Continue execution of your program, like the @value{GDBN} @code{continue}
13514command.
13515
13516@emph{Warning:} In Emacs v19, this command is @kbd{C-c C-p}.
13517
13518@item M-u
13519Go up the number of frames indicated by the numeric argument
13520(@pxref{Arguments, , Numeric Arguments, Emacs, The @sc{gnu} Emacs Manual}),
13521like the @value{GDBN} @code{up} command.
13522
13523@emph{Warning:} In Emacs v19, this command is @kbd{C-c C-u}.
13524
13525@item M-d
13526Go down the number of frames indicated by the numeric argument, like the
13527@value{GDBN} @code{down} command.
13528
13529@emph{Warning:} In Emacs v19, this command is @kbd{C-c C-d}.
13530
13531@item C-x &
13532Read the number where the cursor is positioned, and insert it at the end
13533of the @value{GDBN} I/O buffer. For example, if you wish to disassemble code
13534around an address that was displayed earlier, type @kbd{disassemble};
13535then move the cursor to the address display, and pick up the
13536argument for @code{disassemble} by typing @kbd{C-x &}.
13537
13538You can customize this further by defining elements of the list
13539@code{gdb-print-command}; once it is defined, you can format or
13540otherwise process numbers picked up by @kbd{C-x &} before they are
13541inserted. A numeric argument to @kbd{C-x &} indicates that you
13542wish special formatting, and also acts as an index to pick an element of the
13543list. If the list element is a string, the number to be inserted is
13544formatted using the Emacs function @code{format}; otherwise the number
13545is passed as an argument to the corresponding list element.
13546@end table
13547
13548In any source file, the Emacs command @kbd{C-x SPC} (@code{gdb-break})
13549tells @value{GDBN} to set a breakpoint on the source line point is on.
13550
13551If you accidentally delete the source-display buffer, an easy way to get
13552it back is to type the command @code{f} in the @value{GDBN} buffer, to
13553request a frame display; when you run under Emacs, this recreates
13554the source buffer if necessary to show you the context of the current
13555frame.
13556
13557The source files displayed in Emacs are in ordinary Emacs buffers
13558which are visiting the source files in the usual way. You can edit
13559the files with these buffers if you wish; but keep in mind that @value{GDBN}
13560communicates with Emacs in terms of line numbers. If you add or
13561delete lines from the text, the line numbers that @value{GDBN} knows cease
13562to correspond properly with the code.
13563
13564@c The following dropped because Epoch is nonstandard. Reactivate
13565@c if/when v19 does something similar. ---doc@cygnus.com 19dec1990
13566@ignore
13567@kindex Emacs Epoch environment
13568@kindex Epoch
13569@kindex inspect
13570
5d161b24 13571Version 18 of @sc{gnu} Emacs has a built-in window system
c906108c
SS
13572called the @code{epoch}
13573environment. Users of this environment can use a new command,
13574@code{inspect} which performs identically to @code{print} except that
13575each value is printed in its own window.
13576@end ignore
c906108c 13577
d700128c 13578@include annotate.texi
7162c0ca 13579@include gdbmi.texinfo
d700128c 13580
6d2ebf8b 13581@node GDB Bugs
c906108c
SS
13582@chapter Reporting Bugs in @value{GDBN}
13583@cindex bugs in @value{GDBN}
13584@cindex reporting bugs in @value{GDBN}
13585
13586Your bug reports play an essential role in making @value{GDBN} reliable.
13587
13588Reporting a bug may help you by bringing a solution to your problem, or it
13589may not. But in any case the principal function of a bug report is to help
13590the entire community by making the next version of @value{GDBN} work better. Bug
13591reports are your contribution to the maintenance of @value{GDBN}.
13592
13593In order for a bug report to serve its purpose, you must include the
13594information that enables us to fix the bug.
13595
13596@menu
13597* Bug Criteria:: Have you found a bug?
13598* Bug Reporting:: How to report bugs
13599@end menu
13600
6d2ebf8b 13601@node Bug Criteria
c906108c
SS
13602@section Have you found a bug?
13603@cindex bug criteria
13604
13605If you are not sure whether you have found a bug, here are some guidelines:
13606
13607@itemize @bullet
13608@cindex fatal signal
13609@cindex debugger crash
13610@cindex crash of debugger
13611@item
13612If the debugger gets a fatal signal, for any input whatever, that is a
13613@value{GDBN} bug. Reliable debuggers never crash.
13614
13615@cindex error on valid input
13616@item
13617If @value{GDBN} produces an error message for valid input, that is a
13618bug. (Note that if you're cross debugging, the problem may also be
13619somewhere in the connection to the target.)
13620
13621@cindex invalid input
13622@item
13623If @value{GDBN} does not produce an error message for invalid input,
13624that is a bug. However, you should note that your idea of
13625``invalid input'' might be our idea of ``an extension'' or ``support
13626for traditional practice''.
13627
13628@item
13629If you are an experienced user of debugging tools, your suggestions
13630for improvement of @value{GDBN} are welcome in any case.
13631@end itemize
13632
6d2ebf8b 13633@node Bug Reporting
c906108c
SS
13634@section How to report bugs
13635@cindex bug reports
13636@cindex @value{GDBN} bugs, reporting
13637
c906108c
SS
13638A number of companies and individuals offer support for @sc{gnu} products.
13639If you obtained @value{GDBN} from a support organization, we recommend you
13640contact that organization first.
13641
13642You can find contact information for many support companies and
13643individuals in the file @file{etc/SERVICE} in the @sc{gnu} Emacs
13644distribution.
13645@c should add a web page ref...
13646
13647In any event, we also recommend that you send bug reports for
13648@value{GDBN} to this addresses:
13649
13650@example
d4f3574e 13651bug-gdb@@gnu.org
c906108c
SS
13652@end example
13653
13654@strong{Do not send bug reports to @samp{info-gdb}, or to
d4f3574e 13655@samp{help-gdb}, or to any newsgroups.} Most users of @value{GDBN} do
c906108c
SS
13656not want to receive bug reports. Those that do have arranged to receive
13657@samp{bug-gdb}.
13658
13659The mailing list @samp{bug-gdb} has a newsgroup @samp{gnu.gdb.bug} which
13660serves as a repeater. The mailing list and the newsgroup carry exactly
13661the same messages. Often people think of posting bug reports to the
13662newsgroup instead of mailing them. This appears to work, but it has one
13663problem which can be crucial: a newsgroup posting often lacks a mail
13664path back to the sender. Thus, if we need to ask for more information,
13665we may be unable to reach you. For this reason, it is better to send
13666bug reports to the mailing list.
13667
13668As a last resort, send bug reports on paper to:
13669
13670@example
13671@sc{gnu} Debugger Bugs
13672Free Software Foundation Inc.
1367359 Temple Place - Suite 330
13674Boston, MA 02111-1307
13675USA
13676@end example
c906108c
SS
13677
13678The fundamental principle of reporting bugs usefully is this:
13679@strong{report all the facts}. If you are not sure whether to state a
13680fact or leave it out, state it!
13681
13682Often people omit facts because they think they know what causes the
13683problem and assume that some details do not matter. Thus, you might
13684assume that the name of the variable you use in an example does not matter.
13685Well, probably it does not, but one cannot be sure. Perhaps the bug is a
13686stray memory reference which happens to fetch from the location where that
13687name is stored in memory; perhaps, if the name were different, the contents
13688of that location would fool the debugger into doing the right thing despite
13689the bug. Play it safe and give a specific, complete example. That is the
13690easiest thing for you to do, and the most helpful.
13691
13692Keep in mind that the purpose of a bug report is to enable us to fix the
13693bug. It may be that the bug has been reported previously, but neither
13694you nor we can know that unless your bug report is complete and
13695self-contained.
13696
13697Sometimes people give a few sketchy facts and ask, ``Does this ring a
13698bell?'' Those bug reports are useless, and we urge everyone to
13699@emph{refuse to respond to them} except to chide the sender to report
13700bugs properly.
13701
13702To enable us to fix the bug, you should include all these things:
13703
13704@itemize @bullet
13705@item
13706The version of @value{GDBN}. @value{GDBN} announces it if you start
13707with no arguments; you can also print it at any time using @code{show
13708version}.
13709
13710Without this, we will not know whether there is any point in looking for
13711the bug in the current version of @value{GDBN}.
13712
13713@item
13714The type of machine you are using, and the operating system name and
13715version number.
13716
c906108c
SS
13717@item
13718What compiler (and its version) was used to compile @value{GDBN}---e.g.
13719``@value{GCC}--2.8.1''.
c906108c
SS
13720
13721@item
13722What compiler (and its version) was used to compile the program you are
13723debugging---e.g. ``@value{GCC}--2.8.1'', or ``HP92453-01 A.10.32.03 HP
13724C Compiler''. For GCC, you can say @code{gcc --version} to get this
13725information; for other compilers, see the documentation for those
13726compilers.
13727
13728@item
13729The command arguments you gave the compiler to compile your example and
13730observe the bug. For example, did you use @samp{-O}? To guarantee
13731you will not omit something important, list them all. A copy of the
13732Makefile (or the output from make) is sufficient.
13733
13734If we were to try to guess the arguments, we would probably guess wrong
13735and then we might not encounter the bug.
13736
13737@item
13738A complete input script, and all necessary source files, that will
13739reproduce the bug.
13740
13741@item
13742A description of what behavior you observe that you believe is
13743incorrect. For example, ``It gets a fatal signal.''
13744
13745Of course, if the bug is that @value{GDBN} gets a fatal signal, then we
13746will certainly notice it. But if the bug is incorrect output, we might
13747not notice unless it is glaringly wrong. You might as well not give us
13748a chance to make a mistake.
13749
13750Even if the problem you experience is a fatal signal, you should still
13751say so explicitly. Suppose something strange is going on, such as, your
13752copy of @value{GDBN} is out of synch, or you have encountered a bug in
13753the C library on your system. (This has happened!) Your copy might
13754crash and ours would not. If you told us to expect a crash, then when
13755ours fails to crash, we would know that the bug was not happening for
13756us. If you had not told us to expect a crash, then we would not be able
13757to draw any conclusion from our observations.
13758
c906108c
SS
13759@item
13760If you wish to suggest changes to the @value{GDBN} source, send us context
13761diffs. If you even discuss something in the @value{GDBN} source, refer to
13762it by context, not by line number.
13763
13764The line numbers in our development sources will not match those in your
13765sources. Your line numbers would convey no useful information to us.
53a5351d 13766
c906108c
SS
13767@end itemize
13768
13769Here are some things that are not necessary:
13770
13771@itemize @bullet
13772@item
13773A description of the envelope of the bug.
13774
13775Often people who encounter a bug spend a lot of time investigating
13776which changes to the input file will make the bug go away and which
13777changes will not affect it.
13778
13779This is often time consuming and not very useful, because the way we
13780will find the bug is by running a single example under the debugger
13781with breakpoints, not by pure deduction from a series of examples.
13782We recommend that you save your time for something else.
13783
13784Of course, if you can find a simpler example to report @emph{instead}
13785of the original one, that is a convenience for us. Errors in the
13786output will be easier to spot, running under the debugger will take
13787less time, and so on.
13788
13789However, simplification is not vital; if you do not want to do this,
13790report the bug anyway and send us the entire test case you used.
13791
13792@item
13793A patch for the bug.
13794
13795A patch for the bug does help us if it is a good one. But do not omit
13796the necessary information, such as the test case, on the assumption that
13797a patch is all we need. We might see problems with your patch and decide
13798to fix the problem another way, or we might not understand it at all.
13799
13800Sometimes with a program as complicated as @value{GDBN} it is very hard to
13801construct an example that will make the program follow a certain path
13802through the code. If you do not send us the example, we will not be able
13803to construct one, so we will not be able to verify that the bug is fixed.
13804
13805And if we cannot understand what bug you are trying to fix, or why your
13806patch should be an improvement, we will not install it. A test case will
13807help us to understand.
13808
13809@item
13810A guess about what the bug is or what it depends on.
13811
13812Such guesses are usually wrong. Even we cannot guess right about such
13813things without first using the debugger to find the facts.
13814@end itemize
13815
5d161b24 13816@c The readline documentation is distributed with the readline code
c906108c
SS
13817@c and consists of the two following files:
13818@c rluser.texinfo
7be570e7 13819@c inc-hist.texinfo
c906108c
SS
13820@c Use -I with makeinfo to point to the appropriate directory,
13821@c environment var TEXINPUTS with TeX.
13822@include rluser.texinfo
7be570e7 13823@include inc-hist.texinfo
c906108c
SS
13824
13825
6d2ebf8b 13826@node Formatting Documentation
c906108c
SS
13827@appendix Formatting Documentation
13828
13829@cindex @value{GDBN} reference card
13830@cindex reference card
13831The @value{GDBN} 4 release includes an already-formatted reference card, ready
13832for printing with PostScript or Ghostscript, in the @file{gdb}
13833subdirectory of the main source directory@footnote{In
13834@file{gdb-@value{GDBVN}/gdb/refcard.ps} of the version @value{GDBVN}
13835release.}. If you can use PostScript or Ghostscript with your printer,
13836you can print the reference card immediately with @file{refcard.ps}.
13837
13838The release also includes the source for the reference card. You
13839can format it, using @TeX{}, by typing:
13840
13841@example
13842make refcard.dvi
13843@end example
13844
5d161b24
DB
13845The @value{GDBN} reference card is designed to print in @dfn{landscape}
13846mode on US ``letter'' size paper;
c906108c
SS
13847that is, on a sheet 11 inches wide by 8.5 inches
13848high. You will need to specify this form of printing as an option to
13849your @sc{dvi} output program.
13850
13851@cindex documentation
13852
13853All the documentation for @value{GDBN} comes as part of the machine-readable
13854distribution. The documentation is written in Texinfo format, which is
13855a documentation system that uses a single source file to produce both
13856on-line information and a printed manual. You can use one of the Info
13857formatting commands to create the on-line version of the documentation
13858and @TeX{} (or @code{texi2roff}) to typeset the printed version.
13859
13860@value{GDBN} includes an already formatted copy of the on-line Info
13861version of this manual in the @file{gdb} subdirectory. The main Info
13862file is @file{gdb-@value{GDBVN}/gdb/gdb.info}, and it refers to
13863subordinate files matching @samp{gdb.info*} in the same directory. If
13864necessary, you can print out these files, or read them with any editor;
13865but they are easier to read using the @code{info} subsystem in @sc{gnu}
13866Emacs or the standalone @code{info} program, available as part of the
13867@sc{gnu} Texinfo distribution.
13868
13869If you want to format these Info files yourself, you need one of the
13870Info formatting programs, such as @code{texinfo-format-buffer} or
13871@code{makeinfo}.
13872
13873If you have @code{makeinfo} installed, and are in the top level
13874@value{GDBN} source directory (@file{gdb-@value{GDBVN}}, in the case of
13875version @value{GDBVN}), you can make the Info file by typing:
13876
13877@example
13878cd gdb
13879make gdb.info
13880@end example
13881
13882If you want to typeset and print copies of this manual, you need @TeX{},
13883a program to print its @sc{dvi} output files, and @file{texinfo.tex}, the
13884Texinfo definitions file.
13885
13886@TeX{} is a typesetting program; it does not print files directly, but
13887produces output files called @sc{dvi} files. To print a typeset
13888document, you need a program to print @sc{dvi} files. If your system
13889has @TeX{} installed, chances are it has such a program. The precise
13890command to use depends on your system; @kbd{lpr -d} is common; another
13891(for PostScript devices) is @kbd{dvips}. The @sc{dvi} print command may
13892require a file name without any extension or a @samp{.dvi} extension.
13893
13894@TeX{} also requires a macro definitions file called
13895@file{texinfo.tex}. This file tells @TeX{} how to typeset a document
13896written in Texinfo format. On its own, @TeX{} cannot either read or
13897typeset a Texinfo file. @file{texinfo.tex} is distributed with GDB
13898and is located in the @file{gdb-@var{version-number}/texinfo}
13899directory.
13900
13901If you have @TeX{} and a @sc{dvi} printer program installed, you can
13902typeset and print this manual. First switch to the the @file{gdb}
13903subdirectory of the main source directory (for example, to
13904@file{gdb-@value{GDBVN}/gdb}) and type:
13905
13906@example
13907make gdb.dvi
13908@end example
13909
13910Then give @file{gdb.dvi} to your @sc{dvi} printing program.
c906108c 13911
6d2ebf8b 13912@node Installing GDB
c906108c
SS
13913@appendix Installing @value{GDBN}
13914@cindex configuring @value{GDBN}
13915@cindex installation
13916
c906108c
SS
13917@value{GDBN} comes with a @code{configure} script that automates the process
13918of preparing @value{GDBN} for installation; you can then use @code{make} to
13919build the @code{gdb} program.
13920@iftex
13921@c irrelevant in info file; it's as current as the code it lives with.
13922@footnote{If you have a more recent version of @value{GDBN} than @value{GDBVN},
13923look at the @file{README} file in the sources; we may have improved the
13924installation procedures since publishing this manual.}
13925@end iftex
13926
5d161b24
DB
13927The @value{GDBN} distribution includes all the source code you need for
13928@value{GDBN} in a single directory, whose name is usually composed by
c906108c
SS
13929appending the version number to @samp{gdb}.
13930
13931For example, the @value{GDBN} version @value{GDBVN} distribution is in the
13932@file{gdb-@value{GDBVN}} directory. That directory contains:
13933
13934@table @code
13935@item gdb-@value{GDBVN}/configure @r{(and supporting files)}
13936script for configuring @value{GDBN} and all its supporting libraries
13937
13938@item gdb-@value{GDBVN}/gdb
13939the source specific to @value{GDBN} itself
13940
13941@item gdb-@value{GDBVN}/bfd
13942source for the Binary File Descriptor library
13943
13944@item gdb-@value{GDBVN}/include
13945@sc{gnu} include files
13946
13947@item gdb-@value{GDBVN}/libiberty
13948source for the @samp{-liberty} free software library
13949
13950@item gdb-@value{GDBVN}/opcodes
13951source for the library of opcode tables and disassemblers
13952
13953@item gdb-@value{GDBVN}/readline
13954source for the @sc{gnu} command-line interface
13955
13956@item gdb-@value{GDBVN}/glob
13957source for the @sc{gnu} filename pattern-matching subroutine
13958
13959@item gdb-@value{GDBVN}/mmalloc
13960source for the @sc{gnu} memory-mapped malloc package
13961@end table
13962
13963The simplest way to configure and build @value{GDBN} is to run @code{configure}
13964from the @file{gdb-@var{version-number}} source directory, which in
13965this example is the @file{gdb-@value{GDBVN}} directory.
13966
13967First switch to the @file{gdb-@var{version-number}} source directory
13968if you are not already in it; then run @code{configure}. Pass the
13969identifier for the platform on which @value{GDBN} will run as an
13970argument.
13971
13972For example:
13973
13974@example
13975cd gdb-@value{GDBVN}
13976./configure @var{host}
13977make
13978@end example
13979
13980@noindent
13981where @var{host} is an identifier such as @samp{sun4} or
13982@samp{decstation}, that identifies the platform where @value{GDBN} will run.
13983(You can often leave off @var{host}; @code{configure} tries to guess the
13984correct value by examining your system.)
13985
13986Running @samp{configure @var{host}} and then running @code{make} builds the
13987@file{bfd}, @file{readline}, @file{mmalloc}, and @file{libiberty}
13988libraries, then @code{gdb} itself. The configured source files, and the
13989binaries, are left in the corresponding source directories.
13990
13991@need 750
13992@code{configure} is a Bourne-shell (@code{/bin/sh}) script; if your
13993system does not recognize this automatically when you run a different
13994shell, you may need to run @code{sh} on it explicitly:
13995
13996@example
13997sh configure @var{host}
13998@end example
13999
14000If you run @code{configure} from a directory that contains source
14001directories for multiple libraries or programs, such as the
14002@file{gdb-@value{GDBVN}} source directory for version @value{GDBVN}, @code{configure}
14003creates configuration files for every directory level underneath (unless
14004you tell it not to, with the @samp{--norecursion} option).
14005
14006You can run the @code{configure} script from any of the
14007subordinate directories in the @value{GDBN} distribution if you only want to
14008configure that subdirectory, but be sure to specify a path to it.
14009
14010For example, with version @value{GDBVN}, type the following to configure only
14011the @code{bfd} subdirectory:
14012
14013@example
14014@group
14015cd gdb-@value{GDBVN}/bfd
14016../configure @var{host}
14017@end group
14018@end example
14019
14020You can install @code{@value{GDBP}} anywhere; it has no hardwired paths.
14021However, you should make sure that the shell on your path (named by
14022the @samp{SHELL} environment variable) is publicly readable. Remember
14023that @value{GDBN} uses the shell to start your program---some systems refuse to
14024let @value{GDBN} debug child processes whose programs are not readable.
14025
14026@menu
14027* Separate Objdir:: Compiling @value{GDBN} in another directory
14028* Config Names:: Specifying names for hosts and targets
14029* Configure Options:: Summary of options for configure
14030@end menu
14031
6d2ebf8b 14032@node Separate Objdir
c906108c
SS
14033@section Compiling @value{GDBN} in another directory
14034
14035If you want to run @value{GDBN} versions for several host or target machines,
14036you need a different @code{gdb} compiled for each combination of
14037host and target. @code{configure} is designed to make this easy by
14038allowing you to generate each configuration in a separate subdirectory,
14039rather than in the source directory. If your @code{make} program
14040handles the @samp{VPATH} feature (@sc{gnu} @code{make} does), running
14041@code{make} in each of these directories builds the @code{gdb}
14042program specified there.
14043
14044To build @code{gdb} in a separate directory, run @code{configure}
14045with the @samp{--srcdir} option to specify where to find the source.
14046(You also need to specify a path to find @code{configure}
14047itself from your working directory. If the path to @code{configure}
14048would be the same as the argument to @samp{--srcdir}, you can leave out
14049the @samp{--srcdir} option; it is assumed.)
14050
5d161b24 14051For example, with version @value{GDBVN}, you can build @value{GDBN} in a
c906108c
SS
14052separate directory for a Sun 4 like this:
14053
14054@example
14055@group
14056cd gdb-@value{GDBVN}
14057mkdir ../gdb-sun4
14058cd ../gdb-sun4
14059../gdb-@value{GDBVN}/configure sun4
14060make
14061@end group
14062@end example
14063
14064When @code{configure} builds a configuration using a remote source
14065directory, it creates a tree for the binaries with the same structure
14066(and using the same names) as the tree under the source directory. In
14067the example, you'd find the Sun 4 library @file{libiberty.a} in the
14068directory @file{gdb-sun4/libiberty}, and @value{GDBN} itself in
14069@file{gdb-sun4/gdb}.
14070
14071One popular reason to build several @value{GDBN} configurations in separate
5d161b24
DB
14072directories is to configure @value{GDBN} for cross-compiling (where
14073@value{GDBN} runs on one machine---the @dfn{host}---while debugging
14074programs that run on another machine---the @dfn{target}).
c906108c
SS
14075You specify a cross-debugging target by
14076giving the @samp{--target=@var{target}} option to @code{configure}.
14077
14078When you run @code{make} to build a program or library, you must run
14079it in a configured directory---whatever directory you were in when you
14080called @code{configure} (or one of its subdirectories).
14081
14082The @code{Makefile} that @code{configure} generates in each source
14083directory also runs recursively. If you type @code{make} in a source
14084directory such as @file{gdb-@value{GDBVN}} (or in a separate configured
14085directory configured with @samp{--srcdir=@var{dirname}/gdb-@value{GDBVN}}), you
14086will build all the required libraries, and then build GDB.
14087
14088When you have multiple hosts or targets configured in separate
14089directories, you can run @code{make} on them in parallel (for example,
14090if they are NFS-mounted on each of the hosts); they will not interfere
14091with each other.
14092
6d2ebf8b 14093@node Config Names
c906108c
SS
14094@section Specifying names for hosts and targets
14095
14096The specifications used for hosts and targets in the @code{configure}
14097script are based on a three-part naming scheme, but some short predefined
14098aliases are also supported. The full naming scheme encodes three pieces
14099of information in the following pattern:
14100
14101@example
14102@var{architecture}-@var{vendor}-@var{os}
14103@end example
14104
14105For example, you can use the alias @code{sun4} as a @var{host} argument,
14106or as the value for @var{target} in a @code{--target=@var{target}}
14107option. The equivalent full name is @samp{sparc-sun-sunos4}.
14108
14109The @code{configure} script accompanying @value{GDBN} does not provide
14110any query facility to list all supported host and target names or
14111aliases. @code{configure} calls the Bourne shell script
14112@code{config.sub} to map abbreviations to full names; you can read the
14113script, if you wish, or you can use it to test your guesses on
14114abbreviations---for example:
14115
14116@smallexample
14117% sh config.sub i386-linux
14118i386-pc-linux-gnu
14119% sh config.sub alpha-linux
14120alpha-unknown-linux-gnu
14121% sh config.sub hp9k700
14122hppa1.1-hp-hpux
14123% sh config.sub sun4
14124sparc-sun-sunos4.1.1
14125% sh config.sub sun3
14126m68k-sun-sunos4.1.1
14127% sh config.sub i986v
14128Invalid configuration `i986v': machine `i986v' not recognized
14129@end smallexample
14130
14131@noindent
14132@code{config.sub} is also distributed in the @value{GDBN} source
14133directory (@file{gdb-@value{GDBVN}}, for version @value{GDBVN}).
14134
6d2ebf8b 14135@node Configure Options
c906108c
SS
14136@section @code{configure} options
14137
14138Here is a summary of the @code{configure} options and arguments that
14139are most often useful for building @value{GDBN}. @code{configure} also has
14140several other options not listed here. @inforef{What Configure
14141Does,,configure.info}, for a full explanation of @code{configure}.
14142
14143@example
14144configure @r{[}--help@r{]}
14145 @r{[}--prefix=@var{dir}@r{]}
14146 @r{[}--exec-prefix=@var{dir}@r{]}
14147 @r{[}--srcdir=@var{dirname}@r{]}
14148 @r{[}--norecursion@r{]} @r{[}--rm@r{]}
14149 @r{[}--target=@var{target}@r{]}
14150 @var{host}
14151@end example
14152
14153@noindent
14154You may introduce options with a single @samp{-} rather than
14155@samp{--} if you prefer; but you may abbreviate option names if you use
14156@samp{--}.
14157
14158@table @code
14159@item --help
14160Display a quick summary of how to invoke @code{configure}.
14161
14162@item --prefix=@var{dir}
14163Configure the source to install programs and files under directory
14164@file{@var{dir}}.
14165
14166@item --exec-prefix=@var{dir}
14167Configure the source to install programs under directory
14168@file{@var{dir}}.
14169
14170@c avoid splitting the warning from the explanation:
14171@need 2000
14172@item --srcdir=@var{dirname}
14173@strong{Warning: using this option requires @sc{gnu} @code{make}, or another
14174@code{make} that implements the @code{VPATH} feature.}@*
14175Use this option to make configurations in directories separate from the
14176@value{GDBN} source directories. Among other things, you can use this to
14177build (or maintain) several configurations simultaneously, in separate
14178directories. @code{configure} writes configuration specific files in
14179the current directory, but arranges for them to use the source in the
14180directory @var{dirname}. @code{configure} creates directories under
14181the working directory in parallel to the source directories below
14182@var{dirname}.
14183
14184@item --norecursion
14185Configure only the directory level where @code{configure} is executed; do not
14186propagate configuration to subdirectories.
14187
14188@item --target=@var{target}
14189Configure @value{GDBN} for cross-debugging programs running on the specified
14190@var{target}. Without this option, @value{GDBN} is configured to debug
14191programs that run on the same machine (@var{host}) as @value{GDBN} itself.
14192
14193There is no convenient way to generate a list of all available targets.
14194
14195@item @var{host} @dots{}
14196Configure @value{GDBN} to run on the specified @var{host}.
14197
14198There is no convenient way to generate a list of all available hosts.
14199@end table
14200
14201There are many other options available as well, but they are generally
14202needed for special purposes only.
5d161b24 14203
6d2ebf8b 14204@node Index
c906108c
SS
14205@unnumbered Index
14206
14207@printindex cp
14208
14209@tex
14210% I think something like @colophon should be in texinfo. In the
14211% meantime:
14212\long\def\colophon{\hbox to0pt{}\vfill
14213\centerline{The body of this manual is set in}
14214\centerline{\fontname\tenrm,}
14215\centerline{with headings in {\bf\fontname\tenbf}}
14216\centerline{and examples in {\tt\fontname\tentt}.}
14217\centerline{{\it\fontname\tenit\/},}
14218\centerline{{\bf\fontname\tenbf}, and}
14219\centerline{{\sl\fontname\tensl\/}}
14220\centerline{are used for emphasis.}\vfill}
14221\page\colophon
14222% Blame: doc@cygnus.com, 1991.
14223@end tex
14224
449f3b6c
AC
14225@c TeX can handle the contents at the start but makeinfo 3.12 can not
14226@ifinfo
c906108c 14227@contents
449f3b6c
AC
14228@end ifinfo
14229@ifhtml
14230@contents
14231@end ifhtml
14232
c906108c 14233@bye
This page took 0.853297 seconds and 4 git commands to generate.