2003-08-09 Andrew Cagney <cagney@redhat.com>
[deliverable/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,
1e698235 3@c 1999, 2000, 2001, 2002, 2003
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!
9fe8321b 31@c This is updated by GNU Press.
e9c75b65 32@set EDITION Ninth
c906108c 33
87885426
FN
34@c !!set GDB edit command default editor
35@set EDITOR /bin/ex
c906108c 36
6c0e9fb3 37@c THIS MANUAL REQUIRES TEXINFO 4.0 OR LATER.
c906108c 38
c906108c 39@c This is a dir.info fragment to support semi-automated addition of
6d2ebf8b 40@c manuals to an info tree.
96a2c332
SS
41@dircategory Programming & development tools.
42@direntry
c906108c 43* Gdb: (gdb). The @sc{gnu} debugger.
96a2c332
SS
44@end direntry
45
c906108c
SS
46@ifinfo
47This file documents the @sc{gnu} debugger @value{GDBN}.
48
49
9fe8321b
AC
50This is the @value{EDITION} Edition, of @cite{Debugging with
51@value{GDBN}: the @sc{gnu} Source-Level Debugger} for @value{GDBN}
52Version @value{GDBVN}.
c906108c 53
8a037dd7 54Copyright (C) 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1998,@*
1e698235 55 1999, 2000, 2001, 2002, 2003 Free Software Foundation, Inc.
c906108c 56
e9c75b65
EZ
57Permission is granted to copy, distribute and/or modify this document
58under the terms of the GNU Free Documentation License, Version 1.1 or
59any later version published by the Free Software Foundation; with the
959acfd1
EZ
60Invariant Sections being ``Free Software'' and ``Free Software Needs
61Free Documentation'', with the Front-Cover Texts being ``A GNU Manual,''
62and with the Back-Cover Texts as in (a) below.
c906108c 63
6826cf00
EZ
64(a) The Free Software Foundation's Back-Cover Text is: ``You have
65freedom to copy and modify this GNU Manual, like GNU software. Copies
66published by the Free Software Foundation raise funds for GNU
67development.''
c906108c
SS
68@end ifinfo
69
70@titlepage
71@title Debugging with @value{GDBN}
72@subtitle The @sc{gnu} Source-Level Debugger
c906108c 73@sp 1
c906108c 74@subtitle @value{EDITION} Edition, for @value{GDBN} version @value{GDBVN}
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 86Copyright @copyright{} 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995,
1e698235 871996, 1998, 1999, 2000, 2001, 2002, 2003 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
6c0e9fb3 108@ifnottex
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
9fe8321b 115This is the @value{EDITION} Edition, for @value{GDBN} Version
c906108c
SS
116@value{GDBVN}.
117
1e698235 118Copyright (C) 1988-2003 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
e2e0bcd1 131* Macros:: Preprocessor Macros
b37052ae 132* Tracepoints:: Debugging remote targets non-intrusively
df0cd8c5 133* Overlays:: Debugging programs that use overlays
6d2ebf8b
SS
134
135* Languages:: Using @value{GDBN} with different languages
136
137* Symbols:: Examining the symbol table
138* Altering:: Altering execution
139* GDB Files:: @value{GDBN} files
140* Targets:: Specifying a debugging target
6b2f586d 141* Remote Debugging:: Debugging remote programs
6d2ebf8b
SS
142* Configurations:: Configuration-specific information
143* Controlling GDB:: Controlling @value{GDBN}
144* Sequences:: Canned sequences of commands
c4555f82 145* TUI:: @value{GDBN} Text User Interface
21c294e6 146* Interpreters:: Command Interpreters
6d2ebf8b
SS
147* Emacs:: Using @value{GDBN} under @sc{gnu} Emacs
148* Annotations:: @value{GDBN}'s annotation interface.
7162c0ca 149* GDB/MI:: @value{GDBN}'s Machine Interface.
6d2ebf8b
SS
150
151* GDB Bugs:: Reporting bugs in @value{GDBN}
152* Formatting Documentation:: How to format and print @value{GDBN} documentation
153
154* Command Line Editing:: Command Line Editing
155* Using History Interactively:: Using History Interactively
156* Installing GDB:: Installing GDB
eb12ee30 157* Maintenance Commands:: Maintenance Commands
e0ce93ac 158* Remote Protocol:: GDB Remote Serial Protocol
f418dd93 159* Agent Expressions:: The GDB Agent Expression Mechanism
aab4e0ec
AC
160* Copying:: GNU General Public License says
161 how you can copy and share GDB
6826cf00 162* GNU Free Documentation License:: The license for this documentation
6d2ebf8b
SS
163* Index:: Index
164@end menu
165
6c0e9fb3 166@end ifnottex
c906108c 167
449f3b6c 168@contents
449f3b6c 169
6d2ebf8b 170@node Summary
c906108c
SS
171@unnumbered Summary of @value{GDBN}
172
173The purpose of a debugger such as @value{GDBN} is to allow you to see what is
174going on ``inside'' another program while it executes---or what another
175program was doing at the moment it crashed.
176
177@value{GDBN} can do four main kinds of things (plus other things in support of
178these) to help you catch bugs in the act:
179
180@itemize @bullet
181@item
182Start your program, specifying anything that might affect its behavior.
183
184@item
185Make your program stop on specified conditions.
186
187@item
188Examine what has happened, when your program has stopped.
189
190@item
191Change things in your program, so you can experiment with correcting the
192effects of one bug and go on to learn about another.
193@end itemize
194
cce74817 195You can use @value{GDBN} to debug programs written in C and C++.
c906108c 196For more information, see @ref{Support,,Supported languages}.
c906108c
SS
197For more information, see @ref{C,,C and C++}.
198
cce74817 199@cindex Modula-2
e632838e
AC
200Support for Modula-2 is partial. For information on Modula-2, see
201@ref{Modula-2,,Modula-2}.
c906108c 202
cce74817
JM
203@cindex Pascal
204Debugging Pascal programs which use sets, subranges, file variables, or
205nested functions does not currently work. @value{GDBN} does not support
206entering expressions, printing values, or similar features using Pascal
207syntax.
c906108c 208
c906108c
SS
209@cindex Fortran
210@value{GDBN} can be used to debug programs written in Fortran, although
53a5351d 211it may be necessary to refer to some variables with a trailing
cce74817 212underscore.
c906108c 213
b37303ee
AF
214@value{GDBN} can be used to debug programs written in Objective-C,
215using either the Apple/NeXT or the GNU Objective-C runtime.
216
c906108c
SS
217@menu
218* Free Software:: Freely redistributable software
219* Contributors:: Contributors to GDB
220@end menu
221
6d2ebf8b 222@node Free Software
c906108c
SS
223@unnumberedsec Free software
224
5d161b24 225@value{GDBN} is @dfn{free software}, protected by the @sc{gnu}
c906108c
SS
226General Public License
227(GPL). The GPL gives you the freedom to copy or adapt a licensed
228program---but every person getting a copy also gets with it the
229freedom to modify that copy (which means that they must get access to
230the source code), and the freedom to distribute further copies.
231Typical software companies use copyrights to limit your freedoms; the
232Free Software Foundation uses the GPL to preserve these freedoms.
233
234Fundamentally, the General Public License is a license which says that
235you have these freedoms and that you cannot take these freedoms away
236from anyone else.
237
2666264b 238@unnumberedsec Free Software Needs Free Documentation
959acfd1
EZ
239
240The biggest deficiency in the free software community today is not in
241the software---it is the lack of good free documentation that we can
242include with the free software. Many of our most important
243programs do not come with free reference manuals and free introductory
244texts. Documentation is an essential part of any software package;
245when an important free software package does not come with a free
246manual and a free tutorial, that is a major gap. We have many such
247gaps today.
248
249Consider Perl, for instance. The tutorial manuals that people
250normally use are non-free. How did this come about? Because the
251authors of those manuals published them with restrictive terms---no
252copying, no modification, source files not available---which exclude
253them from the free software world.
254
255That wasn't the first time this sort of thing happened, and it was far
256from the last. Many times we have heard a GNU user eagerly describe a
257manual that he is writing, his intended contribution to the community,
258only to learn that he had ruined everything by signing a publication
259contract to make it non-free.
260
261Free documentation, like free software, is a matter of freedom, not
262price. The problem with the non-free manual is not that publishers
263charge a price for printed copies---that in itself is fine. (The Free
264Software Foundation sells printed copies of manuals, too.) The
265problem is the restrictions on the use of the manual. Free manuals
266are available in source code form, and give you permission to copy and
267modify. Non-free manuals do not allow this.
268
269The criteria of freedom for a free manual are roughly the same as for
270free software. Redistribution (including the normal kinds of
271commercial redistribution) must be permitted, so that the manual can
272accompany every copy of the program, both on-line and on paper.
273
274Permission for modification of the technical content is crucial too.
275When people modify the software, adding or changing features, if they
276are conscientious they will change the manual too---so they can
277provide accurate and clear documentation for the modified program. A
278manual that leaves you no choice but to write a new manual to document
279a changed version of the program is not really available to our
280community.
281
282Some kinds of limits on the way modification is handled are
283acceptable. For example, requirements to preserve the original
284author's copyright notice, the distribution terms, or the list of
285authors, are ok. It is also no problem to require modified versions
286to include notice that they were modified. Even entire sections that
287may not be deleted or changed are acceptable, as long as they deal
288with nontechnical topics (like this one). These kinds of restrictions
289are acceptable because they don't obstruct the community's normal use
290of the manual.
291
292However, it must be possible to modify all the @emph{technical}
293content of the manual, and then distribute the result in all the usual
294media, through all the usual channels. Otherwise, the restrictions
295obstruct the use of the manual, it is not free, and we need another
296manual to replace it.
297
298Please spread the word about this issue. Our community continues to
299lose manuals to proprietary publishing. If we spread the word that
300free software needs free reference manuals and free tutorials, perhaps
301the next person who wants to contribute by writing documentation will
302realize, before it is too late, that only free manuals contribute to
303the free software community.
304
305If you are writing documentation, please insist on publishing it under
306the GNU Free Documentation License or another free documentation
307license. Remember that this decision requires your approval---you
308don't have to let the publisher decide. Some commercial publishers
309will use a free license if you insist, but they will not propose the
310option; it is up to you to raise the issue and say firmly that this is
311what you want. If the publisher you are dealing with refuses, please
312try other publishers. If you're not sure whether a proposed license
42584a72 313is free, write to @email{licensing@@gnu.org}.
959acfd1
EZ
314
315You can encourage commercial publishers to sell more free, copylefted
316manuals and tutorials by buying them, and particularly by buying
317copies from the publishers that paid for their writing or for major
318improvements. Meanwhile, try to avoid buying non-free documentation
319at all. Check the distribution terms of a manual before you buy it,
320and insist that whoever seeks your business must respect your freedom.
72c9928d
EZ
321Check the history of the book, and try to reward the publishers that
322have paid or pay the authors to work on it.
959acfd1
EZ
323
324The Free Software Foundation maintains a list of free documentation
325published by other publishers, at
326@url{http://www.fsf.org/doc/other-free-books.html}.
327
6d2ebf8b 328@node Contributors
96a2c332
SS
329@unnumberedsec Contributors to @value{GDBN}
330
331Richard Stallman was the original author of @value{GDBN}, and of many
332other @sc{gnu} programs. Many others have contributed to its
333development. This section attempts to credit major contributors. One
334of the virtues of free software is that everyone is free to contribute
335to it; with regret, we cannot actually acknowledge everyone here. The
336file @file{ChangeLog} in the @value{GDBN} distribution approximates a
c906108c
SS
337blow-by-blow account.
338
339Changes much prior to version 2.0 are lost in the mists of time.
340
341@quotation
342@emph{Plea:} Additions to this section are particularly welcome. If you
343or your friends (or enemies, to be evenhanded) have been unfairly
344omitted from this list, we would like to add your names!
345@end quotation
346
347So that they may not regard their many labors as thankless, we
348particularly thank those who shepherded @value{GDBN} through major
349releases:
f2c06f52 350Andrew Cagney (releases 6.0, 5.3, 5.2, 5.1 and 5.0);
c906108c
SS
351Jim Blandy (release 4.18);
352Jason Molenda (release 4.17);
353Stan Shebs (release 4.14);
354Fred Fish (releases 4.16, 4.15, 4.13, 4.12, 4.11, 4.10, and 4.9);
355Stu Grossman and John Gilmore (releases 4.8, 4.7, 4.6, 4.5, and 4.4);
356John Gilmore (releases 4.3, 4.2, 4.1, 4.0, and 3.9);
357Jim Kingdon (releases 3.5, 3.4, and 3.3);
358and Randy Smith (releases 3.2, 3.1, and 3.0).
359
360Richard Stallman, assisted at various times by Peter TerMaat, Chris
361Hanson, and Richard Mlynarik, handled releases through 2.8.
362
b37052ae
EZ
363Michael Tiemann is the author of most of the @sc{gnu} C@t{++} support
364in @value{GDBN}, with significant additional contributions from Per
365Bothner and Daniel Berlin. James Clark wrote the @sc{gnu} C@t{++}
366demangler. Early work on C@t{++} was by Peter TerMaat (who also did
367much general update work leading to release 3.0).
c906108c 368
b37052ae 369@value{GDBN} uses the BFD subroutine library to examine multiple
c906108c
SS
370object-file formats; BFD was a joint project of David V.
371Henkel-Wallace, Rich Pixley, Steve Chamberlain, and John Gilmore.
372
373David Johnson wrote the original COFF support; Pace Willison did
374the original support for encapsulated COFF.
375
0179ffac 376Brent Benson of Harris Computer Systems contributed DWARF 2 support.
c906108c
SS
377
378Adam de Boor and Bradley Davis contributed the ISI Optimum V support.
379Per Bothner, Noboyuki Hikichi, and Alessandro Forin contributed MIPS
380support.
381Jean-Daniel Fekete contributed Sun 386i support.
382Chris Hanson improved the HP9000 support.
383Noboyuki Hikichi and Tomoyuki Hasei contributed Sony/News OS 3 support.
384David Johnson contributed Encore Umax support.
385Jyrki Kuoppala contributed Altos 3068 support.
386Jeff Law contributed HP PA and SOM support.
387Keith Packard contributed NS32K support.
388Doug Rabson contributed Acorn Risc Machine support.
389Bob Rusk contributed Harris Nighthawk CX-UX support.
390Chris Smith contributed Convex support (and Fortran debugging).
391Jonathan Stone contributed Pyramid support.
392Michael Tiemann contributed SPARC support.
393Tim Tucker contributed support for the Gould NP1 and Gould Powernode.
394Pace Willison contributed Intel 386 support.
395Jay Vosburgh contributed Symmetry support.
a37295f9 396Marko Mlinar contributed OpenRISC 1000 support.
c906108c 397
1104b9e7 398Andreas Schwab contributed M68K @sc{gnu}/Linux support.
c906108c
SS
399
400Rich Schaefer and Peter Schauer helped with support of SunOS shared
401libraries.
402
403Jay Fenlason and Roland McGrath ensured that @value{GDBN} and GAS agree
404about several machine instruction sets.
405
406Patrick Duval, Ted Goldstein, Vikram Koka and Glenn Engel helped develop
407remote debugging. Intel Corporation, Wind River Systems, AMD, and ARM
408contributed remote debugging modules for the i960, VxWorks, A29K UDI,
409and RDI targets, respectively.
410
411Brian Fox is the author of the readline libraries providing
412command-line editing and command history.
413
7a292a7a
SS
414Andrew Beers of SUNY Buffalo wrote the language-switching code, the
415Modula-2 support, and contributed the Languages chapter of this manual.
c906108c 416
5d161b24 417Fred Fish wrote most of the support for Unix System Vr4.
b37052ae 418He also enhanced the command-completion support to cover C@t{++} overloaded
c906108c 419symbols.
c906108c
SS
420
421Hitachi America, Ltd. sponsored the support for H8/300, H8/500, and
422Super-H processors.
423
424NEC sponsored the support for the v850, Vr4xxx, and Vr5xxx processors.
425
426Mitsubishi sponsored the support for D10V, D30V, and M32R/D processors.
427
428Toshiba sponsored the support for the TX39 Mips processor.
429
430Matsushita sponsored the support for the MN10200 and MN10300 processors.
431
96a2c332 432Fujitsu sponsored the support for SPARClite and FR30 processors.
c906108c
SS
433
434Kung Hsu, Jeff Law, and Rick Sladkey added support for hardware
435watchpoints.
436
437Michael Snyder added support for tracepoints.
438
439Stu Grossman wrote gdbserver.
440
441Jim Kingdon, Peter Schauer, Ian Taylor, and Stu Grossman made
96a2c332 442nearly innumerable bug fixes and cleanups throughout @value{GDBN}.
c906108c
SS
443
444The following people at the Hewlett-Packard Company contributed
445support for the PA-RISC 2.0 architecture, HP-UX 10.20, 10.30, and 11.0
b37052ae 446(narrow mode), HP's implementation of kernel threads, HP's aC@t{++}
c906108c
SS
447compiler, and the terminal user interface: Ben Krepp, Richard Title,
448John Bishop, Susan Macchia, Kathy Mann, Satish Pai, India Paul, Steve
449Rehrauer, and Elena Zannoni. Kim Haase provided HP-specific
450information in this manual.
451
b37052ae
EZ
452DJ Delorie ported @value{GDBN} to MS-DOS, for the DJGPP project.
453Robert Hoehne made significant contributions to the DJGPP port.
454
96a2c332
SS
455Cygnus Solutions has sponsored @value{GDBN} maintenance and much of its
456development since 1991. Cygnus engineers who have worked on @value{GDBN}
2df3850c
JM
457fulltime include Mark Alexander, Jim Blandy, Per Bothner, Kevin
458Buettner, Edith Epstein, Chris Faylor, Fred Fish, Martin Hunt, Jim
459Ingham, John Gilmore, Stu Grossman, Kung Hsu, Jim Kingdon, John Metzler,
460Fernando Nasser, Geoffrey Noer, Dawn Perchik, Rich Pixley, Zdenek
461Radouch, Keith Seitz, Stan Shebs, David Taylor, and Elena Zannoni. In
462addition, Dave Brolley, Ian Carmichael, Steve Chamberlain, Nick Clifton,
463JT Conklin, Stan Cox, DJ Delorie, Ulrich Drepper, Frank Eigler, Doug
464Evans, Sean Fagan, David Henkel-Wallace, Richard Henderson, Jeff
465Holcomb, Jeff Law, Jim Lemke, Tom Lord, Bob Manson, Michael Meissner,
466Jason Merrill, Catherine Moore, Drew Moseley, Ken Raeburn, Gavin
467Romig-Koch, Rob Savoye, Jamie Smith, Mike Stump, Ian Taylor, Angela
468Thomas, Michael Tiemann, Tom Tromey, Ron Unrau, Jim Wilson, and David
469Zuhn have made contributions both large and small.
c906108c 470
e2e0bcd1
JB
471Jim Blandy added support for preprocessor macros, while working for Red
472Hat.
c906108c 473
6d2ebf8b 474@node Sample Session
c906108c
SS
475@chapter A Sample @value{GDBN} Session
476
477You can use this manual at your leisure to read all about @value{GDBN}.
478However, a handful of commands are enough to get started using the
479debugger. This chapter illustrates those commands.
480
481@iftex
482In this sample session, we emphasize user input like this: @b{input},
483to make it easier to pick out from the surrounding output.
484@end iftex
485
486@c FIXME: this example may not be appropriate for some configs, where
487@c FIXME...primary interest is in remote use.
488
489One of the preliminary versions of @sc{gnu} @code{m4} (a generic macro
490processor) exhibits the following bug: sometimes, when we change its
491quote strings from the default, the commands used to capture one macro
492definition within another stop working. In the following short @code{m4}
493session, we define a macro @code{foo} which expands to @code{0000}; we
494then use the @code{m4} built-in @code{defn} to define @code{bar} as the
495same thing. However, when we change the open quote string to
496@code{<QUOTE>} and the close quote string to @code{<UNQUOTE>}, the same
497procedure fails to define a new synonym @code{baz}:
498
499@smallexample
500$ @b{cd gnu/m4}
501$ @b{./m4}
502@b{define(foo,0000)}
503
504@b{foo}
5050000
506@b{define(bar,defn(`foo'))}
507
508@b{bar}
5090000
510@b{changequote(<QUOTE>,<UNQUOTE>)}
511
512@b{define(baz,defn(<QUOTE>foo<UNQUOTE>))}
513@b{baz}
514@b{C-d}
515m4: End of input: 0: fatal error: EOF in string
516@end smallexample
517
518@noindent
519Let us use @value{GDBN} to try to see what is going on.
520
c906108c
SS
521@smallexample
522$ @b{@value{GDBP} m4}
523@c FIXME: this falsifies the exact text played out, to permit smallbook
524@c FIXME... format to come out better.
525@value{GDBN} is free software and you are welcome to distribute copies
5d161b24 526 of it under certain conditions; type "show copying" to see
c906108c 527 the conditions.
5d161b24 528There is absolutely no warranty for @value{GDBN}; type "show warranty"
c906108c
SS
529 for details.
530
531@value{GDBN} @value{GDBVN}, Copyright 1999 Free Software Foundation, Inc...
532(@value{GDBP})
533@end smallexample
c906108c
SS
534
535@noindent
536@value{GDBN} reads only enough symbol data to know where to find the
537rest when needed; as a result, the first prompt comes up very quickly.
538We now tell @value{GDBN} to use a narrower display width than usual, so
539that examples fit in this manual.
540
541@smallexample
542(@value{GDBP}) @b{set width 70}
543@end smallexample
544
545@noindent
546We need to see how the @code{m4} built-in @code{changequote} works.
547Having looked at the source, we know the relevant subroutine is
548@code{m4_changequote}, so we set a breakpoint there with the @value{GDBN}
549@code{break} command.
550
551@smallexample
552(@value{GDBP}) @b{break m4_changequote}
553Breakpoint 1 at 0x62f4: file builtin.c, line 879.
554@end smallexample
555
556@noindent
557Using the @code{run} command, we start @code{m4} running under @value{GDBN}
558control; as long as control does not reach the @code{m4_changequote}
559subroutine, the program runs as usual:
560
561@smallexample
562(@value{GDBP}) @b{run}
563Starting program: /work/Editorial/gdb/gnu/m4/m4
564@b{define(foo,0000)}
565
566@b{foo}
5670000
568@end smallexample
569
570@noindent
571To trigger the breakpoint, we call @code{changequote}. @value{GDBN}
572suspends execution of @code{m4}, displaying information about the
573context where it stops.
574
575@smallexample
576@b{changequote(<QUOTE>,<UNQUOTE>)}
577
5d161b24 578Breakpoint 1, m4_changequote (argc=3, argv=0x33c70)
c906108c
SS
579 at builtin.c:879
580879 if (bad_argc(TOKEN_DATA_TEXT(argv[0]),argc,1,3))
581@end smallexample
582
583@noindent
584Now we use the command @code{n} (@code{next}) to advance execution to
585the next line of the current function.
586
587@smallexample
588(@value{GDBP}) @b{n}
589882 set_quotes((argc >= 2) ? TOKEN_DATA_TEXT(argv[1])\
590 : nil,
591@end smallexample
592
593@noindent
594@code{set_quotes} looks like a promising subroutine. We can go into it
595by using the command @code{s} (@code{step}) instead of @code{next}.
596@code{step} goes to the next line to be executed in @emph{any}
597subroutine, so it steps into @code{set_quotes}.
598
599@smallexample
600(@value{GDBP}) @b{s}
601set_quotes (lq=0x34c78 "<QUOTE>", rq=0x34c88 "<UNQUOTE>")
602 at input.c:530
603530 if (lquote != def_lquote)
604@end smallexample
605
606@noindent
607The display that shows the subroutine where @code{m4} is now
608suspended (and its arguments) is called a stack frame display. It
609shows a summary of the stack. We can use the @code{backtrace}
610command (which can also be spelled @code{bt}), to see where we are
611in the stack as a whole: the @code{backtrace} command displays a
612stack frame for each active subroutine.
613
614@smallexample
615(@value{GDBP}) @b{bt}
616#0 set_quotes (lq=0x34c78 "<QUOTE>", rq=0x34c88 "<UNQUOTE>")
617 at input.c:530
5d161b24 618#1 0x6344 in m4_changequote (argc=3, argv=0x33c70)
c906108c
SS
619 at builtin.c:882
620#2 0x8174 in expand_macro (sym=0x33320) at macro.c:242
621#3 0x7a88 in expand_token (obs=0x0, t=209696, td=0xf7fffa30)
622 at macro.c:71
623#4 0x79dc in expand_input () at macro.c:40
624#5 0x2930 in main (argc=0, argv=0xf7fffb20) at m4.c:195
625@end smallexample
626
627@noindent
628We step through a few more lines to see what happens. The first two
629times, we can use @samp{s}; the next two times we use @code{n} to avoid
630falling into the @code{xstrdup} subroutine.
631
632@smallexample
633(@value{GDBP}) @b{s}
6340x3b5c 532 if (rquote != def_rquote)
635(@value{GDBP}) @b{s}
6360x3b80 535 lquote = (lq == nil || *lq == '\0') ? \
637def_lquote : xstrdup(lq);
638(@value{GDBP}) @b{n}
639536 rquote = (rq == nil || *rq == '\0') ? def_rquote\
640 : xstrdup(rq);
641(@value{GDBP}) @b{n}
642538 len_lquote = strlen(rquote);
643@end smallexample
644
645@noindent
646The last line displayed looks a little odd; we can examine the variables
647@code{lquote} and @code{rquote} to see if they are in fact the new left
648and right quotes we specified. We use the command @code{p}
649(@code{print}) to see their values.
650
651@smallexample
652(@value{GDBP}) @b{p lquote}
653$1 = 0x35d40 "<QUOTE>"
654(@value{GDBP}) @b{p rquote}
655$2 = 0x35d50 "<UNQUOTE>"
656@end smallexample
657
658@noindent
659@code{lquote} and @code{rquote} are indeed the new left and right quotes.
660To look at some context, we can display ten lines of source
661surrounding the current line with the @code{l} (@code{list}) command.
662
663@smallexample
664(@value{GDBP}) @b{l}
665533 xfree(rquote);
666534
667535 lquote = (lq == nil || *lq == '\0') ? def_lquote\
668 : xstrdup (lq);
669536 rquote = (rq == nil || *rq == '\0') ? def_rquote\
670 : xstrdup (rq);
671537
672538 len_lquote = strlen(rquote);
673539 len_rquote = strlen(lquote);
674540 @}
675541
676542 void
677@end smallexample
678
679@noindent
680Let us step past the two lines that set @code{len_lquote} and
681@code{len_rquote}, and then examine the values of those variables.
682
683@smallexample
684(@value{GDBP}) @b{n}
685539 len_rquote = strlen(lquote);
686(@value{GDBP}) @b{n}
687540 @}
688(@value{GDBP}) @b{p len_lquote}
689$3 = 9
690(@value{GDBP}) @b{p len_rquote}
691$4 = 7
692@end smallexample
693
694@noindent
695That certainly looks wrong, assuming @code{len_lquote} and
696@code{len_rquote} are meant to be the lengths of @code{lquote} and
697@code{rquote} respectively. We can set them to better values using
698the @code{p} command, since it can print the value of
699any expression---and that expression can include subroutine calls and
700assignments.
701
702@smallexample
703(@value{GDBP}) @b{p len_lquote=strlen(lquote)}
704$5 = 7
705(@value{GDBP}) @b{p len_rquote=strlen(rquote)}
706$6 = 9
707@end smallexample
708
709@noindent
710Is that enough to fix the problem of using the new quotes with the
711@code{m4} built-in @code{defn}? We can allow @code{m4} to continue
712executing with the @code{c} (@code{continue}) command, and then try the
713example that caused trouble initially:
714
715@smallexample
716(@value{GDBP}) @b{c}
717Continuing.
718
719@b{define(baz,defn(<QUOTE>foo<UNQUOTE>))}
720
721baz
7220000
723@end smallexample
724
725@noindent
726Success! The new quotes now work just as well as the default ones. The
727problem seems to have been just the two typos defining the wrong
728lengths. We allow @code{m4} exit by giving it an EOF as input:
729
730@smallexample
731@b{C-d}
732Program exited normally.
733@end smallexample
734
735@noindent
736The message @samp{Program exited normally.} is from @value{GDBN}; it
737indicates @code{m4} has finished executing. We can end our @value{GDBN}
738session with the @value{GDBN} @code{quit} command.
739
740@smallexample
741(@value{GDBP}) @b{quit}
742@end smallexample
c906108c 743
6d2ebf8b 744@node Invocation
c906108c
SS
745@chapter Getting In and Out of @value{GDBN}
746
747This chapter discusses how to start @value{GDBN}, and how to get out of it.
5d161b24 748The essentials are:
c906108c 749@itemize @bullet
5d161b24 750@item
53a5351d 751type @samp{@value{GDBP}} to start @value{GDBN}.
5d161b24 752@item
c906108c
SS
753type @kbd{quit} or @kbd{C-d} to exit.
754@end itemize
755
756@menu
757* Invoking GDB:: How to start @value{GDBN}
758* Quitting GDB:: How to quit @value{GDBN}
759* Shell Commands:: How to use shell commands inside @value{GDBN}
0fac0b41 760* Logging output:: How to log @value{GDBN}'s output to a file
c906108c
SS
761@end menu
762
6d2ebf8b 763@node Invoking GDB
c906108c
SS
764@section Invoking @value{GDBN}
765
c906108c
SS
766Invoke @value{GDBN} by running the program @code{@value{GDBP}}. Once started,
767@value{GDBN} reads commands from the terminal until you tell it to exit.
768
769You can also run @code{@value{GDBP}} with a variety of arguments and options,
770to specify more of your debugging environment at the outset.
771
c906108c
SS
772The command-line options described here are designed
773to cover a variety of situations; in some environments, some of these
5d161b24 774options may effectively be unavailable.
c906108c
SS
775
776The most usual way to start @value{GDBN} is with one argument,
777specifying an executable program:
778
474c8240 779@smallexample
c906108c 780@value{GDBP} @var{program}
474c8240 781@end smallexample
c906108c 782
c906108c
SS
783@noindent
784You can also start with both an executable program and a core file
785specified:
786
474c8240 787@smallexample
c906108c 788@value{GDBP} @var{program} @var{core}
474c8240 789@end smallexample
c906108c
SS
790
791You can, instead, specify a process ID as a second argument, if you want
792to debug a running process:
793
474c8240 794@smallexample
c906108c 795@value{GDBP} @var{program} 1234
474c8240 796@end smallexample
c906108c
SS
797
798@noindent
799would attach @value{GDBN} to process @code{1234} (unless you also have a file
800named @file{1234}; @value{GDBN} does check for a core file first).
801
c906108c 802Taking advantage of the second command-line argument requires a fairly
2df3850c
JM
803complete operating system; when you use @value{GDBN} as a remote
804debugger attached to a bare board, there may not be any notion of
805``process'', and there is often no way to get a core dump. @value{GDBN}
806will warn you if it is unable to attach or to read core dumps.
c906108c 807
aa26fa3a
TT
808You can optionally have @code{@value{GDBP}} pass any arguments after the
809executable file to the inferior using @code{--args}. This option stops
810option processing.
474c8240 811@smallexample
aa26fa3a 812gdb --args gcc -O2 -c foo.c
474c8240 813@end smallexample
aa26fa3a
TT
814This will cause @code{@value{GDBP}} to debug @code{gcc}, and to set
815@code{gcc}'s command-line arguments (@pxref{Arguments}) to @samp{-O2 -c foo.c}.
816
96a2c332 817You can run @code{@value{GDBP}} without printing the front material, which describes
c906108c
SS
818@value{GDBN}'s non-warranty, by specifying @code{-silent}:
819
820@smallexample
821@value{GDBP} -silent
822@end smallexample
823
824@noindent
825You can further control how @value{GDBN} starts up by using command-line
826options. @value{GDBN} itself can remind you of the options available.
827
828@noindent
829Type
830
474c8240 831@smallexample
c906108c 832@value{GDBP} -help
474c8240 833@end smallexample
c906108c
SS
834
835@noindent
836to display all available options and briefly describe their use
837(@samp{@value{GDBP} -h} is a shorter equivalent).
838
839All options and command line arguments you give are processed
840in sequential order. The order makes a difference when the
841@samp{-x} option is used.
842
843
844@menu
c906108c
SS
845* File Options:: Choosing files
846* Mode Options:: Choosing modes
847@end menu
848
6d2ebf8b 849@node File Options
c906108c
SS
850@subsection Choosing files
851
2df3850c 852When @value{GDBN} starts, it reads any arguments other than options as
c906108c
SS
853specifying an executable file and core file (or process ID). This is
854the same as if the arguments were specified by the @samp{-se} and
19837790
MS
855@samp{-c} (or @samp{-p} options respectively. (@value{GDBN} reads the
856first argument that does not have an associated option flag as
857equivalent to the @samp{-se} option followed by that argument; and the
858second argument that does not have an associated option flag, if any, as
859equivalent to the @samp{-c}/@samp{-p} option followed by that argument.)
860If the second argument begins with a decimal digit, @value{GDBN} will
861first attempt to attach to it as a process, and if that fails, attempt
862to open it as a corefile. If you have a corefile whose name begins with
863a digit, you can prevent @value{GDBN} from treating it as a pid by
79f12247 864prefixing it with @file{./}, eg. @file{./12345}.
7a292a7a
SS
865
866If @value{GDBN} has not been configured to included core file support,
867such as for most embedded targets, then it will complain about a second
868argument and ignore it.
c906108c
SS
869
870Many options have both long and short forms; both are shown in the
871following list. @value{GDBN} also recognizes the long forms if you truncate
872them, so long as enough of the option is present to be unambiguous.
873(If you prefer, you can flag option arguments with @samp{--} rather
874than @samp{-}, though we illustrate the more usual convention.)
875
d700128c
EZ
876@c NOTE: the @cindex entries here use double dashes ON PURPOSE. This
877@c way, both those who look for -foo and --foo in the index, will find
878@c it.
879
c906108c
SS
880@table @code
881@item -symbols @var{file}
882@itemx -s @var{file}
d700128c
EZ
883@cindex @code{--symbols}
884@cindex @code{-s}
c906108c
SS
885Read symbol table from file @var{file}.
886
887@item -exec @var{file}
888@itemx -e @var{file}
d700128c
EZ
889@cindex @code{--exec}
890@cindex @code{-e}
7a292a7a
SS
891Use file @var{file} as the executable file to execute when appropriate,
892and for examining pure data in conjunction with a core dump.
c906108c
SS
893
894@item -se @var{file}
d700128c 895@cindex @code{--se}
c906108c
SS
896Read symbol table from file @var{file} and use it as the executable
897file.
898
c906108c
SS
899@item -core @var{file}
900@itemx -c @var{file}
d700128c
EZ
901@cindex @code{--core}
902@cindex @code{-c}
19837790 903Use file @var{file} as a core dump to examine.
c906108c
SS
904
905@item -c @var{number}
19837790
MS
906@item -pid @var{number}
907@itemx -p @var{number}
908@cindex @code{--pid}
909@cindex @code{-p}
910Connect to process ID @var{number}, as with the @code{attach} command.
911If there is no such process, @value{GDBN} will attempt to open a core
912file named @var{number}.
c906108c
SS
913
914@item -command @var{file}
915@itemx -x @var{file}
d700128c
EZ
916@cindex @code{--command}
917@cindex @code{-x}
c906108c
SS
918Execute @value{GDBN} commands from file @var{file}. @xref{Command
919Files,, Command files}.
920
921@item -directory @var{directory}
922@itemx -d @var{directory}
d700128c
EZ
923@cindex @code{--directory}
924@cindex @code{-d}
c906108c
SS
925Add @var{directory} to the path to search for source files.
926
c906108c
SS
927@item -m
928@itemx -mapped
d700128c
EZ
929@cindex @code{--mapped}
930@cindex @code{-m}
c906108c
SS
931@emph{Warning: this option depends on operating system facilities that are not
932supported on all systems.}@*
933If memory-mapped files are available on your system through the @code{mmap}
5d161b24 934system call, you can use this option
c906108c
SS
935to have @value{GDBN} write the symbols from your
936program into a reusable file in the current directory. If the program you are debugging is
96a2c332 937called @file{/tmp/fred}, the mapped symbol file is @file{/tmp/fred.syms}.
c906108c
SS
938Future @value{GDBN} debugging sessions notice the presence of this file,
939and can quickly map in symbol information from it, rather than reading
940the symbol table from the executable program.
941
942The @file{.syms} file is specific to the host machine where @value{GDBN}
943is run. It holds an exact image of the internal @value{GDBN} symbol
944table. It cannot be shared across multiple host platforms.
c906108c 945
c906108c
SS
946@item -r
947@itemx -readnow
d700128c
EZ
948@cindex @code{--readnow}
949@cindex @code{-r}
c906108c
SS
950Read each symbol file's entire symbol table immediately, rather than
951the default, which is to read it incrementally as it is needed.
952This makes startup slower, but makes future operations faster.
53a5351d 953
c906108c
SS
954@end table
955
2df3850c 956You typically combine the @code{-mapped} and @code{-readnow} options in
c906108c 957order to build a @file{.syms} file that contains complete symbol
2df3850c
JM
958information. (@xref{Files,,Commands to specify files}, for information
959on @file{.syms} files.) A simple @value{GDBN} invocation to do nothing
960but build a @file{.syms} file for future use is:
c906108c 961
474c8240 962@smallexample
2df3850c 963gdb -batch -nx -mapped -readnow programname
474c8240 964@end smallexample
c906108c 965
6d2ebf8b 966@node Mode Options
c906108c
SS
967@subsection Choosing modes
968
969You can run @value{GDBN} in various alternative modes---for example, in
970batch mode or quiet mode.
971
972@table @code
973@item -nx
974@itemx -n
d700128c
EZ
975@cindex @code{--nx}
976@cindex @code{-n}
96565e91 977Do not execute commands found in any initialization files. Normally,
2df3850c
JM
978@value{GDBN} executes the commands in these files after all the command
979options and arguments have been processed. @xref{Command Files,,Command
980files}.
c906108c
SS
981
982@item -quiet
d700128c 983@itemx -silent
c906108c 984@itemx -q
d700128c
EZ
985@cindex @code{--quiet}
986@cindex @code{--silent}
987@cindex @code{-q}
c906108c
SS
988``Quiet''. Do not print the introductory and copyright messages. These
989messages are also suppressed in batch mode.
990
991@item -batch
d700128c 992@cindex @code{--batch}
c906108c
SS
993Run in batch mode. Exit with status @code{0} after processing all the
994command files specified with @samp{-x} (and all commands from
995initialization files, if not inhibited with @samp{-n}). Exit with
996nonzero status if an error occurs in executing the @value{GDBN} commands
997in the command files.
998
2df3850c
JM
999Batch mode may be useful for running @value{GDBN} as a filter, for
1000example to download and run a program on another computer; in order to
1001make this more useful, the message
c906108c 1002
474c8240 1003@smallexample
c906108c 1004Program exited normally.
474c8240 1005@end smallexample
c906108c
SS
1006
1007@noindent
2df3850c
JM
1008(which is ordinarily issued whenever a program running under
1009@value{GDBN} control terminates) is not issued when running in batch
1010mode.
1011
1012@item -nowindows
1013@itemx -nw
d700128c
EZ
1014@cindex @code{--nowindows}
1015@cindex @code{-nw}
2df3850c 1016``No windows''. If @value{GDBN} comes with a graphical user interface
96a2c332 1017(GUI) built in, then this option tells @value{GDBN} to only use the command-line
2df3850c
JM
1018interface. If no GUI is available, this option has no effect.
1019
1020@item -windows
1021@itemx -w
d700128c
EZ
1022@cindex @code{--windows}
1023@cindex @code{-w}
2df3850c
JM
1024If @value{GDBN} includes a GUI, then this option requires it to be
1025used if possible.
c906108c
SS
1026
1027@item -cd @var{directory}
d700128c 1028@cindex @code{--cd}
c906108c
SS
1029Run @value{GDBN} using @var{directory} as its working directory,
1030instead of the current directory.
1031
c906108c
SS
1032@item -fullname
1033@itemx -f
d700128c
EZ
1034@cindex @code{--fullname}
1035@cindex @code{-f}
7a292a7a
SS
1036@sc{gnu} Emacs sets this option when it runs @value{GDBN} as a
1037subprocess. It tells @value{GDBN} to output the full file name and line
1038number in a standard, recognizable fashion each time a stack frame is
1039displayed (which includes each time your program stops). This
1040recognizable format looks like two @samp{\032} characters, followed by
1041the file name, line number and character position separated by colons,
1042and a newline. The Emacs-to-@value{GDBN} interface program uses the two
1043@samp{\032} characters as a signal to display the source code for the
1044frame.
c906108c 1045
d700128c
EZ
1046@item -epoch
1047@cindex @code{--epoch}
1048The Epoch Emacs-@value{GDBN} interface sets this option when it runs
1049@value{GDBN} as a subprocess. It tells @value{GDBN} to modify its print
1050routines so as to allow Epoch to display values of expressions in a
1051separate window.
1052
1053@item -annotate @var{level}
1054@cindex @code{--annotate}
1055This option sets the @dfn{annotation level} inside @value{GDBN}. Its
1056effect is identical to using @samp{set annotate @var{level}}
086432e2
AC
1057(@pxref{Annotations}). The annotation @var{level} controls how much
1058information @value{GDBN} prints together with its prompt, values of
1059expressions, source lines, and other types of output. Level 0 is the
1060normal, level 1 is for use when @value{GDBN} is run as a subprocess of
1061@sc{gnu} Emacs, level 3 is the maximum annotation suitable for programs
1062that control @value{GDBN}, and level 2 has been deprecated.
1063
1064The annotation mechanism has largely been superseeded by @sc{gdb/mi}
1065(@pxref{GDB/MI}).
d700128c
EZ
1066
1067@item -async
1068@cindex @code{--async}
1069Use the asynchronous event loop for the command-line interface.
1070@value{GDBN} processes all events, such as user keyboard input, via a
1071special event loop. This allows @value{GDBN} to accept and process user
1072commands in parallel with the debugged process being
1073run@footnote{@value{GDBN} built with @sc{djgpp} tools for
1074MS-DOS/MS-Windows supports this mode of operation, but the event loop is
1075suspended when the debuggee runs.}, so you don't need to wait for
1076control to return to @value{GDBN} before you type the next command.
b37052ae 1077(@emph{Note:} as of version 5.1, the target side of the asynchronous
d700128c
EZ
1078operation is not yet in place, so @samp{-async} does not work fully
1079yet.)
1080@c FIXME: when the target side of the event loop is done, the above NOTE
1081@c should be removed.
1082
1083When the standard input is connected to a terminal device, @value{GDBN}
1084uses the asynchronous event loop by default, unless disabled by the
1085@samp{-noasync} option.
1086
1087@item -noasync
1088@cindex @code{--noasync}
1089Disable the asynchronous event loop for the command-line interface.
1090
aa26fa3a
TT
1091@item --args
1092@cindex @code{--args}
1093Change interpretation of command line so that arguments following the
1094executable file are passed as command line arguments to the inferior.
1095This option stops option processing.
1096
2df3850c
JM
1097@item -baud @var{bps}
1098@itemx -b @var{bps}
d700128c
EZ
1099@cindex @code{--baud}
1100@cindex @code{-b}
c906108c
SS
1101Set the line speed (baud rate or bits per second) of any serial
1102interface used by @value{GDBN} for remote debugging.
c906108c
SS
1103
1104@item -tty @var{device}
d700128c
EZ
1105@itemx -t @var{device}
1106@cindex @code{--tty}
1107@cindex @code{-t}
c906108c
SS
1108Run using @var{device} for your program's standard input and output.
1109@c FIXME: kingdon thinks there is more to -tty. Investigate.
c906108c 1110
53a5351d 1111@c resolve the situation of these eventually
c4555f82
SC
1112@item -tui
1113@cindex @code{--tui}
1114Activate the Terminal User Interface when starting.
1115The Terminal User Interface manages several text windows on the terminal,
1116showing source, assembly, registers and @value{GDBN} command outputs
1117(@pxref{TUI, ,@value{GDBN} Text User Interface}).
1118Do not use this option if you run @value{GDBN} from Emacs
1119(@pxref{Emacs, ,Using @value{GDBN} under @sc{gnu} Emacs}).
53a5351d
JM
1120
1121@c @item -xdb
d700128c 1122@c @cindex @code{--xdb}
53a5351d
JM
1123@c Run in XDB compatibility mode, allowing the use of certain XDB commands.
1124@c For information, see the file @file{xdb_trans.html}, which is usually
1125@c installed in the directory @code{/opt/langtools/wdb/doc} on HP-UX
1126@c systems.
1127
d700128c
EZ
1128@item -interpreter @var{interp}
1129@cindex @code{--interpreter}
1130Use the interpreter @var{interp} for interface with the controlling
1131program or device. This option is meant to be set by programs which
94bbb2c0 1132communicate with @value{GDBN} using it as a back end.
21c294e6 1133@xref{Interpreters, , Command Interpreters}.
94bbb2c0 1134
da0f9dcd 1135@samp{--interpreter=mi} (or @samp{--interpreter=mi2}) causes
2fcf52f0
AC
1136@value{GDBN} to use the @dfn{@sc{gdb/mi} interface} (@pxref{GDB/MI, ,
1137The @sc{gdb/mi} Interface}) included in @var{GDBN} version 6.0. The
1138previous @sc{gdb/mi} interface, included in @value{GDBN} version 5.3,
1139can be selected with @samp{--interpreter=mi1}. Earlier @sc{gdb/mi}
1140interfaces are not supported.
d700128c
EZ
1141
1142@item -write
1143@cindex @code{--write}
1144Open the executable and core files for both reading and writing. This
1145is equivalent to the @samp{set write on} command inside @value{GDBN}
1146(@pxref{Patching}).
1147
1148@item -statistics
1149@cindex @code{--statistics}
1150This option causes @value{GDBN} to print statistics about time and
1151memory usage after it completes each command and returns to the prompt.
1152
1153@item -version
1154@cindex @code{--version}
1155This option causes @value{GDBN} to print its version number and
1156no-warranty blurb, and exit.
1157
c906108c
SS
1158@end table
1159
6d2ebf8b 1160@node Quitting GDB
c906108c
SS
1161@section Quitting @value{GDBN}
1162@cindex exiting @value{GDBN}
1163@cindex leaving @value{GDBN}
1164
1165@table @code
1166@kindex quit @r{[}@var{expression}@r{]}
41afff9a 1167@kindex q @r{(@code{quit})}
96a2c332
SS
1168@item quit @r{[}@var{expression}@r{]}
1169@itemx q
1170To exit @value{GDBN}, use the @code{quit} command (abbreviated
1171@code{q}), or type an end-of-file character (usually @kbd{C-d}). If you
1172do not supply @var{expression}, @value{GDBN} will terminate normally;
1173otherwise it will terminate using the result of @var{expression} as the
1174error code.
c906108c
SS
1175@end table
1176
1177@cindex interrupt
1178An interrupt (often @kbd{C-c}) does not exit from @value{GDBN}, but rather
1179terminates the action of any @value{GDBN} command that is in progress and
1180returns to @value{GDBN} command level. It is safe to type the interrupt
1181character at any time because @value{GDBN} does not allow it to take effect
1182until a time when it is safe.
1183
c906108c
SS
1184If you have been using @value{GDBN} to control an attached process or
1185device, you can release it with the @code{detach} command
1186(@pxref{Attach, ,Debugging an already-running process}).
c906108c 1187
6d2ebf8b 1188@node Shell Commands
c906108c
SS
1189@section Shell commands
1190
1191If you need to execute occasional shell commands during your
1192debugging session, there is no need to leave or suspend @value{GDBN}; you can
1193just use the @code{shell} command.
1194
1195@table @code
1196@kindex shell
1197@cindex shell escape
1198@item shell @var{command string}
1199Invoke a standard shell to execute @var{command string}.
c906108c 1200If it exists, the environment variable @code{SHELL} determines which
d4f3574e
SS
1201shell to run. Otherwise @value{GDBN} uses the default shell
1202(@file{/bin/sh} on Unix systems, @file{COMMAND.COM} on MS-DOS, etc.).
c906108c
SS
1203@end table
1204
1205The utility @code{make} is often needed in development environments.
1206You do not have to use the @code{shell} command for this purpose in
1207@value{GDBN}:
1208
1209@table @code
1210@kindex make
1211@cindex calling make
1212@item make @var{make-args}
1213Execute the @code{make} program with the specified
1214arguments. This is equivalent to @samp{shell make @var{make-args}}.
1215@end table
1216
0fac0b41
DJ
1217@node Logging output
1218@section Logging output
1219@cindex logging @value{GDBN} output
1220
1221You may want to save the output of @value{GDBN} commands to a file.
1222There are several commands to control @value{GDBN}'s logging.
1223
1224@table @code
1225@kindex set logging
1226@item set logging on
1227Enable logging.
1228@item set logging off
1229Disable logging.
1230@item set logging file @var{file}
1231Change the name of the current logfile. The default logfile is @file{gdb.txt}.
1232@item set logging overwrite [on|off]
1233By default, @value{GDBN} will append to the logfile. Set @code{overwrite} if
1234you want @code{set logging on} to overwrite the logfile instead.
1235@item set logging redirect [on|off]
1236By default, @value{GDBN} output will go to both the terminal and the logfile.
1237Set @code{redirect} if you want output to go only to the log file.
1238@kindex show logging
1239@item show logging
1240Show the current values of the logging settings.
1241@end table
1242
6d2ebf8b 1243@node Commands
c906108c
SS
1244@chapter @value{GDBN} Commands
1245
1246You can abbreviate a @value{GDBN} command to the first few letters of the command
1247name, if that abbreviation is unambiguous; and you can repeat certain
1248@value{GDBN} commands by typing just @key{RET}. You can also use the @key{TAB}
1249key to get @value{GDBN} to fill out the rest of a word in a command (or to
1250show you the alternatives available, if there is more than one possibility).
1251
1252@menu
1253* Command Syntax:: How to give commands to @value{GDBN}
1254* Completion:: Command completion
1255* Help:: How to ask @value{GDBN} for help
1256@end menu
1257
6d2ebf8b 1258@node Command Syntax
c906108c
SS
1259@section Command syntax
1260
1261A @value{GDBN} command is a single line of input. There is no limit on
1262how long it can be. It starts with a command name, which is followed by
1263arguments whose meaning depends on the command name. For example, the
1264command @code{step} accepts an argument which is the number of times to
1265step, as in @samp{step 5}. You can also use the @code{step} command
96a2c332 1266with no arguments. Some commands do not allow any arguments.
c906108c
SS
1267
1268@cindex abbreviation
1269@value{GDBN} command names may always be truncated if that abbreviation is
1270unambiguous. Other possible command abbreviations are listed in the
1271documentation for individual commands. In some cases, even ambiguous
1272abbreviations are allowed; for example, @code{s} is specially defined as
1273equivalent to @code{step} even though there are other commands whose
1274names start with @code{s}. You can test abbreviations by using them as
1275arguments to the @code{help} command.
1276
1277@cindex repeating commands
41afff9a 1278@kindex RET @r{(repeat last command)}
c906108c 1279A blank line as input to @value{GDBN} (typing just @key{RET}) means to
96a2c332 1280repeat the previous command. Certain commands (for example, @code{run})
c906108c
SS
1281will not repeat this way; these are commands whose unintentional
1282repetition might cause trouble and which you are unlikely to want to
1283repeat.
1284
1285The @code{list} and @code{x} commands, when you repeat them with
1286@key{RET}, construct new arguments rather than repeating
1287exactly as typed. This permits easy scanning of source or memory.
1288
1289@value{GDBN} can also use @key{RET} in another way: to partition lengthy
1290output, in a way similar to the common utility @code{more}
1291(@pxref{Screen Size,,Screen size}). Since it is easy to press one
1292@key{RET} too many in this situation, @value{GDBN} disables command
1293repetition after any command that generates this sort of display.
1294
41afff9a 1295@kindex # @r{(a comment)}
c906108c
SS
1296@cindex comment
1297Any text from a @kbd{#} to the end of the line is a comment; it does
1298nothing. This is useful mainly in command files (@pxref{Command
1299Files,,Command files}).
1300
88118b3a
TT
1301@cindex repeating command sequences
1302@kindex C-o @r{(operate-and-get-next)}
1303The @kbd{C-o} binding is useful for repeating a complex sequence of
1304commands. This command accepts the current line, like @kbd{RET}, and
1305then fetches the next line relative to the current line from the history
1306for editing.
1307
6d2ebf8b 1308@node Completion
c906108c
SS
1309@section Command completion
1310
1311@cindex completion
1312@cindex word completion
1313@value{GDBN} can fill in the rest of a word in a command for you, if there is
1314only one possibility; it can also show you what the valid possibilities
1315are for the next word in a command, at any time. This works for @value{GDBN}
1316commands, @value{GDBN} subcommands, and the names of symbols in your program.
1317
1318Press the @key{TAB} key whenever you want @value{GDBN} to fill out the rest
1319of a word. If there is only one possibility, @value{GDBN} fills in the
1320word, and waits for you to finish the command (or press @key{RET} to
1321enter it). For example, if you type
1322
1323@c FIXME "@key" does not distinguish its argument sufficiently to permit
1324@c complete accuracy in these examples; space introduced for clarity.
1325@c If texinfo enhancements make it unnecessary, it would be nice to
1326@c replace " @key" by "@key" in the following...
474c8240 1327@smallexample
c906108c 1328(@value{GDBP}) info bre @key{TAB}
474c8240 1329@end smallexample
c906108c
SS
1330
1331@noindent
1332@value{GDBN} fills in the rest of the word @samp{breakpoints}, since that is
1333the only @code{info} subcommand beginning with @samp{bre}:
1334
474c8240 1335@smallexample
c906108c 1336(@value{GDBP}) info breakpoints
474c8240 1337@end smallexample
c906108c
SS
1338
1339@noindent
1340You can either press @key{RET} at this point, to run the @code{info
1341breakpoints} command, or backspace and enter something else, if
1342@samp{breakpoints} does not look like the command you expected. (If you
1343were sure you wanted @code{info breakpoints} in the first place, you
1344might as well just type @key{RET} immediately after @samp{info bre},
1345to exploit command abbreviations rather than command completion).
1346
1347If there is more than one possibility for the next word when you press
1348@key{TAB}, @value{GDBN} sounds a bell. You can either supply more
1349characters and try again, or just press @key{TAB} a second time;
1350@value{GDBN} displays all the possible completions for that word. For
1351example, you might want to set a breakpoint on a subroutine whose name
1352begins with @samp{make_}, but when you type @kbd{b make_@key{TAB}} @value{GDBN}
1353just sounds the bell. Typing @key{TAB} again displays all the
1354function names in your program that begin with those characters, for
1355example:
1356
474c8240 1357@smallexample
c906108c
SS
1358(@value{GDBP}) b make_ @key{TAB}
1359@exdent @value{GDBN} sounds bell; press @key{TAB} again, to see:
5d161b24
DB
1360make_a_section_from_file make_environ
1361make_abs_section make_function_type
1362make_blockvector make_pointer_type
1363make_cleanup make_reference_type
c906108c
SS
1364make_command make_symbol_completion_list
1365(@value{GDBP}) b make_
474c8240 1366@end smallexample
c906108c
SS
1367
1368@noindent
1369After displaying the available possibilities, @value{GDBN} copies your
1370partial input (@samp{b make_} in the example) so you can finish the
1371command.
1372
1373If you just want to see the list of alternatives in the first place, you
b37052ae 1374can press @kbd{M-?} rather than pressing @key{TAB} twice. @kbd{M-?}
7a292a7a 1375means @kbd{@key{META} ?}. You can type this either by holding down a
c906108c 1376key designated as the @key{META} shift on your keyboard (if there is
7a292a7a 1377one) while typing @kbd{?}, or as @key{ESC} followed by @kbd{?}.
c906108c
SS
1378
1379@cindex quotes in commands
1380@cindex completion of quoted strings
1381Sometimes the string you need, while logically a ``word'', may contain
7a292a7a
SS
1382parentheses or other characters that @value{GDBN} normally excludes from
1383its notion of a word. To permit word completion to work in this
1384situation, you may enclose words in @code{'} (single quote marks) in
1385@value{GDBN} commands.
c906108c 1386
c906108c 1387The most likely situation where you might need this is in typing the
b37052ae
EZ
1388name of a C@t{++} function. This is because C@t{++} allows function
1389overloading (multiple definitions of the same function, distinguished
1390by argument type). For example, when you want to set a breakpoint you
1391may need to distinguish whether you mean the version of @code{name}
1392that takes an @code{int} parameter, @code{name(int)}, or the version
1393that takes a @code{float} parameter, @code{name(float)}. To use the
1394word-completion facilities in this situation, type a single quote
1395@code{'} at the beginning of the function name. This alerts
1396@value{GDBN} that it may need to consider more information than usual
1397when you press @key{TAB} or @kbd{M-?} to request word completion:
c906108c 1398
474c8240 1399@smallexample
96a2c332 1400(@value{GDBP}) b 'bubble( @kbd{M-?}
c906108c
SS
1401bubble(double,double) bubble(int,int)
1402(@value{GDBP}) b 'bubble(
474c8240 1403@end smallexample
c906108c
SS
1404
1405In some cases, @value{GDBN} can tell that completing a name requires using
1406quotes. When this happens, @value{GDBN} inserts the quote for you (while
1407completing as much as it can) if you do not type the quote in the first
1408place:
1409
474c8240 1410@smallexample
c906108c
SS
1411(@value{GDBP}) b bub @key{TAB}
1412@exdent @value{GDBN} alters your input line to the following, and rings a bell:
1413(@value{GDBP}) b 'bubble(
474c8240 1414@end smallexample
c906108c
SS
1415
1416@noindent
1417In general, @value{GDBN} can tell that a quote is needed (and inserts it) if
1418you have not yet started typing the argument list when you ask for
1419completion on an overloaded symbol.
1420
d4f3574e 1421For more information about overloaded functions, see @ref{C plus plus
b37052ae 1422expressions, ,C@t{++} expressions}. You can use the command @code{set
c906108c 1423overload-resolution off} to disable overload resolution;
b37052ae 1424see @ref{Debugging C plus plus, ,@value{GDBN} features for C@t{++}}.
c906108c
SS
1425
1426
6d2ebf8b 1427@node Help
c906108c
SS
1428@section Getting help
1429@cindex online documentation
1430@kindex help
1431
5d161b24 1432You can always ask @value{GDBN} itself for information on its commands,
c906108c
SS
1433using the command @code{help}.
1434
1435@table @code
41afff9a 1436@kindex h @r{(@code{help})}
c906108c
SS
1437@item help
1438@itemx h
1439You can use @code{help} (abbreviated @code{h}) with no arguments to
1440display a short list of named classes of commands:
1441
1442@smallexample
1443(@value{GDBP}) help
1444List of classes of commands:
1445
2df3850c 1446aliases -- Aliases of other commands
c906108c 1447breakpoints -- Making program stop at certain points
2df3850c 1448data -- Examining data
c906108c 1449files -- Specifying and examining files
2df3850c
JM
1450internals -- Maintenance commands
1451obscure -- Obscure features
1452running -- Running the program
1453stack -- Examining the stack
c906108c
SS
1454status -- Status inquiries
1455support -- Support facilities
96a2c332
SS
1456tracepoints -- Tracing of program execution without@*
1457 stopping the program
c906108c 1458user-defined -- User-defined commands
c906108c 1459
5d161b24 1460Type "help" followed by a class name for a list of
c906108c 1461commands in that class.
5d161b24 1462Type "help" followed by command name for full
c906108c
SS
1463documentation.
1464Command name abbreviations are allowed if unambiguous.
1465(@value{GDBP})
1466@end smallexample
96a2c332 1467@c the above line break eliminates huge line overfull...
c906108c
SS
1468
1469@item help @var{class}
1470Using one of the general help classes as an argument, you can get a
1471list of the individual commands in that class. For example, here is the
1472help display for the class @code{status}:
1473
1474@smallexample
1475(@value{GDBP}) help status
1476Status inquiries.
1477
1478List of commands:
1479
1480@c Line break in "show" line falsifies real output, but needed
1481@c to fit in smallbook page size.
2df3850c
JM
1482info -- Generic command for showing things
1483 about the program being debugged
1484show -- Generic command for showing things
1485 about the debugger
c906108c 1486
5d161b24 1487Type "help" followed by command name for full
c906108c
SS
1488documentation.
1489Command name abbreviations are allowed if unambiguous.
1490(@value{GDBP})
1491@end smallexample
1492
1493@item help @var{command}
1494With a command name as @code{help} argument, @value{GDBN} displays a
1495short paragraph on how to use that command.
1496
6837a0a2
DB
1497@kindex apropos
1498@item apropos @var{args}
1499The @code{apropos @var{args}} command searches through all of the @value{GDBN}
1500commands, and their documentation, for the regular expression specified in
1501@var{args}. It prints out all matches found. For example:
1502
1503@smallexample
1504apropos reload
1505@end smallexample
1506
b37052ae
EZ
1507@noindent
1508results in:
6837a0a2
DB
1509
1510@smallexample
6d2ebf8b
SS
1511@c @group
1512set symbol-reloading -- Set dynamic symbol table reloading
1513 multiple times in one run
1514show symbol-reloading -- Show dynamic symbol table reloading
1515 multiple times in one run
1516@c @end group
6837a0a2
DB
1517@end smallexample
1518
c906108c
SS
1519@kindex complete
1520@item complete @var{args}
1521The @code{complete @var{args}} command lists all the possible completions
1522for the beginning of a command. Use @var{args} to specify the beginning of the
1523command you want completed. For example:
1524
1525@smallexample
1526complete i
1527@end smallexample
1528
1529@noindent results in:
1530
1531@smallexample
1532@group
2df3850c
JM
1533if
1534ignore
c906108c
SS
1535info
1536inspect
c906108c
SS
1537@end group
1538@end smallexample
1539
1540@noindent This is intended for use by @sc{gnu} Emacs.
1541@end table
1542
1543In addition to @code{help}, you can use the @value{GDBN} commands @code{info}
1544and @code{show} to inquire about the state of your program, or the state
1545of @value{GDBN} itself. Each command supports many topics of inquiry; this
1546manual introduces each of them in the appropriate context. The listings
1547under @code{info} and under @code{show} in the Index point to
1548all the sub-commands. @xref{Index}.
1549
1550@c @group
1551@table @code
1552@kindex info
41afff9a 1553@kindex i @r{(@code{info})}
c906108c
SS
1554@item info
1555This command (abbreviated @code{i}) is for describing the state of your
1556program. For example, you can list the arguments given to your program
1557with @code{info args}, list the registers currently in use with @code{info
1558registers}, or list the breakpoints you have set with @code{info breakpoints}.
1559You can get a complete list of the @code{info} sub-commands with
1560@w{@code{help info}}.
1561
1562@kindex set
1563@item set
5d161b24 1564You can assign the result of an expression to an environment variable with
c906108c
SS
1565@code{set}. For example, you can set the @value{GDBN} prompt to a $-sign with
1566@code{set prompt $}.
1567
1568@kindex show
1569@item show
5d161b24 1570In contrast to @code{info}, @code{show} is for describing the state of
c906108c
SS
1571@value{GDBN} itself.
1572You can change most of the things you can @code{show}, by using the
1573related command @code{set}; for example, you can control what number
1574system is used for displays with @code{set radix}, or simply inquire
1575which is currently in use with @code{show radix}.
1576
1577@kindex info set
1578To display all the settable parameters and their current
1579values, you can use @code{show} with no arguments; you may also use
1580@code{info set}. Both commands produce the same display.
1581@c FIXME: "info set" violates the rule that "info" is for state of
1582@c FIXME...program. Ck w/ GNU: "info set" to be called something else,
1583@c FIXME...or change desc of rule---eg "state of prog and debugging session"?
1584@end table
1585@c @end group
1586
1587Here are three miscellaneous @code{show} subcommands, all of which are
1588exceptional in lacking corresponding @code{set} commands:
1589
1590@table @code
1591@kindex show version
1592@cindex version number
1593@item show version
1594Show what version of @value{GDBN} is running. You should include this
2df3850c
JM
1595information in @value{GDBN} bug-reports. If multiple versions of
1596@value{GDBN} are in use at your site, you may need to determine which
1597version of @value{GDBN} you are running; as @value{GDBN} evolves, new
1598commands are introduced, and old ones may wither away. Also, many
1599system vendors ship variant versions of @value{GDBN}, and there are
96a2c332 1600variant versions of @value{GDBN} in @sc{gnu}/Linux distributions as well.
2df3850c
JM
1601The version number is the same as the one announced when you start
1602@value{GDBN}.
c906108c
SS
1603
1604@kindex show copying
1605@item show copying
1606Display information about permission for copying @value{GDBN}.
1607
1608@kindex show warranty
1609@item show warranty
2df3850c 1610Display the @sc{gnu} ``NO WARRANTY'' statement, or a warranty,
96a2c332 1611if your version of @value{GDBN} comes with one.
2df3850c 1612
c906108c
SS
1613@end table
1614
6d2ebf8b 1615@node Running
c906108c
SS
1616@chapter Running Programs Under @value{GDBN}
1617
1618When you run a program under @value{GDBN}, you must first generate
1619debugging information when you compile it.
7a292a7a
SS
1620
1621You may start @value{GDBN} with its arguments, if any, in an environment
1622of your choice. If you are doing native debugging, you may redirect
1623your program's input and output, debug an already running process, or
1624kill a child process.
c906108c
SS
1625
1626@menu
1627* Compilation:: Compiling for debugging
1628* Starting:: Starting your program
c906108c
SS
1629* Arguments:: Your program's arguments
1630* Environment:: Your program's environment
c906108c
SS
1631
1632* Working Directory:: Your program's working directory
1633* Input/Output:: Your program's input and output
1634* Attach:: Debugging an already-running process
1635* Kill Process:: Killing the child process
c906108c
SS
1636
1637* Threads:: Debugging programs with multiple threads
1638* Processes:: Debugging programs with multiple processes
1639@end menu
1640
6d2ebf8b 1641@node Compilation
c906108c
SS
1642@section Compiling for debugging
1643
1644In order to debug a program effectively, you need to generate
1645debugging information when you compile it. This debugging information
1646is stored in the object file; it describes the data type of each
1647variable or function and the correspondence between source line numbers
1648and addresses in the executable code.
1649
1650To request debugging information, specify the @samp{-g} option when you run
1651the compiler.
1652
e2e0bcd1
JB
1653Most compilers do not include information about preprocessor macros in
1654the debugging information if you specify the @option{-g} flag alone,
1655because this information is rather large. Version 3.1 of @value{NGCC},
1656the @sc{gnu} C compiler, provides macro information if you specify the
1657options @option{-gdwarf-2} and @option{-g3}; the former option requests
1658debugging information in the Dwarf 2 format, and the latter requests
1659``extra information''. In the future, we hope to find more compact ways
1660to represent macro information, so that it can be included with
1661@option{-g} alone.
1662
c906108c
SS
1663Many C compilers are unable to handle the @samp{-g} and @samp{-O}
1664options together. Using those compilers, you cannot generate optimized
1665executables containing debugging information.
1666
53a5351d
JM
1667@value{NGCC}, the @sc{gnu} C compiler, supports @samp{-g} with or
1668without @samp{-O}, making it possible to debug optimized code. We
1669recommend that you @emph{always} use @samp{-g} whenever you compile a
1670program. You may think your program is correct, but there is no sense
1671in pushing your luck.
c906108c
SS
1672
1673@cindex optimized code, debugging
1674@cindex debugging optimized code
1675When you debug a program compiled with @samp{-g -O}, remember that the
1676optimizer is rearranging your code; the debugger shows you what is
1677really there. Do not be too surprised when the execution path does not
1678exactly match your source file! An extreme example: if you define a
1679variable, but never use it, @value{GDBN} never sees that
1680variable---because the compiler optimizes it out of existence.
1681
1682Some things do not work as well with @samp{-g -O} as with just
1683@samp{-g}, particularly on machines with instruction scheduling. If in
1684doubt, recompile with @samp{-g} alone, and if this fixes the problem,
1685please report it to us as a bug (including a test case!).
1686
1687Older versions of the @sc{gnu} C compiler permitted a variant option
1688@w{@samp{-gg}} for debugging information. @value{GDBN} no longer supports this
1689format; if your @sc{gnu} C compiler has this option, do not use it.
1690
1691@need 2000
6d2ebf8b 1692@node Starting
c906108c
SS
1693@section Starting your program
1694@cindex starting
1695@cindex running
1696
1697@table @code
1698@kindex run
41afff9a 1699@kindex r @r{(@code{run})}
c906108c
SS
1700@item run
1701@itemx r
7a292a7a
SS
1702Use the @code{run} command to start your program under @value{GDBN}.
1703You must first specify the program name (except on VxWorks) with an
1704argument to @value{GDBN} (@pxref{Invocation, ,Getting In and Out of
1705@value{GDBN}}), or by using the @code{file} or @code{exec-file} command
1706(@pxref{Files, ,Commands to specify files}).
c906108c
SS
1707
1708@end table
1709
c906108c
SS
1710If you are running your program in an execution environment that
1711supports processes, @code{run} creates an inferior process and makes
1712that process run your program. (In environments without processes,
1713@code{run} jumps to the start of your program.)
1714
1715The execution of a program is affected by certain information it
1716receives from its superior. @value{GDBN} provides ways to specify this
1717information, which you must do @emph{before} starting your program. (You
1718can change it after starting your program, but such changes only affect
1719your program the next time you start it.) This information may be
1720divided into four categories:
1721
1722@table @asis
1723@item The @emph{arguments.}
1724Specify the arguments to give your program as the arguments of the
1725@code{run} command. If a shell is available on your target, the shell
1726is used to pass the arguments, so that you may use normal conventions
1727(such as wildcard expansion or variable substitution) in describing
1728the arguments.
1729In Unix systems, you can control which shell is used with the
1730@code{SHELL} environment variable.
1731@xref{Arguments, ,Your program's arguments}.
1732
1733@item The @emph{environment.}
1734Your program normally inherits its environment from @value{GDBN}, but you can
1735use the @value{GDBN} commands @code{set environment} and @code{unset
1736environment} to change parts of the environment that affect
1737your program. @xref{Environment, ,Your program's environment}.
1738
1739@item The @emph{working directory.}
1740Your program inherits its working directory from @value{GDBN}. You can set
1741the @value{GDBN} working directory with the @code{cd} command in @value{GDBN}.
1742@xref{Working Directory, ,Your program's working directory}.
1743
1744@item The @emph{standard input and output.}
1745Your program normally uses the same device for standard input and
1746standard output as @value{GDBN} is using. You can redirect input and output
1747in the @code{run} command line, or you can use the @code{tty} command to
1748set a different device for your program.
1749@xref{Input/Output, ,Your program's input and output}.
1750
1751@cindex pipes
1752@emph{Warning:} While input and output redirection work, you cannot use
1753pipes to pass the output of the program you are debugging to another
1754program; if you attempt this, @value{GDBN} is likely to wind up debugging the
1755wrong program.
1756@end table
c906108c
SS
1757
1758When you issue the @code{run} command, your program begins to execute
1759immediately. @xref{Stopping, ,Stopping and continuing}, for discussion
1760of how to arrange for your program to stop. Once your program has
1761stopped, you may call functions in your program, using the @code{print}
1762or @code{call} commands. @xref{Data, ,Examining Data}.
1763
1764If the modification time of your symbol file has changed since the last
1765time @value{GDBN} read its symbols, @value{GDBN} discards its symbol
1766table, and reads it again. When it does this, @value{GDBN} tries to retain
1767your current breakpoints.
1768
6d2ebf8b 1769@node Arguments
c906108c
SS
1770@section Your program's arguments
1771
1772@cindex arguments (to your program)
1773The arguments to your program can be specified by the arguments of the
5d161b24 1774@code{run} command.
c906108c
SS
1775They are passed to a shell, which expands wildcard characters and
1776performs redirection of I/O, and thence to your program. Your
1777@code{SHELL} environment variable (if it exists) specifies what shell
1778@value{GDBN} uses. If you do not define @code{SHELL}, @value{GDBN} uses
d4f3574e
SS
1779the default shell (@file{/bin/sh} on Unix).
1780
1781On non-Unix systems, the program is usually invoked directly by
1782@value{GDBN}, which emulates I/O redirection via the appropriate system
1783calls, and the wildcard characters are expanded by the startup code of
1784the program, not by the shell.
c906108c
SS
1785
1786@code{run} with no arguments uses the same arguments used by the previous
1787@code{run}, or those set by the @code{set args} command.
1788
c906108c 1789@table @code
41afff9a 1790@kindex set args
c906108c
SS
1791@item set args
1792Specify the arguments to be used the next time your program is run. If
1793@code{set args} has no arguments, @code{run} executes your program
1794with no arguments. Once you have run your program with arguments,
1795using @code{set args} before the next @code{run} is the only way to run
1796it again without arguments.
1797
1798@kindex show args
1799@item show args
1800Show the arguments to give your program when it is started.
1801@end table
1802
6d2ebf8b 1803@node Environment
c906108c
SS
1804@section Your program's environment
1805
1806@cindex environment (of your program)
1807The @dfn{environment} consists of a set of environment variables and
1808their values. Environment variables conventionally record such things as
1809your user name, your home directory, your terminal type, and your search
1810path for programs to run. Usually you set up environment variables with
1811the shell and they are inherited by all the other programs you run. When
1812debugging, it can be useful to try running your program with a modified
1813environment without having to start @value{GDBN} over again.
1814
1815@table @code
1816@kindex path
1817@item path @var{directory}
1818Add @var{directory} to the front of the @code{PATH} environment variable
17cc6a06
EZ
1819(the search path for executables) that will be passed to your program.
1820The value of @code{PATH} used by @value{GDBN} does not change.
d4f3574e
SS
1821You may specify several directory names, separated by whitespace or by a
1822system-dependent separator character (@samp{:} on Unix, @samp{;} on
1823MS-DOS and MS-Windows). If @var{directory} is already in the path, it
1824is moved to the front, so it is searched sooner.
c906108c
SS
1825
1826You can use the string @samp{$cwd} to refer to whatever is the current
1827working directory at the time @value{GDBN} searches the path. If you
1828use @samp{.} instead, it refers to the directory where you executed the
1829@code{path} command. @value{GDBN} replaces @samp{.} in the
1830@var{directory} argument (with the current path) before adding
1831@var{directory} to the search path.
1832@c 'path' is explicitly nonrepeatable, but RMS points out it is silly to
1833@c document that, since repeating it would be a no-op.
1834
1835@kindex show paths
1836@item show paths
1837Display the list of search paths for executables (the @code{PATH}
1838environment variable).
1839
1840@kindex show environment
1841@item show environment @r{[}@var{varname}@r{]}
1842Print the value of environment variable @var{varname} to be given to
1843your program when it starts. If you do not supply @var{varname},
1844print the names and values of all environment variables to be given to
1845your program. You can abbreviate @code{environment} as @code{env}.
1846
1847@kindex set environment
53a5351d 1848@item set environment @var{varname} @r{[}=@var{value}@r{]}
c906108c
SS
1849Set environment variable @var{varname} to @var{value}. The value
1850changes for your program only, not for @value{GDBN} itself. @var{value} may
1851be any string; the values of environment variables are just strings, and
1852any interpretation is supplied by your program itself. The @var{value}
1853parameter is optional; if it is eliminated, the variable is set to a
1854null value.
1855@c "any string" here does not include leading, trailing
1856@c blanks. Gnu asks: does anyone care?
1857
1858For example, this command:
1859
474c8240 1860@smallexample
c906108c 1861set env USER = foo
474c8240 1862@end smallexample
c906108c
SS
1863
1864@noindent
d4f3574e 1865tells the debugged program, when subsequently run, that its user is named
c906108c
SS
1866@samp{foo}. (The spaces around @samp{=} are used for clarity here; they
1867are not actually required.)
1868
1869@kindex unset environment
1870@item unset environment @var{varname}
1871Remove variable @var{varname} from the environment to be passed to your
1872program. This is different from @samp{set env @var{varname} =};
1873@code{unset environment} removes the variable from the environment,
1874rather than assigning it an empty value.
1875@end table
1876
d4f3574e
SS
1877@emph{Warning:} On Unix systems, @value{GDBN} runs your program using
1878the shell indicated
c906108c
SS
1879by your @code{SHELL} environment variable if it exists (or
1880@code{/bin/sh} if not). If your @code{SHELL} variable names a shell
1881that runs an initialization file---such as @file{.cshrc} for C-shell, or
1882@file{.bashrc} for BASH---any variables you set in that file affect
1883your program. You may wish to move setting of environment variables to
1884files that are only run when you sign on, such as @file{.login} or
1885@file{.profile}.
1886
6d2ebf8b 1887@node Working Directory
c906108c
SS
1888@section Your program's working directory
1889
1890@cindex working directory (of your program)
1891Each time you start your program with @code{run}, it inherits its
1892working directory from the current working directory of @value{GDBN}.
1893The @value{GDBN} working directory is initially whatever it inherited
1894from its parent process (typically the shell), but you can specify a new
1895working directory in @value{GDBN} with the @code{cd} command.
1896
1897The @value{GDBN} working directory also serves as a default for the commands
1898that specify files for @value{GDBN} to operate on. @xref{Files, ,Commands to
1899specify files}.
1900
1901@table @code
1902@kindex cd
1903@item cd @var{directory}
1904Set the @value{GDBN} working directory to @var{directory}.
1905
1906@kindex pwd
1907@item pwd
1908Print the @value{GDBN} working directory.
1909@end table
1910
6d2ebf8b 1911@node Input/Output
c906108c
SS
1912@section Your program's input and output
1913
1914@cindex redirection
1915@cindex i/o
1916@cindex terminal
1917By default, the program you run under @value{GDBN} does input and output to
5d161b24 1918the same terminal that @value{GDBN} uses. @value{GDBN} switches the terminal
c906108c
SS
1919to its own terminal modes to interact with you, but it records the terminal
1920modes your program was using and switches back to them when you continue
1921running your program.
1922
1923@table @code
1924@kindex info terminal
1925@item info terminal
1926Displays information recorded by @value{GDBN} about the terminal modes your
1927program is using.
1928@end table
1929
1930You can redirect your program's input and/or output using shell
1931redirection with the @code{run} command. For example,
1932
474c8240 1933@smallexample
c906108c 1934run > outfile
474c8240 1935@end smallexample
c906108c
SS
1936
1937@noindent
1938starts your program, diverting its output to the file @file{outfile}.
1939
1940@kindex tty
1941@cindex controlling terminal
1942Another way to specify where your program should do input and output is
1943with the @code{tty} command. This command accepts a file name as
1944argument, and causes this file to be the default for future @code{run}
1945commands. It also resets the controlling terminal for the child
1946process, for future @code{run} commands. For example,
1947
474c8240 1948@smallexample
c906108c 1949tty /dev/ttyb
474c8240 1950@end smallexample
c906108c
SS
1951
1952@noindent
1953directs that processes started with subsequent @code{run} commands
1954default to do input and output on the terminal @file{/dev/ttyb} and have
1955that as their controlling terminal.
1956
1957An explicit redirection in @code{run} overrides the @code{tty} command's
1958effect on the input/output device, but not its effect on the controlling
1959terminal.
1960
1961When you use the @code{tty} command or redirect input in the @code{run}
1962command, only the input @emph{for your program} is affected. The input
1963for @value{GDBN} still comes from your terminal.
1964
6d2ebf8b 1965@node Attach
c906108c
SS
1966@section Debugging an already-running process
1967@kindex attach
1968@cindex attach
1969
1970@table @code
1971@item attach @var{process-id}
1972This command attaches to a running process---one that was started
1973outside @value{GDBN}. (@code{info files} shows your active
1974targets.) The command takes as argument a process ID. The usual way to
1975find out the process-id of a Unix process is with the @code{ps} utility,
1976or with the @samp{jobs -l} shell command.
1977
1978@code{attach} does not repeat if you press @key{RET} a second time after
1979executing the command.
1980@end table
1981
1982To use @code{attach}, your program must be running in an environment
1983which supports processes; for example, @code{attach} does not work for
1984programs on bare-board targets that lack an operating system. You must
1985also have permission to send the process a signal.
1986
1987When you use @code{attach}, the debugger finds the program running in
1988the process first by looking in the current working directory, then (if
1989the program is not found) by using the source file search path
1990(@pxref{Source Path, ,Specifying source directories}). You can also use
1991the @code{file} command to load the program. @xref{Files, ,Commands to
1992Specify Files}.
1993
1994The first thing @value{GDBN} does after arranging to debug the specified
1995process is to stop it. You can examine and modify an attached process
53a5351d
JM
1996with all the @value{GDBN} commands that are ordinarily available when
1997you start processes with @code{run}. You can insert breakpoints; you
1998can step and continue; you can modify storage. If you would rather the
1999process continue running, you may use the @code{continue} command after
c906108c
SS
2000attaching @value{GDBN} to the process.
2001
2002@table @code
2003@kindex detach
2004@item detach
2005When you have finished debugging the attached process, you can use the
2006@code{detach} command to release it from @value{GDBN} control. Detaching
2007the process continues its execution. After the @code{detach} command,
2008that process and @value{GDBN} become completely independent once more, and you
2009are ready to @code{attach} another process or start one with @code{run}.
2010@code{detach} does not repeat if you press @key{RET} again after
2011executing the command.
2012@end table
2013
2014If you exit @value{GDBN} or use the @code{run} command while you have an
2015attached process, you kill that process. By default, @value{GDBN} asks
2016for confirmation if you try to do either of these things; you can
2017control whether or not you need to confirm by using the @code{set
2018confirm} command (@pxref{Messages/Warnings, ,Optional warnings and
2019messages}).
2020
6d2ebf8b 2021@node Kill Process
c906108c 2022@section Killing the child process
c906108c
SS
2023
2024@table @code
2025@kindex kill
2026@item kill
2027Kill the child process in which your program is running under @value{GDBN}.
2028@end table
2029
2030This command is useful if you wish to debug a core dump instead of a
2031running process. @value{GDBN} ignores any core dump file while your program
2032is running.
2033
2034On some operating systems, a program cannot be executed outside @value{GDBN}
2035while you have breakpoints set on it inside @value{GDBN}. You can use the
2036@code{kill} command in this situation to permit running your program
2037outside the debugger.
2038
2039The @code{kill} command is also useful if you wish to recompile and
2040relink your program, since on many systems it is impossible to modify an
2041executable file while it is running in a process. In this case, when you
2042next type @code{run}, @value{GDBN} notices that the file has changed, and
2043reads the symbol table again (while trying to preserve your current
2044breakpoint settings).
2045
6d2ebf8b 2046@node Threads
c906108c 2047@section Debugging programs with multiple threads
c906108c
SS
2048
2049@cindex threads of execution
2050@cindex multiple threads
2051@cindex switching threads
2052In some operating systems, such as HP-UX and Solaris, a single program
2053may have more than one @dfn{thread} of execution. The precise semantics
2054of threads differ from one operating system to another, but in general
2055the threads of a single program are akin to multiple processes---except
2056that they share one address space (that is, they can all examine and
2057modify the same variables). On the other hand, each thread has its own
2058registers and execution stack, and perhaps private memory.
2059
2060@value{GDBN} provides these facilities for debugging multi-thread
2061programs:
2062
2063@itemize @bullet
2064@item automatic notification of new threads
2065@item @samp{thread @var{threadno}}, a command to switch among threads
2066@item @samp{info threads}, a command to inquire about existing threads
5d161b24 2067@item @samp{thread apply [@var{threadno}] [@var{all}] @var{args}},
c906108c
SS
2068a command to apply a command to a list of threads
2069@item thread-specific breakpoints
2070@end itemize
2071
c906108c
SS
2072@quotation
2073@emph{Warning:} These facilities are not yet available on every
2074@value{GDBN} configuration where the operating system supports threads.
2075If your @value{GDBN} does not support threads, these commands have no
2076effect. For example, a system without thread support shows no output
2077from @samp{info threads}, and always rejects the @code{thread} command,
2078like this:
2079
2080@smallexample
2081(@value{GDBP}) info threads
2082(@value{GDBP}) thread 1
2083Thread ID 1 not known. Use the "info threads" command to
2084see the IDs of currently known threads.
2085@end smallexample
2086@c FIXME to implementors: how hard would it be to say "sorry, this GDB
2087@c doesn't support threads"?
2088@end quotation
c906108c
SS
2089
2090@cindex focus of debugging
2091@cindex current thread
2092The @value{GDBN} thread debugging facility allows you to observe all
2093threads while your program runs---but whenever @value{GDBN} takes
2094control, one thread in particular is always the focus of debugging.
2095This thread is called the @dfn{current thread}. Debugging commands show
2096program information from the perspective of the current thread.
2097
41afff9a 2098@cindex @code{New} @var{systag} message
c906108c
SS
2099@cindex thread identifier (system)
2100@c FIXME-implementors!! It would be more helpful if the [New...] message
2101@c included GDB's numeric thread handle, so you could just go to that
2102@c thread without first checking `info threads'.
2103Whenever @value{GDBN} detects a new thread in your program, it displays
2104the target system's identification for the thread with a message in the
2105form @samp{[New @var{systag}]}. @var{systag} is a thread identifier
2106whose form varies depending on the particular system. For example, on
2107LynxOS, you might see
2108
474c8240 2109@smallexample
c906108c 2110[New process 35 thread 27]
474c8240 2111@end smallexample
c906108c
SS
2112
2113@noindent
2114when @value{GDBN} notices a new thread. In contrast, on an SGI system,
2115the @var{systag} is simply something like @samp{process 368}, with no
2116further qualifier.
2117
2118@c FIXME!! (1) Does the [New...] message appear even for the very first
2119@c thread of a program, or does it only appear for the
6ca652b0 2120@c second---i.e.@: when it becomes obvious we have a multithread
c906108c
SS
2121@c program?
2122@c (2) *Is* there necessarily a first thread always? Or do some
2123@c multithread systems permit starting a program with multiple
5d161b24 2124@c threads ab initio?
c906108c
SS
2125
2126@cindex thread number
2127@cindex thread identifier (GDB)
2128For debugging purposes, @value{GDBN} associates its own thread
2129number---always a single integer---with each thread in your program.
2130
2131@table @code
2132@kindex info threads
2133@item info threads
2134Display a summary of all threads currently in your
2135program. @value{GDBN} displays for each thread (in this order):
2136
2137@enumerate
2138@item the thread number assigned by @value{GDBN}
2139
2140@item the target system's thread identifier (@var{systag})
2141
2142@item the current stack frame summary for that thread
2143@end enumerate
2144
2145@noindent
2146An asterisk @samp{*} to the left of the @value{GDBN} thread number
2147indicates the current thread.
2148
5d161b24 2149For example,
c906108c
SS
2150@end table
2151@c end table here to get a little more width for example
2152
2153@smallexample
2154(@value{GDBP}) info threads
2155 3 process 35 thread 27 0x34e5 in sigpause ()
2156 2 process 35 thread 23 0x34e5 in sigpause ()
2157* 1 process 35 thread 13 main (argc=1, argv=0x7ffffff8)
2158 at threadtest.c:68
2159@end smallexample
53a5351d
JM
2160
2161On HP-UX systems:
c906108c
SS
2162
2163@cindex thread number
2164@cindex thread identifier (GDB)
2165For debugging purposes, @value{GDBN} associates its own thread
2166number---a small integer assigned in thread-creation order---with each
2167thread in your program.
2168
41afff9a
EZ
2169@cindex @code{New} @var{systag} message, on HP-UX
2170@cindex thread identifier (system), on HP-UX
c906108c
SS
2171@c FIXME-implementors!! It would be more helpful if the [New...] message
2172@c included GDB's numeric thread handle, so you could just go to that
2173@c thread without first checking `info threads'.
2174Whenever @value{GDBN} detects a new thread in your program, it displays
2175both @value{GDBN}'s thread number and the target system's identification for the thread with a message in the
2176form @samp{[New @var{systag}]}. @var{systag} is a thread identifier
2177whose form varies depending on the particular system. For example, on
2178HP-UX, you see
2179
474c8240 2180@smallexample
c906108c 2181[New thread 2 (system thread 26594)]
474c8240 2182@end smallexample
c906108c
SS
2183
2184@noindent
5d161b24 2185when @value{GDBN} notices a new thread.
c906108c
SS
2186
2187@table @code
2188@kindex info threads
2189@item info threads
2190Display a summary of all threads currently in your
2191program. @value{GDBN} displays for each thread (in this order):
2192
2193@enumerate
2194@item the thread number assigned by @value{GDBN}
2195
2196@item the target system's thread identifier (@var{systag})
2197
2198@item the current stack frame summary for that thread
2199@end enumerate
2200
2201@noindent
2202An asterisk @samp{*} to the left of the @value{GDBN} thread number
2203indicates the current thread.
2204
5d161b24 2205For example,
c906108c
SS
2206@end table
2207@c end table here to get a little more width for example
2208
474c8240 2209@smallexample
c906108c 2210(@value{GDBP}) info threads
6d2ebf8b
SS
2211 * 3 system thread 26607 worker (wptr=0x7b09c318 "@@") \@*
2212 at quicksort.c:137
2213 2 system thread 26606 0x7b0030d8 in __ksleep () \@*
2214 from /usr/lib/libc.2
2215 1 system thread 27905 0x7b003498 in _brk () \@*
2216 from /usr/lib/libc.2
474c8240 2217@end smallexample
c906108c
SS
2218
2219@table @code
2220@kindex thread @var{threadno}
2221@item thread @var{threadno}
2222Make thread number @var{threadno} the current thread. The command
2223argument @var{threadno} is the internal @value{GDBN} thread number, as
2224shown in the first field of the @samp{info threads} display.
2225@value{GDBN} responds by displaying the system identifier of the thread
2226you selected, and its current stack frame summary:
2227
2228@smallexample
2229@c FIXME!! This example made up; find a @value{GDBN} w/threads and get real one
2230(@value{GDBP}) thread 2
c906108c 2231[Switching to process 35 thread 23]
c906108c
SS
22320x34e5 in sigpause ()
2233@end smallexample
2234
2235@noindent
2236As with the @samp{[New @dots{}]} message, the form of the text after
2237@samp{Switching to} depends on your system's conventions for identifying
5d161b24 2238threads.
c906108c
SS
2239
2240@kindex thread apply
2241@item thread apply [@var{threadno}] [@var{all}] @var{args}
2242The @code{thread apply} command allows you to apply a command to one or
2243more threads. Specify the numbers of the threads that you want affected
2244with the command argument @var{threadno}. @var{threadno} is the internal
2245@value{GDBN} thread number, as shown in the first field of the @samp{info
5d161b24
DB
2246threads} display. To apply a command to all threads, use
2247@code{thread apply all} @var{args}.
c906108c
SS
2248@end table
2249
2250@cindex automatic thread selection
2251@cindex switching threads automatically
2252@cindex threads, automatic switching
2253Whenever @value{GDBN} stops your program, due to a breakpoint or a
2254signal, it automatically selects the thread where that breakpoint or
2255signal happened. @value{GDBN} alerts you to the context switch with a
2256message of the form @samp{[Switching to @var{systag}]} to identify the
2257thread.
2258
2259@xref{Thread Stops,,Stopping and starting multi-thread programs}, for
2260more information about how @value{GDBN} behaves when you stop and start
2261programs with multiple threads.
2262
2263@xref{Set Watchpoints,,Setting watchpoints}, for information about
2264watchpoints in programs with multiple threads.
c906108c 2265
6d2ebf8b 2266@node Processes
c906108c
SS
2267@section Debugging programs with multiple processes
2268
2269@cindex fork, debugging programs which call
2270@cindex multiple processes
2271@cindex processes, multiple
53a5351d
JM
2272On most systems, @value{GDBN} has no special support for debugging
2273programs which create additional processes using the @code{fork}
2274function. When a program forks, @value{GDBN} will continue to debug the
2275parent process and the child process will run unimpeded. If you have
2276set a breakpoint in any code which the child then executes, the child
2277will get a @code{SIGTRAP} signal which (unless it catches the signal)
2278will cause it to terminate.
c906108c
SS
2279
2280However, if you want to debug the child process there is a workaround
2281which isn't too painful. Put a call to @code{sleep} in the code which
2282the child process executes after the fork. It may be useful to sleep
2283only if a certain environment variable is set, or a certain file exists,
2284so that the delay need not occur when you don't want to run @value{GDBN}
2285on the child. While the child is sleeping, use the @code{ps} program to
2286get its process ID. Then tell @value{GDBN} (a new invocation of
2287@value{GDBN} if you are also debugging the parent process) to attach to
d4f3574e 2288the child process (@pxref{Attach}). From that point on you can debug
c906108c 2289the child process just like any other process which you attached to.
c906108c 2290
53a5351d
JM
2291On HP-UX (11.x and later only?), @value{GDBN} provides support for
2292debugging programs that create additional processes using the
2293@code{fork} or @code{vfork} function.
c906108c
SS
2294
2295By default, when a program forks, @value{GDBN} will continue to debug
2296the parent process and the child process will run unimpeded.
2297
2298If you want to follow the child process instead of the parent process,
2299use the command @w{@code{set follow-fork-mode}}.
2300
2301@table @code
2302@kindex set follow-fork-mode
2303@item set follow-fork-mode @var{mode}
2304Set the debugger response to a program call of @code{fork} or
2305@code{vfork}. A call to @code{fork} or @code{vfork} creates a new
2306process. The @var{mode} can be:
2307
2308@table @code
2309@item parent
2310The original process is debugged after a fork. The child process runs
2df3850c 2311unimpeded. This is the default.
c906108c
SS
2312
2313@item child
2314The new process is debugged after a fork. The parent process runs
2315unimpeded.
2316
2317@item ask
2318The debugger will ask for one of the above choices.
2319@end table
2320
2321@item show follow-fork-mode
2df3850c 2322Display the current debugger response to a @code{fork} or @code{vfork} call.
c906108c
SS
2323@end table
2324
2325If you ask to debug a child process and a @code{vfork} is followed by an
2326@code{exec}, @value{GDBN} executes the new target up to the first
2327breakpoint in the new target. If you have a breakpoint set on
2328@code{main} in your original program, the breakpoint will also be set on
2329the child process's @code{main}.
2330
2331When a child process is spawned by @code{vfork}, you cannot debug the
2332child or parent until an @code{exec} call completes.
2333
2334If you issue a @code{run} command to @value{GDBN} after an @code{exec}
2335call executes, the new target restarts. To restart the parent process,
2336use the @code{file} command with the parent executable name as its
2337argument.
2338
2339You can use the @code{catch} command to make @value{GDBN} stop whenever
2340a @code{fork}, @code{vfork}, or @code{exec} call is made. @xref{Set
2341Catchpoints, ,Setting catchpoints}.
c906108c 2342
6d2ebf8b 2343@node Stopping
c906108c
SS
2344@chapter Stopping and Continuing
2345
2346The principal purposes of using a debugger are so that you can stop your
2347program before it terminates; or so that, if your program runs into
2348trouble, you can investigate and find out why.
2349
7a292a7a
SS
2350Inside @value{GDBN}, your program may stop for any of several reasons,
2351such as a signal, a breakpoint, or reaching a new line after a
2352@value{GDBN} command such as @code{step}. You may then examine and
2353change variables, set new breakpoints or remove old ones, and then
2354continue execution. Usually, the messages shown by @value{GDBN} provide
2355ample explanation of the status of your program---but you can also
2356explicitly request this information at any time.
c906108c
SS
2357
2358@table @code
2359@kindex info program
2360@item info program
2361Display information about the status of your program: whether it is
7a292a7a 2362running or not, what process it is, and why it stopped.
c906108c
SS
2363@end table
2364
2365@menu
2366* Breakpoints:: Breakpoints, watchpoints, and catchpoints
2367* Continuing and Stepping:: Resuming execution
c906108c 2368* Signals:: Signals
c906108c 2369* Thread Stops:: Stopping and starting multi-thread programs
c906108c
SS
2370@end menu
2371
6d2ebf8b 2372@node Breakpoints
c906108c
SS
2373@section Breakpoints, watchpoints, and catchpoints
2374
2375@cindex breakpoints
2376A @dfn{breakpoint} makes your program stop whenever a certain point in
2377the program is reached. For each breakpoint, you can add conditions to
2378control in finer detail whether your program stops. You can set
2379breakpoints with the @code{break} command and its variants (@pxref{Set
2380Breaks, ,Setting breakpoints}), to specify the place where your program
2381should stop by line number, function name or exact address in the
2382program.
2383
2384In HP-UX, SunOS 4.x, SVR4, and Alpha OSF/1 configurations, you can set
2385breakpoints in shared libraries before the executable is run. There is
2386a minor limitation on HP-UX systems: you must wait until the executable
2387is run in order to set breakpoints in shared library routines that are
2388not called directly by the program (for example, routines that are
2389arguments in a @code{pthread_create} call).
2390
2391@cindex watchpoints
2392@cindex memory tracing
2393@cindex breakpoint on memory address
2394@cindex breakpoint on variable modification
2395A @dfn{watchpoint} is a special breakpoint that stops your program
2396when the value of an expression changes. You must use a different
2397command to set watchpoints (@pxref{Set Watchpoints, ,Setting
2398watchpoints}), but aside from that, you can manage a watchpoint like
2399any other breakpoint: you enable, disable, and delete both breakpoints
2400and watchpoints using the same commands.
2401
2402You can arrange to have values from your program displayed automatically
2403whenever @value{GDBN} stops at a breakpoint. @xref{Auto Display,,
2404Automatic display}.
2405
2406@cindex catchpoints
2407@cindex breakpoint on events
2408A @dfn{catchpoint} is another special breakpoint that stops your program
b37052ae 2409when a certain kind of event occurs, such as the throwing of a C@t{++}
c906108c
SS
2410exception or the loading of a library. As with watchpoints, you use a
2411different command to set a catchpoint (@pxref{Set Catchpoints, ,Setting
2412catchpoints}), but aside from that, you can manage a catchpoint like any
2413other breakpoint. (To stop when your program receives a signal, use the
d4f3574e 2414@code{handle} command; see @ref{Signals, ,Signals}.)
c906108c
SS
2415
2416@cindex breakpoint numbers
2417@cindex numbers for breakpoints
2418@value{GDBN} assigns a number to each breakpoint, watchpoint, or
2419catchpoint when you create it; these numbers are successive integers
2420starting with one. In many of the commands for controlling various
2421features of breakpoints you use the breakpoint number to say which
2422breakpoint you want to change. Each breakpoint may be @dfn{enabled} or
2423@dfn{disabled}; if disabled, it has no effect on your program until you
2424enable it again.
2425
c5394b80
JM
2426@cindex breakpoint ranges
2427@cindex ranges of breakpoints
2428Some @value{GDBN} commands accept a range of breakpoints on which to
2429operate. A breakpoint range is either a single breakpoint number, like
2430@samp{5}, or two such numbers, in increasing order, separated by a
2431hyphen, like @samp{5-7}. When a breakpoint range is given to a command,
2432all breakpoint in that range are operated on.
2433
c906108c
SS
2434@menu
2435* Set Breaks:: Setting breakpoints
2436* Set Watchpoints:: Setting watchpoints
2437* Set Catchpoints:: Setting catchpoints
2438* Delete Breaks:: Deleting breakpoints
2439* Disabling:: Disabling breakpoints
2440* Conditions:: Break conditions
2441* Break Commands:: Breakpoint command lists
c906108c 2442* Breakpoint Menus:: Breakpoint menus
d4f3574e 2443* Error in Breakpoints:: ``Cannot insert breakpoints''
c906108c
SS
2444@end menu
2445
6d2ebf8b 2446@node Set Breaks
c906108c
SS
2447@subsection Setting breakpoints
2448
5d161b24 2449@c FIXME LMB what does GDB do if no code on line of breakpt?
c906108c
SS
2450@c consider in particular declaration with/without initialization.
2451@c
2452@c FIXME 2 is there stuff on this already? break at fun start, already init?
2453
2454@kindex break
41afff9a
EZ
2455@kindex b @r{(@code{break})}
2456@vindex $bpnum@r{, convenience variable}
c906108c
SS
2457@cindex latest breakpoint
2458Breakpoints are set with the @code{break} command (abbreviated
5d161b24 2459@code{b}). The debugger convenience variable @samp{$bpnum} records the
f3b28801 2460number of the breakpoint you've set most recently; see @ref{Convenience
c906108c
SS
2461Vars,, Convenience variables}, for a discussion of what you can do with
2462convenience variables.
2463
2464You have several ways to say where the breakpoint should go.
2465
2466@table @code
2467@item break @var{function}
5d161b24 2468Set a breakpoint at entry to function @var{function}.
c906108c 2469When using source languages that permit overloading of symbols, such as
b37052ae 2470C@t{++}, @var{function} may refer to more than one possible place to break.
c906108c 2471@xref{Breakpoint Menus,,Breakpoint menus}, for a discussion of that situation.
c906108c
SS
2472
2473@item break +@var{offset}
2474@itemx break -@var{offset}
2475Set a breakpoint some number of lines forward or back from the position
d4f3574e 2476at which execution stopped in the currently selected @dfn{stack frame}.
2df3850c 2477(@xref{Frames, ,Frames}, for a description of stack frames.)
c906108c
SS
2478
2479@item break @var{linenum}
2480Set a breakpoint at line @var{linenum} in the current source file.
d4f3574e
SS
2481The current source file is the last file whose source text was printed.
2482The breakpoint will stop your program just before it executes any of the
c906108c
SS
2483code on that line.
2484
2485@item break @var{filename}:@var{linenum}
2486Set a breakpoint at line @var{linenum} in source file @var{filename}.
2487
2488@item break @var{filename}:@var{function}
2489Set a breakpoint at entry to function @var{function} found in file
2490@var{filename}. Specifying a file name as well as a function name is
2491superfluous except when multiple files contain similarly named
2492functions.
2493
2494@item break *@var{address}
2495Set a breakpoint at address @var{address}. You can use this to set
2496breakpoints in parts of your program which do not have debugging
2497information or source files.
2498
2499@item break
2500When called without any arguments, @code{break} sets a breakpoint at
2501the next instruction to be executed in the selected stack frame
2502(@pxref{Stack, ,Examining the Stack}). In any selected frame but the
2503innermost, this makes your program stop as soon as control
2504returns to that frame. This is similar to the effect of a
2505@code{finish} command in the frame inside the selected frame---except
2506that @code{finish} does not leave an active breakpoint. If you use
2507@code{break} without an argument in the innermost frame, @value{GDBN} stops
2508the next time it reaches the current location; this may be useful
2509inside loops.
2510
2511@value{GDBN} normally ignores breakpoints when it resumes execution, until at
2512least one instruction has been executed. If it did not do this, you
2513would be unable to proceed past a breakpoint without first disabling the
2514breakpoint. This rule applies whether or not the breakpoint already
2515existed when your program stopped.
2516
2517@item break @dots{} if @var{cond}
2518Set a breakpoint with condition @var{cond}; evaluate the expression
2519@var{cond} each time the breakpoint is reached, and stop only if the
2520value is nonzero---that is, if @var{cond} evaluates as true.
2521@samp{@dots{}} stands for one of the possible arguments described
2522above (or no argument) specifying where to break. @xref{Conditions,
2523,Break conditions}, for more information on breakpoint conditions.
2524
2525@kindex tbreak
2526@item tbreak @var{args}
2527Set a breakpoint enabled only for one stop. @var{args} are the
2528same as for the @code{break} command, and the breakpoint is set in the same
2529way, but the breakpoint is automatically deleted after the first time your
2530program stops there. @xref{Disabling, ,Disabling breakpoints}.
2531
c906108c
SS
2532@kindex hbreak
2533@item hbreak @var{args}
d4f3574e
SS
2534Set a hardware-assisted breakpoint. @var{args} are the same as for the
2535@code{break} command and the breakpoint is set in the same way, but the
c906108c
SS
2536breakpoint requires hardware support and some target hardware may not
2537have this support. The main purpose of this is EPROM/ROM code
d4f3574e
SS
2538debugging, so you can set a breakpoint at an instruction without
2539changing the instruction. This can be used with the new trap-generation
2540provided by SPARClite DSU and some x86-based targets. These targets
2541will generate traps when a program accesses some data or instruction
2542address that is assigned to the debug registers. However the hardware
2543breakpoint registers can take a limited number of breakpoints. For
2544example, on the DSU, only two data breakpoints can be set at a time, and
2545@value{GDBN} will reject this command if more than two are used. Delete
2546or disable unused hardware breakpoints before setting new ones
2547(@pxref{Disabling, ,Disabling}). @xref{Conditions, ,Break conditions}.
501eef12
AC
2548@xref{set remote hardware-breakpoint-limit}.
2549
c906108c
SS
2550
2551@kindex thbreak
2552@item thbreak @var{args}
2553Set a hardware-assisted breakpoint enabled only for one stop. @var{args}
2554are the same as for the @code{hbreak} command and the breakpoint is set in
5d161b24 2555the same way. However, like the @code{tbreak} command,
c906108c
SS
2556the breakpoint is automatically deleted after the
2557first time your program stops there. Also, like the @code{hbreak}
5d161b24
DB
2558command, the breakpoint requires hardware support and some target hardware
2559may not have this support. @xref{Disabling, ,Disabling breakpoints}.
d4f3574e 2560See also @ref{Conditions, ,Break conditions}.
c906108c
SS
2561
2562@kindex rbreak
2563@cindex regular expression
2564@item rbreak @var{regex}
c906108c 2565Set breakpoints on all functions matching the regular expression
11cf8741
JM
2566@var{regex}. This command sets an unconditional breakpoint on all
2567matches, printing a list of all breakpoints it set. Once these
2568breakpoints are set, they are treated just like the breakpoints set with
2569the @code{break} command. You can delete them, disable them, or make
2570them conditional the same way as any other breakpoint.
2571
2572The syntax of the regular expression is the standard one used with tools
2573like @file{grep}. Note that this is different from the syntax used by
2574shells, so for instance @code{foo*} matches all functions that include
2575an @code{fo} followed by zero or more @code{o}s. There is an implicit
2576@code{.*} leading and trailing the regular expression you supply, so to
2577match only functions that begin with @code{foo}, use @code{^foo}.
c906108c 2578
b37052ae 2579When debugging C@t{++} programs, @code{rbreak} is useful for setting
c906108c
SS
2580breakpoints on overloaded functions that are not members of any special
2581classes.
c906108c
SS
2582
2583@kindex info breakpoints
2584@cindex @code{$_} and @code{info breakpoints}
2585@item info breakpoints @r{[}@var{n}@r{]}
2586@itemx info break @r{[}@var{n}@r{]}
2587@itemx info watchpoints @r{[}@var{n}@r{]}
2588Print a table of all breakpoints, watchpoints, and catchpoints set and
2589not deleted, with the following columns for each breakpoint:
2590
2591@table @emph
2592@item Breakpoint Numbers
2593@item Type
2594Breakpoint, watchpoint, or catchpoint.
2595@item Disposition
2596Whether the breakpoint is marked to be disabled or deleted when hit.
2597@item Enabled or Disabled
2598Enabled breakpoints are marked with @samp{y}. @samp{n} marks breakpoints
2599that are not enabled.
2600@item Address
2df3850c 2601Where the breakpoint is in your program, as a memory address.
c906108c
SS
2602@item What
2603Where the breakpoint is in the source for your program, as a file and
2604line number.
2605@end table
2606
2607@noindent
2608If a breakpoint is conditional, @code{info break} shows the condition on
2609the line following the affected breakpoint; breakpoint commands, if any,
2610are listed after that.
2611
2612@noindent
2613@code{info break} with a breakpoint
2614number @var{n} as argument lists only that breakpoint. The
2615convenience variable @code{$_} and the default examining-address for
2616the @code{x} command are set to the address of the last breakpoint
5d161b24 2617listed (@pxref{Memory, ,Examining memory}).
c906108c
SS
2618
2619@noindent
2620@code{info break} displays a count of the number of times the breakpoint
2621has been hit. This is especially useful in conjunction with the
2622@code{ignore} command. You can ignore a large number of breakpoint
2623hits, look at the breakpoint info to see how many times the breakpoint
2624was hit, and then run again, ignoring one less than that number. This
2625will get you quickly to the last hit of that breakpoint.
2626@end table
2627
2628@value{GDBN} allows you to set any number of breakpoints at the same place in
2629your program. There is nothing silly or meaningless about this. When
2630the breakpoints are conditional, this is even useful
2631(@pxref{Conditions, ,Break conditions}).
2632
2633@cindex negative breakpoint numbers
2634@cindex internal @value{GDBN} breakpoints
eb12ee30
AC
2635@value{GDBN} itself sometimes sets breakpoints in your program for
2636special purposes, such as proper handling of @code{longjmp} (in C
2637programs). These internal breakpoints are assigned negative numbers,
2638starting with @code{-1}; @samp{info breakpoints} does not display them.
c906108c 2639You can see these breakpoints with the @value{GDBN} maintenance command
eb12ee30 2640@samp{maint info breakpoints} (@pxref{maint info breakpoints}).
c906108c
SS
2641
2642
6d2ebf8b 2643@node Set Watchpoints
c906108c
SS
2644@subsection Setting watchpoints
2645
2646@cindex setting watchpoints
2647@cindex software watchpoints
2648@cindex hardware watchpoints
2649You can use a watchpoint to stop execution whenever the value of an
2650expression changes, without having to predict a particular place where
2651this may happen.
2652
2653Depending on your system, watchpoints may be implemented in software or
2df3850c 2654hardware. @value{GDBN} does software watchpointing by single-stepping your
c906108c
SS
2655program and testing the variable's value each time, which is hundreds of
2656times slower than normal execution. (But this may still be worth it, to
2657catch errors where you have no clue what part of your program is the
2658culprit.)
2659
1104b9e7 2660On some systems, such as HP-UX, @sc{gnu}/Linux and some other x86-based targets,
2df3850c 2661@value{GDBN} includes support for
c906108c
SS
2662hardware watchpoints, which do not slow down the running of your
2663program.
2664
2665@table @code
2666@kindex watch
2667@item watch @var{expr}
2668Set a watchpoint for an expression. @value{GDBN} will break when @var{expr}
2669is written into by the program and its value changes.
2670
2671@kindex rwatch
2672@item rwatch @var{expr}
2673Set a watchpoint that will break when watch @var{expr} is read by the program.
c906108c
SS
2674
2675@kindex awatch
2676@item awatch @var{expr}
2df3850c 2677Set a watchpoint that will break when @var{expr} is either read or written into
7be570e7 2678by the program.
c906108c
SS
2679
2680@kindex info watchpoints
2681@item info watchpoints
2682This command prints a list of watchpoints, breakpoints, and catchpoints;
2683it is the same as @code{info break}.
2684@end table
2685
2686@value{GDBN} sets a @dfn{hardware watchpoint} if possible. Hardware
2687watchpoints execute very quickly, and the debugger reports a change in
2688value at the exact instruction where the change occurs. If @value{GDBN}
2689cannot set a hardware watchpoint, it sets a software watchpoint, which
2690executes more slowly and reports the change in value at the next
2691statement, not the instruction, after the change occurs.
2692
2693When you issue the @code{watch} command, @value{GDBN} reports
2694
474c8240 2695@smallexample
c906108c 2696Hardware watchpoint @var{num}: @var{expr}
474c8240 2697@end smallexample
c906108c
SS
2698
2699@noindent
2700if it was able to set a hardware watchpoint.
2701
7be570e7
JM
2702Currently, the @code{awatch} and @code{rwatch} commands can only set
2703hardware watchpoints, because accesses to data that don't change the
2704value of the watched expression cannot be detected without examining
2705every instruction as it is being executed, and @value{GDBN} does not do
2706that currently. If @value{GDBN} finds that it is unable to set a
2707hardware breakpoint with the @code{awatch} or @code{rwatch} command, it
2708will print a message like this:
2709
2710@smallexample
2711Expression cannot be implemented with read/access watchpoint.
2712@end smallexample
2713
2714Sometimes, @value{GDBN} cannot set a hardware watchpoint because the
2715data type of the watched expression is wider than what a hardware
2716watchpoint on the target machine can handle. For example, some systems
2717can only watch regions that are up to 4 bytes wide; on such systems you
2718cannot set hardware watchpoints for an expression that yields a
2719double-precision floating-point number (which is typically 8 bytes
2720wide). As a work-around, it might be possible to break the large region
2721into a series of smaller ones and watch them with separate watchpoints.
2722
2723If you set too many hardware watchpoints, @value{GDBN} might be unable
2724to insert all of them when you resume the execution of your program.
2725Since the precise number of active watchpoints is unknown until such
2726time as the program is about to be resumed, @value{GDBN} might not be
2727able to warn you about this when you set the watchpoints, and the
2728warning will be printed only when the program is resumed:
2729
2730@smallexample
2731Hardware watchpoint @var{num}: Could not insert watchpoint
2732@end smallexample
2733
2734@noindent
2735If this happens, delete or disable some of the watchpoints.
2736
2737The SPARClite DSU will generate traps when a program accesses some data
2738or instruction address that is assigned to the debug registers. For the
2739data addresses, DSU facilitates the @code{watch} command. However the
2740hardware breakpoint registers can only take two data watchpoints, and
2741both watchpoints must be the same kind. For example, you can set two
2742watchpoints with @code{watch} commands, two with @code{rwatch} commands,
2743@strong{or} two with @code{awatch} commands, but you cannot set one
2744watchpoint with one command and the other with a different command.
c906108c
SS
2745@value{GDBN} will reject the command if you try to mix watchpoints.
2746Delete or disable unused watchpoint commands before setting new ones.
2747
2748If you call a function interactively using @code{print} or @code{call},
2df3850c 2749any watchpoints you have set will be inactive until @value{GDBN} reaches another
c906108c
SS
2750kind of breakpoint or the call completes.
2751
7be570e7
JM
2752@value{GDBN} automatically deletes watchpoints that watch local
2753(automatic) variables, or expressions that involve such variables, when
2754they go out of scope, that is, when the execution leaves the block in
2755which these variables were defined. In particular, when the program
2756being debugged terminates, @emph{all} local variables go out of scope,
2757and so only watchpoints that watch global variables remain set. If you
2758rerun the program, you will need to set all such watchpoints again. One
2759way of doing that would be to set a code breakpoint at the entry to the
2760@code{main} function and when it breaks, set all the watchpoints.
2761
c906108c
SS
2762@quotation
2763@cindex watchpoints and threads
2764@cindex threads and watchpoints
c906108c
SS
2765@emph{Warning:} In multi-thread programs, watchpoints have only limited
2766usefulness. With the current watchpoint implementation, @value{GDBN}
2767can only watch the value of an expression @emph{in a single thread}. If
2768you are confident that the expression can only change due to the current
2769thread's activity (and if you are also confident that no other thread
2770can become current), then you can use watchpoints as usual. However,
2771@value{GDBN} may not notice when a non-current thread's activity changes
2772the expression.
53a5351d 2773
d4f3574e 2774@c FIXME: this is almost identical to the previous paragraph.
53a5351d
JM
2775@emph{HP-UX Warning:} In multi-thread programs, software watchpoints
2776have only limited usefulness. If @value{GDBN} creates a software
2777watchpoint, it can only watch the value of an expression @emph{in a
2778single thread}. If you are confident that the expression can only
2779change due to the current thread's activity (and if you are also
2780confident that no other thread can become current), then you can use
2781software watchpoints as usual. However, @value{GDBN} may not notice
2782when a non-current thread's activity changes the expression. (Hardware
2783watchpoints, in contrast, watch an expression in all threads.)
c906108c 2784@end quotation
c906108c 2785
501eef12
AC
2786@xref{set remote hardware-watchpoint-limit}.
2787
6d2ebf8b 2788@node Set Catchpoints
c906108c 2789@subsection Setting catchpoints
d4f3574e 2790@cindex catchpoints, setting
c906108c
SS
2791@cindex exception handlers
2792@cindex event handling
2793
2794You can use @dfn{catchpoints} to cause the debugger to stop for certain
b37052ae 2795kinds of program events, such as C@t{++} exceptions or the loading of a
c906108c
SS
2796shared library. Use the @code{catch} command to set a catchpoint.
2797
2798@table @code
2799@kindex catch
2800@item catch @var{event}
2801Stop when @var{event} occurs. @var{event} can be any of the following:
2802@table @code
2803@item throw
2804@kindex catch throw
b37052ae 2805The throwing of a C@t{++} exception.
c906108c
SS
2806
2807@item catch
2808@kindex catch catch
b37052ae 2809The catching of a C@t{++} exception.
c906108c
SS
2810
2811@item exec
2812@kindex catch exec
2813A call to @code{exec}. This is currently only available for HP-UX.
2814
2815@item fork
2816@kindex catch fork
2817A call to @code{fork}. This is currently only available for HP-UX.
2818
2819@item vfork
2820@kindex catch vfork
2821A call to @code{vfork}. This is currently only available for HP-UX.
2822
2823@item load
2824@itemx load @var{libname}
2825@kindex catch load
2826The dynamic loading of any shared library, or the loading of the library
2827@var{libname}. This is currently only available for HP-UX.
2828
2829@item unload
2830@itemx unload @var{libname}
2831@kindex catch unload
2832The unloading of any dynamically loaded shared library, or the unloading
2833of the library @var{libname}. This is currently only available for HP-UX.
2834@end table
2835
2836@item tcatch @var{event}
2837Set a catchpoint that is enabled only for one stop. The catchpoint is
2838automatically deleted after the first time the event is caught.
2839
2840@end table
2841
2842Use the @code{info break} command to list the current catchpoints.
2843
b37052ae 2844There are currently some limitations to C@t{++} exception handling
c906108c
SS
2845(@code{catch throw} and @code{catch catch}) in @value{GDBN}:
2846
2847@itemize @bullet
2848@item
2849If you call a function interactively, @value{GDBN} normally returns
2850control to you when the function has finished executing. If the call
2851raises an exception, however, the call may bypass the mechanism that
2852returns control to you and cause your program either to abort or to
2853simply continue running until it hits a breakpoint, catches a signal
2854that @value{GDBN} is listening for, or exits. This is the case even if
2855you set a catchpoint for the exception; catchpoints on exceptions are
2856disabled within interactive calls.
2857
2858@item
2859You cannot raise an exception interactively.
2860
2861@item
2862You cannot install an exception handler interactively.
2863@end itemize
2864
2865@cindex raise exceptions
2866Sometimes @code{catch} is not the best way to debug exception handling:
2867if you need to know exactly where an exception is raised, it is better to
2868stop @emph{before} the exception handler is called, since that way you
2869can see the stack before any unwinding takes place. If you set a
2870breakpoint in an exception handler instead, it may not be easy to find
2871out where the exception was raised.
2872
2873To stop just before an exception handler is called, you need some
b37052ae 2874knowledge of the implementation. In the case of @sc{gnu} C@t{++}, exceptions are
c906108c
SS
2875raised by calling a library function named @code{__raise_exception}
2876which has the following ANSI C interface:
2877
474c8240 2878@smallexample
c906108c 2879 /* @var{addr} is where the exception identifier is stored.
d4f3574e
SS
2880 @var{id} is the exception identifier. */
2881 void __raise_exception (void **addr, void *id);
474c8240 2882@end smallexample
c906108c
SS
2883
2884@noindent
2885To make the debugger catch all exceptions before any stack
2886unwinding takes place, set a breakpoint on @code{__raise_exception}
2887(@pxref{Breakpoints, ,Breakpoints; watchpoints; and exceptions}).
2888
2889With a conditional breakpoint (@pxref{Conditions, ,Break conditions})
2890that depends on the value of @var{id}, you can stop your program when
2891a specific exception is raised. You can use multiple conditional
2892breakpoints to stop your program when any of a number of exceptions are
2893raised.
2894
2895
6d2ebf8b 2896@node Delete Breaks
c906108c
SS
2897@subsection Deleting breakpoints
2898
2899@cindex clearing breakpoints, watchpoints, catchpoints
2900@cindex deleting breakpoints, watchpoints, catchpoints
2901It is often necessary to eliminate a breakpoint, watchpoint, or
2902catchpoint once it has done its job and you no longer want your program
2903to stop there. This is called @dfn{deleting} the breakpoint. A
2904breakpoint that has been deleted no longer exists; it is forgotten.
2905
2906With the @code{clear} command you can delete breakpoints according to
2907where they are in your program. With the @code{delete} command you can
2908delete individual breakpoints, watchpoints, or catchpoints by specifying
2909their breakpoint numbers.
2910
2911It is not necessary to delete a breakpoint to proceed past it. @value{GDBN}
2912automatically ignores breakpoints on the first instruction to be executed
2913when you continue execution without changing the execution address.
2914
2915@table @code
2916@kindex clear
2917@item clear
2918Delete any breakpoints at the next instruction to be executed in the
2919selected stack frame (@pxref{Selection, ,Selecting a frame}). When
2920the innermost frame is selected, this is a good way to delete a
2921breakpoint where your program just stopped.
2922
2923@item clear @var{function}
2924@itemx clear @var{filename}:@var{function}
2925Delete any breakpoints set at entry to the function @var{function}.
2926
2927@item clear @var{linenum}
2928@itemx clear @var{filename}:@var{linenum}
2929Delete any breakpoints set at or within the code of the specified line.
2930
2931@cindex delete breakpoints
2932@kindex delete
41afff9a 2933@kindex d @r{(@code{delete})}
c5394b80
JM
2934@item delete @r{[}breakpoints@r{]} @r{[}@var{range}@dots{}@r{]}
2935Delete the breakpoints, watchpoints, or catchpoints of the breakpoint
2936ranges specified as arguments. If no argument is specified, delete all
c906108c
SS
2937breakpoints (@value{GDBN} asks confirmation, unless you have @code{set
2938confirm off}). You can abbreviate this command as @code{d}.
2939@end table
2940
6d2ebf8b 2941@node Disabling
c906108c
SS
2942@subsection Disabling breakpoints
2943
2944@kindex disable breakpoints
2945@kindex enable breakpoints
2946Rather than deleting a breakpoint, watchpoint, or catchpoint, you might
2947prefer to @dfn{disable} it. This makes the breakpoint inoperative as if
2948it had been deleted, but remembers the information on the breakpoint so
2949that you can @dfn{enable} it again later.
2950
2951You disable and enable breakpoints, watchpoints, and catchpoints with
2952the @code{enable} and @code{disable} commands, optionally specifying one
2953or more breakpoint numbers as arguments. Use @code{info break} or
2954@code{info watch} to print a list of breakpoints, watchpoints, and
2955catchpoints if you do not know which numbers to use.
2956
2957A breakpoint, watchpoint, or catchpoint can have any of four different
2958states of enablement:
2959
2960@itemize @bullet
2961@item
2962Enabled. The breakpoint stops your program. A breakpoint set
2963with the @code{break} command starts out in this state.
2964@item
2965Disabled. The breakpoint has no effect on your program.
2966@item
2967Enabled once. The breakpoint stops your program, but then becomes
d4f3574e 2968disabled.
c906108c
SS
2969@item
2970Enabled for deletion. The breakpoint stops your program, but
d4f3574e
SS
2971immediately after it does so it is deleted permanently. A breakpoint
2972set with the @code{tbreak} command starts out in this state.
c906108c
SS
2973@end itemize
2974
2975You can use the following commands to enable or disable breakpoints,
2976watchpoints, and catchpoints:
2977
2978@table @code
2979@kindex disable breakpoints
2980@kindex disable
41afff9a 2981@kindex dis @r{(@code{disable})}
c5394b80 2982@item disable @r{[}breakpoints@r{]} @r{[}@var{range}@dots{}@r{]}
c906108c
SS
2983Disable the specified breakpoints---or all breakpoints, if none are
2984listed. A disabled breakpoint has no effect but is not forgotten. All
2985options such as ignore-counts, conditions and commands are remembered in
2986case the breakpoint is enabled again later. You may abbreviate
2987@code{disable} as @code{dis}.
2988
2989@kindex enable breakpoints
2990@kindex enable
c5394b80 2991@item enable @r{[}breakpoints@r{]} @r{[}@var{range}@dots{}@r{]}
c906108c
SS
2992Enable the specified breakpoints (or all defined breakpoints). They
2993become effective once again in stopping your program.
2994
c5394b80 2995@item enable @r{[}breakpoints@r{]} once @var{range}@dots{}
c906108c
SS
2996Enable the specified breakpoints temporarily. @value{GDBN} disables any
2997of these breakpoints immediately after stopping your program.
2998
c5394b80 2999@item enable @r{[}breakpoints@r{]} delete @var{range}@dots{}
c906108c
SS
3000Enable the specified breakpoints to work once, then die. @value{GDBN}
3001deletes any of these breakpoints as soon as your program stops there.
3002@end table
3003
d4f3574e
SS
3004@c FIXME: I think the following ``Except for [...] @code{tbreak}'' is
3005@c confusing: tbreak is also initially enabled.
c906108c
SS
3006Except for a breakpoint set with @code{tbreak} (@pxref{Set Breaks,
3007,Setting breakpoints}), breakpoints that you set are initially enabled;
3008subsequently, they become disabled or enabled only when you use one of
3009the commands above. (The command @code{until} can set and delete a
3010breakpoint of its own, but it does not change the state of your other
3011breakpoints; see @ref{Continuing and Stepping, ,Continuing and
3012stepping}.)
3013
6d2ebf8b 3014@node Conditions
c906108c
SS
3015@subsection Break conditions
3016@cindex conditional breakpoints
3017@cindex breakpoint conditions
3018
3019@c FIXME what is scope of break condition expr? Context where wanted?
5d161b24 3020@c in particular for a watchpoint?
c906108c
SS
3021The simplest sort of breakpoint breaks every time your program reaches a
3022specified place. You can also specify a @dfn{condition} for a
3023breakpoint. A condition is just a Boolean expression in your
3024programming language (@pxref{Expressions, ,Expressions}). A breakpoint with
3025a condition evaluates the expression each time your program reaches it,
3026and your program stops only if the condition is @emph{true}.
3027
3028This is the converse of using assertions for program validation; in that
3029situation, you want to stop when the assertion is violated---that is,
3030when the condition is false. In C, if you want to test an assertion expressed
3031by the condition @var{assert}, you should set the condition
3032@samp{! @var{assert}} on the appropriate breakpoint.
3033
3034Conditions are also accepted for watchpoints; you may not need them,
3035since a watchpoint is inspecting the value of an expression anyhow---but
3036it might be simpler, say, to just set a watchpoint on a variable name,
3037and specify a condition that tests whether the new value is an interesting
3038one.
3039
3040Break conditions can have side effects, and may even call functions in
3041your program. This can be useful, for example, to activate functions
3042that log program progress, or to use your own print functions to
3043format special data structures. The effects are completely predictable
3044unless there is another enabled breakpoint at the same address. (In
3045that case, @value{GDBN} might see the other breakpoint first and stop your
3046program without checking the condition of this one.) Note that
d4f3574e
SS
3047breakpoint commands are usually more convenient and flexible than break
3048conditions for the
c906108c
SS
3049purpose of performing side effects when a breakpoint is reached
3050(@pxref{Break Commands, ,Breakpoint command lists}).
3051
3052Break conditions can be specified when a breakpoint is set, by using
3053@samp{if} in the arguments to the @code{break} command. @xref{Set
3054Breaks, ,Setting breakpoints}. They can also be changed at any time
3055with the @code{condition} command.
53a5351d 3056
c906108c
SS
3057You can also use the @code{if} keyword with the @code{watch} command.
3058The @code{catch} command does not recognize the @code{if} keyword;
3059@code{condition} is the only way to impose a further condition on a
3060catchpoint.
c906108c
SS
3061
3062@table @code
3063@kindex condition
3064@item condition @var{bnum} @var{expression}
3065Specify @var{expression} as the break condition for breakpoint,
3066watchpoint, or catchpoint number @var{bnum}. After you set a condition,
3067breakpoint @var{bnum} stops your program only if the value of
3068@var{expression} is true (nonzero, in C). When you use
3069@code{condition}, @value{GDBN} checks @var{expression} immediately for
3070syntactic correctness, and to determine whether symbols in it have
d4f3574e
SS
3071referents in the context of your breakpoint. If @var{expression} uses
3072symbols not referenced in the context of the breakpoint, @value{GDBN}
3073prints an error message:
3074
474c8240 3075@smallexample
d4f3574e 3076No symbol "foo" in current context.
474c8240 3077@end smallexample
d4f3574e
SS
3078
3079@noindent
c906108c
SS
3080@value{GDBN} does
3081not actually evaluate @var{expression} at the time the @code{condition}
d4f3574e
SS
3082command (or a command that sets a breakpoint with a condition, like
3083@code{break if @dots{}}) is given, however. @xref{Expressions, ,Expressions}.
c906108c
SS
3084
3085@item condition @var{bnum}
3086Remove the condition from breakpoint number @var{bnum}. It becomes
3087an ordinary unconditional breakpoint.
3088@end table
3089
3090@cindex ignore count (of breakpoint)
3091A special case of a breakpoint condition is to stop only when the
3092breakpoint has been reached a certain number of times. This is so
3093useful that there is a special way to do it, using the @dfn{ignore
3094count} of the breakpoint. Every breakpoint has an ignore count, which
3095is an integer. Most of the time, the ignore count is zero, and
3096therefore has no effect. But if your program reaches a breakpoint whose
3097ignore count is positive, then instead of stopping, it just decrements
3098the ignore count by one and continues. As a result, if the ignore count
3099value is @var{n}, the breakpoint does not stop the next @var{n} times
3100your program reaches it.
3101
3102@table @code
3103@kindex ignore
3104@item ignore @var{bnum} @var{count}
3105Set the ignore count of breakpoint number @var{bnum} to @var{count}.
3106The next @var{count} times the breakpoint is reached, your program's
3107execution does not stop; other than to decrement the ignore count, @value{GDBN}
3108takes no action.
3109
3110To make the breakpoint stop the next time it is reached, specify
3111a count of zero.
3112
3113When you use @code{continue} to resume execution of your program from a
3114breakpoint, you can specify an ignore count directly as an argument to
3115@code{continue}, rather than using @code{ignore}. @xref{Continuing and
3116Stepping,,Continuing and stepping}.
3117
3118If a breakpoint has a positive ignore count and a condition, the
3119condition is not checked. Once the ignore count reaches zero,
3120@value{GDBN} resumes checking the condition.
3121
3122You could achieve the effect of the ignore count with a condition such
3123as @w{@samp{$foo-- <= 0}} using a debugger convenience variable that
3124is decremented each time. @xref{Convenience Vars, ,Convenience
3125variables}.
3126@end table
3127
3128Ignore counts apply to breakpoints, watchpoints, and catchpoints.
3129
3130
6d2ebf8b 3131@node Break Commands
c906108c
SS
3132@subsection Breakpoint command lists
3133
3134@cindex breakpoint commands
3135You can give any breakpoint (or watchpoint or catchpoint) a series of
3136commands to execute when your program stops due to that breakpoint. For
3137example, you might want to print the values of certain expressions, or
3138enable other breakpoints.
3139
3140@table @code
3141@kindex commands
3142@kindex end
3143@item commands @r{[}@var{bnum}@r{]}
3144@itemx @dots{} @var{command-list} @dots{}
3145@itemx end
3146Specify a list of commands for breakpoint number @var{bnum}. The commands
3147themselves appear on the following lines. Type a line containing just
3148@code{end} to terminate the commands.
3149
3150To remove all commands from a breakpoint, type @code{commands} and
3151follow it immediately with @code{end}; that is, give no commands.
3152
3153With no @var{bnum} argument, @code{commands} refers to the last
3154breakpoint, watchpoint, or catchpoint set (not to the breakpoint most
3155recently encountered).
3156@end table
3157
3158Pressing @key{RET} as a means of repeating the last @value{GDBN} command is
3159disabled within a @var{command-list}.
3160
3161You can use breakpoint commands to start your program up again. Simply
3162use the @code{continue} command, or @code{step}, or any other command
3163that resumes execution.
3164
3165Any other commands in the command list, after a command that resumes
3166execution, are ignored. This is because any time you resume execution
3167(even with a simple @code{next} or @code{step}), you may encounter
3168another breakpoint---which could have its own command list, leading to
3169ambiguities about which list to execute.
3170
3171@kindex silent
3172If the first command you specify in a command list is @code{silent}, the
3173usual message about stopping at a breakpoint is not printed. This may
3174be desirable for breakpoints that are to print a specific message and
3175then continue. If none of the remaining commands print anything, you
3176see no sign that the breakpoint was reached. @code{silent} is
3177meaningful only at the beginning of a breakpoint command list.
3178
3179The commands @code{echo}, @code{output}, and @code{printf} allow you to
3180print precisely controlled output, and are often useful in silent
3181breakpoints. @xref{Output, ,Commands for controlled output}.
3182
3183For example, here is how you could use breakpoint commands to print the
3184value of @code{x} at entry to @code{foo} whenever @code{x} is positive.
3185
474c8240 3186@smallexample
c906108c
SS
3187break foo if x>0
3188commands
3189silent
3190printf "x is %d\n",x
3191cont
3192end
474c8240 3193@end smallexample
c906108c
SS
3194
3195One application for breakpoint commands is to compensate for one bug so
3196you can test for another. Put a breakpoint just after the erroneous line
3197of code, give it a condition to detect the case in which something
3198erroneous has been done, and give it commands to assign correct values
3199to any variables that need them. End with the @code{continue} command
3200so that your program does not stop, and start with the @code{silent}
3201command so that no output is produced. Here is an example:
3202
474c8240 3203@smallexample
c906108c
SS
3204break 403
3205commands
3206silent
3207set x = y + 4
3208cont
3209end
474c8240 3210@end smallexample
c906108c 3211
6d2ebf8b 3212@node Breakpoint Menus
c906108c
SS
3213@subsection Breakpoint menus
3214@cindex overloading
3215@cindex symbol overloading
3216
b37303ee
AF
3217Some programming languages (notably C@t{++} and Objective-C) permit a
3218single 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
474c8240 3270@smallexample
d4f3574e
SS
3271Cannot insert breakpoints.
3272The same program may be running in another process.
474c8240 3273@end smallexample
d4f3574e
SS
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
474c8240 3478@smallexample
c906108c
SS
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) @{
474c8240 3484@end smallexample
c906108c
SS
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,
c60eb6f1
EZ
3503,Setting breakpoints}). This form of the command uses breakpoints, and
3504hence is quicker than @code{until} without an argument. The specified
3505location is actually reached only if it is in the current frame. This
3506implies that @code{until} can be used to skip over recursive function
3507invocations. For instance in the code below, if the current location is
3508line @code{96}, issuing @code{until 99} will execute the program up to
3509line @code{99} in the same invocation of factorial, i.e. after the inner
3510invocations have returned.
3511
3512@smallexample
351394 int factorial (int value)
351495 @{
351596 if (value > 1) @{
351697 value *= factorial (value - 1);
351798 @}
351899 return (value);
3519100 @}
3520@end smallexample
3521
3522
3523@kindex advance @var{location}
3524@itemx advance @var{location}
3525Continue running the program up to the given location. An argument is
3526required, anything of the same form as arguments for the @code{break}
3527command. Execution will also stop upon exit from the current stack
3528frame. This command is similar to @code{until}, but @code{advance} will
3529not skip over recursive function calls, and the target location doesn't
3530have to be in the same frame as the current one.
3531
c906108c
SS
3532
3533@kindex stepi
41afff9a 3534@kindex si @r{(@code{stepi})}
c906108c 3535@item stepi
96a2c332 3536@itemx stepi @var{arg}
c906108c
SS
3537@itemx si
3538Execute one machine instruction, then stop and return to the debugger.
3539
3540It is often useful to do @samp{display/i $pc} when stepping by machine
3541instructions. This makes @value{GDBN} automatically display the next
3542instruction to be executed, each time your program stops. @xref{Auto
3543Display,, Automatic display}.
3544
3545An argument is a repeat count, as in @code{step}.
3546
3547@need 750
3548@kindex nexti
41afff9a 3549@kindex ni @r{(@code{nexti})}
c906108c 3550@item nexti
96a2c332 3551@itemx nexti @var{arg}
c906108c
SS
3552@itemx ni
3553Execute one machine instruction, but if it is a function call,
3554proceed until the function returns.
3555
3556An argument is a repeat count, as in @code{next}.
3557@end table
3558
6d2ebf8b 3559@node Signals
c906108c
SS
3560@section Signals
3561@cindex signals
3562
3563A signal is an asynchronous event that can happen in a program. The
3564operating system defines the possible kinds of signals, and gives each
3565kind a name and a number. For example, in Unix @code{SIGINT} is the
d4f3574e 3566signal a program gets when you type an interrupt character (often @kbd{C-c});
c906108c
SS
3567@code{SIGSEGV} is the signal a program gets from referencing a place in
3568memory far away from all the areas in use; @code{SIGALRM} occurs when
3569the alarm clock timer goes off (which happens only if your program has
3570requested an alarm).
3571
3572@cindex fatal signals
3573Some signals, including @code{SIGALRM}, are a normal part of the
3574functioning of your program. Others, such as @code{SIGSEGV}, indicate
d4f3574e 3575errors; these signals are @dfn{fatal} (they kill your program immediately) if the
c906108c
SS
3576program has not specified in advance some other way to handle the signal.
3577@code{SIGINT} does not indicate an error in your program, but it is normally
3578fatal so it can carry out the purpose of the interrupt: to kill the program.
3579
3580@value{GDBN} has the ability to detect any occurrence of a signal in your
3581program. You can tell @value{GDBN} in advance what to do for each kind of
3582signal.
3583
3584@cindex handling signals
24f93129
EZ
3585Normally, @value{GDBN} is set up to let the non-erroneous signals like
3586@code{SIGALRM} be silently passed to your program
3587(so as not to interfere with their role in the program's functioning)
c906108c
SS
3588but to stop your program immediately whenever an error signal happens.
3589You can change these settings with the @code{handle} command.
3590
3591@table @code
3592@kindex info signals
3593@item info signals
96a2c332 3594@itemx info handle
c906108c
SS
3595Print a table of all the kinds of signals and how @value{GDBN} has been told to
3596handle each one. You can use this to see the signal numbers of all
3597the defined types of signals.
3598
d4f3574e 3599@code{info handle} is an alias for @code{info signals}.
c906108c
SS
3600
3601@kindex handle
3602@item handle @var{signal} @var{keywords}@dots{}
5ece1a18
EZ
3603Change the way @value{GDBN} handles signal @var{signal}. @var{signal}
3604can be the number of a signal or its name (with or without the
24f93129 3605@samp{SIG} at the beginning); a list of signal numbers of the form
5ece1a18
EZ
3606@samp{@var{low}-@var{high}}; or the word @samp{all}, meaning all the
3607known signals. The @var{keywords} say what change to make.
c906108c
SS
3608@end table
3609
3610@c @group
3611The keywords allowed by the @code{handle} command can be abbreviated.
3612Their full names are:
3613
3614@table @code
3615@item nostop
3616@value{GDBN} should not stop your program when this signal happens. It may
3617still print a message telling you that the signal has come in.
3618
3619@item stop
3620@value{GDBN} should stop your program when this signal happens. This implies
3621the @code{print} keyword as well.
3622
3623@item print
3624@value{GDBN} should print a message when this signal happens.
3625
3626@item noprint
3627@value{GDBN} should not mention the occurrence of the signal at all. This
3628implies the @code{nostop} keyword as well.
3629
3630@item pass
5ece1a18 3631@itemx noignore
c906108c
SS
3632@value{GDBN} should allow your program to see this signal; your program
3633can handle the signal, or else it may terminate if the signal is fatal
5ece1a18 3634and not handled. @code{pass} and @code{noignore} are synonyms.
c906108c
SS
3635
3636@item nopass
5ece1a18 3637@itemx ignore
c906108c 3638@value{GDBN} should not allow your program to see this signal.
5ece1a18 3639@code{nopass} and @code{ignore} are synonyms.
c906108c
SS
3640@end table
3641@c @end group
3642
d4f3574e
SS
3643When a signal stops your program, the signal is not visible to the
3644program until you
c906108c
SS
3645continue. Your program sees the signal then, if @code{pass} is in
3646effect for the signal in question @emph{at that time}. In other words,
3647after @value{GDBN} reports a signal, you can use the @code{handle}
3648command with @code{pass} or @code{nopass} to control whether your
3649program sees that signal when you continue.
3650
24f93129
EZ
3651The default is set to @code{nostop}, @code{noprint}, @code{pass} for
3652non-erroneous signals such as @code{SIGALRM}, @code{SIGWINCH} and
3653@code{SIGCHLD}, and to @code{stop}, @code{print}, @code{pass} for the
3654erroneous signals.
3655
c906108c
SS
3656You can also use the @code{signal} command to prevent your program from
3657seeing a signal, or cause it to see a signal it normally would not see,
3658or to give it any signal at any time. For example, if your program stopped
3659due to some sort of memory reference error, you might store correct
3660values into the erroneous variables and continue, hoping to see more
3661execution; but your program would probably terminate immediately as
3662a result of the fatal signal once it saw the signal. To prevent this,
3663you can continue with @samp{signal 0}. @xref{Signaling, ,Giving your
5d161b24 3664program a signal}.
c906108c 3665
6d2ebf8b 3666@node Thread Stops
c906108c
SS
3667@section Stopping and starting multi-thread programs
3668
3669When your program has multiple threads (@pxref{Threads,, Debugging
3670programs with multiple threads}), you can choose whether to set
3671breakpoints on all threads, or on a particular thread.
3672
3673@table @code
3674@cindex breakpoints and threads
3675@cindex thread breakpoints
3676@kindex break @dots{} thread @var{threadno}
3677@item break @var{linespec} thread @var{threadno}
3678@itemx break @var{linespec} thread @var{threadno} if @dots{}
3679@var{linespec} specifies source lines; there are several ways of
3680writing them, but the effect is always to specify some source line.
3681
3682Use the qualifier @samp{thread @var{threadno}} with a breakpoint command
3683to specify that you only want @value{GDBN} to stop the program when a
3684particular thread reaches this breakpoint. @var{threadno} is one of the
3685numeric thread identifiers assigned by @value{GDBN}, shown in the first
3686column of the @samp{info threads} display.
3687
3688If you do not specify @samp{thread @var{threadno}} when you set a
3689breakpoint, the breakpoint applies to @emph{all} threads of your
3690program.
3691
3692You can use the @code{thread} qualifier on conditional breakpoints as
3693well; in this case, place @samp{thread @var{threadno}} before the
3694breakpoint condition, like this:
3695
3696@smallexample
2df3850c 3697(@value{GDBP}) break frik.c:13 thread 28 if bartab > lim
c906108c
SS
3698@end smallexample
3699
3700@end table
3701
3702@cindex stopped threads
3703@cindex threads, stopped
3704Whenever your program stops under @value{GDBN} for any reason,
3705@emph{all} threads of execution stop, not just the current thread. This
3706allows you to examine the overall state of the program, including
3707switching between threads, without worrying that things may change
3708underfoot.
3709
3710@cindex continuing threads
3711@cindex threads, continuing
3712Conversely, whenever you restart the program, @emph{all} threads start
3713executing. @emph{This is true even when single-stepping} with commands
5d161b24 3714like @code{step} or @code{next}.
c906108c
SS
3715
3716In particular, @value{GDBN} cannot single-step all threads in lockstep.
3717Since thread scheduling is up to your debugging target's operating
3718system (not controlled by @value{GDBN}), other threads may
3719execute more than one statement while the current thread completes a
3720single step. Moreover, in general other threads stop in the middle of a
3721statement, rather than at a clean statement boundary, when the program
3722stops.
3723
3724You might even find your program stopped in another thread after
3725continuing or even single-stepping. This happens whenever some other
3726thread runs into a breakpoint, a signal, or an exception before the
3727first thread completes whatever you requested.
3728
3729On some OSes, you can lock the OS scheduler and thus allow only a single
3730thread to run.
3731
3732@table @code
3733@item set scheduler-locking @var{mode}
3734Set the scheduler locking mode. If it is @code{off}, then there is no
3735locking and any thread may run at any time. If @code{on}, then only the
3736current thread may run when the inferior is resumed. The @code{step}
3737mode optimizes for single-stepping. It stops other threads from
3738``seizing the prompt'' by preempting the current thread while you are
3739stepping. Other threads will only rarely (or never) get a chance to run
d4f3574e 3740when you step. They are more likely to run when you @samp{next} over a
c906108c 3741function call, and they are completely free to run when you use commands
d4f3574e 3742like @samp{continue}, @samp{until}, or @samp{finish}. However, unless another
c906108c 3743thread hits a breakpoint during its timeslice, they will never steal the
2df3850c 3744@value{GDBN} prompt away from the thread that you are debugging.
c906108c
SS
3745
3746@item show scheduler-locking
3747Display the current scheduler locking mode.
3748@end table
3749
c906108c 3750
6d2ebf8b 3751@node Stack
c906108c
SS
3752@chapter Examining the Stack
3753
3754When your program has stopped, the first thing you need to know is where it
3755stopped and how it got there.
3756
3757@cindex call stack
5d161b24
DB
3758Each time your program performs a function call, information about the call
3759is generated.
3760That information includes the location of the call in your program,
3761the arguments of the call,
c906108c 3762and the local variables of the function being called.
5d161b24 3763The information is saved in a block of data called a @dfn{stack frame}.
c906108c
SS
3764The stack frames are allocated in a region of memory called the @dfn{call
3765stack}.
3766
3767When your program stops, the @value{GDBN} commands for examining the
3768stack allow you to see all of this information.
3769
3770@cindex selected frame
3771One of the stack frames is @dfn{selected} by @value{GDBN} and many
3772@value{GDBN} commands refer implicitly to the selected frame. In
3773particular, whenever you ask @value{GDBN} for the value of a variable in
3774your program, the value is found in the selected frame. There are
3775special @value{GDBN} commands to select whichever frame you are
3776interested in. @xref{Selection, ,Selecting a frame}.
3777
3778When your program stops, @value{GDBN} automatically selects the
5d161b24 3779currently executing frame and describes it briefly, similar to the
c906108c
SS
3780@code{frame} command (@pxref{Frame Info, ,Information about a frame}).
3781
3782@menu
3783* Frames:: Stack frames
3784* Backtrace:: Backtraces
3785* Selection:: Selecting a frame
3786* Frame Info:: Information on a frame
c906108c
SS
3787
3788@end menu
3789
6d2ebf8b 3790@node Frames
c906108c
SS
3791@section Stack frames
3792
d4f3574e 3793@cindex frame, definition
c906108c
SS
3794@cindex stack frame
3795The call stack is divided up into contiguous pieces called @dfn{stack
3796frames}, or @dfn{frames} for short; each frame is the data associated
3797with one call to one function. The frame contains the arguments given
3798to the function, the function's local variables, and the address at
3799which the function is executing.
3800
3801@cindex initial frame
3802@cindex outermost frame
3803@cindex innermost frame
3804When your program is started, the stack has only one frame, that of the
3805function @code{main}. This is called the @dfn{initial} frame or the
3806@dfn{outermost} frame. Each time a function is called, a new frame is
3807made. Each time a function returns, the frame for that function invocation
3808is eliminated. If a function is recursive, there can be many frames for
3809the same function. The frame for the function in which execution is
3810actually occurring is called the @dfn{innermost} frame. This is the most
3811recently created of all the stack frames that still exist.
3812
3813@cindex frame pointer
3814Inside your program, stack frames are identified by their addresses. A
3815stack frame consists of many bytes, each of which has its own address; each
3816kind of computer has a convention for choosing one byte whose
3817address serves as the address of the frame. Usually this address is kept
3818in a register called the @dfn{frame pointer register} while execution is
3819going on in that frame.
3820
3821@cindex frame number
3822@value{GDBN} assigns numbers to all existing stack frames, starting with
3823zero for the innermost frame, one for the frame that called it,
3824and so on upward. These numbers do not really exist in your program;
3825they are assigned by @value{GDBN} to give you a way of designating stack
3826frames in @value{GDBN} commands.
3827
6d2ebf8b
SS
3828@c The -fomit-frame-pointer below perennially causes hbox overflow
3829@c underflow problems.
c906108c
SS
3830@cindex frameless execution
3831Some compilers provide a way to compile functions so that they operate
6d2ebf8b 3832without stack frames. (For example, the @value{GCC} option
474c8240 3833@smallexample
6d2ebf8b 3834@samp{-fomit-frame-pointer}
474c8240 3835@end smallexample
6d2ebf8b 3836generates functions without a frame.)
c906108c
SS
3837This is occasionally done with heavily used library functions to save
3838the frame setup time. @value{GDBN} has limited facilities for dealing
3839with these function invocations. If the innermost function invocation
3840has no stack frame, @value{GDBN} nevertheless regards it as though
3841it had a separate frame, which is numbered zero as usual, allowing
3842correct tracing of the function call chain. However, @value{GDBN} has
3843no provision for frameless functions elsewhere in the stack.
3844
3845@table @code
d4f3574e 3846@kindex frame@r{, command}
41afff9a 3847@cindex current stack frame
c906108c 3848@item frame @var{args}
5d161b24 3849The @code{frame} command allows you to move from one stack frame to another,
c906108c 3850and to print the stack frame you select. @var{args} may be either the
5d161b24
DB
3851address of the frame or the stack frame number. Without an argument,
3852@code{frame} prints the current stack frame.
c906108c
SS
3853
3854@kindex select-frame
41afff9a 3855@cindex selecting frame silently
c906108c
SS
3856@item select-frame
3857The @code{select-frame} command allows you to move from one stack frame
3858to another without printing the frame. This is the silent version of
3859@code{frame}.
3860@end table
3861
6d2ebf8b 3862@node Backtrace
c906108c
SS
3863@section Backtraces
3864
3865@cindex backtraces
3866@cindex tracebacks
3867@cindex stack traces
3868A backtrace is a summary of how your program got where it is. It shows one
3869line per frame, for many frames, starting with the currently executing
3870frame (frame zero), followed by its caller (frame one), and on up the
3871stack.
3872
3873@table @code
3874@kindex backtrace
41afff9a 3875@kindex bt @r{(@code{backtrace})}
c906108c
SS
3876@item backtrace
3877@itemx bt
3878Print a backtrace of the entire stack: one line per frame for all
3879frames in the stack.
3880
3881You can stop the backtrace at any time by typing the system interrupt
3882character, normally @kbd{C-c}.
3883
3884@item backtrace @var{n}
3885@itemx bt @var{n}
3886Similar, but print only the innermost @var{n} frames.
3887
3888@item backtrace -@var{n}
3889@itemx bt -@var{n}
3890Similar, but print only the outermost @var{n} frames.
3891@end table
3892
3893@kindex where
3894@kindex info stack
41afff9a 3895@kindex info s @r{(@code{info stack})}
c906108c
SS
3896The names @code{where} and @code{info stack} (abbreviated @code{info s})
3897are additional aliases for @code{backtrace}.
3898
3899Each line in the backtrace shows the frame number and the function name.
3900The program counter value is also shown---unless you use @code{set
3901print address off}. The backtrace also shows the source file name and
3902line number, as well as the arguments to the function. The program
3903counter value is omitted if it is at the beginning of the code for that
3904line number.
3905
3906Here is an example of a backtrace. It was made with the command
3907@samp{bt 3}, so it shows the innermost three frames.
3908
3909@smallexample
3910@group
5d161b24 3911#0 m4_traceon (obs=0x24eb0, argc=1, argv=0x2b8c8)
c906108c
SS
3912 at builtin.c:993
3913#1 0x6e38 in expand_macro (sym=0x2b600) at macro.c:242
3914#2 0x6840 in expand_token (obs=0x0, t=177664, td=0xf7fffb08)
3915 at macro.c:71
3916(More stack frames follow...)
3917@end group
3918@end smallexample
3919
3920@noindent
3921The display for frame zero does not begin with a program counter
3922value, indicating that your program has stopped at the beginning of the
3923code for line @code{993} of @code{builtin.c}.
3924
b4e9345d
DJ
3925@kindex set backtrace-below-main
3926@kindex show backtrace-below-main
3927
95f90d25
DJ
3928Most programs have a standard entry point---a place where system libraries
3929and startup code transition into user code. For C this is @code{main}.
3930When @value{GDBN} finds the entry function in a backtrace it will terminate
3931the backtrace, to avoid tracing into highly system-specific (and generally
3932uninteresting) code. If you need to examine the startup code, then you can
3933change this behavior.
3934
3935@table @code
3936@item set backtrace-below-main off
3937Backtraces will stop when they encounter the user entry point. This is the
3938default.
3939
3940@item set backtrace-below-main
3941@itemx set backtrace-below-main on
3942Backtraces will continue past the user entry point to the top of the stack.
3943
3944@item show backtrace-below-main
3945Display the current backtrace policy.
3946@end table
3947
6d2ebf8b 3948@node Selection
c906108c
SS
3949@section Selecting a frame
3950
3951Most commands for examining the stack and other data in your program work on
3952whichever stack frame is selected at the moment. Here are the commands for
3953selecting a stack frame; all of them finish by printing a brief description
3954of the stack frame just selected.
3955
3956@table @code
d4f3574e 3957@kindex frame@r{, selecting}
41afff9a 3958@kindex f @r{(@code{frame})}
c906108c
SS
3959@item frame @var{n}
3960@itemx f @var{n}
3961Select frame number @var{n}. Recall that frame zero is the innermost
3962(currently executing) frame, frame one is the frame that called the
3963innermost one, and so on. The highest-numbered frame is the one for
3964@code{main}.
3965
3966@item frame @var{addr}
3967@itemx f @var{addr}
3968Select the frame at address @var{addr}. This is useful mainly if the
3969chaining of stack frames has been damaged by a bug, making it
3970impossible for @value{GDBN} to assign numbers properly to all frames. In
3971addition, this can be useful when your program has multiple stacks and
3972switches between them.
3973
c906108c
SS
3974On the SPARC architecture, @code{frame} needs two addresses to
3975select an arbitrary frame: a frame pointer and a stack pointer.
3976
3977On the MIPS and Alpha architecture, it needs two addresses: a stack
3978pointer and a program counter.
3979
3980On the 29k architecture, it needs three addresses: a register stack
3981pointer, a program counter, and a memory stack pointer.
3982@c note to future updaters: this is conditioned on a flag
3983@c SETUP_ARBITRARY_FRAME in the tm-*.h files. The above is up to date
3984@c as of 27 Jan 1994.
c906108c
SS
3985
3986@kindex up
3987@item up @var{n}
3988Move @var{n} frames up the stack. For positive numbers @var{n}, this
3989advances toward the outermost frame, to higher frame numbers, to frames
3990that have existed longer. @var{n} defaults to one.
3991
3992@kindex down
41afff9a 3993@kindex do @r{(@code{down})}
c906108c
SS
3994@item down @var{n}
3995Move @var{n} frames down the stack. For positive numbers @var{n}, this
3996advances toward the innermost frame, to lower frame numbers, to frames
3997that were created more recently. @var{n} defaults to one. You may
3998abbreviate @code{down} as @code{do}.
3999@end table
4000
4001All of these commands end by printing two lines of output describing the
4002frame. The first line shows the frame number, the function name, the
4003arguments, and the source file and line number of execution in that
5d161b24 4004frame. The second line shows the text of that source line.
c906108c
SS
4005
4006@need 1000
4007For example:
4008
4009@smallexample
4010@group
4011(@value{GDBP}) up
4012#1 0x22f0 in main (argc=1, argv=0xf7fffbf4, env=0xf7fffbfc)
4013 at env.c:10
401410 read_input_file (argv[i]);
4015@end group
4016@end smallexample
4017
4018After such a printout, the @code{list} command with no arguments
4019prints ten lines centered on the point of execution in the frame.
87885426
FN
4020You can also edit the program at the point of execution with your favorite
4021editing program by typing @code{edit}.
4022@xref{List, ,Printing source lines},
4023for details.
c906108c
SS
4024
4025@table @code
4026@kindex down-silently
4027@kindex up-silently
4028@item up-silently @var{n}
4029@itemx down-silently @var{n}
4030These two commands are variants of @code{up} and @code{down},
4031respectively; they differ in that they do their work silently, without
4032causing display of the new frame. They are intended primarily for use
4033in @value{GDBN} command scripts, where the output might be unnecessary and
4034distracting.
4035@end table
4036
6d2ebf8b 4037@node Frame Info
c906108c
SS
4038@section Information about a frame
4039
4040There are several other commands to print information about the selected
4041stack frame.
4042
4043@table @code
4044@item frame
4045@itemx f
4046When used without any argument, this command does not change which
4047frame is selected, but prints a brief description of the currently
4048selected stack frame. It can be abbreviated @code{f}. With an
4049argument, this command is used to select a stack frame.
4050@xref{Selection, ,Selecting a frame}.
4051
4052@kindex info frame
41afff9a 4053@kindex info f @r{(@code{info frame})}
c906108c
SS
4054@item info frame
4055@itemx info f
4056This command prints a verbose description of the selected stack frame,
4057including:
4058
4059@itemize @bullet
5d161b24
DB
4060@item
4061the address of the frame
c906108c
SS
4062@item
4063the address of the next frame down (called by this frame)
4064@item
4065the address of the next frame up (caller of this frame)
4066@item
4067the language in which the source code corresponding to this frame is written
4068@item
4069the address of the frame's arguments
4070@item
d4f3574e
SS
4071the address of the frame's local variables
4072@item
c906108c
SS
4073the program counter saved in it (the address of execution in the caller frame)
4074@item
4075which registers were saved in the frame
4076@end itemize
4077
4078@noindent The verbose description is useful when
4079something has gone wrong that has made the stack format fail to fit
4080the usual conventions.
4081
4082@item info frame @var{addr}
4083@itemx info f @var{addr}
4084Print a verbose description of the frame at address @var{addr}, without
4085selecting that frame. The selected frame remains unchanged by this
4086command. This requires the same kind of address (more than one for some
4087architectures) that you specify in the @code{frame} command.
4088@xref{Selection, ,Selecting a frame}.
4089
4090@kindex info args
4091@item info args
4092Print the arguments of the selected frame, each on a separate line.
4093
4094@item info locals
4095@kindex info locals
4096Print the local variables of the selected frame, each on a separate
4097line. These are all variables (declared either static or automatic)
4098accessible at the point of execution of the selected frame.
4099
c906108c 4100@kindex info catch
d4f3574e
SS
4101@cindex catch exceptions, list active handlers
4102@cindex exception handlers, how to list
c906108c
SS
4103@item info catch
4104Print a list of all the exception handlers that are active in the
4105current stack frame at the current point of execution. To see other
4106exception handlers, visit the associated frame (using the @code{up},
4107@code{down}, or @code{frame} commands); then type @code{info catch}.
4108@xref{Set Catchpoints, , Setting catchpoints}.
53a5351d 4109
c906108c
SS
4110@end table
4111
c906108c 4112
6d2ebf8b 4113@node Source
c906108c
SS
4114@chapter Examining Source Files
4115
4116@value{GDBN} can print parts of your program's source, since the debugging
4117information recorded in the program tells @value{GDBN} what source files were
4118used to build it. When your program stops, @value{GDBN} spontaneously prints
4119the line where it stopped. Likewise, when you select a stack frame
4120(@pxref{Selection, ,Selecting a frame}), @value{GDBN} prints the line where
4121execution in that frame has stopped. You can print other portions of
4122source files by explicit command.
4123
7a292a7a 4124If you use @value{GDBN} through its @sc{gnu} Emacs interface, you may
d4f3574e 4125prefer to use Emacs facilities to view source; see @ref{Emacs, ,Using
7a292a7a 4126@value{GDBN} under @sc{gnu} Emacs}.
c906108c
SS
4127
4128@menu
4129* List:: Printing source lines
87885426 4130* Edit:: Editing source files
c906108c 4131* Search:: Searching source files
c906108c
SS
4132* Source Path:: Specifying source directories
4133* Machine Code:: Source and machine code
4134@end menu
4135
6d2ebf8b 4136@node List
c906108c
SS
4137@section Printing source lines
4138
4139@kindex list
41afff9a 4140@kindex l @r{(@code{list})}
c906108c 4141To print lines from a source file, use the @code{list} command
5d161b24 4142(abbreviated @code{l}). By default, ten lines are printed.
c906108c
SS
4143There are several ways to specify what part of the file you want to print.
4144
4145Here are the forms of the @code{list} command most commonly used:
4146
4147@table @code
4148@item list @var{linenum}
4149Print lines centered around line number @var{linenum} in the
4150current source file.
4151
4152@item list @var{function}
4153Print lines centered around the beginning of function
4154@var{function}.
4155
4156@item list
4157Print more lines. If the last lines printed were printed with a
4158@code{list} command, this prints lines following the last lines
4159printed; however, if the last line printed was a solitary line printed
4160as part of displaying a stack frame (@pxref{Stack, ,Examining the
4161Stack}), this prints lines centered around that line.
4162
4163@item list -
4164Print lines just before the lines last printed.
4165@end table
4166
4167By default, @value{GDBN} prints ten source lines with any of these forms of
4168the @code{list} command. You can change this using @code{set listsize}:
4169
4170@table @code
4171@kindex set listsize
4172@item set listsize @var{count}
4173Make the @code{list} command display @var{count} source lines (unless
4174the @code{list} argument explicitly specifies some other number).
4175
4176@kindex show listsize
4177@item show listsize
4178Display the number of lines that @code{list} prints.
4179@end table
4180
4181Repeating a @code{list} command with @key{RET} discards the argument,
4182so it is equivalent to typing just @code{list}. This is more useful
4183than listing the same lines again. An exception is made for an
4184argument of @samp{-}; that argument is preserved in repetition so that
4185each repetition moves up in the source file.
4186
4187@cindex linespec
4188In general, the @code{list} command expects you to supply zero, one or two
4189@dfn{linespecs}. Linespecs specify source lines; there are several ways
d4f3574e 4190of writing them, but the effect is always to specify some source line.
c906108c
SS
4191Here is a complete description of the possible arguments for @code{list}:
4192
4193@table @code
4194@item list @var{linespec}
4195Print lines centered around the line specified by @var{linespec}.
4196
4197@item list @var{first},@var{last}
4198Print lines from @var{first} to @var{last}. Both arguments are
4199linespecs.
4200
4201@item list ,@var{last}
4202Print lines ending with @var{last}.
4203
4204@item list @var{first},
4205Print lines starting with @var{first}.
4206
4207@item list +
4208Print lines just after the lines last printed.
4209
4210@item list -
4211Print lines just before the lines last printed.
4212
4213@item list
4214As described in the preceding table.
4215@end table
4216
4217Here are the ways of specifying a single source line---all the
4218kinds of linespec.
4219
4220@table @code
4221@item @var{number}
4222Specifies line @var{number} of the current source file.
4223When a @code{list} command has two linespecs, this refers to
4224the same source file as the first linespec.
4225
4226@item +@var{offset}
4227Specifies the line @var{offset} lines after the last line printed.
4228When used as the second linespec in a @code{list} command that has
4229two, this specifies the line @var{offset} lines down from the
4230first linespec.
4231
4232@item -@var{offset}
4233Specifies the line @var{offset} lines before the last line printed.
4234
4235@item @var{filename}:@var{number}
4236Specifies line @var{number} in the source file @var{filename}.
4237
4238@item @var{function}
4239Specifies the line that begins the body of the function @var{function}.
4240For example: in C, this is the line with the open brace.
4241
4242@item @var{filename}:@var{function}
4243Specifies the line of the open-brace that begins the body of the
4244function @var{function} in the file @var{filename}. You only need the
4245file name with a function name to avoid ambiguity when there are
4246identically named functions in different source files.
4247
4248@item *@var{address}
4249Specifies the line containing the program address @var{address}.
4250@var{address} may be any expression.
4251@end table
4252
87885426
FN
4253@node Edit
4254@section Editing source files
4255@cindex editing source files
4256
4257@kindex edit
4258@kindex e @r{(@code{edit})}
4259To edit the lines in a source file, use the @code{edit} command.
4260The editing program of your choice
4261is invoked with the current line set to
4262the active line in the program.
4263Alternatively, there are several ways to specify what part of the file you
4264want to print if you want to see other parts of the program.
4265
4266Here are the forms of the @code{edit} command most commonly used:
4267
4268@table @code
4269@item edit
4270Edit the current source file at the active line number in the program.
4271
4272@item edit @var{number}
4273Edit the current source file with @var{number} as the active line number.
4274
4275@item edit @var{function}
4276Edit the file containing @var{function} at the beginning of its definition.
4277
4278@item edit @var{filename}:@var{number}
4279Specifies line @var{number} in the source file @var{filename}.
4280
4281@item edit @var{filename}:@var{function}
4282Specifies the line that begins the body of the
4283function @var{function} in the file @var{filename}. You only need the
4284file name with a function name to avoid ambiguity when there are
4285identically named functions in different source files.
4286
4287@item edit *@var{address}
4288Specifies the line containing the program address @var{address}.
4289@var{address} may be any expression.
4290@end table
4291
4292@subsection Choosing your editor
4293You can customize @value{GDBN} to use any editor you want
4294@footnote{
4295The only restriction is that your editor (say @code{ex}), recognizes the
4296following command-line syntax:
10998722 4297@smallexample
87885426 4298ex +@var{number} file
10998722
AC
4299@end smallexample
4300The optional numeric value +@var{number} designates the active line in
4301the file.}. By default, it is @value{EDITOR}, but you can change this
4302by setting the environment variable @code{EDITOR} before using
4303@value{GDBN}. For example, to configure @value{GDBN} to use the
4304@code{vi} editor, you could use these commands with the @code{sh} shell:
4305@smallexample
87885426
FN
4306EDITOR=/usr/bin/vi
4307export EDITOR
4308gdb ...
10998722 4309@end smallexample
87885426 4310or in the @code{csh} shell,
10998722 4311@smallexample
87885426
FN
4312setenv EDITOR /usr/bin/vi
4313gdb ...
10998722 4314@end smallexample
87885426 4315
6d2ebf8b 4316@node Search
c906108c
SS
4317@section Searching source files
4318@cindex searching
4319@kindex reverse-search
4320
4321There are two commands for searching through the current source file for a
4322regular expression.
4323
4324@table @code
4325@kindex search
4326@kindex forward-search
4327@item forward-search @var{regexp}
4328@itemx search @var{regexp}
4329The command @samp{forward-search @var{regexp}} checks each line,
4330starting with the one following the last line listed, for a match for
5d161b24 4331@var{regexp}. It lists the line that is found. You can use the
c906108c
SS
4332synonym @samp{search @var{regexp}} or abbreviate the command name as
4333@code{fo}.
4334
4335@item reverse-search @var{regexp}
4336The command @samp{reverse-search @var{regexp}} checks each line, starting
4337with the one before the last line listed and going backward, for a match
4338for @var{regexp}. It lists the line that is found. You can abbreviate
4339this command as @code{rev}.
4340@end table
c906108c 4341
6d2ebf8b 4342@node Source Path
c906108c
SS
4343@section Specifying source directories
4344
4345@cindex source path
4346@cindex directories for source files
4347Executable programs sometimes do not record the directories of the source
4348files from which they were compiled, just the names. Even when they do,
4349the directories could be moved between the compilation and your debugging
4350session. @value{GDBN} has a list of directories to search for source files;
4351this is called the @dfn{source path}. Each time @value{GDBN} wants a source file,
4352it tries all the directories in the list, in the order they are present
4353in the list, until it finds a file with the desired name. Note that
4354the executable search path is @emph{not} used for this purpose. Neither is
4355the current working directory, unless it happens to be in the source
4356path.
4357
4358If @value{GDBN} cannot find a source file in the source path, and the
4359object program records a directory, @value{GDBN} tries that directory
4360too. If the source path is empty, and there is no record of the
4361compilation directory, @value{GDBN} looks in the current directory as a
4362last resort.
4363
4364Whenever you reset or rearrange the source path, @value{GDBN} clears out
4365any information it has cached about where source files are found and where
4366each line is in the file.
4367
4368@kindex directory
4369@kindex dir
d4f3574e
SS
4370When you start @value{GDBN}, its source path includes only @samp{cdir}
4371and @samp{cwd}, in that order.
c906108c
SS
4372To add other directories, use the @code{directory} command.
4373
4374@table @code
4375@item directory @var{dirname} @dots{}
4376@item dir @var{dirname} @dots{}
4377Add directory @var{dirname} to the front of the source path. Several
d4f3574e
SS
4378directory names may be given to this command, separated by @samp{:}
4379(@samp{;} on MS-DOS and MS-Windows, where @samp{:} usually appears as
4380part of absolute file names) or
c906108c
SS
4381whitespace. You may specify a directory that is already in the source
4382path; this moves it forward, so @value{GDBN} searches it sooner.
4383
4384@kindex cdir
4385@kindex cwd
41afff9a
EZ
4386@vindex $cdir@r{, convenience variable}
4387@vindex $cwdr@r{, convenience variable}
c906108c
SS
4388@cindex compilation directory
4389@cindex current directory
4390@cindex working directory
4391@cindex directory, current
4392@cindex directory, compilation
4393You can use the string @samp{$cdir} to refer to the compilation
4394directory (if one is recorded), and @samp{$cwd} to refer to the current
4395working directory. @samp{$cwd} is not the same as @samp{.}---the former
4396tracks the current working directory as it changes during your @value{GDBN}
4397session, while the latter is immediately expanded to the current
4398directory at the time you add an entry to the source path.
4399
4400@item directory
4401Reset the source path to empty again. This requires confirmation.
4402
4403@c RET-repeat for @code{directory} is explicitly disabled, but since
4404@c repeating it would be a no-op we do not say that. (thanks to RMS)
4405
4406@item show directories
4407@kindex show directories
4408Print the source path: show which directories it contains.
4409@end table
4410
4411If your source path is cluttered with directories that are no longer of
4412interest, @value{GDBN} may sometimes cause confusion by finding the wrong
4413versions of source. You can correct the situation as follows:
4414
4415@enumerate
4416@item
4417Use @code{directory} with no argument to reset the source path to empty.
4418
4419@item
4420Use @code{directory} with suitable arguments to reinstall the
4421directories you want in the source path. You can add all the
4422directories in one command.
4423@end enumerate
4424
6d2ebf8b 4425@node Machine Code
c906108c
SS
4426@section Source and machine code
4427
4428You can use the command @code{info line} to map source lines to program
4429addresses (and vice versa), and the command @code{disassemble} to display
4430a range of addresses as machine instructions. When run under @sc{gnu} Emacs
d4f3574e 4431mode, the @code{info line} command causes the arrow to point to the
5d161b24 4432line specified. Also, @code{info line} prints addresses in symbolic form as
c906108c
SS
4433well as hex.
4434
4435@table @code
4436@kindex info line
4437@item info line @var{linespec}
4438Print the starting and ending addresses of the compiled code for
4439source line @var{linespec}. You can specify source lines in any of
4440the ways understood by the @code{list} command (@pxref{List, ,Printing
4441source lines}).
4442@end table
4443
4444For example, we can use @code{info line} to discover the location of
4445the object code for the first line of function
4446@code{m4_changequote}:
4447
d4f3574e
SS
4448@c FIXME: I think this example should also show the addresses in
4449@c symbolic form, as they usually would be displayed.
c906108c 4450@smallexample
96a2c332 4451(@value{GDBP}) info line m4_changequote
c906108c
SS
4452Line 895 of "builtin.c" starts at pc 0x634c and ends at 0x6350.
4453@end smallexample
4454
4455@noindent
4456We can also inquire (using @code{*@var{addr}} as the form for
4457@var{linespec}) what source line covers a particular address:
4458@smallexample
4459(@value{GDBP}) info line *0x63ff
4460Line 926 of "builtin.c" starts at pc 0x63e4 and ends at 0x6404.
4461@end smallexample
4462
4463@cindex @code{$_} and @code{info line}
41afff9a 4464@kindex x@r{(examine), and} info line
c906108c
SS
4465After @code{info line}, the default address for the @code{x} command
4466is changed to the starting address of the line, so that @samp{x/i} is
4467sufficient to begin examining the machine code (@pxref{Memory,
4468,Examining memory}). Also, this address is saved as the value of the
4469convenience variable @code{$_} (@pxref{Convenience Vars, ,Convenience
4470variables}).
4471
4472@table @code
4473@kindex disassemble
4474@cindex assembly instructions
4475@cindex instructions, assembly
4476@cindex machine instructions
4477@cindex listing machine instructions
4478@item disassemble
4479This specialized command dumps a range of memory as machine
4480instructions. The default memory range is the function surrounding the
4481program counter of the selected frame. A single argument to this
4482command is a program counter value; @value{GDBN} dumps the function
4483surrounding this value. Two arguments specify a range of addresses
4484(first inclusive, second exclusive) to dump.
4485@end table
4486
c906108c
SS
4487The following example shows the disassembly of a range of addresses of
4488HP PA-RISC 2.0 code:
4489
4490@smallexample
4491(@value{GDBP}) disas 0x32c4 0x32e4
4492Dump of assembler code from 0x32c4 to 0x32e4:
44930x32c4 <main+204>: addil 0,dp
44940x32c8 <main+208>: ldw 0x22c(sr0,r1),r26
44950x32cc <main+212>: ldil 0x3000,r31
44960x32d0 <main+216>: ble 0x3f8(sr4,r31)
44970x32d4 <main+220>: ldo 0(r31),rp
44980x32d8 <main+224>: addil -0x800,dp
44990x32dc <main+228>: ldo 0x588(r1),r26
45000x32e0 <main+232>: ldil 0x3000,r31
4501End of assembler dump.
4502@end smallexample
c906108c
SS
4503
4504Some architectures have more than one commonly-used set of instruction
4505mnemonics or other syntax.
4506
4507@table @code
d4f3574e 4508@kindex set disassembly-flavor
c906108c
SS
4509@cindex assembly instructions
4510@cindex instructions, assembly
4511@cindex machine instructions
4512@cindex listing machine instructions
d4f3574e
SS
4513@cindex Intel disassembly flavor
4514@cindex AT&T disassembly flavor
4515@item set disassembly-flavor @var{instruction-set}
c906108c
SS
4516Select the instruction set to use when disassembling the
4517program via the @code{disassemble} or @code{x/i} commands.
4518
4519Currently this command is only defined for the Intel x86 family. You
d4f3574e
SS
4520can set @var{instruction-set} to either @code{intel} or @code{att}.
4521The default is @code{att}, the AT&T flavor used by default by Unix
4522assemblers for x86-based targets.
c906108c
SS
4523@end table
4524
4525
6d2ebf8b 4526@node Data
c906108c
SS
4527@chapter Examining Data
4528
4529@cindex printing data
4530@cindex examining data
4531@kindex print
4532@kindex inspect
4533@c "inspect" is not quite a synonym if you are using Epoch, which we do not
4534@c document because it is nonstandard... Under Epoch it displays in a
4535@c different window or something like that.
4536The usual way to examine data in your program is with the @code{print}
7a292a7a
SS
4537command (abbreviated @code{p}), or its synonym @code{inspect}. It
4538evaluates and prints the value of an expression of the language your
4539program is written in (@pxref{Languages, ,Using @value{GDBN} with
4540Different Languages}).
c906108c
SS
4541
4542@table @code
d4f3574e
SS
4543@item print @var{expr}
4544@itemx print /@var{f} @var{expr}
4545@var{expr} is an expression (in the source language). By default the
4546value of @var{expr} is printed in a format appropriate to its data type;
c906108c 4547you can choose a different format by specifying @samp{/@var{f}}, where
d4f3574e 4548@var{f} is a letter specifying the format; see @ref{Output Formats,,Output
c906108c
SS
4549formats}.
4550
4551@item print
4552@itemx print /@var{f}
d4f3574e 4553If you omit @var{expr}, @value{GDBN} displays the last value again (from the
c906108c
SS
4554@dfn{value history}; @pxref{Value History, ,Value history}). This allows you to
4555conveniently inspect the same value in an alternative format.
4556@end table
4557
4558A more low-level way of examining data is with the @code{x} command.
4559It examines data in memory at a specified address and prints it in a
4560specified format. @xref{Memory, ,Examining memory}.
4561
7a292a7a 4562If you are interested in information about types, or about how the
d4f3574e
SS
4563fields of a struct or a class are declared, use the @code{ptype @var{exp}}
4564command rather than @code{print}. @xref{Symbols, ,Examining the Symbol
7a292a7a 4565Table}.
c906108c
SS
4566
4567@menu
4568* Expressions:: Expressions
4569* Variables:: Program variables
4570* Arrays:: Artificial arrays
4571* Output Formats:: Output formats
4572* Memory:: Examining memory
4573* Auto Display:: Automatic display
4574* Print Settings:: Print settings
4575* Value History:: Value history
4576* Convenience Vars:: Convenience variables
4577* Registers:: Registers
c906108c 4578* Floating Point Hardware:: Floating point hardware
53c69bd7 4579* Vector Unit:: Vector Unit
29e57380 4580* Memory Region Attributes:: Memory region attributes
16d9dec6 4581* Dump/Restore Files:: Copy between memory and a file
a0eb71c5
KB
4582* Character Sets:: Debugging programs that use a different
4583 character set than GDB does
c906108c
SS
4584@end menu
4585
6d2ebf8b 4586@node Expressions
c906108c
SS
4587@section Expressions
4588
4589@cindex expressions
4590@code{print} and many other @value{GDBN} commands accept an expression and
4591compute its value. Any kind of constant, variable or operator defined
4592by the programming language you are using is valid in an expression in
e2e0bcd1
JB
4593@value{GDBN}. This includes conditional expressions, function calls,
4594casts, and string constants. It also includes preprocessor macros, if
4595you compiled your program to include this information; see
4596@ref{Compilation}.
c906108c 4597
d4f3574e
SS
4598@value{GDBN} supports array constants in expressions input by
4599the user. The syntax is @{@var{element}, @var{element}@dots{}@}. For example,
5d161b24 4600you can use the command @code{print @{1, 2, 3@}} to build up an array in
d4f3574e 4601memory that is @code{malloc}ed in the target program.
c906108c 4602
c906108c
SS
4603Because C is so widespread, most of the expressions shown in examples in
4604this manual are in C. @xref{Languages, , Using @value{GDBN} with Different
4605Languages}, for information on how to use expressions in other
4606languages.
4607
4608In this section, we discuss operators that you can use in @value{GDBN}
4609expressions regardless of your programming language.
4610
4611Casts are supported in all languages, not just in C, because it is so
4612useful to cast a number into a pointer in order to examine a structure
4613at that address in memory.
4614@c FIXME: casts supported---Mod2 true?
c906108c
SS
4615
4616@value{GDBN} supports these operators, in addition to those common
4617to programming languages:
4618
4619@table @code
4620@item @@
4621@samp{@@} is a binary operator for treating parts of memory as arrays.
4622@xref{Arrays, ,Artificial arrays}, for more information.
4623
4624@item ::
4625@samp{::} allows you to specify a variable in terms of the file or
4626function where it is defined. @xref{Variables, ,Program variables}.
4627
4628@cindex @{@var{type}@}
4629@cindex type casting memory
4630@cindex memory, viewing as typed object
4631@cindex casts, to view memory
4632@item @{@var{type}@} @var{addr}
4633Refers to an object of type @var{type} stored at address @var{addr} in
4634memory. @var{addr} may be any expression whose value is an integer or
4635pointer (but parentheses are required around binary operators, just as in
4636a cast). This construct is allowed regardless of what kind of data is
4637normally supposed to reside at @var{addr}.
4638@end table
4639
6d2ebf8b 4640@node Variables
c906108c
SS
4641@section Program variables
4642
4643The most common kind of expression to use is the name of a variable
4644in your program.
4645
4646Variables in expressions are understood in the selected stack frame
4647(@pxref{Selection, ,Selecting a frame}); they must be either:
4648
4649@itemize @bullet
4650@item
4651global (or file-static)
4652@end itemize
4653
5d161b24 4654@noindent or
c906108c
SS
4655
4656@itemize @bullet
4657@item
4658visible according to the scope rules of the
4659programming language from the point of execution in that frame
5d161b24 4660@end itemize
c906108c
SS
4661
4662@noindent This means that in the function
4663
474c8240 4664@smallexample
c906108c
SS
4665foo (a)
4666 int a;
4667@{
4668 bar (a);
4669 @{
4670 int b = test ();
4671 bar (b);
4672 @}
4673@}
474c8240 4674@end smallexample
c906108c
SS
4675
4676@noindent
4677you can examine and use the variable @code{a} whenever your program is
4678executing within the function @code{foo}, but you can only use or
4679examine the variable @code{b} while your program is executing inside
4680the block where @code{b} is declared.
4681
4682@cindex variable name conflict
4683There is an exception: you can refer to a variable or function whose
4684scope is a single source file even if the current execution point is not
4685in this file. But it is possible to have more than one such variable or
4686function with the same name (in different source files). If that
4687happens, referring to that name has unpredictable effects. If you wish,
4688you can specify a static variable in a particular function or file,
4689using the colon-colon notation:
4690
d4f3574e 4691@cindex colon-colon, context for variables/functions
c906108c
SS
4692@iftex
4693@c info cannot cope with a :: index entry, but why deprive hard copy readers?
41afff9a 4694@cindex @code{::}, context for variables/functions
c906108c 4695@end iftex
474c8240 4696@smallexample
c906108c
SS
4697@var{file}::@var{variable}
4698@var{function}::@var{variable}
474c8240 4699@end smallexample
c906108c
SS
4700
4701@noindent
4702Here @var{file} or @var{function} is the name of the context for the
4703static @var{variable}. In the case of file names, you can use quotes to
4704make sure @value{GDBN} parses the file name as a single word---for example,
4705to print a global value of @code{x} defined in @file{f2.c}:
4706
474c8240 4707@smallexample
c906108c 4708(@value{GDBP}) p 'f2.c'::x
474c8240 4709@end smallexample
c906108c 4710
b37052ae 4711@cindex C@t{++} scope resolution
c906108c 4712This use of @samp{::} is very rarely in conflict with the very similar
b37052ae 4713use of the same notation in C@t{++}. @value{GDBN} also supports use of the C@t{++}
c906108c
SS
4714scope resolution operator in @value{GDBN} expressions.
4715@c FIXME: Um, so what happens in one of those rare cases where it's in
4716@c conflict?? --mew
c906108c
SS
4717
4718@cindex wrong values
4719@cindex variable values, wrong
4720@quotation
4721@emph{Warning:} Occasionally, a local variable may appear to have the
4722wrong value at certain points in a function---just after entry to a new
4723scope, and just before exit.
4724@end quotation
4725You may see this problem when you are stepping by machine instructions.
4726This is because, on most machines, it takes more than one instruction to
4727set up a stack frame (including local variable definitions); if you are
4728stepping by machine instructions, variables may appear to have the wrong
4729values until the stack frame is completely built. On exit, it usually
4730also takes more than one machine instruction to destroy a stack frame;
4731after you begin stepping through that group of instructions, local
4732variable definitions may be gone.
4733
4734This may also happen when the compiler does significant optimizations.
4735To be sure of always seeing accurate values, turn off all optimization
4736when compiling.
4737
d4f3574e
SS
4738@cindex ``No symbol "foo" in current context''
4739Another possible effect of compiler optimizations is to optimize
4740unused variables out of existence, or assign variables to registers (as
4741opposed to memory addresses). Depending on the support for such cases
4742offered by the debug info format used by the compiler, @value{GDBN}
4743might not be able to display values for such local variables. If that
4744happens, @value{GDBN} will print a message like this:
4745
474c8240 4746@smallexample
d4f3574e 4747No symbol "foo" in current context.
474c8240 4748@end smallexample
d4f3574e
SS
4749
4750To solve such problems, either recompile without optimizations, or use a
4751different debug info format, if the compiler supports several such
0179ffac
DC
4752formats. For example, @value{NGCC}, the @sc{gnu} C/C@t{++} compiler
4753usually supports the @option{-gstabs+} option. @option{-gstabs+}
4754produces debug info in a format that is superior to formats such as
4755COFF. You may be able to use DWARF 2 (@option{-gdwarf-2}), which is also
4756an effective form for debug info. @xref{Debugging Options,,Options
4757for Debugging Your Program or @sc{gnu} CC, gcc.info, Using @sc{gnu} CC}.
d4f3574e
SS
4758
4759
6d2ebf8b 4760@node Arrays
c906108c
SS
4761@section Artificial arrays
4762
4763@cindex artificial array
41afff9a 4764@kindex @@@r{, referencing memory as an array}
c906108c
SS
4765It is often useful to print out several successive objects of the
4766same type in memory; a section of an array, or an array of
4767dynamically determined size for which only a pointer exists in the
4768program.
4769
4770You can do this by referring to a contiguous span of memory as an
4771@dfn{artificial array}, using the binary operator @samp{@@}. The left
4772operand of @samp{@@} should be the first element of the desired array
4773and be an individual object. The right operand should be the desired length
4774of the array. The result is an array value whose elements are all of
4775the type of the left argument. The first element is actually the left
4776argument; the second element comes from bytes of memory immediately
4777following those that hold the first element, and so on. Here is an
4778example. If a program says
4779
474c8240 4780@smallexample
c906108c 4781int *array = (int *) malloc (len * sizeof (int));
474c8240 4782@end smallexample
c906108c
SS
4783
4784@noindent
4785you can print the contents of @code{array} with
4786
474c8240 4787@smallexample
c906108c 4788p *array@@len
474c8240 4789@end smallexample
c906108c
SS
4790
4791The left operand of @samp{@@} must reside in memory. Array values made
4792with @samp{@@} in this way behave just like other arrays in terms of
4793subscripting, and are coerced to pointers when used in expressions.
4794Artificial arrays most often appear in expressions via the value history
4795(@pxref{Value History, ,Value history}), after printing one out.
4796
4797Another way to create an artificial array is to use a cast.
4798This re-interprets a value as if it were an array.
4799The value need not be in memory:
474c8240 4800@smallexample
c906108c
SS
4801(@value{GDBP}) p/x (short[2])0x12345678
4802$1 = @{0x1234, 0x5678@}
474c8240 4803@end smallexample
c906108c
SS
4804
4805As a convenience, if you leave the array length out (as in
c3f6f71d 4806@samp{(@var{type}[])@var{value}}) @value{GDBN} calculates the size to fill
c906108c 4807the value (as @samp{sizeof(@var{value})/sizeof(@var{type})}:
474c8240 4808@smallexample
c906108c
SS
4809(@value{GDBP}) p/x (short[])0x12345678
4810$2 = @{0x1234, 0x5678@}
474c8240 4811@end smallexample
c906108c
SS
4812
4813Sometimes the artificial array mechanism is not quite enough; in
4814moderately complex data structures, the elements of interest may not
4815actually be adjacent---for example, if you are interested in the values
4816of pointers in an array. One useful work-around in this situation is
4817to use a convenience variable (@pxref{Convenience Vars, ,Convenience
4818variables}) as a counter in an expression that prints the first
4819interesting value, and then repeat that expression via @key{RET}. For
4820instance, suppose you have an array @code{dtab} of pointers to
4821structures, and you are interested in the values of a field @code{fv}
4822in each structure. Here is an example of what you might type:
4823
474c8240 4824@smallexample
c906108c
SS
4825set $i = 0
4826p dtab[$i++]->fv
4827@key{RET}
4828@key{RET}
4829@dots{}
474c8240 4830@end smallexample
c906108c 4831
6d2ebf8b 4832@node Output Formats
c906108c
SS
4833@section Output formats
4834
4835@cindex formatted output
4836@cindex output formats
4837By default, @value{GDBN} prints a value according to its data type. Sometimes
4838this is not what you want. For example, you might want to print a number
4839in hex, or a pointer in decimal. Or you might want to view data in memory
4840at a certain address as a character string or as an instruction. To do
4841these things, specify an @dfn{output format} when you print a value.
4842
4843The simplest use of output formats is to say how to print a value
4844already computed. This is done by starting the arguments of the
4845@code{print} command with a slash and a format letter. The format
4846letters supported are:
4847
4848@table @code
4849@item x
4850Regard the bits of the value as an integer, and print the integer in
4851hexadecimal.
4852
4853@item d
4854Print as integer in signed decimal.
4855
4856@item u
4857Print as integer in unsigned decimal.
4858
4859@item o
4860Print as integer in octal.
4861
4862@item t
4863Print as integer in binary. The letter @samp{t} stands for ``two''.
4864@footnote{@samp{b} cannot be used because these format letters are also
4865used with the @code{x} command, where @samp{b} stands for ``byte'';
d4f3574e 4866see @ref{Memory,,Examining memory}.}
c906108c
SS
4867
4868@item a
4869@cindex unknown address, locating
3d67e040 4870@cindex locate address
c906108c
SS
4871Print as an address, both absolute in hexadecimal and as an offset from
4872the nearest preceding symbol. You can use this format used to discover
4873where (in what function) an unknown address is located:
4874
474c8240 4875@smallexample
c906108c
SS
4876(@value{GDBP}) p/a 0x54320
4877$3 = 0x54320 <_initialize_vx+396>
474c8240 4878@end smallexample
c906108c 4879
3d67e040
EZ
4880@noindent
4881The command @code{info symbol 0x54320} yields similar results.
4882@xref{Symbols, info symbol}.
4883
c906108c
SS
4884@item c
4885Regard as an integer and print it as a character constant.
4886
4887@item f
4888Regard the bits of the value as a floating point number and print
4889using typical floating point syntax.
4890@end table
4891
4892For example, to print the program counter in hex (@pxref{Registers}), type
4893
474c8240 4894@smallexample
c906108c 4895p/x $pc
474c8240 4896@end smallexample
c906108c
SS
4897
4898@noindent
4899Note that no space is required before the slash; this is because command
4900names in @value{GDBN} cannot contain a slash.
4901
4902To reprint the last value in the value history with a different format,
4903you can use the @code{print} command with just a format and no
4904expression. For example, @samp{p/x} reprints the last value in hex.
4905
6d2ebf8b 4906@node Memory
c906108c
SS
4907@section Examining memory
4908
4909You can use the command @code{x} (for ``examine'') to examine memory in
4910any of several formats, independently of your program's data types.
4911
4912@cindex examining memory
4913@table @code
41afff9a 4914@kindex x @r{(examine memory)}
c906108c
SS
4915@item x/@var{nfu} @var{addr}
4916@itemx x @var{addr}
4917@itemx x
4918Use the @code{x} command to examine memory.
4919@end table
4920
4921@var{n}, @var{f}, and @var{u} are all optional parameters that specify how
4922much memory to display and how to format it; @var{addr} is an
4923expression giving the address where you want to start displaying memory.
4924If you use defaults for @var{nfu}, you need not type the slash @samp{/}.
4925Several commands set convenient defaults for @var{addr}.
4926
4927@table @r
4928@item @var{n}, the repeat count
4929The repeat count is a decimal integer; the default is 1. It specifies
4930how much memory (counting by units @var{u}) to display.
4931@c This really is **decimal**; unaffected by 'set radix' as of GDB
4932@c 4.1.2.
4933
4934@item @var{f}, the display format
4935The display format is one of the formats used by @code{print},
4936@samp{s} (null-terminated string), or @samp{i} (machine instruction).
4937The default is @samp{x} (hexadecimal) initially.
4938The default changes each time you use either @code{x} or @code{print}.
4939
4940@item @var{u}, the unit size
4941The unit size is any of
4942
4943@table @code
4944@item b
4945Bytes.
4946@item h
4947Halfwords (two bytes).
4948@item w
4949Words (four bytes). This is the initial default.
4950@item g
4951Giant words (eight bytes).
4952@end table
4953
4954Each time you specify a unit size with @code{x}, that size becomes the
4955default unit the next time you use @code{x}. (For the @samp{s} and
4956@samp{i} formats, the unit size is ignored and is normally not written.)
4957
4958@item @var{addr}, starting display address
4959@var{addr} is the address where you want @value{GDBN} to begin displaying
4960memory. The expression need not have a pointer value (though it may);
4961it is always interpreted as an integer address of a byte of memory.
4962@xref{Expressions, ,Expressions}, for more information on expressions. The default for
4963@var{addr} is usually just after the last address examined---but several
4964other commands also set the default address: @code{info breakpoints} (to
4965the address of the last breakpoint listed), @code{info line} (to the
4966starting address of a line), and @code{print} (if you use it to display
4967a value from memory).
4968@end table
4969
4970For example, @samp{x/3uh 0x54320} is a request to display three halfwords
4971(@code{h}) of memory, formatted as unsigned decimal integers (@samp{u}),
4972starting at address @code{0x54320}. @samp{x/4xw $sp} prints the four
4973words (@samp{w}) of memory above the stack pointer (here, @samp{$sp};
d4f3574e 4974@pxref{Registers, ,Registers}) in hexadecimal (@samp{x}).
c906108c
SS
4975
4976Since the letters indicating unit sizes are all distinct from the
4977letters specifying output formats, you do not have to remember whether
4978unit size or format comes first; either order works. The output
4979specifications @samp{4xw} and @samp{4wx} mean exactly the same thing.
4980(However, the count @var{n} must come first; @samp{wx4} does not work.)
4981
4982Even though the unit size @var{u} is ignored for the formats @samp{s}
4983and @samp{i}, you might still want to use a count @var{n}; for example,
4984@samp{3i} specifies that you want to see three machine instructions,
4985including any operands. The command @code{disassemble} gives an
d4f3574e 4986alternative way of inspecting machine instructions; see @ref{Machine
c906108c
SS
4987Code,,Source and machine code}.
4988
4989All the defaults for the arguments to @code{x} are designed to make it
4990easy to continue scanning memory with minimal specifications each time
4991you use @code{x}. For example, after you have inspected three machine
4992instructions with @samp{x/3i @var{addr}}, you can inspect the next seven
4993with just @samp{x/7}. If you use @key{RET} to repeat the @code{x} command,
4994the repeat count @var{n} is used again; the other arguments default as
4995for successive uses of @code{x}.
4996
4997@cindex @code{$_}, @code{$__}, and value history
4998The addresses and contents printed by the @code{x} command are not saved
4999in the value history because there is often too much of them and they
5000would get in the way. Instead, @value{GDBN} makes these values available for
5001subsequent use in expressions as values of the convenience variables
5002@code{$_} and @code{$__}. After an @code{x} command, the last address
5003examined is available for use in expressions in the convenience variable
5004@code{$_}. The contents of that address, as examined, are available in
5005the convenience variable @code{$__}.
5006
5007If the @code{x} command has a repeat count, the address and contents saved
5008are from the last memory unit printed; this is not the same as the last
5009address printed if several units were printed on the last line of output.
5010
6d2ebf8b 5011@node Auto Display
c906108c
SS
5012@section Automatic display
5013@cindex automatic display
5014@cindex display of expressions
5015
5016If you find that you want to print the value of an expression frequently
5017(to see how it changes), you might want to add it to the @dfn{automatic
5018display list} so that @value{GDBN} prints its value each time your program stops.
5019Each expression added to the list is given a number to identify it;
5020to remove an expression from the list, you specify that number.
5021The automatic display looks like this:
5022
474c8240 5023@smallexample
c906108c
SS
50242: foo = 38
50253: bar[5] = (struct hack *) 0x3804
474c8240 5026@end smallexample
c906108c
SS
5027
5028@noindent
5029This display shows item numbers, expressions and their current values. As with
5030displays you request manually using @code{x} or @code{print}, you can
5031specify the output format you prefer; in fact, @code{display} decides
5032whether to use @code{print} or @code{x} depending on how elaborate your
5033format specification is---it uses @code{x} if you specify a unit size,
5034or one of the two formats (@samp{i} and @samp{s}) that are only
5035supported by @code{x}; otherwise it uses @code{print}.
5036
5037@table @code
5038@kindex display
d4f3574e
SS
5039@item display @var{expr}
5040Add the expression @var{expr} to the list of expressions to display
c906108c
SS
5041each time your program stops. @xref{Expressions, ,Expressions}.
5042
5043@code{display} does not repeat if you press @key{RET} again after using it.
5044
d4f3574e 5045@item display/@var{fmt} @var{expr}
c906108c 5046For @var{fmt} specifying only a display format and not a size or
d4f3574e 5047count, add the expression @var{expr} to the auto-display list but
c906108c
SS
5048arrange to display it each time in the specified format @var{fmt}.
5049@xref{Output Formats,,Output formats}.
5050
5051@item display/@var{fmt} @var{addr}
5052For @var{fmt} @samp{i} or @samp{s}, or including a unit-size or a
5053number of units, add the expression @var{addr} as a memory address to
5054be examined each time your program stops. Examining means in effect
5055doing @samp{x/@var{fmt} @var{addr}}. @xref{Memory, ,Examining memory}.
5056@end table
5057
5058For example, @samp{display/i $pc} can be helpful, to see the machine
5059instruction about to be executed each time execution stops (@samp{$pc}
d4f3574e 5060is a common name for the program counter; @pxref{Registers, ,Registers}).
c906108c
SS
5061
5062@table @code
5063@kindex delete display
5064@kindex undisplay
5065@item undisplay @var{dnums}@dots{}
5066@itemx delete display @var{dnums}@dots{}
5067Remove item numbers @var{dnums} from the list of expressions to display.
5068
5069@code{undisplay} does not repeat if you press @key{RET} after using it.
5070(Otherwise you would just get the error @samp{No display number @dots{}}.)
5071
5072@kindex disable display
5073@item disable display @var{dnums}@dots{}
5074Disable the display of item numbers @var{dnums}. A disabled display
5075item is not printed automatically, but is not forgotten. It may be
5076enabled again later.
5077
5078@kindex enable display
5079@item enable display @var{dnums}@dots{}
5080Enable display of item numbers @var{dnums}. It becomes effective once
5081again in auto display of its expression, until you specify otherwise.
5082
5083@item display
5084Display the current values of the expressions on the list, just as is
5085done when your program stops.
5086
5087@kindex info display
5088@item info display
5089Print the list of expressions previously set up to display
5090automatically, each one with its item number, but without showing the
5091values. This includes disabled expressions, which are marked as such.
5092It also includes expressions which would not be displayed right now
5093because they refer to automatic variables not currently available.
5094@end table
5095
5096If a display expression refers to local variables, then it does not make
5097sense outside the lexical context for which it was set up. Such an
5098expression is disabled when execution enters a context where one of its
5099variables is not defined. For example, if you give the command
5100@code{display last_char} while inside a function with an argument
5101@code{last_char}, @value{GDBN} displays this argument while your program
5102continues to stop inside that function. When it stops elsewhere---where
5103there is no variable @code{last_char}---the display is disabled
5104automatically. The next time your program stops where @code{last_char}
5105is meaningful, you can enable the display expression once again.
5106
6d2ebf8b 5107@node Print Settings
c906108c
SS
5108@section Print settings
5109
5110@cindex format options
5111@cindex print settings
5112@value{GDBN} provides the following ways to control how arrays, structures,
5113and symbols are printed.
5114
5115@noindent
5116These settings are useful for debugging programs in any language:
5117
5118@table @code
5119@kindex set print address
5120@item set print address
5121@itemx set print address on
5122@value{GDBN} prints memory addresses showing the location of stack
5123traces, structure values, pointer values, breakpoints, and so forth,
5124even when it also displays the contents of those addresses. The default
5125is @code{on}. For example, this is what a stack frame display looks like with
5126@code{set print address on}:
5127
5128@smallexample
5129@group
5130(@value{GDBP}) f
5131#0 set_quotes (lq=0x34c78 "<<", rq=0x34c88 ">>")
5132 at input.c:530
5133530 if (lquote != def_lquote)
5134@end group
5135@end smallexample
5136
5137@item set print address off
5138Do not print addresses when displaying their contents. For example,
5139this is the same stack frame displayed with @code{set print address off}:
5140
5141@smallexample
5142@group
5143(@value{GDBP}) set print addr off
5144(@value{GDBP}) f
5145#0 set_quotes (lq="<<", rq=">>") at input.c:530
5146530 if (lquote != def_lquote)
5147@end group
5148@end smallexample
5149
5150You can use @samp{set print address off} to eliminate all machine
5151dependent displays from the @value{GDBN} interface. For example, with
5152@code{print address off}, you should get the same text for backtraces on
5153all machines---whether or not they involve pointer arguments.
5154
5155@kindex show print address
5156@item show print address
5157Show whether or not addresses are to be printed.
5158@end table
5159
5160When @value{GDBN} prints a symbolic address, it normally prints the
5161closest earlier symbol plus an offset. If that symbol does not uniquely
5162identify the address (for example, it is a name whose scope is a single
5163source file), you may need to clarify. One way to do this is with
5164@code{info line}, for example @samp{info line *0x4537}. Alternately,
5165you can set @value{GDBN} to print the source file and line number when
5166it prints a symbolic address:
5167
5168@table @code
5169@kindex set print symbol-filename
5170@item set print symbol-filename on
5171Tell @value{GDBN} to print the source file name and line number of a
5172symbol in the symbolic form of an address.
5173
5174@item set print symbol-filename off
5175Do not print source file name and line number of a symbol. This is the
5176default.
5177
5178@kindex show print symbol-filename
5179@item show print symbol-filename
5180Show whether or not @value{GDBN} will print the source file name and
5181line number of a symbol in the symbolic form of an address.
5182@end table
5183
5184Another situation where it is helpful to show symbol filenames and line
5185numbers is when disassembling code; @value{GDBN} shows you the line
5186number and source file that corresponds to each instruction.
5187
5188Also, you may wish to see the symbolic form only if the address being
5189printed is reasonably close to the closest earlier symbol:
5190
5191@table @code
5192@kindex set print max-symbolic-offset
5193@item set print max-symbolic-offset @var{max-offset}
5194Tell @value{GDBN} to only display the symbolic form of an address if the
5195offset between the closest earlier symbol and the address is less than
5d161b24 5196@var{max-offset}. The default is 0, which tells @value{GDBN}
c906108c
SS
5197to always print the symbolic form of an address if any symbol precedes it.
5198
5199@kindex show print max-symbolic-offset
5200@item show print max-symbolic-offset
5201Ask how large the maximum offset is that @value{GDBN} prints in a
5202symbolic address.
5203@end table
5204
5205@cindex wild pointer, interpreting
5206@cindex pointer, finding referent
5207If you have a pointer and you are not sure where it points, try
5208@samp{set print symbol-filename on}. Then you can determine the name
5209and source file location of the variable where it points, using
5210@samp{p/a @var{pointer}}. This interprets the address in symbolic form.
5211For example, here @value{GDBN} shows that a variable @code{ptt} points
5212at another variable @code{t}, defined in @file{hi2.c}:
5213
474c8240 5214@smallexample
c906108c
SS
5215(@value{GDBP}) set print symbol-filename on
5216(@value{GDBP}) p/a ptt
5217$4 = 0xe008 <t in hi2.c>
474c8240 5218@end smallexample
c906108c
SS
5219
5220@quotation
5221@emph{Warning:} For pointers that point to a local variable, @samp{p/a}
5222does not show the symbol name and filename of the referent, even with
5223the appropriate @code{set print} options turned on.
5224@end quotation
5225
5226Other settings control how different kinds of objects are printed:
5227
5228@table @code
5229@kindex set print array
5230@item set print array
5231@itemx set print array on
5232Pretty print arrays. This format is more convenient to read,
5233but uses more space. The default is off.
5234
5235@item set print array off
5236Return to compressed format for arrays.
5237
5238@kindex show print array
5239@item show print array
5240Show whether compressed or pretty format is selected for displaying
5241arrays.
5242
5243@kindex set print elements
5244@item set print elements @var{number-of-elements}
5245Set a limit on how many elements of an array @value{GDBN} will print.
5246If @value{GDBN} is printing a large array, it stops printing after it has
5247printed the number of elements set by the @code{set print elements} command.
5248This limit also applies to the display of strings.
d4f3574e 5249When @value{GDBN} starts, this limit is set to 200.
c906108c
SS
5250Setting @var{number-of-elements} to zero means that the printing is unlimited.
5251
5252@kindex show print elements
5253@item show print elements
5254Display the number of elements of a large array that @value{GDBN} will print.
5255If the number is 0, then the printing is unlimited.
5256
5257@kindex set print null-stop
5258@item set print null-stop
5259Cause @value{GDBN} to stop printing the characters of an array when the first
d4f3574e 5260@sc{null} is encountered. This is useful when large arrays actually
c906108c 5261contain only short strings.
d4f3574e 5262The default is off.
c906108c
SS
5263
5264@kindex set print pretty
5265@item set print pretty on
5d161b24 5266Cause @value{GDBN} to print structures in an indented format with one member
c906108c
SS
5267per line, like this:
5268
5269@smallexample
5270@group
5271$1 = @{
5272 next = 0x0,
5273 flags = @{
5274 sweet = 1,
5275 sour = 1
5276 @},
5277 meat = 0x54 "Pork"
5278@}
5279@end group
5280@end smallexample
5281
5282@item set print pretty off
5283Cause @value{GDBN} to print structures in a compact format, like this:
5284
5285@smallexample
5286@group
5287$1 = @{next = 0x0, flags = @{sweet = 1, sour = 1@}, \
5288meat = 0x54 "Pork"@}
5289@end group
5290@end smallexample
5291
5292@noindent
5293This is the default format.
5294
5295@kindex show print pretty
5296@item show print pretty
5297Show which format @value{GDBN} is using to print structures.
5298
5299@kindex set print sevenbit-strings
5300@item set print sevenbit-strings on
5301Print using only seven-bit characters; if this option is set,
5302@value{GDBN} displays any eight-bit characters (in strings or
5303character values) using the notation @code{\}@var{nnn}. This setting is
5304best if you are working in English (@sc{ascii}) and you use the
5305high-order bit of characters as a marker or ``meta'' bit.
5306
5307@item set print sevenbit-strings off
5308Print full eight-bit characters. This allows the use of more
5309international character sets, and is the default.
5310
5311@kindex show print sevenbit-strings
5312@item show print sevenbit-strings
5313Show whether or not @value{GDBN} is printing only seven-bit characters.
5314
5315@kindex set print union
5316@item set print union on
5d161b24 5317Tell @value{GDBN} to print unions which are contained in structures. This
c906108c
SS
5318is the default setting.
5319
5320@item set print union off
5321Tell @value{GDBN} not to print unions which are contained in structures.
5322
5323@kindex show print union
5324@item show print union
5325Ask @value{GDBN} whether or not it will print unions which are contained in
5326structures.
5327
5328For example, given the declarations
5329
5330@smallexample
5331typedef enum @{Tree, Bug@} Species;
5332typedef enum @{Big_tree, Acorn, Seedling@} Tree_forms;
5d161b24 5333typedef enum @{Caterpillar, Cocoon, Butterfly@}
c906108c
SS
5334 Bug_forms;
5335
5336struct thing @{
5337 Species it;
5338 union @{
5339 Tree_forms tree;
5340 Bug_forms bug;
5341 @} form;
5342@};
5343
5344struct thing foo = @{Tree, @{Acorn@}@};
5345@end smallexample
5346
5347@noindent
5348with @code{set print union on} in effect @samp{p foo} would print
5349
5350@smallexample
5351$1 = @{it = Tree, form = @{tree = Acorn, bug = Cocoon@}@}
5352@end smallexample
5353
5354@noindent
5355and with @code{set print union off} in effect it would print
5356
5357@smallexample
5358$1 = @{it = Tree, form = @{...@}@}
5359@end smallexample
5360@end table
5361
c906108c
SS
5362@need 1000
5363@noindent
b37052ae 5364These settings are of interest when debugging C@t{++} programs:
c906108c
SS
5365
5366@table @code
5367@cindex demangling
5368@kindex set print demangle
5369@item set print demangle
5370@itemx set print demangle on
b37052ae 5371Print C@t{++} names in their source form rather than in the encoded
c906108c 5372(``mangled'') form passed to the assembler and linker for type-safe
d4f3574e 5373linkage. The default is on.
c906108c
SS
5374
5375@kindex show print demangle
5376@item show print demangle
b37052ae 5377Show whether C@t{++} names are printed in mangled or demangled form.
c906108c
SS
5378
5379@kindex set print asm-demangle
5380@item set print asm-demangle
5381@itemx set print asm-demangle on
b37052ae 5382Print C@t{++} names in their source form rather than their mangled form, even
c906108c
SS
5383in assembler code printouts such as instruction disassemblies.
5384The default is off.
5385
5386@kindex show print asm-demangle
5387@item show print asm-demangle
b37052ae 5388Show whether C@t{++} names in assembly listings are printed in mangled
c906108c
SS
5389or demangled form.
5390
5391@kindex set demangle-style
b37052ae
EZ
5392@cindex C@t{++} symbol decoding style
5393@cindex symbol decoding style, C@t{++}
c906108c
SS
5394@item set demangle-style @var{style}
5395Choose among several encoding schemes used by different compilers to
b37052ae 5396represent C@t{++} names. The choices for @var{style} are currently:
c906108c
SS
5397
5398@table @code
5399@item auto
5400Allow @value{GDBN} to choose a decoding style by inspecting your program.
5401
5402@item gnu
b37052ae 5403Decode based on the @sc{gnu} C@t{++} compiler (@code{g++}) encoding algorithm.
c906108c 5404This is the default.
c906108c
SS
5405
5406@item hp
b37052ae 5407Decode based on the HP ANSI C@t{++} (@code{aCC}) encoding algorithm.
c906108c
SS
5408
5409@item lucid
b37052ae 5410Decode based on the Lucid C@t{++} compiler (@code{lcc}) encoding algorithm.
c906108c
SS
5411
5412@item arm
b37052ae 5413Decode using the algorithm in the @cite{C@t{++} Annotated Reference Manual}.
c906108c
SS
5414@strong{Warning:} this setting alone is not sufficient to allow
5415debugging @code{cfront}-generated executables. @value{GDBN} would
5416require further enhancement to permit that.
5417
5418@end table
5419If you omit @var{style}, you will see a list of possible formats.
5420
5421@kindex show demangle-style
5422@item show demangle-style
b37052ae 5423Display the encoding style currently in use for decoding C@t{++} symbols.
c906108c
SS
5424
5425@kindex set print object
5426@item set print object
5427@itemx set print object on
5428When displaying a pointer to an object, identify the @emph{actual}
5429(derived) type of the object rather than the @emph{declared} type, using
5430the virtual function table.
5431
5432@item set print object off
5433Display only the declared type of objects, without reference to the
5434virtual function table. This is the default setting.
5435
5436@kindex show print object
5437@item show print object
5438Show whether actual, or declared, object types are displayed.
5439
5440@kindex set print static-members
5441@item set print static-members
5442@itemx set print static-members on
b37052ae 5443Print static members when displaying a C@t{++} object. The default is on.
c906108c
SS
5444
5445@item set print static-members off
b37052ae 5446Do not print static members when displaying a C@t{++} object.
c906108c
SS
5447
5448@kindex show print static-members
5449@item show print static-members
b37052ae 5450Show whether C@t{++} static members are printed, or not.
c906108c
SS
5451
5452@c These don't work with HP ANSI C++ yet.
5453@kindex set print vtbl
5454@item set print vtbl
5455@itemx set print vtbl on
b37052ae 5456Pretty print C@t{++} virtual function tables. The default is off.
c906108c 5457(The @code{vtbl} commands do not work on programs compiled with the HP
b37052ae 5458ANSI C@t{++} compiler (@code{aCC}).)
c906108c
SS
5459
5460@item set print vtbl off
b37052ae 5461Do not pretty print C@t{++} virtual function tables.
c906108c
SS
5462
5463@kindex show print vtbl
5464@item show print vtbl
b37052ae 5465Show whether C@t{++} virtual function tables are pretty printed, or not.
c906108c 5466@end table
c906108c 5467
6d2ebf8b 5468@node Value History
c906108c
SS
5469@section Value history
5470
5471@cindex value history
5d161b24
DB
5472Values printed by the @code{print} command are saved in the @value{GDBN}
5473@dfn{value history}. This allows you to refer to them in other expressions.
5474Values are kept until the symbol table is re-read or discarded
5475(for example with the @code{file} or @code{symbol-file} commands).
5476When the symbol table changes, the value history is discarded,
5477since the values may contain pointers back to the types defined in the
c906108c
SS
5478symbol table.
5479
5480@cindex @code{$}
5481@cindex @code{$$}
5482@cindex history number
5483The values printed are given @dfn{history numbers} by which you can
5484refer to them. These are successive integers starting with one.
5485@code{print} shows you the history number assigned to a value by
5486printing @samp{$@var{num} = } before the value; here @var{num} is the
5487history number.
5488
5489To refer to any previous value, use @samp{$} followed by the value's
5490history number. The way @code{print} labels its output is designed to
5491remind you of this. Just @code{$} refers to the most recent value in
5492the history, and @code{$$} refers to the value before that.
5493@code{$$@var{n}} refers to the @var{n}th value from the end; @code{$$2}
5494is the value just prior to @code{$$}, @code{$$1} is equivalent to
5495@code{$$}, and @code{$$0} is equivalent to @code{$}.
5496
5497For example, suppose you have just printed a pointer to a structure and
5498want to see the contents of the structure. It suffices to type
5499
474c8240 5500@smallexample
c906108c 5501p *$
474c8240 5502@end smallexample
c906108c
SS
5503
5504If you have a chain of structures where the component @code{next} points
5505to the next one, you can print the contents of the next one with this:
5506
474c8240 5507@smallexample
c906108c 5508p *$.next
474c8240 5509@end smallexample
c906108c
SS
5510
5511@noindent
5512You can print successive links in the chain by repeating this
5513command---which you can do by just typing @key{RET}.
5514
5515Note that the history records values, not expressions. If the value of
5516@code{x} is 4 and you type these commands:
5517
474c8240 5518@smallexample
c906108c
SS
5519print x
5520set x=5
474c8240 5521@end smallexample
c906108c
SS
5522
5523@noindent
5524then the value recorded in the value history by the @code{print} command
5525remains 4 even though the value of @code{x} has changed.
5526
5527@table @code
5528@kindex show values
5529@item show values
5530Print the last ten values in the value history, with their item numbers.
5531This is like @samp{p@ $$9} repeated ten times, except that @code{show
5532values} does not change the history.
5533
5534@item show values @var{n}
5535Print ten history values centered on history item number @var{n}.
5536
5537@item show values +
5538Print ten history values just after the values last printed. If no more
5539values are available, @code{show values +} produces no display.
5540@end table
5541
5542Pressing @key{RET} to repeat @code{show values @var{n}} has exactly the
5543same effect as @samp{show values +}.
5544
6d2ebf8b 5545@node Convenience Vars
c906108c
SS
5546@section Convenience variables
5547
5548@cindex convenience variables
5549@value{GDBN} provides @dfn{convenience variables} that you can use within
5550@value{GDBN} to hold on to a value and refer to it later. These variables
5551exist entirely within @value{GDBN}; they are not part of your program, and
5552setting a convenience variable has no direct effect on further execution
5553of your program. That is why you can use them freely.
5554
5555Convenience variables are prefixed with @samp{$}. Any name preceded by
5556@samp{$} can be used for a convenience variable, unless it is one of
d4f3574e 5557the predefined machine-specific register names (@pxref{Registers, ,Registers}).
c906108c
SS
5558(Value history references, in contrast, are @emph{numbers} preceded
5559by @samp{$}. @xref{Value History, ,Value history}.)
5560
5561You can save a value in a convenience variable with an assignment
5562expression, just as you would set a variable in your program.
5563For example:
5564
474c8240 5565@smallexample
c906108c 5566set $foo = *object_ptr
474c8240 5567@end smallexample
c906108c
SS
5568
5569@noindent
5570would save in @code{$foo} the value contained in the object pointed to by
5571@code{object_ptr}.
5572
5573Using a convenience variable for the first time creates it, but its
5574value is @code{void} until you assign a new value. You can alter the
5575value with another assignment at any time.
5576
5577Convenience variables have no fixed types. You can assign a convenience
5578variable any type of value, including structures and arrays, even if
5579that variable already has a value of a different type. The convenience
5580variable, when used as an expression, has the type of its current value.
5581
5582@table @code
5583@kindex show convenience
5584@item show convenience
5585Print a list of convenience variables used so far, and their values.
d4f3574e 5586Abbreviated @code{show conv}.
c906108c
SS
5587@end table
5588
5589One of the ways to use a convenience variable is as a counter to be
5590incremented or a pointer to be advanced. For example, to print
5591a field from successive elements of an array of structures:
5592
474c8240 5593@smallexample
c906108c
SS
5594set $i = 0
5595print bar[$i++]->contents
474c8240 5596@end smallexample
c906108c 5597
d4f3574e
SS
5598@noindent
5599Repeat that command by typing @key{RET}.
c906108c
SS
5600
5601Some convenience variables are created automatically by @value{GDBN} and given
5602values likely to be useful.
5603
5604@table @code
41afff9a 5605@vindex $_@r{, convenience variable}
c906108c
SS
5606@item $_
5607The variable @code{$_} is automatically set by the @code{x} command to
5608the last address examined (@pxref{Memory, ,Examining memory}). Other
5609commands which provide a default address for @code{x} to examine also
5610set @code{$_} to that address; these commands include @code{info line}
5611and @code{info breakpoint}. The type of @code{$_} is @code{void *}
5612except when set by the @code{x} command, in which case it is a pointer
5613to the type of @code{$__}.
5614
41afff9a 5615@vindex $__@r{, convenience variable}
c906108c
SS
5616@item $__
5617The variable @code{$__} is automatically set by the @code{x} command
5618to the value found in the last address examined. Its type is chosen
5619to match the format in which the data was printed.
5620
5621@item $_exitcode
41afff9a 5622@vindex $_exitcode@r{, convenience variable}
c906108c
SS
5623The variable @code{$_exitcode} is automatically set to the exit code when
5624the program being debugged terminates.
5625@end table
5626
53a5351d
JM
5627On HP-UX systems, if you refer to a function or variable name that
5628begins with a dollar sign, @value{GDBN} searches for a user or system
5629name first, before it searches for a convenience variable.
c906108c 5630
6d2ebf8b 5631@node Registers
c906108c
SS
5632@section Registers
5633
5634@cindex registers
5635You can refer to machine register contents, in expressions, as variables
5636with names starting with @samp{$}. The names of registers are different
5637for each machine; use @code{info registers} to see the names used on
5638your machine.
5639
5640@table @code
5641@kindex info registers
5642@item info registers
5643Print the names and values of all registers except floating-point
c85508ee 5644and vector registers (in the selected stack frame).
c906108c
SS
5645
5646@kindex info all-registers
5647@cindex floating point registers
5648@item info all-registers
5649Print the names and values of all registers, including floating-point
c85508ee 5650and vector registers (in the selected stack frame).
c906108c
SS
5651
5652@item info registers @var{regname} @dots{}
5653Print the @dfn{relativized} value of each specified register @var{regname}.
5d161b24
DB
5654As discussed in detail below, register values are normally relative to
5655the selected stack frame. @var{regname} may be any register name valid on
c906108c
SS
5656the machine you are using, with or without the initial @samp{$}.
5657@end table
5658
5659@value{GDBN} has four ``standard'' register names that are available (in
5660expressions) on most machines---whenever they do not conflict with an
5661architecture's canonical mnemonics for registers. The register names
5662@code{$pc} and @code{$sp} are used for the program counter register and
5663the stack pointer. @code{$fp} is used for a register that contains a
5664pointer to the current stack frame, and @code{$ps} is used for a
5665register that contains the processor status. For example,
5666you could print the program counter in hex with
5667
474c8240 5668@smallexample
c906108c 5669p/x $pc
474c8240 5670@end smallexample
c906108c
SS
5671
5672@noindent
5673or print the instruction to be executed next with
5674
474c8240 5675@smallexample
c906108c 5676x/i $pc
474c8240 5677@end smallexample
c906108c
SS
5678
5679@noindent
5680or add four to the stack pointer@footnote{This is a way of removing
5681one word from the stack, on machines where stacks grow downward in
5682memory (most machines, nowadays). This assumes that the innermost
5683stack frame is selected; setting @code{$sp} is not allowed when other
5684stack frames are selected. To pop entire frames off the stack,
5685regardless of machine architecture, use @code{return};
d4f3574e 5686see @ref{Returning, ,Returning from a function}.} with
c906108c 5687
474c8240 5688@smallexample
c906108c 5689set $sp += 4
474c8240 5690@end smallexample
c906108c
SS
5691
5692Whenever possible, these four standard register names are available on
5693your machine even though the machine has different canonical mnemonics,
5694so long as there is no conflict. The @code{info registers} command
5695shows the canonical names. For example, on the SPARC, @code{info
5696registers} displays the processor status register as @code{$psr} but you
d4f3574e
SS
5697can also refer to it as @code{$ps}; and on x86-based machines @code{$ps}
5698is an alias for the @sc{eflags} register.
c906108c
SS
5699
5700@value{GDBN} always considers the contents of an ordinary register as an
5701integer when the register is examined in this way. Some machines have
5702special registers which can hold nothing but floating point; these
5703registers are considered to have floating point values. There is no way
5704to refer to the contents of an ordinary register as floating point value
5705(although you can @emph{print} it as a floating point value with
5706@samp{print/f $@var{regname}}).
5707
5708Some registers have distinct ``raw'' and ``virtual'' data formats. This
5709means that the data format in which the register contents are saved by
5710the operating system is not the same one that your program normally
5711sees. For example, the registers of the 68881 floating point
5712coprocessor are always saved in ``extended'' (raw) format, but all C
5713programs expect to work with ``double'' (virtual) format. In such
5d161b24 5714cases, @value{GDBN} normally works with the virtual format only (the format
c906108c
SS
5715that makes sense for your program), but the @code{info registers} command
5716prints the data in both formats.
5717
5718Normally, register values are relative to the selected stack frame
5719(@pxref{Selection, ,Selecting a frame}). This means that you get the
5720value that the register would contain if all stack frames farther in
5721were exited and their saved registers restored. In order to see the
5722true contents of hardware registers, you must select the innermost
5723frame (with @samp{frame 0}).
5724
5725However, @value{GDBN} must deduce where registers are saved, from the machine
5726code generated by your compiler. If some registers are not saved, or if
5727@value{GDBN} is unable to locate the saved registers, the selected stack
5728frame makes no difference.
5729
6d2ebf8b 5730@node Floating Point Hardware
c906108c
SS
5731@section Floating point hardware
5732@cindex floating point
5733
5734Depending on the configuration, @value{GDBN} may be able to give
5735you more information about the status of the floating point hardware.
5736
5737@table @code
5738@kindex info float
5739@item info float
5740Display hardware-dependent information about the floating
5741point unit. The exact contents and layout vary depending on the
5742floating point chip. Currently, @samp{info float} is supported on
5743the ARM and x86 machines.
5744@end table
c906108c 5745
e76f1f2e
AC
5746@node Vector Unit
5747@section Vector Unit
5748@cindex vector unit
5749
5750Depending on the configuration, @value{GDBN} may be able to give you
5751more information about the status of the vector unit.
5752
5753@table @code
5754@kindex info vector
5755@item info vector
5756Display information about the vector unit. The exact contents and
5757layout vary depending on the hardware.
5758@end table
5759
29e57380 5760@node Memory Region Attributes
16d9dec6 5761@section Memory region attributes
29e57380
C
5762@cindex memory region attributes
5763
5764@dfn{Memory region attributes} allow you to describe special handling
5765required by regions of your target's memory. @value{GDBN} uses attributes
5766to determine whether to allow certain types of memory accesses; whether to
5767use specific width accesses; and whether to cache target memory.
5768
5769Defined memory regions can be individually enabled and disabled. When a
5770memory region is disabled, @value{GDBN} uses the default attributes when
5771accessing memory in that region. Similarly, if no memory regions have
5772been defined, @value{GDBN} uses the default attributes when accessing
5773all memory.
5774
5775When a memory region is defined, it is given a number to identify it;
5776to enable, disable, or remove a memory region, you specify that number.
5777
5778@table @code
5779@kindex mem
bfac230e
DH
5780@item mem @var{lower} @var{upper} @var{attributes}@dots{}
5781Define memory region bounded by @var{lower} and @var{upper} with
5782attributes @var{attributes}@dots{}. Note that @var{upper} == 0 is a
5783special case: it is treated as the the target's maximum memory address.
5784(0xffff on 16 bit targets, 0xffffffff on 32 bit targets, etc.)
29e57380
C
5785
5786@kindex delete mem
5787@item delete mem @var{nums}@dots{}
59649f2e 5788Remove memory regions @var{nums}@dots{}.
29e57380
C
5789
5790@kindex disable mem
5791@item disable mem @var{nums}@dots{}
59649f2e 5792Disable memory regions @var{nums}@dots{}.
29e57380
C
5793A disabled memory region is not forgotten.
5794It may be enabled again later.
5795
5796@kindex enable mem
5797@item enable mem @var{nums}@dots{}
59649f2e 5798Enable memory regions @var{nums}@dots{}.
29e57380
C
5799
5800@kindex info mem
5801@item info mem
5802Print a table of all defined memory regions, with the following columns
5803for each region.
5804
5805@table @emph
5806@item Memory Region Number
5807@item Enabled or Disabled.
5808Enabled memory regions are marked with @samp{y}.
5809Disabled memory regions are marked with @samp{n}.
5810
5811@item Lo Address
5812The address defining the inclusive lower bound of the memory region.
5813
5814@item Hi Address
5815The address defining the exclusive upper bound of the memory region.
5816
5817@item Attributes
5818The list of attributes set for this memory region.
5819@end table
5820@end table
5821
5822
5823@subsection Attributes
5824
5825@subsubsection Memory Access Mode
5826The access mode attributes set whether @value{GDBN} may make read or
5827write accesses to a memory region.
5828
5829While these attributes prevent @value{GDBN} from performing invalid
5830memory accesses, they do nothing to prevent the target system, I/O DMA,
5831etc. from accessing memory.
5832
5833@table @code
5834@item ro
5835Memory is read only.
5836@item wo
5837Memory is write only.
5838@item rw
6ca652b0 5839Memory is read/write. This is the default.
29e57380
C
5840@end table
5841
5842@subsubsection Memory Access Size
5843The acccess size attributes tells @value{GDBN} to use specific sized
5844accesses in the memory region. Often memory mapped device registers
5845require specific sized accesses. If no access size attribute is
5846specified, @value{GDBN} may use accesses of any size.
5847
5848@table @code
5849@item 8
5850Use 8 bit memory accesses.
5851@item 16
5852Use 16 bit memory accesses.
5853@item 32
5854Use 32 bit memory accesses.
5855@item 64
5856Use 64 bit memory accesses.
5857@end table
5858
5859@c @subsubsection Hardware/Software Breakpoints
5860@c The hardware/software breakpoint attributes set whether @value{GDBN}
5861@c will use hardware or software breakpoints for the internal breakpoints
5862@c used by the step, next, finish, until, etc. commands.
5863@c
5864@c @table @code
5865@c @item hwbreak
5866@c Always use hardware breakpoints
5867@c @item swbreak (default)
5868@c @end table
5869
5870@subsubsection Data Cache
5871The data cache attributes set whether @value{GDBN} will cache target
5872memory. While this generally improves performance by reducing debug
5873protocol overhead, it can lead to incorrect results because @value{GDBN}
5874does not know about volatile variables or memory mapped device
5875registers.
5876
5877@table @code
5878@item cache
5879Enable @value{GDBN} to cache target memory.
6ca652b0
EZ
5880@item nocache
5881Disable @value{GDBN} from caching target memory. This is the default.
29e57380
C
5882@end table
5883
5884@c @subsubsection Memory Write Verification
5885@c The memory write verification attributes set whether @value{GDBN}
5886@c will re-reads data after each write to verify the write was successful.
5887@c
5888@c @table @code
5889@c @item verify
5890@c @item noverify (default)
5891@c @end table
5892
16d9dec6
MS
5893@node Dump/Restore Files
5894@section Copy between memory and a file
5895@cindex dump/restore files
5896@cindex append data to a file
5897@cindex dump data to a file
5898@cindex restore data from a file
16d9dec6 5899
df5215a6
JB
5900You can use the commands @code{dump}, @code{append}, and
5901@code{restore} to copy data between target memory and a file. The
5902@code{dump} and @code{append} commands write data to a file, and the
5903@code{restore} command reads data from a file back into the inferior's
5904memory. Files may be in binary, Motorola S-record, Intel hex, or
5905Tektronix Hex format; however, @value{GDBN} can only append to binary
5906files.
5907
5908@table @code
5909
5910@kindex dump
5911@item dump @r{[}@var{format}@r{]} memory @var{filename} @var{start_addr} @var{end_addr}
5912@itemx dump @r{[}@var{format}@r{]} value @var{filename} @var{expr}
5913Dump the contents of memory from @var{start_addr} to @var{end_addr},
5914or the value of @var{expr}, to @var{filename} in the given format.
16d9dec6 5915
df5215a6 5916The @var{format} parameter may be any one of:
16d9dec6 5917@table @code
df5215a6
JB
5918@item binary
5919Raw binary form.
5920@item ihex
5921Intel hex format.
5922@item srec
5923Motorola S-record format.
5924@item tekhex
5925Tektronix Hex format.
5926@end table
5927
5928@value{GDBN} uses the same definitions of these formats as the
5929@sc{gnu} binary utilities, like @samp{objdump} and @samp{objcopy}. If
5930@var{format} is omitted, @value{GDBN} dumps the data in raw binary
5931form.
5932
5933@kindex append
5934@item append @r{[}binary@r{]} memory @var{filename} @var{start_addr} @var{end_addr}
5935@itemx append @r{[}binary@r{]} value @var{filename} @var{expr}
5936Append the contents of memory from @var{start_addr} to @var{end_addr},
5937or the value of @var{expr}, to @var{filename}, in raw binary form.
5938(@value{GDBN} can only append data to files in raw binary form.)
5939
5940@kindex restore
5941@item restore @var{filename} @r{[}binary@r{]} @var{bias} @var{start} @var{end}
5942Restore the contents of file @var{filename} into memory. The
5943@code{restore} command can automatically recognize any known @sc{bfd}
5944file format, except for raw binary. To restore a raw binary file you
5945must specify the optional keyword @code{binary} after the filename.
16d9dec6
MS
5946
5947If @var{bias} is non-zero, its value will be added to the addresses
5948contained in the file. Binary files always start at address zero, so
5949they will be restored at address @var{bias}. Other bfd files have
5950a built-in location; they will be restored at offset @var{bias}
5951from that location.
5952
5953If @var{start} and/or @var{end} are non-zero, then only data between
5954file offset @var{start} and file offset @var{end} will be restored.
5955These offsets are relative to the addresses in the file, before
5956the @var{bias} argument is applied.
5957
5958@end table
5959
a0eb71c5
KB
5960@node Character Sets
5961@section Character Sets
5962@cindex character sets
5963@cindex charset
5964@cindex translating between character sets
5965@cindex host character set
5966@cindex target character set
5967
5968If the program you are debugging uses a different character set to
5969represent characters and strings than the one @value{GDBN} uses itself,
5970@value{GDBN} can automatically translate between the character sets for
5971you. The character set @value{GDBN} uses we call the @dfn{host
5972character set}; the one the inferior program uses we call the
5973@dfn{target character set}.
5974
5975For example, if you are running @value{GDBN} on a @sc{gnu}/Linux system, which
5976uses the ISO Latin 1 character set, but you are using @value{GDBN}'s
5977remote protocol (@pxref{Remote,Remote Debugging}) to debug a program
5978running on an IBM mainframe, which uses the @sc{ebcdic} character set,
5979then the host character set is Latin-1, and the target character set is
5980@sc{ebcdic}. If you give @value{GDBN} the command @code{set
e33d66ec 5981target-charset EBCDIC-US}, then @value{GDBN} translates between
a0eb71c5
KB
5982@sc{ebcdic} and Latin 1 as you print character or string values, or use
5983character and string literals in expressions.
5984
5985@value{GDBN} has no way to automatically recognize which character set
5986the inferior program uses; you must tell it, using the @code{set
5987target-charset} command, described below.
5988
5989Here are the commands for controlling @value{GDBN}'s character set
5990support:
5991
5992@table @code
5993@item set target-charset @var{charset}
5994@kindex set target-charset
5995Set the current target character set to @var{charset}. We list the
e33d66ec
EZ
5996character set names @value{GDBN} recognizes below, but if you type
5997@code{set target-charset} followed by @key{TAB}@key{TAB}, @value{GDBN} will
5998list the target character sets it supports.
a0eb71c5
KB
5999@end table
6000
6001@table @code
6002@item set host-charset @var{charset}
6003@kindex set host-charset
6004Set the current host character set to @var{charset}.
6005
6006By default, @value{GDBN} uses a host character set appropriate to the
6007system it is running on; you can override that default using the
6008@code{set host-charset} command.
6009
6010@value{GDBN} can only use certain character sets as its host character
6011set. We list the character set names @value{GDBN} recognizes below, and
e33d66ec
EZ
6012indicate which can be host character sets, but if you type
6013@code{set target-charset} followed by @key{TAB}@key{TAB}, @value{GDBN} will
6014list the host character sets it supports.
a0eb71c5
KB
6015
6016@item set charset @var{charset}
6017@kindex set charset
e33d66ec
EZ
6018Set the current host and target character sets to @var{charset}. As
6019above, if you type @code{set charset} followed by @key{TAB}@key{TAB},
6020@value{GDBN} will list the name of the character sets that can be used
6021for both host and target.
6022
a0eb71c5
KB
6023
6024@item show charset
a0eb71c5 6025@kindex show charset
e33d66ec
EZ
6026Show the names of the current host and target charsets.
6027
6028@itemx show host-charset
a0eb71c5 6029@kindex show host-charset
e33d66ec
EZ
6030Show the name of the current host charset.
6031
6032@itemx show target-charset
a0eb71c5 6033@kindex show target-charset
e33d66ec 6034Show the name of the current target charset.
a0eb71c5
KB
6035
6036@end table
6037
6038@value{GDBN} currently includes support for the following character
6039sets:
6040
6041@table @code
6042
6043@item ASCII
6044@cindex ASCII character set
6045Seven-bit U.S. @sc{ascii}. @value{GDBN} can use this as its host
6046character set.
6047
6048@item ISO-8859-1
6049@cindex ISO 8859-1 character set
6050@cindex ISO Latin 1 character set
e33d66ec 6051The ISO Latin 1 character set. This extends @sc{ascii} with accented
a0eb71c5
KB
6052characters needed for French, German, and Spanish. @value{GDBN} can use
6053this as its host character set.
6054
6055@item EBCDIC-US
6056@itemx IBM1047
6057@cindex EBCDIC character set
6058@cindex IBM1047 character set
6059Variants of the @sc{ebcdic} character set, used on some of IBM's
6060mainframe operating systems. (@sc{gnu}/Linux on the S/390 uses U.S. @sc{ascii}.)
6061@value{GDBN} cannot use these as its host character set.
6062
6063@end table
6064
6065Note that these are all single-byte character sets. More work inside
6066GDB is needed to support multi-byte or variable-width character
6067encodings, like the UTF-8 and UCS-2 encodings of Unicode.
6068
6069Here is an example of @value{GDBN}'s character set support in action.
6070Assume that the following source code has been placed in the file
6071@file{charset-test.c}:
6072
6073@smallexample
6074#include <stdio.h>
6075
6076char ascii_hello[]
6077 = @{72, 101, 108, 108, 111, 44, 32, 119,
6078 111, 114, 108, 100, 33, 10, 0@};
6079char ibm1047_hello[]
6080 = @{200, 133, 147, 147, 150, 107, 64, 166,
6081 150, 153, 147, 132, 90, 37, 0@};
6082
6083main ()
6084@{
6085 printf ("Hello, world!\n");
6086@}
10998722 6087@end smallexample
a0eb71c5
KB
6088
6089In this program, @code{ascii_hello} and @code{ibm1047_hello} are arrays
6090containing the string @samp{Hello, world!} followed by a newline,
6091encoded in the @sc{ascii} and @sc{ibm1047} character sets.
6092
6093We compile the program, and invoke the debugger on it:
6094
6095@smallexample
6096$ gcc -g charset-test.c -o charset-test
6097$ gdb -nw charset-test
6098GNU gdb 2001-12-19-cvs
6099Copyright 2001 Free Software Foundation, Inc.
6100@dots{}
6101(gdb)
10998722 6102@end smallexample
a0eb71c5
KB
6103
6104We can use the @code{show charset} command to see what character sets
6105@value{GDBN} is currently using to interpret and display characters and
6106strings:
6107
6108@smallexample
6109(gdb) show charset
e33d66ec 6110The current host and target character set is `ISO-8859-1'.
a0eb71c5 6111(gdb)
10998722 6112@end smallexample
a0eb71c5
KB
6113
6114For the sake of printing this manual, let's use @sc{ascii} as our
6115initial character set:
6116@smallexample
e33d66ec 6117(gdb) set charset ASCII
a0eb71c5 6118(gdb) show charset
e33d66ec 6119The current host and target character set is `ASCII'.
a0eb71c5 6120(gdb)
10998722 6121@end smallexample
a0eb71c5
KB
6122
6123Let's assume that @sc{ascii} is indeed the correct character set for our
6124host system --- in other words, let's assume that if @value{GDBN} prints
6125characters using the @sc{ascii} character set, our terminal will display
6126them properly. Since our current target character set is also
6127@sc{ascii}, the contents of @code{ascii_hello} print legibly:
6128
6129@smallexample
6130(gdb) print ascii_hello
6131$1 = 0x401698 "Hello, world!\n"
6132(gdb) print ascii_hello[0]
6133$2 = 72 'H'
6134(gdb)
10998722 6135@end smallexample
a0eb71c5
KB
6136
6137@value{GDBN} uses the target character set for character and string
6138literals you use in expressions:
6139
6140@smallexample
6141(gdb) print '+'
6142$3 = 43 '+'
6143(gdb)
10998722 6144@end smallexample
a0eb71c5
KB
6145
6146The @sc{ascii} character set uses the number 43 to encode the @samp{+}
6147character.
6148
6149@value{GDBN} relies on the user to tell it which character set the
6150target program uses. If we print @code{ibm1047_hello} while our target
6151character set is still @sc{ascii}, we get jibberish:
6152
6153@smallexample
6154(gdb) print ibm1047_hello
6155$4 = 0x4016a8 "\310\205\223\223\226k@@\246\226\231\223\204Z%"
6156(gdb) print ibm1047_hello[0]
6157$5 = 200 '\310'
6158(gdb)
10998722 6159@end smallexample
a0eb71c5 6160
e33d66ec 6161If we invoke the @code{set target-charset} followed by @key{TAB}@key{TAB},
a0eb71c5
KB
6162@value{GDBN} tells us the character sets it supports:
6163
6164@smallexample
6165(gdb) set target-charset
e33d66ec
EZ
6166ASCII EBCDIC-US IBM1047 ISO-8859-1
6167(gdb) set target-charset
10998722 6168@end smallexample
a0eb71c5
KB
6169
6170We can select @sc{ibm1047} as our target character set, and examine the
6171program's strings again. Now the @sc{ascii} string is wrong, but
6172@value{GDBN} translates the contents of @code{ibm1047_hello} from the
6173target character set, @sc{ibm1047}, to the host character set,
6174@sc{ascii}, and they display correctly:
6175
6176@smallexample
e33d66ec 6177(gdb) set target-charset IBM1047
a0eb71c5 6178(gdb) show charset
e33d66ec
EZ
6179The current host character set is `ASCII'.
6180The current target character set is `IBM1047'.
a0eb71c5
KB
6181(gdb) print ascii_hello
6182$6 = 0x401698 "\110\145%%?\054\040\167?\162%\144\041\012"
6183(gdb) print ascii_hello[0]
6184$7 = 72 '\110'
6185(gdb) print ibm1047_hello
6186$8 = 0x4016a8 "Hello, world!\n"
6187(gdb) print ibm1047_hello[0]
6188$9 = 200 'H'
6189(gdb)
10998722 6190@end smallexample
a0eb71c5
KB
6191
6192As above, @value{GDBN} uses the target character set for character and
6193string literals you use in expressions:
6194
6195@smallexample
6196(gdb) print '+'
6197$10 = 78 '+'
6198(gdb)
10998722 6199@end smallexample
a0eb71c5 6200
e33d66ec 6201The @sc{ibm1047} character set uses the number 78 to encode the @samp{+}
a0eb71c5
KB
6202character.
6203
6204
e2e0bcd1
JB
6205@node Macros
6206@chapter C Preprocessor Macros
6207
6208Some languages, such as C and C++, provide a way to define and invoke
6209``preprocessor macros'' which expand into strings of tokens.
6210@value{GDBN} can evaluate expressions containing macro invocations, show
6211the result of macro expansion, and show a macro's definition, including
6212where it was defined.
6213
6214You may need to compile your program specially to provide @value{GDBN}
6215with information about preprocessor macros. Most compilers do not
6216include macros in their debugging information, even when you compile
6217with the @option{-g} flag. @xref{Compilation}.
6218
6219A program may define a macro at one point, remove that definition later,
6220and then provide a different definition after that. Thus, at different
6221points in the program, a macro may have different definitions, or have
6222no definition at all. If there is a current stack frame, @value{GDBN}
6223uses the macros in scope at that frame's source code line. Otherwise,
6224@value{GDBN} uses the macros in scope at the current listing location;
6225see @ref{List}.
6226
6227At the moment, @value{GDBN} does not support the @code{##}
6228token-splicing operator, the @code{#} stringification operator, or
6229variable-arity macros.
6230
6231Whenever @value{GDBN} evaluates an expression, it always expands any
6232macro invocations present in the expression. @value{GDBN} also provides
6233the following commands for working with macros explicitly.
6234
6235@table @code
6236
6237@kindex macro expand
6238@cindex macro expansion, showing the results of preprocessor
6239@cindex preprocessor macro expansion, showing the results of
6240@cindex expanding preprocessor macros
6241@item macro expand @var{expression}
6242@itemx macro exp @var{expression}
6243Show the results of expanding all preprocessor macro invocations in
6244@var{expression}. Since @value{GDBN} simply expands macros, but does
6245not parse the result, @var{expression} need not be a valid expression;
6246it can be any string of tokens.
6247
6248@kindex macro expand-once
6249@item macro expand-once @var{expression}
6250@itemx macro exp1 @var{expression}
6251@i{(This command is not yet implemented.)} Show the results of
6252expanding those preprocessor macro invocations that appear explicitly in
6253@var{expression}. Macro invocations appearing in that expansion are
6254left unchanged. This command allows you to see the effect of a
6255particular macro more clearly, without being confused by further
6256expansions. Since @value{GDBN} simply expands macros, but does not
6257parse the result, @var{expression} need not be a valid expression; it
6258can be any string of tokens.
6259
475b0867 6260@kindex info macro
e2e0bcd1
JB
6261@cindex macro definition, showing
6262@cindex definition, showing a macro's
475b0867 6263@item info macro @var{macro}
e2e0bcd1
JB
6264Show the definition of the macro named @var{macro}, and describe the
6265source location where that definition was established.
6266
6267@kindex macro define
6268@cindex user-defined macros
6269@cindex defining macros interactively
6270@cindex macros, user-defined
6271@item macro define @var{macro} @var{replacement-list}
6272@itemx macro define @var{macro}(@var{arglist}) @var{replacement-list}
6273@i{(This command is not yet implemented.)} Introduce a definition for a
6274preprocessor macro named @var{macro}, invocations of which are replaced
6275by the tokens given in @var{replacement-list}. The first form of this
6276command defines an ``object-like'' macro, which takes no arguments; the
6277second form defines a ``function-like'' macro, which takes the arguments
6278given in @var{arglist}.
6279
6280A definition introduced by this command is in scope in every expression
6281evaluated in @value{GDBN}, until it is removed with the @command{macro
6282undef} command, described below. The definition overrides all
6283definitions for @var{macro} present in the program being debugged, as
6284well as any previous user-supplied definition.
6285
6286@kindex macro undef
6287@item macro undef @var{macro}
6288@i{(This command is not yet implemented.)} Remove any user-supplied
6289definition for the macro named @var{macro}. This command only affects
6290definitions provided with the @command{macro define} command, described
6291above; it cannot remove definitions present in the program being
6292debugged.
6293
6294@end table
6295
6296@cindex macros, example of debugging with
6297Here is a transcript showing the above commands in action. First, we
6298show our source files:
6299
6300@smallexample
6301$ cat sample.c
6302#include <stdio.h>
6303#include "sample.h"
6304
6305#define M 42
6306#define ADD(x) (M + x)
6307
6308main ()
6309@{
6310#define N 28
6311 printf ("Hello, world!\n");
6312#undef N
6313 printf ("We're so creative.\n");
6314#define N 1729
6315 printf ("Goodbye, world!\n");
6316@}
6317$ cat sample.h
6318#define Q <
6319$
6320@end smallexample
6321
6322Now, we compile the program using the @sc{gnu} C compiler, @value{NGCC}.
6323We pass the @option{-gdwarf-2} and @option{-g3} flags to ensure the
6324compiler includes information about preprocessor macros in the debugging
6325information.
6326
6327@smallexample
6328$ gcc -gdwarf-2 -g3 sample.c -o sample
6329$
6330@end smallexample
6331
6332Now, we start @value{GDBN} on our sample program:
6333
6334@smallexample
6335$ gdb -nw sample
6336GNU gdb 2002-05-06-cvs
6337Copyright 2002 Free Software Foundation, Inc.
6338GDB is free software, @dots{}
6339(gdb)
6340@end smallexample
6341
6342We can expand macros and examine their definitions, even when the
6343program is not running. @value{GDBN} uses the current listing position
6344to decide which macro definitions are in scope:
6345
6346@smallexample
6347(gdb) list main
63483
63494 #define M 42
63505 #define ADD(x) (M + x)
63516
63527 main ()
63538 @{
63549 #define N 28
635510 printf ("Hello, world!\n");
635611 #undef N
635712 printf ("We're so creative.\n");
475b0867 6358(gdb) info macro ADD
e2e0bcd1
JB
6359Defined at /home/jimb/gdb/macros/play/sample.c:5
6360#define ADD(x) (M + x)
475b0867 6361(gdb) info macro Q
e2e0bcd1
JB
6362Defined at /home/jimb/gdb/macros/play/sample.h:1
6363 included at /home/jimb/gdb/macros/play/sample.c:2
6364#define Q <
6365(gdb) macro expand ADD(1)
6366expands to: (42 + 1)
6367(gdb) macro expand-once ADD(1)
6368expands to: once (M + 1)
6369(gdb)
6370@end smallexample
6371
6372In the example above, note that @command{macro expand-once} expands only
6373the macro invocation explicit in the original text --- the invocation of
6374@code{ADD} --- but does not expand the invocation of the macro @code{M},
6375which was introduced by @code{ADD}.
6376
6377Once the program is running, GDB uses the macro definitions in force at
6378the source line of the current stack frame:
6379
6380@smallexample
6381(gdb) break main
6382Breakpoint 1 at 0x8048370: file sample.c, line 10.
6383(gdb) run
6384Starting program: /home/jimb/gdb/macros/play/sample
6385
6386Breakpoint 1, main () at sample.c:10
638710 printf ("Hello, world!\n");
6388(gdb)
6389@end smallexample
6390
6391At line 10, the definition of the macro @code{N} at line 9 is in force:
6392
6393@smallexample
475b0867 6394(gdb) info macro N
e2e0bcd1
JB
6395Defined at /home/jimb/gdb/macros/play/sample.c:9
6396#define N 28
6397(gdb) macro expand N Q M
6398expands to: 28 < 42
6399(gdb) print N Q M
6400$1 = 1
6401(gdb)
6402@end smallexample
6403
6404As we step over directives that remove @code{N}'s definition, and then
6405give it a new definition, @value{GDBN} finds the definition (or lack
6406thereof) in force at each point:
6407
6408@smallexample
6409(gdb) next
6410Hello, world!
641112 printf ("We're so creative.\n");
475b0867 6412(gdb) info macro N
e2e0bcd1
JB
6413The symbol `N' has no definition as a C/C++ preprocessor macro
6414at /home/jimb/gdb/macros/play/sample.c:12
6415(gdb) next
6416We're so creative.
641714 printf ("Goodbye, world!\n");
475b0867 6418(gdb) info macro N
e2e0bcd1
JB
6419Defined at /home/jimb/gdb/macros/play/sample.c:13
6420#define N 1729
6421(gdb) macro expand N Q M
6422expands to: 1729 < 42
6423(gdb) print N Q M
6424$2 = 0
6425(gdb)
6426@end smallexample
6427
6428
b37052ae
EZ
6429@node Tracepoints
6430@chapter Tracepoints
6431@c This chapter is based on the documentation written by Michael
6432@c Snyder, David Taylor, Jim Blandy, and Elena Zannoni.
6433
6434@cindex tracepoints
6435In some applications, it is not feasible for the debugger to interrupt
6436the program's execution long enough for the developer to learn
6437anything helpful about its behavior. If the program's correctness
6438depends on its real-time behavior, delays introduced by a debugger
6439might cause the program to change its behavior drastically, or perhaps
6440fail, even when the code itself is correct. It is useful to be able
6441to observe the program's behavior without interrupting it.
6442
6443Using @value{GDBN}'s @code{trace} and @code{collect} commands, you can
6444specify locations in the program, called @dfn{tracepoints}, and
6445arbitrary expressions to evaluate when those tracepoints are reached.
6446Later, using the @code{tfind} command, you can examine the values
6447those expressions had when the program hit the tracepoints. The
6448expressions may also denote objects in memory---structures or arrays,
6449for example---whose values @value{GDBN} should record; while visiting
6450a particular tracepoint, you may inspect those objects as if they were
6451in memory at that moment. However, because @value{GDBN} records these
6452values without interacting with you, it can do so quickly and
6453unobtrusively, hopefully not disturbing the program's behavior.
6454
6455The tracepoint facility is currently available only for remote
2c0069bb
EZ
6456targets. @xref{Targets}. In addition, your remote target must know how
6457to collect trace data. This functionality is implemented in the remote
6458stub; however, none of the stubs distributed with @value{GDBN} support
6459tracepoints as of this writing.
b37052ae
EZ
6460
6461This chapter describes the tracepoint commands and features.
6462
6463@menu
6464* Set Tracepoints::
6465* Analyze Collected Data::
6466* Tracepoint Variables::
6467@end menu
6468
6469@node Set Tracepoints
6470@section Commands to Set Tracepoints
6471
6472Before running such a @dfn{trace experiment}, an arbitrary number of
6473tracepoints can be set. Like a breakpoint (@pxref{Set Breaks}), a
6474tracepoint has a number assigned to it by @value{GDBN}. Like with
6475breakpoints, tracepoint numbers are successive integers starting from
6476one. Many of the commands associated with tracepoints take the
6477tracepoint number as their argument, to identify which tracepoint to
6478work on.
6479
6480For each tracepoint, you can specify, in advance, some arbitrary set
6481of data that you want the target to collect in the trace buffer when
6482it hits that tracepoint. The collected data can include registers,
6483local variables, or global data. Later, you can use @value{GDBN}
6484commands to examine the values these data had at the time the
6485tracepoint was hit.
6486
6487This section describes commands to set tracepoints and associated
6488conditions and actions.
6489
6490@menu
6491* Create and Delete Tracepoints::
6492* Enable and Disable Tracepoints::
6493* Tracepoint Passcounts::
6494* Tracepoint Actions::
6495* Listing Tracepoints::
6496* Starting and Stopping Trace Experiment::
6497@end menu
6498
6499@node Create and Delete Tracepoints
6500@subsection Create and Delete Tracepoints
6501
6502@table @code
6503@cindex set tracepoint
6504@kindex trace
6505@item trace
6506The @code{trace} command is very similar to the @code{break} command.
6507Its argument can be a source line, a function name, or an address in
6508the target program. @xref{Set Breaks}. The @code{trace} command
6509defines a tracepoint, which is a point in the target program where the
6510debugger will briefly stop, collect some data, and then allow the
6511program to continue. Setting a tracepoint or changing its commands
6512doesn't take effect until the next @code{tstart} command; thus, you
6513cannot change the tracepoint attributes once a trace experiment is
6514running.
6515
6516Here are some examples of using the @code{trace} command:
6517
6518@smallexample
6519(@value{GDBP}) @b{trace foo.c:121} // a source file and line number
6520
6521(@value{GDBP}) @b{trace +2} // 2 lines forward
6522
6523(@value{GDBP}) @b{trace my_function} // first source line of function
6524
6525(@value{GDBP}) @b{trace *my_function} // EXACT start address of function
6526
6527(@value{GDBP}) @b{trace *0x2117c4} // an address
6528@end smallexample
6529
6530@noindent
6531You can abbreviate @code{trace} as @code{tr}.
6532
6533@vindex $tpnum
6534@cindex last tracepoint number
6535@cindex recent tracepoint number
6536@cindex tracepoint number
6537The convenience variable @code{$tpnum} records the tracepoint number
6538of the most recently set tracepoint.
6539
6540@kindex delete tracepoint
6541@cindex tracepoint deletion
6542@item delete tracepoint @r{[}@var{num}@r{]}
6543Permanently delete one or more tracepoints. With no argument, the
6544default is to delete all tracepoints.
6545
6546Examples:
6547
6548@smallexample
6549(@value{GDBP}) @b{delete trace 1 2 3} // remove three tracepoints
6550
6551(@value{GDBP}) @b{delete trace} // remove all tracepoints
6552@end smallexample
6553
6554@noindent
6555You can abbreviate this command as @code{del tr}.
6556@end table
6557
6558@node Enable and Disable Tracepoints
6559@subsection Enable and Disable Tracepoints
6560
6561@table @code
6562@kindex disable tracepoint
6563@item disable tracepoint @r{[}@var{num}@r{]}
6564Disable tracepoint @var{num}, or all tracepoints if no argument
6565@var{num} is given. A disabled tracepoint will have no effect during
6566the next trace experiment, but it is not forgotten. You can re-enable
6567a disabled tracepoint using the @code{enable tracepoint} command.
6568
6569@kindex enable tracepoint
6570@item enable tracepoint @r{[}@var{num}@r{]}
6571Enable tracepoint @var{num}, or all tracepoints. The enabled
6572tracepoints will become effective the next time a trace experiment is
6573run.
6574@end table
6575
6576@node Tracepoint Passcounts
6577@subsection Tracepoint Passcounts
6578
6579@table @code
6580@kindex passcount
6581@cindex tracepoint pass count
6582@item passcount @r{[}@var{n} @r{[}@var{num}@r{]]}
6583Set the @dfn{passcount} of a tracepoint. The passcount is a way to
6584automatically stop a trace experiment. If a tracepoint's passcount is
6585@var{n}, then the trace experiment will be automatically stopped on
6586the @var{n}'th time that tracepoint is hit. If the tracepoint number
6587@var{num} is not specified, the @code{passcount} command sets the
6588passcount of the most recently defined tracepoint. If no passcount is
6589given, the trace experiment will run until stopped explicitly by the
6590user.
6591
6592Examples:
6593
6594@smallexample
6826cf00
EZ
6595(@value{GDBP}) @b{passcount 5 2} // Stop on the 5th execution of
6596@exdent @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @code{// tracepoint 2}
b37052ae
EZ
6597
6598(@value{GDBP}) @b{passcount 12} // Stop on the 12th execution of the
6826cf00 6599@exdent @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @code{// most recently defined tracepoint.}
b37052ae
EZ
6600(@value{GDBP}) @b{trace foo}
6601(@value{GDBP}) @b{pass 3}
6602(@value{GDBP}) @b{trace bar}
6603(@value{GDBP}) @b{pass 2}
6604(@value{GDBP}) @b{trace baz}
6605(@value{GDBP}) @b{pass 1} // Stop tracing when foo has been
6826cf00
EZ
6606@exdent @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @code{// executed 3 times OR when bar has}
6607@exdent @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @code{// been executed 2 times}
6608@exdent @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @code{// OR when baz has been executed 1 time.}
b37052ae
EZ
6609@end smallexample
6610@end table
6611
6612@node Tracepoint Actions
6613@subsection Tracepoint Action Lists
6614
6615@table @code
6616@kindex actions
6617@cindex tracepoint actions
6618@item actions @r{[}@var{num}@r{]}
6619This command will prompt for a list of actions to be taken when the
6620tracepoint is hit. If the tracepoint number @var{num} is not
6621specified, this command sets the actions for the one that was most
6622recently defined (so that you can define a tracepoint and then say
6623@code{actions} without bothering about its number). You specify the
6624actions themselves on the following lines, one action at a time, and
6625terminate the actions list with a line containing just @code{end}. So
6626far, the only defined actions are @code{collect} and
6627@code{while-stepping}.
6628
6629@cindex remove actions from a tracepoint
6630To remove all actions from a tracepoint, type @samp{actions @var{num}}
6631and follow it immediately with @samp{end}.
6632
6633@smallexample
6634(@value{GDBP}) @b{collect @var{data}} // collect some data
6635
6826cf00 6636(@value{GDBP}) @b{while-stepping 5} // single-step 5 times, collect data
b37052ae 6637
6826cf00 6638(@value{GDBP}) @b{end} // signals the end of actions.
b37052ae
EZ
6639@end smallexample
6640
6641In the following example, the action list begins with @code{collect}
6642commands indicating the things to be collected when the tracepoint is
6643hit. Then, in order to single-step and collect additional data
6644following the tracepoint, a @code{while-stepping} command is used,
6645followed by the list of things to be collected while stepping. The
6646@code{while-stepping} command is terminated by its own separate
6647@code{end} command. Lastly, the action list is terminated by an
6648@code{end} command.
6649
6650@smallexample
6651(@value{GDBP}) @b{trace foo}
6652(@value{GDBP}) @b{actions}
6653Enter actions for tracepoint 1, one per line:
6654> collect bar,baz
6655> collect $regs
6656> while-stepping 12
6657 > collect $fp, $sp
6658 > end
6659end
6660@end smallexample
6661
6662@kindex collect @r{(tracepoints)}
6663@item collect @var{expr1}, @var{expr2}, @dots{}
6664Collect values of the given expressions when the tracepoint is hit.
6665This command accepts a comma-separated list of any valid expressions.
6666In addition to global, static, or local variables, the following
6667special arguments are supported:
6668
6669@table @code
6670@item $regs
6671collect all registers
6672
6673@item $args
6674collect all function arguments
6675
6676@item $locals
6677collect all local variables.
6678@end table
6679
6680You can give several consecutive @code{collect} commands, each one
6681with a single argument, or one @code{collect} command with several
6682arguments separated by commas: the effect is the same.
6683
f5c37c66
EZ
6684The command @code{info scope} (@pxref{Symbols, info scope}) is
6685particularly useful for figuring out what data to collect.
6686
b37052ae
EZ
6687@kindex while-stepping @r{(tracepoints)}
6688@item while-stepping @var{n}
6689Perform @var{n} single-step traces after the tracepoint, collecting
6690new data at each step. The @code{while-stepping} command is
6691followed by the list of what to collect while stepping (followed by
6692its own @code{end} command):
6693
6694@smallexample
6695> while-stepping 12
6696 > collect $regs, myglobal
6697 > end
6698>
6699@end smallexample
6700
6701@noindent
6702You may abbreviate @code{while-stepping} as @code{ws} or
6703@code{stepping}.
6704@end table
6705
6706@node Listing Tracepoints
6707@subsection Listing Tracepoints
6708
6709@table @code
6710@kindex info tracepoints
6711@cindex information about tracepoints
6712@item info tracepoints @r{[}@var{num}@r{]}
8a037dd7 6713Display information about the tracepoint @var{num}. If you don't specify
798c8bc6 6714a tracepoint number, displays information about all the tracepoints
b37052ae
EZ
6715defined so far. For each tracepoint, the following information is
6716shown:
6717
6718@itemize @bullet
6719@item
6720its number
6721@item
6722whether it is enabled or disabled
6723@item
6724its address
6725@item
6726its passcount as given by the @code{passcount @var{n}} command
6727@item
6728its step count as given by the @code{while-stepping @var{n}} command
6729@item
6730where in the source files is the tracepoint set
6731@item
6732its action list as given by the @code{actions} command
6733@end itemize
6734
6735@smallexample
6736(@value{GDBP}) @b{info trace}
6737Num Enb Address PassC StepC What
67381 y 0x002117c4 0 0 <gdb_asm>
6826cf00
EZ
67392 y 0x0020dc64 0 0 in g_test at g_test.c:1375
67403 y 0x0020b1f4 0 0 in get_data at ../foo.c:41
b37052ae
EZ
6741(@value{GDBP})
6742@end smallexample
6743
6744@noindent
6745This command can be abbreviated @code{info tp}.
6746@end table
6747
6748@node Starting and Stopping Trace Experiment
6749@subsection Starting and Stopping Trace Experiment
6750
6751@table @code
6752@kindex tstart
6753@cindex start a new trace experiment
6754@cindex collected data discarded
6755@item tstart
6756This command takes no arguments. It starts the trace experiment, and
6757begins collecting data. This has the side effect of discarding all
6758the data collected in the trace buffer during the previous trace
6759experiment.
6760
6761@kindex tstop
6762@cindex stop a running trace experiment
6763@item tstop
6764This command takes no arguments. It ends the trace experiment, and
6765stops collecting data.
6766
6767@strong{Note:} a trace experiment and data collection may stop
6768automatically if any tracepoint's passcount is reached
6769(@pxref{Tracepoint Passcounts}), or if the trace buffer becomes full.
6770
6771@kindex tstatus
6772@cindex status of trace data collection
6773@cindex trace experiment, status of
6774@item tstatus
6775This command displays the status of the current trace data
6776collection.
6777@end table
6778
6779Here is an example of the commands we described so far:
6780
6781@smallexample
6782(@value{GDBP}) @b{trace gdb_c_test}
6783(@value{GDBP}) @b{actions}
6784Enter actions for tracepoint #1, one per line.
6785> collect $regs,$locals,$args
6786> while-stepping 11
6787 > collect $regs
6788 > end
6789> end
6790(@value{GDBP}) @b{tstart}
6791 [time passes @dots{}]
6792(@value{GDBP}) @b{tstop}
6793@end smallexample
6794
6795
6796@node Analyze Collected Data
6797@section Using the collected data
6798
6799After the tracepoint experiment ends, you use @value{GDBN} commands
6800for examining the trace data. The basic idea is that each tracepoint
6801collects a trace @dfn{snapshot} every time it is hit and another
6802snapshot every time it single-steps. All these snapshots are
6803consecutively numbered from zero and go into a buffer, and you can
6804examine them later. The way you examine them is to @dfn{focus} on a
6805specific trace snapshot. When the remote stub is focused on a trace
6806snapshot, it will respond to all @value{GDBN} requests for memory and
6807registers by reading from the buffer which belongs to that snapshot,
6808rather than from @emph{real} memory or registers of the program being
6809debugged. This means that @strong{all} @value{GDBN} commands
6810(@code{print}, @code{info registers}, @code{backtrace}, etc.) will
6811behave as if we were currently debugging the program state as it was
6812when the tracepoint occurred. Any requests for data that are not in
6813the buffer will fail.
6814
6815@menu
6816* tfind:: How to select a trace snapshot
6817* tdump:: How to display all data for a snapshot
6818* save-tracepoints:: How to save tracepoints for a future run
6819@end menu
6820
6821@node tfind
6822@subsection @code{tfind @var{n}}
6823
6824@kindex tfind
6825@cindex select trace snapshot
6826@cindex find trace snapshot
6827The basic command for selecting a trace snapshot from the buffer is
6828@code{tfind @var{n}}, which finds trace snapshot number @var{n},
6829counting from zero. If no argument @var{n} is given, the next
6830snapshot is selected.
6831
6832Here are the various forms of using the @code{tfind} command.
6833
6834@table @code
6835@item tfind start
6836Find the first snapshot in the buffer. This is a synonym for
6837@code{tfind 0} (since 0 is the number of the first snapshot).
6838
6839@item tfind none
6840Stop debugging trace snapshots, resume @emph{live} debugging.
6841
6842@item tfind end
6843Same as @samp{tfind none}.
6844
6845@item tfind
6846No argument means find the next trace snapshot.
6847
6848@item tfind -
6849Find the previous trace snapshot before the current one. This permits
6850retracing earlier steps.
6851
6852@item tfind tracepoint @var{num}
6853Find the next snapshot associated with tracepoint @var{num}. Search
6854proceeds forward from the last examined trace snapshot. If no
6855argument @var{num} is given, it means find the next snapshot collected
6856for the same tracepoint as the current snapshot.
6857
6858@item tfind pc @var{addr}
6859Find the next snapshot associated with the value @var{addr} of the
6860program counter. Search proceeds forward from the last examined trace
6861snapshot. If no argument @var{addr} is given, it means find the next
6862snapshot with the same value of PC as the current snapshot.
6863
6864@item tfind outside @var{addr1}, @var{addr2}
6865Find the next snapshot whose PC is outside the given range of
6866addresses.
6867
6868@item tfind range @var{addr1}, @var{addr2}
6869Find the next snapshot whose PC is between @var{addr1} and
6870@var{addr2}. @c FIXME: Is the range inclusive or exclusive?
6871
6872@item tfind line @r{[}@var{file}:@r{]}@var{n}
6873Find the next snapshot associated with the source line @var{n}. If
6874the optional argument @var{file} is given, refer to line @var{n} in
6875that source file. Search proceeds forward from the last examined
6876trace snapshot. If no argument @var{n} is given, it means find the
6877next line other than the one currently being examined; thus saying
6878@code{tfind line} repeatedly can appear to have the same effect as
6879stepping from line to line in a @emph{live} debugging session.
6880@end table
6881
6882The default arguments for the @code{tfind} commands are specifically
6883designed to make it easy to scan through the trace buffer. For
6884instance, @code{tfind} with no argument selects the next trace
6885snapshot, and @code{tfind -} with no argument selects the previous
6886trace snapshot. So, by giving one @code{tfind} command, and then
6887simply hitting @key{RET} repeatedly you can examine all the trace
6888snapshots in order. Or, by saying @code{tfind -} and then hitting
6889@key{RET} repeatedly you can examine the snapshots in reverse order.
6890The @code{tfind line} command with no argument selects the snapshot
6891for the next source line executed. The @code{tfind pc} command with
6892no argument selects the next snapshot with the same program counter
6893(PC) as the current frame. The @code{tfind tracepoint} command with
6894no argument selects the next trace snapshot collected by the same
6895tracepoint as the current one.
6896
6897In addition to letting you scan through the trace buffer manually,
6898these commands make it easy to construct @value{GDBN} scripts that
6899scan through the trace buffer and print out whatever collected data
6900you are interested in. Thus, if we want to examine the PC, FP, and SP
6901registers from each trace frame in the buffer, we can say this:
6902
6903@smallexample
6904(@value{GDBP}) @b{tfind start}
6905(@value{GDBP}) @b{while ($trace_frame != -1)}
6906> printf "Frame %d, PC = %08X, SP = %08X, FP = %08X\n", \
6907 $trace_frame, $pc, $sp, $fp
6908> tfind
6909> end
6910
6911Frame 0, PC = 0020DC64, SP = 0030BF3C, FP = 0030BF44
6912Frame 1, PC = 0020DC6C, SP = 0030BF38, FP = 0030BF44
6913Frame 2, PC = 0020DC70, SP = 0030BF34, FP = 0030BF44
6914Frame 3, PC = 0020DC74, SP = 0030BF30, FP = 0030BF44
6915Frame 4, PC = 0020DC78, SP = 0030BF2C, FP = 0030BF44
6916Frame 5, PC = 0020DC7C, SP = 0030BF28, FP = 0030BF44
6917Frame 6, PC = 0020DC80, SP = 0030BF24, FP = 0030BF44
6918Frame 7, PC = 0020DC84, SP = 0030BF20, FP = 0030BF44
6919Frame 8, PC = 0020DC88, SP = 0030BF1C, FP = 0030BF44
6920Frame 9, PC = 0020DC8E, SP = 0030BF18, FP = 0030BF44
6921Frame 10, PC = 00203F6C, SP = 0030BE3C, FP = 0030BF14
6922@end smallexample
6923
6924Or, if we want to examine the variable @code{X} at each source line in
6925the buffer:
6926
6927@smallexample
6928(@value{GDBP}) @b{tfind start}
6929(@value{GDBP}) @b{while ($trace_frame != -1)}
6930> printf "Frame %d, X == %d\n", $trace_frame, X
6931> tfind line
6932> end
6933
6934Frame 0, X = 1
6935Frame 7, X = 2
6936Frame 13, X = 255
6937@end smallexample
6938
6939@node tdump
6940@subsection @code{tdump}
6941@kindex tdump
6942@cindex dump all data collected at tracepoint
6943@cindex tracepoint data, display
6944
6945This command takes no arguments. It prints all the data collected at
6946the current trace snapshot.
6947
6948@smallexample
6949(@value{GDBP}) @b{trace 444}
6950(@value{GDBP}) @b{actions}
6951Enter actions for tracepoint #2, one per line:
6952> collect $regs, $locals, $args, gdb_long_test
6953> end
6954
6955(@value{GDBP}) @b{tstart}
6956
6957(@value{GDBP}) @b{tfind line 444}
6958#0 gdb_test (p1=0x11, p2=0x22, p3=0x33, p4=0x44, p5=0x55, p6=0x66)
6959at gdb_test.c:444
6960444 printp( "%s: arguments = 0x%X 0x%X 0x%X 0x%X 0x%X 0x%X\n", )
6961
6962(@value{GDBP}) @b{tdump}
6963Data collected at tracepoint 2, trace frame 1:
6964d0 0xc4aa0085 -995491707
6965d1 0x18 24
6966d2 0x80 128
6967d3 0x33 51
6968d4 0x71aea3d 119204413
6969d5 0x22 34
6970d6 0xe0 224
6971d7 0x380035 3670069
6972a0 0x19e24a 1696330
6973a1 0x3000668 50333288
6974a2 0x100 256
6975a3 0x322000 3284992
6976a4 0x3000698 50333336
6977a5 0x1ad3cc 1758156
6978fp 0x30bf3c 0x30bf3c
6979sp 0x30bf34 0x30bf34
6980ps 0x0 0
6981pc 0x20b2c8 0x20b2c8
6982fpcontrol 0x0 0
6983fpstatus 0x0 0
6984fpiaddr 0x0 0
6985p = 0x20e5b4 "gdb-test"
6986p1 = (void *) 0x11
6987p2 = (void *) 0x22
6988p3 = (void *) 0x33
6989p4 = (void *) 0x44
6990p5 = (void *) 0x55
6991p6 = (void *) 0x66
6992gdb_long_test = 17 '\021'
6993
6994(@value{GDBP})
6995@end smallexample
6996
6997@node save-tracepoints
6998@subsection @code{save-tracepoints @var{filename}}
6999@kindex save-tracepoints
7000@cindex save tracepoints for future sessions
7001
7002This command saves all current tracepoint definitions together with
7003their actions and passcounts, into a file @file{@var{filename}}
7004suitable for use in a later debugging session. To read the saved
7005tracepoint definitions, use the @code{source} command (@pxref{Command
7006Files}).
7007
7008@node Tracepoint Variables
7009@section Convenience Variables for Tracepoints
7010@cindex tracepoint variables
7011@cindex convenience variables for tracepoints
7012
7013@table @code
7014@vindex $trace_frame
7015@item (int) $trace_frame
7016The current trace snapshot (a.k.a.@: @dfn{frame}) number, or -1 if no
7017snapshot is selected.
7018
7019@vindex $tracepoint
7020@item (int) $tracepoint
7021The tracepoint for the current trace snapshot.
7022
7023@vindex $trace_line
7024@item (int) $trace_line
7025The line number for the current trace snapshot.
7026
7027@vindex $trace_file
7028@item (char []) $trace_file
7029The source file for the current trace snapshot.
7030
7031@vindex $trace_func
7032@item (char []) $trace_func
7033The name of the function containing @code{$tracepoint}.
7034@end table
7035
7036Note: @code{$trace_file} is not suitable for use in @code{printf},
7037use @code{output} instead.
7038
7039Here's a simple example of using these convenience variables for
7040stepping through all the trace snapshots and printing some of their
7041data.
7042
7043@smallexample
7044(@value{GDBP}) @b{tfind start}
7045
7046(@value{GDBP}) @b{while $trace_frame != -1}
7047> output $trace_file
7048> printf ", line %d (tracepoint #%d)\n", $trace_line, $tracepoint
7049> tfind
7050> end
7051@end smallexample
7052
df0cd8c5
JB
7053@node Overlays
7054@chapter Debugging Programs That Use Overlays
7055@cindex overlays
7056
7057If your program is too large to fit completely in your target system's
7058memory, you can sometimes use @dfn{overlays} to work around this
7059problem. @value{GDBN} provides some support for debugging programs that
7060use overlays.
7061
7062@menu
7063* How Overlays Work:: A general explanation of overlays.
7064* Overlay Commands:: Managing overlays in @value{GDBN}.
7065* Automatic Overlay Debugging:: @value{GDBN} can find out which overlays are
7066 mapped by asking the inferior.
7067* Overlay Sample Program:: A sample program using overlays.
7068@end menu
7069
7070@node How Overlays Work
7071@section How Overlays Work
7072@cindex mapped overlays
7073@cindex unmapped overlays
7074@cindex load address, overlay's
7075@cindex mapped address
7076@cindex overlay area
7077
7078Suppose you have a computer whose instruction address space is only 64
7079kilobytes long, but which has much more memory which can be accessed by
7080other means: special instructions, segment registers, or memory
7081management hardware, for example. Suppose further that you want to
7082adapt a program which is larger than 64 kilobytes to run on this system.
7083
7084One solution is to identify modules of your program which are relatively
7085independent, and need not call each other directly; call these modules
7086@dfn{overlays}. Separate the overlays from the main program, and place
7087their machine code in the larger memory. Place your main program in
7088instruction memory, but leave at least enough space there to hold the
7089largest overlay as well.
7090
7091Now, to call a function located in an overlay, you must first copy that
7092overlay's machine code from the large memory into the space set aside
7093for it in the instruction memory, and then jump to its entry point
7094there.
7095
c928edc0
AC
7096@c NB: In the below the mapped area's size is greater or equal to the
7097@c size of all overlays. This is intentional to remind the developer
7098@c that overlays don't necessarily need to be the same size.
7099
474c8240 7100@smallexample
df0cd8c5 7101@group
c928edc0
AC
7102 Data Instruction Larger
7103Address Space Address Space Address Space
7104+-----------+ +-----------+ +-----------+
7105| | | | | |
7106+-----------+ +-----------+ +-----------+<-- overlay 1
7107| program | | main | .----| overlay 1 | load address
7108| variables | | program | | +-----------+
7109| and heap | | | | | |
7110+-----------+ | | | +-----------+<-- overlay 2
7111| | +-----------+ | | | load address
7112+-----------+ | | | .-| overlay 2 |
7113 | | | | | |
7114 mapped --->+-----------+ | | +-----------+
7115 address | | | | | |
7116 | overlay | <-' | | |
7117 | area | <---' +-----------+<-- overlay 3
7118 | | <---. | | load address
7119 +-----------+ `--| overlay 3 |
7120 | | | |
7121 +-----------+ | |
7122 +-----------+
7123 | |
7124 +-----------+
7125
7126 @anchor{A code overlay}A code overlay
df0cd8c5 7127@end group
474c8240 7128@end smallexample
df0cd8c5 7129
c928edc0
AC
7130The diagram (@pxref{A code overlay}) shows a system with separate data
7131and instruction address spaces. To map an overlay, the program copies
7132its code from the larger address space to the instruction address space.
7133Since the overlays shown here all use the same mapped address, only one
7134may be mapped at a time. For a system with a single address space for
7135data and instructions, the diagram would be similar, except that the
7136program variables and heap would share an address space with the main
7137program and the overlay area.
df0cd8c5
JB
7138
7139An overlay loaded into instruction memory and ready for use is called a
7140@dfn{mapped} overlay; its @dfn{mapped address} is its address in the
7141instruction memory. An overlay not present (or only partially present)
7142in instruction memory is called @dfn{unmapped}; its @dfn{load address}
7143is its address in the larger memory. The mapped address is also called
7144the @dfn{virtual memory address}, or @dfn{VMA}; the load address is also
7145called the @dfn{load memory address}, or @dfn{LMA}.
7146
7147Unfortunately, overlays are not a completely transparent way to adapt a
7148program to limited instruction memory. They introduce a new set of
7149global constraints you must keep in mind as you design your program:
7150
7151@itemize @bullet
7152
7153@item
7154Before calling or returning to a function in an overlay, your program
7155must make sure that overlay is actually mapped. Otherwise, the call or
7156return will transfer control to the right address, but in the wrong
7157overlay, and your program will probably crash.
7158
7159@item
7160If the process of mapping an overlay is expensive on your system, you
7161will need to choose your overlays carefully to minimize their effect on
7162your program's performance.
7163
7164@item
7165The executable file you load onto your system must contain each
7166overlay's instructions, appearing at the overlay's load address, not its
7167mapped address. However, each overlay's instructions must be relocated
7168and its symbols defined as if the overlay were at its mapped address.
7169You can use GNU linker scripts to specify different load and relocation
7170addresses for pieces of your program; see @ref{Overlay Description,,,
7171ld.info, Using ld: the GNU linker}.
7172
7173@item
7174The procedure for loading executable files onto your system must be able
7175to load their contents into the larger address space as well as the
7176instruction and data spaces.
7177
7178@end itemize
7179
7180The overlay system described above is rather simple, and could be
7181improved in many ways:
7182
7183@itemize @bullet
7184
7185@item
7186If your system has suitable bank switch registers or memory management
7187hardware, you could use those facilities to make an overlay's load area
7188contents simply appear at their mapped address in instruction space.
7189This would probably be faster than copying the overlay to its mapped
7190area in the usual way.
7191
7192@item
7193If your overlays are small enough, you could set aside more than one
7194overlay area, and have more than one overlay mapped at a time.
7195
7196@item
7197You can use overlays to manage data, as well as instructions. In
7198general, data overlays are even less transparent to your design than
7199code overlays: whereas code overlays only require care when you call or
7200return to functions, data overlays require care every time you access
7201the data. Also, if you change the contents of a data overlay, you
7202must copy its contents back out to its load address before you can copy a
7203different data overlay into the same mapped area.
7204
7205@end itemize
7206
7207
7208@node Overlay Commands
7209@section Overlay Commands
7210
7211To use @value{GDBN}'s overlay support, each overlay in your program must
7212correspond to a separate section of the executable file. The section's
7213virtual memory address and load memory address must be the overlay's
7214mapped and load addresses. Identifying overlays with sections allows
7215@value{GDBN} to determine the appropriate address of a function or
7216variable, depending on whether the overlay is mapped or not.
7217
7218@value{GDBN}'s overlay commands all start with the word @code{overlay};
7219you can abbreviate this as @code{ov} or @code{ovly}. The commands are:
7220
7221@table @code
7222@item overlay off
7223@kindex overlay off
7224Disable @value{GDBN}'s overlay support. When overlay support is
7225disabled, @value{GDBN} assumes that all functions and variables are
7226always present at their mapped addresses. By default, @value{GDBN}'s
7227overlay support is disabled.
7228
7229@item overlay manual
7230@kindex overlay manual
7231@cindex manual overlay debugging
7232Enable @dfn{manual} overlay debugging. In this mode, @value{GDBN}
7233relies on you to tell it which overlays are mapped, and which are not,
7234using the @code{overlay map-overlay} and @code{overlay unmap-overlay}
7235commands described below.
7236
7237@item overlay map-overlay @var{overlay}
7238@itemx overlay map @var{overlay}
7239@kindex overlay map-overlay
7240@cindex map an overlay
7241Tell @value{GDBN} that @var{overlay} is now mapped; @var{overlay} must
7242be the name of the object file section containing the overlay. When an
7243overlay is mapped, @value{GDBN} assumes it can find the overlay's
7244functions and variables at their mapped addresses. @value{GDBN} assumes
7245that any other overlays whose mapped ranges overlap that of
7246@var{overlay} are now unmapped.
7247
7248@item overlay unmap-overlay @var{overlay}
7249@itemx overlay unmap @var{overlay}
7250@kindex overlay unmap-overlay
7251@cindex unmap an overlay
7252Tell @value{GDBN} that @var{overlay} is no longer mapped; @var{overlay}
7253must be the name of the object file section containing the overlay.
7254When an overlay is unmapped, @value{GDBN} assumes it can find the
7255overlay's functions and variables at their load addresses.
7256
7257@item overlay auto
7258@kindex overlay auto
7259Enable @dfn{automatic} overlay debugging. In this mode, @value{GDBN}
7260consults a data structure the overlay manager maintains in the inferior
7261to see which overlays are mapped. For details, see @ref{Automatic
7262Overlay Debugging}.
7263
7264@item overlay load-target
7265@itemx overlay load
7266@kindex overlay load-target
7267@cindex reloading the overlay table
7268Re-read the overlay table from the inferior. Normally, @value{GDBN}
7269re-reads the table @value{GDBN} automatically each time the inferior
7270stops, so this command should only be necessary if you have changed the
7271overlay mapping yourself using @value{GDBN}. This command is only
7272useful when using automatic overlay debugging.
7273
7274@item overlay list-overlays
7275@itemx overlay list
7276@cindex listing mapped overlays
7277Display a list of the overlays currently mapped, along with their mapped
7278addresses, load addresses, and sizes.
7279
7280@end table
7281
7282Normally, when @value{GDBN} prints a code address, it includes the name
7283of the function the address falls in:
7284
474c8240 7285@smallexample
df0cd8c5
JB
7286(gdb) print main
7287$3 = @{int ()@} 0x11a0 <main>
474c8240 7288@end smallexample
df0cd8c5
JB
7289@noindent
7290When overlay debugging is enabled, @value{GDBN} recognizes code in
7291unmapped overlays, and prints the names of unmapped functions with
7292asterisks around them. For example, if @code{foo} is a function in an
7293unmapped overlay, @value{GDBN} prints it this way:
7294
474c8240 7295@smallexample
df0cd8c5
JB
7296(gdb) overlay list
7297No sections are mapped.
7298(gdb) print foo
7299$5 = @{int (int)@} 0x100000 <*foo*>
474c8240 7300@end smallexample
df0cd8c5
JB
7301@noindent
7302When @code{foo}'s overlay is mapped, @value{GDBN} prints the function's
7303name normally:
7304
474c8240 7305@smallexample
df0cd8c5
JB
7306(gdb) overlay list
7307Section .ov.foo.text, loaded at 0x100000 - 0x100034,
7308 mapped at 0x1016 - 0x104a
7309(gdb) print foo
7310$6 = @{int (int)@} 0x1016 <foo>
474c8240 7311@end smallexample
df0cd8c5
JB
7312
7313When overlay debugging is enabled, @value{GDBN} can find the correct
7314address for functions and variables in an overlay, whether or not the
7315overlay is mapped. This allows most @value{GDBN} commands, like
7316@code{break} and @code{disassemble}, to work normally, even on unmapped
7317code. However, @value{GDBN}'s breakpoint support has some limitations:
7318
7319@itemize @bullet
7320@item
7321@cindex breakpoints in overlays
7322@cindex overlays, setting breakpoints in
7323You can set breakpoints in functions in unmapped overlays, as long as
7324@value{GDBN} can write to the overlay at its load address.
7325@item
7326@value{GDBN} can not set hardware or simulator-based breakpoints in
7327unmapped overlays. However, if you set a breakpoint at the end of your
7328overlay manager (and tell @value{GDBN} which overlays are now mapped, if
7329you are using manual overlay management), @value{GDBN} will re-set its
7330breakpoints properly.
7331@end itemize
7332
7333
7334@node Automatic Overlay Debugging
7335@section Automatic Overlay Debugging
7336@cindex automatic overlay debugging
7337
7338@value{GDBN} can automatically track which overlays are mapped and which
7339are not, given some simple co-operation from the overlay manager in the
7340inferior. If you enable automatic overlay debugging with the
7341@code{overlay auto} command (@pxref{Overlay Commands}), @value{GDBN}
7342looks in the inferior's memory for certain variables describing the
7343current state of the overlays.
7344
7345Here are the variables your overlay manager must define to support
7346@value{GDBN}'s automatic overlay debugging:
7347
7348@table @asis
7349
7350@item @code{_ovly_table}:
7351This variable must be an array of the following structures:
7352
474c8240 7353@smallexample
df0cd8c5
JB
7354struct
7355@{
7356 /* The overlay's mapped address. */
7357 unsigned long vma;
7358
7359 /* The size of the overlay, in bytes. */
7360 unsigned long size;
7361
7362 /* The overlay's load address. */
7363 unsigned long lma;
7364
7365 /* Non-zero if the overlay is currently mapped;
7366 zero otherwise. */
7367 unsigned long mapped;
7368@}
474c8240 7369@end smallexample
df0cd8c5
JB
7370
7371@item @code{_novlys}:
7372This variable must be a four-byte signed integer, holding the total
7373number of elements in @code{_ovly_table}.
7374
7375@end table
7376
7377To decide whether a particular overlay is mapped or not, @value{GDBN}
7378looks for an entry in @w{@code{_ovly_table}} whose @code{vma} and
7379@code{lma} members equal the VMA and LMA of the overlay's section in the
7380executable file. When @value{GDBN} finds a matching entry, it consults
7381the entry's @code{mapped} member to determine whether the overlay is
7382currently mapped.
7383
81d46470 7384In addition, your overlay manager may define a function called
def71bfa 7385@code{_ovly_debug_event}. If this function is defined, @value{GDBN}
81d46470
MS
7386will silently set a breakpoint there. If the overlay manager then
7387calls this function whenever it has changed the overlay table, this
7388will enable @value{GDBN} to accurately keep track of which overlays
7389are in program memory, and update any breakpoints that may be set
7390in overlays. This will allow breakpoints to work even if the
7391overlays are kept in ROM or other non-writable memory while they
7392are not being executed.
df0cd8c5
JB
7393
7394@node Overlay Sample Program
7395@section Overlay Sample Program
7396@cindex overlay example program
7397
7398When linking a program which uses overlays, you must place the overlays
7399at their load addresses, while relocating them to run at their mapped
7400addresses. To do this, you must write a linker script (@pxref{Overlay
7401Description,,, ld.info, Using ld: the GNU linker}). Unfortunately,
7402since linker scripts are specific to a particular host system, target
7403architecture, and target memory layout, this manual cannot provide
7404portable sample code demonstrating @value{GDBN}'s overlay support.
7405
7406However, the @value{GDBN} source distribution does contain an overlaid
7407program, with linker scripts for a few systems, as part of its test
7408suite. The program consists of the following files from
7409@file{gdb/testsuite/gdb.base}:
7410
7411@table @file
7412@item overlays.c
7413The main program file.
7414@item ovlymgr.c
7415A simple overlay manager, used by @file{overlays.c}.
7416@item foo.c
7417@itemx bar.c
7418@itemx baz.c
7419@itemx grbx.c
7420Overlay modules, loaded and used by @file{overlays.c}.
7421@item d10v.ld
7422@itemx m32r.ld
7423Linker scripts for linking the test program on the @code{d10v-elf}
7424and @code{m32r-elf} targets.
7425@end table
7426
7427You can build the test program using the @code{d10v-elf} GCC
7428cross-compiler like this:
7429
474c8240 7430@smallexample
df0cd8c5
JB
7431$ d10v-elf-gcc -g -c overlays.c
7432$ d10v-elf-gcc -g -c ovlymgr.c
7433$ d10v-elf-gcc -g -c foo.c
7434$ d10v-elf-gcc -g -c bar.c
7435$ d10v-elf-gcc -g -c baz.c
7436$ d10v-elf-gcc -g -c grbx.c
7437$ d10v-elf-gcc -g overlays.o ovlymgr.o foo.o bar.o \
7438 baz.o grbx.o -Wl,-Td10v.ld -o overlays
474c8240 7439@end smallexample
df0cd8c5
JB
7440
7441The build process is identical for any other architecture, except that
7442you must substitute the appropriate compiler and linker script for the
7443target system for @code{d10v-elf-gcc} and @code{d10v.ld}.
7444
7445
6d2ebf8b 7446@node Languages
c906108c
SS
7447@chapter Using @value{GDBN} with Different Languages
7448@cindex languages
7449
c906108c
SS
7450Although programming languages generally have common aspects, they are
7451rarely expressed in the same manner. For instance, in ANSI C,
7452dereferencing a pointer @code{p} is accomplished by @code{*p}, but in
7453Modula-2, it is accomplished by @code{p^}. Values can also be
5d161b24 7454represented (and displayed) differently. Hex numbers in C appear as
c906108c 7455@samp{0x1ae}, while in Modula-2 they appear as @samp{1AEH}.
c906108c
SS
7456
7457@cindex working language
7458Language-specific information is built into @value{GDBN} for some languages,
7459allowing you to express operations like the above in your program's
7460native language, and allowing @value{GDBN} to output values in a manner
7461consistent with the syntax of your program's native language. The
7462language you use to build expressions is called the @dfn{working
7463language}.
7464
7465@menu
7466* Setting:: Switching between source languages
7467* Show:: Displaying the language
c906108c 7468* Checks:: Type and range checks
c906108c 7469* Support:: Supported languages
4e562065 7470* Unsupported languages:: Unsupported languages
c906108c
SS
7471@end menu
7472
6d2ebf8b 7473@node Setting
c906108c
SS
7474@section Switching between source languages
7475
7476There are two ways to control the working language---either have @value{GDBN}
7477set it automatically, or select it manually yourself. You can use the
7478@code{set language} command for either purpose. On startup, @value{GDBN}
7479defaults to setting the language automatically. The working language is
7480used to determine how expressions you type are interpreted, how values
7481are printed, etc.
7482
7483In addition to the working language, every source file that
7484@value{GDBN} knows about has its own working language. For some object
7485file formats, the compiler might indicate which language a particular
7486source file is in. However, most of the time @value{GDBN} infers the
7487language from the name of the file. The language of a source file
b37052ae 7488controls whether C@t{++} names are demangled---this way @code{backtrace} can
c906108c 7489show each frame appropriately for its own language. There is no way to
d4f3574e
SS
7490set the language of a source file from within @value{GDBN}, but you can
7491set the language associated with a filename extension. @xref{Show, ,
7492Displaying the language}.
c906108c
SS
7493
7494This is most commonly a problem when you use a program, such
5d161b24 7495as @code{cfront} or @code{f2c}, that generates C but is written in
c906108c
SS
7496another language. In that case, make the
7497program use @code{#line} directives in its C output; that way
7498@value{GDBN} will know the correct language of the source code of the original
7499program, and will display that source code, not the generated C code.
7500
7501@menu
7502* Filenames:: Filename extensions and languages.
7503* Manually:: Setting the working language manually
7504* Automatically:: Having @value{GDBN} infer the source language
7505@end menu
7506
6d2ebf8b 7507@node Filenames
c906108c
SS
7508@subsection List of filename extensions and languages
7509
7510If a source file name ends in one of the following extensions, then
7511@value{GDBN} infers that its language is the one indicated.
7512
7513@table @file
7514
7515@item .c
7516C source file
7517
7518@item .C
7519@itemx .cc
7520@itemx .cp
7521@itemx .cpp
7522@itemx .cxx
7523@itemx .c++
b37052ae 7524C@t{++} source file
c906108c 7525
b37303ee
AF
7526@item .m
7527Objective-C source file
7528
c906108c
SS
7529@item .f
7530@itemx .F
7531Fortran source file
7532
c906108c
SS
7533@item .mod
7534Modula-2 source file
c906108c
SS
7535
7536@item .s
7537@itemx .S
7538Assembler source file. This actually behaves almost like C, but
7539@value{GDBN} does not skip over function prologues when stepping.
7540@end table
7541
7542In addition, you may set the language associated with a filename
7543extension. @xref{Show, , Displaying the language}.
7544
6d2ebf8b 7545@node Manually
c906108c
SS
7546@subsection Setting the working language
7547
7548If you allow @value{GDBN} to set the language automatically,
7549expressions are interpreted the same way in your debugging session and
7550your program.
7551
7552@kindex set language
7553If you wish, you may set the language manually. To do this, issue the
7554command @samp{set language @var{lang}}, where @var{lang} is the name of
5d161b24 7555a language, such as
c906108c 7556@code{c} or @code{modula-2}.
c906108c
SS
7557For a list of the supported languages, type @samp{set language}.
7558
c906108c
SS
7559Setting the language manually prevents @value{GDBN} from updating the working
7560language automatically. This can lead to confusion if you try
7561to debug a program when the working language is not the same as the
7562source language, when an expression is acceptable to both
7563languages---but means different things. For instance, if the current
7564source file were written in C, and @value{GDBN} was parsing Modula-2, a
7565command such as:
7566
474c8240 7567@smallexample
c906108c 7568print a = b + c
474c8240 7569@end smallexample
c906108c
SS
7570
7571@noindent
7572might not have the effect you intended. In C, this means to add
7573@code{b} and @code{c} and place the result in @code{a}. The result
7574printed would be the value of @code{a}. In Modula-2, this means to compare
7575@code{a} to the result of @code{b+c}, yielding a @code{BOOLEAN} value.
c906108c 7576
6d2ebf8b 7577@node Automatically
c906108c
SS
7578@subsection Having @value{GDBN} infer the source language
7579
7580To have @value{GDBN} set the working language automatically, use
7581@samp{set language local} or @samp{set language auto}. @value{GDBN}
7582then infers the working language. That is, when your program stops in a
7583frame (usually by encountering a breakpoint), @value{GDBN} sets the
7584working language to the language recorded for the function in that
7585frame. If the language for a frame is unknown (that is, if the function
7586or block corresponding to the frame was defined in a source file that
7587does not have a recognized extension), the current working language is
7588not changed, and @value{GDBN} issues a warning.
7589
7590This may not seem necessary for most programs, which are written
7591entirely in one source language. However, program modules and libraries
7592written in one source language can be used by a main program written in
7593a different source language. Using @samp{set language auto} in this
7594case frees you from having to set the working language manually.
7595
6d2ebf8b 7596@node Show
c906108c 7597@section Displaying the language
c906108c
SS
7598
7599The following commands help you find out which language is the
7600working language, and also what language source files were written in.
7601
7602@kindex show language
d4f3574e
SS
7603@kindex info frame@r{, show the source language}
7604@kindex info source@r{, show the source language}
c906108c
SS
7605@table @code
7606@item show language
7607Display the current working language. This is the
7608language you can use with commands such as @code{print} to
7609build and compute expressions that may involve variables in your program.
7610
7611@item info frame
5d161b24 7612Display the source language for this frame. This language becomes the
c906108c 7613working language if you use an identifier from this frame.
5d161b24 7614@xref{Frame Info, ,Information about a frame}, to identify the other
c906108c
SS
7615information listed here.
7616
7617@item info source
7618Display the source language of this source file.
5d161b24 7619@xref{Symbols, ,Examining the Symbol Table}, to identify the other
c906108c
SS
7620information listed here.
7621@end table
7622
7623In unusual circumstances, you may have source files with extensions
7624not in the standard list. You can then set the extension associated
7625with a language explicitly:
7626
7627@kindex set extension-language
7628@kindex info extensions
7629@table @code
7630@item set extension-language @var{.ext} @var{language}
7631Set source files with extension @var{.ext} to be assumed to be in
7632the source language @var{language}.
7633
7634@item info extensions
7635List all the filename extensions and the associated languages.
7636@end table
7637
6d2ebf8b 7638@node Checks
c906108c
SS
7639@section Type and range checking
7640
7641@quotation
7642@emph{Warning:} In this release, the @value{GDBN} commands for type and range
7643checking are included, but they do not yet have any effect. This
7644section documents the intended facilities.
7645@end quotation
7646@c FIXME remove warning when type/range code added
7647
7648Some languages are designed to guard you against making seemingly common
7649errors through a series of compile- and run-time checks. These include
7650checking the type of arguments to functions and operators, and making
7651sure mathematical overflows are caught at run time. Checks such as
7652these help to ensure a program's correctness once it has been compiled
7653by eliminating type mismatches, and providing active checks for range
7654errors when your program is running.
7655
7656@value{GDBN} can check for conditions like the above if you wish.
7657Although @value{GDBN} does not check the statements in your program, it
7658can check expressions entered directly into @value{GDBN} for evaluation via
7659the @code{print} command, for example. As with the working language,
7660@value{GDBN} can also decide whether or not to check automatically based on
7661your program's source language. @xref{Support, ,Supported languages},
7662for the default settings of supported languages.
7663
7664@menu
7665* Type Checking:: An overview of type checking
7666* Range Checking:: An overview of range checking
7667@end menu
7668
7669@cindex type checking
7670@cindex checks, type
6d2ebf8b 7671@node Type Checking
c906108c
SS
7672@subsection An overview of type checking
7673
7674Some languages, such as Modula-2, are strongly typed, meaning that the
7675arguments to operators and functions have to be of the correct type,
7676otherwise an error occurs. These checks prevent type mismatch
7677errors from ever causing any run-time problems. For example,
7678
7679@smallexample
76801 + 2 @result{} 3
7681@exdent but
7682@error{} 1 + 2.3
7683@end smallexample
7684
7685The second example fails because the @code{CARDINAL} 1 is not
7686type-compatible with the @code{REAL} 2.3.
7687
5d161b24
DB
7688For the expressions you use in @value{GDBN} commands, you can tell the
7689@value{GDBN} type checker to skip checking;
7690to treat any mismatches as errors and abandon the expression;
7691or to only issue warnings when type mismatches occur,
c906108c
SS
7692but evaluate the expression anyway. When you choose the last of
7693these, @value{GDBN} evaluates expressions like the second example above, but
7694also issues a warning.
7695
5d161b24
DB
7696Even if you turn type checking off, there may be other reasons
7697related to type that prevent @value{GDBN} from evaluating an expression.
7698For instance, @value{GDBN} does not know how to add an @code{int} and
7699a @code{struct foo}. These particular type errors have nothing to do
7700with the language in use, and usually arise from expressions, such as
c906108c
SS
7701the one described above, which make little sense to evaluate anyway.
7702
7703Each language defines to what degree it is strict about type. For
7704instance, both Modula-2 and C require the arguments to arithmetical
7705operators to be numbers. In C, enumerated types and pointers can be
7706represented as numbers, so that they are valid arguments to mathematical
7707operators. @xref{Support, ,Supported languages}, for further
7708details on specific languages.
7709
7710@value{GDBN} provides some additional commands for controlling the type checker:
7711
d4f3574e 7712@kindex set check@r{, type}
c906108c
SS
7713@kindex set check type
7714@kindex show check type
7715@table @code
7716@item set check type auto
7717Set type checking on or off based on the current working language.
7718@xref{Support, ,Supported languages}, for the default settings for
7719each language.
7720
7721@item set check type on
7722@itemx set check type off
7723Set type checking on or off, overriding the default setting for the
7724current working language. Issue a warning if the setting does not
7725match the language default. If any type mismatches occur in
d4f3574e 7726evaluating an expression while type checking is on, @value{GDBN} prints a
c906108c
SS
7727message and aborts evaluation of the expression.
7728
7729@item set check type warn
7730Cause the type checker to issue warnings, but to always attempt to
7731evaluate the expression. Evaluating the expression may still
7732be impossible for other reasons. For example, @value{GDBN} cannot add
7733numbers and structures.
7734
7735@item show type
5d161b24 7736Show the current setting of the type checker, and whether or not @value{GDBN}
c906108c
SS
7737is setting it automatically.
7738@end table
7739
7740@cindex range checking
7741@cindex checks, range
6d2ebf8b 7742@node Range Checking
c906108c
SS
7743@subsection An overview of range checking
7744
7745In some languages (such as Modula-2), it is an error to exceed the
7746bounds of a type; this is enforced with run-time checks. Such range
7747checking is meant to ensure program correctness by making sure
7748computations do not overflow, or indices on an array element access do
7749not exceed the bounds of the array.
7750
7751For expressions you use in @value{GDBN} commands, you can tell
7752@value{GDBN} to treat range errors in one of three ways: ignore them,
7753always treat them as errors and abandon the expression, or issue
7754warnings but evaluate the expression anyway.
7755
7756A range error can result from numerical overflow, from exceeding an
7757array index bound, or when you type a constant that is not a member
7758of any type. Some languages, however, do not treat overflows as an
7759error. In many implementations of C, mathematical overflow causes the
7760result to ``wrap around'' to lower values---for example, if @var{m} is
7761the largest integer value, and @var{s} is the smallest, then
7762
474c8240 7763@smallexample
c906108c 7764@var{m} + 1 @result{} @var{s}
474c8240 7765@end smallexample
c906108c
SS
7766
7767This, too, is specific to individual languages, and in some cases
7768specific to individual compilers or machines. @xref{Support, ,
7769Supported languages}, for further details on specific languages.
7770
7771@value{GDBN} provides some additional commands for controlling the range checker:
7772
d4f3574e 7773@kindex set check@r{, range}
c906108c
SS
7774@kindex set check range
7775@kindex show check range
7776@table @code
7777@item set check range auto
7778Set range checking on or off based on the current working language.
7779@xref{Support, ,Supported languages}, for the default settings for
7780each language.
7781
7782@item set check range on
7783@itemx set check range off
7784Set range checking on or off, overriding the default setting for the
7785current working language. A warning is issued if the setting does not
c3f6f71d
JM
7786match the language default. If a range error occurs and range checking is on,
7787then a message is printed and evaluation of the expression is aborted.
c906108c
SS
7788
7789@item set check range warn
7790Output messages when the @value{GDBN} range checker detects a range error,
7791but attempt to evaluate the expression anyway. Evaluating the
7792expression may still be impossible for other reasons, such as accessing
7793memory that the process does not own (a typical example from many Unix
7794systems).
7795
7796@item show range
7797Show the current setting of the range checker, and whether or not it is
7798being set automatically by @value{GDBN}.
7799@end table
c906108c 7800
6d2ebf8b 7801@node Support
c906108c 7802@section Supported languages
c906108c 7803
b37303ee 7804@value{GDBN} supports C, C@t{++}, Objective-C, Fortran, Java, assembly, and Modula-2.
cce74817 7805@c This is false ...
c906108c
SS
7806Some @value{GDBN} features may be used in expressions regardless of the
7807language you use: the @value{GDBN} @code{@@} and @code{::} operators,
7808and the @samp{@{type@}addr} construct (@pxref{Expressions,
7809,Expressions}) can be used with the constructs of any supported
7810language.
7811
7812The following sections detail to what degree each source language is
7813supported by @value{GDBN}. These sections are not meant to be language
7814tutorials or references, but serve only as a reference guide to what the
7815@value{GDBN} expression parser accepts, and what input and output
7816formats should look like for different languages. There are many good
7817books written on each of these languages; please look to these for a
7818language reference or tutorial.
7819
c906108c 7820@menu
b37303ee
AF
7821* C:: C and C@t{++}
7822* Objective-C:: Objective-C
7823* Modula-2:: Modula-2
c906108c
SS
7824@end menu
7825
6d2ebf8b 7826@node C
b37052ae 7827@subsection C and C@t{++}
7a292a7a 7828
b37052ae
EZ
7829@cindex C and C@t{++}
7830@cindex expressions in C or C@t{++}
c906108c 7831
b37052ae 7832Since C and C@t{++} are so closely related, many features of @value{GDBN} apply
c906108c
SS
7833to both languages. Whenever this is the case, we discuss those languages
7834together.
7835
41afff9a
EZ
7836@cindex C@t{++}
7837@cindex @code{g++}, @sc{gnu} C@t{++} compiler
b37052ae
EZ
7838@cindex @sc{gnu} C@t{++}
7839The C@t{++} debugging facilities are jointly implemented by the C@t{++}
7840compiler and @value{GDBN}. Therefore, to debug your C@t{++} code
7841effectively, you must compile your C@t{++} programs with a supported
7842C@t{++} compiler, such as @sc{gnu} @code{g++}, or the HP ANSI C@t{++}
c906108c
SS
7843compiler (@code{aCC}).
7844
0179ffac
DC
7845For best results when using @sc{gnu} C@t{++}, use the DWARF 2 debugging
7846format; if it doesn't work on your system, try the stabs+ debugging
7847format. You can select those formats explicitly with the @code{g++}
7848command-line options @option{-gdwarf-2} and @option{-gstabs+}.
7849@xref{Debugging Options,,Options for Debugging Your Program or @sc{gnu}
7850CC, gcc.info, Using @sc{gnu} CC}.
c906108c 7851
c906108c 7852@menu
b37052ae
EZ
7853* C Operators:: C and C@t{++} operators
7854* C Constants:: C and C@t{++} constants
7855* C plus plus expressions:: C@t{++} expressions
7856* C Defaults:: Default settings for C and C@t{++}
7857* C Checks:: C and C@t{++} type and range checks
c906108c 7858* Debugging C:: @value{GDBN} and C
b37052ae 7859* Debugging C plus plus:: @value{GDBN} features for C@t{++}
c906108c 7860@end menu
c906108c 7861
6d2ebf8b 7862@node C Operators
b37052ae 7863@subsubsection C and C@t{++} operators
7a292a7a 7864
b37052ae 7865@cindex C and C@t{++} operators
c906108c
SS
7866
7867Operators must be defined on values of specific types. For instance,
7868@code{+} is defined on numbers, but not on structures. Operators are
5d161b24 7869often defined on groups of types.
c906108c 7870
b37052ae 7871For the purposes of C and C@t{++}, the following definitions hold:
c906108c
SS
7872
7873@itemize @bullet
53a5351d 7874
c906108c 7875@item
c906108c 7876@emph{Integral types} include @code{int} with any of its storage-class
b37052ae 7877specifiers; @code{char}; @code{enum}; and, for C@t{++}, @code{bool}.
c906108c
SS
7878
7879@item
d4f3574e
SS
7880@emph{Floating-point types} include @code{float}, @code{double}, and
7881@code{long double} (if supported by the target platform).
c906108c
SS
7882
7883@item
53a5351d 7884@emph{Pointer types} include all types defined as @code{(@var{type} *)}.
c906108c
SS
7885
7886@item
7887@emph{Scalar types} include all of the above.
53a5351d 7888
c906108c
SS
7889@end itemize
7890
7891@noindent
7892The following operators are supported. They are listed here
7893in order of increasing precedence:
7894
7895@table @code
7896@item ,
7897The comma or sequencing operator. Expressions in a comma-separated list
7898are evaluated from left to right, with the result of the entire
7899expression being the last expression evaluated.
7900
7901@item =
7902Assignment. The value of an assignment expression is the value
7903assigned. Defined on scalar types.
7904
7905@item @var{op}=
7906Used in an expression of the form @w{@code{@var{a} @var{op}= @var{b}}},
7907and translated to @w{@code{@var{a} = @var{a op b}}}.
d4f3574e 7908@w{@code{@var{op}=}} and @code{=} have the same precedence.
c906108c
SS
7909@var{op} is any one of the operators @code{|}, @code{^}, @code{&},
7910@code{<<}, @code{>>}, @code{+}, @code{-}, @code{*}, @code{/}, @code{%}.
7911
7912@item ?:
7913The ternary operator. @code{@var{a} ? @var{b} : @var{c}} can be thought
7914of as: if @var{a} then @var{b} else @var{c}. @var{a} should be of an
7915integral type.
7916
7917@item ||
7918Logical @sc{or}. Defined on integral types.
7919
7920@item &&
7921Logical @sc{and}. Defined on integral types.
7922
7923@item |
7924Bitwise @sc{or}. Defined on integral types.
7925
7926@item ^
7927Bitwise exclusive-@sc{or}. Defined on integral types.
7928
7929@item &
7930Bitwise @sc{and}. Defined on integral types.
7931
7932@item ==@r{, }!=
7933Equality and inequality. Defined on scalar types. The value of these
7934expressions is 0 for false and non-zero for true.
7935
7936@item <@r{, }>@r{, }<=@r{, }>=
7937Less than, greater than, less than or equal, greater than or equal.
7938Defined on scalar types. The value of these expressions is 0 for false
7939and non-zero for true.
7940
7941@item <<@r{, }>>
7942left shift, and right shift. Defined on integral types.
7943
7944@item @@
7945The @value{GDBN} ``artificial array'' operator (@pxref{Expressions, ,Expressions}).
7946
7947@item +@r{, }-
7948Addition and subtraction. Defined on integral types, floating-point types and
7949pointer types.
7950
7951@item *@r{, }/@r{, }%
7952Multiplication, division, and modulus. Multiplication and division are
7953defined on integral and floating-point types. Modulus is defined on
7954integral types.
7955
7956@item ++@r{, }--
7957Increment and decrement. When appearing before a variable, the
7958operation is performed before the variable is used in an expression;
7959when appearing after it, the variable's value is used before the
7960operation takes place.
7961
7962@item *
7963Pointer dereferencing. Defined on pointer types. Same precedence as
7964@code{++}.
7965
7966@item &
7967Address operator. Defined on variables. Same precedence as @code{++}.
7968
b37052ae
EZ
7969For debugging C@t{++}, @value{GDBN} implements a use of @samp{&} beyond what is
7970allowed in the C@t{++} language itself: you can use @samp{&(&@var{ref})}
c906108c 7971(or, if you prefer, simply @samp{&&@var{ref}}) to examine the address
b37052ae 7972where a C@t{++} reference variable (declared with @samp{&@var{ref}}) is
c906108c 7973stored.
c906108c
SS
7974
7975@item -
7976Negative. Defined on integral and floating-point types. Same
7977precedence as @code{++}.
7978
7979@item !
7980Logical negation. Defined on integral types. Same precedence as
7981@code{++}.
7982
7983@item ~
7984Bitwise complement operator. Defined on integral types. Same precedence as
7985@code{++}.
7986
7987
7988@item .@r{, }->
7989Structure member, and pointer-to-structure member. For convenience,
7990@value{GDBN} regards the two as equivalent, choosing whether to dereference a
7991pointer based on the stored type information.
7992Defined on @code{struct} and @code{union} data.
7993
c906108c
SS
7994@item .*@r{, }->*
7995Dereferences of pointers to members.
c906108c
SS
7996
7997@item []
7998Array indexing. @code{@var{a}[@var{i}]} is defined as
7999@code{*(@var{a}+@var{i})}. Same precedence as @code{->}.
8000
8001@item ()
8002Function parameter list. Same precedence as @code{->}.
8003
c906108c 8004@item ::
b37052ae 8005C@t{++} scope resolution operator. Defined on @code{struct}, @code{union},
7a292a7a 8006and @code{class} types.
c906108c
SS
8007
8008@item ::
7a292a7a
SS
8009Doubled colons also represent the @value{GDBN} scope operator
8010(@pxref{Expressions, ,Expressions}). Same precedence as @code{::},
8011above.
c906108c
SS
8012@end table
8013
c906108c
SS
8014If an operator is redefined in the user code, @value{GDBN} usually
8015attempts to invoke the redefined version instead of using the operator's
8016predefined meaning.
c906108c 8017
c906108c 8018@menu
5d161b24 8019* C Constants::
c906108c
SS
8020@end menu
8021
6d2ebf8b 8022@node C Constants
b37052ae 8023@subsubsection C and C@t{++} constants
c906108c 8024
b37052ae 8025@cindex C and C@t{++} constants
c906108c 8026
b37052ae 8027@value{GDBN} allows you to express the constants of C and C@t{++} in the
c906108c 8028following ways:
c906108c
SS
8029
8030@itemize @bullet
8031@item
8032Integer constants are a sequence of digits. Octal constants are
6ca652b0
EZ
8033specified by a leading @samp{0} (i.e.@: zero), and hexadecimal constants
8034by a leading @samp{0x} or @samp{0X}. Constants may also end with a letter
c906108c
SS
8035@samp{l}, specifying that the constant should be treated as a
8036@code{long} value.
8037
8038@item
8039Floating point constants are a sequence of digits, followed by a decimal
8040point, followed by a sequence of digits, and optionally followed by an
8041exponent. An exponent is of the form:
8042@samp{@w{e@r{[[}+@r{]|}-@r{]}@var{nnn}}}, where @var{nnn} is another
8043sequence of digits. The @samp{+} is optional for positive exponents.
d4f3574e
SS
8044A floating-point constant may also end with a letter @samp{f} or
8045@samp{F}, specifying that the constant should be treated as being of
8046the @code{float} (as opposed to the default @code{double}) type; or with
8047a letter @samp{l} or @samp{L}, which specifies a @code{long double}
8048constant.
c906108c
SS
8049
8050@item
8051Enumerated constants consist of enumerated identifiers, or their
8052integral equivalents.
8053
8054@item
8055Character constants are a single character surrounded by single quotes
8056(@code{'}), or a number---the ordinal value of the corresponding character
d4f3574e 8057(usually its @sc{ascii} value). Within quotes, the single character may
c906108c
SS
8058be represented by a letter or by @dfn{escape sequences}, which are of
8059the form @samp{\@var{nnn}}, where @var{nnn} is the octal representation
8060of the character's ordinal value; or of the form @samp{\@var{x}}, where
8061@samp{@var{x}} is a predefined special character---for example,
8062@samp{\n} for newline.
8063
8064@item
96a2c332
SS
8065String constants are a sequence of character constants surrounded by
8066double quotes (@code{"}). Any valid character constant (as described
8067above) may appear. Double quotes within the string must be preceded by
8068a backslash, so for instance @samp{"a\"b'c"} is a string of five
8069characters.
c906108c
SS
8070
8071@item
8072Pointer constants are an integral value. You can also write pointers
8073to constants using the C operator @samp{&}.
8074
8075@item
8076Array constants are comma-separated lists surrounded by braces @samp{@{}
8077and @samp{@}}; for example, @samp{@{1,2,3@}} is a three-element array of
8078integers, @samp{@{@{1,2@}, @{3,4@}, @{5,6@}@}} is a three-by-two array,
8079and @samp{@{&"hi", &"there", &"fred"@}} is a three-element array of pointers.
8080@end itemize
8081
c906108c 8082@menu
5d161b24
DB
8083* C plus plus expressions::
8084* C Defaults::
8085* C Checks::
c906108c 8086
5d161b24 8087* Debugging C::
c906108c
SS
8088@end menu
8089
6d2ebf8b 8090@node C plus plus expressions
b37052ae
EZ
8091@subsubsection C@t{++} expressions
8092
8093@cindex expressions in C@t{++}
8094@value{GDBN} expression handling can interpret most C@t{++} expressions.
8095
0179ffac
DC
8096@cindex debugging C@t{++} programs
8097@cindex C@t{++} compilers
8098@cindex debug formats and C@t{++}
8099@cindex @value{NGCC} and C@t{++}
c906108c 8100@quotation
b37052ae 8101@emph{Warning:} @value{GDBN} can only debug C@t{++} code if you use the
0179ffac
DC
8102proper compiler and the proper debug format. Currently, @value{GDBN}
8103works best when debugging C@t{++} code that is compiled with
8104@value{NGCC} 2.95.3 or with @value{NGCC} 3.1 or newer, using the options
8105@option{-gdwarf-2} or @option{-gstabs+}. DWARF 2 is preferred over
8106stabs+. Most configurations of @value{NGCC} emit either DWARF 2 or
8107stabs+ as their default debug format, so you usually don't need to
8108specify a debug format explicitly. Other compilers and/or debug formats
8109are likely to work badly or not at all when using @value{GDBN} to debug
8110C@t{++} code.
c906108c 8111@end quotation
c906108c
SS
8112
8113@enumerate
8114
8115@cindex member functions
8116@item
8117Member function calls are allowed; you can use expressions like
8118
474c8240 8119@smallexample
c906108c 8120count = aml->GetOriginal(x, y)
474c8240 8121@end smallexample
c906108c 8122
41afff9a 8123@vindex this@r{, inside C@t{++} member functions}
b37052ae 8124@cindex namespace in C@t{++}
c906108c
SS
8125@item
8126While a member function is active (in the selected stack frame), your
8127expressions have the same namespace available as the member function;
8128that is, @value{GDBN} allows implicit references to the class instance
b37052ae 8129pointer @code{this} following the same rules as C@t{++}.
c906108c 8130
c906108c 8131@cindex call overloaded functions
d4f3574e 8132@cindex overloaded functions, calling
b37052ae 8133@cindex type conversions in C@t{++}
c906108c
SS
8134@item
8135You can call overloaded functions; @value{GDBN} resolves the function
d4f3574e 8136call to the right definition, with some restrictions. @value{GDBN} does not
c906108c
SS
8137perform overload resolution involving user-defined type conversions,
8138calls to constructors, or instantiations of templates that do not exist
8139in the program. It also cannot handle ellipsis argument lists or
8140default arguments.
8141
8142It does perform integral conversions and promotions, floating-point
8143promotions, arithmetic conversions, pointer conversions, conversions of
8144class objects to base classes, and standard conversions such as those of
8145functions or arrays to pointers; it requires an exact match on the
8146number of function arguments.
8147
8148Overload resolution is always performed, unless you have specified
8149@code{set overload-resolution off}. @xref{Debugging C plus plus,
b37052ae 8150,@value{GDBN} features for C@t{++}}.
c906108c 8151
d4f3574e 8152You must specify @code{set overload-resolution off} in order to use an
c906108c
SS
8153explicit function signature to call an overloaded function, as in
8154@smallexample
8155p 'foo(char,int)'('x', 13)
8156@end smallexample
d4f3574e 8157
c906108c 8158The @value{GDBN} command-completion facility can simplify this;
d4f3574e 8159see @ref{Completion, ,Command completion}.
c906108c 8160
c906108c
SS
8161@cindex reference declarations
8162@item
b37052ae
EZ
8163@value{GDBN} understands variables declared as C@t{++} references; you can use
8164them in expressions just as you do in C@t{++} source---they are automatically
c906108c
SS
8165dereferenced.
8166
8167In the parameter list shown when @value{GDBN} displays a frame, the values of
8168reference variables are not displayed (unlike other variables); this
8169avoids clutter, since references are often used for large structures.
8170The @emph{address} of a reference variable is always shown, unless
8171you have specified @samp{set print address off}.
8172
8173@item
b37052ae 8174@value{GDBN} supports the C@t{++} name resolution operator @code{::}---your
c906108c
SS
8175expressions can use it just as expressions in your program do. Since
8176one scope may be defined in another, you can use @code{::} repeatedly if
8177necessary, for example in an expression like
8178@samp{@var{scope1}::@var{scope2}::@var{name}}. @value{GDBN} also allows
b37052ae 8179resolving name scope by reference to source files, in both C and C@t{++}
c906108c
SS
8180debugging (@pxref{Variables, ,Program variables}).
8181@end enumerate
8182
b37052ae 8183In addition, when used with HP's C@t{++} compiler, @value{GDBN} supports
53a5351d
JM
8184calling virtual functions correctly, printing out virtual bases of
8185objects, calling functions in a base subobject, casting objects, and
8186invoking user-defined operators.
c906108c 8187
6d2ebf8b 8188@node C Defaults
b37052ae 8189@subsubsection C and C@t{++} defaults
7a292a7a 8190
b37052ae 8191@cindex C and C@t{++} defaults
c906108c 8192
c906108c
SS
8193If you allow @value{GDBN} to set type and range checking automatically, they
8194both default to @code{off} whenever the working language changes to
b37052ae 8195C or C@t{++}. This happens regardless of whether you or @value{GDBN}
c906108c 8196selects the working language.
c906108c
SS
8197
8198If you allow @value{GDBN} to set the language automatically, it
8199recognizes source files whose names end with @file{.c}, @file{.C}, or
8200@file{.cc}, etc, and when @value{GDBN} enters code compiled from one of
b37052ae 8201these files, it sets the working language to C or C@t{++}.
c906108c
SS
8202@xref{Automatically, ,Having @value{GDBN} infer the source language},
8203for further details.
8204
c906108c
SS
8205@c Type checking is (a) primarily motivated by Modula-2, and (b)
8206@c unimplemented. If (b) changes, it might make sense to let this node
8207@c appear even if Mod-2 does not, but meanwhile ignore it. roland 16jul93.
7a292a7a 8208
6d2ebf8b 8209@node C Checks
b37052ae 8210@subsubsection C and C@t{++} type and range checks
7a292a7a 8211
b37052ae 8212@cindex C and C@t{++} checks
c906108c 8213
b37052ae 8214By default, when @value{GDBN} parses C or C@t{++} expressions, type checking
c906108c
SS
8215is not used. However, if you turn type checking on, @value{GDBN}
8216considers two variables type equivalent if:
8217
8218@itemize @bullet
8219@item
8220The two variables are structured and have the same structure, union, or
8221enumerated tag.
8222
8223@item
8224The two variables have the same type name, or types that have been
8225declared equivalent through @code{typedef}.
8226
8227@ignore
8228@c leaving this out because neither J Gilmore nor R Pesch understand it.
8229@c FIXME--beers?
8230@item
8231The two @code{struct}, @code{union}, or @code{enum} variables are
8232declared in the same declaration. (Note: this may not be true for all C
8233compilers.)
8234@end ignore
8235@end itemize
8236
8237Range checking, if turned on, is done on mathematical operations. Array
8238indices are not checked, since they are often used to index a pointer
8239that is not itself an array.
c906108c 8240
6d2ebf8b 8241@node Debugging C
c906108c 8242@subsubsection @value{GDBN} and C
c906108c
SS
8243
8244The @code{set print union} and @code{show print union} commands apply to
8245the @code{union} type. When set to @samp{on}, any @code{union} that is
7a292a7a
SS
8246inside a @code{struct} or @code{class} is also printed. Otherwise, it
8247appears as @samp{@{...@}}.
c906108c
SS
8248
8249The @code{@@} operator aids in the debugging of dynamic arrays, formed
8250with pointers and a memory allocation function. @xref{Expressions,
8251,Expressions}.
8252
c906108c 8253@menu
5d161b24 8254* Debugging C plus plus::
c906108c
SS
8255@end menu
8256
6d2ebf8b 8257@node Debugging C plus plus
b37052ae 8258@subsubsection @value{GDBN} features for C@t{++}
c906108c 8259
b37052ae 8260@cindex commands for C@t{++}
7a292a7a 8261
b37052ae
EZ
8262Some @value{GDBN} commands are particularly useful with C@t{++}, and some are
8263designed specifically for use with C@t{++}. Here is a summary:
c906108c
SS
8264
8265@table @code
8266@cindex break in overloaded functions
8267@item @r{breakpoint menus}
8268When you want a breakpoint in a function whose name is overloaded,
8269@value{GDBN} breakpoint menus help you specify which function definition
8270you want. @xref{Breakpoint Menus,,Breakpoint menus}.
8271
b37052ae 8272@cindex overloading in C@t{++}
c906108c
SS
8273@item rbreak @var{regex}
8274Setting breakpoints using regular expressions is helpful for setting
8275breakpoints on overloaded functions that are not members of any special
8276classes.
8277@xref{Set Breaks, ,Setting breakpoints}.
8278
b37052ae 8279@cindex C@t{++} exception handling
c906108c
SS
8280@item catch throw
8281@itemx catch catch
b37052ae 8282Debug C@t{++} exception handling using these commands. @xref{Set
c906108c
SS
8283Catchpoints, , Setting catchpoints}.
8284
8285@cindex inheritance
8286@item ptype @var{typename}
8287Print inheritance relationships as well as other information for type
8288@var{typename}.
8289@xref{Symbols, ,Examining the Symbol Table}.
8290
b37052ae 8291@cindex C@t{++} symbol display
c906108c
SS
8292@item set print demangle
8293@itemx show print demangle
8294@itemx set print asm-demangle
8295@itemx show print asm-demangle
b37052ae
EZ
8296Control whether C@t{++} symbols display in their source form, both when
8297displaying code as C@t{++} source and when displaying disassemblies.
c906108c
SS
8298@xref{Print Settings, ,Print settings}.
8299
8300@item set print object
8301@itemx show print object
8302Choose whether to print derived (actual) or declared types of objects.
8303@xref{Print Settings, ,Print settings}.
8304
8305@item set print vtbl
8306@itemx show print vtbl
8307Control the format for printing virtual function tables.
8308@xref{Print Settings, ,Print settings}.
c906108c 8309(The @code{vtbl} commands do not work on programs compiled with the HP
b37052ae 8310ANSI C@t{++} compiler (@code{aCC}).)
c906108c
SS
8311
8312@kindex set overload-resolution
d4f3574e 8313@cindex overloaded functions, overload resolution
c906108c 8314@item set overload-resolution on
b37052ae 8315Enable overload resolution for C@t{++} expression evaluation. The default
c906108c
SS
8316is on. For overloaded functions, @value{GDBN} evaluates the arguments
8317and searches for a function whose signature matches the argument types,
b37052ae 8318using the standard C@t{++} conversion rules (see @ref{C plus plus expressions, ,C@t{++}
d4f3574e 8319expressions}, for details). If it cannot find a match, it emits a
c906108c
SS
8320message.
8321
8322@item set overload-resolution off
b37052ae 8323Disable overload resolution for C@t{++} expression evaluation. For
c906108c
SS
8324overloaded functions that are not class member functions, @value{GDBN}
8325chooses the first function of the specified name that it finds in the
8326symbol table, whether or not its arguments are of the correct type. For
8327overloaded functions that are class member functions, @value{GDBN}
8328searches for a function whose signature @emph{exactly} matches the
8329argument types.
c906108c
SS
8330
8331@item @r{Overloaded symbol names}
8332You can specify a particular definition of an overloaded symbol, using
b37052ae 8333the same notation that is used to declare such symbols in C@t{++}: type
c906108c
SS
8334@code{@var{symbol}(@var{types})} rather than just @var{symbol}. You can
8335also use the @value{GDBN} command-line word completion facilities to list the
8336available choices, or to finish the type list for you.
8337@xref{Completion,, Command completion}, for details on how to do this.
8338@end table
c906108c 8339
b37303ee
AF
8340@node Objective-C
8341@subsection Objective-C
8342
8343@cindex Objective-C
8344This section provides information about some commands and command
8345options that are useful for debugging Objective-C code.
8346
8347@menu
8348* Method Names in Commands::
8349* The Print Command with Objective-C::
8350@end menu
8351
8352@node Method Names in Commands, The Print Command with Objective-C, Objective-C, Objective-C
8353@subsubsection Method Names in Commands
8354
8355The following commands have been extended to accept Objective-C method
8356names as line specifications:
8357
8358@kindex clear@r{, and Objective-C}
8359@kindex break@r{, and Objective-C}
8360@kindex info line@r{, and Objective-C}
8361@kindex jump@r{, and Objective-C}
8362@kindex list@r{, and Objective-C}
8363@itemize
8364@item @code{clear}
8365@item @code{break}
8366@item @code{info line}
8367@item @code{jump}
8368@item @code{list}
8369@end itemize
8370
8371A fully qualified Objective-C method name is specified as
8372
8373@smallexample
8374-[@var{Class} @var{methodName}]
8375@end smallexample
8376
8377where the minus sign is used to indicate an instance method and a plus
8378sign (not shown) is used to indicate a class method. The
8379class name @var{Class} and method name @var{methoName} are enclosed in
8380brackets, similar to the way messages are specified in Objective-C source
8381code. For example, to set a breakpoint at the @code{create} instance method of
8382class @code{Fruit} in the program currently being debugged, enter:
8383
8384@smallexample
8385break -[Fruit create]
8386@end smallexample
8387
8388To list ten program lines around the @code{initialize} class method,
8389enter:
8390
8391@smallexample
8392list +[NSText initialize]
8393@end smallexample
8394
8395In the current version of GDB, the plus or minus sign is required. In
8396future versions of GDB, the plus or minus sign will be optional, but you
8397can use it to narrow the search. It is also possible to specify just a
8398method name:
8399
8400@smallexample
8401break create
8402@end smallexample
8403
8404You must specify the complete method name, including any colons. If
8405your program's source files contain more than one @code{create} method,
8406you'll be presented with a numbered list of classes that implement that
8407method. Indicate your choice by number, or type @samp{0} to exit if
8408none apply.
8409
8410As another example, to clear a breakpoint established at the
8411@code{makeKeyAndOrderFront:} method of the @code{NSWindow} class, enter:
8412
8413@smallexample
8414clear -[NSWindow makeKeyAndOrderFront:]
8415@end smallexample
8416
8417@node The Print Command with Objective-C
8418@subsubsection The Print Command With Objective-C
8419
8420The print command has also been extended to accept methods. For example:
8421
8422@smallexample
8423print -[object hash]
8424@end smallexample
8425
8426@cindex print an Objective-C object description
8427will tell gdb to send the -hash message to object and print the
8428result. Also an additional command has been added, @code{print-object}
8429or @code{po} for short, which is meant to print the description of an
8430object. However, this command may only work with certain Objective-C
8431libraries that have a particular hook function, called
8432@code{_NSPrintForDebugger} defined.
8433
8434@node Modula-2, , Objective-C, Support
c906108c 8435@subsection Modula-2
7a292a7a 8436
d4f3574e 8437@cindex Modula-2, @value{GDBN} support
c906108c
SS
8438
8439The extensions made to @value{GDBN} to support Modula-2 only support
8440output from the @sc{gnu} Modula-2 compiler (which is currently being
8441developed). Other Modula-2 compilers are not currently supported, and
8442attempting to debug executables produced by them is most likely
8443to give an error as @value{GDBN} reads in the executable's symbol
8444table.
8445
8446@cindex expressions in Modula-2
8447@menu
8448* M2 Operators:: Built-in operators
8449* Built-In Func/Proc:: Built-in functions and procedures
8450* M2 Constants:: Modula-2 constants
8451* M2 Defaults:: Default settings for Modula-2
8452* Deviations:: Deviations from standard Modula-2
8453* M2 Checks:: Modula-2 type and range checks
8454* M2 Scope:: The scope operators @code{::} and @code{.}
8455* GDB/M2:: @value{GDBN} and Modula-2
8456@end menu
8457
6d2ebf8b 8458@node M2 Operators
c906108c
SS
8459@subsubsection Operators
8460@cindex Modula-2 operators
8461
8462Operators must be defined on values of specific types. For instance,
8463@code{+} is defined on numbers, but not on structures. Operators are
8464often defined on groups of types. For the purposes of Modula-2, the
8465following definitions hold:
8466
8467@itemize @bullet
8468
8469@item
8470@emph{Integral types} consist of @code{INTEGER}, @code{CARDINAL}, and
8471their subranges.
8472
8473@item
8474@emph{Character types} consist of @code{CHAR} and its subranges.
8475
8476@item
8477@emph{Floating-point types} consist of @code{REAL}.
8478
8479@item
8480@emph{Pointer types} consist of anything declared as @code{POINTER TO
8481@var{type}}.
8482
8483@item
8484@emph{Scalar types} consist of all of the above.
8485
8486@item
8487@emph{Set types} consist of @code{SET} and @code{BITSET} types.
8488
8489@item
8490@emph{Boolean types} consist of @code{BOOLEAN}.
8491@end itemize
8492
8493@noindent
8494The following operators are supported, and appear in order of
8495increasing precedence:
8496
8497@table @code
8498@item ,
8499Function argument or array index separator.
8500
8501@item :=
8502Assignment. The value of @var{var} @code{:=} @var{value} is
8503@var{value}.
8504
8505@item <@r{, }>
8506Less than, greater than on integral, floating-point, or enumerated
8507types.
8508
8509@item <=@r{, }>=
96a2c332 8510Less than or equal to, greater than or equal to
c906108c
SS
8511on integral, floating-point and enumerated types, or set inclusion on
8512set types. Same precedence as @code{<}.
8513
8514@item =@r{, }<>@r{, }#
8515Equality and two ways of expressing inequality, valid on scalar types.
8516Same precedence as @code{<}. In @value{GDBN} scripts, only @code{<>} is
8517available for inequality, since @code{#} conflicts with the script
8518comment character.
8519
8520@item IN
8521Set membership. Defined on set types and the types of their members.
8522Same precedence as @code{<}.
8523
8524@item OR
8525Boolean disjunction. Defined on boolean types.
8526
8527@item AND@r{, }&
d4f3574e 8528Boolean conjunction. Defined on boolean types.
c906108c
SS
8529
8530@item @@
8531The @value{GDBN} ``artificial array'' operator (@pxref{Expressions, ,Expressions}).
8532
8533@item +@r{, }-
8534Addition and subtraction on integral and floating-point types, or union
8535and difference on set types.
8536
8537@item *
8538Multiplication on integral and floating-point types, or set intersection
8539on set types.
8540
8541@item /
8542Division on floating-point types, or symmetric set difference on set
8543types. Same precedence as @code{*}.
8544
8545@item DIV@r{, }MOD
8546Integer division and remainder. Defined on integral types. Same
8547precedence as @code{*}.
8548
8549@item -
8550Negative. Defined on @code{INTEGER} and @code{REAL} data.
8551
8552@item ^
8553Pointer dereferencing. Defined on pointer types.
8554
8555@item NOT
8556Boolean negation. Defined on boolean types. Same precedence as
8557@code{^}.
8558
8559@item .
8560@code{RECORD} field selector. Defined on @code{RECORD} data. Same
8561precedence as @code{^}.
8562
8563@item []
8564Array indexing. Defined on @code{ARRAY} data. Same precedence as @code{^}.
8565
8566@item ()
8567Procedure argument list. Defined on @code{PROCEDURE} objects. Same precedence
8568as @code{^}.
8569
8570@item ::@r{, }.
8571@value{GDBN} and Modula-2 scope operators.
8572@end table
8573
8574@quotation
8575@emph{Warning:} Sets and their operations are not yet supported, so @value{GDBN}
8576treats the use of the operator @code{IN}, or the use of operators
8577@code{+}, @code{-}, @code{*}, @code{/}, @code{=}, , @code{<>}, @code{#},
8578@code{<=}, and @code{>=} on sets as an error.
8579@end quotation
8580
cb51c4e0 8581
6d2ebf8b 8582@node Built-In Func/Proc
c906108c 8583@subsubsection Built-in functions and procedures
cb51c4e0 8584@cindex Modula-2 built-ins
c906108c
SS
8585
8586Modula-2 also makes available several built-in procedures and functions.
8587In describing these, the following metavariables are used:
8588
8589@table @var
8590
8591@item a
8592represents an @code{ARRAY} variable.
8593
8594@item c
8595represents a @code{CHAR} constant or variable.
8596
8597@item i
8598represents a variable or constant of integral type.
8599
8600@item m
8601represents an identifier that belongs to a set. Generally used in the
8602same function with the metavariable @var{s}. The type of @var{s} should
8603be @code{SET OF @var{mtype}} (where @var{mtype} is the type of @var{m}).
8604
8605@item n
8606represents a variable or constant of integral or floating-point type.
8607
8608@item r
8609represents a variable or constant of floating-point type.
8610
8611@item t
8612represents a type.
8613
8614@item v
8615represents a variable.
8616
8617@item x
8618represents a variable or constant of one of many types. See the
8619explanation of the function for details.
8620@end table
8621
8622All Modula-2 built-in procedures also return a result, described below.
8623
8624@table @code
8625@item ABS(@var{n})
8626Returns the absolute value of @var{n}.
8627
8628@item CAP(@var{c})
8629If @var{c} is a lower case letter, it returns its upper case
c3f6f71d 8630equivalent, otherwise it returns its argument.
c906108c
SS
8631
8632@item CHR(@var{i})
8633Returns the character whose ordinal value is @var{i}.
8634
8635@item DEC(@var{v})
c3f6f71d 8636Decrements the value in the variable @var{v} by one. Returns the new value.
c906108c
SS
8637
8638@item DEC(@var{v},@var{i})
8639Decrements the value in the variable @var{v} by @var{i}. Returns the
8640new value.
8641
8642@item EXCL(@var{m},@var{s})
8643Removes the element @var{m} from the set @var{s}. Returns the new
8644set.
8645
8646@item FLOAT(@var{i})
8647Returns the floating point equivalent of the integer @var{i}.
8648
8649@item HIGH(@var{a})
8650Returns the index of the last member of @var{a}.
8651
8652@item INC(@var{v})
c3f6f71d 8653Increments the value in the variable @var{v} by one. Returns the new value.
c906108c
SS
8654
8655@item INC(@var{v},@var{i})
8656Increments the value in the variable @var{v} by @var{i}. Returns the
8657new value.
8658
8659@item INCL(@var{m},@var{s})
8660Adds the element @var{m} to the set @var{s} if it is not already
8661there. Returns the new set.
8662
8663@item MAX(@var{t})
8664Returns the maximum value of the type @var{t}.
8665
8666@item MIN(@var{t})
8667Returns the minimum value of the type @var{t}.
8668
8669@item ODD(@var{i})
8670Returns boolean TRUE if @var{i} is an odd number.
8671
8672@item ORD(@var{x})
8673Returns the ordinal value of its argument. For example, the ordinal
c3f6f71d
JM
8674value of a character is its @sc{ascii} value (on machines supporting the
8675@sc{ascii} character set). @var{x} must be of an ordered type, which include
c906108c
SS
8676integral, character and enumerated types.
8677
8678@item SIZE(@var{x})
8679Returns the size of its argument. @var{x} can be a variable or a type.
8680
8681@item TRUNC(@var{r})
8682Returns the integral part of @var{r}.
8683
8684@item VAL(@var{t},@var{i})
8685Returns the member of the type @var{t} whose ordinal value is @var{i}.
8686@end table
8687
8688@quotation
8689@emph{Warning:} Sets and their operations are not yet supported, so
8690@value{GDBN} treats the use of procedures @code{INCL} and @code{EXCL} as
8691an error.
8692@end quotation
8693
8694@cindex Modula-2 constants
6d2ebf8b 8695@node M2 Constants
c906108c
SS
8696@subsubsection Constants
8697
8698@value{GDBN} allows you to express the constants of Modula-2 in the following
8699ways:
8700
8701@itemize @bullet
8702
8703@item
8704Integer constants are simply a sequence of digits. When used in an
8705expression, a constant is interpreted to be type-compatible with the
8706rest of the expression. Hexadecimal integers are specified by a
8707trailing @samp{H}, and octal integers by a trailing @samp{B}.
8708
8709@item
8710Floating point constants appear as a sequence of digits, followed by a
8711decimal point and another sequence of digits. An optional exponent can
8712then be specified, in the form @samp{E@r{[}+@r{|}-@r{]}@var{nnn}}, where
8713@samp{@r{[}+@r{|}-@r{]}@var{nnn}} is the desired exponent. All of the
8714digits of the floating point constant must be valid decimal (base 10)
8715digits.
8716
8717@item
8718Character constants consist of a single character enclosed by a pair of
8719like quotes, either single (@code{'}) or double (@code{"}). They may
c3f6f71d 8720also be expressed by their ordinal value (their @sc{ascii} value, usually)
c906108c
SS
8721followed by a @samp{C}.
8722
8723@item
8724String constants consist of a sequence of characters enclosed by a
8725pair of like quotes, either single (@code{'}) or double (@code{"}).
8726Escape sequences in the style of C are also allowed. @xref{C
b37052ae 8727Constants, ,C and C@t{++} constants}, for a brief explanation of escape
c906108c
SS
8728sequences.
8729
8730@item
8731Enumerated constants consist of an enumerated identifier.
8732
8733@item
8734Boolean constants consist of the identifiers @code{TRUE} and
8735@code{FALSE}.
8736
8737@item
8738Pointer constants consist of integral values only.
8739
8740@item
8741Set constants are not yet supported.
8742@end itemize
8743
6d2ebf8b 8744@node M2 Defaults
c906108c
SS
8745@subsubsection Modula-2 defaults
8746@cindex Modula-2 defaults
8747
8748If type and range checking are set automatically by @value{GDBN}, they
8749both default to @code{on} whenever the working language changes to
d4f3574e 8750Modula-2. This happens regardless of whether you or @value{GDBN}
c906108c
SS
8751selected the working language.
8752
8753If you allow @value{GDBN} to set the language automatically, then entering
8754code compiled from a file whose name ends with @file{.mod} sets the
d4f3574e 8755working language to Modula-2. @xref{Automatically, ,Having @value{GDBN} set
c906108c
SS
8756the language automatically}, for further details.
8757
6d2ebf8b 8758@node Deviations
c906108c
SS
8759@subsubsection Deviations from standard Modula-2
8760@cindex Modula-2, deviations from
8761
8762A few changes have been made to make Modula-2 programs easier to debug.
8763This is done primarily via loosening its type strictness:
8764
8765@itemize @bullet
8766@item
8767Unlike in standard Modula-2, pointer constants can be formed by
8768integers. This allows you to modify pointer variables during
8769debugging. (In standard Modula-2, the actual address contained in a
8770pointer variable is hidden from you; it can only be modified
8771through direct assignment to another pointer variable or expression that
8772returned a pointer.)
8773
8774@item
8775C escape sequences can be used in strings and characters to represent
8776non-printable characters. @value{GDBN} prints out strings with these
8777escape sequences embedded. Single non-printable characters are
8778printed using the @samp{CHR(@var{nnn})} format.
8779
8780@item
8781The assignment operator (@code{:=}) returns the value of its right-hand
8782argument.
8783
8784@item
8785All built-in procedures both modify @emph{and} return their argument.
8786@end itemize
8787
6d2ebf8b 8788@node M2 Checks
c906108c
SS
8789@subsubsection Modula-2 type and range checks
8790@cindex Modula-2 checks
8791
8792@quotation
8793@emph{Warning:} in this release, @value{GDBN} does not yet perform type or
8794range checking.
8795@end quotation
8796@c FIXME remove warning when type/range checks added
8797
8798@value{GDBN} considers two Modula-2 variables type equivalent if:
8799
8800@itemize @bullet
8801@item
8802They are of types that have been declared equivalent via a @code{TYPE
8803@var{t1} = @var{t2}} statement
8804
8805@item
8806They have been declared on the same line. (Note: This is true of the
8807@sc{gnu} Modula-2 compiler, but it may not be true of other compilers.)
8808@end itemize
8809
8810As long as type checking is enabled, any attempt to combine variables
8811whose types are not equivalent is an error.
8812
8813Range checking is done on all mathematical operations, assignment, array
8814index bounds, and all built-in functions and procedures.
8815
6d2ebf8b 8816@node M2 Scope
c906108c
SS
8817@subsubsection The scope operators @code{::} and @code{.}
8818@cindex scope
41afff9a 8819@cindex @code{.}, Modula-2 scope operator
c906108c
SS
8820@cindex colon, doubled as scope operator
8821@ifinfo
41afff9a 8822@vindex colon-colon@r{, in Modula-2}
c906108c
SS
8823@c Info cannot handle :: but TeX can.
8824@end ifinfo
8825@iftex
41afff9a 8826@vindex ::@r{, in Modula-2}
c906108c
SS
8827@end iftex
8828
8829There are a few subtle differences between the Modula-2 scope operator
8830(@code{.}) and the @value{GDBN} scope operator (@code{::}). The two have
8831similar syntax:
8832
474c8240 8833@smallexample
c906108c
SS
8834
8835@var{module} . @var{id}
8836@var{scope} :: @var{id}
474c8240 8837@end smallexample
c906108c
SS
8838
8839@noindent
8840where @var{scope} is the name of a module or a procedure,
8841@var{module} the name of a module, and @var{id} is any declared
8842identifier within your program, except another module.
8843
8844Using the @code{::} operator makes @value{GDBN} search the scope
8845specified by @var{scope} for the identifier @var{id}. If it is not
8846found in the specified scope, then @value{GDBN} searches all scopes
8847enclosing the one specified by @var{scope}.
8848
8849Using the @code{.} operator makes @value{GDBN} search the current scope for
8850the identifier specified by @var{id} that was imported from the
8851definition module specified by @var{module}. With this operator, it is
8852an error if the identifier @var{id} was not imported from definition
8853module @var{module}, or if @var{id} is not an identifier in
8854@var{module}.
8855
6d2ebf8b 8856@node GDB/M2
c906108c
SS
8857@subsubsection @value{GDBN} and Modula-2
8858
8859Some @value{GDBN} commands have little use when debugging Modula-2 programs.
8860Five subcommands of @code{set print} and @code{show print} apply
b37052ae 8861specifically to C and C@t{++}: @samp{vtbl}, @samp{demangle},
c906108c 8862@samp{asm-demangle}, @samp{object}, and @samp{union}. The first four
b37052ae 8863apply to C@t{++}, and the last to the C @code{union} type, which has no direct
c906108c
SS
8864analogue in Modula-2.
8865
8866The @code{@@} operator (@pxref{Expressions, ,Expressions}), while available
d4f3574e 8867with any language, is not useful with Modula-2. Its
c906108c 8868intent is to aid the debugging of @dfn{dynamic arrays}, which cannot be
b37052ae 8869created in Modula-2 as they can in C or C@t{++}. However, because an
c906108c 8870address can be specified by an integral constant, the construct
d4f3574e 8871@samp{@{@var{type}@}@var{adrexp}} is still useful.
c906108c
SS
8872
8873@cindex @code{#} in Modula-2
8874In @value{GDBN} scripts, the Modula-2 inequality operator @code{#} is
8875interpreted as the beginning of a comment. Use @code{<>} instead.
c906108c 8876
4e562065
JB
8877@node Unsupported languages
8878@section Unsupported languages
8879
8880@cindex unsupported languages
8881@cindex minimal language
8882In addition to the other fully-supported programming languages,
8883@value{GDBN} also provides a pseudo-language, called @code{minimal}.
8884It does not represent a real programming language, but provides a set
8885of capabilities close to what the C or assembly languages provide.
8886This should allow most simple operations to be performed while debugging
8887an application that uses a language currently not supported by @value{GDBN}.
8888
8889If the language is set to @code{auto}, @value{GDBN} will automatically
8890select this language if the current frame corresponds to an unsupported
8891language.
8892
6d2ebf8b 8893@node Symbols
c906108c
SS
8894@chapter Examining the Symbol Table
8895
d4f3574e 8896The commands described in this chapter allow you to inquire about the
c906108c
SS
8897symbols (names of variables, functions and types) defined in your
8898program. This information is inherent in the text of your program and
8899does not change as your program executes. @value{GDBN} finds it in your
8900program's symbol table, in the file indicated when you started @value{GDBN}
8901(@pxref{File Options, ,Choosing files}), or by one of the
8902file-management commands (@pxref{Files, ,Commands to specify files}).
8903
8904@cindex symbol names
8905@cindex names of symbols
8906@cindex quoting names
8907Occasionally, you may need to refer to symbols that contain unusual
8908characters, which @value{GDBN} ordinarily treats as word delimiters. The
8909most frequent case is in referring to static variables in other
8910source files (@pxref{Variables,,Program variables}). File names
8911are recorded in object files as debugging symbols, but @value{GDBN} would
8912ordinarily parse a typical file name, like @file{foo.c}, as the three words
8913@samp{foo} @samp{.} @samp{c}. To allow @value{GDBN} to recognize
8914@samp{foo.c} as a single symbol, enclose it in single quotes; for example,
8915
474c8240 8916@smallexample
c906108c 8917p 'foo.c'::x
474c8240 8918@end smallexample
c906108c
SS
8919
8920@noindent
8921looks up the value of @code{x} in the scope of the file @file{foo.c}.
8922
8923@table @code
8924@kindex info address
b37052ae 8925@cindex address of a symbol
c906108c
SS
8926@item info address @var{symbol}
8927Describe where the data for @var{symbol} is stored. For a register
8928variable, this says which register it is kept in. For a non-register
8929local variable, this prints the stack-frame offset at which the variable
8930is always stored.
8931
8932Note the contrast with @samp{print &@var{symbol}}, which does not work
8933at all for a register variable, and for a stack local variable prints
8934the exact address of the current instantiation of the variable.
8935
3d67e040 8936@kindex info symbol
b37052ae 8937@cindex symbol from address
3d67e040
EZ
8938@item info symbol @var{addr}
8939Print the name of a symbol which is stored at the address @var{addr}.
8940If no symbol is stored exactly at @var{addr}, @value{GDBN} prints the
8941nearest symbol and an offset from it:
8942
474c8240 8943@smallexample
3d67e040
EZ
8944(@value{GDBP}) info symbol 0x54320
8945_initialize_vx + 396 in section .text
474c8240 8946@end smallexample
3d67e040
EZ
8947
8948@noindent
8949This is the opposite of the @code{info address} command. You can use
8950it to find out the name of a variable or a function given its address.
8951
c906108c 8952@kindex whatis
d4f3574e
SS
8953@item whatis @var{expr}
8954Print the data type of expression @var{expr}. @var{expr} is not
c906108c
SS
8955actually evaluated, and any side-effecting operations (such as
8956assignments or function calls) inside it do not take place.
8957@xref{Expressions, ,Expressions}.
8958
8959@item whatis
8960Print the data type of @code{$}, the last value in the value history.
8961
8962@kindex ptype
8963@item ptype @var{typename}
8964Print a description of data type @var{typename}. @var{typename} may be
7a292a7a
SS
8965the name of a type, or for C code it may have the form @samp{class
8966@var{class-name}}, @samp{struct @var{struct-tag}}, @samp{union
8967@var{union-tag}} or @samp{enum @var{enum-tag}}.
c906108c 8968
d4f3574e 8969@item ptype @var{expr}
c906108c 8970@itemx ptype
d4f3574e 8971Print a description of the type of expression @var{expr}. @code{ptype}
c906108c
SS
8972differs from @code{whatis} by printing a detailed description, instead
8973of just the name of the type.
8974
8975For example, for this variable declaration:
8976
474c8240 8977@smallexample
c906108c 8978struct complex @{double real; double imag;@} v;
474c8240 8979@end smallexample
c906108c
SS
8980
8981@noindent
8982the two commands give this output:
8983
474c8240 8984@smallexample
c906108c
SS
8985@group
8986(@value{GDBP}) whatis v
8987type = struct complex
8988(@value{GDBP}) ptype v
8989type = struct complex @{
8990 double real;
8991 double imag;
8992@}
8993@end group
474c8240 8994@end smallexample
c906108c
SS
8995
8996@noindent
8997As with @code{whatis}, using @code{ptype} without an argument refers to
8998the type of @code{$}, the last value in the value history.
8999
9000@kindex info types
9001@item info types @var{regexp}
9002@itemx info types
d4f3574e 9003Print a brief description of all types whose names match @var{regexp}
c906108c
SS
9004(or all types in your program, if you supply no argument). Each
9005complete typename is matched as though it were a complete line; thus,
9006@samp{i type value} gives information on all types in your program whose
d4f3574e 9007names include the string @code{value}, but @samp{i type ^value$} gives
c906108c
SS
9008information only on types whose complete name is @code{value}.
9009
9010This command differs from @code{ptype} in two ways: first, like
9011@code{whatis}, it does not print a detailed description; second, it
9012lists all source files where a type is defined.
9013
b37052ae
EZ
9014@kindex info scope
9015@cindex local variables
9016@item info scope @var{addr}
9017List all the variables local to a particular scope. This command
9018accepts a location---a function name, a source line, or an address
9019preceded by a @samp{*}, and prints all the variables local to the
9020scope defined by that location. For example:
9021
9022@smallexample
9023(@value{GDBP}) @b{info scope command_line_handler}
9024Scope for command_line_handler:
9025Symbol rl is an argument at stack/frame offset 8, length 4.
9026Symbol linebuffer is in static storage at address 0x150a18, length 4.
9027Symbol linelength is in static storage at address 0x150a1c, length 4.
9028Symbol p is a local variable in register $esi, length 4.
9029Symbol p1 is a local variable in register $ebx, length 4.
9030Symbol nline is a local variable in register $edx, length 4.
9031Symbol repeat is a local variable at frame offset -8, length 4.
9032@end smallexample
9033
f5c37c66
EZ
9034@noindent
9035This command is especially useful for determining what data to collect
9036during a @dfn{trace experiment}, see @ref{Tracepoint Actions,
9037collect}.
9038
c906108c
SS
9039@kindex info source
9040@item info source
919d772c
JB
9041Show information about the current source file---that is, the source file for
9042the function containing the current point of execution:
9043@itemize @bullet
9044@item
9045the name of the source file, and the directory containing it,
9046@item
9047the directory it was compiled in,
9048@item
9049its length, in lines,
9050@item
9051which programming language it is written in,
9052@item
9053whether the executable includes debugging information for that file, and
9054if so, what format the information is in (e.g., STABS, Dwarf 2, etc.), and
9055@item
9056whether the debugging information includes information about
9057preprocessor macros.
9058@end itemize
9059
c906108c
SS
9060
9061@kindex info sources
9062@item info sources
9063Print the names of all source files in your program for which there is
9064debugging information, organized into two lists: files whose symbols
9065have already been read, and files whose symbols will be read when needed.
9066
9067@kindex info functions
9068@item info functions
9069Print the names and data types of all defined functions.
9070
9071@item info functions @var{regexp}
9072Print the names and data types of all defined functions
9073whose names contain a match for regular expression @var{regexp}.
9074Thus, @samp{info fun step} finds all functions whose names
9075include @code{step}; @samp{info fun ^step} finds those whose names
1c5dfdad
MS
9076start with @code{step}. If a function name contains characters
9077that conflict with the regular expression language (eg.
9078@samp{operator*()}), they may be quoted with a backslash.
c906108c
SS
9079
9080@kindex info variables
9081@item info variables
9082Print the names and data types of all variables that are declared
6ca652b0 9083outside of functions (i.e.@: excluding local variables).
c906108c
SS
9084
9085@item info variables @var{regexp}
9086Print the names and data types of all variables (except for local
9087variables) whose names contain a match for regular expression
9088@var{regexp}.
9089
b37303ee
AF
9090@kindex info classes
9091@item info classes
9092@itemx info classes @var{regexp}
9093Display all Objective-C classes in your program, or
9094(with the @var{regexp} argument) all those matching a particular regular
9095expression.
9096
9097@kindex info selectors
9098@item info selectors
9099@itemx info selectors @var{regexp}
9100Display all Objective-C selectors in your program, or
9101(with the @var{regexp} argument) all those matching a particular regular
9102expression.
9103
c906108c
SS
9104@ignore
9105This was never implemented.
9106@kindex info methods
9107@item info methods
9108@itemx info methods @var{regexp}
9109The @code{info methods} command permits the user to examine all defined
b37052ae
EZ
9110methods within C@t{++} program, or (with the @var{regexp} argument) a
9111specific set of methods found in the various C@t{++} classes. Many
9112C@t{++} classes provide a large number of methods. Thus, the output
c906108c
SS
9113from the @code{ptype} command can be overwhelming and hard to use. The
9114@code{info-methods} command filters the methods, printing only those
9115which match the regular-expression @var{regexp}.
9116@end ignore
9117
c906108c
SS
9118@cindex reloading symbols
9119Some systems allow individual object files that make up your program to
7a292a7a
SS
9120be replaced without stopping and restarting your program. For example,
9121in VxWorks you can simply recompile a defective object file and keep on
9122running. If you are running on one of these systems, you can allow
9123@value{GDBN} to reload the symbols for automatically relinked modules:
c906108c
SS
9124
9125@table @code
9126@kindex set symbol-reloading
9127@item set symbol-reloading on
9128Replace symbol definitions for the corresponding source file when an
9129object file with a particular name is seen again.
9130
9131@item set symbol-reloading off
6d2ebf8b
SS
9132Do not replace symbol definitions when encountering object files of the
9133same name more than once. This is the default state; if you are not
9134running on a system that permits automatic relinking of modules, you
9135should leave @code{symbol-reloading} off, since otherwise @value{GDBN}
9136may discard symbols when linking large programs, that may contain
9137several modules (from different directories or libraries) with the same
9138name.
c906108c
SS
9139
9140@kindex show symbol-reloading
9141@item show symbol-reloading
9142Show the current @code{on} or @code{off} setting.
9143@end table
c906108c 9144
c906108c
SS
9145@kindex set opaque-type-resolution
9146@item set opaque-type-resolution on
9147Tell @value{GDBN} to resolve opaque types. An opaque type is a type
9148declared as a pointer to a @code{struct}, @code{class}, or
9149@code{union}---for example, @code{struct MyType *}---that is used in one
9150source file although the full declaration of @code{struct MyType} is in
9151another source file. The default is on.
9152
9153A change in the setting of this subcommand will not take effect until
9154the next time symbols for a file are loaded.
9155
9156@item set opaque-type-resolution off
9157Tell @value{GDBN} not to resolve opaque types. In this case, the type
9158is printed as follows:
9159@smallexample
9160@{<no data fields>@}
9161@end smallexample
9162
9163@kindex show opaque-type-resolution
9164@item show opaque-type-resolution
9165Show whether opaque types are resolved or not.
c906108c
SS
9166
9167@kindex maint print symbols
9168@cindex symbol dump
9169@kindex maint print psymbols
9170@cindex partial symbol dump
9171@item maint print symbols @var{filename}
9172@itemx maint print psymbols @var{filename}
9173@itemx maint print msymbols @var{filename}
9174Write a dump of debugging symbol data into the file @var{filename}.
9175These commands are used to debug the @value{GDBN} symbol-reading code. Only
9176symbols with debugging data are included. If you use @samp{maint print
9177symbols}, @value{GDBN} includes all the symbols for which it has already
9178collected full details: that is, @var{filename} reflects symbols for
9179only those files whose symbols @value{GDBN} has read. You can use the
9180command @code{info sources} to find out which files these are. If you
9181use @samp{maint print psymbols} instead, the dump shows information about
9182symbols that @value{GDBN} only knows partially---that is, symbols defined in
9183files that @value{GDBN} has skimmed, but not yet read completely. Finally,
9184@samp{maint print msymbols} dumps just the minimal symbol information
9185required for each object file from which @value{GDBN} has read some symbols.
9186@xref{Files, ,Commands to specify files}, for a discussion of how
9187@value{GDBN} reads symbols (in the description of @code{symbol-file}).
44ea7b70 9188
5e7b2f39
JB
9189@kindex maint info symtabs
9190@kindex maint info psymtabs
44ea7b70
JB
9191@cindex listing @value{GDBN}'s internal symbol tables
9192@cindex symbol tables, listing @value{GDBN}'s internal
9193@cindex full symbol tables, listing @value{GDBN}'s internal
9194@cindex partial symbol tables, listing @value{GDBN}'s internal
5e7b2f39
JB
9195@item maint info symtabs @r{[} @var{regexp} @r{]}
9196@itemx maint info psymtabs @r{[} @var{regexp} @r{]}
44ea7b70
JB
9197
9198List the @code{struct symtab} or @code{struct partial_symtab}
9199structures whose names match @var{regexp}. If @var{regexp} is not
9200given, list them all. The output includes expressions which you can
9201copy into a @value{GDBN} debugging this one to examine a particular
9202structure in more detail. For example:
9203
9204@smallexample
5e7b2f39 9205(@value{GDBP}) maint info psymtabs dwarf2read
44ea7b70
JB
9206@{ objfile /home/gnu/build/gdb/gdb
9207 ((struct objfile *) 0x82e69d0)
9208 @{ psymtab /home/gnu/src/gdb/dwarf2read.c
9209 ((struct partial_symtab *) 0x8474b10)
9210 readin no
9211 fullname (null)
9212 text addresses 0x814d3c8 -- 0x8158074
9213 globals (* (struct partial_symbol **) 0x8507a08 @@ 9)
9214 statics (* (struct partial_symbol **) 0x40e95b78 @@ 2882)
9215 dependencies (none)
9216 @}
9217@}
5e7b2f39 9218(@value{GDBP}) maint info symtabs
44ea7b70
JB
9219(@value{GDBP})
9220@end smallexample
9221@noindent
9222We see that there is one partial symbol table whose filename contains
9223the string @samp{dwarf2read}, belonging to the @samp{gdb} executable;
9224and we see that @value{GDBN} has not read in any symtabs yet at all.
9225If we set a breakpoint on a function, that will cause @value{GDBN} to
9226read the symtab for the compilation unit containing that function:
9227
9228@smallexample
9229(@value{GDBP}) break dwarf2_psymtab_to_symtab
9230Breakpoint 1 at 0x814e5da: file /home/gnu/src/gdb/dwarf2read.c,
9231line 1574.
5e7b2f39 9232(@value{GDBP}) maint info symtabs
44ea7b70
JB
9233@{ objfile /home/gnu/build/gdb/gdb
9234 ((struct objfile *) 0x82e69d0)
9235 @{ symtab /home/gnu/src/gdb/dwarf2read.c
9236 ((struct symtab *) 0x86c1f38)
9237 dirname (null)
9238 fullname (null)
9239 blockvector ((struct blockvector *) 0x86c1bd0) (primary)
9240 debugformat DWARF 2
9241 @}
9242@}
9243(@value{GDBP})
9244@end smallexample
c906108c
SS
9245@end table
9246
44ea7b70 9247
6d2ebf8b 9248@node Altering
c906108c
SS
9249@chapter Altering Execution
9250
9251Once you think you have found an error in your program, you might want to
9252find out for certain whether correcting the apparent error would lead to
9253correct results in the rest of the run. You can find the answer by
9254experiment, using the @value{GDBN} features for altering execution of the
9255program.
9256
9257For example, you can store new values into variables or memory
7a292a7a
SS
9258locations, give your program a signal, restart it at a different
9259address, or even return prematurely from a function.
c906108c
SS
9260
9261@menu
9262* Assignment:: Assignment to variables
9263* Jumping:: Continuing at a different address
c906108c 9264* Signaling:: Giving your program a signal
c906108c
SS
9265* Returning:: Returning from a function
9266* Calling:: Calling your program's functions
9267* Patching:: Patching your program
9268@end menu
9269
6d2ebf8b 9270@node Assignment
c906108c
SS
9271@section Assignment to variables
9272
9273@cindex assignment
9274@cindex setting variables
9275To alter the value of a variable, evaluate an assignment expression.
9276@xref{Expressions, ,Expressions}. For example,
9277
474c8240 9278@smallexample
c906108c 9279print x=4
474c8240 9280@end smallexample
c906108c
SS
9281
9282@noindent
9283stores the value 4 into the variable @code{x}, and then prints the
5d161b24 9284value of the assignment expression (which is 4).
c906108c
SS
9285@xref{Languages, ,Using @value{GDBN} with Different Languages}, for more
9286information on operators in supported languages.
c906108c
SS
9287
9288@kindex set variable
9289@cindex variables, setting
9290If you are not interested in seeing the value of the assignment, use the
9291@code{set} command instead of the @code{print} command. @code{set} is
9292really the same as @code{print} except that the expression's value is
9293not printed and is not put in the value history (@pxref{Value History,
9294,Value history}). The expression is evaluated only for its effects.
9295
c906108c
SS
9296If the beginning of the argument string of the @code{set} command
9297appears identical to a @code{set} subcommand, use the @code{set
9298variable} command instead of just @code{set}. This command is identical
9299to @code{set} except for its lack of subcommands. For example, if your
9300program has a variable @code{width}, you get an error if you try to set
9301a new value with just @samp{set width=13}, because @value{GDBN} has the
9302command @code{set width}:
9303
474c8240 9304@smallexample
c906108c
SS
9305(@value{GDBP}) whatis width
9306type = double
9307(@value{GDBP}) p width
9308$4 = 13
9309(@value{GDBP}) set width=47
9310Invalid syntax in expression.
474c8240 9311@end smallexample
c906108c
SS
9312
9313@noindent
9314The invalid expression, of course, is @samp{=47}. In
9315order to actually set the program's variable @code{width}, use
9316
474c8240 9317@smallexample
c906108c 9318(@value{GDBP}) set var width=47
474c8240 9319@end smallexample
53a5351d 9320
c906108c
SS
9321Because the @code{set} command has many subcommands that can conflict
9322with the names of program variables, it is a good idea to use the
9323@code{set variable} command instead of just @code{set}. For example, if
9324your program has a variable @code{g}, you run into problems if you try
9325to set a new value with just @samp{set g=4}, because @value{GDBN} has
9326the command @code{set gnutarget}, abbreviated @code{set g}:
9327
474c8240 9328@smallexample
c906108c
SS
9329@group
9330(@value{GDBP}) whatis g
9331type = double
9332(@value{GDBP}) p g
9333$1 = 1
9334(@value{GDBP}) set g=4
2df3850c 9335(@value{GDBP}) p g
c906108c
SS
9336$2 = 1
9337(@value{GDBP}) r
9338The program being debugged has been started already.
9339Start it from the beginning? (y or n) y
9340Starting program: /home/smith/cc_progs/a.out
6d2ebf8b
SS
9341"/home/smith/cc_progs/a.out": can't open to read symbols:
9342 Invalid bfd target.
c906108c
SS
9343(@value{GDBP}) show g
9344The current BFD target is "=4".
9345@end group
474c8240 9346@end smallexample
c906108c
SS
9347
9348@noindent
9349The program variable @code{g} did not change, and you silently set the
9350@code{gnutarget} to an invalid value. In order to set the variable
9351@code{g}, use
9352
474c8240 9353@smallexample
c906108c 9354(@value{GDBP}) set var g=4
474c8240 9355@end smallexample
c906108c
SS
9356
9357@value{GDBN} allows more implicit conversions in assignments than C; you can
9358freely store an integer value into a pointer variable or vice versa,
9359and you can convert any structure to any other structure that is the
9360same length or shorter.
9361@comment FIXME: how do structs align/pad in these conversions?
9362@comment /doc@cygnus.com 18dec1990
9363
9364To store values into arbitrary places in memory, use the @samp{@{@dots{}@}}
9365construct to generate a value of specified type at a specified address
9366(@pxref{Expressions, ,Expressions}). For example, @code{@{int@}0x83040} refers
9367to memory location @code{0x83040} as an integer (which implies a certain size
9368and representation in memory), and
9369
474c8240 9370@smallexample
c906108c 9371set @{int@}0x83040 = 4
474c8240 9372@end smallexample
c906108c
SS
9373
9374@noindent
9375stores the value 4 into that memory location.
9376
6d2ebf8b 9377@node Jumping
c906108c
SS
9378@section Continuing at a different address
9379
9380Ordinarily, when you continue your program, you do so at the place where
9381it stopped, with the @code{continue} command. You can instead continue at
9382an address of your own choosing, with the following commands:
9383
9384@table @code
9385@kindex jump
9386@item jump @var{linespec}
9387Resume execution at line @var{linespec}. Execution stops again
9388immediately if there is a breakpoint there. @xref{List, ,Printing
9389source lines}, for a description of the different forms of
9390@var{linespec}. It is common practice to use the @code{tbreak} command
9391in conjunction with @code{jump}. @xref{Set Breaks, ,Setting
9392breakpoints}.
9393
9394The @code{jump} command does not change the current stack frame, or
9395the stack pointer, or the contents of any memory location or any
9396register other than the program counter. If line @var{linespec} is in
9397a different function from the one currently executing, the results may
9398be bizarre if the two functions expect different patterns of arguments or
9399of local variables. For this reason, the @code{jump} command requests
9400confirmation if the specified line is not in the function currently
9401executing. However, even bizarre results are predictable if you are
9402well acquainted with the machine-language code of your program.
9403
9404@item jump *@var{address}
9405Resume execution at the instruction at address @var{address}.
9406@end table
9407
c906108c 9408@c Doesn't work on HP-UX; have to set $pcoqh and $pcoqt.
53a5351d
JM
9409On many systems, you can get much the same effect as the @code{jump}
9410command by storing a new value into the register @code{$pc}. The
9411difference is that this does not start your program running; it only
9412changes the address of where it @emph{will} run when you continue. For
9413example,
c906108c 9414
474c8240 9415@smallexample
c906108c 9416set $pc = 0x485
474c8240 9417@end smallexample
c906108c
SS
9418
9419@noindent
9420makes the next @code{continue} command or stepping command execute at
9421address @code{0x485}, rather than at the address where your program stopped.
9422@xref{Continuing and Stepping, ,Continuing and stepping}.
c906108c
SS
9423
9424The most common occasion to use the @code{jump} command is to back
9425up---perhaps with more breakpoints set---over a portion of a program
9426that has already executed, in order to examine its execution in more
9427detail.
9428
c906108c 9429@c @group
6d2ebf8b 9430@node Signaling
c906108c
SS
9431@section Giving your program a signal
9432
9433@table @code
9434@kindex signal
9435@item signal @var{signal}
9436Resume execution where your program stopped, but immediately give it the
9437signal @var{signal}. @var{signal} can be the name or the number of a
9438signal. For example, on many systems @code{signal 2} and @code{signal
9439SIGINT} are both ways of sending an interrupt signal.
9440
9441Alternatively, if @var{signal} is zero, continue execution without
9442giving a signal. This is useful when your program stopped on account of
9443a signal and would ordinary see the signal when resumed with the
9444@code{continue} command; @samp{signal 0} causes it to resume without a
9445signal.
9446
9447@code{signal} does not repeat when you press @key{RET} a second time
9448after executing the command.
9449@end table
9450@c @end group
9451
9452Invoking the @code{signal} command is not the same as invoking the
9453@code{kill} utility from the shell. Sending a signal with @code{kill}
9454causes @value{GDBN} to decide what to do with the signal depending on
9455the signal handling tables (@pxref{Signals}). The @code{signal} command
9456passes the signal directly to your program.
9457
c906108c 9458
6d2ebf8b 9459@node Returning
c906108c
SS
9460@section Returning from a function
9461
9462@table @code
9463@cindex returning from a function
9464@kindex return
9465@item return
9466@itemx return @var{expression}
9467You can cancel execution of a function call with the @code{return}
9468command. If you give an
9469@var{expression} argument, its value is used as the function's return
9470value.
9471@end table
9472
9473When you use @code{return}, @value{GDBN} discards the selected stack frame
9474(and all frames within it). You can think of this as making the
9475discarded frame return prematurely. If you wish to specify a value to
9476be returned, give that value as the argument to @code{return}.
9477
9478This pops the selected stack frame (@pxref{Selection, ,Selecting a
9479frame}), and any other frames inside of it, leaving its caller as the
9480innermost remaining frame. That frame becomes selected. The
9481specified value is stored in the registers used for returning values
9482of functions.
9483
9484The @code{return} command does not resume execution; it leaves the
9485program stopped in the state that would exist if the function had just
9486returned. In contrast, the @code{finish} command (@pxref{Continuing
9487and Stepping, ,Continuing and stepping}) resumes execution until the
9488selected stack frame returns naturally.
9489
6d2ebf8b 9490@node Calling
c906108c
SS
9491@section Calling program functions
9492
9493@cindex calling functions
9494@kindex call
9495@table @code
9496@item call @var{expr}
9497Evaluate the expression @var{expr} without displaying @code{void}
9498returned values.
9499@end table
9500
9501You can use this variant of the @code{print} command if you want to
9502execute a function from your program, but without cluttering the output
5d161b24
DB
9503with @code{void} returned values. If the result is not void, it
9504is printed and saved in the value history.
c906108c 9505
6d2ebf8b 9506@node Patching
c906108c 9507@section Patching programs
7a292a7a 9508
c906108c
SS
9509@cindex patching binaries
9510@cindex writing into executables
c906108c 9511@cindex writing into corefiles
c906108c 9512
7a292a7a
SS
9513By default, @value{GDBN} opens the file containing your program's
9514executable code (or the corefile) read-only. This prevents accidental
9515alterations to machine code; but it also prevents you from intentionally
9516patching your program's binary.
c906108c
SS
9517
9518If you'd like to be able to patch the binary, you can specify that
9519explicitly with the @code{set write} command. For example, you might
9520want to turn on internal debugging flags, or even to make emergency
9521repairs.
9522
9523@table @code
9524@kindex set write
9525@item set write on
9526@itemx set write off
7a292a7a
SS
9527If you specify @samp{set write on}, @value{GDBN} opens executable and
9528core files for both reading and writing; if you specify @samp{set write
c906108c
SS
9529off} (the default), @value{GDBN} opens them read-only.
9530
9531If you have already loaded a file, you must load it again (using the
7a292a7a
SS
9532@code{exec-file} or @code{core-file} command) after changing @code{set
9533write}, for your new setting to take effect.
c906108c
SS
9534
9535@item show write
9536@kindex show write
7a292a7a
SS
9537Display whether executable files and core files are opened for writing
9538as well as reading.
c906108c
SS
9539@end table
9540
6d2ebf8b 9541@node GDB Files
c906108c
SS
9542@chapter @value{GDBN} Files
9543
7a292a7a
SS
9544@value{GDBN} needs to know the file name of the program to be debugged,
9545both in order to read its symbol table and in order to start your
9546program. To debug a core dump of a previous run, you must also tell
9547@value{GDBN} the name of the core dump file.
c906108c
SS
9548
9549@menu
9550* Files:: Commands to specify files
5b5d99cf 9551* Separate Debug Files:: Debugging information in separate files
c906108c
SS
9552* Symbol Errors:: Errors reading symbol files
9553@end menu
9554
6d2ebf8b 9555@node Files
c906108c 9556@section Commands to specify files
c906108c 9557
7a292a7a 9558@cindex symbol table
c906108c 9559@cindex core dump file
7a292a7a
SS
9560
9561You may want to specify executable and core dump file names. The usual
9562way to do this is at start-up time, using the arguments to
9563@value{GDBN}'s start-up commands (@pxref{Invocation, , Getting In and
9564Out of @value{GDBN}}).
c906108c
SS
9565
9566Occasionally it is necessary to change to a different file during a
9567@value{GDBN} session. Or you may run @value{GDBN} and forget to specify
9568a file you want to use. In these situations the @value{GDBN} commands
9569to specify new files are useful.
9570
9571@table @code
9572@cindex executable file
9573@kindex file
9574@item file @var{filename}
9575Use @var{filename} as the program to be debugged. It is read for its
9576symbols and for the contents of pure memory. It is also the program
9577executed when you use the @code{run} command. If you do not specify a
5d161b24
DB
9578directory and the file is not found in the @value{GDBN} working directory,
9579@value{GDBN} uses the environment variable @code{PATH} as a list of
9580directories to search, just as the shell does when looking for a program
9581to run. You can change the value of this variable, for both @value{GDBN}
c906108c
SS
9582and your program, using the @code{path} command.
9583
6d2ebf8b 9584On systems with memory-mapped files, an auxiliary file named
c906108c
SS
9585@file{@var{filename}.syms} may hold symbol table information for
9586@var{filename}. If so, @value{GDBN} maps in the symbol table from
9587@file{@var{filename}.syms}, starting up more quickly. See the
9588descriptions of the file options @samp{-mapped} and @samp{-readnow}
9589(available on the command line, and with the commands @code{file},
5d161b24 9590@code{symbol-file}, or @code{add-symbol-file}, described below),
c906108c 9591for more information.
c906108c
SS
9592
9593@item file
9594@code{file} with no argument makes @value{GDBN} discard any information it
9595has on both executable file and the symbol table.
9596
9597@kindex exec-file
9598@item exec-file @r{[} @var{filename} @r{]}
9599Specify that the program to be run (but not the symbol table) is found
9600in @var{filename}. @value{GDBN} searches the environment variable @code{PATH}
9601if necessary to locate your program. Omitting @var{filename} means to
9602discard information on the executable file.
9603
9604@kindex symbol-file
9605@item symbol-file @r{[} @var{filename} @r{]}
9606Read symbol table information from file @var{filename}. @code{PATH} is
9607searched when necessary. Use the @code{file} command to get both symbol
9608table and program to run from the same file.
9609
9610@code{symbol-file} with no argument clears out @value{GDBN} information on your
9611program's symbol table.
9612
5d161b24 9613The @code{symbol-file} command causes @value{GDBN} to forget the contents
c906108c
SS
9614of its convenience variables, the value history, and all breakpoints and
9615auto-display expressions. This is because they may contain pointers to
9616the internal data recording symbols and data types, which are part of
9617the old symbol table data being discarded inside @value{GDBN}.
9618
9619@code{symbol-file} does not repeat if you press @key{RET} again after
9620executing it once.
9621
9622When @value{GDBN} is configured for a particular environment, it
9623understands debugging information in whatever format is the standard
9624generated for that environment; you may use either a @sc{gnu} compiler, or
9625other compilers that adhere to the local conventions.
c906108c
SS
9626Best results are usually obtained from @sc{gnu} compilers; for example,
9627using @code{@value{GCC}} you can generate debugging information for
9628optimized code.
c906108c
SS
9629
9630For most kinds of object files, with the exception of old SVR3 systems
9631using COFF, the @code{symbol-file} command does not normally read the
9632symbol table in full right away. Instead, it scans the symbol table
9633quickly to find which source files and which symbols are present. The
9634details are read later, one source file at a time, as they are needed.
9635
9636The purpose of this two-stage reading strategy is to make @value{GDBN}
9637start up faster. For the most part, it is invisible except for
9638occasional pauses while the symbol table details for a particular source
9639file are being read. (The @code{set verbose} command can turn these
9640pauses into messages if desired. @xref{Messages/Warnings, ,Optional
9641warnings and messages}.)
9642
c906108c
SS
9643We have not implemented the two-stage strategy for COFF yet. When the
9644symbol table is stored in COFF format, @code{symbol-file} reads the
9645symbol table data in full right away. Note that ``stabs-in-COFF''
9646still does the two-stage strategy, since the debug info is actually
9647in stabs format.
9648
9649@kindex readnow
9650@cindex reading symbols immediately
9651@cindex symbols, reading immediately
9652@kindex mapped
9653@cindex memory-mapped symbol file
9654@cindex saving symbol table
9655@item symbol-file @var{filename} @r{[} -readnow @r{]} @r{[} -mapped @r{]}
9656@itemx file @var{filename} @r{[} -readnow @r{]} @r{[} -mapped @r{]}
9657You can override the @value{GDBN} two-stage strategy for reading symbol
9658tables by using the @samp{-readnow} option with any of the commands that
9659load symbol table information, if you want to be sure @value{GDBN} has the
5d161b24 9660entire symbol table available.
c906108c 9661
c906108c
SS
9662If memory-mapped files are available on your system through the
9663@code{mmap} system call, you can use another option, @samp{-mapped}, to
9664cause @value{GDBN} to write the symbols for your program into a reusable
9665file. Future @value{GDBN} debugging sessions map in symbol information
9666from this auxiliary symbol file (if the program has not changed), rather
9667than spending time reading the symbol table from the executable
9668program. Using the @samp{-mapped} option has the same effect as
9669starting @value{GDBN} with the @samp{-mapped} command-line option.
9670
9671You can use both options together, to make sure the auxiliary symbol
9672file has all the symbol information for your program.
9673
9674The auxiliary symbol file for a program called @var{myprog} is called
9675@samp{@var{myprog}.syms}. Once this file exists (so long as it is newer
9676than the corresponding executable), @value{GDBN} always attempts to use
9677it when you debug @var{myprog}; no special options or commands are
9678needed.
9679
9680The @file{.syms} file is specific to the host machine where you run
9681@value{GDBN}. It holds an exact image of the internal @value{GDBN}
9682symbol table. It cannot be shared across multiple host platforms.
c906108c
SS
9683
9684@c FIXME: for now no mention of directories, since this seems to be in
9685@c flux. 13mar1992 status is that in theory GDB would look either in
9686@c current dir or in same dir as myprog; but issues like competing
9687@c GDB's, or clutter in system dirs, mean that in practice right now
9688@c only current dir is used. FFish says maybe a special GDB hierarchy
9689@c (eg rooted in val of env var GDBSYMS) could exist for mappable symbol
9690@c files.
9691
9692@kindex core
9693@kindex core-file
9694@item core-file @r{[} @var{filename} @r{]}
9695Specify the whereabouts of a core dump file to be used as the ``contents
9696of memory''. Traditionally, core files contain only some parts of the
9697address space of the process that generated them; @value{GDBN} can access the
9698executable file itself for other parts.
9699
9700@code{core-file} with no argument specifies that no core file is
9701to be used.
9702
9703Note that the core file is ignored when your program is actually running
7a292a7a
SS
9704under @value{GDBN}. So, if you have been running your program and you
9705wish to debug a core file instead, you must kill the subprocess in which
9706the program is running. To do this, use the @code{kill} command
c906108c 9707(@pxref{Kill Process, ,Killing the child process}).
c906108c 9708
c906108c
SS
9709@kindex add-symbol-file
9710@cindex dynamic linking
9711@item add-symbol-file @var{filename} @var{address}
9712@itemx add-symbol-file @var{filename} @var{address} @r{[} -readnow @r{]} @r{[} -mapped @r{]}
17d9d558 9713@itemx add-symbol-file @var{filename} @r{-s}@var{section} @var{address} @dots{}
96a2c332
SS
9714The @code{add-symbol-file} command reads additional symbol table
9715information from the file @var{filename}. You would use this command
9716when @var{filename} has been dynamically loaded (by some other means)
9717into the program that is running. @var{address} should be the memory
9718address at which the file has been loaded; @value{GDBN} cannot figure
d167840f
EZ
9719this out for itself. You can additionally specify an arbitrary number
9720of @samp{@r{-s}@var{section} @var{address}} pairs, to give an explicit
9721section name and base address for that section. You can specify any
9722@var{address} as an expression.
c906108c
SS
9723
9724The symbol table of the file @var{filename} is added to the symbol table
9725originally read with the @code{symbol-file} command. You can use the
96a2c332
SS
9726@code{add-symbol-file} command any number of times; the new symbol data
9727thus read keeps adding to the old. To discard all old symbol data
9728instead, use the @code{symbol-file} command without any arguments.
c906108c 9729
17d9d558
JB
9730@cindex relocatable object files, reading symbols from
9731@cindex object files, relocatable, reading symbols from
9732@cindex reading symbols from relocatable object files
9733@cindex symbols, reading from relocatable object files
9734@cindex @file{.o} files, reading symbols from
9735Although @var{filename} is typically a shared library file, an
9736executable file, or some other object file which has been fully
9737relocated for loading into a process, you can also load symbolic
9738information from relocatable @file{.o} files, as long as:
9739
9740@itemize @bullet
9741@item
9742the file's symbolic information refers only to linker symbols defined in
9743that file, not to symbols defined by other object files,
9744@item
9745every section the file's symbolic information refers to has actually
9746been loaded into the inferior, as it appears in the file, and
9747@item
9748you can determine the address at which every section was loaded, and
9749provide these to the @code{add-symbol-file} command.
9750@end itemize
9751
9752@noindent
9753Some embedded operating systems, like Sun Chorus and VxWorks, can load
9754relocatable files into an already running program; such systems
9755typically make the requirements above easy to meet. However, it's
9756important to recognize that many native systems use complex link
9757procedures (@code{.linkonce} section factoring and C++ constructor table
9758assembly, for example) that make the requirements difficult to meet. In
9759general, one cannot assume that using @code{add-symbol-file} to read a
9760relocatable object file's symbolic information will have the same effect
9761as linking the relocatable object file into the program in the normal
9762way.
9763
c906108c
SS
9764@code{add-symbol-file} does not repeat if you press @key{RET} after using it.
9765
9766You can use the @samp{-mapped} and @samp{-readnow} options just as with
9767the @code{symbol-file} command, to change how @value{GDBN} manages the symbol
9768table information for @var{filename}.
9769
9770@kindex add-shared-symbol-file
9771@item add-shared-symbol-file
9772The @code{add-shared-symbol-file} command can be used only under Harris' CXUX
5d161b24
DB
9773operating system for the Motorola 88k. @value{GDBN} automatically looks for
9774shared libraries, however if @value{GDBN} does not find yours, you can run
c906108c 9775@code{add-shared-symbol-file}. It takes no arguments.
c906108c 9776
c906108c
SS
9777@kindex section
9778@item section
5d161b24
DB
9779The @code{section} command changes the base address of section SECTION of
9780the exec file to ADDR. This can be used if the exec file does not contain
9781section addresses, (such as in the a.out format), or when the addresses
9782specified in the file itself are wrong. Each section must be changed
d4f3574e
SS
9783separately. The @code{info files} command, described below, lists all
9784the sections and their addresses.
c906108c
SS
9785
9786@kindex info files
9787@kindex info target
9788@item info files
9789@itemx info target
7a292a7a
SS
9790@code{info files} and @code{info target} are synonymous; both print the
9791current target (@pxref{Targets, ,Specifying a Debugging Target}),
9792including the names of the executable and core dump files currently in
9793use by @value{GDBN}, and the files from which symbols were loaded. The
9794command @code{help target} lists all possible targets rather than
9795current ones.
9796
fe95c787
MS
9797@kindex maint info sections
9798@item maint info sections
9799Another command that can give you extra information about program sections
9800is @code{maint info sections}. In addition to the section information
9801displayed by @code{info files}, this command displays the flags and file
9802offset of each section in the executable and core dump files. In addition,
9803@code{maint info sections} provides the following command options (which
9804may be arbitrarily combined):
9805
9806@table @code
9807@item ALLOBJ
9808Display sections for all loaded object files, including shared libraries.
9809@item @var{sections}
6600abed 9810Display info only for named @var{sections}.
fe95c787
MS
9811@item @var{section-flags}
9812Display info only for sections for which @var{section-flags} are true.
9813The section flags that @value{GDBN} currently knows about are:
9814@table @code
9815@item ALLOC
9816Section will have space allocated in the process when loaded.
9817Set for all sections except those containing debug information.
9818@item LOAD
9819Section will be loaded from the file into the child process memory.
9820Set for pre-initialized code and data, clear for @code{.bss} sections.
9821@item RELOC
9822Section needs to be relocated before loading.
9823@item READONLY
9824Section cannot be modified by the child process.
9825@item CODE
9826Section contains executable code only.
6600abed 9827@item DATA
fe95c787
MS
9828Section contains data only (no executable code).
9829@item ROM
9830Section will reside in ROM.
9831@item CONSTRUCTOR
9832Section contains data for constructor/destructor lists.
9833@item HAS_CONTENTS
9834Section is not empty.
9835@item NEVER_LOAD
9836An instruction to the linker to not output the section.
9837@item COFF_SHARED_LIBRARY
9838A notification to the linker that the section contains
9839COFF shared library information.
9840@item IS_COMMON
9841Section contains common symbols.
9842@end table
9843@end table
6763aef9
MS
9844@kindex set trust-readonly-sections
9845@item set trust-readonly-sections on
9846Tell @value{GDBN} that readonly sections in your object file
6ca652b0 9847really are read-only (i.e.@: that their contents will not change).
6763aef9
MS
9848In that case, @value{GDBN} can fetch values from these sections
9849out of the object file, rather than from the target program.
9850For some targets (notably embedded ones), this can be a significant
9851enhancement to debugging performance.
9852
9853The default is off.
9854
9855@item set trust-readonly-sections off
15110bc3 9856Tell @value{GDBN} not to trust readonly sections. This means that
6763aef9
MS
9857the contents of the section might change while the program is running,
9858and must therefore be fetched from the target when needed.
c906108c
SS
9859@end table
9860
9861All file-specifying commands allow both absolute and relative file names
9862as arguments. @value{GDBN} always converts the file name to an absolute file
9863name and remembers it that way.
9864
c906108c 9865@cindex shared libraries
c906108c
SS
9866@value{GDBN} supports HP-UX, SunOS, SVr4, Irix 5, and IBM RS/6000 shared
9867libraries.
53a5351d 9868
c906108c
SS
9869@value{GDBN} automatically loads symbol definitions from shared libraries
9870when you use the @code{run} command, or when you examine a core file.
9871(Before you issue the @code{run} command, @value{GDBN} does not understand
9872references to a function in a shared library, however---unless you are
9873debugging a core file).
53a5351d
JM
9874
9875On HP-UX, if the program loads a library explicitly, @value{GDBN}
9876automatically loads the symbols at the time of the @code{shl_load} call.
9877
c906108c
SS
9878@c FIXME: some @value{GDBN} release may permit some refs to undef
9879@c FIXME...symbols---eg in a break cmd---assuming they are from a shared
9880@c FIXME...lib; check this from time to time when updating manual
9881
b7209cb4
FF
9882There are times, however, when you may wish to not automatically load
9883symbol definitions from shared libraries, such as when they are
9884particularly large or there are many of them.
9885
9886To control the automatic loading of shared library symbols, use the
9887commands:
9888
9889@table @code
9890@kindex set auto-solib-add
9891@item set auto-solib-add @var{mode}
9892If @var{mode} is @code{on}, symbols from all shared object libraries
9893will be loaded automatically when the inferior begins execution, you
9894attach to an independently started inferior, or when the dynamic linker
9895informs @value{GDBN} that a new library has been loaded. If @var{mode}
9896is @code{off}, symbols must be loaded manually, using the
9897@code{sharedlibrary} command. The default value is @code{on}.
9898
9899@kindex show auto-solib-add
9900@item show auto-solib-add
9901Display the current autoloading mode.
9902@end table
9903
9904To explicitly load shared library symbols, use the @code{sharedlibrary}
9905command:
9906
c906108c
SS
9907@table @code
9908@kindex info sharedlibrary
9909@kindex info share
9910@item info share
9911@itemx info sharedlibrary
9912Print the names of the shared libraries which are currently loaded.
9913
9914@kindex sharedlibrary
9915@kindex share
9916@item sharedlibrary @var{regex}
9917@itemx share @var{regex}
c906108c
SS
9918Load shared object library symbols for files matching a
9919Unix regular expression.
9920As with files loaded automatically, it only loads shared libraries
9921required by your program for a core file or after typing @code{run}. If
9922@var{regex} is omitted all shared libraries required by your program are
9923loaded.
9924@end table
9925
b7209cb4
FF
9926On some systems, such as HP-UX systems, @value{GDBN} supports
9927autoloading shared library symbols until a limiting threshold size is
9928reached. This provides the benefit of allowing autoloading to remain on
9929by default, but avoids autoloading excessively large shared libraries,
9930up to a threshold that is initially set, but which you can modify if you
9931wish.
c906108c
SS
9932
9933Beyond that threshold, symbols from shared libraries must be explicitly
d4f3574e
SS
9934loaded. To load these symbols, use the command @code{sharedlibrary
9935@var{filename}}. The base address of the shared library is determined
c906108c
SS
9936automatically by @value{GDBN} and need not be specified.
9937
9938To display or set the threshold, use the commands:
9939
9940@table @code
b7209cb4
FF
9941@kindex set auto-solib-limit
9942@item set auto-solib-limit @var{threshold}
9943Set the autoloading size threshold, in an integral number of megabytes.
9944If @var{threshold} is nonzero and shared library autoloading is enabled,
9945symbols from all shared object libraries will be loaded until the total
9946size of the loaded shared library symbols exceeds this threshold.
c906108c 9947Otherwise, symbols must be loaded manually, using the
6ca652b0 9948@code{sharedlibrary} command. The default threshold is 100 (i.e.@: 100
b7209cb4 9949Mb).
c906108c 9950
b7209cb4
FF
9951@kindex show auto-solib-limit
9952@item show auto-solib-limit
c906108c
SS
9953Display the current autoloading size threshold, in megabytes.
9954@end table
c906108c 9955
f5ebfba0
DJ
9956Shared libraries are also supported in many cross or remote debugging
9957configurations. A copy of the target's libraries need to be present on the
9958host system; they need to be the same as the target libraries, although the
9959copies on the target can be stripped as long as the copies on the host are
9960not.
9961
9962You need to tell @value{GDBN} where the target libraries are, so that it can
9963load the correct copies---otherwise, it may try to load the host's libraries.
9964@value{GDBN} has two variables to specify the search directories for target
9965libraries.
9966
9967@table @code
9968@kindex set solib-absolute-prefix
9969@item set solib-absolute-prefix @var{path}
9970If this variable is set, @var{path} will be used as a prefix for any
9971absolute shared library paths; many runtime loaders store the absolute
9972paths to the shared library in the target program's memory. If you use
9973@samp{solib-absolute-prefix} to find shared libraries, they need to be laid
9974out in the same way that they are on the target, with e.g.@: a
9975@file{/usr/lib} hierarchy under @var{path}.
9976
9977You can set the default value of @samp{solib-absolute-prefix} by using the
9978configure-time @samp{--with-sysroot} option.
9979
9980@kindex show solib-absolute-prefix
9981@item show solib-absolute-prefix
9982Display the current shared library prefix.
9983
9984@kindex set solib-search-path
9985@item set solib-search-path @var{path}
9986If this variable is set, @var{path} is a colon-separated list of directories
9987to search for shared libraries. @samp{solib-search-path} is used after
9988@samp{solib-absolute-prefix} fails to locate the library, or if the path to
9989the library is relative instead of absolute. If you want to use
9990@samp{solib-search-path} instead of @samp{solib-absolute-prefix}, be sure to
9991set @samp{solib-absolute-prefix} to a nonexistant directory to prevent
9992@value{GDBN} from finding your host's libraries.
9993
9994@kindex show solib-search-path
9995@item show solib-search-path
9996Display the current shared library search path.
9997@end table
9998
5b5d99cf
JB
9999
10000@node Separate Debug Files
10001@section Debugging Information in Separate Files
10002@cindex separate debugging information files
10003@cindex debugging information in separate files
10004@cindex @file{.debug} subdirectories
10005@cindex debugging information directory, global
10006@cindex global debugging information directory
10007
10008@value{GDBN} allows you to put a program's debugging information in a
10009file separate from the executable itself, in a way that allows
10010@value{GDBN} to find and load the debugging information automatically.
10011Since debugging information can be very large --- sometimes larger
10012than the executable code itself --- some systems distribute debugging
10013information for their executables in separate files, which users can
10014install only when they need to debug a problem.
10015
10016If an executable's debugging information has been extracted to a
10017separate file, the executable should contain a @dfn{debug link} giving
10018the name of the debugging information file (with no directory
10019components), and a checksum of its contents. (The exact form of a
10020debug link is described below.) If the full name of the directory
10021containing the executable is @var{execdir}, and the executable has a
10022debug link that specifies the name @var{debugfile}, then @value{GDBN}
10023will automatically search for the debugging information file in three
10024places:
10025
10026@itemize @bullet
10027@item
10028the directory containing the executable file (that is, it will look
10029for a file named @file{@var{execdir}/@var{debugfile}},
10030@item
10031a subdirectory of that directory named @file{.debug} (that is, the
10032file @file{@var{execdir}/.debug/@var{debugfile}}, and
10033@item
10034a subdirectory of the global debug file directory that includes the
10035executable's full path, and the name from the link (that is, the file
10036@file{@var{globaldebugdir}/@var{execdir}/@var{debugfile}}, where
10037@var{globaldebugdir} is the global debug file directory, and
10038@var{execdir} has been turned into a relative path).
10039@end itemize
10040@noindent
10041@value{GDBN} checks under each of these names for a debugging
10042information file whose checksum matches that given in the link, and
10043reads the debugging information from the first one it finds.
10044
10045So, for example, if you ask @value{GDBN} to debug @file{/usr/bin/ls},
10046which has a link containing the name @file{ls.debug}, and the global
10047debug directory is @file{/usr/lib/debug}, then @value{GDBN} will look
10048for debug information in @file{/usr/bin/ls.debug},
10049@file{/usr/bin/.debug/ls.debug}, and
10050@file{/usr/lib/debug/usr/bin/ls.debug}.
10051
10052You can set the global debugging info directory's name, and view the
10053name @value{GDBN} is currently using.
10054
10055@table @code
10056
10057@kindex set debug-file-directory
10058@item set debug-file-directory @var{directory}
10059Set the directory which @value{GDBN} searches for separate debugging
10060information files to @var{directory}.
10061
10062@kindex show debug-file-directory
10063@item show debug-file-directory
10064Show the directory @value{GDBN} searches for separate debugging
10065information files.
10066
10067@end table
10068
10069@cindex @code{.gnu_debuglink} sections
10070@cindex debug links
10071A debug link is a special section of the executable file named
10072@code{.gnu_debuglink}. The section must contain:
10073
10074@itemize
10075@item
10076A filename, with any leading directory components removed, followed by
10077a zero byte,
10078@item
10079zero to three bytes of padding, as needed to reach the next four-byte
10080boundary within the section, and
10081@item
10082a four-byte CRC checksum, stored in the same endianness used for the
10083executable file itself. The checksum is computed on the debugging
10084information file's full contents by the function given below, passing
10085zero as the @var{crc} argument.
10086@end itemize
10087
10088Any executable file format can carry a debug link, as long as it can
10089contain a section named @code{.gnu_debuglink} with the contents
10090described above.
10091
10092The debugging information file itself should be an ordinary
10093executable, containing a full set of linker symbols, sections, and
10094debugging information. The sections of the debugging information file
10095should have the same names, addresses and sizes as the original file,
10096but they need not contain any data --- much like a @code{.bss} section
10097in an ordinary executable.
10098
10099As of December 2002, there is no standard GNU utility to produce
10100separated executable / debugging information file pairs. Ulrich
10101Drepper's @file{elfutils} package, starting with version 0.53,
10102contains a version of the @code{strip} command such that the command
10103@kbd{strip foo -f foo.debug} removes the debugging information from
10104the executable file @file{foo}, places it in the file
10105@file{foo.debug}, and leaves behind a debug link in @file{foo}.
10106
10107Since there are many different ways to compute CRC's (different
10108polynomials, reversals, byte ordering, etc.), the simplest way to
10109describe the CRC used in @code{.gnu_debuglink} sections is to give the
10110complete code for a function that computes it:
10111
10112@kindex @code{gnu_debuglink_crc32}
10113@smallexample
10114unsigned long
10115gnu_debuglink_crc32 (unsigned long crc,
10116 unsigned char *buf, size_t len)
10117@{
10118 static const unsigned long crc32_table[256] =
10119 @{
10120 0x00000000, 0x77073096, 0xee0e612c, 0x990951ba, 0x076dc419,
10121 0x706af48f, 0xe963a535, 0x9e6495a3, 0x0edb8832, 0x79dcb8a4,
10122 0xe0d5e91e, 0x97d2d988, 0x09b64c2b, 0x7eb17cbd, 0xe7b82d07,
10123 0x90bf1d91, 0x1db71064, 0x6ab020f2, 0xf3b97148, 0x84be41de,
10124 0x1adad47d, 0x6ddde4eb, 0xf4d4b551, 0x83d385c7, 0x136c9856,
10125 0x646ba8c0, 0xfd62f97a, 0x8a65c9ec, 0x14015c4f, 0x63066cd9,
10126 0xfa0f3d63, 0x8d080df5, 0x3b6e20c8, 0x4c69105e, 0xd56041e4,
10127 0xa2677172, 0x3c03e4d1, 0x4b04d447, 0xd20d85fd, 0xa50ab56b,
10128 0x35b5a8fa, 0x42b2986c, 0xdbbbc9d6, 0xacbcf940, 0x32d86ce3,
10129 0x45df5c75, 0xdcd60dcf, 0xabd13d59, 0x26d930ac, 0x51de003a,
10130 0xc8d75180, 0xbfd06116, 0x21b4f4b5, 0x56b3c423, 0xcfba9599,
10131 0xb8bda50f, 0x2802b89e, 0x5f058808, 0xc60cd9b2, 0xb10be924,
10132 0x2f6f7c87, 0x58684c11, 0xc1611dab, 0xb6662d3d, 0x76dc4190,
10133 0x01db7106, 0x98d220bc, 0xefd5102a, 0x71b18589, 0x06b6b51f,
10134 0x9fbfe4a5, 0xe8b8d433, 0x7807c9a2, 0x0f00f934, 0x9609a88e,
10135 0xe10e9818, 0x7f6a0dbb, 0x086d3d2d, 0x91646c97, 0xe6635c01,
10136 0x6b6b51f4, 0x1c6c6162, 0x856530d8, 0xf262004e, 0x6c0695ed,
10137 0x1b01a57b, 0x8208f4c1, 0xf50fc457, 0x65b0d9c6, 0x12b7e950,
10138 0x8bbeb8ea, 0xfcb9887c, 0x62dd1ddf, 0x15da2d49, 0x8cd37cf3,
10139 0xfbd44c65, 0x4db26158, 0x3ab551ce, 0xa3bc0074, 0xd4bb30e2,
10140 0x4adfa541, 0x3dd895d7, 0xa4d1c46d, 0xd3d6f4fb, 0x4369e96a,
10141 0x346ed9fc, 0xad678846, 0xda60b8d0, 0x44042d73, 0x33031de5,
10142 0xaa0a4c5f, 0xdd0d7cc9, 0x5005713c, 0x270241aa, 0xbe0b1010,
10143 0xc90c2086, 0x5768b525, 0x206f85b3, 0xb966d409, 0xce61e49f,
10144 0x5edef90e, 0x29d9c998, 0xb0d09822, 0xc7d7a8b4, 0x59b33d17,
10145 0x2eb40d81, 0xb7bd5c3b, 0xc0ba6cad, 0xedb88320, 0x9abfb3b6,
10146 0x03b6e20c, 0x74b1d29a, 0xead54739, 0x9dd277af, 0x04db2615,
10147 0x73dc1683, 0xe3630b12, 0x94643b84, 0x0d6d6a3e, 0x7a6a5aa8,
10148 0xe40ecf0b, 0x9309ff9d, 0x0a00ae27, 0x7d079eb1, 0xf00f9344,
10149 0x8708a3d2, 0x1e01f268, 0x6906c2fe, 0xf762575d, 0x806567cb,
10150 0x196c3671, 0x6e6b06e7, 0xfed41b76, 0x89d32be0, 0x10da7a5a,
10151 0x67dd4acc, 0xf9b9df6f, 0x8ebeeff9, 0x17b7be43, 0x60b08ed5,
10152 0xd6d6a3e8, 0xa1d1937e, 0x38d8c2c4, 0x4fdff252, 0xd1bb67f1,
10153 0xa6bc5767, 0x3fb506dd, 0x48b2364b, 0xd80d2bda, 0xaf0a1b4c,
10154 0x36034af6, 0x41047a60, 0xdf60efc3, 0xa867df55, 0x316e8eef,
10155 0x4669be79, 0xcb61b38c, 0xbc66831a, 0x256fd2a0, 0x5268e236,
10156 0xcc0c7795, 0xbb0b4703, 0x220216b9, 0x5505262f, 0xc5ba3bbe,
10157 0xb2bd0b28, 0x2bb45a92, 0x5cb36a04, 0xc2d7ffa7, 0xb5d0cf31,
10158 0x2cd99e8b, 0x5bdeae1d, 0x9b64c2b0, 0xec63f226, 0x756aa39c,
10159 0x026d930a, 0x9c0906a9, 0xeb0e363f, 0x72076785, 0x05005713,
10160 0x95bf4a82, 0xe2b87a14, 0x7bb12bae, 0x0cb61b38, 0x92d28e9b,
10161 0xe5d5be0d, 0x7cdcefb7, 0x0bdbdf21, 0x86d3d2d4, 0xf1d4e242,
10162 0x68ddb3f8, 0x1fda836e, 0x81be16cd, 0xf6b9265b, 0x6fb077e1,
10163 0x18b74777, 0x88085ae6, 0xff0f6a70, 0x66063bca, 0x11010b5c,
10164 0x8f659eff, 0xf862ae69, 0x616bffd3, 0x166ccf45, 0xa00ae278,
10165 0xd70dd2ee, 0x4e048354, 0x3903b3c2, 0xa7672661, 0xd06016f7,
10166 0x4969474d, 0x3e6e77db, 0xaed16a4a, 0xd9d65adc, 0x40df0b66,
10167 0x37d83bf0, 0xa9bcae53, 0xdebb9ec5, 0x47b2cf7f, 0x30b5ffe9,
10168 0xbdbdf21c, 0xcabac28a, 0x53b39330, 0x24b4a3a6, 0xbad03605,
10169 0xcdd70693, 0x54de5729, 0x23d967bf, 0xb3667a2e, 0xc4614ab8,
10170 0x5d681b02, 0x2a6f2b94, 0xb40bbe37, 0xc30c8ea1, 0x5a05df1b,
10171 0x2d02ef8d
10172 @};
10173 unsigned char *end;
10174
10175 crc = ~crc & 0xffffffff;
10176 for (end = buf + len; buf < end; ++buf)
10177 crc = crc32_table[(crc ^ *buf) & 0xff] ^ (crc >> 8);
e7a3abfc 10178 return ~crc & 0xffffffff;
5b5d99cf
JB
10179@}
10180@end smallexample
10181
10182
6d2ebf8b 10183@node Symbol Errors
c906108c
SS
10184@section Errors reading symbol files
10185
10186While reading a symbol file, @value{GDBN} occasionally encounters problems,
10187such as symbol types it does not recognize, or known bugs in compiler
10188output. By default, @value{GDBN} does not notify you of such problems, since
10189they are relatively common and primarily of interest to people
10190debugging compilers. If you are interested in seeing information
10191about ill-constructed symbol tables, you can either ask @value{GDBN} to print
10192only one message about each such type of problem, no matter how many
10193times the problem occurs; or you can ask @value{GDBN} to print more messages,
10194to see how many times the problems occur, with the @code{set
10195complaints} command (@pxref{Messages/Warnings, ,Optional warnings and
10196messages}).
10197
10198The messages currently printed, and their meanings, include:
10199
10200@table @code
10201@item inner block not inside outer block in @var{symbol}
10202
10203The symbol information shows where symbol scopes begin and end
10204(such as at the start of a function or a block of statements). This
10205error indicates that an inner scope block is not fully contained
10206in its outer scope blocks.
10207
10208@value{GDBN} circumvents the problem by treating the inner block as if it had
10209the same scope as the outer block. In the error message, @var{symbol}
10210may be shown as ``@code{(don't know)}'' if the outer block is not a
10211function.
10212
10213@item block at @var{address} out of order
10214
10215The symbol information for symbol scope blocks should occur in
10216order of increasing addresses. This error indicates that it does not
10217do so.
10218
10219@value{GDBN} does not circumvent this problem, and has trouble
10220locating symbols in the source file whose symbols it is reading. (You
10221can often determine what source file is affected by specifying
10222@code{set verbose on}. @xref{Messages/Warnings, ,Optional warnings and
10223messages}.)
10224
10225@item bad block start address patched
10226
10227The symbol information for a symbol scope block has a start address
10228smaller than the address of the preceding source line. This is known
10229to occur in the SunOS 4.1.1 (and earlier) C compiler.
10230
10231@value{GDBN} circumvents the problem by treating the symbol scope block as
10232starting on the previous source line.
10233
10234@item bad string table offset in symbol @var{n}
10235
10236@cindex foo
10237Symbol number @var{n} contains a pointer into the string table which is
10238larger than the size of the string table.
10239
10240@value{GDBN} circumvents the problem by considering the symbol to have the
10241name @code{foo}, which may cause other problems if many symbols end up
10242with this name.
10243
10244@item unknown symbol type @code{0x@var{nn}}
10245
7a292a7a
SS
10246The symbol information contains new data types that @value{GDBN} does
10247not yet know how to read. @code{0x@var{nn}} is the symbol type of the
d4f3574e 10248uncomprehended information, in hexadecimal.
c906108c 10249
7a292a7a
SS
10250@value{GDBN} circumvents the error by ignoring this symbol information.
10251This usually allows you to debug your program, though certain symbols
c906108c 10252are not accessible. If you encounter such a problem and feel like
7a292a7a
SS
10253debugging it, you can debug @code{@value{GDBP}} with itself, breakpoint
10254on @code{complain}, then go up to the function @code{read_dbx_symtab}
10255and examine @code{*bufp} to see the symbol.
c906108c
SS
10256
10257@item stub type has NULL name
c906108c 10258
7a292a7a 10259@value{GDBN} could not find the full definition for a struct or class.
c906108c 10260
7a292a7a 10261@item const/volatile indicator missing (ok if using g++ v1.x), got@dots{}
b37052ae 10262The symbol information for a C@t{++} member function is missing some
7a292a7a
SS
10263information that recent versions of the compiler should have output for
10264it.
c906108c
SS
10265
10266@item info mismatch between compiler and debugger
10267
10268@value{GDBN} could not parse a type specification output by the compiler.
7a292a7a 10269
c906108c
SS
10270@end table
10271
6d2ebf8b 10272@node Targets
c906108c 10273@chapter Specifying a Debugging Target
7a292a7a 10274
c906108c
SS
10275@cindex debugging target
10276@kindex target
10277
10278A @dfn{target} is the execution environment occupied by your program.
53a5351d
JM
10279
10280Often, @value{GDBN} runs in the same host environment as your program;
10281in that case, the debugging target is specified as a side effect when
10282you use the @code{file} or @code{core} commands. When you need more
c906108c
SS
10283flexibility---for example, running @value{GDBN} on a physically separate
10284host, or controlling a standalone system over a serial port or a
53a5351d
JM
10285realtime system over a TCP/IP connection---you can use the @code{target}
10286command to specify one of the target types configured for @value{GDBN}
10287(@pxref{Target Commands, ,Commands for managing targets}).
c906108c
SS
10288
10289@menu
10290* Active Targets:: Active targets
10291* Target Commands:: Commands for managing targets
c906108c
SS
10292* Byte Order:: Choosing target byte order
10293* Remote:: Remote debugging
96baa820 10294* KOD:: Kernel Object Display
c906108c
SS
10295
10296@end menu
10297
6d2ebf8b 10298@node Active Targets
c906108c 10299@section Active targets
7a292a7a 10300
c906108c
SS
10301@cindex stacking targets
10302@cindex active targets
10303@cindex multiple targets
10304
c906108c 10305There are three classes of targets: processes, core files, and
7a292a7a
SS
10306executable files. @value{GDBN} can work concurrently on up to three
10307active targets, one in each class. This allows you to (for example)
10308start a process and inspect its activity without abandoning your work on
10309a core file.
c906108c
SS
10310
10311For example, if you execute @samp{gdb a.out}, then the executable file
10312@code{a.out} is the only active target. If you designate a core file as
10313well---presumably from a prior run that crashed and coredumped---then
10314@value{GDBN} has two active targets and uses them in tandem, looking
10315first in the corefile target, then in the executable file, to satisfy
10316requests for memory addresses. (Typically, these two classes of target
10317are complementary, since core files contain only a program's
10318read-write memory---variables and so on---plus machine status, while
10319executable files contain only the program text and initialized data.)
c906108c
SS
10320
10321When you type @code{run}, your executable file becomes an active process
7a292a7a
SS
10322target as well. When a process target is active, all @value{GDBN}
10323commands requesting memory addresses refer to that target; addresses in
10324an active core file or executable file target are obscured while the
10325process target is active.
c906108c 10326
7a292a7a
SS
10327Use the @code{core-file} and @code{exec-file} commands to select a new
10328core file or executable target (@pxref{Files, ,Commands to specify
c906108c 10329files}). To specify as a target a process that is already running, use
7a292a7a
SS
10330the @code{attach} command (@pxref{Attach, ,Debugging an already-running
10331process}).
c906108c 10332
6d2ebf8b 10333@node Target Commands
c906108c
SS
10334@section Commands for managing targets
10335
10336@table @code
10337@item target @var{type} @var{parameters}
7a292a7a
SS
10338Connects the @value{GDBN} host environment to a target machine or
10339process. A target is typically a protocol for talking to debugging
10340facilities. You use the argument @var{type} to specify the type or
10341protocol of the target machine.
c906108c
SS
10342
10343Further @var{parameters} are interpreted by the target protocol, but
10344typically include things like device names or host names to connect
10345with, process numbers, and baud rates.
c906108c
SS
10346
10347The @code{target} command does not repeat if you press @key{RET} again
10348after executing the command.
10349
10350@kindex help target
10351@item help target
10352Displays the names of all targets available. To display targets
10353currently selected, use either @code{info target} or @code{info files}
10354(@pxref{Files, ,Commands to specify files}).
10355
10356@item help target @var{name}
10357Describe a particular target, including any parameters necessary to
10358select it.
10359
10360@kindex set gnutarget
10361@item set gnutarget @var{args}
5d161b24 10362@value{GDBN} uses its own library BFD to read your files. @value{GDBN}
c906108c 10363knows whether it is reading an @dfn{executable},
5d161b24
DB
10364a @dfn{core}, or a @dfn{.o} file; however, you can specify the file format
10365with the @code{set gnutarget} command. Unlike most @code{target} commands,
c906108c
SS
10366with @code{gnutarget} the @code{target} refers to a program, not a machine.
10367
d4f3574e 10368@quotation
c906108c
SS
10369@emph{Warning:} To specify a file format with @code{set gnutarget},
10370you must know the actual BFD name.
d4f3574e 10371@end quotation
c906108c 10372
d4f3574e
SS
10373@noindent
10374@xref{Files, , Commands to specify files}.
c906108c 10375
5d161b24 10376@kindex show gnutarget
c906108c
SS
10377@item show gnutarget
10378Use the @code{show gnutarget} command to display what file format
10379@code{gnutarget} is set to read. If you have not set @code{gnutarget},
10380@value{GDBN} will determine the file format for each file automatically,
10381and @code{show gnutarget} displays @samp{The current BDF target is "auto"}.
10382@end table
10383
c906108c
SS
10384Here are some common targets (available, or not, depending on the GDB
10385configuration):
c906108c
SS
10386
10387@table @code
10388@kindex target exec
10389@item target exec @var{program}
10390An executable file. @samp{target exec @var{program}} is the same as
10391@samp{exec-file @var{program}}.
10392
c906108c
SS
10393@kindex target core
10394@item target core @var{filename}
10395A core dump file. @samp{target core @var{filename}} is the same as
10396@samp{core-file @var{filename}}.
c906108c
SS
10397
10398@kindex target remote
10399@item target remote @var{dev}
10400Remote serial target in GDB-specific protocol. The argument @var{dev}
10401specifies what serial device to use for the connection (e.g.
10402@file{/dev/ttya}). @xref{Remote, ,Remote debugging}. @code{target remote}
d4f3574e 10403supports the @code{load} command. This is only useful if you have
c906108c
SS
10404some other way of getting the stub to the target system, and you can put
10405it somewhere in memory where it won't get clobbered by the download.
10406
c906108c
SS
10407@kindex target sim
10408@item target sim
2df3850c 10409Builtin CPU simulator. @value{GDBN} includes simulators for most architectures.
104c1213 10410In general,
474c8240 10411@smallexample
104c1213
JM
10412 target sim
10413 load
10414 run
474c8240 10415@end smallexample
d4f3574e 10416@noindent
104c1213 10417works; however, you cannot assume that a specific memory map, device
d4f3574e 10418drivers, or even basic I/O is available, although some simulators do
104c1213
JM
10419provide these. For info about any processor-specific simulator details,
10420see the appropriate section in @ref{Embedded Processors, ,Embedded
10421Processors}.
10422
c906108c
SS
10423@end table
10424
104c1213 10425Some configurations may include these targets as well:
c906108c
SS
10426
10427@table @code
10428
c906108c
SS
10429@kindex target nrom
10430@item target nrom @var{dev}
10431NetROM ROM emulator. This target only supports downloading.
10432
c906108c
SS
10433@end table
10434
5d161b24 10435Different targets are available on different configurations of @value{GDBN};
c906108c 10436your configuration may have more or fewer targets.
c906108c
SS
10437
10438Many remote targets require you to download the executable's code
10439once you've successfully established a connection.
10440
10441@table @code
10442
10443@kindex load @var{filename}
10444@item load @var{filename}
c906108c
SS
10445Depending on what remote debugging facilities are configured into
10446@value{GDBN}, the @code{load} command may be available. Where it exists, it
10447is meant to make @var{filename} (an executable) available for debugging
10448on the remote system---by downloading, or dynamic linking, for example.
10449@code{load} also records the @var{filename} symbol table in @value{GDBN}, like
10450the @code{add-symbol-file} command.
10451
10452If your @value{GDBN} does not have a @code{load} command, attempting to
10453execute it gets the error message ``@code{You can't do that when your
10454target is @dots{}}''
c906108c
SS
10455
10456The file is loaded at whatever address is specified in the executable.
10457For some object file formats, you can specify the load address when you
10458link the program; for other formats, like a.out, the object file format
10459specifies a fixed address.
10460@c FIXME! This would be a good place for an xref to the GNU linker doc.
10461
c906108c
SS
10462@code{load} does not repeat if you press @key{RET} again after using it.
10463@end table
10464
6d2ebf8b 10465@node Byte Order
c906108c 10466@section Choosing target byte order
7a292a7a 10467
c906108c
SS
10468@cindex choosing target byte order
10469@cindex target byte order
c906108c
SS
10470
10471Some types of processors, such as the MIPS, PowerPC, and Hitachi SH,
10472offer the ability to run either big-endian or little-endian byte
10473orders. Usually the executable or symbol will include a bit to
10474designate the endian-ness, and you will not need to worry about
10475which to use. However, you may still find it useful to adjust
d4f3574e 10476@value{GDBN}'s idea of processor endian-ness manually.
c906108c
SS
10477
10478@table @code
10479@kindex set endian big
10480@item set endian big
10481Instruct @value{GDBN} to assume the target is big-endian.
10482
10483@kindex set endian little
10484@item set endian little
10485Instruct @value{GDBN} to assume the target is little-endian.
10486
10487@kindex set endian auto
10488@item set endian auto
10489Instruct @value{GDBN} to use the byte order associated with the
10490executable.
10491
10492@item show endian
10493Display @value{GDBN}'s current idea of the target byte order.
10494
10495@end table
10496
10497Note that these commands merely adjust interpretation of symbolic
10498data on the host, and that they have absolutely no effect on the
10499target system.
10500
6d2ebf8b 10501@node Remote
c906108c
SS
10502@section Remote debugging
10503@cindex remote debugging
10504
10505If you are trying to debug a program running on a machine that cannot run
5d161b24
DB
10506@value{GDBN} in the usual way, it is often useful to use remote debugging.
10507For example, you might use remote debugging on an operating system kernel,
c906108c
SS
10508or on a small system which does not have a general purpose operating system
10509powerful enough to run a full-featured debugger.
10510
10511Some configurations of @value{GDBN} have special serial or TCP/IP interfaces
10512to make this work with particular debugging targets. In addition,
5d161b24 10513@value{GDBN} comes with a generic serial protocol (specific to @value{GDBN},
c906108c
SS
10514but not specific to any particular target system) which you can use if you
10515write the remote stubs---the code that runs on the remote system to
10516communicate with @value{GDBN}.
10517
10518Other remote targets may be available in your
10519configuration of @value{GDBN}; use @code{help target} to list them.
c906108c 10520
6f05cf9f
AC
10521@node KOD
10522@section Kernel Object Display
10523
10524@cindex kernel object display
10525@cindex kernel object
10526@cindex KOD
10527
10528Some targets support kernel object display. Using this facility,
10529@value{GDBN} communicates specially with the underlying operating system
10530and can display information about operating system-level objects such as
10531mutexes and other synchronization objects. Exactly which objects can be
10532displayed is determined on a per-OS basis.
10533
10534Use the @code{set os} command to set the operating system. This tells
10535@value{GDBN} which kernel object display module to initialize:
10536
474c8240 10537@smallexample
6f05cf9f 10538(@value{GDBP}) set os cisco
474c8240 10539@end smallexample
6f05cf9f
AC
10540
10541If @code{set os} succeeds, @value{GDBN} will display some information
10542about the operating system, and will create a new @code{info} command
10543which can be used to query the target. The @code{info} command is named
10544after the operating system:
c906108c 10545
474c8240 10546@smallexample
6f05cf9f
AC
10547(@value{GDBP}) info cisco
10548List of Cisco Kernel Objects
10549Object Description
10550any Any and all objects
474c8240 10551@end smallexample
6f05cf9f
AC
10552
10553Further subcommands can be used to query about particular objects known
10554by the kernel.
10555
10556There is currently no way to determine whether a given operating system
10557is supported other than to try it.
10558
10559
10560@node Remote Debugging
10561@chapter Debugging remote programs
10562
6b2f586d 10563@menu
07f31aa6 10564* Connecting:: Connecting to a remote target
6b2f586d
AC
10565* Server:: Using the gdbserver program
10566* NetWare:: Using the gdbserve.nlm program
501eef12 10567* Remote configuration:: Remote configuration
6b2f586d 10568* remote stub:: Implementing a remote stub
6b2f586d
AC
10569@end menu
10570
07f31aa6
DJ
10571@node Connecting
10572@section Connecting to a remote target
10573
10574On the @value{GDBN} host machine, you will need an unstripped copy of
10575your program, since @value{GDBN} needs symobl and debugging information.
10576Start up @value{GDBN} as usual, using the name of the local copy of your
10577program as the first argument.
10578
10579@cindex serial line, @code{target remote}
10580If you're using a serial line, you may want to give @value{GDBN} the
10581@w{@samp{--baud}} option, or use the @code{set remotebaud} command
10582before the @code{target} command.
10583
10584After that, use @code{target remote} to establish communications with
10585the target machine. Its argument specifies how to communicate---either
10586via a devicename attached to a direct serial line, or a TCP or UDP port
10587(possibly to a terminal server which in turn has a serial line to the
10588target). For example, to use a serial line connected to the device
10589named @file{/dev/ttyb}:
10590
10591@smallexample
10592target remote /dev/ttyb
10593@end smallexample
10594
10595@cindex TCP port, @code{target remote}
10596To use a TCP connection, use an argument of the form
10597@code{@var{host}:@var{port}} or @code{tcp:@var{host}:@var{port}}.
10598For example, to connect to port 2828 on a
10599terminal server named @code{manyfarms}:
10600
10601@smallexample
10602target remote manyfarms:2828
10603@end smallexample
10604
10605If your remote target is actually running on the same machine as
10606your debugger session (e.g.@: a simulator of your target running on
10607the same host), you can omit the hostname. For example, to connect
10608to port 1234 on your local machine:
10609
10610@smallexample
10611target remote :1234
10612@end smallexample
10613@noindent
10614
10615Note that the colon is still required here.
10616
10617@cindex UDP port, @code{target remote}
10618To use a UDP connection, use an argument of the form
10619@code{udp:@var{host}:@var{port}}. For example, to connect to UDP port 2828
10620on a terminal server named @code{manyfarms}:
10621
10622@smallexample
10623target remote udp:manyfarms:2828
10624@end smallexample
10625
10626When using a UDP connection for remote debugging, you should keep in mind
10627that the `U' stands for ``Unreliable''. UDP can silently drop packets on
10628busy or unreliable networks, which will cause havoc with your debugging
10629session.
10630
10631Now you can use all the usual commands to examine and change data and to
10632step and continue the remote program.
10633
10634@cindex interrupting remote programs
10635@cindex remote programs, interrupting
10636Whenever @value{GDBN} is waiting for the remote program, if you type the
10637interrupt character (often @key{C-C}), @value{GDBN} attempts to stop the
10638program. This may or may not succeed, depending in part on the hardware
10639and the serial drivers the remote system uses. If you type the
10640interrupt character once again, @value{GDBN} displays this prompt:
10641
10642@smallexample
10643Interrupted while waiting for the program.
10644Give up (and stop debugging it)? (y or n)
10645@end smallexample
10646
10647If you type @kbd{y}, @value{GDBN} abandons the remote debugging session.
10648(If you decide you want to try again later, you can use @samp{target
10649remote} again to connect once more.) If you type @kbd{n}, @value{GDBN}
10650goes back to waiting.
10651
10652@table @code
10653@kindex detach (remote)
10654@item detach
10655When you have finished debugging the remote program, you can use the
10656@code{detach} command to release it from @value{GDBN} control.
10657Detaching from the target normally resumes its execution, but the results
10658will depend on your particular remote stub. After the @code{detach}
10659command, @value{GDBN} is free to connect to another target.
10660
10661@kindex disconnect
10662@item disconnect
10663The @code{disconnect} command behaves like @code{detach}, except that
10664the target is generally not resumed. It will wait for @value{GDBN}
10665(this instance or another one) to connect and continue debugging. After
10666the @code{disconnect} command, @value{GDBN} is again free to connect to
10667another target.
10668@end table
10669
6f05cf9f
AC
10670@node Server
10671@section Using the @code{gdbserver} program
10672
10673@kindex gdbserver
10674@cindex remote connection without stubs
10675@code{gdbserver} is a control program for Unix-like systems, which
10676allows you to connect your program with a remote @value{GDBN} via
10677@code{target remote}---but without linking in the usual debugging stub.
10678
10679@code{gdbserver} is not a complete replacement for the debugging stubs,
10680because it requires essentially the same operating-system facilities
10681that @value{GDBN} itself does. In fact, a system that can run
10682@code{gdbserver} to connect to a remote @value{GDBN} could also run
10683@value{GDBN} locally! @code{gdbserver} is sometimes useful nevertheless,
10684because it is a much smaller program than @value{GDBN} itself. It is
10685also easier to port than all of @value{GDBN}, so you may be able to get
10686started more quickly on a new system by using @code{gdbserver}.
10687Finally, if you develop code for real-time systems, you may find that
10688the tradeoffs involved in real-time operation make it more convenient to
10689do as much development work as possible on another system, for example
10690by cross-compiling. You can use @code{gdbserver} to make a similar
10691choice for debugging.
10692
10693@value{GDBN} and @code{gdbserver} communicate via either a serial line
10694or a TCP connection, using the standard @value{GDBN} remote serial
10695protocol.
10696
10697@table @emph
10698@item On the target machine,
10699you need to have a copy of the program you want to debug.
10700@code{gdbserver} does not need your program's symbol table, so you can
10701strip the program if necessary to save space. @value{GDBN} on the host
10702system does all the symbol handling.
10703
10704To use the server, you must tell it how to communicate with @value{GDBN};
56460a61 10705the name of your program; and the arguments for your program. The usual
6f05cf9f
AC
10706syntax is:
10707
10708@smallexample
10709target> gdbserver @var{comm} @var{program} [ @var{args} @dots{} ]
10710@end smallexample
10711
10712@var{comm} is either a device name (to use a serial line) or a TCP
10713hostname and portnumber. For example, to debug Emacs with the argument
10714@samp{foo.txt} and communicate with @value{GDBN} over the serial port
10715@file{/dev/com1}:
10716
10717@smallexample
10718target> gdbserver /dev/com1 emacs foo.txt
10719@end smallexample
10720
10721@code{gdbserver} waits passively for the host @value{GDBN} to communicate
10722with it.
10723
10724To use a TCP connection instead of a serial line:
10725
10726@smallexample
10727target> gdbserver host:2345 emacs foo.txt
10728@end smallexample
10729
10730The only difference from the previous example is the first argument,
10731specifying that you are communicating with the host @value{GDBN} via
10732TCP. The @samp{host:2345} argument means that @code{gdbserver} is to
10733expect a TCP connection from machine @samp{host} to local TCP port 2345.
10734(Currently, the @samp{host} part is ignored.) You can choose any number
10735you want for the port number as long as it does not conflict with any
10736TCP ports already in use on the target system (for example, @code{23} is
10737reserved for @code{telnet}).@footnote{If you choose a port number that
10738conflicts with another service, @code{gdbserver} prints an error message
10739and exits.} You must use the same port number with the host @value{GDBN}
10740@code{target remote} command.
10741
56460a61
DJ
10742On some targets, @code{gdbserver} can also attach to running programs.
10743This is accomplished via the @code{--attach} argument. The syntax is:
10744
10745@smallexample
10746target> gdbserver @var{comm} --attach @var{pid}
10747@end smallexample
10748
10749@var{pid} is the process ID of a currently running process. It isn't necessary
10750to point @code{gdbserver} at a binary for the running process.
10751
b1fe9455
DJ
10752@pindex pidof
10753@cindex attach to a program by name
10754You can debug processes by name instead of process ID if your target has the
10755@code{pidof} utility:
10756
10757@smallexample
10758target> gdbserver @var{comm} --attach `pidof @var{PROGRAM}`
10759@end smallexample
10760
10761In case more than one copy of @var{PROGRAM} is running, or @var{PROGRAM}
10762has multiple threads, most versions of @code{pidof} support the
10763@code{-s} option to only return the first process ID.
10764
07f31aa6
DJ
10765@item On the host machine,
10766connect to your target (@pxref{Connecting,,Connecting to a remote target}).
6f05cf9f
AC
10767For TCP connections, you must start up @code{gdbserver} prior to using
10768the @code{target remote} command. Otherwise you may get an error whose
10769text depends on the host system, but which usually looks something like
07f31aa6
DJ
10770@samp{Connection refused}. You don't need to use the @code{load}
10771command in @value{GDBN} when using gdbserver, since the program is
10772already on the target.
10773
6f05cf9f
AC
10774@end table
10775
10776@node NetWare
10777@section Using the @code{gdbserve.nlm} program
10778
10779@kindex gdbserve.nlm
10780@code{gdbserve.nlm} is a control program for NetWare systems, which
10781allows you to connect your program with a remote @value{GDBN} via
10782@code{target remote}.
10783
10784@value{GDBN} and @code{gdbserve.nlm} communicate via a serial line,
10785using the standard @value{GDBN} remote serial protocol.
10786
10787@table @emph
10788@item On the target machine,
10789you need to have a copy of the program you want to debug.
10790@code{gdbserve.nlm} does not need your program's symbol table, so you
10791can strip the program if necessary to save space. @value{GDBN} on the
10792host system does all the symbol handling.
10793
10794To use the server, you must tell it how to communicate with
10795@value{GDBN}; the name of your program; and the arguments for your
10796program. The syntax is:
10797
10798@smallexample
10799load gdbserve [ BOARD=@var{board} ] [ PORT=@var{port} ]
10800 [ BAUD=@var{baud} ] @var{program} [ @var{args} @dots{} ]
10801@end smallexample
10802
10803@var{board} and @var{port} specify the serial line; @var{baud} specifies
10804the baud rate used by the connection. @var{port} and @var{node} default
10805to 0, @var{baud} defaults to 9600@dmn{bps}.
10806
10807For example, to debug Emacs with the argument @samp{foo.txt}and
10808communicate with @value{GDBN} over serial port number 2 or board 1
10809using a 19200@dmn{bps} connection:
10810
10811@smallexample
10812load gdbserve BOARD=1 PORT=2 BAUD=19200 emacs foo.txt
10813@end smallexample
10814
07f31aa6
DJ
10815@item
10816On the @value{GDBN} host machine, connect to your target (@pxref{Connecting,,
10817Connecting to a remote target}).
6f05cf9f 10818
6f05cf9f
AC
10819@end table
10820
501eef12
AC
10821@node Remote configuration
10822@section Remote configuration
10823
10824The following configuration options are available when debugging remote
10825programs:
10826
10827@table @code
10828@kindex set remote hardware-watchpoint-limit
10829@kindex set remote hardware-breakpoint-limit
10830@anchor{set remote hardware-watchpoint-limit}
10831@anchor{set remote hardware-breakpoint-limit}
10832@item set remote hardware-watchpoint-limit @var{limit}
10833@itemx set remote hardware-breakpoint-limit @var{limit}
10834Restrict @value{GDBN} to using @var{limit} remote hardware breakpoint or
10835watchpoints. A limit of -1, the default, is treated as unlimited.
10836@end table
10837
6f05cf9f
AC
10838@node remote stub
10839@section Implementing a remote stub
7a292a7a 10840
8e04817f
AC
10841@cindex debugging stub, example
10842@cindex remote stub, example
10843@cindex stub example, remote debugging
10844The stub files provided with @value{GDBN} implement the target side of the
10845communication protocol, and the @value{GDBN} side is implemented in the
10846@value{GDBN} source file @file{remote.c}. Normally, you can simply allow
10847these subroutines to communicate, and ignore the details. (If you're
10848implementing your own stub file, you can still ignore the details: start
10849with one of the existing stub files. @file{sparc-stub.c} is the best
10850organized, and therefore the easiest to read.)
10851
104c1213
JM
10852@cindex remote serial debugging, overview
10853To debug a program running on another machine (the debugging
10854@dfn{target} machine), you must first arrange for all the usual
10855prerequisites for the program to run by itself. For example, for a C
10856program, you need:
c906108c 10857
104c1213
JM
10858@enumerate
10859@item
10860A startup routine to set up the C runtime environment; these usually
10861have a name like @file{crt0}. The startup routine may be supplied by
10862your hardware supplier, or you may have to write your own.
96baa820 10863
5d161b24 10864@item
d4f3574e 10865A C subroutine library to support your program's
104c1213 10866subroutine calls, notably managing input and output.
96baa820 10867
104c1213
JM
10868@item
10869A way of getting your program to the other machine---for example, a
10870download program. These are often supplied by the hardware
10871manufacturer, but you may have to write your own from hardware
10872documentation.
10873@end enumerate
96baa820 10874
104c1213
JM
10875The next step is to arrange for your program to use a serial port to
10876communicate with the machine where @value{GDBN} is running (the @dfn{host}
10877machine). In general terms, the scheme looks like this:
96baa820 10878
104c1213
JM
10879@table @emph
10880@item On the host,
10881@value{GDBN} already understands how to use this protocol; when everything
10882else is set up, you can simply use the @samp{target remote} command
10883(@pxref{Targets,,Specifying a Debugging Target}).
10884
10885@item On the target,
10886you must link with your program a few special-purpose subroutines that
10887implement the @value{GDBN} remote serial protocol. The file containing these
10888subroutines is called a @dfn{debugging stub}.
10889
10890On certain remote targets, you can use an auxiliary program
10891@code{gdbserver} instead of linking a stub into your program.
10892@xref{Server,,Using the @code{gdbserver} program}, for details.
10893@end table
96baa820 10894
104c1213
JM
10895The debugging stub is specific to the architecture of the remote
10896machine; for example, use @file{sparc-stub.c} to debug programs on
10897@sc{sparc} boards.
96baa820 10898
104c1213
JM
10899@cindex remote serial stub list
10900These working remote stubs are distributed with @value{GDBN}:
96baa820 10901
104c1213
JM
10902@table @code
10903
10904@item i386-stub.c
41afff9a 10905@cindex @file{i386-stub.c}
104c1213
JM
10906@cindex Intel
10907@cindex i386
10908For Intel 386 and compatible architectures.
10909
10910@item m68k-stub.c
41afff9a 10911@cindex @file{m68k-stub.c}
104c1213
JM
10912@cindex Motorola 680x0
10913@cindex m680x0
10914For Motorola 680x0 architectures.
10915
10916@item sh-stub.c
41afff9a 10917@cindex @file{sh-stub.c}
104c1213
JM
10918@cindex Hitachi
10919@cindex SH
10920For Hitachi SH architectures.
10921
10922@item sparc-stub.c
41afff9a 10923@cindex @file{sparc-stub.c}
104c1213
JM
10924@cindex Sparc
10925For @sc{sparc} architectures.
10926
10927@item sparcl-stub.c
41afff9a 10928@cindex @file{sparcl-stub.c}
104c1213
JM
10929@cindex Fujitsu
10930@cindex SparcLite
10931For Fujitsu @sc{sparclite} architectures.
10932
10933@end table
10934
10935The @file{README} file in the @value{GDBN} distribution may list other
10936recently added stubs.
10937
10938@menu
10939* Stub Contents:: What the stub can do for you
10940* Bootstrapping:: What you must do for the stub
10941* Debug Session:: Putting it all together
104c1213
JM
10942@end menu
10943
6d2ebf8b 10944@node Stub Contents
6f05cf9f 10945@subsection What the stub can do for you
104c1213
JM
10946
10947@cindex remote serial stub
10948The debugging stub for your architecture supplies these three
10949subroutines:
10950
10951@table @code
10952@item set_debug_traps
10953@kindex set_debug_traps
10954@cindex remote serial stub, initialization
10955This routine arranges for @code{handle_exception} to run when your
10956program stops. You must call this subroutine explicitly near the
10957beginning of your program.
10958
10959@item handle_exception
10960@kindex handle_exception
10961@cindex remote serial stub, main routine
10962This is the central workhorse, but your program never calls it
10963explicitly---the setup code arranges for @code{handle_exception} to
10964run when a trap is triggered.
10965
10966@code{handle_exception} takes control when your program stops during
10967execution (for example, on a breakpoint), and mediates communications
10968with @value{GDBN} on the host machine. This is where the communications
10969protocol is implemented; @code{handle_exception} acts as the @value{GDBN}
d4f3574e 10970representative on the target machine. It begins by sending summary
104c1213
JM
10971information on the state of your program, then continues to execute,
10972retrieving and transmitting any information @value{GDBN} needs, until you
10973execute a @value{GDBN} command that makes your program resume; at that point,
10974@code{handle_exception} returns control to your own code on the target
5d161b24 10975machine.
104c1213
JM
10976
10977@item breakpoint
10978@cindex @code{breakpoint} subroutine, remote
10979Use this auxiliary subroutine to make your program contain a
10980breakpoint. Depending on the particular situation, this may be the only
10981way for @value{GDBN} to get control. For instance, if your target
10982machine has some sort of interrupt button, you won't need to call this;
10983pressing the interrupt button transfers control to
10984@code{handle_exception}---in effect, to @value{GDBN}. On some machines,
10985simply receiving characters on the serial port may also trigger a trap;
10986again, in that situation, you don't need to call @code{breakpoint} from
10987your own program---simply running @samp{target remote} from the host
5d161b24 10988@value{GDBN} session gets control.
104c1213
JM
10989
10990Call @code{breakpoint} if none of these is true, or if you simply want
10991to make certain your program stops at a predetermined point for the
10992start of your debugging session.
10993@end table
10994
6d2ebf8b 10995@node Bootstrapping
6f05cf9f 10996@subsection What you must do for the stub
104c1213
JM
10997
10998@cindex remote stub, support routines
10999The debugging stubs that come with @value{GDBN} are set up for a particular
11000chip architecture, but they have no information about the rest of your
11001debugging target machine.
11002
11003First of all you need to tell the stub how to communicate with the
11004serial port.
11005
11006@table @code
11007@item int getDebugChar()
11008@kindex getDebugChar
11009Write this subroutine to read a single character from the serial port.
11010It may be identical to @code{getchar} for your target system; a
11011different name is used to allow you to distinguish the two if you wish.
11012
11013@item void putDebugChar(int)
11014@kindex putDebugChar
11015Write this subroutine to write a single character to the serial port.
5d161b24 11016It may be identical to @code{putchar} for your target system; a
104c1213
JM
11017different name is used to allow you to distinguish the two if you wish.
11018@end table
11019
11020@cindex control C, and remote debugging
11021@cindex interrupting remote targets
11022If you want @value{GDBN} to be able to stop your program while it is
11023running, you need to use an interrupt-driven serial driver, and arrange
11024for it to stop when it receives a @code{^C} (@samp{\003}, the control-C
11025character). That is the character which @value{GDBN} uses to tell the
11026remote system to stop.
11027
11028Getting the debugging target to return the proper status to @value{GDBN}
11029probably requires changes to the standard stub; one quick and dirty way
11030is to just execute a breakpoint instruction (the ``dirty'' part is that
11031@value{GDBN} reports a @code{SIGTRAP} instead of a @code{SIGINT}).
11032
11033Other routines you need to supply are:
11034
11035@table @code
11036@item void exceptionHandler (int @var{exception_number}, void *@var{exception_address})
11037@kindex exceptionHandler
11038Write this function to install @var{exception_address} in the exception
11039handling tables. You need to do this because the stub does not have any
11040way of knowing what the exception handling tables on your target system
11041are like (for example, the processor's table might be in @sc{rom},
11042containing entries which point to a table in @sc{ram}).
11043@var{exception_number} is the exception number which should be changed;
11044its meaning is architecture-dependent (for example, different numbers
11045might represent divide by zero, misaligned access, etc). When this
11046exception occurs, control should be transferred directly to
11047@var{exception_address}, and the processor state (stack, registers,
11048and so on) should be just as it is when a processor exception occurs. So if
11049you want to use a jump instruction to reach @var{exception_address}, it
11050should be a simple jump, not a jump to subroutine.
11051
11052For the 386, @var{exception_address} should be installed as an interrupt
11053gate so that interrupts are masked while the handler runs. The gate
11054should be at privilege level 0 (the most privileged level). The
11055@sc{sparc} and 68k stubs are able to mask interrupts themselves without
11056help from @code{exceptionHandler}.
11057
11058@item void flush_i_cache()
11059@kindex flush_i_cache
d4f3574e 11060On @sc{sparc} and @sc{sparclite} only, write this subroutine to flush the
104c1213
JM
11061instruction cache, if any, on your target machine. If there is no
11062instruction cache, this subroutine may be a no-op.
11063
11064On target machines that have instruction caches, @value{GDBN} requires this
11065function to make certain that the state of your program is stable.
11066@end table
11067
11068@noindent
11069You must also make sure this library routine is available:
11070
11071@table @code
11072@item void *memset(void *, int, int)
11073@kindex memset
11074This is the standard library function @code{memset} that sets an area of
11075memory to a known value. If you have one of the free versions of
11076@code{libc.a}, @code{memset} can be found there; otherwise, you must
11077either obtain it from your hardware manufacturer, or write your own.
11078@end table
11079
11080If you do not use the GNU C compiler, you may need other standard
11081library subroutines as well; this varies from one stub to another,
11082but in general the stubs are likely to use any of the common library
d4f3574e 11083subroutines which @code{@value{GCC}} generates as inline code.
104c1213
JM
11084
11085
6d2ebf8b 11086@node Debug Session
6f05cf9f 11087@subsection Putting it all together
104c1213
JM
11088
11089@cindex remote serial debugging summary
11090In summary, when your program is ready to debug, you must follow these
11091steps.
11092
11093@enumerate
11094@item
6d2ebf8b 11095Make sure you have defined the supporting low-level routines
104c1213
JM
11096(@pxref{Bootstrapping,,What you must do for the stub}):
11097@display
11098@code{getDebugChar}, @code{putDebugChar},
11099@code{flush_i_cache}, @code{memset}, @code{exceptionHandler}.
11100@end display
11101
11102@item
11103Insert these lines near the top of your program:
11104
474c8240 11105@smallexample
104c1213
JM
11106set_debug_traps();
11107breakpoint();
474c8240 11108@end smallexample
104c1213
JM
11109
11110@item
11111For the 680x0 stub only, you need to provide a variable called
11112@code{exceptionHook}. Normally you just use:
11113
474c8240 11114@smallexample
104c1213 11115void (*exceptionHook)() = 0;
474c8240 11116@end smallexample
104c1213 11117
d4f3574e 11118@noindent
104c1213 11119but if before calling @code{set_debug_traps}, you set it to point to a
598ca718 11120function in your program, that function is called when
104c1213
JM
11121@code{@value{GDBN}} continues after stopping on a trap (for example, bus
11122error). The function indicated by @code{exceptionHook} is called with
11123one parameter: an @code{int} which is the exception number.
11124
11125@item
11126Compile and link together: your program, the @value{GDBN} debugging stub for
11127your target architecture, and the supporting subroutines.
11128
11129@item
11130Make sure you have a serial connection between your target machine and
11131the @value{GDBN} host, and identify the serial port on the host.
11132
11133@item
11134@c The "remote" target now provides a `load' command, so we should
11135@c document that. FIXME.
11136Download your program to your target machine (or get it there by
11137whatever means the manufacturer provides), and start it.
11138
11139@item
07f31aa6
DJ
11140Start @value{GDBN} on the host, and connect to the target
11141(@pxref{Connecting,,Connecting to a remote target}).
9db8d71f 11142
104c1213
JM
11143@end enumerate
11144
8e04817f
AC
11145@node Configurations
11146@chapter Configuration-Specific Information
104c1213 11147
8e04817f
AC
11148While nearly all @value{GDBN} commands are available for all native and
11149cross versions of the debugger, there are some exceptions. This chapter
11150describes things that are only available in certain configurations.
104c1213 11151
8e04817f
AC
11152There are three major categories of configurations: native
11153configurations, where the host and target are the same, embedded
11154operating system configurations, which are usually the same for several
11155different processor architectures, and bare embedded processors, which
11156are quite different from each other.
104c1213 11157
8e04817f
AC
11158@menu
11159* Native::
11160* Embedded OS::
11161* Embedded Processors::
11162* Architectures::
11163@end menu
104c1213 11164
8e04817f
AC
11165@node Native
11166@section Native
104c1213 11167
8e04817f
AC
11168This section describes details specific to particular native
11169configurations.
6cf7e474 11170
8e04817f
AC
11171@menu
11172* HP-UX:: HP-UX
11173* SVR4 Process Information:: SVR4 process information
11174* DJGPP Native:: Features specific to the DJGPP port
78c47bea 11175* Cygwin Native:: Features specific to the Cygwin port
8e04817f 11176@end menu
6cf7e474 11177
8e04817f
AC
11178@node HP-UX
11179@subsection HP-UX
104c1213 11180
8e04817f
AC
11181On HP-UX systems, if you refer to a function or variable name that
11182begins with a dollar sign, @value{GDBN} searches for a user or system
11183name first, before it searches for a convenience variable.
104c1213 11184
8e04817f
AC
11185@node SVR4 Process Information
11186@subsection SVR4 process information
104c1213 11187
8e04817f
AC
11188@kindex /proc
11189@cindex process image
104c1213 11190
8e04817f
AC
11191Many versions of SVR4 provide a facility called @samp{/proc} that can be
11192used to examine the image of a running process using file-system
11193subroutines. If @value{GDBN} is configured for an operating system with
11194this facility, the command @code{info proc} is available to report on
11195several kinds of information about the process running your program.
11196@code{info proc} works only on SVR4 systems that include the
11197@code{procfs} code. This includes OSF/1 (Digital Unix), Solaris, Irix,
1104b9e7 11198and Unixware, but not HP-UX or @sc{gnu}/Linux, for example.
104c1213 11199
8e04817f
AC
11200@table @code
11201@kindex info proc
11202@item info proc
11203Summarize available information about the process.
6cf7e474 11204
8e04817f
AC
11205@kindex info proc mappings
11206@item info proc mappings
11207Report on the address ranges accessible in the program, with information
11208on whether your program may read, write, or execute each range.
11209@ignore
11210@comment These sub-options of 'info proc' were not included when
11211@comment procfs.c was re-written. Keep their descriptions around
11212@comment against the day when someone finds the time to put them back in.
11213@kindex info proc times
11214@item info proc times
11215Starting time, user CPU time, and system CPU time for your program and
11216its children.
6cf7e474 11217
8e04817f
AC
11218@kindex info proc id
11219@item info proc id
11220Report on the process IDs related to your program: its own process ID,
11221the ID of its parent, the process group ID, and the session ID.
104c1213 11222
8e04817f
AC
11223@kindex info proc status
11224@item info proc status
11225General information on the state of the process. If the process is
11226stopped, this report includes the reason for stopping, and any signal
11227received.
d4f3574e 11228
8e04817f
AC
11229@item info proc all
11230Show all the above information about the process.
11231@end ignore
11232@end table
104c1213 11233
8e04817f
AC
11234@node DJGPP Native
11235@subsection Features for Debugging @sc{djgpp} Programs
11236@cindex @sc{djgpp} debugging
11237@cindex native @sc{djgpp} debugging
11238@cindex MS-DOS-specific commands
104c1213 11239
8e04817f
AC
11240@sc{djgpp} is the port of @sc{gnu} development tools to MS-DOS and
11241MS-Windows. @sc{djgpp} programs are 32-bit protected-mode programs
11242that use the @dfn{DPMI} (DOS Protected-Mode Interface) API to run on
11243top of real-mode DOS systems and their emulations.
104c1213 11244
8e04817f
AC
11245@value{GDBN} supports native debugging of @sc{djgpp} programs, and
11246defines a few commands specific to the @sc{djgpp} port. This
11247subsection describes those commands.
104c1213 11248
8e04817f
AC
11249@table @code
11250@kindex info dos
11251@item info dos
11252This is a prefix of @sc{djgpp}-specific commands which print
11253information about the target system and important OS structures.
f1251bdd 11254
8e04817f
AC
11255@kindex sysinfo
11256@cindex MS-DOS system info
11257@cindex free memory information (MS-DOS)
11258@item info dos sysinfo
11259This command displays assorted information about the underlying
11260platform: the CPU type and features, the OS version and flavor, the
11261DPMI version, and the available conventional and DPMI memory.
104c1213 11262
8e04817f
AC
11263@cindex GDT
11264@cindex LDT
11265@cindex IDT
11266@cindex segment descriptor tables
11267@cindex descriptor tables display
11268@item info dos gdt
11269@itemx info dos ldt
11270@itemx info dos idt
11271These 3 commands display entries from, respectively, Global, Local,
11272and Interrupt Descriptor Tables (GDT, LDT, and IDT). The descriptor
11273tables are data structures which store a descriptor for each segment
11274that is currently in use. The segment's selector is an index into a
11275descriptor table; the table entry for that index holds the
11276descriptor's base address and limit, and its attributes and access
11277rights.
104c1213 11278
8e04817f
AC
11279A typical @sc{djgpp} program uses 3 segments: a code segment, a data
11280segment (used for both data and the stack), and a DOS segment (which
11281allows access to DOS/BIOS data structures and absolute addresses in
11282conventional memory). However, the DPMI host will usually define
11283additional segments in order to support the DPMI environment.
d4f3574e 11284
8e04817f
AC
11285@cindex garbled pointers
11286These commands allow to display entries from the descriptor tables.
11287Without an argument, all entries from the specified table are
11288displayed. An argument, which should be an integer expression, means
11289display a single entry whose index is given by the argument. For
11290example, here's a convenient way to display information about the
11291debugged program's data segment:
104c1213 11292
8e04817f
AC
11293@smallexample
11294@exdent @code{(@value{GDBP}) info dos ldt $ds}
11295@exdent @code{0x13f: base=0x11970000 limit=0x0009ffff 32-Bit Data (Read/Write, Exp-up)}
11296@end smallexample
104c1213 11297
8e04817f
AC
11298@noindent
11299This comes in handy when you want to see whether a pointer is outside
11300the data segment's limit (i.e.@: @dfn{garbled}).
104c1213 11301
8e04817f
AC
11302@cindex page tables display (MS-DOS)
11303@item info dos pde
11304@itemx info dos pte
11305These two commands display entries from, respectively, the Page
11306Directory and the Page Tables. Page Directories and Page Tables are
11307data structures which control how virtual memory addresses are mapped
11308into physical addresses. A Page Table includes an entry for every
11309page of memory that is mapped into the program's address space; there
11310may be several Page Tables, each one holding up to 4096 entries. A
11311Page Directory has up to 4096 entries, one each for every Page Table
11312that is currently in use.
104c1213 11313
8e04817f
AC
11314Without an argument, @kbd{info dos pde} displays the entire Page
11315Directory, and @kbd{info dos pte} displays all the entries in all of
11316the Page Tables. An argument, an integer expression, given to the
11317@kbd{info dos pde} command means display only that entry from the Page
11318Directory table. An argument given to the @kbd{info dos pte} command
11319means display entries from a single Page Table, the one pointed to by
11320the specified entry in the Page Directory.
104c1213 11321
8e04817f
AC
11322@cindex direct memory access (DMA) on MS-DOS
11323These commands are useful when your program uses @dfn{DMA} (Direct
11324Memory Access), which needs physical addresses to program the DMA
11325controller.
104c1213 11326
8e04817f 11327These commands are supported only with some DPMI servers.
104c1213 11328
8e04817f
AC
11329@cindex physical address from linear address
11330@item info dos address-pte @var{addr}
11331This command displays the Page Table entry for a specified linear
11332address. The argument linear address @var{addr} should already have the
11333appropriate segment's base address added to it, because this command
11334accepts addresses which may belong to @emph{any} segment. For
11335example, here's how to display the Page Table entry for the page where
11336the variable @code{i} is stored:
104c1213 11337
8e04817f
AC
11338@smallexample
11339@exdent @code{(@value{GDBP}) info dos address-pte __djgpp_base_address + (char *)&i}
11340@exdent @code{Page Table entry for address 0x11a00d30:}
11341@exdent @code{Base=0x02698000 Dirty Acc. Not-Cached Write-Back Usr Read-Write +0xd30}
11342@end smallexample
104c1213 11343
8e04817f
AC
11344@noindent
11345This says that @code{i} is stored at offset @code{0xd30} from the page
11346whose physical base address is @code{0x02698000}, and prints all the
11347attributes of that page.
104c1213 11348
8e04817f
AC
11349Note that you must cast the addresses of variables to a @code{char *},
11350since otherwise the value of @code{__djgpp_base_address}, the base
11351address of all variables and functions in a @sc{djgpp} program, will
11352be added using the rules of C pointer arithmetics: if @code{i} is
11353declared an @code{int}, @value{GDBN} will add 4 times the value of
11354@code{__djgpp_base_address} to the address of @code{i}.
104c1213 11355
8e04817f
AC
11356Here's another example, it displays the Page Table entry for the
11357transfer buffer:
104c1213 11358
8e04817f
AC
11359@smallexample
11360@exdent @code{(@value{GDBP}) info dos address-pte *((unsigned *)&_go32_info_block + 3)}
11361@exdent @code{Page Table entry for address 0x29110:}
11362@exdent @code{Base=0x00029000 Dirty Acc. Not-Cached Write-Back Usr Read-Write +0x110}
11363@end smallexample
104c1213 11364
8e04817f
AC
11365@noindent
11366(The @code{+ 3} offset is because the transfer buffer's address is the
113673rd member of the @code{_go32_info_block} structure.) The output of
11368this command clearly shows that addresses in conventional memory are
11369mapped 1:1, i.e.@: the physical and linear addresses are identical.
104c1213 11370
8e04817f
AC
11371This command is supported only with some DPMI servers.
11372@end table
104c1213 11373
78c47bea
PM
11374@node Cygwin Native
11375@subsection Features for Debugging MS Windows PE executables
11376@cindex MS Windows debugging
11377@cindex native Cygwin debugging
11378@cindex Cygwin-specific commands
11379
be448670
CF
11380@value{GDBN} supports native debugging of MS Windows programs, including
11381DLLs with and without symbolic debugging information. There are various
11382additional Cygwin-specific commands, described in this subsection. The
11383subsubsection @pxref{Non-debug DLL symbols} describes working with DLLs
11384that have no debugging symbols.
11385
78c47bea
PM
11386
11387@table @code
11388@kindex info w32
11389@item info w32
11390This is a prefix of MS Windows specific commands which print
11391information about the target system and important OS structures.
11392
11393@item info w32 selector
11394This command displays information returned by
11395the Win32 API @code{GetThreadSelectorEntry} function.
11396It takes an optional argument that is evaluated to
11397a long value to give the information about this given selector.
11398Without argument, this command displays information
11399about the the six segment registers.
11400
11401@kindex info dll
11402@item info dll
11403This is a Cygwin specific alias of info shared.
11404
11405@kindex dll-symbols
11406@item dll-symbols
11407This command loads symbols from a dll similarly to
11408add-sym command but without the need to specify a base address.
11409
11410@kindex set new-console
11411@item set new-console @var{mode}
11412If @var{mode} is @code{on} the debuggee will
11413be started in a new console on next start.
11414If @var{mode} is @code{off}i, the debuggee will
11415be started in the same console as the debugger.
11416
11417@kindex show new-console
11418@item show new-console
11419Displays whether a new console is used
11420when the debuggee is started.
11421
11422@kindex set new-group
11423@item set new-group @var{mode}
11424This boolean value controls whether the debuggee should
11425start a new group or stay in the same group as the debugger.
11426This affects the way the Windows OS handles
11427Ctrl-C.
11428
11429@kindex show new-group
11430@item show new-group
11431Displays current value of new-group boolean.
11432
11433@kindex set debugevents
11434@item set debugevents
11435This boolean value adds debug output concerning events seen by the debugger.
11436
11437@kindex set debugexec
11438@item set debugexec
11439This boolean value adds debug output concerning execute events
11440seen by the debugger.
11441
11442@kindex set debugexceptions
11443@item set debugexceptions
11444This boolean value adds debug ouptut concerning exception events
11445seen by the debugger.
11446
11447@kindex set debugmemory
11448@item set debugmemory
11449This boolean value adds debug ouptut concerning memory events
11450seen by the debugger.
11451
11452@kindex set shell
11453@item set shell
11454This boolean values specifies whether the debuggee is called
11455via a shell or directly (default value is on).
11456
11457@kindex show shell
11458@item show shell
11459Displays if the debuggee will be started with a shell.
11460
11461@end table
11462
be448670
CF
11463@menu
11464* Non-debug DLL symbols:: Support for DLLs without debugging symbols
11465@end menu
11466
11467@node Non-debug DLL symbols
11468@subsubsection Support for DLLs without debugging symbols
11469@cindex DLLs with no debugging symbols
11470@cindex Minimal symbols and DLLs
11471
11472Very often on windows, some of the DLLs that your program relies on do
11473not include symbolic debugging information (for example,
11474@file{kernel32.dll}). When @value{GDBN} doesn't recognize any debugging
11475symbols in a DLL, it relies on the minimal amount of symbolic
11476information contained in the DLL's export table. This subsubsection
11477describes working with such symbols, known internally to @value{GDBN} as
11478``minimal symbols''.
11479
11480Note that before the debugged program has started execution, no DLLs
11481will have been loaded. The easiest way around this problem is simply to
11482start the program --- either by setting a breakpoint or letting the
11483program run once to completion. It is also possible to force
11484@value{GDBN} to load a particular DLL before starting the executable ---
11485see the shared library information in @pxref{Files} or the
11486@code{dll-symbols} command in @pxref{Cygwin Native}. Currently,
11487explicitly loading symbols from a DLL with no debugging information will
11488cause the symbol names to be duplicated in @value{GDBN}'s lookup table,
11489which may adversely affect symbol lookup performance.
11490
11491@subsubsection DLL name prefixes
11492
11493In keeping with the naming conventions used by the Microsoft debugging
11494tools, DLL export symbols are made available with a prefix based on the
11495DLL name, for instance @code{KERNEL32!CreateFileA}. The plain name is
11496also entered into the symbol table, so @code{CreateFileA} is often
11497sufficient. In some cases there will be name clashes within a program
11498(particularly if the executable itself includes full debugging symbols)
11499necessitating the use of the fully qualified name when referring to the
11500contents of the DLL. Use single-quotes around the name to avoid the
11501exclamation mark (``!'') being interpreted as a language operator.
11502
11503Note that the internal name of the DLL may be all upper-case, even
11504though the file name of the DLL is lower-case, or vice-versa. Since
11505symbols within @value{GDBN} are @emph{case-sensitive} this may cause
11506some confusion. If in doubt, try the @code{info functions} and
11507@code{info variables} commands or even @code{maint print msymbols} (see
11508@pxref{Symbols}). Here's an example:
11509
11510@smallexample
11511(gdb) info function CreateFileA
11512All functions matching regular expression "CreateFileA":
11513
11514Non-debugging symbols:
115150x77e885f4 CreateFileA
115160x77e885f4 KERNEL32!CreateFileA
11517@end smallexample
11518
11519@smallexample
11520(gdb) info function !
11521All functions matching regular expression "!":
11522
11523Non-debugging symbols:
115240x6100114c cygwin1!__assert
115250x61004034 cygwin1!_dll_crt0@@0
115260x61004240 cygwin1!dll_crt0(per_process *)
11527[etc...]
11528@end smallexample
11529
11530@subsubsection Working with minimal symbols
11531
11532Symbols extracted from a DLL's export table do not contain very much
11533type information. All that @value{GDBN} can do is guess whether a symbol
11534refers to a function or variable depending on the linker section that
11535contains the symbol. Also note that the actual contents of the memory
11536contained in a DLL are not available unless the program is running. This
11537means that you cannot examine the contents of a variable or disassemble
11538a function within a DLL without a running program.
11539
11540Variables are generally treated as pointers and dereferenced
11541automatically. For this reason, it is often necessary to prefix a
11542variable name with the address-of operator (``&'') and provide explicit
11543type information in the command. Here's an example of the type of
11544problem:
11545
11546@smallexample
11547(gdb) print 'cygwin1!__argv'
11548$1 = 268572168
11549@end smallexample
11550
11551@smallexample
11552(gdb) x 'cygwin1!__argv'
115530x10021610: "\230y\""
11554@end smallexample
11555
11556And two possible solutions:
11557
11558@smallexample
11559(gdb) print ((char **)'cygwin1!__argv')[0]
11560$2 = 0x22fd98 "/cygdrive/c/mydirectory/myprogram"
11561@end smallexample
11562
11563@smallexample
11564(gdb) x/2x &'cygwin1!__argv'
115650x610c0aa8 <cygwin1!__argv>: 0x10021608 0x00000000
11566(gdb) x/x 0x10021608
115670x10021608: 0x0022fd98
11568(gdb) x/s 0x0022fd98
115690x22fd98: "/cygdrive/c/mydirectory/myprogram"
11570@end smallexample
11571
11572Setting a break point within a DLL is possible even before the program
11573starts execution. However, under these circumstances, @value{GDBN} can't
11574examine the initial instructions of the function in order to skip the
11575function's frame set-up code. You can work around this by using ``*&''
11576to set the breakpoint at a raw memory address:
11577
11578@smallexample
11579(gdb) break *&'python22!PyOS_Readline'
11580Breakpoint 1 at 0x1e04eff0
11581@end smallexample
11582
11583The author of these extensions is not entirely convinced that setting a
11584break point within a shared DLL like @file{kernel32.dll} is completely
11585safe.
11586
8e04817f
AC
11587@node Embedded OS
11588@section Embedded Operating Systems
104c1213 11589
8e04817f
AC
11590This section describes configurations involving the debugging of
11591embedded operating systems that are available for several different
11592architectures.
d4f3574e 11593
8e04817f
AC
11594@menu
11595* VxWorks:: Using @value{GDBN} with VxWorks
11596@end menu
104c1213 11597
8e04817f
AC
11598@value{GDBN} includes the ability to debug programs running on
11599various real-time operating systems.
104c1213 11600
8e04817f
AC
11601@node VxWorks
11602@subsection Using @value{GDBN} with VxWorks
104c1213 11603
8e04817f 11604@cindex VxWorks
104c1213 11605
8e04817f 11606@table @code
104c1213 11607
8e04817f
AC
11608@kindex target vxworks
11609@item target vxworks @var{machinename}
11610A VxWorks system, attached via TCP/IP. The argument @var{machinename}
11611is the target system's machine name or IP address.
104c1213 11612
8e04817f 11613@end table
104c1213 11614
8e04817f
AC
11615On VxWorks, @code{load} links @var{filename} dynamically on the
11616current target system as well as adding its symbols in @value{GDBN}.
104c1213 11617
8e04817f
AC
11618@value{GDBN} enables developers to spawn and debug tasks running on networked
11619VxWorks targets from a Unix host. Already-running tasks spawned from
11620the VxWorks shell can also be debugged. @value{GDBN} uses code that runs on
11621both the Unix host and on the VxWorks target. The program
11622@code{@value{GDBP}} is installed and executed on the Unix host. (It may be
11623installed with the name @code{vxgdb}, to distinguish it from a
11624@value{GDBN} for debugging programs on the host itself.)
104c1213 11625
8e04817f
AC
11626@table @code
11627@item VxWorks-timeout @var{args}
11628@kindex vxworks-timeout
11629All VxWorks-based targets now support the option @code{vxworks-timeout}.
11630This option is set by the user, and @var{args} represents the number of
11631seconds @value{GDBN} waits for responses to rpc's. You might use this if
11632your VxWorks target is a slow software simulator or is on the far side
11633of a thin network line.
11634@end table
104c1213 11635
8e04817f
AC
11636The following information on connecting to VxWorks was current when
11637this manual was produced; newer releases of VxWorks may use revised
11638procedures.
104c1213 11639
8e04817f
AC
11640@kindex INCLUDE_RDB
11641To use @value{GDBN} with VxWorks, you must rebuild your VxWorks kernel
11642to include the remote debugging interface routines in the VxWorks
11643library @file{rdb.a}. To do this, define @code{INCLUDE_RDB} in the
11644VxWorks configuration file @file{configAll.h} and rebuild your VxWorks
11645kernel. The resulting kernel contains @file{rdb.a}, and spawns the
11646source debugging task @code{tRdbTask} when VxWorks is booted. For more
11647information on configuring and remaking VxWorks, see the manufacturer's
11648manual.
11649@c VxWorks, see the @cite{VxWorks Programmer's Guide}.
104c1213 11650
8e04817f
AC
11651Once you have included @file{rdb.a} in your VxWorks system image and set
11652your Unix execution search path to find @value{GDBN}, you are ready to
11653run @value{GDBN}. From your Unix host, run @code{@value{GDBP}} (or
11654@code{vxgdb}, depending on your installation).
104c1213 11655
8e04817f 11656@value{GDBN} comes up showing the prompt:
104c1213 11657
474c8240 11658@smallexample
8e04817f 11659(vxgdb)
474c8240 11660@end smallexample
104c1213 11661
8e04817f
AC
11662@menu
11663* VxWorks Connection:: Connecting to VxWorks
11664* VxWorks Download:: VxWorks download
11665* VxWorks Attach:: Running tasks
11666@end menu
104c1213 11667
8e04817f
AC
11668@node VxWorks Connection
11669@subsubsection Connecting to VxWorks
104c1213 11670
8e04817f
AC
11671The @value{GDBN} command @code{target} lets you connect to a VxWorks target on the
11672network. To connect to a target whose host name is ``@code{tt}'', type:
104c1213 11673
474c8240 11674@smallexample
8e04817f 11675(vxgdb) target vxworks tt
474c8240 11676@end smallexample
104c1213 11677
8e04817f
AC
11678@need 750
11679@value{GDBN} displays messages like these:
104c1213 11680
8e04817f
AC
11681@smallexample
11682Attaching remote machine across net...
11683Connected to tt.
11684@end smallexample
104c1213 11685
8e04817f
AC
11686@need 1000
11687@value{GDBN} then attempts to read the symbol tables of any object modules
11688loaded into the VxWorks target since it was last booted. @value{GDBN} locates
11689these files by searching the directories listed in the command search
11690path (@pxref{Environment, ,Your program's environment}); if it fails
11691to find an object file, it displays a message such as:
5d161b24 11692
474c8240 11693@smallexample
8e04817f 11694prog.o: No such file or directory.
474c8240 11695@end smallexample
104c1213 11696
8e04817f
AC
11697When this happens, add the appropriate directory to the search path with
11698the @value{GDBN} command @code{path}, and execute the @code{target}
11699command again.
104c1213 11700
8e04817f
AC
11701@node VxWorks Download
11702@subsubsection VxWorks download
104c1213 11703
8e04817f
AC
11704@cindex download to VxWorks
11705If you have connected to the VxWorks target and you want to debug an
11706object that has not yet been loaded, you can use the @value{GDBN}
11707@code{load} command to download a file from Unix to VxWorks
11708incrementally. The object file given as an argument to the @code{load}
11709command is actually opened twice: first by the VxWorks target in order
11710to download the code, then by @value{GDBN} in order to read the symbol
11711table. This can lead to problems if the current working directories on
11712the two systems differ. If both systems have NFS mounted the same
11713filesystems, you can avoid these problems by using absolute paths.
11714Otherwise, it is simplest to set the working directory on both systems
11715to the directory in which the object file resides, and then to reference
11716the file by its name, without any path. For instance, a program
11717@file{prog.o} may reside in @file{@var{vxpath}/vw/demo/rdb} in VxWorks
11718and in @file{@var{hostpath}/vw/demo/rdb} on the host. To load this
11719program, type this on VxWorks:
104c1213 11720
474c8240 11721@smallexample
8e04817f 11722-> cd "@var{vxpath}/vw/demo/rdb"
474c8240 11723@end smallexample
104c1213 11724
8e04817f
AC
11725@noindent
11726Then, in @value{GDBN}, type:
104c1213 11727
474c8240 11728@smallexample
8e04817f
AC
11729(vxgdb) cd @var{hostpath}/vw/demo/rdb
11730(vxgdb) load prog.o
474c8240 11731@end smallexample
104c1213 11732
8e04817f 11733@value{GDBN} displays a response similar to this:
104c1213 11734
8e04817f
AC
11735@smallexample
11736Reading symbol data from wherever/vw/demo/rdb/prog.o... done.
11737@end smallexample
104c1213 11738
8e04817f
AC
11739You can also use the @code{load} command to reload an object module
11740after editing and recompiling the corresponding source file. Note that
11741this makes @value{GDBN} delete all currently-defined breakpoints,
11742auto-displays, and convenience variables, and to clear the value
11743history. (This is necessary in order to preserve the integrity of
11744debugger's data structures that reference the target system's symbol
11745table.)
104c1213 11746
8e04817f
AC
11747@node VxWorks Attach
11748@subsubsection Running tasks
104c1213
JM
11749
11750@cindex running VxWorks tasks
11751You can also attach to an existing task using the @code{attach} command as
11752follows:
11753
474c8240 11754@smallexample
104c1213 11755(vxgdb) attach @var{task}
474c8240 11756@end smallexample
104c1213
JM
11757
11758@noindent
11759where @var{task} is the VxWorks hexadecimal task ID. The task can be running
11760or suspended when you attach to it. Running tasks are suspended at
11761the time of attachment.
11762
6d2ebf8b 11763@node Embedded Processors
104c1213
JM
11764@section Embedded Processors
11765
11766This section goes into details specific to particular embedded
11767configurations.
11768
7d86b5d5 11769
104c1213 11770@menu
104c1213
JM
11771* ARM:: ARM
11772* H8/300:: Hitachi H8/300
11773* H8/500:: Hitachi H8/500
104c1213
JM
11774* M32R/D:: Mitsubishi M32R/D
11775* M68K:: Motorola M68K
104c1213 11776* MIPS Embedded:: MIPS Embedded
a37295f9 11777* OpenRISC 1000:: OpenRisc 1000
104c1213
JM
11778* PA:: HP PA Embedded
11779* PowerPC: PowerPC
11780* SH:: Hitachi SH
11781* Sparclet:: Tsqware Sparclet
11782* Sparclite:: Fujitsu Sparclite
11783* ST2000:: Tandem ST2000
11784* Z8000:: Zilog Z8000
11785@end menu
11786
6d2ebf8b 11787@node ARM
104c1213
JM
11788@subsection ARM
11789
11790@table @code
11791
8e04817f
AC
11792@kindex target rdi
11793@item target rdi @var{dev}
11794ARM Angel monitor, via RDI library interface to ADP protocol. You may
11795use this target to communicate with both boards running the Angel
11796monitor, or with the EmbeddedICE JTAG debug device.
11797
11798@kindex target rdp
11799@item target rdp @var{dev}
11800ARM Demon monitor.
11801
11802@end table
11803
11804@node H8/300
11805@subsection Hitachi H8/300
11806
11807@table @code
11808
11809@kindex target hms@r{, with H8/300}
11810@item target hms @var{dev}
11811A Hitachi SH, H8/300, or H8/500 board, attached via serial line to your host.
11812Use special commands @code{device} and @code{speed} to control the serial
11813line and the communications speed used.
11814
11815@kindex target e7000@r{, with H8/300}
11816@item target e7000 @var{dev}
11817E7000 emulator for Hitachi H8 and SH.
11818
11819@kindex target sh3@r{, with H8/300}
11820@kindex target sh3e@r{, with H8/300}
11821@item target sh3 @var{dev}
11822@itemx target sh3e @var{dev}
11823Hitachi SH-3 and SH-3E target systems.
11824
11825@end table
11826
11827@cindex download to H8/300 or H8/500
11828@cindex H8/300 or H8/500 download
11829@cindex download to Hitachi SH
11830@cindex Hitachi SH download
11831When you select remote debugging to a Hitachi SH, H8/300, or H8/500
11832board, the @code{load} command downloads your program to the Hitachi
11833board and also opens it as the current executable target for
11834@value{GDBN} on your host (like the @code{file} command).
11835
11836@value{GDBN} needs to know these things to talk to your
11837Hitachi SH, H8/300, or H8/500:
11838
11839@enumerate
11840@item
11841that you want to use @samp{target hms}, the remote debugging interface
11842for Hitachi microprocessors, or @samp{target e7000}, the in-circuit
11843emulator for the Hitachi SH and the Hitachi 300H. (@samp{target hms} is
11844the default when @value{GDBN} is configured specifically for the Hitachi SH,
11845H8/300, or H8/500.)
11846
11847@item
11848what serial device connects your host to your Hitachi board (the first
11849serial device available on your host is the default).
11850
11851@item
11852what speed to use over the serial device.
11853@end enumerate
11854
11855@menu
11856* Hitachi Boards:: Connecting to Hitachi boards.
11857* Hitachi ICE:: Using the E7000 In-Circuit Emulator.
11858* Hitachi Special:: Special @value{GDBN} commands for Hitachi micros.
11859@end menu
11860
11861@node Hitachi Boards
11862@subsubsection Connecting to Hitachi boards
11863
11864@c only for Unix hosts
11865@kindex device
11866@cindex serial device, Hitachi micros
11867Use the special @code{@value{GDBN}} command @samp{device @var{port}} if you
11868need to explicitly set the serial device. The default @var{port} is the
11869first available port on your host. This is only necessary on Unix
11870hosts, where it is typically something like @file{/dev/ttya}.
11871
11872@kindex speed
11873@cindex serial line speed, Hitachi micros
11874@code{@value{GDBN}} has another special command to set the communications
11875speed: @samp{speed @var{bps}}. This command also is only used from Unix
11876hosts; on DOS hosts, set the line speed as usual from outside @value{GDBN} with
11877the DOS @code{mode} command (for instance,
11878@w{@kbd{mode com2:9600,n,8,1,p}} for a 9600@dmn{bps} connection).
11879
11880The @samp{device} and @samp{speed} commands are available only when you
11881use a Unix host to debug your Hitachi microprocessor programs. If you
11882use a DOS host,
11883@value{GDBN} depends on an auxiliary terminate-and-stay-resident program
11884called @code{asynctsr} to communicate with the development board
11885through a PC serial port. You must also use the DOS @code{mode} command
11886to set up the serial port on the DOS side.
11887
11888The following sample session illustrates the steps needed to start a
11889program under @value{GDBN} control on an H8/300. The example uses a
11890sample H8/300 program called @file{t.x}. The procedure is the same for
11891the Hitachi SH and the H8/500.
11892
11893First hook up your development board. In this example, we use a
11894board attached to serial port @code{COM2}; if you use a different serial
11895port, substitute its name in the argument of the @code{mode} command.
11896When you call @code{asynctsr}, the auxiliary comms program used by the
11897debugger, you give it just the numeric part of the serial port's name;
11898for example, @samp{asyncstr 2} below runs @code{asyncstr} on
11899@code{COM2}.
11900
474c8240 11901@smallexample
8e04817f
AC
11902C:\H8300\TEST> asynctsr 2
11903C:\H8300\TEST> mode com2:9600,n,8,1,p
11904
11905Resident portion of MODE loaded
11906
11907COM2: 9600, n, 8, 1, p
11908
474c8240 11909@end smallexample
8e04817f
AC
11910
11911@quotation
11912@emph{Warning:} We have noticed a bug in PC-NFS that conflicts with
11913@code{asynctsr}. If you also run PC-NFS on your DOS host, you may need to
11914disable it, or even boot without it, to use @code{asynctsr} to control
11915your development board.
11916@end quotation
11917
11918@kindex target hms@r{, and serial protocol}
11919Now that serial communications are set up, and the development board is
11920connected, you can start up @value{GDBN}. Call @code{@value{GDBP}} with
11921the name of your program as the argument. @code{@value{GDBN}} prompts
11922you, as usual, with the prompt @samp{(@value{GDBP})}. Use two special
11923commands to begin your debugging session: @samp{target hms} to specify
11924cross-debugging to the Hitachi board, and the @code{load} command to
11925download your program to the board. @code{load} displays the names of
11926the program's sections, and a @samp{*} for each 2K of data downloaded.
11927(If you want to refresh @value{GDBN} data on symbols or on the
11928executable file without downloading, use the @value{GDBN} commands
11929@code{file} or @code{symbol-file}. These commands, and @code{load}
11930itself, are described in @ref{Files,,Commands to specify files}.)
11931
11932@smallexample
11933(eg-C:\H8300\TEST) @value{GDBP} t.x
11934@value{GDBN} is free software and you are welcome to distribute copies
11935 of it under certain conditions; type "show copying" to see
11936 the conditions.
11937There is absolutely no warranty for @value{GDBN}; type "show warranty"
11938for details.
11939@value{GDBN} @value{GDBVN}, Copyright 1992 Free Software Foundation, Inc...
11940(@value{GDBP}) target hms
11941Connected to remote H8/300 HMS system.
11942(@value{GDBP}) load t.x
11943.text : 0x8000 .. 0xabde ***********
11944.data : 0xabde .. 0xad30 *
11945.stack : 0xf000 .. 0xf014 *
11946@end smallexample
11947
11948At this point, you're ready to run or debug your program. From here on,
11949you can use all the usual @value{GDBN} commands. The @code{break} command
11950sets breakpoints; the @code{run} command starts your program;
11951@code{print} or @code{x} display data; the @code{continue} command
11952resumes execution after stopping at a breakpoint. You can use the
11953@code{help} command at any time to find out more about @value{GDBN} commands.
11954
11955Remember, however, that @emph{operating system} facilities aren't
11956available on your development board; for example, if your program hangs,
11957you can't send an interrupt---but you can press the @sc{reset} switch!
11958
11959Use the @sc{reset} button on the development board
11960@itemize @bullet
11961@item
11962to interrupt your program (don't use @kbd{ctl-C} on the DOS host---it has
11963no way to pass an interrupt signal to the development board); and
11964
11965@item
11966to return to the @value{GDBN} command prompt after your program finishes
11967normally. The communications protocol provides no other way for @value{GDBN}
11968to detect program completion.
11969@end itemize
11970
11971In either case, @value{GDBN} sees the effect of a @sc{reset} on the
11972development board as a ``normal exit'' of your program.
11973
11974@node Hitachi ICE
11975@subsubsection Using the E7000 in-circuit emulator
11976
11977@kindex target e7000@r{, with Hitachi ICE}
11978You can use the E7000 in-circuit emulator to develop code for either the
11979Hitachi SH or the H8/300H. Use one of these forms of the @samp{target
11980e7000} command to connect @value{GDBN} to your E7000:
11981
11982@table @code
11983@item target e7000 @var{port} @var{speed}
11984Use this form if your E7000 is connected to a serial port. The
11985@var{port} argument identifies what serial port to use (for example,
11986@samp{com2}). The third argument is the line speed in bits per second
11987(for example, @samp{9600}).
11988
11989@item target e7000 @var{hostname}
11990If your E7000 is installed as a host on a TCP/IP network, you can just
11991specify its hostname; @value{GDBN} uses @code{telnet} to connect.
11992@end table
11993
11994@node Hitachi Special
11995@subsubsection Special @value{GDBN} commands for Hitachi micros
11996
11997Some @value{GDBN} commands are available only for the H8/300:
11998
11999@table @code
12000
12001@kindex set machine
12002@kindex show machine
12003@item set machine h8300
12004@itemx set machine h8300h
12005Condition @value{GDBN} for one of the two variants of the H8/300
12006architecture with @samp{set machine}. You can use @samp{show machine}
12007to check which variant is currently in effect.
104c1213
JM
12008
12009@end table
12010
8e04817f
AC
12011@node H8/500
12012@subsection H8/500
104c1213
JM
12013
12014@table @code
12015
8e04817f
AC
12016@kindex set memory @var{mod}
12017@cindex memory models, H8/500
12018@item set memory @var{mod}
12019@itemx show memory
12020Specify which H8/500 memory model (@var{mod}) you are using with
12021@samp{set memory}; check which memory model is in effect with @samp{show
12022memory}. The accepted values for @var{mod} are @code{small},
12023@code{big}, @code{medium}, and @code{compact}.
104c1213 12024
8e04817f 12025@end table
104c1213 12026
8e04817f
AC
12027@node M32R/D
12028@subsection Mitsubishi M32R/D
12029
12030@table @code
12031
12032@kindex target m32r
12033@item target m32r @var{dev}
12034Mitsubishi M32R/D ROM monitor.
12035
12036@end table
12037
12038@node M68K
12039@subsection M68k
12040
12041The Motorola m68k configuration includes ColdFire support, and
12042target command for the following ROM monitors.
12043
12044@table @code
12045
12046@kindex target abug
12047@item target abug @var{dev}
12048ABug ROM monitor for M68K.
12049
12050@kindex target cpu32bug
12051@item target cpu32bug @var{dev}
12052CPU32BUG monitor, running on a CPU32 (M68K) board.
12053
12054@kindex target dbug
12055@item target dbug @var{dev}
12056dBUG ROM monitor for Motorola ColdFire.
12057
12058@kindex target est
12059@item target est @var{dev}
12060EST-300 ICE monitor, running on a CPU32 (M68K) board.
12061
12062@kindex target rom68k
12063@item target rom68k @var{dev}
12064ROM 68K monitor, running on an M68K IDP board.
12065
12066@end table
12067
8e04817f
AC
12068@table @code
12069
12070@kindex target rombug
12071@item target rombug @var{dev}
12072ROMBUG ROM monitor for OS/9000.
12073
12074@end table
12075
8e04817f
AC
12076@node MIPS Embedded
12077@subsection MIPS Embedded
12078
12079@cindex MIPS boards
12080@value{GDBN} can use the MIPS remote debugging protocol to talk to a
12081MIPS board attached to a serial line. This is available when
12082you configure @value{GDBN} with @samp{--target=mips-idt-ecoff}.
104c1213 12083
8e04817f
AC
12084@need 1000
12085Use these @value{GDBN} commands to specify the connection to your target board:
104c1213 12086
8e04817f
AC
12087@table @code
12088@item target mips @var{port}
12089@kindex target mips @var{port}
12090To run a program on the board, start up @code{@value{GDBP}} with the
12091name of your program as the argument. To connect to the board, use the
12092command @samp{target mips @var{port}}, where @var{port} is the name of
12093the serial port connected to the board. If the program has not already
12094been downloaded to the board, you may use the @code{load} command to
12095download it. You can then use all the usual @value{GDBN} commands.
104c1213 12096
8e04817f
AC
12097For example, this sequence connects to the target board through a serial
12098port, and loads and runs a program called @var{prog} through the
12099debugger:
104c1213 12100
474c8240 12101@smallexample
8e04817f
AC
12102host$ @value{GDBP} @var{prog}
12103@value{GDBN} is free software and @dots{}
12104(@value{GDBP}) target mips /dev/ttyb
12105(@value{GDBP}) load @var{prog}
12106(@value{GDBP}) run
474c8240 12107@end smallexample
104c1213 12108
8e04817f
AC
12109@item target mips @var{hostname}:@var{portnumber}
12110On some @value{GDBN} host configurations, you can specify a TCP
12111connection (for instance, to a serial line managed by a terminal
12112concentrator) instead of a serial port, using the syntax
12113@samp{@var{hostname}:@var{portnumber}}.
104c1213 12114
8e04817f
AC
12115@item target pmon @var{port}
12116@kindex target pmon @var{port}
12117PMON ROM monitor.
104c1213 12118
8e04817f
AC
12119@item target ddb @var{port}
12120@kindex target ddb @var{port}
12121NEC's DDB variant of PMON for Vr4300.
104c1213 12122
8e04817f
AC
12123@item target lsi @var{port}
12124@kindex target lsi @var{port}
12125LSI variant of PMON.
104c1213 12126
8e04817f
AC
12127@kindex target r3900
12128@item target r3900 @var{dev}
12129Densan DVE-R3900 ROM monitor for Toshiba R3900 Mips.
104c1213 12130
8e04817f
AC
12131@kindex target array
12132@item target array @var{dev}
12133Array Tech LSI33K RAID controller board.
104c1213 12134
8e04817f 12135@end table
104c1213 12136
104c1213 12137
8e04817f
AC
12138@noindent
12139@value{GDBN} also supports these special commands for MIPS targets:
104c1213 12140
8e04817f
AC
12141@table @code
12142@item set processor @var{args}
12143@itemx show processor
12144@kindex set processor @var{args}
12145@kindex show processor
12146Use the @code{set processor} command to set the type of MIPS
12147processor when you want to access processor-type-specific registers.
12148For example, @code{set processor @var{r3041}} tells @value{GDBN}
12149to use the CPU registers appropriate for the 3041 chip.
12150Use the @code{show processor} command to see what MIPS processor @value{GDBN}
12151is using. Use the @code{info reg} command to see what registers
12152@value{GDBN} is using.
104c1213 12153
8e04817f
AC
12154@item set mipsfpu double
12155@itemx set mipsfpu single
12156@itemx set mipsfpu none
12157@itemx show mipsfpu
12158@kindex set mipsfpu
12159@kindex show mipsfpu
12160@cindex MIPS remote floating point
12161@cindex floating point, MIPS remote
12162If your target board does not support the MIPS floating point
12163coprocessor, you should use the command @samp{set mipsfpu none} (if you
12164need this, you may wish to put the command in your @value{GDBN} init
12165file). This tells @value{GDBN} how to find the return value of
12166functions which return floating point values. It also allows
12167@value{GDBN} to avoid saving the floating point registers when calling
12168functions on the board. If you are using a floating point coprocessor
12169with only single precision floating point support, as on the @sc{r4650}
12170processor, use the command @samp{set mipsfpu single}. The default
12171double precision floating point coprocessor may be selected using
12172@samp{set mipsfpu double}.
104c1213 12173
8e04817f
AC
12174In previous versions the only choices were double precision or no
12175floating point, so @samp{set mipsfpu on} will select double precision
12176and @samp{set mipsfpu off} will select no floating point.
104c1213 12177
8e04817f
AC
12178As usual, you can inquire about the @code{mipsfpu} variable with
12179@samp{show mipsfpu}.
104c1213 12180
8e04817f
AC
12181@item set remotedebug @var{n}
12182@itemx show remotedebug
12183@kindex set remotedebug@r{, MIPS protocol}
12184@kindex show remotedebug@r{, MIPS protocol}
12185@cindex @code{remotedebug}, MIPS protocol
12186@cindex MIPS @code{remotedebug} protocol
12187@c FIXME! For this to be useful, you must know something about the MIPS
12188@c FIXME...protocol. Where is it described?
12189You can see some debugging information about communications with the board
12190by setting the @code{remotedebug} variable. If you set it to @code{1} using
12191@samp{set remotedebug 1}, every packet is displayed. If you set it
12192to @code{2}, every character is displayed. You can check the current value
12193at any time with the command @samp{show remotedebug}.
104c1213 12194
8e04817f
AC
12195@item set timeout @var{seconds}
12196@itemx set retransmit-timeout @var{seconds}
12197@itemx show timeout
12198@itemx show retransmit-timeout
12199@cindex @code{timeout}, MIPS protocol
12200@cindex @code{retransmit-timeout}, MIPS protocol
12201@kindex set timeout
12202@kindex show timeout
12203@kindex set retransmit-timeout
12204@kindex show retransmit-timeout
12205You can control the timeout used while waiting for a packet, in the MIPS
12206remote protocol, with the @code{set timeout @var{seconds}} command. The
12207default is 5 seconds. Similarly, you can control the timeout used while
12208waiting for an acknowledgement of a packet with the @code{set
12209retransmit-timeout @var{seconds}} command. The default is 3 seconds.
12210You can inspect both values with @code{show timeout} and @code{show
12211retransmit-timeout}. (These commands are @emph{only} available when
12212@value{GDBN} is configured for @samp{--target=mips-idt-ecoff}.)
104c1213 12213
8e04817f
AC
12214The timeout set by @code{set timeout} does not apply when @value{GDBN}
12215is waiting for your program to stop. In that case, @value{GDBN} waits
12216forever because it has no way of knowing how long the program is going
12217to run before stopping.
12218@end table
104c1213 12219
a37295f9
MM
12220@node OpenRISC 1000
12221@subsection OpenRISC 1000
12222@cindex OpenRISC 1000
12223
12224@cindex or1k boards
12225See OR1k Architecture document (@uref{www.opencores.org}) for more information
12226about platform and commands.
12227
12228@table @code
12229
12230@kindex target jtag
12231@item target jtag jtag://@var{host}:@var{port}
12232
12233Connects to remote JTAG server.
12234JTAG remote server can be either an or1ksim or JTAG server,
12235connected via parallel port to the board.
12236
12237Example: @code{target jtag jtag://localhost:9999}
12238
12239@kindex or1ksim
12240@item or1ksim @var{command}
12241If connected to @code{or1ksim} OpenRISC 1000 Architectural
12242Simulator, proprietary commands can be executed.
12243
12244@kindex info or1k spr
12245@item info or1k spr
12246Displays spr groups.
12247
12248@item info or1k spr @var{group}
12249@itemx info or1k spr @var{groupno}
12250Displays register names in selected group.
12251
12252@item info or1k spr @var{group} @var{register}
12253@itemx info or1k spr @var{register}
12254@itemx info or1k spr @var{groupno} @var{registerno}
12255@itemx info or1k spr @var{registerno}
12256Shows information about specified spr register.
12257
12258@kindex spr
12259@item spr @var{group} @var{register} @var{value}
12260@itemx spr @var{register @var{value}}
12261@itemx spr @var{groupno} @var{registerno @var{value}}
12262@itemx spr @var{registerno @var{value}}
12263Writes @var{value} to specified spr register.
12264@end table
12265
12266Some implementations of OpenRISC 1000 Architecture also have hardware trace.
12267It is very similar to @value{GDBN} trace, except it does not interfere with normal
12268program execution and is thus much faster. Hardware breakpoints/watchpoint
12269triggers can be set using:
12270@table @code
12271@item $LEA/$LDATA
12272Load effective address/data
12273@item $SEA/$SDATA
12274Store effective address/data
12275@item $AEA/$ADATA
12276Access effective address ($SEA or $LEA) or data ($SDATA/$LDATA)
12277@item $FETCH
12278Fetch data
12279@end table
12280
12281When triggered, it can capture low level data, like: @code{PC}, @code{LSEA},
12282@code{LDATA}, @code{SDATA}, @code{READSPR}, @code{WRITESPR}, @code{INSTR}.
12283
12284@code{htrace} commands:
12285@cindex OpenRISC 1000 htrace
12286@table @code
12287@kindex hwatch
12288@item hwatch @var{conditional}
12289Set hardware watchpoint on combination of Load/Store Effecive Address(es)
12290or Data. For example:
12291
12292@code{hwatch ($LEA == my_var) && ($LDATA < 50) || ($SEA == my_var) && ($SDATA >= 50)}
12293
12294@code{hwatch ($LEA == my_var) && ($LDATA < 50) || ($SEA == my_var) && ($SDATA >= 50)}
12295
12296@kindex htrace info
12297@item htrace info
12298Display information about current HW trace configuration.
12299
12300@kindex htrace trigger
12301@item htrace trigger @var{conditional}
12302Set starting criteria for HW trace.
12303
12304@kindex htrace qualifier
12305@item htrace qualifier @var{conditional}
12306Set acquisition qualifier for HW trace.
12307
12308@kindex htrace stop
12309@item htrace stop @var{conditional}
12310Set HW trace stopping criteria.
12311
12312@kindex htrace record
f153cc92 12313@item htrace record [@var{data}]*
a37295f9
MM
12314Selects the data to be recorded, when qualifier is met and HW trace was
12315triggered.
12316
12317@kindex htrace enable
12318@item htrace enable
12319@kindex htrace disable
12320@itemx htrace disable
12321Enables/disables the HW trace.
12322
12323@kindex htrace rewind
f153cc92 12324@item htrace rewind [@var{filename}]
a37295f9
MM
12325Clears currently recorded trace data.
12326
12327If filename is specified, new trace file is made and any newly collected data
12328will be written there.
12329
12330@kindex htrace print
f153cc92 12331@item htrace print [@var{start} [@var{len}]]
a37295f9
MM
12332Prints trace buffer, using current record configuration.
12333
12334@kindex htrace mode continuous
12335@item htrace mode continuous
12336Set continuous trace mode.
12337
12338@kindex htrace mode suspend
12339@item htrace mode suspend
12340Set suspend trace mode.
12341
12342@end table
12343
8e04817f
AC
12344@node PowerPC
12345@subsection PowerPC
104c1213
JM
12346
12347@table @code
104c1213 12348
8e04817f
AC
12349@kindex target dink32
12350@item target dink32 @var{dev}
12351DINK32 ROM monitor.
104c1213 12352
8e04817f
AC
12353@kindex target ppcbug
12354@item target ppcbug @var{dev}
12355@kindex target ppcbug1
12356@item target ppcbug1 @var{dev}
12357PPCBUG ROM monitor for PowerPC.
104c1213 12358
8e04817f
AC
12359@kindex target sds
12360@item target sds @var{dev}
12361SDS monitor, running on a PowerPC board (such as Motorola's ADS).
12362
12363@end table
12364
12365@node PA
12366@subsection HP PA Embedded
104c1213
JM
12367
12368@table @code
12369
8e04817f
AC
12370@kindex target op50n
12371@item target op50n @var{dev}
12372OP50N monitor, running on an OKI HPPA board.
12373
12374@kindex target w89k
12375@item target w89k @var{dev}
12376W89K monitor, running on a Winbond HPPA board.
104c1213
JM
12377
12378@end table
12379
8e04817f
AC
12380@node SH
12381@subsection Hitachi SH
104c1213
JM
12382
12383@table @code
12384
8e04817f
AC
12385@kindex target hms@r{, with Hitachi SH}
12386@item target hms @var{dev}
12387A Hitachi SH board attached via serial line to your host. Use special
12388commands @code{device} and @code{speed} to control the serial line and
12389the communications speed used.
104c1213 12390
8e04817f
AC
12391@kindex target e7000@r{, with Hitachi SH}
12392@item target e7000 @var{dev}
12393E7000 emulator for Hitachi SH.
104c1213 12394
8e04817f
AC
12395@kindex target sh3@r{, with SH}
12396@kindex target sh3e@r{, with SH}
12397@item target sh3 @var{dev}
12398@item target sh3e @var{dev}
12399Hitachi SH-3 and SH-3E target systems.
104c1213 12400
8e04817f 12401@end table
104c1213 12402
8e04817f
AC
12403@node Sparclet
12404@subsection Tsqware Sparclet
104c1213 12405
8e04817f
AC
12406@cindex Sparclet
12407
12408@value{GDBN} enables developers to debug tasks running on
12409Sparclet targets from a Unix host.
12410@value{GDBN} uses code that runs on
12411both the Unix host and on the Sparclet target. The program
12412@code{@value{GDBP}} is installed and executed on the Unix host.
104c1213 12413
8e04817f
AC
12414@table @code
12415@item remotetimeout @var{args}
12416@kindex remotetimeout
12417@value{GDBN} supports the option @code{remotetimeout}.
12418This option is set by the user, and @var{args} represents the number of
12419seconds @value{GDBN} waits for responses.
104c1213
JM
12420@end table
12421
8e04817f
AC
12422@cindex compiling, on Sparclet
12423When compiling for debugging, include the options @samp{-g} to get debug
12424information and @samp{-Ttext} to relocate the program to where you wish to
12425load it on the target. You may also want to add the options @samp{-n} or
12426@samp{-N} in order to reduce the size of the sections. Example:
104c1213 12427
474c8240 12428@smallexample
8e04817f 12429sparclet-aout-gcc prog.c -Ttext 0x12010000 -g -o prog -N
474c8240 12430@end smallexample
104c1213 12431
8e04817f 12432You can use @code{objdump} to verify that the addresses are what you intended:
104c1213 12433
474c8240 12434@smallexample
8e04817f 12435sparclet-aout-objdump --headers --syms prog
474c8240 12436@end smallexample
104c1213 12437
8e04817f
AC
12438@cindex running, on Sparclet
12439Once you have set
12440your Unix execution search path to find @value{GDBN}, you are ready to
12441run @value{GDBN}. From your Unix host, run @code{@value{GDBP}}
12442(or @code{sparclet-aout-gdb}, depending on your installation).
104c1213 12443
8e04817f
AC
12444@value{GDBN} comes up showing the prompt:
12445
474c8240 12446@smallexample
8e04817f 12447(gdbslet)
474c8240 12448@end smallexample
104c1213
JM
12449
12450@menu
8e04817f
AC
12451* Sparclet File:: Setting the file to debug
12452* Sparclet Connection:: Connecting to Sparclet
12453* Sparclet Download:: Sparclet download
12454* Sparclet Execution:: Running and debugging
104c1213
JM
12455@end menu
12456
8e04817f
AC
12457@node Sparclet File
12458@subsubsection Setting file to debug
104c1213 12459
8e04817f 12460The @value{GDBN} command @code{file} lets you choose with program to debug.
104c1213 12461
474c8240 12462@smallexample
8e04817f 12463(gdbslet) file prog
474c8240 12464@end smallexample
104c1213 12465
8e04817f
AC
12466@need 1000
12467@value{GDBN} then attempts to read the symbol table of @file{prog}.
12468@value{GDBN} locates
12469the file by searching the directories listed in the command search
12470path.
12471If the file was compiled with debug information (option "-g"), source
12472files will be searched as well.
12473@value{GDBN} locates
12474the source files by searching the directories listed in the directory search
12475path (@pxref{Environment, ,Your program's environment}).
12476If it fails
12477to find a file, it displays a message such as:
104c1213 12478
474c8240 12479@smallexample
8e04817f 12480prog: No such file or directory.
474c8240 12481@end smallexample
104c1213 12482
8e04817f
AC
12483When this happens, add the appropriate directories to the search paths with
12484the @value{GDBN} commands @code{path} and @code{dir}, and execute the
12485@code{target} command again.
104c1213 12486
8e04817f
AC
12487@node Sparclet Connection
12488@subsubsection Connecting to Sparclet
104c1213 12489
8e04817f
AC
12490The @value{GDBN} command @code{target} lets you connect to a Sparclet target.
12491To connect to a target on serial port ``@code{ttya}'', type:
104c1213 12492
474c8240 12493@smallexample
8e04817f
AC
12494(gdbslet) target sparclet /dev/ttya
12495Remote target sparclet connected to /dev/ttya
12496main () at ../prog.c:3
474c8240 12497@end smallexample
104c1213 12498
8e04817f
AC
12499@need 750
12500@value{GDBN} displays messages like these:
104c1213 12501
474c8240 12502@smallexample
8e04817f 12503Connected to ttya.
474c8240 12504@end smallexample
104c1213 12505
8e04817f
AC
12506@node Sparclet Download
12507@subsubsection Sparclet download
104c1213 12508
8e04817f
AC
12509@cindex download to Sparclet
12510Once connected to the Sparclet target,
12511you can use the @value{GDBN}
12512@code{load} command to download the file from the host to the target.
12513The file name and load offset should be given as arguments to the @code{load}
12514command.
12515Since the file format is aout, the program must be loaded to the starting
12516address. You can use @code{objdump} to find out what this value is. The load
12517offset is an offset which is added to the VMA (virtual memory address)
12518of each of the file's sections.
12519For instance, if the program
12520@file{prog} was linked to text address 0x1201000, with data at 0x12010160
12521and bss at 0x12010170, in @value{GDBN}, type:
104c1213 12522
474c8240 12523@smallexample
8e04817f
AC
12524(gdbslet) load prog 0x12010000
12525Loading section .text, size 0xdb0 vma 0x12010000
474c8240 12526@end smallexample
104c1213 12527
8e04817f
AC
12528If the code is loaded at a different address then what the program was linked
12529to, you may need to use the @code{section} and @code{add-symbol-file} commands
12530to tell @value{GDBN} where to map the symbol table.
12531
12532@node Sparclet Execution
12533@subsubsection Running and debugging
12534
12535@cindex running and debugging Sparclet programs
12536You can now begin debugging the task using @value{GDBN}'s execution control
12537commands, @code{b}, @code{step}, @code{run}, etc. See the @value{GDBN}
12538manual for the list of commands.
12539
474c8240 12540@smallexample
8e04817f
AC
12541(gdbslet) b main
12542Breakpoint 1 at 0x12010000: file prog.c, line 3.
12543(gdbslet) run
12544Starting program: prog
12545Breakpoint 1, main (argc=1, argv=0xeffff21c) at prog.c:3
125463 char *symarg = 0;
12547(gdbslet) step
125484 char *execarg = "hello!";
12549(gdbslet)
474c8240 12550@end smallexample
8e04817f
AC
12551
12552@node Sparclite
12553@subsection Fujitsu Sparclite
104c1213
JM
12554
12555@table @code
12556
8e04817f
AC
12557@kindex target sparclite
12558@item target sparclite @var{dev}
12559Fujitsu sparclite boards, used only for the purpose of loading.
12560You must use an additional command to debug the program.
12561For example: target remote @var{dev} using @value{GDBN} standard
12562remote protocol.
104c1213
JM
12563
12564@end table
12565
8e04817f
AC
12566@node ST2000
12567@subsection Tandem ST2000
104c1213 12568
8e04817f
AC
12569@value{GDBN} may be used with a Tandem ST2000 phone switch, running Tandem's
12570STDBUG protocol.
104c1213 12571
8e04817f
AC
12572To connect your ST2000 to the host system, see the manufacturer's
12573manual. Once the ST2000 is physically attached, you can run:
104c1213 12574
474c8240 12575@smallexample
8e04817f 12576target st2000 @var{dev} @var{speed}
474c8240 12577@end smallexample
104c1213 12578
8e04817f
AC
12579@noindent
12580to establish it as your debugging environment. @var{dev} is normally
12581the name of a serial device, such as @file{/dev/ttya}, connected to the
12582ST2000 via a serial line. You can instead specify @var{dev} as a TCP
12583connection (for example, to a serial line attached via a terminal
12584concentrator) using the syntax @code{@var{hostname}:@var{portnumber}}.
104c1213 12585
8e04817f
AC
12586The @code{load} and @code{attach} commands are @emph{not} defined for
12587this target; you must load your program into the ST2000 as you normally
12588would for standalone operation. @value{GDBN} reads debugging information
12589(such as symbols) from a separate, debugging version of the program
12590available on your host computer.
12591@c FIXME!! This is terribly vague; what little content is here is
12592@c basically hearsay.
104c1213 12593
8e04817f
AC
12594@cindex ST2000 auxiliary commands
12595These auxiliary @value{GDBN} commands are available to help you with the ST2000
12596environment:
104c1213 12597
8e04817f
AC
12598@table @code
12599@item st2000 @var{command}
12600@kindex st2000 @var{cmd}
12601@cindex STDBUG commands (ST2000)
12602@cindex commands to STDBUG (ST2000)
12603Send a @var{command} to the STDBUG monitor. See the manufacturer's
12604manual for available commands.
104c1213 12605
8e04817f
AC
12606@item connect
12607@cindex connect (to STDBUG)
12608Connect the controlling terminal to the STDBUG command monitor. When
12609you are done interacting with STDBUG, typing either of two character
12610sequences gets you back to the @value{GDBN} command prompt:
12611@kbd{@key{RET}~.} (Return, followed by tilde and period) or
12612@kbd{@key{RET}~@key{C-d}} (Return, followed by tilde and control-D).
104c1213
JM
12613@end table
12614
8e04817f
AC
12615@node Z8000
12616@subsection Zilog Z8000
104c1213 12617
8e04817f
AC
12618@cindex Z8000
12619@cindex simulator, Z8000
12620@cindex Zilog Z8000 simulator
104c1213 12621
8e04817f
AC
12622When configured for debugging Zilog Z8000 targets, @value{GDBN} includes
12623a Z8000 simulator.
12624
12625For the Z8000 family, @samp{target sim} simulates either the Z8002 (the
12626unsegmented variant of the Z8000 architecture) or the Z8001 (the
12627segmented variant). The simulator recognizes which architecture is
12628appropriate by inspecting the object code.
104c1213 12629
8e04817f
AC
12630@table @code
12631@item target sim @var{args}
12632@kindex sim
12633@kindex target sim@r{, with Z8000}
12634Debug programs on a simulated CPU. If the simulator supports setup
12635options, specify them via @var{args}.
104c1213
JM
12636@end table
12637
8e04817f
AC
12638@noindent
12639After specifying this target, you can debug programs for the simulated
12640CPU in the same style as programs for your host computer; use the
12641@code{file} command to load a new program image, the @code{run} command
12642to run your program, and so on.
12643
12644As well as making available all the usual machine registers
12645(@pxref{Registers, ,Registers}), the Z8000 simulator provides three
12646additional items of information as specially named registers:
104c1213
JM
12647
12648@table @code
12649
8e04817f
AC
12650@item cycles
12651Counts clock-ticks in the simulator.
104c1213 12652
8e04817f
AC
12653@item insts
12654Counts instructions run in the simulator.
104c1213 12655
8e04817f
AC
12656@item time
12657Execution time in 60ths of a second.
104c1213 12658
8e04817f 12659@end table
104c1213 12660
8e04817f
AC
12661You can refer to these values in @value{GDBN} expressions with the usual
12662conventions; for example, @w{@samp{b fputc if $cycles>5000}} sets a
12663conditional breakpoint that suspends only after at least 5000
12664simulated clock ticks.
104c1213 12665
8e04817f
AC
12666@node Architectures
12667@section Architectures
104c1213 12668
8e04817f
AC
12669This section describes characteristics of architectures that affect
12670all uses of @value{GDBN} with the architecture, both native and cross.
104c1213 12671
8e04817f
AC
12672@menu
12673* A29K::
12674* Alpha::
12675* MIPS::
12676@end menu
104c1213 12677
8e04817f
AC
12678@node A29K
12679@subsection A29K
104c1213
JM
12680
12681@table @code
104c1213 12682
8e04817f
AC
12683@kindex set rstack_high_address
12684@cindex AMD 29K register stack
12685@cindex register stack, AMD29K
12686@item set rstack_high_address @var{address}
12687On AMD 29000 family processors, registers are saved in a separate
12688@dfn{register stack}. There is no way for @value{GDBN} to determine the
12689extent of this stack. Normally, @value{GDBN} just assumes that the
12690stack is ``large enough''. This may result in @value{GDBN} referencing
12691memory locations that do not exist. If necessary, you can get around
12692this problem by specifying the ending address of the register stack with
12693the @code{set rstack_high_address} command. The argument should be an
12694address, which you probably want to precede with @samp{0x} to specify in
12695hexadecimal.
104c1213 12696
8e04817f
AC
12697@kindex show rstack_high_address
12698@item show rstack_high_address
12699Display the current limit of the register stack, on AMD 29000 family
12700processors.
104c1213 12701
8e04817f 12702@end table
104c1213 12703
8e04817f
AC
12704@node Alpha
12705@subsection Alpha
104c1213 12706
8e04817f 12707See the following section.
104c1213 12708
8e04817f
AC
12709@node MIPS
12710@subsection MIPS
104c1213 12711
8e04817f
AC
12712@cindex stack on Alpha
12713@cindex stack on MIPS
12714@cindex Alpha stack
12715@cindex MIPS stack
12716Alpha- and MIPS-based computers use an unusual stack frame, which
12717sometimes requires @value{GDBN} to search backward in the object code to
12718find the beginning of a function.
104c1213 12719
8e04817f
AC
12720@cindex response time, MIPS debugging
12721To improve response time (especially for embedded applications, where
12722@value{GDBN} may be restricted to a slow serial line for this search)
12723you may want to limit the size of this search, using one of these
12724commands:
104c1213 12725
8e04817f
AC
12726@table @code
12727@cindex @code{heuristic-fence-post} (Alpha, MIPS)
12728@item set heuristic-fence-post @var{limit}
12729Restrict @value{GDBN} to examining at most @var{limit} bytes in its
12730search for the beginning of a function. A value of @var{0} (the
12731default) means there is no limit. However, except for @var{0}, the
12732larger the limit the more bytes @code{heuristic-fence-post} must search
12733and therefore the longer it takes to run.
104c1213 12734
8e04817f
AC
12735@item show heuristic-fence-post
12736Display the current limit.
12737@end table
104c1213
JM
12738
12739@noindent
8e04817f
AC
12740These commands are available @emph{only} when @value{GDBN} is configured
12741for debugging programs on Alpha or MIPS processors.
104c1213 12742
104c1213 12743
8e04817f
AC
12744@node Controlling GDB
12745@chapter Controlling @value{GDBN}
12746
12747You can alter the way @value{GDBN} interacts with you by using the
12748@code{set} command. For commands controlling how @value{GDBN} displays
12749data, see @ref{Print Settings, ,Print settings}. Other settings are
12750described here.
12751
12752@menu
12753* Prompt:: Prompt
12754* Editing:: Command editing
12755* History:: Command history
12756* Screen Size:: Screen size
12757* Numbers:: Numbers
1e698235 12758* ABI:: Configuring the current ABI
8e04817f
AC
12759* Messages/Warnings:: Optional warnings and messages
12760* Debugging Output:: Optional messages about internal happenings
12761@end menu
12762
12763@node Prompt
12764@section Prompt
104c1213 12765
8e04817f 12766@cindex prompt
104c1213 12767
8e04817f
AC
12768@value{GDBN} indicates its readiness to read a command by printing a string
12769called the @dfn{prompt}. This string is normally @samp{(@value{GDBP})}. You
12770can change the prompt string with the @code{set prompt} command. For
12771instance, when debugging @value{GDBN} with @value{GDBN}, it is useful to change
12772the prompt in one of the @value{GDBN} sessions so that you can always tell
12773which one you are talking to.
104c1213 12774
8e04817f
AC
12775@emph{Note:} @code{set prompt} does not add a space for you after the
12776prompt you set. This allows you to set a prompt which ends in a space
12777or a prompt that does not.
104c1213 12778
8e04817f
AC
12779@table @code
12780@kindex set prompt
12781@item set prompt @var{newprompt}
12782Directs @value{GDBN} to use @var{newprompt} as its prompt string henceforth.
104c1213 12783
8e04817f
AC
12784@kindex show prompt
12785@item show prompt
12786Prints a line of the form: @samp{Gdb's prompt is: @var{your-prompt}}
104c1213
JM
12787@end table
12788
8e04817f
AC
12789@node Editing
12790@section Command editing
12791@cindex readline
12792@cindex command line editing
104c1213 12793
8e04817f
AC
12794@value{GDBN} reads its input commands via the @dfn{readline} interface. This
12795@sc{gnu} library provides consistent behavior for programs which provide a
12796command line interface to the user. Advantages are @sc{gnu} Emacs-style
12797or @dfn{vi}-style inline editing of commands, @code{csh}-like history
12798substitution, and a storage and recall of command history across
12799debugging sessions.
104c1213 12800
8e04817f
AC
12801You may control the behavior of command line editing in @value{GDBN} with the
12802command @code{set}.
104c1213 12803
8e04817f
AC
12804@table @code
12805@kindex set editing
12806@cindex editing
12807@item set editing
12808@itemx set editing on
12809Enable command line editing (enabled by default).
104c1213 12810
8e04817f
AC
12811@item set editing off
12812Disable command line editing.
104c1213 12813
8e04817f
AC
12814@kindex show editing
12815@item show editing
12816Show whether command line editing is enabled.
104c1213
JM
12817@end table
12818
8e04817f
AC
12819@node History
12820@section Command history
12821
12822@value{GDBN} can keep track of the commands you type during your
12823debugging sessions, so that you can be certain of precisely what
12824happened. Use these commands to manage the @value{GDBN} command
12825history facility.
104c1213
JM
12826
12827@table @code
8e04817f
AC
12828@cindex history substitution
12829@cindex history file
12830@kindex set history filename
12831@kindex GDBHISTFILE
12832@item set history filename @var{fname}
12833Set the name of the @value{GDBN} command history file to @var{fname}.
12834This is the file where @value{GDBN} reads an initial command history
12835list, and where it writes the command history from this session when it
12836exits. You can access this list through history expansion or through
12837the history command editing characters listed below. This file defaults
12838to the value of the environment variable @code{GDBHISTFILE}, or to
12839@file{./.gdb_history} (@file{./_gdb_history} on MS-DOS) if this variable
12840is not set.
104c1213 12841
8e04817f
AC
12842@cindex history save
12843@kindex set history save
12844@item set history save
12845@itemx set history save on
12846Record command history in a file, whose name may be specified with the
12847@code{set history filename} command. By default, this option is disabled.
104c1213 12848
8e04817f
AC
12849@item set history save off
12850Stop recording command history in a file.
104c1213 12851
8e04817f
AC
12852@cindex history size
12853@kindex set history size
12854@item set history size @var{size}
12855Set the number of commands which @value{GDBN} keeps in its history list.
12856This defaults to the value of the environment variable
12857@code{HISTSIZE}, or to 256 if this variable is not set.
104c1213
JM
12858@end table
12859
8e04817f
AC
12860@cindex history expansion
12861History expansion assigns special meaning to the character @kbd{!}.
12862@ifset have-readline-appendices
12863@xref{Event Designators}.
12864@end ifset
12865
12866Since @kbd{!} is also the logical not operator in C, history expansion
12867is off by default. If you decide to enable history expansion with the
12868@code{set history expansion on} command, you may sometimes need to
12869follow @kbd{!} (when it is used as logical not, in an expression) with
12870a space or a tab to prevent it from being expanded. The readline
12871history facilities do not attempt substitution on the strings
12872@kbd{!=} and @kbd{!(}, even when history expansion is enabled.
12873
12874The commands to control history expansion are:
104c1213
JM
12875
12876@table @code
8e04817f
AC
12877@kindex set history expansion
12878@item set history expansion on
12879@itemx set history expansion
12880Enable history expansion. History expansion is off by default.
104c1213 12881
8e04817f
AC
12882@item set history expansion off
12883Disable history expansion.
104c1213 12884
8e04817f
AC
12885The readline code comes with more complete documentation of
12886editing and history expansion features. Users unfamiliar with @sc{gnu} Emacs
12887or @code{vi} may wish to read it.
12888@ifset have-readline-appendices
12889@xref{Command Line Editing}.
12890@end ifset
104c1213 12891
8e04817f
AC
12892@c @group
12893@kindex show history
12894@item show history
12895@itemx show history filename
12896@itemx show history save
12897@itemx show history size
12898@itemx show history expansion
12899These commands display the state of the @value{GDBN} history parameters.
12900@code{show history} by itself displays all four states.
12901@c @end group
12902@end table
12903
12904@table @code
12905@kindex shows
12906@item show commands
12907Display the last ten commands in the command history.
104c1213 12908
8e04817f
AC
12909@item show commands @var{n}
12910Print ten commands centered on command number @var{n}.
12911
12912@item show commands +
12913Print ten commands just after the commands last printed.
104c1213
JM
12914@end table
12915
8e04817f
AC
12916@node Screen Size
12917@section Screen size
12918@cindex size of screen
12919@cindex pauses in output
104c1213 12920
8e04817f
AC
12921Certain commands to @value{GDBN} may produce large amounts of
12922information output to the screen. To help you read all of it,
12923@value{GDBN} pauses and asks you for input at the end of each page of
12924output. Type @key{RET} when you want to continue the output, or @kbd{q}
12925to discard the remaining output. Also, the screen width setting
12926determines when to wrap lines of output. Depending on what is being
12927printed, @value{GDBN} tries to break the line at a readable place,
12928rather than simply letting it overflow onto the following line.
12929
12930Normally @value{GDBN} knows the size of the screen from the terminal
12931driver software. For example, on Unix @value{GDBN} uses the termcap data base
12932together with the value of the @code{TERM} environment variable and the
12933@code{stty rows} and @code{stty cols} settings. If this is not correct,
12934you can override it with the @code{set height} and @code{set
12935width} commands:
12936
12937@table @code
12938@kindex set height
12939@kindex set width
12940@kindex show width
12941@kindex show height
12942@item set height @var{lpp}
12943@itemx show height
12944@itemx set width @var{cpl}
12945@itemx show width
12946These @code{set} commands specify a screen height of @var{lpp} lines and
12947a screen width of @var{cpl} characters. The associated @code{show}
12948commands display the current settings.
104c1213 12949
8e04817f
AC
12950If you specify a height of zero lines, @value{GDBN} does not pause during
12951output no matter how long the output is. This is useful if output is to a
12952file or to an editor buffer.
104c1213 12953
8e04817f
AC
12954Likewise, you can specify @samp{set width 0} to prevent @value{GDBN}
12955from wrapping its output.
104c1213
JM
12956@end table
12957
8e04817f
AC
12958@node Numbers
12959@section Numbers
12960@cindex number representation
12961@cindex entering numbers
104c1213 12962
8e04817f
AC
12963You can always enter numbers in octal, decimal, or hexadecimal in
12964@value{GDBN} by the usual conventions: octal numbers begin with
12965@samp{0}, decimal numbers end with @samp{.}, and hexadecimal numbers
12966begin with @samp{0x}. Numbers that begin with none of these are, by
12967default, entered in base 10; likewise, the default display for
12968numbers---when no particular format is specified---is base 10. You can
12969change the default base for both input and output with the @code{set
12970radix} command.
104c1213 12971
8e04817f
AC
12972@table @code
12973@kindex set input-radix
12974@item set input-radix @var{base}
12975Set the default base for numeric input. Supported choices
12976for @var{base} are decimal 8, 10, or 16. @var{base} must itself be
12977specified either unambiguously or using the current default radix; for
12978example, any of
104c1213 12979
8e04817f
AC
12980@smallexample
12981set radix 012
12982set radix 10.
12983set radix 0xa
12984@end smallexample
104c1213 12985
8e04817f
AC
12986@noindent
12987sets the base to decimal. On the other hand, @samp{set radix 10}
12988leaves the radix unchanged no matter what it was.
104c1213 12989
8e04817f
AC
12990@kindex set output-radix
12991@item set output-radix @var{base}
12992Set the default base for numeric display. Supported choices
12993for @var{base} are decimal 8, 10, or 16. @var{base} must itself be
12994specified either unambiguously or using the current default radix.
104c1213 12995
8e04817f
AC
12996@kindex show input-radix
12997@item show input-radix
12998Display the current default base for numeric input.
104c1213 12999
8e04817f
AC
13000@kindex show output-radix
13001@item show output-radix
13002Display the current default base for numeric display.
13003@end table
104c1213 13004
1e698235
DJ
13005@node ABI
13006@section Configuring the current ABI
13007
13008@value{GDBN} can determine the @dfn{ABI} (Application Binary Interface) of your
13009application automatically. However, sometimes you need to override its
13010conclusions. Use these commands to manage @value{GDBN}'s view of the
13011current ABI.
13012
98b45e30
DJ
13013@cindex OS ABI
13014@kindex set osabi
b4e9345d 13015@kindex show osabi
98b45e30
DJ
13016
13017One @value{GDBN} configuration can debug binaries for multiple operating
13018system targets, either via remote debugging or native emulation.
13019@value{GDBN} will autodetect the @dfn{OS ABI} (Operating System ABI) in use,
13020but you can override its conclusion using the @code{set osabi} command.
13021One example where this is useful is in debugging of binaries which use
13022an alternate C library (e.g.@: @sc{uClibc} for @sc{gnu}/Linux) which does
13023not have the same identifying marks that the standard C library for your
13024platform provides.
13025
13026@table @code
13027@item show osabi
13028Show the OS ABI currently in use.
13029
13030@item set osabi
13031With no argument, show the list of registered available OS ABI's.
13032
13033@item set osabi @var{abi}
13034Set the current OS ABI to @var{abi}.
13035@end table
13036
1e698235
DJ
13037@cindex float promotion
13038@kindex set coerce-float-to-double
13039
13040Generally, the way that an argument of type @code{float} is passed to a
13041function depends on whether the function is prototyped. For a prototyped
13042(i.e.@: ANSI/ISO style) function, @code{float} arguments are passed unchanged,
13043according to the architecture's convention for @code{float}. For unprototyped
13044(i.e.@: K&R style) functions, @code{float} arguments are first promoted to type
13045@code{double} and then passed.
13046
13047Unfortunately, some forms of debug information do not reliably indicate whether
13048a function is prototyped. If @value{GDBN} calls a function that is not marked
13049as prototyped, it consults @kbd{set coerce-float-to-double}.
13050
13051@table @code
13052@item set coerce-float-to-double
13053@itemx set coerce-float-to-double on
13054Arguments of type @code{float} will be promoted to @code{double} when passed
13055to an unprototyped function. This is the default setting.
13056
13057@item set coerce-float-to-double off
13058Arguments of type @code{float} will be passed directly to unprototyped
13059functions.
13060@end table
13061
f1212245
DJ
13062@kindex set cp-abi
13063@kindex show cp-abi
13064@value{GDBN} needs to know the ABI used for your program's C@t{++}
13065objects. The correct C@t{++} ABI depends on which C@t{++} compiler was
13066used to build your application. @value{GDBN} only fully supports
13067programs with a single C@t{++} ABI; if your program contains code using
13068multiple C@t{++} ABI's or if @value{GDBN} can not identify your
13069program's ABI correctly, you can tell @value{GDBN} which ABI to use.
13070Currently supported ABI's include ``gnu-v2'', for @code{g++} versions
13071before 3.0, ``gnu-v3'', for @code{g++} versions 3.0 and later, and
13072``hpaCC'' for the HP ANSI C@t{++} compiler. Other C@t{++} compilers may
13073use the ``gnu-v2'' or ``gnu-v3'' ABI's as well. The default setting is
13074``auto''.
13075
13076@table @code
13077@item show cp-abi
13078Show the C@t{++} ABI currently in use.
13079
13080@item set cp-abi
13081With no argument, show the list of supported C@t{++} ABI's.
13082
13083@item set cp-abi @var{abi}
13084@itemx set cp-abi auto
13085Set the current C@t{++} ABI to @var{abi}, or return to automatic detection.
13086@end table
13087
8e04817f
AC
13088@node Messages/Warnings
13089@section Optional warnings and messages
104c1213 13090
8e04817f
AC
13091By default, @value{GDBN} is silent about its inner workings. If you are
13092running on a slow machine, you may want to use the @code{set verbose}
13093command. This makes @value{GDBN} tell you when it does a lengthy
13094internal operation, so you will not think it has crashed.
104c1213 13095
8e04817f
AC
13096Currently, the messages controlled by @code{set verbose} are those
13097which announce that the symbol table for a source file is being read;
13098see @code{symbol-file} in @ref{Files, ,Commands to specify files}.
104c1213 13099
8e04817f
AC
13100@table @code
13101@kindex set verbose
13102@item set verbose on
13103Enables @value{GDBN} output of certain informational messages.
104c1213 13104
8e04817f
AC
13105@item set verbose off
13106Disables @value{GDBN} output of certain informational messages.
104c1213 13107
8e04817f
AC
13108@kindex show verbose
13109@item show verbose
13110Displays whether @code{set verbose} is on or off.
13111@end table
104c1213 13112
8e04817f
AC
13113By default, if @value{GDBN} encounters bugs in the symbol table of an
13114object file, it is silent; but if you are debugging a compiler, you may
13115find this information useful (@pxref{Symbol Errors, ,Errors reading
13116symbol files}).
104c1213 13117
8e04817f 13118@table @code
104c1213 13119
8e04817f
AC
13120@kindex set complaints
13121@item set complaints @var{limit}
13122Permits @value{GDBN} to output @var{limit} complaints about each type of
13123unusual symbols before becoming silent about the problem. Set
13124@var{limit} to zero to suppress all complaints; set it to a large number
13125to prevent complaints from being suppressed.
104c1213 13126
8e04817f
AC
13127@kindex show complaints
13128@item show complaints
13129Displays how many symbol complaints @value{GDBN} is permitted to produce.
104c1213 13130
8e04817f 13131@end table
104c1213 13132
8e04817f
AC
13133By default, @value{GDBN} is cautious, and asks what sometimes seems to be a
13134lot of stupid questions to confirm certain commands. For example, if
13135you try to run a program which is already running:
104c1213 13136
474c8240 13137@smallexample
8e04817f
AC
13138(@value{GDBP}) run
13139The program being debugged has been started already.
13140Start it from the beginning? (y or n)
474c8240 13141@end smallexample
104c1213 13142
8e04817f
AC
13143If you are willing to unflinchingly face the consequences of your own
13144commands, you can disable this ``feature'':
104c1213 13145
8e04817f 13146@table @code
104c1213 13147
8e04817f
AC
13148@kindex set confirm
13149@cindex flinching
13150@cindex confirmation
13151@cindex stupid questions
13152@item set confirm off
13153Disables confirmation requests.
104c1213 13154
8e04817f
AC
13155@item set confirm on
13156Enables confirmation requests (the default).
104c1213 13157
8e04817f
AC
13158@kindex show confirm
13159@item show confirm
13160Displays state of confirmation requests.
13161
13162@end table
104c1213 13163
8e04817f
AC
13164@node Debugging Output
13165@section Optional messages about internal happenings
104c1213 13166@table @code
8e04817f
AC
13167@kindex set debug arch
13168@item set debug arch
13169Turns on or off display of gdbarch debugging info. The default is off
13170@kindex show debug arch
13171@item show debug arch
13172Displays the current state of displaying gdbarch debugging info.
13173@kindex set debug event
13174@item set debug event
13175Turns on or off display of @value{GDBN} event debugging info. The
13176default is off.
13177@kindex show debug event
13178@item show debug event
13179Displays the current state of displaying @value{GDBN} event debugging
13180info.
13181@kindex set debug expression
13182@item set debug expression
13183Turns on or off display of @value{GDBN} expression debugging info. The
13184default is off.
13185@kindex show debug expression
13186@item show debug expression
13187Displays the current state of displaying @value{GDBN} expression
13188debugging info.
7453dc06
AC
13189@kindex set debug frame
13190@item set debug frame
13191Turns on or off display of @value{GDBN} frame debugging info. The
13192default is off.
13193@kindex show debug frame
13194@item show debug frame
13195Displays the current state of displaying @value{GDBN} frame debugging
13196info.
8e04817f
AC
13197@kindex set debug overload
13198@item set debug overload
13199Turns on or off display of @value{GDBN} C@t{++} overload debugging
13200info. This includes info such as ranking of functions, etc. The default
13201is off.
13202@kindex show debug overload
13203@item show debug overload
13204Displays the current state of displaying @value{GDBN} C@t{++} overload
13205debugging info.
13206@kindex set debug remote
13207@cindex packets, reporting on stdout
13208@cindex serial connections, debugging
13209@item set debug remote
13210Turns on or off display of reports on all packets sent back and forth across
13211the serial line to the remote machine. The info is printed on the
13212@value{GDBN} standard output stream. The default is off.
13213@kindex show debug remote
13214@item show debug remote
13215Displays the state of display of remote packets.
13216@kindex set debug serial
13217@item set debug serial
13218Turns on or off display of @value{GDBN} serial debugging info. The
13219default is off.
13220@kindex show debug serial
13221@item show debug serial
13222Displays the current state of displaying @value{GDBN} serial debugging
13223info.
13224@kindex set debug target
13225@item set debug target
13226Turns on or off display of @value{GDBN} target debugging info. This info
13227includes what is going on at the target level of GDB, as it happens. The
13228default is off.
13229@kindex show debug target
13230@item show debug target
13231Displays the current state of displaying @value{GDBN} target debugging
13232info.
13233@kindex set debug varobj
13234@item set debug varobj
13235Turns on or off display of @value{GDBN} variable object debugging
13236info. The default is off.
13237@kindex show debug varobj
13238@item show debug varobj
13239Displays the current state of displaying @value{GDBN} variable object
13240debugging info.
13241@end table
104c1213 13242
8e04817f
AC
13243@node Sequences
13244@chapter Canned Sequences of Commands
104c1213 13245
8e04817f
AC
13246Aside from breakpoint commands (@pxref{Break Commands, ,Breakpoint
13247command lists}), @value{GDBN} provides two ways to store sequences of
13248commands for execution as a unit: user-defined commands and command
13249files.
104c1213 13250
8e04817f
AC
13251@menu
13252* Define:: User-defined commands
13253* Hooks:: User-defined command hooks
13254* Command Files:: Command files
13255* Output:: Commands for controlled output
13256@end menu
104c1213 13257
8e04817f
AC
13258@node Define
13259@section User-defined commands
104c1213 13260
8e04817f
AC
13261@cindex user-defined command
13262A @dfn{user-defined command} is a sequence of @value{GDBN} commands to
13263which you assign a new name as a command. This is done with the
13264@code{define} command. User commands may accept up to 10 arguments
13265separated by whitespace. Arguments are accessed within the user command
13266via @var{$arg0@dots{}$arg9}. A trivial example:
104c1213 13267
8e04817f
AC
13268@smallexample
13269define adder
13270 print $arg0 + $arg1 + $arg2
13271@end smallexample
104c1213
JM
13272
13273@noindent
8e04817f 13274To execute the command use:
104c1213 13275
8e04817f
AC
13276@smallexample
13277adder 1 2 3
13278@end smallexample
104c1213 13279
8e04817f
AC
13280@noindent
13281This defines the command @code{adder}, which prints the sum of
13282its three arguments. Note the arguments are text substitutions, so they may
13283reference variables, use complex expressions, or even perform inferior
13284functions calls.
104c1213
JM
13285
13286@table @code
104c1213 13287
8e04817f
AC
13288@kindex define
13289@item define @var{commandname}
13290Define a command named @var{commandname}. If there is already a command
13291by that name, you are asked to confirm that you want to redefine it.
104c1213 13292
8e04817f
AC
13293The definition of the command is made up of other @value{GDBN} command lines,
13294which are given following the @code{define} command. The end of these
13295commands is marked by a line containing @code{end}.
104c1213 13296
8e04817f
AC
13297@kindex if
13298@kindex else
13299@item if
13300Takes a single argument, which is an expression to evaluate.
13301It is followed by a series of commands that are executed
13302only if the expression is true (nonzero).
13303There can then optionally be a line @code{else}, followed
13304by a series of commands that are only executed if the expression
13305was false. The end of the list is marked by a line containing @code{end}.
104c1213 13306
8e04817f
AC
13307@kindex while
13308@item while
13309The syntax is similar to @code{if}: the command takes a single argument,
13310which is an expression to evaluate, and must be followed by the commands to
13311execute, one per line, terminated by an @code{end}.
13312The commands are executed repeatedly as long as the expression
13313evaluates to true.
104c1213 13314
8e04817f
AC
13315@kindex document
13316@item document @var{commandname}
13317Document the user-defined command @var{commandname}, so that it can be
13318accessed by @code{help}. The command @var{commandname} must already be
13319defined. This command reads lines of documentation just as @code{define}
13320reads the lines of the command definition, ending with @code{end}.
13321After the @code{document} command is finished, @code{help} on command
13322@var{commandname} displays the documentation you have written.
104c1213 13323
8e04817f
AC
13324You may use the @code{document} command again to change the
13325documentation of a command. Redefining the command with @code{define}
13326does not change the documentation.
104c1213 13327
8e04817f
AC
13328@kindex help user-defined
13329@item help user-defined
13330List all user-defined commands, with the first line of the documentation
13331(if any) for each.
104c1213 13332
8e04817f
AC
13333@kindex show user
13334@item show user
13335@itemx show user @var{commandname}
13336Display the @value{GDBN} commands used to define @var{commandname} (but
13337not its documentation). If no @var{commandname} is given, display the
13338definitions for all user-defined commands.
104c1213 13339
20f01a46
DH
13340@kindex show max-user-call-depth
13341@kindex set max-user-call-depth
13342@item show max-user-call-depth
5ca0cb28
DH
13343@itemx set max-user-call-depth
13344The value of @code{max-user-call-depth} controls how many recursion
13345levels are allowed in user-defined commands before GDB suspects an
13346infinite recursion and aborts the command.
20f01a46 13347
104c1213
JM
13348@end table
13349
8e04817f
AC
13350When user-defined commands are executed, the
13351commands of the definition are not printed. An error in any command
13352stops execution of the user-defined command.
104c1213 13353
8e04817f
AC
13354If used interactively, commands that would ask for confirmation proceed
13355without asking when used inside a user-defined command. Many @value{GDBN}
13356commands that normally print messages to say what they are doing omit the
13357messages when used in a user-defined command.
104c1213 13358
8e04817f
AC
13359@node Hooks
13360@section User-defined command hooks
13361@cindex command hooks
13362@cindex hooks, for commands
13363@cindex hooks, pre-command
104c1213 13364
8e04817f
AC
13365@kindex hook
13366@kindex hook-
13367You may define @dfn{hooks}, which are a special kind of user-defined
13368command. Whenever you run the command @samp{foo}, if the user-defined
13369command @samp{hook-foo} exists, it is executed (with no arguments)
13370before that command.
104c1213 13371
8e04817f
AC
13372@cindex hooks, post-command
13373@kindex hookpost
13374@kindex hookpost-
13375A hook may also be defined which is run after the command you executed.
13376Whenever you run the command @samp{foo}, if the user-defined command
13377@samp{hookpost-foo} exists, it is executed (with no arguments) after
13378that command. Post-execution hooks may exist simultaneously with
13379pre-execution hooks, for the same command.
104c1213 13380
8e04817f
AC
13381It is valid for a hook to call the command which it hooks. If this
13382occurs, the hook is not re-executed, thereby avoiding infinte recursion.
104c1213 13383
8e04817f
AC
13384@c It would be nice if hookpost could be passed a parameter indicating
13385@c if the command it hooks executed properly or not. FIXME!
104c1213 13386
8e04817f
AC
13387@kindex stop@r{, a pseudo-command}
13388In addition, a pseudo-command, @samp{stop} exists. Defining
13389(@samp{hook-stop}) makes the associated commands execute every time
13390execution stops in your program: before breakpoint commands are run,
13391displays are printed, or the stack frame is printed.
104c1213 13392
8e04817f
AC
13393For example, to ignore @code{SIGALRM} signals while
13394single-stepping, but treat them normally during normal execution,
13395you could define:
104c1213 13396
474c8240 13397@smallexample
8e04817f
AC
13398define hook-stop
13399handle SIGALRM nopass
13400end
104c1213 13401
8e04817f
AC
13402define hook-run
13403handle SIGALRM pass
13404end
104c1213 13405
8e04817f
AC
13406define hook-continue
13407handle SIGLARM pass
13408end
474c8240 13409@end smallexample
104c1213 13410
8e04817f
AC
13411As a further example, to hook at the begining and end of the @code{echo}
13412command, and to add extra text to the beginning and end of the message,
13413you could define:
104c1213 13414
474c8240 13415@smallexample
8e04817f
AC
13416define hook-echo
13417echo <<<---
13418end
104c1213 13419
8e04817f
AC
13420define hookpost-echo
13421echo --->>>\n
13422end
104c1213 13423
8e04817f
AC
13424(@value{GDBP}) echo Hello World
13425<<<---Hello World--->>>
13426(@value{GDBP})
104c1213 13427
474c8240 13428@end smallexample
104c1213 13429
8e04817f
AC
13430You can define a hook for any single-word command in @value{GDBN}, but
13431not for command aliases; you should define a hook for the basic command
13432name, e.g. @code{backtrace} rather than @code{bt}.
13433@c FIXME! So how does Joe User discover whether a command is an alias
13434@c or not?
13435If an error occurs during the execution of your hook, execution of
13436@value{GDBN} commands stops and @value{GDBN} issues a prompt
13437(before the command that you actually typed had a chance to run).
104c1213 13438
8e04817f
AC
13439If you try to define a hook which does not match any known command, you
13440get a warning from the @code{define} command.
c906108c 13441
8e04817f
AC
13442@node Command Files
13443@section Command files
c906108c 13444
8e04817f
AC
13445@cindex command files
13446A command file for @value{GDBN} is a file of lines that are @value{GDBN}
13447commands. Comments (lines starting with @kbd{#}) may also be included.
13448An empty line in a command file does nothing; it does not mean to repeat
13449the last command, as it would from the terminal.
c906108c 13450
8e04817f
AC
13451@cindex init file
13452@cindex @file{.gdbinit}
13453@cindex @file{gdb.ini}
13454When you start @value{GDBN}, it automatically executes commands from its
13455@dfn{init files}, normally called @file{.gdbinit}@footnote{The DJGPP
13456port of @value{GDBN} uses the name @file{gdb.ini} instead, due to the
13457limitations of file names imposed by DOS filesystems.}.
13458During startup, @value{GDBN} does the following:
c906108c 13459
8e04817f
AC
13460@enumerate
13461@item
13462Reads the init file (if any) in your home directory@footnote{On
13463DOS/Windows systems, the home directory is the one pointed to by the
13464@code{HOME} environment variable.}.
c906108c 13465
8e04817f
AC
13466@item
13467Processes command line options and operands.
c906108c 13468
8e04817f
AC
13469@item
13470Reads the init file (if any) in the current working directory.
c906108c 13471
8e04817f
AC
13472@item
13473Reads command files specified by the @samp{-x} option.
13474@end enumerate
c906108c 13475
8e04817f
AC
13476The init file in your home directory can set options (such as @samp{set
13477complaints}) that affect subsequent processing of command line options
13478and operands. Init files are not executed if you use the @samp{-nx}
13479option (@pxref{Mode Options, ,Choosing modes}).
c906108c 13480
8e04817f
AC
13481@cindex init file name
13482On some configurations of @value{GDBN}, the init file is known by a
13483different name (these are typically environments where a specialized
13484form of @value{GDBN} may need to coexist with other forms, hence a
13485different name for the specialized version's init file). These are the
13486environments with special init file names:
c906108c 13487
8e04817f
AC
13488@cindex @file{.vxgdbinit}
13489@itemize @bullet
13490@item
13491VxWorks (Wind River Systems real-time OS): @file{.vxgdbinit}
c906108c 13492
8e04817f
AC
13493@cindex @file{.os68gdbinit}
13494@item
13495OS68K (Enea Data Systems real-time OS): @file{.os68gdbinit}
c906108c 13496
8e04817f
AC
13497@cindex @file{.esgdbinit}
13498@item
13499ES-1800 (Ericsson Telecom AB M68000 emulator): @file{.esgdbinit}
13500@end itemize
c906108c 13501
8e04817f
AC
13502You can also request the execution of a command file with the
13503@code{source} command:
c906108c 13504
8e04817f
AC
13505@table @code
13506@kindex source
13507@item source @var{filename}
13508Execute the command file @var{filename}.
c906108c
SS
13509@end table
13510
8e04817f 13511The lines in a command file are executed sequentially. They are not
a71ec265
DH
13512printed as they are executed. An error in any command terminates
13513execution of the command file and control is returned to the console.
c906108c 13514
8e04817f
AC
13515Commands that would ask for confirmation if used interactively proceed
13516without asking when used in a command file. Many @value{GDBN} commands that
13517normally print messages to say what they are doing omit the messages
13518when called from command files.
c906108c 13519
8e04817f
AC
13520@value{GDBN} also accepts command input from standard input. In this
13521mode, normal output goes to standard output and error output goes to
13522standard error. Errors in a command file supplied on standard input do
13523not terminate execution of the command file --- execution continues with
13524the next command.
c906108c 13525
474c8240 13526@smallexample
8e04817f 13527gdb < cmds > log 2>&1
474c8240 13528@end smallexample
c906108c 13529
8e04817f
AC
13530(The syntax above will vary depending on the shell used.) This example
13531will execute commands from the file @file{cmds}. All output and errors
13532would be directed to @file{log}.
c906108c 13533
8e04817f
AC
13534@node Output
13535@section Commands for controlled output
c906108c 13536
8e04817f
AC
13537During the execution of a command file or a user-defined command, normal
13538@value{GDBN} output is suppressed; the only output that appears is what is
13539explicitly printed by the commands in the definition. This section
13540describes three commands useful for generating exactly the output you
13541want.
c906108c
SS
13542
13543@table @code
8e04817f
AC
13544@kindex echo
13545@item echo @var{text}
13546@c I do not consider backslash-space a standard C escape sequence
13547@c because it is not in ANSI.
13548Print @var{text}. Nonprinting characters can be included in
13549@var{text} using C escape sequences, such as @samp{\n} to print a
13550newline. @strong{No newline is printed unless you specify one.}
13551In addition to the standard C escape sequences, a backslash followed
13552by a space stands for a space. This is useful for displaying a
13553string with spaces at the beginning or the end, since leading and
13554trailing spaces are otherwise trimmed from all arguments.
13555To print @samp{@w{ }and foo =@w{ }}, use the command
13556@samp{echo \@w{ }and foo = \@w{ }}.
c906108c 13557
8e04817f
AC
13558A backslash at the end of @var{text} can be used, as in C, to continue
13559the command onto subsequent lines. For example,
c906108c 13560
474c8240 13561@smallexample
8e04817f
AC
13562echo This is some text\n\
13563which is continued\n\
13564onto several lines.\n
474c8240 13565@end smallexample
c906108c 13566
8e04817f 13567produces the same output as
c906108c 13568
474c8240 13569@smallexample
8e04817f
AC
13570echo This is some text\n
13571echo which is continued\n
13572echo onto several lines.\n
474c8240 13573@end smallexample
c906108c 13574
8e04817f
AC
13575@kindex output
13576@item output @var{expression}
13577Print the value of @var{expression} and nothing but that value: no
13578newlines, no @samp{$@var{nn} = }. The value is not entered in the
13579value history either. @xref{Expressions, ,Expressions}, for more information
13580on expressions.
c906108c 13581
8e04817f
AC
13582@item output/@var{fmt} @var{expression}
13583Print the value of @var{expression} in format @var{fmt}. You can use
13584the same formats as for @code{print}. @xref{Output Formats,,Output
13585formats}, for more information.
c906108c 13586
8e04817f
AC
13587@kindex printf
13588@item printf @var{string}, @var{expressions}@dots{}
13589Print the values of the @var{expressions} under the control of
13590@var{string}. The @var{expressions} are separated by commas and may be
13591either numbers or pointers. Their values are printed as specified by
13592@var{string}, exactly as if your program were to execute the C
13593subroutine
13594@c FIXME: the above implies that at least all ANSI C formats are
13595@c supported, but it isn't true: %E and %G don't work (or so it seems).
13596@c Either this is a bug, or the manual should document what formats are
13597@c supported.
c906108c 13598
474c8240 13599@smallexample
8e04817f 13600printf (@var{string}, @var{expressions}@dots{});
474c8240 13601@end smallexample
c906108c 13602
8e04817f 13603For example, you can print two values in hex like this:
c906108c 13604
8e04817f
AC
13605@smallexample
13606printf "foo, bar-foo = 0x%x, 0x%x\n", foo, bar-foo
13607@end smallexample
c906108c 13608
8e04817f
AC
13609The only backslash-escape sequences that you can use in the format
13610string are the simple ones that consist of backslash followed by a
13611letter.
c906108c
SS
13612@end table
13613
21c294e6
AC
13614@node Interpreters
13615@chapter Command Interpreters
13616@cindex command interpreters
13617
13618@value{GDBN} supports multiple command interpreters, and some command
13619infrastructure to allow users or user interface writers to switch
13620between interpreters or run commands in other interpreters.
13621
13622@value{GDBN} currently supports two command interpreters, the console
13623interpreter (sometimes called the command-line interpreter or @sc{cli})
13624and the machine interface interpreter (or @sc{gdb/mi}). This manual
13625describes both of these interfaces in great detail.
13626
13627By default, @value{GDBN} will start with the console interpreter.
13628However, the user may choose to start @value{GDBN} with another
13629interpreter by specifying the @option{-i} or @option{--interpreter}
13630startup options. Defined interpreters include:
13631
13632@table @code
13633@item console
13634@cindex console interpreter
13635The traditional console or command-line interpreter. This is the most often
13636used interpreter with @value{GDBN}. With no interpreter specified at runtime,
13637@value{GDBN} will use this interpreter.
13638
13639@item mi
13640@cindex mi interpreter
13641The newest @sc{gdb/mi} interface (currently @code{mi2}). Used primarily
13642by programs wishing to use @value{GDBN} as a backend for a debugger GUI
13643or an IDE. For more information, see @ref{GDB/MI, ,The @sc{gdb/mi}
13644Interface}.
13645
13646@item mi2
13647@cindex mi2 interpreter
13648The current @sc{gdb/mi} interface.
13649
13650@item mi1
13651@cindex mi1 interpreter
13652The @sc{gdb/mi} interface included in @value{GDBN} 5.1, 5.2, and 5.3.
13653
13654@end table
13655
13656@cindex invoke another interpreter
13657The interpreter being used by @value{GDBN} may not be dynamically
13658switched at runtime. Although possible, this could lead to a very
13659precarious situation. Consider an IDE using @sc{gdb/mi}. If a user
13660enters the command "interpreter-set console" in a console view,
13661@value{GDBN} would switch to using the console interpreter, rendering
13662the IDE inoperable!
13663
13664@kindex interpreter-exec
13665Although you may only choose a single interpreter at startup, you may execute
13666commands in any interpreter from the current interpreter using the appropriate
13667command. If you are running the console interpreter, simply use the
13668@code{interpreter-exec} command:
13669
13670@smallexample
13671interpreter-exec mi "-data-list-register-names"
13672@end smallexample
13673
13674@sc{gdb/mi} has a similar command, although it is only available in versions of
13675@value{GDBN} which support @sc{gdb/mi} version 2 (or greater).
13676
8e04817f
AC
13677@node TUI
13678@chapter @value{GDBN} Text User Interface
13679@cindex TUI
c906108c 13680
8e04817f
AC
13681@menu
13682* TUI Overview:: TUI overview
13683* TUI Keys:: TUI key bindings
7cf36c78 13684* TUI Single Key Mode:: TUI single key mode
8e04817f
AC
13685* TUI Commands:: TUI specific commands
13686* TUI Configuration:: TUI configuration variables
13687@end menu
c906108c 13688
8e04817f
AC
13689The @value{GDBN} Text User Interface, TUI in short,
13690is a terminal interface which uses the @code{curses} library
13691to show the source file, the assembly output, the program registers
13692and @value{GDBN} commands in separate text windows.
13693The TUI is available only when @value{GDBN} is configured
13694with the @code{--enable-tui} configure option (@pxref{Configure Options}).
c906108c 13695
8e04817f
AC
13696@node TUI Overview
13697@section TUI overview
c906108c 13698
8e04817f
AC
13699The TUI has two display modes that can be switched while
13700@value{GDBN} runs:
c906108c 13701
8e04817f
AC
13702@itemize @bullet
13703@item
13704A curses (or TUI) mode in which it displays several text
13705windows on the terminal.
c906108c 13706
8e04817f
AC
13707@item
13708A standard mode which corresponds to the @value{GDBN} configured without
13709the TUI.
13710@end itemize
c906108c 13711
8e04817f
AC
13712In the TUI mode, @value{GDBN} can display several text window
13713on the terminal:
c906108c 13714
8e04817f
AC
13715@table @emph
13716@item command
13717This window is the @value{GDBN} command window with the @value{GDBN}
13718prompt and the @value{GDBN} outputs. The @value{GDBN} input is still
13719managed using readline but through the TUI. The @emph{command}
13720window is always visible.
c906108c 13721
8e04817f
AC
13722@item source
13723The source window shows the source file of the program. The current
13724line as well as active breakpoints are displayed in this window.
c906108c 13725
8e04817f
AC
13726@item assembly
13727The assembly window shows the disassembly output of the program.
c906108c 13728
8e04817f
AC
13729@item register
13730This window shows the processor registers. It detects when
13731a register is changed and when this is the case, registers that have
13732changed are highlighted.
c906108c 13733
c906108c
SS
13734@end table
13735
269c21fe
SC
13736The source and assembly windows show the current program position
13737by highlighting the current line and marking them with the @samp{>} marker.
13738Breakpoints are also indicated with two markers. A first one
13739indicates the breakpoint type:
13740
13741@table @code
13742@item B
13743Breakpoint which was hit at least once.
13744
13745@item b
13746Breakpoint which was never hit.
13747
13748@item H
13749Hardware breakpoint which was hit at least once.
13750
13751@item h
13752Hardware breakpoint which was never hit.
13753
13754@end table
13755
13756The second marker indicates whether the breakpoint is enabled or not:
13757
13758@table @code
13759@item +
13760Breakpoint is enabled.
13761
13762@item -
13763Breakpoint is disabled.
13764
13765@end table
13766
8e04817f
AC
13767The source, assembly and register windows are attached to the thread
13768and the frame position. They are updated when the current thread
13769changes, when the frame changes or when the program counter changes.
13770These three windows are arranged by the TUI according to several
13771layouts. The layout defines which of these three windows are visible.
13772The following layouts are available:
c906108c 13773
8e04817f
AC
13774@itemize @bullet
13775@item
13776source
2df3850c 13777
8e04817f
AC
13778@item
13779assembly
13780
13781@item
13782source and assembly
13783
13784@item
13785source and registers
c906108c 13786
8e04817f
AC
13787@item
13788assembly and registers
2df3850c 13789
8e04817f 13790@end itemize
c906108c 13791
b7bb15bc
SC
13792On top of the command window a status line gives various information
13793concerning the current process begin debugged. The status line is
13794updated when the information it shows changes. The following fields
13795are displayed:
13796
13797@table @emph
13798@item target
13799Indicates the current gdb target
13800(@pxref{Targets, ,Specifying a Debugging Target}).
13801
13802@item process
13803Gives information about the current process or thread number.
13804When no process is being debugged, this field is set to @code{No process}.
13805
13806@item function
13807Gives the current function name for the selected frame.
13808The name is demangled if demangling is turned on (@pxref{Print Settings}).
13809When there is no symbol corresponding to the current program counter
13810the string @code{??} is displayed.
13811
13812@item line
13813Indicates the current line number for the selected frame.
13814When the current line number is not known the string @code{??} is displayed.
13815
13816@item pc
13817Indicates the current program counter address.
13818
13819@end table
13820
8e04817f
AC
13821@node TUI Keys
13822@section TUI Key Bindings
13823@cindex TUI key bindings
c906108c 13824
8e04817f
AC
13825The TUI installs several key bindings in the readline keymaps
13826(@pxref{Command Line Editing}).
13827They allow to leave or enter in the TUI mode or they operate
7cf36c78
SC
13828directly on the TUI layout and windows. The TUI also provides
13829a @emph{SingleKey} keymap which binds several keys directly to
13830@value{GDBN} commands. The following key bindings
8e04817f 13831are installed for both TUI mode and the @value{GDBN} standard mode.
c906108c 13832
8e04817f
AC
13833@table @kbd
13834@kindex C-x C-a
13835@item C-x C-a
13836@kindex C-x a
13837@itemx C-x a
13838@kindex C-x A
13839@itemx C-x A
13840Enter or leave the TUI mode. When the TUI mode is left,
13841the curses window management is left and @value{GDBN} operates using
13842its standard mode writing on the terminal directly. When the TUI
13843mode is entered, the control is given back to the curses windows.
13844The screen is then refreshed.
c906108c 13845
8e04817f
AC
13846@kindex C-x 1
13847@item C-x 1
13848Use a TUI layout with only one window. The layout will
13849either be @samp{source} or @samp{assembly}. When the TUI mode
13850is not active, it will switch to the TUI mode.
2df3850c 13851
8e04817f 13852Think of this key binding as the Emacs @kbd{C-x 1} binding.
c906108c 13853
8e04817f
AC
13854@kindex C-x 2
13855@item C-x 2
13856Use a TUI layout with at least two windows. When the current
13857layout shows already two windows, a next layout with two windows is used.
13858When a new layout is chosen, one window will always be common to the
13859previous layout and the new one.
c906108c 13860
8e04817f 13861Think of it as the Emacs @kbd{C-x 2} binding.
2df3850c 13862
72ffddc9
SC
13863@kindex C-x o
13864@item C-x o
13865Change the active window. The TUI associates several key bindings
13866(like scrolling and arrow keys) to the active window. This command
13867gives the focus to the next TUI window.
13868
13869Think of it as the Emacs @kbd{C-x o} binding.
13870
7cf36c78
SC
13871@kindex C-x s
13872@item C-x s
13873Use the TUI @emph{SingleKey} keymap that binds single key to gdb commands
13874(@pxref{TUI Single Key Mode}).
13875
c906108c
SS
13876@end table
13877
8e04817f 13878The following key bindings are handled only by the TUI mode:
5d161b24 13879
8e04817f
AC
13880@table @key
13881@kindex PgUp
13882@item PgUp
13883Scroll the active window one page up.
c906108c 13884
8e04817f
AC
13885@kindex PgDn
13886@item PgDn
13887Scroll the active window one page down.
c906108c 13888
8e04817f
AC
13889@kindex Up
13890@item Up
13891Scroll the active window one line up.
c906108c 13892
8e04817f
AC
13893@kindex Down
13894@item Down
13895Scroll the active window one line down.
c906108c 13896
8e04817f
AC
13897@kindex Left
13898@item Left
13899Scroll the active window one column left.
c906108c 13900
8e04817f
AC
13901@kindex Right
13902@item Right
13903Scroll the active window one column right.
c906108c 13904
8e04817f
AC
13905@kindex C-L
13906@item C-L
13907Refresh the screen.
c906108c 13908
8e04817f 13909@end table
c906108c 13910
8e04817f 13911In the TUI mode, the arrow keys are used by the active window
72ffddc9
SC
13912for scrolling. This means they are available for readline when the
13913active window is the command window. When the command window
13914does not have the focus, it is necessary to use other readline
13915key bindings such as @key{C-p}, @key{C-n}, @key{C-b} and @key{C-f}.
8e04817f 13916
7cf36c78
SC
13917@node TUI Single Key Mode
13918@section TUI Single Key Mode
13919@cindex TUI single key mode
13920
13921The TUI provides a @emph{SingleKey} mode in which it installs a particular
13922key binding in the readline keymaps to connect single keys to
13923some gdb commands.
13924
13925@table @kbd
13926@kindex c @r{(SingleKey TUI key)}
13927@item c
13928continue
13929
13930@kindex d @r{(SingleKey TUI key)}
13931@item d
13932down
13933
13934@kindex f @r{(SingleKey TUI key)}
13935@item f
13936finish
13937
13938@kindex n @r{(SingleKey TUI key)}
13939@item n
13940next
13941
13942@kindex q @r{(SingleKey TUI key)}
13943@item q
13944exit the @emph{SingleKey} mode.
13945
13946@kindex r @r{(SingleKey TUI key)}
13947@item r
13948run
13949
13950@kindex s @r{(SingleKey TUI key)}
13951@item s
13952step
13953
13954@kindex u @r{(SingleKey TUI key)}
13955@item u
13956up
13957
13958@kindex v @r{(SingleKey TUI key)}
13959@item v
13960info locals
13961
13962@kindex w @r{(SingleKey TUI key)}
13963@item w
13964where
13965
13966@end table
13967
13968Other keys temporarily switch to the @value{GDBN} command prompt.
13969The key that was pressed is inserted in the editing buffer so that
13970it is possible to type most @value{GDBN} commands without interaction
13971with the TUI @emph{SingleKey} mode. Once the command is entered the TUI
13972@emph{SingleKey} mode is restored. The only way to permanently leave
13973this mode is by hitting @key{q} or @samp{@key{C-x} @key{s}}.
13974
13975
8e04817f
AC
13976@node TUI Commands
13977@section TUI specific commands
13978@cindex TUI commands
13979
13980The TUI has specific commands to control the text windows.
13981These commands are always available, that is they do not depend on
13982the current terminal mode in which @value{GDBN} runs. When @value{GDBN}
13983is in the standard mode, using these commands will automatically switch
13984in the TUI mode.
c906108c
SS
13985
13986@table @code
3d757584
SC
13987@item info win
13988@kindex info win
13989List and give the size of all displayed windows.
13990
8e04817f
AC
13991@item layout next
13992@kindex layout next
13993Display the next layout.
2df3850c 13994
8e04817f
AC
13995@item layout prev
13996@kindex layout prev
13997Display the previous layout.
c906108c 13998
8e04817f
AC
13999@item layout src
14000@kindex layout src
14001Display the source window only.
c906108c 14002
8e04817f
AC
14003@item layout asm
14004@kindex layout asm
14005Display the assembly window only.
c906108c 14006
8e04817f
AC
14007@item layout split
14008@kindex layout split
14009Display the source and assembly window.
c906108c 14010
8e04817f
AC
14011@item layout regs
14012@kindex layout regs
14013Display the register window together with the source or assembly window.
14014
14015@item focus next | prev | src | asm | regs | split
14016@kindex focus
14017Set the focus to the named window.
14018This command allows to change the active window so that scrolling keys
14019can be affected to another window.
c906108c 14020
8e04817f
AC
14021@item refresh
14022@kindex refresh
14023Refresh the screen. This is similar to using @key{C-L} key.
c906108c 14024
8e04817f
AC
14025@item update
14026@kindex update
14027Update the source window and the current execution point.
c906108c 14028
8e04817f
AC
14029@item winheight @var{name} +@var{count}
14030@itemx winheight @var{name} -@var{count}
14031@kindex winheight
14032Change the height of the window @var{name} by @var{count}
14033lines. Positive counts increase the height, while negative counts
14034decrease it.
2df3850c 14035
c906108c
SS
14036@end table
14037
8e04817f
AC
14038@node TUI Configuration
14039@section TUI configuration variables
14040@cindex TUI configuration variables
c906108c 14041
8e04817f
AC
14042The TUI has several configuration variables that control the
14043appearance of windows on the terminal.
c906108c 14044
8e04817f
AC
14045@table @code
14046@item set tui border-kind @var{kind}
14047@kindex set tui border-kind
14048Select the border appearance for the source, assembly and register windows.
14049The possible values are the following:
14050@table @code
14051@item space
14052Use a space character to draw the border.
c906108c 14053
8e04817f
AC
14054@item ascii
14055Use ascii characters + - and | to draw the border.
c906108c 14056
8e04817f
AC
14057@item acs
14058Use the Alternate Character Set to draw the border. The border is
14059drawn using character line graphics if the terminal supports them.
c78b4128 14060
8e04817f 14061@end table
c78b4128 14062
8e04817f
AC
14063@item set tui active-border-mode @var{mode}
14064@kindex set tui active-border-mode
14065Select the attributes to display the border of the active window.
14066The possible values are @code{normal}, @code{standout}, @code{reverse},
14067@code{half}, @code{half-standout}, @code{bold} and @code{bold-standout}.
c78b4128 14068
8e04817f
AC
14069@item set tui border-mode @var{mode}
14070@kindex set tui border-mode
14071Select the attributes to display the border of other windows.
14072The @var{mode} can be one of the following:
14073@table @code
14074@item normal
14075Use normal attributes to display the border.
c906108c 14076
8e04817f
AC
14077@item standout
14078Use standout mode.
c906108c 14079
8e04817f
AC
14080@item reverse
14081Use reverse video mode.
c906108c 14082
8e04817f
AC
14083@item half
14084Use half bright mode.
c906108c 14085
8e04817f
AC
14086@item half-standout
14087Use half bright and standout mode.
c906108c 14088
8e04817f
AC
14089@item bold
14090Use extra bright or bold mode.
c78b4128 14091
8e04817f
AC
14092@item bold-standout
14093Use extra bright or bold and standout mode.
c78b4128 14094
8e04817f 14095@end table
c78b4128 14096
8e04817f 14097@end table
c78b4128 14098
8e04817f
AC
14099@node Emacs
14100@chapter Using @value{GDBN} under @sc{gnu} Emacs
c78b4128 14101
8e04817f
AC
14102@cindex Emacs
14103@cindex @sc{gnu} Emacs
14104A special interface allows you to use @sc{gnu} Emacs to view (and
14105edit) the source files for the program you are debugging with
14106@value{GDBN}.
c906108c 14107
8e04817f
AC
14108To use this interface, use the command @kbd{M-x gdb} in Emacs. Give the
14109executable file you want to debug as an argument. This command starts
14110@value{GDBN} as a subprocess of Emacs, with input and output through a newly
14111created Emacs buffer.
14112@c (Do not use the @code{-tui} option to run @value{GDBN} from Emacs.)
c906108c 14113
8e04817f
AC
14114Using @value{GDBN} under Emacs is just like using @value{GDBN} normally except for two
14115things:
c906108c 14116
8e04817f
AC
14117@itemize @bullet
14118@item
14119All ``terminal'' input and output goes through the Emacs buffer.
14120@end itemize
c906108c 14121
8e04817f
AC
14122This applies both to @value{GDBN} commands and their output, and to the input
14123and output done by the program you are debugging.
bf0184be 14124
8e04817f
AC
14125This is useful because it means that you can copy the text of previous
14126commands and input them again; you can even use parts of the output
14127in this way.
bf0184be 14128
8e04817f
AC
14129All the facilities of Emacs' Shell mode are available for interacting
14130with your program. In particular, you can send signals the usual
14131way---for example, @kbd{C-c C-c} for an interrupt, @kbd{C-c C-z} for a
14132stop.
bf0184be 14133
8e04817f 14134@itemize @bullet
bf0184be 14135@item
8e04817f
AC
14136@value{GDBN} displays source code through Emacs.
14137@end itemize
bf0184be 14138
8e04817f
AC
14139Each time @value{GDBN} displays a stack frame, Emacs automatically finds the
14140source file for that frame and puts an arrow (@samp{=>}) at the
14141left margin of the current line. Emacs uses a separate buffer for
14142source display, and splits the screen to show both your @value{GDBN} session
14143and the source.
bf0184be 14144
8e04817f
AC
14145Explicit @value{GDBN} @code{list} or search commands still produce output as
14146usual, but you probably have no reason to use them from Emacs.
c906108c 14147
64fabec2
AC
14148If you specify an absolute file name when prompted for the @kbd{M-x
14149gdb} argument, then Emacs sets your current working directory to where
14150your program resides. If you only specify the file name, then Emacs
14151sets your current working directory to to the directory associated
14152with the previous buffer. In this case, @value{GDBN} may find your
14153program by searching your environment's @code{PATH} variable, but on
14154some operating systems it might not find the source. So, although the
14155@value{GDBN} input and output session proceeds normally, the auxiliary
14156buffer does not display the current source and line of execution.
14157
14158The initial working directory of @value{GDBN} is printed on the top
14159line of the @value{GDBN} I/O buffer and this serves as a default for
14160the commands that specify files for @value{GDBN} to operate
14161on. @xref{Files, ,Commands to specify files}.
14162
14163By default, @kbd{M-x gdb} calls the program called @file{gdb}. If you
14164need to call @value{GDBN} by a different name (for example, if you
14165keep several configurations around, with different names) you can
14166customize the Emacs variable @code{gud-gdb-command-name} to run the
14167one you want.
8e04817f
AC
14168
14169In the @value{GDBN} I/O buffer, you can use these special Emacs commands in
14170addition to the standard Shell mode commands:
c906108c 14171
8e04817f
AC
14172@table @kbd
14173@item C-h m
14174Describe the features of Emacs' @value{GDBN} Mode.
c906108c 14175
64fabec2 14176@item C-c C-s
8e04817f
AC
14177Execute to another source line, like the @value{GDBN} @code{step} command; also
14178update the display window to show the current file and location.
c906108c 14179
64fabec2 14180@item C-c C-n
8e04817f
AC
14181Execute to next source line in this function, skipping all function
14182calls, like the @value{GDBN} @code{next} command. Then update the display window
14183to show the current file and location.
c906108c 14184
64fabec2 14185@item C-c C-i
8e04817f
AC
14186Execute one instruction, like the @value{GDBN} @code{stepi} command; update
14187display window accordingly.
c906108c 14188
8e04817f
AC
14189@item C-c C-f
14190Execute until exit from the selected stack frame, like the @value{GDBN}
14191@code{finish} command.
c906108c 14192
64fabec2 14193@item C-c C-r
8e04817f
AC
14194Continue execution of your program, like the @value{GDBN} @code{continue}
14195command.
b433d00b 14196
64fabec2 14197@item C-c <
8e04817f
AC
14198Go up the number of frames indicated by the numeric argument
14199(@pxref{Arguments, , Numeric Arguments, Emacs, The @sc{gnu} Emacs Manual}),
14200like the @value{GDBN} @code{up} command.
b433d00b 14201
64fabec2 14202@item C-c >
8e04817f
AC
14203Go down the number of frames indicated by the numeric argument, like the
14204@value{GDBN} @code{down} command.
8e04817f 14205@end table
c906108c 14206
64fabec2 14207In any source file, the Emacs command @kbd{C-x SPC} (@code{gud-break})
8e04817f 14208tells @value{GDBN} to set a breakpoint on the source line point is on.
c906108c 14209
64fabec2
AC
14210If you type @kbd{M-x speedbar}, then Emacs displays a separate frame which
14211shows a backtrace when the @value{GDBN} I/O buffer is current. Move
14212point to any frame in the stack and type @key{RET} to make it become the
14213current frame and display the associated source in the source buffer.
14214Alternatively, click @kbd{Mouse-2} to make the selected frame become the
14215current one.
14216
8e04817f
AC
14217If you accidentally delete the source-display buffer, an easy way to get
14218it back is to type the command @code{f} in the @value{GDBN} buffer, to
14219request a frame display; when you run under Emacs, this recreates
14220the source buffer if necessary to show you the context of the current
14221frame.
c906108c 14222
8e04817f
AC
14223The source files displayed in Emacs are in ordinary Emacs buffers
14224which are visiting the source files in the usual way. You can edit
14225the files with these buffers if you wish; but keep in mind that @value{GDBN}
14226communicates with Emacs in terms of line numbers. If you add or
14227delete lines from the text, the line numbers that @value{GDBN} knows cease
14228to correspond properly with the code.
64fabec2
AC
14229
14230The description given here is for GNU Emacs version 21.3 and a more
14231detailed description of its interaction with @value{GDBN} is given in
14232the Emacs manual (@pxref{Debuggers,,, Emacs, The @sc{gnu} Emacs Manual}).
c906108c 14233
8e04817f
AC
14234@c The following dropped because Epoch is nonstandard. Reactivate
14235@c if/when v19 does something similar. ---doc@cygnus.com 19dec1990
14236@ignore
14237@kindex Emacs Epoch environment
14238@kindex Epoch
14239@kindex inspect
c906108c 14240
8e04817f
AC
14241Version 18 of @sc{gnu} Emacs has a built-in window system
14242called the @code{epoch}
14243environment. Users of this environment can use a new command,
14244@code{inspect} which performs identically to @code{print} except that
14245each value is printed in its own window.
14246@end ignore
c906108c 14247
922fbb7b
AC
14248
14249@node GDB/MI
14250@chapter The @sc{gdb/mi} Interface
14251
14252@unnumberedsec Function and Purpose
14253
14254@cindex @sc{gdb/mi}, its purpose
14255@sc{gdb/mi} is a line based machine oriented text interface to @value{GDBN}. It is
14256specifically intended to support the development of systems which use
14257the debugger as just one small component of a larger system.
14258
14259This chapter is a specification of the @sc{gdb/mi} interface. It is written
14260in the form of a reference manual.
14261
14262Note that @sc{gdb/mi} is still under construction, so some of the
14263features described below are incomplete and subject to change.
14264
14265@unnumberedsec Notation and Terminology
14266
14267@cindex notational conventions, for @sc{gdb/mi}
14268This chapter uses the following notation:
14269
14270@itemize @bullet
14271@item
14272@code{|} separates two alternatives.
14273
14274@item
14275@code{[ @var{something} ]} indicates that @var{something} is optional:
14276it may or may not be given.
14277
14278@item
14279@code{( @var{group} )*} means that @var{group} inside the parentheses
14280may repeat zero or more times.
14281
14282@item
14283@code{( @var{group} )+} means that @var{group} inside the parentheses
14284may repeat one or more times.
14285
14286@item
14287@code{"@var{string}"} means a literal @var{string}.
14288@end itemize
14289
14290@ignore
14291@heading Dependencies
14292@end ignore
14293
14294@heading Acknowledgments
14295
14296In alphabetic order: Andrew Cagney, Fernando Nasser, Stan Shebs and
14297Elena Zannoni.
14298
14299@menu
14300* GDB/MI Command Syntax::
14301* GDB/MI Compatibility with CLI::
14302* GDB/MI Output Records::
14303* GDB/MI Command Description Format::
14304* GDB/MI Breakpoint Table Commands::
14305* GDB/MI Data Manipulation::
14306* GDB/MI Program Control::
14307* GDB/MI Miscellaneous Commands::
14308@ignore
14309* GDB/MI Kod Commands::
14310* GDB/MI Memory Overlay Commands::
14311* GDB/MI Signal Handling Commands::
14312@end ignore
14313* GDB/MI Stack Manipulation::
14314* GDB/MI Symbol Query::
14315* GDB/MI Target Manipulation::
14316* GDB/MI Thread Commands::
14317* GDB/MI Tracepoint Commands::
14318* GDB/MI Variable Objects::
14319@end menu
14320
14321@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
14322@node GDB/MI Command Syntax
14323@section @sc{gdb/mi} Command Syntax
14324
14325@menu
14326* GDB/MI Input Syntax::
14327* GDB/MI Output Syntax::
14328* GDB/MI Simple Examples::
14329@end menu
14330
14331@node GDB/MI Input Syntax
14332@subsection @sc{gdb/mi} Input Syntax
14333
14334@cindex input syntax for @sc{gdb/mi}
14335@cindex @sc{gdb/mi}, input syntax
14336@table @code
14337@item @var{command} @expansion{}
14338@code{@var{cli-command} | @var{mi-command}}
14339
14340@item @var{cli-command} @expansion{}
14341@code{[ @var{token} ] @var{cli-command} @var{nl}}, where
14342@var{cli-command} is any existing @value{GDBN} CLI command.
14343
14344@item @var{mi-command} @expansion{}
14345@code{[ @var{token} ] "-" @var{operation} ( " " @var{option} )*
14346@code{[} " --" @code{]} ( " " @var{parameter} )* @var{nl}}
14347
14348@item @var{token} @expansion{}
14349"any sequence of digits"
14350
14351@item @var{option} @expansion{}
14352@code{"-" @var{parameter} [ " " @var{parameter} ]}
14353
14354@item @var{parameter} @expansion{}
14355@code{@var{non-blank-sequence} | @var{c-string}}
14356
14357@item @var{operation} @expansion{}
14358@emph{any of the operations described in this chapter}
14359
14360@item @var{non-blank-sequence} @expansion{}
14361@emph{anything, provided it doesn't contain special characters such as
14362"-", @var{nl}, """ and of course " "}
14363
14364@item @var{c-string} @expansion{}
14365@code{""" @var{seven-bit-iso-c-string-content} """}
14366
14367@item @var{nl} @expansion{}
14368@code{CR | CR-LF}
14369@end table
14370
14371@noindent
14372Notes:
14373
14374@itemize @bullet
14375@item
14376The CLI commands are still handled by the @sc{mi} interpreter; their
14377output is described below.
14378
14379@item
14380The @code{@var{token}}, when present, is passed back when the command
14381finishes.
14382
14383@item
14384Some @sc{mi} commands accept optional arguments as part of the parameter
14385list. Each option is identified by a leading @samp{-} (dash) and may be
14386followed by an optional argument parameter. Options occur first in the
14387parameter list and can be delimited from normal parameters using
14388@samp{--} (this is useful when some parameters begin with a dash).
14389@end itemize
14390
14391Pragmatics:
14392
14393@itemize @bullet
14394@item
14395We want easy access to the existing CLI syntax (for debugging).
14396
14397@item
14398We want it to be easy to spot a @sc{mi} operation.
14399@end itemize
14400
14401@node GDB/MI Output Syntax
14402@subsection @sc{gdb/mi} Output Syntax
14403
14404@cindex output syntax of @sc{gdb/mi}
14405@cindex @sc{gdb/mi}, output syntax
14406The output from @sc{gdb/mi} consists of zero or more out-of-band records
14407followed, optionally, by a single result record. This result record
14408is for the most recent command. The sequence of output records is
14409terminated by @samp{(@value{GDBP})}.
14410
14411If an input command was prefixed with a @code{@var{token}} then the
14412corresponding output for that command will also be prefixed by that same
14413@var{token}.
14414
14415@table @code
14416@item @var{output} @expansion{}
14417@code{( @var{out-of-band-record} )* [ @var{result-record} ] "(gdb)" @var{nl}}
14418
14419@item @var{result-record} @expansion{}
14420@code{ [ @var{token} ] "^" @var{result-class} ( "," @var{result} )* @var{nl}}
14421
14422@item @var{out-of-band-record} @expansion{}
14423@code{@var{async-record} | @var{stream-record}}
14424
14425@item @var{async-record} @expansion{}
14426@code{@var{exec-async-output} | @var{status-async-output} | @var{notify-async-output}}
14427
14428@item @var{exec-async-output} @expansion{}
14429@code{[ @var{token} ] "*" @var{async-output}}
14430
14431@item @var{status-async-output} @expansion{}
14432@code{[ @var{token} ] "+" @var{async-output}}
14433
14434@item @var{notify-async-output} @expansion{}
14435@code{[ @var{token} ] "=" @var{async-output}}
14436
14437@item @var{async-output} @expansion{}
14438@code{@var{async-class} ( "," @var{result} )* @var{nl}}
14439
14440@item @var{result-class} @expansion{}
14441@code{"done" | "running" | "connected" | "error" | "exit"}
14442
14443@item @var{async-class} @expansion{}
14444@code{"stopped" | @var{others}} (where @var{others} will be added
14445depending on the needs---this is still in development).
14446
14447@item @var{result} @expansion{}
14448@code{ @var{variable} "=" @var{value}}
14449
14450@item @var{variable} @expansion{}
14451@code{ @var{string} }
14452
14453@item @var{value} @expansion{}
14454@code{ @var{const} | @var{tuple} | @var{list} }
14455
14456@item @var{const} @expansion{}
14457@code{@var{c-string}}
14458
14459@item @var{tuple} @expansion{}
14460@code{ "@{@}" | "@{" @var{result} ( "," @var{result} )* "@}" }
14461
14462@item @var{list} @expansion{}
14463@code{ "[]" | "[" @var{value} ( "," @var{value} )* "]" | "["
14464@var{result} ( "," @var{result} )* "]" }
14465
14466@item @var{stream-record} @expansion{}
14467@code{@var{console-stream-output} | @var{target-stream-output} | @var{log-stream-output}}
14468
14469@item @var{console-stream-output} @expansion{}
14470@code{"~" @var{c-string}}
14471
14472@item @var{target-stream-output} @expansion{}
14473@code{"@@" @var{c-string}}
14474
14475@item @var{log-stream-output} @expansion{}
14476@code{"&" @var{c-string}}
14477
14478@item @var{nl} @expansion{}
14479@code{CR | CR-LF}
14480
14481@item @var{token} @expansion{}
14482@emph{any sequence of digits}.
14483@end table
14484
14485@noindent
14486Notes:
14487
14488@itemize @bullet
14489@item
14490All output sequences end in a single line containing a period.
14491
14492@item
14493The @code{@var{token}} is from the corresponding request. If an execution
14494command is interrupted by the @samp{-exec-interrupt} command, the
14495@var{token} associated with the @samp{*stopped} message is the one of the
14496original execution command, not the one of the interrupt command.
14497
14498@item
14499@cindex status output in @sc{gdb/mi}
14500@var{status-async-output} contains on-going status information about the
14501progress of a slow operation. It can be discarded. All status output is
14502prefixed by @samp{+}.
14503
14504@item
14505@cindex async output in @sc{gdb/mi}
14506@var{exec-async-output} contains asynchronous state change on the target
14507(stopped, started, disappeared). All async output is prefixed by
14508@samp{*}.
14509
14510@item
14511@cindex notify output in @sc{gdb/mi}
14512@var{notify-async-output} contains supplementary information that the
14513client should handle (e.g., a new breakpoint information). All notify
14514output is prefixed by @samp{=}.
14515
14516@item
14517@cindex console output in @sc{gdb/mi}
14518@var{console-stream-output} is output that should be displayed as is in the
14519console. It is the textual response to a CLI command. All the console
14520output is prefixed by @samp{~}.
14521
14522@item
14523@cindex target output in @sc{gdb/mi}
14524@var{target-stream-output} is the output produced by the target program.
14525All the target output is prefixed by @samp{@@}.
14526
14527@item
14528@cindex log output in @sc{gdb/mi}
14529@var{log-stream-output} is output text coming from @value{GDBN}'s internals, for
14530instance messages that should be displayed as part of an error log. All
14531the log output is prefixed by @samp{&}.
14532
14533@item
14534@cindex list output in @sc{gdb/mi}
14535New @sc{gdb/mi} commands should only output @var{lists} containing
14536@var{values}.
14537
14538
14539@end itemize
14540
14541@xref{GDB/MI Stream Records, , @sc{gdb/mi} Stream Records}, for more
14542details about the various output records.
14543
14544@node GDB/MI Simple Examples
14545@subsection Simple Examples of @sc{gdb/mi} Interaction
14546@cindex @sc{gdb/mi}, simple examples
14547
14548This subsection presents several simple examples of interaction using
14549the @sc{gdb/mi} interface. In these examples, @samp{->} means that the
14550following line is passed to @sc{gdb/mi} as input, while @samp{<-} means
14551the output received from @sc{gdb/mi}.
14552
14553@subsubheading Target Stop
14554@c Ummm... There is no "-stop" command. This assumes async, no?
14555Here's an example of stopping the inferior process:
14556
14557@smallexample
14558-> -stop
14559<- (@value{GDBP})
14560@end smallexample
14561
14562@noindent
14563and later:
14564
14565@smallexample
14566<- *stop,reason="stop",address="0x123",source="a.c:123"
14567<- (@value{GDBP})
14568@end smallexample
14569
14570@subsubheading Simple CLI Command
14571
14572Here's an example of a simple CLI command being passed through
14573@sc{gdb/mi} and on to the CLI.
14574
14575@smallexample
14576-> print 1+2
14577<- &"print 1+2\n"
14578<- ~"$1 = 3\n"
14579<- ^done
14580<- (@value{GDBP})
14581@end smallexample
14582
14583@subsubheading Command With Side Effects
14584
14585@smallexample
14586-> -symbol-file xyz.exe
14587<- *breakpoint,nr="3",address="0x123",source="a.c:123"
14588<- (@value{GDBP})
14589@end smallexample
14590
14591@subsubheading A Bad Command
14592
14593Here's what happens if you pass a non-existent command:
14594
14595@smallexample
14596-> -rubbish
14597<- ^error,msg="Undefined MI command: rubbish"
14598<- (@value{GDBP})
14599@end smallexample
14600
14601@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
14602@node GDB/MI Compatibility with CLI
14603@section @sc{gdb/mi} Compatibility with CLI
14604
14605@cindex compatibility, @sc{gdb/mi} and CLI
14606@cindex @sc{gdb/mi}, compatibility with CLI
14607To help users familiar with @value{GDBN}'s existing CLI interface, @sc{gdb/mi}
14608accepts existing CLI commands. As specified by the syntax, such
14609commands can be directly entered into the @sc{gdb/mi} interface and @value{GDBN} will
14610respond.
14611
14612This mechanism is provided as an aid to developers of @sc{gdb/mi}
14613clients and not as a reliable interface into the CLI. Since the command
14614is being interpreteted in an environment that assumes @sc{gdb/mi}
14615behaviour, the exact output of such commands is likely to end up being
14616an un-supported hybrid of @sc{gdb/mi} and CLI output.
14617
14618@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
14619@node GDB/MI Output Records
14620@section @sc{gdb/mi} Output Records
14621
14622@menu
14623* GDB/MI Result Records::
14624* GDB/MI Stream Records::
14625* GDB/MI Out-of-band Records::
14626@end menu
14627
14628@node GDB/MI Result Records
14629@subsection @sc{gdb/mi} Result Records
14630
14631@cindex result records in @sc{gdb/mi}
14632@cindex @sc{gdb/mi}, result records
14633In addition to a number of out-of-band notifications, the response to a
14634@sc{gdb/mi} command includes one of the following result indications:
14635
14636@table @code
14637@findex ^done
14638@item "^done" [ "," @var{results} ]
14639The synchronous operation was successful, @code{@var{results}} are the return
14640values.
14641
14642@item "^running"
14643@findex ^running
14644@c Is this one correct? Should it be an out-of-band notification?
14645The asynchronous operation was successfully started. The target is
14646running.
14647
14648@item "^error" "," @var{c-string}
14649@findex ^error
14650The operation failed. The @code{@var{c-string}} contains the corresponding
14651error message.
14652@end table
14653
14654@node GDB/MI Stream Records
14655@subsection @sc{gdb/mi} Stream Records
14656
14657@cindex @sc{gdb/mi}, stream records
14658@cindex stream records in @sc{gdb/mi}
14659@value{GDBN} internally maintains a number of output streams: the console, the
14660target, and the log. The output intended for each of these streams is
14661funneled through the @sc{gdb/mi} interface using @dfn{stream records}.
14662
14663Each stream record begins with a unique @dfn{prefix character} which
14664identifies its stream (@pxref{GDB/MI Output Syntax, , @sc{gdb/mi} Output
14665Syntax}). In addition to the prefix, each stream record contains a
14666@code{@var{string-output}}. This is either raw text (with an implicit new
14667line) or a quoted C string (which does not contain an implicit newline).
14668
14669@table @code
14670@item "~" @var{string-output}
14671The console output stream contains text that should be displayed in the
14672CLI console window. It contains the textual responses to CLI commands.
14673
14674@item "@@" @var{string-output}
14675The target output stream contains any textual output from the running
14676target.
14677
14678@item "&" @var{string-output}
14679The log stream contains debugging messages being produced by @value{GDBN}'s
14680internals.
14681@end table
14682
14683@node GDB/MI Out-of-band Records
14684@subsection @sc{gdb/mi} Out-of-band Records
14685
14686@cindex out-of-band records in @sc{gdb/mi}
14687@cindex @sc{gdb/mi}, out-of-band records
14688@dfn{Out-of-band} records are used to notify the @sc{gdb/mi} client of
14689additional changes that have occurred. Those changes can either be a
14690consequence of @sc{gdb/mi} (e.g., a breakpoint modified) or a result of
14691target activity (e.g., target stopped).
14692
14693The following is a preliminary list of possible out-of-band records.
14694
14695@table @code
14696@item "*" "stop"
14697@end table
14698
14699
14700@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
14701@node GDB/MI Command Description Format
14702@section @sc{gdb/mi} Command Description Format
14703
14704The remaining sections describe blocks of commands. Each block of
14705commands is laid out in a fashion similar to this section.
14706
14707Note the the line breaks shown in the examples are here only for
14708readability. They don't appear in the real output.
14709Also note that the commands with a non-available example (N.A.@:) are
14710not yet implemented.
14711
14712@subheading Motivation
14713
14714The motivation for this collection of commands.
14715
14716@subheading Introduction
14717
14718A brief introduction to this collection of commands as a whole.
14719
14720@subheading Commands
14721
14722For each command in the block, the following is described:
14723
14724@subsubheading Synopsis
14725
14726@smallexample
14727 -command @var{args}@dots{}
14728@end smallexample
14729
14730@subsubheading @value{GDBN} Command
14731
14732The corresponding @value{GDBN} CLI command.
14733
14734@subsubheading Result
14735
14736@subsubheading Out-of-band
14737
14738@subsubheading Notes
14739
14740@subsubheading Example
14741
14742
14743@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
14744@node GDB/MI Breakpoint Table Commands
14745@section @sc{gdb/mi} Breakpoint table commands
14746
14747@cindex breakpoint commands for @sc{gdb/mi}
14748@cindex @sc{gdb/mi}, breakpoint commands
14749This section documents @sc{gdb/mi} commands for manipulating
14750breakpoints.
14751
14752@subheading The @code{-break-after} Command
14753@findex -break-after
14754
14755@subsubheading Synopsis
14756
14757@smallexample
14758 -break-after @var{number} @var{count}
14759@end smallexample
14760
14761The breakpoint number @var{number} is not in effect until it has been
14762hit @var{count} times. To see how this is reflected in the output of
14763the @samp{-break-list} command, see the description of the
14764@samp{-break-list} command below.
14765
14766@subsubheading @value{GDBN} Command
14767
14768The corresponding @value{GDBN} command is @samp{ignore}.
14769
14770@subsubheading Example
14771
14772@smallexample
14773(@value{GDBP})
14774-break-insert main
14775^done,bkpt=@{number="1",addr="0x000100d0",file="hello.c",line="5"@}
14776(@value{GDBP})
14777-break-after 1 3
14778~
14779^done
14780(@value{GDBP})
14781-break-list
14782^done,BreakpointTable=@{nr_rows="1",nr_cols="6",
14783hdr=[@{width="3",alignment="-1",col_name="number",colhdr="Num"@},
14784@{width="14",alignment="-1",col_name="type",colhdr="Type"@},
14785@{width="4",alignment="-1",col_name="disp",colhdr="Disp"@},
14786@{width="3",alignment="-1",col_name="enabled",colhdr="Enb"@},
14787@{width="10",alignment="-1",col_name="addr",colhdr="Address"@},
14788@{width="40",alignment="2",col_name="what",colhdr="What"@}],
14789body=[bkpt=@{number="1",type="breakpoint",disp="keep",enabled="y",
14790addr="0x000100d0",func="main",file="hello.c",line="5",times="0",
14791ignore="3"@}]@}
14792(@value{GDBP})
14793@end smallexample
14794
14795@ignore
14796@subheading The @code{-break-catch} Command
14797@findex -break-catch
14798
14799@subheading The @code{-break-commands} Command
14800@findex -break-commands
14801@end ignore
14802
14803
14804@subheading The @code{-break-condition} Command
14805@findex -break-condition
14806
14807@subsubheading Synopsis
14808
14809@smallexample
14810 -break-condition @var{number} @var{expr}
14811@end smallexample
14812
14813Breakpoint @var{number} will stop the program only if the condition in
14814@var{expr} is true. The condition becomes part of the
14815@samp{-break-list} output (see the description of the @samp{-break-list}
14816command below).
14817
14818@subsubheading @value{GDBN} Command
14819
14820The corresponding @value{GDBN} command is @samp{condition}.
14821
14822@subsubheading Example
14823
14824@smallexample
14825(@value{GDBP})
14826-break-condition 1 1
14827^done
14828(@value{GDBP})
14829-break-list
14830^done,BreakpointTable=@{nr_rows="1",nr_cols="6",
14831hdr=[@{width="3",alignment="-1",col_name="number",colhdr="Num"@},
14832@{width="14",alignment="-1",col_name="type",colhdr="Type"@},
14833@{width="4",alignment="-1",col_name="disp",colhdr="Disp"@},
14834@{width="3",alignment="-1",col_name="enabled",colhdr="Enb"@},
14835@{width="10",alignment="-1",col_name="addr",colhdr="Address"@},
14836@{width="40",alignment="2",col_name="what",colhdr="What"@}],
14837body=[bkpt=@{number="1",type="breakpoint",disp="keep",enabled="y",
14838addr="0x000100d0",func="main",file="hello.c",line="5",cond="1",
14839times="0",ignore="3"@}]@}
14840(@value{GDBP})
14841@end smallexample
14842
14843@subheading The @code{-break-delete} Command
14844@findex -break-delete
14845
14846@subsubheading Synopsis
14847
14848@smallexample
14849 -break-delete ( @var{breakpoint} )+
14850@end smallexample
14851
14852Delete the breakpoint(s) whose number(s) are specified in the argument
14853list. This is obviously reflected in the breakpoint list.
14854
14855@subsubheading @value{GDBN} command
14856
14857The corresponding @value{GDBN} command is @samp{delete}.
14858
14859@subsubheading Example
14860
14861@smallexample
14862(@value{GDBP})
14863-break-delete 1
14864^done
14865(@value{GDBP})
14866-break-list
14867^done,BreakpointTable=@{nr_rows="0",nr_cols="6",
14868hdr=[@{width="3",alignment="-1",col_name="number",colhdr="Num"@},
14869@{width="14",alignment="-1",col_name="type",colhdr="Type"@},
14870@{width="4",alignment="-1",col_name="disp",colhdr="Disp"@},
14871@{width="3",alignment="-1",col_name="enabled",colhdr="Enb"@},
14872@{width="10",alignment="-1",col_name="addr",colhdr="Address"@},
14873@{width="40",alignment="2",col_name="what",colhdr="What"@}],
14874body=[]@}
14875(@value{GDBP})
14876@end smallexample
14877
14878@subheading The @code{-break-disable} Command
14879@findex -break-disable
14880
14881@subsubheading Synopsis
14882
14883@smallexample
14884 -break-disable ( @var{breakpoint} )+
14885@end smallexample
14886
14887Disable the named @var{breakpoint}(s). The field @samp{enabled} in the
14888break list is now set to @samp{n} for the named @var{breakpoint}(s).
14889
14890@subsubheading @value{GDBN} Command
14891
14892The corresponding @value{GDBN} command is @samp{disable}.
14893
14894@subsubheading Example
14895
14896@smallexample
14897(@value{GDBP})
14898-break-disable 2
14899^done
14900(@value{GDBP})
14901-break-list
14902^done,BreakpointTable=@{nr_rows="1",nr_cols="6",
14903hdr=[@{width="3",alignment="-1",col_name="number",colhdr="Num"@},
14904@{width="14",alignment="-1",col_name="type",colhdr="Type"@},
14905@{width="4",alignment="-1",col_name="disp",colhdr="Disp"@},
14906@{width="3",alignment="-1",col_name="enabled",colhdr="Enb"@},
14907@{width="10",alignment="-1",col_name="addr",colhdr="Address"@},
14908@{width="40",alignment="2",col_name="what",colhdr="What"@}],
14909body=[bkpt=@{number="2",type="breakpoint",disp="keep",enabled="n",
14910addr="0x000100d0",func="main",file="hello.c",line="5",times="0"@}]@}
14911(@value{GDBP})
14912@end smallexample
14913
14914@subheading The @code{-break-enable} Command
14915@findex -break-enable
14916
14917@subsubheading Synopsis
14918
14919@smallexample
14920 -break-enable ( @var{breakpoint} )+
14921@end smallexample
14922
14923Enable (previously disabled) @var{breakpoint}(s).
14924
14925@subsubheading @value{GDBN} Command
14926
14927The corresponding @value{GDBN} command is @samp{enable}.
14928
14929@subsubheading Example
14930
14931@smallexample
14932(@value{GDBP})
14933-break-enable 2
14934^done
14935(@value{GDBP})
14936-break-list
14937^done,BreakpointTable=@{nr_rows="1",nr_cols="6",
14938hdr=[@{width="3",alignment="-1",col_name="number",colhdr="Num"@},
14939@{width="14",alignment="-1",col_name="type",colhdr="Type"@},
14940@{width="4",alignment="-1",col_name="disp",colhdr="Disp"@},
14941@{width="3",alignment="-1",col_name="enabled",colhdr="Enb"@},
14942@{width="10",alignment="-1",col_name="addr",colhdr="Address"@},
14943@{width="40",alignment="2",col_name="what",colhdr="What"@}],
14944body=[bkpt=@{number="2",type="breakpoint",disp="keep",enabled="y",
14945addr="0x000100d0",func="main",file="hello.c",line="5",times="0"@}]@}
14946(@value{GDBP})
14947@end smallexample
14948
14949@subheading The @code{-break-info} Command
14950@findex -break-info
14951
14952@subsubheading Synopsis
14953
14954@smallexample
14955 -break-info @var{breakpoint}
14956@end smallexample
14957
14958@c REDUNDANT???
14959Get information about a single breakpoint.
14960
14961@subsubheading @value{GDBN} command
14962
14963The corresponding @value{GDBN} command is @samp{info break @var{breakpoint}}.
14964
14965@subsubheading Example
14966N.A.
14967
14968@subheading The @code{-break-insert} Command
14969@findex -break-insert
14970
14971@subsubheading Synopsis
14972
14973@smallexample
14974 -break-insert [ -t ] [ -h ] [ -r ]
14975 [ -c @var{condition} ] [ -i @var{ignore-count} ]
14976 [ -p @var{thread} ] [ @var{line} | @var{addr} ]
14977@end smallexample
14978
14979@noindent
14980If specified, @var{line}, can be one of:
14981
14982@itemize @bullet
14983@item function
14984@c @item +offset
14985@c @item -offset
14986@c @item linenum
14987@item filename:linenum
14988@item filename:function
14989@item *address
14990@end itemize
14991
14992The possible optional parameters of this command are:
14993
14994@table @samp
14995@item -t
14996Insert a tempoary breakpoint.
14997@item -h
14998Insert a hardware breakpoint.
14999@item -c @var{condition}
15000Make the breakpoint conditional on @var{condition}.
15001@item -i @var{ignore-count}
15002Initialize the @var{ignore-count}.
15003@item -r
15004Insert a regular breakpoint in all the functions whose names match the
15005given regular expression. Other flags are not applicable to regular
15006expresson.
15007@end table
15008
15009@subsubheading Result
15010
15011The result is in the form:
15012
15013@smallexample
15014 ^done,bkptno="@var{number}",func="@var{funcname}",
15015 file="@var{filename}",line="@var{lineno}"
15016@end smallexample
15017
15018@noindent
15019where @var{number} is the @value{GDBN} number for this breakpoint, @var{funcname}
15020is the name of the function where the breakpoint was inserted,
15021@var{filename} is the name of the source file which contains this
15022function, and @var{lineno} is the source line number within that file.
15023
15024Note: this format is open to change.
15025@c An out-of-band breakpoint instead of part of the result?
15026
15027@subsubheading @value{GDBN} Command
15028
15029The corresponding @value{GDBN} commands are @samp{break}, @samp{tbreak},
15030@samp{hbreak}, @samp{thbreak}, and @samp{rbreak}.
15031
15032@subsubheading Example
15033
15034@smallexample
15035(@value{GDBP})
15036-break-insert main
15037^done,bkpt=@{number="1",addr="0x0001072c",file="recursive2.c",line="4"@}
15038(@value{GDBP})
15039-break-insert -t foo
15040^done,bkpt=@{number="2",addr="0x00010774",file="recursive2.c",line="11"@}
15041(@value{GDBP})
15042-break-list
15043^done,BreakpointTable=@{nr_rows="2",nr_cols="6",
15044hdr=[@{width="3",alignment="-1",col_name="number",colhdr="Num"@},
15045@{width="14",alignment="-1",col_name="type",colhdr="Type"@},
15046@{width="4",alignment="-1",col_name="disp",colhdr="Disp"@},
15047@{width="3",alignment="-1",col_name="enabled",colhdr="Enb"@},
15048@{width="10",alignment="-1",col_name="addr",colhdr="Address"@},
15049@{width="40",alignment="2",col_name="what",colhdr="What"@}],
15050body=[bkpt=@{number="1",type="breakpoint",disp="keep",enabled="y",
15051addr="0x0001072c", func="main",file="recursive2.c",line="4",times="0"@},
15052bkpt=@{number="2",type="breakpoint",disp="del",enabled="y",
15053addr="0x00010774",func="foo",file="recursive2.c",line="11",times="0"@}]@}
15054(@value{GDBP})
15055-break-insert -r foo.*
15056~int foo(int, int);
15057^done,bkpt=@{number="3",addr="0x00010774",file="recursive2.c",line="11"@}
15058(@value{GDBP})
15059@end smallexample
15060
15061@subheading The @code{-break-list} Command
15062@findex -break-list
15063
15064@subsubheading Synopsis
15065
15066@smallexample
15067 -break-list
15068@end smallexample
15069
15070Displays the list of inserted breakpoints, showing the following fields:
15071
15072@table @samp
15073@item Number
15074number of the breakpoint
15075@item Type
15076type of the breakpoint: @samp{breakpoint} or @samp{watchpoint}
15077@item Disposition
15078should the breakpoint be deleted or disabled when it is hit: @samp{keep}
15079or @samp{nokeep}
15080@item Enabled
15081is the breakpoint enabled or no: @samp{y} or @samp{n}
15082@item Address
15083memory location at which the breakpoint is set
15084@item What
15085logical location of the breakpoint, expressed by function name, file
15086name, line number
15087@item Times
15088number of times the breakpoint has been hit
15089@end table
15090
15091If there are no breakpoints or watchpoints, the @code{BreakpointTable}
15092@code{body} field is an empty list.
15093
15094@subsubheading @value{GDBN} Command
15095
15096The corresponding @value{GDBN} command is @samp{info break}.
15097
15098@subsubheading Example
15099
15100@smallexample
15101(@value{GDBP})
15102-break-list
15103^done,BreakpointTable=@{nr_rows="2",nr_cols="6",
15104hdr=[@{width="3",alignment="-1",col_name="number",colhdr="Num"@},
15105@{width="14",alignment="-1",col_name="type",colhdr="Type"@},
15106@{width="4",alignment="-1",col_name="disp",colhdr="Disp"@},
15107@{width="3",alignment="-1",col_name="enabled",colhdr="Enb"@},
15108@{width="10",alignment="-1",col_name="addr",colhdr="Address"@},
15109@{width="40",alignment="2",col_name="what",colhdr="What"@}],
15110body=[bkpt=@{number="1",type="breakpoint",disp="keep",enabled="y",
15111addr="0x000100d0",func="main",file="hello.c",line="5",times="0"@},
15112bkpt=@{number="2",type="breakpoint",disp="keep",enabled="y",
15113addr="0x00010114",func="foo",file="hello.c",line="13",times="0"@}]@}
15114(@value{GDBP})
15115@end smallexample
15116
15117Here's an example of the result when there are no breakpoints:
15118
15119@smallexample
15120(@value{GDBP})
15121-break-list
15122^done,BreakpointTable=@{nr_rows="0",nr_cols="6",
15123hdr=[@{width="3",alignment="-1",col_name="number",colhdr="Num"@},
15124@{width="14",alignment="-1",col_name="type",colhdr="Type"@},
15125@{width="4",alignment="-1",col_name="disp",colhdr="Disp"@},
15126@{width="3",alignment="-1",col_name="enabled",colhdr="Enb"@},
15127@{width="10",alignment="-1",col_name="addr",colhdr="Address"@},
15128@{width="40",alignment="2",col_name="what",colhdr="What"@}],
15129body=[]@}
15130(@value{GDBP})
15131@end smallexample
15132
15133@subheading The @code{-break-watch} Command
15134@findex -break-watch
15135
15136@subsubheading Synopsis
15137
15138@smallexample
15139 -break-watch [ -a | -r ]
15140@end smallexample
15141
15142Create a watchpoint. With the @samp{-a} option it will create an
15143@dfn{access} watchpoint, i.e. a watchpoint that triggers either on a
15144read from or on a write to the memory location. With the @samp{-r}
15145option, the watchpoint created is a @dfn{read} watchpoint, i.e. it will
15146trigger only when the memory location is accessed for reading. Without
15147either of the options, the watchpoint created is a regular watchpoint,
15148i.e. it will trigger when the memory location is accessed for writing.
15149@xref{Set Watchpoints, , Setting watchpoints}.
15150
15151Note that @samp{-break-list} will report a single list of watchpoints and
15152breakpoints inserted.
15153
15154@subsubheading @value{GDBN} Command
15155
15156The corresponding @value{GDBN} commands are @samp{watch}, @samp{awatch}, and
15157@samp{rwatch}.
15158
15159@subsubheading Example
15160
15161Setting a watchpoint on a variable in the @code{main} function:
15162
15163@smallexample
15164(@value{GDBP})
15165-break-watch x
15166^done,wpt=@{number="2",exp="x"@}
15167(@value{GDBP})
15168-exec-continue
15169^running
15170^done,reason="watchpoint-trigger",wpt=@{number="2",exp="x"@},
15171value=@{old="-268439212",new="55"@},
15172frame=@{func="main",args=[],file="recursive2.c",line="5"@}
15173(@value{GDBP})
15174@end smallexample
15175
15176Setting a watchpoint on a variable local to a function. @value{GDBN} will stop
15177the program execution twice: first for the variable changing value, then
15178for the watchpoint going out of scope.
15179
15180@smallexample
15181(@value{GDBP})
15182-break-watch C
15183^done,wpt=@{number="5",exp="C"@}
15184(@value{GDBP})
15185-exec-continue
15186^running
15187^done,reason="watchpoint-trigger",
15188wpt=@{number="5",exp="C"@},value=@{old="-276895068",new="3"@},
15189frame=@{func="callee4",args=[],
15190file="../../../devo/gdb/testsuite/gdb.mi/basics.c",line="13"@}
15191(@value{GDBP})
15192-exec-continue
15193^running
15194^done,reason="watchpoint-scope",wpnum="5",
15195frame=@{func="callee3",args=[@{name="strarg",
15196value="0x11940 \"A string argument.\""@}],
15197file="../../../devo/gdb/testsuite/gdb.mi/basics.c",line="18"@}
15198(@value{GDBP})
15199@end smallexample
15200
15201Listing breakpoints and watchpoints, at different points in the program
15202execution. Note that once the watchpoint goes out of scope, it is
15203deleted.
15204
15205@smallexample
15206(@value{GDBP})
15207-break-watch C
15208^done,wpt=@{number="2",exp="C"@}
15209(@value{GDBP})
15210-break-list
15211^done,BreakpointTable=@{nr_rows="2",nr_cols="6",
15212hdr=[@{width="3",alignment="-1",col_name="number",colhdr="Num"@},
15213@{width="14",alignment="-1",col_name="type",colhdr="Type"@},
15214@{width="4",alignment="-1",col_name="disp",colhdr="Disp"@},
15215@{width="3",alignment="-1",col_name="enabled",colhdr="Enb"@},
15216@{width="10",alignment="-1",col_name="addr",colhdr="Address"@},
15217@{width="40",alignment="2",col_name="what",colhdr="What"@}],
15218body=[bkpt=@{number="1",type="breakpoint",disp="keep",enabled="y",
15219addr="0x00010734",func="callee4",
15220file="../../../devo/gdb/testsuite/gdb.mi/basics.c",line="8",times="1"@},
15221bkpt=@{number="2",type="watchpoint",disp="keep",
15222enabled="y",addr="",what="C",times="0"@}]@}
15223(@value{GDBP})
15224-exec-continue
15225^running
15226^done,reason="watchpoint-trigger",wpt=@{number="2",exp="C"@},
15227value=@{old="-276895068",new="3"@},
15228frame=@{func="callee4",args=[],
15229file="../../../devo/gdb/testsuite/gdb.mi/basics.c",line="13"@}
15230(@value{GDBP})
15231-break-list
15232^done,BreakpointTable=@{nr_rows="2",nr_cols="6",
15233hdr=[@{width="3",alignment="-1",col_name="number",colhdr="Num"@},
15234@{width="14",alignment="-1",col_name="type",colhdr="Type"@},
15235@{width="4",alignment="-1",col_name="disp",colhdr="Disp"@},
15236@{width="3",alignment="-1",col_name="enabled",colhdr="Enb"@},
15237@{width="10",alignment="-1",col_name="addr",colhdr="Address"@},
15238@{width="40",alignment="2",col_name="what",colhdr="What"@}],
15239body=[bkpt=@{number="1",type="breakpoint",disp="keep",enabled="y",
15240addr="0x00010734",func="callee4",
15241file="../../../devo/gdb/testsuite/gdb.mi/basics.c",line="8",times="1"@},
15242bkpt=@{number="2",type="watchpoint",disp="keep",
15243enabled="y",addr="",what="C",times="-5"@}]@}
15244(@value{GDBP})
15245-exec-continue
15246^running
15247^done,reason="watchpoint-scope",wpnum="2",
15248frame=@{func="callee3",args=[@{name="strarg",
15249value="0x11940 \"A string argument.\""@}],
15250file="../../../devo/gdb/testsuite/gdb.mi/basics.c",line="18"@}
15251(@value{GDBP})
15252-break-list
15253^done,BreakpointTable=@{nr_rows="1",nr_cols="6",
15254hdr=[@{width="3",alignment="-1",col_name="number",colhdr="Num"@},
15255@{width="14",alignment="-1",col_name="type",colhdr="Type"@},
15256@{width="4",alignment="-1",col_name="disp",colhdr="Disp"@},
15257@{width="3",alignment="-1",col_name="enabled",colhdr="Enb"@},
15258@{width="10",alignment="-1",col_name="addr",colhdr="Address"@},
15259@{width="40",alignment="2",col_name="what",colhdr="What"@}],
15260body=[bkpt=@{number="1",type="breakpoint",disp="keep",enabled="y",
15261addr="0x00010734",func="callee4",
15262file="../../../devo/gdb/testsuite/gdb.mi/basics.c",line="8",times="1"@}]@}
15263(@value{GDBP})
15264@end smallexample
15265
15266@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
15267@node GDB/MI Data Manipulation
15268@section @sc{gdb/mi} Data Manipulation
15269
15270@cindex data manipulation, in @sc{gdb/mi}
15271@cindex @sc{gdb/mi}, data manipulation
15272This section describes the @sc{gdb/mi} commands that manipulate data:
15273examine memory and registers, evaluate expressions, etc.
15274
15275@c REMOVED FROM THE INTERFACE.
15276@c @subheading -data-assign
15277@c Change the value of a program variable. Plenty of side effects.
15278@c @subsubheading GDB command
15279@c set variable
15280@c @subsubheading Example
15281@c N.A.
15282
15283@subheading The @code{-data-disassemble} Command
15284@findex -data-disassemble
15285
15286@subsubheading Synopsis
15287
15288@smallexample
15289 -data-disassemble
15290 [ -s @var{start-addr} -e @var{end-addr} ]
15291 | [ -f @var{filename} -l @var{linenum} [ -n @var{lines} ] ]
15292 -- @var{mode}
15293@end smallexample
15294
15295@noindent
15296Where:
15297
15298@table @samp
15299@item @var{start-addr}
15300is the beginning address (or @code{$pc})
15301@item @var{end-addr}
15302is the end address
15303@item @var{filename}
15304is the name of the file to disassemble
15305@item @var{linenum}
15306is the line number to disassemble around
15307@item @var{lines}
15308is the the number of disassembly lines to be produced. If it is -1,
15309the whole function will be disassembled, in case no @var{end-addr} is
15310specified. If @var{end-addr} is specified as a non-zero value, and
15311@var{lines} is lower than the number of disassembly lines between
15312@var{start-addr} and @var{end-addr}, only @var{lines} lines are
15313displayed; if @var{lines} is higher than the number of lines between
15314@var{start-addr} and @var{end-addr}, only the lines up to @var{end-addr}
15315are displayed.
15316@item @var{mode}
15317is either 0 (meaning only disassembly) or 1 (meaning mixed source and
15318disassembly).
15319@end table
15320
15321@subsubheading Result
15322
15323The output for each instruction is composed of four fields:
15324
15325@itemize @bullet
15326@item Address
15327@item Func-name
15328@item Offset
15329@item Instruction
15330@end itemize
15331
15332Note that whatever included in the instruction field, is not manipulated
15333directely by @sc{gdb/mi}, i.e. it is not possible to adjust its format.
15334
15335@subsubheading @value{GDBN} Command
15336
15337There's no direct mapping from this command to the CLI.
15338
15339@subsubheading Example
15340
15341Disassemble from the current value of @code{$pc} to @code{$pc + 20}:
15342
15343@smallexample
15344(@value{GDBP})
15345-data-disassemble -s $pc -e "$pc + 20" -- 0
15346^done,
15347asm_insns=[
15348@{address="0x000107c0",func-name="main",offset="4",
15349inst="mov 2, %o0"@},
15350@{address="0x000107c4",func-name="main",offset="8",
15351inst="sethi %hi(0x11800), %o2"@},
15352@{address="0x000107c8",func-name="main",offset="12",
15353inst="or %o2, 0x140, %o1\t! 0x11940 <_lib_version+8>"@},
15354@{address="0x000107cc",func-name="main",offset="16",
15355inst="sethi %hi(0x11800), %o2"@},
15356@{address="0x000107d0",func-name="main",offset="20",
15357inst="or %o2, 0x168, %o4\t! 0x11968 <_lib_version+48>"@}]
15358(@value{GDBP})
15359@end smallexample
15360
15361Disassemble the whole @code{main} function. Line 32 is part of
15362@code{main}.
15363
15364@smallexample
15365-data-disassemble -f basics.c -l 32 -- 0
15366^done,asm_insns=[
15367@{address="0x000107bc",func-name="main",offset="0",
15368inst="save %sp, -112, %sp"@},
15369@{address="0x000107c0",func-name="main",offset="4",
15370inst="mov 2, %o0"@},
15371@{address="0x000107c4",func-name="main",offset="8",
15372inst="sethi %hi(0x11800), %o2"@},
15373[@dots{}]
15374@{address="0x0001081c",func-name="main",offset="96",inst="ret "@},
15375@{address="0x00010820",func-name="main",offset="100",inst="restore "@}]
15376(@value{GDBP})
15377@end smallexample
15378
15379Disassemble 3 instructions from the start of @code{main}:
15380
15381@smallexample
15382(@value{GDBP})
15383-data-disassemble -f basics.c -l 32 -n 3 -- 0
15384^done,asm_insns=[
15385@{address="0x000107bc",func-name="main",offset="0",
15386inst="save %sp, -112, %sp"@},
15387@{address="0x000107c0",func-name="main",offset="4",
15388inst="mov 2, %o0"@},
15389@{address="0x000107c4",func-name="main",offset="8",
15390inst="sethi %hi(0x11800), %o2"@}]
15391(@value{GDBP})
15392@end smallexample
15393
15394Disassemble 3 instructions from the start of @code{main} in mixed mode:
15395
15396@smallexample
15397(@value{GDBP})
15398-data-disassemble -f basics.c -l 32 -n 3 -- 1
15399^done,asm_insns=[
15400src_and_asm_line=@{line="31",
15401file="/kwikemart/marge/ezannoni/flathead-dev/devo/gdb/ \
15402 testsuite/gdb.mi/basics.c",line_asm_insn=[
15403@{address="0x000107bc",func-name="main",offset="0",
15404inst="save %sp, -112, %sp"@}]@},
15405src_and_asm_line=@{line="32",
15406file="/kwikemart/marge/ezannoni/flathead-dev/devo/gdb/ \
15407 testsuite/gdb.mi/basics.c",line_asm_insn=[
15408@{address="0x000107c0",func-name="main",offset="4",
15409inst="mov 2, %o0"@},
15410@{address="0x000107c4",func-name="main",offset="8",
15411inst="sethi %hi(0x11800), %o2"@}]@}]
15412(@value{GDBP})
15413@end smallexample
15414
15415
15416@subheading The @code{-data-evaluate-expression} Command
15417@findex -data-evaluate-expression
15418
15419@subsubheading Synopsis
15420
15421@smallexample
15422 -data-evaluate-expression @var{expr}
15423@end smallexample
15424
15425Evaluate @var{expr} as an expression. The expression could contain an
15426inferior function call. The function call will execute synchronously.
15427If the expression contains spaces, it must be enclosed in double quotes.
15428
15429@subsubheading @value{GDBN} Command
15430
15431The corresponding @value{GDBN} commands are @samp{print}, @samp{output}, and
15432@samp{call}. In @code{gdbtk} only, there's a corresponding
15433@samp{gdb_eval} command.
15434
15435@subsubheading Example
15436
15437In the following example, the numbers that precede the commands are the
15438@dfn{tokens} described in @ref{GDB/MI Command Syntax, ,@sc{gdb/mi}
15439Command Syntax}. Notice how @sc{gdb/mi} returns the same tokens in its
15440output.
15441
15442@smallexample
15443211-data-evaluate-expression A
15444211^done,value="1"
15445(@value{GDBP})
15446311-data-evaluate-expression &A
15447311^done,value="0xefffeb7c"
15448(@value{GDBP})
15449411-data-evaluate-expression A+3
15450411^done,value="4"
15451(@value{GDBP})
15452511-data-evaluate-expression "A + 3"
15453511^done,value="4"
15454(@value{GDBP})
15455@end smallexample
15456
15457
15458@subheading The @code{-data-list-changed-registers} Command
15459@findex -data-list-changed-registers
15460
15461@subsubheading Synopsis
15462
15463@smallexample
15464 -data-list-changed-registers
15465@end smallexample
15466
15467Display a list of the registers that have changed.
15468
15469@subsubheading @value{GDBN} Command
15470
15471@value{GDBN} doesn't have a direct analog for this command; @code{gdbtk}
15472has the corresponding command @samp{gdb_changed_register_list}.
15473
15474@subsubheading Example
15475
15476On a PPC MBX board:
15477
15478@smallexample
15479(@value{GDBP})
15480-exec-continue
15481^running
15482
15483(@value{GDBP})
15484*stopped,reason="breakpoint-hit",bkptno="1",frame=@{func="main",
15485args=[],file="try.c",line="5"@}
15486(@value{GDBP})
15487-data-list-changed-registers
15488^done,changed-registers=["0","1","2","4","5","6","7","8","9",
15489"10","11","13","14","15","16","17","18","19","20","21","22","23",
15490"24","25","26","27","28","30","31","64","65","66","67","69"]
15491(@value{GDBP})
15492@end smallexample
15493
15494
15495@subheading The @code{-data-list-register-names} Command
15496@findex -data-list-register-names
15497
15498@subsubheading Synopsis
15499
15500@smallexample
15501 -data-list-register-names [ ( @var{regno} )+ ]
15502@end smallexample
15503
15504Show a list of register names for the current target. If no arguments
15505are given, it shows a list of the names of all the registers. If
15506integer numbers are given as arguments, it will print a list of the
15507names of the registers corresponding to the arguments. To ensure
15508consistency between a register name and its number, the output list may
15509include empty register names.
15510
15511@subsubheading @value{GDBN} Command
15512
15513@value{GDBN} does not have a command which corresponds to
15514@samp{-data-list-register-names}. In @code{gdbtk} there is a
15515corresponding command @samp{gdb_regnames}.
15516
15517@subsubheading Example
15518
15519For the PPC MBX board:
15520@smallexample
15521(@value{GDBP})
15522-data-list-register-names
15523^done,register-names=["r0","r1","r2","r3","r4","r5","r6","r7",
15524"r8","r9","r10","r11","r12","r13","r14","r15","r16","r17","r18",
15525"r19","r20","r21","r22","r23","r24","r25","r26","r27","r28","r29",
15526"r30","r31","f0","f1","f2","f3","f4","f5","f6","f7","f8","f9",
15527"f10","f11","f12","f13","f14","f15","f16","f17","f18","f19","f20",
15528"f21","f22","f23","f24","f25","f26","f27","f28","f29","f30","f31",
15529"", "pc","ps","cr","lr","ctr","xer"]
15530(@value{GDBP})
15531-data-list-register-names 1 2 3
15532^done,register-names=["r1","r2","r3"]
15533(@value{GDBP})
15534@end smallexample
15535
15536@subheading The @code{-data-list-register-values} Command
15537@findex -data-list-register-values
15538
15539@subsubheading Synopsis
15540
15541@smallexample
15542 -data-list-register-values @var{fmt} [ ( @var{regno} )*]
15543@end smallexample
15544
15545Display the registers' contents. @var{fmt} is the format according to
15546which the registers' contents are to be returned, followed by an optional
15547list of numbers specifying the registers to display. A missing list of
15548numbers indicates that the contents of all the registers must be returned.
15549
15550Allowed formats for @var{fmt} are:
15551
15552@table @code
15553@item x
15554Hexadecimal
15555@item o
15556Octal
15557@item t
15558Binary
15559@item d
15560Decimal
15561@item r
15562Raw
15563@item N
15564Natural
15565@end table
15566
15567@subsubheading @value{GDBN} Command
15568
15569The corresponding @value{GDBN} commands are @samp{info reg}, @samp{info
15570all-reg}, and (in @code{gdbtk}) @samp{gdb_fetch_registers}.
15571
15572@subsubheading Example
15573
15574For a PPC MBX board (note: line breaks are for readability only, they
15575don't appear in the actual output):
15576
15577@smallexample
15578(@value{GDBP})
15579-data-list-register-values r 64 65
15580^done,register-values=[@{number="64",value="0xfe00a300"@},
15581@{number="65",value="0x00029002"@}]
15582(@value{GDBP})
15583-data-list-register-values x
15584^done,register-values=[@{number="0",value="0xfe0043c8"@},
15585@{number="1",value="0x3fff88"@},@{number="2",value="0xfffffffe"@},
15586@{number="3",value="0x0"@},@{number="4",value="0xa"@},
15587@{number="5",value="0x3fff68"@},@{number="6",value="0x3fff58"@},
15588@{number="7",value="0xfe011e98"@},@{number="8",value="0x2"@},
15589@{number="9",value="0xfa202820"@},@{number="10",value="0xfa202808"@},
15590@{number="11",value="0x1"@},@{number="12",value="0x0"@},
15591@{number="13",value="0x4544"@},@{number="14",value="0xffdfffff"@},
15592@{number="15",value="0xffffffff"@},@{number="16",value="0xfffffeff"@},
15593@{number="17",value="0xefffffed"@},@{number="18",value="0xfffffffe"@},
15594@{number="19",value="0xffffffff"@},@{number="20",value="0xffffffff"@},
15595@{number="21",value="0xffffffff"@},@{number="22",value="0xfffffff7"@},
15596@{number="23",value="0xffffffff"@},@{number="24",value="0xffffffff"@},
15597@{number="25",value="0xffffffff"@},@{number="26",value="0xfffffffb"@},
15598@{number="27",value="0xffffffff"@},@{number="28",value="0xf7bfffff"@},
15599@{number="29",value="0x0"@},@{number="30",value="0xfe010000"@},
15600@{number="31",value="0x0"@},@{number="32",value="0x0"@},
15601@{number="33",value="0x0"@},@{number="34",value="0x0"@},
15602@{number="35",value="0x0"@},@{number="36",value="0x0"@},
15603@{number="37",value="0x0"@},@{number="38",value="0x0"@},
15604@{number="39",value="0x0"@},@{number="40",value="0x0"@},
15605@{number="41",value="0x0"@},@{number="42",value="0x0"@},
15606@{number="43",value="0x0"@},@{number="44",value="0x0"@},
15607@{number="45",value="0x0"@},@{number="46",value="0x0"@},
15608@{number="47",value="0x0"@},@{number="48",value="0x0"@},
15609@{number="49",value="0x0"@},@{number="50",value="0x0"@},
15610@{number="51",value="0x0"@},@{number="52",value="0x0"@},
15611@{number="53",value="0x0"@},@{number="54",value="0x0"@},
15612@{number="55",value="0x0"@},@{number="56",value="0x0"@},
15613@{number="57",value="0x0"@},@{number="58",value="0x0"@},
15614@{number="59",value="0x0"@},@{number="60",value="0x0"@},
15615@{number="61",value="0x0"@},@{number="62",value="0x0"@},
15616@{number="63",value="0x0"@},@{number="64",value="0xfe00a300"@},
15617@{number="65",value="0x29002"@},@{number="66",value="0x202f04b5"@},
15618@{number="67",value="0xfe0043b0"@},@{number="68",value="0xfe00b3e4"@},
15619@{number="69",value="0x20002b03"@}]
15620(@value{GDBP})
15621@end smallexample
15622
15623
15624@subheading The @code{-data-read-memory} Command
15625@findex -data-read-memory
15626
15627@subsubheading Synopsis
15628
15629@smallexample
15630 -data-read-memory [ -o @var{byte-offset} ]
15631 @var{address} @var{word-format} @var{word-size}
15632 @var{nr-rows} @var{nr-cols} [ @var{aschar} ]
15633@end smallexample
15634
15635@noindent
15636where:
15637
15638@table @samp
15639@item @var{address}
15640An expression specifying the address of the first memory word to be
15641read. Complex expressions containing embedded white space should be
15642quoted using the C convention.
15643
15644@item @var{word-format}
15645The format to be used to print the memory words. The notation is the
15646same as for @value{GDBN}'s @code{print} command (@pxref{Output Formats,
15647,Output formats}).
15648
15649@item @var{word-size}
15650The size of each memory word in bytes.
15651
15652@item @var{nr-rows}
15653The number of rows in the output table.
15654
15655@item @var{nr-cols}
15656The number of columns in the output table.
15657
15658@item @var{aschar}
15659If present, indicates that each row should include an @sc{ascii} dump. The
15660value of @var{aschar} is used as a padding character when a byte is not a
15661member of the printable @sc{ascii} character set (printable @sc{ascii}
15662characters are those whose code is between 32 and 126, inclusively).
15663
15664@item @var{byte-offset}
15665An offset to add to the @var{address} before fetching memory.
15666@end table
15667
15668This command displays memory contents as a table of @var{nr-rows} by
15669@var{nr-cols} words, each word being @var{word-size} bytes. In total,
15670@code{@var{nr-rows} * @var{nr-cols} * @var{word-size}} bytes are read
15671(returned as @samp{total-bytes}). Should less than the requested number
15672of bytes be returned by the target, the missing words are identified
15673using @samp{N/A}. The number of bytes read from the target is returned
15674in @samp{nr-bytes} and the starting address used to read memory in
15675@samp{addr}.
15676
15677The address of the next/previous row or page is available in
15678@samp{next-row} and @samp{prev-row}, @samp{next-page} and
15679@samp{prev-page}.
15680
15681@subsubheading @value{GDBN} Command
15682
15683The corresponding @value{GDBN} command is @samp{x}. @code{gdbtk} has
15684@samp{gdb_get_mem} memory read command.
15685
15686@subsubheading Example
15687
15688Read six bytes of memory starting at @code{bytes+6} but then offset by
15689@code{-6} bytes. Format as three rows of two columns. One byte per
15690word. Display each word in hex.
15691
15692@smallexample
15693(@value{GDBP})
156949-data-read-memory -o -6 -- bytes+6 x 1 3 2
156959^done,addr="0x00001390",nr-bytes="6",total-bytes="6",
15696next-row="0x00001396",prev-row="0x0000138e",next-page="0x00001396",
15697prev-page="0x0000138a",memory=[
15698@{addr="0x00001390",data=["0x00","0x01"]@},
15699@{addr="0x00001392",data=["0x02","0x03"]@},
15700@{addr="0x00001394",data=["0x04","0x05"]@}]
15701(@value{GDBP})
15702@end smallexample
15703
15704Read two bytes of memory starting at address @code{shorts + 64} and
15705display as a single word formatted in decimal.
15706
15707@smallexample
15708(@value{GDBP})
157095-data-read-memory shorts+64 d 2 1 1
157105^done,addr="0x00001510",nr-bytes="2",total-bytes="2",
15711next-row="0x00001512",prev-row="0x0000150e",
15712next-page="0x00001512",prev-page="0x0000150e",memory=[
15713@{addr="0x00001510",data=["128"]@}]
15714(@value{GDBP})
15715@end smallexample
15716
15717Read thirty two bytes of memory starting at @code{bytes+16} and format
15718as eight rows of four columns. Include a string encoding with @samp{x}
15719used as the non-printable character.
15720
15721@smallexample
15722(@value{GDBP})
157234-data-read-memory bytes+16 x 1 8 4 x
157244^done,addr="0x000013a0",nr-bytes="32",total-bytes="32",
15725next-row="0x000013c0",prev-row="0x0000139c",
15726next-page="0x000013c0",prev-page="0x00001380",memory=[
15727@{addr="0x000013a0",data=["0x10","0x11","0x12","0x13"],ascii="xxxx"@},
15728@{addr="0x000013a4",data=["0x14","0x15","0x16","0x17"],ascii="xxxx"@},
15729@{addr="0x000013a8",data=["0x18","0x19","0x1a","0x1b"],ascii="xxxx"@},
15730@{addr="0x000013ac",data=["0x1c","0x1d","0x1e","0x1f"],ascii="xxxx"@},
15731@{addr="0x000013b0",data=["0x20","0x21","0x22","0x23"],ascii=" !\"#"@},
15732@{addr="0x000013b4",data=["0x24","0x25","0x26","0x27"],ascii="$%&'"@},
15733@{addr="0x000013b8",data=["0x28","0x29","0x2a","0x2b"],ascii="()*+"@},
15734@{addr="0x000013bc",data=["0x2c","0x2d","0x2e","0x2f"],ascii=",-./"@}]
15735(@value{GDBP})
15736@end smallexample
15737
15738@subheading The @code{-display-delete} Command
15739@findex -display-delete
15740
15741@subsubheading Synopsis
15742
15743@smallexample
15744 -display-delete @var{number}
15745@end smallexample
15746
15747Delete the display @var{number}.
15748
15749@subsubheading @value{GDBN} Command
15750
15751The corresponding @value{GDBN} command is @samp{delete display}.
15752
15753@subsubheading Example
15754N.A.
15755
15756
15757@subheading The @code{-display-disable} Command
15758@findex -display-disable
15759
15760@subsubheading Synopsis
15761
15762@smallexample
15763 -display-disable @var{number}
15764@end smallexample
15765
15766Disable display @var{number}.
15767
15768@subsubheading @value{GDBN} Command
15769
15770The corresponding @value{GDBN} command is @samp{disable display}.
15771
15772@subsubheading Example
15773N.A.
15774
15775
15776@subheading The @code{-display-enable} Command
15777@findex -display-enable
15778
15779@subsubheading Synopsis
15780
15781@smallexample
15782 -display-enable @var{number}
15783@end smallexample
15784
15785Enable display @var{number}.
15786
15787@subsubheading @value{GDBN} Command
15788
15789The corresponding @value{GDBN} command is @samp{enable display}.
15790
15791@subsubheading Example
15792N.A.
15793
15794
15795@subheading The @code{-display-insert} Command
15796@findex -display-insert
15797
15798@subsubheading Synopsis
15799
15800@smallexample
15801 -display-insert @var{expression}
15802@end smallexample
15803
15804Display @var{expression} every time the program stops.
15805
15806@subsubheading @value{GDBN} Command
15807
15808The corresponding @value{GDBN} command is @samp{display}.
15809
15810@subsubheading Example
15811N.A.
15812
15813
15814@subheading The @code{-display-list} Command
15815@findex -display-list
15816
15817@subsubheading Synopsis
15818
15819@smallexample
15820 -display-list
15821@end smallexample
15822
15823List the displays. Do not show the current values.
15824
15825@subsubheading @value{GDBN} Command
15826
15827The corresponding @value{GDBN} command is @samp{info display}.
15828
15829@subsubheading Example
15830N.A.
15831
15832
15833@subheading The @code{-environment-cd} Command
15834@findex -environment-cd
15835
15836@subsubheading Synopsis
15837
15838@smallexample
15839 -environment-cd @var{pathdir}
15840@end smallexample
15841
15842Set @value{GDBN}'s working directory.
15843
15844@subsubheading @value{GDBN} Command
15845
15846The corresponding @value{GDBN} command is @samp{cd}.
15847
15848@subsubheading Example
15849
15850@smallexample
15851(@value{GDBP})
15852-environment-cd /kwikemart/marge/ezannoni/flathead-dev/devo/gdb
15853^done
15854(@value{GDBP})
15855@end smallexample
15856
15857
15858@subheading The @code{-environment-directory} Command
15859@findex -environment-directory
15860
15861@subsubheading Synopsis
15862
15863@smallexample
15864 -environment-directory [ -r ] [ @var{pathdir} ]+
15865@end smallexample
15866
15867Add directories @var{pathdir} to beginning of search path for source files.
15868If the @samp{-r} option is used, the search path is reset to the default
15869search path. If directories @var{pathdir} are supplied in addition to the
15870@samp{-r} option, the search path is first reset and then addition
15871occurs as normal.
15872Multiple directories may be specified, separated by blanks. Specifying
15873multiple directories in a single command
15874results in the directories added to the beginning of the
15875search path in the same order they were presented in the command.
15876If blanks are needed as
15877part of a directory name, double-quotes should be used around
15878the name. In the command output, the path will show up separated
15879by the system directory-separator character. The directory-seperator
15880character must not be used
15881in any directory name.
15882If no directories are specified, the current search path is displayed.
15883
15884@subsubheading @value{GDBN} Command
15885
15886The corresponding @value{GDBN} command is @samp{dir}.
15887
15888@subsubheading Example
15889
15890@smallexample
15891(@value{GDBP})
15892-environment-directory /kwikemart/marge/ezannoni/flathead-dev/devo/gdb
15893^done,source-path="/kwikemart/marge/ezannoni/flathead-dev/devo/gdb:$cdir:$cwd"
15894(@value{GDBP})
15895-environment-directory ""
15896^done,source-path="/kwikemart/marge/ezannoni/flathead-dev/devo/gdb:$cdir:$cwd"
15897(@value{GDBP})
15898-environment-directory -r /home/jjohnstn/src/gdb /usr/src
15899^done,source-path="/home/jjohnstn/src/gdb:/usr/src:$cdir:$cwd"
15900(@value{GDBP})
15901-environment-directory -r
15902^done,source-path="$cdir:$cwd"
15903(@value{GDBP})
15904@end smallexample
15905
15906
15907@subheading The @code{-environment-path} Command
15908@findex -environment-path
15909
15910@subsubheading Synopsis
15911
15912@smallexample
15913 -environment-path [ -r ] [ @var{pathdir} ]+
15914@end smallexample
15915
15916Add directories @var{pathdir} to beginning of search path for object files.
15917If the @samp{-r} option is used, the search path is reset to the original
15918search path that existed at gdb start-up. If directories @var{pathdir} are
15919supplied in addition to the
15920@samp{-r} option, the search path is first reset and then addition
15921occurs as normal.
15922Multiple directories may be specified, separated by blanks. Specifying
15923multiple directories in a single command
15924results in the directories added to the beginning of the
15925search path in the same order they were presented in the command.
15926If blanks are needed as
15927part of a directory name, double-quotes should be used around
15928the name. In the command output, the path will show up separated
15929by the system directory-separator character. The directory-seperator
15930character must not be used
15931in any directory name.
15932If no directories are specified, the current path is displayed.
15933
15934
15935@subsubheading @value{GDBN} Command
15936
15937The corresponding @value{GDBN} command is @samp{path}.
15938
15939@subsubheading Example
15940
15941@smallexample
15942(@value{GDBP})
15943-environment-path
15944^done,path="/usr/bin"
15945(@value{GDBP})
15946-environment-path /kwikemart/marge/ezannoni/flathead-dev/ppc-eabi/gdb /bin
15947^done,path="/kwikemart/marge/ezannoni/flathead-dev/ppc-eabi/gdb:/bin:/usr/bin"
15948(@value{GDBP})
15949-environment-path -r /usr/local/bin
15950^done,path="/usr/local/bin:/usr/bin"
15951(@value{GDBP})
15952@end smallexample
15953
15954
15955@subheading The @code{-environment-pwd} Command
15956@findex -environment-pwd
15957
15958@subsubheading Synopsis
15959
15960@smallexample
15961 -environment-pwd
15962@end smallexample
15963
15964Show the current working directory.
15965
15966@subsubheading @value{GDBN} command
15967
15968The corresponding @value{GDBN} command is @samp{pwd}.
15969
15970@subsubheading Example
15971
15972@smallexample
15973(@value{GDBP})
15974-environment-pwd
15975^done,cwd="/kwikemart/marge/ezannoni/flathead-dev/devo/gdb"
15976(@value{GDBP})
15977@end smallexample
15978
15979@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
15980@node GDB/MI Program Control
15981@section @sc{gdb/mi} Program control
15982
15983@subsubheading Program termination
15984
15985As a result of execution, the inferior program can run to completion, if
15986it doesn't encounter any breakpoints. In this case the output will
15987include an exit code, if the program has exited exceptionally.
15988
15989@subsubheading Examples
15990
15991@noindent
15992Program exited normally:
15993
15994@smallexample
15995(@value{GDBP})
15996-exec-run
15997^running
15998(@value{GDBP})
15999x = 55
16000*stopped,reason="exited-normally"
16001(@value{GDBP})
16002@end smallexample
16003
16004@noindent
16005Program exited exceptionally:
16006
16007@smallexample
16008(@value{GDBP})
16009-exec-run
16010^running
16011(@value{GDBP})
16012x = 55
16013*stopped,reason="exited",exit-code="01"
16014(@value{GDBP})
16015@end smallexample
16016
16017Another way the program can terminate is if it receives a signal such as
16018@code{SIGINT}. In this case, @sc{gdb/mi} displays this:
16019
16020@smallexample
16021(@value{GDBP})
16022*stopped,reason="exited-signalled",signal-name="SIGINT",
16023signal-meaning="Interrupt"
16024@end smallexample
16025
16026
16027@subheading The @code{-exec-abort} Command
16028@findex -exec-abort
16029
16030@subsubheading Synopsis
16031
16032@smallexample
16033 -exec-abort
16034@end smallexample
16035
16036Kill the inferior running program.
16037
16038@subsubheading @value{GDBN} Command
16039
16040The corresponding @value{GDBN} command is @samp{kill}.
16041
16042@subsubheading Example
16043N.A.
16044
16045
16046@subheading The @code{-exec-arguments} Command
16047@findex -exec-arguments
16048
16049@subsubheading Synopsis
16050
16051@smallexample
16052 -exec-arguments @var{args}
16053@end smallexample
16054
16055Set the inferior program arguments, to be used in the next
16056@samp{-exec-run}.
16057
16058@subsubheading @value{GDBN} Command
16059
16060The corresponding @value{GDBN} command is @samp{set args}.
16061
16062@subsubheading Example
16063
16064@c FIXME!
16065Don't have one around.
16066
16067
16068@subheading The @code{-exec-continue} Command
16069@findex -exec-continue
16070
16071@subsubheading Synopsis
16072
16073@smallexample
16074 -exec-continue
16075@end smallexample
16076
16077Asynchronous command. Resumes the execution of the inferior program
16078until a breakpoint is encountered, or until the inferior exits.
16079
16080@subsubheading @value{GDBN} Command
16081
16082The corresponding @value{GDBN} corresponding is @samp{continue}.
16083
16084@subsubheading Example
16085
16086@smallexample
16087-exec-continue
16088^running
16089(@value{GDBP})
16090@@Hello world
16091*stopped,reason="breakpoint-hit",bkptno="2",frame=@{func="foo",args=[],
16092file="hello.c",line="13"@}
16093(@value{GDBP})
16094@end smallexample
16095
16096
16097@subheading The @code{-exec-finish} Command
16098@findex -exec-finish
16099
16100@subsubheading Synopsis
16101
16102@smallexample
16103 -exec-finish
16104@end smallexample
16105
16106Asynchronous command. Resumes the execution of the inferior program
16107until the current function is exited. Displays the results returned by
16108the function.
16109
16110@subsubheading @value{GDBN} Command
16111
16112The corresponding @value{GDBN} command is @samp{finish}.
16113
16114@subsubheading Example
16115
16116Function returning @code{void}.
16117
16118@smallexample
16119-exec-finish
16120^running
16121(@value{GDBP})
16122@@hello from foo
16123*stopped,reason="function-finished",frame=@{func="main",args=[],
16124file="hello.c",line="7"@}
16125(@value{GDBP})
16126@end smallexample
16127
16128Function returning other than @code{void}. The name of the internal
16129@value{GDBN} variable storing the result is printed, together with the
16130value itself.
16131
16132@smallexample
16133-exec-finish
16134^running
16135(@value{GDBP})
16136*stopped,reason="function-finished",frame=@{addr="0x000107b0",func="foo",
16137args=[@{name="a",value="1"],@{name="b",value="9"@}@},
16138file="recursive2.c",line="14"@},
16139gdb-result-var="$1",return-value="0"
16140(@value{GDBP})
16141@end smallexample
16142
16143
16144@subheading The @code{-exec-interrupt} Command
16145@findex -exec-interrupt
16146
16147@subsubheading Synopsis
16148
16149@smallexample
16150 -exec-interrupt
16151@end smallexample
16152
16153Asynchronous command. Interrupts the background execution of the target.
16154Note how the token associated with the stop message is the one for the
16155execution command that has been interrupted. The token for the interrupt
16156itself only appears in the @samp{^done} output. If the user is trying to
16157interrupt a non-running program, an error message will be printed.
16158
16159@subsubheading @value{GDBN} Command
16160
16161The corresponding @value{GDBN} command is @samp{interrupt}.
16162
16163@subsubheading Example
16164
16165@smallexample
16166(@value{GDBP})
16167111-exec-continue
16168111^running
16169
16170(@value{GDBP})
16171222-exec-interrupt
16172222^done
16173(@value{GDBP})
16174111*stopped,signal-name="SIGINT",signal-meaning="Interrupt",
16175frame=@{addr="0x00010140",func="foo",args=[],file="try.c",line="13"@}
16176(@value{GDBP})
16177
16178(@value{GDBP})
16179-exec-interrupt
16180^error,msg="mi_cmd_exec_interrupt: Inferior not executing."
16181(@value{GDBP})
16182@end smallexample
16183
16184
16185@subheading The @code{-exec-next} Command
16186@findex -exec-next
16187
16188@subsubheading Synopsis
16189
16190@smallexample
16191 -exec-next
16192@end smallexample
16193
16194Asynchronous command. Resumes execution of the inferior program, stopping
16195when the beginning of the next source line is reached.
16196
16197@subsubheading @value{GDBN} Command
16198
16199The corresponding @value{GDBN} command is @samp{next}.
16200
16201@subsubheading Example
16202
16203@smallexample
16204-exec-next
16205^running
16206(@value{GDBP})
16207*stopped,reason="end-stepping-range",line="8",file="hello.c"
16208(@value{GDBP})
16209@end smallexample
16210
16211
16212@subheading The @code{-exec-next-instruction} Command
16213@findex -exec-next-instruction
16214
16215@subsubheading Synopsis
16216
16217@smallexample
16218 -exec-next-instruction
16219@end smallexample
16220
16221Asynchronous command. Executes one machine instruction. If the
16222instruction is a function call continues until the function returns. If
16223the program stops at an instruction in the middle of a source line, the
16224address will be printed as well.
16225
16226@subsubheading @value{GDBN} Command
16227
16228The corresponding @value{GDBN} command is @samp{nexti}.
16229
16230@subsubheading Example
16231
16232@smallexample
16233(@value{GDBP})
16234-exec-next-instruction
16235^running
16236
16237(@value{GDBP})
16238*stopped,reason="end-stepping-range",
16239addr="0x000100d4",line="5",file="hello.c"
16240(@value{GDBP})
16241@end smallexample
16242
16243
16244@subheading The @code{-exec-return} Command
16245@findex -exec-return
16246
16247@subsubheading Synopsis
16248
16249@smallexample
16250 -exec-return
16251@end smallexample
16252
16253Makes current function return immediately. Doesn't execute the inferior.
16254Displays the new current frame.
16255
16256@subsubheading @value{GDBN} Command
16257
16258The corresponding @value{GDBN} command is @samp{return}.
16259
16260@subsubheading Example
16261
16262@smallexample
16263(@value{GDBP})
16264200-break-insert callee4
16265200^done,bkpt=@{number="1",addr="0x00010734",
16266file="../../../devo/gdb/testsuite/gdb.mi/basics.c",line="8"@}
16267(@value{GDBP})
16268000-exec-run
16269000^running
16270(@value{GDBP})
16271000*stopped,reason="breakpoint-hit",bkptno="1",
16272frame=@{func="callee4",args=[],
16273file="../../../devo/gdb/testsuite/gdb.mi/basics.c",line="8"@}
16274(@value{GDBP})
16275205-break-delete
16276205^done
16277(@value{GDBP})
16278111-exec-return
16279111^done,frame=@{level="0",func="callee3",
16280args=[@{name="strarg",
16281value="0x11940 \"A string argument.\""@}],
16282file="../../../devo/gdb/testsuite/gdb.mi/basics.c",line="18"@}
16283(@value{GDBP})
16284@end smallexample
16285
16286
16287@subheading The @code{-exec-run} Command
16288@findex -exec-run
16289
16290@subsubheading Synopsis
16291
16292@smallexample
16293 -exec-run
16294@end smallexample
16295
16296Asynchronous command. Starts execution of the inferior from the
16297beginning. The inferior executes until either a breakpoint is
16298encountered or the program exits.
16299
16300@subsubheading @value{GDBN} Command
16301
16302The corresponding @value{GDBN} command is @samp{run}.
16303
16304@subsubheading Example
16305
16306@smallexample
16307(@value{GDBP})
16308-break-insert main
16309^done,bkpt=@{number="1",addr="0x0001072c",file="recursive2.c",line="4"@}
16310(@value{GDBP})
16311-exec-run
16312^running
16313(@value{GDBP})
16314*stopped,reason="breakpoint-hit",bkptno="1",
16315frame=@{func="main",args=[],file="recursive2.c",line="4"@}
16316(@value{GDBP})
16317@end smallexample
16318
16319
16320@subheading The @code{-exec-show-arguments} Command
16321@findex -exec-show-arguments
16322
16323@subsubheading Synopsis
16324
16325@smallexample
16326 -exec-show-arguments
16327@end smallexample
16328
16329Print the arguments of the program.
16330
16331@subsubheading @value{GDBN} Command
16332
16333The corresponding @value{GDBN} command is @samp{show args}.
16334
16335@subsubheading Example
16336N.A.
16337
16338@c @subheading -exec-signal
16339
16340@subheading The @code{-exec-step} Command
16341@findex -exec-step
16342
16343@subsubheading Synopsis
16344
16345@smallexample
16346 -exec-step
16347@end smallexample
16348
16349Asynchronous command. Resumes execution of the inferior program, stopping
16350when the beginning of the next source line is reached, if the next
16351source line is not a function call. If it is, stop at the first
16352instruction of the called function.
16353
16354@subsubheading @value{GDBN} Command
16355
16356The corresponding @value{GDBN} command is @samp{step}.
16357
16358@subsubheading Example
16359
16360Stepping into a function:
16361
16362@smallexample
16363-exec-step
16364^running
16365(@value{GDBP})
16366*stopped,reason="end-stepping-range",
16367frame=@{func="foo",args=[@{name="a",value="10"@},
16368@{name="b",value="0"@}],file="recursive2.c",line="11"@}
16369(@value{GDBP})
16370@end smallexample
16371
16372Regular stepping:
16373
16374@smallexample
16375-exec-step
16376^running
16377(@value{GDBP})
16378*stopped,reason="end-stepping-range",line="14",file="recursive2.c"
16379(@value{GDBP})
16380@end smallexample
16381
16382
16383@subheading The @code{-exec-step-instruction} Command
16384@findex -exec-step-instruction
16385
16386@subsubheading Synopsis
16387
16388@smallexample
16389 -exec-step-instruction
16390@end smallexample
16391
16392Asynchronous command. Resumes the inferior which executes one machine
16393instruction. The output, once @value{GDBN} has stopped, will vary depending on
16394whether we have stopped in the middle of a source line or not. In the
16395former case, the address at which the program stopped will be printed as
16396well.
16397
16398@subsubheading @value{GDBN} Command
16399
16400The corresponding @value{GDBN} command is @samp{stepi}.
16401
16402@subsubheading Example
16403
16404@smallexample
16405(@value{GDBP})
16406-exec-step-instruction
16407^running
16408
16409(@value{GDBP})
16410*stopped,reason="end-stepping-range",
16411frame=@{func="foo",args=[],file="try.c",line="10"@}
16412(@value{GDBP})
16413-exec-step-instruction
16414^running
16415
16416(@value{GDBP})
16417*stopped,reason="end-stepping-range",
16418frame=@{addr="0x000100f4",func="foo",args=[],file="try.c",line="10"@}
16419(@value{GDBP})
16420@end smallexample
16421
16422
16423@subheading The @code{-exec-until} Command
16424@findex -exec-until
16425
16426@subsubheading Synopsis
16427
16428@smallexample
16429 -exec-until [ @var{location} ]
16430@end smallexample
16431
16432Asynchronous command. Executes the inferior until the @var{location}
16433specified in the argument is reached. If there is no argument, the inferior
16434executes until a source line greater than the current one is reached.
16435The reason for stopping in this case will be @samp{location-reached}.
16436
16437@subsubheading @value{GDBN} Command
16438
16439The corresponding @value{GDBN} command is @samp{until}.
16440
16441@subsubheading Example
16442
16443@smallexample
16444(@value{GDBP})
16445-exec-until recursive2.c:6
16446^running
16447(@value{GDBP})
16448x = 55
16449*stopped,reason="location-reached",frame=@{func="main",args=[],
16450file="recursive2.c",line="6"@}
16451(@value{GDBP})
16452@end smallexample
16453
16454@ignore
16455@subheading -file-clear
16456Is this going away????
16457@end ignore
16458
16459
16460@subheading The @code{-file-exec-and-symbols} Command
16461@findex -file-exec-and-symbols
16462
16463@subsubheading Synopsis
16464
16465@smallexample
16466 -file-exec-and-symbols @var{file}
16467@end smallexample
16468
16469Specify the executable file to be debugged. This file is the one from
16470which the symbol table is also read. If no file is specified, the
16471command clears the executable and symbol information. If breakpoints
16472are set when using this command with no arguments, @value{GDBN} will produce
16473error messages. Otherwise, no output is produced, except a completion
16474notification.
16475
16476@subsubheading @value{GDBN} Command
16477
16478The corresponding @value{GDBN} command is @samp{file}.
16479
16480@subsubheading Example
16481
16482@smallexample
16483(@value{GDBP})
16484-file-exec-and-symbols /kwikemart/marge/ezannoni/TRUNK/mbx/hello.mbx
16485^done
16486(@value{GDBP})
16487@end smallexample
16488
16489
16490@subheading The @code{-file-exec-file} Command
16491@findex -file-exec-file
16492
16493@subsubheading Synopsis
16494
16495@smallexample
16496 -file-exec-file @var{file}
16497@end smallexample
16498
16499Specify the executable file to be debugged. Unlike
16500@samp{-file-exec-and-symbols}, the symbol table is @emph{not} read
16501from this file. If used without argument, @value{GDBN} clears the information
16502about the executable file. No output is produced, except a completion
16503notification.
16504
16505@subsubheading @value{GDBN} Command
16506
16507The corresponding @value{GDBN} command is @samp{exec-file}.
16508
16509@subsubheading Example
16510
16511@smallexample
16512(@value{GDBP})
16513-file-exec-file /kwikemart/marge/ezannoni/TRUNK/mbx/hello.mbx
16514^done
16515(@value{GDBP})
16516@end smallexample
16517
16518
16519@subheading The @code{-file-list-exec-sections} Command
16520@findex -file-list-exec-sections
16521
16522@subsubheading Synopsis
16523
16524@smallexample
16525 -file-list-exec-sections
16526@end smallexample
16527
16528List the sections of the current executable file.
16529
16530@subsubheading @value{GDBN} Command
16531
16532The @value{GDBN} command @samp{info file} shows, among the rest, the same
16533information as this command. @code{gdbtk} has a corresponding command
16534@samp{gdb_load_info}.
16535
16536@subsubheading Example
16537N.A.
16538
16539
1abaf70c
BR
16540@subheading The @code{-file-list-exec-source-file} Command
16541@findex -file-list-exec-source-file
16542
16543@subsubheading Synopsis
16544
16545@smallexample
16546 -file-list-exec-source-file
16547@end smallexample
16548
16549List the line number, the current source file, and the absolute path
16550to the current source file for the current executable.
16551
16552@subsubheading @value{GDBN} Command
16553
16554There's no @value{GDBN} command which directly corresponds to this one.
16555
16556@subsubheading Example
16557
16558@smallexample
16559(@value{GDBP})
16560123-file-list-exec-source-file
16561123^done,line="1",file="foo.c",fullname="/home/bar/foo.c"
16562(@value{GDBP})
16563@end smallexample
16564
16565
922fbb7b
AC
16566@subheading The @code{-file-list-exec-source-files} Command
16567@findex -file-list-exec-source-files
16568
16569@subsubheading Synopsis
16570
16571@smallexample
16572 -file-list-exec-source-files
16573@end smallexample
16574
16575List the source files for the current executable.
16576
16577@subsubheading @value{GDBN} Command
16578
16579There's no @value{GDBN} command which directly corresponds to this one.
16580@code{gdbtk} has an analogous command @samp{gdb_listfiles}.
16581
16582@subsubheading Example
16583N.A.
16584
16585
16586@subheading The @code{-file-list-shared-libraries} Command
16587@findex -file-list-shared-libraries
16588
16589@subsubheading Synopsis
16590
16591@smallexample
16592 -file-list-shared-libraries
16593@end smallexample
16594
16595List the shared libraries in the program.
16596
16597@subsubheading @value{GDBN} Command
16598
16599The corresponding @value{GDBN} command is @samp{info shared}.
16600
16601@subsubheading Example
16602N.A.
16603
16604
16605@subheading The @code{-file-list-symbol-files} Command
16606@findex -file-list-symbol-files
16607
16608@subsubheading Synopsis
16609
16610@smallexample
16611 -file-list-symbol-files
16612@end smallexample
16613
16614List symbol files.
16615
16616@subsubheading @value{GDBN} Command
16617
16618The corresponding @value{GDBN} command is @samp{info file} (part of it).
16619
16620@subsubheading Example
16621N.A.
16622
16623
16624@subheading The @code{-file-symbol-file} Command
16625@findex -file-symbol-file
16626
16627@subsubheading Synopsis
16628
16629@smallexample
16630 -file-symbol-file @var{file}
16631@end smallexample
16632
16633Read symbol table info from the specified @var{file} argument. When
16634used without arguments, clears @value{GDBN}'s symbol table info. No output is
16635produced, except for a completion notification.
16636
16637@subsubheading @value{GDBN} Command
16638
16639The corresponding @value{GDBN} command is @samp{symbol-file}.
16640
16641@subsubheading Example
16642
16643@smallexample
16644(@value{GDBP})
16645-file-symbol-file /kwikemart/marge/ezannoni/TRUNK/mbx/hello.mbx
16646^done
16647(@value{GDBP})
16648@end smallexample
16649
16650@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
16651@node GDB/MI Miscellaneous Commands
16652@section Miscellaneous @value{GDBN} commands in @sc{gdb/mi}
16653
16654@c @subheading -gdb-complete
16655
16656@subheading The @code{-gdb-exit} Command
16657@findex -gdb-exit
16658
16659@subsubheading Synopsis
16660
16661@smallexample
16662 -gdb-exit
16663@end smallexample
16664
16665Exit @value{GDBN} immediately.
16666
16667@subsubheading @value{GDBN} Command
16668
16669Approximately corresponds to @samp{quit}.
16670
16671@subsubheading Example
16672
16673@smallexample
16674(@value{GDBP})
16675-gdb-exit
16676@end smallexample
16677
16678@subheading The @code{-gdb-set} Command
16679@findex -gdb-set
16680
16681@subsubheading Synopsis
16682
16683@smallexample
16684 -gdb-set
16685@end smallexample
16686
16687Set an internal @value{GDBN} variable.
16688@c IS THIS A DOLLAR VARIABLE? OR SOMETHING LIKE ANNOTATE ?????
16689
16690@subsubheading @value{GDBN} Command
16691
16692The corresponding @value{GDBN} command is @samp{set}.
16693
16694@subsubheading Example
16695
16696@smallexample
16697(@value{GDBP})
16698-gdb-set $foo=3
16699^done
16700(@value{GDBP})
16701@end smallexample
16702
16703
16704@subheading The @code{-gdb-show} Command
16705@findex -gdb-show
16706
16707@subsubheading Synopsis
16708
16709@smallexample
16710 -gdb-show
16711@end smallexample
16712
16713Show the current value of a @value{GDBN} variable.
16714
16715@subsubheading @value{GDBN} command
16716
16717The corresponding @value{GDBN} command is @samp{show}.
16718
16719@subsubheading Example
16720
16721@smallexample
16722(@value{GDBP})
16723-gdb-show annotate
16724^done,value="0"
16725(@value{GDBP})
16726@end smallexample
16727
16728@c @subheading -gdb-source
16729
16730
16731@subheading The @code{-gdb-version} Command
16732@findex -gdb-version
16733
16734@subsubheading Synopsis
16735
16736@smallexample
16737 -gdb-version
16738@end smallexample
16739
16740Show version information for @value{GDBN}. Used mostly in testing.
16741
16742@subsubheading @value{GDBN} Command
16743
16744There's no equivalent @value{GDBN} command. @value{GDBN} by default shows this
16745information when you start an interactive session.
16746
16747@subsubheading Example
16748
16749@c This example modifies the actual output from GDB to avoid overfull
16750@c box in TeX.
16751@smallexample
16752(@value{GDBP})
16753-gdb-version
16754~GNU gdb 5.2.1
16755~Copyright 2000 Free Software Foundation, Inc.
16756~GDB is free software, covered by the GNU General Public License, and
16757~you are welcome to change it and/or distribute copies of it under
16758~ certain conditions.
16759~Type "show copying" to see the conditions.
16760~There is absolutely no warranty for GDB. Type "show warranty" for
16761~ details.
16762~This GDB was configured as
16763 "--host=sparc-sun-solaris2.5.1 --target=ppc-eabi".
16764^done
16765(@value{GDBP})
16766@end smallexample
16767
16768@subheading The @code{-interpreter-exec} Command
16769@findex -interpreter-exec
16770
16771@subheading Synopsis
16772
16773@smallexample
16774-interpreter-exec @var{interpreter} @var{command}
16775@end smallexample
16776
16777Execute the specified @var{command} in the given @var{interpreter}.
16778
16779@subheading @value{GDBN} Command
16780
16781The corresponding @value{GDBN} command is @samp{interpreter-exec}.
16782
16783@subheading Example
16784
16785@smallexample
16786(@value{GDBP})
16787-interpreter-exec console "break main"
16788&"During symbol reading, couldn't parse type; debugger out of date?.\n"
16789&"During symbol reading, bad structure-type format.\n"
16790~"Breakpoint 1 at 0x8074fc6: file ../../src/gdb/main.c, line 743.\n"
16791^done
16792(@value{GDBP})
16793@end smallexample
16794
16795@ignore
16796@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
16797@node GDB/MI Kod Commands
16798@section @sc{gdb/mi} Kod Commands
16799
16800The Kod commands are not implemented.
16801
16802@c @subheading -kod-info
16803
16804@c @subheading -kod-list
16805
16806@c @subheading -kod-list-object-types
16807
16808@c @subheading -kod-show
16809
16810@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
16811@node GDB/MI Memory Overlay Commands
16812@section @sc{gdb/mi} Memory Overlay Commands
16813
16814The memory overlay commands are not implemented.
16815
16816@c @subheading -overlay-auto
16817
16818@c @subheading -overlay-list-mapping-state
16819
16820@c @subheading -overlay-list-overlays
16821
16822@c @subheading -overlay-map
16823
16824@c @subheading -overlay-off
16825
16826@c @subheading -overlay-on
16827
16828@c @subheading -overlay-unmap
16829
16830@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
16831@node GDB/MI Signal Handling Commands
16832@section @sc{gdb/mi} Signal Handling Commands
16833
16834Signal handling commands are not implemented.
16835
16836@c @subheading -signal-handle
16837
16838@c @subheading -signal-list-handle-actions
16839
16840@c @subheading -signal-list-signal-types
16841@end ignore
16842
16843
16844@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
16845@node GDB/MI Stack Manipulation
16846@section @sc{gdb/mi} Stack Manipulation Commands
16847
16848
16849@subheading The @code{-stack-info-frame} Command
16850@findex -stack-info-frame
16851
16852@subsubheading Synopsis
16853
16854@smallexample
16855 -stack-info-frame
16856@end smallexample
16857
16858Get info on the current frame.
16859
16860@subsubheading @value{GDBN} Command
16861
16862The corresponding @value{GDBN} command is @samp{info frame} or @samp{frame}
16863(without arguments).
16864
16865@subsubheading Example
16866N.A.
16867
16868@subheading The @code{-stack-info-depth} Command
16869@findex -stack-info-depth
16870
16871@subsubheading Synopsis
16872
16873@smallexample
16874 -stack-info-depth [ @var{max-depth} ]
16875@end smallexample
16876
16877Return the depth of the stack. If the integer argument @var{max-depth}
16878is specified, do not count beyond @var{max-depth} frames.
16879
16880@subsubheading @value{GDBN} Command
16881
16882There's no equivalent @value{GDBN} command.
16883
16884@subsubheading Example
16885
16886For a stack with frame levels 0 through 11:
16887
16888@smallexample
16889(@value{GDBP})
16890-stack-info-depth
16891^done,depth="12"
16892(@value{GDBP})
16893-stack-info-depth 4
16894^done,depth="4"
16895(@value{GDBP})
16896-stack-info-depth 12
16897^done,depth="12"
16898(@value{GDBP})
16899-stack-info-depth 11
16900^done,depth="11"
16901(@value{GDBP})
16902-stack-info-depth 13
16903^done,depth="12"
16904(@value{GDBP})
16905@end smallexample
16906
16907@subheading The @code{-stack-list-arguments} Command
16908@findex -stack-list-arguments
16909
16910@subsubheading Synopsis
16911
16912@smallexample
16913 -stack-list-arguments @var{show-values}
16914 [ @var{low-frame} @var{high-frame} ]
16915@end smallexample
16916
16917Display a list of the arguments for the frames between @var{low-frame}
16918and @var{high-frame} (inclusive). If @var{low-frame} and
16919@var{high-frame} are not provided, list the arguments for the whole call
16920stack.
16921
16922The @var{show-values} argument must have a value of 0 or 1. A value of
169230 means that only the names of the arguments are listed, a value of 1
16924means that both names and values of the arguments are printed.
16925
16926@subsubheading @value{GDBN} Command
16927
16928@value{GDBN} does not have an equivalent command. @code{gdbtk} has a
16929@samp{gdb_get_args} command which partially overlaps with the
16930functionality of @samp{-stack-list-arguments}.
16931
16932@subsubheading Example
16933
16934@smallexample
16935(@value{GDBP})
16936-stack-list-frames
16937^done,
16938stack=[
16939frame=@{level="0",addr="0x00010734",func="callee4",
16940file="../../../devo/gdb/testsuite/gdb.mi/basics.c",line="8"@},
16941frame=@{level="1",addr="0x0001076c",func="callee3",
16942file="../../../devo/gdb/testsuite/gdb.mi/basics.c",line="17"@},
16943frame=@{level="2",addr="0x0001078c",func="callee2",
16944file="../../../devo/gdb/testsuite/gdb.mi/basics.c",line="22"@},
16945frame=@{level="3",addr="0x000107b4",func="callee1",
16946file="../../../devo/gdb/testsuite/gdb.mi/basics.c",line="27"@},
16947frame=@{level="4",addr="0x000107e0",func="main",
16948file="../../../devo/gdb/testsuite/gdb.mi/basics.c",line="32"@}]
16949(@value{GDBP})
16950-stack-list-arguments 0
16951^done,
16952stack-args=[
16953frame=@{level="0",args=[]@},
16954frame=@{level="1",args=[name="strarg"]@},
16955frame=@{level="2",args=[name="intarg",name="strarg"]@},
16956frame=@{level="3",args=[name="intarg",name="strarg",name="fltarg"]@},
16957frame=@{level="4",args=[]@}]
16958(@value{GDBP})
16959-stack-list-arguments 1
16960^done,
16961stack-args=[
16962frame=@{level="0",args=[]@},
16963frame=@{level="1",
16964 args=[@{name="strarg",value="0x11940 \"A string argument.\""@}]@},
16965frame=@{level="2",args=[
16966@{name="intarg",value="2"@},
16967@{name="strarg",value="0x11940 \"A string argument.\""@}]@},
16968@{frame=@{level="3",args=[
16969@{name="intarg",value="2"@},
16970@{name="strarg",value="0x11940 \"A string argument.\""@},
16971@{name="fltarg",value="3.5"@}]@},
16972frame=@{level="4",args=[]@}]
16973(@value{GDBP})
16974-stack-list-arguments 0 2 2
16975^done,stack-args=[frame=@{level="2",args=[name="intarg",name="strarg"]@}]
16976(@value{GDBP})
16977-stack-list-arguments 1 2 2
16978^done,stack-args=[frame=@{level="2",
16979args=[@{name="intarg",value="2"@},
16980@{name="strarg",value="0x11940 \"A string argument.\""@}]@}]
16981(@value{GDBP})
16982@end smallexample
16983
16984@c @subheading -stack-list-exception-handlers
16985
16986
16987@subheading The @code{-stack-list-frames} Command
16988@findex -stack-list-frames
16989
16990@subsubheading Synopsis
16991
16992@smallexample
16993 -stack-list-frames [ @var{low-frame} @var{high-frame} ]
16994@end smallexample
16995
16996List the frames currently on the stack. For each frame it displays the
16997following info:
16998
16999@table @samp
17000@item @var{level}
17001The frame number, 0 being the topmost frame, i.e. the innermost function.
17002@item @var{addr}
17003The @code{$pc} value for that frame.
17004@item @var{func}
17005Function name.
17006@item @var{file}
17007File name of the source file where the function lives.
17008@item @var{line}
17009Line number corresponding to the @code{$pc}.
17010@end table
17011
17012If invoked without arguments, this command prints a backtrace for the
17013whole stack. If given two integer arguments, it shows the frames whose
17014levels are between the two arguments (inclusive). If the two arguments
17015are equal, it shows the single frame at the corresponding level.
17016
17017@subsubheading @value{GDBN} Command
17018
17019The corresponding @value{GDBN} commands are @samp{backtrace} and @samp{where}.
17020
17021@subsubheading Example
17022
17023Full stack backtrace:
17024
17025@smallexample
17026(@value{GDBP})
17027-stack-list-frames
17028^done,stack=
17029[frame=@{level="0",addr="0x0001076c",func="foo",
17030 file="recursive2.c",line="11"@},
17031frame=@{level="1",addr="0x000107a4",func="foo",
17032 file="recursive2.c",line="14"@},
17033frame=@{level="2",addr="0x000107a4",func="foo",
17034 file="recursive2.c",line="14"@},
17035frame=@{level="3",addr="0x000107a4",func="foo",
17036 file="recursive2.c",line="14"@},
17037frame=@{level="4",addr="0x000107a4",func="foo",
17038 file="recursive2.c",line="14"@},
17039frame=@{level="5",addr="0x000107a4",func="foo",
17040 file="recursive2.c",line="14"@},
17041frame=@{level="6",addr="0x000107a4",func="foo",
17042 file="recursive2.c",line="14"@},
17043frame=@{level="7",addr="0x000107a4",func="foo",
17044 file="recursive2.c",line="14"@},
17045frame=@{level="8",addr="0x000107a4",func="foo",
17046 file="recursive2.c",line="14"@},
17047frame=@{level="9",addr="0x000107a4",func="foo",
17048 file="recursive2.c",line="14"@},
17049frame=@{level="10",addr="0x000107a4",func="foo",
17050 file="recursive2.c",line="14"@},
17051frame=@{level="11",addr="0x00010738",func="main",
17052 file="recursive2.c",line="4"@}]
17053(@value{GDBP})
17054@end smallexample
17055
17056Show frames between @var{low_frame} and @var{high_frame}:
17057
17058@smallexample
17059(@value{GDBP})
17060-stack-list-frames 3 5
17061^done,stack=
17062[frame=@{level="3",addr="0x000107a4",func="foo",
17063 file="recursive2.c",line="14"@},
17064frame=@{level="4",addr="0x000107a4",func="foo",
17065 file="recursive2.c",line="14"@},
17066frame=@{level="5",addr="0x000107a4",func="foo",
17067 file="recursive2.c",line="14"@}]
17068(@value{GDBP})
17069@end smallexample
17070
17071Show a single frame:
17072
17073@smallexample
17074(@value{GDBP})
17075-stack-list-frames 3 3
17076^done,stack=
17077[frame=@{level="3",addr="0x000107a4",func="foo",
17078 file="recursive2.c",line="14"@}]
17079(@value{GDBP})
17080@end smallexample
17081
17082
17083@subheading The @code{-stack-list-locals} Command
17084@findex -stack-list-locals
17085
17086@subsubheading Synopsis
17087
17088@smallexample
17089 -stack-list-locals @var{print-values}
17090@end smallexample
17091
17092Display the local variable names for the current frame. With an
17093argument of 0 prints only the names of the variables, with argument of 1
17094prints also their values.
17095
17096@subsubheading @value{GDBN} Command
17097
17098@samp{info locals} in @value{GDBN}, @samp{gdb_get_locals} in @code{gdbtk}.
17099
17100@subsubheading Example
17101
17102@smallexample
17103(@value{GDBP})
17104-stack-list-locals 0
17105^done,locals=[name="A",name="B",name="C"]
17106(@value{GDBP})
17107-stack-list-locals 1
17108^done,locals=[@{name="A",value="1"@},@{name="B",value="2"@},
17109 @{name="C",value="3"@}]
17110(@value{GDBP})
17111@end smallexample
17112
17113
17114@subheading The @code{-stack-select-frame} Command
17115@findex -stack-select-frame
17116
17117@subsubheading Synopsis
17118
17119@smallexample
17120 -stack-select-frame @var{framenum}
17121@end smallexample
17122
17123Change the current frame. Select a different frame @var{framenum} on
17124the stack.
17125
17126@subsubheading @value{GDBN} Command
17127
17128The corresponding @value{GDBN} commands are @samp{frame}, @samp{up},
17129@samp{down}, @samp{select-frame}, @samp{up-silent}, and @samp{down-silent}.
17130
17131@subsubheading Example
17132
17133@smallexample
17134(@value{GDBP})
17135-stack-select-frame 2
17136^done
17137(@value{GDBP})
17138@end smallexample
17139
17140@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
17141@node GDB/MI Symbol Query
17142@section @sc{gdb/mi} Symbol Query Commands
17143
17144
17145@subheading The @code{-symbol-info-address} Command
17146@findex -symbol-info-address
17147
17148@subsubheading Synopsis
17149
17150@smallexample
17151 -symbol-info-address @var{symbol}
17152@end smallexample
17153
17154Describe where @var{symbol} is stored.
17155
17156@subsubheading @value{GDBN} Command
17157
17158The corresponding @value{GDBN} command is @samp{info address}.
17159
17160@subsubheading Example
17161N.A.
17162
17163
17164@subheading The @code{-symbol-info-file} Command
17165@findex -symbol-info-file
17166
17167@subsubheading Synopsis
17168
17169@smallexample
17170 -symbol-info-file
17171@end smallexample
17172
17173Show the file for the symbol.
17174
17175@subsubheading @value{GDBN} Command
17176
17177There's no equivalent @value{GDBN} command. @code{gdbtk} has
17178@samp{gdb_find_file}.
17179
17180@subsubheading Example
17181N.A.
17182
17183
17184@subheading The @code{-symbol-info-function} Command
17185@findex -symbol-info-function
17186
17187@subsubheading Synopsis
17188
17189@smallexample
17190 -symbol-info-function
17191@end smallexample
17192
17193Show which function the symbol lives in.
17194
17195@subsubheading @value{GDBN} Command
17196
17197@samp{gdb_get_function} in @code{gdbtk}.
17198
17199@subsubheading Example
17200N.A.
17201
17202
17203@subheading The @code{-symbol-info-line} Command
17204@findex -symbol-info-line
17205
17206@subsubheading Synopsis
17207
17208@smallexample
17209 -symbol-info-line
17210@end smallexample
17211
17212Show the core addresses of the code for a source line.
17213
17214@subsubheading @value{GDBN} Command
17215
17216The corresponding @value{GDBN} comamnd is @samp{info line}.
17217@code{gdbtk} has the @samp{gdb_get_line} and @samp{gdb_get_file} commands.
17218
17219@subsubheading Example
17220N.A.
17221
17222
17223@subheading The @code{-symbol-info-symbol} Command
17224@findex -symbol-info-symbol
17225
17226@subsubheading Synopsis
17227
17228@smallexample
17229 -symbol-info-symbol @var{addr}
17230@end smallexample
17231
17232Describe what symbol is at location @var{addr}.
17233
17234@subsubheading @value{GDBN} Command
17235
17236The corresponding @value{GDBN} command is @samp{info symbol}.
17237
17238@subsubheading Example
17239N.A.
17240
17241
17242@subheading The @code{-symbol-list-functions} Command
17243@findex -symbol-list-functions
17244
17245@subsubheading Synopsis
17246
17247@smallexample
17248 -symbol-list-functions
17249@end smallexample
17250
17251List the functions in the executable.
17252
17253@subsubheading @value{GDBN} Command
17254
17255@samp{info functions} in @value{GDBN}, @samp{gdb_listfunc} and
17256@samp{gdb_search} in @code{gdbtk}.
17257
17258@subsubheading Example
17259N.A.
17260
17261
32e7087d
JB
17262@subheading The @code{-symbol-list-lines} Command
17263@findex -symbol-list-lines
17264
17265@subsubheading Synopsis
17266
17267@smallexample
17268 -symbol-list-lines @var{filename}
17269@end smallexample
17270
17271Print the list of lines that contain code and their associated program
17272addresses for the given source filename. The entries are sorted in
17273ascending PC order.
17274
17275@subsubheading @value{GDBN} Command
17276
17277There is no corresponding @value{GDBN} command.
17278
17279@subsubheading Example
17280@smallexample
17281(@value{GDBP})
17282-symbol-list-lines basics.c
54ff5908 17283^done,lines=[@{pc="0x08048554",line="7"@},@{pc="0x0804855a",line="8"@}]
32e7087d
JB
17284(@value{GDBP})
17285@end smallexample
17286
17287
922fbb7b
AC
17288@subheading The @code{-symbol-list-types} Command
17289@findex -symbol-list-types
17290
17291@subsubheading Synopsis
17292
17293@smallexample
17294 -symbol-list-types
17295@end smallexample
17296
17297List all the type names.
17298
17299@subsubheading @value{GDBN} Command
17300
17301The corresponding commands are @samp{info types} in @value{GDBN},
17302@samp{gdb_search} in @code{gdbtk}.
17303
17304@subsubheading Example
17305N.A.
17306
17307
17308@subheading The @code{-symbol-list-variables} Command
17309@findex -symbol-list-variables
17310
17311@subsubheading Synopsis
17312
17313@smallexample
17314 -symbol-list-variables
17315@end smallexample
17316
17317List all the global and static variable names.
17318
17319@subsubheading @value{GDBN} Command
17320
17321@samp{info variables} in @value{GDBN}, @samp{gdb_search} in @code{gdbtk}.
17322
17323@subsubheading Example
17324N.A.
17325
17326
17327@subheading The @code{-symbol-locate} Command
17328@findex -symbol-locate
17329
17330@subsubheading Synopsis
17331
17332@smallexample
17333 -symbol-locate
17334@end smallexample
17335
17336@subsubheading @value{GDBN} Command
17337
17338@samp{gdb_loc} in @code{gdbtk}.
17339
17340@subsubheading Example
17341N.A.
17342
17343
17344@subheading The @code{-symbol-type} Command
17345@findex -symbol-type
17346
17347@subsubheading Synopsis
17348
17349@smallexample
17350 -symbol-type @var{variable}
17351@end smallexample
17352
17353Show type of @var{variable}.
17354
17355@subsubheading @value{GDBN} Command
17356
17357The corresponding @value{GDBN} command is @samp{ptype}, @code{gdbtk} has
17358@samp{gdb_obj_variable}.
17359
17360@subsubheading Example
17361N.A.
17362
17363
17364@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
17365@node GDB/MI Target Manipulation
17366@section @sc{gdb/mi} Target Manipulation Commands
17367
17368
17369@subheading The @code{-target-attach} Command
17370@findex -target-attach
17371
17372@subsubheading Synopsis
17373
17374@smallexample
17375 -target-attach @var{pid} | @var{file}
17376@end smallexample
17377
17378Attach to a process @var{pid} or a file @var{file} outside of @value{GDBN}.
17379
17380@subsubheading @value{GDBN} command
17381
17382The corresponding @value{GDBN} command is @samp{attach}.
17383
17384@subsubheading Example
17385N.A.
17386
17387
17388@subheading The @code{-target-compare-sections} Command
17389@findex -target-compare-sections
17390
17391@subsubheading Synopsis
17392
17393@smallexample
17394 -target-compare-sections [ @var{section} ]
17395@end smallexample
17396
17397Compare data of section @var{section} on target to the exec file.
17398Without the argument, all sections are compared.
17399
17400@subsubheading @value{GDBN} Command
17401
17402The @value{GDBN} equivalent is @samp{compare-sections}.
17403
17404@subsubheading Example
17405N.A.
17406
17407
17408@subheading The @code{-target-detach} Command
17409@findex -target-detach
17410
17411@subsubheading Synopsis
17412
17413@smallexample
17414 -target-detach
17415@end smallexample
17416
17417Disconnect from the remote target. There's no output.
17418
17419@subsubheading @value{GDBN} command
17420
17421The corresponding @value{GDBN} command is @samp{detach}.
17422
17423@subsubheading Example
17424
17425@smallexample
17426(@value{GDBP})
17427-target-detach
17428^done
17429(@value{GDBP})
17430@end smallexample
17431
17432
07f31aa6
DJ
17433@subheading The @code{-target-disconnect} Command
17434@findex -target-disconnect
17435
17436@subsubheading Synopsis
17437
17438@example
17439 -target-disconnect
17440@end example
17441
17442Disconnect from the remote target. There's no output.
17443
17444@subsubheading @value{GDBN} command
17445
17446The corresponding @value{GDBN} command is @samp{disconnect}.
17447
17448@subsubheading Example
17449
17450@smallexample
17451(@value{GDBP})
17452-target-disconnect
17453^done
17454(@value{GDBP})
17455@end smallexample
17456
17457
922fbb7b
AC
17458@subheading The @code{-target-download} Command
17459@findex -target-download
17460
17461@subsubheading Synopsis
17462
17463@smallexample
17464 -target-download
17465@end smallexample
17466
17467Loads the executable onto the remote target.
17468It prints out an update message every half second, which includes the fields:
17469
17470@table @samp
17471@item section
17472The name of the section.
17473@item section-sent
17474The size of what has been sent so far for that section.
17475@item section-size
17476The size of the section.
17477@item total-sent
17478The total size of what was sent so far (the current and the previous sections).
17479@item total-size
17480The size of the overall executable to download.
17481@end table
17482
17483@noindent
17484Each message is sent as status record (@pxref{GDB/MI Output Syntax, ,
17485@sc{gdb/mi} Output Syntax}).
17486
17487In addition, it prints the name and size of the sections, as they are
17488downloaded. These messages include the following fields:
17489
17490@table @samp
17491@item section
17492The name of the section.
17493@item section-size
17494The size of the section.
17495@item total-size
17496The size of the overall executable to download.
17497@end table
17498
17499@noindent
17500At the end, a summary is printed.
17501
17502@subsubheading @value{GDBN} Command
17503
17504The corresponding @value{GDBN} command is @samp{load}.
17505
17506@subsubheading Example
17507
17508Note: each status message appears on a single line. Here the messages
17509have been broken down so that they can fit onto a page.
17510
17511@smallexample
17512(@value{GDBP})
17513-target-download
17514+download,@{section=".text",section-size="6668",total-size="9880"@}
17515+download,@{section=".text",section-sent="512",section-size="6668",
17516total-sent="512",total-size="9880"@}
17517+download,@{section=".text",section-sent="1024",section-size="6668",
17518total-sent="1024",total-size="9880"@}
17519+download,@{section=".text",section-sent="1536",section-size="6668",
17520total-sent="1536",total-size="9880"@}
17521+download,@{section=".text",section-sent="2048",section-size="6668",
17522total-sent="2048",total-size="9880"@}
17523+download,@{section=".text",section-sent="2560",section-size="6668",
17524total-sent="2560",total-size="9880"@}
17525+download,@{section=".text",section-sent="3072",section-size="6668",
17526total-sent="3072",total-size="9880"@}
17527+download,@{section=".text",section-sent="3584",section-size="6668",
17528total-sent="3584",total-size="9880"@}
17529+download,@{section=".text",section-sent="4096",section-size="6668",
17530total-sent="4096",total-size="9880"@}
17531+download,@{section=".text",section-sent="4608",section-size="6668",
17532total-sent="4608",total-size="9880"@}
17533+download,@{section=".text",section-sent="5120",section-size="6668",
17534total-sent="5120",total-size="9880"@}
17535+download,@{section=".text",section-sent="5632",section-size="6668",
17536total-sent="5632",total-size="9880"@}
17537+download,@{section=".text",section-sent="6144",section-size="6668",
17538total-sent="6144",total-size="9880"@}
17539+download,@{section=".text",section-sent="6656",section-size="6668",
17540total-sent="6656",total-size="9880"@}
17541+download,@{section=".init",section-size="28",total-size="9880"@}
17542+download,@{section=".fini",section-size="28",total-size="9880"@}
17543+download,@{section=".data",section-size="3156",total-size="9880"@}
17544+download,@{section=".data",section-sent="512",section-size="3156",
17545total-sent="7236",total-size="9880"@}
17546+download,@{section=".data",section-sent="1024",section-size="3156",
17547total-sent="7748",total-size="9880"@}
17548+download,@{section=".data",section-sent="1536",section-size="3156",
17549total-sent="8260",total-size="9880"@}
17550+download,@{section=".data",section-sent="2048",section-size="3156",
17551total-sent="8772",total-size="9880"@}
17552+download,@{section=".data",section-sent="2560",section-size="3156",
17553total-sent="9284",total-size="9880"@}
17554+download,@{section=".data",section-sent="3072",section-size="3156",
17555total-sent="9796",total-size="9880"@}
17556^done,address="0x10004",load-size="9880",transfer-rate="6586",
17557write-rate="429"
17558(@value{GDBP})
17559@end smallexample
17560
17561
17562@subheading The @code{-target-exec-status} Command
17563@findex -target-exec-status
17564
17565@subsubheading Synopsis
17566
17567@smallexample
17568 -target-exec-status
17569@end smallexample
17570
17571Provide information on the state of the target (whether it is running or
17572not, for instance).
17573
17574@subsubheading @value{GDBN} Command
17575
17576There's no equivalent @value{GDBN} command.
17577
17578@subsubheading Example
17579N.A.
17580
17581
17582@subheading The @code{-target-list-available-targets} Command
17583@findex -target-list-available-targets
17584
17585@subsubheading Synopsis
17586
17587@smallexample
17588 -target-list-available-targets
17589@end smallexample
17590
17591List the possible targets to connect to.
17592
17593@subsubheading @value{GDBN} Command
17594
17595The corresponding @value{GDBN} command is @samp{help target}.
17596
17597@subsubheading Example
17598N.A.
17599
17600
17601@subheading The @code{-target-list-current-targets} Command
17602@findex -target-list-current-targets
17603
17604@subsubheading Synopsis
17605
17606@smallexample
17607 -target-list-current-targets
17608@end smallexample
17609
17610Describe the current target.
17611
17612@subsubheading @value{GDBN} Command
17613
17614The corresponding information is printed by @samp{info file} (among
17615other things).
17616
17617@subsubheading Example
17618N.A.
17619
17620
17621@subheading The @code{-target-list-parameters} Command
17622@findex -target-list-parameters
17623
17624@subsubheading Synopsis
17625
17626@smallexample
17627 -target-list-parameters
17628@end smallexample
17629
17630@c ????
17631
17632@subsubheading @value{GDBN} Command
17633
17634No equivalent.
17635
17636@subsubheading Example
17637N.A.
17638
17639
17640@subheading The @code{-target-select} Command
17641@findex -target-select
17642
17643@subsubheading Synopsis
17644
17645@smallexample
17646 -target-select @var{type} @var{parameters @dots{}}
17647@end smallexample
17648
17649Connect @value{GDBN} to the remote target. This command takes two args:
17650
17651@table @samp
17652@item @var{type}
17653The type of target, for instance @samp{async}, @samp{remote}, etc.
17654@item @var{parameters}
17655Device names, host names and the like. @xref{Target Commands, ,
17656Commands for managing targets}, for more details.
17657@end table
17658
17659The output is a connection notification, followed by the address at
17660which the target program is, in the following form:
17661
17662@smallexample
17663^connected,addr="@var{address}",func="@var{function name}",
17664 args=[@var{arg list}]
17665@end smallexample
17666
17667@subsubheading @value{GDBN} Command
17668
17669The corresponding @value{GDBN} command is @samp{target}.
17670
17671@subsubheading Example
17672
17673@smallexample
17674(@value{GDBP})
17675-target-select async /dev/ttya
17676^connected,addr="0xfe00a300",func="??",args=[]
17677(@value{GDBP})
17678@end smallexample
17679
17680@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
17681@node GDB/MI Thread Commands
17682@section @sc{gdb/mi} Thread Commands
17683
17684
17685@subheading The @code{-thread-info} Command
17686@findex -thread-info
17687
17688@subsubheading Synopsis
17689
17690@smallexample
17691 -thread-info
17692@end smallexample
17693
17694@subsubheading @value{GDBN} command
17695
17696No equivalent.
17697
17698@subsubheading Example
17699N.A.
17700
17701
17702@subheading The @code{-thread-list-all-threads} Command
17703@findex -thread-list-all-threads
17704
17705@subsubheading Synopsis
17706
17707@smallexample
17708 -thread-list-all-threads
17709@end smallexample
17710
17711@subsubheading @value{GDBN} Command
17712
17713The equivalent @value{GDBN} command is @samp{info threads}.
17714
17715@subsubheading Example
17716N.A.
17717
17718
17719@subheading The @code{-thread-list-ids} Command
17720@findex -thread-list-ids
17721
17722@subsubheading Synopsis
17723
17724@smallexample
17725 -thread-list-ids
17726@end smallexample
17727
17728Produces a list of the currently known @value{GDBN} thread ids. At the
17729end of the list it also prints the total number of such threads.
17730
17731@subsubheading @value{GDBN} Command
17732
17733Part of @samp{info threads} supplies the same information.
17734
17735@subsubheading Example
17736
17737No threads present, besides the main process:
17738
17739@smallexample
17740(@value{GDBP})
17741-thread-list-ids
17742^done,thread-ids=@{@},number-of-threads="0"
17743(@value{GDBP})
17744@end smallexample
17745
17746
17747Several threads:
17748
17749@smallexample
17750(@value{GDBP})
17751-thread-list-ids
17752^done,thread-ids=@{thread-id="3",thread-id="2",thread-id="1"@},
17753number-of-threads="3"
17754(@value{GDBP})
17755@end smallexample
17756
17757
17758@subheading The @code{-thread-select} Command
17759@findex -thread-select
17760
17761@subsubheading Synopsis
17762
17763@smallexample
17764 -thread-select @var{threadnum}
17765@end smallexample
17766
17767Make @var{threadnum} the current thread. It prints the number of the new
17768current thread, and the topmost frame for that thread.
17769
17770@subsubheading @value{GDBN} Command
17771
17772The corresponding @value{GDBN} command is @samp{thread}.
17773
17774@subsubheading Example
17775
17776@smallexample
17777(@value{GDBP})
17778-exec-next
17779^running
17780(@value{GDBP})
17781*stopped,reason="end-stepping-range",thread-id="2",line="187",
17782file="../../../devo/gdb/testsuite/gdb.threads/linux-dp.c"
17783(@value{GDBP})
17784-thread-list-ids
17785^done,
17786thread-ids=@{thread-id="3",thread-id="2",thread-id="1"@},
17787number-of-threads="3"
17788(@value{GDBP})
17789-thread-select 3
17790^done,new-thread-id="3",
17791frame=@{level="0",func="vprintf",
17792args=[@{name="format",value="0x8048e9c \"%*s%c %d %c\\n\""@},
17793@{name="arg",value="0x2"@}],file="vprintf.c",line="31"@}
17794(@value{GDBP})
17795@end smallexample
17796
17797@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
17798@node GDB/MI Tracepoint Commands
17799@section @sc{gdb/mi} Tracepoint Commands
17800
17801The tracepoint commands are not yet implemented.
17802
17803@c @subheading -trace-actions
17804
17805@c @subheading -trace-delete
17806
17807@c @subheading -trace-disable
17808
17809@c @subheading -trace-dump
17810
17811@c @subheading -trace-enable
17812
17813@c @subheading -trace-exists
17814
17815@c @subheading -trace-find
17816
17817@c @subheading -trace-frame-number
17818
17819@c @subheading -trace-info
17820
17821@c @subheading -trace-insert
17822
17823@c @subheading -trace-list
17824
17825@c @subheading -trace-pass-count
17826
17827@c @subheading -trace-save
17828
17829@c @subheading -trace-start
17830
17831@c @subheading -trace-stop
17832
17833
17834@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
17835@node GDB/MI Variable Objects
17836@section @sc{gdb/mi} Variable Objects
17837
17838
17839@subheading Motivation for Variable Objects in @sc{gdb/mi}
17840
17841For the implementation of a variable debugger window (locals, watched
17842expressions, etc.), we are proposing the adaptation of the existing code
17843used by @code{Insight}.
17844
17845The two main reasons for that are:
17846
17847@enumerate 1
17848@item
17849It has been proven in practice (it is already on its second generation).
17850
17851@item
17852It will shorten development time (needless to say how important it is
17853now).
17854@end enumerate
17855
17856The original interface was designed to be used by Tcl code, so it was
17857slightly changed so it could be used through @sc{gdb/mi}. This section
17858describes the @sc{gdb/mi} operations that will be available and gives some
17859hints about their use.
17860
17861@emph{Note}: In addition to the set of operations described here, we
17862expect the @sc{gui} implementation of a variable window to require, at
17863least, the following operations:
17864
17865@itemize @bullet
17866@item @code{-gdb-show} @code{output-radix}
17867@item @code{-stack-list-arguments}
17868@item @code{-stack-list-locals}
17869@item @code{-stack-select-frame}
17870@end itemize
17871
17872@subheading Introduction to Variable Objects in @sc{gdb/mi}
17873
17874@cindex variable objects in @sc{gdb/mi}
17875The basic idea behind variable objects is the creation of a named object
17876to represent a variable, an expression, a memory location or even a CPU
17877register. For each object created, a set of operations is available for
17878examining or changing its properties.
17879
17880Furthermore, complex data types, such as C structures, are represented
17881in a tree format. For instance, the @code{struct} type variable is the
17882root and the children will represent the struct members. If a child
17883is itself of a complex type, it will also have children of its own.
17884Appropriate language differences are handled for C, C@t{++} and Java.
17885
17886When returning the actual values of the objects, this facility allows
17887for the individual selection of the display format used in the result
17888creation. It can be chosen among: binary, decimal, hexadecimal, octal
17889and natural. Natural refers to a default format automatically
17890chosen based on the variable type (like decimal for an @code{int}, hex
17891for pointers, etc.).
17892
17893The following is the complete set of @sc{gdb/mi} operations defined to
17894access this functionality:
17895
17896@multitable @columnfractions .4 .6
17897@item @strong{Operation}
17898@tab @strong{Description}
17899
17900@item @code{-var-create}
17901@tab create a variable object
17902@item @code{-var-delete}
17903@tab delete the variable object and its children
17904@item @code{-var-set-format}
17905@tab set the display format of this variable
17906@item @code{-var-show-format}
17907@tab show the display format of this variable
17908@item @code{-var-info-num-children}
17909@tab tells how many children this object has
17910@item @code{-var-list-children}
17911@tab return a list of the object's children
17912@item @code{-var-info-type}
17913@tab show the type of this variable object
17914@item @code{-var-info-expression}
17915@tab print what this variable object represents
17916@item @code{-var-show-attributes}
17917@tab is this variable editable? does it exist here?
17918@item @code{-var-evaluate-expression}
17919@tab get the value of this variable
17920@item @code{-var-assign}
17921@tab set the value of this variable
17922@item @code{-var-update}
17923@tab update the variable and its children
17924@end multitable
17925
17926In the next subsection we describe each operation in detail and suggest
17927how it can be used.
17928
17929@subheading Description And Use of Operations on Variable Objects
17930
17931@subheading The @code{-var-create} Command
17932@findex -var-create
17933
17934@subsubheading Synopsis
17935
17936@smallexample
17937 -var-create @{@var{name} | "-"@}
17938 @{@var{frame-addr} | "*"@} @var{expression}
17939@end smallexample
17940
17941This operation creates a variable object, which allows the monitoring of
17942a variable, the result of an expression, a memory cell or a CPU
17943register.
17944
17945The @var{name} parameter is the string by which the object can be
17946referenced. It must be unique. If @samp{-} is specified, the varobj
17947system will generate a string ``varNNNNNN'' automatically. It will be
17948unique provided that one does not specify @var{name} on that format.
17949The command fails if a duplicate name is found.
17950
17951The frame under which the expression should be evaluated can be
17952specified by @var{frame-addr}. A @samp{*} indicates that the current
17953frame should be used.
17954
17955@var{expression} is any expression valid on the current language set (must not
17956begin with a @samp{*}), or one of the following:
17957
17958@itemize @bullet
17959@item
17960@samp{*@var{addr}}, where @var{addr} is the address of a memory cell
17961
17962@item
17963@samp{*@var{addr}-@var{addr}} --- a memory address range (TBD)
17964
17965@item
17966@samp{$@var{regname}} --- a CPU register name
17967@end itemize
17968
17969@subsubheading Result
17970
17971This operation returns the name, number of children and the type of the
17972object created. Type is returned as a string as the ones generated by
17973the @value{GDBN} CLI:
17974
17975@smallexample
17976 name="@var{name}",numchild="N",type="@var{type}"
17977@end smallexample
17978
17979
17980@subheading The @code{-var-delete} Command
17981@findex -var-delete
17982
17983@subsubheading Synopsis
17984
17985@smallexample
17986 -var-delete @var{name}
17987@end smallexample
17988
17989Deletes a previously created variable object and all of its children.
17990
17991Returns an error if the object @var{name} is not found.
17992
17993
17994@subheading The @code{-var-set-format} Command
17995@findex -var-set-format
17996
17997@subsubheading Synopsis
17998
17999@smallexample
18000 -var-set-format @var{name} @var{format-spec}
18001@end smallexample
18002
18003Sets the output format for the value of the object @var{name} to be
18004@var{format-spec}.
18005
18006The syntax for the @var{format-spec} is as follows:
18007
18008@smallexample
18009 @var{format-spec} @expansion{}
18010 @{binary | decimal | hexadecimal | octal | natural@}
18011@end smallexample
18012
18013
18014@subheading The @code{-var-show-format} Command
18015@findex -var-show-format
18016
18017@subsubheading Synopsis
18018
18019@smallexample
18020 -var-show-format @var{name}
18021@end smallexample
18022
18023Returns the format used to display the value of the object @var{name}.
18024
18025@smallexample
18026 @var{format} @expansion{}
18027 @var{format-spec}
18028@end smallexample
18029
18030
18031@subheading The @code{-var-info-num-children} Command
18032@findex -var-info-num-children
18033
18034@subsubheading Synopsis
18035
18036@smallexample
18037 -var-info-num-children @var{name}
18038@end smallexample
18039
18040Returns the number of children of a variable object @var{name}:
18041
18042@smallexample
18043 numchild=@var{n}
18044@end smallexample
18045
18046
18047@subheading The @code{-var-list-children} Command
18048@findex -var-list-children
18049
18050@subsubheading Synopsis
18051
18052@smallexample
18053 -var-list-children @var{name}
18054@end smallexample
18055
18056Returns a list of the children of the specified variable object:
18057
18058@smallexample
18059 numchild=@var{n},children=[@{name=@var{name},
18060 numchild=@var{n},type=@var{type}@},@r{(repeats N times)}]
18061@end smallexample
18062
18063
18064@subheading The @code{-var-info-type} Command
18065@findex -var-info-type
18066
18067@subsubheading Synopsis
18068
18069@smallexample
18070 -var-info-type @var{name}
18071@end smallexample
18072
18073Returns the type of the specified variable @var{name}. The type is
18074returned as a string in the same format as it is output by the
18075@value{GDBN} CLI:
18076
18077@smallexample
18078 type=@var{typename}
18079@end smallexample
18080
18081
18082@subheading The @code{-var-info-expression} Command
18083@findex -var-info-expression
18084
18085@subsubheading Synopsis
18086
18087@smallexample
18088 -var-info-expression @var{name}
18089@end smallexample
18090
18091Returns what is represented by the variable object @var{name}:
18092
18093@smallexample
18094 lang=@var{lang-spec},exp=@var{expression}
18095@end smallexample
18096
18097@noindent
18098where @var{lang-spec} is @code{@{"C" | "C++" | "Java"@}}.
18099
18100@subheading The @code{-var-show-attributes} Command
18101@findex -var-show-attributes
18102
18103@subsubheading Synopsis
18104
18105@smallexample
18106 -var-show-attributes @var{name}
18107@end smallexample
18108
18109List attributes of the specified variable object @var{name}:
18110
18111@smallexample
18112 status=@var{attr} [ ( ,@var{attr} )* ]
18113@end smallexample
18114
18115@noindent
18116where @var{attr} is @code{@{ @{ editable | noneditable @} | TBD @}}.
18117
18118@subheading The @code{-var-evaluate-expression} Command
18119@findex -var-evaluate-expression
18120
18121@subsubheading Synopsis
18122
18123@smallexample
18124 -var-evaluate-expression @var{name}
18125@end smallexample
18126
18127Evaluates the expression that is represented by the specified variable
18128object and returns its value as a string in the current format specified
18129for the object:
18130
18131@smallexample
18132 value=@var{value}
18133@end smallexample
18134
18135Note that one must invoke @code{-var-list-children} for a variable
18136before the value of a child variable can be evaluated.
18137
18138@subheading The @code{-var-assign} Command
18139@findex -var-assign
18140
18141@subsubheading Synopsis
18142
18143@smallexample
18144 -var-assign @var{name} @var{expression}
18145@end smallexample
18146
18147Assigns the value of @var{expression} to the variable object specified
18148by @var{name}. The object must be @samp{editable}. If the variable's
18149value is altered by the assign, the variable will show up in any
18150subsequent @code{-var-update} list.
18151
18152@subsubheading Example
18153
18154@smallexample
18155(@value{GDBP})
18156-var-assign var1 3
18157^done,value="3"
18158(@value{GDBP})
18159-var-update *
18160^done,changelist=[@{name="var1",in_scope="true",type_changed="false"@}]
18161(@value{GDBP})
18162@end smallexample
18163
18164@subheading The @code{-var-update} Command
18165@findex -var-update
18166
18167@subsubheading Synopsis
18168
18169@smallexample
18170 -var-update @{@var{name} | "*"@}
18171@end smallexample
18172
18173Update the value of the variable object @var{name} by evaluating its
18174expression after fetching all the new values from memory or registers.
18175A @samp{*} causes all existing variable objects to be updated.
18176
18177
18178@node Annotations
18179@chapter @value{GDBN} Annotations
18180
086432e2
AC
18181This chapter describes annotations in @value{GDBN}. Annotations were
18182designed to interface @value{GDBN} to graphical user interfaces or other
18183similar programs which want to interact with @value{GDBN} at a
922fbb7b
AC
18184relatively high level.
18185
086432e2
AC
18186The annotation mechanism has largely been superseeded by @sc{gdb/mi}
18187(@pxref{GDB/MI}).
18188
922fbb7b
AC
18189@ignore
18190This is Edition @value{EDITION}, @value{DATE}.
18191@end ignore
18192
18193@menu
18194* Annotations Overview:: What annotations are; the general syntax.
18195* Server Prefix:: Issuing a command without affecting user state.
922fbb7b
AC
18196* Prompting:: Annotations marking @value{GDBN}'s need for input.
18197* Errors:: Annotations for error messages.
922fbb7b
AC
18198* Invalidation:: Some annotations describe things now invalid.
18199* Annotations for Running::
18200 Whether the program is running, how it stopped, etc.
18201* Source Annotations:: Annotations describing source code.
922fbb7b
AC
18202@end menu
18203
18204@node Annotations Overview
18205@section What is an Annotation?
18206@cindex annotations
18207
922fbb7b
AC
18208Annotations start with a newline character, two @samp{control-z}
18209characters, and the name of the annotation. If there is no additional
18210information associated with this annotation, the name of the annotation
18211is followed immediately by a newline. If there is additional
18212information, the name of the annotation is followed by a space, the
18213additional information, and a newline. The additional information
18214cannot contain newline characters.
18215
18216Any output not beginning with a newline and two @samp{control-z}
18217characters denotes literal output from @value{GDBN}. Currently there is
18218no need for @value{GDBN} to output a newline followed by two
18219@samp{control-z} characters, but if there was such a need, the
18220annotations could be extended with an @samp{escape} annotation which
18221means those three characters as output.
18222
086432e2
AC
18223The annotation @var{level}, which is specified using the
18224@option{--annotate} command line option (@pxref{Mode Options}), controls
18225how much information @value{GDBN} prints together with its prompt,
18226values of expressions, source lines, and other types of output. Level 0
18227is for no anntations, level 1 is for use when @value{GDBN} is run as a
18228subprocess of @sc{gnu} Emacs, level 3 is the maximum annotation suitable
18229for programs that control @value{GDBN}, and level 2 annotations have
18230been made obsolete (@pxref{Limitations, , Limitations of the Annotation
18231Interface, annotate, GDB's Obsolete Annotations}). This chapter
18232describes level 3 annotations.
18233
922fbb7b
AC
18234A simple example of starting up @value{GDBN} with annotations is:
18235
18236@smallexample
086432e2
AC
18237$ @kbd{gdb --annotate=3}
18238GNU gdb 6.0
18239Copyright 2003 Free Software Foundation, Inc.
922fbb7b
AC
18240GDB is free software, covered by the GNU General Public License,
18241and you are welcome to change it and/or distribute copies of it
18242under certain conditions.
18243Type "show copying" to see the conditions.
18244There is absolutely no warranty for GDB. Type "show warranty"
18245for details.
086432e2 18246This GDB was configured as "i386-pc-linux-gnu"
922fbb7b
AC
18247
18248^Z^Zpre-prompt
18249(gdb)
18250^Z^Zprompt
086432e2 18251@kbd{quit}
922fbb7b
AC
18252
18253^Z^Zpost-prompt
18254$
18255@end smallexample
18256
18257Here @samp{quit} is input to @value{GDBN}; the rest is output from
18258@value{GDBN}. The three lines beginning @samp{^Z^Z} (where @samp{^Z}
18259denotes a @samp{control-z} character) are annotations; the rest is
18260output from @value{GDBN}.
18261
18262@node Server Prefix
18263@section The Server Prefix
18264@cindex server prefix for annotations
18265
18266To issue a command to @value{GDBN} without affecting certain aspects of
18267the state which is seen by users, prefix it with @samp{server }. This
18268means that this command will not affect the command history, nor will it
18269affect @value{GDBN}'s notion of which command to repeat if @key{RET} is
18270pressed on a line by itself.
18271
18272The server prefix does not affect the recording of values into the value
18273history; to print a value without recording it into the value history,
18274use the @code{output} command instead of the @code{print} command.
18275
922fbb7b
AC
18276@node Prompting
18277@section Annotation for @value{GDBN} Input
18278
18279@cindex annotations for prompts
18280When @value{GDBN} prompts for input, it annotates this fact so it is possible
18281to know when to send output, when the output from a given command is
18282over, etc.
18283
18284Different kinds of input each have a different @dfn{input type}. Each
18285input type has three annotations: a @code{pre-} annotation, which
18286denotes the beginning of any prompt which is being output, a plain
18287annotation, which denotes the end of the prompt, and then a @code{post-}
18288annotation which denotes the end of any echo which may (or may not) be
18289associated with the input. For example, the @code{prompt} input type
18290features the following annotations:
18291
18292@smallexample
18293^Z^Zpre-prompt
18294^Z^Zprompt
18295^Z^Zpost-prompt
18296@end smallexample
18297
18298The input types are
18299
18300@table @code
18301@findex pre-prompt
18302@findex prompt
18303@findex post-prompt
18304@item prompt
18305When @value{GDBN} is prompting for a command (the main @value{GDBN} prompt).
18306
18307@findex pre-commands
18308@findex commands
18309@findex post-commands
18310@item commands
18311When @value{GDBN} prompts for a set of commands, like in the @code{commands}
18312command. The annotations are repeated for each command which is input.
18313
18314@findex pre-overload-choice
18315@findex overload-choice
18316@findex post-overload-choice
18317@item overload-choice
18318When @value{GDBN} wants the user to select between various overloaded functions.
18319
18320@findex pre-query
18321@findex query
18322@findex post-query
18323@item query
18324When @value{GDBN} wants the user to confirm a potentially dangerous operation.
18325
18326@findex pre-prompt-for-continue
18327@findex prompt-for-continue
18328@findex post-prompt-for-continue
18329@item prompt-for-continue
18330When @value{GDBN} is asking the user to press return to continue. Note: Don't
18331expect this to work well; instead use @code{set height 0} to disable
18332prompting. This is because the counting of lines is buggy in the
18333presence of annotations.
18334@end table
18335
18336@node Errors
18337@section Errors
18338@cindex annotations for errors, warnings and interrupts
18339
18340@findex quit
18341@smallexample
18342^Z^Zquit
18343@end smallexample
18344
18345This annotation occurs right before @value{GDBN} responds to an interrupt.
18346
18347@findex error
18348@smallexample
18349^Z^Zerror
18350@end smallexample
18351
18352This annotation occurs right before @value{GDBN} responds to an error.
18353
18354Quit and error annotations indicate that any annotations which @value{GDBN} was
18355in the middle of may end abruptly. For example, if a
18356@code{value-history-begin} annotation is followed by a @code{error}, one
18357cannot expect to receive the matching @code{value-history-end}. One
18358cannot expect not to receive it either, however; an error annotation
18359does not necessarily mean that @value{GDBN} is immediately returning all the way
18360to the top level.
18361
18362@findex error-begin
18363A quit or error annotation may be preceded by
18364
18365@smallexample
18366^Z^Zerror-begin
18367@end smallexample
18368
18369Any output between that and the quit or error annotation is the error
18370message.
18371
18372Warning messages are not yet annotated.
18373@c If we want to change that, need to fix warning(), type_error(),
18374@c range_error(), and possibly other places.
18375
922fbb7b
AC
18376@node Invalidation
18377@section Invalidation Notices
18378
18379@cindex annotations for invalidation messages
18380The following annotations say that certain pieces of state may have
18381changed.
18382
18383@table @code
18384@findex frames-invalid
18385@item ^Z^Zframes-invalid
18386
18387The frames (for example, output from the @code{backtrace} command) may
18388have changed.
18389
18390@findex breakpoints-invalid
18391@item ^Z^Zbreakpoints-invalid
18392
18393The breakpoints may have changed. For example, the user just added or
18394deleted a breakpoint.
18395@end table
18396
18397@node Annotations for Running
18398@section Running the Program
18399@cindex annotations for running programs
18400
18401@findex starting
18402@findex stopping
18403When the program starts executing due to a @value{GDBN} command such as
18404@code{step} or @code{continue},
18405
18406@smallexample
18407^Z^Zstarting
18408@end smallexample
18409
18410is output. When the program stops,
18411
18412@smallexample
18413^Z^Zstopped
18414@end smallexample
18415
18416is output. Before the @code{stopped} annotation, a variety of
18417annotations describe how the program stopped.
18418
18419@table @code
18420@findex exited
18421@item ^Z^Zexited @var{exit-status}
18422The program exited, and @var{exit-status} is the exit status (zero for
18423successful exit, otherwise nonzero).
18424
18425@findex signalled
18426@findex signal-name
18427@findex signal-name-end
18428@findex signal-string
18429@findex signal-string-end
18430@item ^Z^Zsignalled
18431The program exited with a signal. After the @code{^Z^Zsignalled}, the
18432annotation continues:
18433
18434@smallexample
18435@var{intro-text}
18436^Z^Zsignal-name
18437@var{name}
18438^Z^Zsignal-name-end
18439@var{middle-text}
18440^Z^Zsignal-string
18441@var{string}
18442^Z^Zsignal-string-end
18443@var{end-text}
18444@end smallexample
18445
18446@noindent
18447where @var{name} is the name of the signal, such as @code{SIGILL} or
18448@code{SIGSEGV}, and @var{string} is the explanation of the signal, such
18449as @code{Illegal Instruction} or @code{Segmentation fault}.
18450@var{intro-text}, @var{middle-text}, and @var{end-text} are for the
18451user's benefit and have no particular format.
18452
18453@findex signal
18454@item ^Z^Zsignal
18455The syntax of this annotation is just like @code{signalled}, but @value{GDBN} is
18456just saying that the program received the signal, not that it was
18457terminated with it.
18458
18459@findex breakpoint
18460@item ^Z^Zbreakpoint @var{number}
18461The program hit breakpoint number @var{number}.
18462
18463@findex watchpoint
18464@item ^Z^Zwatchpoint @var{number}
18465The program hit watchpoint number @var{number}.
18466@end table
18467
18468@node Source Annotations
18469@section Displaying Source
18470@cindex annotations for source display
18471
18472@findex source
18473The following annotation is used instead of displaying source code:
18474
18475@smallexample
18476^Z^Zsource @var{filename}:@var{line}:@var{character}:@var{middle}:@var{addr}
18477@end smallexample
18478
18479where @var{filename} is an absolute file name indicating which source
18480file, @var{line} is the line number within that file (where 1 is the
18481first line in the file), @var{character} is the character position
18482within the file (where 0 is the first character in the file) (for most
18483debug formats this will necessarily point to the beginning of a line),
18484@var{middle} is @samp{middle} if @var{addr} is in the middle of the
18485line, or @samp{beg} if @var{addr} is at the beginning of the line, and
18486@var{addr} is the address in the target program associated with the
18487source which is being displayed. @var{addr} is in the form @samp{0x}
18488followed by one or more lowercase hex digits (note that this does not
18489depend on the language).
18490
8e04817f
AC
18491@node GDB Bugs
18492@chapter Reporting Bugs in @value{GDBN}
18493@cindex bugs in @value{GDBN}
18494@cindex reporting bugs in @value{GDBN}
c906108c 18495
8e04817f 18496Your bug reports play an essential role in making @value{GDBN} reliable.
c906108c 18497
8e04817f
AC
18498Reporting a bug may help you by bringing a solution to your problem, or it
18499may not. But in any case the principal function of a bug report is to help
18500the entire community by making the next version of @value{GDBN} work better. Bug
18501reports are your contribution to the maintenance of @value{GDBN}.
c906108c 18502
8e04817f
AC
18503In order for a bug report to serve its purpose, you must include the
18504information that enables us to fix the bug.
c4555f82
SC
18505
18506@menu
8e04817f
AC
18507* Bug Criteria:: Have you found a bug?
18508* Bug Reporting:: How to report bugs
c4555f82
SC
18509@end menu
18510
8e04817f
AC
18511@node Bug Criteria
18512@section Have you found a bug?
18513@cindex bug criteria
c4555f82 18514
8e04817f 18515If you are not sure whether you have found a bug, here are some guidelines:
c4555f82
SC
18516
18517@itemize @bullet
8e04817f
AC
18518@cindex fatal signal
18519@cindex debugger crash
18520@cindex crash of debugger
c4555f82 18521@item
8e04817f
AC
18522If the debugger gets a fatal signal, for any input whatever, that is a
18523@value{GDBN} bug. Reliable debuggers never crash.
18524
18525@cindex error on valid input
18526@item
18527If @value{GDBN} produces an error message for valid input, that is a
18528bug. (Note that if you're cross debugging, the problem may also be
18529somewhere in the connection to the target.)
c4555f82 18530
8e04817f 18531@cindex invalid input
c4555f82 18532@item
8e04817f
AC
18533If @value{GDBN} does not produce an error message for invalid input,
18534that is a bug. However, you should note that your idea of
18535``invalid input'' might be our idea of ``an extension'' or ``support
18536for traditional practice''.
18537
18538@item
18539If you are an experienced user of debugging tools, your suggestions
18540for improvement of @value{GDBN} are welcome in any case.
c4555f82
SC
18541@end itemize
18542
8e04817f
AC
18543@node Bug Reporting
18544@section How to report bugs
18545@cindex bug reports
18546@cindex @value{GDBN} bugs, reporting
18547
18548A number of companies and individuals offer support for @sc{gnu} products.
18549If you obtained @value{GDBN} from a support organization, we recommend you
18550contact that organization first.
18551
18552You can find contact information for many support companies and
18553individuals in the file @file{etc/SERVICE} in the @sc{gnu} Emacs
18554distribution.
18555@c should add a web page ref...
18556
129188f6
AC
18557In any event, we also recommend that you submit bug reports for
18558@value{GDBN}. The prefered method is to submit them directly using
18559@uref{http://www.gnu.org/software/gdb/bugs/, @value{GDBN}'s Bugs web
18560page}. Alternatively, the @email{bug-gdb@@gnu.org, e-mail gateway} can
18561be used.
8e04817f
AC
18562
18563@strong{Do not send bug reports to @samp{info-gdb}, or to
18564@samp{help-gdb}, or to any newsgroups.} Most users of @value{GDBN} do
18565not want to receive bug reports. Those that do have arranged to receive
18566@samp{bug-gdb}.
18567
18568The mailing list @samp{bug-gdb} has a newsgroup @samp{gnu.gdb.bug} which
18569serves as a repeater. The mailing list and the newsgroup carry exactly
18570the same messages. Often people think of posting bug reports to the
18571newsgroup instead of mailing them. This appears to work, but it has one
18572problem which can be crucial: a newsgroup posting often lacks a mail
18573path back to the sender. Thus, if we need to ask for more information,
18574we may be unable to reach you. For this reason, it is better to send
18575bug reports to the mailing list.
c4555f82 18576
8e04817f
AC
18577The fundamental principle of reporting bugs usefully is this:
18578@strong{report all the facts}. If you are not sure whether to state a
18579fact or leave it out, state it!
c4555f82 18580
8e04817f
AC
18581Often people omit facts because they think they know what causes the
18582problem and assume that some details do not matter. Thus, you might
18583assume that the name of the variable you use in an example does not matter.
18584Well, probably it does not, but one cannot be sure. Perhaps the bug is a
18585stray memory reference which happens to fetch from the location where that
18586name is stored in memory; perhaps, if the name were different, the contents
18587of that location would fool the debugger into doing the right thing despite
18588the bug. Play it safe and give a specific, complete example. That is the
18589easiest thing for you to do, and the most helpful.
c4555f82 18590
8e04817f
AC
18591Keep in mind that the purpose of a bug report is to enable us to fix the
18592bug. It may be that the bug has been reported previously, but neither
18593you nor we can know that unless your bug report is complete and
18594self-contained.
c4555f82 18595
8e04817f
AC
18596Sometimes people give a few sketchy facts and ask, ``Does this ring a
18597bell?'' Those bug reports are useless, and we urge everyone to
18598@emph{refuse to respond to them} except to chide the sender to report
18599bugs properly.
18600
18601To enable us to fix the bug, you should include all these things:
c4555f82
SC
18602
18603@itemize @bullet
18604@item
8e04817f
AC
18605The version of @value{GDBN}. @value{GDBN} announces it if you start
18606with no arguments; you can also print it at any time using @code{show
18607version}.
c4555f82 18608
8e04817f
AC
18609Without this, we will not know whether there is any point in looking for
18610the bug in the current version of @value{GDBN}.
c4555f82
SC
18611
18612@item
8e04817f
AC
18613The type of machine you are using, and the operating system name and
18614version number.
c4555f82
SC
18615
18616@item
8e04817f
AC
18617What compiler (and its version) was used to compile @value{GDBN}---e.g.
18618``@value{GCC}--2.8.1''.
c4555f82
SC
18619
18620@item
8e04817f
AC
18621What compiler (and its version) was used to compile the program you are
18622debugging---e.g. ``@value{GCC}--2.8.1'', or ``HP92453-01 A.10.32.03 HP
18623C Compiler''. For GCC, you can say @code{gcc --version} to get this
18624information; for other compilers, see the documentation for those
18625compilers.
c4555f82 18626
8e04817f
AC
18627@item
18628The command arguments you gave the compiler to compile your example and
18629observe the bug. For example, did you use @samp{-O}? To guarantee
18630you will not omit something important, list them all. A copy of the
18631Makefile (or the output from make) is sufficient.
c4555f82 18632
8e04817f
AC
18633If we were to try to guess the arguments, we would probably guess wrong
18634and then we might not encounter the bug.
c4555f82 18635
8e04817f
AC
18636@item
18637A complete input script, and all necessary source files, that will
18638reproduce the bug.
c4555f82 18639
8e04817f
AC
18640@item
18641A description of what behavior you observe that you believe is
18642incorrect. For example, ``It gets a fatal signal.''
c4555f82 18643
8e04817f
AC
18644Of course, if the bug is that @value{GDBN} gets a fatal signal, then we
18645will certainly notice it. But if the bug is incorrect output, we might
18646not notice unless it is glaringly wrong. You might as well not give us
18647a chance to make a mistake.
c4555f82 18648
8e04817f
AC
18649Even if the problem you experience is a fatal signal, you should still
18650say so explicitly. Suppose something strange is going on, such as, your
18651copy of @value{GDBN} is out of synch, or you have encountered a bug in
18652the C library on your system. (This has happened!) Your copy might
18653crash and ours would not. If you told us to expect a crash, then when
18654ours fails to crash, we would know that the bug was not happening for
18655us. If you had not told us to expect a crash, then we would not be able
18656to draw any conclusion from our observations.
c4555f82 18657
8e04817f
AC
18658@item
18659If you wish to suggest changes to the @value{GDBN} source, send us context
18660diffs. If you even discuss something in the @value{GDBN} source, refer to
18661it by context, not by line number.
c4555f82 18662
8e04817f
AC
18663The line numbers in our development sources will not match those in your
18664sources. Your line numbers would convey no useful information to us.
c4555f82 18665
8e04817f 18666@end itemize
c4555f82 18667
8e04817f 18668Here are some things that are not necessary:
c4555f82 18669
8e04817f
AC
18670@itemize @bullet
18671@item
18672A description of the envelope of the bug.
c4555f82 18673
8e04817f
AC
18674Often people who encounter a bug spend a lot of time investigating
18675which changes to the input file will make the bug go away and which
18676changes will not affect it.
c4555f82 18677
8e04817f
AC
18678This is often time consuming and not very useful, because the way we
18679will find the bug is by running a single example under the debugger
18680with breakpoints, not by pure deduction from a series of examples.
18681We recommend that you save your time for something else.
c4555f82 18682
8e04817f
AC
18683Of course, if you can find a simpler example to report @emph{instead}
18684of the original one, that is a convenience for us. Errors in the
18685output will be easier to spot, running under the debugger will take
18686less time, and so on.
c4555f82 18687
8e04817f
AC
18688However, simplification is not vital; if you do not want to do this,
18689report the bug anyway and send us the entire test case you used.
c4555f82 18690
8e04817f
AC
18691@item
18692A patch for the bug.
c4555f82 18693
8e04817f
AC
18694A patch for the bug does help us if it is a good one. But do not omit
18695the necessary information, such as the test case, on the assumption that
18696a patch is all we need. We might see problems with your patch and decide
18697to fix the problem another way, or we might not understand it at all.
c4555f82 18698
8e04817f
AC
18699Sometimes with a program as complicated as @value{GDBN} it is very hard to
18700construct an example that will make the program follow a certain path
18701through the code. If you do not send us the example, we will not be able
18702to construct one, so we will not be able to verify that the bug is fixed.
c4555f82 18703
8e04817f
AC
18704And if we cannot understand what bug you are trying to fix, or why your
18705patch should be an improvement, we will not install it. A test case will
18706help us to understand.
c4555f82 18707
8e04817f
AC
18708@item
18709A guess about what the bug is or what it depends on.
c4555f82 18710
8e04817f
AC
18711Such guesses are usually wrong. Even we cannot guess right about such
18712things without first using the debugger to find the facts.
18713@end itemize
c4555f82 18714
8e04817f
AC
18715@c The readline documentation is distributed with the readline code
18716@c and consists of the two following files:
18717@c rluser.texinfo
18718@c inc-hist.texinfo
18719@c Use -I with makeinfo to point to the appropriate directory,
18720@c environment var TEXINPUTS with TeX.
18721@include rluser.texinfo
18722@include inc-hist.texinfo
c4555f82 18723
c4555f82 18724
8e04817f
AC
18725@node Formatting Documentation
18726@appendix Formatting Documentation
c4555f82 18727
8e04817f
AC
18728@cindex @value{GDBN} reference card
18729@cindex reference card
18730The @value{GDBN} 4 release includes an already-formatted reference card, ready
18731for printing with PostScript or Ghostscript, in the @file{gdb}
18732subdirectory of the main source directory@footnote{In
18733@file{gdb-@value{GDBVN}/gdb/refcard.ps} of the version @value{GDBVN}
18734release.}. If you can use PostScript or Ghostscript with your printer,
18735you can print the reference card immediately with @file{refcard.ps}.
c4555f82 18736
8e04817f
AC
18737The release also includes the source for the reference card. You
18738can format it, using @TeX{}, by typing:
c4555f82 18739
474c8240 18740@smallexample
8e04817f 18741make refcard.dvi
474c8240 18742@end smallexample
c4555f82 18743
8e04817f
AC
18744The @value{GDBN} reference card is designed to print in @dfn{landscape}
18745mode on US ``letter'' size paper;
18746that is, on a sheet 11 inches wide by 8.5 inches
18747high. You will need to specify this form of printing as an option to
18748your @sc{dvi} output program.
c4555f82 18749
8e04817f 18750@cindex documentation
c4555f82 18751
8e04817f
AC
18752All the documentation for @value{GDBN} comes as part of the machine-readable
18753distribution. The documentation is written in Texinfo format, which is
18754a documentation system that uses a single source file to produce both
18755on-line information and a printed manual. You can use one of the Info
18756formatting commands to create the on-line version of the documentation
18757and @TeX{} (or @code{texi2roff}) to typeset the printed version.
c4555f82 18758
8e04817f
AC
18759@value{GDBN} includes an already formatted copy of the on-line Info
18760version of this manual in the @file{gdb} subdirectory. The main Info
18761file is @file{gdb-@value{GDBVN}/gdb/gdb.info}, and it refers to
18762subordinate files matching @samp{gdb.info*} in the same directory. If
18763necessary, you can print out these files, or read them with any editor;
18764but they are easier to read using the @code{info} subsystem in @sc{gnu}
18765Emacs or the standalone @code{info} program, available as part of the
18766@sc{gnu} Texinfo distribution.
c4555f82 18767
8e04817f
AC
18768If you want to format these Info files yourself, you need one of the
18769Info formatting programs, such as @code{texinfo-format-buffer} or
18770@code{makeinfo}.
c4555f82 18771
8e04817f
AC
18772If you have @code{makeinfo} installed, and are in the top level
18773@value{GDBN} source directory (@file{gdb-@value{GDBVN}}, in the case of
18774version @value{GDBVN}), you can make the Info file by typing:
c4555f82 18775
474c8240 18776@smallexample
8e04817f
AC
18777cd gdb
18778make gdb.info
474c8240 18779@end smallexample
c4555f82 18780
8e04817f
AC
18781If you want to typeset and print copies of this manual, you need @TeX{},
18782a program to print its @sc{dvi} output files, and @file{texinfo.tex}, the
18783Texinfo definitions file.
c4555f82 18784
8e04817f
AC
18785@TeX{} is a typesetting program; it does not print files directly, but
18786produces output files called @sc{dvi} files. To print a typeset
18787document, you need a program to print @sc{dvi} files. If your system
18788has @TeX{} installed, chances are it has such a program. The precise
18789command to use depends on your system; @kbd{lpr -d} is common; another
18790(for PostScript devices) is @kbd{dvips}. The @sc{dvi} print command may
18791require a file name without any extension or a @samp{.dvi} extension.
c4555f82 18792
8e04817f
AC
18793@TeX{} also requires a macro definitions file called
18794@file{texinfo.tex}. This file tells @TeX{} how to typeset a document
18795written in Texinfo format. On its own, @TeX{} cannot either read or
18796typeset a Texinfo file. @file{texinfo.tex} is distributed with GDB
18797and is located in the @file{gdb-@var{version-number}/texinfo}
18798directory.
c4555f82 18799
8e04817f
AC
18800If you have @TeX{} and a @sc{dvi} printer program installed, you can
18801typeset and print this manual. First switch to the the @file{gdb}
18802subdirectory of the main source directory (for example, to
18803@file{gdb-@value{GDBVN}/gdb}) and type:
c4555f82 18804
474c8240 18805@smallexample
8e04817f 18806make gdb.dvi
474c8240 18807@end smallexample
c4555f82 18808
8e04817f 18809Then give @file{gdb.dvi} to your @sc{dvi} printing program.
c4555f82 18810
8e04817f
AC
18811@node Installing GDB
18812@appendix Installing @value{GDBN}
18813@cindex configuring @value{GDBN}
18814@cindex installation
94e91d6d 18815@cindex configuring @value{GDBN}, and source tree subdirectories
c4555f82 18816
8e04817f
AC
18817@value{GDBN} comes with a @code{configure} script that automates the process
18818of preparing @value{GDBN} for installation; you can then use @code{make} to
18819build the @code{gdb} program.
18820@iftex
18821@c irrelevant in info file; it's as current as the code it lives with.
18822@footnote{If you have a more recent version of @value{GDBN} than @value{GDBVN},
18823look at the @file{README} file in the sources; we may have improved the
18824installation procedures since publishing this manual.}
18825@end iftex
c4555f82 18826
8e04817f
AC
18827The @value{GDBN} distribution includes all the source code you need for
18828@value{GDBN} in a single directory, whose name is usually composed by
18829appending the version number to @samp{gdb}.
c4555f82 18830
8e04817f
AC
18831For example, the @value{GDBN} version @value{GDBVN} distribution is in the
18832@file{gdb-@value{GDBVN}} directory. That directory contains:
c4555f82 18833
8e04817f
AC
18834@table @code
18835@item gdb-@value{GDBVN}/configure @r{(and supporting files)}
18836script for configuring @value{GDBN} and all its supporting libraries
c4555f82 18837
8e04817f
AC
18838@item gdb-@value{GDBVN}/gdb
18839the source specific to @value{GDBN} itself
c4555f82 18840
8e04817f
AC
18841@item gdb-@value{GDBVN}/bfd
18842source for the Binary File Descriptor library
c906108c 18843
8e04817f
AC
18844@item gdb-@value{GDBVN}/include
18845@sc{gnu} include files
c906108c 18846
8e04817f
AC
18847@item gdb-@value{GDBVN}/libiberty
18848source for the @samp{-liberty} free software library
c906108c 18849
8e04817f
AC
18850@item gdb-@value{GDBVN}/opcodes
18851source for the library of opcode tables and disassemblers
c906108c 18852
8e04817f
AC
18853@item gdb-@value{GDBVN}/readline
18854source for the @sc{gnu} command-line interface
c906108c 18855
8e04817f
AC
18856@item gdb-@value{GDBVN}/glob
18857source for the @sc{gnu} filename pattern-matching subroutine
c906108c 18858
8e04817f
AC
18859@item gdb-@value{GDBVN}/mmalloc
18860source for the @sc{gnu} memory-mapped malloc package
18861@end table
c906108c 18862
8e04817f
AC
18863The simplest way to configure and build @value{GDBN} is to run @code{configure}
18864from the @file{gdb-@var{version-number}} source directory, which in
18865this example is the @file{gdb-@value{GDBVN}} directory.
c906108c 18866
8e04817f
AC
18867First switch to the @file{gdb-@var{version-number}} source directory
18868if you are not already in it; then run @code{configure}. Pass the
18869identifier for the platform on which @value{GDBN} will run as an
18870argument.
c906108c 18871
8e04817f 18872For example:
c906108c 18873
474c8240 18874@smallexample
8e04817f
AC
18875cd gdb-@value{GDBVN}
18876./configure @var{host}
18877make
474c8240 18878@end smallexample
c906108c 18879
8e04817f
AC
18880@noindent
18881where @var{host} is an identifier such as @samp{sun4} or
18882@samp{decstation}, that identifies the platform where @value{GDBN} will run.
18883(You can often leave off @var{host}; @code{configure} tries to guess the
18884correct value by examining your system.)
c906108c 18885
8e04817f
AC
18886Running @samp{configure @var{host}} and then running @code{make} builds the
18887@file{bfd}, @file{readline}, @file{mmalloc}, and @file{libiberty}
18888libraries, then @code{gdb} itself. The configured source files, and the
18889binaries, are left in the corresponding source directories.
c906108c 18890
8e04817f
AC
18891@need 750
18892@code{configure} is a Bourne-shell (@code{/bin/sh}) script; if your
18893system does not recognize this automatically when you run a different
18894shell, you may need to run @code{sh} on it explicitly:
c906108c 18895
474c8240 18896@smallexample
8e04817f 18897sh configure @var{host}
474c8240 18898@end smallexample
c906108c 18899
8e04817f
AC
18900If you run @code{configure} from a directory that contains source
18901directories for multiple libraries or programs, such as the
18902@file{gdb-@value{GDBVN}} source directory for version @value{GDBVN}, @code{configure}
18903creates configuration files for every directory level underneath (unless
18904you tell it not to, with the @samp{--norecursion} option).
18905
94e91d6d
MC
18906You should run the @code{configure} script from the top directory in the
18907source tree, the @file{gdb-@var{version-number}} directory. If you run
18908@code{configure} from one of the subdirectories, you will configure only
18909that subdirectory. That is usually not what you want. In particular,
18910if you run the first @code{configure} from the @file{gdb} subdirectory
18911of the @file{gdb-@var{version-number}} directory, you will omit the
18912configuration of @file{bfd}, @file{readline}, and other sibling
18913directories of the @file{gdb} subdirectory. This leads to build errors
18914about missing include files such as @file{bfd/bfd.h}.
c906108c 18915
8e04817f
AC
18916You can install @code{@value{GDBP}} anywhere; it has no hardwired paths.
18917However, you should make sure that the shell on your path (named by
18918the @samp{SHELL} environment variable) is publicly readable. Remember
18919that @value{GDBN} uses the shell to start your program---some systems refuse to
18920let @value{GDBN} debug child processes whose programs are not readable.
c906108c 18921
8e04817f
AC
18922@menu
18923* Separate Objdir:: Compiling @value{GDBN} in another directory
18924* Config Names:: Specifying names for hosts and targets
18925* Configure Options:: Summary of options for configure
18926@end menu
c906108c 18927
8e04817f
AC
18928@node Separate Objdir
18929@section Compiling @value{GDBN} in another directory
c906108c 18930
8e04817f
AC
18931If you want to run @value{GDBN} versions for several host or target machines,
18932you need a different @code{gdb} compiled for each combination of
18933host and target. @code{configure} is designed to make this easy by
18934allowing you to generate each configuration in a separate subdirectory,
18935rather than in the source directory. If your @code{make} program
18936handles the @samp{VPATH} feature (@sc{gnu} @code{make} does), running
18937@code{make} in each of these directories builds the @code{gdb}
18938program specified there.
c906108c 18939
8e04817f
AC
18940To build @code{gdb} in a separate directory, run @code{configure}
18941with the @samp{--srcdir} option to specify where to find the source.
18942(You also need to specify a path to find @code{configure}
18943itself from your working directory. If the path to @code{configure}
18944would be the same as the argument to @samp{--srcdir}, you can leave out
18945the @samp{--srcdir} option; it is assumed.)
c906108c 18946
8e04817f
AC
18947For example, with version @value{GDBVN}, you can build @value{GDBN} in a
18948separate directory for a Sun 4 like this:
c906108c 18949
474c8240 18950@smallexample
8e04817f
AC
18951@group
18952cd gdb-@value{GDBVN}
18953mkdir ../gdb-sun4
18954cd ../gdb-sun4
18955../gdb-@value{GDBVN}/configure sun4
18956make
18957@end group
474c8240 18958@end smallexample
c906108c 18959
8e04817f
AC
18960When @code{configure} builds a configuration using a remote source
18961directory, it creates a tree for the binaries with the same structure
18962(and using the same names) as the tree under the source directory. In
18963the example, you'd find the Sun 4 library @file{libiberty.a} in the
18964directory @file{gdb-sun4/libiberty}, and @value{GDBN} itself in
18965@file{gdb-sun4/gdb}.
c906108c 18966
94e91d6d
MC
18967Make sure that your path to the @file{configure} script has just one
18968instance of @file{gdb} in it. If your path to @file{configure} looks
18969like @file{../gdb-@value{GDBVN}/gdb/configure}, you are configuring only
18970one subdirectory of @value{GDBN}, not the whole package. This leads to
18971build errors about missing include files such as @file{bfd/bfd.h}.
18972
8e04817f
AC
18973One popular reason to build several @value{GDBN} configurations in separate
18974directories is to configure @value{GDBN} for cross-compiling (where
18975@value{GDBN} runs on one machine---the @dfn{host}---while debugging
18976programs that run on another machine---the @dfn{target}).
18977You specify a cross-debugging target by
18978giving the @samp{--target=@var{target}} option to @code{configure}.
c906108c 18979
8e04817f
AC
18980When you run @code{make} to build a program or library, you must run
18981it in a configured directory---whatever directory you were in when you
18982called @code{configure} (or one of its subdirectories).
c906108c 18983
8e04817f
AC
18984The @code{Makefile} that @code{configure} generates in each source
18985directory also runs recursively. If you type @code{make} in a source
18986directory such as @file{gdb-@value{GDBVN}} (or in a separate configured
18987directory configured with @samp{--srcdir=@var{dirname}/gdb-@value{GDBVN}}), you
18988will build all the required libraries, and then build GDB.
c906108c 18989
8e04817f
AC
18990When you have multiple hosts or targets configured in separate
18991directories, you can run @code{make} on them in parallel (for example,
18992if they are NFS-mounted on each of the hosts); they will not interfere
18993with each other.
c906108c 18994
8e04817f
AC
18995@node Config Names
18996@section Specifying names for hosts and targets
c906108c 18997
8e04817f
AC
18998The specifications used for hosts and targets in the @code{configure}
18999script are based on a three-part naming scheme, but some short predefined
19000aliases are also supported. The full naming scheme encodes three pieces
19001of information in the following pattern:
c906108c 19002
474c8240 19003@smallexample
8e04817f 19004@var{architecture}-@var{vendor}-@var{os}
474c8240 19005@end smallexample
c906108c 19006
8e04817f
AC
19007For example, you can use the alias @code{sun4} as a @var{host} argument,
19008or as the value for @var{target} in a @code{--target=@var{target}}
19009option. The equivalent full name is @samp{sparc-sun-sunos4}.
c906108c 19010
8e04817f
AC
19011The @code{configure} script accompanying @value{GDBN} does not provide
19012any query facility to list all supported host and target names or
19013aliases. @code{configure} calls the Bourne shell script
19014@code{config.sub} to map abbreviations to full names; you can read the
19015script, if you wish, or you can use it to test your guesses on
19016abbreviations---for example:
c906108c 19017
8e04817f
AC
19018@smallexample
19019% sh config.sub i386-linux
19020i386-pc-linux-gnu
19021% sh config.sub alpha-linux
19022alpha-unknown-linux-gnu
19023% sh config.sub hp9k700
19024hppa1.1-hp-hpux
19025% sh config.sub sun4
19026sparc-sun-sunos4.1.1
19027% sh config.sub sun3
19028m68k-sun-sunos4.1.1
19029% sh config.sub i986v
19030Invalid configuration `i986v': machine `i986v' not recognized
19031@end smallexample
c906108c 19032
8e04817f
AC
19033@noindent
19034@code{config.sub} is also distributed in the @value{GDBN} source
19035directory (@file{gdb-@value{GDBVN}}, for version @value{GDBVN}).
d700128c 19036
8e04817f
AC
19037@node Configure Options
19038@section @code{configure} options
c906108c 19039
8e04817f
AC
19040Here is a summary of the @code{configure} options and arguments that
19041are most often useful for building @value{GDBN}. @code{configure} also has
19042several other options not listed here. @inforef{What Configure
19043Does,,configure.info}, for a full explanation of @code{configure}.
c906108c 19044
474c8240 19045@smallexample
8e04817f
AC
19046configure @r{[}--help@r{]}
19047 @r{[}--prefix=@var{dir}@r{]}
19048 @r{[}--exec-prefix=@var{dir}@r{]}
19049 @r{[}--srcdir=@var{dirname}@r{]}
19050 @r{[}--norecursion@r{]} @r{[}--rm@r{]}
19051 @r{[}--target=@var{target}@r{]}
19052 @var{host}
474c8240 19053@end smallexample
c906108c 19054
8e04817f
AC
19055@noindent
19056You may introduce options with a single @samp{-} rather than
19057@samp{--} if you prefer; but you may abbreviate option names if you use
19058@samp{--}.
c906108c 19059
8e04817f
AC
19060@table @code
19061@item --help
19062Display a quick summary of how to invoke @code{configure}.
c906108c 19063
8e04817f
AC
19064@item --prefix=@var{dir}
19065Configure the source to install programs and files under directory
19066@file{@var{dir}}.
c906108c 19067
8e04817f
AC
19068@item --exec-prefix=@var{dir}
19069Configure the source to install programs under directory
19070@file{@var{dir}}.
c906108c 19071
8e04817f
AC
19072@c avoid splitting the warning from the explanation:
19073@need 2000
19074@item --srcdir=@var{dirname}
19075@strong{Warning: using this option requires @sc{gnu} @code{make}, or another
19076@code{make} that implements the @code{VPATH} feature.}@*
19077Use this option to make configurations in directories separate from the
19078@value{GDBN} source directories. Among other things, you can use this to
19079build (or maintain) several configurations simultaneously, in separate
19080directories. @code{configure} writes configuration specific files in
19081the current directory, but arranges for them to use the source in the
19082directory @var{dirname}. @code{configure} creates directories under
19083the working directory in parallel to the source directories below
19084@var{dirname}.
c906108c 19085
8e04817f
AC
19086@item --norecursion
19087Configure only the directory level where @code{configure} is executed; do not
19088propagate configuration to subdirectories.
c906108c 19089
8e04817f
AC
19090@item --target=@var{target}
19091Configure @value{GDBN} for cross-debugging programs running on the specified
19092@var{target}. Without this option, @value{GDBN} is configured to debug
19093programs that run on the same machine (@var{host}) as @value{GDBN} itself.
c906108c 19094
8e04817f 19095There is no convenient way to generate a list of all available targets.
c906108c 19096
8e04817f
AC
19097@item @var{host} @dots{}
19098Configure @value{GDBN} to run on the specified @var{host}.
c906108c 19099
8e04817f
AC
19100There is no convenient way to generate a list of all available hosts.
19101@end table
c906108c 19102
8e04817f
AC
19103There are many other options available as well, but they are generally
19104needed for special purposes only.
c906108c 19105
8e04817f
AC
19106@node Maintenance Commands
19107@appendix Maintenance Commands
19108@cindex maintenance commands
19109@cindex internal commands
c906108c 19110
8e04817f
AC
19111In addition to commands intended for @value{GDBN} users, @value{GDBN}
19112includes a number of commands intended for @value{GDBN} developers.
19113These commands are provided here for reference.
c906108c 19114
8e04817f
AC
19115@table @code
19116@kindex maint info breakpoints
19117@item @anchor{maint info breakpoints}maint info breakpoints
19118Using the same format as @samp{info breakpoints}, display both the
19119breakpoints you've set explicitly, and those @value{GDBN} is using for
19120internal purposes. Internal breakpoints are shown with negative
19121breakpoint numbers. The type column identifies what kind of breakpoint
19122is shown:
c906108c 19123
8e04817f
AC
19124@table @code
19125@item breakpoint
19126Normal, explicitly set breakpoint.
c906108c 19127
8e04817f
AC
19128@item watchpoint
19129Normal, explicitly set watchpoint.
c906108c 19130
8e04817f
AC
19131@item longjmp
19132Internal breakpoint, used to handle correctly stepping through
19133@code{longjmp} calls.
c906108c 19134
8e04817f
AC
19135@item longjmp resume
19136Internal breakpoint at the target of a @code{longjmp}.
c906108c 19137
8e04817f
AC
19138@item until
19139Temporary internal breakpoint used by the @value{GDBN} @code{until} command.
c906108c 19140
8e04817f
AC
19141@item finish
19142Temporary internal breakpoint used by the @value{GDBN} @code{finish} command.
c906108c 19143
8e04817f
AC
19144@item shlib events
19145Shared library events.
c906108c 19146
8e04817f 19147@end table
c906108c 19148
8d30a00d
AC
19149@kindex maint internal-error
19150@kindex maint internal-warning
19151@item maint internal-error
19152@itemx maint internal-warning
19153Cause @value{GDBN} to call the internal function @code{internal_error}
19154or @code{internal_warning} and hence behave as though an internal error
19155or internal warning has been detected. In addition to reporting the
19156internal problem, these functions give the user the opportunity to
19157either quit @value{GDBN} or create a core file of the current
19158@value{GDBN} session.
19159
19160@smallexample
19161(gdb) @kbd{maint internal-error testing, 1, 2}
19162@dots{}/maint.c:121: internal-error: testing, 1, 2
19163A problem internal to GDB has been detected. Further
19164debugging may prove unreliable.
19165Quit this debugging session? (y or n) @kbd{n}
19166Create a core file? (y or n) @kbd{n}
19167(gdb)
19168@end smallexample
19169
19170Takes an optional parameter that is used as the text of the error or
19171warning message.
19172
00905d52
AC
19173@kindex maint print dummy-frames
19174@item maint print dummy-frames
19175
19176Prints the contents of @value{GDBN}'s internal dummy-frame stack.
19177
19178@smallexample
19179(gdb) @kbd{b add}
19180@dots{}
19181(gdb) @kbd{print add(2,3)}
19182Breakpoint 2, add (a=2, b=3) at @dots{}
1918358 return (a + b);
19184The program being debugged stopped while in a function called from GDB.
19185@dots{}
19186(gdb) @kbd{maint print dummy-frames}
191870x1a57c80: pc=0x01014068 fp=0x0200bddc sp=0x0200bdd6
19188 top=0x0200bdd4 id=@{stack=0x200bddc,code=0x101405c@}
19189 call_lo=0x01014000 call_hi=0x01014001
19190(gdb)
19191@end smallexample
19192
19193Takes an optional file parameter.
19194
0680b120
AC
19195@kindex maint print registers
19196@kindex maint print raw-registers
19197@kindex maint print cooked-registers
617073a9 19198@kindex maint print register-groups
0680b120
AC
19199@item maint print registers
19200@itemx maint print raw-registers
19201@itemx maint print cooked-registers
617073a9 19202@itemx maint print register-groups
0680b120
AC
19203Print @value{GDBN}'s internal register data structures.
19204
617073a9
AC
19205The command @code{maint print raw-registers} includes the contents of
19206the raw register cache; the command @code{maint print cooked-registers}
19207includes the (cooked) value of all registers; and the command
19208@code{maint print register-groups} includes the groups that each
19209register is a member of. @xref{Registers,, Registers, gdbint,
19210@value{GDBN} Internals}.
0680b120
AC
19211
19212Takes an optional file parameter.
19213
617073a9
AC
19214@kindex maint print reggroups
19215@item maint print reggroups
19216Print @value{GDBN}'s internal register group data structures.
19217
19218Takes an optional file parameter.
19219
19220@smallexample
19221(gdb) @kbd{maint print reggroups}
19222 Group Type
19223 general user
19224 float user
19225 all user
19226 vector user
19227 system user
19228 save internal
19229 restore internal
19230@end smallexample
19231
e7ba9c65
DJ
19232@kindex maint set profile
19233@kindex maint show profile
19234@cindex profiling GDB
19235@item maint set profile
19236@itemx maint show profile
19237Control profiling of @value{GDBN}.
19238
19239Profiling will be disabled until you use the @samp{maint set profile}
19240command to enable it. When you enable profiling, the system will begin
19241collecting timing and execution count data; when you disable profiling or
19242exit @value{GDBN}, the results will be written to a log file. Remember that
19243if you use profiling, @value{GDBN} will overwrite the profiling log file
19244(often called @file{gmon.out}). If you have a record of important profiling
19245data in a @file{gmon.out} file, be sure to move it to a safe location.
19246
19247Configuring with @samp{--enable-profiling} arranges for @value{GDBN} to be
19248compiled with the @samp{-pg} compiler option.
19249
8e04817f 19250@end table
c906108c 19251
c906108c 19252
e0ce93ac 19253@node Remote Protocol
8e04817f 19254@appendix @value{GDBN} Remote Serial Protocol
c906108c 19255
ee2d5c50
AC
19256@menu
19257* Overview::
19258* Packets::
19259* Stop Reply Packets::
19260* General Query Packets::
19261* Register Packet Format::
19262* Examples::
0ce1b118 19263* File-I/O remote protocol extension::
ee2d5c50
AC
19264@end menu
19265
19266@node Overview
19267@section Overview
19268
8e04817f
AC
19269There may be occasions when you need to know something about the
19270protocol---for example, if there is only one serial port to your target
19271machine, you might want your program to do something special if it
19272recognizes a packet meant for @value{GDBN}.
c906108c 19273
d2c6833e 19274In the examples below, @samp{->} and @samp{<-} are used to indicate
8e04817f 19275transmitted and received data respectfully.
c906108c 19276
8e04817f
AC
19277@cindex protocol, @value{GDBN} remote serial
19278@cindex serial protocol, @value{GDBN} remote
19279@cindex remote serial protocol
19280All @value{GDBN} commands and responses (other than acknowledgments) are
19281sent as a @var{packet}. A @var{packet} is introduced with the character
19282@samp{$}, the actual @var{packet-data}, and the terminating character
19283@samp{#} followed by a two-digit @var{checksum}:
c906108c 19284
474c8240 19285@smallexample
8e04817f 19286@code{$}@var{packet-data}@code{#}@var{checksum}
474c8240 19287@end smallexample
8e04817f 19288@noindent
c906108c 19289
8e04817f
AC
19290@cindex checksum, for @value{GDBN} remote
19291@noindent
19292The two-digit @var{checksum} is computed as the modulo 256 sum of all
19293characters between the leading @samp{$} and the trailing @samp{#} (an
19294eight bit unsigned checksum).
c906108c 19295
8e04817f
AC
19296Implementors should note that prior to @value{GDBN} 5.0 the protocol
19297specification also included an optional two-digit @var{sequence-id}:
c906108c 19298
474c8240 19299@smallexample
8e04817f 19300@code{$}@var{sequence-id}@code{:}@var{packet-data}@code{#}@var{checksum}
474c8240 19301@end smallexample
c906108c 19302
8e04817f
AC
19303@cindex sequence-id, for @value{GDBN} remote
19304@noindent
19305That @var{sequence-id} was appended to the acknowledgment. @value{GDBN}
19306has never output @var{sequence-id}s. Stubs that handle packets added
19307since @value{GDBN} 5.0 must not accept @var{sequence-id}.
c906108c 19308
8e04817f
AC
19309@cindex acknowledgment, for @value{GDBN} remote
19310When either the host or the target machine receives a packet, the first
19311response expected is an acknowledgment: either @samp{+} (to indicate
19312the package was received correctly) or @samp{-} (to request
19313retransmission):
c906108c 19314
474c8240 19315@smallexample
d2c6833e
AC
19316-> @code{$}@var{packet-data}@code{#}@var{checksum}
19317<- @code{+}
474c8240 19318@end smallexample
8e04817f 19319@noindent
53a5351d 19320
8e04817f
AC
19321The host (@value{GDBN}) sends @var{command}s, and the target (the
19322debugging stub incorporated in your program) sends a @var{response}. In
19323the case of step and continue @var{command}s, the response is only sent
19324when the operation has completed (the target has again stopped).
c906108c 19325
8e04817f
AC
19326@var{packet-data} consists of a sequence of characters with the
19327exception of @samp{#} and @samp{$} (see @samp{X} packet for additional
19328exceptions).
c906108c 19329
8e04817f 19330Fields within the packet should be separated using @samp{,} @samp{;} or
ee2d5c50 19331@cindex remote protocol, field separator
8e04817f 19332@samp{:}. Except where otherwise noted all numbers are represented in
ee2d5c50 19333@sc{hex} with leading zeros suppressed.
c906108c 19334
8e04817f
AC
19335Implementors should note that prior to @value{GDBN} 5.0, the character
19336@samp{:} could not appear as the third character in a packet (as it
19337would potentially conflict with the @var{sequence-id}).
c906108c 19338
8e04817f
AC
19339Response @var{data} can be run-length encoded to save space. A @samp{*}
19340means that the next character is an @sc{ascii} encoding giving a repeat count
19341which stands for that many repetitions of the character preceding the
19342@samp{*}. The encoding is @code{n+29}, yielding a printable character
19343where @code{n >=3} (which is where rle starts to win). The printable
19344characters @samp{$}, @samp{#}, @samp{+} and @samp{-} or with a numeric
19345value greater than 126 should not be used.
c906108c 19346
8e04817f
AC
19347Some remote systems have used a different run-length encoding mechanism
19348loosely refered to as the cisco encoding. Following the @samp{*}
19349character are two hex digits that indicate the size of the packet.
c906108c 19350
8e04817f 19351So:
474c8240 19352@smallexample
8e04817f 19353"@code{0* }"
474c8240 19354@end smallexample
8e04817f
AC
19355@noindent
19356means the same as "0000".
c906108c 19357
8e04817f
AC
19358The error response returned for some packets includes a two character
19359error number. That number is not well defined.
c906108c 19360
8e04817f
AC
19361For any @var{command} not supported by the stub, an empty response
19362(@samp{$#00}) should be returned. That way it is possible to extend the
19363protocol. A newer @value{GDBN} can tell if a packet is supported based
19364on that response.
c906108c 19365
8e04817f
AC
19366A stub is required to support the @samp{g}, @samp{G}, @samp{m}, @samp{M},
19367@samp{c}, and @samp{s} @var{command}s. All other @var{command}s are
19368optional.
c906108c 19369
ee2d5c50
AC
19370@node Packets
19371@section Packets
19372
19373The following table provides a complete list of all currently defined
19374@var{command}s and their corresponding response @var{data}.
19375
19376@table @r
19377
19378@item @code{!} --- extended mode
19379@cindex @code{!} packet
19380
8e04817f
AC
19381Enable extended mode. In extended mode, the remote server is made
19382persistent. The @samp{R} packet is used to restart the program being
19383debugged.
ee2d5c50
AC
19384
19385Reply:
19386@table @samp
19387@item OK
8e04817f 19388The remote target both supports and has enabled extended mode.
ee2d5c50 19389@end table
c906108c 19390
ee2d5c50
AC
19391@item @code{?} --- last signal
19392@cindex @code{?} packet
c906108c 19393
ee2d5c50
AC
19394Indicate the reason the target halted. The reply is the same as for
19395step and continue.
c906108c 19396
ee2d5c50
AC
19397Reply:
19398@xref{Stop Reply Packets}, for the reply specifications.
19399
19400@item @code{a} --- reserved
19401
19402Reserved for future use.
19403
19404@item @code{A}@var{arglen}@code{,}@var{argnum}@code{,}@var{arg}@code{,@dots{}} --- set program arguments @strong{(reserved)}
19405@cindex @code{A} packet
c906108c 19406
8e04817f
AC
19407Initialized @samp{argv[]} array passed into program. @var{arglen}
19408specifies the number of bytes in the hex encoded byte stream @var{arg}.
ee2d5c50
AC
19409See @code{gdbserver} for more details.
19410
19411Reply:
19412@table @samp
19413@item OK
19414@item E@var{NN}
19415@end table
19416
19417@item @code{b}@var{baud} --- set baud @strong{(deprecated)}
19418@cindex @code{b} packet
19419
19420Change the serial line speed to @var{baud}.
19421
19422JTC: @emph{When does the transport layer state change? When it's
19423received, or after the ACK is transmitted. In either case, there are
19424problems if the command or the acknowledgment packet is dropped.}
19425
19426Stan: @emph{If people really wanted to add something like this, and get
19427it working for the first time, they ought to modify ser-unix.c to send
19428some kind of out-of-band message to a specially-setup stub and have the
19429switch happen "in between" packets, so that from remote protocol's point
19430of view, nothing actually happened.}
19431
19432@item @code{B}@var{addr},@var{mode} --- set breakpoint @strong{(deprecated)}
19433@cindex @code{B} packet
19434
8e04817f 19435Set (@var{mode} is @samp{S}) or clear (@var{mode} is @samp{C}) a
2f870471
AC
19436breakpoint at @var{addr}.
19437
19438This packet has been replaced by the @samp{Z} and @samp{z} packets
19439(@pxref{insert breakpoint or watchpoint packet}).
c906108c 19440
ee2d5c50
AC
19441@item @code{c}@var{addr} --- continue
19442@cindex @code{c} packet
19443
19444@var{addr} is address to resume. If @var{addr} is omitted, resume at
8e04817f 19445current address.
c906108c 19446
ee2d5c50
AC
19447Reply:
19448@xref{Stop Reply Packets}, for the reply specifications.
19449
19450@item @code{C}@var{sig}@code{;}@var{addr} --- continue with signal
19451@cindex @code{C} packet
19452
8e04817f
AC
19453Continue with signal @var{sig} (hex signal number). If
19454@code{;}@var{addr} is omitted, resume at same address.
c906108c 19455
ee2d5c50
AC
19456Reply:
19457@xref{Stop Reply Packets}, for the reply specifications.
c906108c 19458
ee2d5c50
AC
19459@item @code{d} --- toggle debug @strong{(deprecated)}
19460@cindex @code{d} packet
19461
19462Toggle debug flag.
19463
19464@item @code{D} --- detach
19465@cindex @code{D} packet
19466
19467Detach @value{GDBN} from the remote system. Sent to the remote target
07f31aa6 19468before @value{GDBN} disconnects via the @code{detach} command.
ee2d5c50
AC
19469
19470Reply:
19471@table @samp
19472@item @emph{no response}
8e04817f 19473@value{GDBN} does not check for any response after sending this packet.
ee2d5c50 19474@end table
c906108c 19475
ee2d5c50 19476@item @code{e} --- reserved
c906108c 19477
ee2d5c50 19478Reserved for future use.
c906108c 19479
ee2d5c50 19480@item @code{E} --- reserved
c906108c 19481
ee2d5c50 19482Reserved for future use.
c906108c 19483
ee2d5c50
AC
19484@item @code{f} --- reserved
19485
19486Reserved for future use.
19487
0ce1b118
CV
19488@item @code{F}@var{RC}@code{,}@var{EE}@code{,}@var{CF}@code{;}@var{XX} --- Reply to target's F packet.
19489@cindex @code{F} packet
ee2d5c50 19490
0ce1b118
CV
19491This packet is send by @value{GDBN} as reply to a @code{F} request packet
19492sent by the target. This is part of the File-I/O protocol extension.
19493@xref{File-I/O remote protocol extension}, for the specification.
ee2d5c50
AC
19494
19495@item @code{g} --- read registers
19496@anchor{read registers packet}
19497@cindex @code{g} packet
19498
19499Read general registers.
19500
19501Reply:
19502@table @samp
19503@item @var{XX@dots{}}
8e04817f
AC
19504Each byte of register data is described by two hex digits. The bytes
19505with the register are transmitted in target byte order. The size of
19506each register and their position within the @samp{g} @var{packet} are
ee2d5c50
AC
19507determined by the @value{GDBN} internal macros @var{REGISTER_RAW_SIZE}
19508and @var{REGISTER_NAME} macros. The specification of several standard
8e04817f 19509@code{g} packets is specified below.
ee2d5c50
AC
19510@item E@var{NN}
19511for an error.
19512@end table
c906108c 19513
ee2d5c50
AC
19514@item @code{G}@var{XX@dots{}} --- write regs
19515@cindex @code{G} packet
c906108c 19516
ee2d5c50
AC
19517@xref{read registers packet}, for a description of the @var{XX@dots{}}
19518data.
19519
19520Reply:
19521@table @samp
19522@item OK
19523for success
19524@item E@var{NN}
19525for an error
19526@end table
19527
19528@item @code{h} --- reserved
19529
19530Reserved for future use.
19531
19532@item @code{H}@var{c}@var{t@dots{}} --- set thread
19533@cindex @code{H} packet
c906108c 19534
8e04817f 19535Set thread for subsequent operations (@samp{m}, @samp{M}, @samp{g},
ee2d5c50
AC
19536@samp{G}, et.al.). @var{c} depends on the operation to be performed: it
19537should be @samp{c} for step and continue operations, @samp{g} for other
19538operations. The thread designator @var{t@dots{}} may be -1, meaning all
19539the threads, a thread number, or zero which means pick any thread.
19540
19541Reply:
19542@table @samp
19543@item OK
19544for success
19545@item E@var{NN}
19546for an error
19547@end table
c906108c 19548
8e04817f
AC
19549@c FIXME: JTC:
19550@c 'H': How restrictive (or permissive) is the thread model. If a
19551@c thread is selected and stopped, are other threads allowed
19552@c to continue to execute? As I mentioned above, I think the
19553@c semantics of each command when a thread is selected must be
19554@c described. For example:
19555@c
19556@c 'g': If the stub supports threads and a specific thread is
19557@c selected, returns the register block from that thread;
19558@c otherwise returns current registers.
19559@c
19560@c 'G' If the stub supports threads and a specific thread is
19561@c selected, sets the registers of the register block of
19562@c that thread; otherwise sets current registers.
c906108c 19563
ee2d5c50
AC
19564@item @code{i}@var{addr}@code{,}@var{nnn} --- cycle step @strong{(draft)}
19565@anchor{cycle step packet}
19566@cindex @code{i} packet
19567
8e04817f
AC
19568Step the remote target by a single clock cycle. If @code{,}@var{nnn} is
19569present, cycle step @var{nnn} cycles. If @var{addr} is present, cycle
19570step starting at that address.
c906108c 19571
ee2d5c50
AC
19572@item @code{I} --- signal then cycle step @strong{(reserved)}
19573@cindex @code{I} packet
19574
19575@xref{step with signal packet}. @xref{cycle step packet}.
19576
19577@item @code{j} --- reserved
19578
19579Reserved for future use.
19580
19581@item @code{J} --- reserved
c906108c 19582
ee2d5c50 19583Reserved for future use.
c906108c 19584
ee2d5c50
AC
19585@item @code{k} --- kill request
19586@cindex @code{k} packet
c906108c 19587
ac282366 19588FIXME: @emph{There is no description of how to operate when a specific
ee2d5c50
AC
19589thread context has been selected (i.e.@: does 'k' kill only that
19590thread?)}.
c906108c 19591
ee2d5c50 19592@item @code{K} --- reserved
c906108c 19593
ee2d5c50
AC
19594Reserved for future use.
19595
19596@item @code{l} --- reserved
19597
19598Reserved for future use.
19599
19600@item @code{L} --- reserved
19601
19602Reserved for future use.
19603
19604@item @code{m}@var{addr}@code{,}@var{length} --- read memory
19605@cindex @code{m} packet
c906108c 19606
8e04817f 19607Read @var{length} bytes of memory starting at address @var{addr}.
ee2d5c50 19608Neither @value{GDBN} nor the stub assume that sized memory transfers are
2e834e49 19609assumed using word aligned accesses. FIXME: @emph{A word aligned memory
8e04817f 19610transfer mechanism is needed.}
c906108c 19611
ee2d5c50
AC
19612Reply:
19613@table @samp
19614@item @var{XX@dots{}}
19615@var{XX@dots{}} is mem contents. Can be fewer bytes than requested if able
19616to read only part of the data. Neither @value{GDBN} nor the stub assume
2e834e49 19617that sized memory transfers are assumed using word aligned
ee2d5c50
AC
19618accesses. FIXME: @emph{A word aligned memory transfer mechanism is
19619needed.}
19620@item E@var{NN}
19621@var{NN} is errno
19622@end table
19623
19624@item @code{M}@var{addr},@var{length}@code{:}@var{XX@dots{}} --- write mem
19625@cindex @code{M} packet
19626
8e04817f 19627Write @var{length} bytes of memory starting at address @var{addr}.
ee2d5c50
AC
19628@var{XX@dots{}} is the data.
19629
19630Reply:
19631@table @samp
19632@item OK
19633for success
19634@item E@var{NN}
8e04817f
AC
19635for an error (this includes the case where only part of the data was
19636written).
ee2d5c50 19637@end table
c906108c 19638
ee2d5c50 19639@item @code{n} --- reserved
c906108c 19640
ee2d5c50 19641Reserved for future use.
c906108c 19642
ee2d5c50 19643@item @code{N} --- reserved
c906108c 19644
ee2d5c50 19645Reserved for future use.
c906108c 19646
ee2d5c50
AC
19647@item @code{o} --- reserved
19648
19649Reserved for future use.
19650
19651@item @code{O} --- reserved
19652
19653Reserved for future use.
c906108c 19654
ee2d5c50
AC
19655@item @code{p}@var{n@dots{}} --- read reg @strong{(reserved)}
19656@cindex @code{p} packet
19657
19658@xref{write register packet}.
19659
19660Reply:
19661@table @samp
19662@item @var{r@dots{}.}
19663The hex encoded value of the register in target byte order.
19664@end table
19665
19666@item @code{P}@var{n@dots{}}@code{=}@var{r@dots{}} --- write register
19667@anchor{write register packet}
19668@cindex @code{P} packet
19669
19670Write register @var{n@dots{}} with value @var{r@dots{}}, which contains two hex
8e04817f 19671digits for each byte in the register (target byte order).
c906108c 19672
ee2d5c50
AC
19673Reply:
19674@table @samp
19675@item OK
19676for success
19677@item E@var{NN}
19678for an error
19679@end table
19680
19681@item @code{q}@var{query} --- general query
19682@anchor{general query packet}
19683@cindex @code{q} packet
19684
19685Request info about @var{query}. In general @value{GDBN} queries have a
19686leading upper case letter. Custom vendor queries should use a company
19687prefix (in lower case) ex: @samp{qfsf.var}. @var{query} may optionally
19688be followed by a @samp{,} or @samp{;} separated list. Stubs must ensure
19689that they match the full @var{query} name.
19690
19691Reply:
19692@table @samp
19693@item @var{XX@dots{}}
19694Hex encoded data from query. The reply can not be empty.
19695@item E@var{NN}
19696error reply
8e04817f 19697@item
ee2d5c50
AC
19698Indicating an unrecognized @var{query}.
19699@end table
19700
19701@item @code{Q}@var{var}@code{=}@var{val} --- general set
19702@cindex @code{Q} packet
19703
19704Set value of @var{var} to @var{val}.
19705
19706@xref{general query packet}, for a discussion of naming conventions.
c906108c 19707
ee2d5c50
AC
19708@item @code{r} --- reset @strong{(deprecated)}
19709@cindex @code{r} packet
c906108c 19710
8e04817f 19711Reset the entire system.
c906108c 19712
ee2d5c50
AC
19713@item @code{R}@var{XX} --- remote restart
19714@cindex @code{R} packet
19715
8e04817f
AC
19716Restart the program being debugged. @var{XX}, while needed, is ignored.
19717This packet is only available in extended mode.
ee2d5c50
AC
19718
19719Reply:
19720@table @samp
19721@item @emph{no reply}
8e04817f 19722The @samp{R} packet has no reply.
ee2d5c50
AC
19723@end table
19724
19725@item @code{s}@var{addr} --- step
19726@cindex @code{s} packet
c906108c 19727
8e04817f
AC
19728@var{addr} is address to resume. If @var{addr} is omitted, resume at
19729same address.
c906108c 19730
ee2d5c50
AC
19731Reply:
19732@xref{Stop Reply Packets}, for the reply specifications.
19733
19734@item @code{S}@var{sig}@code{;}@var{addr} --- step with signal
19735@anchor{step with signal packet}
19736@cindex @code{S} packet
19737
8e04817f 19738Like @samp{C} but step not continue.
c906108c 19739
ee2d5c50
AC
19740Reply:
19741@xref{Stop Reply Packets}, for the reply specifications.
19742
19743@item @code{t}@var{addr}@code{:}@var{PP}@code{,}@var{MM} --- search
19744@cindex @code{t} packet
19745
8e04817f 19746Search backwards starting at address @var{addr} for a match with pattern
ee2d5c50
AC
19747@var{PP} and mask @var{MM}. @var{PP} and @var{MM} are 4 bytes.
19748@var{addr} must be at least 3 digits.
c906108c 19749
ee2d5c50
AC
19750@item @code{T}@var{XX} --- thread alive
19751@cindex @code{T} packet
c906108c 19752
ee2d5c50 19753Find out if the thread XX is alive.
c906108c 19754
ee2d5c50
AC
19755Reply:
19756@table @samp
19757@item OK
19758thread is still alive
19759@item E@var{NN}
19760thread is dead
19761@end table
19762
19763@item @code{u} --- reserved
19764
19765Reserved for future use.
19766
19767@item @code{U} --- reserved
19768
19769Reserved for future use.
19770
19771@item @code{v} --- reserved
19772
19773Reserved for future use.
19774
19775@item @code{V} --- reserved
c906108c 19776
ee2d5c50 19777Reserved for future use.
c906108c 19778
ee2d5c50 19779@item @code{w} --- reserved
c906108c 19780
ee2d5c50 19781Reserved for future use.
c906108c 19782
ee2d5c50 19783@item @code{W} --- reserved
c906108c 19784
ee2d5c50 19785Reserved for future use.
c906108c 19786
ee2d5c50
AC
19787@item @code{x} --- reserved
19788
19789Reserved for future use.
19790
19791@item @code{X}@var{addr}@code{,}@var{length}@var{:}@var{XX@dots{}} --- write mem (binary)
19792@cindex @code{X} packet
19793
19794@var{addr} is address, @var{length} is number of bytes, @var{XX@dots{}}
19795is binary data. The characters @code{$}, @code{#}, and @code{0x7d} are
8e04817f 19796escaped using @code{0x7d}.
c906108c 19797
ee2d5c50
AC
19798Reply:
19799@table @samp
19800@item OK
19801for success
19802@item E@var{NN}
19803for an error
19804@end table
19805
19806@item @code{y} --- reserved
c906108c 19807
ee2d5c50 19808Reserved for future use.
c906108c 19809
ee2d5c50
AC
19810@item @code{Y} reserved
19811
19812Reserved for future use.
19813
2f870471
AC
19814@item @code{z}@var{type}@code{,}@var{addr}@code{,}@var{length} --- remove breakpoint or watchpoint @strong{(draft)}
19815@itemx @code{Z}@var{type}@code{,}@var{addr}@code{,}@var{length} --- insert breakpoint or watchpoint @strong{(draft)}
19816@anchor{insert breakpoint or watchpoint packet}
ee2d5c50 19817@cindex @code{z} packet
2f870471 19818@cindex @code{Z} packets
ee2d5c50 19819
2f870471
AC
19820Insert (@code{Z}) or remove (@code{z}) a @var{type} breakpoint or
19821watchpoint starting at address @var{address} and covering the next
19822@var{length} bytes.
ee2d5c50 19823
2f870471
AC
19824Each breakpoint and watchpoint packet @var{type} is documented
19825separately.
19826
512217c7
AC
19827@emph{Implementation notes: A remote target shall return an empty string
19828for an unrecognized breakpoint or watchpoint packet @var{type}. A
19829remote target shall support either both or neither of a given
2f870471
AC
19830@code{Z}@var{type}@dots{} and @code{z}@var{type}@dots{} packet pair. To
19831avoid potential problems with duplicate packets, the operations should
19832be implemented in an idempotent way.}
19833
19834@item @code{z}@code{0}@code{,}@var{addr}@code{,}@var{length} --- remove memory breakpoint @strong{(draft)}
19835@item @code{Z}@code{0}@code{,}@var{addr}@code{,}@var{length} --- insert memory breakpoint @strong{(draft)}
19836@cindex @code{z0} packet
19837@cindex @code{Z0} packet
19838
19839Insert (@code{Z0}) or remove (@code{z0}) a memory breakpoint at address
19840@code{addr} of size @code{length}.
19841
19842A memory breakpoint is implemented by replacing the instruction at
19843@var{addr} with a software breakpoint or trap instruction. The
19844@code{length} is used by targets that indicates the size of the
19845breakpoint (in bytes) that should be inserted (e.g., the @sc{arm} and
19846@sc{mips} can insert either a 2 or 4 byte breakpoint).
c906108c 19847
2f870471
AC
19848@emph{Implementation note: It is possible for a target to copy or move
19849code that contains memory breakpoints (e.g., when implementing
19850overlays). The behavior of this packet, in the presence of such a
19851target, is not defined.}
c906108c 19852
ee2d5c50
AC
19853Reply:
19854@table @samp
2f870471
AC
19855@item OK
19856success
19857@item
19858not supported
ee2d5c50
AC
19859@item E@var{NN}
19860for an error
2f870471
AC
19861@end table
19862
19863@item @code{z}@code{1}@code{,}@var{addr}@code{,}@var{length} --- remove hardware breakpoint @strong{(draft)}
19864@item @code{Z}@code{1}@code{,}@var{addr}@code{,}@var{length} --- insert hardware breakpoint @strong{(draft)}
19865@cindex @code{z1} packet
19866@cindex @code{Z1} packet
19867
19868Insert (@code{Z1}) or remove (@code{z1}) a hardware breakpoint at
19869address @code{addr} of size @code{length}.
19870
19871A hardware breakpoint is implemented using a mechanism that is not
19872dependant on being able to modify the target's memory.
19873
19874@emph{Implementation note: A hardware breakpoint is not affected by code
19875movement.}
19876
19877Reply:
19878@table @samp
ee2d5c50 19879@item OK
2f870471
AC
19880success
19881@item
19882not supported
19883@item E@var{NN}
19884for an error
19885@end table
19886
19887@item @code{z}@code{2}@code{,}@var{addr}@code{,}@var{length} --- remove write watchpoint @strong{(draft)}
19888@item @code{Z}@code{2}@code{,}@var{addr}@code{,}@var{length} --- insert write watchpoint @strong{(draft)}
19889@cindex @code{z2} packet
19890@cindex @code{Z2} packet
19891
19892Insert (@code{Z2}) or remove (@code{z2}) a write watchpoint.
19893
19894Reply:
19895@table @samp
19896@item OK
19897success
19898@item
19899not supported
19900@item E@var{NN}
19901for an error
19902@end table
19903
19904@item @code{z}@code{3}@code{,}@var{addr}@code{,}@var{length} --- remove read watchpoint @strong{(draft)}
19905@item @code{Z}@code{3}@code{,}@var{addr}@code{,}@var{length} --- insert read watchpoint @strong{(draft)}
19906@cindex @code{z3} packet
19907@cindex @code{Z3} packet
19908
2e834e49 19909Insert (@code{Z3}) or remove (@code{z3}) a read watchpoint.
2f870471
AC
19910
19911Reply:
19912@table @samp
19913@item OK
19914success
19915@item
19916not supported
19917@item E@var{NN}
19918for an error
19919@end table
19920
2e834e49
HPN
19921@item @code{z}@code{4}@code{,}@var{addr}@code{,}@var{length} --- remove access watchpoint @strong{(draft)}
19922@item @code{Z}@code{4}@code{,}@var{addr}@code{,}@var{length} --- insert access watchpoint @strong{(draft)}
2f870471
AC
19923@cindex @code{z4} packet
19924@cindex @code{Z4} packet
19925
19926Insert (@code{Z4}) or remove (@code{z4}) an access watchpoint.
19927
19928Reply:
19929@table @samp
19930@item OK
19931success
19932@item
19933not supported
19934@item E@var{NN}
19935for an error
ee2d5c50
AC
19936@end table
19937
19938@end table
c906108c 19939
ee2d5c50
AC
19940@node Stop Reply Packets
19941@section Stop Reply Packets
19942@cindex stop reply packets
c906108c 19943
8e04817f
AC
19944The @samp{C}, @samp{c}, @samp{S}, @samp{s} and @samp{?} packets can
19945receive any of the below as a reply. In the case of the @samp{C},
19946@samp{c}, @samp{S} and @samp{s} packets, that reply is only returned
19947when the target halts. In the below the exact meaning of @samp{signal
19948number} is poorly defined. In general one of the UNIX signal numbering
19949conventions is used.
c906108c 19950
ee2d5c50 19951@table @samp
c906108c 19952
ee2d5c50
AC
19953@item S@var{AA}
19954@var{AA} is the signal number
c906108c 19955
8e04817f 19956@item @code{T}@var{AA}@var{n...}@code{:}@var{r...}@code{;}@var{n...}@code{:}@var{r...}@code{;}@var{n...}@code{:}@var{r...}@code{;}
ee2d5c50
AC
19957@cindex @code{T} packet reply
19958
8e04817f
AC
19959@var{AA} = two hex digit signal number; @var{n...} = register number
19960(hex), @var{r...} = target byte ordered register contents, size defined
19961by @code{REGISTER_RAW_SIZE}; @var{n...} = @samp{thread}, @var{r...} =
3c3bea1c
GS
19962thread process ID, this is a hex integer; @var{n...} = (@samp{watch} |
19963@samp{rwatch} | @samp{awatch}, @var{r...} = data address, this is a hex
19964integer; @var{n...} = other string not starting with valid hex digit.
19965@value{GDBN} should ignore this @var{n...}, @var{r...} pair and go on
19966to the next. This way we can extend the protocol.
c906108c 19967
ee2d5c50
AC
19968@item W@var{AA}
19969
8e04817f 19970The process exited, and @var{AA} is the exit status. This is only
ee2d5c50
AC
19971applicable to certain targets.
19972
19973@item X@var{AA}
c906108c 19974
8e04817f 19975The process terminated with signal @var{AA}.
c906108c 19976
ee2d5c50
AC
19977@item N@var{AA};@var{t@dots{}};@var{d@dots{}};@var{b@dots{}} @strong{(obsolete)}
19978
19979@var{AA} = signal number; @var{t@dots{}} = address of symbol
19980@code{_start}; @var{d@dots{}} = base of data section; @var{b@dots{}} =
19981base of bss section. @emph{Note: only used by Cisco Systems targets.
19982The difference between this reply and the @samp{qOffsets} query is that
19983the @samp{N} packet may arrive spontaneously whereas the @samp{qOffsets}
19984is a query initiated by the host debugger.}
c906108c 19985
ee2d5c50 19986@item O@var{XX@dots{}}
c906108c 19987
ee2d5c50
AC
19988@var{XX@dots{}} is hex encoding of @sc{ascii} data. This can happen at
19989any time while the program is running and the debugger should continue
19990to wait for @samp{W}, @samp{T}, etc.
19991
0ce1b118
CV
19992@item F@var{call-id}@code{,}@var{parameter@dots{}}
19993
19994@var{call-id} is the identifier which says which host system call should
19995be called. This is just the name of the function. Translation into the
19996correct system call is only applicable as it's defined in @value{GDBN}.
19997@xref{File-I/O remote protocol extension}, for a list of implemented
19998system calls.
19999
20000@var{parameter@dots{}} is a list of parameters as defined for this very
20001system call.
20002
20003The target replies with this packet when it expects @value{GDBN} to call
20004a host system call on behalf of the target. @value{GDBN} replies with
20005an appropriate @code{F} packet and keeps up waiting for the next reply
20006packet from the target. The latest @samp{C}, @samp{c}, @samp{S} or
20007@samp{s} action is expected to be continued.
20008@xref{File-I/O remote protocol extension}, for more details.
20009
ee2d5c50
AC
20010@end table
20011
20012@node General Query Packets
20013@section General Query Packets
c906108c 20014
8e04817f 20015The following set and query packets have already been defined.
c906108c 20016
ee2d5c50 20017@table @r
c906108c 20018
ee2d5c50
AC
20019@item @code{q}@code{C} --- current thread
20020
20021Return the current thread id.
20022
20023Reply:
20024@table @samp
20025@item @code{QC}@var{pid}
8e04817f 20026Where @var{pid} is a HEX encoded 16 bit process id.
ee2d5c50
AC
20027@item *
20028Any other reply implies the old pid.
20029@end table
20030
20031@item @code{q}@code{fThreadInfo} -- all thread ids
20032
20033@code{q}@code{sThreadInfo}
c906108c 20034
8e04817f
AC
20035Obtain a list of active thread ids from the target (OS). Since there
20036may be too many active threads to fit into one reply packet, this query
20037works iteratively: it may require more than one query/reply sequence to
20038obtain the entire list of threads. The first query of the sequence will
20039be the @code{qf}@code{ThreadInfo} query; subsequent queries in the
20040sequence will be the @code{qs}@code{ThreadInfo} query.
ee2d5c50
AC
20041
20042NOTE: replaces the @code{qL} query (see below).
20043
20044Reply:
20045@table @samp
20046@item @code{m}@var{id}
20047A single thread id
20048@item @code{m}@var{id},@var{id}@dots{}
20049a comma-separated list of thread ids
20050@item @code{l}
20051(lower case 'el') denotes end of list.
20052@end table
20053
20054In response to each query, the target will reply with a list of one or
20055more thread ids, in big-endian hex, separated by commas. @value{GDBN}
20056will respond to each reply with a request for more thread ids (using the
8e04817f
AC
20057@code{qs} form of the query), until the target responds with @code{l}
20058(lower-case el, for @code{'last'}).
c906108c 20059
ee2d5c50
AC
20060@item @code{q}@code{ThreadExtraInfo}@code{,}@var{id} --- extra thread info
20061
20062Where @var{id} is a thread-id in big-endian hex. Obtain a printable
20063string description of a thread's attributes from the target OS. This
20064string may contain anything that the target OS thinks is interesting for
20065@value{GDBN} to tell the user about the thread. The string is displayed
20066in @value{GDBN}'s @samp{info threads} display. Some examples of
20067possible thread extra info strings are ``Runnable'', or ``Blocked on
20068Mutex''.
20069
20070Reply:
20071@table @samp
20072@item @var{XX@dots{}}
20073Where @var{XX@dots{}} is a hex encoding of @sc{ascii} data, comprising
20074the printable string containing the extra information about the thread's
8e04817f 20075attributes.
ee2d5c50
AC
20076@end table
20077
20078@item @code{q}@code{L}@var{startflag}@var{threadcount}@var{nextthread} --- query @var{LIST} or @var{threadLIST} @strong{(deprecated)}
c906108c 20079
8e04817f
AC
20080Obtain thread information from RTOS. Where: @var{startflag} (one hex
20081digit) is one to indicate the first query and zero to indicate a
20082subsequent query; @var{threadcount} (two hex digits) is the maximum
20083number of threads the response packet can contain; and @var{nextthread}
20084(eight hex digits), for subsequent queries (@var{startflag} is zero), is
20085returned in the response as @var{argthread}.
ee2d5c50
AC
20086
20087NOTE: this query is replaced by the @code{q}@code{fThreadInfo} query
20088(see above).
20089
20090Reply:
20091@table @samp
20092@item @code{q}@code{M}@var{count}@var{done}@var{argthread}@var{thread@dots{}}
8e04817f
AC
20093Where: @var{count} (two hex digits) is the number of threads being
20094returned; @var{done} (one hex digit) is zero to indicate more threads
20095and one indicates no further threads; @var{argthreadid} (eight hex
ee2d5c50
AC
20096digits) is @var{nextthread} from the request packet; @var{thread@dots{}}
20097is a sequence of thread IDs from the target. @var{threadid} (eight hex
8e04817f 20098digits). See @code{remote.c:parse_threadlist_response()}.
ee2d5c50 20099@end table
c906108c 20100
ee2d5c50
AC
20101@item @code{q}@code{CRC:}@var{addr}@code{,}@var{length} --- compute CRC of memory block
20102
20103Reply:
20104@table @samp
20105@item @code{E}@var{NN}
20106An error (such as memory fault)
20107@item @code{C}@var{CRC32}
20108A 32 bit cyclic redundancy check of the specified memory region.
20109@end table
20110
20111@item @code{q}@code{Offsets} --- query sect offs
c906108c 20112
8e04817f
AC
20113Get section offsets that the target used when re-locating the downloaded
20114image. @emph{Note: while a @code{Bss} offset is included in the
20115response, @value{GDBN} ignores this and instead applies the @code{Data}
20116offset to the @code{Bss} section.}
c906108c 20117
ee2d5c50
AC
20118Reply:
20119@table @samp
20120@item @code{Text=}@var{xxx}@code{;Data=}@var{yyy}@code{;Bss=}@var{zzz}
20121@end table
20122
20123@item @code{q}@code{P}@var{mode}@var{threadid} --- thread info request
20124
8e04817f
AC
20125Returns information on @var{threadid}. Where: @var{mode} is a hex
20126encoded 32 bit mode; @var{threadid} is a hex encoded 64 bit thread ID.
ee2d5c50
AC
20127
20128Reply:
20129@table @samp
20130@item *
20131@end table
20132
8e04817f 20133See @code{remote.c:remote_unpack_thread_info_response()}.
c906108c 20134
ee2d5c50
AC
20135@item @code{q}@code{Rcmd,}@var{command} --- remote command
20136
20137@var{command} (hex encoded) is passed to the local interpreter for
8e04817f
AC
20138execution. Invalid commands should be reported using the output string.
20139Before the final result packet, the target may also respond with a
ee2d5c50
AC
20140number of intermediate @code{O}@var{output} console output packets.
20141@emph{Implementors should note that providing access to a stubs's
20142interpreter may have security implications}.
20143
20144Reply:
20145@table @samp
20146@item OK
8e04817f 20147A command response with no output.
ee2d5c50 20148@item @var{OUTPUT}
8e04817f 20149A command response with the hex encoded output string @var{OUTPUT}.
ee2d5c50 20150@item @code{E}@var{NN}
8e04817f 20151Indicate a badly formed request.
ee2d5c50 20152@item @samp{}
8e04817f 20153When @samp{q}@samp{Rcmd} is not recognized.
ee2d5c50
AC
20154@end table
20155
20156@item @code{qSymbol::} --- symbol lookup
c906108c 20157
8e04817f
AC
20158Notify the target that @value{GDBN} is prepared to serve symbol lookup
20159requests. Accept requests from the target for the values of symbols.
ee2d5c50
AC
20160
20161Reply:
20162@table @samp
20163@item @code{OK}
8e04817f 20164The target does not need to look up any (more) symbols.
ee2d5c50
AC
20165@item @code{qSymbol:}@var{sym_name}
20166The target requests the value of symbol @var{sym_name} (hex encoded).
20167@value{GDBN} may provide the value by using the
20168@code{qSymbol:}@var{sym_value}:@var{sym_name} message, described below.
20169@end table
20170
20171@item @code{qSymbol:}@var{sym_value}:@var{sym_name} --- symbol value
20172
20173Set the value of @var{sym_name} to @var{sym_value}.
20174
20175@var{sym_name} (hex encoded) is the name of a symbol whose value the
20176target has previously requested.
20177
20178@var{sym_value} (hex) is the value for symbol @var{sym_name}. If
20179@value{GDBN} cannot supply a value for @var{sym_name}, then this field
20180will be empty.
20181
20182Reply:
20183@table @samp
20184@item @code{OK}
8e04817f 20185The target does not need to look up any (more) symbols.
ee2d5c50
AC
20186@item @code{qSymbol:}@var{sym_name}
20187The target requests the value of a new symbol @var{sym_name} (hex
20188encoded). @value{GDBN} will continue to supply the values of symbols
20189(if available), until the target ceases to request them.
20190@end table
eb12ee30 20191
ee2d5c50
AC
20192@end table
20193
20194@node Register Packet Format
20195@section Register Packet Format
eb12ee30 20196
8e04817f 20197The following @samp{g}/@samp{G} packets have previously been defined.
ee2d5c50
AC
20198In the below, some thirty-two bit registers are transferred as
20199sixty-four bits. Those registers should be zero/sign extended (which?)
20200to fill the space allocated. Register bytes are transfered in target
20201byte order. The two nibbles within a register byte are transfered
20202most-significant - least-significant.
eb12ee30 20203
ee2d5c50 20204@table @r
eb12ee30 20205
8e04817f 20206@item MIPS32
ee2d5c50 20207
8e04817f
AC
20208All registers are transfered as thirty-two bit quantities in the order:
2020932 general-purpose; sr; lo; hi; bad; cause; pc; 32 floating-point
20210registers; fsr; fir; fp.
eb12ee30 20211
8e04817f 20212@item MIPS64
ee2d5c50 20213
8e04817f
AC
20214All registers are transfered as sixty-four bit quantities (including
20215thirty-two bit registers such as @code{sr}). The ordering is the same
20216as @code{MIPS32}.
eb12ee30 20217
ee2d5c50
AC
20218@end table
20219
20220@node Examples
20221@section Examples
eb12ee30 20222
8e04817f
AC
20223Example sequence of a target being re-started. Notice how the restart
20224does not get any direct output:
eb12ee30 20225
474c8240 20226@smallexample
d2c6833e
AC
20227-> @code{R00}
20228<- @code{+}
8e04817f 20229@emph{target restarts}
d2c6833e 20230-> @code{?}
8e04817f 20231<- @code{+}
d2c6833e
AC
20232<- @code{T001:1234123412341234}
20233-> @code{+}
474c8240 20234@end smallexample
eb12ee30 20235
8e04817f 20236Example sequence of a target being stepped by a single instruction:
eb12ee30 20237
474c8240 20238@smallexample
d2c6833e 20239-> @code{G1445@dots{}}
8e04817f 20240<- @code{+}
d2c6833e
AC
20241-> @code{s}
20242<- @code{+}
20243@emph{time passes}
20244<- @code{T001:1234123412341234}
8e04817f 20245-> @code{+}
d2c6833e 20246-> @code{g}
8e04817f 20247<- @code{+}
d2c6833e
AC
20248<- @code{1455@dots{}}
20249-> @code{+}
474c8240 20250@end smallexample
eb12ee30 20251
0ce1b118
CV
20252@node File-I/O remote protocol extension
20253@section File-I/O remote protocol extension
20254@cindex File-I/O remote protocol extension
20255
20256@menu
20257* File-I/O Overview::
20258* Protocol basics::
20259* The `F' request packet::
20260* The `F' reply packet::
20261* Memory transfer::
20262* The Ctrl-C message::
20263* Console I/O::
20264* The isatty call::
20265* The system call::
20266* List of supported calls::
20267* Protocol specific representation of datatypes::
20268* Constants::
20269* File-I/O Examples::
20270@end menu
20271
20272@node File-I/O Overview
20273@subsection File-I/O Overview
20274@cindex file-i/o overview
20275
20276The File I/O remote protocol extension (short: File-I/O) allows the
20277target to use the hosts file system and console I/O when calling various
20278system calls. System calls on the target system are translated into a
20279remote protocol packet to the host system which then performs the needed
20280actions and returns with an adequate response packet to the target system.
20281This simulates file system operations even on targets that lack file systems.
20282
20283The protocol is defined host- and target-system independent. It uses
20284it's own independent representation of datatypes and values. Both,
20285@value{GDBN} and the target's @value{GDBN} stub are responsible for
20286translating the system dependent values into the unified protocol values
20287when data is transmitted.
20288
20289The communication is synchronous. A system call is possible only
20290when GDB is waiting for the @samp{C}, @samp{c}, @samp{S} or @samp{s}
20291packets. While @value{GDBN} handles the request for a system call,
20292the target is stopped to allow deterministic access to the target's
20293memory. Therefore File-I/O is not interuptible by target signals. It
20294is possible to interrupt File-I/O by a user interrupt (Ctrl-C), though.
20295
20296The target's request to perform a host system call does not finish
20297the latest @samp{C}, @samp{c}, @samp{S} or @samp{s} action. That means,
20298after finishing the system call, the target returns to continuing the
20299previous activity (continue, step). No additional continue or step
20300request from @value{GDBN} is required.
20301
20302@smallexample
20303(gdb) continue
20304 <- target requests 'system call X'
20305 target is stopped, @value{GDBN} executes system call
20306 -> GDB returns result
20307 ... target continues, GDB returns to wait for the target
20308 <- target hits breakpoint and sends a Txx packet
20309@end smallexample
20310
20311The protocol is only used for files on the host file system and
20312for I/O on the console. Character or block special devices, pipes,
20313named pipes or sockets or any other communication method on the host
20314system are not supported by this protocol.
20315
20316@node Protocol basics
20317@subsection Protocol basics
20318@cindex protocol basics, file-i/o
20319
20320The File-I/O protocol uses the @code{F} packet, as request as well
20321as as reply packet. Since a File-I/O system call can only occur when
20322@value{GDBN} is waiting for the continuing or stepping target, the
20323File-I/O request is a reply that @value{GDBN} has to expect as a result
20324of a former @samp{C}, @samp{c}, @samp{S} or @samp{s} packet.
20325This @code{F} packet contains all information needed to allow @value{GDBN}
20326to call the appropriate host system call:
20327
20328@itemize @bullet
20329@item
20330A unique identifier for the requested system call.
20331
20332@item
20333All parameters to the system call. Pointers are given as addresses
20334in the target memory address space. Pointers to strings are given as
20335pointer/length pair. Numerical values are given as they are.
20336Numerical control values are given in a protocol specific representation.
20337
20338@end itemize
20339
20340At that point @value{GDBN} has to perform the following actions.
20341
20342@itemize @bullet
20343@item
20344If parameter pointer values are given, which point to data needed as input
20345to a system call, @value{GDBN} requests this data from the target with a
20346standard @code{m} packet request. This additional communication has to be
20347expected by the target implementation and is handled as any other @code{m}
20348packet.
20349
20350@item
20351@value{GDBN} translates all value from protocol representation to host
20352representation as needed. Datatypes are coerced into the host types.
20353
20354@item
20355@value{GDBN} calls the system call
20356
20357@item
20358It then coerces datatypes back to protocol representation.
20359
20360@item
20361If pointer parameters in the request packet point to buffer space in which
20362a system call is expected to copy data to, the data is transmitted to the
20363target using a @code{M} or @code{X} packet. This packet has to be expected
20364by the target implementation and is handled as any other @code{M} or @code{X}
20365packet.
20366
20367@end itemize
20368
20369Eventually @value{GDBN} replies with another @code{F} packet which contains all
20370necessary information for the target to continue. This at least contains
20371
20372@itemize @bullet
20373@item
20374Return value.
20375
20376@item
20377@code{errno}, if has been changed by the system call.
20378
20379@item
20380``Ctrl-C'' flag.
20381
20382@end itemize
20383
20384After having done the needed type and value coercion, the target continues
20385the latest continue or step action.
20386
20387@node The `F' request packet
20388@subsection The @code{F} request packet
20389@cindex file-i/o request packet
20390@cindex @code{F} request packet
20391
20392The @code{F} request packet has the following format:
20393
20394@table @samp
20395
20396@smallexample
20397@code{F}@var{call-id}@code{,}@var{parameter@dots{}}
20398@end smallexample
20399
20400@var{call-id} is the identifier to indicate the host system call to be called.
20401This is just the name of the function.
20402
20403@var{parameter@dots{}} are the parameters to the system call.
20404
20405@end table
20406
20407Parameters are hexadecimal integer values, either the real values in case
20408of scalar datatypes, as pointers to target buffer space in case of compound
20409datatypes and unspecified memory areas or as pointer/length pairs in case
20410of string parameters. These are appended to the call-id, each separated
20411from its predecessor by a comma. All values are transmitted in ASCII
20412string representation, pointer/length pairs separated by a slash.
20413
20414@node The `F' reply packet
20415@subsection The @code{F} reply packet
20416@cindex file-i/o reply packet
20417@cindex @code{F} reply packet
20418
20419The @code{F} reply packet has the following format:
20420
20421@table @samp
20422
20423@smallexample
20424@code{F}@var{retcode}@code{,}@var{errno}@code{,}@var{Ctrl-C flag}@code{;}@var{call specific attachment}
20425@end smallexample
20426
20427@var{retcode} is the return code of the system call as hexadecimal value.
20428
20429@var{errno} is the errno set by the call, in protocol specific representation.
20430This parameter can be omitted if the call was successful.
20431
20432@var{Ctrl-C flag} is only send if the user requested a break. In this
20433case, @var{errno} must be send as well, even if the call was successful.
20434The @var{Ctrl-C flag} itself consists of the character 'C':
20435
20436@smallexample
20437F0,0,C
20438@end smallexample
20439
20440@noindent
20441or, if the call was interupted before the host call has been performed:
20442
20443@smallexample
20444F-1,4,C
20445@end smallexample
20446
20447@noindent
20448assuming 4 is the protocol specific representation of @code{EINTR}.
20449
20450@end table
20451
20452@node Memory transfer
20453@subsection Memory transfer
20454@cindex memory transfer, in file-i/o protocol
20455
20456Structured data which is transferred using a memory read or write as e.g.@:
20457a @code{struct stat} is expected to be in a protocol specific format with
20458all scalar multibyte datatypes being big endian. This should be done by
20459the target before the @code{F} packet is sent resp.@: by @value{GDBN} before
20460it transfers memory to the target. Transferred pointers to structured
20461data should point to the already coerced data at any time.
20462
20463@node The Ctrl-C message
20464@subsection The Ctrl-C message
20465@cindex ctrl-c message, in file-i/o protocol
20466
20467A special case is, if the @var{Ctrl-C flag} is set in the @value{GDBN}
20468reply packet. In this case the target should behave, as if it had
20469gotten a break message. The meaning for the target is ``system call
20470interupted by @code{SIGINT}''. Consequentially, the target should actually stop
20471(as with a break message) and return to @value{GDBN} with a @code{T02}
20472packet. In this case, it's important for the target to know, in which
20473state the system call was interrupted. Since this action is by design
20474not an atomic operation, we have to differ between two cases:
20475
20476@itemize @bullet
20477@item
20478The system call hasn't been performed on the host yet.
20479
20480@item
20481The system call on the host has been finished.
20482
20483@end itemize
20484
20485These two states can be distinguished by the target by the value of the
20486returned @code{errno}. If it's the protocol representation of @code{EINTR}, the system
20487call hasn't been performed. This is equivalent to the @code{EINTR} handling
20488on POSIX systems. In any other case, the target may presume that the
20489system call has been finished --- successful or not --- and should behave
20490as if the break message arrived right after the system call.
20491
20492@value{GDBN} must behave reliable. If the system call has not been called
20493yet, @value{GDBN} may send the @code{F} reply immediately, setting @code{EINTR} as
20494@code{errno} in the packet. If the system call on the host has been finished
20495before the user requests a break, the full action must be finshed by
20496@value{GDBN}. This requires sending @code{M} or @code{X} packets as they fit.
20497The @code{F} packet may only be send when either nothing has happened
20498or the full action has been completed.
20499
20500@node Console I/O
20501@subsection Console I/O
20502@cindex console i/o as part of file-i/o
20503
20504By default and if not explicitely closed by the target system, the file
20505descriptors 0, 1 and 2 are connected to the @value{GDBN} console. Output
20506on the @value{GDBN} console is handled as any other file output operation
20507(@code{write(1, @dots{})} or @code{write(2, @dots{})}). Console input is handled
20508by @value{GDBN} so that after the target read request from file descriptor
205090 all following typing is buffered until either one of the following
20510conditions is met:
20511
20512@itemize @bullet
20513@item
20514The user presses @kbd{Ctrl-C}. The behaviour is as explained above, the
20515@code{read}
20516system call is treated as finished.
20517
20518@item
20519The user presses @kbd{Enter}. This is treated as end of input with a trailing
20520line feed.
20521
20522@item
20523The user presses @kbd{Ctrl-D}. This is treated as end of input. No trailing
20524character, especially no Ctrl-D is appended to the input.
20525
20526@end itemize
20527
20528If the user has typed more characters as fit in the buffer given to
20529the read call, the trailing characters are buffered in @value{GDBN} until
20530either another @code{read(0, @dots{})} is requested by the target or debugging
20531is stopped on users request.
20532
20533@node The isatty call
20534@subsection The isatty(3) call
20535@cindex isatty call, file-i/o protocol
20536
20537A special case in this protocol is the library call @code{isatty} which
20538is implemented as it's own call inside of this protocol. It returns
205391 to the target if the file descriptor given as parameter is attached
20540to the @value{GDBN} console, 0 otherwise. Implementing through system calls
20541would require implementing @code{ioctl} and would be more complex than
20542needed.
20543
20544@node The system call
20545@subsection The system(3) call
20546@cindex system call, file-i/o protocol
20547
20548The other special case in this protocol is the @code{system} call which
20549is implemented as it's own call, too. @value{GDBN} is taking over the full
20550task of calling the necessary host calls to perform the @code{system}
20551call. The return value of @code{system} is simplified before it's returned
20552to the target. Basically, the only signal transmitted back is @code{EINTR}
20553in case the user pressed @kbd{Ctrl-C}. Otherwise the return value consists
20554entirely of the exit status of the called command.
20555
20556Due to security concerns, the @code{system} call is refused to be called
20557by @value{GDBN} by default. The user has to allow this call explicitly by
20558entering
20559
20560@table @samp
20561@kindex set remote system-call-allowed 1
20562@item @code{set remote system-call-allowed 1}
20563@end table
20564
20565Disabling the @code{system} call is done by
20566
20567@table @samp
20568@kindex set remote system-call-allowed 0
20569@item @code{set remote system-call-allowed 0}
20570@end table
20571
20572The current setting is shown by typing
20573
20574@table @samp
20575@kindex show remote system-call-allowed
20576@item @code{show remote system-call-allowed}
20577@end table
20578
20579@node List of supported calls
20580@subsection List of supported calls
20581@cindex list of supported file-i/o calls
20582
20583@menu
20584* open::
20585* close::
20586* read::
20587* write::
20588* lseek::
20589* rename::
20590* unlink::
20591* stat/fstat::
20592* gettimeofday::
20593* isatty::
20594* system::
20595@end menu
20596
20597@node open
20598@unnumberedsubsubsec open
20599@cindex open, file-i/o system call
20600
20601@smallexample
20602@exdent Synopsis:
20603int open(const char *pathname, int flags);
20604int open(const char *pathname, int flags, mode_t mode);
20605
20606@exdent Request:
20607Fopen,pathptr/len,flags,mode
20608@end smallexample
20609
20610@noindent
20611@code{flags} is the bitwise or of the following values:
20612
20613@table @code
20614@item O_CREAT
20615If the file does not exist it will be created. The host
20616rules apply as far as file ownership and time stamps
20617are concerned.
20618
20619@item O_EXCL
20620When used with O_CREAT, if the file already exists it is
20621an error and open() fails.
20622
20623@item O_TRUNC
20624If the file already exists and the open mode allows
20625writing (O_RDWR or O_WRONLY is given) it will be
20626truncated to length 0.
20627
20628@item O_APPEND
20629The file is opened in append mode.
20630
20631@item O_RDONLY
20632The file is opened for reading only.
20633
20634@item O_WRONLY
20635The file is opened for writing only.
20636
20637@item O_RDWR
20638The file is opened for reading and writing.
20639
20640@noindent
20641Each other bit is silently ignored.
20642
20643@end table
20644
20645@noindent
20646@code{mode} is the bitwise or of the following values:
20647
20648@table @code
20649@item S_IRUSR
20650User has read permission.
20651
20652@item S_IWUSR
20653User has write permission.
20654
20655@item S_IRGRP
20656Group has read permission.
20657
20658@item S_IWGRP
20659Group has write permission.
20660
20661@item S_IROTH
20662Others have read permission.
20663
20664@item S_IWOTH
20665Others have write permission.
20666
20667@noindent
20668Each other bit is silently ignored.
20669
20670@end table
20671
20672@smallexample
20673@exdent Return value:
20674open returns the new file descriptor or -1 if an error
20675occured.
20676
20677@exdent Errors:
20678@end smallexample
20679
20680@table @code
20681@item EEXIST
20682pathname already exists and O_CREAT and O_EXCL were used.
20683
20684@item EISDIR
20685pathname refers to a directory.
20686
20687@item EACCES
20688The requested access is not allowed.
20689
20690@item ENAMETOOLONG
20691pathname was too long.
20692
20693@item ENOENT
20694A directory component in pathname does not exist.
20695
20696@item ENODEV
20697pathname refers to a device, pipe, named pipe or socket.
20698
20699@item EROFS
20700pathname refers to a file on a read-only filesystem and
20701write access was requested.
20702
20703@item EFAULT
20704pathname is an invalid pointer value.
20705
20706@item ENOSPC
20707No space on device to create the file.
20708
20709@item EMFILE
20710The process already has the maximum number of files open.
20711
20712@item ENFILE
20713The limit on the total number of files open on the system
20714has been reached.
20715
20716@item EINTR
20717The call was interrupted by the user.
20718@end table
20719
20720@node close
20721@unnumberedsubsubsec close
20722@cindex close, file-i/o system call
20723
20724@smallexample
20725@exdent Synopsis:
20726int close(int fd);
20727
20728@exdent Request:
20729Fclose,fd
20730
20731@exdent Return value:
20732close returns zero on success, or -1 if an error occurred.
20733
20734@exdent Errors:
20735@end smallexample
20736
20737@table @code
20738@item EBADF
20739fd isn't a valid open file descriptor.
20740
20741@item EINTR
20742The call was interrupted by the user.
20743@end table
20744
20745@node read
20746@unnumberedsubsubsec read
20747@cindex read, file-i/o system call
20748
20749@smallexample
20750@exdent Synopsis:
20751int read(int fd, void *buf, unsigned int count);
20752
20753@exdent Request:
20754Fread,fd,bufptr,count
20755
20756@exdent Return value:
20757On success, the number of bytes read is returned.
20758Zero indicates end of file. If count is zero, read
20759returns zero as well. On error, -1 is returned.
20760
20761@exdent Errors:
20762@end smallexample
20763
20764@table @code
20765@item EBADF
20766fd is not a valid file descriptor or is not open for
20767reading.
20768
20769@item EFAULT
20770buf is an invalid pointer value.
20771
20772@item EINTR
20773The call was interrupted by the user.
20774@end table
20775
20776@node write
20777@unnumberedsubsubsec write
20778@cindex write, file-i/o system call
20779
20780@smallexample
20781@exdent Synopsis:
20782int write(int fd, const void *buf, unsigned int count);
20783
20784@exdent Request:
20785Fwrite,fd,bufptr,count
20786
20787@exdent Return value:
20788On success, the number of bytes written are returned.
20789Zero indicates nothing was written. On error, -1
20790is returned.
20791
20792@exdent Errors:
20793@end smallexample
20794
20795@table @code
20796@item EBADF
20797fd is not a valid file descriptor or is not open for
20798writing.
20799
20800@item EFAULT
20801buf is an invalid pointer value.
20802
20803@item EFBIG
20804An attempt was made to write a file that exceeds the
20805host specific maximum file size allowed.
20806
20807@item ENOSPC
20808No space on device to write the data.
20809
20810@item EINTR
20811The call was interrupted by the user.
20812@end table
20813
20814@node lseek
20815@unnumberedsubsubsec lseek
20816@cindex lseek, file-i/o system call
20817
20818@smallexample
20819@exdent Synopsis:
20820long lseek (int fd, long offset, int flag);
20821
20822@exdent Request:
20823Flseek,fd,offset,flag
20824@end smallexample
20825
20826@code{flag} is one of:
20827
20828@table @code
20829@item SEEK_SET
20830The offset is set to offset bytes.
20831
20832@item SEEK_CUR
20833The offset is set to its current location plus offset
20834bytes.
20835
20836@item SEEK_END
20837The offset is set to the size of the file plus offset
20838bytes.
20839@end table
20840
20841@smallexample
20842@exdent Return value:
20843On success, the resulting unsigned offset in bytes from
20844the beginning of the file is returned. Otherwise, a
20845value of -1 is returned.
20846
20847@exdent Errors:
20848@end smallexample
20849
20850@table @code
20851@item EBADF
20852fd is not a valid open file descriptor.
20853
20854@item ESPIPE
20855fd is associated with the @value{GDBN} console.
20856
20857@item EINVAL
20858flag is not a proper value.
20859
20860@item EINTR
20861The call was interrupted by the user.
20862@end table
20863
20864@node rename
20865@unnumberedsubsubsec rename
20866@cindex rename, file-i/o system call
20867
20868@smallexample
20869@exdent Synopsis:
20870int rename(const char *oldpath, const char *newpath);
20871
20872@exdent Request:
20873Frename,oldpathptr/len,newpathptr/len
20874
20875@exdent Return value:
20876On success, zero is returned. On error, -1 is returned.
20877
20878@exdent Errors:
20879@end smallexample
20880
20881@table @code
20882@item EISDIR
20883newpath is an existing directory, but oldpath is not a
20884directory.
20885
20886@item EEXIST
20887newpath is a non-empty directory.
20888
20889@item EBUSY
20890oldpath or newpath is a directory that is in use by some
20891process.
20892
20893@item EINVAL
20894An attempt was made to make a directory a subdirectory
20895of itself.
20896
20897@item ENOTDIR
20898A component used as a directory in oldpath or new
20899path is not a directory. Or oldpath is a directory
20900and newpath exists but is not a directory.
20901
20902@item EFAULT
20903oldpathptr or newpathptr are invalid pointer values.
20904
20905@item EACCES
20906No access to the file or the path of the file.
20907
20908@item ENAMETOOLONG
20909
20910oldpath or newpath was too long.
20911
20912@item ENOENT
20913A directory component in oldpath or newpath does not exist.
20914
20915@item EROFS
20916The file is on a read-only filesystem.
20917
20918@item ENOSPC
20919The device containing the file has no room for the new
20920directory entry.
20921
20922@item EINTR
20923The call was interrupted by the user.
20924@end table
20925
20926@node unlink
20927@unnumberedsubsubsec unlink
20928@cindex unlink, file-i/o system call
20929
20930@smallexample
20931@exdent Synopsis:
20932int unlink(const char *pathname);
20933
20934@exdent Request:
20935Funlink,pathnameptr/len
20936
20937@exdent Return value:
20938On success, zero is returned. On error, -1 is returned.
20939
20940@exdent Errors:
20941@end smallexample
20942
20943@table @code
20944@item EACCES
20945No access to the file or the path of the file.
20946
20947@item EPERM
20948The system does not allow unlinking of directories.
20949
20950@item EBUSY
20951The file pathname cannot be unlinked because it's
20952being used by another process.
20953
20954@item EFAULT
20955pathnameptr is an invalid pointer value.
20956
20957@item ENAMETOOLONG
20958pathname was too long.
20959
20960@item ENOENT
20961A directory component in pathname does not exist.
20962
20963@item ENOTDIR
20964A component of the path is not a directory.
20965
20966@item EROFS
20967The file is on a read-only filesystem.
20968
20969@item EINTR
20970The call was interrupted by the user.
20971@end table
20972
20973@node stat/fstat
20974@unnumberedsubsubsec stat/fstat
20975@cindex fstat, file-i/o system call
20976@cindex stat, file-i/o system call
20977
20978@smallexample
20979@exdent Synopsis:
20980int stat(const char *pathname, struct stat *buf);
20981int fstat(int fd, struct stat *buf);
20982
20983@exdent Request:
20984Fstat,pathnameptr/len,bufptr
20985Ffstat,fd,bufptr
20986
20987@exdent Return value:
20988On success, zero is returned. On error, -1 is returned.
20989
20990@exdent Errors:
20991@end smallexample
20992
20993@table @code
20994@item EBADF
20995fd is not a valid open file.
20996
20997@item ENOENT
20998A directory component in pathname does not exist or the
20999path is an empty string.
21000
21001@item ENOTDIR
21002A component of the path is not a directory.
21003
21004@item EFAULT
21005pathnameptr is an invalid pointer value.
21006
21007@item EACCES
21008No access to the file or the path of the file.
21009
21010@item ENAMETOOLONG
21011pathname was too long.
21012
21013@item EINTR
21014The call was interrupted by the user.
21015@end table
21016
21017@node gettimeofday
21018@unnumberedsubsubsec gettimeofday
21019@cindex gettimeofday, file-i/o system call
21020
21021@smallexample
21022@exdent Synopsis:
21023int gettimeofday(struct timeval *tv, void *tz);
21024
21025@exdent Request:
21026Fgettimeofday,tvptr,tzptr
21027
21028@exdent Return value:
21029On success, 0 is returned, -1 otherwise.
21030
21031@exdent Errors:
21032@end smallexample
21033
21034@table @code
21035@item EINVAL
21036tz is a non-NULL pointer.
21037
21038@item EFAULT
21039tvptr and/or tzptr is an invalid pointer value.
21040@end table
21041
21042@node isatty
21043@unnumberedsubsubsec isatty
21044@cindex isatty, file-i/o system call
21045
21046@smallexample
21047@exdent Synopsis:
21048int isatty(int fd);
21049
21050@exdent Request:
21051Fisatty,fd
21052
21053@exdent Return value:
21054Returns 1 if fd refers to the @value{GDBN} console, 0 otherwise.
21055
21056@exdent Errors:
21057@end smallexample
21058
21059@table @code
21060@item EINTR
21061The call was interrupted by the user.
21062@end table
21063
21064@node system
21065@unnumberedsubsubsec system
21066@cindex system, file-i/o system call
21067
21068@smallexample
21069@exdent Synopsis:
21070int system(const char *command);
21071
21072@exdent Request:
21073Fsystem,commandptr/len
21074
21075@exdent Return value:
21076The value returned is -1 on error and the return status
21077of the command otherwise. Only the exit status of the
21078command is returned, which is extracted from the hosts
21079system return value by calling WEXITSTATUS(retval).
21080In case /bin/sh could not be executed, 127 is returned.
21081
21082@exdent Errors:
21083@end smallexample
21084
21085@table @code
21086@item EINTR
21087The call was interrupted by the user.
21088@end table
21089
21090@node Protocol specific representation of datatypes
21091@subsection Protocol specific representation of datatypes
21092@cindex protocol specific representation of datatypes, in file-i/o protocol
21093
21094@menu
21095* Integral datatypes::
21096* Pointer values::
21097* struct stat::
21098* struct timeval::
21099@end menu
21100
21101@node Integral datatypes
21102@unnumberedsubsubsec Integral datatypes
21103@cindex integral datatypes, in file-i/o protocol
21104
21105The integral datatypes used in the system calls are
21106
21107@smallexample
21108int@r{,} unsigned int@r{,} long@r{,} unsigned long@r{,} mode_t @r{and} time_t
21109@end smallexample
21110
21111@code{Int}, @code{unsigned int}, @code{mode_t} and @code{time_t} are
21112implemented as 32 bit values in this protocol.
21113
21114@code{Long} and @code{unsigned long} are implemented as 64 bit types.
21115
21116@xref{Limits}, for corresponding MIN and MAX values (similar to those
21117in @file{limits.h}) to allow range checking on host and target.
21118
21119@code{time_t} datatypes are defined as seconds since the Epoch.
21120
21121All integral datatypes transferred as part of a memory read or write of a
21122structured datatype e.g.@: a @code{struct stat} have to be given in big endian
21123byte order.
21124
21125@node Pointer values
21126@unnumberedsubsubsec Pointer values
21127@cindex pointer values, in file-i/o protocol
21128
21129Pointers to target data are transmitted as they are. An exception
21130is made for pointers to buffers for which the length isn't
21131transmitted as part of the function call, namely strings. Strings
21132are transmitted as a pointer/length pair, both as hex values, e.g.@:
21133
21134@smallexample
21135@code{1aaf/12}
21136@end smallexample
21137
21138@noindent
21139which is a pointer to data of length 18 bytes at position 0x1aaf.
21140The length is defined as the full string length in bytes, including
21141the trailing null byte. Example:
21142
21143@smallexample
21144``hello, world'' at address 0x123456
21145@end smallexample
21146
21147@noindent
21148is transmitted as
21149
21150@smallexample
21151@code{123456/d}
21152@end smallexample
21153
21154@node struct stat
21155@unnumberedsubsubsec struct stat
21156@cindex struct stat, in file-i/o protocol
21157
21158The buffer of type struct stat used by the target and @value{GDBN} is defined
21159as follows:
21160
21161@smallexample
21162struct stat @{
21163 unsigned int st_dev; /* device */
21164 unsigned int st_ino; /* inode */
21165 mode_t st_mode; /* protection */
21166 unsigned int st_nlink; /* number of hard links */
21167 unsigned int st_uid; /* user ID of owner */
21168 unsigned int st_gid; /* group ID of owner */
21169 unsigned int st_rdev; /* device type (if inode device) */
21170 unsigned long st_size; /* total size, in bytes */
21171 unsigned long st_blksize; /* blocksize for filesystem I/O */
21172 unsigned long st_blocks; /* number of blocks allocated */
21173 time_t st_atime; /* time of last access */
21174 time_t st_mtime; /* time of last modification */
21175 time_t st_ctime; /* time of last change */
21176@};
21177@end smallexample
21178
21179The integral datatypes are conforming to the definitions given in the
21180approriate section (see @ref{Integral datatypes}, for details) so this
21181structure is of size 64 bytes.
21182
21183The values of several fields have a restricted meaning and/or
21184range of values.
21185
21186@smallexample
21187st_dev: 0 file
21188 1 console
21189
21190st_ino: No valid meaning for the target. Transmitted unchanged.
21191
21192st_mode: Valid mode bits are described in Appendix C. Any other
21193 bits have currently no meaning for the target.
21194
21195st_uid: No valid meaning for the target. Transmitted unchanged.
21196
21197st_gid: No valid meaning for the target. Transmitted unchanged.
21198
21199st_rdev: No valid meaning for the target. Transmitted unchanged.
21200
21201st_atime, st_mtime, st_ctime:
21202 These values have a host and file system dependent
21203 accuracy. Especially on Windows hosts the file systems
21204 don't support exact timing values.
21205@end smallexample
21206
21207The target gets a struct stat of the above representation and is
21208responsible to coerce it to the target representation before
21209continuing.
21210
21211Note that due to size differences between the host and target
21212representation of stat members, these members could eventually
21213get truncated on the target.
21214
21215@node struct timeval
21216@unnumberedsubsubsec struct timeval
21217@cindex struct timeval, in file-i/o protocol
21218
21219The buffer of type struct timeval used by the target and @value{GDBN}
21220is defined as follows:
21221
21222@smallexample
21223struct timeval @{
21224 time_t tv_sec; /* second */
21225 long tv_usec; /* microsecond */
21226@};
21227@end smallexample
21228
21229The integral datatypes are conforming to the definitions given in the
21230approriate section (see @ref{Integral datatypes}, for details) so this
21231structure is of size 8 bytes.
21232
21233@node Constants
21234@subsection Constants
21235@cindex constants, in file-i/o protocol
21236
21237The following values are used for the constants inside of the
21238protocol. @value{GDBN} and target are resposible to translate these
21239values before and after the call as needed.
21240
21241@menu
21242* Open flags::
21243* mode_t values::
21244* Errno values::
21245* Lseek flags::
21246* Limits::
21247@end menu
21248
21249@node Open flags
21250@unnumberedsubsubsec Open flags
21251@cindex open flags, in file-i/o protocol
21252
21253All values are given in hexadecimal representation.
21254
21255@smallexample
21256 O_RDONLY 0x0
21257 O_WRONLY 0x1
21258 O_RDWR 0x2
21259 O_APPEND 0x8
21260 O_CREAT 0x200
21261 O_TRUNC 0x400
21262 O_EXCL 0x800
21263@end smallexample
21264
21265@node mode_t values
21266@unnumberedsubsubsec mode_t values
21267@cindex mode_t values, in file-i/o protocol
21268
21269All values are given in octal representation.
21270
21271@smallexample
21272 S_IFREG 0100000
21273 S_IFDIR 040000
21274 S_IRUSR 0400
21275 S_IWUSR 0200
21276 S_IXUSR 0100
21277 S_IRGRP 040
21278 S_IWGRP 020
21279 S_IXGRP 010
21280 S_IROTH 04
21281 S_IWOTH 02
21282 S_IXOTH 01
21283@end smallexample
21284
21285@node Errno values
21286@unnumberedsubsubsec Errno values
21287@cindex errno values, in file-i/o protocol
21288
21289All values are given in decimal representation.
21290
21291@smallexample
21292 EPERM 1
21293 ENOENT 2
21294 EINTR 4
21295 EBADF 9
21296 EACCES 13
21297 EFAULT 14
21298 EBUSY 16
21299 EEXIST 17
21300 ENODEV 19
21301 ENOTDIR 20
21302 EISDIR 21
21303 EINVAL 22
21304 ENFILE 23
21305 EMFILE 24
21306 EFBIG 27
21307 ENOSPC 28
21308 ESPIPE 29
21309 EROFS 30
21310 ENAMETOOLONG 91
21311 EUNKNOWN 9999
21312@end smallexample
21313
21314 EUNKNOWN is used as a fallback error value if a host system returns
21315 any error value not in the list of supported error numbers.
21316
21317@node Lseek flags
21318@unnumberedsubsubsec Lseek flags
21319@cindex lseek flags, in file-i/o protocol
21320
21321@smallexample
21322 SEEK_SET 0
21323 SEEK_CUR 1
21324 SEEK_END 2
21325@end smallexample
21326
21327@node Limits
21328@unnumberedsubsubsec Limits
21329@cindex limits, in file-i/o protocol
21330
21331All values are given in decimal representation.
21332
21333@smallexample
21334 INT_MIN -2147483648
21335 INT_MAX 2147483647
21336 UINT_MAX 4294967295
21337 LONG_MIN -9223372036854775808
21338 LONG_MAX 9223372036854775807
21339 ULONG_MAX 18446744073709551615
21340@end smallexample
21341
21342@node File-I/O Examples
21343@subsection File-I/O Examples
21344@cindex file-i/o examples
21345
21346Example sequence of a write call, file descriptor 3, buffer is at target
21347address 0x1234, 6 bytes should be written:
21348
21349@smallexample
21350<- @code{Fwrite,3,1234,6}
21351@emph{request memory read from target}
21352-> @code{m1234,6}
21353<- XXXXXX
21354@emph{return "6 bytes written"}
21355-> @code{F6}
21356@end smallexample
21357
21358Example sequence of a read call, file descriptor 3, buffer is at target
21359address 0x1234, 6 bytes should be read:
21360
21361@smallexample
21362<- @code{Fread,3,1234,6}
21363@emph{request memory write to target}
21364-> @code{X1234,6:XXXXXX}
21365@emph{return "6 bytes read"}
21366-> @code{F6}
21367@end smallexample
21368
21369Example sequence of a read call, call fails on the host due to invalid
21370file descriptor (EBADF):
21371
21372@smallexample
21373<- @code{Fread,3,1234,6}
21374-> @code{F-1,9}
21375@end smallexample
21376
21377Example sequence of a read call, user presses Ctrl-C before syscall on
21378host is called:
21379
21380@smallexample
21381<- @code{Fread,3,1234,6}
21382-> @code{F-1,4,C}
21383<- @code{T02}
21384@end smallexample
21385
21386Example sequence of a read call, user presses Ctrl-C after syscall on
21387host is called:
21388
21389@smallexample
21390<- @code{Fread,3,1234,6}
21391-> @code{X1234,6:XXXXXX}
21392<- @code{T02}
21393@end smallexample
21394
f418dd93
DJ
21395@include agentexpr.texi
21396
aab4e0ec 21397@include gpl.texi
eb12ee30 21398
6826cf00
EZ
21399@include fdl.texi
21400
6d2ebf8b 21401@node Index
c906108c
SS
21402@unnumbered Index
21403
21404@printindex cp
21405
21406@tex
21407% I think something like @colophon should be in texinfo. In the
21408% meantime:
21409\long\def\colophon{\hbox to0pt{}\vfill
21410\centerline{The body of this manual is set in}
21411\centerline{\fontname\tenrm,}
21412\centerline{with headings in {\bf\fontname\tenbf}}
21413\centerline{and examples in {\tt\fontname\tentt}.}
21414\centerline{{\it\fontname\tenit\/},}
21415\centerline{{\bf\fontname\tenbf}, and}
21416\centerline{{\sl\fontname\tensl\/}}
21417\centerline{are used for emphasis.}\vfill}
21418\page\colophon
21419% Blame: doc@cygnus.com, 1991.
21420@end tex
21421
c906108c 21422@bye
This page took 1.388494 seconds and 4 git commands to generate.