]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blame - gdb/doc/gdb.texinfo
* xstormy16-tdep.c (xstormy16_scan_prologue): Add frameless
[thirdparty/binutils-gdb.git] / gdb / doc / gdb.texinfo
CommitLineData
c906108c 1\input texinfo @c -*-texinfo-*-
b6ba6518 2@c Copyright 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1998,
8a037dd7 3@c 1999, 2000, 2001, 2002
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
8a037dd7
EZ
53Copyright (C) 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1998,@*
54 1999, 2000, 2001, 2002 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
6826cf00
EZ
63(a) The Free Software Foundation's Back-Cover Text is: ``You have
64freedom to copy and modify this GNU Manual, like GNU software. Copies
65published by the Free Software Foundation raise funds for GNU
66development.''
c906108c
SS
67@end ifinfo
68
69@titlepage
70@title Debugging with @value{GDBN}
71@subtitle The @sc{gnu} Source-Level Debugger
c906108c 72@sp 1
c906108c
SS
73@subtitle @value{EDITION} Edition, for @value{GDBN} version @value{GDBVN}
74@subtitle @value{DATE}
9e9c5ae7 75@author Richard Stallman, Roland Pesch, Stan Shebs, et al.
c906108c 76@page
c906108c
SS
77@tex
78{\parskip=0pt
53a5351d 79\hfill (Send bugs and comments on @value{GDBN} to bug-gdb\@gnu.org.)\par
c906108c
SS
80\hfill {\it Debugging with @value{GDBN}}\par
81\hfill \TeX{}info \texinfoversion\par
82}
83@end tex
53a5351d 84
c906108c 85@vskip 0pt plus 1filll
8a037dd7
EZ
86Copyright @copyright{} 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995,
871996, 1998, 1999, 2000, 2001, 2002 Free Software Foundation, Inc.
c906108c 88@sp 2
c906108c
SS
89Published by the Free Software Foundation @*
9059 Temple Place - Suite 330, @*
91Boston, MA 02111-1307 USA @*
6d2ebf8b 92ISBN 1-882114-77-9 @*
e9c75b65
EZ
93
94Permission is granted to copy, distribute and/or modify this document
95under the terms of the GNU Free Documentation License, Version 1.1 or
96any later version published by the Free Software Foundation; with the
959acfd1
EZ
97Invariant Sections being ``Free Software'' and ``Free Software Needs
98Free Documentation'', with the Front-Cover Texts being ``A GNU Manual,''
99and with the Back-Cover Texts as in (a) below.
e9c75b65 100
6826cf00
EZ
101(a) The Free Software Foundation's Back-Cover Text is: ``You have
102freedom to copy and modify this GNU Manual, like GNU software. Copies
103published by the Free Software Foundation raise funds for GNU
104development.''
c906108c
SS
105@end titlepage
106@page
107
b9deaee7 108@ifinfo
6d2ebf8b
SS
109@node Top, Summary, (dir), (dir)
110
c906108c
SS
111@top Debugging with @value{GDBN}
112
113This file describes @value{GDBN}, the @sc{gnu} symbolic debugger.
114
5d161b24 115This is the @value{EDITION} Edition, @value{DATE}, for @value{GDBN} Version
c906108c
SS
116@value{GDBVN}.
117
8a037dd7 118Copyright (C) 1988-2002 Free Software Foundation, Inc.
6d2ebf8b
SS
119
120@menu
121* Summary:: Summary of @value{GDBN}
122* Sample Session:: A sample @value{GDBN} session
123
124* Invocation:: Getting in and out of @value{GDBN}
125* Commands:: @value{GDBN} commands
126* Running:: Running programs under @value{GDBN}
127* Stopping:: Stopping and continuing
128* Stack:: Examining the stack
129* Source:: Examining source files
130* Data:: Examining data
b37052ae 131* Tracepoints:: Debugging remote targets non-intrusively
df0cd8c5 132* Overlays:: Debugging programs that use overlays
6d2ebf8b
SS
133
134* Languages:: Using @value{GDBN} with different languages
135
136* Symbols:: Examining the symbol table
137* Altering:: Altering execution
138* GDB Files:: @value{GDBN} files
139* Targets:: Specifying a debugging target
6b2f586d 140* Remote Debugging:: Debugging remote programs
6d2ebf8b
SS
141* Configurations:: Configuration-specific information
142* Controlling GDB:: Controlling @value{GDBN}
143* Sequences:: Canned sequences of commands
c4555f82 144* TUI:: @value{GDBN} Text User Interface
6d2ebf8b
SS
145* Emacs:: Using @value{GDBN} under @sc{gnu} Emacs
146* Annotations:: @value{GDBN}'s annotation interface.
7162c0ca 147* GDB/MI:: @value{GDBN}'s Machine Interface.
6d2ebf8b
SS
148
149* GDB Bugs:: Reporting bugs in @value{GDBN}
150* Formatting Documentation:: How to format and print @value{GDBN} documentation
151
152* Command Line Editing:: Command Line Editing
153* Using History Interactively:: Using History Interactively
154* Installing GDB:: Installing GDB
eb12ee30 155* Maintenance Commands:: Maintenance Commands
6826cf00 156* GNU Free Documentation License:: The license for this documentation
6d2ebf8b
SS
157* Index:: Index
158@end menu
159
b9deaee7 160@end ifinfo
6d2ebf8b
SS
161
162@c the replication sucks, but this avoids a texinfo 3.12 lameness
163
164@ifhtml
165@node Top
166
167@top Debugging with @value{GDBN}
168
169This file describes @value{GDBN}, the @sc{gnu} symbolic debugger.
170
b37052ae 171This is the @value{EDITION} Edition, @value{DATE}, for @value{GDBN} Version
6d2ebf8b
SS
172@value{GDBVN}.
173
174Copyright (C) 1988-2000 Free Software Foundation, Inc.
175
c906108c
SS
176@menu
177* Summary:: Summary of @value{GDBN}
c906108c 178* Sample Session:: A sample @value{GDBN} session
c906108c
SS
179
180* Invocation:: Getting in and out of @value{GDBN}
181* Commands:: @value{GDBN} commands
182* Running:: Running programs under @value{GDBN}
183* Stopping:: Stopping and continuing
184* Stack:: Examining the stack
185* Source:: Examining source files
186* Data:: Examining data
496e6bc3 187* Tracepoints:: Debugging remote targets non-intrusively
df0cd8c5 188* Overlays:: Debugging programs that use overlays
c906108c 189
7a292a7a 190* Languages:: Using @value{GDBN} with different languages
c906108c
SS
191
192* Symbols:: Examining the symbol table
193* Altering:: Altering execution
194* GDB Files:: @value{GDBN} files
195* Targets:: Specifying a debugging target
6b2f586d 196* Remote Debugging:: Debugging remote programs
104c1213 197* Configurations:: Configuration-specific information
c906108c
SS
198* Controlling GDB:: Controlling @value{GDBN}
199* Sequences:: Canned sequences of commands
496e6bc3 200* TUI:: @value{GDBN} Text User Interface
c906108c 201* Emacs:: Using @value{GDBN} under @sc{gnu} Emacs
6d2ebf8b 202* Annotations:: @value{GDBN}'s annotation interface.
496e6bc3 203* GDB/MI:: @value{GDBN}'s Machine Interface.
c906108c
SS
204
205* GDB Bugs:: Reporting bugs in @value{GDBN}
c906108c 206* Formatting Documentation:: How to format and print @value{GDBN} documentation
c906108c
SS
207
208* Command Line Editing:: Command Line Editing
209* Using History Interactively:: Using History Interactively
210* Installing GDB:: Installing GDB
eb12ee30 211* Maintenance Commands:: Maintenance Commands
6826cf00 212* GNU Free Documentation License:: The license for this documentation
c906108c 213* Index:: Index
c906108c
SS
214@end menu
215
6d2ebf8b
SS
216@end ifhtml
217
449f3b6c
AC
218@c TeX can handle the contents at the start but makeinfo 3.12 can not
219@iftex
220@contents
221@end iftex
222
6d2ebf8b 223@node Summary
c906108c
SS
224@unnumbered Summary of @value{GDBN}
225
226The purpose of a debugger such as @value{GDBN} is to allow you to see what is
227going on ``inside'' another program while it executes---or what another
228program was doing at the moment it crashed.
229
230@value{GDBN} can do four main kinds of things (plus other things in support of
231these) to help you catch bugs in the act:
232
233@itemize @bullet
234@item
235Start your program, specifying anything that might affect its behavior.
236
237@item
238Make your program stop on specified conditions.
239
240@item
241Examine what has happened, when your program has stopped.
242
243@item
244Change things in your program, so you can experiment with correcting the
245effects of one bug and go on to learn about another.
246@end itemize
247
cce74817 248You can use @value{GDBN} to debug programs written in C and C++.
c906108c 249For more information, see @ref{Support,,Supported languages}.
c906108c
SS
250For more information, see @ref{C,,C and C++}.
251
cce74817
JM
252@cindex Chill
253@cindex Modula-2
c906108c 254Support for Modula-2 and Chill is partial. For information on Modula-2,
cce74817 255see @ref{Modula-2,,Modula-2}. For information on Chill, see @ref{Chill}.
c906108c 256
cce74817
JM
257@cindex Pascal
258Debugging Pascal programs which use sets, subranges, file variables, or
259nested functions does not currently work. @value{GDBN} does not support
260entering expressions, printing values, or similar features using Pascal
261syntax.
c906108c 262
c906108c
SS
263@cindex Fortran
264@value{GDBN} can be used to debug programs written in Fortran, although
53a5351d 265it may be necessary to refer to some variables with a trailing
cce74817 266underscore.
c906108c 267
c906108c
SS
268@menu
269* Free Software:: Freely redistributable software
270* Contributors:: Contributors to GDB
271@end menu
272
6d2ebf8b 273@node Free Software
c906108c
SS
274@unnumberedsec Free software
275
5d161b24 276@value{GDBN} is @dfn{free software}, protected by the @sc{gnu}
c906108c
SS
277General Public License
278(GPL). The GPL gives you the freedom to copy or adapt a licensed
279program---but every person getting a copy also gets with it the
280freedom to modify that copy (which means that they must get access to
281the source code), and the freedom to distribute further copies.
282Typical software companies use copyrights to limit your freedoms; the
283Free Software Foundation uses the GPL to preserve these freedoms.
284
285Fundamentally, the General Public License is a license which says that
286you have these freedoms and that you cannot take these freedoms away
287from anyone else.
288
2666264b 289@unnumberedsec Free Software Needs Free Documentation
959acfd1
EZ
290
291The biggest deficiency in the free software community today is not in
292the software---it is the lack of good free documentation that we can
293include with the free software. Many of our most important
294programs do not come with free reference manuals and free introductory
295texts. Documentation is an essential part of any software package;
296when an important free software package does not come with a free
297manual and a free tutorial, that is a major gap. We have many such
298gaps today.
299
300Consider Perl, for instance. The tutorial manuals that people
301normally use are non-free. How did this come about? Because the
302authors of those manuals published them with restrictive terms---no
303copying, no modification, source files not available---which exclude
304them from the free software world.
305
306That wasn't the first time this sort of thing happened, and it was far
307from the last. Many times we have heard a GNU user eagerly describe a
308manual that he is writing, his intended contribution to the community,
309only to learn that he had ruined everything by signing a publication
310contract to make it non-free.
311
312Free documentation, like free software, is a matter of freedom, not
313price. The problem with the non-free manual is not that publishers
314charge a price for printed copies---that in itself is fine. (The Free
315Software Foundation sells printed copies of manuals, too.) The
316problem is the restrictions on the use of the manual. Free manuals
317are available in source code form, and give you permission to copy and
318modify. Non-free manuals do not allow this.
319
320The criteria of freedom for a free manual are roughly the same as for
321free software. Redistribution (including the normal kinds of
322commercial redistribution) must be permitted, so that the manual can
323accompany every copy of the program, both on-line and on paper.
324
325Permission for modification of the technical content is crucial too.
326When people modify the software, adding or changing features, if they
327are conscientious they will change the manual too---so they can
328provide accurate and clear documentation for the modified program. A
329manual that leaves you no choice but to write a new manual to document
330a changed version of the program is not really available to our
331community.
332
333Some kinds of limits on the way modification is handled are
334acceptable. For example, requirements to preserve the original
335author's copyright notice, the distribution terms, or the list of
336authors, are ok. It is also no problem to require modified versions
337to include notice that they were modified. Even entire sections that
338may not be deleted or changed are acceptable, as long as they deal
339with nontechnical topics (like this one). These kinds of restrictions
340are acceptable because they don't obstruct the community's normal use
341of the manual.
342
343However, it must be possible to modify all the @emph{technical}
344content of the manual, and then distribute the result in all the usual
345media, through all the usual channels. Otherwise, the restrictions
346obstruct the use of the manual, it is not free, and we need another
347manual to replace it.
348
349Please spread the word about this issue. Our community continues to
350lose manuals to proprietary publishing. If we spread the word that
351free software needs free reference manuals and free tutorials, perhaps
352the next person who wants to contribute by writing documentation will
353realize, before it is too late, that only free manuals contribute to
354the free software community.
355
356If you are writing documentation, please insist on publishing it under
357the GNU Free Documentation License or another free documentation
358license. Remember that this decision requires your approval---you
359don't have to let the publisher decide. Some commercial publishers
360will use a free license if you insist, but they will not propose the
361option; it is up to you to raise the issue and say firmly that this is
362what you want. If the publisher you are dealing with refuses, please
363try other publishers. If you're not sure whether a proposed license
42584a72 364is free, write to @email{licensing@@gnu.org}.
959acfd1
EZ
365
366You can encourage commercial publishers to sell more free, copylefted
367manuals and tutorials by buying them, and particularly by buying
368copies from the publishers that paid for their writing or for major
369improvements. Meanwhile, try to avoid buying non-free documentation
370at all. Check the distribution terms of a manual before you buy it,
371and insist that whoever seeks your business must respect your freedom.
72c9928d
EZ
372Check the history of the book, and try to reward the publishers that
373have paid or pay the authors to work on it.
959acfd1
EZ
374
375The Free Software Foundation maintains a list of free documentation
376published by other publishers, at
377@url{http://www.fsf.org/doc/other-free-books.html}.
378
6d2ebf8b 379@node Contributors
96a2c332
SS
380@unnumberedsec Contributors to @value{GDBN}
381
382Richard Stallman was the original author of @value{GDBN}, and of many
383other @sc{gnu} programs. Many others have contributed to its
384development. This section attempts to credit major contributors. One
385of the virtues of free software is that everyone is free to contribute
386to it; with regret, we cannot actually acknowledge everyone here. The
387file @file{ChangeLog} in the @value{GDBN} distribution approximates a
c906108c
SS
388blow-by-blow account.
389
390Changes much prior to version 2.0 are lost in the mists of time.
391
392@quotation
393@emph{Plea:} Additions to this section are particularly welcome. If you
394or your friends (or enemies, to be evenhanded) have been unfairly
395omitted from this list, we would like to add your names!
396@end quotation
397
398So that they may not regard their many labors as thankless, we
399particularly thank those who shepherded @value{GDBN} through major
400releases:
b37052ae 401Andrew Cagney (releases 5.0 and 5.1);
c906108c
SS
402Jim Blandy (release 4.18);
403Jason Molenda (release 4.17);
404Stan Shebs (release 4.14);
405Fred Fish (releases 4.16, 4.15, 4.13, 4.12, 4.11, 4.10, and 4.9);
406Stu Grossman and John Gilmore (releases 4.8, 4.7, 4.6, 4.5, and 4.4);
407John Gilmore (releases 4.3, 4.2, 4.1, 4.0, and 3.9);
408Jim Kingdon (releases 3.5, 3.4, and 3.3);
409and Randy Smith (releases 3.2, 3.1, and 3.0).
410
411Richard Stallman, assisted at various times by Peter TerMaat, Chris
412Hanson, and Richard Mlynarik, handled releases through 2.8.
413
b37052ae
EZ
414Michael Tiemann is the author of most of the @sc{gnu} C@t{++} support
415in @value{GDBN}, with significant additional contributions from Per
416Bothner and Daniel Berlin. James Clark wrote the @sc{gnu} C@t{++}
417demangler. Early work on C@t{++} was by Peter TerMaat (who also did
418much general update work leading to release 3.0).
c906108c 419
b37052ae 420@value{GDBN} uses the BFD subroutine library to examine multiple
c906108c
SS
421object-file formats; BFD was a joint project of David V.
422Henkel-Wallace, Rich Pixley, Steve Chamberlain, and John Gilmore.
423
424David Johnson wrote the original COFF support; Pace Willison did
425the original support for encapsulated COFF.
426
96c405b3 427Brent Benson of Harris Computer Systems contributed DWARF2 support.
c906108c
SS
428
429Adam de Boor and Bradley Davis contributed the ISI Optimum V support.
430Per Bothner, Noboyuki Hikichi, and Alessandro Forin contributed MIPS
431support.
432Jean-Daniel Fekete contributed Sun 386i support.
433Chris Hanson improved the HP9000 support.
434Noboyuki Hikichi and Tomoyuki Hasei contributed Sony/News OS 3 support.
435David Johnson contributed Encore Umax support.
436Jyrki Kuoppala contributed Altos 3068 support.
437Jeff Law contributed HP PA and SOM support.
438Keith Packard contributed NS32K support.
439Doug Rabson contributed Acorn Risc Machine support.
440Bob Rusk contributed Harris Nighthawk CX-UX support.
441Chris Smith contributed Convex support (and Fortran debugging).
442Jonathan Stone contributed Pyramid support.
443Michael Tiemann contributed SPARC support.
444Tim Tucker contributed support for the Gould NP1 and Gould Powernode.
445Pace Willison contributed Intel 386 support.
446Jay Vosburgh contributed Symmetry support.
447
448Andreas Schwab contributed M68K Linux support.
449
450Rich Schaefer and Peter Schauer helped with support of SunOS shared
451libraries.
452
453Jay Fenlason and Roland McGrath ensured that @value{GDBN} and GAS agree
454about several machine instruction sets.
455
456Patrick Duval, Ted Goldstein, Vikram Koka and Glenn Engel helped develop
457remote debugging. Intel Corporation, Wind River Systems, AMD, and ARM
458contributed remote debugging modules for the i960, VxWorks, A29K UDI,
459and RDI targets, respectively.
460
461Brian Fox is the author of the readline libraries providing
462command-line editing and command history.
463
7a292a7a
SS
464Andrew Beers of SUNY Buffalo wrote the language-switching code, the
465Modula-2 support, and contributed the Languages chapter of this manual.
c906108c 466
5d161b24 467Fred Fish wrote most of the support for Unix System Vr4.
b37052ae 468He also enhanced the command-completion support to cover C@t{++} overloaded
c906108c 469symbols.
c906108c
SS
470
471Hitachi America, Ltd. sponsored the support for H8/300, H8/500, and
472Super-H processors.
473
474NEC sponsored the support for the v850, Vr4xxx, and Vr5xxx processors.
475
476Mitsubishi sponsored the support for D10V, D30V, and M32R/D processors.
477
478Toshiba sponsored the support for the TX39 Mips processor.
479
480Matsushita sponsored the support for the MN10200 and MN10300 processors.
481
96a2c332 482Fujitsu sponsored the support for SPARClite and FR30 processors.
c906108c
SS
483
484Kung Hsu, Jeff Law, and Rick Sladkey added support for hardware
485watchpoints.
486
487Michael Snyder added support for tracepoints.
488
489Stu Grossman wrote gdbserver.
490
491Jim Kingdon, Peter Schauer, Ian Taylor, and Stu Grossman made
96a2c332 492nearly innumerable bug fixes and cleanups throughout @value{GDBN}.
c906108c
SS
493
494The following people at the Hewlett-Packard Company contributed
495support for the PA-RISC 2.0 architecture, HP-UX 10.20, 10.30, and 11.0
b37052ae 496(narrow mode), HP's implementation of kernel threads, HP's aC@t{++}
c906108c
SS
497compiler, and the terminal user interface: Ben Krepp, Richard Title,
498John Bishop, Susan Macchia, Kathy Mann, Satish Pai, India Paul, Steve
499Rehrauer, and Elena Zannoni. Kim Haase provided HP-specific
500information in this manual.
501
b37052ae
EZ
502DJ Delorie ported @value{GDBN} to MS-DOS, for the DJGPP project.
503Robert Hoehne made significant contributions to the DJGPP port.
504
96a2c332
SS
505Cygnus Solutions has sponsored @value{GDBN} maintenance and much of its
506development since 1991. Cygnus engineers who have worked on @value{GDBN}
2df3850c
JM
507fulltime include Mark Alexander, Jim Blandy, Per Bothner, Kevin
508Buettner, Edith Epstein, Chris Faylor, Fred Fish, Martin Hunt, Jim
509Ingham, John Gilmore, Stu Grossman, Kung Hsu, Jim Kingdon, John Metzler,
510Fernando Nasser, Geoffrey Noer, Dawn Perchik, Rich Pixley, Zdenek
511Radouch, Keith Seitz, Stan Shebs, David Taylor, and Elena Zannoni. In
512addition, Dave Brolley, Ian Carmichael, Steve Chamberlain, Nick Clifton,
513JT Conklin, Stan Cox, DJ Delorie, Ulrich Drepper, Frank Eigler, Doug
514Evans, Sean Fagan, David Henkel-Wallace, Richard Henderson, Jeff
515Holcomb, Jeff Law, Jim Lemke, Tom Lord, Bob Manson, Michael Meissner,
516Jason Merrill, Catherine Moore, Drew Moseley, Ken Raeburn, Gavin
517Romig-Koch, Rob Savoye, Jamie Smith, Mike Stump, Ian Taylor, Angela
518Thomas, Michael Tiemann, Tom Tromey, Ron Unrau, Jim Wilson, and David
519Zuhn have made contributions both large and small.
c906108c
SS
520
521
6d2ebf8b 522@node Sample Session
c906108c
SS
523@chapter A Sample @value{GDBN} Session
524
525You can use this manual at your leisure to read all about @value{GDBN}.
526However, a handful of commands are enough to get started using the
527debugger. This chapter illustrates those commands.
528
529@iftex
530In this sample session, we emphasize user input like this: @b{input},
531to make it easier to pick out from the surrounding output.
532@end iftex
533
534@c FIXME: this example may not be appropriate for some configs, where
535@c FIXME...primary interest is in remote use.
536
537One of the preliminary versions of @sc{gnu} @code{m4} (a generic macro
538processor) exhibits the following bug: sometimes, when we change its
539quote strings from the default, the commands used to capture one macro
540definition within another stop working. In the following short @code{m4}
541session, we define a macro @code{foo} which expands to @code{0000}; we
542then use the @code{m4} built-in @code{defn} to define @code{bar} as the
543same thing. However, when we change the open quote string to
544@code{<QUOTE>} and the close quote string to @code{<UNQUOTE>}, the same
545procedure fails to define a new synonym @code{baz}:
546
547@smallexample
548$ @b{cd gnu/m4}
549$ @b{./m4}
550@b{define(foo,0000)}
551
552@b{foo}
5530000
554@b{define(bar,defn(`foo'))}
555
556@b{bar}
5570000
558@b{changequote(<QUOTE>,<UNQUOTE>)}
559
560@b{define(baz,defn(<QUOTE>foo<UNQUOTE>))}
561@b{baz}
562@b{C-d}
563m4: End of input: 0: fatal error: EOF in string
564@end smallexample
565
566@noindent
567Let us use @value{GDBN} to try to see what is going on.
568
c906108c
SS
569@smallexample
570$ @b{@value{GDBP} m4}
571@c FIXME: this falsifies the exact text played out, to permit smallbook
572@c FIXME... format to come out better.
573@value{GDBN} is free software and you are welcome to distribute copies
5d161b24 574 of it under certain conditions; type "show copying" to see
c906108c 575 the conditions.
5d161b24 576There is absolutely no warranty for @value{GDBN}; type "show warranty"
c906108c
SS
577 for details.
578
579@value{GDBN} @value{GDBVN}, Copyright 1999 Free Software Foundation, Inc...
580(@value{GDBP})
581@end smallexample
c906108c
SS
582
583@noindent
584@value{GDBN} reads only enough symbol data to know where to find the
585rest when needed; as a result, the first prompt comes up very quickly.
586We now tell @value{GDBN} to use a narrower display width than usual, so
587that examples fit in this manual.
588
589@smallexample
590(@value{GDBP}) @b{set width 70}
591@end smallexample
592
593@noindent
594We need to see how the @code{m4} built-in @code{changequote} works.
595Having looked at the source, we know the relevant subroutine is
596@code{m4_changequote}, so we set a breakpoint there with the @value{GDBN}
597@code{break} command.
598
599@smallexample
600(@value{GDBP}) @b{break m4_changequote}
601Breakpoint 1 at 0x62f4: file builtin.c, line 879.
602@end smallexample
603
604@noindent
605Using the @code{run} command, we start @code{m4} running under @value{GDBN}
606control; as long as control does not reach the @code{m4_changequote}
607subroutine, the program runs as usual:
608
609@smallexample
610(@value{GDBP}) @b{run}
611Starting program: /work/Editorial/gdb/gnu/m4/m4
612@b{define(foo,0000)}
613
614@b{foo}
6150000
616@end smallexample
617
618@noindent
619To trigger the breakpoint, we call @code{changequote}. @value{GDBN}
620suspends execution of @code{m4}, displaying information about the
621context where it stops.
622
623@smallexample
624@b{changequote(<QUOTE>,<UNQUOTE>)}
625
5d161b24 626Breakpoint 1, m4_changequote (argc=3, argv=0x33c70)
c906108c
SS
627 at builtin.c:879
628879 if (bad_argc(TOKEN_DATA_TEXT(argv[0]),argc,1,3))
629@end smallexample
630
631@noindent
632Now we use the command @code{n} (@code{next}) to advance execution to
633the next line of the current function.
634
635@smallexample
636(@value{GDBP}) @b{n}
637882 set_quotes((argc >= 2) ? TOKEN_DATA_TEXT(argv[1])\
638 : nil,
639@end smallexample
640
641@noindent
642@code{set_quotes} looks like a promising subroutine. We can go into it
643by using the command @code{s} (@code{step}) instead of @code{next}.
644@code{step} goes to the next line to be executed in @emph{any}
645subroutine, so it steps into @code{set_quotes}.
646
647@smallexample
648(@value{GDBP}) @b{s}
649set_quotes (lq=0x34c78 "<QUOTE>", rq=0x34c88 "<UNQUOTE>")
650 at input.c:530
651530 if (lquote != def_lquote)
652@end smallexample
653
654@noindent
655The display that shows the subroutine where @code{m4} is now
656suspended (and its arguments) is called a stack frame display. It
657shows a summary of the stack. We can use the @code{backtrace}
658command (which can also be spelled @code{bt}), to see where we are
659in the stack as a whole: the @code{backtrace} command displays a
660stack frame for each active subroutine.
661
662@smallexample
663(@value{GDBP}) @b{bt}
664#0 set_quotes (lq=0x34c78 "<QUOTE>", rq=0x34c88 "<UNQUOTE>")
665 at input.c:530
5d161b24 666#1 0x6344 in m4_changequote (argc=3, argv=0x33c70)
c906108c
SS
667 at builtin.c:882
668#2 0x8174 in expand_macro (sym=0x33320) at macro.c:242
669#3 0x7a88 in expand_token (obs=0x0, t=209696, td=0xf7fffa30)
670 at macro.c:71
671#4 0x79dc in expand_input () at macro.c:40
672#5 0x2930 in main (argc=0, argv=0xf7fffb20) at m4.c:195
673@end smallexample
674
675@noindent
676We step through a few more lines to see what happens. The first two
677times, we can use @samp{s}; the next two times we use @code{n} to avoid
678falling into the @code{xstrdup} subroutine.
679
680@smallexample
681(@value{GDBP}) @b{s}
6820x3b5c 532 if (rquote != def_rquote)
683(@value{GDBP}) @b{s}
6840x3b80 535 lquote = (lq == nil || *lq == '\0') ? \
685def_lquote : xstrdup(lq);
686(@value{GDBP}) @b{n}
687536 rquote = (rq == nil || *rq == '\0') ? def_rquote\
688 : xstrdup(rq);
689(@value{GDBP}) @b{n}
690538 len_lquote = strlen(rquote);
691@end smallexample
692
693@noindent
694The last line displayed looks a little odd; we can examine the variables
695@code{lquote} and @code{rquote} to see if they are in fact the new left
696and right quotes we specified. We use the command @code{p}
697(@code{print}) to see their values.
698
699@smallexample
700(@value{GDBP}) @b{p lquote}
701$1 = 0x35d40 "<QUOTE>"
702(@value{GDBP}) @b{p rquote}
703$2 = 0x35d50 "<UNQUOTE>"
704@end smallexample
705
706@noindent
707@code{lquote} and @code{rquote} are indeed the new left and right quotes.
708To look at some context, we can display ten lines of source
709surrounding the current line with the @code{l} (@code{list}) command.
710
711@smallexample
712(@value{GDBP}) @b{l}
713533 xfree(rquote);
714534
715535 lquote = (lq == nil || *lq == '\0') ? def_lquote\
716 : xstrdup (lq);
717536 rquote = (rq == nil || *rq == '\0') ? def_rquote\
718 : xstrdup (rq);
719537
720538 len_lquote = strlen(rquote);
721539 len_rquote = strlen(lquote);
722540 @}
723541
724542 void
725@end smallexample
726
727@noindent
728Let us step past the two lines that set @code{len_lquote} and
729@code{len_rquote}, and then examine the values of those variables.
730
731@smallexample
732(@value{GDBP}) @b{n}
733539 len_rquote = strlen(lquote);
734(@value{GDBP}) @b{n}
735540 @}
736(@value{GDBP}) @b{p len_lquote}
737$3 = 9
738(@value{GDBP}) @b{p len_rquote}
739$4 = 7
740@end smallexample
741
742@noindent
743That certainly looks wrong, assuming @code{len_lquote} and
744@code{len_rquote} are meant to be the lengths of @code{lquote} and
745@code{rquote} respectively. We can set them to better values using
746the @code{p} command, since it can print the value of
747any expression---and that expression can include subroutine calls and
748assignments.
749
750@smallexample
751(@value{GDBP}) @b{p len_lquote=strlen(lquote)}
752$5 = 7
753(@value{GDBP}) @b{p len_rquote=strlen(rquote)}
754$6 = 9
755@end smallexample
756
757@noindent
758Is that enough to fix the problem of using the new quotes with the
759@code{m4} built-in @code{defn}? We can allow @code{m4} to continue
760executing with the @code{c} (@code{continue}) command, and then try the
761example that caused trouble initially:
762
763@smallexample
764(@value{GDBP}) @b{c}
765Continuing.
766
767@b{define(baz,defn(<QUOTE>foo<UNQUOTE>))}
768
769baz
7700000
771@end smallexample
772
773@noindent
774Success! The new quotes now work just as well as the default ones. The
775problem seems to have been just the two typos defining the wrong
776lengths. We allow @code{m4} exit by giving it an EOF as input:
777
778@smallexample
779@b{C-d}
780Program exited normally.
781@end smallexample
782
783@noindent
784The message @samp{Program exited normally.} is from @value{GDBN}; it
785indicates @code{m4} has finished executing. We can end our @value{GDBN}
786session with the @value{GDBN} @code{quit} command.
787
788@smallexample
789(@value{GDBP}) @b{quit}
790@end smallexample
c906108c 791
6d2ebf8b 792@node Invocation
c906108c
SS
793@chapter Getting In and Out of @value{GDBN}
794
795This chapter discusses how to start @value{GDBN}, and how to get out of it.
5d161b24 796The essentials are:
c906108c 797@itemize @bullet
5d161b24 798@item
53a5351d 799type @samp{@value{GDBP}} to start @value{GDBN}.
5d161b24 800@item
c906108c
SS
801type @kbd{quit} or @kbd{C-d} to exit.
802@end itemize
803
804@menu
805* Invoking GDB:: How to start @value{GDBN}
806* Quitting GDB:: How to quit @value{GDBN}
807* Shell Commands:: How to use shell commands inside @value{GDBN}
808@end menu
809
6d2ebf8b 810@node Invoking GDB
c906108c
SS
811@section Invoking @value{GDBN}
812
c906108c
SS
813Invoke @value{GDBN} by running the program @code{@value{GDBP}}. Once started,
814@value{GDBN} reads commands from the terminal until you tell it to exit.
815
816You can also run @code{@value{GDBP}} with a variety of arguments and options,
817to specify more of your debugging environment at the outset.
818
c906108c
SS
819The command-line options described here are designed
820to cover a variety of situations; in some environments, some of these
5d161b24 821options may effectively be unavailable.
c906108c
SS
822
823The most usual way to start @value{GDBN} is with one argument,
824specifying an executable program:
825
826@example
827@value{GDBP} @var{program}
828@end example
829
c906108c
SS
830@noindent
831You can also start with both an executable program and a core file
832specified:
833
834@example
835@value{GDBP} @var{program} @var{core}
836@end example
837
838You can, instead, specify a process ID as a second argument, if you want
839to debug a running process:
840
841@example
842@value{GDBP} @var{program} 1234
843@end example
844
845@noindent
846would attach @value{GDBN} to process @code{1234} (unless you also have a file
847named @file{1234}; @value{GDBN} does check for a core file first).
848
c906108c 849Taking advantage of the second command-line argument requires a fairly
2df3850c
JM
850complete operating system; when you use @value{GDBN} as a remote
851debugger attached to a bare board, there may not be any notion of
852``process'', and there is often no way to get a core dump. @value{GDBN}
853will warn you if it is unable to attach or to read core dumps.
c906108c 854
aa26fa3a
TT
855You can optionally have @code{@value{GDBP}} pass any arguments after the
856executable file to the inferior using @code{--args}. This option stops
857option processing.
858@example
859gdb --args gcc -O2 -c foo.c
860@end example
861This will cause @code{@value{GDBP}} to debug @code{gcc}, and to set
862@code{gcc}'s command-line arguments (@pxref{Arguments}) to @samp{-O2 -c foo.c}.
863
96a2c332 864You can run @code{@value{GDBP}} without printing the front material, which describes
c906108c
SS
865@value{GDBN}'s non-warranty, by specifying @code{-silent}:
866
867@smallexample
868@value{GDBP} -silent
869@end smallexample
870
871@noindent
872You can further control how @value{GDBN} starts up by using command-line
873options. @value{GDBN} itself can remind you of the options available.
874
875@noindent
876Type
877
878@example
879@value{GDBP} -help
880@end example
881
882@noindent
883to display all available options and briefly describe their use
884(@samp{@value{GDBP} -h} is a shorter equivalent).
885
886All options and command line arguments you give are processed
887in sequential order. The order makes a difference when the
888@samp{-x} option is used.
889
890
891@menu
c906108c
SS
892* File Options:: Choosing files
893* Mode Options:: Choosing modes
894@end menu
895
6d2ebf8b 896@node File Options
c906108c
SS
897@subsection Choosing files
898
2df3850c 899When @value{GDBN} starts, it reads any arguments other than options as
c906108c
SS
900specifying an executable file and core file (or process ID). This is
901the same as if the arguments were specified by the @samp{-se} and
19837790
MS
902@samp{-c} (or @samp{-p} options respectively. (@value{GDBN} reads the
903first argument that does not have an associated option flag as
904equivalent to the @samp{-se} option followed by that argument; and the
905second argument that does not have an associated option flag, if any, as
906equivalent to the @samp{-c}/@samp{-p} option followed by that argument.)
907If the second argument begins with a decimal digit, @value{GDBN} will
908first attempt to attach to it as a process, and if that fails, attempt
909to open it as a corefile. If you have a corefile whose name begins with
910a digit, you can prevent @value{GDBN} from treating it as a pid by
79f12247 911prefixing it with @file{./}, eg. @file{./12345}.
7a292a7a
SS
912
913If @value{GDBN} has not been configured to included core file support,
914such as for most embedded targets, then it will complain about a second
915argument and ignore it.
c906108c
SS
916
917Many options have both long and short forms; both are shown in the
918following list. @value{GDBN} also recognizes the long forms if you truncate
919them, so long as enough of the option is present to be unambiguous.
920(If you prefer, you can flag option arguments with @samp{--} rather
921than @samp{-}, though we illustrate the more usual convention.)
922
d700128c
EZ
923@c NOTE: the @cindex entries here use double dashes ON PURPOSE. This
924@c way, both those who look for -foo and --foo in the index, will find
925@c it.
926
c906108c
SS
927@table @code
928@item -symbols @var{file}
929@itemx -s @var{file}
d700128c
EZ
930@cindex @code{--symbols}
931@cindex @code{-s}
c906108c
SS
932Read symbol table from file @var{file}.
933
934@item -exec @var{file}
935@itemx -e @var{file}
d700128c
EZ
936@cindex @code{--exec}
937@cindex @code{-e}
7a292a7a
SS
938Use file @var{file} as the executable file to execute when appropriate,
939and for examining pure data in conjunction with a core dump.
c906108c
SS
940
941@item -se @var{file}
d700128c 942@cindex @code{--se}
c906108c
SS
943Read symbol table from file @var{file} and use it as the executable
944file.
945
c906108c
SS
946@item -core @var{file}
947@itemx -c @var{file}
d700128c
EZ
948@cindex @code{--core}
949@cindex @code{-c}
19837790 950Use file @var{file} as a core dump to examine.
c906108c
SS
951
952@item -c @var{number}
19837790
MS
953@item -pid @var{number}
954@itemx -p @var{number}
955@cindex @code{--pid}
956@cindex @code{-p}
957Connect to process ID @var{number}, as with the @code{attach} command.
958If there is no such process, @value{GDBN} will attempt to open a core
959file named @var{number}.
c906108c
SS
960
961@item -command @var{file}
962@itemx -x @var{file}
d700128c
EZ
963@cindex @code{--command}
964@cindex @code{-x}
c906108c
SS
965Execute @value{GDBN} commands from file @var{file}. @xref{Command
966Files,, Command files}.
967
968@item -directory @var{directory}
969@itemx -d @var{directory}
d700128c
EZ
970@cindex @code{--directory}
971@cindex @code{-d}
c906108c
SS
972Add @var{directory} to the path to search for source files.
973
c906108c
SS
974@item -m
975@itemx -mapped
d700128c
EZ
976@cindex @code{--mapped}
977@cindex @code{-m}
c906108c
SS
978@emph{Warning: this option depends on operating system facilities that are not
979supported on all systems.}@*
980If memory-mapped files are available on your system through the @code{mmap}
5d161b24 981system call, you can use this option
c906108c
SS
982to have @value{GDBN} write the symbols from your
983program into a reusable file in the current directory. If the program you are debugging is
96a2c332 984called @file{/tmp/fred}, the mapped symbol file is @file{/tmp/fred.syms}.
c906108c
SS
985Future @value{GDBN} debugging sessions notice the presence of this file,
986and can quickly map in symbol information from it, rather than reading
987the symbol table from the executable program.
988
989The @file{.syms} file is specific to the host machine where @value{GDBN}
990is run. It holds an exact image of the internal @value{GDBN} symbol
991table. It cannot be shared across multiple host platforms.
c906108c 992
c906108c
SS
993@item -r
994@itemx -readnow
d700128c
EZ
995@cindex @code{--readnow}
996@cindex @code{-r}
c906108c
SS
997Read each symbol file's entire symbol table immediately, rather than
998the default, which is to read it incrementally as it is needed.
999This makes startup slower, but makes future operations faster.
53a5351d 1000
c906108c
SS
1001@end table
1002
2df3850c 1003You typically combine the @code{-mapped} and @code{-readnow} options in
c906108c 1004order to build a @file{.syms} file that contains complete symbol
2df3850c
JM
1005information. (@xref{Files,,Commands to specify files}, for information
1006on @file{.syms} files.) A simple @value{GDBN} invocation to do nothing
1007but build a @file{.syms} file for future use is:
c906108c
SS
1008
1009@example
2df3850c 1010gdb -batch -nx -mapped -readnow programname
c906108c 1011@end example
c906108c 1012
6d2ebf8b 1013@node Mode Options
c906108c
SS
1014@subsection Choosing modes
1015
1016You can run @value{GDBN} in various alternative modes---for example, in
1017batch mode or quiet mode.
1018
1019@table @code
1020@item -nx
1021@itemx -n
d700128c
EZ
1022@cindex @code{--nx}
1023@cindex @code{-n}
96565e91 1024Do not execute commands found in any initialization files. Normally,
2df3850c
JM
1025@value{GDBN} executes the commands in these files after all the command
1026options and arguments have been processed. @xref{Command Files,,Command
1027files}.
c906108c
SS
1028
1029@item -quiet
d700128c 1030@itemx -silent
c906108c 1031@itemx -q
d700128c
EZ
1032@cindex @code{--quiet}
1033@cindex @code{--silent}
1034@cindex @code{-q}
c906108c
SS
1035``Quiet''. Do not print the introductory and copyright messages. These
1036messages are also suppressed in batch mode.
1037
1038@item -batch
d700128c 1039@cindex @code{--batch}
c906108c
SS
1040Run in batch mode. Exit with status @code{0} after processing all the
1041command files specified with @samp{-x} (and all commands from
1042initialization files, if not inhibited with @samp{-n}). Exit with
1043nonzero status if an error occurs in executing the @value{GDBN} commands
1044in the command files.
1045
2df3850c
JM
1046Batch mode may be useful for running @value{GDBN} as a filter, for
1047example to download and run a program on another computer; in order to
1048make this more useful, the message
c906108c
SS
1049
1050@example
1051Program exited normally.
1052@end example
1053
1054@noindent
2df3850c
JM
1055(which is ordinarily issued whenever a program running under
1056@value{GDBN} control terminates) is not issued when running in batch
1057mode.
1058
1059@item -nowindows
1060@itemx -nw
d700128c
EZ
1061@cindex @code{--nowindows}
1062@cindex @code{-nw}
2df3850c 1063``No windows''. If @value{GDBN} comes with a graphical user interface
96a2c332 1064(GUI) built in, then this option tells @value{GDBN} to only use the command-line
2df3850c
JM
1065interface. If no GUI is available, this option has no effect.
1066
1067@item -windows
1068@itemx -w
d700128c
EZ
1069@cindex @code{--windows}
1070@cindex @code{-w}
2df3850c
JM
1071If @value{GDBN} includes a GUI, then this option requires it to be
1072used if possible.
c906108c
SS
1073
1074@item -cd @var{directory}
d700128c 1075@cindex @code{--cd}
c906108c
SS
1076Run @value{GDBN} using @var{directory} as its working directory,
1077instead of the current directory.
1078
c906108c
SS
1079@item -fullname
1080@itemx -f
d700128c
EZ
1081@cindex @code{--fullname}
1082@cindex @code{-f}
7a292a7a
SS
1083@sc{gnu} Emacs sets this option when it runs @value{GDBN} as a
1084subprocess. It tells @value{GDBN} to output the full file name and line
1085number in a standard, recognizable fashion each time a stack frame is
1086displayed (which includes each time your program stops). This
1087recognizable format looks like two @samp{\032} characters, followed by
1088the file name, line number and character position separated by colons,
1089and a newline. The Emacs-to-@value{GDBN} interface program uses the two
1090@samp{\032} characters as a signal to display the source code for the
1091frame.
c906108c 1092
d700128c
EZ
1093@item -epoch
1094@cindex @code{--epoch}
1095The Epoch Emacs-@value{GDBN} interface sets this option when it runs
1096@value{GDBN} as a subprocess. It tells @value{GDBN} to modify its print
1097routines so as to allow Epoch to display values of expressions in a
1098separate window.
1099
1100@item -annotate @var{level}
1101@cindex @code{--annotate}
1102This option sets the @dfn{annotation level} inside @value{GDBN}. Its
1103effect is identical to using @samp{set annotate @var{level}}
1104(@pxref{Annotations}).
1105Annotation level controls how much information does @value{GDBN} print
1106together with its prompt, values of expressions, source lines, and other
1107types of output. Level 0 is the normal, level 1 is for use when
1108@value{GDBN} is run as a subprocess of @sc{gnu} Emacs, level 2 is the
1109maximum annotation suitable for programs that control @value{GDBN}.
1110
1111@item -async
1112@cindex @code{--async}
1113Use the asynchronous event loop for the command-line interface.
1114@value{GDBN} processes all events, such as user keyboard input, via a
1115special event loop. This allows @value{GDBN} to accept and process user
1116commands in parallel with the debugged process being
1117run@footnote{@value{GDBN} built with @sc{djgpp} tools for
1118MS-DOS/MS-Windows supports this mode of operation, but the event loop is
1119suspended when the debuggee runs.}, so you don't need to wait for
1120control to return to @value{GDBN} before you type the next command.
b37052ae 1121(@emph{Note:} as of version 5.1, the target side of the asynchronous
d700128c
EZ
1122operation is not yet in place, so @samp{-async} does not work fully
1123yet.)
1124@c FIXME: when the target side of the event loop is done, the above NOTE
1125@c should be removed.
1126
1127When the standard input is connected to a terminal device, @value{GDBN}
1128uses the asynchronous event loop by default, unless disabled by the
1129@samp{-noasync} option.
1130
1131@item -noasync
1132@cindex @code{--noasync}
1133Disable the asynchronous event loop for the command-line interface.
1134
aa26fa3a
TT
1135@item --args
1136@cindex @code{--args}
1137Change interpretation of command line so that arguments following the
1138executable file are passed as command line arguments to the inferior.
1139This option stops option processing.
1140
2df3850c
JM
1141@item -baud @var{bps}
1142@itemx -b @var{bps}
d700128c
EZ
1143@cindex @code{--baud}
1144@cindex @code{-b}
c906108c
SS
1145Set the line speed (baud rate or bits per second) of any serial
1146interface used by @value{GDBN} for remote debugging.
c906108c
SS
1147
1148@item -tty @var{device}
d700128c
EZ
1149@itemx -t @var{device}
1150@cindex @code{--tty}
1151@cindex @code{-t}
c906108c
SS
1152Run using @var{device} for your program's standard input and output.
1153@c FIXME: kingdon thinks there is more to -tty. Investigate.
c906108c 1154
53a5351d 1155@c resolve the situation of these eventually
c4555f82
SC
1156@item -tui
1157@cindex @code{--tui}
1158Activate the Terminal User Interface when starting.
1159The Terminal User Interface manages several text windows on the terminal,
1160showing source, assembly, registers and @value{GDBN} command outputs
1161(@pxref{TUI, ,@value{GDBN} Text User Interface}).
1162Do not use this option if you run @value{GDBN} from Emacs
1163(@pxref{Emacs, ,Using @value{GDBN} under @sc{gnu} Emacs}).
53a5351d
JM
1164
1165@c @item -xdb
d700128c 1166@c @cindex @code{--xdb}
53a5351d
JM
1167@c Run in XDB compatibility mode, allowing the use of certain XDB commands.
1168@c For information, see the file @file{xdb_trans.html}, which is usually
1169@c installed in the directory @code{/opt/langtools/wdb/doc} on HP-UX
1170@c systems.
1171
d700128c
EZ
1172@item -interpreter @var{interp}
1173@cindex @code{--interpreter}
1174Use the interpreter @var{interp} for interface with the controlling
1175program or device. This option is meant to be set by programs which
94bbb2c0
AC
1176communicate with @value{GDBN} using it as a back end.
1177
1178@samp{--interpreter=mi} (or @samp{--interpreter=mi1}) causes
1179@value{GDBN} to use the @dfn{gdb/mi interface} (@pxref{GDB/MI, , The
1180@sc{gdb/mi} Interface}). The older @sc{gdb/mi} interface, included in
1181@value{GDBN} version 5.0 can be selected with @samp{--interpreter=mi0}.
d700128c
EZ
1182
1183@item -write
1184@cindex @code{--write}
1185Open the executable and core files for both reading and writing. This
1186is equivalent to the @samp{set write on} command inside @value{GDBN}
1187(@pxref{Patching}).
1188
1189@item -statistics
1190@cindex @code{--statistics}
1191This option causes @value{GDBN} to print statistics about time and
1192memory usage after it completes each command and returns to the prompt.
1193
1194@item -version
1195@cindex @code{--version}
1196This option causes @value{GDBN} to print its version number and
1197no-warranty blurb, and exit.
1198
c906108c
SS
1199@end table
1200
6d2ebf8b 1201@node Quitting GDB
c906108c
SS
1202@section Quitting @value{GDBN}
1203@cindex exiting @value{GDBN}
1204@cindex leaving @value{GDBN}
1205
1206@table @code
1207@kindex quit @r{[}@var{expression}@r{]}
41afff9a 1208@kindex q @r{(@code{quit})}
96a2c332
SS
1209@item quit @r{[}@var{expression}@r{]}
1210@itemx q
1211To exit @value{GDBN}, use the @code{quit} command (abbreviated
1212@code{q}), or type an end-of-file character (usually @kbd{C-d}). If you
1213do not supply @var{expression}, @value{GDBN} will terminate normally;
1214otherwise it will terminate using the result of @var{expression} as the
1215error code.
c906108c
SS
1216@end table
1217
1218@cindex interrupt
1219An interrupt (often @kbd{C-c}) does not exit from @value{GDBN}, but rather
1220terminates the action of any @value{GDBN} command that is in progress and
1221returns to @value{GDBN} command level. It is safe to type the interrupt
1222character at any time because @value{GDBN} does not allow it to take effect
1223until a time when it is safe.
1224
c906108c
SS
1225If you have been using @value{GDBN} to control an attached process or
1226device, you can release it with the @code{detach} command
1227(@pxref{Attach, ,Debugging an already-running process}).
c906108c 1228
6d2ebf8b 1229@node Shell Commands
c906108c
SS
1230@section Shell commands
1231
1232If you need to execute occasional shell commands during your
1233debugging session, there is no need to leave or suspend @value{GDBN}; you can
1234just use the @code{shell} command.
1235
1236@table @code
1237@kindex shell
1238@cindex shell escape
1239@item shell @var{command string}
1240Invoke a standard shell to execute @var{command string}.
c906108c 1241If it exists, the environment variable @code{SHELL} determines which
d4f3574e
SS
1242shell to run. Otherwise @value{GDBN} uses the default shell
1243(@file{/bin/sh} on Unix systems, @file{COMMAND.COM} on MS-DOS, etc.).
c906108c
SS
1244@end table
1245
1246The utility @code{make} is often needed in development environments.
1247You do not have to use the @code{shell} command for this purpose in
1248@value{GDBN}:
1249
1250@table @code
1251@kindex make
1252@cindex calling make
1253@item make @var{make-args}
1254Execute the @code{make} program with the specified
1255arguments. This is equivalent to @samp{shell make @var{make-args}}.
1256@end table
1257
6d2ebf8b 1258@node Commands
c906108c
SS
1259@chapter @value{GDBN} Commands
1260
1261You can abbreviate a @value{GDBN} command to the first few letters of the command
1262name, if that abbreviation is unambiguous; and you can repeat certain
1263@value{GDBN} commands by typing just @key{RET}. You can also use the @key{TAB}
1264key to get @value{GDBN} to fill out the rest of a word in a command (or to
1265show you the alternatives available, if there is more than one possibility).
1266
1267@menu
1268* Command Syntax:: How to give commands to @value{GDBN}
1269* Completion:: Command completion
1270* Help:: How to ask @value{GDBN} for help
1271@end menu
1272
6d2ebf8b 1273@node Command Syntax
c906108c
SS
1274@section Command syntax
1275
1276A @value{GDBN} command is a single line of input. There is no limit on
1277how long it can be. It starts with a command name, which is followed by
1278arguments whose meaning depends on the command name. For example, the
1279command @code{step} accepts an argument which is the number of times to
1280step, as in @samp{step 5}. You can also use the @code{step} command
96a2c332 1281with no arguments. Some commands do not allow any arguments.
c906108c
SS
1282
1283@cindex abbreviation
1284@value{GDBN} command names may always be truncated if that abbreviation is
1285unambiguous. Other possible command abbreviations are listed in the
1286documentation for individual commands. In some cases, even ambiguous
1287abbreviations are allowed; for example, @code{s} is specially defined as
1288equivalent to @code{step} even though there are other commands whose
1289names start with @code{s}. You can test abbreviations by using them as
1290arguments to the @code{help} command.
1291
1292@cindex repeating commands
41afff9a 1293@kindex RET @r{(repeat last command)}
c906108c 1294A blank line as input to @value{GDBN} (typing just @key{RET}) means to
96a2c332 1295repeat the previous command. Certain commands (for example, @code{run})
c906108c
SS
1296will not repeat this way; these are commands whose unintentional
1297repetition might cause trouble and which you are unlikely to want to
1298repeat.
1299
1300The @code{list} and @code{x} commands, when you repeat them with
1301@key{RET}, construct new arguments rather than repeating
1302exactly as typed. This permits easy scanning of source or memory.
1303
1304@value{GDBN} can also use @key{RET} in another way: to partition lengthy
1305output, in a way similar to the common utility @code{more}
1306(@pxref{Screen Size,,Screen size}). Since it is easy to press one
1307@key{RET} too many in this situation, @value{GDBN} disables command
1308repetition after any command that generates this sort of display.
1309
41afff9a 1310@kindex # @r{(a comment)}
c906108c
SS
1311@cindex comment
1312Any text from a @kbd{#} to the end of the line is a comment; it does
1313nothing. This is useful mainly in command files (@pxref{Command
1314Files,,Command files}).
1315
88118b3a
TT
1316@cindex repeating command sequences
1317@kindex C-o @r{(operate-and-get-next)}
1318The @kbd{C-o} binding is useful for repeating a complex sequence of
1319commands. This command accepts the current line, like @kbd{RET}, and
1320then fetches the next line relative to the current line from the history
1321for editing.
1322
6d2ebf8b 1323@node Completion
c906108c
SS
1324@section Command completion
1325
1326@cindex completion
1327@cindex word completion
1328@value{GDBN} can fill in the rest of a word in a command for you, if there is
1329only one possibility; it can also show you what the valid possibilities
1330are for the next word in a command, at any time. This works for @value{GDBN}
1331commands, @value{GDBN} subcommands, and the names of symbols in your program.
1332
1333Press the @key{TAB} key whenever you want @value{GDBN} to fill out the rest
1334of a word. If there is only one possibility, @value{GDBN} fills in the
1335word, and waits for you to finish the command (or press @key{RET} to
1336enter it). For example, if you type
1337
1338@c FIXME "@key" does not distinguish its argument sufficiently to permit
1339@c complete accuracy in these examples; space introduced for clarity.
1340@c If texinfo enhancements make it unnecessary, it would be nice to
1341@c replace " @key" by "@key" in the following...
1342@example
1343(@value{GDBP}) info bre @key{TAB}
1344@end example
1345
1346@noindent
1347@value{GDBN} fills in the rest of the word @samp{breakpoints}, since that is
1348the only @code{info} subcommand beginning with @samp{bre}:
1349
1350@example
1351(@value{GDBP}) info breakpoints
1352@end example
1353
1354@noindent
1355You can either press @key{RET} at this point, to run the @code{info
1356breakpoints} command, or backspace and enter something else, if
1357@samp{breakpoints} does not look like the command you expected. (If you
1358were sure you wanted @code{info breakpoints} in the first place, you
1359might as well just type @key{RET} immediately after @samp{info bre},
1360to exploit command abbreviations rather than command completion).
1361
1362If there is more than one possibility for the next word when you press
1363@key{TAB}, @value{GDBN} sounds a bell. You can either supply more
1364characters and try again, or just press @key{TAB} a second time;
1365@value{GDBN} displays all the possible completions for that word. For
1366example, you might want to set a breakpoint on a subroutine whose name
1367begins with @samp{make_}, but when you type @kbd{b make_@key{TAB}} @value{GDBN}
1368just sounds the bell. Typing @key{TAB} again displays all the
1369function names in your program that begin with those characters, for
1370example:
1371
1372@example
1373(@value{GDBP}) b make_ @key{TAB}
1374@exdent @value{GDBN} sounds bell; press @key{TAB} again, to see:
5d161b24
DB
1375make_a_section_from_file make_environ
1376make_abs_section make_function_type
1377make_blockvector make_pointer_type
1378make_cleanup make_reference_type
c906108c
SS
1379make_command make_symbol_completion_list
1380(@value{GDBP}) b make_
1381@end example
1382
1383@noindent
1384After displaying the available possibilities, @value{GDBN} copies your
1385partial input (@samp{b make_} in the example) so you can finish the
1386command.
1387
1388If you just want to see the list of alternatives in the first place, you
b37052ae 1389can press @kbd{M-?} rather than pressing @key{TAB} twice. @kbd{M-?}
7a292a7a 1390means @kbd{@key{META} ?}. You can type this either by holding down a
c906108c 1391key designated as the @key{META} shift on your keyboard (if there is
7a292a7a 1392one) while typing @kbd{?}, or as @key{ESC} followed by @kbd{?}.
c906108c
SS
1393
1394@cindex quotes in commands
1395@cindex completion of quoted strings
1396Sometimes the string you need, while logically a ``word'', may contain
7a292a7a
SS
1397parentheses or other characters that @value{GDBN} normally excludes from
1398its notion of a word. To permit word completion to work in this
1399situation, you may enclose words in @code{'} (single quote marks) in
1400@value{GDBN} commands.
c906108c 1401
c906108c 1402The most likely situation where you might need this is in typing the
b37052ae
EZ
1403name of a C@t{++} function. This is because C@t{++} allows function
1404overloading (multiple definitions of the same function, distinguished
1405by argument type). For example, when you want to set a breakpoint you
1406may need to distinguish whether you mean the version of @code{name}
1407that takes an @code{int} parameter, @code{name(int)}, or the version
1408that takes a @code{float} parameter, @code{name(float)}. To use the
1409word-completion facilities in this situation, type a single quote
1410@code{'} at the beginning of the function name. This alerts
1411@value{GDBN} that it may need to consider more information than usual
1412when you press @key{TAB} or @kbd{M-?} to request word completion:
c906108c
SS
1413
1414@example
96a2c332 1415(@value{GDBP}) b 'bubble( @kbd{M-?}
c906108c
SS
1416bubble(double,double) bubble(int,int)
1417(@value{GDBP}) b 'bubble(
1418@end example
1419
1420In some cases, @value{GDBN} can tell that completing a name requires using
1421quotes. When this happens, @value{GDBN} inserts the quote for you (while
1422completing as much as it can) if you do not type the quote in the first
1423place:
1424
1425@example
1426(@value{GDBP}) b bub @key{TAB}
1427@exdent @value{GDBN} alters your input line to the following, and rings a bell:
1428(@value{GDBP}) b 'bubble(
1429@end example
1430
1431@noindent
1432In general, @value{GDBN} can tell that a quote is needed (and inserts it) if
1433you have not yet started typing the argument list when you ask for
1434completion on an overloaded symbol.
1435
d4f3574e 1436For more information about overloaded functions, see @ref{C plus plus
b37052ae 1437expressions, ,C@t{++} expressions}. You can use the command @code{set
c906108c 1438overload-resolution off} to disable overload resolution;
b37052ae 1439see @ref{Debugging C plus plus, ,@value{GDBN} features for C@t{++}}.
c906108c
SS
1440
1441
6d2ebf8b 1442@node Help
c906108c
SS
1443@section Getting help
1444@cindex online documentation
1445@kindex help
1446
5d161b24 1447You can always ask @value{GDBN} itself for information on its commands,
c906108c
SS
1448using the command @code{help}.
1449
1450@table @code
41afff9a 1451@kindex h @r{(@code{help})}
c906108c
SS
1452@item help
1453@itemx h
1454You can use @code{help} (abbreviated @code{h}) with no arguments to
1455display a short list of named classes of commands:
1456
1457@smallexample
1458(@value{GDBP}) help
1459List of classes of commands:
1460
2df3850c 1461aliases -- Aliases of other commands
c906108c 1462breakpoints -- Making program stop at certain points
2df3850c 1463data -- Examining data
c906108c 1464files -- Specifying and examining files
2df3850c
JM
1465internals -- Maintenance commands
1466obscure -- Obscure features
1467running -- Running the program
1468stack -- Examining the stack
c906108c
SS
1469status -- Status inquiries
1470support -- Support facilities
96a2c332
SS
1471tracepoints -- Tracing of program execution without@*
1472 stopping the program
c906108c 1473user-defined -- User-defined commands
c906108c 1474
5d161b24 1475Type "help" followed by a class name for a list of
c906108c 1476commands in that class.
5d161b24 1477Type "help" followed by command name for full
c906108c
SS
1478documentation.
1479Command name abbreviations are allowed if unambiguous.
1480(@value{GDBP})
1481@end smallexample
96a2c332 1482@c the above line break eliminates huge line overfull...
c906108c
SS
1483
1484@item help @var{class}
1485Using one of the general help classes as an argument, you can get a
1486list of the individual commands in that class. For example, here is the
1487help display for the class @code{status}:
1488
1489@smallexample
1490(@value{GDBP}) help status
1491Status inquiries.
1492
1493List of commands:
1494
1495@c Line break in "show" line falsifies real output, but needed
1496@c to fit in smallbook page size.
2df3850c
JM
1497info -- Generic command for showing things
1498 about the program being debugged
1499show -- Generic command for showing things
1500 about the debugger
c906108c 1501
5d161b24 1502Type "help" followed by command name for full
c906108c
SS
1503documentation.
1504Command name abbreviations are allowed if unambiguous.
1505(@value{GDBP})
1506@end smallexample
1507
1508@item help @var{command}
1509With a command name as @code{help} argument, @value{GDBN} displays a
1510short paragraph on how to use that command.
1511
6837a0a2
DB
1512@kindex apropos
1513@item apropos @var{args}
1514The @code{apropos @var{args}} command searches through all of the @value{GDBN}
1515commands, and their documentation, for the regular expression specified in
1516@var{args}. It prints out all matches found. For example:
1517
1518@smallexample
1519apropos reload
1520@end smallexample
1521
b37052ae
EZ
1522@noindent
1523results in:
6837a0a2
DB
1524
1525@smallexample
6d2ebf8b
SS
1526@c @group
1527set symbol-reloading -- Set dynamic symbol table reloading
1528 multiple times in one run
1529show symbol-reloading -- Show dynamic symbol table reloading
1530 multiple times in one run
1531@c @end group
6837a0a2
DB
1532@end smallexample
1533
c906108c
SS
1534@kindex complete
1535@item complete @var{args}
1536The @code{complete @var{args}} command lists all the possible completions
1537for the beginning of a command. Use @var{args} to specify the beginning of the
1538command you want completed. For example:
1539
1540@smallexample
1541complete i
1542@end smallexample
1543
1544@noindent results in:
1545
1546@smallexample
1547@group
2df3850c
JM
1548if
1549ignore
c906108c
SS
1550info
1551inspect
c906108c
SS
1552@end group
1553@end smallexample
1554
1555@noindent This is intended for use by @sc{gnu} Emacs.
1556@end table
1557
1558In addition to @code{help}, you can use the @value{GDBN} commands @code{info}
1559and @code{show} to inquire about the state of your program, or the state
1560of @value{GDBN} itself. Each command supports many topics of inquiry; this
1561manual introduces each of them in the appropriate context. The listings
1562under @code{info} and under @code{show} in the Index point to
1563all the sub-commands. @xref{Index}.
1564
1565@c @group
1566@table @code
1567@kindex info
41afff9a 1568@kindex i @r{(@code{info})}
c906108c
SS
1569@item info
1570This command (abbreviated @code{i}) is for describing the state of your
1571program. For example, you can list the arguments given to your program
1572with @code{info args}, list the registers currently in use with @code{info
1573registers}, or list the breakpoints you have set with @code{info breakpoints}.
1574You can get a complete list of the @code{info} sub-commands with
1575@w{@code{help info}}.
1576
1577@kindex set
1578@item set
5d161b24 1579You can assign the result of an expression to an environment variable with
c906108c
SS
1580@code{set}. For example, you can set the @value{GDBN} prompt to a $-sign with
1581@code{set prompt $}.
1582
1583@kindex show
1584@item show
5d161b24 1585In contrast to @code{info}, @code{show} is for describing the state of
c906108c
SS
1586@value{GDBN} itself.
1587You can change most of the things you can @code{show}, by using the
1588related command @code{set}; for example, you can control what number
1589system is used for displays with @code{set radix}, or simply inquire
1590which is currently in use with @code{show radix}.
1591
1592@kindex info set
1593To display all the settable parameters and their current
1594values, you can use @code{show} with no arguments; you may also use
1595@code{info set}. Both commands produce the same display.
1596@c FIXME: "info set" violates the rule that "info" is for state of
1597@c FIXME...program. Ck w/ GNU: "info set" to be called something else,
1598@c FIXME...or change desc of rule---eg "state of prog and debugging session"?
1599@end table
1600@c @end group
1601
1602Here are three miscellaneous @code{show} subcommands, all of which are
1603exceptional in lacking corresponding @code{set} commands:
1604
1605@table @code
1606@kindex show version
1607@cindex version number
1608@item show version
1609Show what version of @value{GDBN} is running. You should include this
2df3850c
JM
1610information in @value{GDBN} bug-reports. If multiple versions of
1611@value{GDBN} are in use at your site, you may need to determine which
1612version of @value{GDBN} you are running; as @value{GDBN} evolves, new
1613commands are introduced, and old ones may wither away. Also, many
1614system vendors ship variant versions of @value{GDBN}, and there are
96a2c332 1615variant versions of @value{GDBN} in @sc{gnu}/Linux distributions as well.
2df3850c
JM
1616The version number is the same as the one announced when you start
1617@value{GDBN}.
c906108c
SS
1618
1619@kindex show copying
1620@item show copying
1621Display information about permission for copying @value{GDBN}.
1622
1623@kindex show warranty
1624@item show warranty
2df3850c 1625Display the @sc{gnu} ``NO WARRANTY'' statement, or a warranty,
96a2c332 1626if your version of @value{GDBN} comes with one.
2df3850c 1627
c906108c
SS
1628@end table
1629
6d2ebf8b 1630@node Running
c906108c
SS
1631@chapter Running Programs Under @value{GDBN}
1632
1633When you run a program under @value{GDBN}, you must first generate
1634debugging information when you compile it.
7a292a7a
SS
1635
1636You may start @value{GDBN} with its arguments, if any, in an environment
1637of your choice. If you are doing native debugging, you may redirect
1638your program's input and output, debug an already running process, or
1639kill a child process.
c906108c
SS
1640
1641@menu
1642* Compilation:: Compiling for debugging
1643* Starting:: Starting your program
c906108c
SS
1644* Arguments:: Your program's arguments
1645* Environment:: Your program's environment
c906108c
SS
1646
1647* Working Directory:: Your program's working directory
1648* Input/Output:: Your program's input and output
1649* Attach:: Debugging an already-running process
1650* Kill Process:: Killing the child process
c906108c
SS
1651
1652* Threads:: Debugging programs with multiple threads
1653* Processes:: Debugging programs with multiple processes
1654@end menu
1655
6d2ebf8b 1656@node Compilation
c906108c
SS
1657@section Compiling for debugging
1658
1659In order to debug a program effectively, you need to generate
1660debugging information when you compile it. This debugging information
1661is stored in the object file; it describes the data type of each
1662variable or function and the correspondence between source line numbers
1663and addresses in the executable code.
1664
1665To request debugging information, specify the @samp{-g} option when you run
1666the compiler.
1667
1668Many C compilers are unable to handle the @samp{-g} and @samp{-O}
1669options together. Using those compilers, you cannot generate optimized
1670executables containing debugging information.
1671
53a5351d
JM
1672@value{NGCC}, the @sc{gnu} C compiler, supports @samp{-g} with or
1673without @samp{-O}, making it possible to debug optimized code. We
1674recommend that you @emph{always} use @samp{-g} whenever you compile a
1675program. You may think your program is correct, but there is no sense
1676in pushing your luck.
c906108c
SS
1677
1678@cindex optimized code, debugging
1679@cindex debugging optimized code
1680When you debug a program compiled with @samp{-g -O}, remember that the
1681optimizer is rearranging your code; the debugger shows you what is
1682really there. Do not be too surprised when the execution path does not
1683exactly match your source file! An extreme example: if you define a
1684variable, but never use it, @value{GDBN} never sees that
1685variable---because the compiler optimizes it out of existence.
1686
1687Some things do not work as well with @samp{-g -O} as with just
1688@samp{-g}, particularly on machines with instruction scheduling. If in
1689doubt, recompile with @samp{-g} alone, and if this fixes the problem,
1690please report it to us as a bug (including a test case!).
1691
1692Older versions of the @sc{gnu} C compiler permitted a variant option
1693@w{@samp{-gg}} for debugging information. @value{GDBN} no longer supports this
1694format; if your @sc{gnu} C compiler has this option, do not use it.
1695
1696@need 2000
6d2ebf8b 1697@node Starting
c906108c
SS
1698@section Starting your program
1699@cindex starting
1700@cindex running
1701
1702@table @code
1703@kindex run
41afff9a 1704@kindex r @r{(@code{run})}
c906108c
SS
1705@item run
1706@itemx r
7a292a7a
SS
1707Use the @code{run} command to start your program under @value{GDBN}.
1708You must first specify the program name (except on VxWorks) with an
1709argument to @value{GDBN} (@pxref{Invocation, ,Getting In and Out of
1710@value{GDBN}}), or by using the @code{file} or @code{exec-file} command
1711(@pxref{Files, ,Commands to specify files}).
c906108c
SS
1712
1713@end table
1714
c906108c
SS
1715If you are running your program in an execution environment that
1716supports processes, @code{run} creates an inferior process and makes
1717that process run your program. (In environments without processes,
1718@code{run} jumps to the start of your program.)
1719
1720The execution of a program is affected by certain information it
1721receives from its superior. @value{GDBN} provides ways to specify this
1722information, which you must do @emph{before} starting your program. (You
1723can change it after starting your program, but such changes only affect
1724your program the next time you start it.) This information may be
1725divided into four categories:
1726
1727@table @asis
1728@item The @emph{arguments.}
1729Specify the arguments to give your program as the arguments of the
1730@code{run} command. If a shell is available on your target, the shell
1731is used to pass the arguments, so that you may use normal conventions
1732(such as wildcard expansion or variable substitution) in describing
1733the arguments.
1734In Unix systems, you can control which shell is used with the
1735@code{SHELL} environment variable.
1736@xref{Arguments, ,Your program's arguments}.
1737
1738@item The @emph{environment.}
1739Your program normally inherits its environment from @value{GDBN}, but you can
1740use the @value{GDBN} commands @code{set environment} and @code{unset
1741environment} to change parts of the environment that affect
1742your program. @xref{Environment, ,Your program's environment}.
1743
1744@item The @emph{working directory.}
1745Your program inherits its working directory from @value{GDBN}. You can set
1746the @value{GDBN} working directory with the @code{cd} command in @value{GDBN}.
1747@xref{Working Directory, ,Your program's working directory}.
1748
1749@item The @emph{standard input and output.}
1750Your program normally uses the same device for standard input and
1751standard output as @value{GDBN} is using. You can redirect input and output
1752in the @code{run} command line, or you can use the @code{tty} command to
1753set a different device for your program.
1754@xref{Input/Output, ,Your program's input and output}.
1755
1756@cindex pipes
1757@emph{Warning:} While input and output redirection work, you cannot use
1758pipes to pass the output of the program you are debugging to another
1759program; if you attempt this, @value{GDBN} is likely to wind up debugging the
1760wrong program.
1761@end table
c906108c
SS
1762
1763When you issue the @code{run} command, your program begins to execute
1764immediately. @xref{Stopping, ,Stopping and continuing}, for discussion
1765of how to arrange for your program to stop. Once your program has
1766stopped, you may call functions in your program, using the @code{print}
1767or @code{call} commands. @xref{Data, ,Examining Data}.
1768
1769If the modification time of your symbol file has changed since the last
1770time @value{GDBN} read its symbols, @value{GDBN} discards its symbol
1771table, and reads it again. When it does this, @value{GDBN} tries to retain
1772your current breakpoints.
1773
6d2ebf8b 1774@node Arguments
c906108c
SS
1775@section Your program's arguments
1776
1777@cindex arguments (to your program)
1778The arguments to your program can be specified by the arguments of the
5d161b24 1779@code{run} command.
c906108c
SS
1780They are passed to a shell, which expands wildcard characters and
1781performs redirection of I/O, and thence to your program. Your
1782@code{SHELL} environment variable (if it exists) specifies what shell
1783@value{GDBN} uses. If you do not define @code{SHELL}, @value{GDBN} uses
d4f3574e
SS
1784the default shell (@file{/bin/sh} on Unix).
1785
1786On non-Unix systems, the program is usually invoked directly by
1787@value{GDBN}, which emulates I/O redirection via the appropriate system
1788calls, and the wildcard characters are expanded by the startup code of
1789the program, not by the shell.
c906108c
SS
1790
1791@code{run} with no arguments uses the same arguments used by the previous
1792@code{run}, or those set by the @code{set args} command.
1793
c906108c 1794@table @code
41afff9a 1795@kindex set args
c906108c
SS
1796@item set args
1797Specify the arguments to be used the next time your program is run. If
1798@code{set args} has no arguments, @code{run} executes your program
1799with no arguments. Once you have run your program with arguments,
1800using @code{set args} before the next @code{run} is the only way to run
1801it again without arguments.
1802
1803@kindex show args
1804@item show args
1805Show the arguments to give your program when it is started.
1806@end table
1807
6d2ebf8b 1808@node Environment
c906108c
SS
1809@section Your program's environment
1810
1811@cindex environment (of your program)
1812The @dfn{environment} consists of a set of environment variables and
1813their values. Environment variables conventionally record such things as
1814your user name, your home directory, your terminal type, and your search
1815path for programs to run. Usually you set up environment variables with
1816the shell and they are inherited by all the other programs you run. When
1817debugging, it can be useful to try running your program with a modified
1818environment without having to start @value{GDBN} over again.
1819
1820@table @code
1821@kindex path
1822@item path @var{directory}
1823Add @var{directory} to the front of the @code{PATH} environment variable
17cc6a06
EZ
1824(the search path for executables) that will be passed to your program.
1825The value of @code{PATH} used by @value{GDBN} does not change.
d4f3574e
SS
1826You may specify several directory names, separated by whitespace or by a
1827system-dependent separator character (@samp{:} on Unix, @samp{;} on
1828MS-DOS and MS-Windows). If @var{directory} is already in the path, it
1829is moved to the front, so it is searched sooner.
c906108c
SS
1830
1831You can use the string @samp{$cwd} to refer to whatever is the current
1832working directory at the time @value{GDBN} searches the path. If you
1833use @samp{.} instead, it refers to the directory where you executed the
1834@code{path} command. @value{GDBN} replaces @samp{.} in the
1835@var{directory} argument (with the current path) before adding
1836@var{directory} to the search path.
1837@c 'path' is explicitly nonrepeatable, but RMS points out it is silly to
1838@c document that, since repeating it would be a no-op.
1839
1840@kindex show paths
1841@item show paths
1842Display the list of search paths for executables (the @code{PATH}
1843environment variable).
1844
1845@kindex show environment
1846@item show environment @r{[}@var{varname}@r{]}
1847Print the value of environment variable @var{varname} to be given to
1848your program when it starts. If you do not supply @var{varname},
1849print the names and values of all environment variables to be given to
1850your program. You can abbreviate @code{environment} as @code{env}.
1851
1852@kindex set environment
53a5351d 1853@item set environment @var{varname} @r{[}=@var{value}@r{]}
c906108c
SS
1854Set environment variable @var{varname} to @var{value}. The value
1855changes for your program only, not for @value{GDBN} itself. @var{value} may
1856be any string; the values of environment variables are just strings, and
1857any interpretation is supplied by your program itself. The @var{value}
1858parameter is optional; if it is eliminated, the variable is set to a
1859null value.
1860@c "any string" here does not include leading, trailing
1861@c blanks. Gnu asks: does anyone care?
1862
1863For example, this command:
1864
1865@example
1866set env USER = foo
1867@end example
1868
1869@noindent
d4f3574e 1870tells the debugged program, when subsequently run, that its user is named
c906108c
SS
1871@samp{foo}. (The spaces around @samp{=} are used for clarity here; they
1872are not actually required.)
1873
1874@kindex unset environment
1875@item unset environment @var{varname}
1876Remove variable @var{varname} from the environment to be passed to your
1877program. This is different from @samp{set env @var{varname} =};
1878@code{unset environment} removes the variable from the environment,
1879rather than assigning it an empty value.
1880@end table
1881
d4f3574e
SS
1882@emph{Warning:} On Unix systems, @value{GDBN} runs your program using
1883the shell indicated
c906108c
SS
1884by your @code{SHELL} environment variable if it exists (or
1885@code{/bin/sh} if not). If your @code{SHELL} variable names a shell
1886that runs an initialization file---such as @file{.cshrc} for C-shell, or
1887@file{.bashrc} for BASH---any variables you set in that file affect
1888your program. You may wish to move setting of environment variables to
1889files that are only run when you sign on, such as @file{.login} or
1890@file{.profile}.
1891
6d2ebf8b 1892@node Working Directory
c906108c
SS
1893@section Your program's working directory
1894
1895@cindex working directory (of your program)
1896Each time you start your program with @code{run}, it inherits its
1897working directory from the current working directory of @value{GDBN}.
1898The @value{GDBN} working directory is initially whatever it inherited
1899from its parent process (typically the shell), but you can specify a new
1900working directory in @value{GDBN} with the @code{cd} command.
1901
1902The @value{GDBN} working directory also serves as a default for the commands
1903that specify files for @value{GDBN} to operate on. @xref{Files, ,Commands to
1904specify files}.
1905
1906@table @code
1907@kindex cd
1908@item cd @var{directory}
1909Set the @value{GDBN} working directory to @var{directory}.
1910
1911@kindex pwd
1912@item pwd
1913Print the @value{GDBN} working directory.
1914@end table
1915
6d2ebf8b 1916@node Input/Output
c906108c
SS
1917@section Your program's input and output
1918
1919@cindex redirection
1920@cindex i/o
1921@cindex terminal
1922By default, the program you run under @value{GDBN} does input and output to
5d161b24 1923the same terminal that @value{GDBN} uses. @value{GDBN} switches the terminal
c906108c
SS
1924to its own terminal modes to interact with you, but it records the terminal
1925modes your program was using and switches back to them when you continue
1926running your program.
1927
1928@table @code
1929@kindex info terminal
1930@item info terminal
1931Displays information recorded by @value{GDBN} about the terminal modes your
1932program is using.
1933@end table
1934
1935You can redirect your program's input and/or output using shell
1936redirection with the @code{run} command. For example,
1937
1938@example
1939run > outfile
1940@end example
1941
1942@noindent
1943starts your program, diverting its output to the file @file{outfile}.
1944
1945@kindex tty
1946@cindex controlling terminal
1947Another way to specify where your program should do input and output is
1948with the @code{tty} command. This command accepts a file name as
1949argument, and causes this file to be the default for future @code{run}
1950commands. It also resets the controlling terminal for the child
1951process, for future @code{run} commands. For example,
1952
1953@example
1954tty /dev/ttyb
1955@end example
1956
1957@noindent
1958directs that processes started with subsequent @code{run} commands
1959default to do input and output on the terminal @file{/dev/ttyb} and have
1960that as their controlling terminal.
1961
1962An explicit redirection in @code{run} overrides the @code{tty} command's
1963effect on the input/output device, but not its effect on the controlling
1964terminal.
1965
1966When you use the @code{tty} command or redirect input in the @code{run}
1967command, only the input @emph{for your program} is affected. The input
1968for @value{GDBN} still comes from your terminal.
1969
6d2ebf8b 1970@node Attach
c906108c
SS
1971@section Debugging an already-running process
1972@kindex attach
1973@cindex attach
1974
1975@table @code
1976@item attach @var{process-id}
1977This command attaches to a running process---one that was started
1978outside @value{GDBN}. (@code{info files} shows your active
1979targets.) The command takes as argument a process ID. The usual way to
1980find out the process-id of a Unix process is with the @code{ps} utility,
1981or with the @samp{jobs -l} shell command.
1982
1983@code{attach} does not repeat if you press @key{RET} a second time after
1984executing the command.
1985@end table
1986
1987To use @code{attach}, your program must be running in an environment
1988which supports processes; for example, @code{attach} does not work for
1989programs on bare-board targets that lack an operating system. You must
1990also have permission to send the process a signal.
1991
1992When you use @code{attach}, the debugger finds the program running in
1993the process first by looking in the current working directory, then (if
1994the program is not found) by using the source file search path
1995(@pxref{Source Path, ,Specifying source directories}). You can also use
1996the @code{file} command to load the program. @xref{Files, ,Commands to
1997Specify Files}.
1998
1999The first thing @value{GDBN} does after arranging to debug the specified
2000process is to stop it. You can examine and modify an attached process
53a5351d
JM
2001with all the @value{GDBN} commands that are ordinarily available when
2002you start processes with @code{run}. You can insert breakpoints; you
2003can step and continue; you can modify storage. If you would rather the
2004process continue running, you may use the @code{continue} command after
c906108c
SS
2005attaching @value{GDBN} to the process.
2006
2007@table @code
2008@kindex detach
2009@item detach
2010When you have finished debugging the attached process, you can use the
2011@code{detach} command to release it from @value{GDBN} control. Detaching
2012the process continues its execution. After the @code{detach} command,
2013that process and @value{GDBN} become completely independent once more, and you
2014are ready to @code{attach} another process or start one with @code{run}.
2015@code{detach} does not repeat if you press @key{RET} again after
2016executing the command.
2017@end table
2018
2019If you exit @value{GDBN} or use the @code{run} command while you have an
2020attached process, you kill that process. By default, @value{GDBN} asks
2021for confirmation if you try to do either of these things; you can
2022control whether or not you need to confirm by using the @code{set
2023confirm} command (@pxref{Messages/Warnings, ,Optional warnings and
2024messages}).
2025
6d2ebf8b 2026@node Kill Process
c906108c 2027@section Killing the child process
c906108c
SS
2028
2029@table @code
2030@kindex kill
2031@item kill
2032Kill the child process in which your program is running under @value{GDBN}.
2033@end table
2034
2035This command is useful if you wish to debug a core dump instead of a
2036running process. @value{GDBN} ignores any core dump file while your program
2037is running.
2038
2039On some operating systems, a program cannot be executed outside @value{GDBN}
2040while you have breakpoints set on it inside @value{GDBN}. You can use the
2041@code{kill} command in this situation to permit running your program
2042outside the debugger.
2043
2044The @code{kill} command is also useful if you wish to recompile and
2045relink your program, since on many systems it is impossible to modify an
2046executable file while it is running in a process. In this case, when you
2047next type @code{run}, @value{GDBN} notices that the file has changed, and
2048reads the symbol table again (while trying to preserve your current
2049breakpoint settings).
2050
6d2ebf8b 2051@node Threads
c906108c 2052@section Debugging programs with multiple threads
c906108c
SS
2053
2054@cindex threads of execution
2055@cindex multiple threads
2056@cindex switching threads
2057In some operating systems, such as HP-UX and Solaris, a single program
2058may have more than one @dfn{thread} of execution. The precise semantics
2059of threads differ from one operating system to another, but in general
2060the threads of a single program are akin to multiple processes---except
2061that they share one address space (that is, they can all examine and
2062modify the same variables). On the other hand, each thread has its own
2063registers and execution stack, and perhaps private memory.
2064
2065@value{GDBN} provides these facilities for debugging multi-thread
2066programs:
2067
2068@itemize @bullet
2069@item automatic notification of new threads
2070@item @samp{thread @var{threadno}}, a command to switch among threads
2071@item @samp{info threads}, a command to inquire about existing threads
5d161b24 2072@item @samp{thread apply [@var{threadno}] [@var{all}] @var{args}},
c906108c
SS
2073a command to apply a command to a list of threads
2074@item thread-specific breakpoints
2075@end itemize
2076
c906108c
SS
2077@quotation
2078@emph{Warning:} These facilities are not yet available on every
2079@value{GDBN} configuration where the operating system supports threads.
2080If your @value{GDBN} does not support threads, these commands have no
2081effect. For example, a system without thread support shows no output
2082from @samp{info threads}, and always rejects the @code{thread} command,
2083like this:
2084
2085@smallexample
2086(@value{GDBP}) info threads
2087(@value{GDBP}) thread 1
2088Thread ID 1 not known. Use the "info threads" command to
2089see the IDs of currently known threads.
2090@end smallexample
2091@c FIXME to implementors: how hard would it be to say "sorry, this GDB
2092@c doesn't support threads"?
2093@end quotation
c906108c
SS
2094
2095@cindex focus of debugging
2096@cindex current thread
2097The @value{GDBN} thread debugging facility allows you to observe all
2098threads while your program runs---but whenever @value{GDBN} takes
2099control, one thread in particular is always the focus of debugging.
2100This thread is called the @dfn{current thread}. Debugging commands show
2101program information from the perspective of the current thread.
2102
41afff9a 2103@cindex @code{New} @var{systag} message
c906108c
SS
2104@cindex thread identifier (system)
2105@c FIXME-implementors!! It would be more helpful if the [New...] message
2106@c included GDB's numeric thread handle, so you could just go to that
2107@c thread without first checking `info threads'.
2108Whenever @value{GDBN} detects a new thread in your program, it displays
2109the target system's identification for the thread with a message in the
2110form @samp{[New @var{systag}]}. @var{systag} is a thread identifier
2111whose form varies depending on the particular system. For example, on
2112LynxOS, you might see
2113
2114@example
2115[New process 35 thread 27]
2116@end example
2117
2118@noindent
2119when @value{GDBN} notices a new thread. In contrast, on an SGI system,
2120the @var{systag} is simply something like @samp{process 368}, with no
2121further qualifier.
2122
2123@c FIXME!! (1) Does the [New...] message appear even for the very first
2124@c thread of a program, or does it only appear for the
2125@c second---i.e., when it becomes obvious we have a multithread
2126@c program?
2127@c (2) *Is* there necessarily a first thread always? Or do some
2128@c multithread systems permit starting a program with multiple
5d161b24 2129@c threads ab initio?
c906108c
SS
2130
2131@cindex thread number
2132@cindex thread identifier (GDB)
2133For debugging purposes, @value{GDBN} associates its own thread
2134number---always a single integer---with each thread in your program.
2135
2136@table @code
2137@kindex info threads
2138@item info threads
2139Display a summary of all threads currently in your
2140program. @value{GDBN} displays for each thread (in this order):
2141
2142@enumerate
2143@item the thread number assigned by @value{GDBN}
2144
2145@item the target system's thread identifier (@var{systag})
2146
2147@item the current stack frame summary for that thread
2148@end enumerate
2149
2150@noindent
2151An asterisk @samp{*} to the left of the @value{GDBN} thread number
2152indicates the current thread.
2153
5d161b24 2154For example,
c906108c
SS
2155@end table
2156@c end table here to get a little more width for example
2157
2158@smallexample
2159(@value{GDBP}) info threads
2160 3 process 35 thread 27 0x34e5 in sigpause ()
2161 2 process 35 thread 23 0x34e5 in sigpause ()
2162* 1 process 35 thread 13 main (argc=1, argv=0x7ffffff8)
2163 at threadtest.c:68
2164@end smallexample
53a5351d
JM
2165
2166On HP-UX systems:
c906108c
SS
2167
2168@cindex thread number
2169@cindex thread identifier (GDB)
2170For debugging purposes, @value{GDBN} associates its own thread
2171number---a small integer assigned in thread-creation order---with each
2172thread in your program.
2173
41afff9a
EZ
2174@cindex @code{New} @var{systag} message, on HP-UX
2175@cindex thread identifier (system), on HP-UX
c906108c
SS
2176@c FIXME-implementors!! It would be more helpful if the [New...] message
2177@c included GDB's numeric thread handle, so you could just go to that
2178@c thread without first checking `info threads'.
2179Whenever @value{GDBN} detects a new thread in your program, it displays
2180both @value{GDBN}'s thread number and the target system's identification for the thread with a message in the
2181form @samp{[New @var{systag}]}. @var{systag} is a thread identifier
2182whose form varies depending on the particular system. For example, on
2183HP-UX, you see
2184
2185@example
2186[New thread 2 (system thread 26594)]
2187@end example
2188
2189@noindent
5d161b24 2190when @value{GDBN} notices a new thread.
c906108c
SS
2191
2192@table @code
2193@kindex info threads
2194@item info threads
2195Display a summary of all threads currently in your
2196program. @value{GDBN} displays for each thread (in this order):
2197
2198@enumerate
2199@item the thread number assigned by @value{GDBN}
2200
2201@item the target system's thread identifier (@var{systag})
2202
2203@item the current stack frame summary for that thread
2204@end enumerate
2205
2206@noindent
2207An asterisk @samp{*} to the left of the @value{GDBN} thread number
2208indicates the current thread.
2209
5d161b24 2210For example,
c906108c
SS
2211@end table
2212@c end table here to get a little more width for example
2213
2214@example
2215(@value{GDBP}) info threads
6d2ebf8b
SS
2216 * 3 system thread 26607 worker (wptr=0x7b09c318 "@@") \@*
2217 at quicksort.c:137
2218 2 system thread 26606 0x7b0030d8 in __ksleep () \@*
2219 from /usr/lib/libc.2
2220 1 system thread 27905 0x7b003498 in _brk () \@*
2221 from /usr/lib/libc.2
c906108c 2222@end example
c906108c
SS
2223
2224@table @code
2225@kindex thread @var{threadno}
2226@item thread @var{threadno}
2227Make thread number @var{threadno} the current thread. The command
2228argument @var{threadno} is the internal @value{GDBN} thread number, as
2229shown in the first field of the @samp{info threads} display.
2230@value{GDBN} responds by displaying the system identifier of the thread
2231you selected, and its current stack frame summary:
2232
2233@smallexample
2234@c FIXME!! This example made up; find a @value{GDBN} w/threads and get real one
2235(@value{GDBP}) thread 2
c906108c 2236[Switching to process 35 thread 23]
c906108c
SS
22370x34e5 in sigpause ()
2238@end smallexample
2239
2240@noindent
2241As with the @samp{[New @dots{}]} message, the form of the text after
2242@samp{Switching to} depends on your system's conventions for identifying
5d161b24 2243threads.
c906108c
SS
2244
2245@kindex thread apply
2246@item thread apply [@var{threadno}] [@var{all}] @var{args}
2247The @code{thread apply} command allows you to apply a command to one or
2248more threads. Specify the numbers of the threads that you want affected
2249with the command argument @var{threadno}. @var{threadno} is the internal
2250@value{GDBN} thread number, as shown in the first field of the @samp{info
5d161b24
DB
2251threads} display. To apply a command to all threads, use
2252@code{thread apply all} @var{args}.
c906108c
SS
2253@end table
2254
2255@cindex automatic thread selection
2256@cindex switching threads automatically
2257@cindex threads, automatic switching
2258Whenever @value{GDBN} stops your program, due to a breakpoint or a
2259signal, it automatically selects the thread where that breakpoint or
2260signal happened. @value{GDBN} alerts you to the context switch with a
2261message of the form @samp{[Switching to @var{systag}]} to identify the
2262thread.
2263
2264@xref{Thread Stops,,Stopping and starting multi-thread programs}, for
2265more information about how @value{GDBN} behaves when you stop and start
2266programs with multiple threads.
2267
2268@xref{Set Watchpoints,,Setting watchpoints}, for information about
2269watchpoints in programs with multiple threads.
c906108c 2270
6d2ebf8b 2271@node Processes
c906108c
SS
2272@section Debugging programs with multiple processes
2273
2274@cindex fork, debugging programs which call
2275@cindex multiple processes
2276@cindex processes, multiple
53a5351d
JM
2277On most systems, @value{GDBN} has no special support for debugging
2278programs which create additional processes using the @code{fork}
2279function. When a program forks, @value{GDBN} will continue to debug the
2280parent process and the child process will run unimpeded. If you have
2281set a breakpoint in any code which the child then executes, the child
2282will get a @code{SIGTRAP} signal which (unless it catches the signal)
2283will cause it to terminate.
c906108c
SS
2284
2285However, if you want to debug the child process there is a workaround
2286which isn't too painful. Put a call to @code{sleep} in the code which
2287the child process executes after the fork. It may be useful to sleep
2288only if a certain environment variable is set, or a certain file exists,
2289so that the delay need not occur when you don't want to run @value{GDBN}
2290on the child. While the child is sleeping, use the @code{ps} program to
2291get its process ID. Then tell @value{GDBN} (a new invocation of
2292@value{GDBN} if you are also debugging the parent process) to attach to
d4f3574e 2293the child process (@pxref{Attach}). From that point on you can debug
c906108c 2294the child process just like any other process which you attached to.
c906108c 2295
53a5351d
JM
2296On HP-UX (11.x and later only?), @value{GDBN} provides support for
2297debugging programs that create additional processes using the
2298@code{fork} or @code{vfork} function.
c906108c
SS
2299
2300By default, when a program forks, @value{GDBN} will continue to debug
2301the parent process and the child process will run unimpeded.
2302
2303If you want to follow the child process instead of the parent process,
2304use the command @w{@code{set follow-fork-mode}}.
2305
2306@table @code
2307@kindex set follow-fork-mode
2308@item set follow-fork-mode @var{mode}
2309Set the debugger response to a program call of @code{fork} or
2310@code{vfork}. A call to @code{fork} or @code{vfork} creates a new
2311process. The @var{mode} can be:
2312
2313@table @code
2314@item parent
2315The original process is debugged after a fork. The child process runs
2df3850c 2316unimpeded. This is the default.
c906108c
SS
2317
2318@item child
2319The new process is debugged after a fork. The parent process runs
2320unimpeded.
2321
2322@item ask
2323The debugger will ask for one of the above choices.
2324@end table
2325
2326@item show follow-fork-mode
2df3850c 2327Display the current debugger response to a @code{fork} or @code{vfork} call.
c906108c
SS
2328@end table
2329
2330If you ask to debug a child process and a @code{vfork} is followed by an
2331@code{exec}, @value{GDBN} executes the new target up to the first
2332breakpoint in the new target. If you have a breakpoint set on
2333@code{main} in your original program, the breakpoint will also be set on
2334the child process's @code{main}.
2335
2336When a child process is spawned by @code{vfork}, you cannot debug the
2337child or parent until an @code{exec} call completes.
2338
2339If you issue a @code{run} command to @value{GDBN} after an @code{exec}
2340call executes, the new target restarts. To restart the parent process,
2341use the @code{file} command with the parent executable name as its
2342argument.
2343
2344You can use the @code{catch} command to make @value{GDBN} stop whenever
2345a @code{fork}, @code{vfork}, or @code{exec} call is made. @xref{Set
2346Catchpoints, ,Setting catchpoints}.
c906108c 2347
6d2ebf8b 2348@node Stopping
c906108c
SS
2349@chapter Stopping and Continuing
2350
2351The principal purposes of using a debugger are so that you can stop your
2352program before it terminates; or so that, if your program runs into
2353trouble, you can investigate and find out why.
2354
7a292a7a
SS
2355Inside @value{GDBN}, your program may stop for any of several reasons,
2356such as a signal, a breakpoint, or reaching a new line after a
2357@value{GDBN} command such as @code{step}. You may then examine and
2358change variables, set new breakpoints or remove old ones, and then
2359continue execution. Usually, the messages shown by @value{GDBN} provide
2360ample explanation of the status of your program---but you can also
2361explicitly request this information at any time.
c906108c
SS
2362
2363@table @code
2364@kindex info program
2365@item info program
2366Display information about the status of your program: whether it is
7a292a7a 2367running or not, what process it is, and why it stopped.
c906108c
SS
2368@end table
2369
2370@menu
2371* Breakpoints:: Breakpoints, watchpoints, and catchpoints
2372* Continuing and Stepping:: Resuming execution
c906108c 2373* Signals:: Signals
c906108c 2374* Thread Stops:: Stopping and starting multi-thread programs
c906108c
SS
2375@end menu
2376
6d2ebf8b 2377@node Breakpoints
c906108c
SS
2378@section Breakpoints, watchpoints, and catchpoints
2379
2380@cindex breakpoints
2381A @dfn{breakpoint} makes your program stop whenever a certain point in
2382the program is reached. For each breakpoint, you can add conditions to
2383control in finer detail whether your program stops. You can set
2384breakpoints with the @code{break} command and its variants (@pxref{Set
2385Breaks, ,Setting breakpoints}), to specify the place where your program
2386should stop by line number, function name or exact address in the
2387program.
2388
2389In HP-UX, SunOS 4.x, SVR4, and Alpha OSF/1 configurations, you can set
2390breakpoints in shared libraries before the executable is run. There is
2391a minor limitation on HP-UX systems: you must wait until the executable
2392is run in order to set breakpoints in shared library routines that are
2393not called directly by the program (for example, routines that are
2394arguments in a @code{pthread_create} call).
2395
2396@cindex watchpoints
2397@cindex memory tracing
2398@cindex breakpoint on memory address
2399@cindex breakpoint on variable modification
2400A @dfn{watchpoint} is a special breakpoint that stops your program
2401when the value of an expression changes. You must use a different
2402command to set watchpoints (@pxref{Set Watchpoints, ,Setting
2403watchpoints}), but aside from that, you can manage a watchpoint like
2404any other breakpoint: you enable, disable, and delete both breakpoints
2405and watchpoints using the same commands.
2406
2407You can arrange to have values from your program displayed automatically
2408whenever @value{GDBN} stops at a breakpoint. @xref{Auto Display,,
2409Automatic display}.
2410
2411@cindex catchpoints
2412@cindex breakpoint on events
2413A @dfn{catchpoint} is another special breakpoint that stops your program
b37052ae 2414when a certain kind of event occurs, such as the throwing of a C@t{++}
c906108c
SS
2415exception or the loading of a library. As with watchpoints, you use a
2416different command to set a catchpoint (@pxref{Set Catchpoints, ,Setting
2417catchpoints}), but aside from that, you can manage a catchpoint like any
2418other breakpoint. (To stop when your program receives a signal, use the
d4f3574e 2419@code{handle} command; see @ref{Signals, ,Signals}.)
c906108c
SS
2420
2421@cindex breakpoint numbers
2422@cindex numbers for breakpoints
2423@value{GDBN} assigns a number to each breakpoint, watchpoint, or
2424catchpoint when you create it; these numbers are successive integers
2425starting with one. In many of the commands for controlling various
2426features of breakpoints you use the breakpoint number to say which
2427breakpoint you want to change. Each breakpoint may be @dfn{enabled} or
2428@dfn{disabled}; if disabled, it has no effect on your program until you
2429enable it again.
2430
c5394b80
JM
2431@cindex breakpoint ranges
2432@cindex ranges of breakpoints
2433Some @value{GDBN} commands accept a range of breakpoints on which to
2434operate. A breakpoint range is either a single breakpoint number, like
2435@samp{5}, or two such numbers, in increasing order, separated by a
2436hyphen, like @samp{5-7}. When a breakpoint range is given to a command,
2437all breakpoint in that range are operated on.
2438
c906108c
SS
2439@menu
2440* Set Breaks:: Setting breakpoints
2441* Set Watchpoints:: Setting watchpoints
2442* Set Catchpoints:: Setting catchpoints
2443* Delete Breaks:: Deleting breakpoints
2444* Disabling:: Disabling breakpoints
2445* Conditions:: Break conditions
2446* Break Commands:: Breakpoint command lists
c906108c 2447* Breakpoint Menus:: Breakpoint menus
d4f3574e 2448* Error in Breakpoints:: ``Cannot insert breakpoints''
c906108c
SS
2449@end menu
2450
6d2ebf8b 2451@node Set Breaks
c906108c
SS
2452@subsection Setting breakpoints
2453
5d161b24 2454@c FIXME LMB what does GDB do if no code on line of breakpt?
c906108c
SS
2455@c consider in particular declaration with/without initialization.
2456@c
2457@c FIXME 2 is there stuff on this already? break at fun start, already init?
2458
2459@kindex break
41afff9a
EZ
2460@kindex b @r{(@code{break})}
2461@vindex $bpnum@r{, convenience variable}
c906108c
SS
2462@cindex latest breakpoint
2463Breakpoints are set with the @code{break} command (abbreviated
5d161b24 2464@code{b}). The debugger convenience variable @samp{$bpnum} records the
f3b28801 2465number of the breakpoint you've set most recently; see @ref{Convenience
c906108c
SS
2466Vars,, Convenience variables}, for a discussion of what you can do with
2467convenience variables.
2468
2469You have several ways to say where the breakpoint should go.
2470
2471@table @code
2472@item break @var{function}
5d161b24 2473Set a breakpoint at entry to function @var{function}.
c906108c 2474When using source languages that permit overloading of symbols, such as
b37052ae 2475C@t{++}, @var{function} may refer to more than one possible place to break.
c906108c 2476@xref{Breakpoint Menus,,Breakpoint menus}, for a discussion of that situation.
c906108c
SS
2477
2478@item break +@var{offset}
2479@itemx break -@var{offset}
2480Set a breakpoint some number of lines forward or back from the position
d4f3574e 2481at which execution stopped in the currently selected @dfn{stack frame}.
2df3850c 2482(@xref{Frames, ,Frames}, for a description of stack frames.)
c906108c
SS
2483
2484@item break @var{linenum}
2485Set a breakpoint at line @var{linenum} in the current source file.
d4f3574e
SS
2486The current source file is the last file whose source text was printed.
2487The breakpoint will stop your program just before it executes any of the
c906108c
SS
2488code on that line.
2489
2490@item break @var{filename}:@var{linenum}
2491Set a breakpoint at line @var{linenum} in source file @var{filename}.
2492
2493@item break @var{filename}:@var{function}
2494Set a breakpoint at entry to function @var{function} found in file
2495@var{filename}. Specifying a file name as well as a function name is
2496superfluous except when multiple files contain similarly named
2497functions.
2498
2499@item break *@var{address}
2500Set a breakpoint at address @var{address}. You can use this to set
2501breakpoints in parts of your program which do not have debugging
2502information or source files.
2503
2504@item break
2505When called without any arguments, @code{break} sets a breakpoint at
2506the next instruction to be executed in the selected stack frame
2507(@pxref{Stack, ,Examining the Stack}). In any selected frame but the
2508innermost, this makes your program stop as soon as control
2509returns to that frame. This is similar to the effect of a
2510@code{finish} command in the frame inside the selected frame---except
2511that @code{finish} does not leave an active breakpoint. If you use
2512@code{break} without an argument in the innermost frame, @value{GDBN} stops
2513the next time it reaches the current location; this may be useful
2514inside loops.
2515
2516@value{GDBN} normally ignores breakpoints when it resumes execution, until at
2517least one instruction has been executed. If it did not do this, you
2518would be unable to proceed past a breakpoint without first disabling the
2519breakpoint. This rule applies whether or not the breakpoint already
2520existed when your program stopped.
2521
2522@item break @dots{} if @var{cond}
2523Set a breakpoint with condition @var{cond}; evaluate the expression
2524@var{cond} each time the breakpoint is reached, and stop only if the
2525value is nonzero---that is, if @var{cond} evaluates as true.
2526@samp{@dots{}} stands for one of the possible arguments described
2527above (or no argument) specifying where to break. @xref{Conditions,
2528,Break conditions}, for more information on breakpoint conditions.
2529
2530@kindex tbreak
2531@item tbreak @var{args}
2532Set a breakpoint enabled only for one stop. @var{args} are the
2533same as for the @code{break} command, and the breakpoint is set in the same
2534way, but the breakpoint is automatically deleted after the first time your
2535program stops there. @xref{Disabling, ,Disabling breakpoints}.
2536
c906108c
SS
2537@kindex hbreak
2538@item hbreak @var{args}
d4f3574e
SS
2539Set a hardware-assisted breakpoint. @var{args} are the same as for the
2540@code{break} command and the breakpoint is set in the same way, but the
c906108c
SS
2541breakpoint requires hardware support and some target hardware may not
2542have this support. The main purpose of this is EPROM/ROM code
d4f3574e
SS
2543debugging, so you can set a breakpoint at an instruction without
2544changing the instruction. This can be used with the new trap-generation
2545provided by SPARClite DSU and some x86-based targets. These targets
2546will generate traps when a program accesses some data or instruction
2547address that is assigned to the debug registers. However the hardware
2548breakpoint registers can take a limited number of breakpoints. For
2549example, on the DSU, only two data breakpoints can be set at a time, and
2550@value{GDBN} will reject this command if more than two are used. Delete
2551or disable unused hardware breakpoints before setting new ones
2552(@pxref{Disabling, ,Disabling}). @xref{Conditions, ,Break conditions}.
c906108c
SS
2553
2554@kindex thbreak
2555@item thbreak @var{args}
2556Set a hardware-assisted breakpoint enabled only for one stop. @var{args}
2557are the same as for the @code{hbreak} command and the breakpoint is set in
5d161b24 2558the same way. However, like the @code{tbreak} command,
c906108c
SS
2559the breakpoint is automatically deleted after the
2560first time your program stops there. Also, like the @code{hbreak}
5d161b24
DB
2561command, the breakpoint requires hardware support and some target hardware
2562may not have this support. @xref{Disabling, ,Disabling breakpoints}.
d4f3574e 2563See also @ref{Conditions, ,Break conditions}.
c906108c
SS
2564
2565@kindex rbreak
2566@cindex regular expression
2567@item rbreak @var{regex}
c906108c 2568Set breakpoints on all functions matching the regular expression
11cf8741
JM
2569@var{regex}. This command sets an unconditional breakpoint on all
2570matches, printing a list of all breakpoints it set. Once these
2571breakpoints are set, they are treated just like the breakpoints set with
2572the @code{break} command. You can delete them, disable them, or make
2573them conditional the same way as any other breakpoint.
2574
2575The syntax of the regular expression is the standard one used with tools
2576like @file{grep}. Note that this is different from the syntax used by
2577shells, so for instance @code{foo*} matches all functions that include
2578an @code{fo} followed by zero or more @code{o}s. There is an implicit
2579@code{.*} leading and trailing the regular expression you supply, so to
2580match only functions that begin with @code{foo}, use @code{^foo}.
c906108c 2581
b37052ae 2582When debugging C@t{++} programs, @code{rbreak} is useful for setting
c906108c
SS
2583breakpoints on overloaded functions that are not members of any special
2584classes.
c906108c
SS
2585
2586@kindex info breakpoints
2587@cindex @code{$_} and @code{info breakpoints}
2588@item info breakpoints @r{[}@var{n}@r{]}
2589@itemx info break @r{[}@var{n}@r{]}
2590@itemx info watchpoints @r{[}@var{n}@r{]}
2591Print a table of all breakpoints, watchpoints, and catchpoints set and
2592not deleted, with the following columns for each breakpoint:
2593
2594@table @emph
2595@item Breakpoint Numbers
2596@item Type
2597Breakpoint, watchpoint, or catchpoint.
2598@item Disposition
2599Whether the breakpoint is marked to be disabled or deleted when hit.
2600@item Enabled or Disabled
2601Enabled breakpoints are marked with @samp{y}. @samp{n} marks breakpoints
2602that are not enabled.
2603@item Address
2df3850c 2604Where the breakpoint is in your program, as a memory address.
c906108c
SS
2605@item What
2606Where the breakpoint is in the source for your program, as a file and
2607line number.
2608@end table
2609
2610@noindent
2611If a breakpoint is conditional, @code{info break} shows the condition on
2612the line following the affected breakpoint; breakpoint commands, if any,
2613are listed after that.
2614
2615@noindent
2616@code{info break} with a breakpoint
2617number @var{n} as argument lists only that breakpoint. The
2618convenience variable @code{$_} and the default examining-address for
2619the @code{x} command are set to the address of the last breakpoint
5d161b24 2620listed (@pxref{Memory, ,Examining memory}).
c906108c
SS
2621
2622@noindent
2623@code{info break} displays a count of the number of times the breakpoint
2624has been hit. This is especially useful in conjunction with the
2625@code{ignore} command. You can ignore a large number of breakpoint
2626hits, look at the breakpoint info to see how many times the breakpoint
2627was hit, and then run again, ignoring one less than that number. This
2628will get you quickly to the last hit of that breakpoint.
2629@end table
2630
2631@value{GDBN} allows you to set any number of breakpoints at the same place in
2632your program. There is nothing silly or meaningless about this. When
2633the breakpoints are conditional, this is even useful
2634(@pxref{Conditions, ,Break conditions}).
2635
2636@cindex negative breakpoint numbers
2637@cindex internal @value{GDBN} breakpoints
eb12ee30
AC
2638@value{GDBN} itself sometimes sets breakpoints in your program for
2639special purposes, such as proper handling of @code{longjmp} (in C
2640programs). These internal breakpoints are assigned negative numbers,
2641starting with @code{-1}; @samp{info breakpoints} does not display them.
c906108c 2642You can see these breakpoints with the @value{GDBN} maintenance command
eb12ee30 2643@samp{maint info breakpoints} (@pxref{maint info breakpoints}).
c906108c
SS
2644
2645
6d2ebf8b 2646@node Set Watchpoints
c906108c
SS
2647@subsection Setting watchpoints
2648
2649@cindex setting watchpoints
2650@cindex software watchpoints
2651@cindex hardware watchpoints
2652You can use a watchpoint to stop execution whenever the value of an
2653expression changes, without having to predict a particular place where
2654this may happen.
2655
2656Depending on your system, watchpoints may be implemented in software or
2df3850c 2657hardware. @value{GDBN} does software watchpointing by single-stepping your
c906108c
SS
2658program and testing the variable's value each time, which is hundreds of
2659times slower than normal execution. (But this may still be worth it, to
2660catch errors where you have no clue what part of your program is the
2661culprit.)
2662
d4f3574e 2663On some systems, such as HP-UX, Linux and some other x86-based targets,
2df3850c 2664@value{GDBN} includes support for
c906108c
SS
2665hardware watchpoints, which do not slow down the running of your
2666program.
2667
2668@table @code
2669@kindex watch
2670@item watch @var{expr}
2671Set a watchpoint for an expression. @value{GDBN} will break when @var{expr}
2672is written into by the program and its value changes.
2673
2674@kindex rwatch
2675@item rwatch @var{expr}
2676Set a watchpoint that will break when watch @var{expr} is read by the program.
c906108c
SS
2677
2678@kindex awatch
2679@item awatch @var{expr}
2df3850c 2680Set a watchpoint that will break when @var{expr} is either read or written into
7be570e7 2681by the program.
c906108c
SS
2682
2683@kindex info watchpoints
2684@item info watchpoints
2685This command prints a list of watchpoints, breakpoints, and catchpoints;
2686it is the same as @code{info break}.
2687@end table
2688
2689@value{GDBN} sets a @dfn{hardware watchpoint} if possible. Hardware
2690watchpoints execute very quickly, and the debugger reports a change in
2691value at the exact instruction where the change occurs. If @value{GDBN}
2692cannot set a hardware watchpoint, it sets a software watchpoint, which
2693executes more slowly and reports the change in value at the next
2694statement, not the instruction, after the change occurs.
2695
2696When you issue the @code{watch} command, @value{GDBN} reports
2697
2698@example
2699Hardware watchpoint @var{num}: @var{expr}
2700@end example
2701
2702@noindent
2703if it was able to set a hardware watchpoint.
2704
7be570e7
JM
2705Currently, the @code{awatch} and @code{rwatch} commands can only set
2706hardware watchpoints, because accesses to data that don't change the
2707value of the watched expression cannot be detected without examining
2708every instruction as it is being executed, and @value{GDBN} does not do
2709that currently. If @value{GDBN} finds that it is unable to set a
2710hardware breakpoint with the @code{awatch} or @code{rwatch} command, it
2711will print a message like this:
2712
2713@smallexample
2714Expression cannot be implemented with read/access watchpoint.
2715@end smallexample
2716
2717Sometimes, @value{GDBN} cannot set a hardware watchpoint because the
2718data type of the watched expression is wider than what a hardware
2719watchpoint on the target machine can handle. For example, some systems
2720can only watch regions that are up to 4 bytes wide; on such systems you
2721cannot set hardware watchpoints for an expression that yields a
2722double-precision floating-point number (which is typically 8 bytes
2723wide). As a work-around, it might be possible to break the large region
2724into a series of smaller ones and watch them with separate watchpoints.
2725
2726If you set too many hardware watchpoints, @value{GDBN} might be unable
2727to insert all of them when you resume the execution of your program.
2728Since the precise number of active watchpoints is unknown until such
2729time as the program is about to be resumed, @value{GDBN} might not be
2730able to warn you about this when you set the watchpoints, and the
2731warning will be printed only when the program is resumed:
2732
2733@smallexample
2734Hardware watchpoint @var{num}: Could not insert watchpoint
2735@end smallexample
2736
2737@noindent
2738If this happens, delete or disable some of the watchpoints.
2739
2740The SPARClite DSU will generate traps when a program accesses some data
2741or instruction address that is assigned to the debug registers. For the
2742data addresses, DSU facilitates the @code{watch} command. However the
2743hardware breakpoint registers can only take two data watchpoints, and
2744both watchpoints must be the same kind. For example, you can set two
2745watchpoints with @code{watch} commands, two with @code{rwatch} commands,
2746@strong{or} two with @code{awatch} commands, but you cannot set one
2747watchpoint with one command and the other with a different command.
c906108c
SS
2748@value{GDBN} will reject the command if you try to mix watchpoints.
2749Delete or disable unused watchpoint commands before setting new ones.
2750
2751If you call a function interactively using @code{print} or @code{call},
2df3850c 2752any watchpoints you have set will be inactive until @value{GDBN} reaches another
c906108c
SS
2753kind of breakpoint or the call completes.
2754
7be570e7
JM
2755@value{GDBN} automatically deletes watchpoints that watch local
2756(automatic) variables, or expressions that involve such variables, when
2757they go out of scope, that is, when the execution leaves the block in
2758which these variables were defined. In particular, when the program
2759being debugged terminates, @emph{all} local variables go out of scope,
2760and so only watchpoints that watch global variables remain set. If you
2761rerun the program, you will need to set all such watchpoints again. One
2762way of doing that would be to set a code breakpoint at the entry to the
2763@code{main} function and when it breaks, set all the watchpoints.
2764
c906108c
SS
2765@quotation
2766@cindex watchpoints and threads
2767@cindex threads and watchpoints
c906108c
SS
2768@emph{Warning:} In multi-thread programs, watchpoints have only limited
2769usefulness. With the current watchpoint implementation, @value{GDBN}
2770can only watch the value of an expression @emph{in a single thread}. If
2771you are confident that the expression can only change due to the current
2772thread's activity (and if you are also confident that no other thread
2773can become current), then you can use watchpoints as usual. However,
2774@value{GDBN} may not notice when a non-current thread's activity changes
2775the expression.
53a5351d 2776
d4f3574e 2777@c FIXME: this is almost identical to the previous paragraph.
53a5351d
JM
2778@emph{HP-UX Warning:} In multi-thread programs, software watchpoints
2779have only limited usefulness. If @value{GDBN} creates a software
2780watchpoint, it can only watch the value of an expression @emph{in a
2781single thread}. If you are confident that the expression can only
2782change due to the current thread's activity (and if you are also
2783confident that no other thread can become current), then you can use
2784software watchpoints as usual. However, @value{GDBN} may not notice
2785when a non-current thread's activity changes the expression. (Hardware
2786watchpoints, in contrast, watch an expression in all threads.)
c906108c 2787@end quotation
c906108c 2788
6d2ebf8b 2789@node Set Catchpoints
c906108c 2790@subsection Setting catchpoints
d4f3574e 2791@cindex catchpoints, setting
c906108c
SS
2792@cindex exception handlers
2793@cindex event handling
2794
2795You can use @dfn{catchpoints} to cause the debugger to stop for certain
b37052ae 2796kinds of program events, such as C@t{++} exceptions or the loading of a
c906108c
SS
2797shared library. Use the @code{catch} command to set a catchpoint.
2798
2799@table @code
2800@kindex catch
2801@item catch @var{event}
2802Stop when @var{event} occurs. @var{event} can be any of the following:
2803@table @code
2804@item throw
2805@kindex catch throw
b37052ae 2806The throwing of a C@t{++} exception.
c906108c
SS
2807
2808@item catch
2809@kindex catch catch
b37052ae 2810The catching of a C@t{++} exception.
c906108c
SS
2811
2812@item exec
2813@kindex catch exec
2814A call to @code{exec}. This is currently only available for HP-UX.
2815
2816@item fork
2817@kindex catch fork
2818A call to @code{fork}. This is currently only available for HP-UX.
2819
2820@item vfork
2821@kindex catch vfork
2822A call to @code{vfork}. This is currently only available for HP-UX.
2823
2824@item load
2825@itemx load @var{libname}
2826@kindex catch load
2827The dynamic loading of any shared library, or the loading of the library
2828@var{libname}. This is currently only available for HP-UX.
2829
2830@item unload
2831@itemx unload @var{libname}
2832@kindex catch unload
2833The unloading of any dynamically loaded shared library, or the unloading
2834of the library @var{libname}. This is currently only available for HP-UX.
2835@end table
2836
2837@item tcatch @var{event}
2838Set a catchpoint that is enabled only for one stop. The catchpoint is
2839automatically deleted after the first time the event is caught.
2840
2841@end table
2842
2843Use the @code{info break} command to list the current catchpoints.
2844
b37052ae 2845There are currently some limitations to C@t{++} exception handling
c906108c
SS
2846(@code{catch throw} and @code{catch catch}) in @value{GDBN}:
2847
2848@itemize @bullet
2849@item
2850If you call a function interactively, @value{GDBN} normally returns
2851control to you when the function has finished executing. If the call
2852raises an exception, however, the call may bypass the mechanism that
2853returns control to you and cause your program either to abort or to
2854simply continue running until it hits a breakpoint, catches a signal
2855that @value{GDBN} is listening for, or exits. This is the case even if
2856you set a catchpoint for the exception; catchpoints on exceptions are
2857disabled within interactive calls.
2858
2859@item
2860You cannot raise an exception interactively.
2861
2862@item
2863You cannot install an exception handler interactively.
2864@end itemize
2865
2866@cindex raise exceptions
2867Sometimes @code{catch} is not the best way to debug exception handling:
2868if you need to know exactly where an exception is raised, it is better to
2869stop @emph{before} the exception handler is called, since that way you
2870can see the stack before any unwinding takes place. If you set a
2871breakpoint in an exception handler instead, it may not be easy to find
2872out where the exception was raised.
2873
2874To stop just before an exception handler is called, you need some
b37052ae 2875knowledge of the implementation. In the case of @sc{gnu} C@t{++}, exceptions are
c906108c
SS
2876raised by calling a library function named @code{__raise_exception}
2877which has the following ANSI C interface:
2878
2879@example
2880 /* @var{addr} is where the exception identifier is stored.
d4f3574e
SS
2881 @var{id} is the exception identifier. */
2882 void __raise_exception (void **addr, void *id);
c906108c
SS
2883@end example
2884
2885@noindent
2886To make the debugger catch all exceptions before any stack
2887unwinding takes place, set a breakpoint on @code{__raise_exception}
2888(@pxref{Breakpoints, ,Breakpoints; watchpoints; and exceptions}).
2889
2890With a conditional breakpoint (@pxref{Conditions, ,Break conditions})
2891that depends on the value of @var{id}, you can stop your program when
2892a specific exception is raised. You can use multiple conditional
2893breakpoints to stop your program when any of a number of exceptions are
2894raised.
2895
2896
6d2ebf8b 2897@node Delete Breaks
c906108c
SS
2898@subsection Deleting breakpoints
2899
2900@cindex clearing breakpoints, watchpoints, catchpoints
2901@cindex deleting breakpoints, watchpoints, catchpoints
2902It is often necessary to eliminate a breakpoint, watchpoint, or
2903catchpoint once it has done its job and you no longer want your program
2904to stop there. This is called @dfn{deleting} the breakpoint. A
2905breakpoint that has been deleted no longer exists; it is forgotten.
2906
2907With the @code{clear} command you can delete breakpoints according to
2908where they are in your program. With the @code{delete} command you can
2909delete individual breakpoints, watchpoints, or catchpoints by specifying
2910their breakpoint numbers.
2911
2912It is not necessary to delete a breakpoint to proceed past it. @value{GDBN}
2913automatically ignores breakpoints on the first instruction to be executed
2914when you continue execution without changing the execution address.
2915
2916@table @code
2917@kindex clear
2918@item clear
2919Delete any breakpoints at the next instruction to be executed in the
2920selected stack frame (@pxref{Selection, ,Selecting a frame}). When
2921the innermost frame is selected, this is a good way to delete a
2922breakpoint where your program just stopped.
2923
2924@item clear @var{function}
2925@itemx clear @var{filename}:@var{function}
2926Delete any breakpoints set at entry to the function @var{function}.
2927
2928@item clear @var{linenum}
2929@itemx clear @var{filename}:@var{linenum}
2930Delete any breakpoints set at or within the code of the specified line.
2931
2932@cindex delete breakpoints
2933@kindex delete
41afff9a 2934@kindex d @r{(@code{delete})}
c5394b80
JM
2935@item delete @r{[}breakpoints@r{]} @r{[}@var{range}@dots{}@r{]}
2936Delete the breakpoints, watchpoints, or catchpoints of the breakpoint
2937ranges specified as arguments. If no argument is specified, delete all
c906108c
SS
2938breakpoints (@value{GDBN} asks confirmation, unless you have @code{set
2939confirm off}). You can abbreviate this command as @code{d}.
2940@end table
2941
6d2ebf8b 2942@node Disabling
c906108c
SS
2943@subsection Disabling breakpoints
2944
2945@kindex disable breakpoints
2946@kindex enable breakpoints
2947Rather than deleting a breakpoint, watchpoint, or catchpoint, you might
2948prefer to @dfn{disable} it. This makes the breakpoint inoperative as if
2949it had been deleted, but remembers the information on the breakpoint so
2950that you can @dfn{enable} it again later.
2951
2952You disable and enable breakpoints, watchpoints, and catchpoints with
2953the @code{enable} and @code{disable} commands, optionally specifying one
2954or more breakpoint numbers as arguments. Use @code{info break} or
2955@code{info watch} to print a list of breakpoints, watchpoints, and
2956catchpoints if you do not know which numbers to use.
2957
2958A breakpoint, watchpoint, or catchpoint can have any of four different
2959states of enablement:
2960
2961@itemize @bullet
2962@item
2963Enabled. The breakpoint stops your program. A breakpoint set
2964with the @code{break} command starts out in this state.
2965@item
2966Disabled. The breakpoint has no effect on your program.
2967@item
2968Enabled once. The breakpoint stops your program, but then becomes
d4f3574e 2969disabled.
c906108c
SS
2970@item
2971Enabled for deletion. The breakpoint stops your program, but
d4f3574e
SS
2972immediately after it does so it is deleted permanently. A breakpoint
2973set with the @code{tbreak} command starts out in this state.
c906108c
SS
2974@end itemize
2975
2976You can use the following commands to enable or disable breakpoints,
2977watchpoints, and catchpoints:
2978
2979@table @code
2980@kindex disable breakpoints
2981@kindex disable
41afff9a 2982@kindex dis @r{(@code{disable})}
c5394b80 2983@item disable @r{[}breakpoints@r{]} @r{[}@var{range}@dots{}@r{]}
c906108c
SS
2984Disable the specified breakpoints---or all breakpoints, if none are
2985listed. A disabled breakpoint has no effect but is not forgotten. All
2986options such as ignore-counts, conditions and commands are remembered in
2987case the breakpoint is enabled again later. You may abbreviate
2988@code{disable} as @code{dis}.
2989
2990@kindex enable breakpoints
2991@kindex enable
c5394b80 2992@item enable @r{[}breakpoints@r{]} @r{[}@var{range}@dots{}@r{]}
c906108c
SS
2993Enable the specified breakpoints (or all defined breakpoints). They
2994become effective once again in stopping your program.
2995
c5394b80 2996@item enable @r{[}breakpoints@r{]} once @var{range}@dots{}
c906108c
SS
2997Enable the specified breakpoints temporarily. @value{GDBN} disables any
2998of these breakpoints immediately after stopping your program.
2999
c5394b80 3000@item enable @r{[}breakpoints@r{]} delete @var{range}@dots{}
c906108c
SS
3001Enable the specified breakpoints to work once, then die. @value{GDBN}
3002deletes any of these breakpoints as soon as your program stops there.
3003@end table
3004
d4f3574e
SS
3005@c FIXME: I think the following ``Except for [...] @code{tbreak}'' is
3006@c confusing: tbreak is also initially enabled.
c906108c
SS
3007Except for a breakpoint set with @code{tbreak} (@pxref{Set Breaks,
3008,Setting breakpoints}), breakpoints that you set are initially enabled;
3009subsequently, they become disabled or enabled only when you use one of
3010the commands above. (The command @code{until} can set and delete a
3011breakpoint of its own, but it does not change the state of your other
3012breakpoints; see @ref{Continuing and Stepping, ,Continuing and
3013stepping}.)
3014
6d2ebf8b 3015@node Conditions
c906108c
SS
3016@subsection Break conditions
3017@cindex conditional breakpoints
3018@cindex breakpoint conditions
3019
3020@c FIXME what is scope of break condition expr? Context where wanted?
5d161b24 3021@c in particular for a watchpoint?
c906108c
SS
3022The simplest sort of breakpoint breaks every time your program reaches a
3023specified place. You can also specify a @dfn{condition} for a
3024breakpoint. A condition is just a Boolean expression in your
3025programming language (@pxref{Expressions, ,Expressions}). A breakpoint with
3026a condition evaluates the expression each time your program reaches it,
3027and your program stops only if the condition is @emph{true}.
3028
3029This is the converse of using assertions for program validation; in that
3030situation, you want to stop when the assertion is violated---that is,
3031when the condition is false. In C, if you want to test an assertion expressed
3032by the condition @var{assert}, you should set the condition
3033@samp{! @var{assert}} on the appropriate breakpoint.
3034
3035Conditions are also accepted for watchpoints; you may not need them,
3036since a watchpoint is inspecting the value of an expression anyhow---but
3037it might be simpler, say, to just set a watchpoint on a variable name,
3038and specify a condition that tests whether the new value is an interesting
3039one.
3040
3041Break conditions can have side effects, and may even call functions in
3042your program. This can be useful, for example, to activate functions
3043that log program progress, or to use your own print functions to
3044format special data structures. The effects are completely predictable
3045unless there is another enabled breakpoint at the same address. (In
3046that case, @value{GDBN} might see the other breakpoint first and stop your
3047program without checking the condition of this one.) Note that
d4f3574e
SS
3048breakpoint commands are usually more convenient and flexible than break
3049conditions for the
c906108c
SS
3050purpose of performing side effects when a breakpoint is reached
3051(@pxref{Break Commands, ,Breakpoint command lists}).
3052
3053Break conditions can be specified when a breakpoint is set, by using
3054@samp{if} in the arguments to the @code{break} command. @xref{Set
3055Breaks, ,Setting breakpoints}. They can also be changed at any time
3056with the @code{condition} command.
53a5351d 3057
c906108c
SS
3058You can also use the @code{if} keyword with the @code{watch} command.
3059The @code{catch} command does not recognize the @code{if} keyword;
3060@code{condition} is the only way to impose a further condition on a
3061catchpoint.
c906108c
SS
3062
3063@table @code
3064@kindex condition
3065@item condition @var{bnum} @var{expression}
3066Specify @var{expression} as the break condition for breakpoint,
3067watchpoint, or catchpoint number @var{bnum}. After you set a condition,
3068breakpoint @var{bnum} stops your program only if the value of
3069@var{expression} is true (nonzero, in C). When you use
3070@code{condition}, @value{GDBN} checks @var{expression} immediately for
3071syntactic correctness, and to determine whether symbols in it have
d4f3574e
SS
3072referents in the context of your breakpoint. If @var{expression} uses
3073symbols not referenced in the context of the breakpoint, @value{GDBN}
3074prints an error message:
3075
3076@example
3077No symbol "foo" in current context.
3078@end example
3079
3080@noindent
c906108c
SS
3081@value{GDBN} does
3082not actually evaluate @var{expression} at the time the @code{condition}
d4f3574e
SS
3083command (or a command that sets a breakpoint with a condition, like
3084@code{break if @dots{}}) is given, however. @xref{Expressions, ,Expressions}.
c906108c
SS
3085
3086@item condition @var{bnum}
3087Remove the condition from breakpoint number @var{bnum}. It becomes
3088an ordinary unconditional breakpoint.
3089@end table
3090
3091@cindex ignore count (of breakpoint)
3092A special case of a breakpoint condition is to stop only when the
3093breakpoint has been reached a certain number of times. This is so
3094useful that there is a special way to do it, using the @dfn{ignore
3095count} of the breakpoint. Every breakpoint has an ignore count, which
3096is an integer. Most of the time, the ignore count is zero, and
3097therefore has no effect. But if your program reaches a breakpoint whose
3098ignore count is positive, then instead of stopping, it just decrements
3099the ignore count by one and continues. As a result, if the ignore count
3100value is @var{n}, the breakpoint does not stop the next @var{n} times
3101your program reaches it.
3102
3103@table @code
3104@kindex ignore
3105@item ignore @var{bnum} @var{count}
3106Set the ignore count of breakpoint number @var{bnum} to @var{count}.
3107The next @var{count} times the breakpoint is reached, your program's
3108execution does not stop; other than to decrement the ignore count, @value{GDBN}
3109takes no action.
3110
3111To make the breakpoint stop the next time it is reached, specify
3112a count of zero.
3113
3114When you use @code{continue} to resume execution of your program from a
3115breakpoint, you can specify an ignore count directly as an argument to
3116@code{continue}, rather than using @code{ignore}. @xref{Continuing and
3117Stepping,,Continuing and stepping}.
3118
3119If a breakpoint has a positive ignore count and a condition, the
3120condition is not checked. Once the ignore count reaches zero,
3121@value{GDBN} resumes checking the condition.
3122
3123You could achieve the effect of the ignore count with a condition such
3124as @w{@samp{$foo-- <= 0}} using a debugger convenience variable that
3125is decremented each time. @xref{Convenience Vars, ,Convenience
3126variables}.
3127@end table
3128
3129Ignore counts apply to breakpoints, watchpoints, and catchpoints.
3130
3131
6d2ebf8b 3132@node Break Commands
c906108c
SS
3133@subsection Breakpoint command lists
3134
3135@cindex breakpoint commands
3136You can give any breakpoint (or watchpoint or catchpoint) a series of
3137commands to execute when your program stops due to that breakpoint. For
3138example, you might want to print the values of certain expressions, or
3139enable other breakpoints.
3140
3141@table @code
3142@kindex commands
3143@kindex end
3144@item commands @r{[}@var{bnum}@r{]}
3145@itemx @dots{} @var{command-list} @dots{}
3146@itemx end
3147Specify a list of commands for breakpoint number @var{bnum}. The commands
3148themselves appear on the following lines. Type a line containing just
3149@code{end} to terminate the commands.
3150
3151To remove all commands from a breakpoint, type @code{commands} and
3152follow it immediately with @code{end}; that is, give no commands.
3153
3154With no @var{bnum} argument, @code{commands} refers to the last
3155breakpoint, watchpoint, or catchpoint set (not to the breakpoint most
3156recently encountered).
3157@end table
3158
3159Pressing @key{RET} as a means of repeating the last @value{GDBN} command is
3160disabled within a @var{command-list}.
3161
3162You can use breakpoint commands to start your program up again. Simply
3163use the @code{continue} command, or @code{step}, or any other command
3164that resumes execution.
3165
3166Any other commands in the command list, after a command that resumes
3167execution, are ignored. This is because any time you resume execution
3168(even with a simple @code{next} or @code{step}), you may encounter
3169another breakpoint---which could have its own command list, leading to
3170ambiguities about which list to execute.
3171
3172@kindex silent
3173If the first command you specify in a command list is @code{silent}, the
3174usual message about stopping at a breakpoint is not printed. This may
3175be desirable for breakpoints that are to print a specific message and
3176then continue. If none of the remaining commands print anything, you
3177see no sign that the breakpoint was reached. @code{silent} is
3178meaningful only at the beginning of a breakpoint command list.
3179
3180The commands @code{echo}, @code{output}, and @code{printf} allow you to
3181print precisely controlled output, and are often useful in silent
3182breakpoints. @xref{Output, ,Commands for controlled output}.
3183
3184For example, here is how you could use breakpoint commands to print the
3185value of @code{x} at entry to @code{foo} whenever @code{x} is positive.
3186
3187@example
3188break foo if x>0
3189commands
3190silent
3191printf "x is %d\n",x
3192cont
3193end
3194@end example
3195
3196One application for breakpoint commands is to compensate for one bug so
3197you can test for another. Put a breakpoint just after the erroneous line
3198of code, give it a condition to detect the case in which something
3199erroneous has been done, and give it commands to assign correct values
3200to any variables that need them. End with the @code{continue} command
3201so that your program does not stop, and start with the @code{silent}
3202command so that no output is produced. Here is an example:
3203
3204@example
3205break 403
3206commands
3207silent
3208set x = y + 4
3209cont
3210end
3211@end example
3212
6d2ebf8b 3213@node Breakpoint Menus
c906108c
SS
3214@subsection Breakpoint menus
3215@cindex overloading
3216@cindex symbol overloading
3217
b37052ae 3218Some programming languages (notably C@t{++}) permit a single function name
c906108c
SS
3219to be defined several times, for application in different contexts.
3220This is called @dfn{overloading}. When a function name is overloaded,
3221@samp{break @var{function}} is not enough to tell @value{GDBN} where you want
3222a breakpoint. If you realize this is a problem, you can use
3223something like @samp{break @var{function}(@var{types})} to specify which
3224particular version of the function you want. Otherwise, @value{GDBN} offers
3225you a menu of numbered choices for different possible breakpoints, and
3226waits for your selection with the prompt @samp{>}. The first two
3227options are always @samp{[0] cancel} and @samp{[1] all}. Typing @kbd{1}
3228sets a breakpoint at each definition of @var{function}, and typing
3229@kbd{0} aborts the @code{break} command without setting any new
3230breakpoints.
3231
3232For example, the following session excerpt shows an attempt to set a
3233breakpoint at the overloaded symbol @code{String::after}.
3234We choose three particular definitions of that function name:
3235
3236@c FIXME! This is likely to change to show arg type lists, at least
3237@smallexample
3238@group
3239(@value{GDBP}) b String::after
3240[0] cancel
3241[1] all
3242[2] file:String.cc; line number:867
3243[3] file:String.cc; line number:860
3244[4] file:String.cc; line number:875
3245[5] file:String.cc; line number:853
3246[6] file:String.cc; line number:846
3247[7] file:String.cc; line number:735
3248> 2 4 6
3249Breakpoint 1 at 0xb26c: file String.cc, line 867.
3250Breakpoint 2 at 0xb344: file String.cc, line 875.
3251Breakpoint 3 at 0xafcc: file String.cc, line 846.
3252Multiple breakpoints were set.
3253Use the "delete" command to delete unwanted
3254 breakpoints.
3255(@value{GDBP})
3256@end group
3257@end smallexample
c906108c
SS
3258
3259@c @ifclear BARETARGET
6d2ebf8b 3260@node Error in Breakpoints
d4f3574e 3261@subsection ``Cannot insert breakpoints''
c906108c
SS
3262@c
3263@c FIXME!! 14/6/95 Is there a real example of this? Let's use it.
3264@c
d4f3574e
SS
3265Under some operating systems, breakpoints cannot be used in a program if
3266any other process is running that program. In this situation,
5d161b24 3267attempting to run or continue a program with a breakpoint causes
d4f3574e
SS
3268@value{GDBN} to print an error message:
3269
3270@example
3271Cannot insert breakpoints.
3272The same program may be running in another process.
3273@end example
3274
3275When this happens, you have three ways to proceed:
3276
3277@enumerate
3278@item
3279Remove or disable the breakpoints, then continue.
3280
3281@item
5d161b24 3282Suspend @value{GDBN}, and copy the file containing your program to a new
d4f3574e 3283name. Resume @value{GDBN} and use the @code{exec-file} command to specify
5d161b24 3284that @value{GDBN} should run your program under that name.
d4f3574e
SS
3285Then start your program again.
3286
3287@item
3288Relink your program so that the text segment is nonsharable, using the
3289linker option @samp{-N}. The operating system limitation may not apply
3290to nonsharable executables.
3291@end enumerate
c906108c
SS
3292@c @end ifclear
3293
d4f3574e
SS
3294A similar message can be printed if you request too many active
3295hardware-assisted breakpoints and watchpoints:
3296
3297@c FIXME: the precise wording of this message may change; the relevant
3298@c source change is not committed yet (Sep 3, 1999).
3299@smallexample
3300Stopped; cannot insert breakpoints.
3301You may have requested too many hardware breakpoints and watchpoints.
3302@end smallexample
3303
3304@noindent
3305This message is printed when you attempt to resume the program, since
3306only then @value{GDBN} knows exactly how many hardware breakpoints and
3307watchpoints it needs to insert.
3308
3309When this message is printed, you need to disable or remove some of the
3310hardware-assisted breakpoints and watchpoints, and then continue.
3311
3312
6d2ebf8b 3313@node Continuing and Stepping
c906108c
SS
3314@section Continuing and stepping
3315
3316@cindex stepping
3317@cindex continuing
3318@cindex resuming execution
3319@dfn{Continuing} means resuming program execution until your program
3320completes normally. In contrast, @dfn{stepping} means executing just
3321one more ``step'' of your program, where ``step'' may mean either one
3322line of source code, or one machine instruction (depending on what
7a292a7a
SS
3323particular command you use). Either when continuing or when stepping,
3324your program may stop even sooner, due to a breakpoint or a signal. (If
d4f3574e
SS
3325it stops due to a signal, you may want to use @code{handle}, or use
3326@samp{signal 0} to resume execution. @xref{Signals, ,Signals}.)
c906108c
SS
3327
3328@table @code
3329@kindex continue
41afff9a
EZ
3330@kindex c @r{(@code{continue})}
3331@kindex fg @r{(resume foreground execution)}
c906108c
SS
3332@item continue @r{[}@var{ignore-count}@r{]}
3333@itemx c @r{[}@var{ignore-count}@r{]}
3334@itemx fg @r{[}@var{ignore-count}@r{]}
3335Resume program execution, at the address where your program last stopped;
3336any breakpoints set at that address are bypassed. The optional argument
3337@var{ignore-count} allows you to specify a further number of times to
3338ignore a breakpoint at this location; its effect is like that of
3339@code{ignore} (@pxref{Conditions, ,Break conditions}).
3340
3341The argument @var{ignore-count} is meaningful only when your program
3342stopped due to a breakpoint. At other times, the argument to
3343@code{continue} is ignored.
3344
d4f3574e
SS
3345The synonyms @code{c} and @code{fg} (for @dfn{foreground}, as the
3346debugged program is deemed to be the foreground program) are provided
3347purely for convenience, and have exactly the same behavior as
3348@code{continue}.
c906108c
SS
3349@end table
3350
3351To resume execution at a different place, you can use @code{return}
3352(@pxref{Returning, ,Returning from a function}) to go back to the
3353calling function; or @code{jump} (@pxref{Jumping, ,Continuing at a
3354different address}) to go to an arbitrary location in your program.
3355
3356A typical technique for using stepping is to set a breakpoint
3357(@pxref{Breakpoints, ,Breakpoints; watchpoints; and catchpoints}) at the
3358beginning of the function or the section of your program where a problem
3359is believed to lie, run your program until it stops at that breakpoint,
3360and then step through the suspect area, examining the variables that are
3361interesting, until you see the problem happen.
3362
3363@table @code
3364@kindex step
41afff9a 3365@kindex s @r{(@code{step})}
c906108c
SS
3366@item step
3367Continue running your program until control reaches a different source
3368line, then stop it and return control to @value{GDBN}. This command is
3369abbreviated @code{s}.
3370
3371@quotation
3372@c "without debugging information" is imprecise; actually "without line
3373@c numbers in the debugging information". (gcc -g1 has debugging info but
3374@c not line numbers). But it seems complex to try to make that
3375@c distinction here.
3376@emph{Warning:} If you use the @code{step} command while control is
3377within a function that was compiled without debugging information,
3378execution proceeds until control reaches a function that does have
3379debugging information. Likewise, it will not step into a function which
3380is compiled without debugging information. To step through functions
3381without debugging information, use the @code{stepi} command, described
3382below.
3383@end quotation
3384
4a92d011
EZ
3385The @code{step} command only stops at the first instruction of a source
3386line. This prevents the multiple stops that could otherwise occur in
3387@code{switch} statements, @code{for} loops, etc. @code{step} continues
3388to stop if a function that has debugging information is called within
3389the line. In other words, @code{step} @emph{steps inside} any functions
3390called within the line.
c906108c 3391
d4f3574e
SS
3392Also, the @code{step} command only enters a function if there is line
3393number information for the function. Otherwise it acts like the
5d161b24 3394@code{next} command. This avoids problems when using @code{cc -gl}
c906108c 3395on MIPS machines. Previously, @code{step} entered subroutines if there
5d161b24 3396was any debugging information about the routine.
c906108c
SS
3397
3398@item step @var{count}
3399Continue running as in @code{step}, but do so @var{count} times. If a
7a292a7a
SS
3400breakpoint is reached, or a signal not related to stepping occurs before
3401@var{count} steps, stepping stops right away.
c906108c
SS
3402
3403@kindex next
41afff9a 3404@kindex n @r{(@code{next})}
c906108c
SS
3405@item next @r{[}@var{count}@r{]}
3406Continue to the next source line in the current (innermost) stack frame.
7a292a7a
SS
3407This is similar to @code{step}, but function calls that appear within
3408the line of code are executed without stopping. Execution stops when
3409control reaches a different line of code at the original stack level
3410that was executing when you gave the @code{next} command. This command
3411is abbreviated @code{n}.
c906108c
SS
3412
3413An argument @var{count} is a repeat count, as for @code{step}.
3414
3415
3416@c FIX ME!! Do we delete this, or is there a way it fits in with
3417@c the following paragraph? --- Vctoria
3418@c
3419@c @code{next} within a function that lacks debugging information acts like
3420@c @code{step}, but any function calls appearing within the code of the
3421@c function are executed without stopping.
3422
d4f3574e
SS
3423The @code{next} command only stops at the first instruction of a
3424source line. This prevents multiple stops that could otherwise occur in
4a92d011 3425@code{switch} statements, @code{for} loops, etc.
c906108c 3426
b90a5f51
CF
3427@kindex set step-mode
3428@item set step-mode
3429@cindex functions without line info, and stepping
3430@cindex stepping into functions with no line info
3431@itemx set step-mode on
4a92d011 3432The @code{set step-mode on} command causes the @code{step} command to
b90a5f51
CF
3433stop at the first instruction of a function which contains no debug line
3434information rather than stepping over it.
3435
4a92d011
EZ
3436This is useful in cases where you may be interested in inspecting the
3437machine instructions of a function which has no symbolic info and do not
3438want @value{GDBN} to automatically skip over this function.
b90a5f51
CF
3439
3440@item set step-mode off
4a92d011 3441Causes the @code{step} command to step over any functions which contains no
b90a5f51
CF
3442debug information. This is the default.
3443
c906108c
SS
3444@kindex finish
3445@item finish
3446Continue running until just after function in the selected stack frame
3447returns. Print the returned value (if any).
3448
3449Contrast this with the @code{return} command (@pxref{Returning,
3450,Returning from a function}).
3451
3452@kindex until
41afff9a 3453@kindex u @r{(@code{until})}
c906108c
SS
3454@item until
3455@itemx u
3456Continue running until a source line past the current line, in the
3457current stack frame, is reached. This command is used to avoid single
3458stepping through a loop more than once. It is like the @code{next}
3459command, except that when @code{until} encounters a jump, it
3460automatically continues execution until the program counter is greater
3461than the address of the jump.
3462
3463This means that when you reach the end of a loop after single stepping
3464though it, @code{until} makes your program continue execution until it
3465exits the loop. In contrast, a @code{next} command at the end of a loop
3466simply steps back to the beginning of the loop, which forces you to step
3467through the next iteration.
3468
3469@code{until} always stops your program if it attempts to exit the current
3470stack frame.
3471
3472@code{until} may produce somewhat counterintuitive results if the order
3473of machine code does not match the order of the source lines. For
3474example, in the following excerpt from a debugging session, the @code{f}
3475(@code{frame}) command shows that execution is stopped at line
3476@code{206}; yet when we use @code{until}, we get to line @code{195}:
3477
3478@example
3479(@value{GDBP}) f
3480#0 main (argc=4, argv=0xf7fffae8) at m4.c:206
3481206 expand_input();
3482(@value{GDBP}) until
3483195 for ( ; argc > 0; NEXTARG) @{
3484@end example
3485
3486This happened because, for execution efficiency, the compiler had
3487generated code for the loop closure test at the end, rather than the
3488start, of the loop---even though the test in a C @code{for}-loop is
3489written before the body of the loop. The @code{until} command appeared
3490to step back to the beginning of the loop when it advanced to this
3491expression; however, it has not really gone to an earlier
3492statement---not in terms of the actual machine code.
3493
3494@code{until} with no argument works by means of single
3495instruction stepping, and hence is slower than @code{until} with an
3496argument.
3497
3498@item until @var{location}
3499@itemx u @var{location}
3500Continue running your program until either the specified location is
3501reached, or the current stack frame returns. @var{location} is any of
3502the forms of argument acceptable to @code{break} (@pxref{Set Breaks,
3503,Setting breakpoints}). This form of the command uses breakpoints,
3504and hence is quicker than @code{until} without an argument.
3505
3506@kindex stepi
41afff9a 3507@kindex si @r{(@code{stepi})}
c906108c 3508@item stepi
96a2c332 3509@itemx stepi @var{arg}
c906108c
SS
3510@itemx si
3511Execute one machine instruction, then stop and return to the debugger.
3512
3513It is often useful to do @samp{display/i $pc} when stepping by machine
3514instructions. This makes @value{GDBN} automatically display the next
3515instruction to be executed, each time your program stops. @xref{Auto
3516Display,, Automatic display}.
3517
3518An argument is a repeat count, as in @code{step}.
3519
3520@need 750
3521@kindex nexti
41afff9a 3522@kindex ni @r{(@code{nexti})}
c906108c 3523@item nexti
96a2c332 3524@itemx nexti @var{arg}
c906108c
SS
3525@itemx ni
3526Execute one machine instruction, but if it is a function call,
3527proceed until the function returns.
3528
3529An argument is a repeat count, as in @code{next}.
3530@end table
3531
6d2ebf8b 3532@node Signals
c906108c
SS
3533@section Signals
3534@cindex signals
3535
3536A signal is an asynchronous event that can happen in a program. The
3537operating system defines the possible kinds of signals, and gives each
3538kind a name and a number. For example, in Unix @code{SIGINT} is the
d4f3574e 3539signal a program gets when you type an interrupt character (often @kbd{C-c});
c906108c
SS
3540@code{SIGSEGV} is the signal a program gets from referencing a place in
3541memory far away from all the areas in use; @code{SIGALRM} occurs when
3542the alarm clock timer goes off (which happens only if your program has
3543requested an alarm).
3544
3545@cindex fatal signals
3546Some signals, including @code{SIGALRM}, are a normal part of the
3547functioning of your program. Others, such as @code{SIGSEGV}, indicate
d4f3574e 3548errors; these signals are @dfn{fatal} (they kill your program immediately) if the
c906108c
SS
3549program has not specified in advance some other way to handle the signal.
3550@code{SIGINT} does not indicate an error in your program, but it is normally
3551fatal so it can carry out the purpose of the interrupt: to kill the program.
3552
3553@value{GDBN} has the ability to detect any occurrence of a signal in your
3554program. You can tell @value{GDBN} in advance what to do for each kind of
3555signal.
3556
3557@cindex handling signals
24f93129
EZ
3558Normally, @value{GDBN} is set up to let the non-erroneous signals like
3559@code{SIGALRM} be silently passed to your program
3560(so as not to interfere with their role in the program's functioning)
c906108c
SS
3561but to stop your program immediately whenever an error signal happens.
3562You can change these settings with the @code{handle} command.
3563
3564@table @code
3565@kindex info signals
3566@item info signals
96a2c332 3567@itemx info handle
c906108c
SS
3568Print a table of all the kinds of signals and how @value{GDBN} has been told to
3569handle each one. You can use this to see the signal numbers of all
3570the defined types of signals.
3571
d4f3574e 3572@code{info handle} is an alias for @code{info signals}.
c906108c
SS
3573
3574@kindex handle
3575@item handle @var{signal} @var{keywords}@dots{}
5ece1a18
EZ
3576Change the way @value{GDBN} handles signal @var{signal}. @var{signal}
3577can be the number of a signal or its name (with or without the
24f93129 3578@samp{SIG} at the beginning); a list of signal numbers of the form
5ece1a18
EZ
3579@samp{@var{low}-@var{high}}; or the word @samp{all}, meaning all the
3580known signals. The @var{keywords} say what change to make.
c906108c
SS
3581@end table
3582
3583@c @group
3584The keywords allowed by the @code{handle} command can be abbreviated.
3585Their full names are:
3586
3587@table @code
3588@item nostop
3589@value{GDBN} should not stop your program when this signal happens. It may
3590still print a message telling you that the signal has come in.
3591
3592@item stop
3593@value{GDBN} should stop your program when this signal happens. This implies
3594the @code{print} keyword as well.
3595
3596@item print
3597@value{GDBN} should print a message when this signal happens.
3598
3599@item noprint
3600@value{GDBN} should not mention the occurrence of the signal at all. This
3601implies the @code{nostop} keyword as well.
3602
3603@item pass
5ece1a18 3604@itemx noignore
c906108c
SS
3605@value{GDBN} should allow your program to see this signal; your program
3606can handle the signal, or else it may terminate if the signal is fatal
5ece1a18 3607and not handled. @code{pass} and @code{noignore} are synonyms.
c906108c
SS
3608
3609@item nopass
5ece1a18 3610@itemx ignore
c906108c 3611@value{GDBN} should not allow your program to see this signal.
5ece1a18 3612@code{nopass} and @code{ignore} are synonyms.
c906108c
SS
3613@end table
3614@c @end group
3615
d4f3574e
SS
3616When a signal stops your program, the signal is not visible to the
3617program until you
c906108c
SS
3618continue. Your program sees the signal then, if @code{pass} is in
3619effect for the signal in question @emph{at that time}. In other words,
3620after @value{GDBN} reports a signal, you can use the @code{handle}
3621command with @code{pass} or @code{nopass} to control whether your
3622program sees that signal when you continue.
3623
24f93129
EZ
3624The default is set to @code{nostop}, @code{noprint}, @code{pass} for
3625non-erroneous signals such as @code{SIGALRM}, @code{SIGWINCH} and
3626@code{SIGCHLD}, and to @code{stop}, @code{print}, @code{pass} for the
3627erroneous signals.
3628
c906108c
SS
3629You can also use the @code{signal} command to prevent your program from
3630seeing a signal, or cause it to see a signal it normally would not see,
3631or to give it any signal at any time. For example, if your program stopped
3632due to some sort of memory reference error, you might store correct
3633values into the erroneous variables and continue, hoping to see more
3634execution; but your program would probably terminate immediately as
3635a result of the fatal signal once it saw the signal. To prevent this,
3636you can continue with @samp{signal 0}. @xref{Signaling, ,Giving your
5d161b24 3637program a signal}.
c906108c 3638
6d2ebf8b 3639@node Thread Stops
c906108c
SS
3640@section Stopping and starting multi-thread programs
3641
3642When your program has multiple threads (@pxref{Threads,, Debugging
3643programs with multiple threads}), you can choose whether to set
3644breakpoints on all threads, or on a particular thread.
3645
3646@table @code
3647@cindex breakpoints and threads
3648@cindex thread breakpoints
3649@kindex break @dots{} thread @var{threadno}
3650@item break @var{linespec} thread @var{threadno}
3651@itemx break @var{linespec} thread @var{threadno} if @dots{}
3652@var{linespec} specifies source lines; there are several ways of
3653writing them, but the effect is always to specify some source line.
3654
3655Use the qualifier @samp{thread @var{threadno}} with a breakpoint command
3656to specify that you only want @value{GDBN} to stop the program when a
3657particular thread reaches this breakpoint. @var{threadno} is one of the
3658numeric thread identifiers assigned by @value{GDBN}, shown in the first
3659column of the @samp{info threads} display.
3660
3661If you do not specify @samp{thread @var{threadno}} when you set a
3662breakpoint, the breakpoint applies to @emph{all} threads of your
3663program.
3664
3665You can use the @code{thread} qualifier on conditional breakpoints as
3666well; in this case, place @samp{thread @var{threadno}} before the
3667breakpoint condition, like this:
3668
3669@smallexample
2df3850c 3670(@value{GDBP}) break frik.c:13 thread 28 if bartab > lim
c906108c
SS
3671@end smallexample
3672
3673@end table
3674
3675@cindex stopped threads
3676@cindex threads, stopped
3677Whenever your program stops under @value{GDBN} for any reason,
3678@emph{all} threads of execution stop, not just the current thread. This
3679allows you to examine the overall state of the program, including
3680switching between threads, without worrying that things may change
3681underfoot.
3682
3683@cindex continuing threads
3684@cindex threads, continuing
3685Conversely, whenever you restart the program, @emph{all} threads start
3686executing. @emph{This is true even when single-stepping} with commands
5d161b24 3687like @code{step} or @code{next}.
c906108c
SS
3688
3689In particular, @value{GDBN} cannot single-step all threads in lockstep.
3690Since thread scheduling is up to your debugging target's operating
3691system (not controlled by @value{GDBN}), other threads may
3692execute more than one statement while the current thread completes a
3693single step. Moreover, in general other threads stop in the middle of a
3694statement, rather than at a clean statement boundary, when the program
3695stops.
3696
3697You might even find your program stopped in another thread after
3698continuing or even single-stepping. This happens whenever some other
3699thread runs into a breakpoint, a signal, or an exception before the
3700first thread completes whatever you requested.
3701
3702On some OSes, you can lock the OS scheduler and thus allow only a single
3703thread to run.
3704
3705@table @code
3706@item set scheduler-locking @var{mode}
3707Set the scheduler locking mode. If it is @code{off}, then there is no
3708locking and any thread may run at any time. If @code{on}, then only the
3709current thread may run when the inferior is resumed. The @code{step}
3710mode optimizes for single-stepping. It stops other threads from
3711``seizing the prompt'' by preempting the current thread while you are
3712stepping. Other threads will only rarely (or never) get a chance to run
d4f3574e 3713when you step. They are more likely to run when you @samp{next} over a
c906108c 3714function call, and they are completely free to run when you use commands
d4f3574e 3715like @samp{continue}, @samp{until}, or @samp{finish}. However, unless another
c906108c 3716thread hits a breakpoint during its timeslice, they will never steal the
2df3850c 3717@value{GDBN} prompt away from the thread that you are debugging.
c906108c
SS
3718
3719@item show scheduler-locking
3720Display the current scheduler locking mode.
3721@end table
3722
c906108c 3723
6d2ebf8b 3724@node Stack
c906108c
SS
3725@chapter Examining the Stack
3726
3727When your program has stopped, the first thing you need to know is where it
3728stopped and how it got there.
3729
3730@cindex call stack
5d161b24
DB
3731Each time your program performs a function call, information about the call
3732is generated.
3733That information includes the location of the call in your program,
3734the arguments of the call,
c906108c 3735and the local variables of the function being called.
5d161b24 3736The information is saved in a block of data called a @dfn{stack frame}.
c906108c
SS
3737The stack frames are allocated in a region of memory called the @dfn{call
3738stack}.
3739
3740When your program stops, the @value{GDBN} commands for examining the
3741stack allow you to see all of this information.
3742
3743@cindex selected frame
3744One of the stack frames is @dfn{selected} by @value{GDBN} and many
3745@value{GDBN} commands refer implicitly to the selected frame. In
3746particular, whenever you ask @value{GDBN} for the value of a variable in
3747your program, the value is found in the selected frame. There are
3748special @value{GDBN} commands to select whichever frame you are
3749interested in. @xref{Selection, ,Selecting a frame}.
3750
3751When your program stops, @value{GDBN} automatically selects the
5d161b24 3752currently executing frame and describes it briefly, similar to the
c906108c
SS
3753@code{frame} command (@pxref{Frame Info, ,Information about a frame}).
3754
3755@menu
3756* Frames:: Stack frames
3757* Backtrace:: Backtraces
3758* Selection:: Selecting a frame
3759* Frame Info:: Information on a frame
c906108c
SS
3760
3761@end menu
3762
6d2ebf8b 3763@node Frames
c906108c
SS
3764@section Stack frames
3765
d4f3574e 3766@cindex frame, definition
c906108c
SS
3767@cindex stack frame
3768The call stack is divided up into contiguous pieces called @dfn{stack
3769frames}, or @dfn{frames} for short; each frame is the data associated
3770with one call to one function. The frame contains the arguments given
3771to the function, the function's local variables, and the address at
3772which the function is executing.
3773
3774@cindex initial frame
3775@cindex outermost frame
3776@cindex innermost frame
3777When your program is started, the stack has only one frame, that of the
3778function @code{main}. This is called the @dfn{initial} frame or the
3779@dfn{outermost} frame. Each time a function is called, a new frame is
3780made. Each time a function returns, the frame for that function invocation
3781is eliminated. If a function is recursive, there can be many frames for
3782the same function. The frame for the function in which execution is
3783actually occurring is called the @dfn{innermost} frame. This is the most
3784recently created of all the stack frames that still exist.
3785
3786@cindex frame pointer
3787Inside your program, stack frames are identified by their addresses. A
3788stack frame consists of many bytes, each of which has its own address; each
3789kind of computer has a convention for choosing one byte whose
3790address serves as the address of the frame. Usually this address is kept
3791in a register called the @dfn{frame pointer register} while execution is
3792going on in that frame.
3793
3794@cindex frame number
3795@value{GDBN} assigns numbers to all existing stack frames, starting with
3796zero for the innermost frame, one for the frame that called it,
3797and so on upward. These numbers do not really exist in your program;
3798they are assigned by @value{GDBN} to give you a way of designating stack
3799frames in @value{GDBN} commands.
3800
6d2ebf8b
SS
3801@c The -fomit-frame-pointer below perennially causes hbox overflow
3802@c underflow problems.
c906108c
SS
3803@cindex frameless execution
3804Some compilers provide a way to compile functions so that they operate
6d2ebf8b
SS
3805without stack frames. (For example, the @value{GCC} option
3806@example
3807@samp{-fomit-frame-pointer}
3808@end example
3809generates functions without a frame.)
c906108c
SS
3810This is occasionally done with heavily used library functions to save
3811the frame setup time. @value{GDBN} has limited facilities for dealing
3812with these function invocations. If the innermost function invocation
3813has no stack frame, @value{GDBN} nevertheless regards it as though
3814it had a separate frame, which is numbered zero as usual, allowing
3815correct tracing of the function call chain. However, @value{GDBN} has
3816no provision for frameless functions elsewhere in the stack.
3817
3818@table @code
d4f3574e 3819@kindex frame@r{, command}
41afff9a 3820@cindex current stack frame
c906108c 3821@item frame @var{args}
5d161b24 3822The @code{frame} command allows you to move from one stack frame to another,
c906108c 3823and to print the stack frame you select. @var{args} may be either the
5d161b24
DB
3824address of the frame or the stack frame number. Without an argument,
3825@code{frame} prints the current stack frame.
c906108c
SS
3826
3827@kindex select-frame
41afff9a 3828@cindex selecting frame silently
c906108c
SS
3829@item select-frame
3830The @code{select-frame} command allows you to move from one stack frame
3831to another without printing the frame. This is the silent version of
3832@code{frame}.
3833@end table
3834
6d2ebf8b 3835@node Backtrace
c906108c
SS
3836@section Backtraces
3837
3838@cindex backtraces
3839@cindex tracebacks
3840@cindex stack traces
3841A backtrace is a summary of how your program got where it is. It shows one
3842line per frame, for many frames, starting with the currently executing
3843frame (frame zero), followed by its caller (frame one), and on up the
3844stack.
3845
3846@table @code
3847@kindex backtrace
41afff9a 3848@kindex bt @r{(@code{backtrace})}
c906108c
SS
3849@item backtrace
3850@itemx bt
3851Print a backtrace of the entire stack: one line per frame for all
3852frames in the stack.
3853
3854You can stop the backtrace at any time by typing the system interrupt
3855character, normally @kbd{C-c}.
3856
3857@item backtrace @var{n}
3858@itemx bt @var{n}
3859Similar, but print only the innermost @var{n} frames.
3860
3861@item backtrace -@var{n}
3862@itemx bt -@var{n}
3863Similar, but print only the outermost @var{n} frames.
3864@end table
3865
3866@kindex where
3867@kindex info stack
41afff9a 3868@kindex info s @r{(@code{info stack})}
c906108c
SS
3869The names @code{where} and @code{info stack} (abbreviated @code{info s})
3870are additional aliases for @code{backtrace}.
3871
3872Each line in the backtrace shows the frame number and the function name.
3873The program counter value is also shown---unless you use @code{set
3874print address off}. The backtrace also shows the source file name and
3875line number, as well as the arguments to the function. The program
3876counter value is omitted if it is at the beginning of the code for that
3877line number.
3878
3879Here is an example of a backtrace. It was made with the command
3880@samp{bt 3}, so it shows the innermost three frames.
3881
3882@smallexample
3883@group
5d161b24 3884#0 m4_traceon (obs=0x24eb0, argc=1, argv=0x2b8c8)
c906108c
SS
3885 at builtin.c:993
3886#1 0x6e38 in expand_macro (sym=0x2b600) at macro.c:242
3887#2 0x6840 in expand_token (obs=0x0, t=177664, td=0xf7fffb08)
3888 at macro.c:71
3889(More stack frames follow...)
3890@end group
3891@end smallexample
3892
3893@noindent
3894The display for frame zero does not begin with a program counter
3895value, indicating that your program has stopped at the beginning of the
3896code for line @code{993} of @code{builtin.c}.
3897
6d2ebf8b 3898@node Selection
c906108c
SS
3899@section Selecting a frame
3900
3901Most commands for examining the stack and other data in your program work on
3902whichever stack frame is selected at the moment. Here are the commands for
3903selecting a stack frame; all of them finish by printing a brief description
3904of the stack frame just selected.
3905
3906@table @code
d4f3574e 3907@kindex frame@r{, selecting}
41afff9a 3908@kindex f @r{(@code{frame})}
c906108c
SS
3909@item frame @var{n}
3910@itemx f @var{n}
3911Select frame number @var{n}. Recall that frame zero is the innermost
3912(currently executing) frame, frame one is the frame that called the
3913innermost one, and so on. The highest-numbered frame is the one for
3914@code{main}.
3915
3916@item frame @var{addr}
3917@itemx f @var{addr}
3918Select the frame at address @var{addr}. This is useful mainly if the
3919chaining of stack frames has been damaged by a bug, making it
3920impossible for @value{GDBN} to assign numbers properly to all frames. In
3921addition, this can be useful when your program has multiple stacks and
3922switches between them.
3923
c906108c
SS
3924On the SPARC architecture, @code{frame} needs two addresses to
3925select an arbitrary frame: a frame pointer and a stack pointer.
3926
3927On the MIPS and Alpha architecture, it needs two addresses: a stack
3928pointer and a program counter.
3929
3930On the 29k architecture, it needs three addresses: a register stack
3931pointer, a program counter, and a memory stack pointer.
3932@c note to future updaters: this is conditioned on a flag
3933@c SETUP_ARBITRARY_FRAME in the tm-*.h files. The above is up to date
3934@c as of 27 Jan 1994.
c906108c
SS
3935
3936@kindex up
3937@item up @var{n}
3938Move @var{n} frames up the stack. For positive numbers @var{n}, this
3939advances toward the outermost frame, to higher frame numbers, to frames
3940that have existed longer. @var{n} defaults to one.
3941
3942@kindex down
41afff9a 3943@kindex do @r{(@code{down})}
c906108c
SS
3944@item down @var{n}
3945Move @var{n} frames down the stack. For positive numbers @var{n}, this
3946advances toward the innermost frame, to lower frame numbers, to frames
3947that were created more recently. @var{n} defaults to one. You may
3948abbreviate @code{down} as @code{do}.
3949@end table
3950
3951All of these commands end by printing two lines of output describing the
3952frame. The first line shows the frame number, the function name, the
3953arguments, and the source file and line number of execution in that
5d161b24 3954frame. The second line shows the text of that source line.
c906108c
SS
3955
3956@need 1000
3957For example:
3958
3959@smallexample
3960@group
3961(@value{GDBP}) up
3962#1 0x22f0 in main (argc=1, argv=0xf7fffbf4, env=0xf7fffbfc)
3963 at env.c:10
396410 read_input_file (argv[i]);
3965@end group
3966@end smallexample
3967
3968After such a printout, the @code{list} command with no arguments
3969prints ten lines centered on the point of execution in the frame.
3970@xref{List, ,Printing source lines}.
3971
3972@table @code
3973@kindex down-silently
3974@kindex up-silently
3975@item up-silently @var{n}
3976@itemx down-silently @var{n}
3977These two commands are variants of @code{up} and @code{down},
3978respectively; they differ in that they do their work silently, without
3979causing display of the new frame. They are intended primarily for use
3980in @value{GDBN} command scripts, where the output might be unnecessary and
3981distracting.
3982@end table
3983
6d2ebf8b 3984@node Frame Info
c906108c
SS
3985@section Information about a frame
3986
3987There are several other commands to print information about the selected
3988stack frame.
3989
3990@table @code
3991@item frame
3992@itemx f
3993When used without any argument, this command does not change which
3994frame is selected, but prints a brief description of the currently
3995selected stack frame. It can be abbreviated @code{f}. With an
3996argument, this command is used to select a stack frame.
3997@xref{Selection, ,Selecting a frame}.
3998
3999@kindex info frame
41afff9a 4000@kindex info f @r{(@code{info frame})}
c906108c
SS
4001@item info frame
4002@itemx info f
4003This command prints a verbose description of the selected stack frame,
4004including:
4005
4006@itemize @bullet
5d161b24
DB
4007@item
4008the address of the frame
c906108c
SS
4009@item
4010the address of the next frame down (called by this frame)
4011@item
4012the address of the next frame up (caller of this frame)
4013@item
4014the language in which the source code corresponding to this frame is written
4015@item
4016the address of the frame's arguments
4017@item
d4f3574e
SS
4018the address of the frame's local variables
4019@item
c906108c
SS
4020the program counter saved in it (the address of execution in the caller frame)
4021@item
4022which registers were saved in the frame
4023@end itemize
4024
4025@noindent The verbose description is useful when
4026something has gone wrong that has made the stack format fail to fit
4027the usual conventions.
4028
4029@item info frame @var{addr}
4030@itemx info f @var{addr}
4031Print a verbose description of the frame at address @var{addr}, without
4032selecting that frame. The selected frame remains unchanged by this
4033command. This requires the same kind of address (more than one for some
4034architectures) that you specify in the @code{frame} command.
4035@xref{Selection, ,Selecting a frame}.
4036
4037@kindex info args
4038@item info args
4039Print the arguments of the selected frame, each on a separate line.
4040
4041@item info locals
4042@kindex info locals
4043Print the local variables of the selected frame, each on a separate
4044line. These are all variables (declared either static or automatic)
4045accessible at the point of execution of the selected frame.
4046
c906108c 4047@kindex info catch
d4f3574e
SS
4048@cindex catch exceptions, list active handlers
4049@cindex exception handlers, how to list
c906108c
SS
4050@item info catch
4051Print a list of all the exception handlers that are active in the
4052current stack frame at the current point of execution. To see other
4053exception handlers, visit the associated frame (using the @code{up},
4054@code{down}, or @code{frame} commands); then type @code{info catch}.
4055@xref{Set Catchpoints, , Setting catchpoints}.
53a5351d 4056
c906108c
SS
4057@end table
4058
c906108c 4059
6d2ebf8b 4060@node Source
c906108c
SS
4061@chapter Examining Source Files
4062
4063@value{GDBN} can print parts of your program's source, since the debugging
4064information recorded in the program tells @value{GDBN} what source files were
4065used to build it. When your program stops, @value{GDBN} spontaneously prints
4066the line where it stopped. Likewise, when you select a stack frame
4067(@pxref{Selection, ,Selecting a frame}), @value{GDBN} prints the line where
4068execution in that frame has stopped. You can print other portions of
4069source files by explicit command.
4070
7a292a7a 4071If you use @value{GDBN} through its @sc{gnu} Emacs interface, you may
d4f3574e 4072prefer to use Emacs facilities to view source; see @ref{Emacs, ,Using
7a292a7a 4073@value{GDBN} under @sc{gnu} Emacs}.
c906108c
SS
4074
4075@menu
4076* List:: Printing source lines
c906108c 4077* Search:: Searching source files
c906108c
SS
4078* Source Path:: Specifying source directories
4079* Machine Code:: Source and machine code
4080@end menu
4081
6d2ebf8b 4082@node List
c906108c
SS
4083@section Printing source lines
4084
4085@kindex list
41afff9a 4086@kindex l @r{(@code{list})}
c906108c 4087To print lines from a source file, use the @code{list} command
5d161b24 4088(abbreviated @code{l}). By default, ten lines are printed.
c906108c
SS
4089There are several ways to specify what part of the file you want to print.
4090
4091Here are the forms of the @code{list} command most commonly used:
4092
4093@table @code
4094@item list @var{linenum}
4095Print lines centered around line number @var{linenum} in the
4096current source file.
4097
4098@item list @var{function}
4099Print lines centered around the beginning of function
4100@var{function}.
4101
4102@item list
4103Print more lines. If the last lines printed were printed with a
4104@code{list} command, this prints lines following the last lines
4105printed; however, if the last line printed was a solitary line printed
4106as part of displaying a stack frame (@pxref{Stack, ,Examining the
4107Stack}), this prints lines centered around that line.
4108
4109@item list -
4110Print lines just before the lines last printed.
4111@end table
4112
4113By default, @value{GDBN} prints ten source lines with any of these forms of
4114the @code{list} command. You can change this using @code{set listsize}:
4115
4116@table @code
4117@kindex set listsize
4118@item set listsize @var{count}
4119Make the @code{list} command display @var{count} source lines (unless
4120the @code{list} argument explicitly specifies some other number).
4121
4122@kindex show listsize
4123@item show listsize
4124Display the number of lines that @code{list} prints.
4125@end table
4126
4127Repeating a @code{list} command with @key{RET} discards the argument,
4128so it is equivalent to typing just @code{list}. This is more useful
4129than listing the same lines again. An exception is made for an
4130argument of @samp{-}; that argument is preserved in repetition so that
4131each repetition moves up in the source file.
4132
4133@cindex linespec
4134In general, the @code{list} command expects you to supply zero, one or two
4135@dfn{linespecs}. Linespecs specify source lines; there are several ways
d4f3574e 4136of writing them, but the effect is always to specify some source line.
c906108c
SS
4137Here is a complete description of the possible arguments for @code{list}:
4138
4139@table @code
4140@item list @var{linespec}
4141Print lines centered around the line specified by @var{linespec}.
4142
4143@item list @var{first},@var{last}
4144Print lines from @var{first} to @var{last}. Both arguments are
4145linespecs.
4146
4147@item list ,@var{last}
4148Print lines ending with @var{last}.
4149
4150@item list @var{first},
4151Print lines starting with @var{first}.
4152
4153@item list +
4154Print lines just after the lines last printed.
4155
4156@item list -
4157Print lines just before the lines last printed.
4158
4159@item list
4160As described in the preceding table.
4161@end table
4162
4163Here are the ways of specifying a single source line---all the
4164kinds of linespec.
4165
4166@table @code
4167@item @var{number}
4168Specifies line @var{number} of the current source file.
4169When a @code{list} command has two linespecs, this refers to
4170the same source file as the first linespec.
4171
4172@item +@var{offset}
4173Specifies the line @var{offset} lines after the last line printed.
4174When used as the second linespec in a @code{list} command that has
4175two, this specifies the line @var{offset} lines down from the
4176first linespec.
4177
4178@item -@var{offset}
4179Specifies the line @var{offset} lines before the last line printed.
4180
4181@item @var{filename}:@var{number}
4182Specifies line @var{number} in the source file @var{filename}.
4183
4184@item @var{function}
4185Specifies the line that begins the body of the function @var{function}.
4186For example: in C, this is the line with the open brace.
4187
4188@item @var{filename}:@var{function}
4189Specifies the line of the open-brace that begins the body of the
4190function @var{function} in the file @var{filename}. You only need the
4191file name with a function name to avoid ambiguity when there are
4192identically named functions in different source files.
4193
4194@item *@var{address}
4195Specifies the line containing the program address @var{address}.
4196@var{address} may be any expression.
4197@end table
4198
6d2ebf8b 4199@node Search
c906108c
SS
4200@section Searching source files
4201@cindex searching
4202@kindex reverse-search
4203
4204There are two commands for searching through the current source file for a
4205regular expression.
4206
4207@table @code
4208@kindex search
4209@kindex forward-search
4210@item forward-search @var{regexp}
4211@itemx search @var{regexp}
4212The command @samp{forward-search @var{regexp}} checks each line,
4213starting with the one following the last line listed, for a match for
5d161b24 4214@var{regexp}. It lists the line that is found. You can use the
c906108c
SS
4215synonym @samp{search @var{regexp}} or abbreviate the command name as
4216@code{fo}.
4217
4218@item reverse-search @var{regexp}
4219The command @samp{reverse-search @var{regexp}} checks each line, starting
4220with the one before the last line listed and going backward, for a match
4221for @var{regexp}. It lists the line that is found. You can abbreviate
4222this command as @code{rev}.
4223@end table
c906108c 4224
6d2ebf8b 4225@node Source Path
c906108c
SS
4226@section Specifying source directories
4227
4228@cindex source path
4229@cindex directories for source files
4230Executable programs sometimes do not record the directories of the source
4231files from which they were compiled, just the names. Even when they do,
4232the directories could be moved between the compilation and your debugging
4233session. @value{GDBN} has a list of directories to search for source files;
4234this is called the @dfn{source path}. Each time @value{GDBN} wants a source file,
4235it tries all the directories in the list, in the order they are present
4236in the list, until it finds a file with the desired name. Note that
4237the executable search path is @emph{not} used for this purpose. Neither is
4238the current working directory, unless it happens to be in the source
4239path.
4240
4241If @value{GDBN} cannot find a source file in the source path, and the
4242object program records a directory, @value{GDBN} tries that directory
4243too. If the source path is empty, and there is no record of the
4244compilation directory, @value{GDBN} looks in the current directory as a
4245last resort.
4246
4247Whenever you reset or rearrange the source path, @value{GDBN} clears out
4248any information it has cached about where source files are found and where
4249each line is in the file.
4250
4251@kindex directory
4252@kindex dir
d4f3574e
SS
4253When you start @value{GDBN}, its source path includes only @samp{cdir}
4254and @samp{cwd}, in that order.
c906108c
SS
4255To add other directories, use the @code{directory} command.
4256
4257@table @code
4258@item directory @var{dirname} @dots{}
4259@item dir @var{dirname} @dots{}
4260Add directory @var{dirname} to the front of the source path. Several
d4f3574e
SS
4261directory names may be given to this command, separated by @samp{:}
4262(@samp{;} on MS-DOS and MS-Windows, where @samp{:} usually appears as
4263part of absolute file names) or
c906108c
SS
4264whitespace. You may specify a directory that is already in the source
4265path; this moves it forward, so @value{GDBN} searches it sooner.
4266
4267@kindex cdir
4268@kindex cwd
41afff9a
EZ
4269@vindex $cdir@r{, convenience variable}
4270@vindex $cwdr@r{, convenience variable}
c906108c
SS
4271@cindex compilation directory
4272@cindex current directory
4273@cindex working directory
4274@cindex directory, current
4275@cindex directory, compilation
4276You can use the string @samp{$cdir} to refer to the compilation
4277directory (if one is recorded), and @samp{$cwd} to refer to the current
4278working directory. @samp{$cwd} is not the same as @samp{.}---the former
4279tracks the current working directory as it changes during your @value{GDBN}
4280session, while the latter is immediately expanded to the current
4281directory at the time you add an entry to the source path.
4282
4283@item directory
4284Reset the source path to empty again. This requires confirmation.
4285
4286@c RET-repeat for @code{directory} is explicitly disabled, but since
4287@c repeating it would be a no-op we do not say that. (thanks to RMS)
4288
4289@item show directories
4290@kindex show directories
4291Print the source path: show which directories it contains.
4292@end table
4293
4294If your source path is cluttered with directories that are no longer of
4295interest, @value{GDBN} may sometimes cause confusion by finding the wrong
4296versions of source. You can correct the situation as follows:
4297
4298@enumerate
4299@item
4300Use @code{directory} with no argument to reset the source path to empty.
4301
4302@item
4303Use @code{directory} with suitable arguments to reinstall the
4304directories you want in the source path. You can add all the
4305directories in one command.
4306@end enumerate
4307
6d2ebf8b 4308@node Machine Code
c906108c
SS
4309@section Source and machine code
4310
4311You can use the command @code{info line} to map source lines to program
4312addresses (and vice versa), and the command @code{disassemble} to display
4313a range of addresses as machine instructions. When run under @sc{gnu} Emacs
d4f3574e 4314mode, the @code{info line} command causes the arrow to point to the
5d161b24 4315line specified. Also, @code{info line} prints addresses in symbolic form as
c906108c
SS
4316well as hex.
4317
4318@table @code
4319@kindex info line
4320@item info line @var{linespec}
4321Print the starting and ending addresses of the compiled code for
4322source line @var{linespec}. You can specify source lines in any of
4323the ways understood by the @code{list} command (@pxref{List, ,Printing
4324source lines}).
4325@end table
4326
4327For example, we can use @code{info line} to discover the location of
4328the object code for the first line of function
4329@code{m4_changequote}:
4330
d4f3574e
SS
4331@c FIXME: I think this example should also show the addresses in
4332@c symbolic form, as they usually would be displayed.
c906108c 4333@smallexample
96a2c332 4334(@value{GDBP}) info line m4_changequote
c906108c
SS
4335Line 895 of "builtin.c" starts at pc 0x634c and ends at 0x6350.
4336@end smallexample
4337
4338@noindent
4339We can also inquire (using @code{*@var{addr}} as the form for
4340@var{linespec}) what source line covers a particular address:
4341@smallexample
4342(@value{GDBP}) info line *0x63ff
4343Line 926 of "builtin.c" starts at pc 0x63e4 and ends at 0x6404.
4344@end smallexample
4345
4346@cindex @code{$_} and @code{info line}
41afff9a 4347@kindex x@r{(examine), and} info line
c906108c
SS
4348After @code{info line}, the default address for the @code{x} command
4349is changed to the starting address of the line, so that @samp{x/i} is
4350sufficient to begin examining the machine code (@pxref{Memory,
4351,Examining memory}). Also, this address is saved as the value of the
4352convenience variable @code{$_} (@pxref{Convenience Vars, ,Convenience
4353variables}).
4354
4355@table @code
4356@kindex disassemble
4357@cindex assembly instructions
4358@cindex instructions, assembly
4359@cindex machine instructions
4360@cindex listing machine instructions
4361@item disassemble
4362This specialized command dumps a range of memory as machine
4363instructions. The default memory range is the function surrounding the
4364program counter of the selected frame. A single argument to this
4365command is a program counter value; @value{GDBN} dumps the function
4366surrounding this value. Two arguments specify a range of addresses
4367(first inclusive, second exclusive) to dump.
4368@end table
4369
c906108c
SS
4370The following example shows the disassembly of a range of addresses of
4371HP PA-RISC 2.0 code:
4372
4373@smallexample
4374(@value{GDBP}) disas 0x32c4 0x32e4
4375Dump of assembler code from 0x32c4 to 0x32e4:
43760x32c4 <main+204>: addil 0,dp
43770x32c8 <main+208>: ldw 0x22c(sr0,r1),r26
43780x32cc <main+212>: ldil 0x3000,r31
43790x32d0 <main+216>: ble 0x3f8(sr4,r31)
43800x32d4 <main+220>: ldo 0(r31),rp
43810x32d8 <main+224>: addil -0x800,dp
43820x32dc <main+228>: ldo 0x588(r1),r26
43830x32e0 <main+232>: ldil 0x3000,r31
4384End of assembler dump.
4385@end smallexample
c906108c
SS
4386
4387Some architectures have more than one commonly-used set of instruction
4388mnemonics or other syntax.
4389
4390@table @code
d4f3574e 4391@kindex set disassembly-flavor
c906108c
SS
4392@cindex assembly instructions
4393@cindex instructions, assembly
4394@cindex machine instructions
4395@cindex listing machine instructions
d4f3574e
SS
4396@cindex Intel disassembly flavor
4397@cindex AT&T disassembly flavor
4398@item set disassembly-flavor @var{instruction-set}
c906108c
SS
4399Select the instruction set to use when disassembling the
4400program via the @code{disassemble} or @code{x/i} commands.
4401
4402Currently this command is only defined for the Intel x86 family. You
d4f3574e
SS
4403can set @var{instruction-set} to either @code{intel} or @code{att}.
4404The default is @code{att}, the AT&T flavor used by default by Unix
4405assemblers for x86-based targets.
c906108c
SS
4406@end table
4407
4408
6d2ebf8b 4409@node Data
c906108c
SS
4410@chapter Examining Data
4411
4412@cindex printing data
4413@cindex examining data
4414@kindex print
4415@kindex inspect
4416@c "inspect" is not quite a synonym if you are using Epoch, which we do not
4417@c document because it is nonstandard... Under Epoch it displays in a
4418@c different window or something like that.
4419The usual way to examine data in your program is with the @code{print}
7a292a7a
SS
4420command (abbreviated @code{p}), or its synonym @code{inspect}. It
4421evaluates and prints the value of an expression of the language your
4422program is written in (@pxref{Languages, ,Using @value{GDBN} with
4423Different Languages}).
c906108c
SS
4424
4425@table @code
d4f3574e
SS
4426@item print @var{expr}
4427@itemx print /@var{f} @var{expr}
4428@var{expr} is an expression (in the source language). By default the
4429value of @var{expr} is printed in a format appropriate to its data type;
c906108c 4430you can choose a different format by specifying @samp{/@var{f}}, where
d4f3574e 4431@var{f} is a letter specifying the format; see @ref{Output Formats,,Output
c906108c
SS
4432formats}.
4433
4434@item print
4435@itemx print /@var{f}
d4f3574e 4436If you omit @var{expr}, @value{GDBN} displays the last value again (from the
c906108c
SS
4437@dfn{value history}; @pxref{Value History, ,Value history}). This allows you to
4438conveniently inspect the same value in an alternative format.
4439@end table
4440
4441A more low-level way of examining data is with the @code{x} command.
4442It examines data in memory at a specified address and prints it in a
4443specified format. @xref{Memory, ,Examining memory}.
4444
7a292a7a 4445If you are interested in information about types, or about how the
d4f3574e
SS
4446fields of a struct or a class are declared, use the @code{ptype @var{exp}}
4447command rather than @code{print}. @xref{Symbols, ,Examining the Symbol
7a292a7a 4448Table}.
c906108c
SS
4449
4450@menu
4451* Expressions:: Expressions
4452* Variables:: Program variables
4453* Arrays:: Artificial arrays
4454* Output Formats:: Output formats
4455* Memory:: Examining memory
4456* Auto Display:: Automatic display
4457* Print Settings:: Print settings
4458* Value History:: Value history
4459* Convenience Vars:: Convenience variables
4460* Registers:: Registers
c906108c 4461* Floating Point Hardware:: Floating point hardware
29e57380 4462* Memory Region Attributes:: Memory region attributes
c906108c
SS
4463@end menu
4464
6d2ebf8b 4465@node Expressions
c906108c
SS
4466@section Expressions
4467
4468@cindex expressions
4469@code{print} and many other @value{GDBN} commands accept an expression and
4470compute its value. Any kind of constant, variable or operator defined
4471by the programming language you are using is valid in an expression in
4472@value{GDBN}. This includes conditional expressions, function calls, casts
4473and string constants. It unfortunately does not include symbols defined
4474by preprocessor @code{#define} commands.
4475
d4f3574e
SS
4476@value{GDBN} supports array constants in expressions input by
4477the user. The syntax is @{@var{element}, @var{element}@dots{}@}. For example,
5d161b24 4478you can use the command @code{print @{1, 2, 3@}} to build up an array in
d4f3574e 4479memory that is @code{malloc}ed in the target program.
c906108c 4480
c906108c
SS
4481Because C is so widespread, most of the expressions shown in examples in
4482this manual are in C. @xref{Languages, , Using @value{GDBN} with Different
4483Languages}, for information on how to use expressions in other
4484languages.
4485
4486In this section, we discuss operators that you can use in @value{GDBN}
4487expressions regardless of your programming language.
4488
4489Casts are supported in all languages, not just in C, because it is so
4490useful to cast a number into a pointer in order to examine a structure
4491at that address in memory.
4492@c FIXME: casts supported---Mod2 true?
c906108c
SS
4493
4494@value{GDBN} supports these operators, in addition to those common
4495to programming languages:
4496
4497@table @code
4498@item @@
4499@samp{@@} is a binary operator for treating parts of memory as arrays.
4500@xref{Arrays, ,Artificial arrays}, for more information.
4501
4502@item ::
4503@samp{::} allows you to specify a variable in terms of the file or
4504function where it is defined. @xref{Variables, ,Program variables}.
4505
4506@cindex @{@var{type}@}
4507@cindex type casting memory
4508@cindex memory, viewing as typed object
4509@cindex casts, to view memory
4510@item @{@var{type}@} @var{addr}
4511Refers to an object of type @var{type} stored at address @var{addr} in
4512memory. @var{addr} may be any expression whose value is an integer or
4513pointer (but parentheses are required around binary operators, just as in
4514a cast). This construct is allowed regardless of what kind of data is
4515normally supposed to reside at @var{addr}.
4516@end table
4517
6d2ebf8b 4518@node Variables
c906108c
SS
4519@section Program variables
4520
4521The most common kind of expression to use is the name of a variable
4522in your program.
4523
4524Variables in expressions are understood in the selected stack frame
4525(@pxref{Selection, ,Selecting a frame}); they must be either:
4526
4527@itemize @bullet
4528@item
4529global (or file-static)
4530@end itemize
4531
5d161b24 4532@noindent or
c906108c
SS
4533
4534@itemize @bullet
4535@item
4536visible according to the scope rules of the
4537programming language from the point of execution in that frame
5d161b24 4538@end itemize
c906108c
SS
4539
4540@noindent This means that in the function
4541
4542@example
4543foo (a)
4544 int a;
4545@{
4546 bar (a);
4547 @{
4548 int b = test ();
4549 bar (b);
4550 @}
4551@}
4552@end example
4553
4554@noindent
4555you can examine and use the variable @code{a} whenever your program is
4556executing within the function @code{foo}, but you can only use or
4557examine the variable @code{b} while your program is executing inside
4558the block where @code{b} is declared.
4559
4560@cindex variable name conflict
4561There is an exception: you can refer to a variable or function whose
4562scope is a single source file even if the current execution point is not
4563in this file. But it is possible to have more than one such variable or
4564function with the same name (in different source files). If that
4565happens, referring to that name has unpredictable effects. If you wish,
4566you can specify a static variable in a particular function or file,
4567using the colon-colon notation:
4568
d4f3574e 4569@cindex colon-colon, context for variables/functions
c906108c
SS
4570@iftex
4571@c info cannot cope with a :: index entry, but why deprive hard copy readers?
41afff9a 4572@cindex @code{::}, context for variables/functions
c906108c
SS
4573@end iftex
4574@example
4575@var{file}::@var{variable}
4576@var{function}::@var{variable}
4577@end example
4578
4579@noindent
4580Here @var{file} or @var{function} is the name of the context for the
4581static @var{variable}. In the case of file names, you can use quotes to
4582make sure @value{GDBN} parses the file name as a single word---for example,
4583to print a global value of @code{x} defined in @file{f2.c}:
4584
4585@example
4586(@value{GDBP}) p 'f2.c'::x
4587@end example
4588
b37052ae 4589@cindex C@t{++} scope resolution
c906108c 4590This use of @samp{::} is very rarely in conflict with the very similar
b37052ae 4591use of the same notation in C@t{++}. @value{GDBN} also supports use of the C@t{++}
c906108c
SS
4592scope resolution operator in @value{GDBN} expressions.
4593@c FIXME: Um, so what happens in one of those rare cases where it's in
4594@c conflict?? --mew
c906108c
SS
4595
4596@cindex wrong values
4597@cindex variable values, wrong
4598@quotation
4599@emph{Warning:} Occasionally, a local variable may appear to have the
4600wrong value at certain points in a function---just after entry to a new
4601scope, and just before exit.
4602@end quotation
4603You may see this problem when you are stepping by machine instructions.
4604This is because, on most machines, it takes more than one instruction to
4605set up a stack frame (including local variable definitions); if you are
4606stepping by machine instructions, variables may appear to have the wrong
4607values until the stack frame is completely built. On exit, it usually
4608also takes more than one machine instruction to destroy a stack frame;
4609after you begin stepping through that group of instructions, local
4610variable definitions may be gone.
4611
4612This may also happen when the compiler does significant optimizations.
4613To be sure of always seeing accurate values, turn off all optimization
4614when compiling.
4615
d4f3574e
SS
4616@cindex ``No symbol "foo" in current context''
4617Another possible effect of compiler optimizations is to optimize
4618unused variables out of existence, or assign variables to registers (as
4619opposed to memory addresses). Depending on the support for such cases
4620offered by the debug info format used by the compiler, @value{GDBN}
4621might not be able to display values for such local variables. If that
4622happens, @value{GDBN} will print a message like this:
4623
4624@example
4625No symbol "foo" in current context.
4626@end example
4627
4628To solve such problems, either recompile without optimizations, or use a
4629different debug info format, if the compiler supports several such
b37052ae 4630formats. For example, @value{NGCC}, the @sc{gnu} C/C@t{++} compiler usually
d4f3574e
SS
4631supports the @samp{-gstabs} option. @samp{-gstabs} produces debug info
4632in a format that is superior to formats such as COFF. You may be able
96c405b3 4633to use DWARF2 (@samp{-gdwarf-2}), which is also an effective form for
d4f3574e
SS
4634debug info. See @ref{Debugging Options,,Options for Debugging Your
4635Program or @sc{gnu} CC, gcc.info, Using @sc{gnu} CC}, for more
4636information.
4637
4638
6d2ebf8b 4639@node Arrays
c906108c
SS
4640@section Artificial arrays
4641
4642@cindex artificial array
41afff9a 4643@kindex @@@r{, referencing memory as an array}
c906108c
SS
4644It is often useful to print out several successive objects of the
4645same type in memory; a section of an array, or an array of
4646dynamically determined size for which only a pointer exists in the
4647program.
4648
4649You can do this by referring to a contiguous span of memory as an
4650@dfn{artificial array}, using the binary operator @samp{@@}. The left
4651operand of @samp{@@} should be the first element of the desired array
4652and be an individual object. The right operand should be the desired length
4653of the array. The result is an array value whose elements are all of
4654the type of the left argument. The first element is actually the left
4655argument; the second element comes from bytes of memory immediately
4656following those that hold the first element, and so on. Here is an
4657example. If a program says
4658
4659@example
4660int *array = (int *) malloc (len * sizeof (int));
4661@end example
4662
4663@noindent
4664you can print the contents of @code{array} with
4665
4666@example
4667p *array@@len
4668@end example
4669
4670The left operand of @samp{@@} must reside in memory. Array values made
4671with @samp{@@} in this way behave just like other arrays in terms of
4672subscripting, and are coerced to pointers when used in expressions.
4673Artificial arrays most often appear in expressions via the value history
4674(@pxref{Value History, ,Value history}), after printing one out.
4675
4676Another way to create an artificial array is to use a cast.
4677This re-interprets a value as if it were an array.
4678The value need not be in memory:
4679@example
4680(@value{GDBP}) p/x (short[2])0x12345678
4681$1 = @{0x1234, 0x5678@}
4682@end example
4683
4684As a convenience, if you leave the array length out (as in
c3f6f71d 4685@samp{(@var{type}[])@var{value}}) @value{GDBN} calculates the size to fill
c906108c
SS
4686the value (as @samp{sizeof(@var{value})/sizeof(@var{type})}:
4687@example
4688(@value{GDBP}) p/x (short[])0x12345678
4689$2 = @{0x1234, 0x5678@}
4690@end example
4691
4692Sometimes the artificial array mechanism is not quite enough; in
4693moderately complex data structures, the elements of interest may not
4694actually be adjacent---for example, if you are interested in the values
4695of pointers in an array. One useful work-around in this situation is
4696to use a convenience variable (@pxref{Convenience Vars, ,Convenience
4697variables}) as a counter in an expression that prints the first
4698interesting value, and then repeat that expression via @key{RET}. For
4699instance, suppose you have an array @code{dtab} of pointers to
4700structures, and you are interested in the values of a field @code{fv}
4701in each structure. Here is an example of what you might type:
4702
4703@example
4704set $i = 0
4705p dtab[$i++]->fv
4706@key{RET}
4707@key{RET}
4708@dots{}
4709@end example
4710
6d2ebf8b 4711@node Output Formats
c906108c
SS
4712@section Output formats
4713
4714@cindex formatted output
4715@cindex output formats
4716By default, @value{GDBN} prints a value according to its data type. Sometimes
4717this is not what you want. For example, you might want to print a number
4718in hex, or a pointer in decimal. Or you might want to view data in memory
4719at a certain address as a character string or as an instruction. To do
4720these things, specify an @dfn{output format} when you print a value.
4721
4722The simplest use of output formats is to say how to print a value
4723already computed. This is done by starting the arguments of the
4724@code{print} command with a slash and a format letter. The format
4725letters supported are:
4726
4727@table @code
4728@item x
4729Regard the bits of the value as an integer, and print the integer in
4730hexadecimal.
4731
4732@item d
4733Print as integer in signed decimal.
4734
4735@item u
4736Print as integer in unsigned decimal.
4737
4738@item o
4739Print as integer in octal.
4740
4741@item t
4742Print as integer in binary. The letter @samp{t} stands for ``two''.
4743@footnote{@samp{b} cannot be used because these format letters are also
4744used with the @code{x} command, where @samp{b} stands for ``byte'';
d4f3574e 4745see @ref{Memory,,Examining memory}.}
c906108c
SS
4746
4747@item a
4748@cindex unknown address, locating
3d67e040 4749@cindex locate address
c906108c
SS
4750Print as an address, both absolute in hexadecimal and as an offset from
4751the nearest preceding symbol. You can use this format used to discover
4752where (in what function) an unknown address is located:
4753
4754@example
4755(@value{GDBP}) p/a 0x54320
4756$3 = 0x54320 <_initialize_vx+396>
4757@end example
4758
3d67e040
EZ
4759@noindent
4760The command @code{info symbol 0x54320} yields similar results.
4761@xref{Symbols, info symbol}.
4762
c906108c
SS
4763@item c
4764Regard as an integer and print it as a character constant.
4765
4766@item f
4767Regard the bits of the value as a floating point number and print
4768using typical floating point syntax.
4769@end table
4770
4771For example, to print the program counter in hex (@pxref{Registers}), type
4772
4773@example
4774p/x $pc
4775@end example
4776
4777@noindent
4778Note that no space is required before the slash; this is because command
4779names in @value{GDBN} cannot contain a slash.
4780
4781To reprint the last value in the value history with a different format,
4782you can use the @code{print} command with just a format and no
4783expression. For example, @samp{p/x} reprints the last value in hex.
4784
6d2ebf8b 4785@node Memory
c906108c
SS
4786@section Examining memory
4787
4788You can use the command @code{x} (for ``examine'') to examine memory in
4789any of several formats, independently of your program's data types.
4790
4791@cindex examining memory
4792@table @code
41afff9a 4793@kindex x @r{(examine memory)}
c906108c
SS
4794@item x/@var{nfu} @var{addr}
4795@itemx x @var{addr}
4796@itemx x
4797Use the @code{x} command to examine memory.
4798@end table
4799
4800@var{n}, @var{f}, and @var{u} are all optional parameters that specify how
4801much memory to display and how to format it; @var{addr} is an
4802expression giving the address where you want to start displaying memory.
4803If you use defaults for @var{nfu}, you need not type the slash @samp{/}.
4804Several commands set convenient defaults for @var{addr}.
4805
4806@table @r
4807@item @var{n}, the repeat count
4808The repeat count is a decimal integer; the default is 1. It specifies
4809how much memory (counting by units @var{u}) to display.
4810@c This really is **decimal**; unaffected by 'set radix' as of GDB
4811@c 4.1.2.
4812
4813@item @var{f}, the display format
4814The display format is one of the formats used by @code{print},
4815@samp{s} (null-terminated string), or @samp{i} (machine instruction).
4816The default is @samp{x} (hexadecimal) initially.
4817The default changes each time you use either @code{x} or @code{print}.
4818
4819@item @var{u}, the unit size
4820The unit size is any of
4821
4822@table @code
4823@item b
4824Bytes.
4825@item h
4826Halfwords (two bytes).
4827@item w
4828Words (four bytes). This is the initial default.
4829@item g
4830Giant words (eight bytes).
4831@end table
4832
4833Each time you specify a unit size with @code{x}, that size becomes the
4834default unit the next time you use @code{x}. (For the @samp{s} and
4835@samp{i} formats, the unit size is ignored and is normally not written.)
4836
4837@item @var{addr}, starting display address
4838@var{addr} is the address where you want @value{GDBN} to begin displaying
4839memory. The expression need not have a pointer value (though it may);
4840it is always interpreted as an integer address of a byte of memory.
4841@xref{Expressions, ,Expressions}, for more information on expressions. The default for
4842@var{addr} is usually just after the last address examined---but several
4843other commands also set the default address: @code{info breakpoints} (to
4844the address of the last breakpoint listed), @code{info line} (to the
4845starting address of a line), and @code{print} (if you use it to display
4846a value from memory).
4847@end table
4848
4849For example, @samp{x/3uh 0x54320} is a request to display three halfwords
4850(@code{h}) of memory, formatted as unsigned decimal integers (@samp{u}),
4851starting at address @code{0x54320}. @samp{x/4xw $sp} prints the four
4852words (@samp{w}) of memory above the stack pointer (here, @samp{$sp};
d4f3574e 4853@pxref{Registers, ,Registers}) in hexadecimal (@samp{x}).
c906108c
SS
4854
4855Since the letters indicating unit sizes are all distinct from the
4856letters specifying output formats, you do not have to remember whether
4857unit size or format comes first; either order works. The output
4858specifications @samp{4xw} and @samp{4wx} mean exactly the same thing.
4859(However, the count @var{n} must come first; @samp{wx4} does not work.)
4860
4861Even though the unit size @var{u} is ignored for the formats @samp{s}
4862and @samp{i}, you might still want to use a count @var{n}; for example,
4863@samp{3i} specifies that you want to see three machine instructions,
4864including any operands. The command @code{disassemble} gives an
d4f3574e 4865alternative way of inspecting machine instructions; see @ref{Machine
c906108c
SS
4866Code,,Source and machine code}.
4867
4868All the defaults for the arguments to @code{x} are designed to make it
4869easy to continue scanning memory with minimal specifications each time
4870you use @code{x}. For example, after you have inspected three machine
4871instructions with @samp{x/3i @var{addr}}, you can inspect the next seven
4872with just @samp{x/7}. If you use @key{RET} to repeat the @code{x} command,
4873the repeat count @var{n} is used again; the other arguments default as
4874for successive uses of @code{x}.
4875
4876@cindex @code{$_}, @code{$__}, and value history
4877The addresses and contents printed by the @code{x} command are not saved
4878in the value history because there is often too much of them and they
4879would get in the way. Instead, @value{GDBN} makes these values available for
4880subsequent use in expressions as values of the convenience variables
4881@code{$_} and @code{$__}. After an @code{x} command, the last address
4882examined is available for use in expressions in the convenience variable
4883@code{$_}. The contents of that address, as examined, are available in
4884the convenience variable @code{$__}.
4885
4886If the @code{x} command has a repeat count, the address and contents saved
4887are from the last memory unit printed; this is not the same as the last
4888address printed if several units were printed on the last line of output.
4889
6d2ebf8b 4890@node Auto Display
c906108c
SS
4891@section Automatic display
4892@cindex automatic display
4893@cindex display of expressions
4894
4895If you find that you want to print the value of an expression frequently
4896(to see how it changes), you might want to add it to the @dfn{automatic
4897display list} so that @value{GDBN} prints its value each time your program stops.
4898Each expression added to the list is given a number to identify it;
4899to remove an expression from the list, you specify that number.
4900The automatic display looks like this:
4901
4902@example
49032: foo = 38
49043: bar[5] = (struct hack *) 0x3804
4905@end example
4906
4907@noindent
4908This display shows item numbers, expressions and their current values. As with
4909displays you request manually using @code{x} or @code{print}, you can
4910specify the output format you prefer; in fact, @code{display} decides
4911whether to use @code{print} or @code{x} depending on how elaborate your
4912format specification is---it uses @code{x} if you specify a unit size,
4913or one of the two formats (@samp{i} and @samp{s}) that are only
4914supported by @code{x}; otherwise it uses @code{print}.
4915
4916@table @code
4917@kindex display
d4f3574e
SS
4918@item display @var{expr}
4919Add the expression @var{expr} to the list of expressions to display
c906108c
SS
4920each time your program stops. @xref{Expressions, ,Expressions}.
4921
4922@code{display} does not repeat if you press @key{RET} again after using it.
4923
d4f3574e 4924@item display/@var{fmt} @var{expr}
c906108c 4925For @var{fmt} specifying only a display format and not a size or
d4f3574e 4926count, add the expression @var{expr} to the auto-display list but
c906108c
SS
4927arrange to display it each time in the specified format @var{fmt}.
4928@xref{Output Formats,,Output formats}.
4929
4930@item display/@var{fmt} @var{addr}
4931For @var{fmt} @samp{i} or @samp{s}, or including a unit-size or a
4932number of units, add the expression @var{addr} as a memory address to
4933be examined each time your program stops. Examining means in effect
4934doing @samp{x/@var{fmt} @var{addr}}. @xref{Memory, ,Examining memory}.
4935@end table
4936
4937For example, @samp{display/i $pc} can be helpful, to see the machine
4938instruction about to be executed each time execution stops (@samp{$pc}
d4f3574e 4939is a common name for the program counter; @pxref{Registers, ,Registers}).
c906108c
SS
4940
4941@table @code
4942@kindex delete display
4943@kindex undisplay
4944@item undisplay @var{dnums}@dots{}
4945@itemx delete display @var{dnums}@dots{}
4946Remove item numbers @var{dnums} from the list of expressions to display.
4947
4948@code{undisplay} does not repeat if you press @key{RET} after using it.
4949(Otherwise you would just get the error @samp{No display number @dots{}}.)
4950
4951@kindex disable display
4952@item disable display @var{dnums}@dots{}
4953Disable the display of item numbers @var{dnums}. A disabled display
4954item is not printed automatically, but is not forgotten. It may be
4955enabled again later.
4956
4957@kindex enable display
4958@item enable display @var{dnums}@dots{}
4959Enable display of item numbers @var{dnums}. It becomes effective once
4960again in auto display of its expression, until you specify otherwise.
4961
4962@item display
4963Display the current values of the expressions on the list, just as is
4964done when your program stops.
4965
4966@kindex info display
4967@item info display
4968Print the list of expressions previously set up to display
4969automatically, each one with its item number, but without showing the
4970values. This includes disabled expressions, which are marked as such.
4971It also includes expressions which would not be displayed right now
4972because they refer to automatic variables not currently available.
4973@end table
4974
4975If a display expression refers to local variables, then it does not make
4976sense outside the lexical context for which it was set up. Such an
4977expression is disabled when execution enters a context where one of its
4978variables is not defined. For example, if you give the command
4979@code{display last_char} while inside a function with an argument
4980@code{last_char}, @value{GDBN} displays this argument while your program
4981continues to stop inside that function. When it stops elsewhere---where
4982there is no variable @code{last_char}---the display is disabled
4983automatically. The next time your program stops where @code{last_char}
4984is meaningful, you can enable the display expression once again.
4985
6d2ebf8b 4986@node Print Settings
c906108c
SS
4987@section Print settings
4988
4989@cindex format options
4990@cindex print settings
4991@value{GDBN} provides the following ways to control how arrays, structures,
4992and symbols are printed.
4993
4994@noindent
4995These settings are useful for debugging programs in any language:
4996
4997@table @code
4998@kindex set print address
4999@item set print address
5000@itemx set print address on
5001@value{GDBN} prints memory addresses showing the location of stack
5002traces, structure values, pointer values, breakpoints, and so forth,
5003even when it also displays the contents of those addresses. The default
5004is @code{on}. For example, this is what a stack frame display looks like with
5005@code{set print address on}:
5006
5007@smallexample
5008@group
5009(@value{GDBP}) f
5010#0 set_quotes (lq=0x34c78 "<<", rq=0x34c88 ">>")
5011 at input.c:530
5012530 if (lquote != def_lquote)
5013@end group
5014@end smallexample
5015
5016@item set print address off
5017Do not print addresses when displaying their contents. For example,
5018this is the same stack frame displayed with @code{set print address off}:
5019
5020@smallexample
5021@group
5022(@value{GDBP}) set print addr off
5023(@value{GDBP}) f
5024#0 set_quotes (lq="<<", rq=">>") at input.c:530
5025530 if (lquote != def_lquote)
5026@end group
5027@end smallexample
5028
5029You can use @samp{set print address off} to eliminate all machine
5030dependent displays from the @value{GDBN} interface. For example, with
5031@code{print address off}, you should get the same text for backtraces on
5032all machines---whether or not they involve pointer arguments.
5033
5034@kindex show print address
5035@item show print address
5036Show whether or not addresses are to be printed.
5037@end table
5038
5039When @value{GDBN} prints a symbolic address, it normally prints the
5040closest earlier symbol plus an offset. If that symbol does not uniquely
5041identify the address (for example, it is a name whose scope is a single
5042source file), you may need to clarify. One way to do this is with
5043@code{info line}, for example @samp{info line *0x4537}. Alternately,
5044you can set @value{GDBN} to print the source file and line number when
5045it prints a symbolic address:
5046
5047@table @code
5048@kindex set print symbol-filename
5049@item set print symbol-filename on
5050Tell @value{GDBN} to print the source file name and line number of a
5051symbol in the symbolic form of an address.
5052
5053@item set print symbol-filename off
5054Do not print source file name and line number of a symbol. This is the
5055default.
5056
5057@kindex show print symbol-filename
5058@item show print symbol-filename
5059Show whether or not @value{GDBN} will print the source file name and
5060line number of a symbol in the symbolic form of an address.
5061@end table
5062
5063Another situation where it is helpful to show symbol filenames and line
5064numbers is when disassembling code; @value{GDBN} shows you the line
5065number and source file that corresponds to each instruction.
5066
5067Also, you may wish to see the symbolic form only if the address being
5068printed is reasonably close to the closest earlier symbol:
5069
5070@table @code
5071@kindex set print max-symbolic-offset
5072@item set print max-symbolic-offset @var{max-offset}
5073Tell @value{GDBN} to only display the symbolic form of an address if the
5074offset between the closest earlier symbol and the address is less than
5d161b24 5075@var{max-offset}. The default is 0, which tells @value{GDBN}
c906108c
SS
5076to always print the symbolic form of an address if any symbol precedes it.
5077
5078@kindex show print max-symbolic-offset
5079@item show print max-symbolic-offset
5080Ask how large the maximum offset is that @value{GDBN} prints in a
5081symbolic address.
5082@end table
5083
5084@cindex wild pointer, interpreting
5085@cindex pointer, finding referent
5086If you have a pointer and you are not sure where it points, try
5087@samp{set print symbol-filename on}. Then you can determine the name
5088and source file location of the variable where it points, using
5089@samp{p/a @var{pointer}}. This interprets the address in symbolic form.
5090For example, here @value{GDBN} shows that a variable @code{ptt} points
5091at another variable @code{t}, defined in @file{hi2.c}:
5092
5093@example
5094(@value{GDBP}) set print symbol-filename on
5095(@value{GDBP}) p/a ptt
5096$4 = 0xe008 <t in hi2.c>
5097@end example
5098
5099@quotation
5100@emph{Warning:} For pointers that point to a local variable, @samp{p/a}
5101does not show the symbol name and filename of the referent, even with
5102the appropriate @code{set print} options turned on.
5103@end quotation
5104
5105Other settings control how different kinds of objects are printed:
5106
5107@table @code
5108@kindex set print array
5109@item set print array
5110@itemx set print array on
5111Pretty print arrays. This format is more convenient to read,
5112but uses more space. The default is off.
5113
5114@item set print array off
5115Return to compressed format for arrays.
5116
5117@kindex show print array
5118@item show print array
5119Show whether compressed or pretty format is selected for displaying
5120arrays.
5121
5122@kindex set print elements
5123@item set print elements @var{number-of-elements}
5124Set a limit on how many elements of an array @value{GDBN} will print.
5125If @value{GDBN} is printing a large array, it stops printing after it has
5126printed the number of elements set by the @code{set print elements} command.
5127This limit also applies to the display of strings.
d4f3574e 5128When @value{GDBN} starts, this limit is set to 200.
c906108c
SS
5129Setting @var{number-of-elements} to zero means that the printing is unlimited.
5130
5131@kindex show print elements
5132@item show print elements
5133Display the number of elements of a large array that @value{GDBN} will print.
5134If the number is 0, then the printing is unlimited.
5135
5136@kindex set print null-stop
5137@item set print null-stop
5138Cause @value{GDBN} to stop printing the characters of an array when the first
d4f3574e 5139@sc{null} is encountered. This is useful when large arrays actually
c906108c 5140contain only short strings.
d4f3574e 5141The default is off.
c906108c
SS
5142
5143@kindex set print pretty
5144@item set print pretty on
5d161b24 5145Cause @value{GDBN} to print structures in an indented format with one member
c906108c
SS
5146per line, like this:
5147
5148@smallexample
5149@group
5150$1 = @{
5151 next = 0x0,
5152 flags = @{
5153 sweet = 1,
5154 sour = 1
5155 @},
5156 meat = 0x54 "Pork"
5157@}
5158@end group
5159@end smallexample
5160
5161@item set print pretty off
5162Cause @value{GDBN} to print structures in a compact format, like this:
5163
5164@smallexample
5165@group
5166$1 = @{next = 0x0, flags = @{sweet = 1, sour = 1@}, \
5167meat = 0x54 "Pork"@}
5168@end group
5169@end smallexample
5170
5171@noindent
5172This is the default format.
5173
5174@kindex show print pretty
5175@item show print pretty
5176Show which format @value{GDBN} is using to print structures.
5177
5178@kindex set print sevenbit-strings
5179@item set print sevenbit-strings on
5180Print using only seven-bit characters; if this option is set,
5181@value{GDBN} displays any eight-bit characters (in strings or
5182character values) using the notation @code{\}@var{nnn}. This setting is
5183best if you are working in English (@sc{ascii}) and you use the
5184high-order bit of characters as a marker or ``meta'' bit.
5185
5186@item set print sevenbit-strings off
5187Print full eight-bit characters. This allows the use of more
5188international character sets, and is the default.
5189
5190@kindex show print sevenbit-strings
5191@item show print sevenbit-strings
5192Show whether or not @value{GDBN} is printing only seven-bit characters.
5193
5194@kindex set print union
5195@item set print union on
5d161b24 5196Tell @value{GDBN} to print unions which are contained in structures. This
c906108c
SS
5197is the default setting.
5198
5199@item set print union off
5200Tell @value{GDBN} not to print unions which are contained in structures.
5201
5202@kindex show print union
5203@item show print union
5204Ask @value{GDBN} whether or not it will print unions which are contained in
5205structures.
5206
5207For example, given the declarations
5208
5209@smallexample
5210typedef enum @{Tree, Bug@} Species;
5211typedef enum @{Big_tree, Acorn, Seedling@} Tree_forms;
5d161b24 5212typedef enum @{Caterpillar, Cocoon, Butterfly@}
c906108c
SS
5213 Bug_forms;
5214
5215struct thing @{
5216 Species it;
5217 union @{
5218 Tree_forms tree;
5219 Bug_forms bug;
5220 @} form;
5221@};
5222
5223struct thing foo = @{Tree, @{Acorn@}@};
5224@end smallexample
5225
5226@noindent
5227with @code{set print union on} in effect @samp{p foo} would print
5228
5229@smallexample
5230$1 = @{it = Tree, form = @{tree = Acorn, bug = Cocoon@}@}
5231@end smallexample
5232
5233@noindent
5234and with @code{set print union off} in effect it would print
5235
5236@smallexample
5237$1 = @{it = Tree, form = @{...@}@}
5238@end smallexample
5239@end table
5240
c906108c
SS
5241@need 1000
5242@noindent
b37052ae 5243These settings are of interest when debugging C@t{++} programs:
c906108c
SS
5244
5245@table @code
5246@cindex demangling
5247@kindex set print demangle
5248@item set print demangle
5249@itemx set print demangle on
b37052ae 5250Print C@t{++} names in their source form rather than in the encoded
c906108c 5251(``mangled'') form passed to the assembler and linker for type-safe
d4f3574e 5252linkage. The default is on.
c906108c
SS
5253
5254@kindex show print demangle
5255@item show print demangle
b37052ae 5256Show whether C@t{++} names are printed in mangled or demangled form.
c906108c
SS
5257
5258@kindex set print asm-demangle
5259@item set print asm-demangle
5260@itemx set print asm-demangle on
b37052ae 5261Print C@t{++} names in their source form rather than their mangled form, even
c906108c
SS
5262in assembler code printouts such as instruction disassemblies.
5263The default is off.
5264
5265@kindex show print asm-demangle
5266@item show print asm-demangle
b37052ae 5267Show whether C@t{++} names in assembly listings are printed in mangled
c906108c
SS
5268or demangled form.
5269
5270@kindex set demangle-style
b37052ae
EZ
5271@cindex C@t{++} symbol decoding style
5272@cindex symbol decoding style, C@t{++}
c906108c
SS
5273@item set demangle-style @var{style}
5274Choose among several encoding schemes used by different compilers to
b37052ae 5275represent C@t{++} names. The choices for @var{style} are currently:
c906108c
SS
5276
5277@table @code
5278@item auto
5279Allow @value{GDBN} to choose a decoding style by inspecting your program.
5280
5281@item gnu
b37052ae 5282Decode based on the @sc{gnu} C@t{++} compiler (@code{g++}) encoding algorithm.
c906108c 5283This is the default.
c906108c
SS
5284
5285@item hp
b37052ae 5286Decode based on the HP ANSI C@t{++} (@code{aCC}) encoding algorithm.
c906108c
SS
5287
5288@item lucid
b37052ae 5289Decode based on the Lucid C@t{++} compiler (@code{lcc}) encoding algorithm.
c906108c
SS
5290
5291@item arm
b37052ae 5292Decode using the algorithm in the @cite{C@t{++} Annotated Reference Manual}.
c906108c
SS
5293@strong{Warning:} this setting alone is not sufficient to allow
5294debugging @code{cfront}-generated executables. @value{GDBN} would
5295require further enhancement to permit that.
5296
5297@end table
5298If you omit @var{style}, you will see a list of possible formats.
5299
5300@kindex show demangle-style
5301@item show demangle-style
b37052ae 5302Display the encoding style currently in use for decoding C@t{++} symbols.
c906108c
SS
5303
5304@kindex set print object
5305@item set print object
5306@itemx set print object on
5307When displaying a pointer to an object, identify the @emph{actual}
5308(derived) type of the object rather than the @emph{declared} type, using
5309the virtual function table.
5310
5311@item set print object off
5312Display only the declared type of objects, without reference to the
5313virtual function table. This is the default setting.
5314
5315@kindex show print object
5316@item show print object
5317Show whether actual, or declared, object types are displayed.
5318
5319@kindex set print static-members
5320@item set print static-members
5321@itemx set print static-members on
b37052ae 5322Print static members when displaying a C@t{++} object. The default is on.
c906108c
SS
5323
5324@item set print static-members off
b37052ae 5325Do not print static members when displaying a C@t{++} object.
c906108c
SS
5326
5327@kindex show print static-members
5328@item show print static-members
b37052ae 5329Show whether C@t{++} static members are printed, or not.
c906108c
SS
5330
5331@c These don't work with HP ANSI C++ yet.
5332@kindex set print vtbl
5333@item set print vtbl
5334@itemx set print vtbl on
b37052ae 5335Pretty print C@t{++} virtual function tables. The default is off.
c906108c 5336(The @code{vtbl} commands do not work on programs compiled with the HP
b37052ae 5337ANSI C@t{++} compiler (@code{aCC}).)
c906108c
SS
5338
5339@item set print vtbl off
b37052ae 5340Do not pretty print C@t{++} virtual function tables.
c906108c
SS
5341
5342@kindex show print vtbl
5343@item show print vtbl
b37052ae 5344Show whether C@t{++} virtual function tables are pretty printed, or not.
c906108c 5345@end table
c906108c 5346
6d2ebf8b 5347@node Value History
c906108c
SS
5348@section Value history
5349
5350@cindex value history
5d161b24
DB
5351Values printed by the @code{print} command are saved in the @value{GDBN}
5352@dfn{value history}. This allows you to refer to them in other expressions.
5353Values are kept until the symbol table is re-read or discarded
5354(for example with the @code{file} or @code{symbol-file} commands).
5355When the symbol table changes, the value history is discarded,
5356since the values may contain pointers back to the types defined in the
c906108c
SS
5357symbol table.
5358
5359@cindex @code{$}
5360@cindex @code{$$}
5361@cindex history number
5362The values printed are given @dfn{history numbers} by which you can
5363refer to them. These are successive integers starting with one.
5364@code{print} shows you the history number assigned to a value by
5365printing @samp{$@var{num} = } before the value; here @var{num} is the
5366history number.
5367
5368To refer to any previous value, use @samp{$} followed by the value's
5369history number. The way @code{print} labels its output is designed to
5370remind you of this. Just @code{$} refers to the most recent value in
5371the history, and @code{$$} refers to the value before that.
5372@code{$$@var{n}} refers to the @var{n}th value from the end; @code{$$2}
5373is the value just prior to @code{$$}, @code{$$1} is equivalent to
5374@code{$$}, and @code{$$0} is equivalent to @code{$}.
5375
5376For example, suppose you have just printed a pointer to a structure and
5377want to see the contents of the structure. It suffices to type
5378
5379@example
5380p *$
5381@end example
5382
5383If you have a chain of structures where the component @code{next} points
5384to the next one, you can print the contents of the next one with this:
5385
5386@example
5387p *$.next
5388@end example
5389
5390@noindent
5391You can print successive links in the chain by repeating this
5392command---which you can do by just typing @key{RET}.
5393
5394Note that the history records values, not expressions. If the value of
5395@code{x} is 4 and you type these commands:
5396
5397@example
5398print x
5399set x=5
5400@end example
5401
5402@noindent
5403then the value recorded in the value history by the @code{print} command
5404remains 4 even though the value of @code{x} has changed.
5405
5406@table @code
5407@kindex show values
5408@item show values
5409Print the last ten values in the value history, with their item numbers.
5410This is like @samp{p@ $$9} repeated ten times, except that @code{show
5411values} does not change the history.
5412
5413@item show values @var{n}
5414Print ten history values centered on history item number @var{n}.
5415
5416@item show values +
5417Print ten history values just after the values last printed. If no more
5418values are available, @code{show values +} produces no display.
5419@end table
5420
5421Pressing @key{RET} to repeat @code{show values @var{n}} has exactly the
5422same effect as @samp{show values +}.
5423
6d2ebf8b 5424@node Convenience Vars
c906108c
SS
5425@section Convenience variables
5426
5427@cindex convenience variables
5428@value{GDBN} provides @dfn{convenience variables} that you can use within
5429@value{GDBN} to hold on to a value and refer to it later. These variables
5430exist entirely within @value{GDBN}; they are not part of your program, and
5431setting a convenience variable has no direct effect on further execution
5432of your program. That is why you can use them freely.
5433
5434Convenience variables are prefixed with @samp{$}. Any name preceded by
5435@samp{$} can be used for a convenience variable, unless it is one of
d4f3574e 5436the predefined machine-specific register names (@pxref{Registers, ,Registers}).
c906108c
SS
5437(Value history references, in contrast, are @emph{numbers} preceded
5438by @samp{$}. @xref{Value History, ,Value history}.)
5439
5440You can save a value in a convenience variable with an assignment
5441expression, just as you would set a variable in your program.
5442For example:
5443
5444@example
5445set $foo = *object_ptr
5446@end example
5447
5448@noindent
5449would save in @code{$foo} the value contained in the object pointed to by
5450@code{object_ptr}.
5451
5452Using a convenience variable for the first time creates it, but its
5453value is @code{void} until you assign a new value. You can alter the
5454value with another assignment at any time.
5455
5456Convenience variables have no fixed types. You can assign a convenience
5457variable any type of value, including structures and arrays, even if
5458that variable already has a value of a different type. The convenience
5459variable, when used as an expression, has the type of its current value.
5460
5461@table @code
5462@kindex show convenience
5463@item show convenience
5464Print a list of convenience variables used so far, and their values.
d4f3574e 5465Abbreviated @code{show conv}.
c906108c
SS
5466@end table
5467
5468One of the ways to use a convenience variable is as a counter to be
5469incremented or a pointer to be advanced. For example, to print
5470a field from successive elements of an array of structures:
5471
5472@example
5473set $i = 0
5474print bar[$i++]->contents
5475@end example
5476
d4f3574e
SS
5477@noindent
5478Repeat that command by typing @key{RET}.
c906108c
SS
5479
5480Some convenience variables are created automatically by @value{GDBN} and given
5481values likely to be useful.
5482
5483@table @code
41afff9a 5484@vindex $_@r{, convenience variable}
c906108c
SS
5485@item $_
5486The variable @code{$_} is automatically set by the @code{x} command to
5487the last address examined (@pxref{Memory, ,Examining memory}). Other
5488commands which provide a default address for @code{x} to examine also
5489set @code{$_} to that address; these commands include @code{info line}
5490and @code{info breakpoint}. The type of @code{$_} is @code{void *}
5491except when set by the @code{x} command, in which case it is a pointer
5492to the type of @code{$__}.
5493
41afff9a 5494@vindex $__@r{, convenience variable}
c906108c
SS
5495@item $__
5496The variable @code{$__} is automatically set by the @code{x} command
5497to the value found in the last address examined. Its type is chosen
5498to match the format in which the data was printed.
5499
5500@item $_exitcode
41afff9a 5501@vindex $_exitcode@r{, convenience variable}
c906108c
SS
5502The variable @code{$_exitcode} is automatically set to the exit code when
5503the program being debugged terminates.
5504@end table
5505
53a5351d
JM
5506On HP-UX systems, if you refer to a function or variable name that
5507begins with a dollar sign, @value{GDBN} searches for a user or system
5508name first, before it searches for a convenience variable.
c906108c 5509
6d2ebf8b 5510@node Registers
c906108c
SS
5511@section Registers
5512
5513@cindex registers
5514You can refer to machine register contents, in expressions, as variables
5515with names starting with @samp{$}. The names of registers are different
5516for each machine; use @code{info registers} to see the names used on
5517your machine.
5518
5519@table @code
5520@kindex info registers
5521@item info registers
5522Print the names and values of all registers except floating-point
5523registers (in the selected stack frame).
5524
5525@kindex info all-registers
5526@cindex floating point registers
5527@item info all-registers
5528Print the names and values of all registers, including floating-point
5529registers.
5530
5531@item info registers @var{regname} @dots{}
5532Print the @dfn{relativized} value of each specified register @var{regname}.
5d161b24
DB
5533As discussed in detail below, register values are normally relative to
5534the selected stack frame. @var{regname} may be any register name valid on
c906108c
SS
5535the machine you are using, with or without the initial @samp{$}.
5536@end table
5537
5538@value{GDBN} has four ``standard'' register names that are available (in
5539expressions) on most machines---whenever they do not conflict with an
5540architecture's canonical mnemonics for registers. The register names
5541@code{$pc} and @code{$sp} are used for the program counter register and
5542the stack pointer. @code{$fp} is used for a register that contains a
5543pointer to the current stack frame, and @code{$ps} is used for a
5544register that contains the processor status. For example,
5545you could print the program counter in hex with
5546
5547@example
5548p/x $pc
5549@end example
5550
5551@noindent
5552or print the instruction to be executed next with
5553
5554@example
5555x/i $pc
5556@end example
5557
5558@noindent
5559or add four to the stack pointer@footnote{This is a way of removing
5560one word from the stack, on machines where stacks grow downward in
5561memory (most machines, nowadays). This assumes that the innermost
5562stack frame is selected; setting @code{$sp} is not allowed when other
5563stack frames are selected. To pop entire frames off the stack,
5564regardless of machine architecture, use @code{return};
d4f3574e 5565see @ref{Returning, ,Returning from a function}.} with
c906108c
SS
5566
5567@example
5568set $sp += 4
5569@end example
5570
5571Whenever possible, these four standard register names are available on
5572your machine even though the machine has different canonical mnemonics,
5573so long as there is no conflict. The @code{info registers} command
5574shows the canonical names. For example, on the SPARC, @code{info
5575registers} displays the processor status register as @code{$psr} but you
d4f3574e
SS
5576can also refer to it as @code{$ps}; and on x86-based machines @code{$ps}
5577is an alias for the @sc{eflags} register.
c906108c
SS
5578
5579@value{GDBN} always considers the contents of an ordinary register as an
5580integer when the register is examined in this way. Some machines have
5581special registers which can hold nothing but floating point; these
5582registers are considered to have floating point values. There is no way
5583to refer to the contents of an ordinary register as floating point value
5584(although you can @emph{print} it as a floating point value with
5585@samp{print/f $@var{regname}}).
5586
5587Some registers have distinct ``raw'' and ``virtual'' data formats. This
5588means that the data format in which the register contents are saved by
5589the operating system is not the same one that your program normally
5590sees. For example, the registers of the 68881 floating point
5591coprocessor are always saved in ``extended'' (raw) format, but all C
5592programs expect to work with ``double'' (virtual) format. In such
5d161b24 5593cases, @value{GDBN} normally works with the virtual format only (the format
c906108c
SS
5594that makes sense for your program), but the @code{info registers} command
5595prints the data in both formats.
5596
5597Normally, register values are relative to the selected stack frame
5598(@pxref{Selection, ,Selecting a frame}). This means that you get the
5599value that the register would contain if all stack frames farther in
5600were exited and their saved registers restored. In order to see the
5601true contents of hardware registers, you must select the innermost
5602frame (with @samp{frame 0}).
5603
5604However, @value{GDBN} must deduce where registers are saved, from the machine
5605code generated by your compiler. If some registers are not saved, or if
5606@value{GDBN} is unable to locate the saved registers, the selected stack
5607frame makes no difference.
5608
6d2ebf8b 5609@node Floating Point Hardware
c906108c
SS
5610@section Floating point hardware
5611@cindex floating point
5612
5613Depending on the configuration, @value{GDBN} may be able to give
5614you more information about the status of the floating point hardware.
5615
5616@table @code
5617@kindex info float
5618@item info float
5619Display hardware-dependent information about the floating
5620point unit. The exact contents and layout vary depending on the
5621floating point chip. Currently, @samp{info float} is supported on
5622the ARM and x86 machines.
5623@end table
c906108c 5624
29e57380
C
5625@node Memory Region Attributes
5626@section Memory Region Attributes
5627@cindex memory region attributes
5628
5629@dfn{Memory region attributes} allow you to describe special handling
5630required by regions of your target's memory. @value{GDBN} uses attributes
5631to determine whether to allow certain types of memory accesses; whether to
5632use specific width accesses; and whether to cache target memory.
5633
5634Defined memory regions can be individually enabled and disabled. When a
5635memory region is disabled, @value{GDBN} uses the default attributes when
5636accessing memory in that region. Similarly, if no memory regions have
5637been defined, @value{GDBN} uses the default attributes when accessing
5638all memory.
5639
5640When a memory region is defined, it is given a number to identify it;
5641to enable, disable, or remove a memory region, you specify that number.
5642
5643@table @code
5644@kindex mem
5645@item mem @var{address1} @var{address1} @var{attributes}@dots{}
5646Define memory region bounded by @var{address1} and @var{address2}
5647with attributes @var{attributes}@dots{}.
5648
5649@kindex delete mem
5650@item delete mem @var{nums}@dots{}
5651Remove memory region numbers @var{nums}.
5652
5653@kindex disable mem
5654@item disable mem @var{nums}@dots{}
5655Disable memory region numbers @var{nums}.
5656A disabled memory region is not forgotten.
5657It may be enabled again later.
5658
5659@kindex enable mem
5660@item enable mem @var{nums}@dots{}
5661Enable memory region numbers @var{nums}.
5662
5663@kindex info mem
5664@item info mem
5665Print a table of all defined memory regions, with the following columns
5666for each region.
5667
5668@table @emph
5669@item Memory Region Number
5670@item Enabled or Disabled.
5671Enabled memory regions are marked with @samp{y}.
5672Disabled memory regions are marked with @samp{n}.
5673
5674@item Lo Address
5675The address defining the inclusive lower bound of the memory region.
5676
5677@item Hi Address
5678The address defining the exclusive upper bound of the memory region.
5679
5680@item Attributes
5681The list of attributes set for this memory region.
5682@end table
5683@end table
5684
5685
5686@subsection Attributes
5687
5688@subsubsection Memory Access Mode
5689The access mode attributes set whether @value{GDBN} may make read or
5690write accesses to a memory region.
5691
5692While these attributes prevent @value{GDBN} from performing invalid
5693memory accesses, they do nothing to prevent the target system, I/O DMA,
5694etc. from accessing memory.
5695
5696@table @code
5697@item ro
5698Memory is read only.
5699@item wo
5700Memory is write only.
5701@item rw
5702Memory is read/write (default).
5703@end table
5704
5705@subsubsection Memory Access Size
5706The acccess size attributes tells @value{GDBN} to use specific sized
5707accesses in the memory region. Often memory mapped device registers
5708require specific sized accesses. If no access size attribute is
5709specified, @value{GDBN} may use accesses of any size.
5710
5711@table @code
5712@item 8
5713Use 8 bit memory accesses.
5714@item 16
5715Use 16 bit memory accesses.
5716@item 32
5717Use 32 bit memory accesses.
5718@item 64
5719Use 64 bit memory accesses.
5720@end table
5721
5722@c @subsubsection Hardware/Software Breakpoints
5723@c The hardware/software breakpoint attributes set whether @value{GDBN}
5724@c will use hardware or software breakpoints for the internal breakpoints
5725@c used by the step, next, finish, until, etc. commands.
5726@c
5727@c @table @code
5728@c @item hwbreak
5729@c Always use hardware breakpoints
5730@c @item swbreak (default)
5731@c @end table
5732
5733@subsubsection Data Cache
5734The data cache attributes set whether @value{GDBN} will cache target
5735memory. While this generally improves performance by reducing debug
5736protocol overhead, it can lead to incorrect results because @value{GDBN}
5737does not know about volatile variables or memory mapped device
5738registers.
5739
5740@table @code
5741@item cache
5742Enable @value{GDBN} to cache target memory.
5743@item nocache (default)
5744Disable @value{GDBN} from caching target memory.
5745@end table
5746
5747@c @subsubsection Memory Write Verification
5748@c The memory write verification attributes set whether @value{GDBN}
5749@c will re-reads data after each write to verify the write was successful.
5750@c
5751@c @table @code
5752@c @item verify
5753@c @item noverify (default)
5754@c @end table
5755
b37052ae
EZ
5756@node Tracepoints
5757@chapter Tracepoints
5758@c This chapter is based on the documentation written by Michael
5759@c Snyder, David Taylor, Jim Blandy, and Elena Zannoni.
5760
5761@cindex tracepoints
5762In some applications, it is not feasible for the debugger to interrupt
5763the program's execution long enough for the developer to learn
5764anything helpful about its behavior. If the program's correctness
5765depends on its real-time behavior, delays introduced by a debugger
5766might cause the program to change its behavior drastically, or perhaps
5767fail, even when the code itself is correct. It is useful to be able
5768to observe the program's behavior without interrupting it.
5769
5770Using @value{GDBN}'s @code{trace} and @code{collect} commands, you can
5771specify locations in the program, called @dfn{tracepoints}, and
5772arbitrary expressions to evaluate when those tracepoints are reached.
5773Later, using the @code{tfind} command, you can examine the values
5774those expressions had when the program hit the tracepoints. The
5775expressions may also denote objects in memory---structures or arrays,
5776for example---whose values @value{GDBN} should record; while visiting
5777a particular tracepoint, you may inspect those objects as if they were
5778in memory at that moment. However, because @value{GDBN} records these
5779values without interacting with you, it can do so quickly and
5780unobtrusively, hopefully not disturbing the program's behavior.
5781
5782The tracepoint facility is currently available only for remote
2c0069bb
EZ
5783targets. @xref{Targets}. In addition, your remote target must know how
5784to collect trace data. This functionality is implemented in the remote
5785stub; however, none of the stubs distributed with @value{GDBN} support
5786tracepoints as of this writing.
b37052ae
EZ
5787
5788This chapter describes the tracepoint commands and features.
5789
5790@menu
5791* Set Tracepoints::
5792* Analyze Collected Data::
5793* Tracepoint Variables::
5794@end menu
5795
5796@node Set Tracepoints
5797@section Commands to Set Tracepoints
5798
5799Before running such a @dfn{trace experiment}, an arbitrary number of
5800tracepoints can be set. Like a breakpoint (@pxref{Set Breaks}), a
5801tracepoint has a number assigned to it by @value{GDBN}. Like with
5802breakpoints, tracepoint numbers are successive integers starting from
5803one. Many of the commands associated with tracepoints take the
5804tracepoint number as their argument, to identify which tracepoint to
5805work on.
5806
5807For each tracepoint, you can specify, in advance, some arbitrary set
5808of data that you want the target to collect in the trace buffer when
5809it hits that tracepoint. The collected data can include registers,
5810local variables, or global data. Later, you can use @value{GDBN}
5811commands to examine the values these data had at the time the
5812tracepoint was hit.
5813
5814This section describes commands to set tracepoints and associated
5815conditions and actions.
5816
5817@menu
5818* Create and Delete Tracepoints::
5819* Enable and Disable Tracepoints::
5820* Tracepoint Passcounts::
5821* Tracepoint Actions::
5822* Listing Tracepoints::
5823* Starting and Stopping Trace Experiment::
5824@end menu
5825
5826@node Create and Delete Tracepoints
5827@subsection Create and Delete Tracepoints
5828
5829@table @code
5830@cindex set tracepoint
5831@kindex trace
5832@item trace
5833The @code{trace} command is very similar to the @code{break} command.
5834Its argument can be a source line, a function name, or an address in
5835the target program. @xref{Set Breaks}. The @code{trace} command
5836defines a tracepoint, which is a point in the target program where the
5837debugger will briefly stop, collect some data, and then allow the
5838program to continue. Setting a tracepoint or changing its commands
5839doesn't take effect until the next @code{tstart} command; thus, you
5840cannot change the tracepoint attributes once a trace experiment is
5841running.
5842
5843Here are some examples of using the @code{trace} command:
5844
5845@smallexample
5846(@value{GDBP}) @b{trace foo.c:121} // a source file and line number
5847
5848(@value{GDBP}) @b{trace +2} // 2 lines forward
5849
5850(@value{GDBP}) @b{trace my_function} // first source line of function
5851
5852(@value{GDBP}) @b{trace *my_function} // EXACT start address of function
5853
5854(@value{GDBP}) @b{trace *0x2117c4} // an address
5855@end smallexample
5856
5857@noindent
5858You can abbreviate @code{trace} as @code{tr}.
5859
5860@vindex $tpnum
5861@cindex last tracepoint number
5862@cindex recent tracepoint number
5863@cindex tracepoint number
5864The convenience variable @code{$tpnum} records the tracepoint number
5865of the most recently set tracepoint.
5866
5867@kindex delete tracepoint
5868@cindex tracepoint deletion
5869@item delete tracepoint @r{[}@var{num}@r{]}
5870Permanently delete one or more tracepoints. With no argument, the
5871default is to delete all tracepoints.
5872
5873Examples:
5874
5875@smallexample
5876(@value{GDBP}) @b{delete trace 1 2 3} // remove three tracepoints
5877
5878(@value{GDBP}) @b{delete trace} // remove all tracepoints
5879@end smallexample
5880
5881@noindent
5882You can abbreviate this command as @code{del tr}.
5883@end table
5884
5885@node Enable and Disable Tracepoints
5886@subsection Enable and Disable Tracepoints
5887
5888@table @code
5889@kindex disable tracepoint
5890@item disable tracepoint @r{[}@var{num}@r{]}
5891Disable tracepoint @var{num}, or all tracepoints if no argument
5892@var{num} is given. A disabled tracepoint will have no effect during
5893the next trace experiment, but it is not forgotten. You can re-enable
5894a disabled tracepoint using the @code{enable tracepoint} command.
5895
5896@kindex enable tracepoint
5897@item enable tracepoint @r{[}@var{num}@r{]}
5898Enable tracepoint @var{num}, or all tracepoints. The enabled
5899tracepoints will become effective the next time a trace experiment is
5900run.
5901@end table
5902
5903@node Tracepoint Passcounts
5904@subsection Tracepoint Passcounts
5905
5906@table @code
5907@kindex passcount
5908@cindex tracepoint pass count
5909@item passcount @r{[}@var{n} @r{[}@var{num}@r{]]}
5910Set the @dfn{passcount} of a tracepoint. The passcount is a way to
5911automatically stop a trace experiment. If a tracepoint's passcount is
5912@var{n}, then the trace experiment will be automatically stopped on
5913the @var{n}'th time that tracepoint is hit. If the tracepoint number
5914@var{num} is not specified, the @code{passcount} command sets the
5915passcount of the most recently defined tracepoint. If no passcount is
5916given, the trace experiment will run until stopped explicitly by the
5917user.
5918
5919Examples:
5920
5921@smallexample
6826cf00
EZ
5922(@value{GDBP}) @b{passcount 5 2} // Stop on the 5th execution of
5923@exdent @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @code{// tracepoint 2}
b37052ae
EZ
5924
5925(@value{GDBP}) @b{passcount 12} // Stop on the 12th execution of the
6826cf00 5926@exdent @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @code{// most recently defined tracepoint.}
b37052ae
EZ
5927(@value{GDBP}) @b{trace foo}
5928(@value{GDBP}) @b{pass 3}
5929(@value{GDBP}) @b{trace bar}
5930(@value{GDBP}) @b{pass 2}
5931(@value{GDBP}) @b{trace baz}
5932(@value{GDBP}) @b{pass 1} // Stop tracing when foo has been
6826cf00
EZ
5933@exdent @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @code{// executed 3 times OR when bar has}
5934@exdent @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @code{// been executed 2 times}
5935@exdent @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @code{// OR when baz has been executed 1 time.}
b37052ae
EZ
5936@end smallexample
5937@end table
5938
5939@node Tracepoint Actions
5940@subsection Tracepoint Action Lists
5941
5942@table @code
5943@kindex actions
5944@cindex tracepoint actions
5945@item actions @r{[}@var{num}@r{]}
5946This command will prompt for a list of actions to be taken when the
5947tracepoint is hit. If the tracepoint number @var{num} is not
5948specified, this command sets the actions for the one that was most
5949recently defined (so that you can define a tracepoint and then say
5950@code{actions} without bothering about its number). You specify the
5951actions themselves on the following lines, one action at a time, and
5952terminate the actions list with a line containing just @code{end}. So
5953far, the only defined actions are @code{collect} and
5954@code{while-stepping}.
5955
5956@cindex remove actions from a tracepoint
5957To remove all actions from a tracepoint, type @samp{actions @var{num}}
5958and follow it immediately with @samp{end}.
5959
5960@smallexample
5961(@value{GDBP}) @b{collect @var{data}} // collect some data
5962
6826cf00 5963(@value{GDBP}) @b{while-stepping 5} // single-step 5 times, collect data
b37052ae 5964
6826cf00 5965(@value{GDBP}) @b{end} // signals the end of actions.
b37052ae
EZ
5966@end smallexample
5967
5968In the following example, the action list begins with @code{collect}
5969commands indicating the things to be collected when the tracepoint is
5970hit. Then, in order to single-step and collect additional data
5971following the tracepoint, a @code{while-stepping} command is used,
5972followed by the list of things to be collected while stepping. The
5973@code{while-stepping} command is terminated by its own separate
5974@code{end} command. Lastly, the action list is terminated by an
5975@code{end} command.
5976
5977@smallexample
5978(@value{GDBP}) @b{trace foo}
5979(@value{GDBP}) @b{actions}
5980Enter actions for tracepoint 1, one per line:
5981> collect bar,baz
5982> collect $regs
5983> while-stepping 12
5984 > collect $fp, $sp
5985 > end
5986end
5987@end smallexample
5988
5989@kindex collect @r{(tracepoints)}
5990@item collect @var{expr1}, @var{expr2}, @dots{}
5991Collect values of the given expressions when the tracepoint is hit.
5992This command accepts a comma-separated list of any valid expressions.
5993In addition to global, static, or local variables, the following
5994special arguments are supported:
5995
5996@table @code
5997@item $regs
5998collect all registers
5999
6000@item $args
6001collect all function arguments
6002
6003@item $locals
6004collect all local variables.
6005@end table
6006
6007You can give several consecutive @code{collect} commands, each one
6008with a single argument, or one @code{collect} command with several
6009arguments separated by commas: the effect is the same.
6010
f5c37c66
EZ
6011The command @code{info scope} (@pxref{Symbols, info scope}) is
6012particularly useful for figuring out what data to collect.
6013
b37052ae
EZ
6014@kindex while-stepping @r{(tracepoints)}
6015@item while-stepping @var{n}
6016Perform @var{n} single-step traces after the tracepoint, collecting
6017new data at each step. The @code{while-stepping} command is
6018followed by the list of what to collect while stepping (followed by
6019its own @code{end} command):
6020
6021@smallexample
6022> while-stepping 12
6023 > collect $regs, myglobal
6024 > end
6025>
6026@end smallexample
6027
6028@noindent
6029You may abbreviate @code{while-stepping} as @code{ws} or
6030@code{stepping}.
6031@end table
6032
6033@node Listing Tracepoints
6034@subsection Listing Tracepoints
6035
6036@table @code
6037@kindex info tracepoints
6038@cindex information about tracepoints
6039@item info tracepoints @r{[}@var{num}@r{]}
8a037dd7 6040Display information about the tracepoint @var{num}. If you don't specify
798c8bc6 6041a tracepoint number, displays information about all the tracepoints
b37052ae
EZ
6042defined so far. For each tracepoint, the following information is
6043shown:
6044
6045@itemize @bullet
6046@item
6047its number
6048@item
6049whether it is enabled or disabled
6050@item
6051its address
6052@item
6053its passcount as given by the @code{passcount @var{n}} command
6054@item
6055its step count as given by the @code{while-stepping @var{n}} command
6056@item
6057where in the source files is the tracepoint set
6058@item
6059its action list as given by the @code{actions} command
6060@end itemize
6061
6062@smallexample
6063(@value{GDBP}) @b{info trace}
6064Num Enb Address PassC StepC What
60651 y 0x002117c4 0 0 <gdb_asm>
6826cf00
EZ
60662 y 0x0020dc64 0 0 in g_test at g_test.c:1375
60673 y 0x0020b1f4 0 0 in get_data at ../foo.c:41
b37052ae
EZ
6068(@value{GDBP})
6069@end smallexample
6070
6071@noindent
6072This command can be abbreviated @code{info tp}.
6073@end table
6074
6075@node Starting and Stopping Trace Experiment
6076@subsection Starting and Stopping Trace Experiment
6077
6078@table @code
6079@kindex tstart
6080@cindex start a new trace experiment
6081@cindex collected data discarded
6082@item tstart
6083This command takes no arguments. It starts the trace experiment, and
6084begins collecting data. This has the side effect of discarding all
6085the data collected in the trace buffer during the previous trace
6086experiment.
6087
6088@kindex tstop
6089@cindex stop a running trace experiment
6090@item tstop
6091This command takes no arguments. It ends the trace experiment, and
6092stops collecting data.
6093
6094@strong{Note:} a trace experiment and data collection may stop
6095automatically if any tracepoint's passcount is reached
6096(@pxref{Tracepoint Passcounts}), or if the trace buffer becomes full.
6097
6098@kindex tstatus
6099@cindex status of trace data collection
6100@cindex trace experiment, status of
6101@item tstatus
6102This command displays the status of the current trace data
6103collection.
6104@end table
6105
6106Here is an example of the commands we described so far:
6107
6108@smallexample
6109(@value{GDBP}) @b{trace gdb_c_test}
6110(@value{GDBP}) @b{actions}
6111Enter actions for tracepoint #1, one per line.
6112> collect $regs,$locals,$args
6113> while-stepping 11
6114 > collect $regs
6115 > end
6116> end
6117(@value{GDBP}) @b{tstart}
6118 [time passes @dots{}]
6119(@value{GDBP}) @b{tstop}
6120@end smallexample
6121
6122
6123@node Analyze Collected Data
6124@section Using the collected data
6125
6126After the tracepoint experiment ends, you use @value{GDBN} commands
6127for examining the trace data. The basic idea is that each tracepoint
6128collects a trace @dfn{snapshot} every time it is hit and another
6129snapshot every time it single-steps. All these snapshots are
6130consecutively numbered from zero and go into a buffer, and you can
6131examine them later. The way you examine them is to @dfn{focus} on a
6132specific trace snapshot. When the remote stub is focused on a trace
6133snapshot, it will respond to all @value{GDBN} requests for memory and
6134registers by reading from the buffer which belongs to that snapshot,
6135rather than from @emph{real} memory or registers of the program being
6136debugged. This means that @strong{all} @value{GDBN} commands
6137(@code{print}, @code{info registers}, @code{backtrace}, etc.) will
6138behave as if we were currently debugging the program state as it was
6139when the tracepoint occurred. Any requests for data that are not in
6140the buffer will fail.
6141
6142@menu
6143* tfind:: How to select a trace snapshot
6144* tdump:: How to display all data for a snapshot
6145* save-tracepoints:: How to save tracepoints for a future run
6146@end menu
6147
6148@node tfind
6149@subsection @code{tfind @var{n}}
6150
6151@kindex tfind
6152@cindex select trace snapshot
6153@cindex find trace snapshot
6154The basic command for selecting a trace snapshot from the buffer is
6155@code{tfind @var{n}}, which finds trace snapshot number @var{n},
6156counting from zero. If no argument @var{n} is given, the next
6157snapshot is selected.
6158
6159Here are the various forms of using the @code{tfind} command.
6160
6161@table @code
6162@item tfind start
6163Find the first snapshot in the buffer. This is a synonym for
6164@code{tfind 0} (since 0 is the number of the first snapshot).
6165
6166@item tfind none
6167Stop debugging trace snapshots, resume @emph{live} debugging.
6168
6169@item tfind end
6170Same as @samp{tfind none}.
6171
6172@item tfind
6173No argument means find the next trace snapshot.
6174
6175@item tfind -
6176Find the previous trace snapshot before the current one. This permits
6177retracing earlier steps.
6178
6179@item tfind tracepoint @var{num}
6180Find the next snapshot associated with tracepoint @var{num}. Search
6181proceeds forward from the last examined trace snapshot. If no
6182argument @var{num} is given, it means find the next snapshot collected
6183for the same tracepoint as the current snapshot.
6184
6185@item tfind pc @var{addr}
6186Find the next snapshot associated with the value @var{addr} of the
6187program counter. Search proceeds forward from the last examined trace
6188snapshot. If no argument @var{addr} is given, it means find the next
6189snapshot with the same value of PC as the current snapshot.
6190
6191@item tfind outside @var{addr1}, @var{addr2}
6192Find the next snapshot whose PC is outside the given range of
6193addresses.
6194
6195@item tfind range @var{addr1}, @var{addr2}
6196Find the next snapshot whose PC is between @var{addr1} and
6197@var{addr2}. @c FIXME: Is the range inclusive or exclusive?
6198
6199@item tfind line @r{[}@var{file}:@r{]}@var{n}
6200Find the next snapshot associated with the source line @var{n}. If
6201the optional argument @var{file} is given, refer to line @var{n} in
6202that source file. Search proceeds forward from the last examined
6203trace snapshot. If no argument @var{n} is given, it means find the
6204next line other than the one currently being examined; thus saying
6205@code{tfind line} repeatedly can appear to have the same effect as
6206stepping from line to line in a @emph{live} debugging session.
6207@end table
6208
6209The default arguments for the @code{tfind} commands are specifically
6210designed to make it easy to scan through the trace buffer. For
6211instance, @code{tfind} with no argument selects the next trace
6212snapshot, and @code{tfind -} with no argument selects the previous
6213trace snapshot. So, by giving one @code{tfind} command, and then
6214simply hitting @key{RET} repeatedly you can examine all the trace
6215snapshots in order. Or, by saying @code{tfind -} and then hitting
6216@key{RET} repeatedly you can examine the snapshots in reverse order.
6217The @code{tfind line} command with no argument selects the snapshot
6218for the next source line executed. The @code{tfind pc} command with
6219no argument selects the next snapshot with the same program counter
6220(PC) as the current frame. The @code{tfind tracepoint} command with
6221no argument selects the next trace snapshot collected by the same
6222tracepoint as the current one.
6223
6224In addition to letting you scan through the trace buffer manually,
6225these commands make it easy to construct @value{GDBN} scripts that
6226scan through the trace buffer and print out whatever collected data
6227you are interested in. Thus, if we want to examine the PC, FP, and SP
6228registers from each trace frame in the buffer, we can say this:
6229
6230@smallexample
6231(@value{GDBP}) @b{tfind start}
6232(@value{GDBP}) @b{while ($trace_frame != -1)}
6233> printf "Frame %d, PC = %08X, SP = %08X, FP = %08X\n", \
6234 $trace_frame, $pc, $sp, $fp
6235> tfind
6236> end
6237
6238Frame 0, PC = 0020DC64, SP = 0030BF3C, FP = 0030BF44
6239Frame 1, PC = 0020DC6C, SP = 0030BF38, FP = 0030BF44
6240Frame 2, PC = 0020DC70, SP = 0030BF34, FP = 0030BF44
6241Frame 3, PC = 0020DC74, SP = 0030BF30, FP = 0030BF44
6242Frame 4, PC = 0020DC78, SP = 0030BF2C, FP = 0030BF44
6243Frame 5, PC = 0020DC7C, SP = 0030BF28, FP = 0030BF44
6244Frame 6, PC = 0020DC80, SP = 0030BF24, FP = 0030BF44
6245Frame 7, PC = 0020DC84, SP = 0030BF20, FP = 0030BF44
6246Frame 8, PC = 0020DC88, SP = 0030BF1C, FP = 0030BF44
6247Frame 9, PC = 0020DC8E, SP = 0030BF18, FP = 0030BF44
6248Frame 10, PC = 00203F6C, SP = 0030BE3C, FP = 0030BF14
6249@end smallexample
6250
6251Or, if we want to examine the variable @code{X} at each source line in
6252the buffer:
6253
6254@smallexample
6255(@value{GDBP}) @b{tfind start}
6256(@value{GDBP}) @b{while ($trace_frame != -1)}
6257> printf "Frame %d, X == %d\n", $trace_frame, X
6258> tfind line
6259> end
6260
6261Frame 0, X = 1
6262Frame 7, X = 2
6263Frame 13, X = 255
6264@end smallexample
6265
6266@node tdump
6267@subsection @code{tdump}
6268@kindex tdump
6269@cindex dump all data collected at tracepoint
6270@cindex tracepoint data, display
6271
6272This command takes no arguments. It prints all the data collected at
6273the current trace snapshot.
6274
6275@smallexample
6276(@value{GDBP}) @b{trace 444}
6277(@value{GDBP}) @b{actions}
6278Enter actions for tracepoint #2, one per line:
6279> collect $regs, $locals, $args, gdb_long_test
6280> end
6281
6282(@value{GDBP}) @b{tstart}
6283
6284(@value{GDBP}) @b{tfind line 444}
6285#0 gdb_test (p1=0x11, p2=0x22, p3=0x33, p4=0x44, p5=0x55, p6=0x66)
6286at gdb_test.c:444
6287444 printp( "%s: arguments = 0x%X 0x%X 0x%X 0x%X 0x%X 0x%X\n", )
6288
6289(@value{GDBP}) @b{tdump}
6290Data collected at tracepoint 2, trace frame 1:
6291d0 0xc4aa0085 -995491707
6292d1 0x18 24
6293d2 0x80 128
6294d3 0x33 51
6295d4 0x71aea3d 119204413
6296d5 0x22 34
6297d6 0xe0 224
6298d7 0x380035 3670069
6299a0 0x19e24a 1696330
6300a1 0x3000668 50333288
6301a2 0x100 256
6302a3 0x322000 3284992
6303a4 0x3000698 50333336
6304a5 0x1ad3cc 1758156
6305fp 0x30bf3c 0x30bf3c
6306sp 0x30bf34 0x30bf34
6307ps 0x0 0
6308pc 0x20b2c8 0x20b2c8
6309fpcontrol 0x0 0
6310fpstatus 0x0 0
6311fpiaddr 0x0 0
6312p = 0x20e5b4 "gdb-test"
6313p1 = (void *) 0x11
6314p2 = (void *) 0x22
6315p3 = (void *) 0x33
6316p4 = (void *) 0x44
6317p5 = (void *) 0x55
6318p6 = (void *) 0x66
6319gdb_long_test = 17 '\021'
6320
6321(@value{GDBP})
6322@end smallexample
6323
6324@node save-tracepoints
6325@subsection @code{save-tracepoints @var{filename}}
6326@kindex save-tracepoints
6327@cindex save tracepoints for future sessions
6328
6329This command saves all current tracepoint definitions together with
6330their actions and passcounts, into a file @file{@var{filename}}
6331suitable for use in a later debugging session. To read the saved
6332tracepoint definitions, use the @code{source} command (@pxref{Command
6333Files}).
6334
6335@node Tracepoint Variables
6336@section Convenience Variables for Tracepoints
6337@cindex tracepoint variables
6338@cindex convenience variables for tracepoints
6339
6340@table @code
6341@vindex $trace_frame
6342@item (int) $trace_frame
6343The current trace snapshot (a.k.a.@: @dfn{frame}) number, or -1 if no
6344snapshot is selected.
6345
6346@vindex $tracepoint
6347@item (int) $tracepoint
6348The tracepoint for the current trace snapshot.
6349
6350@vindex $trace_line
6351@item (int) $trace_line
6352The line number for the current trace snapshot.
6353
6354@vindex $trace_file
6355@item (char []) $trace_file
6356The source file for the current trace snapshot.
6357
6358@vindex $trace_func
6359@item (char []) $trace_func
6360The name of the function containing @code{$tracepoint}.
6361@end table
6362
6363Note: @code{$trace_file} is not suitable for use in @code{printf},
6364use @code{output} instead.
6365
6366Here's a simple example of using these convenience variables for
6367stepping through all the trace snapshots and printing some of their
6368data.
6369
6370@smallexample
6371(@value{GDBP}) @b{tfind start}
6372
6373(@value{GDBP}) @b{while $trace_frame != -1}
6374> output $trace_file
6375> printf ", line %d (tracepoint #%d)\n", $trace_line, $tracepoint
6376> tfind
6377> end
6378@end smallexample
6379
df0cd8c5
JB
6380@node Overlays
6381@chapter Debugging Programs That Use Overlays
6382@cindex overlays
6383
6384If your program is too large to fit completely in your target system's
6385memory, you can sometimes use @dfn{overlays} to work around this
6386problem. @value{GDBN} provides some support for debugging programs that
6387use overlays.
6388
6389@menu
6390* How Overlays Work:: A general explanation of overlays.
6391* Overlay Commands:: Managing overlays in @value{GDBN}.
6392* Automatic Overlay Debugging:: @value{GDBN} can find out which overlays are
6393 mapped by asking the inferior.
6394* Overlay Sample Program:: A sample program using overlays.
6395@end menu
6396
6397@node How Overlays Work
6398@section How Overlays Work
6399@cindex mapped overlays
6400@cindex unmapped overlays
6401@cindex load address, overlay's
6402@cindex mapped address
6403@cindex overlay area
6404
6405Suppose you have a computer whose instruction address space is only 64
6406kilobytes long, but which has much more memory which can be accessed by
6407other means: special instructions, segment registers, or memory
6408management hardware, for example. Suppose further that you want to
6409adapt a program which is larger than 64 kilobytes to run on this system.
6410
6411One solution is to identify modules of your program which are relatively
6412independent, and need not call each other directly; call these modules
6413@dfn{overlays}. Separate the overlays from the main program, and place
6414their machine code in the larger memory. Place your main program in
6415instruction memory, but leave at least enough space there to hold the
6416largest overlay as well.
6417
6418Now, to call a function located in an overlay, you must first copy that
6419overlay's machine code from the large memory into the space set aside
6420for it in the instruction memory, and then jump to its entry point
6421there.
6422
6423@example
6424@group
6425 Data Instruction Larger
6426Address Space Address Space Address Space
6427+-----------+ +-----------+ +-----------+
6428| | | | | |
6429+-----------+ +-----------+ +-----------+<-- overlay 1
6430| program | | main | | | load address
6431| variables | | program | | overlay 1 |
6432| and heap | | | ,---| |
6433+-----------+ | | | | |
6434| | +-----------+ | +-----------+
6435+-----------+ | | | | |
6436 mapped --->+-----------+ / +-----------+<-- overlay 2
6437 address | overlay | <-' | overlay 2 | load address
6438 | area | <-----| |
6439 | | <---. +-----------+
6440 | | | | |
6441 +-----------+ | | |
6442 | | | +-----------+<-- overlay 3
6443 +-----------+ `--| | load address
6444 | overlay 3 |
6445 | |
6446 +-----------+
6447 | |
6448 +-----------+
6449
6450 To map an overlay, copy its code from the larger address space
6451 to the instruction address space. Since the overlays shown here
6452 all use the same mapped address, only one may be mapped at a time.
6453@end group
6454@end example
6455
6456This diagram shows a system with separate data and instruction address
6457spaces. For a system with a single address space for data and
6458instructions, the diagram would be similar, except that the program
6459variables and heap would share an address space with the main program
6460and the overlay area.
6461
6462An overlay loaded into instruction memory and ready for use is called a
6463@dfn{mapped} overlay; its @dfn{mapped address} is its address in the
6464instruction memory. An overlay not present (or only partially present)
6465in instruction memory is called @dfn{unmapped}; its @dfn{load address}
6466is its address in the larger memory. The mapped address is also called
6467the @dfn{virtual memory address}, or @dfn{VMA}; the load address is also
6468called the @dfn{load memory address}, or @dfn{LMA}.
6469
6470Unfortunately, overlays are not a completely transparent way to adapt a
6471program to limited instruction memory. They introduce a new set of
6472global constraints you must keep in mind as you design your program:
6473
6474@itemize @bullet
6475
6476@item
6477Before calling or returning to a function in an overlay, your program
6478must make sure that overlay is actually mapped. Otherwise, the call or
6479return will transfer control to the right address, but in the wrong
6480overlay, and your program will probably crash.
6481
6482@item
6483If the process of mapping an overlay is expensive on your system, you
6484will need to choose your overlays carefully to minimize their effect on
6485your program's performance.
6486
6487@item
6488The executable file you load onto your system must contain each
6489overlay's instructions, appearing at the overlay's load address, not its
6490mapped address. However, each overlay's instructions must be relocated
6491and its symbols defined as if the overlay were at its mapped address.
6492You can use GNU linker scripts to specify different load and relocation
6493addresses for pieces of your program; see @ref{Overlay Description,,,
6494ld.info, Using ld: the GNU linker}.
6495
6496@item
6497The procedure for loading executable files onto your system must be able
6498to load their contents into the larger address space as well as the
6499instruction and data spaces.
6500
6501@end itemize
6502
6503The overlay system described above is rather simple, and could be
6504improved in many ways:
6505
6506@itemize @bullet
6507
6508@item
6509If your system has suitable bank switch registers or memory management
6510hardware, you could use those facilities to make an overlay's load area
6511contents simply appear at their mapped address in instruction space.
6512This would probably be faster than copying the overlay to its mapped
6513area in the usual way.
6514
6515@item
6516If your overlays are small enough, you could set aside more than one
6517overlay area, and have more than one overlay mapped at a time.
6518
6519@item
6520You can use overlays to manage data, as well as instructions. In
6521general, data overlays are even less transparent to your design than
6522code overlays: whereas code overlays only require care when you call or
6523return to functions, data overlays require care every time you access
6524the data. Also, if you change the contents of a data overlay, you
6525must copy its contents back out to its load address before you can copy a
6526different data overlay into the same mapped area.
6527
6528@end itemize
6529
6530
6531@node Overlay Commands
6532@section Overlay Commands
6533
6534To use @value{GDBN}'s overlay support, each overlay in your program must
6535correspond to a separate section of the executable file. The section's
6536virtual memory address and load memory address must be the overlay's
6537mapped and load addresses. Identifying overlays with sections allows
6538@value{GDBN} to determine the appropriate address of a function or
6539variable, depending on whether the overlay is mapped or not.
6540
6541@value{GDBN}'s overlay commands all start with the word @code{overlay};
6542you can abbreviate this as @code{ov} or @code{ovly}. The commands are:
6543
6544@table @code
6545@item overlay off
6546@kindex overlay off
6547Disable @value{GDBN}'s overlay support. When overlay support is
6548disabled, @value{GDBN} assumes that all functions and variables are
6549always present at their mapped addresses. By default, @value{GDBN}'s
6550overlay support is disabled.
6551
6552@item overlay manual
6553@kindex overlay manual
6554@cindex manual overlay debugging
6555Enable @dfn{manual} overlay debugging. In this mode, @value{GDBN}
6556relies on you to tell it which overlays are mapped, and which are not,
6557using the @code{overlay map-overlay} and @code{overlay unmap-overlay}
6558commands described below.
6559
6560@item overlay map-overlay @var{overlay}
6561@itemx overlay map @var{overlay}
6562@kindex overlay map-overlay
6563@cindex map an overlay
6564Tell @value{GDBN} that @var{overlay} is now mapped; @var{overlay} must
6565be the name of the object file section containing the overlay. When an
6566overlay is mapped, @value{GDBN} assumes it can find the overlay's
6567functions and variables at their mapped addresses. @value{GDBN} assumes
6568that any other overlays whose mapped ranges overlap that of
6569@var{overlay} are now unmapped.
6570
6571@item overlay unmap-overlay @var{overlay}
6572@itemx overlay unmap @var{overlay}
6573@kindex overlay unmap-overlay
6574@cindex unmap an overlay
6575Tell @value{GDBN} that @var{overlay} is no longer mapped; @var{overlay}
6576must be the name of the object file section containing the overlay.
6577When an overlay is unmapped, @value{GDBN} assumes it can find the
6578overlay's functions and variables at their load addresses.
6579
6580@item overlay auto
6581@kindex overlay auto
6582Enable @dfn{automatic} overlay debugging. In this mode, @value{GDBN}
6583consults a data structure the overlay manager maintains in the inferior
6584to see which overlays are mapped. For details, see @ref{Automatic
6585Overlay Debugging}.
6586
6587@item overlay load-target
6588@itemx overlay load
6589@kindex overlay load-target
6590@cindex reloading the overlay table
6591Re-read the overlay table from the inferior. Normally, @value{GDBN}
6592re-reads the table @value{GDBN} automatically each time the inferior
6593stops, so this command should only be necessary if you have changed the
6594overlay mapping yourself using @value{GDBN}. This command is only
6595useful when using automatic overlay debugging.
6596
6597@item overlay list-overlays
6598@itemx overlay list
6599@cindex listing mapped overlays
6600Display a list of the overlays currently mapped, along with their mapped
6601addresses, load addresses, and sizes.
6602
6603@end table
6604
6605Normally, when @value{GDBN} prints a code address, it includes the name
6606of the function the address falls in:
6607
6608@example
6609(gdb) print main
6610$3 = @{int ()@} 0x11a0 <main>
6611@end example
6612@noindent
6613When overlay debugging is enabled, @value{GDBN} recognizes code in
6614unmapped overlays, and prints the names of unmapped functions with
6615asterisks around them. For example, if @code{foo} is a function in an
6616unmapped overlay, @value{GDBN} prints it this way:
6617
6618@example
6619(gdb) overlay list
6620No sections are mapped.
6621(gdb) print foo
6622$5 = @{int (int)@} 0x100000 <*foo*>
6623@end example
6624@noindent
6625When @code{foo}'s overlay is mapped, @value{GDBN} prints the function's
6626name normally:
6627
6628@example
6629(gdb) overlay list
6630Section .ov.foo.text, loaded at 0x100000 - 0x100034,
6631 mapped at 0x1016 - 0x104a
6632(gdb) print foo
6633$6 = @{int (int)@} 0x1016 <foo>
6634@end example
6635
6636When overlay debugging is enabled, @value{GDBN} can find the correct
6637address for functions and variables in an overlay, whether or not the
6638overlay is mapped. This allows most @value{GDBN} commands, like
6639@code{break} and @code{disassemble}, to work normally, even on unmapped
6640code. However, @value{GDBN}'s breakpoint support has some limitations:
6641
6642@itemize @bullet
6643@item
6644@cindex breakpoints in overlays
6645@cindex overlays, setting breakpoints in
6646You can set breakpoints in functions in unmapped overlays, as long as
6647@value{GDBN} can write to the overlay at its load address.
6648@item
6649@value{GDBN} can not set hardware or simulator-based breakpoints in
6650unmapped overlays. However, if you set a breakpoint at the end of your
6651overlay manager (and tell @value{GDBN} which overlays are now mapped, if
6652you are using manual overlay management), @value{GDBN} will re-set its
6653breakpoints properly.
6654@end itemize
6655
6656
6657@node Automatic Overlay Debugging
6658@section Automatic Overlay Debugging
6659@cindex automatic overlay debugging
6660
6661@value{GDBN} can automatically track which overlays are mapped and which
6662are not, given some simple co-operation from the overlay manager in the
6663inferior. If you enable automatic overlay debugging with the
6664@code{overlay auto} command (@pxref{Overlay Commands}), @value{GDBN}
6665looks in the inferior's memory for certain variables describing the
6666current state of the overlays.
6667
6668Here are the variables your overlay manager must define to support
6669@value{GDBN}'s automatic overlay debugging:
6670
6671@table @asis
6672
6673@item @code{_ovly_table}:
6674This variable must be an array of the following structures:
6675
6676@example
6677struct
6678@{
6679 /* The overlay's mapped address. */
6680 unsigned long vma;
6681
6682 /* The size of the overlay, in bytes. */
6683 unsigned long size;
6684
6685 /* The overlay's load address. */
6686 unsigned long lma;
6687
6688 /* Non-zero if the overlay is currently mapped;
6689 zero otherwise. */
6690 unsigned long mapped;
6691@}
6692@end example
6693
6694@item @code{_novlys}:
6695This variable must be a four-byte signed integer, holding the total
6696number of elements in @code{_ovly_table}.
6697
6698@end table
6699
6700To decide whether a particular overlay is mapped or not, @value{GDBN}
6701looks for an entry in @w{@code{_ovly_table}} whose @code{vma} and
6702@code{lma} members equal the VMA and LMA of the overlay's section in the
6703executable file. When @value{GDBN} finds a matching entry, it consults
6704the entry's @code{mapped} member to determine whether the overlay is
6705currently mapped.
6706
6707
6708@node Overlay Sample Program
6709@section Overlay Sample Program
6710@cindex overlay example program
6711
6712When linking a program which uses overlays, you must place the overlays
6713at their load addresses, while relocating them to run at their mapped
6714addresses. To do this, you must write a linker script (@pxref{Overlay
6715Description,,, ld.info, Using ld: the GNU linker}). Unfortunately,
6716since linker scripts are specific to a particular host system, target
6717architecture, and target memory layout, this manual cannot provide
6718portable sample code demonstrating @value{GDBN}'s overlay support.
6719
6720However, the @value{GDBN} source distribution does contain an overlaid
6721program, with linker scripts for a few systems, as part of its test
6722suite. The program consists of the following files from
6723@file{gdb/testsuite/gdb.base}:
6724
6725@table @file
6726@item overlays.c
6727The main program file.
6728@item ovlymgr.c
6729A simple overlay manager, used by @file{overlays.c}.
6730@item foo.c
6731@itemx bar.c
6732@itemx baz.c
6733@itemx grbx.c
6734Overlay modules, loaded and used by @file{overlays.c}.
6735@item d10v.ld
6736@itemx m32r.ld
6737Linker scripts for linking the test program on the @code{d10v-elf}
6738and @code{m32r-elf} targets.
6739@end table
6740
6741You can build the test program using the @code{d10v-elf} GCC
6742cross-compiler like this:
6743
6744@example
6745$ d10v-elf-gcc -g -c overlays.c
6746$ d10v-elf-gcc -g -c ovlymgr.c
6747$ d10v-elf-gcc -g -c foo.c
6748$ d10v-elf-gcc -g -c bar.c
6749$ d10v-elf-gcc -g -c baz.c
6750$ d10v-elf-gcc -g -c grbx.c
6751$ d10v-elf-gcc -g overlays.o ovlymgr.o foo.o bar.o \
6752 baz.o grbx.o -Wl,-Td10v.ld -o overlays
6753@end example
6754
6755The build process is identical for any other architecture, except that
6756you must substitute the appropriate compiler and linker script for the
6757target system for @code{d10v-elf-gcc} and @code{d10v.ld}.
6758
6759
6d2ebf8b 6760@node Languages
c906108c
SS
6761@chapter Using @value{GDBN} with Different Languages
6762@cindex languages
6763
c906108c
SS
6764Although programming languages generally have common aspects, they are
6765rarely expressed in the same manner. For instance, in ANSI C,
6766dereferencing a pointer @code{p} is accomplished by @code{*p}, but in
6767Modula-2, it is accomplished by @code{p^}. Values can also be
5d161b24 6768represented (and displayed) differently. Hex numbers in C appear as
c906108c 6769@samp{0x1ae}, while in Modula-2 they appear as @samp{1AEH}.
c906108c
SS
6770
6771@cindex working language
6772Language-specific information is built into @value{GDBN} for some languages,
6773allowing you to express operations like the above in your program's
6774native language, and allowing @value{GDBN} to output values in a manner
6775consistent with the syntax of your program's native language. The
6776language you use to build expressions is called the @dfn{working
6777language}.
6778
6779@menu
6780* Setting:: Switching between source languages
6781* Show:: Displaying the language
c906108c 6782* Checks:: Type and range checks
c906108c
SS
6783* Support:: Supported languages
6784@end menu
6785
6d2ebf8b 6786@node Setting
c906108c
SS
6787@section Switching between source languages
6788
6789There are two ways to control the working language---either have @value{GDBN}
6790set it automatically, or select it manually yourself. You can use the
6791@code{set language} command for either purpose. On startup, @value{GDBN}
6792defaults to setting the language automatically. The working language is
6793used to determine how expressions you type are interpreted, how values
6794are printed, etc.
6795
6796In addition to the working language, every source file that
6797@value{GDBN} knows about has its own working language. For some object
6798file formats, the compiler might indicate which language a particular
6799source file is in. However, most of the time @value{GDBN} infers the
6800language from the name of the file. The language of a source file
b37052ae 6801controls whether C@t{++} names are demangled---this way @code{backtrace} can
c906108c 6802show each frame appropriately for its own language. There is no way to
d4f3574e
SS
6803set the language of a source file from within @value{GDBN}, but you can
6804set the language associated with a filename extension. @xref{Show, ,
6805Displaying the language}.
c906108c
SS
6806
6807This is most commonly a problem when you use a program, such
5d161b24 6808as @code{cfront} or @code{f2c}, that generates C but is written in
c906108c
SS
6809another language. In that case, make the
6810program use @code{#line} directives in its C output; that way
6811@value{GDBN} will know the correct language of the source code of the original
6812program, and will display that source code, not the generated C code.
6813
6814@menu
6815* Filenames:: Filename extensions and languages.
6816* Manually:: Setting the working language manually
6817* Automatically:: Having @value{GDBN} infer the source language
6818@end menu
6819
6d2ebf8b 6820@node Filenames
c906108c
SS
6821@subsection List of filename extensions and languages
6822
6823If a source file name ends in one of the following extensions, then
6824@value{GDBN} infers that its language is the one indicated.
6825
6826@table @file
6827
6828@item .c
6829C source file
6830
6831@item .C
6832@itemx .cc
6833@itemx .cp
6834@itemx .cpp
6835@itemx .cxx
6836@itemx .c++
b37052ae 6837C@t{++} source file
c906108c
SS
6838
6839@item .f
6840@itemx .F
6841Fortran source file
6842
c906108c
SS
6843@item .ch
6844@itemx .c186
6845@itemx .c286
96a2c332 6846CHILL source file
c906108c 6847
c906108c
SS
6848@item .mod
6849Modula-2 source file
c906108c
SS
6850
6851@item .s
6852@itemx .S
6853Assembler source file. This actually behaves almost like C, but
6854@value{GDBN} does not skip over function prologues when stepping.
6855@end table
6856
6857In addition, you may set the language associated with a filename
6858extension. @xref{Show, , Displaying the language}.
6859
6d2ebf8b 6860@node Manually
c906108c
SS
6861@subsection Setting the working language
6862
6863If you allow @value{GDBN} to set the language automatically,
6864expressions are interpreted the same way in your debugging session and
6865your program.
6866
6867@kindex set language
6868If you wish, you may set the language manually. To do this, issue the
6869command @samp{set language @var{lang}}, where @var{lang} is the name of
5d161b24 6870a language, such as
c906108c 6871@code{c} or @code{modula-2}.
c906108c
SS
6872For a list of the supported languages, type @samp{set language}.
6873
c906108c
SS
6874Setting the language manually prevents @value{GDBN} from updating the working
6875language automatically. This can lead to confusion if you try
6876to debug a program when the working language is not the same as the
6877source language, when an expression is acceptable to both
6878languages---but means different things. For instance, if the current
6879source file were written in C, and @value{GDBN} was parsing Modula-2, a
6880command such as:
6881
6882@example
6883print a = b + c
6884@end example
6885
6886@noindent
6887might not have the effect you intended. In C, this means to add
6888@code{b} and @code{c} and place the result in @code{a}. The result
6889printed would be the value of @code{a}. In Modula-2, this means to compare
6890@code{a} to the result of @code{b+c}, yielding a @code{BOOLEAN} value.
c906108c 6891
6d2ebf8b 6892@node Automatically
c906108c
SS
6893@subsection Having @value{GDBN} infer the source language
6894
6895To have @value{GDBN} set the working language automatically, use
6896@samp{set language local} or @samp{set language auto}. @value{GDBN}
6897then infers the working language. That is, when your program stops in a
6898frame (usually by encountering a breakpoint), @value{GDBN} sets the
6899working language to the language recorded for the function in that
6900frame. If the language for a frame is unknown (that is, if the function
6901or block corresponding to the frame was defined in a source file that
6902does not have a recognized extension), the current working language is
6903not changed, and @value{GDBN} issues a warning.
6904
6905This may not seem necessary for most programs, which are written
6906entirely in one source language. However, program modules and libraries
6907written in one source language can be used by a main program written in
6908a different source language. Using @samp{set language auto} in this
6909case frees you from having to set the working language manually.
6910
6d2ebf8b 6911@node Show
c906108c 6912@section Displaying the language
c906108c
SS
6913
6914The following commands help you find out which language is the
6915working language, and also what language source files were written in.
6916
6917@kindex show language
d4f3574e
SS
6918@kindex info frame@r{, show the source language}
6919@kindex info source@r{, show the source language}
c906108c
SS
6920@table @code
6921@item show language
6922Display the current working language. This is the
6923language you can use with commands such as @code{print} to
6924build and compute expressions that may involve variables in your program.
6925
6926@item info frame
5d161b24 6927Display the source language for this frame. This language becomes the
c906108c 6928working language if you use an identifier from this frame.
5d161b24 6929@xref{Frame Info, ,Information about a frame}, to identify the other
c906108c
SS
6930information listed here.
6931
6932@item info source
6933Display the source language of this source file.
5d161b24 6934@xref{Symbols, ,Examining the Symbol Table}, to identify the other
c906108c
SS
6935information listed here.
6936@end table
6937
6938In unusual circumstances, you may have source files with extensions
6939not in the standard list. You can then set the extension associated
6940with a language explicitly:
6941
6942@kindex set extension-language
6943@kindex info extensions
6944@table @code
6945@item set extension-language @var{.ext} @var{language}
6946Set source files with extension @var{.ext} to be assumed to be in
6947the source language @var{language}.
6948
6949@item info extensions
6950List all the filename extensions and the associated languages.
6951@end table
6952
6d2ebf8b 6953@node Checks
c906108c
SS
6954@section Type and range checking
6955
6956@quotation
6957@emph{Warning:} In this release, the @value{GDBN} commands for type and range
6958checking are included, but they do not yet have any effect. This
6959section documents the intended facilities.
6960@end quotation
6961@c FIXME remove warning when type/range code added
6962
6963Some languages are designed to guard you against making seemingly common
6964errors through a series of compile- and run-time checks. These include
6965checking the type of arguments to functions and operators, and making
6966sure mathematical overflows are caught at run time. Checks such as
6967these help to ensure a program's correctness once it has been compiled
6968by eliminating type mismatches, and providing active checks for range
6969errors when your program is running.
6970
6971@value{GDBN} can check for conditions like the above if you wish.
6972Although @value{GDBN} does not check the statements in your program, it
6973can check expressions entered directly into @value{GDBN} for evaluation via
6974the @code{print} command, for example. As with the working language,
6975@value{GDBN} can also decide whether or not to check automatically based on
6976your program's source language. @xref{Support, ,Supported languages},
6977for the default settings of supported languages.
6978
6979@menu
6980* Type Checking:: An overview of type checking
6981* Range Checking:: An overview of range checking
6982@end menu
6983
6984@cindex type checking
6985@cindex checks, type
6d2ebf8b 6986@node Type Checking
c906108c
SS
6987@subsection An overview of type checking
6988
6989Some languages, such as Modula-2, are strongly typed, meaning that the
6990arguments to operators and functions have to be of the correct type,
6991otherwise an error occurs. These checks prevent type mismatch
6992errors from ever causing any run-time problems. For example,
6993
6994@smallexample
69951 + 2 @result{} 3
6996@exdent but
6997@error{} 1 + 2.3
6998@end smallexample
6999
7000The second example fails because the @code{CARDINAL} 1 is not
7001type-compatible with the @code{REAL} 2.3.
7002
5d161b24
DB
7003For the expressions you use in @value{GDBN} commands, you can tell the
7004@value{GDBN} type checker to skip checking;
7005to treat any mismatches as errors and abandon the expression;
7006or to only issue warnings when type mismatches occur,
c906108c
SS
7007but evaluate the expression anyway. When you choose the last of
7008these, @value{GDBN} evaluates expressions like the second example above, but
7009also issues a warning.
7010
5d161b24
DB
7011Even if you turn type checking off, there may be other reasons
7012related to type that prevent @value{GDBN} from evaluating an expression.
7013For instance, @value{GDBN} does not know how to add an @code{int} and
7014a @code{struct foo}. These particular type errors have nothing to do
7015with the language in use, and usually arise from expressions, such as
c906108c
SS
7016the one described above, which make little sense to evaluate anyway.
7017
7018Each language defines to what degree it is strict about type. For
7019instance, both Modula-2 and C require the arguments to arithmetical
7020operators to be numbers. In C, enumerated types and pointers can be
7021represented as numbers, so that they are valid arguments to mathematical
7022operators. @xref{Support, ,Supported languages}, for further
7023details on specific languages.
7024
7025@value{GDBN} provides some additional commands for controlling the type checker:
7026
d4f3574e 7027@kindex set check@r{, type}
c906108c
SS
7028@kindex set check type
7029@kindex show check type
7030@table @code
7031@item set check type auto
7032Set type checking on or off based on the current working language.
7033@xref{Support, ,Supported languages}, for the default settings for
7034each language.
7035
7036@item set check type on
7037@itemx set check type off
7038Set type checking on or off, overriding the default setting for the
7039current working language. Issue a warning if the setting does not
7040match the language default. If any type mismatches occur in
d4f3574e 7041evaluating an expression while type checking is on, @value{GDBN} prints a
c906108c
SS
7042message and aborts evaluation of the expression.
7043
7044@item set check type warn
7045Cause the type checker to issue warnings, but to always attempt to
7046evaluate the expression. Evaluating the expression may still
7047be impossible for other reasons. For example, @value{GDBN} cannot add
7048numbers and structures.
7049
7050@item show type
5d161b24 7051Show the current setting of the type checker, and whether or not @value{GDBN}
c906108c
SS
7052is setting it automatically.
7053@end table
7054
7055@cindex range checking
7056@cindex checks, range
6d2ebf8b 7057@node Range Checking
c906108c
SS
7058@subsection An overview of range checking
7059
7060In some languages (such as Modula-2), it is an error to exceed the
7061bounds of a type; this is enforced with run-time checks. Such range
7062checking is meant to ensure program correctness by making sure
7063computations do not overflow, or indices on an array element access do
7064not exceed the bounds of the array.
7065
7066For expressions you use in @value{GDBN} commands, you can tell
7067@value{GDBN} to treat range errors in one of three ways: ignore them,
7068always treat them as errors and abandon the expression, or issue
7069warnings but evaluate the expression anyway.
7070
7071A range error can result from numerical overflow, from exceeding an
7072array index bound, or when you type a constant that is not a member
7073of any type. Some languages, however, do not treat overflows as an
7074error. In many implementations of C, mathematical overflow causes the
7075result to ``wrap around'' to lower values---for example, if @var{m} is
7076the largest integer value, and @var{s} is the smallest, then
7077
7078@example
7079@var{m} + 1 @result{} @var{s}
7080@end example
7081
7082This, too, is specific to individual languages, and in some cases
7083specific to individual compilers or machines. @xref{Support, ,
7084Supported languages}, for further details on specific languages.
7085
7086@value{GDBN} provides some additional commands for controlling the range checker:
7087
d4f3574e 7088@kindex set check@r{, range}
c906108c
SS
7089@kindex set check range
7090@kindex show check range
7091@table @code
7092@item set check range auto
7093Set range checking on or off based on the current working language.
7094@xref{Support, ,Supported languages}, for the default settings for
7095each language.
7096
7097@item set check range on
7098@itemx set check range off
7099Set range checking on or off, overriding the default setting for the
7100current working language. A warning is issued if the setting does not
c3f6f71d
JM
7101match the language default. If a range error occurs and range checking is on,
7102then a message is printed and evaluation of the expression is aborted.
c906108c
SS
7103
7104@item set check range warn
7105Output messages when the @value{GDBN} range checker detects a range error,
7106but attempt to evaluate the expression anyway. Evaluating the
7107expression may still be impossible for other reasons, such as accessing
7108memory that the process does not own (a typical example from many Unix
7109systems).
7110
7111@item show range
7112Show the current setting of the range checker, and whether or not it is
7113being set automatically by @value{GDBN}.
7114@end table
c906108c 7115
6d2ebf8b 7116@node Support
c906108c 7117@section Supported languages
c906108c 7118
b37052ae 7119@value{GDBN} supports C, C@t{++}, Fortran, Java, Chill, assembly, and Modula-2.
cce74817 7120@c This is false ...
c906108c
SS
7121Some @value{GDBN} features may be used in expressions regardless of the
7122language you use: the @value{GDBN} @code{@@} and @code{::} operators,
7123and the @samp{@{type@}addr} construct (@pxref{Expressions,
7124,Expressions}) can be used with the constructs of any supported
7125language.
7126
7127The following sections detail to what degree each source language is
7128supported by @value{GDBN}. These sections are not meant to be language
7129tutorials or references, but serve only as a reference guide to what the
7130@value{GDBN} expression parser accepts, and what input and output
7131formats should look like for different languages. There are many good
7132books written on each of these languages; please look to these for a
7133language reference or tutorial.
7134
c906108c 7135@menu
b37052ae 7136* C:: C and C@t{++}
cce74817 7137* Modula-2:: Modula-2
104c1213 7138* Chill:: Chill
c906108c
SS
7139@end menu
7140
6d2ebf8b 7141@node C
b37052ae 7142@subsection C and C@t{++}
7a292a7a 7143
b37052ae
EZ
7144@cindex C and C@t{++}
7145@cindex expressions in C or C@t{++}
c906108c 7146
b37052ae 7147Since C and C@t{++} are so closely related, many features of @value{GDBN} apply
c906108c
SS
7148to both languages. Whenever this is the case, we discuss those languages
7149together.
7150
41afff9a
EZ
7151@cindex C@t{++}
7152@cindex @code{g++}, @sc{gnu} C@t{++} compiler
b37052ae
EZ
7153@cindex @sc{gnu} C@t{++}
7154The C@t{++} debugging facilities are jointly implemented by the C@t{++}
7155compiler and @value{GDBN}. Therefore, to debug your C@t{++} code
7156effectively, you must compile your C@t{++} programs with a supported
7157C@t{++} compiler, such as @sc{gnu} @code{g++}, or the HP ANSI C@t{++}
c906108c
SS
7158compiler (@code{aCC}).
7159
b37052ae 7160For best results when using @sc{gnu} C@t{++}, use the stabs debugging
c906108c
SS
7161format. You can select that format explicitly with the @code{g++}
7162command-line options @samp{-gstabs} or @samp{-gstabs+}. See
7163@ref{Debugging Options,,Options for Debugging Your Program or @sc{gnu}
7164CC, gcc.info, Using @sc{gnu} CC}, for more information.
c906108c 7165
c906108c 7166@menu
b37052ae
EZ
7167* C Operators:: C and C@t{++} operators
7168* C Constants:: C and C@t{++} constants
7169* C plus plus expressions:: C@t{++} expressions
7170* C Defaults:: Default settings for C and C@t{++}
7171* C Checks:: C and C@t{++} type and range checks
c906108c 7172* Debugging C:: @value{GDBN} and C
b37052ae 7173* Debugging C plus plus:: @value{GDBN} features for C@t{++}
c906108c 7174@end menu
c906108c 7175
6d2ebf8b 7176@node C Operators
b37052ae 7177@subsubsection C and C@t{++} operators
7a292a7a 7178
b37052ae 7179@cindex C and C@t{++} operators
c906108c
SS
7180
7181Operators must be defined on values of specific types. For instance,
7182@code{+} is defined on numbers, but not on structures. Operators are
5d161b24 7183often defined on groups of types.
c906108c 7184
b37052ae 7185For the purposes of C and C@t{++}, the following definitions hold:
c906108c
SS
7186
7187@itemize @bullet
53a5351d 7188
c906108c 7189@item
c906108c 7190@emph{Integral types} include @code{int} with any of its storage-class
b37052ae 7191specifiers; @code{char}; @code{enum}; and, for C@t{++}, @code{bool}.
c906108c
SS
7192
7193@item
d4f3574e
SS
7194@emph{Floating-point types} include @code{float}, @code{double}, and
7195@code{long double} (if supported by the target platform).
c906108c
SS
7196
7197@item
53a5351d 7198@emph{Pointer types} include all types defined as @code{(@var{type} *)}.
c906108c
SS
7199
7200@item
7201@emph{Scalar types} include all of the above.
53a5351d 7202
c906108c
SS
7203@end itemize
7204
7205@noindent
7206The following operators are supported. They are listed here
7207in order of increasing precedence:
7208
7209@table @code
7210@item ,
7211The comma or sequencing operator. Expressions in a comma-separated list
7212are evaluated from left to right, with the result of the entire
7213expression being the last expression evaluated.
7214
7215@item =
7216Assignment. The value of an assignment expression is the value
7217assigned. Defined on scalar types.
7218
7219@item @var{op}=
7220Used in an expression of the form @w{@code{@var{a} @var{op}= @var{b}}},
7221and translated to @w{@code{@var{a} = @var{a op b}}}.
d4f3574e 7222@w{@code{@var{op}=}} and @code{=} have the same precedence.
c906108c
SS
7223@var{op} is any one of the operators @code{|}, @code{^}, @code{&},
7224@code{<<}, @code{>>}, @code{+}, @code{-}, @code{*}, @code{/}, @code{%}.
7225
7226@item ?:
7227The ternary operator. @code{@var{a} ? @var{b} : @var{c}} can be thought
7228of as: if @var{a} then @var{b} else @var{c}. @var{a} should be of an
7229integral type.
7230
7231@item ||
7232Logical @sc{or}. Defined on integral types.
7233
7234@item &&
7235Logical @sc{and}. Defined on integral types.
7236
7237@item |
7238Bitwise @sc{or}. Defined on integral types.
7239
7240@item ^
7241Bitwise exclusive-@sc{or}. Defined on integral types.
7242
7243@item &
7244Bitwise @sc{and}. Defined on integral types.
7245
7246@item ==@r{, }!=
7247Equality and inequality. Defined on scalar types. The value of these
7248expressions is 0 for false and non-zero for true.
7249
7250@item <@r{, }>@r{, }<=@r{, }>=
7251Less than, greater than, less than or equal, greater than or equal.
7252Defined on scalar types. The value of these expressions is 0 for false
7253and non-zero for true.
7254
7255@item <<@r{, }>>
7256left shift, and right shift. Defined on integral types.
7257
7258@item @@
7259The @value{GDBN} ``artificial array'' operator (@pxref{Expressions, ,Expressions}).
7260
7261@item +@r{, }-
7262Addition and subtraction. Defined on integral types, floating-point types and
7263pointer types.
7264
7265@item *@r{, }/@r{, }%
7266Multiplication, division, and modulus. Multiplication and division are
7267defined on integral and floating-point types. Modulus is defined on
7268integral types.
7269
7270@item ++@r{, }--
7271Increment and decrement. When appearing before a variable, the
7272operation is performed before the variable is used in an expression;
7273when appearing after it, the variable's value is used before the
7274operation takes place.
7275
7276@item *
7277Pointer dereferencing. Defined on pointer types. Same precedence as
7278@code{++}.
7279
7280@item &
7281Address operator. Defined on variables. Same precedence as @code{++}.
7282
b37052ae
EZ
7283For debugging C@t{++}, @value{GDBN} implements a use of @samp{&} beyond what is
7284allowed in the C@t{++} language itself: you can use @samp{&(&@var{ref})}
c906108c 7285(or, if you prefer, simply @samp{&&@var{ref}}) to examine the address
b37052ae 7286where a C@t{++} reference variable (declared with @samp{&@var{ref}}) is
c906108c 7287stored.
c906108c
SS
7288
7289@item -
7290Negative. Defined on integral and floating-point types. Same
7291precedence as @code{++}.
7292
7293@item !
7294Logical negation. Defined on integral types. Same precedence as
7295@code{++}.
7296
7297@item ~
7298Bitwise complement operator. Defined on integral types. Same precedence as
7299@code{++}.
7300
7301
7302@item .@r{, }->
7303Structure member, and pointer-to-structure member. For convenience,
7304@value{GDBN} regards the two as equivalent, choosing whether to dereference a
7305pointer based on the stored type information.
7306Defined on @code{struct} and @code{union} data.
7307
c906108c
SS
7308@item .*@r{, }->*
7309Dereferences of pointers to members.
c906108c
SS
7310
7311@item []
7312Array indexing. @code{@var{a}[@var{i}]} is defined as
7313@code{*(@var{a}+@var{i})}. Same precedence as @code{->}.
7314
7315@item ()
7316Function parameter list. Same precedence as @code{->}.
7317
c906108c 7318@item ::
b37052ae 7319C@t{++} scope resolution operator. Defined on @code{struct}, @code{union},
7a292a7a 7320and @code{class} types.
c906108c
SS
7321
7322@item ::
7a292a7a
SS
7323Doubled colons also represent the @value{GDBN} scope operator
7324(@pxref{Expressions, ,Expressions}). Same precedence as @code{::},
7325above.
c906108c
SS
7326@end table
7327
c906108c
SS
7328If an operator is redefined in the user code, @value{GDBN} usually
7329attempts to invoke the redefined version instead of using the operator's
7330predefined meaning.
c906108c 7331
c906108c 7332@menu
5d161b24 7333* C Constants::
c906108c
SS
7334@end menu
7335
6d2ebf8b 7336@node C Constants
b37052ae 7337@subsubsection C and C@t{++} constants
c906108c 7338
b37052ae 7339@cindex C and C@t{++} constants
c906108c 7340
b37052ae 7341@value{GDBN} allows you to express the constants of C and C@t{++} in the
c906108c 7342following ways:
c906108c
SS
7343
7344@itemize @bullet
7345@item
7346Integer constants are a sequence of digits. Octal constants are
7347specified by a leading @samp{0} (i.e. zero), and hexadecimal constants by
7348a leading @samp{0x} or @samp{0X}. Constants may also end with a letter
7349@samp{l}, specifying that the constant should be treated as a
7350@code{long} value.
7351
7352@item
7353Floating point constants are a sequence of digits, followed by a decimal
7354point, followed by a sequence of digits, and optionally followed by an
7355exponent. An exponent is of the form:
7356@samp{@w{e@r{[[}+@r{]|}-@r{]}@var{nnn}}}, where @var{nnn} is another
7357sequence of digits. The @samp{+} is optional for positive exponents.
d4f3574e
SS
7358A floating-point constant may also end with a letter @samp{f} or
7359@samp{F}, specifying that the constant should be treated as being of
7360the @code{float} (as opposed to the default @code{double}) type; or with
7361a letter @samp{l} or @samp{L}, which specifies a @code{long double}
7362constant.
c906108c
SS
7363
7364@item
7365Enumerated constants consist of enumerated identifiers, or their
7366integral equivalents.
7367
7368@item
7369Character constants are a single character surrounded by single quotes
7370(@code{'}), or a number---the ordinal value of the corresponding character
d4f3574e 7371(usually its @sc{ascii} value). Within quotes, the single character may
c906108c
SS
7372be represented by a letter or by @dfn{escape sequences}, which are of
7373the form @samp{\@var{nnn}}, where @var{nnn} is the octal representation
7374of the character's ordinal value; or of the form @samp{\@var{x}}, where
7375@samp{@var{x}} is a predefined special character---for example,
7376@samp{\n} for newline.
7377
7378@item
96a2c332
SS
7379String constants are a sequence of character constants surrounded by
7380double quotes (@code{"}). Any valid character constant (as described
7381above) may appear. Double quotes within the string must be preceded by
7382a backslash, so for instance @samp{"a\"b'c"} is a string of five
7383characters.
c906108c
SS
7384
7385@item
7386Pointer constants are an integral value. You can also write pointers
7387to constants using the C operator @samp{&}.
7388
7389@item
7390Array constants are comma-separated lists surrounded by braces @samp{@{}
7391and @samp{@}}; for example, @samp{@{1,2,3@}} is a three-element array of
7392integers, @samp{@{@{1,2@}, @{3,4@}, @{5,6@}@}} is a three-by-two array,
7393and @samp{@{&"hi", &"there", &"fred"@}} is a three-element array of pointers.
7394@end itemize
7395
c906108c 7396@menu
5d161b24
DB
7397* C plus plus expressions::
7398* C Defaults::
7399* C Checks::
c906108c 7400
5d161b24 7401* Debugging C::
c906108c
SS
7402@end menu
7403
6d2ebf8b 7404@node C plus plus expressions
b37052ae
EZ
7405@subsubsection C@t{++} expressions
7406
7407@cindex expressions in C@t{++}
7408@value{GDBN} expression handling can interpret most C@t{++} expressions.
7409
7410@cindex C@t{++} support, not in @sc{coff}
7411@cindex @sc{coff} versus C@t{++}
7412@cindex C@t{++} and object formats
7413@cindex object formats and C@t{++}
7414@cindex a.out and C@t{++}
7415@cindex @sc{ecoff} and C@t{++}
7416@cindex @sc{xcoff} and C@t{++}
7417@cindex @sc{elf}/stabs and C@t{++}
7418@cindex @sc{elf}/@sc{dwarf} and C@t{++}
c906108c
SS
7419@c FIXME!! GDB may eventually be able to debug C++ using DWARF; check
7420@c periodically whether this has happened...
7421@quotation
b37052ae
EZ
7422@emph{Warning:} @value{GDBN} can only debug C@t{++} code if you use the
7423proper compiler. Typically, C@t{++} debugging depends on the use of
c906108c
SS
7424additional debugging information in the symbol table, and thus requires
7425special support. In particular, if your compiler generates a.out, MIPS
7426@sc{ecoff}, RS/6000 @sc{xcoff}, or @sc{elf} with stabs extensions to the
7427symbol table, these facilities are all available. (With @sc{gnu} CC,
7428you can use the @samp{-gstabs} option to request stabs debugging
7429extensions explicitly.) Where the object code format is standard
b37052ae 7430@sc{coff} or @sc{dwarf} in @sc{elf}, on the other hand, most of the C@t{++}
c906108c
SS
7431support in @value{GDBN} does @emph{not} work.
7432@end quotation
c906108c
SS
7433
7434@enumerate
7435
7436@cindex member functions
7437@item
7438Member function calls are allowed; you can use expressions like
7439
7440@example
7441count = aml->GetOriginal(x, y)
7442@end example
7443
41afff9a 7444@vindex this@r{, inside C@t{++} member functions}
b37052ae 7445@cindex namespace in C@t{++}
c906108c
SS
7446@item
7447While a member function is active (in the selected stack frame), your
7448expressions have the same namespace available as the member function;
7449that is, @value{GDBN} allows implicit references to the class instance
b37052ae 7450pointer @code{this} following the same rules as C@t{++}.
c906108c 7451
c906108c 7452@cindex call overloaded functions
d4f3574e 7453@cindex overloaded functions, calling
b37052ae 7454@cindex type conversions in C@t{++}
c906108c
SS
7455@item
7456You can call overloaded functions; @value{GDBN} resolves the function
d4f3574e 7457call to the right definition, with some restrictions. @value{GDBN} does not
c906108c
SS
7458perform overload resolution involving user-defined type conversions,
7459calls to constructors, or instantiations of templates that do not exist
7460in the program. It also cannot handle ellipsis argument lists or
7461default arguments.
7462
7463It does perform integral conversions and promotions, floating-point
7464promotions, arithmetic conversions, pointer conversions, conversions of
7465class objects to base classes, and standard conversions such as those of
7466functions or arrays to pointers; it requires an exact match on the
7467number of function arguments.
7468
7469Overload resolution is always performed, unless you have specified
7470@code{set overload-resolution off}. @xref{Debugging C plus plus,
b37052ae 7471,@value{GDBN} features for C@t{++}}.
c906108c 7472
d4f3574e 7473You must specify @code{set overload-resolution off} in order to use an
c906108c
SS
7474explicit function signature to call an overloaded function, as in
7475@smallexample
7476p 'foo(char,int)'('x', 13)
7477@end smallexample
d4f3574e 7478
c906108c 7479The @value{GDBN} command-completion facility can simplify this;
d4f3574e 7480see @ref{Completion, ,Command completion}.
c906108c 7481
c906108c
SS
7482@cindex reference declarations
7483@item
b37052ae
EZ
7484@value{GDBN} understands variables declared as C@t{++} references; you can use
7485them in expressions just as you do in C@t{++} source---they are automatically
c906108c
SS
7486dereferenced.
7487
7488In the parameter list shown when @value{GDBN} displays a frame, the values of
7489reference variables are not displayed (unlike other variables); this
7490avoids clutter, since references are often used for large structures.
7491The @emph{address} of a reference variable is always shown, unless
7492you have specified @samp{set print address off}.
7493
7494@item
b37052ae 7495@value{GDBN} supports the C@t{++} name resolution operator @code{::}---your
c906108c
SS
7496expressions can use it just as expressions in your program do. Since
7497one scope may be defined in another, you can use @code{::} repeatedly if
7498necessary, for example in an expression like
7499@samp{@var{scope1}::@var{scope2}::@var{name}}. @value{GDBN} also allows
b37052ae 7500resolving name scope by reference to source files, in both C and C@t{++}
c906108c
SS
7501debugging (@pxref{Variables, ,Program variables}).
7502@end enumerate
7503
b37052ae 7504In addition, when used with HP's C@t{++} compiler, @value{GDBN} supports
53a5351d
JM
7505calling virtual functions correctly, printing out virtual bases of
7506objects, calling functions in a base subobject, casting objects, and
7507invoking user-defined operators.
c906108c 7508
6d2ebf8b 7509@node C Defaults
b37052ae 7510@subsubsection C and C@t{++} defaults
7a292a7a 7511
b37052ae 7512@cindex C and C@t{++} defaults
c906108c 7513
c906108c
SS
7514If you allow @value{GDBN} to set type and range checking automatically, they
7515both default to @code{off} whenever the working language changes to
b37052ae 7516C or C@t{++}. This happens regardless of whether you or @value{GDBN}
c906108c 7517selects the working language.
c906108c
SS
7518
7519If you allow @value{GDBN} to set the language automatically, it
7520recognizes source files whose names end with @file{.c}, @file{.C}, or
7521@file{.cc}, etc, and when @value{GDBN} enters code compiled from one of
b37052ae 7522these files, it sets the working language to C or C@t{++}.
c906108c
SS
7523@xref{Automatically, ,Having @value{GDBN} infer the source language},
7524for further details.
7525
c906108c
SS
7526@c Type checking is (a) primarily motivated by Modula-2, and (b)
7527@c unimplemented. If (b) changes, it might make sense to let this node
7528@c appear even if Mod-2 does not, but meanwhile ignore it. roland 16jul93.
7a292a7a 7529
6d2ebf8b 7530@node C Checks
b37052ae 7531@subsubsection C and C@t{++} type and range checks
7a292a7a 7532
b37052ae 7533@cindex C and C@t{++} checks
c906108c 7534
b37052ae 7535By default, when @value{GDBN} parses C or C@t{++} expressions, type checking
c906108c
SS
7536is not used. However, if you turn type checking on, @value{GDBN}
7537considers two variables type equivalent if:
7538
7539@itemize @bullet
7540@item
7541The two variables are structured and have the same structure, union, or
7542enumerated tag.
7543
7544@item
7545The two variables have the same type name, or types that have been
7546declared equivalent through @code{typedef}.
7547
7548@ignore
7549@c leaving this out because neither J Gilmore nor R Pesch understand it.
7550@c FIXME--beers?
7551@item
7552The two @code{struct}, @code{union}, or @code{enum} variables are
7553declared in the same declaration. (Note: this may not be true for all C
7554compilers.)
7555@end ignore
7556@end itemize
7557
7558Range checking, if turned on, is done on mathematical operations. Array
7559indices are not checked, since they are often used to index a pointer
7560that is not itself an array.
c906108c 7561
6d2ebf8b 7562@node Debugging C
c906108c 7563@subsubsection @value{GDBN} and C
c906108c
SS
7564
7565The @code{set print union} and @code{show print union} commands apply to
7566the @code{union} type. When set to @samp{on}, any @code{union} that is
7a292a7a
SS
7567inside a @code{struct} or @code{class} is also printed. Otherwise, it
7568appears as @samp{@{...@}}.
c906108c
SS
7569
7570The @code{@@} operator aids in the debugging of dynamic arrays, formed
7571with pointers and a memory allocation function. @xref{Expressions,
7572,Expressions}.
7573
c906108c 7574@menu
5d161b24 7575* Debugging C plus plus::
c906108c
SS
7576@end menu
7577
6d2ebf8b 7578@node Debugging C plus plus
b37052ae 7579@subsubsection @value{GDBN} features for C@t{++}
c906108c 7580
b37052ae 7581@cindex commands for C@t{++}
7a292a7a 7582
b37052ae
EZ
7583Some @value{GDBN} commands are particularly useful with C@t{++}, and some are
7584designed specifically for use with C@t{++}. Here is a summary:
c906108c
SS
7585
7586@table @code
7587@cindex break in overloaded functions
7588@item @r{breakpoint menus}
7589When you want a breakpoint in a function whose name is overloaded,
7590@value{GDBN} breakpoint menus help you specify which function definition
7591you want. @xref{Breakpoint Menus,,Breakpoint menus}.
7592
b37052ae 7593@cindex overloading in C@t{++}
c906108c
SS
7594@item rbreak @var{regex}
7595Setting breakpoints using regular expressions is helpful for setting
7596breakpoints on overloaded functions that are not members of any special
7597classes.
7598@xref{Set Breaks, ,Setting breakpoints}.
7599
b37052ae 7600@cindex C@t{++} exception handling
c906108c
SS
7601@item catch throw
7602@itemx catch catch
b37052ae 7603Debug C@t{++} exception handling using these commands. @xref{Set
c906108c
SS
7604Catchpoints, , Setting catchpoints}.
7605
7606@cindex inheritance
7607@item ptype @var{typename}
7608Print inheritance relationships as well as other information for type
7609@var{typename}.
7610@xref{Symbols, ,Examining the Symbol Table}.
7611
b37052ae 7612@cindex C@t{++} symbol display
c906108c
SS
7613@item set print demangle
7614@itemx show print demangle
7615@itemx set print asm-demangle
7616@itemx show print asm-demangle
b37052ae
EZ
7617Control whether C@t{++} symbols display in their source form, both when
7618displaying code as C@t{++} source and when displaying disassemblies.
c906108c
SS
7619@xref{Print Settings, ,Print settings}.
7620
7621@item set print object
7622@itemx show print object
7623Choose whether to print derived (actual) or declared types of objects.
7624@xref{Print Settings, ,Print settings}.
7625
7626@item set print vtbl
7627@itemx show print vtbl
7628Control the format for printing virtual function tables.
7629@xref{Print Settings, ,Print settings}.
c906108c 7630(The @code{vtbl} commands do not work on programs compiled with the HP
b37052ae 7631ANSI C@t{++} compiler (@code{aCC}).)
c906108c
SS
7632
7633@kindex set overload-resolution
d4f3574e 7634@cindex overloaded functions, overload resolution
c906108c 7635@item set overload-resolution on
b37052ae 7636Enable overload resolution for C@t{++} expression evaluation. The default
c906108c
SS
7637is on. For overloaded functions, @value{GDBN} evaluates the arguments
7638and searches for a function whose signature matches the argument types,
b37052ae 7639using the standard C@t{++} conversion rules (see @ref{C plus plus expressions, ,C@t{++}
d4f3574e 7640expressions}, for details). If it cannot find a match, it emits a
c906108c
SS
7641message.
7642
7643@item set overload-resolution off
b37052ae 7644Disable overload resolution for C@t{++} expression evaluation. For
c906108c
SS
7645overloaded functions that are not class member functions, @value{GDBN}
7646chooses the first function of the specified name that it finds in the
7647symbol table, whether or not its arguments are of the correct type. For
7648overloaded functions that are class member functions, @value{GDBN}
7649searches for a function whose signature @emph{exactly} matches the
7650argument types.
c906108c
SS
7651
7652@item @r{Overloaded symbol names}
7653You can specify a particular definition of an overloaded symbol, using
b37052ae 7654the same notation that is used to declare such symbols in C@t{++}: type
c906108c
SS
7655@code{@var{symbol}(@var{types})} rather than just @var{symbol}. You can
7656also use the @value{GDBN} command-line word completion facilities to list the
7657available choices, or to finish the type list for you.
7658@xref{Completion,, Command completion}, for details on how to do this.
7659@end table
c906108c 7660
6d2ebf8b 7661@node Modula-2
c906108c 7662@subsection Modula-2
7a292a7a 7663
d4f3574e 7664@cindex Modula-2, @value{GDBN} support
c906108c
SS
7665
7666The extensions made to @value{GDBN} to support Modula-2 only support
7667output from the @sc{gnu} Modula-2 compiler (which is currently being
7668developed). Other Modula-2 compilers are not currently supported, and
7669attempting to debug executables produced by them is most likely
7670to give an error as @value{GDBN} reads in the executable's symbol
7671table.
7672
7673@cindex expressions in Modula-2
7674@menu
7675* M2 Operators:: Built-in operators
7676* Built-In Func/Proc:: Built-in functions and procedures
7677* M2 Constants:: Modula-2 constants
7678* M2 Defaults:: Default settings for Modula-2
7679* Deviations:: Deviations from standard Modula-2
7680* M2 Checks:: Modula-2 type and range checks
7681* M2 Scope:: The scope operators @code{::} and @code{.}
7682* GDB/M2:: @value{GDBN} and Modula-2
7683@end menu
7684
6d2ebf8b 7685@node M2 Operators
c906108c
SS
7686@subsubsection Operators
7687@cindex Modula-2 operators
7688
7689Operators must be defined on values of specific types. For instance,
7690@code{+} is defined on numbers, but not on structures. Operators are
7691often defined on groups of types. For the purposes of Modula-2, the
7692following definitions hold:
7693
7694@itemize @bullet
7695
7696@item
7697@emph{Integral types} consist of @code{INTEGER}, @code{CARDINAL}, and
7698their subranges.
7699
7700@item
7701@emph{Character types} consist of @code{CHAR} and its subranges.
7702
7703@item
7704@emph{Floating-point types} consist of @code{REAL}.
7705
7706@item
7707@emph{Pointer types} consist of anything declared as @code{POINTER TO
7708@var{type}}.
7709
7710@item
7711@emph{Scalar types} consist of all of the above.
7712
7713@item
7714@emph{Set types} consist of @code{SET} and @code{BITSET} types.
7715
7716@item
7717@emph{Boolean types} consist of @code{BOOLEAN}.
7718@end itemize
7719
7720@noindent
7721The following operators are supported, and appear in order of
7722increasing precedence:
7723
7724@table @code
7725@item ,
7726Function argument or array index separator.
7727
7728@item :=
7729Assignment. The value of @var{var} @code{:=} @var{value} is
7730@var{value}.
7731
7732@item <@r{, }>
7733Less than, greater than on integral, floating-point, or enumerated
7734types.
7735
7736@item <=@r{, }>=
96a2c332 7737Less than or equal to, greater than or equal to
c906108c
SS
7738on integral, floating-point and enumerated types, or set inclusion on
7739set types. Same precedence as @code{<}.
7740
7741@item =@r{, }<>@r{, }#
7742Equality and two ways of expressing inequality, valid on scalar types.
7743Same precedence as @code{<}. In @value{GDBN} scripts, only @code{<>} is
7744available for inequality, since @code{#} conflicts with the script
7745comment character.
7746
7747@item IN
7748Set membership. Defined on set types and the types of their members.
7749Same precedence as @code{<}.
7750
7751@item OR
7752Boolean disjunction. Defined on boolean types.
7753
7754@item AND@r{, }&
d4f3574e 7755Boolean conjunction. Defined on boolean types.
c906108c
SS
7756
7757@item @@
7758The @value{GDBN} ``artificial array'' operator (@pxref{Expressions, ,Expressions}).
7759
7760@item +@r{, }-
7761Addition and subtraction on integral and floating-point types, or union
7762and difference on set types.
7763
7764@item *
7765Multiplication on integral and floating-point types, or set intersection
7766on set types.
7767
7768@item /
7769Division on floating-point types, or symmetric set difference on set
7770types. Same precedence as @code{*}.
7771
7772@item DIV@r{, }MOD
7773Integer division and remainder. Defined on integral types. Same
7774precedence as @code{*}.
7775
7776@item -
7777Negative. Defined on @code{INTEGER} and @code{REAL} data.
7778
7779@item ^
7780Pointer dereferencing. Defined on pointer types.
7781
7782@item NOT
7783Boolean negation. Defined on boolean types. Same precedence as
7784@code{^}.
7785
7786@item .
7787@code{RECORD} field selector. Defined on @code{RECORD} data. Same
7788precedence as @code{^}.
7789
7790@item []
7791Array indexing. Defined on @code{ARRAY} data. Same precedence as @code{^}.
7792
7793@item ()
7794Procedure argument list. Defined on @code{PROCEDURE} objects. Same precedence
7795as @code{^}.
7796
7797@item ::@r{, }.
7798@value{GDBN} and Modula-2 scope operators.
7799@end table
7800
7801@quotation
7802@emph{Warning:} Sets and their operations are not yet supported, so @value{GDBN}
7803treats the use of the operator @code{IN}, or the use of operators
7804@code{+}, @code{-}, @code{*}, @code{/}, @code{=}, , @code{<>}, @code{#},
7805@code{<=}, and @code{>=} on sets as an error.
7806@end quotation
7807
cb51c4e0 7808
6d2ebf8b 7809@node Built-In Func/Proc
c906108c 7810@subsubsection Built-in functions and procedures
cb51c4e0 7811@cindex Modula-2 built-ins
c906108c
SS
7812
7813Modula-2 also makes available several built-in procedures and functions.
7814In describing these, the following metavariables are used:
7815
7816@table @var
7817
7818@item a
7819represents an @code{ARRAY} variable.
7820
7821@item c
7822represents a @code{CHAR} constant or variable.
7823
7824@item i
7825represents a variable or constant of integral type.
7826
7827@item m
7828represents an identifier that belongs to a set. Generally used in the
7829same function with the metavariable @var{s}. The type of @var{s} should
7830be @code{SET OF @var{mtype}} (where @var{mtype} is the type of @var{m}).
7831
7832@item n
7833represents a variable or constant of integral or floating-point type.
7834
7835@item r
7836represents a variable or constant of floating-point type.
7837
7838@item t
7839represents a type.
7840
7841@item v
7842represents a variable.
7843
7844@item x
7845represents a variable or constant of one of many types. See the
7846explanation of the function for details.
7847@end table
7848
7849All Modula-2 built-in procedures also return a result, described below.
7850
7851@table @code
7852@item ABS(@var{n})
7853Returns the absolute value of @var{n}.
7854
7855@item CAP(@var{c})
7856If @var{c} is a lower case letter, it returns its upper case
c3f6f71d 7857equivalent, otherwise it returns its argument.
c906108c
SS
7858
7859@item CHR(@var{i})
7860Returns the character whose ordinal value is @var{i}.
7861
7862@item DEC(@var{v})
c3f6f71d 7863Decrements the value in the variable @var{v} by one. Returns the new value.
c906108c
SS
7864
7865@item DEC(@var{v},@var{i})
7866Decrements the value in the variable @var{v} by @var{i}. Returns the
7867new value.
7868
7869@item EXCL(@var{m},@var{s})
7870Removes the element @var{m} from the set @var{s}. Returns the new
7871set.
7872
7873@item FLOAT(@var{i})
7874Returns the floating point equivalent of the integer @var{i}.
7875
7876@item HIGH(@var{a})
7877Returns the index of the last member of @var{a}.
7878
7879@item INC(@var{v})
c3f6f71d 7880Increments the value in the variable @var{v} by one. Returns the new value.
c906108c
SS
7881
7882@item INC(@var{v},@var{i})
7883Increments the value in the variable @var{v} by @var{i}. Returns the
7884new value.
7885
7886@item INCL(@var{m},@var{s})
7887Adds the element @var{m} to the set @var{s} if it is not already
7888there. Returns the new set.
7889
7890@item MAX(@var{t})
7891Returns the maximum value of the type @var{t}.
7892
7893@item MIN(@var{t})
7894Returns the minimum value of the type @var{t}.
7895
7896@item ODD(@var{i})
7897Returns boolean TRUE if @var{i} is an odd number.
7898
7899@item ORD(@var{x})
7900Returns the ordinal value of its argument. For example, the ordinal
c3f6f71d
JM
7901value of a character is its @sc{ascii} value (on machines supporting the
7902@sc{ascii} character set). @var{x} must be of an ordered type, which include
c906108c
SS
7903integral, character and enumerated types.
7904
7905@item SIZE(@var{x})
7906Returns the size of its argument. @var{x} can be a variable or a type.
7907
7908@item TRUNC(@var{r})
7909Returns the integral part of @var{r}.
7910
7911@item VAL(@var{t},@var{i})
7912Returns the member of the type @var{t} whose ordinal value is @var{i}.
7913@end table
7914
7915@quotation
7916@emph{Warning:} Sets and their operations are not yet supported, so
7917@value{GDBN} treats the use of procedures @code{INCL} and @code{EXCL} as
7918an error.
7919@end quotation
7920
7921@cindex Modula-2 constants
6d2ebf8b 7922@node M2 Constants
c906108c
SS
7923@subsubsection Constants
7924
7925@value{GDBN} allows you to express the constants of Modula-2 in the following
7926ways:
7927
7928@itemize @bullet
7929
7930@item
7931Integer constants are simply a sequence of digits. When used in an
7932expression, a constant is interpreted to be type-compatible with the
7933rest of the expression. Hexadecimal integers are specified by a
7934trailing @samp{H}, and octal integers by a trailing @samp{B}.
7935
7936@item
7937Floating point constants appear as a sequence of digits, followed by a
7938decimal point and another sequence of digits. An optional exponent can
7939then be specified, in the form @samp{E@r{[}+@r{|}-@r{]}@var{nnn}}, where
7940@samp{@r{[}+@r{|}-@r{]}@var{nnn}} is the desired exponent. All of the
7941digits of the floating point constant must be valid decimal (base 10)
7942digits.
7943
7944@item
7945Character constants consist of a single character enclosed by a pair of
7946like quotes, either single (@code{'}) or double (@code{"}). They may
c3f6f71d 7947also be expressed by their ordinal value (their @sc{ascii} value, usually)
c906108c
SS
7948followed by a @samp{C}.
7949
7950@item
7951String constants consist of a sequence of characters enclosed by a
7952pair of like quotes, either single (@code{'}) or double (@code{"}).
7953Escape sequences in the style of C are also allowed. @xref{C
b37052ae 7954Constants, ,C and C@t{++} constants}, for a brief explanation of escape
c906108c
SS
7955sequences.
7956
7957@item
7958Enumerated constants consist of an enumerated identifier.
7959
7960@item
7961Boolean constants consist of the identifiers @code{TRUE} and
7962@code{FALSE}.
7963
7964@item
7965Pointer constants consist of integral values only.
7966
7967@item
7968Set constants are not yet supported.
7969@end itemize
7970
6d2ebf8b 7971@node M2 Defaults
c906108c
SS
7972@subsubsection Modula-2 defaults
7973@cindex Modula-2 defaults
7974
7975If type and range checking are set automatically by @value{GDBN}, they
7976both default to @code{on} whenever the working language changes to
d4f3574e 7977Modula-2. This happens regardless of whether you or @value{GDBN}
c906108c
SS
7978selected the working language.
7979
7980If you allow @value{GDBN} to set the language automatically, then entering
7981code compiled from a file whose name ends with @file{.mod} sets the
d4f3574e 7982working language to Modula-2. @xref{Automatically, ,Having @value{GDBN} set
c906108c
SS
7983the language automatically}, for further details.
7984
6d2ebf8b 7985@node Deviations
c906108c
SS
7986@subsubsection Deviations from standard Modula-2
7987@cindex Modula-2, deviations from
7988
7989A few changes have been made to make Modula-2 programs easier to debug.
7990This is done primarily via loosening its type strictness:
7991
7992@itemize @bullet
7993@item
7994Unlike in standard Modula-2, pointer constants can be formed by
7995integers. This allows you to modify pointer variables during
7996debugging. (In standard Modula-2, the actual address contained in a
7997pointer variable is hidden from you; it can only be modified
7998through direct assignment to another pointer variable or expression that
7999returned a pointer.)
8000
8001@item
8002C escape sequences can be used in strings and characters to represent
8003non-printable characters. @value{GDBN} prints out strings with these
8004escape sequences embedded. Single non-printable characters are
8005printed using the @samp{CHR(@var{nnn})} format.
8006
8007@item
8008The assignment operator (@code{:=}) returns the value of its right-hand
8009argument.
8010
8011@item
8012All built-in procedures both modify @emph{and} return their argument.
8013@end itemize
8014
6d2ebf8b 8015@node M2 Checks
c906108c
SS
8016@subsubsection Modula-2 type and range checks
8017@cindex Modula-2 checks
8018
8019@quotation
8020@emph{Warning:} in this release, @value{GDBN} does not yet perform type or
8021range checking.
8022@end quotation
8023@c FIXME remove warning when type/range checks added
8024
8025@value{GDBN} considers two Modula-2 variables type equivalent if:
8026
8027@itemize @bullet
8028@item
8029They are of types that have been declared equivalent via a @code{TYPE
8030@var{t1} = @var{t2}} statement
8031
8032@item
8033They have been declared on the same line. (Note: This is true of the
8034@sc{gnu} Modula-2 compiler, but it may not be true of other compilers.)
8035@end itemize
8036
8037As long as type checking is enabled, any attempt to combine variables
8038whose types are not equivalent is an error.
8039
8040Range checking is done on all mathematical operations, assignment, array
8041index bounds, and all built-in functions and procedures.
8042
6d2ebf8b 8043@node M2 Scope
c906108c
SS
8044@subsubsection The scope operators @code{::} and @code{.}
8045@cindex scope
41afff9a 8046@cindex @code{.}, Modula-2 scope operator
c906108c
SS
8047@cindex colon, doubled as scope operator
8048@ifinfo
41afff9a 8049@vindex colon-colon@r{, in Modula-2}
c906108c
SS
8050@c Info cannot handle :: but TeX can.
8051@end ifinfo
8052@iftex
41afff9a 8053@vindex ::@r{, in Modula-2}
c906108c
SS
8054@end iftex
8055
8056There are a few subtle differences between the Modula-2 scope operator
8057(@code{.}) and the @value{GDBN} scope operator (@code{::}). The two have
8058similar syntax:
8059
8060@example
8061
8062@var{module} . @var{id}
8063@var{scope} :: @var{id}
8064@end example
8065
8066@noindent
8067where @var{scope} is the name of a module or a procedure,
8068@var{module} the name of a module, and @var{id} is any declared
8069identifier within your program, except another module.
8070
8071Using the @code{::} operator makes @value{GDBN} search the scope
8072specified by @var{scope} for the identifier @var{id}. If it is not
8073found in the specified scope, then @value{GDBN} searches all scopes
8074enclosing the one specified by @var{scope}.
8075
8076Using the @code{.} operator makes @value{GDBN} search the current scope for
8077the identifier specified by @var{id} that was imported from the
8078definition module specified by @var{module}. With this operator, it is
8079an error if the identifier @var{id} was not imported from definition
8080module @var{module}, or if @var{id} is not an identifier in
8081@var{module}.
8082
6d2ebf8b 8083@node GDB/M2
c906108c
SS
8084@subsubsection @value{GDBN} and Modula-2
8085
8086Some @value{GDBN} commands have little use when debugging Modula-2 programs.
8087Five subcommands of @code{set print} and @code{show print} apply
b37052ae 8088specifically to C and C@t{++}: @samp{vtbl}, @samp{demangle},
c906108c 8089@samp{asm-demangle}, @samp{object}, and @samp{union}. The first four
b37052ae 8090apply to C@t{++}, and the last to the C @code{union} type, which has no direct
c906108c
SS
8091analogue in Modula-2.
8092
8093The @code{@@} operator (@pxref{Expressions, ,Expressions}), while available
d4f3574e 8094with any language, is not useful with Modula-2. Its
c906108c 8095intent is to aid the debugging of @dfn{dynamic arrays}, which cannot be
b37052ae 8096created in Modula-2 as they can in C or C@t{++}. However, because an
c906108c 8097address can be specified by an integral constant, the construct
d4f3574e 8098@samp{@{@var{type}@}@var{adrexp}} is still useful.
c906108c
SS
8099
8100@cindex @code{#} in Modula-2
8101In @value{GDBN} scripts, the Modula-2 inequality operator @code{#} is
8102interpreted as the beginning of a comment. Use @code{<>} instead.
c906108c 8103
6d2ebf8b 8104@node Chill
cce74817
JM
8105@subsection Chill
8106
8107The extensions made to @value{GDBN} to support Chill only support output
d4f3574e 8108from the @sc{gnu} Chill compiler. Other Chill compilers are not currently
cce74817
JM
8109supported, and attempting to debug executables produced by them is most
8110likely to give an error as @value{GDBN} reads in the executable's symbol
8111table.
8112
d4f3574e
SS
8113@c This used to say "... following Chill related topics ...", but since
8114@c menus are not shown in the printed manual, it would look awkward.
8115This section covers the Chill related topics and the features
cce74817
JM
8116of @value{GDBN} which support these topics.
8117
8118@menu
104c1213
JM
8119* How modes are displayed:: How modes are displayed
8120* Locations:: Locations and their accesses
cce74817 8121* Values and their Operations:: Values and their Operations
5d161b24 8122* Chill type and range checks::
53a5351d 8123* Chill defaults::
cce74817
JM
8124@end menu
8125
6d2ebf8b 8126@node How modes are displayed
cce74817
JM
8127@subsubsection How modes are displayed
8128
8129The Chill Datatype- (Mode) support of @value{GDBN} is directly related
d4f3574e 8130with the functionality of the @sc{gnu} Chill compiler, and therefore deviates
cce74817
JM
8131slightly from the standard specification of the Chill language. The
8132provided modes are:
d4f3574e
SS
8133
8134@c FIXME: this @table's contents effectively disable @code by using @r
8135@c on every @item. So why does it need @code?
cce74817
JM
8136@table @code
8137@item @r{@emph{Discrete modes:}}
8138@itemize @bullet
8139@item
8140@emph{Integer Modes} which are predefined by @code{BYTE, UBYTE, INT,
8141UINT, LONG, ULONG},
8142@item
5d161b24 8143@emph{Boolean Mode} which is predefined by @code{BOOL},
cce74817 8144@item
5d161b24 8145@emph{Character Mode} which is predefined by @code{CHAR},
cce74817
JM
8146@item
8147@emph{Set Mode} which is displayed by the keyword @code{SET}.
8148@smallexample
8149(@value{GDBP}) ptype x
8150type = SET (karli = 10, susi = 20, fritzi = 100)
8151@end smallexample
8152If the type is an unnumbered set the set element values are omitted.
8153@item
6d2ebf8b
SS
8154@emph{Range Mode} which is displayed by
8155@smallexample
8156@code{type = <basemode>(<lower bound> : <upper bound>)}
8157@end smallexample
8158where @code{<lower bound>, <upper bound>} can be of any discrete literal
8159expression (e.g. set element names).
cce74817
JM
8160@end itemize
8161
8162@item @r{@emph{Powerset Mode:}}
8163A Powerset Mode is displayed by the keyword @code{POWERSET} followed by
d4f3574e 8164the member mode of the powerset. The member mode can be any discrete mode.
cce74817
JM
8165@smallexample
8166(@value{GDBP}) ptype x
8167type = POWERSET SET (egon, hugo, otto)
8168@end smallexample
8169
8170@item @r{@emph{Reference Modes:}}
8171@itemize @bullet
8172@item
d4f3574e 8173@emph{Bound Reference Mode} which is displayed by the keyword @code{REF}
cce74817
JM
8174followed by the mode name to which the reference is bound.
8175@item
8176@emph{Free Reference Mode} which is displayed by the keyword @code{PTR}.
8177@end itemize
8178
8179@item @r{@emph{Procedure mode}}
8180The procedure mode is displayed by @code{type = PROC(<parameter list>)
8181<return mode> EXCEPTIONS (<exception list>)}. The @code{<parameter
d4f3574e
SS
8182list>} is a list of the parameter modes. @code{<return mode>} indicates
8183the mode of the result of the procedure if any. The exceptionlist lists
cce74817
JM
8184all possible exceptions which can be raised by the procedure.
8185
8186@ignore
8187@item @r{@emph{Instance mode}}
8188The instance mode is represented by a structure, which has a static
5d161b24 8189type, and is therefore not really of interest.
cce74817
JM
8190@end ignore
8191
5d161b24 8192@item @r{@emph{Synchronization Modes:}}
cce74817
JM
8193@itemize @bullet
8194@item
6d2ebf8b
SS
8195@emph{Event Mode} which is displayed by
8196@smallexample
8197@code{EVENT (<event length>)}
8198@end smallexample
cce74817
JM
8199where @code{(<event length>)} is optional.
8200@item
6d2ebf8b
SS
8201@emph{Buffer Mode} which is displayed by
8202@smallexample
8203@code{BUFFER (<buffer length>)<buffer element mode>}
8204@end smallexample
8205where @code{(<buffer length>)} is optional.
cce74817
JM
8206@end itemize
8207
5d161b24 8208@item @r{@emph{Timing Modes:}}
cce74817
JM
8209@itemize @bullet
8210@item
8211@emph{Duration Mode} which is predefined by @code{DURATION}
8212@item
8213@emph{Absolute Time Mode} which is predefined by @code{TIME}
8214@end itemize
8215
8216@item @r{@emph{Real Modes:}}
8217Real Modes are predefined with @code{REAL} and @code{LONG_REAL}.
8218
8219@item @r{@emph{String Modes:}}
8220@itemize @bullet
8221@item
6d2ebf8b
SS
8222@emph{Character String Mode} which is displayed by
8223@smallexample
8224@code{CHARS(<string length>)}
8225@end smallexample
8226followed by the keyword @code{VARYING} if the String Mode is a varying
8227mode
cce74817 8228@item
6d2ebf8b
SS
8229@emph{Bit String Mode} which is displayed by
8230@smallexample
8231@code{BOOLS(<string
8232length>)}
8233@end smallexample
cce74817
JM
8234@end itemize
8235
8236@item @r{@emph{Array Mode:}}
8237The Array Mode is displayed by the keyword @code{ARRAY(<range>)}
8238followed by the element mode (which may in turn be an array mode).
8239@smallexample
8240(@value{GDBP}) ptype x
5d161b24
DB
8241type = ARRAY (1:42)
8242 ARRAY (1:20)
cce74817
JM
8243 SET (karli = 10, susi = 20, fritzi = 100)
8244@end smallexample
8245
5d161b24 8246@item @r{@emph{Structure Mode}}
cce74817 8247The Structure mode is displayed by the keyword @code{STRUCT(<field
d4f3574e
SS
8248list>)}. The @code{<field list>} consists of names and modes of fields
8249of the structure. Variant structures have the keyword @code{CASE <field>
8250OF <variant fields> ESAC} in their field list. Since the current version
cce74817
JM
8251of the GNU Chill compiler doesn't implement tag processing (no runtime
8252checks of variant fields, and therefore no debugging info), the output
8253always displays all variant fields.
8254@smallexample
8255(@value{GDBP}) ptype str
8256type = STRUCT (
8257 as x,
8258 bs x,
8259 CASE bs OF
8260 (karli):
8261 cs a
8262 (ott):
8263 ds x
8264 ESAC
8265)
8266@end smallexample
8267@end table
8268
6d2ebf8b 8269@node Locations
cce74817
JM
8270@subsubsection Locations and their accesses
8271
8272A location in Chill is an object which can contain values.
8273
8274A value of a location is generally accessed by the (declared) name of
d4f3574e
SS
8275the location. The output conforms to the specification of values in
8276Chill programs. How values are specified
8277is the topic of the next section, @ref{Values and their Operations}.
cce74817
JM
8278
8279The pseudo-location @code{RESULT} (or @code{result}) can be used to
8280display or change the result of a currently-active procedure:
d4f3574e 8281
cce74817
JM
8282@smallexample
8283set result := EXPR
8284@end smallexample
d4f3574e
SS
8285
8286@noindent
8287This does the same as the Chill action @code{RESULT EXPR} (which
c3f6f71d 8288is not available in @value{GDBN}).
cce74817
JM
8289
8290Values of reference mode locations are printed by @code{PTR(<hex
8291value>)} in case of a free reference mode, and by @code{(REF <reference
d4f3574e 8292mode>) (<hex-value>)} in case of a bound reference. @code{<hex value>}
cce74817
JM
8293represents the address where the reference points to. To access the
8294value of the location referenced by the pointer, use the dereference
d4f3574e 8295operator @samp{->}.
cce74817 8296
6d2ebf8b
SS
8297Values of procedure mode locations are displayed by
8298@smallexample
8299@code{@{ PROC
cce74817 8300(<argument modes> ) <return mode> @} <address> <name of procedure
6d2ebf8b
SS
8301location>}
8302@end smallexample
8303@code{<argument modes>} is a list of modes according to the parameter
8304specification of the procedure and @code{<address>} shows the address of
8305the entry point.
cce74817
JM
8306
8307@ignore
8308Locations of instance modes are displayed just like a structure with two
8309fields specifying the @emph{process type} and the @emph{copy number} of
8310the investigated instance location@footnote{This comes from the current
d4f3574e
SS
8311implementation of instances. They are implemented as a structure (no
8312na). The output should be something like @code{[<name of the process>;
8313<instance number>]}.}. The field names are @code{__proc_type} and
cce74817
JM
8314@code{__proc_copy}.
8315
8316Locations of synchronization modes are displayed like a structure with
8317the field name @code{__event_data} in case of a event mode location, and
8318like a structure with the field @code{__buffer_data} in case of a buffer
8319mode location (refer to previous paragraph).
8320
8321Structure Mode locations are printed by @code{[.<field name>: <value>,
d4f3574e 8322...]}. The @code{<field name>} corresponds to the structure mode
cce74817 8323definition and the layout of @code{<value>} varies depending of the mode
d4f3574e
SS
8324of the field. If the investigated structure mode location is of variant
8325structure mode, the variant parts of the structure are enclosed in curled
8326braces (@samp{@{@}}). Fields enclosed by @samp{@{,@}} are residing
cce74817 8327on the same memory location and represent the current values of the
d4f3574e 8328memory location in their specific modes. Since no tag processing is done
cce74817 8329all variants are displayed. A variant field is printed by
d4f3574e 8330@code{(<variant name>) = .<field name>: <value>}. (who implements the
cce74817
JM
8331stuff ???)
8332@smallexample
8333(@value{GDBP}) print str1 $4 = [.as: 0, .bs: karli, .<TAG>: { (karli) =
8334[.cs: []], (susi) = [.ds: susi]}]
8335@end smallexample
8336@end ignore
8337
8338Substructures of string mode-, array mode- or structure mode-values
8339(e.g. array slices, fields of structure locations) are accessed using
d4f3574e
SS
8340certain operations which are described in the next section, @ref{Values
8341and their Operations}.
cce74817
JM
8342
8343A location value may be interpreted as having a different mode using the
d4f3574e
SS
8344location conversion. This mode conversion is written as @code{<mode
8345name>(<location>)}. The user has to consider that the sizes of the modes
8346have to be equal otherwise an error occurs. Furthermore, no range
8347checking of the location against the destination mode is performed, and
cce74817 8348therefore the result can be quite confusing.
d4f3574e 8349
cce74817
JM
8350@smallexample
8351(@value{GDBP}) print int (s(3 up 4)) XXX TO be filled in !! XXX
8352@end smallexample
8353
6d2ebf8b 8354@node Values and their Operations
cce74817
JM
8355@subsubsection Values and their Operations
8356
8357Values are used to alter locations, to investigate complex structures in
8358more detail or to filter relevant information out of a large amount of
d4f3574e
SS
8359data. There are several (mode dependent) operations defined which enable
8360such investigations. These operations are not only applicable to
cce74817 8361constant values but also to locations, which can become quite useful
d4f3574e 8362when debugging complex structures. During parsing the command line
cce74817
JM
8363(e.g. evaluating an expression) @value{GDBN} treats location names as
8364the values behind these locations.
8365
d4f3574e 8366This section describes how values have to be specified and which
cce74817
JM
8367operations are legal to be used with such values.
8368
8369@table @code
8370@item Literal Values
d4f3574e
SS
8371Literal values are specified in the same manner as in @sc{gnu} Chill programs.
8372For detailed specification refer to the @sc{gnu} Chill implementation Manual
cce74817 8373chapter 1.5.
d4f3574e
SS
8374@c FIXME: if the Chill Manual is a Texinfo documents, the above should
8375@c be converted to a @ref.
cce74817 8376
5d161b24 8377@ignore
cce74817
JM
8378@itemize @bullet
8379@item
8380@emph{Integer Literals} are specified in the same manner as in Chill
d4f3574e 8381programs (refer to the Chill Standard z200/88 chpt 5.2.4.2)
cce74817
JM
8382@item
8383@emph{Boolean Literals} are defined by @code{TRUE} and @code{FALSE}.
8384@item
8385@emph{Character Literals} are defined by @code{'<character>'}. (e.g.
8386@code{'M'})
8387@item
8388@emph{Set Literals} are defined by a name which was specified in a set
d4f3574e 8389mode. The value delivered by a Set Literal is the set value. This is
b37052ae 8390comparable to an enumeration in C/C@t{++} language.
cce74817 8391@item
d4f3574e 8392@emph{Emptiness Literal} is predefined by @code{NULL}. The value of the
cce74817 8393emptiness literal delivers either the empty reference value, the empty
5d161b24 8394procedure value or the empty instance value.
cce74817
JM
8395
8396@item
8397@emph{Character String Literals} are defined by a sequence of characters
d4f3574e 8398enclosed in single- or double quotes. If a single- or double quote has
cce74817
JM
8399to be part of the string literal it has to be stuffed (specified twice).
8400@item
8401@emph{Bitstring Literals} are specified in the same manner as in Chill
8402programs (refer z200/88 chpt 5.2.4.8).
8403@item
8404@emph{Floating point literals} are specified in the same manner as in
d4f3574e 8405(gnu-)Chill programs (refer @sc{gnu} Chill implementation Manual chapter 1.5).
cce74817
JM
8406@end itemize
8407@end ignore
8408
8409@item Tuple Values
8410A tuple is specified by @code{<mode name>[<tuple>]}, where @code{<mode
d4f3574e 8411name>} can be omitted if the mode of the tuple is unambiguous. This
cce74817
JM
8412unambiguity is derived from the context of a evaluated expression.
8413@code{<tuple>} can be one of the following:
d4f3574e 8414
cce74817
JM
8415@itemize @bullet
8416@item @emph{Powerset Tuple}
8417@item @emph{Array Tuple}
8418@item @emph{Structure Tuple}
8419Powerset tuples, array tuples and structure tuples are specified in the
d4f3574e 8420same manner as in Chill programs refer to z200/88 chpt 5.2.5.
cce74817
JM
8421@end itemize
8422
8423@item String Element Value
6d2ebf8b
SS
8424A string element value is specified by
8425@smallexample
8426@code{<string value>(<index>)}
8427@end smallexample
d4f3574e 8428where @code{<index>} is a integer expression. It delivers a character
cce74817
JM
8429value which is equivalent to the character indexed by @code{<index>} in
8430the string.
8431
8432@item String Slice Value
8433A string slice value is specified by @code{<string value>(<slice
8434spec>)}, where @code{<slice spec>} can be either a range of integer
8435expressions or specified by @code{<start expr> up <size>}.
8436@code{<size>} denotes the number of elements which the slice contains.
8437The delivered value is a string value, which is part of the specified
8438string.
8439
8440@item Array Element Values
8441An array element value is specified by @code{<array value>(<expr>)} and
8442delivers a array element value of the mode of the specified array.
8443
8444@item Array Slice Values
8445An array slice is specified by @code{<array value>(<slice spec>)}, where
8446@code{<slice spec>} can be either a range specified by expressions or by
d4f3574e
SS
8447@code{<start expr> up <size>}. @code{<size>} denotes the number of
8448arrayelements the slice contains. The delivered value is an array value
cce74817
JM
8449which is part of the specified array.
8450
8451@item Structure Field Values
8452A structure field value is derived by @code{<structure value>.<field
d4f3574e
SS
8453name>}, where @code{<field name>} indicates the name of a field specified
8454in the mode definition of the structure. The mode of the delivered value
cce74817
JM
8455corresponds to this mode definition in the structure definition.
8456
8457@item Procedure Call Value
8458The procedure call value is derived from the return value of the
8459procedure@footnote{If a procedure call is used for instance in an
8460expression, then this procedure is called with all its side
d4f3574e 8461effects. This can lead to confusing results if used carelessly.}.
cce74817 8462
d4f3574e 8463Values of duration mode locations are represented by @code{ULONG} literals.
cce74817 8464
6d2ebf8b
SS
8465Values of time mode locations appear as
8466@smallexample
8467@code{TIME(<secs>:<nsecs>)}
8468@end smallexample
8469
cce74817
JM
8470
8471@ignore
8472This is not implemented yet:
8473@item Built-in Value
8474@noindent
8475The following built in functions are provided:
d4f3574e 8476
cce74817
JM
8477@table @code
8478@item @code{ADDR()}
8479@item @code{NUM()}
8480@item @code{PRED()}
8481@item @code{SUCC()}
8482@item @code{ABS()}
8483@item @code{CARD()}
8484@item @code{MAX()}
8485@item @code{MIN()}
8486@item @code{SIZE()}
8487@item @code{UPPER()}
8488@item @code{LOWER()}
8489@item @code{LENGTH()}
8490@item @code{SIN()}
8491@item @code{COS()}
8492@item @code{TAN()}
8493@item @code{ARCSIN()}
8494@item @code{ARCCOS()}
8495@item @code{ARCTAN()}
8496@item @code{EXP()}
8497@item @code{LN()}
8498@item @code{LOG()}
8499@item @code{SQRT()}
8500@end table
8501
8502For a detailed description refer to the GNU Chill implementation manual
8503chapter 1.6.
8504@end ignore
8505
8506@item Zero-adic Operator Value
8507The zero-adic operator value is derived from the instance value for the
8508current active process.
8509
8510@item Expression Values
8511The value delivered by an expression is the result of the evaluation of
d4f3574e 8512the specified expression. If there are error conditions (mode
cce74817 8513incompatibility, etc.) the evaluation of expressions is aborted with a
d4f3574e 8514corresponding error message. Expressions may be parenthesised which
cce74817 8515causes the evaluation of this expression before any other expression
d4f3574e 8516which uses the result of the parenthesised expression. The following
cce74817 8517operators are supported by @value{GDBN}:
d4f3574e 8518
cce74817
JM
8519@table @code
8520@item @code{OR, ORIF, XOR}
d4f3574e
SS
8521@itemx @code{AND, ANDIF}
8522@itemx @code{NOT}
cce74817 8523Logical operators defined over operands of boolean mode.
d4f3574e 8524
cce74817
JM
8525@item @code{=, /=}
8526Equality and inequality operators defined over all modes.
d4f3574e 8527
cce74817 8528@item @code{>, >=}
d4f3574e 8529@itemx @code{<, <=}
cce74817 8530Relational operators defined over predefined modes.
d4f3574e 8531
cce74817 8532@item @code{+, -}
d4f3574e 8533@itemx @code{*, /, MOD, REM}
cce74817 8534Arithmetic operators defined over predefined modes.
d4f3574e 8535
cce74817
JM
8536@item @code{-}
8537Change sign operator.
d4f3574e 8538
cce74817
JM
8539@item @code{//}
8540String concatenation operator.
d4f3574e 8541
cce74817
JM
8542@item @code{()}
8543String repetition operator.
d4f3574e 8544
cce74817
JM
8545@item @code{->}
8546Referenced location operator which can be used either to take the
8547address of a location (@code{->loc}), or to dereference a reference
8548location (@code{loc->}).
d4f3574e 8549
cce74817 8550@item @code{OR, XOR}
d4f3574e
SS
8551@itemx @code{AND}
8552@itemx @code{NOT}
cce74817 8553Powerset and bitstring operators.
d4f3574e 8554
cce74817 8555@item @code{>, >=}
d4f3574e 8556@itemx @code{<, <=}
cce74817 8557Powerset inclusion operators.
d4f3574e 8558
cce74817
JM
8559@item @code{IN}
8560Membership operator.
8561@end table
8562@end table
8563
6d2ebf8b 8564@node Chill type and range checks
cce74817
JM
8565@subsubsection Chill type and range checks
8566
8567@value{GDBN} considers two Chill variables mode equivalent if the sizes
d4f3574e 8568of the two modes are equal. This rule applies recursively to more
cce74817 8569complex datatypes which means that complex modes are treated
d4f3574e 8570equivalent if all element modes (which also can be complex modes like
cce74817
JM
8571structures, arrays, etc.) have the same size.
8572
8573Range checking is done on all mathematical operations, assignment, array
8574index bounds and all built in procedures.
8575
8576Strong type checks are forced using the @value{GDBN} command @code{set
d4f3574e 8577check strong}. This enforces strong type and range checks on all
cce74817
JM
8578operations where Chill constructs are used (expressions, built in
8579functions, etc.) in respect to the semantics as defined in the z.200
8580language specification.
8581
cce74817
JM
8582All checks can be disabled by the @value{GDBN} command @code{set check
8583off}.
8584
5d161b24 8585@ignore
53a5351d 8586@c Deviations from the Chill Standard Z200/88
cce74817
JM
8587see last paragraph ?
8588@end ignore
8589
6d2ebf8b 8590@node Chill defaults
cce74817
JM
8591@subsubsection Chill defaults
8592
8593If type and range checking are set automatically by @value{GDBN}, they
8594both default to @code{on} whenever the working language changes to
d4f3574e 8595Chill. This happens regardless of whether you or @value{GDBN}
cce74817
JM
8596selected the working language.
8597
8598If you allow @value{GDBN} to set the language automatically, then entering
8599code compiled from a file whose name ends with @file{.ch} sets the
d4f3574e 8600working language to Chill. @xref{Automatically, ,Having @value{GDBN} set
cce74817
JM
8601the language automatically}, for further details.
8602
6d2ebf8b 8603@node Symbols
c906108c
SS
8604@chapter Examining the Symbol Table
8605
d4f3574e 8606The commands described in this chapter allow you to inquire about the
c906108c
SS
8607symbols (names of variables, functions and types) defined in your
8608program. This information is inherent in the text of your program and
8609does not change as your program executes. @value{GDBN} finds it in your
8610program's symbol table, in the file indicated when you started @value{GDBN}
8611(@pxref{File Options, ,Choosing files}), or by one of the
8612file-management commands (@pxref{Files, ,Commands to specify files}).
8613
8614@cindex symbol names
8615@cindex names of symbols
8616@cindex quoting names
8617Occasionally, you may need to refer to symbols that contain unusual
8618characters, which @value{GDBN} ordinarily treats as word delimiters. The
8619most frequent case is in referring to static variables in other
8620source files (@pxref{Variables,,Program variables}). File names
8621are recorded in object files as debugging symbols, but @value{GDBN} would
8622ordinarily parse a typical file name, like @file{foo.c}, as the three words
8623@samp{foo} @samp{.} @samp{c}. To allow @value{GDBN} to recognize
8624@samp{foo.c} as a single symbol, enclose it in single quotes; for example,
8625
8626@example
8627p 'foo.c'::x
8628@end example
8629
8630@noindent
8631looks up the value of @code{x} in the scope of the file @file{foo.c}.
8632
8633@table @code
8634@kindex info address
b37052ae 8635@cindex address of a symbol
c906108c
SS
8636@item info address @var{symbol}
8637Describe where the data for @var{symbol} is stored. For a register
8638variable, this says which register it is kept in. For a non-register
8639local variable, this prints the stack-frame offset at which the variable
8640is always stored.
8641
8642Note the contrast with @samp{print &@var{symbol}}, which does not work
8643at all for a register variable, and for a stack local variable prints
8644the exact address of the current instantiation of the variable.
8645
3d67e040 8646@kindex info symbol
b37052ae 8647@cindex symbol from address
3d67e040
EZ
8648@item info symbol @var{addr}
8649Print the name of a symbol which is stored at the address @var{addr}.
8650If no symbol is stored exactly at @var{addr}, @value{GDBN} prints the
8651nearest symbol and an offset from it:
8652
8653@example
8654(@value{GDBP}) info symbol 0x54320
8655_initialize_vx + 396 in section .text
8656@end example
8657
8658@noindent
8659This is the opposite of the @code{info address} command. You can use
8660it to find out the name of a variable or a function given its address.
8661
c906108c 8662@kindex whatis
d4f3574e
SS
8663@item whatis @var{expr}
8664Print the data type of expression @var{expr}. @var{expr} is not
c906108c
SS
8665actually evaluated, and any side-effecting operations (such as
8666assignments or function calls) inside it do not take place.
8667@xref{Expressions, ,Expressions}.
8668
8669@item whatis
8670Print the data type of @code{$}, the last value in the value history.
8671
8672@kindex ptype
8673@item ptype @var{typename}
8674Print a description of data type @var{typename}. @var{typename} may be
7a292a7a
SS
8675the name of a type, or for C code it may have the form @samp{class
8676@var{class-name}}, @samp{struct @var{struct-tag}}, @samp{union
8677@var{union-tag}} or @samp{enum @var{enum-tag}}.
c906108c 8678
d4f3574e 8679@item ptype @var{expr}
c906108c 8680@itemx ptype
d4f3574e 8681Print a description of the type of expression @var{expr}. @code{ptype}
c906108c
SS
8682differs from @code{whatis} by printing a detailed description, instead
8683of just the name of the type.
8684
8685For example, for this variable declaration:
8686
8687@example
8688struct complex @{double real; double imag;@} v;
8689@end example
8690
8691@noindent
8692the two commands give this output:
8693
8694@example
8695@group
8696(@value{GDBP}) whatis v
8697type = struct complex
8698(@value{GDBP}) ptype v
8699type = struct complex @{
8700 double real;
8701 double imag;
8702@}
8703@end group
8704@end example
8705
8706@noindent
8707As with @code{whatis}, using @code{ptype} without an argument refers to
8708the type of @code{$}, the last value in the value history.
8709
8710@kindex info types
8711@item info types @var{regexp}
8712@itemx info types
d4f3574e 8713Print a brief description of all types whose names match @var{regexp}
c906108c
SS
8714(or all types in your program, if you supply no argument). Each
8715complete typename is matched as though it were a complete line; thus,
8716@samp{i type value} gives information on all types in your program whose
d4f3574e 8717names include the string @code{value}, but @samp{i type ^value$} gives
c906108c
SS
8718information only on types whose complete name is @code{value}.
8719
8720This command differs from @code{ptype} in two ways: first, like
8721@code{whatis}, it does not print a detailed description; second, it
8722lists all source files where a type is defined.
8723
b37052ae
EZ
8724@kindex info scope
8725@cindex local variables
8726@item info scope @var{addr}
8727List all the variables local to a particular scope. This command
8728accepts a location---a function name, a source line, or an address
8729preceded by a @samp{*}, and prints all the variables local to the
8730scope defined by that location. For example:
8731
8732@smallexample
8733(@value{GDBP}) @b{info scope command_line_handler}
8734Scope for command_line_handler:
8735Symbol rl is an argument at stack/frame offset 8, length 4.
8736Symbol linebuffer is in static storage at address 0x150a18, length 4.
8737Symbol linelength is in static storage at address 0x150a1c, length 4.
8738Symbol p is a local variable in register $esi, length 4.
8739Symbol p1 is a local variable in register $ebx, length 4.
8740Symbol nline is a local variable in register $edx, length 4.
8741Symbol repeat is a local variable at frame offset -8, length 4.
8742@end smallexample
8743
f5c37c66
EZ
8744@noindent
8745This command is especially useful for determining what data to collect
8746during a @dfn{trace experiment}, see @ref{Tracepoint Actions,
8747collect}.
8748
c906108c
SS
8749@kindex info source
8750@item info source
8751Show the name of the current source file---that is, the source file for
8752the function containing the current point of execution---and the language
8753it was written in.
8754
8755@kindex info sources
8756@item info sources
8757Print the names of all source files in your program for which there is
8758debugging information, organized into two lists: files whose symbols
8759have already been read, and files whose symbols will be read when needed.
8760
8761@kindex info functions
8762@item info functions
8763Print the names and data types of all defined functions.
8764
8765@item info functions @var{regexp}
8766Print the names and data types of all defined functions
8767whose names contain a match for regular expression @var{regexp}.
8768Thus, @samp{info fun step} finds all functions whose names
8769include @code{step}; @samp{info fun ^step} finds those whose names
1c5dfdad
MS
8770start with @code{step}. If a function name contains characters
8771that conflict with the regular expression language (eg.
8772@samp{operator*()}), they may be quoted with a backslash.
c906108c
SS
8773
8774@kindex info variables
8775@item info variables
8776Print the names and data types of all variables that are declared
8777outside of functions (i.e., excluding local variables).
8778
8779@item info variables @var{regexp}
8780Print the names and data types of all variables (except for local
8781variables) whose names contain a match for regular expression
8782@var{regexp}.
8783
8784@ignore
8785This was never implemented.
8786@kindex info methods
8787@item info methods
8788@itemx info methods @var{regexp}
8789The @code{info methods} command permits the user to examine all defined
b37052ae
EZ
8790methods within C@t{++} program, or (with the @var{regexp} argument) a
8791specific set of methods found in the various C@t{++} classes. Many
8792C@t{++} classes provide a large number of methods. Thus, the output
c906108c
SS
8793from the @code{ptype} command can be overwhelming and hard to use. The
8794@code{info-methods} command filters the methods, printing only those
8795which match the regular-expression @var{regexp}.
8796@end ignore
8797
c906108c
SS
8798@cindex reloading symbols
8799Some systems allow individual object files that make up your program to
7a292a7a
SS
8800be replaced without stopping and restarting your program. For example,
8801in VxWorks you can simply recompile a defective object file and keep on
8802running. If you are running on one of these systems, you can allow
8803@value{GDBN} to reload the symbols for automatically relinked modules:
c906108c
SS
8804
8805@table @code
8806@kindex set symbol-reloading
8807@item set symbol-reloading on
8808Replace symbol definitions for the corresponding source file when an
8809object file with a particular name is seen again.
8810
8811@item set symbol-reloading off
6d2ebf8b
SS
8812Do not replace symbol definitions when encountering object files of the
8813same name more than once. This is the default state; if you are not
8814running on a system that permits automatic relinking of modules, you
8815should leave @code{symbol-reloading} off, since otherwise @value{GDBN}
8816may discard symbols when linking large programs, that may contain
8817several modules (from different directories or libraries) with the same
8818name.
c906108c
SS
8819
8820@kindex show symbol-reloading
8821@item show symbol-reloading
8822Show the current @code{on} or @code{off} setting.
8823@end table
c906108c 8824
c906108c
SS
8825@kindex set opaque-type-resolution
8826@item set opaque-type-resolution on
8827Tell @value{GDBN} to resolve opaque types. An opaque type is a type
8828declared as a pointer to a @code{struct}, @code{class}, or
8829@code{union}---for example, @code{struct MyType *}---that is used in one
8830source file although the full declaration of @code{struct MyType} is in
8831another source file. The default is on.
8832
8833A change in the setting of this subcommand will not take effect until
8834the next time symbols for a file are loaded.
8835
8836@item set opaque-type-resolution off
8837Tell @value{GDBN} not to resolve opaque types. In this case, the type
8838is printed as follows:
8839@smallexample
8840@{<no data fields>@}
8841@end smallexample
8842
8843@kindex show opaque-type-resolution
8844@item show opaque-type-resolution
8845Show whether opaque types are resolved or not.
c906108c
SS
8846
8847@kindex maint print symbols
8848@cindex symbol dump
8849@kindex maint print psymbols
8850@cindex partial symbol dump
8851@item maint print symbols @var{filename}
8852@itemx maint print psymbols @var{filename}
8853@itemx maint print msymbols @var{filename}
8854Write a dump of debugging symbol data into the file @var{filename}.
8855These commands are used to debug the @value{GDBN} symbol-reading code. Only
8856symbols with debugging data are included. If you use @samp{maint print
8857symbols}, @value{GDBN} includes all the symbols for which it has already
8858collected full details: that is, @var{filename} reflects symbols for
8859only those files whose symbols @value{GDBN} has read. You can use the
8860command @code{info sources} to find out which files these are. If you
8861use @samp{maint print psymbols} instead, the dump shows information about
8862symbols that @value{GDBN} only knows partially---that is, symbols defined in
8863files that @value{GDBN} has skimmed, but not yet read completely. Finally,
8864@samp{maint print msymbols} dumps just the minimal symbol information
8865required for each object file from which @value{GDBN} has read some symbols.
8866@xref{Files, ,Commands to specify files}, for a discussion of how
8867@value{GDBN} reads symbols (in the description of @code{symbol-file}).
8868@end table
8869
6d2ebf8b 8870@node Altering
c906108c
SS
8871@chapter Altering Execution
8872
8873Once you think you have found an error in your program, you might want to
8874find out for certain whether correcting the apparent error would lead to
8875correct results in the rest of the run. You can find the answer by
8876experiment, using the @value{GDBN} features for altering execution of the
8877program.
8878
8879For example, you can store new values into variables or memory
7a292a7a
SS
8880locations, give your program a signal, restart it at a different
8881address, or even return prematurely from a function.
c906108c
SS
8882
8883@menu
8884* Assignment:: Assignment to variables
8885* Jumping:: Continuing at a different address
c906108c 8886* Signaling:: Giving your program a signal
c906108c
SS
8887* Returning:: Returning from a function
8888* Calling:: Calling your program's functions
8889* Patching:: Patching your program
8890@end menu
8891
6d2ebf8b 8892@node Assignment
c906108c
SS
8893@section Assignment to variables
8894
8895@cindex assignment
8896@cindex setting variables
8897To alter the value of a variable, evaluate an assignment expression.
8898@xref{Expressions, ,Expressions}. For example,
8899
8900@example
8901print x=4
8902@end example
8903
8904@noindent
8905stores the value 4 into the variable @code{x}, and then prints the
5d161b24 8906value of the assignment expression (which is 4).
c906108c
SS
8907@xref{Languages, ,Using @value{GDBN} with Different Languages}, for more
8908information on operators in supported languages.
c906108c
SS
8909
8910@kindex set variable
8911@cindex variables, setting
8912If you are not interested in seeing the value of the assignment, use the
8913@code{set} command instead of the @code{print} command. @code{set} is
8914really the same as @code{print} except that the expression's value is
8915not printed and is not put in the value history (@pxref{Value History,
8916,Value history}). The expression is evaluated only for its effects.
8917
c906108c
SS
8918If the beginning of the argument string of the @code{set} command
8919appears identical to a @code{set} subcommand, use the @code{set
8920variable} command instead of just @code{set}. This command is identical
8921to @code{set} except for its lack of subcommands. For example, if your
8922program has a variable @code{width}, you get an error if you try to set
8923a new value with just @samp{set width=13}, because @value{GDBN} has the
8924command @code{set width}:
8925
8926@example
8927(@value{GDBP}) whatis width
8928type = double
8929(@value{GDBP}) p width
8930$4 = 13
8931(@value{GDBP}) set width=47
8932Invalid syntax in expression.
8933@end example
8934
8935@noindent
8936The invalid expression, of course, is @samp{=47}. In
8937order to actually set the program's variable @code{width}, use
8938
8939@example
8940(@value{GDBP}) set var width=47
8941@end example
53a5351d 8942
c906108c
SS
8943Because the @code{set} command has many subcommands that can conflict
8944with the names of program variables, it is a good idea to use the
8945@code{set variable} command instead of just @code{set}. For example, if
8946your program has a variable @code{g}, you run into problems if you try
8947to set a new value with just @samp{set g=4}, because @value{GDBN} has
8948the command @code{set gnutarget}, abbreviated @code{set g}:
8949
8950@example
8951@group
8952(@value{GDBP}) whatis g
8953type = double
8954(@value{GDBP}) p g
8955$1 = 1
8956(@value{GDBP}) set g=4
2df3850c 8957(@value{GDBP}) p g
c906108c
SS
8958$2 = 1
8959(@value{GDBP}) r
8960The program being debugged has been started already.
8961Start it from the beginning? (y or n) y
8962Starting program: /home/smith/cc_progs/a.out
6d2ebf8b
SS
8963"/home/smith/cc_progs/a.out": can't open to read symbols:
8964 Invalid bfd target.
c906108c
SS
8965(@value{GDBP}) show g
8966The current BFD target is "=4".
8967@end group
8968@end example
8969
8970@noindent
8971The program variable @code{g} did not change, and you silently set the
8972@code{gnutarget} to an invalid value. In order to set the variable
8973@code{g}, use
8974
8975@example
8976(@value{GDBP}) set var g=4
8977@end example
c906108c
SS
8978
8979@value{GDBN} allows more implicit conversions in assignments than C; you can
8980freely store an integer value into a pointer variable or vice versa,
8981and you can convert any structure to any other structure that is the
8982same length or shorter.
8983@comment FIXME: how do structs align/pad in these conversions?
8984@comment /doc@cygnus.com 18dec1990
8985
8986To store values into arbitrary places in memory, use the @samp{@{@dots{}@}}
8987construct to generate a value of specified type at a specified address
8988(@pxref{Expressions, ,Expressions}). For example, @code{@{int@}0x83040} refers
8989to memory location @code{0x83040} as an integer (which implies a certain size
8990and representation in memory), and
8991
8992@example
8993set @{int@}0x83040 = 4
8994@end example
8995
8996@noindent
8997stores the value 4 into that memory location.
8998
6d2ebf8b 8999@node Jumping
c906108c
SS
9000@section Continuing at a different address
9001
9002Ordinarily, when you continue your program, you do so at the place where
9003it stopped, with the @code{continue} command. You can instead continue at
9004an address of your own choosing, with the following commands:
9005
9006@table @code
9007@kindex jump
9008@item jump @var{linespec}
9009Resume execution at line @var{linespec}. Execution stops again
9010immediately if there is a breakpoint there. @xref{List, ,Printing
9011source lines}, for a description of the different forms of
9012@var{linespec}. It is common practice to use the @code{tbreak} command
9013in conjunction with @code{jump}. @xref{Set Breaks, ,Setting
9014breakpoints}.
9015
9016The @code{jump} command does not change the current stack frame, or
9017the stack pointer, or the contents of any memory location or any
9018register other than the program counter. If line @var{linespec} is in
9019a different function from the one currently executing, the results may
9020be bizarre if the two functions expect different patterns of arguments or
9021of local variables. For this reason, the @code{jump} command requests
9022confirmation if the specified line is not in the function currently
9023executing. However, even bizarre results are predictable if you are
9024well acquainted with the machine-language code of your program.
9025
9026@item jump *@var{address}
9027Resume execution at the instruction at address @var{address}.
9028@end table
9029
c906108c 9030@c Doesn't work on HP-UX; have to set $pcoqh and $pcoqt.
53a5351d
JM
9031On many systems, you can get much the same effect as the @code{jump}
9032command by storing a new value into the register @code{$pc}. The
9033difference is that this does not start your program running; it only
9034changes the address of where it @emph{will} run when you continue. For
9035example,
c906108c
SS
9036
9037@example
9038set $pc = 0x485
9039@end example
9040
9041@noindent
9042makes the next @code{continue} command or stepping command execute at
9043address @code{0x485}, rather than at the address where your program stopped.
9044@xref{Continuing and Stepping, ,Continuing and stepping}.
c906108c
SS
9045
9046The most common occasion to use the @code{jump} command is to back
9047up---perhaps with more breakpoints set---over a portion of a program
9048that has already executed, in order to examine its execution in more
9049detail.
9050
c906108c 9051@c @group
6d2ebf8b 9052@node Signaling
c906108c
SS
9053@section Giving your program a signal
9054
9055@table @code
9056@kindex signal
9057@item signal @var{signal}
9058Resume execution where your program stopped, but immediately give it the
9059signal @var{signal}. @var{signal} can be the name or the number of a
9060signal. For example, on many systems @code{signal 2} and @code{signal
9061SIGINT} are both ways of sending an interrupt signal.
9062
9063Alternatively, if @var{signal} is zero, continue execution without
9064giving a signal. This is useful when your program stopped on account of
9065a signal and would ordinary see the signal when resumed with the
9066@code{continue} command; @samp{signal 0} causes it to resume without a
9067signal.
9068
9069@code{signal} does not repeat when you press @key{RET} a second time
9070after executing the command.
9071@end table
9072@c @end group
9073
9074Invoking the @code{signal} command is not the same as invoking the
9075@code{kill} utility from the shell. Sending a signal with @code{kill}
9076causes @value{GDBN} to decide what to do with the signal depending on
9077the signal handling tables (@pxref{Signals}). The @code{signal} command
9078passes the signal directly to your program.
9079
c906108c 9080
6d2ebf8b 9081@node Returning
c906108c
SS
9082@section Returning from a function
9083
9084@table @code
9085@cindex returning from a function
9086@kindex return
9087@item return
9088@itemx return @var{expression}
9089You can cancel execution of a function call with the @code{return}
9090command. If you give an
9091@var{expression} argument, its value is used as the function's return
9092value.
9093@end table
9094
9095When you use @code{return}, @value{GDBN} discards the selected stack frame
9096(and all frames within it). You can think of this as making the
9097discarded frame return prematurely. If you wish to specify a value to
9098be returned, give that value as the argument to @code{return}.
9099
9100This pops the selected stack frame (@pxref{Selection, ,Selecting a
9101frame}), and any other frames inside of it, leaving its caller as the
9102innermost remaining frame. That frame becomes selected. The
9103specified value is stored in the registers used for returning values
9104of functions.
9105
9106The @code{return} command does not resume execution; it leaves the
9107program stopped in the state that would exist if the function had just
9108returned. In contrast, the @code{finish} command (@pxref{Continuing
9109and Stepping, ,Continuing and stepping}) resumes execution until the
9110selected stack frame returns naturally.
9111
6d2ebf8b 9112@node Calling
c906108c
SS
9113@section Calling program functions
9114
9115@cindex calling functions
9116@kindex call
9117@table @code
9118@item call @var{expr}
9119Evaluate the expression @var{expr} without displaying @code{void}
9120returned values.
9121@end table
9122
9123You can use this variant of the @code{print} command if you want to
9124execute a function from your program, but without cluttering the output
5d161b24
DB
9125with @code{void} returned values. If the result is not void, it
9126is printed and saved in the value history.
c906108c 9127
7d86b5d5
AC
9128@c OBSOLETE For the A29K, a user-controlled variable @code{call_scratch_address},
9129@c OBSOLETE specifies the location of a scratch area to be used when @value{GDBN}
9130@c OBSOLETE calls a function in the target. This is necessary because the usual
9131@c OBSOLETE method of putting the scratch area on the stack does not work in systems
9132@c OBSOLETE that have separate instruction and data spaces.
c906108c 9133
6d2ebf8b 9134@node Patching
c906108c 9135@section Patching programs
7a292a7a 9136
c906108c
SS
9137@cindex patching binaries
9138@cindex writing into executables
c906108c 9139@cindex writing into corefiles
c906108c 9140
7a292a7a
SS
9141By default, @value{GDBN} opens the file containing your program's
9142executable code (or the corefile) read-only. This prevents accidental
9143alterations to machine code; but it also prevents you from intentionally
9144patching your program's binary.
c906108c
SS
9145
9146If you'd like to be able to patch the binary, you can specify that
9147explicitly with the @code{set write} command. For example, you might
9148want to turn on internal debugging flags, or even to make emergency
9149repairs.
9150
9151@table @code
9152@kindex set write
9153@item set write on
9154@itemx set write off
7a292a7a
SS
9155If you specify @samp{set write on}, @value{GDBN} opens executable and
9156core files for both reading and writing; if you specify @samp{set write
c906108c
SS
9157off} (the default), @value{GDBN} opens them read-only.
9158
9159If you have already loaded a file, you must load it again (using the
7a292a7a
SS
9160@code{exec-file} or @code{core-file} command) after changing @code{set
9161write}, for your new setting to take effect.
c906108c
SS
9162
9163@item show write
9164@kindex show write
7a292a7a
SS
9165Display whether executable files and core files are opened for writing
9166as well as reading.
c906108c
SS
9167@end table
9168
6d2ebf8b 9169@node GDB Files
c906108c
SS
9170@chapter @value{GDBN} Files
9171
7a292a7a
SS
9172@value{GDBN} needs to know the file name of the program to be debugged,
9173both in order to read its symbol table and in order to start your
9174program. To debug a core dump of a previous run, you must also tell
9175@value{GDBN} the name of the core dump file.
c906108c
SS
9176
9177@menu
9178* Files:: Commands to specify files
9179* Symbol Errors:: Errors reading symbol files
9180@end menu
9181
6d2ebf8b 9182@node Files
c906108c 9183@section Commands to specify files
c906108c 9184
7a292a7a 9185@cindex symbol table
c906108c 9186@cindex core dump file
7a292a7a
SS
9187
9188You may want to specify executable and core dump file names. The usual
9189way to do this is at start-up time, using the arguments to
9190@value{GDBN}'s start-up commands (@pxref{Invocation, , Getting In and
9191Out of @value{GDBN}}).
c906108c
SS
9192
9193Occasionally it is necessary to change to a different file during a
9194@value{GDBN} session. Or you may run @value{GDBN} and forget to specify
9195a file you want to use. In these situations the @value{GDBN} commands
9196to specify new files are useful.
9197
9198@table @code
9199@cindex executable file
9200@kindex file
9201@item file @var{filename}
9202Use @var{filename} as the program to be debugged. It is read for its
9203symbols and for the contents of pure memory. It is also the program
9204executed when you use the @code{run} command. If you do not specify a
5d161b24
DB
9205directory and the file is not found in the @value{GDBN} working directory,
9206@value{GDBN} uses the environment variable @code{PATH} as a list of
9207directories to search, just as the shell does when looking for a program
9208to run. You can change the value of this variable, for both @value{GDBN}
c906108c
SS
9209and your program, using the @code{path} command.
9210
6d2ebf8b 9211On systems with memory-mapped files, an auxiliary file named
c906108c
SS
9212@file{@var{filename}.syms} may hold symbol table information for
9213@var{filename}. If so, @value{GDBN} maps in the symbol table from
9214@file{@var{filename}.syms}, starting up more quickly. See the
9215descriptions of the file options @samp{-mapped} and @samp{-readnow}
9216(available on the command line, and with the commands @code{file},
5d161b24 9217@code{symbol-file}, or @code{add-symbol-file}, described below),
c906108c 9218for more information.
c906108c
SS
9219
9220@item file
9221@code{file} with no argument makes @value{GDBN} discard any information it
9222has on both executable file and the symbol table.
9223
9224@kindex exec-file
9225@item exec-file @r{[} @var{filename} @r{]}
9226Specify that the program to be run (but not the symbol table) is found
9227in @var{filename}. @value{GDBN} searches the environment variable @code{PATH}
9228if necessary to locate your program. Omitting @var{filename} means to
9229discard information on the executable file.
9230
9231@kindex symbol-file
9232@item symbol-file @r{[} @var{filename} @r{]}
9233Read symbol table information from file @var{filename}. @code{PATH} is
9234searched when necessary. Use the @code{file} command to get both symbol
9235table and program to run from the same file.
9236
9237@code{symbol-file} with no argument clears out @value{GDBN} information on your
9238program's symbol table.
9239
5d161b24 9240The @code{symbol-file} command causes @value{GDBN} to forget the contents
c906108c
SS
9241of its convenience variables, the value history, and all breakpoints and
9242auto-display expressions. This is because they may contain pointers to
9243the internal data recording symbols and data types, which are part of
9244the old symbol table data being discarded inside @value{GDBN}.
9245
9246@code{symbol-file} does not repeat if you press @key{RET} again after
9247executing it once.
9248
9249When @value{GDBN} is configured for a particular environment, it
9250understands debugging information in whatever format is the standard
9251generated for that environment; you may use either a @sc{gnu} compiler, or
9252other compilers that adhere to the local conventions.
c906108c
SS
9253Best results are usually obtained from @sc{gnu} compilers; for example,
9254using @code{@value{GCC}} you can generate debugging information for
9255optimized code.
c906108c
SS
9256
9257For most kinds of object files, with the exception of old SVR3 systems
9258using COFF, the @code{symbol-file} command does not normally read the
9259symbol table in full right away. Instead, it scans the symbol table
9260quickly to find which source files and which symbols are present. The
9261details are read later, one source file at a time, as they are needed.
9262
9263The purpose of this two-stage reading strategy is to make @value{GDBN}
9264start up faster. For the most part, it is invisible except for
9265occasional pauses while the symbol table details for a particular source
9266file are being read. (The @code{set verbose} command can turn these
9267pauses into messages if desired. @xref{Messages/Warnings, ,Optional
9268warnings and messages}.)
9269
c906108c
SS
9270We have not implemented the two-stage strategy for COFF yet. When the
9271symbol table is stored in COFF format, @code{symbol-file} reads the
9272symbol table data in full right away. Note that ``stabs-in-COFF''
9273still does the two-stage strategy, since the debug info is actually
9274in stabs format.
9275
9276@kindex readnow
9277@cindex reading symbols immediately
9278@cindex symbols, reading immediately
9279@kindex mapped
9280@cindex memory-mapped symbol file
9281@cindex saving symbol table
9282@item symbol-file @var{filename} @r{[} -readnow @r{]} @r{[} -mapped @r{]}
9283@itemx file @var{filename} @r{[} -readnow @r{]} @r{[} -mapped @r{]}
9284You can override the @value{GDBN} two-stage strategy for reading symbol
9285tables by using the @samp{-readnow} option with any of the commands that
9286load symbol table information, if you want to be sure @value{GDBN} has the
5d161b24 9287entire symbol table available.
c906108c 9288
c906108c
SS
9289If memory-mapped files are available on your system through the
9290@code{mmap} system call, you can use another option, @samp{-mapped}, to
9291cause @value{GDBN} to write the symbols for your program into a reusable
9292file. Future @value{GDBN} debugging sessions map in symbol information
9293from this auxiliary symbol file (if the program has not changed), rather
9294than spending time reading the symbol table from the executable
9295program. Using the @samp{-mapped} option has the same effect as
9296starting @value{GDBN} with the @samp{-mapped} command-line option.
9297
9298You can use both options together, to make sure the auxiliary symbol
9299file has all the symbol information for your program.
9300
9301The auxiliary symbol file for a program called @var{myprog} is called
9302@samp{@var{myprog}.syms}. Once this file exists (so long as it is newer
9303than the corresponding executable), @value{GDBN} always attempts to use
9304it when you debug @var{myprog}; no special options or commands are
9305needed.
9306
9307The @file{.syms} file is specific to the host machine where you run
9308@value{GDBN}. It holds an exact image of the internal @value{GDBN}
9309symbol table. It cannot be shared across multiple host platforms.
c906108c
SS
9310
9311@c FIXME: for now no mention of directories, since this seems to be in
9312@c flux. 13mar1992 status is that in theory GDB would look either in
9313@c current dir or in same dir as myprog; but issues like competing
9314@c GDB's, or clutter in system dirs, mean that in practice right now
9315@c only current dir is used. FFish says maybe a special GDB hierarchy
9316@c (eg rooted in val of env var GDBSYMS) could exist for mappable symbol
9317@c files.
9318
9319@kindex core
9320@kindex core-file
9321@item core-file @r{[} @var{filename} @r{]}
9322Specify the whereabouts of a core dump file to be used as the ``contents
9323of memory''. Traditionally, core files contain only some parts of the
9324address space of the process that generated them; @value{GDBN} can access the
9325executable file itself for other parts.
9326
9327@code{core-file} with no argument specifies that no core file is
9328to be used.
9329
9330Note that the core file is ignored when your program is actually running
7a292a7a
SS
9331under @value{GDBN}. So, if you have been running your program and you
9332wish to debug a core file instead, you must kill the subprocess in which
9333the program is running. To do this, use the @code{kill} command
c906108c 9334(@pxref{Kill Process, ,Killing the child process}).
c906108c 9335
c906108c
SS
9336@kindex add-symbol-file
9337@cindex dynamic linking
9338@item add-symbol-file @var{filename} @var{address}
9339@itemx add-symbol-file @var{filename} @var{address} @r{[} -readnow @r{]} @r{[} -mapped @r{]}
17d9d558 9340@itemx add-symbol-file @var{filename} @r{-s}@var{section} @var{address} @dots{}
96a2c332
SS
9341The @code{add-symbol-file} command reads additional symbol table
9342information from the file @var{filename}. You would use this command
9343when @var{filename} has been dynamically loaded (by some other means)
9344into the program that is running. @var{address} should be the memory
9345address at which the file has been loaded; @value{GDBN} cannot figure
d167840f
EZ
9346this out for itself. You can additionally specify an arbitrary number
9347of @samp{@r{-s}@var{section} @var{address}} pairs, to give an explicit
9348section name and base address for that section. You can specify any
9349@var{address} as an expression.
c906108c
SS
9350
9351The symbol table of the file @var{filename} is added to the symbol table
9352originally read with the @code{symbol-file} command. You can use the
96a2c332
SS
9353@code{add-symbol-file} command any number of times; the new symbol data
9354thus read keeps adding to the old. To discard all old symbol data
9355instead, use the @code{symbol-file} command without any arguments.
c906108c 9356
17d9d558
JB
9357@cindex relocatable object files, reading symbols from
9358@cindex object files, relocatable, reading symbols from
9359@cindex reading symbols from relocatable object files
9360@cindex symbols, reading from relocatable object files
9361@cindex @file{.o} files, reading symbols from
9362Although @var{filename} is typically a shared library file, an
9363executable file, or some other object file which has been fully
9364relocated for loading into a process, you can also load symbolic
9365information from relocatable @file{.o} files, as long as:
9366
9367@itemize @bullet
9368@item
9369the file's symbolic information refers only to linker symbols defined in
9370that file, not to symbols defined by other object files,
9371@item
9372every section the file's symbolic information refers to has actually
9373been loaded into the inferior, as it appears in the file, and
9374@item
9375you can determine the address at which every section was loaded, and
9376provide these to the @code{add-symbol-file} command.
9377@end itemize
9378
9379@noindent
9380Some embedded operating systems, like Sun Chorus and VxWorks, can load
9381relocatable files into an already running program; such systems
9382typically make the requirements above easy to meet. However, it's
9383important to recognize that many native systems use complex link
9384procedures (@code{.linkonce} section factoring and C++ constructor table
9385assembly, for example) that make the requirements difficult to meet. In
9386general, one cannot assume that using @code{add-symbol-file} to read a
9387relocatable object file's symbolic information will have the same effect
9388as linking the relocatable object file into the program in the normal
9389way.
9390
c906108c
SS
9391@code{add-symbol-file} does not repeat if you press @key{RET} after using it.
9392
9393You can use the @samp{-mapped} and @samp{-readnow} options just as with
9394the @code{symbol-file} command, to change how @value{GDBN} manages the symbol
9395table information for @var{filename}.
9396
9397@kindex add-shared-symbol-file
9398@item add-shared-symbol-file
9399The @code{add-shared-symbol-file} command can be used only under Harris' CXUX
5d161b24
DB
9400operating system for the Motorola 88k. @value{GDBN} automatically looks for
9401shared libraries, however if @value{GDBN} does not find yours, you can run
c906108c 9402@code{add-shared-symbol-file}. It takes no arguments.
c906108c 9403
c906108c
SS
9404@kindex section
9405@item section
5d161b24
DB
9406The @code{section} command changes the base address of section SECTION of
9407the exec file to ADDR. This can be used if the exec file does not contain
9408section addresses, (such as in the a.out format), or when the addresses
9409specified in the file itself are wrong. Each section must be changed
d4f3574e
SS
9410separately. The @code{info files} command, described below, lists all
9411the sections and their addresses.
c906108c
SS
9412
9413@kindex info files
9414@kindex info target
9415@item info files
9416@itemx info target
7a292a7a
SS
9417@code{info files} and @code{info target} are synonymous; both print the
9418current target (@pxref{Targets, ,Specifying a Debugging Target}),
9419including the names of the executable and core dump files currently in
9420use by @value{GDBN}, and the files from which symbols were loaded. The
9421command @code{help target} lists all possible targets rather than
9422current ones.
9423
fe95c787
MS
9424@kindex maint info sections
9425@item maint info sections
9426Another command that can give you extra information about program sections
9427is @code{maint info sections}. In addition to the section information
9428displayed by @code{info files}, this command displays the flags and file
9429offset of each section in the executable and core dump files. In addition,
9430@code{maint info sections} provides the following command options (which
9431may be arbitrarily combined):
9432
9433@table @code
9434@item ALLOBJ
9435Display sections for all loaded object files, including shared libraries.
9436@item @var{sections}
6600abed 9437Display info only for named @var{sections}.
fe95c787
MS
9438@item @var{section-flags}
9439Display info only for sections for which @var{section-flags} are true.
9440The section flags that @value{GDBN} currently knows about are:
9441@table @code
9442@item ALLOC
9443Section will have space allocated in the process when loaded.
9444Set for all sections except those containing debug information.
9445@item LOAD
9446Section will be loaded from the file into the child process memory.
9447Set for pre-initialized code and data, clear for @code{.bss} sections.
9448@item RELOC
9449Section needs to be relocated before loading.
9450@item READONLY
9451Section cannot be modified by the child process.
9452@item CODE
9453Section contains executable code only.
6600abed 9454@item DATA
fe95c787
MS
9455Section contains data only (no executable code).
9456@item ROM
9457Section will reside in ROM.
9458@item CONSTRUCTOR
9459Section contains data for constructor/destructor lists.
9460@item HAS_CONTENTS
9461Section is not empty.
9462@item NEVER_LOAD
9463An instruction to the linker to not output the section.
9464@item COFF_SHARED_LIBRARY
9465A notification to the linker that the section contains
9466COFF shared library information.
9467@item IS_COMMON
9468Section contains common symbols.
9469@end table
9470@end table
c906108c
SS
9471@end table
9472
9473All file-specifying commands allow both absolute and relative file names
9474as arguments. @value{GDBN} always converts the file name to an absolute file
9475name and remembers it that way.
9476
c906108c 9477@cindex shared libraries
c906108c
SS
9478@value{GDBN} supports HP-UX, SunOS, SVr4, Irix 5, and IBM RS/6000 shared
9479libraries.
53a5351d 9480
c906108c
SS
9481@value{GDBN} automatically loads symbol definitions from shared libraries
9482when you use the @code{run} command, or when you examine a core file.
9483(Before you issue the @code{run} command, @value{GDBN} does not understand
9484references to a function in a shared library, however---unless you are
9485debugging a core file).
53a5351d
JM
9486
9487On HP-UX, if the program loads a library explicitly, @value{GDBN}
9488automatically loads the symbols at the time of the @code{shl_load} call.
9489
c906108c
SS
9490@c FIXME: some @value{GDBN} release may permit some refs to undef
9491@c FIXME...symbols---eg in a break cmd---assuming they are from a shared
9492@c FIXME...lib; check this from time to time when updating manual
9493
b7209cb4
FF
9494There are times, however, when you may wish to not automatically load
9495symbol definitions from shared libraries, such as when they are
9496particularly large or there are many of them.
9497
9498To control the automatic loading of shared library symbols, use the
9499commands:
9500
9501@table @code
9502@kindex set auto-solib-add
9503@item set auto-solib-add @var{mode}
9504If @var{mode} is @code{on}, symbols from all shared object libraries
9505will be loaded automatically when the inferior begins execution, you
9506attach to an independently started inferior, or when the dynamic linker
9507informs @value{GDBN} that a new library has been loaded. If @var{mode}
9508is @code{off}, symbols must be loaded manually, using the
9509@code{sharedlibrary} command. The default value is @code{on}.
9510
9511@kindex show auto-solib-add
9512@item show auto-solib-add
9513Display the current autoloading mode.
9514@end table
9515
9516To explicitly load shared library symbols, use the @code{sharedlibrary}
9517command:
9518
c906108c
SS
9519@table @code
9520@kindex info sharedlibrary
9521@kindex info share
9522@item info share
9523@itemx info sharedlibrary
9524Print the names of the shared libraries which are currently loaded.
9525
9526@kindex sharedlibrary
9527@kindex share
9528@item sharedlibrary @var{regex}
9529@itemx share @var{regex}
c906108c
SS
9530Load shared object library symbols for files matching a
9531Unix regular expression.
9532As with files loaded automatically, it only loads shared libraries
9533required by your program for a core file or after typing @code{run}. If
9534@var{regex} is omitted all shared libraries required by your program are
9535loaded.
9536@end table
9537
b7209cb4
FF
9538On some systems, such as HP-UX systems, @value{GDBN} supports
9539autoloading shared library symbols until a limiting threshold size is
9540reached. This provides the benefit of allowing autoloading to remain on
9541by default, but avoids autoloading excessively large shared libraries,
9542up to a threshold that is initially set, but which you can modify if you
9543wish.
c906108c
SS
9544
9545Beyond that threshold, symbols from shared libraries must be explicitly
d4f3574e
SS
9546loaded. To load these symbols, use the command @code{sharedlibrary
9547@var{filename}}. The base address of the shared library is determined
c906108c
SS
9548automatically by @value{GDBN} and need not be specified.
9549
9550To display or set the threshold, use the commands:
9551
9552@table @code
b7209cb4
FF
9553@kindex set auto-solib-limit
9554@item set auto-solib-limit @var{threshold}
9555Set the autoloading size threshold, in an integral number of megabytes.
9556If @var{threshold} is nonzero and shared library autoloading is enabled,
9557symbols from all shared object libraries will be loaded until the total
9558size of the loaded shared library symbols exceeds this threshold.
c906108c 9559Otherwise, symbols must be loaded manually, using the
b7209cb4
FF
9560@code{sharedlibrary} command. The default threshold is 100 (i.e. 100
9561Mb).
c906108c 9562
b7209cb4
FF
9563@kindex show auto-solib-limit
9564@item show auto-solib-limit
c906108c
SS
9565Display the current autoloading size threshold, in megabytes.
9566@end table
c906108c 9567
6d2ebf8b 9568@node Symbol Errors
c906108c
SS
9569@section Errors reading symbol files
9570
9571While reading a symbol file, @value{GDBN} occasionally encounters problems,
9572such as symbol types it does not recognize, or known bugs in compiler
9573output. By default, @value{GDBN} does not notify you of such problems, since
9574they are relatively common and primarily of interest to people
9575debugging compilers. If you are interested in seeing information
9576about ill-constructed symbol tables, you can either ask @value{GDBN} to print
9577only one message about each such type of problem, no matter how many
9578times the problem occurs; or you can ask @value{GDBN} to print more messages,
9579to see how many times the problems occur, with the @code{set
9580complaints} command (@pxref{Messages/Warnings, ,Optional warnings and
9581messages}).
9582
9583The messages currently printed, and their meanings, include:
9584
9585@table @code
9586@item inner block not inside outer block in @var{symbol}
9587
9588The symbol information shows where symbol scopes begin and end
9589(such as at the start of a function or a block of statements). This
9590error indicates that an inner scope block is not fully contained
9591in its outer scope blocks.
9592
9593@value{GDBN} circumvents the problem by treating the inner block as if it had
9594the same scope as the outer block. In the error message, @var{symbol}
9595may be shown as ``@code{(don't know)}'' if the outer block is not a
9596function.
9597
9598@item block at @var{address} out of order
9599
9600The symbol information for symbol scope blocks should occur in
9601order of increasing addresses. This error indicates that it does not
9602do so.
9603
9604@value{GDBN} does not circumvent this problem, and has trouble
9605locating symbols in the source file whose symbols it is reading. (You
9606can often determine what source file is affected by specifying
9607@code{set verbose on}. @xref{Messages/Warnings, ,Optional warnings and
9608messages}.)
9609
9610@item bad block start address patched
9611
9612The symbol information for a symbol scope block has a start address
9613smaller than the address of the preceding source line. This is known
9614to occur in the SunOS 4.1.1 (and earlier) C compiler.
9615
9616@value{GDBN} circumvents the problem by treating the symbol scope block as
9617starting on the previous source line.
9618
9619@item bad string table offset in symbol @var{n}
9620
9621@cindex foo
9622Symbol number @var{n} contains a pointer into the string table which is
9623larger than the size of the string table.
9624
9625@value{GDBN} circumvents the problem by considering the symbol to have the
9626name @code{foo}, which may cause other problems if many symbols end up
9627with this name.
9628
9629@item unknown symbol type @code{0x@var{nn}}
9630
7a292a7a
SS
9631The symbol information contains new data types that @value{GDBN} does
9632not yet know how to read. @code{0x@var{nn}} is the symbol type of the
d4f3574e 9633uncomprehended information, in hexadecimal.
c906108c 9634
7a292a7a
SS
9635@value{GDBN} circumvents the error by ignoring this symbol information.
9636This usually allows you to debug your program, though certain symbols
c906108c 9637are not accessible. If you encounter such a problem and feel like
7a292a7a
SS
9638debugging it, you can debug @code{@value{GDBP}} with itself, breakpoint
9639on @code{complain}, then go up to the function @code{read_dbx_symtab}
9640and examine @code{*bufp} to see the symbol.
c906108c
SS
9641
9642@item stub type has NULL name
c906108c 9643
7a292a7a 9644@value{GDBN} could not find the full definition for a struct or class.
c906108c 9645
7a292a7a 9646@item const/volatile indicator missing (ok if using g++ v1.x), got@dots{}
b37052ae 9647The symbol information for a C@t{++} member function is missing some
7a292a7a
SS
9648information that recent versions of the compiler should have output for
9649it.
c906108c
SS
9650
9651@item info mismatch between compiler and debugger
9652
9653@value{GDBN} could not parse a type specification output by the compiler.
7a292a7a 9654
c906108c
SS
9655@end table
9656
6d2ebf8b 9657@node Targets
c906108c 9658@chapter Specifying a Debugging Target
7a292a7a 9659
c906108c
SS
9660@cindex debugging target
9661@kindex target
9662
9663A @dfn{target} is the execution environment occupied by your program.
53a5351d
JM
9664
9665Often, @value{GDBN} runs in the same host environment as your program;
9666in that case, the debugging target is specified as a side effect when
9667you use the @code{file} or @code{core} commands. When you need more
c906108c
SS
9668flexibility---for example, running @value{GDBN} on a physically separate
9669host, or controlling a standalone system over a serial port or a
53a5351d
JM
9670realtime system over a TCP/IP connection---you can use the @code{target}
9671command to specify one of the target types configured for @value{GDBN}
9672(@pxref{Target Commands, ,Commands for managing targets}).
c906108c
SS
9673
9674@menu
9675* Active Targets:: Active targets
9676* Target Commands:: Commands for managing targets
c906108c
SS
9677* Byte Order:: Choosing target byte order
9678* Remote:: Remote debugging
96baa820 9679* KOD:: Kernel Object Display
c906108c
SS
9680
9681@end menu
9682
6d2ebf8b 9683@node Active Targets
c906108c 9684@section Active targets
7a292a7a 9685
c906108c
SS
9686@cindex stacking targets
9687@cindex active targets
9688@cindex multiple targets
9689
c906108c 9690There are three classes of targets: processes, core files, and
7a292a7a
SS
9691executable files. @value{GDBN} can work concurrently on up to three
9692active targets, one in each class. This allows you to (for example)
9693start a process and inspect its activity without abandoning your work on
9694a core file.
c906108c
SS
9695
9696For example, if you execute @samp{gdb a.out}, then the executable file
9697@code{a.out} is the only active target. If you designate a core file as
9698well---presumably from a prior run that crashed and coredumped---then
9699@value{GDBN} has two active targets and uses them in tandem, looking
9700first in the corefile target, then in the executable file, to satisfy
9701requests for memory addresses. (Typically, these two classes of target
9702are complementary, since core files contain only a program's
9703read-write memory---variables and so on---plus machine status, while
9704executable files contain only the program text and initialized data.)
c906108c
SS
9705
9706When you type @code{run}, your executable file becomes an active process
7a292a7a
SS
9707target as well. When a process target is active, all @value{GDBN}
9708commands requesting memory addresses refer to that target; addresses in
9709an active core file or executable file target are obscured while the
9710process target is active.
c906108c 9711
7a292a7a
SS
9712Use the @code{core-file} and @code{exec-file} commands to select a new
9713core file or executable target (@pxref{Files, ,Commands to specify
c906108c 9714files}). To specify as a target a process that is already running, use
7a292a7a
SS
9715the @code{attach} command (@pxref{Attach, ,Debugging an already-running
9716process}).
c906108c 9717
6d2ebf8b 9718@node Target Commands
c906108c
SS
9719@section Commands for managing targets
9720
9721@table @code
9722@item target @var{type} @var{parameters}
7a292a7a
SS
9723Connects the @value{GDBN} host environment to a target machine or
9724process. A target is typically a protocol for talking to debugging
9725facilities. You use the argument @var{type} to specify the type or
9726protocol of the target machine.
c906108c
SS
9727
9728Further @var{parameters} are interpreted by the target protocol, but
9729typically include things like device names or host names to connect
9730with, process numbers, and baud rates.
c906108c
SS
9731
9732The @code{target} command does not repeat if you press @key{RET} again
9733after executing the command.
9734
9735@kindex help target
9736@item help target
9737Displays the names of all targets available. To display targets
9738currently selected, use either @code{info target} or @code{info files}
9739(@pxref{Files, ,Commands to specify files}).
9740
9741@item help target @var{name}
9742Describe a particular target, including any parameters necessary to
9743select it.
9744
9745@kindex set gnutarget
9746@item set gnutarget @var{args}
5d161b24 9747@value{GDBN} uses its own library BFD to read your files. @value{GDBN}
c906108c 9748knows whether it is reading an @dfn{executable},
5d161b24
DB
9749a @dfn{core}, or a @dfn{.o} file; however, you can specify the file format
9750with the @code{set gnutarget} command. Unlike most @code{target} commands,
c906108c
SS
9751with @code{gnutarget} the @code{target} refers to a program, not a machine.
9752
d4f3574e 9753@quotation
c906108c
SS
9754@emph{Warning:} To specify a file format with @code{set gnutarget},
9755you must know the actual BFD name.
d4f3574e 9756@end quotation
c906108c 9757
d4f3574e
SS
9758@noindent
9759@xref{Files, , Commands to specify files}.
c906108c 9760
5d161b24 9761@kindex show gnutarget
c906108c
SS
9762@item show gnutarget
9763Use the @code{show gnutarget} command to display what file format
9764@code{gnutarget} is set to read. If you have not set @code{gnutarget},
9765@value{GDBN} will determine the file format for each file automatically,
9766and @code{show gnutarget} displays @samp{The current BDF target is "auto"}.
9767@end table
9768
c906108c
SS
9769Here are some common targets (available, or not, depending on the GDB
9770configuration):
c906108c
SS
9771
9772@table @code
9773@kindex target exec
9774@item target exec @var{program}
9775An executable file. @samp{target exec @var{program}} is the same as
9776@samp{exec-file @var{program}}.
9777
c906108c
SS
9778@kindex target core
9779@item target core @var{filename}
9780A core dump file. @samp{target core @var{filename}} is the same as
9781@samp{core-file @var{filename}}.
c906108c
SS
9782
9783@kindex target remote
9784@item target remote @var{dev}
9785Remote serial target in GDB-specific protocol. The argument @var{dev}
9786specifies what serial device to use for the connection (e.g.
9787@file{/dev/ttya}). @xref{Remote, ,Remote debugging}. @code{target remote}
d4f3574e 9788supports the @code{load} command. This is only useful if you have
c906108c
SS
9789some other way of getting the stub to the target system, and you can put
9790it somewhere in memory where it won't get clobbered by the download.
9791
c906108c
SS
9792@kindex target sim
9793@item target sim
2df3850c 9794Builtin CPU simulator. @value{GDBN} includes simulators for most architectures.
104c1213
JM
9795In general,
9796@example
9797 target sim
9798 load
9799 run
9800@end example
d4f3574e 9801@noindent
104c1213 9802works; however, you cannot assume that a specific memory map, device
d4f3574e 9803drivers, or even basic I/O is available, although some simulators do
104c1213
JM
9804provide these. For info about any processor-specific simulator details,
9805see the appropriate section in @ref{Embedded Processors, ,Embedded
9806Processors}.
9807
c906108c
SS
9808@end table
9809
104c1213 9810Some configurations may include these targets as well:
c906108c
SS
9811
9812@table @code
9813
c906108c
SS
9814@kindex target nrom
9815@item target nrom @var{dev}
9816NetROM ROM emulator. This target only supports downloading.
9817
c906108c
SS
9818@end table
9819
5d161b24 9820Different targets are available on different configurations of @value{GDBN};
c906108c 9821your configuration may have more or fewer targets.
c906108c
SS
9822
9823Many remote targets require you to download the executable's code
9824once you've successfully established a connection.
9825
9826@table @code
9827
9828@kindex load @var{filename}
9829@item load @var{filename}
c906108c
SS
9830Depending on what remote debugging facilities are configured into
9831@value{GDBN}, the @code{load} command may be available. Where it exists, it
9832is meant to make @var{filename} (an executable) available for debugging
9833on the remote system---by downloading, or dynamic linking, for example.
9834@code{load} also records the @var{filename} symbol table in @value{GDBN}, like
9835the @code{add-symbol-file} command.
9836
9837If your @value{GDBN} does not have a @code{load} command, attempting to
9838execute it gets the error message ``@code{You can't do that when your
9839target is @dots{}}''
c906108c
SS
9840
9841The file is loaded at whatever address is specified in the executable.
9842For some object file formats, you can specify the load address when you
9843link the program; for other formats, like a.out, the object file format
9844specifies a fixed address.
9845@c FIXME! This would be a good place for an xref to the GNU linker doc.
9846
c906108c
SS
9847@code{load} does not repeat if you press @key{RET} again after using it.
9848@end table
9849
6d2ebf8b 9850@node Byte Order
c906108c 9851@section Choosing target byte order
7a292a7a 9852
c906108c
SS
9853@cindex choosing target byte order
9854@cindex target byte order
c906108c
SS
9855
9856Some types of processors, such as the MIPS, PowerPC, and Hitachi SH,
9857offer the ability to run either big-endian or little-endian byte
9858orders. Usually the executable or symbol will include a bit to
9859designate the endian-ness, and you will not need to worry about
9860which to use. However, you may still find it useful to adjust
d4f3574e 9861@value{GDBN}'s idea of processor endian-ness manually.
c906108c
SS
9862
9863@table @code
9864@kindex set endian big
9865@item set endian big
9866Instruct @value{GDBN} to assume the target is big-endian.
9867
9868@kindex set endian little
9869@item set endian little
9870Instruct @value{GDBN} to assume the target is little-endian.
9871
9872@kindex set endian auto
9873@item set endian auto
9874Instruct @value{GDBN} to use the byte order associated with the
9875executable.
9876
9877@item show endian
9878Display @value{GDBN}'s current idea of the target byte order.
9879
9880@end table
9881
9882Note that these commands merely adjust interpretation of symbolic
9883data on the host, and that they have absolutely no effect on the
9884target system.
9885
6d2ebf8b 9886@node Remote
c906108c
SS
9887@section Remote debugging
9888@cindex remote debugging
9889
9890If you are trying to debug a program running on a machine that cannot run
5d161b24
DB
9891@value{GDBN} in the usual way, it is often useful to use remote debugging.
9892For example, you might use remote debugging on an operating system kernel,
c906108c
SS
9893or on a small system which does not have a general purpose operating system
9894powerful enough to run a full-featured debugger.
9895
9896Some configurations of @value{GDBN} have special serial or TCP/IP interfaces
9897to make this work with particular debugging targets. In addition,
5d161b24 9898@value{GDBN} comes with a generic serial protocol (specific to @value{GDBN},
c906108c
SS
9899but not specific to any particular target system) which you can use if you
9900write the remote stubs---the code that runs on the remote system to
9901communicate with @value{GDBN}.
9902
9903Other remote targets may be available in your
9904configuration of @value{GDBN}; use @code{help target} to list them.
c906108c 9905
6f05cf9f
AC
9906@node KOD
9907@section Kernel Object Display
9908
9909@cindex kernel object display
9910@cindex kernel object
9911@cindex KOD
9912
9913Some targets support kernel object display. Using this facility,
9914@value{GDBN} communicates specially with the underlying operating system
9915and can display information about operating system-level objects such as
9916mutexes and other synchronization objects. Exactly which objects can be
9917displayed is determined on a per-OS basis.
9918
9919Use the @code{set os} command to set the operating system. This tells
9920@value{GDBN} which kernel object display module to initialize:
9921
9922@example
9923(@value{GDBP}) set os cisco
9924@end example
9925
9926If @code{set os} succeeds, @value{GDBN} will display some information
9927about the operating system, and will create a new @code{info} command
9928which can be used to query the target. The @code{info} command is named
9929after the operating system:
c906108c 9930
6f05cf9f
AC
9931@example
9932(@value{GDBP}) info cisco
9933List of Cisco Kernel Objects
9934Object Description
9935any Any and all objects
9936@end example
9937
9938Further subcommands can be used to query about particular objects known
9939by the kernel.
9940
9941There is currently no way to determine whether a given operating system
9942is supported other than to try it.
9943
9944
9945@node Remote Debugging
9946@chapter Debugging remote programs
9947
6b2f586d
AC
9948@menu
9949* Server:: Using the gdbserver program
9950* NetWare:: Using the gdbserve.nlm program
9951* remote stub:: Implementing a remote stub
9952* Protocol:: Communication protocol
9953@end menu
9954
6f05cf9f
AC
9955@node Server
9956@section Using the @code{gdbserver} program
9957
9958@kindex gdbserver
9959@cindex remote connection without stubs
9960@code{gdbserver} is a control program for Unix-like systems, which
9961allows you to connect your program with a remote @value{GDBN} via
9962@code{target remote}---but without linking in the usual debugging stub.
9963
9964@code{gdbserver} is not a complete replacement for the debugging stubs,
9965because it requires essentially the same operating-system facilities
9966that @value{GDBN} itself does. In fact, a system that can run
9967@code{gdbserver} to connect to a remote @value{GDBN} could also run
9968@value{GDBN} locally! @code{gdbserver} is sometimes useful nevertheless,
9969because it is a much smaller program than @value{GDBN} itself. It is
9970also easier to port than all of @value{GDBN}, so you may be able to get
9971started more quickly on a new system by using @code{gdbserver}.
9972Finally, if you develop code for real-time systems, you may find that
9973the tradeoffs involved in real-time operation make it more convenient to
9974do as much development work as possible on another system, for example
9975by cross-compiling. You can use @code{gdbserver} to make a similar
9976choice for debugging.
9977
9978@value{GDBN} and @code{gdbserver} communicate via either a serial line
9979or a TCP connection, using the standard @value{GDBN} remote serial
9980protocol.
9981
9982@table @emph
9983@item On the target machine,
9984you need to have a copy of the program you want to debug.
9985@code{gdbserver} does not need your program's symbol table, so you can
9986strip the program if necessary to save space. @value{GDBN} on the host
9987system does all the symbol handling.
9988
9989To use the server, you must tell it how to communicate with @value{GDBN};
9990the name of your program; and the arguments for your program. The
9991syntax is:
9992
9993@smallexample
9994target> gdbserver @var{comm} @var{program} [ @var{args} @dots{} ]
9995@end smallexample
9996
9997@var{comm} is either a device name (to use a serial line) or a TCP
9998hostname and portnumber. For example, to debug Emacs with the argument
9999@samp{foo.txt} and communicate with @value{GDBN} over the serial port
10000@file{/dev/com1}:
10001
10002@smallexample
10003target> gdbserver /dev/com1 emacs foo.txt
10004@end smallexample
10005
10006@code{gdbserver} waits passively for the host @value{GDBN} to communicate
10007with it.
10008
10009To use a TCP connection instead of a serial line:
10010
10011@smallexample
10012target> gdbserver host:2345 emacs foo.txt
10013@end smallexample
10014
10015The only difference from the previous example is the first argument,
10016specifying that you are communicating with the host @value{GDBN} via
10017TCP. The @samp{host:2345} argument means that @code{gdbserver} is to
10018expect a TCP connection from machine @samp{host} to local TCP port 2345.
10019(Currently, the @samp{host} part is ignored.) You can choose any number
10020you want for the port number as long as it does not conflict with any
10021TCP ports already in use on the target system (for example, @code{23} is
10022reserved for @code{telnet}).@footnote{If you choose a port number that
10023conflicts with another service, @code{gdbserver} prints an error message
10024and exits.} You must use the same port number with the host @value{GDBN}
10025@code{target remote} command.
10026
10027@item On the @value{GDBN} host machine,
10028you need an unstripped copy of your program, since @value{GDBN} needs
10029symbols and debugging information. Start up @value{GDBN} as usual,
10030using the name of the local copy of your program as the first argument.
10031(You may also need the @w{@samp{--baud}} option if the serial line is
10032running at anything other than 9600@dmn{bps}.) After that, use @code{target
10033remote} to establish communications with @code{gdbserver}. Its argument
10034is either a device name (usually a serial device, like
10035@file{/dev/ttyb}), or a TCP port descriptor in the form
10036@code{@var{host}:@var{PORT}}. For example:
10037
10038@smallexample
10039(@value{GDBP}) target remote /dev/ttyb
10040@end smallexample
10041
10042@noindent
10043communicates with the server via serial line @file{/dev/ttyb}, and
10044
10045@smallexample
10046(@value{GDBP}) target remote the-target:2345
10047@end smallexample
10048
10049@noindent
10050communicates via a TCP connection to port 2345 on host @w{@file{the-target}}.
10051For TCP connections, you must start up @code{gdbserver} prior to using
10052the @code{target remote} command. Otherwise you may get an error whose
10053text depends on the host system, but which usually looks something like
10054@samp{Connection refused}.
10055@end table
10056
10057@node NetWare
10058@section Using the @code{gdbserve.nlm} program
10059
10060@kindex gdbserve.nlm
10061@code{gdbserve.nlm} is a control program for NetWare systems, which
10062allows you to connect your program with a remote @value{GDBN} via
10063@code{target remote}.
10064
10065@value{GDBN} and @code{gdbserve.nlm} communicate via a serial line,
10066using the standard @value{GDBN} remote serial protocol.
10067
10068@table @emph
10069@item On the target machine,
10070you need to have a copy of the program you want to debug.
10071@code{gdbserve.nlm} does not need your program's symbol table, so you
10072can strip the program if necessary to save space. @value{GDBN} on the
10073host system does all the symbol handling.
10074
10075To use the server, you must tell it how to communicate with
10076@value{GDBN}; the name of your program; and the arguments for your
10077program. The syntax is:
10078
10079@smallexample
10080load gdbserve [ BOARD=@var{board} ] [ PORT=@var{port} ]
10081 [ BAUD=@var{baud} ] @var{program} [ @var{args} @dots{} ]
10082@end smallexample
10083
10084@var{board} and @var{port} specify the serial line; @var{baud} specifies
10085the baud rate used by the connection. @var{port} and @var{node} default
10086to 0, @var{baud} defaults to 9600@dmn{bps}.
10087
10088For example, to debug Emacs with the argument @samp{foo.txt}and
10089communicate with @value{GDBN} over serial port number 2 or board 1
10090using a 19200@dmn{bps} connection:
10091
10092@smallexample
10093load gdbserve BOARD=1 PORT=2 BAUD=19200 emacs foo.txt
10094@end smallexample
10095
10096@item On the @value{GDBN} host machine,
10097you need an unstripped copy of your program, since @value{GDBN} needs
10098symbols and debugging information. Start up @value{GDBN} as usual,
10099using the name of the local copy of your program as the first argument.
10100(You may also need the @w{@samp{--baud}} option if the serial line is
10101running at anything other than 9600@dmn{bps}. After that, use @code{target
10102remote} to establish communications with @code{gdbserve.nlm}. Its
10103argument is a device name (usually a serial device, like
10104@file{/dev/ttyb}). For example:
10105
10106@smallexample
10107(@value{GDBP}) target remote /dev/ttyb
10108@end smallexample
10109
10110@noindent
10111communications with the server via serial line @file{/dev/ttyb}.
10112@end table
10113
10114@node remote stub
10115@section Implementing a remote stub
7a292a7a 10116
104c1213
JM
10117@cindex remote serial debugging, overview
10118To debug a program running on another machine (the debugging
10119@dfn{target} machine), you must first arrange for all the usual
10120prerequisites for the program to run by itself. For example, for a C
10121program, you need:
c906108c 10122
104c1213
JM
10123@enumerate
10124@item
10125A startup routine to set up the C runtime environment; these usually
10126have a name like @file{crt0}. The startup routine may be supplied by
10127your hardware supplier, or you may have to write your own.
96baa820 10128
5d161b24 10129@item
d4f3574e 10130A C subroutine library to support your program's
104c1213 10131subroutine calls, notably managing input and output.
96baa820 10132
104c1213
JM
10133@item
10134A way of getting your program to the other machine---for example, a
10135download program. These are often supplied by the hardware
10136manufacturer, but you may have to write your own from hardware
10137documentation.
10138@end enumerate
96baa820 10139
104c1213
JM
10140The next step is to arrange for your program to use a serial port to
10141communicate with the machine where @value{GDBN} is running (the @dfn{host}
10142machine). In general terms, the scheme looks like this:
96baa820 10143
104c1213
JM
10144@table @emph
10145@item On the host,
10146@value{GDBN} already understands how to use this protocol; when everything
10147else is set up, you can simply use the @samp{target remote} command
10148(@pxref{Targets,,Specifying a Debugging Target}).
10149
10150@item On the target,
10151you must link with your program a few special-purpose subroutines that
10152implement the @value{GDBN} remote serial protocol. The file containing these
10153subroutines is called a @dfn{debugging stub}.
10154
10155On certain remote targets, you can use an auxiliary program
10156@code{gdbserver} instead of linking a stub into your program.
10157@xref{Server,,Using the @code{gdbserver} program}, for details.
10158@end table
96baa820 10159
104c1213
JM
10160The debugging stub is specific to the architecture of the remote
10161machine; for example, use @file{sparc-stub.c} to debug programs on
10162@sc{sparc} boards.
96baa820 10163
104c1213
JM
10164@cindex remote serial stub list
10165These working remote stubs are distributed with @value{GDBN}:
96baa820 10166
104c1213
JM
10167@table @code
10168
10169@item i386-stub.c
41afff9a 10170@cindex @file{i386-stub.c}
104c1213
JM
10171@cindex Intel
10172@cindex i386
10173For Intel 386 and compatible architectures.
10174
10175@item m68k-stub.c
41afff9a 10176@cindex @file{m68k-stub.c}
104c1213
JM
10177@cindex Motorola 680x0
10178@cindex m680x0
10179For Motorola 680x0 architectures.
10180
10181@item sh-stub.c
41afff9a 10182@cindex @file{sh-stub.c}
104c1213
JM
10183@cindex Hitachi
10184@cindex SH
10185For Hitachi SH architectures.
10186
10187@item sparc-stub.c
41afff9a 10188@cindex @file{sparc-stub.c}
104c1213
JM
10189@cindex Sparc
10190For @sc{sparc} architectures.
10191
10192@item sparcl-stub.c
41afff9a 10193@cindex @file{sparcl-stub.c}
104c1213
JM
10194@cindex Fujitsu
10195@cindex SparcLite
10196For Fujitsu @sc{sparclite} architectures.
10197
10198@end table
10199
10200The @file{README} file in the @value{GDBN} distribution may list other
10201recently added stubs.
10202
10203@menu
10204* Stub Contents:: What the stub can do for you
10205* Bootstrapping:: What you must do for the stub
10206* Debug Session:: Putting it all together
104c1213
JM
10207@end menu
10208
6d2ebf8b 10209@node Stub Contents
6f05cf9f 10210@subsection What the stub can do for you
104c1213
JM
10211
10212@cindex remote serial stub
10213The debugging stub for your architecture supplies these three
10214subroutines:
10215
10216@table @code
10217@item set_debug_traps
10218@kindex set_debug_traps
10219@cindex remote serial stub, initialization
10220This routine arranges for @code{handle_exception} to run when your
10221program stops. You must call this subroutine explicitly near the
10222beginning of your program.
10223
10224@item handle_exception
10225@kindex handle_exception
10226@cindex remote serial stub, main routine
10227This is the central workhorse, but your program never calls it
10228explicitly---the setup code arranges for @code{handle_exception} to
10229run when a trap is triggered.
10230
10231@code{handle_exception} takes control when your program stops during
10232execution (for example, on a breakpoint), and mediates communications
10233with @value{GDBN} on the host machine. This is where the communications
10234protocol is implemented; @code{handle_exception} acts as the @value{GDBN}
d4f3574e 10235representative on the target machine. It begins by sending summary
104c1213
JM
10236information on the state of your program, then continues to execute,
10237retrieving and transmitting any information @value{GDBN} needs, until you
10238execute a @value{GDBN} command that makes your program resume; at that point,
10239@code{handle_exception} returns control to your own code on the target
5d161b24 10240machine.
104c1213
JM
10241
10242@item breakpoint
10243@cindex @code{breakpoint} subroutine, remote
10244Use this auxiliary subroutine to make your program contain a
10245breakpoint. Depending on the particular situation, this may be the only
10246way for @value{GDBN} to get control. For instance, if your target
10247machine has some sort of interrupt button, you won't need to call this;
10248pressing the interrupt button transfers control to
10249@code{handle_exception}---in effect, to @value{GDBN}. On some machines,
10250simply receiving characters on the serial port may also trigger a trap;
10251again, in that situation, you don't need to call @code{breakpoint} from
10252your own program---simply running @samp{target remote} from the host
5d161b24 10253@value{GDBN} session gets control.
104c1213
JM
10254
10255Call @code{breakpoint} if none of these is true, or if you simply want
10256to make certain your program stops at a predetermined point for the
10257start of your debugging session.
10258@end table
10259
6d2ebf8b 10260@node Bootstrapping
6f05cf9f 10261@subsection What you must do for the stub
104c1213
JM
10262
10263@cindex remote stub, support routines
10264The debugging stubs that come with @value{GDBN} are set up for a particular
10265chip architecture, but they have no information about the rest of your
10266debugging target machine.
10267
10268First of all you need to tell the stub how to communicate with the
10269serial port.
10270
10271@table @code
10272@item int getDebugChar()
10273@kindex getDebugChar
10274Write this subroutine to read a single character from the serial port.
10275It may be identical to @code{getchar} for your target system; a
10276different name is used to allow you to distinguish the two if you wish.
10277
10278@item void putDebugChar(int)
10279@kindex putDebugChar
10280Write this subroutine to write a single character to the serial port.
5d161b24 10281It may be identical to @code{putchar} for your target system; a
104c1213
JM
10282different name is used to allow you to distinguish the two if you wish.
10283@end table
10284
10285@cindex control C, and remote debugging
10286@cindex interrupting remote targets
10287If you want @value{GDBN} to be able to stop your program while it is
10288running, you need to use an interrupt-driven serial driver, and arrange
10289for it to stop when it receives a @code{^C} (@samp{\003}, the control-C
10290character). That is the character which @value{GDBN} uses to tell the
10291remote system to stop.
10292
10293Getting the debugging target to return the proper status to @value{GDBN}
10294probably requires changes to the standard stub; one quick and dirty way
10295is to just execute a breakpoint instruction (the ``dirty'' part is that
10296@value{GDBN} reports a @code{SIGTRAP} instead of a @code{SIGINT}).
10297
10298Other routines you need to supply are:
10299
10300@table @code
10301@item void exceptionHandler (int @var{exception_number}, void *@var{exception_address})
10302@kindex exceptionHandler
10303Write this function to install @var{exception_address} in the exception
10304handling tables. You need to do this because the stub does not have any
10305way of knowing what the exception handling tables on your target system
10306are like (for example, the processor's table might be in @sc{rom},
10307containing entries which point to a table in @sc{ram}).
10308@var{exception_number} is the exception number which should be changed;
10309its meaning is architecture-dependent (for example, different numbers
10310might represent divide by zero, misaligned access, etc). When this
10311exception occurs, control should be transferred directly to
10312@var{exception_address}, and the processor state (stack, registers,
10313and so on) should be just as it is when a processor exception occurs. So if
10314you want to use a jump instruction to reach @var{exception_address}, it
10315should be a simple jump, not a jump to subroutine.
10316
10317For the 386, @var{exception_address} should be installed as an interrupt
10318gate so that interrupts are masked while the handler runs. The gate
10319should be at privilege level 0 (the most privileged level). The
10320@sc{sparc} and 68k stubs are able to mask interrupts themselves without
10321help from @code{exceptionHandler}.
10322
10323@item void flush_i_cache()
10324@kindex flush_i_cache
d4f3574e 10325On @sc{sparc} and @sc{sparclite} only, write this subroutine to flush the
104c1213
JM
10326instruction cache, if any, on your target machine. If there is no
10327instruction cache, this subroutine may be a no-op.
10328
10329On target machines that have instruction caches, @value{GDBN} requires this
10330function to make certain that the state of your program is stable.
10331@end table
10332
10333@noindent
10334You must also make sure this library routine is available:
10335
10336@table @code
10337@item void *memset(void *, int, int)
10338@kindex memset
10339This is the standard library function @code{memset} that sets an area of
10340memory to a known value. If you have one of the free versions of
10341@code{libc.a}, @code{memset} can be found there; otherwise, you must
10342either obtain it from your hardware manufacturer, or write your own.
10343@end table
10344
10345If you do not use the GNU C compiler, you may need other standard
10346library subroutines as well; this varies from one stub to another,
10347but in general the stubs are likely to use any of the common library
d4f3574e 10348subroutines which @code{@value{GCC}} generates as inline code.
104c1213
JM
10349
10350
6d2ebf8b 10351@node Debug Session
6f05cf9f 10352@subsection Putting it all together
104c1213
JM
10353
10354@cindex remote serial debugging summary
10355In summary, when your program is ready to debug, you must follow these
10356steps.
10357
10358@enumerate
10359@item
6d2ebf8b 10360Make sure you have defined the supporting low-level routines
104c1213
JM
10361(@pxref{Bootstrapping,,What you must do for the stub}):
10362@display
10363@code{getDebugChar}, @code{putDebugChar},
10364@code{flush_i_cache}, @code{memset}, @code{exceptionHandler}.
10365@end display
10366
10367@item
10368Insert these lines near the top of your program:
10369
10370@example
10371set_debug_traps();
10372breakpoint();
10373@end example
10374
10375@item
10376For the 680x0 stub only, you need to provide a variable called
10377@code{exceptionHook}. Normally you just use:
10378
10379@example
10380void (*exceptionHook)() = 0;
10381@end example
10382
d4f3574e 10383@noindent
104c1213 10384but if before calling @code{set_debug_traps}, you set it to point to a
598ca718 10385function in your program, that function is called when
104c1213
JM
10386@code{@value{GDBN}} continues after stopping on a trap (for example, bus
10387error). The function indicated by @code{exceptionHook} is called with
10388one parameter: an @code{int} which is the exception number.
10389
10390@item
10391Compile and link together: your program, the @value{GDBN} debugging stub for
10392your target architecture, and the supporting subroutines.
10393
10394@item
10395Make sure you have a serial connection between your target machine and
10396the @value{GDBN} host, and identify the serial port on the host.
10397
10398@item
10399@c The "remote" target now provides a `load' command, so we should
10400@c document that. FIXME.
10401Download your program to your target machine (or get it there by
10402whatever means the manufacturer provides), and start it.
10403
10404@item
10405To start remote debugging, run @value{GDBN} on the host machine, and specify
10406as an executable file the program that is running in the remote machine.
10407This tells @value{GDBN} how to find your program's symbols and the contents
10408of its pure text.
10409
d4f3574e 10410@item
104c1213 10411@cindex serial line, @code{target remote}
d4f3574e 10412Establish communication using the @code{target remote} command.
104c1213
JM
10413Its argument specifies how to communicate with the target
10414machine---either via a devicename attached to a direct serial line, or a
10415TCP port (usually to a terminal server which in turn has a serial line
10416to the target). For example, to use a serial line connected to the
10417device named @file{/dev/ttyb}:
10418
10419@example
10420target remote /dev/ttyb
10421@end example
10422
10423@cindex TCP port, @code{target remote}
10424To use a TCP connection, use an argument of the form
10425@code{@var{host}:port}. For example, to connect to port 2828 on a
10426terminal server named @code{manyfarms}:
10427
10428@example
10429target remote manyfarms:2828
10430@end example
a2bea4c3
CV
10431
10432If your remote target is actually running on the same machine as
10433your debugger session (e.g.@: a simulator of your target running on
10434the same host), you can omit the hostname. For example, to connect
10435to port 1234 on your local machine:
10436
10437@example
10438target remote :1234
10439@end example
10440@noindent
10441
10442Note that the colon is still required here.
104c1213
JM
10443@end enumerate
10444
10445Now you can use all the usual commands to examine and change data and to
10446step and continue the remote program.
10447
10448To resume the remote program and stop debugging it, use the @code{detach}
10449command.
10450
10451@cindex interrupting remote programs
10452@cindex remote programs, interrupting
10453Whenever @value{GDBN} is waiting for the remote program, if you type the
10454interrupt character (often @key{C-C}), @value{GDBN} attempts to stop the
10455program. This may or may not succeed, depending in part on the hardware
10456and the serial drivers the remote system uses. If you type the
10457interrupt character once again, @value{GDBN} displays this prompt:
10458
10459@example
10460Interrupted while waiting for the program.
10461Give up (and stop debugging it)? (y or n)
10462@end example
10463
10464If you type @kbd{y}, @value{GDBN} abandons the remote debugging session.
10465(If you decide you want to try again later, you can use @samp{target
10466remote} again to connect once more.) If you type @kbd{n}, @value{GDBN}
10467goes back to waiting.
10468
6d2ebf8b 10469@node Protocol
6f05cf9f 10470@section Communication protocol
104c1213
JM
10471
10472@cindex debugging stub, example
10473@cindex remote stub, example
10474@cindex stub example, remote debugging
10475The stub files provided with @value{GDBN} implement the target side of the
10476communication protocol, and the @value{GDBN} side is implemented in the
10477@value{GDBN} source file @file{remote.c}. Normally, you can simply allow
10478these subroutines to communicate, and ignore the details. (If you're
10479implementing your own stub file, you can still ignore the details: start
10480with one of the existing stub files. @file{sparc-stub.c} is the best
10481organized, and therefore the easiest to read.)
10482
10483However, there may be occasions when you need to know something about
10484the protocol---for example, if there is only one serial port to your
10485target machine, you might want your program to do something special if
10486it recognizes a packet meant for @value{GDBN}.
10487
10488In the examples below, @samp{<-} and @samp{->} are used to indicate
10489transmitted and received data respectfully.
10490
10491@cindex protocol, @value{GDBN} remote serial
10492@cindex serial protocol, @value{GDBN} remote
10493@cindex remote serial protocol
6cf7e474
AC
10494All @value{GDBN} commands and responses (other than acknowledgments) are
10495sent as a @var{packet}. A @var{packet} is introduced with the character
10496@samp{$}, the actual @var{packet-data}, and the terminating character
10497@samp{#} followed by a two-digit @var{checksum}:
104c1213
JM
10498
10499@example
10500@code{$}@var{packet-data}@code{#}@var{checksum}
10501@end example
10502@noindent
104c1213
JM
10503
10504@cindex checksum, for @value{GDBN} remote
10505@noindent
10506The two-digit @var{checksum} is computed as the modulo 256 sum of all
6cf7e474
AC
10507characters between the leading @samp{$} and the trailing @samp{#} (an
10508eight bit unsigned checksum).
10509
10510Implementors should note that prior to @value{GDBN} 5.0 the protocol
10511specification also included an optional two-digit @var{sequence-id}:
10512
10513@example
10514@code{$}@var{sequence-id}@code{:}@var{packet-data}@code{#}@var{checksum}
10515@end example
104c1213
JM
10516
10517@cindex sequence-id, for @value{GDBN} remote
10518@noindent
6cf7e474
AC
10519That @var{sequence-id} was appended to the acknowledgment. @value{GDBN}
10520has never output @var{sequence-id}s. Stubs that handle packets added
10521since @value{GDBN} 5.0 must not accept @var{sequence-id}.
104c1213 10522
6cf7e474 10523@cindex acknowledgment, for @value{GDBN} remote
104c1213
JM
10524When either the host or the target machine receives a packet, the first
10525response expected is an acknowledgment: either @samp{+} (to indicate
10526the package was received correctly) or @samp{-} (to request
10527retransmission):
10528
10529@example
10530<- @code{$}@var{packet-data}@code{#}@var{checksum}
10531-> @code{+}
10532@end example
10533@noindent
104c1213
JM
10534
10535The host (@value{GDBN}) sends @var{command}s, and the target (the
10536debugging stub incorporated in your program) sends a @var{response}. In
10537the case of step and continue @var{command}s, the response is only sent
10538when the operation has completed (the target has again stopped).
10539
10540@var{packet-data} consists of a sequence of characters with the
6cf7e474
AC
10541exception of @samp{#} and @samp{$} (see @samp{X} packet for additional
10542exceptions).
10543
10544Fields within the packet should be separated using @samp{,} @samp{;} or
10545@samp{:}. Except where otherwise noted all numbers are represented in
10546HEX with leading zeros suppressed.
10547
10548Implementors should note that prior to @value{GDBN} 5.0, the character
10549@samp{:} could not appear as the third character in a packet (as it
10550would potentially conflict with the @var{sequence-id}).
104c1213
JM
10551
10552Response @var{data} can be run-length encoded to save space. A @samp{*}
c3f6f71d 10553means that the next character is an @sc{ascii} encoding giving a repeat count
104c1213
JM
10554which stands for that many repetitions of the character preceding the
10555@samp{*}. The encoding is @code{n+29}, yielding a printable character
d4f3574e
SS
10556where @code{n >=3} (which is where rle starts to win). The printable
10557characters @samp{$}, @samp{#}, @samp{+} and @samp{-} or with a numeric
10558value greater than 126 should not be used.
10559
10560Some remote systems have used a different run-length encoding mechanism
10561loosely refered to as the cisco encoding. Following the @samp{*}
10562character are two hex digits that indicate the size of the packet.
104c1213
JM
10563
10564So:
10565@example
10566"@code{0* }"
10567@end example
10568@noindent
10569means the same as "0000".
10570
598ca718 10571The error response returned for some packets includes a two character
104c1213
JM
10572error number. That number is not well defined.
10573
10574For any @var{command} not supported by the stub, an empty response
10575(@samp{$#00}) should be returned. That way it is possible to extend the
10576protocol. A newer @value{GDBN} can tell if a packet is supported based
d4f3574e 10577on that response.
104c1213 10578
f1251bdd
C
10579A stub is required to support the @samp{g}, @samp{G}, @samp{m}, @samp{M},
10580@samp{c}, and @samp{s} @var{command}s. All other @var{command}s are
10581optional.
10582
104c1213
JM
10583Below is a complete list of all currently defined @var{command}s and
10584their corresponding response @var{data}:
598ca718 10585@page
104c1213
JM
10586@multitable @columnfractions .30 .30 .40
10587@item Packet
10588@tab Request
10589@tab Description
10590
df2396a1 10591@item extended mode
104c1213
JM
10592@tab @code{!}
10593@tab
df2396a1 10594Enable extended mode. In extended mode, the remote server is made
656db9b0 10595persistent. The @samp{R} packet is used to restart the program being
df2396a1 10596debugged.
104c1213 10597@item
df2396a1 10598@tab reply @samp{OK}
104c1213 10599@tab
df2396a1 10600The remote target both supports and has enabled extended mode.
104c1213
JM
10601
10602@item last signal
10603@tab @code{?}
10604@tab
d4f3574e
SS
10605Indicate the reason the target halted. The reply is the same as for step
10606and continue.
10607@item
10608@tab reply
10609@tab see below
10610
104c1213
JM
10611
10612@item reserved
10613@tab @code{a}
5d161b24 10614@tab Reserved for future use
104c1213 10615
f1251bdd 10616@item set program arguments @strong{(reserved)}
104c1213
JM
10617@tab @code{A}@var{arglen}@code{,}@var{argnum}@code{,}@var{arg}@code{,...}
10618@tab
598ca718
EZ
10619@item
10620@tab
10621@tab
104c1213
JM
10622Initialized @samp{argv[]} array passed into program. @var{arglen}
10623specifies the number of bytes in the hex encoded byte stream @var{arg}.
d4f3574e 10624See @file{gdbserver} for more details.
104c1213
JM
10625@item
10626@tab reply @code{OK}
10627@item
10628@tab reply @code{E}@var{NN}
10629
10630@item set baud @strong{(deprecated)}
10631@tab @code{b}@var{baud}
10632@tab
10633Change the serial line speed to @var{baud}. JTC: @emph{When does the
10634transport layer state change? When it's received, or after the ACK is
10635transmitted. In either case, there are problems if the command or the
10636acknowledgment packet is dropped.} Stan: @emph{If people really wanted
10637to add something like this, and get it working for the first time, they
10638ought to modify ser-unix.c to send some kind of out-of-band message to a
10639specially-setup stub and have the switch happen "in between" packets, so
10640that from remote protocol's point of view, nothing actually
10641happened.}
10642
10643@item set breakpoint @strong{(deprecated)}
10644@tab @code{B}@var{addr},@var{mode}
10645@tab
10646Set (@var{mode} is @samp{S}) or clear (@var{mode} is @samp{C}) a
10647breakpoint at @var{addr}. @emph{This has been replaced by the @samp{Z} and
10648@samp{z} packets.}
10649
10650@item continue
10651@tab @code{c}@var{addr}
10652@tab
10653@var{addr} is address to resume. If @var{addr} is omitted, resume at
10654current address.
10655@item
10656@tab reply
10657@tab see below
10658
f1251bdd 10659@item continue with signal
104c1213
JM
10660@tab @code{C}@var{sig}@code{;}@var{addr}
10661@tab
10662Continue with signal @var{sig} (hex signal number). If
10663@code{;}@var{addr} is omitted, resume at same address.
10664@item
10665@tab reply
10666@tab see below
10667
598ca718 10668@item toggle debug @strong{(deprecated)}
104c1213
JM
10669@tab @code{d}
10670@tab
d4f3574e 10671toggle debug flag.
104c1213 10672
f1251bdd 10673@item detach
104c1213 10674@tab @code{D}
d4f3574e 10675@tab
2df3850c
JM
10676Detach @value{GDBN} from the remote system. Sent to the remote target before
10677@value{GDBN} disconnects.
d4f3574e
SS
10678@item
10679@tab reply @emph{no response}
10680@tab
598ca718 10681@value{GDBN} does not check for any response after sending this packet.
104c1213
JM
10682
10683@item reserved
10684@tab @code{e}
5d161b24 10685@tab Reserved for future use
104c1213
JM
10686
10687@item reserved
10688@tab @code{E}
5d161b24 10689@tab Reserved for future use
104c1213
JM
10690
10691@item reserved
10692@tab @code{f}
5d161b24 10693@tab Reserved for future use
104c1213
JM
10694
10695@item reserved
10696@tab @code{F}
5d161b24 10697@tab Reserved for future use
104c1213
JM
10698
10699@item read registers
10700@tab @code{g}
10701@tab Read general registers.
10702@item
10703@tab reply @var{XX...}
10704@tab
10705Each byte of register data is described by two hex digits. The bytes
10706with the register are transmitted in target byte order. The size of
d4f3574e 10707each register and their position within the @samp{g} @var{packet} are
2df3850c 10708determined by the @value{GDBN} internal macros @var{REGISTER_RAW_SIZE} and
d4f3574e
SS
10709@var{REGISTER_NAME} macros. The specification of several standard
10710@code{g} packets is specified below.
104c1213
JM
10711@item
10712@tab @code{E}@var{NN}
10713@tab for an error.
10714
10715@item write regs
10716@tab @code{G}@var{XX...}
10717@tab
10718See @samp{g} for a description of the @var{XX...} data.
10719@item
10720@tab reply @code{OK}
10721@tab for success
10722@item
10723@tab reply @code{E}@var{NN}
10724@tab for an error
10725
10726@item reserved
10727@tab @code{h}
5d161b24 10728@tab Reserved for future use
104c1213 10729
f1251bdd 10730@item set thread
104c1213
JM
10731@tab @code{H}@var{c}@var{t...}
10732@tab
d4f3574e
SS
10733Set thread for subsequent operations (@samp{m}, @samp{M}, @samp{g},
10734@samp{G}, et.al.). @var{c} = @samp{c} for thread used in step and
10735continue; @var{t...} can be -1 for all threads. @var{c} = @samp{g} for
10736thread used in other operations. If zero, pick a thread, any thread.
104c1213
JM
10737@item
10738@tab reply @code{OK}
10739@tab for success
10740@item
10741@tab reply @code{E}@var{NN}
10742@tab for an error
10743
d4f3574e
SS
10744@c FIXME: JTC:
10745@c 'H': How restrictive (or permissive) is the thread model. If a
5d161b24 10746@c thread is selected and stopped, are other threads allowed
d4f3574e
SS
10747@c to continue to execute? As I mentioned above, I think the
10748@c semantics of each command when a thread is selected must be
10749@c described. For example:
10750@c
10751@c 'g': If the stub supports threads and a specific thread is
10752@c selected, returns the register block from that thread;
10753@c otherwise returns current registers.
10754@c
10755@c 'G' If the stub supports threads and a specific thread is
10756@c selected, sets the registers of the register block of
10757@c that thread; otherwise sets current registers.
10758
f1251bdd 10759@item cycle step @strong{(draft)}
104c1213
JM
10760@tab @code{i}@var{addr}@code{,}@var{nnn}
10761@tab
10762Step the remote target by a single clock cycle. If @code{,}@var{nnn} is
10763present, cycle step @var{nnn} cycles. If @var{addr} is present, cycle
10764step starting at that address.
10765
f1251bdd 10766@item signal then cycle step @strong{(reserved)}
104c1213
JM
10767@tab @code{I}
10768@tab
10769See @samp{i} and @samp{S} for likely syntax and semantics.
10770
10771@item reserved
10772@tab @code{j}
10773@tab Reserved for future use
10774
10775@item reserved
10776@tab @code{J}
5d161b24 10777@tab Reserved for future use
104c1213 10778
f1251bdd 10779@item kill request
104c1213
JM
10780@tab @code{k}
10781@tab
d4f3574e
SS
10782FIXME: @emph{There is no description of how operate when a specific
10783thread context has been selected (ie. does 'k' kill only that thread?)}.
104c1213
JM
10784
10785@item reserved
10786@tab @code{l}
5d161b24 10787@tab Reserved for future use
104c1213
JM
10788
10789@item reserved
10790@tab @code{L}
5d161b24 10791@tab Reserved for future use
104c1213
JM
10792
10793@item read memory
10794@tab @code{m}@var{addr}@code{,}@var{length}
10795@tab
10796Read @var{length} bytes of memory starting at address @var{addr}.
2df3850c 10797Neither @value{GDBN} nor the stub assume that sized memory transfers are assumed
d4f3574e
SS
10798using word alligned accesses. FIXME: @emph{A word aligned memory
10799transfer mechanism is needed.}
104c1213
JM
10800@item
10801@tab reply @var{XX...}
10802@tab
d4f3574e 10803@var{XX...} is mem contents. Can be fewer bytes than requested if able
2df3850c 10804to read only part of the data. Neither @value{GDBN} nor the stub assume that
d4f3574e
SS
10805sized memory transfers are assumed using word alligned accesses. FIXME:
10806@emph{A word aligned memory transfer mechanism is needed.}
104c1213
JM
10807@item
10808@tab reply @code{E}@var{NN}
10809@tab @var{NN} is errno
10810
10811@item write mem
10812@tab @code{M}@var{addr},@var{length}@code{:}@var{XX...}
10813@tab
10814Write @var{length} bytes of memory starting at address @var{addr}.
10815@var{XX...} is the data.
10816@item
10817@tab reply @code{OK}
10818@tab for success
10819@item
10820@tab reply @code{E}@var{NN}
10821@tab
10822for an error (this includes the case where only part of the data was
10823written).
10824
10825@item reserved
10826@tab @code{n}
5d161b24 10827@tab Reserved for future use
104c1213
JM
10828
10829@item reserved
10830@tab @code{N}
5d161b24 10831@tab Reserved for future use
104c1213
JM
10832
10833@item reserved
10834@tab @code{o}
5d161b24 10835@tab Reserved for future use
104c1213
JM
10836
10837@item reserved
10838@tab @code{O}
5d161b24 10839@tab Reserved for future use
104c1213
JM
10840
10841@item read reg @strong{(reserved)}
10842@tab @code{p}@var{n...}
10843@tab
10844See write register.
10845@item
10846@tab return @var{r....}
10847@tab The hex encoded value of the register in target byte order.
10848
f1251bdd 10849@item write reg
104c1213
JM
10850@tab @code{P}@var{n...}@code{=}@var{r...}
10851@tab
10852Write register @var{n...} with value @var{r...}, which contains two hex
10853digits for each byte in the register (target byte order).
10854@item
10855@tab reply @code{OK}
10856@tab for success
10857@item
10858@tab reply @code{E}@var{NN}
10859@tab for an error
10860
f1251bdd 10861@item general query
104c1213
JM
10862@tab @code{q}@var{query}
10863@tab
598ca718 10864Request info about @var{query}. In general @value{GDBN} queries
104c1213 10865have a leading upper case letter. Custom vendor queries should use a
d4f3574e
SS
10866company prefix (in lower case) ex: @samp{qfsf.var}. @var{query} may
10867optionally be followed by a @samp{,} or @samp{;} separated list. Stubs
10868must ensure that they match the full @var{query} name.
104c1213
JM
10869@item
10870@tab reply @code{XX...}
d4f3574e 10871@tab Hex encoded data from query. The reply can not be empty.
104c1213
JM
10872@item
10873@tab reply @code{E}@var{NN}
10874@tab error reply
10875@item
10876@tab reply @samp{}
10877@tab Indicating an unrecognized @var{query}.
10878
f1251bdd 10879@item general set
104c1213
JM
10880@tab @code{Q}@var{var}@code{=}@var{val}
10881@tab
10882Set value of @var{var} to @var{val}. See @samp{q} for a discussing of
10883naming conventions.
10884
598ca718 10885@item reset @strong{(deprecated)}
d4f3574e
SS
10886@tab @code{r}
10887@tab
10888Reset the entire system.
104c1213 10889
f1251bdd 10890@item remote restart
104c1213
JM
10891@tab @code{R}@var{XX}
10892@tab
df2396a1
AC
10893Restart the program being debugged. @var{XX}, while needed, is ignored.
10894This packet is only available in extended mode.
10895@item
10896@tab
10897no reply
10898@tab
10899The @samp{R} packet has no reply.
104c1213 10900
f1251bdd 10901@item step
104c1213
JM
10902@tab @code{s}@var{addr}
10903@tab
10904@var{addr} is address to resume. If @var{addr} is omitted, resume at
10905same address.
10906@item
10907@tab reply
10908@tab see below
10909
f1251bdd 10910@item step with signal
104c1213
JM
10911@tab @code{S}@var{sig}@code{;}@var{addr}
10912@tab
10913Like @samp{C} but step not continue.
10914@item
10915@tab reply
10916@tab see below
10917
f1251bdd 10918@item search
104c1213
JM
10919@tab @code{t}@var{addr}@code{:}@var{PP}@code{,}@var{MM}
10920@tab
10921Search backwards starting at address @var{addr} for a match with pattern
10922@var{PP} and mask @var{MM}. @var{PP} and @var{MM} are 4
d4f3574e 10923bytes. @var{addr} must be at least 3 digits.
104c1213 10924
f1251bdd 10925@item thread alive
104c1213
JM
10926@tab @code{T}@var{XX}
10927@tab Find out if the thread XX is alive.
10928@item
10929@tab reply @code{OK}
10930@tab thread is still alive
10931@item
10932@tab reply @code{E}@var{NN}
10933@tab thread is dead
5d161b24 10934
104c1213
JM
10935@item reserved
10936@tab @code{u}
5d161b24 10937@tab Reserved for future use
104c1213
JM
10938
10939@item reserved
10940@tab @code{U}
5d161b24 10941@tab Reserved for future use
104c1213
JM
10942
10943@item reserved
10944@tab @code{v}
5d161b24 10945@tab Reserved for future use
104c1213
JM
10946
10947@item reserved
10948@tab @code{V}
5d161b24 10949@tab Reserved for future use
104c1213
JM
10950
10951@item reserved
10952@tab @code{w}
5d161b24 10953@tab Reserved for future use
104c1213
JM
10954
10955@item reserved
10956@tab @code{W}
5d161b24 10957@tab Reserved for future use
104c1213
JM
10958
10959@item reserved
10960@tab @code{x}
5d161b24 10961@tab Reserved for future use
104c1213 10962
f1251bdd 10963@item write mem (binary)
104c1213
JM
10964@tab @code{X}@var{addr}@code{,}@var{length}@var{:}@var{XX...}
10965@tab
10966@var{addr} is address, @var{length} is number of bytes, @var{XX...} is
d4f3574e
SS
10967binary data. The characters @code{$}, @code{#}, and @code{0x7d} are
10968escaped using @code{0x7d}.
104c1213
JM
10969@item
10970@tab reply @code{OK}
10971@tab for success
10972@item
10973@tab reply @code{E}@var{NN}
10974@tab for an error
10975
10976@item reserved
10977@tab @code{y}
5d161b24 10978@tab Reserved for future use
104c1213
JM
10979
10980@item reserved
10981@tab @code{Y}
5d161b24 10982@tab Reserved for future use
104c1213 10983
f1251bdd 10984@item remove break or watchpoint @strong{(draft)}
104c1213
JM
10985@tab @code{z}@var{t}@code{,}@var{addr}@code{,}@var{length}
10986@tab
10987See @samp{Z}.
10988
f1251bdd 10989@item insert break or watchpoint @strong{(draft)}
104c1213
JM
10990@tab @code{Z}@var{t}@code{,}@var{addr}@code{,}@var{length}
10991@tab
10992@var{t} is type: @samp{0} - software breakpoint, @samp{1} - hardware
10993breakpoint, @samp{2} - write watchpoint, @samp{3} - read watchpoint,
10994@samp{4} - access watchpoint; @var{addr} is address; @var{length} is in
10995bytes. For a software breakpoint, @var{length} specifies the size of
10996the instruction to be patched. For hardware breakpoints and watchpoints
d4f3574e
SS
10997@var{length} specifies the memory region to be monitored. To avoid
10998potential problems with duplicate packets, the operations should be
6d2ebf8b 10999implemented in an idempotent way.
104c1213
JM
11000@item
11001@tab reply @code{E}@var{NN}
11002@tab for an error
11003@item
11004@tab reply @code{OK}
11005@tab for success
11006@item
11007@tab @samp{}
11008@tab If not supported.
11009
11010@item reserved
11011@tab <other>
5d161b24 11012@tab Reserved for future use
104c1213
JM
11013
11014@end multitable
11015
d4f3574e
SS
11016The @samp{C}, @samp{c}, @samp{S}, @samp{s} and @samp{?} packets can
11017receive any of the below as a reply. In the case of the @samp{C},
11018@samp{c}, @samp{S} and @samp{s} packets, that reply is only returned
11019when the target halts. In the below the exact meaning of @samp{signal
11020number} is poorly defined. In general one of the UNIX signal numbering
11021conventions is used.
104c1213
JM
11022
11023@multitable @columnfractions .4 .6
11024
11025@item @code{S}@var{AA}
11026@tab @var{AA} is the signal number
11027
11028@item @code{T}@var{AA}@var{n...}@code{:}@var{r...}@code{;}@var{n...}@code{:}@var{r...}@code{;}@var{n...}@code{:}@var{r...}@code{;}
11029@tab
11030@var{AA} = two hex digit signal number; @var{n...} = register number
11031(hex), @var{r...} = target byte ordered register contents, size defined
11032by @code{REGISTER_RAW_SIZE}; @var{n...} = @samp{thread}, @var{r...} =
11033thread process ID, this is a hex integer; @var{n...} = other string not
d4f3574e 11034starting with valid hex digit. @value{GDBN} should ignore this
104c1213
JM
11035@var{n...}, @var{r...} pair and go on to the next. This way we can
11036extend the protocol.
11037
11038@item @code{W}@var{AA}
11039@tab
11040The process exited, and @var{AA} is the exit status. This is only
11041applicable for certains sorts of targets.
11042
11043@item @code{X}@var{AA}
11044@tab
11045The process terminated with signal @var{AA}.
11046
6d2ebf8b 11047@item @code{N}@var{AA}@code{;}@var{t...}@code{;}@var{d...}@code{;}@var{b...} @strong{(obsolete)}
104c1213 11048@tab
6d2ebf8b
SS
11049@var{AA} = signal number; @var{t...} = address of symbol "_start";
11050@var{d...} = base of data section; @var{b...} = base of bss section.
11051@emph{Note: only used by Cisco Systems targets. The difference between
11052this reply and the "qOffsets" query is that the 'N' packet may arrive
11053spontaneously whereas the 'qOffsets' is a query initiated by the host
11054debugger.}
104c1213
JM
11055
11056@item @code{O}@var{XX...}
11057@tab
c3f6f71d 11058@var{XX...} is hex encoding of @sc{ascii} data. This can happen at any time
104c1213
JM
11059while the program is running and the debugger should continue to wait
11060for 'W', 'T', etc.
11061
11062@end multitable
11063
d4f3574e
SS
11064The following set and query packets have already been defined.
11065
11066@multitable @columnfractions .2 .2 .6
11067
11068@item current thread
11069@tab @code{q}@code{C}
11070@tab Return the current thread id.
11071@item
11072@tab reply @code{QC}@var{pid}
11073@tab
11074Where @var{pid} is a HEX encoded 16 bit process id.
11075@item
11076@tab reply *
11077@tab Any other reply implies the old pid.
11078
bba2971c
MS
11079@item all thread ids
11080@tab @code{q}@code{fThreadInfo}
11081@item
11082@tab @code{q}@code{sThreadInfo}
d4f3574e 11083@tab
bba2971c
MS
11084Obtain a list of active thread ids from the target (OS). Since there
11085may be too many active threads to fit into one reply packet, this query
11086works iteratively: it may require more than one query/reply sequence to
11087obtain the entire list of threads. The first query of the sequence will
5d161b24 11088be the @code{qf}@code{ThreadInfo} query; subsequent queries in the
bba2971c 11089sequence will be the @code{qs}@code{ThreadInfo} query.
d4f3574e 11090@item
bba2971c
MS
11091@tab
11092@tab NOTE: replaces the @code{qL} query (see below).
d4f3574e 11093@item
5d161b24 11094@tab reply @code{m}@var{<id>}
bba2971c
MS
11095@tab A single thread id
11096@item
00e4a2e4 11097@tab reply @code{m}@var{<id>},@var{<id>...}
bba2971c
MS
11098@tab a comma-separated list of thread ids
11099@item
11100@tab reply @code{l}
11101@tab (lower case 'el') denotes end of list.
11102@item
11103@tab
11104@tab
11105In response to each query, the target will reply with a list of one
11106or more thread ids, in big-endian hex, separated by commas. GDB will
11107respond to each reply with a request for more thread ids (using the
11108@code{qs} form of the query), until the target responds with @code{l}
11109(lower-case el, for @code{'last'}).
11110
11111@item extra thread info
480ff1fb 11112@tab @code{q}@code{ThreadExtraInfo}@code{,}@var{id}
bba2971c
MS
11113@tab
11114@item
11115@tab
11116@tab
11117Where @var{<id>} is a thread-id in big-endian hex.
11118Obtain a printable string description of a thread's attributes from
11119the target OS. This string may contain anything that the target OS
11120thinks is interesting for @value{GDBN} to tell the user about the thread.
11121The string is displayed in @value{GDBN}'s @samp{info threads} display.
5d161b24 11122Some examples of possible thread extra info strings are "Runnable", or
bba2971c
MS
11123"Blocked on Mutex".
11124@item
11125@tab reply @var{XX...}
11126@tab
11127Where @var{XX...} is a hex encoding of @sc{ascii} data, comprising the
11128printable string containing the extra information about the thread's
11129attributes.
d4f3574e
SS
11130
11131@item query @var{LIST} or @var{threadLIST} @strong{(deprecated)}
11132@tab @code{q}@code{L}@var{startflag}@var{threadcount}@var{nextthread}
11133@tab
2b628194
MS
11134@item
11135@tab
11136@tab
d4f3574e
SS
11137Obtain thread information from RTOS. Where: @var{startflag} (one hex
11138digit) is one to indicate the first query and zero to indicate a
11139subsequent query; @var{threadcount} (two hex digits) is the maximum
11140number of threads the response packet can contain; and @var{nextthread}
11141(eight hex digits), for subsequent queries (@var{startflag} is zero), is
11142returned in the response as @var{argthread}.
11143@item
bba2971c
MS
11144@tab
11145@tab NOTE: this query is replaced by the @code{q}@code{fThreadInfo}
11146query (see above).
11147@item
d4f3574e
SS
11148@tab reply @code{q}@code{M}@var{count}@var{done}@var{argthread}@var{thread...}
11149@tab
2b628194
MS
11150@item
11151@tab
11152@tab
d4f3574e
SS
11153Where: @var{count} (two hex digits) is the number of threads being
11154returned; @var{done} (one hex digit) is zero to indicate more threads
11155and one indicates no further threads; @var{argthreadid} (eight hex
11156digits) is @var{nextthread} from the request packet; @var{thread...} is
11157a sequence of thread IDs from the target. @var{threadid} (eight hex
11158digits). See @code{remote.c:parse_threadlist_response()}.
11159
bba2971c
MS
11160@item compute CRC of memory block
11161@tab @code{q}@code{CRC:}@var{addr}@code{,}@var{length}
11162@tab
11163@item
11164@tab reply @code{E}@var{NN}
11165@tab An error (such as memory fault)
11166@item
11167@tab reply @code{C}@var{CRC32}
11168@tab A 32 bit cyclic redundancy check of the specified memory region.
11169
d4f3574e
SS
11170@item query sect offs
11171@tab @code{q}@code{Offsets}
917317f4
JM
11172@tab
11173Get section offsets that the target used when re-locating the downloaded
11174image. @emph{Note: while a @code{Bss} offset is included in the
11175response, @value{GDBN} ignores this and instead applies the @code{Data}
11176offset to the @code{Bss} section.}
d4f3574e
SS
11177@item
11178@tab reply @code{Text=}@var{xxx}@code{;Data=}@var{yyy}@code{;Bss=}@var{zzz}
11179
11180@item thread info request
11181@tab @code{q}@code{P}@var{mode}@var{threadid}
11182@tab
598ca718
EZ
11183@item
11184@tab
11185@tab
d4f3574e
SS
11186Returns information on @var{threadid}. Where: @var{mode} is a hex
11187encoded 32 bit mode; @var{threadid} is a hex encoded 64 bit thread ID.
11188@item
11189@tab reply *
11190@tab
11191See @code{remote.c:remote_unpack_thread_info_response()}.
11192
11193@item remote command
11194@tab @code{q}@code{Rcmd,}@var{COMMAND}
11195@tab
598ca718
EZ
11196@item
11197@tab
11198@tab
d4f3574e
SS
11199@var{COMMAND} (hex encoded) is passed to the local interpreter for
11200execution. Invalid commands should be reported using the output string.
11201Before the final result packet, the target may also respond with a
11202number of intermediate @code{O}@var{OUTPUT} console output
11203packets. @emph{Implementors should note that providing access to a
11204stubs's interpreter may have security implications}.
11205@item
11206@tab reply @code{OK}
11207@tab
11208A command response with no output.
11209@item
11210@tab reply @var{OUTPUT}
11211@tab
11212A command response with the hex encoded output string @var{OUTPUT}.
11213@item
11214@tab reply @code{E}@var{NN}
11215@tab
11216Indicate a badly formed request.
11217
11218@item
11219@tab reply @samp{}
11220@tab
11221When @samp{q}@samp{Rcmd} is not recognized.
11222
0f1f2b0a
MS
11223@item symbol lookup
11224@tab @code{qSymbol::}
11225@tab
11226Notify the target that @value{GDBN} is prepared to serve symbol lookup
11227requests. Accept requests from the target for the values of symbols.
11228@item
11229@tab
11230@tab
11231@item
11232@tab reply @code{OK}
11233@tab
11234The target does not need to look up any (more) symbols.
11235@item
11236@tab reply @code{qSymbol:}@var{sym_name}
11237@tab
6826cf00
EZ
11238@sp 2
11239@noindent
0f1f2b0a
MS
11240The target requests the value of symbol @var{sym_name} (hex encoded).
11241@value{GDBN} may provide the value by using the
11242@code{qSymbol:}@var{sym_value}:@var{sym_name}
11243message, described below.
11244
11245@item symbol value
11246@tab @code{qSymbol:}@var{sym_value}:@var{sym_name}
11247@tab
6826cf00
EZ
11248@sp 1
11249@noindent
0f1f2b0a
MS
11250Set the value of SYM_NAME to SYM_VALUE.
11251@item
11252@tab
11253@tab
11254@var{sym_name} (hex encoded) is the name of a symbol whose value
11255the target has previously requested.
11256@item
11257@tab
11258@tab
11259@var{sym_value} (hex) is the value for symbol @var{sym_name}.
11260If @value{GDBN} cannot supply a value for @var{sym_name}, then this
11261field will be empty.
11262@item
11263@tab reply @code{OK}
11264@tab
11265The target does not need to look up any (more) symbols.
11266@item
11267@tab reply @code{qSymbol:}@var{sym_name}
11268@tab
6826cf00
EZ
11269@sp 2
11270@noindent
0f1f2b0a
MS
11271The target requests the value of a new symbol @var{sym_name} (hex encoded).
11272@value{GDBN} will continue to supply the values of symbols (if available),
11273until the target ceases to request them.
11274
d4f3574e
SS
11275@end multitable
11276
11277The following @samp{g}/@samp{G} packets have previously been defined.
11278In the below, some thirty-two bit registers are transferred as sixty-four
11279bits. Those registers should be zero/sign extended (which?) to fill the
11280space allocated. Register bytes are transfered in target byte order.
11281The two nibbles within a register byte are transfered most-significant -
11282least-significant.
11283
11284@multitable @columnfractions .5 .5
11285
11286@item MIPS32
11287@tab
11288All registers are transfered as thirty-two bit quantities in the order:
1128932 general-purpose; sr; lo; hi; bad; cause; pc; 32 floating-point
11290registers; fsr; fir; fp.
11291
11292@item MIPS64
11293@tab
11294All registers are transfered as sixty-four bit quantities (including
11295thirty-two bit registers such as @code{sr}). The ordering is the same
11296as @code{MIPS32}.
11297
11298@end multitable
11299
104c1213
JM
11300Example sequence of a target being re-started. Notice how the restart
11301does not get any direct output:
11302
11303@example
11304<- @code{R00}
11305-> @code{+}
11306@emph{target restarts}
11307<- @code{?}
11308-> @code{+}
11309-> @code{T001:1234123412341234}
11310<- @code{+}
11311@end example
11312
11313Example sequence of a target being stepped by a single instruction:
11314
11315@example
11316<- @code{G1445...}
11317-> @code{+}
11318<- @code{s}
11319-> @code{+}
11320@emph{time passes}
11321-> @code{T001:1234123412341234}
11322<- @code{+}
11323<- @code{g}
11324-> @code{+}
11325-> @code{1455...}
11326<- @code{+}
11327@end example
11328
96baa820 11329
6d2ebf8b 11330@node Configurations
104c1213
JM
11331@chapter Configuration-Specific Information
11332
11333While nearly all @value{GDBN} commands are available for all native and
11334cross versions of the debugger, there are some exceptions. This chapter
11335describes things that are only available in certain configurations.
11336
11337There are three major categories of configurations: native
11338configurations, where the host and target are the same, embedded
11339operating system configurations, which are usually the same for several
11340different processor architectures, and bare embedded processors, which
11341are quite different from each other.
11342
11343@menu
11344* Native::
11345* Embedded OS::
11346* Embedded Processors::
11347* Architectures::
11348@end menu
11349
6d2ebf8b 11350@node Native
104c1213
JM
11351@section Native
11352
11353This section describes details specific to particular native
11354configurations.
11355
11356@menu
11357* HP-UX:: HP-UX
11358* SVR4 Process Information:: SVR4 process information
9f20bf26 11359* DJGPP Native:: Features specific to the DJGPP port
104c1213
JM
11360@end menu
11361
6d2ebf8b 11362@node HP-UX
104c1213
JM
11363@subsection HP-UX
11364
11365On HP-UX systems, if you refer to a function or variable name that
11366begins with a dollar sign, @value{GDBN} searches for a user or system
11367name first, before it searches for a convenience variable.
11368
6d2ebf8b 11369@node SVR4 Process Information
104c1213
JM
11370@subsection SVR4 process information
11371
11372@kindex /proc
11373@cindex process image
11374
11375Many versions of SVR4 provide a facility called @samp{/proc} that can be
11376used to examine the image of a running process using file-system
11377subroutines. If @value{GDBN} is configured for an operating system with
11378this facility, the command @code{info proc} is available to report on
11379several kinds of information about the process running your program.
11380@code{info proc} works only on SVR4 systems that include the
11381@code{procfs} code. This includes OSF/1 (Digital Unix), Solaris, Irix,
11382and Unixware, but not HP-UX or Linux, for example.
11383
11384@table @code
11385@kindex info proc
11386@item info proc
11387Summarize available information about the process.
11388
11389@kindex info proc mappings
11390@item info proc mappings
11391Report on the address ranges accessible in the program, with information
11392on whether your program may read, write, or execute each range.
f6680716
MS
11393@ignore
11394@comment These sub-options of 'info proc' were not included when
11395@comment procfs.c was re-written. Keep their descriptions around
11396@comment against the day when someone finds the time to put them back in.
104c1213
JM
11397@kindex info proc times
11398@item info proc times
11399Starting time, user CPU time, and system CPU time for your program and
11400its children.
11401
11402@kindex info proc id
11403@item info proc id
11404Report on the process IDs related to your program: its own process ID,
11405the ID of its parent, the process group ID, and the session ID.
11406
11407@kindex info proc status
11408@item info proc status
11409General information on the state of the process. If the process is
11410stopped, this report includes the reason for stopping, and any signal
11411received.
11412
11413@item info proc all
11414Show all the above information about the process.
f6680716 11415@end ignore
104c1213
JM
11416@end table
11417
9f20bf26
EZ
11418@node DJGPP Native
11419@subsection Features for Debugging @sc{djgpp} Programs
11420@cindex @sc{djgpp} debugging
11421@cindex native @sc{djgpp} debugging
11422@cindex MS-DOS-specific commands
11423
11424@sc{djgpp} is the port of @sc{gnu} development tools to MS-DOS and
11425MS-Windows. @sc{djgpp} programs are 32-bit protected-mode programs
11426that use the @dfn{DPMI} (DOS Protected-Mode Interface) API to run on
11427top of real-mode DOS systems and their emulations.
11428
11429@value{GDBN} supports native debugging of @sc{djgpp} programs, and
11430defines a few commands specific to the @sc{djgpp} port. This
11431subsection describes those commands.
11432
11433@table @code
11434@kindex info dos
11435@item info dos
11436This is a prefix of @sc{djgpp}-specific commands which print
11437information about the target system and important OS structures.
11438
11439@kindex sysinfo
11440@cindex MS-DOS system info
11441@cindex free memory information (MS-DOS)
11442@item info dos sysinfo
11443This command displays assorted information about the underlying
11444platform: the CPU type and features, the OS version and flavor, the
11445DPMI version, and the available conventional and DPMI memory.
11446
11447@cindex GDT
11448@cindex LDT
11449@cindex IDT
11450@cindex segment descriptor tables
11451@cindex descriptor tables display
11452@item info dos gdt
11453@itemx info dos ldt
11454@itemx info dos idt
11455These 3 commands display entries from, respectively, Global, Local,
11456and Interrupt Descriptor Tables (GDT, LDT, and IDT). The descriptor
11457tables are data structures which store a descriptor for each segment
11458that is currently in use. The segment's selector is an index into a
11459descriptor table; the table entry for that index holds the
11460descriptor's base address and limit, and its attributes and access
11461rights.
11462
11463A typical @sc{djgpp} program uses 3 segments: a code segment, a data
11464segment (used for both data and the stack), and a DOS segment (which
11465allows access to DOS/BIOS data structures and absolute addresses in
11466conventional memory). However, the DPMI host will usually define
11467additional segments in order to support the DPMI environment.
11468
11469@cindex garbled pointers
11470These commands allow to display entries from the descriptor tables.
11471Without an argument, all entries from the specified table are
11472displayed. An argument, which should be an integer expression, means
11473display a single entry whose index is given by the argument. For
11474example, here's a convenient way to display information about the
11475debugged program's data segment:
11476
11477@smallexample
56248298
EZ
11478@exdent @code{(@value{GDBP}) info dos ldt $ds}
11479@exdent @code{0x13f: base=0x11970000 limit=0x0009ffff 32-Bit Data (Read/Write, Exp-up)}
9f20bf26
EZ
11480@end smallexample
11481
11482@noindent
11483This comes in handy when you want to see whether a pointer is outside
11484the data segment's limit (i.e.@: @dfn{garbled}).
11485
11486@cindex page tables display (MS-DOS)
11487@item info dos pde
11488@itemx info dos pte
11489These two commands display entries from, respectively, the Page
11490Directory and the Page Tables. Page Directories and Page Tables are
11491data structures which control how virtual memory addresses are mapped
11492into physical addresses. A Page Table includes an entry for every
11493page of memory that is mapped into the program's address space; there
11494may be several Page Tables, each one holding up to 4096 entries. A
11495Page Directory has up to 4096 entries, one each for every Page Table
11496that is currently in use.
11497
11498Without an argument, @kbd{info dos pde} displays the entire Page
11499Directory, and @kbd{info dos pte} displays all the entries in all of
11500the Page Tables. An argument, an integer expression, given to the
11501@kbd{info dos pde} command means display only that entry from the Page
11502Directory table. An argument given to the @kbd{info dos pte} command
11503means display entries from a single Page Table, the one pointed to by
11504the specified entry in the Page Directory.
11505
56248298 11506@cindex direct memory access (DMA) on MS-DOS
9f20bf26
EZ
11507These commands are useful when your program uses @dfn{DMA} (Direct
11508Memory Access), which needs physical addresses to program the DMA
11509controller.
11510
11511These commands are supported only with some DPMI servers.
11512
11513@cindex physical address from linear address
56248298 11514@item info dos address-pte @var{addr}
9f20bf26 11515This command displays the Page Table entry for a specified linear
56248298 11516address. The argument linear address @var{addr} should already have the
9f20bf26
EZ
11517appropriate segment's base address added to it, because this command
11518accepts addresses which may belong to @emph{any} segment. For
11519example, here's how to display the Page Table entry for the page where
11520the variable @code{i} is stored:
11521
56248298
EZ
11522@smallexample
11523@exdent @code{(@value{GDBP}) info dos address-pte __djgpp_base_address + (char *)&i}
11524@exdent @code{Page Table entry for address 0x11a00d30:}
11525@exdent @code{Base=0x02698000 Dirty Acc. Not-Cached Write-Back Usr Read-Write +0xd30}
9f20bf26
EZ
11526@end smallexample
11527
11528@noindent
11529This says that @code{i} is stored at offset @code{0xd30} from the page
11530whose physical base address is @code{0x02698000}, and prints all the
11531attributes of that page.
11532
11533Note that you must cast the addresses of variables to a @code{char *},
11534since otherwise the value of @code{__djgpp_base_address}, the base
11535address of all variables and functions in a @sc{djgpp} program, will
11536be added using the rules of C pointer arithmetics: if @code{i} is
11537declared an @code{int}, @value{GDBN} will add 4 times the value of
11538@code{__djgpp_base_address} to the address of @code{i}.
11539
11540Here's another example, it displays the Page Table entry for the
11541transfer buffer:
11542
11543@smallexample
56248298
EZ
11544@exdent @code{(@value{GDBP}) info dos address-pte *((unsigned *)&_go32_info_block + 3)}
11545@exdent @code{Page Table entry for address 0x29110:}
11546@exdent @code{Base=0x00029000 Dirty Acc. Not-Cached Write-Back Usr Read-Write +0x110}
9f20bf26
EZ
11547@end smallexample
11548
11549@noindent
11550(The @code{+ 3} offset is because the transfer buffer's address is the
115513rd member of the @code{_go32_info_block} structure.) The output of
11552this command clearly shows that addresses in conventional memory are
11553mapped 1:1, i.e.@: the physical and linear addresses are identical.
11554
11555This command is supported only with some DPMI servers.
11556@end table
11557
6d2ebf8b 11558@node Embedded OS
104c1213
JM
11559@section Embedded Operating Systems
11560
11561This section describes configurations involving the debugging of
11562embedded operating systems that are available for several different
11563architectures.
11564
11565@menu
11566* VxWorks:: Using @value{GDBN} with VxWorks
11567@end menu
11568
11569@value{GDBN} includes the ability to debug programs running on
11570various real-time operating systems.
11571
6d2ebf8b 11572@node VxWorks
104c1213
JM
11573@subsection Using @value{GDBN} with VxWorks
11574
11575@cindex VxWorks
11576
11577@table @code
11578
11579@kindex target vxworks
11580@item target vxworks @var{machinename}
11581A VxWorks system, attached via TCP/IP. The argument @var{machinename}
11582is the target system's machine name or IP address.
11583
11584@end table
11585
11586On VxWorks, @code{load} links @var{filename} dynamically on the
11587current target system as well as adding its symbols in @value{GDBN}.
11588
11589@value{GDBN} enables developers to spawn and debug tasks running on networked
11590VxWorks targets from a Unix host. Already-running tasks spawned from
11591the VxWorks shell can also be debugged. @value{GDBN} uses code that runs on
11592both the Unix host and on the VxWorks target. The program
d4f3574e 11593@code{@value{GDBP}} is installed and executed on the Unix host. (It may be
104c1213 11594installed with the name @code{vxgdb}, to distinguish it from a
96a2c332 11595@value{GDBN} for debugging programs on the host itself.)
104c1213
JM
11596
11597@table @code
11598@item VxWorks-timeout @var{args}
11599@kindex vxworks-timeout
5d161b24
DB
11600All VxWorks-based targets now support the option @code{vxworks-timeout}.
11601This option is set by the user, and @var{args} represents the number of
11602seconds @value{GDBN} waits for responses to rpc's. You might use this if
11603your VxWorks target is a slow software simulator or is on the far side
104c1213
JM
11604of a thin network line.
11605@end table
11606
11607The following information on connecting to VxWorks was current when
11608this manual was produced; newer releases of VxWorks may use revised
11609procedures.
11610
11611@kindex INCLUDE_RDB
11612To use @value{GDBN} with VxWorks, you must rebuild your VxWorks kernel
11613to include the remote debugging interface routines in the VxWorks
11614library @file{rdb.a}. To do this, define @code{INCLUDE_RDB} in the
11615VxWorks configuration file @file{configAll.h} and rebuild your VxWorks
11616kernel. The resulting kernel contains @file{rdb.a}, and spawns the
11617source debugging task @code{tRdbTask} when VxWorks is booted. For more
11618information on configuring and remaking VxWorks, see the manufacturer's
11619manual.
11620@c VxWorks, see the @cite{VxWorks Programmer's Guide}.
11621
11622Once you have included @file{rdb.a} in your VxWorks system image and set
11623your Unix execution search path to find @value{GDBN}, you are ready to
96a2c332
SS
11624run @value{GDBN}. From your Unix host, run @code{@value{GDBP}} (or
11625@code{vxgdb}, depending on your installation).
104c1213
JM
11626
11627@value{GDBN} comes up showing the prompt:
11628
11629@example
11630(vxgdb)
11631@end example
11632
11633@menu
11634* VxWorks Connection:: Connecting to VxWorks
11635* VxWorks Download:: VxWorks download
11636* VxWorks Attach:: Running tasks
11637@end menu
11638
6d2ebf8b 11639@node VxWorks Connection
104c1213
JM
11640@subsubsection Connecting to VxWorks
11641
11642The @value{GDBN} command @code{target} lets you connect to a VxWorks target on the
11643network. To connect to a target whose host name is ``@code{tt}'', type:
11644
11645@example
11646(vxgdb) target vxworks tt
11647@end example
11648
11649@need 750
11650@value{GDBN} displays messages like these:
11651
11652@smallexample
5d161b24 11653Attaching remote machine across net...
104c1213
JM
11654Connected to tt.
11655@end smallexample
11656
11657@need 1000
11658@value{GDBN} then attempts to read the symbol tables of any object modules
11659loaded into the VxWorks target since it was last booted. @value{GDBN} locates
11660these files by searching the directories listed in the command search
11661path (@pxref{Environment, ,Your program's environment}); if it fails
11662to find an object file, it displays a message such as:
11663
11664@example
11665prog.o: No such file or directory.
11666@end example
11667
11668When this happens, add the appropriate directory to the search path with
11669the @value{GDBN} command @code{path}, and execute the @code{target}
11670command again.
11671
6d2ebf8b 11672@node VxWorks Download
104c1213
JM
11673@subsubsection VxWorks download
11674
11675@cindex download to VxWorks
11676If you have connected to the VxWorks target and you want to debug an
11677object that has not yet been loaded, you can use the @value{GDBN}
11678@code{load} command to download a file from Unix to VxWorks
11679incrementally. The object file given as an argument to the @code{load}
11680command is actually opened twice: first by the VxWorks target in order
11681to download the code, then by @value{GDBN} in order to read the symbol
11682table. This can lead to problems if the current working directories on
11683the two systems differ. If both systems have NFS mounted the same
11684filesystems, you can avoid these problems by using absolute paths.
11685Otherwise, it is simplest to set the working directory on both systems
11686to the directory in which the object file resides, and then to reference
11687the file by its name, without any path. For instance, a program
11688@file{prog.o} may reside in @file{@var{vxpath}/vw/demo/rdb} in VxWorks
11689and in @file{@var{hostpath}/vw/demo/rdb} on the host. To load this
11690program, type this on VxWorks:
11691
11692@example
11693-> cd "@var{vxpath}/vw/demo/rdb"
11694@end example
d4f3574e
SS
11695
11696@noindent
104c1213
JM
11697Then, in @value{GDBN}, type:
11698
11699@example
5d161b24 11700(vxgdb) cd @var{hostpath}/vw/demo/rdb
104c1213
JM
11701(vxgdb) load prog.o
11702@end example
11703
11704@value{GDBN} displays a response similar to this:
11705
11706@smallexample
11707Reading symbol data from wherever/vw/demo/rdb/prog.o... done.
11708@end smallexample
11709
11710You can also use the @code{load} command to reload an object module
11711after editing and recompiling the corresponding source file. Note that
11712this makes @value{GDBN} delete all currently-defined breakpoints,
11713auto-displays, and convenience variables, and to clear the value
11714history. (This is necessary in order to preserve the integrity of
d4f3574e 11715debugger's data structures that reference the target system's symbol
104c1213
JM
11716table.)
11717
6d2ebf8b 11718@node VxWorks Attach
104c1213
JM
11719@subsubsection Running tasks
11720
11721@cindex running VxWorks tasks
11722You can also attach to an existing task using the @code{attach} command as
11723follows:
11724
11725@example
11726(vxgdb) attach @var{task}
11727@end example
11728
11729@noindent
11730where @var{task} is the VxWorks hexadecimal task ID. The task can be running
11731or suspended when you attach to it. Running tasks are suspended at
11732the time of attachment.
11733
6d2ebf8b 11734@node Embedded Processors
104c1213
JM
11735@section Embedded Processors
11736
11737This section goes into details specific to particular embedded
11738configurations.
11739
7d86b5d5
AC
11740
11741@c OBSOLETE * A29K Embedded:: AMD A29K Embedded
104c1213 11742@menu
104c1213
JM
11743* ARM:: ARM
11744* H8/300:: Hitachi H8/300
11745* H8/500:: Hitachi H8/500
11746* i960:: Intel i960
11747* M32R/D:: Mitsubishi M32R/D
11748* M68K:: Motorola M68K
11749* M88K:: Motorola M88K
11750* MIPS Embedded:: MIPS Embedded
11751* PA:: HP PA Embedded
11752* PowerPC: PowerPC
11753* SH:: Hitachi SH
11754* Sparclet:: Tsqware Sparclet
11755* Sparclite:: Fujitsu Sparclite
11756* ST2000:: Tandem ST2000
11757* Z8000:: Zilog Z8000
11758@end menu
11759
7d86b5d5
AC
11760@c OBSOLETE @node A29K Embedded
11761@c OBSOLETE @subsection AMD A29K Embedded
11762@c OBSOLETE
11763@c OBSOLETE @menu
11764@c OBSOLETE * A29K UDI::
11765@c OBSOLETE * A29K EB29K::
11766@c OBSOLETE * Comms (EB29K):: Communications setup
11767@c OBSOLETE * gdb-EB29K:: EB29K cross-debugging
11768@c OBSOLETE * Remote Log:: Remote log
11769@c OBSOLETE @end menu
11770@c OBSOLETE
11771@c OBSOLETE @table @code
11772@c OBSOLETE
11773@c OBSOLETE @kindex target adapt
11774@c OBSOLETE @item target adapt @var{dev}
11775@c OBSOLETE Adapt monitor for A29K.
11776@c OBSOLETE
11777@c OBSOLETE @kindex target amd-eb
11778@c OBSOLETE @item target amd-eb @var{dev} @var{speed} @var{PROG}
11779@c OBSOLETE @cindex AMD EB29K
11780@c OBSOLETE Remote PC-resident AMD EB29K board, attached over serial lines.
11781@c OBSOLETE @var{dev} is the serial device, as for @code{target remote};
11782@c OBSOLETE @var{speed} allows you to specify the linespeed; and @var{PROG} is the
11783@c OBSOLETE name of the program to be debugged, as it appears to DOS on the PC.
11784@c OBSOLETE @xref{A29K EB29K, ,EBMON protocol for AMD29K}.
11785@c OBSOLETE
11786@c OBSOLETE @end table
11787@c OBSOLETE
11788@c OBSOLETE @node A29K UDI
11789@c OBSOLETE @subsubsection A29K UDI
11790@c OBSOLETE
11791@c OBSOLETE @cindex UDI
11792@c OBSOLETE @cindex AMD29K via UDI
11793@c OBSOLETE
11794@c OBSOLETE @value{GDBN} supports AMD's UDI (``Universal Debugger Interface'')
11795@c OBSOLETE protocol for debugging the a29k processor family. To use this
11796@c OBSOLETE configuration with AMD targets running the MiniMON monitor, you need the
11797@c OBSOLETE program @code{MONTIP}, available from AMD at no charge. You can also
11798@c OBSOLETE use @value{GDBN} with the UDI-conformant a29k simulator program
11799@c OBSOLETE @code{ISSTIP}, also available from AMD.
11800@c OBSOLETE
11801@c OBSOLETE @table @code
11802@c OBSOLETE @item target udi @var{keyword}
11803@c OBSOLETE @kindex udi
11804@c OBSOLETE Select the UDI interface to a remote a29k board or simulator, where
11805@c OBSOLETE @var{keyword} is an entry in the AMD configuration file @file{udi_soc}.
11806@c OBSOLETE This file contains keyword entries which specify parameters used to
11807@c OBSOLETE connect to a29k targets. If the @file{udi_soc} file is not in your
11808@c OBSOLETE working directory, you must set the environment variable @samp{UDICONF}
11809@c OBSOLETE to its pathname.
11810@c OBSOLETE @end table
11811@c OBSOLETE
11812@c OBSOLETE @node A29K EB29K
11813@c OBSOLETE @subsubsection EBMON protocol for AMD29K
11814@c OBSOLETE
11815@c OBSOLETE @cindex EB29K board
11816@c OBSOLETE @cindex running 29K programs
11817@c OBSOLETE
11818@c OBSOLETE AMD distributes a 29K development board meant to fit in a PC, together
11819@c OBSOLETE with a DOS-hosted monitor program called @code{EBMON}. As a shorthand
11820@c OBSOLETE term, this development system is called the ``EB29K''. To use
11821@c OBSOLETE @value{GDBN} from a Unix system to run programs on the EB29K board, you
11822@c OBSOLETE must first connect a serial cable between the PC (which hosts the EB29K
11823@c OBSOLETE board) and a serial port on the Unix system. In the following, we
11824@c OBSOLETE assume you've hooked the cable between the PC's @file{COM1} port and
11825@c OBSOLETE @file{/dev/ttya} on the Unix system.
11826@c OBSOLETE
11827@c OBSOLETE @node Comms (EB29K)
11828@c OBSOLETE @subsubsection Communications setup
11829@c OBSOLETE
11830@c OBSOLETE The next step is to set up the PC's port, by doing something like this
11831@c OBSOLETE in DOS on the PC:
11832@c OBSOLETE
11833@c OBSOLETE @example
11834@c OBSOLETE C:\> MODE com1:9600,n,8,1,none
11835@c OBSOLETE @end example
11836@c OBSOLETE
11837@c OBSOLETE @noindent
11838@c OBSOLETE This example---run on an MS DOS 4.0 system---sets the PC port to 9600
11839@c OBSOLETE bps, no parity, eight data bits, one stop bit, and no ``retry'' action;
11840@c OBSOLETE you must match the communications parameters when establishing the Unix
11841@c OBSOLETE end of the connection as well.
11842@c OBSOLETE @c FIXME: Who knows what this "no retry action" crud from the DOS manual may
11843@c OBSOLETE @c mean? It's optional; leave it out? ---doc@cygnus.com, 25feb91
11844@c OBSOLETE @c
11845@c OBSOLETE @c It's optional, but it's unwise to omit it: who knows what is the
11846@c OBSOLETE @c default value set when the DOS machines boots? "No retry" means that
11847@c OBSOLETE @c the DOS serial device driver won't retry the operation if it fails;
11848@c OBSOLETE @c I understand that this is needed because the GDB serial protocol
11849@c OBSOLETE @c handles any errors and retransmissions itself. ---Eli Zaretskii, 3sep99
11850@c OBSOLETE
11851@c OBSOLETE To give control of the PC to the Unix side of the serial line, type
11852@c OBSOLETE the following at the DOS console:
11853@c OBSOLETE
11854@c OBSOLETE @example
11855@c OBSOLETE C:\> CTTY com1
11856@c OBSOLETE @end example
11857@c OBSOLETE
11858@c OBSOLETE @noindent
11859@c OBSOLETE (Later, if you wish to return control to the DOS console, you can use
11860@c OBSOLETE the command @code{CTTY con}---but you must send it over the device that
11861@c OBSOLETE had control, in our example over the @file{COM1} serial line.)
11862@c OBSOLETE
11863@c OBSOLETE From the Unix host, use a communications program such as @code{tip} or
11864@c OBSOLETE @code{cu} to communicate with the PC; for example,
11865@c OBSOLETE
11866@c OBSOLETE @example
11867@c OBSOLETE cu -s 9600 -l /dev/ttya
11868@c OBSOLETE @end example
11869@c OBSOLETE
11870@c OBSOLETE @noindent
11871@c OBSOLETE The @code{cu} options shown specify, respectively, the linespeed and the
11872@c OBSOLETE serial port to use. If you use @code{tip} instead, your command line
11873@c OBSOLETE may look something like the following:
11874@c OBSOLETE
11875@c OBSOLETE @example
11876@c OBSOLETE tip -9600 /dev/ttya
11877@c OBSOLETE @end example
11878@c OBSOLETE
11879@c OBSOLETE @noindent
11880@c OBSOLETE Your system may require a different name where we show
11881@c OBSOLETE @file{/dev/ttya} as the argument to @code{tip}. The communications
11882@c OBSOLETE parameters, including which port to use, are associated with the
11883@c OBSOLETE @code{tip} argument in the ``remote'' descriptions file---normally the
11884@c OBSOLETE system table @file{/etc/remote}.
11885@c OBSOLETE @c FIXME: What if anything needs doing to match the "n,8,1,none" part of
11886@c OBSOLETE @c the DOS side's comms setup? cu can support -o (odd
11887@c OBSOLETE @c parity), -e (even parity)---apparently no settings for no parity or
11888@c OBSOLETE @c for character size. Taken from stty maybe...? John points out tip
11889@c OBSOLETE @c can set these as internal variables, eg ~s parity=none; man stty
11890@c OBSOLETE @c suggests that it *might* work to stty these options with stdin or
11891@c OBSOLETE @c stdout redirected... ---doc@cygnus.com, 25feb91
11892@c OBSOLETE @c
11893@c OBSOLETE @c There's nothing to be done for the "none" part of the DOS MODE
11894@c OBSOLETE @c command. The rest of the parameters should be matched by the
11895@c OBSOLETE @c baudrate, bits, and parity used by the Unix side. ---Eli Zaretskii, 3Sep99
11896@c OBSOLETE
11897@c OBSOLETE @kindex EBMON
11898@c OBSOLETE Using the @code{tip} or @code{cu} connection, change the DOS working
11899@c OBSOLETE directory to the directory containing a copy of your 29K program, then
11900@c OBSOLETE start the PC program @code{EBMON} (an EB29K control program supplied
11901@c OBSOLETE with your board by AMD). You should see an initial display from
11902@c OBSOLETE @code{EBMON} similar to the one that follows, ending with the
11903@c OBSOLETE @code{EBMON} prompt @samp{#}---
11904@c OBSOLETE
11905@c OBSOLETE @example
11906@c OBSOLETE C:\> G:
11907@c OBSOLETE
11908@c OBSOLETE G:\> CD \usr\joe\work29k
11909@c OBSOLETE
11910@c OBSOLETE G:\USR\JOE\WORK29K> EBMON
11911@c OBSOLETE Am29000 PC Coprocessor Board Monitor, version 3.0-18
11912@c OBSOLETE Copyright 1990 Advanced Micro Devices, Inc.
11913@c OBSOLETE Written by Gibbons and Associates, Inc.
11914@c OBSOLETE
11915@c OBSOLETE Enter '?' or 'H' for help
11916@c OBSOLETE
11917@c OBSOLETE PC Coprocessor Type = EB29K
11918@c OBSOLETE I/O Base = 0x208
11919@c OBSOLETE Memory Base = 0xd0000
11920@c OBSOLETE
11921@c OBSOLETE Data Memory Size = 2048KB
11922@c OBSOLETE Available I-RAM Range = 0x8000 to 0x1fffff
11923@c OBSOLETE Available D-RAM Range = 0x80002000 to 0x801fffff
11924@c OBSOLETE
11925@c OBSOLETE PageSize = 0x400
11926@c OBSOLETE Register Stack Size = 0x800
11927@c OBSOLETE Memory Stack Size = 0x1800
11928@c OBSOLETE
11929@c OBSOLETE CPU PRL = 0x3
11930@c OBSOLETE Am29027 Available = No
11931@c OBSOLETE Byte Write Available = Yes
11932@c OBSOLETE
11933@c OBSOLETE # ~.
11934@c OBSOLETE @end example
11935@c OBSOLETE
11936@c OBSOLETE Then exit the @code{cu} or @code{tip} program (done in the example by
11937@c OBSOLETE typing @code{~.} at the @code{EBMON} prompt). @code{EBMON} keeps
11938@c OBSOLETE running, ready for @value{GDBN} to take over.
11939@c OBSOLETE
11940@c OBSOLETE For this example, we've assumed what is probably the most convenient
11941@c OBSOLETE way to make sure the same 29K program is on both the PC and the Unix
11942@c OBSOLETE system: a PC/NFS connection that establishes ``drive @file{G:}'' on the
11943@c OBSOLETE PC as a file system on the Unix host. If you do not have PC/NFS or
11944@c OBSOLETE something similar connecting the two systems, you must arrange some
11945@c OBSOLETE other way---perhaps floppy-disk transfer---of getting the 29K program
11946@c OBSOLETE from the Unix system to the PC; @value{GDBN} does @emph{not} download it over the
11947@c OBSOLETE serial line.
11948@c OBSOLETE
11949@c OBSOLETE @node gdb-EB29K
11950@c OBSOLETE @subsubsection EB29K cross-debugging
11951@c OBSOLETE
11952@c OBSOLETE Finally, @code{cd} to the directory containing an image of your 29K
11953@c OBSOLETE program on the Unix system, and start @value{GDBN}---specifying as argument the
11954@c OBSOLETE name of your 29K program:
11955@c OBSOLETE
11956@c OBSOLETE @example
11957@c OBSOLETE cd /usr/joe/work29k
11958@c OBSOLETE @value{GDBP} myfoo
11959@c OBSOLETE @end example
11960@c OBSOLETE
11961@c OBSOLETE @need 500
11962@c OBSOLETE Now you can use the @code{target} command:
11963@c OBSOLETE
11964@c OBSOLETE @example
11965@c OBSOLETE target amd-eb /dev/ttya 9600 MYFOO
11966@c OBSOLETE @c FIXME: test above 'target amd-eb' as spelled, with caps! caps are meant to
11967@c OBSOLETE @c emphasize that this is the name as seen by DOS (since I think DOS is
11968@c OBSOLETE @c single-minded about case of letters). ---doc@cygnus.com, 25feb91
11969@c OBSOLETE @end example
11970@c OBSOLETE
11971@c OBSOLETE @noindent
11972@c OBSOLETE In this example, we've assumed your program is in a file called
11973@c OBSOLETE @file{myfoo}. Note that the filename given as the last argument to
11974@c OBSOLETE @code{target amd-eb} should be the name of the program as it appears to DOS.
11975@c OBSOLETE In our example this is simply @code{MYFOO}, but in general it can include
11976@c OBSOLETE a DOS path, and depending on your transfer mechanism may not resemble
11977@c OBSOLETE the name on the Unix side.
11978@c OBSOLETE
11979@c OBSOLETE At this point, you can set any breakpoints you wish; when you are ready
11980@c OBSOLETE to see your program run on the 29K board, use the @value{GDBN} command
11981@c OBSOLETE @code{run}.
11982@c OBSOLETE
11983@c OBSOLETE To stop debugging the remote program, use the @value{GDBN} @code{detach}
11984@c OBSOLETE command.
11985@c OBSOLETE
11986@c OBSOLETE To return control of the PC to its console, use @code{tip} or @code{cu}
11987@c OBSOLETE once again, after your @value{GDBN} session has concluded, to attach to
11988@c OBSOLETE @code{EBMON}. You can then type the command @code{q} to shut down
11989@c OBSOLETE @code{EBMON}, returning control to the DOS command-line interpreter.
11990@c OBSOLETE Type @kbd{CTTY con} to return command input to the main DOS console,
11991@c OBSOLETE and type @kbd{~.} to leave @code{tip} or @code{cu}.
11992@c OBSOLETE
11993@c OBSOLETE @node Remote Log
11994@c OBSOLETE @subsubsection Remote log
11995@c OBSOLETE @cindex @file{eb.log}, a log file for EB29K
11996@c OBSOLETE @cindex log file for EB29K
11997@c OBSOLETE
11998@c OBSOLETE The @code{target amd-eb} command creates a file @file{eb.log} in the
11999@c OBSOLETE current working directory, to help debug problems with the connection.
12000@c OBSOLETE @file{eb.log} records all the output from @code{EBMON}, including echoes
12001@c OBSOLETE of the commands sent to it. Running @samp{tail -f} on this file in
12002@c OBSOLETE another window often helps to understand trouble with @code{EBMON}, or
12003@c OBSOLETE unexpected events on the PC side of the connection.
104c1213 12004
6d2ebf8b 12005@node ARM
104c1213
JM
12006@subsection ARM
12007
12008@table @code
12009
12010@kindex target rdi
12011@item target rdi @var{dev}
12012ARM Angel monitor, via RDI library interface to ADP protocol. You may
12013use this target to communicate with both boards running the Angel
12014monitor, or with the EmbeddedICE JTAG debug device.
5d161b24 12015
104c1213
JM
12016@kindex target rdp
12017@item target rdp @var{dev}
12018ARM Demon monitor.
12019
12020@end table
12021
6d2ebf8b 12022@node H8/300
104c1213
JM
12023@subsection Hitachi H8/300
12024
12025@table @code
12026
d4f3574e 12027@kindex target hms@r{, with H8/300}
104c1213
JM
12028@item target hms @var{dev}
12029A Hitachi SH, H8/300, or H8/500 board, attached via serial line to your host.
12030Use special commands @code{device} and @code{speed} to control the serial
12031line and the communications speed used.
12032
d4f3574e 12033@kindex target e7000@r{, with H8/300}
104c1213
JM
12034@item target e7000 @var{dev}
12035E7000 emulator for Hitachi H8 and SH.
12036
d4f3574e
SS
12037@kindex target sh3@r{, with H8/300}
12038@kindex target sh3e@r{, with H8/300}
104c1213 12039@item target sh3 @var{dev}
96a2c332 12040@itemx target sh3e @var{dev}
104c1213
JM
12041Hitachi SH-3 and SH-3E target systems.
12042
12043@end table
12044
12045@cindex download to H8/300 or H8/500
12046@cindex H8/300 or H8/500 download
12047@cindex download to Hitachi SH
12048@cindex Hitachi SH download
12049When you select remote debugging to a Hitachi SH, H8/300, or H8/500
12050board, the @code{load} command downloads your program to the Hitachi
12051board and also opens it as the current executable target for
12052@value{GDBN} on your host (like the @code{file} command).
12053
12054@value{GDBN} needs to know these things to talk to your
5d161b24 12055Hitachi SH, H8/300, or H8/500:
104c1213
JM
12056
12057@enumerate
12058@item
12059that you want to use @samp{target hms}, the remote debugging interface
12060for Hitachi microprocessors, or @samp{target e7000}, the in-circuit
12061emulator for the Hitachi SH and the Hitachi 300H. (@samp{target hms} is
2df3850c 12062the default when @value{GDBN} is configured specifically for the Hitachi SH,
104c1213
JM
12063H8/300, or H8/500.)
12064
12065@item
12066what serial device connects your host to your Hitachi board (the first
12067serial device available on your host is the default).
12068
12069@item
12070what speed to use over the serial device.
12071@end enumerate
12072
12073@menu
12074* Hitachi Boards:: Connecting to Hitachi boards.
12075* Hitachi ICE:: Using the E7000 In-Circuit Emulator.
12076* Hitachi Special:: Special @value{GDBN} commands for Hitachi micros.
12077@end menu
12078
6d2ebf8b 12079@node Hitachi Boards
104c1213
JM
12080@subsubsection Connecting to Hitachi boards
12081
12082@c only for Unix hosts
12083@kindex device
12084@cindex serial device, Hitachi micros
96a2c332 12085Use the special @code{@value{GDBN}} command @samp{device @var{port}} if you
104c1213
JM
12086need to explicitly set the serial device. The default @var{port} is the
12087first available port on your host. This is only necessary on Unix
12088hosts, where it is typically something like @file{/dev/ttya}.
12089
12090@kindex speed
12091@cindex serial line speed, Hitachi micros
96a2c332 12092@code{@value{GDBN}} has another special command to set the communications
104c1213 12093speed: @samp{speed @var{bps}}. This command also is only used from Unix
2df3850c 12094hosts; on DOS hosts, set the line speed as usual from outside @value{GDBN} with
d4f3574e
SS
12095the DOS @code{mode} command (for instance,
12096@w{@kbd{mode com2:9600,n,8,1,p}} for a 9600@dmn{bps} connection).
104c1213
JM
12097
12098The @samp{device} and @samp{speed} commands are available only when you
12099use a Unix host to debug your Hitachi microprocessor programs. If you
12100use a DOS host,
12101@value{GDBN} depends on an auxiliary terminate-and-stay-resident program
12102called @code{asynctsr} to communicate with the development board
12103through a PC serial port. You must also use the DOS @code{mode} command
12104to set up the serial port on the DOS side.
12105
12106The following sample session illustrates the steps needed to start a
12107program under @value{GDBN} control on an H8/300. The example uses a
12108sample H8/300 program called @file{t.x}. The procedure is the same for
12109the Hitachi SH and the H8/500.
12110
12111First hook up your development board. In this example, we use a
12112board attached to serial port @code{COM2}; if you use a different serial
12113port, substitute its name in the argument of the @code{mode} command.
12114When you call @code{asynctsr}, the auxiliary comms program used by the
d4f3574e 12115debugger, you give it just the numeric part of the serial port's name;
104c1213
JM
12116for example, @samp{asyncstr 2} below runs @code{asyncstr} on
12117@code{COM2}.
12118
12119@example
12120C:\H8300\TEST> asynctsr 2
12121C:\H8300\TEST> mode com2:9600,n,8,1,p
12122
12123Resident portion of MODE loaded
12124
12125COM2: 9600, n, 8, 1, p
12126
12127@end example
12128
12129@quotation
12130@emph{Warning:} We have noticed a bug in PC-NFS that conflicts with
12131@code{asynctsr}. If you also run PC-NFS on your DOS host, you may need to
12132disable it, or even boot without it, to use @code{asynctsr} to control
12133your development board.
12134@end quotation
12135
d4f3574e 12136@kindex target hms@r{, and serial protocol}
104c1213
JM
12137Now that serial communications are set up, and the development board is
12138connected, you can start up @value{GDBN}. Call @code{@value{GDBP}} with
96a2c332 12139the name of your program as the argument. @code{@value{GDBN}} prompts
104c1213
JM
12140you, as usual, with the prompt @samp{(@value{GDBP})}. Use two special
12141commands to begin your debugging session: @samp{target hms} to specify
12142cross-debugging to the Hitachi board, and the @code{load} command to
12143download your program to the board. @code{load} displays the names of
12144the program's sections, and a @samp{*} for each 2K of data downloaded.
12145(If you want to refresh @value{GDBN} data on symbols or on the
12146executable file without downloading, use the @value{GDBN} commands
12147@code{file} or @code{symbol-file}. These commands, and @code{load}
12148itself, are described in @ref{Files,,Commands to specify files}.)
12149
12150@smallexample
12151(eg-C:\H8300\TEST) @value{GDBP} t.x
2df3850c 12152@value{GDBN} is free software and you are welcome to distribute copies
5d161b24 12153 of it under certain conditions; type "show copying" to see
104c1213 12154 the conditions.
5d161b24 12155There is absolutely no warranty for @value{GDBN}; type "show warranty"
104c1213 12156for details.
2df3850c
JM
12157@value{GDBN} @value{GDBVN}, Copyright 1992 Free Software Foundation, Inc...
12158(@value{GDBP}) target hms
104c1213 12159Connected to remote H8/300 HMS system.
2df3850c 12160(@value{GDBP}) load t.x
104c1213
JM
12161.text : 0x8000 .. 0xabde ***********
12162.data : 0xabde .. 0xad30 *
12163.stack : 0xf000 .. 0xf014 *
12164@end smallexample
12165
12166At this point, you're ready to run or debug your program. From here on,
12167you can use all the usual @value{GDBN} commands. The @code{break} command
12168sets breakpoints; the @code{run} command starts your program;
12169@code{print} or @code{x} display data; the @code{continue} command
12170resumes execution after stopping at a breakpoint. You can use the
12171@code{help} command at any time to find out more about @value{GDBN} commands.
12172
12173Remember, however, that @emph{operating system} facilities aren't
12174available on your development board; for example, if your program hangs,
12175you can't send an interrupt---but you can press the @sc{reset} switch!
12176
12177Use the @sc{reset} button on the development board
12178@itemize @bullet
12179@item
12180to interrupt your program (don't use @kbd{ctl-C} on the DOS host---it has
12181no way to pass an interrupt signal to the development board); and
12182
12183@item
12184to return to the @value{GDBN} command prompt after your program finishes
12185normally. The communications protocol provides no other way for @value{GDBN}
12186to detect program completion.
12187@end itemize
12188
12189In either case, @value{GDBN} sees the effect of a @sc{reset} on the
12190development board as a ``normal exit'' of your program.
12191
6d2ebf8b 12192@node Hitachi ICE
104c1213
JM
12193@subsubsection Using the E7000 in-circuit emulator
12194
d4f3574e 12195@kindex target e7000@r{, with Hitachi ICE}
104c1213
JM
12196You can use the E7000 in-circuit emulator to develop code for either the
12197Hitachi SH or the H8/300H. Use one of these forms of the @samp{target
12198e7000} command to connect @value{GDBN} to your E7000:
12199
12200@table @code
12201@item target e7000 @var{port} @var{speed}
12202Use this form if your E7000 is connected to a serial port. The
12203@var{port} argument identifies what serial port to use (for example,
12204@samp{com2}). The third argument is the line speed in bits per second
12205(for example, @samp{9600}).
12206
12207@item target e7000 @var{hostname}
12208If your E7000 is installed as a host on a TCP/IP network, you can just
12209specify its hostname; @value{GDBN} uses @code{telnet} to connect.
12210@end table
12211
6d2ebf8b 12212@node Hitachi Special
104c1213
JM
12213@subsubsection Special @value{GDBN} commands for Hitachi micros
12214
12215Some @value{GDBN} commands are available only for the H8/300:
12216
12217@table @code
12218
12219@kindex set machine
12220@kindex show machine
12221@item set machine h8300
12222@itemx set machine h8300h
12223Condition @value{GDBN} for one of the two variants of the H8/300
12224architecture with @samp{set machine}. You can use @samp{show machine}
12225to check which variant is currently in effect.
12226
12227@end table
12228
6d2ebf8b 12229@node H8/500
104c1213
JM
12230@subsection H8/500
12231
12232@table @code
12233
12234@kindex set memory @var{mod}
12235@cindex memory models, H8/500
12236@item set memory @var{mod}
12237@itemx show memory
12238Specify which H8/500 memory model (@var{mod}) you are using with
12239@samp{set memory}; check which memory model is in effect with @samp{show
12240memory}. The accepted values for @var{mod} are @code{small},
12241@code{big}, @code{medium}, and @code{compact}.
12242
12243@end table
12244
6d2ebf8b 12245@node i960
104c1213
JM
12246@subsection Intel i960
12247
12248@table @code
12249
12250@kindex target mon960
12251@item target mon960 @var{dev}
12252MON960 monitor for Intel i960.
12253
f0ca3dce 12254@kindex target nindy
104c1213
JM
12255@item target nindy @var{devicename}
12256An Intel 960 board controlled by a Nindy Monitor. @var{devicename} is
12257the name of the serial device to use for the connection, e.g.
12258@file{/dev/ttya}.
12259
12260@end table
12261
12262@cindex Nindy
12263@cindex i960
12264@dfn{Nindy} is a ROM Monitor program for Intel 960 target systems. When
12265@value{GDBN} is configured to control a remote Intel 960 using Nindy, you can
12266tell @value{GDBN} how to connect to the 960 in several ways:
12267
12268@itemize @bullet
12269@item
12270Through command line options specifying serial port, version of the
12271Nindy protocol, and communications speed;
12272
12273@item
12274By responding to a prompt on startup;
12275
12276@item
12277By using the @code{target} command at any point during your @value{GDBN}
12278session. @xref{Target Commands, ,Commands for managing targets}.
12279
104c1213
JM
12280@end itemize
12281
12282@cindex download to Nindy-960
12283With the Nindy interface to an Intel 960 board, @code{load}
12284downloads @var{filename} to the 960 as well as adding its symbols in
12285@value{GDBN}.
12286
12287@menu
12288* Nindy Startup:: Startup with Nindy
12289* Nindy Options:: Options for Nindy
12290* Nindy Reset:: Nindy reset command
12291@end menu
12292
6d2ebf8b 12293@node Nindy Startup
104c1213
JM
12294@subsubsection Startup with Nindy
12295
12296If you simply start @code{@value{GDBP}} without using any command-line
12297options, you are prompted for what serial port to use, @emph{before} you
12298reach the ordinary @value{GDBN} prompt:
12299
12300@example
5d161b24 12301Attach /dev/ttyNN -- specify NN, or "quit" to quit:
104c1213
JM
12302@end example
12303
12304@noindent
12305Respond to the prompt with whatever suffix (after @samp{/dev/tty})
12306identifies the serial port you want to use. You can, if you choose,
12307simply start up with no Nindy connection by responding to the prompt
12308with an empty line. If you do this and later wish to attach to Nindy,
12309use @code{target} (@pxref{Target Commands, ,Commands for managing targets}).
12310
6d2ebf8b 12311@node Nindy Options
104c1213
JM
12312@subsubsection Options for Nindy
12313
12314These are the startup options for beginning your @value{GDBN} session with a
12315Nindy-960 board attached:
12316
12317@table @code
12318@item -r @var{port}
12319Specify the serial port name of a serial interface to be used to connect
12320to the target system. This option is only available when @value{GDBN} is
12321configured for the Intel 960 target architecture. You may specify
12322@var{port} as any of: a full pathname (e.g. @samp{-r /dev/ttya}), a
12323device name in @file{/dev} (e.g. @samp{-r ttya}), or simply the unique
12324suffix for a specific @code{tty} (e.g. @samp{-r a}).
12325
12326@item -O
12327(An uppercase letter ``O'', not a zero.) Specify that @value{GDBN} should use
12328the ``old'' Nindy monitor protocol to connect to the target system.
12329This option is only available when @value{GDBN} is configured for the Intel 960
12330target architecture.
12331
12332@quotation
12333@emph{Warning:} if you specify @samp{-O}, but are actually trying to
12334connect to a target system that expects the newer protocol, the connection
12335fails, appearing to be a speed mismatch. @value{GDBN} repeatedly
12336attempts to reconnect at several different line speeds. You can abort
12337this process with an interrupt.
12338@end quotation
12339
12340@item -brk
12341Specify that @value{GDBN} should first send a @code{BREAK} signal to the target
12342system, in an attempt to reset it, before connecting to a Nindy target.
12343
12344@quotation
12345@emph{Warning:} Many target systems do not have the hardware that this
12346requires; it only works with a few boards.
12347@end quotation
12348@end table
12349
12350The standard @samp{-b} option controls the line speed used on the serial
12351port.
12352
12353@c @group
6d2ebf8b 12354@node Nindy Reset
104c1213
JM
12355@subsubsection Nindy reset command
12356
12357@table @code
12358@item reset
12359@kindex reset
12360For a Nindy target, this command sends a ``break'' to the remote target
12361system; this is only useful if the target has been equipped with a
12362circuit to perform a hard reset (or some other interesting action) when
12363a break is detected.
12364@end table
12365@c @end group
12366
6d2ebf8b 12367@node M32R/D
104c1213
JM
12368@subsection Mitsubishi M32R/D
12369
12370@table @code
12371
12372@kindex target m32r
12373@item target m32r @var{dev}
12374Mitsubishi M32R/D ROM monitor.
12375
12376@end table
12377
6d2ebf8b 12378@node M68K
104c1213
JM
12379@subsection M68k
12380
12381The Motorola m68k configuration includes ColdFire support, and
12382target command for the following ROM monitors.
12383
12384@table @code
12385
12386@kindex target abug
12387@item target abug @var{dev}
12388ABug ROM monitor for M68K.
12389
12390@kindex target cpu32bug
12391@item target cpu32bug @var{dev}
12392CPU32BUG monitor, running on a CPU32 (M68K) board.
12393
12394@kindex target dbug
12395@item target dbug @var{dev}
12396dBUG ROM monitor for Motorola ColdFire.
12397
12398@kindex target est
12399@item target est @var{dev}
12400EST-300 ICE monitor, running on a CPU32 (M68K) board.
12401
12402@kindex target rom68k
12403@item target rom68k @var{dev}
12404ROM 68K monitor, running on an M68K IDP board.
12405
12406@end table
12407
12408If @value{GDBN} is configured with @code{m68*-ericsson-*}, it will
12409instead have only a single special target command:
12410
12411@table @code
12412
12413@kindex target es1800
12414@item target es1800 @var{dev}
12415ES-1800 emulator for M68K.
12416
12417@end table
12418
12419[context?]
12420
12421@table @code
12422
12423@kindex target rombug
12424@item target rombug @var{dev}
12425ROMBUG ROM monitor for OS/9000.
12426
12427@end table
12428
6d2ebf8b 12429@node M88K
104c1213
JM
12430@subsection M88K
12431
12432@table @code
12433
12434@kindex target bug
12435@item target bug @var{dev}
12436BUG monitor, running on a MVME187 (m88k) board.
12437
12438@end table
12439
6d2ebf8b 12440@node MIPS Embedded
104c1213
JM
12441@subsection MIPS Embedded
12442
12443@cindex MIPS boards
12444@value{GDBN} can use the MIPS remote debugging protocol to talk to a
12445MIPS board attached to a serial line. This is available when
12446you configure @value{GDBN} with @samp{--target=mips-idt-ecoff}.
12447
12448@need 1000
12449Use these @value{GDBN} commands to specify the connection to your target board:
12450
12451@table @code
12452@item target mips @var{port}
12453@kindex target mips @var{port}
12454To run a program on the board, start up @code{@value{GDBP}} with the
12455name of your program as the argument. To connect to the board, use the
12456command @samp{target mips @var{port}}, where @var{port} is the name of
12457the serial port connected to the board. If the program has not already
12458been downloaded to the board, you may use the @code{load} command to
12459download it. You can then use all the usual @value{GDBN} commands.
12460
12461For example, this sequence connects to the target board through a serial
12462port, and loads and runs a program called @var{prog} through the
12463debugger:
12464
12465@example
12466host$ @value{GDBP} @var{prog}
2df3850c
JM
12467@value{GDBN} is free software and @dots{}
12468(@value{GDBP}) target mips /dev/ttyb
12469(@value{GDBP}) load @var{prog}
12470(@value{GDBP}) run
104c1213
JM
12471@end example
12472
12473@item target mips @var{hostname}:@var{portnumber}
12474On some @value{GDBN} host configurations, you can specify a TCP
12475connection (for instance, to a serial line managed by a terminal
12476concentrator) instead of a serial port, using the syntax
12477@samp{@var{hostname}:@var{portnumber}}.
12478
12479@item target pmon @var{port}
12480@kindex target pmon @var{port}
12481PMON ROM monitor.
12482
12483@item target ddb @var{port}
12484@kindex target ddb @var{port}
12485NEC's DDB variant of PMON for Vr4300.
12486
12487@item target lsi @var{port}
12488@kindex target lsi @var{port}
12489LSI variant of PMON.
12490
12491@kindex target r3900
12492@item target r3900 @var{dev}
12493Densan DVE-R3900 ROM monitor for Toshiba R3900 Mips.
12494
12495@kindex target array
12496@item target array @var{dev}
12497Array Tech LSI33K RAID controller board.
12498
12499@end table
12500
12501
12502@noindent
12503@value{GDBN} also supports these special commands for MIPS targets:
12504
12505@table @code
12506@item set processor @var{args}
12507@itemx show processor
12508@kindex set processor @var{args}
12509@kindex show processor
12510Use the @code{set processor} command to set the type of MIPS
12511processor when you want to access processor-type-specific registers.
5d161b24 12512For example, @code{set processor @var{r3041}} tells @value{GDBN}
96c405b3 12513to use the CPU registers appropriate for the 3041 chip.
5d161b24 12514Use the @code{show processor} command to see what MIPS processor @value{GDBN}
104c1213 12515is using. Use the @code{info reg} command to see what registers
5d161b24 12516@value{GDBN} is using.
104c1213
JM
12517
12518@item set mipsfpu double
12519@itemx set mipsfpu single
12520@itemx set mipsfpu none
12521@itemx show mipsfpu
12522@kindex set mipsfpu
12523@kindex show mipsfpu
12524@cindex MIPS remote floating point
12525@cindex floating point, MIPS remote
12526If your target board does not support the MIPS floating point
12527coprocessor, you should use the command @samp{set mipsfpu none} (if you
96a2c332 12528need this, you may wish to put the command in your @value{GDBN} init
104c1213
JM
12529file). This tells @value{GDBN} how to find the return value of
12530functions which return floating point values. It also allows
12531@value{GDBN} to avoid saving the floating point registers when calling
12532functions on the board. If you are using a floating point coprocessor
12533with only single precision floating point support, as on the @sc{r4650}
12534processor, use the command @samp{set mipsfpu single}. The default
12535double precision floating point coprocessor may be selected using
12536@samp{set mipsfpu double}.
12537
12538In previous versions the only choices were double precision or no
12539floating point, so @samp{set mipsfpu on} will select double precision
12540and @samp{set mipsfpu off} will select no floating point.
12541
12542As usual, you can inquire about the @code{mipsfpu} variable with
12543@samp{show mipsfpu}.
12544
12545@item set remotedebug @var{n}
12546@itemx show remotedebug
d4f3574e
SS
12547@kindex set remotedebug@r{, MIPS protocol}
12548@kindex show remotedebug@r{, MIPS protocol}
104c1213
JM
12549@cindex @code{remotedebug}, MIPS protocol
12550@cindex MIPS @code{remotedebug} protocol
12551@c FIXME! For this to be useful, you must know something about the MIPS
12552@c FIXME...protocol. Where is it described?
12553You can see some debugging information about communications with the board
12554by setting the @code{remotedebug} variable. If you set it to @code{1} using
12555@samp{set remotedebug 1}, every packet is displayed. If you set it
12556to @code{2}, every character is displayed. You can check the current value
12557at any time with the command @samp{show remotedebug}.
12558
12559@item set timeout @var{seconds}
12560@itemx set retransmit-timeout @var{seconds}
12561@itemx show timeout
12562@itemx show retransmit-timeout
12563@cindex @code{timeout}, MIPS protocol
12564@cindex @code{retransmit-timeout}, MIPS protocol
12565@kindex set timeout
12566@kindex show timeout
12567@kindex set retransmit-timeout
12568@kindex show retransmit-timeout
12569You can control the timeout used while waiting for a packet, in the MIPS
12570remote protocol, with the @code{set timeout @var{seconds}} command. The
12571default is 5 seconds. Similarly, you can control the timeout used while
12572waiting for an acknowledgement of a packet with the @code{set
12573retransmit-timeout @var{seconds}} command. The default is 3 seconds.
12574You can inspect both values with @code{show timeout} and @code{show
12575retransmit-timeout}. (These commands are @emph{only} available when
12576@value{GDBN} is configured for @samp{--target=mips-idt-ecoff}.)
12577
12578The timeout set by @code{set timeout} does not apply when @value{GDBN}
12579is waiting for your program to stop. In that case, @value{GDBN} waits
12580forever because it has no way of knowing how long the program is going
12581to run before stopping.
12582@end table
12583
6d2ebf8b 12584@node PowerPC
104c1213
JM
12585@subsection PowerPC
12586
12587@table @code
12588
12589@kindex target dink32
12590@item target dink32 @var{dev}
12591DINK32 ROM monitor.
12592
12593@kindex target ppcbug
12594@item target ppcbug @var{dev}
12595@kindex target ppcbug1
12596@item target ppcbug1 @var{dev}
12597PPCBUG ROM monitor for PowerPC.
12598
12599@kindex target sds
12600@item target sds @var{dev}
12601SDS monitor, running on a PowerPC board (such as Motorola's ADS).
12602
12603@end table
12604
6d2ebf8b 12605@node PA
104c1213
JM
12606@subsection HP PA Embedded
12607
12608@table @code
12609
12610@kindex target op50n
12611@item target op50n @var{dev}
12612OP50N monitor, running on an OKI HPPA board.
12613
12614@kindex target w89k
12615@item target w89k @var{dev}
12616W89K monitor, running on a Winbond HPPA board.
12617
12618@end table
12619
6d2ebf8b 12620@node SH
104c1213
JM
12621@subsection Hitachi SH
12622
12623@table @code
12624
d4f3574e 12625@kindex target hms@r{, with Hitachi SH}
104c1213
JM
12626@item target hms @var{dev}
12627A Hitachi SH board attached via serial line to your host. Use special
12628commands @code{device} and @code{speed} to control the serial line and
12629the communications speed used.
12630
d4f3574e 12631@kindex target e7000@r{, with Hitachi SH}
104c1213
JM
12632@item target e7000 @var{dev}
12633E7000 emulator for Hitachi SH.
12634
d4f3574e
SS
12635@kindex target sh3@r{, with SH}
12636@kindex target sh3e@r{, with SH}
104c1213
JM
12637@item target sh3 @var{dev}
12638@item target sh3e @var{dev}
12639Hitachi SH-3 and SH-3E target systems.
12640
12641@end table
12642
6d2ebf8b 12643@node Sparclet
104c1213
JM
12644@subsection Tsqware Sparclet
12645
12646@cindex Sparclet
12647
5d161b24
DB
12648@value{GDBN} enables developers to debug tasks running on
12649Sparclet targets from a Unix host.
104c1213
JM
12650@value{GDBN} uses code that runs on
12651both the Unix host and on the Sparclet target. The program
5d161b24 12652@code{@value{GDBP}} is installed and executed on the Unix host.
104c1213
JM
12653
12654@table @code
f0ca3dce 12655@item remotetimeout @var{args}
104c1213 12656@kindex remotetimeout
5d161b24
DB
12657@value{GDBN} supports the option @code{remotetimeout}.
12658This option is set by the user, and @var{args} represents the number of
12659seconds @value{GDBN} waits for responses.
104c1213
JM
12660@end table
12661
41afff9a 12662@cindex compiling, on Sparclet
5d161b24 12663When compiling for debugging, include the options @samp{-g} to get debug
d4f3574e 12664information and @samp{-Ttext} to relocate the program to where you wish to
5d161b24 12665load it on the target. You may also want to add the options @samp{-n} or
d4f3574e 12666@samp{-N} in order to reduce the size of the sections. Example:
104c1213
JM
12667
12668@example
12669sparclet-aout-gcc prog.c -Ttext 0x12010000 -g -o prog -N
12670@end example
12671
d4f3574e 12672You can use @code{objdump} to verify that the addresses are what you intended:
104c1213
JM
12673
12674@example
12675sparclet-aout-objdump --headers --syms prog
12676@end example
12677
41afff9a 12678@cindex running, on Sparclet
104c1213
JM
12679Once you have set
12680your Unix execution search path to find @value{GDBN}, you are ready to
5d161b24 12681run @value{GDBN}. From your Unix host, run @code{@value{GDBP}}
104c1213
JM
12682(or @code{sparclet-aout-gdb}, depending on your installation).
12683
12684@value{GDBN} comes up showing the prompt:
12685
12686@example
12687(gdbslet)
12688@end example
12689
12690@menu
12691* Sparclet File:: Setting the file to debug
12692* Sparclet Connection:: Connecting to Sparclet
12693* Sparclet Download:: Sparclet download
5d161b24 12694* Sparclet Execution:: Running and debugging
104c1213
JM
12695@end menu
12696
6d2ebf8b 12697@node Sparclet File
104c1213
JM
12698@subsubsection Setting file to debug
12699
12700The @value{GDBN} command @code{file} lets you choose with program to debug.
12701
12702@example
12703(gdbslet) file prog
12704@end example
12705
12706@need 1000
12707@value{GDBN} then attempts to read the symbol table of @file{prog}.
12708@value{GDBN} locates
12709the file by searching the directories listed in the command search
12710path.
12711If the file was compiled with debug information (option "-g"), source
12712files will be searched as well.
12713@value{GDBN} locates
12714the source files by searching the directories listed in the directory search
12715path (@pxref{Environment, ,Your program's environment}).
12716If it fails
12717to find a file, it displays a message such as:
12718
12719@example
12720prog: No such file or directory.
12721@end example
12722
12723When this happens, add the appropriate directories to the search paths with
5d161b24 12724the @value{GDBN} commands @code{path} and @code{dir}, and execute the
104c1213
JM
12725@code{target} command again.
12726
6d2ebf8b 12727@node Sparclet Connection
104c1213
JM
12728@subsubsection Connecting to Sparclet
12729
12730The @value{GDBN} command @code{target} lets you connect to a Sparclet target.
12731To connect to a target on serial port ``@code{ttya}'', type:
12732
12733@example
12734(gdbslet) target sparclet /dev/ttya
12735Remote target sparclet connected to /dev/ttya
5d161b24 12736main () at ../prog.c:3
104c1213
JM
12737@end example
12738
12739@need 750
12740@value{GDBN} displays messages like these:
12741
d4f3574e 12742@example
104c1213 12743Connected to ttya.
d4f3574e 12744@end example
104c1213 12745
6d2ebf8b 12746@node Sparclet Download
104c1213
JM
12747@subsubsection Sparclet download
12748
12749@cindex download to Sparclet
5d161b24 12750Once connected to the Sparclet target,
104c1213
JM
12751you can use the @value{GDBN}
12752@code{load} command to download the file from the host to the target.
12753The file name and load offset should be given as arguments to the @code{load}
12754command.
5d161b24 12755Since the file format is aout, the program must be loaded to the starting
d4f3574e 12756address. You can use @code{objdump} to find out what this value is. The load
104c1213
JM
12757offset is an offset which is added to the VMA (virtual memory address)
12758of each of the file's sections.
12759For instance, if the program
12760@file{prog} was linked to text address 0x1201000, with data at 0x12010160
12761and bss at 0x12010170, in @value{GDBN}, type:
12762
12763@example
12764(gdbslet) load prog 0x12010000
12765Loading section .text, size 0xdb0 vma 0x12010000
12766@end example
12767
5d161b24
DB
12768If the code is loaded at a different address then what the program was linked
12769to, you may need to use the @code{section} and @code{add-symbol-file} commands
104c1213
JM
12770to tell @value{GDBN} where to map the symbol table.
12771
6d2ebf8b 12772@node Sparclet Execution
104c1213
JM
12773@subsubsection Running and debugging
12774
12775@cindex running and debugging Sparclet programs
12776You can now begin debugging the task using @value{GDBN}'s execution control
5d161b24 12777commands, @code{b}, @code{step}, @code{run}, etc. See the @value{GDBN}
104c1213
JM
12778manual for the list of commands.
12779
12780@example
12781(gdbslet) b main
12782Breakpoint 1 at 0x12010000: file prog.c, line 3.
5d161b24 12783(gdbslet) run
104c1213
JM
12784Starting program: prog
12785Breakpoint 1, main (argc=1, argv=0xeffff21c) at prog.c:3
127863 char *symarg = 0;
12787(gdbslet) step
127884 char *execarg = "hello!";
5d161b24 12789(gdbslet)
104c1213
JM
12790@end example
12791
6d2ebf8b 12792@node Sparclite
104c1213
JM
12793@subsection Fujitsu Sparclite
12794
12795@table @code
12796
12797@kindex target sparclite
12798@item target sparclite @var{dev}
5d161b24
DB
12799Fujitsu sparclite boards, used only for the purpose of loading.
12800You must use an additional command to debug the program.
12801For example: target remote @var{dev} using @value{GDBN} standard
104c1213
JM
12802remote protocol.
12803
12804@end table
12805
6d2ebf8b 12806@node ST2000
104c1213
JM
12807@subsection Tandem ST2000
12808
2df3850c 12809@value{GDBN} may be used with a Tandem ST2000 phone switch, running Tandem's
104c1213
JM
12810STDBUG protocol.
12811
12812To connect your ST2000 to the host system, see the manufacturer's
12813manual. Once the ST2000 is physically attached, you can run:
12814
12815@example
12816target st2000 @var{dev} @var{speed}
12817@end example
12818
12819@noindent
12820to establish it as your debugging environment. @var{dev} is normally
12821the name of a serial device, such as @file{/dev/ttya}, connected to the
12822ST2000 via a serial line. You can instead specify @var{dev} as a TCP
12823connection (for example, to a serial line attached via a terminal
12824concentrator) using the syntax @code{@var{hostname}:@var{portnumber}}.
12825
12826The @code{load} and @code{attach} commands are @emph{not} defined for
12827this target; you must load your program into the ST2000 as you normally
12828would for standalone operation. @value{GDBN} reads debugging information
12829(such as symbols) from a separate, debugging version of the program
12830available on your host computer.
12831@c FIXME!! This is terribly vague; what little content is here is
12832@c basically hearsay.
12833
12834@cindex ST2000 auxiliary commands
12835These auxiliary @value{GDBN} commands are available to help you with the ST2000
12836environment:
12837
12838@table @code
12839@item st2000 @var{command}
12840@kindex st2000 @var{cmd}
12841@cindex STDBUG commands (ST2000)
12842@cindex commands to STDBUG (ST2000)
12843Send a @var{command} to the STDBUG monitor. See the manufacturer's
12844manual for available commands.
12845
12846@item connect
12847@cindex connect (to STDBUG)
12848Connect the controlling terminal to the STDBUG command monitor. When
12849you are done interacting with STDBUG, typing either of two character
12850sequences gets you back to the @value{GDBN} command prompt:
12851@kbd{@key{RET}~.} (Return, followed by tilde and period) or
12852@kbd{@key{RET}~@key{C-d}} (Return, followed by tilde and control-D).
12853@end table
12854
6d2ebf8b 12855@node Z8000
104c1213
JM
12856@subsection Zilog Z8000
12857
12858@cindex Z8000
12859@cindex simulator, Z8000
12860@cindex Zilog Z8000 simulator
12861
12862When configured for debugging Zilog Z8000 targets, @value{GDBN} includes
12863a Z8000 simulator.
12864
12865For the Z8000 family, @samp{target sim} simulates either the Z8002 (the
12866unsegmented variant of the Z8000 architecture) or the Z8001 (the
12867segmented variant). The simulator recognizes which architecture is
12868appropriate by inspecting the object code.
12869
12870@table @code
12871@item target sim @var{args}
12872@kindex sim
d4f3574e 12873@kindex target sim@r{, with Z8000}
104c1213
JM
12874Debug programs on a simulated CPU. If the simulator supports setup
12875options, specify them via @var{args}.
12876@end table
12877
12878@noindent
12879After specifying this target, you can debug programs for the simulated
12880CPU in the same style as programs for your host computer; use the
12881@code{file} command to load a new program image, the @code{run} command
12882to run your program, and so on.
12883
d4f3574e
SS
12884As well as making available all the usual machine registers
12885(@pxref{Registers, ,Registers}), the Z8000 simulator provides three
12886additional items of information as specially named registers:
104c1213
JM
12887
12888@table @code
12889
12890@item cycles
12891Counts clock-ticks in the simulator.
12892
12893@item insts
12894Counts instructions run in the simulator.
12895
12896@item time
12897Execution time in 60ths of a second.
12898
12899@end table
12900
12901You can refer to these values in @value{GDBN} expressions with the usual
12902conventions; for example, @w{@samp{b fputc if $cycles>5000}} sets a
12903conditional breakpoint that suspends only after at least 5000
12904simulated clock ticks.
12905
6d2ebf8b 12906@node Architectures
104c1213
JM
12907@section Architectures
12908
12909This section describes characteristics of architectures that affect
2df3850c 12910all uses of @value{GDBN} with the architecture, both native and cross.
104c1213
JM
12911
12912@menu
12913* A29K::
12914* Alpha::
12915* MIPS::
12916@end menu
12917
6d2ebf8b 12918@node A29K
104c1213
JM
12919@subsection A29K
12920
12921@table @code
12922
12923@kindex set rstack_high_address
12924@cindex AMD 29K register stack
12925@cindex register stack, AMD29K
12926@item set rstack_high_address @var{address}
12927On AMD 29000 family processors, registers are saved in a separate
d4f3574e 12928@dfn{register stack}. There is no way for @value{GDBN} to determine the
104c1213
JM
12929extent of this stack. Normally, @value{GDBN} just assumes that the
12930stack is ``large enough''. This may result in @value{GDBN} referencing
12931memory locations that do not exist. If necessary, you can get around
12932this problem by specifying the ending address of the register stack with
12933the @code{set rstack_high_address} command. The argument should be an
12934address, which you probably want to precede with @samp{0x} to specify in
12935hexadecimal.
12936
12937@kindex show rstack_high_address
12938@item show rstack_high_address
12939Display the current limit of the register stack, on AMD 29000 family
12940processors.
12941
12942@end table
12943
6d2ebf8b 12944@node Alpha
104c1213
JM
12945@subsection Alpha
12946
12947See the following section.
12948
6d2ebf8b 12949@node MIPS
104c1213
JM
12950@subsection MIPS
12951
12952@cindex stack on Alpha
12953@cindex stack on MIPS
12954@cindex Alpha stack
12955@cindex MIPS stack
12956Alpha- and MIPS-based computers use an unusual stack frame, which
12957sometimes requires @value{GDBN} to search backward in the object code to
12958find the beginning of a function.
12959
12960@cindex response time, MIPS debugging
12961To improve response time (especially for embedded applications, where
12962@value{GDBN} may be restricted to a slow serial line for this search)
12963you may want to limit the size of this search, using one of these
12964commands:
12965
12966@table @code
00e4a2e4 12967@cindex @code{heuristic-fence-post} (Alpha, MIPS)
104c1213
JM
12968@item set heuristic-fence-post @var{limit}
12969Restrict @value{GDBN} to examining at most @var{limit} bytes in its
12970search for the beginning of a function. A value of @var{0} (the
12971default) means there is no limit. However, except for @var{0}, the
12972larger the limit the more bytes @code{heuristic-fence-post} must search
12973and therefore the longer it takes to run.
12974
12975@item show heuristic-fence-post
12976Display the current limit.
12977@end table
12978
12979@noindent
12980These commands are available @emph{only} when @value{GDBN} is configured
12981for debugging programs on Alpha or MIPS processors.
12982
12983
6d2ebf8b 12984@node Controlling GDB
c906108c
SS
12985@chapter Controlling @value{GDBN}
12986
53a5351d
JM
12987You can alter the way @value{GDBN} interacts with you by using the
12988@code{set} command. For commands controlling how @value{GDBN} displays
d4f3574e 12989data, see @ref{Print Settings, ,Print settings}. Other settings are
53a5351d 12990described here.
c906108c
SS
12991
12992@menu
12993* Prompt:: Prompt
12994* Editing:: Command editing
12995* History:: Command history
12996* Screen Size:: Screen size
12997* Numbers:: Numbers
12998* Messages/Warnings:: Optional warnings and messages
5d161b24 12999* Debugging Output:: Optional messages about internal happenings
c906108c
SS
13000@end menu
13001
6d2ebf8b 13002@node Prompt
c906108c
SS
13003@section Prompt
13004
13005@cindex prompt
13006
13007@value{GDBN} indicates its readiness to read a command by printing a string
13008called the @dfn{prompt}. This string is normally @samp{(@value{GDBP})}. You
13009can change the prompt string with the @code{set prompt} command. For
13010instance, when debugging @value{GDBN} with @value{GDBN}, it is useful to change
5d161b24 13011the prompt in one of the @value{GDBN} sessions so that you can always tell
c906108c
SS
13012which one you are talking to.
13013
d4f3574e 13014@emph{Note:} @code{set prompt} does not add a space for you after the
c906108c
SS
13015prompt you set. This allows you to set a prompt which ends in a space
13016or a prompt that does not.
13017
13018@table @code
13019@kindex set prompt
13020@item set prompt @var{newprompt}
13021Directs @value{GDBN} to use @var{newprompt} as its prompt string henceforth.
13022
13023@kindex show prompt
13024@item show prompt
13025Prints a line of the form: @samp{Gdb's prompt is: @var{your-prompt}}
13026@end table
13027
6d2ebf8b 13028@node Editing
c906108c
SS
13029@section Command editing
13030@cindex readline
13031@cindex command line editing
13032
13033@value{GDBN} reads its input commands via the @dfn{readline} interface. This
13034@sc{gnu} library provides consistent behavior for programs which provide a
13035command line interface to the user. Advantages are @sc{gnu} Emacs-style
13036or @dfn{vi}-style inline editing of commands, @code{csh}-like history
13037substitution, and a storage and recall of command history across
13038debugging sessions.
13039
13040You may control the behavior of command line editing in @value{GDBN} with the
13041command @code{set}.
13042
13043@table @code
13044@kindex set editing
13045@cindex editing
13046@item set editing
13047@itemx set editing on
13048Enable command line editing (enabled by default).
13049
13050@item set editing off
13051Disable command line editing.
13052
13053@kindex show editing
13054@item show editing
13055Show whether command line editing is enabled.
13056@end table
13057
6d2ebf8b 13058@node History
c906108c
SS
13059@section Command history
13060
13061@value{GDBN} can keep track of the commands you type during your
13062debugging sessions, so that you can be certain of precisely what
13063happened. Use these commands to manage the @value{GDBN} command
13064history facility.
13065
13066@table @code
13067@cindex history substitution
13068@cindex history file
13069@kindex set history filename
13070@kindex GDBHISTFILE
13071@item set history filename @var{fname}
13072Set the name of the @value{GDBN} command history file to @var{fname}.
13073This is the file where @value{GDBN} reads an initial command history
13074list, and where it writes the command history from this session when it
13075exits. You can access this list through history expansion or through
13076the history command editing characters listed below. This file defaults
13077to the value of the environment variable @code{GDBHISTFILE}, or to
d4f3574e
SS
13078@file{./.gdb_history} (@file{./_gdb_history} on MS-DOS) if this variable
13079is not set.
c906108c
SS
13080
13081@cindex history save
13082@kindex set history save
13083@item set history save
13084@itemx set history save on
13085Record command history in a file, whose name may be specified with the
13086@code{set history filename} command. By default, this option is disabled.
13087
13088@item set history save off
13089Stop recording command history in a file.
13090
13091@cindex history size
13092@kindex set history size
13093@item set history size @var{size}
13094Set the number of commands which @value{GDBN} keeps in its history list.
13095This defaults to the value of the environment variable
13096@code{HISTSIZE}, or to 256 if this variable is not set.
13097@end table
13098
13099@cindex history expansion
13100History expansion assigns special meaning to the character @kbd{!}.
13101@ifset have-readline-appendices
13102@xref{Event Designators}.
13103@end ifset
13104
13105Since @kbd{!} is also the logical not operator in C, history expansion
13106is off by default. If you decide to enable history expansion with the
13107@code{set history expansion on} command, you may sometimes need to
13108follow @kbd{!} (when it is used as logical not, in an expression) with
13109a space or a tab to prevent it from being expanded. The readline
13110history facilities do not attempt substitution on the strings
13111@kbd{!=} and @kbd{!(}, even when history expansion is enabled.
13112
13113The commands to control history expansion are:
13114
13115@table @code
13116@kindex set history expansion
13117@item set history expansion on
13118@itemx set history expansion
13119Enable history expansion. History expansion is off by default.
13120
13121@item set history expansion off
13122Disable history expansion.
13123
13124The readline code comes with more complete documentation of
13125editing and history expansion features. Users unfamiliar with @sc{gnu} Emacs
13126or @code{vi} may wish to read it.
13127@ifset have-readline-appendices
13128@xref{Command Line Editing}.
13129@end ifset
13130
13131@c @group
13132@kindex show history
13133@item show history
13134@itemx show history filename
13135@itemx show history save
13136@itemx show history size
13137@itemx show history expansion
13138These commands display the state of the @value{GDBN} history parameters.
13139@code{show history} by itself displays all four states.
13140@c @end group
13141@end table
13142
13143@table @code
41afff9a 13144@kindex shows
c906108c
SS
13145@item show commands
13146Display the last ten commands in the command history.
13147
13148@item show commands @var{n}
13149Print ten commands centered on command number @var{n}.
13150
13151@item show commands +
13152Print ten commands just after the commands last printed.
13153@end table
13154
6d2ebf8b 13155@node Screen Size
c906108c
SS
13156@section Screen size
13157@cindex size of screen
13158@cindex pauses in output
13159
13160Certain commands to @value{GDBN} may produce large amounts of
13161information output to the screen. To help you read all of it,
13162@value{GDBN} pauses and asks you for input at the end of each page of
13163output. Type @key{RET} when you want to continue the output, or @kbd{q}
13164to discard the remaining output. Also, the screen width setting
13165determines when to wrap lines of output. Depending on what is being
13166printed, @value{GDBN} tries to break the line at a readable place,
13167rather than simply letting it overflow onto the following line.
13168
d4f3574e
SS
13169Normally @value{GDBN} knows the size of the screen from the terminal
13170driver software. For example, on Unix @value{GDBN} uses the termcap data base
c906108c 13171together with the value of the @code{TERM} environment variable and the
d4f3574e 13172@code{stty rows} and @code{stty cols} settings. If this is not correct,
c906108c
SS
13173you can override it with the @code{set height} and @code{set
13174width} commands:
13175
13176@table @code
13177@kindex set height
13178@kindex set width
13179@kindex show width
13180@kindex show height
13181@item set height @var{lpp}
13182@itemx show height
13183@itemx set width @var{cpl}
13184@itemx show width
13185These @code{set} commands specify a screen height of @var{lpp} lines and
13186a screen width of @var{cpl} characters. The associated @code{show}
13187commands display the current settings.
13188
5d161b24
DB
13189If you specify a height of zero lines, @value{GDBN} does not pause during
13190output no matter how long the output is. This is useful if output is to a
c906108c
SS
13191file or to an editor buffer.
13192
13193Likewise, you can specify @samp{set width 0} to prevent @value{GDBN}
13194from wrapping its output.
13195@end table
13196
6d2ebf8b 13197@node Numbers
c906108c
SS
13198@section Numbers
13199@cindex number representation
13200@cindex entering numbers
13201
2df3850c
JM
13202You can always enter numbers in octal, decimal, or hexadecimal in
13203@value{GDBN} by the usual conventions: octal numbers begin with
13204@samp{0}, decimal numbers end with @samp{.}, and hexadecimal numbers
13205begin with @samp{0x}. Numbers that begin with none of these are, by
13206default, entered in base 10; likewise, the default display for
13207numbers---when no particular format is specified---is base 10. You can
13208change the default base for both input and output with the @code{set
13209radix} command.
c906108c
SS
13210
13211@table @code
13212@kindex set input-radix
13213@item set input-radix @var{base}
13214Set the default base for numeric input. Supported choices
13215for @var{base} are decimal 8, 10, or 16. @var{base} must itself be
13216specified either unambiguously or using the current default radix; for
13217example, any of
13218
13219@smallexample
13220set radix 012
13221set radix 10.
13222set radix 0xa
13223@end smallexample
13224
13225@noindent
13226sets the base to decimal. On the other hand, @samp{set radix 10}
13227leaves the radix unchanged no matter what it was.
13228
13229@kindex set output-radix
13230@item set output-radix @var{base}
13231Set the default base for numeric display. Supported choices
13232for @var{base} are decimal 8, 10, or 16. @var{base} must itself be
13233specified either unambiguously or using the current default radix.
13234
13235@kindex show input-radix
13236@item show input-radix
13237Display the current default base for numeric input.
13238
13239@kindex show output-radix
13240@item show output-radix
13241Display the current default base for numeric display.
13242@end table
13243
6d2ebf8b 13244@node Messages/Warnings
c906108c
SS
13245@section Optional warnings and messages
13246
2df3850c
JM
13247By default, @value{GDBN} is silent about its inner workings. If you are
13248running on a slow machine, you may want to use the @code{set verbose}
13249command. This makes @value{GDBN} tell you when it does a lengthy
13250internal operation, so you will not think it has crashed.
c906108c
SS
13251
13252Currently, the messages controlled by @code{set verbose} are those
13253which announce that the symbol table for a source file is being read;
13254see @code{symbol-file} in @ref{Files, ,Commands to specify files}.
13255
13256@table @code
13257@kindex set verbose
13258@item set verbose on
13259Enables @value{GDBN} output of certain informational messages.
13260
13261@item set verbose off
13262Disables @value{GDBN} output of certain informational messages.
13263
13264@kindex show verbose
13265@item show verbose
13266Displays whether @code{set verbose} is on or off.
13267@end table
13268
2df3850c
JM
13269By default, if @value{GDBN} encounters bugs in the symbol table of an
13270object file, it is silent; but if you are debugging a compiler, you may
13271find this information useful (@pxref{Symbol Errors, ,Errors reading
13272symbol files}).
c906108c
SS
13273
13274@table @code
2df3850c 13275
c906108c
SS
13276@kindex set complaints
13277@item set complaints @var{limit}
2df3850c
JM
13278Permits @value{GDBN} to output @var{limit} complaints about each type of
13279unusual symbols before becoming silent about the problem. Set
13280@var{limit} to zero to suppress all complaints; set it to a large number
13281to prevent complaints from being suppressed.
c906108c
SS
13282
13283@kindex show complaints
13284@item show complaints
13285Displays how many symbol complaints @value{GDBN} is permitted to produce.
2df3850c 13286
c906108c
SS
13287@end table
13288
13289By default, @value{GDBN} is cautious, and asks what sometimes seems to be a
13290lot of stupid questions to confirm certain commands. For example, if
13291you try to run a program which is already running:
13292
13293@example
13294(@value{GDBP}) run
13295The program being debugged has been started already.
13296Start it from the beginning? (y or n)
13297@end example
13298
13299If you are willing to unflinchingly face the consequences of your own
13300commands, you can disable this ``feature'':
13301
13302@table @code
2df3850c 13303
c906108c
SS
13304@kindex set confirm
13305@cindex flinching
13306@cindex confirmation
13307@cindex stupid questions
13308@item set confirm off
13309Disables confirmation requests.
13310
13311@item set confirm on
13312Enables confirmation requests (the default).
13313
13314@kindex show confirm
13315@item show confirm
13316Displays state of confirmation requests.
2df3850c 13317
c906108c
SS
13318@end table
13319
6d2ebf8b 13320@node Debugging Output
5d161b24
DB
13321@section Optional messages about internal happenings
13322@table @code
13323@kindex set debug arch
13324@item set debug arch
13325Turns on or off display of gdbarch debugging info. The default is off
13326@kindex show debug arch
13327@item show debug arch
13328Displays the current state of displaying gdbarch debugging info.
13329@kindex set debug event
13330@item set debug event
13331Turns on or off display of @value{GDBN} event debugging info. The
13332default is off.
13333@kindex show debug event
13334@item show debug event
13335Displays the current state of displaying @value{GDBN} event debugging
13336info.
13337@kindex set debug expression
13338@item set debug expression
13339Turns on or off display of @value{GDBN} expression debugging info. The
13340default is off.
13341@kindex show debug expression
13342@item show debug expression
13343Displays the current state of displaying @value{GDBN} expression
13344debugging info.
13345@kindex set debug overload
13346@item set debug overload
b37052ae 13347Turns on or off display of @value{GDBN} C@t{++} overload debugging
5d161b24
DB
13348info. This includes info such as ranking of functions, etc. The default
13349is off.
13350@kindex show debug overload
13351@item show debug overload
b37052ae 13352Displays the current state of displaying @value{GDBN} C@t{++} overload
5d161b24
DB
13353debugging info.
13354@kindex set debug remote
13355@cindex packets, reporting on stdout
13356@cindex serial connections, debugging
13357@item set debug remote
13358Turns on or off display of reports on all packets sent back and forth across
13359the serial line to the remote machine. The info is printed on the
13360@value{GDBN} standard output stream. The default is off.
13361@kindex show debug remote
13362@item show debug remote
13363Displays the state of display of remote packets.
13364@kindex set debug serial
13365@item set debug serial
13366Turns on or off display of @value{GDBN} serial debugging info. The
13367default is off.
13368@kindex show debug serial
13369@item show debug serial
13370Displays the current state of displaying @value{GDBN} serial debugging
13371info.
13372@kindex set debug target
13373@item set debug target
13374Turns on or off display of @value{GDBN} target debugging info. This info
13375includes what is going on at the target level of GDB, as it happens. The
13376default is off.
13377@kindex show debug target
13378@item show debug target
13379Displays the current state of displaying @value{GDBN} target debugging
13380info.
13381@kindex set debug varobj
13382@item set debug varobj
13383Turns on or off display of @value{GDBN} variable object debugging
13384info. The default is off.
13385@kindex show debug varobj
13386@item show debug varobj
13387Displays the current state of displaying @value{GDBN} variable object
13388debugging info.
13389@end table
13390
6d2ebf8b 13391@node Sequences
c906108c
SS
13392@chapter Canned Sequences of Commands
13393
13394Aside from breakpoint commands (@pxref{Break Commands, ,Breakpoint
2df3850c
JM
13395command lists}), @value{GDBN} provides two ways to store sequences of
13396commands for execution as a unit: user-defined commands and command
13397files.
c906108c
SS
13398
13399@menu
13400* Define:: User-defined commands
13401* Hooks:: User-defined command hooks
13402* Command Files:: Command files
13403* Output:: Commands for controlled output
13404@end menu
13405
6d2ebf8b 13406@node Define
c906108c
SS
13407@section User-defined commands
13408
13409@cindex user-defined command
2df3850c
JM
13410A @dfn{user-defined command} is a sequence of @value{GDBN} commands to
13411which you assign a new name as a command. This is done with the
13412@code{define} command. User commands may accept up to 10 arguments
13413separated by whitespace. Arguments are accessed within the user command
13414via @var{$arg0@dots{}$arg9}. A trivial example:
c906108c
SS
13415
13416@smallexample
13417define adder
13418 print $arg0 + $arg1 + $arg2
13419@end smallexample
13420
d4f3574e
SS
13421@noindent
13422To execute the command use:
c906108c
SS
13423
13424@smallexample
13425adder 1 2 3
13426@end smallexample
13427
d4f3574e
SS
13428@noindent
13429This defines the command @code{adder}, which prints the sum of
5d161b24 13430its three arguments. Note the arguments are text substitutions, so they may
c906108c
SS
13431reference variables, use complex expressions, or even perform inferior
13432functions calls.
13433
13434@table @code
2df3850c 13435
c906108c
SS
13436@kindex define
13437@item define @var{commandname}
13438Define a command named @var{commandname}. If there is already a command
13439by that name, you are asked to confirm that you want to redefine it.
13440
13441The definition of the command is made up of other @value{GDBN} command lines,
13442which are given following the @code{define} command. The end of these
13443commands is marked by a line containing @code{end}.
13444
13445@kindex if
13446@kindex else
13447@item if
13448Takes a single argument, which is an expression to evaluate.
13449It is followed by a series of commands that are executed
13450only if the expression is true (nonzero).
13451There can then optionally be a line @code{else}, followed
13452by a series of commands that are only executed if the expression
13453was false. The end of the list is marked by a line containing @code{end}.
13454
13455@kindex while
13456@item while
13457The syntax is similar to @code{if}: the command takes a single argument,
13458which is an expression to evaluate, and must be followed by the commands to
13459execute, one per line, terminated by an @code{end}.
13460The commands are executed repeatedly as long as the expression
13461evaluates to true.
13462
13463@kindex document
13464@item document @var{commandname}
13465Document the user-defined command @var{commandname}, so that it can be
5d161b24
DB
13466accessed by @code{help}. The command @var{commandname} must already be
13467defined. This command reads lines of documentation just as @code{define}
13468reads the lines of the command definition, ending with @code{end}.
13469After the @code{document} command is finished, @code{help} on command
c906108c
SS
13470@var{commandname} displays the documentation you have written.
13471
13472You may use the @code{document} command again to change the
13473documentation of a command. Redefining the command with @code{define}
13474does not change the documentation.
13475
13476@kindex help user-defined
13477@item help user-defined
13478List all user-defined commands, with the first line of the documentation
13479(if any) for each.
13480
13481@kindex show user
13482@item show user
13483@itemx show user @var{commandname}
2df3850c
JM
13484Display the @value{GDBN} commands used to define @var{commandname} (but
13485not its documentation). If no @var{commandname} is given, display the
c906108c 13486definitions for all user-defined commands.
2df3850c 13487
c906108c
SS
13488@end table
13489
13490When user-defined commands are executed, the
13491commands of the definition are not printed. An error in any command
13492stops execution of the user-defined command.
13493
13494If used interactively, commands that would ask for confirmation proceed
5d161b24
DB
13495without asking when used inside a user-defined command. Many @value{GDBN}
13496commands that normally print messages to say what they are doing omit the
c906108c
SS
13497messages when used in a user-defined command.
13498
6d2ebf8b 13499@node Hooks
c906108c 13500@section User-defined command hooks
d4f3574e
SS
13501@cindex command hooks
13502@cindex hooks, for commands
c78b4128 13503@cindex hooks, pre-command
c906108c 13504
c78b4128
EZ
13505@kindex hook
13506@kindex hook-
13507You may define @dfn{hooks}, which are a special kind of user-defined
c906108c
SS
13508command. Whenever you run the command @samp{foo}, if the user-defined
13509command @samp{hook-foo} exists, it is executed (with no arguments)
13510before that command.
13511
c78b4128
EZ
13512@cindex hooks, post-command
13513@kindex hookpost
13514@kindex hookpost-
13515A hook may also be defined which is run after the command you executed.
13516Whenever you run the command @samp{foo}, if the user-defined command
13517@samp{hookpost-foo} exists, it is executed (with no arguments) after
13518that command. Post-execution hooks may exist simultaneously with
13519pre-execution hooks, for the same command.
13520
13521It is valid for a hook to call the command which it hooks. If this
13522occurs, the hook is not re-executed, thereby avoiding infinte recursion.
13523
13524@c It would be nice if hookpost could be passed a parameter indicating
13525@c if the command it hooks executed properly or not. FIXME!
13526
d4f3574e 13527@kindex stop@r{, a pseudo-command}
c906108c
SS
13528In addition, a pseudo-command, @samp{stop} exists. Defining
13529(@samp{hook-stop}) makes the associated commands execute every time
13530execution stops in your program: before breakpoint commands are run,
13531displays are printed, or the stack frame is printed.
13532
c906108c
SS
13533For example, to ignore @code{SIGALRM} signals while
13534single-stepping, but treat them normally during normal execution,
13535you could define:
13536
13537@example
13538define hook-stop
13539handle SIGALRM nopass
13540end
13541
13542define hook-run
13543handle SIGALRM pass
13544end
13545
13546define hook-continue
13547handle SIGLARM pass
13548end
13549@end example
c906108c 13550
c78b4128
EZ
13551As a further example, to hook at the begining and end of the @code{echo}
13552command, and to add extra text to the beginning and end of the message,
13553you could define:
13554
13555@example
13556define hook-echo
13557echo <<<---
13558end
13559
13560define hookpost-echo
13561echo --->>>\n
13562end
13563
13564(@value{GDBP}) echo Hello World
13565<<<---Hello World--->>>
13566(@value{GDBP})
13567
13568@end example
13569
c906108c
SS
13570You can define a hook for any single-word command in @value{GDBN}, but
13571not for command aliases; you should define a hook for the basic command
13572name, e.g. @code{backtrace} rather than @code{bt}.
13573@c FIXME! So how does Joe User discover whether a command is an alias
13574@c or not?
13575If an error occurs during the execution of your hook, execution of
13576@value{GDBN} commands stops and @value{GDBN} issues a prompt
13577(before the command that you actually typed had a chance to run).
13578
13579If you try to define a hook which does not match any known command, you
13580get a warning from the @code{define} command.
13581
6d2ebf8b 13582@node Command Files
c906108c
SS
13583@section Command files
13584
13585@cindex command files
5d161b24
DB
13586A command file for @value{GDBN} is a file of lines that are @value{GDBN}
13587commands. Comments (lines starting with @kbd{#}) may also be included.
13588An empty line in a command file does nothing; it does not mean to repeat
c906108c
SS
13589the last command, as it would from the terminal.
13590
13591@cindex init file
13592@cindex @file{.gdbinit}
d4f3574e 13593@cindex @file{gdb.ini}
c906108c 13594When you start @value{GDBN}, it automatically executes commands from its
96565e91
CF
13595@dfn{init files}, normally called @file{.gdbinit}@footnote{The DJGPP
13596port of @value{GDBN} uses the name @file{gdb.ini} instead, due to the
13597limitations of file names imposed by DOS filesystems.}.
13598During startup, @value{GDBN} does the following:
bf0184be
ND
13599
13600@enumerate
13601@item
13602Reads the init file (if any) in your home directory@footnote{On
13603DOS/Windows systems, the home directory is the one pointed to by the
13604@code{HOME} environment variable.}.
13605
13606@item
13607Processes command line options and operands.
13608
13609@item
13610Reads the init file (if any) in the current working directory.
13611
13612@item
13613Reads command files specified by the @samp{-x} option.
13614@end enumerate
13615
13616The init file in your home directory can set options (such as @samp{set
13617complaints}) that affect subsequent processing of command line options
13618and operands. Init files are not executed if you use the @samp{-nx}
13619option (@pxref{Mode Options, ,Choosing modes}).
c906108c 13620
c906108c
SS
13621@cindex init file name
13622On some configurations of @value{GDBN}, the init file is known by a
13623different name (these are typically environments where a specialized
13624form of @value{GDBN} may need to coexist with other forms, hence a
13625different name for the specialized version's init file). These are the
13626environments with special init file names:
13627
00e4a2e4 13628@cindex @file{.vxgdbinit}
c906108c
SS
13629@itemize @bullet
13630@item
00e4a2e4 13631VxWorks (Wind River Systems real-time OS): @file{.vxgdbinit}
c906108c 13632
00e4a2e4 13633@cindex @file{.os68gdbinit}
c906108c 13634@item
00e4a2e4 13635OS68K (Enea Data Systems real-time OS): @file{.os68gdbinit}
c906108c 13636
00e4a2e4 13637@cindex @file{.esgdbinit}
c906108c 13638@item
00e4a2e4 13639ES-1800 (Ericsson Telecom AB M68000 emulator): @file{.esgdbinit}
c906108c 13640@end itemize
c906108c
SS
13641
13642You can also request the execution of a command file with the
13643@code{source} command:
13644
13645@table @code
13646@kindex source
13647@item source @var{filename}
13648Execute the command file @var{filename}.
13649@end table
13650
13651The lines in a command file are executed sequentially. They are not
13652printed as they are executed. An error in any command terminates execution
13653of the command file.
13654
13655Commands that would ask for confirmation if used interactively proceed
13656without asking when used in a command file. Many @value{GDBN} commands that
13657normally print messages to say what they are doing omit the messages
13658when called from command files.
13659
b433d00b
DH
13660@value{GDBN} also accepts command input from standard input. In this
13661mode, normal output goes to standard output and error output goes to
13662standard error. Errors in a command file supplied on standard input do
13663not terminate execution of the command file --- execution continues with
13664the next command.
13665
13666@example
13667gdb < cmds > log 2>&1
13668@end example
13669
13670(The syntax above will vary depending on the shell used.) This example
13671will execute commands from the file @file{cmds}. All output and errors
13672would be directed to @file{log}.
13673
6d2ebf8b 13674@node Output
c906108c
SS
13675@section Commands for controlled output
13676
13677During the execution of a command file or a user-defined command, normal
13678@value{GDBN} output is suppressed; the only output that appears is what is
13679explicitly printed by the commands in the definition. This section
13680describes three commands useful for generating exactly the output you
13681want.
13682
13683@table @code
13684@kindex echo
13685@item echo @var{text}
13686@c I do not consider backslash-space a standard C escape sequence
13687@c because it is not in ANSI.
13688Print @var{text}. Nonprinting characters can be included in
13689@var{text} using C escape sequences, such as @samp{\n} to print a
13690newline. @strong{No newline is printed unless you specify one.}
13691In addition to the standard C escape sequences, a backslash followed
13692by a space stands for a space. This is useful for displaying a
13693string with spaces at the beginning or the end, since leading and
5d161b24 13694trailing spaces are otherwise trimmed from all arguments.
c906108c
SS
13695To print @samp{@w{ }and foo =@w{ }}, use the command
13696@samp{echo \@w{ }and foo = \@w{ }}.
13697
13698A backslash at the end of @var{text} can be used, as in C, to continue
13699the command onto subsequent lines. For example,
13700
13701@example
13702echo This is some text\n\
13703which is continued\n\
13704onto several lines.\n
13705@end example
13706
13707produces the same output as
13708
13709@example
13710echo This is some text\n
13711echo which is continued\n
13712echo onto several lines.\n
13713@end example
13714
13715@kindex output
13716@item output @var{expression}
13717Print the value of @var{expression} and nothing but that value: no
13718newlines, no @samp{$@var{nn} = }. The value is not entered in the
5d161b24 13719value history either. @xref{Expressions, ,Expressions}, for more information
c906108c
SS
13720on expressions.
13721
13722@item output/@var{fmt} @var{expression}
13723Print the value of @var{expression} in format @var{fmt}. You can use
13724the same formats as for @code{print}. @xref{Output Formats,,Output
13725formats}, for more information.
13726
13727@kindex printf
13728@item printf @var{string}, @var{expressions}@dots{}
13729Print the values of the @var{expressions} under the control of
13730@var{string}. The @var{expressions} are separated by commas and may be
13731either numbers or pointers. Their values are printed as specified by
13732@var{string}, exactly as if your program were to execute the C
13733subroutine
d4f3574e
SS
13734@c FIXME: the above implies that at least all ANSI C formats are
13735@c supported, but it isn't true: %E and %G don't work (or so it seems).
13736@c Either this is a bug, or the manual should document what formats are
13737@c supported.
c906108c
SS
13738
13739@example
13740printf (@var{string}, @var{expressions}@dots{});
13741@end example
13742
13743For example, you can print two values in hex like this:
13744
13745@smallexample
13746printf "foo, bar-foo = 0x%x, 0x%x\n", foo, bar-foo
13747@end smallexample
13748
13749The only backslash-escape sequences that you can use in the format
13750string are the simple ones that consist of backslash followed by a
13751letter.
13752@end table
13753
c4555f82
SC
13754@node TUI
13755@chapter @value{GDBN} Text User Interface
13756@cindex TUI
13757
13758@menu
13759* TUI Overview:: TUI overview
13760* TUI Keys:: TUI key bindings
13761* TUI Commands:: TUI specific commands
13762* TUI Configuration:: TUI configuration variables
13763@end menu
13764
13765The @value{GDBN} Text User Interface, TUI in short,
13766is a terminal interface which uses the @code{curses} library
13767to show the source file, the assembly output, the program registers
13768and @value{GDBN} commands in separate text windows.
13769The TUI is available only when @value{GDBN} is configured
13770with the @code{--enable-tui} configure option (@pxref{Configure Options}).
13771
13772@node TUI Overview
13773@section TUI overview
13774
13775The TUI has two display modes that can be switched while
13776@value{GDBN} runs:
13777
13778@itemize @bullet
13779@item
13780A curses (or TUI) mode in which it displays several text
13781windows on the terminal.
13782
13783@item
13784A standard mode which corresponds to the @value{GDBN} configured without
13785the TUI.
13786@end itemize
13787
13788In the TUI mode, @value{GDBN} can display several text window
13789on the terminal:
13790
13791@table @emph
13792@item command
13793This window is the @value{GDBN} command window with the @value{GDBN}
13794prompt and the @value{GDBN} outputs. The @value{GDBN} input is still
13795managed using readline but through the TUI. The @emph{command}
13796window is always visible.
13797
13798@item source
13799The source window shows the source file of the program. The current
13800line as well as active breakpoints are displayed in this window.
13801The current program position is shown with the @samp{>} marker and
13802active breakpoints are shown with @samp{*} markers.
13803
13804@item assembly
13805The assembly window shows the disassembly output of the program.
13806
13807@item register
13808This window shows the processor registers. It detects when
13809a register is changed and when this is the case, registers that have
13810changed are highlighted.
13811
13812@end table
13813
13814The source, assembly and register windows are attached to the thread
13815and the frame position. They are updated when the current thread
13816changes, when the frame changes or when the program counter changes.
13817These three windows are arranged by the TUI according to several
13818layouts. The layout defines which of these three windows are visible.
13819The following layouts are available:
13820
13821@itemize @bullet
13822@item
13823source
13824
13825@item
13826assembly
13827
13828@item
13829source and assembly
13830
13831@item
13832source and registers
13833
13834@item
13835assembly and registers
13836
13837@end itemize
13838
13839@node TUI Keys
13840@section TUI Key Bindings
13841@cindex TUI key bindings
13842
13843The TUI installs several key bindings in the readline keymaps
13844(@pxref{Command Line Editing}).
13845They allow to leave or enter in the TUI mode or they operate
13846directly on the TUI layout and windows. The following key bindings
13847are installed for both TUI mode and the @value{GDBN} standard mode.
13848
13849@table @kbd
13850@kindex C-x C-a
13851@item C-x C-a
13852@kindex C-x a
13853@itemx C-x a
13854@kindex C-x A
13855@itemx C-x A
13856Enter or leave the TUI mode. When the TUI mode is left,
13857the curses window management is left and @value{GDBN} operates using
13858its standard mode writing on the terminal directly. When the TUI
13859mode is entered, the control is given back to the curses windows.
13860The screen is then refreshed.
13861
13862@kindex C-x 1
13863@item C-x 1
13864Use a TUI layout with only one window. The layout will
13865either be @samp{source} or @samp{assembly}. When the TUI mode
13866is not active, it will switch to the TUI mode.
13867
13868Think of this key binding as the Emacs @kbd{C-x 1} binding.
13869
13870@kindex C-x 2
13871@item C-x 2
13872Use a TUI layout with at least two windows. When the current
13873layout shows already two windows, a next layout with two windows is used.
13874When a new layout is chosen, one window will always be common to the
13875previous layout and the new one.
13876
13877Think of it as the Emacs @kbd{C-x 2} binding.
13878
13879@end table
13880
13881The following key bindings are handled only by the TUI mode:
13882
13883@table @key
13884@kindex PgUp
13885@item PgUp
13886Scroll the active window one page up.
13887
13888@kindex PgDn
13889@item PgDn
13890Scroll the active window one page down.
13891
13892@kindex Up
13893@item Up
13894Scroll the active window one line up.
13895
13896@kindex Down
13897@item Down
13898Scroll the active window one line down.
13899
13900@kindex Left
13901@item Left
13902Scroll the active window one column left.
13903
13904@kindex Right
13905@item Right
13906Scroll the active window one column right.
13907
13908@kindex C-L
13909@item C-L
13910Refresh the screen.
13911
13912@end table
13913
13914In the TUI mode, the arrow keys are used by the active window
13915for scrolling. This means they are not available for readline. It is
13916necessary to use other readline key bindings such as @key{C-p}, @key{C-n},
13917@key{C-b} and @key{C-f}.
13918
13919@node TUI Commands
13920@section TUI specific commands
13921@cindex TUI commands
13922
13923The TUI has specific commands to control the text windows.
13924These commands are always available, that is they do not depend on
13925the current terminal mode in which @value{GDBN} runs. When @value{GDBN}
13926is in the standard mode, using these commands will automatically switch
13927in the TUI mode.
13928
13929@table @code
13930@item layout next
13931@kindex layout next
13932Display the next layout.
13933
13934@item layout prev
13935@kindex layout prev
13936Display the previous layout.
13937
13938@item layout src
13939@kindex layout src
13940Display the source window only.
13941
13942@item layout asm
13943@kindex layout asm
13944Display the assembly window only.
13945
13946@item layout split
13947@kindex layout split
13948Display the source and assembly window.
13949
13950@item layout regs
13951@kindex layout regs
13952Display the register window together with the source or assembly window.
13953
13954@item focus next | prev | src | asm | regs | split
13955@kindex focus
13956Set the focus to the named window.
13957This command allows to change the active window so that scrolling keys
13958can be affected to another window.
13959
13960@item refresh
13961@kindex refresh
13962Refresh the screen. This is similar to using @key{C-L} key.
13963
13964@item update
13965@kindex update
13966Update the source window and the current execution point.
13967
13968@item winheight @var{name} +@var{count}
13969@itemx winheight @var{name} -@var{count}
13970@kindex winheight
13971Change the height of the window @var{name} by @var{count}
13972lines. Positive counts increase the height, while negative counts
13973decrease it.
13974
13975@end table
13976
13977@node TUI Configuration
13978@section TUI configuration variables
13979@cindex TUI configuration variables
13980
13981The TUI has several configuration variables that control the
13982appearance of windows on the terminal.
13983
13984@table @code
732b3002
SC
13985@item set tui border-kind @var{kind}
13986@kindex set tui border-kind
c4555f82
SC
13987Select the border appearance for the source, assembly and register windows.
13988The possible values are the following:
13989@table @code
13990@item space
13991Use a space character to draw the border.
13992
13993@item ascii
13994Use ascii characters + - and | to draw the border.
13995
13996@item acs
13997Use the Alternate Character Set to draw the border. The border is
13998drawn using character line graphics if the terminal supports them.
13999
14000@end table
14001
732b3002
SC
14002@item set tui active-border-mode @var{mode}
14003@kindex set tui active-border-mode
c4555f82
SC
14004Select the attributes to display the border of the active window.
14005The possible values are @code{normal}, @code{standout}, @code{reverse},
14006@code{half}, @code{half-standout}, @code{bold} and @code{bold-standout}.
14007
732b3002
SC
14008@item set tui border-mode @var{mode}
14009@kindex set tui border-mode
c4555f82
SC
14010Select the attributes to display the border of other windows.
14011The @var{mode} can be one of the following:
14012@table @code
14013@item normal
14014Use normal attributes to display the border.
14015
14016@item standout
14017Use standout mode.
14018
14019@item reverse
14020Use reverse video mode.
14021
14022@item half
14023Use half bright mode.
14024
14025@item half-standout
14026Use half bright and standout mode.
14027
14028@item bold
14029Use extra bright or bold mode.
14030
14031@item bold-standout
14032Use extra bright or bold and standout mode.
14033
14034@end table
14035
14036@end table
14037
6d2ebf8b 14038@node Emacs
c906108c
SS
14039@chapter Using @value{GDBN} under @sc{gnu} Emacs
14040
14041@cindex Emacs
14042@cindex @sc{gnu} Emacs
14043A special interface allows you to use @sc{gnu} Emacs to view (and
14044edit) the source files for the program you are debugging with
14045@value{GDBN}.
14046
14047To use this interface, use the command @kbd{M-x gdb} in Emacs. Give the
14048executable file you want to debug as an argument. This command starts
14049@value{GDBN} as a subprocess of Emacs, with input and output through a newly
14050created Emacs buffer.
53a5351d 14051@c (Do not use the @code{-tui} option to run @value{GDBN} from Emacs.)
c906108c
SS
14052
14053Using @value{GDBN} under Emacs is just like using @value{GDBN} normally except for two
14054things:
14055
14056@itemize @bullet
14057@item
14058All ``terminal'' input and output goes through the Emacs buffer.
14059@end itemize
14060
14061This applies both to @value{GDBN} commands and their output, and to the input
14062and output done by the program you are debugging.
14063
14064This is useful because it means that you can copy the text of previous
14065commands and input them again; you can even use parts of the output
14066in this way.
14067
14068All the facilities of Emacs' Shell mode are available for interacting
14069with your program. In particular, you can send signals the usual
14070way---for example, @kbd{C-c C-c} for an interrupt, @kbd{C-c C-z} for a
14071stop.
14072
14073@itemize @bullet
14074@item
14075@value{GDBN} displays source code through Emacs.
14076@end itemize
14077
14078Each time @value{GDBN} displays a stack frame, Emacs automatically finds the
14079source file for that frame and puts an arrow (@samp{=>}) at the
14080left margin of the current line. Emacs uses a separate buffer for
14081source display, and splits the screen to show both your @value{GDBN} session
14082and the source.
14083
14084Explicit @value{GDBN} @code{list} or search commands still produce output as
14085usual, but you probably have no reason to use them from Emacs.
14086
14087@quotation
14088@emph{Warning:} If the directory where your program resides is not your
14089current directory, it can be easy to confuse Emacs about the location of
14090the source files, in which case the auxiliary display buffer does not
14091appear to show your source. @value{GDBN} can find programs by searching your
14092environment's @code{PATH} variable, so the @value{GDBN} input and output
14093session proceeds normally; but Emacs does not get enough information
14094back from @value{GDBN} to locate the source files in this situation. To
14095avoid this problem, either start @value{GDBN} mode from the directory where
14096your program resides, or specify an absolute file name when prompted for the
14097@kbd{M-x gdb} argument.
14098
14099A similar confusion can result if you use the @value{GDBN} @code{file} command to
14100switch to debugging a program in some other location, from an existing
14101@value{GDBN} buffer in Emacs.
14102@end quotation
14103
14104By default, @kbd{M-x gdb} calls the program called @file{gdb}. If
14105you need to call @value{GDBN} by a different name (for example, if you keep
14106several configurations around, with different names) you can set the
14107Emacs variable @code{gdb-command-name}; for example,
14108
14109@example
14110(setq gdb-command-name "mygdb")
14111@end example
14112
14113@noindent
d4f3574e 14114(preceded by @kbd{M-:} or @kbd{ESC :}, or typed in the @code{*scratch*} buffer, or
c906108c
SS
14115in your @file{.emacs} file) makes Emacs call the program named
14116``@code{mygdb}'' instead.
14117
14118In the @value{GDBN} I/O buffer, you can use these special Emacs commands in
14119addition to the standard Shell mode commands:
14120
14121@table @kbd
14122@item C-h m
14123Describe the features of Emacs' @value{GDBN} Mode.
14124
14125@item M-s
14126Execute to another source line, like the @value{GDBN} @code{step} command; also
14127update the display window to show the current file and location.
14128
14129@item M-n
14130Execute to next source line in this function, skipping all function
14131calls, like the @value{GDBN} @code{next} command. Then update the display window
14132to show the current file and location.
14133
14134@item M-i
14135Execute one instruction, like the @value{GDBN} @code{stepi} command; update
14136display window accordingly.
14137
14138@item M-x gdb-nexti
14139Execute to next instruction, using the @value{GDBN} @code{nexti} command; update
14140display window accordingly.
14141
14142@item C-c C-f
14143Execute until exit from the selected stack frame, like the @value{GDBN}
14144@code{finish} command.
14145
14146@item M-c
14147Continue execution of your program, like the @value{GDBN} @code{continue}
14148command.
14149
14150@emph{Warning:} In Emacs v19, this command is @kbd{C-c C-p}.
14151
14152@item M-u
14153Go up the number of frames indicated by the numeric argument
14154(@pxref{Arguments, , Numeric Arguments, Emacs, The @sc{gnu} Emacs Manual}),
14155like the @value{GDBN} @code{up} command.
14156
14157@emph{Warning:} In Emacs v19, this command is @kbd{C-c C-u}.
14158
14159@item M-d
14160Go down the number of frames indicated by the numeric argument, like the
14161@value{GDBN} @code{down} command.
14162
14163@emph{Warning:} In Emacs v19, this command is @kbd{C-c C-d}.
14164
14165@item C-x &
14166Read the number where the cursor is positioned, and insert it at the end
14167of the @value{GDBN} I/O buffer. For example, if you wish to disassemble code
14168around an address that was displayed earlier, type @kbd{disassemble};
14169then move the cursor to the address display, and pick up the
14170argument for @code{disassemble} by typing @kbd{C-x &}.
14171
14172You can customize this further by defining elements of the list
14173@code{gdb-print-command}; once it is defined, you can format or
14174otherwise process numbers picked up by @kbd{C-x &} before they are
14175inserted. A numeric argument to @kbd{C-x &} indicates that you
14176wish special formatting, and also acts as an index to pick an element of the
14177list. If the list element is a string, the number to be inserted is
14178formatted using the Emacs function @code{format}; otherwise the number
14179is passed as an argument to the corresponding list element.
14180@end table
14181
14182In any source file, the Emacs command @kbd{C-x SPC} (@code{gdb-break})
14183tells @value{GDBN} to set a breakpoint on the source line point is on.
14184
14185If you accidentally delete the source-display buffer, an easy way to get
14186it back is to type the command @code{f} in the @value{GDBN} buffer, to
14187request a frame display; when you run under Emacs, this recreates
14188the source buffer if necessary to show you the context of the current
14189frame.
14190
14191The source files displayed in Emacs are in ordinary Emacs buffers
14192which are visiting the source files in the usual way. You can edit
14193the files with these buffers if you wish; but keep in mind that @value{GDBN}
14194communicates with Emacs in terms of line numbers. If you add or
14195delete lines from the text, the line numbers that @value{GDBN} knows cease
14196to correspond properly with the code.
14197
14198@c The following dropped because Epoch is nonstandard. Reactivate
14199@c if/when v19 does something similar. ---doc@cygnus.com 19dec1990
14200@ignore
14201@kindex Emacs Epoch environment
14202@kindex Epoch
14203@kindex inspect
14204
5d161b24 14205Version 18 of @sc{gnu} Emacs has a built-in window system
c906108c
SS
14206called the @code{epoch}
14207environment. Users of this environment can use a new command,
14208@code{inspect} which performs identically to @code{print} except that
14209each value is printed in its own window.
14210@end ignore
c906108c 14211
d700128c 14212@include annotate.texi
7162c0ca 14213@include gdbmi.texinfo
d700128c 14214
6d2ebf8b 14215@node GDB Bugs
c906108c
SS
14216@chapter Reporting Bugs in @value{GDBN}
14217@cindex bugs in @value{GDBN}
14218@cindex reporting bugs in @value{GDBN}
14219
14220Your bug reports play an essential role in making @value{GDBN} reliable.
14221
14222Reporting a bug may help you by bringing a solution to your problem, or it
14223may not. But in any case the principal function of a bug report is to help
14224the entire community by making the next version of @value{GDBN} work better. Bug
14225reports are your contribution to the maintenance of @value{GDBN}.
14226
14227In order for a bug report to serve its purpose, you must include the
14228information that enables us to fix the bug.
14229
14230@menu
14231* Bug Criteria:: Have you found a bug?
14232* Bug Reporting:: How to report bugs
14233@end menu
14234
6d2ebf8b 14235@node Bug Criteria
c906108c
SS
14236@section Have you found a bug?
14237@cindex bug criteria
14238
14239If you are not sure whether you have found a bug, here are some guidelines:
14240
14241@itemize @bullet
14242@cindex fatal signal
14243@cindex debugger crash
14244@cindex crash of debugger
14245@item
14246If the debugger gets a fatal signal, for any input whatever, that is a
14247@value{GDBN} bug. Reliable debuggers never crash.
14248
14249@cindex error on valid input
14250@item
14251If @value{GDBN} produces an error message for valid input, that is a
14252bug. (Note that if you're cross debugging, the problem may also be
14253somewhere in the connection to the target.)
14254
14255@cindex invalid input
14256@item
14257If @value{GDBN} does not produce an error message for invalid input,
14258that is a bug. However, you should note that your idea of
14259``invalid input'' might be our idea of ``an extension'' or ``support
14260for traditional practice''.
14261
14262@item
14263If you are an experienced user of debugging tools, your suggestions
14264for improvement of @value{GDBN} are welcome in any case.
14265@end itemize
14266
6d2ebf8b 14267@node Bug Reporting
c906108c
SS
14268@section How to report bugs
14269@cindex bug reports
14270@cindex @value{GDBN} bugs, reporting
14271
c906108c
SS
14272A number of companies and individuals offer support for @sc{gnu} products.
14273If you obtained @value{GDBN} from a support organization, we recommend you
14274contact that organization first.
14275
14276You can find contact information for many support companies and
14277individuals in the file @file{etc/SERVICE} in the @sc{gnu} Emacs
14278distribution.
14279@c should add a web page ref...
14280
14281In any event, we also recommend that you send bug reports for
14282@value{GDBN} to this addresses:
14283
14284@example
d4f3574e 14285bug-gdb@@gnu.org
c906108c
SS
14286@end example
14287
14288@strong{Do not send bug reports to @samp{info-gdb}, or to
d4f3574e 14289@samp{help-gdb}, or to any newsgroups.} Most users of @value{GDBN} do
c906108c
SS
14290not want to receive bug reports. Those that do have arranged to receive
14291@samp{bug-gdb}.
14292
14293The mailing list @samp{bug-gdb} has a newsgroup @samp{gnu.gdb.bug} which
14294serves as a repeater. The mailing list and the newsgroup carry exactly
14295the same messages. Often people think of posting bug reports to the
14296newsgroup instead of mailing them. This appears to work, but it has one
14297problem which can be crucial: a newsgroup posting often lacks a mail
14298path back to the sender. Thus, if we need to ask for more information,
14299we may be unable to reach you. For this reason, it is better to send
14300bug reports to the mailing list.
14301
14302As a last resort, send bug reports on paper to:
14303
14304@example
14305@sc{gnu} Debugger Bugs
14306Free Software Foundation Inc.
1430759 Temple Place - Suite 330
14308Boston, MA 02111-1307
14309USA
14310@end example
c906108c
SS
14311
14312The fundamental principle of reporting bugs usefully is this:
14313@strong{report all the facts}. If you are not sure whether to state a
14314fact or leave it out, state it!
14315
14316Often people omit facts because they think they know what causes the
14317problem and assume that some details do not matter. Thus, you might
14318assume that the name of the variable you use in an example does not matter.
14319Well, probably it does not, but one cannot be sure. Perhaps the bug is a
14320stray memory reference which happens to fetch from the location where that
14321name is stored in memory; perhaps, if the name were different, the contents
14322of that location would fool the debugger into doing the right thing despite
14323the bug. Play it safe and give a specific, complete example. That is the
14324easiest thing for you to do, and the most helpful.
14325
14326Keep in mind that the purpose of a bug report is to enable us to fix the
14327bug. It may be that the bug has been reported previously, but neither
14328you nor we can know that unless your bug report is complete and
14329self-contained.
14330
14331Sometimes people give a few sketchy facts and ask, ``Does this ring a
14332bell?'' Those bug reports are useless, and we urge everyone to
14333@emph{refuse to respond to them} except to chide the sender to report
14334bugs properly.
14335
14336To enable us to fix the bug, you should include all these things:
14337
14338@itemize @bullet
14339@item
14340The version of @value{GDBN}. @value{GDBN} announces it if you start
14341with no arguments; you can also print it at any time using @code{show
14342version}.
14343
14344Without this, we will not know whether there is any point in looking for
14345the bug in the current version of @value{GDBN}.
14346
14347@item
14348The type of machine you are using, and the operating system name and
14349version number.
14350
c906108c
SS
14351@item
14352What compiler (and its version) was used to compile @value{GDBN}---e.g.
14353``@value{GCC}--2.8.1''.
c906108c
SS
14354
14355@item
14356What compiler (and its version) was used to compile the program you are
14357debugging---e.g. ``@value{GCC}--2.8.1'', or ``HP92453-01 A.10.32.03 HP
14358C Compiler''. For GCC, you can say @code{gcc --version} to get this
14359information; for other compilers, see the documentation for those
14360compilers.
14361
14362@item
14363The command arguments you gave the compiler to compile your example and
14364observe the bug. For example, did you use @samp{-O}? To guarantee
14365you will not omit something important, list them all. A copy of the
14366Makefile (or the output from make) is sufficient.
14367
14368If we were to try to guess the arguments, we would probably guess wrong
14369and then we might not encounter the bug.
14370
14371@item
14372A complete input script, and all necessary source files, that will
14373reproduce the bug.
14374
14375@item
14376A description of what behavior you observe that you believe is
14377incorrect. For example, ``It gets a fatal signal.''
14378
14379Of course, if the bug is that @value{GDBN} gets a fatal signal, then we
14380will certainly notice it. But if the bug is incorrect output, we might
14381not notice unless it is glaringly wrong. You might as well not give us
14382a chance to make a mistake.
14383
14384Even if the problem you experience is a fatal signal, you should still
14385say so explicitly. Suppose something strange is going on, such as, your
14386copy of @value{GDBN} is out of synch, or you have encountered a bug in
14387the C library on your system. (This has happened!) Your copy might
14388crash and ours would not. If you told us to expect a crash, then when
14389ours fails to crash, we would know that the bug was not happening for
14390us. If you had not told us to expect a crash, then we would not be able
14391to draw any conclusion from our observations.
14392
c906108c
SS
14393@item
14394If you wish to suggest changes to the @value{GDBN} source, send us context
14395diffs. If you even discuss something in the @value{GDBN} source, refer to
14396it by context, not by line number.
14397
14398The line numbers in our development sources will not match those in your
14399sources. Your line numbers would convey no useful information to us.
53a5351d 14400
c906108c
SS
14401@end itemize
14402
14403Here are some things that are not necessary:
14404
14405@itemize @bullet
14406@item
14407A description of the envelope of the bug.
14408
14409Often people who encounter a bug spend a lot of time investigating
14410which changes to the input file will make the bug go away and which
14411changes will not affect it.
14412
14413This is often time consuming and not very useful, because the way we
14414will find the bug is by running a single example under the debugger
14415with breakpoints, not by pure deduction from a series of examples.
14416We recommend that you save your time for something else.
14417
14418Of course, if you can find a simpler example to report @emph{instead}
14419of the original one, that is a convenience for us. Errors in the
14420output will be easier to spot, running under the debugger will take
14421less time, and so on.
14422
14423However, simplification is not vital; if you do not want to do this,
14424report the bug anyway and send us the entire test case you used.
14425
14426@item
14427A patch for the bug.
14428
14429A patch for the bug does help us if it is a good one. But do not omit
14430the necessary information, such as the test case, on the assumption that
14431a patch is all we need. We might see problems with your patch and decide
14432to fix the problem another way, or we might not understand it at all.
14433
14434Sometimes with a program as complicated as @value{GDBN} it is very hard to
14435construct an example that will make the program follow a certain path
14436through the code. If you do not send us the example, we will not be able
14437to construct one, so we will not be able to verify that the bug is fixed.
14438
14439And if we cannot understand what bug you are trying to fix, or why your
14440patch should be an improvement, we will not install it. A test case will
14441help us to understand.
14442
14443@item
14444A guess about what the bug is or what it depends on.
14445
14446Such guesses are usually wrong. Even we cannot guess right about such
14447things without first using the debugger to find the facts.
14448@end itemize
14449
5d161b24 14450@c The readline documentation is distributed with the readline code
c906108c
SS
14451@c and consists of the two following files:
14452@c rluser.texinfo
7be570e7 14453@c inc-hist.texinfo
c906108c
SS
14454@c Use -I with makeinfo to point to the appropriate directory,
14455@c environment var TEXINPUTS with TeX.
14456@include rluser.texinfo
7be570e7 14457@include inc-hist.texinfo
c906108c
SS
14458
14459
6d2ebf8b 14460@node Formatting Documentation
c906108c
SS
14461@appendix Formatting Documentation
14462
14463@cindex @value{GDBN} reference card
14464@cindex reference card
14465The @value{GDBN} 4 release includes an already-formatted reference card, ready
14466for printing with PostScript or Ghostscript, in the @file{gdb}
14467subdirectory of the main source directory@footnote{In
14468@file{gdb-@value{GDBVN}/gdb/refcard.ps} of the version @value{GDBVN}
14469release.}. If you can use PostScript or Ghostscript with your printer,
14470you can print the reference card immediately with @file{refcard.ps}.
14471
14472The release also includes the source for the reference card. You
14473can format it, using @TeX{}, by typing:
14474
14475@example
14476make refcard.dvi
14477@end example
14478
5d161b24
DB
14479The @value{GDBN} reference card is designed to print in @dfn{landscape}
14480mode on US ``letter'' size paper;
c906108c
SS
14481that is, on a sheet 11 inches wide by 8.5 inches
14482high. You will need to specify this form of printing as an option to
14483your @sc{dvi} output program.
14484
14485@cindex documentation
14486
14487All the documentation for @value{GDBN} comes as part of the machine-readable
14488distribution. The documentation is written in Texinfo format, which is
14489a documentation system that uses a single source file to produce both
14490on-line information and a printed manual. You can use one of the Info
14491formatting commands to create the on-line version of the documentation
14492and @TeX{} (or @code{texi2roff}) to typeset the printed version.
14493
14494@value{GDBN} includes an already formatted copy of the on-line Info
14495version of this manual in the @file{gdb} subdirectory. The main Info
14496file is @file{gdb-@value{GDBVN}/gdb/gdb.info}, and it refers to
14497subordinate files matching @samp{gdb.info*} in the same directory. If
14498necessary, you can print out these files, or read them with any editor;
14499but they are easier to read using the @code{info} subsystem in @sc{gnu}
14500Emacs or the standalone @code{info} program, available as part of the
14501@sc{gnu} Texinfo distribution.
14502
14503If you want to format these Info files yourself, you need one of the
14504Info formatting programs, such as @code{texinfo-format-buffer} or
14505@code{makeinfo}.
14506
14507If you have @code{makeinfo} installed, and are in the top level
14508@value{GDBN} source directory (@file{gdb-@value{GDBVN}}, in the case of
14509version @value{GDBVN}), you can make the Info file by typing:
14510
14511@example
14512cd gdb
14513make gdb.info
14514@end example
14515
14516If you want to typeset and print copies of this manual, you need @TeX{},
14517a program to print its @sc{dvi} output files, and @file{texinfo.tex}, the
14518Texinfo definitions file.
14519
14520@TeX{} is a typesetting program; it does not print files directly, but
14521produces output files called @sc{dvi} files. To print a typeset
14522document, you need a program to print @sc{dvi} files. If your system
14523has @TeX{} installed, chances are it has such a program. The precise
14524command to use depends on your system; @kbd{lpr -d} is common; another
14525(for PostScript devices) is @kbd{dvips}. The @sc{dvi} print command may
14526require a file name without any extension or a @samp{.dvi} extension.
14527
14528@TeX{} also requires a macro definitions file called
14529@file{texinfo.tex}. This file tells @TeX{} how to typeset a document
14530written in Texinfo format. On its own, @TeX{} cannot either read or
14531typeset a Texinfo file. @file{texinfo.tex} is distributed with GDB
14532and is located in the @file{gdb-@var{version-number}/texinfo}
14533directory.
14534
14535If you have @TeX{} and a @sc{dvi} printer program installed, you can
14536typeset and print this manual. First switch to the the @file{gdb}
14537subdirectory of the main source directory (for example, to
14538@file{gdb-@value{GDBVN}/gdb}) and type:
14539
14540@example
14541make gdb.dvi
14542@end example
14543
14544Then give @file{gdb.dvi} to your @sc{dvi} printing program.
c906108c 14545
6d2ebf8b 14546@node Installing GDB
c906108c
SS
14547@appendix Installing @value{GDBN}
14548@cindex configuring @value{GDBN}
14549@cindex installation
14550
c906108c
SS
14551@value{GDBN} comes with a @code{configure} script that automates the process
14552of preparing @value{GDBN} for installation; you can then use @code{make} to
14553build the @code{gdb} program.
14554@iftex
14555@c irrelevant in info file; it's as current as the code it lives with.
14556@footnote{If you have a more recent version of @value{GDBN} than @value{GDBVN},
14557look at the @file{README} file in the sources; we may have improved the
14558installation procedures since publishing this manual.}
14559@end iftex
14560
5d161b24
DB
14561The @value{GDBN} distribution includes all the source code you need for
14562@value{GDBN} in a single directory, whose name is usually composed by
c906108c
SS
14563appending the version number to @samp{gdb}.
14564
14565For example, the @value{GDBN} version @value{GDBVN} distribution is in the
14566@file{gdb-@value{GDBVN}} directory. That directory contains:
14567
14568@table @code
14569@item gdb-@value{GDBVN}/configure @r{(and supporting files)}
14570script for configuring @value{GDBN} and all its supporting libraries
14571
14572@item gdb-@value{GDBVN}/gdb
14573the source specific to @value{GDBN} itself
14574
14575@item gdb-@value{GDBVN}/bfd
14576source for the Binary File Descriptor library
14577
14578@item gdb-@value{GDBVN}/include
14579@sc{gnu} include files
14580
14581@item gdb-@value{GDBVN}/libiberty
14582source for the @samp{-liberty} free software library
14583
14584@item gdb-@value{GDBVN}/opcodes
14585source for the library of opcode tables and disassemblers
14586
14587@item gdb-@value{GDBVN}/readline
14588source for the @sc{gnu} command-line interface
14589
14590@item gdb-@value{GDBVN}/glob
14591source for the @sc{gnu} filename pattern-matching subroutine
14592
14593@item gdb-@value{GDBVN}/mmalloc
14594source for the @sc{gnu} memory-mapped malloc package
14595@end table
14596
14597The simplest way to configure and build @value{GDBN} is to run @code{configure}
14598from the @file{gdb-@var{version-number}} source directory, which in
14599this example is the @file{gdb-@value{GDBVN}} directory.
14600
14601First switch to the @file{gdb-@var{version-number}} source directory
14602if you are not already in it; then run @code{configure}. Pass the
14603identifier for the platform on which @value{GDBN} will run as an
14604argument.
14605
14606For example:
14607
14608@example
14609cd gdb-@value{GDBVN}
14610./configure @var{host}
14611make
14612@end example
14613
14614@noindent
14615where @var{host} is an identifier such as @samp{sun4} or
14616@samp{decstation}, that identifies the platform where @value{GDBN} will run.
14617(You can often leave off @var{host}; @code{configure} tries to guess the
14618correct value by examining your system.)
14619
14620Running @samp{configure @var{host}} and then running @code{make} builds the
14621@file{bfd}, @file{readline}, @file{mmalloc}, and @file{libiberty}
14622libraries, then @code{gdb} itself. The configured source files, and the
14623binaries, are left in the corresponding source directories.
14624
14625@need 750
14626@code{configure} is a Bourne-shell (@code{/bin/sh}) script; if your
14627system does not recognize this automatically when you run a different
14628shell, you may need to run @code{sh} on it explicitly:
14629
14630@example
14631sh configure @var{host}
14632@end example
14633
14634If you run @code{configure} from a directory that contains source
14635directories for multiple libraries or programs, such as the
14636@file{gdb-@value{GDBVN}} source directory for version @value{GDBVN}, @code{configure}
14637creates configuration files for every directory level underneath (unless
14638you tell it not to, with the @samp{--norecursion} option).
14639
14640You can run the @code{configure} script from any of the
14641subordinate directories in the @value{GDBN} distribution if you only want to
14642configure that subdirectory, but be sure to specify a path to it.
14643
14644For example, with version @value{GDBVN}, type the following to configure only
14645the @code{bfd} subdirectory:
14646
14647@example
14648@group
14649cd gdb-@value{GDBVN}/bfd
14650../configure @var{host}
14651@end group
14652@end example
14653
14654You can install @code{@value{GDBP}} anywhere; it has no hardwired paths.
14655However, you should make sure that the shell on your path (named by
14656the @samp{SHELL} environment variable) is publicly readable. Remember
14657that @value{GDBN} uses the shell to start your program---some systems refuse to
14658let @value{GDBN} debug child processes whose programs are not readable.
14659
14660@menu
14661* Separate Objdir:: Compiling @value{GDBN} in another directory
14662* Config Names:: Specifying names for hosts and targets
14663* Configure Options:: Summary of options for configure
14664@end menu
14665
6d2ebf8b 14666@node Separate Objdir
c906108c
SS
14667@section Compiling @value{GDBN} in another directory
14668
14669If you want to run @value{GDBN} versions for several host or target machines,
14670you need a different @code{gdb} compiled for each combination of
14671host and target. @code{configure} is designed to make this easy by
14672allowing you to generate each configuration in a separate subdirectory,
14673rather than in the source directory. If your @code{make} program
14674handles the @samp{VPATH} feature (@sc{gnu} @code{make} does), running
14675@code{make} in each of these directories builds the @code{gdb}
14676program specified there.
14677
14678To build @code{gdb} in a separate directory, run @code{configure}
14679with the @samp{--srcdir} option to specify where to find the source.
14680(You also need to specify a path to find @code{configure}
14681itself from your working directory. If the path to @code{configure}
14682would be the same as the argument to @samp{--srcdir}, you can leave out
14683the @samp{--srcdir} option; it is assumed.)
14684
5d161b24 14685For example, with version @value{GDBVN}, you can build @value{GDBN} in a
c906108c
SS
14686separate directory for a Sun 4 like this:
14687
14688@example
14689@group
14690cd gdb-@value{GDBVN}
14691mkdir ../gdb-sun4
14692cd ../gdb-sun4
14693../gdb-@value{GDBVN}/configure sun4
14694make
14695@end group
14696@end example
14697
14698When @code{configure} builds a configuration using a remote source
14699directory, it creates a tree for the binaries with the same structure
14700(and using the same names) as the tree under the source directory. In
14701the example, you'd find the Sun 4 library @file{libiberty.a} in the
14702directory @file{gdb-sun4/libiberty}, and @value{GDBN} itself in
14703@file{gdb-sun4/gdb}.
14704
14705One popular reason to build several @value{GDBN} configurations in separate
5d161b24
DB
14706directories is to configure @value{GDBN} for cross-compiling (where
14707@value{GDBN} runs on one machine---the @dfn{host}---while debugging
14708programs that run on another machine---the @dfn{target}).
c906108c
SS
14709You specify a cross-debugging target by
14710giving the @samp{--target=@var{target}} option to @code{configure}.
14711
14712When you run @code{make} to build a program or library, you must run
14713it in a configured directory---whatever directory you were in when you
14714called @code{configure} (or one of its subdirectories).
14715
14716The @code{Makefile} that @code{configure} generates in each source
14717directory also runs recursively. If you type @code{make} in a source
14718directory such as @file{gdb-@value{GDBVN}} (or in a separate configured
14719directory configured with @samp{--srcdir=@var{dirname}/gdb-@value{GDBVN}}), you
14720will build all the required libraries, and then build GDB.
14721
14722When you have multiple hosts or targets configured in separate
14723directories, you can run @code{make} on them in parallel (for example,
14724if they are NFS-mounted on each of the hosts); they will not interfere
14725with each other.
14726
6d2ebf8b 14727@node Config Names
c906108c
SS
14728@section Specifying names for hosts and targets
14729
14730The specifications used for hosts and targets in the @code{configure}
14731script are based on a three-part naming scheme, but some short predefined
14732aliases are also supported. The full naming scheme encodes three pieces
14733of information in the following pattern:
14734
14735@example
14736@var{architecture}-@var{vendor}-@var{os}
14737@end example
14738
14739For example, you can use the alias @code{sun4} as a @var{host} argument,
14740or as the value for @var{target} in a @code{--target=@var{target}}
14741option. The equivalent full name is @samp{sparc-sun-sunos4}.
14742
14743The @code{configure} script accompanying @value{GDBN} does not provide
14744any query facility to list all supported host and target names or
14745aliases. @code{configure} calls the Bourne shell script
14746@code{config.sub} to map abbreviations to full names; you can read the
14747script, if you wish, or you can use it to test your guesses on
14748abbreviations---for example:
14749
14750@smallexample
14751% sh config.sub i386-linux
14752i386-pc-linux-gnu
14753% sh config.sub alpha-linux
14754alpha-unknown-linux-gnu
14755% sh config.sub hp9k700
14756hppa1.1-hp-hpux
14757% sh config.sub sun4
14758sparc-sun-sunos4.1.1
14759% sh config.sub sun3
14760m68k-sun-sunos4.1.1
14761% sh config.sub i986v
14762Invalid configuration `i986v': machine `i986v' not recognized
14763@end smallexample
14764
14765@noindent
14766@code{config.sub} is also distributed in the @value{GDBN} source
14767directory (@file{gdb-@value{GDBVN}}, for version @value{GDBVN}).
14768
6d2ebf8b 14769@node Configure Options
c906108c
SS
14770@section @code{configure} options
14771
14772Here is a summary of the @code{configure} options and arguments that
14773are most often useful for building @value{GDBN}. @code{configure} also has
14774several other options not listed here. @inforef{What Configure
14775Does,,configure.info}, for a full explanation of @code{configure}.
14776
14777@example
14778configure @r{[}--help@r{]}
14779 @r{[}--prefix=@var{dir}@r{]}
14780 @r{[}--exec-prefix=@var{dir}@r{]}
14781 @r{[}--srcdir=@var{dirname}@r{]}
14782 @r{[}--norecursion@r{]} @r{[}--rm@r{]}
14783 @r{[}--target=@var{target}@r{]}
14784 @var{host}
14785@end example
14786
14787@noindent
14788You may introduce options with a single @samp{-} rather than
14789@samp{--} if you prefer; but you may abbreviate option names if you use
14790@samp{--}.
14791
14792@table @code
14793@item --help
14794Display a quick summary of how to invoke @code{configure}.
14795
14796@item --prefix=@var{dir}
14797Configure the source to install programs and files under directory
14798@file{@var{dir}}.
14799
14800@item --exec-prefix=@var{dir}
14801Configure the source to install programs under directory
14802@file{@var{dir}}.
14803
14804@c avoid splitting the warning from the explanation:
14805@need 2000
14806@item --srcdir=@var{dirname}
14807@strong{Warning: using this option requires @sc{gnu} @code{make}, or another
14808@code{make} that implements the @code{VPATH} feature.}@*
14809Use this option to make configurations in directories separate from the
14810@value{GDBN} source directories. Among other things, you can use this to
14811build (or maintain) several configurations simultaneously, in separate
14812directories. @code{configure} writes configuration specific files in
14813the current directory, but arranges for them to use the source in the
14814directory @var{dirname}. @code{configure} creates directories under
14815the working directory in parallel to the source directories below
14816@var{dirname}.
14817
14818@item --norecursion
14819Configure only the directory level where @code{configure} is executed; do not
14820propagate configuration to subdirectories.
14821
14822@item --target=@var{target}
14823Configure @value{GDBN} for cross-debugging programs running on the specified
14824@var{target}. Without this option, @value{GDBN} is configured to debug
14825programs that run on the same machine (@var{host}) as @value{GDBN} itself.
14826
14827There is no convenient way to generate a list of all available targets.
14828
14829@item @var{host} @dots{}
14830Configure @value{GDBN} to run on the specified @var{host}.
14831
14832There is no convenient way to generate a list of all available hosts.
14833@end table
14834
14835There are many other options available as well, but they are generally
14836needed for special purposes only.
5d161b24 14837
eb12ee30
AC
14838@node Maintenance Commands
14839@appendix Maintenance Commands
14840@cindex maintenance commands
14841@cindex internal commands
14842
14843In addition to commands intended for @value{GDBN} users, @value{GDBN}
14844includes a number of commands intended for @value{GDBN} developers.
14845These commands are provided here for reference.
14846
14847@table @code
14848@kindex maint info breakpoints
14849@item @anchor{maint info breakpoints}maint info breakpoints
14850Using the same format as @samp{info breakpoints}, display both the
14851breakpoints you've set explicitly, and those @value{GDBN} is using for
14852internal purposes. Internal breakpoints are shown with negative
14853breakpoint numbers. The type column identifies what kind of breakpoint
14854is shown:
14855
14856@table @code
14857@item breakpoint
14858Normal, explicitly set breakpoint.
14859
14860@item watchpoint
14861Normal, explicitly set watchpoint.
14862
14863@item longjmp
14864Internal breakpoint, used to handle correctly stepping through
14865@code{longjmp} calls.
14866
14867@item longjmp resume
14868Internal breakpoint at the target of a @code{longjmp}.
14869
14870@item until
14871Temporary internal breakpoint used by the @value{GDBN} @code{until} command.
14872
14873@item finish
14874Temporary internal breakpoint used by the @value{GDBN} @code{finish} command.
14875
14876@item shlib events
14877Shared library events.
14878
14879@end table
14880
14881@end table
14882
6826cf00
EZ
14883@include fdl.texi
14884
6d2ebf8b 14885@node Index
c906108c
SS
14886@unnumbered Index
14887
14888@printindex cp
14889
14890@tex
14891% I think something like @colophon should be in texinfo. In the
14892% meantime:
14893\long\def\colophon{\hbox to0pt{}\vfill
14894\centerline{The body of this manual is set in}
14895\centerline{\fontname\tenrm,}
14896\centerline{with headings in {\bf\fontname\tenbf}}
14897\centerline{and examples in {\tt\fontname\tentt}.}
14898\centerline{{\it\fontname\tenit\/},}
14899\centerline{{\bf\fontname\tenbf}, and}
14900\centerline{{\sl\fontname\tensl\/}}
14901\centerline{are used for emphasis.}\vfill}
14902\page\colophon
14903% Blame: doc@cygnus.com, 1991.
14904@end tex
14905
449f3b6c
AC
14906@c TeX can handle the contents at the start but makeinfo 3.12 can not
14907@ifinfo
c906108c 14908@contents
449f3b6c
AC
14909@end ifinfo
14910@ifhtml
14911@contents
14912@end ifhtml
14913
c906108c 14914@bye