]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blame - gdb/doc/gdb.texinfo
* gdb.base/bigcore.exp: Deactivate on IRIX targets.
[thirdparty/binutils-gdb.git] / gdb / doc / gdb.texinfo
CommitLineData
c906108c 1\input texinfo @c -*-texinfo-*-
b6ba6518 2@c Copyright 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1998,
c552b3bb 3@c 1999, 2000, 2001, 2002, 2003, 2004
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.
03727ca6 41@dircategory Software development
96a2c332 42@direntry
03727ca6 43* Gdb: (gdb). The 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,@*
c552b3bb 55 1999, 2000, 2001, 2002, 2003, 2004 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,
b51970ac 871996, 1998, 1999, 2000, 2001, 2002, 2003, 2004 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
c552b3bb 118Copyright (C) 1988-2004 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
49efadf5 195You can use @value{GDBN} to debug programs written in C and C@t{++}.
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:
faae5abe 350Andrew Cagney (releases 6.1, 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 420
f24c5e49
KI
421Hitachi America (now Renesas America), Ltd. sponsored the support for
422H8/300, H8/500, and Super-H processors.
c906108c
SS
423
424NEC sponsored the support for the v850, Vr4xxx, and Vr5xxx processors.
425
f24c5e49
KI
426Mitsubishi (now Renesas) sponsored the support for D10V, D30V, and M32R/D
427processors.
c906108c
SS
428
429Toshiba sponsored the support for the TX39 Mips processor.
430
431Matsushita sponsored the support for the MN10200 and MN10300 processors.
432
96a2c332 433Fujitsu sponsored the support for SPARClite and FR30 processors.
c906108c
SS
434
435Kung Hsu, Jeff Law, and Rick Sladkey added support for hardware
436watchpoints.
437
438Michael Snyder added support for tracepoints.
439
440Stu Grossman wrote gdbserver.
441
442Jim Kingdon, Peter Schauer, Ian Taylor, and Stu Grossman made
96a2c332 443nearly innumerable bug fixes and cleanups throughout @value{GDBN}.
c906108c
SS
444
445The following people at the Hewlett-Packard Company contributed
446support for the PA-RISC 2.0 architecture, HP-UX 10.20, 10.30, and 11.0
b37052ae 447(narrow mode), HP's implementation of kernel threads, HP's aC@t{++}
d0d5df6f
AC
448compiler, and the Text User Interface (nee Terminal User Interface):
449Ben Krepp, Richard Title, John Bishop, Susan Macchia, Kathy Mann,
450Satish Pai, India Paul, Steve Rehrauer, and Elena Zannoni. Kim Haase
451provided HP-specific information in this manual.
c906108c 452
b37052ae
EZ
453DJ Delorie ported @value{GDBN} to MS-DOS, for the DJGPP project.
454Robert Hoehne made significant contributions to the DJGPP port.
455
96a2c332
SS
456Cygnus Solutions has sponsored @value{GDBN} maintenance and much of its
457development since 1991. Cygnus engineers who have worked on @value{GDBN}
2df3850c
JM
458fulltime include Mark Alexander, Jim Blandy, Per Bothner, Kevin
459Buettner, Edith Epstein, Chris Faylor, Fred Fish, Martin Hunt, Jim
460Ingham, John Gilmore, Stu Grossman, Kung Hsu, Jim Kingdon, John Metzler,
461Fernando Nasser, Geoffrey Noer, Dawn Perchik, Rich Pixley, Zdenek
462Radouch, Keith Seitz, Stan Shebs, David Taylor, and Elena Zannoni. In
463addition, Dave Brolley, Ian Carmichael, Steve Chamberlain, Nick Clifton,
464JT Conklin, Stan Cox, DJ Delorie, Ulrich Drepper, Frank Eigler, Doug
465Evans, Sean Fagan, David Henkel-Wallace, Richard Henderson, Jeff
466Holcomb, Jeff Law, Jim Lemke, Tom Lord, Bob Manson, Michael Meissner,
467Jason Merrill, Catherine Moore, Drew Moseley, Ken Raeburn, Gavin
468Romig-Koch, Rob Savoye, Jamie Smith, Mike Stump, Ian Taylor, Angela
469Thomas, Michael Tiemann, Tom Tromey, Ron Unrau, Jim Wilson, and David
470Zuhn have made contributions both large and small.
c906108c 471
e2e0bcd1
JB
472Jim Blandy added support for preprocessor macros, while working for Red
473Hat.
c906108c 474
6d2ebf8b 475@node Sample Session
c906108c
SS
476@chapter A Sample @value{GDBN} Session
477
478You can use this manual at your leisure to read all about @value{GDBN}.
479However, a handful of commands are enough to get started using the
480debugger. This chapter illustrates those commands.
481
482@iftex
483In this sample session, we emphasize user input like this: @b{input},
484to make it easier to pick out from the surrounding output.
485@end iftex
486
487@c FIXME: this example may not be appropriate for some configs, where
488@c FIXME...primary interest is in remote use.
489
490One of the preliminary versions of @sc{gnu} @code{m4} (a generic macro
491processor) exhibits the following bug: sometimes, when we change its
492quote strings from the default, the commands used to capture one macro
493definition within another stop working. In the following short @code{m4}
494session, we define a macro @code{foo} which expands to @code{0000}; we
495then use the @code{m4} built-in @code{defn} to define @code{bar} as the
496same thing. However, when we change the open quote string to
497@code{<QUOTE>} and the close quote string to @code{<UNQUOTE>}, the same
498procedure fails to define a new synonym @code{baz}:
499
500@smallexample
501$ @b{cd gnu/m4}
502$ @b{./m4}
503@b{define(foo,0000)}
504
505@b{foo}
5060000
507@b{define(bar,defn(`foo'))}
508
509@b{bar}
5100000
511@b{changequote(<QUOTE>,<UNQUOTE>)}
512
513@b{define(baz,defn(<QUOTE>foo<UNQUOTE>))}
514@b{baz}
515@b{C-d}
516m4: End of input: 0: fatal error: EOF in string
517@end smallexample
518
519@noindent
520Let us use @value{GDBN} to try to see what is going on.
521
c906108c
SS
522@smallexample
523$ @b{@value{GDBP} m4}
524@c FIXME: this falsifies the exact text played out, to permit smallbook
525@c FIXME... format to come out better.
526@value{GDBN} is free software and you are welcome to distribute copies
5d161b24 527 of it under certain conditions; type "show copying" to see
c906108c 528 the conditions.
5d161b24 529There is absolutely no warranty for @value{GDBN}; type "show warranty"
c906108c
SS
530 for details.
531
532@value{GDBN} @value{GDBVN}, Copyright 1999 Free Software Foundation, Inc...
533(@value{GDBP})
534@end smallexample
c906108c
SS
535
536@noindent
537@value{GDBN} reads only enough symbol data to know where to find the
538rest when needed; as a result, the first prompt comes up very quickly.
539We now tell @value{GDBN} to use a narrower display width than usual, so
540that examples fit in this manual.
541
542@smallexample
543(@value{GDBP}) @b{set width 70}
544@end smallexample
545
546@noindent
547We need to see how the @code{m4} built-in @code{changequote} works.
548Having looked at the source, we know the relevant subroutine is
549@code{m4_changequote}, so we set a breakpoint there with the @value{GDBN}
550@code{break} command.
551
552@smallexample
553(@value{GDBP}) @b{break m4_changequote}
554Breakpoint 1 at 0x62f4: file builtin.c, line 879.
555@end smallexample
556
557@noindent
558Using the @code{run} command, we start @code{m4} running under @value{GDBN}
559control; as long as control does not reach the @code{m4_changequote}
560subroutine, the program runs as usual:
561
562@smallexample
563(@value{GDBP}) @b{run}
564Starting program: /work/Editorial/gdb/gnu/m4/m4
565@b{define(foo,0000)}
566
567@b{foo}
5680000
569@end smallexample
570
571@noindent
572To trigger the breakpoint, we call @code{changequote}. @value{GDBN}
573suspends execution of @code{m4}, displaying information about the
574context where it stops.
575
576@smallexample
577@b{changequote(<QUOTE>,<UNQUOTE>)}
578
5d161b24 579Breakpoint 1, m4_changequote (argc=3, argv=0x33c70)
c906108c
SS
580 at builtin.c:879
581879 if (bad_argc(TOKEN_DATA_TEXT(argv[0]),argc,1,3))
582@end smallexample
583
584@noindent
585Now we use the command @code{n} (@code{next}) to advance execution to
586the next line of the current function.
587
588@smallexample
589(@value{GDBP}) @b{n}
590882 set_quotes((argc >= 2) ? TOKEN_DATA_TEXT(argv[1])\
591 : nil,
592@end smallexample
593
594@noindent
595@code{set_quotes} looks like a promising subroutine. We can go into it
596by using the command @code{s} (@code{step}) instead of @code{next}.
597@code{step} goes to the next line to be executed in @emph{any}
598subroutine, so it steps into @code{set_quotes}.
599
600@smallexample
601(@value{GDBP}) @b{s}
602set_quotes (lq=0x34c78 "<QUOTE>", rq=0x34c88 "<UNQUOTE>")
603 at input.c:530
604530 if (lquote != def_lquote)
605@end smallexample
606
607@noindent
608The display that shows the subroutine where @code{m4} is now
609suspended (and its arguments) is called a stack frame display. It
610shows a summary of the stack. We can use the @code{backtrace}
611command (which can also be spelled @code{bt}), to see where we are
612in the stack as a whole: the @code{backtrace} command displays a
613stack frame for each active subroutine.
614
615@smallexample
616(@value{GDBP}) @b{bt}
617#0 set_quotes (lq=0x34c78 "<QUOTE>", rq=0x34c88 "<UNQUOTE>")
618 at input.c:530
5d161b24 619#1 0x6344 in m4_changequote (argc=3, argv=0x33c70)
c906108c
SS
620 at builtin.c:882
621#2 0x8174 in expand_macro (sym=0x33320) at macro.c:242
622#3 0x7a88 in expand_token (obs=0x0, t=209696, td=0xf7fffa30)
623 at macro.c:71
624#4 0x79dc in expand_input () at macro.c:40
625#5 0x2930 in main (argc=0, argv=0xf7fffb20) at m4.c:195
626@end smallexample
627
628@noindent
629We step through a few more lines to see what happens. The first two
630times, we can use @samp{s}; the next two times we use @code{n} to avoid
631falling into the @code{xstrdup} subroutine.
632
633@smallexample
634(@value{GDBP}) @b{s}
6350x3b5c 532 if (rquote != def_rquote)
636(@value{GDBP}) @b{s}
6370x3b80 535 lquote = (lq == nil || *lq == '\0') ? \
638def_lquote : xstrdup(lq);
639(@value{GDBP}) @b{n}
640536 rquote = (rq == nil || *rq == '\0') ? def_rquote\
641 : xstrdup(rq);
642(@value{GDBP}) @b{n}
643538 len_lquote = strlen(rquote);
644@end smallexample
645
646@noindent
647The last line displayed looks a little odd; we can examine the variables
648@code{lquote} and @code{rquote} to see if they are in fact the new left
649and right quotes we specified. We use the command @code{p}
650(@code{print}) to see their values.
651
652@smallexample
653(@value{GDBP}) @b{p lquote}
654$1 = 0x35d40 "<QUOTE>"
655(@value{GDBP}) @b{p rquote}
656$2 = 0x35d50 "<UNQUOTE>"
657@end smallexample
658
659@noindent
660@code{lquote} and @code{rquote} are indeed the new left and right quotes.
661To look at some context, we can display ten lines of source
662surrounding the current line with the @code{l} (@code{list}) command.
663
664@smallexample
665(@value{GDBP}) @b{l}
666533 xfree(rquote);
667534
668535 lquote = (lq == nil || *lq == '\0') ? def_lquote\
669 : xstrdup (lq);
670536 rquote = (rq == nil || *rq == '\0') ? def_rquote\
671 : xstrdup (rq);
672537
673538 len_lquote = strlen(rquote);
674539 len_rquote = strlen(lquote);
675540 @}
676541
677542 void
678@end smallexample
679
680@noindent
681Let us step past the two lines that set @code{len_lquote} and
682@code{len_rquote}, and then examine the values of those variables.
683
684@smallexample
685(@value{GDBP}) @b{n}
686539 len_rquote = strlen(lquote);
687(@value{GDBP}) @b{n}
688540 @}
689(@value{GDBP}) @b{p len_lquote}
690$3 = 9
691(@value{GDBP}) @b{p len_rquote}
692$4 = 7
693@end smallexample
694
695@noindent
696That certainly looks wrong, assuming @code{len_lquote} and
697@code{len_rquote} are meant to be the lengths of @code{lquote} and
698@code{rquote} respectively. We can set them to better values using
699the @code{p} command, since it can print the value of
700any expression---and that expression can include subroutine calls and
701assignments.
702
703@smallexample
704(@value{GDBP}) @b{p len_lquote=strlen(lquote)}
705$5 = 7
706(@value{GDBP}) @b{p len_rquote=strlen(rquote)}
707$6 = 9
708@end smallexample
709
710@noindent
711Is that enough to fix the problem of using the new quotes with the
712@code{m4} built-in @code{defn}? We can allow @code{m4} to continue
713executing with the @code{c} (@code{continue}) command, and then try the
714example that caused trouble initially:
715
716@smallexample
717(@value{GDBP}) @b{c}
718Continuing.
719
720@b{define(baz,defn(<QUOTE>foo<UNQUOTE>))}
721
722baz
7230000
724@end smallexample
725
726@noindent
727Success! The new quotes now work just as well as the default ones. The
728problem seems to have been just the two typos defining the wrong
729lengths. We allow @code{m4} exit by giving it an EOF as input:
730
731@smallexample
732@b{C-d}
733Program exited normally.
734@end smallexample
735
736@noindent
737The message @samp{Program exited normally.} is from @value{GDBN}; it
738indicates @code{m4} has finished executing. We can end our @value{GDBN}
739session with the @value{GDBN} @code{quit} command.
740
741@smallexample
742(@value{GDBP}) @b{quit}
743@end smallexample
c906108c 744
6d2ebf8b 745@node Invocation
c906108c
SS
746@chapter Getting In and Out of @value{GDBN}
747
748This chapter discusses how to start @value{GDBN}, and how to get out of it.
5d161b24 749The essentials are:
c906108c 750@itemize @bullet
5d161b24 751@item
53a5351d 752type @samp{@value{GDBP}} to start @value{GDBN}.
5d161b24 753@item
c906108c
SS
754type @kbd{quit} or @kbd{C-d} to exit.
755@end itemize
756
757@menu
758* Invoking GDB:: How to start @value{GDBN}
759* Quitting GDB:: How to quit @value{GDBN}
760* Shell Commands:: How to use shell commands inside @value{GDBN}
0fac0b41 761* Logging output:: How to log @value{GDBN}'s output to a file
c906108c
SS
762@end menu
763
6d2ebf8b 764@node Invoking GDB
c906108c
SS
765@section Invoking @value{GDBN}
766
c906108c
SS
767Invoke @value{GDBN} by running the program @code{@value{GDBP}}. Once started,
768@value{GDBN} reads commands from the terminal until you tell it to exit.
769
770You can also run @code{@value{GDBP}} with a variety of arguments and options,
771to specify more of your debugging environment at the outset.
772
c906108c
SS
773The command-line options described here are designed
774to cover a variety of situations; in some environments, some of these
5d161b24 775options may effectively be unavailable.
c906108c
SS
776
777The most usual way to start @value{GDBN} is with one argument,
778specifying an executable program:
779
474c8240 780@smallexample
c906108c 781@value{GDBP} @var{program}
474c8240 782@end smallexample
c906108c 783
c906108c
SS
784@noindent
785You can also start with both an executable program and a core file
786specified:
787
474c8240 788@smallexample
c906108c 789@value{GDBP} @var{program} @var{core}
474c8240 790@end smallexample
c906108c
SS
791
792You can, instead, specify a process ID as a second argument, if you want
793to debug a running process:
794
474c8240 795@smallexample
c906108c 796@value{GDBP} @var{program} 1234
474c8240 797@end smallexample
c906108c
SS
798
799@noindent
800would attach @value{GDBN} to process @code{1234} (unless you also have a file
801named @file{1234}; @value{GDBN} does check for a core file first).
802
c906108c 803Taking advantage of the second command-line argument requires a fairly
2df3850c
JM
804complete operating system; when you use @value{GDBN} as a remote
805debugger attached to a bare board, there may not be any notion of
806``process'', and there is often no way to get a core dump. @value{GDBN}
807will warn you if it is unable to attach or to read core dumps.
c906108c 808
aa26fa3a
TT
809You can optionally have @code{@value{GDBP}} pass any arguments after the
810executable file to the inferior using @code{--args}. This option stops
811option processing.
474c8240 812@smallexample
aa26fa3a 813gdb --args gcc -O2 -c foo.c
474c8240 814@end smallexample
aa26fa3a
TT
815This will cause @code{@value{GDBP}} to debug @code{gcc}, and to set
816@code{gcc}'s command-line arguments (@pxref{Arguments}) to @samp{-O2 -c foo.c}.
817
96a2c332 818You can run @code{@value{GDBP}} without printing the front material, which describes
c906108c
SS
819@value{GDBN}'s non-warranty, by specifying @code{-silent}:
820
821@smallexample
822@value{GDBP} -silent
823@end smallexample
824
825@noindent
826You can further control how @value{GDBN} starts up by using command-line
827options. @value{GDBN} itself can remind you of the options available.
828
829@noindent
830Type
831
474c8240 832@smallexample
c906108c 833@value{GDBP} -help
474c8240 834@end smallexample
c906108c
SS
835
836@noindent
837to display all available options and briefly describe their use
838(@samp{@value{GDBP} -h} is a shorter equivalent).
839
840All options and command line arguments you give are processed
841in sequential order. The order makes a difference when the
842@samp{-x} option is used.
843
844
845@menu
c906108c
SS
846* File Options:: Choosing files
847* Mode Options:: Choosing modes
848@end menu
849
6d2ebf8b 850@node File Options
c906108c
SS
851@subsection Choosing files
852
2df3850c 853When @value{GDBN} starts, it reads any arguments other than options as
c906108c
SS
854specifying an executable file and core file (or process ID). This is
855the same as if the arguments were specified by the @samp{-se} and
19837790
MS
856@samp{-c} (or @samp{-p} options respectively. (@value{GDBN} reads the
857first argument that does not have an associated option flag as
858equivalent to the @samp{-se} option followed by that argument; and the
859second argument that does not have an associated option flag, if any, as
860equivalent to the @samp{-c}/@samp{-p} option followed by that argument.)
861If the second argument begins with a decimal digit, @value{GDBN} will
862first attempt to attach to it as a process, and if that fails, attempt
863to open it as a corefile. If you have a corefile whose name begins with
b383017d 864a digit, you can prevent @value{GDBN} from treating it as a pid by
79f12247 865prefixing it with @file{./}, eg. @file{./12345}.
7a292a7a
SS
866
867If @value{GDBN} has not been configured to included core file support,
868such as for most embedded targets, then it will complain about a second
869argument and ignore it.
c906108c
SS
870
871Many options have both long and short forms; both are shown in the
872following list. @value{GDBN} also recognizes the long forms if you truncate
873them, so long as enough of the option is present to be unambiguous.
874(If you prefer, you can flag option arguments with @samp{--} rather
875than @samp{-}, though we illustrate the more usual convention.)
876
d700128c
EZ
877@c NOTE: the @cindex entries here use double dashes ON PURPOSE. This
878@c way, both those who look for -foo and --foo in the index, will find
879@c it.
880
c906108c
SS
881@table @code
882@item -symbols @var{file}
883@itemx -s @var{file}
d700128c
EZ
884@cindex @code{--symbols}
885@cindex @code{-s}
c906108c
SS
886Read symbol table from file @var{file}.
887
888@item -exec @var{file}
889@itemx -e @var{file}
d700128c
EZ
890@cindex @code{--exec}
891@cindex @code{-e}
7a292a7a
SS
892Use file @var{file} as the executable file to execute when appropriate,
893and for examining pure data in conjunction with a core dump.
c906108c
SS
894
895@item -se @var{file}
d700128c 896@cindex @code{--se}
c906108c
SS
897Read symbol table from file @var{file} and use it as the executable
898file.
899
c906108c
SS
900@item -core @var{file}
901@itemx -c @var{file}
d700128c
EZ
902@cindex @code{--core}
903@cindex @code{-c}
b383017d 904Use file @var{file} as a core dump to examine.
c906108c
SS
905
906@item -c @var{number}
19837790
MS
907@item -pid @var{number}
908@itemx -p @var{number}
909@cindex @code{--pid}
910@cindex @code{-p}
911Connect to process ID @var{number}, as with the @code{attach} command.
912If there is no such process, @value{GDBN} will attempt to open a core
913file named @var{number}.
c906108c
SS
914
915@item -command @var{file}
916@itemx -x @var{file}
d700128c
EZ
917@cindex @code{--command}
918@cindex @code{-x}
c906108c
SS
919Execute @value{GDBN} commands from file @var{file}. @xref{Command
920Files,, Command files}.
921
922@item -directory @var{directory}
923@itemx -d @var{directory}
d700128c
EZ
924@cindex @code{--directory}
925@cindex @code{-d}
c906108c
SS
926Add @var{directory} to the path to search for source files.
927
c906108c
SS
928@item -m
929@itemx -mapped
d700128c
EZ
930@cindex @code{--mapped}
931@cindex @code{-m}
c906108c
SS
932@emph{Warning: this option depends on operating system facilities that are not
933supported on all systems.}@*
934If memory-mapped files are available on your system through the @code{mmap}
5d161b24 935system call, you can use this option
c906108c
SS
936to have @value{GDBN} write the symbols from your
937program into a reusable file in the current directory. If the program you are debugging is
96a2c332 938called @file{/tmp/fred}, the mapped symbol file is @file{/tmp/fred.syms}.
c906108c
SS
939Future @value{GDBN} debugging sessions notice the presence of this file,
940and can quickly map in symbol information from it, rather than reading
941the symbol table from the executable program.
942
943The @file{.syms} file is specific to the host machine where @value{GDBN}
944is run. It holds an exact image of the internal @value{GDBN} symbol
945table. It cannot be shared across multiple host platforms.
c906108c 946
c906108c
SS
947@item -r
948@itemx -readnow
d700128c
EZ
949@cindex @code{--readnow}
950@cindex @code{-r}
c906108c
SS
951Read each symbol file's entire symbol table immediately, rather than
952the default, which is to read it incrementally as it is needed.
953This makes startup slower, but makes future operations faster.
53a5351d 954
c906108c
SS
955@end table
956
2df3850c 957You typically combine the @code{-mapped} and @code{-readnow} options in
c906108c 958order to build a @file{.syms} file that contains complete symbol
2df3850c
JM
959information. (@xref{Files,,Commands to specify files}, for information
960on @file{.syms} files.) A simple @value{GDBN} invocation to do nothing
961but build a @file{.syms} file for future use is:
c906108c 962
474c8240 963@smallexample
2df3850c 964gdb -batch -nx -mapped -readnow programname
474c8240 965@end smallexample
c906108c 966
6d2ebf8b 967@node Mode Options
c906108c
SS
968@subsection Choosing modes
969
970You can run @value{GDBN} in various alternative modes---for example, in
971batch mode or quiet mode.
972
973@table @code
974@item -nx
975@itemx -n
d700128c
EZ
976@cindex @code{--nx}
977@cindex @code{-n}
96565e91 978Do not execute commands found in any initialization files. Normally,
2df3850c
JM
979@value{GDBN} executes the commands in these files after all the command
980options and arguments have been processed. @xref{Command Files,,Command
981files}.
c906108c
SS
982
983@item -quiet
d700128c 984@itemx -silent
c906108c 985@itemx -q
d700128c
EZ
986@cindex @code{--quiet}
987@cindex @code{--silent}
988@cindex @code{-q}
c906108c
SS
989``Quiet''. Do not print the introductory and copyright messages. These
990messages are also suppressed in batch mode.
991
992@item -batch
d700128c 993@cindex @code{--batch}
c906108c
SS
994Run in batch mode. Exit with status @code{0} after processing all the
995command files specified with @samp{-x} (and all commands from
996initialization files, if not inhibited with @samp{-n}). Exit with
997nonzero status if an error occurs in executing the @value{GDBN} commands
998in the command files.
999
2df3850c
JM
1000Batch mode may be useful for running @value{GDBN} as a filter, for
1001example to download and run a program on another computer; in order to
1002make this more useful, the message
c906108c 1003
474c8240 1004@smallexample
c906108c 1005Program exited normally.
474c8240 1006@end smallexample
c906108c
SS
1007
1008@noindent
2df3850c
JM
1009(which is ordinarily issued whenever a program running under
1010@value{GDBN} control terminates) is not issued when running in batch
1011mode.
1012
1013@item -nowindows
1014@itemx -nw
d700128c
EZ
1015@cindex @code{--nowindows}
1016@cindex @code{-nw}
2df3850c 1017``No windows''. If @value{GDBN} comes with a graphical user interface
96a2c332 1018(GUI) built in, then this option tells @value{GDBN} to only use the command-line
2df3850c
JM
1019interface. If no GUI is available, this option has no effect.
1020
1021@item -windows
1022@itemx -w
d700128c
EZ
1023@cindex @code{--windows}
1024@cindex @code{-w}
2df3850c
JM
1025If @value{GDBN} includes a GUI, then this option requires it to be
1026used if possible.
c906108c
SS
1027
1028@item -cd @var{directory}
d700128c 1029@cindex @code{--cd}
c906108c
SS
1030Run @value{GDBN} using @var{directory} as its working directory,
1031instead of the current directory.
1032
c906108c
SS
1033@item -fullname
1034@itemx -f
d700128c
EZ
1035@cindex @code{--fullname}
1036@cindex @code{-f}
7a292a7a
SS
1037@sc{gnu} Emacs sets this option when it runs @value{GDBN} as a
1038subprocess. It tells @value{GDBN} to output the full file name and line
1039number in a standard, recognizable fashion each time a stack frame is
1040displayed (which includes each time your program stops). This
1041recognizable format looks like two @samp{\032} characters, followed by
1042the file name, line number and character position separated by colons,
1043and a newline. The Emacs-to-@value{GDBN} interface program uses the two
1044@samp{\032} characters as a signal to display the source code for the
1045frame.
c906108c 1046
d700128c
EZ
1047@item -epoch
1048@cindex @code{--epoch}
1049The Epoch Emacs-@value{GDBN} interface sets this option when it runs
1050@value{GDBN} as a subprocess. It tells @value{GDBN} to modify its print
1051routines so as to allow Epoch to display values of expressions in a
1052separate window.
1053
1054@item -annotate @var{level}
1055@cindex @code{--annotate}
1056This option sets the @dfn{annotation level} inside @value{GDBN}. Its
1057effect is identical to using @samp{set annotate @var{level}}
086432e2
AC
1058(@pxref{Annotations}). The annotation @var{level} controls how much
1059information @value{GDBN} prints together with its prompt, values of
1060expressions, source lines, and other types of output. Level 0 is the
1061normal, level 1 is for use when @value{GDBN} is run as a subprocess of
1062@sc{gnu} Emacs, level 3 is the maximum annotation suitable for programs
1063that control @value{GDBN}, and level 2 has been deprecated.
1064
1065The annotation mechanism has largely been superseeded by @sc{gdb/mi}
1066(@pxref{GDB/MI}).
d700128c 1067
aa26fa3a
TT
1068@item --args
1069@cindex @code{--args}
1070Change interpretation of command line so that arguments following the
1071executable file are passed as command line arguments to the inferior.
1072This option stops option processing.
1073
2df3850c
JM
1074@item -baud @var{bps}
1075@itemx -b @var{bps}
d700128c
EZ
1076@cindex @code{--baud}
1077@cindex @code{-b}
c906108c
SS
1078Set the line speed (baud rate or bits per second) of any serial
1079interface used by @value{GDBN} for remote debugging.
c906108c
SS
1080
1081@item -tty @var{device}
d700128c
EZ
1082@itemx -t @var{device}
1083@cindex @code{--tty}
1084@cindex @code{-t}
c906108c
SS
1085Run using @var{device} for your program's standard input and output.
1086@c FIXME: kingdon thinks there is more to -tty. Investigate.
c906108c 1087
53a5351d 1088@c resolve the situation of these eventually
c4555f82
SC
1089@item -tui
1090@cindex @code{--tui}
d0d5df6f
AC
1091Activate the @dfn{Text User Interface} when starting. The Text User
1092Interface manages several text windows on the terminal, showing
1093source, assembly, registers and @value{GDBN} command outputs
1094(@pxref{TUI, ,@value{GDBN} Text User Interface}). Alternatively, the
1095Text User Interface can be enabled by invoking the program
1096@samp{gdbtui}. Do not use this option if you run @value{GDBN} from
1097Emacs (@pxref{Emacs, ,Using @value{GDBN} under @sc{gnu} Emacs}).
53a5351d
JM
1098
1099@c @item -xdb
d700128c 1100@c @cindex @code{--xdb}
53a5351d
JM
1101@c Run in XDB compatibility mode, allowing the use of certain XDB commands.
1102@c For information, see the file @file{xdb_trans.html}, which is usually
1103@c installed in the directory @code{/opt/langtools/wdb/doc} on HP-UX
1104@c systems.
1105
d700128c
EZ
1106@item -interpreter @var{interp}
1107@cindex @code{--interpreter}
1108Use the interpreter @var{interp} for interface with the controlling
1109program or device. This option is meant to be set by programs which
94bbb2c0 1110communicate with @value{GDBN} using it as a back end.
21c294e6 1111@xref{Interpreters, , Command Interpreters}.
94bbb2c0 1112
da0f9dcd 1113@samp{--interpreter=mi} (or @samp{--interpreter=mi2}) causes
2fcf52f0 1114@value{GDBN} to use the @dfn{@sc{gdb/mi} interface} (@pxref{GDB/MI, ,
6c74ac8b
AC
1115The @sc{gdb/mi} Interface}) included since @var{GDBN} version 6.0. The
1116previous @sc{gdb/mi} interface, included in @value{GDBN} version 5.3 and
1117selected with @samp{--interpreter=mi1}, is deprecated. Earlier
1118@sc{gdb/mi} interfaces are no longer supported.
d700128c
EZ
1119
1120@item -write
1121@cindex @code{--write}
1122Open the executable and core files for both reading and writing. This
1123is equivalent to the @samp{set write on} command inside @value{GDBN}
1124(@pxref{Patching}).
1125
1126@item -statistics
1127@cindex @code{--statistics}
1128This option causes @value{GDBN} to print statistics about time and
1129memory usage after it completes each command and returns to the prompt.
1130
1131@item -version
1132@cindex @code{--version}
1133This option causes @value{GDBN} to print its version number and
1134no-warranty blurb, and exit.
1135
c906108c
SS
1136@end table
1137
6d2ebf8b 1138@node Quitting GDB
c906108c
SS
1139@section Quitting @value{GDBN}
1140@cindex exiting @value{GDBN}
1141@cindex leaving @value{GDBN}
1142
1143@table @code
1144@kindex quit @r{[}@var{expression}@r{]}
41afff9a 1145@kindex q @r{(@code{quit})}
96a2c332
SS
1146@item quit @r{[}@var{expression}@r{]}
1147@itemx q
1148To exit @value{GDBN}, use the @code{quit} command (abbreviated
1149@code{q}), or type an end-of-file character (usually @kbd{C-d}). If you
1150do not supply @var{expression}, @value{GDBN} will terminate normally;
1151otherwise it will terminate using the result of @var{expression} as the
1152error code.
c906108c
SS
1153@end table
1154
1155@cindex interrupt
1156An interrupt (often @kbd{C-c}) does not exit from @value{GDBN}, but rather
1157terminates the action of any @value{GDBN} command that is in progress and
1158returns to @value{GDBN} command level. It is safe to type the interrupt
1159character at any time because @value{GDBN} does not allow it to take effect
1160until a time when it is safe.
1161
c906108c
SS
1162If you have been using @value{GDBN} to control an attached process or
1163device, you can release it with the @code{detach} command
1164(@pxref{Attach, ,Debugging an already-running process}).
c906108c 1165
6d2ebf8b 1166@node Shell Commands
c906108c
SS
1167@section Shell commands
1168
1169If you need to execute occasional shell commands during your
1170debugging session, there is no need to leave or suspend @value{GDBN}; you can
1171just use the @code{shell} command.
1172
1173@table @code
1174@kindex shell
1175@cindex shell escape
1176@item shell @var{command string}
1177Invoke a standard shell to execute @var{command string}.
c906108c 1178If it exists, the environment variable @code{SHELL} determines which
d4f3574e
SS
1179shell to run. Otherwise @value{GDBN} uses the default shell
1180(@file{/bin/sh} on Unix systems, @file{COMMAND.COM} on MS-DOS, etc.).
c906108c
SS
1181@end table
1182
1183The utility @code{make} is often needed in development environments.
1184You do not have to use the @code{shell} command for this purpose in
1185@value{GDBN}:
1186
1187@table @code
1188@kindex make
1189@cindex calling make
1190@item make @var{make-args}
1191Execute the @code{make} program with the specified
1192arguments. This is equivalent to @samp{shell make @var{make-args}}.
1193@end table
1194
0fac0b41
DJ
1195@node Logging output
1196@section Logging output
1197@cindex logging @value{GDBN} output
1198
1199You may want to save the output of @value{GDBN} commands to a file.
1200There are several commands to control @value{GDBN}'s logging.
1201
1202@table @code
1203@kindex set logging
1204@item set logging on
1205Enable logging.
1206@item set logging off
1207Disable logging.
1208@item set logging file @var{file}
1209Change the name of the current logfile. The default logfile is @file{gdb.txt}.
1210@item set logging overwrite [on|off]
1211By default, @value{GDBN} will append to the logfile. Set @code{overwrite} if
1212you want @code{set logging on} to overwrite the logfile instead.
1213@item set logging redirect [on|off]
1214By default, @value{GDBN} output will go to both the terminal and the logfile.
1215Set @code{redirect} if you want output to go only to the log file.
1216@kindex show logging
1217@item show logging
1218Show the current values of the logging settings.
1219@end table
1220
6d2ebf8b 1221@node Commands
c906108c
SS
1222@chapter @value{GDBN} Commands
1223
1224You can abbreviate a @value{GDBN} command to the first few letters of the command
1225name, if that abbreviation is unambiguous; and you can repeat certain
1226@value{GDBN} commands by typing just @key{RET}. You can also use the @key{TAB}
1227key to get @value{GDBN} to fill out the rest of a word in a command (or to
1228show you the alternatives available, if there is more than one possibility).
1229
1230@menu
1231* Command Syntax:: How to give commands to @value{GDBN}
1232* Completion:: Command completion
1233* Help:: How to ask @value{GDBN} for help
1234@end menu
1235
6d2ebf8b 1236@node Command Syntax
c906108c
SS
1237@section Command syntax
1238
1239A @value{GDBN} command is a single line of input. There is no limit on
1240how long it can be. It starts with a command name, which is followed by
1241arguments whose meaning depends on the command name. For example, the
1242command @code{step} accepts an argument which is the number of times to
1243step, as in @samp{step 5}. You can also use the @code{step} command
96a2c332 1244with no arguments. Some commands do not allow any arguments.
c906108c
SS
1245
1246@cindex abbreviation
1247@value{GDBN} command names may always be truncated if that abbreviation is
1248unambiguous. Other possible command abbreviations are listed in the
1249documentation for individual commands. In some cases, even ambiguous
1250abbreviations are allowed; for example, @code{s} is specially defined as
1251equivalent to @code{step} even though there are other commands whose
1252names start with @code{s}. You can test abbreviations by using them as
1253arguments to the @code{help} command.
1254
1255@cindex repeating commands
41afff9a 1256@kindex RET @r{(repeat last command)}
c906108c 1257A blank line as input to @value{GDBN} (typing just @key{RET}) means to
96a2c332 1258repeat the previous command. Certain commands (for example, @code{run})
c906108c
SS
1259will not repeat this way; these are commands whose unintentional
1260repetition might cause trouble and which you are unlikely to want to
1261repeat.
1262
1263The @code{list} and @code{x} commands, when you repeat them with
1264@key{RET}, construct new arguments rather than repeating
1265exactly as typed. This permits easy scanning of source or memory.
1266
1267@value{GDBN} can also use @key{RET} in another way: to partition lengthy
1268output, in a way similar to the common utility @code{more}
1269(@pxref{Screen Size,,Screen size}). Since it is easy to press one
1270@key{RET} too many in this situation, @value{GDBN} disables command
1271repetition after any command that generates this sort of display.
1272
41afff9a 1273@kindex # @r{(a comment)}
c906108c
SS
1274@cindex comment
1275Any text from a @kbd{#} to the end of the line is a comment; it does
1276nothing. This is useful mainly in command files (@pxref{Command
1277Files,,Command files}).
1278
88118b3a
TT
1279@cindex repeating command sequences
1280@kindex C-o @r{(operate-and-get-next)}
1281The @kbd{C-o} binding is useful for repeating a complex sequence of
1282commands. This command accepts the current line, like @kbd{RET}, and
1283then fetches the next line relative to the current line from the history
1284for editing.
1285
6d2ebf8b 1286@node Completion
c906108c
SS
1287@section Command completion
1288
1289@cindex completion
1290@cindex word completion
1291@value{GDBN} can fill in the rest of a word in a command for you, if there is
1292only one possibility; it can also show you what the valid possibilities
1293are for the next word in a command, at any time. This works for @value{GDBN}
1294commands, @value{GDBN} subcommands, and the names of symbols in your program.
1295
1296Press the @key{TAB} key whenever you want @value{GDBN} to fill out the rest
1297of a word. If there is only one possibility, @value{GDBN} fills in the
1298word, and waits for you to finish the command (or press @key{RET} to
1299enter it). For example, if you type
1300
1301@c FIXME "@key" does not distinguish its argument sufficiently to permit
1302@c complete accuracy in these examples; space introduced for clarity.
1303@c If texinfo enhancements make it unnecessary, it would be nice to
1304@c replace " @key" by "@key" in the following...
474c8240 1305@smallexample
c906108c 1306(@value{GDBP}) info bre @key{TAB}
474c8240 1307@end smallexample
c906108c
SS
1308
1309@noindent
1310@value{GDBN} fills in the rest of the word @samp{breakpoints}, since that is
1311the only @code{info} subcommand beginning with @samp{bre}:
1312
474c8240 1313@smallexample
c906108c 1314(@value{GDBP}) info breakpoints
474c8240 1315@end smallexample
c906108c
SS
1316
1317@noindent
1318You can either press @key{RET} at this point, to run the @code{info
1319breakpoints} command, or backspace and enter something else, if
1320@samp{breakpoints} does not look like the command you expected. (If you
1321were sure you wanted @code{info breakpoints} in the first place, you
1322might as well just type @key{RET} immediately after @samp{info bre},
1323to exploit command abbreviations rather than command completion).
1324
1325If there is more than one possibility for the next word when you press
1326@key{TAB}, @value{GDBN} sounds a bell. You can either supply more
1327characters and try again, or just press @key{TAB} a second time;
1328@value{GDBN} displays all the possible completions for that word. For
1329example, you might want to set a breakpoint on a subroutine whose name
1330begins with @samp{make_}, but when you type @kbd{b make_@key{TAB}} @value{GDBN}
1331just sounds the bell. Typing @key{TAB} again displays all the
1332function names in your program that begin with those characters, for
1333example:
1334
474c8240 1335@smallexample
c906108c
SS
1336(@value{GDBP}) b make_ @key{TAB}
1337@exdent @value{GDBN} sounds bell; press @key{TAB} again, to see:
5d161b24
DB
1338make_a_section_from_file make_environ
1339make_abs_section make_function_type
1340make_blockvector make_pointer_type
1341make_cleanup make_reference_type
c906108c
SS
1342make_command make_symbol_completion_list
1343(@value{GDBP}) b make_
474c8240 1344@end smallexample
c906108c
SS
1345
1346@noindent
1347After displaying the available possibilities, @value{GDBN} copies your
1348partial input (@samp{b make_} in the example) so you can finish the
1349command.
1350
1351If you just want to see the list of alternatives in the first place, you
b37052ae 1352can press @kbd{M-?} rather than pressing @key{TAB} twice. @kbd{M-?}
7a292a7a 1353means @kbd{@key{META} ?}. You can type this either by holding down a
c906108c 1354key designated as the @key{META} shift on your keyboard (if there is
7a292a7a 1355one) while typing @kbd{?}, or as @key{ESC} followed by @kbd{?}.
c906108c
SS
1356
1357@cindex quotes in commands
1358@cindex completion of quoted strings
1359Sometimes the string you need, while logically a ``word'', may contain
7a292a7a
SS
1360parentheses or other characters that @value{GDBN} normally excludes from
1361its notion of a word. To permit word completion to work in this
1362situation, you may enclose words in @code{'} (single quote marks) in
1363@value{GDBN} commands.
c906108c 1364
c906108c 1365The most likely situation where you might need this is in typing the
b37052ae
EZ
1366name of a C@t{++} function. This is because C@t{++} allows function
1367overloading (multiple definitions of the same function, distinguished
1368by argument type). For example, when you want to set a breakpoint you
1369may need to distinguish whether you mean the version of @code{name}
1370that takes an @code{int} parameter, @code{name(int)}, or the version
1371that takes a @code{float} parameter, @code{name(float)}. To use the
1372word-completion facilities in this situation, type a single quote
1373@code{'} at the beginning of the function name. This alerts
1374@value{GDBN} that it may need to consider more information than usual
1375when you press @key{TAB} or @kbd{M-?} to request word completion:
c906108c 1376
474c8240 1377@smallexample
96a2c332 1378(@value{GDBP}) b 'bubble( @kbd{M-?}
c906108c
SS
1379bubble(double,double) bubble(int,int)
1380(@value{GDBP}) b 'bubble(
474c8240 1381@end smallexample
c906108c
SS
1382
1383In some cases, @value{GDBN} can tell that completing a name requires using
1384quotes. When this happens, @value{GDBN} inserts the quote for you (while
1385completing as much as it can) if you do not type the quote in the first
1386place:
1387
474c8240 1388@smallexample
c906108c
SS
1389(@value{GDBP}) b bub @key{TAB}
1390@exdent @value{GDBN} alters your input line to the following, and rings a bell:
1391(@value{GDBP}) b 'bubble(
474c8240 1392@end smallexample
c906108c
SS
1393
1394@noindent
1395In general, @value{GDBN} can tell that a quote is needed (and inserts it) if
1396you have not yet started typing the argument list when you ask for
1397completion on an overloaded symbol.
1398
d4f3574e 1399For more information about overloaded functions, see @ref{C plus plus
b37052ae 1400expressions, ,C@t{++} expressions}. You can use the command @code{set
c906108c 1401overload-resolution off} to disable overload resolution;
b37052ae 1402see @ref{Debugging C plus plus, ,@value{GDBN} features for C@t{++}}.
c906108c
SS
1403
1404
6d2ebf8b 1405@node Help
c906108c
SS
1406@section Getting help
1407@cindex online documentation
1408@kindex help
1409
5d161b24 1410You can always ask @value{GDBN} itself for information on its commands,
c906108c
SS
1411using the command @code{help}.
1412
1413@table @code
41afff9a 1414@kindex h @r{(@code{help})}
c906108c
SS
1415@item help
1416@itemx h
1417You can use @code{help} (abbreviated @code{h}) with no arguments to
1418display a short list of named classes of commands:
1419
1420@smallexample
1421(@value{GDBP}) help
1422List of classes of commands:
1423
2df3850c 1424aliases -- Aliases of other commands
c906108c 1425breakpoints -- Making program stop at certain points
2df3850c 1426data -- Examining data
c906108c 1427files -- Specifying and examining files
2df3850c
JM
1428internals -- Maintenance commands
1429obscure -- Obscure features
1430running -- Running the program
1431stack -- Examining the stack
c906108c
SS
1432status -- Status inquiries
1433support -- Support facilities
96a2c332
SS
1434tracepoints -- Tracing of program execution without@*
1435 stopping the program
c906108c 1436user-defined -- User-defined commands
c906108c 1437
5d161b24 1438Type "help" followed by a class name for a list of
c906108c 1439commands in that class.
5d161b24 1440Type "help" followed by command name for full
c906108c
SS
1441documentation.
1442Command name abbreviations are allowed if unambiguous.
1443(@value{GDBP})
1444@end smallexample
96a2c332 1445@c the above line break eliminates huge line overfull...
c906108c
SS
1446
1447@item help @var{class}
1448Using one of the general help classes as an argument, you can get a
1449list of the individual commands in that class. For example, here is the
1450help display for the class @code{status}:
1451
1452@smallexample
1453(@value{GDBP}) help status
1454Status inquiries.
1455
1456List of commands:
1457
1458@c Line break in "show" line falsifies real output, but needed
1459@c to fit in smallbook page size.
2df3850c
JM
1460info -- Generic command for showing things
1461 about the program being debugged
1462show -- Generic command for showing things
1463 about the debugger
c906108c 1464
5d161b24 1465Type "help" followed by command name for full
c906108c
SS
1466documentation.
1467Command name abbreviations are allowed if unambiguous.
1468(@value{GDBP})
1469@end smallexample
1470
1471@item help @var{command}
1472With a command name as @code{help} argument, @value{GDBN} displays a
1473short paragraph on how to use that command.
1474
6837a0a2
DB
1475@kindex apropos
1476@item apropos @var{args}
1477The @code{apropos @var{args}} command searches through all of the @value{GDBN}
1478commands, and their documentation, for the regular expression specified in
1479@var{args}. It prints out all matches found. For example:
1480
1481@smallexample
1482apropos reload
1483@end smallexample
1484
b37052ae
EZ
1485@noindent
1486results in:
6837a0a2
DB
1487
1488@smallexample
6d2ebf8b
SS
1489@c @group
1490set symbol-reloading -- Set dynamic symbol table reloading
1491 multiple times in one run
1492show symbol-reloading -- Show dynamic symbol table reloading
1493 multiple times in one run
1494@c @end group
6837a0a2
DB
1495@end smallexample
1496
c906108c
SS
1497@kindex complete
1498@item complete @var{args}
1499The @code{complete @var{args}} command lists all the possible completions
1500for the beginning of a command. Use @var{args} to specify the beginning of the
1501command you want completed. For example:
1502
1503@smallexample
1504complete i
1505@end smallexample
1506
1507@noindent results in:
1508
1509@smallexample
1510@group
2df3850c
JM
1511if
1512ignore
c906108c
SS
1513info
1514inspect
c906108c
SS
1515@end group
1516@end smallexample
1517
1518@noindent This is intended for use by @sc{gnu} Emacs.
1519@end table
1520
1521In addition to @code{help}, you can use the @value{GDBN} commands @code{info}
1522and @code{show} to inquire about the state of your program, or the state
1523of @value{GDBN} itself. Each command supports many topics of inquiry; this
1524manual introduces each of them in the appropriate context. The listings
1525under @code{info} and under @code{show} in the Index point to
1526all the sub-commands. @xref{Index}.
1527
1528@c @group
1529@table @code
1530@kindex info
41afff9a 1531@kindex i @r{(@code{info})}
c906108c
SS
1532@item info
1533This command (abbreviated @code{i}) is for describing the state of your
1534program. For example, you can list the arguments given to your program
1535with @code{info args}, list the registers currently in use with @code{info
1536registers}, or list the breakpoints you have set with @code{info breakpoints}.
1537You can get a complete list of the @code{info} sub-commands with
1538@w{@code{help info}}.
1539
1540@kindex set
1541@item set
5d161b24 1542You can assign the result of an expression to an environment variable with
c906108c
SS
1543@code{set}. For example, you can set the @value{GDBN} prompt to a $-sign with
1544@code{set prompt $}.
1545
1546@kindex show
1547@item show
5d161b24 1548In contrast to @code{info}, @code{show} is for describing the state of
c906108c
SS
1549@value{GDBN} itself.
1550You can change most of the things you can @code{show}, by using the
1551related command @code{set}; for example, you can control what number
1552system is used for displays with @code{set radix}, or simply inquire
1553which is currently in use with @code{show radix}.
1554
1555@kindex info set
1556To display all the settable parameters and their current
1557values, you can use @code{show} with no arguments; you may also use
1558@code{info set}. Both commands produce the same display.
1559@c FIXME: "info set" violates the rule that "info" is for state of
1560@c FIXME...program. Ck w/ GNU: "info set" to be called something else,
1561@c FIXME...or change desc of rule---eg "state of prog and debugging session"?
1562@end table
1563@c @end group
1564
1565Here are three miscellaneous @code{show} subcommands, all of which are
1566exceptional in lacking corresponding @code{set} commands:
1567
1568@table @code
1569@kindex show version
1570@cindex version number
1571@item show version
1572Show what version of @value{GDBN} is running. You should include this
2df3850c
JM
1573information in @value{GDBN} bug-reports. If multiple versions of
1574@value{GDBN} are in use at your site, you may need to determine which
1575version of @value{GDBN} you are running; as @value{GDBN} evolves, new
1576commands are introduced, and old ones may wither away. Also, many
1577system vendors ship variant versions of @value{GDBN}, and there are
96a2c332 1578variant versions of @value{GDBN} in @sc{gnu}/Linux distributions as well.
2df3850c
JM
1579The version number is the same as the one announced when you start
1580@value{GDBN}.
c906108c
SS
1581
1582@kindex show copying
1583@item show copying
1584Display information about permission for copying @value{GDBN}.
1585
1586@kindex show warranty
1587@item show warranty
2df3850c 1588Display the @sc{gnu} ``NO WARRANTY'' statement, or a warranty,
96a2c332 1589if your version of @value{GDBN} comes with one.
2df3850c 1590
c906108c
SS
1591@end table
1592
6d2ebf8b 1593@node Running
c906108c
SS
1594@chapter Running Programs Under @value{GDBN}
1595
1596When you run a program under @value{GDBN}, you must first generate
1597debugging information when you compile it.
7a292a7a
SS
1598
1599You may start @value{GDBN} with its arguments, if any, in an environment
1600of your choice. If you are doing native debugging, you may redirect
1601your program's input and output, debug an already running process, or
1602kill a child process.
c906108c
SS
1603
1604@menu
1605* Compilation:: Compiling for debugging
1606* Starting:: Starting your program
c906108c
SS
1607* Arguments:: Your program's arguments
1608* Environment:: Your program's environment
c906108c
SS
1609
1610* Working Directory:: Your program's working directory
1611* Input/Output:: Your program's input and output
1612* Attach:: Debugging an already-running process
1613* Kill Process:: Killing the child process
c906108c
SS
1614
1615* Threads:: Debugging programs with multiple threads
1616* Processes:: Debugging programs with multiple processes
1617@end menu
1618
6d2ebf8b 1619@node Compilation
c906108c
SS
1620@section Compiling for debugging
1621
1622In order to debug a program effectively, you need to generate
1623debugging information when you compile it. This debugging information
1624is stored in the object file; it describes the data type of each
1625variable or function and the correspondence between source line numbers
1626and addresses in the executable code.
1627
1628To request debugging information, specify the @samp{-g} option when you run
1629the compiler.
1630
e2e0bcd1
JB
1631Most compilers do not include information about preprocessor macros in
1632the debugging information if you specify the @option{-g} flag alone,
1633because this information is rather large. Version 3.1 of @value{NGCC},
1634the @sc{gnu} C compiler, provides macro information if you specify the
1635options @option{-gdwarf-2} and @option{-g3}; the former option requests
1636debugging information in the Dwarf 2 format, and the latter requests
1637``extra information''. In the future, we hope to find more compact ways
1638to represent macro information, so that it can be included with
1639@option{-g} alone.
1640
c906108c
SS
1641Many C compilers are unable to handle the @samp{-g} and @samp{-O}
1642options together. Using those compilers, you cannot generate optimized
1643executables containing debugging information.
1644
53a5351d
JM
1645@value{NGCC}, the @sc{gnu} C compiler, supports @samp{-g} with or
1646without @samp{-O}, making it possible to debug optimized code. We
1647recommend that you @emph{always} use @samp{-g} whenever you compile a
1648program. You may think your program is correct, but there is no sense
1649in pushing your luck.
c906108c
SS
1650
1651@cindex optimized code, debugging
1652@cindex debugging optimized code
1653When you debug a program compiled with @samp{-g -O}, remember that the
1654optimizer is rearranging your code; the debugger shows you what is
1655really there. Do not be too surprised when the execution path does not
1656exactly match your source file! An extreme example: if you define a
1657variable, but never use it, @value{GDBN} never sees that
1658variable---because the compiler optimizes it out of existence.
1659
1660Some things do not work as well with @samp{-g -O} as with just
1661@samp{-g}, particularly on machines with instruction scheduling. If in
1662doubt, recompile with @samp{-g} alone, and if this fixes the problem,
1663please report it to us as a bug (including a test case!).
15387254 1664@xref{Variables}, for more information about debugging optimized code.
c906108c
SS
1665
1666Older versions of the @sc{gnu} C compiler permitted a variant option
1667@w{@samp{-gg}} for debugging information. @value{GDBN} no longer supports this
1668format; if your @sc{gnu} C compiler has this option, do not use it.
1669
1670@need 2000
6d2ebf8b 1671@node Starting
c906108c
SS
1672@section Starting your program
1673@cindex starting
1674@cindex running
1675
1676@table @code
1677@kindex run
41afff9a 1678@kindex r @r{(@code{run})}
c906108c
SS
1679@item run
1680@itemx r
7a292a7a
SS
1681Use the @code{run} command to start your program under @value{GDBN}.
1682You must first specify the program name (except on VxWorks) with an
1683argument to @value{GDBN} (@pxref{Invocation, ,Getting In and Out of
1684@value{GDBN}}), or by using the @code{file} or @code{exec-file} command
1685(@pxref{Files, ,Commands to specify files}).
c906108c
SS
1686
1687@end table
1688
c906108c
SS
1689If you are running your program in an execution environment that
1690supports processes, @code{run} creates an inferior process and makes
1691that process run your program. (In environments without processes,
1692@code{run} jumps to the start of your program.)
1693
1694The execution of a program is affected by certain information it
1695receives from its superior. @value{GDBN} provides ways to specify this
1696information, which you must do @emph{before} starting your program. (You
1697can change it after starting your program, but such changes only affect
1698your program the next time you start it.) This information may be
1699divided into four categories:
1700
1701@table @asis
1702@item The @emph{arguments.}
1703Specify the arguments to give your program as the arguments of the
1704@code{run} command. If a shell is available on your target, the shell
1705is used to pass the arguments, so that you may use normal conventions
1706(such as wildcard expansion or variable substitution) in describing
1707the arguments.
1708In Unix systems, you can control which shell is used with the
1709@code{SHELL} environment variable.
1710@xref{Arguments, ,Your program's arguments}.
1711
1712@item The @emph{environment.}
1713Your program normally inherits its environment from @value{GDBN}, but you can
1714use the @value{GDBN} commands @code{set environment} and @code{unset
1715environment} to change parts of the environment that affect
1716your program. @xref{Environment, ,Your program's environment}.
1717
1718@item The @emph{working directory.}
1719Your program inherits its working directory from @value{GDBN}. You can set
1720the @value{GDBN} working directory with the @code{cd} command in @value{GDBN}.
1721@xref{Working Directory, ,Your program's working directory}.
1722
1723@item The @emph{standard input and output.}
1724Your program normally uses the same device for standard input and
1725standard output as @value{GDBN} is using. You can redirect input and output
1726in the @code{run} command line, or you can use the @code{tty} command to
1727set a different device for your program.
1728@xref{Input/Output, ,Your program's input and output}.
1729
1730@cindex pipes
1731@emph{Warning:} While input and output redirection work, you cannot use
1732pipes to pass the output of the program you are debugging to another
1733program; if you attempt this, @value{GDBN} is likely to wind up debugging the
1734wrong program.
1735@end table
c906108c
SS
1736
1737When you issue the @code{run} command, your program begins to execute
1738immediately. @xref{Stopping, ,Stopping and continuing}, for discussion
1739of how to arrange for your program to stop. Once your program has
1740stopped, you may call functions in your program, using the @code{print}
1741or @code{call} commands. @xref{Data, ,Examining Data}.
1742
1743If the modification time of your symbol file has changed since the last
1744time @value{GDBN} read its symbols, @value{GDBN} discards its symbol
1745table, and reads it again. When it does this, @value{GDBN} tries to retain
1746your current breakpoints.
1747
4e8b0763
JB
1748@table @code
1749@kindex start
1750@item start
1751@cindex run to main procedure
1752The name of the main procedure can vary from language to language.
1753With C or C@t{++}, the main procedure name is always @code{main}, but
1754other languages such as Ada do not require a specific name for their
1755main procedure. The debugger provides a convenient way to start the
1756execution of the program and to stop at the beginning of the main
1757procedure, depending on the language used.
1758
1759The @samp{start} command does the equivalent of setting a temporary
1760breakpoint at the beginning of the main procedure and then invoking
1761the @samp{run} command.
1762
1763Some programs contain an elaboration phase where some startup code is
1764executed before the main program is called. This depends on the
1765languages used to write your program. In C@t{++} for instance,
1766constructors for static and global objects are executed before
1767@code{main} is called. It is therefore possible that the debugger stops
1768before reaching the main procedure. However, the temporary breakpoint
1769will remain to halt execution.
1770
1771Specify the arguments to give to your program as arguments to the
1772@samp{start} command. These arguments will be given verbatim to the
1773underlying @samp{run} command. Note that the same arguments will be
1774reused if no argument is provided during subsequent calls to
1775@samp{start} or @samp{run}.
1776
1777It is sometimes necessary to debug the program during elaboration. In
1778these cases, using the @code{start} command would stop the execution of
1779your program too late, as the program would have already completed the
1780elaboration phase. Under these circumstances, insert breakpoints in your
1781elaboration code before running your program.
1782@end table
1783
6d2ebf8b 1784@node Arguments
c906108c
SS
1785@section Your program's arguments
1786
1787@cindex arguments (to your program)
1788The arguments to your program can be specified by the arguments of the
5d161b24 1789@code{run} command.
c906108c
SS
1790They are passed to a shell, which expands wildcard characters and
1791performs redirection of I/O, and thence to your program. Your
1792@code{SHELL} environment variable (if it exists) specifies what shell
1793@value{GDBN} uses. If you do not define @code{SHELL}, @value{GDBN} uses
d4f3574e
SS
1794the default shell (@file{/bin/sh} on Unix).
1795
1796On non-Unix systems, the program is usually invoked directly by
1797@value{GDBN}, which emulates I/O redirection via the appropriate system
1798calls, and the wildcard characters are expanded by the startup code of
1799the program, not by the shell.
c906108c
SS
1800
1801@code{run} with no arguments uses the same arguments used by the previous
1802@code{run}, or those set by the @code{set args} command.
1803
c906108c 1804@table @code
41afff9a 1805@kindex set args
c906108c
SS
1806@item set args
1807Specify the arguments to be used the next time your program is run. If
1808@code{set args} has no arguments, @code{run} executes your program
1809with no arguments. Once you have run your program with arguments,
1810using @code{set args} before the next @code{run} is the only way to run
1811it again without arguments.
1812
1813@kindex show args
1814@item show args
1815Show the arguments to give your program when it is started.
1816@end table
1817
6d2ebf8b 1818@node Environment
c906108c
SS
1819@section Your program's environment
1820
1821@cindex environment (of your program)
1822The @dfn{environment} consists of a set of environment variables and
1823their values. Environment variables conventionally record such things as
1824your user name, your home directory, your terminal type, and your search
1825path for programs to run. Usually you set up environment variables with
1826the shell and they are inherited by all the other programs you run. When
1827debugging, it can be useful to try running your program with a modified
1828environment without having to start @value{GDBN} over again.
1829
1830@table @code
1831@kindex path
1832@item path @var{directory}
1833Add @var{directory} to the front of the @code{PATH} environment variable
17cc6a06
EZ
1834(the search path for executables) that will be passed to your program.
1835The value of @code{PATH} used by @value{GDBN} does not change.
d4f3574e
SS
1836You may specify several directory names, separated by whitespace or by a
1837system-dependent separator character (@samp{:} on Unix, @samp{;} on
1838MS-DOS and MS-Windows). If @var{directory} is already in the path, it
1839is moved to the front, so it is searched sooner.
c906108c
SS
1840
1841You can use the string @samp{$cwd} to refer to whatever is the current
1842working directory at the time @value{GDBN} searches the path. If you
1843use @samp{.} instead, it refers to the directory where you executed the
1844@code{path} command. @value{GDBN} replaces @samp{.} in the
1845@var{directory} argument (with the current path) before adding
1846@var{directory} to the search path.
1847@c 'path' is explicitly nonrepeatable, but RMS points out it is silly to
1848@c document that, since repeating it would be a no-op.
1849
1850@kindex show paths
1851@item show paths
1852Display the list of search paths for executables (the @code{PATH}
1853environment variable).
1854
1855@kindex show environment
1856@item show environment @r{[}@var{varname}@r{]}
1857Print the value of environment variable @var{varname} to be given to
1858your program when it starts. If you do not supply @var{varname},
1859print the names and values of all environment variables to be given to
1860your program. You can abbreviate @code{environment} as @code{env}.
1861
1862@kindex set environment
53a5351d 1863@item set environment @var{varname} @r{[}=@var{value}@r{]}
c906108c
SS
1864Set environment variable @var{varname} to @var{value}. The value
1865changes for your program only, not for @value{GDBN} itself. @var{value} may
1866be any string; the values of environment variables are just strings, and
1867any interpretation is supplied by your program itself. The @var{value}
1868parameter is optional; if it is eliminated, the variable is set to a
1869null value.
1870@c "any string" here does not include leading, trailing
1871@c blanks. Gnu asks: does anyone care?
1872
1873For example, this command:
1874
474c8240 1875@smallexample
c906108c 1876set env USER = foo
474c8240 1877@end smallexample
c906108c
SS
1878
1879@noindent
d4f3574e 1880tells the debugged program, when subsequently run, that its user is named
c906108c
SS
1881@samp{foo}. (The spaces around @samp{=} are used for clarity here; they
1882are not actually required.)
1883
1884@kindex unset environment
1885@item unset environment @var{varname}
1886Remove variable @var{varname} from the environment to be passed to your
1887program. This is different from @samp{set env @var{varname} =};
1888@code{unset environment} removes the variable from the environment,
1889rather than assigning it an empty value.
1890@end table
1891
d4f3574e
SS
1892@emph{Warning:} On Unix systems, @value{GDBN} runs your program using
1893the shell indicated
c906108c
SS
1894by your @code{SHELL} environment variable if it exists (or
1895@code{/bin/sh} if not). If your @code{SHELL} variable names a shell
1896that runs an initialization file---such as @file{.cshrc} for C-shell, or
1897@file{.bashrc} for BASH---any variables you set in that file affect
1898your program. You may wish to move setting of environment variables to
1899files that are only run when you sign on, such as @file{.login} or
1900@file{.profile}.
1901
6d2ebf8b 1902@node Working Directory
c906108c
SS
1903@section Your program's working directory
1904
1905@cindex working directory (of your program)
1906Each time you start your program with @code{run}, it inherits its
1907working directory from the current working directory of @value{GDBN}.
1908The @value{GDBN} working directory is initially whatever it inherited
1909from its parent process (typically the shell), but you can specify a new
1910working directory in @value{GDBN} with the @code{cd} command.
1911
1912The @value{GDBN} working directory also serves as a default for the commands
1913that specify files for @value{GDBN} to operate on. @xref{Files, ,Commands to
1914specify files}.
1915
1916@table @code
1917@kindex cd
1918@item cd @var{directory}
1919Set the @value{GDBN} working directory to @var{directory}.
1920
1921@kindex pwd
1922@item pwd
1923Print the @value{GDBN} working directory.
1924@end table
1925
6d2ebf8b 1926@node Input/Output
c906108c
SS
1927@section Your program's input and output
1928
1929@cindex redirection
1930@cindex i/o
1931@cindex terminal
1932By default, the program you run under @value{GDBN} does input and output to
5d161b24 1933the same terminal that @value{GDBN} uses. @value{GDBN} switches the terminal
c906108c
SS
1934to its own terminal modes to interact with you, but it records the terminal
1935modes your program was using and switches back to them when you continue
1936running your program.
1937
1938@table @code
1939@kindex info terminal
1940@item info terminal
1941Displays information recorded by @value{GDBN} about the terminal modes your
1942program is using.
1943@end table
1944
1945You can redirect your program's input and/or output using shell
1946redirection with the @code{run} command. For example,
1947
474c8240 1948@smallexample
c906108c 1949run > outfile
474c8240 1950@end smallexample
c906108c
SS
1951
1952@noindent
1953starts your program, diverting its output to the file @file{outfile}.
1954
1955@kindex tty
1956@cindex controlling terminal
1957Another way to specify where your program should do input and output is
1958with the @code{tty} command. This command accepts a file name as
1959argument, and causes this file to be the default for future @code{run}
1960commands. It also resets the controlling terminal for the child
1961process, for future @code{run} commands. For example,
1962
474c8240 1963@smallexample
c906108c 1964tty /dev/ttyb
474c8240 1965@end smallexample
c906108c
SS
1966
1967@noindent
1968directs that processes started with subsequent @code{run} commands
1969default to do input and output on the terminal @file{/dev/ttyb} and have
1970that as their controlling terminal.
1971
1972An explicit redirection in @code{run} overrides the @code{tty} command's
1973effect on the input/output device, but not its effect on the controlling
1974terminal.
1975
1976When you use the @code{tty} command or redirect input in the @code{run}
1977command, only the input @emph{for your program} is affected. The input
1978for @value{GDBN} still comes from your terminal.
1979
6d2ebf8b 1980@node Attach
c906108c
SS
1981@section Debugging an already-running process
1982@kindex attach
1983@cindex attach
1984
1985@table @code
1986@item attach @var{process-id}
1987This command attaches to a running process---one that was started
1988outside @value{GDBN}. (@code{info files} shows your active
1989targets.) The command takes as argument a process ID. The usual way to
1990find out the process-id of a Unix process is with the @code{ps} utility,
1991or with the @samp{jobs -l} shell command.
1992
1993@code{attach} does not repeat if you press @key{RET} a second time after
1994executing the command.
1995@end table
1996
1997To use @code{attach}, your program must be running in an environment
1998which supports processes; for example, @code{attach} does not work for
1999programs on bare-board targets that lack an operating system. You must
2000also have permission to send the process a signal.
2001
2002When you use @code{attach}, the debugger finds the program running in
2003the process first by looking in the current working directory, then (if
2004the program is not found) by using the source file search path
2005(@pxref{Source Path, ,Specifying source directories}). You can also use
2006the @code{file} command to load the program. @xref{Files, ,Commands to
2007Specify Files}.
2008
2009The first thing @value{GDBN} does after arranging to debug the specified
2010process is to stop it. You can examine and modify an attached process
53a5351d
JM
2011with all the @value{GDBN} commands that are ordinarily available when
2012you start processes with @code{run}. You can insert breakpoints; you
2013can step and continue; you can modify storage. If you would rather the
2014process continue running, you may use the @code{continue} command after
c906108c
SS
2015attaching @value{GDBN} to the process.
2016
2017@table @code
2018@kindex detach
2019@item detach
2020When you have finished debugging the attached process, you can use the
2021@code{detach} command to release it from @value{GDBN} control. Detaching
2022the process continues its execution. After the @code{detach} command,
2023that process and @value{GDBN} become completely independent once more, and you
2024are ready to @code{attach} another process or start one with @code{run}.
2025@code{detach} does not repeat if you press @key{RET} again after
2026executing the command.
2027@end table
2028
2029If you exit @value{GDBN} or use the @code{run} command while you have an
2030attached process, you kill that process. By default, @value{GDBN} asks
2031for confirmation if you try to do either of these things; you can
2032control whether or not you need to confirm by using the @code{set
2033confirm} command (@pxref{Messages/Warnings, ,Optional warnings and
2034messages}).
2035
6d2ebf8b 2036@node Kill Process
c906108c 2037@section Killing the child process
c906108c
SS
2038
2039@table @code
2040@kindex kill
2041@item kill
2042Kill the child process in which your program is running under @value{GDBN}.
2043@end table
2044
2045This command is useful if you wish to debug a core dump instead of a
2046running process. @value{GDBN} ignores any core dump file while your program
2047is running.
2048
2049On some operating systems, a program cannot be executed outside @value{GDBN}
2050while you have breakpoints set on it inside @value{GDBN}. You can use the
2051@code{kill} command in this situation to permit running your program
2052outside the debugger.
2053
2054The @code{kill} command is also useful if you wish to recompile and
2055relink your program, since on many systems it is impossible to modify an
2056executable file while it is running in a process. In this case, when you
2057next type @code{run}, @value{GDBN} notices that the file has changed, and
2058reads the symbol table again (while trying to preserve your current
2059breakpoint settings).
2060
6d2ebf8b 2061@node Threads
c906108c 2062@section Debugging programs with multiple threads
c906108c
SS
2063
2064@cindex threads of execution
2065@cindex multiple threads
2066@cindex switching threads
2067In some operating systems, such as HP-UX and Solaris, a single program
2068may have more than one @dfn{thread} of execution. The precise semantics
2069of threads differ from one operating system to another, but in general
2070the threads of a single program are akin to multiple processes---except
2071that they share one address space (that is, they can all examine and
2072modify the same variables). On the other hand, each thread has its own
2073registers and execution stack, and perhaps private memory.
2074
2075@value{GDBN} provides these facilities for debugging multi-thread
2076programs:
2077
2078@itemize @bullet
2079@item automatic notification of new threads
2080@item @samp{thread @var{threadno}}, a command to switch among threads
2081@item @samp{info threads}, a command to inquire about existing threads
5d161b24 2082@item @samp{thread apply [@var{threadno}] [@var{all}] @var{args}},
c906108c
SS
2083a command to apply a command to a list of threads
2084@item thread-specific breakpoints
2085@end itemize
2086
c906108c
SS
2087@quotation
2088@emph{Warning:} These facilities are not yet available on every
2089@value{GDBN} configuration where the operating system supports threads.
2090If your @value{GDBN} does not support threads, these commands have no
2091effect. For example, a system without thread support shows no output
2092from @samp{info threads}, and always rejects the @code{thread} command,
2093like this:
2094
2095@smallexample
2096(@value{GDBP}) info threads
2097(@value{GDBP}) thread 1
2098Thread ID 1 not known. Use the "info threads" command to
2099see the IDs of currently known threads.
2100@end smallexample
2101@c FIXME to implementors: how hard would it be to say "sorry, this GDB
2102@c doesn't support threads"?
2103@end quotation
c906108c
SS
2104
2105@cindex focus of debugging
2106@cindex current thread
2107The @value{GDBN} thread debugging facility allows you to observe all
2108threads while your program runs---but whenever @value{GDBN} takes
2109control, one thread in particular is always the focus of debugging.
2110This thread is called the @dfn{current thread}. Debugging commands show
2111program information from the perspective of the current thread.
2112
41afff9a 2113@cindex @code{New} @var{systag} message
c906108c
SS
2114@cindex thread identifier (system)
2115@c FIXME-implementors!! It would be more helpful if the [New...] message
2116@c included GDB's numeric thread handle, so you could just go to that
2117@c thread without first checking `info threads'.
2118Whenever @value{GDBN} detects a new thread in your program, it displays
2119the target system's identification for the thread with a message in the
2120form @samp{[New @var{systag}]}. @var{systag} is a thread identifier
2121whose form varies depending on the particular system. For example, on
2122LynxOS, you might see
2123
474c8240 2124@smallexample
c906108c 2125[New process 35 thread 27]
474c8240 2126@end smallexample
c906108c
SS
2127
2128@noindent
2129when @value{GDBN} notices a new thread. In contrast, on an SGI system,
2130the @var{systag} is simply something like @samp{process 368}, with no
2131further qualifier.
2132
2133@c FIXME!! (1) Does the [New...] message appear even for the very first
2134@c thread of a program, or does it only appear for the
6ca652b0 2135@c second---i.e.@: when it becomes obvious we have a multithread
c906108c
SS
2136@c program?
2137@c (2) *Is* there necessarily a first thread always? Or do some
2138@c multithread systems permit starting a program with multiple
5d161b24 2139@c threads ab initio?
c906108c
SS
2140
2141@cindex thread number
2142@cindex thread identifier (GDB)
2143For debugging purposes, @value{GDBN} associates its own thread
2144number---always a single integer---with each thread in your program.
2145
2146@table @code
2147@kindex info threads
2148@item info threads
2149Display a summary of all threads currently in your
2150program. @value{GDBN} displays for each thread (in this order):
2151
2152@enumerate
2153@item the thread number assigned by @value{GDBN}
2154
2155@item the target system's thread identifier (@var{systag})
2156
2157@item the current stack frame summary for that thread
2158@end enumerate
2159
2160@noindent
2161An asterisk @samp{*} to the left of the @value{GDBN} thread number
2162indicates the current thread.
2163
5d161b24 2164For example,
c906108c
SS
2165@end table
2166@c end table here to get a little more width for example
2167
2168@smallexample
2169(@value{GDBP}) info threads
2170 3 process 35 thread 27 0x34e5 in sigpause ()
2171 2 process 35 thread 23 0x34e5 in sigpause ()
2172* 1 process 35 thread 13 main (argc=1, argv=0x7ffffff8)
2173 at threadtest.c:68
2174@end smallexample
53a5351d
JM
2175
2176On HP-UX systems:
c906108c 2177
4644b6e3
EZ
2178@cindex debugging multithreaded programs (on HP-UX)
2179@cindex thread identifier (GDB), on HP-UX
c906108c
SS
2180For debugging purposes, @value{GDBN} associates its own thread
2181number---a small integer assigned in thread-creation order---with each
2182thread in your program.
2183
41afff9a
EZ
2184@cindex @code{New} @var{systag} message, on HP-UX
2185@cindex thread identifier (system), on HP-UX
c906108c
SS
2186@c FIXME-implementors!! It would be more helpful if the [New...] message
2187@c included GDB's numeric thread handle, so you could just go to that
2188@c thread without first checking `info threads'.
2189Whenever @value{GDBN} detects a new thread in your program, it displays
2190both @value{GDBN}'s thread number and the target system's identification for the thread with a message in the
2191form @samp{[New @var{systag}]}. @var{systag} is a thread identifier
2192whose form varies depending on the particular system. For example, on
2193HP-UX, you see
2194
474c8240 2195@smallexample
c906108c 2196[New thread 2 (system thread 26594)]
474c8240 2197@end smallexample
c906108c
SS
2198
2199@noindent
5d161b24 2200when @value{GDBN} notices a new thread.
c906108c
SS
2201
2202@table @code
4644b6e3 2203@kindex info threads (HP-UX)
c906108c
SS
2204@item info threads
2205Display a summary of all threads currently in your
2206program. @value{GDBN} displays for each thread (in this order):
2207
2208@enumerate
2209@item the thread number assigned by @value{GDBN}
2210
2211@item the target system's thread identifier (@var{systag})
2212
2213@item the current stack frame summary for that thread
2214@end enumerate
2215
2216@noindent
2217An asterisk @samp{*} to the left of the @value{GDBN} thread number
2218indicates the current thread.
2219
5d161b24 2220For example,
c906108c
SS
2221@end table
2222@c end table here to get a little more width for example
2223
474c8240 2224@smallexample
c906108c 2225(@value{GDBP}) info threads
6d2ebf8b
SS
2226 * 3 system thread 26607 worker (wptr=0x7b09c318 "@@") \@*
2227 at quicksort.c:137
2228 2 system thread 26606 0x7b0030d8 in __ksleep () \@*
2229 from /usr/lib/libc.2
2230 1 system thread 27905 0x7b003498 in _brk () \@*
2231 from /usr/lib/libc.2
474c8240 2232@end smallexample
c906108c
SS
2233
2234@table @code
2235@kindex thread @var{threadno}
2236@item thread @var{threadno}
2237Make thread number @var{threadno} the current thread. The command
2238argument @var{threadno} is the internal @value{GDBN} thread number, as
2239shown in the first field of the @samp{info threads} display.
2240@value{GDBN} responds by displaying the system identifier of the thread
2241you selected, and its current stack frame summary:
2242
2243@smallexample
2244@c FIXME!! This example made up; find a @value{GDBN} w/threads and get real one
2245(@value{GDBP}) thread 2
c906108c 2246[Switching to process 35 thread 23]
c906108c
SS
22470x34e5 in sigpause ()
2248@end smallexample
2249
2250@noindent
2251As with the @samp{[New @dots{}]} message, the form of the text after
2252@samp{Switching to} depends on your system's conventions for identifying
5d161b24 2253threads.
c906108c 2254
c906108c
SS
2255@item thread apply [@var{threadno}] [@var{all}] @var{args}
2256The @code{thread apply} command allows you to apply a command to one or
2257more threads. Specify the numbers of the threads that you want affected
2258with the command argument @var{threadno}. @var{threadno} is the internal
2259@value{GDBN} thread number, as shown in the first field of the @samp{info
5d161b24
DB
2260threads} display. To apply a command to all threads, use
2261@code{thread apply all} @var{args}.
c906108c
SS
2262@end table
2263
2264@cindex automatic thread selection
2265@cindex switching threads automatically
2266@cindex threads, automatic switching
2267Whenever @value{GDBN} stops your program, due to a breakpoint or a
2268signal, it automatically selects the thread where that breakpoint or
2269signal happened. @value{GDBN} alerts you to the context switch with a
2270message of the form @samp{[Switching to @var{systag}]} to identify the
2271thread.
2272
2273@xref{Thread Stops,,Stopping and starting multi-thread programs}, for
2274more information about how @value{GDBN} behaves when you stop and start
2275programs with multiple threads.
2276
2277@xref{Set Watchpoints,,Setting watchpoints}, for information about
2278watchpoints in programs with multiple threads.
c906108c 2279
6d2ebf8b 2280@node Processes
c906108c
SS
2281@section Debugging programs with multiple processes
2282
2283@cindex fork, debugging programs which call
2284@cindex multiple processes
2285@cindex processes, multiple
53a5351d
JM
2286On most systems, @value{GDBN} has no special support for debugging
2287programs which create additional processes using the @code{fork}
2288function. When a program forks, @value{GDBN} will continue to debug the
2289parent process and the child process will run unimpeded. If you have
2290set a breakpoint in any code which the child then executes, the child
2291will get a @code{SIGTRAP} signal which (unless it catches the signal)
2292will cause it to terminate.
c906108c
SS
2293
2294However, if you want to debug the child process there is a workaround
2295which isn't too painful. Put a call to @code{sleep} in the code which
2296the child process executes after the fork. It may be useful to sleep
2297only if a certain environment variable is set, or a certain file exists,
2298so that the delay need not occur when you don't want to run @value{GDBN}
2299on the child. While the child is sleeping, use the @code{ps} program to
2300get its process ID. Then tell @value{GDBN} (a new invocation of
2301@value{GDBN} if you are also debugging the parent process) to attach to
d4f3574e 2302the child process (@pxref{Attach}). From that point on you can debug
c906108c 2303the child process just like any other process which you attached to.
c906108c 2304
b51970ac
DJ
2305On some systems, @value{GDBN} provides support for debugging programs that
2306create additional processes using the @code{fork} or @code{vfork} functions.
2307Currently, the only platforms with this feature are HP-UX (11.x and later
2308only?) and GNU/Linux (kernel version 2.5.60 and later).
c906108c
SS
2309
2310By default, when a program forks, @value{GDBN} will continue to debug
2311the parent process and the child process will run unimpeded.
2312
2313If you want to follow the child process instead of the parent process,
2314use the command @w{@code{set follow-fork-mode}}.
2315
2316@table @code
2317@kindex set follow-fork-mode
2318@item set follow-fork-mode @var{mode}
2319Set the debugger response to a program call of @code{fork} or
2320@code{vfork}. A call to @code{fork} or @code{vfork} creates a new
2321process. The @var{mode} can be:
2322
2323@table @code
2324@item parent
2325The original process is debugged after a fork. The child process runs
2df3850c 2326unimpeded. This is the default.
c906108c
SS
2327
2328@item child
2329The new process is debugged after a fork. The parent process runs
2330unimpeded.
2331
c906108c
SS
2332@end table
2333
2334@item show follow-fork-mode
2df3850c 2335Display the current debugger response to a @code{fork} or @code{vfork} call.
c906108c
SS
2336@end table
2337
2338If you ask to debug a child process and a @code{vfork} is followed by an
2339@code{exec}, @value{GDBN} executes the new target up to the first
2340breakpoint in the new target. If you have a breakpoint set on
2341@code{main} in your original program, the breakpoint will also be set on
2342the child process's @code{main}.
2343
2344When a child process is spawned by @code{vfork}, you cannot debug the
2345child or parent until an @code{exec} call completes.
2346
2347If you issue a @code{run} command to @value{GDBN} after an @code{exec}
2348call executes, the new target restarts. To restart the parent process,
2349use the @code{file} command with the parent executable name as its
2350argument.
2351
2352You can use the @code{catch} command to make @value{GDBN} stop whenever
2353a @code{fork}, @code{vfork}, or @code{exec} call is made. @xref{Set
2354Catchpoints, ,Setting catchpoints}.
c906108c 2355
6d2ebf8b 2356@node Stopping
c906108c
SS
2357@chapter Stopping and Continuing
2358
2359The principal purposes of using a debugger are so that you can stop your
2360program before it terminates; or so that, if your program runs into
2361trouble, you can investigate and find out why.
2362
7a292a7a
SS
2363Inside @value{GDBN}, your program may stop for any of several reasons,
2364such as a signal, a breakpoint, or reaching a new line after a
2365@value{GDBN} command such as @code{step}. You may then examine and
2366change variables, set new breakpoints or remove old ones, and then
2367continue execution. Usually, the messages shown by @value{GDBN} provide
2368ample explanation of the status of your program---but you can also
2369explicitly request this information at any time.
c906108c
SS
2370
2371@table @code
2372@kindex info program
2373@item info program
2374Display information about the status of your program: whether it is
7a292a7a 2375running or not, what process it is, and why it stopped.
c906108c
SS
2376@end table
2377
2378@menu
2379* Breakpoints:: Breakpoints, watchpoints, and catchpoints
2380* Continuing and Stepping:: Resuming execution
c906108c 2381* Signals:: Signals
c906108c 2382* Thread Stops:: Stopping and starting multi-thread programs
c906108c
SS
2383@end menu
2384
6d2ebf8b 2385@node Breakpoints
c906108c
SS
2386@section Breakpoints, watchpoints, and catchpoints
2387
2388@cindex breakpoints
2389A @dfn{breakpoint} makes your program stop whenever a certain point in
2390the program is reached. For each breakpoint, you can add conditions to
2391control in finer detail whether your program stops. You can set
2392breakpoints with the @code{break} command and its variants (@pxref{Set
2393Breaks, ,Setting breakpoints}), to specify the place where your program
2394should stop by line number, function name or exact address in the
2395program.
2396
2397In HP-UX, SunOS 4.x, SVR4, and Alpha OSF/1 configurations, you can set
2398breakpoints in shared libraries before the executable is run. There is
2399a minor limitation on HP-UX systems: you must wait until the executable
2400is run in order to set breakpoints in shared library routines that are
2401not called directly by the program (for example, routines that are
2402arguments in a @code{pthread_create} call).
2403
2404@cindex watchpoints
2405@cindex memory tracing
2406@cindex breakpoint on memory address
2407@cindex breakpoint on variable modification
2408A @dfn{watchpoint} is a special breakpoint that stops your program
2409when the value of an expression changes. You must use a different
2410command to set watchpoints (@pxref{Set Watchpoints, ,Setting
2411watchpoints}), but aside from that, you can manage a watchpoint like
2412any other breakpoint: you enable, disable, and delete both breakpoints
2413and watchpoints using the same commands.
2414
2415You can arrange to have values from your program displayed automatically
2416whenever @value{GDBN} stops at a breakpoint. @xref{Auto Display,,
2417Automatic display}.
2418
2419@cindex catchpoints
2420@cindex breakpoint on events
2421A @dfn{catchpoint} is another special breakpoint that stops your program
b37052ae 2422when a certain kind of event occurs, such as the throwing of a C@t{++}
c906108c
SS
2423exception or the loading of a library. As with watchpoints, you use a
2424different command to set a catchpoint (@pxref{Set Catchpoints, ,Setting
2425catchpoints}), but aside from that, you can manage a catchpoint like any
2426other breakpoint. (To stop when your program receives a signal, use the
d4f3574e 2427@code{handle} command; see @ref{Signals, ,Signals}.)
c906108c
SS
2428
2429@cindex breakpoint numbers
2430@cindex numbers for breakpoints
2431@value{GDBN} assigns a number to each breakpoint, watchpoint, or
2432catchpoint when you create it; these numbers are successive integers
2433starting with one. In many of the commands for controlling various
2434features of breakpoints you use the breakpoint number to say which
2435breakpoint you want to change. Each breakpoint may be @dfn{enabled} or
2436@dfn{disabled}; if disabled, it has no effect on your program until you
2437enable it again.
2438
c5394b80
JM
2439@cindex breakpoint ranges
2440@cindex ranges of breakpoints
2441Some @value{GDBN} commands accept a range of breakpoints on which to
2442operate. A breakpoint range is either a single breakpoint number, like
2443@samp{5}, or two such numbers, in increasing order, separated by a
2444hyphen, like @samp{5-7}. When a breakpoint range is given to a command,
2445all breakpoint in that range are operated on.
2446
c906108c
SS
2447@menu
2448* Set Breaks:: Setting breakpoints
2449* Set Watchpoints:: Setting watchpoints
2450* Set Catchpoints:: Setting catchpoints
2451* Delete Breaks:: Deleting breakpoints
2452* Disabling:: Disabling breakpoints
2453* Conditions:: Break conditions
2454* Break Commands:: Breakpoint command lists
c906108c 2455* Breakpoint Menus:: Breakpoint menus
d4f3574e 2456* Error in Breakpoints:: ``Cannot insert breakpoints''
e4d5f7e1 2457* Breakpoint related warnings:: ``Breakpoint address adjusted...''
c906108c
SS
2458@end menu
2459
6d2ebf8b 2460@node Set Breaks
c906108c
SS
2461@subsection Setting breakpoints
2462
5d161b24 2463@c FIXME LMB what does GDB do if no code on line of breakpt?
c906108c
SS
2464@c consider in particular declaration with/without initialization.
2465@c
2466@c FIXME 2 is there stuff on this already? break at fun start, already init?
2467
2468@kindex break
41afff9a
EZ
2469@kindex b @r{(@code{break})}
2470@vindex $bpnum@r{, convenience variable}
c906108c
SS
2471@cindex latest breakpoint
2472Breakpoints are set with the @code{break} command (abbreviated
5d161b24 2473@code{b}). The debugger convenience variable @samp{$bpnum} records the
f3b28801 2474number of the breakpoint you've set most recently; see @ref{Convenience
c906108c
SS
2475Vars,, Convenience variables}, for a discussion of what you can do with
2476convenience variables.
2477
2478You have several ways to say where the breakpoint should go.
2479
2480@table @code
2481@item break @var{function}
5d161b24 2482Set a breakpoint at entry to function @var{function}.
c906108c 2483When using source languages that permit overloading of symbols, such as
b37052ae 2484C@t{++}, @var{function} may refer to more than one possible place to break.
c906108c 2485@xref{Breakpoint Menus,,Breakpoint menus}, for a discussion of that situation.
c906108c
SS
2486
2487@item break +@var{offset}
2488@itemx break -@var{offset}
2489Set a breakpoint some number of lines forward or back from the position
d4f3574e 2490at which execution stopped in the currently selected @dfn{stack frame}.
2df3850c 2491(@xref{Frames, ,Frames}, for a description of stack frames.)
c906108c
SS
2492
2493@item break @var{linenum}
2494Set a breakpoint at line @var{linenum} in the current source file.
d4f3574e
SS
2495The current source file is the last file whose source text was printed.
2496The breakpoint will stop your program just before it executes any of the
c906108c
SS
2497code on that line.
2498
2499@item break @var{filename}:@var{linenum}
2500Set a breakpoint at line @var{linenum} in source file @var{filename}.
2501
2502@item break @var{filename}:@var{function}
2503Set a breakpoint at entry to function @var{function} found in file
2504@var{filename}. Specifying a file name as well as a function name is
2505superfluous except when multiple files contain similarly named
2506functions.
2507
2508@item break *@var{address}
2509Set a breakpoint at address @var{address}. You can use this to set
2510breakpoints in parts of your program which do not have debugging
2511information or source files.
2512
2513@item break
2514When called without any arguments, @code{break} sets a breakpoint at
2515the next instruction to be executed in the selected stack frame
2516(@pxref{Stack, ,Examining the Stack}). In any selected frame but the
2517innermost, this makes your program stop as soon as control
2518returns to that frame. This is similar to the effect of a
2519@code{finish} command in the frame inside the selected frame---except
2520that @code{finish} does not leave an active breakpoint. If you use
2521@code{break} without an argument in the innermost frame, @value{GDBN} stops
2522the next time it reaches the current location; this may be useful
2523inside loops.
2524
2525@value{GDBN} normally ignores breakpoints when it resumes execution, until at
2526least one instruction has been executed. If it did not do this, you
2527would be unable to proceed past a breakpoint without first disabling the
2528breakpoint. This rule applies whether or not the breakpoint already
2529existed when your program stopped.
2530
2531@item break @dots{} if @var{cond}
2532Set a breakpoint with condition @var{cond}; evaluate the expression
2533@var{cond} each time the breakpoint is reached, and stop only if the
2534value is nonzero---that is, if @var{cond} evaluates as true.
2535@samp{@dots{}} stands for one of the possible arguments described
2536above (or no argument) specifying where to break. @xref{Conditions,
2537,Break conditions}, for more information on breakpoint conditions.
2538
2539@kindex tbreak
2540@item tbreak @var{args}
2541Set a breakpoint enabled only for one stop. @var{args} are the
2542same as for the @code{break} command, and the breakpoint is set in the same
2543way, but the breakpoint is automatically deleted after the first time your
2544program stops there. @xref{Disabling, ,Disabling breakpoints}.
2545
c906108c
SS
2546@kindex hbreak
2547@item hbreak @var{args}
d4f3574e
SS
2548Set a hardware-assisted breakpoint. @var{args} are the same as for the
2549@code{break} command and the breakpoint is set in the same way, but the
c906108c
SS
2550breakpoint requires hardware support and some target hardware may not
2551have this support. The main purpose of this is EPROM/ROM code
d4f3574e
SS
2552debugging, so you can set a breakpoint at an instruction without
2553changing the instruction. This can be used with the new trap-generation
2554provided by SPARClite DSU and some x86-based targets. These targets
2555will generate traps when a program accesses some data or instruction
2556address that is assigned to the debug registers. However the hardware
2557breakpoint registers can take a limited number of breakpoints. For
2558example, on the DSU, only two data breakpoints can be set at a time, and
2559@value{GDBN} will reject this command if more than two are used. Delete
2560or disable unused hardware breakpoints before setting new ones
2561(@pxref{Disabling, ,Disabling}). @xref{Conditions, ,Break conditions}.
501eef12
AC
2562@xref{set remote hardware-breakpoint-limit}.
2563
c906108c
SS
2564
2565@kindex thbreak
2566@item thbreak @var{args}
2567Set a hardware-assisted breakpoint enabled only for one stop. @var{args}
2568are the same as for the @code{hbreak} command and the breakpoint is set in
5d161b24 2569the same way. However, like the @code{tbreak} command,
c906108c
SS
2570the breakpoint is automatically deleted after the
2571first time your program stops there. Also, like the @code{hbreak}
5d161b24
DB
2572command, the breakpoint requires hardware support and some target hardware
2573may not have this support. @xref{Disabling, ,Disabling breakpoints}.
d4f3574e 2574See also @ref{Conditions, ,Break conditions}.
c906108c
SS
2575
2576@kindex rbreak
2577@cindex regular expression
2578@item rbreak @var{regex}
c906108c 2579Set breakpoints on all functions matching the regular expression
11cf8741
JM
2580@var{regex}. This command sets an unconditional breakpoint on all
2581matches, printing a list of all breakpoints it set. Once these
2582breakpoints are set, they are treated just like the breakpoints set with
2583the @code{break} command. You can delete them, disable them, or make
2584them conditional the same way as any other breakpoint.
2585
2586The syntax of the regular expression is the standard one used with tools
2587like @file{grep}. Note that this is different from the syntax used by
2588shells, so for instance @code{foo*} matches all functions that include
2589an @code{fo} followed by zero or more @code{o}s. There is an implicit
2590@code{.*} leading and trailing the regular expression you supply, so to
2591match only functions that begin with @code{foo}, use @code{^foo}.
c906108c 2592
b37052ae 2593When debugging C@t{++} programs, @code{rbreak} is useful for setting
c906108c
SS
2594breakpoints on overloaded functions that are not members of any special
2595classes.
c906108c
SS
2596
2597@kindex info breakpoints
2598@cindex @code{$_} and @code{info breakpoints}
2599@item info breakpoints @r{[}@var{n}@r{]}
2600@itemx info break @r{[}@var{n}@r{]}
2601@itemx info watchpoints @r{[}@var{n}@r{]}
2602Print a table of all breakpoints, watchpoints, and catchpoints set and
2603not deleted, with the following columns for each breakpoint:
2604
2605@table @emph
2606@item Breakpoint Numbers
2607@item Type
2608Breakpoint, watchpoint, or catchpoint.
2609@item Disposition
2610Whether the breakpoint is marked to be disabled or deleted when hit.
2611@item Enabled or Disabled
2612Enabled breakpoints are marked with @samp{y}. @samp{n} marks breakpoints
2613that are not enabled.
2614@item Address
2650777c
JJ
2615Where the breakpoint is in your program, as a memory address. If the
2616breakpoint is pending (see below for details) on a future load of a shared library, the address
2617will be listed as @samp{<PENDING>}.
c906108c
SS
2618@item What
2619Where the breakpoint is in the source for your program, as a file and
2650777c
JJ
2620line number. For a pending breakpoint, the original string passed to
2621the breakpoint command will be listed as it cannot be resolved until
2622the appropriate shared library is loaded in the future.
c906108c
SS
2623@end table
2624
2625@noindent
2626If a breakpoint is conditional, @code{info break} shows the condition on
2627the line following the affected breakpoint; breakpoint commands, if any,
2650777c
JJ
2628are listed after that. A pending breakpoint is allowed to have a condition
2629specified for it. The condition is not parsed for validity until a shared
2630library is loaded that allows the pending breakpoint to resolve to a
2631valid location.
c906108c
SS
2632
2633@noindent
2634@code{info break} with a breakpoint
2635number @var{n} as argument lists only that breakpoint. The
2636convenience variable @code{$_} and the default examining-address for
2637the @code{x} command are set to the address of the last breakpoint
5d161b24 2638listed (@pxref{Memory, ,Examining memory}).
c906108c
SS
2639
2640@noindent
2641@code{info break} displays a count of the number of times the breakpoint
2642has been hit. This is especially useful in conjunction with the
2643@code{ignore} command. You can ignore a large number of breakpoint
2644hits, look at the breakpoint info to see how many times the breakpoint
2645was hit, and then run again, ignoring one less than that number. This
2646will get you quickly to the last hit of that breakpoint.
2647@end table
2648
2649@value{GDBN} allows you to set any number of breakpoints at the same place in
2650your program. There is nothing silly or meaningless about this. When
2651the breakpoints are conditional, this is even useful
2652(@pxref{Conditions, ,Break conditions}).
2653
2650777c 2654@cindex pending breakpoints
dd79a6cf
JJ
2655If a specified breakpoint location cannot be found, it may be due to the fact
2656that the location is in a shared library that is yet to be loaded. In such
2657a case, you may want @value{GDBN} to create a special breakpoint (known as
2658a @dfn{pending breakpoint}) that
2659attempts to resolve itself in the future when an appropriate shared library
2660gets loaded.
2661
2662Pending breakpoints are useful to set at the start of your
2650777c
JJ
2663@value{GDBN} session for locations that you know will be dynamically loaded
2664later by the program being debugged. When shared libraries are loaded,
dd79a6cf
JJ
2665a check is made to see if the load resolves any pending breakpoint locations.
2666If a pending breakpoint location gets resolved,
2667a regular breakpoint is created and the original pending breakpoint is removed.
2668
2669@value{GDBN} provides some additional commands for controlling pending
2670breakpoint support:
2671
2672@kindex set breakpoint pending
2673@kindex show breakpoint pending
2674@table @code
2675@item set breakpoint pending auto
2676This is the default behavior. When @value{GDBN} cannot find the breakpoint
2677location, it queries you whether a pending breakpoint should be created.
2678
2679@item set breakpoint pending on
2680This indicates that an unrecognized breakpoint location should automatically
2681result in a pending breakpoint being created.
2682
2683@item set breakpoint pending off
2684This indicates that pending breakpoints are not to be created. Any
2685unrecognized breakpoint location results in an error. This setting does
2686not affect any pending breakpoints previously created.
2687
2688@item show breakpoint pending
2689Show the current behavior setting for creating pending breakpoints.
2690@end table
2650777c 2691
649e03f6
RM
2692@cindex operations allowed on pending breakpoints
2693Normal breakpoint operations apply to pending breakpoints as well. You may
2694specify a condition for a pending breakpoint and/or commands to run when the
2650777c
JJ
2695breakpoint is reached. You can also enable or disable
2696the pending breakpoint. When you specify a condition for a pending breakpoint,
2697the parsing of the condition will be deferred until the point where the
2698pending breakpoint location is resolved. Disabling a pending breakpoint
2699tells @value{GDBN} to not attempt to resolve the breakpoint on any subsequent
2700shared library load. When a pending breakpoint is re-enabled,
649e03f6 2701@value{GDBN} checks to see if the location is already resolved.
2650777c
JJ
2702This is done because any number of shared library loads could have
2703occurred since the time the breakpoint was disabled and one or more
2704of these loads could resolve the location.
2705
c906108c
SS
2706@cindex negative breakpoint numbers
2707@cindex internal @value{GDBN} breakpoints
eb12ee30
AC
2708@value{GDBN} itself sometimes sets breakpoints in your program for
2709special purposes, such as proper handling of @code{longjmp} (in C
2710programs). These internal breakpoints are assigned negative numbers,
2711starting with @code{-1}; @samp{info breakpoints} does not display them.
c906108c 2712You can see these breakpoints with the @value{GDBN} maintenance command
eb12ee30 2713@samp{maint info breakpoints} (@pxref{maint info breakpoints}).
c906108c
SS
2714
2715
6d2ebf8b 2716@node Set Watchpoints
c906108c
SS
2717@subsection Setting watchpoints
2718
2719@cindex setting watchpoints
2720@cindex software watchpoints
2721@cindex hardware watchpoints
2722You can use a watchpoint to stop execution whenever the value of an
2723expression changes, without having to predict a particular place where
2724this may happen.
2725
2726Depending on your system, watchpoints may be implemented in software or
2df3850c 2727hardware. @value{GDBN} does software watchpointing by single-stepping your
c906108c
SS
2728program and testing the variable's value each time, which is hundreds of
2729times slower than normal execution. (But this may still be worth it, to
2730catch errors where you have no clue what part of your program is the
2731culprit.)
2732
1104b9e7 2733On some systems, such as HP-UX, @sc{gnu}/Linux and some other x86-based targets,
2df3850c 2734@value{GDBN} includes support for
c906108c
SS
2735hardware watchpoints, which do not slow down the running of your
2736program.
2737
2738@table @code
2739@kindex watch
2740@item watch @var{expr}
2741Set a watchpoint for an expression. @value{GDBN} will break when @var{expr}
2742is written into by the program and its value changes.
2743
2744@kindex rwatch
2745@item rwatch @var{expr}
2746Set a watchpoint that will break when watch @var{expr} is read by the program.
c906108c
SS
2747
2748@kindex awatch
2749@item awatch @var{expr}
2df3850c 2750Set a watchpoint that will break when @var{expr} is either read or written into
7be570e7 2751by the program.
c906108c
SS
2752
2753@kindex info watchpoints
2754@item info watchpoints
2755This command prints a list of watchpoints, breakpoints, and catchpoints;
2756it is the same as @code{info break}.
2757@end table
2758
2759@value{GDBN} sets a @dfn{hardware watchpoint} if possible. Hardware
2760watchpoints execute very quickly, and the debugger reports a change in
2761value at the exact instruction where the change occurs. If @value{GDBN}
2762cannot set a hardware watchpoint, it sets a software watchpoint, which
2763executes more slowly and reports the change in value at the next
2764statement, not the instruction, after the change occurs.
2765
2766When you issue the @code{watch} command, @value{GDBN} reports
2767
474c8240 2768@smallexample
c906108c 2769Hardware watchpoint @var{num}: @var{expr}
474c8240 2770@end smallexample
c906108c
SS
2771
2772@noindent
2773if it was able to set a hardware watchpoint.
2774
7be570e7
JM
2775Currently, the @code{awatch} and @code{rwatch} commands can only set
2776hardware watchpoints, because accesses to data that don't change the
2777value of the watched expression cannot be detected without examining
2778every instruction as it is being executed, and @value{GDBN} does not do
2779that currently. If @value{GDBN} finds that it is unable to set a
2780hardware breakpoint with the @code{awatch} or @code{rwatch} command, it
2781will print a message like this:
2782
2783@smallexample
2784Expression cannot be implemented with read/access watchpoint.
2785@end smallexample
2786
2787Sometimes, @value{GDBN} cannot set a hardware watchpoint because the
2788data type of the watched expression is wider than what a hardware
2789watchpoint on the target machine can handle. For example, some systems
2790can only watch regions that are up to 4 bytes wide; on such systems you
2791cannot set hardware watchpoints for an expression that yields a
2792double-precision floating-point number (which is typically 8 bytes
2793wide). As a work-around, it might be possible to break the large region
2794into a series of smaller ones and watch them with separate watchpoints.
2795
2796If you set too many hardware watchpoints, @value{GDBN} might be unable
2797to insert all of them when you resume the execution of your program.
2798Since the precise number of active watchpoints is unknown until such
2799time as the program is about to be resumed, @value{GDBN} might not be
2800able to warn you about this when you set the watchpoints, and the
2801warning will be printed only when the program is resumed:
2802
2803@smallexample
2804Hardware watchpoint @var{num}: Could not insert watchpoint
2805@end smallexample
2806
2807@noindent
2808If this happens, delete or disable some of the watchpoints.
2809
2810The SPARClite DSU will generate traps when a program accesses some data
2811or instruction address that is assigned to the debug registers. For the
2812data addresses, DSU facilitates the @code{watch} command. However the
2813hardware breakpoint registers can only take two data watchpoints, and
2814both watchpoints must be the same kind. For example, you can set two
2815watchpoints with @code{watch} commands, two with @code{rwatch} commands,
2816@strong{or} two with @code{awatch} commands, but you cannot set one
2817watchpoint with one command and the other with a different command.
c906108c
SS
2818@value{GDBN} will reject the command if you try to mix watchpoints.
2819Delete or disable unused watchpoint commands before setting new ones.
2820
2821If you call a function interactively using @code{print} or @code{call},
2df3850c 2822any watchpoints you have set will be inactive until @value{GDBN} reaches another
c906108c
SS
2823kind of breakpoint or the call completes.
2824
7be570e7
JM
2825@value{GDBN} automatically deletes watchpoints that watch local
2826(automatic) variables, or expressions that involve such variables, when
2827they go out of scope, that is, when the execution leaves the block in
2828which these variables were defined. In particular, when the program
2829being debugged terminates, @emph{all} local variables go out of scope,
2830and so only watchpoints that watch global variables remain set. If you
2831rerun the program, you will need to set all such watchpoints again. One
2832way of doing that would be to set a code breakpoint at the entry to the
2833@code{main} function and when it breaks, set all the watchpoints.
2834
c906108c
SS
2835@quotation
2836@cindex watchpoints and threads
2837@cindex threads and watchpoints
c906108c
SS
2838@emph{Warning:} In multi-thread programs, watchpoints have only limited
2839usefulness. With the current watchpoint implementation, @value{GDBN}
2840can only watch the value of an expression @emph{in a single thread}. If
2841you are confident that the expression can only change due to the current
2842thread's activity (and if you are also confident that no other thread
2843can become current), then you can use watchpoints as usual. However,
2844@value{GDBN} may not notice when a non-current thread's activity changes
2845the expression.
53a5351d 2846
d4f3574e 2847@c FIXME: this is almost identical to the previous paragraph.
53a5351d
JM
2848@emph{HP-UX Warning:} In multi-thread programs, software watchpoints
2849have only limited usefulness. If @value{GDBN} creates a software
2850watchpoint, it can only watch the value of an expression @emph{in a
2851single thread}. If you are confident that the expression can only
2852change due to the current thread's activity (and if you are also
2853confident that no other thread can become current), then you can use
2854software watchpoints as usual. However, @value{GDBN} may not notice
2855when a non-current thread's activity changes the expression. (Hardware
2856watchpoints, in contrast, watch an expression in all threads.)
c906108c 2857@end quotation
c906108c 2858
501eef12
AC
2859@xref{set remote hardware-watchpoint-limit}.
2860
6d2ebf8b 2861@node Set Catchpoints
c906108c 2862@subsection Setting catchpoints
d4f3574e 2863@cindex catchpoints, setting
c906108c
SS
2864@cindex exception handlers
2865@cindex event handling
2866
2867You can use @dfn{catchpoints} to cause the debugger to stop for certain
b37052ae 2868kinds of program events, such as C@t{++} exceptions or the loading of a
c906108c
SS
2869shared library. Use the @code{catch} command to set a catchpoint.
2870
2871@table @code
2872@kindex catch
2873@item catch @var{event}
2874Stop when @var{event} occurs. @var{event} can be any of the following:
2875@table @code
2876@item throw
4644b6e3 2877@cindex stop on C@t{++} exceptions
b37052ae 2878The throwing of a C@t{++} exception.
c906108c
SS
2879
2880@item catch
b37052ae 2881The catching of a C@t{++} exception.
c906108c
SS
2882
2883@item exec
4644b6e3 2884@cindex break on fork/exec
c906108c
SS
2885A call to @code{exec}. This is currently only available for HP-UX.
2886
2887@item fork
c906108c
SS
2888A call to @code{fork}. This is currently only available for HP-UX.
2889
2890@item vfork
c906108c
SS
2891A call to @code{vfork}. This is currently only available for HP-UX.
2892
2893@item load
2894@itemx load @var{libname}
4644b6e3 2895@cindex break on load/unload of shared library
c906108c
SS
2896The dynamic loading of any shared library, or the loading of the library
2897@var{libname}. This is currently only available for HP-UX.
2898
2899@item unload
2900@itemx unload @var{libname}
c906108c
SS
2901The unloading of any dynamically loaded shared library, or the unloading
2902of the library @var{libname}. This is currently only available for HP-UX.
2903@end table
2904
2905@item tcatch @var{event}
2906Set a catchpoint that is enabled only for one stop. The catchpoint is
2907automatically deleted after the first time the event is caught.
2908
2909@end table
2910
2911Use the @code{info break} command to list the current catchpoints.
2912
b37052ae 2913There are currently some limitations to C@t{++} exception handling
c906108c
SS
2914(@code{catch throw} and @code{catch catch}) in @value{GDBN}:
2915
2916@itemize @bullet
2917@item
2918If you call a function interactively, @value{GDBN} normally returns
2919control to you when the function has finished executing. If the call
2920raises an exception, however, the call may bypass the mechanism that
2921returns control to you and cause your program either to abort or to
2922simply continue running until it hits a breakpoint, catches a signal
2923that @value{GDBN} is listening for, or exits. This is the case even if
2924you set a catchpoint for the exception; catchpoints on exceptions are
2925disabled within interactive calls.
2926
2927@item
2928You cannot raise an exception interactively.
2929
2930@item
2931You cannot install an exception handler interactively.
2932@end itemize
2933
2934@cindex raise exceptions
2935Sometimes @code{catch} is not the best way to debug exception handling:
2936if you need to know exactly where an exception is raised, it is better to
2937stop @emph{before} the exception handler is called, since that way you
2938can see the stack before any unwinding takes place. If you set a
2939breakpoint in an exception handler instead, it may not be easy to find
2940out where the exception was raised.
2941
2942To stop just before an exception handler is called, you need some
b37052ae 2943knowledge of the implementation. In the case of @sc{gnu} C@t{++}, exceptions are
c906108c
SS
2944raised by calling a library function named @code{__raise_exception}
2945which has the following ANSI C interface:
2946
474c8240 2947@smallexample
c906108c 2948 /* @var{addr} is where the exception identifier is stored.
d4f3574e
SS
2949 @var{id} is the exception identifier. */
2950 void __raise_exception (void **addr, void *id);
474c8240 2951@end smallexample
c906108c
SS
2952
2953@noindent
2954To make the debugger catch all exceptions before any stack
2955unwinding takes place, set a breakpoint on @code{__raise_exception}
2956(@pxref{Breakpoints, ,Breakpoints; watchpoints; and exceptions}).
2957
2958With a conditional breakpoint (@pxref{Conditions, ,Break conditions})
2959that depends on the value of @var{id}, you can stop your program when
2960a specific exception is raised. You can use multiple conditional
2961breakpoints to stop your program when any of a number of exceptions are
2962raised.
2963
2964
6d2ebf8b 2965@node Delete Breaks
c906108c
SS
2966@subsection Deleting breakpoints
2967
2968@cindex clearing breakpoints, watchpoints, catchpoints
2969@cindex deleting breakpoints, watchpoints, catchpoints
2970It is often necessary to eliminate a breakpoint, watchpoint, or
2971catchpoint once it has done its job and you no longer want your program
2972to stop there. This is called @dfn{deleting} the breakpoint. A
2973breakpoint that has been deleted no longer exists; it is forgotten.
2974
2975With the @code{clear} command you can delete breakpoints according to
2976where they are in your program. With the @code{delete} command you can
2977delete individual breakpoints, watchpoints, or catchpoints by specifying
2978their breakpoint numbers.
2979
2980It is not necessary to delete a breakpoint to proceed past it. @value{GDBN}
2981automatically ignores breakpoints on the first instruction to be executed
2982when you continue execution without changing the execution address.
2983
2984@table @code
2985@kindex clear
2986@item clear
2987Delete any breakpoints at the next instruction to be executed in the
2988selected stack frame (@pxref{Selection, ,Selecting a frame}). When
2989the innermost frame is selected, this is a good way to delete a
2990breakpoint where your program just stopped.
2991
2992@item clear @var{function}
2993@itemx clear @var{filename}:@var{function}
2994Delete any breakpoints set at entry to the function @var{function}.
2995
2996@item clear @var{linenum}
2997@itemx clear @var{filename}:@var{linenum}
2998Delete any breakpoints set at or within the code of the specified line.
2999
3000@cindex delete breakpoints
3001@kindex delete
41afff9a 3002@kindex d @r{(@code{delete})}
c5394b80
JM
3003@item delete @r{[}breakpoints@r{]} @r{[}@var{range}@dots{}@r{]}
3004Delete the breakpoints, watchpoints, or catchpoints of the breakpoint
3005ranges specified as arguments. If no argument is specified, delete all
c906108c
SS
3006breakpoints (@value{GDBN} asks confirmation, unless you have @code{set
3007confirm off}). You can abbreviate this command as @code{d}.
3008@end table
3009
6d2ebf8b 3010@node Disabling
c906108c
SS
3011@subsection Disabling breakpoints
3012
4644b6e3 3013@cindex enable/disable a breakpoint
c906108c
SS
3014Rather than deleting a breakpoint, watchpoint, or catchpoint, you might
3015prefer to @dfn{disable} it. This makes the breakpoint inoperative as if
3016it had been deleted, but remembers the information on the breakpoint so
3017that you can @dfn{enable} it again later.
3018
3019You disable and enable breakpoints, watchpoints, and catchpoints with
3020the @code{enable} and @code{disable} commands, optionally specifying one
3021or more breakpoint numbers as arguments. Use @code{info break} or
3022@code{info watch} to print a list of breakpoints, watchpoints, and
3023catchpoints if you do not know which numbers to use.
3024
3025A breakpoint, watchpoint, or catchpoint can have any of four different
3026states of enablement:
3027
3028@itemize @bullet
3029@item
3030Enabled. The breakpoint stops your program. A breakpoint set
3031with the @code{break} command starts out in this state.
3032@item
3033Disabled. The breakpoint has no effect on your program.
3034@item
3035Enabled once. The breakpoint stops your program, but then becomes
d4f3574e 3036disabled.
c906108c
SS
3037@item
3038Enabled for deletion. The breakpoint stops your program, but
d4f3574e
SS
3039immediately after it does so it is deleted permanently. A breakpoint
3040set with the @code{tbreak} command starts out in this state.
c906108c
SS
3041@end itemize
3042
3043You can use the following commands to enable or disable breakpoints,
3044watchpoints, and catchpoints:
3045
3046@table @code
c906108c 3047@kindex disable
41afff9a 3048@kindex dis @r{(@code{disable})}
c5394b80 3049@item disable @r{[}breakpoints@r{]} @r{[}@var{range}@dots{}@r{]}
c906108c
SS
3050Disable the specified breakpoints---or all breakpoints, if none are
3051listed. A disabled breakpoint has no effect but is not forgotten. All
3052options such as ignore-counts, conditions and commands are remembered in
3053case the breakpoint is enabled again later. You may abbreviate
3054@code{disable} as @code{dis}.
3055
c906108c 3056@kindex enable
c5394b80 3057@item enable @r{[}breakpoints@r{]} @r{[}@var{range}@dots{}@r{]}
c906108c
SS
3058Enable the specified breakpoints (or all defined breakpoints). They
3059become effective once again in stopping your program.
3060
c5394b80 3061@item enable @r{[}breakpoints@r{]} once @var{range}@dots{}
c906108c
SS
3062Enable the specified breakpoints temporarily. @value{GDBN} disables any
3063of these breakpoints immediately after stopping your program.
3064
c5394b80 3065@item enable @r{[}breakpoints@r{]} delete @var{range}@dots{}
c906108c
SS
3066Enable the specified breakpoints to work once, then die. @value{GDBN}
3067deletes any of these breakpoints as soon as your program stops there.
3068@end table
3069
d4f3574e
SS
3070@c FIXME: I think the following ``Except for [...] @code{tbreak}'' is
3071@c confusing: tbreak is also initially enabled.
c906108c
SS
3072Except for a breakpoint set with @code{tbreak} (@pxref{Set Breaks,
3073,Setting breakpoints}), breakpoints that you set are initially enabled;
3074subsequently, they become disabled or enabled only when you use one of
3075the commands above. (The command @code{until} can set and delete a
3076breakpoint of its own, but it does not change the state of your other
3077breakpoints; see @ref{Continuing and Stepping, ,Continuing and
3078stepping}.)
3079
6d2ebf8b 3080@node Conditions
c906108c
SS
3081@subsection Break conditions
3082@cindex conditional breakpoints
3083@cindex breakpoint conditions
3084
3085@c FIXME what is scope of break condition expr? Context where wanted?
5d161b24 3086@c in particular for a watchpoint?
c906108c
SS
3087The simplest sort of breakpoint breaks every time your program reaches a
3088specified place. You can also specify a @dfn{condition} for a
3089breakpoint. A condition is just a Boolean expression in your
3090programming language (@pxref{Expressions, ,Expressions}). A breakpoint with
3091a condition evaluates the expression each time your program reaches it,
3092and your program stops only if the condition is @emph{true}.
3093
3094This is the converse of using assertions for program validation; in that
3095situation, you want to stop when the assertion is violated---that is,
3096when the condition is false. In C, if you want to test an assertion expressed
3097by the condition @var{assert}, you should set the condition
3098@samp{! @var{assert}} on the appropriate breakpoint.
3099
3100Conditions are also accepted for watchpoints; you may not need them,
3101since a watchpoint is inspecting the value of an expression anyhow---but
3102it might be simpler, say, to just set a watchpoint on a variable name,
3103and specify a condition that tests whether the new value is an interesting
3104one.
3105
3106Break conditions can have side effects, and may even call functions in
3107your program. This can be useful, for example, to activate functions
3108that log program progress, or to use your own print functions to
3109format special data structures. The effects are completely predictable
3110unless there is another enabled breakpoint at the same address. (In
3111that case, @value{GDBN} might see the other breakpoint first and stop your
3112program without checking the condition of this one.) Note that
d4f3574e
SS
3113breakpoint commands are usually more convenient and flexible than break
3114conditions for the
c906108c
SS
3115purpose of performing side effects when a breakpoint is reached
3116(@pxref{Break Commands, ,Breakpoint command lists}).
3117
3118Break conditions can be specified when a breakpoint is set, by using
3119@samp{if} in the arguments to the @code{break} command. @xref{Set
3120Breaks, ,Setting breakpoints}. They can also be changed at any time
3121with the @code{condition} command.
53a5351d 3122
c906108c
SS
3123You can also use the @code{if} keyword with the @code{watch} command.
3124The @code{catch} command does not recognize the @code{if} keyword;
3125@code{condition} is the only way to impose a further condition on a
3126catchpoint.
c906108c
SS
3127
3128@table @code
3129@kindex condition
3130@item condition @var{bnum} @var{expression}
3131Specify @var{expression} as the break condition for breakpoint,
3132watchpoint, or catchpoint number @var{bnum}. After you set a condition,
3133breakpoint @var{bnum} stops your program only if the value of
3134@var{expression} is true (nonzero, in C). When you use
3135@code{condition}, @value{GDBN} checks @var{expression} immediately for
3136syntactic correctness, and to determine whether symbols in it have
d4f3574e
SS
3137referents in the context of your breakpoint. If @var{expression} uses
3138symbols not referenced in the context of the breakpoint, @value{GDBN}
3139prints an error message:
3140
474c8240 3141@smallexample
d4f3574e 3142No symbol "foo" in current context.
474c8240 3143@end smallexample
d4f3574e
SS
3144
3145@noindent
c906108c
SS
3146@value{GDBN} does
3147not actually evaluate @var{expression} at the time the @code{condition}
d4f3574e
SS
3148command (or a command that sets a breakpoint with a condition, like
3149@code{break if @dots{}}) is given, however. @xref{Expressions, ,Expressions}.
c906108c
SS
3150
3151@item condition @var{bnum}
3152Remove the condition from breakpoint number @var{bnum}. It becomes
3153an ordinary unconditional breakpoint.
3154@end table
3155
3156@cindex ignore count (of breakpoint)
3157A special case of a breakpoint condition is to stop only when the
3158breakpoint has been reached a certain number of times. This is so
3159useful that there is a special way to do it, using the @dfn{ignore
3160count} of the breakpoint. Every breakpoint has an ignore count, which
3161is an integer. Most of the time, the ignore count is zero, and
3162therefore has no effect. But if your program reaches a breakpoint whose
3163ignore count is positive, then instead of stopping, it just decrements
3164the ignore count by one and continues. As a result, if the ignore count
3165value is @var{n}, the breakpoint does not stop the next @var{n} times
3166your program reaches it.
3167
3168@table @code
3169@kindex ignore
3170@item ignore @var{bnum} @var{count}
3171Set the ignore count of breakpoint number @var{bnum} to @var{count}.
3172The next @var{count} times the breakpoint is reached, your program's
3173execution does not stop; other than to decrement the ignore count, @value{GDBN}
3174takes no action.
3175
3176To make the breakpoint stop the next time it is reached, specify
3177a count of zero.
3178
3179When you use @code{continue} to resume execution of your program from a
3180breakpoint, you can specify an ignore count directly as an argument to
3181@code{continue}, rather than using @code{ignore}. @xref{Continuing and
3182Stepping,,Continuing and stepping}.
3183
3184If a breakpoint has a positive ignore count and a condition, the
3185condition is not checked. Once the ignore count reaches zero,
3186@value{GDBN} resumes checking the condition.
3187
3188You could achieve the effect of the ignore count with a condition such
3189as @w{@samp{$foo-- <= 0}} using a debugger convenience variable that
3190is decremented each time. @xref{Convenience Vars, ,Convenience
3191variables}.
3192@end table
3193
3194Ignore counts apply to breakpoints, watchpoints, and catchpoints.
3195
3196
6d2ebf8b 3197@node Break Commands
c906108c
SS
3198@subsection Breakpoint command lists
3199
3200@cindex breakpoint commands
3201You can give any breakpoint (or watchpoint or catchpoint) a series of
3202commands to execute when your program stops due to that breakpoint. For
3203example, you might want to print the values of certain expressions, or
3204enable other breakpoints.
3205
3206@table @code
3207@kindex commands
3208@kindex end
3209@item commands @r{[}@var{bnum}@r{]}
3210@itemx @dots{} @var{command-list} @dots{}
3211@itemx end
3212Specify a list of commands for breakpoint number @var{bnum}. The commands
3213themselves appear on the following lines. Type a line containing just
3214@code{end} to terminate the commands.
3215
3216To remove all commands from a breakpoint, type @code{commands} and
3217follow it immediately with @code{end}; that is, give no commands.
3218
3219With no @var{bnum} argument, @code{commands} refers to the last
3220breakpoint, watchpoint, or catchpoint set (not to the breakpoint most
3221recently encountered).
3222@end table
3223
3224Pressing @key{RET} as a means of repeating the last @value{GDBN} command is
3225disabled within a @var{command-list}.
3226
3227You can use breakpoint commands to start your program up again. Simply
3228use the @code{continue} command, or @code{step}, or any other command
3229that resumes execution.
3230
3231Any other commands in the command list, after a command that resumes
3232execution, are ignored. This is because any time you resume execution
3233(even with a simple @code{next} or @code{step}), you may encounter
3234another breakpoint---which could have its own command list, leading to
3235ambiguities about which list to execute.
3236
3237@kindex silent
3238If the first command you specify in a command list is @code{silent}, the
3239usual message about stopping at a breakpoint is not printed. This may
3240be desirable for breakpoints that are to print a specific message and
3241then continue. If none of the remaining commands print anything, you
3242see no sign that the breakpoint was reached. @code{silent} is
3243meaningful only at the beginning of a breakpoint command list.
3244
3245The commands @code{echo}, @code{output}, and @code{printf} allow you to
3246print precisely controlled output, and are often useful in silent
3247breakpoints. @xref{Output, ,Commands for controlled output}.
3248
3249For example, here is how you could use breakpoint commands to print the
3250value of @code{x} at entry to @code{foo} whenever @code{x} is positive.
3251
474c8240 3252@smallexample
c906108c
SS
3253break foo if x>0
3254commands
3255silent
3256printf "x is %d\n",x
3257cont
3258end
474c8240 3259@end smallexample
c906108c
SS
3260
3261One application for breakpoint commands is to compensate for one bug so
3262you can test for another. Put a breakpoint just after the erroneous line
3263of code, give it a condition to detect the case in which something
3264erroneous has been done, and give it commands to assign correct values
3265to any variables that need them. End with the @code{continue} command
3266so that your program does not stop, and start with the @code{silent}
3267command so that no output is produced. Here is an example:
3268
474c8240 3269@smallexample
c906108c
SS
3270break 403
3271commands
3272silent
3273set x = y + 4
3274cont
3275end
474c8240 3276@end smallexample
c906108c 3277
6d2ebf8b 3278@node Breakpoint Menus
c906108c
SS
3279@subsection Breakpoint menus
3280@cindex overloading
3281@cindex symbol overloading
3282
b383017d 3283Some programming languages (notably C@t{++} and Objective-C) permit a
b37303ee 3284single function name
c906108c
SS
3285to be defined several times, for application in different contexts.
3286This is called @dfn{overloading}. When a function name is overloaded,
3287@samp{break @var{function}} is not enough to tell @value{GDBN} where you want
3288a breakpoint. If you realize this is a problem, you can use
3289something like @samp{break @var{function}(@var{types})} to specify which
3290particular version of the function you want. Otherwise, @value{GDBN} offers
3291you a menu of numbered choices for different possible breakpoints, and
3292waits for your selection with the prompt @samp{>}. The first two
3293options are always @samp{[0] cancel} and @samp{[1] all}. Typing @kbd{1}
3294sets a breakpoint at each definition of @var{function}, and typing
3295@kbd{0} aborts the @code{break} command without setting any new
3296breakpoints.
3297
3298For example, the following session excerpt shows an attempt to set a
3299breakpoint at the overloaded symbol @code{String::after}.
3300We choose three particular definitions of that function name:
3301
3302@c FIXME! This is likely to change to show arg type lists, at least
3303@smallexample
3304@group
3305(@value{GDBP}) b String::after
3306[0] cancel
3307[1] all
3308[2] file:String.cc; line number:867
3309[3] file:String.cc; line number:860
3310[4] file:String.cc; line number:875
3311[5] file:String.cc; line number:853
3312[6] file:String.cc; line number:846
3313[7] file:String.cc; line number:735
3314> 2 4 6
3315Breakpoint 1 at 0xb26c: file String.cc, line 867.
3316Breakpoint 2 at 0xb344: file String.cc, line 875.
3317Breakpoint 3 at 0xafcc: file String.cc, line 846.
3318Multiple breakpoints were set.
3319Use the "delete" command to delete unwanted
3320 breakpoints.
3321(@value{GDBP})
3322@end group
3323@end smallexample
c906108c
SS
3324
3325@c @ifclear BARETARGET
6d2ebf8b 3326@node Error in Breakpoints
d4f3574e 3327@subsection ``Cannot insert breakpoints''
c906108c
SS
3328@c
3329@c FIXME!! 14/6/95 Is there a real example of this? Let's use it.
3330@c
d4f3574e
SS
3331Under some operating systems, breakpoints cannot be used in a program if
3332any other process is running that program. In this situation,
5d161b24 3333attempting to run or continue a program with a breakpoint causes
d4f3574e
SS
3334@value{GDBN} to print an error message:
3335
474c8240 3336@smallexample
d4f3574e
SS
3337Cannot insert breakpoints.
3338The same program may be running in another process.
474c8240 3339@end smallexample
d4f3574e
SS
3340
3341When this happens, you have three ways to proceed:
3342
3343@enumerate
3344@item
3345Remove or disable the breakpoints, then continue.
3346
3347@item
5d161b24 3348Suspend @value{GDBN}, and copy the file containing your program to a new
d4f3574e 3349name. Resume @value{GDBN} and use the @code{exec-file} command to specify
5d161b24 3350that @value{GDBN} should run your program under that name.
d4f3574e
SS
3351Then start your program again.
3352
3353@item
3354Relink your program so that the text segment is nonsharable, using the
3355linker option @samp{-N}. The operating system limitation may not apply
3356to nonsharable executables.
3357@end enumerate
c906108c
SS
3358@c @end ifclear
3359
d4f3574e
SS
3360A similar message can be printed if you request too many active
3361hardware-assisted breakpoints and watchpoints:
3362
3363@c FIXME: the precise wording of this message may change; the relevant
3364@c source change is not committed yet (Sep 3, 1999).
3365@smallexample
3366Stopped; cannot insert breakpoints.
3367You may have requested too many hardware breakpoints and watchpoints.
3368@end smallexample
3369
3370@noindent
3371This message is printed when you attempt to resume the program, since
3372only then @value{GDBN} knows exactly how many hardware breakpoints and
3373watchpoints it needs to insert.
3374
3375When this message is printed, you need to disable or remove some of the
3376hardware-assisted breakpoints and watchpoints, and then continue.
3377
1485d690
KB
3378@node Breakpoint related warnings
3379@subsection ``Breakpoint address adjusted...''
3380@cindex breakpoint address adjusted
3381
3382Some processor architectures place constraints on the addresses at
3383which breakpoints may be placed. For architectures thus constrained,
3384@value{GDBN} will attempt to adjust the breakpoint's address to comply
3385with the constraints dictated by the architecture.
3386
3387One example of such an architecture is the Fujitsu FR-V. The FR-V is
3388a VLIW architecture in which a number of RISC-like instructions may be
3389bundled together for parallel execution. The FR-V architecture
3390constrains the location of a breakpoint instruction within such a
3391bundle to the instruction with the lowest address. @value{GDBN}
3392honors this constraint by adjusting a breakpoint's address to the
3393first in the bundle.
3394
3395It is not uncommon for optimized code to have bundles which contain
3396instructions from different source statements, thus it may happen that
3397a breakpoint's address will be adjusted from one source statement to
3398another. Since this adjustment may significantly alter @value{GDBN}'s
3399breakpoint related behavior from what the user expects, a warning is
3400printed when the breakpoint is first set and also when the breakpoint
3401is hit.
3402
3403A warning like the one below is printed when setting a breakpoint
3404that's been subject to address adjustment:
3405
3406@smallexample
3407warning: Breakpoint address adjusted from 0x00010414 to 0x00010410.
3408@end smallexample
3409
3410Such warnings are printed both for user settable and @value{GDBN}'s
3411internal breakpoints. If you see one of these warnings, you should
3412verify that a breakpoint set at the adjusted address will have the
3413desired affect. If not, the breakpoint in question may be removed and
b383017d 3414other breakpoints may be set which will have the desired behavior.
1485d690
KB
3415E.g., it may be sufficient to place the breakpoint at a later
3416instruction. A conditional breakpoint may also be useful in some
3417cases to prevent the breakpoint from triggering too often.
3418
3419@value{GDBN} will also issue a warning when stopping at one of these
3420adjusted breakpoints:
3421
3422@smallexample
3423warning: Breakpoint 1 address previously adjusted from 0x00010414
3424to 0x00010410.
3425@end smallexample
3426
3427When this warning is encountered, it may be too late to take remedial
3428action except in cases where the breakpoint is hit earlier or more
3429frequently than expected.
d4f3574e 3430
6d2ebf8b 3431@node Continuing and Stepping
c906108c
SS
3432@section Continuing and stepping
3433
3434@cindex stepping
3435@cindex continuing
3436@cindex resuming execution
3437@dfn{Continuing} means resuming program execution until your program
3438completes normally. In contrast, @dfn{stepping} means executing just
3439one more ``step'' of your program, where ``step'' may mean either one
3440line of source code, or one machine instruction (depending on what
7a292a7a
SS
3441particular command you use). Either when continuing or when stepping,
3442your program may stop even sooner, due to a breakpoint or a signal. (If
d4f3574e
SS
3443it stops due to a signal, you may want to use @code{handle}, or use
3444@samp{signal 0} to resume execution. @xref{Signals, ,Signals}.)
c906108c
SS
3445
3446@table @code
3447@kindex continue
41afff9a
EZ
3448@kindex c @r{(@code{continue})}
3449@kindex fg @r{(resume foreground execution)}
c906108c
SS
3450@item continue @r{[}@var{ignore-count}@r{]}
3451@itemx c @r{[}@var{ignore-count}@r{]}
3452@itemx fg @r{[}@var{ignore-count}@r{]}
3453Resume program execution, at the address where your program last stopped;
3454any breakpoints set at that address are bypassed. The optional argument
3455@var{ignore-count} allows you to specify a further number of times to
3456ignore a breakpoint at this location; its effect is like that of
3457@code{ignore} (@pxref{Conditions, ,Break conditions}).
3458
3459The argument @var{ignore-count} is meaningful only when your program
3460stopped due to a breakpoint. At other times, the argument to
3461@code{continue} is ignored.
3462
d4f3574e
SS
3463The synonyms @code{c} and @code{fg} (for @dfn{foreground}, as the
3464debugged program is deemed to be the foreground program) are provided
3465purely for convenience, and have exactly the same behavior as
3466@code{continue}.
c906108c
SS
3467@end table
3468
3469To resume execution at a different place, you can use @code{return}
3470(@pxref{Returning, ,Returning from a function}) to go back to the
3471calling function; or @code{jump} (@pxref{Jumping, ,Continuing at a
3472different address}) to go to an arbitrary location in your program.
3473
3474A typical technique for using stepping is to set a breakpoint
3475(@pxref{Breakpoints, ,Breakpoints; watchpoints; and catchpoints}) at the
3476beginning of the function or the section of your program where a problem
3477is believed to lie, run your program until it stops at that breakpoint,
3478and then step through the suspect area, examining the variables that are
3479interesting, until you see the problem happen.
3480
3481@table @code
3482@kindex step
41afff9a 3483@kindex s @r{(@code{step})}
c906108c
SS
3484@item step
3485Continue running your program until control reaches a different source
3486line, then stop it and return control to @value{GDBN}. This command is
3487abbreviated @code{s}.
3488
3489@quotation
3490@c "without debugging information" is imprecise; actually "without line
3491@c numbers in the debugging information". (gcc -g1 has debugging info but
3492@c not line numbers). But it seems complex to try to make that
3493@c distinction here.
3494@emph{Warning:} If you use the @code{step} command while control is
3495within a function that was compiled without debugging information,
3496execution proceeds until control reaches a function that does have
3497debugging information. Likewise, it will not step into a function which
3498is compiled without debugging information. To step through functions
3499without debugging information, use the @code{stepi} command, described
3500below.
3501@end quotation
3502
4a92d011
EZ
3503The @code{step} command only stops at the first instruction of a source
3504line. This prevents the multiple stops that could otherwise occur in
3505@code{switch} statements, @code{for} loops, etc. @code{step} continues
3506to stop if a function that has debugging information is called within
3507the line. In other words, @code{step} @emph{steps inside} any functions
3508called within the line.
c906108c 3509
d4f3574e
SS
3510Also, the @code{step} command only enters a function if there is line
3511number information for the function. Otherwise it acts like the
5d161b24 3512@code{next} command. This avoids problems when using @code{cc -gl}
c906108c 3513on MIPS machines. Previously, @code{step} entered subroutines if there
5d161b24 3514was any debugging information about the routine.
c906108c
SS
3515
3516@item step @var{count}
3517Continue running as in @code{step}, but do so @var{count} times. If a
7a292a7a
SS
3518breakpoint is reached, or a signal not related to stepping occurs before
3519@var{count} steps, stepping stops right away.
c906108c
SS
3520
3521@kindex next
41afff9a 3522@kindex n @r{(@code{next})}
c906108c
SS
3523@item next @r{[}@var{count}@r{]}
3524Continue to the next source line in the current (innermost) stack frame.
7a292a7a
SS
3525This is similar to @code{step}, but function calls that appear within
3526the line of code are executed without stopping. Execution stops when
3527control reaches a different line of code at the original stack level
3528that was executing when you gave the @code{next} command. This command
3529is abbreviated @code{n}.
c906108c
SS
3530
3531An argument @var{count} is a repeat count, as for @code{step}.
3532
3533
3534@c FIX ME!! Do we delete this, or is there a way it fits in with
3535@c the following paragraph? --- Vctoria
3536@c
3537@c @code{next} within a function that lacks debugging information acts like
3538@c @code{step}, but any function calls appearing within the code of the
3539@c function are executed without stopping.
3540
d4f3574e
SS
3541The @code{next} command only stops at the first instruction of a
3542source line. This prevents multiple stops that could otherwise occur in
4a92d011 3543@code{switch} statements, @code{for} loops, etc.
c906108c 3544
b90a5f51
CF
3545@kindex set step-mode
3546@item set step-mode
3547@cindex functions without line info, and stepping
3548@cindex stepping into functions with no line info
3549@itemx set step-mode on
4a92d011 3550The @code{set step-mode on} command causes the @code{step} command to
b90a5f51
CF
3551stop at the first instruction of a function which contains no debug line
3552information rather than stepping over it.
3553
4a92d011
EZ
3554This is useful in cases where you may be interested in inspecting the
3555machine instructions of a function which has no symbolic info and do not
3556want @value{GDBN} to automatically skip over this function.
b90a5f51
CF
3557
3558@item set step-mode off
4a92d011 3559Causes the @code{step} command to step over any functions which contains no
b90a5f51
CF
3560debug information. This is the default.
3561
c906108c
SS
3562@kindex finish
3563@item finish
3564Continue running until just after function in the selected stack frame
3565returns. Print the returned value (if any).
3566
3567Contrast this with the @code{return} command (@pxref{Returning,
3568,Returning from a function}).
3569
3570@kindex until
41afff9a 3571@kindex u @r{(@code{until})}
c906108c
SS
3572@item until
3573@itemx u
3574Continue running until a source line past the current line, in the
3575current stack frame, is reached. This command is used to avoid single
3576stepping through a loop more than once. It is like the @code{next}
3577command, except that when @code{until} encounters a jump, it
3578automatically continues execution until the program counter is greater
3579than the address of the jump.
3580
3581This means that when you reach the end of a loop after single stepping
3582though it, @code{until} makes your program continue execution until it
3583exits the loop. In contrast, a @code{next} command at the end of a loop
3584simply steps back to the beginning of the loop, which forces you to step
3585through the next iteration.
3586
3587@code{until} always stops your program if it attempts to exit the current
3588stack frame.
3589
3590@code{until} may produce somewhat counterintuitive results if the order
3591of machine code does not match the order of the source lines. For
3592example, in the following excerpt from a debugging session, the @code{f}
3593(@code{frame}) command shows that execution is stopped at line
3594@code{206}; yet when we use @code{until}, we get to line @code{195}:
3595
474c8240 3596@smallexample
c906108c
SS
3597(@value{GDBP}) f
3598#0 main (argc=4, argv=0xf7fffae8) at m4.c:206
3599206 expand_input();
3600(@value{GDBP}) until
3601195 for ( ; argc > 0; NEXTARG) @{
474c8240 3602@end smallexample
c906108c
SS
3603
3604This happened because, for execution efficiency, the compiler had
3605generated code for the loop closure test at the end, rather than the
3606start, of the loop---even though the test in a C @code{for}-loop is
3607written before the body of the loop. The @code{until} command appeared
3608to step back to the beginning of the loop when it advanced to this
3609expression; however, it has not really gone to an earlier
3610statement---not in terms of the actual machine code.
3611
3612@code{until} with no argument works by means of single
3613instruction stepping, and hence is slower than @code{until} with an
3614argument.
3615
3616@item until @var{location}
3617@itemx u @var{location}
3618Continue running your program until either the specified location is
3619reached, or the current stack frame returns. @var{location} is any of
3620the forms of argument acceptable to @code{break} (@pxref{Set Breaks,
c60eb6f1
EZ
3621,Setting breakpoints}). This form of the command uses breakpoints, and
3622hence is quicker than @code{until} without an argument. The specified
3623location is actually reached only if it is in the current frame. This
3624implies that @code{until} can be used to skip over recursive function
3625invocations. For instance in the code below, if the current location is
3626line @code{96}, issuing @code{until 99} will execute the program up to
3627line @code{99} in the same invocation of factorial, i.e. after the inner
3628invocations have returned.
3629
3630@smallexample
363194 int factorial (int value)
363295 @{
363396 if (value > 1) @{
363497 value *= factorial (value - 1);
363598 @}
363699 return (value);
3637100 @}
3638@end smallexample
3639
3640
3641@kindex advance @var{location}
3642@itemx advance @var{location}
3643Continue running the program up to the given location. An argument is
3644required, anything of the same form as arguments for the @code{break}
3645command. Execution will also stop upon exit from the current stack
3646frame. This command is similar to @code{until}, but @code{advance} will
3647not skip over recursive function calls, and the target location doesn't
3648have to be in the same frame as the current one.
3649
c906108c
SS
3650
3651@kindex stepi
41afff9a 3652@kindex si @r{(@code{stepi})}
c906108c 3653@item stepi
96a2c332 3654@itemx stepi @var{arg}
c906108c
SS
3655@itemx si
3656Execute one machine instruction, then stop and return to the debugger.
3657
3658It is often useful to do @samp{display/i $pc} when stepping by machine
3659instructions. This makes @value{GDBN} automatically display the next
3660instruction to be executed, each time your program stops. @xref{Auto
3661Display,, Automatic display}.
3662
3663An argument is a repeat count, as in @code{step}.
3664
3665@need 750
3666@kindex nexti
41afff9a 3667@kindex ni @r{(@code{nexti})}
c906108c 3668@item nexti
96a2c332 3669@itemx nexti @var{arg}
c906108c
SS
3670@itemx ni
3671Execute one machine instruction, but if it is a function call,
3672proceed until the function returns.
3673
3674An argument is a repeat count, as in @code{next}.
3675@end table
3676
6d2ebf8b 3677@node Signals
c906108c
SS
3678@section Signals
3679@cindex signals
3680
3681A signal is an asynchronous event that can happen in a program. The
3682operating system defines the possible kinds of signals, and gives each
3683kind a name and a number. For example, in Unix @code{SIGINT} is the
d4f3574e 3684signal a program gets when you type an interrupt character (often @kbd{C-c});
c906108c
SS
3685@code{SIGSEGV} is the signal a program gets from referencing a place in
3686memory far away from all the areas in use; @code{SIGALRM} occurs when
3687the alarm clock timer goes off (which happens only if your program has
3688requested an alarm).
3689
3690@cindex fatal signals
3691Some signals, including @code{SIGALRM}, are a normal part of the
3692functioning of your program. Others, such as @code{SIGSEGV}, indicate
d4f3574e 3693errors; these signals are @dfn{fatal} (they kill your program immediately) if the
c906108c
SS
3694program has not specified in advance some other way to handle the signal.
3695@code{SIGINT} does not indicate an error in your program, but it is normally
3696fatal so it can carry out the purpose of the interrupt: to kill the program.
3697
3698@value{GDBN} has the ability to detect any occurrence of a signal in your
3699program. You can tell @value{GDBN} in advance what to do for each kind of
3700signal.
3701
3702@cindex handling signals
24f93129
EZ
3703Normally, @value{GDBN} is set up to let the non-erroneous signals like
3704@code{SIGALRM} be silently passed to your program
3705(so as not to interfere with their role in the program's functioning)
c906108c
SS
3706but to stop your program immediately whenever an error signal happens.
3707You can change these settings with the @code{handle} command.
3708
3709@table @code
3710@kindex info signals
3711@item info signals
96a2c332 3712@itemx info handle
c906108c
SS
3713Print a table of all the kinds of signals and how @value{GDBN} has been told to
3714handle each one. You can use this to see the signal numbers of all
3715the defined types of signals.
3716
d4f3574e 3717@code{info handle} is an alias for @code{info signals}.
c906108c
SS
3718
3719@kindex handle
3720@item handle @var{signal} @var{keywords}@dots{}
5ece1a18
EZ
3721Change the way @value{GDBN} handles signal @var{signal}. @var{signal}
3722can be the number of a signal or its name (with or without the
24f93129 3723@samp{SIG} at the beginning); a list of signal numbers of the form
5ece1a18
EZ
3724@samp{@var{low}-@var{high}}; or the word @samp{all}, meaning all the
3725known signals. The @var{keywords} say what change to make.
c906108c
SS
3726@end table
3727
3728@c @group
3729The keywords allowed by the @code{handle} command can be abbreviated.
3730Their full names are:
3731
3732@table @code
3733@item nostop
3734@value{GDBN} should not stop your program when this signal happens. It may
3735still print a message telling you that the signal has come in.
3736
3737@item stop
3738@value{GDBN} should stop your program when this signal happens. This implies
3739the @code{print} keyword as well.
3740
3741@item print
3742@value{GDBN} should print a message when this signal happens.
3743
3744@item noprint
3745@value{GDBN} should not mention the occurrence of the signal at all. This
3746implies the @code{nostop} keyword as well.
3747
3748@item pass
5ece1a18 3749@itemx noignore
c906108c
SS
3750@value{GDBN} should allow your program to see this signal; your program
3751can handle the signal, or else it may terminate if the signal is fatal
5ece1a18 3752and not handled. @code{pass} and @code{noignore} are synonyms.
c906108c
SS
3753
3754@item nopass
5ece1a18 3755@itemx ignore
c906108c 3756@value{GDBN} should not allow your program to see this signal.
5ece1a18 3757@code{nopass} and @code{ignore} are synonyms.
c906108c
SS
3758@end table
3759@c @end group
3760
d4f3574e
SS
3761When a signal stops your program, the signal is not visible to the
3762program until you
c906108c
SS
3763continue. Your program sees the signal then, if @code{pass} is in
3764effect for the signal in question @emph{at that time}. In other words,
3765after @value{GDBN} reports a signal, you can use the @code{handle}
3766command with @code{pass} or @code{nopass} to control whether your
3767program sees that signal when you continue.
3768
24f93129
EZ
3769The default is set to @code{nostop}, @code{noprint}, @code{pass} for
3770non-erroneous signals such as @code{SIGALRM}, @code{SIGWINCH} and
3771@code{SIGCHLD}, and to @code{stop}, @code{print}, @code{pass} for the
3772erroneous signals.
3773
c906108c
SS
3774You can also use the @code{signal} command to prevent your program from
3775seeing a signal, or cause it to see a signal it normally would not see,
3776or to give it any signal at any time. For example, if your program stopped
3777due to some sort of memory reference error, you might store correct
3778values into the erroneous variables and continue, hoping to see more
3779execution; but your program would probably terminate immediately as
3780a result of the fatal signal once it saw the signal. To prevent this,
3781you can continue with @samp{signal 0}. @xref{Signaling, ,Giving your
5d161b24 3782program a signal}.
c906108c 3783
6d2ebf8b 3784@node Thread Stops
c906108c
SS
3785@section Stopping and starting multi-thread programs
3786
3787When your program has multiple threads (@pxref{Threads,, Debugging
3788programs with multiple threads}), you can choose whether to set
3789breakpoints on all threads, or on a particular thread.
3790
3791@table @code
3792@cindex breakpoints and threads
3793@cindex thread breakpoints
3794@kindex break @dots{} thread @var{threadno}
3795@item break @var{linespec} thread @var{threadno}
3796@itemx break @var{linespec} thread @var{threadno} if @dots{}
3797@var{linespec} specifies source lines; there are several ways of
3798writing them, but the effect is always to specify some source line.
3799
3800Use the qualifier @samp{thread @var{threadno}} with a breakpoint command
3801to specify that you only want @value{GDBN} to stop the program when a
3802particular thread reaches this breakpoint. @var{threadno} is one of the
3803numeric thread identifiers assigned by @value{GDBN}, shown in the first
3804column of the @samp{info threads} display.
3805
3806If you do not specify @samp{thread @var{threadno}} when you set a
3807breakpoint, the breakpoint applies to @emph{all} threads of your
3808program.
3809
3810You can use the @code{thread} qualifier on conditional breakpoints as
3811well; in this case, place @samp{thread @var{threadno}} before the
3812breakpoint condition, like this:
3813
3814@smallexample
2df3850c 3815(@value{GDBP}) break frik.c:13 thread 28 if bartab > lim
c906108c
SS
3816@end smallexample
3817
3818@end table
3819
3820@cindex stopped threads
3821@cindex threads, stopped
3822Whenever your program stops under @value{GDBN} for any reason,
3823@emph{all} threads of execution stop, not just the current thread. This
3824allows you to examine the overall state of the program, including
3825switching between threads, without worrying that things may change
3826underfoot.
3827
36d86913
MC
3828@cindex thread breakpoints and system calls
3829@cindex system calls and thread breakpoints
3830@cindex premature return from system calls
3831There is an unfortunate side effect. If one thread stops for a
3832breakpoint, or for some other reason, and another thread is blocked in a
3833system call, then the system call may return prematurely. This is a
3834consequence of the interaction between multiple threads and the signals
3835that @value{GDBN} uses to implement breakpoints and other events that
3836stop execution.
3837
3838To handle this problem, your program should check the return value of
3839each system call and react appropriately. This is good programming
3840style anyways.
3841
3842For example, do not write code like this:
3843
3844@smallexample
3845 sleep (10);
3846@end smallexample
3847
3848The call to @code{sleep} will return early if a different thread stops
3849at a breakpoint or for some other reason.
3850
3851Instead, write this:
3852
3853@smallexample
3854 int unslept = 10;
3855 while (unslept > 0)
3856 unslept = sleep (unslept);
3857@end smallexample
3858
3859A system call is allowed to return early, so the system is still
3860conforming to its specification. But @value{GDBN} does cause your
3861multi-threaded program to behave differently than it would without
3862@value{GDBN}.
3863
3864Also, @value{GDBN} uses internal breakpoints in the thread library to
3865monitor certain events such as thread creation and thread destruction.
3866When such an event happens, a system call in another thread may return
3867prematurely, even though your program does not appear to stop.
3868
c906108c
SS
3869@cindex continuing threads
3870@cindex threads, continuing
3871Conversely, whenever you restart the program, @emph{all} threads start
3872executing. @emph{This is true even when single-stepping} with commands
5d161b24 3873like @code{step} or @code{next}.
c906108c
SS
3874
3875In particular, @value{GDBN} cannot single-step all threads in lockstep.
3876Since thread scheduling is up to your debugging target's operating
3877system (not controlled by @value{GDBN}), other threads may
3878execute more than one statement while the current thread completes a
3879single step. Moreover, in general other threads stop in the middle of a
3880statement, rather than at a clean statement boundary, when the program
3881stops.
3882
3883You might even find your program stopped in another thread after
3884continuing or even single-stepping. This happens whenever some other
3885thread runs into a breakpoint, a signal, or an exception before the
3886first thread completes whatever you requested.
3887
3888On some OSes, you can lock the OS scheduler and thus allow only a single
3889thread to run.
3890
3891@table @code
3892@item set scheduler-locking @var{mode}
3893Set the scheduler locking mode. If it is @code{off}, then there is no
3894locking and any thread may run at any time. If @code{on}, then only the
3895current thread may run when the inferior is resumed. The @code{step}
3896mode optimizes for single-stepping. It stops other threads from
3897``seizing the prompt'' by preempting the current thread while you are
3898stepping. Other threads will only rarely (or never) get a chance to run
d4f3574e 3899when you step. They are more likely to run when you @samp{next} over a
c906108c 3900function call, and they are completely free to run when you use commands
d4f3574e 3901like @samp{continue}, @samp{until}, or @samp{finish}. However, unless another
c906108c 3902thread hits a breakpoint during its timeslice, they will never steal the
2df3850c 3903@value{GDBN} prompt away from the thread that you are debugging.
c906108c
SS
3904
3905@item show scheduler-locking
3906Display the current scheduler locking mode.
3907@end table
3908
c906108c 3909
6d2ebf8b 3910@node Stack
c906108c
SS
3911@chapter Examining the Stack
3912
3913When your program has stopped, the first thing you need to know is where it
3914stopped and how it got there.
3915
3916@cindex call stack
5d161b24
DB
3917Each time your program performs a function call, information about the call
3918is generated.
3919That information includes the location of the call in your program,
3920the arguments of the call,
c906108c 3921and the local variables of the function being called.
5d161b24 3922The information is saved in a block of data called a @dfn{stack frame}.
c906108c
SS
3923The stack frames are allocated in a region of memory called the @dfn{call
3924stack}.
3925
3926When your program stops, the @value{GDBN} commands for examining the
3927stack allow you to see all of this information.
3928
3929@cindex selected frame
3930One of the stack frames is @dfn{selected} by @value{GDBN} and many
3931@value{GDBN} commands refer implicitly to the selected frame. In
3932particular, whenever you ask @value{GDBN} for the value of a variable in
3933your program, the value is found in the selected frame. There are
3934special @value{GDBN} commands to select whichever frame you are
3935interested in. @xref{Selection, ,Selecting a frame}.
3936
3937When your program stops, @value{GDBN} automatically selects the
5d161b24 3938currently executing frame and describes it briefly, similar to the
c906108c
SS
3939@code{frame} command (@pxref{Frame Info, ,Information about a frame}).
3940
3941@menu
3942* Frames:: Stack frames
3943* Backtrace:: Backtraces
3944* Selection:: Selecting a frame
3945* Frame Info:: Information on a frame
c906108c
SS
3946
3947@end menu
3948
6d2ebf8b 3949@node Frames
c906108c
SS
3950@section Stack frames
3951
d4f3574e 3952@cindex frame, definition
c906108c
SS
3953@cindex stack frame
3954The call stack is divided up into contiguous pieces called @dfn{stack
3955frames}, or @dfn{frames} for short; each frame is the data associated
3956with one call to one function. The frame contains the arguments given
3957to the function, the function's local variables, and the address at
3958which the function is executing.
3959
3960@cindex initial frame
3961@cindex outermost frame
3962@cindex innermost frame
3963When your program is started, the stack has only one frame, that of the
3964function @code{main}. This is called the @dfn{initial} frame or the
3965@dfn{outermost} frame. Each time a function is called, a new frame is
3966made. Each time a function returns, the frame for that function invocation
3967is eliminated. If a function is recursive, there can be many frames for
3968the same function. The frame for the function in which execution is
3969actually occurring is called the @dfn{innermost} frame. This is the most
3970recently created of all the stack frames that still exist.
3971
3972@cindex frame pointer
3973Inside your program, stack frames are identified by their addresses. A
3974stack frame consists of many bytes, each of which has its own address; each
3975kind of computer has a convention for choosing one byte whose
3976address serves as the address of the frame. Usually this address is kept
3977in a register called the @dfn{frame pointer register} while execution is
3978going on in that frame.
3979
3980@cindex frame number
3981@value{GDBN} assigns numbers to all existing stack frames, starting with
3982zero for the innermost frame, one for the frame that called it,
3983and so on upward. These numbers do not really exist in your program;
3984they are assigned by @value{GDBN} to give you a way of designating stack
3985frames in @value{GDBN} commands.
3986
6d2ebf8b
SS
3987@c The -fomit-frame-pointer below perennially causes hbox overflow
3988@c underflow problems.
c906108c
SS
3989@cindex frameless execution
3990Some compilers provide a way to compile functions so that they operate
6d2ebf8b 3991without stack frames. (For example, the @value{GCC} option
474c8240 3992@smallexample
6d2ebf8b 3993@samp{-fomit-frame-pointer}
474c8240 3994@end smallexample
6d2ebf8b 3995generates functions without a frame.)
c906108c
SS
3996This is occasionally done with heavily used library functions to save
3997the frame setup time. @value{GDBN} has limited facilities for dealing
3998with these function invocations. If the innermost function invocation
3999has no stack frame, @value{GDBN} nevertheless regards it as though
4000it had a separate frame, which is numbered zero as usual, allowing
4001correct tracing of the function call chain. However, @value{GDBN} has
4002no provision for frameless functions elsewhere in the stack.
4003
4004@table @code
d4f3574e 4005@kindex frame@r{, command}
41afff9a 4006@cindex current stack frame
c906108c 4007@item frame @var{args}
5d161b24 4008The @code{frame} command allows you to move from one stack frame to another,
c906108c 4009and to print the stack frame you select. @var{args} may be either the
5d161b24
DB
4010address of the frame or the stack frame number. Without an argument,
4011@code{frame} prints the current stack frame.
c906108c
SS
4012
4013@kindex select-frame
41afff9a 4014@cindex selecting frame silently
c906108c
SS
4015@item select-frame
4016The @code{select-frame} command allows you to move from one stack frame
4017to another without printing the frame. This is the silent version of
4018@code{frame}.
4019@end table
4020
6d2ebf8b 4021@node Backtrace
c906108c
SS
4022@section Backtraces
4023
4024@cindex backtraces
4025@cindex tracebacks
4026@cindex stack traces
4027A backtrace is a summary of how your program got where it is. It shows one
4028line per frame, for many frames, starting with the currently executing
4029frame (frame zero), followed by its caller (frame one), and on up the
4030stack.
4031
4032@table @code
4033@kindex backtrace
41afff9a 4034@kindex bt @r{(@code{backtrace})}
c906108c
SS
4035@item backtrace
4036@itemx bt
4037Print a backtrace of the entire stack: one line per frame for all
4038frames in the stack.
4039
4040You can stop the backtrace at any time by typing the system interrupt
4041character, normally @kbd{C-c}.
4042
4043@item backtrace @var{n}
4044@itemx bt @var{n}
4045Similar, but print only the innermost @var{n} frames.
4046
4047@item backtrace -@var{n}
4048@itemx bt -@var{n}
4049Similar, but print only the outermost @var{n} frames.
4050@end table
4051
4052@kindex where
4053@kindex info stack
c906108c
SS
4054The names @code{where} and @code{info stack} (abbreviated @code{info s})
4055are additional aliases for @code{backtrace}.
4056
4057Each line in the backtrace shows the frame number and the function name.
4058The program counter value is also shown---unless you use @code{set
4059print address off}. The backtrace also shows the source file name and
4060line number, as well as the arguments to the function. The program
4061counter value is omitted if it is at the beginning of the code for that
4062line number.
4063
4064Here is an example of a backtrace. It was made with the command
4065@samp{bt 3}, so it shows the innermost three frames.
4066
4067@smallexample
4068@group
5d161b24 4069#0 m4_traceon (obs=0x24eb0, argc=1, argv=0x2b8c8)
c906108c
SS
4070 at builtin.c:993
4071#1 0x6e38 in expand_macro (sym=0x2b600) at macro.c:242
4072#2 0x6840 in expand_token (obs=0x0, t=177664, td=0xf7fffb08)
4073 at macro.c:71
4074(More stack frames follow...)
4075@end group
4076@end smallexample
4077
4078@noindent
4079The display for frame zero does not begin with a program counter
4080value, indicating that your program has stopped at the beginning of the
4081code for line @code{993} of @code{builtin.c}.
4082
25d29d70
AC
4083Most programs have a standard user entry point---a place where system
4084libraries and startup code transition into user code. For C this is
4085@code{main}. When @value{GDBN} finds the entry function in a backtrace
4086it will terminate the backtrace, to avoid tracing into highly
4087system-specific (and generally uninteresting) code.
4088
4089If you need to examine the startup code, or limit the number of levels
4090in a backtrace, you can change this behavior:
95f90d25
DJ
4091
4092@table @code
25d29d70
AC
4093@item set backtrace past-main
4094@itemx set backtrace past-main on
4644b6e3 4095@kindex set backtrace
25d29d70
AC
4096Backtraces will continue past the user entry point.
4097
4098@item set backtrace past-main off
95f90d25
DJ
4099Backtraces will stop when they encounter the user entry point. This is the
4100default.
4101
25d29d70 4102@item show backtrace past-main
4644b6e3 4103@kindex show backtrace
25d29d70
AC
4104Display the current user entry point backtrace policy.
4105
4106@item set backtrace limit @var{n}
4107@itemx set backtrace limit 0
4108@cindex backtrace limit
4109Limit the backtrace to @var{n} levels. A value of zero means
4110unlimited.
95f90d25 4111
25d29d70
AC
4112@item show backtrace limit
4113Display the current limit on backtrace levels.
95f90d25
DJ
4114@end table
4115
6d2ebf8b 4116@node Selection
c906108c
SS
4117@section Selecting a frame
4118
4119Most commands for examining the stack and other data in your program work on
4120whichever stack frame is selected at the moment. Here are the commands for
4121selecting a stack frame; all of them finish by printing a brief description
4122of the stack frame just selected.
4123
4124@table @code
d4f3574e 4125@kindex frame@r{, selecting}
41afff9a 4126@kindex f @r{(@code{frame})}
c906108c
SS
4127@item frame @var{n}
4128@itemx f @var{n}
4129Select frame number @var{n}. Recall that frame zero is the innermost
4130(currently executing) frame, frame one is the frame that called the
4131innermost one, and so on. The highest-numbered frame is the one for
4132@code{main}.
4133
4134@item frame @var{addr}
4135@itemx f @var{addr}
4136Select the frame at address @var{addr}. This is useful mainly if the
4137chaining of stack frames has been damaged by a bug, making it
4138impossible for @value{GDBN} to assign numbers properly to all frames. In
4139addition, this can be useful when your program has multiple stacks and
4140switches between them.
4141
c906108c
SS
4142On the SPARC architecture, @code{frame} needs two addresses to
4143select an arbitrary frame: a frame pointer and a stack pointer.
4144
4145On the MIPS and Alpha architecture, it needs two addresses: a stack
4146pointer and a program counter.
4147
4148On the 29k architecture, it needs three addresses: a register stack
4149pointer, a program counter, and a memory stack pointer.
4150@c note to future updaters: this is conditioned on a flag
4151@c SETUP_ARBITRARY_FRAME in the tm-*.h files. The above is up to date
4152@c as of 27 Jan 1994.
c906108c
SS
4153
4154@kindex up
4155@item up @var{n}
4156Move @var{n} frames up the stack. For positive numbers @var{n}, this
4157advances toward the outermost frame, to higher frame numbers, to frames
4158that have existed longer. @var{n} defaults to one.
4159
4160@kindex down
41afff9a 4161@kindex do @r{(@code{down})}
c906108c
SS
4162@item down @var{n}
4163Move @var{n} frames down the stack. For positive numbers @var{n}, this
4164advances toward the innermost frame, to lower frame numbers, to frames
4165that were created more recently. @var{n} defaults to one. You may
4166abbreviate @code{down} as @code{do}.
4167@end table
4168
4169All of these commands end by printing two lines of output describing the
4170frame. The first line shows the frame number, the function name, the
4171arguments, and the source file and line number of execution in that
5d161b24 4172frame. The second line shows the text of that source line.
c906108c
SS
4173
4174@need 1000
4175For example:
4176
4177@smallexample
4178@group
4179(@value{GDBP}) up
4180#1 0x22f0 in main (argc=1, argv=0xf7fffbf4, env=0xf7fffbfc)
4181 at env.c:10
418210 read_input_file (argv[i]);
4183@end group
4184@end smallexample
4185
4186After such a printout, the @code{list} command with no arguments
4187prints ten lines centered on the point of execution in the frame.
87885426
FN
4188You can also edit the program at the point of execution with your favorite
4189editing program by typing @code{edit}.
4190@xref{List, ,Printing source lines},
4191for details.
c906108c
SS
4192
4193@table @code
4194@kindex down-silently
4195@kindex up-silently
4196@item up-silently @var{n}
4197@itemx down-silently @var{n}
4198These two commands are variants of @code{up} and @code{down},
4199respectively; they differ in that they do their work silently, without
4200causing display of the new frame. They are intended primarily for use
4201in @value{GDBN} command scripts, where the output might be unnecessary and
4202distracting.
4203@end table
4204
6d2ebf8b 4205@node Frame Info
c906108c
SS
4206@section Information about a frame
4207
4208There are several other commands to print information about the selected
4209stack frame.
4210
4211@table @code
4212@item frame
4213@itemx f
4214When used without any argument, this command does not change which
4215frame is selected, but prints a brief description of the currently
4216selected stack frame. It can be abbreviated @code{f}. With an
4217argument, this command is used to select a stack frame.
4218@xref{Selection, ,Selecting a frame}.
4219
4220@kindex info frame
41afff9a 4221@kindex info f @r{(@code{info frame})}
c906108c
SS
4222@item info frame
4223@itemx info f
4224This command prints a verbose description of the selected stack frame,
4225including:
4226
4227@itemize @bullet
5d161b24
DB
4228@item
4229the address of the frame
c906108c
SS
4230@item
4231the address of the next frame down (called by this frame)
4232@item
4233the address of the next frame up (caller of this frame)
4234@item
4235the language in which the source code corresponding to this frame is written
4236@item
4237the address of the frame's arguments
4238@item
d4f3574e
SS
4239the address of the frame's local variables
4240@item
c906108c
SS
4241the program counter saved in it (the address of execution in the caller frame)
4242@item
4243which registers were saved in the frame
4244@end itemize
4245
4246@noindent The verbose description is useful when
4247something has gone wrong that has made the stack format fail to fit
4248the usual conventions.
4249
4250@item info frame @var{addr}
4251@itemx info f @var{addr}
4252Print a verbose description of the frame at address @var{addr}, without
4253selecting that frame. The selected frame remains unchanged by this
4254command. This requires the same kind of address (more than one for some
4255architectures) that you specify in the @code{frame} command.
4256@xref{Selection, ,Selecting a frame}.
4257
4258@kindex info args
4259@item info args
4260Print the arguments of the selected frame, each on a separate line.
4261
4262@item info locals
4263@kindex info locals
4264Print the local variables of the selected frame, each on a separate
4265line. These are all variables (declared either static or automatic)
4266accessible at the point of execution of the selected frame.
4267
c906108c 4268@kindex info catch
d4f3574e
SS
4269@cindex catch exceptions, list active handlers
4270@cindex exception handlers, how to list
c906108c
SS
4271@item info catch
4272Print a list of all the exception handlers that are active in the
4273current stack frame at the current point of execution. To see other
4274exception handlers, visit the associated frame (using the @code{up},
4275@code{down}, or @code{frame} commands); then type @code{info catch}.
4276@xref{Set Catchpoints, , Setting catchpoints}.
53a5351d 4277
c906108c
SS
4278@end table
4279
c906108c 4280
6d2ebf8b 4281@node Source
c906108c
SS
4282@chapter Examining Source Files
4283
4284@value{GDBN} can print parts of your program's source, since the debugging
4285information recorded in the program tells @value{GDBN} what source files were
4286used to build it. When your program stops, @value{GDBN} spontaneously prints
4287the line where it stopped. Likewise, when you select a stack frame
4288(@pxref{Selection, ,Selecting a frame}), @value{GDBN} prints the line where
4289execution in that frame has stopped. You can print other portions of
4290source files by explicit command.
4291
7a292a7a 4292If you use @value{GDBN} through its @sc{gnu} Emacs interface, you may
d4f3574e 4293prefer to use Emacs facilities to view source; see @ref{Emacs, ,Using
7a292a7a 4294@value{GDBN} under @sc{gnu} Emacs}.
c906108c
SS
4295
4296@menu
4297* List:: Printing source lines
87885426 4298* Edit:: Editing source files
c906108c 4299* Search:: Searching source files
c906108c
SS
4300* Source Path:: Specifying source directories
4301* Machine Code:: Source and machine code
4302@end menu
4303
6d2ebf8b 4304@node List
c906108c
SS
4305@section Printing source lines
4306
4307@kindex list
41afff9a 4308@kindex l @r{(@code{list})}
c906108c 4309To print lines from a source file, use the @code{list} command
5d161b24 4310(abbreviated @code{l}). By default, ten lines are printed.
c906108c
SS
4311There are several ways to specify what part of the file you want to print.
4312
4313Here are the forms of the @code{list} command most commonly used:
4314
4315@table @code
4316@item list @var{linenum}
4317Print lines centered around line number @var{linenum} in the
4318current source file.
4319
4320@item list @var{function}
4321Print lines centered around the beginning of function
4322@var{function}.
4323
4324@item list
4325Print more lines. If the last lines printed were printed with a
4326@code{list} command, this prints lines following the last lines
4327printed; however, if the last line printed was a solitary line printed
4328as part of displaying a stack frame (@pxref{Stack, ,Examining the
4329Stack}), this prints lines centered around that line.
4330
4331@item list -
4332Print lines just before the lines last printed.
4333@end table
4334
4335By default, @value{GDBN} prints ten source lines with any of these forms of
4336the @code{list} command. You can change this using @code{set listsize}:
4337
4338@table @code
4339@kindex set listsize
4340@item set listsize @var{count}
4341Make the @code{list} command display @var{count} source lines (unless
4342the @code{list} argument explicitly specifies some other number).
4343
4344@kindex show listsize
4345@item show listsize
4346Display the number of lines that @code{list} prints.
4347@end table
4348
4349Repeating a @code{list} command with @key{RET} discards the argument,
4350so it is equivalent to typing just @code{list}. This is more useful
4351than listing the same lines again. An exception is made for an
4352argument of @samp{-}; that argument is preserved in repetition so that
4353each repetition moves up in the source file.
4354
4355@cindex linespec
4356In general, the @code{list} command expects you to supply zero, one or two
4357@dfn{linespecs}. Linespecs specify source lines; there are several ways
d4f3574e 4358of writing them, but the effect is always to specify some source line.
c906108c
SS
4359Here is a complete description of the possible arguments for @code{list}:
4360
4361@table @code
4362@item list @var{linespec}
4363Print lines centered around the line specified by @var{linespec}.
4364
4365@item list @var{first},@var{last}
4366Print lines from @var{first} to @var{last}. Both arguments are
4367linespecs.
4368
4369@item list ,@var{last}
4370Print lines ending with @var{last}.
4371
4372@item list @var{first},
4373Print lines starting with @var{first}.
4374
4375@item list +
4376Print lines just after the lines last printed.
4377
4378@item list -
4379Print lines just before the lines last printed.
4380
4381@item list
4382As described in the preceding table.
4383@end table
4384
4385Here are the ways of specifying a single source line---all the
4386kinds of linespec.
4387
4388@table @code
4389@item @var{number}
4390Specifies line @var{number} of the current source file.
4391When a @code{list} command has two linespecs, this refers to
4392the same source file as the first linespec.
4393
4394@item +@var{offset}
4395Specifies the line @var{offset} lines after the last line printed.
4396When used as the second linespec in a @code{list} command that has
4397two, this specifies the line @var{offset} lines down from the
4398first linespec.
4399
4400@item -@var{offset}
4401Specifies the line @var{offset} lines before the last line printed.
4402
4403@item @var{filename}:@var{number}
4404Specifies line @var{number} in the source file @var{filename}.
4405
4406@item @var{function}
4407Specifies the line that begins the body of the function @var{function}.
4408For example: in C, this is the line with the open brace.
4409
4410@item @var{filename}:@var{function}
4411Specifies the line of the open-brace that begins the body of the
4412function @var{function} in the file @var{filename}. You only need the
4413file name with a function name to avoid ambiguity when there are
4414identically named functions in different source files.
4415
4416@item *@var{address}
4417Specifies the line containing the program address @var{address}.
4418@var{address} may be any expression.
4419@end table
4420
87885426
FN
4421@node Edit
4422@section Editing source files
4423@cindex editing source files
4424
4425@kindex edit
4426@kindex e @r{(@code{edit})}
4427To edit the lines in a source file, use the @code{edit} command.
4428The editing program of your choice
4429is invoked with the current line set to
4430the active line in the program.
4431Alternatively, there are several ways to specify what part of the file you
4432want to print if you want to see other parts of the program.
4433
4434Here are the forms of the @code{edit} command most commonly used:
4435
4436@table @code
4437@item edit
4438Edit the current source file at the active line number in the program.
4439
4440@item edit @var{number}
4441Edit the current source file with @var{number} as the active line number.
4442
4443@item edit @var{function}
4444Edit the file containing @var{function} at the beginning of its definition.
4445
4446@item edit @var{filename}:@var{number}
4447Specifies line @var{number} in the source file @var{filename}.
4448
4449@item edit @var{filename}:@var{function}
4450Specifies the line that begins the body of the
4451function @var{function} in the file @var{filename}. You only need the
4452file name with a function name to avoid ambiguity when there are
4453identically named functions in different source files.
4454
4455@item edit *@var{address}
4456Specifies the line containing the program address @var{address}.
4457@var{address} may be any expression.
4458@end table
4459
4460@subsection Choosing your editor
4461You can customize @value{GDBN} to use any editor you want
4462@footnote{
4463The only restriction is that your editor (say @code{ex}), recognizes the
4464following command-line syntax:
10998722 4465@smallexample
87885426 4466ex +@var{number} file
10998722 4467@end smallexample
15387254
EZ
4468The optional numeric value +@var{number} specifies the number of the line in
4469the file where to start editing.}.
4470By default, it is @file{@value{EDITOR}}, but you can change this
10998722
AC
4471by setting the environment variable @code{EDITOR} before using
4472@value{GDBN}. For example, to configure @value{GDBN} to use the
4473@code{vi} editor, you could use these commands with the @code{sh} shell:
4474@smallexample
87885426
FN
4475EDITOR=/usr/bin/vi
4476export EDITOR
15387254 4477gdb @dots{}
10998722 4478@end smallexample
87885426 4479or in the @code{csh} shell,
10998722 4480@smallexample
87885426 4481setenv EDITOR /usr/bin/vi
15387254 4482gdb @dots{}
10998722 4483@end smallexample
87885426 4484
6d2ebf8b 4485@node Search
c906108c 4486@section Searching source files
15387254 4487@cindex searching source files
c906108c
SS
4488@kindex reverse-search
4489
4490There are two commands for searching through the current source file for a
4491regular expression.
4492
4493@table @code
4494@kindex search
4495@kindex forward-search
4496@item forward-search @var{regexp}
4497@itemx search @var{regexp}
4498The command @samp{forward-search @var{regexp}} checks each line,
4499starting with the one following the last line listed, for a match for
5d161b24 4500@var{regexp}. It lists the line that is found. You can use the
c906108c
SS
4501synonym @samp{search @var{regexp}} or abbreviate the command name as
4502@code{fo}.
4503
4504@item reverse-search @var{regexp}
4505The command @samp{reverse-search @var{regexp}} checks each line, starting
4506with the one before the last line listed and going backward, for a match
4507for @var{regexp}. It lists the line that is found. You can abbreviate
4508this command as @code{rev}.
4509@end table
c906108c 4510
6d2ebf8b 4511@node Source Path
c906108c
SS
4512@section Specifying source directories
4513
4514@cindex source path
4515@cindex directories for source files
4516Executable programs sometimes do not record the directories of the source
4517files from which they were compiled, just the names. Even when they do,
4518the directories could be moved between the compilation and your debugging
4519session. @value{GDBN} has a list of directories to search for source files;
4520this is called the @dfn{source path}. Each time @value{GDBN} wants a source file,
4521it tries all the directories in the list, in the order they are present
0b66e38c
EZ
4522in the list, until it finds a file with the desired name.
4523
4524For example, suppose an executable references the file
4525@file{/usr/src/foo-1.0/lib/foo.c}, and our source path is
4526@file{/mnt/cross}. The file is first looked up literally; if this
4527fails, @file{/mnt/cross/usr/src/foo-1.0/lib/foo.c} is tried; if this
4528fails, @file{/mnt/cross/foo.c} is opened; if this fails, an error
4529message is printed. @value{GDBN} does not look up the parts of the
4530source file name, such as @file{/mnt/cross/src/foo-1.0/lib/foo.c}.
4531Likewise, the subdirectories of the source path are not searched: if
4532the source path is @file{/mnt/cross}, and the binary refers to
4533@file{foo.c}, @value{GDBN} would not find it under
4534@file{/mnt/cross/usr/src/foo-1.0/lib}.
4535
4536Plain file names, relative file names with leading directories, file
4537names containing dots, etc.@: are all treated as described above; for
4538instance, if the source path is @file{/mnt/cross}, and the source file
4539is recorded as @file{../lib/foo.c}, @value{GDBN} would first try
4540@file{../lib/foo.c}, then @file{/mnt/cross/../lib/foo.c}, and after
4541that---@file{/mnt/cross/foo.c}.
4542
4543Note that the executable search path is @emph{not} used to locate the
4544source files. Neither is the current working directory, unless it
4545happens to be in the source path.
c906108c
SS
4546
4547Whenever you reset or rearrange the source path, @value{GDBN} clears out
4548any information it has cached about where source files are found and where
4549each line is in the file.
4550
4551@kindex directory
4552@kindex dir
d4f3574e
SS
4553When you start @value{GDBN}, its source path includes only @samp{cdir}
4554and @samp{cwd}, in that order.
c906108c
SS
4555To add other directories, use the @code{directory} command.
4556
4557@table @code
4558@item directory @var{dirname} @dots{}
4559@item dir @var{dirname} @dots{}
4560Add directory @var{dirname} to the front of the source path. Several
d4f3574e
SS
4561directory names may be given to this command, separated by @samp{:}
4562(@samp{;} on MS-DOS and MS-Windows, where @samp{:} usually appears as
4563part of absolute file names) or
c906108c
SS
4564whitespace. You may specify a directory that is already in the source
4565path; this moves it forward, so @value{GDBN} searches it sooner.
4566
4567@kindex cdir
4568@kindex cwd
41afff9a
EZ
4569@vindex $cdir@r{, convenience variable}
4570@vindex $cwdr@r{, convenience variable}
c906108c
SS
4571@cindex compilation directory
4572@cindex current directory
4573@cindex working directory
4574@cindex directory, current
4575@cindex directory, compilation
4576You can use the string @samp{$cdir} to refer to the compilation
4577directory (if one is recorded), and @samp{$cwd} to refer to the current
4578working directory. @samp{$cwd} is not the same as @samp{.}---the former
4579tracks the current working directory as it changes during your @value{GDBN}
4580session, while the latter is immediately expanded to the current
4581directory at the time you add an entry to the source path.
4582
4583@item directory
4584Reset the source path to empty again. This requires confirmation.
4585
4586@c RET-repeat for @code{directory} is explicitly disabled, but since
4587@c repeating it would be a no-op we do not say that. (thanks to RMS)
4588
4589@item show directories
4590@kindex show directories
4591Print the source path: show which directories it contains.
4592@end table
4593
4594If your source path is cluttered with directories that are no longer of
4595interest, @value{GDBN} may sometimes cause confusion by finding the wrong
4596versions of source. You can correct the situation as follows:
4597
4598@enumerate
4599@item
4600Use @code{directory} with no argument to reset the source path to empty.
4601
4602@item
4603Use @code{directory} with suitable arguments to reinstall the
4604directories you want in the source path. You can add all the
4605directories in one command.
4606@end enumerate
4607
6d2ebf8b 4608@node Machine Code
c906108c 4609@section Source and machine code
15387254 4610@cindex source line and its code address
c906108c
SS
4611
4612You can use the command @code{info line} to map source lines to program
4613addresses (and vice versa), and the command @code{disassemble} to display
4614a range of addresses as machine instructions. When run under @sc{gnu} Emacs
d4f3574e 4615mode, the @code{info line} command causes the arrow to point to the
5d161b24 4616line specified. Also, @code{info line} prints addresses in symbolic form as
c906108c
SS
4617well as hex.
4618
4619@table @code
4620@kindex info line
4621@item info line @var{linespec}
4622Print the starting and ending addresses of the compiled code for
4623source line @var{linespec}. You can specify source lines in any of
4624the ways understood by the @code{list} command (@pxref{List, ,Printing
4625source lines}).
4626@end table
4627
4628For example, we can use @code{info line} to discover the location of
4629the object code for the first line of function
4630@code{m4_changequote}:
4631
d4f3574e
SS
4632@c FIXME: I think this example should also show the addresses in
4633@c symbolic form, as they usually would be displayed.
c906108c 4634@smallexample
96a2c332 4635(@value{GDBP}) info line m4_changequote
c906108c
SS
4636Line 895 of "builtin.c" starts at pc 0x634c and ends at 0x6350.
4637@end smallexample
4638
4639@noindent
15387254 4640@cindex code address and its source line
c906108c
SS
4641We can also inquire (using @code{*@var{addr}} as the form for
4642@var{linespec}) what source line covers a particular address:
4643@smallexample
4644(@value{GDBP}) info line *0x63ff
4645Line 926 of "builtin.c" starts at pc 0x63e4 and ends at 0x6404.
4646@end smallexample
4647
4648@cindex @code{$_} and @code{info line}
15387254 4649@cindex @code{x} command, default address
41afff9a 4650@kindex x@r{(examine), and} info line
c906108c
SS
4651After @code{info line}, the default address for the @code{x} command
4652is changed to the starting address of the line, so that @samp{x/i} is
4653sufficient to begin examining the machine code (@pxref{Memory,
4654,Examining memory}). Also, this address is saved as the value of the
4655convenience variable @code{$_} (@pxref{Convenience Vars, ,Convenience
4656variables}).
4657
4658@table @code
4659@kindex disassemble
4660@cindex assembly instructions
4661@cindex instructions, assembly
4662@cindex machine instructions
4663@cindex listing machine instructions
4664@item disassemble
4665This specialized command dumps a range of memory as machine
4666instructions. The default memory range is the function surrounding the
4667program counter of the selected frame. A single argument to this
4668command is a program counter value; @value{GDBN} dumps the function
4669surrounding this value. Two arguments specify a range of addresses
4670(first inclusive, second exclusive) to dump.
4671@end table
4672
c906108c
SS
4673The following example shows the disassembly of a range of addresses of
4674HP PA-RISC 2.0 code:
4675
4676@smallexample
4677(@value{GDBP}) disas 0x32c4 0x32e4
4678Dump of assembler code from 0x32c4 to 0x32e4:
46790x32c4 <main+204>: addil 0,dp
46800x32c8 <main+208>: ldw 0x22c(sr0,r1),r26
46810x32cc <main+212>: ldil 0x3000,r31
46820x32d0 <main+216>: ble 0x3f8(sr4,r31)
46830x32d4 <main+220>: ldo 0(r31),rp
46840x32d8 <main+224>: addil -0x800,dp
46850x32dc <main+228>: ldo 0x588(r1),r26
46860x32e0 <main+232>: ldil 0x3000,r31
4687End of assembler dump.
4688@end smallexample
c906108c
SS
4689
4690Some architectures have more than one commonly-used set of instruction
4691mnemonics or other syntax.
4692
4693@table @code
d4f3574e 4694@kindex set disassembly-flavor
d4f3574e
SS
4695@cindex Intel disassembly flavor
4696@cindex AT&T disassembly flavor
4697@item set disassembly-flavor @var{instruction-set}
c906108c
SS
4698Select the instruction set to use when disassembling the
4699program via the @code{disassemble} or @code{x/i} commands.
4700
4701Currently this command is only defined for the Intel x86 family. You
d4f3574e
SS
4702can set @var{instruction-set} to either @code{intel} or @code{att}.
4703The default is @code{att}, the AT&T flavor used by default by Unix
4704assemblers for x86-based targets.
c906108c
SS
4705@end table
4706
4707
6d2ebf8b 4708@node Data
c906108c
SS
4709@chapter Examining Data
4710
4711@cindex printing data
4712@cindex examining data
4713@kindex print
4714@kindex inspect
4715@c "inspect" is not quite a synonym if you are using Epoch, which we do not
4716@c document because it is nonstandard... Under Epoch it displays in a
4717@c different window or something like that.
4718The usual way to examine data in your program is with the @code{print}
7a292a7a
SS
4719command (abbreviated @code{p}), or its synonym @code{inspect}. It
4720evaluates and prints the value of an expression of the language your
4721program is written in (@pxref{Languages, ,Using @value{GDBN} with
4722Different Languages}).
c906108c
SS
4723
4724@table @code
d4f3574e
SS
4725@item print @var{expr}
4726@itemx print /@var{f} @var{expr}
4727@var{expr} is an expression (in the source language). By default the
4728value of @var{expr} is printed in a format appropriate to its data type;
c906108c 4729you can choose a different format by specifying @samp{/@var{f}}, where
d4f3574e 4730@var{f} is a letter specifying the format; see @ref{Output Formats,,Output
c906108c
SS
4731formats}.
4732
4733@item print
4734@itemx print /@var{f}
15387254 4735@cindex reprint the last value
d4f3574e 4736If you omit @var{expr}, @value{GDBN} displays the last value again (from the
c906108c
SS
4737@dfn{value history}; @pxref{Value History, ,Value history}). This allows you to
4738conveniently inspect the same value in an alternative format.
4739@end table
4740
4741A more low-level way of examining data is with the @code{x} command.
4742It examines data in memory at a specified address and prints it in a
4743specified format. @xref{Memory, ,Examining memory}.
4744
7a292a7a 4745If you are interested in information about types, or about how the
d4f3574e
SS
4746fields of a struct or a class are declared, use the @code{ptype @var{exp}}
4747command rather than @code{print}. @xref{Symbols, ,Examining the Symbol
7a292a7a 4748Table}.
c906108c
SS
4749
4750@menu
4751* Expressions:: Expressions
4752* Variables:: Program variables
4753* Arrays:: Artificial arrays
4754* Output Formats:: Output formats
4755* Memory:: Examining memory
4756* Auto Display:: Automatic display
4757* Print Settings:: Print settings
4758* Value History:: Value history
4759* Convenience Vars:: Convenience variables
4760* Registers:: Registers
c906108c 4761* Floating Point Hardware:: Floating point hardware
53c69bd7 4762* Vector Unit:: Vector Unit
b383017d 4763* Auxiliary Vector:: Auxiliary data provided by operating system
29e57380 4764* Memory Region Attributes:: Memory region attributes
16d9dec6 4765* Dump/Restore Files:: Copy between memory and a file
a0eb71c5
KB
4766* Character Sets:: Debugging programs that use a different
4767 character set than GDB does
c906108c
SS
4768@end menu
4769
6d2ebf8b 4770@node Expressions
c906108c
SS
4771@section Expressions
4772
4773@cindex expressions
4774@code{print} and many other @value{GDBN} commands accept an expression and
4775compute its value. Any kind of constant, variable or operator defined
4776by the programming language you are using is valid in an expression in
e2e0bcd1
JB
4777@value{GDBN}. This includes conditional expressions, function calls,
4778casts, and string constants. It also includes preprocessor macros, if
4779you compiled your program to include this information; see
4780@ref{Compilation}.
c906108c 4781
15387254 4782@cindex arrays in expressions
d4f3574e
SS
4783@value{GDBN} supports array constants in expressions input by
4784the user. The syntax is @{@var{element}, @var{element}@dots{}@}. For example,
5d161b24 4785you can use the command @code{print @{1, 2, 3@}} to build up an array in
d4f3574e 4786memory that is @code{malloc}ed in the target program.
c906108c 4787
c906108c
SS
4788Because C is so widespread, most of the expressions shown in examples in
4789this manual are in C. @xref{Languages, , Using @value{GDBN} with Different
4790Languages}, for information on how to use expressions in other
4791languages.
4792
4793In this section, we discuss operators that you can use in @value{GDBN}
4794expressions regardless of your programming language.
4795
15387254 4796@cindex casts, in expressions
c906108c
SS
4797Casts are supported in all languages, not just in C, because it is so
4798useful to cast a number into a pointer in order to examine a structure
4799at that address in memory.
4800@c FIXME: casts supported---Mod2 true?
c906108c
SS
4801
4802@value{GDBN} supports these operators, in addition to those common
4803to programming languages:
4804
4805@table @code
4806@item @@
4807@samp{@@} is a binary operator for treating parts of memory as arrays.
4808@xref{Arrays, ,Artificial arrays}, for more information.
4809
4810@item ::
4811@samp{::} allows you to specify a variable in terms of the file or
4812function where it is defined. @xref{Variables, ,Program variables}.
4813
4814@cindex @{@var{type}@}
4815@cindex type casting memory
4816@cindex memory, viewing as typed object
4817@cindex casts, to view memory
4818@item @{@var{type}@} @var{addr}
4819Refers to an object of type @var{type} stored at address @var{addr} in
4820memory. @var{addr} may be any expression whose value is an integer or
4821pointer (but parentheses are required around binary operators, just as in
4822a cast). This construct is allowed regardless of what kind of data is
4823normally supposed to reside at @var{addr}.
4824@end table
4825
6d2ebf8b 4826@node Variables
c906108c
SS
4827@section Program variables
4828
4829The most common kind of expression to use is the name of a variable
4830in your program.
4831
4832Variables in expressions are understood in the selected stack frame
4833(@pxref{Selection, ,Selecting a frame}); they must be either:
4834
4835@itemize @bullet
4836@item
4837global (or file-static)
4838@end itemize
4839
5d161b24 4840@noindent or
c906108c
SS
4841
4842@itemize @bullet
4843@item
4844visible according to the scope rules of the
4845programming language from the point of execution in that frame
5d161b24 4846@end itemize
c906108c
SS
4847
4848@noindent This means that in the function
4849
474c8240 4850@smallexample
c906108c
SS
4851foo (a)
4852 int a;
4853@{
4854 bar (a);
4855 @{
4856 int b = test ();
4857 bar (b);
4858 @}
4859@}
474c8240 4860@end smallexample
c906108c
SS
4861
4862@noindent
4863you can examine and use the variable @code{a} whenever your program is
4864executing within the function @code{foo}, but you can only use or
4865examine the variable @code{b} while your program is executing inside
4866the block where @code{b} is declared.
4867
4868@cindex variable name conflict
4869There is an exception: you can refer to a variable or function whose
4870scope is a single source file even if the current execution point is not
4871in this file. But it is possible to have more than one such variable or
4872function with the same name (in different source files). If that
4873happens, referring to that name has unpredictable effects. If you wish,
4874you can specify a static variable in a particular function or file,
15387254 4875using the colon-colon (@code{::}) notation:
c906108c 4876
d4f3574e 4877@cindex colon-colon, context for variables/functions
c906108c
SS
4878@iftex
4879@c info cannot cope with a :: index entry, but why deprive hard copy readers?
41afff9a 4880@cindex @code{::}, context for variables/functions
c906108c 4881@end iftex
474c8240 4882@smallexample
c906108c
SS
4883@var{file}::@var{variable}
4884@var{function}::@var{variable}
474c8240 4885@end smallexample
c906108c
SS
4886
4887@noindent
4888Here @var{file} or @var{function} is the name of the context for the
4889static @var{variable}. In the case of file names, you can use quotes to
4890make sure @value{GDBN} parses the file name as a single word---for example,
4891to print a global value of @code{x} defined in @file{f2.c}:
4892
474c8240 4893@smallexample
c906108c 4894(@value{GDBP}) p 'f2.c'::x
474c8240 4895@end smallexample
c906108c 4896
b37052ae 4897@cindex C@t{++} scope resolution
c906108c 4898This use of @samp{::} is very rarely in conflict with the very similar
b37052ae 4899use of the same notation in C@t{++}. @value{GDBN} also supports use of the C@t{++}
c906108c
SS
4900scope resolution operator in @value{GDBN} expressions.
4901@c FIXME: Um, so what happens in one of those rare cases where it's in
4902@c conflict?? --mew
c906108c
SS
4903
4904@cindex wrong values
4905@cindex variable values, wrong
15387254
EZ
4906@cindex function entry/exit, wrong values of variables
4907@cindex optimized code, wrong values of variables
c906108c
SS
4908@quotation
4909@emph{Warning:} Occasionally, a local variable may appear to have the
4910wrong value at certain points in a function---just after entry to a new
4911scope, and just before exit.
4912@end quotation
4913You may see this problem when you are stepping by machine instructions.
4914This is because, on most machines, it takes more than one instruction to
4915set up a stack frame (including local variable definitions); if you are
4916stepping by machine instructions, variables may appear to have the wrong
4917values until the stack frame is completely built. On exit, it usually
4918also takes more than one machine instruction to destroy a stack frame;
4919after you begin stepping through that group of instructions, local
4920variable definitions may be gone.
4921
4922This may also happen when the compiler does significant optimizations.
4923To be sure of always seeing accurate values, turn off all optimization
4924when compiling.
4925
d4f3574e
SS
4926@cindex ``No symbol "foo" in current context''
4927Another possible effect of compiler optimizations is to optimize
4928unused variables out of existence, or assign variables to registers (as
4929opposed to memory addresses). Depending on the support for such cases
4930offered by the debug info format used by the compiler, @value{GDBN}
4931might not be able to display values for such local variables. If that
4932happens, @value{GDBN} will print a message like this:
4933
474c8240 4934@smallexample
d4f3574e 4935No symbol "foo" in current context.
474c8240 4936@end smallexample
d4f3574e
SS
4937
4938To solve such problems, either recompile without optimizations, or use a
4939different debug info format, if the compiler supports several such
15387254 4940formats. For example, @value{NGCC}, the @sc{gnu} C/C@t{++} compiler,
0179ffac
DC
4941usually supports the @option{-gstabs+} option. @option{-gstabs+}
4942produces debug info in a format that is superior to formats such as
4943COFF. You may be able to use DWARF 2 (@option{-gdwarf-2}), which is also
4944an effective form for debug info. @xref{Debugging Options,,Options
4945for Debugging Your Program or @sc{gnu} CC, gcc.info, Using @sc{gnu} CC}.
15387254
EZ
4946@xref{C, , Debugging C++}, for more info about debug info formats
4947that are best suited to C@t{++} programs.
d4f3574e 4948
6d2ebf8b 4949@node Arrays
c906108c
SS
4950@section Artificial arrays
4951
4952@cindex artificial array
15387254 4953@cindex arrays
41afff9a 4954@kindex @@@r{, referencing memory as an array}
c906108c
SS
4955It is often useful to print out several successive objects of the
4956same type in memory; a section of an array, or an array of
4957dynamically determined size for which only a pointer exists in the
4958program.
4959
4960You can do this by referring to a contiguous span of memory as an
4961@dfn{artificial array}, using the binary operator @samp{@@}. The left
4962operand of @samp{@@} should be the first element of the desired array
4963and be an individual object. The right operand should be the desired length
4964of the array. The result is an array value whose elements are all of
4965the type of the left argument. The first element is actually the left
4966argument; the second element comes from bytes of memory immediately
4967following those that hold the first element, and so on. Here is an
4968example. If a program says
4969
474c8240 4970@smallexample
c906108c 4971int *array = (int *) malloc (len * sizeof (int));
474c8240 4972@end smallexample
c906108c
SS
4973
4974@noindent
4975you can print the contents of @code{array} with
4976
474c8240 4977@smallexample
c906108c 4978p *array@@len
474c8240 4979@end smallexample
c906108c
SS
4980
4981The left operand of @samp{@@} must reside in memory. Array values made
4982with @samp{@@} in this way behave just like other arrays in terms of
4983subscripting, and are coerced to pointers when used in expressions.
4984Artificial arrays most often appear in expressions via the value history
4985(@pxref{Value History, ,Value history}), after printing one out.
4986
4987Another way to create an artificial array is to use a cast.
4988This re-interprets a value as if it were an array.
4989The value need not be in memory:
474c8240 4990@smallexample
c906108c
SS
4991(@value{GDBP}) p/x (short[2])0x12345678
4992$1 = @{0x1234, 0x5678@}
474c8240 4993@end smallexample
c906108c
SS
4994
4995As a convenience, if you leave the array length out (as in
c3f6f71d 4996@samp{(@var{type}[])@var{value}}) @value{GDBN} calculates the size to fill
c906108c 4997the value (as @samp{sizeof(@var{value})/sizeof(@var{type})}:
474c8240 4998@smallexample
c906108c
SS
4999(@value{GDBP}) p/x (short[])0x12345678
5000$2 = @{0x1234, 0x5678@}
474c8240 5001@end smallexample
c906108c
SS
5002
5003Sometimes the artificial array mechanism is not quite enough; in
5004moderately complex data structures, the elements of interest may not
5005actually be adjacent---for example, if you are interested in the values
5006of pointers in an array. One useful work-around in this situation is
5007to use a convenience variable (@pxref{Convenience Vars, ,Convenience
5008variables}) as a counter in an expression that prints the first
5009interesting value, and then repeat that expression via @key{RET}. For
5010instance, suppose you have an array @code{dtab} of pointers to
5011structures, and you are interested in the values of a field @code{fv}
5012in each structure. Here is an example of what you might type:
5013
474c8240 5014@smallexample
c906108c
SS
5015set $i = 0
5016p dtab[$i++]->fv
5017@key{RET}
5018@key{RET}
5019@dots{}
474c8240 5020@end smallexample
c906108c 5021
6d2ebf8b 5022@node Output Formats
c906108c
SS
5023@section Output formats
5024
5025@cindex formatted output
5026@cindex output formats
5027By default, @value{GDBN} prints a value according to its data type. Sometimes
5028this is not what you want. For example, you might want to print a number
5029in hex, or a pointer in decimal. Or you might want to view data in memory
5030at a certain address as a character string or as an instruction. To do
5031these things, specify an @dfn{output format} when you print a value.
5032
5033The simplest use of output formats is to say how to print a value
5034already computed. This is done by starting the arguments of the
5035@code{print} command with a slash and a format letter. The format
5036letters supported are:
5037
5038@table @code
5039@item x
5040Regard the bits of the value as an integer, and print the integer in
5041hexadecimal.
5042
5043@item d
5044Print as integer in signed decimal.
5045
5046@item u
5047Print as integer in unsigned decimal.
5048
5049@item o
5050Print as integer in octal.
5051
5052@item t
5053Print as integer in binary. The letter @samp{t} stands for ``two''.
5054@footnote{@samp{b} cannot be used because these format letters are also
5055used with the @code{x} command, where @samp{b} stands for ``byte'';
d4f3574e 5056see @ref{Memory,,Examining memory}.}
c906108c
SS
5057
5058@item a
5059@cindex unknown address, locating
3d67e040 5060@cindex locate address
c906108c
SS
5061Print as an address, both absolute in hexadecimal and as an offset from
5062the nearest preceding symbol. You can use this format used to discover
5063where (in what function) an unknown address is located:
5064
474c8240 5065@smallexample
c906108c
SS
5066(@value{GDBP}) p/a 0x54320
5067$3 = 0x54320 <_initialize_vx+396>
474c8240 5068@end smallexample
c906108c 5069
3d67e040
EZ
5070@noindent
5071The command @code{info symbol 0x54320} yields similar results.
5072@xref{Symbols, info symbol}.
5073
c906108c
SS
5074@item c
5075Regard as an integer and print it as a character constant.
5076
5077@item f
5078Regard the bits of the value as a floating point number and print
5079using typical floating point syntax.
5080@end table
5081
5082For example, to print the program counter in hex (@pxref{Registers}), type
5083
474c8240 5084@smallexample
c906108c 5085p/x $pc
474c8240 5086@end smallexample
c906108c
SS
5087
5088@noindent
5089Note that no space is required before the slash; this is because command
5090names in @value{GDBN} cannot contain a slash.
5091
5092To reprint the last value in the value history with a different format,
5093you can use the @code{print} command with just a format and no
5094expression. For example, @samp{p/x} reprints the last value in hex.
5095
6d2ebf8b 5096@node Memory
c906108c
SS
5097@section Examining memory
5098
5099You can use the command @code{x} (for ``examine'') to examine memory in
5100any of several formats, independently of your program's data types.
5101
5102@cindex examining memory
5103@table @code
41afff9a 5104@kindex x @r{(examine memory)}
c906108c
SS
5105@item x/@var{nfu} @var{addr}
5106@itemx x @var{addr}
5107@itemx x
5108Use the @code{x} command to examine memory.
5109@end table
5110
5111@var{n}, @var{f}, and @var{u} are all optional parameters that specify how
5112much memory to display and how to format it; @var{addr} is an
5113expression giving the address where you want to start displaying memory.
5114If you use defaults for @var{nfu}, you need not type the slash @samp{/}.
5115Several commands set convenient defaults for @var{addr}.
5116
5117@table @r
5118@item @var{n}, the repeat count
5119The repeat count is a decimal integer; the default is 1. It specifies
5120how much memory (counting by units @var{u}) to display.
5121@c This really is **decimal**; unaffected by 'set radix' as of GDB
5122@c 4.1.2.
5123
5124@item @var{f}, the display format
5125The display format is one of the formats used by @code{print},
5126@samp{s} (null-terminated string), or @samp{i} (machine instruction).
5127The default is @samp{x} (hexadecimal) initially.
5128The default changes each time you use either @code{x} or @code{print}.
5129
5130@item @var{u}, the unit size
5131The unit size is any of
5132
5133@table @code
5134@item b
5135Bytes.
5136@item h
5137Halfwords (two bytes).
5138@item w
5139Words (four bytes). This is the initial default.
5140@item g
5141Giant words (eight bytes).
5142@end table
5143
5144Each time you specify a unit size with @code{x}, that size becomes the
5145default unit the next time you use @code{x}. (For the @samp{s} and
5146@samp{i} formats, the unit size is ignored and is normally not written.)
5147
5148@item @var{addr}, starting display address
5149@var{addr} is the address where you want @value{GDBN} to begin displaying
5150memory. The expression need not have a pointer value (though it may);
5151it is always interpreted as an integer address of a byte of memory.
5152@xref{Expressions, ,Expressions}, for more information on expressions. The default for
5153@var{addr} is usually just after the last address examined---but several
5154other commands also set the default address: @code{info breakpoints} (to
5155the address of the last breakpoint listed), @code{info line} (to the
5156starting address of a line), and @code{print} (if you use it to display
5157a value from memory).
5158@end table
5159
5160For example, @samp{x/3uh 0x54320} is a request to display three halfwords
5161(@code{h}) of memory, formatted as unsigned decimal integers (@samp{u}),
5162starting at address @code{0x54320}. @samp{x/4xw $sp} prints the four
5163words (@samp{w}) of memory above the stack pointer (here, @samp{$sp};
d4f3574e 5164@pxref{Registers, ,Registers}) in hexadecimal (@samp{x}).
c906108c
SS
5165
5166Since the letters indicating unit sizes are all distinct from the
5167letters specifying output formats, you do not have to remember whether
5168unit size or format comes first; either order works. The output
5169specifications @samp{4xw} and @samp{4wx} mean exactly the same thing.
5170(However, the count @var{n} must come first; @samp{wx4} does not work.)
5171
5172Even though the unit size @var{u} is ignored for the formats @samp{s}
5173and @samp{i}, you might still want to use a count @var{n}; for example,
5174@samp{3i} specifies that you want to see three machine instructions,
5175including any operands. The command @code{disassemble} gives an
d4f3574e 5176alternative way of inspecting machine instructions; see @ref{Machine
c906108c
SS
5177Code,,Source and machine code}.
5178
5179All the defaults for the arguments to @code{x} are designed to make it
5180easy to continue scanning memory with minimal specifications each time
5181you use @code{x}. For example, after you have inspected three machine
5182instructions with @samp{x/3i @var{addr}}, you can inspect the next seven
5183with just @samp{x/7}. If you use @key{RET} to repeat the @code{x} command,
5184the repeat count @var{n} is used again; the other arguments default as
5185for successive uses of @code{x}.
5186
5187@cindex @code{$_}, @code{$__}, and value history
5188The addresses and contents printed by the @code{x} command are not saved
5189in the value history because there is often too much of them and they
5190would get in the way. Instead, @value{GDBN} makes these values available for
5191subsequent use in expressions as values of the convenience variables
5192@code{$_} and @code{$__}. After an @code{x} command, the last address
5193examined is available for use in expressions in the convenience variable
5194@code{$_}. The contents of that address, as examined, are available in
5195the convenience variable @code{$__}.
5196
5197If the @code{x} command has a repeat count, the address and contents saved
5198are from the last memory unit printed; this is not the same as the last
5199address printed if several units were printed on the last line of output.
5200
6d2ebf8b 5201@node Auto Display
c906108c
SS
5202@section Automatic display
5203@cindex automatic display
5204@cindex display of expressions
5205
5206If you find that you want to print the value of an expression frequently
5207(to see how it changes), you might want to add it to the @dfn{automatic
5208display list} so that @value{GDBN} prints its value each time your program stops.
5209Each expression added to the list is given a number to identify it;
5210to remove an expression from the list, you specify that number.
5211The automatic display looks like this:
5212
474c8240 5213@smallexample
c906108c
SS
52142: foo = 38
52153: bar[5] = (struct hack *) 0x3804
474c8240 5216@end smallexample
c906108c
SS
5217
5218@noindent
5219This display shows item numbers, expressions and their current values. As with
5220displays you request manually using @code{x} or @code{print}, you can
5221specify the output format you prefer; in fact, @code{display} decides
5222whether to use @code{print} or @code{x} depending on how elaborate your
5223format specification is---it uses @code{x} if you specify a unit size,
5224or one of the two formats (@samp{i} and @samp{s}) that are only
5225supported by @code{x}; otherwise it uses @code{print}.
5226
5227@table @code
5228@kindex display
d4f3574e
SS
5229@item display @var{expr}
5230Add the expression @var{expr} to the list of expressions to display
c906108c
SS
5231each time your program stops. @xref{Expressions, ,Expressions}.
5232
5233@code{display} does not repeat if you press @key{RET} again after using it.
5234
d4f3574e 5235@item display/@var{fmt} @var{expr}
c906108c 5236For @var{fmt} specifying only a display format and not a size or
d4f3574e 5237count, add the expression @var{expr} to the auto-display list but
c906108c
SS
5238arrange to display it each time in the specified format @var{fmt}.
5239@xref{Output Formats,,Output formats}.
5240
5241@item display/@var{fmt} @var{addr}
5242For @var{fmt} @samp{i} or @samp{s}, or including a unit-size or a
5243number of units, add the expression @var{addr} as a memory address to
5244be examined each time your program stops. Examining means in effect
5245doing @samp{x/@var{fmt} @var{addr}}. @xref{Memory, ,Examining memory}.
5246@end table
5247
5248For example, @samp{display/i $pc} can be helpful, to see the machine
5249instruction about to be executed each time execution stops (@samp{$pc}
d4f3574e 5250is a common name for the program counter; @pxref{Registers, ,Registers}).
c906108c
SS
5251
5252@table @code
5253@kindex delete display
5254@kindex undisplay
5255@item undisplay @var{dnums}@dots{}
5256@itemx delete display @var{dnums}@dots{}
5257Remove item numbers @var{dnums} from the list of expressions to display.
5258
5259@code{undisplay} does not repeat if you press @key{RET} after using it.
5260(Otherwise you would just get the error @samp{No display number @dots{}}.)
5261
5262@kindex disable display
5263@item disable display @var{dnums}@dots{}
5264Disable the display of item numbers @var{dnums}. A disabled display
5265item is not printed automatically, but is not forgotten. It may be
5266enabled again later.
5267
5268@kindex enable display
5269@item enable display @var{dnums}@dots{}
5270Enable display of item numbers @var{dnums}. It becomes effective once
5271again in auto display of its expression, until you specify otherwise.
5272
5273@item display
5274Display the current values of the expressions on the list, just as is
5275done when your program stops.
5276
5277@kindex info display
5278@item info display
5279Print the list of expressions previously set up to display
5280automatically, each one with its item number, but without showing the
5281values. This includes disabled expressions, which are marked as such.
5282It also includes expressions which would not be displayed right now
5283because they refer to automatic variables not currently available.
5284@end table
5285
15387254 5286@cindex display disabled out of scope
c906108c
SS
5287If a display expression refers to local variables, then it does not make
5288sense outside the lexical context for which it was set up. Such an
5289expression is disabled when execution enters a context where one of its
5290variables is not defined. For example, if you give the command
5291@code{display last_char} while inside a function with an argument
5292@code{last_char}, @value{GDBN} displays this argument while your program
5293continues to stop inside that function. When it stops elsewhere---where
5294there is no variable @code{last_char}---the display is disabled
5295automatically. The next time your program stops where @code{last_char}
5296is meaningful, you can enable the display expression once again.
5297
6d2ebf8b 5298@node Print Settings
c906108c
SS
5299@section Print settings
5300
5301@cindex format options
5302@cindex print settings
5303@value{GDBN} provides the following ways to control how arrays, structures,
5304and symbols are printed.
5305
5306@noindent
5307These settings are useful for debugging programs in any language:
5308
5309@table @code
4644b6e3 5310@kindex set print
c906108c
SS
5311@item set print address
5312@itemx set print address on
4644b6e3 5313@cindex print/don't print memory addresses
c906108c
SS
5314@value{GDBN} prints memory addresses showing the location of stack
5315traces, structure values, pointer values, breakpoints, and so forth,
5316even when it also displays the contents of those addresses. The default
5317is @code{on}. For example, this is what a stack frame display looks like with
5318@code{set print address on}:
5319
5320@smallexample
5321@group
5322(@value{GDBP}) f
5323#0 set_quotes (lq=0x34c78 "<<", rq=0x34c88 ">>")
5324 at input.c:530
5325530 if (lquote != def_lquote)
5326@end group
5327@end smallexample
5328
5329@item set print address off
5330Do not print addresses when displaying their contents. For example,
5331this is the same stack frame displayed with @code{set print address off}:
5332
5333@smallexample
5334@group
5335(@value{GDBP}) set print addr off
5336(@value{GDBP}) f
5337#0 set_quotes (lq="<<", rq=">>") at input.c:530
5338530 if (lquote != def_lquote)
5339@end group
5340@end smallexample
5341
5342You can use @samp{set print address off} to eliminate all machine
5343dependent displays from the @value{GDBN} interface. For example, with
5344@code{print address off}, you should get the same text for backtraces on
5345all machines---whether or not they involve pointer arguments.
5346
4644b6e3 5347@kindex show print
c906108c
SS
5348@item show print address
5349Show whether or not addresses are to be printed.
5350@end table
5351
5352When @value{GDBN} prints a symbolic address, it normally prints the
5353closest earlier symbol plus an offset. If that symbol does not uniquely
5354identify the address (for example, it is a name whose scope is a single
5355source file), you may need to clarify. One way to do this is with
5356@code{info line}, for example @samp{info line *0x4537}. Alternately,
5357you can set @value{GDBN} to print the source file and line number when
5358it prints a symbolic address:
5359
5360@table @code
c906108c 5361@item set print symbol-filename on
4644b6e3 5362@cindex closest symbol and offset for an address
c906108c
SS
5363Tell @value{GDBN} to print the source file name and line number of a
5364symbol in the symbolic form of an address.
5365
5366@item set print symbol-filename off
5367Do not print source file name and line number of a symbol. This is the
5368default.
5369
c906108c
SS
5370@item show print symbol-filename
5371Show whether or not @value{GDBN} will print the source file name and
5372line number of a symbol in the symbolic form of an address.
5373@end table
5374
5375Another situation where it is helpful to show symbol filenames and line
5376numbers is when disassembling code; @value{GDBN} shows you the line
5377number and source file that corresponds to each instruction.
5378
5379Also, you may wish to see the symbolic form only if the address being
5380printed is reasonably close to the closest earlier symbol:
5381
5382@table @code
c906108c 5383@item set print max-symbolic-offset @var{max-offset}
4644b6e3 5384@cindex maximum value for offset of closest symbol
c906108c
SS
5385Tell @value{GDBN} to only display the symbolic form of an address if the
5386offset between the closest earlier symbol and the address is less than
5d161b24 5387@var{max-offset}. The default is 0, which tells @value{GDBN}
c906108c
SS
5388to always print the symbolic form of an address if any symbol precedes it.
5389
c906108c
SS
5390@item show print max-symbolic-offset
5391Ask how large the maximum offset is that @value{GDBN} prints in a
5392symbolic address.
5393@end table
5394
5395@cindex wild pointer, interpreting
5396@cindex pointer, finding referent
5397If you have a pointer and you are not sure where it points, try
5398@samp{set print symbol-filename on}. Then you can determine the name
5399and source file location of the variable where it points, using
5400@samp{p/a @var{pointer}}. This interprets the address in symbolic form.
5401For example, here @value{GDBN} shows that a variable @code{ptt} points
5402at another variable @code{t}, defined in @file{hi2.c}:
5403
474c8240 5404@smallexample
c906108c
SS
5405(@value{GDBP}) set print symbol-filename on
5406(@value{GDBP}) p/a ptt
5407$4 = 0xe008 <t in hi2.c>
474c8240 5408@end smallexample
c906108c
SS
5409
5410@quotation
5411@emph{Warning:} For pointers that point to a local variable, @samp{p/a}
5412does not show the symbol name and filename of the referent, even with
5413the appropriate @code{set print} options turned on.
5414@end quotation
5415
5416Other settings control how different kinds of objects are printed:
5417
5418@table @code
c906108c
SS
5419@item set print array
5420@itemx set print array on
4644b6e3 5421@cindex pretty print arrays
c906108c
SS
5422Pretty print arrays. This format is more convenient to read,
5423but uses more space. The default is off.
5424
5425@item set print array off
5426Return to compressed format for arrays.
5427
c906108c
SS
5428@item show print array
5429Show whether compressed or pretty format is selected for displaying
5430arrays.
5431
c906108c 5432@item set print elements @var{number-of-elements}
4644b6e3 5433@cindex number of array elements to print
c906108c
SS
5434Set a limit on how many elements of an array @value{GDBN} will print.
5435If @value{GDBN} is printing a large array, it stops printing after it has
5436printed the number of elements set by the @code{set print elements} command.
5437This limit also applies to the display of strings.
d4f3574e 5438When @value{GDBN} starts, this limit is set to 200.
c906108c
SS
5439Setting @var{number-of-elements} to zero means that the printing is unlimited.
5440
c906108c
SS
5441@item show print elements
5442Display the number of elements of a large array that @value{GDBN} will print.
5443If the number is 0, then the printing is unlimited.
5444
c906108c 5445@item set print null-stop
4644b6e3 5446@cindex @sc{null} elements in arrays
c906108c 5447Cause @value{GDBN} to stop printing the characters of an array when the first
d4f3574e 5448@sc{null} is encountered. This is useful when large arrays actually
c906108c 5449contain only short strings.
d4f3574e 5450The default is off.
c906108c 5451
c906108c 5452@item set print pretty on
5d161b24 5453Cause @value{GDBN} to print structures in an indented format with one member
c906108c
SS
5454per line, like this:
5455
5456@smallexample
5457@group
5458$1 = @{
5459 next = 0x0,
5460 flags = @{
5461 sweet = 1,
5462 sour = 1
5463 @},
5464 meat = 0x54 "Pork"
5465@}
5466@end group
5467@end smallexample
5468
5469@item set print pretty off
5470Cause @value{GDBN} to print structures in a compact format, like this:
5471
5472@smallexample
5473@group
5474$1 = @{next = 0x0, flags = @{sweet = 1, sour = 1@}, \
5475meat = 0x54 "Pork"@}
5476@end group
5477@end smallexample
5478
5479@noindent
5480This is the default format.
5481
c906108c
SS
5482@item show print pretty
5483Show which format @value{GDBN} is using to print structures.
5484
c906108c 5485@item set print sevenbit-strings on
4644b6e3
EZ
5486@cindex eight-bit characters in strings
5487@cindex octal escapes in strings
c906108c
SS
5488Print using only seven-bit characters; if this option is set,
5489@value{GDBN} displays any eight-bit characters (in strings or
5490character values) using the notation @code{\}@var{nnn}. This setting is
5491best if you are working in English (@sc{ascii}) and you use the
5492high-order bit of characters as a marker or ``meta'' bit.
5493
5494@item set print sevenbit-strings off
5495Print full eight-bit characters. This allows the use of more
5496international character sets, and is the default.
5497
c906108c
SS
5498@item show print sevenbit-strings
5499Show whether or not @value{GDBN} is printing only seven-bit characters.
5500
c906108c 5501@item set print union on
4644b6e3 5502@cindex unions in structures, printing
5d161b24 5503Tell @value{GDBN} to print unions which are contained in structures. This
c906108c
SS
5504is the default setting.
5505
5506@item set print union off
5507Tell @value{GDBN} not to print unions which are contained in structures.
5508
c906108c
SS
5509@item show print union
5510Ask @value{GDBN} whether or not it will print unions which are contained in
5511structures.
5512
5513For example, given the declarations
5514
5515@smallexample
5516typedef enum @{Tree, Bug@} Species;
5517typedef enum @{Big_tree, Acorn, Seedling@} Tree_forms;
5d161b24 5518typedef enum @{Caterpillar, Cocoon, Butterfly@}
c906108c
SS
5519 Bug_forms;
5520
5521struct thing @{
5522 Species it;
5523 union @{
5524 Tree_forms tree;
5525 Bug_forms bug;
5526 @} form;
5527@};
5528
5529struct thing foo = @{Tree, @{Acorn@}@};
5530@end smallexample
5531
5532@noindent
5533with @code{set print union on} in effect @samp{p foo} would print
5534
5535@smallexample
5536$1 = @{it = Tree, form = @{tree = Acorn, bug = Cocoon@}@}
5537@end smallexample
5538
5539@noindent
5540and with @code{set print union off} in effect it would print
5541
5542@smallexample
5543$1 = @{it = Tree, form = @{...@}@}
5544@end smallexample
5545@end table
5546
c906108c
SS
5547@need 1000
5548@noindent
b37052ae 5549These settings are of interest when debugging C@t{++} programs:
c906108c
SS
5550
5551@table @code
4644b6e3 5552@cindex demangling C@t{++} names
c906108c
SS
5553@item set print demangle
5554@itemx set print demangle on
b37052ae 5555Print C@t{++} names in their source form rather than in the encoded
c906108c 5556(``mangled'') form passed to the assembler and linker for type-safe
d4f3574e 5557linkage. The default is on.
c906108c 5558
c906108c 5559@item show print demangle
b37052ae 5560Show whether C@t{++} names are printed in mangled or demangled form.
c906108c 5561
c906108c
SS
5562@item set print asm-demangle
5563@itemx set print asm-demangle on
b37052ae 5564Print C@t{++} names in their source form rather than their mangled form, even
c906108c
SS
5565in assembler code printouts such as instruction disassemblies.
5566The default is off.
5567
c906108c 5568@item show print asm-demangle
b37052ae 5569Show whether C@t{++} names in assembly listings are printed in mangled
c906108c
SS
5570or demangled form.
5571
b37052ae
EZ
5572@cindex C@t{++} symbol decoding style
5573@cindex symbol decoding style, C@t{++}
c906108c
SS
5574@item set demangle-style @var{style}
5575Choose among several encoding schemes used by different compilers to
b37052ae 5576represent C@t{++} names. The choices for @var{style} are currently:
c906108c
SS
5577
5578@table @code
5579@item auto
5580Allow @value{GDBN} to choose a decoding style by inspecting your program.
5581
5582@item gnu
b37052ae 5583Decode based on the @sc{gnu} C@t{++} compiler (@code{g++}) encoding algorithm.
c906108c 5584This is the default.
c906108c
SS
5585
5586@item hp
b37052ae 5587Decode based on the HP ANSI C@t{++} (@code{aCC}) encoding algorithm.
c906108c
SS
5588
5589@item lucid
b37052ae 5590Decode based on the Lucid C@t{++} compiler (@code{lcc}) encoding algorithm.
c906108c
SS
5591
5592@item arm
b37052ae 5593Decode using the algorithm in the @cite{C@t{++} Annotated Reference Manual}.
c906108c
SS
5594@strong{Warning:} this setting alone is not sufficient to allow
5595debugging @code{cfront}-generated executables. @value{GDBN} would
5596require further enhancement to permit that.
5597
5598@end table
5599If you omit @var{style}, you will see a list of possible formats.
5600
c906108c 5601@item show demangle-style
b37052ae 5602Display the encoding style currently in use for decoding C@t{++} symbols.
c906108c 5603
c906108c
SS
5604@item set print object
5605@itemx set print object on
4644b6e3 5606@cindex derived type of an object, printing
c906108c
SS
5607When displaying a pointer to an object, identify the @emph{actual}
5608(derived) type of the object rather than the @emph{declared} type, using
5609the virtual function table.
5610
5611@item set print object off
5612Display only the declared type of objects, without reference to the
5613virtual function table. This is the default setting.
5614
c906108c
SS
5615@item show print object
5616Show whether actual, or declared, object types are displayed.
5617
c906108c
SS
5618@item set print static-members
5619@itemx set print static-members on
4644b6e3 5620@cindex static members of C@t{++} objects
b37052ae 5621Print static members when displaying a C@t{++} object. The default is on.
c906108c
SS
5622
5623@item set print static-members off
b37052ae 5624Do not print static members when displaying a C@t{++} object.
c906108c 5625
c906108c 5626@item show print static-members
b37052ae 5627Show whether C@t{++} static members are printed, or not.
c906108c
SS
5628
5629@c These don't work with HP ANSI C++ yet.
c906108c
SS
5630@item set print vtbl
5631@itemx set print vtbl on
4644b6e3 5632@cindex pretty print C@t{++} virtual function tables
b37052ae 5633Pretty print C@t{++} virtual function tables. The default is off.
c906108c 5634(The @code{vtbl} commands do not work on programs compiled with the HP
b37052ae 5635ANSI C@t{++} compiler (@code{aCC}).)
c906108c
SS
5636
5637@item set print vtbl off
b37052ae 5638Do not pretty print C@t{++} virtual function tables.
c906108c 5639
c906108c 5640@item show print vtbl
b37052ae 5641Show whether C@t{++} virtual function tables are pretty printed, or not.
c906108c 5642@end table
c906108c 5643
6d2ebf8b 5644@node Value History
c906108c
SS
5645@section Value history
5646
5647@cindex value history
5d161b24
DB
5648Values printed by the @code{print} command are saved in the @value{GDBN}
5649@dfn{value history}. This allows you to refer to them in other expressions.
5650Values are kept until the symbol table is re-read or discarded
5651(for example with the @code{file} or @code{symbol-file} commands).
5652When the symbol table changes, the value history is discarded,
5653since the values may contain pointers back to the types defined in the
c906108c
SS
5654symbol table.
5655
5656@cindex @code{$}
5657@cindex @code{$$}
5658@cindex history number
5659The values printed are given @dfn{history numbers} by which you can
5660refer to them. These are successive integers starting with one.
5661@code{print} shows you the history number assigned to a value by
5662printing @samp{$@var{num} = } before the value; here @var{num} is the
5663history number.
5664
5665To refer to any previous value, use @samp{$} followed by the value's
5666history number. The way @code{print} labels its output is designed to
5667remind you of this. Just @code{$} refers to the most recent value in
5668the history, and @code{$$} refers to the value before that.
5669@code{$$@var{n}} refers to the @var{n}th value from the end; @code{$$2}
5670is the value just prior to @code{$$}, @code{$$1} is equivalent to
5671@code{$$}, and @code{$$0} is equivalent to @code{$}.
5672
5673For example, suppose you have just printed a pointer to a structure and
5674want to see the contents of the structure. It suffices to type
5675
474c8240 5676@smallexample
c906108c 5677p *$
474c8240 5678@end smallexample
c906108c
SS
5679
5680If you have a chain of structures where the component @code{next} points
5681to the next one, you can print the contents of the next one with this:
5682
474c8240 5683@smallexample
c906108c 5684p *$.next
474c8240 5685@end smallexample
c906108c
SS
5686
5687@noindent
5688You can print successive links in the chain by repeating this
5689command---which you can do by just typing @key{RET}.
5690
5691Note that the history records values, not expressions. If the value of
5692@code{x} is 4 and you type these commands:
5693
474c8240 5694@smallexample
c906108c
SS
5695print x
5696set x=5
474c8240 5697@end smallexample
c906108c
SS
5698
5699@noindent
5700then the value recorded in the value history by the @code{print} command
5701remains 4 even though the value of @code{x} has changed.
5702
5703@table @code
5704@kindex show values
5705@item show values
5706Print the last ten values in the value history, with their item numbers.
5707This is like @samp{p@ $$9} repeated ten times, except that @code{show
5708values} does not change the history.
5709
5710@item show values @var{n}
5711Print ten history values centered on history item number @var{n}.
5712
5713@item show values +
5714Print ten history values just after the values last printed. If no more
5715values are available, @code{show values +} produces no display.
5716@end table
5717
5718Pressing @key{RET} to repeat @code{show values @var{n}} has exactly the
5719same effect as @samp{show values +}.
5720
6d2ebf8b 5721@node Convenience Vars
c906108c
SS
5722@section Convenience variables
5723
5724@cindex convenience variables
5725@value{GDBN} provides @dfn{convenience variables} that you can use within
5726@value{GDBN} to hold on to a value and refer to it later. These variables
5727exist entirely within @value{GDBN}; they are not part of your program, and
5728setting a convenience variable has no direct effect on further execution
5729of your program. That is why you can use them freely.
5730
5731Convenience variables are prefixed with @samp{$}. Any name preceded by
5732@samp{$} can be used for a convenience variable, unless it is one of
d4f3574e 5733the predefined machine-specific register names (@pxref{Registers, ,Registers}).
c906108c
SS
5734(Value history references, in contrast, are @emph{numbers} preceded
5735by @samp{$}. @xref{Value History, ,Value history}.)
5736
5737You can save a value in a convenience variable with an assignment
5738expression, just as you would set a variable in your program.
5739For example:
5740
474c8240 5741@smallexample
c906108c 5742set $foo = *object_ptr
474c8240 5743@end smallexample
c906108c
SS
5744
5745@noindent
5746would save in @code{$foo} the value contained in the object pointed to by
5747@code{object_ptr}.
5748
5749Using a convenience variable for the first time creates it, but its
5750value is @code{void} until you assign a new value. You can alter the
5751value with another assignment at any time.
5752
5753Convenience variables have no fixed types. You can assign a convenience
5754variable any type of value, including structures and arrays, even if
5755that variable already has a value of a different type. The convenience
5756variable, when used as an expression, has the type of its current value.
5757
5758@table @code
5759@kindex show convenience
5760@item show convenience
5761Print a list of convenience variables used so far, and their values.
d4f3574e 5762Abbreviated @code{show conv}.
c906108c
SS
5763@end table
5764
5765One of the ways to use a convenience variable is as a counter to be
5766incremented or a pointer to be advanced. For example, to print
5767a field from successive elements of an array of structures:
5768
474c8240 5769@smallexample
c906108c
SS
5770set $i = 0
5771print bar[$i++]->contents
474c8240 5772@end smallexample
c906108c 5773
d4f3574e
SS
5774@noindent
5775Repeat that command by typing @key{RET}.
c906108c
SS
5776
5777Some convenience variables are created automatically by @value{GDBN} and given
5778values likely to be useful.
5779
5780@table @code
41afff9a 5781@vindex $_@r{, convenience variable}
c906108c
SS
5782@item $_
5783The variable @code{$_} is automatically set by the @code{x} command to
5784the last address examined (@pxref{Memory, ,Examining memory}). Other
5785commands which provide a default address for @code{x} to examine also
5786set @code{$_} to that address; these commands include @code{info line}
5787and @code{info breakpoint}. The type of @code{$_} is @code{void *}
5788except when set by the @code{x} command, in which case it is a pointer
5789to the type of @code{$__}.
5790
41afff9a 5791@vindex $__@r{, convenience variable}
c906108c
SS
5792@item $__
5793The variable @code{$__} is automatically set by the @code{x} command
5794to the value found in the last address examined. Its type is chosen
5795to match the format in which the data was printed.
5796
5797@item $_exitcode
41afff9a 5798@vindex $_exitcode@r{, convenience variable}
c906108c
SS
5799The variable @code{$_exitcode} is automatically set to the exit code when
5800the program being debugged terminates.
5801@end table
5802
53a5351d
JM
5803On HP-UX systems, if you refer to a function or variable name that
5804begins with a dollar sign, @value{GDBN} searches for a user or system
5805name first, before it searches for a convenience variable.
c906108c 5806
6d2ebf8b 5807@node Registers
c906108c
SS
5808@section Registers
5809
5810@cindex registers
5811You can refer to machine register contents, in expressions, as variables
5812with names starting with @samp{$}. The names of registers are different
5813for each machine; use @code{info registers} to see the names used on
5814your machine.
5815
5816@table @code
5817@kindex info registers
5818@item info registers
5819Print the names and values of all registers except floating-point
c85508ee 5820and vector registers (in the selected stack frame).
c906108c
SS
5821
5822@kindex info all-registers
5823@cindex floating point registers
5824@item info all-registers
5825Print the names and values of all registers, including floating-point
c85508ee 5826and vector registers (in the selected stack frame).
c906108c
SS
5827
5828@item info registers @var{regname} @dots{}
5829Print the @dfn{relativized} value of each specified register @var{regname}.
5d161b24
DB
5830As discussed in detail below, register values are normally relative to
5831the selected stack frame. @var{regname} may be any register name valid on
c906108c
SS
5832the machine you are using, with or without the initial @samp{$}.
5833@end table
5834
5835@value{GDBN} has four ``standard'' register names that are available (in
5836expressions) on most machines---whenever they do not conflict with an
5837architecture's canonical mnemonics for registers. The register names
5838@code{$pc} and @code{$sp} are used for the program counter register and
5839the stack pointer. @code{$fp} is used for a register that contains a
5840pointer to the current stack frame, and @code{$ps} is used for a
5841register that contains the processor status. For example,
5842you could print the program counter in hex with
5843
474c8240 5844@smallexample
c906108c 5845p/x $pc
474c8240 5846@end smallexample
c906108c
SS
5847
5848@noindent
5849or print the instruction to be executed next with
5850
474c8240 5851@smallexample
c906108c 5852x/i $pc
474c8240 5853@end smallexample
c906108c
SS
5854
5855@noindent
5856or add four to the stack pointer@footnote{This is a way of removing
5857one word from the stack, on machines where stacks grow downward in
5858memory (most machines, nowadays). This assumes that the innermost
5859stack frame is selected; setting @code{$sp} is not allowed when other
5860stack frames are selected. To pop entire frames off the stack,
5861regardless of machine architecture, use @code{return};
d4f3574e 5862see @ref{Returning, ,Returning from a function}.} with
c906108c 5863
474c8240 5864@smallexample
c906108c 5865set $sp += 4
474c8240 5866@end smallexample
c906108c
SS
5867
5868Whenever possible, these four standard register names are available on
5869your machine even though the machine has different canonical mnemonics,
5870so long as there is no conflict. The @code{info registers} command
5871shows the canonical names. For example, on the SPARC, @code{info
5872registers} displays the processor status register as @code{$psr} but you
d4f3574e
SS
5873can also refer to it as @code{$ps}; and on x86-based machines @code{$ps}
5874is an alias for the @sc{eflags} register.
c906108c
SS
5875
5876@value{GDBN} always considers the contents of an ordinary register as an
5877integer when the register is examined in this way. Some machines have
5878special registers which can hold nothing but floating point; these
5879registers are considered to have floating point values. There is no way
5880to refer to the contents of an ordinary register as floating point value
5881(although you can @emph{print} it as a floating point value with
5882@samp{print/f $@var{regname}}).
5883
5884Some registers have distinct ``raw'' and ``virtual'' data formats. This
5885means that the data format in which the register contents are saved by
5886the operating system is not the same one that your program normally
5887sees. For example, the registers of the 68881 floating point
5888coprocessor are always saved in ``extended'' (raw) format, but all C
5889programs expect to work with ``double'' (virtual) format. In such
5d161b24 5890cases, @value{GDBN} normally works with the virtual format only (the format
c906108c
SS
5891that makes sense for your program), but the @code{info registers} command
5892prints the data in both formats.
5893
5894Normally, register values are relative to the selected stack frame
5895(@pxref{Selection, ,Selecting a frame}). This means that you get the
5896value that the register would contain if all stack frames farther in
5897were exited and their saved registers restored. In order to see the
5898true contents of hardware registers, you must select the innermost
5899frame (with @samp{frame 0}).
5900
5901However, @value{GDBN} must deduce where registers are saved, from the machine
5902code generated by your compiler. If some registers are not saved, or if
5903@value{GDBN} is unable to locate the saved registers, the selected stack
5904frame makes no difference.
5905
6d2ebf8b 5906@node Floating Point Hardware
c906108c
SS
5907@section Floating point hardware
5908@cindex floating point
5909
5910Depending on the configuration, @value{GDBN} may be able to give
5911you more information about the status of the floating point hardware.
5912
5913@table @code
5914@kindex info float
5915@item info float
5916Display hardware-dependent information about the floating
5917point unit. The exact contents and layout vary depending on the
5918floating point chip. Currently, @samp{info float} is supported on
5919the ARM and x86 machines.
5920@end table
c906108c 5921
e76f1f2e
AC
5922@node Vector Unit
5923@section Vector Unit
5924@cindex vector unit
5925
5926Depending on the configuration, @value{GDBN} may be able to give you
5927more information about the status of the vector unit.
5928
5929@table @code
5930@kindex info vector
5931@item info vector
5932Display information about the vector unit. The exact contents and
5933layout vary depending on the hardware.
5934@end table
5935
b383017d
RM
5936@node Auxiliary Vector
5937@section Operating system auxiliary vector
5938@cindex auxiliary vector
5939@cindex vector, auxiliary
5940
5941Some operating systems supply an @dfn{auxiliary vector} to programs at
5942startup. This is akin to the arguments and environment that you
5943specify for a program, but contains a system-dependent variety of
5944binary values that tell system libraries important details about the
5945hardware, operating system, and process. Each value's purpose is
5946identified by an integer tag; the meanings are well-known but system-specific.
5947Depending on the configuration and operating system facilities,
5948@value{GDBN} may be able to show you this information.
5949
5950@table @code
5951@kindex info auxv
5952@item info auxv
5953Display the auxiliary vector of the inferior, which can be either a
e4937fc1 5954live process or a core dump file. @value{GDBN} prints each tag value
b383017d
RM
5955numerically, and also shows names and text descriptions for recognized
5956tags. Some values in the vector are numbers, some bit masks, and some
e4937fc1 5957pointers to strings or other data. @value{GDBN} displays each value in the
b383017d
RM
5958most appropriate form for a recognized tag, and in hexadecimal for
5959an unrecognized tag.
5960@end table
5961
29e57380 5962@node Memory Region Attributes
b383017d 5963@section Memory region attributes
29e57380
C
5964@cindex memory region attributes
5965
b383017d
RM
5966@dfn{Memory region attributes} allow you to describe special handling
5967required by regions of your target's memory. @value{GDBN} uses attributes
29e57380
C
5968to determine whether to allow certain types of memory accesses; whether to
5969use specific width accesses; and whether to cache target memory.
5970
5971Defined memory regions can be individually enabled and disabled. When a
5972memory region is disabled, @value{GDBN} uses the default attributes when
5973accessing memory in that region. Similarly, if no memory regions have
5974been defined, @value{GDBN} uses the default attributes when accessing
5975all memory.
5976
b383017d 5977When a memory region is defined, it is given a number to identify it;
29e57380
C
5978to enable, disable, or remove a memory region, you specify that number.
5979
5980@table @code
5981@kindex mem
bfac230e
DH
5982@item mem @var{lower} @var{upper} @var{attributes}@dots{}
5983Define memory region bounded by @var{lower} and @var{upper} with
5984attributes @var{attributes}@dots{}. Note that @var{upper} == 0 is a
5985special case: it is treated as the the target's maximum memory address.
5986(0xffff on 16 bit targets, 0xffffffff on 32 bit targets, etc.)
29e57380
C
5987
5988@kindex delete mem
5989@item delete mem @var{nums}@dots{}
59649f2e 5990Remove memory regions @var{nums}@dots{}.
29e57380
C
5991
5992@kindex disable mem
5993@item disable mem @var{nums}@dots{}
59649f2e 5994Disable memory regions @var{nums}@dots{}.
b383017d 5995A disabled memory region is not forgotten.
29e57380
C
5996It may be enabled again later.
5997
5998@kindex enable mem
5999@item enable mem @var{nums}@dots{}
59649f2e 6000Enable memory regions @var{nums}@dots{}.
29e57380
C
6001
6002@kindex info mem
6003@item info mem
6004Print a table of all defined memory regions, with the following columns
6005for each region.
6006
6007@table @emph
6008@item Memory Region Number
6009@item Enabled or Disabled.
b383017d 6010Enabled memory regions are marked with @samp{y}.
29e57380
C
6011Disabled memory regions are marked with @samp{n}.
6012
6013@item Lo Address
6014The address defining the inclusive lower bound of the memory region.
6015
6016@item Hi Address
6017The address defining the exclusive upper bound of the memory region.
6018
6019@item Attributes
6020The list of attributes set for this memory region.
6021@end table
6022@end table
6023
6024
6025@subsection Attributes
6026
b383017d 6027@subsubsection Memory Access Mode
29e57380
C
6028The access mode attributes set whether @value{GDBN} may make read or
6029write accesses to a memory region.
6030
6031While these attributes prevent @value{GDBN} from performing invalid
6032memory accesses, they do nothing to prevent the target system, I/O DMA,
6033etc. from accessing memory.
6034
6035@table @code
6036@item ro
6037Memory is read only.
6038@item wo
6039Memory is write only.
6040@item rw
6ca652b0 6041Memory is read/write. This is the default.
29e57380
C
6042@end table
6043
6044@subsubsection Memory Access Size
6045The acccess size attributes tells @value{GDBN} to use specific sized
6046accesses in the memory region. Often memory mapped device registers
6047require specific sized accesses. If no access size attribute is
6048specified, @value{GDBN} may use accesses of any size.
6049
6050@table @code
6051@item 8
6052Use 8 bit memory accesses.
6053@item 16
6054Use 16 bit memory accesses.
6055@item 32
6056Use 32 bit memory accesses.
6057@item 64
6058Use 64 bit memory accesses.
6059@end table
6060
6061@c @subsubsection Hardware/Software Breakpoints
6062@c The hardware/software breakpoint attributes set whether @value{GDBN}
6063@c will use hardware or software breakpoints for the internal breakpoints
6064@c used by the step, next, finish, until, etc. commands.
6065@c
6066@c @table @code
6067@c @item hwbreak
b383017d 6068@c Always use hardware breakpoints
29e57380
C
6069@c @item swbreak (default)
6070@c @end table
6071
6072@subsubsection Data Cache
6073The data cache attributes set whether @value{GDBN} will cache target
6074memory. While this generally improves performance by reducing debug
6075protocol overhead, it can lead to incorrect results because @value{GDBN}
6076does not know about volatile variables or memory mapped device
6077registers.
6078
6079@table @code
6080@item cache
b383017d 6081Enable @value{GDBN} to cache target memory.
6ca652b0
EZ
6082@item nocache
6083Disable @value{GDBN} from caching target memory. This is the default.
29e57380
C
6084@end table
6085
6086@c @subsubsection Memory Write Verification
b383017d 6087@c The memory write verification attributes set whether @value{GDBN}
29e57380
C
6088@c will re-reads data after each write to verify the write was successful.
6089@c
6090@c @table @code
6091@c @item verify
6092@c @item noverify (default)
6093@c @end table
6094
16d9dec6
MS
6095@node Dump/Restore Files
6096@section Copy between memory and a file
6097@cindex dump/restore files
6098@cindex append data to a file
6099@cindex dump data to a file
6100@cindex restore data from a file
16d9dec6 6101
df5215a6
JB
6102You can use the commands @code{dump}, @code{append}, and
6103@code{restore} to copy data between target memory and a file. The
6104@code{dump} and @code{append} commands write data to a file, and the
6105@code{restore} command reads data from a file back into the inferior's
6106memory. Files may be in binary, Motorola S-record, Intel hex, or
6107Tektronix Hex format; however, @value{GDBN} can only append to binary
6108files.
6109
6110@table @code
6111
6112@kindex dump
6113@item dump @r{[}@var{format}@r{]} memory @var{filename} @var{start_addr} @var{end_addr}
6114@itemx dump @r{[}@var{format}@r{]} value @var{filename} @var{expr}
6115Dump the contents of memory from @var{start_addr} to @var{end_addr},
6116or the value of @var{expr}, to @var{filename} in the given format.
16d9dec6 6117
df5215a6 6118The @var{format} parameter may be any one of:
16d9dec6 6119@table @code
df5215a6
JB
6120@item binary
6121Raw binary form.
6122@item ihex
6123Intel hex format.
6124@item srec
6125Motorola S-record format.
6126@item tekhex
6127Tektronix Hex format.
6128@end table
6129
6130@value{GDBN} uses the same definitions of these formats as the
6131@sc{gnu} binary utilities, like @samp{objdump} and @samp{objcopy}. If
6132@var{format} is omitted, @value{GDBN} dumps the data in raw binary
6133form.
6134
6135@kindex append
6136@item append @r{[}binary@r{]} memory @var{filename} @var{start_addr} @var{end_addr}
6137@itemx append @r{[}binary@r{]} value @var{filename} @var{expr}
6138Append the contents of memory from @var{start_addr} to @var{end_addr},
6139or the value of @var{expr}, to @var{filename}, in raw binary form.
6140(@value{GDBN} can only append data to files in raw binary form.)
6141
6142@kindex restore
6143@item restore @var{filename} @r{[}binary@r{]} @var{bias} @var{start} @var{end}
6144Restore the contents of file @var{filename} into memory. The
6145@code{restore} command can automatically recognize any known @sc{bfd}
6146file format, except for raw binary. To restore a raw binary file you
6147must specify the optional keyword @code{binary} after the filename.
16d9dec6 6148
b383017d 6149If @var{bias} is non-zero, its value will be added to the addresses
16d9dec6
MS
6150contained in the file. Binary files always start at address zero, so
6151they will be restored at address @var{bias}. Other bfd files have
6152a built-in location; they will be restored at offset @var{bias}
6153from that location.
6154
6155If @var{start} and/or @var{end} are non-zero, then only data between
6156file offset @var{start} and file offset @var{end} will be restored.
b383017d 6157These offsets are relative to the addresses in the file, before
16d9dec6
MS
6158the @var{bias} argument is applied.
6159
6160@end table
6161
a0eb71c5
KB
6162@node Character Sets
6163@section Character Sets
6164@cindex character sets
6165@cindex charset
6166@cindex translating between character sets
6167@cindex host character set
6168@cindex target character set
6169
6170If the program you are debugging uses a different character set to
6171represent characters and strings than the one @value{GDBN} uses itself,
6172@value{GDBN} can automatically translate between the character sets for
6173you. The character set @value{GDBN} uses we call the @dfn{host
6174character set}; the one the inferior program uses we call the
6175@dfn{target character set}.
6176
6177For example, if you are running @value{GDBN} on a @sc{gnu}/Linux system, which
6178uses the ISO Latin 1 character set, but you are using @value{GDBN}'s
6179remote protocol (@pxref{Remote,Remote Debugging}) to debug a program
6180running on an IBM mainframe, which uses the @sc{ebcdic} character set,
6181then the host character set is Latin-1, and the target character set is
6182@sc{ebcdic}. If you give @value{GDBN} the command @code{set
e33d66ec 6183target-charset EBCDIC-US}, then @value{GDBN} translates between
a0eb71c5
KB
6184@sc{ebcdic} and Latin 1 as you print character or string values, or use
6185character and string literals in expressions.
6186
6187@value{GDBN} has no way to automatically recognize which character set
6188the inferior program uses; you must tell it, using the @code{set
6189target-charset} command, described below.
6190
6191Here are the commands for controlling @value{GDBN}'s character set
6192support:
6193
6194@table @code
6195@item set target-charset @var{charset}
6196@kindex set target-charset
6197Set the current target character set to @var{charset}. We list the
e33d66ec
EZ
6198character set names @value{GDBN} recognizes below, but if you type
6199@code{set target-charset} followed by @key{TAB}@key{TAB}, @value{GDBN} will
6200list the target character sets it supports.
a0eb71c5
KB
6201@end table
6202
6203@table @code
6204@item set host-charset @var{charset}
6205@kindex set host-charset
6206Set the current host character set to @var{charset}.
6207
6208By default, @value{GDBN} uses a host character set appropriate to the
6209system it is running on; you can override that default using the
6210@code{set host-charset} command.
6211
6212@value{GDBN} can only use certain character sets as its host character
6213set. We list the character set names @value{GDBN} recognizes below, and
e33d66ec
EZ
6214indicate which can be host character sets, but if you type
6215@code{set target-charset} followed by @key{TAB}@key{TAB}, @value{GDBN} will
6216list the host character sets it supports.
a0eb71c5
KB
6217
6218@item set charset @var{charset}
6219@kindex set charset
e33d66ec
EZ
6220Set the current host and target character sets to @var{charset}. As
6221above, if you type @code{set charset} followed by @key{TAB}@key{TAB},
6222@value{GDBN} will list the name of the character sets that can be used
6223for both host and target.
6224
a0eb71c5
KB
6225
6226@item show charset
a0eb71c5 6227@kindex show charset
b383017d 6228Show the names of the current host and target charsets.
e33d66ec
EZ
6229
6230@itemx show host-charset
a0eb71c5 6231@kindex show host-charset
b383017d 6232Show the name of the current host charset.
e33d66ec
EZ
6233
6234@itemx show target-charset
a0eb71c5 6235@kindex show target-charset
b383017d 6236Show the name of the current target charset.
a0eb71c5
KB
6237
6238@end table
6239
6240@value{GDBN} currently includes support for the following character
6241sets:
6242
6243@table @code
6244
6245@item ASCII
6246@cindex ASCII character set
6247Seven-bit U.S. @sc{ascii}. @value{GDBN} can use this as its host
6248character set.
6249
6250@item ISO-8859-1
6251@cindex ISO 8859-1 character set
6252@cindex ISO Latin 1 character set
e33d66ec 6253The ISO Latin 1 character set. This extends @sc{ascii} with accented
a0eb71c5
KB
6254characters needed for French, German, and Spanish. @value{GDBN} can use
6255this as its host character set.
6256
6257@item EBCDIC-US
6258@itemx IBM1047
6259@cindex EBCDIC character set
6260@cindex IBM1047 character set
6261Variants of the @sc{ebcdic} character set, used on some of IBM's
6262mainframe operating systems. (@sc{gnu}/Linux on the S/390 uses U.S. @sc{ascii}.)
6263@value{GDBN} cannot use these as its host character set.
6264
6265@end table
6266
6267Note that these are all single-byte character sets. More work inside
6268GDB is needed to support multi-byte or variable-width character
6269encodings, like the UTF-8 and UCS-2 encodings of Unicode.
6270
6271Here is an example of @value{GDBN}'s character set support in action.
6272Assume that the following source code has been placed in the file
6273@file{charset-test.c}:
6274
6275@smallexample
6276#include <stdio.h>
6277
6278char ascii_hello[]
6279 = @{72, 101, 108, 108, 111, 44, 32, 119,
6280 111, 114, 108, 100, 33, 10, 0@};
6281char ibm1047_hello[]
6282 = @{200, 133, 147, 147, 150, 107, 64, 166,
6283 150, 153, 147, 132, 90, 37, 0@};
6284
6285main ()
6286@{
6287 printf ("Hello, world!\n");
6288@}
10998722 6289@end smallexample
a0eb71c5
KB
6290
6291In this program, @code{ascii_hello} and @code{ibm1047_hello} are arrays
6292containing the string @samp{Hello, world!} followed by a newline,
6293encoded in the @sc{ascii} and @sc{ibm1047} character sets.
6294
6295We compile the program, and invoke the debugger on it:
6296
6297@smallexample
6298$ gcc -g charset-test.c -o charset-test
6299$ gdb -nw charset-test
6300GNU gdb 2001-12-19-cvs
6301Copyright 2001 Free Software Foundation, Inc.
6302@dots{}
b383017d 6303(gdb)
10998722 6304@end smallexample
a0eb71c5
KB
6305
6306We can use the @code{show charset} command to see what character sets
6307@value{GDBN} is currently using to interpret and display characters and
6308strings:
6309
6310@smallexample
6311(gdb) show charset
e33d66ec 6312The current host and target character set is `ISO-8859-1'.
b383017d 6313(gdb)
10998722 6314@end smallexample
a0eb71c5
KB
6315
6316For the sake of printing this manual, let's use @sc{ascii} as our
6317initial character set:
6318@smallexample
e33d66ec 6319(gdb) set charset ASCII
a0eb71c5 6320(gdb) show charset
e33d66ec 6321The current host and target character set is `ASCII'.
b383017d 6322(gdb)
10998722 6323@end smallexample
a0eb71c5
KB
6324
6325Let's assume that @sc{ascii} is indeed the correct character set for our
6326host system --- in other words, let's assume that if @value{GDBN} prints
6327characters using the @sc{ascii} character set, our terminal will display
6328them properly. Since our current target character set is also
6329@sc{ascii}, the contents of @code{ascii_hello} print legibly:
6330
6331@smallexample
6332(gdb) print ascii_hello
6333$1 = 0x401698 "Hello, world!\n"
6334(gdb) print ascii_hello[0]
6335$2 = 72 'H'
b383017d 6336(gdb)
10998722 6337@end smallexample
a0eb71c5
KB
6338
6339@value{GDBN} uses the target character set for character and string
6340literals you use in expressions:
6341
6342@smallexample
6343(gdb) print '+'
6344$3 = 43 '+'
b383017d 6345(gdb)
10998722 6346@end smallexample
a0eb71c5
KB
6347
6348The @sc{ascii} character set uses the number 43 to encode the @samp{+}
6349character.
6350
6351@value{GDBN} relies on the user to tell it which character set the
6352target program uses. If we print @code{ibm1047_hello} while our target
6353character set is still @sc{ascii}, we get jibberish:
6354
6355@smallexample
6356(gdb) print ibm1047_hello
6357$4 = 0x4016a8 "\310\205\223\223\226k@@\246\226\231\223\204Z%"
6358(gdb) print ibm1047_hello[0]
6359$5 = 200 '\310'
b383017d 6360(gdb)
10998722 6361@end smallexample
a0eb71c5 6362
e33d66ec 6363If we invoke the @code{set target-charset} followed by @key{TAB}@key{TAB},
a0eb71c5
KB
6364@value{GDBN} tells us the character sets it supports:
6365
6366@smallexample
6367(gdb) set target-charset
b383017d
RM
6368ASCII EBCDIC-US IBM1047 ISO-8859-1
6369(gdb) set target-charset
10998722 6370@end smallexample
a0eb71c5
KB
6371
6372We can select @sc{ibm1047} as our target character set, and examine the
6373program's strings again. Now the @sc{ascii} string is wrong, but
6374@value{GDBN} translates the contents of @code{ibm1047_hello} from the
6375target character set, @sc{ibm1047}, to the host character set,
6376@sc{ascii}, and they display correctly:
6377
6378@smallexample
e33d66ec 6379(gdb) set target-charset IBM1047
a0eb71c5 6380(gdb) show charset
e33d66ec
EZ
6381The current host character set is `ASCII'.
6382The current target character set is `IBM1047'.
a0eb71c5
KB
6383(gdb) print ascii_hello
6384$6 = 0x401698 "\110\145%%?\054\040\167?\162%\144\041\012"
6385(gdb) print ascii_hello[0]
6386$7 = 72 '\110'
6387(gdb) print ibm1047_hello
6388$8 = 0x4016a8 "Hello, world!\n"
6389(gdb) print ibm1047_hello[0]
6390$9 = 200 'H'
6391(gdb)
10998722 6392@end smallexample
a0eb71c5
KB
6393
6394As above, @value{GDBN} uses the target character set for character and
6395string literals you use in expressions:
6396
6397@smallexample
6398(gdb) print '+'
6399$10 = 78 '+'
b383017d 6400(gdb)
10998722 6401@end smallexample
a0eb71c5 6402
e33d66ec 6403The @sc{ibm1047} character set uses the number 78 to encode the @samp{+}
a0eb71c5
KB
6404character.
6405
6406
e2e0bcd1
JB
6407@node Macros
6408@chapter C Preprocessor Macros
6409
49efadf5 6410Some languages, such as C and C@t{++}, provide a way to define and invoke
e2e0bcd1
JB
6411``preprocessor macros'' which expand into strings of tokens.
6412@value{GDBN} can evaluate expressions containing macro invocations, show
6413the result of macro expansion, and show a macro's definition, including
6414where it was defined.
6415
6416You may need to compile your program specially to provide @value{GDBN}
6417with information about preprocessor macros. Most compilers do not
6418include macros in their debugging information, even when you compile
6419with the @option{-g} flag. @xref{Compilation}.
6420
6421A program may define a macro at one point, remove that definition later,
6422and then provide a different definition after that. Thus, at different
6423points in the program, a macro may have different definitions, or have
6424no definition at all. If there is a current stack frame, @value{GDBN}
6425uses the macros in scope at that frame's source code line. Otherwise,
6426@value{GDBN} uses the macros in scope at the current listing location;
6427see @ref{List}.
6428
6429At the moment, @value{GDBN} does not support the @code{##}
6430token-splicing operator, the @code{#} stringification operator, or
6431variable-arity macros.
6432
6433Whenever @value{GDBN} evaluates an expression, it always expands any
6434macro invocations present in the expression. @value{GDBN} also provides
6435the following commands for working with macros explicitly.
6436
6437@table @code
6438
6439@kindex macro expand
6440@cindex macro expansion, showing the results of preprocessor
6441@cindex preprocessor macro expansion, showing the results of
6442@cindex expanding preprocessor macros
6443@item macro expand @var{expression}
6444@itemx macro exp @var{expression}
6445Show the results of expanding all preprocessor macro invocations in
6446@var{expression}. Since @value{GDBN} simply expands macros, but does
6447not parse the result, @var{expression} need not be a valid expression;
6448it can be any string of tokens.
6449
e2e0bcd1
JB
6450@item macro expand-once @var{expression}
6451@itemx macro exp1 @var{expression}
4644b6e3 6452@cindex expand macro once
e2e0bcd1
JB
6453@i{(This command is not yet implemented.)} Show the results of
6454expanding those preprocessor macro invocations that appear explicitly in
6455@var{expression}. Macro invocations appearing in that expansion are
6456left unchanged. This command allows you to see the effect of a
6457particular macro more clearly, without being confused by further
6458expansions. Since @value{GDBN} simply expands macros, but does not
6459parse the result, @var{expression} need not be a valid expression; it
6460can be any string of tokens.
6461
475b0867 6462@kindex info macro
e2e0bcd1
JB
6463@cindex macro definition, showing
6464@cindex definition, showing a macro's
475b0867 6465@item info macro @var{macro}
e2e0bcd1
JB
6466Show the definition of the macro named @var{macro}, and describe the
6467source location where that definition was established.
6468
6469@kindex macro define
6470@cindex user-defined macros
6471@cindex defining macros interactively
6472@cindex macros, user-defined
6473@item macro define @var{macro} @var{replacement-list}
6474@itemx macro define @var{macro}(@var{arglist}) @var{replacement-list}
6475@i{(This command is not yet implemented.)} Introduce a definition for a
6476preprocessor macro named @var{macro}, invocations of which are replaced
6477by the tokens given in @var{replacement-list}. The first form of this
6478command defines an ``object-like'' macro, which takes no arguments; the
6479second form defines a ``function-like'' macro, which takes the arguments
6480given in @var{arglist}.
6481
6482A definition introduced by this command is in scope in every expression
6483evaluated in @value{GDBN}, until it is removed with the @command{macro
6484undef} command, described below. The definition overrides all
6485definitions for @var{macro} present in the program being debugged, as
6486well as any previous user-supplied definition.
6487
6488@kindex macro undef
6489@item macro undef @var{macro}
6490@i{(This command is not yet implemented.)} Remove any user-supplied
6491definition for the macro named @var{macro}. This command only affects
6492definitions provided with the @command{macro define} command, described
6493above; it cannot remove definitions present in the program being
6494debugged.
6495
6496@end table
6497
6498@cindex macros, example of debugging with
6499Here is a transcript showing the above commands in action. First, we
6500show our source files:
6501
6502@smallexample
6503$ cat sample.c
6504#include <stdio.h>
6505#include "sample.h"
6506
6507#define M 42
6508#define ADD(x) (M + x)
6509
6510main ()
6511@{
6512#define N 28
6513 printf ("Hello, world!\n");
6514#undef N
6515 printf ("We're so creative.\n");
6516#define N 1729
6517 printf ("Goodbye, world!\n");
6518@}
6519$ cat sample.h
6520#define Q <
6521$
6522@end smallexample
6523
6524Now, we compile the program using the @sc{gnu} C compiler, @value{NGCC}.
6525We pass the @option{-gdwarf-2} and @option{-g3} flags to ensure the
6526compiler includes information about preprocessor macros in the debugging
6527information.
6528
6529@smallexample
6530$ gcc -gdwarf-2 -g3 sample.c -o sample
6531$
6532@end smallexample
6533
6534Now, we start @value{GDBN} on our sample program:
6535
6536@smallexample
6537$ gdb -nw sample
6538GNU gdb 2002-05-06-cvs
6539Copyright 2002 Free Software Foundation, Inc.
6540GDB is free software, @dots{}
6541(gdb)
6542@end smallexample
6543
6544We can expand macros and examine their definitions, even when the
6545program is not running. @value{GDBN} uses the current listing position
6546to decide which macro definitions are in scope:
6547
6548@smallexample
6549(gdb) list main
65503
65514 #define M 42
65525 #define ADD(x) (M + x)
65536
65547 main ()
65558 @{
65569 #define N 28
655710 printf ("Hello, world!\n");
655811 #undef N
655912 printf ("We're so creative.\n");
475b0867 6560(gdb) info macro ADD
e2e0bcd1
JB
6561Defined at /home/jimb/gdb/macros/play/sample.c:5
6562#define ADD(x) (M + x)
475b0867 6563(gdb) info macro Q
e2e0bcd1
JB
6564Defined at /home/jimb/gdb/macros/play/sample.h:1
6565 included at /home/jimb/gdb/macros/play/sample.c:2
6566#define Q <
6567(gdb) macro expand ADD(1)
6568expands to: (42 + 1)
6569(gdb) macro expand-once ADD(1)
6570expands to: once (M + 1)
b383017d 6571(gdb)
e2e0bcd1
JB
6572@end smallexample
6573
6574In the example above, note that @command{macro expand-once} expands only
6575the macro invocation explicit in the original text --- the invocation of
6576@code{ADD} --- but does not expand the invocation of the macro @code{M},
6577which was introduced by @code{ADD}.
6578
6579Once the program is running, GDB uses the macro definitions in force at
6580the source line of the current stack frame:
6581
6582@smallexample
6583(gdb) break main
6584Breakpoint 1 at 0x8048370: file sample.c, line 10.
6585(gdb) run
b383017d 6586Starting program: /home/jimb/gdb/macros/play/sample
e2e0bcd1
JB
6587
6588Breakpoint 1, main () at sample.c:10
658910 printf ("Hello, world!\n");
b383017d 6590(gdb)
e2e0bcd1
JB
6591@end smallexample
6592
6593At line 10, the definition of the macro @code{N} at line 9 is in force:
6594
6595@smallexample
475b0867 6596(gdb) info macro N
e2e0bcd1
JB
6597Defined at /home/jimb/gdb/macros/play/sample.c:9
6598#define N 28
6599(gdb) macro expand N Q M
6600expands to: 28 < 42
6601(gdb) print N Q M
6602$1 = 1
b383017d 6603(gdb)
e2e0bcd1
JB
6604@end smallexample
6605
6606As we step over directives that remove @code{N}'s definition, and then
6607give it a new definition, @value{GDBN} finds the definition (or lack
6608thereof) in force at each point:
6609
6610@smallexample
6611(gdb) next
6612Hello, world!
661312 printf ("We're so creative.\n");
475b0867 6614(gdb) info macro N
e2e0bcd1
JB
6615The symbol `N' has no definition as a C/C++ preprocessor macro
6616at /home/jimb/gdb/macros/play/sample.c:12
6617(gdb) next
6618We're so creative.
661914 printf ("Goodbye, world!\n");
475b0867 6620(gdb) info macro N
e2e0bcd1
JB
6621Defined at /home/jimb/gdb/macros/play/sample.c:13
6622#define N 1729
6623(gdb) macro expand N Q M
6624expands to: 1729 < 42
6625(gdb) print N Q M
6626$2 = 0
b383017d 6627(gdb)
e2e0bcd1
JB
6628@end smallexample
6629
6630
b37052ae
EZ
6631@node Tracepoints
6632@chapter Tracepoints
6633@c This chapter is based on the documentation written by Michael
6634@c Snyder, David Taylor, Jim Blandy, and Elena Zannoni.
6635
6636@cindex tracepoints
6637In some applications, it is not feasible for the debugger to interrupt
6638the program's execution long enough for the developer to learn
6639anything helpful about its behavior. If the program's correctness
6640depends on its real-time behavior, delays introduced by a debugger
6641might cause the program to change its behavior drastically, or perhaps
6642fail, even when the code itself is correct. It is useful to be able
6643to observe the program's behavior without interrupting it.
6644
6645Using @value{GDBN}'s @code{trace} and @code{collect} commands, you can
6646specify locations in the program, called @dfn{tracepoints}, and
6647arbitrary expressions to evaluate when those tracepoints are reached.
6648Later, using the @code{tfind} command, you can examine the values
6649those expressions had when the program hit the tracepoints. The
6650expressions may also denote objects in memory---structures or arrays,
6651for example---whose values @value{GDBN} should record; while visiting
6652a particular tracepoint, you may inspect those objects as if they were
6653in memory at that moment. However, because @value{GDBN} records these
6654values without interacting with you, it can do so quickly and
6655unobtrusively, hopefully not disturbing the program's behavior.
6656
6657The tracepoint facility is currently available only for remote
2c0069bb
EZ
6658targets. @xref{Targets}. In addition, your remote target must know how
6659to collect trace data. This functionality is implemented in the remote
6660stub; however, none of the stubs distributed with @value{GDBN} support
6661tracepoints as of this writing.
b37052ae
EZ
6662
6663This chapter describes the tracepoint commands and features.
6664
6665@menu
b383017d
RM
6666* Set Tracepoints::
6667* Analyze Collected Data::
6668* Tracepoint Variables::
b37052ae
EZ
6669@end menu
6670
6671@node Set Tracepoints
6672@section Commands to Set Tracepoints
6673
6674Before running such a @dfn{trace experiment}, an arbitrary number of
6675tracepoints can be set. Like a breakpoint (@pxref{Set Breaks}), a
6676tracepoint has a number assigned to it by @value{GDBN}. Like with
6677breakpoints, tracepoint numbers are successive integers starting from
6678one. Many of the commands associated with tracepoints take the
6679tracepoint number as their argument, to identify which tracepoint to
6680work on.
6681
6682For each tracepoint, you can specify, in advance, some arbitrary set
6683of data that you want the target to collect in the trace buffer when
6684it hits that tracepoint. The collected data can include registers,
6685local variables, or global data. Later, you can use @value{GDBN}
6686commands to examine the values these data had at the time the
6687tracepoint was hit.
6688
6689This section describes commands to set tracepoints and associated
6690conditions and actions.
6691
6692@menu
b383017d
RM
6693* Create and Delete Tracepoints::
6694* Enable and Disable Tracepoints::
6695* Tracepoint Passcounts::
6696* Tracepoint Actions::
6697* Listing Tracepoints::
6698* Starting and Stopping Trace Experiment::
b37052ae
EZ
6699@end menu
6700
6701@node Create and Delete Tracepoints
6702@subsection Create and Delete Tracepoints
6703
6704@table @code
6705@cindex set tracepoint
6706@kindex trace
6707@item trace
6708The @code{trace} command is very similar to the @code{break} command.
6709Its argument can be a source line, a function name, or an address in
6710the target program. @xref{Set Breaks}. The @code{trace} command
6711defines a tracepoint, which is a point in the target program where the
6712debugger will briefly stop, collect some data, and then allow the
6713program to continue. Setting a tracepoint or changing its commands
6714doesn't take effect until the next @code{tstart} command; thus, you
6715cannot change the tracepoint attributes once a trace experiment is
6716running.
6717
6718Here are some examples of using the @code{trace} command:
6719
6720@smallexample
6721(@value{GDBP}) @b{trace foo.c:121} // a source file and line number
6722
6723(@value{GDBP}) @b{trace +2} // 2 lines forward
6724
6725(@value{GDBP}) @b{trace my_function} // first source line of function
6726
6727(@value{GDBP}) @b{trace *my_function} // EXACT start address of function
6728
6729(@value{GDBP}) @b{trace *0x2117c4} // an address
6730@end smallexample
6731
6732@noindent
6733You can abbreviate @code{trace} as @code{tr}.
6734
6735@vindex $tpnum
6736@cindex last tracepoint number
6737@cindex recent tracepoint number
6738@cindex tracepoint number
6739The convenience variable @code{$tpnum} records the tracepoint number
6740of the most recently set tracepoint.
6741
6742@kindex delete tracepoint
6743@cindex tracepoint deletion
6744@item delete tracepoint @r{[}@var{num}@r{]}
6745Permanently delete one or more tracepoints. With no argument, the
6746default is to delete all tracepoints.
6747
6748Examples:
6749
6750@smallexample
6751(@value{GDBP}) @b{delete trace 1 2 3} // remove three tracepoints
6752
6753(@value{GDBP}) @b{delete trace} // remove all tracepoints
6754@end smallexample
6755
6756@noindent
6757You can abbreviate this command as @code{del tr}.
6758@end table
6759
6760@node Enable and Disable Tracepoints
6761@subsection Enable and Disable Tracepoints
6762
6763@table @code
6764@kindex disable tracepoint
6765@item disable tracepoint @r{[}@var{num}@r{]}
6766Disable tracepoint @var{num}, or all tracepoints if no argument
6767@var{num} is given. A disabled tracepoint will have no effect during
6768the next trace experiment, but it is not forgotten. You can re-enable
6769a disabled tracepoint using the @code{enable tracepoint} command.
6770
6771@kindex enable tracepoint
6772@item enable tracepoint @r{[}@var{num}@r{]}
6773Enable tracepoint @var{num}, or all tracepoints. The enabled
6774tracepoints will become effective the next time a trace experiment is
6775run.
6776@end table
6777
6778@node Tracepoint Passcounts
6779@subsection Tracepoint Passcounts
6780
6781@table @code
6782@kindex passcount
6783@cindex tracepoint pass count
6784@item passcount @r{[}@var{n} @r{[}@var{num}@r{]]}
6785Set the @dfn{passcount} of a tracepoint. The passcount is a way to
6786automatically stop a trace experiment. If a tracepoint's passcount is
6787@var{n}, then the trace experiment will be automatically stopped on
6788the @var{n}'th time that tracepoint is hit. If the tracepoint number
6789@var{num} is not specified, the @code{passcount} command sets the
6790passcount of the most recently defined tracepoint. If no passcount is
6791given, the trace experiment will run until stopped explicitly by the
6792user.
6793
6794Examples:
6795
6796@smallexample
b383017d 6797(@value{GDBP}) @b{passcount 5 2} // Stop on the 5th execution of
6826cf00 6798@exdent @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @code{// tracepoint 2}
b37052ae
EZ
6799
6800(@value{GDBP}) @b{passcount 12} // Stop on the 12th execution of the
6826cf00 6801@exdent @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @code{// most recently defined tracepoint.}
b37052ae
EZ
6802(@value{GDBP}) @b{trace foo}
6803(@value{GDBP}) @b{pass 3}
6804(@value{GDBP}) @b{trace bar}
6805(@value{GDBP}) @b{pass 2}
6806(@value{GDBP}) @b{trace baz}
6807(@value{GDBP}) @b{pass 1} // Stop tracing when foo has been
6826cf00
EZ
6808@exdent @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @code{// executed 3 times OR when bar has}
6809@exdent @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @code{// been executed 2 times}
6810@exdent @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @code{// OR when baz has been executed 1 time.}
b37052ae
EZ
6811@end smallexample
6812@end table
6813
6814@node Tracepoint Actions
6815@subsection Tracepoint Action Lists
6816
6817@table @code
6818@kindex actions
6819@cindex tracepoint actions
6820@item actions @r{[}@var{num}@r{]}
6821This command will prompt for a list of actions to be taken when the
6822tracepoint is hit. If the tracepoint number @var{num} is not
6823specified, this command sets the actions for the one that was most
6824recently defined (so that you can define a tracepoint and then say
6825@code{actions} without bothering about its number). You specify the
6826actions themselves on the following lines, one action at a time, and
6827terminate the actions list with a line containing just @code{end}. So
6828far, the only defined actions are @code{collect} and
6829@code{while-stepping}.
6830
6831@cindex remove actions from a tracepoint
6832To remove all actions from a tracepoint, type @samp{actions @var{num}}
6833and follow it immediately with @samp{end}.
6834
6835@smallexample
6836(@value{GDBP}) @b{collect @var{data}} // collect some data
6837
6826cf00 6838(@value{GDBP}) @b{while-stepping 5} // single-step 5 times, collect data
b37052ae 6839
6826cf00 6840(@value{GDBP}) @b{end} // signals the end of actions.
b37052ae
EZ
6841@end smallexample
6842
6843In the following example, the action list begins with @code{collect}
6844commands indicating the things to be collected when the tracepoint is
6845hit. Then, in order to single-step and collect additional data
6846following the tracepoint, a @code{while-stepping} command is used,
6847followed by the list of things to be collected while stepping. The
6848@code{while-stepping} command is terminated by its own separate
6849@code{end} command. Lastly, the action list is terminated by an
6850@code{end} command.
6851
6852@smallexample
6853(@value{GDBP}) @b{trace foo}
6854(@value{GDBP}) @b{actions}
6855Enter actions for tracepoint 1, one per line:
6856> collect bar,baz
6857> collect $regs
6858> while-stepping 12
6859 > collect $fp, $sp
6860 > end
6861end
6862@end smallexample
6863
6864@kindex collect @r{(tracepoints)}
6865@item collect @var{expr1}, @var{expr2}, @dots{}
6866Collect values of the given expressions when the tracepoint is hit.
6867This command accepts a comma-separated list of any valid expressions.
6868In addition to global, static, or local variables, the following
6869special arguments are supported:
6870
6871@table @code
6872@item $regs
6873collect all registers
6874
6875@item $args
6876collect all function arguments
6877
6878@item $locals
6879collect all local variables.
6880@end table
6881
6882You can give several consecutive @code{collect} commands, each one
6883with a single argument, or one @code{collect} command with several
6884arguments separated by commas: the effect is the same.
6885
f5c37c66
EZ
6886The command @code{info scope} (@pxref{Symbols, info scope}) is
6887particularly useful for figuring out what data to collect.
6888
b37052ae
EZ
6889@kindex while-stepping @r{(tracepoints)}
6890@item while-stepping @var{n}
6891Perform @var{n} single-step traces after the tracepoint, collecting
6892new data at each step. The @code{while-stepping} command is
6893followed by the list of what to collect while stepping (followed by
6894its own @code{end} command):
6895
6896@smallexample
6897> while-stepping 12
6898 > collect $regs, myglobal
6899 > end
6900>
6901@end smallexample
6902
6903@noindent
6904You may abbreviate @code{while-stepping} as @code{ws} or
6905@code{stepping}.
6906@end table
6907
6908@node Listing Tracepoints
6909@subsection Listing Tracepoints
6910
6911@table @code
6912@kindex info tracepoints
6913@cindex information about tracepoints
6914@item info tracepoints @r{[}@var{num}@r{]}
8a037dd7 6915Display information about the tracepoint @var{num}. If you don't specify
798c8bc6 6916a tracepoint number, displays information about all the tracepoints
b37052ae
EZ
6917defined so far. For each tracepoint, the following information is
6918shown:
6919
6920@itemize @bullet
6921@item
6922its number
6923@item
6924whether it is enabled or disabled
6925@item
6926its address
6927@item
6928its passcount as given by the @code{passcount @var{n}} command
6929@item
6930its step count as given by the @code{while-stepping @var{n}} command
6931@item
6932where in the source files is the tracepoint set
6933@item
6934its action list as given by the @code{actions} command
6935@end itemize
6936
6937@smallexample
6938(@value{GDBP}) @b{info trace}
6939Num Enb Address PassC StepC What
69401 y 0x002117c4 0 0 <gdb_asm>
6826cf00
EZ
69412 y 0x0020dc64 0 0 in g_test at g_test.c:1375
69423 y 0x0020b1f4 0 0 in get_data at ../foo.c:41
b37052ae
EZ
6943(@value{GDBP})
6944@end smallexample
6945
6946@noindent
6947This command can be abbreviated @code{info tp}.
6948@end table
6949
6950@node Starting and Stopping Trace Experiment
6951@subsection Starting and Stopping Trace Experiment
6952
6953@table @code
6954@kindex tstart
6955@cindex start a new trace experiment
6956@cindex collected data discarded
6957@item tstart
6958This command takes no arguments. It starts the trace experiment, and
6959begins collecting data. This has the side effect of discarding all
6960the data collected in the trace buffer during the previous trace
6961experiment.
6962
6963@kindex tstop
6964@cindex stop a running trace experiment
6965@item tstop
6966This command takes no arguments. It ends the trace experiment, and
6967stops collecting data.
6968
6969@strong{Note:} a trace experiment and data collection may stop
6970automatically if any tracepoint's passcount is reached
6971(@pxref{Tracepoint Passcounts}), or if the trace buffer becomes full.
6972
6973@kindex tstatus
6974@cindex status of trace data collection
6975@cindex trace experiment, status of
6976@item tstatus
6977This command displays the status of the current trace data
6978collection.
6979@end table
6980
6981Here is an example of the commands we described so far:
6982
6983@smallexample
6984(@value{GDBP}) @b{trace gdb_c_test}
6985(@value{GDBP}) @b{actions}
6986Enter actions for tracepoint #1, one per line.
6987> collect $regs,$locals,$args
6988> while-stepping 11
6989 > collect $regs
6990 > end
6991> end
6992(@value{GDBP}) @b{tstart}
6993 [time passes @dots{}]
6994(@value{GDBP}) @b{tstop}
6995@end smallexample
6996
6997
6998@node Analyze Collected Data
6999@section Using the collected data
7000
7001After the tracepoint experiment ends, you use @value{GDBN} commands
7002for examining the trace data. The basic idea is that each tracepoint
7003collects a trace @dfn{snapshot} every time it is hit and another
7004snapshot every time it single-steps. All these snapshots are
7005consecutively numbered from zero and go into a buffer, and you can
7006examine them later. The way you examine them is to @dfn{focus} on a
7007specific trace snapshot. When the remote stub is focused on a trace
7008snapshot, it will respond to all @value{GDBN} requests for memory and
7009registers by reading from the buffer which belongs to that snapshot,
7010rather than from @emph{real} memory or registers of the program being
7011debugged. This means that @strong{all} @value{GDBN} commands
7012(@code{print}, @code{info registers}, @code{backtrace}, etc.) will
7013behave as if we were currently debugging the program state as it was
7014when the tracepoint occurred. Any requests for data that are not in
7015the buffer will fail.
7016
7017@menu
7018* tfind:: How to select a trace snapshot
7019* tdump:: How to display all data for a snapshot
7020* save-tracepoints:: How to save tracepoints for a future run
7021@end menu
7022
7023@node tfind
7024@subsection @code{tfind @var{n}}
7025
7026@kindex tfind
7027@cindex select trace snapshot
7028@cindex find trace snapshot
7029The basic command for selecting a trace snapshot from the buffer is
7030@code{tfind @var{n}}, which finds trace snapshot number @var{n},
7031counting from zero. If no argument @var{n} is given, the next
7032snapshot is selected.
7033
7034Here are the various forms of using the @code{tfind} command.
7035
7036@table @code
7037@item tfind start
7038Find the first snapshot in the buffer. This is a synonym for
7039@code{tfind 0} (since 0 is the number of the first snapshot).
7040
7041@item tfind none
7042Stop debugging trace snapshots, resume @emph{live} debugging.
7043
7044@item tfind end
7045Same as @samp{tfind none}.
7046
7047@item tfind
7048No argument means find the next trace snapshot.
7049
7050@item tfind -
7051Find the previous trace snapshot before the current one. This permits
7052retracing earlier steps.
7053
7054@item tfind tracepoint @var{num}
7055Find the next snapshot associated with tracepoint @var{num}. Search
7056proceeds forward from the last examined trace snapshot. If no
7057argument @var{num} is given, it means find the next snapshot collected
7058for the same tracepoint as the current snapshot.
7059
7060@item tfind pc @var{addr}
7061Find the next snapshot associated with the value @var{addr} of the
7062program counter. Search proceeds forward from the last examined trace
7063snapshot. If no argument @var{addr} is given, it means find the next
7064snapshot with the same value of PC as the current snapshot.
7065
7066@item tfind outside @var{addr1}, @var{addr2}
7067Find the next snapshot whose PC is outside the given range of
7068addresses.
7069
7070@item tfind range @var{addr1}, @var{addr2}
7071Find the next snapshot whose PC is between @var{addr1} and
7072@var{addr2}. @c FIXME: Is the range inclusive or exclusive?
7073
7074@item tfind line @r{[}@var{file}:@r{]}@var{n}
7075Find the next snapshot associated with the source line @var{n}. If
7076the optional argument @var{file} is given, refer to line @var{n} in
7077that source file. Search proceeds forward from the last examined
7078trace snapshot. If no argument @var{n} is given, it means find the
7079next line other than the one currently being examined; thus saying
7080@code{tfind line} repeatedly can appear to have the same effect as
7081stepping from line to line in a @emph{live} debugging session.
7082@end table
7083
7084The default arguments for the @code{tfind} commands are specifically
7085designed to make it easy to scan through the trace buffer. For
7086instance, @code{tfind} with no argument selects the next trace
7087snapshot, and @code{tfind -} with no argument selects the previous
7088trace snapshot. So, by giving one @code{tfind} command, and then
7089simply hitting @key{RET} repeatedly you can examine all the trace
7090snapshots in order. Or, by saying @code{tfind -} and then hitting
7091@key{RET} repeatedly you can examine the snapshots in reverse order.
7092The @code{tfind line} command with no argument selects the snapshot
7093for the next source line executed. The @code{tfind pc} command with
7094no argument selects the next snapshot with the same program counter
7095(PC) as the current frame. The @code{tfind tracepoint} command with
7096no argument selects the next trace snapshot collected by the same
7097tracepoint as the current one.
7098
7099In addition to letting you scan through the trace buffer manually,
7100these commands make it easy to construct @value{GDBN} scripts that
7101scan through the trace buffer and print out whatever collected data
7102you are interested in. Thus, if we want to examine the PC, FP, and SP
7103registers from each trace frame in the buffer, we can say this:
7104
7105@smallexample
7106(@value{GDBP}) @b{tfind start}
7107(@value{GDBP}) @b{while ($trace_frame != -1)}
7108> printf "Frame %d, PC = %08X, SP = %08X, FP = %08X\n", \
7109 $trace_frame, $pc, $sp, $fp
7110> tfind
7111> end
7112
7113Frame 0, PC = 0020DC64, SP = 0030BF3C, FP = 0030BF44
7114Frame 1, PC = 0020DC6C, SP = 0030BF38, FP = 0030BF44
7115Frame 2, PC = 0020DC70, SP = 0030BF34, FP = 0030BF44
7116Frame 3, PC = 0020DC74, SP = 0030BF30, FP = 0030BF44
7117Frame 4, PC = 0020DC78, SP = 0030BF2C, FP = 0030BF44
7118Frame 5, PC = 0020DC7C, SP = 0030BF28, FP = 0030BF44
7119Frame 6, PC = 0020DC80, SP = 0030BF24, FP = 0030BF44
7120Frame 7, PC = 0020DC84, SP = 0030BF20, FP = 0030BF44
7121Frame 8, PC = 0020DC88, SP = 0030BF1C, FP = 0030BF44
7122Frame 9, PC = 0020DC8E, SP = 0030BF18, FP = 0030BF44
7123Frame 10, PC = 00203F6C, SP = 0030BE3C, FP = 0030BF14
7124@end smallexample
7125
7126Or, if we want to examine the variable @code{X} at each source line in
7127the buffer:
7128
7129@smallexample
7130(@value{GDBP}) @b{tfind start}
7131(@value{GDBP}) @b{while ($trace_frame != -1)}
7132> printf "Frame %d, X == %d\n", $trace_frame, X
7133> tfind line
7134> end
7135
7136Frame 0, X = 1
7137Frame 7, X = 2
7138Frame 13, X = 255
7139@end smallexample
7140
7141@node tdump
7142@subsection @code{tdump}
7143@kindex tdump
7144@cindex dump all data collected at tracepoint
7145@cindex tracepoint data, display
7146
7147This command takes no arguments. It prints all the data collected at
7148the current trace snapshot.
7149
7150@smallexample
7151(@value{GDBP}) @b{trace 444}
7152(@value{GDBP}) @b{actions}
7153Enter actions for tracepoint #2, one per line:
7154> collect $regs, $locals, $args, gdb_long_test
7155> end
7156
7157(@value{GDBP}) @b{tstart}
7158
7159(@value{GDBP}) @b{tfind line 444}
7160#0 gdb_test (p1=0x11, p2=0x22, p3=0x33, p4=0x44, p5=0x55, p6=0x66)
7161at gdb_test.c:444
7162444 printp( "%s: arguments = 0x%X 0x%X 0x%X 0x%X 0x%X 0x%X\n", )
7163
7164(@value{GDBP}) @b{tdump}
7165Data collected at tracepoint 2, trace frame 1:
7166d0 0xc4aa0085 -995491707
7167d1 0x18 24
7168d2 0x80 128
7169d3 0x33 51
7170d4 0x71aea3d 119204413
7171d5 0x22 34
7172d6 0xe0 224
7173d7 0x380035 3670069
7174a0 0x19e24a 1696330
7175a1 0x3000668 50333288
7176a2 0x100 256
7177a3 0x322000 3284992
7178a4 0x3000698 50333336
7179a5 0x1ad3cc 1758156
7180fp 0x30bf3c 0x30bf3c
7181sp 0x30bf34 0x30bf34
7182ps 0x0 0
7183pc 0x20b2c8 0x20b2c8
7184fpcontrol 0x0 0
7185fpstatus 0x0 0
7186fpiaddr 0x0 0
7187p = 0x20e5b4 "gdb-test"
7188p1 = (void *) 0x11
7189p2 = (void *) 0x22
7190p3 = (void *) 0x33
7191p4 = (void *) 0x44
7192p5 = (void *) 0x55
7193p6 = (void *) 0x66
7194gdb_long_test = 17 '\021'
7195
7196(@value{GDBP})
7197@end smallexample
7198
7199@node save-tracepoints
7200@subsection @code{save-tracepoints @var{filename}}
7201@kindex save-tracepoints
7202@cindex save tracepoints for future sessions
7203
7204This command saves all current tracepoint definitions together with
7205their actions and passcounts, into a file @file{@var{filename}}
7206suitable for use in a later debugging session. To read the saved
7207tracepoint definitions, use the @code{source} command (@pxref{Command
7208Files}).
7209
7210@node Tracepoint Variables
7211@section Convenience Variables for Tracepoints
7212@cindex tracepoint variables
7213@cindex convenience variables for tracepoints
7214
7215@table @code
7216@vindex $trace_frame
7217@item (int) $trace_frame
7218The current trace snapshot (a.k.a.@: @dfn{frame}) number, or -1 if no
7219snapshot is selected.
7220
7221@vindex $tracepoint
7222@item (int) $tracepoint
7223The tracepoint for the current trace snapshot.
7224
7225@vindex $trace_line
7226@item (int) $trace_line
7227The line number for the current trace snapshot.
7228
7229@vindex $trace_file
7230@item (char []) $trace_file
7231The source file for the current trace snapshot.
7232
7233@vindex $trace_func
7234@item (char []) $trace_func
7235The name of the function containing @code{$tracepoint}.
7236@end table
7237
7238Note: @code{$trace_file} is not suitable for use in @code{printf},
7239use @code{output} instead.
7240
7241Here's a simple example of using these convenience variables for
7242stepping through all the trace snapshots and printing some of their
7243data.
7244
7245@smallexample
7246(@value{GDBP}) @b{tfind start}
7247
7248(@value{GDBP}) @b{while $trace_frame != -1}
7249> output $trace_file
7250> printf ", line %d (tracepoint #%d)\n", $trace_line, $tracepoint
7251> tfind
7252> end
7253@end smallexample
7254
df0cd8c5
JB
7255@node Overlays
7256@chapter Debugging Programs That Use Overlays
7257@cindex overlays
7258
7259If your program is too large to fit completely in your target system's
7260memory, you can sometimes use @dfn{overlays} to work around this
7261problem. @value{GDBN} provides some support for debugging programs that
7262use overlays.
7263
7264@menu
7265* How Overlays Work:: A general explanation of overlays.
7266* Overlay Commands:: Managing overlays in @value{GDBN}.
7267* Automatic Overlay Debugging:: @value{GDBN} can find out which overlays are
7268 mapped by asking the inferior.
7269* Overlay Sample Program:: A sample program using overlays.
7270@end menu
7271
7272@node How Overlays Work
7273@section How Overlays Work
7274@cindex mapped overlays
7275@cindex unmapped overlays
7276@cindex load address, overlay's
7277@cindex mapped address
7278@cindex overlay area
7279
7280Suppose you have a computer whose instruction address space is only 64
7281kilobytes long, but which has much more memory which can be accessed by
7282other means: special instructions, segment registers, or memory
7283management hardware, for example. Suppose further that you want to
7284adapt a program which is larger than 64 kilobytes to run on this system.
7285
7286One solution is to identify modules of your program which are relatively
7287independent, and need not call each other directly; call these modules
7288@dfn{overlays}. Separate the overlays from the main program, and place
7289their machine code in the larger memory. Place your main program in
7290instruction memory, but leave at least enough space there to hold the
7291largest overlay as well.
7292
7293Now, to call a function located in an overlay, you must first copy that
7294overlay's machine code from the large memory into the space set aside
7295for it in the instruction memory, and then jump to its entry point
7296there.
7297
c928edc0
AC
7298@c NB: In the below the mapped area's size is greater or equal to the
7299@c size of all overlays. This is intentional to remind the developer
7300@c that overlays don't necessarily need to be the same size.
7301
474c8240 7302@smallexample
df0cd8c5 7303@group
c928edc0
AC
7304 Data Instruction Larger
7305Address Space Address Space Address Space
7306+-----------+ +-----------+ +-----------+
7307| | | | | |
7308+-----------+ +-----------+ +-----------+<-- overlay 1
7309| program | | main | .----| overlay 1 | load address
7310| variables | | program | | +-----------+
7311| and heap | | | | | |
7312+-----------+ | | | +-----------+<-- overlay 2
7313| | +-----------+ | | | load address
7314+-----------+ | | | .-| overlay 2 |
7315 | | | | | |
7316 mapped --->+-----------+ | | +-----------+
7317 address | | | | | |
7318 | overlay | <-' | | |
7319 | area | <---' +-----------+<-- overlay 3
7320 | | <---. | | load address
7321 +-----------+ `--| overlay 3 |
7322 | | | |
7323 +-----------+ | |
7324 +-----------+
7325 | |
7326 +-----------+
7327
7328 @anchor{A code overlay}A code overlay
df0cd8c5 7329@end group
474c8240 7330@end smallexample
df0cd8c5 7331
c928edc0
AC
7332The diagram (@pxref{A code overlay}) shows a system with separate data
7333and instruction address spaces. To map an overlay, the program copies
7334its code from the larger address space to the instruction address space.
7335Since the overlays shown here all use the same mapped address, only one
7336may be mapped at a time. For a system with a single address space for
7337data and instructions, the diagram would be similar, except that the
7338program variables and heap would share an address space with the main
7339program and the overlay area.
df0cd8c5
JB
7340
7341An overlay loaded into instruction memory and ready for use is called a
7342@dfn{mapped} overlay; its @dfn{mapped address} is its address in the
7343instruction memory. An overlay not present (or only partially present)
7344in instruction memory is called @dfn{unmapped}; its @dfn{load address}
7345is its address in the larger memory. The mapped address is also called
7346the @dfn{virtual memory address}, or @dfn{VMA}; the load address is also
7347called the @dfn{load memory address}, or @dfn{LMA}.
7348
7349Unfortunately, overlays are not a completely transparent way to adapt a
7350program to limited instruction memory. They introduce a new set of
7351global constraints you must keep in mind as you design your program:
7352
7353@itemize @bullet
7354
7355@item
7356Before calling or returning to a function in an overlay, your program
7357must make sure that overlay is actually mapped. Otherwise, the call or
7358return will transfer control to the right address, but in the wrong
7359overlay, and your program will probably crash.
7360
7361@item
7362If the process of mapping an overlay is expensive on your system, you
7363will need to choose your overlays carefully to minimize their effect on
7364your program's performance.
7365
7366@item
7367The executable file you load onto your system must contain each
7368overlay's instructions, appearing at the overlay's load address, not its
7369mapped address. However, each overlay's instructions must be relocated
7370and its symbols defined as if the overlay were at its mapped address.
7371You can use GNU linker scripts to specify different load and relocation
7372addresses for pieces of your program; see @ref{Overlay Description,,,
7373ld.info, Using ld: the GNU linker}.
7374
7375@item
7376The procedure for loading executable files onto your system must be able
7377to load their contents into the larger address space as well as the
7378instruction and data spaces.
7379
7380@end itemize
7381
7382The overlay system described above is rather simple, and could be
7383improved in many ways:
7384
7385@itemize @bullet
7386
7387@item
7388If your system has suitable bank switch registers or memory management
7389hardware, you could use those facilities to make an overlay's load area
7390contents simply appear at their mapped address in instruction space.
7391This would probably be faster than copying the overlay to its mapped
7392area in the usual way.
7393
7394@item
7395If your overlays are small enough, you could set aside more than one
7396overlay area, and have more than one overlay mapped at a time.
7397
7398@item
7399You can use overlays to manage data, as well as instructions. In
7400general, data overlays are even less transparent to your design than
7401code overlays: whereas code overlays only require care when you call or
7402return to functions, data overlays require care every time you access
7403the data. Also, if you change the contents of a data overlay, you
7404must copy its contents back out to its load address before you can copy a
7405different data overlay into the same mapped area.
7406
7407@end itemize
7408
7409
7410@node Overlay Commands
7411@section Overlay Commands
7412
7413To use @value{GDBN}'s overlay support, each overlay in your program must
7414correspond to a separate section of the executable file. The section's
7415virtual memory address and load memory address must be the overlay's
7416mapped and load addresses. Identifying overlays with sections allows
7417@value{GDBN} to determine the appropriate address of a function or
7418variable, depending on whether the overlay is mapped or not.
7419
7420@value{GDBN}'s overlay commands all start with the word @code{overlay};
7421you can abbreviate this as @code{ov} or @code{ovly}. The commands are:
7422
7423@table @code
7424@item overlay off
4644b6e3 7425@kindex overlay
df0cd8c5
JB
7426Disable @value{GDBN}'s overlay support. When overlay support is
7427disabled, @value{GDBN} assumes that all functions and variables are
7428always present at their mapped addresses. By default, @value{GDBN}'s
7429overlay support is disabled.
7430
7431@item overlay manual
df0cd8c5
JB
7432@cindex manual overlay debugging
7433Enable @dfn{manual} overlay debugging. In this mode, @value{GDBN}
7434relies on you to tell it which overlays are mapped, and which are not,
7435using the @code{overlay map-overlay} and @code{overlay unmap-overlay}
7436commands described below.
7437
7438@item overlay map-overlay @var{overlay}
7439@itemx overlay map @var{overlay}
df0cd8c5
JB
7440@cindex map an overlay
7441Tell @value{GDBN} that @var{overlay} is now mapped; @var{overlay} must
7442be the name of the object file section containing the overlay. When an
7443overlay is mapped, @value{GDBN} assumes it can find the overlay's
7444functions and variables at their mapped addresses. @value{GDBN} assumes
7445that any other overlays whose mapped ranges overlap that of
7446@var{overlay} are now unmapped.
7447
7448@item overlay unmap-overlay @var{overlay}
7449@itemx overlay unmap @var{overlay}
df0cd8c5
JB
7450@cindex unmap an overlay
7451Tell @value{GDBN} that @var{overlay} is no longer mapped; @var{overlay}
7452must be the name of the object file section containing the overlay.
7453When an overlay is unmapped, @value{GDBN} assumes it can find the
7454overlay's functions and variables at their load addresses.
7455
7456@item overlay auto
df0cd8c5
JB
7457Enable @dfn{automatic} overlay debugging. In this mode, @value{GDBN}
7458consults a data structure the overlay manager maintains in the inferior
7459to see which overlays are mapped. For details, see @ref{Automatic
7460Overlay Debugging}.
7461
7462@item overlay load-target
7463@itemx overlay load
df0cd8c5
JB
7464@cindex reloading the overlay table
7465Re-read the overlay table from the inferior. Normally, @value{GDBN}
7466re-reads the table @value{GDBN} automatically each time the inferior
7467stops, so this command should only be necessary if you have changed the
7468overlay mapping yourself using @value{GDBN}. This command is only
7469useful when using automatic overlay debugging.
7470
7471@item overlay list-overlays
7472@itemx overlay list
7473@cindex listing mapped overlays
7474Display a list of the overlays currently mapped, along with their mapped
7475addresses, load addresses, and sizes.
7476
7477@end table
7478
7479Normally, when @value{GDBN} prints a code address, it includes the name
7480of the function the address falls in:
7481
474c8240 7482@smallexample
df0cd8c5
JB
7483(gdb) print main
7484$3 = @{int ()@} 0x11a0 <main>
474c8240 7485@end smallexample
df0cd8c5
JB
7486@noindent
7487When overlay debugging is enabled, @value{GDBN} recognizes code in
7488unmapped overlays, and prints the names of unmapped functions with
7489asterisks around them. For example, if @code{foo} is a function in an
7490unmapped overlay, @value{GDBN} prints it this way:
7491
474c8240 7492@smallexample
df0cd8c5
JB
7493(gdb) overlay list
7494No sections are mapped.
7495(gdb) print foo
7496$5 = @{int (int)@} 0x100000 <*foo*>
474c8240 7497@end smallexample
df0cd8c5
JB
7498@noindent
7499When @code{foo}'s overlay is mapped, @value{GDBN} prints the function's
7500name normally:
7501
474c8240 7502@smallexample
df0cd8c5 7503(gdb) overlay list
b383017d 7504Section .ov.foo.text, loaded at 0x100000 - 0x100034,
df0cd8c5
JB
7505 mapped at 0x1016 - 0x104a
7506(gdb) print foo
7507$6 = @{int (int)@} 0x1016 <foo>
474c8240 7508@end smallexample
df0cd8c5
JB
7509
7510When overlay debugging is enabled, @value{GDBN} can find the correct
7511address for functions and variables in an overlay, whether or not the
7512overlay is mapped. This allows most @value{GDBN} commands, like
7513@code{break} and @code{disassemble}, to work normally, even on unmapped
7514code. However, @value{GDBN}'s breakpoint support has some limitations:
7515
7516@itemize @bullet
7517@item
7518@cindex breakpoints in overlays
7519@cindex overlays, setting breakpoints in
7520You can set breakpoints in functions in unmapped overlays, as long as
7521@value{GDBN} can write to the overlay at its load address.
7522@item
7523@value{GDBN} can not set hardware or simulator-based breakpoints in
7524unmapped overlays. However, if you set a breakpoint at the end of your
7525overlay manager (and tell @value{GDBN} which overlays are now mapped, if
7526you are using manual overlay management), @value{GDBN} will re-set its
7527breakpoints properly.
7528@end itemize
7529
7530
7531@node Automatic Overlay Debugging
7532@section Automatic Overlay Debugging
7533@cindex automatic overlay debugging
7534
7535@value{GDBN} can automatically track which overlays are mapped and which
7536are not, given some simple co-operation from the overlay manager in the
7537inferior. If you enable automatic overlay debugging with the
7538@code{overlay auto} command (@pxref{Overlay Commands}), @value{GDBN}
7539looks in the inferior's memory for certain variables describing the
7540current state of the overlays.
7541
7542Here are the variables your overlay manager must define to support
7543@value{GDBN}'s automatic overlay debugging:
7544
7545@table @asis
7546
7547@item @code{_ovly_table}:
7548This variable must be an array of the following structures:
7549
474c8240 7550@smallexample
df0cd8c5
JB
7551struct
7552@{
7553 /* The overlay's mapped address. */
7554 unsigned long vma;
7555
7556 /* The size of the overlay, in bytes. */
7557 unsigned long size;
7558
7559 /* The overlay's load address. */
7560 unsigned long lma;
7561
7562 /* Non-zero if the overlay is currently mapped;
7563 zero otherwise. */
7564 unsigned long mapped;
7565@}
474c8240 7566@end smallexample
df0cd8c5
JB
7567
7568@item @code{_novlys}:
7569This variable must be a four-byte signed integer, holding the total
7570number of elements in @code{_ovly_table}.
7571
7572@end table
7573
7574To decide whether a particular overlay is mapped or not, @value{GDBN}
7575looks for an entry in @w{@code{_ovly_table}} whose @code{vma} and
7576@code{lma} members equal the VMA and LMA of the overlay's section in the
7577executable file. When @value{GDBN} finds a matching entry, it consults
7578the entry's @code{mapped} member to determine whether the overlay is
7579currently mapped.
7580
81d46470 7581In addition, your overlay manager may define a function called
def71bfa 7582@code{_ovly_debug_event}. If this function is defined, @value{GDBN}
81d46470
MS
7583will silently set a breakpoint there. If the overlay manager then
7584calls this function whenever it has changed the overlay table, this
7585will enable @value{GDBN} to accurately keep track of which overlays
7586are in program memory, and update any breakpoints that may be set
b383017d 7587in overlays. This will allow breakpoints to work even if the
81d46470
MS
7588overlays are kept in ROM or other non-writable memory while they
7589are not being executed.
df0cd8c5
JB
7590
7591@node Overlay Sample Program
7592@section Overlay Sample Program
7593@cindex overlay example program
7594
7595When linking a program which uses overlays, you must place the overlays
7596at their load addresses, while relocating them to run at their mapped
7597addresses. To do this, you must write a linker script (@pxref{Overlay
7598Description,,, ld.info, Using ld: the GNU linker}). Unfortunately,
7599since linker scripts are specific to a particular host system, target
7600architecture, and target memory layout, this manual cannot provide
7601portable sample code demonstrating @value{GDBN}'s overlay support.
7602
7603However, the @value{GDBN} source distribution does contain an overlaid
7604program, with linker scripts for a few systems, as part of its test
7605suite. The program consists of the following files from
7606@file{gdb/testsuite/gdb.base}:
7607
7608@table @file
7609@item overlays.c
7610The main program file.
7611@item ovlymgr.c
7612A simple overlay manager, used by @file{overlays.c}.
7613@item foo.c
7614@itemx bar.c
7615@itemx baz.c
7616@itemx grbx.c
7617Overlay modules, loaded and used by @file{overlays.c}.
7618@item d10v.ld
7619@itemx m32r.ld
7620Linker scripts for linking the test program on the @code{d10v-elf}
7621and @code{m32r-elf} targets.
7622@end table
7623
7624You can build the test program using the @code{d10v-elf} GCC
7625cross-compiler like this:
7626
474c8240 7627@smallexample
df0cd8c5
JB
7628$ d10v-elf-gcc -g -c overlays.c
7629$ d10v-elf-gcc -g -c ovlymgr.c
7630$ d10v-elf-gcc -g -c foo.c
7631$ d10v-elf-gcc -g -c bar.c
7632$ d10v-elf-gcc -g -c baz.c
7633$ d10v-elf-gcc -g -c grbx.c
7634$ d10v-elf-gcc -g overlays.o ovlymgr.o foo.o bar.o \
7635 baz.o grbx.o -Wl,-Td10v.ld -o overlays
474c8240 7636@end smallexample
df0cd8c5
JB
7637
7638The build process is identical for any other architecture, except that
7639you must substitute the appropriate compiler and linker script for the
7640target system for @code{d10v-elf-gcc} and @code{d10v.ld}.
7641
7642
6d2ebf8b 7643@node Languages
c906108c
SS
7644@chapter Using @value{GDBN} with Different Languages
7645@cindex languages
7646
c906108c
SS
7647Although programming languages generally have common aspects, they are
7648rarely expressed in the same manner. For instance, in ANSI C,
7649dereferencing a pointer @code{p} is accomplished by @code{*p}, but in
7650Modula-2, it is accomplished by @code{p^}. Values can also be
5d161b24 7651represented (and displayed) differently. Hex numbers in C appear as
c906108c 7652@samp{0x1ae}, while in Modula-2 they appear as @samp{1AEH}.
c906108c
SS
7653
7654@cindex working language
7655Language-specific information is built into @value{GDBN} for some languages,
7656allowing you to express operations like the above in your program's
7657native language, and allowing @value{GDBN} to output values in a manner
7658consistent with the syntax of your program's native language. The
7659language you use to build expressions is called the @dfn{working
7660language}.
7661
7662@menu
7663* Setting:: Switching between source languages
7664* Show:: Displaying the language
c906108c 7665* Checks:: Type and range checks
c906108c 7666* Support:: Supported languages
4e562065 7667* Unsupported languages:: Unsupported languages
c906108c
SS
7668@end menu
7669
6d2ebf8b 7670@node Setting
c906108c
SS
7671@section Switching between source languages
7672
7673There are two ways to control the working language---either have @value{GDBN}
7674set it automatically, or select it manually yourself. You can use the
7675@code{set language} command for either purpose. On startup, @value{GDBN}
7676defaults to setting the language automatically. The working language is
7677used to determine how expressions you type are interpreted, how values
7678are printed, etc.
7679
7680In addition to the working language, every source file that
7681@value{GDBN} knows about has its own working language. For some object
7682file formats, the compiler might indicate which language a particular
7683source file is in. However, most of the time @value{GDBN} infers the
7684language from the name of the file. The language of a source file
b37052ae 7685controls whether C@t{++} names are demangled---this way @code{backtrace} can
c906108c 7686show each frame appropriately for its own language. There is no way to
d4f3574e
SS
7687set the language of a source file from within @value{GDBN}, but you can
7688set the language associated with a filename extension. @xref{Show, ,
7689Displaying the language}.
c906108c
SS
7690
7691This is most commonly a problem when you use a program, such
5d161b24 7692as @code{cfront} or @code{f2c}, that generates C but is written in
c906108c
SS
7693another language. In that case, make the
7694program use @code{#line} directives in its C output; that way
7695@value{GDBN} will know the correct language of the source code of the original
7696program, and will display that source code, not the generated C code.
7697
7698@menu
7699* Filenames:: Filename extensions and languages.
7700* Manually:: Setting the working language manually
7701* Automatically:: Having @value{GDBN} infer the source language
7702@end menu
7703
6d2ebf8b 7704@node Filenames
c906108c
SS
7705@subsection List of filename extensions and languages
7706
7707If a source file name ends in one of the following extensions, then
7708@value{GDBN} infers that its language is the one indicated.
7709
7710@table @file
7711
7712@item .c
7713C source file
7714
7715@item .C
7716@itemx .cc
7717@itemx .cp
7718@itemx .cpp
7719@itemx .cxx
7720@itemx .c++
b37052ae 7721C@t{++} source file
c906108c 7722
b37303ee
AF
7723@item .m
7724Objective-C source file
7725
c906108c
SS
7726@item .f
7727@itemx .F
7728Fortran source file
7729
c906108c
SS
7730@item .mod
7731Modula-2 source file
c906108c
SS
7732
7733@item .s
7734@itemx .S
7735Assembler source file. This actually behaves almost like C, but
7736@value{GDBN} does not skip over function prologues when stepping.
7737@end table
7738
7739In addition, you may set the language associated with a filename
7740extension. @xref{Show, , Displaying the language}.
7741
6d2ebf8b 7742@node Manually
c906108c
SS
7743@subsection Setting the working language
7744
7745If you allow @value{GDBN} to set the language automatically,
7746expressions are interpreted the same way in your debugging session and
7747your program.
7748
7749@kindex set language
7750If you wish, you may set the language manually. To do this, issue the
7751command @samp{set language @var{lang}}, where @var{lang} is the name of
5d161b24 7752a language, such as
c906108c 7753@code{c} or @code{modula-2}.
c906108c
SS
7754For a list of the supported languages, type @samp{set language}.
7755
c906108c
SS
7756Setting the language manually prevents @value{GDBN} from updating the working
7757language automatically. This can lead to confusion if you try
7758to debug a program when the working language is not the same as the
7759source language, when an expression is acceptable to both
7760languages---but means different things. For instance, if the current
7761source file were written in C, and @value{GDBN} was parsing Modula-2, a
7762command such as:
7763
474c8240 7764@smallexample
c906108c 7765print a = b + c
474c8240 7766@end smallexample
c906108c
SS
7767
7768@noindent
7769might not have the effect you intended. In C, this means to add
7770@code{b} and @code{c} and place the result in @code{a}. The result
7771printed would be the value of @code{a}. In Modula-2, this means to compare
7772@code{a} to the result of @code{b+c}, yielding a @code{BOOLEAN} value.
c906108c 7773
6d2ebf8b 7774@node Automatically
c906108c
SS
7775@subsection Having @value{GDBN} infer the source language
7776
7777To have @value{GDBN} set the working language automatically, use
7778@samp{set language local} or @samp{set language auto}. @value{GDBN}
7779then infers the working language. That is, when your program stops in a
7780frame (usually by encountering a breakpoint), @value{GDBN} sets the
7781working language to the language recorded for the function in that
7782frame. If the language for a frame is unknown (that is, if the function
7783or block corresponding to the frame was defined in a source file that
7784does not have a recognized extension), the current working language is
7785not changed, and @value{GDBN} issues a warning.
7786
7787This may not seem necessary for most programs, which are written
7788entirely in one source language. However, program modules and libraries
7789written in one source language can be used by a main program written in
7790a different source language. Using @samp{set language auto} in this
7791case frees you from having to set the working language manually.
7792
6d2ebf8b 7793@node Show
c906108c 7794@section Displaying the language
c906108c
SS
7795
7796The following commands help you find out which language is the
7797working language, and also what language source files were written in.
7798
7799@kindex show language
c906108c
SS
7800@table @code
7801@item show language
7802Display the current working language. This is the
7803language you can use with commands such as @code{print} to
7804build and compute expressions that may involve variables in your program.
7805
7806@item info frame
4644b6e3 7807@kindex info frame@r{, show the source language}
5d161b24 7808Display the source language for this frame. This language becomes the
c906108c 7809working language if you use an identifier from this frame.
5d161b24 7810@xref{Frame Info, ,Information about a frame}, to identify the other
c906108c
SS
7811information listed here.
7812
7813@item info source
4644b6e3 7814@kindex info source@r{, show the source language}
c906108c 7815Display the source language of this source file.
5d161b24 7816@xref{Symbols, ,Examining the Symbol Table}, to identify the other
c906108c
SS
7817information listed here.
7818@end table
7819
7820In unusual circumstances, you may have source files with extensions
7821not in the standard list. You can then set the extension associated
7822with a language explicitly:
7823
7824@kindex set extension-language
7825@kindex info extensions
7826@table @code
7827@item set extension-language @var{.ext} @var{language}
7828Set source files with extension @var{.ext} to be assumed to be in
7829the source language @var{language}.
7830
7831@item info extensions
7832List all the filename extensions and the associated languages.
7833@end table
7834
6d2ebf8b 7835@node Checks
c906108c
SS
7836@section Type and range checking
7837
7838@quotation
7839@emph{Warning:} In this release, the @value{GDBN} commands for type and range
7840checking are included, but they do not yet have any effect. This
7841section documents the intended facilities.
7842@end quotation
7843@c FIXME remove warning when type/range code added
7844
7845Some languages are designed to guard you against making seemingly common
7846errors through a series of compile- and run-time checks. These include
7847checking the type of arguments to functions and operators, and making
7848sure mathematical overflows are caught at run time. Checks such as
7849these help to ensure a program's correctness once it has been compiled
7850by eliminating type mismatches, and providing active checks for range
7851errors when your program is running.
7852
7853@value{GDBN} can check for conditions like the above if you wish.
7854Although @value{GDBN} does not check the statements in your program, it
7855can check expressions entered directly into @value{GDBN} for evaluation via
7856the @code{print} command, for example. As with the working language,
7857@value{GDBN} can also decide whether or not to check automatically based on
7858your program's source language. @xref{Support, ,Supported languages},
7859for the default settings of supported languages.
7860
7861@menu
7862* Type Checking:: An overview of type checking
7863* Range Checking:: An overview of range checking
7864@end menu
7865
7866@cindex type checking
7867@cindex checks, type
6d2ebf8b 7868@node Type Checking
c906108c
SS
7869@subsection An overview of type checking
7870
7871Some languages, such as Modula-2, are strongly typed, meaning that the
7872arguments to operators and functions have to be of the correct type,
7873otherwise an error occurs. These checks prevent type mismatch
7874errors from ever causing any run-time problems. For example,
7875
7876@smallexample
78771 + 2 @result{} 3
7878@exdent but
7879@error{} 1 + 2.3
7880@end smallexample
7881
7882The second example fails because the @code{CARDINAL} 1 is not
7883type-compatible with the @code{REAL} 2.3.
7884
5d161b24
DB
7885For the expressions you use in @value{GDBN} commands, you can tell the
7886@value{GDBN} type checker to skip checking;
7887to treat any mismatches as errors and abandon the expression;
7888or to only issue warnings when type mismatches occur,
c906108c
SS
7889but evaluate the expression anyway. When you choose the last of
7890these, @value{GDBN} evaluates expressions like the second example above, but
7891also issues a warning.
7892
5d161b24
DB
7893Even if you turn type checking off, there may be other reasons
7894related to type that prevent @value{GDBN} from evaluating an expression.
7895For instance, @value{GDBN} does not know how to add an @code{int} and
7896a @code{struct foo}. These particular type errors have nothing to do
7897with the language in use, and usually arise from expressions, such as
c906108c
SS
7898the one described above, which make little sense to evaluate anyway.
7899
7900Each language defines to what degree it is strict about type. For
7901instance, both Modula-2 and C require the arguments to arithmetical
7902operators to be numbers. In C, enumerated types and pointers can be
7903represented as numbers, so that they are valid arguments to mathematical
7904operators. @xref{Support, ,Supported languages}, for further
7905details on specific languages.
7906
7907@value{GDBN} provides some additional commands for controlling the type checker:
7908
c906108c
SS
7909@kindex set check type
7910@kindex show check type
7911@table @code
7912@item set check type auto
7913Set type checking on or off based on the current working language.
7914@xref{Support, ,Supported languages}, for the default settings for
7915each language.
7916
7917@item set check type on
7918@itemx set check type off
7919Set type checking on or off, overriding the default setting for the
7920current working language. Issue a warning if the setting does not
7921match the language default. If any type mismatches occur in
d4f3574e 7922evaluating an expression while type checking is on, @value{GDBN} prints a
c906108c
SS
7923message and aborts evaluation of the expression.
7924
7925@item set check type warn
7926Cause the type checker to issue warnings, but to always attempt to
7927evaluate the expression. Evaluating the expression may still
7928be impossible for other reasons. For example, @value{GDBN} cannot add
7929numbers and structures.
7930
7931@item show type
5d161b24 7932Show the current setting of the type checker, and whether or not @value{GDBN}
c906108c
SS
7933is setting it automatically.
7934@end table
7935
7936@cindex range checking
7937@cindex checks, range
6d2ebf8b 7938@node Range Checking
c906108c
SS
7939@subsection An overview of range checking
7940
7941In some languages (such as Modula-2), it is an error to exceed the
7942bounds of a type; this is enforced with run-time checks. Such range
7943checking is meant to ensure program correctness by making sure
7944computations do not overflow, or indices on an array element access do
7945not exceed the bounds of the array.
7946
7947For expressions you use in @value{GDBN} commands, you can tell
7948@value{GDBN} to treat range errors in one of three ways: ignore them,
7949always treat them as errors and abandon the expression, or issue
7950warnings but evaluate the expression anyway.
7951
7952A range error can result from numerical overflow, from exceeding an
7953array index bound, or when you type a constant that is not a member
7954of any type. Some languages, however, do not treat overflows as an
7955error. In many implementations of C, mathematical overflow causes the
7956result to ``wrap around'' to lower values---for example, if @var{m} is
7957the largest integer value, and @var{s} is the smallest, then
7958
474c8240 7959@smallexample
c906108c 7960@var{m} + 1 @result{} @var{s}
474c8240 7961@end smallexample
c906108c
SS
7962
7963This, too, is specific to individual languages, and in some cases
7964specific to individual compilers or machines. @xref{Support, ,
7965Supported languages}, for further details on specific languages.
7966
7967@value{GDBN} provides some additional commands for controlling the range checker:
7968
c906108c
SS
7969@kindex set check range
7970@kindex show check range
7971@table @code
7972@item set check range auto
7973Set range checking on or off based on the current working language.
7974@xref{Support, ,Supported languages}, for the default settings for
7975each language.
7976
7977@item set check range on
7978@itemx set check range off
7979Set range checking on or off, overriding the default setting for the
7980current working language. A warning is issued if the setting does not
c3f6f71d
JM
7981match the language default. If a range error occurs and range checking is on,
7982then a message is printed and evaluation of the expression is aborted.
c906108c
SS
7983
7984@item set check range warn
7985Output messages when the @value{GDBN} range checker detects a range error,
7986but attempt to evaluate the expression anyway. Evaluating the
7987expression may still be impossible for other reasons, such as accessing
7988memory that the process does not own (a typical example from many Unix
7989systems).
7990
7991@item show range
7992Show the current setting of the range checker, and whether or not it is
7993being set automatically by @value{GDBN}.
7994@end table
c906108c 7995
6d2ebf8b 7996@node Support
c906108c 7997@section Supported languages
c906108c 7998
b37303ee 7999@value{GDBN} supports C, C@t{++}, Objective-C, Fortran, Java, assembly, and Modula-2.
cce74817 8000@c This is false ...
c906108c
SS
8001Some @value{GDBN} features may be used in expressions regardless of the
8002language you use: the @value{GDBN} @code{@@} and @code{::} operators,
8003and the @samp{@{type@}addr} construct (@pxref{Expressions,
8004,Expressions}) can be used with the constructs of any supported
8005language.
8006
8007The following sections detail to what degree each source language is
8008supported by @value{GDBN}. These sections are not meant to be language
8009tutorials or references, but serve only as a reference guide to what the
8010@value{GDBN} expression parser accepts, and what input and output
8011formats should look like for different languages. There are many good
8012books written on each of these languages; please look to these for a
8013language reference or tutorial.
8014
c906108c 8015@menu
b37303ee 8016* C:: C and C@t{++}
b383017d 8017* Objective-C:: Objective-C
b37303ee 8018* Modula-2:: Modula-2
c906108c
SS
8019@end menu
8020
6d2ebf8b 8021@node C
b37052ae 8022@subsection C and C@t{++}
7a292a7a 8023
b37052ae
EZ
8024@cindex C and C@t{++}
8025@cindex expressions in C or C@t{++}
c906108c 8026
b37052ae 8027Since C and C@t{++} are so closely related, many features of @value{GDBN} apply
c906108c
SS
8028to both languages. Whenever this is the case, we discuss those languages
8029together.
8030
41afff9a
EZ
8031@cindex C@t{++}
8032@cindex @code{g++}, @sc{gnu} C@t{++} compiler
b37052ae
EZ
8033@cindex @sc{gnu} C@t{++}
8034The C@t{++} debugging facilities are jointly implemented by the C@t{++}
8035compiler and @value{GDBN}. Therefore, to debug your C@t{++} code
8036effectively, you must compile your C@t{++} programs with a supported
8037C@t{++} compiler, such as @sc{gnu} @code{g++}, or the HP ANSI C@t{++}
c906108c
SS
8038compiler (@code{aCC}).
8039
0179ffac
DC
8040For best results when using @sc{gnu} C@t{++}, use the DWARF 2 debugging
8041format; if it doesn't work on your system, try the stabs+ debugging
8042format. You can select those formats explicitly with the @code{g++}
8043command-line options @option{-gdwarf-2} and @option{-gstabs+}.
8044@xref{Debugging Options,,Options for Debugging Your Program or @sc{gnu}
8045CC, gcc.info, Using @sc{gnu} CC}.
c906108c 8046
c906108c 8047@menu
b37052ae
EZ
8048* C Operators:: C and C@t{++} operators
8049* C Constants:: C and C@t{++} constants
8050* C plus plus expressions:: C@t{++} expressions
8051* C Defaults:: Default settings for C and C@t{++}
8052* C Checks:: C and C@t{++} type and range checks
c906108c 8053* Debugging C:: @value{GDBN} and C
b37052ae 8054* Debugging C plus plus:: @value{GDBN} features for C@t{++}
c906108c 8055@end menu
c906108c 8056
6d2ebf8b 8057@node C Operators
b37052ae 8058@subsubsection C and C@t{++} operators
7a292a7a 8059
b37052ae 8060@cindex C and C@t{++} operators
c906108c
SS
8061
8062Operators must be defined on values of specific types. For instance,
8063@code{+} is defined on numbers, but not on structures. Operators are
5d161b24 8064often defined on groups of types.
c906108c 8065
b37052ae 8066For the purposes of C and C@t{++}, the following definitions hold:
c906108c
SS
8067
8068@itemize @bullet
53a5351d 8069
c906108c 8070@item
c906108c 8071@emph{Integral types} include @code{int} with any of its storage-class
b37052ae 8072specifiers; @code{char}; @code{enum}; and, for C@t{++}, @code{bool}.
c906108c
SS
8073
8074@item
d4f3574e
SS
8075@emph{Floating-point types} include @code{float}, @code{double}, and
8076@code{long double} (if supported by the target platform).
c906108c
SS
8077
8078@item
53a5351d 8079@emph{Pointer types} include all types defined as @code{(@var{type} *)}.
c906108c
SS
8080
8081@item
8082@emph{Scalar types} include all of the above.
53a5351d 8083
c906108c
SS
8084@end itemize
8085
8086@noindent
8087The following operators are supported. They are listed here
8088in order of increasing precedence:
8089
8090@table @code
8091@item ,
8092The comma or sequencing operator. Expressions in a comma-separated list
8093are evaluated from left to right, with the result of the entire
8094expression being the last expression evaluated.
8095
8096@item =
8097Assignment. The value of an assignment expression is the value
8098assigned. Defined on scalar types.
8099
8100@item @var{op}=
8101Used in an expression of the form @w{@code{@var{a} @var{op}= @var{b}}},
8102and translated to @w{@code{@var{a} = @var{a op b}}}.
d4f3574e 8103@w{@code{@var{op}=}} and @code{=} have the same precedence.
c906108c
SS
8104@var{op} is any one of the operators @code{|}, @code{^}, @code{&},
8105@code{<<}, @code{>>}, @code{+}, @code{-}, @code{*}, @code{/}, @code{%}.
8106
8107@item ?:
8108The ternary operator. @code{@var{a} ? @var{b} : @var{c}} can be thought
8109of as: if @var{a} then @var{b} else @var{c}. @var{a} should be of an
8110integral type.
8111
8112@item ||
8113Logical @sc{or}. Defined on integral types.
8114
8115@item &&
8116Logical @sc{and}. Defined on integral types.
8117
8118@item |
8119Bitwise @sc{or}. Defined on integral types.
8120
8121@item ^
8122Bitwise exclusive-@sc{or}. Defined on integral types.
8123
8124@item &
8125Bitwise @sc{and}. Defined on integral types.
8126
8127@item ==@r{, }!=
8128Equality and inequality. Defined on scalar types. The value of these
8129expressions is 0 for false and non-zero for true.
8130
8131@item <@r{, }>@r{, }<=@r{, }>=
8132Less than, greater than, less than or equal, greater than or equal.
8133Defined on scalar types. The value of these expressions is 0 for false
8134and non-zero for true.
8135
8136@item <<@r{, }>>
8137left shift, and right shift. Defined on integral types.
8138
8139@item @@
8140The @value{GDBN} ``artificial array'' operator (@pxref{Expressions, ,Expressions}).
8141
8142@item +@r{, }-
8143Addition and subtraction. Defined on integral types, floating-point types and
8144pointer types.
8145
8146@item *@r{, }/@r{, }%
8147Multiplication, division, and modulus. Multiplication and division are
8148defined on integral and floating-point types. Modulus is defined on
8149integral types.
8150
8151@item ++@r{, }--
8152Increment and decrement. When appearing before a variable, the
8153operation is performed before the variable is used in an expression;
8154when appearing after it, the variable's value is used before the
8155operation takes place.
8156
8157@item *
8158Pointer dereferencing. Defined on pointer types. Same precedence as
8159@code{++}.
8160
8161@item &
8162Address operator. Defined on variables. Same precedence as @code{++}.
8163
b37052ae
EZ
8164For debugging C@t{++}, @value{GDBN} implements a use of @samp{&} beyond what is
8165allowed in the C@t{++} language itself: you can use @samp{&(&@var{ref})}
c906108c 8166(or, if you prefer, simply @samp{&&@var{ref}}) to examine the address
b37052ae 8167where a C@t{++} reference variable (declared with @samp{&@var{ref}}) is
c906108c 8168stored.
c906108c
SS
8169
8170@item -
8171Negative. Defined on integral and floating-point types. Same
8172precedence as @code{++}.
8173
8174@item !
8175Logical negation. Defined on integral types. Same precedence as
8176@code{++}.
8177
8178@item ~
8179Bitwise complement operator. Defined on integral types. Same precedence as
8180@code{++}.
8181
8182
8183@item .@r{, }->
8184Structure member, and pointer-to-structure member. For convenience,
8185@value{GDBN} regards the two as equivalent, choosing whether to dereference a
8186pointer based on the stored type information.
8187Defined on @code{struct} and @code{union} data.
8188
c906108c
SS
8189@item .*@r{, }->*
8190Dereferences of pointers to members.
c906108c
SS
8191
8192@item []
8193Array indexing. @code{@var{a}[@var{i}]} is defined as
8194@code{*(@var{a}+@var{i})}. Same precedence as @code{->}.
8195
8196@item ()
8197Function parameter list. Same precedence as @code{->}.
8198
c906108c 8199@item ::
b37052ae 8200C@t{++} scope resolution operator. Defined on @code{struct}, @code{union},
7a292a7a 8201and @code{class} types.
c906108c
SS
8202
8203@item ::
7a292a7a
SS
8204Doubled colons also represent the @value{GDBN} scope operator
8205(@pxref{Expressions, ,Expressions}). Same precedence as @code{::},
8206above.
c906108c
SS
8207@end table
8208
c906108c
SS
8209If an operator is redefined in the user code, @value{GDBN} usually
8210attempts to invoke the redefined version instead of using the operator's
8211predefined meaning.
c906108c 8212
c906108c 8213@menu
5d161b24 8214* C Constants::
c906108c
SS
8215@end menu
8216
6d2ebf8b 8217@node C Constants
b37052ae 8218@subsubsection C and C@t{++} constants
c906108c 8219
b37052ae 8220@cindex C and C@t{++} constants
c906108c 8221
b37052ae 8222@value{GDBN} allows you to express the constants of C and C@t{++} in the
c906108c 8223following ways:
c906108c
SS
8224
8225@itemize @bullet
8226@item
8227Integer constants are a sequence of digits. Octal constants are
6ca652b0
EZ
8228specified by a leading @samp{0} (i.e.@: zero), and hexadecimal constants
8229by a leading @samp{0x} or @samp{0X}. Constants may also end with a letter
c906108c
SS
8230@samp{l}, specifying that the constant should be treated as a
8231@code{long} value.
8232
8233@item
8234Floating point constants are a sequence of digits, followed by a decimal
8235point, followed by a sequence of digits, and optionally followed by an
8236exponent. An exponent is of the form:
8237@samp{@w{e@r{[[}+@r{]|}-@r{]}@var{nnn}}}, where @var{nnn} is another
8238sequence of digits. The @samp{+} is optional for positive exponents.
d4f3574e
SS
8239A floating-point constant may also end with a letter @samp{f} or
8240@samp{F}, specifying that the constant should be treated as being of
8241the @code{float} (as opposed to the default @code{double}) type; or with
8242a letter @samp{l} or @samp{L}, which specifies a @code{long double}
8243constant.
c906108c
SS
8244
8245@item
8246Enumerated constants consist of enumerated identifiers, or their
8247integral equivalents.
8248
8249@item
8250Character constants are a single character surrounded by single quotes
8251(@code{'}), or a number---the ordinal value of the corresponding character
d4f3574e 8252(usually its @sc{ascii} value). Within quotes, the single character may
c906108c
SS
8253be represented by a letter or by @dfn{escape sequences}, which are of
8254the form @samp{\@var{nnn}}, where @var{nnn} is the octal representation
8255of the character's ordinal value; or of the form @samp{\@var{x}}, where
8256@samp{@var{x}} is a predefined special character---for example,
8257@samp{\n} for newline.
8258
8259@item
96a2c332
SS
8260String constants are a sequence of character constants surrounded by
8261double quotes (@code{"}). Any valid character constant (as described
8262above) may appear. Double quotes within the string must be preceded by
8263a backslash, so for instance @samp{"a\"b'c"} is a string of five
8264characters.
c906108c
SS
8265
8266@item
8267Pointer constants are an integral value. You can also write pointers
8268to constants using the C operator @samp{&}.
8269
8270@item
8271Array constants are comma-separated lists surrounded by braces @samp{@{}
8272and @samp{@}}; for example, @samp{@{1,2,3@}} is a three-element array of
8273integers, @samp{@{@{1,2@}, @{3,4@}, @{5,6@}@}} is a three-by-two array,
8274and @samp{@{&"hi", &"there", &"fred"@}} is a three-element array of pointers.
8275@end itemize
8276
c906108c 8277@menu
5d161b24
DB
8278* C plus plus expressions::
8279* C Defaults::
8280* C Checks::
c906108c 8281
5d161b24 8282* Debugging C::
c906108c
SS
8283@end menu
8284
6d2ebf8b 8285@node C plus plus expressions
b37052ae
EZ
8286@subsubsection C@t{++} expressions
8287
8288@cindex expressions in C@t{++}
8289@value{GDBN} expression handling can interpret most C@t{++} expressions.
8290
0179ffac
DC
8291@cindex debugging C@t{++} programs
8292@cindex C@t{++} compilers
8293@cindex debug formats and C@t{++}
8294@cindex @value{NGCC} and C@t{++}
c906108c 8295@quotation
b37052ae 8296@emph{Warning:} @value{GDBN} can only debug C@t{++} code if you use the
0179ffac
DC
8297proper compiler and the proper debug format. Currently, @value{GDBN}
8298works best when debugging C@t{++} code that is compiled with
8299@value{NGCC} 2.95.3 or with @value{NGCC} 3.1 or newer, using the options
8300@option{-gdwarf-2} or @option{-gstabs+}. DWARF 2 is preferred over
8301stabs+. Most configurations of @value{NGCC} emit either DWARF 2 or
8302stabs+ as their default debug format, so you usually don't need to
8303specify a debug format explicitly. Other compilers and/or debug formats
8304are likely to work badly or not at all when using @value{GDBN} to debug
8305C@t{++} code.
c906108c 8306@end quotation
c906108c
SS
8307
8308@enumerate
8309
8310@cindex member functions
8311@item
8312Member function calls are allowed; you can use expressions like
8313
474c8240 8314@smallexample
c906108c 8315count = aml->GetOriginal(x, y)
474c8240 8316@end smallexample
c906108c 8317
41afff9a 8318@vindex this@r{, inside C@t{++} member functions}
b37052ae 8319@cindex namespace in C@t{++}
c906108c
SS
8320@item
8321While a member function is active (in the selected stack frame), your
8322expressions have the same namespace available as the member function;
8323that is, @value{GDBN} allows implicit references to the class instance
b37052ae 8324pointer @code{this} following the same rules as C@t{++}.
c906108c 8325
c906108c 8326@cindex call overloaded functions
d4f3574e 8327@cindex overloaded functions, calling
b37052ae 8328@cindex type conversions in C@t{++}
c906108c
SS
8329@item
8330You can call overloaded functions; @value{GDBN} resolves the function
d4f3574e 8331call to the right definition, with some restrictions. @value{GDBN} does not
c906108c
SS
8332perform overload resolution involving user-defined type conversions,
8333calls to constructors, or instantiations of templates that do not exist
8334in the program. It also cannot handle ellipsis argument lists or
8335default arguments.
8336
8337It does perform integral conversions and promotions, floating-point
8338promotions, arithmetic conversions, pointer conversions, conversions of
8339class objects to base classes, and standard conversions such as those of
8340functions or arrays to pointers; it requires an exact match on the
8341number of function arguments.
8342
8343Overload resolution is always performed, unless you have specified
8344@code{set overload-resolution off}. @xref{Debugging C plus plus,
b37052ae 8345,@value{GDBN} features for C@t{++}}.
c906108c 8346
d4f3574e 8347You must specify @code{set overload-resolution off} in order to use an
c906108c
SS
8348explicit function signature to call an overloaded function, as in
8349@smallexample
8350p 'foo(char,int)'('x', 13)
8351@end smallexample
d4f3574e 8352
c906108c 8353The @value{GDBN} command-completion facility can simplify this;
d4f3574e 8354see @ref{Completion, ,Command completion}.
c906108c 8355
c906108c
SS
8356@cindex reference declarations
8357@item
b37052ae
EZ
8358@value{GDBN} understands variables declared as C@t{++} references; you can use
8359them in expressions just as you do in C@t{++} source---they are automatically
c906108c
SS
8360dereferenced.
8361
8362In the parameter list shown when @value{GDBN} displays a frame, the values of
8363reference variables are not displayed (unlike other variables); this
8364avoids clutter, since references are often used for large structures.
8365The @emph{address} of a reference variable is always shown, unless
8366you have specified @samp{set print address off}.
8367
8368@item
b37052ae 8369@value{GDBN} supports the C@t{++} name resolution operator @code{::}---your
c906108c
SS
8370expressions can use it just as expressions in your program do. Since
8371one scope may be defined in another, you can use @code{::} repeatedly if
8372necessary, for example in an expression like
8373@samp{@var{scope1}::@var{scope2}::@var{name}}. @value{GDBN} also allows
b37052ae 8374resolving name scope by reference to source files, in both C and C@t{++}
c906108c
SS
8375debugging (@pxref{Variables, ,Program variables}).
8376@end enumerate
8377
b37052ae 8378In addition, when used with HP's C@t{++} compiler, @value{GDBN} supports
53a5351d
JM
8379calling virtual functions correctly, printing out virtual bases of
8380objects, calling functions in a base subobject, casting objects, and
8381invoking user-defined operators.
c906108c 8382
6d2ebf8b 8383@node C Defaults
b37052ae 8384@subsubsection C and C@t{++} defaults
7a292a7a 8385
b37052ae 8386@cindex C and C@t{++} defaults
c906108c 8387
c906108c
SS
8388If you allow @value{GDBN} to set type and range checking automatically, they
8389both default to @code{off} whenever the working language changes to
b37052ae 8390C or C@t{++}. This happens regardless of whether you or @value{GDBN}
c906108c 8391selects the working language.
c906108c
SS
8392
8393If you allow @value{GDBN} to set the language automatically, it
8394recognizes source files whose names end with @file{.c}, @file{.C}, or
8395@file{.cc}, etc, and when @value{GDBN} enters code compiled from one of
b37052ae 8396these files, it sets the working language to C or C@t{++}.
c906108c
SS
8397@xref{Automatically, ,Having @value{GDBN} infer the source language},
8398for further details.
8399
c906108c
SS
8400@c Type checking is (a) primarily motivated by Modula-2, and (b)
8401@c unimplemented. If (b) changes, it might make sense to let this node
8402@c appear even if Mod-2 does not, but meanwhile ignore it. roland 16jul93.
7a292a7a 8403
6d2ebf8b 8404@node C Checks
b37052ae 8405@subsubsection C and C@t{++} type and range checks
7a292a7a 8406
b37052ae 8407@cindex C and C@t{++} checks
c906108c 8408
b37052ae 8409By default, when @value{GDBN} parses C or C@t{++} expressions, type checking
c906108c
SS
8410is not used. However, if you turn type checking on, @value{GDBN}
8411considers two variables type equivalent if:
8412
8413@itemize @bullet
8414@item
8415The two variables are structured and have the same structure, union, or
8416enumerated tag.
8417
8418@item
8419The two variables have the same type name, or types that have been
8420declared equivalent through @code{typedef}.
8421
8422@ignore
8423@c leaving this out because neither J Gilmore nor R Pesch understand it.
8424@c FIXME--beers?
8425@item
8426The two @code{struct}, @code{union}, or @code{enum} variables are
8427declared in the same declaration. (Note: this may not be true for all C
8428compilers.)
8429@end ignore
8430@end itemize
8431
8432Range checking, if turned on, is done on mathematical operations. Array
8433indices are not checked, since they are often used to index a pointer
8434that is not itself an array.
c906108c 8435
6d2ebf8b 8436@node Debugging C
c906108c 8437@subsubsection @value{GDBN} and C
c906108c
SS
8438
8439The @code{set print union} and @code{show print union} commands apply to
8440the @code{union} type. When set to @samp{on}, any @code{union} that is
7a292a7a
SS
8441inside a @code{struct} or @code{class} is also printed. Otherwise, it
8442appears as @samp{@{...@}}.
c906108c
SS
8443
8444The @code{@@} operator aids in the debugging of dynamic arrays, formed
8445with pointers and a memory allocation function. @xref{Expressions,
8446,Expressions}.
8447
c906108c 8448@menu
5d161b24 8449* Debugging C plus plus::
c906108c
SS
8450@end menu
8451
6d2ebf8b 8452@node Debugging C plus plus
b37052ae 8453@subsubsection @value{GDBN} features for C@t{++}
c906108c 8454
b37052ae 8455@cindex commands for C@t{++}
7a292a7a 8456
b37052ae
EZ
8457Some @value{GDBN} commands are particularly useful with C@t{++}, and some are
8458designed specifically for use with C@t{++}. Here is a summary:
c906108c
SS
8459
8460@table @code
8461@cindex break in overloaded functions
8462@item @r{breakpoint menus}
8463When you want a breakpoint in a function whose name is overloaded,
8464@value{GDBN} breakpoint menus help you specify which function definition
8465you want. @xref{Breakpoint Menus,,Breakpoint menus}.
8466
b37052ae 8467@cindex overloading in C@t{++}
c906108c
SS
8468@item rbreak @var{regex}
8469Setting breakpoints using regular expressions is helpful for setting
8470breakpoints on overloaded functions that are not members of any special
8471classes.
8472@xref{Set Breaks, ,Setting breakpoints}.
8473
b37052ae 8474@cindex C@t{++} exception handling
c906108c
SS
8475@item catch throw
8476@itemx catch catch
b37052ae 8477Debug C@t{++} exception handling using these commands. @xref{Set
c906108c
SS
8478Catchpoints, , Setting catchpoints}.
8479
8480@cindex inheritance
8481@item ptype @var{typename}
8482Print inheritance relationships as well as other information for type
8483@var{typename}.
8484@xref{Symbols, ,Examining the Symbol Table}.
8485
b37052ae 8486@cindex C@t{++} symbol display
c906108c
SS
8487@item set print demangle
8488@itemx show print demangle
8489@itemx set print asm-demangle
8490@itemx show print asm-demangle
b37052ae
EZ
8491Control whether C@t{++} symbols display in their source form, both when
8492displaying code as C@t{++} source and when displaying disassemblies.
c906108c
SS
8493@xref{Print Settings, ,Print settings}.
8494
8495@item set print object
8496@itemx show print object
8497Choose whether to print derived (actual) or declared types of objects.
8498@xref{Print Settings, ,Print settings}.
8499
8500@item set print vtbl
8501@itemx show print vtbl
8502Control the format for printing virtual function tables.
8503@xref{Print Settings, ,Print settings}.
c906108c 8504(The @code{vtbl} commands do not work on programs compiled with the HP
b37052ae 8505ANSI C@t{++} compiler (@code{aCC}).)
c906108c
SS
8506
8507@kindex set overload-resolution
d4f3574e 8508@cindex overloaded functions, overload resolution
c906108c 8509@item set overload-resolution on
b37052ae 8510Enable overload resolution for C@t{++} expression evaluation. The default
c906108c
SS
8511is on. For overloaded functions, @value{GDBN} evaluates the arguments
8512and searches for a function whose signature matches the argument types,
b37052ae 8513using the standard C@t{++} conversion rules (see @ref{C plus plus expressions, ,C@t{++}
d4f3574e 8514expressions}, for details). If it cannot find a match, it emits a
c906108c
SS
8515message.
8516
8517@item set overload-resolution off
b37052ae 8518Disable overload resolution for C@t{++} expression evaluation. For
c906108c
SS
8519overloaded functions that are not class member functions, @value{GDBN}
8520chooses the first function of the specified name that it finds in the
8521symbol table, whether or not its arguments are of the correct type. For
8522overloaded functions that are class member functions, @value{GDBN}
8523searches for a function whose signature @emph{exactly} matches the
8524argument types.
c906108c
SS
8525
8526@item @r{Overloaded symbol names}
8527You can specify a particular definition of an overloaded symbol, using
b37052ae 8528the same notation that is used to declare such symbols in C@t{++}: type
c906108c
SS
8529@code{@var{symbol}(@var{types})} rather than just @var{symbol}. You can
8530also use the @value{GDBN} command-line word completion facilities to list the
8531available choices, or to finish the type list for you.
8532@xref{Completion,, Command completion}, for details on how to do this.
8533@end table
c906108c 8534
b37303ee
AF
8535@node Objective-C
8536@subsection Objective-C
8537
8538@cindex Objective-C
8539This section provides information about some commands and command
8540options that are useful for debugging Objective-C code.
8541
8542@menu
b383017d
RM
8543* Method Names in Commands::
8544* The Print Command with Objective-C::
b37303ee
AF
8545@end menu
8546
8547@node Method Names in Commands, The Print Command with Objective-C, Objective-C, Objective-C
8548@subsubsection Method Names in Commands
8549
8550The following commands have been extended to accept Objective-C method
8551names as line specifications:
8552
8553@kindex clear@r{, and Objective-C}
8554@kindex break@r{, and Objective-C}
8555@kindex info line@r{, and Objective-C}
8556@kindex jump@r{, and Objective-C}
8557@kindex list@r{, and Objective-C}
8558@itemize
8559@item @code{clear}
8560@item @code{break}
8561@item @code{info line}
8562@item @code{jump}
8563@item @code{list}
8564@end itemize
8565
8566A fully qualified Objective-C method name is specified as
8567
8568@smallexample
8569-[@var{Class} @var{methodName}]
8570@end smallexample
8571
c552b3bb
JM
8572where the minus sign is used to indicate an instance method and a
8573plus sign (not shown) is used to indicate a class method. The class
8574name @var{Class} and method name @var{methodName} are enclosed in
8575brackets, similar to the way messages are specified in Objective-C
8576source code. For example, to set a breakpoint at the @code{create}
8577instance method of class @code{Fruit} in the program currently being
8578debugged, enter:
b37303ee
AF
8579
8580@smallexample
8581break -[Fruit create]
8582@end smallexample
8583
8584To list ten program lines around the @code{initialize} class method,
8585enter:
8586
8587@smallexample
8588list +[NSText initialize]
8589@end smallexample
8590
c552b3bb
JM
8591In the current version of @value{GDBN}, the plus or minus sign is
8592required. In future versions of @value{GDBN}, the plus or minus
8593sign will be optional, but you can use it to narrow the search. It
8594is also possible to specify just a method name:
b37303ee
AF
8595
8596@smallexample
8597break create
8598@end smallexample
8599
8600You must specify the complete method name, including any colons. If
8601your program's source files contain more than one @code{create} method,
8602you'll be presented with a numbered list of classes that implement that
8603method. Indicate your choice by number, or type @samp{0} to exit if
8604none apply.
8605
8606As another example, to clear a breakpoint established at the
8607@code{makeKeyAndOrderFront:} method of the @code{NSWindow} class, enter:
8608
8609@smallexample
8610clear -[NSWindow makeKeyAndOrderFront:]
8611@end smallexample
8612
8613@node The Print Command with Objective-C
8614@subsubsection The Print Command With Objective-C
c552b3bb
JM
8615@kindex print-object
8616@kindex po @r{(@code{print-object})}
b37303ee 8617
c552b3bb 8618The print command has also been extended to accept methods. For example:
b37303ee
AF
8619
8620@smallexample
c552b3bb 8621print -[@var{object} hash]
b37303ee
AF
8622@end smallexample
8623
8624@cindex print an Objective-C object description
c552b3bb
JM
8625@cindex @code{_NSPrintForDebugger}, and printing Objective-C objects
8626@noindent
8627will tell @value{GDBN} to send the @code{hash} message to @var{object}
8628and print the result. Also, an additional command has been added,
8629@code{print-object} or @code{po} for short, which is meant to print
8630the description of an object. However, this command may only work
8631with certain Objective-C libraries that have a particular hook
8632function, @code{_NSPrintForDebugger}, defined.
b37303ee
AF
8633
8634@node Modula-2, , Objective-C, Support
c906108c 8635@subsection Modula-2
7a292a7a 8636
d4f3574e 8637@cindex Modula-2, @value{GDBN} support
c906108c
SS
8638
8639The extensions made to @value{GDBN} to support Modula-2 only support
8640output from the @sc{gnu} Modula-2 compiler (which is currently being
8641developed). Other Modula-2 compilers are not currently supported, and
8642attempting to debug executables produced by them is most likely
8643to give an error as @value{GDBN} reads in the executable's symbol
8644table.
8645
8646@cindex expressions in Modula-2
8647@menu
8648* M2 Operators:: Built-in operators
8649* Built-In Func/Proc:: Built-in functions and procedures
8650* M2 Constants:: Modula-2 constants
8651* M2 Defaults:: Default settings for Modula-2
8652* Deviations:: Deviations from standard Modula-2
8653* M2 Checks:: Modula-2 type and range checks
8654* M2 Scope:: The scope operators @code{::} and @code{.}
8655* GDB/M2:: @value{GDBN} and Modula-2
8656@end menu
8657
6d2ebf8b 8658@node M2 Operators
c906108c
SS
8659@subsubsection Operators
8660@cindex Modula-2 operators
8661
8662Operators must be defined on values of specific types. For instance,
8663@code{+} is defined on numbers, but not on structures. Operators are
8664often defined on groups of types. For the purposes of Modula-2, the
8665following definitions hold:
8666
8667@itemize @bullet
8668
8669@item
8670@emph{Integral types} consist of @code{INTEGER}, @code{CARDINAL}, and
8671their subranges.
8672
8673@item
8674@emph{Character types} consist of @code{CHAR} and its subranges.
8675
8676@item
8677@emph{Floating-point types} consist of @code{REAL}.
8678
8679@item
8680@emph{Pointer types} consist of anything declared as @code{POINTER TO
8681@var{type}}.
8682
8683@item
8684@emph{Scalar types} consist of all of the above.
8685
8686@item
8687@emph{Set types} consist of @code{SET} and @code{BITSET} types.
8688
8689@item
8690@emph{Boolean types} consist of @code{BOOLEAN}.
8691@end itemize
8692
8693@noindent
8694The following operators are supported, and appear in order of
8695increasing precedence:
8696
8697@table @code
8698@item ,
8699Function argument or array index separator.
8700
8701@item :=
8702Assignment. The value of @var{var} @code{:=} @var{value} is
8703@var{value}.
8704
8705@item <@r{, }>
8706Less than, greater than on integral, floating-point, or enumerated
8707types.
8708
8709@item <=@r{, }>=
96a2c332 8710Less than or equal to, greater than or equal to
c906108c
SS
8711on integral, floating-point and enumerated types, or set inclusion on
8712set types. Same precedence as @code{<}.
8713
8714@item =@r{, }<>@r{, }#
8715Equality and two ways of expressing inequality, valid on scalar types.
8716Same precedence as @code{<}. In @value{GDBN} scripts, only @code{<>} is
8717available for inequality, since @code{#} conflicts with the script
8718comment character.
8719
8720@item IN
8721Set membership. Defined on set types and the types of their members.
8722Same precedence as @code{<}.
8723
8724@item OR
8725Boolean disjunction. Defined on boolean types.
8726
8727@item AND@r{, }&
d4f3574e 8728Boolean conjunction. Defined on boolean types.
c906108c
SS
8729
8730@item @@
8731The @value{GDBN} ``artificial array'' operator (@pxref{Expressions, ,Expressions}).
8732
8733@item +@r{, }-
8734Addition and subtraction on integral and floating-point types, or union
8735and difference on set types.
8736
8737@item *
8738Multiplication on integral and floating-point types, or set intersection
8739on set types.
8740
8741@item /
8742Division on floating-point types, or symmetric set difference on set
8743types. Same precedence as @code{*}.
8744
8745@item DIV@r{, }MOD
8746Integer division and remainder. Defined on integral types. Same
8747precedence as @code{*}.
8748
8749@item -
8750Negative. Defined on @code{INTEGER} and @code{REAL} data.
8751
8752@item ^
8753Pointer dereferencing. Defined on pointer types.
8754
8755@item NOT
8756Boolean negation. Defined on boolean types. Same precedence as
8757@code{^}.
8758
8759@item .
8760@code{RECORD} field selector. Defined on @code{RECORD} data. Same
8761precedence as @code{^}.
8762
8763@item []
8764Array indexing. Defined on @code{ARRAY} data. Same precedence as @code{^}.
8765
8766@item ()
8767Procedure argument list. Defined on @code{PROCEDURE} objects. Same precedence
8768as @code{^}.
8769
8770@item ::@r{, }.
8771@value{GDBN} and Modula-2 scope operators.
8772@end table
8773
8774@quotation
8775@emph{Warning:} Sets and their operations are not yet supported, so @value{GDBN}
8776treats the use of the operator @code{IN}, or the use of operators
8777@code{+}, @code{-}, @code{*}, @code{/}, @code{=}, , @code{<>}, @code{#},
8778@code{<=}, and @code{>=} on sets as an error.
8779@end quotation
8780
cb51c4e0 8781
6d2ebf8b 8782@node Built-In Func/Proc
c906108c 8783@subsubsection Built-in functions and procedures
cb51c4e0 8784@cindex Modula-2 built-ins
c906108c
SS
8785
8786Modula-2 also makes available several built-in procedures and functions.
8787In describing these, the following metavariables are used:
8788
8789@table @var
8790
8791@item a
8792represents an @code{ARRAY} variable.
8793
8794@item c
8795represents a @code{CHAR} constant or variable.
8796
8797@item i
8798represents a variable or constant of integral type.
8799
8800@item m
8801represents an identifier that belongs to a set. Generally used in the
8802same function with the metavariable @var{s}. The type of @var{s} should
8803be @code{SET OF @var{mtype}} (where @var{mtype} is the type of @var{m}).
8804
8805@item n
8806represents a variable or constant of integral or floating-point type.
8807
8808@item r
8809represents a variable or constant of floating-point type.
8810
8811@item t
8812represents a type.
8813
8814@item v
8815represents a variable.
8816
8817@item x
8818represents a variable or constant of one of many types. See the
8819explanation of the function for details.
8820@end table
8821
8822All Modula-2 built-in procedures also return a result, described below.
8823
8824@table @code
8825@item ABS(@var{n})
8826Returns the absolute value of @var{n}.
8827
8828@item CAP(@var{c})
8829If @var{c} is a lower case letter, it returns its upper case
c3f6f71d 8830equivalent, otherwise it returns its argument.
c906108c
SS
8831
8832@item CHR(@var{i})
8833Returns the character whose ordinal value is @var{i}.
8834
8835@item DEC(@var{v})
c3f6f71d 8836Decrements the value in the variable @var{v} by one. Returns the new value.
c906108c
SS
8837
8838@item DEC(@var{v},@var{i})
8839Decrements the value in the variable @var{v} by @var{i}. Returns the
8840new value.
8841
8842@item EXCL(@var{m},@var{s})
8843Removes the element @var{m} from the set @var{s}. Returns the new
8844set.
8845
8846@item FLOAT(@var{i})
8847Returns the floating point equivalent of the integer @var{i}.
8848
8849@item HIGH(@var{a})
8850Returns the index of the last member of @var{a}.
8851
8852@item INC(@var{v})
c3f6f71d 8853Increments the value in the variable @var{v} by one. Returns the new value.
c906108c
SS
8854
8855@item INC(@var{v},@var{i})
8856Increments the value in the variable @var{v} by @var{i}. Returns the
8857new value.
8858
8859@item INCL(@var{m},@var{s})
8860Adds the element @var{m} to the set @var{s} if it is not already
8861there. Returns the new set.
8862
8863@item MAX(@var{t})
8864Returns the maximum value of the type @var{t}.
8865
8866@item MIN(@var{t})
8867Returns the minimum value of the type @var{t}.
8868
8869@item ODD(@var{i})
8870Returns boolean TRUE if @var{i} is an odd number.
8871
8872@item ORD(@var{x})
8873Returns the ordinal value of its argument. For example, the ordinal
c3f6f71d
JM
8874value of a character is its @sc{ascii} value (on machines supporting the
8875@sc{ascii} character set). @var{x} must be of an ordered type, which include
c906108c
SS
8876integral, character and enumerated types.
8877
8878@item SIZE(@var{x})
8879Returns the size of its argument. @var{x} can be a variable or a type.
8880
8881@item TRUNC(@var{r})
8882Returns the integral part of @var{r}.
8883
8884@item VAL(@var{t},@var{i})
8885Returns the member of the type @var{t} whose ordinal value is @var{i}.
8886@end table
8887
8888@quotation
8889@emph{Warning:} Sets and their operations are not yet supported, so
8890@value{GDBN} treats the use of procedures @code{INCL} and @code{EXCL} as
8891an error.
8892@end quotation
8893
8894@cindex Modula-2 constants
6d2ebf8b 8895@node M2 Constants
c906108c
SS
8896@subsubsection Constants
8897
8898@value{GDBN} allows you to express the constants of Modula-2 in the following
8899ways:
8900
8901@itemize @bullet
8902
8903@item
8904Integer constants are simply a sequence of digits. When used in an
8905expression, a constant is interpreted to be type-compatible with the
8906rest of the expression. Hexadecimal integers are specified by a
8907trailing @samp{H}, and octal integers by a trailing @samp{B}.
8908
8909@item
8910Floating point constants appear as a sequence of digits, followed by a
8911decimal point and another sequence of digits. An optional exponent can
8912then be specified, in the form @samp{E@r{[}+@r{|}-@r{]}@var{nnn}}, where
8913@samp{@r{[}+@r{|}-@r{]}@var{nnn}} is the desired exponent. All of the
8914digits of the floating point constant must be valid decimal (base 10)
8915digits.
8916
8917@item
8918Character constants consist of a single character enclosed by a pair of
8919like quotes, either single (@code{'}) or double (@code{"}). They may
c3f6f71d 8920also be expressed by their ordinal value (their @sc{ascii} value, usually)
c906108c
SS
8921followed by a @samp{C}.
8922
8923@item
8924String constants consist of a sequence of characters enclosed by a
8925pair of like quotes, either single (@code{'}) or double (@code{"}).
8926Escape sequences in the style of C are also allowed. @xref{C
b37052ae 8927Constants, ,C and C@t{++} constants}, for a brief explanation of escape
c906108c
SS
8928sequences.
8929
8930@item
8931Enumerated constants consist of an enumerated identifier.
8932
8933@item
8934Boolean constants consist of the identifiers @code{TRUE} and
8935@code{FALSE}.
8936
8937@item
8938Pointer constants consist of integral values only.
8939
8940@item
8941Set constants are not yet supported.
8942@end itemize
8943
6d2ebf8b 8944@node M2 Defaults
c906108c
SS
8945@subsubsection Modula-2 defaults
8946@cindex Modula-2 defaults
8947
8948If type and range checking are set automatically by @value{GDBN}, they
8949both default to @code{on} whenever the working language changes to
d4f3574e 8950Modula-2. This happens regardless of whether you or @value{GDBN}
c906108c
SS
8951selected the working language.
8952
8953If you allow @value{GDBN} to set the language automatically, then entering
8954code compiled from a file whose name ends with @file{.mod} sets the
d4f3574e 8955working language to Modula-2. @xref{Automatically, ,Having @value{GDBN} set
c906108c
SS
8956the language automatically}, for further details.
8957
6d2ebf8b 8958@node Deviations
c906108c
SS
8959@subsubsection Deviations from standard Modula-2
8960@cindex Modula-2, deviations from
8961
8962A few changes have been made to make Modula-2 programs easier to debug.
8963This is done primarily via loosening its type strictness:
8964
8965@itemize @bullet
8966@item
8967Unlike in standard Modula-2, pointer constants can be formed by
8968integers. This allows you to modify pointer variables during
8969debugging. (In standard Modula-2, the actual address contained in a
8970pointer variable is hidden from you; it can only be modified
8971through direct assignment to another pointer variable or expression that
8972returned a pointer.)
8973
8974@item
8975C escape sequences can be used in strings and characters to represent
8976non-printable characters. @value{GDBN} prints out strings with these
8977escape sequences embedded. Single non-printable characters are
8978printed using the @samp{CHR(@var{nnn})} format.
8979
8980@item
8981The assignment operator (@code{:=}) returns the value of its right-hand
8982argument.
8983
8984@item
8985All built-in procedures both modify @emph{and} return their argument.
8986@end itemize
8987
6d2ebf8b 8988@node M2 Checks
c906108c
SS
8989@subsubsection Modula-2 type and range checks
8990@cindex Modula-2 checks
8991
8992@quotation
8993@emph{Warning:} in this release, @value{GDBN} does not yet perform type or
8994range checking.
8995@end quotation
8996@c FIXME remove warning when type/range checks added
8997
8998@value{GDBN} considers two Modula-2 variables type equivalent if:
8999
9000@itemize @bullet
9001@item
9002They are of types that have been declared equivalent via a @code{TYPE
9003@var{t1} = @var{t2}} statement
9004
9005@item
9006They have been declared on the same line. (Note: This is true of the
9007@sc{gnu} Modula-2 compiler, but it may not be true of other compilers.)
9008@end itemize
9009
9010As long as type checking is enabled, any attempt to combine variables
9011whose types are not equivalent is an error.
9012
9013Range checking is done on all mathematical operations, assignment, array
9014index bounds, and all built-in functions and procedures.
9015
6d2ebf8b 9016@node M2 Scope
c906108c
SS
9017@subsubsection The scope operators @code{::} and @code{.}
9018@cindex scope
41afff9a 9019@cindex @code{.}, Modula-2 scope operator
c906108c
SS
9020@cindex colon, doubled as scope operator
9021@ifinfo
41afff9a 9022@vindex colon-colon@r{, in Modula-2}
c906108c
SS
9023@c Info cannot handle :: but TeX can.
9024@end ifinfo
9025@iftex
41afff9a 9026@vindex ::@r{, in Modula-2}
c906108c
SS
9027@end iftex
9028
9029There are a few subtle differences between the Modula-2 scope operator
9030(@code{.}) and the @value{GDBN} scope operator (@code{::}). The two have
9031similar syntax:
9032
474c8240 9033@smallexample
c906108c
SS
9034
9035@var{module} . @var{id}
9036@var{scope} :: @var{id}
474c8240 9037@end smallexample
c906108c
SS
9038
9039@noindent
9040where @var{scope} is the name of a module or a procedure,
9041@var{module} the name of a module, and @var{id} is any declared
9042identifier within your program, except another module.
9043
9044Using the @code{::} operator makes @value{GDBN} search the scope
9045specified by @var{scope} for the identifier @var{id}. If it is not
9046found in the specified scope, then @value{GDBN} searches all scopes
9047enclosing the one specified by @var{scope}.
9048
9049Using the @code{.} operator makes @value{GDBN} search the current scope for
9050the identifier specified by @var{id} that was imported from the
9051definition module specified by @var{module}. With this operator, it is
9052an error if the identifier @var{id} was not imported from definition
9053module @var{module}, or if @var{id} is not an identifier in
9054@var{module}.
9055
6d2ebf8b 9056@node GDB/M2
c906108c
SS
9057@subsubsection @value{GDBN} and Modula-2
9058
9059Some @value{GDBN} commands have little use when debugging Modula-2 programs.
9060Five subcommands of @code{set print} and @code{show print} apply
b37052ae 9061specifically to C and C@t{++}: @samp{vtbl}, @samp{demangle},
c906108c 9062@samp{asm-demangle}, @samp{object}, and @samp{union}. The first four
b37052ae 9063apply to C@t{++}, and the last to the C @code{union} type, which has no direct
c906108c
SS
9064analogue in Modula-2.
9065
9066The @code{@@} operator (@pxref{Expressions, ,Expressions}), while available
d4f3574e 9067with any language, is not useful with Modula-2. Its
c906108c 9068intent is to aid the debugging of @dfn{dynamic arrays}, which cannot be
b37052ae 9069created in Modula-2 as they can in C or C@t{++}. However, because an
c906108c 9070address can be specified by an integral constant, the construct
d4f3574e 9071@samp{@{@var{type}@}@var{adrexp}} is still useful.
c906108c
SS
9072
9073@cindex @code{#} in Modula-2
9074In @value{GDBN} scripts, the Modula-2 inequality operator @code{#} is
9075interpreted as the beginning of a comment. Use @code{<>} instead.
c906108c 9076
4e562065
JB
9077@node Unsupported languages
9078@section Unsupported languages
9079
9080@cindex unsupported languages
9081@cindex minimal language
9082In addition to the other fully-supported programming languages,
9083@value{GDBN} also provides a pseudo-language, called @code{minimal}.
9084It does not represent a real programming language, but provides a set
9085of capabilities close to what the C or assembly languages provide.
9086This should allow most simple operations to be performed while debugging
9087an application that uses a language currently not supported by @value{GDBN}.
9088
9089If the language is set to @code{auto}, @value{GDBN} will automatically
9090select this language if the current frame corresponds to an unsupported
9091language.
9092
6d2ebf8b 9093@node Symbols
c906108c
SS
9094@chapter Examining the Symbol Table
9095
d4f3574e 9096The commands described in this chapter allow you to inquire about the
c906108c
SS
9097symbols (names of variables, functions and types) defined in your
9098program. This information is inherent in the text of your program and
9099does not change as your program executes. @value{GDBN} finds it in your
9100program's symbol table, in the file indicated when you started @value{GDBN}
9101(@pxref{File Options, ,Choosing files}), or by one of the
9102file-management commands (@pxref{Files, ,Commands to specify files}).
9103
9104@cindex symbol names
9105@cindex names of symbols
9106@cindex quoting names
9107Occasionally, you may need to refer to symbols that contain unusual
9108characters, which @value{GDBN} ordinarily treats as word delimiters. The
9109most frequent case is in referring to static variables in other
9110source files (@pxref{Variables,,Program variables}). File names
9111are recorded in object files as debugging symbols, but @value{GDBN} would
9112ordinarily parse a typical file name, like @file{foo.c}, as the three words
9113@samp{foo} @samp{.} @samp{c}. To allow @value{GDBN} to recognize
9114@samp{foo.c} as a single symbol, enclose it in single quotes; for example,
9115
474c8240 9116@smallexample
c906108c 9117p 'foo.c'::x
474c8240 9118@end smallexample
c906108c
SS
9119
9120@noindent
9121looks up the value of @code{x} in the scope of the file @file{foo.c}.
9122
9123@table @code
9124@kindex info address
b37052ae 9125@cindex address of a symbol
c906108c
SS
9126@item info address @var{symbol}
9127Describe where the data for @var{symbol} is stored. For a register
9128variable, this says which register it is kept in. For a non-register
9129local variable, this prints the stack-frame offset at which the variable
9130is always stored.
9131
9132Note the contrast with @samp{print &@var{symbol}}, which does not work
9133at all for a register variable, and for a stack local variable prints
9134the exact address of the current instantiation of the variable.
9135
3d67e040 9136@kindex info symbol
b37052ae 9137@cindex symbol from address
3d67e040
EZ
9138@item info symbol @var{addr}
9139Print the name of a symbol which is stored at the address @var{addr}.
9140If no symbol is stored exactly at @var{addr}, @value{GDBN} prints the
9141nearest symbol and an offset from it:
9142
474c8240 9143@smallexample
3d67e040
EZ
9144(@value{GDBP}) info symbol 0x54320
9145_initialize_vx + 396 in section .text
474c8240 9146@end smallexample
3d67e040
EZ
9147
9148@noindent
9149This is the opposite of the @code{info address} command. You can use
9150it to find out the name of a variable or a function given its address.
9151
c906108c 9152@kindex whatis
d4f3574e
SS
9153@item whatis @var{expr}
9154Print the data type of expression @var{expr}. @var{expr} is not
c906108c
SS
9155actually evaluated, and any side-effecting operations (such as
9156assignments or function calls) inside it do not take place.
9157@xref{Expressions, ,Expressions}.
9158
9159@item whatis
9160Print the data type of @code{$}, the last value in the value history.
9161
9162@kindex ptype
9163@item ptype @var{typename}
9164Print a description of data type @var{typename}. @var{typename} may be
7a292a7a
SS
9165the name of a type, or for C code it may have the form @samp{class
9166@var{class-name}}, @samp{struct @var{struct-tag}}, @samp{union
9167@var{union-tag}} or @samp{enum @var{enum-tag}}.
c906108c 9168
d4f3574e 9169@item ptype @var{expr}
c906108c 9170@itemx ptype
d4f3574e 9171Print a description of the type of expression @var{expr}. @code{ptype}
c906108c
SS
9172differs from @code{whatis} by printing a detailed description, instead
9173of just the name of the type.
9174
9175For example, for this variable declaration:
9176
474c8240 9177@smallexample
c906108c 9178struct complex @{double real; double imag;@} v;
474c8240 9179@end smallexample
c906108c
SS
9180
9181@noindent
9182the two commands give this output:
9183
474c8240 9184@smallexample
c906108c
SS
9185@group
9186(@value{GDBP}) whatis v
9187type = struct complex
9188(@value{GDBP}) ptype v
9189type = struct complex @{
9190 double real;
9191 double imag;
9192@}
9193@end group
474c8240 9194@end smallexample
c906108c
SS
9195
9196@noindent
9197As with @code{whatis}, using @code{ptype} without an argument refers to
9198the type of @code{$}, the last value in the value history.
9199
9200@kindex info types
9201@item info types @var{regexp}
9202@itemx info types
d4f3574e 9203Print a brief description of all types whose names match @var{regexp}
c906108c
SS
9204(or all types in your program, if you supply no argument). Each
9205complete typename is matched as though it were a complete line; thus,
9206@samp{i type value} gives information on all types in your program whose
d4f3574e 9207names include the string @code{value}, but @samp{i type ^value$} gives
c906108c
SS
9208information only on types whose complete name is @code{value}.
9209
9210This command differs from @code{ptype} in two ways: first, like
9211@code{whatis}, it does not print a detailed description; second, it
9212lists all source files where a type is defined.
9213
b37052ae
EZ
9214@kindex info scope
9215@cindex local variables
9216@item info scope @var{addr}
9217List all the variables local to a particular scope. This command
9218accepts a location---a function name, a source line, or an address
9219preceded by a @samp{*}, and prints all the variables local to the
9220scope defined by that location. For example:
9221
9222@smallexample
9223(@value{GDBP}) @b{info scope command_line_handler}
9224Scope for command_line_handler:
9225Symbol rl is an argument at stack/frame offset 8, length 4.
9226Symbol linebuffer is in static storage at address 0x150a18, length 4.
9227Symbol linelength is in static storage at address 0x150a1c, length 4.
9228Symbol p is a local variable in register $esi, length 4.
9229Symbol p1 is a local variable in register $ebx, length 4.
9230Symbol nline is a local variable in register $edx, length 4.
9231Symbol repeat is a local variable at frame offset -8, length 4.
9232@end smallexample
9233
f5c37c66
EZ
9234@noindent
9235This command is especially useful for determining what data to collect
9236during a @dfn{trace experiment}, see @ref{Tracepoint Actions,
9237collect}.
9238
c906108c
SS
9239@kindex info source
9240@item info source
919d772c
JB
9241Show information about the current source file---that is, the source file for
9242the function containing the current point of execution:
9243@itemize @bullet
9244@item
9245the name of the source file, and the directory containing it,
9246@item
9247the directory it was compiled in,
9248@item
9249its length, in lines,
9250@item
9251which programming language it is written in,
9252@item
9253whether the executable includes debugging information for that file, and
9254if so, what format the information is in (e.g., STABS, Dwarf 2, etc.), and
9255@item
9256whether the debugging information includes information about
9257preprocessor macros.
9258@end itemize
9259
c906108c
SS
9260
9261@kindex info sources
9262@item info sources
9263Print the names of all source files in your program for which there is
9264debugging information, organized into two lists: files whose symbols
9265have already been read, and files whose symbols will be read when needed.
9266
9267@kindex info functions
9268@item info functions
9269Print the names and data types of all defined functions.
9270
9271@item info functions @var{regexp}
9272Print the names and data types of all defined functions
9273whose names contain a match for regular expression @var{regexp}.
9274Thus, @samp{info fun step} finds all functions whose names
9275include @code{step}; @samp{info fun ^step} finds those whose names
b383017d
RM
9276start with @code{step}. If a function name contains characters
9277that conflict with the regular expression language (eg.
1c5dfdad 9278@samp{operator*()}), they may be quoted with a backslash.
c906108c
SS
9279
9280@kindex info variables
9281@item info variables
9282Print the names and data types of all variables that are declared
6ca652b0 9283outside of functions (i.e.@: excluding local variables).
c906108c
SS
9284
9285@item info variables @var{regexp}
9286Print the names and data types of all variables (except for local
9287variables) whose names contain a match for regular expression
9288@var{regexp}.
9289
b37303ee
AF
9290@kindex info classes
9291@item info classes
9292@itemx info classes @var{regexp}
9293Display all Objective-C classes in your program, or
9294(with the @var{regexp} argument) all those matching a particular regular
9295expression.
9296
9297@kindex info selectors
9298@item info selectors
9299@itemx info selectors @var{regexp}
9300Display all Objective-C selectors in your program, or
9301(with the @var{regexp} argument) all those matching a particular regular
9302expression.
9303
c906108c
SS
9304@ignore
9305This was never implemented.
9306@kindex info methods
9307@item info methods
9308@itemx info methods @var{regexp}
9309The @code{info methods} command permits the user to examine all defined
b37052ae
EZ
9310methods within C@t{++} program, or (with the @var{regexp} argument) a
9311specific set of methods found in the various C@t{++} classes. Many
9312C@t{++} classes provide a large number of methods. Thus, the output
c906108c
SS
9313from the @code{ptype} command can be overwhelming and hard to use. The
9314@code{info-methods} command filters the methods, printing only those
9315which match the regular-expression @var{regexp}.
9316@end ignore
9317
c906108c
SS
9318@cindex reloading symbols
9319Some systems allow individual object files that make up your program to
7a292a7a
SS
9320be replaced without stopping and restarting your program. For example,
9321in VxWorks you can simply recompile a defective object file and keep on
9322running. If you are running on one of these systems, you can allow
9323@value{GDBN} to reload the symbols for automatically relinked modules:
c906108c
SS
9324
9325@table @code
9326@kindex set symbol-reloading
9327@item set symbol-reloading on
9328Replace symbol definitions for the corresponding source file when an
9329object file with a particular name is seen again.
9330
9331@item set symbol-reloading off
6d2ebf8b
SS
9332Do not replace symbol definitions when encountering object files of the
9333same name more than once. This is the default state; if you are not
9334running on a system that permits automatic relinking of modules, you
9335should leave @code{symbol-reloading} off, since otherwise @value{GDBN}
9336may discard symbols when linking large programs, that may contain
9337several modules (from different directories or libraries) with the same
9338name.
c906108c
SS
9339
9340@kindex show symbol-reloading
9341@item show symbol-reloading
9342Show the current @code{on} or @code{off} setting.
9343@end table
c906108c 9344
c906108c
SS
9345@kindex set opaque-type-resolution
9346@item set opaque-type-resolution on
9347Tell @value{GDBN} to resolve opaque types. An opaque type is a type
9348declared as a pointer to a @code{struct}, @code{class}, or
9349@code{union}---for example, @code{struct MyType *}---that is used in one
9350source file although the full declaration of @code{struct MyType} is in
9351another source file. The default is on.
9352
9353A change in the setting of this subcommand will not take effect until
9354the next time symbols for a file are loaded.
9355
9356@item set opaque-type-resolution off
9357Tell @value{GDBN} not to resolve opaque types. In this case, the type
9358is printed as follows:
9359@smallexample
9360@{<no data fields>@}
9361@end smallexample
9362
9363@kindex show opaque-type-resolution
9364@item show opaque-type-resolution
9365Show whether opaque types are resolved or not.
c906108c
SS
9366
9367@kindex maint print symbols
9368@cindex symbol dump
9369@kindex maint print psymbols
9370@cindex partial symbol dump
9371@item maint print symbols @var{filename}
9372@itemx maint print psymbols @var{filename}
9373@itemx maint print msymbols @var{filename}
9374Write a dump of debugging symbol data into the file @var{filename}.
9375These commands are used to debug the @value{GDBN} symbol-reading code. Only
9376symbols with debugging data are included. If you use @samp{maint print
9377symbols}, @value{GDBN} includes all the symbols for which it has already
9378collected full details: that is, @var{filename} reflects symbols for
9379only those files whose symbols @value{GDBN} has read. You can use the
9380command @code{info sources} to find out which files these are. If you
9381use @samp{maint print psymbols} instead, the dump shows information about
9382symbols that @value{GDBN} only knows partially---that is, symbols defined in
9383files that @value{GDBN} has skimmed, but not yet read completely. Finally,
9384@samp{maint print msymbols} dumps just the minimal symbol information
9385required for each object file from which @value{GDBN} has read some symbols.
9386@xref{Files, ,Commands to specify files}, for a discussion of how
9387@value{GDBN} reads symbols (in the description of @code{symbol-file}).
44ea7b70 9388
5e7b2f39
JB
9389@kindex maint info symtabs
9390@kindex maint info psymtabs
44ea7b70
JB
9391@cindex listing @value{GDBN}'s internal symbol tables
9392@cindex symbol tables, listing @value{GDBN}'s internal
9393@cindex full symbol tables, listing @value{GDBN}'s internal
9394@cindex partial symbol tables, listing @value{GDBN}'s internal
5e7b2f39
JB
9395@item maint info symtabs @r{[} @var{regexp} @r{]}
9396@itemx maint info psymtabs @r{[} @var{regexp} @r{]}
44ea7b70
JB
9397
9398List the @code{struct symtab} or @code{struct partial_symtab}
9399structures whose names match @var{regexp}. If @var{regexp} is not
9400given, list them all. The output includes expressions which you can
9401copy into a @value{GDBN} debugging this one to examine a particular
9402structure in more detail. For example:
9403
9404@smallexample
5e7b2f39 9405(@value{GDBP}) maint info psymtabs dwarf2read
44ea7b70
JB
9406@{ objfile /home/gnu/build/gdb/gdb
9407 ((struct objfile *) 0x82e69d0)
b383017d 9408 @{ psymtab /home/gnu/src/gdb/dwarf2read.c
44ea7b70
JB
9409 ((struct partial_symtab *) 0x8474b10)
9410 readin no
9411 fullname (null)
9412 text addresses 0x814d3c8 -- 0x8158074
9413 globals (* (struct partial_symbol **) 0x8507a08 @@ 9)
9414 statics (* (struct partial_symbol **) 0x40e95b78 @@ 2882)
9415 dependencies (none)
9416 @}
9417@}
5e7b2f39 9418(@value{GDBP}) maint info symtabs
44ea7b70
JB
9419(@value{GDBP})
9420@end smallexample
9421@noindent
9422We see that there is one partial symbol table whose filename contains
9423the string @samp{dwarf2read}, belonging to the @samp{gdb} executable;
9424and we see that @value{GDBN} has not read in any symtabs yet at all.
9425If we set a breakpoint on a function, that will cause @value{GDBN} to
9426read the symtab for the compilation unit containing that function:
9427
9428@smallexample
9429(@value{GDBP}) break dwarf2_psymtab_to_symtab
9430Breakpoint 1 at 0x814e5da: file /home/gnu/src/gdb/dwarf2read.c,
9431line 1574.
5e7b2f39 9432(@value{GDBP}) maint info symtabs
b383017d 9433@{ objfile /home/gnu/build/gdb/gdb
44ea7b70 9434 ((struct objfile *) 0x82e69d0)
b383017d 9435 @{ symtab /home/gnu/src/gdb/dwarf2read.c
44ea7b70
JB
9436 ((struct symtab *) 0x86c1f38)
9437 dirname (null)
9438 fullname (null)
9439 blockvector ((struct blockvector *) 0x86c1bd0) (primary)
9440 debugformat DWARF 2
9441 @}
9442@}
b383017d 9443(@value{GDBP})
44ea7b70 9444@end smallexample
c906108c
SS
9445@end table
9446
44ea7b70 9447
6d2ebf8b 9448@node Altering
c906108c
SS
9449@chapter Altering Execution
9450
9451Once you think you have found an error in your program, you might want to
9452find out for certain whether correcting the apparent error would lead to
9453correct results in the rest of the run. You can find the answer by
9454experiment, using the @value{GDBN} features for altering execution of the
9455program.
9456
9457For example, you can store new values into variables or memory
7a292a7a
SS
9458locations, give your program a signal, restart it at a different
9459address, or even return prematurely from a function.
c906108c
SS
9460
9461@menu
9462* Assignment:: Assignment to variables
9463* Jumping:: Continuing at a different address
c906108c 9464* Signaling:: Giving your program a signal
c906108c
SS
9465* Returning:: Returning from a function
9466* Calling:: Calling your program's functions
9467* Patching:: Patching your program
9468@end menu
9469
6d2ebf8b 9470@node Assignment
c906108c
SS
9471@section Assignment to variables
9472
9473@cindex assignment
9474@cindex setting variables
9475To alter the value of a variable, evaluate an assignment expression.
9476@xref{Expressions, ,Expressions}. For example,
9477
474c8240 9478@smallexample
c906108c 9479print x=4
474c8240 9480@end smallexample
c906108c
SS
9481
9482@noindent
9483stores the value 4 into the variable @code{x}, and then prints the
5d161b24 9484value of the assignment expression (which is 4).
c906108c
SS
9485@xref{Languages, ,Using @value{GDBN} with Different Languages}, for more
9486information on operators in supported languages.
c906108c
SS
9487
9488@kindex set variable
9489@cindex variables, setting
9490If you are not interested in seeing the value of the assignment, use the
9491@code{set} command instead of the @code{print} command. @code{set} is
9492really the same as @code{print} except that the expression's value is
9493not printed and is not put in the value history (@pxref{Value History,
9494,Value history}). The expression is evaluated only for its effects.
9495
c906108c
SS
9496If the beginning of the argument string of the @code{set} command
9497appears identical to a @code{set} subcommand, use the @code{set
9498variable} command instead of just @code{set}. This command is identical
9499to @code{set} except for its lack of subcommands. For example, if your
9500program has a variable @code{width}, you get an error if you try to set
9501a new value with just @samp{set width=13}, because @value{GDBN} has the
9502command @code{set width}:
9503
474c8240 9504@smallexample
c906108c
SS
9505(@value{GDBP}) whatis width
9506type = double
9507(@value{GDBP}) p width
9508$4 = 13
9509(@value{GDBP}) set width=47
9510Invalid syntax in expression.
474c8240 9511@end smallexample
c906108c
SS
9512
9513@noindent
9514The invalid expression, of course, is @samp{=47}. In
9515order to actually set the program's variable @code{width}, use
9516
474c8240 9517@smallexample
c906108c 9518(@value{GDBP}) set var width=47
474c8240 9519@end smallexample
53a5351d 9520
c906108c
SS
9521Because the @code{set} command has many subcommands that can conflict
9522with the names of program variables, it is a good idea to use the
9523@code{set variable} command instead of just @code{set}. For example, if
9524your program has a variable @code{g}, you run into problems if you try
9525to set a new value with just @samp{set g=4}, because @value{GDBN} has
9526the command @code{set gnutarget}, abbreviated @code{set g}:
9527
474c8240 9528@smallexample
c906108c
SS
9529@group
9530(@value{GDBP}) whatis g
9531type = double
9532(@value{GDBP}) p g
9533$1 = 1
9534(@value{GDBP}) set g=4
2df3850c 9535(@value{GDBP}) p g
c906108c
SS
9536$2 = 1
9537(@value{GDBP}) r
9538The program being debugged has been started already.
9539Start it from the beginning? (y or n) y
9540Starting program: /home/smith/cc_progs/a.out
6d2ebf8b
SS
9541"/home/smith/cc_progs/a.out": can't open to read symbols:
9542 Invalid bfd target.
c906108c
SS
9543(@value{GDBP}) show g
9544The current BFD target is "=4".
9545@end group
474c8240 9546@end smallexample
c906108c
SS
9547
9548@noindent
9549The program variable @code{g} did not change, and you silently set the
9550@code{gnutarget} to an invalid value. In order to set the variable
9551@code{g}, use
9552
474c8240 9553@smallexample
c906108c 9554(@value{GDBP}) set var g=4
474c8240 9555@end smallexample
c906108c
SS
9556
9557@value{GDBN} allows more implicit conversions in assignments than C; you can
9558freely store an integer value into a pointer variable or vice versa,
9559and you can convert any structure to any other structure that is the
9560same length or shorter.
9561@comment FIXME: how do structs align/pad in these conversions?
9562@comment /doc@cygnus.com 18dec1990
9563
9564To store values into arbitrary places in memory, use the @samp{@{@dots{}@}}
9565construct to generate a value of specified type at a specified address
9566(@pxref{Expressions, ,Expressions}). For example, @code{@{int@}0x83040} refers
9567to memory location @code{0x83040} as an integer (which implies a certain size
9568and representation in memory), and
9569
474c8240 9570@smallexample
c906108c 9571set @{int@}0x83040 = 4
474c8240 9572@end smallexample
c906108c
SS
9573
9574@noindent
9575stores the value 4 into that memory location.
9576
6d2ebf8b 9577@node Jumping
c906108c
SS
9578@section Continuing at a different address
9579
9580Ordinarily, when you continue your program, you do so at the place where
9581it stopped, with the @code{continue} command. You can instead continue at
9582an address of your own choosing, with the following commands:
9583
9584@table @code
9585@kindex jump
9586@item jump @var{linespec}
9587Resume execution at line @var{linespec}. Execution stops again
9588immediately if there is a breakpoint there. @xref{List, ,Printing
9589source lines}, for a description of the different forms of
9590@var{linespec}. It is common practice to use the @code{tbreak} command
9591in conjunction with @code{jump}. @xref{Set Breaks, ,Setting
9592breakpoints}.
9593
9594The @code{jump} command does not change the current stack frame, or
9595the stack pointer, or the contents of any memory location or any
9596register other than the program counter. If line @var{linespec} is in
9597a different function from the one currently executing, the results may
9598be bizarre if the two functions expect different patterns of arguments or
9599of local variables. For this reason, the @code{jump} command requests
9600confirmation if the specified line is not in the function currently
9601executing. However, even bizarre results are predictable if you are
9602well acquainted with the machine-language code of your program.
9603
9604@item jump *@var{address}
9605Resume execution at the instruction at address @var{address}.
9606@end table
9607
c906108c 9608@c Doesn't work on HP-UX; have to set $pcoqh and $pcoqt.
53a5351d
JM
9609On many systems, you can get much the same effect as the @code{jump}
9610command by storing a new value into the register @code{$pc}. The
9611difference is that this does not start your program running; it only
9612changes the address of where it @emph{will} run when you continue. For
9613example,
c906108c 9614
474c8240 9615@smallexample
c906108c 9616set $pc = 0x485
474c8240 9617@end smallexample
c906108c
SS
9618
9619@noindent
9620makes the next @code{continue} command or stepping command execute at
9621address @code{0x485}, rather than at the address where your program stopped.
9622@xref{Continuing and Stepping, ,Continuing and stepping}.
c906108c
SS
9623
9624The most common occasion to use the @code{jump} command is to back
9625up---perhaps with more breakpoints set---over a portion of a program
9626that has already executed, in order to examine its execution in more
9627detail.
9628
c906108c 9629@c @group
6d2ebf8b 9630@node Signaling
c906108c
SS
9631@section Giving your program a signal
9632
9633@table @code
9634@kindex signal
9635@item signal @var{signal}
9636Resume execution where your program stopped, but immediately give it the
9637signal @var{signal}. @var{signal} can be the name or the number of a
9638signal. For example, on many systems @code{signal 2} and @code{signal
9639SIGINT} are both ways of sending an interrupt signal.
9640
9641Alternatively, if @var{signal} is zero, continue execution without
9642giving a signal. This is useful when your program stopped on account of
9643a signal and would ordinary see the signal when resumed with the
9644@code{continue} command; @samp{signal 0} causes it to resume without a
9645signal.
9646
9647@code{signal} does not repeat when you press @key{RET} a second time
9648after executing the command.
9649@end table
9650@c @end group
9651
9652Invoking the @code{signal} command is not the same as invoking the
9653@code{kill} utility from the shell. Sending a signal with @code{kill}
9654causes @value{GDBN} to decide what to do with the signal depending on
9655the signal handling tables (@pxref{Signals}). The @code{signal} command
9656passes the signal directly to your program.
9657
c906108c 9658
6d2ebf8b 9659@node Returning
c906108c
SS
9660@section Returning from a function
9661
9662@table @code
9663@cindex returning from a function
9664@kindex return
9665@item return
9666@itemx return @var{expression}
9667You can cancel execution of a function call with the @code{return}
9668command. If you give an
9669@var{expression} argument, its value is used as the function's return
9670value.
9671@end table
9672
9673When you use @code{return}, @value{GDBN} discards the selected stack frame
9674(and all frames within it). You can think of this as making the
9675discarded frame return prematurely. If you wish to specify a value to
9676be returned, give that value as the argument to @code{return}.
9677
9678This pops the selected stack frame (@pxref{Selection, ,Selecting a
9679frame}), and any other frames inside of it, leaving its caller as the
9680innermost remaining frame. That frame becomes selected. The
9681specified value is stored in the registers used for returning values
9682of functions.
9683
9684The @code{return} command does not resume execution; it leaves the
9685program stopped in the state that would exist if the function had just
9686returned. In contrast, the @code{finish} command (@pxref{Continuing
9687and Stepping, ,Continuing and stepping}) resumes execution until the
9688selected stack frame returns naturally.
9689
6d2ebf8b 9690@node Calling
c906108c
SS
9691@section Calling program functions
9692
9693@cindex calling functions
9694@kindex call
9695@table @code
9696@item call @var{expr}
9697Evaluate the expression @var{expr} without displaying @code{void}
9698returned values.
9699@end table
9700
9701You can use this variant of the @code{print} command if you want to
9702execute a function from your program, but without cluttering the output
5d161b24
DB
9703with @code{void} returned values. If the result is not void, it
9704is printed and saved in the value history.
c906108c 9705
6d2ebf8b 9706@node Patching
c906108c 9707@section Patching programs
7a292a7a 9708
c906108c
SS
9709@cindex patching binaries
9710@cindex writing into executables
c906108c 9711@cindex writing into corefiles
c906108c 9712
7a292a7a
SS
9713By default, @value{GDBN} opens the file containing your program's
9714executable code (or the corefile) read-only. This prevents accidental
9715alterations to machine code; but it also prevents you from intentionally
9716patching your program's binary.
c906108c
SS
9717
9718If you'd like to be able to patch the binary, you can specify that
9719explicitly with the @code{set write} command. For example, you might
9720want to turn on internal debugging flags, or even to make emergency
9721repairs.
9722
9723@table @code
9724@kindex set write
9725@item set write on
9726@itemx set write off
7a292a7a
SS
9727If you specify @samp{set write on}, @value{GDBN} opens executable and
9728core files for both reading and writing; if you specify @samp{set write
c906108c
SS
9729off} (the default), @value{GDBN} opens them read-only.
9730
9731If you have already loaded a file, you must load it again (using the
7a292a7a
SS
9732@code{exec-file} or @code{core-file} command) after changing @code{set
9733write}, for your new setting to take effect.
c906108c
SS
9734
9735@item show write
9736@kindex show write
7a292a7a
SS
9737Display whether executable files and core files are opened for writing
9738as well as reading.
c906108c
SS
9739@end table
9740
6d2ebf8b 9741@node GDB Files
c906108c
SS
9742@chapter @value{GDBN} Files
9743
7a292a7a
SS
9744@value{GDBN} needs to know the file name of the program to be debugged,
9745both in order to read its symbol table and in order to start your
9746program. To debug a core dump of a previous run, you must also tell
9747@value{GDBN} the name of the core dump file.
c906108c
SS
9748
9749@menu
9750* Files:: Commands to specify files
5b5d99cf 9751* Separate Debug Files:: Debugging information in separate files
c906108c
SS
9752* Symbol Errors:: Errors reading symbol files
9753@end menu
9754
6d2ebf8b 9755@node Files
c906108c 9756@section Commands to specify files
c906108c 9757
7a292a7a 9758@cindex symbol table
c906108c 9759@cindex core dump file
7a292a7a
SS
9760
9761You may want to specify executable and core dump file names. The usual
9762way to do this is at start-up time, using the arguments to
9763@value{GDBN}'s start-up commands (@pxref{Invocation, , Getting In and
9764Out of @value{GDBN}}).
c906108c
SS
9765
9766Occasionally it is necessary to change to a different file during a
9767@value{GDBN} session. Or you may run @value{GDBN} and forget to specify
9768a file you want to use. In these situations the @value{GDBN} commands
9769to specify new files are useful.
9770
9771@table @code
9772@cindex executable file
9773@kindex file
9774@item file @var{filename}
9775Use @var{filename} as the program to be debugged. It is read for its
9776symbols and for the contents of pure memory. It is also the program
9777executed when you use the @code{run} command. If you do not specify a
5d161b24
DB
9778directory and the file is not found in the @value{GDBN} working directory,
9779@value{GDBN} uses the environment variable @code{PATH} as a list of
9780directories to search, just as the shell does when looking for a program
9781to run. You can change the value of this variable, for both @value{GDBN}
c906108c
SS
9782and your program, using the @code{path} command.
9783
6d2ebf8b 9784On systems with memory-mapped files, an auxiliary file named
c906108c
SS
9785@file{@var{filename}.syms} may hold symbol table information for
9786@var{filename}. If so, @value{GDBN} maps in the symbol table from
9787@file{@var{filename}.syms}, starting up more quickly. See the
9788descriptions of the file options @samp{-mapped} and @samp{-readnow}
9789(available on the command line, and with the commands @code{file},
5d161b24 9790@code{symbol-file}, or @code{add-symbol-file}, described below),
c906108c 9791for more information.
c906108c
SS
9792
9793@item file
9794@code{file} with no argument makes @value{GDBN} discard any information it
9795has on both executable file and the symbol table.
9796
9797@kindex exec-file
9798@item exec-file @r{[} @var{filename} @r{]}
9799Specify that the program to be run (but not the symbol table) is found
9800in @var{filename}. @value{GDBN} searches the environment variable @code{PATH}
9801if necessary to locate your program. Omitting @var{filename} means to
9802discard information on the executable file.
9803
9804@kindex symbol-file
9805@item symbol-file @r{[} @var{filename} @r{]}
9806Read symbol table information from file @var{filename}. @code{PATH} is
9807searched when necessary. Use the @code{file} command to get both symbol
9808table and program to run from the same file.
9809
9810@code{symbol-file} with no argument clears out @value{GDBN} information on your
9811program's symbol table.
9812
5d161b24 9813The @code{symbol-file} command causes @value{GDBN} to forget the contents
c906108c
SS
9814of its convenience variables, the value history, and all breakpoints and
9815auto-display expressions. This is because they may contain pointers to
9816the internal data recording symbols and data types, which are part of
9817the old symbol table data being discarded inside @value{GDBN}.
9818
9819@code{symbol-file} does not repeat if you press @key{RET} again after
9820executing it once.
9821
9822When @value{GDBN} is configured for a particular environment, it
9823understands debugging information in whatever format is the standard
9824generated for that environment; you may use either a @sc{gnu} compiler, or
9825other compilers that adhere to the local conventions.
c906108c
SS
9826Best results are usually obtained from @sc{gnu} compilers; for example,
9827using @code{@value{GCC}} you can generate debugging information for
9828optimized code.
c906108c
SS
9829
9830For most kinds of object files, with the exception of old SVR3 systems
9831using COFF, the @code{symbol-file} command does not normally read the
9832symbol table in full right away. Instead, it scans the symbol table
9833quickly to find which source files and which symbols are present. The
9834details are read later, one source file at a time, as they are needed.
9835
9836The purpose of this two-stage reading strategy is to make @value{GDBN}
9837start up faster. For the most part, it is invisible except for
9838occasional pauses while the symbol table details for a particular source
9839file are being read. (The @code{set verbose} command can turn these
9840pauses into messages if desired. @xref{Messages/Warnings, ,Optional
9841warnings and messages}.)
9842
c906108c
SS
9843We have not implemented the two-stage strategy for COFF yet. When the
9844symbol table is stored in COFF format, @code{symbol-file} reads the
9845symbol table data in full right away. Note that ``stabs-in-COFF''
9846still does the two-stage strategy, since the debug info is actually
9847in stabs format.
9848
9849@kindex readnow
9850@cindex reading symbols immediately
9851@cindex symbols, reading immediately
9852@kindex mapped
9853@cindex memory-mapped symbol file
9854@cindex saving symbol table
9855@item symbol-file @var{filename} @r{[} -readnow @r{]} @r{[} -mapped @r{]}
9856@itemx file @var{filename} @r{[} -readnow @r{]} @r{[} -mapped @r{]}
9857You can override the @value{GDBN} two-stage strategy for reading symbol
9858tables by using the @samp{-readnow} option with any of the commands that
9859load symbol table information, if you want to be sure @value{GDBN} has the
5d161b24 9860entire symbol table available.
c906108c 9861
c906108c
SS
9862If memory-mapped files are available on your system through the
9863@code{mmap} system call, you can use another option, @samp{-mapped}, to
9864cause @value{GDBN} to write the symbols for your program into a reusable
9865file. Future @value{GDBN} debugging sessions map in symbol information
9866from this auxiliary symbol file (if the program has not changed), rather
9867than spending time reading the symbol table from the executable
9868program. Using the @samp{-mapped} option has the same effect as
9869starting @value{GDBN} with the @samp{-mapped} command-line option.
9870
9871You can use both options together, to make sure the auxiliary symbol
9872file has all the symbol information for your program.
9873
9874The auxiliary symbol file for a program called @var{myprog} is called
9875@samp{@var{myprog}.syms}. Once this file exists (so long as it is newer
9876than the corresponding executable), @value{GDBN} always attempts to use
9877it when you debug @var{myprog}; no special options or commands are
9878needed.
9879
9880The @file{.syms} file is specific to the host machine where you run
9881@value{GDBN}. It holds an exact image of the internal @value{GDBN}
9882symbol table. It cannot be shared across multiple host platforms.
c906108c
SS
9883
9884@c FIXME: for now no mention of directories, since this seems to be in
9885@c flux. 13mar1992 status is that in theory GDB would look either in
9886@c current dir or in same dir as myprog; but issues like competing
9887@c GDB's, or clutter in system dirs, mean that in practice right now
9888@c only current dir is used. FFish says maybe a special GDB hierarchy
9889@c (eg rooted in val of env var GDBSYMS) could exist for mappable symbol
9890@c files.
9891
c906108c
SS
9892@kindex core-file
9893@item core-file @r{[} @var{filename} @r{]}
4644b6e3 9894@itemx core
c906108c
SS
9895Specify the whereabouts of a core dump file to be used as the ``contents
9896of memory''. Traditionally, core files contain only some parts of the
9897address space of the process that generated them; @value{GDBN} can access the
9898executable file itself for other parts.
9899
9900@code{core-file} with no argument specifies that no core file is
9901to be used.
9902
9903Note that the core file is ignored when your program is actually running
7a292a7a
SS
9904under @value{GDBN}. So, if you have been running your program and you
9905wish to debug a core file instead, you must kill the subprocess in which
9906the program is running. To do this, use the @code{kill} command
c906108c 9907(@pxref{Kill Process, ,Killing the child process}).
c906108c 9908
c906108c
SS
9909@kindex add-symbol-file
9910@cindex dynamic linking
9911@item add-symbol-file @var{filename} @var{address}
9912@itemx add-symbol-file @var{filename} @var{address} @r{[} -readnow @r{]} @r{[} -mapped @r{]}
17d9d558 9913@itemx add-symbol-file @var{filename} @r{-s}@var{section} @var{address} @dots{}
96a2c332
SS
9914The @code{add-symbol-file} command reads additional symbol table
9915information from the file @var{filename}. You would use this command
9916when @var{filename} has been dynamically loaded (by some other means)
9917into the program that is running. @var{address} should be the memory
9918address at which the file has been loaded; @value{GDBN} cannot figure
d167840f
EZ
9919this out for itself. You can additionally specify an arbitrary number
9920of @samp{@r{-s}@var{section} @var{address}} pairs, to give an explicit
9921section name and base address for that section. You can specify any
9922@var{address} as an expression.
c906108c
SS
9923
9924The symbol table of the file @var{filename} is added to the symbol table
9925originally read with the @code{symbol-file} command. You can use the
96a2c332
SS
9926@code{add-symbol-file} command any number of times; the new symbol data
9927thus read keeps adding to the old. To discard all old symbol data
9928instead, use the @code{symbol-file} command without any arguments.
c906108c 9929
17d9d558
JB
9930@cindex relocatable object files, reading symbols from
9931@cindex object files, relocatable, reading symbols from
9932@cindex reading symbols from relocatable object files
9933@cindex symbols, reading from relocatable object files
9934@cindex @file{.o} files, reading symbols from
9935Although @var{filename} is typically a shared library file, an
9936executable file, or some other object file which has been fully
9937relocated for loading into a process, you can also load symbolic
9938information from relocatable @file{.o} files, as long as:
9939
9940@itemize @bullet
9941@item
9942the file's symbolic information refers only to linker symbols defined in
9943that file, not to symbols defined by other object files,
9944@item
9945every section the file's symbolic information refers to has actually
9946been loaded into the inferior, as it appears in the file, and
9947@item
9948you can determine the address at which every section was loaded, and
9949provide these to the @code{add-symbol-file} command.
9950@end itemize
9951
9952@noindent
9953Some embedded operating systems, like Sun Chorus and VxWorks, can load
9954relocatable files into an already running program; such systems
9955typically make the requirements above easy to meet. However, it's
9956important to recognize that many native systems use complex link
49efadf5 9957procedures (@code{.linkonce} section factoring and C@t{++} constructor table
17d9d558
JB
9958assembly, for example) that make the requirements difficult to meet. In
9959general, one cannot assume that using @code{add-symbol-file} to read a
9960relocatable object file's symbolic information will have the same effect
9961as linking the relocatable object file into the program in the normal
9962way.
9963
c906108c
SS
9964@code{add-symbol-file} does not repeat if you press @key{RET} after using it.
9965
9966You can use the @samp{-mapped} and @samp{-readnow} options just as with
9967the @code{symbol-file} command, to change how @value{GDBN} manages the symbol
9968table information for @var{filename}.
9969
9970@kindex add-shared-symbol-file
9971@item add-shared-symbol-file
9972The @code{add-shared-symbol-file} command can be used only under Harris' CXUX
5d161b24
DB
9973operating system for the Motorola 88k. @value{GDBN} automatically looks for
9974shared libraries, however if @value{GDBN} does not find yours, you can run
c906108c 9975@code{add-shared-symbol-file}. It takes no arguments.
c906108c 9976
c906108c
SS
9977@kindex section
9978@item section
5d161b24
DB
9979The @code{section} command changes the base address of section SECTION of
9980the exec file to ADDR. This can be used if the exec file does not contain
9981section addresses, (such as in the a.out format), or when the addresses
9982specified in the file itself are wrong. Each section must be changed
d4f3574e
SS
9983separately. The @code{info files} command, described below, lists all
9984the sections and their addresses.
c906108c
SS
9985
9986@kindex info files
9987@kindex info target
9988@item info files
9989@itemx info target
7a292a7a
SS
9990@code{info files} and @code{info target} are synonymous; both print the
9991current target (@pxref{Targets, ,Specifying a Debugging Target}),
9992including the names of the executable and core dump files currently in
9993use by @value{GDBN}, and the files from which symbols were loaded. The
9994command @code{help target} lists all possible targets rather than
9995current ones.
9996
fe95c787
MS
9997@kindex maint info sections
9998@item maint info sections
9999Another command that can give you extra information about program sections
10000is @code{maint info sections}. In addition to the section information
10001displayed by @code{info files}, this command displays the flags and file
10002offset of each section in the executable and core dump files. In addition,
10003@code{maint info sections} provides the following command options (which
10004may be arbitrarily combined):
10005
10006@table @code
10007@item ALLOBJ
10008Display sections for all loaded object files, including shared libraries.
10009@item @var{sections}
6600abed 10010Display info only for named @var{sections}.
fe95c787
MS
10011@item @var{section-flags}
10012Display info only for sections for which @var{section-flags} are true.
10013The section flags that @value{GDBN} currently knows about are:
10014@table @code
10015@item ALLOC
10016Section will have space allocated in the process when loaded.
10017Set for all sections except those containing debug information.
10018@item LOAD
10019Section will be loaded from the file into the child process memory.
10020Set for pre-initialized code and data, clear for @code{.bss} sections.
10021@item RELOC
10022Section needs to be relocated before loading.
10023@item READONLY
10024Section cannot be modified by the child process.
10025@item CODE
10026Section contains executable code only.
6600abed 10027@item DATA
fe95c787
MS
10028Section contains data only (no executable code).
10029@item ROM
10030Section will reside in ROM.
10031@item CONSTRUCTOR
10032Section contains data for constructor/destructor lists.
10033@item HAS_CONTENTS
10034Section is not empty.
10035@item NEVER_LOAD
10036An instruction to the linker to not output the section.
10037@item COFF_SHARED_LIBRARY
10038A notification to the linker that the section contains
10039COFF shared library information.
10040@item IS_COMMON
10041Section contains common symbols.
10042@end table
10043@end table
6763aef9
MS
10044@kindex set trust-readonly-sections
10045@item set trust-readonly-sections on
10046Tell @value{GDBN} that readonly sections in your object file
6ca652b0 10047really are read-only (i.e.@: that their contents will not change).
6763aef9
MS
10048In that case, @value{GDBN} can fetch values from these sections
10049out of the object file, rather than from the target program.
10050For some targets (notably embedded ones), this can be a significant
10051enhancement to debugging performance.
10052
10053The default is off.
10054
10055@item set trust-readonly-sections off
15110bc3 10056Tell @value{GDBN} not to trust readonly sections. This means that
6763aef9
MS
10057the contents of the section might change while the program is running,
10058and must therefore be fetched from the target when needed.
c906108c
SS
10059@end table
10060
10061All file-specifying commands allow both absolute and relative file names
10062as arguments. @value{GDBN} always converts the file name to an absolute file
10063name and remembers it that way.
10064
c906108c 10065@cindex shared libraries
c906108c
SS
10066@value{GDBN} supports HP-UX, SunOS, SVr4, Irix 5, and IBM RS/6000 shared
10067libraries.
53a5351d 10068
c906108c
SS
10069@value{GDBN} automatically loads symbol definitions from shared libraries
10070when you use the @code{run} command, or when you examine a core file.
10071(Before you issue the @code{run} command, @value{GDBN} does not understand
10072references to a function in a shared library, however---unless you are
10073debugging a core file).
53a5351d
JM
10074
10075On HP-UX, if the program loads a library explicitly, @value{GDBN}
10076automatically loads the symbols at the time of the @code{shl_load} call.
10077
c906108c
SS
10078@c FIXME: some @value{GDBN} release may permit some refs to undef
10079@c FIXME...symbols---eg in a break cmd---assuming they are from a shared
10080@c FIXME...lib; check this from time to time when updating manual
10081
b7209cb4
FF
10082There are times, however, when you may wish to not automatically load
10083symbol definitions from shared libraries, such as when they are
10084particularly large or there are many of them.
10085
10086To control the automatic loading of shared library symbols, use the
10087commands:
10088
10089@table @code
10090@kindex set auto-solib-add
10091@item set auto-solib-add @var{mode}
10092If @var{mode} is @code{on}, symbols from all shared object libraries
10093will be loaded automatically when the inferior begins execution, you
10094attach to an independently started inferior, or when the dynamic linker
10095informs @value{GDBN} that a new library has been loaded. If @var{mode}
10096is @code{off}, symbols must be loaded manually, using the
10097@code{sharedlibrary} command. The default value is @code{on}.
10098
10099@kindex show auto-solib-add
10100@item show auto-solib-add
10101Display the current autoloading mode.
10102@end table
10103
10104To explicitly load shared library symbols, use the @code{sharedlibrary}
10105command:
10106
c906108c
SS
10107@table @code
10108@kindex info sharedlibrary
10109@kindex info share
10110@item info share
10111@itemx info sharedlibrary
10112Print the names of the shared libraries which are currently loaded.
10113
10114@kindex sharedlibrary
10115@kindex share
10116@item sharedlibrary @var{regex}
10117@itemx share @var{regex}
c906108c
SS
10118Load shared object library symbols for files matching a
10119Unix regular expression.
10120As with files loaded automatically, it only loads shared libraries
10121required by your program for a core file or after typing @code{run}. If
10122@var{regex} is omitted all shared libraries required by your program are
10123loaded.
10124@end table
10125
b7209cb4
FF
10126On some systems, such as HP-UX systems, @value{GDBN} supports
10127autoloading shared library symbols until a limiting threshold size is
10128reached. This provides the benefit of allowing autoloading to remain on
10129by default, but avoids autoloading excessively large shared libraries,
10130up to a threshold that is initially set, but which you can modify if you
10131wish.
c906108c
SS
10132
10133Beyond that threshold, symbols from shared libraries must be explicitly
d4f3574e
SS
10134loaded. To load these symbols, use the command @code{sharedlibrary
10135@var{filename}}. The base address of the shared library is determined
c906108c
SS
10136automatically by @value{GDBN} and need not be specified.
10137
10138To display or set the threshold, use the commands:
10139
10140@table @code
b7209cb4
FF
10141@kindex set auto-solib-limit
10142@item set auto-solib-limit @var{threshold}
10143Set the autoloading size threshold, in an integral number of megabytes.
10144If @var{threshold} is nonzero and shared library autoloading is enabled,
10145symbols from all shared object libraries will be loaded until the total
10146size of the loaded shared library symbols exceeds this threshold.
c906108c 10147Otherwise, symbols must be loaded manually, using the
6ca652b0 10148@code{sharedlibrary} command. The default threshold is 100 (i.e.@: 100
b7209cb4 10149Mb).
c906108c 10150
b7209cb4
FF
10151@kindex show auto-solib-limit
10152@item show auto-solib-limit
c906108c
SS
10153Display the current autoloading size threshold, in megabytes.
10154@end table
c906108c 10155
f5ebfba0
DJ
10156Shared libraries are also supported in many cross or remote debugging
10157configurations. A copy of the target's libraries need to be present on the
10158host system; they need to be the same as the target libraries, although the
10159copies on the target can be stripped as long as the copies on the host are
10160not.
10161
10162You need to tell @value{GDBN} where the target libraries are, so that it can
10163load the correct copies---otherwise, it may try to load the host's libraries.
10164@value{GDBN} has two variables to specify the search directories for target
10165libraries.
10166
10167@table @code
10168@kindex set solib-absolute-prefix
10169@item set solib-absolute-prefix @var{path}
10170If this variable is set, @var{path} will be used as a prefix for any
10171absolute shared library paths; many runtime loaders store the absolute
10172paths to the shared library in the target program's memory. If you use
10173@samp{solib-absolute-prefix} to find shared libraries, they need to be laid
10174out in the same way that they are on the target, with e.g.@: a
10175@file{/usr/lib} hierarchy under @var{path}.
10176
10177You can set the default value of @samp{solib-absolute-prefix} by using the
10178configure-time @samp{--with-sysroot} option.
10179
10180@kindex show solib-absolute-prefix
10181@item show solib-absolute-prefix
10182Display the current shared library prefix.
10183
10184@kindex set solib-search-path
10185@item set solib-search-path @var{path}
10186If this variable is set, @var{path} is a colon-separated list of directories
10187to search for shared libraries. @samp{solib-search-path} is used after
10188@samp{solib-absolute-prefix} fails to locate the library, or if the path to
10189the library is relative instead of absolute. If you want to use
10190@samp{solib-search-path} instead of @samp{solib-absolute-prefix}, be sure to
10191set @samp{solib-absolute-prefix} to a nonexistant directory to prevent
10192@value{GDBN} from finding your host's libraries.
10193
10194@kindex show solib-search-path
10195@item show solib-search-path
10196Display the current shared library search path.
10197@end table
10198
5b5d99cf
JB
10199
10200@node Separate Debug Files
10201@section Debugging Information in Separate Files
10202@cindex separate debugging information files
10203@cindex debugging information in separate files
10204@cindex @file{.debug} subdirectories
10205@cindex debugging information directory, global
10206@cindex global debugging information directory
10207
10208@value{GDBN} allows you to put a program's debugging information in a
10209file separate from the executable itself, in a way that allows
10210@value{GDBN} to find and load the debugging information automatically.
10211Since debugging information can be very large --- sometimes larger
10212than the executable code itself --- some systems distribute debugging
10213information for their executables in separate files, which users can
10214install only when they need to debug a problem.
10215
10216If an executable's debugging information has been extracted to a
10217separate file, the executable should contain a @dfn{debug link} giving
10218the name of the debugging information file (with no directory
10219components), and a checksum of its contents. (The exact form of a
10220debug link is described below.) If the full name of the directory
10221containing the executable is @var{execdir}, and the executable has a
10222debug link that specifies the name @var{debugfile}, then @value{GDBN}
10223will automatically search for the debugging information file in three
10224places:
10225
10226@itemize @bullet
10227@item
10228the directory containing the executable file (that is, it will look
10229for a file named @file{@var{execdir}/@var{debugfile}},
10230@item
10231a subdirectory of that directory named @file{.debug} (that is, the
10232file @file{@var{execdir}/.debug/@var{debugfile}}, and
10233@item
10234a subdirectory of the global debug file directory that includes the
10235executable's full path, and the name from the link (that is, the file
10236@file{@var{globaldebugdir}/@var{execdir}/@var{debugfile}}, where
10237@var{globaldebugdir} is the global debug file directory, and
10238@var{execdir} has been turned into a relative path).
10239@end itemize
10240@noindent
10241@value{GDBN} checks under each of these names for a debugging
10242information file whose checksum matches that given in the link, and
10243reads the debugging information from the first one it finds.
10244
10245So, for example, if you ask @value{GDBN} to debug @file{/usr/bin/ls},
10246which has a link containing the name @file{ls.debug}, and the global
10247debug directory is @file{/usr/lib/debug}, then @value{GDBN} will look
10248for debug information in @file{/usr/bin/ls.debug},
10249@file{/usr/bin/.debug/ls.debug}, and
10250@file{/usr/lib/debug/usr/bin/ls.debug}.
10251
10252You can set the global debugging info directory's name, and view the
10253name @value{GDBN} is currently using.
10254
10255@table @code
10256
10257@kindex set debug-file-directory
10258@item set debug-file-directory @var{directory}
10259Set the directory which @value{GDBN} searches for separate debugging
10260information files to @var{directory}.
10261
10262@kindex show debug-file-directory
10263@item show debug-file-directory
10264Show the directory @value{GDBN} searches for separate debugging
10265information files.
10266
10267@end table
10268
10269@cindex @code{.gnu_debuglink} sections
10270@cindex debug links
10271A debug link is a special section of the executable file named
10272@code{.gnu_debuglink}. The section must contain:
10273
10274@itemize
10275@item
10276A filename, with any leading directory components removed, followed by
10277a zero byte,
10278@item
10279zero to three bytes of padding, as needed to reach the next four-byte
10280boundary within the section, and
10281@item
10282a four-byte CRC checksum, stored in the same endianness used for the
10283executable file itself. The checksum is computed on the debugging
10284information file's full contents by the function given below, passing
10285zero as the @var{crc} argument.
10286@end itemize
10287
10288Any executable file format can carry a debug link, as long as it can
10289contain a section named @code{.gnu_debuglink} with the contents
10290described above.
10291
10292The debugging information file itself should be an ordinary
10293executable, containing a full set of linker symbols, sections, and
10294debugging information. The sections of the debugging information file
10295should have the same names, addresses and sizes as the original file,
10296but they need not contain any data --- much like a @code{.bss} section
10297in an ordinary executable.
10298
10299As of December 2002, there is no standard GNU utility to produce
10300separated executable / debugging information file pairs. Ulrich
10301Drepper's @file{elfutils} package, starting with version 0.53,
10302contains a version of the @code{strip} command such that the command
10303@kbd{strip foo -f foo.debug} removes the debugging information from
10304the executable file @file{foo}, places it in the file
10305@file{foo.debug}, and leaves behind a debug link in @file{foo}.
10306
10307Since there are many different ways to compute CRC's (different
10308polynomials, reversals, byte ordering, etc.), the simplest way to
10309describe the CRC used in @code{.gnu_debuglink} sections is to give the
10310complete code for a function that computes it:
10311
4644b6e3 10312@kindex gnu_debuglink_crc32
5b5d99cf
JB
10313@smallexample
10314unsigned long
10315gnu_debuglink_crc32 (unsigned long crc,
10316 unsigned char *buf, size_t len)
10317@{
10318 static const unsigned long crc32_table[256] =
10319 @{
10320 0x00000000, 0x77073096, 0xee0e612c, 0x990951ba, 0x076dc419,
10321 0x706af48f, 0xe963a535, 0x9e6495a3, 0x0edb8832, 0x79dcb8a4,
10322 0xe0d5e91e, 0x97d2d988, 0x09b64c2b, 0x7eb17cbd, 0xe7b82d07,
10323 0x90bf1d91, 0x1db71064, 0x6ab020f2, 0xf3b97148, 0x84be41de,
10324 0x1adad47d, 0x6ddde4eb, 0xf4d4b551, 0x83d385c7, 0x136c9856,
10325 0x646ba8c0, 0xfd62f97a, 0x8a65c9ec, 0x14015c4f, 0x63066cd9,
10326 0xfa0f3d63, 0x8d080df5, 0x3b6e20c8, 0x4c69105e, 0xd56041e4,
10327 0xa2677172, 0x3c03e4d1, 0x4b04d447, 0xd20d85fd, 0xa50ab56b,
10328 0x35b5a8fa, 0x42b2986c, 0xdbbbc9d6, 0xacbcf940, 0x32d86ce3,
10329 0x45df5c75, 0xdcd60dcf, 0xabd13d59, 0x26d930ac, 0x51de003a,
10330 0xc8d75180, 0xbfd06116, 0x21b4f4b5, 0x56b3c423, 0xcfba9599,
10331 0xb8bda50f, 0x2802b89e, 0x5f058808, 0xc60cd9b2, 0xb10be924,
10332 0x2f6f7c87, 0x58684c11, 0xc1611dab, 0xb6662d3d, 0x76dc4190,
10333 0x01db7106, 0x98d220bc, 0xefd5102a, 0x71b18589, 0x06b6b51f,
10334 0x9fbfe4a5, 0xe8b8d433, 0x7807c9a2, 0x0f00f934, 0x9609a88e,
10335 0xe10e9818, 0x7f6a0dbb, 0x086d3d2d, 0x91646c97, 0xe6635c01,
10336 0x6b6b51f4, 0x1c6c6162, 0x856530d8, 0xf262004e, 0x6c0695ed,
10337 0x1b01a57b, 0x8208f4c1, 0xf50fc457, 0x65b0d9c6, 0x12b7e950,
10338 0x8bbeb8ea, 0xfcb9887c, 0x62dd1ddf, 0x15da2d49, 0x8cd37cf3,
10339 0xfbd44c65, 0x4db26158, 0x3ab551ce, 0xa3bc0074, 0xd4bb30e2,
10340 0x4adfa541, 0x3dd895d7, 0xa4d1c46d, 0xd3d6f4fb, 0x4369e96a,
10341 0x346ed9fc, 0xad678846, 0xda60b8d0, 0x44042d73, 0x33031de5,
10342 0xaa0a4c5f, 0xdd0d7cc9, 0x5005713c, 0x270241aa, 0xbe0b1010,
10343 0xc90c2086, 0x5768b525, 0x206f85b3, 0xb966d409, 0xce61e49f,
10344 0x5edef90e, 0x29d9c998, 0xb0d09822, 0xc7d7a8b4, 0x59b33d17,
10345 0x2eb40d81, 0xb7bd5c3b, 0xc0ba6cad, 0xedb88320, 0x9abfb3b6,
10346 0x03b6e20c, 0x74b1d29a, 0xead54739, 0x9dd277af, 0x04db2615,
10347 0x73dc1683, 0xe3630b12, 0x94643b84, 0x0d6d6a3e, 0x7a6a5aa8,
10348 0xe40ecf0b, 0x9309ff9d, 0x0a00ae27, 0x7d079eb1, 0xf00f9344,
10349 0x8708a3d2, 0x1e01f268, 0x6906c2fe, 0xf762575d, 0x806567cb,
10350 0x196c3671, 0x6e6b06e7, 0xfed41b76, 0x89d32be0, 0x10da7a5a,
10351 0x67dd4acc, 0xf9b9df6f, 0x8ebeeff9, 0x17b7be43, 0x60b08ed5,
10352 0xd6d6a3e8, 0xa1d1937e, 0x38d8c2c4, 0x4fdff252, 0xd1bb67f1,
10353 0xa6bc5767, 0x3fb506dd, 0x48b2364b, 0xd80d2bda, 0xaf0a1b4c,
10354 0x36034af6, 0x41047a60, 0xdf60efc3, 0xa867df55, 0x316e8eef,
10355 0x4669be79, 0xcb61b38c, 0xbc66831a, 0x256fd2a0, 0x5268e236,
10356 0xcc0c7795, 0xbb0b4703, 0x220216b9, 0x5505262f, 0xc5ba3bbe,
10357 0xb2bd0b28, 0x2bb45a92, 0x5cb36a04, 0xc2d7ffa7, 0xb5d0cf31,
10358 0x2cd99e8b, 0x5bdeae1d, 0x9b64c2b0, 0xec63f226, 0x756aa39c,
10359 0x026d930a, 0x9c0906a9, 0xeb0e363f, 0x72076785, 0x05005713,
10360 0x95bf4a82, 0xe2b87a14, 0x7bb12bae, 0x0cb61b38, 0x92d28e9b,
10361 0xe5d5be0d, 0x7cdcefb7, 0x0bdbdf21, 0x86d3d2d4, 0xf1d4e242,
10362 0x68ddb3f8, 0x1fda836e, 0x81be16cd, 0xf6b9265b, 0x6fb077e1,
10363 0x18b74777, 0x88085ae6, 0xff0f6a70, 0x66063bca, 0x11010b5c,
10364 0x8f659eff, 0xf862ae69, 0x616bffd3, 0x166ccf45, 0xa00ae278,
10365 0xd70dd2ee, 0x4e048354, 0x3903b3c2, 0xa7672661, 0xd06016f7,
10366 0x4969474d, 0x3e6e77db, 0xaed16a4a, 0xd9d65adc, 0x40df0b66,
10367 0x37d83bf0, 0xa9bcae53, 0xdebb9ec5, 0x47b2cf7f, 0x30b5ffe9,
10368 0xbdbdf21c, 0xcabac28a, 0x53b39330, 0x24b4a3a6, 0xbad03605,
10369 0xcdd70693, 0x54de5729, 0x23d967bf, 0xb3667a2e, 0xc4614ab8,
10370 0x5d681b02, 0x2a6f2b94, 0xb40bbe37, 0xc30c8ea1, 0x5a05df1b,
10371 0x2d02ef8d
10372 @};
10373 unsigned char *end;
10374
10375 crc = ~crc & 0xffffffff;
10376 for (end = buf + len; buf < end; ++buf)
10377 crc = crc32_table[(crc ^ *buf) & 0xff] ^ (crc >> 8);
e7a3abfc 10378 return ~crc & 0xffffffff;
5b5d99cf
JB
10379@}
10380@end smallexample
10381
10382
6d2ebf8b 10383@node Symbol Errors
c906108c
SS
10384@section Errors reading symbol files
10385
10386While reading a symbol file, @value{GDBN} occasionally encounters problems,
10387such as symbol types it does not recognize, or known bugs in compiler
10388output. By default, @value{GDBN} does not notify you of such problems, since
10389they are relatively common and primarily of interest to people
10390debugging compilers. If you are interested in seeing information
10391about ill-constructed symbol tables, you can either ask @value{GDBN} to print
10392only one message about each such type of problem, no matter how many
10393times the problem occurs; or you can ask @value{GDBN} to print more messages,
10394to see how many times the problems occur, with the @code{set
10395complaints} command (@pxref{Messages/Warnings, ,Optional warnings and
10396messages}).
10397
10398The messages currently printed, and their meanings, include:
10399
10400@table @code
10401@item inner block not inside outer block in @var{symbol}
10402
10403The symbol information shows where symbol scopes begin and end
10404(such as at the start of a function or a block of statements). This
10405error indicates that an inner scope block is not fully contained
10406in its outer scope blocks.
10407
10408@value{GDBN} circumvents the problem by treating the inner block as if it had
10409the same scope as the outer block. In the error message, @var{symbol}
10410may be shown as ``@code{(don't know)}'' if the outer block is not a
10411function.
10412
10413@item block at @var{address} out of order
10414
10415The symbol information for symbol scope blocks should occur in
10416order of increasing addresses. This error indicates that it does not
10417do so.
10418
10419@value{GDBN} does not circumvent this problem, and has trouble
10420locating symbols in the source file whose symbols it is reading. (You
10421can often determine what source file is affected by specifying
10422@code{set verbose on}. @xref{Messages/Warnings, ,Optional warnings and
10423messages}.)
10424
10425@item bad block start address patched
10426
10427The symbol information for a symbol scope block has a start address
10428smaller than the address of the preceding source line. This is known
10429to occur in the SunOS 4.1.1 (and earlier) C compiler.
10430
10431@value{GDBN} circumvents the problem by treating the symbol scope block as
10432starting on the previous source line.
10433
10434@item bad string table offset in symbol @var{n}
10435
10436@cindex foo
10437Symbol number @var{n} contains a pointer into the string table which is
10438larger than the size of the string table.
10439
10440@value{GDBN} circumvents the problem by considering the symbol to have the
10441name @code{foo}, which may cause other problems if many symbols end up
10442with this name.
10443
10444@item unknown symbol type @code{0x@var{nn}}
10445
7a292a7a
SS
10446The symbol information contains new data types that @value{GDBN} does
10447not yet know how to read. @code{0x@var{nn}} is the symbol type of the
d4f3574e 10448uncomprehended information, in hexadecimal.
c906108c 10449
7a292a7a
SS
10450@value{GDBN} circumvents the error by ignoring this symbol information.
10451This usually allows you to debug your program, though certain symbols
c906108c 10452are not accessible. If you encounter such a problem and feel like
7a292a7a
SS
10453debugging it, you can debug @code{@value{GDBP}} with itself, breakpoint
10454on @code{complain}, then go up to the function @code{read_dbx_symtab}
10455and examine @code{*bufp} to see the symbol.
c906108c
SS
10456
10457@item stub type has NULL name
c906108c 10458
7a292a7a 10459@value{GDBN} could not find the full definition for a struct or class.
c906108c 10460
7a292a7a 10461@item const/volatile indicator missing (ok if using g++ v1.x), got@dots{}
b37052ae 10462The symbol information for a C@t{++} member function is missing some
7a292a7a
SS
10463information that recent versions of the compiler should have output for
10464it.
c906108c
SS
10465
10466@item info mismatch between compiler and debugger
10467
10468@value{GDBN} could not parse a type specification output by the compiler.
7a292a7a 10469
c906108c
SS
10470@end table
10471
6d2ebf8b 10472@node Targets
c906108c 10473@chapter Specifying a Debugging Target
7a292a7a 10474
c906108c
SS
10475@cindex debugging target
10476@kindex target
10477
10478A @dfn{target} is the execution environment occupied by your program.
53a5351d
JM
10479
10480Often, @value{GDBN} runs in the same host environment as your program;
10481in that case, the debugging target is specified as a side effect when
10482you use the @code{file} or @code{core} commands. When you need more
c906108c
SS
10483flexibility---for example, running @value{GDBN} on a physically separate
10484host, or controlling a standalone system over a serial port or a
53a5351d
JM
10485realtime system over a TCP/IP connection---you can use the @code{target}
10486command to specify one of the target types configured for @value{GDBN}
10487(@pxref{Target Commands, ,Commands for managing targets}).
c906108c
SS
10488
10489@menu
10490* Active Targets:: Active targets
10491* Target Commands:: Commands for managing targets
c906108c
SS
10492* Byte Order:: Choosing target byte order
10493* Remote:: Remote debugging
96baa820 10494* KOD:: Kernel Object Display
c906108c
SS
10495
10496@end menu
10497
6d2ebf8b 10498@node Active Targets
c906108c 10499@section Active targets
7a292a7a 10500
c906108c
SS
10501@cindex stacking targets
10502@cindex active targets
10503@cindex multiple targets
10504
c906108c 10505There are three classes of targets: processes, core files, and
7a292a7a
SS
10506executable files. @value{GDBN} can work concurrently on up to three
10507active targets, one in each class. This allows you to (for example)
10508start a process and inspect its activity without abandoning your work on
10509a core file.
c906108c
SS
10510
10511For example, if you execute @samp{gdb a.out}, then the executable file
10512@code{a.out} is the only active target. If you designate a core file as
10513well---presumably from a prior run that crashed and coredumped---then
10514@value{GDBN} has two active targets and uses them in tandem, looking
10515first in the corefile target, then in the executable file, to satisfy
10516requests for memory addresses. (Typically, these two classes of target
10517are complementary, since core files contain only a program's
10518read-write memory---variables and so on---plus machine status, while
10519executable files contain only the program text and initialized data.)
c906108c
SS
10520
10521When you type @code{run}, your executable file becomes an active process
7a292a7a
SS
10522target as well. When a process target is active, all @value{GDBN}
10523commands requesting memory addresses refer to that target; addresses in
10524an active core file or executable file target are obscured while the
10525process target is active.
c906108c 10526
7a292a7a
SS
10527Use the @code{core-file} and @code{exec-file} commands to select a new
10528core file or executable target (@pxref{Files, ,Commands to specify
c906108c 10529files}). To specify as a target a process that is already running, use
7a292a7a
SS
10530the @code{attach} command (@pxref{Attach, ,Debugging an already-running
10531process}).
c906108c 10532
6d2ebf8b 10533@node Target Commands
c906108c
SS
10534@section Commands for managing targets
10535
10536@table @code
10537@item target @var{type} @var{parameters}
7a292a7a
SS
10538Connects the @value{GDBN} host environment to a target machine or
10539process. A target is typically a protocol for talking to debugging
10540facilities. You use the argument @var{type} to specify the type or
10541protocol of the target machine.
c906108c
SS
10542
10543Further @var{parameters} are interpreted by the target protocol, but
10544typically include things like device names or host names to connect
10545with, process numbers, and baud rates.
c906108c
SS
10546
10547The @code{target} command does not repeat if you press @key{RET} again
10548after executing the command.
10549
10550@kindex help target
10551@item help target
10552Displays the names of all targets available. To display targets
10553currently selected, use either @code{info target} or @code{info files}
10554(@pxref{Files, ,Commands to specify files}).
10555
10556@item help target @var{name}
10557Describe a particular target, including any parameters necessary to
10558select it.
10559
10560@kindex set gnutarget
10561@item set gnutarget @var{args}
5d161b24 10562@value{GDBN} uses its own library BFD to read your files. @value{GDBN}
c906108c 10563knows whether it is reading an @dfn{executable},
5d161b24
DB
10564a @dfn{core}, or a @dfn{.o} file; however, you can specify the file format
10565with the @code{set gnutarget} command. Unlike most @code{target} commands,
c906108c
SS
10566with @code{gnutarget} the @code{target} refers to a program, not a machine.
10567
d4f3574e 10568@quotation
c906108c
SS
10569@emph{Warning:} To specify a file format with @code{set gnutarget},
10570you must know the actual BFD name.
d4f3574e 10571@end quotation
c906108c 10572
d4f3574e
SS
10573@noindent
10574@xref{Files, , Commands to specify files}.
c906108c 10575
5d161b24 10576@kindex show gnutarget
c906108c
SS
10577@item show gnutarget
10578Use the @code{show gnutarget} command to display what file format
10579@code{gnutarget} is set to read. If you have not set @code{gnutarget},
10580@value{GDBN} will determine the file format for each file automatically,
10581and @code{show gnutarget} displays @samp{The current BDF target is "auto"}.
10582@end table
10583
4644b6e3 10584@cindex common targets
c906108c
SS
10585Here are some common targets (available, or not, depending on the GDB
10586configuration):
c906108c
SS
10587
10588@table @code
4644b6e3 10589@kindex target
c906108c 10590@item target exec @var{program}
4644b6e3 10591@cindex executable file target
c906108c
SS
10592An executable file. @samp{target exec @var{program}} is the same as
10593@samp{exec-file @var{program}}.
10594
c906108c 10595@item target core @var{filename}
4644b6e3 10596@cindex core dump file target
c906108c
SS
10597A core dump file. @samp{target core @var{filename}} is the same as
10598@samp{core-file @var{filename}}.
c906108c 10599
c906108c 10600@item target remote @var{dev}
4644b6e3 10601@cindex remote target
c906108c
SS
10602Remote serial target in GDB-specific protocol. The argument @var{dev}
10603specifies what serial device to use for the connection (e.g.
10604@file{/dev/ttya}). @xref{Remote, ,Remote debugging}. @code{target remote}
d4f3574e 10605supports the @code{load} command. This is only useful if you have
c906108c
SS
10606some other way of getting the stub to the target system, and you can put
10607it somewhere in memory where it won't get clobbered by the download.
10608
c906108c 10609@item target sim
4644b6e3 10610@cindex built-in simulator target
2df3850c 10611Builtin CPU simulator. @value{GDBN} includes simulators for most architectures.
104c1213 10612In general,
474c8240 10613@smallexample
104c1213
JM
10614 target sim
10615 load
10616 run
474c8240 10617@end smallexample
d4f3574e 10618@noindent
104c1213 10619works; however, you cannot assume that a specific memory map, device
d4f3574e 10620drivers, or even basic I/O is available, although some simulators do
104c1213
JM
10621provide these. For info about any processor-specific simulator details,
10622see the appropriate section in @ref{Embedded Processors, ,Embedded
10623Processors}.
10624
c906108c
SS
10625@end table
10626
104c1213 10627Some configurations may include these targets as well:
c906108c
SS
10628
10629@table @code
10630
c906108c 10631@item target nrom @var{dev}
4644b6e3 10632@cindex NetROM ROM emulator target
c906108c
SS
10633NetROM ROM emulator. This target only supports downloading.
10634
c906108c
SS
10635@end table
10636
5d161b24 10637Different targets are available on different configurations of @value{GDBN};
c906108c 10638your configuration may have more or fewer targets.
c906108c
SS
10639
10640Many remote targets require you to download the executable's code
10641once you've successfully established a connection.
10642
10643@table @code
10644
10645@kindex load @var{filename}
10646@item load @var{filename}
c906108c
SS
10647Depending on what remote debugging facilities are configured into
10648@value{GDBN}, the @code{load} command may be available. Where it exists, it
10649is meant to make @var{filename} (an executable) available for debugging
10650on the remote system---by downloading, or dynamic linking, for example.
10651@code{load} also records the @var{filename} symbol table in @value{GDBN}, like
10652the @code{add-symbol-file} command.
10653
10654If your @value{GDBN} does not have a @code{load} command, attempting to
10655execute it gets the error message ``@code{You can't do that when your
10656target is @dots{}}''
c906108c
SS
10657
10658The file is loaded at whatever address is specified in the executable.
10659For some object file formats, you can specify the load address when you
10660link the program; for other formats, like a.out, the object file format
10661specifies a fixed address.
10662@c FIXME! This would be a good place for an xref to the GNU linker doc.
10663
c906108c
SS
10664@code{load} does not repeat if you press @key{RET} again after using it.
10665@end table
10666
6d2ebf8b 10667@node Byte Order
c906108c 10668@section Choosing target byte order
7a292a7a 10669
c906108c
SS
10670@cindex choosing target byte order
10671@cindex target byte order
c906108c 10672
172c2a43 10673Some types of processors, such as the MIPS, PowerPC, and Renesas SH,
c906108c
SS
10674offer the ability to run either big-endian or little-endian byte
10675orders. Usually the executable or symbol will include a bit to
10676designate the endian-ness, and you will not need to worry about
10677which to use. However, you may still find it useful to adjust
d4f3574e 10678@value{GDBN}'s idea of processor endian-ness manually.
c906108c
SS
10679
10680@table @code
4644b6e3 10681@kindex set endian
c906108c
SS
10682@item set endian big
10683Instruct @value{GDBN} to assume the target is big-endian.
10684
c906108c
SS
10685@item set endian little
10686Instruct @value{GDBN} to assume the target is little-endian.
10687
c906108c
SS
10688@item set endian auto
10689Instruct @value{GDBN} to use the byte order associated with the
10690executable.
10691
10692@item show endian
10693Display @value{GDBN}'s current idea of the target byte order.
10694
10695@end table
10696
10697Note that these commands merely adjust interpretation of symbolic
10698data on the host, and that they have absolutely no effect on the
10699target system.
10700
6d2ebf8b 10701@node Remote
c906108c
SS
10702@section Remote debugging
10703@cindex remote debugging
10704
10705If you are trying to debug a program running on a machine that cannot run
5d161b24
DB
10706@value{GDBN} in the usual way, it is often useful to use remote debugging.
10707For example, you might use remote debugging on an operating system kernel,
c906108c
SS
10708or on a small system which does not have a general purpose operating system
10709powerful enough to run a full-featured debugger.
10710
10711Some configurations of @value{GDBN} have special serial or TCP/IP interfaces
10712to make this work with particular debugging targets. In addition,
5d161b24 10713@value{GDBN} comes with a generic serial protocol (specific to @value{GDBN},
c906108c
SS
10714but not specific to any particular target system) which you can use if you
10715write the remote stubs---the code that runs on the remote system to
10716communicate with @value{GDBN}.
10717
10718Other remote targets may be available in your
10719configuration of @value{GDBN}; use @code{help target} to list them.
c906108c 10720
6f05cf9f
AC
10721@node KOD
10722@section Kernel Object Display
6f05cf9f 10723@cindex kernel object display
6f05cf9f
AC
10724@cindex KOD
10725
10726Some targets support kernel object display. Using this facility,
10727@value{GDBN} communicates specially with the underlying operating system
10728and can display information about operating system-level objects such as
10729mutexes and other synchronization objects. Exactly which objects can be
10730displayed is determined on a per-OS basis.
10731
3bbe9696 10732@kindex set os
6f05cf9f
AC
10733Use the @code{set os} command to set the operating system. This tells
10734@value{GDBN} which kernel object display module to initialize:
10735
474c8240 10736@smallexample
6f05cf9f 10737(@value{GDBP}) set os cisco
474c8240 10738@end smallexample
6f05cf9f 10739
3bbe9696
EZ
10740@kindex show os
10741The associated command @code{show os} displays the operating system
10742set with the @code{set os} command; if no operating system has been
10743set, @code{show os} will display an empty string @samp{""}.
10744
6f05cf9f
AC
10745If @code{set os} succeeds, @value{GDBN} will display some information
10746about the operating system, and will create a new @code{info} command
10747which can be used to query the target. The @code{info} command is named
10748after the operating system:
c906108c 10749
3bbe9696 10750@kindex info cisco
474c8240 10751@smallexample
6f05cf9f
AC
10752(@value{GDBP}) info cisco
10753List of Cisco Kernel Objects
10754Object Description
10755any Any and all objects
474c8240 10756@end smallexample
6f05cf9f
AC
10757
10758Further subcommands can be used to query about particular objects known
10759by the kernel.
10760
3bbe9696
EZ
10761There is currently no way to determine whether a given operating
10762system is supported other than to try setting it with @kbd{set os
10763@var{name}}, where @var{name} is the name of the operating system you
10764want to try.
6f05cf9f
AC
10765
10766
10767@node Remote Debugging
10768@chapter Debugging remote programs
10769
6b2f586d 10770@menu
07f31aa6 10771* Connecting:: Connecting to a remote target
6b2f586d
AC
10772* Server:: Using the gdbserver program
10773* NetWare:: Using the gdbserve.nlm program
501eef12 10774* Remote configuration:: Remote configuration
6b2f586d 10775* remote stub:: Implementing a remote stub
6b2f586d
AC
10776@end menu
10777
07f31aa6
DJ
10778@node Connecting
10779@section Connecting to a remote target
10780
10781On the @value{GDBN} host machine, you will need an unstripped copy of
10782your program, since @value{GDBN} needs symobl and debugging information.
10783Start up @value{GDBN} as usual, using the name of the local copy of your
10784program as the first argument.
10785
10786@cindex serial line, @code{target remote}
10787If you're using a serial line, you may want to give @value{GDBN} the
10788@w{@samp{--baud}} option, or use the @code{set remotebaud} command
10789before the @code{target} command.
10790
10791After that, use @code{target remote} to establish communications with
10792the target machine. Its argument specifies how to communicate---either
10793via a devicename attached to a direct serial line, or a TCP or UDP port
10794(possibly to a terminal server which in turn has a serial line to the
10795target). For example, to use a serial line connected to the device
10796named @file{/dev/ttyb}:
10797
10798@smallexample
10799target remote /dev/ttyb
10800@end smallexample
10801
10802@cindex TCP port, @code{target remote}
10803To use a TCP connection, use an argument of the form
10804@code{@var{host}:@var{port}} or @code{tcp:@var{host}:@var{port}}.
10805For example, to connect to port 2828 on a
10806terminal server named @code{manyfarms}:
10807
10808@smallexample
10809target remote manyfarms:2828
10810@end smallexample
10811
10812If your remote target is actually running on the same machine as
10813your debugger session (e.g.@: a simulator of your target running on
10814the same host), you can omit the hostname. For example, to connect
10815to port 1234 on your local machine:
10816
10817@smallexample
10818target remote :1234
10819@end smallexample
10820@noindent
10821
10822Note that the colon is still required here.
10823
10824@cindex UDP port, @code{target remote}
10825To use a UDP connection, use an argument of the form
10826@code{udp:@var{host}:@var{port}}. For example, to connect to UDP port 2828
10827on a terminal server named @code{manyfarms}:
10828
10829@smallexample
10830target remote udp:manyfarms:2828
10831@end smallexample
10832
10833When using a UDP connection for remote debugging, you should keep in mind
10834that the `U' stands for ``Unreliable''. UDP can silently drop packets on
10835busy or unreliable networks, which will cause havoc with your debugging
10836session.
10837
10838Now you can use all the usual commands to examine and change data and to
10839step and continue the remote program.
10840
10841@cindex interrupting remote programs
10842@cindex remote programs, interrupting
10843Whenever @value{GDBN} is waiting for the remote program, if you type the
10844interrupt character (often @key{C-C}), @value{GDBN} attempts to stop the
10845program. This may or may not succeed, depending in part on the hardware
10846and the serial drivers the remote system uses. If you type the
10847interrupt character once again, @value{GDBN} displays this prompt:
10848
10849@smallexample
10850Interrupted while waiting for the program.
10851Give up (and stop debugging it)? (y or n)
10852@end smallexample
10853
10854If you type @kbd{y}, @value{GDBN} abandons the remote debugging session.
10855(If you decide you want to try again later, you can use @samp{target
10856remote} again to connect once more.) If you type @kbd{n}, @value{GDBN}
10857goes back to waiting.
10858
10859@table @code
10860@kindex detach (remote)
10861@item detach
10862When you have finished debugging the remote program, you can use the
10863@code{detach} command to release it from @value{GDBN} control.
10864Detaching from the target normally resumes its execution, but the results
10865will depend on your particular remote stub. After the @code{detach}
10866command, @value{GDBN} is free to connect to another target.
10867
10868@kindex disconnect
10869@item disconnect
10870The @code{disconnect} command behaves like @code{detach}, except that
10871the target is generally not resumed. It will wait for @value{GDBN}
10872(this instance or another one) to connect and continue debugging. After
10873the @code{disconnect} command, @value{GDBN} is again free to connect to
10874another target.
10875@end table
10876
6f05cf9f
AC
10877@node Server
10878@section Using the @code{gdbserver} program
10879
10880@kindex gdbserver
10881@cindex remote connection without stubs
10882@code{gdbserver} is a control program for Unix-like systems, which
10883allows you to connect your program with a remote @value{GDBN} via
10884@code{target remote}---but without linking in the usual debugging stub.
10885
10886@code{gdbserver} is not a complete replacement for the debugging stubs,
10887because it requires essentially the same operating-system facilities
10888that @value{GDBN} itself does. In fact, a system that can run
10889@code{gdbserver} to connect to a remote @value{GDBN} could also run
10890@value{GDBN} locally! @code{gdbserver} is sometimes useful nevertheless,
10891because it is a much smaller program than @value{GDBN} itself. It is
10892also easier to port than all of @value{GDBN}, so you may be able to get
10893started more quickly on a new system by using @code{gdbserver}.
10894Finally, if you develop code for real-time systems, you may find that
10895the tradeoffs involved in real-time operation make it more convenient to
10896do as much development work as possible on another system, for example
10897by cross-compiling. You can use @code{gdbserver} to make a similar
10898choice for debugging.
10899
10900@value{GDBN} and @code{gdbserver} communicate via either a serial line
10901or a TCP connection, using the standard @value{GDBN} remote serial
10902protocol.
10903
10904@table @emph
10905@item On the target machine,
10906you need to have a copy of the program you want to debug.
10907@code{gdbserver} does not need your program's symbol table, so you can
10908strip the program if necessary to save space. @value{GDBN} on the host
10909system does all the symbol handling.
10910
10911To use the server, you must tell it how to communicate with @value{GDBN};
56460a61 10912the name of your program; and the arguments for your program. The usual
6f05cf9f
AC
10913syntax is:
10914
10915@smallexample
10916target> gdbserver @var{comm} @var{program} [ @var{args} @dots{} ]
10917@end smallexample
10918
10919@var{comm} is either a device name (to use a serial line) or a TCP
10920hostname and portnumber. For example, to debug Emacs with the argument
10921@samp{foo.txt} and communicate with @value{GDBN} over the serial port
10922@file{/dev/com1}:
10923
10924@smallexample
10925target> gdbserver /dev/com1 emacs foo.txt
10926@end smallexample
10927
10928@code{gdbserver} waits passively for the host @value{GDBN} to communicate
10929with it.
10930
10931To use a TCP connection instead of a serial line:
10932
10933@smallexample
10934target> gdbserver host:2345 emacs foo.txt
10935@end smallexample
10936
10937The only difference from the previous example is the first argument,
10938specifying that you are communicating with the host @value{GDBN} via
10939TCP. The @samp{host:2345} argument means that @code{gdbserver} is to
10940expect a TCP connection from machine @samp{host} to local TCP port 2345.
10941(Currently, the @samp{host} part is ignored.) You can choose any number
10942you want for the port number as long as it does not conflict with any
10943TCP ports already in use on the target system (for example, @code{23} is
10944reserved for @code{telnet}).@footnote{If you choose a port number that
10945conflicts with another service, @code{gdbserver} prints an error message
10946and exits.} You must use the same port number with the host @value{GDBN}
10947@code{target remote} command.
10948
56460a61
DJ
10949On some targets, @code{gdbserver} can also attach to running programs.
10950This is accomplished via the @code{--attach} argument. The syntax is:
10951
10952@smallexample
10953target> gdbserver @var{comm} --attach @var{pid}
10954@end smallexample
10955
10956@var{pid} is the process ID of a currently running process. It isn't necessary
10957to point @code{gdbserver} at a binary for the running process.
10958
b1fe9455
DJ
10959@pindex pidof
10960@cindex attach to a program by name
10961You can debug processes by name instead of process ID if your target has the
10962@code{pidof} utility:
10963
10964@smallexample
10965target> gdbserver @var{comm} --attach `pidof @var{PROGRAM}`
10966@end smallexample
10967
10968In case more than one copy of @var{PROGRAM} is running, or @var{PROGRAM}
10969has multiple threads, most versions of @code{pidof} support the
10970@code{-s} option to only return the first process ID.
10971
07f31aa6
DJ
10972@item On the host machine,
10973connect to your target (@pxref{Connecting,,Connecting to a remote target}).
6f05cf9f
AC
10974For TCP connections, you must start up @code{gdbserver} prior to using
10975the @code{target remote} command. Otherwise you may get an error whose
10976text depends on the host system, but which usually looks something like
07f31aa6
DJ
10977@samp{Connection refused}. You don't need to use the @code{load}
10978command in @value{GDBN} when using gdbserver, since the program is
10979already on the target.
10980
6f05cf9f
AC
10981@end table
10982
10983@node NetWare
10984@section Using the @code{gdbserve.nlm} program
10985
10986@kindex gdbserve.nlm
10987@code{gdbserve.nlm} is a control program for NetWare systems, which
10988allows you to connect your program with a remote @value{GDBN} via
10989@code{target remote}.
10990
10991@value{GDBN} and @code{gdbserve.nlm} communicate via a serial line,
10992using the standard @value{GDBN} remote serial protocol.
10993
10994@table @emph
10995@item On the target machine,
10996you need to have a copy of the program you want to debug.
10997@code{gdbserve.nlm} does not need your program's symbol table, so you
10998can strip the program if necessary to save space. @value{GDBN} on the
10999host system does all the symbol handling.
11000
11001To use the server, you must tell it how to communicate with
11002@value{GDBN}; the name of your program; and the arguments for your
11003program. The syntax is:
11004
11005@smallexample
11006load gdbserve [ BOARD=@var{board} ] [ PORT=@var{port} ]
11007 [ BAUD=@var{baud} ] @var{program} [ @var{args} @dots{} ]
11008@end smallexample
11009
11010@var{board} and @var{port} specify the serial line; @var{baud} specifies
11011the baud rate used by the connection. @var{port} and @var{node} default
11012to 0, @var{baud} defaults to 9600@dmn{bps}.
11013
11014For example, to debug Emacs with the argument @samp{foo.txt}and
11015communicate with @value{GDBN} over serial port number 2 or board 1
11016using a 19200@dmn{bps} connection:
11017
11018@smallexample
11019load gdbserve BOARD=1 PORT=2 BAUD=19200 emacs foo.txt
11020@end smallexample
11021
07f31aa6
DJ
11022@item
11023On the @value{GDBN} host machine, connect to your target (@pxref{Connecting,,
11024Connecting to a remote target}).
6f05cf9f 11025
6f05cf9f
AC
11026@end table
11027
501eef12
AC
11028@node Remote configuration
11029@section Remote configuration
11030
11031The following configuration options are available when debugging remote
11032programs:
11033
11034@table @code
11035@kindex set remote hardware-watchpoint-limit
11036@kindex set remote hardware-breakpoint-limit
11037@anchor{set remote hardware-watchpoint-limit}
11038@anchor{set remote hardware-breakpoint-limit}
11039@item set remote hardware-watchpoint-limit @var{limit}
11040@itemx set remote hardware-breakpoint-limit @var{limit}
11041Restrict @value{GDBN} to using @var{limit} remote hardware breakpoint or
11042watchpoints. A limit of -1, the default, is treated as unlimited.
11043@end table
11044
6f05cf9f
AC
11045@node remote stub
11046@section Implementing a remote stub
7a292a7a 11047
8e04817f
AC
11048@cindex debugging stub, example
11049@cindex remote stub, example
11050@cindex stub example, remote debugging
11051The stub files provided with @value{GDBN} implement the target side of the
11052communication protocol, and the @value{GDBN} side is implemented in the
11053@value{GDBN} source file @file{remote.c}. Normally, you can simply allow
11054these subroutines to communicate, and ignore the details. (If you're
11055implementing your own stub file, you can still ignore the details: start
11056with one of the existing stub files. @file{sparc-stub.c} is the best
11057organized, and therefore the easiest to read.)
11058
104c1213
JM
11059@cindex remote serial debugging, overview
11060To debug a program running on another machine (the debugging
11061@dfn{target} machine), you must first arrange for all the usual
11062prerequisites for the program to run by itself. For example, for a C
11063program, you need:
c906108c 11064
104c1213
JM
11065@enumerate
11066@item
11067A startup routine to set up the C runtime environment; these usually
11068have a name like @file{crt0}. The startup routine may be supplied by
11069your hardware supplier, or you may have to write your own.
96baa820 11070
5d161b24 11071@item
d4f3574e 11072A C subroutine library to support your program's
104c1213 11073subroutine calls, notably managing input and output.
96baa820 11074
104c1213
JM
11075@item
11076A way of getting your program to the other machine---for example, a
11077download program. These are often supplied by the hardware
11078manufacturer, but you may have to write your own from hardware
11079documentation.
11080@end enumerate
96baa820 11081
104c1213
JM
11082The next step is to arrange for your program to use a serial port to
11083communicate with the machine where @value{GDBN} is running (the @dfn{host}
11084machine). In general terms, the scheme looks like this:
96baa820 11085
104c1213
JM
11086@table @emph
11087@item On the host,
11088@value{GDBN} already understands how to use this protocol; when everything
11089else is set up, you can simply use the @samp{target remote} command
11090(@pxref{Targets,,Specifying a Debugging Target}).
11091
11092@item On the target,
11093you must link with your program a few special-purpose subroutines that
11094implement the @value{GDBN} remote serial protocol. The file containing these
11095subroutines is called a @dfn{debugging stub}.
11096
11097On certain remote targets, you can use an auxiliary program
11098@code{gdbserver} instead of linking a stub into your program.
11099@xref{Server,,Using the @code{gdbserver} program}, for details.
11100@end table
96baa820 11101
104c1213
JM
11102The debugging stub is specific to the architecture of the remote
11103machine; for example, use @file{sparc-stub.c} to debug programs on
11104@sc{sparc} boards.
96baa820 11105
104c1213
JM
11106@cindex remote serial stub list
11107These working remote stubs are distributed with @value{GDBN}:
96baa820 11108
104c1213
JM
11109@table @code
11110
11111@item i386-stub.c
41afff9a 11112@cindex @file{i386-stub.c}
104c1213
JM
11113@cindex Intel
11114@cindex i386
11115For Intel 386 and compatible architectures.
11116
11117@item m68k-stub.c
41afff9a 11118@cindex @file{m68k-stub.c}
104c1213
JM
11119@cindex Motorola 680x0
11120@cindex m680x0
11121For Motorola 680x0 architectures.
11122
11123@item sh-stub.c
41afff9a 11124@cindex @file{sh-stub.c}
172c2a43 11125@cindex Renesas
104c1213 11126@cindex SH
172c2a43 11127For Renesas SH architectures.
104c1213
JM
11128
11129@item sparc-stub.c
41afff9a 11130@cindex @file{sparc-stub.c}
104c1213
JM
11131@cindex Sparc
11132For @sc{sparc} architectures.
11133
11134@item sparcl-stub.c
41afff9a 11135@cindex @file{sparcl-stub.c}
104c1213
JM
11136@cindex Fujitsu
11137@cindex SparcLite
11138For Fujitsu @sc{sparclite} architectures.
11139
11140@end table
11141
11142The @file{README} file in the @value{GDBN} distribution may list other
11143recently added stubs.
11144
11145@menu
11146* Stub Contents:: What the stub can do for you
11147* Bootstrapping:: What you must do for the stub
11148* Debug Session:: Putting it all together
104c1213
JM
11149@end menu
11150
6d2ebf8b 11151@node Stub Contents
6f05cf9f 11152@subsection What the stub can do for you
104c1213
JM
11153
11154@cindex remote serial stub
11155The debugging stub for your architecture supplies these three
11156subroutines:
11157
11158@table @code
11159@item set_debug_traps
4644b6e3 11160@findex set_debug_traps
104c1213
JM
11161@cindex remote serial stub, initialization
11162This routine arranges for @code{handle_exception} to run when your
11163program stops. You must call this subroutine explicitly near the
11164beginning of your program.
11165
11166@item handle_exception
4644b6e3 11167@findex handle_exception
104c1213
JM
11168@cindex remote serial stub, main routine
11169This is the central workhorse, but your program never calls it
11170explicitly---the setup code arranges for @code{handle_exception} to
11171run when a trap is triggered.
11172
11173@code{handle_exception} takes control when your program stops during
11174execution (for example, on a breakpoint), and mediates communications
11175with @value{GDBN} on the host machine. This is where the communications
11176protocol is implemented; @code{handle_exception} acts as the @value{GDBN}
d4f3574e 11177representative on the target machine. It begins by sending summary
104c1213
JM
11178information on the state of your program, then continues to execute,
11179retrieving and transmitting any information @value{GDBN} needs, until you
11180execute a @value{GDBN} command that makes your program resume; at that point,
11181@code{handle_exception} returns control to your own code on the target
5d161b24 11182machine.
104c1213
JM
11183
11184@item breakpoint
11185@cindex @code{breakpoint} subroutine, remote
11186Use this auxiliary subroutine to make your program contain a
11187breakpoint. Depending on the particular situation, this may be the only
11188way for @value{GDBN} to get control. For instance, if your target
11189machine has some sort of interrupt button, you won't need to call this;
11190pressing the interrupt button transfers control to
11191@code{handle_exception}---in effect, to @value{GDBN}. On some machines,
11192simply receiving characters on the serial port may also trigger a trap;
11193again, in that situation, you don't need to call @code{breakpoint} from
11194your own program---simply running @samp{target remote} from the host
5d161b24 11195@value{GDBN} session gets control.
104c1213
JM
11196
11197Call @code{breakpoint} if none of these is true, or if you simply want
11198to make certain your program stops at a predetermined point for the
11199start of your debugging session.
11200@end table
11201
6d2ebf8b 11202@node Bootstrapping
6f05cf9f 11203@subsection What you must do for the stub
104c1213
JM
11204
11205@cindex remote stub, support routines
11206The debugging stubs that come with @value{GDBN} are set up for a particular
11207chip architecture, but they have no information about the rest of your
11208debugging target machine.
11209
11210First of all you need to tell the stub how to communicate with the
11211serial port.
11212
11213@table @code
11214@item int getDebugChar()
4644b6e3 11215@findex getDebugChar
104c1213
JM
11216Write this subroutine to read a single character from the serial port.
11217It may be identical to @code{getchar} for your target system; a
11218different name is used to allow you to distinguish the two if you wish.
11219
11220@item void putDebugChar(int)
4644b6e3 11221@findex putDebugChar
104c1213 11222Write this subroutine to write a single character to the serial port.
5d161b24 11223It may be identical to @code{putchar} for your target system; a
104c1213
JM
11224different name is used to allow you to distinguish the two if you wish.
11225@end table
11226
11227@cindex control C, and remote debugging
11228@cindex interrupting remote targets
11229If you want @value{GDBN} to be able to stop your program while it is
11230running, you need to use an interrupt-driven serial driver, and arrange
11231for it to stop when it receives a @code{^C} (@samp{\003}, the control-C
11232character). That is the character which @value{GDBN} uses to tell the
11233remote system to stop.
11234
11235Getting the debugging target to return the proper status to @value{GDBN}
11236probably requires changes to the standard stub; one quick and dirty way
11237is to just execute a breakpoint instruction (the ``dirty'' part is that
11238@value{GDBN} reports a @code{SIGTRAP} instead of a @code{SIGINT}).
11239
11240Other routines you need to supply are:
11241
11242@table @code
11243@item void exceptionHandler (int @var{exception_number}, void *@var{exception_address})
4644b6e3 11244@findex exceptionHandler
104c1213
JM
11245Write this function to install @var{exception_address} in the exception
11246handling tables. You need to do this because the stub does not have any
11247way of knowing what the exception handling tables on your target system
11248are like (for example, the processor's table might be in @sc{rom},
11249containing entries which point to a table in @sc{ram}).
11250@var{exception_number} is the exception number which should be changed;
11251its meaning is architecture-dependent (for example, different numbers
11252might represent divide by zero, misaligned access, etc). When this
11253exception occurs, control should be transferred directly to
11254@var{exception_address}, and the processor state (stack, registers,
11255and so on) should be just as it is when a processor exception occurs. So if
11256you want to use a jump instruction to reach @var{exception_address}, it
11257should be a simple jump, not a jump to subroutine.
11258
11259For the 386, @var{exception_address} should be installed as an interrupt
11260gate so that interrupts are masked while the handler runs. The gate
11261should be at privilege level 0 (the most privileged level). The
11262@sc{sparc} and 68k stubs are able to mask interrupts themselves without
11263help from @code{exceptionHandler}.
11264
11265@item void flush_i_cache()
4644b6e3 11266@findex flush_i_cache
d4f3574e 11267On @sc{sparc} and @sc{sparclite} only, write this subroutine to flush the
104c1213
JM
11268instruction cache, if any, on your target machine. If there is no
11269instruction cache, this subroutine may be a no-op.
11270
11271On target machines that have instruction caches, @value{GDBN} requires this
11272function to make certain that the state of your program is stable.
11273@end table
11274
11275@noindent
11276You must also make sure this library routine is available:
11277
11278@table @code
11279@item void *memset(void *, int, int)
4644b6e3 11280@findex memset
104c1213
JM
11281This is the standard library function @code{memset} that sets an area of
11282memory to a known value. If you have one of the free versions of
11283@code{libc.a}, @code{memset} can be found there; otherwise, you must
11284either obtain it from your hardware manufacturer, or write your own.
11285@end table
11286
11287If you do not use the GNU C compiler, you may need other standard
11288library subroutines as well; this varies from one stub to another,
11289but in general the stubs are likely to use any of the common library
d4f3574e 11290subroutines which @code{@value{GCC}} generates as inline code.
104c1213
JM
11291
11292
6d2ebf8b 11293@node Debug Session
6f05cf9f 11294@subsection Putting it all together
104c1213
JM
11295
11296@cindex remote serial debugging summary
11297In summary, when your program is ready to debug, you must follow these
11298steps.
11299
11300@enumerate
11301@item
6d2ebf8b 11302Make sure you have defined the supporting low-level routines
104c1213
JM
11303(@pxref{Bootstrapping,,What you must do for the stub}):
11304@display
11305@code{getDebugChar}, @code{putDebugChar},
11306@code{flush_i_cache}, @code{memset}, @code{exceptionHandler}.
11307@end display
11308
11309@item
11310Insert these lines near the top of your program:
11311
474c8240 11312@smallexample
104c1213
JM
11313set_debug_traps();
11314breakpoint();
474c8240 11315@end smallexample
104c1213
JM
11316
11317@item
11318For the 680x0 stub only, you need to provide a variable called
11319@code{exceptionHook}. Normally you just use:
11320
474c8240 11321@smallexample
104c1213 11322void (*exceptionHook)() = 0;
474c8240 11323@end smallexample
104c1213 11324
d4f3574e 11325@noindent
104c1213 11326but if before calling @code{set_debug_traps}, you set it to point to a
598ca718 11327function in your program, that function is called when
104c1213
JM
11328@code{@value{GDBN}} continues after stopping on a trap (for example, bus
11329error). The function indicated by @code{exceptionHook} is called with
11330one parameter: an @code{int} which is the exception number.
11331
11332@item
11333Compile and link together: your program, the @value{GDBN} debugging stub for
11334your target architecture, and the supporting subroutines.
11335
11336@item
11337Make sure you have a serial connection between your target machine and
11338the @value{GDBN} host, and identify the serial port on the host.
11339
11340@item
11341@c The "remote" target now provides a `load' command, so we should
11342@c document that. FIXME.
11343Download your program to your target machine (or get it there by
11344whatever means the manufacturer provides), and start it.
11345
11346@item
07f31aa6
DJ
11347Start @value{GDBN} on the host, and connect to the target
11348(@pxref{Connecting,,Connecting to a remote target}).
9db8d71f 11349
104c1213
JM
11350@end enumerate
11351
8e04817f
AC
11352@node Configurations
11353@chapter Configuration-Specific Information
104c1213 11354
8e04817f
AC
11355While nearly all @value{GDBN} commands are available for all native and
11356cross versions of the debugger, there are some exceptions. This chapter
11357describes things that are only available in certain configurations.
104c1213 11358
8e04817f
AC
11359There are three major categories of configurations: native
11360configurations, where the host and target are the same, embedded
11361operating system configurations, which are usually the same for several
11362different processor architectures, and bare embedded processors, which
11363are quite different from each other.
104c1213 11364
8e04817f
AC
11365@menu
11366* Native::
11367* Embedded OS::
11368* Embedded Processors::
11369* Architectures::
11370@end menu
104c1213 11371
8e04817f
AC
11372@node Native
11373@section Native
104c1213 11374
8e04817f
AC
11375This section describes details specific to particular native
11376configurations.
6cf7e474 11377
8e04817f
AC
11378@menu
11379* HP-UX:: HP-UX
7561d450 11380* BSD libkvm Interface:: Debugging BSD kernel memory images
8e04817f
AC
11381* SVR4 Process Information:: SVR4 process information
11382* DJGPP Native:: Features specific to the DJGPP port
78c47bea 11383* Cygwin Native:: Features specific to the Cygwin port
8e04817f 11384@end menu
6cf7e474 11385
8e04817f
AC
11386@node HP-UX
11387@subsection HP-UX
104c1213 11388
8e04817f
AC
11389On HP-UX systems, if you refer to a function or variable name that
11390begins with a dollar sign, @value{GDBN} searches for a user or system
11391name first, before it searches for a convenience variable.
104c1213 11392
7561d450
MK
11393@node BSD libkvm Interface
11394@subsection BSD libkvm Interface
11395
11396@cindex libkvm
11397@cindex kernel memory image
11398@cindex kernel crash dump
11399
11400BSD-derived systems (FreeBSD/NetBSD/OpenBSD) have a kernel memory
11401interface that provides a uniform interface for accessing kernel virtual
11402memory images, including live systems and crash dumps. @value{GDBN}
11403uses this interface to allow you to debug live kernels and kernel crash
11404dumps on many native BSD configurations. This is implemented as a
11405special @code{kvm} debugging target. For debugging a live system, load
11406the currently running kernel into @value{GDBN} and connect to the
11407@code{kvm} target:
11408
11409@smallexample
11410(@value{GDBP}) @b{target kvm}
11411@end smallexample
11412
11413For debugging crash dumps, provide the file name of the crash dump as an
11414argument:
11415
11416@smallexample
11417(@value{GDBP}) @b{target kvm /var/crash/bsd.0}
11418@end smallexample
11419
11420Once connected to the @code{kvm} target, the following commands are
11421available:
11422
11423@table @code
11424@kindex kvm
11425@item kvm pcb
11426Set current context from pcb address.
11427
11428@item kvm proc
11429Set current context from proc address. This command isn't available on
11430modern FreeBSD systems.
11431@end table
11432
8e04817f
AC
11433@node SVR4 Process Information
11434@subsection SVR4 process information
104c1213 11435
8e04817f
AC
11436@kindex /proc
11437@cindex process image
104c1213 11438
8e04817f
AC
11439Many versions of SVR4 provide a facility called @samp{/proc} that can be
11440used to examine the image of a running process using file-system
11441subroutines. If @value{GDBN} is configured for an operating system with
11442this facility, the command @code{info proc} is available to report on
11443several kinds of information about the process running your program.
11444@code{info proc} works only on SVR4 systems that include the
11445@code{procfs} code. This includes OSF/1 (Digital Unix), Solaris, Irix,
1104b9e7 11446and Unixware, but not HP-UX or @sc{gnu}/Linux, for example.
104c1213 11447
8e04817f
AC
11448@table @code
11449@kindex info proc
11450@item info proc
11451Summarize available information about the process.
6cf7e474 11452
8e04817f
AC
11453@kindex info proc mappings
11454@item info proc mappings
11455Report on the address ranges accessible in the program, with information
11456on whether your program may read, write, or execute each range.
11457@ignore
11458@comment These sub-options of 'info proc' were not included when
11459@comment procfs.c was re-written. Keep their descriptions around
11460@comment against the day when someone finds the time to put them back in.
11461@kindex info proc times
11462@item info proc times
11463Starting time, user CPU time, and system CPU time for your program and
11464its children.
6cf7e474 11465
8e04817f
AC
11466@kindex info proc id
11467@item info proc id
11468Report on the process IDs related to your program: its own process ID,
11469the ID of its parent, the process group ID, and the session ID.
104c1213 11470
8e04817f
AC
11471@kindex info proc status
11472@item info proc status
11473General information on the state of the process. If the process is
11474stopped, this report includes the reason for stopping, and any signal
11475received.
d4f3574e 11476
8e04817f
AC
11477@item info proc all
11478Show all the above information about the process.
11479@end ignore
11480@end table
104c1213 11481
8e04817f
AC
11482@node DJGPP Native
11483@subsection Features for Debugging @sc{djgpp} Programs
11484@cindex @sc{djgpp} debugging
11485@cindex native @sc{djgpp} debugging
11486@cindex MS-DOS-specific commands
104c1213 11487
8e04817f
AC
11488@sc{djgpp} is the port of @sc{gnu} development tools to MS-DOS and
11489MS-Windows. @sc{djgpp} programs are 32-bit protected-mode programs
11490that use the @dfn{DPMI} (DOS Protected-Mode Interface) API to run on
11491top of real-mode DOS systems and their emulations.
104c1213 11492
8e04817f
AC
11493@value{GDBN} supports native debugging of @sc{djgpp} programs, and
11494defines a few commands specific to the @sc{djgpp} port. This
11495subsection describes those commands.
104c1213 11496
8e04817f
AC
11497@table @code
11498@kindex info dos
11499@item info dos
11500This is a prefix of @sc{djgpp}-specific commands which print
11501information about the target system and important OS structures.
f1251bdd 11502
8e04817f
AC
11503@kindex sysinfo
11504@cindex MS-DOS system info
11505@cindex free memory information (MS-DOS)
11506@item info dos sysinfo
11507This command displays assorted information about the underlying
11508platform: the CPU type and features, the OS version and flavor, the
11509DPMI version, and the available conventional and DPMI memory.
104c1213 11510
8e04817f
AC
11511@cindex GDT
11512@cindex LDT
11513@cindex IDT
11514@cindex segment descriptor tables
11515@cindex descriptor tables display
11516@item info dos gdt
11517@itemx info dos ldt
11518@itemx info dos idt
11519These 3 commands display entries from, respectively, Global, Local,
11520and Interrupt Descriptor Tables (GDT, LDT, and IDT). The descriptor
11521tables are data structures which store a descriptor for each segment
11522that is currently in use. The segment's selector is an index into a
11523descriptor table; the table entry for that index holds the
11524descriptor's base address and limit, and its attributes and access
11525rights.
104c1213 11526
8e04817f
AC
11527A typical @sc{djgpp} program uses 3 segments: a code segment, a data
11528segment (used for both data and the stack), and a DOS segment (which
11529allows access to DOS/BIOS data structures and absolute addresses in
11530conventional memory). However, the DPMI host will usually define
11531additional segments in order to support the DPMI environment.
d4f3574e 11532
8e04817f
AC
11533@cindex garbled pointers
11534These commands allow to display entries from the descriptor tables.
11535Without an argument, all entries from the specified table are
11536displayed. An argument, which should be an integer expression, means
11537display a single entry whose index is given by the argument. For
11538example, here's a convenient way to display information about the
11539debugged program's data segment:
104c1213 11540
8e04817f
AC
11541@smallexample
11542@exdent @code{(@value{GDBP}) info dos ldt $ds}
11543@exdent @code{0x13f: base=0x11970000 limit=0x0009ffff 32-Bit Data (Read/Write, Exp-up)}
11544@end smallexample
104c1213 11545
8e04817f
AC
11546@noindent
11547This comes in handy when you want to see whether a pointer is outside
11548the data segment's limit (i.e.@: @dfn{garbled}).
104c1213 11549
8e04817f
AC
11550@cindex page tables display (MS-DOS)
11551@item info dos pde
11552@itemx info dos pte
11553These two commands display entries from, respectively, the Page
11554Directory and the Page Tables. Page Directories and Page Tables are
11555data structures which control how virtual memory addresses are mapped
11556into physical addresses. A Page Table includes an entry for every
11557page of memory that is mapped into the program's address space; there
11558may be several Page Tables, each one holding up to 4096 entries. A
11559Page Directory has up to 4096 entries, one each for every Page Table
11560that is currently in use.
104c1213 11561
8e04817f
AC
11562Without an argument, @kbd{info dos pde} displays the entire Page
11563Directory, and @kbd{info dos pte} displays all the entries in all of
11564the Page Tables. An argument, an integer expression, given to the
11565@kbd{info dos pde} command means display only that entry from the Page
11566Directory table. An argument given to the @kbd{info dos pte} command
11567means display entries from a single Page Table, the one pointed to by
11568the specified entry in the Page Directory.
104c1213 11569
8e04817f
AC
11570@cindex direct memory access (DMA) on MS-DOS
11571These commands are useful when your program uses @dfn{DMA} (Direct
11572Memory Access), which needs physical addresses to program the DMA
11573controller.
104c1213 11574
8e04817f 11575These commands are supported only with some DPMI servers.
104c1213 11576
8e04817f
AC
11577@cindex physical address from linear address
11578@item info dos address-pte @var{addr}
11579This command displays the Page Table entry for a specified linear
11580address. The argument linear address @var{addr} should already have the
11581appropriate segment's base address added to it, because this command
11582accepts addresses which may belong to @emph{any} segment. For
11583example, here's how to display the Page Table entry for the page where
11584the variable @code{i} is stored:
104c1213 11585
b383017d 11586@smallexample
8e04817f
AC
11587@exdent @code{(@value{GDBP}) info dos address-pte __djgpp_base_address + (char *)&i}
11588@exdent @code{Page Table entry for address 0x11a00d30:}
b383017d 11589@exdent @code{Base=0x02698000 Dirty Acc. Not-Cached Write-Back Usr Read-Write +0xd30}
8e04817f 11590@end smallexample
104c1213 11591
8e04817f
AC
11592@noindent
11593This says that @code{i} is stored at offset @code{0xd30} from the page
11594whose physical base address is @code{0x02698000}, and prints all the
11595attributes of that page.
104c1213 11596
8e04817f
AC
11597Note that you must cast the addresses of variables to a @code{char *},
11598since otherwise the value of @code{__djgpp_base_address}, the base
11599address of all variables and functions in a @sc{djgpp} program, will
11600be added using the rules of C pointer arithmetics: if @code{i} is
11601declared an @code{int}, @value{GDBN} will add 4 times the value of
11602@code{__djgpp_base_address} to the address of @code{i}.
104c1213 11603
8e04817f
AC
11604Here's another example, it displays the Page Table entry for the
11605transfer buffer:
104c1213 11606
8e04817f
AC
11607@smallexample
11608@exdent @code{(@value{GDBP}) info dos address-pte *((unsigned *)&_go32_info_block + 3)}
11609@exdent @code{Page Table entry for address 0x29110:}
11610@exdent @code{Base=0x00029000 Dirty Acc. Not-Cached Write-Back Usr Read-Write +0x110}
11611@end smallexample
104c1213 11612
8e04817f
AC
11613@noindent
11614(The @code{+ 3} offset is because the transfer buffer's address is the
116153rd member of the @code{_go32_info_block} structure.) The output of
11616this command clearly shows that addresses in conventional memory are
11617mapped 1:1, i.e.@: the physical and linear addresses are identical.
104c1213 11618
8e04817f
AC
11619This command is supported only with some DPMI servers.
11620@end table
104c1213 11621
78c47bea
PM
11622@node Cygwin Native
11623@subsection Features for Debugging MS Windows PE executables
11624@cindex MS Windows debugging
11625@cindex native Cygwin debugging
11626@cindex Cygwin-specific commands
11627
be448670
CF
11628@value{GDBN} supports native debugging of MS Windows programs, including
11629DLLs with and without symbolic debugging information. There are various
11630additional Cygwin-specific commands, described in this subsection. The
11631subsubsection @pxref{Non-debug DLL symbols} describes working with DLLs
11632that have no debugging symbols.
11633
78c47bea
PM
11634
11635@table @code
11636@kindex info w32
11637@item info w32
11638This is a prefix of MS Windows specific commands which print
11639information about the target system and important OS structures.
11640
11641@item info w32 selector
11642This command displays information returned by
11643the Win32 API @code{GetThreadSelectorEntry} function.
11644It takes an optional argument that is evaluated to
11645a long value to give the information about this given selector.
11646Without argument, this command displays information
11647about the the six segment registers.
11648
11649@kindex info dll
11650@item info dll
11651This is a Cygwin specific alias of info shared.
11652
11653@kindex dll-symbols
11654@item dll-symbols
11655This command loads symbols from a dll similarly to
11656add-sym command but without the need to specify a base address.
11657
b383017d 11658@kindex set new-console
78c47bea 11659@item set new-console @var{mode}
b383017d 11660If @var{mode} is @code{on} the debuggee will
78c47bea
PM
11661be started in a new console on next start.
11662If @var{mode} is @code{off}i, the debuggee will
11663be started in the same console as the debugger.
11664
11665@kindex show new-console
11666@item show new-console
11667Displays whether a new console is used
11668when the debuggee is started.
11669
11670@kindex set new-group
11671@item set new-group @var{mode}
11672This boolean value controls whether the debuggee should
11673start a new group or stay in the same group as the debugger.
11674This affects the way the Windows OS handles
11675Ctrl-C.
11676
11677@kindex show new-group
11678@item show new-group
11679Displays current value of new-group boolean.
11680
11681@kindex set debugevents
11682@item set debugevents
11683This boolean value adds debug output concerning events seen by the debugger.
11684
11685@kindex set debugexec
11686@item set debugexec
b383017d 11687This boolean value adds debug output concerning execute events
78c47bea
PM
11688seen by the debugger.
11689
11690@kindex set debugexceptions
11691@item set debugexceptions
b383017d 11692This boolean value adds debug ouptut concerning exception events
78c47bea
PM
11693seen by the debugger.
11694
11695@kindex set debugmemory
11696@item set debugmemory
b383017d 11697This boolean value adds debug ouptut concerning memory events
78c47bea
PM
11698seen by the debugger.
11699
11700@kindex set shell
11701@item set shell
11702This boolean values specifies whether the debuggee is called
11703via a shell or directly (default value is on).
11704
11705@kindex show shell
11706@item show shell
11707Displays if the debuggee will be started with a shell.
11708
11709@end table
11710
be448670
CF
11711@menu
11712* Non-debug DLL symbols:: Support for DLLs without debugging symbols
11713@end menu
11714
11715@node Non-debug DLL symbols
11716@subsubsection Support for DLLs without debugging symbols
11717@cindex DLLs with no debugging symbols
11718@cindex Minimal symbols and DLLs
11719
11720Very often on windows, some of the DLLs that your program relies on do
11721not include symbolic debugging information (for example,
11722@file{kernel32.dll}). When @value{GDBN} doesn't recognize any debugging
11723symbols in a DLL, it relies on the minimal amount of symbolic
11724information contained in the DLL's export table. This subsubsection
11725describes working with such symbols, known internally to @value{GDBN} as
11726``minimal symbols''.
11727
11728Note that before the debugged program has started execution, no DLLs
11729will have been loaded. The easiest way around this problem is simply to
11730start the program --- either by setting a breakpoint or letting the
11731program run once to completion. It is also possible to force
11732@value{GDBN} to load a particular DLL before starting the executable ---
11733see the shared library information in @pxref{Files} or the
11734@code{dll-symbols} command in @pxref{Cygwin Native}. Currently,
11735explicitly loading symbols from a DLL with no debugging information will
11736cause the symbol names to be duplicated in @value{GDBN}'s lookup table,
11737which may adversely affect symbol lookup performance.
11738
11739@subsubsection DLL name prefixes
11740
11741In keeping with the naming conventions used by the Microsoft debugging
11742tools, DLL export symbols are made available with a prefix based on the
11743DLL name, for instance @code{KERNEL32!CreateFileA}. The plain name is
11744also entered into the symbol table, so @code{CreateFileA} is often
11745sufficient. In some cases there will be name clashes within a program
11746(particularly if the executable itself includes full debugging symbols)
11747necessitating the use of the fully qualified name when referring to the
11748contents of the DLL. Use single-quotes around the name to avoid the
11749exclamation mark (``!'') being interpreted as a language operator.
11750
11751Note that the internal name of the DLL may be all upper-case, even
11752though the file name of the DLL is lower-case, or vice-versa. Since
11753symbols within @value{GDBN} are @emph{case-sensitive} this may cause
11754some confusion. If in doubt, try the @code{info functions} and
11755@code{info variables} commands or even @code{maint print msymbols} (see
11756@pxref{Symbols}). Here's an example:
11757
11758@smallexample
11759(gdb) info function CreateFileA
11760All functions matching regular expression "CreateFileA":
11761
11762Non-debugging symbols:
117630x77e885f4 CreateFileA
117640x77e885f4 KERNEL32!CreateFileA
11765@end smallexample
11766
11767@smallexample
11768(gdb) info function !
11769All functions matching regular expression "!":
11770
11771Non-debugging symbols:
117720x6100114c cygwin1!__assert
117730x61004034 cygwin1!_dll_crt0@@0
117740x61004240 cygwin1!dll_crt0(per_process *)
11775[etc...]
11776@end smallexample
11777
11778@subsubsection Working with minimal symbols
11779
11780Symbols extracted from a DLL's export table do not contain very much
11781type information. All that @value{GDBN} can do is guess whether a symbol
11782refers to a function or variable depending on the linker section that
11783contains the symbol. Also note that the actual contents of the memory
11784contained in a DLL are not available unless the program is running. This
11785means that you cannot examine the contents of a variable or disassemble
11786a function within a DLL without a running program.
11787
11788Variables are generally treated as pointers and dereferenced
11789automatically. For this reason, it is often necessary to prefix a
11790variable name with the address-of operator (``&'') and provide explicit
11791type information in the command. Here's an example of the type of
11792problem:
11793
11794@smallexample
11795(gdb) print 'cygwin1!__argv'
11796$1 = 268572168
11797@end smallexample
11798
11799@smallexample
11800(gdb) x 'cygwin1!__argv'
118010x10021610: "\230y\""
11802@end smallexample
11803
11804And two possible solutions:
11805
11806@smallexample
11807(gdb) print ((char **)'cygwin1!__argv')[0]
11808$2 = 0x22fd98 "/cygdrive/c/mydirectory/myprogram"
11809@end smallexample
11810
11811@smallexample
11812(gdb) x/2x &'cygwin1!__argv'
118130x610c0aa8 <cygwin1!__argv>: 0x10021608 0x00000000
11814(gdb) x/x 0x10021608
118150x10021608: 0x0022fd98
11816(gdb) x/s 0x0022fd98
118170x22fd98: "/cygdrive/c/mydirectory/myprogram"
11818@end smallexample
11819
11820Setting a break point within a DLL is possible even before the program
11821starts execution. However, under these circumstances, @value{GDBN} can't
11822examine the initial instructions of the function in order to skip the
11823function's frame set-up code. You can work around this by using ``*&''
11824to set the breakpoint at a raw memory address:
11825
11826@smallexample
11827(gdb) break *&'python22!PyOS_Readline'
11828Breakpoint 1 at 0x1e04eff0
11829@end smallexample
11830
11831The author of these extensions is not entirely convinced that setting a
11832break point within a shared DLL like @file{kernel32.dll} is completely
11833safe.
11834
8e04817f
AC
11835@node Embedded OS
11836@section Embedded Operating Systems
104c1213 11837
8e04817f
AC
11838This section describes configurations involving the debugging of
11839embedded operating systems that are available for several different
11840architectures.
d4f3574e 11841
8e04817f
AC
11842@menu
11843* VxWorks:: Using @value{GDBN} with VxWorks
11844@end menu
104c1213 11845
8e04817f
AC
11846@value{GDBN} includes the ability to debug programs running on
11847various real-time operating systems.
104c1213 11848
8e04817f
AC
11849@node VxWorks
11850@subsection Using @value{GDBN} with VxWorks
104c1213 11851
8e04817f 11852@cindex VxWorks
104c1213 11853
8e04817f 11854@table @code
104c1213 11855
8e04817f
AC
11856@kindex target vxworks
11857@item target vxworks @var{machinename}
11858A VxWorks system, attached via TCP/IP. The argument @var{machinename}
11859is the target system's machine name or IP address.
104c1213 11860
8e04817f 11861@end table
104c1213 11862
8e04817f
AC
11863On VxWorks, @code{load} links @var{filename} dynamically on the
11864current target system as well as adding its symbols in @value{GDBN}.
104c1213 11865
8e04817f
AC
11866@value{GDBN} enables developers to spawn and debug tasks running on networked
11867VxWorks targets from a Unix host. Already-running tasks spawned from
11868the VxWorks shell can also be debugged. @value{GDBN} uses code that runs on
11869both the Unix host and on the VxWorks target. The program
11870@code{@value{GDBP}} is installed and executed on the Unix host. (It may be
11871installed with the name @code{vxgdb}, to distinguish it from a
11872@value{GDBN} for debugging programs on the host itself.)
104c1213 11873
8e04817f
AC
11874@table @code
11875@item VxWorks-timeout @var{args}
11876@kindex vxworks-timeout
11877All VxWorks-based targets now support the option @code{vxworks-timeout}.
11878This option is set by the user, and @var{args} represents the number of
11879seconds @value{GDBN} waits for responses to rpc's. You might use this if
11880your VxWorks target is a slow software simulator or is on the far side
11881of a thin network line.
11882@end table
104c1213 11883
8e04817f
AC
11884The following information on connecting to VxWorks was current when
11885this manual was produced; newer releases of VxWorks may use revised
11886procedures.
104c1213 11887
4644b6e3 11888@findex INCLUDE_RDB
8e04817f
AC
11889To use @value{GDBN} with VxWorks, you must rebuild your VxWorks kernel
11890to include the remote debugging interface routines in the VxWorks
11891library @file{rdb.a}. To do this, define @code{INCLUDE_RDB} in the
11892VxWorks configuration file @file{configAll.h} and rebuild your VxWorks
11893kernel. The resulting kernel contains @file{rdb.a}, and spawns the
11894source debugging task @code{tRdbTask} when VxWorks is booted. For more
11895information on configuring and remaking VxWorks, see the manufacturer's
11896manual.
11897@c VxWorks, see the @cite{VxWorks Programmer's Guide}.
104c1213 11898
8e04817f
AC
11899Once you have included @file{rdb.a} in your VxWorks system image and set
11900your Unix execution search path to find @value{GDBN}, you are ready to
11901run @value{GDBN}. From your Unix host, run @code{@value{GDBP}} (or
11902@code{vxgdb}, depending on your installation).
104c1213 11903
8e04817f 11904@value{GDBN} comes up showing the prompt:
104c1213 11905
474c8240 11906@smallexample
8e04817f 11907(vxgdb)
474c8240 11908@end smallexample
104c1213 11909
8e04817f
AC
11910@menu
11911* VxWorks Connection:: Connecting to VxWorks
11912* VxWorks Download:: VxWorks download
11913* VxWorks Attach:: Running tasks
11914@end menu
104c1213 11915
8e04817f
AC
11916@node VxWorks Connection
11917@subsubsection Connecting to VxWorks
104c1213 11918
8e04817f
AC
11919The @value{GDBN} command @code{target} lets you connect to a VxWorks target on the
11920network. To connect to a target whose host name is ``@code{tt}'', type:
104c1213 11921
474c8240 11922@smallexample
8e04817f 11923(vxgdb) target vxworks tt
474c8240 11924@end smallexample
104c1213 11925
8e04817f
AC
11926@need 750
11927@value{GDBN} displays messages like these:
104c1213 11928
8e04817f
AC
11929@smallexample
11930Attaching remote machine across net...
11931Connected to tt.
11932@end smallexample
104c1213 11933
8e04817f
AC
11934@need 1000
11935@value{GDBN} then attempts to read the symbol tables of any object modules
11936loaded into the VxWorks target since it was last booted. @value{GDBN} locates
11937these files by searching the directories listed in the command search
11938path (@pxref{Environment, ,Your program's environment}); if it fails
11939to find an object file, it displays a message such as:
5d161b24 11940
474c8240 11941@smallexample
8e04817f 11942prog.o: No such file or directory.
474c8240 11943@end smallexample
104c1213 11944
8e04817f
AC
11945When this happens, add the appropriate directory to the search path with
11946the @value{GDBN} command @code{path}, and execute the @code{target}
11947command again.
104c1213 11948
8e04817f
AC
11949@node VxWorks Download
11950@subsubsection VxWorks download
104c1213 11951
8e04817f
AC
11952@cindex download to VxWorks
11953If you have connected to the VxWorks target and you want to debug an
11954object that has not yet been loaded, you can use the @value{GDBN}
11955@code{load} command to download a file from Unix to VxWorks
11956incrementally. The object file given as an argument to the @code{load}
11957command is actually opened twice: first by the VxWorks target in order
11958to download the code, then by @value{GDBN} in order to read the symbol
11959table. This can lead to problems if the current working directories on
11960the two systems differ. If both systems have NFS mounted the same
11961filesystems, you can avoid these problems by using absolute paths.
11962Otherwise, it is simplest to set the working directory on both systems
11963to the directory in which the object file resides, and then to reference
11964the file by its name, without any path. For instance, a program
11965@file{prog.o} may reside in @file{@var{vxpath}/vw/demo/rdb} in VxWorks
11966and in @file{@var{hostpath}/vw/demo/rdb} on the host. To load this
11967program, type this on VxWorks:
104c1213 11968
474c8240 11969@smallexample
8e04817f 11970-> cd "@var{vxpath}/vw/demo/rdb"
474c8240 11971@end smallexample
104c1213 11972
8e04817f
AC
11973@noindent
11974Then, in @value{GDBN}, type:
104c1213 11975
474c8240 11976@smallexample
8e04817f
AC
11977(vxgdb) cd @var{hostpath}/vw/demo/rdb
11978(vxgdb) load prog.o
474c8240 11979@end smallexample
104c1213 11980
8e04817f 11981@value{GDBN} displays a response similar to this:
104c1213 11982
8e04817f
AC
11983@smallexample
11984Reading symbol data from wherever/vw/demo/rdb/prog.o... done.
11985@end smallexample
104c1213 11986
8e04817f
AC
11987You can also use the @code{load} command to reload an object module
11988after editing and recompiling the corresponding source file. Note that
11989this makes @value{GDBN} delete all currently-defined breakpoints,
11990auto-displays, and convenience variables, and to clear the value
11991history. (This is necessary in order to preserve the integrity of
11992debugger's data structures that reference the target system's symbol
11993table.)
104c1213 11994
8e04817f
AC
11995@node VxWorks Attach
11996@subsubsection Running tasks
104c1213
JM
11997
11998@cindex running VxWorks tasks
11999You can also attach to an existing task using the @code{attach} command as
12000follows:
12001
474c8240 12002@smallexample
104c1213 12003(vxgdb) attach @var{task}
474c8240 12004@end smallexample
104c1213
JM
12005
12006@noindent
12007where @var{task} is the VxWorks hexadecimal task ID. The task can be running
12008or suspended when you attach to it. Running tasks are suspended at
12009the time of attachment.
12010
6d2ebf8b 12011@node Embedded Processors
104c1213
JM
12012@section Embedded Processors
12013
12014This section goes into details specific to particular embedded
12015configurations.
12016
7d86b5d5 12017
104c1213 12018@menu
104c1213 12019* ARM:: ARM
172c2a43
KI
12020* H8/300:: Renesas H8/300
12021* H8/500:: Renesas H8/500
12022* M32R/D:: Renesas M32R/D
104c1213 12023* M68K:: Motorola M68K
104c1213 12024* MIPS Embedded:: MIPS Embedded
a37295f9 12025* OpenRISC 1000:: OpenRisc 1000
104c1213
JM
12026* PA:: HP PA Embedded
12027* PowerPC: PowerPC
172c2a43 12028* SH:: Renesas SH
104c1213
JM
12029* Sparclet:: Tsqware Sparclet
12030* Sparclite:: Fujitsu Sparclite
12031* ST2000:: Tandem ST2000
12032* Z8000:: Zilog Z8000
12033@end menu
12034
6d2ebf8b 12035@node ARM
104c1213
JM
12036@subsection ARM
12037
12038@table @code
12039
8e04817f
AC
12040@kindex target rdi
12041@item target rdi @var{dev}
12042ARM Angel monitor, via RDI library interface to ADP protocol. You may
12043use this target to communicate with both boards running the Angel
12044monitor, or with the EmbeddedICE JTAG debug device.
12045
12046@kindex target rdp
12047@item target rdp @var{dev}
12048ARM Demon monitor.
12049
12050@end table
12051
12052@node H8/300
172c2a43 12053@subsection Renesas H8/300
8e04817f
AC
12054
12055@table @code
12056
12057@kindex target hms@r{, with H8/300}
12058@item target hms @var{dev}
172c2a43 12059A Renesas SH, H8/300, or H8/500 board, attached via serial line to your host.
8e04817f
AC
12060Use special commands @code{device} and @code{speed} to control the serial
12061line and the communications speed used.
12062
12063@kindex target e7000@r{, with H8/300}
12064@item target e7000 @var{dev}
172c2a43 12065E7000 emulator for Renesas H8 and SH.
8e04817f
AC
12066
12067@kindex target sh3@r{, with H8/300}
12068@kindex target sh3e@r{, with H8/300}
12069@item target sh3 @var{dev}
12070@itemx target sh3e @var{dev}
172c2a43 12071Renesas SH-3 and SH-3E target systems.
8e04817f
AC
12072
12073@end table
12074
12075@cindex download to H8/300 or H8/500
12076@cindex H8/300 or H8/500 download
172c2a43
KI
12077@cindex download to Renesas SH
12078@cindex Renesas SH download
12079When you select remote debugging to a Renesas SH, H8/300, or H8/500
12080board, the @code{load} command downloads your program to the Renesas
8e04817f
AC
12081board and also opens it as the current executable target for
12082@value{GDBN} on your host (like the @code{file} command).
12083
12084@value{GDBN} needs to know these things to talk to your
172c2a43 12085Renesas SH, H8/300, or H8/500:
8e04817f
AC
12086
12087@enumerate
12088@item
12089that you want to use @samp{target hms}, the remote debugging interface
172c2a43
KI
12090for Renesas microprocessors, or @samp{target e7000}, the in-circuit
12091emulator for the Renesas SH and the Renesas 300H. (@samp{target hms} is
12092the default when @value{GDBN} is configured specifically for the Renesas SH,
8e04817f
AC
12093H8/300, or H8/500.)
12094
12095@item
172c2a43 12096what serial device connects your host to your Renesas board (the first
8e04817f
AC
12097serial device available on your host is the default).
12098
12099@item
12100what speed to use over the serial device.
12101@end enumerate
12102
12103@menu
172c2a43
KI
12104* Renesas Boards:: Connecting to Renesas boards.
12105* Renesas ICE:: Using the E7000 In-Circuit Emulator.
12106* Renesas Special:: Special @value{GDBN} commands for Renesas micros.
8e04817f
AC
12107@end menu
12108
172c2a43
KI
12109@node Renesas Boards
12110@subsubsection Connecting to Renesas boards
8e04817f
AC
12111
12112@c only for Unix hosts
12113@kindex device
172c2a43 12114@cindex serial device, Renesas micros
8e04817f
AC
12115Use the special @code{@value{GDBN}} command @samp{device @var{port}} if you
12116need to explicitly set the serial device. The default @var{port} is the
12117first available port on your host. This is only necessary on Unix
12118hosts, where it is typically something like @file{/dev/ttya}.
12119
12120@kindex speed
172c2a43 12121@cindex serial line speed, Renesas micros
8e04817f
AC
12122@code{@value{GDBN}} has another special command to set the communications
12123speed: @samp{speed @var{bps}}. This command also is only used from Unix
12124hosts; on DOS hosts, set the line speed as usual from outside @value{GDBN} with
12125the DOS @code{mode} command (for instance,
12126@w{@kbd{mode com2:9600,n,8,1,p}} for a 9600@dmn{bps} connection).
12127
12128The @samp{device} and @samp{speed} commands are available only when you
172c2a43 12129use a Unix host to debug your Renesas microprocessor programs. If you
8e04817f
AC
12130use a DOS host,
12131@value{GDBN} depends on an auxiliary terminate-and-stay-resident program
12132called @code{asynctsr} to communicate with the development board
12133through a PC serial port. You must also use the DOS @code{mode} command
12134to set up the serial port on the DOS side.
12135
12136The following sample session illustrates the steps needed to start a
12137program under @value{GDBN} control on an H8/300. The example uses a
12138sample H8/300 program called @file{t.x}. The procedure is the same for
172c2a43 12139the Renesas SH and the H8/500.
8e04817f
AC
12140
12141First hook up your development board. In this example, we use a
12142board attached to serial port @code{COM2}; if you use a different serial
12143port, substitute its name in the argument of the @code{mode} command.
12144When you call @code{asynctsr}, the auxiliary comms program used by the
12145debugger, you give it just the numeric part of the serial port's name;
12146for example, @samp{asyncstr 2} below runs @code{asyncstr} on
12147@code{COM2}.
12148
474c8240 12149@smallexample
8e04817f
AC
12150C:\H8300\TEST> asynctsr 2
12151C:\H8300\TEST> mode com2:9600,n,8,1,p
12152
12153Resident portion of MODE loaded
12154
12155COM2: 9600, n, 8, 1, p
12156
474c8240 12157@end smallexample
8e04817f
AC
12158
12159@quotation
12160@emph{Warning:} We have noticed a bug in PC-NFS that conflicts with
12161@code{asynctsr}. If you also run PC-NFS on your DOS host, you may need to
12162disable it, or even boot without it, to use @code{asynctsr} to control
12163your development board.
12164@end quotation
12165
12166@kindex target hms@r{, and serial protocol}
12167Now that serial communications are set up, and the development board is
12168connected, you can start up @value{GDBN}. Call @code{@value{GDBP}} with
12169the name of your program as the argument. @code{@value{GDBN}} prompts
12170you, as usual, with the prompt @samp{(@value{GDBP})}. Use two special
12171commands to begin your debugging session: @samp{target hms} to specify
172c2a43 12172cross-debugging to the Renesas board, and the @code{load} command to
8e04817f
AC
12173download your program to the board. @code{load} displays the names of
12174the program's sections, and a @samp{*} for each 2K of data downloaded.
12175(If you want to refresh @value{GDBN} data on symbols or on the
12176executable file without downloading, use the @value{GDBN} commands
12177@code{file} or @code{symbol-file}. These commands, and @code{load}
12178itself, are described in @ref{Files,,Commands to specify files}.)
12179
12180@smallexample
12181(eg-C:\H8300\TEST) @value{GDBP} t.x
12182@value{GDBN} is free software and you are welcome to distribute copies
12183 of it under certain conditions; type "show copying" to see
12184 the conditions.
12185There is absolutely no warranty for @value{GDBN}; type "show warranty"
12186for details.
12187@value{GDBN} @value{GDBVN}, Copyright 1992 Free Software Foundation, Inc...
12188(@value{GDBP}) target hms
12189Connected to remote H8/300 HMS system.
12190(@value{GDBP}) load t.x
12191.text : 0x8000 .. 0xabde ***********
12192.data : 0xabde .. 0xad30 *
12193.stack : 0xf000 .. 0xf014 *
12194@end smallexample
12195
12196At this point, you're ready to run or debug your program. From here on,
12197you can use all the usual @value{GDBN} commands. The @code{break} command
12198sets breakpoints; the @code{run} command starts your program;
12199@code{print} or @code{x} display data; the @code{continue} command
12200resumes execution after stopping at a breakpoint. You can use the
12201@code{help} command at any time to find out more about @value{GDBN} commands.
12202
12203Remember, however, that @emph{operating system} facilities aren't
12204available on your development board; for example, if your program hangs,
12205you can't send an interrupt---but you can press the @sc{reset} switch!
12206
12207Use the @sc{reset} button on the development board
12208@itemize @bullet
12209@item
12210to interrupt your program (don't use @kbd{ctl-C} on the DOS host---it has
12211no way to pass an interrupt signal to the development board); and
12212
12213@item
12214to return to the @value{GDBN} command prompt after your program finishes
12215normally. The communications protocol provides no other way for @value{GDBN}
12216to detect program completion.
12217@end itemize
12218
12219In either case, @value{GDBN} sees the effect of a @sc{reset} on the
12220development board as a ``normal exit'' of your program.
12221
172c2a43 12222@node Renesas ICE
8e04817f
AC
12223@subsubsection Using the E7000 in-circuit emulator
12224
172c2a43 12225@kindex target e7000@r{, with Renesas ICE}
8e04817f 12226You can use the E7000 in-circuit emulator to develop code for either the
172c2a43 12227Renesas SH or the H8/300H. Use one of these forms of the @samp{target
8e04817f
AC
12228e7000} command to connect @value{GDBN} to your E7000:
12229
12230@table @code
12231@item target e7000 @var{port} @var{speed}
12232Use this form if your E7000 is connected to a serial port. The
12233@var{port} argument identifies what serial port to use (for example,
12234@samp{com2}). The third argument is the line speed in bits per second
12235(for example, @samp{9600}).
12236
12237@item target e7000 @var{hostname}
12238If your E7000 is installed as a host on a TCP/IP network, you can just
12239specify its hostname; @value{GDBN} uses @code{telnet} to connect.
12240@end table
12241
172c2a43
KI
12242@node Renesas Special
12243@subsubsection Special @value{GDBN} commands for Renesas micros
8e04817f
AC
12244
12245Some @value{GDBN} commands are available only for the H8/300:
12246
12247@table @code
12248
12249@kindex set machine
12250@kindex show machine
12251@item set machine h8300
12252@itemx set machine h8300h
12253Condition @value{GDBN} for one of the two variants of the H8/300
12254architecture with @samp{set machine}. You can use @samp{show machine}
12255to check which variant is currently in effect.
104c1213
JM
12256
12257@end table
12258
8e04817f
AC
12259@node H8/500
12260@subsection H8/500
104c1213
JM
12261
12262@table @code
12263
8e04817f
AC
12264@kindex set memory @var{mod}
12265@cindex memory models, H8/500
12266@item set memory @var{mod}
12267@itemx show memory
12268Specify which H8/500 memory model (@var{mod}) you are using with
12269@samp{set memory}; check which memory model is in effect with @samp{show
12270memory}. The accepted values for @var{mod} are @code{small},
12271@code{big}, @code{medium}, and @code{compact}.
104c1213 12272
8e04817f 12273@end table
104c1213 12274
8e04817f 12275@node M32R/D
172c2a43 12276@subsection Renesas M32R/D
8e04817f
AC
12277
12278@table @code
12279
12280@kindex target m32r
12281@item target m32r @var{dev}
172c2a43 12282Renesas M32R/D ROM monitor.
8e04817f 12283
fb3e19c0
KI
12284@kindex target m32rsdi
12285@item target m32rsdi @var{dev}
12286Renesas M32R SDI server, connected via parallel port to the board.
12287
8e04817f
AC
12288@end table
12289
12290@node M68K
12291@subsection M68k
12292
12293The Motorola m68k configuration includes ColdFire support, and
12294target command for the following ROM monitors.
12295
12296@table @code
12297
12298@kindex target abug
12299@item target abug @var{dev}
12300ABug ROM monitor for M68K.
12301
12302@kindex target cpu32bug
12303@item target cpu32bug @var{dev}
12304CPU32BUG monitor, running on a CPU32 (M68K) board.
12305
12306@kindex target dbug
12307@item target dbug @var{dev}
12308dBUG ROM monitor for Motorola ColdFire.
12309
12310@kindex target est
12311@item target est @var{dev}
12312EST-300 ICE monitor, running on a CPU32 (M68K) board.
12313
12314@kindex target rom68k
12315@item target rom68k @var{dev}
12316ROM 68K monitor, running on an M68K IDP board.
12317
12318@end table
12319
8e04817f
AC
12320@table @code
12321
12322@kindex target rombug
12323@item target rombug @var{dev}
12324ROMBUG ROM monitor for OS/9000.
12325
12326@end table
12327
8e04817f
AC
12328@node MIPS Embedded
12329@subsection MIPS Embedded
12330
12331@cindex MIPS boards
12332@value{GDBN} can use the MIPS remote debugging protocol to talk to a
12333MIPS board attached to a serial line. This is available when
12334you configure @value{GDBN} with @samp{--target=mips-idt-ecoff}.
104c1213 12335
8e04817f
AC
12336@need 1000
12337Use these @value{GDBN} commands to specify the connection to your target board:
104c1213 12338
8e04817f
AC
12339@table @code
12340@item target mips @var{port}
12341@kindex target mips @var{port}
12342To run a program on the board, start up @code{@value{GDBP}} with the
12343name of your program as the argument. To connect to the board, use the
12344command @samp{target mips @var{port}}, where @var{port} is the name of
12345the serial port connected to the board. If the program has not already
12346been downloaded to the board, you may use the @code{load} command to
12347download it. You can then use all the usual @value{GDBN} commands.
104c1213 12348
8e04817f
AC
12349For example, this sequence connects to the target board through a serial
12350port, and loads and runs a program called @var{prog} through the
12351debugger:
104c1213 12352
474c8240 12353@smallexample
8e04817f
AC
12354host$ @value{GDBP} @var{prog}
12355@value{GDBN} is free software and @dots{}
12356(@value{GDBP}) target mips /dev/ttyb
12357(@value{GDBP}) load @var{prog}
12358(@value{GDBP}) run
474c8240 12359@end smallexample
104c1213 12360
8e04817f
AC
12361@item target mips @var{hostname}:@var{portnumber}
12362On some @value{GDBN} host configurations, you can specify a TCP
12363connection (for instance, to a serial line managed by a terminal
12364concentrator) instead of a serial port, using the syntax
12365@samp{@var{hostname}:@var{portnumber}}.
104c1213 12366
8e04817f
AC
12367@item target pmon @var{port}
12368@kindex target pmon @var{port}
12369PMON ROM monitor.
104c1213 12370
8e04817f
AC
12371@item target ddb @var{port}
12372@kindex target ddb @var{port}
12373NEC's DDB variant of PMON for Vr4300.
104c1213 12374
8e04817f
AC
12375@item target lsi @var{port}
12376@kindex target lsi @var{port}
12377LSI variant of PMON.
104c1213 12378
8e04817f
AC
12379@kindex target r3900
12380@item target r3900 @var{dev}
12381Densan DVE-R3900 ROM monitor for Toshiba R3900 Mips.
104c1213 12382
8e04817f
AC
12383@kindex target array
12384@item target array @var{dev}
12385Array Tech LSI33K RAID controller board.
104c1213 12386
8e04817f 12387@end table
104c1213 12388
104c1213 12389
8e04817f
AC
12390@noindent
12391@value{GDBN} also supports these special commands for MIPS targets:
104c1213 12392
8e04817f
AC
12393@table @code
12394@item set processor @var{args}
12395@itemx show processor
12396@kindex set processor @var{args}
12397@kindex show processor
12398Use the @code{set processor} command to set the type of MIPS
12399processor when you want to access processor-type-specific registers.
12400For example, @code{set processor @var{r3041}} tells @value{GDBN}
12401to use the CPU registers appropriate for the 3041 chip.
12402Use the @code{show processor} command to see what MIPS processor @value{GDBN}
12403is using. Use the @code{info reg} command to see what registers
12404@value{GDBN} is using.
104c1213 12405
8e04817f
AC
12406@item set mipsfpu double
12407@itemx set mipsfpu single
12408@itemx set mipsfpu none
12409@itemx show mipsfpu
12410@kindex set mipsfpu
12411@kindex show mipsfpu
12412@cindex MIPS remote floating point
12413@cindex floating point, MIPS remote
12414If your target board does not support the MIPS floating point
12415coprocessor, you should use the command @samp{set mipsfpu none} (if you
12416need this, you may wish to put the command in your @value{GDBN} init
12417file). This tells @value{GDBN} how to find the return value of
12418functions which return floating point values. It also allows
12419@value{GDBN} to avoid saving the floating point registers when calling
12420functions on the board. If you are using a floating point coprocessor
12421with only single precision floating point support, as on the @sc{r4650}
12422processor, use the command @samp{set mipsfpu single}. The default
12423double precision floating point coprocessor may be selected using
12424@samp{set mipsfpu double}.
104c1213 12425
8e04817f
AC
12426In previous versions the only choices were double precision or no
12427floating point, so @samp{set mipsfpu on} will select double precision
12428and @samp{set mipsfpu off} will select no floating point.
104c1213 12429
8e04817f
AC
12430As usual, you can inquire about the @code{mipsfpu} variable with
12431@samp{show mipsfpu}.
104c1213 12432
8e04817f
AC
12433@item set remotedebug @var{n}
12434@itemx show remotedebug
12435@kindex set remotedebug@r{, MIPS protocol}
12436@kindex show remotedebug@r{, MIPS protocol}
12437@cindex @code{remotedebug}, MIPS protocol
12438@cindex MIPS @code{remotedebug} protocol
12439@c FIXME! For this to be useful, you must know something about the MIPS
12440@c FIXME...protocol. Where is it described?
12441You can see some debugging information about communications with the board
12442by setting the @code{remotedebug} variable. If you set it to @code{1} using
12443@samp{set remotedebug 1}, every packet is displayed. If you set it
12444to @code{2}, every character is displayed. You can check the current value
12445at any time with the command @samp{show remotedebug}.
104c1213 12446
8e04817f
AC
12447@item set timeout @var{seconds}
12448@itemx set retransmit-timeout @var{seconds}
12449@itemx show timeout
12450@itemx show retransmit-timeout
12451@cindex @code{timeout}, MIPS protocol
12452@cindex @code{retransmit-timeout}, MIPS protocol
12453@kindex set timeout
12454@kindex show timeout
12455@kindex set retransmit-timeout
12456@kindex show retransmit-timeout
12457You can control the timeout used while waiting for a packet, in the MIPS
12458remote protocol, with the @code{set timeout @var{seconds}} command. The
12459default is 5 seconds. Similarly, you can control the timeout used while
12460waiting for an acknowledgement of a packet with the @code{set
12461retransmit-timeout @var{seconds}} command. The default is 3 seconds.
12462You can inspect both values with @code{show timeout} and @code{show
12463retransmit-timeout}. (These commands are @emph{only} available when
12464@value{GDBN} is configured for @samp{--target=mips-idt-ecoff}.)
104c1213 12465
8e04817f
AC
12466The timeout set by @code{set timeout} does not apply when @value{GDBN}
12467is waiting for your program to stop. In that case, @value{GDBN} waits
12468forever because it has no way of knowing how long the program is going
12469to run before stopping.
12470@end table
104c1213 12471
a37295f9
MM
12472@node OpenRISC 1000
12473@subsection OpenRISC 1000
12474@cindex OpenRISC 1000
12475
12476@cindex or1k boards
12477See OR1k Architecture document (@uref{www.opencores.org}) for more information
12478about platform and commands.
12479
12480@table @code
12481
12482@kindex target jtag
12483@item target jtag jtag://@var{host}:@var{port}
12484
12485Connects to remote JTAG server.
12486JTAG remote server can be either an or1ksim or JTAG server,
12487connected via parallel port to the board.
12488
12489Example: @code{target jtag jtag://localhost:9999}
12490
12491@kindex or1ksim
12492@item or1ksim @var{command}
12493If connected to @code{or1ksim} OpenRISC 1000 Architectural
12494Simulator, proprietary commands can be executed.
12495
12496@kindex info or1k spr
12497@item info or1k spr
12498Displays spr groups.
12499
12500@item info or1k spr @var{group}
12501@itemx info or1k spr @var{groupno}
12502Displays register names in selected group.
12503
12504@item info or1k spr @var{group} @var{register}
12505@itemx info or1k spr @var{register}
12506@itemx info or1k spr @var{groupno} @var{registerno}
12507@itemx info or1k spr @var{registerno}
12508Shows information about specified spr register.
12509
12510@kindex spr
12511@item spr @var{group} @var{register} @var{value}
12512@itemx spr @var{register @var{value}}
12513@itemx spr @var{groupno} @var{registerno @var{value}}
12514@itemx spr @var{registerno @var{value}}
12515Writes @var{value} to specified spr register.
12516@end table
12517
12518Some implementations of OpenRISC 1000 Architecture also have hardware trace.
12519It is very similar to @value{GDBN} trace, except it does not interfere with normal
12520program execution and is thus much faster. Hardware breakpoints/watchpoint
12521triggers can be set using:
12522@table @code
12523@item $LEA/$LDATA
12524Load effective address/data
12525@item $SEA/$SDATA
12526Store effective address/data
12527@item $AEA/$ADATA
12528Access effective address ($SEA or $LEA) or data ($SDATA/$LDATA)
12529@item $FETCH
12530Fetch data
12531@end table
12532
12533When triggered, it can capture low level data, like: @code{PC}, @code{LSEA},
12534@code{LDATA}, @code{SDATA}, @code{READSPR}, @code{WRITESPR}, @code{INSTR}.
12535
12536@code{htrace} commands:
12537@cindex OpenRISC 1000 htrace
12538@table @code
12539@kindex hwatch
12540@item hwatch @var{conditional}
12541Set hardware watchpoint on combination of Load/Store Effecive Address(es)
12542or Data. For example:
12543
12544@code{hwatch ($LEA == my_var) && ($LDATA < 50) || ($SEA == my_var) && ($SDATA >= 50)}
12545
12546@code{hwatch ($LEA == my_var) && ($LDATA < 50) || ($SEA == my_var) && ($SDATA >= 50)}
12547
4644b6e3 12548@kindex htrace
a37295f9
MM
12549@item htrace info
12550Display information about current HW trace configuration.
12551
a37295f9
MM
12552@item htrace trigger @var{conditional}
12553Set starting criteria for HW trace.
12554
a37295f9
MM
12555@item htrace qualifier @var{conditional}
12556Set acquisition qualifier for HW trace.
12557
a37295f9
MM
12558@item htrace stop @var{conditional}
12559Set HW trace stopping criteria.
12560
f153cc92 12561@item htrace record [@var{data}]*
a37295f9
MM
12562Selects the data to be recorded, when qualifier is met and HW trace was
12563triggered.
12564
a37295f9 12565@item htrace enable
a37295f9
MM
12566@itemx htrace disable
12567Enables/disables the HW trace.
12568
f153cc92 12569@item htrace rewind [@var{filename}]
a37295f9
MM
12570Clears currently recorded trace data.
12571
12572If filename is specified, new trace file is made and any newly collected data
12573will be written there.
12574
f153cc92 12575@item htrace print [@var{start} [@var{len}]]
a37295f9
MM
12576Prints trace buffer, using current record configuration.
12577
a37295f9
MM
12578@item htrace mode continuous
12579Set continuous trace mode.
12580
a37295f9
MM
12581@item htrace mode suspend
12582Set suspend trace mode.
12583
12584@end table
12585
8e04817f
AC
12586@node PowerPC
12587@subsection PowerPC
104c1213
JM
12588
12589@table @code
104c1213 12590
8e04817f
AC
12591@kindex target dink32
12592@item target dink32 @var{dev}
12593DINK32 ROM monitor.
104c1213 12594
8e04817f
AC
12595@kindex target ppcbug
12596@item target ppcbug @var{dev}
12597@kindex target ppcbug1
12598@item target ppcbug1 @var{dev}
12599PPCBUG ROM monitor for PowerPC.
104c1213 12600
8e04817f
AC
12601@kindex target sds
12602@item target sds @var{dev}
12603SDS monitor, running on a PowerPC board (such as Motorola's ADS).
12604
12605@end table
12606
12607@node PA
12608@subsection HP PA Embedded
104c1213
JM
12609
12610@table @code
12611
8e04817f
AC
12612@kindex target op50n
12613@item target op50n @var{dev}
12614OP50N monitor, running on an OKI HPPA board.
12615
12616@kindex target w89k
12617@item target w89k @var{dev}
12618W89K monitor, running on a Winbond HPPA board.
104c1213
JM
12619
12620@end table
12621
8e04817f 12622@node SH
172c2a43 12623@subsection Renesas SH
104c1213
JM
12624
12625@table @code
12626
172c2a43 12627@kindex target hms@r{, with Renesas SH}
8e04817f 12628@item target hms @var{dev}
172c2a43 12629A Renesas SH board attached via serial line to your host. Use special
8e04817f
AC
12630commands @code{device} and @code{speed} to control the serial line and
12631the communications speed used.
104c1213 12632
172c2a43 12633@kindex target e7000@r{, with Renesas SH}
8e04817f 12634@item target e7000 @var{dev}
172c2a43 12635E7000 emulator for Renesas SH.
104c1213 12636
8e04817f
AC
12637@kindex target sh3@r{, with SH}
12638@kindex target sh3e@r{, with SH}
12639@item target sh3 @var{dev}
12640@item target sh3e @var{dev}
172c2a43 12641Renesas SH-3 and SH-3E target systems.
104c1213 12642
8e04817f 12643@end table
104c1213 12644
8e04817f
AC
12645@node Sparclet
12646@subsection Tsqware Sparclet
104c1213 12647
8e04817f
AC
12648@cindex Sparclet
12649
12650@value{GDBN} enables developers to debug tasks running on
12651Sparclet targets from a Unix host.
12652@value{GDBN} uses code that runs on
12653both the Unix host and on the Sparclet target. The program
12654@code{@value{GDBP}} is installed and executed on the Unix host.
104c1213 12655
8e04817f
AC
12656@table @code
12657@item remotetimeout @var{args}
12658@kindex remotetimeout
12659@value{GDBN} supports the option @code{remotetimeout}.
12660This option is set by the user, and @var{args} represents the number of
12661seconds @value{GDBN} waits for responses.
104c1213
JM
12662@end table
12663
8e04817f
AC
12664@cindex compiling, on Sparclet
12665When compiling for debugging, include the options @samp{-g} to get debug
12666information and @samp{-Ttext} to relocate the program to where you wish to
12667load it on the target. You may also want to add the options @samp{-n} or
12668@samp{-N} in order to reduce the size of the sections. Example:
104c1213 12669
474c8240 12670@smallexample
8e04817f 12671sparclet-aout-gcc prog.c -Ttext 0x12010000 -g -o prog -N
474c8240 12672@end smallexample
104c1213 12673
8e04817f 12674You can use @code{objdump} to verify that the addresses are what you intended:
104c1213 12675
474c8240 12676@smallexample
8e04817f 12677sparclet-aout-objdump --headers --syms prog
474c8240 12678@end smallexample
104c1213 12679
8e04817f
AC
12680@cindex running, on Sparclet
12681Once you have set
12682your Unix execution search path to find @value{GDBN}, you are ready to
12683run @value{GDBN}. From your Unix host, run @code{@value{GDBP}}
12684(or @code{sparclet-aout-gdb}, depending on your installation).
104c1213 12685
8e04817f
AC
12686@value{GDBN} comes up showing the prompt:
12687
474c8240 12688@smallexample
8e04817f 12689(gdbslet)
474c8240 12690@end smallexample
104c1213
JM
12691
12692@menu
8e04817f
AC
12693* Sparclet File:: Setting the file to debug
12694* Sparclet Connection:: Connecting to Sparclet
12695* Sparclet Download:: Sparclet download
12696* Sparclet Execution:: Running and debugging
104c1213
JM
12697@end menu
12698
8e04817f
AC
12699@node Sparclet File
12700@subsubsection Setting file to debug
104c1213 12701
8e04817f 12702The @value{GDBN} command @code{file} lets you choose with program to debug.
104c1213 12703
474c8240 12704@smallexample
8e04817f 12705(gdbslet) file prog
474c8240 12706@end smallexample
104c1213 12707
8e04817f
AC
12708@need 1000
12709@value{GDBN} then attempts to read the symbol table of @file{prog}.
12710@value{GDBN} locates
12711the file by searching the directories listed in the command search
12712path.
12713If the file was compiled with debug information (option "-g"), source
12714files will be searched as well.
12715@value{GDBN} locates
12716the source files by searching the directories listed in the directory search
12717path (@pxref{Environment, ,Your program's environment}).
12718If it fails
12719to find a file, it displays a message such as:
104c1213 12720
474c8240 12721@smallexample
8e04817f 12722prog: No such file or directory.
474c8240 12723@end smallexample
104c1213 12724
8e04817f
AC
12725When this happens, add the appropriate directories to the search paths with
12726the @value{GDBN} commands @code{path} and @code{dir}, and execute the
12727@code{target} command again.
104c1213 12728
8e04817f
AC
12729@node Sparclet Connection
12730@subsubsection Connecting to Sparclet
104c1213 12731
8e04817f
AC
12732The @value{GDBN} command @code{target} lets you connect to a Sparclet target.
12733To connect to a target on serial port ``@code{ttya}'', type:
104c1213 12734
474c8240 12735@smallexample
8e04817f
AC
12736(gdbslet) target sparclet /dev/ttya
12737Remote target sparclet connected to /dev/ttya
12738main () at ../prog.c:3
474c8240 12739@end smallexample
104c1213 12740
8e04817f
AC
12741@need 750
12742@value{GDBN} displays messages like these:
104c1213 12743
474c8240 12744@smallexample
8e04817f 12745Connected to ttya.
474c8240 12746@end smallexample
104c1213 12747
8e04817f
AC
12748@node Sparclet Download
12749@subsubsection Sparclet download
104c1213 12750
8e04817f
AC
12751@cindex download to Sparclet
12752Once connected to the Sparclet target,
12753you can use the @value{GDBN}
12754@code{load} command to download the file from the host to the target.
12755The file name and load offset should be given as arguments to the @code{load}
12756command.
12757Since the file format is aout, the program must be loaded to the starting
12758address. You can use @code{objdump} to find out what this value is. The load
12759offset is an offset which is added to the VMA (virtual memory address)
12760of each of the file's sections.
12761For instance, if the program
12762@file{prog} was linked to text address 0x1201000, with data at 0x12010160
12763and bss at 0x12010170, in @value{GDBN}, type:
104c1213 12764
474c8240 12765@smallexample
8e04817f
AC
12766(gdbslet) load prog 0x12010000
12767Loading section .text, size 0xdb0 vma 0x12010000
474c8240 12768@end smallexample
104c1213 12769
8e04817f
AC
12770If the code is loaded at a different address then what the program was linked
12771to, you may need to use the @code{section} and @code{add-symbol-file} commands
12772to tell @value{GDBN} where to map the symbol table.
12773
12774@node Sparclet Execution
12775@subsubsection Running and debugging
12776
12777@cindex running and debugging Sparclet programs
12778You can now begin debugging the task using @value{GDBN}'s execution control
12779commands, @code{b}, @code{step}, @code{run}, etc. See the @value{GDBN}
12780manual for the list of commands.
12781
474c8240 12782@smallexample
8e04817f
AC
12783(gdbslet) b main
12784Breakpoint 1 at 0x12010000: file prog.c, line 3.
12785(gdbslet) run
12786Starting program: prog
12787Breakpoint 1, main (argc=1, argv=0xeffff21c) at prog.c:3
127883 char *symarg = 0;
12789(gdbslet) step
127904 char *execarg = "hello!";
12791(gdbslet)
474c8240 12792@end smallexample
8e04817f
AC
12793
12794@node Sparclite
12795@subsection Fujitsu Sparclite
104c1213
JM
12796
12797@table @code
12798
8e04817f
AC
12799@kindex target sparclite
12800@item target sparclite @var{dev}
12801Fujitsu sparclite boards, used only for the purpose of loading.
12802You must use an additional command to debug the program.
12803For example: target remote @var{dev} using @value{GDBN} standard
12804remote protocol.
104c1213
JM
12805
12806@end table
12807
8e04817f
AC
12808@node ST2000
12809@subsection Tandem ST2000
104c1213 12810
8e04817f
AC
12811@value{GDBN} may be used with a Tandem ST2000 phone switch, running Tandem's
12812STDBUG protocol.
104c1213 12813
8e04817f
AC
12814To connect your ST2000 to the host system, see the manufacturer's
12815manual. Once the ST2000 is physically attached, you can run:
104c1213 12816
474c8240 12817@smallexample
8e04817f 12818target st2000 @var{dev} @var{speed}
474c8240 12819@end smallexample
104c1213 12820
8e04817f
AC
12821@noindent
12822to establish it as your debugging environment. @var{dev} is normally
12823the name of a serial device, such as @file{/dev/ttya}, connected to the
12824ST2000 via a serial line. You can instead specify @var{dev} as a TCP
12825connection (for example, to a serial line attached via a terminal
12826concentrator) using the syntax @code{@var{hostname}:@var{portnumber}}.
104c1213 12827
8e04817f
AC
12828The @code{load} and @code{attach} commands are @emph{not} defined for
12829this target; you must load your program into the ST2000 as you normally
12830would for standalone operation. @value{GDBN} reads debugging information
12831(such as symbols) from a separate, debugging version of the program
12832available on your host computer.
12833@c FIXME!! This is terribly vague; what little content is here is
12834@c basically hearsay.
104c1213 12835
8e04817f
AC
12836@cindex ST2000 auxiliary commands
12837These auxiliary @value{GDBN} commands are available to help you with the ST2000
12838environment:
104c1213 12839
8e04817f
AC
12840@table @code
12841@item st2000 @var{command}
12842@kindex st2000 @var{cmd}
12843@cindex STDBUG commands (ST2000)
12844@cindex commands to STDBUG (ST2000)
12845Send a @var{command} to the STDBUG monitor. See the manufacturer's
12846manual for available commands.
104c1213 12847
8e04817f
AC
12848@item connect
12849@cindex connect (to STDBUG)
12850Connect the controlling terminal to the STDBUG command monitor. When
12851you are done interacting with STDBUG, typing either of two character
12852sequences gets you back to the @value{GDBN} command prompt:
12853@kbd{@key{RET}~.} (Return, followed by tilde and period) or
12854@kbd{@key{RET}~@key{C-d}} (Return, followed by tilde and control-D).
104c1213
JM
12855@end table
12856
8e04817f
AC
12857@node Z8000
12858@subsection Zilog Z8000
104c1213 12859
8e04817f
AC
12860@cindex Z8000
12861@cindex simulator, Z8000
12862@cindex Zilog Z8000 simulator
104c1213 12863
8e04817f
AC
12864When configured for debugging Zilog Z8000 targets, @value{GDBN} includes
12865a Z8000 simulator.
12866
12867For the Z8000 family, @samp{target sim} simulates either the Z8002 (the
12868unsegmented variant of the Z8000 architecture) or the Z8001 (the
12869segmented variant). The simulator recognizes which architecture is
12870appropriate by inspecting the object code.
104c1213 12871
8e04817f
AC
12872@table @code
12873@item target sim @var{args}
12874@kindex sim
12875@kindex target sim@r{, with Z8000}
12876Debug programs on a simulated CPU. If the simulator supports setup
12877options, specify them via @var{args}.
104c1213
JM
12878@end table
12879
8e04817f
AC
12880@noindent
12881After specifying this target, you can debug programs for the simulated
12882CPU in the same style as programs for your host computer; use the
12883@code{file} command to load a new program image, the @code{run} command
12884to run your program, and so on.
12885
12886As well as making available all the usual machine registers
12887(@pxref{Registers, ,Registers}), the Z8000 simulator provides three
12888additional items of information as specially named registers:
104c1213
JM
12889
12890@table @code
12891
8e04817f
AC
12892@item cycles
12893Counts clock-ticks in the simulator.
104c1213 12894
8e04817f
AC
12895@item insts
12896Counts instructions run in the simulator.
104c1213 12897
8e04817f
AC
12898@item time
12899Execution time in 60ths of a second.
104c1213 12900
8e04817f 12901@end table
104c1213 12902
8e04817f
AC
12903You can refer to these values in @value{GDBN} expressions with the usual
12904conventions; for example, @w{@samp{b fputc if $cycles>5000}} sets a
12905conditional breakpoint that suspends only after at least 5000
12906simulated clock ticks.
104c1213 12907
8e04817f
AC
12908@node Architectures
12909@section Architectures
104c1213 12910
8e04817f
AC
12911This section describes characteristics of architectures that affect
12912all uses of @value{GDBN} with the architecture, both native and cross.
104c1213 12913
8e04817f
AC
12914@menu
12915* A29K::
12916* Alpha::
12917* MIPS::
12918@end menu
104c1213 12919
8e04817f
AC
12920@node A29K
12921@subsection A29K
104c1213
JM
12922
12923@table @code
104c1213 12924
8e04817f
AC
12925@kindex set rstack_high_address
12926@cindex AMD 29K register stack
12927@cindex register stack, AMD29K
12928@item set rstack_high_address @var{address}
12929On AMD 29000 family processors, registers are saved in a separate
12930@dfn{register stack}. There is no way for @value{GDBN} to determine the
12931extent of this stack. Normally, @value{GDBN} just assumes that the
12932stack is ``large enough''. This may result in @value{GDBN} referencing
12933memory locations that do not exist. If necessary, you can get around
12934this problem by specifying the ending address of the register stack with
12935the @code{set rstack_high_address} command. The argument should be an
12936address, which you probably want to precede with @samp{0x} to specify in
12937hexadecimal.
104c1213 12938
8e04817f
AC
12939@kindex show rstack_high_address
12940@item show rstack_high_address
12941Display the current limit of the register stack, on AMD 29000 family
12942processors.
104c1213 12943
8e04817f 12944@end table
104c1213 12945
8e04817f
AC
12946@node Alpha
12947@subsection Alpha
104c1213 12948
8e04817f 12949See the following section.
104c1213 12950
8e04817f
AC
12951@node MIPS
12952@subsection MIPS
104c1213 12953
8e04817f
AC
12954@cindex stack on Alpha
12955@cindex stack on MIPS
12956@cindex Alpha stack
12957@cindex MIPS stack
12958Alpha- and MIPS-based computers use an unusual stack frame, which
12959sometimes requires @value{GDBN} to search backward in the object code to
12960find the beginning of a function.
104c1213 12961
8e04817f
AC
12962@cindex response time, MIPS debugging
12963To improve response time (especially for embedded applications, where
12964@value{GDBN} may be restricted to a slow serial line for this search)
12965you may want to limit the size of this search, using one of these
12966commands:
104c1213 12967
8e04817f
AC
12968@table @code
12969@cindex @code{heuristic-fence-post} (Alpha, MIPS)
12970@item set heuristic-fence-post @var{limit}
12971Restrict @value{GDBN} to examining at most @var{limit} bytes in its
12972search for the beginning of a function. A value of @var{0} (the
12973default) means there is no limit. However, except for @var{0}, the
12974larger the limit the more bytes @code{heuristic-fence-post} must search
12975and therefore the longer it takes to run.
104c1213 12976
8e04817f
AC
12977@item show heuristic-fence-post
12978Display the current limit.
12979@end table
104c1213
JM
12980
12981@noindent
8e04817f
AC
12982These commands are available @emph{only} when @value{GDBN} is configured
12983for debugging programs on Alpha or MIPS processors.
104c1213 12984
104c1213 12985
8e04817f
AC
12986@node Controlling GDB
12987@chapter Controlling @value{GDBN}
12988
12989You can alter the way @value{GDBN} interacts with you by using the
12990@code{set} command. For commands controlling how @value{GDBN} displays
12991data, see @ref{Print Settings, ,Print settings}. Other settings are
12992described here.
12993
12994@menu
12995* Prompt:: Prompt
12996* Editing:: Command editing
12997* History:: Command history
12998* Screen Size:: Screen size
12999* Numbers:: Numbers
1e698235 13000* ABI:: Configuring the current ABI
8e04817f
AC
13001* Messages/Warnings:: Optional warnings and messages
13002* Debugging Output:: Optional messages about internal happenings
13003@end menu
13004
13005@node Prompt
13006@section Prompt
104c1213 13007
8e04817f 13008@cindex prompt
104c1213 13009
8e04817f
AC
13010@value{GDBN} indicates its readiness to read a command by printing a string
13011called the @dfn{prompt}. This string is normally @samp{(@value{GDBP})}. You
13012can change the prompt string with the @code{set prompt} command. For
13013instance, when debugging @value{GDBN} with @value{GDBN}, it is useful to change
13014the prompt in one of the @value{GDBN} sessions so that you can always tell
13015which one you are talking to.
104c1213 13016
8e04817f
AC
13017@emph{Note:} @code{set prompt} does not add a space for you after the
13018prompt you set. This allows you to set a prompt which ends in a space
13019or a prompt that does not.
104c1213 13020
8e04817f
AC
13021@table @code
13022@kindex set prompt
13023@item set prompt @var{newprompt}
13024Directs @value{GDBN} to use @var{newprompt} as its prompt string henceforth.
104c1213 13025
8e04817f
AC
13026@kindex show prompt
13027@item show prompt
13028Prints a line of the form: @samp{Gdb's prompt is: @var{your-prompt}}
104c1213
JM
13029@end table
13030
8e04817f
AC
13031@node Editing
13032@section Command editing
13033@cindex readline
13034@cindex command line editing
104c1213 13035
8e04817f
AC
13036@value{GDBN} reads its input commands via the @dfn{readline} interface. This
13037@sc{gnu} library provides consistent behavior for programs which provide a
13038command line interface to the user. Advantages are @sc{gnu} Emacs-style
13039or @dfn{vi}-style inline editing of commands, @code{csh}-like history
13040substitution, and a storage and recall of command history across
13041debugging sessions.
104c1213 13042
8e04817f
AC
13043You may control the behavior of command line editing in @value{GDBN} with the
13044command @code{set}.
104c1213 13045
8e04817f
AC
13046@table @code
13047@kindex set editing
13048@cindex editing
13049@item set editing
13050@itemx set editing on
13051Enable command line editing (enabled by default).
104c1213 13052
8e04817f
AC
13053@item set editing off
13054Disable command line editing.
104c1213 13055
8e04817f
AC
13056@kindex show editing
13057@item show editing
13058Show whether command line editing is enabled.
104c1213
JM
13059@end table
13060
8e04817f
AC
13061@node History
13062@section Command history
13063
13064@value{GDBN} can keep track of the commands you type during your
13065debugging sessions, so that you can be certain of precisely what
13066happened. Use these commands to manage the @value{GDBN} command
13067history facility.
104c1213
JM
13068
13069@table @code
8e04817f
AC
13070@cindex history substitution
13071@cindex history file
13072@kindex set history filename
4644b6e3 13073@cindex @env{GDBHISTFILE}, environment variable
8e04817f
AC
13074@item set history filename @var{fname}
13075Set the name of the @value{GDBN} command history file to @var{fname}.
13076This is the file where @value{GDBN} reads an initial command history
13077list, and where it writes the command history from this session when it
13078exits. You can access this list through history expansion or through
13079the history command editing characters listed below. This file defaults
13080to the value of the environment variable @code{GDBHISTFILE}, or to
13081@file{./.gdb_history} (@file{./_gdb_history} on MS-DOS) if this variable
13082is not set.
104c1213 13083
8e04817f 13084@cindex history save
4644b6e3 13085@kindex set history
8e04817f
AC
13086@item set history save
13087@itemx set history save on
13088Record command history in a file, whose name may be specified with the
13089@code{set history filename} command. By default, this option is disabled.
104c1213 13090
8e04817f
AC
13091@item set history save off
13092Stop recording command history in a file.
104c1213 13093
8e04817f 13094@cindex history size
8e04817f
AC
13095@item set history size @var{size}
13096Set the number of commands which @value{GDBN} keeps in its history list.
13097This defaults to the value of the environment variable
13098@code{HISTSIZE}, or to 256 if this variable is not set.
104c1213
JM
13099@end table
13100
8e04817f
AC
13101@cindex history expansion
13102History expansion assigns special meaning to the character @kbd{!}.
13103@ifset have-readline-appendices
13104@xref{Event Designators}.
13105@end ifset
13106
13107Since @kbd{!} is also the logical not operator in C, history expansion
13108is off by default. If you decide to enable history expansion with the
13109@code{set history expansion on} command, you may sometimes need to
13110follow @kbd{!} (when it is used as logical not, in an expression) with
13111a space or a tab to prevent it from being expanded. The readline
13112history facilities do not attempt substitution on the strings
13113@kbd{!=} and @kbd{!(}, even when history expansion is enabled.
13114
13115The commands to control history expansion are:
104c1213
JM
13116
13117@table @code
8e04817f
AC
13118@item set history expansion on
13119@itemx set history expansion
4644b6e3 13120@cindex history expansion
8e04817f 13121Enable history expansion. History expansion is off by default.
104c1213 13122
8e04817f
AC
13123@item set history expansion off
13124Disable history expansion.
104c1213 13125
8e04817f
AC
13126The readline code comes with more complete documentation of
13127editing and history expansion features. Users unfamiliar with @sc{gnu} Emacs
13128or @code{vi} may wish to read it.
13129@ifset have-readline-appendices
13130@xref{Command Line Editing}.
13131@end ifset
104c1213 13132
8e04817f
AC
13133@c @group
13134@kindex show history
13135@item show history
13136@itemx show history filename
13137@itemx show history save
13138@itemx show history size
13139@itemx show history expansion
13140These commands display the state of the @value{GDBN} history parameters.
13141@code{show history} by itself displays all four states.
13142@c @end group
13143@end table
13144
13145@table @code
13146@kindex shows
13147@item show commands
13148Display the last ten commands in the command history.
104c1213 13149
8e04817f
AC
13150@item show commands @var{n}
13151Print ten commands centered on command number @var{n}.
13152
13153@item show commands +
13154Print ten commands just after the commands last printed.
104c1213
JM
13155@end table
13156
8e04817f
AC
13157@node Screen Size
13158@section Screen size
13159@cindex size of screen
13160@cindex pauses in output
104c1213 13161
8e04817f
AC
13162Certain commands to @value{GDBN} may produce large amounts of
13163information output to the screen. To help you read all of it,
13164@value{GDBN} pauses and asks you for input at the end of each page of
13165output. Type @key{RET} when you want to continue the output, or @kbd{q}
13166to discard the remaining output. Also, the screen width setting
13167determines when to wrap lines of output. Depending on what is being
13168printed, @value{GDBN} tries to break the line at a readable place,
13169rather than simply letting it overflow onto the following line.
13170
13171Normally @value{GDBN} knows the size of the screen from the terminal
13172driver software. For example, on Unix @value{GDBN} uses the termcap data base
13173together with the value of the @code{TERM} environment variable and the
13174@code{stty rows} and @code{stty cols} settings. If this is not correct,
13175you can override it with the @code{set height} and @code{set
13176width} commands:
13177
13178@table @code
13179@kindex set height
13180@kindex set width
13181@kindex show width
13182@kindex show height
13183@item set height @var{lpp}
13184@itemx show height
13185@itemx set width @var{cpl}
13186@itemx show width
13187These @code{set} commands specify a screen height of @var{lpp} lines and
13188a screen width of @var{cpl} characters. The associated @code{show}
13189commands display the current settings.
104c1213 13190
8e04817f
AC
13191If you specify a height of zero lines, @value{GDBN} does not pause during
13192output no matter how long the output is. This is useful if output is to a
13193file or to an editor buffer.
104c1213 13194
8e04817f
AC
13195Likewise, you can specify @samp{set width 0} to prevent @value{GDBN}
13196from wrapping its output.
104c1213
JM
13197@end table
13198
8e04817f
AC
13199@node Numbers
13200@section Numbers
13201@cindex number representation
13202@cindex entering numbers
104c1213 13203
8e04817f
AC
13204You can always enter numbers in octal, decimal, or hexadecimal in
13205@value{GDBN} by the usual conventions: octal numbers begin with
13206@samp{0}, decimal numbers end with @samp{.}, and hexadecimal numbers
13207begin with @samp{0x}. Numbers that begin with none of these are, by
13208default, entered in base 10; likewise, the default display for
13209numbers---when no particular format is specified---is base 10. You can
13210change the default base for both input and output with the @code{set
13211radix} command.
104c1213 13212
8e04817f
AC
13213@table @code
13214@kindex set input-radix
13215@item set input-radix @var{base}
13216Set the default base for numeric input. Supported choices
13217for @var{base} are decimal 8, 10, or 16. @var{base} must itself be
13218specified either unambiguously or using the current default radix; for
13219example, any of
104c1213 13220
8e04817f
AC
13221@smallexample
13222set radix 012
13223set radix 10.
13224set radix 0xa
13225@end smallexample
104c1213 13226
8e04817f
AC
13227@noindent
13228sets the base to decimal. On the other hand, @samp{set radix 10}
13229leaves the radix unchanged no matter what it was.
104c1213 13230
8e04817f
AC
13231@kindex set output-radix
13232@item set output-radix @var{base}
13233Set the default base for numeric display. Supported choices
13234for @var{base} are decimal 8, 10, or 16. @var{base} must itself be
13235specified either unambiguously or using the current default radix.
104c1213 13236
8e04817f
AC
13237@kindex show input-radix
13238@item show input-radix
13239Display the current default base for numeric input.
104c1213 13240
8e04817f
AC
13241@kindex show output-radix
13242@item show output-radix
13243Display the current default base for numeric display.
13244@end table
104c1213 13245
1e698235
DJ
13246@node ABI
13247@section Configuring the current ABI
13248
13249@value{GDBN} can determine the @dfn{ABI} (Application Binary Interface) of your
13250application automatically. However, sometimes you need to override its
13251conclusions. Use these commands to manage @value{GDBN}'s view of the
13252current ABI.
13253
98b45e30
DJ
13254@cindex OS ABI
13255@kindex set osabi
b4e9345d 13256@kindex show osabi
98b45e30
DJ
13257
13258One @value{GDBN} configuration can debug binaries for multiple operating
b383017d 13259system targets, either via remote debugging or native emulation.
98b45e30
DJ
13260@value{GDBN} will autodetect the @dfn{OS ABI} (Operating System ABI) in use,
13261but you can override its conclusion using the @code{set osabi} command.
13262One example where this is useful is in debugging of binaries which use
13263an alternate C library (e.g.@: @sc{uClibc} for @sc{gnu}/Linux) which does
13264not have the same identifying marks that the standard C library for your
13265platform provides.
13266
13267@table @code
13268@item show osabi
13269Show the OS ABI currently in use.
13270
13271@item set osabi
13272With no argument, show the list of registered available OS ABI's.
13273
13274@item set osabi @var{abi}
13275Set the current OS ABI to @var{abi}.
13276@end table
13277
1e698235
DJ
13278@cindex float promotion
13279@kindex set coerce-float-to-double
13280
13281Generally, the way that an argument of type @code{float} is passed to a
13282function depends on whether the function is prototyped. For a prototyped
13283(i.e.@: ANSI/ISO style) function, @code{float} arguments are passed unchanged,
13284according to the architecture's convention for @code{float}. For unprototyped
13285(i.e.@: K&R style) functions, @code{float} arguments are first promoted to type
13286@code{double} and then passed.
13287
13288Unfortunately, some forms of debug information do not reliably indicate whether
13289a function is prototyped. If @value{GDBN} calls a function that is not marked
13290as prototyped, it consults @kbd{set coerce-float-to-double}.
13291
13292@table @code
13293@item set coerce-float-to-double
13294@itemx set coerce-float-to-double on
13295Arguments of type @code{float} will be promoted to @code{double} when passed
13296to an unprototyped function. This is the default setting.
13297
13298@item set coerce-float-to-double off
13299Arguments of type @code{float} will be passed directly to unprototyped
13300functions.
13301@end table
13302
f1212245
DJ
13303@kindex set cp-abi
13304@kindex show cp-abi
13305@value{GDBN} needs to know the ABI used for your program's C@t{++}
13306objects. The correct C@t{++} ABI depends on which C@t{++} compiler was
13307used to build your application. @value{GDBN} only fully supports
13308programs with a single C@t{++} ABI; if your program contains code using
13309multiple C@t{++} ABI's or if @value{GDBN} can not identify your
13310program's ABI correctly, you can tell @value{GDBN} which ABI to use.
13311Currently supported ABI's include ``gnu-v2'', for @code{g++} versions
13312before 3.0, ``gnu-v3'', for @code{g++} versions 3.0 and later, and
13313``hpaCC'' for the HP ANSI C@t{++} compiler. Other C@t{++} compilers may
13314use the ``gnu-v2'' or ``gnu-v3'' ABI's as well. The default setting is
13315``auto''.
13316
13317@table @code
13318@item show cp-abi
13319Show the C@t{++} ABI currently in use.
13320
13321@item set cp-abi
13322With no argument, show the list of supported C@t{++} ABI's.
13323
13324@item set cp-abi @var{abi}
13325@itemx set cp-abi auto
13326Set the current C@t{++} ABI to @var{abi}, or return to automatic detection.
13327@end table
13328
8e04817f
AC
13329@node Messages/Warnings
13330@section Optional warnings and messages
104c1213 13331
8e04817f
AC
13332By default, @value{GDBN} is silent about its inner workings. If you are
13333running on a slow machine, you may want to use the @code{set verbose}
13334command. This makes @value{GDBN} tell you when it does a lengthy
13335internal operation, so you will not think it has crashed.
104c1213 13336
8e04817f
AC
13337Currently, the messages controlled by @code{set verbose} are those
13338which announce that the symbol table for a source file is being read;
13339see @code{symbol-file} in @ref{Files, ,Commands to specify files}.
104c1213 13340
8e04817f
AC
13341@table @code
13342@kindex set verbose
13343@item set verbose on
13344Enables @value{GDBN} output of certain informational messages.
104c1213 13345
8e04817f
AC
13346@item set verbose off
13347Disables @value{GDBN} output of certain informational messages.
104c1213 13348
8e04817f
AC
13349@kindex show verbose
13350@item show verbose
13351Displays whether @code{set verbose} is on or off.
13352@end table
104c1213 13353
8e04817f
AC
13354By default, if @value{GDBN} encounters bugs in the symbol table of an
13355object file, it is silent; but if you are debugging a compiler, you may
13356find this information useful (@pxref{Symbol Errors, ,Errors reading
13357symbol files}).
104c1213 13358
8e04817f 13359@table @code
104c1213 13360
8e04817f
AC
13361@kindex set complaints
13362@item set complaints @var{limit}
13363Permits @value{GDBN} to output @var{limit} complaints about each type of
13364unusual symbols before becoming silent about the problem. Set
13365@var{limit} to zero to suppress all complaints; set it to a large number
13366to prevent complaints from being suppressed.
104c1213 13367
8e04817f
AC
13368@kindex show complaints
13369@item show complaints
13370Displays how many symbol complaints @value{GDBN} is permitted to produce.
104c1213 13371
8e04817f 13372@end table
104c1213 13373
8e04817f
AC
13374By default, @value{GDBN} is cautious, and asks what sometimes seems to be a
13375lot of stupid questions to confirm certain commands. For example, if
13376you try to run a program which is already running:
104c1213 13377
474c8240 13378@smallexample
8e04817f
AC
13379(@value{GDBP}) run
13380The program being debugged has been started already.
13381Start it from the beginning? (y or n)
474c8240 13382@end smallexample
104c1213 13383
8e04817f
AC
13384If you are willing to unflinchingly face the consequences of your own
13385commands, you can disable this ``feature'':
104c1213 13386
8e04817f 13387@table @code
104c1213 13388
8e04817f
AC
13389@kindex set confirm
13390@cindex flinching
13391@cindex confirmation
13392@cindex stupid questions
13393@item set confirm off
13394Disables confirmation requests.
104c1213 13395
8e04817f
AC
13396@item set confirm on
13397Enables confirmation requests (the default).
104c1213 13398
8e04817f
AC
13399@kindex show confirm
13400@item show confirm
13401Displays state of confirmation requests.
13402
13403@end table
104c1213 13404
8e04817f
AC
13405@node Debugging Output
13406@section Optional messages about internal happenings
4644b6e3
EZ
13407@cindex optional debugging messages
13408
104c1213 13409@table @code
4644b6e3
EZ
13410@kindex set debug
13411@cindex gdbarch debugging info
8e04817f
AC
13412@item set debug arch
13413Turns on or off display of gdbarch debugging info. The default is off
4644b6e3 13414@kindex show debug
8e04817f
AC
13415@item show debug arch
13416Displays the current state of displaying gdbarch debugging info.
8e04817f 13417@item set debug event
4644b6e3 13418@cindex event debugging info
8e04817f
AC
13419Turns on or off display of @value{GDBN} event debugging info. The
13420default is off.
8e04817f
AC
13421@item show debug event
13422Displays the current state of displaying @value{GDBN} event debugging
13423info.
8e04817f 13424@item set debug expression
4644b6e3 13425@cindex expression debugging info
8e04817f
AC
13426Turns on or off display of @value{GDBN} expression debugging info. The
13427default is off.
8e04817f
AC
13428@item show debug expression
13429Displays the current state of displaying @value{GDBN} expression
13430debugging info.
7453dc06 13431@item set debug frame
4644b6e3 13432@cindex frame debugging info
7453dc06
AC
13433Turns on or off display of @value{GDBN} frame debugging info. The
13434default is off.
7453dc06
AC
13435@item show debug frame
13436Displays the current state of displaying @value{GDBN} frame debugging
13437info.
2b4855ab 13438@item set debug observer
4644b6e3 13439@cindex observer debugging info
2b4855ab
AC
13440Turns on or off display of @value{GDBN} observer debugging. This
13441includes info such as the notification of observable events.
2b4855ab
AC
13442@item show debug observer
13443Displays the current state of observer debugging.
8e04817f 13444@item set debug overload
4644b6e3 13445@cindex C@t{++} overload debugging info
8e04817f
AC
13446Turns on or off display of @value{GDBN} C@t{++} overload debugging
13447info. This includes info such as ranking of functions, etc. The default
13448is off.
8e04817f
AC
13449@item show debug overload
13450Displays the current state of displaying @value{GDBN} C@t{++} overload
13451debugging info.
8e04817f
AC
13452@cindex packets, reporting on stdout
13453@cindex serial connections, debugging
13454@item set debug remote
13455Turns on or off display of reports on all packets sent back and forth across
13456the serial line to the remote machine. The info is printed on the
13457@value{GDBN} standard output stream. The default is off.
8e04817f
AC
13458@item show debug remote
13459Displays the state of display of remote packets.
8e04817f
AC
13460@item set debug serial
13461Turns on or off display of @value{GDBN} serial debugging info. The
13462default is off.
8e04817f
AC
13463@item show debug serial
13464Displays the current state of displaying @value{GDBN} serial debugging
13465info.
8e04817f 13466@item set debug target
4644b6e3 13467@cindex target debugging info
8e04817f
AC
13468Turns on or off display of @value{GDBN} target debugging info. This info
13469includes what is going on at the target level of GDB, as it happens. The
701b08bb
DJ
13470default is 0. Set it to 1 to track events, and to 2 to also track the
13471value of large memory transfers. Changes to this flag do not take effect
13472until the next time you connect to a target or use the @code{run} command.
8e04817f
AC
13473@item show debug target
13474Displays the current state of displaying @value{GDBN} target debugging
13475info.
8e04817f 13476@item set debug varobj
4644b6e3 13477@cindex variable object debugging info
8e04817f
AC
13478Turns on or off display of @value{GDBN} variable object debugging
13479info. The default is off.
8e04817f
AC
13480@item show debug varobj
13481Displays the current state of displaying @value{GDBN} variable object
13482debugging info.
13483@end table
104c1213 13484
8e04817f
AC
13485@node Sequences
13486@chapter Canned Sequences of Commands
104c1213 13487
8e04817f
AC
13488Aside from breakpoint commands (@pxref{Break Commands, ,Breakpoint
13489command lists}), @value{GDBN} provides two ways to store sequences of
13490commands for execution as a unit: user-defined commands and command
13491files.
104c1213 13492
8e04817f
AC
13493@menu
13494* Define:: User-defined commands
13495* Hooks:: User-defined command hooks
13496* Command Files:: Command files
13497* Output:: Commands for controlled output
13498@end menu
104c1213 13499
8e04817f
AC
13500@node Define
13501@section User-defined commands
104c1213 13502
8e04817f
AC
13503@cindex user-defined command
13504A @dfn{user-defined command} is a sequence of @value{GDBN} commands to
13505which you assign a new name as a command. This is done with the
13506@code{define} command. User commands may accept up to 10 arguments
13507separated by whitespace. Arguments are accessed within the user command
13508via @var{$arg0@dots{}$arg9}. A trivial example:
104c1213 13509
8e04817f
AC
13510@smallexample
13511define adder
13512 print $arg0 + $arg1 + $arg2
13513@end smallexample
104c1213
JM
13514
13515@noindent
8e04817f 13516To execute the command use:
104c1213 13517
8e04817f
AC
13518@smallexample
13519adder 1 2 3
13520@end smallexample
104c1213 13521
8e04817f
AC
13522@noindent
13523This defines the command @code{adder}, which prints the sum of
13524its three arguments. Note the arguments are text substitutions, so they may
13525reference variables, use complex expressions, or even perform inferior
13526functions calls.
104c1213
JM
13527
13528@table @code
104c1213 13529
8e04817f
AC
13530@kindex define
13531@item define @var{commandname}
13532Define a command named @var{commandname}. If there is already a command
13533by that name, you are asked to confirm that you want to redefine it.
104c1213 13534
8e04817f
AC
13535The definition of the command is made up of other @value{GDBN} command lines,
13536which are given following the @code{define} command. The end of these
13537commands is marked by a line containing @code{end}.
104c1213 13538
8e04817f
AC
13539@kindex if
13540@kindex else
13541@item if
13542Takes a single argument, which is an expression to evaluate.
13543It is followed by a series of commands that are executed
13544only if the expression is true (nonzero).
13545There can then optionally be a line @code{else}, followed
13546by a series of commands that are only executed if the expression
13547was false. The end of the list is marked by a line containing @code{end}.
104c1213 13548
8e04817f
AC
13549@kindex while
13550@item while
13551The syntax is similar to @code{if}: the command takes a single argument,
13552which is an expression to evaluate, and must be followed by the commands to
13553execute, one per line, terminated by an @code{end}.
13554The commands are executed repeatedly as long as the expression
13555evaluates to true.
104c1213 13556
8e04817f
AC
13557@kindex document
13558@item document @var{commandname}
13559Document the user-defined command @var{commandname}, so that it can be
13560accessed by @code{help}. The command @var{commandname} must already be
13561defined. This command reads lines of documentation just as @code{define}
13562reads the lines of the command definition, ending with @code{end}.
13563After the @code{document} command is finished, @code{help} on command
13564@var{commandname} displays the documentation you have written.
104c1213 13565
8e04817f
AC
13566You may use the @code{document} command again to change the
13567documentation of a command. Redefining the command with @code{define}
13568does not change the documentation.
104c1213 13569
8e04817f
AC
13570@kindex help user-defined
13571@item help user-defined
13572List all user-defined commands, with the first line of the documentation
13573(if any) for each.
104c1213 13574
8e04817f
AC
13575@kindex show user
13576@item show user
13577@itemx show user @var{commandname}
13578Display the @value{GDBN} commands used to define @var{commandname} (but
13579not its documentation). If no @var{commandname} is given, display the
13580definitions for all user-defined commands.
104c1213 13581
20f01a46
DH
13582@kindex show max-user-call-depth
13583@kindex set max-user-call-depth
13584@item show max-user-call-depth
5ca0cb28
DH
13585@itemx set max-user-call-depth
13586The value of @code{max-user-call-depth} controls how many recursion
13587levels are allowed in user-defined commands before GDB suspects an
13588infinite recursion and aborts the command.
20f01a46 13589
104c1213
JM
13590@end table
13591
8e04817f
AC
13592When user-defined commands are executed, the
13593commands of the definition are not printed. An error in any command
13594stops execution of the user-defined command.
104c1213 13595
8e04817f
AC
13596If used interactively, commands that would ask for confirmation proceed
13597without asking when used inside a user-defined command. Many @value{GDBN}
13598commands that normally print messages to say what they are doing omit the
13599messages when used in a user-defined command.
104c1213 13600
8e04817f
AC
13601@node Hooks
13602@section User-defined command hooks
13603@cindex command hooks
13604@cindex hooks, for commands
13605@cindex hooks, pre-command
104c1213 13606
8e04817f 13607@kindex hook
8e04817f
AC
13608You may define @dfn{hooks}, which are a special kind of user-defined
13609command. Whenever you run the command @samp{foo}, if the user-defined
13610command @samp{hook-foo} exists, it is executed (with no arguments)
13611before that command.
104c1213 13612
8e04817f
AC
13613@cindex hooks, post-command
13614@kindex hookpost
8e04817f
AC
13615A hook may also be defined which is run after the command you executed.
13616Whenever you run the command @samp{foo}, if the user-defined command
13617@samp{hookpost-foo} exists, it is executed (with no arguments) after
13618that command. Post-execution hooks may exist simultaneously with
13619pre-execution hooks, for the same command.
104c1213 13620
8e04817f
AC
13621It is valid for a hook to call the command which it hooks. If this
13622occurs, the hook is not re-executed, thereby avoiding infinte recursion.
104c1213 13623
8e04817f
AC
13624@c It would be nice if hookpost could be passed a parameter indicating
13625@c if the command it hooks executed properly or not. FIXME!
104c1213 13626
8e04817f
AC
13627@kindex stop@r{, a pseudo-command}
13628In addition, a pseudo-command, @samp{stop} exists. Defining
13629(@samp{hook-stop}) makes the associated commands execute every time
13630execution stops in your program: before breakpoint commands are run,
13631displays are printed, or the stack frame is printed.
104c1213 13632
8e04817f
AC
13633For example, to ignore @code{SIGALRM} signals while
13634single-stepping, but treat them normally during normal execution,
13635you could define:
104c1213 13636
474c8240 13637@smallexample
8e04817f
AC
13638define hook-stop
13639handle SIGALRM nopass
13640end
104c1213 13641
8e04817f
AC
13642define hook-run
13643handle SIGALRM pass
13644end
104c1213 13645
8e04817f
AC
13646define hook-continue
13647handle SIGLARM pass
13648end
474c8240 13649@end smallexample
104c1213 13650
8e04817f 13651As a further example, to hook at the begining and end of the @code{echo}
b383017d 13652command, and to add extra text to the beginning and end of the message,
8e04817f 13653you could define:
104c1213 13654
474c8240 13655@smallexample
8e04817f
AC
13656define hook-echo
13657echo <<<---
13658end
104c1213 13659
8e04817f
AC
13660define hookpost-echo
13661echo --->>>\n
13662end
104c1213 13663
8e04817f
AC
13664(@value{GDBP}) echo Hello World
13665<<<---Hello World--->>>
13666(@value{GDBP})
104c1213 13667
474c8240 13668@end smallexample
104c1213 13669
8e04817f
AC
13670You can define a hook for any single-word command in @value{GDBN}, but
13671not for command aliases; you should define a hook for the basic command
13672name, e.g. @code{backtrace} rather than @code{bt}.
13673@c FIXME! So how does Joe User discover whether a command is an alias
13674@c or not?
13675If an error occurs during the execution of your hook, execution of
13676@value{GDBN} commands stops and @value{GDBN} issues a prompt
13677(before the command that you actually typed had a chance to run).
104c1213 13678
8e04817f
AC
13679If you try to define a hook which does not match any known command, you
13680get a warning from the @code{define} command.
c906108c 13681
8e04817f
AC
13682@node Command Files
13683@section Command files
c906108c 13684
8e04817f
AC
13685@cindex command files
13686A command file for @value{GDBN} is a file of lines that are @value{GDBN}
13687commands. Comments (lines starting with @kbd{#}) may also be included.
13688An empty line in a command file does nothing; it does not mean to repeat
13689the last command, as it would from the terminal.
c906108c 13690
8e04817f
AC
13691@cindex init file
13692@cindex @file{.gdbinit}
13693@cindex @file{gdb.ini}
13694When you start @value{GDBN}, it automatically executes commands from its
13695@dfn{init files}, normally called @file{.gdbinit}@footnote{The DJGPP
13696port of @value{GDBN} uses the name @file{gdb.ini} instead, due to the
13697limitations of file names imposed by DOS filesystems.}.
13698During startup, @value{GDBN} does the following:
c906108c 13699
8e04817f
AC
13700@enumerate
13701@item
13702Reads the init file (if any) in your home directory@footnote{On
13703DOS/Windows systems, the home directory is the one pointed to by the
13704@code{HOME} environment variable.}.
c906108c 13705
8e04817f
AC
13706@item
13707Processes command line options and operands.
c906108c 13708
8e04817f
AC
13709@item
13710Reads the init file (if any) in the current working directory.
c906108c 13711
8e04817f
AC
13712@item
13713Reads command files specified by the @samp{-x} option.
13714@end enumerate
c906108c 13715
8e04817f
AC
13716The init file in your home directory can set options (such as @samp{set
13717complaints}) that affect subsequent processing of command line options
13718and operands. Init files are not executed if you use the @samp{-nx}
13719option (@pxref{Mode Options, ,Choosing modes}).
c906108c 13720
8e04817f
AC
13721@cindex init file name
13722On some configurations of @value{GDBN}, the init file is known by a
13723different name (these are typically environments where a specialized
13724form of @value{GDBN} may need to coexist with other forms, hence a
13725different name for the specialized version's init file). These are the
13726environments with special init file names:
c906108c 13727
8e04817f
AC
13728@cindex @file{.vxgdbinit}
13729@itemize @bullet
13730@item
13731VxWorks (Wind River Systems real-time OS): @file{.vxgdbinit}
c906108c 13732
8e04817f
AC
13733@cindex @file{.os68gdbinit}
13734@item
13735OS68K (Enea Data Systems real-time OS): @file{.os68gdbinit}
c906108c 13736
8e04817f
AC
13737@cindex @file{.esgdbinit}
13738@item
13739ES-1800 (Ericsson Telecom AB M68000 emulator): @file{.esgdbinit}
13740@end itemize
c906108c 13741
8e04817f
AC
13742You can also request the execution of a command file with the
13743@code{source} command:
c906108c 13744
8e04817f
AC
13745@table @code
13746@kindex source
13747@item source @var{filename}
13748Execute the command file @var{filename}.
c906108c
SS
13749@end table
13750
8e04817f 13751The lines in a command file are executed sequentially. They are not
a71ec265
DH
13752printed as they are executed. An error in any command terminates
13753execution of the command file and control is returned to the console.
c906108c 13754
8e04817f
AC
13755Commands that would ask for confirmation if used interactively proceed
13756without asking when used in a command file. Many @value{GDBN} commands that
13757normally print messages to say what they are doing omit the messages
13758when called from command files.
c906108c 13759
8e04817f
AC
13760@value{GDBN} also accepts command input from standard input. In this
13761mode, normal output goes to standard output and error output goes to
13762standard error. Errors in a command file supplied on standard input do
13763not terminate execution of the command file --- execution continues with
13764the next command.
c906108c 13765
474c8240 13766@smallexample
8e04817f 13767gdb < cmds > log 2>&1
474c8240 13768@end smallexample
c906108c 13769
8e04817f
AC
13770(The syntax above will vary depending on the shell used.) This example
13771will execute commands from the file @file{cmds}. All output and errors
13772would be directed to @file{log}.
c906108c 13773
8e04817f
AC
13774@node Output
13775@section Commands for controlled output
c906108c 13776
8e04817f
AC
13777During the execution of a command file or a user-defined command, normal
13778@value{GDBN} output is suppressed; the only output that appears is what is
13779explicitly printed by the commands in the definition. This section
13780describes three commands useful for generating exactly the output you
13781want.
c906108c
SS
13782
13783@table @code
8e04817f
AC
13784@kindex echo
13785@item echo @var{text}
13786@c I do not consider backslash-space a standard C escape sequence
13787@c because it is not in ANSI.
13788Print @var{text}. Nonprinting characters can be included in
13789@var{text} using C escape sequences, such as @samp{\n} to print a
13790newline. @strong{No newline is printed unless you specify one.}
13791In addition to the standard C escape sequences, a backslash followed
13792by a space stands for a space. This is useful for displaying a
13793string with spaces at the beginning or the end, since leading and
13794trailing spaces are otherwise trimmed from all arguments.
13795To print @samp{@w{ }and foo =@w{ }}, use the command
13796@samp{echo \@w{ }and foo = \@w{ }}.
c906108c 13797
8e04817f
AC
13798A backslash at the end of @var{text} can be used, as in C, to continue
13799the command onto subsequent lines. For example,
c906108c 13800
474c8240 13801@smallexample
8e04817f
AC
13802echo This is some text\n\
13803which is continued\n\
13804onto several lines.\n
474c8240 13805@end smallexample
c906108c 13806
8e04817f 13807produces the same output as
c906108c 13808
474c8240 13809@smallexample
8e04817f
AC
13810echo This is some text\n
13811echo which is continued\n
13812echo onto several lines.\n
474c8240 13813@end smallexample
c906108c 13814
8e04817f
AC
13815@kindex output
13816@item output @var{expression}
13817Print the value of @var{expression} and nothing but that value: no
13818newlines, no @samp{$@var{nn} = }. The value is not entered in the
13819value history either. @xref{Expressions, ,Expressions}, for more information
13820on expressions.
c906108c 13821
8e04817f
AC
13822@item output/@var{fmt} @var{expression}
13823Print the value of @var{expression} in format @var{fmt}. You can use
13824the same formats as for @code{print}. @xref{Output Formats,,Output
13825formats}, for more information.
c906108c 13826
8e04817f
AC
13827@kindex printf
13828@item printf @var{string}, @var{expressions}@dots{}
13829Print the values of the @var{expressions} under the control of
13830@var{string}. The @var{expressions} are separated by commas and may be
13831either numbers or pointers. Their values are printed as specified by
13832@var{string}, exactly as if your program were to execute the C
13833subroutine
13834@c FIXME: the above implies that at least all ANSI C formats are
13835@c supported, but it isn't true: %E and %G don't work (or so it seems).
13836@c Either this is a bug, or the manual should document what formats are
13837@c supported.
c906108c 13838
474c8240 13839@smallexample
8e04817f 13840printf (@var{string}, @var{expressions}@dots{});
474c8240 13841@end smallexample
c906108c 13842
8e04817f 13843For example, you can print two values in hex like this:
c906108c 13844
8e04817f
AC
13845@smallexample
13846printf "foo, bar-foo = 0x%x, 0x%x\n", foo, bar-foo
13847@end smallexample
c906108c 13848
8e04817f
AC
13849The only backslash-escape sequences that you can use in the format
13850string are the simple ones that consist of backslash followed by a
13851letter.
c906108c
SS
13852@end table
13853
21c294e6
AC
13854@node Interpreters
13855@chapter Command Interpreters
13856@cindex command interpreters
13857
13858@value{GDBN} supports multiple command interpreters, and some command
13859infrastructure to allow users or user interface writers to switch
13860between interpreters or run commands in other interpreters.
13861
13862@value{GDBN} currently supports two command interpreters, the console
13863interpreter (sometimes called the command-line interpreter or @sc{cli})
13864and the machine interface interpreter (or @sc{gdb/mi}). This manual
13865describes both of these interfaces in great detail.
13866
13867By default, @value{GDBN} will start with the console interpreter.
13868However, the user may choose to start @value{GDBN} with another
13869interpreter by specifying the @option{-i} or @option{--interpreter}
13870startup options. Defined interpreters include:
13871
13872@table @code
13873@item console
13874@cindex console interpreter
13875The traditional console or command-line interpreter. This is the most often
13876used interpreter with @value{GDBN}. With no interpreter specified at runtime,
13877@value{GDBN} will use this interpreter.
13878
13879@item mi
13880@cindex mi interpreter
13881The newest @sc{gdb/mi} interface (currently @code{mi2}). Used primarily
13882by programs wishing to use @value{GDBN} as a backend for a debugger GUI
13883or an IDE. For more information, see @ref{GDB/MI, ,The @sc{gdb/mi}
13884Interface}.
13885
13886@item mi2
13887@cindex mi2 interpreter
13888The current @sc{gdb/mi} interface.
13889
13890@item mi1
13891@cindex mi1 interpreter
13892The @sc{gdb/mi} interface included in @value{GDBN} 5.1, 5.2, and 5.3.
13893
13894@end table
13895
13896@cindex invoke another interpreter
13897The interpreter being used by @value{GDBN} may not be dynamically
13898switched at runtime. Although possible, this could lead to a very
13899precarious situation. Consider an IDE using @sc{gdb/mi}. If a user
13900enters the command "interpreter-set console" in a console view,
13901@value{GDBN} would switch to using the console interpreter, rendering
13902the IDE inoperable!
13903
13904@kindex interpreter-exec
13905Although you may only choose a single interpreter at startup, you may execute
13906commands in any interpreter from the current interpreter using the appropriate
13907command. If you are running the console interpreter, simply use the
13908@code{interpreter-exec} command:
13909
13910@smallexample
13911interpreter-exec mi "-data-list-register-names"
13912@end smallexample
13913
13914@sc{gdb/mi} has a similar command, although it is only available in versions of
13915@value{GDBN} which support @sc{gdb/mi} version 2 (or greater).
13916
8e04817f
AC
13917@node TUI
13918@chapter @value{GDBN} Text User Interface
13919@cindex TUI
d0d5df6f 13920@cindex Text User Interface
c906108c 13921
8e04817f
AC
13922@menu
13923* TUI Overview:: TUI overview
13924* TUI Keys:: TUI key bindings
7cf36c78 13925* TUI Single Key Mode:: TUI single key mode
8e04817f
AC
13926* TUI Commands:: TUI specific commands
13927* TUI Configuration:: TUI configuration variables
13928@end menu
c906108c 13929
d0d5df6f
AC
13930The @value{GDBN} Text User Interface, TUI in short, is a terminal
13931interface which uses the @code{curses} library to show the source
13932file, the assembly output, the program registers and @value{GDBN}
13933commands in separate text windows.
13934
13935The TUI is enabled by invoking @value{GDBN} using either
13936@pindex gdbtui
13937@samp{gdbtui} or @samp{gdb -tui}.
c906108c 13938
8e04817f
AC
13939@node TUI Overview
13940@section TUI overview
c906108c 13941
8e04817f
AC
13942The TUI has two display modes that can be switched while
13943@value{GDBN} runs:
c906108c 13944
8e04817f
AC
13945@itemize @bullet
13946@item
13947A curses (or TUI) mode in which it displays several text
13948windows on the terminal.
c906108c 13949
8e04817f
AC
13950@item
13951A standard mode which corresponds to the @value{GDBN} configured without
13952the TUI.
13953@end itemize
c906108c 13954
8e04817f
AC
13955In the TUI mode, @value{GDBN} can display several text window
13956on the terminal:
c906108c 13957
8e04817f
AC
13958@table @emph
13959@item command
13960This window is the @value{GDBN} command window with the @value{GDBN}
13961prompt and the @value{GDBN} outputs. The @value{GDBN} input is still
13962managed using readline but through the TUI. The @emph{command}
13963window is always visible.
c906108c 13964
8e04817f
AC
13965@item source
13966The source window shows the source file of the program. The current
13967line as well as active breakpoints are displayed in this window.
c906108c 13968
8e04817f
AC
13969@item assembly
13970The assembly window shows the disassembly output of the program.
c906108c 13971
8e04817f
AC
13972@item register
13973This window shows the processor registers. It detects when
13974a register is changed and when this is the case, registers that have
6a1b180d 13975changed are highlighted.
c906108c 13976
c906108c
SS
13977@end table
13978
269c21fe
SC
13979The source and assembly windows show the current program position
13980by highlighting the current line and marking them with the @samp{>} marker.
13981Breakpoints are also indicated with two markers. A first one
13982indicates the breakpoint type:
13983
13984@table @code
13985@item B
13986Breakpoint which was hit at least once.
13987
13988@item b
13989Breakpoint which was never hit.
13990
13991@item H
13992Hardware breakpoint which was hit at least once.
13993
13994@item h
13995Hardware breakpoint which was never hit.
13996
13997@end table
13998
13999The second marker indicates whether the breakpoint is enabled or not:
14000
14001@table @code
14002@item +
14003Breakpoint is enabled.
14004
14005@item -
14006Breakpoint is disabled.
14007
14008@end table
14009
8e04817f
AC
14010The source, assembly and register windows are attached to the thread
14011and the frame position. They are updated when the current thread
14012changes, when the frame changes or when the program counter changes.
14013These three windows are arranged by the TUI according to several
14014layouts. The layout defines which of these three windows are visible.
14015The following layouts are available:
c906108c 14016
8e04817f
AC
14017@itemize @bullet
14018@item
14019source
2df3850c 14020
8e04817f
AC
14021@item
14022assembly
14023
14024@item
14025source and assembly
14026
14027@item
14028source and registers
c906108c 14029
8e04817f
AC
14030@item
14031assembly and registers
2df3850c 14032
8e04817f 14033@end itemize
c906108c 14034
b7bb15bc
SC
14035On top of the command window a status line gives various information
14036concerning the current process begin debugged. The status line is
14037updated when the information it shows changes. The following fields
14038are displayed:
14039
14040@table @emph
14041@item target
14042Indicates the current gdb target
14043(@pxref{Targets, ,Specifying a Debugging Target}).
14044
14045@item process
14046Gives information about the current process or thread number.
14047When no process is being debugged, this field is set to @code{No process}.
14048
14049@item function
14050Gives the current function name for the selected frame.
14051The name is demangled if demangling is turned on (@pxref{Print Settings}).
14052When there is no symbol corresponding to the current program counter
14053the string @code{??} is displayed.
14054
14055@item line
14056Indicates the current line number for the selected frame.
14057When the current line number is not known the string @code{??} is displayed.
14058
14059@item pc
14060Indicates the current program counter address.
14061
14062@end table
14063
8e04817f
AC
14064@node TUI Keys
14065@section TUI Key Bindings
14066@cindex TUI key bindings
c906108c 14067
8e04817f
AC
14068The TUI installs several key bindings in the readline keymaps
14069(@pxref{Command Line Editing}).
14070They allow to leave or enter in the TUI mode or they operate
7cf36c78
SC
14071directly on the TUI layout and windows. The TUI also provides
14072a @emph{SingleKey} keymap which binds several keys directly to
14073@value{GDBN} commands. The following key bindings
8e04817f 14074are installed for both TUI mode and the @value{GDBN} standard mode.
c906108c 14075
8e04817f
AC
14076@table @kbd
14077@kindex C-x C-a
14078@item C-x C-a
14079@kindex C-x a
14080@itemx C-x a
14081@kindex C-x A
14082@itemx C-x A
14083Enter or leave the TUI mode. When the TUI mode is left,
14084the curses window management is left and @value{GDBN} operates using
14085its standard mode writing on the terminal directly. When the TUI
14086mode is entered, the control is given back to the curses windows.
14087The screen is then refreshed.
c906108c 14088
8e04817f
AC
14089@kindex C-x 1
14090@item C-x 1
14091Use a TUI layout with only one window. The layout will
14092either be @samp{source} or @samp{assembly}. When the TUI mode
14093is not active, it will switch to the TUI mode.
2df3850c 14094
8e04817f 14095Think of this key binding as the Emacs @kbd{C-x 1} binding.
c906108c 14096
8e04817f
AC
14097@kindex C-x 2
14098@item C-x 2
14099Use a TUI layout with at least two windows. When the current
14100layout shows already two windows, a next layout with two windows is used.
14101When a new layout is chosen, one window will always be common to the
14102previous layout and the new one.
c906108c 14103
8e04817f 14104Think of it as the Emacs @kbd{C-x 2} binding.
2df3850c 14105
72ffddc9
SC
14106@kindex C-x o
14107@item C-x o
14108Change the active window. The TUI associates several key bindings
14109(like scrolling and arrow keys) to the active window. This command
14110gives the focus to the next TUI window.
14111
14112Think of it as the Emacs @kbd{C-x o} binding.
14113
7cf36c78
SC
14114@kindex C-x s
14115@item C-x s
14116Use the TUI @emph{SingleKey} keymap that binds single key to gdb commands
14117(@pxref{TUI Single Key Mode}).
14118
c906108c
SS
14119@end table
14120
8e04817f 14121The following key bindings are handled only by the TUI mode:
5d161b24 14122
8e04817f
AC
14123@table @key
14124@kindex PgUp
14125@item PgUp
14126Scroll the active window one page up.
c906108c 14127
8e04817f
AC
14128@kindex PgDn
14129@item PgDn
14130Scroll the active window one page down.
c906108c 14131
8e04817f
AC
14132@kindex Up
14133@item Up
14134Scroll the active window one line up.
c906108c 14135
8e04817f
AC
14136@kindex Down
14137@item Down
14138Scroll the active window one line down.
c906108c 14139
8e04817f
AC
14140@kindex Left
14141@item Left
14142Scroll the active window one column left.
c906108c 14143
8e04817f
AC
14144@kindex Right
14145@item Right
14146Scroll the active window one column right.
c906108c 14147
8e04817f
AC
14148@kindex C-L
14149@item C-L
14150Refresh the screen.
c906108c 14151
8e04817f 14152@end table
c906108c 14153
8e04817f 14154In the TUI mode, the arrow keys are used by the active window
72ffddc9
SC
14155for scrolling. This means they are available for readline when the
14156active window is the command window. When the command window
14157does not have the focus, it is necessary to use other readline
14158key bindings such as @key{C-p}, @key{C-n}, @key{C-b} and @key{C-f}.
8e04817f 14159
7cf36c78
SC
14160@node TUI Single Key Mode
14161@section TUI Single Key Mode
14162@cindex TUI single key mode
14163
14164The TUI provides a @emph{SingleKey} mode in which it installs a particular
14165key binding in the readline keymaps to connect single keys to
b383017d 14166some gdb commands.
7cf36c78
SC
14167
14168@table @kbd
14169@kindex c @r{(SingleKey TUI key)}
14170@item c
14171continue
14172
14173@kindex d @r{(SingleKey TUI key)}
14174@item d
14175down
14176
14177@kindex f @r{(SingleKey TUI key)}
14178@item f
14179finish
14180
14181@kindex n @r{(SingleKey TUI key)}
14182@item n
14183next
14184
14185@kindex q @r{(SingleKey TUI key)}
14186@item q
14187exit the @emph{SingleKey} mode.
14188
14189@kindex r @r{(SingleKey TUI key)}
14190@item r
14191run
14192
14193@kindex s @r{(SingleKey TUI key)}
14194@item s
14195step
14196
14197@kindex u @r{(SingleKey TUI key)}
14198@item u
14199up
14200
14201@kindex v @r{(SingleKey TUI key)}
14202@item v
14203info locals
14204
14205@kindex w @r{(SingleKey TUI key)}
14206@item w
14207where
14208
14209@end table
14210
14211Other keys temporarily switch to the @value{GDBN} command prompt.
14212The key that was pressed is inserted in the editing buffer so that
14213it is possible to type most @value{GDBN} commands without interaction
14214with the TUI @emph{SingleKey} mode. Once the command is entered the TUI
14215@emph{SingleKey} mode is restored. The only way to permanently leave
14216this mode is by hitting @key{q} or @samp{@key{C-x} @key{s}}.
14217
14218
8e04817f
AC
14219@node TUI Commands
14220@section TUI specific commands
14221@cindex TUI commands
14222
14223The TUI has specific commands to control the text windows.
14224These commands are always available, that is they do not depend on
14225the current terminal mode in which @value{GDBN} runs. When @value{GDBN}
14226is in the standard mode, using these commands will automatically switch
14227in the TUI mode.
c906108c
SS
14228
14229@table @code
3d757584
SC
14230@item info win
14231@kindex info win
14232List and give the size of all displayed windows.
14233
8e04817f 14234@item layout next
4644b6e3 14235@kindex layout
8e04817f 14236Display the next layout.
2df3850c 14237
8e04817f 14238@item layout prev
8e04817f 14239Display the previous layout.
c906108c 14240
8e04817f 14241@item layout src
8e04817f 14242Display the source window only.
c906108c 14243
8e04817f 14244@item layout asm
8e04817f 14245Display the assembly window only.
c906108c 14246
8e04817f 14247@item layout split
8e04817f 14248Display the source and assembly window.
c906108c 14249
8e04817f 14250@item layout regs
8e04817f
AC
14251Display the register window together with the source or assembly window.
14252
14253@item focus next | prev | src | asm | regs | split
14254@kindex focus
14255Set the focus to the named window.
14256This command allows to change the active window so that scrolling keys
14257can be affected to another window.
c906108c 14258
8e04817f
AC
14259@item refresh
14260@kindex refresh
14261Refresh the screen. This is similar to using @key{C-L} key.
c906108c 14262
6a1b180d
SC
14263@item tui reg float
14264@kindex tui reg
14265Show the floating point registers in the register window.
14266
14267@item tui reg general
14268Show the general registers in the register window.
14269
14270@item tui reg next
14271Show the next register group. The list of register groups as well as
14272their order is target specific. The predefined register groups are the
14273following: @code{general}, @code{float}, @code{system}, @code{vector},
14274@code{all}, @code{save}, @code{restore}.
14275
14276@item tui reg system
14277Show the system registers in the register window.
14278
8e04817f
AC
14279@item update
14280@kindex update
14281Update the source window and the current execution point.
c906108c 14282
8e04817f
AC
14283@item winheight @var{name} +@var{count}
14284@itemx winheight @var{name} -@var{count}
14285@kindex winheight
14286Change the height of the window @var{name} by @var{count}
14287lines. Positive counts increase the height, while negative counts
14288decrease it.
2df3850c 14289
c906108c
SS
14290@end table
14291
8e04817f
AC
14292@node TUI Configuration
14293@section TUI configuration variables
14294@cindex TUI configuration variables
c906108c 14295
8e04817f
AC
14296The TUI has several configuration variables that control the
14297appearance of windows on the terminal.
c906108c 14298
8e04817f
AC
14299@table @code
14300@item set tui border-kind @var{kind}
14301@kindex set tui border-kind
14302Select the border appearance for the source, assembly and register windows.
14303The possible values are the following:
14304@table @code
14305@item space
14306Use a space character to draw the border.
c906108c 14307
8e04817f
AC
14308@item ascii
14309Use ascii characters + - and | to draw the border.
c906108c 14310
8e04817f
AC
14311@item acs
14312Use the Alternate Character Set to draw the border. The border is
14313drawn using character line graphics if the terminal supports them.
c78b4128 14314
8e04817f 14315@end table
c78b4128 14316
8e04817f
AC
14317@item set tui active-border-mode @var{mode}
14318@kindex set tui active-border-mode
14319Select the attributes to display the border of the active window.
14320The possible values are @code{normal}, @code{standout}, @code{reverse},
14321@code{half}, @code{half-standout}, @code{bold} and @code{bold-standout}.
c78b4128 14322
8e04817f
AC
14323@item set tui border-mode @var{mode}
14324@kindex set tui border-mode
14325Select the attributes to display the border of other windows.
14326The @var{mode} can be one of the following:
14327@table @code
14328@item normal
14329Use normal attributes to display the border.
c906108c 14330
8e04817f
AC
14331@item standout
14332Use standout mode.
c906108c 14333
8e04817f
AC
14334@item reverse
14335Use reverse video mode.
c906108c 14336
8e04817f
AC
14337@item half
14338Use half bright mode.
c906108c 14339
8e04817f
AC
14340@item half-standout
14341Use half bright and standout mode.
c906108c 14342
8e04817f
AC
14343@item bold
14344Use extra bright or bold mode.
c78b4128 14345
8e04817f
AC
14346@item bold-standout
14347Use extra bright or bold and standout mode.
c78b4128 14348
8e04817f 14349@end table
c78b4128 14350
8e04817f 14351@end table
c78b4128 14352
8e04817f
AC
14353@node Emacs
14354@chapter Using @value{GDBN} under @sc{gnu} Emacs
c78b4128 14355
8e04817f
AC
14356@cindex Emacs
14357@cindex @sc{gnu} Emacs
14358A special interface allows you to use @sc{gnu} Emacs to view (and
14359edit) the source files for the program you are debugging with
14360@value{GDBN}.
c906108c 14361
8e04817f
AC
14362To use this interface, use the command @kbd{M-x gdb} in Emacs. Give the
14363executable file you want to debug as an argument. This command starts
14364@value{GDBN} as a subprocess of Emacs, with input and output through a newly
14365created Emacs buffer.
14366@c (Do not use the @code{-tui} option to run @value{GDBN} from Emacs.)
c906108c 14367
8e04817f
AC
14368Using @value{GDBN} under Emacs is just like using @value{GDBN} normally except for two
14369things:
c906108c 14370
8e04817f
AC
14371@itemize @bullet
14372@item
14373All ``terminal'' input and output goes through the Emacs buffer.
14374@end itemize
c906108c 14375
8e04817f
AC
14376This applies both to @value{GDBN} commands and their output, and to the input
14377and output done by the program you are debugging.
bf0184be 14378
8e04817f
AC
14379This is useful because it means that you can copy the text of previous
14380commands and input them again; you can even use parts of the output
14381in this way.
bf0184be 14382
8e04817f
AC
14383All the facilities of Emacs' Shell mode are available for interacting
14384with your program. In particular, you can send signals the usual
14385way---for example, @kbd{C-c C-c} for an interrupt, @kbd{C-c C-z} for a
14386stop.
bf0184be 14387
8e04817f 14388@itemize @bullet
bf0184be 14389@item
8e04817f
AC
14390@value{GDBN} displays source code through Emacs.
14391@end itemize
bf0184be 14392
8e04817f
AC
14393Each time @value{GDBN} displays a stack frame, Emacs automatically finds the
14394source file for that frame and puts an arrow (@samp{=>}) at the
14395left margin of the current line. Emacs uses a separate buffer for
14396source display, and splits the screen to show both your @value{GDBN} session
14397and the source.
bf0184be 14398
8e04817f
AC
14399Explicit @value{GDBN} @code{list} or search commands still produce output as
14400usual, but you probably have no reason to use them from Emacs.
c906108c 14401
64fabec2
AC
14402If you specify an absolute file name when prompted for the @kbd{M-x
14403gdb} argument, then Emacs sets your current working directory to where
14404your program resides. If you only specify the file name, then Emacs
14405sets your current working directory to to the directory associated
14406with the previous buffer. In this case, @value{GDBN} may find your
14407program by searching your environment's @code{PATH} variable, but on
14408some operating systems it might not find the source. So, although the
14409@value{GDBN} input and output session proceeds normally, the auxiliary
14410buffer does not display the current source and line of execution.
14411
14412The initial working directory of @value{GDBN} is printed on the top
14413line of the @value{GDBN} I/O buffer and this serves as a default for
14414the commands that specify files for @value{GDBN} to operate
14415on. @xref{Files, ,Commands to specify files}.
14416
14417By default, @kbd{M-x gdb} calls the program called @file{gdb}. If you
14418need to call @value{GDBN} by a different name (for example, if you
14419keep several configurations around, with different names) you can
14420customize the Emacs variable @code{gud-gdb-command-name} to run the
14421one you want.
8e04817f
AC
14422
14423In the @value{GDBN} I/O buffer, you can use these special Emacs commands in
14424addition to the standard Shell mode commands:
c906108c 14425
8e04817f
AC
14426@table @kbd
14427@item C-h m
14428Describe the features of Emacs' @value{GDBN} Mode.
c906108c 14429
64fabec2 14430@item C-c C-s
8e04817f
AC
14431Execute to another source line, like the @value{GDBN} @code{step} command; also
14432update the display window to show the current file and location.
c906108c 14433
64fabec2 14434@item C-c C-n
8e04817f
AC
14435Execute to next source line in this function, skipping all function
14436calls, like the @value{GDBN} @code{next} command. Then update the display window
14437to show the current file and location.
c906108c 14438
64fabec2 14439@item C-c C-i
8e04817f
AC
14440Execute one instruction, like the @value{GDBN} @code{stepi} command; update
14441display window accordingly.
c906108c 14442
8e04817f
AC
14443@item C-c C-f
14444Execute until exit from the selected stack frame, like the @value{GDBN}
14445@code{finish} command.
c906108c 14446
64fabec2 14447@item C-c C-r
8e04817f
AC
14448Continue execution of your program, like the @value{GDBN} @code{continue}
14449command.
b433d00b 14450
64fabec2 14451@item C-c <
8e04817f
AC
14452Go up the number of frames indicated by the numeric argument
14453(@pxref{Arguments, , Numeric Arguments, Emacs, The @sc{gnu} Emacs Manual}),
14454like the @value{GDBN} @code{up} command.
b433d00b 14455
64fabec2 14456@item C-c >
8e04817f
AC
14457Go down the number of frames indicated by the numeric argument, like the
14458@value{GDBN} @code{down} command.
8e04817f 14459@end table
c906108c 14460
64fabec2 14461In any source file, the Emacs command @kbd{C-x SPC} (@code{gud-break})
8e04817f 14462tells @value{GDBN} to set a breakpoint on the source line point is on.
c906108c 14463
64fabec2
AC
14464If you type @kbd{M-x speedbar}, then Emacs displays a separate frame which
14465shows a backtrace when the @value{GDBN} I/O buffer is current. Move
14466point to any frame in the stack and type @key{RET} to make it become the
14467current frame and display the associated source in the source buffer.
14468Alternatively, click @kbd{Mouse-2} to make the selected frame become the
14469current one.
14470
8e04817f
AC
14471If you accidentally delete the source-display buffer, an easy way to get
14472it back is to type the command @code{f} in the @value{GDBN} buffer, to
14473request a frame display; when you run under Emacs, this recreates
14474the source buffer if necessary to show you the context of the current
14475frame.
c906108c 14476
8e04817f
AC
14477The source files displayed in Emacs are in ordinary Emacs buffers
14478which are visiting the source files in the usual way. You can edit
14479the files with these buffers if you wish; but keep in mind that @value{GDBN}
14480communicates with Emacs in terms of line numbers. If you add or
14481delete lines from the text, the line numbers that @value{GDBN} knows cease
14482to correspond properly with the code.
b383017d 14483
64fabec2
AC
14484The description given here is for GNU Emacs version 21.3 and a more
14485detailed description of its interaction with @value{GDBN} is given in
14486the Emacs manual (@pxref{Debuggers,,, Emacs, The @sc{gnu} Emacs Manual}).
c906108c 14487
8e04817f
AC
14488@c The following dropped because Epoch is nonstandard. Reactivate
14489@c if/when v19 does something similar. ---doc@cygnus.com 19dec1990
14490@ignore
14491@kindex Emacs Epoch environment
14492@kindex Epoch
14493@kindex inspect
c906108c 14494
8e04817f
AC
14495Version 18 of @sc{gnu} Emacs has a built-in window system
14496called the @code{epoch}
14497environment. Users of this environment can use a new command,
14498@code{inspect} which performs identically to @code{print} except that
14499each value is printed in its own window.
14500@end ignore
c906108c 14501
922fbb7b
AC
14502
14503@node GDB/MI
14504@chapter The @sc{gdb/mi} Interface
14505
14506@unnumberedsec Function and Purpose
14507
14508@cindex @sc{gdb/mi}, its purpose
14509@sc{gdb/mi} is a line based machine oriented text interface to @value{GDBN}. It is
14510specifically intended to support the development of systems which use
14511the debugger as just one small component of a larger system.
14512
14513This chapter is a specification of the @sc{gdb/mi} interface. It is written
14514in the form of a reference manual.
14515
14516Note that @sc{gdb/mi} is still under construction, so some of the
14517features described below are incomplete and subject to change.
14518
14519@unnumberedsec Notation and Terminology
14520
14521@cindex notational conventions, for @sc{gdb/mi}
14522This chapter uses the following notation:
14523
14524@itemize @bullet
14525@item
14526@code{|} separates two alternatives.
14527
14528@item
14529@code{[ @var{something} ]} indicates that @var{something} is optional:
14530it may or may not be given.
14531
14532@item
14533@code{( @var{group} )*} means that @var{group} inside the parentheses
14534may repeat zero or more times.
14535
14536@item
14537@code{( @var{group} )+} means that @var{group} inside the parentheses
14538may repeat one or more times.
14539
14540@item
14541@code{"@var{string}"} means a literal @var{string}.
14542@end itemize
14543
14544@ignore
14545@heading Dependencies
14546@end ignore
14547
14548@heading Acknowledgments
14549
14550In alphabetic order: Andrew Cagney, Fernando Nasser, Stan Shebs and
14551Elena Zannoni.
14552
14553@menu
14554* GDB/MI Command Syntax::
14555* GDB/MI Compatibility with CLI::
14556* GDB/MI Output Records::
14557* GDB/MI Command Description Format::
14558* GDB/MI Breakpoint Table Commands::
14559* GDB/MI Data Manipulation::
14560* GDB/MI Program Control::
14561* GDB/MI Miscellaneous Commands::
14562@ignore
14563* GDB/MI Kod Commands::
14564* GDB/MI Memory Overlay Commands::
14565* GDB/MI Signal Handling Commands::
14566@end ignore
14567* GDB/MI Stack Manipulation::
14568* GDB/MI Symbol Query::
14569* GDB/MI Target Manipulation::
14570* GDB/MI Thread Commands::
14571* GDB/MI Tracepoint Commands::
14572* GDB/MI Variable Objects::
14573@end menu
14574
14575@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
14576@node GDB/MI Command Syntax
14577@section @sc{gdb/mi} Command Syntax
14578
14579@menu
14580* GDB/MI Input Syntax::
14581* GDB/MI Output Syntax::
14582* GDB/MI Simple Examples::
14583@end menu
14584
14585@node GDB/MI Input Syntax
14586@subsection @sc{gdb/mi} Input Syntax
14587
14588@cindex input syntax for @sc{gdb/mi}
14589@cindex @sc{gdb/mi}, input syntax
14590@table @code
14591@item @var{command} @expansion{}
14592@code{@var{cli-command} | @var{mi-command}}
14593
14594@item @var{cli-command} @expansion{}
14595@code{[ @var{token} ] @var{cli-command} @var{nl}}, where
14596@var{cli-command} is any existing @value{GDBN} CLI command.
14597
14598@item @var{mi-command} @expansion{}
14599@code{[ @var{token} ] "-" @var{operation} ( " " @var{option} )*
14600@code{[} " --" @code{]} ( " " @var{parameter} )* @var{nl}}
14601
14602@item @var{token} @expansion{}
14603"any sequence of digits"
14604
14605@item @var{option} @expansion{}
14606@code{"-" @var{parameter} [ " " @var{parameter} ]}
14607
14608@item @var{parameter} @expansion{}
14609@code{@var{non-blank-sequence} | @var{c-string}}
14610
14611@item @var{operation} @expansion{}
14612@emph{any of the operations described in this chapter}
14613
14614@item @var{non-blank-sequence} @expansion{}
14615@emph{anything, provided it doesn't contain special characters such as
14616"-", @var{nl}, """ and of course " "}
14617
14618@item @var{c-string} @expansion{}
14619@code{""" @var{seven-bit-iso-c-string-content} """}
14620
14621@item @var{nl} @expansion{}
14622@code{CR | CR-LF}
14623@end table
14624
14625@noindent
14626Notes:
14627
14628@itemize @bullet
14629@item
14630The CLI commands are still handled by the @sc{mi} interpreter; their
14631output is described below.
14632
14633@item
14634The @code{@var{token}}, when present, is passed back when the command
14635finishes.
14636
14637@item
14638Some @sc{mi} commands accept optional arguments as part of the parameter
14639list. Each option is identified by a leading @samp{-} (dash) and may be
14640followed by an optional argument parameter. Options occur first in the
14641parameter list and can be delimited from normal parameters using
14642@samp{--} (this is useful when some parameters begin with a dash).
14643@end itemize
14644
14645Pragmatics:
14646
14647@itemize @bullet
14648@item
14649We want easy access to the existing CLI syntax (for debugging).
14650
14651@item
14652We want it to be easy to spot a @sc{mi} operation.
14653@end itemize
14654
14655@node GDB/MI Output Syntax
14656@subsection @sc{gdb/mi} Output Syntax
14657
14658@cindex output syntax of @sc{gdb/mi}
14659@cindex @sc{gdb/mi}, output syntax
14660The output from @sc{gdb/mi} consists of zero or more out-of-band records
14661followed, optionally, by a single result record. This result record
14662is for the most recent command. The sequence of output records is
14663terminated by @samp{(@value{GDBP})}.
14664
14665If an input command was prefixed with a @code{@var{token}} then the
14666corresponding output for that command will also be prefixed by that same
14667@var{token}.
14668
14669@table @code
14670@item @var{output} @expansion{}
14671@code{( @var{out-of-band-record} )* [ @var{result-record} ] "(gdb)" @var{nl}}
14672
14673@item @var{result-record} @expansion{}
14674@code{ [ @var{token} ] "^" @var{result-class} ( "," @var{result} )* @var{nl}}
14675
14676@item @var{out-of-band-record} @expansion{}
14677@code{@var{async-record} | @var{stream-record}}
14678
14679@item @var{async-record} @expansion{}
14680@code{@var{exec-async-output} | @var{status-async-output} | @var{notify-async-output}}
14681
14682@item @var{exec-async-output} @expansion{}
14683@code{[ @var{token} ] "*" @var{async-output}}
14684
14685@item @var{status-async-output} @expansion{}
14686@code{[ @var{token} ] "+" @var{async-output}}
14687
14688@item @var{notify-async-output} @expansion{}
14689@code{[ @var{token} ] "=" @var{async-output}}
14690
14691@item @var{async-output} @expansion{}
14692@code{@var{async-class} ( "," @var{result} )* @var{nl}}
14693
14694@item @var{result-class} @expansion{}
14695@code{"done" | "running" | "connected" | "error" | "exit"}
14696
14697@item @var{async-class} @expansion{}
14698@code{"stopped" | @var{others}} (where @var{others} will be added
14699depending on the needs---this is still in development).
14700
14701@item @var{result} @expansion{}
14702@code{ @var{variable} "=" @var{value}}
14703
14704@item @var{variable} @expansion{}
14705@code{ @var{string} }
14706
14707@item @var{value} @expansion{}
14708@code{ @var{const} | @var{tuple} | @var{list} }
14709
14710@item @var{const} @expansion{}
14711@code{@var{c-string}}
14712
14713@item @var{tuple} @expansion{}
14714@code{ "@{@}" | "@{" @var{result} ( "," @var{result} )* "@}" }
14715
14716@item @var{list} @expansion{}
14717@code{ "[]" | "[" @var{value} ( "," @var{value} )* "]" | "["
14718@var{result} ( "," @var{result} )* "]" }
14719
14720@item @var{stream-record} @expansion{}
14721@code{@var{console-stream-output} | @var{target-stream-output} | @var{log-stream-output}}
14722
14723@item @var{console-stream-output} @expansion{}
14724@code{"~" @var{c-string}}
14725
14726@item @var{target-stream-output} @expansion{}
14727@code{"@@" @var{c-string}}
14728
14729@item @var{log-stream-output} @expansion{}
14730@code{"&" @var{c-string}}
14731
14732@item @var{nl} @expansion{}
14733@code{CR | CR-LF}
14734
14735@item @var{token} @expansion{}
14736@emph{any sequence of digits}.
14737@end table
14738
14739@noindent
14740Notes:
14741
14742@itemize @bullet
14743@item
14744All output sequences end in a single line containing a period.
14745
14746@item
14747The @code{@var{token}} is from the corresponding request. If an execution
14748command is interrupted by the @samp{-exec-interrupt} command, the
14749@var{token} associated with the @samp{*stopped} message is the one of the
14750original execution command, not the one of the interrupt command.
14751
14752@item
14753@cindex status output in @sc{gdb/mi}
14754@var{status-async-output} contains on-going status information about the
14755progress of a slow operation. It can be discarded. All status output is
14756prefixed by @samp{+}.
14757
14758@item
14759@cindex async output in @sc{gdb/mi}
14760@var{exec-async-output} contains asynchronous state change on the target
14761(stopped, started, disappeared). All async output is prefixed by
14762@samp{*}.
14763
14764@item
14765@cindex notify output in @sc{gdb/mi}
14766@var{notify-async-output} contains supplementary information that the
14767client should handle (e.g., a new breakpoint information). All notify
14768output is prefixed by @samp{=}.
14769
14770@item
14771@cindex console output in @sc{gdb/mi}
14772@var{console-stream-output} is output that should be displayed as is in the
14773console. It is the textual response to a CLI command. All the console
14774output is prefixed by @samp{~}.
14775
14776@item
14777@cindex target output in @sc{gdb/mi}
14778@var{target-stream-output} is the output produced by the target program.
14779All the target output is prefixed by @samp{@@}.
14780
14781@item
14782@cindex log output in @sc{gdb/mi}
14783@var{log-stream-output} is output text coming from @value{GDBN}'s internals, for
14784instance messages that should be displayed as part of an error log. All
14785the log output is prefixed by @samp{&}.
14786
14787@item
14788@cindex list output in @sc{gdb/mi}
14789New @sc{gdb/mi} commands should only output @var{lists} containing
14790@var{values}.
14791
14792
14793@end itemize
14794
14795@xref{GDB/MI Stream Records, , @sc{gdb/mi} Stream Records}, for more
14796details about the various output records.
14797
14798@node GDB/MI Simple Examples
14799@subsection Simple Examples of @sc{gdb/mi} Interaction
14800@cindex @sc{gdb/mi}, simple examples
14801
14802This subsection presents several simple examples of interaction using
14803the @sc{gdb/mi} interface. In these examples, @samp{->} means that the
14804following line is passed to @sc{gdb/mi} as input, while @samp{<-} means
14805the output received from @sc{gdb/mi}.
14806
14807@subsubheading Target Stop
14808@c Ummm... There is no "-stop" command. This assumes async, no?
14809Here's an example of stopping the inferior process:
14810
14811@smallexample
14812-> -stop
14813<- (@value{GDBP})
14814@end smallexample
14815
14816@noindent
14817and later:
14818
14819@smallexample
14820<- *stop,reason="stop",address="0x123",source="a.c:123"
14821<- (@value{GDBP})
14822@end smallexample
14823
14824@subsubheading Simple CLI Command
14825
14826Here's an example of a simple CLI command being passed through
14827@sc{gdb/mi} and on to the CLI.
14828
14829@smallexample
14830-> print 1+2
14831<- &"print 1+2\n"
14832<- ~"$1 = 3\n"
14833<- ^done
14834<- (@value{GDBP})
14835@end smallexample
14836
14837@subsubheading Command With Side Effects
14838
14839@smallexample
14840-> -symbol-file xyz.exe
14841<- *breakpoint,nr="3",address="0x123",source="a.c:123"
14842<- (@value{GDBP})
14843@end smallexample
14844
14845@subsubheading A Bad Command
14846
14847Here's what happens if you pass a non-existent command:
14848
14849@smallexample
14850-> -rubbish
14851<- ^error,msg="Undefined MI command: rubbish"
14852<- (@value{GDBP})
14853@end smallexample
14854
14855@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
14856@node GDB/MI Compatibility with CLI
14857@section @sc{gdb/mi} Compatibility with CLI
14858
14859@cindex compatibility, @sc{gdb/mi} and CLI
14860@cindex @sc{gdb/mi}, compatibility with CLI
14861To help users familiar with @value{GDBN}'s existing CLI interface, @sc{gdb/mi}
14862accepts existing CLI commands. As specified by the syntax, such
14863commands can be directly entered into the @sc{gdb/mi} interface and @value{GDBN} will
14864respond.
14865
14866This mechanism is provided as an aid to developers of @sc{gdb/mi}
14867clients and not as a reliable interface into the CLI. Since the command
14868is being interpreteted in an environment that assumes @sc{gdb/mi}
14869behaviour, the exact output of such commands is likely to end up being
14870an un-supported hybrid of @sc{gdb/mi} and CLI output.
14871
14872@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
14873@node GDB/MI Output Records
14874@section @sc{gdb/mi} Output Records
14875
14876@menu
14877* GDB/MI Result Records::
14878* GDB/MI Stream Records::
14879* GDB/MI Out-of-band Records::
14880@end menu
14881
14882@node GDB/MI Result Records
14883@subsection @sc{gdb/mi} Result Records
14884
14885@cindex result records in @sc{gdb/mi}
14886@cindex @sc{gdb/mi}, result records
14887In addition to a number of out-of-band notifications, the response to a
14888@sc{gdb/mi} command includes one of the following result indications:
14889
14890@table @code
14891@findex ^done
14892@item "^done" [ "," @var{results} ]
14893The synchronous operation was successful, @code{@var{results}} are the return
14894values.
14895
14896@item "^running"
14897@findex ^running
14898@c Is this one correct? Should it be an out-of-band notification?
14899The asynchronous operation was successfully started. The target is
14900running.
14901
14902@item "^error" "," @var{c-string}
14903@findex ^error
14904The operation failed. The @code{@var{c-string}} contains the corresponding
14905error message.
14906@end table
14907
14908@node GDB/MI Stream Records
14909@subsection @sc{gdb/mi} Stream Records
14910
14911@cindex @sc{gdb/mi}, stream records
14912@cindex stream records in @sc{gdb/mi}
14913@value{GDBN} internally maintains a number of output streams: the console, the
14914target, and the log. The output intended for each of these streams is
14915funneled through the @sc{gdb/mi} interface using @dfn{stream records}.
14916
14917Each stream record begins with a unique @dfn{prefix character} which
14918identifies its stream (@pxref{GDB/MI Output Syntax, , @sc{gdb/mi} Output
14919Syntax}). In addition to the prefix, each stream record contains a
14920@code{@var{string-output}}. This is either raw text (with an implicit new
14921line) or a quoted C string (which does not contain an implicit newline).
14922
14923@table @code
14924@item "~" @var{string-output}
14925The console output stream contains text that should be displayed in the
14926CLI console window. It contains the textual responses to CLI commands.
14927
14928@item "@@" @var{string-output}
14929The target output stream contains any textual output from the running
14930target.
14931
14932@item "&" @var{string-output}
14933The log stream contains debugging messages being produced by @value{GDBN}'s
14934internals.
14935@end table
14936
14937@node GDB/MI Out-of-band Records
14938@subsection @sc{gdb/mi} Out-of-band Records
14939
14940@cindex out-of-band records in @sc{gdb/mi}
14941@cindex @sc{gdb/mi}, out-of-band records
14942@dfn{Out-of-band} records are used to notify the @sc{gdb/mi} client of
14943additional changes that have occurred. Those changes can either be a
14944consequence of @sc{gdb/mi} (e.g., a breakpoint modified) or a result of
14945target activity (e.g., target stopped).
14946
14947The following is a preliminary list of possible out-of-band records.
14948
14949@table @code
14950@item "*" "stop"
14951@end table
14952
14953
14954@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
14955@node GDB/MI Command Description Format
14956@section @sc{gdb/mi} Command Description Format
14957
14958The remaining sections describe blocks of commands. Each block of
14959commands is laid out in a fashion similar to this section.
14960
14961Note the the line breaks shown in the examples are here only for
14962readability. They don't appear in the real output.
14963Also note that the commands with a non-available example (N.A.@:) are
14964not yet implemented.
14965
14966@subheading Motivation
14967
14968The motivation for this collection of commands.
14969
14970@subheading Introduction
14971
14972A brief introduction to this collection of commands as a whole.
14973
14974@subheading Commands
14975
14976For each command in the block, the following is described:
14977
14978@subsubheading Synopsis
14979
14980@smallexample
14981 -command @var{args}@dots{}
14982@end smallexample
14983
14984@subsubheading @value{GDBN} Command
14985
14986The corresponding @value{GDBN} CLI command.
14987
14988@subsubheading Result
14989
14990@subsubheading Out-of-band
14991
14992@subsubheading Notes
14993
14994@subsubheading Example
14995
14996
14997@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
14998@node GDB/MI Breakpoint Table Commands
14999@section @sc{gdb/mi} Breakpoint table commands
15000
15001@cindex breakpoint commands for @sc{gdb/mi}
15002@cindex @sc{gdb/mi}, breakpoint commands
15003This section documents @sc{gdb/mi} commands for manipulating
15004breakpoints.
15005
15006@subheading The @code{-break-after} Command
15007@findex -break-after
15008
15009@subsubheading Synopsis
15010
15011@smallexample
15012 -break-after @var{number} @var{count}
15013@end smallexample
15014
15015The breakpoint number @var{number} is not in effect until it has been
15016hit @var{count} times. To see how this is reflected in the output of
15017the @samp{-break-list} command, see the description of the
15018@samp{-break-list} command below.
15019
15020@subsubheading @value{GDBN} Command
15021
15022The corresponding @value{GDBN} command is @samp{ignore}.
15023
15024@subsubheading Example
15025
15026@smallexample
15027(@value{GDBP})
15028-break-insert main
15029^done,bkpt=@{number="1",addr="0x000100d0",file="hello.c",line="5"@}
15030(@value{GDBP})
15031-break-after 1 3
15032~
15033^done
15034(@value{GDBP})
15035-break-list
15036^done,BreakpointTable=@{nr_rows="1",nr_cols="6",
15037hdr=[@{width="3",alignment="-1",col_name="number",colhdr="Num"@},
15038@{width="14",alignment="-1",col_name="type",colhdr="Type"@},
15039@{width="4",alignment="-1",col_name="disp",colhdr="Disp"@},
15040@{width="3",alignment="-1",col_name="enabled",colhdr="Enb"@},
15041@{width="10",alignment="-1",col_name="addr",colhdr="Address"@},
15042@{width="40",alignment="2",col_name="what",colhdr="What"@}],
15043body=[bkpt=@{number="1",type="breakpoint",disp="keep",enabled="y",
15044addr="0x000100d0",func="main",file="hello.c",line="5",times="0",
15045ignore="3"@}]@}
15046(@value{GDBP})
15047@end smallexample
15048
15049@ignore
15050@subheading The @code{-break-catch} Command
15051@findex -break-catch
15052
15053@subheading The @code{-break-commands} Command
15054@findex -break-commands
15055@end ignore
15056
15057
15058@subheading The @code{-break-condition} Command
15059@findex -break-condition
15060
15061@subsubheading Synopsis
15062
15063@smallexample
15064 -break-condition @var{number} @var{expr}
15065@end smallexample
15066
15067Breakpoint @var{number} will stop the program only if the condition in
15068@var{expr} is true. The condition becomes part of the
15069@samp{-break-list} output (see the description of the @samp{-break-list}
15070command below).
15071
15072@subsubheading @value{GDBN} Command
15073
15074The corresponding @value{GDBN} command is @samp{condition}.
15075
15076@subsubheading Example
15077
15078@smallexample
15079(@value{GDBP})
15080-break-condition 1 1
15081^done
15082(@value{GDBP})
15083-break-list
15084^done,BreakpointTable=@{nr_rows="1",nr_cols="6",
15085hdr=[@{width="3",alignment="-1",col_name="number",colhdr="Num"@},
15086@{width="14",alignment="-1",col_name="type",colhdr="Type"@},
15087@{width="4",alignment="-1",col_name="disp",colhdr="Disp"@},
15088@{width="3",alignment="-1",col_name="enabled",colhdr="Enb"@},
15089@{width="10",alignment="-1",col_name="addr",colhdr="Address"@},
15090@{width="40",alignment="2",col_name="what",colhdr="What"@}],
15091body=[bkpt=@{number="1",type="breakpoint",disp="keep",enabled="y",
15092addr="0x000100d0",func="main",file="hello.c",line="5",cond="1",
15093times="0",ignore="3"@}]@}
15094(@value{GDBP})
15095@end smallexample
15096
15097@subheading The @code{-break-delete} Command
15098@findex -break-delete
15099
15100@subsubheading Synopsis
15101
15102@smallexample
15103 -break-delete ( @var{breakpoint} )+
15104@end smallexample
15105
15106Delete the breakpoint(s) whose number(s) are specified in the argument
15107list. This is obviously reflected in the breakpoint list.
15108
15109@subsubheading @value{GDBN} command
15110
15111The corresponding @value{GDBN} command is @samp{delete}.
15112
15113@subsubheading Example
15114
15115@smallexample
15116(@value{GDBP})
15117-break-delete 1
15118^done
15119(@value{GDBP})
15120-break-list
15121^done,BreakpointTable=@{nr_rows="0",nr_cols="6",
15122hdr=[@{width="3",alignment="-1",col_name="number",colhdr="Num"@},
15123@{width="14",alignment="-1",col_name="type",colhdr="Type"@},
15124@{width="4",alignment="-1",col_name="disp",colhdr="Disp"@},
15125@{width="3",alignment="-1",col_name="enabled",colhdr="Enb"@},
15126@{width="10",alignment="-1",col_name="addr",colhdr="Address"@},
15127@{width="40",alignment="2",col_name="what",colhdr="What"@}],
15128body=[]@}
15129(@value{GDBP})
15130@end smallexample
15131
15132@subheading The @code{-break-disable} Command
15133@findex -break-disable
15134
15135@subsubheading Synopsis
15136
15137@smallexample
15138 -break-disable ( @var{breakpoint} )+
15139@end smallexample
15140
15141Disable the named @var{breakpoint}(s). The field @samp{enabled} in the
15142break list is now set to @samp{n} for the named @var{breakpoint}(s).
15143
15144@subsubheading @value{GDBN} Command
15145
15146The corresponding @value{GDBN} command is @samp{disable}.
15147
15148@subsubheading Example
15149
15150@smallexample
15151(@value{GDBP})
15152-break-disable 2
15153^done
15154(@value{GDBP})
15155-break-list
15156^done,BreakpointTable=@{nr_rows="1",nr_cols="6",
15157hdr=[@{width="3",alignment="-1",col_name="number",colhdr="Num"@},
15158@{width="14",alignment="-1",col_name="type",colhdr="Type"@},
15159@{width="4",alignment="-1",col_name="disp",colhdr="Disp"@},
15160@{width="3",alignment="-1",col_name="enabled",colhdr="Enb"@},
15161@{width="10",alignment="-1",col_name="addr",colhdr="Address"@},
15162@{width="40",alignment="2",col_name="what",colhdr="What"@}],
15163body=[bkpt=@{number="2",type="breakpoint",disp="keep",enabled="n",
15164addr="0x000100d0",func="main",file="hello.c",line="5",times="0"@}]@}
15165(@value{GDBP})
15166@end smallexample
15167
15168@subheading The @code{-break-enable} Command
15169@findex -break-enable
15170
15171@subsubheading Synopsis
15172
15173@smallexample
15174 -break-enable ( @var{breakpoint} )+
15175@end smallexample
15176
15177Enable (previously disabled) @var{breakpoint}(s).
15178
15179@subsubheading @value{GDBN} Command
15180
15181The corresponding @value{GDBN} command is @samp{enable}.
15182
15183@subsubheading Example
15184
15185@smallexample
15186(@value{GDBP})
15187-break-enable 2
15188^done
15189(@value{GDBP})
15190-break-list
15191^done,BreakpointTable=@{nr_rows="1",nr_cols="6",
15192hdr=[@{width="3",alignment="-1",col_name="number",colhdr="Num"@},
15193@{width="14",alignment="-1",col_name="type",colhdr="Type"@},
15194@{width="4",alignment="-1",col_name="disp",colhdr="Disp"@},
15195@{width="3",alignment="-1",col_name="enabled",colhdr="Enb"@},
15196@{width="10",alignment="-1",col_name="addr",colhdr="Address"@},
15197@{width="40",alignment="2",col_name="what",colhdr="What"@}],
15198body=[bkpt=@{number="2",type="breakpoint",disp="keep",enabled="y",
15199addr="0x000100d0",func="main",file="hello.c",line="5",times="0"@}]@}
15200(@value{GDBP})
15201@end smallexample
15202
15203@subheading The @code{-break-info} Command
15204@findex -break-info
15205
15206@subsubheading Synopsis
15207
15208@smallexample
15209 -break-info @var{breakpoint}
15210@end smallexample
15211
15212@c REDUNDANT???
15213Get information about a single breakpoint.
15214
15215@subsubheading @value{GDBN} command
15216
15217The corresponding @value{GDBN} command is @samp{info break @var{breakpoint}}.
15218
15219@subsubheading Example
15220N.A.
15221
15222@subheading The @code{-break-insert} Command
15223@findex -break-insert
15224
15225@subsubheading Synopsis
15226
15227@smallexample
15228 -break-insert [ -t ] [ -h ] [ -r ]
15229 [ -c @var{condition} ] [ -i @var{ignore-count} ]
15230 [ -p @var{thread} ] [ @var{line} | @var{addr} ]
15231@end smallexample
15232
15233@noindent
15234If specified, @var{line}, can be one of:
15235
15236@itemize @bullet
15237@item function
15238@c @item +offset
15239@c @item -offset
15240@c @item linenum
15241@item filename:linenum
15242@item filename:function
15243@item *address
15244@end itemize
15245
15246The possible optional parameters of this command are:
15247
15248@table @samp
15249@item -t
15250Insert a tempoary breakpoint.
15251@item -h
15252Insert a hardware breakpoint.
15253@item -c @var{condition}
15254Make the breakpoint conditional on @var{condition}.
15255@item -i @var{ignore-count}
15256Initialize the @var{ignore-count}.
15257@item -r
15258Insert a regular breakpoint in all the functions whose names match the
15259given regular expression. Other flags are not applicable to regular
15260expresson.
15261@end table
15262
15263@subsubheading Result
15264
15265The result is in the form:
15266
15267@smallexample
15268 ^done,bkptno="@var{number}",func="@var{funcname}",
15269 file="@var{filename}",line="@var{lineno}"
15270@end smallexample
15271
15272@noindent
15273where @var{number} is the @value{GDBN} number for this breakpoint, @var{funcname}
15274is the name of the function where the breakpoint was inserted,
15275@var{filename} is the name of the source file which contains this
15276function, and @var{lineno} is the source line number within that file.
15277
15278Note: this format is open to change.
15279@c An out-of-band breakpoint instead of part of the result?
15280
15281@subsubheading @value{GDBN} Command
15282
15283The corresponding @value{GDBN} commands are @samp{break}, @samp{tbreak},
15284@samp{hbreak}, @samp{thbreak}, and @samp{rbreak}.
15285
15286@subsubheading Example
15287
15288@smallexample
15289(@value{GDBP})
15290-break-insert main
15291^done,bkpt=@{number="1",addr="0x0001072c",file="recursive2.c",line="4"@}
15292(@value{GDBP})
15293-break-insert -t foo
15294^done,bkpt=@{number="2",addr="0x00010774",file="recursive2.c",line="11"@}
15295(@value{GDBP})
15296-break-list
15297^done,BreakpointTable=@{nr_rows="2",nr_cols="6",
15298hdr=[@{width="3",alignment="-1",col_name="number",colhdr="Num"@},
15299@{width="14",alignment="-1",col_name="type",colhdr="Type"@},
15300@{width="4",alignment="-1",col_name="disp",colhdr="Disp"@},
15301@{width="3",alignment="-1",col_name="enabled",colhdr="Enb"@},
15302@{width="10",alignment="-1",col_name="addr",colhdr="Address"@},
15303@{width="40",alignment="2",col_name="what",colhdr="What"@}],
15304body=[bkpt=@{number="1",type="breakpoint",disp="keep",enabled="y",
15305addr="0x0001072c", func="main",file="recursive2.c",line="4",times="0"@},
15306bkpt=@{number="2",type="breakpoint",disp="del",enabled="y",
15307addr="0x00010774",func="foo",file="recursive2.c",line="11",times="0"@}]@}
15308(@value{GDBP})
15309-break-insert -r foo.*
15310~int foo(int, int);
15311^done,bkpt=@{number="3",addr="0x00010774",file="recursive2.c",line="11"@}
15312(@value{GDBP})
15313@end smallexample
15314
15315@subheading The @code{-break-list} Command
15316@findex -break-list
15317
15318@subsubheading Synopsis
15319
15320@smallexample
15321 -break-list
15322@end smallexample
15323
15324Displays the list of inserted breakpoints, showing the following fields:
15325
15326@table @samp
15327@item Number
15328number of the breakpoint
15329@item Type
15330type of the breakpoint: @samp{breakpoint} or @samp{watchpoint}
15331@item Disposition
15332should the breakpoint be deleted or disabled when it is hit: @samp{keep}
15333or @samp{nokeep}
15334@item Enabled
15335is the breakpoint enabled or no: @samp{y} or @samp{n}
15336@item Address
15337memory location at which the breakpoint is set
15338@item What
15339logical location of the breakpoint, expressed by function name, file
15340name, line number
15341@item Times
15342number of times the breakpoint has been hit
15343@end table
15344
15345If there are no breakpoints or watchpoints, the @code{BreakpointTable}
15346@code{body} field is an empty list.
15347
15348@subsubheading @value{GDBN} Command
15349
15350The corresponding @value{GDBN} command is @samp{info break}.
15351
15352@subsubheading Example
15353
15354@smallexample
15355(@value{GDBP})
15356-break-list
15357^done,BreakpointTable=@{nr_rows="2",nr_cols="6",
15358hdr=[@{width="3",alignment="-1",col_name="number",colhdr="Num"@},
15359@{width="14",alignment="-1",col_name="type",colhdr="Type"@},
15360@{width="4",alignment="-1",col_name="disp",colhdr="Disp"@},
15361@{width="3",alignment="-1",col_name="enabled",colhdr="Enb"@},
15362@{width="10",alignment="-1",col_name="addr",colhdr="Address"@},
15363@{width="40",alignment="2",col_name="what",colhdr="What"@}],
15364body=[bkpt=@{number="1",type="breakpoint",disp="keep",enabled="y",
15365addr="0x000100d0",func="main",file="hello.c",line="5",times="0"@},
15366bkpt=@{number="2",type="breakpoint",disp="keep",enabled="y",
15367addr="0x00010114",func="foo",file="hello.c",line="13",times="0"@}]@}
15368(@value{GDBP})
15369@end smallexample
15370
15371Here's an example of the result when there are no breakpoints:
15372
15373@smallexample
15374(@value{GDBP})
15375-break-list
15376^done,BreakpointTable=@{nr_rows="0",nr_cols="6",
15377hdr=[@{width="3",alignment="-1",col_name="number",colhdr="Num"@},
15378@{width="14",alignment="-1",col_name="type",colhdr="Type"@},
15379@{width="4",alignment="-1",col_name="disp",colhdr="Disp"@},
15380@{width="3",alignment="-1",col_name="enabled",colhdr="Enb"@},
15381@{width="10",alignment="-1",col_name="addr",colhdr="Address"@},
15382@{width="40",alignment="2",col_name="what",colhdr="What"@}],
15383body=[]@}
15384(@value{GDBP})
15385@end smallexample
15386
15387@subheading The @code{-break-watch} Command
15388@findex -break-watch
15389
15390@subsubheading Synopsis
15391
15392@smallexample
15393 -break-watch [ -a | -r ]
15394@end smallexample
15395
15396Create a watchpoint. With the @samp{-a} option it will create an
15397@dfn{access} watchpoint, i.e. a watchpoint that triggers either on a
15398read from or on a write to the memory location. With the @samp{-r}
15399option, the watchpoint created is a @dfn{read} watchpoint, i.e. it will
15400trigger only when the memory location is accessed for reading. Without
15401either of the options, the watchpoint created is a regular watchpoint,
15402i.e. it will trigger when the memory location is accessed for writing.
15403@xref{Set Watchpoints, , Setting watchpoints}.
15404
15405Note that @samp{-break-list} will report a single list of watchpoints and
15406breakpoints inserted.
15407
15408@subsubheading @value{GDBN} Command
15409
15410The corresponding @value{GDBN} commands are @samp{watch}, @samp{awatch}, and
15411@samp{rwatch}.
15412
15413@subsubheading Example
15414
15415Setting a watchpoint on a variable in the @code{main} function:
15416
15417@smallexample
15418(@value{GDBP})
15419-break-watch x
15420^done,wpt=@{number="2",exp="x"@}
15421(@value{GDBP})
15422-exec-continue
15423^running
15424^done,reason="watchpoint-trigger",wpt=@{number="2",exp="x"@},
15425value=@{old="-268439212",new="55"@},
15426frame=@{func="main",args=[],file="recursive2.c",line="5"@}
15427(@value{GDBP})
15428@end smallexample
15429
15430Setting a watchpoint on a variable local to a function. @value{GDBN} will stop
15431the program execution twice: first for the variable changing value, then
15432for the watchpoint going out of scope.
15433
15434@smallexample
15435(@value{GDBP})
15436-break-watch C
15437^done,wpt=@{number="5",exp="C"@}
15438(@value{GDBP})
15439-exec-continue
15440^running
15441^done,reason="watchpoint-trigger",
15442wpt=@{number="5",exp="C"@},value=@{old="-276895068",new="3"@},
15443frame=@{func="callee4",args=[],
15444file="../../../devo/gdb/testsuite/gdb.mi/basics.c",line="13"@}
15445(@value{GDBP})
15446-exec-continue
15447^running
15448^done,reason="watchpoint-scope",wpnum="5",
15449frame=@{func="callee3",args=[@{name="strarg",
15450value="0x11940 \"A string argument.\""@}],
15451file="../../../devo/gdb/testsuite/gdb.mi/basics.c",line="18"@}
15452(@value{GDBP})
15453@end smallexample
15454
15455Listing breakpoints and watchpoints, at different points in the program
15456execution. Note that once the watchpoint goes out of scope, it is
15457deleted.
15458
15459@smallexample
15460(@value{GDBP})
15461-break-watch C
15462^done,wpt=@{number="2",exp="C"@}
15463(@value{GDBP})
15464-break-list
15465^done,BreakpointTable=@{nr_rows="2",nr_cols="6",
15466hdr=[@{width="3",alignment="-1",col_name="number",colhdr="Num"@},
15467@{width="14",alignment="-1",col_name="type",colhdr="Type"@},
15468@{width="4",alignment="-1",col_name="disp",colhdr="Disp"@},
15469@{width="3",alignment="-1",col_name="enabled",colhdr="Enb"@},
15470@{width="10",alignment="-1",col_name="addr",colhdr="Address"@},
15471@{width="40",alignment="2",col_name="what",colhdr="What"@}],
15472body=[bkpt=@{number="1",type="breakpoint",disp="keep",enabled="y",
15473addr="0x00010734",func="callee4",
15474file="../../../devo/gdb/testsuite/gdb.mi/basics.c",line="8",times="1"@},
15475bkpt=@{number="2",type="watchpoint",disp="keep",
15476enabled="y",addr="",what="C",times="0"@}]@}
15477(@value{GDBP})
15478-exec-continue
15479^running
15480^done,reason="watchpoint-trigger",wpt=@{number="2",exp="C"@},
15481value=@{old="-276895068",new="3"@},
15482frame=@{func="callee4",args=[],
15483file="../../../devo/gdb/testsuite/gdb.mi/basics.c",line="13"@}
15484(@value{GDBP})
15485-break-list
15486^done,BreakpointTable=@{nr_rows="2",nr_cols="6",
15487hdr=[@{width="3",alignment="-1",col_name="number",colhdr="Num"@},
15488@{width="14",alignment="-1",col_name="type",colhdr="Type"@},
15489@{width="4",alignment="-1",col_name="disp",colhdr="Disp"@},
15490@{width="3",alignment="-1",col_name="enabled",colhdr="Enb"@},
15491@{width="10",alignment="-1",col_name="addr",colhdr="Address"@},
15492@{width="40",alignment="2",col_name="what",colhdr="What"@}],
15493body=[bkpt=@{number="1",type="breakpoint",disp="keep",enabled="y",
15494addr="0x00010734",func="callee4",
15495file="../../../devo/gdb/testsuite/gdb.mi/basics.c",line="8",times="1"@},
15496bkpt=@{number="2",type="watchpoint",disp="keep",
15497enabled="y",addr="",what="C",times="-5"@}]@}
15498(@value{GDBP})
15499-exec-continue
15500^running
15501^done,reason="watchpoint-scope",wpnum="2",
15502frame=@{func="callee3",args=[@{name="strarg",
15503value="0x11940 \"A string argument.\""@}],
15504file="../../../devo/gdb/testsuite/gdb.mi/basics.c",line="18"@}
15505(@value{GDBP})
15506-break-list
15507^done,BreakpointTable=@{nr_rows="1",nr_cols="6",
15508hdr=[@{width="3",alignment="-1",col_name="number",colhdr="Num"@},
15509@{width="14",alignment="-1",col_name="type",colhdr="Type"@},
15510@{width="4",alignment="-1",col_name="disp",colhdr="Disp"@},
15511@{width="3",alignment="-1",col_name="enabled",colhdr="Enb"@},
15512@{width="10",alignment="-1",col_name="addr",colhdr="Address"@},
15513@{width="40",alignment="2",col_name="what",colhdr="What"@}],
15514body=[bkpt=@{number="1",type="breakpoint",disp="keep",enabled="y",
15515addr="0x00010734",func="callee4",
15516file="../../../devo/gdb/testsuite/gdb.mi/basics.c",line="8",times="1"@}]@}
15517(@value{GDBP})
15518@end smallexample
15519
15520@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
15521@node GDB/MI Data Manipulation
15522@section @sc{gdb/mi} Data Manipulation
15523
15524@cindex data manipulation, in @sc{gdb/mi}
15525@cindex @sc{gdb/mi}, data manipulation
15526This section describes the @sc{gdb/mi} commands that manipulate data:
15527examine memory and registers, evaluate expressions, etc.
15528
15529@c REMOVED FROM THE INTERFACE.
15530@c @subheading -data-assign
15531@c Change the value of a program variable. Plenty of side effects.
15532@c @subsubheading GDB command
15533@c set variable
15534@c @subsubheading Example
15535@c N.A.
15536
15537@subheading The @code{-data-disassemble} Command
15538@findex -data-disassemble
15539
15540@subsubheading Synopsis
15541
15542@smallexample
15543 -data-disassemble
15544 [ -s @var{start-addr} -e @var{end-addr} ]
15545 | [ -f @var{filename} -l @var{linenum} [ -n @var{lines} ] ]
15546 -- @var{mode}
15547@end smallexample
15548
15549@noindent
15550Where:
15551
15552@table @samp
15553@item @var{start-addr}
15554is the beginning address (or @code{$pc})
15555@item @var{end-addr}
15556is the end address
15557@item @var{filename}
15558is the name of the file to disassemble
15559@item @var{linenum}
15560is the line number to disassemble around
15561@item @var{lines}
15562is the the number of disassembly lines to be produced. If it is -1,
15563the whole function will be disassembled, in case no @var{end-addr} is
15564specified. If @var{end-addr} is specified as a non-zero value, and
15565@var{lines} is lower than the number of disassembly lines between
15566@var{start-addr} and @var{end-addr}, only @var{lines} lines are
15567displayed; if @var{lines} is higher than the number of lines between
15568@var{start-addr} and @var{end-addr}, only the lines up to @var{end-addr}
15569are displayed.
15570@item @var{mode}
15571is either 0 (meaning only disassembly) or 1 (meaning mixed source and
15572disassembly).
15573@end table
15574
15575@subsubheading Result
15576
15577The output for each instruction is composed of four fields:
15578
15579@itemize @bullet
15580@item Address
15581@item Func-name
15582@item Offset
15583@item Instruction
15584@end itemize
15585
15586Note that whatever included in the instruction field, is not manipulated
15587directely by @sc{gdb/mi}, i.e. it is not possible to adjust its format.
15588
15589@subsubheading @value{GDBN} Command
15590
15591There's no direct mapping from this command to the CLI.
15592
15593@subsubheading Example
15594
15595Disassemble from the current value of @code{$pc} to @code{$pc + 20}:
15596
15597@smallexample
15598(@value{GDBP})
15599-data-disassemble -s $pc -e "$pc + 20" -- 0
15600^done,
15601asm_insns=[
15602@{address="0x000107c0",func-name="main",offset="4",
15603inst="mov 2, %o0"@},
15604@{address="0x000107c4",func-name="main",offset="8",
15605inst="sethi %hi(0x11800), %o2"@},
15606@{address="0x000107c8",func-name="main",offset="12",
15607inst="or %o2, 0x140, %o1\t! 0x11940 <_lib_version+8>"@},
15608@{address="0x000107cc",func-name="main",offset="16",
15609inst="sethi %hi(0x11800), %o2"@},
15610@{address="0x000107d0",func-name="main",offset="20",
15611inst="or %o2, 0x168, %o4\t! 0x11968 <_lib_version+48>"@}]
15612(@value{GDBP})
15613@end smallexample
15614
15615Disassemble the whole @code{main} function. Line 32 is part of
15616@code{main}.
15617
15618@smallexample
15619-data-disassemble -f basics.c -l 32 -- 0
15620^done,asm_insns=[
15621@{address="0x000107bc",func-name="main",offset="0",
15622inst="save %sp, -112, %sp"@},
15623@{address="0x000107c0",func-name="main",offset="4",
15624inst="mov 2, %o0"@},
15625@{address="0x000107c4",func-name="main",offset="8",
15626inst="sethi %hi(0x11800), %o2"@},
15627[@dots{}]
15628@{address="0x0001081c",func-name="main",offset="96",inst="ret "@},
15629@{address="0x00010820",func-name="main",offset="100",inst="restore "@}]
15630(@value{GDBP})
15631@end smallexample
15632
15633Disassemble 3 instructions from the start of @code{main}:
15634
15635@smallexample
15636(@value{GDBP})
15637-data-disassemble -f basics.c -l 32 -n 3 -- 0
15638^done,asm_insns=[
15639@{address="0x000107bc",func-name="main",offset="0",
15640inst="save %sp, -112, %sp"@},
15641@{address="0x000107c0",func-name="main",offset="4",
15642inst="mov 2, %o0"@},
15643@{address="0x000107c4",func-name="main",offset="8",
15644inst="sethi %hi(0x11800), %o2"@}]
15645(@value{GDBP})
15646@end smallexample
15647
15648Disassemble 3 instructions from the start of @code{main} in mixed mode:
15649
15650@smallexample
15651(@value{GDBP})
15652-data-disassemble -f basics.c -l 32 -n 3 -- 1
15653^done,asm_insns=[
15654src_and_asm_line=@{line="31",
15655file="/kwikemart/marge/ezannoni/flathead-dev/devo/gdb/ \
15656 testsuite/gdb.mi/basics.c",line_asm_insn=[
15657@{address="0x000107bc",func-name="main",offset="0",
15658inst="save %sp, -112, %sp"@}]@},
15659src_and_asm_line=@{line="32",
15660file="/kwikemart/marge/ezannoni/flathead-dev/devo/gdb/ \
15661 testsuite/gdb.mi/basics.c",line_asm_insn=[
15662@{address="0x000107c0",func-name="main",offset="4",
15663inst="mov 2, %o0"@},
15664@{address="0x000107c4",func-name="main",offset="8",
15665inst="sethi %hi(0x11800), %o2"@}]@}]
15666(@value{GDBP})
15667@end smallexample
15668
15669
15670@subheading The @code{-data-evaluate-expression} Command
15671@findex -data-evaluate-expression
15672
15673@subsubheading Synopsis
15674
15675@smallexample
15676 -data-evaluate-expression @var{expr}
15677@end smallexample
15678
15679Evaluate @var{expr} as an expression. The expression could contain an
15680inferior function call. The function call will execute synchronously.
15681If the expression contains spaces, it must be enclosed in double quotes.
15682
15683@subsubheading @value{GDBN} Command
15684
15685The corresponding @value{GDBN} commands are @samp{print}, @samp{output}, and
15686@samp{call}. In @code{gdbtk} only, there's a corresponding
15687@samp{gdb_eval} command.
15688
15689@subsubheading Example
15690
15691In the following example, the numbers that precede the commands are the
15692@dfn{tokens} described in @ref{GDB/MI Command Syntax, ,@sc{gdb/mi}
15693Command Syntax}. Notice how @sc{gdb/mi} returns the same tokens in its
15694output.
15695
15696@smallexample
15697211-data-evaluate-expression A
15698211^done,value="1"
15699(@value{GDBP})
15700311-data-evaluate-expression &A
15701311^done,value="0xefffeb7c"
15702(@value{GDBP})
15703411-data-evaluate-expression A+3
15704411^done,value="4"
15705(@value{GDBP})
15706511-data-evaluate-expression "A + 3"
15707511^done,value="4"
15708(@value{GDBP})
15709@end smallexample
15710
15711
15712@subheading The @code{-data-list-changed-registers} Command
15713@findex -data-list-changed-registers
15714
15715@subsubheading Synopsis
15716
15717@smallexample
15718 -data-list-changed-registers
15719@end smallexample
15720
15721Display a list of the registers that have changed.
15722
15723@subsubheading @value{GDBN} Command
15724
15725@value{GDBN} doesn't have a direct analog for this command; @code{gdbtk}
15726has the corresponding command @samp{gdb_changed_register_list}.
15727
15728@subsubheading Example
15729
15730On a PPC MBX board:
15731
15732@smallexample
15733(@value{GDBP})
15734-exec-continue
15735^running
15736
15737(@value{GDBP})
15738*stopped,reason="breakpoint-hit",bkptno="1",frame=@{func="main",
15739args=[],file="try.c",line="5"@}
15740(@value{GDBP})
15741-data-list-changed-registers
15742^done,changed-registers=["0","1","2","4","5","6","7","8","9",
15743"10","11","13","14","15","16","17","18","19","20","21","22","23",
15744"24","25","26","27","28","30","31","64","65","66","67","69"]
15745(@value{GDBP})
15746@end smallexample
15747
15748
15749@subheading The @code{-data-list-register-names} Command
15750@findex -data-list-register-names
15751
15752@subsubheading Synopsis
15753
15754@smallexample
15755 -data-list-register-names [ ( @var{regno} )+ ]
15756@end smallexample
15757
15758Show a list of register names for the current target. If no arguments
15759are given, it shows a list of the names of all the registers. If
15760integer numbers are given as arguments, it will print a list of the
15761names of the registers corresponding to the arguments. To ensure
15762consistency between a register name and its number, the output list may
15763include empty register names.
15764
15765@subsubheading @value{GDBN} Command
15766
15767@value{GDBN} does not have a command which corresponds to
15768@samp{-data-list-register-names}. In @code{gdbtk} there is a
15769corresponding command @samp{gdb_regnames}.
15770
15771@subsubheading Example
15772
15773For the PPC MBX board:
15774@smallexample
15775(@value{GDBP})
15776-data-list-register-names
15777^done,register-names=["r0","r1","r2","r3","r4","r5","r6","r7",
15778"r8","r9","r10","r11","r12","r13","r14","r15","r16","r17","r18",
15779"r19","r20","r21","r22","r23","r24","r25","r26","r27","r28","r29",
15780"r30","r31","f0","f1","f2","f3","f4","f5","f6","f7","f8","f9",
15781"f10","f11","f12","f13","f14","f15","f16","f17","f18","f19","f20",
15782"f21","f22","f23","f24","f25","f26","f27","f28","f29","f30","f31",
15783"", "pc","ps","cr","lr","ctr","xer"]
15784(@value{GDBP})
15785-data-list-register-names 1 2 3
15786^done,register-names=["r1","r2","r3"]
15787(@value{GDBP})
15788@end smallexample
15789
15790@subheading The @code{-data-list-register-values} Command
15791@findex -data-list-register-values
15792
15793@subsubheading Synopsis
15794
15795@smallexample
15796 -data-list-register-values @var{fmt} [ ( @var{regno} )*]
15797@end smallexample
15798
15799Display the registers' contents. @var{fmt} is the format according to
15800which the registers' contents are to be returned, followed by an optional
15801list of numbers specifying the registers to display. A missing list of
15802numbers indicates that the contents of all the registers must be returned.
15803
15804Allowed formats for @var{fmt} are:
15805
15806@table @code
15807@item x
15808Hexadecimal
15809@item o
15810Octal
15811@item t
15812Binary
15813@item d
15814Decimal
15815@item r
15816Raw
15817@item N
15818Natural
15819@end table
15820
15821@subsubheading @value{GDBN} Command
15822
15823The corresponding @value{GDBN} commands are @samp{info reg}, @samp{info
15824all-reg}, and (in @code{gdbtk}) @samp{gdb_fetch_registers}.
15825
15826@subsubheading Example
15827
15828For a PPC MBX board (note: line breaks are for readability only, they
15829don't appear in the actual output):
15830
15831@smallexample
15832(@value{GDBP})
15833-data-list-register-values r 64 65
15834^done,register-values=[@{number="64",value="0xfe00a300"@},
15835@{number="65",value="0x00029002"@}]
15836(@value{GDBP})
15837-data-list-register-values x
15838^done,register-values=[@{number="0",value="0xfe0043c8"@},
15839@{number="1",value="0x3fff88"@},@{number="2",value="0xfffffffe"@},
15840@{number="3",value="0x0"@},@{number="4",value="0xa"@},
15841@{number="5",value="0x3fff68"@},@{number="6",value="0x3fff58"@},
15842@{number="7",value="0xfe011e98"@},@{number="8",value="0x2"@},
15843@{number="9",value="0xfa202820"@},@{number="10",value="0xfa202808"@},
15844@{number="11",value="0x1"@},@{number="12",value="0x0"@},
15845@{number="13",value="0x4544"@},@{number="14",value="0xffdfffff"@},
15846@{number="15",value="0xffffffff"@},@{number="16",value="0xfffffeff"@},
15847@{number="17",value="0xefffffed"@},@{number="18",value="0xfffffffe"@},
15848@{number="19",value="0xffffffff"@},@{number="20",value="0xffffffff"@},
15849@{number="21",value="0xffffffff"@},@{number="22",value="0xfffffff7"@},
15850@{number="23",value="0xffffffff"@},@{number="24",value="0xffffffff"@},
15851@{number="25",value="0xffffffff"@},@{number="26",value="0xfffffffb"@},
15852@{number="27",value="0xffffffff"@},@{number="28",value="0xf7bfffff"@},
15853@{number="29",value="0x0"@},@{number="30",value="0xfe010000"@},
15854@{number="31",value="0x0"@},@{number="32",value="0x0"@},
15855@{number="33",value="0x0"@},@{number="34",value="0x0"@},
15856@{number="35",value="0x0"@},@{number="36",value="0x0"@},
15857@{number="37",value="0x0"@},@{number="38",value="0x0"@},
15858@{number="39",value="0x0"@},@{number="40",value="0x0"@},
15859@{number="41",value="0x0"@},@{number="42",value="0x0"@},
15860@{number="43",value="0x0"@},@{number="44",value="0x0"@},
15861@{number="45",value="0x0"@},@{number="46",value="0x0"@},
15862@{number="47",value="0x0"@},@{number="48",value="0x0"@},
15863@{number="49",value="0x0"@},@{number="50",value="0x0"@},
15864@{number="51",value="0x0"@},@{number="52",value="0x0"@},
15865@{number="53",value="0x0"@},@{number="54",value="0x0"@},
15866@{number="55",value="0x0"@},@{number="56",value="0x0"@},
15867@{number="57",value="0x0"@},@{number="58",value="0x0"@},
15868@{number="59",value="0x0"@},@{number="60",value="0x0"@},
15869@{number="61",value="0x0"@},@{number="62",value="0x0"@},
15870@{number="63",value="0x0"@},@{number="64",value="0xfe00a300"@},
15871@{number="65",value="0x29002"@},@{number="66",value="0x202f04b5"@},
15872@{number="67",value="0xfe0043b0"@},@{number="68",value="0xfe00b3e4"@},
15873@{number="69",value="0x20002b03"@}]
15874(@value{GDBP})
15875@end smallexample
15876
15877
15878@subheading The @code{-data-read-memory} Command
15879@findex -data-read-memory
15880
15881@subsubheading Synopsis
15882
15883@smallexample
15884 -data-read-memory [ -o @var{byte-offset} ]
15885 @var{address} @var{word-format} @var{word-size}
15886 @var{nr-rows} @var{nr-cols} [ @var{aschar} ]
15887@end smallexample
15888
15889@noindent
15890where:
15891
15892@table @samp
15893@item @var{address}
15894An expression specifying the address of the first memory word to be
15895read. Complex expressions containing embedded white space should be
15896quoted using the C convention.
15897
15898@item @var{word-format}
15899The format to be used to print the memory words. The notation is the
15900same as for @value{GDBN}'s @code{print} command (@pxref{Output Formats,
15901,Output formats}).
15902
15903@item @var{word-size}
15904The size of each memory word in bytes.
15905
15906@item @var{nr-rows}
15907The number of rows in the output table.
15908
15909@item @var{nr-cols}
15910The number of columns in the output table.
15911
15912@item @var{aschar}
15913If present, indicates that each row should include an @sc{ascii} dump. The
15914value of @var{aschar} is used as a padding character when a byte is not a
15915member of the printable @sc{ascii} character set (printable @sc{ascii}
15916characters are those whose code is between 32 and 126, inclusively).
15917
15918@item @var{byte-offset}
15919An offset to add to the @var{address} before fetching memory.
15920@end table
15921
15922This command displays memory contents as a table of @var{nr-rows} by
15923@var{nr-cols} words, each word being @var{word-size} bytes. In total,
15924@code{@var{nr-rows} * @var{nr-cols} * @var{word-size}} bytes are read
15925(returned as @samp{total-bytes}). Should less than the requested number
15926of bytes be returned by the target, the missing words are identified
15927using @samp{N/A}. The number of bytes read from the target is returned
15928in @samp{nr-bytes} and the starting address used to read memory in
15929@samp{addr}.
15930
15931The address of the next/previous row or page is available in
15932@samp{next-row} and @samp{prev-row}, @samp{next-page} and
15933@samp{prev-page}.
15934
15935@subsubheading @value{GDBN} Command
15936
15937The corresponding @value{GDBN} command is @samp{x}. @code{gdbtk} has
15938@samp{gdb_get_mem} memory read command.
15939
15940@subsubheading Example
15941
15942Read six bytes of memory starting at @code{bytes+6} but then offset by
15943@code{-6} bytes. Format as three rows of two columns. One byte per
15944word. Display each word in hex.
15945
15946@smallexample
15947(@value{GDBP})
159489-data-read-memory -o -6 -- bytes+6 x 1 3 2
159499^done,addr="0x00001390",nr-bytes="6",total-bytes="6",
15950next-row="0x00001396",prev-row="0x0000138e",next-page="0x00001396",
15951prev-page="0x0000138a",memory=[
15952@{addr="0x00001390",data=["0x00","0x01"]@},
15953@{addr="0x00001392",data=["0x02","0x03"]@},
15954@{addr="0x00001394",data=["0x04","0x05"]@}]
15955(@value{GDBP})
15956@end smallexample
15957
15958Read two bytes of memory starting at address @code{shorts + 64} and
15959display as a single word formatted in decimal.
15960
15961@smallexample
15962(@value{GDBP})
159635-data-read-memory shorts+64 d 2 1 1
159645^done,addr="0x00001510",nr-bytes="2",total-bytes="2",
15965next-row="0x00001512",prev-row="0x0000150e",
15966next-page="0x00001512",prev-page="0x0000150e",memory=[
15967@{addr="0x00001510",data=["128"]@}]
15968(@value{GDBP})
15969@end smallexample
15970
15971Read thirty two bytes of memory starting at @code{bytes+16} and format
15972as eight rows of four columns. Include a string encoding with @samp{x}
15973used as the non-printable character.
15974
15975@smallexample
15976(@value{GDBP})
159774-data-read-memory bytes+16 x 1 8 4 x
159784^done,addr="0x000013a0",nr-bytes="32",total-bytes="32",
15979next-row="0x000013c0",prev-row="0x0000139c",
15980next-page="0x000013c0",prev-page="0x00001380",memory=[
15981@{addr="0x000013a0",data=["0x10","0x11","0x12","0x13"],ascii="xxxx"@},
15982@{addr="0x000013a4",data=["0x14","0x15","0x16","0x17"],ascii="xxxx"@},
15983@{addr="0x000013a8",data=["0x18","0x19","0x1a","0x1b"],ascii="xxxx"@},
15984@{addr="0x000013ac",data=["0x1c","0x1d","0x1e","0x1f"],ascii="xxxx"@},
15985@{addr="0x000013b0",data=["0x20","0x21","0x22","0x23"],ascii=" !\"#"@},
15986@{addr="0x000013b4",data=["0x24","0x25","0x26","0x27"],ascii="$%&'"@},
15987@{addr="0x000013b8",data=["0x28","0x29","0x2a","0x2b"],ascii="()*+"@},
15988@{addr="0x000013bc",data=["0x2c","0x2d","0x2e","0x2f"],ascii=",-./"@}]
15989(@value{GDBP})
15990@end smallexample
15991
15992@subheading The @code{-display-delete} Command
15993@findex -display-delete
15994
15995@subsubheading Synopsis
15996
15997@smallexample
15998 -display-delete @var{number}
15999@end smallexample
16000
16001Delete the display @var{number}.
16002
16003@subsubheading @value{GDBN} Command
16004
16005The corresponding @value{GDBN} command is @samp{delete display}.
16006
16007@subsubheading Example
16008N.A.
16009
16010
16011@subheading The @code{-display-disable} Command
16012@findex -display-disable
16013
16014@subsubheading Synopsis
16015
16016@smallexample
16017 -display-disable @var{number}
16018@end smallexample
16019
16020Disable display @var{number}.
16021
16022@subsubheading @value{GDBN} Command
16023
16024The corresponding @value{GDBN} command is @samp{disable display}.
16025
16026@subsubheading Example
16027N.A.
16028
16029
16030@subheading The @code{-display-enable} Command
16031@findex -display-enable
16032
16033@subsubheading Synopsis
16034
16035@smallexample
16036 -display-enable @var{number}
16037@end smallexample
16038
16039Enable display @var{number}.
16040
16041@subsubheading @value{GDBN} Command
16042
16043The corresponding @value{GDBN} command is @samp{enable display}.
16044
16045@subsubheading Example
16046N.A.
16047
16048
16049@subheading The @code{-display-insert} Command
16050@findex -display-insert
16051
16052@subsubheading Synopsis
16053
16054@smallexample
16055 -display-insert @var{expression}
16056@end smallexample
16057
16058Display @var{expression} every time the program stops.
16059
16060@subsubheading @value{GDBN} Command
16061
16062The corresponding @value{GDBN} command is @samp{display}.
16063
16064@subsubheading Example
16065N.A.
16066
16067
16068@subheading The @code{-display-list} Command
16069@findex -display-list
16070
16071@subsubheading Synopsis
16072
16073@smallexample
16074 -display-list
16075@end smallexample
16076
16077List the displays. Do not show the current values.
16078
16079@subsubheading @value{GDBN} Command
16080
16081The corresponding @value{GDBN} command is @samp{info display}.
16082
16083@subsubheading Example
16084N.A.
16085
16086
16087@subheading The @code{-environment-cd} Command
16088@findex -environment-cd
16089
16090@subsubheading Synopsis
16091
16092@smallexample
16093 -environment-cd @var{pathdir}
16094@end smallexample
16095
16096Set @value{GDBN}'s working directory.
16097
16098@subsubheading @value{GDBN} Command
16099
16100The corresponding @value{GDBN} command is @samp{cd}.
16101
16102@subsubheading Example
16103
16104@smallexample
16105(@value{GDBP})
16106-environment-cd /kwikemart/marge/ezannoni/flathead-dev/devo/gdb
16107^done
16108(@value{GDBP})
16109@end smallexample
16110
16111
16112@subheading The @code{-environment-directory} Command
16113@findex -environment-directory
16114
16115@subsubheading Synopsis
16116
16117@smallexample
16118 -environment-directory [ -r ] [ @var{pathdir} ]+
16119@end smallexample
16120
16121Add directories @var{pathdir} to beginning of search path for source files.
16122If the @samp{-r} option is used, the search path is reset to the default
b383017d 16123search path. If directories @var{pathdir} are supplied in addition to the
922fbb7b
AC
16124@samp{-r} option, the search path is first reset and then addition
16125occurs as normal.
b383017d 16126Multiple directories may be specified, separated by blanks. Specifying
922fbb7b
AC
16127multiple directories in a single command
16128results in the directories added to the beginning of the
16129search path in the same order they were presented in the command.
16130If blanks are needed as
16131part of a directory name, double-quotes should be used around
16132the name. In the command output, the path will show up separated
b383017d 16133by the system directory-separator character. The directory-seperator
922fbb7b
AC
16134character must not be used
16135in any directory name.
16136If no directories are specified, the current search path is displayed.
16137
16138@subsubheading @value{GDBN} Command
16139
16140The corresponding @value{GDBN} command is @samp{dir}.
16141
16142@subsubheading Example
16143
16144@smallexample
16145(@value{GDBP})
16146-environment-directory /kwikemart/marge/ezannoni/flathead-dev/devo/gdb
16147^done,source-path="/kwikemart/marge/ezannoni/flathead-dev/devo/gdb:$cdir:$cwd"
16148(@value{GDBP})
16149-environment-directory ""
16150^done,source-path="/kwikemart/marge/ezannoni/flathead-dev/devo/gdb:$cdir:$cwd"
16151(@value{GDBP})
16152-environment-directory -r /home/jjohnstn/src/gdb /usr/src
16153^done,source-path="/home/jjohnstn/src/gdb:/usr/src:$cdir:$cwd"
16154(@value{GDBP})
16155-environment-directory -r
16156^done,source-path="$cdir:$cwd"
16157(@value{GDBP})
16158@end smallexample
16159
16160
16161@subheading The @code{-environment-path} Command
16162@findex -environment-path
16163
16164@subsubheading Synopsis
16165
16166@smallexample
16167 -environment-path [ -r ] [ @var{pathdir} ]+
16168@end smallexample
16169
16170Add directories @var{pathdir} to beginning of search path for object files.
16171If the @samp{-r} option is used, the search path is reset to the original
b383017d
RM
16172search path that existed at gdb start-up. If directories @var{pathdir} are
16173supplied in addition to the
922fbb7b
AC
16174@samp{-r} option, the search path is first reset and then addition
16175occurs as normal.
b383017d 16176Multiple directories may be specified, separated by blanks. Specifying
922fbb7b
AC
16177multiple directories in a single command
16178results in the directories added to the beginning of the
16179search path in the same order they were presented in the command.
16180If blanks are needed as
16181part of a directory name, double-quotes should be used around
16182the name. In the command output, the path will show up separated
b383017d 16183by the system directory-separator character. The directory-seperator
922fbb7b
AC
16184character must not be used
16185in any directory name.
16186If no directories are specified, the current path is displayed.
16187
16188
16189@subsubheading @value{GDBN} Command
16190
16191The corresponding @value{GDBN} command is @samp{path}.
16192
16193@subsubheading Example
16194
16195@smallexample
16196(@value{GDBP})
b383017d 16197-environment-path
922fbb7b
AC
16198^done,path="/usr/bin"
16199(@value{GDBP})
16200-environment-path /kwikemart/marge/ezannoni/flathead-dev/ppc-eabi/gdb /bin
16201^done,path="/kwikemart/marge/ezannoni/flathead-dev/ppc-eabi/gdb:/bin:/usr/bin"
16202(@value{GDBP})
16203-environment-path -r /usr/local/bin
16204^done,path="/usr/local/bin:/usr/bin"
16205(@value{GDBP})
16206@end smallexample
16207
16208
16209@subheading The @code{-environment-pwd} Command
16210@findex -environment-pwd
16211
16212@subsubheading Synopsis
16213
16214@smallexample
16215 -environment-pwd
16216@end smallexample
16217
16218Show the current working directory.
16219
16220@subsubheading @value{GDBN} command
16221
16222The corresponding @value{GDBN} command is @samp{pwd}.
16223
16224@subsubheading Example
16225
16226@smallexample
16227(@value{GDBP})
16228-environment-pwd
16229^done,cwd="/kwikemart/marge/ezannoni/flathead-dev/devo/gdb"
16230(@value{GDBP})
16231@end smallexample
16232
16233@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
16234@node GDB/MI Program Control
16235@section @sc{gdb/mi} Program control
16236
16237@subsubheading Program termination
16238
16239As a result of execution, the inferior program can run to completion, if
16240it doesn't encounter any breakpoints. In this case the output will
16241include an exit code, if the program has exited exceptionally.
16242
16243@subsubheading Examples
16244
16245@noindent
16246Program exited normally:
16247
16248@smallexample
16249(@value{GDBP})
16250-exec-run
16251^running
16252(@value{GDBP})
16253x = 55
16254*stopped,reason="exited-normally"
16255(@value{GDBP})
16256@end smallexample
16257
16258@noindent
16259Program exited exceptionally:
16260
16261@smallexample
16262(@value{GDBP})
16263-exec-run
16264^running
16265(@value{GDBP})
16266x = 55
16267*stopped,reason="exited",exit-code="01"
16268(@value{GDBP})
16269@end smallexample
16270
16271Another way the program can terminate is if it receives a signal such as
16272@code{SIGINT}. In this case, @sc{gdb/mi} displays this:
16273
16274@smallexample
16275(@value{GDBP})
16276*stopped,reason="exited-signalled",signal-name="SIGINT",
16277signal-meaning="Interrupt"
16278@end smallexample
16279
16280
16281@subheading The @code{-exec-abort} Command
16282@findex -exec-abort
16283
16284@subsubheading Synopsis
16285
16286@smallexample
16287 -exec-abort
16288@end smallexample
16289
16290Kill the inferior running program.
16291
16292@subsubheading @value{GDBN} Command
16293
16294The corresponding @value{GDBN} command is @samp{kill}.
16295
16296@subsubheading Example
16297N.A.
16298
16299
16300@subheading The @code{-exec-arguments} Command
16301@findex -exec-arguments
16302
16303@subsubheading Synopsis
16304
16305@smallexample
16306 -exec-arguments @var{args}
16307@end smallexample
16308
16309Set the inferior program arguments, to be used in the next
16310@samp{-exec-run}.
16311
16312@subsubheading @value{GDBN} Command
16313
16314The corresponding @value{GDBN} command is @samp{set args}.
16315
16316@subsubheading Example
16317
16318@c FIXME!
16319Don't have one around.
16320
16321
16322@subheading The @code{-exec-continue} Command
16323@findex -exec-continue
16324
16325@subsubheading Synopsis
16326
16327@smallexample
16328 -exec-continue
16329@end smallexample
16330
16331Asynchronous command. Resumes the execution of the inferior program
16332until a breakpoint is encountered, or until the inferior exits.
16333
16334@subsubheading @value{GDBN} Command
16335
16336The corresponding @value{GDBN} corresponding is @samp{continue}.
16337
16338@subsubheading Example
16339
16340@smallexample
16341-exec-continue
16342^running
16343(@value{GDBP})
16344@@Hello world
16345*stopped,reason="breakpoint-hit",bkptno="2",frame=@{func="foo",args=[],
16346file="hello.c",line="13"@}
16347(@value{GDBP})
16348@end smallexample
16349
16350
16351@subheading The @code{-exec-finish} Command
16352@findex -exec-finish
16353
16354@subsubheading Synopsis
16355
16356@smallexample
16357 -exec-finish
16358@end smallexample
16359
16360Asynchronous command. Resumes the execution of the inferior program
16361until the current function is exited. Displays the results returned by
16362the function.
16363
16364@subsubheading @value{GDBN} Command
16365
16366The corresponding @value{GDBN} command is @samp{finish}.
16367
16368@subsubheading Example
16369
16370Function returning @code{void}.
16371
16372@smallexample
16373-exec-finish
16374^running
16375(@value{GDBP})
16376@@hello from foo
16377*stopped,reason="function-finished",frame=@{func="main",args=[],
16378file="hello.c",line="7"@}
16379(@value{GDBP})
16380@end smallexample
16381
16382Function returning other than @code{void}. The name of the internal
16383@value{GDBN} variable storing the result is printed, together with the
16384value itself.
16385
16386@smallexample
16387-exec-finish
16388^running
16389(@value{GDBP})
16390*stopped,reason="function-finished",frame=@{addr="0x000107b0",func="foo",
16391args=[@{name="a",value="1"],@{name="b",value="9"@}@},
16392file="recursive2.c",line="14"@},
16393gdb-result-var="$1",return-value="0"
16394(@value{GDBP})
16395@end smallexample
16396
16397
16398@subheading The @code{-exec-interrupt} Command
16399@findex -exec-interrupt
16400
16401@subsubheading Synopsis
16402
16403@smallexample
16404 -exec-interrupt
16405@end smallexample
16406
16407Asynchronous command. Interrupts the background execution of the target.
16408Note how the token associated with the stop message is the one for the
16409execution command that has been interrupted. The token for the interrupt
16410itself only appears in the @samp{^done} output. If the user is trying to
16411interrupt a non-running program, an error message will be printed.
16412
16413@subsubheading @value{GDBN} Command
16414
16415The corresponding @value{GDBN} command is @samp{interrupt}.
16416
16417@subsubheading Example
16418
16419@smallexample
16420(@value{GDBP})
16421111-exec-continue
16422111^running
16423
16424(@value{GDBP})
16425222-exec-interrupt
16426222^done
16427(@value{GDBP})
16428111*stopped,signal-name="SIGINT",signal-meaning="Interrupt",
16429frame=@{addr="0x00010140",func="foo",args=[],file="try.c",line="13"@}
16430(@value{GDBP})
16431
16432(@value{GDBP})
16433-exec-interrupt
16434^error,msg="mi_cmd_exec_interrupt: Inferior not executing."
16435(@value{GDBP})
16436@end smallexample
16437
16438
16439@subheading The @code{-exec-next} Command
16440@findex -exec-next
16441
16442@subsubheading Synopsis
16443
16444@smallexample
16445 -exec-next
16446@end smallexample
16447
16448Asynchronous command. Resumes execution of the inferior program, stopping
16449when the beginning of the next source line is reached.
16450
16451@subsubheading @value{GDBN} Command
16452
16453The corresponding @value{GDBN} command is @samp{next}.
16454
16455@subsubheading Example
16456
16457@smallexample
16458-exec-next
16459^running
16460(@value{GDBP})
16461*stopped,reason="end-stepping-range",line="8",file="hello.c"
16462(@value{GDBP})
16463@end smallexample
16464
16465
16466@subheading The @code{-exec-next-instruction} Command
16467@findex -exec-next-instruction
16468
16469@subsubheading Synopsis
16470
16471@smallexample
16472 -exec-next-instruction
16473@end smallexample
16474
16475Asynchronous command. Executes one machine instruction. If the
16476instruction is a function call continues until the function returns. If
16477the program stops at an instruction in the middle of a source line, the
16478address will be printed as well.
16479
16480@subsubheading @value{GDBN} Command
16481
16482The corresponding @value{GDBN} command is @samp{nexti}.
16483
16484@subsubheading Example
16485
16486@smallexample
16487(@value{GDBP})
16488-exec-next-instruction
16489^running
16490
16491(@value{GDBP})
16492*stopped,reason="end-stepping-range",
16493addr="0x000100d4",line="5",file="hello.c"
16494(@value{GDBP})
16495@end smallexample
16496
16497
16498@subheading The @code{-exec-return} Command
16499@findex -exec-return
16500
16501@subsubheading Synopsis
16502
16503@smallexample
16504 -exec-return
16505@end smallexample
16506
16507Makes current function return immediately. Doesn't execute the inferior.
16508Displays the new current frame.
16509
16510@subsubheading @value{GDBN} Command
16511
16512The corresponding @value{GDBN} command is @samp{return}.
16513
16514@subsubheading Example
16515
16516@smallexample
16517(@value{GDBP})
16518200-break-insert callee4
16519200^done,bkpt=@{number="1",addr="0x00010734",
16520file="../../../devo/gdb/testsuite/gdb.mi/basics.c",line="8"@}
16521(@value{GDBP})
16522000-exec-run
16523000^running
16524(@value{GDBP})
16525000*stopped,reason="breakpoint-hit",bkptno="1",
16526frame=@{func="callee4",args=[],
16527file="../../../devo/gdb/testsuite/gdb.mi/basics.c",line="8"@}
16528(@value{GDBP})
16529205-break-delete
16530205^done
16531(@value{GDBP})
16532111-exec-return
16533111^done,frame=@{level="0",func="callee3",
16534args=[@{name="strarg",
16535value="0x11940 \"A string argument.\""@}],
16536file="../../../devo/gdb/testsuite/gdb.mi/basics.c",line="18"@}
16537(@value{GDBP})
16538@end smallexample
16539
16540
16541@subheading The @code{-exec-run} Command
16542@findex -exec-run
16543
16544@subsubheading Synopsis
16545
16546@smallexample
16547 -exec-run
16548@end smallexample
16549
16550Asynchronous command. Starts execution of the inferior from the
16551beginning. The inferior executes until either a breakpoint is
16552encountered or the program exits.
16553
16554@subsubheading @value{GDBN} Command
16555
16556The corresponding @value{GDBN} command is @samp{run}.
16557
16558@subsubheading Example
16559
16560@smallexample
16561(@value{GDBP})
16562-break-insert main
16563^done,bkpt=@{number="1",addr="0x0001072c",file="recursive2.c",line="4"@}
16564(@value{GDBP})
16565-exec-run
16566^running
16567(@value{GDBP})
16568*stopped,reason="breakpoint-hit",bkptno="1",
16569frame=@{func="main",args=[],file="recursive2.c",line="4"@}
16570(@value{GDBP})
16571@end smallexample
16572
16573
16574@subheading The @code{-exec-show-arguments} Command
16575@findex -exec-show-arguments
16576
16577@subsubheading Synopsis
16578
16579@smallexample
16580 -exec-show-arguments
16581@end smallexample
16582
16583Print the arguments of the program.
16584
16585@subsubheading @value{GDBN} Command
16586
16587The corresponding @value{GDBN} command is @samp{show args}.
16588
16589@subsubheading Example
16590N.A.
16591
16592@c @subheading -exec-signal
16593
16594@subheading The @code{-exec-step} Command
16595@findex -exec-step
16596
16597@subsubheading Synopsis
16598
16599@smallexample
16600 -exec-step
16601@end smallexample
16602
16603Asynchronous command. Resumes execution of the inferior program, stopping
16604when the beginning of the next source line is reached, if the next
16605source line is not a function call. If it is, stop at the first
16606instruction of the called function.
16607
16608@subsubheading @value{GDBN} Command
16609
16610The corresponding @value{GDBN} command is @samp{step}.
16611
16612@subsubheading Example
16613
16614Stepping into a function:
16615
16616@smallexample
16617-exec-step
16618^running
16619(@value{GDBP})
16620*stopped,reason="end-stepping-range",
16621frame=@{func="foo",args=[@{name="a",value="10"@},
16622@{name="b",value="0"@}],file="recursive2.c",line="11"@}
16623(@value{GDBP})
16624@end smallexample
16625
16626Regular stepping:
16627
16628@smallexample
16629-exec-step
16630^running
16631(@value{GDBP})
16632*stopped,reason="end-stepping-range",line="14",file="recursive2.c"
16633(@value{GDBP})
16634@end smallexample
16635
16636
16637@subheading The @code{-exec-step-instruction} Command
16638@findex -exec-step-instruction
16639
16640@subsubheading Synopsis
16641
16642@smallexample
16643 -exec-step-instruction
16644@end smallexample
16645
16646Asynchronous command. Resumes the inferior which executes one machine
16647instruction. The output, once @value{GDBN} has stopped, will vary depending on
16648whether we have stopped in the middle of a source line or not. In the
16649former case, the address at which the program stopped will be printed as
16650well.
16651
16652@subsubheading @value{GDBN} Command
16653
16654The corresponding @value{GDBN} command is @samp{stepi}.
16655
16656@subsubheading Example
16657
16658@smallexample
16659(@value{GDBP})
16660-exec-step-instruction
16661^running
16662
16663(@value{GDBP})
16664*stopped,reason="end-stepping-range",
16665frame=@{func="foo",args=[],file="try.c",line="10"@}
16666(@value{GDBP})
16667-exec-step-instruction
16668^running
16669
16670(@value{GDBP})
16671*stopped,reason="end-stepping-range",
16672frame=@{addr="0x000100f4",func="foo",args=[],file="try.c",line="10"@}
16673(@value{GDBP})
16674@end smallexample
16675
16676
16677@subheading The @code{-exec-until} Command
16678@findex -exec-until
16679
16680@subsubheading Synopsis
16681
16682@smallexample
16683 -exec-until [ @var{location} ]
16684@end smallexample
16685
16686Asynchronous command. Executes the inferior until the @var{location}
16687specified in the argument is reached. If there is no argument, the inferior
16688executes until a source line greater than the current one is reached.
16689The reason for stopping in this case will be @samp{location-reached}.
16690
16691@subsubheading @value{GDBN} Command
16692
16693The corresponding @value{GDBN} command is @samp{until}.
16694
16695@subsubheading Example
16696
16697@smallexample
16698(@value{GDBP})
16699-exec-until recursive2.c:6
16700^running
16701(@value{GDBP})
16702x = 55
16703*stopped,reason="location-reached",frame=@{func="main",args=[],
16704file="recursive2.c",line="6"@}
16705(@value{GDBP})
16706@end smallexample
16707
16708@ignore
16709@subheading -file-clear
16710Is this going away????
16711@end ignore
16712
16713
16714@subheading The @code{-file-exec-and-symbols} Command
16715@findex -file-exec-and-symbols
16716
16717@subsubheading Synopsis
16718
16719@smallexample
16720 -file-exec-and-symbols @var{file}
16721@end smallexample
16722
16723Specify the executable file to be debugged. This file is the one from
16724which the symbol table is also read. If no file is specified, the
16725command clears the executable and symbol information. If breakpoints
16726are set when using this command with no arguments, @value{GDBN} will produce
16727error messages. Otherwise, no output is produced, except a completion
16728notification.
16729
16730@subsubheading @value{GDBN} Command
16731
16732The corresponding @value{GDBN} command is @samp{file}.
16733
16734@subsubheading Example
16735
16736@smallexample
16737(@value{GDBP})
16738-file-exec-and-symbols /kwikemart/marge/ezannoni/TRUNK/mbx/hello.mbx
16739^done
16740(@value{GDBP})
16741@end smallexample
16742
16743
16744@subheading The @code{-file-exec-file} Command
16745@findex -file-exec-file
16746
16747@subsubheading Synopsis
16748
16749@smallexample
16750 -file-exec-file @var{file}
16751@end smallexample
16752
16753Specify the executable file to be debugged. Unlike
16754@samp{-file-exec-and-symbols}, the symbol table is @emph{not} read
16755from this file. If used without argument, @value{GDBN} clears the information
16756about the executable file. No output is produced, except a completion
16757notification.
16758
16759@subsubheading @value{GDBN} Command
16760
16761The corresponding @value{GDBN} command is @samp{exec-file}.
16762
16763@subsubheading Example
16764
16765@smallexample
16766(@value{GDBP})
16767-file-exec-file /kwikemart/marge/ezannoni/TRUNK/mbx/hello.mbx
16768^done
16769(@value{GDBP})
16770@end smallexample
16771
16772
16773@subheading The @code{-file-list-exec-sections} Command
16774@findex -file-list-exec-sections
16775
16776@subsubheading Synopsis
16777
16778@smallexample
16779 -file-list-exec-sections
16780@end smallexample
16781
16782List the sections of the current executable file.
16783
16784@subsubheading @value{GDBN} Command
16785
16786The @value{GDBN} command @samp{info file} shows, among the rest, the same
16787information as this command. @code{gdbtk} has a corresponding command
16788@samp{gdb_load_info}.
16789
16790@subsubheading Example
16791N.A.
16792
16793
1abaf70c
BR
16794@subheading The @code{-file-list-exec-source-file} Command
16795@findex -file-list-exec-source-file
16796
16797@subsubheading Synopsis
16798
16799@smallexample
16800 -file-list-exec-source-file
16801@end smallexample
16802
b383017d 16803List the line number, the current source file, and the absolute path
1abaf70c
BR
16804to the current source file for the current executable.
16805
16806@subsubheading @value{GDBN} Command
16807
16808There's no @value{GDBN} command which directly corresponds to this one.
16809
16810@subsubheading Example
16811
16812@smallexample
16813(@value{GDBP})
16814123-file-list-exec-source-file
16815123^done,line="1",file="foo.c",fullname="/home/bar/foo.c"
16816(@value{GDBP})
16817@end smallexample
16818
16819
922fbb7b
AC
16820@subheading The @code{-file-list-exec-source-files} Command
16821@findex -file-list-exec-source-files
16822
16823@subsubheading Synopsis
16824
16825@smallexample
16826 -file-list-exec-source-files
16827@end smallexample
16828
16829List the source files for the current executable.
16830
57c22c6c
BR
16831It will always output the filename, but only when GDB can find the absolute
16832file name of a source file, will it output the fullname.
16833
922fbb7b
AC
16834@subsubheading @value{GDBN} Command
16835
16836There's no @value{GDBN} command which directly corresponds to this one.
16837@code{gdbtk} has an analogous command @samp{gdb_listfiles}.
16838
16839@subsubheading Example
57c22c6c
BR
16840@smallexample
16841(@value{GDBP})
16842-file-list-exec-source-files
16843^done,files=[
16844@{file=foo.c,fullname=/home/foo.c@},
16845@{file=/home/bar.c,fullname=/home/bar.c@},
16846@{file=gdb_could_not_find_fullpath.c@}]
16847(@value{GDBP})
16848@end smallexample
922fbb7b
AC
16849
16850@subheading The @code{-file-list-shared-libraries} Command
16851@findex -file-list-shared-libraries
16852
16853@subsubheading Synopsis
16854
16855@smallexample
16856 -file-list-shared-libraries
16857@end smallexample
16858
16859List the shared libraries in the program.
16860
16861@subsubheading @value{GDBN} Command
16862
16863The corresponding @value{GDBN} command is @samp{info shared}.
16864
16865@subsubheading Example
16866N.A.
16867
16868
16869@subheading The @code{-file-list-symbol-files} Command
16870@findex -file-list-symbol-files
16871
16872@subsubheading Synopsis
16873
16874@smallexample
16875 -file-list-symbol-files
16876@end smallexample
16877
16878List symbol files.
16879
16880@subsubheading @value{GDBN} Command
16881
16882The corresponding @value{GDBN} command is @samp{info file} (part of it).
16883
16884@subsubheading Example
16885N.A.
16886
16887
16888@subheading The @code{-file-symbol-file} Command
16889@findex -file-symbol-file
16890
16891@subsubheading Synopsis
16892
16893@smallexample
16894 -file-symbol-file @var{file}
16895@end smallexample
16896
16897Read symbol table info from the specified @var{file} argument. When
16898used without arguments, clears @value{GDBN}'s symbol table info. No output is
16899produced, except for a completion notification.
16900
16901@subsubheading @value{GDBN} Command
16902
16903The corresponding @value{GDBN} command is @samp{symbol-file}.
16904
16905@subsubheading Example
16906
16907@smallexample
16908(@value{GDBP})
16909-file-symbol-file /kwikemart/marge/ezannoni/TRUNK/mbx/hello.mbx
16910^done
16911(@value{GDBP})
16912@end smallexample
16913
16914@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
16915@node GDB/MI Miscellaneous Commands
16916@section Miscellaneous @value{GDBN} commands in @sc{gdb/mi}
16917
16918@c @subheading -gdb-complete
16919
16920@subheading The @code{-gdb-exit} Command
16921@findex -gdb-exit
16922
16923@subsubheading Synopsis
16924
16925@smallexample
16926 -gdb-exit
16927@end smallexample
16928
16929Exit @value{GDBN} immediately.
16930
16931@subsubheading @value{GDBN} Command
16932
16933Approximately corresponds to @samp{quit}.
16934
16935@subsubheading Example
16936
16937@smallexample
16938(@value{GDBP})
16939-gdb-exit
16940@end smallexample
16941
16942@subheading The @code{-gdb-set} Command
16943@findex -gdb-set
16944
16945@subsubheading Synopsis
16946
16947@smallexample
16948 -gdb-set
16949@end smallexample
16950
16951Set an internal @value{GDBN} variable.
16952@c IS THIS A DOLLAR VARIABLE? OR SOMETHING LIKE ANNOTATE ?????
16953
16954@subsubheading @value{GDBN} Command
16955
16956The corresponding @value{GDBN} command is @samp{set}.
16957
16958@subsubheading Example
16959
16960@smallexample
16961(@value{GDBP})
16962-gdb-set $foo=3
16963^done
16964(@value{GDBP})
16965@end smallexample
16966
16967
16968@subheading The @code{-gdb-show} Command
16969@findex -gdb-show
16970
16971@subsubheading Synopsis
16972
16973@smallexample
16974 -gdb-show
16975@end smallexample
16976
16977Show the current value of a @value{GDBN} variable.
16978
16979@subsubheading @value{GDBN} command
16980
16981The corresponding @value{GDBN} command is @samp{show}.
16982
16983@subsubheading Example
16984
16985@smallexample
16986(@value{GDBP})
16987-gdb-show annotate
16988^done,value="0"
16989(@value{GDBP})
16990@end smallexample
16991
16992@c @subheading -gdb-source
16993
16994
16995@subheading The @code{-gdb-version} Command
16996@findex -gdb-version
16997
16998@subsubheading Synopsis
16999
17000@smallexample
17001 -gdb-version
17002@end smallexample
17003
17004Show version information for @value{GDBN}. Used mostly in testing.
17005
17006@subsubheading @value{GDBN} Command
17007
17008There's no equivalent @value{GDBN} command. @value{GDBN} by default shows this
17009information when you start an interactive session.
17010
17011@subsubheading Example
17012
17013@c This example modifies the actual output from GDB to avoid overfull
17014@c box in TeX.
17015@smallexample
17016(@value{GDBP})
17017-gdb-version
17018~GNU gdb 5.2.1
17019~Copyright 2000 Free Software Foundation, Inc.
17020~GDB is free software, covered by the GNU General Public License, and
17021~you are welcome to change it and/or distribute copies of it under
17022~ certain conditions.
17023~Type "show copying" to see the conditions.
17024~There is absolutely no warranty for GDB. Type "show warranty" for
17025~ details.
b383017d 17026~This GDB was configured as
922fbb7b
AC
17027 "--host=sparc-sun-solaris2.5.1 --target=ppc-eabi".
17028^done
17029(@value{GDBP})
17030@end smallexample
17031
17032@subheading The @code{-interpreter-exec} Command
17033@findex -interpreter-exec
17034
17035@subheading Synopsis
17036
17037@smallexample
17038-interpreter-exec @var{interpreter} @var{command}
17039@end smallexample
17040
17041Execute the specified @var{command} in the given @var{interpreter}.
17042
17043@subheading @value{GDBN} Command
17044
17045The corresponding @value{GDBN} command is @samp{interpreter-exec}.
17046
17047@subheading Example
17048
17049@smallexample
17050(@value{GDBP})
17051-interpreter-exec console "break main"
17052&"During symbol reading, couldn't parse type; debugger out of date?.\n"
17053&"During symbol reading, bad structure-type format.\n"
17054~"Breakpoint 1 at 0x8074fc6: file ../../src/gdb/main.c, line 743.\n"
17055^done
17056(@value{GDBP})
17057@end smallexample
17058
17059@ignore
17060@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
17061@node GDB/MI Kod Commands
17062@section @sc{gdb/mi} Kod Commands
17063
17064The Kod commands are not implemented.
17065
17066@c @subheading -kod-info
17067
17068@c @subheading -kod-list
17069
17070@c @subheading -kod-list-object-types
17071
17072@c @subheading -kod-show
17073
17074@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
17075@node GDB/MI Memory Overlay Commands
17076@section @sc{gdb/mi} Memory Overlay Commands
17077
17078The memory overlay commands are not implemented.
17079
17080@c @subheading -overlay-auto
17081
17082@c @subheading -overlay-list-mapping-state
17083
17084@c @subheading -overlay-list-overlays
17085
17086@c @subheading -overlay-map
17087
17088@c @subheading -overlay-off
17089
17090@c @subheading -overlay-on
17091
17092@c @subheading -overlay-unmap
17093
17094@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
17095@node GDB/MI Signal Handling Commands
17096@section @sc{gdb/mi} Signal Handling Commands
17097
17098Signal handling commands are not implemented.
17099
17100@c @subheading -signal-handle
17101
17102@c @subheading -signal-list-handle-actions
17103
17104@c @subheading -signal-list-signal-types
17105@end ignore
17106
17107
17108@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
17109@node GDB/MI Stack Manipulation
17110@section @sc{gdb/mi} Stack Manipulation Commands
17111
17112
17113@subheading The @code{-stack-info-frame} Command
17114@findex -stack-info-frame
17115
17116@subsubheading Synopsis
17117
17118@smallexample
17119 -stack-info-frame
17120@end smallexample
17121
17122Get info on the current frame.
17123
17124@subsubheading @value{GDBN} Command
17125
17126The corresponding @value{GDBN} command is @samp{info frame} or @samp{frame}
17127(without arguments).
17128
17129@subsubheading Example
17130N.A.
17131
17132@subheading The @code{-stack-info-depth} Command
17133@findex -stack-info-depth
17134
17135@subsubheading Synopsis
17136
17137@smallexample
17138 -stack-info-depth [ @var{max-depth} ]
17139@end smallexample
17140
17141Return the depth of the stack. If the integer argument @var{max-depth}
17142is specified, do not count beyond @var{max-depth} frames.
17143
17144@subsubheading @value{GDBN} Command
17145
17146There's no equivalent @value{GDBN} command.
17147
17148@subsubheading Example
17149
17150For a stack with frame levels 0 through 11:
17151
17152@smallexample
17153(@value{GDBP})
17154-stack-info-depth
17155^done,depth="12"
17156(@value{GDBP})
17157-stack-info-depth 4
17158^done,depth="4"
17159(@value{GDBP})
17160-stack-info-depth 12
17161^done,depth="12"
17162(@value{GDBP})
17163-stack-info-depth 11
17164^done,depth="11"
17165(@value{GDBP})
17166-stack-info-depth 13
17167^done,depth="12"
17168(@value{GDBP})
17169@end smallexample
17170
17171@subheading The @code{-stack-list-arguments} Command
17172@findex -stack-list-arguments
17173
17174@subsubheading Synopsis
17175
17176@smallexample
17177 -stack-list-arguments @var{show-values}
17178 [ @var{low-frame} @var{high-frame} ]
17179@end smallexample
17180
17181Display a list of the arguments for the frames between @var{low-frame}
17182and @var{high-frame} (inclusive). If @var{low-frame} and
17183@var{high-frame} are not provided, list the arguments for the whole call
17184stack.
17185
17186The @var{show-values} argument must have a value of 0 or 1. A value of
171870 means that only the names of the arguments are listed, a value of 1
17188means that both names and values of the arguments are printed.
17189
17190@subsubheading @value{GDBN} Command
17191
17192@value{GDBN} does not have an equivalent command. @code{gdbtk} has a
17193@samp{gdb_get_args} command which partially overlaps with the
17194functionality of @samp{-stack-list-arguments}.
17195
17196@subsubheading Example
17197
17198@smallexample
17199(@value{GDBP})
17200-stack-list-frames
17201^done,
17202stack=[
17203frame=@{level="0",addr="0x00010734",func="callee4",
17204file="../../../devo/gdb/testsuite/gdb.mi/basics.c",line="8"@},
17205frame=@{level="1",addr="0x0001076c",func="callee3",
17206file="../../../devo/gdb/testsuite/gdb.mi/basics.c",line="17"@},
17207frame=@{level="2",addr="0x0001078c",func="callee2",
17208file="../../../devo/gdb/testsuite/gdb.mi/basics.c",line="22"@},
17209frame=@{level="3",addr="0x000107b4",func="callee1",
17210file="../../../devo/gdb/testsuite/gdb.mi/basics.c",line="27"@},
17211frame=@{level="4",addr="0x000107e0",func="main",
17212file="../../../devo/gdb/testsuite/gdb.mi/basics.c",line="32"@}]
17213(@value{GDBP})
17214-stack-list-arguments 0
17215^done,
17216stack-args=[
17217frame=@{level="0",args=[]@},
17218frame=@{level="1",args=[name="strarg"]@},
17219frame=@{level="2",args=[name="intarg",name="strarg"]@},
17220frame=@{level="3",args=[name="intarg",name="strarg",name="fltarg"]@},
17221frame=@{level="4",args=[]@}]
17222(@value{GDBP})
17223-stack-list-arguments 1
17224^done,
17225stack-args=[
17226frame=@{level="0",args=[]@},
17227frame=@{level="1",
17228 args=[@{name="strarg",value="0x11940 \"A string argument.\""@}]@},
17229frame=@{level="2",args=[
17230@{name="intarg",value="2"@},
17231@{name="strarg",value="0x11940 \"A string argument.\""@}]@},
17232@{frame=@{level="3",args=[
17233@{name="intarg",value="2"@},
17234@{name="strarg",value="0x11940 \"A string argument.\""@},
17235@{name="fltarg",value="3.5"@}]@},
17236frame=@{level="4",args=[]@}]
17237(@value{GDBP})
17238-stack-list-arguments 0 2 2
17239^done,stack-args=[frame=@{level="2",args=[name="intarg",name="strarg"]@}]
17240(@value{GDBP})
17241-stack-list-arguments 1 2 2
17242^done,stack-args=[frame=@{level="2",
17243args=[@{name="intarg",value="2"@},
17244@{name="strarg",value="0x11940 \"A string argument.\""@}]@}]
17245(@value{GDBP})
17246@end smallexample
17247
17248@c @subheading -stack-list-exception-handlers
17249
17250
17251@subheading The @code{-stack-list-frames} Command
17252@findex -stack-list-frames
17253
17254@subsubheading Synopsis
17255
17256@smallexample
17257 -stack-list-frames [ @var{low-frame} @var{high-frame} ]
17258@end smallexample
17259
17260List the frames currently on the stack. For each frame it displays the
17261following info:
17262
17263@table @samp
17264@item @var{level}
17265The frame number, 0 being the topmost frame, i.e. the innermost function.
17266@item @var{addr}
17267The @code{$pc} value for that frame.
17268@item @var{func}
17269Function name.
17270@item @var{file}
17271File name of the source file where the function lives.
17272@item @var{line}
17273Line number corresponding to the @code{$pc}.
17274@end table
17275
17276If invoked without arguments, this command prints a backtrace for the
17277whole stack. If given two integer arguments, it shows the frames whose
17278levels are between the two arguments (inclusive). If the two arguments
17279are equal, it shows the single frame at the corresponding level.
17280
17281@subsubheading @value{GDBN} Command
17282
17283The corresponding @value{GDBN} commands are @samp{backtrace} and @samp{where}.
17284
17285@subsubheading Example
17286
17287Full stack backtrace:
17288
17289@smallexample
17290(@value{GDBP})
17291-stack-list-frames
17292^done,stack=
17293[frame=@{level="0",addr="0x0001076c",func="foo",
17294 file="recursive2.c",line="11"@},
17295frame=@{level="1",addr="0x000107a4",func="foo",
17296 file="recursive2.c",line="14"@},
17297frame=@{level="2",addr="0x000107a4",func="foo",
17298 file="recursive2.c",line="14"@},
17299frame=@{level="3",addr="0x000107a4",func="foo",
17300 file="recursive2.c",line="14"@},
17301frame=@{level="4",addr="0x000107a4",func="foo",
17302 file="recursive2.c",line="14"@},
17303frame=@{level="5",addr="0x000107a4",func="foo",
17304 file="recursive2.c",line="14"@},
17305frame=@{level="6",addr="0x000107a4",func="foo",
17306 file="recursive2.c",line="14"@},
17307frame=@{level="7",addr="0x000107a4",func="foo",
17308 file="recursive2.c",line="14"@},
17309frame=@{level="8",addr="0x000107a4",func="foo",
17310 file="recursive2.c",line="14"@},
17311frame=@{level="9",addr="0x000107a4",func="foo",
17312 file="recursive2.c",line="14"@},
17313frame=@{level="10",addr="0x000107a4",func="foo",
17314 file="recursive2.c",line="14"@},
17315frame=@{level="11",addr="0x00010738",func="main",
17316 file="recursive2.c",line="4"@}]
17317(@value{GDBP})
17318@end smallexample
17319
17320Show frames between @var{low_frame} and @var{high_frame}:
17321
17322@smallexample
17323(@value{GDBP})
17324-stack-list-frames 3 5
17325^done,stack=
17326[frame=@{level="3",addr="0x000107a4",func="foo",
17327 file="recursive2.c",line="14"@},
17328frame=@{level="4",addr="0x000107a4",func="foo",
17329 file="recursive2.c",line="14"@},
17330frame=@{level="5",addr="0x000107a4",func="foo",
17331 file="recursive2.c",line="14"@}]
17332(@value{GDBP})
17333@end smallexample
17334
17335Show a single frame:
17336
17337@smallexample
17338(@value{GDBP})
17339-stack-list-frames 3 3
17340^done,stack=
17341[frame=@{level="3",addr="0x000107a4",func="foo",
17342 file="recursive2.c",line="14"@}]
17343(@value{GDBP})
17344@end smallexample
17345
17346
17347@subheading The @code{-stack-list-locals} Command
17348@findex -stack-list-locals
17349
17350@subsubheading Synopsis
17351
17352@smallexample
17353 -stack-list-locals @var{print-values}
17354@end smallexample
17355
17356Display the local variable names for the current frame. With an
bc8ced35
NR
17357argument of 0 or @code{--no-values}, prints only the names of the variables.
17358With argument of 1 or @code{--all-values}, prints also their values. With
17359argument of 2 or @code{--simple-values}, prints the name, type and value for
17360simple data types and the name and type for arrays, structures and
17361unions. In this last case, the idea is that the user can see the
17362value of simple data types immediately and he can create variable
17363objects for other data types if he wishes to explore their values in
17364more detail.
922fbb7b
AC
17365
17366@subsubheading @value{GDBN} Command
17367
17368@samp{info locals} in @value{GDBN}, @samp{gdb_get_locals} in @code{gdbtk}.
17369
17370@subsubheading Example
17371
17372@smallexample
17373(@value{GDBP})
17374-stack-list-locals 0
17375^done,locals=[name="A",name="B",name="C"]
17376(@value{GDBP})
bc8ced35 17377-stack-list-locals --all-values
922fbb7b 17378^done,locals=[@{name="A",value="1"@},@{name="B",value="2"@},
bc8ced35
NR
17379 @{name="C",value="@{1, 2, 3@}"@}]
17380-stack-list-locals --simple-values
17381^done,locals=[@{name="A",type="int",value="1"@},
17382 @{name="B",type="int",value="2"@},@{name="C",type="int [3]"@}]
922fbb7b
AC
17383(@value{GDBP})
17384@end smallexample
17385
17386
17387@subheading The @code{-stack-select-frame} Command
17388@findex -stack-select-frame
17389
17390@subsubheading Synopsis
17391
17392@smallexample
17393 -stack-select-frame @var{framenum}
17394@end smallexample
17395
17396Change the current frame. Select a different frame @var{framenum} on
17397the stack.
17398
17399@subsubheading @value{GDBN} Command
17400
17401The corresponding @value{GDBN} commands are @samp{frame}, @samp{up},
17402@samp{down}, @samp{select-frame}, @samp{up-silent}, and @samp{down-silent}.
17403
17404@subsubheading Example
17405
17406@smallexample
17407(@value{GDBP})
17408-stack-select-frame 2
17409^done
17410(@value{GDBP})
17411@end smallexample
17412
17413@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
17414@node GDB/MI Symbol Query
17415@section @sc{gdb/mi} Symbol Query Commands
17416
17417
17418@subheading The @code{-symbol-info-address} Command
17419@findex -symbol-info-address
17420
17421@subsubheading Synopsis
17422
17423@smallexample
17424 -symbol-info-address @var{symbol}
17425@end smallexample
17426
17427Describe where @var{symbol} is stored.
17428
17429@subsubheading @value{GDBN} Command
17430
17431The corresponding @value{GDBN} command is @samp{info address}.
17432
17433@subsubheading Example
17434N.A.
17435
17436
17437@subheading The @code{-symbol-info-file} Command
17438@findex -symbol-info-file
17439
17440@subsubheading Synopsis
17441
17442@smallexample
17443 -symbol-info-file
17444@end smallexample
17445
17446Show the file for the symbol.
17447
17448@subsubheading @value{GDBN} Command
17449
17450There's no equivalent @value{GDBN} command. @code{gdbtk} has
17451@samp{gdb_find_file}.
17452
17453@subsubheading Example
17454N.A.
17455
17456
17457@subheading The @code{-symbol-info-function} Command
17458@findex -symbol-info-function
17459
17460@subsubheading Synopsis
17461
17462@smallexample
17463 -symbol-info-function
17464@end smallexample
17465
17466Show which function the symbol lives in.
17467
17468@subsubheading @value{GDBN} Command
17469
17470@samp{gdb_get_function} in @code{gdbtk}.
17471
17472@subsubheading Example
17473N.A.
17474
17475
17476@subheading The @code{-symbol-info-line} Command
17477@findex -symbol-info-line
17478
17479@subsubheading Synopsis
17480
17481@smallexample
17482 -symbol-info-line
17483@end smallexample
17484
17485Show the core addresses of the code for a source line.
17486
17487@subsubheading @value{GDBN} Command
17488
71952f4c 17489The corresponding @value{GDBN} command is @samp{info line}.
922fbb7b
AC
17490@code{gdbtk} has the @samp{gdb_get_line} and @samp{gdb_get_file} commands.
17491
17492@subsubheading Example
17493N.A.
17494
17495
17496@subheading The @code{-symbol-info-symbol} Command
17497@findex -symbol-info-symbol
17498
17499@subsubheading Synopsis
17500
17501@smallexample
17502 -symbol-info-symbol @var{addr}
17503@end smallexample
17504
17505Describe what symbol is at location @var{addr}.
17506
17507@subsubheading @value{GDBN} Command
17508
17509The corresponding @value{GDBN} command is @samp{info symbol}.
17510
17511@subsubheading Example
17512N.A.
17513
17514
17515@subheading The @code{-symbol-list-functions} Command
17516@findex -symbol-list-functions
17517
17518@subsubheading Synopsis
17519
17520@smallexample
17521 -symbol-list-functions
17522@end smallexample
17523
17524List the functions in the executable.
17525
17526@subsubheading @value{GDBN} Command
17527
17528@samp{info functions} in @value{GDBN}, @samp{gdb_listfunc} and
17529@samp{gdb_search} in @code{gdbtk}.
17530
17531@subsubheading Example
17532N.A.
17533
17534
32e7087d
JB
17535@subheading The @code{-symbol-list-lines} Command
17536@findex -symbol-list-lines
17537
17538@subsubheading Synopsis
17539
17540@smallexample
17541 -symbol-list-lines @var{filename}
17542@end smallexample
17543
17544Print the list of lines that contain code and their associated program
17545addresses for the given source filename. The entries are sorted in
17546ascending PC order.
17547
17548@subsubheading @value{GDBN} Command
17549
17550There is no corresponding @value{GDBN} command.
17551
17552@subsubheading Example
17553@smallexample
17554(@value{GDBP})
17555-symbol-list-lines basics.c
54ff5908 17556^done,lines=[@{pc="0x08048554",line="7"@},@{pc="0x0804855a",line="8"@}]
32e7087d
JB
17557(@value{GDBP})
17558@end smallexample
17559
17560
922fbb7b
AC
17561@subheading The @code{-symbol-list-types} Command
17562@findex -symbol-list-types
17563
17564@subsubheading Synopsis
17565
17566@smallexample
17567 -symbol-list-types
17568@end smallexample
17569
17570List all the type names.
17571
17572@subsubheading @value{GDBN} Command
17573
17574The corresponding commands are @samp{info types} in @value{GDBN},
17575@samp{gdb_search} in @code{gdbtk}.
17576
17577@subsubheading Example
17578N.A.
17579
17580
17581@subheading The @code{-symbol-list-variables} Command
17582@findex -symbol-list-variables
17583
17584@subsubheading Synopsis
17585
17586@smallexample
17587 -symbol-list-variables
17588@end smallexample
17589
17590List all the global and static variable names.
17591
17592@subsubheading @value{GDBN} Command
17593
17594@samp{info variables} in @value{GDBN}, @samp{gdb_search} in @code{gdbtk}.
17595
17596@subsubheading Example
17597N.A.
17598
17599
17600@subheading The @code{-symbol-locate} Command
17601@findex -symbol-locate
17602
17603@subsubheading Synopsis
17604
17605@smallexample
17606 -symbol-locate
17607@end smallexample
17608
17609@subsubheading @value{GDBN} Command
17610
17611@samp{gdb_loc} in @code{gdbtk}.
17612
17613@subsubheading Example
17614N.A.
17615
17616
17617@subheading The @code{-symbol-type} Command
17618@findex -symbol-type
17619
17620@subsubheading Synopsis
17621
17622@smallexample
17623 -symbol-type @var{variable}
17624@end smallexample
17625
17626Show type of @var{variable}.
17627
17628@subsubheading @value{GDBN} Command
17629
17630The corresponding @value{GDBN} command is @samp{ptype}, @code{gdbtk} has
17631@samp{gdb_obj_variable}.
17632
17633@subsubheading Example
17634N.A.
17635
17636
17637@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
17638@node GDB/MI Target Manipulation
17639@section @sc{gdb/mi} Target Manipulation Commands
17640
17641
17642@subheading The @code{-target-attach} Command
17643@findex -target-attach
17644
17645@subsubheading Synopsis
17646
17647@smallexample
17648 -target-attach @var{pid} | @var{file}
17649@end smallexample
17650
17651Attach to a process @var{pid} or a file @var{file} outside of @value{GDBN}.
17652
17653@subsubheading @value{GDBN} command
17654
17655The corresponding @value{GDBN} command is @samp{attach}.
17656
17657@subsubheading Example
17658N.A.
17659
17660
17661@subheading The @code{-target-compare-sections} Command
17662@findex -target-compare-sections
17663
17664@subsubheading Synopsis
17665
17666@smallexample
17667 -target-compare-sections [ @var{section} ]
17668@end smallexample
17669
17670Compare data of section @var{section} on target to the exec file.
17671Without the argument, all sections are compared.
17672
17673@subsubheading @value{GDBN} Command
17674
17675The @value{GDBN} equivalent is @samp{compare-sections}.
17676
17677@subsubheading Example
17678N.A.
17679
17680
17681@subheading The @code{-target-detach} Command
17682@findex -target-detach
17683
17684@subsubheading Synopsis
17685
17686@smallexample
17687 -target-detach
17688@end smallexample
17689
17690Disconnect from the remote target. There's no output.
17691
17692@subsubheading @value{GDBN} command
17693
17694The corresponding @value{GDBN} command is @samp{detach}.
17695
17696@subsubheading Example
17697
17698@smallexample
17699(@value{GDBP})
17700-target-detach
17701^done
17702(@value{GDBP})
17703@end smallexample
17704
17705
07f31aa6
DJ
17706@subheading The @code{-target-disconnect} Command
17707@findex -target-disconnect
17708
17709@subsubheading Synopsis
17710
17711@example
17712 -target-disconnect
17713@end example
17714
17715Disconnect from the remote target. There's no output.
17716
17717@subsubheading @value{GDBN} command
17718
17719The corresponding @value{GDBN} command is @samp{disconnect}.
17720
17721@subsubheading Example
17722
17723@smallexample
17724(@value{GDBP})
17725-target-disconnect
17726^done
17727(@value{GDBP})
17728@end smallexample
17729
17730
922fbb7b
AC
17731@subheading The @code{-target-download} Command
17732@findex -target-download
17733
17734@subsubheading Synopsis
17735
17736@smallexample
17737 -target-download
17738@end smallexample
17739
17740Loads the executable onto the remote target.
17741It prints out an update message every half second, which includes the fields:
17742
17743@table @samp
17744@item section
17745The name of the section.
17746@item section-sent
17747The size of what has been sent so far for that section.
17748@item section-size
17749The size of the section.
17750@item total-sent
17751The total size of what was sent so far (the current and the previous sections).
17752@item total-size
17753The size of the overall executable to download.
17754@end table
17755
17756@noindent
17757Each message is sent as status record (@pxref{GDB/MI Output Syntax, ,
17758@sc{gdb/mi} Output Syntax}).
17759
17760In addition, it prints the name and size of the sections, as they are
17761downloaded. These messages include the following fields:
17762
17763@table @samp
17764@item section
17765The name of the section.
17766@item section-size
17767The size of the section.
17768@item total-size
17769The size of the overall executable to download.
17770@end table
17771
17772@noindent
17773At the end, a summary is printed.
17774
17775@subsubheading @value{GDBN} Command
17776
17777The corresponding @value{GDBN} command is @samp{load}.
17778
17779@subsubheading Example
17780
17781Note: each status message appears on a single line. Here the messages
17782have been broken down so that they can fit onto a page.
17783
17784@smallexample
17785(@value{GDBP})
17786-target-download
17787+download,@{section=".text",section-size="6668",total-size="9880"@}
17788+download,@{section=".text",section-sent="512",section-size="6668",
17789total-sent="512",total-size="9880"@}
17790+download,@{section=".text",section-sent="1024",section-size="6668",
17791total-sent="1024",total-size="9880"@}
17792+download,@{section=".text",section-sent="1536",section-size="6668",
17793total-sent="1536",total-size="9880"@}
17794+download,@{section=".text",section-sent="2048",section-size="6668",
17795total-sent="2048",total-size="9880"@}
17796+download,@{section=".text",section-sent="2560",section-size="6668",
17797total-sent="2560",total-size="9880"@}
17798+download,@{section=".text",section-sent="3072",section-size="6668",
17799total-sent="3072",total-size="9880"@}
17800+download,@{section=".text",section-sent="3584",section-size="6668",
17801total-sent="3584",total-size="9880"@}
17802+download,@{section=".text",section-sent="4096",section-size="6668",
17803total-sent="4096",total-size="9880"@}
17804+download,@{section=".text",section-sent="4608",section-size="6668",
17805total-sent="4608",total-size="9880"@}
17806+download,@{section=".text",section-sent="5120",section-size="6668",
17807total-sent="5120",total-size="9880"@}
17808+download,@{section=".text",section-sent="5632",section-size="6668",
17809total-sent="5632",total-size="9880"@}
17810+download,@{section=".text",section-sent="6144",section-size="6668",
17811total-sent="6144",total-size="9880"@}
17812+download,@{section=".text",section-sent="6656",section-size="6668",
17813total-sent="6656",total-size="9880"@}
17814+download,@{section=".init",section-size="28",total-size="9880"@}
17815+download,@{section=".fini",section-size="28",total-size="9880"@}
17816+download,@{section=".data",section-size="3156",total-size="9880"@}
17817+download,@{section=".data",section-sent="512",section-size="3156",
17818total-sent="7236",total-size="9880"@}
17819+download,@{section=".data",section-sent="1024",section-size="3156",
17820total-sent="7748",total-size="9880"@}
17821+download,@{section=".data",section-sent="1536",section-size="3156",
17822total-sent="8260",total-size="9880"@}
17823+download,@{section=".data",section-sent="2048",section-size="3156",
17824total-sent="8772",total-size="9880"@}
17825+download,@{section=".data",section-sent="2560",section-size="3156",
17826total-sent="9284",total-size="9880"@}
17827+download,@{section=".data",section-sent="3072",section-size="3156",
17828total-sent="9796",total-size="9880"@}
17829^done,address="0x10004",load-size="9880",transfer-rate="6586",
17830write-rate="429"
17831(@value{GDBP})
17832@end smallexample
17833
17834
17835@subheading The @code{-target-exec-status} Command
17836@findex -target-exec-status
17837
17838@subsubheading Synopsis
17839
17840@smallexample
17841 -target-exec-status
17842@end smallexample
17843
17844Provide information on the state of the target (whether it is running or
17845not, for instance).
17846
17847@subsubheading @value{GDBN} Command
17848
17849There's no equivalent @value{GDBN} command.
17850
17851@subsubheading Example
17852N.A.
17853
17854
17855@subheading The @code{-target-list-available-targets} Command
17856@findex -target-list-available-targets
17857
17858@subsubheading Synopsis
17859
17860@smallexample
17861 -target-list-available-targets
17862@end smallexample
17863
17864List the possible targets to connect to.
17865
17866@subsubheading @value{GDBN} Command
17867
17868The corresponding @value{GDBN} command is @samp{help target}.
17869
17870@subsubheading Example
17871N.A.
17872
17873
17874@subheading The @code{-target-list-current-targets} Command
17875@findex -target-list-current-targets
17876
17877@subsubheading Synopsis
17878
17879@smallexample
17880 -target-list-current-targets
17881@end smallexample
17882
17883Describe the current target.
17884
17885@subsubheading @value{GDBN} Command
17886
17887The corresponding information is printed by @samp{info file} (among
17888other things).
17889
17890@subsubheading Example
17891N.A.
17892
17893
17894@subheading The @code{-target-list-parameters} Command
17895@findex -target-list-parameters
17896
17897@subsubheading Synopsis
17898
17899@smallexample
17900 -target-list-parameters
17901@end smallexample
17902
17903@c ????
17904
17905@subsubheading @value{GDBN} Command
17906
17907No equivalent.
17908
17909@subsubheading Example
17910N.A.
17911
17912
17913@subheading The @code{-target-select} Command
17914@findex -target-select
17915
17916@subsubheading Synopsis
17917
17918@smallexample
17919 -target-select @var{type} @var{parameters @dots{}}
17920@end smallexample
17921
17922Connect @value{GDBN} to the remote target. This command takes two args:
17923
17924@table @samp
17925@item @var{type}
17926The type of target, for instance @samp{async}, @samp{remote}, etc.
17927@item @var{parameters}
17928Device names, host names and the like. @xref{Target Commands, ,
17929Commands for managing targets}, for more details.
17930@end table
17931
17932The output is a connection notification, followed by the address at
17933which the target program is, in the following form:
17934
17935@smallexample
17936^connected,addr="@var{address}",func="@var{function name}",
17937 args=[@var{arg list}]
17938@end smallexample
17939
17940@subsubheading @value{GDBN} Command
17941
17942The corresponding @value{GDBN} command is @samp{target}.
17943
17944@subsubheading Example
17945
17946@smallexample
17947(@value{GDBP})
17948-target-select async /dev/ttya
17949^connected,addr="0xfe00a300",func="??",args=[]
17950(@value{GDBP})
17951@end smallexample
17952
17953@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
17954@node GDB/MI Thread Commands
17955@section @sc{gdb/mi} Thread Commands
17956
17957
17958@subheading The @code{-thread-info} Command
17959@findex -thread-info
17960
17961@subsubheading Synopsis
17962
17963@smallexample
17964 -thread-info
17965@end smallexample
17966
17967@subsubheading @value{GDBN} command
17968
17969No equivalent.
17970
17971@subsubheading Example
17972N.A.
17973
17974
17975@subheading The @code{-thread-list-all-threads} Command
17976@findex -thread-list-all-threads
17977
17978@subsubheading Synopsis
17979
17980@smallexample
17981 -thread-list-all-threads
17982@end smallexample
17983
17984@subsubheading @value{GDBN} Command
17985
17986The equivalent @value{GDBN} command is @samp{info threads}.
17987
17988@subsubheading Example
17989N.A.
17990
17991
17992@subheading The @code{-thread-list-ids} Command
17993@findex -thread-list-ids
17994
17995@subsubheading Synopsis
17996
17997@smallexample
17998 -thread-list-ids
17999@end smallexample
18000
18001Produces a list of the currently known @value{GDBN} thread ids. At the
18002end of the list it also prints the total number of such threads.
18003
18004@subsubheading @value{GDBN} Command
18005
18006Part of @samp{info threads} supplies the same information.
18007
18008@subsubheading Example
18009
18010No threads present, besides the main process:
18011
18012@smallexample
18013(@value{GDBP})
18014-thread-list-ids
18015^done,thread-ids=@{@},number-of-threads="0"
18016(@value{GDBP})
18017@end smallexample
18018
18019
18020Several threads:
18021
18022@smallexample
18023(@value{GDBP})
18024-thread-list-ids
18025^done,thread-ids=@{thread-id="3",thread-id="2",thread-id="1"@},
18026number-of-threads="3"
18027(@value{GDBP})
18028@end smallexample
18029
18030
18031@subheading The @code{-thread-select} Command
18032@findex -thread-select
18033
18034@subsubheading Synopsis
18035
18036@smallexample
18037 -thread-select @var{threadnum}
18038@end smallexample
18039
18040Make @var{threadnum} the current thread. It prints the number of the new
18041current thread, and the topmost frame for that thread.
18042
18043@subsubheading @value{GDBN} Command
18044
18045The corresponding @value{GDBN} command is @samp{thread}.
18046
18047@subsubheading Example
18048
18049@smallexample
18050(@value{GDBP})
18051-exec-next
18052^running
18053(@value{GDBP})
18054*stopped,reason="end-stepping-range",thread-id="2",line="187",
18055file="../../../devo/gdb/testsuite/gdb.threads/linux-dp.c"
18056(@value{GDBP})
18057-thread-list-ids
18058^done,
18059thread-ids=@{thread-id="3",thread-id="2",thread-id="1"@},
18060number-of-threads="3"
18061(@value{GDBP})
18062-thread-select 3
18063^done,new-thread-id="3",
18064frame=@{level="0",func="vprintf",
18065args=[@{name="format",value="0x8048e9c \"%*s%c %d %c\\n\""@},
18066@{name="arg",value="0x2"@}],file="vprintf.c",line="31"@}
18067(@value{GDBP})
18068@end smallexample
18069
18070@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
18071@node GDB/MI Tracepoint Commands
18072@section @sc{gdb/mi} Tracepoint Commands
18073
18074The tracepoint commands are not yet implemented.
18075
18076@c @subheading -trace-actions
18077
18078@c @subheading -trace-delete
18079
18080@c @subheading -trace-disable
18081
18082@c @subheading -trace-dump
18083
18084@c @subheading -trace-enable
18085
18086@c @subheading -trace-exists
18087
18088@c @subheading -trace-find
18089
18090@c @subheading -trace-frame-number
18091
18092@c @subheading -trace-info
18093
18094@c @subheading -trace-insert
18095
18096@c @subheading -trace-list
18097
18098@c @subheading -trace-pass-count
18099
18100@c @subheading -trace-save
18101
18102@c @subheading -trace-start
18103
18104@c @subheading -trace-stop
18105
18106
18107@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
18108@node GDB/MI Variable Objects
18109@section @sc{gdb/mi} Variable Objects
18110
18111
18112@subheading Motivation for Variable Objects in @sc{gdb/mi}
18113
18114For the implementation of a variable debugger window (locals, watched
18115expressions, etc.), we are proposing the adaptation of the existing code
18116used by @code{Insight}.
18117
18118The two main reasons for that are:
18119
18120@enumerate 1
18121@item
18122It has been proven in practice (it is already on its second generation).
18123
18124@item
18125It will shorten development time (needless to say how important it is
18126now).
18127@end enumerate
18128
18129The original interface was designed to be used by Tcl code, so it was
18130slightly changed so it could be used through @sc{gdb/mi}. This section
18131describes the @sc{gdb/mi} operations that will be available and gives some
18132hints about their use.
18133
18134@emph{Note}: In addition to the set of operations described here, we
18135expect the @sc{gui} implementation of a variable window to require, at
18136least, the following operations:
18137
18138@itemize @bullet
18139@item @code{-gdb-show} @code{output-radix}
18140@item @code{-stack-list-arguments}
18141@item @code{-stack-list-locals}
18142@item @code{-stack-select-frame}
18143@end itemize
18144
18145@subheading Introduction to Variable Objects in @sc{gdb/mi}
18146
18147@cindex variable objects in @sc{gdb/mi}
18148The basic idea behind variable objects is the creation of a named object
18149to represent a variable, an expression, a memory location or even a CPU
18150register. For each object created, a set of operations is available for
18151examining or changing its properties.
18152
18153Furthermore, complex data types, such as C structures, are represented
18154in a tree format. For instance, the @code{struct} type variable is the
18155root and the children will represent the struct members. If a child
18156is itself of a complex type, it will also have children of its own.
18157Appropriate language differences are handled for C, C@t{++} and Java.
18158
18159When returning the actual values of the objects, this facility allows
18160for the individual selection of the display format used in the result
18161creation. It can be chosen among: binary, decimal, hexadecimal, octal
18162and natural. Natural refers to a default format automatically
18163chosen based on the variable type (like decimal for an @code{int}, hex
18164for pointers, etc.).
18165
18166The following is the complete set of @sc{gdb/mi} operations defined to
18167access this functionality:
18168
18169@multitable @columnfractions .4 .6
18170@item @strong{Operation}
18171@tab @strong{Description}
18172
18173@item @code{-var-create}
18174@tab create a variable object
18175@item @code{-var-delete}
18176@tab delete the variable object and its children
18177@item @code{-var-set-format}
18178@tab set the display format of this variable
18179@item @code{-var-show-format}
18180@tab show the display format of this variable
18181@item @code{-var-info-num-children}
18182@tab tells how many children this object has
18183@item @code{-var-list-children}
18184@tab return a list of the object's children
18185@item @code{-var-info-type}
18186@tab show the type of this variable object
18187@item @code{-var-info-expression}
18188@tab print what this variable object represents
18189@item @code{-var-show-attributes}
18190@tab is this variable editable? does it exist here?
18191@item @code{-var-evaluate-expression}
18192@tab get the value of this variable
18193@item @code{-var-assign}
18194@tab set the value of this variable
18195@item @code{-var-update}
18196@tab update the variable and its children
18197@end multitable
18198
18199In the next subsection we describe each operation in detail and suggest
18200how it can be used.
18201
18202@subheading Description And Use of Operations on Variable Objects
18203
18204@subheading The @code{-var-create} Command
18205@findex -var-create
18206
18207@subsubheading Synopsis
18208
18209@smallexample
18210 -var-create @{@var{name} | "-"@}
18211 @{@var{frame-addr} | "*"@} @var{expression}
18212@end smallexample
18213
18214This operation creates a variable object, which allows the monitoring of
18215a variable, the result of an expression, a memory cell or a CPU
18216register.
18217
18218The @var{name} parameter is the string by which the object can be
18219referenced. It must be unique. If @samp{-} is specified, the varobj
18220system will generate a string ``varNNNNNN'' automatically. It will be
18221unique provided that one does not specify @var{name} on that format.
18222The command fails if a duplicate name is found.
18223
18224The frame under which the expression should be evaluated can be
18225specified by @var{frame-addr}. A @samp{*} indicates that the current
18226frame should be used.
18227
18228@var{expression} is any expression valid on the current language set (must not
18229begin with a @samp{*}), or one of the following:
18230
18231@itemize @bullet
18232@item
18233@samp{*@var{addr}}, where @var{addr} is the address of a memory cell
18234
18235@item
18236@samp{*@var{addr}-@var{addr}} --- a memory address range (TBD)
18237
18238@item
18239@samp{$@var{regname}} --- a CPU register name
18240@end itemize
18241
18242@subsubheading Result
18243
18244This operation returns the name, number of children and the type of the
18245object created. Type is returned as a string as the ones generated by
18246the @value{GDBN} CLI:
18247
18248@smallexample
18249 name="@var{name}",numchild="N",type="@var{type}"
18250@end smallexample
18251
18252
18253@subheading The @code{-var-delete} Command
18254@findex -var-delete
18255
18256@subsubheading Synopsis
18257
18258@smallexample
18259 -var-delete @var{name}
18260@end smallexample
18261
18262Deletes a previously created variable object and all of its children.
18263
18264Returns an error if the object @var{name} is not found.
18265
18266
18267@subheading The @code{-var-set-format} Command
18268@findex -var-set-format
18269
18270@subsubheading Synopsis
18271
18272@smallexample
18273 -var-set-format @var{name} @var{format-spec}
18274@end smallexample
18275
18276Sets the output format for the value of the object @var{name} to be
18277@var{format-spec}.
18278
18279The syntax for the @var{format-spec} is as follows:
18280
18281@smallexample
18282 @var{format-spec} @expansion{}
18283 @{binary | decimal | hexadecimal | octal | natural@}
18284@end smallexample
18285
18286
18287@subheading The @code{-var-show-format} Command
18288@findex -var-show-format
18289
18290@subsubheading Synopsis
18291
18292@smallexample
18293 -var-show-format @var{name}
18294@end smallexample
18295
18296Returns the format used to display the value of the object @var{name}.
18297
18298@smallexample
18299 @var{format} @expansion{}
18300 @var{format-spec}
18301@end smallexample
18302
18303
18304@subheading The @code{-var-info-num-children} Command
18305@findex -var-info-num-children
18306
18307@subsubheading Synopsis
18308
18309@smallexample
18310 -var-info-num-children @var{name}
18311@end smallexample
18312
18313Returns the number of children of a variable object @var{name}:
18314
18315@smallexample
18316 numchild=@var{n}
18317@end smallexample
18318
18319
18320@subheading The @code{-var-list-children} Command
18321@findex -var-list-children
18322
18323@subsubheading Synopsis
18324
18325@smallexample
bc8ced35 18326 -var-list-children [@var{print-values}] @var{name}
922fbb7b
AC
18327@end smallexample
18328
bc8ced35
NR
18329Returns a list of the children of the specified variable object. With
18330just the variable object name as an argument or with an optional
18331preceding argument of 0 or @code{--no-values}, prints only the names of the
18332variables. With an optional preceding argument of 1 or @code{--all-values},
18333also prints their values.
18334
18335@subsubheading Example
922fbb7b
AC
18336
18337@smallexample
bc8ced35
NR
18338(@value{GDBP})
18339 -var-list-children n
922fbb7b
AC
18340 numchild=@var{n},children=[@{name=@var{name},
18341 numchild=@var{n},type=@var{type}@},@r{(repeats N times)}]
bc8ced35
NR
18342(@value{GDBP})
18343 -var-list-children --all-values n
18344 numchild=@var{n},children=[@{name=@var{name},
18345 numchild=@var{n},value=@var{value},type=@var{type}@},@r{(repeats N times)}]
922fbb7b
AC
18346@end smallexample
18347
18348
18349@subheading The @code{-var-info-type} Command
18350@findex -var-info-type
18351
18352@subsubheading Synopsis
18353
18354@smallexample
18355 -var-info-type @var{name}
18356@end smallexample
18357
18358Returns the type of the specified variable @var{name}. The type is
18359returned as a string in the same format as it is output by the
18360@value{GDBN} CLI:
18361
18362@smallexample
18363 type=@var{typename}
18364@end smallexample
18365
18366
18367@subheading The @code{-var-info-expression} Command
18368@findex -var-info-expression
18369
18370@subsubheading Synopsis
18371
18372@smallexample
18373 -var-info-expression @var{name}
18374@end smallexample
18375
18376Returns what is represented by the variable object @var{name}:
18377
18378@smallexample
18379 lang=@var{lang-spec},exp=@var{expression}
18380@end smallexample
18381
18382@noindent
18383where @var{lang-spec} is @code{@{"C" | "C++" | "Java"@}}.
18384
18385@subheading The @code{-var-show-attributes} Command
18386@findex -var-show-attributes
18387
18388@subsubheading Synopsis
18389
18390@smallexample
18391 -var-show-attributes @var{name}
18392@end smallexample
18393
18394List attributes of the specified variable object @var{name}:
18395
18396@smallexample
18397 status=@var{attr} [ ( ,@var{attr} )* ]
18398@end smallexample
18399
18400@noindent
18401where @var{attr} is @code{@{ @{ editable | noneditable @} | TBD @}}.
18402
18403@subheading The @code{-var-evaluate-expression} Command
18404@findex -var-evaluate-expression
18405
18406@subsubheading Synopsis
18407
18408@smallexample
18409 -var-evaluate-expression @var{name}
18410@end smallexample
18411
18412Evaluates the expression that is represented by the specified variable
18413object and returns its value as a string in the current format specified
18414for the object:
18415
18416@smallexample
18417 value=@var{value}
18418@end smallexample
18419
18420Note that one must invoke @code{-var-list-children} for a variable
18421before the value of a child variable can be evaluated.
18422
18423@subheading The @code{-var-assign} Command
18424@findex -var-assign
18425
18426@subsubheading Synopsis
18427
18428@smallexample
18429 -var-assign @var{name} @var{expression}
18430@end smallexample
18431
18432Assigns the value of @var{expression} to the variable object specified
18433by @var{name}. The object must be @samp{editable}. If the variable's
b383017d 18434value is altered by the assign, the variable will show up in any
922fbb7b
AC
18435subsequent @code{-var-update} list.
18436
18437@subsubheading Example
18438
18439@smallexample
18440(@value{GDBP})
18441-var-assign var1 3
18442^done,value="3"
18443(@value{GDBP})
18444-var-update *
18445^done,changelist=[@{name="var1",in_scope="true",type_changed="false"@}]
18446(@value{GDBP})
18447@end smallexample
18448
18449@subheading The @code{-var-update} Command
18450@findex -var-update
18451
18452@subsubheading Synopsis
18453
18454@smallexample
18455 -var-update @{@var{name} | "*"@}
18456@end smallexample
18457
18458Update the value of the variable object @var{name} by evaluating its
18459expression after fetching all the new values from memory or registers.
18460A @samp{*} causes all existing variable objects to be updated.
18461
18462
18463@node Annotations
18464@chapter @value{GDBN} Annotations
18465
086432e2
AC
18466This chapter describes annotations in @value{GDBN}. Annotations were
18467designed to interface @value{GDBN} to graphical user interfaces or other
18468similar programs which want to interact with @value{GDBN} at a
922fbb7b
AC
18469relatively high level.
18470
086432e2
AC
18471The annotation mechanism has largely been superseeded by @sc{gdb/mi}
18472(@pxref{GDB/MI}).
18473
922fbb7b
AC
18474@ignore
18475This is Edition @value{EDITION}, @value{DATE}.
18476@end ignore
18477
18478@menu
18479* Annotations Overview:: What annotations are; the general syntax.
18480* Server Prefix:: Issuing a command without affecting user state.
922fbb7b
AC
18481* Prompting:: Annotations marking @value{GDBN}'s need for input.
18482* Errors:: Annotations for error messages.
922fbb7b
AC
18483* Invalidation:: Some annotations describe things now invalid.
18484* Annotations for Running::
18485 Whether the program is running, how it stopped, etc.
18486* Source Annotations:: Annotations describing source code.
922fbb7b
AC
18487@end menu
18488
18489@node Annotations Overview
18490@section What is an Annotation?
18491@cindex annotations
18492
922fbb7b
AC
18493Annotations start with a newline character, two @samp{control-z}
18494characters, and the name of the annotation. If there is no additional
18495information associated with this annotation, the name of the annotation
18496is followed immediately by a newline. If there is additional
18497information, the name of the annotation is followed by a space, the
18498additional information, and a newline. The additional information
18499cannot contain newline characters.
18500
18501Any output not beginning with a newline and two @samp{control-z}
18502characters denotes literal output from @value{GDBN}. Currently there is
18503no need for @value{GDBN} to output a newline followed by two
18504@samp{control-z} characters, but if there was such a need, the
18505annotations could be extended with an @samp{escape} annotation which
18506means those three characters as output.
18507
086432e2
AC
18508The annotation @var{level}, which is specified using the
18509@option{--annotate} command line option (@pxref{Mode Options}), controls
18510how much information @value{GDBN} prints together with its prompt,
18511values of expressions, source lines, and other types of output. Level 0
18512is for no anntations, level 1 is for use when @value{GDBN} is run as a
18513subprocess of @sc{gnu} Emacs, level 3 is the maximum annotation suitable
18514for programs that control @value{GDBN}, and level 2 annotations have
18515been made obsolete (@pxref{Limitations, , Limitations of the Annotation
18516Interface, annotate, GDB's Obsolete Annotations}). This chapter
18517describes level 3 annotations.
18518
922fbb7b
AC
18519A simple example of starting up @value{GDBN} with annotations is:
18520
18521@smallexample
086432e2
AC
18522$ @kbd{gdb --annotate=3}
18523GNU gdb 6.0
18524Copyright 2003 Free Software Foundation, Inc.
922fbb7b
AC
18525GDB is free software, covered by the GNU General Public License,
18526and you are welcome to change it and/or distribute copies of it
18527under certain conditions.
18528Type "show copying" to see the conditions.
18529There is absolutely no warranty for GDB. Type "show warranty"
18530for details.
086432e2 18531This GDB was configured as "i386-pc-linux-gnu"
922fbb7b
AC
18532
18533^Z^Zpre-prompt
b383017d 18534(gdb)
922fbb7b 18535^Z^Zprompt
086432e2 18536@kbd{quit}
922fbb7b
AC
18537
18538^Z^Zpost-prompt
b383017d 18539$
922fbb7b
AC
18540@end smallexample
18541
18542Here @samp{quit} is input to @value{GDBN}; the rest is output from
18543@value{GDBN}. The three lines beginning @samp{^Z^Z} (where @samp{^Z}
18544denotes a @samp{control-z} character) are annotations; the rest is
18545output from @value{GDBN}.
18546
18547@node Server Prefix
18548@section The Server Prefix
18549@cindex server prefix for annotations
18550
18551To issue a command to @value{GDBN} without affecting certain aspects of
18552the state which is seen by users, prefix it with @samp{server }. This
18553means that this command will not affect the command history, nor will it
18554affect @value{GDBN}'s notion of which command to repeat if @key{RET} is
18555pressed on a line by itself.
18556
18557The server prefix does not affect the recording of values into the value
18558history; to print a value without recording it into the value history,
18559use the @code{output} command instead of the @code{print} command.
18560
922fbb7b
AC
18561@node Prompting
18562@section Annotation for @value{GDBN} Input
18563
18564@cindex annotations for prompts
18565When @value{GDBN} prompts for input, it annotates this fact so it is possible
18566to know when to send output, when the output from a given command is
18567over, etc.
18568
18569Different kinds of input each have a different @dfn{input type}. Each
18570input type has three annotations: a @code{pre-} annotation, which
18571denotes the beginning of any prompt which is being output, a plain
18572annotation, which denotes the end of the prompt, and then a @code{post-}
18573annotation which denotes the end of any echo which may (or may not) be
18574associated with the input. For example, the @code{prompt} input type
18575features the following annotations:
18576
18577@smallexample
18578^Z^Zpre-prompt
18579^Z^Zprompt
18580^Z^Zpost-prompt
18581@end smallexample
18582
18583The input types are
18584
18585@table @code
18586@findex pre-prompt
18587@findex prompt
18588@findex post-prompt
18589@item prompt
18590When @value{GDBN} is prompting for a command (the main @value{GDBN} prompt).
18591
18592@findex pre-commands
18593@findex commands
18594@findex post-commands
18595@item commands
18596When @value{GDBN} prompts for a set of commands, like in the @code{commands}
18597command. The annotations are repeated for each command which is input.
18598
18599@findex pre-overload-choice
18600@findex overload-choice
18601@findex post-overload-choice
18602@item overload-choice
18603When @value{GDBN} wants the user to select between various overloaded functions.
18604
18605@findex pre-query
18606@findex query
18607@findex post-query
18608@item query
18609When @value{GDBN} wants the user to confirm a potentially dangerous operation.
18610
18611@findex pre-prompt-for-continue
18612@findex prompt-for-continue
18613@findex post-prompt-for-continue
18614@item prompt-for-continue
18615When @value{GDBN} is asking the user to press return to continue. Note: Don't
18616expect this to work well; instead use @code{set height 0} to disable
18617prompting. This is because the counting of lines is buggy in the
18618presence of annotations.
18619@end table
18620
18621@node Errors
18622@section Errors
18623@cindex annotations for errors, warnings and interrupts
18624
18625@findex quit
18626@smallexample
18627^Z^Zquit
18628@end smallexample
18629
18630This annotation occurs right before @value{GDBN} responds to an interrupt.
18631
18632@findex error
18633@smallexample
18634^Z^Zerror
18635@end smallexample
18636
18637This annotation occurs right before @value{GDBN} responds to an error.
18638
18639Quit and error annotations indicate that any annotations which @value{GDBN} was
18640in the middle of may end abruptly. For example, if a
18641@code{value-history-begin} annotation is followed by a @code{error}, one
18642cannot expect to receive the matching @code{value-history-end}. One
18643cannot expect not to receive it either, however; an error annotation
18644does not necessarily mean that @value{GDBN} is immediately returning all the way
18645to the top level.
18646
18647@findex error-begin
18648A quit or error annotation may be preceded by
18649
18650@smallexample
18651^Z^Zerror-begin
18652@end smallexample
18653
18654Any output between that and the quit or error annotation is the error
18655message.
18656
18657Warning messages are not yet annotated.
18658@c If we want to change that, need to fix warning(), type_error(),
18659@c range_error(), and possibly other places.
18660
922fbb7b
AC
18661@node Invalidation
18662@section Invalidation Notices
18663
18664@cindex annotations for invalidation messages
18665The following annotations say that certain pieces of state may have
18666changed.
18667
18668@table @code
18669@findex frames-invalid
18670@item ^Z^Zframes-invalid
18671
18672The frames (for example, output from the @code{backtrace} command) may
18673have changed.
18674
18675@findex breakpoints-invalid
18676@item ^Z^Zbreakpoints-invalid
18677
18678The breakpoints may have changed. For example, the user just added or
18679deleted a breakpoint.
18680@end table
18681
18682@node Annotations for Running
18683@section Running the Program
18684@cindex annotations for running programs
18685
18686@findex starting
18687@findex stopping
18688When the program starts executing due to a @value{GDBN} command such as
b383017d 18689@code{step} or @code{continue},
922fbb7b
AC
18690
18691@smallexample
18692^Z^Zstarting
18693@end smallexample
18694
b383017d 18695is output. When the program stops,
922fbb7b
AC
18696
18697@smallexample
18698^Z^Zstopped
18699@end smallexample
18700
18701is output. Before the @code{stopped} annotation, a variety of
18702annotations describe how the program stopped.
18703
18704@table @code
18705@findex exited
18706@item ^Z^Zexited @var{exit-status}
18707The program exited, and @var{exit-status} is the exit status (zero for
18708successful exit, otherwise nonzero).
18709
18710@findex signalled
18711@findex signal-name
18712@findex signal-name-end
18713@findex signal-string
18714@findex signal-string-end
18715@item ^Z^Zsignalled
18716The program exited with a signal. After the @code{^Z^Zsignalled}, the
18717annotation continues:
18718
18719@smallexample
18720@var{intro-text}
18721^Z^Zsignal-name
18722@var{name}
18723^Z^Zsignal-name-end
18724@var{middle-text}
18725^Z^Zsignal-string
18726@var{string}
18727^Z^Zsignal-string-end
18728@var{end-text}
18729@end smallexample
18730
18731@noindent
18732where @var{name} is the name of the signal, such as @code{SIGILL} or
18733@code{SIGSEGV}, and @var{string} is the explanation of the signal, such
18734as @code{Illegal Instruction} or @code{Segmentation fault}.
18735@var{intro-text}, @var{middle-text}, and @var{end-text} are for the
18736user's benefit and have no particular format.
18737
18738@findex signal
18739@item ^Z^Zsignal
18740The syntax of this annotation is just like @code{signalled}, but @value{GDBN} is
18741just saying that the program received the signal, not that it was
18742terminated with it.
18743
18744@findex breakpoint
18745@item ^Z^Zbreakpoint @var{number}
18746The program hit breakpoint number @var{number}.
18747
18748@findex watchpoint
18749@item ^Z^Zwatchpoint @var{number}
18750The program hit watchpoint number @var{number}.
18751@end table
18752
18753@node Source Annotations
18754@section Displaying Source
18755@cindex annotations for source display
18756
18757@findex source
18758The following annotation is used instead of displaying source code:
18759
18760@smallexample
18761^Z^Zsource @var{filename}:@var{line}:@var{character}:@var{middle}:@var{addr}
18762@end smallexample
18763
18764where @var{filename} is an absolute file name indicating which source
18765file, @var{line} is the line number within that file (where 1 is the
18766first line in the file), @var{character} is the character position
18767within the file (where 0 is the first character in the file) (for most
18768debug formats this will necessarily point to the beginning of a line),
18769@var{middle} is @samp{middle} if @var{addr} is in the middle of the
18770line, or @samp{beg} if @var{addr} is at the beginning of the line, and
18771@var{addr} is the address in the target program associated with the
18772source which is being displayed. @var{addr} is in the form @samp{0x}
18773followed by one or more lowercase hex digits (note that this does not
18774depend on the language).
18775
8e04817f
AC
18776@node GDB Bugs
18777@chapter Reporting Bugs in @value{GDBN}
18778@cindex bugs in @value{GDBN}
18779@cindex reporting bugs in @value{GDBN}
c906108c 18780
8e04817f 18781Your bug reports play an essential role in making @value{GDBN} reliable.
c906108c 18782
8e04817f
AC
18783Reporting a bug may help you by bringing a solution to your problem, or it
18784may not. But in any case the principal function of a bug report is to help
18785the entire community by making the next version of @value{GDBN} work better. Bug
18786reports are your contribution to the maintenance of @value{GDBN}.
c906108c 18787
8e04817f
AC
18788In order for a bug report to serve its purpose, you must include the
18789information that enables us to fix the bug.
c4555f82
SC
18790
18791@menu
8e04817f
AC
18792* Bug Criteria:: Have you found a bug?
18793* Bug Reporting:: How to report bugs
c4555f82
SC
18794@end menu
18795
8e04817f
AC
18796@node Bug Criteria
18797@section Have you found a bug?
18798@cindex bug criteria
c4555f82 18799
8e04817f 18800If you are not sure whether you have found a bug, here are some guidelines:
c4555f82
SC
18801
18802@itemize @bullet
8e04817f
AC
18803@cindex fatal signal
18804@cindex debugger crash
18805@cindex crash of debugger
c4555f82 18806@item
8e04817f
AC
18807If the debugger gets a fatal signal, for any input whatever, that is a
18808@value{GDBN} bug. Reliable debuggers never crash.
18809
18810@cindex error on valid input
18811@item
18812If @value{GDBN} produces an error message for valid input, that is a
18813bug. (Note that if you're cross debugging, the problem may also be
18814somewhere in the connection to the target.)
c4555f82 18815
8e04817f 18816@cindex invalid input
c4555f82 18817@item
8e04817f
AC
18818If @value{GDBN} does not produce an error message for invalid input,
18819that is a bug. However, you should note that your idea of
18820``invalid input'' might be our idea of ``an extension'' or ``support
18821for traditional practice''.
18822
18823@item
18824If you are an experienced user of debugging tools, your suggestions
18825for improvement of @value{GDBN} are welcome in any case.
c4555f82
SC
18826@end itemize
18827
8e04817f
AC
18828@node Bug Reporting
18829@section How to report bugs
18830@cindex bug reports
18831@cindex @value{GDBN} bugs, reporting
18832
18833A number of companies and individuals offer support for @sc{gnu} products.
18834If you obtained @value{GDBN} from a support organization, we recommend you
18835contact that organization first.
18836
18837You can find contact information for many support companies and
18838individuals in the file @file{etc/SERVICE} in the @sc{gnu} Emacs
18839distribution.
18840@c should add a web page ref...
18841
129188f6
AC
18842In any event, we also recommend that you submit bug reports for
18843@value{GDBN}. The prefered method is to submit them directly using
18844@uref{http://www.gnu.org/software/gdb/bugs/, @value{GDBN}'s Bugs web
18845page}. Alternatively, the @email{bug-gdb@@gnu.org, e-mail gateway} can
18846be used.
8e04817f
AC
18847
18848@strong{Do not send bug reports to @samp{info-gdb}, or to
18849@samp{help-gdb}, or to any newsgroups.} Most users of @value{GDBN} do
18850not want to receive bug reports. Those that do have arranged to receive
18851@samp{bug-gdb}.
18852
18853The mailing list @samp{bug-gdb} has a newsgroup @samp{gnu.gdb.bug} which
18854serves as a repeater. The mailing list and the newsgroup carry exactly
18855the same messages. Often people think of posting bug reports to the
18856newsgroup instead of mailing them. This appears to work, but it has one
18857problem which can be crucial: a newsgroup posting often lacks a mail
18858path back to the sender. Thus, if we need to ask for more information,
18859we may be unable to reach you. For this reason, it is better to send
18860bug reports to the mailing list.
c4555f82 18861
8e04817f
AC
18862The fundamental principle of reporting bugs usefully is this:
18863@strong{report all the facts}. If you are not sure whether to state a
18864fact or leave it out, state it!
c4555f82 18865
8e04817f
AC
18866Often people omit facts because they think they know what causes the
18867problem and assume that some details do not matter. Thus, you might
18868assume that the name of the variable you use in an example does not matter.
18869Well, probably it does not, but one cannot be sure. Perhaps the bug is a
18870stray memory reference which happens to fetch from the location where that
18871name is stored in memory; perhaps, if the name were different, the contents
18872of that location would fool the debugger into doing the right thing despite
18873the bug. Play it safe and give a specific, complete example. That is the
18874easiest thing for you to do, and the most helpful.
c4555f82 18875
8e04817f
AC
18876Keep in mind that the purpose of a bug report is to enable us to fix the
18877bug. It may be that the bug has been reported previously, but neither
18878you nor we can know that unless your bug report is complete and
18879self-contained.
c4555f82 18880
8e04817f
AC
18881Sometimes people give a few sketchy facts and ask, ``Does this ring a
18882bell?'' Those bug reports are useless, and we urge everyone to
18883@emph{refuse to respond to them} except to chide the sender to report
18884bugs properly.
18885
18886To enable us to fix the bug, you should include all these things:
c4555f82
SC
18887
18888@itemize @bullet
18889@item
8e04817f
AC
18890The version of @value{GDBN}. @value{GDBN} announces it if you start
18891with no arguments; you can also print it at any time using @code{show
18892version}.
c4555f82 18893
8e04817f
AC
18894Without this, we will not know whether there is any point in looking for
18895the bug in the current version of @value{GDBN}.
c4555f82
SC
18896
18897@item
8e04817f
AC
18898The type of machine you are using, and the operating system name and
18899version number.
c4555f82
SC
18900
18901@item
8e04817f
AC
18902What compiler (and its version) was used to compile @value{GDBN}---e.g.
18903``@value{GCC}--2.8.1''.
c4555f82
SC
18904
18905@item
8e04817f
AC
18906What compiler (and its version) was used to compile the program you are
18907debugging---e.g. ``@value{GCC}--2.8.1'', or ``HP92453-01 A.10.32.03 HP
18908C Compiler''. For GCC, you can say @code{gcc --version} to get this
18909information; for other compilers, see the documentation for those
18910compilers.
c4555f82 18911
8e04817f
AC
18912@item
18913The command arguments you gave the compiler to compile your example and
18914observe the bug. For example, did you use @samp{-O}? To guarantee
18915you will not omit something important, list them all. A copy of the
18916Makefile (or the output from make) is sufficient.
c4555f82 18917
8e04817f
AC
18918If we were to try to guess the arguments, we would probably guess wrong
18919and then we might not encounter the bug.
c4555f82 18920
8e04817f
AC
18921@item
18922A complete input script, and all necessary source files, that will
18923reproduce the bug.
c4555f82 18924
8e04817f
AC
18925@item
18926A description of what behavior you observe that you believe is
18927incorrect. For example, ``It gets a fatal signal.''
c4555f82 18928
8e04817f
AC
18929Of course, if the bug is that @value{GDBN} gets a fatal signal, then we
18930will certainly notice it. But if the bug is incorrect output, we might
18931not notice unless it is glaringly wrong. You might as well not give us
18932a chance to make a mistake.
c4555f82 18933
8e04817f
AC
18934Even if the problem you experience is a fatal signal, you should still
18935say so explicitly. Suppose something strange is going on, such as, your
18936copy of @value{GDBN} is out of synch, or you have encountered a bug in
18937the C library on your system. (This has happened!) Your copy might
18938crash and ours would not. If you told us to expect a crash, then when
18939ours fails to crash, we would know that the bug was not happening for
18940us. If you had not told us to expect a crash, then we would not be able
18941to draw any conclusion from our observations.
c4555f82 18942
e0c07bf0
MC
18943@pindex script
18944@cindex recording a session script
18945To collect all this information, you can use a session recording program
18946such as @command{script}, which is available on many Unix systems.
18947Just run your @value{GDBN} session inside @command{script} and then
18948include the @file{typescript} file with your bug report.
18949
18950Another way to record a @value{GDBN} session is to run @value{GDBN}
18951inside Emacs and then save the entire buffer to a file.
18952
8e04817f
AC
18953@item
18954If you wish to suggest changes to the @value{GDBN} source, send us context
18955diffs. If you even discuss something in the @value{GDBN} source, refer to
18956it by context, not by line number.
c4555f82 18957
8e04817f
AC
18958The line numbers in our development sources will not match those in your
18959sources. Your line numbers would convey no useful information to us.
c4555f82 18960
8e04817f 18961@end itemize
c4555f82 18962
8e04817f 18963Here are some things that are not necessary:
c4555f82 18964
8e04817f
AC
18965@itemize @bullet
18966@item
18967A description of the envelope of the bug.
c4555f82 18968
8e04817f
AC
18969Often people who encounter a bug spend a lot of time investigating
18970which changes to the input file will make the bug go away and which
18971changes will not affect it.
c4555f82 18972
8e04817f
AC
18973This is often time consuming and not very useful, because the way we
18974will find the bug is by running a single example under the debugger
18975with breakpoints, not by pure deduction from a series of examples.
18976We recommend that you save your time for something else.
c4555f82 18977
8e04817f
AC
18978Of course, if you can find a simpler example to report @emph{instead}
18979of the original one, that is a convenience for us. Errors in the
18980output will be easier to spot, running under the debugger will take
18981less time, and so on.
c4555f82 18982
8e04817f
AC
18983However, simplification is not vital; if you do not want to do this,
18984report the bug anyway and send us the entire test case you used.
c4555f82 18985
8e04817f
AC
18986@item
18987A patch for the bug.
c4555f82 18988
8e04817f
AC
18989A patch for the bug does help us if it is a good one. But do not omit
18990the necessary information, such as the test case, on the assumption that
18991a patch is all we need. We might see problems with your patch and decide
18992to fix the problem another way, or we might not understand it at all.
c4555f82 18993
8e04817f
AC
18994Sometimes with a program as complicated as @value{GDBN} it is very hard to
18995construct an example that will make the program follow a certain path
18996through the code. If you do not send us the example, we will not be able
18997to construct one, so we will not be able to verify that the bug is fixed.
c4555f82 18998
8e04817f
AC
18999And if we cannot understand what bug you are trying to fix, or why your
19000patch should be an improvement, we will not install it. A test case will
19001help us to understand.
c4555f82 19002
8e04817f
AC
19003@item
19004A guess about what the bug is or what it depends on.
c4555f82 19005
8e04817f
AC
19006Such guesses are usually wrong. Even we cannot guess right about such
19007things without first using the debugger to find the facts.
19008@end itemize
c4555f82 19009
8e04817f
AC
19010@c The readline documentation is distributed with the readline code
19011@c and consists of the two following files:
19012@c rluser.texinfo
19013@c inc-hist.texinfo
19014@c Use -I with makeinfo to point to the appropriate directory,
19015@c environment var TEXINPUTS with TeX.
19016@include rluser.texinfo
19017@include inc-hist.texinfo
c4555f82 19018
c4555f82 19019
8e04817f
AC
19020@node Formatting Documentation
19021@appendix Formatting Documentation
c4555f82 19022
8e04817f
AC
19023@cindex @value{GDBN} reference card
19024@cindex reference card
19025The @value{GDBN} 4 release includes an already-formatted reference card, ready
19026for printing with PostScript or Ghostscript, in the @file{gdb}
19027subdirectory of the main source directory@footnote{In
19028@file{gdb-@value{GDBVN}/gdb/refcard.ps} of the version @value{GDBVN}
19029release.}. If you can use PostScript or Ghostscript with your printer,
19030you can print the reference card immediately with @file{refcard.ps}.
c4555f82 19031
8e04817f
AC
19032The release also includes the source for the reference card. You
19033can format it, using @TeX{}, by typing:
c4555f82 19034
474c8240 19035@smallexample
8e04817f 19036make refcard.dvi
474c8240 19037@end smallexample
c4555f82 19038
8e04817f
AC
19039The @value{GDBN} reference card is designed to print in @dfn{landscape}
19040mode on US ``letter'' size paper;
19041that is, on a sheet 11 inches wide by 8.5 inches
19042high. You will need to specify this form of printing as an option to
19043your @sc{dvi} output program.
c4555f82 19044
8e04817f 19045@cindex documentation
c4555f82 19046
8e04817f
AC
19047All the documentation for @value{GDBN} comes as part of the machine-readable
19048distribution. The documentation is written in Texinfo format, which is
19049a documentation system that uses a single source file to produce both
19050on-line information and a printed manual. You can use one of the Info
19051formatting commands to create the on-line version of the documentation
19052and @TeX{} (or @code{texi2roff}) to typeset the printed version.
c4555f82 19053
8e04817f
AC
19054@value{GDBN} includes an already formatted copy of the on-line Info
19055version of this manual in the @file{gdb} subdirectory. The main Info
19056file is @file{gdb-@value{GDBVN}/gdb/gdb.info}, and it refers to
19057subordinate files matching @samp{gdb.info*} in the same directory. If
19058necessary, you can print out these files, or read them with any editor;
19059but they are easier to read using the @code{info} subsystem in @sc{gnu}
19060Emacs or the standalone @code{info} program, available as part of the
19061@sc{gnu} Texinfo distribution.
c4555f82 19062
8e04817f
AC
19063If you want to format these Info files yourself, you need one of the
19064Info formatting programs, such as @code{texinfo-format-buffer} or
19065@code{makeinfo}.
c4555f82 19066
8e04817f
AC
19067If you have @code{makeinfo} installed, and are in the top level
19068@value{GDBN} source directory (@file{gdb-@value{GDBVN}}, in the case of
19069version @value{GDBVN}), you can make the Info file by typing:
c4555f82 19070
474c8240 19071@smallexample
8e04817f
AC
19072cd gdb
19073make gdb.info
474c8240 19074@end smallexample
c4555f82 19075
8e04817f
AC
19076If you want to typeset and print copies of this manual, you need @TeX{},
19077a program to print its @sc{dvi} output files, and @file{texinfo.tex}, the
19078Texinfo definitions file.
c4555f82 19079
8e04817f
AC
19080@TeX{} is a typesetting program; it does not print files directly, but
19081produces output files called @sc{dvi} files. To print a typeset
19082document, you need a program to print @sc{dvi} files. If your system
19083has @TeX{} installed, chances are it has such a program. The precise
19084command to use depends on your system; @kbd{lpr -d} is common; another
19085(for PostScript devices) is @kbd{dvips}. The @sc{dvi} print command may
19086require a file name without any extension or a @samp{.dvi} extension.
c4555f82 19087
8e04817f
AC
19088@TeX{} also requires a macro definitions file called
19089@file{texinfo.tex}. This file tells @TeX{} how to typeset a document
19090written in Texinfo format. On its own, @TeX{} cannot either read or
19091typeset a Texinfo file. @file{texinfo.tex} is distributed with GDB
19092and is located in the @file{gdb-@var{version-number}/texinfo}
19093directory.
c4555f82 19094
8e04817f
AC
19095If you have @TeX{} and a @sc{dvi} printer program installed, you can
19096typeset and print this manual. First switch to the the @file{gdb}
19097subdirectory of the main source directory (for example, to
19098@file{gdb-@value{GDBVN}/gdb}) and type:
c4555f82 19099
474c8240 19100@smallexample
8e04817f 19101make gdb.dvi
474c8240 19102@end smallexample
c4555f82 19103
8e04817f 19104Then give @file{gdb.dvi} to your @sc{dvi} printing program.
c4555f82 19105
8e04817f
AC
19106@node Installing GDB
19107@appendix Installing @value{GDBN}
19108@cindex configuring @value{GDBN}
19109@cindex installation
94e91d6d 19110@cindex configuring @value{GDBN}, and source tree subdirectories
c4555f82 19111
8e04817f
AC
19112@value{GDBN} comes with a @code{configure} script that automates the process
19113of preparing @value{GDBN} for installation; you can then use @code{make} to
19114build the @code{gdb} program.
19115@iftex
19116@c irrelevant in info file; it's as current as the code it lives with.
19117@footnote{If you have a more recent version of @value{GDBN} than @value{GDBVN},
19118look at the @file{README} file in the sources; we may have improved the
19119installation procedures since publishing this manual.}
19120@end iftex
c4555f82 19121
8e04817f
AC
19122The @value{GDBN} distribution includes all the source code you need for
19123@value{GDBN} in a single directory, whose name is usually composed by
19124appending the version number to @samp{gdb}.
c4555f82 19125
8e04817f
AC
19126For example, the @value{GDBN} version @value{GDBVN} distribution is in the
19127@file{gdb-@value{GDBVN}} directory. That directory contains:
c4555f82 19128
8e04817f
AC
19129@table @code
19130@item gdb-@value{GDBVN}/configure @r{(and supporting files)}
19131script for configuring @value{GDBN} and all its supporting libraries
c4555f82 19132
8e04817f
AC
19133@item gdb-@value{GDBVN}/gdb
19134the source specific to @value{GDBN} itself
c4555f82 19135
8e04817f
AC
19136@item gdb-@value{GDBVN}/bfd
19137source for the Binary File Descriptor library
c906108c 19138
8e04817f
AC
19139@item gdb-@value{GDBVN}/include
19140@sc{gnu} include files
c906108c 19141
8e04817f
AC
19142@item gdb-@value{GDBVN}/libiberty
19143source for the @samp{-liberty} free software library
c906108c 19144
8e04817f
AC
19145@item gdb-@value{GDBVN}/opcodes
19146source for the library of opcode tables and disassemblers
c906108c 19147
8e04817f
AC
19148@item gdb-@value{GDBVN}/readline
19149source for the @sc{gnu} command-line interface
c906108c 19150
8e04817f
AC
19151@item gdb-@value{GDBVN}/glob
19152source for the @sc{gnu} filename pattern-matching subroutine
c906108c 19153
8e04817f
AC
19154@item gdb-@value{GDBVN}/mmalloc
19155source for the @sc{gnu} memory-mapped malloc package
19156@end table
c906108c 19157
8e04817f
AC
19158The simplest way to configure and build @value{GDBN} is to run @code{configure}
19159from the @file{gdb-@var{version-number}} source directory, which in
19160this example is the @file{gdb-@value{GDBVN}} directory.
c906108c 19161
8e04817f
AC
19162First switch to the @file{gdb-@var{version-number}} source directory
19163if you are not already in it; then run @code{configure}. Pass the
19164identifier for the platform on which @value{GDBN} will run as an
19165argument.
c906108c 19166
8e04817f 19167For example:
c906108c 19168
474c8240 19169@smallexample
8e04817f
AC
19170cd gdb-@value{GDBVN}
19171./configure @var{host}
19172make
474c8240 19173@end smallexample
c906108c 19174
8e04817f
AC
19175@noindent
19176where @var{host} is an identifier such as @samp{sun4} or
19177@samp{decstation}, that identifies the platform where @value{GDBN} will run.
19178(You can often leave off @var{host}; @code{configure} tries to guess the
19179correct value by examining your system.)
c906108c 19180
8e04817f
AC
19181Running @samp{configure @var{host}} and then running @code{make} builds the
19182@file{bfd}, @file{readline}, @file{mmalloc}, and @file{libiberty}
19183libraries, then @code{gdb} itself. The configured source files, and the
19184binaries, are left in the corresponding source directories.
c906108c 19185
8e04817f
AC
19186@need 750
19187@code{configure} is a Bourne-shell (@code{/bin/sh}) script; if your
19188system does not recognize this automatically when you run a different
19189shell, you may need to run @code{sh} on it explicitly:
c906108c 19190
474c8240 19191@smallexample
8e04817f 19192sh configure @var{host}
474c8240 19193@end smallexample
c906108c 19194
8e04817f
AC
19195If you run @code{configure} from a directory that contains source
19196directories for multiple libraries or programs, such as the
19197@file{gdb-@value{GDBVN}} source directory for version @value{GDBVN}, @code{configure}
19198creates configuration files for every directory level underneath (unless
19199you tell it not to, with the @samp{--norecursion} option).
19200
94e91d6d
MC
19201You should run the @code{configure} script from the top directory in the
19202source tree, the @file{gdb-@var{version-number}} directory. If you run
19203@code{configure} from one of the subdirectories, you will configure only
19204that subdirectory. That is usually not what you want. In particular,
19205if you run the first @code{configure} from the @file{gdb} subdirectory
19206of the @file{gdb-@var{version-number}} directory, you will omit the
19207configuration of @file{bfd}, @file{readline}, and other sibling
19208directories of the @file{gdb} subdirectory. This leads to build errors
19209about missing include files such as @file{bfd/bfd.h}.
c906108c 19210
8e04817f
AC
19211You can install @code{@value{GDBP}} anywhere; it has no hardwired paths.
19212However, you should make sure that the shell on your path (named by
19213the @samp{SHELL} environment variable) is publicly readable. Remember
19214that @value{GDBN} uses the shell to start your program---some systems refuse to
19215let @value{GDBN} debug child processes whose programs are not readable.
c906108c 19216
8e04817f
AC
19217@menu
19218* Separate Objdir:: Compiling @value{GDBN} in another directory
19219* Config Names:: Specifying names for hosts and targets
19220* Configure Options:: Summary of options for configure
19221@end menu
c906108c 19222
8e04817f
AC
19223@node Separate Objdir
19224@section Compiling @value{GDBN} in another directory
c906108c 19225
8e04817f
AC
19226If you want to run @value{GDBN} versions for several host or target machines,
19227you need a different @code{gdb} compiled for each combination of
19228host and target. @code{configure} is designed to make this easy by
19229allowing you to generate each configuration in a separate subdirectory,
19230rather than in the source directory. If your @code{make} program
19231handles the @samp{VPATH} feature (@sc{gnu} @code{make} does), running
19232@code{make} in each of these directories builds the @code{gdb}
19233program specified there.
c906108c 19234
8e04817f
AC
19235To build @code{gdb} in a separate directory, run @code{configure}
19236with the @samp{--srcdir} option to specify where to find the source.
19237(You also need to specify a path to find @code{configure}
19238itself from your working directory. If the path to @code{configure}
19239would be the same as the argument to @samp{--srcdir}, you can leave out
19240the @samp{--srcdir} option; it is assumed.)
c906108c 19241
8e04817f
AC
19242For example, with version @value{GDBVN}, you can build @value{GDBN} in a
19243separate directory for a Sun 4 like this:
c906108c 19244
474c8240 19245@smallexample
8e04817f
AC
19246@group
19247cd gdb-@value{GDBVN}
19248mkdir ../gdb-sun4
19249cd ../gdb-sun4
19250../gdb-@value{GDBVN}/configure sun4
19251make
19252@end group
474c8240 19253@end smallexample
c906108c 19254
8e04817f
AC
19255When @code{configure} builds a configuration using a remote source
19256directory, it creates a tree for the binaries with the same structure
19257(and using the same names) as the tree under the source directory. In
19258the example, you'd find the Sun 4 library @file{libiberty.a} in the
19259directory @file{gdb-sun4/libiberty}, and @value{GDBN} itself in
19260@file{gdb-sun4/gdb}.
c906108c 19261
94e91d6d
MC
19262Make sure that your path to the @file{configure} script has just one
19263instance of @file{gdb} in it. If your path to @file{configure} looks
19264like @file{../gdb-@value{GDBVN}/gdb/configure}, you are configuring only
19265one subdirectory of @value{GDBN}, not the whole package. This leads to
19266build errors about missing include files such as @file{bfd/bfd.h}.
19267
8e04817f
AC
19268One popular reason to build several @value{GDBN} configurations in separate
19269directories is to configure @value{GDBN} for cross-compiling (where
19270@value{GDBN} runs on one machine---the @dfn{host}---while debugging
19271programs that run on another machine---the @dfn{target}).
19272You specify a cross-debugging target by
19273giving the @samp{--target=@var{target}} option to @code{configure}.
c906108c 19274
8e04817f
AC
19275When you run @code{make} to build a program or library, you must run
19276it in a configured directory---whatever directory you were in when you
19277called @code{configure} (or one of its subdirectories).
c906108c 19278
8e04817f
AC
19279The @code{Makefile} that @code{configure} generates in each source
19280directory also runs recursively. If you type @code{make} in a source
19281directory such as @file{gdb-@value{GDBVN}} (or in a separate configured
19282directory configured with @samp{--srcdir=@var{dirname}/gdb-@value{GDBVN}}), you
19283will build all the required libraries, and then build GDB.
c906108c 19284
8e04817f
AC
19285When you have multiple hosts or targets configured in separate
19286directories, you can run @code{make} on them in parallel (for example,
19287if they are NFS-mounted on each of the hosts); they will not interfere
19288with each other.
c906108c 19289
8e04817f
AC
19290@node Config Names
19291@section Specifying names for hosts and targets
c906108c 19292
8e04817f
AC
19293The specifications used for hosts and targets in the @code{configure}
19294script are based on a three-part naming scheme, but some short predefined
19295aliases are also supported. The full naming scheme encodes three pieces
19296of information in the following pattern:
c906108c 19297
474c8240 19298@smallexample
8e04817f 19299@var{architecture}-@var{vendor}-@var{os}
474c8240 19300@end smallexample
c906108c 19301
8e04817f
AC
19302For example, you can use the alias @code{sun4} as a @var{host} argument,
19303or as the value for @var{target} in a @code{--target=@var{target}}
19304option. The equivalent full name is @samp{sparc-sun-sunos4}.
c906108c 19305
8e04817f
AC
19306The @code{configure} script accompanying @value{GDBN} does not provide
19307any query facility to list all supported host and target names or
19308aliases. @code{configure} calls the Bourne shell script
19309@code{config.sub} to map abbreviations to full names; you can read the
19310script, if you wish, or you can use it to test your guesses on
19311abbreviations---for example:
c906108c 19312
8e04817f
AC
19313@smallexample
19314% sh config.sub i386-linux
19315i386-pc-linux-gnu
19316% sh config.sub alpha-linux
19317alpha-unknown-linux-gnu
19318% sh config.sub hp9k700
19319hppa1.1-hp-hpux
19320% sh config.sub sun4
19321sparc-sun-sunos4.1.1
19322% sh config.sub sun3
19323m68k-sun-sunos4.1.1
19324% sh config.sub i986v
19325Invalid configuration `i986v': machine `i986v' not recognized
19326@end smallexample
c906108c 19327
8e04817f
AC
19328@noindent
19329@code{config.sub} is also distributed in the @value{GDBN} source
19330directory (@file{gdb-@value{GDBVN}}, for version @value{GDBVN}).
d700128c 19331
8e04817f
AC
19332@node Configure Options
19333@section @code{configure} options
c906108c 19334
8e04817f
AC
19335Here is a summary of the @code{configure} options and arguments that
19336are most often useful for building @value{GDBN}. @code{configure} also has
19337several other options not listed here. @inforef{What Configure
19338Does,,configure.info}, for a full explanation of @code{configure}.
c906108c 19339
474c8240 19340@smallexample
8e04817f
AC
19341configure @r{[}--help@r{]}
19342 @r{[}--prefix=@var{dir}@r{]}
19343 @r{[}--exec-prefix=@var{dir}@r{]}
19344 @r{[}--srcdir=@var{dirname}@r{]}
19345 @r{[}--norecursion@r{]} @r{[}--rm@r{]}
19346 @r{[}--target=@var{target}@r{]}
19347 @var{host}
474c8240 19348@end smallexample
c906108c 19349
8e04817f
AC
19350@noindent
19351You may introduce options with a single @samp{-} rather than
19352@samp{--} if you prefer; but you may abbreviate option names if you use
19353@samp{--}.
c906108c 19354
8e04817f
AC
19355@table @code
19356@item --help
19357Display a quick summary of how to invoke @code{configure}.
c906108c 19358
8e04817f
AC
19359@item --prefix=@var{dir}
19360Configure the source to install programs and files under directory
19361@file{@var{dir}}.
c906108c 19362
8e04817f
AC
19363@item --exec-prefix=@var{dir}
19364Configure the source to install programs under directory
19365@file{@var{dir}}.
c906108c 19366
8e04817f
AC
19367@c avoid splitting the warning from the explanation:
19368@need 2000
19369@item --srcdir=@var{dirname}
19370@strong{Warning: using this option requires @sc{gnu} @code{make}, or another
19371@code{make} that implements the @code{VPATH} feature.}@*
19372Use this option to make configurations in directories separate from the
19373@value{GDBN} source directories. Among other things, you can use this to
19374build (or maintain) several configurations simultaneously, in separate
19375directories. @code{configure} writes configuration specific files in
19376the current directory, but arranges for them to use the source in the
19377directory @var{dirname}. @code{configure} creates directories under
19378the working directory in parallel to the source directories below
19379@var{dirname}.
c906108c 19380
8e04817f
AC
19381@item --norecursion
19382Configure only the directory level where @code{configure} is executed; do not
19383propagate configuration to subdirectories.
c906108c 19384
8e04817f
AC
19385@item --target=@var{target}
19386Configure @value{GDBN} for cross-debugging programs running on the specified
19387@var{target}. Without this option, @value{GDBN} is configured to debug
19388programs that run on the same machine (@var{host}) as @value{GDBN} itself.
c906108c 19389
8e04817f 19390There is no convenient way to generate a list of all available targets.
c906108c 19391
8e04817f
AC
19392@item @var{host} @dots{}
19393Configure @value{GDBN} to run on the specified @var{host}.
c906108c 19394
8e04817f
AC
19395There is no convenient way to generate a list of all available hosts.
19396@end table
c906108c 19397
8e04817f
AC
19398There are many other options available as well, but they are generally
19399needed for special purposes only.
c906108c 19400
8e04817f
AC
19401@node Maintenance Commands
19402@appendix Maintenance Commands
19403@cindex maintenance commands
19404@cindex internal commands
c906108c 19405
8e04817f
AC
19406In addition to commands intended for @value{GDBN} users, @value{GDBN}
19407includes a number of commands intended for @value{GDBN} developers.
19408These commands are provided here for reference.
c906108c 19409
8e04817f
AC
19410@table @code
19411@kindex maint info breakpoints
19412@item @anchor{maint info breakpoints}maint info breakpoints
19413Using the same format as @samp{info breakpoints}, display both the
19414breakpoints you've set explicitly, and those @value{GDBN} is using for
19415internal purposes. Internal breakpoints are shown with negative
19416breakpoint numbers. The type column identifies what kind of breakpoint
19417is shown:
c906108c 19418
8e04817f
AC
19419@table @code
19420@item breakpoint
19421Normal, explicitly set breakpoint.
c906108c 19422
8e04817f
AC
19423@item watchpoint
19424Normal, explicitly set watchpoint.
c906108c 19425
8e04817f
AC
19426@item longjmp
19427Internal breakpoint, used to handle correctly stepping through
19428@code{longjmp} calls.
c906108c 19429
8e04817f
AC
19430@item longjmp resume
19431Internal breakpoint at the target of a @code{longjmp}.
c906108c 19432
8e04817f
AC
19433@item until
19434Temporary internal breakpoint used by the @value{GDBN} @code{until} command.
c906108c 19435
8e04817f
AC
19436@item finish
19437Temporary internal breakpoint used by the @value{GDBN} @code{finish} command.
c906108c 19438
8e04817f
AC
19439@item shlib events
19440Shared library events.
c906108c 19441
8e04817f 19442@end table
c906108c 19443
8d30a00d
AC
19444@kindex maint internal-error
19445@kindex maint internal-warning
19446@item maint internal-error
19447@itemx maint internal-warning
19448Cause @value{GDBN} to call the internal function @code{internal_error}
19449or @code{internal_warning} and hence behave as though an internal error
19450or internal warning has been detected. In addition to reporting the
19451internal problem, these functions give the user the opportunity to
19452either quit @value{GDBN} or create a core file of the current
19453@value{GDBN} session.
19454
19455@smallexample
19456(gdb) @kbd{maint internal-error testing, 1, 2}
19457@dots{}/maint.c:121: internal-error: testing, 1, 2
19458A problem internal to GDB has been detected. Further
19459debugging may prove unreliable.
19460Quit this debugging session? (y or n) @kbd{n}
19461Create a core file? (y or n) @kbd{n}
b383017d 19462(gdb)
8d30a00d
AC
19463@end smallexample
19464
19465Takes an optional parameter that is used as the text of the error or
19466warning message.
19467
00905d52
AC
19468@kindex maint print dummy-frames
19469@item maint print dummy-frames
19470
19471Prints the contents of @value{GDBN}'s internal dummy-frame stack.
19472
19473@smallexample
19474(gdb) @kbd{b add}
19475@dots{}
19476(gdb) @kbd{print add(2,3)}
19477Breakpoint 2, add (a=2, b=3) at @dots{}
1947858 return (a + b);
19479The program being debugged stopped while in a function called from GDB.
19480@dots{}
19481(gdb) @kbd{maint print dummy-frames}
194820x1a57c80: pc=0x01014068 fp=0x0200bddc sp=0x0200bdd6
19483 top=0x0200bdd4 id=@{stack=0x200bddc,code=0x101405c@}
19484 call_lo=0x01014000 call_hi=0x01014001
b383017d 19485(gdb)
00905d52
AC
19486@end smallexample
19487
19488Takes an optional file parameter.
19489
0680b120
AC
19490@kindex maint print registers
19491@kindex maint print raw-registers
19492@kindex maint print cooked-registers
617073a9 19493@kindex maint print register-groups
0680b120
AC
19494@item maint print registers
19495@itemx maint print raw-registers
19496@itemx maint print cooked-registers
617073a9 19497@itemx maint print register-groups
0680b120
AC
19498Print @value{GDBN}'s internal register data structures.
19499
617073a9
AC
19500The command @code{maint print raw-registers} includes the contents of
19501the raw register cache; the command @code{maint print cooked-registers}
19502includes the (cooked) value of all registers; and the command
19503@code{maint print register-groups} includes the groups that each
19504register is a member of. @xref{Registers,, Registers, gdbint,
19505@value{GDBN} Internals}.
0680b120
AC
19506
19507Takes an optional file parameter.
19508
617073a9
AC
19509@kindex maint print reggroups
19510@item maint print reggroups
19511Print @value{GDBN}'s internal register group data structures.
19512
19513Takes an optional file parameter.
19514
19515@smallexample
19516(gdb) @kbd{maint print reggroups}
b383017d
RM
19517 Group Type
19518 general user
19519 float user
19520 all user
19521 vector user
19522 system user
19523 save internal
19524 restore internal
617073a9
AC
19525@end smallexample
19526
e7ba9c65
DJ
19527@kindex maint set profile
19528@kindex maint show profile
19529@cindex profiling GDB
19530@item maint set profile
19531@itemx maint show profile
19532Control profiling of @value{GDBN}.
19533
19534Profiling will be disabled until you use the @samp{maint set profile}
19535command to enable it. When you enable profiling, the system will begin
19536collecting timing and execution count data; when you disable profiling or
19537exit @value{GDBN}, the results will be written to a log file. Remember that
19538if you use profiling, @value{GDBN} will overwrite the profiling log file
19539(often called @file{gmon.out}). If you have a record of important profiling
19540data in a @file{gmon.out} file, be sure to move it to a safe location.
19541
19542Configuring with @samp{--enable-profiling} arranges for @value{GDBN} to be
b383017d 19543compiled with the @samp{-pg} compiler option.
e7ba9c65 19544
8e04817f 19545@end table
c906108c 19546
c906108c 19547
e0ce93ac 19548@node Remote Protocol
8e04817f 19549@appendix @value{GDBN} Remote Serial Protocol
c906108c 19550
ee2d5c50
AC
19551@menu
19552* Overview::
19553* Packets::
19554* Stop Reply Packets::
19555* General Query Packets::
19556* Register Packet Format::
19557* Examples::
0ce1b118 19558* File-I/O remote protocol extension::
ee2d5c50
AC
19559@end menu
19560
19561@node Overview
19562@section Overview
19563
8e04817f
AC
19564There may be occasions when you need to know something about the
19565protocol---for example, if there is only one serial port to your target
19566machine, you might want your program to do something special if it
19567recognizes a packet meant for @value{GDBN}.
c906108c 19568
d2c6833e 19569In the examples below, @samp{->} and @samp{<-} are used to indicate
8e04817f 19570transmitted and received data respectfully.
c906108c 19571
8e04817f
AC
19572@cindex protocol, @value{GDBN} remote serial
19573@cindex serial protocol, @value{GDBN} remote
19574@cindex remote serial protocol
19575All @value{GDBN} commands and responses (other than acknowledgments) are
19576sent as a @var{packet}. A @var{packet} is introduced with the character
19577@samp{$}, the actual @var{packet-data}, and the terminating character
19578@samp{#} followed by a two-digit @var{checksum}:
c906108c 19579
474c8240 19580@smallexample
8e04817f 19581@code{$}@var{packet-data}@code{#}@var{checksum}
474c8240 19582@end smallexample
8e04817f 19583@noindent
c906108c 19584
8e04817f
AC
19585@cindex checksum, for @value{GDBN} remote
19586@noindent
19587The two-digit @var{checksum} is computed as the modulo 256 sum of all
19588characters between the leading @samp{$} and the trailing @samp{#} (an
19589eight bit unsigned checksum).
c906108c 19590
8e04817f
AC
19591Implementors should note that prior to @value{GDBN} 5.0 the protocol
19592specification also included an optional two-digit @var{sequence-id}:
c906108c 19593
474c8240 19594@smallexample
8e04817f 19595@code{$}@var{sequence-id}@code{:}@var{packet-data}@code{#}@var{checksum}
474c8240 19596@end smallexample
c906108c 19597
8e04817f
AC
19598@cindex sequence-id, for @value{GDBN} remote
19599@noindent
19600That @var{sequence-id} was appended to the acknowledgment. @value{GDBN}
19601has never output @var{sequence-id}s. Stubs that handle packets added
19602since @value{GDBN} 5.0 must not accept @var{sequence-id}.
c906108c 19603
8e04817f
AC
19604@cindex acknowledgment, for @value{GDBN} remote
19605When either the host or the target machine receives a packet, the first
19606response expected is an acknowledgment: either @samp{+} (to indicate
19607the package was received correctly) or @samp{-} (to request
19608retransmission):
c906108c 19609
474c8240 19610@smallexample
d2c6833e
AC
19611-> @code{$}@var{packet-data}@code{#}@var{checksum}
19612<- @code{+}
474c8240 19613@end smallexample
8e04817f 19614@noindent
53a5351d 19615
8e04817f
AC
19616The host (@value{GDBN}) sends @var{command}s, and the target (the
19617debugging stub incorporated in your program) sends a @var{response}. In
19618the case of step and continue @var{command}s, the response is only sent
19619when the operation has completed (the target has again stopped).
c906108c 19620
8e04817f
AC
19621@var{packet-data} consists of a sequence of characters with the
19622exception of @samp{#} and @samp{$} (see @samp{X} packet for additional
19623exceptions).
c906108c 19624
8e04817f 19625Fields within the packet should be separated using @samp{,} @samp{;} or
ee2d5c50 19626@cindex remote protocol, field separator
8e04817f 19627@samp{:}. Except where otherwise noted all numbers are represented in
ee2d5c50 19628@sc{hex} with leading zeros suppressed.
c906108c 19629
8e04817f
AC
19630Implementors should note that prior to @value{GDBN} 5.0, the character
19631@samp{:} could not appear as the third character in a packet (as it
19632would potentially conflict with the @var{sequence-id}).
c906108c 19633
8e04817f
AC
19634Response @var{data} can be run-length encoded to save space. A @samp{*}
19635means that the next character is an @sc{ascii} encoding giving a repeat count
19636which stands for that many repetitions of the character preceding the
19637@samp{*}. The encoding is @code{n+29}, yielding a printable character
19638where @code{n >=3} (which is where rle starts to win). The printable
19639characters @samp{$}, @samp{#}, @samp{+} and @samp{-} or with a numeric
19640value greater than 126 should not be used.
c906108c 19641
8e04817f 19642So:
474c8240 19643@smallexample
8e04817f 19644"@code{0* }"
474c8240 19645@end smallexample
8e04817f
AC
19646@noindent
19647means the same as "0000".
c906108c 19648
8e04817f
AC
19649The error response returned for some packets includes a two character
19650error number. That number is not well defined.
c906108c 19651
8e04817f
AC
19652For any @var{command} not supported by the stub, an empty response
19653(@samp{$#00}) should be returned. That way it is possible to extend the
19654protocol. A newer @value{GDBN} can tell if a packet is supported based
19655on that response.
c906108c 19656
b383017d
RM
19657A stub is required to support the @samp{g}, @samp{G}, @samp{m}, @samp{M},
19658@samp{c}, and @samp{s} @var{command}s. All other @var{command}s are
8e04817f 19659optional.
c906108c 19660
ee2d5c50
AC
19661@node Packets
19662@section Packets
19663
19664The following table provides a complete list of all currently defined
19665@var{command}s and their corresponding response @var{data}.
19666
19667@table @r
19668
19669@item @code{!} --- extended mode
19670@cindex @code{!} packet
19671
8e04817f
AC
19672Enable extended mode. In extended mode, the remote server is made
19673persistent. The @samp{R} packet is used to restart the program being
19674debugged.
ee2d5c50
AC
19675
19676Reply:
19677@table @samp
19678@item OK
8e04817f 19679The remote target both supports and has enabled extended mode.
ee2d5c50 19680@end table
c906108c 19681
ee2d5c50
AC
19682@item @code{?} --- last signal
19683@cindex @code{?} packet
c906108c 19684
ee2d5c50
AC
19685Indicate the reason the target halted. The reply is the same as for
19686step and continue.
c906108c 19687
ee2d5c50
AC
19688Reply:
19689@xref{Stop Reply Packets}, for the reply specifications.
19690
19691@item @code{a} --- reserved
19692
19693Reserved for future use.
19694
19695@item @code{A}@var{arglen}@code{,}@var{argnum}@code{,}@var{arg}@code{,@dots{}} --- set program arguments @strong{(reserved)}
19696@cindex @code{A} packet
c906108c 19697
8e04817f
AC
19698Initialized @samp{argv[]} array passed into program. @var{arglen}
19699specifies the number of bytes in the hex encoded byte stream @var{arg}.
ee2d5c50
AC
19700See @code{gdbserver} for more details.
19701
19702Reply:
19703@table @samp
19704@item OK
19705@item E@var{NN}
19706@end table
19707
19708@item @code{b}@var{baud} --- set baud @strong{(deprecated)}
19709@cindex @code{b} packet
19710
19711Change the serial line speed to @var{baud}.
19712
19713JTC: @emph{When does the transport layer state change? When it's
19714received, or after the ACK is transmitted. In either case, there are
19715problems if the command or the acknowledgment packet is dropped.}
19716
19717Stan: @emph{If people really wanted to add something like this, and get
19718it working for the first time, they ought to modify ser-unix.c to send
19719some kind of out-of-band message to a specially-setup stub and have the
19720switch happen "in between" packets, so that from remote protocol's point
19721of view, nothing actually happened.}
19722
19723@item @code{B}@var{addr},@var{mode} --- set breakpoint @strong{(deprecated)}
19724@cindex @code{B} packet
19725
8e04817f 19726Set (@var{mode} is @samp{S}) or clear (@var{mode} is @samp{C}) a
2f870471
AC
19727breakpoint at @var{addr}.
19728
19729This packet has been replaced by the @samp{Z} and @samp{z} packets
19730(@pxref{insert breakpoint or watchpoint packet}).
c906108c 19731
ee2d5c50
AC
19732@item @code{c}@var{addr} --- continue
19733@cindex @code{c} packet
19734
19735@var{addr} is address to resume. If @var{addr} is omitted, resume at
8e04817f 19736current address.
c906108c 19737
ee2d5c50
AC
19738Reply:
19739@xref{Stop Reply Packets}, for the reply specifications.
19740
19741@item @code{C}@var{sig}@code{;}@var{addr} --- continue with signal
19742@cindex @code{C} packet
19743
8e04817f
AC
19744Continue with signal @var{sig} (hex signal number). If
19745@code{;}@var{addr} is omitted, resume at same address.
c906108c 19746
ee2d5c50
AC
19747Reply:
19748@xref{Stop Reply Packets}, for the reply specifications.
c906108c 19749
ee2d5c50
AC
19750@item @code{d} --- toggle debug @strong{(deprecated)}
19751@cindex @code{d} packet
19752
19753Toggle debug flag.
19754
19755@item @code{D} --- detach
19756@cindex @code{D} packet
19757
19758Detach @value{GDBN} from the remote system. Sent to the remote target
07f31aa6 19759before @value{GDBN} disconnects via the @code{detach} command.
ee2d5c50
AC
19760
19761Reply:
19762@table @samp
19763@item @emph{no response}
8e04817f 19764@value{GDBN} does not check for any response after sending this packet.
ee2d5c50 19765@end table
c906108c 19766
ee2d5c50 19767@item @code{e} --- reserved
c906108c 19768
ee2d5c50 19769Reserved for future use.
c906108c 19770
ee2d5c50 19771@item @code{E} --- reserved
c906108c 19772
ee2d5c50 19773Reserved for future use.
c906108c 19774
ee2d5c50
AC
19775@item @code{f} --- reserved
19776
19777Reserved for future use.
19778
0ce1b118
CV
19779@item @code{F}@var{RC}@code{,}@var{EE}@code{,}@var{CF}@code{;}@var{XX} --- Reply to target's F packet.
19780@cindex @code{F} packet
ee2d5c50 19781
0ce1b118
CV
19782This packet is send by @value{GDBN} as reply to a @code{F} request packet
19783sent by the target. This is part of the File-I/O protocol extension.
19784@xref{File-I/O remote protocol extension}, for the specification.
ee2d5c50
AC
19785
19786@item @code{g} --- read registers
19787@anchor{read registers packet}
19788@cindex @code{g} packet
19789
19790Read general registers.
19791
19792Reply:
19793@table @samp
19794@item @var{XX@dots{}}
8e04817f
AC
19795Each byte of register data is described by two hex digits. The bytes
19796with the register are transmitted in target byte order. The size of
19797each register and their position within the @samp{g} @var{packet} are
12c266ea
AC
19798determined by the @value{GDBN} internal macros
19799@var{DEPRECATED_REGISTER_RAW_SIZE} and @var{REGISTER_NAME} macros. The
19800specification of several standard @code{g} packets is specified below.
ee2d5c50
AC
19801@item E@var{NN}
19802for an error.
19803@end table
c906108c 19804
ee2d5c50
AC
19805@item @code{G}@var{XX@dots{}} --- write regs
19806@cindex @code{G} packet
c906108c 19807
ee2d5c50
AC
19808@xref{read registers packet}, for a description of the @var{XX@dots{}}
19809data.
19810
19811Reply:
19812@table @samp
19813@item OK
19814for success
19815@item E@var{NN}
19816for an error
19817@end table
19818
19819@item @code{h} --- reserved
19820
19821Reserved for future use.
19822
b383017d 19823@item @code{H}@var{c}@var{t@dots{}} --- set thread
ee2d5c50 19824@cindex @code{H} packet
c906108c 19825
8e04817f 19826Set thread for subsequent operations (@samp{m}, @samp{M}, @samp{g},
ee2d5c50
AC
19827@samp{G}, et.al.). @var{c} depends on the operation to be performed: it
19828should be @samp{c} for step and continue operations, @samp{g} for other
19829operations. The thread designator @var{t@dots{}} may be -1, meaning all
19830the threads, a thread number, or zero which means pick any thread.
19831
19832Reply:
19833@table @samp
19834@item OK
19835for success
19836@item E@var{NN}
19837for an error
19838@end table
c906108c 19839
8e04817f
AC
19840@c FIXME: JTC:
19841@c 'H': How restrictive (or permissive) is the thread model. If a
19842@c thread is selected and stopped, are other threads allowed
19843@c to continue to execute? As I mentioned above, I think the
19844@c semantics of each command when a thread is selected must be
19845@c described. For example:
19846@c
19847@c 'g': If the stub supports threads and a specific thread is
19848@c selected, returns the register block from that thread;
19849@c otherwise returns current registers.
19850@c
19851@c 'G' If the stub supports threads and a specific thread is
19852@c selected, sets the registers of the register block of
19853@c that thread; otherwise sets current registers.
c906108c 19854
ee2d5c50
AC
19855@item @code{i}@var{addr}@code{,}@var{nnn} --- cycle step @strong{(draft)}
19856@anchor{cycle step packet}
19857@cindex @code{i} packet
19858
8e04817f
AC
19859Step the remote target by a single clock cycle. If @code{,}@var{nnn} is
19860present, cycle step @var{nnn} cycles. If @var{addr} is present, cycle
19861step starting at that address.
c906108c 19862
ee2d5c50
AC
19863@item @code{I} --- signal then cycle step @strong{(reserved)}
19864@cindex @code{I} packet
19865
19866@xref{step with signal packet}. @xref{cycle step packet}.
19867
19868@item @code{j} --- reserved
19869
19870Reserved for future use.
19871
19872@item @code{J} --- reserved
c906108c 19873
ee2d5c50 19874Reserved for future use.
c906108c 19875
ee2d5c50
AC
19876@item @code{k} --- kill request
19877@cindex @code{k} packet
c906108c 19878
ac282366 19879FIXME: @emph{There is no description of how to operate when a specific
ee2d5c50
AC
19880thread context has been selected (i.e.@: does 'k' kill only that
19881thread?)}.
c906108c 19882
ee2d5c50 19883@item @code{K} --- reserved
c906108c 19884
ee2d5c50
AC
19885Reserved for future use.
19886
19887@item @code{l} --- reserved
19888
19889Reserved for future use.
19890
19891@item @code{L} --- reserved
19892
19893Reserved for future use.
19894
19895@item @code{m}@var{addr}@code{,}@var{length} --- read memory
19896@cindex @code{m} packet
c906108c 19897
8e04817f 19898Read @var{length} bytes of memory starting at address @var{addr}.
ee2d5c50 19899Neither @value{GDBN} nor the stub assume that sized memory transfers are
2e834e49 19900assumed using word aligned accesses. FIXME: @emph{A word aligned memory
8e04817f 19901transfer mechanism is needed.}
c906108c 19902
ee2d5c50
AC
19903Reply:
19904@table @samp
19905@item @var{XX@dots{}}
19906@var{XX@dots{}} is mem contents. Can be fewer bytes than requested if able
19907to read only part of the data. Neither @value{GDBN} nor the stub assume
2e834e49 19908that sized memory transfers are assumed using word aligned
ee2d5c50
AC
19909accesses. FIXME: @emph{A word aligned memory transfer mechanism is
19910needed.}
19911@item E@var{NN}
19912@var{NN} is errno
19913@end table
19914
19915@item @code{M}@var{addr},@var{length}@code{:}@var{XX@dots{}} --- write mem
19916@cindex @code{M} packet
19917
8e04817f 19918Write @var{length} bytes of memory starting at address @var{addr}.
ee2d5c50
AC
19919@var{XX@dots{}} is the data.
19920
19921Reply:
19922@table @samp
19923@item OK
19924for success
19925@item E@var{NN}
8e04817f
AC
19926for an error (this includes the case where only part of the data was
19927written).
ee2d5c50 19928@end table
c906108c 19929
ee2d5c50 19930@item @code{n} --- reserved
c906108c 19931
ee2d5c50 19932Reserved for future use.
c906108c 19933
ee2d5c50 19934@item @code{N} --- reserved
c906108c 19935
ee2d5c50 19936Reserved for future use.
c906108c 19937
ee2d5c50
AC
19938@item @code{o} --- reserved
19939
19940Reserved for future use.
19941
19942@item @code{O} --- reserved
19943
19944Reserved for future use.
c906108c 19945
ee2d5c50
AC
19946@item @code{p}@var{n@dots{}} --- read reg @strong{(reserved)}
19947@cindex @code{p} packet
19948
19949@xref{write register packet}.
19950
19951Reply:
19952@table @samp
19953@item @var{r@dots{}.}
19954The hex encoded value of the register in target byte order.
19955@end table
19956
19957@item @code{P}@var{n@dots{}}@code{=}@var{r@dots{}} --- write register
19958@anchor{write register packet}
19959@cindex @code{P} packet
19960
19961Write register @var{n@dots{}} with value @var{r@dots{}}, which contains two hex
8e04817f 19962digits for each byte in the register (target byte order).
c906108c 19963
ee2d5c50
AC
19964Reply:
19965@table @samp
19966@item OK
19967for success
19968@item E@var{NN}
19969for an error
19970@end table
19971
19972@item @code{q}@var{query} --- general query
19973@anchor{general query packet}
19974@cindex @code{q} packet
19975
19976Request info about @var{query}. In general @value{GDBN} queries have a
19977leading upper case letter. Custom vendor queries should use a company
19978prefix (in lower case) ex: @samp{qfsf.var}. @var{query} may optionally
19979be followed by a @samp{,} or @samp{;} separated list. Stubs must ensure
19980that they match the full @var{query} name.
19981
19982Reply:
19983@table @samp
19984@item @var{XX@dots{}}
19985Hex encoded data from query. The reply can not be empty.
19986@item E@var{NN}
19987error reply
8e04817f 19988@item
ee2d5c50
AC
19989Indicating an unrecognized @var{query}.
19990@end table
19991
19992@item @code{Q}@var{var}@code{=}@var{val} --- general set
19993@cindex @code{Q} packet
19994
19995Set value of @var{var} to @var{val}.
19996
19997@xref{general query packet}, for a discussion of naming conventions.
c906108c 19998
ee2d5c50
AC
19999@item @code{r} --- reset @strong{(deprecated)}
20000@cindex @code{r} packet
c906108c 20001
8e04817f 20002Reset the entire system.
c906108c 20003
ee2d5c50
AC
20004@item @code{R}@var{XX} --- remote restart
20005@cindex @code{R} packet
20006
8e04817f
AC
20007Restart the program being debugged. @var{XX}, while needed, is ignored.
20008This packet is only available in extended mode.
ee2d5c50
AC
20009
20010Reply:
20011@table @samp
20012@item @emph{no reply}
8e04817f 20013The @samp{R} packet has no reply.
ee2d5c50
AC
20014@end table
20015
20016@item @code{s}@var{addr} --- step
20017@cindex @code{s} packet
c906108c 20018
8e04817f
AC
20019@var{addr} is address to resume. If @var{addr} is omitted, resume at
20020same address.
c906108c 20021
ee2d5c50
AC
20022Reply:
20023@xref{Stop Reply Packets}, for the reply specifications.
20024
20025@item @code{S}@var{sig}@code{;}@var{addr} --- step with signal
20026@anchor{step with signal packet}
20027@cindex @code{S} packet
20028
8e04817f 20029Like @samp{C} but step not continue.
c906108c 20030
ee2d5c50
AC
20031Reply:
20032@xref{Stop Reply Packets}, for the reply specifications.
20033
b383017d 20034@item @code{t}@var{addr}@code{:}@var{PP}@code{,}@var{MM} --- search
ee2d5c50
AC
20035@cindex @code{t} packet
20036
8e04817f 20037Search backwards starting at address @var{addr} for a match with pattern
ee2d5c50
AC
20038@var{PP} and mask @var{MM}. @var{PP} and @var{MM} are 4 bytes.
20039@var{addr} must be at least 3 digits.
c906108c 20040
ee2d5c50
AC
20041@item @code{T}@var{XX} --- thread alive
20042@cindex @code{T} packet
c906108c 20043
ee2d5c50 20044Find out if the thread XX is alive.
c906108c 20045
ee2d5c50
AC
20046Reply:
20047@table @samp
20048@item OK
20049thread is still alive
20050@item E@var{NN}
20051thread is dead
20052@end table
20053
20054@item @code{u} --- reserved
20055
20056Reserved for future use.
20057
20058@item @code{U} --- reserved
20059
20060Reserved for future use.
20061
86d30acc 20062@item @code{v} --- verbose packet prefix
ee2d5c50 20063
86d30acc
DJ
20064Packets starting with @code{v} are identified by a multi-letter name,
20065up to the first @code{;} or @code{?} (or the end of the packet).
20066
20067@item @code{vCont}[;@var{action}[@code{:}@var{tid}]]... --- extended resume
20068@cindex @code{vCont} packet
20069
20070Resume the inferior. Different actions may be specified for each thread.
20071If an action is specified with no @var{tid}, then it is applied to any
20072threads that don't have a specific action specified; if no default action is
20073specified then other threads should remain stopped. Specifying multiple
20074default actions is an error; specifying no actions is also an error.
20075Thread IDs are specified in hexadecimal. Currently supported actions are:
20076
20077@table @code
20078@item c
20079Continue.
20080@item C@var{sig}
20081Continue with signal @var{sig}. @var{sig} should be two hex digits.
20082@item s
20083Step.
20084@item S@var{sig}
20085Step with signal @var{sig}. @var{sig} should be two hex digits.
20086@end table
20087
20088The optional @var{addr} argument normally associated with these packets is
20089not supported in @code{vCont}.
20090
20091Reply:
20092@xref{Stop Reply Packets}, for the reply specifications.
20093
20094@item @code{vCont?} --- extended resume query
20095@cindex @code{vCont?} packet
20096
20097Query support for the @code{vCont} packet.
20098
20099Reply:
20100@table @samp
20101@item @code{vCont}[;@var{action}]...
20102The @code{vCont} packet is supported. Each @var{action} is a supported
20103command in the @code{vCont} packet.
20104@item
20105The @code{vCont} packet is not supported.
20106@end table
ee2d5c50
AC
20107
20108@item @code{V} --- reserved
c906108c 20109
ee2d5c50 20110Reserved for future use.
c906108c 20111
ee2d5c50 20112@item @code{w} --- reserved
c906108c 20113
ee2d5c50 20114Reserved for future use.
c906108c 20115
ee2d5c50 20116@item @code{W} --- reserved
c906108c 20117
ee2d5c50 20118Reserved for future use.
c906108c 20119
ee2d5c50
AC
20120@item @code{x} --- reserved
20121
20122Reserved for future use.
20123
20124@item @code{X}@var{addr}@code{,}@var{length}@var{:}@var{XX@dots{}} --- write mem (binary)
20125@cindex @code{X} packet
20126
20127@var{addr} is address, @var{length} is number of bytes, @var{XX@dots{}}
20128is binary data. The characters @code{$}, @code{#}, and @code{0x7d} are
8e04817f 20129escaped using @code{0x7d}.
c906108c 20130
ee2d5c50
AC
20131Reply:
20132@table @samp
20133@item OK
20134for success
20135@item E@var{NN}
20136for an error
20137@end table
20138
20139@item @code{y} --- reserved
c906108c 20140
ee2d5c50 20141Reserved for future use.
c906108c 20142
ee2d5c50
AC
20143@item @code{Y} reserved
20144
20145Reserved for future use.
20146
2f870471
AC
20147@item @code{z}@var{type}@code{,}@var{addr}@code{,}@var{length} --- remove breakpoint or watchpoint @strong{(draft)}
20148@itemx @code{Z}@var{type}@code{,}@var{addr}@code{,}@var{length} --- insert breakpoint or watchpoint @strong{(draft)}
20149@anchor{insert breakpoint or watchpoint packet}
ee2d5c50 20150@cindex @code{z} packet
2f870471 20151@cindex @code{Z} packets
ee2d5c50 20152
2f870471
AC
20153Insert (@code{Z}) or remove (@code{z}) a @var{type} breakpoint or
20154watchpoint starting at address @var{address} and covering the next
20155@var{length} bytes.
ee2d5c50 20156
2f870471
AC
20157Each breakpoint and watchpoint packet @var{type} is documented
20158separately.
20159
512217c7
AC
20160@emph{Implementation notes: A remote target shall return an empty string
20161for an unrecognized breakpoint or watchpoint packet @var{type}. A
20162remote target shall support either both or neither of a given
2f870471
AC
20163@code{Z}@var{type}@dots{} and @code{z}@var{type}@dots{} packet pair. To
20164avoid potential problems with duplicate packets, the operations should
20165be implemented in an idempotent way.}
20166
20167@item @code{z}@code{0}@code{,}@var{addr}@code{,}@var{length} --- remove memory breakpoint @strong{(draft)}
20168@item @code{Z}@code{0}@code{,}@var{addr}@code{,}@var{length} --- insert memory breakpoint @strong{(draft)}
20169@cindex @code{z0} packet
20170@cindex @code{Z0} packet
20171
20172Insert (@code{Z0}) or remove (@code{z0}) a memory breakpoint at address
20173@code{addr} of size @code{length}.
20174
20175A memory breakpoint is implemented by replacing the instruction at
20176@var{addr} with a software breakpoint or trap instruction. The
20177@code{length} is used by targets that indicates the size of the
20178breakpoint (in bytes) that should be inserted (e.g., the @sc{arm} and
20179@sc{mips} can insert either a 2 or 4 byte breakpoint).
c906108c 20180
2f870471
AC
20181@emph{Implementation note: It is possible for a target to copy or move
20182code that contains memory breakpoints (e.g., when implementing
20183overlays). The behavior of this packet, in the presence of such a
20184target, is not defined.}
c906108c 20185
ee2d5c50
AC
20186Reply:
20187@table @samp
2f870471
AC
20188@item OK
20189success
20190@item
20191not supported
ee2d5c50
AC
20192@item E@var{NN}
20193for an error
2f870471
AC
20194@end table
20195
20196@item @code{z}@code{1}@code{,}@var{addr}@code{,}@var{length} --- remove hardware breakpoint @strong{(draft)}
20197@item @code{Z}@code{1}@code{,}@var{addr}@code{,}@var{length} --- insert hardware breakpoint @strong{(draft)}
20198@cindex @code{z1} packet
20199@cindex @code{Z1} packet
20200
20201Insert (@code{Z1}) or remove (@code{z1}) a hardware breakpoint at
20202address @code{addr} of size @code{length}.
20203
20204A hardware breakpoint is implemented using a mechanism that is not
20205dependant on being able to modify the target's memory.
20206
20207@emph{Implementation note: A hardware breakpoint is not affected by code
20208movement.}
20209
20210Reply:
20211@table @samp
ee2d5c50 20212@item OK
2f870471
AC
20213success
20214@item
20215not supported
20216@item E@var{NN}
20217for an error
20218@end table
20219
20220@item @code{z}@code{2}@code{,}@var{addr}@code{,}@var{length} --- remove write watchpoint @strong{(draft)}
20221@item @code{Z}@code{2}@code{,}@var{addr}@code{,}@var{length} --- insert write watchpoint @strong{(draft)}
20222@cindex @code{z2} packet
20223@cindex @code{Z2} packet
20224
20225Insert (@code{Z2}) or remove (@code{z2}) a write watchpoint.
20226
20227Reply:
20228@table @samp
20229@item OK
20230success
20231@item
20232not supported
20233@item E@var{NN}
20234for an error
20235@end table
20236
20237@item @code{z}@code{3}@code{,}@var{addr}@code{,}@var{length} --- remove read watchpoint @strong{(draft)}
20238@item @code{Z}@code{3}@code{,}@var{addr}@code{,}@var{length} --- insert read watchpoint @strong{(draft)}
20239@cindex @code{z3} packet
20240@cindex @code{Z3} packet
20241
2e834e49 20242Insert (@code{Z3}) or remove (@code{z3}) a read watchpoint.
2f870471
AC
20243
20244Reply:
20245@table @samp
20246@item OK
20247success
20248@item
20249not supported
20250@item E@var{NN}
20251for an error
20252@end table
20253
2e834e49
HPN
20254@item @code{z}@code{4}@code{,}@var{addr}@code{,}@var{length} --- remove access watchpoint @strong{(draft)}
20255@item @code{Z}@code{4}@code{,}@var{addr}@code{,}@var{length} --- insert access watchpoint @strong{(draft)}
2f870471
AC
20256@cindex @code{z4} packet
20257@cindex @code{Z4} packet
20258
20259Insert (@code{Z4}) or remove (@code{z4}) an access watchpoint.
20260
20261Reply:
20262@table @samp
20263@item OK
20264success
20265@item
20266not supported
20267@item E@var{NN}
20268for an error
ee2d5c50
AC
20269@end table
20270
20271@end table
c906108c 20272
ee2d5c50
AC
20273@node Stop Reply Packets
20274@section Stop Reply Packets
20275@cindex stop reply packets
c906108c 20276
8e04817f
AC
20277The @samp{C}, @samp{c}, @samp{S}, @samp{s} and @samp{?} packets can
20278receive any of the below as a reply. In the case of the @samp{C},
20279@samp{c}, @samp{S} and @samp{s} packets, that reply is only returned
20280when the target halts. In the below the exact meaning of @samp{signal
20281number} is poorly defined. In general one of the UNIX signal numbering
20282conventions is used.
c906108c 20283
ee2d5c50 20284@table @samp
c906108c 20285
ee2d5c50
AC
20286@item S@var{AA}
20287@var{AA} is the signal number
c906108c 20288
8e04817f 20289@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
20290@cindex @code{T} packet reply
20291
8e04817f
AC
20292@var{AA} = two hex digit signal number; @var{n...} = register number
20293(hex), @var{r...} = target byte ordered register contents, size defined
12c266ea
AC
20294by @code{DEPRECATED_REGISTER_RAW_SIZE}; @var{n...} = @samp{thread},
20295@var{r...} = thread process ID, this is a hex integer; @var{n...} =
20296(@samp{watch} | @samp{rwatch} | @samp{awatch}, @var{r...} = data
20297address, this is a hex integer; @var{n...} = other string not starting
20298with valid hex digit. @value{GDBN} should ignore this @var{n...},
20299@var{r...} pair and go on to the next. This way we can extend the
20300protocol.
c906108c 20301
ee2d5c50
AC
20302@item W@var{AA}
20303
8e04817f 20304The process exited, and @var{AA} is the exit status. This is only
ee2d5c50
AC
20305applicable to certain targets.
20306
20307@item X@var{AA}
c906108c 20308
8e04817f 20309The process terminated with signal @var{AA}.
c906108c 20310
ee2d5c50 20311@item O@var{XX@dots{}}
c906108c 20312
ee2d5c50
AC
20313@var{XX@dots{}} is hex encoding of @sc{ascii} data. This can happen at
20314any time while the program is running and the debugger should continue
20315to wait for @samp{W}, @samp{T}, etc.
20316
0ce1b118
CV
20317@item F@var{call-id}@code{,}@var{parameter@dots{}}
20318
20319@var{call-id} is the identifier which says which host system call should
20320be called. This is just the name of the function. Translation into the
20321correct system call is only applicable as it's defined in @value{GDBN}.
20322@xref{File-I/O remote protocol extension}, for a list of implemented
20323system calls.
20324
20325@var{parameter@dots{}} is a list of parameters as defined for this very
20326system call.
20327
20328The target replies with this packet when it expects @value{GDBN} to call
20329a host system call on behalf of the target. @value{GDBN} replies with
20330an appropriate @code{F} packet and keeps up waiting for the next reply
20331packet from the target. The latest @samp{C}, @samp{c}, @samp{S} or
20332@samp{s} action is expected to be continued.
20333@xref{File-I/O remote protocol extension}, for more details.
20334
ee2d5c50
AC
20335@end table
20336
20337@node General Query Packets
20338@section General Query Packets
c906108c 20339
8e04817f 20340The following set and query packets have already been defined.
c906108c 20341
ee2d5c50 20342@table @r
c906108c 20343
ee2d5c50
AC
20344@item @code{q}@code{C} --- current thread
20345
20346Return the current thread id.
20347
20348Reply:
20349@table @samp
20350@item @code{QC}@var{pid}
8e04817f 20351Where @var{pid} is a HEX encoded 16 bit process id.
ee2d5c50
AC
20352@item *
20353Any other reply implies the old pid.
20354@end table
20355
20356@item @code{q}@code{fThreadInfo} -- all thread ids
20357
20358@code{q}@code{sThreadInfo}
c906108c 20359
8e04817f
AC
20360Obtain a list of active thread ids from the target (OS). Since there
20361may be too many active threads to fit into one reply packet, this query
20362works iteratively: it may require more than one query/reply sequence to
20363obtain the entire list of threads. The first query of the sequence will
20364be the @code{qf}@code{ThreadInfo} query; subsequent queries in the
20365sequence will be the @code{qs}@code{ThreadInfo} query.
ee2d5c50
AC
20366
20367NOTE: replaces the @code{qL} query (see below).
20368
20369Reply:
20370@table @samp
20371@item @code{m}@var{id}
20372A single thread id
20373@item @code{m}@var{id},@var{id}@dots{}
20374a comma-separated list of thread ids
20375@item @code{l}
20376(lower case 'el') denotes end of list.
20377@end table
20378
20379In response to each query, the target will reply with a list of one or
20380more thread ids, in big-endian hex, separated by commas. @value{GDBN}
20381will respond to each reply with a request for more thread ids (using the
8e04817f
AC
20382@code{qs} form of the query), until the target responds with @code{l}
20383(lower-case el, for @code{'last'}).
c906108c 20384
ee2d5c50
AC
20385@item @code{q}@code{ThreadExtraInfo}@code{,}@var{id} --- extra thread info
20386
20387Where @var{id} is a thread-id in big-endian hex. Obtain a printable
20388string description of a thread's attributes from the target OS. This
20389string may contain anything that the target OS thinks is interesting for
20390@value{GDBN} to tell the user about the thread. The string is displayed
20391in @value{GDBN}'s @samp{info threads} display. Some examples of
20392possible thread extra info strings are ``Runnable'', or ``Blocked on
20393Mutex''.
20394
20395Reply:
20396@table @samp
20397@item @var{XX@dots{}}
20398Where @var{XX@dots{}} is a hex encoding of @sc{ascii} data, comprising
20399the printable string containing the extra information about the thread's
8e04817f 20400attributes.
ee2d5c50
AC
20401@end table
20402
20403@item @code{q}@code{L}@var{startflag}@var{threadcount}@var{nextthread} --- query @var{LIST} or @var{threadLIST} @strong{(deprecated)}
c906108c 20404
8e04817f
AC
20405Obtain thread information from RTOS. Where: @var{startflag} (one hex
20406digit) is one to indicate the first query and zero to indicate a
20407subsequent query; @var{threadcount} (two hex digits) is the maximum
20408number of threads the response packet can contain; and @var{nextthread}
20409(eight hex digits), for subsequent queries (@var{startflag} is zero), is
20410returned in the response as @var{argthread}.
ee2d5c50
AC
20411
20412NOTE: this query is replaced by the @code{q}@code{fThreadInfo} query
20413(see above).
20414
20415Reply:
20416@table @samp
20417@item @code{q}@code{M}@var{count}@var{done}@var{argthread}@var{thread@dots{}}
8e04817f
AC
20418Where: @var{count} (two hex digits) is the number of threads being
20419returned; @var{done} (one hex digit) is zero to indicate more threads
20420and one indicates no further threads; @var{argthreadid} (eight hex
ee2d5c50
AC
20421digits) is @var{nextthread} from the request packet; @var{thread@dots{}}
20422is a sequence of thread IDs from the target. @var{threadid} (eight hex
8e04817f 20423digits). See @code{remote.c:parse_threadlist_response()}.
ee2d5c50 20424@end table
c906108c 20425
ee2d5c50
AC
20426@item @code{q}@code{CRC:}@var{addr}@code{,}@var{length} --- compute CRC of memory block
20427
20428Reply:
20429@table @samp
20430@item @code{E}@var{NN}
20431An error (such as memory fault)
20432@item @code{C}@var{CRC32}
20433A 32 bit cyclic redundancy check of the specified memory region.
20434@end table
20435
20436@item @code{q}@code{Offsets} --- query sect offs
c906108c 20437
8e04817f
AC
20438Get section offsets that the target used when re-locating the downloaded
20439image. @emph{Note: while a @code{Bss} offset is included in the
20440response, @value{GDBN} ignores this and instead applies the @code{Data}
20441offset to the @code{Bss} section.}
c906108c 20442
ee2d5c50
AC
20443Reply:
20444@table @samp
20445@item @code{Text=}@var{xxx}@code{;Data=}@var{yyy}@code{;Bss=}@var{zzz}
20446@end table
20447
20448@item @code{q}@code{P}@var{mode}@var{threadid} --- thread info request
20449
8e04817f
AC
20450Returns information on @var{threadid}. Where: @var{mode} is a hex
20451encoded 32 bit mode; @var{threadid} is a hex encoded 64 bit thread ID.
ee2d5c50
AC
20452
20453Reply:
20454@table @samp
20455@item *
20456@end table
20457
8e04817f 20458See @code{remote.c:remote_unpack_thread_info_response()}.
c906108c 20459
ee2d5c50
AC
20460@item @code{q}@code{Rcmd,}@var{command} --- remote command
20461
20462@var{command} (hex encoded) is passed to the local interpreter for
8e04817f
AC
20463execution. Invalid commands should be reported using the output string.
20464Before the final result packet, the target may also respond with a
ee2d5c50
AC
20465number of intermediate @code{O}@var{output} console output packets.
20466@emph{Implementors should note that providing access to a stubs's
20467interpreter may have security implications}.
20468
20469Reply:
20470@table @samp
20471@item OK
8e04817f 20472A command response with no output.
ee2d5c50 20473@item @var{OUTPUT}
8e04817f 20474A command response with the hex encoded output string @var{OUTPUT}.
ee2d5c50 20475@item @code{E}@var{NN}
8e04817f 20476Indicate a badly formed request.
ee2d5c50 20477@item @samp{}
8e04817f 20478When @samp{q}@samp{Rcmd} is not recognized.
ee2d5c50
AC
20479@end table
20480
20481@item @code{qSymbol::} --- symbol lookup
c906108c 20482
8e04817f
AC
20483Notify the target that @value{GDBN} is prepared to serve symbol lookup
20484requests. Accept requests from the target for the values of symbols.
ee2d5c50
AC
20485
20486Reply:
20487@table @samp
20488@item @code{OK}
8e04817f 20489The target does not need to look up any (more) symbols.
ee2d5c50
AC
20490@item @code{qSymbol:}@var{sym_name}
20491The target requests the value of symbol @var{sym_name} (hex encoded).
20492@value{GDBN} may provide the value by using the
20493@code{qSymbol:}@var{sym_value}:@var{sym_name} message, described below.
20494@end table
20495
20496@item @code{qSymbol:}@var{sym_value}:@var{sym_name} --- symbol value
20497
20498Set the value of @var{sym_name} to @var{sym_value}.
20499
20500@var{sym_name} (hex encoded) is the name of a symbol whose value the
20501target has previously requested.
20502
20503@var{sym_value} (hex) is the value for symbol @var{sym_name}. If
20504@value{GDBN} cannot supply a value for @var{sym_name}, then this field
20505will be empty.
20506
20507Reply:
20508@table @samp
20509@item @code{OK}
8e04817f 20510The target does not need to look up any (more) symbols.
ee2d5c50
AC
20511@item @code{qSymbol:}@var{sym_name}
20512The target requests the value of a new symbol @var{sym_name} (hex
20513encoded). @value{GDBN} will continue to supply the values of symbols
20514(if available), until the target ceases to request them.
20515@end table
eb12ee30 20516
649e03f6
RM
20517@item @code{qPart}:@var{object}:@code{read}:@var{annex}:@var{offset},@var{length} --- read special data
20518
20519Read uninterpreted bytes from the target's special data area
20520identified by the keyword @code{object}.
20521Request @var{length} bytes starting at @var{offset} bytes into the data.
20522The content and encoding of @var{annex} is specific to the object;
20523it can supply additional details about what data to access.
20524
20525Here are the specific requests of this form defined so far.
20526All @samp{@code{qPart}:@var{object}:@code{read}:@dots{}}
20527requests use the same reply formats, listed below.
20528
20529@table @asis
20530@item @code{qPart}:@code{auxv}:@code{read}::@var{offset},@var{length}
20531Access the target's @dfn{auxiliary vector}. @xref{Auxiliary Vector}.
20532Note @var{annex} must be empty.
20533@end table
20534
20535Reply:
20536@table @asis
20537@item @code{OK}
20538The @var{offset} in the request is at the end of the data.
20539There is no more data to be read.
20540
20541@item @var{XX@dots{}}
20542Hex encoded data bytes read.
20543This may be fewer bytes than the @var{length} in the request.
20544
20545@item @code{E00}
20546The request was malformed, or @var{annex} was invalid.
20547
20548@item @code{E}@var{nn}
20549The offset was invalid, or there was an error encountered reading the data.
20550@var{nn} is a hex-encoded @code{errno} value.
20551
20552@item @code{""} (empty)
20553An empty reply indicates the @var{object} or @var{annex} string was not
20554recognized by the stub.
20555@end table
20556
20557@item @code{qPart}:@var{object}:@code{write}:@var{annex}:@var{offset}:@var{data@dots{}}
20558
20559Write uninterpreted bytes into the target's special data area
20560identified by the keyword @code{object},
20561starting at @var{offset} bytes into the data.
20562@var{data@dots{}} is the hex-encoded data to be written.
20563The content and encoding of @var{annex} is specific to the object;
20564it can supply additional details about what data to access.
20565
20566No requests of this form are presently in use. This specification
20567serves as a placeholder to document the common format that new
20568specific request specifications ought to use.
20569
20570Reply:
20571@table @asis
20572@item @var{nn}
20573@var{nn} (hex encoded) is the number of bytes written.
20574This may be fewer bytes than supplied in the request.
20575
20576@item @code{E00}
20577The request was malformed, or @var{annex} was invalid.
20578
20579@item @code{E}@var{nn}
20580The offset was invalid, or there was an error encountered writing the data.
20581@var{nn} is a hex-encoded @code{errno} value.
20582
20583@item @code{""} (empty)
20584An empty reply indicates the @var{object} or @var{annex} string was not
20585recognized by the stub, or that the object does not support writing.
20586@end table
20587
20588@item @code{qPart}:@var{object}:@var{operation}:@dots{}
20589Requests of this form may be added in the future. When a stub does
20590not recognize the @var{object} keyword, or its support for
20591@var{object} does not recognize the @var{operation} keyword,
20592the stub must respond with an empty packet.
ee2d5c50
AC
20593@end table
20594
20595@node Register Packet Format
20596@section Register Packet Format
eb12ee30 20597
8e04817f 20598The following @samp{g}/@samp{G} packets have previously been defined.
ee2d5c50
AC
20599In the below, some thirty-two bit registers are transferred as
20600sixty-four bits. Those registers should be zero/sign extended (which?)
20601to fill the space allocated. Register bytes are transfered in target
20602byte order. The two nibbles within a register byte are transfered
20603most-significant - least-significant.
eb12ee30 20604
ee2d5c50 20605@table @r
eb12ee30 20606
8e04817f 20607@item MIPS32
ee2d5c50 20608
8e04817f
AC
20609All registers are transfered as thirty-two bit quantities in the order:
2061032 general-purpose; sr; lo; hi; bad; cause; pc; 32 floating-point
20611registers; fsr; fir; fp.
eb12ee30 20612
8e04817f 20613@item MIPS64
ee2d5c50 20614
8e04817f
AC
20615All registers are transfered as sixty-four bit quantities (including
20616thirty-two bit registers such as @code{sr}). The ordering is the same
20617as @code{MIPS32}.
eb12ee30 20618
ee2d5c50
AC
20619@end table
20620
20621@node Examples
20622@section Examples
eb12ee30 20623
8e04817f
AC
20624Example sequence of a target being re-started. Notice how the restart
20625does not get any direct output:
eb12ee30 20626
474c8240 20627@smallexample
d2c6833e
AC
20628-> @code{R00}
20629<- @code{+}
8e04817f 20630@emph{target restarts}
d2c6833e 20631-> @code{?}
8e04817f 20632<- @code{+}
d2c6833e
AC
20633<- @code{T001:1234123412341234}
20634-> @code{+}
474c8240 20635@end smallexample
eb12ee30 20636
8e04817f 20637Example sequence of a target being stepped by a single instruction:
eb12ee30 20638
474c8240 20639@smallexample
d2c6833e 20640-> @code{G1445@dots{}}
8e04817f 20641<- @code{+}
d2c6833e
AC
20642-> @code{s}
20643<- @code{+}
20644@emph{time passes}
20645<- @code{T001:1234123412341234}
8e04817f 20646-> @code{+}
d2c6833e 20647-> @code{g}
8e04817f 20648<- @code{+}
d2c6833e
AC
20649<- @code{1455@dots{}}
20650-> @code{+}
474c8240 20651@end smallexample
eb12ee30 20652
0ce1b118
CV
20653@node File-I/O remote protocol extension
20654@section File-I/O remote protocol extension
20655@cindex File-I/O remote protocol extension
20656
20657@menu
20658* File-I/O Overview::
20659* Protocol basics::
1d8b2f28
JB
20660* The F request packet::
20661* The F reply packet::
0ce1b118
CV
20662* Memory transfer::
20663* The Ctrl-C message::
20664* Console I/O::
20665* The isatty call::
20666* The system call::
20667* List of supported calls::
20668* Protocol specific representation of datatypes::
20669* Constants::
20670* File-I/O Examples::
20671@end menu
20672
20673@node File-I/O Overview
20674@subsection File-I/O Overview
20675@cindex file-i/o overview
20676
20677The File I/O remote protocol extension (short: File-I/O) allows the
20678target to use the hosts file system and console I/O when calling various
20679system calls. System calls on the target system are translated into a
20680remote protocol packet to the host system which then performs the needed
20681actions and returns with an adequate response packet to the target system.
20682This simulates file system operations even on targets that lack file systems.
20683
20684The protocol is defined host- and target-system independent. It uses
20685it's own independent representation of datatypes and values. Both,
20686@value{GDBN} and the target's @value{GDBN} stub are responsible for
20687translating the system dependent values into the unified protocol values
20688when data is transmitted.
20689
20690The communication is synchronous. A system call is possible only
20691when GDB is waiting for the @samp{C}, @samp{c}, @samp{S} or @samp{s}
20692packets. While @value{GDBN} handles the request for a system call,
20693the target is stopped to allow deterministic access to the target's
20694memory. Therefore File-I/O is not interuptible by target signals. It
20695is possible to interrupt File-I/O by a user interrupt (Ctrl-C), though.
20696
20697The target's request to perform a host system call does not finish
20698the latest @samp{C}, @samp{c}, @samp{S} or @samp{s} action. That means,
20699after finishing the system call, the target returns to continuing the
20700previous activity (continue, step). No additional continue or step
20701request from @value{GDBN} is required.
20702
20703@smallexample
20704(gdb) continue
20705 <- target requests 'system call X'
20706 target is stopped, @value{GDBN} executes system call
20707 -> GDB returns result
20708 ... target continues, GDB returns to wait for the target
20709 <- target hits breakpoint and sends a Txx packet
20710@end smallexample
20711
20712The protocol is only used for files on the host file system and
20713for I/O on the console. Character or block special devices, pipes,
20714named pipes or sockets or any other communication method on the host
20715system are not supported by this protocol.
20716
20717@node Protocol basics
20718@subsection Protocol basics
20719@cindex protocol basics, file-i/o
20720
20721The File-I/O protocol uses the @code{F} packet, as request as well
20722as as reply packet. Since a File-I/O system call can only occur when
b383017d 20723@value{GDBN} is waiting for the continuing or stepping target, the
0ce1b118
CV
20724File-I/O request is a reply that @value{GDBN} has to expect as a result
20725of a former @samp{C}, @samp{c}, @samp{S} or @samp{s} packet.
20726This @code{F} packet contains all information needed to allow @value{GDBN}
20727to call the appropriate host system call:
20728
20729@itemize @bullet
b383017d 20730@item
0ce1b118
CV
20731A unique identifier for the requested system call.
20732
20733@item
20734All parameters to the system call. Pointers are given as addresses
20735in the target memory address space. Pointers to strings are given as
b383017d 20736pointer/length pair. Numerical values are given as they are.
0ce1b118
CV
20737Numerical control values are given in a protocol specific representation.
20738
20739@end itemize
20740
20741At that point @value{GDBN} has to perform the following actions.
20742
20743@itemize @bullet
b383017d 20744@item
0ce1b118
CV
20745If parameter pointer values are given, which point to data needed as input
20746to a system call, @value{GDBN} requests this data from the target with a
20747standard @code{m} packet request. This additional communication has to be
20748expected by the target implementation and is handled as any other @code{m}
20749packet.
20750
20751@item
20752@value{GDBN} translates all value from protocol representation to host
20753representation as needed. Datatypes are coerced into the host types.
20754
20755@item
20756@value{GDBN} calls the system call
20757
20758@item
20759It then coerces datatypes back to protocol representation.
20760
20761@item
20762If pointer parameters in the request packet point to buffer space in which
20763a system call is expected to copy data to, the data is transmitted to the
20764target using a @code{M} or @code{X} packet. This packet has to be expected
20765by the target implementation and is handled as any other @code{M} or @code{X}
20766packet.
20767
20768@end itemize
20769
20770Eventually @value{GDBN} replies with another @code{F} packet which contains all
20771necessary information for the target to continue. This at least contains
20772
20773@itemize @bullet
20774@item
20775Return value.
20776
20777@item
20778@code{errno}, if has been changed by the system call.
20779
20780@item
20781``Ctrl-C'' flag.
20782
20783@end itemize
20784
20785After having done the needed type and value coercion, the target continues
20786the latest continue or step action.
20787
1d8b2f28 20788@node The F request packet
0ce1b118
CV
20789@subsection The @code{F} request packet
20790@cindex file-i/o request packet
20791@cindex @code{F} request packet
20792
20793The @code{F} request packet has the following format:
20794
20795@table @samp
20796
20797@smallexample
20798@code{F}@var{call-id}@code{,}@var{parameter@dots{}}
20799@end smallexample
20800
20801@var{call-id} is the identifier to indicate the host system call to be called.
20802This is just the name of the function.
20803
20804@var{parameter@dots{}} are the parameters to the system call.
20805
b383017d 20806@end table
0ce1b118
CV
20807
20808Parameters are hexadecimal integer values, either the real values in case
20809of scalar datatypes, as pointers to target buffer space in case of compound
20810datatypes and unspecified memory areas or as pointer/length pairs in case
20811of string parameters. These are appended to the call-id, each separated
20812from its predecessor by a comma. All values are transmitted in ASCII
20813string representation, pointer/length pairs separated by a slash.
20814
1d8b2f28 20815@node The F reply packet
0ce1b118
CV
20816@subsection The @code{F} reply packet
20817@cindex file-i/o reply packet
20818@cindex @code{F} reply packet
20819
20820The @code{F} reply packet has the following format:
20821
20822@table @samp
20823
20824@smallexample
20825@code{F}@var{retcode}@code{,}@var{errno}@code{,}@var{Ctrl-C flag}@code{;}@var{call specific attachment}
20826@end smallexample
20827
20828@var{retcode} is the return code of the system call as hexadecimal value.
20829
20830@var{errno} is the errno set by the call, in protocol specific representation.
20831This parameter can be omitted if the call was successful.
20832
20833@var{Ctrl-C flag} is only send if the user requested a break. In this
20834case, @var{errno} must be send as well, even if the call was successful.
20835The @var{Ctrl-C flag} itself consists of the character 'C':
20836
20837@smallexample
20838F0,0,C
20839@end smallexample
20840
20841@noindent
20842or, if the call was interupted before the host call has been performed:
20843
20844@smallexample
20845F-1,4,C
20846@end smallexample
20847
20848@noindent
20849assuming 4 is the protocol specific representation of @code{EINTR}.
20850
20851@end table
20852
20853@node Memory transfer
20854@subsection Memory transfer
20855@cindex memory transfer, in file-i/o protocol
20856
20857Structured data which is transferred using a memory read or write as e.g.@:
20858a @code{struct stat} is expected to be in a protocol specific format with
20859all scalar multibyte datatypes being big endian. This should be done by
20860the target before the @code{F} packet is sent resp.@: by @value{GDBN} before
20861it transfers memory to the target. Transferred pointers to structured
20862data should point to the already coerced data at any time.
20863
20864@node The Ctrl-C message
20865@subsection The Ctrl-C message
20866@cindex ctrl-c message, in file-i/o protocol
20867
20868A special case is, if the @var{Ctrl-C flag} is set in the @value{GDBN}
20869reply packet. In this case the target should behave, as if it had
20870gotten a break message. The meaning for the target is ``system call
20871interupted by @code{SIGINT}''. Consequentially, the target should actually stop
20872(as with a break message) and return to @value{GDBN} with a @code{T02}
b383017d 20873packet. In this case, it's important for the target to know, in which
0ce1b118
CV
20874state the system call was interrupted. Since this action is by design
20875not an atomic operation, we have to differ between two cases:
20876
20877@itemize @bullet
20878@item
20879The system call hasn't been performed on the host yet.
20880
20881@item
20882The system call on the host has been finished.
20883
20884@end itemize
20885
20886These two states can be distinguished by the target by the value of the
20887returned @code{errno}. If it's the protocol representation of @code{EINTR}, the system
20888call hasn't been performed. This is equivalent to the @code{EINTR} handling
20889on POSIX systems. In any other case, the target may presume that the
20890system call has been finished --- successful or not --- and should behave
20891as if the break message arrived right after the system call.
20892
20893@value{GDBN} must behave reliable. If the system call has not been called
20894yet, @value{GDBN} may send the @code{F} reply immediately, setting @code{EINTR} as
20895@code{errno} in the packet. If the system call on the host has been finished
20896before the user requests a break, the full action must be finshed by
20897@value{GDBN}. This requires sending @code{M} or @code{X} packets as they fit.
20898The @code{F} packet may only be send when either nothing has happened
20899or the full action has been completed.
20900
20901@node Console I/O
20902@subsection Console I/O
20903@cindex console i/o as part of file-i/o
20904
20905By default and if not explicitely closed by the target system, the file
20906descriptors 0, 1 and 2 are connected to the @value{GDBN} console. Output
20907on the @value{GDBN} console is handled as any other file output operation
20908(@code{write(1, @dots{})} or @code{write(2, @dots{})}). Console input is handled
20909by @value{GDBN} so that after the target read request from file descriptor
209100 all following typing is buffered until either one of the following
20911conditions is met:
20912
20913@itemize @bullet
20914@item
20915The user presses @kbd{Ctrl-C}. The behaviour is as explained above, the
20916@code{read}
20917system call is treated as finished.
20918
20919@item
20920The user presses @kbd{Enter}. This is treated as end of input with a trailing
20921line feed.
20922
20923@item
20924The user presses @kbd{Ctrl-D}. This is treated as end of input. No trailing
20925character, especially no Ctrl-D is appended to the input.
20926
20927@end itemize
20928
20929If the user has typed more characters as fit in the buffer given to
20930the read call, the trailing characters are buffered in @value{GDBN} until
20931either another @code{read(0, @dots{})} is requested by the target or debugging
20932is stopped on users request.
20933
20934@node The isatty call
20935@subsection The isatty(3) call
20936@cindex isatty call, file-i/o protocol
20937
20938A special case in this protocol is the library call @code{isatty} which
20939is implemented as it's own call inside of this protocol. It returns
209401 to the target if the file descriptor given as parameter is attached
20941to the @value{GDBN} console, 0 otherwise. Implementing through system calls
20942would require implementing @code{ioctl} and would be more complex than
20943needed.
20944
20945@node The system call
20946@subsection The system(3) call
20947@cindex system call, file-i/o protocol
20948
20949The other special case in this protocol is the @code{system} call which
20950is implemented as it's own call, too. @value{GDBN} is taking over the full
20951task of calling the necessary host calls to perform the @code{system}
20952call. The return value of @code{system} is simplified before it's returned
20953to the target. Basically, the only signal transmitted back is @code{EINTR}
20954in case the user pressed @kbd{Ctrl-C}. Otherwise the return value consists
20955entirely of the exit status of the called command.
20956
20957Due to security concerns, the @code{system} call is refused to be called
b383017d 20958by @value{GDBN} by default. The user has to allow this call explicitly by
0ce1b118
CV
20959entering
20960
20961@table @samp
20962@kindex set remote system-call-allowed 1
20963@item @code{set remote system-call-allowed 1}
20964@end table
20965
20966Disabling the @code{system} call is done by
20967
20968@table @samp
20969@kindex set remote system-call-allowed 0
20970@item @code{set remote system-call-allowed 0}
20971@end table
20972
20973The current setting is shown by typing
20974
20975@table @samp
20976@kindex show remote system-call-allowed
20977@item @code{show remote system-call-allowed}
20978@end table
20979
20980@node List of supported calls
20981@subsection List of supported calls
20982@cindex list of supported file-i/o calls
20983
20984@menu
20985* open::
20986* close::
20987* read::
20988* write::
20989* lseek::
20990* rename::
20991* unlink::
20992* stat/fstat::
20993* gettimeofday::
20994* isatty::
20995* system::
20996@end menu
20997
20998@node open
20999@unnumberedsubsubsec open
21000@cindex open, file-i/o system call
21001
21002@smallexample
21003@exdent Synopsis:
21004int open(const char *pathname, int flags);
21005int open(const char *pathname, int flags, mode_t mode);
21006
b383017d 21007@exdent Request:
0ce1b118
CV
21008Fopen,pathptr/len,flags,mode
21009@end smallexample
21010
21011@noindent
21012@code{flags} is the bitwise or of the following values:
21013
21014@table @code
b383017d 21015@item O_CREAT
0ce1b118
CV
21016If the file does not exist it will be created. The host
21017rules apply as far as file ownership and time stamps
21018are concerned.
21019
b383017d 21020@item O_EXCL
0ce1b118
CV
21021When used with O_CREAT, if the file already exists it is
21022an error and open() fails.
21023
b383017d 21024@item O_TRUNC
0ce1b118
CV
21025If the file already exists and the open mode allows
21026writing (O_RDWR or O_WRONLY is given) it will be
21027truncated to length 0.
21028
b383017d 21029@item O_APPEND
0ce1b118
CV
21030The file is opened in append mode.
21031
b383017d 21032@item O_RDONLY
0ce1b118
CV
21033The file is opened for reading only.
21034
b383017d 21035@item O_WRONLY
0ce1b118
CV
21036The file is opened for writing only.
21037
b383017d 21038@item O_RDWR
0ce1b118
CV
21039The file is opened for reading and writing.
21040
21041@noindent
21042Each other bit is silently ignored.
21043
21044@end table
21045
21046@noindent
21047@code{mode} is the bitwise or of the following values:
21048
21049@table @code
b383017d 21050@item S_IRUSR
0ce1b118
CV
21051User has read permission.
21052
b383017d 21053@item S_IWUSR
0ce1b118
CV
21054User has write permission.
21055
b383017d 21056@item S_IRGRP
0ce1b118
CV
21057Group has read permission.
21058
b383017d 21059@item S_IWGRP
0ce1b118
CV
21060Group has write permission.
21061
b383017d 21062@item S_IROTH
0ce1b118
CV
21063Others have read permission.
21064
b383017d 21065@item S_IWOTH
0ce1b118
CV
21066Others have write permission.
21067
21068@noindent
21069Each other bit is silently ignored.
21070
21071@end table
21072
21073@smallexample
21074@exdent Return value:
21075open returns the new file descriptor or -1 if an error
21076occured.
21077
21078@exdent Errors:
21079@end smallexample
21080
21081@table @code
b383017d 21082@item EEXIST
0ce1b118
CV
21083pathname already exists and O_CREAT and O_EXCL were used.
21084
b383017d 21085@item EISDIR
0ce1b118
CV
21086pathname refers to a directory.
21087
b383017d 21088@item EACCES
0ce1b118
CV
21089The requested access is not allowed.
21090
21091@item ENAMETOOLONG
21092pathname was too long.
21093
b383017d 21094@item ENOENT
0ce1b118
CV
21095A directory component in pathname does not exist.
21096
b383017d 21097@item ENODEV
0ce1b118
CV
21098pathname refers to a device, pipe, named pipe or socket.
21099
b383017d 21100@item EROFS
0ce1b118
CV
21101pathname refers to a file on a read-only filesystem and
21102write access was requested.
21103
b383017d 21104@item EFAULT
0ce1b118
CV
21105pathname is an invalid pointer value.
21106
b383017d 21107@item ENOSPC
0ce1b118
CV
21108No space on device to create the file.
21109
b383017d 21110@item EMFILE
0ce1b118
CV
21111The process already has the maximum number of files open.
21112
b383017d 21113@item ENFILE
0ce1b118
CV
21114The limit on the total number of files open on the system
21115has been reached.
21116
b383017d 21117@item EINTR
0ce1b118
CV
21118The call was interrupted by the user.
21119@end table
21120
21121@node close
21122@unnumberedsubsubsec close
21123@cindex close, file-i/o system call
21124
21125@smallexample
b383017d 21126@exdent Synopsis:
0ce1b118
CV
21127int close(int fd);
21128
b383017d 21129@exdent Request:
0ce1b118
CV
21130Fclose,fd
21131
21132@exdent Return value:
21133close returns zero on success, or -1 if an error occurred.
21134
21135@exdent Errors:
21136@end smallexample
21137
21138@table @code
b383017d 21139@item EBADF
0ce1b118
CV
21140fd isn't a valid open file descriptor.
21141
b383017d 21142@item EINTR
0ce1b118
CV
21143The call was interrupted by the user.
21144@end table
21145
21146@node read
21147@unnumberedsubsubsec read
21148@cindex read, file-i/o system call
21149
21150@smallexample
b383017d 21151@exdent Synopsis:
0ce1b118
CV
21152int read(int fd, void *buf, unsigned int count);
21153
b383017d 21154@exdent Request:
0ce1b118
CV
21155Fread,fd,bufptr,count
21156
21157@exdent Return value:
21158On success, the number of bytes read is returned.
21159Zero indicates end of file. If count is zero, read
b383017d 21160returns zero as well. On error, -1 is returned.
0ce1b118
CV
21161
21162@exdent Errors:
21163@end smallexample
21164
21165@table @code
b383017d 21166@item EBADF
0ce1b118
CV
21167fd is not a valid file descriptor or is not open for
21168reading.
21169
b383017d 21170@item EFAULT
0ce1b118
CV
21171buf is an invalid pointer value.
21172
b383017d 21173@item EINTR
0ce1b118
CV
21174The call was interrupted by the user.
21175@end table
21176
21177@node write
21178@unnumberedsubsubsec write
21179@cindex write, file-i/o system call
21180
21181@smallexample
b383017d 21182@exdent Synopsis:
0ce1b118
CV
21183int write(int fd, const void *buf, unsigned int count);
21184
b383017d 21185@exdent Request:
0ce1b118
CV
21186Fwrite,fd,bufptr,count
21187
21188@exdent Return value:
21189On success, the number of bytes written are returned.
21190Zero indicates nothing was written. On error, -1
21191is returned.
21192
21193@exdent Errors:
21194@end smallexample
21195
21196@table @code
b383017d 21197@item EBADF
0ce1b118
CV
21198fd is not a valid file descriptor or is not open for
21199writing.
21200
b383017d 21201@item EFAULT
0ce1b118
CV
21202buf is an invalid pointer value.
21203
b383017d 21204@item EFBIG
0ce1b118
CV
21205An attempt was made to write a file that exceeds the
21206host specific maximum file size allowed.
21207
b383017d 21208@item ENOSPC
0ce1b118
CV
21209No space on device to write the data.
21210
b383017d 21211@item EINTR
0ce1b118
CV
21212The call was interrupted by the user.
21213@end table
21214
21215@node lseek
21216@unnumberedsubsubsec lseek
21217@cindex lseek, file-i/o system call
21218
21219@smallexample
b383017d 21220@exdent Synopsis:
0ce1b118
CV
21221long lseek (int fd, long offset, int flag);
21222
b383017d 21223@exdent Request:
0ce1b118
CV
21224Flseek,fd,offset,flag
21225@end smallexample
21226
21227@code{flag} is one of:
21228
21229@table @code
b383017d 21230@item SEEK_SET
0ce1b118
CV
21231The offset is set to offset bytes.
21232
b383017d 21233@item SEEK_CUR
0ce1b118
CV
21234The offset is set to its current location plus offset
21235bytes.
21236
b383017d 21237@item SEEK_END
0ce1b118
CV
21238The offset is set to the size of the file plus offset
21239bytes.
21240@end table
21241
21242@smallexample
21243@exdent Return value:
21244On success, the resulting unsigned offset in bytes from
21245the beginning of the file is returned. Otherwise, a
21246value of -1 is returned.
21247
21248@exdent Errors:
21249@end smallexample
21250
21251@table @code
b383017d 21252@item EBADF
0ce1b118
CV
21253fd is not a valid open file descriptor.
21254
b383017d 21255@item ESPIPE
0ce1b118
CV
21256fd is associated with the @value{GDBN} console.
21257
b383017d 21258@item EINVAL
0ce1b118
CV
21259flag is not a proper value.
21260
b383017d 21261@item EINTR
0ce1b118
CV
21262The call was interrupted by the user.
21263@end table
21264
21265@node rename
21266@unnumberedsubsubsec rename
21267@cindex rename, file-i/o system call
21268
21269@smallexample
b383017d 21270@exdent Synopsis:
0ce1b118
CV
21271int rename(const char *oldpath, const char *newpath);
21272
b383017d 21273@exdent Request:
0ce1b118
CV
21274Frename,oldpathptr/len,newpathptr/len
21275
21276@exdent Return value:
21277On success, zero is returned. On error, -1 is returned.
21278
21279@exdent Errors:
21280@end smallexample
21281
21282@table @code
b383017d 21283@item EISDIR
0ce1b118
CV
21284newpath is an existing directory, but oldpath is not a
21285directory.
21286
b383017d 21287@item EEXIST
0ce1b118
CV
21288newpath is a non-empty directory.
21289
b383017d 21290@item EBUSY
0ce1b118
CV
21291oldpath or newpath is a directory that is in use by some
21292process.
21293
b383017d 21294@item EINVAL
0ce1b118
CV
21295An attempt was made to make a directory a subdirectory
21296of itself.
21297
b383017d 21298@item ENOTDIR
0ce1b118
CV
21299A component used as a directory in oldpath or new
21300path is not a directory. Or oldpath is a directory
21301and newpath exists but is not a directory.
21302
b383017d 21303@item EFAULT
0ce1b118
CV
21304oldpathptr or newpathptr are invalid pointer values.
21305
b383017d 21306@item EACCES
0ce1b118
CV
21307No access to the file or the path of the file.
21308
21309@item ENAMETOOLONG
b383017d 21310
0ce1b118
CV
21311oldpath or newpath was too long.
21312
b383017d 21313@item ENOENT
0ce1b118
CV
21314A directory component in oldpath or newpath does not exist.
21315
b383017d 21316@item EROFS
0ce1b118
CV
21317The file is on a read-only filesystem.
21318
b383017d 21319@item ENOSPC
0ce1b118
CV
21320The device containing the file has no room for the new
21321directory entry.
21322
b383017d 21323@item EINTR
0ce1b118
CV
21324The call was interrupted by the user.
21325@end table
21326
21327@node unlink
21328@unnumberedsubsubsec unlink
21329@cindex unlink, file-i/o system call
21330
21331@smallexample
b383017d 21332@exdent Synopsis:
0ce1b118
CV
21333int unlink(const char *pathname);
21334
b383017d 21335@exdent Request:
0ce1b118
CV
21336Funlink,pathnameptr/len
21337
21338@exdent Return value:
21339On success, zero is returned. On error, -1 is returned.
21340
21341@exdent Errors:
21342@end smallexample
21343
21344@table @code
b383017d 21345@item EACCES
0ce1b118
CV
21346No access to the file or the path of the file.
21347
b383017d 21348@item EPERM
0ce1b118
CV
21349The system does not allow unlinking of directories.
21350
b383017d 21351@item EBUSY
0ce1b118
CV
21352The file pathname cannot be unlinked because it's
21353being used by another process.
21354
b383017d 21355@item EFAULT
0ce1b118
CV
21356pathnameptr is an invalid pointer value.
21357
21358@item ENAMETOOLONG
21359pathname was too long.
21360
b383017d 21361@item ENOENT
0ce1b118
CV
21362A directory component in pathname does not exist.
21363
b383017d 21364@item ENOTDIR
0ce1b118
CV
21365A component of the path is not a directory.
21366
b383017d 21367@item EROFS
0ce1b118
CV
21368The file is on a read-only filesystem.
21369
b383017d 21370@item EINTR
0ce1b118
CV
21371The call was interrupted by the user.
21372@end table
21373
21374@node stat/fstat
21375@unnumberedsubsubsec stat/fstat
21376@cindex fstat, file-i/o system call
21377@cindex stat, file-i/o system call
21378
21379@smallexample
b383017d 21380@exdent Synopsis:
0ce1b118
CV
21381int stat(const char *pathname, struct stat *buf);
21382int fstat(int fd, struct stat *buf);
21383
b383017d 21384@exdent Request:
0ce1b118
CV
21385Fstat,pathnameptr/len,bufptr
21386Ffstat,fd,bufptr
21387
21388@exdent Return value:
21389On success, zero is returned. On error, -1 is returned.
21390
21391@exdent Errors:
21392@end smallexample
21393
21394@table @code
b383017d 21395@item EBADF
0ce1b118
CV
21396fd is not a valid open file.
21397
b383017d 21398@item ENOENT
0ce1b118
CV
21399A directory component in pathname does not exist or the
21400path is an empty string.
21401
b383017d 21402@item ENOTDIR
0ce1b118
CV
21403A component of the path is not a directory.
21404
b383017d 21405@item EFAULT
0ce1b118
CV
21406pathnameptr is an invalid pointer value.
21407
b383017d 21408@item EACCES
0ce1b118
CV
21409No access to the file or the path of the file.
21410
21411@item ENAMETOOLONG
21412pathname was too long.
21413
b383017d 21414@item EINTR
0ce1b118
CV
21415The call was interrupted by the user.
21416@end table
21417
21418@node gettimeofday
21419@unnumberedsubsubsec gettimeofday
21420@cindex gettimeofday, file-i/o system call
21421
21422@smallexample
b383017d 21423@exdent Synopsis:
0ce1b118
CV
21424int gettimeofday(struct timeval *tv, void *tz);
21425
b383017d 21426@exdent Request:
0ce1b118
CV
21427Fgettimeofday,tvptr,tzptr
21428
21429@exdent Return value:
21430On success, 0 is returned, -1 otherwise.
21431
21432@exdent Errors:
21433@end smallexample
21434
21435@table @code
b383017d 21436@item EINVAL
0ce1b118
CV
21437tz is a non-NULL pointer.
21438
b383017d 21439@item EFAULT
0ce1b118
CV
21440tvptr and/or tzptr is an invalid pointer value.
21441@end table
21442
21443@node isatty
21444@unnumberedsubsubsec isatty
21445@cindex isatty, file-i/o system call
21446
21447@smallexample
b383017d 21448@exdent Synopsis:
0ce1b118
CV
21449int isatty(int fd);
21450
b383017d 21451@exdent Request:
0ce1b118
CV
21452Fisatty,fd
21453
21454@exdent Return value:
21455Returns 1 if fd refers to the @value{GDBN} console, 0 otherwise.
21456
21457@exdent Errors:
21458@end smallexample
21459
21460@table @code
b383017d 21461@item EINTR
0ce1b118
CV
21462The call was interrupted by the user.
21463@end table
21464
21465@node system
21466@unnumberedsubsubsec system
21467@cindex system, file-i/o system call
21468
21469@smallexample
b383017d 21470@exdent Synopsis:
0ce1b118
CV
21471int system(const char *command);
21472
b383017d 21473@exdent Request:
0ce1b118
CV
21474Fsystem,commandptr/len
21475
21476@exdent Return value:
21477The value returned is -1 on error and the return status
21478of the command otherwise. Only the exit status of the
21479command is returned, which is extracted from the hosts
21480system return value by calling WEXITSTATUS(retval).
21481In case /bin/sh could not be executed, 127 is returned.
21482
21483@exdent Errors:
21484@end smallexample
21485
21486@table @code
b383017d 21487@item EINTR
0ce1b118
CV
21488The call was interrupted by the user.
21489@end table
21490
21491@node Protocol specific representation of datatypes
21492@subsection Protocol specific representation of datatypes
21493@cindex protocol specific representation of datatypes, in file-i/o protocol
21494
21495@menu
21496* Integral datatypes::
21497* Pointer values::
21498* struct stat::
21499* struct timeval::
21500@end menu
21501
21502@node Integral datatypes
21503@unnumberedsubsubsec Integral datatypes
21504@cindex integral datatypes, in file-i/o protocol
21505
21506The integral datatypes used in the system calls are
21507
21508@smallexample
21509int@r{,} unsigned int@r{,} long@r{,} unsigned long@r{,} mode_t @r{and} time_t
21510@end smallexample
21511
21512@code{Int}, @code{unsigned int}, @code{mode_t} and @code{time_t} are
21513implemented as 32 bit values in this protocol.
21514
b383017d
RM
21515@code{Long} and @code{unsigned long} are implemented as 64 bit types.
21516
0ce1b118
CV
21517@xref{Limits}, for corresponding MIN and MAX values (similar to those
21518in @file{limits.h}) to allow range checking on host and target.
21519
21520@code{time_t} datatypes are defined as seconds since the Epoch.
21521
21522All integral datatypes transferred as part of a memory read or write of a
21523structured datatype e.g.@: a @code{struct stat} have to be given in big endian
21524byte order.
21525
21526@node Pointer values
21527@unnumberedsubsubsec Pointer values
21528@cindex pointer values, in file-i/o protocol
21529
21530Pointers to target data are transmitted as they are. An exception
21531is made for pointers to buffers for which the length isn't
21532transmitted as part of the function call, namely strings. Strings
21533are transmitted as a pointer/length pair, both as hex values, e.g.@:
21534
21535@smallexample
21536@code{1aaf/12}
21537@end smallexample
21538
21539@noindent
21540which is a pointer to data of length 18 bytes at position 0x1aaf.
21541The length is defined as the full string length in bytes, including
21542the trailing null byte. Example:
21543
21544@smallexample
21545``hello, world'' at address 0x123456
21546@end smallexample
21547
21548@noindent
21549is transmitted as
21550
21551@smallexample
21552@code{123456/d}
21553@end smallexample
21554
21555@node struct stat
21556@unnumberedsubsubsec struct stat
21557@cindex struct stat, in file-i/o protocol
21558
21559The buffer of type struct stat used by the target and @value{GDBN} is defined
21560as follows:
21561
21562@smallexample
21563struct stat @{
21564 unsigned int st_dev; /* device */
21565 unsigned int st_ino; /* inode */
21566 mode_t st_mode; /* protection */
21567 unsigned int st_nlink; /* number of hard links */
21568 unsigned int st_uid; /* user ID of owner */
21569 unsigned int st_gid; /* group ID of owner */
21570 unsigned int st_rdev; /* device type (if inode device) */
21571 unsigned long st_size; /* total size, in bytes */
21572 unsigned long st_blksize; /* blocksize for filesystem I/O */
21573 unsigned long st_blocks; /* number of blocks allocated */
21574 time_t st_atime; /* time of last access */
21575 time_t st_mtime; /* time of last modification */
21576 time_t st_ctime; /* time of last change */
21577@};
21578@end smallexample
21579
21580The integral datatypes are conforming to the definitions given in the
21581approriate section (see @ref{Integral datatypes}, for details) so this
21582structure is of size 64 bytes.
21583
21584The values of several fields have a restricted meaning and/or
21585range of values.
21586
21587@smallexample
21588st_dev: 0 file
21589 1 console
21590
21591st_ino: No valid meaning for the target. Transmitted unchanged.
21592
21593st_mode: Valid mode bits are described in Appendix C. Any other
21594 bits have currently no meaning for the target.
21595
21596st_uid: No valid meaning for the target. Transmitted unchanged.
21597
21598st_gid: No valid meaning for the target. Transmitted unchanged.
21599
21600st_rdev: No valid meaning for the target. Transmitted unchanged.
21601
21602st_atime, st_mtime, st_ctime:
21603 These values have a host and file system dependent
21604 accuracy. Especially on Windows hosts the file systems
21605 don't support exact timing values.
21606@end smallexample
21607
21608The target gets a struct stat of the above representation and is
21609responsible to coerce it to the target representation before
21610continuing.
21611
21612Note that due to size differences between the host and target
21613representation of stat members, these members could eventually
21614get truncated on the target.
21615
21616@node struct timeval
21617@unnumberedsubsubsec struct timeval
21618@cindex struct timeval, in file-i/o protocol
21619
21620The buffer of type struct timeval used by the target and @value{GDBN}
21621is defined as follows:
21622
21623@smallexample
b383017d 21624struct timeval @{
0ce1b118
CV
21625 time_t tv_sec; /* second */
21626 long tv_usec; /* microsecond */
21627@};
21628@end smallexample
21629
21630The integral datatypes are conforming to the definitions given in the
21631approriate section (see @ref{Integral datatypes}, for details) so this
21632structure is of size 8 bytes.
21633
21634@node Constants
21635@subsection Constants
21636@cindex constants, in file-i/o protocol
21637
21638The following values are used for the constants inside of the
21639protocol. @value{GDBN} and target are resposible to translate these
21640values before and after the call as needed.
21641
21642@menu
21643* Open flags::
21644* mode_t values::
21645* Errno values::
21646* Lseek flags::
21647* Limits::
21648@end menu
21649
21650@node Open flags
21651@unnumberedsubsubsec Open flags
21652@cindex open flags, in file-i/o protocol
21653
21654All values are given in hexadecimal representation.
21655
21656@smallexample
21657 O_RDONLY 0x0
21658 O_WRONLY 0x1
21659 O_RDWR 0x2
21660 O_APPEND 0x8
21661 O_CREAT 0x200
21662 O_TRUNC 0x400
21663 O_EXCL 0x800
21664@end smallexample
21665
21666@node mode_t values
21667@unnumberedsubsubsec mode_t values
21668@cindex mode_t values, in file-i/o protocol
21669
21670All values are given in octal representation.
21671
21672@smallexample
21673 S_IFREG 0100000
21674 S_IFDIR 040000
21675 S_IRUSR 0400
21676 S_IWUSR 0200
21677 S_IXUSR 0100
21678 S_IRGRP 040
21679 S_IWGRP 020
21680 S_IXGRP 010
21681 S_IROTH 04
21682 S_IWOTH 02
21683 S_IXOTH 01
21684@end smallexample
21685
21686@node Errno values
21687@unnumberedsubsubsec Errno values
21688@cindex errno values, in file-i/o protocol
21689
21690All values are given in decimal representation.
21691
21692@smallexample
21693 EPERM 1
21694 ENOENT 2
21695 EINTR 4
21696 EBADF 9
21697 EACCES 13
21698 EFAULT 14
21699 EBUSY 16
21700 EEXIST 17
21701 ENODEV 19
21702 ENOTDIR 20
21703 EISDIR 21
21704 EINVAL 22
21705 ENFILE 23
21706 EMFILE 24
21707 EFBIG 27
21708 ENOSPC 28
21709 ESPIPE 29
21710 EROFS 30
21711 ENAMETOOLONG 91
21712 EUNKNOWN 9999
21713@end smallexample
21714
21715 EUNKNOWN is used as a fallback error value if a host system returns
21716 any error value not in the list of supported error numbers.
21717
21718@node Lseek flags
21719@unnumberedsubsubsec Lseek flags
21720@cindex lseek flags, in file-i/o protocol
21721
21722@smallexample
21723 SEEK_SET 0
21724 SEEK_CUR 1
21725 SEEK_END 2
21726@end smallexample
21727
21728@node Limits
21729@unnumberedsubsubsec Limits
21730@cindex limits, in file-i/o protocol
21731
21732All values are given in decimal representation.
21733
21734@smallexample
21735 INT_MIN -2147483648
21736 INT_MAX 2147483647
21737 UINT_MAX 4294967295
21738 LONG_MIN -9223372036854775808
21739 LONG_MAX 9223372036854775807
21740 ULONG_MAX 18446744073709551615
21741@end smallexample
21742
21743@node File-I/O Examples
21744@subsection File-I/O Examples
21745@cindex file-i/o examples
21746
21747Example sequence of a write call, file descriptor 3, buffer is at target
21748address 0x1234, 6 bytes should be written:
21749
21750@smallexample
21751<- @code{Fwrite,3,1234,6}
21752@emph{request memory read from target}
21753-> @code{m1234,6}
21754<- XXXXXX
21755@emph{return "6 bytes written"}
21756-> @code{F6}
21757@end smallexample
21758
21759Example sequence of a read call, file descriptor 3, buffer is at target
21760address 0x1234, 6 bytes should be read:
21761
21762@smallexample
21763<- @code{Fread,3,1234,6}
21764@emph{request memory write to target}
21765-> @code{X1234,6:XXXXXX}
21766@emph{return "6 bytes read"}
21767-> @code{F6}
21768@end smallexample
21769
21770Example sequence of a read call, call fails on the host due to invalid
21771file descriptor (EBADF):
21772
21773@smallexample
21774<- @code{Fread,3,1234,6}
21775-> @code{F-1,9}
21776@end smallexample
21777
21778Example sequence of a read call, user presses Ctrl-C before syscall on
21779host is called:
21780
21781@smallexample
21782<- @code{Fread,3,1234,6}
21783-> @code{F-1,4,C}
21784<- @code{T02}
21785@end smallexample
21786
21787Example sequence of a read call, user presses Ctrl-C after syscall on
21788host is called:
21789
21790@smallexample
21791<- @code{Fread,3,1234,6}
21792-> @code{X1234,6:XXXXXX}
21793<- @code{T02}
21794@end smallexample
21795
f418dd93
DJ
21796@include agentexpr.texi
21797
aab4e0ec 21798@include gpl.texi
eb12ee30 21799
2154891a 21800@raisesections
6826cf00 21801@include fdl.texi
2154891a 21802@lowersections
6826cf00 21803
6d2ebf8b 21804@node Index
c906108c
SS
21805@unnumbered Index
21806
21807@printindex cp
21808
21809@tex
21810% I think something like @colophon should be in texinfo. In the
21811% meantime:
21812\long\def\colophon{\hbox to0pt{}\vfill
21813\centerline{The body of this manual is set in}
21814\centerline{\fontname\tenrm,}
21815\centerline{with headings in {\bf\fontname\tenbf}}
21816\centerline{and examples in {\tt\fontname\tentt}.}
21817\centerline{{\it\fontname\tenit\/},}
21818\centerline{{\bf\fontname\tenbf}, and}
21819\centerline{{\sl\fontname\tensl\/}}
21820\centerline{are used for emphasis.}\vfill}
21821\page\colophon
21822% Blame: doc@cygnus.com, 1991.
21823@end tex
21824
c906108c 21825@bye