]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blame - gdb/doc/gdb.texinfo
* tc-arm.c ((do_ldst): Fix handling an immediate expression pseudo
[thirdparty/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
959acfd1 34@set DATE December 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
959acfd1
EZ
59Invariant Sections being ``Free Software'' and ``Free Software Needs
60Free Documentation'', with the Front-Cover Texts being ``A GNU Manual,''
61and with 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
959acfd1
EZ
96Invariant Sections being ``Free Software'' and ``Free Software Needs
97Free Documentation'', with the Front-Cover Texts being ``A GNU Manual,''
98and with the Back-Cover Texts as in (a) below.
e9c75b65
EZ
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
df0cd8c5 130* Overlays:: Debugging programs that use overlays
6d2ebf8b
SS
131
132* Languages:: Using @value{GDBN} with different languages
133
134* Symbols:: Examining the symbol table
135* Altering:: Altering execution
136* GDB Files:: @value{GDBN} files
137* Targets:: Specifying a debugging target
138* Configurations:: Configuration-specific information
139* Controlling GDB:: Controlling @value{GDBN}
140* Sequences:: Canned sequences of commands
c4555f82 141* TUI:: @value{GDBN} Text User Interface
6d2ebf8b
SS
142* Emacs:: Using @value{GDBN} under @sc{gnu} Emacs
143* Annotations:: @value{GDBN}'s annotation interface.
7162c0ca 144* GDB/MI:: @value{GDBN}'s Machine Interface.
6d2ebf8b
SS
145
146* GDB Bugs:: Reporting bugs in @value{GDBN}
147* Formatting Documentation:: How to format and print @value{GDBN} documentation
148
149* Command Line Editing:: Command Line Editing
150* Using History Interactively:: Using History Interactively
151* Installing GDB:: Installing GDB
152* Index:: Index
153@end menu
154
b9deaee7 155@end ifinfo
6d2ebf8b
SS
156
157@c the replication sucks, but this avoids a texinfo 3.12 lameness
158
159@ifhtml
160@node Top
161
162@top Debugging with @value{GDBN}
163
164This file describes @value{GDBN}, the @sc{gnu} symbolic debugger.
165
b37052ae 166This is the @value{EDITION} Edition, @value{DATE}, for @value{GDBN} Version
6d2ebf8b
SS
167@value{GDBVN}.
168
169Copyright (C) 1988-2000 Free Software Foundation, Inc.
170
c906108c
SS
171@menu
172* Summary:: Summary of @value{GDBN}
c906108c 173* Sample Session:: A sample @value{GDBN} session
c906108c
SS
174
175* Invocation:: Getting in and out of @value{GDBN}
176* Commands:: @value{GDBN} commands
177* Running:: Running programs under @value{GDBN}
178* Stopping:: Stopping and continuing
179* Stack:: Examining the stack
180* Source:: Examining source files
181* Data:: Examining data
496e6bc3 182* Tracepoints:: Debugging remote targets non-intrusively
df0cd8c5 183* Overlays:: Debugging programs that use overlays
c906108c 184
7a292a7a 185* Languages:: Using @value{GDBN} with different languages
c906108c
SS
186
187* Symbols:: Examining the symbol table
188* Altering:: Altering execution
189* GDB Files:: @value{GDBN} files
190* Targets:: Specifying a debugging target
104c1213 191* Configurations:: Configuration-specific information
c906108c
SS
192* Controlling GDB:: Controlling @value{GDBN}
193* Sequences:: Canned sequences of commands
496e6bc3 194* TUI:: @value{GDBN} Text User Interface
c906108c 195* Emacs:: Using @value{GDBN} under @sc{gnu} Emacs
6d2ebf8b 196* Annotations:: @value{GDBN}'s annotation interface.
496e6bc3 197* GDB/MI:: @value{GDBN}'s Machine Interface.
c906108c
SS
198
199* GDB Bugs:: Reporting bugs in @value{GDBN}
c906108c 200* Formatting Documentation:: How to format and print @value{GDBN} documentation
c906108c
SS
201
202* Command Line Editing:: Command Line Editing
203* Using History Interactively:: Using History Interactively
204* Installing GDB:: Installing GDB
205* Index:: Index
c906108c
SS
206@end menu
207
6d2ebf8b
SS
208@end ifhtml
209
449f3b6c
AC
210@c TeX can handle the contents at the start but makeinfo 3.12 can not
211@iftex
212@contents
213@end iftex
214
6d2ebf8b 215@node Summary
c906108c
SS
216@unnumbered Summary of @value{GDBN}
217
218The purpose of a debugger such as @value{GDBN} is to allow you to see what is
219going on ``inside'' another program while it executes---or what another
220program was doing at the moment it crashed.
221
222@value{GDBN} can do four main kinds of things (plus other things in support of
223these) to help you catch bugs in the act:
224
225@itemize @bullet
226@item
227Start your program, specifying anything that might affect its behavior.
228
229@item
230Make your program stop on specified conditions.
231
232@item
233Examine what has happened, when your program has stopped.
234
235@item
236Change things in your program, so you can experiment with correcting the
237effects of one bug and go on to learn about another.
238@end itemize
239
cce74817 240You can use @value{GDBN} to debug programs written in C and C++.
c906108c 241For more information, see @ref{Support,,Supported languages}.
c906108c
SS
242For more information, see @ref{C,,C and C++}.
243
cce74817
JM
244@cindex Chill
245@cindex Modula-2
c906108c 246Support for Modula-2 and Chill is partial. For information on Modula-2,
cce74817 247see @ref{Modula-2,,Modula-2}. For information on Chill, see @ref{Chill}.
c906108c 248
cce74817
JM
249@cindex Pascal
250Debugging Pascal programs which use sets, subranges, file variables, or
251nested functions does not currently work. @value{GDBN} does not support
252entering expressions, printing values, or similar features using Pascal
253syntax.
c906108c 254
c906108c
SS
255@cindex Fortran
256@value{GDBN} can be used to debug programs written in Fortran, although
53a5351d 257it may be necessary to refer to some variables with a trailing
cce74817 258underscore.
c906108c 259
c906108c
SS
260@menu
261* Free Software:: Freely redistributable software
262* Contributors:: Contributors to GDB
263@end menu
264
6d2ebf8b 265@node Free Software
c906108c
SS
266@unnumberedsec Free software
267
5d161b24 268@value{GDBN} is @dfn{free software}, protected by the @sc{gnu}
c906108c
SS
269General Public License
270(GPL). The GPL gives you the freedom to copy or adapt a licensed
271program---but every person getting a copy also gets with it the
272freedom to modify that copy (which means that they must get access to
273the source code), and the freedom to distribute further copies.
274Typical software companies use copyrights to limit your freedoms; the
275Free Software Foundation uses the GPL to preserve these freedoms.
276
277Fundamentally, the General Public License is a license which says that
278you have these freedoms and that you cannot take these freedoms away
279from anyone else.
280
2666264b 281@unnumberedsec Free Software Needs Free Documentation
959acfd1
EZ
282
283The biggest deficiency in the free software community today is not in
284the software---it is the lack of good free documentation that we can
285include with the free software. Many of our most important
286programs do not come with free reference manuals and free introductory
287texts. Documentation is an essential part of any software package;
288when an important free software package does not come with a free
289manual and a free tutorial, that is a major gap. We have many such
290gaps today.
291
292Consider Perl, for instance. The tutorial manuals that people
293normally use are non-free. How did this come about? Because the
294authors of those manuals published them with restrictive terms---no
295copying, no modification, source files not available---which exclude
296them from the free software world.
297
298That wasn't the first time this sort of thing happened, and it was far
299from the last. Many times we have heard a GNU user eagerly describe a
300manual that he is writing, his intended contribution to the community,
301only to learn that he had ruined everything by signing a publication
302contract to make it non-free.
303
304Free documentation, like free software, is a matter of freedom, not
305price. The problem with the non-free manual is not that publishers
306charge a price for printed copies---that in itself is fine. (The Free
307Software Foundation sells printed copies of manuals, too.) The
308problem is the restrictions on the use of the manual. Free manuals
309are available in source code form, and give you permission to copy and
310modify. Non-free manuals do not allow this.
311
312The criteria of freedom for a free manual are roughly the same as for
313free software. Redistribution (including the normal kinds of
314commercial redistribution) must be permitted, so that the manual can
315accompany every copy of the program, both on-line and on paper.
316
317Permission for modification of the technical content is crucial too.
318When people modify the software, adding or changing features, if they
319are conscientious they will change the manual too---so they can
320provide accurate and clear documentation for the modified program. A
321manual that leaves you no choice but to write a new manual to document
322a changed version of the program is not really available to our
323community.
324
325Some kinds of limits on the way modification is handled are
326acceptable. For example, requirements to preserve the original
327author's copyright notice, the distribution terms, or the list of
328authors, are ok. It is also no problem to require modified versions
329to include notice that they were modified. Even entire sections that
330may not be deleted or changed are acceptable, as long as they deal
331with nontechnical topics (like this one). These kinds of restrictions
332are acceptable because they don't obstruct the community's normal use
333of the manual.
334
335However, it must be possible to modify all the @emph{technical}
336content of the manual, and then distribute the result in all the usual
337media, through all the usual channels. Otherwise, the restrictions
338obstruct the use of the manual, it is not free, and we need another
339manual to replace it.
340
341Please spread the word about this issue. Our community continues to
342lose manuals to proprietary publishing. If we spread the word that
343free software needs free reference manuals and free tutorials, perhaps
344the next person who wants to contribute by writing documentation will
345realize, before it is too late, that only free manuals contribute to
346the free software community.
347
348If you are writing documentation, please insist on publishing it under
349the GNU Free Documentation License or another free documentation
350license. Remember that this decision requires your approval---you
351don't have to let the publisher decide. Some commercial publishers
352will use a free license if you insist, but they will not propose the
353option; it is up to you to raise the issue and say firmly that this is
354what you want. If the publisher you are dealing with refuses, please
355try other publishers. If you're not sure whether a proposed license
42584a72 356is free, write to @email{licensing@@gnu.org}.
959acfd1
EZ
357
358You can encourage commercial publishers to sell more free, copylefted
359manuals and tutorials by buying them, and particularly by buying
360copies from the publishers that paid for their writing or for major
361improvements. Meanwhile, try to avoid buying non-free documentation
362at all. Check the distribution terms of a manual before you buy it,
363and insist that whoever seeks your business must respect your freedom.
72c9928d
EZ
364Check the history of the book, and try to reward the publishers that
365have paid or pay the authors to work on it.
959acfd1
EZ
366
367The Free Software Foundation maintains a list of free documentation
368published by other publishers, at
369@url{http://www.fsf.org/doc/other-free-books.html}.
370
6d2ebf8b 371@node Contributors
96a2c332
SS
372@unnumberedsec Contributors to @value{GDBN}
373
374Richard Stallman was the original author of @value{GDBN}, and of many
375other @sc{gnu} programs. Many others have contributed to its
376development. This section attempts to credit major contributors. One
377of the virtues of free software is that everyone is free to contribute
378to it; with regret, we cannot actually acknowledge everyone here. The
379file @file{ChangeLog} in the @value{GDBN} distribution approximates a
c906108c
SS
380blow-by-blow account.
381
382Changes much prior to version 2.0 are lost in the mists of time.
383
384@quotation
385@emph{Plea:} Additions to this section are particularly welcome. If you
386or your friends (or enemies, to be evenhanded) have been unfairly
387omitted from this list, we would like to add your names!
388@end quotation
389
390So that they may not regard their many labors as thankless, we
391particularly thank those who shepherded @value{GDBN} through major
392releases:
b37052ae 393Andrew Cagney (releases 5.0 and 5.1);
c906108c
SS
394Jim Blandy (release 4.18);
395Jason Molenda (release 4.17);
396Stan Shebs (release 4.14);
397Fred Fish (releases 4.16, 4.15, 4.13, 4.12, 4.11, 4.10, and 4.9);
398Stu Grossman and John Gilmore (releases 4.8, 4.7, 4.6, 4.5, and 4.4);
399John Gilmore (releases 4.3, 4.2, 4.1, 4.0, and 3.9);
400Jim Kingdon (releases 3.5, 3.4, and 3.3);
401and Randy Smith (releases 3.2, 3.1, and 3.0).
402
403Richard Stallman, assisted at various times by Peter TerMaat, Chris
404Hanson, and Richard Mlynarik, handled releases through 2.8.
405
b37052ae
EZ
406Michael Tiemann is the author of most of the @sc{gnu} C@t{++} support
407in @value{GDBN}, with significant additional contributions from Per
408Bothner and Daniel Berlin. James Clark wrote the @sc{gnu} C@t{++}
409demangler. Early work on C@t{++} was by Peter TerMaat (who also did
410much general update work leading to release 3.0).
c906108c 411
b37052ae 412@value{GDBN} uses the BFD subroutine library to examine multiple
c906108c
SS
413object-file formats; BFD was a joint project of David V.
414Henkel-Wallace, Rich Pixley, Steve Chamberlain, and John Gilmore.
415
416David Johnson wrote the original COFF support; Pace Willison did
417the original support for encapsulated COFF.
418
96c405b3 419Brent Benson of Harris Computer Systems contributed DWARF2 support.
c906108c
SS
420
421Adam de Boor and Bradley Davis contributed the ISI Optimum V support.
422Per Bothner, Noboyuki Hikichi, and Alessandro Forin contributed MIPS
423support.
424Jean-Daniel Fekete contributed Sun 386i support.
425Chris Hanson improved the HP9000 support.
426Noboyuki Hikichi and Tomoyuki Hasei contributed Sony/News OS 3 support.
427David Johnson contributed Encore Umax support.
428Jyrki Kuoppala contributed Altos 3068 support.
429Jeff Law contributed HP PA and SOM support.
430Keith Packard contributed NS32K support.
431Doug Rabson contributed Acorn Risc Machine support.
432Bob Rusk contributed Harris Nighthawk CX-UX support.
433Chris Smith contributed Convex support (and Fortran debugging).
434Jonathan Stone contributed Pyramid support.
435Michael Tiemann contributed SPARC support.
436Tim Tucker contributed support for the Gould NP1 and Gould Powernode.
437Pace Willison contributed Intel 386 support.
438Jay Vosburgh contributed Symmetry support.
439
440Andreas Schwab contributed M68K Linux support.
441
442Rich Schaefer and Peter Schauer helped with support of SunOS shared
443libraries.
444
445Jay Fenlason and Roland McGrath ensured that @value{GDBN} and GAS agree
446about several machine instruction sets.
447
448Patrick Duval, Ted Goldstein, Vikram Koka and Glenn Engel helped develop
449remote debugging. Intel Corporation, Wind River Systems, AMD, and ARM
450contributed remote debugging modules for the i960, VxWorks, A29K UDI,
451and RDI targets, respectively.
452
453Brian Fox is the author of the readline libraries providing
454command-line editing and command history.
455
7a292a7a
SS
456Andrew Beers of SUNY Buffalo wrote the language-switching code, the
457Modula-2 support, and contributed the Languages chapter of this manual.
c906108c 458
5d161b24 459Fred Fish wrote most of the support for Unix System Vr4.
b37052ae 460He also enhanced the command-completion support to cover C@t{++} overloaded
c906108c 461symbols.
c906108c
SS
462
463Hitachi America, Ltd. sponsored the support for H8/300, H8/500, and
464Super-H processors.
465
466NEC sponsored the support for the v850, Vr4xxx, and Vr5xxx processors.
467
468Mitsubishi sponsored the support for D10V, D30V, and M32R/D processors.
469
470Toshiba sponsored the support for the TX39 Mips processor.
471
472Matsushita sponsored the support for the MN10200 and MN10300 processors.
473
96a2c332 474Fujitsu sponsored the support for SPARClite and FR30 processors.
c906108c
SS
475
476Kung Hsu, Jeff Law, and Rick Sladkey added support for hardware
477watchpoints.
478
479Michael Snyder added support for tracepoints.
480
481Stu Grossman wrote gdbserver.
482
483Jim Kingdon, Peter Schauer, Ian Taylor, and Stu Grossman made
96a2c332 484nearly innumerable bug fixes and cleanups throughout @value{GDBN}.
c906108c
SS
485
486The following people at the Hewlett-Packard Company contributed
487support for the PA-RISC 2.0 architecture, HP-UX 10.20, 10.30, and 11.0
b37052ae 488(narrow mode), HP's implementation of kernel threads, HP's aC@t{++}
c906108c
SS
489compiler, and the terminal user interface: Ben Krepp, Richard Title,
490John Bishop, Susan Macchia, Kathy Mann, Satish Pai, India Paul, Steve
491Rehrauer, and Elena Zannoni. Kim Haase provided HP-specific
492information in this manual.
493
b37052ae
EZ
494DJ Delorie ported @value{GDBN} to MS-DOS, for the DJGPP project.
495Robert Hoehne made significant contributions to the DJGPP port.
496
96a2c332
SS
497Cygnus Solutions has sponsored @value{GDBN} maintenance and much of its
498development since 1991. Cygnus engineers who have worked on @value{GDBN}
2df3850c
JM
499fulltime include Mark Alexander, Jim Blandy, Per Bothner, Kevin
500Buettner, Edith Epstein, Chris Faylor, Fred Fish, Martin Hunt, Jim
501Ingham, John Gilmore, Stu Grossman, Kung Hsu, Jim Kingdon, John Metzler,
502Fernando Nasser, Geoffrey Noer, Dawn Perchik, Rich Pixley, Zdenek
503Radouch, Keith Seitz, Stan Shebs, David Taylor, and Elena Zannoni. In
504addition, Dave Brolley, Ian Carmichael, Steve Chamberlain, Nick Clifton,
505JT Conklin, Stan Cox, DJ Delorie, Ulrich Drepper, Frank Eigler, Doug
506Evans, Sean Fagan, David Henkel-Wallace, Richard Henderson, Jeff
507Holcomb, Jeff Law, Jim Lemke, Tom Lord, Bob Manson, Michael Meissner,
508Jason Merrill, Catherine Moore, Drew Moseley, Ken Raeburn, Gavin
509Romig-Koch, Rob Savoye, Jamie Smith, Mike Stump, Ian Taylor, Angela
510Thomas, Michael Tiemann, Tom Tromey, Ron Unrau, Jim Wilson, and David
511Zuhn have made contributions both large and small.
c906108c
SS
512
513
6d2ebf8b 514@node Sample Session
c906108c
SS
515@chapter A Sample @value{GDBN} Session
516
517You can use this manual at your leisure to read all about @value{GDBN}.
518However, a handful of commands are enough to get started using the
519debugger. This chapter illustrates those commands.
520
521@iftex
522In this sample session, we emphasize user input like this: @b{input},
523to make it easier to pick out from the surrounding output.
524@end iftex
525
526@c FIXME: this example may not be appropriate for some configs, where
527@c FIXME...primary interest is in remote use.
528
529One of the preliminary versions of @sc{gnu} @code{m4} (a generic macro
530processor) exhibits the following bug: sometimes, when we change its
531quote strings from the default, the commands used to capture one macro
532definition within another stop working. In the following short @code{m4}
533session, we define a macro @code{foo} which expands to @code{0000}; we
534then use the @code{m4} built-in @code{defn} to define @code{bar} as the
535same thing. However, when we change the open quote string to
536@code{<QUOTE>} and the close quote string to @code{<UNQUOTE>}, the same
537procedure fails to define a new synonym @code{baz}:
538
539@smallexample
540$ @b{cd gnu/m4}
541$ @b{./m4}
542@b{define(foo,0000)}
543
544@b{foo}
5450000
546@b{define(bar,defn(`foo'))}
547
548@b{bar}
5490000
550@b{changequote(<QUOTE>,<UNQUOTE>)}
551
552@b{define(baz,defn(<QUOTE>foo<UNQUOTE>))}
553@b{baz}
554@b{C-d}
555m4: End of input: 0: fatal error: EOF in string
556@end smallexample
557
558@noindent
559Let us use @value{GDBN} to try to see what is going on.
560
c906108c
SS
561@smallexample
562$ @b{@value{GDBP} m4}
563@c FIXME: this falsifies the exact text played out, to permit smallbook
564@c FIXME... format to come out better.
565@value{GDBN} is free software and you are welcome to distribute copies
5d161b24 566 of it under certain conditions; type "show copying" to see
c906108c 567 the conditions.
5d161b24 568There is absolutely no warranty for @value{GDBN}; type "show warranty"
c906108c
SS
569 for details.
570
571@value{GDBN} @value{GDBVN}, Copyright 1999 Free Software Foundation, Inc...
572(@value{GDBP})
573@end smallexample
c906108c
SS
574
575@noindent
576@value{GDBN} reads only enough symbol data to know where to find the
577rest when needed; as a result, the first prompt comes up very quickly.
578We now tell @value{GDBN} to use a narrower display width than usual, so
579that examples fit in this manual.
580
581@smallexample
582(@value{GDBP}) @b{set width 70}
583@end smallexample
584
585@noindent
586We need to see how the @code{m4} built-in @code{changequote} works.
587Having looked at the source, we know the relevant subroutine is
588@code{m4_changequote}, so we set a breakpoint there with the @value{GDBN}
589@code{break} command.
590
591@smallexample
592(@value{GDBP}) @b{break m4_changequote}
593Breakpoint 1 at 0x62f4: file builtin.c, line 879.
594@end smallexample
595
596@noindent
597Using the @code{run} command, we start @code{m4} running under @value{GDBN}
598control; as long as control does not reach the @code{m4_changequote}
599subroutine, the program runs as usual:
600
601@smallexample
602(@value{GDBP}) @b{run}
603Starting program: /work/Editorial/gdb/gnu/m4/m4
604@b{define(foo,0000)}
605
606@b{foo}
6070000
608@end smallexample
609
610@noindent
611To trigger the breakpoint, we call @code{changequote}. @value{GDBN}
612suspends execution of @code{m4}, displaying information about the
613context where it stops.
614
615@smallexample
616@b{changequote(<QUOTE>,<UNQUOTE>)}
617
5d161b24 618Breakpoint 1, m4_changequote (argc=3, argv=0x33c70)
c906108c
SS
619 at builtin.c:879
620879 if (bad_argc(TOKEN_DATA_TEXT(argv[0]),argc,1,3))
621@end smallexample
622
623@noindent
624Now we use the command @code{n} (@code{next}) to advance execution to
625the next line of the current function.
626
627@smallexample
628(@value{GDBP}) @b{n}
629882 set_quotes((argc >= 2) ? TOKEN_DATA_TEXT(argv[1])\
630 : nil,
631@end smallexample
632
633@noindent
634@code{set_quotes} looks like a promising subroutine. We can go into it
635by using the command @code{s} (@code{step}) instead of @code{next}.
636@code{step} goes to the next line to be executed in @emph{any}
637subroutine, so it steps into @code{set_quotes}.
638
639@smallexample
640(@value{GDBP}) @b{s}
641set_quotes (lq=0x34c78 "<QUOTE>", rq=0x34c88 "<UNQUOTE>")
642 at input.c:530
643530 if (lquote != def_lquote)
644@end smallexample
645
646@noindent
647The display that shows the subroutine where @code{m4} is now
648suspended (and its arguments) is called a stack frame display. It
649shows a summary of the stack. We can use the @code{backtrace}
650command (which can also be spelled @code{bt}), to see where we are
651in the stack as a whole: the @code{backtrace} command displays a
652stack frame for each active subroutine.
653
654@smallexample
655(@value{GDBP}) @b{bt}
656#0 set_quotes (lq=0x34c78 "<QUOTE>", rq=0x34c88 "<UNQUOTE>")
657 at input.c:530
5d161b24 658#1 0x6344 in m4_changequote (argc=3, argv=0x33c70)
c906108c
SS
659 at builtin.c:882
660#2 0x8174 in expand_macro (sym=0x33320) at macro.c:242
661#3 0x7a88 in expand_token (obs=0x0, t=209696, td=0xf7fffa30)
662 at macro.c:71
663#4 0x79dc in expand_input () at macro.c:40
664#5 0x2930 in main (argc=0, argv=0xf7fffb20) at m4.c:195
665@end smallexample
666
667@noindent
668We step through a few more lines to see what happens. The first two
669times, we can use @samp{s}; the next two times we use @code{n} to avoid
670falling into the @code{xstrdup} subroutine.
671
672@smallexample
673(@value{GDBP}) @b{s}
6740x3b5c 532 if (rquote != def_rquote)
675(@value{GDBP}) @b{s}
6760x3b80 535 lquote = (lq == nil || *lq == '\0') ? \
677def_lquote : xstrdup(lq);
678(@value{GDBP}) @b{n}
679536 rquote = (rq == nil || *rq == '\0') ? def_rquote\
680 : xstrdup(rq);
681(@value{GDBP}) @b{n}
682538 len_lquote = strlen(rquote);
683@end smallexample
684
685@noindent
686The last line displayed looks a little odd; we can examine the variables
687@code{lquote} and @code{rquote} to see if they are in fact the new left
688and right quotes we specified. We use the command @code{p}
689(@code{print}) to see their values.
690
691@smallexample
692(@value{GDBP}) @b{p lquote}
693$1 = 0x35d40 "<QUOTE>"
694(@value{GDBP}) @b{p rquote}
695$2 = 0x35d50 "<UNQUOTE>"
696@end smallexample
697
698@noindent
699@code{lquote} and @code{rquote} are indeed the new left and right quotes.
700To look at some context, we can display ten lines of source
701surrounding the current line with the @code{l} (@code{list}) command.
702
703@smallexample
704(@value{GDBP}) @b{l}
705533 xfree(rquote);
706534
707535 lquote = (lq == nil || *lq == '\0') ? def_lquote\
708 : xstrdup (lq);
709536 rquote = (rq == nil || *rq == '\0') ? def_rquote\
710 : xstrdup (rq);
711537
712538 len_lquote = strlen(rquote);
713539 len_rquote = strlen(lquote);
714540 @}
715541
716542 void
717@end smallexample
718
719@noindent
720Let us step past the two lines that set @code{len_lquote} and
721@code{len_rquote}, and then examine the values of those variables.
722
723@smallexample
724(@value{GDBP}) @b{n}
725539 len_rquote = strlen(lquote);
726(@value{GDBP}) @b{n}
727540 @}
728(@value{GDBP}) @b{p len_lquote}
729$3 = 9
730(@value{GDBP}) @b{p len_rquote}
731$4 = 7
732@end smallexample
733
734@noindent
735That certainly looks wrong, assuming @code{len_lquote} and
736@code{len_rquote} are meant to be the lengths of @code{lquote} and
737@code{rquote} respectively. We can set them to better values using
738the @code{p} command, since it can print the value of
739any expression---and that expression can include subroutine calls and
740assignments.
741
742@smallexample
743(@value{GDBP}) @b{p len_lquote=strlen(lquote)}
744$5 = 7
745(@value{GDBP}) @b{p len_rquote=strlen(rquote)}
746$6 = 9
747@end smallexample
748
749@noindent
750Is that enough to fix the problem of using the new quotes with the
751@code{m4} built-in @code{defn}? We can allow @code{m4} to continue
752executing with the @code{c} (@code{continue}) command, and then try the
753example that caused trouble initially:
754
755@smallexample
756(@value{GDBP}) @b{c}
757Continuing.
758
759@b{define(baz,defn(<QUOTE>foo<UNQUOTE>))}
760
761baz
7620000
763@end smallexample
764
765@noindent
766Success! The new quotes now work just as well as the default ones. The
767problem seems to have been just the two typos defining the wrong
768lengths. We allow @code{m4} exit by giving it an EOF as input:
769
770@smallexample
771@b{C-d}
772Program exited normally.
773@end smallexample
774
775@noindent
776The message @samp{Program exited normally.} is from @value{GDBN}; it
777indicates @code{m4} has finished executing. We can end our @value{GDBN}
778session with the @value{GDBN} @code{quit} command.
779
780@smallexample
781(@value{GDBP}) @b{quit}
782@end smallexample
c906108c 783
6d2ebf8b 784@node Invocation
c906108c
SS
785@chapter Getting In and Out of @value{GDBN}
786
787This chapter discusses how to start @value{GDBN}, and how to get out of it.
5d161b24 788The essentials are:
c906108c 789@itemize @bullet
5d161b24 790@item
53a5351d 791type @samp{@value{GDBP}} to start @value{GDBN}.
5d161b24 792@item
c906108c
SS
793type @kbd{quit} or @kbd{C-d} to exit.
794@end itemize
795
796@menu
797* Invoking GDB:: How to start @value{GDBN}
798* Quitting GDB:: How to quit @value{GDBN}
799* Shell Commands:: How to use shell commands inside @value{GDBN}
800@end menu
801
6d2ebf8b 802@node Invoking GDB
c906108c
SS
803@section Invoking @value{GDBN}
804
c906108c
SS
805Invoke @value{GDBN} by running the program @code{@value{GDBP}}. Once started,
806@value{GDBN} reads commands from the terminal until you tell it to exit.
807
808You can also run @code{@value{GDBP}} with a variety of arguments and options,
809to specify more of your debugging environment at the outset.
810
c906108c
SS
811The command-line options described here are designed
812to cover a variety of situations; in some environments, some of these
5d161b24 813options may effectively be unavailable.
c906108c
SS
814
815The most usual way to start @value{GDBN} is with one argument,
816specifying an executable program:
817
818@example
819@value{GDBP} @var{program}
820@end example
821
c906108c
SS
822@noindent
823You can also start with both an executable program and a core file
824specified:
825
826@example
827@value{GDBP} @var{program} @var{core}
828@end example
829
830You can, instead, specify a process ID as a second argument, if you want
831to debug a running process:
832
833@example
834@value{GDBP} @var{program} 1234
835@end example
836
837@noindent
838would attach @value{GDBN} to process @code{1234} (unless you also have a file
839named @file{1234}; @value{GDBN} does check for a core file first).
840
c906108c 841Taking advantage of the second command-line argument requires a fairly
2df3850c
JM
842complete operating system; when you use @value{GDBN} as a remote
843debugger attached to a bare board, there may not be any notion of
844``process'', and there is often no way to get a core dump. @value{GDBN}
845will warn you if it is unable to attach or to read core dumps.
c906108c 846
aa26fa3a
TT
847You can optionally have @code{@value{GDBP}} pass any arguments after the
848executable file to the inferior using @code{--args}. This option stops
849option processing.
850@example
851gdb --args gcc -O2 -c foo.c
852@end example
853This will cause @code{@value{GDBP}} to debug @code{gcc}, and to set
854@code{gcc}'s command-line arguments (@pxref{Arguments}) to @samp{-O2 -c foo.c}.
855
96a2c332 856You can run @code{@value{GDBP}} without printing the front material, which describes
c906108c
SS
857@value{GDBN}'s non-warranty, by specifying @code{-silent}:
858
859@smallexample
860@value{GDBP} -silent
861@end smallexample
862
863@noindent
864You can further control how @value{GDBN} starts up by using command-line
865options. @value{GDBN} itself can remind you of the options available.
866
867@noindent
868Type
869
870@example
871@value{GDBP} -help
872@end example
873
874@noindent
875to display all available options and briefly describe their use
876(@samp{@value{GDBP} -h} is a shorter equivalent).
877
878All options and command line arguments you give are processed
879in sequential order. The order makes a difference when the
880@samp{-x} option is used.
881
882
883@menu
c906108c
SS
884* File Options:: Choosing files
885* Mode Options:: Choosing modes
886@end menu
887
6d2ebf8b 888@node File Options
c906108c
SS
889@subsection Choosing files
890
2df3850c 891When @value{GDBN} starts, it reads any arguments other than options as
c906108c
SS
892specifying an executable file and core file (or process ID). This is
893the same as if the arguments were specified by the @samp{-se} and
19837790
MS
894@samp{-c} (or @samp{-p} options respectively. (@value{GDBN} reads the
895first argument that does not have an associated option flag as
896equivalent to the @samp{-se} option followed by that argument; and the
897second argument that does not have an associated option flag, if any, as
898equivalent to the @samp{-c}/@samp{-p} option followed by that argument.)
899If the second argument begins with a decimal digit, @value{GDBN} will
900first attempt to attach to it as a process, and if that fails, attempt
901to open it as a corefile. If you have a corefile whose name begins with
902a digit, you can prevent @value{GDBN} from treating it as a pid by
903prefixing it with @samp{"./"}, eg. @samp{"./12345"}.
7a292a7a
SS
904
905If @value{GDBN} has not been configured to included core file support,
906such as for most embedded targets, then it will complain about a second
907argument and ignore it.
c906108c
SS
908
909Many options have both long and short forms; both are shown in the
910following list. @value{GDBN} also recognizes the long forms if you truncate
911them, so long as enough of the option is present to be unambiguous.
912(If you prefer, you can flag option arguments with @samp{--} rather
913than @samp{-}, though we illustrate the more usual convention.)
914
d700128c
EZ
915@c NOTE: the @cindex entries here use double dashes ON PURPOSE. This
916@c way, both those who look for -foo and --foo in the index, will find
917@c it.
918
c906108c
SS
919@table @code
920@item -symbols @var{file}
921@itemx -s @var{file}
d700128c
EZ
922@cindex @code{--symbols}
923@cindex @code{-s}
c906108c
SS
924Read symbol table from file @var{file}.
925
926@item -exec @var{file}
927@itemx -e @var{file}
d700128c
EZ
928@cindex @code{--exec}
929@cindex @code{-e}
7a292a7a
SS
930Use file @var{file} as the executable file to execute when appropriate,
931and for examining pure data in conjunction with a core dump.
c906108c
SS
932
933@item -se @var{file}
d700128c 934@cindex @code{--se}
c906108c
SS
935Read symbol table from file @var{file} and use it as the executable
936file.
937
c906108c
SS
938@item -core @var{file}
939@itemx -c @var{file}
d700128c
EZ
940@cindex @code{--core}
941@cindex @code{-c}
19837790 942Use file @var{file} as a core dump to examine.
c906108c
SS
943
944@item -c @var{number}
19837790
MS
945@item -pid @var{number}
946@itemx -p @var{number}
947@cindex @code{--pid}
948@cindex @code{-p}
949Connect to process ID @var{number}, as with the @code{attach} command.
950If there is no such process, @value{GDBN} will attempt to open a core
951file named @var{number}.
c906108c
SS
952
953@item -command @var{file}
954@itemx -x @var{file}
d700128c
EZ
955@cindex @code{--command}
956@cindex @code{-x}
c906108c
SS
957Execute @value{GDBN} commands from file @var{file}. @xref{Command
958Files,, Command files}.
959
960@item -directory @var{directory}
961@itemx -d @var{directory}
d700128c
EZ
962@cindex @code{--directory}
963@cindex @code{-d}
c906108c
SS
964Add @var{directory} to the path to search for source files.
965
c906108c
SS
966@item -m
967@itemx -mapped
d700128c
EZ
968@cindex @code{--mapped}
969@cindex @code{-m}
c906108c
SS
970@emph{Warning: this option depends on operating system facilities that are not
971supported on all systems.}@*
972If memory-mapped files are available on your system through the @code{mmap}
5d161b24 973system call, you can use this option
c906108c
SS
974to have @value{GDBN} write the symbols from your
975program into a reusable file in the current directory. If the program you are debugging is
96a2c332 976called @file{/tmp/fred}, the mapped symbol file is @file{/tmp/fred.syms}.
c906108c
SS
977Future @value{GDBN} debugging sessions notice the presence of this file,
978and can quickly map in symbol information from it, rather than reading
979the symbol table from the executable program.
980
981The @file{.syms} file is specific to the host machine where @value{GDBN}
982is run. It holds an exact image of the internal @value{GDBN} symbol
983table. It cannot be shared across multiple host platforms.
c906108c 984
c906108c
SS
985@item -r
986@itemx -readnow
d700128c
EZ
987@cindex @code{--readnow}
988@cindex @code{-r}
c906108c
SS
989Read each symbol file's entire symbol table immediately, rather than
990the default, which is to read it incrementally as it is needed.
991This makes startup slower, but makes future operations faster.
53a5351d 992
c906108c
SS
993@end table
994
2df3850c 995You typically combine the @code{-mapped} and @code{-readnow} options in
c906108c 996order to build a @file{.syms} file that contains complete symbol
2df3850c
JM
997information. (@xref{Files,,Commands to specify files}, for information
998on @file{.syms} files.) A simple @value{GDBN} invocation to do nothing
999but build a @file{.syms} file for future use is:
c906108c
SS
1000
1001@example
2df3850c 1002gdb -batch -nx -mapped -readnow programname
c906108c 1003@end example
c906108c 1004
6d2ebf8b 1005@node Mode Options
c906108c
SS
1006@subsection Choosing modes
1007
1008You can run @value{GDBN} in various alternative modes---for example, in
1009batch mode or quiet mode.
1010
1011@table @code
1012@item -nx
1013@itemx -n
d700128c
EZ
1014@cindex @code{--nx}
1015@cindex @code{-n}
96565e91 1016Do not execute commands found in any initialization files. Normally,
2df3850c
JM
1017@value{GDBN} executes the commands in these files after all the command
1018options and arguments have been processed. @xref{Command Files,,Command
1019files}.
c906108c
SS
1020
1021@item -quiet
d700128c 1022@itemx -silent
c906108c 1023@itemx -q
d700128c
EZ
1024@cindex @code{--quiet}
1025@cindex @code{--silent}
1026@cindex @code{-q}
c906108c
SS
1027``Quiet''. Do not print the introductory and copyright messages. These
1028messages are also suppressed in batch mode.
1029
1030@item -batch
d700128c 1031@cindex @code{--batch}
c906108c
SS
1032Run in batch mode. Exit with status @code{0} after processing all the
1033command files specified with @samp{-x} (and all commands from
1034initialization files, if not inhibited with @samp{-n}). Exit with
1035nonzero status if an error occurs in executing the @value{GDBN} commands
1036in the command files.
1037
2df3850c
JM
1038Batch mode may be useful for running @value{GDBN} as a filter, for
1039example to download and run a program on another computer; in order to
1040make this more useful, the message
c906108c
SS
1041
1042@example
1043Program exited normally.
1044@end example
1045
1046@noindent
2df3850c
JM
1047(which is ordinarily issued whenever a program running under
1048@value{GDBN} control terminates) is not issued when running in batch
1049mode.
1050
1051@item -nowindows
1052@itemx -nw
d700128c
EZ
1053@cindex @code{--nowindows}
1054@cindex @code{-nw}
2df3850c 1055``No windows''. If @value{GDBN} comes with a graphical user interface
96a2c332 1056(GUI) built in, then this option tells @value{GDBN} to only use the command-line
2df3850c
JM
1057interface. If no GUI is available, this option has no effect.
1058
1059@item -windows
1060@itemx -w
d700128c
EZ
1061@cindex @code{--windows}
1062@cindex @code{-w}
2df3850c
JM
1063If @value{GDBN} includes a GUI, then this option requires it to be
1064used if possible.
c906108c
SS
1065
1066@item -cd @var{directory}
d700128c 1067@cindex @code{--cd}
c906108c
SS
1068Run @value{GDBN} using @var{directory} as its working directory,
1069instead of the current directory.
1070
c906108c
SS
1071@item -fullname
1072@itemx -f
d700128c
EZ
1073@cindex @code{--fullname}
1074@cindex @code{-f}
7a292a7a
SS
1075@sc{gnu} Emacs sets this option when it runs @value{GDBN} as a
1076subprocess. It tells @value{GDBN} to output the full file name and line
1077number in a standard, recognizable fashion each time a stack frame is
1078displayed (which includes each time your program stops). This
1079recognizable format looks like two @samp{\032} characters, followed by
1080the file name, line number and character position separated by colons,
1081and a newline. The Emacs-to-@value{GDBN} interface program uses the two
1082@samp{\032} characters as a signal to display the source code for the
1083frame.
c906108c 1084
d700128c
EZ
1085@item -epoch
1086@cindex @code{--epoch}
1087The Epoch Emacs-@value{GDBN} interface sets this option when it runs
1088@value{GDBN} as a subprocess. It tells @value{GDBN} to modify its print
1089routines so as to allow Epoch to display values of expressions in a
1090separate window.
1091
1092@item -annotate @var{level}
1093@cindex @code{--annotate}
1094This option sets the @dfn{annotation level} inside @value{GDBN}. Its
1095effect is identical to using @samp{set annotate @var{level}}
1096(@pxref{Annotations}).
1097Annotation level controls how much information does @value{GDBN} print
1098together with its prompt, values of expressions, source lines, and other
1099types of output. Level 0 is the normal, level 1 is for use when
1100@value{GDBN} is run as a subprocess of @sc{gnu} Emacs, level 2 is the
1101maximum annotation suitable for programs that control @value{GDBN}.
1102
1103@item -async
1104@cindex @code{--async}
1105Use the asynchronous event loop for the command-line interface.
1106@value{GDBN} processes all events, such as user keyboard input, via a
1107special event loop. This allows @value{GDBN} to accept and process user
1108commands in parallel with the debugged process being
1109run@footnote{@value{GDBN} built with @sc{djgpp} tools for
1110MS-DOS/MS-Windows supports this mode of operation, but the event loop is
1111suspended when the debuggee runs.}, so you don't need to wait for
1112control to return to @value{GDBN} before you type the next command.
b37052ae 1113(@emph{Note:} as of version 5.1, the target side of the asynchronous
d700128c
EZ
1114operation is not yet in place, so @samp{-async} does not work fully
1115yet.)
1116@c FIXME: when the target side of the event loop is done, the above NOTE
1117@c should be removed.
1118
1119When the standard input is connected to a terminal device, @value{GDBN}
1120uses the asynchronous event loop by default, unless disabled by the
1121@samp{-noasync} option.
1122
1123@item -noasync
1124@cindex @code{--noasync}
1125Disable the asynchronous event loop for the command-line interface.
1126
aa26fa3a
TT
1127@item --args
1128@cindex @code{--args}
1129Change interpretation of command line so that arguments following the
1130executable file are passed as command line arguments to the inferior.
1131This option stops option processing.
1132
2df3850c
JM
1133@item -baud @var{bps}
1134@itemx -b @var{bps}
d700128c
EZ
1135@cindex @code{--baud}
1136@cindex @code{-b}
c906108c
SS
1137Set the line speed (baud rate or bits per second) of any serial
1138interface used by @value{GDBN} for remote debugging.
c906108c
SS
1139
1140@item -tty @var{device}
d700128c
EZ
1141@itemx -t @var{device}
1142@cindex @code{--tty}
1143@cindex @code{-t}
c906108c
SS
1144Run using @var{device} for your program's standard input and output.
1145@c FIXME: kingdon thinks there is more to -tty. Investigate.
c906108c 1146
53a5351d 1147@c resolve the situation of these eventually
c4555f82
SC
1148@item -tui
1149@cindex @code{--tui}
1150Activate the Terminal User Interface when starting.
1151The Terminal User Interface manages several text windows on the terminal,
1152showing source, assembly, registers and @value{GDBN} command outputs
1153(@pxref{TUI, ,@value{GDBN} Text User Interface}).
1154Do not use this option if you run @value{GDBN} from Emacs
1155(@pxref{Emacs, ,Using @value{GDBN} under @sc{gnu} Emacs}).
53a5351d
JM
1156
1157@c @item -xdb
d700128c 1158@c @cindex @code{--xdb}
53a5351d
JM
1159@c Run in XDB compatibility mode, allowing the use of certain XDB commands.
1160@c For information, see the file @file{xdb_trans.html}, which is usually
1161@c installed in the directory @code{/opt/langtools/wdb/doc} on HP-UX
1162@c systems.
1163
d700128c
EZ
1164@item -interpreter @var{interp}
1165@cindex @code{--interpreter}
1166Use the interpreter @var{interp} for interface with the controlling
1167program or device. This option is meant to be set by programs which
94bbb2c0
AC
1168communicate with @value{GDBN} using it as a back end.
1169
1170@samp{--interpreter=mi} (or @samp{--interpreter=mi1}) causes
1171@value{GDBN} to use the @dfn{gdb/mi interface} (@pxref{GDB/MI, , The
1172@sc{gdb/mi} Interface}). The older @sc{gdb/mi} interface, included in
1173@value{GDBN} version 5.0 can be selected with @samp{--interpreter=mi0}.
d700128c
EZ
1174
1175@item -write
1176@cindex @code{--write}
1177Open the executable and core files for both reading and writing. This
1178is equivalent to the @samp{set write on} command inside @value{GDBN}
1179(@pxref{Patching}).
1180
1181@item -statistics
1182@cindex @code{--statistics}
1183This option causes @value{GDBN} to print statistics about time and
1184memory usage after it completes each command and returns to the prompt.
1185
1186@item -version
1187@cindex @code{--version}
1188This option causes @value{GDBN} to print its version number and
1189no-warranty blurb, and exit.
1190
c906108c
SS
1191@end table
1192
6d2ebf8b 1193@node Quitting GDB
c906108c
SS
1194@section Quitting @value{GDBN}
1195@cindex exiting @value{GDBN}
1196@cindex leaving @value{GDBN}
1197
1198@table @code
1199@kindex quit @r{[}@var{expression}@r{]}
41afff9a 1200@kindex q @r{(@code{quit})}
96a2c332
SS
1201@item quit @r{[}@var{expression}@r{]}
1202@itemx q
1203To exit @value{GDBN}, use the @code{quit} command (abbreviated
1204@code{q}), or type an end-of-file character (usually @kbd{C-d}). If you
1205do not supply @var{expression}, @value{GDBN} will terminate normally;
1206otherwise it will terminate using the result of @var{expression} as the
1207error code.
c906108c
SS
1208@end table
1209
1210@cindex interrupt
1211An interrupt (often @kbd{C-c}) does not exit from @value{GDBN}, but rather
1212terminates the action of any @value{GDBN} command that is in progress and
1213returns to @value{GDBN} command level. It is safe to type the interrupt
1214character at any time because @value{GDBN} does not allow it to take effect
1215until a time when it is safe.
1216
c906108c
SS
1217If you have been using @value{GDBN} to control an attached process or
1218device, you can release it with the @code{detach} command
1219(@pxref{Attach, ,Debugging an already-running process}).
c906108c 1220
6d2ebf8b 1221@node Shell Commands
c906108c
SS
1222@section Shell commands
1223
1224If you need to execute occasional shell commands during your
1225debugging session, there is no need to leave or suspend @value{GDBN}; you can
1226just use the @code{shell} command.
1227
1228@table @code
1229@kindex shell
1230@cindex shell escape
1231@item shell @var{command string}
1232Invoke a standard shell to execute @var{command string}.
c906108c 1233If it exists, the environment variable @code{SHELL} determines which
d4f3574e
SS
1234shell to run. Otherwise @value{GDBN} uses the default shell
1235(@file{/bin/sh} on Unix systems, @file{COMMAND.COM} on MS-DOS, etc.).
c906108c
SS
1236@end table
1237
1238The utility @code{make} is often needed in development environments.
1239You do not have to use the @code{shell} command for this purpose in
1240@value{GDBN}:
1241
1242@table @code
1243@kindex make
1244@cindex calling make
1245@item make @var{make-args}
1246Execute the @code{make} program with the specified
1247arguments. This is equivalent to @samp{shell make @var{make-args}}.
1248@end table
1249
6d2ebf8b 1250@node Commands
c906108c
SS
1251@chapter @value{GDBN} Commands
1252
1253You can abbreviate a @value{GDBN} command to the first few letters of the command
1254name, if that abbreviation is unambiguous; and you can repeat certain
1255@value{GDBN} commands by typing just @key{RET}. You can also use the @key{TAB}
1256key to get @value{GDBN} to fill out the rest of a word in a command (or to
1257show you the alternatives available, if there is more than one possibility).
1258
1259@menu
1260* Command Syntax:: How to give commands to @value{GDBN}
1261* Completion:: Command completion
1262* Help:: How to ask @value{GDBN} for help
1263@end menu
1264
6d2ebf8b 1265@node Command Syntax
c906108c
SS
1266@section Command syntax
1267
1268A @value{GDBN} command is a single line of input. There is no limit on
1269how long it can be. It starts with a command name, which is followed by
1270arguments whose meaning depends on the command name. For example, the
1271command @code{step} accepts an argument which is the number of times to
1272step, as in @samp{step 5}. You can also use the @code{step} command
96a2c332 1273with no arguments. Some commands do not allow any arguments.
c906108c
SS
1274
1275@cindex abbreviation
1276@value{GDBN} command names may always be truncated if that abbreviation is
1277unambiguous. Other possible command abbreviations are listed in the
1278documentation for individual commands. In some cases, even ambiguous
1279abbreviations are allowed; for example, @code{s} is specially defined as
1280equivalent to @code{step} even though there are other commands whose
1281names start with @code{s}. You can test abbreviations by using them as
1282arguments to the @code{help} command.
1283
1284@cindex repeating commands
41afff9a 1285@kindex RET @r{(repeat last command)}
c906108c 1286A blank line as input to @value{GDBN} (typing just @key{RET}) means to
96a2c332 1287repeat the previous command. Certain commands (for example, @code{run})
c906108c
SS
1288will not repeat this way; these are commands whose unintentional
1289repetition might cause trouble and which you are unlikely to want to
1290repeat.
1291
1292The @code{list} and @code{x} commands, when you repeat them with
1293@key{RET}, construct new arguments rather than repeating
1294exactly as typed. This permits easy scanning of source or memory.
1295
1296@value{GDBN} can also use @key{RET} in another way: to partition lengthy
1297output, in a way similar to the common utility @code{more}
1298(@pxref{Screen Size,,Screen size}). Since it is easy to press one
1299@key{RET} too many in this situation, @value{GDBN} disables command
1300repetition after any command that generates this sort of display.
1301
41afff9a 1302@kindex # @r{(a comment)}
c906108c
SS
1303@cindex comment
1304Any text from a @kbd{#} to the end of the line is a comment; it does
1305nothing. This is useful mainly in command files (@pxref{Command
1306Files,,Command files}).
1307
88118b3a
TT
1308@cindex repeating command sequences
1309@kindex C-o @r{(operate-and-get-next)}
1310The @kbd{C-o} binding is useful for repeating a complex sequence of
1311commands. This command accepts the current line, like @kbd{RET}, and
1312then fetches the next line relative to the current line from the history
1313for editing.
1314
6d2ebf8b 1315@node Completion
c906108c
SS
1316@section Command completion
1317
1318@cindex completion
1319@cindex word completion
1320@value{GDBN} can fill in the rest of a word in a command for you, if there is
1321only one possibility; it can also show you what the valid possibilities
1322are for the next word in a command, at any time. This works for @value{GDBN}
1323commands, @value{GDBN} subcommands, and the names of symbols in your program.
1324
1325Press the @key{TAB} key whenever you want @value{GDBN} to fill out the rest
1326of a word. If there is only one possibility, @value{GDBN} fills in the
1327word, and waits for you to finish the command (or press @key{RET} to
1328enter it). For example, if you type
1329
1330@c FIXME "@key" does not distinguish its argument sufficiently to permit
1331@c complete accuracy in these examples; space introduced for clarity.
1332@c If texinfo enhancements make it unnecessary, it would be nice to
1333@c replace " @key" by "@key" in the following...
1334@example
1335(@value{GDBP}) info bre @key{TAB}
1336@end example
1337
1338@noindent
1339@value{GDBN} fills in the rest of the word @samp{breakpoints}, since that is
1340the only @code{info} subcommand beginning with @samp{bre}:
1341
1342@example
1343(@value{GDBP}) info breakpoints
1344@end example
1345
1346@noindent
1347You can either press @key{RET} at this point, to run the @code{info
1348breakpoints} command, or backspace and enter something else, if
1349@samp{breakpoints} does not look like the command you expected. (If you
1350were sure you wanted @code{info breakpoints} in the first place, you
1351might as well just type @key{RET} immediately after @samp{info bre},
1352to exploit command abbreviations rather than command completion).
1353
1354If there is more than one possibility for the next word when you press
1355@key{TAB}, @value{GDBN} sounds a bell. You can either supply more
1356characters and try again, or just press @key{TAB} a second time;
1357@value{GDBN} displays all the possible completions for that word. For
1358example, you might want to set a breakpoint on a subroutine whose name
1359begins with @samp{make_}, but when you type @kbd{b make_@key{TAB}} @value{GDBN}
1360just sounds the bell. Typing @key{TAB} again displays all the
1361function names in your program that begin with those characters, for
1362example:
1363
1364@example
1365(@value{GDBP}) b make_ @key{TAB}
1366@exdent @value{GDBN} sounds bell; press @key{TAB} again, to see:
5d161b24
DB
1367make_a_section_from_file make_environ
1368make_abs_section make_function_type
1369make_blockvector make_pointer_type
1370make_cleanup make_reference_type
c906108c
SS
1371make_command make_symbol_completion_list
1372(@value{GDBP}) b make_
1373@end example
1374
1375@noindent
1376After displaying the available possibilities, @value{GDBN} copies your
1377partial input (@samp{b make_} in the example) so you can finish the
1378command.
1379
1380If you just want to see the list of alternatives in the first place, you
b37052ae 1381can press @kbd{M-?} rather than pressing @key{TAB} twice. @kbd{M-?}
7a292a7a 1382means @kbd{@key{META} ?}. You can type this either by holding down a
c906108c 1383key designated as the @key{META} shift on your keyboard (if there is
7a292a7a 1384one) while typing @kbd{?}, or as @key{ESC} followed by @kbd{?}.
c906108c
SS
1385
1386@cindex quotes in commands
1387@cindex completion of quoted strings
1388Sometimes the string you need, while logically a ``word'', may contain
7a292a7a
SS
1389parentheses or other characters that @value{GDBN} normally excludes from
1390its notion of a word. To permit word completion to work in this
1391situation, you may enclose words in @code{'} (single quote marks) in
1392@value{GDBN} commands.
c906108c 1393
c906108c 1394The most likely situation where you might need this is in typing the
b37052ae
EZ
1395name of a C@t{++} function. This is because C@t{++} allows function
1396overloading (multiple definitions of the same function, distinguished
1397by argument type). For example, when you want to set a breakpoint you
1398may need to distinguish whether you mean the version of @code{name}
1399that takes an @code{int} parameter, @code{name(int)}, or the version
1400that takes a @code{float} parameter, @code{name(float)}. To use the
1401word-completion facilities in this situation, type a single quote
1402@code{'} at the beginning of the function name. This alerts
1403@value{GDBN} that it may need to consider more information than usual
1404when you press @key{TAB} or @kbd{M-?} to request word completion:
c906108c
SS
1405
1406@example
96a2c332 1407(@value{GDBP}) b 'bubble( @kbd{M-?}
c906108c
SS
1408bubble(double,double) bubble(int,int)
1409(@value{GDBP}) b 'bubble(
1410@end example
1411
1412In some cases, @value{GDBN} can tell that completing a name requires using
1413quotes. When this happens, @value{GDBN} inserts the quote for you (while
1414completing as much as it can) if you do not type the quote in the first
1415place:
1416
1417@example
1418(@value{GDBP}) b bub @key{TAB}
1419@exdent @value{GDBN} alters your input line to the following, and rings a bell:
1420(@value{GDBP}) b 'bubble(
1421@end example
1422
1423@noindent
1424In general, @value{GDBN} can tell that a quote is needed (and inserts it) if
1425you have not yet started typing the argument list when you ask for
1426completion on an overloaded symbol.
1427
d4f3574e 1428For more information about overloaded functions, see @ref{C plus plus
b37052ae 1429expressions, ,C@t{++} expressions}. You can use the command @code{set
c906108c 1430overload-resolution off} to disable overload resolution;
b37052ae 1431see @ref{Debugging C plus plus, ,@value{GDBN} features for C@t{++}}.
c906108c
SS
1432
1433
6d2ebf8b 1434@node Help
c906108c
SS
1435@section Getting help
1436@cindex online documentation
1437@kindex help
1438
5d161b24 1439You can always ask @value{GDBN} itself for information on its commands,
c906108c
SS
1440using the command @code{help}.
1441
1442@table @code
41afff9a 1443@kindex h @r{(@code{help})}
c906108c
SS
1444@item help
1445@itemx h
1446You can use @code{help} (abbreviated @code{h}) with no arguments to
1447display a short list of named classes of commands:
1448
1449@smallexample
1450(@value{GDBP}) help
1451List of classes of commands:
1452
2df3850c 1453aliases -- Aliases of other commands
c906108c 1454breakpoints -- Making program stop at certain points
2df3850c 1455data -- Examining data
c906108c 1456files -- Specifying and examining files
2df3850c
JM
1457internals -- Maintenance commands
1458obscure -- Obscure features
1459running -- Running the program
1460stack -- Examining the stack
c906108c
SS
1461status -- Status inquiries
1462support -- Support facilities
96a2c332
SS
1463tracepoints -- Tracing of program execution without@*
1464 stopping the program
c906108c 1465user-defined -- User-defined commands
c906108c 1466
5d161b24 1467Type "help" followed by a class name for a list of
c906108c 1468commands in that class.
5d161b24 1469Type "help" followed by command name for full
c906108c
SS
1470documentation.
1471Command name abbreviations are allowed if unambiguous.
1472(@value{GDBP})
1473@end smallexample
96a2c332 1474@c the above line break eliminates huge line overfull...
c906108c
SS
1475
1476@item help @var{class}
1477Using one of the general help classes as an argument, you can get a
1478list of the individual commands in that class. For example, here is the
1479help display for the class @code{status}:
1480
1481@smallexample
1482(@value{GDBP}) help status
1483Status inquiries.
1484
1485List of commands:
1486
1487@c Line break in "show" line falsifies real output, but needed
1488@c to fit in smallbook page size.
2df3850c
JM
1489info -- Generic command for showing things
1490 about the program being debugged
1491show -- Generic command for showing things
1492 about the debugger
c906108c 1493
5d161b24 1494Type "help" followed by command name for full
c906108c
SS
1495documentation.
1496Command name abbreviations are allowed if unambiguous.
1497(@value{GDBP})
1498@end smallexample
1499
1500@item help @var{command}
1501With a command name as @code{help} argument, @value{GDBN} displays a
1502short paragraph on how to use that command.
1503
6837a0a2
DB
1504@kindex apropos
1505@item apropos @var{args}
1506The @code{apropos @var{args}} command searches through all of the @value{GDBN}
1507commands, and their documentation, for the regular expression specified in
1508@var{args}. It prints out all matches found. For example:
1509
1510@smallexample
1511apropos reload
1512@end smallexample
1513
b37052ae
EZ
1514@noindent
1515results in:
6837a0a2
DB
1516
1517@smallexample
6d2ebf8b
SS
1518@c @group
1519set symbol-reloading -- Set dynamic symbol table reloading
1520 multiple times in one run
1521show symbol-reloading -- Show dynamic symbol table reloading
1522 multiple times in one run
1523@c @end group
6837a0a2
DB
1524@end smallexample
1525
c906108c
SS
1526@kindex complete
1527@item complete @var{args}
1528The @code{complete @var{args}} command lists all the possible completions
1529for the beginning of a command. Use @var{args} to specify the beginning of the
1530command you want completed. For example:
1531
1532@smallexample
1533complete i
1534@end smallexample
1535
1536@noindent results in:
1537
1538@smallexample
1539@group
2df3850c
JM
1540if
1541ignore
c906108c
SS
1542info
1543inspect
c906108c
SS
1544@end group
1545@end smallexample
1546
1547@noindent This is intended for use by @sc{gnu} Emacs.
1548@end table
1549
1550In addition to @code{help}, you can use the @value{GDBN} commands @code{info}
1551and @code{show} to inquire about the state of your program, or the state
1552of @value{GDBN} itself. Each command supports many topics of inquiry; this
1553manual introduces each of them in the appropriate context. The listings
1554under @code{info} and under @code{show} in the Index point to
1555all the sub-commands. @xref{Index}.
1556
1557@c @group
1558@table @code
1559@kindex info
41afff9a 1560@kindex i @r{(@code{info})}
c906108c
SS
1561@item info
1562This command (abbreviated @code{i}) is for describing the state of your
1563program. For example, you can list the arguments given to your program
1564with @code{info args}, list the registers currently in use with @code{info
1565registers}, or list the breakpoints you have set with @code{info breakpoints}.
1566You can get a complete list of the @code{info} sub-commands with
1567@w{@code{help info}}.
1568
1569@kindex set
1570@item set
5d161b24 1571You can assign the result of an expression to an environment variable with
c906108c
SS
1572@code{set}. For example, you can set the @value{GDBN} prompt to a $-sign with
1573@code{set prompt $}.
1574
1575@kindex show
1576@item show
5d161b24 1577In contrast to @code{info}, @code{show} is for describing the state of
c906108c
SS
1578@value{GDBN} itself.
1579You can change most of the things you can @code{show}, by using the
1580related command @code{set}; for example, you can control what number
1581system is used for displays with @code{set radix}, or simply inquire
1582which is currently in use with @code{show radix}.
1583
1584@kindex info set
1585To display all the settable parameters and their current
1586values, you can use @code{show} with no arguments; you may also use
1587@code{info set}. Both commands produce the same display.
1588@c FIXME: "info set" violates the rule that "info" is for state of
1589@c FIXME...program. Ck w/ GNU: "info set" to be called something else,
1590@c FIXME...or change desc of rule---eg "state of prog and debugging session"?
1591@end table
1592@c @end group
1593
1594Here are three miscellaneous @code{show} subcommands, all of which are
1595exceptional in lacking corresponding @code{set} commands:
1596
1597@table @code
1598@kindex show version
1599@cindex version number
1600@item show version
1601Show what version of @value{GDBN} is running. You should include this
2df3850c
JM
1602information in @value{GDBN} bug-reports. If multiple versions of
1603@value{GDBN} are in use at your site, you may need to determine which
1604version of @value{GDBN} you are running; as @value{GDBN} evolves, new
1605commands are introduced, and old ones may wither away. Also, many
1606system vendors ship variant versions of @value{GDBN}, and there are
96a2c332 1607variant versions of @value{GDBN} in @sc{gnu}/Linux distributions as well.
2df3850c
JM
1608The version number is the same as the one announced when you start
1609@value{GDBN}.
c906108c
SS
1610
1611@kindex show copying
1612@item show copying
1613Display information about permission for copying @value{GDBN}.
1614
1615@kindex show warranty
1616@item show warranty
2df3850c 1617Display the @sc{gnu} ``NO WARRANTY'' statement, or a warranty,
96a2c332 1618if your version of @value{GDBN} comes with one.
2df3850c 1619
c906108c
SS
1620@end table
1621
6d2ebf8b 1622@node Running
c906108c
SS
1623@chapter Running Programs Under @value{GDBN}
1624
1625When you run a program under @value{GDBN}, you must first generate
1626debugging information when you compile it.
7a292a7a
SS
1627
1628You may start @value{GDBN} with its arguments, if any, in an environment
1629of your choice. If you are doing native debugging, you may redirect
1630your program's input and output, debug an already running process, or
1631kill a child process.
c906108c
SS
1632
1633@menu
1634* Compilation:: Compiling for debugging
1635* Starting:: Starting your program
c906108c
SS
1636* Arguments:: Your program's arguments
1637* Environment:: Your program's environment
c906108c
SS
1638
1639* Working Directory:: Your program's working directory
1640* Input/Output:: Your program's input and output
1641* Attach:: Debugging an already-running process
1642* Kill Process:: Killing the child process
c906108c
SS
1643
1644* Threads:: Debugging programs with multiple threads
1645* Processes:: Debugging programs with multiple processes
1646@end menu
1647
6d2ebf8b 1648@node Compilation
c906108c
SS
1649@section Compiling for debugging
1650
1651In order to debug a program effectively, you need to generate
1652debugging information when you compile it. This debugging information
1653is stored in the object file; it describes the data type of each
1654variable or function and the correspondence between source line numbers
1655and addresses in the executable code.
1656
1657To request debugging information, specify the @samp{-g} option when you run
1658the compiler.
1659
1660Many C compilers are unable to handle the @samp{-g} and @samp{-O}
1661options together. Using those compilers, you cannot generate optimized
1662executables containing debugging information.
1663
53a5351d
JM
1664@value{NGCC}, the @sc{gnu} C compiler, supports @samp{-g} with or
1665without @samp{-O}, making it possible to debug optimized code. We
1666recommend that you @emph{always} use @samp{-g} whenever you compile a
1667program. You may think your program is correct, but there is no sense
1668in pushing your luck.
c906108c
SS
1669
1670@cindex optimized code, debugging
1671@cindex debugging optimized code
1672When you debug a program compiled with @samp{-g -O}, remember that the
1673optimizer is rearranging your code; the debugger shows you what is
1674really there. Do not be too surprised when the execution path does not
1675exactly match your source file! An extreme example: if you define a
1676variable, but never use it, @value{GDBN} never sees that
1677variable---because the compiler optimizes it out of existence.
1678
1679Some things do not work as well with @samp{-g -O} as with just
1680@samp{-g}, particularly on machines with instruction scheduling. If in
1681doubt, recompile with @samp{-g} alone, and if this fixes the problem,
1682please report it to us as a bug (including a test case!).
1683
1684Older versions of the @sc{gnu} C compiler permitted a variant option
1685@w{@samp{-gg}} for debugging information. @value{GDBN} no longer supports this
1686format; if your @sc{gnu} C compiler has this option, do not use it.
1687
1688@need 2000
6d2ebf8b 1689@node Starting
c906108c
SS
1690@section Starting your program
1691@cindex starting
1692@cindex running
1693
1694@table @code
1695@kindex run
41afff9a 1696@kindex r @r{(@code{run})}
c906108c
SS
1697@item run
1698@itemx r
7a292a7a
SS
1699Use the @code{run} command to start your program under @value{GDBN}.
1700You must first specify the program name (except on VxWorks) with an
1701argument to @value{GDBN} (@pxref{Invocation, ,Getting In and Out of
1702@value{GDBN}}), or by using the @code{file} or @code{exec-file} command
1703(@pxref{Files, ,Commands to specify files}).
c906108c
SS
1704
1705@end table
1706
c906108c
SS
1707If you are running your program in an execution environment that
1708supports processes, @code{run} creates an inferior process and makes
1709that process run your program. (In environments without processes,
1710@code{run} jumps to the start of your program.)
1711
1712The execution of a program is affected by certain information it
1713receives from its superior. @value{GDBN} provides ways to specify this
1714information, which you must do @emph{before} starting your program. (You
1715can change it after starting your program, but such changes only affect
1716your program the next time you start it.) This information may be
1717divided into four categories:
1718
1719@table @asis
1720@item The @emph{arguments.}
1721Specify the arguments to give your program as the arguments of the
1722@code{run} command. If a shell is available on your target, the shell
1723is used to pass the arguments, so that you may use normal conventions
1724(such as wildcard expansion or variable substitution) in describing
1725the arguments.
1726In Unix systems, you can control which shell is used with the
1727@code{SHELL} environment variable.
1728@xref{Arguments, ,Your program's arguments}.
1729
1730@item The @emph{environment.}
1731Your program normally inherits its environment from @value{GDBN}, but you can
1732use the @value{GDBN} commands @code{set environment} and @code{unset
1733environment} to change parts of the environment that affect
1734your program. @xref{Environment, ,Your program's environment}.
1735
1736@item The @emph{working directory.}
1737Your program inherits its working directory from @value{GDBN}. You can set
1738the @value{GDBN} working directory with the @code{cd} command in @value{GDBN}.
1739@xref{Working Directory, ,Your program's working directory}.
1740
1741@item The @emph{standard input and output.}
1742Your program normally uses the same device for standard input and
1743standard output as @value{GDBN} is using. You can redirect input and output
1744in the @code{run} command line, or you can use the @code{tty} command to
1745set a different device for your program.
1746@xref{Input/Output, ,Your program's input and output}.
1747
1748@cindex pipes
1749@emph{Warning:} While input and output redirection work, you cannot use
1750pipes to pass the output of the program you are debugging to another
1751program; if you attempt this, @value{GDBN} is likely to wind up debugging the
1752wrong program.
1753@end table
c906108c
SS
1754
1755When you issue the @code{run} command, your program begins to execute
1756immediately. @xref{Stopping, ,Stopping and continuing}, for discussion
1757of how to arrange for your program to stop. Once your program has
1758stopped, you may call functions in your program, using the @code{print}
1759or @code{call} commands. @xref{Data, ,Examining Data}.
1760
1761If the modification time of your symbol file has changed since the last
1762time @value{GDBN} read its symbols, @value{GDBN} discards its symbol
1763table, and reads it again. When it does this, @value{GDBN} tries to retain
1764your current breakpoints.
1765
6d2ebf8b 1766@node Arguments
c906108c
SS
1767@section Your program's arguments
1768
1769@cindex arguments (to your program)
1770The arguments to your program can be specified by the arguments of the
5d161b24 1771@code{run} command.
c906108c
SS
1772They are passed to a shell, which expands wildcard characters and
1773performs redirection of I/O, and thence to your program. Your
1774@code{SHELL} environment variable (if it exists) specifies what shell
1775@value{GDBN} uses. If you do not define @code{SHELL}, @value{GDBN} uses
d4f3574e
SS
1776the default shell (@file{/bin/sh} on Unix).
1777
1778On non-Unix systems, the program is usually invoked directly by
1779@value{GDBN}, which emulates I/O redirection via the appropriate system
1780calls, and the wildcard characters are expanded by the startup code of
1781the program, not by the shell.
c906108c
SS
1782
1783@code{run} with no arguments uses the same arguments used by the previous
1784@code{run}, or those set by the @code{set args} command.
1785
c906108c 1786@table @code
41afff9a 1787@kindex set args
c906108c
SS
1788@item set args
1789Specify the arguments to be used the next time your program is run. If
1790@code{set args} has no arguments, @code{run} executes your program
1791with no arguments. Once you have run your program with arguments,
1792using @code{set args} before the next @code{run} is the only way to run
1793it again without arguments.
1794
1795@kindex show args
1796@item show args
1797Show the arguments to give your program when it is started.
1798@end table
1799
6d2ebf8b 1800@node Environment
c906108c
SS
1801@section Your program's environment
1802
1803@cindex environment (of your program)
1804The @dfn{environment} consists of a set of environment variables and
1805their values. Environment variables conventionally record such things as
1806your user name, your home directory, your terminal type, and your search
1807path for programs to run. Usually you set up environment variables with
1808the shell and they are inherited by all the other programs you run. When
1809debugging, it can be useful to try running your program with a modified
1810environment without having to start @value{GDBN} over again.
1811
1812@table @code
1813@kindex path
1814@item path @var{directory}
1815Add @var{directory} to the front of the @code{PATH} environment variable
17cc6a06
EZ
1816(the search path for executables) that will be passed to your program.
1817The value of @code{PATH} used by @value{GDBN} does not change.
d4f3574e
SS
1818You may specify several directory names, separated by whitespace or by a
1819system-dependent separator character (@samp{:} on Unix, @samp{;} on
1820MS-DOS and MS-Windows). If @var{directory} is already in the path, it
1821is moved to the front, so it is searched sooner.
c906108c
SS
1822
1823You can use the string @samp{$cwd} to refer to whatever is the current
1824working directory at the time @value{GDBN} searches the path. If you
1825use @samp{.} instead, it refers to the directory where you executed the
1826@code{path} command. @value{GDBN} replaces @samp{.} in the
1827@var{directory} argument (with the current path) before adding
1828@var{directory} to the search path.
1829@c 'path' is explicitly nonrepeatable, but RMS points out it is silly to
1830@c document that, since repeating it would be a no-op.
1831
1832@kindex show paths
1833@item show paths
1834Display the list of search paths for executables (the @code{PATH}
1835environment variable).
1836
1837@kindex show environment
1838@item show environment @r{[}@var{varname}@r{]}
1839Print the value of environment variable @var{varname} to be given to
1840your program when it starts. If you do not supply @var{varname},
1841print the names and values of all environment variables to be given to
1842your program. You can abbreviate @code{environment} as @code{env}.
1843
1844@kindex set environment
53a5351d 1845@item set environment @var{varname} @r{[}=@var{value}@r{]}
c906108c
SS
1846Set environment variable @var{varname} to @var{value}. The value
1847changes for your program only, not for @value{GDBN} itself. @var{value} may
1848be any string; the values of environment variables are just strings, and
1849any interpretation is supplied by your program itself. The @var{value}
1850parameter is optional; if it is eliminated, the variable is set to a
1851null value.
1852@c "any string" here does not include leading, trailing
1853@c blanks. Gnu asks: does anyone care?
1854
1855For example, this command:
1856
1857@example
1858set env USER = foo
1859@end example
1860
1861@noindent
d4f3574e 1862tells the debugged program, when subsequently run, that its user is named
c906108c
SS
1863@samp{foo}. (The spaces around @samp{=} are used for clarity here; they
1864are not actually required.)
1865
1866@kindex unset environment
1867@item unset environment @var{varname}
1868Remove variable @var{varname} from the environment to be passed to your
1869program. This is different from @samp{set env @var{varname} =};
1870@code{unset environment} removes the variable from the environment,
1871rather than assigning it an empty value.
1872@end table
1873
d4f3574e
SS
1874@emph{Warning:} On Unix systems, @value{GDBN} runs your program using
1875the shell indicated
c906108c
SS
1876by your @code{SHELL} environment variable if it exists (or
1877@code{/bin/sh} if not). If your @code{SHELL} variable names a shell
1878that runs an initialization file---such as @file{.cshrc} for C-shell, or
1879@file{.bashrc} for BASH---any variables you set in that file affect
1880your program. You may wish to move setting of environment variables to
1881files that are only run when you sign on, such as @file{.login} or
1882@file{.profile}.
1883
6d2ebf8b 1884@node Working Directory
c906108c
SS
1885@section Your program's working directory
1886
1887@cindex working directory (of your program)
1888Each time you start your program with @code{run}, it inherits its
1889working directory from the current working directory of @value{GDBN}.
1890The @value{GDBN} working directory is initially whatever it inherited
1891from its parent process (typically the shell), but you can specify a new
1892working directory in @value{GDBN} with the @code{cd} command.
1893
1894The @value{GDBN} working directory also serves as a default for the commands
1895that specify files for @value{GDBN} to operate on. @xref{Files, ,Commands to
1896specify files}.
1897
1898@table @code
1899@kindex cd
1900@item cd @var{directory}
1901Set the @value{GDBN} working directory to @var{directory}.
1902
1903@kindex pwd
1904@item pwd
1905Print the @value{GDBN} working directory.
1906@end table
1907
6d2ebf8b 1908@node Input/Output
c906108c
SS
1909@section Your program's input and output
1910
1911@cindex redirection
1912@cindex i/o
1913@cindex terminal
1914By default, the program you run under @value{GDBN} does input and output to
5d161b24 1915the same terminal that @value{GDBN} uses. @value{GDBN} switches the terminal
c906108c
SS
1916to its own terminal modes to interact with you, but it records the terminal
1917modes your program was using and switches back to them when you continue
1918running your program.
1919
1920@table @code
1921@kindex info terminal
1922@item info terminal
1923Displays information recorded by @value{GDBN} about the terminal modes your
1924program is using.
1925@end table
1926
1927You can redirect your program's input and/or output using shell
1928redirection with the @code{run} command. For example,
1929
1930@example
1931run > outfile
1932@end example
1933
1934@noindent
1935starts your program, diverting its output to the file @file{outfile}.
1936
1937@kindex tty
1938@cindex controlling terminal
1939Another way to specify where your program should do input and output is
1940with the @code{tty} command. This command accepts a file name as
1941argument, and causes this file to be the default for future @code{run}
1942commands. It also resets the controlling terminal for the child
1943process, for future @code{run} commands. For example,
1944
1945@example
1946tty /dev/ttyb
1947@end example
1948
1949@noindent
1950directs that processes started with subsequent @code{run} commands
1951default to do input and output on the terminal @file{/dev/ttyb} and have
1952that as their controlling terminal.
1953
1954An explicit redirection in @code{run} overrides the @code{tty} command's
1955effect on the input/output device, but not its effect on the controlling
1956terminal.
1957
1958When you use the @code{tty} command or redirect input in the @code{run}
1959command, only the input @emph{for your program} is affected. The input
1960for @value{GDBN} still comes from your terminal.
1961
6d2ebf8b 1962@node Attach
c906108c
SS
1963@section Debugging an already-running process
1964@kindex attach
1965@cindex attach
1966
1967@table @code
1968@item attach @var{process-id}
1969This command attaches to a running process---one that was started
1970outside @value{GDBN}. (@code{info files} shows your active
1971targets.) The command takes as argument a process ID. The usual way to
1972find out the process-id of a Unix process is with the @code{ps} utility,
1973or with the @samp{jobs -l} shell command.
1974
1975@code{attach} does not repeat if you press @key{RET} a second time after
1976executing the command.
1977@end table
1978
1979To use @code{attach}, your program must be running in an environment
1980which supports processes; for example, @code{attach} does not work for
1981programs on bare-board targets that lack an operating system. You must
1982also have permission to send the process a signal.
1983
1984When you use @code{attach}, the debugger finds the program running in
1985the process first by looking in the current working directory, then (if
1986the program is not found) by using the source file search path
1987(@pxref{Source Path, ,Specifying source directories}). You can also use
1988the @code{file} command to load the program. @xref{Files, ,Commands to
1989Specify Files}.
1990
1991The first thing @value{GDBN} does after arranging to debug the specified
1992process is to stop it. You can examine and modify an attached process
53a5351d
JM
1993with all the @value{GDBN} commands that are ordinarily available when
1994you start processes with @code{run}. You can insert breakpoints; you
1995can step and continue; you can modify storage. If you would rather the
1996process continue running, you may use the @code{continue} command after
c906108c
SS
1997attaching @value{GDBN} to the process.
1998
1999@table @code
2000@kindex detach
2001@item detach
2002When you have finished debugging the attached process, you can use the
2003@code{detach} command to release it from @value{GDBN} control. Detaching
2004the process continues its execution. After the @code{detach} command,
2005that process and @value{GDBN} become completely independent once more, and you
2006are ready to @code{attach} another process or start one with @code{run}.
2007@code{detach} does not repeat if you press @key{RET} again after
2008executing the command.
2009@end table
2010
2011If you exit @value{GDBN} or use the @code{run} command while you have an
2012attached process, you kill that process. By default, @value{GDBN} asks
2013for confirmation if you try to do either of these things; you can
2014control whether or not you need to confirm by using the @code{set
2015confirm} command (@pxref{Messages/Warnings, ,Optional warnings and
2016messages}).
2017
6d2ebf8b 2018@node Kill Process
c906108c 2019@section Killing the child process
c906108c
SS
2020
2021@table @code
2022@kindex kill
2023@item kill
2024Kill the child process in which your program is running under @value{GDBN}.
2025@end table
2026
2027This command is useful if you wish to debug a core dump instead of a
2028running process. @value{GDBN} ignores any core dump file while your program
2029is running.
2030
2031On some operating systems, a program cannot be executed outside @value{GDBN}
2032while you have breakpoints set on it inside @value{GDBN}. You can use the
2033@code{kill} command in this situation to permit running your program
2034outside the debugger.
2035
2036The @code{kill} command is also useful if you wish to recompile and
2037relink your program, since on many systems it is impossible to modify an
2038executable file while it is running in a process. In this case, when you
2039next type @code{run}, @value{GDBN} notices that the file has changed, and
2040reads the symbol table again (while trying to preserve your current
2041breakpoint settings).
2042
6d2ebf8b 2043@node Threads
c906108c 2044@section Debugging programs with multiple threads
c906108c
SS
2045
2046@cindex threads of execution
2047@cindex multiple threads
2048@cindex switching threads
2049In some operating systems, such as HP-UX and Solaris, a single program
2050may have more than one @dfn{thread} of execution. The precise semantics
2051of threads differ from one operating system to another, but in general
2052the threads of a single program are akin to multiple processes---except
2053that they share one address space (that is, they can all examine and
2054modify the same variables). On the other hand, each thread has its own
2055registers and execution stack, and perhaps private memory.
2056
2057@value{GDBN} provides these facilities for debugging multi-thread
2058programs:
2059
2060@itemize @bullet
2061@item automatic notification of new threads
2062@item @samp{thread @var{threadno}}, a command to switch among threads
2063@item @samp{info threads}, a command to inquire about existing threads
5d161b24 2064@item @samp{thread apply [@var{threadno}] [@var{all}] @var{args}},
c906108c
SS
2065a command to apply a command to a list of threads
2066@item thread-specific breakpoints
2067@end itemize
2068
c906108c
SS
2069@quotation
2070@emph{Warning:} These facilities are not yet available on every
2071@value{GDBN} configuration where the operating system supports threads.
2072If your @value{GDBN} does not support threads, these commands have no
2073effect. For example, a system without thread support shows no output
2074from @samp{info threads}, and always rejects the @code{thread} command,
2075like this:
2076
2077@smallexample
2078(@value{GDBP}) info threads
2079(@value{GDBP}) thread 1
2080Thread ID 1 not known. Use the "info threads" command to
2081see the IDs of currently known threads.
2082@end smallexample
2083@c FIXME to implementors: how hard would it be to say "sorry, this GDB
2084@c doesn't support threads"?
2085@end quotation
c906108c
SS
2086
2087@cindex focus of debugging
2088@cindex current thread
2089The @value{GDBN} thread debugging facility allows you to observe all
2090threads while your program runs---but whenever @value{GDBN} takes
2091control, one thread in particular is always the focus of debugging.
2092This thread is called the @dfn{current thread}. Debugging commands show
2093program information from the perspective of the current thread.
2094
41afff9a 2095@cindex @code{New} @var{systag} message
c906108c
SS
2096@cindex thread identifier (system)
2097@c FIXME-implementors!! It would be more helpful if the [New...] message
2098@c included GDB's numeric thread handle, so you could just go to that
2099@c thread without first checking `info threads'.
2100Whenever @value{GDBN} detects a new thread in your program, it displays
2101the target system's identification for the thread with a message in the
2102form @samp{[New @var{systag}]}. @var{systag} is a thread identifier
2103whose form varies depending on the particular system. For example, on
2104LynxOS, you might see
2105
2106@example
2107[New process 35 thread 27]
2108@end example
2109
2110@noindent
2111when @value{GDBN} notices a new thread. In contrast, on an SGI system,
2112the @var{systag} is simply something like @samp{process 368}, with no
2113further qualifier.
2114
2115@c FIXME!! (1) Does the [New...] message appear even for the very first
2116@c thread of a program, or does it only appear for the
2117@c second---i.e., when it becomes obvious we have a multithread
2118@c program?
2119@c (2) *Is* there necessarily a first thread always? Or do some
2120@c multithread systems permit starting a program with multiple
5d161b24 2121@c threads ab initio?
c906108c
SS
2122
2123@cindex thread number
2124@cindex thread identifier (GDB)
2125For debugging purposes, @value{GDBN} associates its own thread
2126number---always a single integer---with each thread in your program.
2127
2128@table @code
2129@kindex info threads
2130@item info threads
2131Display a summary of all threads currently in your
2132program. @value{GDBN} displays for each thread (in this order):
2133
2134@enumerate
2135@item the thread number assigned by @value{GDBN}
2136
2137@item the target system's thread identifier (@var{systag})
2138
2139@item the current stack frame summary for that thread
2140@end enumerate
2141
2142@noindent
2143An asterisk @samp{*} to the left of the @value{GDBN} thread number
2144indicates the current thread.
2145
5d161b24 2146For example,
c906108c
SS
2147@end table
2148@c end table here to get a little more width for example
2149
2150@smallexample
2151(@value{GDBP}) info threads
2152 3 process 35 thread 27 0x34e5 in sigpause ()
2153 2 process 35 thread 23 0x34e5 in sigpause ()
2154* 1 process 35 thread 13 main (argc=1, argv=0x7ffffff8)
2155 at threadtest.c:68
2156@end smallexample
53a5351d
JM
2157
2158On HP-UX systems:
c906108c
SS
2159
2160@cindex thread number
2161@cindex thread identifier (GDB)
2162For debugging purposes, @value{GDBN} associates its own thread
2163number---a small integer assigned in thread-creation order---with each
2164thread in your program.
2165
41afff9a
EZ
2166@cindex @code{New} @var{systag} message, on HP-UX
2167@cindex thread identifier (system), on HP-UX
c906108c
SS
2168@c FIXME-implementors!! It would be more helpful if the [New...] message
2169@c included GDB's numeric thread handle, so you could just go to that
2170@c thread without first checking `info threads'.
2171Whenever @value{GDBN} detects a new thread in your program, it displays
2172both @value{GDBN}'s thread number and the target system's identification for the thread with a message in the
2173form @samp{[New @var{systag}]}. @var{systag} is a thread identifier
2174whose form varies depending on the particular system. For example, on
2175HP-UX, you see
2176
2177@example
2178[New thread 2 (system thread 26594)]
2179@end example
2180
2181@noindent
5d161b24 2182when @value{GDBN} notices a new thread.
c906108c
SS
2183
2184@table @code
2185@kindex info threads
2186@item info threads
2187Display a summary of all threads currently in your
2188program. @value{GDBN} displays for each thread (in this order):
2189
2190@enumerate
2191@item the thread number assigned by @value{GDBN}
2192
2193@item the target system's thread identifier (@var{systag})
2194
2195@item the current stack frame summary for that thread
2196@end enumerate
2197
2198@noindent
2199An asterisk @samp{*} to the left of the @value{GDBN} thread number
2200indicates the current thread.
2201
5d161b24 2202For example,
c906108c
SS
2203@end table
2204@c end table here to get a little more width for example
2205
2206@example
2207(@value{GDBP}) info threads
6d2ebf8b
SS
2208 * 3 system thread 26607 worker (wptr=0x7b09c318 "@@") \@*
2209 at quicksort.c:137
2210 2 system thread 26606 0x7b0030d8 in __ksleep () \@*
2211 from /usr/lib/libc.2
2212 1 system thread 27905 0x7b003498 in _brk () \@*
2213 from /usr/lib/libc.2
c906108c 2214@end example
c906108c
SS
2215
2216@table @code
2217@kindex thread @var{threadno}
2218@item thread @var{threadno}
2219Make thread number @var{threadno} the current thread. The command
2220argument @var{threadno} is the internal @value{GDBN} thread number, as
2221shown in the first field of the @samp{info threads} display.
2222@value{GDBN} responds by displaying the system identifier of the thread
2223you selected, and its current stack frame summary:
2224
2225@smallexample
2226@c FIXME!! This example made up; find a @value{GDBN} w/threads and get real one
2227(@value{GDBP}) thread 2
c906108c 2228[Switching to process 35 thread 23]
c906108c
SS
22290x34e5 in sigpause ()
2230@end smallexample
2231
2232@noindent
2233As with the @samp{[New @dots{}]} message, the form of the text after
2234@samp{Switching to} depends on your system's conventions for identifying
5d161b24 2235threads.
c906108c
SS
2236
2237@kindex thread apply
2238@item thread apply [@var{threadno}] [@var{all}] @var{args}
2239The @code{thread apply} command allows you to apply a command to one or
2240more threads. Specify the numbers of the threads that you want affected
2241with the command argument @var{threadno}. @var{threadno} is the internal
2242@value{GDBN} thread number, as shown in the first field of the @samp{info
5d161b24
DB
2243threads} display. To apply a command to all threads, use
2244@code{thread apply all} @var{args}.
c906108c
SS
2245@end table
2246
2247@cindex automatic thread selection
2248@cindex switching threads automatically
2249@cindex threads, automatic switching
2250Whenever @value{GDBN} stops your program, due to a breakpoint or a
2251signal, it automatically selects the thread where that breakpoint or
2252signal happened. @value{GDBN} alerts you to the context switch with a
2253message of the form @samp{[Switching to @var{systag}]} to identify the
2254thread.
2255
2256@xref{Thread Stops,,Stopping and starting multi-thread programs}, for
2257more information about how @value{GDBN} behaves when you stop and start
2258programs with multiple threads.
2259
2260@xref{Set Watchpoints,,Setting watchpoints}, for information about
2261watchpoints in programs with multiple threads.
c906108c 2262
6d2ebf8b 2263@node Processes
c906108c
SS
2264@section Debugging programs with multiple processes
2265
2266@cindex fork, debugging programs which call
2267@cindex multiple processes
2268@cindex processes, multiple
53a5351d
JM
2269On most systems, @value{GDBN} has no special support for debugging
2270programs which create additional processes using the @code{fork}
2271function. When a program forks, @value{GDBN} will continue to debug the
2272parent process and the child process will run unimpeded. If you have
2273set a breakpoint in any code which the child then executes, the child
2274will get a @code{SIGTRAP} signal which (unless it catches the signal)
2275will cause it to terminate.
c906108c
SS
2276
2277However, if you want to debug the child process there is a workaround
2278which isn't too painful. Put a call to @code{sleep} in the code which
2279the child process executes after the fork. It may be useful to sleep
2280only if a certain environment variable is set, or a certain file exists,
2281so that the delay need not occur when you don't want to run @value{GDBN}
2282on the child. While the child is sleeping, use the @code{ps} program to
2283get its process ID. Then tell @value{GDBN} (a new invocation of
2284@value{GDBN} if you are also debugging the parent process) to attach to
d4f3574e 2285the child process (@pxref{Attach}). From that point on you can debug
c906108c 2286the child process just like any other process which you attached to.
c906108c 2287
53a5351d
JM
2288On HP-UX (11.x and later only?), @value{GDBN} provides support for
2289debugging programs that create additional processes using the
2290@code{fork} or @code{vfork} function.
c906108c
SS
2291
2292By default, when a program forks, @value{GDBN} will continue to debug
2293the parent process and the child process will run unimpeded.
2294
2295If you want to follow the child process instead of the parent process,
2296use the command @w{@code{set follow-fork-mode}}.
2297
2298@table @code
2299@kindex set follow-fork-mode
2300@item set follow-fork-mode @var{mode}
2301Set the debugger response to a program call of @code{fork} or
2302@code{vfork}. A call to @code{fork} or @code{vfork} creates a new
2303process. The @var{mode} can be:
2304
2305@table @code
2306@item parent
2307The original process is debugged after a fork. The child process runs
2df3850c 2308unimpeded. This is the default.
c906108c
SS
2309
2310@item child
2311The new process is debugged after a fork. The parent process runs
2312unimpeded.
2313
2314@item ask
2315The debugger will ask for one of the above choices.
2316@end table
2317
2318@item show follow-fork-mode
2df3850c 2319Display the current debugger response to a @code{fork} or @code{vfork} call.
c906108c
SS
2320@end table
2321
2322If you ask to debug a child process and a @code{vfork} is followed by an
2323@code{exec}, @value{GDBN} executes the new target up to the first
2324breakpoint in the new target. If you have a breakpoint set on
2325@code{main} in your original program, the breakpoint will also be set on
2326the child process's @code{main}.
2327
2328When a child process is spawned by @code{vfork}, you cannot debug the
2329child or parent until an @code{exec} call completes.
2330
2331If you issue a @code{run} command to @value{GDBN} after an @code{exec}
2332call executes, the new target restarts. To restart the parent process,
2333use the @code{file} command with the parent executable name as its
2334argument.
2335
2336You can use the @code{catch} command to make @value{GDBN} stop whenever
2337a @code{fork}, @code{vfork}, or @code{exec} call is made. @xref{Set
2338Catchpoints, ,Setting catchpoints}.
c906108c 2339
6d2ebf8b 2340@node Stopping
c906108c
SS
2341@chapter Stopping and Continuing
2342
2343The principal purposes of using a debugger are so that you can stop your
2344program before it terminates; or so that, if your program runs into
2345trouble, you can investigate and find out why.
2346
7a292a7a
SS
2347Inside @value{GDBN}, your program may stop for any of several reasons,
2348such as a signal, a breakpoint, or reaching a new line after a
2349@value{GDBN} command such as @code{step}. You may then examine and
2350change variables, set new breakpoints or remove old ones, and then
2351continue execution. Usually, the messages shown by @value{GDBN} provide
2352ample explanation of the status of your program---but you can also
2353explicitly request this information at any time.
c906108c
SS
2354
2355@table @code
2356@kindex info program
2357@item info program
2358Display information about the status of your program: whether it is
7a292a7a 2359running or not, what process it is, and why it stopped.
c906108c
SS
2360@end table
2361
2362@menu
2363* Breakpoints:: Breakpoints, watchpoints, and catchpoints
2364* Continuing and Stepping:: Resuming execution
c906108c 2365* Signals:: Signals
c906108c 2366* Thread Stops:: Stopping and starting multi-thread programs
c906108c
SS
2367@end menu
2368
6d2ebf8b 2369@node Breakpoints
c906108c
SS
2370@section Breakpoints, watchpoints, and catchpoints
2371
2372@cindex breakpoints
2373A @dfn{breakpoint} makes your program stop whenever a certain point in
2374the program is reached. For each breakpoint, you can add conditions to
2375control in finer detail whether your program stops. You can set
2376breakpoints with the @code{break} command and its variants (@pxref{Set
2377Breaks, ,Setting breakpoints}), to specify the place where your program
2378should stop by line number, function name or exact address in the
2379program.
2380
2381In HP-UX, SunOS 4.x, SVR4, and Alpha OSF/1 configurations, you can set
2382breakpoints in shared libraries before the executable is run. There is
2383a minor limitation on HP-UX systems: you must wait until the executable
2384is run in order to set breakpoints in shared library routines that are
2385not called directly by the program (for example, routines that are
2386arguments in a @code{pthread_create} call).
2387
2388@cindex watchpoints
2389@cindex memory tracing
2390@cindex breakpoint on memory address
2391@cindex breakpoint on variable modification
2392A @dfn{watchpoint} is a special breakpoint that stops your program
2393when the value of an expression changes. You must use a different
2394command to set watchpoints (@pxref{Set Watchpoints, ,Setting
2395watchpoints}), but aside from that, you can manage a watchpoint like
2396any other breakpoint: you enable, disable, and delete both breakpoints
2397and watchpoints using the same commands.
2398
2399You can arrange to have values from your program displayed automatically
2400whenever @value{GDBN} stops at a breakpoint. @xref{Auto Display,,
2401Automatic display}.
2402
2403@cindex catchpoints
2404@cindex breakpoint on events
2405A @dfn{catchpoint} is another special breakpoint that stops your program
b37052ae 2406when a certain kind of event occurs, such as the throwing of a C@t{++}
c906108c
SS
2407exception or the loading of a library. As with watchpoints, you use a
2408different command to set a catchpoint (@pxref{Set Catchpoints, ,Setting
2409catchpoints}), but aside from that, you can manage a catchpoint like any
2410other breakpoint. (To stop when your program receives a signal, use the
d4f3574e 2411@code{handle} command; see @ref{Signals, ,Signals}.)
c906108c
SS
2412
2413@cindex breakpoint numbers
2414@cindex numbers for breakpoints
2415@value{GDBN} assigns a number to each breakpoint, watchpoint, or
2416catchpoint when you create it; these numbers are successive integers
2417starting with one. In many of the commands for controlling various
2418features of breakpoints you use the breakpoint number to say which
2419breakpoint you want to change. Each breakpoint may be @dfn{enabled} or
2420@dfn{disabled}; if disabled, it has no effect on your program until you
2421enable it again.
2422
c5394b80
JM
2423@cindex breakpoint ranges
2424@cindex ranges of breakpoints
2425Some @value{GDBN} commands accept a range of breakpoints on which to
2426operate. A breakpoint range is either a single breakpoint number, like
2427@samp{5}, or two such numbers, in increasing order, separated by a
2428hyphen, like @samp{5-7}. When a breakpoint range is given to a command,
2429all breakpoint in that range are operated on.
2430
c906108c
SS
2431@menu
2432* Set Breaks:: Setting breakpoints
2433* Set Watchpoints:: Setting watchpoints
2434* Set Catchpoints:: Setting catchpoints
2435* Delete Breaks:: Deleting breakpoints
2436* Disabling:: Disabling breakpoints
2437* Conditions:: Break conditions
2438* Break Commands:: Breakpoint command lists
c906108c 2439* Breakpoint Menus:: Breakpoint menus
d4f3574e 2440* Error in Breakpoints:: ``Cannot insert breakpoints''
c906108c
SS
2441@end menu
2442
6d2ebf8b 2443@node Set Breaks
c906108c
SS
2444@subsection Setting breakpoints
2445
5d161b24 2446@c FIXME LMB what does GDB do if no code on line of breakpt?
c906108c
SS
2447@c consider in particular declaration with/without initialization.
2448@c
2449@c FIXME 2 is there stuff on this already? break at fun start, already init?
2450
2451@kindex break
41afff9a
EZ
2452@kindex b @r{(@code{break})}
2453@vindex $bpnum@r{, convenience variable}
c906108c
SS
2454@cindex latest breakpoint
2455Breakpoints are set with the @code{break} command (abbreviated
5d161b24 2456@code{b}). The debugger convenience variable @samp{$bpnum} records the
f3b28801 2457number of the breakpoint you've set most recently; see @ref{Convenience
c906108c
SS
2458Vars,, Convenience variables}, for a discussion of what you can do with
2459convenience variables.
2460
2461You have several ways to say where the breakpoint should go.
2462
2463@table @code
2464@item break @var{function}
5d161b24 2465Set a breakpoint at entry to function @var{function}.
c906108c 2466When using source languages that permit overloading of symbols, such as
b37052ae 2467C@t{++}, @var{function} may refer to more than one possible place to break.
c906108c 2468@xref{Breakpoint Menus,,Breakpoint menus}, for a discussion of that situation.
c906108c
SS
2469
2470@item break +@var{offset}
2471@itemx break -@var{offset}
2472Set a breakpoint some number of lines forward or back from the position
d4f3574e 2473at which execution stopped in the currently selected @dfn{stack frame}.
2df3850c 2474(@xref{Frames, ,Frames}, for a description of stack frames.)
c906108c
SS
2475
2476@item break @var{linenum}
2477Set a breakpoint at line @var{linenum} in the current source file.
d4f3574e
SS
2478The current source file is the last file whose source text was printed.
2479The breakpoint will stop your program just before it executes any of the
c906108c
SS
2480code on that line.
2481
2482@item break @var{filename}:@var{linenum}
2483Set a breakpoint at line @var{linenum} in source file @var{filename}.
2484
2485@item break @var{filename}:@var{function}
2486Set a breakpoint at entry to function @var{function} found in file
2487@var{filename}. Specifying a file name as well as a function name is
2488superfluous except when multiple files contain similarly named
2489functions.
2490
2491@item break *@var{address}
2492Set a breakpoint at address @var{address}. You can use this to set
2493breakpoints in parts of your program which do not have debugging
2494information or source files.
2495
2496@item break
2497When called without any arguments, @code{break} sets a breakpoint at
2498the next instruction to be executed in the selected stack frame
2499(@pxref{Stack, ,Examining the Stack}). In any selected frame but the
2500innermost, this makes your program stop as soon as control
2501returns to that frame. This is similar to the effect of a
2502@code{finish} command in the frame inside the selected frame---except
2503that @code{finish} does not leave an active breakpoint. If you use
2504@code{break} without an argument in the innermost frame, @value{GDBN} stops
2505the next time it reaches the current location; this may be useful
2506inside loops.
2507
2508@value{GDBN} normally ignores breakpoints when it resumes execution, until at
2509least one instruction has been executed. If it did not do this, you
2510would be unable to proceed past a breakpoint without first disabling the
2511breakpoint. This rule applies whether or not the breakpoint already
2512existed when your program stopped.
2513
2514@item break @dots{} if @var{cond}
2515Set a breakpoint with condition @var{cond}; evaluate the expression
2516@var{cond} each time the breakpoint is reached, and stop only if the
2517value is nonzero---that is, if @var{cond} evaluates as true.
2518@samp{@dots{}} stands for one of the possible arguments described
2519above (or no argument) specifying where to break. @xref{Conditions,
2520,Break conditions}, for more information on breakpoint conditions.
2521
2522@kindex tbreak
2523@item tbreak @var{args}
2524Set a breakpoint enabled only for one stop. @var{args} are the
2525same as for the @code{break} command, and the breakpoint is set in the same
2526way, but the breakpoint is automatically deleted after the first time your
2527program stops there. @xref{Disabling, ,Disabling breakpoints}.
2528
c906108c
SS
2529@kindex hbreak
2530@item hbreak @var{args}
d4f3574e
SS
2531Set a hardware-assisted breakpoint. @var{args} are the same as for the
2532@code{break} command and the breakpoint is set in the same way, but the
c906108c
SS
2533breakpoint requires hardware support and some target hardware may not
2534have this support. The main purpose of this is EPROM/ROM code
d4f3574e
SS
2535debugging, so you can set a breakpoint at an instruction without
2536changing the instruction. This can be used with the new trap-generation
2537provided by SPARClite DSU and some x86-based targets. These targets
2538will generate traps when a program accesses some data or instruction
2539address that is assigned to the debug registers. However the hardware
2540breakpoint registers can take a limited number of breakpoints. For
2541example, on the DSU, only two data breakpoints can be set at a time, and
2542@value{GDBN} will reject this command if more than two are used. Delete
2543or disable unused hardware breakpoints before setting new ones
2544(@pxref{Disabling, ,Disabling}). @xref{Conditions, ,Break conditions}.
c906108c
SS
2545
2546@kindex thbreak
2547@item thbreak @var{args}
2548Set a hardware-assisted breakpoint enabled only for one stop. @var{args}
2549are the same as for the @code{hbreak} command and the breakpoint is set in
5d161b24 2550the same way. However, like the @code{tbreak} command,
c906108c
SS
2551the breakpoint is automatically deleted after the
2552first time your program stops there. Also, like the @code{hbreak}
5d161b24
DB
2553command, the breakpoint requires hardware support and some target hardware
2554may not have this support. @xref{Disabling, ,Disabling breakpoints}.
d4f3574e 2555See also @ref{Conditions, ,Break conditions}.
c906108c
SS
2556
2557@kindex rbreak
2558@cindex regular expression
2559@item rbreak @var{regex}
c906108c 2560Set breakpoints on all functions matching the regular expression
11cf8741
JM
2561@var{regex}. This command sets an unconditional breakpoint on all
2562matches, printing a list of all breakpoints it set. Once these
2563breakpoints are set, they are treated just like the breakpoints set with
2564the @code{break} command. You can delete them, disable them, or make
2565them conditional the same way as any other breakpoint.
2566
2567The syntax of the regular expression is the standard one used with tools
2568like @file{grep}. Note that this is different from the syntax used by
2569shells, so for instance @code{foo*} matches all functions that include
2570an @code{fo} followed by zero or more @code{o}s. There is an implicit
2571@code{.*} leading and trailing the regular expression you supply, so to
2572match only functions that begin with @code{foo}, use @code{^foo}.
c906108c 2573
b37052ae 2574When debugging C@t{++} programs, @code{rbreak} is useful for setting
c906108c
SS
2575breakpoints on overloaded functions that are not members of any special
2576classes.
c906108c
SS
2577
2578@kindex info breakpoints
2579@cindex @code{$_} and @code{info breakpoints}
2580@item info breakpoints @r{[}@var{n}@r{]}
2581@itemx info break @r{[}@var{n}@r{]}
2582@itemx info watchpoints @r{[}@var{n}@r{]}
2583Print a table of all breakpoints, watchpoints, and catchpoints set and
2584not deleted, with the following columns for each breakpoint:
2585
2586@table @emph
2587@item Breakpoint Numbers
2588@item Type
2589Breakpoint, watchpoint, or catchpoint.
2590@item Disposition
2591Whether the breakpoint is marked to be disabled or deleted when hit.
2592@item Enabled or Disabled
2593Enabled breakpoints are marked with @samp{y}. @samp{n} marks breakpoints
2594that are not enabled.
2595@item Address
2df3850c 2596Where the breakpoint is in your program, as a memory address.
c906108c
SS
2597@item What
2598Where the breakpoint is in the source for your program, as a file and
2599line number.
2600@end table
2601
2602@noindent
2603If a breakpoint is conditional, @code{info break} shows the condition on
2604the line following the affected breakpoint; breakpoint commands, if any,
2605are listed after that.
2606
2607@noindent
2608@code{info break} with a breakpoint
2609number @var{n} as argument lists only that breakpoint. The
2610convenience variable @code{$_} and the default examining-address for
2611the @code{x} command are set to the address of the last breakpoint
5d161b24 2612listed (@pxref{Memory, ,Examining memory}).
c906108c
SS
2613
2614@noindent
2615@code{info break} displays a count of the number of times the breakpoint
2616has been hit. This is especially useful in conjunction with the
2617@code{ignore} command. You can ignore a large number of breakpoint
2618hits, look at the breakpoint info to see how many times the breakpoint
2619was hit, and then run again, ignoring one less than that number. This
2620will get you quickly to the last hit of that breakpoint.
2621@end table
2622
2623@value{GDBN} allows you to set any number of breakpoints at the same place in
2624your program. There is nothing silly or meaningless about this. When
2625the breakpoints are conditional, this is even useful
2626(@pxref{Conditions, ,Break conditions}).
2627
2628@cindex negative breakpoint numbers
2629@cindex internal @value{GDBN} breakpoints
2630@value{GDBN} itself sometimes sets breakpoints in your program for special
2631purposes, such as proper handling of @code{longjmp} (in C programs).
2632These internal breakpoints are assigned negative numbers, starting with
2633@code{-1}; @samp{info breakpoints} does not display them.
2634
2635You can see these breakpoints with the @value{GDBN} maintenance command
2636@samp{maint info breakpoints}.
2637
2638@table @code
2639@kindex maint info breakpoints
2640@item maint info breakpoints
2641Using the same format as @samp{info breakpoints}, display both the
2642breakpoints you've set explicitly, and those @value{GDBN} is using for
2643internal purposes. Internal breakpoints are shown with negative
2644breakpoint numbers. The type column identifies what kind of breakpoint
2645is shown:
2646
2647@table @code
2648@item breakpoint
2649Normal, explicitly set breakpoint.
2650
2651@item watchpoint
2652Normal, explicitly set watchpoint.
2653
2654@item longjmp
2655Internal breakpoint, used to handle correctly stepping through
2656@code{longjmp} calls.
2657
2658@item longjmp resume
2659Internal breakpoint at the target of a @code{longjmp}.
2660
2661@item until
2662Temporary internal breakpoint used by the @value{GDBN} @code{until} command.
2663
2664@item finish
2665Temporary internal breakpoint used by the @value{GDBN} @code{finish} command.
2666
c906108c
SS
2667@item shlib events
2668Shared library events.
53a5351d 2669
c906108c 2670@end table
53a5351d 2671
c906108c
SS
2672@end table
2673
2674
6d2ebf8b 2675@node Set Watchpoints
c906108c
SS
2676@subsection Setting watchpoints
2677
2678@cindex setting watchpoints
2679@cindex software watchpoints
2680@cindex hardware watchpoints
2681You can use a watchpoint to stop execution whenever the value of an
2682expression changes, without having to predict a particular place where
2683this may happen.
2684
2685Depending on your system, watchpoints may be implemented in software or
2df3850c 2686hardware. @value{GDBN} does software watchpointing by single-stepping your
c906108c
SS
2687program and testing the variable's value each time, which is hundreds of
2688times slower than normal execution. (But this may still be worth it, to
2689catch errors where you have no clue what part of your program is the
2690culprit.)
2691
d4f3574e 2692On some systems, such as HP-UX, Linux and some other x86-based targets,
2df3850c 2693@value{GDBN} includes support for
c906108c
SS
2694hardware watchpoints, which do not slow down the running of your
2695program.
2696
2697@table @code
2698@kindex watch
2699@item watch @var{expr}
2700Set a watchpoint for an expression. @value{GDBN} will break when @var{expr}
2701is written into by the program and its value changes.
2702
2703@kindex rwatch
2704@item rwatch @var{expr}
2705Set a watchpoint that will break when watch @var{expr} is read by the program.
c906108c
SS
2706
2707@kindex awatch
2708@item awatch @var{expr}
2df3850c 2709Set a watchpoint that will break when @var{expr} is either read or written into
7be570e7 2710by the program.
c906108c
SS
2711
2712@kindex info watchpoints
2713@item info watchpoints
2714This command prints a list of watchpoints, breakpoints, and catchpoints;
2715it is the same as @code{info break}.
2716@end table
2717
2718@value{GDBN} sets a @dfn{hardware watchpoint} if possible. Hardware
2719watchpoints execute very quickly, and the debugger reports a change in
2720value at the exact instruction where the change occurs. If @value{GDBN}
2721cannot set a hardware watchpoint, it sets a software watchpoint, which
2722executes more slowly and reports the change in value at the next
2723statement, not the instruction, after the change occurs.
2724
2725When you issue the @code{watch} command, @value{GDBN} reports
2726
2727@example
2728Hardware watchpoint @var{num}: @var{expr}
2729@end example
2730
2731@noindent
2732if it was able to set a hardware watchpoint.
2733
7be570e7
JM
2734Currently, the @code{awatch} and @code{rwatch} commands can only set
2735hardware watchpoints, because accesses to data that don't change the
2736value of the watched expression cannot be detected without examining
2737every instruction as it is being executed, and @value{GDBN} does not do
2738that currently. If @value{GDBN} finds that it is unable to set a
2739hardware breakpoint with the @code{awatch} or @code{rwatch} command, it
2740will print a message like this:
2741
2742@smallexample
2743Expression cannot be implemented with read/access watchpoint.
2744@end smallexample
2745
2746Sometimes, @value{GDBN} cannot set a hardware watchpoint because the
2747data type of the watched expression is wider than what a hardware
2748watchpoint on the target machine can handle. For example, some systems
2749can only watch regions that are up to 4 bytes wide; on such systems you
2750cannot set hardware watchpoints for an expression that yields a
2751double-precision floating-point number (which is typically 8 bytes
2752wide). As a work-around, it might be possible to break the large region
2753into a series of smaller ones and watch them with separate watchpoints.
2754
2755If you set too many hardware watchpoints, @value{GDBN} might be unable
2756to insert all of them when you resume the execution of your program.
2757Since the precise number of active watchpoints is unknown until such
2758time as the program is about to be resumed, @value{GDBN} might not be
2759able to warn you about this when you set the watchpoints, and the
2760warning will be printed only when the program is resumed:
2761
2762@smallexample
2763Hardware watchpoint @var{num}: Could not insert watchpoint
2764@end smallexample
2765
2766@noindent
2767If this happens, delete or disable some of the watchpoints.
2768
2769The SPARClite DSU will generate traps when a program accesses some data
2770or instruction address that is assigned to the debug registers. For the
2771data addresses, DSU facilitates the @code{watch} command. However the
2772hardware breakpoint registers can only take two data watchpoints, and
2773both watchpoints must be the same kind. For example, you can set two
2774watchpoints with @code{watch} commands, two with @code{rwatch} commands,
2775@strong{or} two with @code{awatch} commands, but you cannot set one
2776watchpoint with one command and the other with a different command.
c906108c
SS
2777@value{GDBN} will reject the command if you try to mix watchpoints.
2778Delete or disable unused watchpoint commands before setting new ones.
2779
2780If you call a function interactively using @code{print} or @code{call},
2df3850c 2781any watchpoints you have set will be inactive until @value{GDBN} reaches another
c906108c
SS
2782kind of breakpoint or the call completes.
2783
7be570e7
JM
2784@value{GDBN} automatically deletes watchpoints that watch local
2785(automatic) variables, or expressions that involve such variables, when
2786they go out of scope, that is, when the execution leaves the block in
2787which these variables were defined. In particular, when the program
2788being debugged terminates, @emph{all} local variables go out of scope,
2789and so only watchpoints that watch global variables remain set. If you
2790rerun the program, you will need to set all such watchpoints again. One
2791way of doing that would be to set a code breakpoint at the entry to the
2792@code{main} function and when it breaks, set all the watchpoints.
2793
c906108c
SS
2794@quotation
2795@cindex watchpoints and threads
2796@cindex threads and watchpoints
c906108c
SS
2797@emph{Warning:} In multi-thread programs, watchpoints have only limited
2798usefulness. With the current watchpoint implementation, @value{GDBN}
2799can only watch the value of an expression @emph{in a single thread}. If
2800you are confident that the expression can only change due to the current
2801thread's activity (and if you are also confident that no other thread
2802can become current), then you can use watchpoints as usual. However,
2803@value{GDBN} may not notice when a non-current thread's activity changes
2804the expression.
53a5351d 2805
d4f3574e 2806@c FIXME: this is almost identical to the previous paragraph.
53a5351d
JM
2807@emph{HP-UX Warning:} In multi-thread programs, software watchpoints
2808have only limited usefulness. If @value{GDBN} creates a software
2809watchpoint, it can only watch the value of an expression @emph{in a
2810single thread}. If you are confident that the expression can only
2811change due to the current thread's activity (and if you are also
2812confident that no other thread can become current), then you can use
2813software watchpoints as usual. However, @value{GDBN} may not notice
2814when a non-current thread's activity changes the expression. (Hardware
2815watchpoints, in contrast, watch an expression in all threads.)
c906108c 2816@end quotation
c906108c 2817
6d2ebf8b 2818@node Set Catchpoints
c906108c 2819@subsection Setting catchpoints
d4f3574e 2820@cindex catchpoints, setting
c906108c
SS
2821@cindex exception handlers
2822@cindex event handling
2823
2824You can use @dfn{catchpoints} to cause the debugger to stop for certain
b37052ae 2825kinds of program events, such as C@t{++} exceptions or the loading of a
c906108c
SS
2826shared library. Use the @code{catch} command to set a catchpoint.
2827
2828@table @code
2829@kindex catch
2830@item catch @var{event}
2831Stop when @var{event} occurs. @var{event} can be any of the following:
2832@table @code
2833@item throw
2834@kindex catch throw
b37052ae 2835The throwing of a C@t{++} exception.
c906108c
SS
2836
2837@item catch
2838@kindex catch catch
b37052ae 2839The catching of a C@t{++} exception.
c906108c
SS
2840
2841@item exec
2842@kindex catch exec
2843A call to @code{exec}. This is currently only available for HP-UX.
2844
2845@item fork
2846@kindex catch fork
2847A call to @code{fork}. This is currently only available for HP-UX.
2848
2849@item vfork
2850@kindex catch vfork
2851A call to @code{vfork}. This is currently only available for HP-UX.
2852
2853@item load
2854@itemx load @var{libname}
2855@kindex catch load
2856The dynamic loading of any shared library, or the loading of the library
2857@var{libname}. This is currently only available for HP-UX.
2858
2859@item unload
2860@itemx unload @var{libname}
2861@kindex catch unload
2862The unloading of any dynamically loaded shared library, or the unloading
2863of the library @var{libname}. This is currently only available for HP-UX.
2864@end table
2865
2866@item tcatch @var{event}
2867Set a catchpoint that is enabled only for one stop. The catchpoint is
2868automatically deleted after the first time the event is caught.
2869
2870@end table
2871
2872Use the @code{info break} command to list the current catchpoints.
2873
b37052ae 2874There are currently some limitations to C@t{++} exception handling
c906108c
SS
2875(@code{catch throw} and @code{catch catch}) in @value{GDBN}:
2876
2877@itemize @bullet
2878@item
2879If you call a function interactively, @value{GDBN} normally returns
2880control to you when the function has finished executing. If the call
2881raises an exception, however, the call may bypass the mechanism that
2882returns control to you and cause your program either to abort or to
2883simply continue running until it hits a breakpoint, catches a signal
2884that @value{GDBN} is listening for, or exits. This is the case even if
2885you set a catchpoint for the exception; catchpoints on exceptions are
2886disabled within interactive calls.
2887
2888@item
2889You cannot raise an exception interactively.
2890
2891@item
2892You cannot install an exception handler interactively.
2893@end itemize
2894
2895@cindex raise exceptions
2896Sometimes @code{catch} is not the best way to debug exception handling:
2897if you need to know exactly where an exception is raised, it is better to
2898stop @emph{before} the exception handler is called, since that way you
2899can see the stack before any unwinding takes place. If you set a
2900breakpoint in an exception handler instead, it may not be easy to find
2901out where the exception was raised.
2902
2903To stop just before an exception handler is called, you need some
b37052ae 2904knowledge of the implementation. In the case of @sc{gnu} C@t{++}, exceptions are
c906108c
SS
2905raised by calling a library function named @code{__raise_exception}
2906which has the following ANSI C interface:
2907
2908@example
2909 /* @var{addr} is where the exception identifier is stored.
d4f3574e
SS
2910 @var{id} is the exception identifier. */
2911 void __raise_exception (void **addr, void *id);
c906108c
SS
2912@end example
2913
2914@noindent
2915To make the debugger catch all exceptions before any stack
2916unwinding takes place, set a breakpoint on @code{__raise_exception}
2917(@pxref{Breakpoints, ,Breakpoints; watchpoints; and exceptions}).
2918
2919With a conditional breakpoint (@pxref{Conditions, ,Break conditions})
2920that depends on the value of @var{id}, you can stop your program when
2921a specific exception is raised. You can use multiple conditional
2922breakpoints to stop your program when any of a number of exceptions are
2923raised.
2924
2925
6d2ebf8b 2926@node Delete Breaks
c906108c
SS
2927@subsection Deleting breakpoints
2928
2929@cindex clearing breakpoints, watchpoints, catchpoints
2930@cindex deleting breakpoints, watchpoints, catchpoints
2931It is often necessary to eliminate a breakpoint, watchpoint, or
2932catchpoint once it has done its job and you no longer want your program
2933to stop there. This is called @dfn{deleting} the breakpoint. A
2934breakpoint that has been deleted no longer exists; it is forgotten.
2935
2936With the @code{clear} command you can delete breakpoints according to
2937where they are in your program. With the @code{delete} command you can
2938delete individual breakpoints, watchpoints, or catchpoints by specifying
2939their breakpoint numbers.
2940
2941It is not necessary to delete a breakpoint to proceed past it. @value{GDBN}
2942automatically ignores breakpoints on the first instruction to be executed
2943when you continue execution without changing the execution address.
2944
2945@table @code
2946@kindex clear
2947@item clear
2948Delete any breakpoints at the next instruction to be executed in the
2949selected stack frame (@pxref{Selection, ,Selecting a frame}). When
2950the innermost frame is selected, this is a good way to delete a
2951breakpoint where your program just stopped.
2952
2953@item clear @var{function}
2954@itemx clear @var{filename}:@var{function}
2955Delete any breakpoints set at entry to the function @var{function}.
2956
2957@item clear @var{linenum}
2958@itemx clear @var{filename}:@var{linenum}
2959Delete any breakpoints set at or within the code of the specified line.
2960
2961@cindex delete breakpoints
2962@kindex delete
41afff9a 2963@kindex d @r{(@code{delete})}
c5394b80
JM
2964@item delete @r{[}breakpoints@r{]} @r{[}@var{range}@dots{}@r{]}
2965Delete the breakpoints, watchpoints, or catchpoints of the breakpoint
2966ranges specified as arguments. If no argument is specified, delete all
c906108c
SS
2967breakpoints (@value{GDBN} asks confirmation, unless you have @code{set
2968confirm off}). You can abbreviate this command as @code{d}.
2969@end table
2970
6d2ebf8b 2971@node Disabling
c906108c
SS
2972@subsection Disabling breakpoints
2973
2974@kindex disable breakpoints
2975@kindex enable breakpoints
2976Rather than deleting a breakpoint, watchpoint, or catchpoint, you might
2977prefer to @dfn{disable} it. This makes the breakpoint inoperative as if
2978it had been deleted, but remembers the information on the breakpoint so
2979that you can @dfn{enable} it again later.
2980
2981You disable and enable breakpoints, watchpoints, and catchpoints with
2982the @code{enable} and @code{disable} commands, optionally specifying one
2983or more breakpoint numbers as arguments. Use @code{info break} or
2984@code{info watch} to print a list of breakpoints, watchpoints, and
2985catchpoints if you do not know which numbers to use.
2986
2987A breakpoint, watchpoint, or catchpoint can have any of four different
2988states of enablement:
2989
2990@itemize @bullet
2991@item
2992Enabled. The breakpoint stops your program. A breakpoint set
2993with the @code{break} command starts out in this state.
2994@item
2995Disabled. The breakpoint has no effect on your program.
2996@item
2997Enabled once. The breakpoint stops your program, but then becomes
d4f3574e 2998disabled.
c906108c
SS
2999@item
3000Enabled for deletion. The breakpoint stops your program, but
d4f3574e
SS
3001immediately after it does so it is deleted permanently. A breakpoint
3002set with the @code{tbreak} command starts out in this state.
c906108c
SS
3003@end itemize
3004
3005You can use the following commands to enable or disable breakpoints,
3006watchpoints, and catchpoints:
3007
3008@table @code
3009@kindex disable breakpoints
3010@kindex disable
41afff9a 3011@kindex dis @r{(@code{disable})}
c5394b80 3012@item disable @r{[}breakpoints@r{]} @r{[}@var{range}@dots{}@r{]}
c906108c
SS
3013Disable the specified breakpoints---or all breakpoints, if none are
3014listed. A disabled breakpoint has no effect but is not forgotten. All
3015options such as ignore-counts, conditions and commands are remembered in
3016case the breakpoint is enabled again later. You may abbreviate
3017@code{disable} as @code{dis}.
3018
3019@kindex enable breakpoints
3020@kindex enable
c5394b80 3021@item enable @r{[}breakpoints@r{]} @r{[}@var{range}@dots{}@r{]}
c906108c
SS
3022Enable the specified breakpoints (or all defined breakpoints). They
3023become effective once again in stopping your program.
3024
c5394b80 3025@item enable @r{[}breakpoints@r{]} once @var{range}@dots{}
c906108c
SS
3026Enable the specified breakpoints temporarily. @value{GDBN} disables any
3027of these breakpoints immediately after stopping your program.
3028
c5394b80 3029@item enable @r{[}breakpoints@r{]} delete @var{range}@dots{}
c906108c
SS
3030Enable the specified breakpoints to work once, then die. @value{GDBN}
3031deletes any of these breakpoints as soon as your program stops there.
3032@end table
3033
d4f3574e
SS
3034@c FIXME: I think the following ``Except for [...] @code{tbreak}'' is
3035@c confusing: tbreak is also initially enabled.
c906108c
SS
3036Except for a breakpoint set with @code{tbreak} (@pxref{Set Breaks,
3037,Setting breakpoints}), breakpoints that you set are initially enabled;
3038subsequently, they become disabled or enabled only when you use one of
3039the commands above. (The command @code{until} can set and delete a
3040breakpoint of its own, but it does not change the state of your other
3041breakpoints; see @ref{Continuing and Stepping, ,Continuing and
3042stepping}.)
3043
6d2ebf8b 3044@node Conditions
c906108c
SS
3045@subsection Break conditions
3046@cindex conditional breakpoints
3047@cindex breakpoint conditions
3048
3049@c FIXME what is scope of break condition expr? Context where wanted?
5d161b24 3050@c in particular for a watchpoint?
c906108c
SS
3051The simplest sort of breakpoint breaks every time your program reaches a
3052specified place. You can also specify a @dfn{condition} for a
3053breakpoint. A condition is just a Boolean expression in your
3054programming language (@pxref{Expressions, ,Expressions}). A breakpoint with
3055a condition evaluates the expression each time your program reaches it,
3056and your program stops only if the condition is @emph{true}.
3057
3058This is the converse of using assertions for program validation; in that
3059situation, you want to stop when the assertion is violated---that is,
3060when the condition is false. In C, if you want to test an assertion expressed
3061by the condition @var{assert}, you should set the condition
3062@samp{! @var{assert}} on the appropriate breakpoint.
3063
3064Conditions are also accepted for watchpoints; you may not need them,
3065since a watchpoint is inspecting the value of an expression anyhow---but
3066it might be simpler, say, to just set a watchpoint on a variable name,
3067and specify a condition that tests whether the new value is an interesting
3068one.
3069
3070Break conditions can have side effects, and may even call functions in
3071your program. This can be useful, for example, to activate functions
3072that log program progress, or to use your own print functions to
3073format special data structures. The effects are completely predictable
3074unless there is another enabled breakpoint at the same address. (In
3075that case, @value{GDBN} might see the other breakpoint first and stop your
3076program without checking the condition of this one.) Note that
d4f3574e
SS
3077breakpoint commands are usually more convenient and flexible than break
3078conditions for the
c906108c
SS
3079purpose of performing side effects when a breakpoint is reached
3080(@pxref{Break Commands, ,Breakpoint command lists}).
3081
3082Break conditions can be specified when a breakpoint is set, by using
3083@samp{if} in the arguments to the @code{break} command. @xref{Set
3084Breaks, ,Setting breakpoints}. They can also be changed at any time
3085with the @code{condition} command.
53a5351d 3086
c906108c
SS
3087You can also use the @code{if} keyword with the @code{watch} command.
3088The @code{catch} command does not recognize the @code{if} keyword;
3089@code{condition} is the only way to impose a further condition on a
3090catchpoint.
c906108c
SS
3091
3092@table @code
3093@kindex condition
3094@item condition @var{bnum} @var{expression}
3095Specify @var{expression} as the break condition for breakpoint,
3096watchpoint, or catchpoint number @var{bnum}. After you set a condition,
3097breakpoint @var{bnum} stops your program only if the value of
3098@var{expression} is true (nonzero, in C). When you use
3099@code{condition}, @value{GDBN} checks @var{expression} immediately for
3100syntactic correctness, and to determine whether symbols in it have
d4f3574e
SS
3101referents in the context of your breakpoint. If @var{expression} uses
3102symbols not referenced in the context of the breakpoint, @value{GDBN}
3103prints an error message:
3104
3105@example
3106No symbol "foo" in current context.
3107@end example
3108
3109@noindent
c906108c
SS
3110@value{GDBN} does
3111not actually evaluate @var{expression} at the time the @code{condition}
d4f3574e
SS
3112command (or a command that sets a breakpoint with a condition, like
3113@code{break if @dots{}}) is given, however. @xref{Expressions, ,Expressions}.
c906108c
SS
3114
3115@item condition @var{bnum}
3116Remove the condition from breakpoint number @var{bnum}. It becomes
3117an ordinary unconditional breakpoint.
3118@end table
3119
3120@cindex ignore count (of breakpoint)
3121A special case of a breakpoint condition is to stop only when the
3122breakpoint has been reached a certain number of times. This is so
3123useful that there is a special way to do it, using the @dfn{ignore
3124count} of the breakpoint. Every breakpoint has an ignore count, which
3125is an integer. Most of the time, the ignore count is zero, and
3126therefore has no effect. But if your program reaches a breakpoint whose
3127ignore count is positive, then instead of stopping, it just decrements
3128the ignore count by one and continues. As a result, if the ignore count
3129value is @var{n}, the breakpoint does not stop the next @var{n} times
3130your program reaches it.
3131
3132@table @code
3133@kindex ignore
3134@item ignore @var{bnum} @var{count}
3135Set the ignore count of breakpoint number @var{bnum} to @var{count}.
3136The next @var{count} times the breakpoint is reached, your program's
3137execution does not stop; other than to decrement the ignore count, @value{GDBN}
3138takes no action.
3139
3140To make the breakpoint stop the next time it is reached, specify
3141a count of zero.
3142
3143When you use @code{continue} to resume execution of your program from a
3144breakpoint, you can specify an ignore count directly as an argument to
3145@code{continue}, rather than using @code{ignore}. @xref{Continuing and
3146Stepping,,Continuing and stepping}.
3147
3148If a breakpoint has a positive ignore count and a condition, the
3149condition is not checked. Once the ignore count reaches zero,
3150@value{GDBN} resumes checking the condition.
3151
3152You could achieve the effect of the ignore count with a condition such
3153as @w{@samp{$foo-- <= 0}} using a debugger convenience variable that
3154is decremented each time. @xref{Convenience Vars, ,Convenience
3155variables}.
3156@end table
3157
3158Ignore counts apply to breakpoints, watchpoints, and catchpoints.
3159
3160
6d2ebf8b 3161@node Break Commands
c906108c
SS
3162@subsection Breakpoint command lists
3163
3164@cindex breakpoint commands
3165You can give any breakpoint (or watchpoint or catchpoint) a series of
3166commands to execute when your program stops due to that breakpoint. For
3167example, you might want to print the values of certain expressions, or
3168enable other breakpoints.
3169
3170@table @code
3171@kindex commands
3172@kindex end
3173@item commands @r{[}@var{bnum}@r{]}
3174@itemx @dots{} @var{command-list} @dots{}
3175@itemx end
3176Specify a list of commands for breakpoint number @var{bnum}. The commands
3177themselves appear on the following lines. Type a line containing just
3178@code{end} to terminate the commands.
3179
3180To remove all commands from a breakpoint, type @code{commands} and
3181follow it immediately with @code{end}; that is, give no commands.
3182
3183With no @var{bnum} argument, @code{commands} refers to the last
3184breakpoint, watchpoint, or catchpoint set (not to the breakpoint most
3185recently encountered).
3186@end table
3187
3188Pressing @key{RET} as a means of repeating the last @value{GDBN} command is
3189disabled within a @var{command-list}.
3190
3191You can use breakpoint commands to start your program up again. Simply
3192use the @code{continue} command, or @code{step}, or any other command
3193that resumes execution.
3194
3195Any other commands in the command list, after a command that resumes
3196execution, are ignored. This is because any time you resume execution
3197(even with a simple @code{next} or @code{step}), you may encounter
3198another breakpoint---which could have its own command list, leading to
3199ambiguities about which list to execute.
3200
3201@kindex silent
3202If the first command you specify in a command list is @code{silent}, the
3203usual message about stopping at a breakpoint is not printed. This may
3204be desirable for breakpoints that are to print a specific message and
3205then continue. If none of the remaining commands print anything, you
3206see no sign that the breakpoint was reached. @code{silent} is
3207meaningful only at the beginning of a breakpoint command list.
3208
3209The commands @code{echo}, @code{output}, and @code{printf} allow you to
3210print precisely controlled output, and are often useful in silent
3211breakpoints. @xref{Output, ,Commands for controlled output}.
3212
3213For example, here is how you could use breakpoint commands to print the
3214value of @code{x} at entry to @code{foo} whenever @code{x} is positive.
3215
3216@example
3217break foo if x>0
3218commands
3219silent
3220printf "x is %d\n",x
3221cont
3222end
3223@end example
3224
3225One application for breakpoint commands is to compensate for one bug so
3226you can test for another. Put a breakpoint just after the erroneous line
3227of code, give it a condition to detect the case in which something
3228erroneous has been done, and give it commands to assign correct values
3229to any variables that need them. End with the @code{continue} command
3230so that your program does not stop, and start with the @code{silent}
3231command so that no output is produced. Here is an example:
3232
3233@example
3234break 403
3235commands
3236silent
3237set x = y + 4
3238cont
3239end
3240@end example
3241
6d2ebf8b 3242@node Breakpoint Menus
c906108c
SS
3243@subsection Breakpoint menus
3244@cindex overloading
3245@cindex symbol overloading
3246
b37052ae 3247Some programming languages (notably C@t{++}) permit a single function name
c906108c
SS
3248to be defined several times, for application in different contexts.
3249This is called @dfn{overloading}. When a function name is overloaded,
3250@samp{break @var{function}} is not enough to tell @value{GDBN} where you want
3251a breakpoint. If you realize this is a problem, you can use
3252something like @samp{break @var{function}(@var{types})} to specify which
3253particular version of the function you want. Otherwise, @value{GDBN} offers
3254you a menu of numbered choices for different possible breakpoints, and
3255waits for your selection with the prompt @samp{>}. The first two
3256options are always @samp{[0] cancel} and @samp{[1] all}. Typing @kbd{1}
3257sets a breakpoint at each definition of @var{function}, and typing
3258@kbd{0} aborts the @code{break} command without setting any new
3259breakpoints.
3260
3261For example, the following session excerpt shows an attempt to set a
3262breakpoint at the overloaded symbol @code{String::after}.
3263We choose three particular definitions of that function name:
3264
3265@c FIXME! This is likely to change to show arg type lists, at least
3266@smallexample
3267@group
3268(@value{GDBP}) b String::after
3269[0] cancel
3270[1] all
3271[2] file:String.cc; line number:867
3272[3] file:String.cc; line number:860
3273[4] file:String.cc; line number:875
3274[5] file:String.cc; line number:853
3275[6] file:String.cc; line number:846
3276[7] file:String.cc; line number:735
3277> 2 4 6
3278Breakpoint 1 at 0xb26c: file String.cc, line 867.
3279Breakpoint 2 at 0xb344: file String.cc, line 875.
3280Breakpoint 3 at 0xafcc: file String.cc, line 846.
3281Multiple breakpoints were set.
3282Use the "delete" command to delete unwanted
3283 breakpoints.
3284(@value{GDBP})
3285@end group
3286@end smallexample
c906108c
SS
3287
3288@c @ifclear BARETARGET
6d2ebf8b 3289@node Error in Breakpoints
d4f3574e 3290@subsection ``Cannot insert breakpoints''
c906108c
SS
3291@c
3292@c FIXME!! 14/6/95 Is there a real example of this? Let's use it.
3293@c
d4f3574e
SS
3294Under some operating systems, breakpoints cannot be used in a program if
3295any other process is running that program. In this situation,
5d161b24 3296attempting to run or continue a program with a breakpoint causes
d4f3574e
SS
3297@value{GDBN} to print an error message:
3298
3299@example
3300Cannot insert breakpoints.
3301The same program may be running in another process.
3302@end example
3303
3304When this happens, you have three ways to proceed:
3305
3306@enumerate
3307@item
3308Remove or disable the breakpoints, then continue.
3309
3310@item
5d161b24 3311Suspend @value{GDBN}, and copy the file containing your program to a new
d4f3574e 3312name. Resume @value{GDBN} and use the @code{exec-file} command to specify
5d161b24 3313that @value{GDBN} should run your program under that name.
d4f3574e
SS
3314Then start your program again.
3315
3316@item
3317Relink your program so that the text segment is nonsharable, using the
3318linker option @samp{-N}. The operating system limitation may not apply
3319to nonsharable executables.
3320@end enumerate
c906108c
SS
3321@c @end ifclear
3322
d4f3574e
SS
3323A similar message can be printed if you request too many active
3324hardware-assisted breakpoints and watchpoints:
3325
3326@c FIXME: the precise wording of this message may change; the relevant
3327@c source change is not committed yet (Sep 3, 1999).
3328@smallexample
3329Stopped; cannot insert breakpoints.
3330You may have requested too many hardware breakpoints and watchpoints.
3331@end smallexample
3332
3333@noindent
3334This message is printed when you attempt to resume the program, since
3335only then @value{GDBN} knows exactly how many hardware breakpoints and
3336watchpoints it needs to insert.
3337
3338When this message is printed, you need to disable or remove some of the
3339hardware-assisted breakpoints and watchpoints, and then continue.
3340
3341
6d2ebf8b 3342@node Continuing and Stepping
c906108c
SS
3343@section Continuing and stepping
3344
3345@cindex stepping
3346@cindex continuing
3347@cindex resuming execution
3348@dfn{Continuing} means resuming program execution until your program
3349completes normally. In contrast, @dfn{stepping} means executing just
3350one more ``step'' of your program, where ``step'' may mean either one
3351line of source code, or one machine instruction (depending on what
7a292a7a
SS
3352particular command you use). Either when continuing or when stepping,
3353your program may stop even sooner, due to a breakpoint or a signal. (If
d4f3574e
SS
3354it stops due to a signal, you may want to use @code{handle}, or use
3355@samp{signal 0} to resume execution. @xref{Signals, ,Signals}.)
c906108c
SS
3356
3357@table @code
3358@kindex continue
41afff9a
EZ
3359@kindex c @r{(@code{continue})}
3360@kindex fg @r{(resume foreground execution)}
c906108c
SS
3361@item continue @r{[}@var{ignore-count}@r{]}
3362@itemx c @r{[}@var{ignore-count}@r{]}
3363@itemx fg @r{[}@var{ignore-count}@r{]}
3364Resume program execution, at the address where your program last stopped;
3365any breakpoints set at that address are bypassed. The optional argument
3366@var{ignore-count} allows you to specify a further number of times to
3367ignore a breakpoint at this location; its effect is like that of
3368@code{ignore} (@pxref{Conditions, ,Break conditions}).
3369
3370The argument @var{ignore-count} is meaningful only when your program
3371stopped due to a breakpoint. At other times, the argument to
3372@code{continue} is ignored.
3373
d4f3574e
SS
3374The synonyms @code{c} and @code{fg} (for @dfn{foreground}, as the
3375debugged program is deemed to be the foreground program) are provided
3376purely for convenience, and have exactly the same behavior as
3377@code{continue}.
c906108c
SS
3378@end table
3379
3380To resume execution at a different place, you can use @code{return}
3381(@pxref{Returning, ,Returning from a function}) to go back to the
3382calling function; or @code{jump} (@pxref{Jumping, ,Continuing at a
3383different address}) to go to an arbitrary location in your program.
3384
3385A typical technique for using stepping is to set a breakpoint
3386(@pxref{Breakpoints, ,Breakpoints; watchpoints; and catchpoints}) at the
3387beginning of the function or the section of your program where a problem
3388is believed to lie, run your program until it stops at that breakpoint,
3389and then step through the suspect area, examining the variables that are
3390interesting, until you see the problem happen.
3391
3392@table @code
3393@kindex step
41afff9a 3394@kindex s @r{(@code{step})}
c906108c
SS
3395@item step
3396Continue running your program until control reaches a different source
3397line, then stop it and return control to @value{GDBN}. This command is
3398abbreviated @code{s}.
3399
3400@quotation
3401@c "without debugging information" is imprecise; actually "without line
3402@c numbers in the debugging information". (gcc -g1 has debugging info but
3403@c not line numbers). But it seems complex to try to make that
3404@c distinction here.
3405@emph{Warning:} If you use the @code{step} command while control is
3406within a function that was compiled without debugging information,
3407execution proceeds until control reaches a function that does have
3408debugging information. Likewise, it will not step into a function which
3409is compiled without debugging information. To step through functions
3410without debugging information, use the @code{stepi} command, described
3411below.
3412@end quotation
3413
4a92d011
EZ
3414The @code{step} command only stops at the first instruction of a source
3415line. This prevents the multiple stops that could otherwise occur in
3416@code{switch} statements, @code{for} loops, etc. @code{step} continues
3417to stop if a function that has debugging information is called within
3418the line. In other words, @code{step} @emph{steps inside} any functions
3419called within the line.
c906108c 3420
d4f3574e
SS
3421Also, the @code{step} command only enters a function if there is line
3422number information for the function. Otherwise it acts like the
5d161b24 3423@code{next} command. This avoids problems when using @code{cc -gl}
c906108c 3424on MIPS machines. Previously, @code{step} entered subroutines if there
5d161b24 3425was any debugging information about the routine.
c906108c
SS
3426
3427@item step @var{count}
3428Continue running as in @code{step}, but do so @var{count} times. If a
7a292a7a
SS
3429breakpoint is reached, or a signal not related to stepping occurs before
3430@var{count} steps, stepping stops right away.
c906108c
SS
3431
3432@kindex next
41afff9a 3433@kindex n @r{(@code{next})}
c906108c
SS
3434@item next @r{[}@var{count}@r{]}
3435Continue to the next source line in the current (innermost) stack frame.
7a292a7a
SS
3436This is similar to @code{step}, but function calls that appear within
3437the line of code are executed without stopping. Execution stops when
3438control reaches a different line of code at the original stack level
3439that was executing when you gave the @code{next} command. This command
3440is abbreviated @code{n}.
c906108c
SS
3441
3442An argument @var{count} is a repeat count, as for @code{step}.
3443
3444
3445@c FIX ME!! Do we delete this, or is there a way it fits in with
3446@c the following paragraph? --- Vctoria
3447@c
3448@c @code{next} within a function that lacks debugging information acts like
3449@c @code{step}, but any function calls appearing within the code of the
3450@c function are executed without stopping.
3451
d4f3574e
SS
3452The @code{next} command only stops at the first instruction of a
3453source line. This prevents multiple stops that could otherwise occur in
4a92d011 3454@code{switch} statements, @code{for} loops, etc.
c906108c 3455
b90a5f51
CF
3456@kindex set step-mode
3457@item set step-mode
3458@cindex functions without line info, and stepping
3459@cindex stepping into functions with no line info
3460@itemx set step-mode on
4a92d011 3461The @code{set step-mode on} command causes the @code{step} command to
b90a5f51
CF
3462stop at the first instruction of a function which contains no debug line
3463information rather than stepping over it.
3464
4a92d011
EZ
3465This is useful in cases where you may be interested in inspecting the
3466machine instructions of a function which has no symbolic info and do not
3467want @value{GDBN} to automatically skip over this function.
b90a5f51
CF
3468
3469@item set step-mode off
4a92d011 3470Causes the @code{step} command to step over any functions which contains no
b90a5f51
CF
3471debug information. This is the default.
3472
c906108c
SS
3473@kindex finish
3474@item finish
3475Continue running until just after function in the selected stack frame
3476returns. Print the returned value (if any).
3477
3478Contrast this with the @code{return} command (@pxref{Returning,
3479,Returning from a function}).
3480
3481@kindex until
41afff9a 3482@kindex u @r{(@code{until})}
c906108c
SS
3483@item until
3484@itemx u
3485Continue running until a source line past the current line, in the
3486current stack frame, is reached. This command is used to avoid single
3487stepping through a loop more than once. It is like the @code{next}
3488command, except that when @code{until} encounters a jump, it
3489automatically continues execution until the program counter is greater
3490than the address of the jump.
3491
3492This means that when you reach the end of a loop after single stepping
3493though it, @code{until} makes your program continue execution until it
3494exits the loop. In contrast, a @code{next} command at the end of a loop
3495simply steps back to the beginning of the loop, which forces you to step
3496through the next iteration.
3497
3498@code{until} always stops your program if it attempts to exit the current
3499stack frame.
3500
3501@code{until} may produce somewhat counterintuitive results if the order
3502of machine code does not match the order of the source lines. For
3503example, in the following excerpt from a debugging session, the @code{f}
3504(@code{frame}) command shows that execution is stopped at line
3505@code{206}; yet when we use @code{until}, we get to line @code{195}:
3506
3507@example
3508(@value{GDBP}) f
3509#0 main (argc=4, argv=0xf7fffae8) at m4.c:206
3510206 expand_input();
3511(@value{GDBP}) until
3512195 for ( ; argc > 0; NEXTARG) @{
3513@end example
3514
3515This happened because, for execution efficiency, the compiler had
3516generated code for the loop closure test at the end, rather than the
3517start, of the loop---even though the test in a C @code{for}-loop is
3518written before the body of the loop. The @code{until} command appeared
3519to step back to the beginning of the loop when it advanced to this
3520expression; however, it has not really gone to an earlier
3521statement---not in terms of the actual machine code.
3522
3523@code{until} with no argument works by means of single
3524instruction stepping, and hence is slower than @code{until} with an
3525argument.
3526
3527@item until @var{location}
3528@itemx u @var{location}
3529Continue running your program until either the specified location is
3530reached, or the current stack frame returns. @var{location} is any of
3531the forms of argument acceptable to @code{break} (@pxref{Set Breaks,
3532,Setting breakpoints}). This form of the command uses breakpoints,
3533and hence is quicker than @code{until} without an argument.
3534
3535@kindex stepi
41afff9a 3536@kindex si @r{(@code{stepi})}
c906108c 3537@item stepi
96a2c332 3538@itemx stepi @var{arg}
c906108c
SS
3539@itemx si
3540Execute one machine instruction, then stop and return to the debugger.
3541
3542It is often useful to do @samp{display/i $pc} when stepping by machine
3543instructions. This makes @value{GDBN} automatically display the next
3544instruction to be executed, each time your program stops. @xref{Auto
3545Display,, Automatic display}.
3546
3547An argument is a repeat count, as in @code{step}.
3548
3549@need 750
3550@kindex nexti
41afff9a 3551@kindex ni @r{(@code{nexti})}
c906108c 3552@item nexti
96a2c332 3553@itemx nexti @var{arg}
c906108c
SS
3554@itemx ni
3555Execute one machine instruction, but if it is a function call,
3556proceed until the function returns.
3557
3558An argument is a repeat count, as in @code{next}.
3559@end table
3560
6d2ebf8b 3561@node Signals
c906108c
SS
3562@section Signals
3563@cindex signals
3564
3565A signal is an asynchronous event that can happen in a program. The
3566operating system defines the possible kinds of signals, and gives each
3567kind a name and a number. For example, in Unix @code{SIGINT} is the
d4f3574e 3568signal a program gets when you type an interrupt character (often @kbd{C-c});
c906108c
SS
3569@code{SIGSEGV} is the signal a program gets from referencing a place in
3570memory far away from all the areas in use; @code{SIGALRM} occurs when
3571the alarm clock timer goes off (which happens only if your program has
3572requested an alarm).
3573
3574@cindex fatal signals
3575Some signals, including @code{SIGALRM}, are a normal part of the
3576functioning of your program. Others, such as @code{SIGSEGV}, indicate
d4f3574e 3577errors; these signals are @dfn{fatal} (they kill your program immediately) if the
c906108c
SS
3578program has not specified in advance some other way to handle the signal.
3579@code{SIGINT} does not indicate an error in your program, but it is normally
3580fatal so it can carry out the purpose of the interrupt: to kill the program.
3581
3582@value{GDBN} has the ability to detect any occurrence of a signal in your
3583program. You can tell @value{GDBN} in advance what to do for each kind of
3584signal.
3585
3586@cindex handling signals
24f93129
EZ
3587Normally, @value{GDBN} is set up to let the non-erroneous signals like
3588@code{SIGALRM} be silently passed to your program
3589(so as not to interfere with their role in the program's functioning)
c906108c
SS
3590but to stop your program immediately whenever an error signal happens.
3591You can change these settings with the @code{handle} command.
3592
3593@table @code
3594@kindex info signals
3595@item info signals
96a2c332 3596@itemx info handle
c906108c
SS
3597Print a table of all the kinds of signals and how @value{GDBN} has been told to
3598handle each one. You can use this to see the signal numbers of all
3599the defined types of signals.
3600
d4f3574e 3601@code{info handle} is an alias for @code{info signals}.
c906108c
SS
3602
3603@kindex handle
3604@item handle @var{signal} @var{keywords}@dots{}
5ece1a18
EZ
3605Change the way @value{GDBN} handles signal @var{signal}. @var{signal}
3606can be the number of a signal or its name (with or without the
24f93129 3607@samp{SIG} at the beginning); a list of signal numbers of the form
5ece1a18
EZ
3608@samp{@var{low}-@var{high}}; or the word @samp{all}, meaning all the
3609known signals. The @var{keywords} say what change to make.
c906108c
SS
3610@end table
3611
3612@c @group
3613The keywords allowed by the @code{handle} command can be abbreviated.
3614Their full names are:
3615
3616@table @code
3617@item nostop
3618@value{GDBN} should not stop your program when this signal happens. It may
3619still print a message telling you that the signal has come in.
3620
3621@item stop
3622@value{GDBN} should stop your program when this signal happens. This implies
3623the @code{print} keyword as well.
3624
3625@item print
3626@value{GDBN} should print a message when this signal happens.
3627
3628@item noprint
3629@value{GDBN} should not mention the occurrence of the signal at all. This
3630implies the @code{nostop} keyword as well.
3631
3632@item pass
5ece1a18 3633@itemx noignore
c906108c
SS
3634@value{GDBN} should allow your program to see this signal; your program
3635can handle the signal, or else it may terminate if the signal is fatal
5ece1a18 3636and not handled. @code{pass} and @code{noignore} are synonyms.
c906108c
SS
3637
3638@item nopass
5ece1a18 3639@itemx ignore
c906108c 3640@value{GDBN} should not allow your program to see this signal.
5ece1a18 3641@code{nopass} and @code{ignore} are synonyms.
c906108c
SS
3642@end table
3643@c @end group
3644
d4f3574e
SS
3645When a signal stops your program, the signal is not visible to the
3646program until you
c906108c
SS
3647continue. Your program sees the signal then, if @code{pass} is in
3648effect for the signal in question @emph{at that time}. In other words,
3649after @value{GDBN} reports a signal, you can use the @code{handle}
3650command with @code{pass} or @code{nopass} to control whether your
3651program sees that signal when you continue.
3652
24f93129
EZ
3653The default is set to @code{nostop}, @code{noprint}, @code{pass} for
3654non-erroneous signals such as @code{SIGALRM}, @code{SIGWINCH} and
3655@code{SIGCHLD}, and to @code{stop}, @code{print}, @code{pass} for the
3656erroneous signals.
3657
c906108c
SS
3658You can also use the @code{signal} command to prevent your program from
3659seeing a signal, or cause it to see a signal it normally would not see,
3660or to give it any signal at any time. For example, if your program stopped
3661due to some sort of memory reference error, you might store correct
3662values into the erroneous variables and continue, hoping to see more
3663execution; but your program would probably terminate immediately as
3664a result of the fatal signal once it saw the signal. To prevent this,
3665you can continue with @samp{signal 0}. @xref{Signaling, ,Giving your
5d161b24 3666program a signal}.
c906108c 3667
6d2ebf8b 3668@node Thread Stops
c906108c
SS
3669@section Stopping and starting multi-thread programs
3670
3671When your program has multiple threads (@pxref{Threads,, Debugging
3672programs with multiple threads}), you can choose whether to set
3673breakpoints on all threads, or on a particular thread.
3674
3675@table @code
3676@cindex breakpoints and threads
3677@cindex thread breakpoints
3678@kindex break @dots{} thread @var{threadno}
3679@item break @var{linespec} thread @var{threadno}
3680@itemx break @var{linespec} thread @var{threadno} if @dots{}
3681@var{linespec} specifies source lines; there are several ways of
3682writing them, but the effect is always to specify some source line.
3683
3684Use the qualifier @samp{thread @var{threadno}} with a breakpoint command
3685to specify that you only want @value{GDBN} to stop the program when a
3686particular thread reaches this breakpoint. @var{threadno} is one of the
3687numeric thread identifiers assigned by @value{GDBN}, shown in the first
3688column of the @samp{info threads} display.
3689
3690If you do not specify @samp{thread @var{threadno}} when you set a
3691breakpoint, the breakpoint applies to @emph{all} threads of your
3692program.
3693
3694You can use the @code{thread} qualifier on conditional breakpoints as
3695well; in this case, place @samp{thread @var{threadno}} before the
3696breakpoint condition, like this:
3697
3698@smallexample
2df3850c 3699(@value{GDBP}) break frik.c:13 thread 28 if bartab > lim
c906108c
SS
3700@end smallexample
3701
3702@end table
3703
3704@cindex stopped threads
3705@cindex threads, stopped
3706Whenever your program stops under @value{GDBN} for any reason,
3707@emph{all} threads of execution stop, not just the current thread. This
3708allows you to examine the overall state of the program, including
3709switching between threads, without worrying that things may change
3710underfoot.
3711
3712@cindex continuing threads
3713@cindex threads, continuing
3714Conversely, whenever you restart the program, @emph{all} threads start
3715executing. @emph{This is true even when single-stepping} with commands
5d161b24 3716like @code{step} or @code{next}.
c906108c
SS
3717
3718In particular, @value{GDBN} cannot single-step all threads in lockstep.
3719Since thread scheduling is up to your debugging target's operating
3720system (not controlled by @value{GDBN}), other threads may
3721execute more than one statement while the current thread completes a
3722single step. Moreover, in general other threads stop in the middle of a
3723statement, rather than at a clean statement boundary, when the program
3724stops.
3725
3726You might even find your program stopped in another thread after
3727continuing or even single-stepping. This happens whenever some other
3728thread runs into a breakpoint, a signal, or an exception before the
3729first thread completes whatever you requested.
3730
3731On some OSes, you can lock the OS scheduler and thus allow only a single
3732thread to run.
3733
3734@table @code
3735@item set scheduler-locking @var{mode}
3736Set the scheduler locking mode. If it is @code{off}, then there is no
3737locking and any thread may run at any time. If @code{on}, then only the
3738current thread may run when the inferior is resumed. The @code{step}
3739mode optimizes for single-stepping. It stops other threads from
3740``seizing the prompt'' by preempting the current thread while you are
3741stepping. Other threads will only rarely (or never) get a chance to run
d4f3574e 3742when you step. They are more likely to run when you @samp{next} over a
c906108c 3743function call, and they are completely free to run when you use commands
d4f3574e 3744like @samp{continue}, @samp{until}, or @samp{finish}. However, unless another
c906108c 3745thread hits a breakpoint during its timeslice, they will never steal the
2df3850c 3746@value{GDBN} prompt away from the thread that you are debugging.
c906108c
SS
3747
3748@item show scheduler-locking
3749Display the current scheduler locking mode.
3750@end table
3751
c906108c 3752
6d2ebf8b 3753@node Stack
c906108c
SS
3754@chapter Examining the Stack
3755
3756When your program has stopped, the first thing you need to know is where it
3757stopped and how it got there.
3758
3759@cindex call stack
5d161b24
DB
3760Each time your program performs a function call, information about the call
3761is generated.
3762That information includes the location of the call in your program,
3763the arguments of the call,
c906108c 3764and the local variables of the function being called.
5d161b24 3765The information is saved in a block of data called a @dfn{stack frame}.
c906108c
SS
3766The stack frames are allocated in a region of memory called the @dfn{call
3767stack}.
3768
3769When your program stops, the @value{GDBN} commands for examining the
3770stack allow you to see all of this information.
3771
3772@cindex selected frame
3773One of the stack frames is @dfn{selected} by @value{GDBN} and many
3774@value{GDBN} commands refer implicitly to the selected frame. In
3775particular, whenever you ask @value{GDBN} for the value of a variable in
3776your program, the value is found in the selected frame. There are
3777special @value{GDBN} commands to select whichever frame you are
3778interested in. @xref{Selection, ,Selecting a frame}.
3779
3780When your program stops, @value{GDBN} automatically selects the
5d161b24 3781currently executing frame and describes it briefly, similar to the
c906108c
SS
3782@code{frame} command (@pxref{Frame Info, ,Information about a frame}).
3783
3784@menu
3785* Frames:: Stack frames
3786* Backtrace:: Backtraces
3787* Selection:: Selecting a frame
3788* Frame Info:: Information on a frame
c906108c
SS
3789
3790@end menu
3791
6d2ebf8b 3792@node Frames
c906108c
SS
3793@section Stack frames
3794
d4f3574e 3795@cindex frame, definition
c906108c
SS
3796@cindex stack frame
3797The call stack is divided up into contiguous pieces called @dfn{stack
3798frames}, or @dfn{frames} for short; each frame is the data associated
3799with one call to one function. The frame contains the arguments given
3800to the function, the function's local variables, and the address at
3801which the function is executing.
3802
3803@cindex initial frame
3804@cindex outermost frame
3805@cindex innermost frame
3806When your program is started, the stack has only one frame, that of the
3807function @code{main}. This is called the @dfn{initial} frame or the
3808@dfn{outermost} frame. Each time a function is called, a new frame is
3809made. Each time a function returns, the frame for that function invocation
3810is eliminated. If a function is recursive, there can be many frames for
3811the same function. The frame for the function in which execution is
3812actually occurring is called the @dfn{innermost} frame. This is the most
3813recently created of all the stack frames that still exist.
3814
3815@cindex frame pointer
3816Inside your program, stack frames are identified by their addresses. A
3817stack frame consists of many bytes, each of which has its own address; each
3818kind of computer has a convention for choosing one byte whose
3819address serves as the address of the frame. Usually this address is kept
3820in a register called the @dfn{frame pointer register} while execution is
3821going on in that frame.
3822
3823@cindex frame number
3824@value{GDBN} assigns numbers to all existing stack frames, starting with
3825zero for the innermost frame, one for the frame that called it,
3826and so on upward. These numbers do not really exist in your program;
3827they are assigned by @value{GDBN} to give you a way of designating stack
3828frames in @value{GDBN} commands.
3829
6d2ebf8b
SS
3830@c The -fomit-frame-pointer below perennially causes hbox overflow
3831@c underflow problems.
c906108c
SS
3832@cindex frameless execution
3833Some compilers provide a way to compile functions so that they operate
6d2ebf8b
SS
3834without stack frames. (For example, the @value{GCC} option
3835@example
3836@samp{-fomit-frame-pointer}
3837@end example
3838generates functions without a frame.)
c906108c
SS
3839This is occasionally done with heavily used library functions to save
3840the frame setup time. @value{GDBN} has limited facilities for dealing
3841with these function invocations. If the innermost function invocation
3842has no stack frame, @value{GDBN} nevertheless regards it as though
3843it had a separate frame, which is numbered zero as usual, allowing
3844correct tracing of the function call chain. However, @value{GDBN} has
3845no provision for frameless functions elsewhere in the stack.
3846
3847@table @code
d4f3574e 3848@kindex frame@r{, command}
41afff9a 3849@cindex current stack frame
c906108c 3850@item frame @var{args}
5d161b24 3851The @code{frame} command allows you to move from one stack frame to another,
c906108c 3852and to print the stack frame you select. @var{args} may be either the
5d161b24
DB
3853address of the frame or the stack frame number. Without an argument,
3854@code{frame} prints the current stack frame.
c906108c
SS
3855
3856@kindex select-frame
41afff9a 3857@cindex selecting frame silently
c906108c
SS
3858@item select-frame
3859The @code{select-frame} command allows you to move from one stack frame
3860to another without printing the frame. This is the silent version of
3861@code{frame}.
3862@end table
3863
6d2ebf8b 3864@node Backtrace
c906108c
SS
3865@section Backtraces
3866
3867@cindex backtraces
3868@cindex tracebacks
3869@cindex stack traces
3870A backtrace is a summary of how your program got where it is. It shows one
3871line per frame, for many frames, starting with the currently executing
3872frame (frame zero), followed by its caller (frame one), and on up the
3873stack.
3874
3875@table @code
3876@kindex backtrace
41afff9a 3877@kindex bt @r{(@code{backtrace})}
c906108c
SS
3878@item backtrace
3879@itemx bt
3880Print a backtrace of the entire stack: one line per frame for all
3881frames in the stack.
3882
3883You can stop the backtrace at any time by typing the system interrupt
3884character, normally @kbd{C-c}.
3885
3886@item backtrace @var{n}
3887@itemx bt @var{n}
3888Similar, but print only the innermost @var{n} frames.
3889
3890@item backtrace -@var{n}
3891@itemx bt -@var{n}
3892Similar, but print only the outermost @var{n} frames.
3893@end table
3894
3895@kindex where
3896@kindex info stack
41afff9a 3897@kindex info s @r{(@code{info stack})}
c906108c
SS
3898The names @code{where} and @code{info stack} (abbreviated @code{info s})
3899are additional aliases for @code{backtrace}.
3900
3901Each line in the backtrace shows the frame number and the function name.
3902The program counter value is also shown---unless you use @code{set
3903print address off}. The backtrace also shows the source file name and
3904line number, as well as the arguments to the function. The program
3905counter value is omitted if it is at the beginning of the code for that
3906line number.
3907
3908Here is an example of a backtrace. It was made with the command
3909@samp{bt 3}, so it shows the innermost three frames.
3910
3911@smallexample
3912@group
5d161b24 3913#0 m4_traceon (obs=0x24eb0, argc=1, argv=0x2b8c8)
c906108c
SS
3914 at builtin.c:993
3915#1 0x6e38 in expand_macro (sym=0x2b600) at macro.c:242
3916#2 0x6840 in expand_token (obs=0x0, t=177664, td=0xf7fffb08)
3917 at macro.c:71
3918(More stack frames follow...)
3919@end group
3920@end smallexample
3921
3922@noindent
3923The display for frame zero does not begin with a program counter
3924value, indicating that your program has stopped at the beginning of the
3925code for line @code{993} of @code{builtin.c}.
3926
6d2ebf8b 3927@node Selection
c906108c
SS
3928@section Selecting a frame
3929
3930Most commands for examining the stack and other data in your program work on
3931whichever stack frame is selected at the moment. Here are the commands for
3932selecting a stack frame; all of them finish by printing a brief description
3933of the stack frame just selected.
3934
3935@table @code
d4f3574e 3936@kindex frame@r{, selecting}
41afff9a 3937@kindex f @r{(@code{frame})}
c906108c
SS
3938@item frame @var{n}
3939@itemx f @var{n}
3940Select frame number @var{n}. Recall that frame zero is the innermost
3941(currently executing) frame, frame one is the frame that called the
3942innermost one, and so on. The highest-numbered frame is the one for
3943@code{main}.
3944
3945@item frame @var{addr}
3946@itemx f @var{addr}
3947Select the frame at address @var{addr}. This is useful mainly if the
3948chaining of stack frames has been damaged by a bug, making it
3949impossible for @value{GDBN} to assign numbers properly to all frames. In
3950addition, this can be useful when your program has multiple stacks and
3951switches between them.
3952
c906108c
SS
3953On the SPARC architecture, @code{frame} needs two addresses to
3954select an arbitrary frame: a frame pointer and a stack pointer.
3955
3956On the MIPS and Alpha architecture, it needs two addresses: a stack
3957pointer and a program counter.
3958
3959On the 29k architecture, it needs three addresses: a register stack
3960pointer, a program counter, and a memory stack pointer.
3961@c note to future updaters: this is conditioned on a flag
3962@c SETUP_ARBITRARY_FRAME in the tm-*.h files. The above is up to date
3963@c as of 27 Jan 1994.
c906108c
SS
3964
3965@kindex up
3966@item up @var{n}
3967Move @var{n} frames up the stack. For positive numbers @var{n}, this
3968advances toward the outermost frame, to higher frame numbers, to frames
3969that have existed longer. @var{n} defaults to one.
3970
3971@kindex down
41afff9a 3972@kindex do @r{(@code{down})}
c906108c
SS
3973@item down @var{n}
3974Move @var{n} frames down the stack. For positive numbers @var{n}, this
3975advances toward the innermost frame, to lower frame numbers, to frames
3976that were created more recently. @var{n} defaults to one. You may
3977abbreviate @code{down} as @code{do}.
3978@end table
3979
3980All of these commands end by printing two lines of output describing the
3981frame. The first line shows the frame number, the function name, the
3982arguments, and the source file and line number of execution in that
5d161b24 3983frame. The second line shows the text of that source line.
c906108c
SS
3984
3985@need 1000
3986For example:
3987
3988@smallexample
3989@group
3990(@value{GDBP}) up
3991#1 0x22f0 in main (argc=1, argv=0xf7fffbf4, env=0xf7fffbfc)
3992 at env.c:10
399310 read_input_file (argv[i]);
3994@end group
3995@end smallexample
3996
3997After such a printout, the @code{list} command with no arguments
3998prints ten lines centered on the point of execution in the frame.
3999@xref{List, ,Printing source lines}.
4000
4001@table @code
4002@kindex down-silently
4003@kindex up-silently
4004@item up-silently @var{n}
4005@itemx down-silently @var{n}
4006These two commands are variants of @code{up} and @code{down},
4007respectively; they differ in that they do their work silently, without
4008causing display of the new frame. They are intended primarily for use
4009in @value{GDBN} command scripts, where the output might be unnecessary and
4010distracting.
4011@end table
4012
6d2ebf8b 4013@node Frame Info
c906108c
SS
4014@section Information about a frame
4015
4016There are several other commands to print information about the selected
4017stack frame.
4018
4019@table @code
4020@item frame
4021@itemx f
4022When used without any argument, this command does not change which
4023frame is selected, but prints a brief description of the currently
4024selected stack frame. It can be abbreviated @code{f}. With an
4025argument, this command is used to select a stack frame.
4026@xref{Selection, ,Selecting a frame}.
4027
4028@kindex info frame
41afff9a 4029@kindex info f @r{(@code{info frame})}
c906108c
SS
4030@item info frame
4031@itemx info f
4032This command prints a verbose description of the selected stack frame,
4033including:
4034
4035@itemize @bullet
5d161b24
DB
4036@item
4037the address of the frame
c906108c
SS
4038@item
4039the address of the next frame down (called by this frame)
4040@item
4041the address of the next frame up (caller of this frame)
4042@item
4043the language in which the source code corresponding to this frame is written
4044@item
4045the address of the frame's arguments
4046@item
d4f3574e
SS
4047the address of the frame's local variables
4048@item
c906108c
SS
4049the program counter saved in it (the address of execution in the caller frame)
4050@item
4051which registers were saved in the frame
4052@end itemize
4053
4054@noindent The verbose description is useful when
4055something has gone wrong that has made the stack format fail to fit
4056the usual conventions.
4057
4058@item info frame @var{addr}
4059@itemx info f @var{addr}
4060Print a verbose description of the frame at address @var{addr}, without
4061selecting that frame. The selected frame remains unchanged by this
4062command. This requires the same kind of address (more than one for some
4063architectures) that you specify in the @code{frame} command.
4064@xref{Selection, ,Selecting a frame}.
4065
4066@kindex info args
4067@item info args
4068Print the arguments of the selected frame, each on a separate line.
4069
4070@item info locals
4071@kindex info locals
4072Print the local variables of the selected frame, each on a separate
4073line. These are all variables (declared either static or automatic)
4074accessible at the point of execution of the selected frame.
4075
c906108c 4076@kindex info catch
d4f3574e
SS
4077@cindex catch exceptions, list active handlers
4078@cindex exception handlers, how to list
c906108c
SS
4079@item info catch
4080Print a list of all the exception handlers that are active in the
4081current stack frame at the current point of execution. To see other
4082exception handlers, visit the associated frame (using the @code{up},
4083@code{down}, or @code{frame} commands); then type @code{info catch}.
4084@xref{Set Catchpoints, , Setting catchpoints}.
53a5351d 4085
c906108c
SS
4086@end table
4087
c906108c 4088
6d2ebf8b 4089@node Source
c906108c
SS
4090@chapter Examining Source Files
4091
4092@value{GDBN} can print parts of your program's source, since the debugging
4093information recorded in the program tells @value{GDBN} what source files were
4094used to build it. When your program stops, @value{GDBN} spontaneously prints
4095the line where it stopped. Likewise, when you select a stack frame
4096(@pxref{Selection, ,Selecting a frame}), @value{GDBN} prints the line where
4097execution in that frame has stopped. You can print other portions of
4098source files by explicit command.
4099
7a292a7a 4100If you use @value{GDBN} through its @sc{gnu} Emacs interface, you may
d4f3574e 4101prefer to use Emacs facilities to view source; see @ref{Emacs, ,Using
7a292a7a 4102@value{GDBN} under @sc{gnu} Emacs}.
c906108c
SS
4103
4104@menu
4105* List:: Printing source lines
c906108c 4106* Search:: Searching source files
c906108c
SS
4107* Source Path:: Specifying source directories
4108* Machine Code:: Source and machine code
4109@end menu
4110
6d2ebf8b 4111@node List
c906108c
SS
4112@section Printing source lines
4113
4114@kindex list
41afff9a 4115@kindex l @r{(@code{list})}
c906108c 4116To print lines from a source file, use the @code{list} command
5d161b24 4117(abbreviated @code{l}). By default, ten lines are printed.
c906108c
SS
4118There are several ways to specify what part of the file you want to print.
4119
4120Here are the forms of the @code{list} command most commonly used:
4121
4122@table @code
4123@item list @var{linenum}
4124Print lines centered around line number @var{linenum} in the
4125current source file.
4126
4127@item list @var{function}
4128Print lines centered around the beginning of function
4129@var{function}.
4130
4131@item list
4132Print more lines. If the last lines printed were printed with a
4133@code{list} command, this prints lines following the last lines
4134printed; however, if the last line printed was a solitary line printed
4135as part of displaying a stack frame (@pxref{Stack, ,Examining the
4136Stack}), this prints lines centered around that line.
4137
4138@item list -
4139Print lines just before the lines last printed.
4140@end table
4141
4142By default, @value{GDBN} prints ten source lines with any of these forms of
4143the @code{list} command. You can change this using @code{set listsize}:
4144
4145@table @code
4146@kindex set listsize
4147@item set listsize @var{count}
4148Make the @code{list} command display @var{count} source lines (unless
4149the @code{list} argument explicitly specifies some other number).
4150
4151@kindex show listsize
4152@item show listsize
4153Display the number of lines that @code{list} prints.
4154@end table
4155
4156Repeating a @code{list} command with @key{RET} discards the argument,
4157so it is equivalent to typing just @code{list}. This is more useful
4158than listing the same lines again. An exception is made for an
4159argument of @samp{-}; that argument is preserved in repetition so that
4160each repetition moves up in the source file.
4161
4162@cindex linespec
4163In general, the @code{list} command expects you to supply zero, one or two
4164@dfn{linespecs}. Linespecs specify source lines; there are several ways
d4f3574e 4165of writing them, but the effect is always to specify some source line.
c906108c
SS
4166Here is a complete description of the possible arguments for @code{list}:
4167
4168@table @code
4169@item list @var{linespec}
4170Print lines centered around the line specified by @var{linespec}.
4171
4172@item list @var{first},@var{last}
4173Print lines from @var{first} to @var{last}. Both arguments are
4174linespecs.
4175
4176@item list ,@var{last}
4177Print lines ending with @var{last}.
4178
4179@item list @var{first},
4180Print lines starting with @var{first}.
4181
4182@item list +
4183Print lines just after the lines last printed.
4184
4185@item list -
4186Print lines just before the lines last printed.
4187
4188@item list
4189As described in the preceding table.
4190@end table
4191
4192Here are the ways of specifying a single source line---all the
4193kinds of linespec.
4194
4195@table @code
4196@item @var{number}
4197Specifies line @var{number} of the current source file.
4198When a @code{list} command has two linespecs, this refers to
4199the same source file as the first linespec.
4200
4201@item +@var{offset}
4202Specifies the line @var{offset} lines after the last line printed.
4203When used as the second linespec in a @code{list} command that has
4204two, this specifies the line @var{offset} lines down from the
4205first linespec.
4206
4207@item -@var{offset}
4208Specifies the line @var{offset} lines before the last line printed.
4209
4210@item @var{filename}:@var{number}
4211Specifies line @var{number} in the source file @var{filename}.
4212
4213@item @var{function}
4214Specifies the line that begins the body of the function @var{function}.
4215For example: in C, this is the line with the open brace.
4216
4217@item @var{filename}:@var{function}
4218Specifies the line of the open-brace that begins the body of the
4219function @var{function} in the file @var{filename}. You only need the
4220file name with a function name to avoid ambiguity when there are
4221identically named functions in different source files.
4222
4223@item *@var{address}
4224Specifies the line containing the program address @var{address}.
4225@var{address} may be any expression.
4226@end table
4227
6d2ebf8b 4228@node Search
c906108c
SS
4229@section Searching source files
4230@cindex searching
4231@kindex reverse-search
4232
4233There are two commands for searching through the current source file for a
4234regular expression.
4235
4236@table @code
4237@kindex search
4238@kindex forward-search
4239@item forward-search @var{regexp}
4240@itemx search @var{regexp}
4241The command @samp{forward-search @var{regexp}} checks each line,
4242starting with the one following the last line listed, for a match for
5d161b24 4243@var{regexp}. It lists the line that is found. You can use the
c906108c
SS
4244synonym @samp{search @var{regexp}} or abbreviate the command name as
4245@code{fo}.
4246
4247@item reverse-search @var{regexp}
4248The command @samp{reverse-search @var{regexp}} checks each line, starting
4249with the one before the last line listed and going backward, for a match
4250for @var{regexp}. It lists the line that is found. You can abbreviate
4251this command as @code{rev}.
4252@end table
c906108c 4253
6d2ebf8b 4254@node Source Path
c906108c
SS
4255@section Specifying source directories
4256
4257@cindex source path
4258@cindex directories for source files
4259Executable programs sometimes do not record the directories of the source
4260files from which they were compiled, just the names. Even when they do,
4261the directories could be moved between the compilation and your debugging
4262session. @value{GDBN} has a list of directories to search for source files;
4263this is called the @dfn{source path}. Each time @value{GDBN} wants a source file,
4264it tries all the directories in the list, in the order they are present
4265in the list, until it finds a file with the desired name. Note that
4266the executable search path is @emph{not} used for this purpose. Neither is
4267the current working directory, unless it happens to be in the source
4268path.
4269
4270If @value{GDBN} cannot find a source file in the source path, and the
4271object program records a directory, @value{GDBN} tries that directory
4272too. If the source path is empty, and there is no record of the
4273compilation directory, @value{GDBN} looks in the current directory as a
4274last resort.
4275
4276Whenever you reset or rearrange the source path, @value{GDBN} clears out
4277any information it has cached about where source files are found and where
4278each line is in the file.
4279
4280@kindex directory
4281@kindex dir
d4f3574e
SS
4282When you start @value{GDBN}, its source path includes only @samp{cdir}
4283and @samp{cwd}, in that order.
c906108c
SS
4284To add other directories, use the @code{directory} command.
4285
4286@table @code
4287@item directory @var{dirname} @dots{}
4288@item dir @var{dirname} @dots{}
4289Add directory @var{dirname} to the front of the source path. Several
d4f3574e
SS
4290directory names may be given to this command, separated by @samp{:}
4291(@samp{;} on MS-DOS and MS-Windows, where @samp{:} usually appears as
4292part of absolute file names) or
c906108c
SS
4293whitespace. You may specify a directory that is already in the source
4294path; this moves it forward, so @value{GDBN} searches it sooner.
4295
4296@kindex cdir
4297@kindex cwd
41afff9a
EZ
4298@vindex $cdir@r{, convenience variable}
4299@vindex $cwdr@r{, convenience variable}
c906108c
SS
4300@cindex compilation directory
4301@cindex current directory
4302@cindex working directory
4303@cindex directory, current
4304@cindex directory, compilation
4305You can use the string @samp{$cdir} to refer to the compilation
4306directory (if one is recorded), and @samp{$cwd} to refer to the current
4307working directory. @samp{$cwd} is not the same as @samp{.}---the former
4308tracks the current working directory as it changes during your @value{GDBN}
4309session, while the latter is immediately expanded to the current
4310directory at the time you add an entry to the source path.
4311
4312@item directory
4313Reset the source path to empty again. This requires confirmation.
4314
4315@c RET-repeat for @code{directory} is explicitly disabled, but since
4316@c repeating it would be a no-op we do not say that. (thanks to RMS)
4317
4318@item show directories
4319@kindex show directories
4320Print the source path: show which directories it contains.
4321@end table
4322
4323If your source path is cluttered with directories that are no longer of
4324interest, @value{GDBN} may sometimes cause confusion by finding the wrong
4325versions of source. You can correct the situation as follows:
4326
4327@enumerate
4328@item
4329Use @code{directory} with no argument to reset the source path to empty.
4330
4331@item
4332Use @code{directory} with suitable arguments to reinstall the
4333directories you want in the source path. You can add all the
4334directories in one command.
4335@end enumerate
4336
6d2ebf8b 4337@node Machine Code
c906108c
SS
4338@section Source and machine code
4339
4340You can use the command @code{info line} to map source lines to program
4341addresses (and vice versa), and the command @code{disassemble} to display
4342a range of addresses as machine instructions. When run under @sc{gnu} Emacs
d4f3574e 4343mode, the @code{info line} command causes the arrow to point to the
5d161b24 4344line specified. Also, @code{info line} prints addresses in symbolic form as
c906108c
SS
4345well as hex.
4346
4347@table @code
4348@kindex info line
4349@item info line @var{linespec}
4350Print the starting and ending addresses of the compiled code for
4351source line @var{linespec}. You can specify source lines in any of
4352the ways understood by the @code{list} command (@pxref{List, ,Printing
4353source lines}).
4354@end table
4355
4356For example, we can use @code{info line} to discover the location of
4357the object code for the first line of function
4358@code{m4_changequote}:
4359
d4f3574e
SS
4360@c FIXME: I think this example should also show the addresses in
4361@c symbolic form, as they usually would be displayed.
c906108c 4362@smallexample
96a2c332 4363(@value{GDBP}) info line m4_changequote
c906108c
SS
4364Line 895 of "builtin.c" starts at pc 0x634c and ends at 0x6350.
4365@end smallexample
4366
4367@noindent
4368We can also inquire (using @code{*@var{addr}} as the form for
4369@var{linespec}) what source line covers a particular address:
4370@smallexample
4371(@value{GDBP}) info line *0x63ff
4372Line 926 of "builtin.c" starts at pc 0x63e4 and ends at 0x6404.
4373@end smallexample
4374
4375@cindex @code{$_} and @code{info line}
41afff9a 4376@kindex x@r{(examine), and} info line
c906108c
SS
4377After @code{info line}, the default address for the @code{x} command
4378is changed to the starting address of the line, so that @samp{x/i} is
4379sufficient to begin examining the machine code (@pxref{Memory,
4380,Examining memory}). Also, this address is saved as the value of the
4381convenience variable @code{$_} (@pxref{Convenience Vars, ,Convenience
4382variables}).
4383
4384@table @code
4385@kindex disassemble
4386@cindex assembly instructions
4387@cindex instructions, assembly
4388@cindex machine instructions
4389@cindex listing machine instructions
4390@item disassemble
4391This specialized command dumps a range of memory as machine
4392instructions. The default memory range is the function surrounding the
4393program counter of the selected frame. A single argument to this
4394command is a program counter value; @value{GDBN} dumps the function
4395surrounding this value. Two arguments specify a range of addresses
4396(first inclusive, second exclusive) to dump.
4397@end table
4398
c906108c
SS
4399The following example shows the disassembly of a range of addresses of
4400HP PA-RISC 2.0 code:
4401
4402@smallexample
4403(@value{GDBP}) disas 0x32c4 0x32e4
4404Dump of assembler code from 0x32c4 to 0x32e4:
44050x32c4 <main+204>: addil 0,dp
44060x32c8 <main+208>: ldw 0x22c(sr0,r1),r26
44070x32cc <main+212>: ldil 0x3000,r31
44080x32d0 <main+216>: ble 0x3f8(sr4,r31)
44090x32d4 <main+220>: ldo 0(r31),rp
44100x32d8 <main+224>: addil -0x800,dp
44110x32dc <main+228>: ldo 0x588(r1),r26
44120x32e0 <main+232>: ldil 0x3000,r31
4413End of assembler dump.
4414@end smallexample
c906108c
SS
4415
4416Some architectures have more than one commonly-used set of instruction
4417mnemonics or other syntax.
4418
4419@table @code
d4f3574e 4420@kindex set disassembly-flavor
c906108c
SS
4421@cindex assembly instructions
4422@cindex instructions, assembly
4423@cindex machine instructions
4424@cindex listing machine instructions
d4f3574e
SS
4425@cindex Intel disassembly flavor
4426@cindex AT&T disassembly flavor
4427@item set disassembly-flavor @var{instruction-set}
c906108c
SS
4428Select the instruction set to use when disassembling the
4429program via the @code{disassemble} or @code{x/i} commands.
4430
4431Currently this command is only defined for the Intel x86 family. You
d4f3574e
SS
4432can set @var{instruction-set} to either @code{intel} or @code{att}.
4433The default is @code{att}, the AT&T flavor used by default by Unix
4434assemblers for x86-based targets.
c906108c
SS
4435@end table
4436
4437
6d2ebf8b 4438@node Data
c906108c
SS
4439@chapter Examining Data
4440
4441@cindex printing data
4442@cindex examining data
4443@kindex print
4444@kindex inspect
4445@c "inspect" is not quite a synonym if you are using Epoch, which we do not
4446@c document because it is nonstandard... Under Epoch it displays in a
4447@c different window or something like that.
4448The usual way to examine data in your program is with the @code{print}
7a292a7a
SS
4449command (abbreviated @code{p}), or its synonym @code{inspect}. It
4450evaluates and prints the value of an expression of the language your
4451program is written in (@pxref{Languages, ,Using @value{GDBN} with
4452Different Languages}).
c906108c
SS
4453
4454@table @code
d4f3574e
SS
4455@item print @var{expr}
4456@itemx print /@var{f} @var{expr}
4457@var{expr} is an expression (in the source language). By default the
4458value of @var{expr} is printed in a format appropriate to its data type;
c906108c 4459you can choose a different format by specifying @samp{/@var{f}}, where
d4f3574e 4460@var{f} is a letter specifying the format; see @ref{Output Formats,,Output
c906108c
SS
4461formats}.
4462
4463@item print
4464@itemx print /@var{f}
d4f3574e 4465If you omit @var{expr}, @value{GDBN} displays the last value again (from the
c906108c
SS
4466@dfn{value history}; @pxref{Value History, ,Value history}). This allows you to
4467conveniently inspect the same value in an alternative format.
4468@end table
4469
4470A more low-level way of examining data is with the @code{x} command.
4471It examines data in memory at a specified address and prints it in a
4472specified format. @xref{Memory, ,Examining memory}.
4473
7a292a7a 4474If you are interested in information about types, or about how the
d4f3574e
SS
4475fields of a struct or a class are declared, use the @code{ptype @var{exp}}
4476command rather than @code{print}. @xref{Symbols, ,Examining the Symbol
7a292a7a 4477Table}.
c906108c
SS
4478
4479@menu
4480* Expressions:: Expressions
4481* Variables:: Program variables
4482* Arrays:: Artificial arrays
4483* Output Formats:: Output formats
4484* Memory:: Examining memory
4485* Auto Display:: Automatic display
4486* Print Settings:: Print settings
4487* Value History:: Value history
4488* Convenience Vars:: Convenience variables
4489* Registers:: Registers
c906108c 4490* Floating Point Hardware:: Floating point hardware
29e57380 4491* Memory Region Attributes:: Memory region attributes
c906108c
SS
4492@end menu
4493
6d2ebf8b 4494@node Expressions
c906108c
SS
4495@section Expressions
4496
4497@cindex expressions
4498@code{print} and many other @value{GDBN} commands accept an expression and
4499compute its value. Any kind of constant, variable or operator defined
4500by the programming language you are using is valid in an expression in
4501@value{GDBN}. This includes conditional expressions, function calls, casts
4502and string constants. It unfortunately does not include symbols defined
4503by preprocessor @code{#define} commands.
4504
d4f3574e
SS
4505@value{GDBN} supports array constants in expressions input by
4506the user. The syntax is @{@var{element}, @var{element}@dots{}@}. For example,
5d161b24 4507you can use the command @code{print @{1, 2, 3@}} to build up an array in
d4f3574e 4508memory that is @code{malloc}ed in the target program.
c906108c 4509
c906108c
SS
4510Because C is so widespread, most of the expressions shown in examples in
4511this manual are in C. @xref{Languages, , Using @value{GDBN} with Different
4512Languages}, for information on how to use expressions in other
4513languages.
4514
4515In this section, we discuss operators that you can use in @value{GDBN}
4516expressions regardless of your programming language.
4517
4518Casts are supported in all languages, not just in C, because it is so
4519useful to cast a number into a pointer in order to examine a structure
4520at that address in memory.
4521@c FIXME: casts supported---Mod2 true?
c906108c
SS
4522
4523@value{GDBN} supports these operators, in addition to those common
4524to programming languages:
4525
4526@table @code
4527@item @@
4528@samp{@@} is a binary operator for treating parts of memory as arrays.
4529@xref{Arrays, ,Artificial arrays}, for more information.
4530
4531@item ::
4532@samp{::} allows you to specify a variable in terms of the file or
4533function where it is defined. @xref{Variables, ,Program variables}.
4534
4535@cindex @{@var{type}@}
4536@cindex type casting memory
4537@cindex memory, viewing as typed object
4538@cindex casts, to view memory
4539@item @{@var{type}@} @var{addr}
4540Refers to an object of type @var{type} stored at address @var{addr} in
4541memory. @var{addr} may be any expression whose value is an integer or
4542pointer (but parentheses are required around binary operators, just as in
4543a cast). This construct is allowed regardless of what kind of data is
4544normally supposed to reside at @var{addr}.
4545@end table
4546
6d2ebf8b 4547@node Variables
c906108c
SS
4548@section Program variables
4549
4550The most common kind of expression to use is the name of a variable
4551in your program.
4552
4553Variables in expressions are understood in the selected stack frame
4554(@pxref{Selection, ,Selecting a frame}); they must be either:
4555
4556@itemize @bullet
4557@item
4558global (or file-static)
4559@end itemize
4560
5d161b24 4561@noindent or
c906108c
SS
4562
4563@itemize @bullet
4564@item
4565visible according to the scope rules of the
4566programming language from the point of execution in that frame
5d161b24 4567@end itemize
c906108c
SS
4568
4569@noindent This means that in the function
4570
4571@example
4572foo (a)
4573 int a;
4574@{
4575 bar (a);
4576 @{
4577 int b = test ();
4578 bar (b);
4579 @}
4580@}
4581@end example
4582
4583@noindent
4584you can examine and use the variable @code{a} whenever your program is
4585executing within the function @code{foo}, but you can only use or
4586examine the variable @code{b} while your program is executing inside
4587the block where @code{b} is declared.
4588
4589@cindex variable name conflict
4590There is an exception: you can refer to a variable or function whose
4591scope is a single source file even if the current execution point is not
4592in this file. But it is possible to have more than one such variable or
4593function with the same name (in different source files). If that
4594happens, referring to that name has unpredictable effects. If you wish,
4595you can specify a static variable in a particular function or file,
4596using the colon-colon notation:
4597
d4f3574e 4598@cindex colon-colon, context for variables/functions
c906108c
SS
4599@iftex
4600@c info cannot cope with a :: index entry, but why deprive hard copy readers?
41afff9a 4601@cindex @code{::}, context for variables/functions
c906108c
SS
4602@end iftex
4603@example
4604@var{file}::@var{variable}
4605@var{function}::@var{variable}
4606@end example
4607
4608@noindent
4609Here @var{file} or @var{function} is the name of the context for the
4610static @var{variable}. In the case of file names, you can use quotes to
4611make sure @value{GDBN} parses the file name as a single word---for example,
4612to print a global value of @code{x} defined in @file{f2.c}:
4613
4614@example
4615(@value{GDBP}) p 'f2.c'::x
4616@end example
4617
b37052ae 4618@cindex C@t{++} scope resolution
c906108c 4619This use of @samp{::} is very rarely in conflict with the very similar
b37052ae 4620use of the same notation in C@t{++}. @value{GDBN} also supports use of the C@t{++}
c906108c
SS
4621scope resolution operator in @value{GDBN} expressions.
4622@c FIXME: Um, so what happens in one of those rare cases where it's in
4623@c conflict?? --mew
c906108c
SS
4624
4625@cindex wrong values
4626@cindex variable values, wrong
4627@quotation
4628@emph{Warning:} Occasionally, a local variable may appear to have the
4629wrong value at certain points in a function---just after entry to a new
4630scope, and just before exit.
4631@end quotation
4632You may see this problem when you are stepping by machine instructions.
4633This is because, on most machines, it takes more than one instruction to
4634set up a stack frame (including local variable definitions); if you are
4635stepping by machine instructions, variables may appear to have the wrong
4636values until the stack frame is completely built. On exit, it usually
4637also takes more than one machine instruction to destroy a stack frame;
4638after you begin stepping through that group of instructions, local
4639variable definitions may be gone.
4640
4641This may also happen when the compiler does significant optimizations.
4642To be sure of always seeing accurate values, turn off all optimization
4643when compiling.
4644
d4f3574e
SS
4645@cindex ``No symbol "foo" in current context''
4646Another possible effect of compiler optimizations is to optimize
4647unused variables out of existence, or assign variables to registers (as
4648opposed to memory addresses). Depending on the support for such cases
4649offered by the debug info format used by the compiler, @value{GDBN}
4650might not be able to display values for such local variables. If that
4651happens, @value{GDBN} will print a message like this:
4652
4653@example
4654No symbol "foo" in current context.
4655@end example
4656
4657To solve such problems, either recompile without optimizations, or use a
4658different debug info format, if the compiler supports several such
b37052ae 4659formats. For example, @value{NGCC}, the @sc{gnu} C/C@t{++} compiler usually
d4f3574e
SS
4660supports the @samp{-gstabs} option. @samp{-gstabs} produces debug info
4661in a format that is superior to formats such as COFF. You may be able
96c405b3 4662to use DWARF2 (@samp{-gdwarf-2}), which is also an effective form for
d4f3574e
SS
4663debug info. See @ref{Debugging Options,,Options for Debugging Your
4664Program or @sc{gnu} CC, gcc.info, Using @sc{gnu} CC}, for more
4665information.
4666
4667
6d2ebf8b 4668@node Arrays
c906108c
SS
4669@section Artificial arrays
4670
4671@cindex artificial array
41afff9a 4672@kindex @@@r{, referencing memory as an array}
c906108c
SS
4673It is often useful to print out several successive objects of the
4674same type in memory; a section of an array, or an array of
4675dynamically determined size for which only a pointer exists in the
4676program.
4677
4678You can do this by referring to a contiguous span of memory as an
4679@dfn{artificial array}, using the binary operator @samp{@@}. The left
4680operand of @samp{@@} should be the first element of the desired array
4681and be an individual object. The right operand should be the desired length
4682of the array. The result is an array value whose elements are all of
4683the type of the left argument. The first element is actually the left
4684argument; the second element comes from bytes of memory immediately
4685following those that hold the first element, and so on. Here is an
4686example. If a program says
4687
4688@example
4689int *array = (int *) malloc (len * sizeof (int));
4690@end example
4691
4692@noindent
4693you can print the contents of @code{array} with
4694
4695@example
4696p *array@@len
4697@end example
4698
4699The left operand of @samp{@@} must reside in memory. Array values made
4700with @samp{@@} in this way behave just like other arrays in terms of
4701subscripting, and are coerced to pointers when used in expressions.
4702Artificial arrays most often appear in expressions via the value history
4703(@pxref{Value History, ,Value history}), after printing one out.
4704
4705Another way to create an artificial array is to use a cast.
4706This re-interprets a value as if it were an array.
4707The value need not be in memory:
4708@example
4709(@value{GDBP}) p/x (short[2])0x12345678
4710$1 = @{0x1234, 0x5678@}
4711@end example
4712
4713As a convenience, if you leave the array length out (as in
c3f6f71d 4714@samp{(@var{type}[])@var{value}}) @value{GDBN} calculates the size to fill
c906108c
SS
4715the value (as @samp{sizeof(@var{value})/sizeof(@var{type})}:
4716@example
4717(@value{GDBP}) p/x (short[])0x12345678
4718$2 = @{0x1234, 0x5678@}
4719@end example
4720
4721Sometimes the artificial array mechanism is not quite enough; in
4722moderately complex data structures, the elements of interest may not
4723actually be adjacent---for example, if you are interested in the values
4724of pointers in an array. One useful work-around in this situation is
4725to use a convenience variable (@pxref{Convenience Vars, ,Convenience
4726variables}) as a counter in an expression that prints the first
4727interesting value, and then repeat that expression via @key{RET}. For
4728instance, suppose you have an array @code{dtab} of pointers to
4729structures, and you are interested in the values of a field @code{fv}
4730in each structure. Here is an example of what you might type:
4731
4732@example
4733set $i = 0
4734p dtab[$i++]->fv
4735@key{RET}
4736@key{RET}
4737@dots{}
4738@end example
4739
6d2ebf8b 4740@node Output Formats
c906108c
SS
4741@section Output formats
4742
4743@cindex formatted output
4744@cindex output formats
4745By default, @value{GDBN} prints a value according to its data type. Sometimes
4746this is not what you want. For example, you might want to print a number
4747in hex, or a pointer in decimal. Or you might want to view data in memory
4748at a certain address as a character string or as an instruction. To do
4749these things, specify an @dfn{output format} when you print a value.
4750
4751The simplest use of output formats is to say how to print a value
4752already computed. This is done by starting the arguments of the
4753@code{print} command with a slash and a format letter. The format
4754letters supported are:
4755
4756@table @code
4757@item x
4758Regard the bits of the value as an integer, and print the integer in
4759hexadecimal.
4760
4761@item d
4762Print as integer in signed decimal.
4763
4764@item u
4765Print as integer in unsigned decimal.
4766
4767@item o
4768Print as integer in octal.
4769
4770@item t
4771Print as integer in binary. The letter @samp{t} stands for ``two''.
4772@footnote{@samp{b} cannot be used because these format letters are also
4773used with the @code{x} command, where @samp{b} stands for ``byte'';
d4f3574e 4774see @ref{Memory,,Examining memory}.}
c906108c
SS
4775
4776@item a
4777@cindex unknown address, locating
3d67e040 4778@cindex locate address
c906108c
SS
4779Print as an address, both absolute in hexadecimal and as an offset from
4780the nearest preceding symbol. You can use this format used to discover
4781where (in what function) an unknown address is located:
4782
4783@example
4784(@value{GDBP}) p/a 0x54320
4785$3 = 0x54320 <_initialize_vx+396>
4786@end example
4787
3d67e040
EZ
4788@noindent
4789The command @code{info symbol 0x54320} yields similar results.
4790@xref{Symbols, info symbol}.
4791
c906108c
SS
4792@item c
4793Regard as an integer and print it as a character constant.
4794
4795@item f
4796Regard the bits of the value as a floating point number and print
4797using typical floating point syntax.
4798@end table
4799
4800For example, to print the program counter in hex (@pxref{Registers}), type
4801
4802@example
4803p/x $pc
4804@end example
4805
4806@noindent
4807Note that no space is required before the slash; this is because command
4808names in @value{GDBN} cannot contain a slash.
4809
4810To reprint the last value in the value history with a different format,
4811you can use the @code{print} command with just a format and no
4812expression. For example, @samp{p/x} reprints the last value in hex.
4813
6d2ebf8b 4814@node Memory
c906108c
SS
4815@section Examining memory
4816
4817You can use the command @code{x} (for ``examine'') to examine memory in
4818any of several formats, independently of your program's data types.
4819
4820@cindex examining memory
4821@table @code
41afff9a 4822@kindex x @r{(examine memory)}
c906108c
SS
4823@item x/@var{nfu} @var{addr}
4824@itemx x @var{addr}
4825@itemx x
4826Use the @code{x} command to examine memory.
4827@end table
4828
4829@var{n}, @var{f}, and @var{u} are all optional parameters that specify how
4830much memory to display and how to format it; @var{addr} is an
4831expression giving the address where you want to start displaying memory.
4832If you use defaults for @var{nfu}, you need not type the slash @samp{/}.
4833Several commands set convenient defaults for @var{addr}.
4834
4835@table @r
4836@item @var{n}, the repeat count
4837The repeat count is a decimal integer; the default is 1. It specifies
4838how much memory (counting by units @var{u}) to display.
4839@c This really is **decimal**; unaffected by 'set radix' as of GDB
4840@c 4.1.2.
4841
4842@item @var{f}, the display format
4843The display format is one of the formats used by @code{print},
4844@samp{s} (null-terminated string), or @samp{i} (machine instruction).
4845The default is @samp{x} (hexadecimal) initially.
4846The default changes each time you use either @code{x} or @code{print}.
4847
4848@item @var{u}, the unit size
4849The unit size is any of
4850
4851@table @code
4852@item b
4853Bytes.
4854@item h
4855Halfwords (two bytes).
4856@item w
4857Words (four bytes). This is the initial default.
4858@item g
4859Giant words (eight bytes).
4860@end table
4861
4862Each time you specify a unit size with @code{x}, that size becomes the
4863default unit the next time you use @code{x}. (For the @samp{s} and
4864@samp{i} formats, the unit size is ignored and is normally not written.)
4865
4866@item @var{addr}, starting display address
4867@var{addr} is the address where you want @value{GDBN} to begin displaying
4868memory. The expression need not have a pointer value (though it may);
4869it is always interpreted as an integer address of a byte of memory.
4870@xref{Expressions, ,Expressions}, for more information on expressions. The default for
4871@var{addr} is usually just after the last address examined---but several
4872other commands also set the default address: @code{info breakpoints} (to
4873the address of the last breakpoint listed), @code{info line} (to the
4874starting address of a line), and @code{print} (if you use it to display
4875a value from memory).
4876@end table
4877
4878For example, @samp{x/3uh 0x54320} is a request to display three halfwords
4879(@code{h}) of memory, formatted as unsigned decimal integers (@samp{u}),
4880starting at address @code{0x54320}. @samp{x/4xw $sp} prints the four
4881words (@samp{w}) of memory above the stack pointer (here, @samp{$sp};
d4f3574e 4882@pxref{Registers, ,Registers}) in hexadecimal (@samp{x}).
c906108c
SS
4883
4884Since the letters indicating unit sizes are all distinct from the
4885letters specifying output formats, you do not have to remember whether
4886unit size or format comes first; either order works. The output
4887specifications @samp{4xw} and @samp{4wx} mean exactly the same thing.
4888(However, the count @var{n} must come first; @samp{wx4} does not work.)
4889
4890Even though the unit size @var{u} is ignored for the formats @samp{s}
4891and @samp{i}, you might still want to use a count @var{n}; for example,
4892@samp{3i} specifies that you want to see three machine instructions,
4893including any operands. The command @code{disassemble} gives an
d4f3574e 4894alternative way of inspecting machine instructions; see @ref{Machine
c906108c
SS
4895Code,,Source and machine code}.
4896
4897All the defaults for the arguments to @code{x} are designed to make it
4898easy to continue scanning memory with minimal specifications each time
4899you use @code{x}. For example, after you have inspected three machine
4900instructions with @samp{x/3i @var{addr}}, you can inspect the next seven
4901with just @samp{x/7}. If you use @key{RET} to repeat the @code{x} command,
4902the repeat count @var{n} is used again; the other arguments default as
4903for successive uses of @code{x}.
4904
4905@cindex @code{$_}, @code{$__}, and value history
4906The addresses and contents printed by the @code{x} command are not saved
4907in the value history because there is often too much of them and they
4908would get in the way. Instead, @value{GDBN} makes these values available for
4909subsequent use in expressions as values of the convenience variables
4910@code{$_} and @code{$__}. After an @code{x} command, the last address
4911examined is available for use in expressions in the convenience variable
4912@code{$_}. The contents of that address, as examined, are available in
4913the convenience variable @code{$__}.
4914
4915If the @code{x} command has a repeat count, the address and contents saved
4916are from the last memory unit printed; this is not the same as the last
4917address printed if several units were printed on the last line of output.
4918
6d2ebf8b 4919@node Auto Display
c906108c
SS
4920@section Automatic display
4921@cindex automatic display
4922@cindex display of expressions
4923
4924If you find that you want to print the value of an expression frequently
4925(to see how it changes), you might want to add it to the @dfn{automatic
4926display list} so that @value{GDBN} prints its value each time your program stops.
4927Each expression added to the list is given a number to identify it;
4928to remove an expression from the list, you specify that number.
4929The automatic display looks like this:
4930
4931@example
49322: foo = 38
49333: bar[5] = (struct hack *) 0x3804
4934@end example
4935
4936@noindent
4937This display shows item numbers, expressions and their current values. As with
4938displays you request manually using @code{x} or @code{print}, you can
4939specify the output format you prefer; in fact, @code{display} decides
4940whether to use @code{print} or @code{x} depending on how elaborate your
4941format specification is---it uses @code{x} if you specify a unit size,
4942or one of the two formats (@samp{i} and @samp{s}) that are only
4943supported by @code{x}; otherwise it uses @code{print}.
4944
4945@table @code
4946@kindex display
d4f3574e
SS
4947@item display @var{expr}
4948Add the expression @var{expr} to the list of expressions to display
c906108c
SS
4949each time your program stops. @xref{Expressions, ,Expressions}.
4950
4951@code{display} does not repeat if you press @key{RET} again after using it.
4952
d4f3574e 4953@item display/@var{fmt} @var{expr}
c906108c 4954For @var{fmt} specifying only a display format and not a size or
d4f3574e 4955count, add the expression @var{expr} to the auto-display list but
c906108c
SS
4956arrange to display it each time in the specified format @var{fmt}.
4957@xref{Output Formats,,Output formats}.
4958
4959@item display/@var{fmt} @var{addr}
4960For @var{fmt} @samp{i} or @samp{s}, or including a unit-size or a
4961number of units, add the expression @var{addr} as a memory address to
4962be examined each time your program stops. Examining means in effect
4963doing @samp{x/@var{fmt} @var{addr}}. @xref{Memory, ,Examining memory}.
4964@end table
4965
4966For example, @samp{display/i $pc} can be helpful, to see the machine
4967instruction about to be executed each time execution stops (@samp{$pc}
d4f3574e 4968is a common name for the program counter; @pxref{Registers, ,Registers}).
c906108c
SS
4969
4970@table @code
4971@kindex delete display
4972@kindex undisplay
4973@item undisplay @var{dnums}@dots{}
4974@itemx delete display @var{dnums}@dots{}
4975Remove item numbers @var{dnums} from the list of expressions to display.
4976
4977@code{undisplay} does not repeat if you press @key{RET} after using it.
4978(Otherwise you would just get the error @samp{No display number @dots{}}.)
4979
4980@kindex disable display
4981@item disable display @var{dnums}@dots{}
4982Disable the display of item numbers @var{dnums}. A disabled display
4983item is not printed automatically, but is not forgotten. It may be
4984enabled again later.
4985
4986@kindex enable display
4987@item enable display @var{dnums}@dots{}
4988Enable display of item numbers @var{dnums}. It becomes effective once
4989again in auto display of its expression, until you specify otherwise.
4990
4991@item display
4992Display the current values of the expressions on the list, just as is
4993done when your program stops.
4994
4995@kindex info display
4996@item info display
4997Print the list of expressions previously set up to display
4998automatically, each one with its item number, but without showing the
4999values. This includes disabled expressions, which are marked as such.
5000It also includes expressions which would not be displayed right now
5001because they refer to automatic variables not currently available.
5002@end table
5003
5004If a display expression refers to local variables, then it does not make
5005sense outside the lexical context for which it was set up. Such an
5006expression is disabled when execution enters a context where one of its
5007variables is not defined. For example, if you give the command
5008@code{display last_char} while inside a function with an argument
5009@code{last_char}, @value{GDBN} displays this argument while your program
5010continues to stop inside that function. When it stops elsewhere---where
5011there is no variable @code{last_char}---the display is disabled
5012automatically. The next time your program stops where @code{last_char}
5013is meaningful, you can enable the display expression once again.
5014
6d2ebf8b 5015@node Print Settings
c906108c
SS
5016@section Print settings
5017
5018@cindex format options
5019@cindex print settings
5020@value{GDBN} provides the following ways to control how arrays, structures,
5021and symbols are printed.
5022
5023@noindent
5024These settings are useful for debugging programs in any language:
5025
5026@table @code
5027@kindex set print address
5028@item set print address
5029@itemx set print address on
5030@value{GDBN} prints memory addresses showing the location of stack
5031traces, structure values, pointer values, breakpoints, and so forth,
5032even when it also displays the contents of those addresses. The default
5033is @code{on}. For example, this is what a stack frame display looks like with
5034@code{set print address on}:
5035
5036@smallexample
5037@group
5038(@value{GDBP}) f
5039#0 set_quotes (lq=0x34c78 "<<", rq=0x34c88 ">>")
5040 at input.c:530
5041530 if (lquote != def_lquote)
5042@end group
5043@end smallexample
5044
5045@item set print address off
5046Do not print addresses when displaying their contents. For example,
5047this is the same stack frame displayed with @code{set print address off}:
5048
5049@smallexample
5050@group
5051(@value{GDBP}) set print addr off
5052(@value{GDBP}) f
5053#0 set_quotes (lq="<<", rq=">>") at input.c:530
5054530 if (lquote != def_lquote)
5055@end group
5056@end smallexample
5057
5058You can use @samp{set print address off} to eliminate all machine
5059dependent displays from the @value{GDBN} interface. For example, with
5060@code{print address off}, you should get the same text for backtraces on
5061all machines---whether or not they involve pointer arguments.
5062
5063@kindex show print address
5064@item show print address
5065Show whether or not addresses are to be printed.
5066@end table
5067
5068When @value{GDBN} prints a symbolic address, it normally prints the
5069closest earlier symbol plus an offset. If that symbol does not uniquely
5070identify the address (for example, it is a name whose scope is a single
5071source file), you may need to clarify. One way to do this is with
5072@code{info line}, for example @samp{info line *0x4537}. Alternately,
5073you can set @value{GDBN} to print the source file and line number when
5074it prints a symbolic address:
5075
5076@table @code
5077@kindex set print symbol-filename
5078@item set print symbol-filename on
5079Tell @value{GDBN} to print the source file name and line number of a
5080symbol in the symbolic form of an address.
5081
5082@item set print symbol-filename off
5083Do not print source file name and line number of a symbol. This is the
5084default.
5085
5086@kindex show print symbol-filename
5087@item show print symbol-filename
5088Show whether or not @value{GDBN} will print the source file name and
5089line number of a symbol in the symbolic form of an address.
5090@end table
5091
5092Another situation where it is helpful to show symbol filenames and line
5093numbers is when disassembling code; @value{GDBN} shows you the line
5094number and source file that corresponds to each instruction.
5095
5096Also, you may wish to see the symbolic form only if the address being
5097printed is reasonably close to the closest earlier symbol:
5098
5099@table @code
5100@kindex set print max-symbolic-offset
5101@item set print max-symbolic-offset @var{max-offset}
5102Tell @value{GDBN} to only display the symbolic form of an address if the
5103offset between the closest earlier symbol and the address is less than
5d161b24 5104@var{max-offset}. The default is 0, which tells @value{GDBN}
c906108c
SS
5105to always print the symbolic form of an address if any symbol precedes it.
5106
5107@kindex show print max-symbolic-offset
5108@item show print max-symbolic-offset
5109Ask how large the maximum offset is that @value{GDBN} prints in a
5110symbolic address.
5111@end table
5112
5113@cindex wild pointer, interpreting
5114@cindex pointer, finding referent
5115If you have a pointer and you are not sure where it points, try
5116@samp{set print symbol-filename on}. Then you can determine the name
5117and source file location of the variable where it points, using
5118@samp{p/a @var{pointer}}. This interprets the address in symbolic form.
5119For example, here @value{GDBN} shows that a variable @code{ptt} points
5120at another variable @code{t}, defined in @file{hi2.c}:
5121
5122@example
5123(@value{GDBP}) set print symbol-filename on
5124(@value{GDBP}) p/a ptt
5125$4 = 0xe008 <t in hi2.c>
5126@end example
5127
5128@quotation
5129@emph{Warning:} For pointers that point to a local variable, @samp{p/a}
5130does not show the symbol name and filename of the referent, even with
5131the appropriate @code{set print} options turned on.
5132@end quotation
5133
5134Other settings control how different kinds of objects are printed:
5135
5136@table @code
5137@kindex set print array
5138@item set print array
5139@itemx set print array on
5140Pretty print arrays. This format is more convenient to read,
5141but uses more space. The default is off.
5142
5143@item set print array off
5144Return to compressed format for arrays.
5145
5146@kindex show print array
5147@item show print array
5148Show whether compressed or pretty format is selected for displaying
5149arrays.
5150
5151@kindex set print elements
5152@item set print elements @var{number-of-elements}
5153Set a limit on how many elements of an array @value{GDBN} will print.
5154If @value{GDBN} is printing a large array, it stops printing after it has
5155printed the number of elements set by the @code{set print elements} command.
5156This limit also applies to the display of strings.
d4f3574e 5157When @value{GDBN} starts, this limit is set to 200.
c906108c
SS
5158Setting @var{number-of-elements} to zero means that the printing is unlimited.
5159
5160@kindex show print elements
5161@item show print elements
5162Display the number of elements of a large array that @value{GDBN} will print.
5163If the number is 0, then the printing is unlimited.
5164
5165@kindex set print null-stop
5166@item set print null-stop
5167Cause @value{GDBN} to stop printing the characters of an array when the first
d4f3574e 5168@sc{null} is encountered. This is useful when large arrays actually
c906108c 5169contain only short strings.
d4f3574e 5170The default is off.
c906108c
SS
5171
5172@kindex set print pretty
5173@item set print pretty on
5d161b24 5174Cause @value{GDBN} to print structures in an indented format with one member
c906108c
SS
5175per line, like this:
5176
5177@smallexample
5178@group
5179$1 = @{
5180 next = 0x0,
5181 flags = @{
5182 sweet = 1,
5183 sour = 1
5184 @},
5185 meat = 0x54 "Pork"
5186@}
5187@end group
5188@end smallexample
5189
5190@item set print pretty off
5191Cause @value{GDBN} to print structures in a compact format, like this:
5192
5193@smallexample
5194@group
5195$1 = @{next = 0x0, flags = @{sweet = 1, sour = 1@}, \
5196meat = 0x54 "Pork"@}
5197@end group
5198@end smallexample
5199
5200@noindent
5201This is the default format.
5202
5203@kindex show print pretty
5204@item show print pretty
5205Show which format @value{GDBN} is using to print structures.
5206
5207@kindex set print sevenbit-strings
5208@item set print sevenbit-strings on
5209Print using only seven-bit characters; if this option is set,
5210@value{GDBN} displays any eight-bit characters (in strings or
5211character values) using the notation @code{\}@var{nnn}. This setting is
5212best if you are working in English (@sc{ascii}) and you use the
5213high-order bit of characters as a marker or ``meta'' bit.
5214
5215@item set print sevenbit-strings off
5216Print full eight-bit characters. This allows the use of more
5217international character sets, and is the default.
5218
5219@kindex show print sevenbit-strings
5220@item show print sevenbit-strings
5221Show whether or not @value{GDBN} is printing only seven-bit characters.
5222
5223@kindex set print union
5224@item set print union on
5d161b24 5225Tell @value{GDBN} to print unions which are contained in structures. This
c906108c
SS
5226is the default setting.
5227
5228@item set print union off
5229Tell @value{GDBN} not to print unions which are contained in structures.
5230
5231@kindex show print union
5232@item show print union
5233Ask @value{GDBN} whether or not it will print unions which are contained in
5234structures.
5235
5236For example, given the declarations
5237
5238@smallexample
5239typedef enum @{Tree, Bug@} Species;
5240typedef enum @{Big_tree, Acorn, Seedling@} Tree_forms;
5d161b24 5241typedef enum @{Caterpillar, Cocoon, Butterfly@}
c906108c
SS
5242 Bug_forms;
5243
5244struct thing @{
5245 Species it;
5246 union @{
5247 Tree_forms tree;
5248 Bug_forms bug;
5249 @} form;
5250@};
5251
5252struct thing foo = @{Tree, @{Acorn@}@};
5253@end smallexample
5254
5255@noindent
5256with @code{set print union on} in effect @samp{p foo} would print
5257
5258@smallexample
5259$1 = @{it = Tree, form = @{tree = Acorn, bug = Cocoon@}@}
5260@end smallexample
5261
5262@noindent
5263and with @code{set print union off} in effect it would print
5264
5265@smallexample
5266$1 = @{it = Tree, form = @{...@}@}
5267@end smallexample
5268@end table
5269
c906108c
SS
5270@need 1000
5271@noindent
b37052ae 5272These settings are of interest when debugging C@t{++} programs:
c906108c
SS
5273
5274@table @code
5275@cindex demangling
5276@kindex set print demangle
5277@item set print demangle
5278@itemx set print demangle on
b37052ae 5279Print C@t{++} names in their source form rather than in the encoded
c906108c 5280(``mangled'') form passed to the assembler and linker for type-safe
d4f3574e 5281linkage. The default is on.
c906108c
SS
5282
5283@kindex show print demangle
5284@item show print demangle
b37052ae 5285Show whether C@t{++} names are printed in mangled or demangled form.
c906108c
SS
5286
5287@kindex set print asm-demangle
5288@item set print asm-demangle
5289@itemx set print asm-demangle on
b37052ae 5290Print C@t{++} names in their source form rather than their mangled form, even
c906108c
SS
5291in assembler code printouts such as instruction disassemblies.
5292The default is off.
5293
5294@kindex show print asm-demangle
5295@item show print asm-demangle
b37052ae 5296Show whether C@t{++} names in assembly listings are printed in mangled
c906108c
SS
5297or demangled form.
5298
5299@kindex set demangle-style
b37052ae
EZ
5300@cindex C@t{++} symbol decoding style
5301@cindex symbol decoding style, C@t{++}
c906108c
SS
5302@item set demangle-style @var{style}
5303Choose among several encoding schemes used by different compilers to
b37052ae 5304represent C@t{++} names. The choices for @var{style} are currently:
c906108c
SS
5305
5306@table @code
5307@item auto
5308Allow @value{GDBN} to choose a decoding style by inspecting your program.
5309
5310@item gnu
b37052ae 5311Decode based on the @sc{gnu} C@t{++} compiler (@code{g++}) encoding algorithm.
c906108c 5312This is the default.
c906108c
SS
5313
5314@item hp
b37052ae 5315Decode based on the HP ANSI C@t{++} (@code{aCC}) encoding algorithm.
c906108c
SS
5316
5317@item lucid
b37052ae 5318Decode based on the Lucid C@t{++} compiler (@code{lcc}) encoding algorithm.
c906108c
SS
5319
5320@item arm
b37052ae 5321Decode using the algorithm in the @cite{C@t{++} Annotated Reference Manual}.
c906108c
SS
5322@strong{Warning:} this setting alone is not sufficient to allow
5323debugging @code{cfront}-generated executables. @value{GDBN} would
5324require further enhancement to permit that.
5325
5326@end table
5327If you omit @var{style}, you will see a list of possible formats.
5328
5329@kindex show demangle-style
5330@item show demangle-style
b37052ae 5331Display the encoding style currently in use for decoding C@t{++} symbols.
c906108c
SS
5332
5333@kindex set print object
5334@item set print object
5335@itemx set print object on
5336When displaying a pointer to an object, identify the @emph{actual}
5337(derived) type of the object rather than the @emph{declared} type, using
5338the virtual function table.
5339
5340@item set print object off
5341Display only the declared type of objects, without reference to the
5342virtual function table. This is the default setting.
5343
5344@kindex show print object
5345@item show print object
5346Show whether actual, or declared, object types are displayed.
5347
5348@kindex set print static-members
5349@item set print static-members
5350@itemx set print static-members on
b37052ae 5351Print static members when displaying a C@t{++} object. The default is on.
c906108c
SS
5352
5353@item set print static-members off
b37052ae 5354Do not print static members when displaying a C@t{++} object.
c906108c
SS
5355
5356@kindex show print static-members
5357@item show print static-members
b37052ae 5358Show whether C@t{++} static members are printed, or not.
c906108c
SS
5359
5360@c These don't work with HP ANSI C++ yet.
5361@kindex set print vtbl
5362@item set print vtbl
5363@itemx set print vtbl on
b37052ae 5364Pretty print C@t{++} virtual function tables. The default is off.
c906108c 5365(The @code{vtbl} commands do not work on programs compiled with the HP
b37052ae 5366ANSI C@t{++} compiler (@code{aCC}).)
c906108c
SS
5367
5368@item set print vtbl off
b37052ae 5369Do not pretty print C@t{++} virtual function tables.
c906108c
SS
5370
5371@kindex show print vtbl
5372@item show print vtbl
b37052ae 5373Show whether C@t{++} virtual function tables are pretty printed, or not.
c906108c 5374@end table
c906108c 5375
6d2ebf8b 5376@node Value History
c906108c
SS
5377@section Value history
5378
5379@cindex value history
5d161b24
DB
5380Values printed by the @code{print} command are saved in the @value{GDBN}
5381@dfn{value history}. This allows you to refer to them in other expressions.
5382Values are kept until the symbol table is re-read or discarded
5383(for example with the @code{file} or @code{symbol-file} commands).
5384When the symbol table changes, the value history is discarded,
5385since the values may contain pointers back to the types defined in the
c906108c
SS
5386symbol table.
5387
5388@cindex @code{$}
5389@cindex @code{$$}
5390@cindex history number
5391The values printed are given @dfn{history numbers} by which you can
5392refer to them. These are successive integers starting with one.
5393@code{print} shows you the history number assigned to a value by
5394printing @samp{$@var{num} = } before the value; here @var{num} is the
5395history number.
5396
5397To refer to any previous value, use @samp{$} followed by the value's
5398history number. The way @code{print} labels its output is designed to
5399remind you of this. Just @code{$} refers to the most recent value in
5400the history, and @code{$$} refers to the value before that.
5401@code{$$@var{n}} refers to the @var{n}th value from the end; @code{$$2}
5402is the value just prior to @code{$$}, @code{$$1} is equivalent to
5403@code{$$}, and @code{$$0} is equivalent to @code{$}.
5404
5405For example, suppose you have just printed a pointer to a structure and
5406want to see the contents of the structure. It suffices to type
5407
5408@example
5409p *$
5410@end example
5411
5412If you have a chain of structures where the component @code{next} points
5413to the next one, you can print the contents of the next one with this:
5414
5415@example
5416p *$.next
5417@end example
5418
5419@noindent
5420You can print successive links in the chain by repeating this
5421command---which you can do by just typing @key{RET}.
5422
5423Note that the history records values, not expressions. If the value of
5424@code{x} is 4 and you type these commands:
5425
5426@example
5427print x
5428set x=5
5429@end example
5430
5431@noindent
5432then the value recorded in the value history by the @code{print} command
5433remains 4 even though the value of @code{x} has changed.
5434
5435@table @code
5436@kindex show values
5437@item show values
5438Print the last ten values in the value history, with their item numbers.
5439This is like @samp{p@ $$9} repeated ten times, except that @code{show
5440values} does not change the history.
5441
5442@item show values @var{n}
5443Print ten history values centered on history item number @var{n}.
5444
5445@item show values +
5446Print ten history values just after the values last printed. If no more
5447values are available, @code{show values +} produces no display.
5448@end table
5449
5450Pressing @key{RET} to repeat @code{show values @var{n}} has exactly the
5451same effect as @samp{show values +}.
5452
6d2ebf8b 5453@node Convenience Vars
c906108c
SS
5454@section Convenience variables
5455
5456@cindex convenience variables
5457@value{GDBN} provides @dfn{convenience variables} that you can use within
5458@value{GDBN} to hold on to a value and refer to it later. These variables
5459exist entirely within @value{GDBN}; they are not part of your program, and
5460setting a convenience variable has no direct effect on further execution
5461of your program. That is why you can use them freely.
5462
5463Convenience variables are prefixed with @samp{$}. Any name preceded by
5464@samp{$} can be used for a convenience variable, unless it is one of
d4f3574e 5465the predefined machine-specific register names (@pxref{Registers, ,Registers}).
c906108c
SS
5466(Value history references, in contrast, are @emph{numbers} preceded
5467by @samp{$}. @xref{Value History, ,Value history}.)
5468
5469You can save a value in a convenience variable with an assignment
5470expression, just as you would set a variable in your program.
5471For example:
5472
5473@example
5474set $foo = *object_ptr
5475@end example
5476
5477@noindent
5478would save in @code{$foo} the value contained in the object pointed to by
5479@code{object_ptr}.
5480
5481Using a convenience variable for the first time creates it, but its
5482value is @code{void} until you assign a new value. You can alter the
5483value with another assignment at any time.
5484
5485Convenience variables have no fixed types. You can assign a convenience
5486variable any type of value, including structures and arrays, even if
5487that variable already has a value of a different type. The convenience
5488variable, when used as an expression, has the type of its current value.
5489
5490@table @code
5491@kindex show convenience
5492@item show convenience
5493Print a list of convenience variables used so far, and their values.
d4f3574e 5494Abbreviated @code{show conv}.
c906108c
SS
5495@end table
5496
5497One of the ways to use a convenience variable is as a counter to be
5498incremented or a pointer to be advanced. For example, to print
5499a field from successive elements of an array of structures:
5500
5501@example
5502set $i = 0
5503print bar[$i++]->contents
5504@end example
5505
d4f3574e
SS
5506@noindent
5507Repeat that command by typing @key{RET}.
c906108c
SS
5508
5509Some convenience variables are created automatically by @value{GDBN} and given
5510values likely to be useful.
5511
5512@table @code
41afff9a 5513@vindex $_@r{, convenience variable}
c906108c
SS
5514@item $_
5515The variable @code{$_} is automatically set by the @code{x} command to
5516the last address examined (@pxref{Memory, ,Examining memory}). Other
5517commands which provide a default address for @code{x} to examine also
5518set @code{$_} to that address; these commands include @code{info line}
5519and @code{info breakpoint}. The type of @code{$_} is @code{void *}
5520except when set by the @code{x} command, in which case it is a pointer
5521to the type of @code{$__}.
5522
41afff9a 5523@vindex $__@r{, convenience variable}
c906108c
SS
5524@item $__
5525The variable @code{$__} is automatically set by the @code{x} command
5526to the value found in the last address examined. Its type is chosen
5527to match the format in which the data was printed.
5528
5529@item $_exitcode
41afff9a 5530@vindex $_exitcode@r{, convenience variable}
c906108c
SS
5531The variable @code{$_exitcode} is automatically set to the exit code when
5532the program being debugged terminates.
5533@end table
5534
53a5351d
JM
5535On HP-UX systems, if you refer to a function or variable name that
5536begins with a dollar sign, @value{GDBN} searches for a user or system
5537name first, before it searches for a convenience variable.
c906108c 5538
6d2ebf8b 5539@node Registers
c906108c
SS
5540@section Registers
5541
5542@cindex registers
5543You can refer to machine register contents, in expressions, as variables
5544with names starting with @samp{$}. The names of registers are different
5545for each machine; use @code{info registers} to see the names used on
5546your machine.
5547
5548@table @code
5549@kindex info registers
5550@item info registers
5551Print the names and values of all registers except floating-point
5552registers (in the selected stack frame).
5553
5554@kindex info all-registers
5555@cindex floating point registers
5556@item info all-registers
5557Print the names and values of all registers, including floating-point
5558registers.
5559
5560@item info registers @var{regname} @dots{}
5561Print the @dfn{relativized} value of each specified register @var{regname}.
5d161b24
DB
5562As discussed in detail below, register values are normally relative to
5563the selected stack frame. @var{regname} may be any register name valid on
c906108c
SS
5564the machine you are using, with or without the initial @samp{$}.
5565@end table
5566
5567@value{GDBN} has four ``standard'' register names that are available (in
5568expressions) on most machines---whenever they do not conflict with an
5569architecture's canonical mnemonics for registers. The register names
5570@code{$pc} and @code{$sp} are used for the program counter register and
5571the stack pointer. @code{$fp} is used for a register that contains a
5572pointer to the current stack frame, and @code{$ps} is used for a
5573register that contains the processor status. For example,
5574you could print the program counter in hex with
5575
5576@example
5577p/x $pc
5578@end example
5579
5580@noindent
5581or print the instruction to be executed next with
5582
5583@example
5584x/i $pc
5585@end example
5586
5587@noindent
5588or add four to the stack pointer@footnote{This is a way of removing
5589one word from the stack, on machines where stacks grow downward in
5590memory (most machines, nowadays). This assumes that the innermost
5591stack frame is selected; setting @code{$sp} is not allowed when other
5592stack frames are selected. To pop entire frames off the stack,
5593regardless of machine architecture, use @code{return};
d4f3574e 5594see @ref{Returning, ,Returning from a function}.} with
c906108c
SS
5595
5596@example
5597set $sp += 4
5598@end example
5599
5600Whenever possible, these four standard register names are available on
5601your machine even though the machine has different canonical mnemonics,
5602so long as there is no conflict. The @code{info registers} command
5603shows the canonical names. For example, on the SPARC, @code{info
5604registers} displays the processor status register as @code{$psr} but you
d4f3574e
SS
5605can also refer to it as @code{$ps}; and on x86-based machines @code{$ps}
5606is an alias for the @sc{eflags} register.
c906108c
SS
5607
5608@value{GDBN} always considers the contents of an ordinary register as an
5609integer when the register is examined in this way. Some machines have
5610special registers which can hold nothing but floating point; these
5611registers are considered to have floating point values. There is no way
5612to refer to the contents of an ordinary register as floating point value
5613(although you can @emph{print} it as a floating point value with
5614@samp{print/f $@var{regname}}).
5615
5616Some registers have distinct ``raw'' and ``virtual'' data formats. This
5617means that the data format in which the register contents are saved by
5618the operating system is not the same one that your program normally
5619sees. For example, the registers of the 68881 floating point
5620coprocessor are always saved in ``extended'' (raw) format, but all C
5621programs expect to work with ``double'' (virtual) format. In such
5d161b24 5622cases, @value{GDBN} normally works with the virtual format only (the format
c906108c
SS
5623that makes sense for your program), but the @code{info registers} command
5624prints the data in both formats.
5625
5626Normally, register values are relative to the selected stack frame
5627(@pxref{Selection, ,Selecting a frame}). This means that you get the
5628value that the register would contain if all stack frames farther in
5629were exited and their saved registers restored. In order to see the
5630true contents of hardware registers, you must select the innermost
5631frame (with @samp{frame 0}).
5632
5633However, @value{GDBN} must deduce where registers are saved, from the machine
5634code generated by your compiler. If some registers are not saved, or if
5635@value{GDBN} is unable to locate the saved registers, the selected stack
5636frame makes no difference.
5637
6d2ebf8b 5638@node Floating Point Hardware
c906108c
SS
5639@section Floating point hardware
5640@cindex floating point
5641
5642Depending on the configuration, @value{GDBN} may be able to give
5643you more information about the status of the floating point hardware.
5644
5645@table @code
5646@kindex info float
5647@item info float
5648Display hardware-dependent information about the floating
5649point unit. The exact contents and layout vary depending on the
5650floating point chip. Currently, @samp{info float} is supported on
5651the ARM and x86 machines.
5652@end table
c906108c 5653
29e57380
C
5654@node Memory Region Attributes
5655@section Memory Region Attributes
5656@cindex memory region attributes
5657
5658@dfn{Memory region attributes} allow you to describe special handling
5659required by regions of your target's memory. @value{GDBN} uses attributes
5660to determine whether to allow certain types of memory accesses; whether to
5661use specific width accesses; and whether to cache target memory.
5662
5663Defined memory regions can be individually enabled and disabled. When a
5664memory region is disabled, @value{GDBN} uses the default attributes when
5665accessing memory in that region. Similarly, if no memory regions have
5666been defined, @value{GDBN} uses the default attributes when accessing
5667all memory.
5668
5669When a memory region is defined, it is given a number to identify it;
5670to enable, disable, or remove a memory region, you specify that number.
5671
5672@table @code
5673@kindex mem
5674@item mem @var{address1} @var{address1} @var{attributes}@dots{}
5675Define memory region bounded by @var{address1} and @var{address2}
5676with attributes @var{attributes}@dots{}.
5677
5678@kindex delete mem
5679@item delete mem @var{nums}@dots{}
5680Remove memory region numbers @var{nums}.
5681
5682@kindex disable mem
5683@item disable mem @var{nums}@dots{}
5684Disable memory region numbers @var{nums}.
5685A disabled memory region is not forgotten.
5686It may be enabled again later.
5687
5688@kindex enable mem
5689@item enable mem @var{nums}@dots{}
5690Enable memory region numbers @var{nums}.
5691
5692@kindex info mem
5693@item info mem
5694Print a table of all defined memory regions, with the following columns
5695for each region.
5696
5697@table @emph
5698@item Memory Region Number
5699@item Enabled or Disabled.
5700Enabled memory regions are marked with @samp{y}.
5701Disabled memory regions are marked with @samp{n}.
5702
5703@item Lo Address
5704The address defining the inclusive lower bound of the memory region.
5705
5706@item Hi Address
5707The address defining the exclusive upper bound of the memory region.
5708
5709@item Attributes
5710The list of attributes set for this memory region.
5711@end table
5712@end table
5713
5714
5715@subsection Attributes
5716
5717@subsubsection Memory Access Mode
5718The access mode attributes set whether @value{GDBN} may make read or
5719write accesses to a memory region.
5720
5721While these attributes prevent @value{GDBN} from performing invalid
5722memory accesses, they do nothing to prevent the target system, I/O DMA,
5723etc. from accessing memory.
5724
5725@table @code
5726@item ro
5727Memory is read only.
5728@item wo
5729Memory is write only.
5730@item rw
5731Memory is read/write (default).
5732@end table
5733
5734@subsubsection Memory Access Size
5735The acccess size attributes tells @value{GDBN} to use specific sized
5736accesses in the memory region. Often memory mapped device registers
5737require specific sized accesses. If no access size attribute is
5738specified, @value{GDBN} may use accesses of any size.
5739
5740@table @code
5741@item 8
5742Use 8 bit memory accesses.
5743@item 16
5744Use 16 bit memory accesses.
5745@item 32
5746Use 32 bit memory accesses.
5747@item 64
5748Use 64 bit memory accesses.
5749@end table
5750
5751@c @subsubsection Hardware/Software Breakpoints
5752@c The hardware/software breakpoint attributes set whether @value{GDBN}
5753@c will use hardware or software breakpoints for the internal breakpoints
5754@c used by the step, next, finish, until, etc. commands.
5755@c
5756@c @table @code
5757@c @item hwbreak
5758@c Always use hardware breakpoints
5759@c @item swbreak (default)
5760@c @end table
5761
5762@subsubsection Data Cache
5763The data cache attributes set whether @value{GDBN} will cache target
5764memory. While this generally improves performance by reducing debug
5765protocol overhead, it can lead to incorrect results because @value{GDBN}
5766does not know about volatile variables or memory mapped device
5767registers.
5768
5769@table @code
5770@item cache
5771Enable @value{GDBN} to cache target memory.
5772@item nocache (default)
5773Disable @value{GDBN} from caching target memory.
5774@end table
5775
5776@c @subsubsection Memory Write Verification
5777@c The memory write verification attributes set whether @value{GDBN}
5778@c will re-reads data after each write to verify the write was successful.
5779@c
5780@c @table @code
5781@c @item verify
5782@c @item noverify (default)
5783@c @end table
5784
b37052ae
EZ
5785@node Tracepoints
5786@chapter Tracepoints
5787@c This chapter is based on the documentation written by Michael
5788@c Snyder, David Taylor, Jim Blandy, and Elena Zannoni.
5789
5790@cindex tracepoints
5791In some applications, it is not feasible for the debugger to interrupt
5792the program's execution long enough for the developer to learn
5793anything helpful about its behavior. If the program's correctness
5794depends on its real-time behavior, delays introduced by a debugger
5795might cause the program to change its behavior drastically, or perhaps
5796fail, even when the code itself is correct. It is useful to be able
5797to observe the program's behavior without interrupting it.
5798
5799Using @value{GDBN}'s @code{trace} and @code{collect} commands, you can
5800specify locations in the program, called @dfn{tracepoints}, and
5801arbitrary expressions to evaluate when those tracepoints are reached.
5802Later, using the @code{tfind} command, you can examine the values
5803those expressions had when the program hit the tracepoints. The
5804expressions may also denote objects in memory---structures or arrays,
5805for example---whose values @value{GDBN} should record; while visiting
5806a particular tracepoint, you may inspect those objects as if they were
5807in memory at that moment. However, because @value{GDBN} records these
5808values without interacting with you, it can do so quickly and
5809unobtrusively, hopefully not disturbing the program's behavior.
5810
5811The tracepoint facility is currently available only for remote
2c0069bb
EZ
5812targets. @xref{Targets}. In addition, your remote target must know how
5813to collect trace data. This functionality is implemented in the remote
5814stub; however, none of the stubs distributed with @value{GDBN} support
5815tracepoints as of this writing.
b37052ae
EZ
5816
5817This chapter describes the tracepoint commands and features.
5818
5819@menu
5820* Set Tracepoints::
5821* Analyze Collected Data::
5822* Tracepoint Variables::
5823@end menu
5824
5825@node Set Tracepoints
5826@section Commands to Set Tracepoints
5827
5828Before running such a @dfn{trace experiment}, an arbitrary number of
5829tracepoints can be set. Like a breakpoint (@pxref{Set Breaks}), a
5830tracepoint has a number assigned to it by @value{GDBN}. Like with
5831breakpoints, tracepoint numbers are successive integers starting from
5832one. Many of the commands associated with tracepoints take the
5833tracepoint number as their argument, to identify which tracepoint to
5834work on.
5835
5836For each tracepoint, you can specify, in advance, some arbitrary set
5837of data that you want the target to collect in the trace buffer when
5838it hits that tracepoint. The collected data can include registers,
5839local variables, or global data. Later, you can use @value{GDBN}
5840commands to examine the values these data had at the time the
5841tracepoint was hit.
5842
5843This section describes commands to set tracepoints and associated
5844conditions and actions.
5845
5846@menu
5847* Create and Delete Tracepoints::
5848* Enable and Disable Tracepoints::
5849* Tracepoint Passcounts::
5850* Tracepoint Actions::
5851* Listing Tracepoints::
5852* Starting and Stopping Trace Experiment::
5853@end menu
5854
5855@node Create and Delete Tracepoints
5856@subsection Create and Delete Tracepoints
5857
5858@table @code
5859@cindex set tracepoint
5860@kindex trace
5861@item trace
5862The @code{trace} command is very similar to the @code{break} command.
5863Its argument can be a source line, a function name, or an address in
5864the target program. @xref{Set Breaks}. The @code{trace} command
5865defines a tracepoint, which is a point in the target program where the
5866debugger will briefly stop, collect some data, and then allow the
5867program to continue. Setting a tracepoint or changing its commands
5868doesn't take effect until the next @code{tstart} command; thus, you
5869cannot change the tracepoint attributes once a trace experiment is
5870running.
5871
5872Here are some examples of using the @code{trace} command:
5873
5874@smallexample
5875(@value{GDBP}) @b{trace foo.c:121} // a source file and line number
5876
5877(@value{GDBP}) @b{trace +2} // 2 lines forward
5878
5879(@value{GDBP}) @b{trace my_function} // first source line of function
5880
5881(@value{GDBP}) @b{trace *my_function} // EXACT start address of function
5882
5883(@value{GDBP}) @b{trace *0x2117c4} // an address
5884@end smallexample
5885
5886@noindent
5887You can abbreviate @code{trace} as @code{tr}.
5888
5889@vindex $tpnum
5890@cindex last tracepoint number
5891@cindex recent tracepoint number
5892@cindex tracepoint number
5893The convenience variable @code{$tpnum} records the tracepoint number
5894of the most recently set tracepoint.
5895
5896@kindex delete tracepoint
5897@cindex tracepoint deletion
5898@item delete tracepoint @r{[}@var{num}@r{]}
5899Permanently delete one or more tracepoints. With no argument, the
5900default is to delete all tracepoints.
5901
5902Examples:
5903
5904@smallexample
5905(@value{GDBP}) @b{delete trace 1 2 3} // remove three tracepoints
5906
5907(@value{GDBP}) @b{delete trace} // remove all tracepoints
5908@end smallexample
5909
5910@noindent
5911You can abbreviate this command as @code{del tr}.
5912@end table
5913
5914@node Enable and Disable Tracepoints
5915@subsection Enable and Disable Tracepoints
5916
5917@table @code
5918@kindex disable tracepoint
5919@item disable tracepoint @r{[}@var{num}@r{]}
5920Disable tracepoint @var{num}, or all tracepoints if no argument
5921@var{num} is given. A disabled tracepoint will have no effect during
5922the next trace experiment, but it is not forgotten. You can re-enable
5923a disabled tracepoint using the @code{enable tracepoint} command.
5924
5925@kindex enable tracepoint
5926@item enable tracepoint @r{[}@var{num}@r{]}
5927Enable tracepoint @var{num}, or all tracepoints. The enabled
5928tracepoints will become effective the next time a trace experiment is
5929run.
5930@end table
5931
5932@node Tracepoint Passcounts
5933@subsection Tracepoint Passcounts
5934
5935@table @code
5936@kindex passcount
5937@cindex tracepoint pass count
5938@item passcount @r{[}@var{n} @r{[}@var{num}@r{]]}
5939Set the @dfn{passcount} of a tracepoint. The passcount is a way to
5940automatically stop a trace experiment. If a tracepoint's passcount is
5941@var{n}, then the trace experiment will be automatically stopped on
5942the @var{n}'th time that tracepoint is hit. If the tracepoint number
5943@var{num} is not specified, the @code{passcount} command sets the
5944passcount of the most recently defined tracepoint. If no passcount is
5945given, the trace experiment will run until stopped explicitly by the
5946user.
5947
5948Examples:
5949
5950@smallexample
5951(@value{GDBP}) @b{passcount 5 2} // Stop on the 5th execution of tracepoint 2
5952
5953(@value{GDBP}) @b{passcount 12} // Stop on the 12th execution of the
5954 // most recently defined tracepoint.
5955(@value{GDBP}) @b{trace foo}
5956(@value{GDBP}) @b{pass 3}
5957(@value{GDBP}) @b{trace bar}
5958(@value{GDBP}) @b{pass 2}
5959(@value{GDBP}) @b{trace baz}
5960(@value{GDBP}) @b{pass 1} // Stop tracing when foo has been
5961 // executed 3 times OR when bar has
5962 // been executed 2 times
5963 // OR when baz has been executed 1 time.
5964@end smallexample
5965@end table
5966
5967@node Tracepoint Actions
5968@subsection Tracepoint Action Lists
5969
5970@table @code
5971@kindex actions
5972@cindex tracepoint actions
5973@item actions @r{[}@var{num}@r{]}
5974This command will prompt for a list of actions to be taken when the
5975tracepoint is hit. If the tracepoint number @var{num} is not
5976specified, this command sets the actions for the one that was most
5977recently defined (so that you can define a tracepoint and then say
5978@code{actions} without bothering about its number). You specify the
5979actions themselves on the following lines, one action at a time, and
5980terminate the actions list with a line containing just @code{end}. So
5981far, the only defined actions are @code{collect} and
5982@code{while-stepping}.
5983
5984@cindex remove actions from a tracepoint
5985To remove all actions from a tracepoint, type @samp{actions @var{num}}
5986and follow it immediately with @samp{end}.
5987
5988@smallexample
5989(@value{GDBP}) @b{collect @var{data}} // collect some data
5990
5991(@value{GDBP}) @b{while-stepping 5} // single-step 5 times and collect data
5992
5993(@value{GDBP}) @b{end} // signals the end of actions.
5994@end smallexample
5995
5996In the following example, the action list begins with @code{collect}
5997commands indicating the things to be collected when the tracepoint is
5998hit. Then, in order to single-step and collect additional data
5999following the tracepoint, a @code{while-stepping} command is used,
6000followed by the list of things to be collected while stepping. The
6001@code{while-stepping} command is terminated by its own separate
6002@code{end} command. Lastly, the action list is terminated by an
6003@code{end} command.
6004
6005@smallexample
6006(@value{GDBP}) @b{trace foo}
6007(@value{GDBP}) @b{actions}
6008Enter actions for tracepoint 1, one per line:
6009> collect bar,baz
6010> collect $regs
6011> while-stepping 12
6012 > collect $fp, $sp
6013 > end
6014end
6015@end smallexample
6016
6017@kindex collect @r{(tracepoints)}
6018@item collect @var{expr1}, @var{expr2}, @dots{}
6019Collect values of the given expressions when the tracepoint is hit.
6020This command accepts a comma-separated list of any valid expressions.
6021In addition to global, static, or local variables, the following
6022special arguments are supported:
6023
6024@table @code
6025@item $regs
6026collect all registers
6027
6028@item $args
6029collect all function arguments
6030
6031@item $locals
6032collect all local variables.
6033@end table
6034
6035You can give several consecutive @code{collect} commands, each one
6036with a single argument, or one @code{collect} command with several
6037arguments separated by commas: the effect is the same.
6038
f5c37c66
EZ
6039The command @code{info scope} (@pxref{Symbols, info scope}) is
6040particularly useful for figuring out what data to collect.
6041
b37052ae
EZ
6042@kindex while-stepping @r{(tracepoints)}
6043@item while-stepping @var{n}
6044Perform @var{n} single-step traces after the tracepoint, collecting
6045new data at each step. The @code{while-stepping} command is
6046followed by the list of what to collect while stepping (followed by
6047its own @code{end} command):
6048
6049@smallexample
6050> while-stepping 12
6051 > collect $regs, myglobal
6052 > end
6053>
6054@end smallexample
6055
6056@noindent
6057You may abbreviate @code{while-stepping} as @code{ws} or
6058@code{stepping}.
6059@end table
6060
6061@node Listing Tracepoints
6062@subsection Listing Tracepoints
6063
6064@table @code
6065@kindex info tracepoints
6066@cindex information about tracepoints
6067@item info tracepoints @r{[}@var{num}@r{]}
6068Display information the tracepoint @var{num}. If you don't specify a
6069tracepoint number displays information about all the tracepoints
6070defined so far. For each tracepoint, the following information is
6071shown:
6072
6073@itemize @bullet
6074@item
6075its number
6076@item
6077whether it is enabled or disabled
6078@item
6079its address
6080@item
6081its passcount as given by the @code{passcount @var{n}} command
6082@item
6083its step count as given by the @code{while-stepping @var{n}} command
6084@item
6085where in the source files is the tracepoint set
6086@item
6087its action list as given by the @code{actions} command
6088@end itemize
6089
6090@smallexample
6091(@value{GDBP}) @b{info trace}
6092Num Enb Address PassC StepC What
60931 y 0x002117c4 0 0 <gdb_asm>
60942 y 0x0020dc64 0 0 in gdb_test at gdb_test.c:375
60953 y 0x0020b1f4 0 0 in collect_data at ../foo.c:1741
6096(@value{GDBP})
6097@end smallexample
6098
6099@noindent
6100This command can be abbreviated @code{info tp}.
6101@end table
6102
6103@node Starting and Stopping Trace Experiment
6104@subsection Starting and Stopping Trace Experiment
6105
6106@table @code
6107@kindex tstart
6108@cindex start a new trace experiment
6109@cindex collected data discarded
6110@item tstart
6111This command takes no arguments. It starts the trace experiment, and
6112begins collecting data. This has the side effect of discarding all
6113the data collected in the trace buffer during the previous trace
6114experiment.
6115
6116@kindex tstop
6117@cindex stop a running trace experiment
6118@item tstop
6119This command takes no arguments. It ends the trace experiment, and
6120stops collecting data.
6121
6122@strong{Note:} a trace experiment and data collection may stop
6123automatically if any tracepoint's passcount is reached
6124(@pxref{Tracepoint Passcounts}), or if the trace buffer becomes full.
6125
6126@kindex tstatus
6127@cindex status of trace data collection
6128@cindex trace experiment, status of
6129@item tstatus
6130This command displays the status of the current trace data
6131collection.
6132@end table
6133
6134Here is an example of the commands we described so far:
6135
6136@smallexample
6137(@value{GDBP}) @b{trace gdb_c_test}
6138(@value{GDBP}) @b{actions}
6139Enter actions for tracepoint #1, one per line.
6140> collect $regs,$locals,$args
6141> while-stepping 11
6142 > collect $regs
6143 > end
6144> end
6145(@value{GDBP}) @b{tstart}
6146 [time passes @dots{}]
6147(@value{GDBP}) @b{tstop}
6148@end smallexample
6149
6150
6151@node Analyze Collected Data
6152@section Using the collected data
6153
6154After the tracepoint experiment ends, you use @value{GDBN} commands
6155for examining the trace data. The basic idea is that each tracepoint
6156collects a trace @dfn{snapshot} every time it is hit and another
6157snapshot every time it single-steps. All these snapshots are
6158consecutively numbered from zero and go into a buffer, and you can
6159examine them later. The way you examine them is to @dfn{focus} on a
6160specific trace snapshot. When the remote stub is focused on a trace
6161snapshot, it will respond to all @value{GDBN} requests for memory and
6162registers by reading from the buffer which belongs to that snapshot,
6163rather than from @emph{real} memory or registers of the program being
6164debugged. This means that @strong{all} @value{GDBN} commands
6165(@code{print}, @code{info registers}, @code{backtrace}, etc.) will
6166behave as if we were currently debugging the program state as it was
6167when the tracepoint occurred. Any requests for data that are not in
6168the buffer will fail.
6169
6170@menu
6171* tfind:: How to select a trace snapshot
6172* tdump:: How to display all data for a snapshot
6173* save-tracepoints:: How to save tracepoints for a future run
6174@end menu
6175
6176@node tfind
6177@subsection @code{tfind @var{n}}
6178
6179@kindex tfind
6180@cindex select trace snapshot
6181@cindex find trace snapshot
6182The basic command for selecting a trace snapshot from the buffer is
6183@code{tfind @var{n}}, which finds trace snapshot number @var{n},
6184counting from zero. If no argument @var{n} is given, the next
6185snapshot is selected.
6186
6187Here are the various forms of using the @code{tfind} command.
6188
6189@table @code
6190@item tfind start
6191Find the first snapshot in the buffer. This is a synonym for
6192@code{tfind 0} (since 0 is the number of the first snapshot).
6193
6194@item tfind none
6195Stop debugging trace snapshots, resume @emph{live} debugging.
6196
6197@item tfind end
6198Same as @samp{tfind none}.
6199
6200@item tfind
6201No argument means find the next trace snapshot.
6202
6203@item tfind -
6204Find the previous trace snapshot before the current one. This permits
6205retracing earlier steps.
6206
6207@item tfind tracepoint @var{num}
6208Find the next snapshot associated with tracepoint @var{num}. Search
6209proceeds forward from the last examined trace snapshot. If no
6210argument @var{num} is given, it means find the next snapshot collected
6211for the same tracepoint as the current snapshot.
6212
6213@item tfind pc @var{addr}
6214Find the next snapshot associated with the value @var{addr} of the
6215program counter. Search proceeds forward from the last examined trace
6216snapshot. If no argument @var{addr} is given, it means find the next
6217snapshot with the same value of PC as the current snapshot.
6218
6219@item tfind outside @var{addr1}, @var{addr2}
6220Find the next snapshot whose PC is outside the given range of
6221addresses.
6222
6223@item tfind range @var{addr1}, @var{addr2}
6224Find the next snapshot whose PC is between @var{addr1} and
6225@var{addr2}. @c FIXME: Is the range inclusive or exclusive?
6226
6227@item tfind line @r{[}@var{file}:@r{]}@var{n}
6228Find the next snapshot associated with the source line @var{n}. If
6229the optional argument @var{file} is given, refer to line @var{n} in
6230that source file. Search proceeds forward from the last examined
6231trace snapshot. If no argument @var{n} is given, it means find the
6232next line other than the one currently being examined; thus saying
6233@code{tfind line} repeatedly can appear to have the same effect as
6234stepping from line to line in a @emph{live} debugging session.
6235@end table
6236
6237The default arguments for the @code{tfind} commands are specifically
6238designed to make it easy to scan through the trace buffer. For
6239instance, @code{tfind} with no argument selects the next trace
6240snapshot, and @code{tfind -} with no argument selects the previous
6241trace snapshot. So, by giving one @code{tfind} command, and then
6242simply hitting @key{RET} repeatedly you can examine all the trace
6243snapshots in order. Or, by saying @code{tfind -} and then hitting
6244@key{RET} repeatedly you can examine the snapshots in reverse order.
6245The @code{tfind line} command with no argument selects the snapshot
6246for the next source line executed. The @code{tfind pc} command with
6247no argument selects the next snapshot with the same program counter
6248(PC) as the current frame. The @code{tfind tracepoint} command with
6249no argument selects the next trace snapshot collected by the same
6250tracepoint as the current one.
6251
6252In addition to letting you scan through the trace buffer manually,
6253these commands make it easy to construct @value{GDBN} scripts that
6254scan through the trace buffer and print out whatever collected data
6255you are interested in. Thus, if we want to examine the PC, FP, and SP
6256registers from each trace frame in the buffer, we can say this:
6257
6258@smallexample
6259(@value{GDBP}) @b{tfind start}
6260(@value{GDBP}) @b{while ($trace_frame != -1)}
6261> printf "Frame %d, PC = %08X, SP = %08X, FP = %08X\n", \
6262 $trace_frame, $pc, $sp, $fp
6263> tfind
6264> end
6265
6266Frame 0, PC = 0020DC64, SP = 0030BF3C, FP = 0030BF44
6267Frame 1, PC = 0020DC6C, SP = 0030BF38, FP = 0030BF44
6268Frame 2, PC = 0020DC70, SP = 0030BF34, FP = 0030BF44
6269Frame 3, PC = 0020DC74, SP = 0030BF30, FP = 0030BF44
6270Frame 4, PC = 0020DC78, SP = 0030BF2C, FP = 0030BF44
6271Frame 5, PC = 0020DC7C, SP = 0030BF28, FP = 0030BF44
6272Frame 6, PC = 0020DC80, SP = 0030BF24, FP = 0030BF44
6273Frame 7, PC = 0020DC84, SP = 0030BF20, FP = 0030BF44
6274Frame 8, PC = 0020DC88, SP = 0030BF1C, FP = 0030BF44
6275Frame 9, PC = 0020DC8E, SP = 0030BF18, FP = 0030BF44
6276Frame 10, PC = 00203F6C, SP = 0030BE3C, FP = 0030BF14
6277@end smallexample
6278
6279Or, if we want to examine the variable @code{X} at each source line in
6280the buffer:
6281
6282@smallexample
6283(@value{GDBP}) @b{tfind start}
6284(@value{GDBP}) @b{while ($trace_frame != -1)}
6285> printf "Frame %d, X == %d\n", $trace_frame, X
6286> tfind line
6287> end
6288
6289Frame 0, X = 1
6290Frame 7, X = 2
6291Frame 13, X = 255
6292@end smallexample
6293
6294@node tdump
6295@subsection @code{tdump}
6296@kindex tdump
6297@cindex dump all data collected at tracepoint
6298@cindex tracepoint data, display
6299
6300This command takes no arguments. It prints all the data collected at
6301the current trace snapshot.
6302
6303@smallexample
6304(@value{GDBP}) @b{trace 444}
6305(@value{GDBP}) @b{actions}
6306Enter actions for tracepoint #2, one per line:
6307> collect $regs, $locals, $args, gdb_long_test
6308> end
6309
6310(@value{GDBP}) @b{tstart}
6311
6312(@value{GDBP}) @b{tfind line 444}
6313#0 gdb_test (p1=0x11, p2=0x22, p3=0x33, p4=0x44, p5=0x55, p6=0x66)
6314at gdb_test.c:444
6315444 printp( "%s: arguments = 0x%X 0x%X 0x%X 0x%X 0x%X 0x%X\n", )
6316
6317(@value{GDBP}) @b{tdump}
6318Data collected at tracepoint 2, trace frame 1:
6319d0 0xc4aa0085 -995491707
6320d1 0x18 24
6321d2 0x80 128
6322d3 0x33 51
6323d4 0x71aea3d 119204413
6324d5 0x22 34
6325d6 0xe0 224
6326d7 0x380035 3670069
6327a0 0x19e24a 1696330
6328a1 0x3000668 50333288
6329a2 0x100 256
6330a3 0x322000 3284992
6331a4 0x3000698 50333336
6332a5 0x1ad3cc 1758156
6333fp 0x30bf3c 0x30bf3c
6334sp 0x30bf34 0x30bf34
6335ps 0x0 0
6336pc 0x20b2c8 0x20b2c8
6337fpcontrol 0x0 0
6338fpstatus 0x0 0
6339fpiaddr 0x0 0
6340p = 0x20e5b4 "gdb-test"
6341p1 = (void *) 0x11
6342p2 = (void *) 0x22
6343p3 = (void *) 0x33
6344p4 = (void *) 0x44
6345p5 = (void *) 0x55
6346p6 = (void *) 0x66
6347gdb_long_test = 17 '\021'
6348
6349(@value{GDBP})
6350@end smallexample
6351
6352@node save-tracepoints
6353@subsection @code{save-tracepoints @var{filename}}
6354@kindex save-tracepoints
6355@cindex save tracepoints for future sessions
6356
6357This command saves all current tracepoint definitions together with
6358their actions and passcounts, into a file @file{@var{filename}}
6359suitable for use in a later debugging session. To read the saved
6360tracepoint definitions, use the @code{source} command (@pxref{Command
6361Files}).
6362
6363@node Tracepoint Variables
6364@section Convenience Variables for Tracepoints
6365@cindex tracepoint variables
6366@cindex convenience variables for tracepoints
6367
6368@table @code
6369@vindex $trace_frame
6370@item (int) $trace_frame
6371The current trace snapshot (a.k.a.@: @dfn{frame}) number, or -1 if no
6372snapshot is selected.
6373
6374@vindex $tracepoint
6375@item (int) $tracepoint
6376The tracepoint for the current trace snapshot.
6377
6378@vindex $trace_line
6379@item (int) $trace_line
6380The line number for the current trace snapshot.
6381
6382@vindex $trace_file
6383@item (char []) $trace_file
6384The source file for the current trace snapshot.
6385
6386@vindex $trace_func
6387@item (char []) $trace_func
6388The name of the function containing @code{$tracepoint}.
6389@end table
6390
6391Note: @code{$trace_file} is not suitable for use in @code{printf},
6392use @code{output} instead.
6393
6394Here's a simple example of using these convenience variables for
6395stepping through all the trace snapshots and printing some of their
6396data.
6397
6398@smallexample
6399(@value{GDBP}) @b{tfind start}
6400
6401(@value{GDBP}) @b{while $trace_frame != -1}
6402> output $trace_file
6403> printf ", line %d (tracepoint #%d)\n", $trace_line, $tracepoint
6404> tfind
6405> end
6406@end smallexample
6407
df0cd8c5
JB
6408@node Overlays
6409@chapter Debugging Programs That Use Overlays
6410@cindex overlays
6411
6412If your program is too large to fit completely in your target system's
6413memory, you can sometimes use @dfn{overlays} to work around this
6414problem. @value{GDBN} provides some support for debugging programs that
6415use overlays.
6416
6417@menu
6418* How Overlays Work:: A general explanation of overlays.
6419* Overlay Commands:: Managing overlays in @value{GDBN}.
6420* Automatic Overlay Debugging:: @value{GDBN} can find out which overlays are
6421 mapped by asking the inferior.
6422* Overlay Sample Program:: A sample program using overlays.
6423@end menu
6424
6425@node How Overlays Work
6426@section How Overlays Work
6427@cindex mapped overlays
6428@cindex unmapped overlays
6429@cindex load address, overlay's
6430@cindex mapped address
6431@cindex overlay area
6432
6433Suppose you have a computer whose instruction address space is only 64
6434kilobytes long, but which has much more memory which can be accessed by
6435other means: special instructions, segment registers, or memory
6436management hardware, for example. Suppose further that you want to
6437adapt a program which is larger than 64 kilobytes to run on this system.
6438
6439One solution is to identify modules of your program which are relatively
6440independent, and need not call each other directly; call these modules
6441@dfn{overlays}. Separate the overlays from the main program, and place
6442their machine code in the larger memory. Place your main program in
6443instruction memory, but leave at least enough space there to hold the
6444largest overlay as well.
6445
6446Now, to call a function located in an overlay, you must first copy that
6447overlay's machine code from the large memory into the space set aside
6448for it in the instruction memory, and then jump to its entry point
6449there.
6450
6451@example
6452@group
6453 Data Instruction Larger
6454Address Space Address Space Address Space
6455+-----------+ +-----------+ +-----------+
6456| | | | | |
6457+-----------+ +-----------+ +-----------+<-- overlay 1
6458| program | | main | | | load address
6459| variables | | program | | overlay 1 |
6460| and heap | | | ,---| |
6461+-----------+ | | | | |
6462| | +-----------+ | +-----------+
6463+-----------+ | | | | |
6464 mapped --->+-----------+ / +-----------+<-- overlay 2
6465 address | overlay | <-' | overlay 2 | load address
6466 | area | <-----| |
6467 | | <---. +-----------+
6468 | | | | |
6469 +-----------+ | | |
6470 | | | +-----------+<-- overlay 3
6471 +-----------+ `--| | load address
6472 | overlay 3 |
6473 | |
6474 +-----------+
6475 | |
6476 +-----------+
6477
6478 To map an overlay, copy its code from the larger address space
6479 to the instruction address space. Since the overlays shown here
6480 all use the same mapped address, only one may be mapped at a time.
6481@end group
6482@end example
6483
6484This diagram shows a system with separate data and instruction address
6485spaces. For a system with a single address space for data and
6486instructions, the diagram would be similar, except that the program
6487variables and heap would share an address space with the main program
6488and the overlay area.
6489
6490An overlay loaded into instruction memory and ready for use is called a
6491@dfn{mapped} overlay; its @dfn{mapped address} is its address in the
6492instruction memory. An overlay not present (or only partially present)
6493in instruction memory is called @dfn{unmapped}; its @dfn{load address}
6494is its address in the larger memory. The mapped address is also called
6495the @dfn{virtual memory address}, or @dfn{VMA}; the load address is also
6496called the @dfn{load memory address}, or @dfn{LMA}.
6497
6498Unfortunately, overlays are not a completely transparent way to adapt a
6499program to limited instruction memory. They introduce a new set of
6500global constraints you must keep in mind as you design your program:
6501
6502@itemize @bullet
6503
6504@item
6505Before calling or returning to a function in an overlay, your program
6506must make sure that overlay is actually mapped. Otherwise, the call or
6507return will transfer control to the right address, but in the wrong
6508overlay, and your program will probably crash.
6509
6510@item
6511If the process of mapping an overlay is expensive on your system, you
6512will need to choose your overlays carefully to minimize their effect on
6513your program's performance.
6514
6515@item
6516The executable file you load onto your system must contain each
6517overlay's instructions, appearing at the overlay's load address, not its
6518mapped address. However, each overlay's instructions must be relocated
6519and its symbols defined as if the overlay were at its mapped address.
6520You can use GNU linker scripts to specify different load and relocation
6521addresses for pieces of your program; see @ref{Overlay Description,,,
6522ld.info, Using ld: the GNU linker}.
6523
6524@item
6525The procedure for loading executable files onto your system must be able
6526to load their contents into the larger address space as well as the
6527instruction and data spaces.
6528
6529@end itemize
6530
6531The overlay system described above is rather simple, and could be
6532improved in many ways:
6533
6534@itemize @bullet
6535
6536@item
6537If your system has suitable bank switch registers or memory management
6538hardware, you could use those facilities to make an overlay's load area
6539contents simply appear at their mapped address in instruction space.
6540This would probably be faster than copying the overlay to its mapped
6541area in the usual way.
6542
6543@item
6544If your overlays are small enough, you could set aside more than one
6545overlay area, and have more than one overlay mapped at a time.
6546
6547@item
6548You can use overlays to manage data, as well as instructions. In
6549general, data overlays are even less transparent to your design than
6550code overlays: whereas code overlays only require care when you call or
6551return to functions, data overlays require care every time you access
6552the data. Also, if you change the contents of a data overlay, you
6553must copy its contents back out to its load address before you can copy a
6554different data overlay into the same mapped area.
6555
6556@end itemize
6557
6558
6559@node Overlay Commands
6560@section Overlay Commands
6561
6562To use @value{GDBN}'s overlay support, each overlay in your program must
6563correspond to a separate section of the executable file. The section's
6564virtual memory address and load memory address must be the overlay's
6565mapped and load addresses. Identifying overlays with sections allows
6566@value{GDBN} to determine the appropriate address of a function or
6567variable, depending on whether the overlay is mapped or not.
6568
6569@value{GDBN}'s overlay commands all start with the word @code{overlay};
6570you can abbreviate this as @code{ov} or @code{ovly}. The commands are:
6571
6572@table @code
6573@item overlay off
6574@kindex overlay off
6575Disable @value{GDBN}'s overlay support. When overlay support is
6576disabled, @value{GDBN} assumes that all functions and variables are
6577always present at their mapped addresses. By default, @value{GDBN}'s
6578overlay support is disabled.
6579
6580@item overlay manual
6581@kindex overlay manual
6582@cindex manual overlay debugging
6583Enable @dfn{manual} overlay debugging. In this mode, @value{GDBN}
6584relies on you to tell it which overlays are mapped, and which are not,
6585using the @code{overlay map-overlay} and @code{overlay unmap-overlay}
6586commands described below.
6587
6588@item overlay map-overlay @var{overlay}
6589@itemx overlay map @var{overlay}
6590@kindex overlay map-overlay
6591@cindex map an overlay
6592Tell @value{GDBN} that @var{overlay} is now mapped; @var{overlay} must
6593be the name of the object file section containing the overlay. When an
6594overlay is mapped, @value{GDBN} assumes it can find the overlay's
6595functions and variables at their mapped addresses. @value{GDBN} assumes
6596that any other overlays whose mapped ranges overlap that of
6597@var{overlay} are now unmapped.
6598
6599@item overlay unmap-overlay @var{overlay}
6600@itemx overlay unmap @var{overlay}
6601@kindex overlay unmap-overlay
6602@cindex unmap an overlay
6603Tell @value{GDBN} that @var{overlay} is no longer mapped; @var{overlay}
6604must be the name of the object file section containing the overlay.
6605When an overlay is unmapped, @value{GDBN} assumes it can find the
6606overlay's functions and variables at their load addresses.
6607
6608@item overlay auto
6609@kindex overlay auto
6610Enable @dfn{automatic} overlay debugging. In this mode, @value{GDBN}
6611consults a data structure the overlay manager maintains in the inferior
6612to see which overlays are mapped. For details, see @ref{Automatic
6613Overlay Debugging}.
6614
6615@item overlay load-target
6616@itemx overlay load
6617@kindex overlay load-target
6618@cindex reloading the overlay table
6619Re-read the overlay table from the inferior. Normally, @value{GDBN}
6620re-reads the table @value{GDBN} automatically each time the inferior
6621stops, so this command should only be necessary if you have changed the
6622overlay mapping yourself using @value{GDBN}. This command is only
6623useful when using automatic overlay debugging.
6624
6625@item overlay list-overlays
6626@itemx overlay list
6627@cindex listing mapped overlays
6628Display a list of the overlays currently mapped, along with their mapped
6629addresses, load addresses, and sizes.
6630
6631@end table
6632
6633Normally, when @value{GDBN} prints a code address, it includes the name
6634of the function the address falls in:
6635
6636@example
6637(gdb) print main
6638$3 = @{int ()@} 0x11a0 <main>
6639@end example
6640@noindent
6641When overlay debugging is enabled, @value{GDBN} recognizes code in
6642unmapped overlays, and prints the names of unmapped functions with
6643asterisks around them. For example, if @code{foo} is a function in an
6644unmapped overlay, @value{GDBN} prints it this way:
6645
6646@example
6647(gdb) overlay list
6648No sections are mapped.
6649(gdb) print foo
6650$5 = @{int (int)@} 0x100000 <*foo*>
6651@end example
6652@noindent
6653When @code{foo}'s overlay is mapped, @value{GDBN} prints the function's
6654name normally:
6655
6656@example
6657(gdb) overlay list
6658Section .ov.foo.text, loaded at 0x100000 - 0x100034,
6659 mapped at 0x1016 - 0x104a
6660(gdb) print foo
6661$6 = @{int (int)@} 0x1016 <foo>
6662@end example
6663
6664When overlay debugging is enabled, @value{GDBN} can find the correct
6665address for functions and variables in an overlay, whether or not the
6666overlay is mapped. This allows most @value{GDBN} commands, like
6667@code{break} and @code{disassemble}, to work normally, even on unmapped
6668code. However, @value{GDBN}'s breakpoint support has some limitations:
6669
6670@itemize @bullet
6671@item
6672@cindex breakpoints in overlays
6673@cindex overlays, setting breakpoints in
6674You can set breakpoints in functions in unmapped overlays, as long as
6675@value{GDBN} can write to the overlay at its load address.
6676@item
6677@value{GDBN} can not set hardware or simulator-based breakpoints in
6678unmapped overlays. However, if you set a breakpoint at the end of your
6679overlay manager (and tell @value{GDBN} which overlays are now mapped, if
6680you are using manual overlay management), @value{GDBN} will re-set its
6681breakpoints properly.
6682@end itemize
6683
6684
6685@node Automatic Overlay Debugging
6686@section Automatic Overlay Debugging
6687@cindex automatic overlay debugging
6688
6689@value{GDBN} can automatically track which overlays are mapped and which
6690are not, given some simple co-operation from the overlay manager in the
6691inferior. If you enable automatic overlay debugging with the
6692@code{overlay auto} command (@pxref{Overlay Commands}), @value{GDBN}
6693looks in the inferior's memory for certain variables describing the
6694current state of the overlays.
6695
6696Here are the variables your overlay manager must define to support
6697@value{GDBN}'s automatic overlay debugging:
6698
6699@table @asis
6700
6701@item @code{_ovly_table}:
6702This variable must be an array of the following structures:
6703
6704@example
6705struct
6706@{
6707 /* The overlay's mapped address. */
6708 unsigned long vma;
6709
6710 /* The size of the overlay, in bytes. */
6711 unsigned long size;
6712
6713 /* The overlay's load address. */
6714 unsigned long lma;
6715
6716 /* Non-zero if the overlay is currently mapped;
6717 zero otherwise. */
6718 unsigned long mapped;
6719@}
6720@end example
6721
6722@item @code{_novlys}:
6723This variable must be a four-byte signed integer, holding the total
6724number of elements in @code{_ovly_table}.
6725
6726@end table
6727
6728To decide whether a particular overlay is mapped or not, @value{GDBN}
6729looks for an entry in @w{@code{_ovly_table}} whose @code{vma} and
6730@code{lma} members equal the VMA and LMA of the overlay's section in the
6731executable file. When @value{GDBN} finds a matching entry, it consults
6732the entry's @code{mapped} member to determine whether the overlay is
6733currently mapped.
6734
6735
6736@node Overlay Sample Program
6737@section Overlay Sample Program
6738@cindex overlay example program
6739
6740When linking a program which uses overlays, you must place the overlays
6741at their load addresses, while relocating them to run at their mapped
6742addresses. To do this, you must write a linker script (@pxref{Overlay
6743Description,,, ld.info, Using ld: the GNU linker}). Unfortunately,
6744since linker scripts are specific to a particular host system, target
6745architecture, and target memory layout, this manual cannot provide
6746portable sample code demonstrating @value{GDBN}'s overlay support.
6747
6748However, the @value{GDBN} source distribution does contain an overlaid
6749program, with linker scripts for a few systems, as part of its test
6750suite. The program consists of the following files from
6751@file{gdb/testsuite/gdb.base}:
6752
6753@table @file
6754@item overlays.c
6755The main program file.
6756@item ovlymgr.c
6757A simple overlay manager, used by @file{overlays.c}.
6758@item foo.c
6759@itemx bar.c
6760@itemx baz.c
6761@itemx grbx.c
6762Overlay modules, loaded and used by @file{overlays.c}.
6763@item d10v.ld
6764@itemx m32r.ld
6765Linker scripts for linking the test program on the @code{d10v-elf}
6766and @code{m32r-elf} targets.
6767@end table
6768
6769You can build the test program using the @code{d10v-elf} GCC
6770cross-compiler like this:
6771
6772@example
6773$ d10v-elf-gcc -g -c overlays.c
6774$ d10v-elf-gcc -g -c ovlymgr.c
6775$ d10v-elf-gcc -g -c foo.c
6776$ d10v-elf-gcc -g -c bar.c
6777$ d10v-elf-gcc -g -c baz.c
6778$ d10v-elf-gcc -g -c grbx.c
6779$ d10v-elf-gcc -g overlays.o ovlymgr.o foo.o bar.o \
6780 baz.o grbx.o -Wl,-Td10v.ld -o overlays
6781@end example
6782
6783The build process is identical for any other architecture, except that
6784you must substitute the appropriate compiler and linker script for the
6785target system for @code{d10v-elf-gcc} and @code{d10v.ld}.
6786
6787
6d2ebf8b 6788@node Languages
c906108c
SS
6789@chapter Using @value{GDBN} with Different Languages
6790@cindex languages
6791
c906108c
SS
6792Although programming languages generally have common aspects, they are
6793rarely expressed in the same manner. For instance, in ANSI C,
6794dereferencing a pointer @code{p} is accomplished by @code{*p}, but in
6795Modula-2, it is accomplished by @code{p^}. Values can also be
5d161b24 6796represented (and displayed) differently. Hex numbers in C appear as
c906108c 6797@samp{0x1ae}, while in Modula-2 they appear as @samp{1AEH}.
c906108c
SS
6798
6799@cindex working language
6800Language-specific information is built into @value{GDBN} for some languages,
6801allowing you to express operations like the above in your program's
6802native language, and allowing @value{GDBN} to output values in a manner
6803consistent with the syntax of your program's native language. The
6804language you use to build expressions is called the @dfn{working
6805language}.
6806
6807@menu
6808* Setting:: Switching between source languages
6809* Show:: Displaying the language
c906108c 6810* Checks:: Type and range checks
c906108c
SS
6811* Support:: Supported languages
6812@end menu
6813
6d2ebf8b 6814@node Setting
c906108c
SS
6815@section Switching between source languages
6816
6817There are two ways to control the working language---either have @value{GDBN}
6818set it automatically, or select it manually yourself. You can use the
6819@code{set language} command for either purpose. On startup, @value{GDBN}
6820defaults to setting the language automatically. The working language is
6821used to determine how expressions you type are interpreted, how values
6822are printed, etc.
6823
6824In addition to the working language, every source file that
6825@value{GDBN} knows about has its own working language. For some object
6826file formats, the compiler might indicate which language a particular
6827source file is in. However, most of the time @value{GDBN} infers the
6828language from the name of the file. The language of a source file
b37052ae 6829controls whether C@t{++} names are demangled---this way @code{backtrace} can
c906108c 6830show each frame appropriately for its own language. There is no way to
d4f3574e
SS
6831set the language of a source file from within @value{GDBN}, but you can
6832set the language associated with a filename extension. @xref{Show, ,
6833Displaying the language}.
c906108c
SS
6834
6835This is most commonly a problem when you use a program, such
5d161b24 6836as @code{cfront} or @code{f2c}, that generates C but is written in
c906108c
SS
6837another language. In that case, make the
6838program use @code{#line} directives in its C output; that way
6839@value{GDBN} will know the correct language of the source code of the original
6840program, and will display that source code, not the generated C code.
6841
6842@menu
6843* Filenames:: Filename extensions and languages.
6844* Manually:: Setting the working language manually
6845* Automatically:: Having @value{GDBN} infer the source language
6846@end menu
6847
6d2ebf8b 6848@node Filenames
c906108c
SS
6849@subsection List of filename extensions and languages
6850
6851If a source file name ends in one of the following extensions, then
6852@value{GDBN} infers that its language is the one indicated.
6853
6854@table @file
6855
6856@item .c
6857C source file
6858
6859@item .C
6860@itemx .cc
6861@itemx .cp
6862@itemx .cpp
6863@itemx .cxx
6864@itemx .c++
b37052ae 6865C@t{++} source file
c906108c
SS
6866
6867@item .f
6868@itemx .F
6869Fortran source file
6870
c906108c
SS
6871@item .ch
6872@itemx .c186
6873@itemx .c286
96a2c332 6874CHILL source file
c906108c 6875
c906108c
SS
6876@item .mod
6877Modula-2 source file
c906108c
SS
6878
6879@item .s
6880@itemx .S
6881Assembler source file. This actually behaves almost like C, but
6882@value{GDBN} does not skip over function prologues when stepping.
6883@end table
6884
6885In addition, you may set the language associated with a filename
6886extension. @xref{Show, , Displaying the language}.
6887
6d2ebf8b 6888@node Manually
c906108c
SS
6889@subsection Setting the working language
6890
6891If you allow @value{GDBN} to set the language automatically,
6892expressions are interpreted the same way in your debugging session and
6893your program.
6894
6895@kindex set language
6896If you wish, you may set the language manually. To do this, issue the
6897command @samp{set language @var{lang}}, where @var{lang} is the name of
5d161b24 6898a language, such as
c906108c 6899@code{c} or @code{modula-2}.
c906108c
SS
6900For a list of the supported languages, type @samp{set language}.
6901
c906108c
SS
6902Setting the language manually prevents @value{GDBN} from updating the working
6903language automatically. This can lead to confusion if you try
6904to debug a program when the working language is not the same as the
6905source language, when an expression is acceptable to both
6906languages---but means different things. For instance, if the current
6907source file were written in C, and @value{GDBN} was parsing Modula-2, a
6908command such as:
6909
6910@example
6911print a = b + c
6912@end example
6913
6914@noindent
6915might not have the effect you intended. In C, this means to add
6916@code{b} and @code{c} and place the result in @code{a}. The result
6917printed would be the value of @code{a}. In Modula-2, this means to compare
6918@code{a} to the result of @code{b+c}, yielding a @code{BOOLEAN} value.
c906108c 6919
6d2ebf8b 6920@node Automatically
c906108c
SS
6921@subsection Having @value{GDBN} infer the source language
6922
6923To have @value{GDBN} set the working language automatically, use
6924@samp{set language local} or @samp{set language auto}. @value{GDBN}
6925then infers the working language. That is, when your program stops in a
6926frame (usually by encountering a breakpoint), @value{GDBN} sets the
6927working language to the language recorded for the function in that
6928frame. If the language for a frame is unknown (that is, if the function
6929or block corresponding to the frame was defined in a source file that
6930does not have a recognized extension), the current working language is
6931not changed, and @value{GDBN} issues a warning.
6932
6933This may not seem necessary for most programs, which are written
6934entirely in one source language. However, program modules and libraries
6935written in one source language can be used by a main program written in
6936a different source language. Using @samp{set language auto} in this
6937case frees you from having to set the working language manually.
6938
6d2ebf8b 6939@node Show
c906108c 6940@section Displaying the language
c906108c
SS
6941
6942The following commands help you find out which language is the
6943working language, and also what language source files were written in.
6944
6945@kindex show language
d4f3574e
SS
6946@kindex info frame@r{, show the source language}
6947@kindex info source@r{, show the source language}
c906108c
SS
6948@table @code
6949@item show language
6950Display the current working language. This is the
6951language you can use with commands such as @code{print} to
6952build and compute expressions that may involve variables in your program.
6953
6954@item info frame
5d161b24 6955Display the source language for this frame. This language becomes the
c906108c 6956working language if you use an identifier from this frame.
5d161b24 6957@xref{Frame Info, ,Information about a frame}, to identify the other
c906108c
SS
6958information listed here.
6959
6960@item info source
6961Display the source language of this source file.
5d161b24 6962@xref{Symbols, ,Examining the Symbol Table}, to identify the other
c906108c
SS
6963information listed here.
6964@end table
6965
6966In unusual circumstances, you may have source files with extensions
6967not in the standard list. You can then set the extension associated
6968with a language explicitly:
6969
6970@kindex set extension-language
6971@kindex info extensions
6972@table @code
6973@item set extension-language @var{.ext} @var{language}
6974Set source files with extension @var{.ext} to be assumed to be in
6975the source language @var{language}.
6976
6977@item info extensions
6978List all the filename extensions and the associated languages.
6979@end table
6980
6d2ebf8b 6981@node Checks
c906108c
SS
6982@section Type and range checking
6983
6984@quotation
6985@emph{Warning:} In this release, the @value{GDBN} commands for type and range
6986checking are included, but they do not yet have any effect. This
6987section documents the intended facilities.
6988@end quotation
6989@c FIXME remove warning when type/range code added
6990
6991Some languages are designed to guard you against making seemingly common
6992errors through a series of compile- and run-time checks. These include
6993checking the type of arguments to functions and operators, and making
6994sure mathematical overflows are caught at run time. Checks such as
6995these help to ensure a program's correctness once it has been compiled
6996by eliminating type mismatches, and providing active checks for range
6997errors when your program is running.
6998
6999@value{GDBN} can check for conditions like the above if you wish.
7000Although @value{GDBN} does not check the statements in your program, it
7001can check expressions entered directly into @value{GDBN} for evaluation via
7002the @code{print} command, for example. As with the working language,
7003@value{GDBN} can also decide whether or not to check automatically based on
7004your program's source language. @xref{Support, ,Supported languages},
7005for the default settings of supported languages.
7006
7007@menu
7008* Type Checking:: An overview of type checking
7009* Range Checking:: An overview of range checking
7010@end menu
7011
7012@cindex type checking
7013@cindex checks, type
6d2ebf8b 7014@node Type Checking
c906108c
SS
7015@subsection An overview of type checking
7016
7017Some languages, such as Modula-2, are strongly typed, meaning that the
7018arguments to operators and functions have to be of the correct type,
7019otherwise an error occurs. These checks prevent type mismatch
7020errors from ever causing any run-time problems. For example,
7021
7022@smallexample
70231 + 2 @result{} 3
7024@exdent but
7025@error{} 1 + 2.3
7026@end smallexample
7027
7028The second example fails because the @code{CARDINAL} 1 is not
7029type-compatible with the @code{REAL} 2.3.
7030
5d161b24
DB
7031For the expressions you use in @value{GDBN} commands, you can tell the
7032@value{GDBN} type checker to skip checking;
7033to treat any mismatches as errors and abandon the expression;
7034or to only issue warnings when type mismatches occur,
c906108c
SS
7035but evaluate the expression anyway. When you choose the last of
7036these, @value{GDBN} evaluates expressions like the second example above, but
7037also issues a warning.
7038
5d161b24
DB
7039Even if you turn type checking off, there may be other reasons
7040related to type that prevent @value{GDBN} from evaluating an expression.
7041For instance, @value{GDBN} does not know how to add an @code{int} and
7042a @code{struct foo}. These particular type errors have nothing to do
7043with the language in use, and usually arise from expressions, such as
c906108c
SS
7044the one described above, which make little sense to evaluate anyway.
7045
7046Each language defines to what degree it is strict about type. For
7047instance, both Modula-2 and C require the arguments to arithmetical
7048operators to be numbers. In C, enumerated types and pointers can be
7049represented as numbers, so that they are valid arguments to mathematical
7050operators. @xref{Support, ,Supported languages}, for further
7051details on specific languages.
7052
7053@value{GDBN} provides some additional commands for controlling the type checker:
7054
d4f3574e 7055@kindex set check@r{, type}
c906108c
SS
7056@kindex set check type
7057@kindex show check type
7058@table @code
7059@item set check type auto
7060Set type checking on or off based on the current working language.
7061@xref{Support, ,Supported languages}, for the default settings for
7062each language.
7063
7064@item set check type on
7065@itemx set check type off
7066Set type checking on or off, overriding the default setting for the
7067current working language. Issue a warning if the setting does not
7068match the language default. If any type mismatches occur in
d4f3574e 7069evaluating an expression while type checking is on, @value{GDBN} prints a
c906108c
SS
7070message and aborts evaluation of the expression.
7071
7072@item set check type warn
7073Cause the type checker to issue warnings, but to always attempt to
7074evaluate the expression. Evaluating the expression may still
7075be impossible for other reasons. For example, @value{GDBN} cannot add
7076numbers and structures.
7077
7078@item show type
5d161b24 7079Show the current setting of the type checker, and whether or not @value{GDBN}
c906108c
SS
7080is setting it automatically.
7081@end table
7082
7083@cindex range checking
7084@cindex checks, range
6d2ebf8b 7085@node Range Checking
c906108c
SS
7086@subsection An overview of range checking
7087
7088In some languages (such as Modula-2), it is an error to exceed the
7089bounds of a type; this is enforced with run-time checks. Such range
7090checking is meant to ensure program correctness by making sure
7091computations do not overflow, or indices on an array element access do
7092not exceed the bounds of the array.
7093
7094For expressions you use in @value{GDBN} commands, you can tell
7095@value{GDBN} to treat range errors in one of three ways: ignore them,
7096always treat them as errors and abandon the expression, or issue
7097warnings but evaluate the expression anyway.
7098
7099A range error can result from numerical overflow, from exceeding an
7100array index bound, or when you type a constant that is not a member
7101of any type. Some languages, however, do not treat overflows as an
7102error. In many implementations of C, mathematical overflow causes the
7103result to ``wrap around'' to lower values---for example, if @var{m} is
7104the largest integer value, and @var{s} is the smallest, then
7105
7106@example
7107@var{m} + 1 @result{} @var{s}
7108@end example
7109
7110This, too, is specific to individual languages, and in some cases
7111specific to individual compilers or machines. @xref{Support, ,
7112Supported languages}, for further details on specific languages.
7113
7114@value{GDBN} provides some additional commands for controlling the range checker:
7115
d4f3574e 7116@kindex set check@r{, range}
c906108c
SS
7117@kindex set check range
7118@kindex show check range
7119@table @code
7120@item set check range auto
7121Set range checking on or off based on the current working language.
7122@xref{Support, ,Supported languages}, for the default settings for
7123each language.
7124
7125@item set check range on
7126@itemx set check range off
7127Set range checking on or off, overriding the default setting for the
7128current working language. A warning is issued if the setting does not
c3f6f71d
JM
7129match the language default. If a range error occurs and range checking is on,
7130then a message is printed and evaluation of the expression is aborted.
c906108c
SS
7131
7132@item set check range warn
7133Output messages when the @value{GDBN} range checker detects a range error,
7134but attempt to evaluate the expression anyway. Evaluating the
7135expression may still be impossible for other reasons, such as accessing
7136memory that the process does not own (a typical example from many Unix
7137systems).
7138
7139@item show range
7140Show the current setting of the range checker, and whether or not it is
7141being set automatically by @value{GDBN}.
7142@end table
c906108c 7143
6d2ebf8b 7144@node Support
c906108c 7145@section Supported languages
c906108c 7146
b37052ae 7147@value{GDBN} supports C, C@t{++}, Fortran, Java, Chill, assembly, and Modula-2.
cce74817 7148@c This is false ...
c906108c
SS
7149Some @value{GDBN} features may be used in expressions regardless of the
7150language you use: the @value{GDBN} @code{@@} and @code{::} operators,
7151and the @samp{@{type@}addr} construct (@pxref{Expressions,
7152,Expressions}) can be used with the constructs of any supported
7153language.
7154
7155The following sections detail to what degree each source language is
7156supported by @value{GDBN}. These sections are not meant to be language
7157tutorials or references, but serve only as a reference guide to what the
7158@value{GDBN} expression parser accepts, and what input and output
7159formats should look like for different languages. There are many good
7160books written on each of these languages; please look to these for a
7161language reference or tutorial.
7162
c906108c 7163@menu
b37052ae 7164* C:: C and C@t{++}
cce74817 7165* Modula-2:: Modula-2
104c1213 7166* Chill:: Chill
c906108c
SS
7167@end menu
7168
6d2ebf8b 7169@node C
b37052ae 7170@subsection C and C@t{++}
7a292a7a 7171
b37052ae
EZ
7172@cindex C and C@t{++}
7173@cindex expressions in C or C@t{++}
c906108c 7174
b37052ae 7175Since C and C@t{++} are so closely related, many features of @value{GDBN} apply
c906108c
SS
7176to both languages. Whenever this is the case, we discuss those languages
7177together.
7178
41afff9a
EZ
7179@cindex C@t{++}
7180@cindex @code{g++}, @sc{gnu} C@t{++} compiler
b37052ae
EZ
7181@cindex @sc{gnu} C@t{++}
7182The C@t{++} debugging facilities are jointly implemented by the C@t{++}
7183compiler and @value{GDBN}. Therefore, to debug your C@t{++} code
7184effectively, you must compile your C@t{++} programs with a supported
7185C@t{++} compiler, such as @sc{gnu} @code{g++}, or the HP ANSI C@t{++}
c906108c
SS
7186compiler (@code{aCC}).
7187
b37052ae 7188For best results when using @sc{gnu} C@t{++}, use the stabs debugging
c906108c
SS
7189format. You can select that format explicitly with the @code{g++}
7190command-line options @samp{-gstabs} or @samp{-gstabs+}. See
7191@ref{Debugging Options,,Options for Debugging Your Program or @sc{gnu}
7192CC, gcc.info, Using @sc{gnu} CC}, for more information.
c906108c 7193
c906108c 7194@menu
b37052ae
EZ
7195* C Operators:: C and C@t{++} operators
7196* C Constants:: C and C@t{++} constants
7197* C plus plus expressions:: C@t{++} expressions
7198* C Defaults:: Default settings for C and C@t{++}
7199* C Checks:: C and C@t{++} type and range checks
c906108c 7200* Debugging C:: @value{GDBN} and C
b37052ae 7201* Debugging C plus plus:: @value{GDBN} features for C@t{++}
c906108c 7202@end menu
c906108c 7203
6d2ebf8b 7204@node C Operators
b37052ae 7205@subsubsection C and C@t{++} operators
7a292a7a 7206
b37052ae 7207@cindex C and C@t{++} operators
c906108c
SS
7208
7209Operators must be defined on values of specific types. For instance,
7210@code{+} is defined on numbers, but not on structures. Operators are
5d161b24 7211often defined on groups of types.
c906108c 7212
b37052ae 7213For the purposes of C and C@t{++}, the following definitions hold:
c906108c
SS
7214
7215@itemize @bullet
53a5351d 7216
c906108c 7217@item
c906108c 7218@emph{Integral types} include @code{int} with any of its storage-class
b37052ae 7219specifiers; @code{char}; @code{enum}; and, for C@t{++}, @code{bool}.
c906108c
SS
7220
7221@item
d4f3574e
SS
7222@emph{Floating-point types} include @code{float}, @code{double}, and
7223@code{long double} (if supported by the target platform).
c906108c
SS
7224
7225@item
53a5351d 7226@emph{Pointer types} include all types defined as @code{(@var{type} *)}.
c906108c
SS
7227
7228@item
7229@emph{Scalar types} include all of the above.
53a5351d 7230
c906108c
SS
7231@end itemize
7232
7233@noindent
7234The following operators are supported. They are listed here
7235in order of increasing precedence:
7236
7237@table @code
7238@item ,
7239The comma or sequencing operator. Expressions in a comma-separated list
7240are evaluated from left to right, with the result of the entire
7241expression being the last expression evaluated.
7242
7243@item =
7244Assignment. The value of an assignment expression is the value
7245assigned. Defined on scalar types.
7246
7247@item @var{op}=
7248Used in an expression of the form @w{@code{@var{a} @var{op}= @var{b}}},
7249and translated to @w{@code{@var{a} = @var{a op b}}}.
d4f3574e 7250@w{@code{@var{op}=}} and @code{=} have the same precedence.
c906108c
SS
7251@var{op} is any one of the operators @code{|}, @code{^}, @code{&},
7252@code{<<}, @code{>>}, @code{+}, @code{-}, @code{*}, @code{/}, @code{%}.
7253
7254@item ?:
7255The ternary operator. @code{@var{a} ? @var{b} : @var{c}} can be thought
7256of as: if @var{a} then @var{b} else @var{c}. @var{a} should be of an
7257integral type.
7258
7259@item ||
7260Logical @sc{or}. Defined on integral types.
7261
7262@item &&
7263Logical @sc{and}. Defined on integral types.
7264
7265@item |
7266Bitwise @sc{or}. Defined on integral types.
7267
7268@item ^
7269Bitwise exclusive-@sc{or}. Defined on integral types.
7270
7271@item &
7272Bitwise @sc{and}. Defined on integral types.
7273
7274@item ==@r{, }!=
7275Equality and inequality. Defined on scalar types. The value of these
7276expressions is 0 for false and non-zero for true.
7277
7278@item <@r{, }>@r{, }<=@r{, }>=
7279Less than, greater than, less than or equal, greater than or equal.
7280Defined on scalar types. The value of these expressions is 0 for false
7281and non-zero for true.
7282
7283@item <<@r{, }>>
7284left shift, and right shift. Defined on integral types.
7285
7286@item @@
7287The @value{GDBN} ``artificial array'' operator (@pxref{Expressions, ,Expressions}).
7288
7289@item +@r{, }-
7290Addition and subtraction. Defined on integral types, floating-point types and
7291pointer types.
7292
7293@item *@r{, }/@r{, }%
7294Multiplication, division, and modulus. Multiplication and division are
7295defined on integral and floating-point types. Modulus is defined on
7296integral types.
7297
7298@item ++@r{, }--
7299Increment and decrement. When appearing before a variable, the
7300operation is performed before the variable is used in an expression;
7301when appearing after it, the variable's value is used before the
7302operation takes place.
7303
7304@item *
7305Pointer dereferencing. Defined on pointer types. Same precedence as
7306@code{++}.
7307
7308@item &
7309Address operator. Defined on variables. Same precedence as @code{++}.
7310
b37052ae
EZ
7311For debugging C@t{++}, @value{GDBN} implements a use of @samp{&} beyond what is
7312allowed in the C@t{++} language itself: you can use @samp{&(&@var{ref})}
c906108c 7313(or, if you prefer, simply @samp{&&@var{ref}}) to examine the address
b37052ae 7314where a C@t{++} reference variable (declared with @samp{&@var{ref}}) is
c906108c 7315stored.
c906108c
SS
7316
7317@item -
7318Negative. Defined on integral and floating-point types. Same
7319precedence as @code{++}.
7320
7321@item !
7322Logical negation. Defined on integral types. Same precedence as
7323@code{++}.
7324
7325@item ~
7326Bitwise complement operator. Defined on integral types. Same precedence as
7327@code{++}.
7328
7329
7330@item .@r{, }->
7331Structure member, and pointer-to-structure member. For convenience,
7332@value{GDBN} regards the two as equivalent, choosing whether to dereference a
7333pointer based on the stored type information.
7334Defined on @code{struct} and @code{union} data.
7335
c906108c
SS
7336@item .*@r{, }->*
7337Dereferences of pointers to members.
c906108c
SS
7338
7339@item []
7340Array indexing. @code{@var{a}[@var{i}]} is defined as
7341@code{*(@var{a}+@var{i})}. Same precedence as @code{->}.
7342
7343@item ()
7344Function parameter list. Same precedence as @code{->}.
7345
c906108c 7346@item ::
b37052ae 7347C@t{++} scope resolution operator. Defined on @code{struct}, @code{union},
7a292a7a 7348and @code{class} types.
c906108c
SS
7349
7350@item ::
7a292a7a
SS
7351Doubled colons also represent the @value{GDBN} scope operator
7352(@pxref{Expressions, ,Expressions}). Same precedence as @code{::},
7353above.
c906108c
SS
7354@end table
7355
c906108c
SS
7356If an operator is redefined in the user code, @value{GDBN} usually
7357attempts to invoke the redefined version instead of using the operator's
7358predefined meaning.
c906108c 7359
c906108c 7360@menu
5d161b24 7361* C Constants::
c906108c
SS
7362@end menu
7363
6d2ebf8b 7364@node C Constants
b37052ae 7365@subsubsection C and C@t{++} constants
c906108c 7366
b37052ae 7367@cindex C and C@t{++} constants
c906108c 7368
b37052ae 7369@value{GDBN} allows you to express the constants of C and C@t{++} in the
c906108c 7370following ways:
c906108c
SS
7371
7372@itemize @bullet
7373@item
7374Integer constants are a sequence of digits. Octal constants are
7375specified by a leading @samp{0} (i.e. zero), and hexadecimal constants by
7376a leading @samp{0x} or @samp{0X}. Constants may also end with a letter
7377@samp{l}, specifying that the constant should be treated as a
7378@code{long} value.
7379
7380@item
7381Floating point constants are a sequence of digits, followed by a decimal
7382point, followed by a sequence of digits, and optionally followed by an
7383exponent. An exponent is of the form:
7384@samp{@w{e@r{[[}+@r{]|}-@r{]}@var{nnn}}}, where @var{nnn} is another
7385sequence of digits. The @samp{+} is optional for positive exponents.
d4f3574e
SS
7386A floating-point constant may also end with a letter @samp{f} or
7387@samp{F}, specifying that the constant should be treated as being of
7388the @code{float} (as opposed to the default @code{double}) type; or with
7389a letter @samp{l} or @samp{L}, which specifies a @code{long double}
7390constant.
c906108c
SS
7391
7392@item
7393Enumerated constants consist of enumerated identifiers, or their
7394integral equivalents.
7395
7396@item
7397Character constants are a single character surrounded by single quotes
7398(@code{'}), or a number---the ordinal value of the corresponding character
d4f3574e 7399(usually its @sc{ascii} value). Within quotes, the single character may
c906108c
SS
7400be represented by a letter or by @dfn{escape sequences}, which are of
7401the form @samp{\@var{nnn}}, where @var{nnn} is the octal representation
7402of the character's ordinal value; or of the form @samp{\@var{x}}, where
7403@samp{@var{x}} is a predefined special character---for example,
7404@samp{\n} for newline.
7405
7406@item
96a2c332
SS
7407String constants are a sequence of character constants surrounded by
7408double quotes (@code{"}). Any valid character constant (as described
7409above) may appear. Double quotes within the string must be preceded by
7410a backslash, so for instance @samp{"a\"b'c"} is a string of five
7411characters.
c906108c
SS
7412
7413@item
7414Pointer constants are an integral value. You can also write pointers
7415to constants using the C operator @samp{&}.
7416
7417@item
7418Array constants are comma-separated lists surrounded by braces @samp{@{}
7419and @samp{@}}; for example, @samp{@{1,2,3@}} is a three-element array of
7420integers, @samp{@{@{1,2@}, @{3,4@}, @{5,6@}@}} is a three-by-two array,
7421and @samp{@{&"hi", &"there", &"fred"@}} is a three-element array of pointers.
7422@end itemize
7423
c906108c 7424@menu
5d161b24
DB
7425* C plus plus expressions::
7426* C Defaults::
7427* C Checks::
c906108c 7428
5d161b24 7429* Debugging C::
c906108c
SS
7430@end menu
7431
6d2ebf8b 7432@node C plus plus expressions
b37052ae
EZ
7433@subsubsection C@t{++} expressions
7434
7435@cindex expressions in C@t{++}
7436@value{GDBN} expression handling can interpret most C@t{++} expressions.
7437
7438@cindex C@t{++} support, not in @sc{coff}
7439@cindex @sc{coff} versus C@t{++}
7440@cindex C@t{++} and object formats
7441@cindex object formats and C@t{++}
7442@cindex a.out and C@t{++}
7443@cindex @sc{ecoff} and C@t{++}
7444@cindex @sc{xcoff} and C@t{++}
7445@cindex @sc{elf}/stabs and C@t{++}
7446@cindex @sc{elf}/@sc{dwarf} and C@t{++}
c906108c
SS
7447@c FIXME!! GDB may eventually be able to debug C++ using DWARF; check
7448@c periodically whether this has happened...
7449@quotation
b37052ae
EZ
7450@emph{Warning:} @value{GDBN} can only debug C@t{++} code if you use the
7451proper compiler. Typically, C@t{++} debugging depends on the use of
c906108c
SS
7452additional debugging information in the symbol table, and thus requires
7453special support. In particular, if your compiler generates a.out, MIPS
7454@sc{ecoff}, RS/6000 @sc{xcoff}, or @sc{elf} with stabs extensions to the
7455symbol table, these facilities are all available. (With @sc{gnu} CC,
7456you can use the @samp{-gstabs} option to request stabs debugging
7457extensions explicitly.) Where the object code format is standard
b37052ae 7458@sc{coff} or @sc{dwarf} in @sc{elf}, on the other hand, most of the C@t{++}
c906108c
SS
7459support in @value{GDBN} does @emph{not} work.
7460@end quotation
c906108c
SS
7461
7462@enumerate
7463
7464@cindex member functions
7465@item
7466Member function calls are allowed; you can use expressions like
7467
7468@example
7469count = aml->GetOriginal(x, y)
7470@end example
7471
41afff9a 7472@vindex this@r{, inside C@t{++} member functions}
b37052ae 7473@cindex namespace in C@t{++}
c906108c
SS
7474@item
7475While a member function is active (in the selected stack frame), your
7476expressions have the same namespace available as the member function;
7477that is, @value{GDBN} allows implicit references to the class instance
b37052ae 7478pointer @code{this} following the same rules as C@t{++}.
c906108c 7479
c906108c 7480@cindex call overloaded functions
d4f3574e 7481@cindex overloaded functions, calling
b37052ae 7482@cindex type conversions in C@t{++}
c906108c
SS
7483@item
7484You can call overloaded functions; @value{GDBN} resolves the function
d4f3574e 7485call to the right definition, with some restrictions. @value{GDBN} does not
c906108c
SS
7486perform overload resolution involving user-defined type conversions,
7487calls to constructors, or instantiations of templates that do not exist
7488in the program. It also cannot handle ellipsis argument lists or
7489default arguments.
7490
7491It does perform integral conversions and promotions, floating-point
7492promotions, arithmetic conversions, pointer conversions, conversions of
7493class objects to base classes, and standard conversions such as those of
7494functions or arrays to pointers; it requires an exact match on the
7495number of function arguments.
7496
7497Overload resolution is always performed, unless you have specified
7498@code{set overload-resolution off}. @xref{Debugging C plus plus,
b37052ae 7499,@value{GDBN} features for C@t{++}}.
c906108c 7500
d4f3574e 7501You must specify @code{set overload-resolution off} in order to use an
c906108c
SS
7502explicit function signature to call an overloaded function, as in
7503@smallexample
7504p 'foo(char,int)'('x', 13)
7505@end smallexample
d4f3574e 7506
c906108c 7507The @value{GDBN} command-completion facility can simplify this;
d4f3574e 7508see @ref{Completion, ,Command completion}.
c906108c 7509
c906108c
SS
7510@cindex reference declarations
7511@item
b37052ae
EZ
7512@value{GDBN} understands variables declared as C@t{++} references; you can use
7513them in expressions just as you do in C@t{++} source---they are automatically
c906108c
SS
7514dereferenced.
7515
7516In the parameter list shown when @value{GDBN} displays a frame, the values of
7517reference variables are not displayed (unlike other variables); this
7518avoids clutter, since references are often used for large structures.
7519The @emph{address} of a reference variable is always shown, unless
7520you have specified @samp{set print address off}.
7521
7522@item
b37052ae 7523@value{GDBN} supports the C@t{++} name resolution operator @code{::}---your
c906108c
SS
7524expressions can use it just as expressions in your program do. Since
7525one scope may be defined in another, you can use @code{::} repeatedly if
7526necessary, for example in an expression like
7527@samp{@var{scope1}::@var{scope2}::@var{name}}. @value{GDBN} also allows
b37052ae 7528resolving name scope by reference to source files, in both C and C@t{++}
c906108c
SS
7529debugging (@pxref{Variables, ,Program variables}).
7530@end enumerate
7531
b37052ae 7532In addition, when used with HP's C@t{++} compiler, @value{GDBN} supports
53a5351d
JM
7533calling virtual functions correctly, printing out virtual bases of
7534objects, calling functions in a base subobject, casting objects, and
7535invoking user-defined operators.
c906108c 7536
6d2ebf8b 7537@node C Defaults
b37052ae 7538@subsubsection C and C@t{++} defaults
7a292a7a 7539
b37052ae 7540@cindex C and C@t{++} defaults
c906108c 7541
c906108c
SS
7542If you allow @value{GDBN} to set type and range checking automatically, they
7543both default to @code{off} whenever the working language changes to
b37052ae 7544C or C@t{++}. This happens regardless of whether you or @value{GDBN}
c906108c 7545selects the working language.
c906108c
SS
7546
7547If you allow @value{GDBN} to set the language automatically, it
7548recognizes source files whose names end with @file{.c}, @file{.C}, or
7549@file{.cc}, etc, and when @value{GDBN} enters code compiled from one of
b37052ae 7550these files, it sets the working language to C or C@t{++}.
c906108c
SS
7551@xref{Automatically, ,Having @value{GDBN} infer the source language},
7552for further details.
7553
c906108c
SS
7554@c Type checking is (a) primarily motivated by Modula-2, and (b)
7555@c unimplemented. If (b) changes, it might make sense to let this node
7556@c appear even if Mod-2 does not, but meanwhile ignore it. roland 16jul93.
7a292a7a 7557
6d2ebf8b 7558@node C Checks
b37052ae 7559@subsubsection C and C@t{++} type and range checks
7a292a7a 7560
b37052ae 7561@cindex C and C@t{++} checks
c906108c 7562
b37052ae 7563By default, when @value{GDBN} parses C or C@t{++} expressions, type checking
c906108c
SS
7564is not used. However, if you turn type checking on, @value{GDBN}
7565considers two variables type equivalent if:
7566
7567@itemize @bullet
7568@item
7569The two variables are structured and have the same structure, union, or
7570enumerated tag.
7571
7572@item
7573The two variables have the same type name, or types that have been
7574declared equivalent through @code{typedef}.
7575
7576@ignore
7577@c leaving this out because neither J Gilmore nor R Pesch understand it.
7578@c FIXME--beers?
7579@item
7580The two @code{struct}, @code{union}, or @code{enum} variables are
7581declared in the same declaration. (Note: this may not be true for all C
7582compilers.)
7583@end ignore
7584@end itemize
7585
7586Range checking, if turned on, is done on mathematical operations. Array
7587indices are not checked, since they are often used to index a pointer
7588that is not itself an array.
c906108c 7589
6d2ebf8b 7590@node Debugging C
c906108c 7591@subsubsection @value{GDBN} and C
c906108c
SS
7592
7593The @code{set print union} and @code{show print union} commands apply to
7594the @code{union} type. When set to @samp{on}, any @code{union} that is
7a292a7a
SS
7595inside a @code{struct} or @code{class} is also printed. Otherwise, it
7596appears as @samp{@{...@}}.
c906108c
SS
7597
7598The @code{@@} operator aids in the debugging of dynamic arrays, formed
7599with pointers and a memory allocation function. @xref{Expressions,
7600,Expressions}.
7601
c906108c 7602@menu
5d161b24 7603* Debugging C plus plus::
c906108c
SS
7604@end menu
7605
6d2ebf8b 7606@node Debugging C plus plus
b37052ae 7607@subsubsection @value{GDBN} features for C@t{++}
c906108c 7608
b37052ae 7609@cindex commands for C@t{++}
7a292a7a 7610
b37052ae
EZ
7611Some @value{GDBN} commands are particularly useful with C@t{++}, and some are
7612designed specifically for use with C@t{++}. Here is a summary:
c906108c
SS
7613
7614@table @code
7615@cindex break in overloaded functions
7616@item @r{breakpoint menus}
7617When you want a breakpoint in a function whose name is overloaded,
7618@value{GDBN} breakpoint menus help you specify which function definition
7619you want. @xref{Breakpoint Menus,,Breakpoint menus}.
7620
b37052ae 7621@cindex overloading in C@t{++}
c906108c
SS
7622@item rbreak @var{regex}
7623Setting breakpoints using regular expressions is helpful for setting
7624breakpoints on overloaded functions that are not members of any special
7625classes.
7626@xref{Set Breaks, ,Setting breakpoints}.
7627
b37052ae 7628@cindex C@t{++} exception handling
c906108c
SS
7629@item catch throw
7630@itemx catch catch
b37052ae 7631Debug C@t{++} exception handling using these commands. @xref{Set
c906108c
SS
7632Catchpoints, , Setting catchpoints}.
7633
7634@cindex inheritance
7635@item ptype @var{typename}
7636Print inheritance relationships as well as other information for type
7637@var{typename}.
7638@xref{Symbols, ,Examining the Symbol Table}.
7639
b37052ae 7640@cindex C@t{++} symbol display
c906108c
SS
7641@item set print demangle
7642@itemx show print demangle
7643@itemx set print asm-demangle
7644@itemx show print asm-demangle
b37052ae
EZ
7645Control whether C@t{++} symbols display in their source form, both when
7646displaying code as C@t{++} source and when displaying disassemblies.
c906108c
SS
7647@xref{Print Settings, ,Print settings}.
7648
7649@item set print object
7650@itemx show print object
7651Choose whether to print derived (actual) or declared types of objects.
7652@xref{Print Settings, ,Print settings}.
7653
7654@item set print vtbl
7655@itemx show print vtbl
7656Control the format for printing virtual function tables.
7657@xref{Print Settings, ,Print settings}.
c906108c 7658(The @code{vtbl} commands do not work on programs compiled with the HP
b37052ae 7659ANSI C@t{++} compiler (@code{aCC}).)
c906108c
SS
7660
7661@kindex set overload-resolution
d4f3574e 7662@cindex overloaded functions, overload resolution
c906108c 7663@item set overload-resolution on
b37052ae 7664Enable overload resolution for C@t{++} expression evaluation. The default
c906108c
SS
7665is on. For overloaded functions, @value{GDBN} evaluates the arguments
7666and searches for a function whose signature matches the argument types,
b37052ae 7667using the standard C@t{++} conversion rules (see @ref{C plus plus expressions, ,C@t{++}
d4f3574e 7668expressions}, for details). If it cannot find a match, it emits a
c906108c
SS
7669message.
7670
7671@item set overload-resolution off
b37052ae 7672Disable overload resolution for C@t{++} expression evaluation. For
c906108c
SS
7673overloaded functions that are not class member functions, @value{GDBN}
7674chooses the first function of the specified name that it finds in the
7675symbol table, whether or not its arguments are of the correct type. For
7676overloaded functions that are class member functions, @value{GDBN}
7677searches for a function whose signature @emph{exactly} matches the
7678argument types.
c906108c
SS
7679
7680@item @r{Overloaded symbol names}
7681You can specify a particular definition of an overloaded symbol, using
b37052ae 7682the same notation that is used to declare such symbols in C@t{++}: type
c906108c
SS
7683@code{@var{symbol}(@var{types})} rather than just @var{symbol}. You can
7684also use the @value{GDBN} command-line word completion facilities to list the
7685available choices, or to finish the type list for you.
7686@xref{Completion,, Command completion}, for details on how to do this.
7687@end table
c906108c 7688
6d2ebf8b 7689@node Modula-2
c906108c 7690@subsection Modula-2
7a292a7a 7691
d4f3574e 7692@cindex Modula-2, @value{GDBN} support
c906108c
SS
7693
7694The extensions made to @value{GDBN} to support Modula-2 only support
7695output from the @sc{gnu} Modula-2 compiler (which is currently being
7696developed). Other Modula-2 compilers are not currently supported, and
7697attempting to debug executables produced by them is most likely
7698to give an error as @value{GDBN} reads in the executable's symbol
7699table.
7700
7701@cindex expressions in Modula-2
7702@menu
7703* M2 Operators:: Built-in operators
7704* Built-In Func/Proc:: Built-in functions and procedures
7705* M2 Constants:: Modula-2 constants
7706* M2 Defaults:: Default settings for Modula-2
7707* Deviations:: Deviations from standard Modula-2
7708* M2 Checks:: Modula-2 type and range checks
7709* M2 Scope:: The scope operators @code{::} and @code{.}
7710* GDB/M2:: @value{GDBN} and Modula-2
7711@end menu
7712
6d2ebf8b 7713@node M2 Operators
c906108c
SS
7714@subsubsection Operators
7715@cindex Modula-2 operators
7716
7717Operators must be defined on values of specific types. For instance,
7718@code{+} is defined on numbers, but not on structures. Operators are
7719often defined on groups of types. For the purposes of Modula-2, the
7720following definitions hold:
7721
7722@itemize @bullet
7723
7724@item
7725@emph{Integral types} consist of @code{INTEGER}, @code{CARDINAL}, and
7726their subranges.
7727
7728@item
7729@emph{Character types} consist of @code{CHAR} and its subranges.
7730
7731@item
7732@emph{Floating-point types} consist of @code{REAL}.
7733
7734@item
7735@emph{Pointer types} consist of anything declared as @code{POINTER TO
7736@var{type}}.
7737
7738@item
7739@emph{Scalar types} consist of all of the above.
7740
7741@item
7742@emph{Set types} consist of @code{SET} and @code{BITSET} types.
7743
7744@item
7745@emph{Boolean types} consist of @code{BOOLEAN}.
7746@end itemize
7747
7748@noindent
7749The following operators are supported, and appear in order of
7750increasing precedence:
7751
7752@table @code
7753@item ,
7754Function argument or array index separator.
7755
7756@item :=
7757Assignment. The value of @var{var} @code{:=} @var{value} is
7758@var{value}.
7759
7760@item <@r{, }>
7761Less than, greater than on integral, floating-point, or enumerated
7762types.
7763
7764@item <=@r{, }>=
96a2c332 7765Less than or equal to, greater than or equal to
c906108c
SS
7766on integral, floating-point and enumerated types, or set inclusion on
7767set types. Same precedence as @code{<}.
7768
7769@item =@r{, }<>@r{, }#
7770Equality and two ways of expressing inequality, valid on scalar types.
7771Same precedence as @code{<}. In @value{GDBN} scripts, only @code{<>} is
7772available for inequality, since @code{#} conflicts with the script
7773comment character.
7774
7775@item IN
7776Set membership. Defined on set types and the types of their members.
7777Same precedence as @code{<}.
7778
7779@item OR
7780Boolean disjunction. Defined on boolean types.
7781
7782@item AND@r{, }&
d4f3574e 7783Boolean conjunction. Defined on boolean types.
c906108c
SS
7784
7785@item @@
7786The @value{GDBN} ``artificial array'' operator (@pxref{Expressions, ,Expressions}).
7787
7788@item +@r{, }-
7789Addition and subtraction on integral and floating-point types, or union
7790and difference on set types.
7791
7792@item *
7793Multiplication on integral and floating-point types, or set intersection
7794on set types.
7795
7796@item /
7797Division on floating-point types, or symmetric set difference on set
7798types. Same precedence as @code{*}.
7799
7800@item DIV@r{, }MOD
7801Integer division and remainder. Defined on integral types. Same
7802precedence as @code{*}.
7803
7804@item -
7805Negative. Defined on @code{INTEGER} and @code{REAL} data.
7806
7807@item ^
7808Pointer dereferencing. Defined on pointer types.
7809
7810@item NOT
7811Boolean negation. Defined on boolean types. Same precedence as
7812@code{^}.
7813
7814@item .
7815@code{RECORD} field selector. Defined on @code{RECORD} data. Same
7816precedence as @code{^}.
7817
7818@item []
7819Array indexing. Defined on @code{ARRAY} data. Same precedence as @code{^}.
7820
7821@item ()
7822Procedure argument list. Defined on @code{PROCEDURE} objects. Same precedence
7823as @code{^}.
7824
7825@item ::@r{, }.
7826@value{GDBN} and Modula-2 scope operators.
7827@end table
7828
7829@quotation
7830@emph{Warning:} Sets and their operations are not yet supported, so @value{GDBN}
7831treats the use of the operator @code{IN}, or the use of operators
7832@code{+}, @code{-}, @code{*}, @code{/}, @code{=}, , @code{<>}, @code{#},
7833@code{<=}, and @code{>=} on sets as an error.
7834@end quotation
7835
cb51c4e0 7836
6d2ebf8b 7837@node Built-In Func/Proc
c906108c 7838@subsubsection Built-in functions and procedures
cb51c4e0 7839@cindex Modula-2 built-ins
c906108c
SS
7840
7841Modula-2 also makes available several built-in procedures and functions.
7842In describing these, the following metavariables are used:
7843
7844@table @var
7845
7846@item a
7847represents an @code{ARRAY} variable.
7848
7849@item c
7850represents a @code{CHAR} constant or variable.
7851
7852@item i
7853represents a variable or constant of integral type.
7854
7855@item m
7856represents an identifier that belongs to a set. Generally used in the
7857same function with the metavariable @var{s}. The type of @var{s} should
7858be @code{SET OF @var{mtype}} (where @var{mtype} is the type of @var{m}).
7859
7860@item n
7861represents a variable or constant of integral or floating-point type.
7862
7863@item r
7864represents a variable or constant of floating-point type.
7865
7866@item t
7867represents a type.
7868
7869@item v
7870represents a variable.
7871
7872@item x
7873represents a variable or constant of one of many types. See the
7874explanation of the function for details.
7875@end table
7876
7877All Modula-2 built-in procedures also return a result, described below.
7878
7879@table @code
7880@item ABS(@var{n})
7881Returns the absolute value of @var{n}.
7882
7883@item CAP(@var{c})
7884If @var{c} is a lower case letter, it returns its upper case
c3f6f71d 7885equivalent, otherwise it returns its argument.
c906108c
SS
7886
7887@item CHR(@var{i})
7888Returns the character whose ordinal value is @var{i}.
7889
7890@item DEC(@var{v})
c3f6f71d 7891Decrements the value in the variable @var{v} by one. Returns the new value.
c906108c
SS
7892
7893@item DEC(@var{v},@var{i})
7894Decrements the value in the variable @var{v} by @var{i}. Returns the
7895new value.
7896
7897@item EXCL(@var{m},@var{s})
7898Removes the element @var{m} from the set @var{s}. Returns the new
7899set.
7900
7901@item FLOAT(@var{i})
7902Returns the floating point equivalent of the integer @var{i}.
7903
7904@item HIGH(@var{a})
7905Returns the index of the last member of @var{a}.
7906
7907@item INC(@var{v})
c3f6f71d 7908Increments the value in the variable @var{v} by one. Returns the new value.
c906108c
SS
7909
7910@item INC(@var{v},@var{i})
7911Increments the value in the variable @var{v} by @var{i}. Returns the
7912new value.
7913
7914@item INCL(@var{m},@var{s})
7915Adds the element @var{m} to the set @var{s} if it is not already
7916there. Returns the new set.
7917
7918@item MAX(@var{t})
7919Returns the maximum value of the type @var{t}.
7920
7921@item MIN(@var{t})
7922Returns the minimum value of the type @var{t}.
7923
7924@item ODD(@var{i})
7925Returns boolean TRUE if @var{i} is an odd number.
7926
7927@item ORD(@var{x})
7928Returns the ordinal value of its argument. For example, the ordinal
c3f6f71d
JM
7929value of a character is its @sc{ascii} value (on machines supporting the
7930@sc{ascii} character set). @var{x} must be of an ordered type, which include
c906108c
SS
7931integral, character and enumerated types.
7932
7933@item SIZE(@var{x})
7934Returns the size of its argument. @var{x} can be a variable or a type.
7935
7936@item TRUNC(@var{r})
7937Returns the integral part of @var{r}.
7938
7939@item VAL(@var{t},@var{i})
7940Returns the member of the type @var{t} whose ordinal value is @var{i}.
7941@end table
7942
7943@quotation
7944@emph{Warning:} Sets and their operations are not yet supported, so
7945@value{GDBN} treats the use of procedures @code{INCL} and @code{EXCL} as
7946an error.
7947@end quotation
7948
7949@cindex Modula-2 constants
6d2ebf8b 7950@node M2 Constants
c906108c
SS
7951@subsubsection Constants
7952
7953@value{GDBN} allows you to express the constants of Modula-2 in the following
7954ways:
7955
7956@itemize @bullet
7957
7958@item
7959Integer constants are simply a sequence of digits. When used in an
7960expression, a constant is interpreted to be type-compatible with the
7961rest of the expression. Hexadecimal integers are specified by a
7962trailing @samp{H}, and octal integers by a trailing @samp{B}.
7963
7964@item
7965Floating point constants appear as a sequence of digits, followed by a
7966decimal point and another sequence of digits. An optional exponent can
7967then be specified, in the form @samp{E@r{[}+@r{|}-@r{]}@var{nnn}}, where
7968@samp{@r{[}+@r{|}-@r{]}@var{nnn}} is the desired exponent. All of the
7969digits of the floating point constant must be valid decimal (base 10)
7970digits.
7971
7972@item
7973Character constants consist of a single character enclosed by a pair of
7974like quotes, either single (@code{'}) or double (@code{"}). They may
c3f6f71d 7975also be expressed by their ordinal value (their @sc{ascii} value, usually)
c906108c
SS
7976followed by a @samp{C}.
7977
7978@item
7979String constants consist of a sequence of characters enclosed by a
7980pair of like quotes, either single (@code{'}) or double (@code{"}).
7981Escape sequences in the style of C are also allowed. @xref{C
b37052ae 7982Constants, ,C and C@t{++} constants}, for a brief explanation of escape
c906108c
SS
7983sequences.
7984
7985@item
7986Enumerated constants consist of an enumerated identifier.
7987
7988@item
7989Boolean constants consist of the identifiers @code{TRUE} and
7990@code{FALSE}.
7991
7992@item
7993Pointer constants consist of integral values only.
7994
7995@item
7996Set constants are not yet supported.
7997@end itemize
7998
6d2ebf8b 7999@node M2 Defaults
c906108c
SS
8000@subsubsection Modula-2 defaults
8001@cindex Modula-2 defaults
8002
8003If type and range checking are set automatically by @value{GDBN}, they
8004both default to @code{on} whenever the working language changes to
d4f3574e 8005Modula-2. This happens regardless of whether you or @value{GDBN}
c906108c
SS
8006selected the working language.
8007
8008If you allow @value{GDBN} to set the language automatically, then entering
8009code compiled from a file whose name ends with @file{.mod} sets the
d4f3574e 8010working language to Modula-2. @xref{Automatically, ,Having @value{GDBN} set
c906108c
SS
8011the language automatically}, for further details.
8012
6d2ebf8b 8013@node Deviations
c906108c
SS
8014@subsubsection Deviations from standard Modula-2
8015@cindex Modula-2, deviations from
8016
8017A few changes have been made to make Modula-2 programs easier to debug.
8018This is done primarily via loosening its type strictness:
8019
8020@itemize @bullet
8021@item
8022Unlike in standard Modula-2, pointer constants can be formed by
8023integers. This allows you to modify pointer variables during
8024debugging. (In standard Modula-2, the actual address contained in a
8025pointer variable is hidden from you; it can only be modified
8026through direct assignment to another pointer variable or expression that
8027returned a pointer.)
8028
8029@item
8030C escape sequences can be used in strings and characters to represent
8031non-printable characters. @value{GDBN} prints out strings with these
8032escape sequences embedded. Single non-printable characters are
8033printed using the @samp{CHR(@var{nnn})} format.
8034
8035@item
8036The assignment operator (@code{:=}) returns the value of its right-hand
8037argument.
8038
8039@item
8040All built-in procedures both modify @emph{and} return their argument.
8041@end itemize
8042
6d2ebf8b 8043@node M2 Checks
c906108c
SS
8044@subsubsection Modula-2 type and range checks
8045@cindex Modula-2 checks
8046
8047@quotation
8048@emph{Warning:} in this release, @value{GDBN} does not yet perform type or
8049range checking.
8050@end quotation
8051@c FIXME remove warning when type/range checks added
8052
8053@value{GDBN} considers two Modula-2 variables type equivalent if:
8054
8055@itemize @bullet
8056@item
8057They are of types that have been declared equivalent via a @code{TYPE
8058@var{t1} = @var{t2}} statement
8059
8060@item
8061They have been declared on the same line. (Note: This is true of the
8062@sc{gnu} Modula-2 compiler, but it may not be true of other compilers.)
8063@end itemize
8064
8065As long as type checking is enabled, any attempt to combine variables
8066whose types are not equivalent is an error.
8067
8068Range checking is done on all mathematical operations, assignment, array
8069index bounds, and all built-in functions and procedures.
8070
6d2ebf8b 8071@node M2 Scope
c906108c
SS
8072@subsubsection The scope operators @code{::} and @code{.}
8073@cindex scope
41afff9a 8074@cindex @code{.}, Modula-2 scope operator
c906108c
SS
8075@cindex colon, doubled as scope operator
8076@ifinfo
41afff9a 8077@vindex colon-colon@r{, in Modula-2}
c906108c
SS
8078@c Info cannot handle :: but TeX can.
8079@end ifinfo
8080@iftex
41afff9a 8081@vindex ::@r{, in Modula-2}
c906108c
SS
8082@end iftex
8083
8084There are a few subtle differences between the Modula-2 scope operator
8085(@code{.}) and the @value{GDBN} scope operator (@code{::}). The two have
8086similar syntax:
8087
8088@example
8089
8090@var{module} . @var{id}
8091@var{scope} :: @var{id}
8092@end example
8093
8094@noindent
8095where @var{scope} is the name of a module or a procedure,
8096@var{module} the name of a module, and @var{id} is any declared
8097identifier within your program, except another module.
8098
8099Using the @code{::} operator makes @value{GDBN} search the scope
8100specified by @var{scope} for the identifier @var{id}. If it is not
8101found in the specified scope, then @value{GDBN} searches all scopes
8102enclosing the one specified by @var{scope}.
8103
8104Using the @code{.} operator makes @value{GDBN} search the current scope for
8105the identifier specified by @var{id} that was imported from the
8106definition module specified by @var{module}. With this operator, it is
8107an error if the identifier @var{id} was not imported from definition
8108module @var{module}, or if @var{id} is not an identifier in
8109@var{module}.
8110
6d2ebf8b 8111@node GDB/M2
c906108c
SS
8112@subsubsection @value{GDBN} and Modula-2
8113
8114Some @value{GDBN} commands have little use when debugging Modula-2 programs.
8115Five subcommands of @code{set print} and @code{show print} apply
b37052ae 8116specifically to C and C@t{++}: @samp{vtbl}, @samp{demangle},
c906108c 8117@samp{asm-demangle}, @samp{object}, and @samp{union}. The first four
b37052ae 8118apply to C@t{++}, and the last to the C @code{union} type, which has no direct
c906108c
SS
8119analogue in Modula-2.
8120
8121The @code{@@} operator (@pxref{Expressions, ,Expressions}), while available
d4f3574e 8122with any language, is not useful with Modula-2. Its
c906108c 8123intent is to aid the debugging of @dfn{dynamic arrays}, which cannot be
b37052ae 8124created in Modula-2 as they can in C or C@t{++}. However, because an
c906108c 8125address can be specified by an integral constant, the construct
d4f3574e 8126@samp{@{@var{type}@}@var{adrexp}} is still useful.
c906108c
SS
8127
8128@cindex @code{#} in Modula-2
8129In @value{GDBN} scripts, the Modula-2 inequality operator @code{#} is
8130interpreted as the beginning of a comment. Use @code{<>} instead.
c906108c 8131
6d2ebf8b 8132@node Chill
cce74817
JM
8133@subsection Chill
8134
8135The extensions made to @value{GDBN} to support Chill only support output
d4f3574e 8136from the @sc{gnu} Chill compiler. Other Chill compilers are not currently
cce74817
JM
8137supported, and attempting to debug executables produced by them is most
8138likely to give an error as @value{GDBN} reads in the executable's symbol
8139table.
8140
d4f3574e
SS
8141@c This used to say "... following Chill related topics ...", but since
8142@c menus are not shown in the printed manual, it would look awkward.
8143This section covers the Chill related topics and the features
cce74817
JM
8144of @value{GDBN} which support these topics.
8145
8146@menu
104c1213
JM
8147* How modes are displayed:: How modes are displayed
8148* Locations:: Locations and their accesses
cce74817 8149* Values and their Operations:: Values and their Operations
5d161b24 8150* Chill type and range checks::
53a5351d 8151* Chill defaults::
cce74817
JM
8152@end menu
8153
6d2ebf8b 8154@node How modes are displayed
cce74817
JM
8155@subsubsection How modes are displayed
8156
8157The Chill Datatype- (Mode) support of @value{GDBN} is directly related
d4f3574e 8158with the functionality of the @sc{gnu} Chill compiler, and therefore deviates
cce74817
JM
8159slightly from the standard specification of the Chill language. The
8160provided modes are:
d4f3574e
SS
8161
8162@c FIXME: this @table's contents effectively disable @code by using @r
8163@c on every @item. So why does it need @code?
cce74817
JM
8164@table @code
8165@item @r{@emph{Discrete modes:}}
8166@itemize @bullet
8167@item
8168@emph{Integer Modes} which are predefined by @code{BYTE, UBYTE, INT,
8169UINT, LONG, ULONG},
8170@item
5d161b24 8171@emph{Boolean Mode} which is predefined by @code{BOOL},
cce74817 8172@item
5d161b24 8173@emph{Character Mode} which is predefined by @code{CHAR},
cce74817
JM
8174@item
8175@emph{Set Mode} which is displayed by the keyword @code{SET}.
8176@smallexample
8177(@value{GDBP}) ptype x
8178type = SET (karli = 10, susi = 20, fritzi = 100)
8179@end smallexample
8180If the type is an unnumbered set the set element values are omitted.
8181@item
6d2ebf8b
SS
8182@emph{Range Mode} which is displayed by
8183@smallexample
8184@code{type = <basemode>(<lower bound> : <upper bound>)}
8185@end smallexample
8186where @code{<lower bound>, <upper bound>} can be of any discrete literal
8187expression (e.g. set element names).
cce74817
JM
8188@end itemize
8189
8190@item @r{@emph{Powerset Mode:}}
8191A Powerset Mode is displayed by the keyword @code{POWERSET} followed by
d4f3574e 8192the member mode of the powerset. The member mode can be any discrete mode.
cce74817
JM
8193@smallexample
8194(@value{GDBP}) ptype x
8195type = POWERSET SET (egon, hugo, otto)
8196@end smallexample
8197
8198@item @r{@emph{Reference Modes:}}
8199@itemize @bullet
8200@item
d4f3574e 8201@emph{Bound Reference Mode} which is displayed by the keyword @code{REF}
cce74817
JM
8202followed by the mode name to which the reference is bound.
8203@item
8204@emph{Free Reference Mode} which is displayed by the keyword @code{PTR}.
8205@end itemize
8206
8207@item @r{@emph{Procedure mode}}
8208The procedure mode is displayed by @code{type = PROC(<parameter list>)
8209<return mode> EXCEPTIONS (<exception list>)}. The @code{<parameter
d4f3574e
SS
8210list>} is a list of the parameter modes. @code{<return mode>} indicates
8211the mode of the result of the procedure if any. The exceptionlist lists
cce74817
JM
8212all possible exceptions which can be raised by the procedure.
8213
8214@ignore
8215@item @r{@emph{Instance mode}}
8216The instance mode is represented by a structure, which has a static
5d161b24 8217type, and is therefore not really of interest.
cce74817
JM
8218@end ignore
8219
5d161b24 8220@item @r{@emph{Synchronization Modes:}}
cce74817
JM
8221@itemize @bullet
8222@item
6d2ebf8b
SS
8223@emph{Event Mode} which is displayed by
8224@smallexample
8225@code{EVENT (<event length>)}
8226@end smallexample
cce74817
JM
8227where @code{(<event length>)} is optional.
8228@item
6d2ebf8b
SS
8229@emph{Buffer Mode} which is displayed by
8230@smallexample
8231@code{BUFFER (<buffer length>)<buffer element mode>}
8232@end smallexample
8233where @code{(<buffer length>)} is optional.
cce74817
JM
8234@end itemize
8235
5d161b24 8236@item @r{@emph{Timing Modes:}}
cce74817
JM
8237@itemize @bullet
8238@item
8239@emph{Duration Mode} which is predefined by @code{DURATION}
8240@item
8241@emph{Absolute Time Mode} which is predefined by @code{TIME}
8242@end itemize
8243
8244@item @r{@emph{Real Modes:}}
8245Real Modes are predefined with @code{REAL} and @code{LONG_REAL}.
8246
8247@item @r{@emph{String Modes:}}
8248@itemize @bullet
8249@item
6d2ebf8b
SS
8250@emph{Character String Mode} which is displayed by
8251@smallexample
8252@code{CHARS(<string length>)}
8253@end smallexample
8254followed by the keyword @code{VARYING} if the String Mode is a varying
8255mode
cce74817 8256@item
6d2ebf8b
SS
8257@emph{Bit String Mode} which is displayed by
8258@smallexample
8259@code{BOOLS(<string
8260length>)}
8261@end smallexample
cce74817
JM
8262@end itemize
8263
8264@item @r{@emph{Array Mode:}}
8265The Array Mode is displayed by the keyword @code{ARRAY(<range>)}
8266followed by the element mode (which may in turn be an array mode).
8267@smallexample
8268(@value{GDBP}) ptype x
5d161b24
DB
8269type = ARRAY (1:42)
8270 ARRAY (1:20)
cce74817
JM
8271 SET (karli = 10, susi = 20, fritzi = 100)
8272@end smallexample
8273
5d161b24 8274@item @r{@emph{Structure Mode}}
cce74817 8275The Structure mode is displayed by the keyword @code{STRUCT(<field
d4f3574e
SS
8276list>)}. The @code{<field list>} consists of names and modes of fields
8277of the structure. Variant structures have the keyword @code{CASE <field>
8278OF <variant fields> ESAC} in their field list. Since the current version
cce74817
JM
8279of the GNU Chill compiler doesn't implement tag processing (no runtime
8280checks of variant fields, and therefore no debugging info), the output
8281always displays all variant fields.
8282@smallexample
8283(@value{GDBP}) ptype str
8284type = STRUCT (
8285 as x,
8286 bs x,
8287 CASE bs OF
8288 (karli):
8289 cs a
8290 (ott):
8291 ds x
8292 ESAC
8293)
8294@end smallexample
8295@end table
8296
6d2ebf8b 8297@node Locations
cce74817
JM
8298@subsubsection Locations and their accesses
8299
8300A location in Chill is an object which can contain values.
8301
8302A value of a location is generally accessed by the (declared) name of
d4f3574e
SS
8303the location. The output conforms to the specification of values in
8304Chill programs. How values are specified
8305is the topic of the next section, @ref{Values and their Operations}.
cce74817
JM
8306
8307The pseudo-location @code{RESULT} (or @code{result}) can be used to
8308display or change the result of a currently-active procedure:
d4f3574e 8309
cce74817
JM
8310@smallexample
8311set result := EXPR
8312@end smallexample
d4f3574e
SS
8313
8314@noindent
8315This does the same as the Chill action @code{RESULT EXPR} (which
c3f6f71d 8316is not available in @value{GDBN}).
cce74817
JM
8317
8318Values of reference mode locations are printed by @code{PTR(<hex
8319value>)} in case of a free reference mode, and by @code{(REF <reference
d4f3574e 8320mode>) (<hex-value>)} in case of a bound reference. @code{<hex value>}
cce74817
JM
8321represents the address where the reference points to. To access the
8322value of the location referenced by the pointer, use the dereference
d4f3574e 8323operator @samp{->}.
cce74817 8324
6d2ebf8b
SS
8325Values of procedure mode locations are displayed by
8326@smallexample
8327@code{@{ PROC
cce74817 8328(<argument modes> ) <return mode> @} <address> <name of procedure
6d2ebf8b
SS
8329location>}
8330@end smallexample
8331@code{<argument modes>} is a list of modes according to the parameter
8332specification of the procedure and @code{<address>} shows the address of
8333the entry point.
cce74817
JM
8334
8335@ignore
8336Locations of instance modes are displayed just like a structure with two
8337fields specifying the @emph{process type} and the @emph{copy number} of
8338the investigated instance location@footnote{This comes from the current
d4f3574e
SS
8339implementation of instances. They are implemented as a structure (no
8340na). The output should be something like @code{[<name of the process>;
8341<instance number>]}.}. The field names are @code{__proc_type} and
cce74817
JM
8342@code{__proc_copy}.
8343
8344Locations of synchronization modes are displayed like a structure with
8345the field name @code{__event_data} in case of a event mode location, and
8346like a structure with the field @code{__buffer_data} in case of a buffer
8347mode location (refer to previous paragraph).
8348
8349Structure Mode locations are printed by @code{[.<field name>: <value>,
d4f3574e 8350...]}. The @code{<field name>} corresponds to the structure mode
cce74817 8351definition and the layout of @code{<value>} varies depending of the mode
d4f3574e
SS
8352of the field. If the investigated structure mode location is of variant
8353structure mode, the variant parts of the structure are enclosed in curled
8354braces (@samp{@{@}}). Fields enclosed by @samp{@{,@}} are residing
cce74817 8355on the same memory location and represent the current values of the
d4f3574e 8356memory location in their specific modes. Since no tag processing is done
cce74817 8357all variants are displayed. A variant field is printed by
d4f3574e 8358@code{(<variant name>) = .<field name>: <value>}. (who implements the
cce74817
JM
8359stuff ???)
8360@smallexample
8361(@value{GDBP}) print str1 $4 = [.as: 0, .bs: karli, .<TAG>: { (karli) =
8362[.cs: []], (susi) = [.ds: susi]}]
8363@end smallexample
8364@end ignore
8365
8366Substructures of string mode-, array mode- or structure mode-values
8367(e.g. array slices, fields of structure locations) are accessed using
d4f3574e
SS
8368certain operations which are described in the next section, @ref{Values
8369and their Operations}.
cce74817
JM
8370
8371A location value may be interpreted as having a different mode using the
d4f3574e
SS
8372location conversion. This mode conversion is written as @code{<mode
8373name>(<location>)}. The user has to consider that the sizes of the modes
8374have to be equal otherwise an error occurs. Furthermore, no range
8375checking of the location against the destination mode is performed, and
cce74817 8376therefore the result can be quite confusing.
d4f3574e 8377
cce74817
JM
8378@smallexample
8379(@value{GDBP}) print int (s(3 up 4)) XXX TO be filled in !! XXX
8380@end smallexample
8381
6d2ebf8b 8382@node Values and their Operations
cce74817
JM
8383@subsubsection Values and their Operations
8384
8385Values are used to alter locations, to investigate complex structures in
8386more detail or to filter relevant information out of a large amount of
d4f3574e
SS
8387data. There are several (mode dependent) operations defined which enable
8388such investigations. These operations are not only applicable to
cce74817 8389constant values but also to locations, which can become quite useful
d4f3574e 8390when debugging complex structures. During parsing the command line
cce74817
JM
8391(e.g. evaluating an expression) @value{GDBN} treats location names as
8392the values behind these locations.
8393
d4f3574e 8394This section describes how values have to be specified and which
cce74817
JM
8395operations are legal to be used with such values.
8396
8397@table @code
8398@item Literal Values
d4f3574e
SS
8399Literal values are specified in the same manner as in @sc{gnu} Chill programs.
8400For detailed specification refer to the @sc{gnu} Chill implementation Manual
cce74817 8401chapter 1.5.
d4f3574e
SS
8402@c FIXME: if the Chill Manual is a Texinfo documents, the above should
8403@c be converted to a @ref.
cce74817 8404
5d161b24 8405@ignore
cce74817
JM
8406@itemize @bullet
8407@item
8408@emph{Integer Literals} are specified in the same manner as in Chill
d4f3574e 8409programs (refer to the Chill Standard z200/88 chpt 5.2.4.2)
cce74817
JM
8410@item
8411@emph{Boolean Literals} are defined by @code{TRUE} and @code{FALSE}.
8412@item
8413@emph{Character Literals} are defined by @code{'<character>'}. (e.g.
8414@code{'M'})
8415@item
8416@emph{Set Literals} are defined by a name which was specified in a set
d4f3574e 8417mode. The value delivered by a Set Literal is the set value. This is
b37052ae 8418comparable to an enumeration in C/C@t{++} language.
cce74817 8419@item
d4f3574e 8420@emph{Emptiness Literal} is predefined by @code{NULL}. The value of the
cce74817 8421emptiness literal delivers either the empty reference value, the empty
5d161b24 8422procedure value or the empty instance value.
cce74817
JM
8423
8424@item
8425@emph{Character String Literals} are defined by a sequence of characters
d4f3574e 8426enclosed in single- or double quotes. If a single- or double quote has
cce74817
JM
8427to be part of the string literal it has to be stuffed (specified twice).
8428@item
8429@emph{Bitstring Literals} are specified in the same manner as in Chill
8430programs (refer z200/88 chpt 5.2.4.8).
8431@item
8432@emph{Floating point literals} are specified in the same manner as in
d4f3574e 8433(gnu-)Chill programs (refer @sc{gnu} Chill implementation Manual chapter 1.5).
cce74817
JM
8434@end itemize
8435@end ignore
8436
8437@item Tuple Values
8438A tuple is specified by @code{<mode name>[<tuple>]}, where @code{<mode
d4f3574e 8439name>} can be omitted if the mode of the tuple is unambiguous. This
cce74817
JM
8440unambiguity is derived from the context of a evaluated expression.
8441@code{<tuple>} can be one of the following:
d4f3574e 8442
cce74817
JM
8443@itemize @bullet
8444@item @emph{Powerset Tuple}
8445@item @emph{Array Tuple}
8446@item @emph{Structure Tuple}
8447Powerset tuples, array tuples and structure tuples are specified in the
d4f3574e 8448same manner as in Chill programs refer to z200/88 chpt 5.2.5.
cce74817
JM
8449@end itemize
8450
8451@item String Element Value
6d2ebf8b
SS
8452A string element value is specified by
8453@smallexample
8454@code{<string value>(<index>)}
8455@end smallexample
d4f3574e 8456where @code{<index>} is a integer expression. It delivers a character
cce74817
JM
8457value which is equivalent to the character indexed by @code{<index>} in
8458the string.
8459
8460@item String Slice Value
8461A string slice value is specified by @code{<string value>(<slice
8462spec>)}, where @code{<slice spec>} can be either a range of integer
8463expressions or specified by @code{<start expr> up <size>}.
8464@code{<size>} denotes the number of elements which the slice contains.
8465The delivered value is a string value, which is part of the specified
8466string.
8467
8468@item Array Element Values
8469An array element value is specified by @code{<array value>(<expr>)} and
8470delivers a array element value of the mode of the specified array.
8471
8472@item Array Slice Values
8473An array slice is specified by @code{<array value>(<slice spec>)}, where
8474@code{<slice spec>} can be either a range specified by expressions or by
d4f3574e
SS
8475@code{<start expr> up <size>}. @code{<size>} denotes the number of
8476arrayelements the slice contains. The delivered value is an array value
cce74817
JM
8477which is part of the specified array.
8478
8479@item Structure Field Values
8480A structure field value is derived by @code{<structure value>.<field
d4f3574e
SS
8481name>}, where @code{<field name>} indicates the name of a field specified
8482in the mode definition of the structure. The mode of the delivered value
cce74817
JM
8483corresponds to this mode definition in the structure definition.
8484
8485@item Procedure Call Value
8486The procedure call value is derived from the return value of the
8487procedure@footnote{If a procedure call is used for instance in an
8488expression, then this procedure is called with all its side
d4f3574e 8489effects. This can lead to confusing results if used carelessly.}.
cce74817 8490
d4f3574e 8491Values of duration mode locations are represented by @code{ULONG} literals.
cce74817 8492
6d2ebf8b
SS
8493Values of time mode locations appear as
8494@smallexample
8495@code{TIME(<secs>:<nsecs>)}
8496@end smallexample
8497
cce74817
JM
8498
8499@ignore
8500This is not implemented yet:
8501@item Built-in Value
8502@noindent
8503The following built in functions are provided:
d4f3574e 8504
cce74817
JM
8505@table @code
8506@item @code{ADDR()}
8507@item @code{NUM()}
8508@item @code{PRED()}
8509@item @code{SUCC()}
8510@item @code{ABS()}
8511@item @code{CARD()}
8512@item @code{MAX()}
8513@item @code{MIN()}
8514@item @code{SIZE()}
8515@item @code{UPPER()}
8516@item @code{LOWER()}
8517@item @code{LENGTH()}
8518@item @code{SIN()}
8519@item @code{COS()}
8520@item @code{TAN()}
8521@item @code{ARCSIN()}
8522@item @code{ARCCOS()}
8523@item @code{ARCTAN()}
8524@item @code{EXP()}
8525@item @code{LN()}
8526@item @code{LOG()}
8527@item @code{SQRT()}
8528@end table
8529
8530For a detailed description refer to the GNU Chill implementation manual
8531chapter 1.6.
8532@end ignore
8533
8534@item Zero-adic Operator Value
8535The zero-adic operator value is derived from the instance value for the
8536current active process.
8537
8538@item Expression Values
8539The value delivered by an expression is the result of the evaluation of
d4f3574e 8540the specified expression. If there are error conditions (mode
cce74817 8541incompatibility, etc.) the evaluation of expressions is aborted with a
d4f3574e 8542corresponding error message. Expressions may be parenthesised which
cce74817 8543causes the evaluation of this expression before any other expression
d4f3574e 8544which uses the result of the parenthesised expression. The following
cce74817 8545operators are supported by @value{GDBN}:
d4f3574e 8546
cce74817
JM
8547@table @code
8548@item @code{OR, ORIF, XOR}
d4f3574e
SS
8549@itemx @code{AND, ANDIF}
8550@itemx @code{NOT}
cce74817 8551Logical operators defined over operands of boolean mode.
d4f3574e 8552
cce74817
JM
8553@item @code{=, /=}
8554Equality and inequality operators defined over all modes.
d4f3574e 8555
cce74817 8556@item @code{>, >=}
d4f3574e 8557@itemx @code{<, <=}
cce74817 8558Relational operators defined over predefined modes.
d4f3574e 8559
cce74817 8560@item @code{+, -}
d4f3574e 8561@itemx @code{*, /, MOD, REM}
cce74817 8562Arithmetic operators defined over predefined modes.
d4f3574e 8563
cce74817
JM
8564@item @code{-}
8565Change sign operator.
d4f3574e 8566
cce74817
JM
8567@item @code{//}
8568String concatenation operator.
d4f3574e 8569
cce74817
JM
8570@item @code{()}
8571String repetition operator.
d4f3574e 8572
cce74817
JM
8573@item @code{->}
8574Referenced location operator which can be used either to take the
8575address of a location (@code{->loc}), or to dereference a reference
8576location (@code{loc->}).
d4f3574e 8577
cce74817 8578@item @code{OR, XOR}
d4f3574e
SS
8579@itemx @code{AND}
8580@itemx @code{NOT}
cce74817 8581Powerset and bitstring operators.
d4f3574e 8582
cce74817 8583@item @code{>, >=}
d4f3574e 8584@itemx @code{<, <=}
cce74817 8585Powerset inclusion operators.
d4f3574e 8586
cce74817
JM
8587@item @code{IN}
8588Membership operator.
8589@end table
8590@end table
8591
6d2ebf8b 8592@node Chill type and range checks
cce74817
JM
8593@subsubsection Chill type and range checks
8594
8595@value{GDBN} considers two Chill variables mode equivalent if the sizes
d4f3574e 8596of the two modes are equal. This rule applies recursively to more
cce74817 8597complex datatypes which means that complex modes are treated
d4f3574e 8598equivalent if all element modes (which also can be complex modes like
cce74817
JM
8599structures, arrays, etc.) have the same size.
8600
8601Range checking is done on all mathematical operations, assignment, array
8602index bounds and all built in procedures.
8603
8604Strong type checks are forced using the @value{GDBN} command @code{set
d4f3574e 8605check strong}. This enforces strong type and range checks on all
cce74817
JM
8606operations where Chill constructs are used (expressions, built in
8607functions, etc.) in respect to the semantics as defined in the z.200
8608language specification.
8609
cce74817
JM
8610All checks can be disabled by the @value{GDBN} command @code{set check
8611off}.
8612
5d161b24 8613@ignore
53a5351d 8614@c Deviations from the Chill Standard Z200/88
cce74817
JM
8615see last paragraph ?
8616@end ignore
8617
6d2ebf8b 8618@node Chill defaults
cce74817
JM
8619@subsubsection Chill defaults
8620
8621If type and range checking are set automatically by @value{GDBN}, they
8622both default to @code{on} whenever the working language changes to
d4f3574e 8623Chill. This happens regardless of whether you or @value{GDBN}
cce74817
JM
8624selected the working language.
8625
8626If you allow @value{GDBN} to set the language automatically, then entering
8627code compiled from a file whose name ends with @file{.ch} sets the
d4f3574e 8628working language to Chill. @xref{Automatically, ,Having @value{GDBN} set
cce74817
JM
8629the language automatically}, for further details.
8630
6d2ebf8b 8631@node Symbols
c906108c
SS
8632@chapter Examining the Symbol Table
8633
d4f3574e 8634The commands described in this chapter allow you to inquire about the
c906108c
SS
8635symbols (names of variables, functions and types) defined in your
8636program. This information is inherent in the text of your program and
8637does not change as your program executes. @value{GDBN} finds it in your
8638program's symbol table, in the file indicated when you started @value{GDBN}
8639(@pxref{File Options, ,Choosing files}), or by one of the
8640file-management commands (@pxref{Files, ,Commands to specify files}).
8641
8642@cindex symbol names
8643@cindex names of symbols
8644@cindex quoting names
8645Occasionally, you may need to refer to symbols that contain unusual
8646characters, which @value{GDBN} ordinarily treats as word delimiters. The
8647most frequent case is in referring to static variables in other
8648source files (@pxref{Variables,,Program variables}). File names
8649are recorded in object files as debugging symbols, but @value{GDBN} would
8650ordinarily parse a typical file name, like @file{foo.c}, as the three words
8651@samp{foo} @samp{.} @samp{c}. To allow @value{GDBN} to recognize
8652@samp{foo.c} as a single symbol, enclose it in single quotes; for example,
8653
8654@example
8655p 'foo.c'::x
8656@end example
8657
8658@noindent
8659looks up the value of @code{x} in the scope of the file @file{foo.c}.
8660
8661@table @code
8662@kindex info address
b37052ae 8663@cindex address of a symbol
c906108c
SS
8664@item info address @var{symbol}
8665Describe where the data for @var{symbol} is stored. For a register
8666variable, this says which register it is kept in. For a non-register
8667local variable, this prints the stack-frame offset at which the variable
8668is always stored.
8669
8670Note the contrast with @samp{print &@var{symbol}}, which does not work
8671at all for a register variable, and for a stack local variable prints
8672the exact address of the current instantiation of the variable.
8673
3d67e040 8674@kindex info symbol
b37052ae 8675@cindex symbol from address
3d67e040
EZ
8676@item info symbol @var{addr}
8677Print the name of a symbol which is stored at the address @var{addr}.
8678If no symbol is stored exactly at @var{addr}, @value{GDBN} prints the
8679nearest symbol and an offset from it:
8680
8681@example
8682(@value{GDBP}) info symbol 0x54320
8683_initialize_vx + 396 in section .text
8684@end example
8685
8686@noindent
8687This is the opposite of the @code{info address} command. You can use
8688it to find out the name of a variable or a function given its address.
8689
c906108c 8690@kindex whatis
d4f3574e
SS
8691@item whatis @var{expr}
8692Print the data type of expression @var{expr}. @var{expr} is not
c906108c
SS
8693actually evaluated, and any side-effecting operations (such as
8694assignments or function calls) inside it do not take place.
8695@xref{Expressions, ,Expressions}.
8696
8697@item whatis
8698Print the data type of @code{$}, the last value in the value history.
8699
8700@kindex ptype
8701@item ptype @var{typename}
8702Print a description of data type @var{typename}. @var{typename} may be
7a292a7a
SS
8703the name of a type, or for C code it may have the form @samp{class
8704@var{class-name}}, @samp{struct @var{struct-tag}}, @samp{union
8705@var{union-tag}} or @samp{enum @var{enum-tag}}.
c906108c 8706
d4f3574e 8707@item ptype @var{expr}
c906108c 8708@itemx ptype
d4f3574e 8709Print a description of the type of expression @var{expr}. @code{ptype}
c906108c
SS
8710differs from @code{whatis} by printing a detailed description, instead
8711of just the name of the type.
8712
8713For example, for this variable declaration:
8714
8715@example
8716struct complex @{double real; double imag;@} v;
8717@end example
8718
8719@noindent
8720the two commands give this output:
8721
8722@example
8723@group
8724(@value{GDBP}) whatis v
8725type = struct complex
8726(@value{GDBP}) ptype v
8727type = struct complex @{
8728 double real;
8729 double imag;
8730@}
8731@end group
8732@end example
8733
8734@noindent
8735As with @code{whatis}, using @code{ptype} without an argument refers to
8736the type of @code{$}, the last value in the value history.
8737
8738@kindex info types
8739@item info types @var{regexp}
8740@itemx info types
d4f3574e 8741Print a brief description of all types whose names match @var{regexp}
c906108c
SS
8742(or all types in your program, if you supply no argument). Each
8743complete typename is matched as though it were a complete line; thus,
8744@samp{i type value} gives information on all types in your program whose
d4f3574e 8745names include the string @code{value}, but @samp{i type ^value$} gives
c906108c
SS
8746information only on types whose complete name is @code{value}.
8747
8748This command differs from @code{ptype} in two ways: first, like
8749@code{whatis}, it does not print a detailed description; second, it
8750lists all source files where a type is defined.
8751
b37052ae
EZ
8752@kindex info scope
8753@cindex local variables
8754@item info scope @var{addr}
8755List all the variables local to a particular scope. This command
8756accepts a location---a function name, a source line, or an address
8757preceded by a @samp{*}, and prints all the variables local to the
8758scope defined by that location. For example:
8759
8760@smallexample
8761(@value{GDBP}) @b{info scope command_line_handler}
8762Scope for command_line_handler:
8763Symbol rl is an argument at stack/frame offset 8, length 4.
8764Symbol linebuffer is in static storage at address 0x150a18, length 4.
8765Symbol linelength is in static storage at address 0x150a1c, length 4.
8766Symbol p is a local variable in register $esi, length 4.
8767Symbol p1 is a local variable in register $ebx, length 4.
8768Symbol nline is a local variable in register $edx, length 4.
8769Symbol repeat is a local variable at frame offset -8, length 4.
8770@end smallexample
8771
f5c37c66
EZ
8772@noindent
8773This command is especially useful for determining what data to collect
8774during a @dfn{trace experiment}, see @ref{Tracepoint Actions,
8775collect}.
8776
c906108c
SS
8777@kindex info source
8778@item info source
8779Show the name of the current source file---that is, the source file for
8780the function containing the current point of execution---and the language
8781it was written in.
8782
8783@kindex info sources
8784@item info sources
8785Print the names of all source files in your program for which there is
8786debugging information, organized into two lists: files whose symbols
8787have already been read, and files whose symbols will be read when needed.
8788
8789@kindex info functions
8790@item info functions
8791Print the names and data types of all defined functions.
8792
8793@item info functions @var{regexp}
8794Print the names and data types of all defined functions
8795whose names contain a match for regular expression @var{regexp}.
8796Thus, @samp{info fun step} finds all functions whose names
8797include @code{step}; @samp{info fun ^step} finds those whose names
1c5dfdad
MS
8798start with @code{step}. If a function name contains characters
8799that conflict with the regular expression language (eg.
8800@samp{operator*()}), they may be quoted with a backslash.
c906108c
SS
8801
8802@kindex info variables
8803@item info variables
8804Print the names and data types of all variables that are declared
8805outside of functions (i.e., excluding local variables).
8806
8807@item info variables @var{regexp}
8808Print the names and data types of all variables (except for local
8809variables) whose names contain a match for regular expression
8810@var{regexp}.
8811
8812@ignore
8813This was never implemented.
8814@kindex info methods
8815@item info methods
8816@itemx info methods @var{regexp}
8817The @code{info methods} command permits the user to examine all defined
b37052ae
EZ
8818methods within C@t{++} program, or (with the @var{regexp} argument) a
8819specific set of methods found in the various C@t{++} classes. Many
8820C@t{++} classes provide a large number of methods. Thus, the output
c906108c
SS
8821from the @code{ptype} command can be overwhelming and hard to use. The
8822@code{info-methods} command filters the methods, printing only those
8823which match the regular-expression @var{regexp}.
8824@end ignore
8825
c906108c
SS
8826@cindex reloading symbols
8827Some systems allow individual object files that make up your program to
7a292a7a
SS
8828be replaced without stopping and restarting your program. For example,
8829in VxWorks you can simply recompile a defective object file and keep on
8830running. If you are running on one of these systems, you can allow
8831@value{GDBN} to reload the symbols for automatically relinked modules:
c906108c
SS
8832
8833@table @code
8834@kindex set symbol-reloading
8835@item set symbol-reloading on
8836Replace symbol definitions for the corresponding source file when an
8837object file with a particular name is seen again.
8838
8839@item set symbol-reloading off
6d2ebf8b
SS
8840Do not replace symbol definitions when encountering object files of the
8841same name more than once. This is the default state; if you are not
8842running on a system that permits automatic relinking of modules, you
8843should leave @code{symbol-reloading} off, since otherwise @value{GDBN}
8844may discard symbols when linking large programs, that may contain
8845several modules (from different directories or libraries) with the same
8846name.
c906108c
SS
8847
8848@kindex show symbol-reloading
8849@item show symbol-reloading
8850Show the current @code{on} or @code{off} setting.
8851@end table
c906108c 8852
c906108c
SS
8853@kindex set opaque-type-resolution
8854@item set opaque-type-resolution on
8855Tell @value{GDBN} to resolve opaque types. An opaque type is a type
8856declared as a pointer to a @code{struct}, @code{class}, or
8857@code{union}---for example, @code{struct MyType *}---that is used in one
8858source file although the full declaration of @code{struct MyType} is in
8859another source file. The default is on.
8860
8861A change in the setting of this subcommand will not take effect until
8862the next time symbols for a file are loaded.
8863
8864@item set opaque-type-resolution off
8865Tell @value{GDBN} not to resolve opaque types. In this case, the type
8866is printed as follows:
8867@smallexample
8868@{<no data fields>@}
8869@end smallexample
8870
8871@kindex show opaque-type-resolution
8872@item show opaque-type-resolution
8873Show whether opaque types are resolved or not.
c906108c
SS
8874
8875@kindex maint print symbols
8876@cindex symbol dump
8877@kindex maint print psymbols
8878@cindex partial symbol dump
8879@item maint print symbols @var{filename}
8880@itemx maint print psymbols @var{filename}
8881@itemx maint print msymbols @var{filename}
8882Write a dump of debugging symbol data into the file @var{filename}.
8883These commands are used to debug the @value{GDBN} symbol-reading code. Only
8884symbols with debugging data are included. If you use @samp{maint print
8885symbols}, @value{GDBN} includes all the symbols for which it has already
8886collected full details: that is, @var{filename} reflects symbols for
8887only those files whose symbols @value{GDBN} has read. You can use the
8888command @code{info sources} to find out which files these are. If you
8889use @samp{maint print psymbols} instead, the dump shows information about
8890symbols that @value{GDBN} only knows partially---that is, symbols defined in
8891files that @value{GDBN} has skimmed, but not yet read completely. Finally,
8892@samp{maint print msymbols} dumps just the minimal symbol information
8893required for each object file from which @value{GDBN} has read some symbols.
8894@xref{Files, ,Commands to specify files}, for a discussion of how
8895@value{GDBN} reads symbols (in the description of @code{symbol-file}).
8896@end table
8897
6d2ebf8b 8898@node Altering
c906108c
SS
8899@chapter Altering Execution
8900
8901Once you think you have found an error in your program, you might want to
8902find out for certain whether correcting the apparent error would lead to
8903correct results in the rest of the run. You can find the answer by
8904experiment, using the @value{GDBN} features for altering execution of the
8905program.
8906
8907For example, you can store new values into variables or memory
7a292a7a
SS
8908locations, give your program a signal, restart it at a different
8909address, or even return prematurely from a function.
c906108c
SS
8910
8911@menu
8912* Assignment:: Assignment to variables
8913* Jumping:: Continuing at a different address
c906108c 8914* Signaling:: Giving your program a signal
c906108c
SS
8915* Returning:: Returning from a function
8916* Calling:: Calling your program's functions
8917* Patching:: Patching your program
8918@end menu
8919
6d2ebf8b 8920@node Assignment
c906108c
SS
8921@section Assignment to variables
8922
8923@cindex assignment
8924@cindex setting variables
8925To alter the value of a variable, evaluate an assignment expression.
8926@xref{Expressions, ,Expressions}. For example,
8927
8928@example
8929print x=4
8930@end example
8931
8932@noindent
8933stores the value 4 into the variable @code{x}, and then prints the
5d161b24 8934value of the assignment expression (which is 4).
c906108c
SS
8935@xref{Languages, ,Using @value{GDBN} with Different Languages}, for more
8936information on operators in supported languages.
c906108c
SS
8937
8938@kindex set variable
8939@cindex variables, setting
8940If you are not interested in seeing the value of the assignment, use the
8941@code{set} command instead of the @code{print} command. @code{set} is
8942really the same as @code{print} except that the expression's value is
8943not printed and is not put in the value history (@pxref{Value History,
8944,Value history}). The expression is evaluated only for its effects.
8945
c906108c
SS
8946If the beginning of the argument string of the @code{set} command
8947appears identical to a @code{set} subcommand, use the @code{set
8948variable} command instead of just @code{set}. This command is identical
8949to @code{set} except for its lack of subcommands. For example, if your
8950program has a variable @code{width}, you get an error if you try to set
8951a new value with just @samp{set width=13}, because @value{GDBN} has the
8952command @code{set width}:
8953
8954@example
8955(@value{GDBP}) whatis width
8956type = double
8957(@value{GDBP}) p width
8958$4 = 13
8959(@value{GDBP}) set width=47
8960Invalid syntax in expression.
8961@end example
8962
8963@noindent
8964The invalid expression, of course, is @samp{=47}. In
8965order to actually set the program's variable @code{width}, use
8966
8967@example
8968(@value{GDBP}) set var width=47
8969@end example
53a5351d 8970
c906108c
SS
8971Because the @code{set} command has many subcommands that can conflict
8972with the names of program variables, it is a good idea to use the
8973@code{set variable} command instead of just @code{set}. For example, if
8974your program has a variable @code{g}, you run into problems if you try
8975to set a new value with just @samp{set g=4}, because @value{GDBN} has
8976the command @code{set gnutarget}, abbreviated @code{set g}:
8977
8978@example
8979@group
8980(@value{GDBP}) whatis g
8981type = double
8982(@value{GDBP}) p g
8983$1 = 1
8984(@value{GDBP}) set g=4
2df3850c 8985(@value{GDBP}) p g
c906108c
SS
8986$2 = 1
8987(@value{GDBP}) r
8988The program being debugged has been started already.
8989Start it from the beginning? (y or n) y
8990Starting program: /home/smith/cc_progs/a.out
6d2ebf8b
SS
8991"/home/smith/cc_progs/a.out": can't open to read symbols:
8992 Invalid bfd target.
c906108c
SS
8993(@value{GDBP}) show g
8994The current BFD target is "=4".
8995@end group
8996@end example
8997
8998@noindent
8999The program variable @code{g} did not change, and you silently set the
9000@code{gnutarget} to an invalid value. In order to set the variable
9001@code{g}, use
9002
9003@example
9004(@value{GDBP}) set var g=4
9005@end example
c906108c
SS
9006
9007@value{GDBN} allows more implicit conversions in assignments than C; you can
9008freely store an integer value into a pointer variable or vice versa,
9009and you can convert any structure to any other structure that is the
9010same length or shorter.
9011@comment FIXME: how do structs align/pad in these conversions?
9012@comment /doc@cygnus.com 18dec1990
9013
9014To store values into arbitrary places in memory, use the @samp{@{@dots{}@}}
9015construct to generate a value of specified type at a specified address
9016(@pxref{Expressions, ,Expressions}). For example, @code{@{int@}0x83040} refers
9017to memory location @code{0x83040} as an integer (which implies a certain size
9018and representation in memory), and
9019
9020@example
9021set @{int@}0x83040 = 4
9022@end example
9023
9024@noindent
9025stores the value 4 into that memory location.
9026
6d2ebf8b 9027@node Jumping
c906108c
SS
9028@section Continuing at a different address
9029
9030Ordinarily, when you continue your program, you do so at the place where
9031it stopped, with the @code{continue} command. You can instead continue at
9032an address of your own choosing, with the following commands:
9033
9034@table @code
9035@kindex jump
9036@item jump @var{linespec}
9037Resume execution at line @var{linespec}. Execution stops again
9038immediately if there is a breakpoint there. @xref{List, ,Printing
9039source lines}, for a description of the different forms of
9040@var{linespec}. It is common practice to use the @code{tbreak} command
9041in conjunction with @code{jump}. @xref{Set Breaks, ,Setting
9042breakpoints}.
9043
9044The @code{jump} command does not change the current stack frame, or
9045the stack pointer, or the contents of any memory location or any
9046register other than the program counter. If line @var{linespec} is in
9047a different function from the one currently executing, the results may
9048be bizarre if the two functions expect different patterns of arguments or
9049of local variables. For this reason, the @code{jump} command requests
9050confirmation if the specified line is not in the function currently
9051executing. However, even bizarre results are predictable if you are
9052well acquainted with the machine-language code of your program.
9053
9054@item jump *@var{address}
9055Resume execution at the instruction at address @var{address}.
9056@end table
9057
c906108c 9058@c Doesn't work on HP-UX; have to set $pcoqh and $pcoqt.
53a5351d
JM
9059On many systems, you can get much the same effect as the @code{jump}
9060command by storing a new value into the register @code{$pc}. The
9061difference is that this does not start your program running; it only
9062changes the address of where it @emph{will} run when you continue. For
9063example,
c906108c
SS
9064
9065@example
9066set $pc = 0x485
9067@end example
9068
9069@noindent
9070makes the next @code{continue} command or stepping command execute at
9071address @code{0x485}, rather than at the address where your program stopped.
9072@xref{Continuing and Stepping, ,Continuing and stepping}.
c906108c
SS
9073
9074The most common occasion to use the @code{jump} command is to back
9075up---perhaps with more breakpoints set---over a portion of a program
9076that has already executed, in order to examine its execution in more
9077detail.
9078
c906108c 9079@c @group
6d2ebf8b 9080@node Signaling
c906108c
SS
9081@section Giving your program a signal
9082
9083@table @code
9084@kindex signal
9085@item signal @var{signal}
9086Resume execution where your program stopped, but immediately give it the
9087signal @var{signal}. @var{signal} can be the name or the number of a
9088signal. For example, on many systems @code{signal 2} and @code{signal
9089SIGINT} are both ways of sending an interrupt signal.
9090
9091Alternatively, if @var{signal} is zero, continue execution without
9092giving a signal. This is useful when your program stopped on account of
9093a signal and would ordinary see the signal when resumed with the
9094@code{continue} command; @samp{signal 0} causes it to resume without a
9095signal.
9096
9097@code{signal} does not repeat when you press @key{RET} a second time
9098after executing the command.
9099@end table
9100@c @end group
9101
9102Invoking the @code{signal} command is not the same as invoking the
9103@code{kill} utility from the shell. Sending a signal with @code{kill}
9104causes @value{GDBN} to decide what to do with the signal depending on
9105the signal handling tables (@pxref{Signals}). The @code{signal} command
9106passes the signal directly to your program.
9107
c906108c 9108
6d2ebf8b 9109@node Returning
c906108c
SS
9110@section Returning from a function
9111
9112@table @code
9113@cindex returning from a function
9114@kindex return
9115@item return
9116@itemx return @var{expression}
9117You can cancel execution of a function call with the @code{return}
9118command. If you give an
9119@var{expression} argument, its value is used as the function's return
9120value.
9121@end table
9122
9123When you use @code{return}, @value{GDBN} discards the selected stack frame
9124(and all frames within it). You can think of this as making the
9125discarded frame return prematurely. If you wish to specify a value to
9126be returned, give that value as the argument to @code{return}.
9127
9128This pops the selected stack frame (@pxref{Selection, ,Selecting a
9129frame}), and any other frames inside of it, leaving its caller as the
9130innermost remaining frame. That frame becomes selected. The
9131specified value is stored in the registers used for returning values
9132of functions.
9133
9134The @code{return} command does not resume execution; it leaves the
9135program stopped in the state that would exist if the function had just
9136returned. In contrast, the @code{finish} command (@pxref{Continuing
9137and Stepping, ,Continuing and stepping}) resumes execution until the
9138selected stack frame returns naturally.
9139
6d2ebf8b 9140@node Calling
c906108c
SS
9141@section Calling program functions
9142
9143@cindex calling functions
9144@kindex call
9145@table @code
9146@item call @var{expr}
9147Evaluate the expression @var{expr} without displaying @code{void}
9148returned values.
9149@end table
9150
9151You can use this variant of the @code{print} command if you want to
9152execute a function from your program, but without cluttering the output
5d161b24
DB
9153with @code{void} returned values. If the result is not void, it
9154is printed and saved in the value history.
c906108c 9155
c906108c
SS
9156For the A29K, a user-controlled variable @code{call_scratch_address},
9157specifies the location of a scratch area to be used when @value{GDBN}
9158calls a function in the target. This is necessary because the usual
9159method of putting the scratch area on the stack does not work in systems
9160that have separate instruction and data spaces.
c906108c 9161
6d2ebf8b 9162@node Patching
c906108c 9163@section Patching programs
7a292a7a 9164
c906108c
SS
9165@cindex patching binaries
9166@cindex writing into executables
c906108c 9167@cindex writing into corefiles
c906108c 9168
7a292a7a
SS
9169By default, @value{GDBN} opens the file containing your program's
9170executable code (or the corefile) read-only. This prevents accidental
9171alterations to machine code; but it also prevents you from intentionally
9172patching your program's binary.
c906108c
SS
9173
9174If you'd like to be able to patch the binary, you can specify that
9175explicitly with the @code{set write} command. For example, you might
9176want to turn on internal debugging flags, or even to make emergency
9177repairs.
9178
9179@table @code
9180@kindex set write
9181@item set write on
9182@itemx set write off
7a292a7a
SS
9183If you specify @samp{set write on}, @value{GDBN} opens executable and
9184core files for both reading and writing; if you specify @samp{set write
c906108c
SS
9185off} (the default), @value{GDBN} opens them read-only.
9186
9187If you have already loaded a file, you must load it again (using the
7a292a7a
SS
9188@code{exec-file} or @code{core-file} command) after changing @code{set
9189write}, for your new setting to take effect.
c906108c
SS
9190
9191@item show write
9192@kindex show write
7a292a7a
SS
9193Display whether executable files and core files are opened for writing
9194as well as reading.
c906108c
SS
9195@end table
9196
6d2ebf8b 9197@node GDB Files
c906108c
SS
9198@chapter @value{GDBN} Files
9199
7a292a7a
SS
9200@value{GDBN} needs to know the file name of the program to be debugged,
9201both in order to read its symbol table and in order to start your
9202program. To debug a core dump of a previous run, you must also tell
9203@value{GDBN} the name of the core dump file.
c906108c
SS
9204
9205@menu
9206* Files:: Commands to specify files
9207* Symbol Errors:: Errors reading symbol files
9208@end menu
9209
6d2ebf8b 9210@node Files
c906108c 9211@section Commands to specify files
c906108c 9212
7a292a7a 9213@cindex symbol table
c906108c 9214@cindex core dump file
7a292a7a
SS
9215
9216You may want to specify executable and core dump file names. The usual
9217way to do this is at start-up time, using the arguments to
9218@value{GDBN}'s start-up commands (@pxref{Invocation, , Getting In and
9219Out of @value{GDBN}}).
c906108c
SS
9220
9221Occasionally it is necessary to change to a different file during a
9222@value{GDBN} session. Or you may run @value{GDBN} and forget to specify
9223a file you want to use. In these situations the @value{GDBN} commands
9224to specify new files are useful.
9225
9226@table @code
9227@cindex executable file
9228@kindex file
9229@item file @var{filename}
9230Use @var{filename} as the program to be debugged. It is read for its
9231symbols and for the contents of pure memory. It is also the program
9232executed when you use the @code{run} command. If you do not specify a
5d161b24
DB
9233directory and the file is not found in the @value{GDBN} working directory,
9234@value{GDBN} uses the environment variable @code{PATH} as a list of
9235directories to search, just as the shell does when looking for a program
9236to run. You can change the value of this variable, for both @value{GDBN}
c906108c
SS
9237and your program, using the @code{path} command.
9238
6d2ebf8b 9239On systems with memory-mapped files, an auxiliary file named
c906108c
SS
9240@file{@var{filename}.syms} may hold symbol table information for
9241@var{filename}. If so, @value{GDBN} maps in the symbol table from
9242@file{@var{filename}.syms}, starting up more quickly. See the
9243descriptions of the file options @samp{-mapped} and @samp{-readnow}
9244(available on the command line, and with the commands @code{file},
5d161b24 9245@code{symbol-file}, or @code{add-symbol-file}, described below),
c906108c 9246for more information.
c906108c
SS
9247
9248@item file
9249@code{file} with no argument makes @value{GDBN} discard any information it
9250has on both executable file and the symbol table.
9251
9252@kindex exec-file
9253@item exec-file @r{[} @var{filename} @r{]}
9254Specify that the program to be run (but not the symbol table) is found
9255in @var{filename}. @value{GDBN} searches the environment variable @code{PATH}
9256if necessary to locate your program. Omitting @var{filename} means to
9257discard information on the executable file.
9258
9259@kindex symbol-file
9260@item symbol-file @r{[} @var{filename} @r{]}
9261Read symbol table information from file @var{filename}. @code{PATH} is
9262searched when necessary. Use the @code{file} command to get both symbol
9263table and program to run from the same file.
9264
9265@code{symbol-file} with no argument clears out @value{GDBN} information on your
9266program's symbol table.
9267
5d161b24 9268The @code{symbol-file} command causes @value{GDBN} to forget the contents
c906108c
SS
9269of its convenience variables, the value history, and all breakpoints and
9270auto-display expressions. This is because they may contain pointers to
9271the internal data recording symbols and data types, which are part of
9272the old symbol table data being discarded inside @value{GDBN}.
9273
9274@code{symbol-file} does not repeat if you press @key{RET} again after
9275executing it once.
9276
9277When @value{GDBN} is configured for a particular environment, it
9278understands debugging information in whatever format is the standard
9279generated for that environment; you may use either a @sc{gnu} compiler, or
9280other compilers that adhere to the local conventions.
c906108c
SS
9281Best results are usually obtained from @sc{gnu} compilers; for example,
9282using @code{@value{GCC}} you can generate debugging information for
9283optimized code.
c906108c
SS
9284
9285For most kinds of object files, with the exception of old SVR3 systems
9286using COFF, the @code{symbol-file} command does not normally read the
9287symbol table in full right away. Instead, it scans the symbol table
9288quickly to find which source files and which symbols are present. The
9289details are read later, one source file at a time, as they are needed.
9290
9291The purpose of this two-stage reading strategy is to make @value{GDBN}
9292start up faster. For the most part, it is invisible except for
9293occasional pauses while the symbol table details for a particular source
9294file are being read. (The @code{set verbose} command can turn these
9295pauses into messages if desired. @xref{Messages/Warnings, ,Optional
9296warnings and messages}.)
9297
c906108c
SS
9298We have not implemented the two-stage strategy for COFF yet. When the
9299symbol table is stored in COFF format, @code{symbol-file} reads the
9300symbol table data in full right away. Note that ``stabs-in-COFF''
9301still does the two-stage strategy, since the debug info is actually
9302in stabs format.
9303
9304@kindex readnow
9305@cindex reading symbols immediately
9306@cindex symbols, reading immediately
9307@kindex mapped
9308@cindex memory-mapped symbol file
9309@cindex saving symbol table
9310@item symbol-file @var{filename} @r{[} -readnow @r{]} @r{[} -mapped @r{]}
9311@itemx file @var{filename} @r{[} -readnow @r{]} @r{[} -mapped @r{]}
9312You can override the @value{GDBN} two-stage strategy for reading symbol
9313tables by using the @samp{-readnow} option with any of the commands that
9314load symbol table information, if you want to be sure @value{GDBN} has the
5d161b24 9315entire symbol table available.
c906108c 9316
c906108c
SS
9317If memory-mapped files are available on your system through the
9318@code{mmap} system call, you can use another option, @samp{-mapped}, to
9319cause @value{GDBN} to write the symbols for your program into a reusable
9320file. Future @value{GDBN} debugging sessions map in symbol information
9321from this auxiliary symbol file (if the program has not changed), rather
9322than spending time reading the symbol table from the executable
9323program. Using the @samp{-mapped} option has the same effect as
9324starting @value{GDBN} with the @samp{-mapped} command-line option.
9325
9326You can use both options together, to make sure the auxiliary symbol
9327file has all the symbol information for your program.
9328
9329The auxiliary symbol file for a program called @var{myprog} is called
9330@samp{@var{myprog}.syms}. Once this file exists (so long as it is newer
9331than the corresponding executable), @value{GDBN} always attempts to use
9332it when you debug @var{myprog}; no special options or commands are
9333needed.
9334
9335The @file{.syms} file is specific to the host machine where you run
9336@value{GDBN}. It holds an exact image of the internal @value{GDBN}
9337symbol table. It cannot be shared across multiple host platforms.
c906108c
SS
9338
9339@c FIXME: for now no mention of directories, since this seems to be in
9340@c flux. 13mar1992 status is that in theory GDB would look either in
9341@c current dir or in same dir as myprog; but issues like competing
9342@c GDB's, or clutter in system dirs, mean that in practice right now
9343@c only current dir is used. FFish says maybe a special GDB hierarchy
9344@c (eg rooted in val of env var GDBSYMS) could exist for mappable symbol
9345@c files.
9346
9347@kindex core
9348@kindex core-file
9349@item core-file @r{[} @var{filename} @r{]}
9350Specify the whereabouts of a core dump file to be used as the ``contents
9351of memory''. Traditionally, core files contain only some parts of the
9352address space of the process that generated them; @value{GDBN} can access the
9353executable file itself for other parts.
9354
9355@code{core-file} with no argument specifies that no core file is
9356to be used.
9357
9358Note that the core file is ignored when your program is actually running
7a292a7a
SS
9359under @value{GDBN}. So, if you have been running your program and you
9360wish to debug a core file instead, you must kill the subprocess in which
9361the program is running. To do this, use the @code{kill} command
c906108c 9362(@pxref{Kill Process, ,Killing the child process}).
c906108c 9363
c906108c
SS
9364@kindex add-symbol-file
9365@cindex dynamic linking
9366@item add-symbol-file @var{filename} @var{address}
9367@itemx add-symbol-file @var{filename} @var{address} @r{[} -readnow @r{]} @r{[} -mapped @r{]}
17d9d558 9368@itemx add-symbol-file @var{filename} @r{-s}@var{section} @var{address} @dots{}
96a2c332
SS
9369The @code{add-symbol-file} command reads additional symbol table
9370information from the file @var{filename}. You would use this command
9371when @var{filename} has been dynamically loaded (by some other means)
9372into the program that is running. @var{address} should be the memory
9373address at which the file has been loaded; @value{GDBN} cannot figure
d167840f
EZ
9374this out for itself. You can additionally specify an arbitrary number
9375of @samp{@r{-s}@var{section} @var{address}} pairs, to give an explicit
9376section name and base address for that section. You can specify any
9377@var{address} as an expression.
c906108c
SS
9378
9379The symbol table of the file @var{filename} is added to the symbol table
9380originally read with the @code{symbol-file} command. You can use the
96a2c332
SS
9381@code{add-symbol-file} command any number of times; the new symbol data
9382thus read keeps adding to the old. To discard all old symbol data
9383instead, use the @code{symbol-file} command without any arguments.
c906108c 9384
17d9d558
JB
9385@cindex relocatable object files, reading symbols from
9386@cindex object files, relocatable, reading symbols from
9387@cindex reading symbols from relocatable object files
9388@cindex symbols, reading from relocatable object files
9389@cindex @file{.o} files, reading symbols from
9390Although @var{filename} is typically a shared library file, an
9391executable file, or some other object file which has been fully
9392relocated for loading into a process, you can also load symbolic
9393information from relocatable @file{.o} files, as long as:
9394
9395@itemize @bullet
9396@item
9397the file's symbolic information refers only to linker symbols defined in
9398that file, not to symbols defined by other object files,
9399@item
9400every section the file's symbolic information refers to has actually
9401been loaded into the inferior, as it appears in the file, and
9402@item
9403you can determine the address at which every section was loaded, and
9404provide these to the @code{add-symbol-file} command.
9405@end itemize
9406
9407@noindent
9408Some embedded operating systems, like Sun Chorus and VxWorks, can load
9409relocatable files into an already running program; such systems
9410typically make the requirements above easy to meet. However, it's
9411important to recognize that many native systems use complex link
9412procedures (@code{.linkonce} section factoring and C++ constructor table
9413assembly, for example) that make the requirements difficult to meet. In
9414general, one cannot assume that using @code{add-symbol-file} to read a
9415relocatable object file's symbolic information will have the same effect
9416as linking the relocatable object file into the program in the normal
9417way.
9418
c906108c
SS
9419@code{add-symbol-file} does not repeat if you press @key{RET} after using it.
9420
9421You can use the @samp{-mapped} and @samp{-readnow} options just as with
9422the @code{symbol-file} command, to change how @value{GDBN} manages the symbol
9423table information for @var{filename}.
9424
9425@kindex add-shared-symbol-file
9426@item add-shared-symbol-file
9427The @code{add-shared-symbol-file} command can be used only under Harris' CXUX
5d161b24
DB
9428operating system for the Motorola 88k. @value{GDBN} automatically looks for
9429shared libraries, however if @value{GDBN} does not find yours, you can run
c906108c 9430@code{add-shared-symbol-file}. It takes no arguments.
c906108c 9431
c906108c
SS
9432@kindex section
9433@item section
5d161b24
DB
9434The @code{section} command changes the base address of section SECTION of
9435the exec file to ADDR. This can be used if the exec file does not contain
9436section addresses, (such as in the a.out format), or when the addresses
9437specified in the file itself are wrong. Each section must be changed
d4f3574e
SS
9438separately. The @code{info files} command, described below, lists all
9439the sections and their addresses.
c906108c
SS
9440
9441@kindex info files
9442@kindex info target
9443@item info files
9444@itemx info target
7a292a7a
SS
9445@code{info files} and @code{info target} are synonymous; both print the
9446current target (@pxref{Targets, ,Specifying a Debugging Target}),
9447including the names of the executable and core dump files currently in
9448use by @value{GDBN}, and the files from which symbols were loaded. The
9449command @code{help target} lists all possible targets rather than
9450current ones.
9451
fe95c787
MS
9452@kindex maint info sections
9453@item maint info sections
9454Another command that can give you extra information about program sections
9455is @code{maint info sections}. In addition to the section information
9456displayed by @code{info files}, this command displays the flags and file
9457offset of each section in the executable and core dump files. In addition,
9458@code{maint info sections} provides the following command options (which
9459may be arbitrarily combined):
9460
9461@table @code
9462@item ALLOBJ
9463Display sections for all loaded object files, including shared libraries.
9464@item @var{sections}
6600abed 9465Display info only for named @var{sections}.
fe95c787
MS
9466@item @var{section-flags}
9467Display info only for sections for which @var{section-flags} are true.
9468The section flags that @value{GDBN} currently knows about are:
9469@table @code
9470@item ALLOC
9471Section will have space allocated in the process when loaded.
9472Set for all sections except those containing debug information.
9473@item LOAD
9474Section will be loaded from the file into the child process memory.
9475Set for pre-initialized code and data, clear for @code{.bss} sections.
9476@item RELOC
9477Section needs to be relocated before loading.
9478@item READONLY
9479Section cannot be modified by the child process.
9480@item CODE
9481Section contains executable code only.
6600abed 9482@item DATA
fe95c787
MS
9483Section contains data only (no executable code).
9484@item ROM
9485Section will reside in ROM.
9486@item CONSTRUCTOR
9487Section contains data for constructor/destructor lists.
9488@item HAS_CONTENTS
9489Section is not empty.
9490@item NEVER_LOAD
9491An instruction to the linker to not output the section.
9492@item COFF_SHARED_LIBRARY
9493A notification to the linker that the section contains
9494COFF shared library information.
9495@item IS_COMMON
9496Section contains common symbols.
9497@end table
9498@end table
c906108c
SS
9499@end table
9500
9501All file-specifying commands allow both absolute and relative file names
9502as arguments. @value{GDBN} always converts the file name to an absolute file
9503name and remembers it that way.
9504
c906108c 9505@cindex shared libraries
c906108c
SS
9506@value{GDBN} supports HP-UX, SunOS, SVr4, Irix 5, and IBM RS/6000 shared
9507libraries.
53a5351d 9508
c906108c
SS
9509@value{GDBN} automatically loads symbol definitions from shared libraries
9510when you use the @code{run} command, or when you examine a core file.
9511(Before you issue the @code{run} command, @value{GDBN} does not understand
9512references to a function in a shared library, however---unless you are
9513debugging a core file).
53a5351d
JM
9514
9515On HP-UX, if the program loads a library explicitly, @value{GDBN}
9516automatically loads the symbols at the time of the @code{shl_load} call.
9517
c906108c
SS
9518@c FIXME: some @value{GDBN} release may permit some refs to undef
9519@c FIXME...symbols---eg in a break cmd---assuming they are from a shared
9520@c FIXME...lib; check this from time to time when updating manual
9521
b7209cb4
FF
9522There are times, however, when you may wish to not automatically load
9523symbol definitions from shared libraries, such as when they are
9524particularly large or there are many of them.
9525
9526To control the automatic loading of shared library symbols, use the
9527commands:
9528
9529@table @code
9530@kindex set auto-solib-add
9531@item set auto-solib-add @var{mode}
9532If @var{mode} is @code{on}, symbols from all shared object libraries
9533will be loaded automatically when the inferior begins execution, you
9534attach to an independently started inferior, or when the dynamic linker
9535informs @value{GDBN} that a new library has been loaded. If @var{mode}
9536is @code{off}, symbols must be loaded manually, using the
9537@code{sharedlibrary} command. The default value is @code{on}.
9538
9539@kindex show auto-solib-add
9540@item show auto-solib-add
9541Display the current autoloading mode.
9542@end table
9543
9544To explicitly load shared library symbols, use the @code{sharedlibrary}
9545command:
9546
c906108c
SS
9547@table @code
9548@kindex info sharedlibrary
9549@kindex info share
9550@item info share
9551@itemx info sharedlibrary
9552Print the names of the shared libraries which are currently loaded.
9553
9554@kindex sharedlibrary
9555@kindex share
9556@item sharedlibrary @var{regex}
9557@itemx share @var{regex}
c906108c
SS
9558Load shared object library symbols for files matching a
9559Unix regular expression.
9560As with files loaded automatically, it only loads shared libraries
9561required by your program for a core file or after typing @code{run}. If
9562@var{regex} is omitted all shared libraries required by your program are
9563loaded.
9564@end table
9565
b7209cb4
FF
9566On some systems, such as HP-UX systems, @value{GDBN} supports
9567autoloading shared library symbols until a limiting threshold size is
9568reached. This provides the benefit of allowing autoloading to remain on
9569by default, but avoids autoloading excessively large shared libraries,
9570up to a threshold that is initially set, but which you can modify if you
9571wish.
c906108c
SS
9572
9573Beyond that threshold, symbols from shared libraries must be explicitly
d4f3574e
SS
9574loaded. To load these symbols, use the command @code{sharedlibrary
9575@var{filename}}. The base address of the shared library is determined
c906108c
SS
9576automatically by @value{GDBN} and need not be specified.
9577
9578To display or set the threshold, use the commands:
9579
9580@table @code
b7209cb4
FF
9581@kindex set auto-solib-limit
9582@item set auto-solib-limit @var{threshold}
9583Set the autoloading size threshold, in an integral number of megabytes.
9584If @var{threshold} is nonzero and shared library autoloading is enabled,
9585symbols from all shared object libraries will be loaded until the total
9586size of the loaded shared library symbols exceeds this threshold.
c906108c 9587Otherwise, symbols must be loaded manually, using the
b7209cb4
FF
9588@code{sharedlibrary} command. The default threshold is 100 (i.e. 100
9589Mb).
c906108c 9590
b7209cb4
FF
9591@kindex show auto-solib-limit
9592@item show auto-solib-limit
c906108c
SS
9593Display the current autoloading size threshold, in megabytes.
9594@end table
c906108c 9595
6d2ebf8b 9596@node Symbol Errors
c906108c
SS
9597@section Errors reading symbol files
9598
9599While reading a symbol file, @value{GDBN} occasionally encounters problems,
9600such as symbol types it does not recognize, or known bugs in compiler
9601output. By default, @value{GDBN} does not notify you of such problems, since
9602they are relatively common and primarily of interest to people
9603debugging compilers. If you are interested in seeing information
9604about ill-constructed symbol tables, you can either ask @value{GDBN} to print
9605only one message about each such type of problem, no matter how many
9606times the problem occurs; or you can ask @value{GDBN} to print more messages,
9607to see how many times the problems occur, with the @code{set
9608complaints} command (@pxref{Messages/Warnings, ,Optional warnings and
9609messages}).
9610
9611The messages currently printed, and their meanings, include:
9612
9613@table @code
9614@item inner block not inside outer block in @var{symbol}
9615
9616The symbol information shows where symbol scopes begin and end
9617(such as at the start of a function or a block of statements). This
9618error indicates that an inner scope block is not fully contained
9619in its outer scope blocks.
9620
9621@value{GDBN} circumvents the problem by treating the inner block as if it had
9622the same scope as the outer block. In the error message, @var{symbol}
9623may be shown as ``@code{(don't know)}'' if the outer block is not a
9624function.
9625
9626@item block at @var{address} out of order
9627
9628The symbol information for symbol scope blocks should occur in
9629order of increasing addresses. This error indicates that it does not
9630do so.
9631
9632@value{GDBN} does not circumvent this problem, and has trouble
9633locating symbols in the source file whose symbols it is reading. (You
9634can often determine what source file is affected by specifying
9635@code{set verbose on}. @xref{Messages/Warnings, ,Optional warnings and
9636messages}.)
9637
9638@item bad block start address patched
9639
9640The symbol information for a symbol scope block has a start address
9641smaller than the address of the preceding source line. This is known
9642to occur in the SunOS 4.1.1 (and earlier) C compiler.
9643
9644@value{GDBN} circumvents the problem by treating the symbol scope block as
9645starting on the previous source line.
9646
9647@item bad string table offset in symbol @var{n}
9648
9649@cindex foo
9650Symbol number @var{n} contains a pointer into the string table which is
9651larger than the size of the string table.
9652
9653@value{GDBN} circumvents the problem by considering the symbol to have the
9654name @code{foo}, which may cause other problems if many symbols end up
9655with this name.
9656
9657@item unknown symbol type @code{0x@var{nn}}
9658
7a292a7a
SS
9659The symbol information contains new data types that @value{GDBN} does
9660not yet know how to read. @code{0x@var{nn}} is the symbol type of the
d4f3574e 9661uncomprehended information, in hexadecimal.
c906108c 9662
7a292a7a
SS
9663@value{GDBN} circumvents the error by ignoring this symbol information.
9664This usually allows you to debug your program, though certain symbols
c906108c 9665are not accessible. If you encounter such a problem and feel like
7a292a7a
SS
9666debugging it, you can debug @code{@value{GDBP}} with itself, breakpoint
9667on @code{complain}, then go up to the function @code{read_dbx_symtab}
9668and examine @code{*bufp} to see the symbol.
c906108c
SS
9669
9670@item stub type has NULL name
c906108c 9671
7a292a7a 9672@value{GDBN} could not find the full definition for a struct or class.
c906108c 9673
7a292a7a 9674@item const/volatile indicator missing (ok if using g++ v1.x), got@dots{}
b37052ae 9675The symbol information for a C@t{++} member function is missing some
7a292a7a
SS
9676information that recent versions of the compiler should have output for
9677it.
c906108c
SS
9678
9679@item info mismatch between compiler and debugger
9680
9681@value{GDBN} could not parse a type specification output by the compiler.
7a292a7a 9682
c906108c
SS
9683@end table
9684
6d2ebf8b 9685@node Targets
c906108c 9686@chapter Specifying a Debugging Target
7a292a7a 9687
c906108c
SS
9688@cindex debugging target
9689@kindex target
9690
9691A @dfn{target} is the execution environment occupied by your program.
53a5351d
JM
9692
9693Often, @value{GDBN} runs in the same host environment as your program;
9694in that case, the debugging target is specified as a side effect when
9695you use the @code{file} or @code{core} commands. When you need more
c906108c
SS
9696flexibility---for example, running @value{GDBN} on a physically separate
9697host, or controlling a standalone system over a serial port or a
53a5351d
JM
9698realtime system over a TCP/IP connection---you can use the @code{target}
9699command to specify one of the target types configured for @value{GDBN}
9700(@pxref{Target Commands, ,Commands for managing targets}).
c906108c
SS
9701
9702@menu
9703* Active Targets:: Active targets
9704* Target Commands:: Commands for managing targets
c906108c
SS
9705* Byte Order:: Choosing target byte order
9706* Remote:: Remote debugging
96baa820 9707* KOD:: Kernel Object Display
c906108c
SS
9708
9709@end menu
9710
6d2ebf8b 9711@node Active Targets
c906108c 9712@section Active targets
7a292a7a 9713
c906108c
SS
9714@cindex stacking targets
9715@cindex active targets
9716@cindex multiple targets
9717
c906108c 9718There are three classes of targets: processes, core files, and
7a292a7a
SS
9719executable files. @value{GDBN} can work concurrently on up to three
9720active targets, one in each class. This allows you to (for example)
9721start a process and inspect its activity without abandoning your work on
9722a core file.
c906108c
SS
9723
9724For example, if you execute @samp{gdb a.out}, then the executable file
9725@code{a.out} is the only active target. If you designate a core file as
9726well---presumably from a prior run that crashed and coredumped---then
9727@value{GDBN} has two active targets and uses them in tandem, looking
9728first in the corefile target, then in the executable file, to satisfy
9729requests for memory addresses. (Typically, these two classes of target
9730are complementary, since core files contain only a program's
9731read-write memory---variables and so on---plus machine status, while
9732executable files contain only the program text and initialized data.)
c906108c
SS
9733
9734When you type @code{run}, your executable file becomes an active process
7a292a7a
SS
9735target as well. When a process target is active, all @value{GDBN}
9736commands requesting memory addresses refer to that target; addresses in
9737an active core file or executable file target are obscured while the
9738process target is active.
c906108c 9739
7a292a7a
SS
9740Use the @code{core-file} and @code{exec-file} commands to select a new
9741core file or executable target (@pxref{Files, ,Commands to specify
c906108c 9742files}). To specify as a target a process that is already running, use
7a292a7a
SS
9743the @code{attach} command (@pxref{Attach, ,Debugging an already-running
9744process}).
c906108c 9745
6d2ebf8b 9746@node Target Commands
c906108c
SS
9747@section Commands for managing targets
9748
9749@table @code
9750@item target @var{type} @var{parameters}
7a292a7a
SS
9751Connects the @value{GDBN} host environment to a target machine or
9752process. A target is typically a protocol for talking to debugging
9753facilities. You use the argument @var{type} to specify the type or
9754protocol of the target machine.
c906108c
SS
9755
9756Further @var{parameters} are interpreted by the target protocol, but
9757typically include things like device names or host names to connect
9758with, process numbers, and baud rates.
c906108c
SS
9759
9760The @code{target} command does not repeat if you press @key{RET} again
9761after executing the command.
9762
9763@kindex help target
9764@item help target
9765Displays the names of all targets available. To display targets
9766currently selected, use either @code{info target} or @code{info files}
9767(@pxref{Files, ,Commands to specify files}).
9768
9769@item help target @var{name}
9770Describe a particular target, including any parameters necessary to
9771select it.
9772
9773@kindex set gnutarget
9774@item set gnutarget @var{args}
5d161b24 9775@value{GDBN} uses its own library BFD to read your files. @value{GDBN}
c906108c 9776knows whether it is reading an @dfn{executable},
5d161b24
DB
9777a @dfn{core}, or a @dfn{.o} file; however, you can specify the file format
9778with the @code{set gnutarget} command. Unlike most @code{target} commands,
c906108c
SS
9779with @code{gnutarget} the @code{target} refers to a program, not a machine.
9780
d4f3574e 9781@quotation
c906108c
SS
9782@emph{Warning:} To specify a file format with @code{set gnutarget},
9783you must know the actual BFD name.
d4f3574e 9784@end quotation
c906108c 9785
d4f3574e
SS
9786@noindent
9787@xref{Files, , Commands to specify files}.
c906108c 9788
5d161b24 9789@kindex show gnutarget
c906108c
SS
9790@item show gnutarget
9791Use the @code{show gnutarget} command to display what file format
9792@code{gnutarget} is set to read. If you have not set @code{gnutarget},
9793@value{GDBN} will determine the file format for each file automatically,
9794and @code{show gnutarget} displays @samp{The current BDF target is "auto"}.
9795@end table
9796
c906108c
SS
9797Here are some common targets (available, or not, depending on the GDB
9798configuration):
c906108c
SS
9799
9800@table @code
9801@kindex target exec
9802@item target exec @var{program}
9803An executable file. @samp{target exec @var{program}} is the same as
9804@samp{exec-file @var{program}}.
9805
c906108c
SS
9806@kindex target core
9807@item target core @var{filename}
9808A core dump file. @samp{target core @var{filename}} is the same as
9809@samp{core-file @var{filename}}.
c906108c
SS
9810
9811@kindex target remote
9812@item target remote @var{dev}
9813Remote serial target in GDB-specific protocol. The argument @var{dev}
9814specifies what serial device to use for the connection (e.g.
9815@file{/dev/ttya}). @xref{Remote, ,Remote debugging}. @code{target remote}
d4f3574e 9816supports the @code{load} command. This is only useful if you have
c906108c
SS
9817some other way of getting the stub to the target system, and you can put
9818it somewhere in memory where it won't get clobbered by the download.
9819
c906108c
SS
9820@kindex target sim
9821@item target sim
2df3850c 9822Builtin CPU simulator. @value{GDBN} includes simulators for most architectures.
104c1213
JM
9823In general,
9824@example
9825 target sim
9826 load
9827 run
9828@end example
d4f3574e 9829@noindent
104c1213 9830works; however, you cannot assume that a specific memory map, device
d4f3574e 9831drivers, or even basic I/O is available, although some simulators do
104c1213
JM
9832provide these. For info about any processor-specific simulator details,
9833see the appropriate section in @ref{Embedded Processors, ,Embedded
9834Processors}.
9835
c906108c
SS
9836@end table
9837
104c1213 9838Some configurations may include these targets as well:
c906108c
SS
9839
9840@table @code
9841
c906108c
SS
9842@kindex target nrom
9843@item target nrom @var{dev}
9844NetROM ROM emulator. This target only supports downloading.
9845
c906108c
SS
9846@end table
9847
5d161b24 9848Different targets are available on different configurations of @value{GDBN};
c906108c 9849your configuration may have more or fewer targets.
c906108c
SS
9850
9851Many remote targets require you to download the executable's code
9852once you've successfully established a connection.
9853
9854@table @code
9855
9856@kindex load @var{filename}
9857@item load @var{filename}
c906108c
SS
9858Depending on what remote debugging facilities are configured into
9859@value{GDBN}, the @code{load} command may be available. Where it exists, it
9860is meant to make @var{filename} (an executable) available for debugging
9861on the remote system---by downloading, or dynamic linking, for example.
9862@code{load} also records the @var{filename} symbol table in @value{GDBN}, like
9863the @code{add-symbol-file} command.
9864
9865If your @value{GDBN} does not have a @code{load} command, attempting to
9866execute it gets the error message ``@code{You can't do that when your
9867target is @dots{}}''
c906108c
SS
9868
9869The file is loaded at whatever address is specified in the executable.
9870For some object file formats, you can specify the load address when you
9871link the program; for other formats, like a.out, the object file format
9872specifies a fixed address.
9873@c FIXME! This would be a good place for an xref to the GNU linker doc.
9874
c906108c
SS
9875@code{load} does not repeat if you press @key{RET} again after using it.
9876@end table
9877
6d2ebf8b 9878@node Byte Order
c906108c 9879@section Choosing target byte order
7a292a7a 9880
c906108c
SS
9881@cindex choosing target byte order
9882@cindex target byte order
c906108c
SS
9883
9884Some types of processors, such as the MIPS, PowerPC, and Hitachi SH,
9885offer the ability to run either big-endian or little-endian byte
9886orders. Usually the executable or symbol will include a bit to
9887designate the endian-ness, and you will not need to worry about
9888which to use. However, you may still find it useful to adjust
d4f3574e 9889@value{GDBN}'s idea of processor endian-ness manually.
c906108c
SS
9890
9891@table @code
9892@kindex set endian big
9893@item set endian big
9894Instruct @value{GDBN} to assume the target is big-endian.
9895
9896@kindex set endian little
9897@item set endian little
9898Instruct @value{GDBN} to assume the target is little-endian.
9899
9900@kindex set endian auto
9901@item set endian auto
9902Instruct @value{GDBN} to use the byte order associated with the
9903executable.
9904
9905@item show endian
9906Display @value{GDBN}'s current idea of the target byte order.
9907
9908@end table
9909
9910Note that these commands merely adjust interpretation of symbolic
9911data on the host, and that they have absolutely no effect on the
9912target system.
9913
6d2ebf8b 9914@node Remote
c906108c
SS
9915@section Remote debugging
9916@cindex remote debugging
9917
9918If you are trying to debug a program running on a machine that cannot run
5d161b24
DB
9919@value{GDBN} in the usual way, it is often useful to use remote debugging.
9920For example, you might use remote debugging on an operating system kernel,
c906108c
SS
9921or on a small system which does not have a general purpose operating system
9922powerful enough to run a full-featured debugger.
9923
9924Some configurations of @value{GDBN} have special serial or TCP/IP interfaces
9925to make this work with particular debugging targets. In addition,
5d161b24 9926@value{GDBN} comes with a generic serial protocol (specific to @value{GDBN},
c906108c
SS
9927but not specific to any particular target system) which you can use if you
9928write the remote stubs---the code that runs on the remote system to
9929communicate with @value{GDBN}.
9930
9931Other remote targets may be available in your
9932configuration of @value{GDBN}; use @code{help target} to list them.
c906108c 9933
c906108c 9934@menu
c906108c 9935* Remote Serial:: @value{GDBN} remote serial protocol
c906108c
SS
9936@end menu
9937
6d2ebf8b 9938@node Remote Serial
104c1213 9939@subsection The @value{GDBN} remote serial protocol
7a292a7a 9940
104c1213
JM
9941@cindex remote serial debugging, overview
9942To debug a program running on another machine (the debugging
9943@dfn{target} machine), you must first arrange for all the usual
9944prerequisites for the program to run by itself. For example, for a C
9945program, you need:
c906108c 9946
104c1213
JM
9947@enumerate
9948@item
9949A startup routine to set up the C runtime environment; these usually
9950have a name like @file{crt0}. The startup routine may be supplied by
9951your hardware supplier, or you may have to write your own.
96baa820 9952
5d161b24 9953@item
d4f3574e 9954A C subroutine library to support your program's
104c1213 9955subroutine calls, notably managing input and output.
96baa820 9956
104c1213
JM
9957@item
9958A way of getting your program to the other machine---for example, a
9959download program. These are often supplied by the hardware
9960manufacturer, but you may have to write your own from hardware
9961documentation.
9962@end enumerate
96baa820 9963
104c1213
JM
9964The next step is to arrange for your program to use a serial port to
9965communicate with the machine where @value{GDBN} is running (the @dfn{host}
9966machine). In general terms, the scheme looks like this:
96baa820 9967
104c1213
JM
9968@table @emph
9969@item On the host,
9970@value{GDBN} already understands how to use this protocol; when everything
9971else is set up, you can simply use the @samp{target remote} command
9972(@pxref{Targets,,Specifying a Debugging Target}).
9973
9974@item On the target,
9975you must link with your program a few special-purpose subroutines that
9976implement the @value{GDBN} remote serial protocol. The file containing these
9977subroutines is called a @dfn{debugging stub}.
9978
9979On certain remote targets, you can use an auxiliary program
9980@code{gdbserver} instead of linking a stub into your program.
9981@xref{Server,,Using the @code{gdbserver} program}, for details.
9982@end table
96baa820 9983
104c1213
JM
9984The debugging stub is specific to the architecture of the remote
9985machine; for example, use @file{sparc-stub.c} to debug programs on
9986@sc{sparc} boards.
96baa820 9987
104c1213
JM
9988@cindex remote serial stub list
9989These working remote stubs are distributed with @value{GDBN}:
96baa820 9990
104c1213
JM
9991@table @code
9992
9993@item i386-stub.c
41afff9a 9994@cindex @file{i386-stub.c}
104c1213
JM
9995@cindex Intel
9996@cindex i386
9997For Intel 386 and compatible architectures.
9998
9999@item m68k-stub.c
41afff9a 10000@cindex @file{m68k-stub.c}
104c1213
JM
10001@cindex Motorola 680x0
10002@cindex m680x0
10003For Motorola 680x0 architectures.
10004
10005@item sh-stub.c
41afff9a 10006@cindex @file{sh-stub.c}
104c1213
JM
10007@cindex Hitachi
10008@cindex SH
10009For Hitachi SH architectures.
10010
10011@item sparc-stub.c
41afff9a 10012@cindex @file{sparc-stub.c}
104c1213
JM
10013@cindex Sparc
10014For @sc{sparc} architectures.
10015
10016@item sparcl-stub.c
41afff9a 10017@cindex @file{sparcl-stub.c}
104c1213
JM
10018@cindex Fujitsu
10019@cindex SparcLite
10020For Fujitsu @sc{sparclite} architectures.
10021
10022@end table
10023
10024The @file{README} file in the @value{GDBN} distribution may list other
10025recently added stubs.
10026
10027@menu
10028* Stub Contents:: What the stub can do for you
10029* Bootstrapping:: What you must do for the stub
10030* Debug Session:: Putting it all together
10031* Protocol:: Definition of the communication protocol
10032* Server:: Using the `gdbserver' program
10033* NetWare:: Using the `gdbserve.nlm' program
10034@end menu
10035
6d2ebf8b 10036@node Stub Contents
104c1213
JM
10037@subsubsection What the stub can do for you
10038
10039@cindex remote serial stub
10040The debugging stub for your architecture supplies these three
10041subroutines:
10042
10043@table @code
10044@item set_debug_traps
10045@kindex set_debug_traps
10046@cindex remote serial stub, initialization
10047This routine arranges for @code{handle_exception} to run when your
10048program stops. You must call this subroutine explicitly near the
10049beginning of your program.
10050
10051@item handle_exception
10052@kindex handle_exception
10053@cindex remote serial stub, main routine
10054This is the central workhorse, but your program never calls it
10055explicitly---the setup code arranges for @code{handle_exception} to
10056run when a trap is triggered.
10057
10058@code{handle_exception} takes control when your program stops during
10059execution (for example, on a breakpoint), and mediates communications
10060with @value{GDBN} on the host machine. This is where the communications
10061protocol is implemented; @code{handle_exception} acts as the @value{GDBN}
d4f3574e 10062representative on the target machine. It begins by sending summary
104c1213
JM
10063information on the state of your program, then continues to execute,
10064retrieving and transmitting any information @value{GDBN} needs, until you
10065execute a @value{GDBN} command that makes your program resume; at that point,
10066@code{handle_exception} returns control to your own code on the target
5d161b24 10067machine.
104c1213
JM
10068
10069@item breakpoint
10070@cindex @code{breakpoint} subroutine, remote
10071Use this auxiliary subroutine to make your program contain a
10072breakpoint. Depending on the particular situation, this may be the only
10073way for @value{GDBN} to get control. For instance, if your target
10074machine has some sort of interrupt button, you won't need to call this;
10075pressing the interrupt button transfers control to
10076@code{handle_exception}---in effect, to @value{GDBN}. On some machines,
10077simply receiving characters on the serial port may also trigger a trap;
10078again, in that situation, you don't need to call @code{breakpoint} from
10079your own program---simply running @samp{target remote} from the host
5d161b24 10080@value{GDBN} session gets control.
104c1213
JM
10081
10082Call @code{breakpoint} if none of these is true, or if you simply want
10083to make certain your program stops at a predetermined point for the
10084start of your debugging session.
10085@end table
10086
6d2ebf8b 10087@node Bootstrapping
104c1213
JM
10088@subsubsection What you must do for the stub
10089
10090@cindex remote stub, support routines
10091The debugging stubs that come with @value{GDBN} are set up for a particular
10092chip architecture, but they have no information about the rest of your
10093debugging target machine.
10094
10095First of all you need to tell the stub how to communicate with the
10096serial port.
10097
10098@table @code
10099@item int getDebugChar()
10100@kindex getDebugChar
10101Write this subroutine to read a single character from the serial port.
10102It may be identical to @code{getchar} for your target system; a
10103different name is used to allow you to distinguish the two if you wish.
10104
10105@item void putDebugChar(int)
10106@kindex putDebugChar
10107Write this subroutine to write a single character to the serial port.
5d161b24 10108It may be identical to @code{putchar} for your target system; a
104c1213
JM
10109different name is used to allow you to distinguish the two if you wish.
10110@end table
10111
10112@cindex control C, and remote debugging
10113@cindex interrupting remote targets
10114If you want @value{GDBN} to be able to stop your program while it is
10115running, you need to use an interrupt-driven serial driver, and arrange
10116for it to stop when it receives a @code{^C} (@samp{\003}, the control-C
10117character). That is the character which @value{GDBN} uses to tell the
10118remote system to stop.
10119
10120Getting the debugging target to return the proper status to @value{GDBN}
10121probably requires changes to the standard stub; one quick and dirty way
10122is to just execute a breakpoint instruction (the ``dirty'' part is that
10123@value{GDBN} reports a @code{SIGTRAP} instead of a @code{SIGINT}).
10124
10125Other routines you need to supply are:
10126
10127@table @code
10128@item void exceptionHandler (int @var{exception_number}, void *@var{exception_address})
10129@kindex exceptionHandler
10130Write this function to install @var{exception_address} in the exception
10131handling tables. You need to do this because the stub does not have any
10132way of knowing what the exception handling tables on your target system
10133are like (for example, the processor's table might be in @sc{rom},
10134containing entries which point to a table in @sc{ram}).
10135@var{exception_number} is the exception number which should be changed;
10136its meaning is architecture-dependent (for example, different numbers
10137might represent divide by zero, misaligned access, etc). When this
10138exception occurs, control should be transferred directly to
10139@var{exception_address}, and the processor state (stack, registers,
10140and so on) should be just as it is when a processor exception occurs. So if
10141you want to use a jump instruction to reach @var{exception_address}, it
10142should be a simple jump, not a jump to subroutine.
10143
10144For the 386, @var{exception_address} should be installed as an interrupt
10145gate so that interrupts are masked while the handler runs. The gate
10146should be at privilege level 0 (the most privileged level). The
10147@sc{sparc} and 68k stubs are able to mask interrupts themselves without
10148help from @code{exceptionHandler}.
10149
10150@item void flush_i_cache()
10151@kindex flush_i_cache
d4f3574e 10152On @sc{sparc} and @sc{sparclite} only, write this subroutine to flush the
104c1213
JM
10153instruction cache, if any, on your target machine. If there is no
10154instruction cache, this subroutine may be a no-op.
10155
10156On target machines that have instruction caches, @value{GDBN} requires this
10157function to make certain that the state of your program is stable.
10158@end table
10159
10160@noindent
10161You must also make sure this library routine is available:
10162
10163@table @code
10164@item void *memset(void *, int, int)
10165@kindex memset
10166This is the standard library function @code{memset} that sets an area of
10167memory to a known value. If you have one of the free versions of
10168@code{libc.a}, @code{memset} can be found there; otherwise, you must
10169either obtain it from your hardware manufacturer, or write your own.
10170@end table
10171
10172If you do not use the GNU C compiler, you may need other standard
10173library subroutines as well; this varies from one stub to another,
10174but in general the stubs are likely to use any of the common library
d4f3574e 10175subroutines which @code{@value{GCC}} generates as inline code.
104c1213
JM
10176
10177
6d2ebf8b 10178@node Debug Session
104c1213
JM
10179@subsubsection Putting it all together
10180
10181@cindex remote serial debugging summary
10182In summary, when your program is ready to debug, you must follow these
10183steps.
10184
10185@enumerate
10186@item
6d2ebf8b 10187Make sure you have defined the supporting low-level routines
104c1213
JM
10188(@pxref{Bootstrapping,,What you must do for the stub}):
10189@display
10190@code{getDebugChar}, @code{putDebugChar},
10191@code{flush_i_cache}, @code{memset}, @code{exceptionHandler}.
10192@end display
10193
10194@item
10195Insert these lines near the top of your program:
10196
10197@example
10198set_debug_traps();
10199breakpoint();
10200@end example
10201
10202@item
10203For the 680x0 stub only, you need to provide a variable called
10204@code{exceptionHook}. Normally you just use:
10205
10206@example
10207void (*exceptionHook)() = 0;
10208@end example
10209
d4f3574e 10210@noindent
104c1213 10211but if before calling @code{set_debug_traps}, you set it to point to a
598ca718 10212function in your program, that function is called when
104c1213
JM
10213@code{@value{GDBN}} continues after stopping on a trap (for example, bus
10214error). The function indicated by @code{exceptionHook} is called with
10215one parameter: an @code{int} which is the exception number.
10216
10217@item
10218Compile and link together: your program, the @value{GDBN} debugging stub for
10219your target architecture, and the supporting subroutines.
10220
10221@item
10222Make sure you have a serial connection between your target machine and
10223the @value{GDBN} host, and identify the serial port on the host.
10224
10225@item
10226@c The "remote" target now provides a `load' command, so we should
10227@c document that. FIXME.
10228Download your program to your target machine (or get it there by
10229whatever means the manufacturer provides), and start it.
10230
10231@item
10232To start remote debugging, run @value{GDBN} on the host machine, and specify
10233as an executable file the program that is running in the remote machine.
10234This tells @value{GDBN} how to find your program's symbols and the contents
10235of its pure text.
10236
d4f3574e 10237@item
104c1213 10238@cindex serial line, @code{target remote}
d4f3574e 10239Establish communication using the @code{target remote} command.
104c1213
JM
10240Its argument specifies how to communicate with the target
10241machine---either via a devicename attached to a direct serial line, or a
10242TCP port (usually to a terminal server which in turn has a serial line
10243to the target). For example, to use a serial line connected to the
10244device named @file{/dev/ttyb}:
10245
10246@example
10247target remote /dev/ttyb
10248@end example
10249
10250@cindex TCP port, @code{target remote}
10251To use a TCP connection, use an argument of the form
10252@code{@var{host}:port}. For example, to connect to port 2828 on a
10253terminal server named @code{manyfarms}:
10254
10255@example
10256target remote manyfarms:2828
10257@end example
a2bea4c3
CV
10258
10259If your remote target is actually running on the same machine as
10260your debugger session (e.g.@: a simulator of your target running on
10261the same host), you can omit the hostname. For example, to connect
10262to port 1234 on your local machine:
10263
10264@example
10265target remote :1234
10266@end example
10267@noindent
10268
10269Note that the colon is still required here.
104c1213
JM
10270@end enumerate
10271
10272Now you can use all the usual commands to examine and change data and to
10273step and continue the remote program.
10274
10275To resume the remote program and stop debugging it, use the @code{detach}
10276command.
10277
10278@cindex interrupting remote programs
10279@cindex remote programs, interrupting
10280Whenever @value{GDBN} is waiting for the remote program, if you type the
10281interrupt character (often @key{C-C}), @value{GDBN} attempts to stop the
10282program. This may or may not succeed, depending in part on the hardware
10283and the serial drivers the remote system uses. If you type the
10284interrupt character once again, @value{GDBN} displays this prompt:
10285
10286@example
10287Interrupted while waiting for the program.
10288Give up (and stop debugging it)? (y or n)
10289@end example
10290
10291If you type @kbd{y}, @value{GDBN} abandons the remote debugging session.
10292(If you decide you want to try again later, you can use @samp{target
10293remote} again to connect once more.) If you type @kbd{n}, @value{GDBN}
10294goes back to waiting.
10295
6d2ebf8b 10296@node Protocol
104c1213
JM
10297@subsubsection Communication protocol
10298
10299@cindex debugging stub, example
10300@cindex remote stub, example
10301@cindex stub example, remote debugging
10302The stub files provided with @value{GDBN} implement the target side of the
10303communication protocol, and the @value{GDBN} side is implemented in the
10304@value{GDBN} source file @file{remote.c}. Normally, you can simply allow
10305these subroutines to communicate, and ignore the details. (If you're
10306implementing your own stub file, you can still ignore the details: start
10307with one of the existing stub files. @file{sparc-stub.c} is the best
10308organized, and therefore the easiest to read.)
10309
10310However, there may be occasions when you need to know something about
10311the protocol---for example, if there is only one serial port to your
10312target machine, you might want your program to do something special if
10313it recognizes a packet meant for @value{GDBN}.
10314
10315In the examples below, @samp{<-} and @samp{->} are used to indicate
10316transmitted and received data respectfully.
10317
10318@cindex protocol, @value{GDBN} remote serial
10319@cindex serial protocol, @value{GDBN} remote
10320@cindex remote serial protocol
6cf7e474
AC
10321All @value{GDBN} commands and responses (other than acknowledgments) are
10322sent as a @var{packet}. A @var{packet} is introduced with the character
10323@samp{$}, the actual @var{packet-data}, and the terminating character
10324@samp{#} followed by a two-digit @var{checksum}:
104c1213
JM
10325
10326@example
10327@code{$}@var{packet-data}@code{#}@var{checksum}
10328@end example
10329@noindent
104c1213
JM
10330
10331@cindex checksum, for @value{GDBN} remote
10332@noindent
10333The two-digit @var{checksum} is computed as the modulo 256 sum of all
6cf7e474
AC
10334characters between the leading @samp{$} and the trailing @samp{#} (an
10335eight bit unsigned checksum).
10336
10337Implementors should note that prior to @value{GDBN} 5.0 the protocol
10338specification also included an optional two-digit @var{sequence-id}:
10339
10340@example
10341@code{$}@var{sequence-id}@code{:}@var{packet-data}@code{#}@var{checksum}
10342@end example
104c1213
JM
10343
10344@cindex sequence-id, for @value{GDBN} remote
10345@noindent
6cf7e474
AC
10346That @var{sequence-id} was appended to the acknowledgment. @value{GDBN}
10347has never output @var{sequence-id}s. Stubs that handle packets added
10348since @value{GDBN} 5.0 must not accept @var{sequence-id}.
104c1213 10349
6cf7e474 10350@cindex acknowledgment, for @value{GDBN} remote
104c1213
JM
10351When either the host or the target machine receives a packet, the first
10352response expected is an acknowledgment: either @samp{+} (to indicate
10353the package was received correctly) or @samp{-} (to request
10354retransmission):
10355
10356@example
10357<- @code{$}@var{packet-data}@code{#}@var{checksum}
10358-> @code{+}
10359@end example
10360@noindent
104c1213
JM
10361
10362The host (@value{GDBN}) sends @var{command}s, and the target (the
10363debugging stub incorporated in your program) sends a @var{response}. In
10364the case of step and continue @var{command}s, the response is only sent
10365when the operation has completed (the target has again stopped).
10366
10367@var{packet-data} consists of a sequence of characters with the
6cf7e474
AC
10368exception of @samp{#} and @samp{$} (see @samp{X} packet for additional
10369exceptions).
10370
10371Fields within the packet should be separated using @samp{,} @samp{;} or
10372@samp{:}. Except where otherwise noted all numbers are represented in
10373HEX with leading zeros suppressed.
10374
10375Implementors should note that prior to @value{GDBN} 5.0, the character
10376@samp{:} could not appear as the third character in a packet (as it
10377would potentially conflict with the @var{sequence-id}).
104c1213
JM
10378
10379Response @var{data} can be run-length encoded to save space. A @samp{*}
c3f6f71d 10380means that the next character is an @sc{ascii} encoding giving a repeat count
104c1213
JM
10381which stands for that many repetitions of the character preceding the
10382@samp{*}. The encoding is @code{n+29}, yielding a printable character
d4f3574e
SS
10383where @code{n >=3} (which is where rle starts to win). The printable
10384characters @samp{$}, @samp{#}, @samp{+} and @samp{-} or with a numeric
10385value greater than 126 should not be used.
10386
10387Some remote systems have used a different run-length encoding mechanism
10388loosely refered to as the cisco encoding. Following the @samp{*}
10389character are two hex digits that indicate the size of the packet.
104c1213
JM
10390
10391So:
10392@example
10393"@code{0* }"
10394@end example
10395@noindent
10396means the same as "0000".
10397
598ca718 10398The error response returned for some packets includes a two character
104c1213
JM
10399error number. That number is not well defined.
10400
10401For any @var{command} not supported by the stub, an empty response
10402(@samp{$#00}) should be returned. That way it is possible to extend the
10403protocol. A newer @value{GDBN} can tell if a packet is supported based
d4f3574e 10404on that response.
104c1213 10405
f1251bdd
C
10406A stub is required to support the @samp{g}, @samp{G}, @samp{m}, @samp{M},
10407@samp{c}, and @samp{s} @var{command}s. All other @var{command}s are
10408optional.
10409
104c1213
JM
10410Below is a complete list of all currently defined @var{command}s and
10411their corresponding response @var{data}:
598ca718 10412@page
104c1213
JM
10413@multitable @columnfractions .30 .30 .40
10414@item Packet
10415@tab Request
10416@tab Description
10417
df2396a1 10418@item extended mode
104c1213
JM
10419@tab @code{!}
10420@tab
df2396a1 10421Enable extended mode. In extended mode, the remote server is made
656db9b0 10422persistent. The @samp{R} packet is used to restart the program being
df2396a1 10423debugged.
104c1213 10424@item
df2396a1 10425@tab reply @samp{OK}
104c1213 10426@tab
df2396a1 10427The remote target both supports and has enabled extended mode.
104c1213
JM
10428
10429@item last signal
10430@tab @code{?}
10431@tab
d4f3574e
SS
10432Indicate the reason the target halted. The reply is the same as for step
10433and continue.
10434@item
10435@tab reply
10436@tab see below
10437
104c1213
JM
10438
10439@item reserved
10440@tab @code{a}
5d161b24 10441@tab Reserved for future use
104c1213 10442
f1251bdd 10443@item set program arguments @strong{(reserved)}
104c1213
JM
10444@tab @code{A}@var{arglen}@code{,}@var{argnum}@code{,}@var{arg}@code{,...}
10445@tab
598ca718
EZ
10446@item
10447@tab
10448@tab
104c1213
JM
10449Initialized @samp{argv[]} array passed into program. @var{arglen}
10450specifies the number of bytes in the hex encoded byte stream @var{arg}.
d4f3574e 10451See @file{gdbserver} for more details.
104c1213
JM
10452@item
10453@tab reply @code{OK}
10454@item
10455@tab reply @code{E}@var{NN}
10456
10457@item set baud @strong{(deprecated)}
10458@tab @code{b}@var{baud}
10459@tab
10460Change the serial line speed to @var{baud}. JTC: @emph{When does the
10461transport layer state change? When it's received, or after the ACK is
10462transmitted. In either case, there are problems if the command or the
10463acknowledgment packet is dropped.} Stan: @emph{If people really wanted
10464to add something like this, and get it working for the first time, they
10465ought to modify ser-unix.c to send some kind of out-of-band message to a
10466specially-setup stub and have the switch happen "in between" packets, so
10467that from remote protocol's point of view, nothing actually
10468happened.}
10469
10470@item set breakpoint @strong{(deprecated)}
10471@tab @code{B}@var{addr},@var{mode}
10472@tab
10473Set (@var{mode} is @samp{S}) or clear (@var{mode} is @samp{C}) a
10474breakpoint at @var{addr}. @emph{This has been replaced by the @samp{Z} and
10475@samp{z} packets.}
10476
10477@item continue
10478@tab @code{c}@var{addr}
10479@tab
10480@var{addr} is address to resume. If @var{addr} is omitted, resume at
10481current address.
10482@item
10483@tab reply
10484@tab see below
10485
f1251bdd 10486@item continue with signal
104c1213
JM
10487@tab @code{C}@var{sig}@code{;}@var{addr}
10488@tab
10489Continue with signal @var{sig} (hex signal number). If
10490@code{;}@var{addr} is omitted, resume at same address.
10491@item
10492@tab reply
10493@tab see below
10494
598ca718 10495@item toggle debug @strong{(deprecated)}
104c1213
JM
10496@tab @code{d}
10497@tab
d4f3574e 10498toggle debug flag.
104c1213 10499
f1251bdd 10500@item detach
104c1213 10501@tab @code{D}
d4f3574e 10502@tab
2df3850c
JM
10503Detach @value{GDBN} from the remote system. Sent to the remote target before
10504@value{GDBN} disconnects.
d4f3574e
SS
10505@item
10506@tab reply @emph{no response}
10507@tab
598ca718 10508@value{GDBN} does not check for any response after sending this packet.
104c1213
JM
10509
10510@item reserved
10511@tab @code{e}
5d161b24 10512@tab Reserved for future use
104c1213
JM
10513
10514@item reserved
10515@tab @code{E}
5d161b24 10516@tab Reserved for future use
104c1213
JM
10517
10518@item reserved
10519@tab @code{f}
5d161b24 10520@tab Reserved for future use
104c1213
JM
10521
10522@item reserved
10523@tab @code{F}
5d161b24 10524@tab Reserved for future use
104c1213
JM
10525
10526@item read registers
10527@tab @code{g}
10528@tab Read general registers.
10529@item
10530@tab reply @var{XX...}
10531@tab
10532Each byte of register data is described by two hex digits. The bytes
10533with the register are transmitted in target byte order. The size of
d4f3574e 10534each register and their position within the @samp{g} @var{packet} are
2df3850c 10535determined by the @value{GDBN} internal macros @var{REGISTER_RAW_SIZE} and
d4f3574e
SS
10536@var{REGISTER_NAME} macros. The specification of several standard
10537@code{g} packets is specified below.
104c1213
JM
10538@item
10539@tab @code{E}@var{NN}
10540@tab for an error.
10541
10542@item write regs
10543@tab @code{G}@var{XX...}
10544@tab
10545See @samp{g} for a description of the @var{XX...} data.
10546@item
10547@tab reply @code{OK}
10548@tab for success
10549@item
10550@tab reply @code{E}@var{NN}
10551@tab for an error
10552
10553@item reserved
10554@tab @code{h}
5d161b24 10555@tab Reserved for future use
104c1213 10556
f1251bdd 10557@item set thread
104c1213
JM
10558@tab @code{H}@var{c}@var{t...}
10559@tab
d4f3574e
SS
10560Set thread for subsequent operations (@samp{m}, @samp{M}, @samp{g},
10561@samp{G}, et.al.). @var{c} = @samp{c} for thread used in step and
10562continue; @var{t...} can be -1 for all threads. @var{c} = @samp{g} for
10563thread used in other operations. If zero, pick a thread, any thread.
104c1213
JM
10564@item
10565@tab reply @code{OK}
10566@tab for success
10567@item
10568@tab reply @code{E}@var{NN}
10569@tab for an error
10570
d4f3574e
SS
10571@c FIXME: JTC:
10572@c 'H': How restrictive (or permissive) is the thread model. If a
5d161b24 10573@c thread is selected and stopped, are other threads allowed
d4f3574e
SS
10574@c to continue to execute? As I mentioned above, I think the
10575@c semantics of each command when a thread is selected must be
10576@c described. For example:
10577@c
10578@c 'g': If the stub supports threads and a specific thread is
10579@c selected, returns the register block from that thread;
10580@c otherwise returns current registers.
10581@c
10582@c 'G' If the stub supports threads and a specific thread is
10583@c selected, sets the registers of the register block of
10584@c that thread; otherwise sets current registers.
10585
f1251bdd 10586@item cycle step @strong{(draft)}
104c1213
JM
10587@tab @code{i}@var{addr}@code{,}@var{nnn}
10588@tab
10589Step the remote target by a single clock cycle. If @code{,}@var{nnn} is
10590present, cycle step @var{nnn} cycles. If @var{addr} is present, cycle
10591step starting at that address.
10592
f1251bdd 10593@item signal then cycle step @strong{(reserved)}
104c1213
JM
10594@tab @code{I}
10595@tab
10596See @samp{i} and @samp{S} for likely syntax and semantics.
10597
10598@item reserved
10599@tab @code{j}
10600@tab Reserved for future use
10601
10602@item reserved
10603@tab @code{J}
5d161b24 10604@tab Reserved for future use
104c1213 10605
f1251bdd 10606@item kill request
104c1213
JM
10607@tab @code{k}
10608@tab
d4f3574e
SS
10609FIXME: @emph{There is no description of how operate when a specific
10610thread context has been selected (ie. does 'k' kill only that thread?)}.
104c1213
JM
10611
10612@item reserved
10613@tab @code{l}
5d161b24 10614@tab Reserved for future use
104c1213
JM
10615
10616@item reserved
10617@tab @code{L}
5d161b24 10618@tab Reserved for future use
104c1213
JM
10619
10620@item read memory
10621@tab @code{m}@var{addr}@code{,}@var{length}
10622@tab
10623Read @var{length} bytes of memory starting at address @var{addr}.
2df3850c 10624Neither @value{GDBN} nor the stub assume that sized memory transfers are assumed
d4f3574e
SS
10625using word alligned accesses. FIXME: @emph{A word aligned memory
10626transfer mechanism is needed.}
104c1213
JM
10627@item
10628@tab reply @var{XX...}
10629@tab
d4f3574e 10630@var{XX...} is mem contents. Can be fewer bytes than requested if able
2df3850c 10631to read only part of the data. Neither @value{GDBN} nor the stub assume that
d4f3574e
SS
10632sized memory transfers are assumed using word alligned accesses. FIXME:
10633@emph{A word aligned memory transfer mechanism is needed.}
104c1213
JM
10634@item
10635@tab reply @code{E}@var{NN}
10636@tab @var{NN} is errno
10637
10638@item write mem
10639@tab @code{M}@var{addr},@var{length}@code{:}@var{XX...}
10640@tab
10641Write @var{length} bytes of memory starting at address @var{addr}.
10642@var{XX...} is the data.
10643@item
10644@tab reply @code{OK}
10645@tab for success
10646@item
10647@tab reply @code{E}@var{NN}
10648@tab
10649for an error (this includes the case where only part of the data was
10650written).
10651
10652@item reserved
10653@tab @code{n}
5d161b24 10654@tab Reserved for future use
104c1213
JM
10655
10656@item reserved
10657@tab @code{N}
5d161b24 10658@tab Reserved for future use
104c1213
JM
10659
10660@item reserved
10661@tab @code{o}
5d161b24 10662@tab Reserved for future use
104c1213
JM
10663
10664@item reserved
10665@tab @code{O}
5d161b24 10666@tab Reserved for future use
104c1213
JM
10667
10668@item read reg @strong{(reserved)}
10669@tab @code{p}@var{n...}
10670@tab
10671See write register.
10672@item
10673@tab return @var{r....}
10674@tab The hex encoded value of the register in target byte order.
10675
f1251bdd 10676@item write reg
104c1213
JM
10677@tab @code{P}@var{n...}@code{=}@var{r...}
10678@tab
10679Write register @var{n...} with value @var{r...}, which contains two hex
10680digits for each byte in the register (target byte order).
10681@item
10682@tab reply @code{OK}
10683@tab for success
10684@item
10685@tab reply @code{E}@var{NN}
10686@tab for an error
10687
f1251bdd 10688@item general query
104c1213
JM
10689@tab @code{q}@var{query}
10690@tab
598ca718 10691Request info about @var{query}. In general @value{GDBN} queries
104c1213 10692have a leading upper case letter. Custom vendor queries should use a
d4f3574e
SS
10693company prefix (in lower case) ex: @samp{qfsf.var}. @var{query} may
10694optionally be followed by a @samp{,} or @samp{;} separated list. Stubs
10695must ensure that they match the full @var{query} name.
104c1213
JM
10696@item
10697@tab reply @code{XX...}
d4f3574e 10698@tab Hex encoded data from query. The reply can not be empty.
104c1213
JM
10699@item
10700@tab reply @code{E}@var{NN}
10701@tab error reply
10702@item
10703@tab reply @samp{}
10704@tab Indicating an unrecognized @var{query}.
10705
f1251bdd 10706@item general set
104c1213
JM
10707@tab @code{Q}@var{var}@code{=}@var{val}
10708@tab
10709Set value of @var{var} to @var{val}. See @samp{q} for a discussing of
10710naming conventions.
10711
598ca718 10712@item reset @strong{(deprecated)}
d4f3574e
SS
10713@tab @code{r}
10714@tab
10715Reset the entire system.
104c1213 10716
f1251bdd 10717@item remote restart
104c1213
JM
10718@tab @code{R}@var{XX}
10719@tab
df2396a1
AC
10720Restart the program being debugged. @var{XX}, while needed, is ignored.
10721This packet is only available in extended mode.
10722@item
10723@tab
10724no reply
10725@tab
10726The @samp{R} packet has no reply.
104c1213 10727
f1251bdd 10728@item step
104c1213
JM
10729@tab @code{s}@var{addr}
10730@tab
10731@var{addr} is address to resume. If @var{addr} is omitted, resume at
10732same address.
10733@item
10734@tab reply
10735@tab see below
10736
f1251bdd 10737@item step with signal
104c1213
JM
10738@tab @code{S}@var{sig}@code{;}@var{addr}
10739@tab
10740Like @samp{C} but step not continue.
10741@item
10742@tab reply
10743@tab see below
10744
f1251bdd 10745@item search
104c1213
JM
10746@tab @code{t}@var{addr}@code{:}@var{PP}@code{,}@var{MM}
10747@tab
10748Search backwards starting at address @var{addr} for a match with pattern
10749@var{PP} and mask @var{MM}. @var{PP} and @var{MM} are 4
d4f3574e 10750bytes. @var{addr} must be at least 3 digits.
104c1213 10751
f1251bdd 10752@item thread alive
104c1213
JM
10753@tab @code{T}@var{XX}
10754@tab Find out if the thread XX is alive.
10755@item
10756@tab reply @code{OK}
10757@tab thread is still alive
10758@item
10759@tab reply @code{E}@var{NN}
10760@tab thread is dead
5d161b24 10761
104c1213
JM
10762@item reserved
10763@tab @code{u}
5d161b24 10764@tab Reserved for future use
104c1213
JM
10765
10766@item reserved
10767@tab @code{U}
5d161b24 10768@tab Reserved for future use
104c1213
JM
10769
10770@item reserved
10771@tab @code{v}
5d161b24 10772@tab Reserved for future use
104c1213
JM
10773
10774@item reserved
10775@tab @code{V}
5d161b24 10776@tab Reserved for future use
104c1213
JM
10777
10778@item reserved
10779@tab @code{w}
5d161b24 10780@tab Reserved for future use
104c1213
JM
10781
10782@item reserved
10783@tab @code{W}
5d161b24 10784@tab Reserved for future use
104c1213
JM
10785
10786@item reserved
10787@tab @code{x}
5d161b24 10788@tab Reserved for future use
104c1213 10789
f1251bdd 10790@item write mem (binary)
104c1213
JM
10791@tab @code{X}@var{addr}@code{,}@var{length}@var{:}@var{XX...}
10792@tab
10793@var{addr} is address, @var{length} is number of bytes, @var{XX...} is
d4f3574e
SS
10794binary data. The characters @code{$}, @code{#}, and @code{0x7d} are
10795escaped using @code{0x7d}.
104c1213
JM
10796@item
10797@tab reply @code{OK}
10798@tab for success
10799@item
10800@tab reply @code{E}@var{NN}
10801@tab for an error
10802
10803@item reserved
10804@tab @code{y}
5d161b24 10805@tab Reserved for future use
104c1213
JM
10806
10807@item reserved
10808@tab @code{Y}
5d161b24 10809@tab Reserved for future use
104c1213 10810
f1251bdd 10811@item remove break or watchpoint @strong{(draft)}
104c1213
JM
10812@tab @code{z}@var{t}@code{,}@var{addr}@code{,}@var{length}
10813@tab
10814See @samp{Z}.
10815
f1251bdd 10816@item insert break or watchpoint @strong{(draft)}
104c1213
JM
10817@tab @code{Z}@var{t}@code{,}@var{addr}@code{,}@var{length}
10818@tab
10819@var{t} is type: @samp{0} - software breakpoint, @samp{1} - hardware
10820breakpoint, @samp{2} - write watchpoint, @samp{3} - read watchpoint,
10821@samp{4} - access watchpoint; @var{addr} is address; @var{length} is in
10822bytes. For a software breakpoint, @var{length} specifies the size of
10823the instruction to be patched. For hardware breakpoints and watchpoints
d4f3574e
SS
10824@var{length} specifies the memory region to be monitored. To avoid
10825potential problems with duplicate packets, the operations should be
6d2ebf8b 10826implemented in an idempotent way.
104c1213
JM
10827@item
10828@tab reply @code{E}@var{NN}
10829@tab for an error
10830@item
10831@tab reply @code{OK}
10832@tab for success
10833@item
10834@tab @samp{}
10835@tab If not supported.
10836
10837@item reserved
10838@tab <other>
5d161b24 10839@tab Reserved for future use
104c1213
JM
10840
10841@end multitable
10842
d4f3574e
SS
10843The @samp{C}, @samp{c}, @samp{S}, @samp{s} and @samp{?} packets can
10844receive any of the below as a reply. In the case of the @samp{C},
10845@samp{c}, @samp{S} and @samp{s} packets, that reply is only returned
10846when the target halts. In the below the exact meaning of @samp{signal
10847number} is poorly defined. In general one of the UNIX signal numbering
10848conventions is used.
104c1213
JM
10849
10850@multitable @columnfractions .4 .6
10851
10852@item @code{S}@var{AA}
10853@tab @var{AA} is the signal number
10854
10855@item @code{T}@var{AA}@var{n...}@code{:}@var{r...}@code{;}@var{n...}@code{:}@var{r...}@code{;}@var{n...}@code{:}@var{r...}@code{;}
10856@tab
10857@var{AA} = two hex digit signal number; @var{n...} = register number
10858(hex), @var{r...} = target byte ordered register contents, size defined
10859by @code{REGISTER_RAW_SIZE}; @var{n...} = @samp{thread}, @var{r...} =
10860thread process ID, this is a hex integer; @var{n...} = other string not
d4f3574e 10861starting with valid hex digit. @value{GDBN} should ignore this
104c1213
JM
10862@var{n...}, @var{r...} pair and go on to the next. This way we can
10863extend the protocol.
10864
10865@item @code{W}@var{AA}
10866@tab
10867The process exited, and @var{AA} is the exit status. This is only
10868applicable for certains sorts of targets.
10869
10870@item @code{X}@var{AA}
10871@tab
10872The process terminated with signal @var{AA}.
10873
6d2ebf8b 10874@item @code{N}@var{AA}@code{;}@var{t...}@code{;}@var{d...}@code{;}@var{b...} @strong{(obsolete)}
104c1213 10875@tab
6d2ebf8b
SS
10876@var{AA} = signal number; @var{t...} = address of symbol "_start";
10877@var{d...} = base of data section; @var{b...} = base of bss section.
10878@emph{Note: only used by Cisco Systems targets. The difference between
10879this reply and the "qOffsets" query is that the 'N' packet may arrive
10880spontaneously whereas the 'qOffsets' is a query initiated by the host
10881debugger.}
104c1213
JM
10882
10883@item @code{O}@var{XX...}
10884@tab
c3f6f71d 10885@var{XX...} is hex encoding of @sc{ascii} data. This can happen at any time
104c1213
JM
10886while the program is running and the debugger should continue to wait
10887for 'W', 'T', etc.
10888
10889@end multitable
10890
d4f3574e
SS
10891The following set and query packets have already been defined.
10892
10893@multitable @columnfractions .2 .2 .6
10894
10895@item current thread
10896@tab @code{q}@code{C}
10897@tab Return the current thread id.
10898@item
10899@tab reply @code{QC}@var{pid}
10900@tab
10901Where @var{pid} is a HEX encoded 16 bit process id.
10902@item
10903@tab reply *
10904@tab Any other reply implies the old pid.
10905
bba2971c
MS
10906@item all thread ids
10907@tab @code{q}@code{fThreadInfo}
10908@item
10909@tab @code{q}@code{sThreadInfo}
d4f3574e 10910@tab
bba2971c
MS
10911Obtain a list of active thread ids from the target (OS). Since there
10912may be too many active threads to fit into one reply packet, this query
10913works iteratively: it may require more than one query/reply sequence to
10914obtain the entire list of threads. The first query of the sequence will
5d161b24 10915be the @code{qf}@code{ThreadInfo} query; subsequent queries in the
bba2971c 10916sequence will be the @code{qs}@code{ThreadInfo} query.
d4f3574e 10917@item
bba2971c
MS
10918@tab
10919@tab NOTE: replaces the @code{qL} query (see below).
d4f3574e 10920@item
5d161b24 10921@tab reply @code{m}@var{<id>}
bba2971c
MS
10922@tab A single thread id
10923@item
00e4a2e4 10924@tab reply @code{m}@var{<id>},@var{<id>...}
bba2971c
MS
10925@tab a comma-separated list of thread ids
10926@item
10927@tab reply @code{l}
10928@tab (lower case 'el') denotes end of list.
10929@item
10930@tab
10931@tab
10932In response to each query, the target will reply with a list of one
10933or more thread ids, in big-endian hex, separated by commas. GDB will
10934respond to each reply with a request for more thread ids (using the
10935@code{qs} form of the query), until the target responds with @code{l}
10936(lower-case el, for @code{'last'}).
10937
10938@item extra thread info
480ff1fb 10939@tab @code{q}@code{ThreadExtraInfo}@code{,}@var{id}
bba2971c
MS
10940@tab
10941@item
10942@tab
10943@tab
10944Where @var{<id>} is a thread-id in big-endian hex.
10945Obtain a printable string description of a thread's attributes from
10946the target OS. This string may contain anything that the target OS
10947thinks is interesting for @value{GDBN} to tell the user about the thread.
10948The string is displayed in @value{GDBN}'s @samp{info threads} display.
5d161b24 10949Some examples of possible thread extra info strings are "Runnable", or
bba2971c
MS
10950"Blocked on Mutex".
10951@item
10952@tab reply @var{XX...}
10953@tab
10954Where @var{XX...} is a hex encoding of @sc{ascii} data, comprising the
10955printable string containing the extra information about the thread's
10956attributes.
d4f3574e
SS
10957
10958@item query @var{LIST} or @var{threadLIST} @strong{(deprecated)}
10959@tab @code{q}@code{L}@var{startflag}@var{threadcount}@var{nextthread}
10960@tab
2b628194
MS
10961@item
10962@tab
10963@tab
d4f3574e
SS
10964Obtain thread information from RTOS. Where: @var{startflag} (one hex
10965digit) is one to indicate the first query and zero to indicate a
10966subsequent query; @var{threadcount} (two hex digits) is the maximum
10967number of threads the response packet can contain; and @var{nextthread}
10968(eight hex digits), for subsequent queries (@var{startflag} is zero), is
10969returned in the response as @var{argthread}.
10970@item
bba2971c
MS
10971@tab
10972@tab NOTE: this query is replaced by the @code{q}@code{fThreadInfo}
10973query (see above).
10974@item
d4f3574e
SS
10975@tab reply @code{q}@code{M}@var{count}@var{done}@var{argthread}@var{thread...}
10976@tab
2b628194
MS
10977@item
10978@tab
10979@tab
d4f3574e
SS
10980Where: @var{count} (two hex digits) is the number of threads being
10981returned; @var{done} (one hex digit) is zero to indicate more threads
10982and one indicates no further threads; @var{argthreadid} (eight hex
10983digits) is @var{nextthread} from the request packet; @var{thread...} is
10984a sequence of thread IDs from the target. @var{threadid} (eight hex
10985digits). See @code{remote.c:parse_threadlist_response()}.
10986
bba2971c
MS
10987@item compute CRC of memory block
10988@tab @code{q}@code{CRC:}@var{addr}@code{,}@var{length}
10989@tab
10990@item
10991@tab reply @code{E}@var{NN}
10992@tab An error (such as memory fault)
10993@item
10994@tab reply @code{C}@var{CRC32}
10995@tab A 32 bit cyclic redundancy check of the specified memory region.
10996
d4f3574e
SS
10997@item query sect offs
10998@tab @code{q}@code{Offsets}
917317f4
JM
10999@tab
11000Get section offsets that the target used when re-locating the downloaded
11001image. @emph{Note: while a @code{Bss} offset is included in the
11002response, @value{GDBN} ignores this and instead applies the @code{Data}
11003offset to the @code{Bss} section.}
d4f3574e
SS
11004@item
11005@tab reply @code{Text=}@var{xxx}@code{;Data=}@var{yyy}@code{;Bss=}@var{zzz}
11006
11007@item thread info request
11008@tab @code{q}@code{P}@var{mode}@var{threadid}
11009@tab
598ca718
EZ
11010@item
11011@tab
11012@tab
d4f3574e
SS
11013Returns information on @var{threadid}. Where: @var{mode} is a hex
11014encoded 32 bit mode; @var{threadid} is a hex encoded 64 bit thread ID.
11015@item
11016@tab reply *
11017@tab
11018See @code{remote.c:remote_unpack_thread_info_response()}.
11019
11020@item remote command
11021@tab @code{q}@code{Rcmd,}@var{COMMAND}
11022@tab
598ca718
EZ
11023@item
11024@tab
11025@tab
d4f3574e
SS
11026@var{COMMAND} (hex encoded) is passed to the local interpreter for
11027execution. Invalid commands should be reported using the output string.
11028Before the final result packet, the target may also respond with a
11029number of intermediate @code{O}@var{OUTPUT} console output
11030packets. @emph{Implementors should note that providing access to a
11031stubs's interpreter may have security implications}.
11032@item
11033@tab reply @code{OK}
11034@tab
11035A command response with no output.
11036@item
11037@tab reply @var{OUTPUT}
11038@tab
11039A command response with the hex encoded output string @var{OUTPUT}.
11040@item
11041@tab reply @code{E}@var{NN}
11042@tab
11043Indicate a badly formed request.
11044
11045@item
11046@tab reply @samp{}
11047@tab
11048When @samp{q}@samp{Rcmd} is not recognized.
11049
0f1f2b0a
MS
11050@item symbol lookup
11051@tab @code{qSymbol::}
11052@tab
11053Notify the target that @value{GDBN} is prepared to serve symbol lookup
11054requests. Accept requests from the target for the values of symbols.
11055@item
11056@tab
11057@tab
11058@item
11059@tab reply @code{OK}
11060@tab
11061The target does not need to look up any (more) symbols.
11062@item
11063@tab reply @code{qSymbol:}@var{sym_name}
11064@tab
11065The target requests the value of symbol @var{sym_name} (hex encoded).
11066@value{GDBN} may provide the value by using the
11067@code{qSymbol:}@var{sym_value}:@var{sym_name}
11068message, described below.
11069
11070@item symbol value
11071@tab @code{qSymbol:}@var{sym_value}:@var{sym_name}
11072@tab
11073Set the value of SYM_NAME to SYM_VALUE.
11074@item
11075@tab
11076@tab
11077@var{sym_name} (hex encoded) is the name of a symbol whose value
11078the target has previously requested.
11079@item
11080@tab
11081@tab
11082@var{sym_value} (hex) is the value for symbol @var{sym_name}.
11083If @value{GDBN} cannot supply a value for @var{sym_name}, then this
11084field will be empty.
11085@item
11086@tab reply @code{OK}
11087@tab
11088The target does not need to look up any (more) symbols.
11089@item
11090@tab reply @code{qSymbol:}@var{sym_name}
11091@tab
11092The target requests the value of a new symbol @var{sym_name} (hex encoded).
11093@value{GDBN} will continue to supply the values of symbols (if available),
11094until the target ceases to request them.
11095
d4f3574e
SS
11096@end multitable
11097
11098The following @samp{g}/@samp{G} packets have previously been defined.
11099In the below, some thirty-two bit registers are transferred as sixty-four
11100bits. Those registers should be zero/sign extended (which?) to fill the
11101space allocated. Register bytes are transfered in target byte order.
11102The two nibbles within a register byte are transfered most-significant -
11103least-significant.
11104
11105@multitable @columnfractions .5 .5
11106
11107@item MIPS32
11108@tab
11109All registers are transfered as thirty-two bit quantities in the order:
1111032 general-purpose; sr; lo; hi; bad; cause; pc; 32 floating-point
11111registers; fsr; fir; fp.
11112
11113@item MIPS64
11114@tab
11115All registers are transfered as sixty-four bit quantities (including
11116thirty-two bit registers such as @code{sr}). The ordering is the same
11117as @code{MIPS32}.
11118
11119@end multitable
11120
104c1213
JM
11121Example sequence of a target being re-started. Notice how the restart
11122does not get any direct output:
11123
11124@example
11125<- @code{R00}
11126-> @code{+}
11127@emph{target restarts}
11128<- @code{?}
11129-> @code{+}
11130-> @code{T001:1234123412341234}
11131<- @code{+}
11132@end example
11133
11134Example sequence of a target being stepped by a single instruction:
11135
11136@example
11137<- @code{G1445...}
11138-> @code{+}
11139<- @code{s}
11140-> @code{+}
11141@emph{time passes}
11142-> @code{T001:1234123412341234}
11143<- @code{+}
11144<- @code{g}
11145-> @code{+}
11146-> @code{1455...}
11147<- @code{+}
11148@end example
11149
6d2ebf8b 11150@node Server
104c1213
JM
11151@subsubsection Using the @code{gdbserver} program
11152
11153@kindex gdbserver
11154@cindex remote connection without stubs
11155@code{gdbserver} is a control program for Unix-like systems, which
11156allows you to connect your program with a remote @value{GDBN} via
11157@code{target remote}---but without linking in the usual debugging stub.
11158
11159@code{gdbserver} is not a complete replacement for the debugging stubs,
11160because it requires essentially the same operating-system facilities
11161that @value{GDBN} itself does. In fact, a system that can run
11162@code{gdbserver} to connect to a remote @value{GDBN} could also run
11163@value{GDBN} locally! @code{gdbserver} is sometimes useful nevertheless,
11164because it is a much smaller program than @value{GDBN} itself. It is
11165also easier to port than all of @value{GDBN}, so you may be able to get
11166started more quickly on a new system by using @code{gdbserver}.
11167Finally, if you develop code for real-time systems, you may find that
11168the tradeoffs involved in real-time operation make it more convenient to
11169do as much development work as possible on another system, for example
11170by cross-compiling. You can use @code{gdbserver} to make a similar
11171choice for debugging.
11172
11173@value{GDBN} and @code{gdbserver} communicate via either a serial line
11174or a TCP connection, using the standard @value{GDBN} remote serial
11175protocol.
11176
11177@table @emph
11178@item On the target machine,
11179you need to have a copy of the program you want to debug.
11180@code{gdbserver} does not need your program's symbol table, so you can
11181strip the program if necessary to save space. @value{GDBN} on the host
11182system does all the symbol handling.
11183
11184To use the server, you must tell it how to communicate with @value{GDBN};
11185the name of your program; and the arguments for your program. The
11186syntax is:
11187
11188@smallexample
11189target> gdbserver @var{comm} @var{program} [ @var{args} @dots{} ]
11190@end smallexample
11191
11192@var{comm} is either a device name (to use a serial line) or a TCP
11193hostname and portnumber. For example, to debug Emacs with the argument
11194@samp{foo.txt} and communicate with @value{GDBN} over the serial port
11195@file{/dev/com1}:
11196
11197@smallexample
11198target> gdbserver /dev/com1 emacs foo.txt
11199@end smallexample
11200
11201@code{gdbserver} waits passively for the host @value{GDBN} to communicate
11202with it.
11203
11204To use a TCP connection instead of a serial line:
11205
11206@smallexample
11207target> gdbserver host:2345 emacs foo.txt
11208@end smallexample
11209
11210The only difference from the previous example is the first argument,
11211specifying that you are communicating with the host @value{GDBN} via
11212TCP. The @samp{host:2345} argument means that @code{gdbserver} is to
11213expect a TCP connection from machine @samp{host} to local TCP port 2345.
11214(Currently, the @samp{host} part is ignored.) You can choose any number
11215you want for the port number as long as it does not conflict with any
11216TCP ports already in use on the target system (for example, @code{23} is
11217reserved for @code{telnet}).@footnote{If you choose a port number that
11218conflicts with another service, @code{gdbserver} prints an error message
d4f3574e 11219and exits.} You must use the same port number with the host @value{GDBN}
104c1213
JM
11220@code{target remote} command.
11221
11222@item On the @value{GDBN} host machine,
11223you need an unstripped copy of your program, since @value{GDBN} needs
11224symbols and debugging information. Start up @value{GDBN} as usual,
11225using the name of the local copy of your program as the first argument.
11226(You may also need the @w{@samp{--baud}} option if the serial line is
d4f3574e 11227running at anything other than 9600@dmn{bps}.) After that, use @code{target
104c1213
JM
11228remote} to establish communications with @code{gdbserver}. Its argument
11229is either a device name (usually a serial device, like
11230@file{/dev/ttyb}), or a TCP port descriptor in the form
11231@code{@var{host}:@var{PORT}}. For example:
11232
11233@smallexample
11234(@value{GDBP}) target remote /dev/ttyb
11235@end smallexample
11236
11237@noindent
11238communicates with the server via serial line @file{/dev/ttyb}, and
11239
11240@smallexample
11241(@value{GDBP}) target remote the-target:2345
11242@end smallexample
11243
11244@noindent
11245communicates via a TCP connection to port 2345 on host @w{@file{the-target}}.
11246For TCP connections, you must start up @code{gdbserver} prior to using
11247the @code{target remote} command. Otherwise you may get an error whose
11248text depends on the host system, but which usually looks something like
11249@samp{Connection refused}.
11250@end table
11251
6d2ebf8b 11252@node NetWare
104c1213
JM
11253@subsubsection Using the @code{gdbserve.nlm} program
11254
11255@kindex gdbserve.nlm
11256@code{gdbserve.nlm} is a control program for NetWare systems, which
11257allows you to connect your program with a remote @value{GDBN} via
11258@code{target remote}.
11259
11260@value{GDBN} and @code{gdbserve.nlm} communicate via a serial line,
11261using the standard @value{GDBN} remote serial protocol.
11262
11263@table @emph
11264@item On the target machine,
11265you need to have a copy of the program you want to debug.
11266@code{gdbserve.nlm} does not need your program's symbol table, so you
11267can strip the program if necessary to save space. @value{GDBN} on the
11268host system does all the symbol handling.
11269
11270To use the server, you must tell it how to communicate with
11271@value{GDBN}; the name of your program; and the arguments for your
11272program. The syntax is:
11273
5d161b24 11274@smallexample
104c1213
JM
11275load gdbserve [ BOARD=@var{board} ] [ PORT=@var{port} ]
11276 [ BAUD=@var{baud} ] @var{program} [ @var{args} @dots{} ]
11277@end smallexample
11278
11279@var{board} and @var{port} specify the serial line; @var{baud} specifies
11280the baud rate used by the connection. @var{port} and @var{node} default
d4f3574e 11281to 0, @var{baud} defaults to 9600@dmn{bps}.
104c1213
JM
11282
11283For example, to debug Emacs with the argument @samp{foo.txt}and
5d161b24 11284communicate with @value{GDBN} over serial port number 2 or board 1
d4f3574e 11285using a 19200@dmn{bps} connection:
104c1213
JM
11286
11287@smallexample
11288load gdbserve BOARD=1 PORT=2 BAUD=19200 emacs foo.txt
11289@end smallexample
11290
11291@item On the @value{GDBN} host machine,
11292you need an unstripped copy of your program, since @value{GDBN} needs
11293symbols and debugging information. Start up @value{GDBN} as usual,
11294using the name of the local copy of your program as the first argument.
11295(You may also need the @w{@samp{--baud}} option if the serial line is
d4f3574e 11296running at anything other than 9600@dmn{bps}. After that, use @code{target
104c1213
JM
11297remote} to establish communications with @code{gdbserve.nlm}. Its
11298argument is a device name (usually a serial device, like
11299@file{/dev/ttyb}). For example:
11300
11301@smallexample
11302(@value{GDBP}) target remote /dev/ttyb
11303@end smallexample
11304
11305@noindent
11306communications with the server via serial line @file{/dev/ttyb}.
11307@end table
11308
6d2ebf8b 11309@node KOD
104c1213
JM
11310@section Kernel Object Display
11311
11312@cindex kernel object display
11313@cindex kernel object
11314@cindex KOD
11315
11316Some targets support kernel object display. Using this facility,
11317@value{GDBN} communicates specially with the underlying operating system
11318and can display information about operating system-level objects such as
11319mutexes and other synchronization objects. Exactly which objects can be
11320displayed is determined on a per-OS basis.
11321
11322Use the @code{set os} command to set the operating system. This tells
11323@value{GDBN} which kernel object display module to initialize:
11324
11325@example
2df3850c 11326(@value{GDBP}) set os cisco
104c1213
JM
11327@end example
11328
11329If @code{set os} succeeds, @value{GDBN} will display some information
11330about the operating system, and will create a new @code{info} command
11331which can be used to query the target. The @code{info} command is named
11332after the operating system:
11333
11334@example
2df3850c 11335(@value{GDBP}) info cisco
104c1213
JM
11336List of Cisco Kernel Objects
11337Object Description
11338any Any and all objects
11339@end example
11340
11341Further subcommands can be used to query about particular objects known
11342by the kernel.
11343
11344There is currently no way to determine whether a given operating system
96baa820
JM
11345is supported other than to try it.
11346
11347
6d2ebf8b 11348@node Configurations
104c1213
JM
11349@chapter Configuration-Specific Information
11350
11351While nearly all @value{GDBN} commands are available for all native and
11352cross versions of the debugger, there are some exceptions. This chapter
11353describes things that are only available in certain configurations.
11354
11355There are three major categories of configurations: native
11356configurations, where the host and target are the same, embedded
11357operating system configurations, which are usually the same for several
11358different processor architectures, and bare embedded processors, which
11359are quite different from each other.
11360
11361@menu
11362* Native::
11363* Embedded OS::
11364* Embedded Processors::
11365* Architectures::
11366@end menu
11367
6d2ebf8b 11368@node Native
104c1213
JM
11369@section Native
11370
11371This section describes details specific to particular native
11372configurations.
11373
11374@menu
11375* HP-UX:: HP-UX
11376* SVR4 Process Information:: SVR4 process information
9f20bf26 11377* DJGPP Native:: Features specific to the DJGPP port
104c1213
JM
11378@end menu
11379
6d2ebf8b 11380@node HP-UX
104c1213
JM
11381@subsection HP-UX
11382
11383On HP-UX systems, if you refer to a function or variable name that
11384begins with a dollar sign, @value{GDBN} searches for a user or system
11385name first, before it searches for a convenience variable.
11386
6d2ebf8b 11387@node SVR4 Process Information
104c1213
JM
11388@subsection SVR4 process information
11389
11390@kindex /proc
11391@cindex process image
11392
11393Many versions of SVR4 provide a facility called @samp{/proc} that can be
11394used to examine the image of a running process using file-system
11395subroutines. If @value{GDBN} is configured for an operating system with
11396this facility, the command @code{info proc} is available to report on
11397several kinds of information about the process running your program.
11398@code{info proc} works only on SVR4 systems that include the
11399@code{procfs} code. This includes OSF/1 (Digital Unix), Solaris, Irix,
11400and Unixware, but not HP-UX or Linux, for example.
11401
11402@table @code
11403@kindex info proc
11404@item info proc
11405Summarize available information about the process.
11406
11407@kindex info proc mappings
11408@item info proc mappings
11409Report on the address ranges accessible in the program, with information
11410on whether your program may read, write, or execute each range.
f6680716
MS
11411@ignore
11412@comment These sub-options of 'info proc' were not included when
11413@comment procfs.c was re-written. Keep their descriptions around
11414@comment against the day when someone finds the time to put them back in.
104c1213
JM
11415@kindex info proc times
11416@item info proc times
11417Starting time, user CPU time, and system CPU time for your program and
11418its children.
11419
11420@kindex info proc id
11421@item info proc id
11422Report on the process IDs related to your program: its own process ID,
11423the ID of its parent, the process group ID, and the session ID.
11424
11425@kindex info proc status
11426@item info proc status
11427General information on the state of the process. If the process is
11428stopped, this report includes the reason for stopping, and any signal
11429received.
11430
11431@item info proc all
11432Show all the above information about the process.
f6680716 11433@end ignore
104c1213
JM
11434@end table
11435
9f20bf26
EZ
11436@node DJGPP Native
11437@subsection Features for Debugging @sc{djgpp} Programs
11438@cindex @sc{djgpp} debugging
11439@cindex native @sc{djgpp} debugging
11440@cindex MS-DOS-specific commands
11441
11442@sc{djgpp} is the port of @sc{gnu} development tools to MS-DOS and
11443MS-Windows. @sc{djgpp} programs are 32-bit protected-mode programs
11444that use the @dfn{DPMI} (DOS Protected-Mode Interface) API to run on
11445top of real-mode DOS systems and their emulations.
11446
11447@value{GDBN} supports native debugging of @sc{djgpp} programs, and
11448defines a few commands specific to the @sc{djgpp} port. This
11449subsection describes those commands.
11450
11451@table @code
11452@kindex info dos
11453@item info dos
11454This is a prefix of @sc{djgpp}-specific commands which print
11455information about the target system and important OS structures.
11456
11457@kindex sysinfo
11458@cindex MS-DOS system info
11459@cindex free memory information (MS-DOS)
11460@item info dos sysinfo
11461This command displays assorted information about the underlying
11462platform: the CPU type and features, the OS version and flavor, the
11463DPMI version, and the available conventional and DPMI memory.
11464
11465@cindex GDT
11466@cindex LDT
11467@cindex IDT
11468@cindex segment descriptor tables
11469@cindex descriptor tables display
11470@item info dos gdt
11471@itemx info dos ldt
11472@itemx info dos idt
11473These 3 commands display entries from, respectively, Global, Local,
11474and Interrupt Descriptor Tables (GDT, LDT, and IDT). The descriptor
11475tables are data structures which store a descriptor for each segment
11476that is currently in use. The segment's selector is an index into a
11477descriptor table; the table entry for that index holds the
11478descriptor's base address and limit, and its attributes and access
11479rights.
11480
11481A typical @sc{djgpp} program uses 3 segments: a code segment, a data
11482segment (used for both data and the stack), and a DOS segment (which
11483allows access to DOS/BIOS data structures and absolute addresses in
11484conventional memory). However, the DPMI host will usually define
11485additional segments in order to support the DPMI environment.
11486
11487@cindex garbled pointers
11488These commands allow to display entries from the descriptor tables.
11489Without an argument, all entries from the specified table are
11490displayed. An argument, which should be an integer expression, means
11491display a single entry whose index is given by the argument. For
11492example, here's a convenient way to display information about the
11493debugged program's data segment:
11494
11495@smallexample
11496(@value{GDBP}) info dos ldt $ds
114970x13f: base=0x11970000 limit=0x0009ffff 32-Bit Data (Read/Write, Exp-up)
11498@end smallexample
11499
11500@noindent
11501This comes in handy when you want to see whether a pointer is outside
11502the data segment's limit (i.e.@: @dfn{garbled}).
11503
11504@cindex page tables display (MS-DOS)
11505@item info dos pde
11506@itemx info dos pte
11507These two commands display entries from, respectively, the Page
11508Directory and the Page Tables. Page Directories and Page Tables are
11509data structures which control how virtual memory addresses are mapped
11510into physical addresses. A Page Table includes an entry for every
11511page of memory that is mapped into the program's address space; there
11512may be several Page Tables, each one holding up to 4096 entries. A
11513Page Directory has up to 4096 entries, one each for every Page Table
11514that is currently in use.
11515
11516Without an argument, @kbd{info dos pde} displays the entire Page
11517Directory, and @kbd{info dos pte} displays all the entries in all of
11518the Page Tables. An argument, an integer expression, given to the
11519@kbd{info dos pde} command means display only that entry from the Page
11520Directory table. An argument given to the @kbd{info dos pte} command
11521means display entries from a single Page Table, the one pointed to by
11522the specified entry in the Page Directory.
11523
11524These commands are useful when your program uses @dfn{DMA} (Direct
11525Memory Access), which needs physical addresses to program the DMA
11526controller.
11527
11528These commands are supported only with some DPMI servers.
11529
11530@cindex physical address from linear address
11531@item info dos address-pte
11532This command displays the Page Table entry for a specified linear
11533address. The argument linear address should already have the
11534appropriate segment's base address added to it, because this command
11535accepts addresses which may belong to @emph{any} segment. For
11536example, here's how to display the Page Table entry for the page where
11537the variable @code{i} is stored:
11538
11539@smallexample
11540(@value{GDBP}) info dos address-pte __djgpp_base_address + (char *)&i
11541Page Table entry for address 0x11a00d30:
11542Base=0x02698000 Dirty Acc. Not-Cached Write-Back Usr Read-Write +0xd30
11543@end smallexample
11544
11545@noindent
11546This says that @code{i} is stored at offset @code{0xd30} from the page
11547whose physical base address is @code{0x02698000}, and prints all the
11548attributes of that page.
11549
11550Note that you must cast the addresses of variables to a @code{char *},
11551since otherwise the value of @code{__djgpp_base_address}, the base
11552address of all variables and functions in a @sc{djgpp} program, will
11553be added using the rules of C pointer arithmetics: if @code{i} is
11554declared an @code{int}, @value{GDBN} will add 4 times the value of
11555@code{__djgpp_base_address} to the address of @code{i}.
11556
11557Here's another example, it displays the Page Table entry for the
11558transfer buffer:
11559
11560@smallexample
11561(@value{GDBP}) info dos address-pte *((unsigned *)&_go32_info_block + 3)
11562Page Table entry for address 0x29110:
11563Base=0x00029000 Dirty Acc. Not-Cached Write-Back Usr Read-Write +0x110
11564@end smallexample
11565
11566@noindent
11567(The @code{+ 3} offset is because the transfer buffer's address is the
115683rd member of the @code{_go32_info_block} structure.) The output of
11569this command clearly shows that addresses in conventional memory are
11570mapped 1:1, i.e.@: the physical and linear addresses are identical.
11571
11572This command is supported only with some DPMI servers.
11573@end table
11574
6d2ebf8b 11575@node Embedded OS
104c1213
JM
11576@section Embedded Operating Systems
11577
11578This section describes configurations involving the debugging of
11579embedded operating systems that are available for several different
11580architectures.
11581
11582@menu
11583* VxWorks:: Using @value{GDBN} with VxWorks
11584@end menu
11585
11586@value{GDBN} includes the ability to debug programs running on
11587various real-time operating systems.
11588
6d2ebf8b 11589@node VxWorks
104c1213
JM
11590@subsection Using @value{GDBN} with VxWorks
11591
11592@cindex VxWorks
11593
11594@table @code
11595
11596@kindex target vxworks
11597@item target vxworks @var{machinename}
11598A VxWorks system, attached via TCP/IP. The argument @var{machinename}
11599is the target system's machine name or IP address.
11600
11601@end table
11602
11603On VxWorks, @code{load} links @var{filename} dynamically on the
11604current target system as well as adding its symbols in @value{GDBN}.
11605
11606@value{GDBN} enables developers to spawn and debug tasks running on networked
11607VxWorks targets from a Unix host. Already-running tasks spawned from
11608the VxWorks shell can also be debugged. @value{GDBN} uses code that runs on
11609both the Unix host and on the VxWorks target. The program
d4f3574e 11610@code{@value{GDBP}} is installed and executed on the Unix host. (It may be
104c1213 11611installed with the name @code{vxgdb}, to distinguish it from a
96a2c332 11612@value{GDBN} for debugging programs on the host itself.)
104c1213
JM
11613
11614@table @code
11615@item VxWorks-timeout @var{args}
11616@kindex vxworks-timeout
5d161b24
DB
11617All VxWorks-based targets now support the option @code{vxworks-timeout}.
11618This option is set by the user, and @var{args} represents the number of
11619seconds @value{GDBN} waits for responses to rpc's. You might use this if
11620your VxWorks target is a slow software simulator or is on the far side
104c1213
JM
11621of a thin network line.
11622@end table
11623
11624The following information on connecting to VxWorks was current when
11625this manual was produced; newer releases of VxWorks may use revised
11626procedures.
11627
11628@kindex INCLUDE_RDB
11629To use @value{GDBN} with VxWorks, you must rebuild your VxWorks kernel
11630to include the remote debugging interface routines in the VxWorks
11631library @file{rdb.a}. To do this, define @code{INCLUDE_RDB} in the
11632VxWorks configuration file @file{configAll.h} and rebuild your VxWorks
11633kernel. The resulting kernel contains @file{rdb.a}, and spawns the
11634source debugging task @code{tRdbTask} when VxWorks is booted. For more
11635information on configuring and remaking VxWorks, see the manufacturer's
11636manual.
11637@c VxWorks, see the @cite{VxWorks Programmer's Guide}.
11638
11639Once you have included @file{rdb.a} in your VxWorks system image and set
11640your Unix execution search path to find @value{GDBN}, you are ready to
96a2c332
SS
11641run @value{GDBN}. From your Unix host, run @code{@value{GDBP}} (or
11642@code{vxgdb}, depending on your installation).
104c1213
JM
11643
11644@value{GDBN} comes up showing the prompt:
11645
11646@example
11647(vxgdb)
11648@end example
11649
11650@menu
11651* VxWorks Connection:: Connecting to VxWorks
11652* VxWorks Download:: VxWorks download
11653* VxWorks Attach:: Running tasks
11654@end menu
11655
6d2ebf8b 11656@node VxWorks Connection
104c1213
JM
11657@subsubsection Connecting to VxWorks
11658
11659The @value{GDBN} command @code{target} lets you connect to a VxWorks target on the
11660network. To connect to a target whose host name is ``@code{tt}'', type:
11661
11662@example
11663(vxgdb) target vxworks tt
11664@end example
11665
11666@need 750
11667@value{GDBN} displays messages like these:
11668
11669@smallexample
5d161b24 11670Attaching remote machine across net...
104c1213
JM
11671Connected to tt.
11672@end smallexample
11673
11674@need 1000
11675@value{GDBN} then attempts to read the symbol tables of any object modules
11676loaded into the VxWorks target since it was last booted. @value{GDBN} locates
11677these files by searching the directories listed in the command search
11678path (@pxref{Environment, ,Your program's environment}); if it fails
11679to find an object file, it displays a message such as:
11680
11681@example
11682prog.o: No such file or directory.
11683@end example
11684
11685When this happens, add the appropriate directory to the search path with
11686the @value{GDBN} command @code{path}, and execute the @code{target}
11687command again.
11688
6d2ebf8b 11689@node VxWorks Download
104c1213
JM
11690@subsubsection VxWorks download
11691
11692@cindex download to VxWorks
11693If you have connected to the VxWorks target and you want to debug an
11694object that has not yet been loaded, you can use the @value{GDBN}
11695@code{load} command to download a file from Unix to VxWorks
11696incrementally. The object file given as an argument to the @code{load}
11697command is actually opened twice: first by the VxWorks target in order
11698to download the code, then by @value{GDBN} in order to read the symbol
11699table. This can lead to problems if the current working directories on
11700the two systems differ. If both systems have NFS mounted the same
11701filesystems, you can avoid these problems by using absolute paths.
11702Otherwise, it is simplest to set the working directory on both systems
11703to the directory in which the object file resides, and then to reference
11704the file by its name, without any path. For instance, a program
11705@file{prog.o} may reside in @file{@var{vxpath}/vw/demo/rdb} in VxWorks
11706and in @file{@var{hostpath}/vw/demo/rdb} on the host. To load this
11707program, type this on VxWorks:
11708
11709@example
11710-> cd "@var{vxpath}/vw/demo/rdb"
11711@end example
d4f3574e
SS
11712
11713@noindent
104c1213
JM
11714Then, in @value{GDBN}, type:
11715
11716@example
5d161b24 11717(vxgdb) cd @var{hostpath}/vw/demo/rdb
104c1213
JM
11718(vxgdb) load prog.o
11719@end example
11720
11721@value{GDBN} displays a response similar to this:
11722
11723@smallexample
11724Reading symbol data from wherever/vw/demo/rdb/prog.o... done.
11725@end smallexample
11726
11727You can also use the @code{load} command to reload an object module
11728after editing and recompiling the corresponding source file. Note that
11729this makes @value{GDBN} delete all currently-defined breakpoints,
11730auto-displays, and convenience variables, and to clear the value
11731history. (This is necessary in order to preserve the integrity of
d4f3574e 11732debugger's data structures that reference the target system's symbol
104c1213
JM
11733table.)
11734
6d2ebf8b 11735@node VxWorks Attach
104c1213
JM
11736@subsubsection Running tasks
11737
11738@cindex running VxWorks tasks
11739You can also attach to an existing task using the @code{attach} command as
11740follows:
11741
11742@example
11743(vxgdb) attach @var{task}
11744@end example
11745
11746@noindent
11747where @var{task} is the VxWorks hexadecimal task ID. The task can be running
11748or suspended when you attach to it. Running tasks are suspended at
11749the time of attachment.
11750
6d2ebf8b 11751@node Embedded Processors
104c1213
JM
11752@section Embedded Processors
11753
11754This section goes into details specific to particular embedded
11755configurations.
11756
11757@menu
11758* A29K Embedded:: AMD A29K Embedded
11759* ARM:: ARM
11760* H8/300:: Hitachi H8/300
11761* H8/500:: Hitachi H8/500
11762* i960:: Intel i960
11763* M32R/D:: Mitsubishi M32R/D
11764* M68K:: Motorola M68K
11765* M88K:: Motorola M88K
11766* MIPS Embedded:: MIPS Embedded
11767* PA:: HP PA Embedded
11768* PowerPC: PowerPC
11769* SH:: Hitachi SH
11770* Sparclet:: Tsqware Sparclet
11771* Sparclite:: Fujitsu Sparclite
11772* ST2000:: Tandem ST2000
11773* Z8000:: Zilog Z8000
11774@end menu
11775
6d2ebf8b 11776@node A29K Embedded
104c1213
JM
11777@subsection AMD A29K Embedded
11778
11779@menu
11780* A29K UDI::
11781* A29K EB29K::
11782* Comms (EB29K):: Communications setup
11783* gdb-EB29K:: EB29K cross-debugging
11784* Remote Log:: Remote log
11785@end menu
11786
11787@table @code
11788
11789@kindex target adapt
11790@item target adapt @var{dev}
11791Adapt monitor for A29K.
11792
11793@kindex target amd-eb
11794@item target amd-eb @var{dev} @var{speed} @var{PROG}
11795@cindex AMD EB29K
11796Remote PC-resident AMD EB29K board, attached over serial lines.
11797@var{dev} is the serial device, as for @code{target remote};
11798@var{speed} allows you to specify the linespeed; and @var{PROG} is the
11799name of the program to be debugged, as it appears to DOS on the PC.
11800@xref{A29K EB29K, ,EBMON protocol for AMD29K}.
11801
11802@end table
11803
6d2ebf8b 11804@node A29K UDI
104c1213
JM
11805@subsubsection A29K UDI
11806
11807@cindex UDI
11808@cindex AMD29K via UDI
11809
11810@value{GDBN} supports AMD's UDI (``Universal Debugger Interface'')
11811protocol for debugging the a29k processor family. To use this
11812configuration with AMD targets running the MiniMON monitor, you need the
11813program @code{MONTIP}, available from AMD at no charge. You can also
11814use @value{GDBN} with the UDI-conformant a29k simulator program
11815@code{ISSTIP}, also available from AMD.
11816
11817@table @code
11818@item target udi @var{keyword}
11819@kindex udi
11820Select the UDI interface to a remote a29k board or simulator, where
11821@var{keyword} is an entry in the AMD configuration file @file{udi_soc}.
11822This file contains keyword entries which specify parameters used to
11823connect to a29k targets. If the @file{udi_soc} file is not in your
11824working directory, you must set the environment variable @samp{UDICONF}
11825to its pathname.
11826@end table
11827
6d2ebf8b 11828@node A29K EB29K
104c1213
JM
11829@subsubsection EBMON protocol for AMD29K
11830
11831@cindex EB29K board
11832@cindex running 29K programs
11833
11834AMD distributes a 29K development board meant to fit in a PC, together
11835with a DOS-hosted monitor program called @code{EBMON}. As a shorthand
11836term, this development system is called the ``EB29K''. To use
11837@value{GDBN} from a Unix system to run programs on the EB29K board, you
11838must first connect a serial cable between the PC (which hosts the EB29K
11839board) and a serial port on the Unix system. In the following, we
11840assume you've hooked the cable between the PC's @file{COM1} port and
11841@file{/dev/ttya} on the Unix system.
11842
6d2ebf8b 11843@node Comms (EB29K)
104c1213
JM
11844@subsubsection Communications setup
11845
11846The next step is to set up the PC's port, by doing something like this
11847in DOS on the PC:
11848
11849@example
11850C:\> MODE com1:9600,n,8,1,none
11851@end example
11852
11853@noindent
11854This example---run on an MS DOS 4.0 system---sets the PC port to 9600
11855bps, no parity, eight data bits, one stop bit, and no ``retry'' action;
11856you must match the communications parameters when establishing the Unix
11857end of the connection as well.
11858@c FIXME: Who knows what this "no retry action" crud from the DOS manual may
5d161b24 11859@c mean? It's optional; leave it out? ---doc@cygnus.com, 25feb91
d4f3574e
SS
11860@c
11861@c It's optional, but it's unwise to omit it: who knows what is the
11862@c default value set when the DOS machines boots? "No retry" means that
11863@c the DOS serial device driver won't retry the operation if it fails;
11864@c I understand that this is needed because the GDB serial protocol
11865@c handles any errors and retransmissions itself. ---Eli Zaretskii, 3sep99
104c1213
JM
11866
11867To give control of the PC to the Unix side of the serial line, type
11868the following at the DOS console:
11869
11870@example
11871C:\> CTTY com1
11872@end example
11873
11874@noindent
11875(Later, if you wish to return control to the DOS console, you can use
11876the command @code{CTTY con}---but you must send it over the device that
96a2c332 11877had control, in our example over the @file{COM1} serial line.)
104c1213
JM
11878
11879From the Unix host, use a communications program such as @code{tip} or
11880@code{cu} to communicate with the PC; for example,
11881
11882@example
11883cu -s 9600 -l /dev/ttya
11884@end example
11885
11886@noindent
11887The @code{cu} options shown specify, respectively, the linespeed and the
11888serial port to use. If you use @code{tip} instead, your command line
11889may look something like the following:
11890
11891@example
11892tip -9600 /dev/ttya
11893@end example
11894
11895@noindent
11896Your system may require a different name where we show
11897@file{/dev/ttya} as the argument to @code{tip}. The communications
11898parameters, including which port to use, are associated with the
11899@code{tip} argument in the ``remote'' descriptions file---normally the
11900system table @file{/etc/remote}.
11901@c FIXME: What if anything needs doing to match the "n,8,1,none" part of
11902@c the DOS side's comms setup? cu can support -o (odd
11903@c parity), -e (even parity)---apparently no settings for no parity or
11904@c for character size. Taken from stty maybe...? John points out tip
11905@c can set these as internal variables, eg ~s parity=none; man stty
11906@c suggests that it *might* work to stty these options with stdin or
11907@c stdout redirected... ---doc@cygnus.com, 25feb91
d4f3574e
SS
11908@c
11909@c There's nothing to be done for the "none" part of the DOS MODE
11910@c command. The rest of the parameters should be matched by the
11911@c baudrate, bits, and parity used by the Unix side. ---Eli Zaretskii, 3Sep99
104c1213
JM
11912
11913@kindex EBMON
11914Using the @code{tip} or @code{cu} connection, change the DOS working
11915directory to the directory containing a copy of your 29K program, then
11916start the PC program @code{EBMON} (an EB29K control program supplied
11917with your board by AMD). You should see an initial display from
11918@code{EBMON} similar to the one that follows, ending with the
11919@code{EBMON} prompt @samp{#}---
11920
11921@example
11922C:\> G:
11923
11924G:\> CD \usr\joe\work29k
11925
11926G:\USR\JOE\WORK29K> EBMON
11927Am29000 PC Coprocessor Board Monitor, version 3.0-18
11928Copyright 1990 Advanced Micro Devices, Inc.
11929Written by Gibbons and Associates, Inc.
11930
11931Enter '?' or 'H' for help
11932
11933PC Coprocessor Type = EB29K
11934I/O Base = 0x208
11935Memory Base = 0xd0000
11936
11937Data Memory Size = 2048KB
11938Available I-RAM Range = 0x8000 to 0x1fffff
11939Available D-RAM Range = 0x80002000 to 0x801fffff
11940
11941PageSize = 0x400
11942Register Stack Size = 0x800
11943Memory Stack Size = 0x1800
11944
11945CPU PRL = 0x3
11946Am29027 Available = No
11947Byte Write Available = Yes
11948
11949# ~.
11950@end example
11951
11952Then exit the @code{cu} or @code{tip} program (done in the example by
11953typing @code{~.} at the @code{EBMON} prompt). @code{EBMON} keeps
11954running, ready for @value{GDBN} to take over.
11955
11956For this example, we've assumed what is probably the most convenient
11957way to make sure the same 29K program is on both the PC and the Unix
d4f3574e 11958system: a PC/NFS connection that establishes ``drive @file{G:}'' on the
104c1213
JM
11959PC as a file system on the Unix host. If you do not have PC/NFS or
11960something similar connecting the two systems, you must arrange some
11961other way---perhaps floppy-disk transfer---of getting the 29K program
11962from the Unix system to the PC; @value{GDBN} does @emph{not} download it over the
11963serial line.
11964
6d2ebf8b 11965@node gdb-EB29K
104c1213
JM
11966@subsubsection EB29K cross-debugging
11967
11968Finally, @code{cd} to the directory containing an image of your 29K
11969program on the Unix system, and start @value{GDBN}---specifying as argument the
11970name of your 29K program:
11971
11972@example
11973cd /usr/joe/work29k
11974@value{GDBP} myfoo
11975@end example
11976
11977@need 500
11978Now you can use the @code{target} command:
11979
11980@example
11981target amd-eb /dev/ttya 9600 MYFOO
11982@c FIXME: test above 'target amd-eb' as spelled, with caps! caps are meant to
11983@c emphasize that this is the name as seen by DOS (since I think DOS is
11984@c single-minded about case of letters). ---doc@cygnus.com, 25feb91
11985@end example
11986
11987@noindent
11988In this example, we've assumed your program is in a file called
11989@file{myfoo}. Note that the filename given as the last argument to
11990@code{target amd-eb} should be the name of the program as it appears to DOS.
11991In our example this is simply @code{MYFOO}, but in general it can include
11992a DOS path, and depending on your transfer mechanism may not resemble
11993the name on the Unix side.
11994
11995At this point, you can set any breakpoints you wish; when you are ready
11996to see your program run on the 29K board, use the @value{GDBN} command
11997@code{run}.
11998
11999To stop debugging the remote program, use the @value{GDBN} @code{detach}
12000command.
12001
12002To return control of the PC to its console, use @code{tip} or @code{cu}
12003once again, after your @value{GDBN} session has concluded, to attach to
12004@code{EBMON}. You can then type the command @code{q} to shut down
12005@code{EBMON}, returning control to the DOS command-line interpreter.
d4f3574e 12006Type @kbd{CTTY con} to return command input to the main DOS console,
104c1213
JM
12007and type @kbd{~.} to leave @code{tip} or @code{cu}.
12008
6d2ebf8b 12009@node Remote Log
104c1213 12010@subsubsection Remote log
41afff9a 12011@cindex @file{eb.log}, a log file for EB29K
104c1213
JM
12012@cindex log file for EB29K
12013
12014The @code{target amd-eb} command creates a file @file{eb.log} in the
12015current working directory, to help debug problems with the connection.
12016@file{eb.log} records all the output from @code{EBMON}, including echoes
12017of the commands sent to it. Running @samp{tail -f} on this file in
12018another window often helps to understand trouble with @code{EBMON}, or
12019unexpected events on the PC side of the connection.
12020
6d2ebf8b 12021@node ARM
104c1213
JM
12022@subsection ARM
12023
12024@table @code
12025
12026@kindex target rdi
12027@item target rdi @var{dev}
12028ARM Angel monitor, via RDI library interface to ADP protocol. You may
12029use this target to communicate with both boards running the Angel
12030monitor, or with the EmbeddedICE JTAG debug device.
5d161b24 12031
104c1213
JM
12032@kindex target rdp
12033@item target rdp @var{dev}
12034ARM Demon monitor.
12035
12036@end table
12037
6d2ebf8b 12038@node H8/300
104c1213
JM
12039@subsection Hitachi H8/300
12040
12041@table @code
12042
d4f3574e 12043@kindex target hms@r{, with H8/300}
104c1213
JM
12044@item target hms @var{dev}
12045A Hitachi SH, H8/300, or H8/500 board, attached via serial line to your host.
12046Use special commands @code{device} and @code{speed} to control the serial
12047line and the communications speed used.
12048
d4f3574e 12049@kindex target e7000@r{, with H8/300}
104c1213
JM
12050@item target e7000 @var{dev}
12051E7000 emulator for Hitachi H8 and SH.
12052
d4f3574e
SS
12053@kindex target sh3@r{, with H8/300}
12054@kindex target sh3e@r{, with H8/300}
104c1213 12055@item target sh3 @var{dev}
96a2c332 12056@itemx target sh3e @var{dev}
104c1213
JM
12057Hitachi SH-3 and SH-3E target systems.
12058
12059@end table
12060
12061@cindex download to H8/300 or H8/500
12062@cindex H8/300 or H8/500 download
12063@cindex download to Hitachi SH
12064@cindex Hitachi SH download
12065When you select remote debugging to a Hitachi SH, H8/300, or H8/500
12066board, the @code{load} command downloads your program to the Hitachi
12067board and also opens it as the current executable target for
12068@value{GDBN} on your host (like the @code{file} command).
12069
12070@value{GDBN} needs to know these things to talk to your
5d161b24 12071Hitachi SH, H8/300, or H8/500:
104c1213
JM
12072
12073@enumerate
12074@item
12075that you want to use @samp{target hms}, the remote debugging interface
12076for Hitachi microprocessors, or @samp{target e7000}, the in-circuit
12077emulator for the Hitachi SH and the Hitachi 300H. (@samp{target hms} is
2df3850c 12078the default when @value{GDBN} is configured specifically for the Hitachi SH,
104c1213
JM
12079H8/300, or H8/500.)
12080
12081@item
12082what serial device connects your host to your Hitachi board (the first
12083serial device available on your host is the default).
12084
12085@item
12086what speed to use over the serial device.
12087@end enumerate
12088
12089@menu
12090* Hitachi Boards:: Connecting to Hitachi boards.
12091* Hitachi ICE:: Using the E7000 In-Circuit Emulator.
12092* Hitachi Special:: Special @value{GDBN} commands for Hitachi micros.
12093@end menu
12094
6d2ebf8b 12095@node Hitachi Boards
104c1213
JM
12096@subsubsection Connecting to Hitachi boards
12097
12098@c only for Unix hosts
12099@kindex device
12100@cindex serial device, Hitachi micros
96a2c332 12101Use the special @code{@value{GDBN}} command @samp{device @var{port}} if you
104c1213
JM
12102need to explicitly set the serial device. The default @var{port} is the
12103first available port on your host. This is only necessary on Unix
12104hosts, where it is typically something like @file{/dev/ttya}.
12105
12106@kindex speed
12107@cindex serial line speed, Hitachi micros
96a2c332 12108@code{@value{GDBN}} has another special command to set the communications
104c1213 12109speed: @samp{speed @var{bps}}. This command also is only used from Unix
2df3850c 12110hosts; on DOS hosts, set the line speed as usual from outside @value{GDBN} with
d4f3574e
SS
12111the DOS @code{mode} command (for instance,
12112@w{@kbd{mode com2:9600,n,8,1,p}} for a 9600@dmn{bps} connection).
104c1213
JM
12113
12114The @samp{device} and @samp{speed} commands are available only when you
12115use a Unix host to debug your Hitachi microprocessor programs. If you
12116use a DOS host,
12117@value{GDBN} depends on an auxiliary terminate-and-stay-resident program
12118called @code{asynctsr} to communicate with the development board
12119through a PC serial port. You must also use the DOS @code{mode} command
12120to set up the serial port on the DOS side.
12121
12122The following sample session illustrates the steps needed to start a
12123program under @value{GDBN} control on an H8/300. The example uses a
12124sample H8/300 program called @file{t.x}. The procedure is the same for
12125the Hitachi SH and the H8/500.
12126
12127First hook up your development board. In this example, we use a
12128board attached to serial port @code{COM2}; if you use a different serial
12129port, substitute its name in the argument of the @code{mode} command.
12130When you call @code{asynctsr}, the auxiliary comms program used by the
d4f3574e 12131debugger, you give it just the numeric part of the serial port's name;
104c1213
JM
12132for example, @samp{asyncstr 2} below runs @code{asyncstr} on
12133@code{COM2}.
12134
12135@example
12136C:\H8300\TEST> asynctsr 2
12137C:\H8300\TEST> mode com2:9600,n,8,1,p
12138
12139Resident portion of MODE loaded
12140
12141COM2: 9600, n, 8, 1, p
12142
12143@end example
12144
12145@quotation
12146@emph{Warning:} We have noticed a bug in PC-NFS that conflicts with
12147@code{asynctsr}. If you also run PC-NFS on your DOS host, you may need to
12148disable it, or even boot without it, to use @code{asynctsr} to control
12149your development board.
12150@end quotation
12151
d4f3574e 12152@kindex target hms@r{, and serial protocol}
104c1213
JM
12153Now that serial communications are set up, and the development board is
12154connected, you can start up @value{GDBN}. Call @code{@value{GDBP}} with
96a2c332 12155the name of your program as the argument. @code{@value{GDBN}} prompts
104c1213
JM
12156you, as usual, with the prompt @samp{(@value{GDBP})}. Use two special
12157commands to begin your debugging session: @samp{target hms} to specify
12158cross-debugging to the Hitachi board, and the @code{load} command to
12159download your program to the board. @code{load} displays the names of
12160the program's sections, and a @samp{*} for each 2K of data downloaded.
12161(If you want to refresh @value{GDBN} data on symbols or on the
12162executable file without downloading, use the @value{GDBN} commands
12163@code{file} or @code{symbol-file}. These commands, and @code{load}
12164itself, are described in @ref{Files,,Commands to specify files}.)
12165
12166@smallexample
12167(eg-C:\H8300\TEST) @value{GDBP} t.x
2df3850c 12168@value{GDBN} is free software and you are welcome to distribute copies
5d161b24 12169 of it under certain conditions; type "show copying" to see
104c1213 12170 the conditions.
5d161b24 12171There is absolutely no warranty for @value{GDBN}; type "show warranty"
104c1213 12172for details.
2df3850c
JM
12173@value{GDBN} @value{GDBVN}, Copyright 1992 Free Software Foundation, Inc...
12174(@value{GDBP}) target hms
104c1213 12175Connected to remote H8/300 HMS system.
2df3850c 12176(@value{GDBP}) load t.x
104c1213
JM
12177.text : 0x8000 .. 0xabde ***********
12178.data : 0xabde .. 0xad30 *
12179.stack : 0xf000 .. 0xf014 *
12180@end smallexample
12181
12182At this point, you're ready to run or debug your program. From here on,
12183you can use all the usual @value{GDBN} commands. The @code{break} command
12184sets breakpoints; the @code{run} command starts your program;
12185@code{print} or @code{x} display data; the @code{continue} command
12186resumes execution after stopping at a breakpoint. You can use the
12187@code{help} command at any time to find out more about @value{GDBN} commands.
12188
12189Remember, however, that @emph{operating system} facilities aren't
12190available on your development board; for example, if your program hangs,
12191you can't send an interrupt---but you can press the @sc{reset} switch!
12192
12193Use the @sc{reset} button on the development board
12194@itemize @bullet
12195@item
12196to interrupt your program (don't use @kbd{ctl-C} on the DOS host---it has
12197no way to pass an interrupt signal to the development board); and
12198
12199@item
12200to return to the @value{GDBN} command prompt after your program finishes
12201normally. The communications protocol provides no other way for @value{GDBN}
12202to detect program completion.
12203@end itemize
12204
12205In either case, @value{GDBN} sees the effect of a @sc{reset} on the
12206development board as a ``normal exit'' of your program.
12207
6d2ebf8b 12208@node Hitachi ICE
104c1213
JM
12209@subsubsection Using the E7000 in-circuit emulator
12210
d4f3574e 12211@kindex target e7000@r{, with Hitachi ICE}
104c1213
JM
12212You can use the E7000 in-circuit emulator to develop code for either the
12213Hitachi SH or the H8/300H. Use one of these forms of the @samp{target
12214e7000} command to connect @value{GDBN} to your E7000:
12215
12216@table @code
12217@item target e7000 @var{port} @var{speed}
12218Use this form if your E7000 is connected to a serial port. The
12219@var{port} argument identifies what serial port to use (for example,
12220@samp{com2}). The third argument is the line speed in bits per second
12221(for example, @samp{9600}).
12222
12223@item target e7000 @var{hostname}
12224If your E7000 is installed as a host on a TCP/IP network, you can just
12225specify its hostname; @value{GDBN} uses @code{telnet} to connect.
12226@end table
12227
6d2ebf8b 12228@node Hitachi Special
104c1213
JM
12229@subsubsection Special @value{GDBN} commands for Hitachi micros
12230
12231Some @value{GDBN} commands are available only for the H8/300:
12232
12233@table @code
12234
12235@kindex set machine
12236@kindex show machine
12237@item set machine h8300
12238@itemx set machine h8300h
12239Condition @value{GDBN} for one of the two variants of the H8/300
12240architecture with @samp{set machine}. You can use @samp{show machine}
12241to check which variant is currently in effect.
12242
12243@end table
12244
6d2ebf8b 12245@node H8/500
104c1213
JM
12246@subsection H8/500
12247
12248@table @code
12249
12250@kindex set memory @var{mod}
12251@cindex memory models, H8/500
12252@item set memory @var{mod}
12253@itemx show memory
12254Specify which H8/500 memory model (@var{mod}) you are using with
12255@samp{set memory}; check which memory model is in effect with @samp{show
12256memory}. The accepted values for @var{mod} are @code{small},
12257@code{big}, @code{medium}, and @code{compact}.
12258
12259@end table
12260
6d2ebf8b 12261@node i960
104c1213
JM
12262@subsection Intel i960
12263
12264@table @code
12265
12266@kindex target mon960
12267@item target mon960 @var{dev}
12268MON960 monitor for Intel i960.
12269
f0ca3dce 12270@kindex target nindy
104c1213
JM
12271@item target nindy @var{devicename}
12272An Intel 960 board controlled by a Nindy Monitor. @var{devicename} is
12273the name of the serial device to use for the connection, e.g.
12274@file{/dev/ttya}.
12275
12276@end table
12277
12278@cindex Nindy
12279@cindex i960
12280@dfn{Nindy} is a ROM Monitor program for Intel 960 target systems. When
12281@value{GDBN} is configured to control a remote Intel 960 using Nindy, you can
12282tell @value{GDBN} how to connect to the 960 in several ways:
12283
12284@itemize @bullet
12285@item
12286Through command line options specifying serial port, version of the
12287Nindy protocol, and communications speed;
12288
12289@item
12290By responding to a prompt on startup;
12291
12292@item
12293By using the @code{target} command at any point during your @value{GDBN}
12294session. @xref{Target Commands, ,Commands for managing targets}.
12295
104c1213
JM
12296@end itemize
12297
12298@cindex download to Nindy-960
12299With the Nindy interface to an Intel 960 board, @code{load}
12300downloads @var{filename} to the 960 as well as adding its symbols in
12301@value{GDBN}.
12302
12303@menu
12304* Nindy Startup:: Startup with Nindy
12305* Nindy Options:: Options for Nindy
12306* Nindy Reset:: Nindy reset command
12307@end menu
12308
6d2ebf8b 12309@node Nindy Startup
104c1213
JM
12310@subsubsection Startup with Nindy
12311
12312If you simply start @code{@value{GDBP}} without using any command-line
12313options, you are prompted for what serial port to use, @emph{before} you
12314reach the ordinary @value{GDBN} prompt:
12315
12316@example
5d161b24 12317Attach /dev/ttyNN -- specify NN, or "quit" to quit:
104c1213
JM
12318@end example
12319
12320@noindent
12321Respond to the prompt with whatever suffix (after @samp{/dev/tty})
12322identifies the serial port you want to use. You can, if you choose,
12323simply start up with no Nindy connection by responding to the prompt
12324with an empty line. If you do this and later wish to attach to Nindy,
12325use @code{target} (@pxref{Target Commands, ,Commands for managing targets}).
12326
6d2ebf8b 12327@node Nindy Options
104c1213
JM
12328@subsubsection Options for Nindy
12329
12330These are the startup options for beginning your @value{GDBN} session with a
12331Nindy-960 board attached:
12332
12333@table @code
12334@item -r @var{port}
12335Specify the serial port name of a serial interface to be used to connect
12336to the target system. This option is only available when @value{GDBN} is
12337configured for the Intel 960 target architecture. You may specify
12338@var{port} as any of: a full pathname (e.g. @samp{-r /dev/ttya}), a
12339device name in @file{/dev} (e.g. @samp{-r ttya}), or simply the unique
12340suffix for a specific @code{tty} (e.g. @samp{-r a}).
12341
12342@item -O
12343(An uppercase letter ``O'', not a zero.) Specify that @value{GDBN} should use
12344the ``old'' Nindy monitor protocol to connect to the target system.
12345This option is only available when @value{GDBN} is configured for the Intel 960
12346target architecture.
12347
12348@quotation
12349@emph{Warning:} if you specify @samp{-O}, but are actually trying to
12350connect to a target system that expects the newer protocol, the connection
12351fails, appearing to be a speed mismatch. @value{GDBN} repeatedly
12352attempts to reconnect at several different line speeds. You can abort
12353this process with an interrupt.
12354@end quotation
12355
12356@item -brk
12357Specify that @value{GDBN} should first send a @code{BREAK} signal to the target
12358system, in an attempt to reset it, before connecting to a Nindy target.
12359
12360@quotation
12361@emph{Warning:} Many target systems do not have the hardware that this
12362requires; it only works with a few boards.
12363@end quotation
12364@end table
12365
12366The standard @samp{-b} option controls the line speed used on the serial
12367port.
12368
12369@c @group
6d2ebf8b 12370@node Nindy Reset
104c1213
JM
12371@subsubsection Nindy reset command
12372
12373@table @code
12374@item reset
12375@kindex reset
12376For a Nindy target, this command sends a ``break'' to the remote target
12377system; this is only useful if the target has been equipped with a
12378circuit to perform a hard reset (or some other interesting action) when
12379a break is detected.
12380@end table
12381@c @end group
12382
6d2ebf8b 12383@node M32R/D
104c1213
JM
12384@subsection Mitsubishi M32R/D
12385
12386@table @code
12387
12388@kindex target m32r
12389@item target m32r @var{dev}
12390Mitsubishi M32R/D ROM monitor.
12391
12392@end table
12393
6d2ebf8b 12394@node M68K
104c1213
JM
12395@subsection M68k
12396
12397The Motorola m68k configuration includes ColdFire support, and
12398target command for the following ROM monitors.
12399
12400@table @code
12401
12402@kindex target abug
12403@item target abug @var{dev}
12404ABug ROM monitor for M68K.
12405
12406@kindex target cpu32bug
12407@item target cpu32bug @var{dev}
12408CPU32BUG monitor, running on a CPU32 (M68K) board.
12409
12410@kindex target dbug
12411@item target dbug @var{dev}
12412dBUG ROM monitor for Motorola ColdFire.
12413
12414@kindex target est
12415@item target est @var{dev}
12416EST-300 ICE monitor, running on a CPU32 (M68K) board.
12417
12418@kindex target rom68k
12419@item target rom68k @var{dev}
12420ROM 68K monitor, running on an M68K IDP board.
12421
12422@end table
12423
12424If @value{GDBN} is configured with @code{m68*-ericsson-*}, it will
12425instead have only a single special target command:
12426
12427@table @code
12428
12429@kindex target es1800
12430@item target es1800 @var{dev}
12431ES-1800 emulator for M68K.
12432
12433@end table
12434
12435[context?]
12436
12437@table @code
12438
12439@kindex target rombug
12440@item target rombug @var{dev}
12441ROMBUG ROM monitor for OS/9000.
12442
12443@end table
12444
6d2ebf8b 12445@node M88K
104c1213
JM
12446@subsection M88K
12447
12448@table @code
12449
12450@kindex target bug
12451@item target bug @var{dev}
12452BUG monitor, running on a MVME187 (m88k) board.
12453
12454@end table
12455
6d2ebf8b 12456@node MIPS Embedded
104c1213
JM
12457@subsection MIPS Embedded
12458
12459@cindex MIPS boards
12460@value{GDBN} can use the MIPS remote debugging protocol to talk to a
12461MIPS board attached to a serial line. This is available when
12462you configure @value{GDBN} with @samp{--target=mips-idt-ecoff}.
12463
12464@need 1000
12465Use these @value{GDBN} commands to specify the connection to your target board:
12466
12467@table @code
12468@item target mips @var{port}
12469@kindex target mips @var{port}
12470To run a program on the board, start up @code{@value{GDBP}} with the
12471name of your program as the argument. To connect to the board, use the
12472command @samp{target mips @var{port}}, where @var{port} is the name of
12473the serial port connected to the board. If the program has not already
12474been downloaded to the board, you may use the @code{load} command to
12475download it. You can then use all the usual @value{GDBN} commands.
12476
12477For example, this sequence connects to the target board through a serial
12478port, and loads and runs a program called @var{prog} through the
12479debugger:
12480
12481@example
12482host$ @value{GDBP} @var{prog}
2df3850c
JM
12483@value{GDBN} is free software and @dots{}
12484(@value{GDBP}) target mips /dev/ttyb
12485(@value{GDBP}) load @var{prog}
12486(@value{GDBP}) run
104c1213
JM
12487@end example
12488
12489@item target mips @var{hostname}:@var{portnumber}
12490On some @value{GDBN} host configurations, you can specify a TCP
12491connection (for instance, to a serial line managed by a terminal
12492concentrator) instead of a serial port, using the syntax
12493@samp{@var{hostname}:@var{portnumber}}.
12494
12495@item target pmon @var{port}
12496@kindex target pmon @var{port}
12497PMON ROM monitor.
12498
12499@item target ddb @var{port}
12500@kindex target ddb @var{port}
12501NEC's DDB variant of PMON for Vr4300.
12502
12503@item target lsi @var{port}
12504@kindex target lsi @var{port}
12505LSI variant of PMON.
12506
12507@kindex target r3900
12508@item target r3900 @var{dev}
12509Densan DVE-R3900 ROM monitor for Toshiba R3900 Mips.
12510
12511@kindex target array
12512@item target array @var{dev}
12513Array Tech LSI33K RAID controller board.
12514
12515@end table
12516
12517
12518@noindent
12519@value{GDBN} also supports these special commands for MIPS targets:
12520
12521@table @code
12522@item set processor @var{args}
12523@itemx show processor
12524@kindex set processor @var{args}
12525@kindex show processor
12526Use the @code{set processor} command to set the type of MIPS
12527processor when you want to access processor-type-specific registers.
5d161b24 12528For example, @code{set processor @var{r3041}} tells @value{GDBN}
96c405b3 12529to use the CPU registers appropriate for the 3041 chip.
5d161b24 12530Use the @code{show processor} command to see what MIPS processor @value{GDBN}
104c1213 12531is using. Use the @code{info reg} command to see what registers
5d161b24 12532@value{GDBN} is using.
104c1213
JM
12533
12534@item set mipsfpu double
12535@itemx set mipsfpu single
12536@itemx set mipsfpu none
12537@itemx show mipsfpu
12538@kindex set mipsfpu
12539@kindex show mipsfpu
12540@cindex MIPS remote floating point
12541@cindex floating point, MIPS remote
12542If your target board does not support the MIPS floating point
12543coprocessor, you should use the command @samp{set mipsfpu none} (if you
96a2c332 12544need this, you may wish to put the command in your @value{GDBN} init
104c1213
JM
12545file). This tells @value{GDBN} how to find the return value of
12546functions which return floating point values. It also allows
12547@value{GDBN} to avoid saving the floating point registers when calling
12548functions on the board. If you are using a floating point coprocessor
12549with only single precision floating point support, as on the @sc{r4650}
12550processor, use the command @samp{set mipsfpu single}. The default
12551double precision floating point coprocessor may be selected using
12552@samp{set mipsfpu double}.
12553
12554In previous versions the only choices were double precision or no
12555floating point, so @samp{set mipsfpu on} will select double precision
12556and @samp{set mipsfpu off} will select no floating point.
12557
12558As usual, you can inquire about the @code{mipsfpu} variable with
12559@samp{show mipsfpu}.
12560
12561@item set remotedebug @var{n}
12562@itemx show remotedebug
d4f3574e
SS
12563@kindex set remotedebug@r{, MIPS protocol}
12564@kindex show remotedebug@r{, MIPS protocol}
104c1213
JM
12565@cindex @code{remotedebug}, MIPS protocol
12566@cindex MIPS @code{remotedebug} protocol
12567@c FIXME! For this to be useful, you must know something about the MIPS
12568@c FIXME...protocol. Where is it described?
12569You can see some debugging information about communications with the board
12570by setting the @code{remotedebug} variable. If you set it to @code{1} using
12571@samp{set remotedebug 1}, every packet is displayed. If you set it
12572to @code{2}, every character is displayed. You can check the current value
12573at any time with the command @samp{show remotedebug}.
12574
12575@item set timeout @var{seconds}
12576@itemx set retransmit-timeout @var{seconds}
12577@itemx show timeout
12578@itemx show retransmit-timeout
12579@cindex @code{timeout}, MIPS protocol
12580@cindex @code{retransmit-timeout}, MIPS protocol
12581@kindex set timeout
12582@kindex show timeout
12583@kindex set retransmit-timeout
12584@kindex show retransmit-timeout
12585You can control the timeout used while waiting for a packet, in the MIPS
12586remote protocol, with the @code{set timeout @var{seconds}} command. The
12587default is 5 seconds. Similarly, you can control the timeout used while
12588waiting for an acknowledgement of a packet with the @code{set
12589retransmit-timeout @var{seconds}} command. The default is 3 seconds.
12590You can inspect both values with @code{show timeout} and @code{show
12591retransmit-timeout}. (These commands are @emph{only} available when
12592@value{GDBN} is configured for @samp{--target=mips-idt-ecoff}.)
12593
12594The timeout set by @code{set timeout} does not apply when @value{GDBN}
12595is waiting for your program to stop. In that case, @value{GDBN} waits
12596forever because it has no way of knowing how long the program is going
12597to run before stopping.
12598@end table
12599
6d2ebf8b 12600@node PowerPC
104c1213
JM
12601@subsection PowerPC
12602
12603@table @code
12604
12605@kindex target dink32
12606@item target dink32 @var{dev}
12607DINK32 ROM monitor.
12608
12609@kindex target ppcbug
12610@item target ppcbug @var{dev}
12611@kindex target ppcbug1
12612@item target ppcbug1 @var{dev}
12613PPCBUG ROM monitor for PowerPC.
12614
12615@kindex target sds
12616@item target sds @var{dev}
12617SDS monitor, running on a PowerPC board (such as Motorola's ADS).
12618
12619@end table
12620
6d2ebf8b 12621@node PA
104c1213
JM
12622@subsection HP PA Embedded
12623
12624@table @code
12625
12626@kindex target op50n
12627@item target op50n @var{dev}
12628OP50N monitor, running on an OKI HPPA board.
12629
12630@kindex target w89k
12631@item target w89k @var{dev}
12632W89K monitor, running on a Winbond HPPA board.
12633
12634@end table
12635
6d2ebf8b 12636@node SH
104c1213
JM
12637@subsection Hitachi SH
12638
12639@table @code
12640
d4f3574e 12641@kindex target hms@r{, with Hitachi SH}
104c1213
JM
12642@item target hms @var{dev}
12643A Hitachi SH board attached via serial line to your host. Use special
12644commands @code{device} and @code{speed} to control the serial line and
12645the communications speed used.
12646
d4f3574e 12647@kindex target e7000@r{, with Hitachi SH}
104c1213
JM
12648@item target e7000 @var{dev}
12649E7000 emulator for Hitachi SH.
12650
d4f3574e
SS
12651@kindex target sh3@r{, with SH}
12652@kindex target sh3e@r{, with SH}
104c1213
JM
12653@item target sh3 @var{dev}
12654@item target sh3e @var{dev}
12655Hitachi SH-3 and SH-3E target systems.
12656
12657@end table
12658
6d2ebf8b 12659@node Sparclet
104c1213
JM
12660@subsection Tsqware Sparclet
12661
12662@cindex Sparclet
12663
5d161b24
DB
12664@value{GDBN} enables developers to debug tasks running on
12665Sparclet targets from a Unix host.
104c1213
JM
12666@value{GDBN} uses code that runs on
12667both the Unix host and on the Sparclet target. The program
5d161b24 12668@code{@value{GDBP}} is installed and executed on the Unix host.
104c1213
JM
12669
12670@table @code
f0ca3dce 12671@item remotetimeout @var{args}
104c1213 12672@kindex remotetimeout
5d161b24
DB
12673@value{GDBN} supports the option @code{remotetimeout}.
12674This option is set by the user, and @var{args} represents the number of
12675seconds @value{GDBN} waits for responses.
104c1213
JM
12676@end table
12677
41afff9a 12678@cindex compiling, on Sparclet
5d161b24 12679When compiling for debugging, include the options @samp{-g} to get debug
d4f3574e 12680information and @samp{-Ttext} to relocate the program to where you wish to
5d161b24 12681load it on the target. You may also want to add the options @samp{-n} or
d4f3574e 12682@samp{-N} in order to reduce the size of the sections. Example:
104c1213
JM
12683
12684@example
12685sparclet-aout-gcc prog.c -Ttext 0x12010000 -g -o prog -N
12686@end example
12687
d4f3574e 12688You can use @code{objdump} to verify that the addresses are what you intended:
104c1213
JM
12689
12690@example
12691sparclet-aout-objdump --headers --syms prog
12692@end example
12693
41afff9a 12694@cindex running, on Sparclet
104c1213
JM
12695Once you have set
12696your Unix execution search path to find @value{GDBN}, you are ready to
5d161b24 12697run @value{GDBN}. From your Unix host, run @code{@value{GDBP}}
104c1213
JM
12698(or @code{sparclet-aout-gdb}, depending on your installation).
12699
12700@value{GDBN} comes up showing the prompt:
12701
12702@example
12703(gdbslet)
12704@end example
12705
12706@menu
12707* Sparclet File:: Setting the file to debug
12708* Sparclet Connection:: Connecting to Sparclet
12709* Sparclet Download:: Sparclet download
5d161b24 12710* Sparclet Execution:: Running and debugging
104c1213
JM
12711@end menu
12712
6d2ebf8b 12713@node Sparclet File
104c1213
JM
12714@subsubsection Setting file to debug
12715
12716The @value{GDBN} command @code{file} lets you choose with program to debug.
12717
12718@example
12719(gdbslet) file prog
12720@end example
12721
12722@need 1000
12723@value{GDBN} then attempts to read the symbol table of @file{prog}.
12724@value{GDBN} locates
12725the file by searching the directories listed in the command search
12726path.
12727If the file was compiled with debug information (option "-g"), source
12728files will be searched as well.
12729@value{GDBN} locates
12730the source files by searching the directories listed in the directory search
12731path (@pxref{Environment, ,Your program's environment}).
12732If it fails
12733to find a file, it displays a message such as:
12734
12735@example
12736prog: No such file or directory.
12737@end example
12738
12739When this happens, add the appropriate directories to the search paths with
5d161b24 12740the @value{GDBN} commands @code{path} and @code{dir}, and execute the
104c1213
JM
12741@code{target} command again.
12742
6d2ebf8b 12743@node Sparclet Connection
104c1213
JM
12744@subsubsection Connecting to Sparclet
12745
12746The @value{GDBN} command @code{target} lets you connect to a Sparclet target.
12747To connect to a target on serial port ``@code{ttya}'', type:
12748
12749@example
12750(gdbslet) target sparclet /dev/ttya
12751Remote target sparclet connected to /dev/ttya
5d161b24 12752main () at ../prog.c:3
104c1213
JM
12753@end example
12754
12755@need 750
12756@value{GDBN} displays messages like these:
12757
d4f3574e 12758@example
104c1213 12759Connected to ttya.
d4f3574e 12760@end example
104c1213 12761
6d2ebf8b 12762@node Sparclet Download
104c1213
JM
12763@subsubsection Sparclet download
12764
12765@cindex download to Sparclet
5d161b24 12766Once connected to the Sparclet target,
104c1213
JM
12767you can use the @value{GDBN}
12768@code{load} command to download the file from the host to the target.
12769The file name and load offset should be given as arguments to the @code{load}
12770command.
5d161b24 12771Since the file format is aout, the program must be loaded to the starting
d4f3574e 12772address. You can use @code{objdump} to find out what this value is. The load
104c1213
JM
12773offset is an offset which is added to the VMA (virtual memory address)
12774of each of the file's sections.
12775For instance, if the program
12776@file{prog} was linked to text address 0x1201000, with data at 0x12010160
12777and bss at 0x12010170, in @value{GDBN}, type:
12778
12779@example
12780(gdbslet) load prog 0x12010000
12781Loading section .text, size 0xdb0 vma 0x12010000
12782@end example
12783
5d161b24
DB
12784If the code is loaded at a different address then what the program was linked
12785to, you may need to use the @code{section} and @code{add-symbol-file} commands
104c1213
JM
12786to tell @value{GDBN} where to map the symbol table.
12787
6d2ebf8b 12788@node Sparclet Execution
104c1213
JM
12789@subsubsection Running and debugging
12790
12791@cindex running and debugging Sparclet programs
12792You can now begin debugging the task using @value{GDBN}'s execution control
5d161b24 12793commands, @code{b}, @code{step}, @code{run}, etc. See the @value{GDBN}
104c1213
JM
12794manual for the list of commands.
12795
12796@example
12797(gdbslet) b main
12798Breakpoint 1 at 0x12010000: file prog.c, line 3.
5d161b24 12799(gdbslet) run
104c1213
JM
12800Starting program: prog
12801Breakpoint 1, main (argc=1, argv=0xeffff21c) at prog.c:3
128023 char *symarg = 0;
12803(gdbslet) step
128044 char *execarg = "hello!";
5d161b24 12805(gdbslet)
104c1213
JM
12806@end example
12807
6d2ebf8b 12808@node Sparclite
104c1213
JM
12809@subsection Fujitsu Sparclite
12810
12811@table @code
12812
12813@kindex target sparclite
12814@item target sparclite @var{dev}
5d161b24
DB
12815Fujitsu sparclite boards, used only for the purpose of loading.
12816You must use an additional command to debug the program.
12817For example: target remote @var{dev} using @value{GDBN} standard
104c1213
JM
12818remote protocol.
12819
12820@end table
12821
6d2ebf8b 12822@node ST2000
104c1213
JM
12823@subsection Tandem ST2000
12824
2df3850c 12825@value{GDBN} may be used with a Tandem ST2000 phone switch, running Tandem's
104c1213
JM
12826STDBUG protocol.
12827
12828To connect your ST2000 to the host system, see the manufacturer's
12829manual. Once the ST2000 is physically attached, you can run:
12830
12831@example
12832target st2000 @var{dev} @var{speed}
12833@end example
12834
12835@noindent
12836to establish it as your debugging environment. @var{dev} is normally
12837the name of a serial device, such as @file{/dev/ttya}, connected to the
12838ST2000 via a serial line. You can instead specify @var{dev} as a TCP
12839connection (for example, to a serial line attached via a terminal
12840concentrator) using the syntax @code{@var{hostname}:@var{portnumber}}.
12841
12842The @code{load} and @code{attach} commands are @emph{not} defined for
12843this target; you must load your program into the ST2000 as you normally
12844would for standalone operation. @value{GDBN} reads debugging information
12845(such as symbols) from a separate, debugging version of the program
12846available on your host computer.
12847@c FIXME!! This is terribly vague; what little content is here is
12848@c basically hearsay.
12849
12850@cindex ST2000 auxiliary commands
12851These auxiliary @value{GDBN} commands are available to help you with the ST2000
12852environment:
12853
12854@table @code
12855@item st2000 @var{command}
12856@kindex st2000 @var{cmd}
12857@cindex STDBUG commands (ST2000)
12858@cindex commands to STDBUG (ST2000)
12859Send a @var{command} to the STDBUG monitor. See the manufacturer's
12860manual for available commands.
12861
12862@item connect
12863@cindex connect (to STDBUG)
12864Connect the controlling terminal to the STDBUG command monitor. When
12865you are done interacting with STDBUG, typing either of two character
12866sequences gets you back to the @value{GDBN} command prompt:
12867@kbd{@key{RET}~.} (Return, followed by tilde and period) or
12868@kbd{@key{RET}~@key{C-d}} (Return, followed by tilde and control-D).
12869@end table
12870
6d2ebf8b 12871@node Z8000
104c1213
JM
12872@subsection Zilog Z8000
12873
12874@cindex Z8000
12875@cindex simulator, Z8000
12876@cindex Zilog Z8000 simulator
12877
12878When configured for debugging Zilog Z8000 targets, @value{GDBN} includes
12879a Z8000 simulator.
12880
12881For the Z8000 family, @samp{target sim} simulates either the Z8002 (the
12882unsegmented variant of the Z8000 architecture) or the Z8001 (the
12883segmented variant). The simulator recognizes which architecture is
12884appropriate by inspecting the object code.
12885
12886@table @code
12887@item target sim @var{args}
12888@kindex sim
d4f3574e 12889@kindex target sim@r{, with Z8000}
104c1213
JM
12890Debug programs on a simulated CPU. If the simulator supports setup
12891options, specify them via @var{args}.
12892@end table
12893
12894@noindent
12895After specifying this target, you can debug programs for the simulated
12896CPU in the same style as programs for your host computer; use the
12897@code{file} command to load a new program image, the @code{run} command
12898to run your program, and so on.
12899
d4f3574e
SS
12900As well as making available all the usual machine registers
12901(@pxref{Registers, ,Registers}), the Z8000 simulator provides three
12902additional items of information as specially named registers:
104c1213
JM
12903
12904@table @code
12905
12906@item cycles
12907Counts clock-ticks in the simulator.
12908
12909@item insts
12910Counts instructions run in the simulator.
12911
12912@item time
12913Execution time in 60ths of a second.
12914
12915@end table
12916
12917You can refer to these values in @value{GDBN} expressions with the usual
12918conventions; for example, @w{@samp{b fputc if $cycles>5000}} sets a
12919conditional breakpoint that suspends only after at least 5000
12920simulated clock ticks.
12921
6d2ebf8b 12922@node Architectures
104c1213
JM
12923@section Architectures
12924
12925This section describes characteristics of architectures that affect
2df3850c 12926all uses of @value{GDBN} with the architecture, both native and cross.
104c1213
JM
12927
12928@menu
12929* A29K::
12930* Alpha::
12931* MIPS::
12932@end menu
12933
6d2ebf8b 12934@node A29K
104c1213
JM
12935@subsection A29K
12936
12937@table @code
12938
12939@kindex set rstack_high_address
12940@cindex AMD 29K register stack
12941@cindex register stack, AMD29K
12942@item set rstack_high_address @var{address}
12943On AMD 29000 family processors, registers are saved in a separate
d4f3574e 12944@dfn{register stack}. There is no way for @value{GDBN} to determine the
104c1213
JM
12945extent of this stack. Normally, @value{GDBN} just assumes that the
12946stack is ``large enough''. This may result in @value{GDBN} referencing
12947memory locations that do not exist. If necessary, you can get around
12948this problem by specifying the ending address of the register stack with
12949the @code{set rstack_high_address} command. The argument should be an
12950address, which you probably want to precede with @samp{0x} to specify in
12951hexadecimal.
12952
12953@kindex show rstack_high_address
12954@item show rstack_high_address
12955Display the current limit of the register stack, on AMD 29000 family
12956processors.
12957
12958@end table
12959
6d2ebf8b 12960@node Alpha
104c1213
JM
12961@subsection Alpha
12962
12963See the following section.
12964
6d2ebf8b 12965@node MIPS
104c1213
JM
12966@subsection MIPS
12967
12968@cindex stack on Alpha
12969@cindex stack on MIPS
12970@cindex Alpha stack
12971@cindex MIPS stack
12972Alpha- and MIPS-based computers use an unusual stack frame, which
12973sometimes requires @value{GDBN} to search backward in the object code to
12974find the beginning of a function.
12975
12976@cindex response time, MIPS debugging
12977To improve response time (especially for embedded applications, where
12978@value{GDBN} may be restricted to a slow serial line for this search)
12979you may want to limit the size of this search, using one of these
12980commands:
12981
12982@table @code
00e4a2e4 12983@cindex @code{heuristic-fence-post} (Alpha, MIPS)
104c1213
JM
12984@item set heuristic-fence-post @var{limit}
12985Restrict @value{GDBN} to examining at most @var{limit} bytes in its
12986search for the beginning of a function. A value of @var{0} (the
12987default) means there is no limit. However, except for @var{0}, the
12988larger the limit the more bytes @code{heuristic-fence-post} must search
12989and therefore the longer it takes to run.
12990
12991@item show heuristic-fence-post
12992Display the current limit.
12993@end table
12994
12995@noindent
12996These commands are available @emph{only} when @value{GDBN} is configured
12997for debugging programs on Alpha or MIPS processors.
12998
12999
6d2ebf8b 13000@node Controlling GDB
c906108c
SS
13001@chapter Controlling @value{GDBN}
13002
53a5351d
JM
13003You can alter the way @value{GDBN} interacts with you by using the
13004@code{set} command. For commands controlling how @value{GDBN} displays
d4f3574e 13005data, see @ref{Print Settings, ,Print settings}. Other settings are
53a5351d 13006described here.
c906108c
SS
13007
13008@menu
13009* Prompt:: Prompt
13010* Editing:: Command editing
13011* History:: Command history
13012* Screen Size:: Screen size
13013* Numbers:: Numbers
13014* Messages/Warnings:: Optional warnings and messages
5d161b24 13015* Debugging Output:: Optional messages about internal happenings
c906108c
SS
13016@end menu
13017
6d2ebf8b 13018@node Prompt
c906108c
SS
13019@section Prompt
13020
13021@cindex prompt
13022
13023@value{GDBN} indicates its readiness to read a command by printing a string
13024called the @dfn{prompt}. This string is normally @samp{(@value{GDBP})}. You
13025can change the prompt string with the @code{set prompt} command. For
13026instance, when debugging @value{GDBN} with @value{GDBN}, it is useful to change
5d161b24 13027the prompt in one of the @value{GDBN} sessions so that you can always tell
c906108c
SS
13028which one you are talking to.
13029
d4f3574e 13030@emph{Note:} @code{set prompt} does not add a space for you after the
c906108c
SS
13031prompt you set. This allows you to set a prompt which ends in a space
13032or a prompt that does not.
13033
13034@table @code
13035@kindex set prompt
13036@item set prompt @var{newprompt}
13037Directs @value{GDBN} to use @var{newprompt} as its prompt string henceforth.
13038
13039@kindex show prompt
13040@item show prompt
13041Prints a line of the form: @samp{Gdb's prompt is: @var{your-prompt}}
13042@end table
13043
6d2ebf8b 13044@node Editing
c906108c
SS
13045@section Command editing
13046@cindex readline
13047@cindex command line editing
13048
13049@value{GDBN} reads its input commands via the @dfn{readline} interface. This
13050@sc{gnu} library provides consistent behavior for programs which provide a
13051command line interface to the user. Advantages are @sc{gnu} Emacs-style
13052or @dfn{vi}-style inline editing of commands, @code{csh}-like history
13053substitution, and a storage and recall of command history across
13054debugging sessions.
13055
13056You may control the behavior of command line editing in @value{GDBN} with the
13057command @code{set}.
13058
13059@table @code
13060@kindex set editing
13061@cindex editing
13062@item set editing
13063@itemx set editing on
13064Enable command line editing (enabled by default).
13065
13066@item set editing off
13067Disable command line editing.
13068
13069@kindex show editing
13070@item show editing
13071Show whether command line editing is enabled.
13072@end table
13073
6d2ebf8b 13074@node History
c906108c
SS
13075@section Command history
13076
13077@value{GDBN} can keep track of the commands you type during your
13078debugging sessions, so that you can be certain of precisely what
13079happened. Use these commands to manage the @value{GDBN} command
13080history facility.
13081
13082@table @code
13083@cindex history substitution
13084@cindex history file
13085@kindex set history filename
13086@kindex GDBHISTFILE
13087@item set history filename @var{fname}
13088Set the name of the @value{GDBN} command history file to @var{fname}.
13089This is the file where @value{GDBN} reads an initial command history
13090list, and where it writes the command history from this session when it
13091exits. You can access this list through history expansion or through
13092the history command editing characters listed below. This file defaults
13093to the value of the environment variable @code{GDBHISTFILE}, or to
d4f3574e
SS
13094@file{./.gdb_history} (@file{./_gdb_history} on MS-DOS) if this variable
13095is not set.
c906108c
SS
13096
13097@cindex history save
13098@kindex set history save
13099@item set history save
13100@itemx set history save on
13101Record command history in a file, whose name may be specified with the
13102@code{set history filename} command. By default, this option is disabled.
13103
13104@item set history save off
13105Stop recording command history in a file.
13106
13107@cindex history size
13108@kindex set history size
13109@item set history size @var{size}
13110Set the number of commands which @value{GDBN} keeps in its history list.
13111This defaults to the value of the environment variable
13112@code{HISTSIZE}, or to 256 if this variable is not set.
13113@end table
13114
13115@cindex history expansion
13116History expansion assigns special meaning to the character @kbd{!}.
13117@ifset have-readline-appendices
13118@xref{Event Designators}.
13119@end ifset
13120
13121Since @kbd{!} is also the logical not operator in C, history expansion
13122is off by default. If you decide to enable history expansion with the
13123@code{set history expansion on} command, you may sometimes need to
13124follow @kbd{!} (when it is used as logical not, in an expression) with
13125a space or a tab to prevent it from being expanded. The readline
13126history facilities do not attempt substitution on the strings
13127@kbd{!=} and @kbd{!(}, even when history expansion is enabled.
13128
13129The commands to control history expansion are:
13130
13131@table @code
13132@kindex set history expansion
13133@item set history expansion on
13134@itemx set history expansion
13135Enable history expansion. History expansion is off by default.
13136
13137@item set history expansion off
13138Disable history expansion.
13139
13140The readline code comes with more complete documentation of
13141editing and history expansion features. Users unfamiliar with @sc{gnu} Emacs
13142or @code{vi} may wish to read it.
13143@ifset have-readline-appendices
13144@xref{Command Line Editing}.
13145@end ifset
13146
13147@c @group
13148@kindex show history
13149@item show history
13150@itemx show history filename
13151@itemx show history save
13152@itemx show history size
13153@itemx show history expansion
13154These commands display the state of the @value{GDBN} history parameters.
13155@code{show history} by itself displays all four states.
13156@c @end group
13157@end table
13158
13159@table @code
41afff9a 13160@kindex shows
c906108c
SS
13161@item show commands
13162Display the last ten commands in the command history.
13163
13164@item show commands @var{n}
13165Print ten commands centered on command number @var{n}.
13166
13167@item show commands +
13168Print ten commands just after the commands last printed.
13169@end table
13170
6d2ebf8b 13171@node Screen Size
c906108c
SS
13172@section Screen size
13173@cindex size of screen
13174@cindex pauses in output
13175
13176Certain commands to @value{GDBN} may produce large amounts of
13177information output to the screen. To help you read all of it,
13178@value{GDBN} pauses and asks you for input at the end of each page of
13179output. Type @key{RET} when you want to continue the output, or @kbd{q}
13180to discard the remaining output. Also, the screen width setting
13181determines when to wrap lines of output. Depending on what is being
13182printed, @value{GDBN} tries to break the line at a readable place,
13183rather than simply letting it overflow onto the following line.
13184
d4f3574e
SS
13185Normally @value{GDBN} knows the size of the screen from the terminal
13186driver software. For example, on Unix @value{GDBN} uses the termcap data base
c906108c 13187together with the value of the @code{TERM} environment variable and the
d4f3574e 13188@code{stty rows} and @code{stty cols} settings. If this is not correct,
c906108c
SS
13189you can override it with the @code{set height} and @code{set
13190width} commands:
13191
13192@table @code
13193@kindex set height
13194@kindex set width
13195@kindex show width
13196@kindex show height
13197@item set height @var{lpp}
13198@itemx show height
13199@itemx set width @var{cpl}
13200@itemx show width
13201These @code{set} commands specify a screen height of @var{lpp} lines and
13202a screen width of @var{cpl} characters. The associated @code{show}
13203commands display the current settings.
13204
5d161b24
DB
13205If you specify a height of zero lines, @value{GDBN} does not pause during
13206output no matter how long the output is. This is useful if output is to a
c906108c
SS
13207file or to an editor buffer.
13208
13209Likewise, you can specify @samp{set width 0} to prevent @value{GDBN}
13210from wrapping its output.
13211@end table
13212
6d2ebf8b 13213@node Numbers
c906108c
SS
13214@section Numbers
13215@cindex number representation
13216@cindex entering numbers
13217
2df3850c
JM
13218You can always enter numbers in octal, decimal, or hexadecimal in
13219@value{GDBN} by the usual conventions: octal numbers begin with
13220@samp{0}, decimal numbers end with @samp{.}, and hexadecimal numbers
13221begin with @samp{0x}. Numbers that begin with none of these are, by
13222default, entered in base 10; likewise, the default display for
13223numbers---when no particular format is specified---is base 10. You can
13224change the default base for both input and output with the @code{set
13225radix} command.
c906108c
SS
13226
13227@table @code
13228@kindex set input-radix
13229@item set input-radix @var{base}
13230Set the default base for numeric input. Supported choices
13231for @var{base} are decimal 8, 10, or 16. @var{base} must itself be
13232specified either unambiguously or using the current default radix; for
13233example, any of
13234
13235@smallexample
13236set radix 012
13237set radix 10.
13238set radix 0xa
13239@end smallexample
13240
13241@noindent
13242sets the base to decimal. On the other hand, @samp{set radix 10}
13243leaves the radix unchanged no matter what it was.
13244
13245@kindex set output-radix
13246@item set output-radix @var{base}
13247Set the default base for numeric display. Supported choices
13248for @var{base} are decimal 8, 10, or 16. @var{base} must itself be
13249specified either unambiguously or using the current default radix.
13250
13251@kindex show input-radix
13252@item show input-radix
13253Display the current default base for numeric input.
13254
13255@kindex show output-radix
13256@item show output-radix
13257Display the current default base for numeric display.
13258@end table
13259
6d2ebf8b 13260@node Messages/Warnings
c906108c
SS
13261@section Optional warnings and messages
13262
2df3850c
JM
13263By default, @value{GDBN} is silent about its inner workings. If you are
13264running on a slow machine, you may want to use the @code{set verbose}
13265command. This makes @value{GDBN} tell you when it does a lengthy
13266internal operation, so you will not think it has crashed.
c906108c
SS
13267
13268Currently, the messages controlled by @code{set verbose} are those
13269which announce that the symbol table for a source file is being read;
13270see @code{symbol-file} in @ref{Files, ,Commands to specify files}.
13271
13272@table @code
13273@kindex set verbose
13274@item set verbose on
13275Enables @value{GDBN} output of certain informational messages.
13276
13277@item set verbose off
13278Disables @value{GDBN} output of certain informational messages.
13279
13280@kindex show verbose
13281@item show verbose
13282Displays whether @code{set verbose} is on or off.
13283@end table
13284
2df3850c
JM
13285By default, if @value{GDBN} encounters bugs in the symbol table of an
13286object file, it is silent; but if you are debugging a compiler, you may
13287find this information useful (@pxref{Symbol Errors, ,Errors reading
13288symbol files}).
c906108c
SS
13289
13290@table @code
2df3850c 13291
c906108c
SS
13292@kindex set complaints
13293@item set complaints @var{limit}
2df3850c
JM
13294Permits @value{GDBN} to output @var{limit} complaints about each type of
13295unusual symbols before becoming silent about the problem. Set
13296@var{limit} to zero to suppress all complaints; set it to a large number
13297to prevent complaints from being suppressed.
c906108c
SS
13298
13299@kindex show complaints
13300@item show complaints
13301Displays how many symbol complaints @value{GDBN} is permitted to produce.
2df3850c 13302
c906108c
SS
13303@end table
13304
13305By default, @value{GDBN} is cautious, and asks what sometimes seems to be a
13306lot of stupid questions to confirm certain commands. For example, if
13307you try to run a program which is already running:
13308
13309@example
13310(@value{GDBP}) run
13311The program being debugged has been started already.
13312Start it from the beginning? (y or n)
13313@end example
13314
13315If you are willing to unflinchingly face the consequences of your own
13316commands, you can disable this ``feature'':
13317
13318@table @code
2df3850c 13319
c906108c
SS
13320@kindex set confirm
13321@cindex flinching
13322@cindex confirmation
13323@cindex stupid questions
13324@item set confirm off
13325Disables confirmation requests.
13326
13327@item set confirm on
13328Enables confirmation requests (the default).
13329
13330@kindex show confirm
13331@item show confirm
13332Displays state of confirmation requests.
2df3850c 13333
c906108c
SS
13334@end table
13335
6d2ebf8b 13336@node Debugging Output
5d161b24
DB
13337@section Optional messages about internal happenings
13338@table @code
13339@kindex set debug arch
13340@item set debug arch
13341Turns on or off display of gdbarch debugging info. The default is off
13342@kindex show debug arch
13343@item show debug arch
13344Displays the current state of displaying gdbarch debugging info.
13345@kindex set debug event
13346@item set debug event
13347Turns on or off display of @value{GDBN} event debugging info. The
13348default is off.
13349@kindex show debug event
13350@item show debug event
13351Displays the current state of displaying @value{GDBN} event debugging
13352info.
13353@kindex set debug expression
13354@item set debug expression
13355Turns on or off display of @value{GDBN} expression debugging info. The
13356default is off.
13357@kindex show debug expression
13358@item show debug expression
13359Displays the current state of displaying @value{GDBN} expression
13360debugging info.
13361@kindex set debug overload
13362@item set debug overload
b37052ae 13363Turns on or off display of @value{GDBN} C@t{++} overload debugging
5d161b24
DB
13364info. This includes info such as ranking of functions, etc. The default
13365is off.
13366@kindex show debug overload
13367@item show debug overload
b37052ae 13368Displays the current state of displaying @value{GDBN} C@t{++} overload
5d161b24
DB
13369debugging info.
13370@kindex set debug remote
13371@cindex packets, reporting on stdout
13372@cindex serial connections, debugging
13373@item set debug remote
13374Turns on or off display of reports on all packets sent back and forth across
13375the serial line to the remote machine. The info is printed on the
13376@value{GDBN} standard output stream. The default is off.
13377@kindex show debug remote
13378@item show debug remote
13379Displays the state of display of remote packets.
13380@kindex set debug serial
13381@item set debug serial
13382Turns on or off display of @value{GDBN} serial debugging info. The
13383default is off.
13384@kindex show debug serial
13385@item show debug serial
13386Displays the current state of displaying @value{GDBN} serial debugging
13387info.
13388@kindex set debug target
13389@item set debug target
13390Turns on or off display of @value{GDBN} target debugging info. This info
13391includes what is going on at the target level of GDB, as it happens. The
13392default is off.
13393@kindex show debug target
13394@item show debug target
13395Displays the current state of displaying @value{GDBN} target debugging
13396info.
13397@kindex set debug varobj
13398@item set debug varobj
13399Turns on or off display of @value{GDBN} variable object debugging
13400info. The default is off.
13401@kindex show debug varobj
13402@item show debug varobj
13403Displays the current state of displaying @value{GDBN} variable object
13404debugging info.
13405@end table
13406
6d2ebf8b 13407@node Sequences
c906108c
SS
13408@chapter Canned Sequences of Commands
13409
13410Aside from breakpoint commands (@pxref{Break Commands, ,Breakpoint
2df3850c
JM
13411command lists}), @value{GDBN} provides two ways to store sequences of
13412commands for execution as a unit: user-defined commands and command
13413files.
c906108c
SS
13414
13415@menu
13416* Define:: User-defined commands
13417* Hooks:: User-defined command hooks
13418* Command Files:: Command files
13419* Output:: Commands for controlled output
13420@end menu
13421
6d2ebf8b 13422@node Define
c906108c
SS
13423@section User-defined commands
13424
13425@cindex user-defined command
2df3850c
JM
13426A @dfn{user-defined command} is a sequence of @value{GDBN} commands to
13427which you assign a new name as a command. This is done with the
13428@code{define} command. User commands may accept up to 10 arguments
13429separated by whitespace. Arguments are accessed within the user command
13430via @var{$arg0@dots{}$arg9}. A trivial example:
c906108c
SS
13431
13432@smallexample
13433define adder
13434 print $arg0 + $arg1 + $arg2
13435@end smallexample
13436
d4f3574e
SS
13437@noindent
13438To execute the command use:
c906108c
SS
13439
13440@smallexample
13441adder 1 2 3
13442@end smallexample
13443
d4f3574e
SS
13444@noindent
13445This defines the command @code{adder}, which prints the sum of
5d161b24 13446its three arguments. Note the arguments are text substitutions, so they may
c906108c
SS
13447reference variables, use complex expressions, or even perform inferior
13448functions calls.
13449
13450@table @code
2df3850c 13451
c906108c
SS
13452@kindex define
13453@item define @var{commandname}
13454Define a command named @var{commandname}. If there is already a command
13455by that name, you are asked to confirm that you want to redefine it.
13456
13457The definition of the command is made up of other @value{GDBN} command lines,
13458which are given following the @code{define} command. The end of these
13459commands is marked by a line containing @code{end}.
13460
13461@kindex if
13462@kindex else
13463@item if
13464Takes a single argument, which is an expression to evaluate.
13465It is followed by a series of commands that are executed
13466only if the expression is true (nonzero).
13467There can then optionally be a line @code{else}, followed
13468by a series of commands that are only executed if the expression
13469was false. The end of the list is marked by a line containing @code{end}.
13470
13471@kindex while
13472@item while
13473The syntax is similar to @code{if}: the command takes a single argument,
13474which is an expression to evaluate, and must be followed by the commands to
13475execute, one per line, terminated by an @code{end}.
13476The commands are executed repeatedly as long as the expression
13477evaluates to true.
13478
13479@kindex document
13480@item document @var{commandname}
13481Document the user-defined command @var{commandname}, so that it can be
5d161b24
DB
13482accessed by @code{help}. The command @var{commandname} must already be
13483defined. This command reads lines of documentation just as @code{define}
13484reads the lines of the command definition, ending with @code{end}.
13485After the @code{document} command is finished, @code{help} on command
c906108c
SS
13486@var{commandname} displays the documentation you have written.
13487
13488You may use the @code{document} command again to change the
13489documentation of a command. Redefining the command with @code{define}
13490does not change the documentation.
13491
13492@kindex help user-defined
13493@item help user-defined
13494List all user-defined commands, with the first line of the documentation
13495(if any) for each.
13496
13497@kindex show user
13498@item show user
13499@itemx show user @var{commandname}
2df3850c
JM
13500Display the @value{GDBN} commands used to define @var{commandname} (but
13501not its documentation). If no @var{commandname} is given, display the
c906108c 13502definitions for all user-defined commands.
2df3850c 13503
c906108c
SS
13504@end table
13505
13506When user-defined commands are executed, the
13507commands of the definition are not printed. An error in any command
13508stops execution of the user-defined command.
13509
13510If used interactively, commands that would ask for confirmation proceed
5d161b24
DB
13511without asking when used inside a user-defined command. Many @value{GDBN}
13512commands that normally print messages to say what they are doing omit the
c906108c
SS
13513messages when used in a user-defined command.
13514
6d2ebf8b 13515@node Hooks
c906108c 13516@section User-defined command hooks
d4f3574e
SS
13517@cindex command hooks
13518@cindex hooks, for commands
c78b4128 13519@cindex hooks, pre-command
c906108c 13520
c78b4128
EZ
13521@kindex hook
13522@kindex hook-
13523You may define @dfn{hooks}, which are a special kind of user-defined
c906108c
SS
13524command. Whenever you run the command @samp{foo}, if the user-defined
13525command @samp{hook-foo} exists, it is executed (with no arguments)
13526before that command.
13527
c78b4128
EZ
13528@cindex hooks, post-command
13529@kindex hookpost
13530@kindex hookpost-
13531A hook may also be defined which is run after the command you executed.
13532Whenever you run the command @samp{foo}, if the user-defined command
13533@samp{hookpost-foo} exists, it is executed (with no arguments) after
13534that command. Post-execution hooks may exist simultaneously with
13535pre-execution hooks, for the same command.
13536
13537It is valid for a hook to call the command which it hooks. If this
13538occurs, the hook is not re-executed, thereby avoiding infinte recursion.
13539
13540@c It would be nice if hookpost could be passed a parameter indicating
13541@c if the command it hooks executed properly or not. FIXME!
13542
d4f3574e 13543@kindex stop@r{, a pseudo-command}
c906108c
SS
13544In addition, a pseudo-command, @samp{stop} exists. Defining
13545(@samp{hook-stop}) makes the associated commands execute every time
13546execution stops in your program: before breakpoint commands are run,
13547displays are printed, or the stack frame is printed.
13548
c906108c
SS
13549For example, to ignore @code{SIGALRM} signals while
13550single-stepping, but treat them normally during normal execution,
13551you could define:
13552
13553@example
13554define hook-stop
13555handle SIGALRM nopass
13556end
13557
13558define hook-run
13559handle SIGALRM pass
13560end
13561
13562define hook-continue
13563handle SIGLARM pass
13564end
13565@end example
c906108c 13566
c78b4128
EZ
13567As a further example, to hook at the begining and end of the @code{echo}
13568command, and to add extra text to the beginning and end of the message,
13569you could define:
13570
13571@example
13572define hook-echo
13573echo <<<---
13574end
13575
13576define hookpost-echo
13577echo --->>>\n
13578end
13579
13580(@value{GDBP}) echo Hello World
13581<<<---Hello World--->>>
13582(@value{GDBP})
13583
13584@end example
13585
c906108c
SS
13586You can define a hook for any single-word command in @value{GDBN}, but
13587not for command aliases; you should define a hook for the basic command
13588name, e.g. @code{backtrace} rather than @code{bt}.
13589@c FIXME! So how does Joe User discover whether a command is an alias
13590@c or not?
13591If an error occurs during the execution of your hook, execution of
13592@value{GDBN} commands stops and @value{GDBN} issues a prompt
13593(before the command that you actually typed had a chance to run).
13594
13595If you try to define a hook which does not match any known command, you
13596get a warning from the @code{define} command.
13597
6d2ebf8b 13598@node Command Files
c906108c
SS
13599@section Command files
13600
13601@cindex command files
5d161b24
DB
13602A command file for @value{GDBN} is a file of lines that are @value{GDBN}
13603commands. Comments (lines starting with @kbd{#}) may also be included.
13604An empty line in a command file does nothing; it does not mean to repeat
c906108c
SS
13605the last command, as it would from the terminal.
13606
13607@cindex init file
13608@cindex @file{.gdbinit}
d4f3574e 13609@cindex @file{gdb.ini}
c906108c 13610When you start @value{GDBN}, it automatically executes commands from its
96565e91
CF
13611@dfn{init files}, normally called @file{.gdbinit}@footnote{The DJGPP
13612port of @value{GDBN} uses the name @file{gdb.ini} instead, due to the
13613limitations of file names imposed by DOS filesystems.}.
13614During startup, @value{GDBN} does the following:
bf0184be
ND
13615
13616@enumerate
13617@item
13618Reads the init file (if any) in your home directory@footnote{On
13619DOS/Windows systems, the home directory is the one pointed to by the
13620@code{HOME} environment variable.}.
13621
13622@item
13623Processes command line options and operands.
13624
13625@item
13626Reads the init file (if any) in the current working directory.
13627
13628@item
13629Reads command files specified by the @samp{-x} option.
13630@end enumerate
13631
13632The init file in your home directory can set options (such as @samp{set
13633complaints}) that affect subsequent processing of command line options
13634and operands. Init files are not executed if you use the @samp{-nx}
13635option (@pxref{Mode Options, ,Choosing modes}).
c906108c 13636
c906108c
SS
13637@cindex init file name
13638On some configurations of @value{GDBN}, the init file is known by a
13639different name (these are typically environments where a specialized
13640form of @value{GDBN} may need to coexist with other forms, hence a
13641different name for the specialized version's init file). These are the
13642environments with special init file names:
13643
00e4a2e4 13644@cindex @file{.vxgdbinit}
c906108c
SS
13645@itemize @bullet
13646@item
00e4a2e4 13647VxWorks (Wind River Systems real-time OS): @file{.vxgdbinit}
c906108c 13648
00e4a2e4 13649@cindex @file{.os68gdbinit}
c906108c 13650@item
00e4a2e4 13651OS68K (Enea Data Systems real-time OS): @file{.os68gdbinit}
c906108c 13652
00e4a2e4 13653@cindex @file{.esgdbinit}
c906108c 13654@item
00e4a2e4 13655ES-1800 (Ericsson Telecom AB M68000 emulator): @file{.esgdbinit}
c906108c 13656@end itemize
c906108c
SS
13657
13658You can also request the execution of a command file with the
13659@code{source} command:
13660
13661@table @code
13662@kindex source
13663@item source @var{filename}
13664Execute the command file @var{filename}.
13665@end table
13666
13667The lines in a command file are executed sequentially. They are not
13668printed as they are executed. An error in any command terminates execution
13669of the command file.
13670
13671Commands that would ask for confirmation if used interactively proceed
13672without asking when used in a command file. Many @value{GDBN} commands that
13673normally print messages to say what they are doing omit the messages
13674when called from command files.
13675
b433d00b
DH
13676@value{GDBN} also accepts command input from standard input. In this
13677mode, normal output goes to standard output and error output goes to
13678standard error. Errors in a command file supplied on standard input do
13679not terminate execution of the command file --- execution continues with
13680the next command.
13681
13682@example
13683gdb < cmds > log 2>&1
13684@end example
13685
13686(The syntax above will vary depending on the shell used.) This example
13687will execute commands from the file @file{cmds}. All output and errors
13688would be directed to @file{log}.
13689
6d2ebf8b 13690@node Output
c906108c
SS
13691@section Commands for controlled output
13692
13693During the execution of a command file or a user-defined command, normal
13694@value{GDBN} output is suppressed; the only output that appears is what is
13695explicitly printed by the commands in the definition. This section
13696describes three commands useful for generating exactly the output you
13697want.
13698
13699@table @code
13700@kindex echo
13701@item echo @var{text}
13702@c I do not consider backslash-space a standard C escape sequence
13703@c because it is not in ANSI.
13704Print @var{text}. Nonprinting characters can be included in
13705@var{text} using C escape sequences, such as @samp{\n} to print a
13706newline. @strong{No newline is printed unless you specify one.}
13707In addition to the standard C escape sequences, a backslash followed
13708by a space stands for a space. This is useful for displaying a
13709string with spaces at the beginning or the end, since leading and
5d161b24 13710trailing spaces are otherwise trimmed from all arguments.
c906108c
SS
13711To print @samp{@w{ }and foo =@w{ }}, use the command
13712@samp{echo \@w{ }and foo = \@w{ }}.
13713
13714A backslash at the end of @var{text} can be used, as in C, to continue
13715the command onto subsequent lines. For example,
13716
13717@example
13718echo This is some text\n\
13719which is continued\n\
13720onto several lines.\n
13721@end example
13722
13723produces the same output as
13724
13725@example
13726echo This is some text\n
13727echo which is continued\n
13728echo onto several lines.\n
13729@end example
13730
13731@kindex output
13732@item output @var{expression}
13733Print the value of @var{expression} and nothing but that value: no
13734newlines, no @samp{$@var{nn} = }. The value is not entered in the
5d161b24 13735value history either. @xref{Expressions, ,Expressions}, for more information
c906108c
SS
13736on expressions.
13737
13738@item output/@var{fmt} @var{expression}
13739Print the value of @var{expression} in format @var{fmt}. You can use
13740the same formats as for @code{print}. @xref{Output Formats,,Output
13741formats}, for more information.
13742
13743@kindex printf
13744@item printf @var{string}, @var{expressions}@dots{}
13745Print the values of the @var{expressions} under the control of
13746@var{string}. The @var{expressions} are separated by commas and may be
13747either numbers or pointers. Their values are printed as specified by
13748@var{string}, exactly as if your program were to execute the C
13749subroutine
d4f3574e
SS
13750@c FIXME: the above implies that at least all ANSI C formats are
13751@c supported, but it isn't true: %E and %G don't work (or so it seems).
13752@c Either this is a bug, or the manual should document what formats are
13753@c supported.
c906108c
SS
13754
13755@example
13756printf (@var{string}, @var{expressions}@dots{});
13757@end example
13758
13759For example, you can print two values in hex like this:
13760
13761@smallexample
13762printf "foo, bar-foo = 0x%x, 0x%x\n", foo, bar-foo
13763@end smallexample
13764
13765The only backslash-escape sequences that you can use in the format
13766string are the simple ones that consist of backslash followed by a
13767letter.
13768@end table
13769
c4555f82
SC
13770@node TUI
13771@chapter @value{GDBN} Text User Interface
13772@cindex TUI
13773
13774@menu
13775* TUI Overview:: TUI overview
13776* TUI Keys:: TUI key bindings
13777* TUI Commands:: TUI specific commands
13778* TUI Configuration:: TUI configuration variables
13779@end menu
13780
13781The @value{GDBN} Text User Interface, TUI in short,
13782is a terminal interface which uses the @code{curses} library
13783to show the source file, the assembly output, the program registers
13784and @value{GDBN} commands in separate text windows.
13785The TUI is available only when @value{GDBN} is configured
13786with the @code{--enable-tui} configure option (@pxref{Configure Options}).
13787
13788@node TUI Overview
13789@section TUI overview
13790
13791The TUI has two display modes that can be switched while
13792@value{GDBN} runs:
13793
13794@itemize @bullet
13795@item
13796A curses (or TUI) mode in which it displays several text
13797windows on the terminal.
13798
13799@item
13800A standard mode which corresponds to the @value{GDBN} configured without
13801the TUI.
13802@end itemize
13803
13804In the TUI mode, @value{GDBN} can display several text window
13805on the terminal:
13806
13807@table @emph
13808@item command
13809This window is the @value{GDBN} command window with the @value{GDBN}
13810prompt and the @value{GDBN} outputs. The @value{GDBN} input is still
13811managed using readline but through the TUI. The @emph{command}
13812window is always visible.
13813
13814@item source
13815The source window shows the source file of the program. The current
13816line as well as active breakpoints are displayed in this window.
13817The current program position is shown with the @samp{>} marker and
13818active breakpoints are shown with @samp{*} markers.
13819
13820@item assembly
13821The assembly window shows the disassembly output of the program.
13822
13823@item register
13824This window shows the processor registers. It detects when
13825a register is changed and when this is the case, registers that have
13826changed are highlighted.
13827
13828@end table
13829
13830The source, assembly and register windows are attached to the thread
13831and the frame position. They are updated when the current thread
13832changes, when the frame changes or when the program counter changes.
13833These three windows are arranged by the TUI according to several
13834layouts. The layout defines which of these three windows are visible.
13835The following layouts are available:
13836
13837@itemize @bullet
13838@item
13839source
13840
13841@item
13842assembly
13843
13844@item
13845source and assembly
13846
13847@item
13848source and registers
13849
13850@item
13851assembly and registers
13852
13853@end itemize
13854
13855@node TUI Keys
13856@section TUI Key Bindings
13857@cindex TUI key bindings
13858
13859The TUI installs several key bindings in the readline keymaps
13860(@pxref{Command Line Editing}).
13861They allow to leave or enter in the TUI mode or they operate
13862directly on the TUI layout and windows. The following key bindings
13863are installed for both TUI mode and the @value{GDBN} standard mode.
13864
13865@table @kbd
13866@kindex C-x C-a
13867@item C-x C-a
13868@kindex C-x a
13869@itemx C-x a
13870@kindex C-x A
13871@itemx C-x A
13872Enter or leave the TUI mode. When the TUI mode is left,
13873the curses window management is left and @value{GDBN} operates using
13874its standard mode writing on the terminal directly. When the TUI
13875mode is entered, the control is given back to the curses windows.
13876The screen is then refreshed.
13877
13878@kindex C-x 1
13879@item C-x 1
13880Use a TUI layout with only one window. The layout will
13881either be @samp{source} or @samp{assembly}. When the TUI mode
13882is not active, it will switch to the TUI mode.
13883
13884Think of this key binding as the Emacs @kbd{C-x 1} binding.
13885
13886@kindex C-x 2
13887@item C-x 2
13888Use a TUI layout with at least two windows. When the current
13889layout shows already two windows, a next layout with two windows is used.
13890When a new layout is chosen, one window will always be common to the
13891previous layout and the new one.
13892
13893Think of it as the Emacs @kbd{C-x 2} binding.
13894
13895@end table
13896
13897The following key bindings are handled only by the TUI mode:
13898
13899@table @key
13900@kindex PgUp
13901@item PgUp
13902Scroll the active window one page up.
13903
13904@kindex PgDn
13905@item PgDn
13906Scroll the active window one page down.
13907
13908@kindex Up
13909@item Up
13910Scroll the active window one line up.
13911
13912@kindex Down
13913@item Down
13914Scroll the active window one line down.
13915
13916@kindex Left
13917@item Left
13918Scroll the active window one column left.
13919
13920@kindex Right
13921@item Right
13922Scroll the active window one column right.
13923
13924@kindex C-L
13925@item C-L
13926Refresh the screen.
13927
13928@end table
13929
13930In the TUI mode, the arrow keys are used by the active window
13931for scrolling. This means they are not available for readline. It is
13932necessary to use other readline key bindings such as @key{C-p}, @key{C-n},
13933@key{C-b} and @key{C-f}.
13934
13935@node TUI Commands
13936@section TUI specific commands
13937@cindex TUI commands
13938
13939The TUI has specific commands to control the text windows.
13940These commands are always available, that is they do not depend on
13941the current terminal mode in which @value{GDBN} runs. When @value{GDBN}
13942is in the standard mode, using these commands will automatically switch
13943in the TUI mode.
13944
13945@table @code
13946@item layout next
13947@kindex layout next
13948Display the next layout.
13949
13950@item layout prev
13951@kindex layout prev
13952Display the previous layout.
13953
13954@item layout src
13955@kindex layout src
13956Display the source window only.
13957
13958@item layout asm
13959@kindex layout asm
13960Display the assembly window only.
13961
13962@item layout split
13963@kindex layout split
13964Display the source and assembly window.
13965
13966@item layout regs
13967@kindex layout regs
13968Display the register window together with the source or assembly window.
13969
13970@item focus next | prev | src | asm | regs | split
13971@kindex focus
13972Set the focus to the named window.
13973This command allows to change the active window so that scrolling keys
13974can be affected to another window.
13975
13976@item refresh
13977@kindex refresh
13978Refresh the screen. This is similar to using @key{C-L} key.
13979
13980@item update
13981@kindex update
13982Update the source window and the current execution point.
13983
13984@item winheight @var{name} +@var{count}
13985@itemx winheight @var{name} -@var{count}
13986@kindex winheight
13987Change the height of the window @var{name} by @var{count}
13988lines. Positive counts increase the height, while negative counts
13989decrease it.
13990
13991@end table
13992
13993@node TUI Configuration
13994@section TUI configuration variables
13995@cindex TUI configuration variables
13996
13997The TUI has several configuration variables that control the
13998appearance of windows on the terminal.
13999
14000@table @code
732b3002
SC
14001@item set tui border-kind @var{kind}
14002@kindex set tui border-kind
c4555f82
SC
14003Select the border appearance for the source, assembly and register windows.
14004The possible values are the following:
14005@table @code
14006@item space
14007Use a space character to draw the border.
14008
14009@item ascii
14010Use ascii characters + - and | to draw the border.
14011
14012@item acs
14013Use the Alternate Character Set to draw the border. The border is
14014drawn using character line graphics if the terminal supports them.
14015
14016@end table
14017
732b3002
SC
14018@item set tui active-border-mode @var{mode}
14019@kindex set tui active-border-mode
c4555f82
SC
14020Select the attributes to display the border of the active window.
14021The possible values are @code{normal}, @code{standout}, @code{reverse},
14022@code{half}, @code{half-standout}, @code{bold} and @code{bold-standout}.
14023
732b3002
SC
14024@item set tui border-mode @var{mode}
14025@kindex set tui border-mode
c4555f82
SC
14026Select the attributes to display the border of other windows.
14027The @var{mode} can be one of the following:
14028@table @code
14029@item normal
14030Use normal attributes to display the border.
14031
14032@item standout
14033Use standout mode.
14034
14035@item reverse
14036Use reverse video mode.
14037
14038@item half
14039Use half bright mode.
14040
14041@item half-standout
14042Use half bright and standout mode.
14043
14044@item bold
14045Use extra bright or bold mode.
14046
14047@item bold-standout
14048Use extra bright or bold and standout mode.
14049
14050@end table
14051
14052@end table
14053
6d2ebf8b 14054@node Emacs
c906108c
SS
14055@chapter Using @value{GDBN} under @sc{gnu} Emacs
14056
14057@cindex Emacs
14058@cindex @sc{gnu} Emacs
14059A special interface allows you to use @sc{gnu} Emacs to view (and
14060edit) the source files for the program you are debugging with
14061@value{GDBN}.
14062
14063To use this interface, use the command @kbd{M-x gdb} in Emacs. Give the
14064executable file you want to debug as an argument. This command starts
14065@value{GDBN} as a subprocess of Emacs, with input and output through a newly
14066created Emacs buffer.
53a5351d 14067@c (Do not use the @code{-tui} option to run @value{GDBN} from Emacs.)
c906108c
SS
14068
14069Using @value{GDBN} under Emacs is just like using @value{GDBN} normally except for two
14070things:
14071
14072@itemize @bullet
14073@item
14074All ``terminal'' input and output goes through the Emacs buffer.
14075@end itemize
14076
14077This applies both to @value{GDBN} commands and their output, and to the input
14078and output done by the program you are debugging.
14079
14080This is useful because it means that you can copy the text of previous
14081commands and input them again; you can even use parts of the output
14082in this way.
14083
14084All the facilities of Emacs' Shell mode are available for interacting
14085with your program. In particular, you can send signals the usual
14086way---for example, @kbd{C-c C-c} for an interrupt, @kbd{C-c C-z} for a
14087stop.
14088
14089@itemize @bullet
14090@item
14091@value{GDBN} displays source code through Emacs.
14092@end itemize
14093
14094Each time @value{GDBN} displays a stack frame, Emacs automatically finds the
14095source file for that frame and puts an arrow (@samp{=>}) at the
14096left margin of the current line. Emacs uses a separate buffer for
14097source display, and splits the screen to show both your @value{GDBN} session
14098and the source.
14099
14100Explicit @value{GDBN} @code{list} or search commands still produce output as
14101usual, but you probably have no reason to use them from Emacs.
14102
14103@quotation
14104@emph{Warning:} If the directory where your program resides is not your
14105current directory, it can be easy to confuse Emacs about the location of
14106the source files, in which case the auxiliary display buffer does not
14107appear to show your source. @value{GDBN} can find programs by searching your
14108environment's @code{PATH} variable, so the @value{GDBN} input and output
14109session proceeds normally; but Emacs does not get enough information
14110back from @value{GDBN} to locate the source files in this situation. To
14111avoid this problem, either start @value{GDBN} mode from the directory where
14112your program resides, or specify an absolute file name when prompted for the
14113@kbd{M-x gdb} argument.
14114
14115A similar confusion can result if you use the @value{GDBN} @code{file} command to
14116switch to debugging a program in some other location, from an existing
14117@value{GDBN} buffer in Emacs.
14118@end quotation
14119
14120By default, @kbd{M-x gdb} calls the program called @file{gdb}. If
14121you need to call @value{GDBN} by a different name (for example, if you keep
14122several configurations around, with different names) you can set the
14123Emacs variable @code{gdb-command-name}; for example,
14124
14125@example
14126(setq gdb-command-name "mygdb")
14127@end example
14128
14129@noindent
d4f3574e 14130(preceded by @kbd{M-:} or @kbd{ESC :}, or typed in the @code{*scratch*} buffer, or
c906108c
SS
14131in your @file{.emacs} file) makes Emacs call the program named
14132``@code{mygdb}'' instead.
14133
14134In the @value{GDBN} I/O buffer, you can use these special Emacs commands in
14135addition to the standard Shell mode commands:
14136
14137@table @kbd
14138@item C-h m
14139Describe the features of Emacs' @value{GDBN} Mode.
14140
14141@item M-s
14142Execute to another source line, like the @value{GDBN} @code{step} command; also
14143update the display window to show the current file and location.
14144
14145@item M-n
14146Execute to next source line in this function, skipping all function
14147calls, like the @value{GDBN} @code{next} command. Then update the display window
14148to show the current file and location.
14149
14150@item M-i
14151Execute one instruction, like the @value{GDBN} @code{stepi} command; update
14152display window accordingly.
14153
14154@item M-x gdb-nexti
14155Execute to next instruction, using the @value{GDBN} @code{nexti} command; update
14156display window accordingly.
14157
14158@item C-c C-f
14159Execute until exit from the selected stack frame, like the @value{GDBN}
14160@code{finish} command.
14161
14162@item M-c
14163Continue execution of your program, like the @value{GDBN} @code{continue}
14164command.
14165
14166@emph{Warning:} In Emacs v19, this command is @kbd{C-c C-p}.
14167
14168@item M-u
14169Go up the number of frames indicated by the numeric argument
14170(@pxref{Arguments, , Numeric Arguments, Emacs, The @sc{gnu} Emacs Manual}),
14171like the @value{GDBN} @code{up} command.
14172
14173@emph{Warning:} In Emacs v19, this command is @kbd{C-c C-u}.
14174
14175@item M-d
14176Go down the number of frames indicated by the numeric argument, like the
14177@value{GDBN} @code{down} command.
14178
14179@emph{Warning:} In Emacs v19, this command is @kbd{C-c C-d}.
14180
14181@item C-x &
14182Read the number where the cursor is positioned, and insert it at the end
14183of the @value{GDBN} I/O buffer. For example, if you wish to disassemble code
14184around an address that was displayed earlier, type @kbd{disassemble};
14185then move the cursor to the address display, and pick up the
14186argument for @code{disassemble} by typing @kbd{C-x &}.
14187
14188You can customize this further by defining elements of the list
14189@code{gdb-print-command}; once it is defined, you can format or
14190otherwise process numbers picked up by @kbd{C-x &} before they are
14191inserted. A numeric argument to @kbd{C-x &} indicates that you
14192wish special formatting, and also acts as an index to pick an element of the
14193list. If the list element is a string, the number to be inserted is
14194formatted using the Emacs function @code{format}; otherwise the number
14195is passed as an argument to the corresponding list element.
14196@end table
14197
14198In any source file, the Emacs command @kbd{C-x SPC} (@code{gdb-break})
14199tells @value{GDBN} to set a breakpoint on the source line point is on.
14200
14201If you accidentally delete the source-display buffer, an easy way to get
14202it back is to type the command @code{f} in the @value{GDBN} buffer, to
14203request a frame display; when you run under Emacs, this recreates
14204the source buffer if necessary to show you the context of the current
14205frame.
14206
14207The source files displayed in Emacs are in ordinary Emacs buffers
14208which are visiting the source files in the usual way. You can edit
14209the files with these buffers if you wish; but keep in mind that @value{GDBN}
14210communicates with Emacs in terms of line numbers. If you add or
14211delete lines from the text, the line numbers that @value{GDBN} knows cease
14212to correspond properly with the code.
14213
14214@c The following dropped because Epoch is nonstandard. Reactivate
14215@c if/when v19 does something similar. ---doc@cygnus.com 19dec1990
14216@ignore
14217@kindex Emacs Epoch environment
14218@kindex Epoch
14219@kindex inspect
14220
5d161b24 14221Version 18 of @sc{gnu} Emacs has a built-in window system
c906108c
SS
14222called the @code{epoch}
14223environment. Users of this environment can use a new command,
14224@code{inspect} which performs identically to @code{print} except that
14225each value is printed in its own window.
14226@end ignore
c906108c 14227
d700128c 14228@include annotate.texi
7162c0ca 14229@include gdbmi.texinfo
d700128c 14230
6d2ebf8b 14231@node GDB Bugs
c906108c
SS
14232@chapter Reporting Bugs in @value{GDBN}
14233@cindex bugs in @value{GDBN}
14234@cindex reporting bugs in @value{GDBN}
14235
14236Your bug reports play an essential role in making @value{GDBN} reliable.
14237
14238Reporting a bug may help you by bringing a solution to your problem, or it
14239may not. But in any case the principal function of a bug report is to help
14240the entire community by making the next version of @value{GDBN} work better. Bug
14241reports are your contribution to the maintenance of @value{GDBN}.
14242
14243In order for a bug report to serve its purpose, you must include the
14244information that enables us to fix the bug.
14245
14246@menu
14247* Bug Criteria:: Have you found a bug?
14248* Bug Reporting:: How to report bugs
14249@end menu
14250
6d2ebf8b 14251@node Bug Criteria
c906108c
SS
14252@section Have you found a bug?
14253@cindex bug criteria
14254
14255If you are not sure whether you have found a bug, here are some guidelines:
14256
14257@itemize @bullet
14258@cindex fatal signal
14259@cindex debugger crash
14260@cindex crash of debugger
14261@item
14262If the debugger gets a fatal signal, for any input whatever, that is a
14263@value{GDBN} bug. Reliable debuggers never crash.
14264
14265@cindex error on valid input
14266@item
14267If @value{GDBN} produces an error message for valid input, that is a
14268bug. (Note that if you're cross debugging, the problem may also be
14269somewhere in the connection to the target.)
14270
14271@cindex invalid input
14272@item
14273If @value{GDBN} does not produce an error message for invalid input,
14274that is a bug. However, you should note that your idea of
14275``invalid input'' might be our idea of ``an extension'' or ``support
14276for traditional practice''.
14277
14278@item
14279If you are an experienced user of debugging tools, your suggestions
14280for improvement of @value{GDBN} are welcome in any case.
14281@end itemize
14282
6d2ebf8b 14283@node Bug Reporting
c906108c
SS
14284@section How to report bugs
14285@cindex bug reports
14286@cindex @value{GDBN} bugs, reporting
14287
c906108c
SS
14288A number of companies and individuals offer support for @sc{gnu} products.
14289If you obtained @value{GDBN} from a support organization, we recommend you
14290contact that organization first.
14291
14292You can find contact information for many support companies and
14293individuals in the file @file{etc/SERVICE} in the @sc{gnu} Emacs
14294distribution.
14295@c should add a web page ref...
14296
14297In any event, we also recommend that you send bug reports for
14298@value{GDBN} to this addresses:
14299
14300@example
d4f3574e 14301bug-gdb@@gnu.org
c906108c
SS
14302@end example
14303
14304@strong{Do not send bug reports to @samp{info-gdb}, or to
d4f3574e 14305@samp{help-gdb}, or to any newsgroups.} Most users of @value{GDBN} do
c906108c
SS
14306not want to receive bug reports. Those that do have arranged to receive
14307@samp{bug-gdb}.
14308
14309The mailing list @samp{bug-gdb} has a newsgroup @samp{gnu.gdb.bug} which
14310serves as a repeater. The mailing list and the newsgroup carry exactly
14311the same messages. Often people think of posting bug reports to the
14312newsgroup instead of mailing them. This appears to work, but it has one
14313problem which can be crucial: a newsgroup posting often lacks a mail
14314path back to the sender. Thus, if we need to ask for more information,
14315we may be unable to reach you. For this reason, it is better to send
14316bug reports to the mailing list.
14317
14318As a last resort, send bug reports on paper to:
14319
14320@example
14321@sc{gnu} Debugger Bugs
14322Free Software Foundation Inc.
1432359 Temple Place - Suite 330
14324Boston, MA 02111-1307
14325USA
14326@end example
c906108c
SS
14327
14328The fundamental principle of reporting bugs usefully is this:
14329@strong{report all the facts}. If you are not sure whether to state a
14330fact or leave it out, state it!
14331
14332Often people omit facts because they think they know what causes the
14333problem and assume that some details do not matter. Thus, you might
14334assume that the name of the variable you use in an example does not matter.
14335Well, probably it does not, but one cannot be sure. Perhaps the bug is a
14336stray memory reference which happens to fetch from the location where that
14337name is stored in memory; perhaps, if the name were different, the contents
14338of that location would fool the debugger into doing the right thing despite
14339the bug. Play it safe and give a specific, complete example. That is the
14340easiest thing for you to do, and the most helpful.
14341
14342Keep in mind that the purpose of a bug report is to enable us to fix the
14343bug. It may be that the bug has been reported previously, but neither
14344you nor we can know that unless your bug report is complete and
14345self-contained.
14346
14347Sometimes people give a few sketchy facts and ask, ``Does this ring a
14348bell?'' Those bug reports are useless, and we urge everyone to
14349@emph{refuse to respond to them} except to chide the sender to report
14350bugs properly.
14351
14352To enable us to fix the bug, you should include all these things:
14353
14354@itemize @bullet
14355@item
14356The version of @value{GDBN}. @value{GDBN} announces it if you start
14357with no arguments; you can also print it at any time using @code{show
14358version}.
14359
14360Without this, we will not know whether there is any point in looking for
14361the bug in the current version of @value{GDBN}.
14362
14363@item
14364The type of machine you are using, and the operating system name and
14365version number.
14366
c906108c
SS
14367@item
14368What compiler (and its version) was used to compile @value{GDBN}---e.g.
14369``@value{GCC}--2.8.1''.
c906108c
SS
14370
14371@item
14372What compiler (and its version) was used to compile the program you are
14373debugging---e.g. ``@value{GCC}--2.8.1'', or ``HP92453-01 A.10.32.03 HP
14374C Compiler''. For GCC, you can say @code{gcc --version} to get this
14375information; for other compilers, see the documentation for those
14376compilers.
14377
14378@item
14379The command arguments you gave the compiler to compile your example and
14380observe the bug. For example, did you use @samp{-O}? To guarantee
14381you will not omit something important, list them all. A copy of the
14382Makefile (or the output from make) is sufficient.
14383
14384If we were to try to guess the arguments, we would probably guess wrong
14385and then we might not encounter the bug.
14386
14387@item
14388A complete input script, and all necessary source files, that will
14389reproduce the bug.
14390
14391@item
14392A description of what behavior you observe that you believe is
14393incorrect. For example, ``It gets a fatal signal.''
14394
14395Of course, if the bug is that @value{GDBN} gets a fatal signal, then we
14396will certainly notice it. But if the bug is incorrect output, we might
14397not notice unless it is glaringly wrong. You might as well not give us
14398a chance to make a mistake.
14399
14400Even if the problem you experience is a fatal signal, you should still
14401say so explicitly. Suppose something strange is going on, such as, your
14402copy of @value{GDBN} is out of synch, or you have encountered a bug in
14403the C library on your system. (This has happened!) Your copy might
14404crash and ours would not. If you told us to expect a crash, then when
14405ours fails to crash, we would know that the bug was not happening for
14406us. If you had not told us to expect a crash, then we would not be able
14407to draw any conclusion from our observations.
14408
c906108c
SS
14409@item
14410If you wish to suggest changes to the @value{GDBN} source, send us context
14411diffs. If you even discuss something in the @value{GDBN} source, refer to
14412it by context, not by line number.
14413
14414The line numbers in our development sources will not match those in your
14415sources. Your line numbers would convey no useful information to us.
53a5351d 14416
c906108c
SS
14417@end itemize
14418
14419Here are some things that are not necessary:
14420
14421@itemize @bullet
14422@item
14423A description of the envelope of the bug.
14424
14425Often people who encounter a bug spend a lot of time investigating
14426which changes to the input file will make the bug go away and which
14427changes will not affect it.
14428
14429This is often time consuming and not very useful, because the way we
14430will find the bug is by running a single example under the debugger
14431with breakpoints, not by pure deduction from a series of examples.
14432We recommend that you save your time for something else.
14433
14434Of course, if you can find a simpler example to report @emph{instead}
14435of the original one, that is a convenience for us. Errors in the
14436output will be easier to spot, running under the debugger will take
14437less time, and so on.
14438
14439However, simplification is not vital; if you do not want to do this,
14440report the bug anyway and send us the entire test case you used.
14441
14442@item
14443A patch for the bug.
14444
14445A patch for the bug does help us if it is a good one. But do not omit
14446the necessary information, such as the test case, on the assumption that
14447a patch is all we need. We might see problems with your patch and decide
14448to fix the problem another way, or we might not understand it at all.
14449
14450Sometimes with a program as complicated as @value{GDBN} it is very hard to
14451construct an example that will make the program follow a certain path
14452through the code. If you do not send us the example, we will not be able
14453to construct one, so we will not be able to verify that the bug is fixed.
14454
14455And if we cannot understand what bug you are trying to fix, or why your
14456patch should be an improvement, we will not install it. A test case will
14457help us to understand.
14458
14459@item
14460A guess about what the bug is or what it depends on.
14461
14462Such guesses are usually wrong. Even we cannot guess right about such
14463things without first using the debugger to find the facts.
14464@end itemize
14465
5d161b24 14466@c The readline documentation is distributed with the readline code
c906108c
SS
14467@c and consists of the two following files:
14468@c rluser.texinfo
7be570e7 14469@c inc-hist.texinfo
c906108c
SS
14470@c Use -I with makeinfo to point to the appropriate directory,
14471@c environment var TEXINPUTS with TeX.
14472@include rluser.texinfo
7be570e7 14473@include inc-hist.texinfo
c906108c
SS
14474
14475
6d2ebf8b 14476@node Formatting Documentation
c906108c
SS
14477@appendix Formatting Documentation
14478
14479@cindex @value{GDBN} reference card
14480@cindex reference card
14481The @value{GDBN} 4 release includes an already-formatted reference card, ready
14482for printing with PostScript or Ghostscript, in the @file{gdb}
14483subdirectory of the main source directory@footnote{In
14484@file{gdb-@value{GDBVN}/gdb/refcard.ps} of the version @value{GDBVN}
14485release.}. If you can use PostScript or Ghostscript with your printer,
14486you can print the reference card immediately with @file{refcard.ps}.
14487
14488The release also includes the source for the reference card. You
14489can format it, using @TeX{}, by typing:
14490
14491@example
14492make refcard.dvi
14493@end example
14494
5d161b24
DB
14495The @value{GDBN} reference card is designed to print in @dfn{landscape}
14496mode on US ``letter'' size paper;
c906108c
SS
14497that is, on a sheet 11 inches wide by 8.5 inches
14498high. You will need to specify this form of printing as an option to
14499your @sc{dvi} output program.
14500
14501@cindex documentation
14502
14503All the documentation for @value{GDBN} comes as part of the machine-readable
14504distribution. The documentation is written in Texinfo format, which is
14505a documentation system that uses a single source file to produce both
14506on-line information and a printed manual. You can use one of the Info
14507formatting commands to create the on-line version of the documentation
14508and @TeX{} (or @code{texi2roff}) to typeset the printed version.
14509
14510@value{GDBN} includes an already formatted copy of the on-line Info
14511version of this manual in the @file{gdb} subdirectory. The main Info
14512file is @file{gdb-@value{GDBVN}/gdb/gdb.info}, and it refers to
14513subordinate files matching @samp{gdb.info*} in the same directory. If
14514necessary, you can print out these files, or read them with any editor;
14515but they are easier to read using the @code{info} subsystem in @sc{gnu}
14516Emacs or the standalone @code{info} program, available as part of the
14517@sc{gnu} Texinfo distribution.
14518
14519If you want to format these Info files yourself, you need one of the
14520Info formatting programs, such as @code{texinfo-format-buffer} or
14521@code{makeinfo}.
14522
14523If you have @code{makeinfo} installed, and are in the top level
14524@value{GDBN} source directory (@file{gdb-@value{GDBVN}}, in the case of
14525version @value{GDBVN}), you can make the Info file by typing:
14526
14527@example
14528cd gdb
14529make gdb.info
14530@end example
14531
14532If you want to typeset and print copies of this manual, you need @TeX{},
14533a program to print its @sc{dvi} output files, and @file{texinfo.tex}, the
14534Texinfo definitions file.
14535
14536@TeX{} is a typesetting program; it does not print files directly, but
14537produces output files called @sc{dvi} files. To print a typeset
14538document, you need a program to print @sc{dvi} files. If your system
14539has @TeX{} installed, chances are it has such a program. The precise
14540command to use depends on your system; @kbd{lpr -d} is common; another
14541(for PostScript devices) is @kbd{dvips}. The @sc{dvi} print command may
14542require a file name without any extension or a @samp{.dvi} extension.
14543
14544@TeX{} also requires a macro definitions file called
14545@file{texinfo.tex}. This file tells @TeX{} how to typeset a document
14546written in Texinfo format. On its own, @TeX{} cannot either read or
14547typeset a Texinfo file. @file{texinfo.tex} is distributed with GDB
14548and is located in the @file{gdb-@var{version-number}/texinfo}
14549directory.
14550
14551If you have @TeX{} and a @sc{dvi} printer program installed, you can
14552typeset and print this manual. First switch to the the @file{gdb}
14553subdirectory of the main source directory (for example, to
14554@file{gdb-@value{GDBVN}/gdb}) and type:
14555
14556@example
14557make gdb.dvi
14558@end example
14559
14560Then give @file{gdb.dvi} to your @sc{dvi} printing program.
c906108c 14561
6d2ebf8b 14562@node Installing GDB
c906108c
SS
14563@appendix Installing @value{GDBN}
14564@cindex configuring @value{GDBN}
14565@cindex installation
14566
c906108c
SS
14567@value{GDBN} comes with a @code{configure} script that automates the process
14568of preparing @value{GDBN} for installation; you can then use @code{make} to
14569build the @code{gdb} program.
14570@iftex
14571@c irrelevant in info file; it's as current as the code it lives with.
14572@footnote{If you have a more recent version of @value{GDBN} than @value{GDBVN},
14573look at the @file{README} file in the sources; we may have improved the
14574installation procedures since publishing this manual.}
14575@end iftex
14576
5d161b24
DB
14577The @value{GDBN} distribution includes all the source code you need for
14578@value{GDBN} in a single directory, whose name is usually composed by
c906108c
SS
14579appending the version number to @samp{gdb}.
14580
14581For example, the @value{GDBN} version @value{GDBVN} distribution is in the
14582@file{gdb-@value{GDBVN}} directory. That directory contains:
14583
14584@table @code
14585@item gdb-@value{GDBVN}/configure @r{(and supporting files)}
14586script for configuring @value{GDBN} and all its supporting libraries
14587
14588@item gdb-@value{GDBVN}/gdb
14589the source specific to @value{GDBN} itself
14590
14591@item gdb-@value{GDBVN}/bfd
14592source for the Binary File Descriptor library
14593
14594@item gdb-@value{GDBVN}/include
14595@sc{gnu} include files
14596
14597@item gdb-@value{GDBVN}/libiberty
14598source for the @samp{-liberty} free software library
14599
14600@item gdb-@value{GDBVN}/opcodes
14601source for the library of opcode tables and disassemblers
14602
14603@item gdb-@value{GDBVN}/readline
14604source for the @sc{gnu} command-line interface
14605
14606@item gdb-@value{GDBVN}/glob
14607source for the @sc{gnu} filename pattern-matching subroutine
14608
14609@item gdb-@value{GDBVN}/mmalloc
14610source for the @sc{gnu} memory-mapped malloc package
14611@end table
14612
14613The simplest way to configure and build @value{GDBN} is to run @code{configure}
14614from the @file{gdb-@var{version-number}} source directory, which in
14615this example is the @file{gdb-@value{GDBVN}} directory.
14616
14617First switch to the @file{gdb-@var{version-number}} source directory
14618if you are not already in it; then run @code{configure}. Pass the
14619identifier for the platform on which @value{GDBN} will run as an
14620argument.
14621
14622For example:
14623
14624@example
14625cd gdb-@value{GDBVN}
14626./configure @var{host}
14627make
14628@end example
14629
14630@noindent
14631where @var{host} is an identifier such as @samp{sun4} or
14632@samp{decstation}, that identifies the platform where @value{GDBN} will run.
14633(You can often leave off @var{host}; @code{configure} tries to guess the
14634correct value by examining your system.)
14635
14636Running @samp{configure @var{host}} and then running @code{make} builds the
14637@file{bfd}, @file{readline}, @file{mmalloc}, and @file{libiberty}
14638libraries, then @code{gdb} itself. The configured source files, and the
14639binaries, are left in the corresponding source directories.
14640
14641@need 750
14642@code{configure} is a Bourne-shell (@code{/bin/sh}) script; if your
14643system does not recognize this automatically when you run a different
14644shell, you may need to run @code{sh} on it explicitly:
14645
14646@example
14647sh configure @var{host}
14648@end example
14649
14650If you run @code{configure} from a directory that contains source
14651directories for multiple libraries or programs, such as the
14652@file{gdb-@value{GDBVN}} source directory for version @value{GDBVN}, @code{configure}
14653creates configuration files for every directory level underneath (unless
14654you tell it not to, with the @samp{--norecursion} option).
14655
14656You can run the @code{configure} script from any of the
14657subordinate directories in the @value{GDBN} distribution if you only want to
14658configure that subdirectory, but be sure to specify a path to it.
14659
14660For example, with version @value{GDBVN}, type the following to configure only
14661the @code{bfd} subdirectory:
14662
14663@example
14664@group
14665cd gdb-@value{GDBVN}/bfd
14666../configure @var{host}
14667@end group
14668@end example
14669
14670You can install @code{@value{GDBP}} anywhere; it has no hardwired paths.
14671However, you should make sure that the shell on your path (named by
14672the @samp{SHELL} environment variable) is publicly readable. Remember
14673that @value{GDBN} uses the shell to start your program---some systems refuse to
14674let @value{GDBN} debug child processes whose programs are not readable.
14675
14676@menu
14677* Separate Objdir:: Compiling @value{GDBN} in another directory
14678* Config Names:: Specifying names for hosts and targets
14679* Configure Options:: Summary of options for configure
14680@end menu
14681
6d2ebf8b 14682@node Separate Objdir
c906108c
SS
14683@section Compiling @value{GDBN} in another directory
14684
14685If you want to run @value{GDBN} versions for several host or target machines,
14686you need a different @code{gdb} compiled for each combination of
14687host and target. @code{configure} is designed to make this easy by
14688allowing you to generate each configuration in a separate subdirectory,
14689rather than in the source directory. If your @code{make} program
14690handles the @samp{VPATH} feature (@sc{gnu} @code{make} does), running
14691@code{make} in each of these directories builds the @code{gdb}
14692program specified there.
14693
14694To build @code{gdb} in a separate directory, run @code{configure}
14695with the @samp{--srcdir} option to specify where to find the source.
14696(You also need to specify a path to find @code{configure}
14697itself from your working directory. If the path to @code{configure}
14698would be the same as the argument to @samp{--srcdir}, you can leave out
14699the @samp{--srcdir} option; it is assumed.)
14700
5d161b24 14701For example, with version @value{GDBVN}, you can build @value{GDBN} in a
c906108c
SS
14702separate directory for a Sun 4 like this:
14703
14704@example
14705@group
14706cd gdb-@value{GDBVN}
14707mkdir ../gdb-sun4
14708cd ../gdb-sun4
14709../gdb-@value{GDBVN}/configure sun4
14710make
14711@end group
14712@end example
14713
14714When @code{configure} builds a configuration using a remote source
14715directory, it creates a tree for the binaries with the same structure
14716(and using the same names) as the tree under the source directory. In
14717the example, you'd find the Sun 4 library @file{libiberty.a} in the
14718directory @file{gdb-sun4/libiberty}, and @value{GDBN} itself in
14719@file{gdb-sun4/gdb}.
14720
14721One popular reason to build several @value{GDBN} configurations in separate
5d161b24
DB
14722directories is to configure @value{GDBN} for cross-compiling (where
14723@value{GDBN} runs on one machine---the @dfn{host}---while debugging
14724programs that run on another machine---the @dfn{target}).
c906108c
SS
14725You specify a cross-debugging target by
14726giving the @samp{--target=@var{target}} option to @code{configure}.
14727
14728When you run @code{make} to build a program or library, you must run
14729it in a configured directory---whatever directory you were in when you
14730called @code{configure} (or one of its subdirectories).
14731
14732The @code{Makefile} that @code{configure} generates in each source
14733directory also runs recursively. If you type @code{make} in a source
14734directory such as @file{gdb-@value{GDBVN}} (or in a separate configured
14735directory configured with @samp{--srcdir=@var{dirname}/gdb-@value{GDBVN}}), you
14736will build all the required libraries, and then build GDB.
14737
14738When you have multiple hosts or targets configured in separate
14739directories, you can run @code{make} on them in parallel (for example,
14740if they are NFS-mounted on each of the hosts); they will not interfere
14741with each other.
14742
6d2ebf8b 14743@node Config Names
c906108c
SS
14744@section Specifying names for hosts and targets
14745
14746The specifications used for hosts and targets in the @code{configure}
14747script are based on a three-part naming scheme, but some short predefined
14748aliases are also supported. The full naming scheme encodes three pieces
14749of information in the following pattern:
14750
14751@example
14752@var{architecture}-@var{vendor}-@var{os}
14753@end example
14754
14755For example, you can use the alias @code{sun4} as a @var{host} argument,
14756or as the value for @var{target} in a @code{--target=@var{target}}
14757option. The equivalent full name is @samp{sparc-sun-sunos4}.
14758
14759The @code{configure} script accompanying @value{GDBN} does not provide
14760any query facility to list all supported host and target names or
14761aliases. @code{configure} calls the Bourne shell script
14762@code{config.sub} to map abbreviations to full names; you can read the
14763script, if you wish, or you can use it to test your guesses on
14764abbreviations---for example:
14765
14766@smallexample
14767% sh config.sub i386-linux
14768i386-pc-linux-gnu
14769% sh config.sub alpha-linux
14770alpha-unknown-linux-gnu
14771% sh config.sub hp9k700
14772hppa1.1-hp-hpux
14773% sh config.sub sun4
14774sparc-sun-sunos4.1.1
14775% sh config.sub sun3
14776m68k-sun-sunos4.1.1
14777% sh config.sub i986v
14778Invalid configuration `i986v': machine `i986v' not recognized
14779@end smallexample
14780
14781@noindent
14782@code{config.sub} is also distributed in the @value{GDBN} source
14783directory (@file{gdb-@value{GDBVN}}, for version @value{GDBVN}).
14784
6d2ebf8b 14785@node Configure Options
c906108c
SS
14786@section @code{configure} options
14787
14788Here is a summary of the @code{configure} options and arguments that
14789are most often useful for building @value{GDBN}. @code{configure} also has
14790several other options not listed here. @inforef{What Configure
14791Does,,configure.info}, for a full explanation of @code{configure}.
14792
14793@example
14794configure @r{[}--help@r{]}
14795 @r{[}--prefix=@var{dir}@r{]}
14796 @r{[}--exec-prefix=@var{dir}@r{]}
14797 @r{[}--srcdir=@var{dirname}@r{]}
14798 @r{[}--norecursion@r{]} @r{[}--rm@r{]}
14799 @r{[}--target=@var{target}@r{]}
14800 @var{host}
14801@end example
14802
14803@noindent
14804You may introduce options with a single @samp{-} rather than
14805@samp{--} if you prefer; but you may abbreviate option names if you use
14806@samp{--}.
14807
14808@table @code
14809@item --help
14810Display a quick summary of how to invoke @code{configure}.
14811
14812@item --prefix=@var{dir}
14813Configure the source to install programs and files under directory
14814@file{@var{dir}}.
14815
14816@item --exec-prefix=@var{dir}
14817Configure the source to install programs under directory
14818@file{@var{dir}}.
14819
14820@c avoid splitting the warning from the explanation:
14821@need 2000
14822@item --srcdir=@var{dirname}
14823@strong{Warning: using this option requires @sc{gnu} @code{make}, or another
14824@code{make} that implements the @code{VPATH} feature.}@*
14825Use this option to make configurations in directories separate from the
14826@value{GDBN} source directories. Among other things, you can use this to
14827build (or maintain) several configurations simultaneously, in separate
14828directories. @code{configure} writes configuration specific files in
14829the current directory, but arranges for them to use the source in the
14830directory @var{dirname}. @code{configure} creates directories under
14831the working directory in parallel to the source directories below
14832@var{dirname}.
14833
14834@item --norecursion
14835Configure only the directory level where @code{configure} is executed; do not
14836propagate configuration to subdirectories.
14837
14838@item --target=@var{target}
14839Configure @value{GDBN} for cross-debugging programs running on the specified
14840@var{target}. Without this option, @value{GDBN} is configured to debug
14841programs that run on the same machine (@var{host}) as @value{GDBN} itself.
14842
14843There is no convenient way to generate a list of all available targets.
14844
14845@item @var{host} @dots{}
14846Configure @value{GDBN} to run on the specified @var{host}.
14847
14848There is no convenient way to generate a list of all available hosts.
14849@end table
14850
14851There are many other options available as well, but they are generally
14852needed for special purposes only.
5d161b24 14853
6d2ebf8b 14854@node Index
c906108c
SS
14855@unnumbered Index
14856
14857@printindex cp
14858
14859@tex
14860% I think something like @colophon should be in texinfo. In the
14861% meantime:
14862\long\def\colophon{\hbox to0pt{}\vfill
14863\centerline{The body of this manual is set in}
14864\centerline{\fontname\tenrm,}
14865\centerline{with headings in {\bf\fontname\tenbf}}
14866\centerline{and examples in {\tt\fontname\tentt}.}
14867\centerline{{\it\fontname\tenit\/},}
14868\centerline{{\bf\fontname\tenbf}, and}
14869\centerline{{\sl\fontname\tensl\/}}
14870\centerline{are used for emphasis.}\vfill}
14871\page\colophon
14872% Blame: doc@cygnus.com, 1991.
14873@end tex
14874
449f3b6c
AC
14875@c TeX can handle the contents at the start but makeinfo 3.12 can not
14876@ifinfo
c906108c 14877@contents
449f3b6c
AC
14878@end ifinfo
14879@ifhtml
14880@contents
14881@end ifhtml
14882
c906108c 14883@bye