]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blame - gdb/doc/gdb.texinfo
* netbsd-core.c (netbsd_core_file_p): Make `i' unsigned.
[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
f018e82f
EZ
1763@cindex elaboration phase
1764Some programs contain an @dfn{elaboration} phase where some startup code is
1765executed before the main procedure is called. This depends on the
1766languages used to write your program. In C@t{++}, for instance,
4e8b0763
JB
1767constructors for static and global objects are executed before
1768@code{main} is called. It is therefore possible that the debugger stops
1769before reaching the main procedure. However, the temporary breakpoint
1770will remain to halt execution.
1771
1772Specify the arguments to give to your program as arguments to the
1773@samp{start} command. These arguments will be given verbatim to the
1774underlying @samp{run} command. Note that the same arguments will be
1775reused if no argument is provided during subsequent calls to
1776@samp{start} or @samp{run}.
1777
1778It is sometimes necessary to debug the program during elaboration. In
1779these cases, using the @code{start} command would stop the execution of
1780your program too late, as the program would have already completed the
1781elaboration phase. Under these circumstances, insert breakpoints in your
1782elaboration code before running your program.
1783@end table
1784
6d2ebf8b 1785@node Arguments
c906108c
SS
1786@section Your program's arguments
1787
1788@cindex arguments (to your program)
1789The arguments to your program can be specified by the arguments of the
5d161b24 1790@code{run} command.
c906108c
SS
1791They are passed to a shell, which expands wildcard characters and
1792performs redirection of I/O, and thence to your program. Your
1793@code{SHELL} environment variable (if it exists) specifies what shell
1794@value{GDBN} uses. If you do not define @code{SHELL}, @value{GDBN} uses
d4f3574e
SS
1795the default shell (@file{/bin/sh} on Unix).
1796
1797On non-Unix systems, the program is usually invoked directly by
1798@value{GDBN}, which emulates I/O redirection via the appropriate system
1799calls, and the wildcard characters are expanded by the startup code of
1800the program, not by the shell.
c906108c
SS
1801
1802@code{run} with no arguments uses the same arguments used by the previous
1803@code{run}, or those set by the @code{set args} command.
1804
c906108c 1805@table @code
41afff9a 1806@kindex set args
c906108c
SS
1807@item set args
1808Specify the arguments to be used the next time your program is run. If
1809@code{set args} has no arguments, @code{run} executes your program
1810with no arguments. Once you have run your program with arguments,
1811using @code{set args} before the next @code{run} is the only way to run
1812it again without arguments.
1813
1814@kindex show args
1815@item show args
1816Show the arguments to give your program when it is started.
1817@end table
1818
6d2ebf8b 1819@node Environment
c906108c
SS
1820@section Your program's environment
1821
1822@cindex environment (of your program)
1823The @dfn{environment} consists of a set of environment variables and
1824their values. Environment variables conventionally record such things as
1825your user name, your home directory, your terminal type, and your search
1826path for programs to run. Usually you set up environment variables with
1827the shell and they are inherited by all the other programs you run. When
1828debugging, it can be useful to try running your program with a modified
1829environment without having to start @value{GDBN} over again.
1830
1831@table @code
1832@kindex path
1833@item path @var{directory}
1834Add @var{directory} to the front of the @code{PATH} environment variable
17cc6a06
EZ
1835(the search path for executables) that will be passed to your program.
1836The value of @code{PATH} used by @value{GDBN} does not change.
d4f3574e
SS
1837You may specify several directory names, separated by whitespace or by a
1838system-dependent separator character (@samp{:} on Unix, @samp{;} on
1839MS-DOS and MS-Windows). If @var{directory} is already in the path, it
1840is moved to the front, so it is searched sooner.
c906108c
SS
1841
1842You can use the string @samp{$cwd} to refer to whatever is the current
1843working directory at the time @value{GDBN} searches the path. If you
1844use @samp{.} instead, it refers to the directory where you executed the
1845@code{path} command. @value{GDBN} replaces @samp{.} in the
1846@var{directory} argument (with the current path) before adding
1847@var{directory} to the search path.
1848@c 'path' is explicitly nonrepeatable, but RMS points out it is silly to
1849@c document that, since repeating it would be a no-op.
1850
1851@kindex show paths
1852@item show paths
1853Display the list of search paths for executables (the @code{PATH}
1854environment variable).
1855
1856@kindex show environment
1857@item show environment @r{[}@var{varname}@r{]}
1858Print the value of environment variable @var{varname} to be given to
1859your program when it starts. If you do not supply @var{varname},
1860print the names and values of all environment variables to be given to
1861your program. You can abbreviate @code{environment} as @code{env}.
1862
1863@kindex set environment
53a5351d 1864@item set environment @var{varname} @r{[}=@var{value}@r{]}
c906108c
SS
1865Set environment variable @var{varname} to @var{value}. The value
1866changes for your program only, not for @value{GDBN} itself. @var{value} may
1867be any string; the values of environment variables are just strings, and
1868any interpretation is supplied by your program itself. The @var{value}
1869parameter is optional; if it is eliminated, the variable is set to a
1870null value.
1871@c "any string" here does not include leading, trailing
1872@c blanks. Gnu asks: does anyone care?
1873
1874For example, this command:
1875
474c8240 1876@smallexample
c906108c 1877set env USER = foo
474c8240 1878@end smallexample
c906108c
SS
1879
1880@noindent
d4f3574e 1881tells the debugged program, when subsequently run, that its user is named
c906108c
SS
1882@samp{foo}. (The spaces around @samp{=} are used for clarity here; they
1883are not actually required.)
1884
1885@kindex unset environment
1886@item unset environment @var{varname}
1887Remove variable @var{varname} from the environment to be passed to your
1888program. This is different from @samp{set env @var{varname} =};
1889@code{unset environment} removes the variable from the environment,
1890rather than assigning it an empty value.
1891@end table
1892
d4f3574e
SS
1893@emph{Warning:} On Unix systems, @value{GDBN} runs your program using
1894the shell indicated
c906108c
SS
1895by your @code{SHELL} environment variable if it exists (or
1896@code{/bin/sh} if not). If your @code{SHELL} variable names a shell
1897that runs an initialization file---such as @file{.cshrc} for C-shell, or
1898@file{.bashrc} for BASH---any variables you set in that file affect
1899your program. You may wish to move setting of environment variables to
1900files that are only run when you sign on, such as @file{.login} or
1901@file{.profile}.
1902
6d2ebf8b 1903@node Working Directory
c906108c
SS
1904@section Your program's working directory
1905
1906@cindex working directory (of your program)
1907Each time you start your program with @code{run}, it inherits its
1908working directory from the current working directory of @value{GDBN}.
1909The @value{GDBN} working directory is initially whatever it inherited
1910from its parent process (typically the shell), but you can specify a new
1911working directory in @value{GDBN} with the @code{cd} command.
1912
1913The @value{GDBN} working directory also serves as a default for the commands
1914that specify files for @value{GDBN} to operate on. @xref{Files, ,Commands to
1915specify files}.
1916
1917@table @code
1918@kindex cd
1919@item cd @var{directory}
1920Set the @value{GDBN} working directory to @var{directory}.
1921
1922@kindex pwd
1923@item pwd
1924Print the @value{GDBN} working directory.
1925@end table
1926
60bf7e09
EZ
1927It is generally impossible to find the current working directory of
1928the process being debugged (since a program can change its directory
1929during its run). If you work on a system where @value{GDBN} is
1930configured with the @file{/proc} support, you can use the @code{info
1931proc} command (@pxref{SVR4 Process Information}) to find out the
1932current working directory of the debuggee.
1933
6d2ebf8b 1934@node Input/Output
c906108c
SS
1935@section Your program's input and output
1936
1937@cindex redirection
1938@cindex i/o
1939@cindex terminal
1940By default, the program you run under @value{GDBN} does input and output to
5d161b24 1941the same terminal that @value{GDBN} uses. @value{GDBN} switches the terminal
c906108c
SS
1942to its own terminal modes to interact with you, but it records the terminal
1943modes your program was using and switches back to them when you continue
1944running your program.
1945
1946@table @code
1947@kindex info terminal
1948@item info terminal
1949Displays information recorded by @value{GDBN} about the terminal modes your
1950program is using.
1951@end table
1952
1953You can redirect your program's input and/or output using shell
1954redirection with the @code{run} command. For example,
1955
474c8240 1956@smallexample
c906108c 1957run > outfile
474c8240 1958@end smallexample
c906108c
SS
1959
1960@noindent
1961starts your program, diverting its output to the file @file{outfile}.
1962
1963@kindex tty
1964@cindex controlling terminal
1965Another way to specify where your program should do input and output is
1966with the @code{tty} command. This command accepts a file name as
1967argument, and causes this file to be the default for future @code{run}
1968commands. It also resets the controlling terminal for the child
1969process, for future @code{run} commands. For example,
1970
474c8240 1971@smallexample
c906108c 1972tty /dev/ttyb
474c8240 1973@end smallexample
c906108c
SS
1974
1975@noindent
1976directs that processes started with subsequent @code{run} commands
1977default to do input and output on the terminal @file{/dev/ttyb} and have
1978that as their controlling terminal.
1979
1980An explicit redirection in @code{run} overrides the @code{tty} command's
1981effect on the input/output device, but not its effect on the controlling
1982terminal.
1983
1984When you use the @code{tty} command or redirect input in the @code{run}
1985command, only the input @emph{for your program} is affected. The input
1986for @value{GDBN} still comes from your terminal.
1987
6d2ebf8b 1988@node Attach
c906108c
SS
1989@section Debugging an already-running process
1990@kindex attach
1991@cindex attach
1992
1993@table @code
1994@item attach @var{process-id}
1995This command attaches to a running process---one that was started
1996outside @value{GDBN}. (@code{info files} shows your active
1997targets.) The command takes as argument a process ID. The usual way to
1998find out the process-id of a Unix process is with the @code{ps} utility,
1999or with the @samp{jobs -l} shell command.
2000
2001@code{attach} does not repeat if you press @key{RET} a second time after
2002executing the command.
2003@end table
2004
2005To use @code{attach}, your program must be running in an environment
2006which supports processes; for example, @code{attach} does not work for
2007programs on bare-board targets that lack an operating system. You must
2008also have permission to send the process a signal.
2009
2010When you use @code{attach}, the debugger finds the program running in
2011the process first by looking in the current working directory, then (if
2012the program is not found) by using the source file search path
2013(@pxref{Source Path, ,Specifying source directories}). You can also use
2014the @code{file} command to load the program. @xref{Files, ,Commands to
2015Specify Files}.
2016
2017The first thing @value{GDBN} does after arranging to debug the specified
2018process is to stop it. You can examine and modify an attached process
53a5351d
JM
2019with all the @value{GDBN} commands that are ordinarily available when
2020you start processes with @code{run}. You can insert breakpoints; you
2021can step and continue; you can modify storage. If you would rather the
2022process continue running, you may use the @code{continue} command after
c906108c
SS
2023attaching @value{GDBN} to the process.
2024
2025@table @code
2026@kindex detach
2027@item detach
2028When you have finished debugging the attached process, you can use the
2029@code{detach} command to release it from @value{GDBN} control. Detaching
2030the process continues its execution. After the @code{detach} command,
2031that process and @value{GDBN} become completely independent once more, and you
2032are ready to @code{attach} another process or start one with @code{run}.
2033@code{detach} does not repeat if you press @key{RET} again after
2034executing the command.
2035@end table
2036
2037If you exit @value{GDBN} or use the @code{run} command while you have an
2038attached process, you kill that process. By default, @value{GDBN} asks
2039for confirmation if you try to do either of these things; you can
2040control whether or not you need to confirm by using the @code{set
2041confirm} command (@pxref{Messages/Warnings, ,Optional warnings and
2042messages}).
2043
6d2ebf8b 2044@node Kill Process
c906108c 2045@section Killing the child process
c906108c
SS
2046
2047@table @code
2048@kindex kill
2049@item kill
2050Kill the child process in which your program is running under @value{GDBN}.
2051@end table
2052
2053This command is useful if you wish to debug a core dump instead of a
2054running process. @value{GDBN} ignores any core dump file while your program
2055is running.
2056
2057On some operating systems, a program cannot be executed outside @value{GDBN}
2058while you have breakpoints set on it inside @value{GDBN}. You can use the
2059@code{kill} command in this situation to permit running your program
2060outside the debugger.
2061
2062The @code{kill} command is also useful if you wish to recompile and
2063relink your program, since on many systems it is impossible to modify an
2064executable file while it is running in a process. In this case, when you
2065next type @code{run}, @value{GDBN} notices that the file has changed, and
2066reads the symbol table again (while trying to preserve your current
2067breakpoint settings).
2068
6d2ebf8b 2069@node Threads
c906108c 2070@section Debugging programs with multiple threads
c906108c
SS
2071
2072@cindex threads of execution
2073@cindex multiple threads
2074@cindex switching threads
2075In some operating systems, such as HP-UX and Solaris, a single program
2076may have more than one @dfn{thread} of execution. The precise semantics
2077of threads differ from one operating system to another, but in general
2078the threads of a single program are akin to multiple processes---except
2079that they share one address space (that is, they can all examine and
2080modify the same variables). On the other hand, each thread has its own
2081registers and execution stack, and perhaps private memory.
2082
2083@value{GDBN} provides these facilities for debugging multi-thread
2084programs:
2085
2086@itemize @bullet
2087@item automatic notification of new threads
2088@item @samp{thread @var{threadno}}, a command to switch among threads
2089@item @samp{info threads}, a command to inquire about existing threads
5d161b24 2090@item @samp{thread apply [@var{threadno}] [@var{all}] @var{args}},
c906108c
SS
2091a command to apply a command to a list of threads
2092@item thread-specific breakpoints
2093@end itemize
2094
c906108c
SS
2095@quotation
2096@emph{Warning:} These facilities are not yet available on every
2097@value{GDBN} configuration where the operating system supports threads.
2098If your @value{GDBN} does not support threads, these commands have no
2099effect. For example, a system without thread support shows no output
2100from @samp{info threads}, and always rejects the @code{thread} command,
2101like this:
2102
2103@smallexample
2104(@value{GDBP}) info threads
2105(@value{GDBP}) thread 1
2106Thread ID 1 not known. Use the "info threads" command to
2107see the IDs of currently known threads.
2108@end smallexample
2109@c FIXME to implementors: how hard would it be to say "sorry, this GDB
2110@c doesn't support threads"?
2111@end quotation
c906108c
SS
2112
2113@cindex focus of debugging
2114@cindex current thread
2115The @value{GDBN} thread debugging facility allows you to observe all
2116threads while your program runs---but whenever @value{GDBN} takes
2117control, one thread in particular is always the focus of debugging.
2118This thread is called the @dfn{current thread}. Debugging commands show
2119program information from the perspective of the current thread.
2120
41afff9a 2121@cindex @code{New} @var{systag} message
c906108c
SS
2122@cindex thread identifier (system)
2123@c FIXME-implementors!! It would be more helpful if the [New...] message
2124@c included GDB's numeric thread handle, so you could just go to that
2125@c thread without first checking `info threads'.
2126Whenever @value{GDBN} detects a new thread in your program, it displays
2127the target system's identification for the thread with a message in the
2128form @samp{[New @var{systag}]}. @var{systag} is a thread identifier
2129whose form varies depending on the particular system. For example, on
2130LynxOS, you might see
2131
474c8240 2132@smallexample
c906108c 2133[New process 35 thread 27]
474c8240 2134@end smallexample
c906108c
SS
2135
2136@noindent
2137when @value{GDBN} notices a new thread. In contrast, on an SGI system,
2138the @var{systag} is simply something like @samp{process 368}, with no
2139further qualifier.
2140
2141@c FIXME!! (1) Does the [New...] message appear even for the very first
2142@c thread of a program, or does it only appear for the
6ca652b0 2143@c second---i.e.@: when it becomes obvious we have a multithread
c906108c
SS
2144@c program?
2145@c (2) *Is* there necessarily a first thread always? Or do some
2146@c multithread systems permit starting a program with multiple
5d161b24 2147@c threads ab initio?
c906108c
SS
2148
2149@cindex thread number
2150@cindex thread identifier (GDB)
2151For debugging purposes, @value{GDBN} associates its own thread
2152number---always a single integer---with each thread in your program.
2153
2154@table @code
2155@kindex info threads
2156@item info threads
2157Display a summary of all threads currently in your
2158program. @value{GDBN} displays for each thread (in this order):
2159
2160@enumerate
2161@item the thread number assigned by @value{GDBN}
2162
2163@item the target system's thread identifier (@var{systag})
2164
2165@item the current stack frame summary for that thread
2166@end enumerate
2167
2168@noindent
2169An asterisk @samp{*} to the left of the @value{GDBN} thread number
2170indicates the current thread.
2171
5d161b24 2172For example,
c906108c
SS
2173@end table
2174@c end table here to get a little more width for example
2175
2176@smallexample
2177(@value{GDBP}) info threads
2178 3 process 35 thread 27 0x34e5 in sigpause ()
2179 2 process 35 thread 23 0x34e5 in sigpause ()
2180* 1 process 35 thread 13 main (argc=1, argv=0x7ffffff8)
2181 at threadtest.c:68
2182@end smallexample
53a5351d
JM
2183
2184On HP-UX systems:
c906108c 2185
4644b6e3
EZ
2186@cindex debugging multithreaded programs (on HP-UX)
2187@cindex thread identifier (GDB), on HP-UX
c906108c
SS
2188For debugging purposes, @value{GDBN} associates its own thread
2189number---a small integer assigned in thread-creation order---with each
2190thread in your program.
2191
41afff9a
EZ
2192@cindex @code{New} @var{systag} message, on HP-UX
2193@cindex thread identifier (system), on HP-UX
c906108c
SS
2194@c FIXME-implementors!! It would be more helpful if the [New...] message
2195@c included GDB's numeric thread handle, so you could just go to that
2196@c thread without first checking `info threads'.
2197Whenever @value{GDBN} detects a new thread in your program, it displays
2198both @value{GDBN}'s thread number and the target system's identification for the thread with a message in the
2199form @samp{[New @var{systag}]}. @var{systag} is a thread identifier
2200whose form varies depending on the particular system. For example, on
2201HP-UX, you see
2202
474c8240 2203@smallexample
c906108c 2204[New thread 2 (system thread 26594)]
474c8240 2205@end smallexample
c906108c
SS
2206
2207@noindent
5d161b24 2208when @value{GDBN} notices a new thread.
c906108c
SS
2209
2210@table @code
4644b6e3 2211@kindex info threads (HP-UX)
c906108c
SS
2212@item info threads
2213Display a summary of all threads currently in your
2214program. @value{GDBN} displays for each thread (in this order):
2215
2216@enumerate
2217@item the thread number assigned by @value{GDBN}
2218
2219@item the target system's thread identifier (@var{systag})
2220
2221@item the current stack frame summary for that thread
2222@end enumerate
2223
2224@noindent
2225An asterisk @samp{*} to the left of the @value{GDBN} thread number
2226indicates the current thread.
2227
5d161b24 2228For example,
c906108c
SS
2229@end table
2230@c end table here to get a little more width for example
2231
474c8240 2232@smallexample
c906108c 2233(@value{GDBP}) info threads
6d2ebf8b
SS
2234 * 3 system thread 26607 worker (wptr=0x7b09c318 "@@") \@*
2235 at quicksort.c:137
2236 2 system thread 26606 0x7b0030d8 in __ksleep () \@*
2237 from /usr/lib/libc.2
2238 1 system thread 27905 0x7b003498 in _brk () \@*
2239 from /usr/lib/libc.2
474c8240 2240@end smallexample
c906108c
SS
2241
2242@table @code
2243@kindex thread @var{threadno}
2244@item thread @var{threadno}
2245Make thread number @var{threadno} the current thread. The command
2246argument @var{threadno} is the internal @value{GDBN} thread number, as
2247shown in the first field of the @samp{info threads} display.
2248@value{GDBN} responds by displaying the system identifier of the thread
2249you selected, and its current stack frame summary:
2250
2251@smallexample
2252@c FIXME!! This example made up; find a @value{GDBN} w/threads and get real one
2253(@value{GDBP}) thread 2
c906108c 2254[Switching to process 35 thread 23]
c906108c
SS
22550x34e5 in sigpause ()
2256@end smallexample
2257
2258@noindent
2259As with the @samp{[New @dots{}]} message, the form of the text after
2260@samp{Switching to} depends on your system's conventions for identifying
5d161b24 2261threads.
c906108c 2262
c906108c
SS
2263@item thread apply [@var{threadno}] [@var{all}] @var{args}
2264The @code{thread apply} command allows you to apply a command to one or
2265more threads. Specify the numbers of the threads that you want affected
2266with the command argument @var{threadno}. @var{threadno} is the internal
2267@value{GDBN} thread number, as shown in the first field of the @samp{info
5d161b24
DB
2268threads} display. To apply a command to all threads, use
2269@code{thread apply all} @var{args}.
c906108c
SS
2270@end table
2271
2272@cindex automatic thread selection
2273@cindex switching threads automatically
2274@cindex threads, automatic switching
2275Whenever @value{GDBN} stops your program, due to a breakpoint or a
2276signal, it automatically selects the thread where that breakpoint or
2277signal happened. @value{GDBN} alerts you to the context switch with a
2278message of the form @samp{[Switching to @var{systag}]} to identify the
2279thread.
2280
2281@xref{Thread Stops,,Stopping and starting multi-thread programs}, for
2282more information about how @value{GDBN} behaves when you stop and start
2283programs with multiple threads.
2284
2285@xref{Set Watchpoints,,Setting watchpoints}, for information about
2286watchpoints in programs with multiple threads.
c906108c 2287
6d2ebf8b 2288@node Processes
c906108c
SS
2289@section Debugging programs with multiple processes
2290
2291@cindex fork, debugging programs which call
2292@cindex multiple processes
2293@cindex processes, multiple
53a5351d
JM
2294On most systems, @value{GDBN} has no special support for debugging
2295programs which create additional processes using the @code{fork}
2296function. When a program forks, @value{GDBN} will continue to debug the
2297parent process and the child process will run unimpeded. If you have
2298set a breakpoint in any code which the child then executes, the child
2299will get a @code{SIGTRAP} signal which (unless it catches the signal)
2300will cause it to terminate.
c906108c
SS
2301
2302However, if you want to debug the child process there is a workaround
2303which isn't too painful. Put a call to @code{sleep} in the code which
2304the child process executes after the fork. It may be useful to sleep
2305only if a certain environment variable is set, or a certain file exists,
2306so that the delay need not occur when you don't want to run @value{GDBN}
2307on the child. While the child is sleeping, use the @code{ps} program to
2308get its process ID. Then tell @value{GDBN} (a new invocation of
2309@value{GDBN} if you are also debugging the parent process) to attach to
d4f3574e 2310the child process (@pxref{Attach}). From that point on you can debug
c906108c 2311the child process just like any other process which you attached to.
c906108c 2312
b51970ac
DJ
2313On some systems, @value{GDBN} provides support for debugging programs that
2314create additional processes using the @code{fork} or @code{vfork} functions.
2315Currently, the only platforms with this feature are HP-UX (11.x and later
2316only?) and GNU/Linux (kernel version 2.5.60 and later).
c906108c
SS
2317
2318By default, when a program forks, @value{GDBN} will continue to debug
2319the parent process and the child process will run unimpeded.
2320
2321If you want to follow the child process instead of the parent process,
2322use the command @w{@code{set follow-fork-mode}}.
2323
2324@table @code
2325@kindex set follow-fork-mode
2326@item set follow-fork-mode @var{mode}
2327Set the debugger response to a program call of @code{fork} or
2328@code{vfork}. A call to @code{fork} or @code{vfork} creates a new
2329process. The @var{mode} can be:
2330
2331@table @code
2332@item parent
2333The original process is debugged after a fork. The child process runs
2df3850c 2334unimpeded. This is the default.
c906108c
SS
2335
2336@item child
2337The new process is debugged after a fork. The parent process runs
2338unimpeded.
2339
c906108c
SS
2340@end table
2341
2342@item show follow-fork-mode
2df3850c 2343Display the current debugger response to a @code{fork} or @code{vfork} call.
c906108c
SS
2344@end table
2345
2346If you ask to debug a child process and a @code{vfork} is followed by an
2347@code{exec}, @value{GDBN} executes the new target up to the first
2348breakpoint in the new target. If you have a breakpoint set on
2349@code{main} in your original program, the breakpoint will also be set on
2350the child process's @code{main}.
2351
2352When a child process is spawned by @code{vfork}, you cannot debug the
2353child or parent until an @code{exec} call completes.
2354
2355If you issue a @code{run} command to @value{GDBN} after an @code{exec}
2356call executes, the new target restarts. To restart the parent process,
2357use the @code{file} command with the parent executable name as its
2358argument.
2359
2360You can use the @code{catch} command to make @value{GDBN} stop whenever
2361a @code{fork}, @code{vfork}, or @code{exec} call is made. @xref{Set
2362Catchpoints, ,Setting catchpoints}.
c906108c 2363
6d2ebf8b 2364@node Stopping
c906108c
SS
2365@chapter Stopping and Continuing
2366
2367The principal purposes of using a debugger are so that you can stop your
2368program before it terminates; or so that, if your program runs into
2369trouble, you can investigate and find out why.
2370
7a292a7a
SS
2371Inside @value{GDBN}, your program may stop for any of several reasons,
2372such as a signal, a breakpoint, or reaching a new line after a
2373@value{GDBN} command such as @code{step}. You may then examine and
2374change variables, set new breakpoints or remove old ones, and then
2375continue execution. Usually, the messages shown by @value{GDBN} provide
2376ample explanation of the status of your program---but you can also
2377explicitly request this information at any time.
c906108c
SS
2378
2379@table @code
2380@kindex info program
2381@item info program
2382Display information about the status of your program: whether it is
7a292a7a 2383running or not, what process it is, and why it stopped.
c906108c
SS
2384@end table
2385
2386@menu
2387* Breakpoints:: Breakpoints, watchpoints, and catchpoints
2388* Continuing and Stepping:: Resuming execution
c906108c 2389* Signals:: Signals
c906108c 2390* Thread Stops:: Stopping and starting multi-thread programs
c906108c
SS
2391@end menu
2392
6d2ebf8b 2393@node Breakpoints
c906108c
SS
2394@section Breakpoints, watchpoints, and catchpoints
2395
2396@cindex breakpoints
2397A @dfn{breakpoint} makes your program stop whenever a certain point in
2398the program is reached. For each breakpoint, you can add conditions to
2399control in finer detail whether your program stops. You can set
2400breakpoints with the @code{break} command and its variants (@pxref{Set
2401Breaks, ,Setting breakpoints}), to specify the place where your program
2402should stop by line number, function name or exact address in the
2403program.
2404
2405In HP-UX, SunOS 4.x, SVR4, and Alpha OSF/1 configurations, you can set
2406breakpoints in shared libraries before the executable is run. There is
2407a minor limitation on HP-UX systems: you must wait until the executable
2408is run in order to set breakpoints in shared library routines that are
2409not called directly by the program (for example, routines that are
2410arguments in a @code{pthread_create} call).
2411
2412@cindex watchpoints
2413@cindex memory tracing
2414@cindex breakpoint on memory address
2415@cindex breakpoint on variable modification
2416A @dfn{watchpoint} is a special breakpoint that stops your program
2417when the value of an expression changes. You must use a different
2418command to set watchpoints (@pxref{Set Watchpoints, ,Setting
2419watchpoints}), but aside from that, you can manage a watchpoint like
2420any other breakpoint: you enable, disable, and delete both breakpoints
2421and watchpoints using the same commands.
2422
2423You can arrange to have values from your program displayed automatically
2424whenever @value{GDBN} stops at a breakpoint. @xref{Auto Display,,
2425Automatic display}.
2426
2427@cindex catchpoints
2428@cindex breakpoint on events
2429A @dfn{catchpoint} is another special breakpoint that stops your program
b37052ae 2430when a certain kind of event occurs, such as the throwing of a C@t{++}
c906108c
SS
2431exception or the loading of a library. As with watchpoints, you use a
2432different command to set a catchpoint (@pxref{Set Catchpoints, ,Setting
2433catchpoints}), but aside from that, you can manage a catchpoint like any
2434other breakpoint. (To stop when your program receives a signal, use the
d4f3574e 2435@code{handle} command; see @ref{Signals, ,Signals}.)
c906108c
SS
2436
2437@cindex breakpoint numbers
2438@cindex numbers for breakpoints
2439@value{GDBN} assigns a number to each breakpoint, watchpoint, or
2440catchpoint when you create it; these numbers are successive integers
2441starting with one. In many of the commands for controlling various
2442features of breakpoints you use the breakpoint number to say which
2443breakpoint you want to change. Each breakpoint may be @dfn{enabled} or
2444@dfn{disabled}; if disabled, it has no effect on your program until you
2445enable it again.
2446
c5394b80
JM
2447@cindex breakpoint ranges
2448@cindex ranges of breakpoints
2449Some @value{GDBN} commands accept a range of breakpoints on which to
2450operate. A breakpoint range is either a single breakpoint number, like
2451@samp{5}, or two such numbers, in increasing order, separated by a
2452hyphen, like @samp{5-7}. When a breakpoint range is given to a command,
2453all breakpoint in that range are operated on.
2454
c906108c
SS
2455@menu
2456* Set Breaks:: Setting breakpoints
2457* Set Watchpoints:: Setting watchpoints
2458* Set Catchpoints:: Setting catchpoints
2459* Delete Breaks:: Deleting breakpoints
2460* Disabling:: Disabling breakpoints
2461* Conditions:: Break conditions
2462* Break Commands:: Breakpoint command lists
c906108c 2463* Breakpoint Menus:: Breakpoint menus
d4f3574e 2464* Error in Breakpoints:: ``Cannot insert breakpoints''
e4d5f7e1 2465* Breakpoint related warnings:: ``Breakpoint address adjusted...''
c906108c
SS
2466@end menu
2467
6d2ebf8b 2468@node Set Breaks
c906108c
SS
2469@subsection Setting breakpoints
2470
5d161b24 2471@c FIXME LMB what does GDB do if no code on line of breakpt?
c906108c
SS
2472@c consider in particular declaration with/without initialization.
2473@c
2474@c FIXME 2 is there stuff on this already? break at fun start, already init?
2475
2476@kindex break
41afff9a
EZ
2477@kindex b @r{(@code{break})}
2478@vindex $bpnum@r{, convenience variable}
c906108c
SS
2479@cindex latest breakpoint
2480Breakpoints are set with the @code{break} command (abbreviated
5d161b24 2481@code{b}). The debugger convenience variable @samp{$bpnum} records the
f3b28801 2482number of the breakpoint you've set most recently; see @ref{Convenience
c906108c
SS
2483Vars,, Convenience variables}, for a discussion of what you can do with
2484convenience variables.
2485
2486You have several ways to say where the breakpoint should go.
2487
2488@table @code
2489@item break @var{function}
5d161b24 2490Set a breakpoint at entry to function @var{function}.
c906108c 2491When using source languages that permit overloading of symbols, such as
b37052ae 2492C@t{++}, @var{function} may refer to more than one possible place to break.
c906108c 2493@xref{Breakpoint Menus,,Breakpoint menus}, for a discussion of that situation.
c906108c
SS
2494
2495@item break +@var{offset}
2496@itemx break -@var{offset}
2497Set a breakpoint some number of lines forward or back from the position
d4f3574e 2498at which execution stopped in the currently selected @dfn{stack frame}.
2df3850c 2499(@xref{Frames, ,Frames}, for a description of stack frames.)
c906108c
SS
2500
2501@item break @var{linenum}
2502Set a breakpoint at line @var{linenum} in the current source file.
d4f3574e
SS
2503The current source file is the last file whose source text was printed.
2504The breakpoint will stop your program just before it executes any of the
c906108c
SS
2505code on that line.
2506
2507@item break @var{filename}:@var{linenum}
2508Set a breakpoint at line @var{linenum} in source file @var{filename}.
2509
2510@item break @var{filename}:@var{function}
2511Set a breakpoint at entry to function @var{function} found in file
2512@var{filename}. Specifying a file name as well as a function name is
2513superfluous except when multiple files contain similarly named
2514functions.
2515
2516@item break *@var{address}
2517Set a breakpoint at address @var{address}. You can use this to set
2518breakpoints in parts of your program which do not have debugging
2519information or source files.
2520
2521@item break
2522When called without any arguments, @code{break} sets a breakpoint at
2523the next instruction to be executed in the selected stack frame
2524(@pxref{Stack, ,Examining the Stack}). In any selected frame but the
2525innermost, this makes your program stop as soon as control
2526returns to that frame. This is similar to the effect of a
2527@code{finish} command in the frame inside the selected frame---except
2528that @code{finish} does not leave an active breakpoint. If you use
2529@code{break} without an argument in the innermost frame, @value{GDBN} stops
2530the next time it reaches the current location; this may be useful
2531inside loops.
2532
2533@value{GDBN} normally ignores breakpoints when it resumes execution, until at
2534least one instruction has been executed. If it did not do this, you
2535would be unable to proceed past a breakpoint without first disabling the
2536breakpoint. This rule applies whether or not the breakpoint already
2537existed when your program stopped.
2538
2539@item break @dots{} if @var{cond}
2540Set a breakpoint with condition @var{cond}; evaluate the expression
2541@var{cond} each time the breakpoint is reached, and stop only if the
2542value is nonzero---that is, if @var{cond} evaluates as true.
2543@samp{@dots{}} stands for one of the possible arguments described
2544above (or no argument) specifying where to break. @xref{Conditions,
2545,Break conditions}, for more information on breakpoint conditions.
2546
2547@kindex tbreak
2548@item tbreak @var{args}
2549Set a breakpoint enabled only for one stop. @var{args} are the
2550same as for the @code{break} command, and the breakpoint is set in the same
2551way, but the breakpoint is automatically deleted after the first time your
2552program stops there. @xref{Disabling, ,Disabling breakpoints}.
2553
c906108c
SS
2554@kindex hbreak
2555@item hbreak @var{args}
d4f3574e
SS
2556Set a hardware-assisted breakpoint. @var{args} are the same as for the
2557@code{break} command and the breakpoint is set in the same way, but the
c906108c
SS
2558breakpoint requires hardware support and some target hardware may not
2559have this support. The main purpose of this is EPROM/ROM code
d4f3574e
SS
2560debugging, so you can set a breakpoint at an instruction without
2561changing the instruction. This can be used with the new trap-generation
2562provided by SPARClite DSU and some x86-based targets. These targets
2563will generate traps when a program accesses some data or instruction
2564address that is assigned to the debug registers. However the hardware
2565breakpoint registers can take a limited number of breakpoints. For
2566example, on the DSU, only two data breakpoints can be set at a time, and
2567@value{GDBN} will reject this command if more than two are used. Delete
2568or disable unused hardware breakpoints before setting new ones
2569(@pxref{Disabling, ,Disabling}). @xref{Conditions, ,Break conditions}.
501eef12
AC
2570@xref{set remote hardware-breakpoint-limit}.
2571
c906108c
SS
2572
2573@kindex thbreak
2574@item thbreak @var{args}
2575Set a hardware-assisted breakpoint enabled only for one stop. @var{args}
2576are the same as for the @code{hbreak} command and the breakpoint is set in
5d161b24 2577the same way. However, like the @code{tbreak} command,
c906108c
SS
2578the breakpoint is automatically deleted after the
2579first time your program stops there. Also, like the @code{hbreak}
5d161b24
DB
2580command, the breakpoint requires hardware support and some target hardware
2581may not have this support. @xref{Disabling, ,Disabling breakpoints}.
d4f3574e 2582See also @ref{Conditions, ,Break conditions}.
c906108c
SS
2583
2584@kindex rbreak
2585@cindex regular expression
2586@item rbreak @var{regex}
c906108c 2587Set breakpoints on all functions matching the regular expression
11cf8741
JM
2588@var{regex}. This command sets an unconditional breakpoint on all
2589matches, printing a list of all breakpoints it set. Once these
2590breakpoints are set, they are treated just like the breakpoints set with
2591the @code{break} command. You can delete them, disable them, or make
2592them conditional the same way as any other breakpoint.
2593
2594The syntax of the regular expression is the standard one used with tools
2595like @file{grep}. Note that this is different from the syntax used by
2596shells, so for instance @code{foo*} matches all functions that include
2597an @code{fo} followed by zero or more @code{o}s. There is an implicit
2598@code{.*} leading and trailing the regular expression you supply, so to
2599match only functions that begin with @code{foo}, use @code{^foo}.
c906108c 2600
f7dc1244 2601@cindex non-member C@t{++} functions, set breakpoint in
b37052ae 2602When debugging C@t{++} programs, @code{rbreak} is useful for setting
c906108c
SS
2603breakpoints on overloaded functions that are not members of any special
2604classes.
c906108c 2605
f7dc1244
EZ
2606@cindex set breakpoints on all functions
2607The @code{rbreak} command can be used to set breakpoints in
2608@strong{all} the functions in a program, like this:
2609
2610@smallexample
2611(@value{GDBP}) rbreak .
2612@end smallexample
2613
c906108c
SS
2614@kindex info breakpoints
2615@cindex @code{$_} and @code{info breakpoints}
2616@item info breakpoints @r{[}@var{n}@r{]}
2617@itemx info break @r{[}@var{n}@r{]}
2618@itemx info watchpoints @r{[}@var{n}@r{]}
2619Print a table of all breakpoints, watchpoints, and catchpoints set and
2620not deleted, with the following columns for each breakpoint:
2621
2622@table @emph
2623@item Breakpoint Numbers
2624@item Type
2625Breakpoint, watchpoint, or catchpoint.
2626@item Disposition
2627Whether the breakpoint is marked to be disabled or deleted when hit.
2628@item Enabled or Disabled
2629Enabled breakpoints are marked with @samp{y}. @samp{n} marks breakpoints
2630that are not enabled.
2631@item Address
2650777c
JJ
2632Where the breakpoint is in your program, as a memory address. If the
2633breakpoint is pending (see below for details) on a future load of a shared library, the address
2634will be listed as @samp{<PENDING>}.
c906108c
SS
2635@item What
2636Where the breakpoint is in the source for your program, as a file and
2650777c
JJ
2637line number. For a pending breakpoint, the original string passed to
2638the breakpoint command will be listed as it cannot be resolved until
2639the appropriate shared library is loaded in the future.
c906108c
SS
2640@end table
2641
2642@noindent
2643If a breakpoint is conditional, @code{info break} shows the condition on
2644the line following the affected breakpoint; breakpoint commands, if any,
2650777c
JJ
2645are listed after that. A pending breakpoint is allowed to have a condition
2646specified for it. The condition is not parsed for validity until a shared
2647library is loaded that allows the pending breakpoint to resolve to a
2648valid location.
c906108c
SS
2649
2650@noindent
2651@code{info break} with a breakpoint
2652number @var{n} as argument lists only that breakpoint. The
2653convenience variable @code{$_} and the default examining-address for
2654the @code{x} command are set to the address of the last breakpoint
5d161b24 2655listed (@pxref{Memory, ,Examining memory}).
c906108c
SS
2656
2657@noindent
2658@code{info break} displays a count of the number of times the breakpoint
2659has been hit. This is especially useful in conjunction with the
2660@code{ignore} command. You can ignore a large number of breakpoint
2661hits, look at the breakpoint info to see how many times the breakpoint
2662was hit, and then run again, ignoring one less than that number. This
2663will get you quickly to the last hit of that breakpoint.
2664@end table
2665
2666@value{GDBN} allows you to set any number of breakpoints at the same place in
2667your program. There is nothing silly or meaningless about this. When
2668the breakpoints are conditional, this is even useful
2669(@pxref{Conditions, ,Break conditions}).
2670
2650777c 2671@cindex pending breakpoints
dd79a6cf
JJ
2672If a specified breakpoint location cannot be found, it may be due to the fact
2673that the location is in a shared library that is yet to be loaded. In such
2674a case, you may want @value{GDBN} to create a special breakpoint (known as
2675a @dfn{pending breakpoint}) that
2676attempts to resolve itself in the future when an appropriate shared library
2677gets loaded.
2678
2679Pending breakpoints are useful to set at the start of your
2650777c
JJ
2680@value{GDBN} session for locations that you know will be dynamically loaded
2681later by the program being debugged. When shared libraries are loaded,
dd79a6cf
JJ
2682a check is made to see if the load resolves any pending breakpoint locations.
2683If a pending breakpoint location gets resolved,
2684a regular breakpoint is created and the original pending breakpoint is removed.
2685
2686@value{GDBN} provides some additional commands for controlling pending
2687breakpoint support:
2688
2689@kindex set breakpoint pending
2690@kindex show breakpoint pending
2691@table @code
2692@item set breakpoint pending auto
2693This is the default behavior. When @value{GDBN} cannot find the breakpoint
2694location, it queries you whether a pending breakpoint should be created.
2695
2696@item set breakpoint pending on
2697This indicates that an unrecognized breakpoint location should automatically
2698result in a pending breakpoint being created.
2699
2700@item set breakpoint pending off
2701This indicates that pending breakpoints are not to be created. Any
2702unrecognized breakpoint location results in an error. This setting does
2703not affect any pending breakpoints previously created.
2704
2705@item show breakpoint pending
2706Show the current behavior setting for creating pending breakpoints.
2707@end table
2650777c 2708
649e03f6
RM
2709@cindex operations allowed on pending breakpoints
2710Normal breakpoint operations apply to pending breakpoints as well. You may
2711specify a condition for a pending breakpoint and/or commands to run when the
2650777c
JJ
2712breakpoint is reached. You can also enable or disable
2713the pending breakpoint. When you specify a condition for a pending breakpoint,
2714the parsing of the condition will be deferred until the point where the
2715pending breakpoint location is resolved. Disabling a pending breakpoint
2716tells @value{GDBN} to not attempt to resolve the breakpoint on any subsequent
2717shared library load. When a pending breakpoint is re-enabled,
649e03f6 2718@value{GDBN} checks to see if the location is already resolved.
2650777c
JJ
2719This is done because any number of shared library loads could have
2720occurred since the time the breakpoint was disabled and one or more
2721of these loads could resolve the location.
2722
c906108c
SS
2723@cindex negative breakpoint numbers
2724@cindex internal @value{GDBN} breakpoints
eb12ee30
AC
2725@value{GDBN} itself sometimes sets breakpoints in your program for
2726special purposes, such as proper handling of @code{longjmp} (in C
2727programs). These internal breakpoints are assigned negative numbers,
2728starting with @code{-1}; @samp{info breakpoints} does not display them.
c906108c 2729You can see these breakpoints with the @value{GDBN} maintenance command
eb12ee30 2730@samp{maint info breakpoints} (@pxref{maint info breakpoints}).
c906108c
SS
2731
2732
6d2ebf8b 2733@node Set Watchpoints
c906108c
SS
2734@subsection Setting watchpoints
2735
2736@cindex setting watchpoints
2737@cindex software watchpoints
2738@cindex hardware watchpoints
2739You can use a watchpoint to stop execution whenever the value of an
2740expression changes, without having to predict a particular place where
2741this may happen.
2742
2743Depending on your system, watchpoints may be implemented in software or
2df3850c 2744hardware. @value{GDBN} does software watchpointing by single-stepping your
c906108c
SS
2745program and testing the variable's value each time, which is hundreds of
2746times slower than normal execution. (But this may still be worth it, to
2747catch errors where you have no clue what part of your program is the
2748culprit.)
2749
1104b9e7 2750On some systems, such as HP-UX, @sc{gnu}/Linux and some other x86-based targets,
2df3850c 2751@value{GDBN} includes support for
c906108c
SS
2752hardware watchpoints, which do not slow down the running of your
2753program.
2754
2755@table @code
2756@kindex watch
2757@item watch @var{expr}
2758Set a watchpoint for an expression. @value{GDBN} will break when @var{expr}
2759is written into by the program and its value changes.
2760
2761@kindex rwatch
2762@item rwatch @var{expr}
2763Set a watchpoint that will break when watch @var{expr} is read by the program.
c906108c
SS
2764
2765@kindex awatch
2766@item awatch @var{expr}
2df3850c 2767Set a watchpoint that will break when @var{expr} is either read or written into
7be570e7 2768by the program.
c906108c
SS
2769
2770@kindex info watchpoints
2771@item info watchpoints
2772This command prints a list of watchpoints, breakpoints, and catchpoints;
2773it is the same as @code{info break}.
2774@end table
2775
2776@value{GDBN} sets a @dfn{hardware watchpoint} if possible. Hardware
2777watchpoints execute very quickly, and the debugger reports a change in
2778value at the exact instruction where the change occurs. If @value{GDBN}
2779cannot set a hardware watchpoint, it sets a software watchpoint, which
2780executes more slowly and reports the change in value at the next
2781statement, not the instruction, after the change occurs.
2782
2783When you issue the @code{watch} command, @value{GDBN} reports
2784
474c8240 2785@smallexample
c906108c 2786Hardware watchpoint @var{num}: @var{expr}
474c8240 2787@end smallexample
c906108c
SS
2788
2789@noindent
2790if it was able to set a hardware watchpoint.
2791
7be570e7
JM
2792Currently, the @code{awatch} and @code{rwatch} commands can only set
2793hardware watchpoints, because accesses to data that don't change the
2794value of the watched expression cannot be detected without examining
2795every instruction as it is being executed, and @value{GDBN} does not do
2796that currently. If @value{GDBN} finds that it is unable to set a
2797hardware breakpoint with the @code{awatch} or @code{rwatch} command, it
2798will print a message like this:
2799
2800@smallexample
2801Expression cannot be implemented with read/access watchpoint.
2802@end smallexample
2803
2804Sometimes, @value{GDBN} cannot set a hardware watchpoint because the
2805data type of the watched expression is wider than what a hardware
2806watchpoint on the target machine can handle. For example, some systems
2807can only watch regions that are up to 4 bytes wide; on such systems you
2808cannot set hardware watchpoints for an expression that yields a
2809double-precision floating-point number (which is typically 8 bytes
2810wide). As a work-around, it might be possible to break the large region
2811into a series of smaller ones and watch them with separate watchpoints.
2812
2813If you set too many hardware watchpoints, @value{GDBN} might be unable
2814to insert all of them when you resume the execution of your program.
2815Since the precise number of active watchpoints is unknown until such
2816time as the program is about to be resumed, @value{GDBN} might not be
2817able to warn you about this when you set the watchpoints, and the
2818warning will be printed only when the program is resumed:
2819
2820@smallexample
2821Hardware watchpoint @var{num}: Could not insert watchpoint
2822@end smallexample
2823
2824@noindent
2825If this happens, delete or disable some of the watchpoints.
2826
2827The SPARClite DSU will generate traps when a program accesses some data
2828or instruction address that is assigned to the debug registers. For the
2829data addresses, DSU facilitates the @code{watch} command. However the
2830hardware breakpoint registers can only take two data watchpoints, and
2831both watchpoints must be the same kind. For example, you can set two
2832watchpoints with @code{watch} commands, two with @code{rwatch} commands,
2833@strong{or} two with @code{awatch} commands, but you cannot set one
2834watchpoint with one command and the other with a different command.
c906108c
SS
2835@value{GDBN} will reject the command if you try to mix watchpoints.
2836Delete or disable unused watchpoint commands before setting new ones.
2837
2838If you call a function interactively using @code{print} or @code{call},
2df3850c 2839any watchpoints you have set will be inactive until @value{GDBN} reaches another
c906108c
SS
2840kind of breakpoint or the call completes.
2841
7be570e7
JM
2842@value{GDBN} automatically deletes watchpoints that watch local
2843(automatic) variables, or expressions that involve such variables, when
2844they go out of scope, that is, when the execution leaves the block in
2845which these variables were defined. In particular, when the program
2846being debugged terminates, @emph{all} local variables go out of scope,
2847and so only watchpoints that watch global variables remain set. If you
2848rerun the program, you will need to set all such watchpoints again. One
2849way of doing that would be to set a code breakpoint at the entry to the
2850@code{main} function and when it breaks, set all the watchpoints.
2851
c906108c
SS
2852@quotation
2853@cindex watchpoints and threads
2854@cindex threads and watchpoints
c906108c
SS
2855@emph{Warning:} In multi-thread programs, watchpoints have only limited
2856usefulness. With the current watchpoint implementation, @value{GDBN}
2857can only watch the value of an expression @emph{in a single thread}. If
2858you are confident that the expression can only change due to the current
2859thread's activity (and if you are also confident that no other thread
2860can become current), then you can use watchpoints as usual. However,
2861@value{GDBN} may not notice when a non-current thread's activity changes
2862the expression.
53a5351d 2863
d4f3574e 2864@c FIXME: this is almost identical to the previous paragraph.
53a5351d
JM
2865@emph{HP-UX Warning:} In multi-thread programs, software watchpoints
2866have only limited usefulness. If @value{GDBN} creates a software
2867watchpoint, it can only watch the value of an expression @emph{in a
2868single thread}. If you are confident that the expression can only
2869change due to the current thread's activity (and if you are also
2870confident that no other thread can become current), then you can use
2871software watchpoints as usual. However, @value{GDBN} may not notice
2872when a non-current thread's activity changes the expression. (Hardware
2873watchpoints, in contrast, watch an expression in all threads.)
c906108c 2874@end quotation
c906108c 2875
501eef12
AC
2876@xref{set remote hardware-watchpoint-limit}.
2877
6d2ebf8b 2878@node Set Catchpoints
c906108c 2879@subsection Setting catchpoints
d4f3574e 2880@cindex catchpoints, setting
c906108c
SS
2881@cindex exception handlers
2882@cindex event handling
2883
2884You can use @dfn{catchpoints} to cause the debugger to stop for certain
b37052ae 2885kinds of program events, such as C@t{++} exceptions or the loading of a
c906108c
SS
2886shared library. Use the @code{catch} command to set a catchpoint.
2887
2888@table @code
2889@kindex catch
2890@item catch @var{event}
2891Stop when @var{event} occurs. @var{event} can be any of the following:
2892@table @code
2893@item throw
4644b6e3 2894@cindex stop on C@t{++} exceptions
b37052ae 2895The throwing of a C@t{++} exception.
c906108c
SS
2896
2897@item catch
b37052ae 2898The catching of a C@t{++} exception.
c906108c
SS
2899
2900@item exec
4644b6e3 2901@cindex break on fork/exec
c906108c
SS
2902A call to @code{exec}. This is currently only available for HP-UX.
2903
2904@item fork
c906108c
SS
2905A call to @code{fork}. This is currently only available for HP-UX.
2906
2907@item vfork
c906108c
SS
2908A call to @code{vfork}. This is currently only available for HP-UX.
2909
2910@item load
2911@itemx load @var{libname}
4644b6e3 2912@cindex break on load/unload of shared library
c906108c
SS
2913The dynamic loading of any shared library, or the loading of the library
2914@var{libname}. This is currently only available for HP-UX.
2915
2916@item unload
2917@itemx unload @var{libname}
c906108c
SS
2918The unloading of any dynamically loaded shared library, or the unloading
2919of the library @var{libname}. This is currently only available for HP-UX.
2920@end table
2921
2922@item tcatch @var{event}
2923Set a catchpoint that is enabled only for one stop. The catchpoint is
2924automatically deleted after the first time the event is caught.
2925
2926@end table
2927
2928Use the @code{info break} command to list the current catchpoints.
2929
b37052ae 2930There are currently some limitations to C@t{++} exception handling
c906108c
SS
2931(@code{catch throw} and @code{catch catch}) in @value{GDBN}:
2932
2933@itemize @bullet
2934@item
2935If you call a function interactively, @value{GDBN} normally returns
2936control to you when the function has finished executing. If the call
2937raises an exception, however, the call may bypass the mechanism that
2938returns control to you and cause your program either to abort or to
2939simply continue running until it hits a breakpoint, catches a signal
2940that @value{GDBN} is listening for, or exits. This is the case even if
2941you set a catchpoint for the exception; catchpoints on exceptions are
2942disabled within interactive calls.
2943
2944@item
2945You cannot raise an exception interactively.
2946
2947@item
2948You cannot install an exception handler interactively.
2949@end itemize
2950
2951@cindex raise exceptions
2952Sometimes @code{catch} is not the best way to debug exception handling:
2953if you need to know exactly where an exception is raised, it is better to
2954stop @emph{before} the exception handler is called, since that way you
2955can see the stack before any unwinding takes place. If you set a
2956breakpoint in an exception handler instead, it may not be easy to find
2957out where the exception was raised.
2958
2959To stop just before an exception handler is called, you need some
b37052ae 2960knowledge of the implementation. In the case of @sc{gnu} C@t{++}, exceptions are
c906108c
SS
2961raised by calling a library function named @code{__raise_exception}
2962which has the following ANSI C interface:
2963
474c8240 2964@smallexample
c906108c 2965 /* @var{addr} is where the exception identifier is stored.
d4f3574e
SS
2966 @var{id} is the exception identifier. */
2967 void __raise_exception (void **addr, void *id);
474c8240 2968@end smallexample
c906108c
SS
2969
2970@noindent
2971To make the debugger catch all exceptions before any stack
2972unwinding takes place, set a breakpoint on @code{__raise_exception}
2973(@pxref{Breakpoints, ,Breakpoints; watchpoints; and exceptions}).
2974
2975With a conditional breakpoint (@pxref{Conditions, ,Break conditions})
2976that depends on the value of @var{id}, you can stop your program when
2977a specific exception is raised. You can use multiple conditional
2978breakpoints to stop your program when any of a number of exceptions are
2979raised.
2980
2981
6d2ebf8b 2982@node Delete Breaks
c906108c
SS
2983@subsection Deleting breakpoints
2984
2985@cindex clearing breakpoints, watchpoints, catchpoints
2986@cindex deleting breakpoints, watchpoints, catchpoints
2987It is often necessary to eliminate a breakpoint, watchpoint, or
2988catchpoint once it has done its job and you no longer want your program
2989to stop there. This is called @dfn{deleting} the breakpoint. A
2990breakpoint that has been deleted no longer exists; it is forgotten.
2991
2992With the @code{clear} command you can delete breakpoints according to
2993where they are in your program. With the @code{delete} command you can
2994delete individual breakpoints, watchpoints, or catchpoints by specifying
2995their breakpoint numbers.
2996
2997It is not necessary to delete a breakpoint to proceed past it. @value{GDBN}
2998automatically ignores breakpoints on the first instruction to be executed
2999when you continue execution without changing the execution address.
3000
3001@table @code
3002@kindex clear
3003@item clear
3004Delete any breakpoints at the next instruction to be executed in the
3005selected stack frame (@pxref{Selection, ,Selecting a frame}). When
3006the innermost frame is selected, this is a good way to delete a
3007breakpoint where your program just stopped.
3008
3009@item clear @var{function}
3010@itemx clear @var{filename}:@var{function}
3011Delete any breakpoints set at entry to the function @var{function}.
3012
3013@item clear @var{linenum}
3014@itemx clear @var{filename}:@var{linenum}
3015Delete any breakpoints set at or within the code of the specified line.
3016
3017@cindex delete breakpoints
3018@kindex delete
41afff9a 3019@kindex d @r{(@code{delete})}
c5394b80
JM
3020@item delete @r{[}breakpoints@r{]} @r{[}@var{range}@dots{}@r{]}
3021Delete the breakpoints, watchpoints, or catchpoints of the breakpoint
3022ranges specified as arguments. If no argument is specified, delete all
c906108c
SS
3023breakpoints (@value{GDBN} asks confirmation, unless you have @code{set
3024confirm off}). You can abbreviate this command as @code{d}.
3025@end table
3026
6d2ebf8b 3027@node Disabling
c906108c
SS
3028@subsection Disabling breakpoints
3029
4644b6e3 3030@cindex enable/disable a breakpoint
c906108c
SS
3031Rather than deleting a breakpoint, watchpoint, or catchpoint, you might
3032prefer to @dfn{disable} it. This makes the breakpoint inoperative as if
3033it had been deleted, but remembers the information on the breakpoint so
3034that you can @dfn{enable} it again later.
3035
3036You disable and enable breakpoints, watchpoints, and catchpoints with
3037the @code{enable} and @code{disable} commands, optionally specifying one
3038or more breakpoint numbers as arguments. Use @code{info break} or
3039@code{info watch} to print a list of breakpoints, watchpoints, and
3040catchpoints if you do not know which numbers to use.
3041
3042A breakpoint, watchpoint, or catchpoint can have any of four different
3043states of enablement:
3044
3045@itemize @bullet
3046@item
3047Enabled. The breakpoint stops your program. A breakpoint set
3048with the @code{break} command starts out in this state.
3049@item
3050Disabled. The breakpoint has no effect on your program.
3051@item
3052Enabled once. The breakpoint stops your program, but then becomes
d4f3574e 3053disabled.
c906108c
SS
3054@item
3055Enabled for deletion. The breakpoint stops your program, but
d4f3574e
SS
3056immediately after it does so it is deleted permanently. A breakpoint
3057set with the @code{tbreak} command starts out in this state.
c906108c
SS
3058@end itemize
3059
3060You can use the following commands to enable or disable breakpoints,
3061watchpoints, and catchpoints:
3062
3063@table @code
c906108c 3064@kindex disable
41afff9a 3065@kindex dis @r{(@code{disable})}
c5394b80 3066@item disable @r{[}breakpoints@r{]} @r{[}@var{range}@dots{}@r{]}
c906108c
SS
3067Disable the specified breakpoints---or all breakpoints, if none are
3068listed. A disabled breakpoint has no effect but is not forgotten. All
3069options such as ignore-counts, conditions and commands are remembered in
3070case the breakpoint is enabled again later. You may abbreviate
3071@code{disable} as @code{dis}.
3072
c906108c 3073@kindex enable
c5394b80 3074@item enable @r{[}breakpoints@r{]} @r{[}@var{range}@dots{}@r{]}
c906108c
SS
3075Enable the specified breakpoints (or all defined breakpoints). They
3076become effective once again in stopping your program.
3077
c5394b80 3078@item enable @r{[}breakpoints@r{]} once @var{range}@dots{}
c906108c
SS
3079Enable the specified breakpoints temporarily. @value{GDBN} disables any
3080of these breakpoints immediately after stopping your program.
3081
c5394b80 3082@item enable @r{[}breakpoints@r{]} delete @var{range}@dots{}
c906108c
SS
3083Enable the specified breakpoints to work once, then die. @value{GDBN}
3084deletes any of these breakpoints as soon as your program stops there.
3085@end table
3086
d4f3574e
SS
3087@c FIXME: I think the following ``Except for [...] @code{tbreak}'' is
3088@c confusing: tbreak is also initially enabled.
c906108c
SS
3089Except for a breakpoint set with @code{tbreak} (@pxref{Set Breaks,
3090,Setting breakpoints}), breakpoints that you set are initially enabled;
3091subsequently, they become disabled or enabled only when you use one of
3092the commands above. (The command @code{until} can set and delete a
3093breakpoint of its own, but it does not change the state of your other
3094breakpoints; see @ref{Continuing and Stepping, ,Continuing and
3095stepping}.)
3096
6d2ebf8b 3097@node Conditions
c906108c
SS
3098@subsection Break conditions
3099@cindex conditional breakpoints
3100@cindex breakpoint conditions
3101
3102@c FIXME what is scope of break condition expr? Context where wanted?
5d161b24 3103@c in particular for a watchpoint?
c906108c
SS
3104The simplest sort of breakpoint breaks every time your program reaches a
3105specified place. You can also specify a @dfn{condition} for a
3106breakpoint. A condition is just a Boolean expression in your
3107programming language (@pxref{Expressions, ,Expressions}). A breakpoint with
3108a condition evaluates the expression each time your program reaches it,
3109and your program stops only if the condition is @emph{true}.
3110
3111This is the converse of using assertions for program validation; in that
3112situation, you want to stop when the assertion is violated---that is,
3113when the condition is false. In C, if you want to test an assertion expressed
3114by the condition @var{assert}, you should set the condition
3115@samp{! @var{assert}} on the appropriate breakpoint.
3116
3117Conditions are also accepted for watchpoints; you may not need them,
3118since a watchpoint is inspecting the value of an expression anyhow---but
3119it might be simpler, say, to just set a watchpoint on a variable name,
3120and specify a condition that tests whether the new value is an interesting
3121one.
3122
3123Break conditions can have side effects, and may even call functions in
3124your program. This can be useful, for example, to activate functions
3125that log program progress, or to use your own print functions to
3126format special data structures. The effects are completely predictable
3127unless there is another enabled breakpoint at the same address. (In
3128that case, @value{GDBN} might see the other breakpoint first and stop your
3129program without checking the condition of this one.) Note that
d4f3574e
SS
3130breakpoint commands are usually more convenient and flexible than break
3131conditions for the
c906108c
SS
3132purpose of performing side effects when a breakpoint is reached
3133(@pxref{Break Commands, ,Breakpoint command lists}).
3134
3135Break conditions can be specified when a breakpoint is set, by using
3136@samp{if} in the arguments to the @code{break} command. @xref{Set
3137Breaks, ,Setting breakpoints}. They can also be changed at any time
3138with the @code{condition} command.
53a5351d 3139
c906108c
SS
3140You can also use the @code{if} keyword with the @code{watch} command.
3141The @code{catch} command does not recognize the @code{if} keyword;
3142@code{condition} is the only way to impose a further condition on a
3143catchpoint.
c906108c
SS
3144
3145@table @code
3146@kindex condition
3147@item condition @var{bnum} @var{expression}
3148Specify @var{expression} as the break condition for breakpoint,
3149watchpoint, or catchpoint number @var{bnum}. After you set a condition,
3150breakpoint @var{bnum} stops your program only if the value of
3151@var{expression} is true (nonzero, in C). When you use
3152@code{condition}, @value{GDBN} checks @var{expression} immediately for
3153syntactic correctness, and to determine whether symbols in it have
d4f3574e
SS
3154referents in the context of your breakpoint. If @var{expression} uses
3155symbols not referenced in the context of the breakpoint, @value{GDBN}
3156prints an error message:
3157
474c8240 3158@smallexample
d4f3574e 3159No symbol "foo" in current context.
474c8240 3160@end smallexample
d4f3574e
SS
3161
3162@noindent
c906108c
SS
3163@value{GDBN} does
3164not actually evaluate @var{expression} at the time the @code{condition}
d4f3574e
SS
3165command (or a command that sets a breakpoint with a condition, like
3166@code{break if @dots{}}) is given, however. @xref{Expressions, ,Expressions}.
c906108c
SS
3167
3168@item condition @var{bnum}
3169Remove the condition from breakpoint number @var{bnum}. It becomes
3170an ordinary unconditional breakpoint.
3171@end table
3172
3173@cindex ignore count (of breakpoint)
3174A special case of a breakpoint condition is to stop only when the
3175breakpoint has been reached a certain number of times. This is so
3176useful that there is a special way to do it, using the @dfn{ignore
3177count} of the breakpoint. Every breakpoint has an ignore count, which
3178is an integer. Most of the time, the ignore count is zero, and
3179therefore has no effect. But if your program reaches a breakpoint whose
3180ignore count is positive, then instead of stopping, it just decrements
3181the ignore count by one and continues. As a result, if the ignore count
3182value is @var{n}, the breakpoint does not stop the next @var{n} times
3183your program reaches it.
3184
3185@table @code
3186@kindex ignore
3187@item ignore @var{bnum} @var{count}
3188Set the ignore count of breakpoint number @var{bnum} to @var{count}.
3189The next @var{count} times the breakpoint is reached, your program's
3190execution does not stop; other than to decrement the ignore count, @value{GDBN}
3191takes no action.
3192
3193To make the breakpoint stop the next time it is reached, specify
3194a count of zero.
3195
3196When you use @code{continue} to resume execution of your program from a
3197breakpoint, you can specify an ignore count directly as an argument to
3198@code{continue}, rather than using @code{ignore}. @xref{Continuing and
3199Stepping,,Continuing and stepping}.
3200
3201If a breakpoint has a positive ignore count and a condition, the
3202condition is not checked. Once the ignore count reaches zero,
3203@value{GDBN} resumes checking the condition.
3204
3205You could achieve the effect of the ignore count with a condition such
3206as @w{@samp{$foo-- <= 0}} using a debugger convenience variable that
3207is decremented each time. @xref{Convenience Vars, ,Convenience
3208variables}.
3209@end table
3210
3211Ignore counts apply to breakpoints, watchpoints, and catchpoints.
3212
3213
6d2ebf8b 3214@node Break Commands
c906108c
SS
3215@subsection Breakpoint command lists
3216
3217@cindex breakpoint commands
3218You can give any breakpoint (or watchpoint or catchpoint) a series of
3219commands to execute when your program stops due to that breakpoint. For
3220example, you might want to print the values of certain expressions, or
3221enable other breakpoints.
3222
3223@table @code
3224@kindex commands
3225@kindex end
3226@item commands @r{[}@var{bnum}@r{]}
3227@itemx @dots{} @var{command-list} @dots{}
3228@itemx end
3229Specify a list of commands for breakpoint number @var{bnum}. The commands
3230themselves appear on the following lines. Type a line containing just
3231@code{end} to terminate the commands.
3232
3233To remove all commands from a breakpoint, type @code{commands} and
3234follow it immediately with @code{end}; that is, give no commands.
3235
3236With no @var{bnum} argument, @code{commands} refers to the last
3237breakpoint, watchpoint, or catchpoint set (not to the breakpoint most
3238recently encountered).
3239@end table
3240
3241Pressing @key{RET} as a means of repeating the last @value{GDBN} command is
3242disabled within a @var{command-list}.
3243
3244You can use breakpoint commands to start your program up again. Simply
3245use the @code{continue} command, or @code{step}, or any other command
3246that resumes execution.
3247
3248Any other commands in the command list, after a command that resumes
3249execution, are ignored. This is because any time you resume execution
3250(even with a simple @code{next} or @code{step}), you may encounter
3251another breakpoint---which could have its own command list, leading to
3252ambiguities about which list to execute.
3253
3254@kindex silent
3255If the first command you specify in a command list is @code{silent}, the
3256usual message about stopping at a breakpoint is not printed. This may
3257be desirable for breakpoints that are to print a specific message and
3258then continue. If none of the remaining commands print anything, you
3259see no sign that the breakpoint was reached. @code{silent} is
3260meaningful only at the beginning of a breakpoint command list.
3261
3262The commands @code{echo}, @code{output}, and @code{printf} allow you to
3263print precisely controlled output, and are often useful in silent
3264breakpoints. @xref{Output, ,Commands for controlled output}.
3265
3266For example, here is how you could use breakpoint commands to print the
3267value of @code{x} at entry to @code{foo} whenever @code{x} is positive.
3268
474c8240 3269@smallexample
c906108c
SS
3270break foo if x>0
3271commands
3272silent
3273printf "x is %d\n",x
3274cont
3275end
474c8240 3276@end smallexample
c906108c
SS
3277
3278One application for breakpoint commands is to compensate for one bug so
3279you can test for another. Put a breakpoint just after the erroneous line
3280of code, give it a condition to detect the case in which something
3281erroneous has been done, and give it commands to assign correct values
3282to any variables that need them. End with the @code{continue} command
3283so that your program does not stop, and start with the @code{silent}
3284command so that no output is produced. Here is an example:
3285
474c8240 3286@smallexample
c906108c
SS
3287break 403
3288commands
3289silent
3290set x = y + 4
3291cont
3292end
474c8240 3293@end smallexample
c906108c 3294
6d2ebf8b 3295@node Breakpoint Menus
c906108c
SS
3296@subsection Breakpoint menus
3297@cindex overloading
3298@cindex symbol overloading
3299
b383017d 3300Some programming languages (notably C@t{++} and Objective-C) permit a
b37303ee 3301single function name
c906108c
SS
3302to be defined several times, for application in different contexts.
3303This is called @dfn{overloading}. When a function name is overloaded,
3304@samp{break @var{function}} is not enough to tell @value{GDBN} where you want
3305a breakpoint. If you realize this is a problem, you can use
3306something like @samp{break @var{function}(@var{types})} to specify which
3307particular version of the function you want. Otherwise, @value{GDBN} offers
3308you a menu of numbered choices for different possible breakpoints, and
3309waits for your selection with the prompt @samp{>}. The first two
3310options are always @samp{[0] cancel} and @samp{[1] all}. Typing @kbd{1}
3311sets a breakpoint at each definition of @var{function}, and typing
3312@kbd{0} aborts the @code{break} command without setting any new
3313breakpoints.
3314
3315For example, the following session excerpt shows an attempt to set a
3316breakpoint at the overloaded symbol @code{String::after}.
3317We choose three particular definitions of that function name:
3318
3319@c FIXME! This is likely to change to show arg type lists, at least
3320@smallexample
3321@group
3322(@value{GDBP}) b String::after
3323[0] cancel
3324[1] all
3325[2] file:String.cc; line number:867
3326[3] file:String.cc; line number:860
3327[4] file:String.cc; line number:875
3328[5] file:String.cc; line number:853
3329[6] file:String.cc; line number:846
3330[7] file:String.cc; line number:735
3331> 2 4 6
3332Breakpoint 1 at 0xb26c: file String.cc, line 867.
3333Breakpoint 2 at 0xb344: file String.cc, line 875.
3334Breakpoint 3 at 0xafcc: file String.cc, line 846.
3335Multiple breakpoints were set.
3336Use the "delete" command to delete unwanted
3337 breakpoints.
3338(@value{GDBP})
3339@end group
3340@end smallexample
c906108c
SS
3341
3342@c @ifclear BARETARGET
6d2ebf8b 3343@node Error in Breakpoints
d4f3574e 3344@subsection ``Cannot insert breakpoints''
c906108c
SS
3345@c
3346@c FIXME!! 14/6/95 Is there a real example of this? Let's use it.
3347@c
d4f3574e
SS
3348Under some operating systems, breakpoints cannot be used in a program if
3349any other process is running that program. In this situation,
5d161b24 3350attempting to run or continue a program with a breakpoint causes
d4f3574e
SS
3351@value{GDBN} to print an error message:
3352
474c8240 3353@smallexample
d4f3574e
SS
3354Cannot insert breakpoints.
3355The same program may be running in another process.
474c8240 3356@end smallexample
d4f3574e
SS
3357
3358When this happens, you have three ways to proceed:
3359
3360@enumerate
3361@item
3362Remove or disable the breakpoints, then continue.
3363
3364@item
5d161b24 3365Suspend @value{GDBN}, and copy the file containing your program to a new
d4f3574e 3366name. Resume @value{GDBN} and use the @code{exec-file} command to specify
5d161b24 3367that @value{GDBN} should run your program under that name.
d4f3574e
SS
3368Then start your program again.
3369
3370@item
3371Relink your program so that the text segment is nonsharable, using the
3372linker option @samp{-N}. The operating system limitation may not apply
3373to nonsharable executables.
3374@end enumerate
c906108c
SS
3375@c @end ifclear
3376
d4f3574e
SS
3377A similar message can be printed if you request too many active
3378hardware-assisted breakpoints and watchpoints:
3379
3380@c FIXME: the precise wording of this message may change; the relevant
3381@c source change is not committed yet (Sep 3, 1999).
3382@smallexample
3383Stopped; cannot insert breakpoints.
3384You may have requested too many hardware breakpoints and watchpoints.
3385@end smallexample
3386
3387@noindent
3388This message is printed when you attempt to resume the program, since
3389only then @value{GDBN} knows exactly how many hardware breakpoints and
3390watchpoints it needs to insert.
3391
3392When this message is printed, you need to disable or remove some of the
3393hardware-assisted breakpoints and watchpoints, and then continue.
3394
1485d690
KB
3395@node Breakpoint related warnings
3396@subsection ``Breakpoint address adjusted...''
3397@cindex breakpoint address adjusted
3398
3399Some processor architectures place constraints on the addresses at
3400which breakpoints may be placed. For architectures thus constrained,
3401@value{GDBN} will attempt to adjust the breakpoint's address to comply
3402with the constraints dictated by the architecture.
3403
3404One example of such an architecture is the Fujitsu FR-V. The FR-V is
3405a VLIW architecture in which a number of RISC-like instructions may be
3406bundled together for parallel execution. The FR-V architecture
3407constrains the location of a breakpoint instruction within such a
3408bundle to the instruction with the lowest address. @value{GDBN}
3409honors this constraint by adjusting a breakpoint's address to the
3410first in the bundle.
3411
3412It is not uncommon for optimized code to have bundles which contain
3413instructions from different source statements, thus it may happen that
3414a breakpoint's address will be adjusted from one source statement to
3415another. Since this adjustment may significantly alter @value{GDBN}'s
3416breakpoint related behavior from what the user expects, a warning is
3417printed when the breakpoint is first set and also when the breakpoint
3418is hit.
3419
3420A warning like the one below is printed when setting a breakpoint
3421that's been subject to address adjustment:
3422
3423@smallexample
3424warning: Breakpoint address adjusted from 0x00010414 to 0x00010410.
3425@end smallexample
3426
3427Such warnings are printed both for user settable and @value{GDBN}'s
3428internal breakpoints. If you see one of these warnings, you should
3429verify that a breakpoint set at the adjusted address will have the
3430desired affect. If not, the breakpoint in question may be removed and
b383017d 3431other breakpoints may be set which will have the desired behavior.
1485d690
KB
3432E.g., it may be sufficient to place the breakpoint at a later
3433instruction. A conditional breakpoint may also be useful in some
3434cases to prevent the breakpoint from triggering too often.
3435
3436@value{GDBN} will also issue a warning when stopping at one of these
3437adjusted breakpoints:
3438
3439@smallexample
3440warning: Breakpoint 1 address previously adjusted from 0x00010414
3441to 0x00010410.
3442@end smallexample
3443
3444When this warning is encountered, it may be too late to take remedial
3445action except in cases where the breakpoint is hit earlier or more
3446frequently than expected.
d4f3574e 3447
6d2ebf8b 3448@node Continuing and Stepping
c906108c
SS
3449@section Continuing and stepping
3450
3451@cindex stepping
3452@cindex continuing
3453@cindex resuming execution
3454@dfn{Continuing} means resuming program execution until your program
3455completes normally. In contrast, @dfn{stepping} means executing just
3456one more ``step'' of your program, where ``step'' may mean either one
3457line of source code, or one machine instruction (depending on what
7a292a7a
SS
3458particular command you use). Either when continuing or when stepping,
3459your program may stop even sooner, due to a breakpoint or a signal. (If
d4f3574e
SS
3460it stops due to a signal, you may want to use @code{handle}, or use
3461@samp{signal 0} to resume execution. @xref{Signals, ,Signals}.)
c906108c
SS
3462
3463@table @code
3464@kindex continue
41afff9a
EZ
3465@kindex c @r{(@code{continue})}
3466@kindex fg @r{(resume foreground execution)}
c906108c
SS
3467@item continue @r{[}@var{ignore-count}@r{]}
3468@itemx c @r{[}@var{ignore-count}@r{]}
3469@itemx fg @r{[}@var{ignore-count}@r{]}
3470Resume program execution, at the address where your program last stopped;
3471any breakpoints set at that address are bypassed. The optional argument
3472@var{ignore-count} allows you to specify a further number of times to
3473ignore a breakpoint at this location; its effect is like that of
3474@code{ignore} (@pxref{Conditions, ,Break conditions}).
3475
3476The argument @var{ignore-count} is meaningful only when your program
3477stopped due to a breakpoint. At other times, the argument to
3478@code{continue} is ignored.
3479
d4f3574e
SS
3480The synonyms @code{c} and @code{fg} (for @dfn{foreground}, as the
3481debugged program is deemed to be the foreground program) are provided
3482purely for convenience, and have exactly the same behavior as
3483@code{continue}.
c906108c
SS
3484@end table
3485
3486To resume execution at a different place, you can use @code{return}
3487(@pxref{Returning, ,Returning from a function}) to go back to the
3488calling function; or @code{jump} (@pxref{Jumping, ,Continuing at a
3489different address}) to go to an arbitrary location in your program.
3490
3491A typical technique for using stepping is to set a breakpoint
3492(@pxref{Breakpoints, ,Breakpoints; watchpoints; and catchpoints}) at the
3493beginning of the function or the section of your program where a problem
3494is believed to lie, run your program until it stops at that breakpoint,
3495and then step through the suspect area, examining the variables that are
3496interesting, until you see the problem happen.
3497
3498@table @code
3499@kindex step
41afff9a 3500@kindex s @r{(@code{step})}
c906108c
SS
3501@item step
3502Continue running your program until control reaches a different source
3503line, then stop it and return control to @value{GDBN}. This command is
3504abbreviated @code{s}.
3505
3506@quotation
3507@c "without debugging information" is imprecise; actually "without line
3508@c numbers in the debugging information". (gcc -g1 has debugging info but
3509@c not line numbers). But it seems complex to try to make that
3510@c distinction here.
3511@emph{Warning:} If you use the @code{step} command while control is
3512within a function that was compiled without debugging information,
3513execution proceeds until control reaches a function that does have
3514debugging information. Likewise, it will not step into a function which
3515is compiled without debugging information. To step through functions
3516without debugging information, use the @code{stepi} command, described
3517below.
3518@end quotation
3519
4a92d011
EZ
3520The @code{step} command only stops at the first instruction of a source
3521line. This prevents the multiple stops that could otherwise occur in
3522@code{switch} statements, @code{for} loops, etc. @code{step} continues
3523to stop if a function that has debugging information is called within
3524the line. In other words, @code{step} @emph{steps inside} any functions
3525called within the line.
c906108c 3526
d4f3574e
SS
3527Also, the @code{step} command only enters a function if there is line
3528number information for the function. Otherwise it acts like the
5d161b24 3529@code{next} command. This avoids problems when using @code{cc -gl}
c906108c 3530on MIPS machines. Previously, @code{step} entered subroutines if there
5d161b24 3531was any debugging information about the routine.
c906108c
SS
3532
3533@item step @var{count}
3534Continue running as in @code{step}, but do so @var{count} times. If a
7a292a7a
SS
3535breakpoint is reached, or a signal not related to stepping occurs before
3536@var{count} steps, stepping stops right away.
c906108c
SS
3537
3538@kindex next
41afff9a 3539@kindex n @r{(@code{next})}
c906108c
SS
3540@item next @r{[}@var{count}@r{]}
3541Continue to the next source line in the current (innermost) stack frame.
7a292a7a
SS
3542This is similar to @code{step}, but function calls that appear within
3543the line of code are executed without stopping. Execution stops when
3544control reaches a different line of code at the original stack level
3545that was executing when you gave the @code{next} command. This command
3546is abbreviated @code{n}.
c906108c
SS
3547
3548An argument @var{count} is a repeat count, as for @code{step}.
3549
3550
3551@c FIX ME!! Do we delete this, or is there a way it fits in with
3552@c the following paragraph? --- Vctoria
3553@c
3554@c @code{next} within a function that lacks debugging information acts like
3555@c @code{step}, but any function calls appearing within the code of the
3556@c function are executed without stopping.
3557
d4f3574e
SS
3558The @code{next} command only stops at the first instruction of a
3559source line. This prevents multiple stops that could otherwise occur in
4a92d011 3560@code{switch} statements, @code{for} loops, etc.
c906108c 3561
b90a5f51
CF
3562@kindex set step-mode
3563@item set step-mode
3564@cindex functions without line info, and stepping
3565@cindex stepping into functions with no line info
3566@itemx set step-mode on
4a92d011 3567The @code{set step-mode on} command causes the @code{step} command to
b90a5f51
CF
3568stop at the first instruction of a function which contains no debug line
3569information rather than stepping over it.
3570
4a92d011
EZ
3571This is useful in cases where you may be interested in inspecting the
3572machine instructions of a function which has no symbolic info and do not
3573want @value{GDBN} to automatically skip over this function.
b90a5f51
CF
3574
3575@item set step-mode off
4a92d011 3576Causes the @code{step} command to step over any functions which contains no
b90a5f51
CF
3577debug information. This is the default.
3578
c906108c
SS
3579@kindex finish
3580@item finish
3581Continue running until just after function in the selected stack frame
3582returns. Print the returned value (if any).
3583
3584Contrast this with the @code{return} command (@pxref{Returning,
3585,Returning from a function}).
3586
3587@kindex until
41afff9a 3588@kindex u @r{(@code{until})}
c906108c
SS
3589@item until
3590@itemx u
3591Continue running until a source line past the current line, in the
3592current stack frame, is reached. This command is used to avoid single
3593stepping through a loop more than once. It is like the @code{next}
3594command, except that when @code{until} encounters a jump, it
3595automatically continues execution until the program counter is greater
3596than the address of the jump.
3597
3598This means that when you reach the end of a loop after single stepping
3599though it, @code{until} makes your program continue execution until it
3600exits the loop. In contrast, a @code{next} command at the end of a loop
3601simply steps back to the beginning of the loop, which forces you to step
3602through the next iteration.
3603
3604@code{until} always stops your program if it attempts to exit the current
3605stack frame.
3606
3607@code{until} may produce somewhat counterintuitive results if the order
3608of machine code does not match the order of the source lines. For
3609example, in the following excerpt from a debugging session, the @code{f}
3610(@code{frame}) command shows that execution is stopped at line
3611@code{206}; yet when we use @code{until}, we get to line @code{195}:
3612
474c8240 3613@smallexample
c906108c
SS
3614(@value{GDBP}) f
3615#0 main (argc=4, argv=0xf7fffae8) at m4.c:206
3616206 expand_input();
3617(@value{GDBP}) until
3618195 for ( ; argc > 0; NEXTARG) @{
474c8240 3619@end smallexample
c906108c
SS
3620
3621This happened because, for execution efficiency, the compiler had
3622generated code for the loop closure test at the end, rather than the
3623start, of the loop---even though the test in a C @code{for}-loop is
3624written before the body of the loop. The @code{until} command appeared
3625to step back to the beginning of the loop when it advanced to this
3626expression; however, it has not really gone to an earlier
3627statement---not in terms of the actual machine code.
3628
3629@code{until} with no argument works by means of single
3630instruction stepping, and hence is slower than @code{until} with an
3631argument.
3632
3633@item until @var{location}
3634@itemx u @var{location}
3635Continue running your program until either the specified location is
3636reached, or the current stack frame returns. @var{location} is any of
3637the forms of argument acceptable to @code{break} (@pxref{Set Breaks,
c60eb6f1
EZ
3638,Setting breakpoints}). This form of the command uses breakpoints, and
3639hence is quicker than @code{until} without an argument. The specified
3640location is actually reached only if it is in the current frame. This
3641implies that @code{until} can be used to skip over recursive function
3642invocations. For instance in the code below, if the current location is
3643line @code{96}, issuing @code{until 99} will execute the program up to
3644line @code{99} in the same invocation of factorial, i.e. after the inner
3645invocations have returned.
3646
3647@smallexample
364894 int factorial (int value)
364995 @{
365096 if (value > 1) @{
365197 value *= factorial (value - 1);
365298 @}
365399 return (value);
3654100 @}
3655@end smallexample
3656
3657
3658@kindex advance @var{location}
3659@itemx advance @var{location}
3660Continue running the program up to the given location. An argument is
3661required, anything of the same form as arguments for the @code{break}
3662command. Execution will also stop upon exit from the current stack
3663frame. This command is similar to @code{until}, but @code{advance} will
3664not skip over recursive function calls, and the target location doesn't
3665have to be in the same frame as the current one.
3666
c906108c
SS
3667
3668@kindex stepi
41afff9a 3669@kindex si @r{(@code{stepi})}
c906108c 3670@item stepi
96a2c332 3671@itemx stepi @var{arg}
c906108c
SS
3672@itemx si
3673Execute one machine instruction, then stop and return to the debugger.
3674
3675It is often useful to do @samp{display/i $pc} when stepping by machine
3676instructions. This makes @value{GDBN} automatically display the next
3677instruction to be executed, each time your program stops. @xref{Auto
3678Display,, Automatic display}.
3679
3680An argument is a repeat count, as in @code{step}.
3681
3682@need 750
3683@kindex nexti
41afff9a 3684@kindex ni @r{(@code{nexti})}
c906108c 3685@item nexti
96a2c332 3686@itemx nexti @var{arg}
c906108c
SS
3687@itemx ni
3688Execute one machine instruction, but if it is a function call,
3689proceed until the function returns.
3690
3691An argument is a repeat count, as in @code{next}.
3692@end table
3693
6d2ebf8b 3694@node Signals
c906108c
SS
3695@section Signals
3696@cindex signals
3697
3698A signal is an asynchronous event that can happen in a program. The
3699operating system defines the possible kinds of signals, and gives each
3700kind a name and a number. For example, in Unix @code{SIGINT} is the
d4f3574e 3701signal a program gets when you type an interrupt character (often @kbd{C-c});
c906108c
SS
3702@code{SIGSEGV} is the signal a program gets from referencing a place in
3703memory far away from all the areas in use; @code{SIGALRM} occurs when
3704the alarm clock timer goes off (which happens only if your program has
3705requested an alarm).
3706
3707@cindex fatal signals
3708Some signals, including @code{SIGALRM}, are a normal part of the
3709functioning of your program. Others, such as @code{SIGSEGV}, indicate
d4f3574e 3710errors; these signals are @dfn{fatal} (they kill your program immediately) if the
c906108c
SS
3711program has not specified in advance some other way to handle the signal.
3712@code{SIGINT} does not indicate an error in your program, but it is normally
3713fatal so it can carry out the purpose of the interrupt: to kill the program.
3714
3715@value{GDBN} has the ability to detect any occurrence of a signal in your
3716program. You can tell @value{GDBN} in advance what to do for each kind of
3717signal.
3718
3719@cindex handling signals
24f93129
EZ
3720Normally, @value{GDBN} is set up to let the non-erroneous signals like
3721@code{SIGALRM} be silently passed to your program
3722(so as not to interfere with their role in the program's functioning)
c906108c
SS
3723but to stop your program immediately whenever an error signal happens.
3724You can change these settings with the @code{handle} command.
3725
3726@table @code
3727@kindex info signals
3728@item info signals
96a2c332 3729@itemx info handle
c906108c
SS
3730Print a table of all the kinds of signals and how @value{GDBN} has been told to
3731handle each one. You can use this to see the signal numbers of all
3732the defined types of signals.
3733
d4f3574e 3734@code{info handle} is an alias for @code{info signals}.
c906108c
SS
3735
3736@kindex handle
3737@item handle @var{signal} @var{keywords}@dots{}
5ece1a18
EZ
3738Change the way @value{GDBN} handles signal @var{signal}. @var{signal}
3739can be the number of a signal or its name (with or without the
24f93129 3740@samp{SIG} at the beginning); a list of signal numbers of the form
5ece1a18
EZ
3741@samp{@var{low}-@var{high}}; or the word @samp{all}, meaning all the
3742known signals. The @var{keywords} say what change to make.
c906108c
SS
3743@end table
3744
3745@c @group
3746The keywords allowed by the @code{handle} command can be abbreviated.
3747Their full names are:
3748
3749@table @code
3750@item nostop
3751@value{GDBN} should not stop your program when this signal happens. It may
3752still print a message telling you that the signal has come in.
3753
3754@item stop
3755@value{GDBN} should stop your program when this signal happens. This implies
3756the @code{print} keyword as well.
3757
3758@item print
3759@value{GDBN} should print a message when this signal happens.
3760
3761@item noprint
3762@value{GDBN} should not mention the occurrence of the signal at all. This
3763implies the @code{nostop} keyword as well.
3764
3765@item pass
5ece1a18 3766@itemx noignore
c906108c
SS
3767@value{GDBN} should allow your program to see this signal; your program
3768can handle the signal, or else it may terminate if the signal is fatal
5ece1a18 3769and not handled. @code{pass} and @code{noignore} are synonyms.
c906108c
SS
3770
3771@item nopass
5ece1a18 3772@itemx ignore
c906108c 3773@value{GDBN} should not allow your program to see this signal.
5ece1a18 3774@code{nopass} and @code{ignore} are synonyms.
c906108c
SS
3775@end table
3776@c @end group
3777
d4f3574e
SS
3778When a signal stops your program, the signal is not visible to the
3779program until you
c906108c
SS
3780continue. Your program sees the signal then, if @code{pass} is in
3781effect for the signal in question @emph{at that time}. In other words,
3782after @value{GDBN} reports a signal, you can use the @code{handle}
3783command with @code{pass} or @code{nopass} to control whether your
3784program sees that signal when you continue.
3785
24f93129
EZ
3786The default is set to @code{nostop}, @code{noprint}, @code{pass} for
3787non-erroneous signals such as @code{SIGALRM}, @code{SIGWINCH} and
3788@code{SIGCHLD}, and to @code{stop}, @code{print}, @code{pass} for the
3789erroneous signals.
3790
c906108c
SS
3791You can also use the @code{signal} command to prevent your program from
3792seeing a signal, or cause it to see a signal it normally would not see,
3793or to give it any signal at any time. For example, if your program stopped
3794due to some sort of memory reference error, you might store correct
3795values into the erroneous variables and continue, hoping to see more
3796execution; but your program would probably terminate immediately as
3797a result of the fatal signal once it saw the signal. To prevent this,
3798you can continue with @samp{signal 0}. @xref{Signaling, ,Giving your
5d161b24 3799program a signal}.
c906108c 3800
6d2ebf8b 3801@node Thread Stops
c906108c
SS
3802@section Stopping and starting multi-thread programs
3803
3804When your program has multiple threads (@pxref{Threads,, Debugging
3805programs with multiple threads}), you can choose whether to set
3806breakpoints on all threads, or on a particular thread.
3807
3808@table @code
3809@cindex breakpoints and threads
3810@cindex thread breakpoints
3811@kindex break @dots{} thread @var{threadno}
3812@item break @var{linespec} thread @var{threadno}
3813@itemx break @var{linespec} thread @var{threadno} if @dots{}
3814@var{linespec} specifies source lines; there are several ways of
3815writing them, but the effect is always to specify some source line.
3816
3817Use the qualifier @samp{thread @var{threadno}} with a breakpoint command
3818to specify that you only want @value{GDBN} to stop the program when a
3819particular thread reaches this breakpoint. @var{threadno} is one of the
3820numeric thread identifiers assigned by @value{GDBN}, shown in the first
3821column of the @samp{info threads} display.
3822
3823If you do not specify @samp{thread @var{threadno}} when you set a
3824breakpoint, the breakpoint applies to @emph{all} threads of your
3825program.
3826
3827You can use the @code{thread} qualifier on conditional breakpoints as
3828well; in this case, place @samp{thread @var{threadno}} before the
3829breakpoint condition, like this:
3830
3831@smallexample
2df3850c 3832(@value{GDBP}) break frik.c:13 thread 28 if bartab > lim
c906108c
SS
3833@end smallexample
3834
3835@end table
3836
3837@cindex stopped threads
3838@cindex threads, stopped
3839Whenever your program stops under @value{GDBN} for any reason,
3840@emph{all} threads of execution stop, not just the current thread. This
3841allows you to examine the overall state of the program, including
3842switching between threads, without worrying that things may change
3843underfoot.
3844
36d86913
MC
3845@cindex thread breakpoints and system calls
3846@cindex system calls and thread breakpoints
3847@cindex premature return from system calls
3848There is an unfortunate side effect. If one thread stops for a
3849breakpoint, or for some other reason, and another thread is blocked in a
3850system call, then the system call may return prematurely. This is a
3851consequence of the interaction between multiple threads and the signals
3852that @value{GDBN} uses to implement breakpoints and other events that
3853stop execution.
3854
3855To handle this problem, your program should check the return value of
3856each system call and react appropriately. This is good programming
3857style anyways.
3858
3859For example, do not write code like this:
3860
3861@smallexample
3862 sleep (10);
3863@end smallexample
3864
3865The call to @code{sleep} will return early if a different thread stops
3866at a breakpoint or for some other reason.
3867
3868Instead, write this:
3869
3870@smallexample
3871 int unslept = 10;
3872 while (unslept > 0)
3873 unslept = sleep (unslept);
3874@end smallexample
3875
3876A system call is allowed to return early, so the system is still
3877conforming to its specification. But @value{GDBN} does cause your
3878multi-threaded program to behave differently than it would without
3879@value{GDBN}.
3880
3881Also, @value{GDBN} uses internal breakpoints in the thread library to
3882monitor certain events such as thread creation and thread destruction.
3883When such an event happens, a system call in another thread may return
3884prematurely, even though your program does not appear to stop.
3885
c906108c
SS
3886@cindex continuing threads
3887@cindex threads, continuing
3888Conversely, whenever you restart the program, @emph{all} threads start
3889executing. @emph{This is true even when single-stepping} with commands
5d161b24 3890like @code{step} or @code{next}.
c906108c
SS
3891
3892In particular, @value{GDBN} cannot single-step all threads in lockstep.
3893Since thread scheduling is up to your debugging target's operating
3894system (not controlled by @value{GDBN}), other threads may
3895execute more than one statement while the current thread completes a
3896single step. Moreover, in general other threads stop in the middle of a
3897statement, rather than at a clean statement boundary, when the program
3898stops.
3899
3900You might even find your program stopped in another thread after
3901continuing or even single-stepping. This happens whenever some other
3902thread runs into a breakpoint, a signal, or an exception before the
3903first thread completes whatever you requested.
3904
3905On some OSes, you can lock the OS scheduler and thus allow only a single
3906thread to run.
3907
3908@table @code
3909@item set scheduler-locking @var{mode}
3910Set the scheduler locking mode. If it is @code{off}, then there is no
3911locking and any thread may run at any time. If @code{on}, then only the
3912current thread may run when the inferior is resumed. The @code{step}
3913mode optimizes for single-stepping. It stops other threads from
3914``seizing the prompt'' by preempting the current thread while you are
3915stepping. Other threads will only rarely (or never) get a chance to run
d4f3574e 3916when you step. They are more likely to run when you @samp{next} over a
c906108c 3917function call, and they are completely free to run when you use commands
d4f3574e 3918like @samp{continue}, @samp{until}, or @samp{finish}. However, unless another
c906108c 3919thread hits a breakpoint during its timeslice, they will never steal the
2df3850c 3920@value{GDBN} prompt away from the thread that you are debugging.
c906108c
SS
3921
3922@item show scheduler-locking
3923Display the current scheduler locking mode.
3924@end table
3925
c906108c 3926
6d2ebf8b 3927@node Stack
c906108c
SS
3928@chapter Examining the Stack
3929
3930When your program has stopped, the first thing you need to know is where it
3931stopped and how it got there.
3932
3933@cindex call stack
5d161b24
DB
3934Each time your program performs a function call, information about the call
3935is generated.
3936That information includes the location of the call in your program,
3937the arguments of the call,
c906108c 3938and the local variables of the function being called.
5d161b24 3939The information is saved in a block of data called a @dfn{stack frame}.
c906108c
SS
3940The stack frames are allocated in a region of memory called the @dfn{call
3941stack}.
3942
3943When your program stops, the @value{GDBN} commands for examining the
3944stack allow you to see all of this information.
3945
3946@cindex selected frame
3947One of the stack frames is @dfn{selected} by @value{GDBN} and many
3948@value{GDBN} commands refer implicitly to the selected frame. In
3949particular, whenever you ask @value{GDBN} for the value of a variable in
3950your program, the value is found in the selected frame. There are
3951special @value{GDBN} commands to select whichever frame you are
3952interested in. @xref{Selection, ,Selecting a frame}.
3953
3954When your program stops, @value{GDBN} automatically selects the
5d161b24 3955currently executing frame and describes it briefly, similar to the
c906108c
SS
3956@code{frame} command (@pxref{Frame Info, ,Information about a frame}).
3957
3958@menu
3959* Frames:: Stack frames
3960* Backtrace:: Backtraces
3961* Selection:: Selecting a frame
3962* Frame Info:: Information on a frame
c906108c
SS
3963
3964@end menu
3965
6d2ebf8b 3966@node Frames
c906108c
SS
3967@section Stack frames
3968
d4f3574e 3969@cindex frame, definition
c906108c
SS
3970@cindex stack frame
3971The call stack is divided up into contiguous pieces called @dfn{stack
3972frames}, or @dfn{frames} for short; each frame is the data associated
3973with one call to one function. The frame contains the arguments given
3974to the function, the function's local variables, and the address at
3975which the function is executing.
3976
3977@cindex initial frame
3978@cindex outermost frame
3979@cindex innermost frame
3980When your program is started, the stack has only one frame, that of the
3981function @code{main}. This is called the @dfn{initial} frame or the
3982@dfn{outermost} frame. Each time a function is called, a new frame is
3983made. Each time a function returns, the frame for that function invocation
3984is eliminated. If a function is recursive, there can be many frames for
3985the same function. The frame for the function in which execution is
3986actually occurring is called the @dfn{innermost} frame. This is the most
3987recently created of all the stack frames that still exist.
3988
3989@cindex frame pointer
3990Inside your program, stack frames are identified by their addresses. A
3991stack frame consists of many bytes, each of which has its own address; each
3992kind of computer has a convention for choosing one byte whose
3993address serves as the address of the frame. Usually this address is kept
3994in a register called the @dfn{frame pointer register} while execution is
3995going on in that frame.
3996
3997@cindex frame number
3998@value{GDBN} assigns numbers to all existing stack frames, starting with
3999zero for the innermost frame, one for the frame that called it,
4000and so on upward. These numbers do not really exist in your program;
4001they are assigned by @value{GDBN} to give you a way of designating stack
4002frames in @value{GDBN} commands.
4003
6d2ebf8b
SS
4004@c The -fomit-frame-pointer below perennially causes hbox overflow
4005@c underflow problems.
c906108c
SS
4006@cindex frameless execution
4007Some compilers provide a way to compile functions so that they operate
6d2ebf8b 4008without stack frames. (For example, the @value{GCC} option
474c8240 4009@smallexample
6d2ebf8b 4010@samp{-fomit-frame-pointer}
474c8240 4011@end smallexample
6d2ebf8b 4012generates functions without a frame.)
c906108c
SS
4013This is occasionally done with heavily used library functions to save
4014the frame setup time. @value{GDBN} has limited facilities for dealing
4015with these function invocations. If the innermost function invocation
4016has no stack frame, @value{GDBN} nevertheless regards it as though
4017it had a separate frame, which is numbered zero as usual, allowing
4018correct tracing of the function call chain. However, @value{GDBN} has
4019no provision for frameless functions elsewhere in the stack.
4020
4021@table @code
d4f3574e 4022@kindex frame@r{, command}
41afff9a 4023@cindex current stack frame
c906108c 4024@item frame @var{args}
5d161b24 4025The @code{frame} command allows you to move from one stack frame to another,
c906108c 4026and to print the stack frame you select. @var{args} may be either the
5d161b24
DB
4027address of the frame or the stack frame number. Without an argument,
4028@code{frame} prints the current stack frame.
c906108c
SS
4029
4030@kindex select-frame
41afff9a 4031@cindex selecting frame silently
c906108c
SS
4032@item select-frame
4033The @code{select-frame} command allows you to move from one stack frame
4034to another without printing the frame. This is the silent version of
4035@code{frame}.
4036@end table
4037
6d2ebf8b 4038@node Backtrace
c906108c
SS
4039@section Backtraces
4040
4041@cindex backtraces
4042@cindex tracebacks
4043@cindex stack traces
4044A backtrace is a summary of how your program got where it is. It shows one
4045line per frame, for many frames, starting with the currently executing
4046frame (frame zero), followed by its caller (frame one), and on up the
4047stack.
4048
4049@table @code
4050@kindex backtrace
41afff9a 4051@kindex bt @r{(@code{backtrace})}
c906108c
SS
4052@item backtrace
4053@itemx bt
4054Print a backtrace of the entire stack: one line per frame for all
4055frames in the stack.
4056
4057You can stop the backtrace at any time by typing the system interrupt
4058character, normally @kbd{C-c}.
4059
4060@item backtrace @var{n}
4061@itemx bt @var{n}
4062Similar, but print only the innermost @var{n} frames.
4063
4064@item backtrace -@var{n}
4065@itemx bt -@var{n}
4066Similar, but print only the outermost @var{n} frames.
4067@end table
4068
4069@kindex where
4070@kindex info stack
c906108c
SS
4071The names @code{where} and @code{info stack} (abbreviated @code{info s})
4072are additional aliases for @code{backtrace}.
4073
4074Each line in the backtrace shows the frame number and the function name.
4075The program counter value is also shown---unless you use @code{set
4076print address off}. The backtrace also shows the source file name and
4077line number, as well as the arguments to the function. The program
4078counter value is omitted if it is at the beginning of the code for that
4079line number.
4080
4081Here is an example of a backtrace. It was made with the command
4082@samp{bt 3}, so it shows the innermost three frames.
4083
4084@smallexample
4085@group
5d161b24 4086#0 m4_traceon (obs=0x24eb0, argc=1, argv=0x2b8c8)
c906108c
SS
4087 at builtin.c:993
4088#1 0x6e38 in expand_macro (sym=0x2b600) at macro.c:242
4089#2 0x6840 in expand_token (obs=0x0, t=177664, td=0xf7fffb08)
4090 at macro.c:71
4091(More stack frames follow...)
4092@end group
4093@end smallexample
4094
4095@noindent
4096The display for frame zero does not begin with a program counter
4097value, indicating that your program has stopped at the beginning of the
4098code for line @code{993} of @code{builtin.c}.
4099
25d29d70
AC
4100Most programs have a standard user entry point---a place where system
4101libraries and startup code transition into user code. For C this is
4102@code{main}. When @value{GDBN} finds the entry function in a backtrace
4103it will terminate the backtrace, to avoid tracing into highly
4104system-specific (and generally uninteresting) code.
4105
4106If you need to examine the startup code, or limit the number of levels
4107in a backtrace, you can change this behavior:
95f90d25
DJ
4108
4109@table @code
25d29d70
AC
4110@item set backtrace past-main
4111@itemx set backtrace past-main on
4644b6e3 4112@kindex set backtrace
25d29d70
AC
4113Backtraces will continue past the user entry point.
4114
4115@item set backtrace past-main off
95f90d25
DJ
4116Backtraces will stop when they encounter the user entry point. This is the
4117default.
4118
25d29d70 4119@item show backtrace past-main
4644b6e3 4120@kindex show backtrace
25d29d70
AC
4121Display the current user entry point backtrace policy.
4122
2315ffec
RC
4123@item set backtrace past-entry
4124@itemx set backtrace past-entry on
4125Backtraces will continue past the internal entry point of an application.
4126This entry point is encoded by the linker when the application is built,
4127and is likely before the user entry point @code{main} (or equivalent) is called.
4128
4129@item set backtrace past-entry off
4130Backtraces will stop when they encouter the internal entry point of an
4131application. This is the default.
4132
4133@item show backtrace past-entry
4134Display the current internal entry point backtrace policy.
4135
25d29d70
AC
4136@item set backtrace limit @var{n}
4137@itemx set backtrace limit 0
4138@cindex backtrace limit
4139Limit the backtrace to @var{n} levels. A value of zero means
4140unlimited.
95f90d25 4141
25d29d70
AC
4142@item show backtrace limit
4143Display the current limit on backtrace levels.
95f90d25
DJ
4144@end table
4145
6d2ebf8b 4146@node Selection
c906108c
SS
4147@section Selecting a frame
4148
4149Most commands for examining the stack and other data in your program work on
4150whichever stack frame is selected at the moment. Here are the commands for
4151selecting a stack frame; all of them finish by printing a brief description
4152of the stack frame just selected.
4153
4154@table @code
d4f3574e 4155@kindex frame@r{, selecting}
41afff9a 4156@kindex f @r{(@code{frame})}
c906108c
SS
4157@item frame @var{n}
4158@itemx f @var{n}
4159Select frame number @var{n}. Recall that frame zero is the innermost
4160(currently executing) frame, frame one is the frame that called the
4161innermost one, and so on. The highest-numbered frame is the one for
4162@code{main}.
4163
4164@item frame @var{addr}
4165@itemx f @var{addr}
4166Select the frame at address @var{addr}. This is useful mainly if the
4167chaining of stack frames has been damaged by a bug, making it
4168impossible for @value{GDBN} to assign numbers properly to all frames. In
4169addition, this can be useful when your program has multiple stacks and
4170switches between them.
4171
c906108c
SS
4172On the SPARC architecture, @code{frame} needs two addresses to
4173select an arbitrary frame: a frame pointer and a stack pointer.
4174
4175On the MIPS and Alpha architecture, it needs two addresses: a stack
4176pointer and a program counter.
4177
4178On the 29k architecture, it needs three addresses: a register stack
4179pointer, a program counter, and a memory stack pointer.
4180@c note to future updaters: this is conditioned on a flag
4181@c SETUP_ARBITRARY_FRAME in the tm-*.h files. The above is up to date
4182@c as of 27 Jan 1994.
c906108c
SS
4183
4184@kindex up
4185@item up @var{n}
4186Move @var{n} frames up the stack. For positive numbers @var{n}, this
4187advances toward the outermost frame, to higher frame numbers, to frames
4188that have existed longer. @var{n} defaults to one.
4189
4190@kindex down
41afff9a 4191@kindex do @r{(@code{down})}
c906108c
SS
4192@item down @var{n}
4193Move @var{n} frames down the stack. For positive numbers @var{n}, this
4194advances toward the innermost frame, to lower frame numbers, to frames
4195that were created more recently. @var{n} defaults to one. You may
4196abbreviate @code{down} as @code{do}.
4197@end table
4198
4199All of these commands end by printing two lines of output describing the
4200frame. The first line shows the frame number, the function name, the
4201arguments, and the source file and line number of execution in that
5d161b24 4202frame. The second line shows the text of that source line.
c906108c
SS
4203
4204@need 1000
4205For example:
4206
4207@smallexample
4208@group
4209(@value{GDBP}) up
4210#1 0x22f0 in main (argc=1, argv=0xf7fffbf4, env=0xf7fffbfc)
4211 at env.c:10
421210 read_input_file (argv[i]);
4213@end group
4214@end smallexample
4215
4216After such a printout, the @code{list} command with no arguments
4217prints ten lines centered on the point of execution in the frame.
87885426
FN
4218You can also edit the program at the point of execution with your favorite
4219editing program by typing @code{edit}.
4220@xref{List, ,Printing source lines},
4221for details.
c906108c
SS
4222
4223@table @code
4224@kindex down-silently
4225@kindex up-silently
4226@item up-silently @var{n}
4227@itemx down-silently @var{n}
4228These two commands are variants of @code{up} and @code{down},
4229respectively; they differ in that they do their work silently, without
4230causing display of the new frame. They are intended primarily for use
4231in @value{GDBN} command scripts, where the output might be unnecessary and
4232distracting.
4233@end table
4234
6d2ebf8b 4235@node Frame Info
c906108c
SS
4236@section Information about a frame
4237
4238There are several other commands to print information about the selected
4239stack frame.
4240
4241@table @code
4242@item frame
4243@itemx f
4244When used without any argument, this command does not change which
4245frame is selected, but prints a brief description of the currently
4246selected stack frame. It can be abbreviated @code{f}. With an
4247argument, this command is used to select a stack frame.
4248@xref{Selection, ,Selecting a frame}.
4249
4250@kindex info frame
41afff9a 4251@kindex info f @r{(@code{info frame})}
c906108c
SS
4252@item info frame
4253@itemx info f
4254This command prints a verbose description of the selected stack frame,
4255including:
4256
4257@itemize @bullet
5d161b24
DB
4258@item
4259the address of the frame
c906108c
SS
4260@item
4261the address of the next frame down (called by this frame)
4262@item
4263the address of the next frame up (caller of this frame)
4264@item
4265the language in which the source code corresponding to this frame is written
4266@item
4267the address of the frame's arguments
4268@item
d4f3574e
SS
4269the address of the frame's local variables
4270@item
c906108c
SS
4271the program counter saved in it (the address of execution in the caller frame)
4272@item
4273which registers were saved in the frame
4274@end itemize
4275
4276@noindent The verbose description is useful when
4277something has gone wrong that has made the stack format fail to fit
4278the usual conventions.
4279
4280@item info frame @var{addr}
4281@itemx info f @var{addr}
4282Print a verbose description of the frame at address @var{addr}, without
4283selecting that frame. The selected frame remains unchanged by this
4284command. This requires the same kind of address (more than one for some
4285architectures) that you specify in the @code{frame} command.
4286@xref{Selection, ,Selecting a frame}.
4287
4288@kindex info args
4289@item info args
4290Print the arguments of the selected frame, each on a separate line.
4291
4292@item info locals
4293@kindex info locals
4294Print the local variables of the selected frame, each on a separate
4295line. These are all variables (declared either static or automatic)
4296accessible at the point of execution of the selected frame.
4297
c906108c 4298@kindex info catch
d4f3574e
SS
4299@cindex catch exceptions, list active handlers
4300@cindex exception handlers, how to list
c906108c
SS
4301@item info catch
4302Print a list of all the exception handlers that are active in the
4303current stack frame at the current point of execution. To see other
4304exception handlers, visit the associated frame (using the @code{up},
4305@code{down}, or @code{frame} commands); then type @code{info catch}.
4306@xref{Set Catchpoints, , Setting catchpoints}.
53a5351d 4307
c906108c
SS
4308@end table
4309
c906108c 4310
6d2ebf8b 4311@node Source
c906108c
SS
4312@chapter Examining Source Files
4313
4314@value{GDBN} can print parts of your program's source, since the debugging
4315information recorded in the program tells @value{GDBN} what source files were
4316used to build it. When your program stops, @value{GDBN} spontaneously prints
4317the line where it stopped. Likewise, when you select a stack frame
4318(@pxref{Selection, ,Selecting a frame}), @value{GDBN} prints the line where
4319execution in that frame has stopped. You can print other portions of
4320source files by explicit command.
4321
7a292a7a 4322If you use @value{GDBN} through its @sc{gnu} Emacs interface, you may
d4f3574e 4323prefer to use Emacs facilities to view source; see @ref{Emacs, ,Using
7a292a7a 4324@value{GDBN} under @sc{gnu} Emacs}.
c906108c
SS
4325
4326@menu
4327* List:: Printing source lines
87885426 4328* Edit:: Editing source files
c906108c 4329* Search:: Searching source files
c906108c
SS
4330* Source Path:: Specifying source directories
4331* Machine Code:: Source and machine code
4332@end menu
4333
6d2ebf8b 4334@node List
c906108c
SS
4335@section Printing source lines
4336
4337@kindex list
41afff9a 4338@kindex l @r{(@code{list})}
c906108c 4339To print lines from a source file, use the @code{list} command
5d161b24 4340(abbreviated @code{l}). By default, ten lines are printed.
c906108c
SS
4341There are several ways to specify what part of the file you want to print.
4342
4343Here are the forms of the @code{list} command most commonly used:
4344
4345@table @code
4346@item list @var{linenum}
4347Print lines centered around line number @var{linenum} in the
4348current source file.
4349
4350@item list @var{function}
4351Print lines centered around the beginning of function
4352@var{function}.
4353
4354@item list
4355Print more lines. If the last lines printed were printed with a
4356@code{list} command, this prints lines following the last lines
4357printed; however, if the last line printed was a solitary line printed
4358as part of displaying a stack frame (@pxref{Stack, ,Examining the
4359Stack}), this prints lines centered around that line.
4360
4361@item list -
4362Print lines just before the lines last printed.
4363@end table
4364
4365By default, @value{GDBN} prints ten source lines with any of these forms of
4366the @code{list} command. You can change this using @code{set listsize}:
4367
4368@table @code
4369@kindex set listsize
4370@item set listsize @var{count}
4371Make the @code{list} command display @var{count} source lines (unless
4372the @code{list} argument explicitly specifies some other number).
4373
4374@kindex show listsize
4375@item show listsize
4376Display the number of lines that @code{list} prints.
4377@end table
4378
4379Repeating a @code{list} command with @key{RET} discards the argument,
4380so it is equivalent to typing just @code{list}. This is more useful
4381than listing the same lines again. An exception is made for an
4382argument of @samp{-}; that argument is preserved in repetition so that
4383each repetition moves up in the source file.
4384
4385@cindex linespec
4386In general, the @code{list} command expects you to supply zero, one or two
4387@dfn{linespecs}. Linespecs specify source lines; there are several ways
d4f3574e 4388of writing them, but the effect is always to specify some source line.
c906108c
SS
4389Here is a complete description of the possible arguments for @code{list}:
4390
4391@table @code
4392@item list @var{linespec}
4393Print lines centered around the line specified by @var{linespec}.
4394
4395@item list @var{first},@var{last}
4396Print lines from @var{first} to @var{last}. Both arguments are
4397linespecs.
4398
4399@item list ,@var{last}
4400Print lines ending with @var{last}.
4401
4402@item list @var{first},
4403Print lines starting with @var{first}.
4404
4405@item list +
4406Print lines just after the lines last printed.
4407
4408@item list -
4409Print lines just before the lines last printed.
4410
4411@item list
4412As described in the preceding table.
4413@end table
4414
4415Here are the ways of specifying a single source line---all the
4416kinds of linespec.
4417
4418@table @code
4419@item @var{number}
4420Specifies line @var{number} of the current source file.
4421When a @code{list} command has two linespecs, this refers to
4422the same source file as the first linespec.
4423
4424@item +@var{offset}
4425Specifies the line @var{offset} lines after the last line printed.
4426When used as the second linespec in a @code{list} command that has
4427two, this specifies the line @var{offset} lines down from the
4428first linespec.
4429
4430@item -@var{offset}
4431Specifies the line @var{offset} lines before the last line printed.
4432
4433@item @var{filename}:@var{number}
4434Specifies line @var{number} in the source file @var{filename}.
4435
4436@item @var{function}
4437Specifies the line that begins the body of the function @var{function}.
4438For example: in C, this is the line with the open brace.
4439
4440@item @var{filename}:@var{function}
4441Specifies the line of the open-brace that begins the body of the
4442function @var{function} in the file @var{filename}. You only need the
4443file name with a function name to avoid ambiguity when there are
4444identically named functions in different source files.
4445
4446@item *@var{address}
4447Specifies the line containing the program address @var{address}.
4448@var{address} may be any expression.
4449@end table
4450
87885426
FN
4451@node Edit
4452@section Editing source files
4453@cindex editing source files
4454
4455@kindex edit
4456@kindex e @r{(@code{edit})}
4457To edit the lines in a source file, use the @code{edit} command.
4458The editing program of your choice
4459is invoked with the current line set to
4460the active line in the program.
4461Alternatively, there are several ways to specify what part of the file you
4462want to print if you want to see other parts of the program.
4463
4464Here are the forms of the @code{edit} command most commonly used:
4465
4466@table @code
4467@item edit
4468Edit the current source file at the active line number in the program.
4469
4470@item edit @var{number}
4471Edit the current source file with @var{number} as the active line number.
4472
4473@item edit @var{function}
4474Edit the file containing @var{function} at the beginning of its definition.
4475
4476@item edit @var{filename}:@var{number}
4477Specifies line @var{number} in the source file @var{filename}.
4478
4479@item edit @var{filename}:@var{function}
4480Specifies the line that begins the body of the
4481function @var{function} in the file @var{filename}. You only need the
4482file name with a function name to avoid ambiguity when there are
4483identically named functions in different source files.
4484
4485@item edit *@var{address}
4486Specifies the line containing the program address @var{address}.
4487@var{address} may be any expression.
4488@end table
4489
4490@subsection Choosing your editor
4491You can customize @value{GDBN} to use any editor you want
4492@footnote{
4493The only restriction is that your editor (say @code{ex}), recognizes the
4494following command-line syntax:
10998722 4495@smallexample
87885426 4496ex +@var{number} file
10998722 4497@end smallexample
15387254
EZ
4498The optional numeric value +@var{number} specifies the number of the line in
4499the file where to start editing.}.
4500By default, it is @file{@value{EDITOR}}, but you can change this
10998722
AC
4501by setting the environment variable @code{EDITOR} before using
4502@value{GDBN}. For example, to configure @value{GDBN} to use the
4503@code{vi} editor, you could use these commands with the @code{sh} shell:
4504@smallexample
87885426
FN
4505EDITOR=/usr/bin/vi
4506export EDITOR
15387254 4507gdb @dots{}
10998722 4508@end smallexample
87885426 4509or in the @code{csh} shell,
10998722 4510@smallexample
87885426 4511setenv EDITOR /usr/bin/vi
15387254 4512gdb @dots{}
10998722 4513@end smallexample
87885426 4514
6d2ebf8b 4515@node Search
c906108c 4516@section Searching source files
15387254 4517@cindex searching source files
c906108c
SS
4518@kindex reverse-search
4519
4520There are two commands for searching through the current source file for a
4521regular expression.
4522
4523@table @code
4524@kindex search
4525@kindex forward-search
4526@item forward-search @var{regexp}
4527@itemx search @var{regexp}
4528The command @samp{forward-search @var{regexp}} checks each line,
4529starting with the one following the last line listed, for a match for
5d161b24 4530@var{regexp}. It lists the line that is found. You can use the
c906108c
SS
4531synonym @samp{search @var{regexp}} or abbreviate the command name as
4532@code{fo}.
4533
4534@item reverse-search @var{regexp}
4535The command @samp{reverse-search @var{regexp}} checks each line, starting
4536with the one before the last line listed and going backward, for a match
4537for @var{regexp}. It lists the line that is found. You can abbreviate
4538this command as @code{rev}.
4539@end table
c906108c 4540
6d2ebf8b 4541@node Source Path
c906108c
SS
4542@section Specifying source directories
4543
4544@cindex source path
4545@cindex directories for source files
4546Executable programs sometimes do not record the directories of the source
4547files from which they were compiled, just the names. Even when they do,
4548the directories could be moved between the compilation and your debugging
4549session. @value{GDBN} has a list of directories to search for source files;
4550this is called the @dfn{source path}. Each time @value{GDBN} wants a source file,
4551it tries all the directories in the list, in the order they are present
0b66e38c
EZ
4552in the list, until it finds a file with the desired name.
4553
4554For example, suppose an executable references the file
4555@file{/usr/src/foo-1.0/lib/foo.c}, and our source path is
4556@file{/mnt/cross}. The file is first looked up literally; if this
4557fails, @file{/mnt/cross/usr/src/foo-1.0/lib/foo.c} is tried; if this
4558fails, @file{/mnt/cross/foo.c} is opened; if this fails, an error
4559message is printed. @value{GDBN} does not look up the parts of the
4560source file name, such as @file{/mnt/cross/src/foo-1.0/lib/foo.c}.
4561Likewise, the subdirectories of the source path are not searched: if
4562the source path is @file{/mnt/cross}, and the binary refers to
4563@file{foo.c}, @value{GDBN} would not find it under
4564@file{/mnt/cross/usr/src/foo-1.0/lib}.
4565
4566Plain file names, relative file names with leading directories, file
4567names containing dots, etc.@: are all treated as described above; for
4568instance, if the source path is @file{/mnt/cross}, and the source file
4569is recorded as @file{../lib/foo.c}, @value{GDBN} would first try
4570@file{../lib/foo.c}, then @file{/mnt/cross/../lib/foo.c}, and after
4571that---@file{/mnt/cross/foo.c}.
4572
4573Note that the executable search path is @emph{not} used to locate the
4574source files. Neither is the current working directory, unless it
4575happens to be in the source path.
c906108c
SS
4576
4577Whenever you reset or rearrange the source path, @value{GDBN} clears out
4578any information it has cached about where source files are found and where
4579each line is in the file.
4580
4581@kindex directory
4582@kindex dir
d4f3574e
SS
4583When you start @value{GDBN}, its source path includes only @samp{cdir}
4584and @samp{cwd}, in that order.
c906108c
SS
4585To add other directories, use the @code{directory} command.
4586
4587@table @code
4588@item directory @var{dirname} @dots{}
4589@item dir @var{dirname} @dots{}
4590Add directory @var{dirname} to the front of the source path. Several
d4f3574e
SS
4591directory names may be given to this command, separated by @samp{:}
4592(@samp{;} on MS-DOS and MS-Windows, where @samp{:} usually appears as
4593part of absolute file names) or
c906108c
SS
4594whitespace. You may specify a directory that is already in the source
4595path; this moves it forward, so @value{GDBN} searches it sooner.
4596
4597@kindex cdir
4598@kindex cwd
41afff9a
EZ
4599@vindex $cdir@r{, convenience variable}
4600@vindex $cwdr@r{, convenience variable}
c906108c
SS
4601@cindex compilation directory
4602@cindex current directory
4603@cindex working directory
4604@cindex directory, current
4605@cindex directory, compilation
4606You can use the string @samp{$cdir} to refer to the compilation
4607directory (if one is recorded), and @samp{$cwd} to refer to the current
4608working directory. @samp{$cwd} is not the same as @samp{.}---the former
4609tracks the current working directory as it changes during your @value{GDBN}
4610session, while the latter is immediately expanded to the current
4611directory at the time you add an entry to the source path.
4612
4613@item directory
4614Reset the source path to empty again. This requires confirmation.
4615
4616@c RET-repeat for @code{directory} is explicitly disabled, but since
4617@c repeating it would be a no-op we do not say that. (thanks to RMS)
4618
4619@item show directories
4620@kindex show directories
4621Print the source path: show which directories it contains.
4622@end table
4623
4624If your source path is cluttered with directories that are no longer of
4625interest, @value{GDBN} may sometimes cause confusion by finding the wrong
4626versions of source. You can correct the situation as follows:
4627
4628@enumerate
4629@item
4630Use @code{directory} with no argument to reset the source path to empty.
4631
4632@item
4633Use @code{directory} with suitable arguments to reinstall the
4634directories you want in the source path. You can add all the
4635directories in one command.
4636@end enumerate
4637
6d2ebf8b 4638@node Machine Code
c906108c 4639@section Source and machine code
15387254 4640@cindex source line and its code address
c906108c
SS
4641
4642You can use the command @code{info line} to map source lines to program
4643addresses (and vice versa), and the command @code{disassemble} to display
4644a range of addresses as machine instructions. When run under @sc{gnu} Emacs
d4f3574e 4645mode, the @code{info line} command causes the arrow to point to the
5d161b24 4646line specified. Also, @code{info line} prints addresses in symbolic form as
c906108c
SS
4647well as hex.
4648
4649@table @code
4650@kindex info line
4651@item info line @var{linespec}
4652Print the starting and ending addresses of the compiled code for
4653source line @var{linespec}. You can specify source lines in any of
4654the ways understood by the @code{list} command (@pxref{List, ,Printing
4655source lines}).
4656@end table
4657
4658For example, we can use @code{info line} to discover the location of
4659the object code for the first line of function
4660@code{m4_changequote}:
4661
d4f3574e
SS
4662@c FIXME: I think this example should also show the addresses in
4663@c symbolic form, as they usually would be displayed.
c906108c 4664@smallexample
96a2c332 4665(@value{GDBP}) info line m4_changequote
c906108c
SS
4666Line 895 of "builtin.c" starts at pc 0x634c and ends at 0x6350.
4667@end smallexample
4668
4669@noindent
15387254 4670@cindex code address and its source line
c906108c
SS
4671We can also inquire (using @code{*@var{addr}} as the form for
4672@var{linespec}) what source line covers a particular address:
4673@smallexample
4674(@value{GDBP}) info line *0x63ff
4675Line 926 of "builtin.c" starts at pc 0x63e4 and ends at 0x6404.
4676@end smallexample
4677
4678@cindex @code{$_} and @code{info line}
15387254 4679@cindex @code{x} command, default address
41afff9a 4680@kindex x@r{(examine), and} info line
c906108c
SS
4681After @code{info line}, the default address for the @code{x} command
4682is changed to the starting address of the line, so that @samp{x/i} is
4683sufficient to begin examining the machine code (@pxref{Memory,
4684,Examining memory}). Also, this address is saved as the value of the
4685convenience variable @code{$_} (@pxref{Convenience Vars, ,Convenience
4686variables}).
4687
4688@table @code
4689@kindex disassemble
4690@cindex assembly instructions
4691@cindex instructions, assembly
4692@cindex machine instructions
4693@cindex listing machine instructions
4694@item disassemble
4695This specialized command dumps a range of memory as machine
4696instructions. The default memory range is the function surrounding the
4697program counter of the selected frame. A single argument to this
4698command is a program counter value; @value{GDBN} dumps the function
4699surrounding this value. Two arguments specify a range of addresses
4700(first inclusive, second exclusive) to dump.
4701@end table
4702
c906108c
SS
4703The following example shows the disassembly of a range of addresses of
4704HP PA-RISC 2.0 code:
4705
4706@smallexample
4707(@value{GDBP}) disas 0x32c4 0x32e4
4708Dump of assembler code from 0x32c4 to 0x32e4:
47090x32c4 <main+204>: addil 0,dp
47100x32c8 <main+208>: ldw 0x22c(sr0,r1),r26
47110x32cc <main+212>: ldil 0x3000,r31
47120x32d0 <main+216>: ble 0x3f8(sr4,r31)
47130x32d4 <main+220>: ldo 0(r31),rp
47140x32d8 <main+224>: addil -0x800,dp
47150x32dc <main+228>: ldo 0x588(r1),r26
47160x32e0 <main+232>: ldil 0x3000,r31
4717End of assembler dump.
4718@end smallexample
c906108c
SS
4719
4720Some architectures have more than one commonly-used set of instruction
4721mnemonics or other syntax.
4722
4723@table @code
d4f3574e 4724@kindex set disassembly-flavor
d4f3574e
SS
4725@cindex Intel disassembly flavor
4726@cindex AT&T disassembly flavor
4727@item set disassembly-flavor @var{instruction-set}
c906108c
SS
4728Select the instruction set to use when disassembling the
4729program via the @code{disassemble} or @code{x/i} commands.
4730
4731Currently this command is only defined for the Intel x86 family. You
d4f3574e
SS
4732can set @var{instruction-set} to either @code{intel} or @code{att}.
4733The default is @code{att}, the AT&T flavor used by default by Unix
4734assemblers for x86-based targets.
c906108c
SS
4735@end table
4736
4737
6d2ebf8b 4738@node Data
c906108c
SS
4739@chapter Examining Data
4740
4741@cindex printing data
4742@cindex examining data
4743@kindex print
4744@kindex inspect
4745@c "inspect" is not quite a synonym if you are using Epoch, which we do not
4746@c document because it is nonstandard... Under Epoch it displays in a
4747@c different window or something like that.
4748The usual way to examine data in your program is with the @code{print}
7a292a7a
SS
4749command (abbreviated @code{p}), or its synonym @code{inspect}. It
4750evaluates and prints the value of an expression of the language your
4751program is written in (@pxref{Languages, ,Using @value{GDBN} with
4752Different Languages}).
c906108c
SS
4753
4754@table @code
d4f3574e
SS
4755@item print @var{expr}
4756@itemx print /@var{f} @var{expr}
4757@var{expr} is an expression (in the source language). By default the
4758value of @var{expr} is printed in a format appropriate to its data type;
c906108c 4759you can choose a different format by specifying @samp{/@var{f}}, where
d4f3574e 4760@var{f} is a letter specifying the format; see @ref{Output Formats,,Output
c906108c
SS
4761formats}.
4762
4763@item print
4764@itemx print /@var{f}
15387254 4765@cindex reprint the last value
d4f3574e 4766If you omit @var{expr}, @value{GDBN} displays the last value again (from the
c906108c
SS
4767@dfn{value history}; @pxref{Value History, ,Value history}). This allows you to
4768conveniently inspect the same value in an alternative format.
4769@end table
4770
4771A more low-level way of examining data is with the @code{x} command.
4772It examines data in memory at a specified address and prints it in a
4773specified format. @xref{Memory, ,Examining memory}.
4774
7a292a7a 4775If you are interested in information about types, or about how the
d4f3574e
SS
4776fields of a struct or a class are declared, use the @code{ptype @var{exp}}
4777command rather than @code{print}. @xref{Symbols, ,Examining the Symbol
7a292a7a 4778Table}.
c906108c
SS
4779
4780@menu
4781* Expressions:: Expressions
4782* Variables:: Program variables
4783* Arrays:: Artificial arrays
4784* Output Formats:: Output formats
4785* Memory:: Examining memory
4786* Auto Display:: Automatic display
4787* Print Settings:: Print settings
4788* Value History:: Value history
4789* Convenience Vars:: Convenience variables
4790* Registers:: Registers
c906108c 4791* Floating Point Hardware:: Floating point hardware
53c69bd7 4792* Vector Unit:: Vector Unit
b383017d 4793* Auxiliary Vector:: Auxiliary data provided by operating system
29e57380 4794* Memory Region Attributes:: Memory region attributes
16d9dec6 4795* Dump/Restore Files:: Copy between memory and a file
384ee23f 4796* Core File Generation:: Cause a program dump its core
a0eb71c5
KB
4797* Character Sets:: Debugging programs that use a different
4798 character set than GDB does
c906108c
SS
4799@end menu
4800
6d2ebf8b 4801@node Expressions
c906108c
SS
4802@section Expressions
4803
4804@cindex expressions
4805@code{print} and many other @value{GDBN} commands accept an expression and
4806compute its value. Any kind of constant, variable or operator defined
4807by the programming language you are using is valid in an expression in
e2e0bcd1
JB
4808@value{GDBN}. This includes conditional expressions, function calls,
4809casts, and string constants. It also includes preprocessor macros, if
4810you compiled your program to include this information; see
4811@ref{Compilation}.
c906108c 4812
15387254 4813@cindex arrays in expressions
d4f3574e
SS
4814@value{GDBN} supports array constants in expressions input by
4815the user. The syntax is @{@var{element}, @var{element}@dots{}@}. For example,
5d161b24 4816you can use the command @code{print @{1, 2, 3@}} to build up an array in
d4f3574e 4817memory that is @code{malloc}ed in the target program.
c906108c 4818
c906108c
SS
4819Because C is so widespread, most of the expressions shown in examples in
4820this manual are in C. @xref{Languages, , Using @value{GDBN} with Different
4821Languages}, for information on how to use expressions in other
4822languages.
4823
4824In this section, we discuss operators that you can use in @value{GDBN}
4825expressions regardless of your programming language.
4826
15387254 4827@cindex casts, in expressions
c906108c
SS
4828Casts are supported in all languages, not just in C, because it is so
4829useful to cast a number into a pointer in order to examine a structure
4830at that address in memory.
4831@c FIXME: casts supported---Mod2 true?
c906108c
SS
4832
4833@value{GDBN} supports these operators, in addition to those common
4834to programming languages:
4835
4836@table @code
4837@item @@
4838@samp{@@} is a binary operator for treating parts of memory as arrays.
4839@xref{Arrays, ,Artificial arrays}, for more information.
4840
4841@item ::
4842@samp{::} allows you to specify a variable in terms of the file or
4843function where it is defined. @xref{Variables, ,Program variables}.
4844
4845@cindex @{@var{type}@}
4846@cindex type casting memory
4847@cindex memory, viewing as typed object
4848@cindex casts, to view memory
4849@item @{@var{type}@} @var{addr}
4850Refers to an object of type @var{type} stored at address @var{addr} in
4851memory. @var{addr} may be any expression whose value is an integer or
4852pointer (but parentheses are required around binary operators, just as in
4853a cast). This construct is allowed regardless of what kind of data is
4854normally supposed to reside at @var{addr}.
4855@end table
4856
6d2ebf8b 4857@node Variables
c906108c
SS
4858@section Program variables
4859
4860The most common kind of expression to use is the name of a variable
4861in your program.
4862
4863Variables in expressions are understood in the selected stack frame
4864(@pxref{Selection, ,Selecting a frame}); they must be either:
4865
4866@itemize @bullet
4867@item
4868global (or file-static)
4869@end itemize
4870
5d161b24 4871@noindent or
c906108c
SS
4872
4873@itemize @bullet
4874@item
4875visible according to the scope rules of the
4876programming language from the point of execution in that frame
5d161b24 4877@end itemize
c906108c
SS
4878
4879@noindent This means that in the function
4880
474c8240 4881@smallexample
c906108c
SS
4882foo (a)
4883 int a;
4884@{
4885 bar (a);
4886 @{
4887 int b = test ();
4888 bar (b);
4889 @}
4890@}
474c8240 4891@end smallexample
c906108c
SS
4892
4893@noindent
4894you can examine and use the variable @code{a} whenever your program is
4895executing within the function @code{foo}, but you can only use or
4896examine the variable @code{b} while your program is executing inside
4897the block where @code{b} is declared.
4898
4899@cindex variable name conflict
4900There is an exception: you can refer to a variable or function whose
4901scope is a single source file even if the current execution point is not
4902in this file. But it is possible to have more than one such variable or
4903function with the same name (in different source files). If that
4904happens, referring to that name has unpredictable effects. If you wish,
4905you can specify a static variable in a particular function or file,
15387254 4906using the colon-colon (@code{::}) notation:
c906108c 4907
d4f3574e 4908@cindex colon-colon, context for variables/functions
c906108c
SS
4909@iftex
4910@c info cannot cope with a :: index entry, but why deprive hard copy readers?
41afff9a 4911@cindex @code{::}, context for variables/functions
c906108c 4912@end iftex
474c8240 4913@smallexample
c906108c
SS
4914@var{file}::@var{variable}
4915@var{function}::@var{variable}
474c8240 4916@end smallexample
c906108c
SS
4917
4918@noindent
4919Here @var{file} or @var{function} is the name of the context for the
4920static @var{variable}. In the case of file names, you can use quotes to
4921make sure @value{GDBN} parses the file name as a single word---for example,
4922to print a global value of @code{x} defined in @file{f2.c}:
4923
474c8240 4924@smallexample
c906108c 4925(@value{GDBP}) p 'f2.c'::x
474c8240 4926@end smallexample
c906108c 4927
b37052ae 4928@cindex C@t{++} scope resolution
c906108c 4929This use of @samp{::} is very rarely in conflict with the very similar
b37052ae 4930use of the same notation in C@t{++}. @value{GDBN} also supports use of the C@t{++}
c906108c
SS
4931scope resolution operator in @value{GDBN} expressions.
4932@c FIXME: Um, so what happens in one of those rare cases where it's in
4933@c conflict?? --mew
c906108c
SS
4934
4935@cindex wrong values
4936@cindex variable values, wrong
15387254
EZ
4937@cindex function entry/exit, wrong values of variables
4938@cindex optimized code, wrong values of variables
c906108c
SS
4939@quotation
4940@emph{Warning:} Occasionally, a local variable may appear to have the
4941wrong value at certain points in a function---just after entry to a new
4942scope, and just before exit.
4943@end quotation
4944You may see this problem when you are stepping by machine instructions.
4945This is because, on most machines, it takes more than one instruction to
4946set up a stack frame (including local variable definitions); if you are
4947stepping by machine instructions, variables may appear to have the wrong
4948values until the stack frame is completely built. On exit, it usually
4949also takes more than one machine instruction to destroy a stack frame;
4950after you begin stepping through that group of instructions, local
4951variable definitions may be gone.
4952
4953This may also happen when the compiler does significant optimizations.
4954To be sure of always seeing accurate values, turn off all optimization
4955when compiling.
4956
d4f3574e
SS
4957@cindex ``No symbol "foo" in current context''
4958Another possible effect of compiler optimizations is to optimize
4959unused variables out of existence, or assign variables to registers (as
4960opposed to memory addresses). Depending on the support for such cases
4961offered by the debug info format used by the compiler, @value{GDBN}
4962might not be able to display values for such local variables. If that
4963happens, @value{GDBN} will print a message like this:
4964
474c8240 4965@smallexample
d4f3574e 4966No symbol "foo" in current context.
474c8240 4967@end smallexample
d4f3574e
SS
4968
4969To solve such problems, either recompile without optimizations, or use a
4970different debug info format, if the compiler supports several such
15387254 4971formats. For example, @value{NGCC}, the @sc{gnu} C/C@t{++} compiler,
0179ffac
DC
4972usually supports the @option{-gstabs+} option. @option{-gstabs+}
4973produces debug info in a format that is superior to formats such as
4974COFF. You may be able to use DWARF 2 (@option{-gdwarf-2}), which is also
4975an effective form for debug info. @xref{Debugging Options,,Options
4976for Debugging Your Program or @sc{gnu} CC, gcc.info, Using @sc{gnu} CC}.
15387254
EZ
4977@xref{C, , Debugging C++}, for more info about debug info formats
4978that are best suited to C@t{++} programs.
d4f3574e 4979
6d2ebf8b 4980@node Arrays
c906108c
SS
4981@section Artificial arrays
4982
4983@cindex artificial array
15387254 4984@cindex arrays
41afff9a 4985@kindex @@@r{, referencing memory as an array}
c906108c
SS
4986It is often useful to print out several successive objects of the
4987same type in memory; a section of an array, or an array of
4988dynamically determined size for which only a pointer exists in the
4989program.
4990
4991You can do this by referring to a contiguous span of memory as an
4992@dfn{artificial array}, using the binary operator @samp{@@}. The left
4993operand of @samp{@@} should be the first element of the desired array
4994and be an individual object. The right operand should be the desired length
4995of the array. The result is an array value whose elements are all of
4996the type of the left argument. The first element is actually the left
4997argument; the second element comes from bytes of memory immediately
4998following those that hold the first element, and so on. Here is an
4999example. If a program says
5000
474c8240 5001@smallexample
c906108c 5002int *array = (int *) malloc (len * sizeof (int));
474c8240 5003@end smallexample
c906108c
SS
5004
5005@noindent
5006you can print the contents of @code{array} with
5007
474c8240 5008@smallexample
c906108c 5009p *array@@len
474c8240 5010@end smallexample
c906108c
SS
5011
5012The left operand of @samp{@@} must reside in memory. Array values made
5013with @samp{@@} in this way behave just like other arrays in terms of
5014subscripting, and are coerced to pointers when used in expressions.
5015Artificial arrays most often appear in expressions via the value history
5016(@pxref{Value History, ,Value history}), after printing one out.
5017
5018Another way to create an artificial array is to use a cast.
5019This re-interprets a value as if it were an array.
5020The value need not be in memory:
474c8240 5021@smallexample
c906108c
SS
5022(@value{GDBP}) p/x (short[2])0x12345678
5023$1 = @{0x1234, 0x5678@}
474c8240 5024@end smallexample
c906108c
SS
5025
5026As a convenience, if you leave the array length out (as in
c3f6f71d 5027@samp{(@var{type}[])@var{value}}) @value{GDBN} calculates the size to fill
c906108c 5028the value (as @samp{sizeof(@var{value})/sizeof(@var{type})}:
474c8240 5029@smallexample
c906108c
SS
5030(@value{GDBP}) p/x (short[])0x12345678
5031$2 = @{0x1234, 0x5678@}
474c8240 5032@end smallexample
c906108c
SS
5033
5034Sometimes the artificial array mechanism is not quite enough; in
5035moderately complex data structures, the elements of interest may not
5036actually be adjacent---for example, if you are interested in the values
5037of pointers in an array. One useful work-around in this situation is
5038to use a convenience variable (@pxref{Convenience Vars, ,Convenience
5039variables}) as a counter in an expression that prints the first
5040interesting value, and then repeat that expression via @key{RET}. For
5041instance, suppose you have an array @code{dtab} of pointers to
5042structures, and you are interested in the values of a field @code{fv}
5043in each structure. Here is an example of what you might type:
5044
474c8240 5045@smallexample
c906108c
SS
5046set $i = 0
5047p dtab[$i++]->fv
5048@key{RET}
5049@key{RET}
5050@dots{}
474c8240 5051@end smallexample
c906108c 5052
6d2ebf8b 5053@node Output Formats
c906108c
SS
5054@section Output formats
5055
5056@cindex formatted output
5057@cindex output formats
5058By default, @value{GDBN} prints a value according to its data type. Sometimes
5059this is not what you want. For example, you might want to print a number
5060in hex, or a pointer in decimal. Or you might want to view data in memory
5061at a certain address as a character string or as an instruction. To do
5062these things, specify an @dfn{output format} when you print a value.
5063
5064The simplest use of output formats is to say how to print a value
5065already computed. This is done by starting the arguments of the
5066@code{print} command with a slash and a format letter. The format
5067letters supported are:
5068
5069@table @code
5070@item x
5071Regard the bits of the value as an integer, and print the integer in
5072hexadecimal.
5073
5074@item d
5075Print as integer in signed decimal.
5076
5077@item u
5078Print as integer in unsigned decimal.
5079
5080@item o
5081Print as integer in octal.
5082
5083@item t
5084Print as integer in binary. The letter @samp{t} stands for ``two''.
5085@footnote{@samp{b} cannot be used because these format letters are also
5086used with the @code{x} command, where @samp{b} stands for ``byte'';
d4f3574e 5087see @ref{Memory,,Examining memory}.}
c906108c
SS
5088
5089@item a
5090@cindex unknown address, locating
3d67e040 5091@cindex locate address
c906108c
SS
5092Print as an address, both absolute in hexadecimal and as an offset from
5093the nearest preceding symbol. You can use this format used to discover
5094where (in what function) an unknown address is located:
5095
474c8240 5096@smallexample
c906108c
SS
5097(@value{GDBP}) p/a 0x54320
5098$3 = 0x54320 <_initialize_vx+396>
474c8240 5099@end smallexample
c906108c 5100
3d67e040
EZ
5101@noindent
5102The command @code{info symbol 0x54320} yields similar results.
5103@xref{Symbols, info symbol}.
5104
c906108c
SS
5105@item c
5106Regard as an integer and print it as a character constant.
5107
5108@item f
5109Regard the bits of the value as a floating point number and print
5110using typical floating point syntax.
5111@end table
5112
5113For example, to print the program counter in hex (@pxref{Registers}), type
5114
474c8240 5115@smallexample
c906108c 5116p/x $pc
474c8240 5117@end smallexample
c906108c
SS
5118
5119@noindent
5120Note that no space is required before the slash; this is because command
5121names in @value{GDBN} cannot contain a slash.
5122
5123To reprint the last value in the value history with a different format,
5124you can use the @code{print} command with just a format and no
5125expression. For example, @samp{p/x} reprints the last value in hex.
5126
6d2ebf8b 5127@node Memory
c906108c
SS
5128@section Examining memory
5129
5130You can use the command @code{x} (for ``examine'') to examine memory in
5131any of several formats, independently of your program's data types.
5132
5133@cindex examining memory
5134@table @code
41afff9a 5135@kindex x @r{(examine memory)}
c906108c
SS
5136@item x/@var{nfu} @var{addr}
5137@itemx x @var{addr}
5138@itemx x
5139Use the @code{x} command to examine memory.
5140@end table
5141
5142@var{n}, @var{f}, and @var{u} are all optional parameters that specify how
5143much memory to display and how to format it; @var{addr} is an
5144expression giving the address where you want to start displaying memory.
5145If you use defaults for @var{nfu}, you need not type the slash @samp{/}.
5146Several commands set convenient defaults for @var{addr}.
5147
5148@table @r
5149@item @var{n}, the repeat count
5150The repeat count is a decimal integer; the default is 1. It specifies
5151how much memory (counting by units @var{u}) to display.
5152@c This really is **decimal**; unaffected by 'set radix' as of GDB
5153@c 4.1.2.
5154
5155@item @var{f}, the display format
5156The display format is one of the formats used by @code{print},
5157@samp{s} (null-terminated string), or @samp{i} (machine instruction).
5158The default is @samp{x} (hexadecimal) initially.
5159The default changes each time you use either @code{x} or @code{print}.
5160
5161@item @var{u}, the unit size
5162The unit size is any of
5163
5164@table @code
5165@item b
5166Bytes.
5167@item h
5168Halfwords (two bytes).
5169@item w
5170Words (four bytes). This is the initial default.
5171@item g
5172Giant words (eight bytes).
5173@end table
5174
5175Each time you specify a unit size with @code{x}, that size becomes the
5176default unit the next time you use @code{x}. (For the @samp{s} and
5177@samp{i} formats, the unit size is ignored and is normally not written.)
5178
5179@item @var{addr}, starting display address
5180@var{addr} is the address where you want @value{GDBN} to begin displaying
5181memory. The expression need not have a pointer value (though it may);
5182it is always interpreted as an integer address of a byte of memory.
5183@xref{Expressions, ,Expressions}, for more information on expressions. The default for
5184@var{addr} is usually just after the last address examined---but several
5185other commands also set the default address: @code{info breakpoints} (to
5186the address of the last breakpoint listed), @code{info line} (to the
5187starting address of a line), and @code{print} (if you use it to display
5188a value from memory).
5189@end table
5190
5191For example, @samp{x/3uh 0x54320} is a request to display three halfwords
5192(@code{h}) of memory, formatted as unsigned decimal integers (@samp{u}),
5193starting at address @code{0x54320}. @samp{x/4xw $sp} prints the four
5194words (@samp{w}) of memory above the stack pointer (here, @samp{$sp};
d4f3574e 5195@pxref{Registers, ,Registers}) in hexadecimal (@samp{x}).
c906108c
SS
5196
5197Since the letters indicating unit sizes are all distinct from the
5198letters specifying output formats, you do not have to remember whether
5199unit size or format comes first; either order works. The output
5200specifications @samp{4xw} and @samp{4wx} mean exactly the same thing.
5201(However, the count @var{n} must come first; @samp{wx4} does not work.)
5202
5203Even though the unit size @var{u} is ignored for the formats @samp{s}
5204and @samp{i}, you might still want to use a count @var{n}; for example,
5205@samp{3i} specifies that you want to see three machine instructions,
5206including any operands. The command @code{disassemble} gives an
d4f3574e 5207alternative way of inspecting machine instructions; see @ref{Machine
c906108c
SS
5208Code,,Source and machine code}.
5209
5210All the defaults for the arguments to @code{x} are designed to make it
5211easy to continue scanning memory with minimal specifications each time
5212you use @code{x}. For example, after you have inspected three machine
5213instructions with @samp{x/3i @var{addr}}, you can inspect the next seven
5214with just @samp{x/7}. If you use @key{RET} to repeat the @code{x} command,
5215the repeat count @var{n} is used again; the other arguments default as
5216for successive uses of @code{x}.
5217
5218@cindex @code{$_}, @code{$__}, and value history
5219The addresses and contents printed by the @code{x} command are not saved
5220in the value history because there is often too much of them and they
5221would get in the way. Instead, @value{GDBN} makes these values available for
5222subsequent use in expressions as values of the convenience variables
5223@code{$_} and @code{$__}. After an @code{x} command, the last address
5224examined is available for use in expressions in the convenience variable
5225@code{$_}. The contents of that address, as examined, are available in
5226the convenience variable @code{$__}.
5227
5228If the @code{x} command has a repeat count, the address and contents saved
5229are from the last memory unit printed; this is not the same as the last
5230address printed if several units were printed on the last line of output.
5231
6d2ebf8b 5232@node Auto Display
c906108c
SS
5233@section Automatic display
5234@cindex automatic display
5235@cindex display of expressions
5236
5237If you find that you want to print the value of an expression frequently
5238(to see how it changes), you might want to add it to the @dfn{automatic
5239display list} so that @value{GDBN} prints its value each time your program stops.
5240Each expression added to the list is given a number to identify it;
5241to remove an expression from the list, you specify that number.
5242The automatic display looks like this:
5243
474c8240 5244@smallexample
c906108c
SS
52452: foo = 38
52463: bar[5] = (struct hack *) 0x3804
474c8240 5247@end smallexample
c906108c
SS
5248
5249@noindent
5250This display shows item numbers, expressions and their current values. As with
5251displays you request manually using @code{x} or @code{print}, you can
5252specify the output format you prefer; in fact, @code{display} decides
5253whether to use @code{print} or @code{x} depending on how elaborate your
5254format specification is---it uses @code{x} if you specify a unit size,
5255or one of the two formats (@samp{i} and @samp{s}) that are only
5256supported by @code{x}; otherwise it uses @code{print}.
5257
5258@table @code
5259@kindex display
d4f3574e
SS
5260@item display @var{expr}
5261Add the expression @var{expr} to the list of expressions to display
c906108c
SS
5262each time your program stops. @xref{Expressions, ,Expressions}.
5263
5264@code{display} does not repeat if you press @key{RET} again after using it.
5265
d4f3574e 5266@item display/@var{fmt} @var{expr}
c906108c 5267For @var{fmt} specifying only a display format and not a size or
d4f3574e 5268count, add the expression @var{expr} to the auto-display list but
c906108c
SS
5269arrange to display it each time in the specified format @var{fmt}.
5270@xref{Output Formats,,Output formats}.
5271
5272@item display/@var{fmt} @var{addr}
5273For @var{fmt} @samp{i} or @samp{s}, or including a unit-size or a
5274number of units, add the expression @var{addr} as a memory address to
5275be examined each time your program stops. Examining means in effect
5276doing @samp{x/@var{fmt} @var{addr}}. @xref{Memory, ,Examining memory}.
5277@end table
5278
5279For example, @samp{display/i $pc} can be helpful, to see the machine
5280instruction about to be executed each time execution stops (@samp{$pc}
d4f3574e 5281is a common name for the program counter; @pxref{Registers, ,Registers}).
c906108c
SS
5282
5283@table @code
5284@kindex delete display
5285@kindex undisplay
5286@item undisplay @var{dnums}@dots{}
5287@itemx delete display @var{dnums}@dots{}
5288Remove item numbers @var{dnums} from the list of expressions to display.
5289
5290@code{undisplay} does not repeat if you press @key{RET} after using it.
5291(Otherwise you would just get the error @samp{No display number @dots{}}.)
5292
5293@kindex disable display
5294@item disable display @var{dnums}@dots{}
5295Disable the display of item numbers @var{dnums}. A disabled display
5296item is not printed automatically, but is not forgotten. It may be
5297enabled again later.
5298
5299@kindex enable display
5300@item enable display @var{dnums}@dots{}
5301Enable display of item numbers @var{dnums}. It becomes effective once
5302again in auto display of its expression, until you specify otherwise.
5303
5304@item display
5305Display the current values of the expressions on the list, just as is
5306done when your program stops.
5307
5308@kindex info display
5309@item info display
5310Print the list of expressions previously set up to display
5311automatically, each one with its item number, but without showing the
5312values. This includes disabled expressions, which are marked as such.
5313It also includes expressions which would not be displayed right now
5314because they refer to automatic variables not currently available.
5315@end table
5316
15387254 5317@cindex display disabled out of scope
c906108c
SS
5318If a display expression refers to local variables, then it does not make
5319sense outside the lexical context for which it was set up. Such an
5320expression is disabled when execution enters a context where one of its
5321variables is not defined. For example, if you give the command
5322@code{display last_char} while inside a function with an argument
5323@code{last_char}, @value{GDBN} displays this argument while your program
5324continues to stop inside that function. When it stops elsewhere---where
5325there is no variable @code{last_char}---the display is disabled
5326automatically. The next time your program stops where @code{last_char}
5327is meaningful, you can enable the display expression once again.
5328
6d2ebf8b 5329@node Print Settings
c906108c
SS
5330@section Print settings
5331
5332@cindex format options
5333@cindex print settings
5334@value{GDBN} provides the following ways to control how arrays, structures,
5335and symbols are printed.
5336
5337@noindent
5338These settings are useful for debugging programs in any language:
5339
5340@table @code
4644b6e3 5341@kindex set print
c906108c
SS
5342@item set print address
5343@itemx set print address on
4644b6e3 5344@cindex print/don't print memory addresses
c906108c
SS
5345@value{GDBN} prints memory addresses showing the location of stack
5346traces, structure values, pointer values, breakpoints, and so forth,
5347even when it also displays the contents of those addresses. The default
5348is @code{on}. For example, this is what a stack frame display looks like with
5349@code{set print address on}:
5350
5351@smallexample
5352@group
5353(@value{GDBP}) f
5354#0 set_quotes (lq=0x34c78 "<<", rq=0x34c88 ">>")
5355 at input.c:530
5356530 if (lquote != def_lquote)
5357@end group
5358@end smallexample
5359
5360@item set print address off
5361Do not print addresses when displaying their contents. For example,
5362this is the same stack frame displayed with @code{set print address off}:
5363
5364@smallexample
5365@group
5366(@value{GDBP}) set print addr off
5367(@value{GDBP}) f
5368#0 set_quotes (lq="<<", rq=">>") at input.c:530
5369530 if (lquote != def_lquote)
5370@end group
5371@end smallexample
5372
5373You can use @samp{set print address off} to eliminate all machine
5374dependent displays from the @value{GDBN} interface. For example, with
5375@code{print address off}, you should get the same text for backtraces on
5376all machines---whether or not they involve pointer arguments.
5377
4644b6e3 5378@kindex show print
c906108c
SS
5379@item show print address
5380Show whether or not addresses are to be printed.
5381@end table
5382
5383When @value{GDBN} prints a symbolic address, it normally prints the
5384closest earlier symbol plus an offset. If that symbol does not uniquely
5385identify the address (for example, it is a name whose scope is a single
5386source file), you may need to clarify. One way to do this is with
5387@code{info line}, for example @samp{info line *0x4537}. Alternately,
5388you can set @value{GDBN} to print the source file and line number when
5389it prints a symbolic address:
5390
5391@table @code
c906108c 5392@item set print symbol-filename on
4644b6e3 5393@cindex closest symbol and offset for an address
c906108c
SS
5394Tell @value{GDBN} to print the source file name and line number of a
5395symbol in the symbolic form of an address.
5396
5397@item set print symbol-filename off
5398Do not print source file name and line number of a symbol. This is the
5399default.
5400
c906108c
SS
5401@item show print symbol-filename
5402Show whether or not @value{GDBN} will print the source file name and
5403line number of a symbol in the symbolic form of an address.
5404@end table
5405
5406Another situation where it is helpful to show symbol filenames and line
5407numbers is when disassembling code; @value{GDBN} shows you the line
5408number and source file that corresponds to each instruction.
5409
5410Also, you may wish to see the symbolic form only if the address being
5411printed is reasonably close to the closest earlier symbol:
5412
5413@table @code
c906108c 5414@item set print max-symbolic-offset @var{max-offset}
4644b6e3 5415@cindex maximum value for offset of closest symbol
c906108c
SS
5416Tell @value{GDBN} to only display the symbolic form of an address if the
5417offset between the closest earlier symbol and the address is less than
5d161b24 5418@var{max-offset}. The default is 0, which tells @value{GDBN}
c906108c
SS
5419to always print the symbolic form of an address if any symbol precedes it.
5420
c906108c
SS
5421@item show print max-symbolic-offset
5422Ask how large the maximum offset is that @value{GDBN} prints in a
5423symbolic address.
5424@end table
5425
5426@cindex wild pointer, interpreting
5427@cindex pointer, finding referent
5428If you have a pointer and you are not sure where it points, try
5429@samp{set print symbol-filename on}. Then you can determine the name
5430and source file location of the variable where it points, using
5431@samp{p/a @var{pointer}}. This interprets the address in symbolic form.
5432For example, here @value{GDBN} shows that a variable @code{ptt} points
5433at another variable @code{t}, defined in @file{hi2.c}:
5434
474c8240 5435@smallexample
c906108c
SS
5436(@value{GDBP}) set print symbol-filename on
5437(@value{GDBP}) p/a ptt
5438$4 = 0xe008 <t in hi2.c>
474c8240 5439@end smallexample
c906108c
SS
5440
5441@quotation
5442@emph{Warning:} For pointers that point to a local variable, @samp{p/a}
5443does not show the symbol name and filename of the referent, even with
5444the appropriate @code{set print} options turned on.
5445@end quotation
5446
5447Other settings control how different kinds of objects are printed:
5448
5449@table @code
c906108c
SS
5450@item set print array
5451@itemx set print array on
4644b6e3 5452@cindex pretty print arrays
c906108c
SS
5453Pretty print arrays. This format is more convenient to read,
5454but uses more space. The default is off.
5455
5456@item set print array off
5457Return to compressed format for arrays.
5458
c906108c
SS
5459@item show print array
5460Show whether compressed or pretty format is selected for displaying
5461arrays.
5462
c906108c 5463@item set print elements @var{number-of-elements}
4644b6e3 5464@cindex number of array elements to print
c906108c
SS
5465Set a limit on how many elements of an array @value{GDBN} will print.
5466If @value{GDBN} is printing a large array, it stops printing after it has
5467printed the number of elements set by the @code{set print elements} command.
5468This limit also applies to the display of strings.
d4f3574e 5469When @value{GDBN} starts, this limit is set to 200.
c906108c
SS
5470Setting @var{number-of-elements} to zero means that the printing is unlimited.
5471
c906108c
SS
5472@item show print elements
5473Display the number of elements of a large array that @value{GDBN} will print.
5474If the number is 0, then the printing is unlimited.
5475
c906108c 5476@item set print null-stop
4644b6e3 5477@cindex @sc{null} elements in arrays
c906108c 5478Cause @value{GDBN} to stop printing the characters of an array when the first
d4f3574e 5479@sc{null} is encountered. This is useful when large arrays actually
c906108c 5480contain only short strings.
d4f3574e 5481The default is off.
c906108c 5482
c906108c 5483@item set print pretty on
5d161b24 5484Cause @value{GDBN} to print structures in an indented format with one member
c906108c
SS
5485per line, like this:
5486
5487@smallexample
5488@group
5489$1 = @{
5490 next = 0x0,
5491 flags = @{
5492 sweet = 1,
5493 sour = 1
5494 @},
5495 meat = 0x54 "Pork"
5496@}
5497@end group
5498@end smallexample
5499
5500@item set print pretty off
5501Cause @value{GDBN} to print structures in a compact format, like this:
5502
5503@smallexample
5504@group
5505$1 = @{next = 0x0, flags = @{sweet = 1, sour = 1@}, \
5506meat = 0x54 "Pork"@}
5507@end group
5508@end smallexample
5509
5510@noindent
5511This is the default format.
5512
c906108c
SS
5513@item show print pretty
5514Show which format @value{GDBN} is using to print structures.
5515
c906108c 5516@item set print sevenbit-strings on
4644b6e3
EZ
5517@cindex eight-bit characters in strings
5518@cindex octal escapes in strings
c906108c
SS
5519Print using only seven-bit characters; if this option is set,
5520@value{GDBN} displays any eight-bit characters (in strings or
5521character values) using the notation @code{\}@var{nnn}. This setting is
5522best if you are working in English (@sc{ascii}) and you use the
5523high-order bit of characters as a marker or ``meta'' bit.
5524
5525@item set print sevenbit-strings off
5526Print full eight-bit characters. This allows the use of more
5527international character sets, and is the default.
5528
c906108c
SS
5529@item show print sevenbit-strings
5530Show whether or not @value{GDBN} is printing only seven-bit characters.
5531
c906108c 5532@item set print union on
4644b6e3 5533@cindex unions in structures, printing
5d161b24 5534Tell @value{GDBN} to print unions which are contained in structures. This
c906108c
SS
5535is the default setting.
5536
5537@item set print union off
5538Tell @value{GDBN} not to print unions which are contained in structures.
5539
c906108c
SS
5540@item show print union
5541Ask @value{GDBN} whether or not it will print unions which are contained in
5542structures.
5543
5544For example, given the declarations
5545
5546@smallexample
5547typedef enum @{Tree, Bug@} Species;
5548typedef enum @{Big_tree, Acorn, Seedling@} Tree_forms;
5d161b24 5549typedef enum @{Caterpillar, Cocoon, Butterfly@}
c906108c
SS
5550 Bug_forms;
5551
5552struct thing @{
5553 Species it;
5554 union @{
5555 Tree_forms tree;
5556 Bug_forms bug;
5557 @} form;
5558@};
5559
5560struct thing foo = @{Tree, @{Acorn@}@};
5561@end smallexample
5562
5563@noindent
5564with @code{set print union on} in effect @samp{p foo} would print
5565
5566@smallexample
5567$1 = @{it = Tree, form = @{tree = Acorn, bug = Cocoon@}@}
5568@end smallexample
5569
5570@noindent
5571and with @code{set print union off} in effect it would print
5572
5573@smallexample
5574$1 = @{it = Tree, form = @{...@}@}
5575@end smallexample
5576@end table
5577
c906108c
SS
5578@need 1000
5579@noindent
b37052ae 5580These settings are of interest when debugging C@t{++} programs:
c906108c
SS
5581
5582@table @code
4644b6e3 5583@cindex demangling C@t{++} names
c906108c
SS
5584@item set print demangle
5585@itemx set print demangle on
b37052ae 5586Print C@t{++} names in their source form rather than in the encoded
c906108c 5587(``mangled'') form passed to the assembler and linker for type-safe
d4f3574e 5588linkage. The default is on.
c906108c 5589
c906108c 5590@item show print demangle
b37052ae 5591Show whether C@t{++} names are printed in mangled or demangled form.
c906108c 5592
c906108c
SS
5593@item set print asm-demangle
5594@itemx set print asm-demangle on
b37052ae 5595Print C@t{++} names in their source form rather than their mangled form, even
c906108c
SS
5596in assembler code printouts such as instruction disassemblies.
5597The default is off.
5598
c906108c 5599@item show print asm-demangle
b37052ae 5600Show whether C@t{++} names in assembly listings are printed in mangled
c906108c
SS
5601or demangled form.
5602
b37052ae
EZ
5603@cindex C@t{++} symbol decoding style
5604@cindex symbol decoding style, C@t{++}
c906108c
SS
5605@item set demangle-style @var{style}
5606Choose among several encoding schemes used by different compilers to
b37052ae 5607represent C@t{++} names. The choices for @var{style} are currently:
c906108c
SS
5608
5609@table @code
5610@item auto
5611Allow @value{GDBN} to choose a decoding style by inspecting your program.
5612
5613@item gnu
b37052ae 5614Decode based on the @sc{gnu} C@t{++} compiler (@code{g++}) encoding algorithm.
c906108c 5615This is the default.
c906108c
SS
5616
5617@item hp
b37052ae 5618Decode based on the HP ANSI C@t{++} (@code{aCC}) encoding algorithm.
c906108c
SS
5619
5620@item lucid
b37052ae 5621Decode based on the Lucid C@t{++} compiler (@code{lcc}) encoding algorithm.
c906108c
SS
5622
5623@item arm
b37052ae 5624Decode using the algorithm in the @cite{C@t{++} Annotated Reference Manual}.
c906108c
SS
5625@strong{Warning:} this setting alone is not sufficient to allow
5626debugging @code{cfront}-generated executables. @value{GDBN} would
5627require further enhancement to permit that.
5628
5629@end table
5630If you omit @var{style}, you will see a list of possible formats.
5631
c906108c 5632@item show demangle-style
b37052ae 5633Display the encoding style currently in use for decoding C@t{++} symbols.
c906108c 5634
c906108c
SS
5635@item set print object
5636@itemx set print object on
4644b6e3 5637@cindex derived type of an object, printing
c906108c
SS
5638When displaying a pointer to an object, identify the @emph{actual}
5639(derived) type of the object rather than the @emph{declared} type, using
5640the virtual function table.
5641
5642@item set print object off
5643Display only the declared type of objects, without reference to the
5644virtual function table. This is the default setting.
5645
c906108c
SS
5646@item show print object
5647Show whether actual, or declared, object types are displayed.
5648
c906108c
SS
5649@item set print static-members
5650@itemx set print static-members on
4644b6e3 5651@cindex static members of C@t{++} objects
b37052ae 5652Print static members when displaying a C@t{++} object. The default is on.
c906108c
SS
5653
5654@item set print static-members off
b37052ae 5655Do not print static members when displaying a C@t{++} object.
c906108c 5656
c906108c 5657@item show print static-members
b37052ae 5658Show whether C@t{++} static members are printed, or not.
c906108c
SS
5659
5660@c These don't work with HP ANSI C++ yet.
c906108c
SS
5661@item set print vtbl
5662@itemx set print vtbl on
4644b6e3 5663@cindex pretty print C@t{++} virtual function tables
b37052ae 5664Pretty print C@t{++} virtual function tables. The default is off.
c906108c 5665(The @code{vtbl} commands do not work on programs compiled with the HP
b37052ae 5666ANSI C@t{++} compiler (@code{aCC}).)
c906108c
SS
5667
5668@item set print vtbl off
b37052ae 5669Do not pretty print C@t{++} virtual function tables.
c906108c 5670
c906108c 5671@item show print vtbl
b37052ae 5672Show whether C@t{++} virtual function tables are pretty printed, or not.
c906108c 5673@end table
c906108c 5674
6d2ebf8b 5675@node Value History
c906108c
SS
5676@section Value history
5677
5678@cindex value history
5d161b24
DB
5679Values printed by the @code{print} command are saved in the @value{GDBN}
5680@dfn{value history}. This allows you to refer to them in other expressions.
5681Values are kept until the symbol table is re-read or discarded
5682(for example with the @code{file} or @code{symbol-file} commands).
5683When the symbol table changes, the value history is discarded,
5684since the values may contain pointers back to the types defined in the
c906108c
SS
5685symbol table.
5686
5687@cindex @code{$}
5688@cindex @code{$$}
5689@cindex history number
5690The values printed are given @dfn{history numbers} by which you can
5691refer to them. These are successive integers starting with one.
5692@code{print} shows you the history number assigned to a value by
5693printing @samp{$@var{num} = } before the value; here @var{num} is the
5694history number.
5695
5696To refer to any previous value, use @samp{$} followed by the value's
5697history number. The way @code{print} labels its output is designed to
5698remind you of this. Just @code{$} refers to the most recent value in
5699the history, and @code{$$} refers to the value before that.
5700@code{$$@var{n}} refers to the @var{n}th value from the end; @code{$$2}
5701is the value just prior to @code{$$}, @code{$$1} is equivalent to
5702@code{$$}, and @code{$$0} is equivalent to @code{$}.
5703
5704For example, suppose you have just printed a pointer to a structure and
5705want to see the contents of the structure. It suffices to type
5706
474c8240 5707@smallexample
c906108c 5708p *$
474c8240 5709@end smallexample
c906108c
SS
5710
5711If you have a chain of structures where the component @code{next} points
5712to the next one, you can print the contents of the next one with this:
5713
474c8240 5714@smallexample
c906108c 5715p *$.next
474c8240 5716@end smallexample
c906108c
SS
5717
5718@noindent
5719You can print successive links in the chain by repeating this
5720command---which you can do by just typing @key{RET}.
5721
5722Note that the history records values, not expressions. If the value of
5723@code{x} is 4 and you type these commands:
5724
474c8240 5725@smallexample
c906108c
SS
5726print x
5727set x=5
474c8240 5728@end smallexample
c906108c
SS
5729
5730@noindent
5731then the value recorded in the value history by the @code{print} command
5732remains 4 even though the value of @code{x} has changed.
5733
5734@table @code
5735@kindex show values
5736@item show values
5737Print the last ten values in the value history, with their item numbers.
5738This is like @samp{p@ $$9} repeated ten times, except that @code{show
5739values} does not change the history.
5740
5741@item show values @var{n}
5742Print ten history values centered on history item number @var{n}.
5743
5744@item show values +
5745Print ten history values just after the values last printed. If no more
5746values are available, @code{show values +} produces no display.
5747@end table
5748
5749Pressing @key{RET} to repeat @code{show values @var{n}} has exactly the
5750same effect as @samp{show values +}.
5751
6d2ebf8b 5752@node Convenience Vars
c906108c
SS
5753@section Convenience variables
5754
5755@cindex convenience variables
5756@value{GDBN} provides @dfn{convenience variables} that you can use within
5757@value{GDBN} to hold on to a value and refer to it later. These variables
5758exist entirely within @value{GDBN}; they are not part of your program, and
5759setting a convenience variable has no direct effect on further execution
5760of your program. That is why you can use them freely.
5761
5762Convenience variables are prefixed with @samp{$}. Any name preceded by
5763@samp{$} can be used for a convenience variable, unless it is one of
d4f3574e 5764the predefined machine-specific register names (@pxref{Registers, ,Registers}).
c906108c
SS
5765(Value history references, in contrast, are @emph{numbers} preceded
5766by @samp{$}. @xref{Value History, ,Value history}.)
5767
5768You can save a value in a convenience variable with an assignment
5769expression, just as you would set a variable in your program.
5770For example:
5771
474c8240 5772@smallexample
c906108c 5773set $foo = *object_ptr
474c8240 5774@end smallexample
c906108c
SS
5775
5776@noindent
5777would save in @code{$foo} the value contained in the object pointed to by
5778@code{object_ptr}.
5779
5780Using a convenience variable for the first time creates it, but its
5781value is @code{void} until you assign a new value. You can alter the
5782value with another assignment at any time.
5783
5784Convenience variables have no fixed types. You can assign a convenience
5785variable any type of value, including structures and arrays, even if
5786that variable already has a value of a different type. The convenience
5787variable, when used as an expression, has the type of its current value.
5788
5789@table @code
5790@kindex show convenience
5791@item show convenience
5792Print a list of convenience variables used so far, and their values.
d4f3574e 5793Abbreviated @code{show conv}.
c906108c
SS
5794@end table
5795
5796One of the ways to use a convenience variable is as a counter to be
5797incremented or a pointer to be advanced. For example, to print
5798a field from successive elements of an array of structures:
5799
474c8240 5800@smallexample
c906108c
SS
5801set $i = 0
5802print bar[$i++]->contents
474c8240 5803@end smallexample
c906108c 5804
d4f3574e
SS
5805@noindent
5806Repeat that command by typing @key{RET}.
c906108c
SS
5807
5808Some convenience variables are created automatically by @value{GDBN} and given
5809values likely to be useful.
5810
5811@table @code
41afff9a 5812@vindex $_@r{, convenience variable}
c906108c
SS
5813@item $_
5814The variable @code{$_} is automatically set by the @code{x} command to
5815the last address examined (@pxref{Memory, ,Examining memory}). Other
5816commands which provide a default address for @code{x} to examine also
5817set @code{$_} to that address; these commands include @code{info line}
5818and @code{info breakpoint}. The type of @code{$_} is @code{void *}
5819except when set by the @code{x} command, in which case it is a pointer
5820to the type of @code{$__}.
5821
41afff9a 5822@vindex $__@r{, convenience variable}
c906108c
SS
5823@item $__
5824The variable @code{$__} is automatically set by the @code{x} command
5825to the value found in the last address examined. Its type is chosen
5826to match the format in which the data was printed.
5827
5828@item $_exitcode
41afff9a 5829@vindex $_exitcode@r{, convenience variable}
c906108c
SS
5830The variable @code{$_exitcode} is automatically set to the exit code when
5831the program being debugged terminates.
5832@end table
5833
53a5351d
JM
5834On HP-UX systems, if you refer to a function or variable name that
5835begins with a dollar sign, @value{GDBN} searches for a user or system
5836name first, before it searches for a convenience variable.
c906108c 5837
6d2ebf8b 5838@node Registers
c906108c
SS
5839@section Registers
5840
5841@cindex registers
5842You can refer to machine register contents, in expressions, as variables
5843with names starting with @samp{$}. The names of registers are different
5844for each machine; use @code{info registers} to see the names used on
5845your machine.
5846
5847@table @code
5848@kindex info registers
5849@item info registers
5850Print the names and values of all registers except floating-point
c85508ee 5851and vector registers (in the selected stack frame).
c906108c
SS
5852
5853@kindex info all-registers
5854@cindex floating point registers
5855@item info all-registers
5856Print the names and values of all registers, including floating-point
c85508ee 5857and vector registers (in the selected stack frame).
c906108c
SS
5858
5859@item info registers @var{regname} @dots{}
5860Print the @dfn{relativized} value of each specified register @var{regname}.
5d161b24
DB
5861As discussed in detail below, register values are normally relative to
5862the selected stack frame. @var{regname} may be any register name valid on
c906108c
SS
5863the machine you are using, with or without the initial @samp{$}.
5864@end table
5865
5866@value{GDBN} has four ``standard'' register names that are available (in
5867expressions) on most machines---whenever they do not conflict with an
5868architecture's canonical mnemonics for registers. The register names
5869@code{$pc} and @code{$sp} are used for the program counter register and
5870the stack pointer. @code{$fp} is used for a register that contains a
5871pointer to the current stack frame, and @code{$ps} is used for a
5872register that contains the processor status. For example,
5873you could print the program counter in hex with
5874
474c8240 5875@smallexample
c906108c 5876p/x $pc
474c8240 5877@end smallexample
c906108c
SS
5878
5879@noindent
5880or print the instruction to be executed next with
5881
474c8240 5882@smallexample
c906108c 5883x/i $pc
474c8240 5884@end smallexample
c906108c
SS
5885
5886@noindent
5887or add four to the stack pointer@footnote{This is a way of removing
5888one word from the stack, on machines where stacks grow downward in
5889memory (most machines, nowadays). This assumes that the innermost
5890stack frame is selected; setting @code{$sp} is not allowed when other
5891stack frames are selected. To pop entire frames off the stack,
5892regardless of machine architecture, use @code{return};
d4f3574e 5893see @ref{Returning, ,Returning from a function}.} with
c906108c 5894
474c8240 5895@smallexample
c906108c 5896set $sp += 4
474c8240 5897@end smallexample
c906108c
SS
5898
5899Whenever possible, these four standard register names are available on
5900your machine even though the machine has different canonical mnemonics,
5901so long as there is no conflict. The @code{info registers} command
5902shows the canonical names. For example, on the SPARC, @code{info
5903registers} displays the processor status register as @code{$psr} but you
d4f3574e
SS
5904can also refer to it as @code{$ps}; and on x86-based machines @code{$ps}
5905is an alias for the @sc{eflags} register.
c906108c
SS
5906
5907@value{GDBN} always considers the contents of an ordinary register as an
5908integer when the register is examined in this way. Some machines have
5909special registers which can hold nothing but floating point; these
5910registers are considered to have floating point values. There is no way
5911to refer to the contents of an ordinary register as floating point value
5912(although you can @emph{print} it as a floating point value with
5913@samp{print/f $@var{regname}}).
5914
5915Some registers have distinct ``raw'' and ``virtual'' data formats. This
5916means that the data format in which the register contents are saved by
5917the operating system is not the same one that your program normally
5918sees. For example, the registers of the 68881 floating point
5919coprocessor are always saved in ``extended'' (raw) format, but all C
5920programs expect to work with ``double'' (virtual) format. In such
5d161b24 5921cases, @value{GDBN} normally works with the virtual format only (the format
c906108c
SS
5922that makes sense for your program), but the @code{info registers} command
5923prints the data in both formats.
5924
5925Normally, register values are relative to the selected stack frame
5926(@pxref{Selection, ,Selecting a frame}). This means that you get the
5927value that the register would contain if all stack frames farther in
5928were exited and their saved registers restored. In order to see the
5929true contents of hardware registers, you must select the innermost
5930frame (with @samp{frame 0}).
5931
5932However, @value{GDBN} must deduce where registers are saved, from the machine
5933code generated by your compiler. If some registers are not saved, or if
5934@value{GDBN} is unable to locate the saved registers, the selected stack
5935frame makes no difference.
5936
6d2ebf8b 5937@node Floating Point Hardware
c906108c
SS
5938@section Floating point hardware
5939@cindex floating point
5940
5941Depending on the configuration, @value{GDBN} may be able to give
5942you more information about the status of the floating point hardware.
5943
5944@table @code
5945@kindex info float
5946@item info float
5947Display hardware-dependent information about the floating
5948point unit. The exact contents and layout vary depending on the
5949floating point chip. Currently, @samp{info float} is supported on
5950the ARM and x86 machines.
5951@end table
c906108c 5952
e76f1f2e
AC
5953@node Vector Unit
5954@section Vector Unit
5955@cindex vector unit
5956
5957Depending on the configuration, @value{GDBN} may be able to give you
5958more information about the status of the vector unit.
5959
5960@table @code
5961@kindex info vector
5962@item info vector
5963Display information about the vector unit. The exact contents and
5964layout vary depending on the hardware.
5965@end table
5966
b383017d
RM
5967@node Auxiliary Vector
5968@section Operating system auxiliary vector
5969@cindex auxiliary vector
5970@cindex vector, auxiliary
5971
5972Some operating systems supply an @dfn{auxiliary vector} to programs at
5973startup. This is akin to the arguments and environment that you
5974specify for a program, but contains a system-dependent variety of
5975binary values that tell system libraries important details about the
5976hardware, operating system, and process. Each value's purpose is
5977identified by an integer tag; the meanings are well-known but system-specific.
5978Depending on the configuration and operating system facilities,
5979@value{GDBN} may be able to show you this information.
5980
5981@table @code
5982@kindex info auxv
5983@item info auxv
5984Display the auxiliary vector of the inferior, which can be either a
e4937fc1 5985live process or a core dump file. @value{GDBN} prints each tag value
b383017d
RM
5986numerically, and also shows names and text descriptions for recognized
5987tags. Some values in the vector are numbers, some bit masks, and some
e4937fc1 5988pointers to strings or other data. @value{GDBN} displays each value in the
b383017d
RM
5989most appropriate form for a recognized tag, and in hexadecimal for
5990an unrecognized tag.
5991@end table
5992
29e57380 5993@node Memory Region Attributes
b383017d 5994@section Memory region attributes
29e57380
C
5995@cindex memory region attributes
5996
b383017d
RM
5997@dfn{Memory region attributes} allow you to describe special handling
5998required by regions of your target's memory. @value{GDBN} uses attributes
29e57380
C
5999to determine whether to allow certain types of memory accesses; whether to
6000use specific width accesses; and whether to cache target memory.
6001
6002Defined memory regions can be individually enabled and disabled. When a
6003memory region is disabled, @value{GDBN} uses the default attributes when
6004accessing memory in that region. Similarly, if no memory regions have
6005been defined, @value{GDBN} uses the default attributes when accessing
6006all memory.
6007
b383017d 6008When a memory region is defined, it is given a number to identify it;
29e57380
C
6009to enable, disable, or remove a memory region, you specify that number.
6010
6011@table @code
6012@kindex mem
bfac230e
DH
6013@item mem @var{lower} @var{upper} @var{attributes}@dots{}
6014Define memory region bounded by @var{lower} and @var{upper} with
6015attributes @var{attributes}@dots{}. Note that @var{upper} == 0 is a
6016special case: it is treated as the the target's maximum memory address.
6017(0xffff on 16 bit targets, 0xffffffff on 32 bit targets, etc.)
29e57380
C
6018
6019@kindex delete mem
6020@item delete mem @var{nums}@dots{}
59649f2e 6021Remove memory regions @var{nums}@dots{}.
29e57380
C
6022
6023@kindex disable mem
6024@item disable mem @var{nums}@dots{}
59649f2e 6025Disable memory regions @var{nums}@dots{}.
b383017d 6026A disabled memory region is not forgotten.
29e57380
C
6027It may be enabled again later.
6028
6029@kindex enable mem
6030@item enable mem @var{nums}@dots{}
59649f2e 6031Enable memory regions @var{nums}@dots{}.
29e57380
C
6032
6033@kindex info mem
6034@item info mem
6035Print a table of all defined memory regions, with the following columns
6036for each region.
6037
6038@table @emph
6039@item Memory Region Number
6040@item Enabled or Disabled.
b383017d 6041Enabled memory regions are marked with @samp{y}.
29e57380
C
6042Disabled memory regions are marked with @samp{n}.
6043
6044@item Lo Address
6045The address defining the inclusive lower bound of the memory region.
6046
6047@item Hi Address
6048The address defining the exclusive upper bound of the memory region.
6049
6050@item Attributes
6051The list of attributes set for this memory region.
6052@end table
6053@end table
6054
6055
6056@subsection Attributes
6057
b383017d 6058@subsubsection Memory Access Mode
29e57380
C
6059The access mode attributes set whether @value{GDBN} may make read or
6060write accesses to a memory region.
6061
6062While these attributes prevent @value{GDBN} from performing invalid
6063memory accesses, they do nothing to prevent the target system, I/O DMA,
6064etc. from accessing memory.
6065
6066@table @code
6067@item ro
6068Memory is read only.
6069@item wo
6070Memory is write only.
6071@item rw
6ca652b0 6072Memory is read/write. This is the default.
29e57380
C
6073@end table
6074
6075@subsubsection Memory Access Size
6076The acccess size attributes tells @value{GDBN} to use specific sized
6077accesses in the memory region. Often memory mapped device registers
6078require specific sized accesses. If no access size attribute is
6079specified, @value{GDBN} may use accesses of any size.
6080
6081@table @code
6082@item 8
6083Use 8 bit memory accesses.
6084@item 16
6085Use 16 bit memory accesses.
6086@item 32
6087Use 32 bit memory accesses.
6088@item 64
6089Use 64 bit memory accesses.
6090@end table
6091
6092@c @subsubsection Hardware/Software Breakpoints
6093@c The hardware/software breakpoint attributes set whether @value{GDBN}
6094@c will use hardware or software breakpoints for the internal breakpoints
6095@c used by the step, next, finish, until, etc. commands.
6096@c
6097@c @table @code
6098@c @item hwbreak
b383017d 6099@c Always use hardware breakpoints
29e57380
C
6100@c @item swbreak (default)
6101@c @end table
6102
6103@subsubsection Data Cache
6104The data cache attributes set whether @value{GDBN} will cache target
6105memory. While this generally improves performance by reducing debug
6106protocol overhead, it can lead to incorrect results because @value{GDBN}
6107does not know about volatile variables or memory mapped device
6108registers.
6109
6110@table @code
6111@item cache
b383017d 6112Enable @value{GDBN} to cache target memory.
6ca652b0
EZ
6113@item nocache
6114Disable @value{GDBN} from caching target memory. This is the default.
29e57380
C
6115@end table
6116
6117@c @subsubsection Memory Write Verification
b383017d 6118@c The memory write verification attributes set whether @value{GDBN}
29e57380
C
6119@c will re-reads data after each write to verify the write was successful.
6120@c
6121@c @table @code
6122@c @item verify
6123@c @item noverify (default)
6124@c @end table
6125
16d9dec6
MS
6126@node Dump/Restore Files
6127@section Copy between memory and a file
6128@cindex dump/restore files
6129@cindex append data to a file
6130@cindex dump data to a file
6131@cindex restore data from a file
16d9dec6 6132
df5215a6
JB
6133You can use the commands @code{dump}, @code{append}, and
6134@code{restore} to copy data between target memory and a file. The
6135@code{dump} and @code{append} commands write data to a file, and the
6136@code{restore} command reads data from a file back into the inferior's
6137memory. Files may be in binary, Motorola S-record, Intel hex, or
6138Tektronix Hex format; however, @value{GDBN} can only append to binary
6139files.
6140
6141@table @code
6142
6143@kindex dump
6144@item dump @r{[}@var{format}@r{]} memory @var{filename} @var{start_addr} @var{end_addr}
6145@itemx dump @r{[}@var{format}@r{]} value @var{filename} @var{expr}
6146Dump the contents of memory from @var{start_addr} to @var{end_addr},
6147or the value of @var{expr}, to @var{filename} in the given format.
16d9dec6 6148
df5215a6 6149The @var{format} parameter may be any one of:
16d9dec6 6150@table @code
df5215a6
JB
6151@item binary
6152Raw binary form.
6153@item ihex
6154Intel hex format.
6155@item srec
6156Motorola S-record format.
6157@item tekhex
6158Tektronix Hex format.
6159@end table
6160
6161@value{GDBN} uses the same definitions of these formats as the
6162@sc{gnu} binary utilities, like @samp{objdump} and @samp{objcopy}. If
6163@var{format} is omitted, @value{GDBN} dumps the data in raw binary
6164form.
6165
6166@kindex append
6167@item append @r{[}binary@r{]} memory @var{filename} @var{start_addr} @var{end_addr}
6168@itemx append @r{[}binary@r{]} value @var{filename} @var{expr}
6169Append the contents of memory from @var{start_addr} to @var{end_addr},
6170or the value of @var{expr}, to @var{filename}, in raw binary form.
6171(@value{GDBN} can only append data to files in raw binary form.)
6172
6173@kindex restore
6174@item restore @var{filename} @r{[}binary@r{]} @var{bias} @var{start} @var{end}
6175Restore the contents of file @var{filename} into memory. The
6176@code{restore} command can automatically recognize any known @sc{bfd}
6177file format, except for raw binary. To restore a raw binary file you
6178must specify the optional keyword @code{binary} after the filename.
16d9dec6 6179
b383017d 6180If @var{bias} is non-zero, its value will be added to the addresses
16d9dec6
MS
6181contained in the file. Binary files always start at address zero, so
6182they will be restored at address @var{bias}. Other bfd files have
6183a built-in location; they will be restored at offset @var{bias}
6184from that location.
6185
6186If @var{start} and/or @var{end} are non-zero, then only data between
6187file offset @var{start} and file offset @var{end} will be restored.
b383017d 6188These offsets are relative to the addresses in the file, before
16d9dec6
MS
6189the @var{bias} argument is applied.
6190
6191@end table
6192
384ee23f
EZ
6193@node Core File Generation
6194@section How to Produce a Core File from Your Program
6195@cindex dump core from inferior
6196
6197A @dfn{core file} or @dfn{core dump} is a file that records the memory
6198image of a running process and its process status (register values
6199etc.). Its primary use is post-mortem debugging of a program that
6200crashed while it ran outside a debugger. A program that crashes
6201automatically produces a core file, unless this feature is disabled by
6202the user. @xref{Files}, for information on invoking @value{GDBN} in
6203the post-mortem debugging mode.
6204
6205Occasionally, you may wish to produce a core file of the program you
6206are debugging in order to preserve a snapshot of its state.
6207@value{GDBN} has a special command for that.
6208
6209@table @code
6210@kindex gcore
6211@kindex generate-core-file
6212@item generate-core-file [@var{file}]
6213@itemx gcore [@var{file}]
6214Produce a core dump of the inferior process. The optional argument
6215@var{file} specifies the file name where to put the core dump. If not
6216specified, the file name defaults to @file{core.@var{pid}}, where
6217@var{pid} is the inferior process ID.
6218
6219Note that this command is implemented only for some systems (as of
6220this writing, @sc{gnu}/Linux, FreeBSD, Solaris, Unixware, and S390).
6221@end table
6222
a0eb71c5
KB
6223@node Character Sets
6224@section Character Sets
6225@cindex character sets
6226@cindex charset
6227@cindex translating between character sets
6228@cindex host character set
6229@cindex target character set
6230
6231If the program you are debugging uses a different character set to
6232represent characters and strings than the one @value{GDBN} uses itself,
6233@value{GDBN} can automatically translate between the character sets for
6234you. The character set @value{GDBN} uses we call the @dfn{host
6235character set}; the one the inferior program uses we call the
6236@dfn{target character set}.
6237
6238For example, if you are running @value{GDBN} on a @sc{gnu}/Linux system, which
6239uses the ISO Latin 1 character set, but you are using @value{GDBN}'s
6240remote protocol (@pxref{Remote,Remote Debugging}) to debug a program
6241running on an IBM mainframe, which uses the @sc{ebcdic} character set,
6242then the host character set is Latin-1, and the target character set is
6243@sc{ebcdic}. If you give @value{GDBN} the command @code{set
e33d66ec 6244target-charset EBCDIC-US}, then @value{GDBN} translates between
a0eb71c5
KB
6245@sc{ebcdic} and Latin 1 as you print character or string values, or use
6246character and string literals in expressions.
6247
6248@value{GDBN} has no way to automatically recognize which character set
6249the inferior program uses; you must tell it, using the @code{set
6250target-charset} command, described below.
6251
6252Here are the commands for controlling @value{GDBN}'s character set
6253support:
6254
6255@table @code
6256@item set target-charset @var{charset}
6257@kindex set target-charset
6258Set the current target character set to @var{charset}. We list the
e33d66ec
EZ
6259character set names @value{GDBN} recognizes below, but if you type
6260@code{set target-charset} followed by @key{TAB}@key{TAB}, @value{GDBN} will
6261list the target character sets it supports.
a0eb71c5
KB
6262@end table
6263
6264@table @code
6265@item set host-charset @var{charset}
6266@kindex set host-charset
6267Set the current host character set to @var{charset}.
6268
6269By default, @value{GDBN} uses a host character set appropriate to the
6270system it is running on; you can override that default using the
6271@code{set host-charset} command.
6272
6273@value{GDBN} can only use certain character sets as its host character
6274set. We list the character set names @value{GDBN} recognizes below, and
e33d66ec
EZ
6275indicate which can be host character sets, but if you type
6276@code{set target-charset} followed by @key{TAB}@key{TAB}, @value{GDBN} will
6277list the host character sets it supports.
a0eb71c5
KB
6278
6279@item set charset @var{charset}
6280@kindex set charset
e33d66ec
EZ
6281Set the current host and target character sets to @var{charset}. As
6282above, if you type @code{set charset} followed by @key{TAB}@key{TAB},
6283@value{GDBN} will list the name of the character sets that can be used
6284for both host and target.
6285
a0eb71c5
KB
6286
6287@item show charset
a0eb71c5 6288@kindex show charset
b383017d 6289Show the names of the current host and target charsets.
e33d66ec
EZ
6290
6291@itemx show host-charset
a0eb71c5 6292@kindex show host-charset
b383017d 6293Show the name of the current host charset.
e33d66ec
EZ
6294
6295@itemx show target-charset
a0eb71c5 6296@kindex show target-charset
b383017d 6297Show the name of the current target charset.
a0eb71c5
KB
6298
6299@end table
6300
6301@value{GDBN} currently includes support for the following character
6302sets:
6303
6304@table @code
6305
6306@item ASCII
6307@cindex ASCII character set
6308Seven-bit U.S. @sc{ascii}. @value{GDBN} can use this as its host
6309character set.
6310
6311@item ISO-8859-1
6312@cindex ISO 8859-1 character set
6313@cindex ISO Latin 1 character set
e33d66ec 6314The ISO Latin 1 character set. This extends @sc{ascii} with accented
a0eb71c5
KB
6315characters needed for French, German, and Spanish. @value{GDBN} can use
6316this as its host character set.
6317
6318@item EBCDIC-US
6319@itemx IBM1047
6320@cindex EBCDIC character set
6321@cindex IBM1047 character set
6322Variants of the @sc{ebcdic} character set, used on some of IBM's
6323mainframe operating systems. (@sc{gnu}/Linux on the S/390 uses U.S. @sc{ascii}.)
6324@value{GDBN} cannot use these as its host character set.
6325
6326@end table
6327
6328Note that these are all single-byte character sets. More work inside
6329GDB is needed to support multi-byte or variable-width character
6330encodings, like the UTF-8 and UCS-2 encodings of Unicode.
6331
6332Here is an example of @value{GDBN}'s character set support in action.
6333Assume that the following source code has been placed in the file
6334@file{charset-test.c}:
6335
6336@smallexample
6337#include <stdio.h>
6338
6339char ascii_hello[]
6340 = @{72, 101, 108, 108, 111, 44, 32, 119,
6341 111, 114, 108, 100, 33, 10, 0@};
6342char ibm1047_hello[]
6343 = @{200, 133, 147, 147, 150, 107, 64, 166,
6344 150, 153, 147, 132, 90, 37, 0@};
6345
6346main ()
6347@{
6348 printf ("Hello, world!\n");
6349@}
10998722 6350@end smallexample
a0eb71c5
KB
6351
6352In this program, @code{ascii_hello} and @code{ibm1047_hello} are arrays
6353containing the string @samp{Hello, world!} followed by a newline,
6354encoded in the @sc{ascii} and @sc{ibm1047} character sets.
6355
6356We compile the program, and invoke the debugger on it:
6357
6358@smallexample
6359$ gcc -g charset-test.c -o charset-test
6360$ gdb -nw charset-test
6361GNU gdb 2001-12-19-cvs
6362Copyright 2001 Free Software Foundation, Inc.
6363@dots{}
f7dc1244 6364(@value{GDBP})
10998722 6365@end smallexample
a0eb71c5
KB
6366
6367We can use the @code{show charset} command to see what character sets
6368@value{GDBN} is currently using to interpret and display characters and
6369strings:
6370
6371@smallexample
f7dc1244 6372(@value{GDBP}) show charset
e33d66ec 6373The current host and target character set is `ISO-8859-1'.
f7dc1244 6374(@value{GDBP})
10998722 6375@end smallexample
a0eb71c5
KB
6376
6377For the sake of printing this manual, let's use @sc{ascii} as our
6378initial character set:
6379@smallexample
f7dc1244
EZ
6380(@value{GDBP}) set charset ASCII
6381(@value{GDBP}) show charset
e33d66ec 6382The current host and target character set is `ASCII'.
f7dc1244 6383(@value{GDBP})
10998722 6384@end smallexample
a0eb71c5
KB
6385
6386Let's assume that @sc{ascii} is indeed the correct character set for our
6387host system --- in other words, let's assume that if @value{GDBN} prints
6388characters using the @sc{ascii} character set, our terminal will display
6389them properly. Since our current target character set is also
6390@sc{ascii}, the contents of @code{ascii_hello} print legibly:
6391
6392@smallexample
f7dc1244 6393(@value{GDBP}) print ascii_hello
a0eb71c5 6394$1 = 0x401698 "Hello, world!\n"
f7dc1244 6395(@value{GDBP}) print ascii_hello[0]
a0eb71c5 6396$2 = 72 'H'
f7dc1244 6397(@value{GDBP})
10998722 6398@end smallexample
a0eb71c5
KB
6399
6400@value{GDBN} uses the target character set for character and string
6401literals you use in expressions:
6402
6403@smallexample
f7dc1244 6404(@value{GDBP}) print '+'
a0eb71c5 6405$3 = 43 '+'
f7dc1244 6406(@value{GDBP})
10998722 6407@end smallexample
a0eb71c5
KB
6408
6409The @sc{ascii} character set uses the number 43 to encode the @samp{+}
6410character.
6411
6412@value{GDBN} relies on the user to tell it which character set the
6413target program uses. If we print @code{ibm1047_hello} while our target
6414character set is still @sc{ascii}, we get jibberish:
6415
6416@smallexample
f7dc1244 6417(@value{GDBP}) print ibm1047_hello
a0eb71c5 6418$4 = 0x4016a8 "\310\205\223\223\226k@@\246\226\231\223\204Z%"
f7dc1244 6419(@value{GDBP}) print ibm1047_hello[0]
a0eb71c5 6420$5 = 200 '\310'
f7dc1244 6421(@value{GDBP})
10998722 6422@end smallexample
a0eb71c5 6423
e33d66ec 6424If we invoke the @code{set target-charset} followed by @key{TAB}@key{TAB},
a0eb71c5
KB
6425@value{GDBN} tells us the character sets it supports:
6426
6427@smallexample
f7dc1244 6428(@value{GDBP}) set target-charset
b383017d 6429ASCII EBCDIC-US IBM1047 ISO-8859-1
f7dc1244 6430(@value{GDBP}) set target-charset
10998722 6431@end smallexample
a0eb71c5
KB
6432
6433We can select @sc{ibm1047} as our target character set, and examine the
6434program's strings again. Now the @sc{ascii} string is wrong, but
6435@value{GDBN} translates the contents of @code{ibm1047_hello} from the
6436target character set, @sc{ibm1047}, to the host character set,
6437@sc{ascii}, and they display correctly:
6438
6439@smallexample
f7dc1244
EZ
6440(@value{GDBP}) set target-charset IBM1047
6441(@value{GDBP}) show charset
e33d66ec
EZ
6442The current host character set is `ASCII'.
6443The current target character set is `IBM1047'.
f7dc1244 6444(@value{GDBP}) print ascii_hello
a0eb71c5 6445$6 = 0x401698 "\110\145%%?\054\040\167?\162%\144\041\012"
f7dc1244 6446(@value{GDBP}) print ascii_hello[0]
a0eb71c5 6447$7 = 72 '\110'
f7dc1244 6448(@value{GDBP}) print ibm1047_hello
a0eb71c5 6449$8 = 0x4016a8 "Hello, world!\n"
f7dc1244 6450(@value{GDBP}) print ibm1047_hello[0]
a0eb71c5 6451$9 = 200 'H'
f7dc1244 6452(@value{GDBP})
10998722 6453@end smallexample
a0eb71c5
KB
6454
6455As above, @value{GDBN} uses the target character set for character and
6456string literals you use in expressions:
6457
6458@smallexample
f7dc1244 6459(@value{GDBP}) print '+'
a0eb71c5 6460$10 = 78 '+'
f7dc1244 6461(@value{GDBP})
10998722 6462@end smallexample
a0eb71c5 6463
e33d66ec 6464The @sc{ibm1047} character set uses the number 78 to encode the @samp{+}
a0eb71c5
KB
6465character.
6466
6467
e2e0bcd1
JB
6468@node Macros
6469@chapter C Preprocessor Macros
6470
49efadf5 6471Some languages, such as C and C@t{++}, provide a way to define and invoke
e2e0bcd1
JB
6472``preprocessor macros'' which expand into strings of tokens.
6473@value{GDBN} can evaluate expressions containing macro invocations, show
6474the result of macro expansion, and show a macro's definition, including
6475where it was defined.
6476
6477You may need to compile your program specially to provide @value{GDBN}
6478with information about preprocessor macros. Most compilers do not
6479include macros in their debugging information, even when you compile
6480with the @option{-g} flag. @xref{Compilation}.
6481
6482A program may define a macro at one point, remove that definition later,
6483and then provide a different definition after that. Thus, at different
6484points in the program, a macro may have different definitions, or have
6485no definition at all. If there is a current stack frame, @value{GDBN}
6486uses the macros in scope at that frame's source code line. Otherwise,
6487@value{GDBN} uses the macros in scope at the current listing location;
6488see @ref{List}.
6489
6490At the moment, @value{GDBN} does not support the @code{##}
6491token-splicing operator, the @code{#} stringification operator, or
6492variable-arity macros.
6493
6494Whenever @value{GDBN} evaluates an expression, it always expands any
6495macro invocations present in the expression. @value{GDBN} also provides
6496the following commands for working with macros explicitly.
6497
6498@table @code
6499
6500@kindex macro expand
6501@cindex macro expansion, showing the results of preprocessor
6502@cindex preprocessor macro expansion, showing the results of
6503@cindex expanding preprocessor macros
6504@item macro expand @var{expression}
6505@itemx macro exp @var{expression}
6506Show the results of expanding all preprocessor macro invocations in
6507@var{expression}. Since @value{GDBN} simply expands macros, but does
6508not parse the result, @var{expression} need not be a valid expression;
6509it can be any string of tokens.
6510
e2e0bcd1
JB
6511@item macro expand-once @var{expression}
6512@itemx macro exp1 @var{expression}
4644b6e3 6513@cindex expand macro once
e2e0bcd1
JB
6514@i{(This command is not yet implemented.)} Show the results of
6515expanding those preprocessor macro invocations that appear explicitly in
6516@var{expression}. Macro invocations appearing in that expansion are
6517left unchanged. This command allows you to see the effect of a
6518particular macro more clearly, without being confused by further
6519expansions. Since @value{GDBN} simply expands macros, but does not
6520parse the result, @var{expression} need not be a valid expression; it
6521can be any string of tokens.
6522
475b0867 6523@kindex info macro
e2e0bcd1
JB
6524@cindex macro definition, showing
6525@cindex definition, showing a macro's
475b0867 6526@item info macro @var{macro}
e2e0bcd1
JB
6527Show the definition of the macro named @var{macro}, and describe the
6528source location where that definition was established.
6529
6530@kindex macro define
6531@cindex user-defined macros
6532@cindex defining macros interactively
6533@cindex macros, user-defined
6534@item macro define @var{macro} @var{replacement-list}
6535@itemx macro define @var{macro}(@var{arglist}) @var{replacement-list}
6536@i{(This command is not yet implemented.)} Introduce a definition for a
6537preprocessor macro named @var{macro}, invocations of which are replaced
6538by the tokens given in @var{replacement-list}. The first form of this
6539command defines an ``object-like'' macro, which takes no arguments; the
6540second form defines a ``function-like'' macro, which takes the arguments
6541given in @var{arglist}.
6542
6543A definition introduced by this command is in scope in every expression
6544evaluated in @value{GDBN}, until it is removed with the @command{macro
6545undef} command, described below. The definition overrides all
6546definitions for @var{macro} present in the program being debugged, as
6547well as any previous user-supplied definition.
6548
6549@kindex macro undef
6550@item macro undef @var{macro}
6551@i{(This command is not yet implemented.)} Remove any user-supplied
6552definition for the macro named @var{macro}. This command only affects
6553definitions provided with the @command{macro define} command, described
6554above; it cannot remove definitions present in the program being
6555debugged.
6556
6557@end table
6558
6559@cindex macros, example of debugging with
6560Here is a transcript showing the above commands in action. First, we
6561show our source files:
6562
6563@smallexample
6564$ cat sample.c
6565#include <stdio.h>
6566#include "sample.h"
6567
6568#define M 42
6569#define ADD(x) (M + x)
6570
6571main ()
6572@{
6573#define N 28
6574 printf ("Hello, world!\n");
6575#undef N
6576 printf ("We're so creative.\n");
6577#define N 1729
6578 printf ("Goodbye, world!\n");
6579@}
6580$ cat sample.h
6581#define Q <
6582$
6583@end smallexample
6584
6585Now, we compile the program using the @sc{gnu} C compiler, @value{NGCC}.
6586We pass the @option{-gdwarf-2} and @option{-g3} flags to ensure the
6587compiler includes information about preprocessor macros in the debugging
6588information.
6589
6590@smallexample
6591$ gcc -gdwarf-2 -g3 sample.c -o sample
6592$
6593@end smallexample
6594
6595Now, we start @value{GDBN} on our sample program:
6596
6597@smallexample
6598$ gdb -nw sample
6599GNU gdb 2002-05-06-cvs
6600Copyright 2002 Free Software Foundation, Inc.
6601GDB is free software, @dots{}
f7dc1244 6602(@value{GDBP})
e2e0bcd1
JB
6603@end smallexample
6604
6605We can expand macros and examine their definitions, even when the
6606program is not running. @value{GDBN} uses the current listing position
6607to decide which macro definitions are in scope:
6608
6609@smallexample
f7dc1244 6610(@value{GDBP}) list main
e2e0bcd1
JB
66113
66124 #define M 42
66135 #define ADD(x) (M + x)
66146
66157 main ()
66168 @{
66179 #define N 28
661810 printf ("Hello, world!\n");
661911 #undef N
662012 printf ("We're so creative.\n");
f7dc1244 6621(@value{GDBP}) info macro ADD
e2e0bcd1
JB
6622Defined at /home/jimb/gdb/macros/play/sample.c:5
6623#define ADD(x) (M + x)
f7dc1244 6624(@value{GDBP}) info macro Q
e2e0bcd1
JB
6625Defined at /home/jimb/gdb/macros/play/sample.h:1
6626 included at /home/jimb/gdb/macros/play/sample.c:2
6627#define Q <
f7dc1244 6628(@value{GDBP}) macro expand ADD(1)
e2e0bcd1 6629expands to: (42 + 1)
f7dc1244 6630(@value{GDBP}) macro expand-once ADD(1)
e2e0bcd1 6631expands to: once (M + 1)
f7dc1244 6632(@value{GDBP})
e2e0bcd1
JB
6633@end smallexample
6634
6635In the example above, note that @command{macro expand-once} expands only
6636the macro invocation explicit in the original text --- the invocation of
6637@code{ADD} --- but does not expand the invocation of the macro @code{M},
6638which was introduced by @code{ADD}.
6639
6640Once the program is running, GDB uses the macro definitions in force at
6641the source line of the current stack frame:
6642
6643@smallexample
f7dc1244 6644(@value{GDBP}) break main
e2e0bcd1 6645Breakpoint 1 at 0x8048370: file sample.c, line 10.
f7dc1244 6646(@value{GDBP}) run
b383017d 6647Starting program: /home/jimb/gdb/macros/play/sample
e2e0bcd1
JB
6648
6649Breakpoint 1, main () at sample.c:10
665010 printf ("Hello, world!\n");
f7dc1244 6651(@value{GDBP})
e2e0bcd1
JB
6652@end smallexample
6653
6654At line 10, the definition of the macro @code{N} at line 9 is in force:
6655
6656@smallexample
f7dc1244 6657(@value{GDBP}) info macro N
e2e0bcd1
JB
6658Defined at /home/jimb/gdb/macros/play/sample.c:9
6659#define N 28
f7dc1244 6660(@value{GDBP}) macro expand N Q M
e2e0bcd1 6661expands to: 28 < 42
f7dc1244 6662(@value{GDBP}) print N Q M
e2e0bcd1 6663$1 = 1
f7dc1244 6664(@value{GDBP})
e2e0bcd1
JB
6665@end smallexample
6666
6667As we step over directives that remove @code{N}'s definition, and then
6668give it a new definition, @value{GDBN} finds the definition (or lack
6669thereof) in force at each point:
6670
6671@smallexample
f7dc1244 6672(@value{GDBP}) next
e2e0bcd1
JB
6673Hello, world!
667412 printf ("We're so creative.\n");
f7dc1244 6675(@value{GDBP}) info macro N
e2e0bcd1
JB
6676The symbol `N' has no definition as a C/C++ preprocessor macro
6677at /home/jimb/gdb/macros/play/sample.c:12
f7dc1244 6678(@value{GDBP}) next
e2e0bcd1
JB
6679We're so creative.
668014 printf ("Goodbye, world!\n");
f7dc1244 6681(@value{GDBP}) info macro N
e2e0bcd1
JB
6682Defined at /home/jimb/gdb/macros/play/sample.c:13
6683#define N 1729
f7dc1244 6684(@value{GDBP}) macro expand N Q M
e2e0bcd1 6685expands to: 1729 < 42
f7dc1244 6686(@value{GDBP}) print N Q M
e2e0bcd1 6687$2 = 0
f7dc1244 6688(@value{GDBP})
e2e0bcd1
JB
6689@end smallexample
6690
6691
b37052ae
EZ
6692@node Tracepoints
6693@chapter Tracepoints
6694@c This chapter is based on the documentation written by Michael
6695@c Snyder, David Taylor, Jim Blandy, and Elena Zannoni.
6696
6697@cindex tracepoints
6698In some applications, it is not feasible for the debugger to interrupt
6699the program's execution long enough for the developer to learn
6700anything helpful about its behavior. If the program's correctness
6701depends on its real-time behavior, delays introduced by a debugger
6702might cause the program to change its behavior drastically, or perhaps
6703fail, even when the code itself is correct. It is useful to be able
6704to observe the program's behavior without interrupting it.
6705
6706Using @value{GDBN}'s @code{trace} and @code{collect} commands, you can
6707specify locations in the program, called @dfn{tracepoints}, and
6708arbitrary expressions to evaluate when those tracepoints are reached.
6709Later, using the @code{tfind} command, you can examine the values
6710those expressions had when the program hit the tracepoints. The
6711expressions may also denote objects in memory---structures or arrays,
6712for example---whose values @value{GDBN} should record; while visiting
6713a particular tracepoint, you may inspect those objects as if they were
6714in memory at that moment. However, because @value{GDBN} records these
6715values without interacting with you, it can do so quickly and
6716unobtrusively, hopefully not disturbing the program's behavior.
6717
6718The tracepoint facility is currently available only for remote
2c0069bb
EZ
6719targets. @xref{Targets}. In addition, your remote target must know how
6720to collect trace data. This functionality is implemented in the remote
6721stub; however, none of the stubs distributed with @value{GDBN} support
6722tracepoints as of this writing.
b37052ae
EZ
6723
6724This chapter describes the tracepoint commands and features.
6725
6726@menu
b383017d
RM
6727* Set Tracepoints::
6728* Analyze Collected Data::
6729* Tracepoint Variables::
b37052ae
EZ
6730@end menu
6731
6732@node Set Tracepoints
6733@section Commands to Set Tracepoints
6734
6735Before running such a @dfn{trace experiment}, an arbitrary number of
6736tracepoints can be set. Like a breakpoint (@pxref{Set Breaks}), a
6737tracepoint has a number assigned to it by @value{GDBN}. Like with
6738breakpoints, tracepoint numbers are successive integers starting from
6739one. Many of the commands associated with tracepoints take the
6740tracepoint number as their argument, to identify which tracepoint to
6741work on.
6742
6743For each tracepoint, you can specify, in advance, some arbitrary set
6744of data that you want the target to collect in the trace buffer when
6745it hits that tracepoint. The collected data can include registers,
6746local variables, or global data. Later, you can use @value{GDBN}
6747commands to examine the values these data had at the time the
6748tracepoint was hit.
6749
6750This section describes commands to set tracepoints and associated
6751conditions and actions.
6752
6753@menu
b383017d
RM
6754* Create and Delete Tracepoints::
6755* Enable and Disable Tracepoints::
6756* Tracepoint Passcounts::
6757* Tracepoint Actions::
6758* Listing Tracepoints::
6759* Starting and Stopping Trace Experiment::
b37052ae
EZ
6760@end menu
6761
6762@node Create and Delete Tracepoints
6763@subsection Create and Delete Tracepoints
6764
6765@table @code
6766@cindex set tracepoint
6767@kindex trace
6768@item trace
6769The @code{trace} command is very similar to the @code{break} command.
6770Its argument can be a source line, a function name, or an address in
6771the target program. @xref{Set Breaks}. The @code{trace} command
6772defines a tracepoint, which is a point in the target program where the
6773debugger will briefly stop, collect some data, and then allow the
6774program to continue. Setting a tracepoint or changing its commands
6775doesn't take effect until the next @code{tstart} command; thus, you
6776cannot change the tracepoint attributes once a trace experiment is
6777running.
6778
6779Here are some examples of using the @code{trace} command:
6780
6781@smallexample
6782(@value{GDBP}) @b{trace foo.c:121} // a source file and line number
6783
6784(@value{GDBP}) @b{trace +2} // 2 lines forward
6785
6786(@value{GDBP}) @b{trace my_function} // first source line of function
6787
6788(@value{GDBP}) @b{trace *my_function} // EXACT start address of function
6789
6790(@value{GDBP}) @b{trace *0x2117c4} // an address
6791@end smallexample
6792
6793@noindent
6794You can abbreviate @code{trace} as @code{tr}.
6795
6796@vindex $tpnum
6797@cindex last tracepoint number
6798@cindex recent tracepoint number
6799@cindex tracepoint number
6800The convenience variable @code{$tpnum} records the tracepoint number
6801of the most recently set tracepoint.
6802
6803@kindex delete tracepoint
6804@cindex tracepoint deletion
6805@item delete tracepoint @r{[}@var{num}@r{]}
6806Permanently delete one or more tracepoints. With no argument, the
6807default is to delete all tracepoints.
6808
6809Examples:
6810
6811@smallexample
6812(@value{GDBP}) @b{delete trace 1 2 3} // remove three tracepoints
6813
6814(@value{GDBP}) @b{delete trace} // remove all tracepoints
6815@end smallexample
6816
6817@noindent
6818You can abbreviate this command as @code{del tr}.
6819@end table
6820
6821@node Enable and Disable Tracepoints
6822@subsection Enable and Disable Tracepoints
6823
6824@table @code
6825@kindex disable tracepoint
6826@item disable tracepoint @r{[}@var{num}@r{]}
6827Disable tracepoint @var{num}, or all tracepoints if no argument
6828@var{num} is given. A disabled tracepoint will have no effect during
6829the next trace experiment, but it is not forgotten. You can re-enable
6830a disabled tracepoint using the @code{enable tracepoint} command.
6831
6832@kindex enable tracepoint
6833@item enable tracepoint @r{[}@var{num}@r{]}
6834Enable tracepoint @var{num}, or all tracepoints. The enabled
6835tracepoints will become effective the next time a trace experiment is
6836run.
6837@end table
6838
6839@node Tracepoint Passcounts
6840@subsection Tracepoint Passcounts
6841
6842@table @code
6843@kindex passcount
6844@cindex tracepoint pass count
6845@item passcount @r{[}@var{n} @r{[}@var{num}@r{]]}
6846Set the @dfn{passcount} of a tracepoint. The passcount is a way to
6847automatically stop a trace experiment. If a tracepoint's passcount is
6848@var{n}, then the trace experiment will be automatically stopped on
6849the @var{n}'th time that tracepoint is hit. If the tracepoint number
6850@var{num} is not specified, the @code{passcount} command sets the
6851passcount of the most recently defined tracepoint. If no passcount is
6852given, the trace experiment will run until stopped explicitly by the
6853user.
6854
6855Examples:
6856
6857@smallexample
b383017d 6858(@value{GDBP}) @b{passcount 5 2} // Stop on the 5th execution of
6826cf00 6859@exdent @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @code{// tracepoint 2}
b37052ae
EZ
6860
6861(@value{GDBP}) @b{passcount 12} // Stop on the 12th execution of the
6826cf00 6862@exdent @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @code{// most recently defined tracepoint.}
b37052ae
EZ
6863(@value{GDBP}) @b{trace foo}
6864(@value{GDBP}) @b{pass 3}
6865(@value{GDBP}) @b{trace bar}
6866(@value{GDBP}) @b{pass 2}
6867(@value{GDBP}) @b{trace baz}
6868(@value{GDBP}) @b{pass 1} // Stop tracing when foo has been
6826cf00
EZ
6869@exdent @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @code{// executed 3 times OR when bar has}
6870@exdent @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @code{// been executed 2 times}
6871@exdent @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @code{// OR when baz has been executed 1 time.}
b37052ae
EZ
6872@end smallexample
6873@end table
6874
6875@node Tracepoint Actions
6876@subsection Tracepoint Action Lists
6877
6878@table @code
6879@kindex actions
6880@cindex tracepoint actions
6881@item actions @r{[}@var{num}@r{]}
6882This command will prompt for a list of actions to be taken when the
6883tracepoint is hit. If the tracepoint number @var{num} is not
6884specified, this command sets the actions for the one that was most
6885recently defined (so that you can define a tracepoint and then say
6886@code{actions} without bothering about its number). You specify the
6887actions themselves on the following lines, one action at a time, and
6888terminate the actions list with a line containing just @code{end}. So
6889far, the only defined actions are @code{collect} and
6890@code{while-stepping}.
6891
6892@cindex remove actions from a tracepoint
6893To remove all actions from a tracepoint, type @samp{actions @var{num}}
6894and follow it immediately with @samp{end}.
6895
6896@smallexample
6897(@value{GDBP}) @b{collect @var{data}} // collect some data
6898
6826cf00 6899(@value{GDBP}) @b{while-stepping 5} // single-step 5 times, collect data
b37052ae 6900
6826cf00 6901(@value{GDBP}) @b{end} // signals the end of actions.
b37052ae
EZ
6902@end smallexample
6903
6904In the following example, the action list begins with @code{collect}
6905commands indicating the things to be collected when the tracepoint is
6906hit. Then, in order to single-step and collect additional data
6907following the tracepoint, a @code{while-stepping} command is used,
6908followed by the list of things to be collected while stepping. The
6909@code{while-stepping} command is terminated by its own separate
6910@code{end} command. Lastly, the action list is terminated by an
6911@code{end} command.
6912
6913@smallexample
6914(@value{GDBP}) @b{trace foo}
6915(@value{GDBP}) @b{actions}
6916Enter actions for tracepoint 1, one per line:
6917> collect bar,baz
6918> collect $regs
6919> while-stepping 12
6920 > collect $fp, $sp
6921 > end
6922end
6923@end smallexample
6924
6925@kindex collect @r{(tracepoints)}
6926@item collect @var{expr1}, @var{expr2}, @dots{}
6927Collect values of the given expressions when the tracepoint is hit.
6928This command accepts a comma-separated list of any valid expressions.
6929In addition to global, static, or local variables, the following
6930special arguments are supported:
6931
6932@table @code
6933@item $regs
6934collect all registers
6935
6936@item $args
6937collect all function arguments
6938
6939@item $locals
6940collect all local variables.
6941@end table
6942
6943You can give several consecutive @code{collect} commands, each one
6944with a single argument, or one @code{collect} command with several
6945arguments separated by commas: the effect is the same.
6946
f5c37c66
EZ
6947The command @code{info scope} (@pxref{Symbols, info scope}) is
6948particularly useful for figuring out what data to collect.
6949
b37052ae
EZ
6950@kindex while-stepping @r{(tracepoints)}
6951@item while-stepping @var{n}
6952Perform @var{n} single-step traces after the tracepoint, collecting
6953new data at each step. The @code{while-stepping} command is
6954followed by the list of what to collect while stepping (followed by
6955its own @code{end} command):
6956
6957@smallexample
6958> while-stepping 12
6959 > collect $regs, myglobal
6960 > end
6961>
6962@end smallexample
6963
6964@noindent
6965You may abbreviate @code{while-stepping} as @code{ws} or
6966@code{stepping}.
6967@end table
6968
6969@node Listing Tracepoints
6970@subsection Listing Tracepoints
6971
6972@table @code
6973@kindex info tracepoints
6974@cindex information about tracepoints
6975@item info tracepoints @r{[}@var{num}@r{]}
8a037dd7 6976Display information about the tracepoint @var{num}. If you don't specify
798c8bc6 6977a tracepoint number, displays information about all the tracepoints
b37052ae
EZ
6978defined so far. For each tracepoint, the following information is
6979shown:
6980
6981@itemize @bullet
6982@item
6983its number
6984@item
6985whether it is enabled or disabled
6986@item
6987its address
6988@item
6989its passcount as given by the @code{passcount @var{n}} command
6990@item
6991its step count as given by the @code{while-stepping @var{n}} command
6992@item
6993where in the source files is the tracepoint set
6994@item
6995its action list as given by the @code{actions} command
6996@end itemize
6997
6998@smallexample
6999(@value{GDBP}) @b{info trace}
7000Num Enb Address PassC StepC What
70011 y 0x002117c4 0 0 <gdb_asm>
6826cf00
EZ
70022 y 0x0020dc64 0 0 in g_test at g_test.c:1375
70033 y 0x0020b1f4 0 0 in get_data at ../foo.c:41
b37052ae
EZ
7004(@value{GDBP})
7005@end smallexample
7006
7007@noindent
7008This command can be abbreviated @code{info tp}.
7009@end table
7010
7011@node Starting and Stopping Trace Experiment
7012@subsection Starting and Stopping Trace Experiment
7013
7014@table @code
7015@kindex tstart
7016@cindex start a new trace experiment
7017@cindex collected data discarded
7018@item tstart
7019This command takes no arguments. It starts the trace experiment, and
7020begins collecting data. This has the side effect of discarding all
7021the data collected in the trace buffer during the previous trace
7022experiment.
7023
7024@kindex tstop
7025@cindex stop a running trace experiment
7026@item tstop
7027This command takes no arguments. It ends the trace experiment, and
7028stops collecting data.
7029
7030@strong{Note:} a trace experiment and data collection may stop
7031automatically if any tracepoint's passcount is reached
7032(@pxref{Tracepoint Passcounts}), or if the trace buffer becomes full.
7033
7034@kindex tstatus
7035@cindex status of trace data collection
7036@cindex trace experiment, status of
7037@item tstatus
7038This command displays the status of the current trace data
7039collection.
7040@end table
7041
7042Here is an example of the commands we described so far:
7043
7044@smallexample
7045(@value{GDBP}) @b{trace gdb_c_test}
7046(@value{GDBP}) @b{actions}
7047Enter actions for tracepoint #1, one per line.
7048> collect $regs,$locals,$args
7049> while-stepping 11
7050 > collect $regs
7051 > end
7052> end
7053(@value{GDBP}) @b{tstart}
7054 [time passes @dots{}]
7055(@value{GDBP}) @b{tstop}
7056@end smallexample
7057
7058
7059@node Analyze Collected Data
7060@section Using the collected data
7061
7062After the tracepoint experiment ends, you use @value{GDBN} commands
7063for examining the trace data. The basic idea is that each tracepoint
7064collects a trace @dfn{snapshot} every time it is hit and another
7065snapshot every time it single-steps. All these snapshots are
7066consecutively numbered from zero and go into a buffer, and you can
7067examine them later. The way you examine them is to @dfn{focus} on a
7068specific trace snapshot. When the remote stub is focused on a trace
7069snapshot, it will respond to all @value{GDBN} requests for memory and
7070registers by reading from the buffer which belongs to that snapshot,
7071rather than from @emph{real} memory or registers of the program being
7072debugged. This means that @strong{all} @value{GDBN} commands
7073(@code{print}, @code{info registers}, @code{backtrace}, etc.) will
7074behave as if we were currently debugging the program state as it was
7075when the tracepoint occurred. Any requests for data that are not in
7076the buffer will fail.
7077
7078@menu
7079* tfind:: How to select a trace snapshot
7080* tdump:: How to display all data for a snapshot
7081* save-tracepoints:: How to save tracepoints for a future run
7082@end menu
7083
7084@node tfind
7085@subsection @code{tfind @var{n}}
7086
7087@kindex tfind
7088@cindex select trace snapshot
7089@cindex find trace snapshot
7090The basic command for selecting a trace snapshot from the buffer is
7091@code{tfind @var{n}}, which finds trace snapshot number @var{n},
7092counting from zero. If no argument @var{n} is given, the next
7093snapshot is selected.
7094
7095Here are the various forms of using the @code{tfind} command.
7096
7097@table @code
7098@item tfind start
7099Find the first snapshot in the buffer. This is a synonym for
7100@code{tfind 0} (since 0 is the number of the first snapshot).
7101
7102@item tfind none
7103Stop debugging trace snapshots, resume @emph{live} debugging.
7104
7105@item tfind end
7106Same as @samp{tfind none}.
7107
7108@item tfind
7109No argument means find the next trace snapshot.
7110
7111@item tfind -
7112Find the previous trace snapshot before the current one. This permits
7113retracing earlier steps.
7114
7115@item tfind tracepoint @var{num}
7116Find the next snapshot associated with tracepoint @var{num}. Search
7117proceeds forward from the last examined trace snapshot. If no
7118argument @var{num} is given, it means find the next snapshot collected
7119for the same tracepoint as the current snapshot.
7120
7121@item tfind pc @var{addr}
7122Find the next snapshot associated with the value @var{addr} of the
7123program counter. Search proceeds forward from the last examined trace
7124snapshot. If no argument @var{addr} is given, it means find the next
7125snapshot with the same value of PC as the current snapshot.
7126
7127@item tfind outside @var{addr1}, @var{addr2}
7128Find the next snapshot whose PC is outside the given range of
7129addresses.
7130
7131@item tfind range @var{addr1}, @var{addr2}
7132Find the next snapshot whose PC is between @var{addr1} and
7133@var{addr2}. @c FIXME: Is the range inclusive or exclusive?
7134
7135@item tfind line @r{[}@var{file}:@r{]}@var{n}
7136Find the next snapshot associated with the source line @var{n}. If
7137the optional argument @var{file} is given, refer to line @var{n} in
7138that source file. Search proceeds forward from the last examined
7139trace snapshot. If no argument @var{n} is given, it means find the
7140next line other than the one currently being examined; thus saying
7141@code{tfind line} repeatedly can appear to have the same effect as
7142stepping from line to line in a @emph{live} debugging session.
7143@end table
7144
7145The default arguments for the @code{tfind} commands are specifically
7146designed to make it easy to scan through the trace buffer. For
7147instance, @code{tfind} with no argument selects the next trace
7148snapshot, and @code{tfind -} with no argument selects the previous
7149trace snapshot. So, by giving one @code{tfind} command, and then
7150simply hitting @key{RET} repeatedly you can examine all the trace
7151snapshots in order. Or, by saying @code{tfind -} and then hitting
7152@key{RET} repeatedly you can examine the snapshots in reverse order.
7153The @code{tfind line} command with no argument selects the snapshot
7154for the next source line executed. The @code{tfind pc} command with
7155no argument selects the next snapshot with the same program counter
7156(PC) as the current frame. The @code{tfind tracepoint} command with
7157no argument selects the next trace snapshot collected by the same
7158tracepoint as the current one.
7159
7160In addition to letting you scan through the trace buffer manually,
7161these commands make it easy to construct @value{GDBN} scripts that
7162scan through the trace buffer and print out whatever collected data
7163you are interested in. Thus, if we want to examine the PC, FP, and SP
7164registers from each trace frame in the buffer, we can say this:
7165
7166@smallexample
7167(@value{GDBP}) @b{tfind start}
7168(@value{GDBP}) @b{while ($trace_frame != -1)}
7169> printf "Frame %d, PC = %08X, SP = %08X, FP = %08X\n", \
7170 $trace_frame, $pc, $sp, $fp
7171> tfind
7172> end
7173
7174Frame 0, PC = 0020DC64, SP = 0030BF3C, FP = 0030BF44
7175Frame 1, PC = 0020DC6C, SP = 0030BF38, FP = 0030BF44
7176Frame 2, PC = 0020DC70, SP = 0030BF34, FP = 0030BF44
7177Frame 3, PC = 0020DC74, SP = 0030BF30, FP = 0030BF44
7178Frame 4, PC = 0020DC78, SP = 0030BF2C, FP = 0030BF44
7179Frame 5, PC = 0020DC7C, SP = 0030BF28, FP = 0030BF44
7180Frame 6, PC = 0020DC80, SP = 0030BF24, FP = 0030BF44
7181Frame 7, PC = 0020DC84, SP = 0030BF20, FP = 0030BF44
7182Frame 8, PC = 0020DC88, SP = 0030BF1C, FP = 0030BF44
7183Frame 9, PC = 0020DC8E, SP = 0030BF18, FP = 0030BF44
7184Frame 10, PC = 00203F6C, SP = 0030BE3C, FP = 0030BF14
7185@end smallexample
7186
7187Or, if we want to examine the variable @code{X} at each source line in
7188the buffer:
7189
7190@smallexample
7191(@value{GDBP}) @b{tfind start}
7192(@value{GDBP}) @b{while ($trace_frame != -1)}
7193> printf "Frame %d, X == %d\n", $trace_frame, X
7194> tfind line
7195> end
7196
7197Frame 0, X = 1
7198Frame 7, X = 2
7199Frame 13, X = 255
7200@end smallexample
7201
7202@node tdump
7203@subsection @code{tdump}
7204@kindex tdump
7205@cindex dump all data collected at tracepoint
7206@cindex tracepoint data, display
7207
7208This command takes no arguments. It prints all the data collected at
7209the current trace snapshot.
7210
7211@smallexample
7212(@value{GDBP}) @b{trace 444}
7213(@value{GDBP}) @b{actions}
7214Enter actions for tracepoint #2, one per line:
7215> collect $regs, $locals, $args, gdb_long_test
7216> end
7217
7218(@value{GDBP}) @b{tstart}
7219
7220(@value{GDBP}) @b{tfind line 444}
7221#0 gdb_test (p1=0x11, p2=0x22, p3=0x33, p4=0x44, p5=0x55, p6=0x66)
7222at gdb_test.c:444
7223444 printp( "%s: arguments = 0x%X 0x%X 0x%X 0x%X 0x%X 0x%X\n", )
7224
7225(@value{GDBP}) @b{tdump}
7226Data collected at tracepoint 2, trace frame 1:
7227d0 0xc4aa0085 -995491707
7228d1 0x18 24
7229d2 0x80 128
7230d3 0x33 51
7231d4 0x71aea3d 119204413
7232d5 0x22 34
7233d6 0xe0 224
7234d7 0x380035 3670069
7235a0 0x19e24a 1696330
7236a1 0x3000668 50333288
7237a2 0x100 256
7238a3 0x322000 3284992
7239a4 0x3000698 50333336
7240a5 0x1ad3cc 1758156
7241fp 0x30bf3c 0x30bf3c
7242sp 0x30bf34 0x30bf34
7243ps 0x0 0
7244pc 0x20b2c8 0x20b2c8
7245fpcontrol 0x0 0
7246fpstatus 0x0 0
7247fpiaddr 0x0 0
7248p = 0x20e5b4 "gdb-test"
7249p1 = (void *) 0x11
7250p2 = (void *) 0x22
7251p3 = (void *) 0x33
7252p4 = (void *) 0x44
7253p5 = (void *) 0x55
7254p6 = (void *) 0x66
7255gdb_long_test = 17 '\021'
7256
7257(@value{GDBP})
7258@end smallexample
7259
7260@node save-tracepoints
7261@subsection @code{save-tracepoints @var{filename}}
7262@kindex save-tracepoints
7263@cindex save tracepoints for future sessions
7264
7265This command saves all current tracepoint definitions together with
7266their actions and passcounts, into a file @file{@var{filename}}
7267suitable for use in a later debugging session. To read the saved
7268tracepoint definitions, use the @code{source} command (@pxref{Command
7269Files}).
7270
7271@node Tracepoint Variables
7272@section Convenience Variables for Tracepoints
7273@cindex tracepoint variables
7274@cindex convenience variables for tracepoints
7275
7276@table @code
7277@vindex $trace_frame
7278@item (int) $trace_frame
7279The current trace snapshot (a.k.a.@: @dfn{frame}) number, or -1 if no
7280snapshot is selected.
7281
7282@vindex $tracepoint
7283@item (int) $tracepoint
7284The tracepoint for the current trace snapshot.
7285
7286@vindex $trace_line
7287@item (int) $trace_line
7288The line number for the current trace snapshot.
7289
7290@vindex $trace_file
7291@item (char []) $trace_file
7292The source file for the current trace snapshot.
7293
7294@vindex $trace_func
7295@item (char []) $trace_func
7296The name of the function containing @code{$tracepoint}.
7297@end table
7298
7299Note: @code{$trace_file} is not suitable for use in @code{printf},
7300use @code{output} instead.
7301
7302Here's a simple example of using these convenience variables for
7303stepping through all the trace snapshots and printing some of their
7304data.
7305
7306@smallexample
7307(@value{GDBP}) @b{tfind start}
7308
7309(@value{GDBP}) @b{while $trace_frame != -1}
7310> output $trace_file
7311> printf ", line %d (tracepoint #%d)\n", $trace_line, $tracepoint
7312> tfind
7313> end
7314@end smallexample
7315
df0cd8c5
JB
7316@node Overlays
7317@chapter Debugging Programs That Use Overlays
7318@cindex overlays
7319
7320If your program is too large to fit completely in your target system's
7321memory, you can sometimes use @dfn{overlays} to work around this
7322problem. @value{GDBN} provides some support for debugging programs that
7323use overlays.
7324
7325@menu
7326* How Overlays Work:: A general explanation of overlays.
7327* Overlay Commands:: Managing overlays in @value{GDBN}.
7328* Automatic Overlay Debugging:: @value{GDBN} can find out which overlays are
7329 mapped by asking the inferior.
7330* Overlay Sample Program:: A sample program using overlays.
7331@end menu
7332
7333@node How Overlays Work
7334@section How Overlays Work
7335@cindex mapped overlays
7336@cindex unmapped overlays
7337@cindex load address, overlay's
7338@cindex mapped address
7339@cindex overlay area
7340
7341Suppose you have a computer whose instruction address space is only 64
7342kilobytes long, but which has much more memory which can be accessed by
7343other means: special instructions, segment registers, or memory
7344management hardware, for example. Suppose further that you want to
7345adapt a program which is larger than 64 kilobytes to run on this system.
7346
7347One solution is to identify modules of your program which are relatively
7348independent, and need not call each other directly; call these modules
7349@dfn{overlays}. Separate the overlays from the main program, and place
7350their machine code in the larger memory. Place your main program in
7351instruction memory, but leave at least enough space there to hold the
7352largest overlay as well.
7353
7354Now, to call a function located in an overlay, you must first copy that
7355overlay's machine code from the large memory into the space set aside
7356for it in the instruction memory, and then jump to its entry point
7357there.
7358
c928edc0
AC
7359@c NB: In the below the mapped area's size is greater or equal to the
7360@c size of all overlays. This is intentional to remind the developer
7361@c that overlays don't necessarily need to be the same size.
7362
474c8240 7363@smallexample
df0cd8c5 7364@group
c928edc0
AC
7365 Data Instruction Larger
7366Address Space Address Space Address Space
7367+-----------+ +-----------+ +-----------+
7368| | | | | |
7369+-----------+ +-----------+ +-----------+<-- overlay 1
7370| program | | main | .----| overlay 1 | load address
7371| variables | | program | | +-----------+
7372| and heap | | | | | |
7373+-----------+ | | | +-----------+<-- overlay 2
7374| | +-----------+ | | | load address
7375+-----------+ | | | .-| overlay 2 |
7376 | | | | | |
7377 mapped --->+-----------+ | | +-----------+
7378 address | | | | | |
7379 | overlay | <-' | | |
7380 | area | <---' +-----------+<-- overlay 3
7381 | | <---. | | load address
7382 +-----------+ `--| overlay 3 |
7383 | | | |
7384 +-----------+ | |
7385 +-----------+
7386 | |
7387 +-----------+
7388
7389 @anchor{A code overlay}A code overlay
df0cd8c5 7390@end group
474c8240 7391@end smallexample
df0cd8c5 7392
c928edc0
AC
7393The diagram (@pxref{A code overlay}) shows a system with separate data
7394and instruction address spaces. To map an overlay, the program copies
7395its code from the larger address space to the instruction address space.
7396Since the overlays shown here all use the same mapped address, only one
7397may be mapped at a time. For a system with a single address space for
7398data and instructions, the diagram would be similar, except that the
7399program variables and heap would share an address space with the main
7400program and the overlay area.
df0cd8c5
JB
7401
7402An overlay loaded into instruction memory and ready for use is called a
7403@dfn{mapped} overlay; its @dfn{mapped address} is its address in the
7404instruction memory. An overlay not present (or only partially present)
7405in instruction memory is called @dfn{unmapped}; its @dfn{load address}
7406is its address in the larger memory. The mapped address is also called
7407the @dfn{virtual memory address}, or @dfn{VMA}; the load address is also
7408called the @dfn{load memory address}, or @dfn{LMA}.
7409
7410Unfortunately, overlays are not a completely transparent way to adapt a
7411program to limited instruction memory. They introduce a new set of
7412global constraints you must keep in mind as you design your program:
7413
7414@itemize @bullet
7415
7416@item
7417Before calling or returning to a function in an overlay, your program
7418must make sure that overlay is actually mapped. Otherwise, the call or
7419return will transfer control to the right address, but in the wrong
7420overlay, and your program will probably crash.
7421
7422@item
7423If the process of mapping an overlay is expensive on your system, you
7424will need to choose your overlays carefully to minimize their effect on
7425your program's performance.
7426
7427@item
7428The executable file you load onto your system must contain each
7429overlay's instructions, appearing at the overlay's load address, not its
7430mapped address. However, each overlay's instructions must be relocated
7431and its symbols defined as if the overlay were at its mapped address.
7432You can use GNU linker scripts to specify different load and relocation
7433addresses for pieces of your program; see @ref{Overlay Description,,,
7434ld.info, Using ld: the GNU linker}.
7435
7436@item
7437The procedure for loading executable files onto your system must be able
7438to load their contents into the larger address space as well as the
7439instruction and data spaces.
7440
7441@end itemize
7442
7443The overlay system described above is rather simple, and could be
7444improved in many ways:
7445
7446@itemize @bullet
7447
7448@item
7449If your system has suitable bank switch registers or memory management
7450hardware, you could use those facilities to make an overlay's load area
7451contents simply appear at their mapped address in instruction space.
7452This would probably be faster than copying the overlay to its mapped
7453area in the usual way.
7454
7455@item
7456If your overlays are small enough, you could set aside more than one
7457overlay area, and have more than one overlay mapped at a time.
7458
7459@item
7460You can use overlays to manage data, as well as instructions. In
7461general, data overlays are even less transparent to your design than
7462code overlays: whereas code overlays only require care when you call or
7463return to functions, data overlays require care every time you access
7464the data. Also, if you change the contents of a data overlay, you
7465must copy its contents back out to its load address before you can copy a
7466different data overlay into the same mapped area.
7467
7468@end itemize
7469
7470
7471@node Overlay Commands
7472@section Overlay Commands
7473
7474To use @value{GDBN}'s overlay support, each overlay in your program must
7475correspond to a separate section of the executable file. The section's
7476virtual memory address and load memory address must be the overlay's
7477mapped and load addresses. Identifying overlays with sections allows
7478@value{GDBN} to determine the appropriate address of a function or
7479variable, depending on whether the overlay is mapped or not.
7480
7481@value{GDBN}'s overlay commands all start with the word @code{overlay};
7482you can abbreviate this as @code{ov} or @code{ovly}. The commands are:
7483
7484@table @code
7485@item overlay off
4644b6e3 7486@kindex overlay
df0cd8c5
JB
7487Disable @value{GDBN}'s overlay support. When overlay support is
7488disabled, @value{GDBN} assumes that all functions and variables are
7489always present at their mapped addresses. By default, @value{GDBN}'s
7490overlay support is disabled.
7491
7492@item overlay manual
df0cd8c5
JB
7493@cindex manual overlay debugging
7494Enable @dfn{manual} overlay debugging. In this mode, @value{GDBN}
7495relies on you to tell it which overlays are mapped, and which are not,
7496using the @code{overlay map-overlay} and @code{overlay unmap-overlay}
7497commands described below.
7498
7499@item overlay map-overlay @var{overlay}
7500@itemx overlay map @var{overlay}
df0cd8c5
JB
7501@cindex map an overlay
7502Tell @value{GDBN} that @var{overlay} is now mapped; @var{overlay} must
7503be the name of the object file section containing the overlay. When an
7504overlay is mapped, @value{GDBN} assumes it can find the overlay's
7505functions and variables at their mapped addresses. @value{GDBN} assumes
7506that any other overlays whose mapped ranges overlap that of
7507@var{overlay} are now unmapped.
7508
7509@item overlay unmap-overlay @var{overlay}
7510@itemx overlay unmap @var{overlay}
df0cd8c5
JB
7511@cindex unmap an overlay
7512Tell @value{GDBN} that @var{overlay} is no longer mapped; @var{overlay}
7513must be the name of the object file section containing the overlay.
7514When an overlay is unmapped, @value{GDBN} assumes it can find the
7515overlay's functions and variables at their load addresses.
7516
7517@item overlay auto
df0cd8c5
JB
7518Enable @dfn{automatic} overlay debugging. In this mode, @value{GDBN}
7519consults a data structure the overlay manager maintains in the inferior
7520to see which overlays are mapped. For details, see @ref{Automatic
7521Overlay Debugging}.
7522
7523@item overlay load-target
7524@itemx overlay load
df0cd8c5
JB
7525@cindex reloading the overlay table
7526Re-read the overlay table from the inferior. Normally, @value{GDBN}
7527re-reads the table @value{GDBN} automatically each time the inferior
7528stops, so this command should only be necessary if you have changed the
7529overlay mapping yourself using @value{GDBN}. This command is only
7530useful when using automatic overlay debugging.
7531
7532@item overlay list-overlays
7533@itemx overlay list
7534@cindex listing mapped overlays
7535Display a list of the overlays currently mapped, along with their mapped
7536addresses, load addresses, and sizes.
7537
7538@end table
7539
7540Normally, when @value{GDBN} prints a code address, it includes the name
7541of the function the address falls in:
7542
474c8240 7543@smallexample
f7dc1244 7544(@value{GDBP}) print main
df0cd8c5 7545$3 = @{int ()@} 0x11a0 <main>
474c8240 7546@end smallexample
df0cd8c5
JB
7547@noindent
7548When overlay debugging is enabled, @value{GDBN} recognizes code in
7549unmapped overlays, and prints the names of unmapped functions with
7550asterisks around them. For example, if @code{foo} is a function in an
7551unmapped overlay, @value{GDBN} prints it this way:
7552
474c8240 7553@smallexample
f7dc1244 7554(@value{GDBP}) overlay list
df0cd8c5 7555No sections are mapped.
f7dc1244 7556(@value{GDBP}) print foo
df0cd8c5 7557$5 = @{int (int)@} 0x100000 <*foo*>
474c8240 7558@end smallexample
df0cd8c5
JB
7559@noindent
7560When @code{foo}'s overlay is mapped, @value{GDBN} prints the function's
7561name normally:
7562
474c8240 7563@smallexample
f7dc1244 7564(@value{GDBP}) overlay list
b383017d 7565Section .ov.foo.text, loaded at 0x100000 - 0x100034,
df0cd8c5 7566 mapped at 0x1016 - 0x104a
f7dc1244 7567(@value{GDBP}) print foo
df0cd8c5 7568$6 = @{int (int)@} 0x1016 <foo>
474c8240 7569@end smallexample
df0cd8c5
JB
7570
7571When overlay debugging is enabled, @value{GDBN} can find the correct
7572address for functions and variables in an overlay, whether or not the
7573overlay is mapped. This allows most @value{GDBN} commands, like
7574@code{break} and @code{disassemble}, to work normally, even on unmapped
7575code. However, @value{GDBN}'s breakpoint support has some limitations:
7576
7577@itemize @bullet
7578@item
7579@cindex breakpoints in overlays
7580@cindex overlays, setting breakpoints in
7581You can set breakpoints in functions in unmapped overlays, as long as
7582@value{GDBN} can write to the overlay at its load address.
7583@item
7584@value{GDBN} can not set hardware or simulator-based breakpoints in
7585unmapped overlays. However, if you set a breakpoint at the end of your
7586overlay manager (and tell @value{GDBN} which overlays are now mapped, if
7587you are using manual overlay management), @value{GDBN} will re-set its
7588breakpoints properly.
7589@end itemize
7590
7591
7592@node Automatic Overlay Debugging
7593@section Automatic Overlay Debugging
7594@cindex automatic overlay debugging
7595
7596@value{GDBN} can automatically track which overlays are mapped and which
7597are not, given some simple co-operation from the overlay manager in the
7598inferior. If you enable automatic overlay debugging with the
7599@code{overlay auto} command (@pxref{Overlay Commands}), @value{GDBN}
7600looks in the inferior's memory for certain variables describing the
7601current state of the overlays.
7602
7603Here are the variables your overlay manager must define to support
7604@value{GDBN}'s automatic overlay debugging:
7605
7606@table @asis
7607
7608@item @code{_ovly_table}:
7609This variable must be an array of the following structures:
7610
474c8240 7611@smallexample
df0cd8c5
JB
7612struct
7613@{
7614 /* The overlay's mapped address. */
7615 unsigned long vma;
7616
7617 /* The size of the overlay, in bytes. */
7618 unsigned long size;
7619
7620 /* The overlay's load address. */
7621 unsigned long lma;
7622
7623 /* Non-zero if the overlay is currently mapped;
7624 zero otherwise. */
7625 unsigned long mapped;
7626@}
474c8240 7627@end smallexample
df0cd8c5
JB
7628
7629@item @code{_novlys}:
7630This variable must be a four-byte signed integer, holding the total
7631number of elements in @code{_ovly_table}.
7632
7633@end table
7634
7635To decide whether a particular overlay is mapped or not, @value{GDBN}
7636looks for an entry in @w{@code{_ovly_table}} whose @code{vma} and
7637@code{lma} members equal the VMA and LMA of the overlay's section in the
7638executable file. When @value{GDBN} finds a matching entry, it consults
7639the entry's @code{mapped} member to determine whether the overlay is
7640currently mapped.
7641
81d46470 7642In addition, your overlay manager may define a function called
def71bfa 7643@code{_ovly_debug_event}. If this function is defined, @value{GDBN}
81d46470
MS
7644will silently set a breakpoint there. If the overlay manager then
7645calls this function whenever it has changed the overlay table, this
7646will enable @value{GDBN} to accurately keep track of which overlays
7647are in program memory, and update any breakpoints that may be set
b383017d 7648in overlays. This will allow breakpoints to work even if the
81d46470
MS
7649overlays are kept in ROM or other non-writable memory while they
7650are not being executed.
df0cd8c5
JB
7651
7652@node Overlay Sample Program
7653@section Overlay Sample Program
7654@cindex overlay example program
7655
7656When linking a program which uses overlays, you must place the overlays
7657at their load addresses, while relocating them to run at their mapped
7658addresses. To do this, you must write a linker script (@pxref{Overlay
7659Description,,, ld.info, Using ld: the GNU linker}). Unfortunately,
7660since linker scripts are specific to a particular host system, target
7661architecture, and target memory layout, this manual cannot provide
7662portable sample code demonstrating @value{GDBN}'s overlay support.
7663
7664However, the @value{GDBN} source distribution does contain an overlaid
7665program, with linker scripts for a few systems, as part of its test
7666suite. The program consists of the following files from
7667@file{gdb/testsuite/gdb.base}:
7668
7669@table @file
7670@item overlays.c
7671The main program file.
7672@item ovlymgr.c
7673A simple overlay manager, used by @file{overlays.c}.
7674@item foo.c
7675@itemx bar.c
7676@itemx baz.c
7677@itemx grbx.c
7678Overlay modules, loaded and used by @file{overlays.c}.
7679@item d10v.ld
7680@itemx m32r.ld
7681Linker scripts for linking the test program on the @code{d10v-elf}
7682and @code{m32r-elf} targets.
7683@end table
7684
7685You can build the test program using the @code{d10v-elf} GCC
7686cross-compiler like this:
7687
474c8240 7688@smallexample
df0cd8c5
JB
7689$ d10v-elf-gcc -g -c overlays.c
7690$ d10v-elf-gcc -g -c ovlymgr.c
7691$ d10v-elf-gcc -g -c foo.c
7692$ d10v-elf-gcc -g -c bar.c
7693$ d10v-elf-gcc -g -c baz.c
7694$ d10v-elf-gcc -g -c grbx.c
7695$ d10v-elf-gcc -g overlays.o ovlymgr.o foo.o bar.o \
7696 baz.o grbx.o -Wl,-Td10v.ld -o overlays
474c8240 7697@end smallexample
df0cd8c5
JB
7698
7699The build process is identical for any other architecture, except that
7700you must substitute the appropriate compiler and linker script for the
7701target system for @code{d10v-elf-gcc} and @code{d10v.ld}.
7702
7703
6d2ebf8b 7704@node Languages
c906108c
SS
7705@chapter Using @value{GDBN} with Different Languages
7706@cindex languages
7707
c906108c
SS
7708Although programming languages generally have common aspects, they are
7709rarely expressed in the same manner. For instance, in ANSI C,
7710dereferencing a pointer @code{p} is accomplished by @code{*p}, but in
7711Modula-2, it is accomplished by @code{p^}. Values can also be
5d161b24 7712represented (and displayed) differently. Hex numbers in C appear as
c906108c 7713@samp{0x1ae}, while in Modula-2 they appear as @samp{1AEH}.
c906108c
SS
7714
7715@cindex working language
7716Language-specific information is built into @value{GDBN} for some languages,
7717allowing you to express operations like the above in your program's
7718native language, and allowing @value{GDBN} to output values in a manner
7719consistent with the syntax of your program's native language. The
7720language you use to build expressions is called the @dfn{working
7721language}.
7722
7723@menu
7724* Setting:: Switching between source languages
7725* Show:: Displaying the language
c906108c 7726* Checks:: Type and range checks
c906108c 7727* Support:: Supported languages
4e562065 7728* Unsupported languages:: Unsupported languages
c906108c
SS
7729@end menu
7730
6d2ebf8b 7731@node Setting
c906108c
SS
7732@section Switching between source languages
7733
7734There are two ways to control the working language---either have @value{GDBN}
7735set it automatically, or select it manually yourself. You can use the
7736@code{set language} command for either purpose. On startup, @value{GDBN}
7737defaults to setting the language automatically. The working language is
7738used to determine how expressions you type are interpreted, how values
7739are printed, etc.
7740
7741In addition to the working language, every source file that
7742@value{GDBN} knows about has its own working language. For some object
7743file formats, the compiler might indicate which language a particular
7744source file is in. However, most of the time @value{GDBN} infers the
7745language from the name of the file. The language of a source file
b37052ae 7746controls whether C@t{++} names are demangled---this way @code{backtrace} can
c906108c 7747show each frame appropriately for its own language. There is no way to
d4f3574e
SS
7748set the language of a source file from within @value{GDBN}, but you can
7749set the language associated with a filename extension. @xref{Show, ,
7750Displaying the language}.
c906108c
SS
7751
7752This is most commonly a problem when you use a program, such
5d161b24 7753as @code{cfront} or @code{f2c}, that generates C but is written in
c906108c
SS
7754another language. In that case, make the
7755program use @code{#line} directives in its C output; that way
7756@value{GDBN} will know the correct language of the source code of the original
7757program, and will display that source code, not the generated C code.
7758
7759@menu
7760* Filenames:: Filename extensions and languages.
7761* Manually:: Setting the working language manually
7762* Automatically:: Having @value{GDBN} infer the source language
7763@end menu
7764
6d2ebf8b 7765@node Filenames
c906108c
SS
7766@subsection List of filename extensions and languages
7767
7768If a source file name ends in one of the following extensions, then
7769@value{GDBN} infers that its language is the one indicated.
7770
7771@table @file
e07c999f
PH
7772@item .ada
7773@itemx .ads
7774@itemx .adb
7775@itemx .a
7776Ada source file.
c906108c
SS
7777
7778@item .c
7779C source file
7780
7781@item .C
7782@itemx .cc
7783@itemx .cp
7784@itemx .cpp
7785@itemx .cxx
7786@itemx .c++
b37052ae 7787C@t{++} source file
c906108c 7788
b37303ee
AF
7789@item .m
7790Objective-C source file
7791
c906108c
SS
7792@item .f
7793@itemx .F
7794Fortran source file
7795
c906108c
SS
7796@item .mod
7797Modula-2 source file
c906108c
SS
7798
7799@item .s
7800@itemx .S
7801Assembler source file. This actually behaves almost like C, but
7802@value{GDBN} does not skip over function prologues when stepping.
7803@end table
7804
7805In addition, you may set the language associated with a filename
7806extension. @xref{Show, , Displaying the language}.
7807
6d2ebf8b 7808@node Manually
c906108c
SS
7809@subsection Setting the working language
7810
7811If you allow @value{GDBN} to set the language automatically,
7812expressions are interpreted the same way in your debugging session and
7813your program.
7814
7815@kindex set language
7816If you wish, you may set the language manually. To do this, issue the
7817command @samp{set language @var{lang}}, where @var{lang} is the name of
5d161b24 7818a language, such as
c906108c 7819@code{c} or @code{modula-2}.
c906108c
SS
7820For a list of the supported languages, type @samp{set language}.
7821
c906108c
SS
7822Setting the language manually prevents @value{GDBN} from updating the working
7823language automatically. This can lead to confusion if you try
7824to debug a program when the working language is not the same as the
7825source language, when an expression is acceptable to both
7826languages---but means different things. For instance, if the current
7827source file were written in C, and @value{GDBN} was parsing Modula-2, a
7828command such as:
7829
474c8240 7830@smallexample
c906108c 7831print a = b + c
474c8240 7832@end smallexample
c906108c
SS
7833
7834@noindent
7835might not have the effect you intended. In C, this means to add
7836@code{b} and @code{c} and place the result in @code{a}. The result
7837printed would be the value of @code{a}. In Modula-2, this means to compare
7838@code{a} to the result of @code{b+c}, yielding a @code{BOOLEAN} value.
c906108c 7839
6d2ebf8b 7840@node Automatically
c906108c
SS
7841@subsection Having @value{GDBN} infer the source language
7842
7843To have @value{GDBN} set the working language automatically, use
7844@samp{set language local} or @samp{set language auto}. @value{GDBN}
7845then infers the working language. That is, when your program stops in a
7846frame (usually by encountering a breakpoint), @value{GDBN} sets the
7847working language to the language recorded for the function in that
7848frame. If the language for a frame is unknown (that is, if the function
7849or block corresponding to the frame was defined in a source file that
7850does not have a recognized extension), the current working language is
7851not changed, and @value{GDBN} issues a warning.
7852
7853This may not seem necessary for most programs, which are written
7854entirely in one source language. However, program modules and libraries
7855written in one source language can be used by a main program written in
7856a different source language. Using @samp{set language auto} in this
7857case frees you from having to set the working language manually.
7858
6d2ebf8b 7859@node Show
c906108c 7860@section Displaying the language
c906108c
SS
7861
7862The following commands help you find out which language is the
7863working language, and also what language source files were written in.
7864
7865@kindex show language
c906108c
SS
7866@table @code
7867@item show language
7868Display the current working language. This is the
7869language you can use with commands such as @code{print} to
7870build and compute expressions that may involve variables in your program.
7871
7872@item info frame
4644b6e3 7873@kindex info frame@r{, show the source language}
5d161b24 7874Display the source language for this frame. This language becomes the
c906108c 7875working language if you use an identifier from this frame.
5d161b24 7876@xref{Frame Info, ,Information about a frame}, to identify the other
c906108c
SS
7877information listed here.
7878
7879@item info source
4644b6e3 7880@kindex info source@r{, show the source language}
c906108c 7881Display the source language of this source file.
5d161b24 7882@xref{Symbols, ,Examining the Symbol Table}, to identify the other
c906108c
SS
7883information listed here.
7884@end table
7885
7886In unusual circumstances, you may have source files with extensions
7887not in the standard list. You can then set the extension associated
7888with a language explicitly:
7889
7890@kindex set extension-language
7891@kindex info extensions
7892@table @code
7893@item set extension-language @var{.ext} @var{language}
7894Set source files with extension @var{.ext} to be assumed to be in
7895the source language @var{language}.
7896
7897@item info extensions
7898List all the filename extensions and the associated languages.
7899@end table
7900
6d2ebf8b 7901@node Checks
c906108c
SS
7902@section Type and range checking
7903
7904@quotation
7905@emph{Warning:} In this release, the @value{GDBN} commands for type and range
7906checking are included, but they do not yet have any effect. This
7907section documents the intended facilities.
7908@end quotation
7909@c FIXME remove warning when type/range code added
7910
7911Some languages are designed to guard you against making seemingly common
7912errors through a series of compile- and run-time checks. These include
7913checking the type of arguments to functions and operators, and making
7914sure mathematical overflows are caught at run time. Checks such as
7915these help to ensure a program's correctness once it has been compiled
7916by eliminating type mismatches, and providing active checks for range
7917errors when your program is running.
7918
7919@value{GDBN} can check for conditions like the above if you wish.
7920Although @value{GDBN} does not check the statements in your program, it
7921can check expressions entered directly into @value{GDBN} for evaluation via
7922the @code{print} command, for example. As with the working language,
7923@value{GDBN} can also decide whether or not to check automatically based on
7924your program's source language. @xref{Support, ,Supported languages},
7925for the default settings of supported languages.
7926
7927@menu
7928* Type Checking:: An overview of type checking
7929* Range Checking:: An overview of range checking
7930@end menu
7931
7932@cindex type checking
7933@cindex checks, type
6d2ebf8b 7934@node Type Checking
c906108c
SS
7935@subsection An overview of type checking
7936
7937Some languages, such as Modula-2, are strongly typed, meaning that the
7938arguments to operators and functions have to be of the correct type,
7939otherwise an error occurs. These checks prevent type mismatch
7940errors from ever causing any run-time problems. For example,
7941
7942@smallexample
79431 + 2 @result{} 3
7944@exdent but
7945@error{} 1 + 2.3
7946@end smallexample
7947
7948The second example fails because the @code{CARDINAL} 1 is not
7949type-compatible with the @code{REAL} 2.3.
7950
5d161b24
DB
7951For the expressions you use in @value{GDBN} commands, you can tell the
7952@value{GDBN} type checker to skip checking;
7953to treat any mismatches as errors and abandon the expression;
7954or to only issue warnings when type mismatches occur,
c906108c
SS
7955but evaluate the expression anyway. When you choose the last of
7956these, @value{GDBN} evaluates expressions like the second example above, but
7957also issues a warning.
7958
5d161b24
DB
7959Even if you turn type checking off, there may be other reasons
7960related to type that prevent @value{GDBN} from evaluating an expression.
7961For instance, @value{GDBN} does not know how to add an @code{int} and
7962a @code{struct foo}. These particular type errors have nothing to do
7963with the language in use, and usually arise from expressions, such as
c906108c
SS
7964the one described above, which make little sense to evaluate anyway.
7965
7966Each language defines to what degree it is strict about type. For
7967instance, both Modula-2 and C require the arguments to arithmetical
7968operators to be numbers. In C, enumerated types and pointers can be
7969represented as numbers, so that they are valid arguments to mathematical
7970operators. @xref{Support, ,Supported languages}, for further
7971details on specific languages.
7972
7973@value{GDBN} provides some additional commands for controlling the type checker:
7974
c906108c
SS
7975@kindex set check type
7976@kindex show check type
7977@table @code
7978@item set check type auto
7979Set type checking on or off based on the current working language.
7980@xref{Support, ,Supported languages}, for the default settings for
7981each language.
7982
7983@item set check type on
7984@itemx set check type off
7985Set type checking on or off, overriding the default setting for the
7986current working language. Issue a warning if the setting does not
7987match the language default. If any type mismatches occur in
d4f3574e 7988evaluating an expression while type checking is on, @value{GDBN} prints a
c906108c
SS
7989message and aborts evaluation of the expression.
7990
7991@item set check type warn
7992Cause the type checker to issue warnings, but to always attempt to
7993evaluate the expression. Evaluating the expression may still
7994be impossible for other reasons. For example, @value{GDBN} cannot add
7995numbers and structures.
7996
7997@item show type
5d161b24 7998Show the current setting of the type checker, and whether or not @value{GDBN}
c906108c
SS
7999is setting it automatically.
8000@end table
8001
8002@cindex range checking
8003@cindex checks, range
6d2ebf8b 8004@node Range Checking
c906108c
SS
8005@subsection An overview of range checking
8006
8007In some languages (such as Modula-2), it is an error to exceed the
8008bounds of a type; this is enforced with run-time checks. Such range
8009checking is meant to ensure program correctness by making sure
8010computations do not overflow, or indices on an array element access do
8011not exceed the bounds of the array.
8012
8013For expressions you use in @value{GDBN} commands, you can tell
8014@value{GDBN} to treat range errors in one of three ways: ignore them,
8015always treat them as errors and abandon the expression, or issue
8016warnings but evaluate the expression anyway.
8017
8018A range error can result from numerical overflow, from exceeding an
8019array index bound, or when you type a constant that is not a member
8020of any type. Some languages, however, do not treat overflows as an
8021error. In many implementations of C, mathematical overflow causes the
8022result to ``wrap around'' to lower values---for example, if @var{m} is
8023the largest integer value, and @var{s} is the smallest, then
8024
474c8240 8025@smallexample
c906108c 8026@var{m} + 1 @result{} @var{s}
474c8240 8027@end smallexample
c906108c
SS
8028
8029This, too, is specific to individual languages, and in some cases
8030specific to individual compilers or machines. @xref{Support, ,
8031Supported languages}, for further details on specific languages.
8032
8033@value{GDBN} provides some additional commands for controlling the range checker:
8034
c906108c
SS
8035@kindex set check range
8036@kindex show check range
8037@table @code
8038@item set check range auto
8039Set range checking on or off based on the current working language.
8040@xref{Support, ,Supported languages}, for the default settings for
8041each language.
8042
8043@item set check range on
8044@itemx set check range off
8045Set range checking on or off, overriding the default setting for the
8046current working language. A warning is issued if the setting does not
c3f6f71d
JM
8047match the language default. If a range error occurs and range checking is on,
8048then a message is printed and evaluation of the expression is aborted.
c906108c
SS
8049
8050@item set check range warn
8051Output messages when the @value{GDBN} range checker detects a range error,
8052but attempt to evaluate the expression anyway. Evaluating the
8053expression may still be impossible for other reasons, such as accessing
8054memory that the process does not own (a typical example from many Unix
8055systems).
8056
8057@item show range
8058Show the current setting of the range checker, and whether or not it is
8059being set automatically by @value{GDBN}.
8060@end table
c906108c 8061
6d2ebf8b 8062@node Support
c906108c 8063@section Supported languages
c906108c 8064
e07c999f 8065@value{GDBN} supports C, C@t{++}, Objective-C, Fortran, Java, assembly, Modula-2, and Ada.
cce74817 8066@c This is false ...
c906108c
SS
8067Some @value{GDBN} features may be used in expressions regardless of the
8068language you use: the @value{GDBN} @code{@@} and @code{::} operators,
8069and the @samp{@{type@}addr} construct (@pxref{Expressions,
8070,Expressions}) can be used with the constructs of any supported
8071language.
8072
8073The following sections detail to what degree each source language is
8074supported by @value{GDBN}. These sections are not meant to be language
8075tutorials or references, but serve only as a reference guide to what the
8076@value{GDBN} expression parser accepts, and what input and output
8077formats should look like for different languages. There are many good
8078books written on each of these languages; please look to these for a
8079language reference or tutorial.
8080
c906108c 8081@menu
b37303ee 8082* C:: C and C@t{++}
b383017d 8083* Objective-C:: Objective-C
b37303ee 8084* Modula-2:: Modula-2
e07c999f 8085* Ada:: Ada
c906108c
SS
8086@end menu
8087
6d2ebf8b 8088@node C
b37052ae 8089@subsection C and C@t{++}
7a292a7a 8090
b37052ae
EZ
8091@cindex C and C@t{++}
8092@cindex expressions in C or C@t{++}
c906108c 8093
b37052ae 8094Since C and C@t{++} are so closely related, many features of @value{GDBN} apply
c906108c
SS
8095to both languages. Whenever this is the case, we discuss those languages
8096together.
8097
41afff9a
EZ
8098@cindex C@t{++}
8099@cindex @code{g++}, @sc{gnu} C@t{++} compiler
b37052ae
EZ
8100@cindex @sc{gnu} C@t{++}
8101The C@t{++} debugging facilities are jointly implemented by the C@t{++}
8102compiler and @value{GDBN}. Therefore, to debug your C@t{++} code
8103effectively, you must compile your C@t{++} programs with a supported
8104C@t{++} compiler, such as @sc{gnu} @code{g++}, or the HP ANSI C@t{++}
c906108c
SS
8105compiler (@code{aCC}).
8106
0179ffac
DC
8107For best results when using @sc{gnu} C@t{++}, use the DWARF 2 debugging
8108format; if it doesn't work on your system, try the stabs+ debugging
8109format. You can select those formats explicitly with the @code{g++}
8110command-line options @option{-gdwarf-2} and @option{-gstabs+}.
8111@xref{Debugging Options,,Options for Debugging Your Program or @sc{gnu}
8112CC, gcc.info, Using @sc{gnu} CC}.
c906108c 8113
c906108c 8114@menu
b37052ae
EZ
8115* C Operators:: C and C@t{++} operators
8116* C Constants:: C and C@t{++} constants
8117* C plus plus expressions:: C@t{++} expressions
8118* C Defaults:: Default settings for C and C@t{++}
8119* C Checks:: C and C@t{++} type and range checks
c906108c 8120* Debugging C:: @value{GDBN} and C
b37052ae 8121* Debugging C plus plus:: @value{GDBN} features for C@t{++}
c906108c 8122@end menu
c906108c 8123
6d2ebf8b 8124@node C Operators
b37052ae 8125@subsubsection C and C@t{++} operators
7a292a7a 8126
b37052ae 8127@cindex C and C@t{++} operators
c906108c
SS
8128
8129Operators must be defined on values of specific types. For instance,
8130@code{+} is defined on numbers, but not on structures. Operators are
5d161b24 8131often defined on groups of types.
c906108c 8132
b37052ae 8133For the purposes of C and C@t{++}, the following definitions hold:
c906108c
SS
8134
8135@itemize @bullet
53a5351d 8136
c906108c 8137@item
c906108c 8138@emph{Integral types} include @code{int} with any of its storage-class
b37052ae 8139specifiers; @code{char}; @code{enum}; and, for C@t{++}, @code{bool}.
c906108c
SS
8140
8141@item
d4f3574e
SS
8142@emph{Floating-point types} include @code{float}, @code{double}, and
8143@code{long double} (if supported by the target platform).
c906108c
SS
8144
8145@item
53a5351d 8146@emph{Pointer types} include all types defined as @code{(@var{type} *)}.
c906108c
SS
8147
8148@item
8149@emph{Scalar types} include all of the above.
53a5351d 8150
c906108c
SS
8151@end itemize
8152
8153@noindent
8154The following operators are supported. They are listed here
8155in order of increasing precedence:
8156
8157@table @code
8158@item ,
8159The comma or sequencing operator. Expressions in a comma-separated list
8160are evaluated from left to right, with the result of the entire
8161expression being the last expression evaluated.
8162
8163@item =
8164Assignment. The value of an assignment expression is the value
8165assigned. Defined on scalar types.
8166
8167@item @var{op}=
8168Used in an expression of the form @w{@code{@var{a} @var{op}= @var{b}}},
8169and translated to @w{@code{@var{a} = @var{a op b}}}.
d4f3574e 8170@w{@code{@var{op}=}} and @code{=} have the same precedence.
c906108c
SS
8171@var{op} is any one of the operators @code{|}, @code{^}, @code{&},
8172@code{<<}, @code{>>}, @code{+}, @code{-}, @code{*}, @code{/}, @code{%}.
8173
8174@item ?:
8175The ternary operator. @code{@var{a} ? @var{b} : @var{c}} can be thought
8176of as: if @var{a} then @var{b} else @var{c}. @var{a} should be of an
8177integral type.
8178
8179@item ||
8180Logical @sc{or}. Defined on integral types.
8181
8182@item &&
8183Logical @sc{and}. Defined on integral types.
8184
8185@item |
8186Bitwise @sc{or}. Defined on integral types.
8187
8188@item ^
8189Bitwise exclusive-@sc{or}. Defined on integral types.
8190
8191@item &
8192Bitwise @sc{and}. Defined on integral types.
8193
8194@item ==@r{, }!=
8195Equality and inequality. Defined on scalar types. The value of these
8196expressions is 0 for false and non-zero for true.
8197
8198@item <@r{, }>@r{, }<=@r{, }>=
8199Less than, greater than, less than or equal, greater than or equal.
8200Defined on scalar types. The value of these expressions is 0 for false
8201and non-zero for true.
8202
8203@item <<@r{, }>>
8204left shift, and right shift. Defined on integral types.
8205
8206@item @@
8207The @value{GDBN} ``artificial array'' operator (@pxref{Expressions, ,Expressions}).
8208
8209@item +@r{, }-
8210Addition and subtraction. Defined on integral types, floating-point types and
8211pointer types.
8212
8213@item *@r{, }/@r{, }%
8214Multiplication, division, and modulus. Multiplication and division are
8215defined on integral and floating-point types. Modulus is defined on
8216integral types.
8217
8218@item ++@r{, }--
8219Increment and decrement. When appearing before a variable, the
8220operation is performed before the variable is used in an expression;
8221when appearing after it, the variable's value is used before the
8222operation takes place.
8223
8224@item *
8225Pointer dereferencing. Defined on pointer types. Same precedence as
8226@code{++}.
8227
8228@item &
8229Address operator. Defined on variables. Same precedence as @code{++}.
8230
b37052ae
EZ
8231For debugging C@t{++}, @value{GDBN} implements a use of @samp{&} beyond what is
8232allowed in the C@t{++} language itself: you can use @samp{&(&@var{ref})}
c906108c 8233(or, if you prefer, simply @samp{&&@var{ref}}) to examine the address
b37052ae 8234where a C@t{++} reference variable (declared with @samp{&@var{ref}}) is
c906108c 8235stored.
c906108c
SS
8236
8237@item -
8238Negative. Defined on integral and floating-point types. Same
8239precedence as @code{++}.
8240
8241@item !
8242Logical negation. Defined on integral types. Same precedence as
8243@code{++}.
8244
8245@item ~
8246Bitwise complement operator. Defined on integral types. Same precedence as
8247@code{++}.
8248
8249
8250@item .@r{, }->
8251Structure member, and pointer-to-structure member. For convenience,
8252@value{GDBN} regards the two as equivalent, choosing whether to dereference a
8253pointer based on the stored type information.
8254Defined on @code{struct} and @code{union} data.
8255
c906108c
SS
8256@item .*@r{, }->*
8257Dereferences of pointers to members.
c906108c
SS
8258
8259@item []
8260Array indexing. @code{@var{a}[@var{i}]} is defined as
8261@code{*(@var{a}+@var{i})}. Same precedence as @code{->}.
8262
8263@item ()
8264Function parameter list. Same precedence as @code{->}.
8265
c906108c 8266@item ::
b37052ae 8267C@t{++} scope resolution operator. Defined on @code{struct}, @code{union},
7a292a7a 8268and @code{class} types.
c906108c
SS
8269
8270@item ::
7a292a7a
SS
8271Doubled colons also represent the @value{GDBN} scope operator
8272(@pxref{Expressions, ,Expressions}). Same precedence as @code{::},
8273above.
c906108c
SS
8274@end table
8275
c906108c
SS
8276If an operator is redefined in the user code, @value{GDBN} usually
8277attempts to invoke the redefined version instead of using the operator's
8278predefined meaning.
c906108c 8279
c906108c 8280@menu
5d161b24 8281* C Constants::
c906108c
SS
8282@end menu
8283
6d2ebf8b 8284@node C Constants
b37052ae 8285@subsubsection C and C@t{++} constants
c906108c 8286
b37052ae 8287@cindex C and C@t{++} constants
c906108c 8288
b37052ae 8289@value{GDBN} allows you to express the constants of C and C@t{++} in the
c906108c 8290following ways:
c906108c
SS
8291
8292@itemize @bullet
8293@item
8294Integer constants are a sequence of digits. Octal constants are
6ca652b0
EZ
8295specified by a leading @samp{0} (i.e.@: zero), and hexadecimal constants
8296by a leading @samp{0x} or @samp{0X}. Constants may also end with a letter
c906108c
SS
8297@samp{l}, specifying that the constant should be treated as a
8298@code{long} value.
8299
8300@item
8301Floating point constants are a sequence of digits, followed by a decimal
8302point, followed by a sequence of digits, and optionally followed by an
8303exponent. An exponent is of the form:
8304@samp{@w{e@r{[[}+@r{]|}-@r{]}@var{nnn}}}, where @var{nnn} is another
8305sequence of digits. The @samp{+} is optional for positive exponents.
d4f3574e
SS
8306A floating-point constant may also end with a letter @samp{f} or
8307@samp{F}, specifying that the constant should be treated as being of
8308the @code{float} (as opposed to the default @code{double}) type; or with
8309a letter @samp{l} or @samp{L}, which specifies a @code{long double}
8310constant.
c906108c
SS
8311
8312@item
8313Enumerated constants consist of enumerated identifiers, or their
8314integral equivalents.
8315
8316@item
8317Character constants are a single character surrounded by single quotes
8318(@code{'}), or a number---the ordinal value of the corresponding character
d4f3574e 8319(usually its @sc{ascii} value). Within quotes, the single character may
c906108c
SS
8320be represented by a letter or by @dfn{escape sequences}, which are of
8321the form @samp{\@var{nnn}}, where @var{nnn} is the octal representation
8322of the character's ordinal value; or of the form @samp{\@var{x}}, where
8323@samp{@var{x}} is a predefined special character---for example,
8324@samp{\n} for newline.
8325
8326@item
96a2c332
SS
8327String constants are a sequence of character constants surrounded by
8328double quotes (@code{"}). Any valid character constant (as described
8329above) may appear. Double quotes within the string must be preceded by
8330a backslash, so for instance @samp{"a\"b'c"} is a string of five
8331characters.
c906108c
SS
8332
8333@item
8334Pointer constants are an integral value. You can also write pointers
8335to constants using the C operator @samp{&}.
8336
8337@item
8338Array constants are comma-separated lists surrounded by braces @samp{@{}
8339and @samp{@}}; for example, @samp{@{1,2,3@}} is a three-element array of
8340integers, @samp{@{@{1,2@}, @{3,4@}, @{5,6@}@}} is a three-by-two array,
8341and @samp{@{&"hi", &"there", &"fred"@}} is a three-element array of pointers.
8342@end itemize
8343
c906108c 8344@menu
5d161b24
DB
8345* C plus plus expressions::
8346* C Defaults::
8347* C Checks::
c906108c 8348
5d161b24 8349* Debugging C::
c906108c
SS
8350@end menu
8351
6d2ebf8b 8352@node C plus plus expressions
b37052ae
EZ
8353@subsubsection C@t{++} expressions
8354
8355@cindex expressions in C@t{++}
8356@value{GDBN} expression handling can interpret most C@t{++} expressions.
8357
0179ffac
DC
8358@cindex debugging C@t{++} programs
8359@cindex C@t{++} compilers
8360@cindex debug formats and C@t{++}
8361@cindex @value{NGCC} and C@t{++}
c906108c 8362@quotation
b37052ae 8363@emph{Warning:} @value{GDBN} can only debug C@t{++} code if you use the
0179ffac
DC
8364proper compiler and the proper debug format. Currently, @value{GDBN}
8365works best when debugging C@t{++} code that is compiled with
8366@value{NGCC} 2.95.3 or with @value{NGCC} 3.1 or newer, using the options
8367@option{-gdwarf-2} or @option{-gstabs+}. DWARF 2 is preferred over
8368stabs+. Most configurations of @value{NGCC} emit either DWARF 2 or
8369stabs+ as their default debug format, so you usually don't need to
8370specify a debug format explicitly. Other compilers and/or debug formats
8371are likely to work badly or not at all when using @value{GDBN} to debug
8372C@t{++} code.
c906108c 8373@end quotation
c906108c
SS
8374
8375@enumerate
8376
8377@cindex member functions
8378@item
8379Member function calls are allowed; you can use expressions like
8380
474c8240 8381@smallexample
c906108c 8382count = aml->GetOriginal(x, y)
474c8240 8383@end smallexample
c906108c 8384
41afff9a 8385@vindex this@r{, inside C@t{++} member functions}
b37052ae 8386@cindex namespace in C@t{++}
c906108c
SS
8387@item
8388While a member function is active (in the selected stack frame), your
8389expressions have the same namespace available as the member function;
8390that is, @value{GDBN} allows implicit references to the class instance
b37052ae 8391pointer @code{this} following the same rules as C@t{++}.
c906108c 8392
c906108c 8393@cindex call overloaded functions
d4f3574e 8394@cindex overloaded functions, calling
b37052ae 8395@cindex type conversions in C@t{++}
c906108c
SS
8396@item
8397You can call overloaded functions; @value{GDBN} resolves the function
d4f3574e 8398call to the right definition, with some restrictions. @value{GDBN} does not
c906108c
SS
8399perform overload resolution involving user-defined type conversions,
8400calls to constructors, or instantiations of templates that do not exist
8401in the program. It also cannot handle ellipsis argument lists or
8402default arguments.
8403
8404It does perform integral conversions and promotions, floating-point
8405promotions, arithmetic conversions, pointer conversions, conversions of
8406class objects to base classes, and standard conversions such as those of
8407functions or arrays to pointers; it requires an exact match on the
8408number of function arguments.
8409
8410Overload resolution is always performed, unless you have specified
8411@code{set overload-resolution off}. @xref{Debugging C plus plus,
b37052ae 8412,@value{GDBN} features for C@t{++}}.
c906108c 8413
d4f3574e 8414You must specify @code{set overload-resolution off} in order to use an
c906108c
SS
8415explicit function signature to call an overloaded function, as in
8416@smallexample
8417p 'foo(char,int)'('x', 13)
8418@end smallexample
d4f3574e 8419
c906108c 8420The @value{GDBN} command-completion facility can simplify this;
d4f3574e 8421see @ref{Completion, ,Command completion}.
c906108c 8422
c906108c
SS
8423@cindex reference declarations
8424@item
b37052ae
EZ
8425@value{GDBN} understands variables declared as C@t{++} references; you can use
8426them in expressions just as you do in C@t{++} source---they are automatically
c906108c
SS
8427dereferenced.
8428
8429In the parameter list shown when @value{GDBN} displays a frame, the values of
8430reference variables are not displayed (unlike other variables); this
8431avoids clutter, since references are often used for large structures.
8432The @emph{address} of a reference variable is always shown, unless
8433you have specified @samp{set print address off}.
8434
8435@item
b37052ae 8436@value{GDBN} supports the C@t{++} name resolution operator @code{::}---your
c906108c
SS
8437expressions can use it just as expressions in your program do. Since
8438one scope may be defined in another, you can use @code{::} repeatedly if
8439necessary, for example in an expression like
8440@samp{@var{scope1}::@var{scope2}::@var{name}}. @value{GDBN} also allows
b37052ae 8441resolving name scope by reference to source files, in both C and C@t{++}
c906108c
SS
8442debugging (@pxref{Variables, ,Program variables}).
8443@end enumerate
8444
b37052ae 8445In addition, when used with HP's C@t{++} compiler, @value{GDBN} supports
53a5351d
JM
8446calling virtual functions correctly, printing out virtual bases of
8447objects, calling functions in a base subobject, casting objects, and
8448invoking user-defined operators.
c906108c 8449
6d2ebf8b 8450@node C Defaults
b37052ae 8451@subsubsection C and C@t{++} defaults
7a292a7a 8452
b37052ae 8453@cindex C and C@t{++} defaults
c906108c 8454
c906108c
SS
8455If you allow @value{GDBN} to set type and range checking automatically, they
8456both default to @code{off} whenever the working language changes to
b37052ae 8457C or C@t{++}. This happens regardless of whether you or @value{GDBN}
c906108c 8458selects the working language.
c906108c
SS
8459
8460If you allow @value{GDBN} to set the language automatically, it
8461recognizes source files whose names end with @file{.c}, @file{.C}, or
8462@file{.cc}, etc, and when @value{GDBN} enters code compiled from one of
b37052ae 8463these files, it sets the working language to C or C@t{++}.
c906108c
SS
8464@xref{Automatically, ,Having @value{GDBN} infer the source language},
8465for further details.
8466
c906108c
SS
8467@c Type checking is (a) primarily motivated by Modula-2, and (b)
8468@c unimplemented. If (b) changes, it might make sense to let this node
8469@c appear even if Mod-2 does not, but meanwhile ignore it. roland 16jul93.
7a292a7a 8470
6d2ebf8b 8471@node C Checks
b37052ae 8472@subsubsection C and C@t{++} type and range checks
7a292a7a 8473
b37052ae 8474@cindex C and C@t{++} checks
c906108c 8475
b37052ae 8476By default, when @value{GDBN} parses C or C@t{++} expressions, type checking
c906108c
SS
8477is not used. However, if you turn type checking on, @value{GDBN}
8478considers two variables type equivalent if:
8479
8480@itemize @bullet
8481@item
8482The two variables are structured and have the same structure, union, or
8483enumerated tag.
8484
8485@item
8486The two variables have the same type name, or types that have been
8487declared equivalent through @code{typedef}.
8488
8489@ignore
8490@c leaving this out because neither J Gilmore nor R Pesch understand it.
8491@c FIXME--beers?
8492@item
8493The two @code{struct}, @code{union}, or @code{enum} variables are
8494declared in the same declaration. (Note: this may not be true for all C
8495compilers.)
8496@end ignore
8497@end itemize
8498
8499Range checking, if turned on, is done on mathematical operations. Array
8500indices are not checked, since they are often used to index a pointer
8501that is not itself an array.
c906108c 8502
6d2ebf8b 8503@node Debugging C
c906108c 8504@subsubsection @value{GDBN} and C
c906108c
SS
8505
8506The @code{set print union} and @code{show print union} commands apply to
8507the @code{union} type. When set to @samp{on}, any @code{union} that is
7a292a7a
SS
8508inside a @code{struct} or @code{class} is also printed. Otherwise, it
8509appears as @samp{@{...@}}.
c906108c
SS
8510
8511The @code{@@} operator aids in the debugging of dynamic arrays, formed
8512with pointers and a memory allocation function. @xref{Expressions,
8513,Expressions}.
8514
c906108c 8515@menu
5d161b24 8516* Debugging C plus plus::
c906108c
SS
8517@end menu
8518
6d2ebf8b 8519@node Debugging C plus plus
b37052ae 8520@subsubsection @value{GDBN} features for C@t{++}
c906108c 8521
b37052ae 8522@cindex commands for C@t{++}
7a292a7a 8523
b37052ae
EZ
8524Some @value{GDBN} commands are particularly useful with C@t{++}, and some are
8525designed specifically for use with C@t{++}. Here is a summary:
c906108c
SS
8526
8527@table @code
8528@cindex break in overloaded functions
8529@item @r{breakpoint menus}
8530When you want a breakpoint in a function whose name is overloaded,
8531@value{GDBN} breakpoint menus help you specify which function definition
8532you want. @xref{Breakpoint Menus,,Breakpoint menus}.
8533
b37052ae 8534@cindex overloading in C@t{++}
c906108c
SS
8535@item rbreak @var{regex}
8536Setting breakpoints using regular expressions is helpful for setting
8537breakpoints on overloaded functions that are not members of any special
8538classes.
8539@xref{Set Breaks, ,Setting breakpoints}.
8540
b37052ae 8541@cindex C@t{++} exception handling
c906108c
SS
8542@item catch throw
8543@itemx catch catch
b37052ae 8544Debug C@t{++} exception handling using these commands. @xref{Set
c906108c
SS
8545Catchpoints, , Setting catchpoints}.
8546
8547@cindex inheritance
8548@item ptype @var{typename}
8549Print inheritance relationships as well as other information for type
8550@var{typename}.
8551@xref{Symbols, ,Examining the Symbol Table}.
8552
b37052ae 8553@cindex C@t{++} symbol display
c906108c
SS
8554@item set print demangle
8555@itemx show print demangle
8556@itemx set print asm-demangle
8557@itemx show print asm-demangle
b37052ae
EZ
8558Control whether C@t{++} symbols display in their source form, both when
8559displaying code as C@t{++} source and when displaying disassemblies.
c906108c
SS
8560@xref{Print Settings, ,Print settings}.
8561
8562@item set print object
8563@itemx show print object
8564Choose whether to print derived (actual) or declared types of objects.
8565@xref{Print Settings, ,Print settings}.
8566
8567@item set print vtbl
8568@itemx show print vtbl
8569Control the format for printing virtual function tables.
8570@xref{Print Settings, ,Print settings}.
c906108c 8571(The @code{vtbl} commands do not work on programs compiled with the HP
b37052ae 8572ANSI C@t{++} compiler (@code{aCC}).)
c906108c
SS
8573
8574@kindex set overload-resolution
d4f3574e 8575@cindex overloaded functions, overload resolution
c906108c 8576@item set overload-resolution on
b37052ae 8577Enable overload resolution for C@t{++} expression evaluation. The default
c906108c
SS
8578is on. For overloaded functions, @value{GDBN} evaluates the arguments
8579and searches for a function whose signature matches the argument types,
b37052ae 8580using the standard C@t{++} conversion rules (see @ref{C plus plus expressions, ,C@t{++}
d4f3574e 8581expressions}, for details). If it cannot find a match, it emits a
c906108c
SS
8582message.
8583
8584@item set overload-resolution off
b37052ae 8585Disable overload resolution for C@t{++} expression evaluation. For
c906108c
SS
8586overloaded functions that are not class member functions, @value{GDBN}
8587chooses the first function of the specified name that it finds in the
8588symbol table, whether or not its arguments are of the correct type. For
8589overloaded functions that are class member functions, @value{GDBN}
8590searches for a function whose signature @emph{exactly} matches the
8591argument types.
c906108c
SS
8592
8593@item @r{Overloaded symbol names}
8594You can specify a particular definition of an overloaded symbol, using
b37052ae 8595the same notation that is used to declare such symbols in C@t{++}: type
c906108c
SS
8596@code{@var{symbol}(@var{types})} rather than just @var{symbol}. You can
8597also use the @value{GDBN} command-line word completion facilities to list the
8598available choices, or to finish the type list for you.
8599@xref{Completion,, Command completion}, for details on how to do this.
8600@end table
c906108c 8601
b37303ee
AF
8602@node Objective-C
8603@subsection Objective-C
8604
8605@cindex Objective-C
8606This section provides information about some commands and command
8607options that are useful for debugging Objective-C code.
8608
8609@menu
b383017d
RM
8610* Method Names in Commands::
8611* The Print Command with Objective-C::
b37303ee
AF
8612@end menu
8613
8614@node Method Names in Commands, The Print Command with Objective-C, Objective-C, Objective-C
8615@subsubsection Method Names in Commands
8616
8617The following commands have been extended to accept Objective-C method
8618names as line specifications:
8619
8620@kindex clear@r{, and Objective-C}
8621@kindex break@r{, and Objective-C}
8622@kindex info line@r{, and Objective-C}
8623@kindex jump@r{, and Objective-C}
8624@kindex list@r{, and Objective-C}
8625@itemize
8626@item @code{clear}
8627@item @code{break}
8628@item @code{info line}
8629@item @code{jump}
8630@item @code{list}
8631@end itemize
8632
8633A fully qualified Objective-C method name is specified as
8634
8635@smallexample
8636-[@var{Class} @var{methodName}]
8637@end smallexample
8638
c552b3bb
JM
8639where the minus sign is used to indicate an instance method and a
8640plus sign (not shown) is used to indicate a class method. The class
8641name @var{Class} and method name @var{methodName} are enclosed in
8642brackets, similar to the way messages are specified in Objective-C
8643source code. For example, to set a breakpoint at the @code{create}
8644instance method of class @code{Fruit} in the program currently being
8645debugged, enter:
b37303ee
AF
8646
8647@smallexample
8648break -[Fruit create]
8649@end smallexample
8650
8651To list ten program lines around the @code{initialize} class method,
8652enter:
8653
8654@smallexample
8655list +[NSText initialize]
8656@end smallexample
8657
c552b3bb
JM
8658In the current version of @value{GDBN}, the plus or minus sign is
8659required. In future versions of @value{GDBN}, the plus or minus
8660sign will be optional, but you can use it to narrow the search. It
8661is also possible to specify just a method name:
b37303ee
AF
8662
8663@smallexample
8664break create
8665@end smallexample
8666
8667You must specify the complete method name, including any colons. If
8668your program's source files contain more than one @code{create} method,
8669you'll be presented with a numbered list of classes that implement that
8670method. Indicate your choice by number, or type @samp{0} to exit if
8671none apply.
8672
8673As another example, to clear a breakpoint established at the
8674@code{makeKeyAndOrderFront:} method of the @code{NSWindow} class, enter:
8675
8676@smallexample
8677clear -[NSWindow makeKeyAndOrderFront:]
8678@end smallexample
8679
8680@node The Print Command with Objective-C
8681@subsubsection The Print Command With Objective-C
c552b3bb
JM
8682@kindex print-object
8683@kindex po @r{(@code{print-object})}
b37303ee 8684
c552b3bb 8685The print command has also been extended to accept methods. For example:
b37303ee
AF
8686
8687@smallexample
c552b3bb 8688print -[@var{object} hash]
b37303ee
AF
8689@end smallexample
8690
8691@cindex print an Objective-C object description
c552b3bb
JM
8692@cindex @code{_NSPrintForDebugger}, and printing Objective-C objects
8693@noindent
8694will tell @value{GDBN} to send the @code{hash} message to @var{object}
8695and print the result. Also, an additional command has been added,
8696@code{print-object} or @code{po} for short, which is meant to print
8697the description of an object. However, this command may only work
8698with certain Objective-C libraries that have a particular hook
8699function, @code{_NSPrintForDebugger}, defined.
b37303ee 8700
e07c999f 8701@node Modula-2, Ada, Objective-C, Support
c906108c 8702@subsection Modula-2
7a292a7a 8703
d4f3574e 8704@cindex Modula-2, @value{GDBN} support
c906108c
SS
8705
8706The extensions made to @value{GDBN} to support Modula-2 only support
8707output from the @sc{gnu} Modula-2 compiler (which is currently being
8708developed). Other Modula-2 compilers are not currently supported, and
8709attempting to debug executables produced by them is most likely
8710to give an error as @value{GDBN} reads in the executable's symbol
8711table.
8712
8713@cindex expressions in Modula-2
8714@menu
8715* M2 Operators:: Built-in operators
8716* Built-In Func/Proc:: Built-in functions and procedures
8717* M2 Constants:: Modula-2 constants
8718* M2 Defaults:: Default settings for Modula-2
8719* Deviations:: Deviations from standard Modula-2
8720* M2 Checks:: Modula-2 type and range checks
8721* M2 Scope:: The scope operators @code{::} and @code{.}
8722* GDB/M2:: @value{GDBN} and Modula-2
8723@end menu
8724
6d2ebf8b 8725@node M2 Operators
c906108c
SS
8726@subsubsection Operators
8727@cindex Modula-2 operators
8728
8729Operators must be defined on values of specific types. For instance,
8730@code{+} is defined on numbers, but not on structures. Operators are
8731often defined on groups of types. For the purposes of Modula-2, the
8732following definitions hold:
8733
8734@itemize @bullet
8735
8736@item
8737@emph{Integral types} consist of @code{INTEGER}, @code{CARDINAL}, and
8738their subranges.
8739
8740@item
8741@emph{Character types} consist of @code{CHAR} and its subranges.
8742
8743@item
8744@emph{Floating-point types} consist of @code{REAL}.
8745
8746@item
8747@emph{Pointer types} consist of anything declared as @code{POINTER TO
8748@var{type}}.
8749
8750@item
8751@emph{Scalar types} consist of all of the above.
8752
8753@item
8754@emph{Set types} consist of @code{SET} and @code{BITSET} types.
8755
8756@item
8757@emph{Boolean types} consist of @code{BOOLEAN}.
8758@end itemize
8759
8760@noindent
8761The following operators are supported, and appear in order of
8762increasing precedence:
8763
8764@table @code
8765@item ,
8766Function argument or array index separator.
8767
8768@item :=
8769Assignment. The value of @var{var} @code{:=} @var{value} is
8770@var{value}.
8771
8772@item <@r{, }>
8773Less than, greater than on integral, floating-point, or enumerated
8774types.
8775
8776@item <=@r{, }>=
96a2c332 8777Less than or equal to, greater than or equal to
c906108c
SS
8778on integral, floating-point and enumerated types, or set inclusion on
8779set types. Same precedence as @code{<}.
8780
8781@item =@r{, }<>@r{, }#
8782Equality and two ways of expressing inequality, valid on scalar types.
8783Same precedence as @code{<}. In @value{GDBN} scripts, only @code{<>} is
8784available for inequality, since @code{#} conflicts with the script
8785comment character.
8786
8787@item IN
8788Set membership. Defined on set types and the types of their members.
8789Same precedence as @code{<}.
8790
8791@item OR
8792Boolean disjunction. Defined on boolean types.
8793
8794@item AND@r{, }&
d4f3574e 8795Boolean conjunction. Defined on boolean types.
c906108c
SS
8796
8797@item @@
8798The @value{GDBN} ``artificial array'' operator (@pxref{Expressions, ,Expressions}).
8799
8800@item +@r{, }-
8801Addition and subtraction on integral and floating-point types, or union
8802and difference on set types.
8803
8804@item *
8805Multiplication on integral and floating-point types, or set intersection
8806on set types.
8807
8808@item /
8809Division on floating-point types, or symmetric set difference on set
8810types. Same precedence as @code{*}.
8811
8812@item DIV@r{, }MOD
8813Integer division and remainder. Defined on integral types. Same
8814precedence as @code{*}.
8815
8816@item -
8817Negative. Defined on @code{INTEGER} and @code{REAL} data.
8818
8819@item ^
8820Pointer dereferencing. Defined on pointer types.
8821
8822@item NOT
8823Boolean negation. Defined on boolean types. Same precedence as
8824@code{^}.
8825
8826@item .
8827@code{RECORD} field selector. Defined on @code{RECORD} data. Same
8828precedence as @code{^}.
8829
8830@item []
8831Array indexing. Defined on @code{ARRAY} data. Same precedence as @code{^}.
8832
8833@item ()
8834Procedure argument list. Defined on @code{PROCEDURE} objects. Same precedence
8835as @code{^}.
8836
8837@item ::@r{, }.
8838@value{GDBN} and Modula-2 scope operators.
8839@end table
8840
8841@quotation
8842@emph{Warning:} Sets and their operations are not yet supported, so @value{GDBN}
8843treats the use of the operator @code{IN}, or the use of operators
8844@code{+}, @code{-}, @code{*}, @code{/}, @code{=}, , @code{<>}, @code{#},
8845@code{<=}, and @code{>=} on sets as an error.
8846@end quotation
8847
cb51c4e0 8848
6d2ebf8b 8849@node Built-In Func/Proc
c906108c 8850@subsubsection Built-in functions and procedures
cb51c4e0 8851@cindex Modula-2 built-ins
c906108c
SS
8852
8853Modula-2 also makes available several built-in procedures and functions.
8854In describing these, the following metavariables are used:
8855
8856@table @var
8857
8858@item a
8859represents an @code{ARRAY} variable.
8860
8861@item c
8862represents a @code{CHAR} constant or variable.
8863
8864@item i
8865represents a variable or constant of integral type.
8866
8867@item m
8868represents an identifier that belongs to a set. Generally used in the
8869same function with the metavariable @var{s}. The type of @var{s} should
8870be @code{SET OF @var{mtype}} (where @var{mtype} is the type of @var{m}).
8871
8872@item n
8873represents a variable or constant of integral or floating-point type.
8874
8875@item r
8876represents a variable or constant of floating-point type.
8877
8878@item t
8879represents a type.
8880
8881@item v
8882represents a variable.
8883
8884@item x
8885represents a variable or constant of one of many types. See the
8886explanation of the function for details.
8887@end table
8888
8889All Modula-2 built-in procedures also return a result, described below.
8890
8891@table @code
8892@item ABS(@var{n})
8893Returns the absolute value of @var{n}.
8894
8895@item CAP(@var{c})
8896If @var{c} is a lower case letter, it returns its upper case
c3f6f71d 8897equivalent, otherwise it returns its argument.
c906108c
SS
8898
8899@item CHR(@var{i})
8900Returns the character whose ordinal value is @var{i}.
8901
8902@item DEC(@var{v})
c3f6f71d 8903Decrements the value in the variable @var{v} by one. Returns the new value.
c906108c
SS
8904
8905@item DEC(@var{v},@var{i})
8906Decrements the value in the variable @var{v} by @var{i}. Returns the
8907new value.
8908
8909@item EXCL(@var{m},@var{s})
8910Removes the element @var{m} from the set @var{s}. Returns the new
8911set.
8912
8913@item FLOAT(@var{i})
8914Returns the floating point equivalent of the integer @var{i}.
8915
8916@item HIGH(@var{a})
8917Returns the index of the last member of @var{a}.
8918
8919@item INC(@var{v})
c3f6f71d 8920Increments the value in the variable @var{v} by one. Returns the new value.
c906108c
SS
8921
8922@item INC(@var{v},@var{i})
8923Increments the value in the variable @var{v} by @var{i}. Returns the
8924new value.
8925
8926@item INCL(@var{m},@var{s})
8927Adds the element @var{m} to the set @var{s} if it is not already
8928there. Returns the new set.
8929
8930@item MAX(@var{t})
8931Returns the maximum value of the type @var{t}.
8932
8933@item MIN(@var{t})
8934Returns the minimum value of the type @var{t}.
8935
8936@item ODD(@var{i})
8937Returns boolean TRUE if @var{i} is an odd number.
8938
8939@item ORD(@var{x})
8940Returns the ordinal value of its argument. For example, the ordinal
c3f6f71d
JM
8941value of a character is its @sc{ascii} value (on machines supporting the
8942@sc{ascii} character set). @var{x} must be of an ordered type, which include
c906108c
SS
8943integral, character and enumerated types.
8944
8945@item SIZE(@var{x})
8946Returns the size of its argument. @var{x} can be a variable or a type.
8947
8948@item TRUNC(@var{r})
8949Returns the integral part of @var{r}.
8950
8951@item VAL(@var{t},@var{i})
8952Returns the member of the type @var{t} whose ordinal value is @var{i}.
8953@end table
8954
8955@quotation
8956@emph{Warning:} Sets and their operations are not yet supported, so
8957@value{GDBN} treats the use of procedures @code{INCL} and @code{EXCL} as
8958an error.
8959@end quotation
8960
8961@cindex Modula-2 constants
6d2ebf8b 8962@node M2 Constants
c906108c
SS
8963@subsubsection Constants
8964
8965@value{GDBN} allows you to express the constants of Modula-2 in the following
8966ways:
8967
8968@itemize @bullet
8969
8970@item
8971Integer constants are simply a sequence of digits. When used in an
8972expression, a constant is interpreted to be type-compatible with the
8973rest of the expression. Hexadecimal integers are specified by a
8974trailing @samp{H}, and octal integers by a trailing @samp{B}.
8975
8976@item
8977Floating point constants appear as a sequence of digits, followed by a
8978decimal point and another sequence of digits. An optional exponent can
8979then be specified, in the form @samp{E@r{[}+@r{|}-@r{]}@var{nnn}}, where
8980@samp{@r{[}+@r{|}-@r{]}@var{nnn}} is the desired exponent. All of the
8981digits of the floating point constant must be valid decimal (base 10)
8982digits.
8983
8984@item
8985Character constants consist of a single character enclosed by a pair of
8986like quotes, either single (@code{'}) or double (@code{"}). They may
c3f6f71d 8987also be expressed by their ordinal value (their @sc{ascii} value, usually)
c906108c
SS
8988followed by a @samp{C}.
8989
8990@item
8991String constants consist of a sequence of characters enclosed by a
8992pair of like quotes, either single (@code{'}) or double (@code{"}).
8993Escape sequences in the style of C are also allowed. @xref{C
b37052ae 8994Constants, ,C and C@t{++} constants}, for a brief explanation of escape
c906108c
SS
8995sequences.
8996
8997@item
8998Enumerated constants consist of an enumerated identifier.
8999
9000@item
9001Boolean constants consist of the identifiers @code{TRUE} and
9002@code{FALSE}.
9003
9004@item
9005Pointer constants consist of integral values only.
9006
9007@item
9008Set constants are not yet supported.
9009@end itemize
9010
6d2ebf8b 9011@node M2 Defaults
c906108c
SS
9012@subsubsection Modula-2 defaults
9013@cindex Modula-2 defaults
9014
9015If type and range checking are set automatically by @value{GDBN}, they
9016both default to @code{on} whenever the working language changes to
d4f3574e 9017Modula-2. This happens regardless of whether you or @value{GDBN}
c906108c
SS
9018selected the working language.
9019
9020If you allow @value{GDBN} to set the language automatically, then entering
9021code compiled from a file whose name ends with @file{.mod} sets the
d4f3574e 9022working language to Modula-2. @xref{Automatically, ,Having @value{GDBN} set
c906108c
SS
9023the language automatically}, for further details.
9024
6d2ebf8b 9025@node Deviations
c906108c
SS
9026@subsubsection Deviations from standard Modula-2
9027@cindex Modula-2, deviations from
9028
9029A few changes have been made to make Modula-2 programs easier to debug.
9030This is done primarily via loosening its type strictness:
9031
9032@itemize @bullet
9033@item
9034Unlike in standard Modula-2, pointer constants can be formed by
9035integers. This allows you to modify pointer variables during
9036debugging. (In standard Modula-2, the actual address contained in a
9037pointer variable is hidden from you; it can only be modified
9038through direct assignment to another pointer variable or expression that
9039returned a pointer.)
9040
9041@item
9042C escape sequences can be used in strings and characters to represent
9043non-printable characters. @value{GDBN} prints out strings with these
9044escape sequences embedded. Single non-printable characters are
9045printed using the @samp{CHR(@var{nnn})} format.
9046
9047@item
9048The assignment operator (@code{:=}) returns the value of its right-hand
9049argument.
9050
9051@item
9052All built-in procedures both modify @emph{and} return their argument.
9053@end itemize
9054
6d2ebf8b 9055@node M2 Checks
c906108c
SS
9056@subsubsection Modula-2 type and range checks
9057@cindex Modula-2 checks
9058
9059@quotation
9060@emph{Warning:} in this release, @value{GDBN} does not yet perform type or
9061range checking.
9062@end quotation
9063@c FIXME remove warning when type/range checks added
9064
9065@value{GDBN} considers two Modula-2 variables type equivalent if:
9066
9067@itemize @bullet
9068@item
9069They are of types that have been declared equivalent via a @code{TYPE
9070@var{t1} = @var{t2}} statement
9071
9072@item
9073They have been declared on the same line. (Note: This is true of the
9074@sc{gnu} Modula-2 compiler, but it may not be true of other compilers.)
9075@end itemize
9076
9077As long as type checking is enabled, any attempt to combine variables
9078whose types are not equivalent is an error.
9079
9080Range checking is done on all mathematical operations, assignment, array
9081index bounds, and all built-in functions and procedures.
9082
6d2ebf8b 9083@node M2 Scope
c906108c
SS
9084@subsubsection The scope operators @code{::} and @code{.}
9085@cindex scope
41afff9a 9086@cindex @code{.}, Modula-2 scope operator
c906108c
SS
9087@cindex colon, doubled as scope operator
9088@ifinfo
41afff9a 9089@vindex colon-colon@r{, in Modula-2}
c906108c
SS
9090@c Info cannot handle :: but TeX can.
9091@end ifinfo
9092@iftex
41afff9a 9093@vindex ::@r{, in Modula-2}
c906108c
SS
9094@end iftex
9095
9096There are a few subtle differences between the Modula-2 scope operator
9097(@code{.}) and the @value{GDBN} scope operator (@code{::}). The two have
9098similar syntax:
9099
474c8240 9100@smallexample
c906108c
SS
9101
9102@var{module} . @var{id}
9103@var{scope} :: @var{id}
474c8240 9104@end smallexample
c906108c
SS
9105
9106@noindent
9107where @var{scope} is the name of a module or a procedure,
9108@var{module} the name of a module, and @var{id} is any declared
9109identifier within your program, except another module.
9110
9111Using the @code{::} operator makes @value{GDBN} search the scope
9112specified by @var{scope} for the identifier @var{id}. If it is not
9113found in the specified scope, then @value{GDBN} searches all scopes
9114enclosing the one specified by @var{scope}.
9115
9116Using the @code{.} operator makes @value{GDBN} search the current scope for
9117the identifier specified by @var{id} that was imported from the
9118definition module specified by @var{module}. With this operator, it is
9119an error if the identifier @var{id} was not imported from definition
9120module @var{module}, or if @var{id} is not an identifier in
9121@var{module}.
9122
6d2ebf8b 9123@node GDB/M2
c906108c
SS
9124@subsubsection @value{GDBN} and Modula-2
9125
9126Some @value{GDBN} commands have little use when debugging Modula-2 programs.
9127Five subcommands of @code{set print} and @code{show print} apply
b37052ae 9128specifically to C and C@t{++}: @samp{vtbl}, @samp{demangle},
c906108c 9129@samp{asm-demangle}, @samp{object}, and @samp{union}. The first four
b37052ae 9130apply to C@t{++}, and the last to the C @code{union} type, which has no direct
c906108c
SS
9131analogue in Modula-2.
9132
9133The @code{@@} operator (@pxref{Expressions, ,Expressions}), while available
d4f3574e 9134with any language, is not useful with Modula-2. Its
c906108c 9135intent is to aid the debugging of @dfn{dynamic arrays}, which cannot be
b37052ae 9136created in Modula-2 as they can in C or C@t{++}. However, because an
c906108c 9137address can be specified by an integral constant, the construct
d4f3574e 9138@samp{@{@var{type}@}@var{adrexp}} is still useful.
c906108c
SS
9139
9140@cindex @code{#} in Modula-2
9141In @value{GDBN} scripts, the Modula-2 inequality operator @code{#} is
9142interpreted as the beginning of a comment. Use @code{<>} instead.
c906108c 9143
e07c999f
PH
9144@node Ada
9145@subsection Ada
9146@cindex Ada
9147
9148The extensions made to @value{GDBN} for Ada only support
9149output from the @sc{gnu} Ada (GNAT) compiler.
9150Other Ada compilers are not currently supported, and
9151attempting to debug executables produced by them is most likely
9152to be difficult.
9153
9154
9155@cindex expressions in Ada
9156@menu
9157* Ada Mode Intro:: General remarks on the Ada syntax
9158 and semantics supported by Ada mode
9159 in @value{GDBN}.
9160* Omissions from Ada:: Restrictions on the Ada expression syntax.
9161* Additions to Ada:: Extensions of the Ada expression syntax.
9162* Stopping Before Main Program:: Debugging the program during elaboration.
9163* Ada Glitches:: Known peculiarities of Ada mode.
9164@end menu
9165
9166@node Ada Mode Intro
9167@subsubsection Introduction
9168@cindex Ada mode, general
9169
9170The Ada mode of @value{GDBN} supports a fairly large subset of Ada expression
9171syntax, with some extensions.
9172The philosophy behind the design of this subset is
9173
9174@itemize @bullet
9175@item
9176That @value{GDBN} should provide basic literals and access to operations for
9177arithmetic, dereferencing, field selection, indexing, and subprogram calls,
9178leaving more sophisticated computations to subprograms written into the
9179program (which therefore may be called from @value{GDBN}).
9180
9181@item
9182That type safety and strict adherence to Ada language restrictions
9183are not particularly important to the @value{GDBN} user.
9184
9185@item
9186That brevity is important to the @value{GDBN} user.
9187@end itemize
9188
9189Thus, for brevity, the debugger acts as if there were
9190implicit @code{with} and @code{use} clauses in effect for all user-written
9191packages, making it unnecessary to fully qualify most names with
9192their packages, regardless of context. Where this causes ambiguity,
9193@value{GDBN} asks the user's intent.
9194
9195The debugger will start in Ada mode if it detects an Ada main program.
9196As for other languages, it will enter Ada mode when stopped in a program that
9197was translated from an Ada source file.
9198
9199While in Ada mode, you may use `@t{--}' for comments. This is useful
9200mostly for documenting command files. The standard @value{GDBN} comment
9201(@samp{#}) still works at the beginning of a line in Ada mode, but not in the
9202middle (to allow based literals).
9203
9204The debugger supports limited overloading. Given a subprogram call in which
9205the function symbol has multiple definitions, it will use the number of
9206actual parameters and some information about their types to attempt to narrow
9207the set of definitions. It also makes very limited use of context, preferring
9208procedures to functions in the context of the @code{call} command, and
9209functions to procedures elsewhere.
9210
9211@node Omissions from Ada
9212@subsubsection Omissions from Ada
9213@cindex Ada, omissions from
9214
9215Here are the notable omissions from the subset:
9216
9217@itemize @bullet
9218@item
9219Only a subset of the attributes are supported:
9220
9221@itemize @minus
9222@item
9223@t{'First}, @t{'Last}, and @t{'Length}
9224 on array objects (not on types and subtypes).
9225
9226@item
9227@t{'Min} and @t{'Max}.
9228
9229@item
9230@t{'Pos} and @t{'Val}.
9231
9232@item
9233@t{'Tag}.
9234
9235@item
9236@t{'Range} on array objects (not subtypes), but only as the right
9237operand of the membership (@code{in}) operator.
9238
9239@item
9240@t{'Access}, @t{'Unchecked_Access}, and
9241@t{'Unrestricted_Access} (a GNAT extension).
9242
9243@item
9244@t{'Address}.
9245@end itemize
9246
9247@item
9248The names in
9249@code{Characters.Latin_1} are not available and
9250concatenation is not implemented. Thus, escape characters in strings are
9251not currently available.
9252
9253@item
9254Equality tests (@samp{=} and @samp{/=}) on arrays test for bitwise
9255equality of representations. They will generally work correctly
9256for strings and arrays whose elements have integer or enumeration types.
9257They may not work correctly for arrays whose element
9258types have user-defined equality, for arrays of real values
9259(in particular, IEEE-conformant floating point, because of negative
9260zeroes and NaNs), and for arrays whose elements contain unused bits with
9261indeterminate values.
9262
9263@item
9264The other component-by-component array operations (@code{and}, @code{or},
9265@code{xor}, @code{not}, and relational tests other than equality)
9266are not implemented.
9267
9268@item
9269There are no record or array aggregates.
9270
9271@item
9272Calls to dispatching subprograms are not implemented.
9273
9274@item
9275The overloading algorithm is much more limited (i.e., less selective)
9276than that of real Ada. It makes only limited use of the context in which a subexpression
9277appears to resolve its meaning, and it is much looser in its rules for allowing
9278type matches. As a result, some function calls will be ambiguous, and the user
9279will be asked to choose the proper resolution.
9280
9281@item
9282The @code{new} operator is not implemented.
9283
9284@item
9285Entry calls are not implemented.
9286
9287@item
9288Aside from printing, arithmetic operations on the native VAX floating-point
9289formats are not supported.
9290
9291@item
9292It is not possible to slice a packed array.
9293@end itemize
9294
9295@node Additions to Ada
9296@subsubsection Additions to Ada
9297@cindex Ada, deviations from
9298
9299As it does for other languages, @value{GDBN} makes certain generic
9300extensions to Ada (@pxref{Expressions}):
9301
9302@itemize @bullet
9303@item
9304If the expression @var{E} is a variable residing in memory
9305(typically a local variable or array element) and @var{N} is
9306a positive integer, then @code{@var{E}@@@var{N}} displays the values of
9307@var{E} and the @var{N}-1 adjacent variables following it in memory as an array.
9308In Ada, this operator is generally not necessary, since its prime use
9309is in displaying parts of an array, and slicing will usually do this in Ada.
9310However, there are occasional uses when debugging programs
9311in which certain debugging information has been optimized away.
9312
9313@item
9314@code{@var{B}::@var{var}} means ``the variable named @var{var} that appears
9315in function or file @var{B}.'' When @var{B} is a file name, you must typically
9316surround it in single quotes.
9317
9318@item
9319The expression @code{@{@var{type}@} @var{addr}} means ``the variable of type
9320@var{type} that appears at address @var{addr}.''
9321
9322@item
9323A name starting with @samp{$} is a convenience variable
9324(@pxref{Convenience Vars}) or a machine register (@pxref{Registers}).
9325@end itemize
9326
9327In addition, @value{GDBN} provides a few other shortcuts and outright additions specific
9328to Ada:
9329
9330@itemize @bullet
9331@item
9332The assignment statement is allowed as an expression, returning
9333its right-hand operand as its value. Thus, you may enter
9334
9335@smallexample
9336set x := y + 3
9337print A(tmp := y + 1)
9338@end smallexample
9339
9340@item
9341The semicolon is allowed as an ``operator,'' returning as its value
9342the value of its right-hand operand.
9343This allows, for example,
9344complex conditional breaks:
9345
9346@smallexample
9347break f
9348condition 1 (report(i); k += 1; A(k) > 100)
9349@end smallexample
9350
9351@item
9352Rather than use catenation and symbolic character names to introduce special
9353characters into strings, one may instead use a special bracket notation,
9354which is also used to print strings. A sequence of characters of the form
9355@samp{["@var{XX}"]} within a string or character literal denotes the
9356(single) character whose numeric encoding is @var{XX} in hexadecimal. The
9357sequence of characters @samp{["""]} also denotes a single quotation mark
9358in strings. For example,
9359@smallexample
9360 "One line.["0a"]Next line.["0a"]"
9361@end smallexample
9362@noindent
9363contains an ASCII newline character (@code{Ada.Characters.Latin_1.LF}) after each
9364period.
9365
9366@item
9367The subtype used as a prefix for the attributes @t{'Pos}, @t{'Min}, and
9368@t{'Max} is optional (and is ignored in any case). For example, it is valid
9369to write
9370
9371@smallexample
9372print 'max(x, y)
9373@end smallexample
9374
9375@item
9376When printing arrays, @value{GDBN} uses positional notation when the
9377array has a lower bound of 1, and uses a modified named notation otherwise.
9378For example, a one-dimensional array of three integers with a lower bound of 3 might print as
9379
9380@smallexample
9381(3 => 10, 17, 1)
9382@end smallexample
9383
9384@noindent
9385That is, in contrast to valid Ada, only the first component has a @code{=>}
9386clause.
9387
9388@item
9389You may abbreviate attributes in expressions with any unique,
9390multi-character subsequence of
9391their names (an exact match gets preference).
9392For example, you may use @t{a'len}, @t{a'gth}, or @t{a'lh}
9393in place of @t{a'length}.
9394
9395@item
9396@cindex quoting Ada internal identifiers
9397Since Ada is case-insensitive, the debugger normally maps identifiers you type
9398to lower case. The GNAT compiler uses upper-case characters for
9399some of its internal identifiers, which are normally of no interest to users.
9400For the rare occasions when you actually have to look at them,
9401enclose them in angle brackets to avoid the lower-case mapping.
9402For example,
9403@smallexample
9404@value{GDBP} print <JMPBUF_SAVE>[0]
9405@end smallexample
9406
9407@item
9408Printing an object of class-wide type or dereferencing an
9409access-to-class-wide value will display all the components of the object's
9410specific type (as indicated by its run-time tag). Likewise, component
9411selection on such a value will operate on the specific type of the
9412object.
9413
9414@end itemize
9415
9416@node Stopping Before Main Program
9417@subsubsection Stopping at the Very Beginning
9418
9419@cindex breakpointing Ada elaboration code
9420It is sometimes necessary to debug the program during elaboration, and
9421before reaching the main procedure.
9422As defined in the Ada Reference
9423Manual, the elaboration code is invoked from a procedure called
9424@code{adainit}. To run your program up to the beginning of
9425elaboration, simply use the following two commands:
9426@code{tbreak adainit} and @code{run}.
9427
9428@node Ada Glitches
9429@subsubsection Known Peculiarities of Ada Mode
9430@cindex Ada, problems
9431
9432Besides the omissions listed previously (@pxref{Omissions from Ada}),
9433we know of several problems with and limitations of Ada mode in
9434@value{GDBN},
9435some of which will be fixed with planned future releases of the debugger
9436and the GNU Ada compiler.
9437
9438@itemize @bullet
9439@item
9440Currently, the debugger
9441has insufficient information to determine whether certain pointers represent
9442pointers to objects or the objects themselves.
9443Thus, the user may have to tack an extra @code{.all} after an expression
9444to get it printed properly.
9445
9446@item
9447Static constants that the compiler chooses not to materialize as objects in
9448storage are invisible to the debugger.
9449
9450@item
9451Named parameter associations in function argument lists are ignored (the
9452argument lists are treated as positional).
9453
9454@item
9455Many useful library packages are currently invisible to the debugger.
9456
9457@item
9458Fixed-point arithmetic, conversions, input, and output is carried out using
9459floating-point arithmetic, and may give results that only approximate those on
9460the host machine.
9461
9462@item
9463The type of the @t{'Address} attribute may not be @code{System.Address}.
9464
9465@item
9466The GNAT compiler never generates the prefix @code{Standard} for any of
9467the standard symbols defined by the Ada language. @value{GDBN} knows about
9468this: it will strip the prefix from names when you use it, and will never
9469look for a name you have so qualified among local symbols, nor match against
9470symbols in other packages or subprograms. If you have
9471defined entities anywhere in your program other than parameters and
9472local variables whose simple names match names in @code{Standard},
9473GNAT's lack of qualification here can cause confusion. When this happens,
9474you can usually resolve the confusion
9475by qualifying the problematic names with package
9476@code{Standard} explicitly.
9477@end itemize
9478
4e562065
JB
9479@node Unsupported languages
9480@section Unsupported languages
9481
9482@cindex unsupported languages
9483@cindex minimal language
9484In addition to the other fully-supported programming languages,
9485@value{GDBN} also provides a pseudo-language, called @code{minimal}.
9486It does not represent a real programming language, but provides a set
9487of capabilities close to what the C or assembly languages provide.
9488This should allow most simple operations to be performed while debugging
9489an application that uses a language currently not supported by @value{GDBN}.
9490
9491If the language is set to @code{auto}, @value{GDBN} will automatically
9492select this language if the current frame corresponds to an unsupported
9493language.
9494
6d2ebf8b 9495@node Symbols
c906108c
SS
9496@chapter Examining the Symbol Table
9497
d4f3574e 9498The commands described in this chapter allow you to inquire about the
c906108c
SS
9499symbols (names of variables, functions and types) defined in your
9500program. This information is inherent in the text of your program and
9501does not change as your program executes. @value{GDBN} finds it in your
9502program's symbol table, in the file indicated when you started @value{GDBN}
9503(@pxref{File Options, ,Choosing files}), or by one of the
9504file-management commands (@pxref{Files, ,Commands to specify files}).
9505
9506@cindex symbol names
9507@cindex names of symbols
9508@cindex quoting names
9509Occasionally, you may need to refer to symbols that contain unusual
9510characters, which @value{GDBN} ordinarily treats as word delimiters. The
9511most frequent case is in referring to static variables in other
9512source files (@pxref{Variables,,Program variables}). File names
9513are recorded in object files as debugging symbols, but @value{GDBN} would
9514ordinarily parse a typical file name, like @file{foo.c}, as the three words
9515@samp{foo} @samp{.} @samp{c}. To allow @value{GDBN} to recognize
9516@samp{foo.c} as a single symbol, enclose it in single quotes; for example,
9517
474c8240 9518@smallexample
c906108c 9519p 'foo.c'::x
474c8240 9520@end smallexample
c906108c
SS
9521
9522@noindent
9523looks up the value of @code{x} in the scope of the file @file{foo.c}.
9524
9525@table @code
9526@kindex info address
b37052ae 9527@cindex address of a symbol
c906108c
SS
9528@item info address @var{symbol}
9529Describe where the data for @var{symbol} is stored. For a register
9530variable, this says which register it is kept in. For a non-register
9531local variable, this prints the stack-frame offset at which the variable
9532is always stored.
9533
9534Note the contrast with @samp{print &@var{symbol}}, which does not work
9535at all for a register variable, and for a stack local variable prints
9536the exact address of the current instantiation of the variable.
9537
3d67e040 9538@kindex info symbol
b37052ae 9539@cindex symbol from address
3d67e040
EZ
9540@item info symbol @var{addr}
9541Print the name of a symbol which is stored at the address @var{addr}.
9542If no symbol is stored exactly at @var{addr}, @value{GDBN} prints the
9543nearest symbol and an offset from it:
9544
474c8240 9545@smallexample
3d67e040
EZ
9546(@value{GDBP}) info symbol 0x54320
9547_initialize_vx + 396 in section .text
474c8240 9548@end smallexample
3d67e040
EZ
9549
9550@noindent
9551This is the opposite of the @code{info address} command. You can use
9552it to find out the name of a variable or a function given its address.
9553
c906108c 9554@kindex whatis
d4f3574e
SS
9555@item whatis @var{expr}
9556Print the data type of expression @var{expr}. @var{expr} is not
c906108c
SS
9557actually evaluated, and any side-effecting operations (such as
9558assignments or function calls) inside it do not take place.
9559@xref{Expressions, ,Expressions}.
9560
9561@item whatis
9562Print the data type of @code{$}, the last value in the value history.
9563
9564@kindex ptype
9565@item ptype @var{typename}
9566Print a description of data type @var{typename}. @var{typename} may be
7a292a7a
SS
9567the name of a type, or for C code it may have the form @samp{class
9568@var{class-name}}, @samp{struct @var{struct-tag}}, @samp{union
9569@var{union-tag}} or @samp{enum @var{enum-tag}}.
c906108c 9570
d4f3574e 9571@item ptype @var{expr}
c906108c 9572@itemx ptype
d4f3574e 9573Print a description of the type of expression @var{expr}. @code{ptype}
c906108c
SS
9574differs from @code{whatis} by printing a detailed description, instead
9575of just the name of the type.
9576
9577For example, for this variable declaration:
9578
474c8240 9579@smallexample
c906108c 9580struct complex @{double real; double imag;@} v;
474c8240 9581@end smallexample
c906108c
SS
9582
9583@noindent
9584the two commands give this output:
9585
474c8240 9586@smallexample
c906108c
SS
9587@group
9588(@value{GDBP}) whatis v
9589type = struct complex
9590(@value{GDBP}) ptype v
9591type = struct complex @{
9592 double real;
9593 double imag;
9594@}
9595@end group
474c8240 9596@end smallexample
c906108c
SS
9597
9598@noindent
9599As with @code{whatis}, using @code{ptype} without an argument refers to
9600the type of @code{$}, the last value in the value history.
9601
9602@kindex info types
9603@item info types @var{regexp}
9604@itemx info types
d4f3574e 9605Print a brief description of all types whose names match @var{regexp}
c906108c
SS
9606(or all types in your program, if you supply no argument). Each
9607complete typename is matched as though it were a complete line; thus,
9608@samp{i type value} gives information on all types in your program whose
d4f3574e 9609names include the string @code{value}, but @samp{i type ^value$} gives
c906108c
SS
9610information only on types whose complete name is @code{value}.
9611
9612This command differs from @code{ptype} in two ways: first, like
9613@code{whatis}, it does not print a detailed description; second, it
9614lists all source files where a type is defined.
9615
b37052ae
EZ
9616@kindex info scope
9617@cindex local variables
9618@item info scope @var{addr}
9619List all the variables local to a particular scope. This command
9620accepts a location---a function name, a source line, or an address
9621preceded by a @samp{*}, and prints all the variables local to the
9622scope defined by that location. For example:
9623
9624@smallexample
9625(@value{GDBP}) @b{info scope command_line_handler}
9626Scope for command_line_handler:
9627Symbol rl is an argument at stack/frame offset 8, length 4.
9628Symbol linebuffer is in static storage at address 0x150a18, length 4.
9629Symbol linelength is in static storage at address 0x150a1c, length 4.
9630Symbol p is a local variable in register $esi, length 4.
9631Symbol p1 is a local variable in register $ebx, length 4.
9632Symbol nline is a local variable in register $edx, length 4.
9633Symbol repeat is a local variable at frame offset -8, length 4.
9634@end smallexample
9635
f5c37c66
EZ
9636@noindent
9637This command is especially useful for determining what data to collect
9638during a @dfn{trace experiment}, see @ref{Tracepoint Actions,
9639collect}.
9640
c906108c
SS
9641@kindex info source
9642@item info source
919d772c
JB
9643Show information about the current source file---that is, the source file for
9644the function containing the current point of execution:
9645@itemize @bullet
9646@item
9647the name of the source file, and the directory containing it,
9648@item
9649the directory it was compiled in,
9650@item
9651its length, in lines,
9652@item
9653which programming language it is written in,
9654@item
9655whether the executable includes debugging information for that file, and
9656if so, what format the information is in (e.g., STABS, Dwarf 2, etc.), and
9657@item
9658whether the debugging information includes information about
9659preprocessor macros.
9660@end itemize
9661
c906108c
SS
9662
9663@kindex info sources
9664@item info sources
9665Print the names of all source files in your program for which there is
9666debugging information, organized into two lists: files whose symbols
9667have already been read, and files whose symbols will be read when needed.
9668
9669@kindex info functions
9670@item info functions
9671Print the names and data types of all defined functions.
9672
9673@item info functions @var{regexp}
9674Print the names and data types of all defined functions
9675whose names contain a match for regular expression @var{regexp}.
9676Thus, @samp{info fun step} finds all functions whose names
9677include @code{step}; @samp{info fun ^step} finds those whose names
b383017d
RM
9678start with @code{step}. If a function name contains characters
9679that conflict with the regular expression language (eg.
1c5dfdad 9680@samp{operator*()}), they may be quoted with a backslash.
c906108c
SS
9681
9682@kindex info variables
9683@item info variables
9684Print the names and data types of all variables that are declared
6ca652b0 9685outside of functions (i.e.@: excluding local variables).
c906108c
SS
9686
9687@item info variables @var{regexp}
9688Print the names and data types of all variables (except for local
9689variables) whose names contain a match for regular expression
9690@var{regexp}.
9691
b37303ee
AF
9692@kindex info classes
9693@item info classes
9694@itemx info classes @var{regexp}
9695Display all Objective-C classes in your program, or
9696(with the @var{regexp} argument) all those matching a particular regular
9697expression.
9698
9699@kindex info selectors
9700@item info selectors
9701@itemx info selectors @var{regexp}
9702Display all Objective-C selectors in your program, or
9703(with the @var{regexp} argument) all those matching a particular regular
9704expression.
9705
c906108c
SS
9706@ignore
9707This was never implemented.
9708@kindex info methods
9709@item info methods
9710@itemx info methods @var{regexp}
9711The @code{info methods} command permits the user to examine all defined
b37052ae
EZ
9712methods within C@t{++} program, or (with the @var{regexp} argument) a
9713specific set of methods found in the various C@t{++} classes. Many
9714C@t{++} classes provide a large number of methods. Thus, the output
c906108c
SS
9715from the @code{ptype} command can be overwhelming and hard to use. The
9716@code{info-methods} command filters the methods, printing only those
9717which match the regular-expression @var{regexp}.
9718@end ignore
9719
c906108c
SS
9720@cindex reloading symbols
9721Some systems allow individual object files that make up your program to
7a292a7a
SS
9722be replaced without stopping and restarting your program. For example,
9723in VxWorks you can simply recompile a defective object file and keep on
9724running. If you are running on one of these systems, you can allow
9725@value{GDBN} to reload the symbols for automatically relinked modules:
c906108c
SS
9726
9727@table @code
9728@kindex set symbol-reloading
9729@item set symbol-reloading on
9730Replace symbol definitions for the corresponding source file when an
9731object file with a particular name is seen again.
9732
9733@item set symbol-reloading off
6d2ebf8b
SS
9734Do not replace symbol definitions when encountering object files of the
9735same name more than once. This is the default state; if you are not
9736running on a system that permits automatic relinking of modules, you
9737should leave @code{symbol-reloading} off, since otherwise @value{GDBN}
9738may discard symbols when linking large programs, that may contain
9739several modules (from different directories or libraries) with the same
9740name.
c906108c
SS
9741
9742@kindex show symbol-reloading
9743@item show symbol-reloading
9744Show the current @code{on} or @code{off} setting.
9745@end table
c906108c 9746
c906108c
SS
9747@kindex set opaque-type-resolution
9748@item set opaque-type-resolution on
9749Tell @value{GDBN} to resolve opaque types. An opaque type is a type
9750declared as a pointer to a @code{struct}, @code{class}, or
9751@code{union}---for example, @code{struct MyType *}---that is used in one
9752source file although the full declaration of @code{struct MyType} is in
9753another source file. The default is on.
9754
9755A change in the setting of this subcommand will not take effect until
9756the next time symbols for a file are loaded.
9757
9758@item set opaque-type-resolution off
9759Tell @value{GDBN} not to resolve opaque types. In this case, the type
9760is printed as follows:
9761@smallexample
9762@{<no data fields>@}
9763@end smallexample
9764
9765@kindex show opaque-type-resolution
9766@item show opaque-type-resolution
9767Show whether opaque types are resolved or not.
c906108c
SS
9768
9769@kindex maint print symbols
9770@cindex symbol dump
9771@kindex maint print psymbols
9772@cindex partial symbol dump
9773@item maint print symbols @var{filename}
9774@itemx maint print psymbols @var{filename}
9775@itemx maint print msymbols @var{filename}
9776Write a dump of debugging symbol data into the file @var{filename}.
9777These commands are used to debug the @value{GDBN} symbol-reading code. Only
9778symbols with debugging data are included. If you use @samp{maint print
9779symbols}, @value{GDBN} includes all the symbols for which it has already
9780collected full details: that is, @var{filename} reflects symbols for
9781only those files whose symbols @value{GDBN} has read. You can use the
9782command @code{info sources} to find out which files these are. If you
9783use @samp{maint print psymbols} instead, the dump shows information about
9784symbols that @value{GDBN} only knows partially---that is, symbols defined in
9785files that @value{GDBN} has skimmed, but not yet read completely. Finally,
9786@samp{maint print msymbols} dumps just the minimal symbol information
9787required for each object file from which @value{GDBN} has read some symbols.
9788@xref{Files, ,Commands to specify files}, for a discussion of how
9789@value{GDBN} reads symbols (in the description of @code{symbol-file}).
44ea7b70 9790
5e7b2f39
JB
9791@kindex maint info symtabs
9792@kindex maint info psymtabs
44ea7b70
JB
9793@cindex listing @value{GDBN}'s internal symbol tables
9794@cindex symbol tables, listing @value{GDBN}'s internal
9795@cindex full symbol tables, listing @value{GDBN}'s internal
9796@cindex partial symbol tables, listing @value{GDBN}'s internal
5e7b2f39
JB
9797@item maint info symtabs @r{[} @var{regexp} @r{]}
9798@itemx maint info psymtabs @r{[} @var{regexp} @r{]}
44ea7b70
JB
9799
9800List the @code{struct symtab} or @code{struct partial_symtab}
9801structures whose names match @var{regexp}. If @var{regexp} is not
9802given, list them all. The output includes expressions which you can
9803copy into a @value{GDBN} debugging this one to examine a particular
9804structure in more detail. For example:
9805
9806@smallexample
5e7b2f39 9807(@value{GDBP}) maint info psymtabs dwarf2read
44ea7b70
JB
9808@{ objfile /home/gnu/build/gdb/gdb
9809 ((struct objfile *) 0x82e69d0)
b383017d 9810 @{ psymtab /home/gnu/src/gdb/dwarf2read.c
44ea7b70
JB
9811 ((struct partial_symtab *) 0x8474b10)
9812 readin no
9813 fullname (null)
9814 text addresses 0x814d3c8 -- 0x8158074
9815 globals (* (struct partial_symbol **) 0x8507a08 @@ 9)
9816 statics (* (struct partial_symbol **) 0x40e95b78 @@ 2882)
9817 dependencies (none)
9818 @}
9819@}
5e7b2f39 9820(@value{GDBP}) maint info symtabs
44ea7b70
JB
9821(@value{GDBP})
9822@end smallexample
9823@noindent
9824We see that there is one partial symbol table whose filename contains
9825the string @samp{dwarf2read}, belonging to the @samp{gdb} executable;
9826and we see that @value{GDBN} has not read in any symtabs yet at all.
9827If we set a breakpoint on a function, that will cause @value{GDBN} to
9828read the symtab for the compilation unit containing that function:
9829
9830@smallexample
9831(@value{GDBP}) break dwarf2_psymtab_to_symtab
9832Breakpoint 1 at 0x814e5da: file /home/gnu/src/gdb/dwarf2read.c,
9833line 1574.
5e7b2f39 9834(@value{GDBP}) maint info symtabs
b383017d 9835@{ objfile /home/gnu/build/gdb/gdb
44ea7b70 9836 ((struct objfile *) 0x82e69d0)
b383017d 9837 @{ symtab /home/gnu/src/gdb/dwarf2read.c
44ea7b70
JB
9838 ((struct symtab *) 0x86c1f38)
9839 dirname (null)
9840 fullname (null)
9841 blockvector ((struct blockvector *) 0x86c1bd0) (primary)
9842 debugformat DWARF 2
9843 @}
9844@}
b383017d 9845(@value{GDBP})
44ea7b70 9846@end smallexample
c906108c
SS
9847@end table
9848
44ea7b70 9849
6d2ebf8b 9850@node Altering
c906108c
SS
9851@chapter Altering Execution
9852
9853Once you think you have found an error in your program, you might want to
9854find out for certain whether correcting the apparent error would lead to
9855correct results in the rest of the run. You can find the answer by
9856experiment, using the @value{GDBN} features for altering execution of the
9857program.
9858
9859For example, you can store new values into variables or memory
7a292a7a
SS
9860locations, give your program a signal, restart it at a different
9861address, or even return prematurely from a function.
c906108c
SS
9862
9863@menu
9864* Assignment:: Assignment to variables
9865* Jumping:: Continuing at a different address
c906108c 9866* Signaling:: Giving your program a signal
c906108c
SS
9867* Returning:: Returning from a function
9868* Calling:: Calling your program's functions
9869* Patching:: Patching your program
9870@end menu
9871
6d2ebf8b 9872@node Assignment
c906108c
SS
9873@section Assignment to variables
9874
9875@cindex assignment
9876@cindex setting variables
9877To alter the value of a variable, evaluate an assignment expression.
9878@xref{Expressions, ,Expressions}. For example,
9879
474c8240 9880@smallexample
c906108c 9881print x=4
474c8240 9882@end smallexample
c906108c
SS
9883
9884@noindent
9885stores the value 4 into the variable @code{x}, and then prints the
5d161b24 9886value of the assignment expression (which is 4).
c906108c
SS
9887@xref{Languages, ,Using @value{GDBN} with Different Languages}, for more
9888information on operators in supported languages.
c906108c
SS
9889
9890@kindex set variable
9891@cindex variables, setting
9892If you are not interested in seeing the value of the assignment, use the
9893@code{set} command instead of the @code{print} command. @code{set} is
9894really the same as @code{print} except that the expression's value is
9895not printed and is not put in the value history (@pxref{Value History,
9896,Value history}). The expression is evaluated only for its effects.
9897
c906108c
SS
9898If the beginning of the argument string of the @code{set} command
9899appears identical to a @code{set} subcommand, use the @code{set
9900variable} command instead of just @code{set}. This command is identical
9901to @code{set} except for its lack of subcommands. For example, if your
9902program has a variable @code{width}, you get an error if you try to set
9903a new value with just @samp{set width=13}, because @value{GDBN} has the
9904command @code{set width}:
9905
474c8240 9906@smallexample
c906108c
SS
9907(@value{GDBP}) whatis width
9908type = double
9909(@value{GDBP}) p width
9910$4 = 13
9911(@value{GDBP}) set width=47
9912Invalid syntax in expression.
474c8240 9913@end smallexample
c906108c
SS
9914
9915@noindent
9916The invalid expression, of course, is @samp{=47}. In
9917order to actually set the program's variable @code{width}, use
9918
474c8240 9919@smallexample
c906108c 9920(@value{GDBP}) set var width=47
474c8240 9921@end smallexample
53a5351d 9922
c906108c
SS
9923Because the @code{set} command has many subcommands that can conflict
9924with the names of program variables, it is a good idea to use the
9925@code{set variable} command instead of just @code{set}. For example, if
9926your program has a variable @code{g}, you run into problems if you try
9927to set a new value with just @samp{set g=4}, because @value{GDBN} has
9928the command @code{set gnutarget}, abbreviated @code{set g}:
9929
474c8240 9930@smallexample
c906108c
SS
9931@group
9932(@value{GDBP}) whatis g
9933type = double
9934(@value{GDBP}) p g
9935$1 = 1
9936(@value{GDBP}) set g=4
2df3850c 9937(@value{GDBP}) p g
c906108c
SS
9938$2 = 1
9939(@value{GDBP}) r
9940The program being debugged has been started already.
9941Start it from the beginning? (y or n) y
9942Starting program: /home/smith/cc_progs/a.out
6d2ebf8b
SS
9943"/home/smith/cc_progs/a.out": can't open to read symbols:
9944 Invalid bfd target.
c906108c
SS
9945(@value{GDBP}) show g
9946The current BFD target is "=4".
9947@end group
474c8240 9948@end smallexample
c906108c
SS
9949
9950@noindent
9951The program variable @code{g} did not change, and you silently set the
9952@code{gnutarget} to an invalid value. In order to set the variable
9953@code{g}, use
9954
474c8240 9955@smallexample
c906108c 9956(@value{GDBP}) set var g=4
474c8240 9957@end smallexample
c906108c
SS
9958
9959@value{GDBN} allows more implicit conversions in assignments than C; you can
9960freely store an integer value into a pointer variable or vice versa,
9961and you can convert any structure to any other structure that is the
9962same length or shorter.
9963@comment FIXME: how do structs align/pad in these conversions?
9964@comment /doc@cygnus.com 18dec1990
9965
9966To store values into arbitrary places in memory, use the @samp{@{@dots{}@}}
9967construct to generate a value of specified type at a specified address
9968(@pxref{Expressions, ,Expressions}). For example, @code{@{int@}0x83040} refers
9969to memory location @code{0x83040} as an integer (which implies a certain size
9970and representation in memory), and
9971
474c8240 9972@smallexample
c906108c 9973set @{int@}0x83040 = 4
474c8240 9974@end smallexample
c906108c
SS
9975
9976@noindent
9977stores the value 4 into that memory location.
9978
6d2ebf8b 9979@node Jumping
c906108c
SS
9980@section Continuing at a different address
9981
9982Ordinarily, when you continue your program, you do so at the place where
9983it stopped, with the @code{continue} command. You can instead continue at
9984an address of your own choosing, with the following commands:
9985
9986@table @code
9987@kindex jump
9988@item jump @var{linespec}
9989Resume execution at line @var{linespec}. Execution stops again
9990immediately if there is a breakpoint there. @xref{List, ,Printing
9991source lines}, for a description of the different forms of
9992@var{linespec}. It is common practice to use the @code{tbreak} command
9993in conjunction with @code{jump}. @xref{Set Breaks, ,Setting
9994breakpoints}.
9995
9996The @code{jump} command does not change the current stack frame, or
9997the stack pointer, or the contents of any memory location or any
9998register other than the program counter. If line @var{linespec} is in
9999a different function from the one currently executing, the results may
10000be bizarre if the two functions expect different patterns of arguments or
10001of local variables. For this reason, the @code{jump} command requests
10002confirmation if the specified line is not in the function currently
10003executing. However, even bizarre results are predictable if you are
10004well acquainted with the machine-language code of your program.
10005
10006@item jump *@var{address}
10007Resume execution at the instruction at address @var{address}.
10008@end table
10009
c906108c 10010@c Doesn't work on HP-UX; have to set $pcoqh and $pcoqt.
53a5351d
JM
10011On many systems, you can get much the same effect as the @code{jump}
10012command by storing a new value into the register @code{$pc}. The
10013difference is that this does not start your program running; it only
10014changes the address of where it @emph{will} run when you continue. For
10015example,
c906108c 10016
474c8240 10017@smallexample
c906108c 10018set $pc = 0x485
474c8240 10019@end smallexample
c906108c
SS
10020
10021@noindent
10022makes the next @code{continue} command or stepping command execute at
10023address @code{0x485}, rather than at the address where your program stopped.
10024@xref{Continuing and Stepping, ,Continuing and stepping}.
c906108c
SS
10025
10026The most common occasion to use the @code{jump} command is to back
10027up---perhaps with more breakpoints set---over a portion of a program
10028that has already executed, in order to examine its execution in more
10029detail.
10030
c906108c 10031@c @group
6d2ebf8b 10032@node Signaling
c906108c
SS
10033@section Giving your program a signal
10034
10035@table @code
10036@kindex signal
10037@item signal @var{signal}
10038Resume execution where your program stopped, but immediately give it the
10039signal @var{signal}. @var{signal} can be the name or the number of a
10040signal. For example, on many systems @code{signal 2} and @code{signal
10041SIGINT} are both ways of sending an interrupt signal.
10042
10043Alternatively, if @var{signal} is zero, continue execution without
10044giving a signal. This is useful when your program stopped on account of
10045a signal and would ordinary see the signal when resumed with the
10046@code{continue} command; @samp{signal 0} causes it to resume without a
10047signal.
10048
10049@code{signal} does not repeat when you press @key{RET} a second time
10050after executing the command.
10051@end table
10052@c @end group
10053
10054Invoking the @code{signal} command is not the same as invoking the
10055@code{kill} utility from the shell. Sending a signal with @code{kill}
10056causes @value{GDBN} to decide what to do with the signal depending on
10057the signal handling tables (@pxref{Signals}). The @code{signal} command
10058passes the signal directly to your program.
10059
c906108c 10060
6d2ebf8b 10061@node Returning
c906108c
SS
10062@section Returning from a function
10063
10064@table @code
10065@cindex returning from a function
10066@kindex return
10067@item return
10068@itemx return @var{expression}
10069You can cancel execution of a function call with the @code{return}
10070command. If you give an
10071@var{expression} argument, its value is used as the function's return
10072value.
10073@end table
10074
10075When you use @code{return}, @value{GDBN} discards the selected stack frame
10076(and all frames within it). You can think of this as making the
10077discarded frame return prematurely. If you wish to specify a value to
10078be returned, give that value as the argument to @code{return}.
10079
10080This pops the selected stack frame (@pxref{Selection, ,Selecting a
10081frame}), and any other frames inside of it, leaving its caller as the
10082innermost remaining frame. That frame becomes selected. The
10083specified value is stored in the registers used for returning values
10084of functions.
10085
10086The @code{return} command does not resume execution; it leaves the
10087program stopped in the state that would exist if the function had just
10088returned. In contrast, the @code{finish} command (@pxref{Continuing
10089and Stepping, ,Continuing and stepping}) resumes execution until the
10090selected stack frame returns naturally.
10091
6d2ebf8b 10092@node Calling
c906108c
SS
10093@section Calling program functions
10094
f8568604 10095@table @code
c906108c 10096@cindex calling functions
f8568604
EZ
10097@cindex inferior functions, calling
10098@item print @var{expr}
10099Evaluate the expression @var{expr} and displaying the resuling value.
10100@var{expr} may include calls to functions in the program being
10101debugged.
10102
c906108c 10103@kindex call
c906108c
SS
10104@item call @var{expr}
10105Evaluate the expression @var{expr} without displaying @code{void}
10106returned values.
c906108c
SS
10107
10108You can use this variant of the @code{print} command if you want to
f8568604
EZ
10109execute a function from your program that does not return anything
10110(a.k.a.@: @dfn{a void function}), but without cluttering the output
10111with @code{void} returned values that @value{GDBN} will otherwise
10112print. If the result is not void, it is printed and saved in the
10113value history.
10114@end table
10115
10116@cindex weak alias functions
10117Sometimes, a function you wish to call is actually a @dfn{weak alias}
10118for another function. In such case, @value{GDBN} might not pick up
10119the type information, including the types of the function arguments,
10120which causes @value{GDBN} to call the inferior function incorrectly.
10121As a result, the called function will function erroneously and may
10122even crash. A solution to that is to use the name of the aliased
10123function instead.
c906108c 10124
6d2ebf8b 10125@node Patching
c906108c 10126@section Patching programs
7a292a7a 10127
c906108c
SS
10128@cindex patching binaries
10129@cindex writing into executables
c906108c 10130@cindex writing into corefiles
c906108c 10131
7a292a7a
SS
10132By default, @value{GDBN} opens the file containing your program's
10133executable code (or the corefile) read-only. This prevents accidental
10134alterations to machine code; but it also prevents you from intentionally
10135patching your program's binary.
c906108c
SS
10136
10137If you'd like to be able to patch the binary, you can specify that
10138explicitly with the @code{set write} command. For example, you might
10139want to turn on internal debugging flags, or even to make emergency
10140repairs.
10141
10142@table @code
10143@kindex set write
10144@item set write on
10145@itemx set write off
7a292a7a
SS
10146If you specify @samp{set write on}, @value{GDBN} opens executable and
10147core files for both reading and writing; if you specify @samp{set write
c906108c
SS
10148off} (the default), @value{GDBN} opens them read-only.
10149
10150If you have already loaded a file, you must load it again (using the
7a292a7a
SS
10151@code{exec-file} or @code{core-file} command) after changing @code{set
10152write}, for your new setting to take effect.
c906108c
SS
10153
10154@item show write
10155@kindex show write
7a292a7a
SS
10156Display whether executable files and core files are opened for writing
10157as well as reading.
c906108c
SS
10158@end table
10159
6d2ebf8b 10160@node GDB Files
c906108c
SS
10161@chapter @value{GDBN} Files
10162
7a292a7a
SS
10163@value{GDBN} needs to know the file name of the program to be debugged,
10164both in order to read its symbol table and in order to start your
10165program. To debug a core dump of a previous run, you must also tell
10166@value{GDBN} the name of the core dump file.
c906108c
SS
10167
10168@menu
10169* Files:: Commands to specify files
5b5d99cf 10170* Separate Debug Files:: Debugging information in separate files
c906108c
SS
10171* Symbol Errors:: Errors reading symbol files
10172@end menu
10173
6d2ebf8b 10174@node Files
c906108c 10175@section Commands to specify files
c906108c 10176
7a292a7a 10177@cindex symbol table
c906108c 10178@cindex core dump file
7a292a7a
SS
10179
10180You may want to specify executable and core dump file names. The usual
10181way to do this is at start-up time, using the arguments to
10182@value{GDBN}'s start-up commands (@pxref{Invocation, , Getting In and
10183Out of @value{GDBN}}).
c906108c
SS
10184
10185Occasionally it is necessary to change to a different file during a
10186@value{GDBN} session. Or you may run @value{GDBN} and forget to specify
10187a file you want to use. In these situations the @value{GDBN} commands
10188to specify new files are useful.
10189
10190@table @code
10191@cindex executable file
10192@kindex file
10193@item file @var{filename}
10194Use @var{filename} as the program to be debugged. It is read for its
10195symbols and for the contents of pure memory. It is also the program
10196executed when you use the @code{run} command. If you do not specify a
5d161b24
DB
10197directory and the file is not found in the @value{GDBN} working directory,
10198@value{GDBN} uses the environment variable @code{PATH} as a list of
10199directories to search, just as the shell does when looking for a program
10200to run. You can change the value of this variable, for both @value{GDBN}
c906108c
SS
10201and your program, using the @code{path} command.
10202
6d2ebf8b 10203On systems with memory-mapped files, an auxiliary file named
c906108c
SS
10204@file{@var{filename}.syms} may hold symbol table information for
10205@var{filename}. If so, @value{GDBN} maps in the symbol table from
10206@file{@var{filename}.syms}, starting up more quickly. See the
10207descriptions of the file options @samp{-mapped} and @samp{-readnow}
7b5ba0cc
EZ
10208(available on the command line, see @ref{File Options, , -readnow},
10209and with the commands @code{file}, @code{symbol-file}, or
10210@code{add-symbol-file}, described below), for more information.
c906108c
SS
10211
10212@item file
10213@code{file} with no argument makes @value{GDBN} discard any information it
10214has on both executable file and the symbol table.
10215
10216@kindex exec-file
10217@item exec-file @r{[} @var{filename} @r{]}
10218Specify that the program to be run (but not the symbol table) is found
10219in @var{filename}. @value{GDBN} searches the environment variable @code{PATH}
10220if necessary to locate your program. Omitting @var{filename} means to
10221discard information on the executable file.
10222
10223@kindex symbol-file
10224@item symbol-file @r{[} @var{filename} @r{]}
10225Read symbol table information from file @var{filename}. @code{PATH} is
10226searched when necessary. Use the @code{file} command to get both symbol
10227table and program to run from the same file.
10228
10229@code{symbol-file} with no argument clears out @value{GDBN} information on your
10230program's symbol table.
10231
5d161b24 10232The @code{symbol-file} command causes @value{GDBN} to forget the contents
c906108c
SS
10233of its convenience variables, the value history, and all breakpoints and
10234auto-display expressions. This is because they may contain pointers to
10235the internal data recording symbols and data types, which are part of
10236the old symbol table data being discarded inside @value{GDBN}.
10237
10238@code{symbol-file} does not repeat if you press @key{RET} again after
10239executing it once.
10240
10241When @value{GDBN} is configured for a particular environment, it
10242understands debugging information in whatever format is the standard
10243generated for that environment; you may use either a @sc{gnu} compiler, or
10244other compilers that adhere to the local conventions.
c906108c
SS
10245Best results are usually obtained from @sc{gnu} compilers; for example,
10246using @code{@value{GCC}} you can generate debugging information for
10247optimized code.
c906108c
SS
10248
10249For most kinds of object files, with the exception of old SVR3 systems
10250using COFF, the @code{symbol-file} command does not normally read the
10251symbol table in full right away. Instead, it scans the symbol table
10252quickly to find which source files and which symbols are present. The
10253details are read later, one source file at a time, as they are needed.
10254
10255The purpose of this two-stage reading strategy is to make @value{GDBN}
10256start up faster. For the most part, it is invisible except for
10257occasional pauses while the symbol table details for a particular source
10258file are being read. (The @code{set verbose} command can turn these
10259pauses into messages if desired. @xref{Messages/Warnings, ,Optional
10260warnings and messages}.)
10261
c906108c
SS
10262We have not implemented the two-stage strategy for COFF yet. When the
10263symbol table is stored in COFF format, @code{symbol-file} reads the
10264symbol table data in full right away. Note that ``stabs-in-COFF''
10265still does the two-stage strategy, since the debug info is actually
10266in stabs format.
10267
10268@kindex readnow
10269@cindex reading symbols immediately
10270@cindex symbols, reading immediately
10271@kindex mapped
10272@cindex memory-mapped symbol file
10273@cindex saving symbol table
10274@item symbol-file @var{filename} @r{[} -readnow @r{]} @r{[} -mapped @r{]}
10275@itemx file @var{filename} @r{[} -readnow @r{]} @r{[} -mapped @r{]}
10276You can override the @value{GDBN} two-stage strategy for reading symbol
10277tables by using the @samp{-readnow} option with any of the commands that
10278load symbol table information, if you want to be sure @value{GDBN} has the
5d161b24 10279entire symbol table available.
c906108c 10280
c906108c
SS
10281If memory-mapped files are available on your system through the
10282@code{mmap} system call, you can use another option, @samp{-mapped}, to
10283cause @value{GDBN} to write the symbols for your program into a reusable
10284file. Future @value{GDBN} debugging sessions map in symbol information
10285from this auxiliary symbol file (if the program has not changed), rather
10286than spending time reading the symbol table from the executable
10287program. Using the @samp{-mapped} option has the same effect as
10288starting @value{GDBN} with the @samp{-mapped} command-line option.
10289
10290You can use both options together, to make sure the auxiliary symbol
10291file has all the symbol information for your program.
10292
10293The auxiliary symbol file for a program called @var{myprog} is called
10294@samp{@var{myprog}.syms}. Once this file exists (so long as it is newer
10295than the corresponding executable), @value{GDBN} always attempts to use
10296it when you debug @var{myprog}; no special options or commands are
10297needed.
10298
10299The @file{.syms} file is specific to the host machine where you run
10300@value{GDBN}. It holds an exact image of the internal @value{GDBN}
10301symbol table. It cannot be shared across multiple host platforms.
c906108c
SS
10302
10303@c FIXME: for now no mention of directories, since this seems to be in
10304@c flux. 13mar1992 status is that in theory GDB would look either in
10305@c current dir or in same dir as myprog; but issues like competing
10306@c GDB's, or clutter in system dirs, mean that in practice right now
10307@c only current dir is used. FFish says maybe a special GDB hierarchy
10308@c (eg rooted in val of env var GDBSYMS) could exist for mappable symbol
10309@c files.
10310
c906108c
SS
10311@kindex core-file
10312@item core-file @r{[} @var{filename} @r{]}
4644b6e3 10313@itemx core
c906108c
SS
10314Specify the whereabouts of a core dump file to be used as the ``contents
10315of memory''. Traditionally, core files contain only some parts of the
10316address space of the process that generated them; @value{GDBN} can access the
10317executable file itself for other parts.
10318
10319@code{core-file} with no argument specifies that no core file is
10320to be used.
10321
10322Note that the core file is ignored when your program is actually running
7a292a7a
SS
10323under @value{GDBN}. So, if you have been running your program and you
10324wish to debug a core file instead, you must kill the subprocess in which
10325the program is running. To do this, use the @code{kill} command
c906108c 10326(@pxref{Kill Process, ,Killing the child process}).
c906108c 10327
c906108c
SS
10328@kindex add-symbol-file
10329@cindex dynamic linking
10330@item add-symbol-file @var{filename} @var{address}
10331@itemx add-symbol-file @var{filename} @var{address} @r{[} -readnow @r{]} @r{[} -mapped @r{]}
17d9d558 10332@itemx add-symbol-file @var{filename} @r{-s}@var{section} @var{address} @dots{}
96a2c332
SS
10333The @code{add-symbol-file} command reads additional symbol table
10334information from the file @var{filename}. You would use this command
10335when @var{filename} has been dynamically loaded (by some other means)
10336into the program that is running. @var{address} should be the memory
10337address at which the file has been loaded; @value{GDBN} cannot figure
d167840f
EZ
10338this out for itself. You can additionally specify an arbitrary number
10339of @samp{@r{-s}@var{section} @var{address}} pairs, to give an explicit
10340section name and base address for that section. You can specify any
10341@var{address} as an expression.
c906108c
SS
10342
10343The symbol table of the file @var{filename} is added to the symbol table
10344originally read with the @code{symbol-file} command. You can use the
96a2c332
SS
10345@code{add-symbol-file} command any number of times; the new symbol data
10346thus read keeps adding to the old. To discard all old symbol data
10347instead, use the @code{symbol-file} command without any arguments.
c906108c 10348
17d9d558
JB
10349@cindex relocatable object files, reading symbols from
10350@cindex object files, relocatable, reading symbols from
10351@cindex reading symbols from relocatable object files
10352@cindex symbols, reading from relocatable object files
10353@cindex @file{.o} files, reading symbols from
10354Although @var{filename} is typically a shared library file, an
10355executable file, or some other object file which has been fully
10356relocated for loading into a process, you can also load symbolic
10357information from relocatable @file{.o} files, as long as:
10358
10359@itemize @bullet
10360@item
10361the file's symbolic information refers only to linker symbols defined in
10362that file, not to symbols defined by other object files,
10363@item
10364every section the file's symbolic information refers to has actually
10365been loaded into the inferior, as it appears in the file, and
10366@item
10367you can determine the address at which every section was loaded, and
10368provide these to the @code{add-symbol-file} command.
10369@end itemize
10370
10371@noindent
10372Some embedded operating systems, like Sun Chorus and VxWorks, can load
10373relocatable files into an already running program; such systems
10374typically make the requirements above easy to meet. However, it's
10375important to recognize that many native systems use complex link
49efadf5 10376procedures (@code{.linkonce} section factoring and C@t{++} constructor table
17d9d558
JB
10377assembly, for example) that make the requirements difficult to meet. In
10378general, one cannot assume that using @code{add-symbol-file} to read a
10379relocatable object file's symbolic information will have the same effect
10380as linking the relocatable object file into the program in the normal
10381way.
10382
c906108c
SS
10383@code{add-symbol-file} does not repeat if you press @key{RET} after using it.
10384
10385You can use the @samp{-mapped} and @samp{-readnow} options just as with
10386the @code{symbol-file} command, to change how @value{GDBN} manages the symbol
10387table information for @var{filename}.
10388
10389@kindex add-shared-symbol-file
10390@item add-shared-symbol-file
10391The @code{add-shared-symbol-file} command can be used only under Harris' CXUX
5d161b24
DB
10392operating system for the Motorola 88k. @value{GDBN} automatically looks for
10393shared libraries, however if @value{GDBN} does not find yours, you can run
c906108c 10394@code{add-shared-symbol-file}. It takes no arguments.
c906108c 10395
c906108c
SS
10396@kindex section
10397@item section
5d161b24
DB
10398The @code{section} command changes the base address of section SECTION of
10399the exec file to ADDR. This can be used if the exec file does not contain
10400section addresses, (such as in the a.out format), or when the addresses
10401specified in the file itself are wrong. Each section must be changed
d4f3574e
SS
10402separately. The @code{info files} command, described below, lists all
10403the sections and their addresses.
c906108c
SS
10404
10405@kindex info files
10406@kindex info target
10407@item info files
10408@itemx info target
7a292a7a
SS
10409@code{info files} and @code{info target} are synonymous; both print the
10410current target (@pxref{Targets, ,Specifying a Debugging Target}),
10411including the names of the executable and core dump files currently in
10412use by @value{GDBN}, and the files from which symbols were loaded. The
10413command @code{help target} lists all possible targets rather than
10414current ones.
10415
fe95c787
MS
10416@kindex maint info sections
10417@item maint info sections
10418Another command that can give you extra information about program sections
10419is @code{maint info sections}. In addition to the section information
10420displayed by @code{info files}, this command displays the flags and file
10421offset of each section in the executable and core dump files. In addition,
10422@code{maint info sections} provides the following command options (which
10423may be arbitrarily combined):
10424
10425@table @code
10426@item ALLOBJ
10427Display sections for all loaded object files, including shared libraries.
10428@item @var{sections}
6600abed 10429Display info only for named @var{sections}.
fe95c787
MS
10430@item @var{section-flags}
10431Display info only for sections for which @var{section-flags} are true.
10432The section flags that @value{GDBN} currently knows about are:
10433@table @code
10434@item ALLOC
10435Section will have space allocated in the process when loaded.
10436Set for all sections except those containing debug information.
10437@item LOAD
10438Section will be loaded from the file into the child process memory.
10439Set for pre-initialized code and data, clear for @code{.bss} sections.
10440@item RELOC
10441Section needs to be relocated before loading.
10442@item READONLY
10443Section cannot be modified by the child process.
10444@item CODE
10445Section contains executable code only.
6600abed 10446@item DATA
fe95c787
MS
10447Section contains data only (no executable code).
10448@item ROM
10449Section will reside in ROM.
10450@item CONSTRUCTOR
10451Section contains data for constructor/destructor lists.
10452@item HAS_CONTENTS
10453Section is not empty.
10454@item NEVER_LOAD
10455An instruction to the linker to not output the section.
10456@item COFF_SHARED_LIBRARY
10457A notification to the linker that the section contains
10458COFF shared library information.
10459@item IS_COMMON
10460Section contains common symbols.
10461@end table
10462@end table
6763aef9
MS
10463@kindex set trust-readonly-sections
10464@item set trust-readonly-sections on
10465Tell @value{GDBN} that readonly sections in your object file
6ca652b0 10466really are read-only (i.e.@: that their contents will not change).
6763aef9
MS
10467In that case, @value{GDBN} can fetch values from these sections
10468out of the object file, rather than from the target program.
10469For some targets (notably embedded ones), this can be a significant
10470enhancement to debugging performance.
10471
10472The default is off.
10473
10474@item set trust-readonly-sections off
15110bc3 10475Tell @value{GDBN} not to trust readonly sections. This means that
6763aef9
MS
10476the contents of the section might change while the program is running,
10477and must therefore be fetched from the target when needed.
c906108c
SS
10478@end table
10479
10480All file-specifying commands allow both absolute and relative file names
10481as arguments. @value{GDBN} always converts the file name to an absolute file
10482name and remembers it that way.
10483
c906108c 10484@cindex shared libraries
c906108c
SS
10485@value{GDBN} supports HP-UX, SunOS, SVr4, Irix 5, and IBM RS/6000 shared
10486libraries.
53a5351d 10487
c906108c
SS
10488@value{GDBN} automatically loads symbol definitions from shared libraries
10489when you use the @code{run} command, or when you examine a core file.
10490(Before you issue the @code{run} command, @value{GDBN} does not understand
10491references to a function in a shared library, however---unless you are
10492debugging a core file).
53a5351d
JM
10493
10494On HP-UX, if the program loads a library explicitly, @value{GDBN}
10495automatically loads the symbols at the time of the @code{shl_load} call.
10496
c906108c
SS
10497@c FIXME: some @value{GDBN} release may permit some refs to undef
10498@c FIXME...symbols---eg in a break cmd---assuming they are from a shared
10499@c FIXME...lib; check this from time to time when updating manual
10500
b7209cb4
FF
10501There are times, however, when you may wish to not automatically load
10502symbol definitions from shared libraries, such as when they are
10503particularly large or there are many of them.
10504
10505To control the automatic loading of shared library symbols, use the
10506commands:
10507
10508@table @code
10509@kindex set auto-solib-add
10510@item set auto-solib-add @var{mode}
10511If @var{mode} is @code{on}, symbols from all shared object libraries
10512will be loaded automatically when the inferior begins execution, you
10513attach to an independently started inferior, or when the dynamic linker
10514informs @value{GDBN} that a new library has been loaded. If @var{mode}
10515is @code{off}, symbols must be loaded manually, using the
10516@code{sharedlibrary} command. The default value is @code{on}.
10517
dcaf7c2c
EZ
10518@cindex memory used for symbol tables
10519If your program uses lots of shared libraries with debug info that
10520takes large amounts of memory, you can decrease the @value{GDBN}
10521memory footprint by preventing it from automatically loading the
10522symbols from shared libraries. To that end, type @kbd{set
10523auto-solib-add off} before running the inferior, then load each
10524library whose debug symbols you do need with @kbd{sharedlibrary
10525@var{regexp}}, where @var{regexp} is a regular expresion that matches
10526the libraries whose symbols you want to be loaded.
10527
b7209cb4
FF
10528@kindex show auto-solib-add
10529@item show auto-solib-add
10530Display the current autoloading mode.
10531@end table
10532
10533To explicitly load shared library symbols, use the @code{sharedlibrary}
10534command:
10535
c906108c
SS
10536@table @code
10537@kindex info sharedlibrary
10538@kindex info share
10539@item info share
10540@itemx info sharedlibrary
10541Print the names of the shared libraries which are currently loaded.
10542
10543@kindex sharedlibrary
10544@kindex share
10545@item sharedlibrary @var{regex}
10546@itemx share @var{regex}
c906108c
SS
10547Load shared object library symbols for files matching a
10548Unix regular expression.
10549As with files loaded automatically, it only loads shared libraries
10550required by your program for a core file or after typing @code{run}. If
10551@var{regex} is omitted all shared libraries required by your program are
10552loaded.
10553@end table
10554
b7209cb4
FF
10555On some systems, such as HP-UX systems, @value{GDBN} supports
10556autoloading shared library symbols until a limiting threshold size is
10557reached. This provides the benefit of allowing autoloading to remain on
10558by default, but avoids autoloading excessively large shared libraries,
10559up to a threshold that is initially set, but which you can modify if you
10560wish.
c906108c
SS
10561
10562Beyond that threshold, symbols from shared libraries must be explicitly
d4f3574e
SS
10563loaded. To load these symbols, use the command @code{sharedlibrary
10564@var{filename}}. The base address of the shared library is determined
c906108c
SS
10565automatically by @value{GDBN} and need not be specified.
10566
10567To display or set the threshold, use the commands:
10568
10569@table @code
b7209cb4
FF
10570@kindex set auto-solib-limit
10571@item set auto-solib-limit @var{threshold}
10572Set the autoloading size threshold, in an integral number of megabytes.
10573If @var{threshold} is nonzero and shared library autoloading is enabled,
10574symbols from all shared object libraries will be loaded until the total
10575size of the loaded shared library symbols exceeds this threshold.
c906108c 10576Otherwise, symbols must be loaded manually, using the
6ca652b0 10577@code{sharedlibrary} command. The default threshold is 100 (i.e.@: 100
b7209cb4 10578Mb).
c906108c 10579
b7209cb4
FF
10580@kindex show auto-solib-limit
10581@item show auto-solib-limit
c906108c
SS
10582Display the current autoloading size threshold, in megabytes.
10583@end table
c906108c 10584
f5ebfba0
DJ
10585Shared libraries are also supported in many cross or remote debugging
10586configurations. A copy of the target's libraries need to be present on the
10587host system; they need to be the same as the target libraries, although the
10588copies on the target can be stripped as long as the copies on the host are
10589not.
10590
10591You need to tell @value{GDBN} where the target libraries are, so that it can
10592load the correct copies---otherwise, it may try to load the host's libraries.
10593@value{GDBN} has two variables to specify the search directories for target
10594libraries.
10595
10596@table @code
10597@kindex set solib-absolute-prefix
10598@item set solib-absolute-prefix @var{path}
10599If this variable is set, @var{path} will be used as a prefix for any
10600absolute shared library paths; many runtime loaders store the absolute
10601paths to the shared library in the target program's memory. If you use
10602@samp{solib-absolute-prefix} to find shared libraries, they need to be laid
10603out in the same way that they are on the target, with e.g.@: a
10604@file{/usr/lib} hierarchy under @var{path}.
10605
10606You can set the default value of @samp{solib-absolute-prefix} by using the
10607configure-time @samp{--with-sysroot} option.
10608
10609@kindex show solib-absolute-prefix
10610@item show solib-absolute-prefix
10611Display the current shared library prefix.
10612
10613@kindex set solib-search-path
10614@item set solib-search-path @var{path}
10615If this variable is set, @var{path} is a colon-separated list of directories
10616to search for shared libraries. @samp{solib-search-path} is used after
10617@samp{solib-absolute-prefix} fails to locate the library, or if the path to
10618the library is relative instead of absolute. If you want to use
10619@samp{solib-search-path} instead of @samp{solib-absolute-prefix}, be sure to
10620set @samp{solib-absolute-prefix} to a nonexistant directory to prevent
10621@value{GDBN} from finding your host's libraries.
10622
10623@kindex show solib-search-path
10624@item show solib-search-path
10625Display the current shared library search path.
10626@end table
10627
5b5d99cf
JB
10628
10629@node Separate Debug Files
10630@section Debugging Information in Separate Files
10631@cindex separate debugging information files
10632@cindex debugging information in separate files
10633@cindex @file{.debug} subdirectories
10634@cindex debugging information directory, global
10635@cindex global debugging information directory
10636
10637@value{GDBN} allows you to put a program's debugging information in a
10638file separate from the executable itself, in a way that allows
10639@value{GDBN} to find and load the debugging information automatically.
10640Since debugging information can be very large --- sometimes larger
10641than the executable code itself --- some systems distribute debugging
10642information for their executables in separate files, which users can
10643install only when they need to debug a problem.
10644
10645If an executable's debugging information has been extracted to a
10646separate file, the executable should contain a @dfn{debug link} giving
10647the name of the debugging information file (with no directory
10648components), and a checksum of its contents. (The exact form of a
10649debug link is described below.) If the full name of the directory
10650containing the executable is @var{execdir}, and the executable has a
10651debug link that specifies the name @var{debugfile}, then @value{GDBN}
10652will automatically search for the debugging information file in three
10653places:
10654
10655@itemize @bullet
10656@item
10657the directory containing the executable file (that is, it will look
10658for a file named @file{@var{execdir}/@var{debugfile}},
10659@item
10660a subdirectory of that directory named @file{.debug} (that is, the
10661file @file{@var{execdir}/.debug/@var{debugfile}}, and
10662@item
10663a subdirectory of the global debug file directory that includes the
10664executable's full path, and the name from the link (that is, the file
10665@file{@var{globaldebugdir}/@var{execdir}/@var{debugfile}}, where
10666@var{globaldebugdir} is the global debug file directory, and
10667@var{execdir} has been turned into a relative path).
10668@end itemize
10669@noindent
10670@value{GDBN} checks under each of these names for a debugging
10671information file whose checksum matches that given in the link, and
10672reads the debugging information from the first one it finds.
10673
10674So, for example, if you ask @value{GDBN} to debug @file{/usr/bin/ls},
10675which has a link containing the name @file{ls.debug}, and the global
10676debug directory is @file{/usr/lib/debug}, then @value{GDBN} will look
10677for debug information in @file{/usr/bin/ls.debug},
10678@file{/usr/bin/.debug/ls.debug}, and
10679@file{/usr/lib/debug/usr/bin/ls.debug}.
10680
10681You can set the global debugging info directory's name, and view the
10682name @value{GDBN} is currently using.
10683
10684@table @code
10685
10686@kindex set debug-file-directory
10687@item set debug-file-directory @var{directory}
10688Set the directory which @value{GDBN} searches for separate debugging
10689information files to @var{directory}.
10690
10691@kindex show debug-file-directory
10692@item show debug-file-directory
10693Show the directory @value{GDBN} searches for separate debugging
10694information files.
10695
10696@end table
10697
10698@cindex @code{.gnu_debuglink} sections
10699@cindex debug links
10700A debug link is a special section of the executable file named
10701@code{.gnu_debuglink}. The section must contain:
10702
10703@itemize
10704@item
10705A filename, with any leading directory components removed, followed by
10706a zero byte,
10707@item
10708zero to three bytes of padding, as needed to reach the next four-byte
10709boundary within the section, and
10710@item
10711a four-byte CRC checksum, stored in the same endianness used for the
10712executable file itself. The checksum is computed on the debugging
10713information file's full contents by the function given below, passing
10714zero as the @var{crc} argument.
10715@end itemize
10716
10717Any executable file format can carry a debug link, as long as it can
10718contain a section named @code{.gnu_debuglink} with the contents
10719described above.
10720
10721The debugging information file itself should be an ordinary
10722executable, containing a full set of linker symbols, sections, and
10723debugging information. The sections of the debugging information file
10724should have the same names, addresses and sizes as the original file,
10725but they need not contain any data --- much like a @code{.bss} section
10726in an ordinary executable.
10727
10728As of December 2002, there is no standard GNU utility to produce
10729separated executable / debugging information file pairs. Ulrich
10730Drepper's @file{elfutils} package, starting with version 0.53,
10731contains a version of the @code{strip} command such that the command
10732@kbd{strip foo -f foo.debug} removes the debugging information from
10733the executable file @file{foo}, places it in the file
10734@file{foo.debug}, and leaves behind a debug link in @file{foo}.
10735
10736Since there are many different ways to compute CRC's (different
10737polynomials, reversals, byte ordering, etc.), the simplest way to
10738describe the CRC used in @code{.gnu_debuglink} sections is to give the
10739complete code for a function that computes it:
10740
4644b6e3 10741@kindex gnu_debuglink_crc32
5b5d99cf
JB
10742@smallexample
10743unsigned long
10744gnu_debuglink_crc32 (unsigned long crc,
10745 unsigned char *buf, size_t len)
10746@{
10747 static const unsigned long crc32_table[256] =
10748 @{
10749 0x00000000, 0x77073096, 0xee0e612c, 0x990951ba, 0x076dc419,
10750 0x706af48f, 0xe963a535, 0x9e6495a3, 0x0edb8832, 0x79dcb8a4,
10751 0xe0d5e91e, 0x97d2d988, 0x09b64c2b, 0x7eb17cbd, 0xe7b82d07,
10752 0x90bf1d91, 0x1db71064, 0x6ab020f2, 0xf3b97148, 0x84be41de,
10753 0x1adad47d, 0x6ddde4eb, 0xf4d4b551, 0x83d385c7, 0x136c9856,
10754 0x646ba8c0, 0xfd62f97a, 0x8a65c9ec, 0x14015c4f, 0x63066cd9,
10755 0xfa0f3d63, 0x8d080df5, 0x3b6e20c8, 0x4c69105e, 0xd56041e4,
10756 0xa2677172, 0x3c03e4d1, 0x4b04d447, 0xd20d85fd, 0xa50ab56b,
10757 0x35b5a8fa, 0x42b2986c, 0xdbbbc9d6, 0xacbcf940, 0x32d86ce3,
10758 0x45df5c75, 0xdcd60dcf, 0xabd13d59, 0x26d930ac, 0x51de003a,
10759 0xc8d75180, 0xbfd06116, 0x21b4f4b5, 0x56b3c423, 0xcfba9599,
10760 0xb8bda50f, 0x2802b89e, 0x5f058808, 0xc60cd9b2, 0xb10be924,
10761 0x2f6f7c87, 0x58684c11, 0xc1611dab, 0xb6662d3d, 0x76dc4190,
10762 0x01db7106, 0x98d220bc, 0xefd5102a, 0x71b18589, 0x06b6b51f,
10763 0x9fbfe4a5, 0xe8b8d433, 0x7807c9a2, 0x0f00f934, 0x9609a88e,
10764 0xe10e9818, 0x7f6a0dbb, 0x086d3d2d, 0x91646c97, 0xe6635c01,
10765 0x6b6b51f4, 0x1c6c6162, 0x856530d8, 0xf262004e, 0x6c0695ed,
10766 0x1b01a57b, 0x8208f4c1, 0xf50fc457, 0x65b0d9c6, 0x12b7e950,
10767 0x8bbeb8ea, 0xfcb9887c, 0x62dd1ddf, 0x15da2d49, 0x8cd37cf3,
10768 0xfbd44c65, 0x4db26158, 0x3ab551ce, 0xa3bc0074, 0xd4bb30e2,
10769 0x4adfa541, 0x3dd895d7, 0xa4d1c46d, 0xd3d6f4fb, 0x4369e96a,
10770 0x346ed9fc, 0xad678846, 0xda60b8d0, 0x44042d73, 0x33031de5,
10771 0xaa0a4c5f, 0xdd0d7cc9, 0x5005713c, 0x270241aa, 0xbe0b1010,
10772 0xc90c2086, 0x5768b525, 0x206f85b3, 0xb966d409, 0xce61e49f,
10773 0x5edef90e, 0x29d9c998, 0xb0d09822, 0xc7d7a8b4, 0x59b33d17,
10774 0x2eb40d81, 0xb7bd5c3b, 0xc0ba6cad, 0xedb88320, 0x9abfb3b6,
10775 0x03b6e20c, 0x74b1d29a, 0xead54739, 0x9dd277af, 0x04db2615,
10776 0x73dc1683, 0xe3630b12, 0x94643b84, 0x0d6d6a3e, 0x7a6a5aa8,
10777 0xe40ecf0b, 0x9309ff9d, 0x0a00ae27, 0x7d079eb1, 0xf00f9344,
10778 0x8708a3d2, 0x1e01f268, 0x6906c2fe, 0xf762575d, 0x806567cb,
10779 0x196c3671, 0x6e6b06e7, 0xfed41b76, 0x89d32be0, 0x10da7a5a,
10780 0x67dd4acc, 0xf9b9df6f, 0x8ebeeff9, 0x17b7be43, 0x60b08ed5,
10781 0xd6d6a3e8, 0xa1d1937e, 0x38d8c2c4, 0x4fdff252, 0xd1bb67f1,
10782 0xa6bc5767, 0x3fb506dd, 0x48b2364b, 0xd80d2bda, 0xaf0a1b4c,
10783 0x36034af6, 0x41047a60, 0xdf60efc3, 0xa867df55, 0x316e8eef,
10784 0x4669be79, 0xcb61b38c, 0xbc66831a, 0x256fd2a0, 0x5268e236,
10785 0xcc0c7795, 0xbb0b4703, 0x220216b9, 0x5505262f, 0xc5ba3bbe,
10786 0xb2bd0b28, 0x2bb45a92, 0x5cb36a04, 0xc2d7ffa7, 0xb5d0cf31,
10787 0x2cd99e8b, 0x5bdeae1d, 0x9b64c2b0, 0xec63f226, 0x756aa39c,
10788 0x026d930a, 0x9c0906a9, 0xeb0e363f, 0x72076785, 0x05005713,
10789 0x95bf4a82, 0xe2b87a14, 0x7bb12bae, 0x0cb61b38, 0x92d28e9b,
10790 0xe5d5be0d, 0x7cdcefb7, 0x0bdbdf21, 0x86d3d2d4, 0xf1d4e242,
10791 0x68ddb3f8, 0x1fda836e, 0x81be16cd, 0xf6b9265b, 0x6fb077e1,
10792 0x18b74777, 0x88085ae6, 0xff0f6a70, 0x66063bca, 0x11010b5c,
10793 0x8f659eff, 0xf862ae69, 0x616bffd3, 0x166ccf45, 0xa00ae278,
10794 0xd70dd2ee, 0x4e048354, 0x3903b3c2, 0xa7672661, 0xd06016f7,
10795 0x4969474d, 0x3e6e77db, 0xaed16a4a, 0xd9d65adc, 0x40df0b66,
10796 0x37d83bf0, 0xa9bcae53, 0xdebb9ec5, 0x47b2cf7f, 0x30b5ffe9,
10797 0xbdbdf21c, 0xcabac28a, 0x53b39330, 0x24b4a3a6, 0xbad03605,
10798 0xcdd70693, 0x54de5729, 0x23d967bf, 0xb3667a2e, 0xc4614ab8,
10799 0x5d681b02, 0x2a6f2b94, 0xb40bbe37, 0xc30c8ea1, 0x5a05df1b,
10800 0x2d02ef8d
10801 @};
10802 unsigned char *end;
10803
10804 crc = ~crc & 0xffffffff;
10805 for (end = buf + len; buf < end; ++buf)
10806 crc = crc32_table[(crc ^ *buf) & 0xff] ^ (crc >> 8);
e7a3abfc 10807 return ~crc & 0xffffffff;
5b5d99cf
JB
10808@}
10809@end smallexample
10810
10811
6d2ebf8b 10812@node Symbol Errors
c906108c
SS
10813@section Errors reading symbol files
10814
10815While reading a symbol file, @value{GDBN} occasionally encounters problems,
10816such as symbol types it does not recognize, or known bugs in compiler
10817output. By default, @value{GDBN} does not notify you of such problems, since
10818they are relatively common and primarily of interest to people
10819debugging compilers. If you are interested in seeing information
10820about ill-constructed symbol tables, you can either ask @value{GDBN} to print
10821only one message about each such type of problem, no matter how many
10822times the problem occurs; or you can ask @value{GDBN} to print more messages,
10823to see how many times the problems occur, with the @code{set
10824complaints} command (@pxref{Messages/Warnings, ,Optional warnings and
10825messages}).
10826
10827The messages currently printed, and their meanings, include:
10828
10829@table @code
10830@item inner block not inside outer block in @var{symbol}
10831
10832The symbol information shows where symbol scopes begin and end
10833(such as at the start of a function or a block of statements). This
10834error indicates that an inner scope block is not fully contained
10835in its outer scope blocks.
10836
10837@value{GDBN} circumvents the problem by treating the inner block as if it had
10838the same scope as the outer block. In the error message, @var{symbol}
10839may be shown as ``@code{(don't know)}'' if the outer block is not a
10840function.
10841
10842@item block at @var{address} out of order
10843
10844The symbol information for symbol scope blocks should occur in
10845order of increasing addresses. This error indicates that it does not
10846do so.
10847
10848@value{GDBN} does not circumvent this problem, and has trouble
10849locating symbols in the source file whose symbols it is reading. (You
10850can often determine what source file is affected by specifying
10851@code{set verbose on}. @xref{Messages/Warnings, ,Optional warnings and
10852messages}.)
10853
10854@item bad block start address patched
10855
10856The symbol information for a symbol scope block has a start address
10857smaller than the address of the preceding source line. This is known
10858to occur in the SunOS 4.1.1 (and earlier) C compiler.
10859
10860@value{GDBN} circumvents the problem by treating the symbol scope block as
10861starting on the previous source line.
10862
10863@item bad string table offset in symbol @var{n}
10864
10865@cindex foo
10866Symbol number @var{n} contains a pointer into the string table which is
10867larger than the size of the string table.
10868
10869@value{GDBN} circumvents the problem by considering the symbol to have the
10870name @code{foo}, which may cause other problems if many symbols end up
10871with this name.
10872
10873@item unknown symbol type @code{0x@var{nn}}
10874
7a292a7a
SS
10875The symbol information contains new data types that @value{GDBN} does
10876not yet know how to read. @code{0x@var{nn}} is the symbol type of the
d4f3574e 10877uncomprehended information, in hexadecimal.
c906108c 10878
7a292a7a
SS
10879@value{GDBN} circumvents the error by ignoring this symbol information.
10880This usually allows you to debug your program, though certain symbols
c906108c 10881are not accessible. If you encounter such a problem and feel like
7a292a7a
SS
10882debugging it, you can debug @code{@value{GDBP}} with itself, breakpoint
10883on @code{complain}, then go up to the function @code{read_dbx_symtab}
10884and examine @code{*bufp} to see the symbol.
c906108c
SS
10885
10886@item stub type has NULL name
c906108c 10887
7a292a7a 10888@value{GDBN} could not find the full definition for a struct or class.
c906108c 10889
7a292a7a 10890@item const/volatile indicator missing (ok if using g++ v1.x), got@dots{}
b37052ae 10891The symbol information for a C@t{++} member function is missing some
7a292a7a
SS
10892information that recent versions of the compiler should have output for
10893it.
c906108c
SS
10894
10895@item info mismatch between compiler and debugger
10896
10897@value{GDBN} could not parse a type specification output by the compiler.
7a292a7a 10898
c906108c
SS
10899@end table
10900
6d2ebf8b 10901@node Targets
c906108c 10902@chapter Specifying a Debugging Target
7a292a7a 10903
c906108c
SS
10904@cindex debugging target
10905@kindex target
10906
10907A @dfn{target} is the execution environment occupied by your program.
53a5351d
JM
10908
10909Often, @value{GDBN} runs in the same host environment as your program;
10910in that case, the debugging target is specified as a side effect when
10911you use the @code{file} or @code{core} commands. When you need more
c906108c
SS
10912flexibility---for example, running @value{GDBN} on a physically separate
10913host, or controlling a standalone system over a serial port or a
53a5351d
JM
10914realtime system over a TCP/IP connection---you can use the @code{target}
10915command to specify one of the target types configured for @value{GDBN}
10916(@pxref{Target Commands, ,Commands for managing targets}).
c906108c
SS
10917
10918@menu
10919* Active Targets:: Active targets
10920* Target Commands:: Commands for managing targets
c906108c
SS
10921* Byte Order:: Choosing target byte order
10922* Remote:: Remote debugging
96baa820 10923* KOD:: Kernel Object Display
c906108c
SS
10924
10925@end menu
10926
6d2ebf8b 10927@node Active Targets
c906108c 10928@section Active targets
7a292a7a 10929
c906108c
SS
10930@cindex stacking targets
10931@cindex active targets
10932@cindex multiple targets
10933
c906108c 10934There are three classes of targets: processes, core files, and
7a292a7a
SS
10935executable files. @value{GDBN} can work concurrently on up to three
10936active targets, one in each class. This allows you to (for example)
10937start a process and inspect its activity without abandoning your work on
10938a core file.
c906108c
SS
10939
10940For example, if you execute @samp{gdb a.out}, then the executable file
10941@code{a.out} is the only active target. If you designate a core file as
10942well---presumably from a prior run that crashed and coredumped---then
10943@value{GDBN} has two active targets and uses them in tandem, looking
10944first in the corefile target, then in the executable file, to satisfy
10945requests for memory addresses. (Typically, these two classes of target
10946are complementary, since core files contain only a program's
10947read-write memory---variables and so on---plus machine status, while
10948executable files contain only the program text and initialized data.)
c906108c
SS
10949
10950When you type @code{run}, your executable file becomes an active process
7a292a7a
SS
10951target as well. When a process target is active, all @value{GDBN}
10952commands requesting memory addresses refer to that target; addresses in
10953an active core file or executable file target are obscured while the
10954process target is active.
c906108c 10955
7a292a7a
SS
10956Use the @code{core-file} and @code{exec-file} commands to select a new
10957core file or executable target (@pxref{Files, ,Commands to specify
c906108c 10958files}). To specify as a target a process that is already running, use
7a292a7a
SS
10959the @code{attach} command (@pxref{Attach, ,Debugging an already-running
10960process}).
c906108c 10961
6d2ebf8b 10962@node Target Commands
c906108c
SS
10963@section Commands for managing targets
10964
10965@table @code
10966@item target @var{type} @var{parameters}
7a292a7a
SS
10967Connects the @value{GDBN} host environment to a target machine or
10968process. A target is typically a protocol for talking to debugging
10969facilities. You use the argument @var{type} to specify the type or
10970protocol of the target machine.
c906108c
SS
10971
10972Further @var{parameters} are interpreted by the target protocol, but
10973typically include things like device names or host names to connect
10974with, process numbers, and baud rates.
c906108c
SS
10975
10976The @code{target} command does not repeat if you press @key{RET} again
10977after executing the command.
10978
10979@kindex help target
10980@item help target
10981Displays the names of all targets available. To display targets
10982currently selected, use either @code{info target} or @code{info files}
10983(@pxref{Files, ,Commands to specify files}).
10984
10985@item help target @var{name}
10986Describe a particular target, including any parameters necessary to
10987select it.
10988
10989@kindex set gnutarget
10990@item set gnutarget @var{args}
5d161b24 10991@value{GDBN} uses its own library BFD to read your files. @value{GDBN}
c906108c 10992knows whether it is reading an @dfn{executable},
5d161b24
DB
10993a @dfn{core}, or a @dfn{.o} file; however, you can specify the file format
10994with the @code{set gnutarget} command. Unlike most @code{target} commands,
c906108c
SS
10995with @code{gnutarget} the @code{target} refers to a program, not a machine.
10996
d4f3574e 10997@quotation
c906108c
SS
10998@emph{Warning:} To specify a file format with @code{set gnutarget},
10999you must know the actual BFD name.
d4f3574e 11000@end quotation
c906108c 11001
d4f3574e
SS
11002@noindent
11003@xref{Files, , Commands to specify files}.
c906108c 11004
5d161b24 11005@kindex show gnutarget
c906108c
SS
11006@item show gnutarget
11007Use the @code{show gnutarget} command to display what file format
11008@code{gnutarget} is set to read. If you have not set @code{gnutarget},
11009@value{GDBN} will determine the file format for each file automatically,
11010and @code{show gnutarget} displays @samp{The current BDF target is "auto"}.
11011@end table
11012
4644b6e3 11013@cindex common targets
c906108c
SS
11014Here are some common targets (available, or not, depending on the GDB
11015configuration):
c906108c
SS
11016
11017@table @code
4644b6e3 11018@kindex target
c906108c 11019@item target exec @var{program}
4644b6e3 11020@cindex executable file target
c906108c
SS
11021An executable file. @samp{target exec @var{program}} is the same as
11022@samp{exec-file @var{program}}.
11023
c906108c 11024@item target core @var{filename}
4644b6e3 11025@cindex core dump file target
c906108c
SS
11026A core dump file. @samp{target core @var{filename}} is the same as
11027@samp{core-file @var{filename}}.
c906108c 11028
c906108c 11029@item target remote @var{dev}
4644b6e3 11030@cindex remote target
c906108c
SS
11031Remote serial target in GDB-specific protocol. The argument @var{dev}
11032specifies what serial device to use for the connection (e.g.
11033@file{/dev/ttya}). @xref{Remote, ,Remote debugging}. @code{target remote}
d4f3574e 11034supports the @code{load} command. This is only useful if you have
c906108c
SS
11035some other way of getting the stub to the target system, and you can put
11036it somewhere in memory where it won't get clobbered by the download.
11037
c906108c 11038@item target sim
4644b6e3 11039@cindex built-in simulator target
2df3850c 11040Builtin CPU simulator. @value{GDBN} includes simulators for most architectures.
104c1213 11041In general,
474c8240 11042@smallexample
104c1213
JM
11043 target sim
11044 load
11045 run
474c8240 11046@end smallexample
d4f3574e 11047@noindent
104c1213 11048works; however, you cannot assume that a specific memory map, device
d4f3574e 11049drivers, or even basic I/O is available, although some simulators do
104c1213
JM
11050provide these. For info about any processor-specific simulator details,
11051see the appropriate section in @ref{Embedded Processors, ,Embedded
11052Processors}.
11053
c906108c
SS
11054@end table
11055
104c1213 11056Some configurations may include these targets as well:
c906108c
SS
11057
11058@table @code
11059
c906108c 11060@item target nrom @var{dev}
4644b6e3 11061@cindex NetROM ROM emulator target
c906108c
SS
11062NetROM ROM emulator. This target only supports downloading.
11063
c906108c
SS
11064@end table
11065
5d161b24 11066Different targets are available on different configurations of @value{GDBN};
c906108c 11067your configuration may have more or fewer targets.
c906108c
SS
11068
11069Many remote targets require you to download the executable's code
11070once you've successfully established a connection.
11071
11072@table @code
11073
11074@kindex load @var{filename}
11075@item load @var{filename}
c906108c
SS
11076Depending on what remote debugging facilities are configured into
11077@value{GDBN}, the @code{load} command may be available. Where it exists, it
11078is meant to make @var{filename} (an executable) available for debugging
11079on the remote system---by downloading, or dynamic linking, for example.
11080@code{load} also records the @var{filename} symbol table in @value{GDBN}, like
11081the @code{add-symbol-file} command.
11082
11083If your @value{GDBN} does not have a @code{load} command, attempting to
11084execute it gets the error message ``@code{You can't do that when your
11085target is @dots{}}''
c906108c
SS
11086
11087The file is loaded at whatever address is specified in the executable.
11088For some object file formats, you can specify the load address when you
11089link the program; for other formats, like a.out, the object file format
11090specifies a fixed address.
11091@c FIXME! This would be a good place for an xref to the GNU linker doc.
11092
c906108c
SS
11093@code{load} does not repeat if you press @key{RET} again after using it.
11094@end table
11095
6d2ebf8b 11096@node Byte Order
c906108c 11097@section Choosing target byte order
7a292a7a 11098
c906108c
SS
11099@cindex choosing target byte order
11100@cindex target byte order
c906108c 11101
172c2a43 11102Some types of processors, such as the MIPS, PowerPC, and Renesas SH,
c906108c
SS
11103offer the ability to run either big-endian or little-endian byte
11104orders. Usually the executable or symbol will include a bit to
11105designate the endian-ness, and you will not need to worry about
11106which to use. However, you may still find it useful to adjust
d4f3574e 11107@value{GDBN}'s idea of processor endian-ness manually.
c906108c
SS
11108
11109@table @code
4644b6e3 11110@kindex set endian
c906108c
SS
11111@item set endian big
11112Instruct @value{GDBN} to assume the target is big-endian.
11113
c906108c
SS
11114@item set endian little
11115Instruct @value{GDBN} to assume the target is little-endian.
11116
c906108c
SS
11117@item set endian auto
11118Instruct @value{GDBN} to use the byte order associated with the
11119executable.
11120
11121@item show endian
11122Display @value{GDBN}'s current idea of the target byte order.
11123
11124@end table
11125
11126Note that these commands merely adjust interpretation of symbolic
11127data on the host, and that they have absolutely no effect on the
11128target system.
11129
6d2ebf8b 11130@node Remote
c906108c
SS
11131@section Remote debugging
11132@cindex remote debugging
11133
11134If you are trying to debug a program running on a machine that cannot run
5d161b24
DB
11135@value{GDBN} in the usual way, it is often useful to use remote debugging.
11136For example, you might use remote debugging on an operating system kernel,
c906108c
SS
11137or on a small system which does not have a general purpose operating system
11138powerful enough to run a full-featured debugger.
11139
11140Some configurations of @value{GDBN} have special serial or TCP/IP interfaces
11141to make this work with particular debugging targets. In addition,
5d161b24 11142@value{GDBN} comes with a generic serial protocol (specific to @value{GDBN},
c906108c
SS
11143but not specific to any particular target system) which you can use if you
11144write the remote stubs---the code that runs on the remote system to
11145communicate with @value{GDBN}.
11146
11147Other remote targets may be available in your
11148configuration of @value{GDBN}; use @code{help target} to list them.
c906108c 11149
6f05cf9f
AC
11150@node KOD
11151@section Kernel Object Display
6f05cf9f 11152@cindex kernel object display
6f05cf9f
AC
11153@cindex KOD
11154
11155Some targets support kernel object display. Using this facility,
11156@value{GDBN} communicates specially with the underlying operating system
11157and can display information about operating system-level objects such as
11158mutexes and other synchronization objects. Exactly which objects can be
11159displayed is determined on a per-OS basis.
11160
3bbe9696 11161@kindex set os
6f05cf9f
AC
11162Use the @code{set os} command to set the operating system. This tells
11163@value{GDBN} which kernel object display module to initialize:
11164
474c8240 11165@smallexample
6f05cf9f 11166(@value{GDBP}) set os cisco
474c8240 11167@end smallexample
6f05cf9f 11168
3bbe9696
EZ
11169@kindex show os
11170The associated command @code{show os} displays the operating system
11171set with the @code{set os} command; if no operating system has been
11172set, @code{show os} will display an empty string @samp{""}.
11173
6f05cf9f
AC
11174If @code{set os} succeeds, @value{GDBN} will display some information
11175about the operating system, and will create a new @code{info} command
11176which can be used to query the target. The @code{info} command is named
11177after the operating system:
c906108c 11178
3bbe9696 11179@kindex info cisco
474c8240 11180@smallexample
6f05cf9f
AC
11181(@value{GDBP}) info cisco
11182List of Cisco Kernel Objects
11183Object Description
11184any Any and all objects
474c8240 11185@end smallexample
6f05cf9f
AC
11186
11187Further subcommands can be used to query about particular objects known
11188by the kernel.
11189
3bbe9696
EZ
11190There is currently no way to determine whether a given operating
11191system is supported other than to try setting it with @kbd{set os
11192@var{name}}, where @var{name} is the name of the operating system you
11193want to try.
6f05cf9f
AC
11194
11195
11196@node Remote Debugging
11197@chapter Debugging remote programs
11198
6b2f586d 11199@menu
07f31aa6 11200* Connecting:: Connecting to a remote target
6b2f586d
AC
11201* Server:: Using the gdbserver program
11202* NetWare:: Using the gdbserve.nlm program
501eef12 11203* Remote configuration:: Remote configuration
6b2f586d 11204* remote stub:: Implementing a remote stub
6b2f586d
AC
11205@end menu
11206
07f31aa6
DJ
11207@node Connecting
11208@section Connecting to a remote target
11209
11210On the @value{GDBN} host machine, you will need an unstripped copy of
11211your program, since @value{GDBN} needs symobl and debugging information.
11212Start up @value{GDBN} as usual, using the name of the local copy of your
11213program as the first argument.
11214
11215@cindex serial line, @code{target remote}
11216If you're using a serial line, you may want to give @value{GDBN} the
11217@w{@samp{--baud}} option, or use the @code{set remotebaud} command
11218before the @code{target} command.
11219
11220After that, use @code{target remote} to establish communications with
11221the target machine. Its argument specifies how to communicate---either
11222via a devicename attached to a direct serial line, or a TCP or UDP port
11223(possibly to a terminal server which in turn has a serial line to the
11224target). For example, to use a serial line connected to the device
11225named @file{/dev/ttyb}:
11226
11227@smallexample
11228target remote /dev/ttyb
11229@end smallexample
11230
11231@cindex TCP port, @code{target remote}
11232To use a TCP connection, use an argument of the form
11233@code{@var{host}:@var{port}} or @code{tcp:@var{host}:@var{port}}.
11234For example, to connect to port 2828 on a
11235terminal server named @code{manyfarms}:
11236
11237@smallexample
11238target remote manyfarms:2828
11239@end smallexample
11240
11241If your remote target is actually running on the same machine as
11242your debugger session (e.g.@: a simulator of your target running on
11243the same host), you can omit the hostname. For example, to connect
11244to port 1234 on your local machine:
11245
11246@smallexample
11247target remote :1234
11248@end smallexample
11249@noindent
11250
11251Note that the colon is still required here.
11252
11253@cindex UDP port, @code{target remote}
11254To use a UDP connection, use an argument of the form
11255@code{udp:@var{host}:@var{port}}. For example, to connect to UDP port 2828
11256on a terminal server named @code{manyfarms}:
11257
11258@smallexample
11259target remote udp:manyfarms:2828
11260@end smallexample
11261
11262When using a UDP connection for remote debugging, you should keep in mind
11263that the `U' stands for ``Unreliable''. UDP can silently drop packets on
11264busy or unreliable networks, which will cause havoc with your debugging
11265session.
11266
11267Now you can use all the usual commands to examine and change data and to
11268step and continue the remote program.
11269
11270@cindex interrupting remote programs
11271@cindex remote programs, interrupting
11272Whenever @value{GDBN} is waiting for the remote program, if you type the
11273interrupt character (often @key{C-C}), @value{GDBN} attempts to stop the
11274program. This may or may not succeed, depending in part on the hardware
11275and the serial drivers the remote system uses. If you type the
11276interrupt character once again, @value{GDBN} displays this prompt:
11277
11278@smallexample
11279Interrupted while waiting for the program.
11280Give up (and stop debugging it)? (y or n)
11281@end smallexample
11282
11283If you type @kbd{y}, @value{GDBN} abandons the remote debugging session.
11284(If you decide you want to try again later, you can use @samp{target
11285remote} again to connect once more.) If you type @kbd{n}, @value{GDBN}
11286goes back to waiting.
11287
11288@table @code
11289@kindex detach (remote)
11290@item detach
11291When you have finished debugging the remote program, you can use the
11292@code{detach} command to release it from @value{GDBN} control.
11293Detaching from the target normally resumes its execution, but the results
11294will depend on your particular remote stub. After the @code{detach}
11295command, @value{GDBN} is free to connect to another target.
11296
11297@kindex disconnect
11298@item disconnect
11299The @code{disconnect} command behaves like @code{detach}, except that
11300the target is generally not resumed. It will wait for @value{GDBN}
11301(this instance or another one) to connect and continue debugging. After
11302the @code{disconnect} command, @value{GDBN} is again free to connect to
11303another target.
11304@end table
11305
6f05cf9f
AC
11306@node Server
11307@section Using the @code{gdbserver} program
11308
11309@kindex gdbserver
11310@cindex remote connection without stubs
11311@code{gdbserver} is a control program for Unix-like systems, which
11312allows you to connect your program with a remote @value{GDBN} via
11313@code{target remote}---but without linking in the usual debugging stub.
11314
11315@code{gdbserver} is not a complete replacement for the debugging stubs,
11316because it requires essentially the same operating-system facilities
11317that @value{GDBN} itself does. In fact, a system that can run
11318@code{gdbserver} to connect to a remote @value{GDBN} could also run
11319@value{GDBN} locally! @code{gdbserver} is sometimes useful nevertheless,
11320because it is a much smaller program than @value{GDBN} itself. It is
11321also easier to port than all of @value{GDBN}, so you may be able to get
11322started more quickly on a new system by using @code{gdbserver}.
11323Finally, if you develop code for real-time systems, you may find that
11324the tradeoffs involved in real-time operation make it more convenient to
11325do as much development work as possible on another system, for example
11326by cross-compiling. You can use @code{gdbserver} to make a similar
11327choice for debugging.
11328
11329@value{GDBN} and @code{gdbserver} communicate via either a serial line
11330or a TCP connection, using the standard @value{GDBN} remote serial
11331protocol.
11332
11333@table @emph
11334@item On the target machine,
11335you need to have a copy of the program you want to debug.
11336@code{gdbserver} does not need your program's symbol table, so you can
11337strip the program if necessary to save space. @value{GDBN} on the host
11338system does all the symbol handling.
11339
11340To use the server, you must tell it how to communicate with @value{GDBN};
56460a61 11341the name of your program; and the arguments for your program. The usual
6f05cf9f
AC
11342syntax is:
11343
11344@smallexample
11345target> gdbserver @var{comm} @var{program} [ @var{args} @dots{} ]
11346@end smallexample
11347
11348@var{comm} is either a device name (to use a serial line) or a TCP
11349hostname and portnumber. For example, to debug Emacs with the argument
11350@samp{foo.txt} and communicate with @value{GDBN} over the serial port
11351@file{/dev/com1}:
11352
11353@smallexample
11354target> gdbserver /dev/com1 emacs foo.txt
11355@end smallexample
11356
11357@code{gdbserver} waits passively for the host @value{GDBN} to communicate
11358with it.
11359
11360To use a TCP connection instead of a serial line:
11361
11362@smallexample
11363target> gdbserver host:2345 emacs foo.txt
11364@end smallexample
11365
11366The only difference from the previous example is the first argument,
11367specifying that you are communicating with the host @value{GDBN} via
11368TCP. The @samp{host:2345} argument means that @code{gdbserver} is to
11369expect a TCP connection from machine @samp{host} to local TCP port 2345.
11370(Currently, the @samp{host} part is ignored.) You can choose any number
11371you want for the port number as long as it does not conflict with any
11372TCP ports already in use on the target system (for example, @code{23} is
11373reserved for @code{telnet}).@footnote{If you choose a port number that
11374conflicts with another service, @code{gdbserver} prints an error message
11375and exits.} You must use the same port number with the host @value{GDBN}
11376@code{target remote} command.
11377
56460a61
DJ
11378On some targets, @code{gdbserver} can also attach to running programs.
11379This is accomplished via the @code{--attach} argument. The syntax is:
11380
11381@smallexample
11382target> gdbserver @var{comm} --attach @var{pid}
11383@end smallexample
11384
11385@var{pid} is the process ID of a currently running process. It isn't necessary
11386to point @code{gdbserver} at a binary for the running process.
11387
b1fe9455
DJ
11388@pindex pidof
11389@cindex attach to a program by name
11390You can debug processes by name instead of process ID if your target has the
11391@code{pidof} utility:
11392
11393@smallexample
11394target> gdbserver @var{comm} --attach `pidof @var{PROGRAM}`
11395@end smallexample
11396
11397In case more than one copy of @var{PROGRAM} is running, or @var{PROGRAM}
11398has multiple threads, most versions of @code{pidof} support the
11399@code{-s} option to only return the first process ID.
11400
07f31aa6
DJ
11401@item On the host machine,
11402connect to your target (@pxref{Connecting,,Connecting to a remote target}).
6f05cf9f
AC
11403For TCP connections, you must start up @code{gdbserver} prior to using
11404the @code{target remote} command. Otherwise you may get an error whose
11405text depends on the host system, but which usually looks something like
07f31aa6
DJ
11406@samp{Connection refused}. You don't need to use the @code{load}
11407command in @value{GDBN} when using gdbserver, since the program is
11408already on the target.
11409
6f05cf9f
AC
11410@end table
11411
11412@node NetWare
11413@section Using the @code{gdbserve.nlm} program
11414
11415@kindex gdbserve.nlm
11416@code{gdbserve.nlm} is a control program for NetWare systems, which
11417allows you to connect your program with a remote @value{GDBN} via
11418@code{target remote}.
11419
11420@value{GDBN} and @code{gdbserve.nlm} communicate via a serial line,
11421using the standard @value{GDBN} remote serial protocol.
11422
11423@table @emph
11424@item On the target machine,
11425you need to have a copy of the program you want to debug.
11426@code{gdbserve.nlm} does not need your program's symbol table, so you
11427can strip the program if necessary to save space. @value{GDBN} on the
11428host system does all the symbol handling.
11429
11430To use the server, you must tell it how to communicate with
11431@value{GDBN}; the name of your program; and the arguments for your
11432program. The syntax is:
11433
11434@smallexample
11435load gdbserve [ BOARD=@var{board} ] [ PORT=@var{port} ]
11436 [ BAUD=@var{baud} ] @var{program} [ @var{args} @dots{} ]
11437@end smallexample
11438
11439@var{board} and @var{port} specify the serial line; @var{baud} specifies
11440the baud rate used by the connection. @var{port} and @var{node} default
11441to 0, @var{baud} defaults to 9600@dmn{bps}.
11442
11443For example, to debug Emacs with the argument @samp{foo.txt}and
11444communicate with @value{GDBN} over serial port number 2 or board 1
11445using a 19200@dmn{bps} connection:
11446
11447@smallexample
11448load gdbserve BOARD=1 PORT=2 BAUD=19200 emacs foo.txt
11449@end smallexample
11450
07f31aa6
DJ
11451@item
11452On the @value{GDBN} host machine, connect to your target (@pxref{Connecting,,
11453Connecting to a remote target}).
6f05cf9f 11454
6f05cf9f
AC
11455@end table
11456
501eef12
AC
11457@node Remote configuration
11458@section Remote configuration
11459
11460The following configuration options are available when debugging remote
11461programs:
11462
11463@table @code
11464@kindex set remote hardware-watchpoint-limit
11465@kindex set remote hardware-breakpoint-limit
11466@anchor{set remote hardware-watchpoint-limit}
11467@anchor{set remote hardware-breakpoint-limit}
11468@item set remote hardware-watchpoint-limit @var{limit}
11469@itemx set remote hardware-breakpoint-limit @var{limit}
11470Restrict @value{GDBN} to using @var{limit} remote hardware breakpoint or
11471watchpoints. A limit of -1, the default, is treated as unlimited.
11472@end table
11473
6f05cf9f
AC
11474@node remote stub
11475@section Implementing a remote stub
7a292a7a 11476
8e04817f
AC
11477@cindex debugging stub, example
11478@cindex remote stub, example
11479@cindex stub example, remote debugging
11480The stub files provided with @value{GDBN} implement the target side of the
11481communication protocol, and the @value{GDBN} side is implemented in the
11482@value{GDBN} source file @file{remote.c}. Normally, you can simply allow
11483these subroutines to communicate, and ignore the details. (If you're
11484implementing your own stub file, you can still ignore the details: start
11485with one of the existing stub files. @file{sparc-stub.c} is the best
11486organized, and therefore the easiest to read.)
11487
104c1213
JM
11488@cindex remote serial debugging, overview
11489To debug a program running on another machine (the debugging
11490@dfn{target} machine), you must first arrange for all the usual
11491prerequisites for the program to run by itself. For example, for a C
11492program, you need:
c906108c 11493
104c1213
JM
11494@enumerate
11495@item
11496A startup routine to set up the C runtime environment; these usually
11497have a name like @file{crt0}. The startup routine may be supplied by
11498your hardware supplier, or you may have to write your own.
96baa820 11499
5d161b24 11500@item
d4f3574e 11501A C subroutine library to support your program's
104c1213 11502subroutine calls, notably managing input and output.
96baa820 11503
104c1213
JM
11504@item
11505A way of getting your program to the other machine---for example, a
11506download program. These are often supplied by the hardware
11507manufacturer, but you may have to write your own from hardware
11508documentation.
11509@end enumerate
96baa820 11510
104c1213
JM
11511The next step is to arrange for your program to use a serial port to
11512communicate with the machine where @value{GDBN} is running (the @dfn{host}
11513machine). In general terms, the scheme looks like this:
96baa820 11514
104c1213
JM
11515@table @emph
11516@item On the host,
11517@value{GDBN} already understands how to use this protocol; when everything
11518else is set up, you can simply use the @samp{target remote} command
11519(@pxref{Targets,,Specifying a Debugging Target}).
11520
11521@item On the target,
11522you must link with your program a few special-purpose subroutines that
11523implement the @value{GDBN} remote serial protocol. The file containing these
11524subroutines is called a @dfn{debugging stub}.
11525
11526On certain remote targets, you can use an auxiliary program
11527@code{gdbserver} instead of linking a stub into your program.
11528@xref{Server,,Using the @code{gdbserver} program}, for details.
11529@end table
96baa820 11530
104c1213
JM
11531The debugging stub is specific to the architecture of the remote
11532machine; for example, use @file{sparc-stub.c} to debug programs on
11533@sc{sparc} boards.
96baa820 11534
104c1213
JM
11535@cindex remote serial stub list
11536These working remote stubs are distributed with @value{GDBN}:
96baa820 11537
104c1213
JM
11538@table @code
11539
11540@item i386-stub.c
41afff9a 11541@cindex @file{i386-stub.c}
104c1213
JM
11542@cindex Intel
11543@cindex i386
11544For Intel 386 and compatible architectures.
11545
11546@item m68k-stub.c
41afff9a 11547@cindex @file{m68k-stub.c}
104c1213
JM
11548@cindex Motorola 680x0
11549@cindex m680x0
11550For Motorola 680x0 architectures.
11551
11552@item sh-stub.c
41afff9a 11553@cindex @file{sh-stub.c}
172c2a43 11554@cindex Renesas
104c1213 11555@cindex SH
172c2a43 11556For Renesas SH architectures.
104c1213
JM
11557
11558@item sparc-stub.c
41afff9a 11559@cindex @file{sparc-stub.c}
104c1213
JM
11560@cindex Sparc
11561For @sc{sparc} architectures.
11562
11563@item sparcl-stub.c
41afff9a 11564@cindex @file{sparcl-stub.c}
104c1213
JM
11565@cindex Fujitsu
11566@cindex SparcLite
11567For Fujitsu @sc{sparclite} architectures.
11568
11569@end table
11570
11571The @file{README} file in the @value{GDBN} distribution may list other
11572recently added stubs.
11573
11574@menu
11575* Stub Contents:: What the stub can do for you
11576* Bootstrapping:: What you must do for the stub
11577* Debug Session:: Putting it all together
104c1213
JM
11578@end menu
11579
6d2ebf8b 11580@node Stub Contents
6f05cf9f 11581@subsection What the stub can do for you
104c1213
JM
11582
11583@cindex remote serial stub
11584The debugging stub for your architecture supplies these three
11585subroutines:
11586
11587@table @code
11588@item set_debug_traps
4644b6e3 11589@findex set_debug_traps
104c1213
JM
11590@cindex remote serial stub, initialization
11591This routine arranges for @code{handle_exception} to run when your
11592program stops. You must call this subroutine explicitly near the
11593beginning of your program.
11594
11595@item handle_exception
4644b6e3 11596@findex handle_exception
104c1213
JM
11597@cindex remote serial stub, main routine
11598This is the central workhorse, but your program never calls it
11599explicitly---the setup code arranges for @code{handle_exception} to
11600run when a trap is triggered.
11601
11602@code{handle_exception} takes control when your program stops during
11603execution (for example, on a breakpoint), and mediates communications
11604with @value{GDBN} on the host machine. This is where the communications
11605protocol is implemented; @code{handle_exception} acts as the @value{GDBN}
d4f3574e 11606representative on the target machine. It begins by sending summary
104c1213
JM
11607information on the state of your program, then continues to execute,
11608retrieving and transmitting any information @value{GDBN} needs, until you
11609execute a @value{GDBN} command that makes your program resume; at that point,
11610@code{handle_exception} returns control to your own code on the target
5d161b24 11611machine.
104c1213
JM
11612
11613@item breakpoint
11614@cindex @code{breakpoint} subroutine, remote
11615Use this auxiliary subroutine to make your program contain a
11616breakpoint. Depending on the particular situation, this may be the only
11617way for @value{GDBN} to get control. For instance, if your target
11618machine has some sort of interrupt button, you won't need to call this;
11619pressing the interrupt button transfers control to
11620@code{handle_exception}---in effect, to @value{GDBN}. On some machines,
11621simply receiving characters on the serial port may also trigger a trap;
11622again, in that situation, you don't need to call @code{breakpoint} from
11623your own program---simply running @samp{target remote} from the host
5d161b24 11624@value{GDBN} session gets control.
104c1213
JM
11625
11626Call @code{breakpoint} if none of these is true, or if you simply want
11627to make certain your program stops at a predetermined point for the
11628start of your debugging session.
11629@end table
11630
6d2ebf8b 11631@node Bootstrapping
6f05cf9f 11632@subsection What you must do for the stub
104c1213
JM
11633
11634@cindex remote stub, support routines
11635The debugging stubs that come with @value{GDBN} are set up for a particular
11636chip architecture, but they have no information about the rest of your
11637debugging target machine.
11638
11639First of all you need to tell the stub how to communicate with the
11640serial port.
11641
11642@table @code
11643@item int getDebugChar()
4644b6e3 11644@findex getDebugChar
104c1213
JM
11645Write this subroutine to read a single character from the serial port.
11646It may be identical to @code{getchar} for your target system; a
11647different name is used to allow you to distinguish the two if you wish.
11648
11649@item void putDebugChar(int)
4644b6e3 11650@findex putDebugChar
104c1213 11651Write this subroutine to write a single character to the serial port.
5d161b24 11652It may be identical to @code{putchar} for your target system; a
104c1213
JM
11653different name is used to allow you to distinguish the two if you wish.
11654@end table
11655
11656@cindex control C, and remote debugging
11657@cindex interrupting remote targets
11658If you want @value{GDBN} to be able to stop your program while it is
11659running, you need to use an interrupt-driven serial driver, and arrange
11660for it to stop when it receives a @code{^C} (@samp{\003}, the control-C
11661character). That is the character which @value{GDBN} uses to tell the
11662remote system to stop.
11663
11664Getting the debugging target to return the proper status to @value{GDBN}
11665probably requires changes to the standard stub; one quick and dirty way
11666is to just execute a breakpoint instruction (the ``dirty'' part is that
11667@value{GDBN} reports a @code{SIGTRAP} instead of a @code{SIGINT}).
11668
11669Other routines you need to supply are:
11670
11671@table @code
11672@item void exceptionHandler (int @var{exception_number}, void *@var{exception_address})
4644b6e3 11673@findex exceptionHandler
104c1213
JM
11674Write this function to install @var{exception_address} in the exception
11675handling tables. You need to do this because the stub does not have any
11676way of knowing what the exception handling tables on your target system
11677are like (for example, the processor's table might be in @sc{rom},
11678containing entries which point to a table in @sc{ram}).
11679@var{exception_number} is the exception number which should be changed;
11680its meaning is architecture-dependent (for example, different numbers
11681might represent divide by zero, misaligned access, etc). When this
11682exception occurs, control should be transferred directly to
11683@var{exception_address}, and the processor state (stack, registers,
11684and so on) should be just as it is when a processor exception occurs. So if
11685you want to use a jump instruction to reach @var{exception_address}, it
11686should be a simple jump, not a jump to subroutine.
11687
11688For the 386, @var{exception_address} should be installed as an interrupt
11689gate so that interrupts are masked while the handler runs. The gate
11690should be at privilege level 0 (the most privileged level). The
11691@sc{sparc} and 68k stubs are able to mask interrupts themselves without
11692help from @code{exceptionHandler}.
11693
11694@item void flush_i_cache()
4644b6e3 11695@findex flush_i_cache
d4f3574e 11696On @sc{sparc} and @sc{sparclite} only, write this subroutine to flush the
104c1213
JM
11697instruction cache, if any, on your target machine. If there is no
11698instruction cache, this subroutine may be a no-op.
11699
11700On target machines that have instruction caches, @value{GDBN} requires this
11701function to make certain that the state of your program is stable.
11702@end table
11703
11704@noindent
11705You must also make sure this library routine is available:
11706
11707@table @code
11708@item void *memset(void *, int, int)
4644b6e3 11709@findex memset
104c1213
JM
11710This is the standard library function @code{memset} that sets an area of
11711memory to a known value. If you have one of the free versions of
11712@code{libc.a}, @code{memset} can be found there; otherwise, you must
11713either obtain it from your hardware manufacturer, or write your own.
11714@end table
11715
11716If you do not use the GNU C compiler, you may need other standard
11717library subroutines as well; this varies from one stub to another,
11718but in general the stubs are likely to use any of the common library
d4f3574e 11719subroutines which @code{@value{GCC}} generates as inline code.
104c1213
JM
11720
11721
6d2ebf8b 11722@node Debug Session
6f05cf9f 11723@subsection Putting it all together
104c1213
JM
11724
11725@cindex remote serial debugging summary
11726In summary, when your program is ready to debug, you must follow these
11727steps.
11728
11729@enumerate
11730@item
6d2ebf8b 11731Make sure you have defined the supporting low-level routines
104c1213
JM
11732(@pxref{Bootstrapping,,What you must do for the stub}):
11733@display
11734@code{getDebugChar}, @code{putDebugChar},
11735@code{flush_i_cache}, @code{memset}, @code{exceptionHandler}.
11736@end display
11737
11738@item
11739Insert these lines near the top of your program:
11740
474c8240 11741@smallexample
104c1213
JM
11742set_debug_traps();
11743breakpoint();
474c8240 11744@end smallexample
104c1213
JM
11745
11746@item
11747For the 680x0 stub only, you need to provide a variable called
11748@code{exceptionHook}. Normally you just use:
11749
474c8240 11750@smallexample
104c1213 11751void (*exceptionHook)() = 0;
474c8240 11752@end smallexample
104c1213 11753
d4f3574e 11754@noindent
104c1213 11755but if before calling @code{set_debug_traps}, you set it to point to a
598ca718 11756function in your program, that function is called when
104c1213
JM
11757@code{@value{GDBN}} continues after stopping on a trap (for example, bus
11758error). The function indicated by @code{exceptionHook} is called with
11759one parameter: an @code{int} which is the exception number.
11760
11761@item
11762Compile and link together: your program, the @value{GDBN} debugging stub for
11763your target architecture, and the supporting subroutines.
11764
11765@item
11766Make sure you have a serial connection between your target machine and
11767the @value{GDBN} host, and identify the serial port on the host.
11768
11769@item
11770@c The "remote" target now provides a `load' command, so we should
11771@c document that. FIXME.
11772Download your program to your target machine (or get it there by
11773whatever means the manufacturer provides), and start it.
11774
11775@item
07f31aa6
DJ
11776Start @value{GDBN} on the host, and connect to the target
11777(@pxref{Connecting,,Connecting to a remote target}).
9db8d71f 11778
104c1213
JM
11779@end enumerate
11780
8e04817f
AC
11781@node Configurations
11782@chapter Configuration-Specific Information
104c1213 11783
8e04817f
AC
11784While nearly all @value{GDBN} commands are available for all native and
11785cross versions of the debugger, there are some exceptions. This chapter
11786describes things that are only available in certain configurations.
104c1213 11787
8e04817f
AC
11788There are three major categories of configurations: native
11789configurations, where the host and target are the same, embedded
11790operating system configurations, which are usually the same for several
11791different processor architectures, and bare embedded processors, which
11792are quite different from each other.
104c1213 11793
8e04817f
AC
11794@menu
11795* Native::
11796* Embedded OS::
11797* Embedded Processors::
11798* Architectures::
11799@end menu
104c1213 11800
8e04817f
AC
11801@node Native
11802@section Native
104c1213 11803
8e04817f
AC
11804This section describes details specific to particular native
11805configurations.
6cf7e474 11806
8e04817f
AC
11807@menu
11808* HP-UX:: HP-UX
7561d450 11809* BSD libkvm Interface:: Debugging BSD kernel memory images
8e04817f
AC
11810* SVR4 Process Information:: SVR4 process information
11811* DJGPP Native:: Features specific to the DJGPP port
78c47bea 11812* Cygwin Native:: Features specific to the Cygwin port
8e04817f 11813@end menu
6cf7e474 11814
8e04817f
AC
11815@node HP-UX
11816@subsection HP-UX
104c1213 11817
8e04817f
AC
11818On HP-UX systems, if you refer to a function or variable name that
11819begins with a dollar sign, @value{GDBN} searches for a user or system
11820name first, before it searches for a convenience variable.
104c1213 11821
7561d450
MK
11822@node BSD libkvm Interface
11823@subsection BSD libkvm Interface
11824
11825@cindex libkvm
11826@cindex kernel memory image
11827@cindex kernel crash dump
11828
11829BSD-derived systems (FreeBSD/NetBSD/OpenBSD) have a kernel memory
11830interface that provides a uniform interface for accessing kernel virtual
11831memory images, including live systems and crash dumps. @value{GDBN}
11832uses this interface to allow you to debug live kernels and kernel crash
11833dumps on many native BSD configurations. This is implemented as a
11834special @code{kvm} debugging target. For debugging a live system, load
11835the currently running kernel into @value{GDBN} and connect to the
11836@code{kvm} target:
11837
11838@smallexample
11839(@value{GDBP}) @b{target kvm}
11840@end smallexample
11841
11842For debugging crash dumps, provide the file name of the crash dump as an
11843argument:
11844
11845@smallexample
11846(@value{GDBP}) @b{target kvm /var/crash/bsd.0}
11847@end smallexample
11848
11849Once connected to the @code{kvm} target, the following commands are
11850available:
11851
11852@table @code
11853@kindex kvm
11854@item kvm pcb
11855Set current context from pcb address.
11856
11857@item kvm proc
11858Set current context from proc address. This command isn't available on
11859modern FreeBSD systems.
11860@end table
11861
8e04817f
AC
11862@node SVR4 Process Information
11863@subsection SVR4 process information
60bf7e09
EZ
11864@cindex /proc
11865@cindex examine process image
11866@cindex process info via @file{/proc}
104c1213 11867
60bf7e09
EZ
11868Many versions of SVR4 and compatible systems provide a facility called
11869@samp{/proc} that can be used to examine the image of a running
11870process using file-system subroutines. If @value{GDBN} is configured
11871for an operating system with this facility, the command @code{info
11872proc} is available to report information about the process running
11873your program, or about any process running on your system. @code{info
11874proc} works only on SVR4 systems that include the @code{procfs} code.
11875This includes, as of this writing, @sc{gnu}/Linux, OSF/1 (Digital
11876Unix), Solaris, Irix, and Unixware, but not HP-UX, for example.
104c1213 11877
8e04817f
AC
11878@table @code
11879@kindex info proc
60bf7e09 11880@cindex process ID
8e04817f 11881@item info proc
60bf7e09
EZ
11882@itemx info proc @var{process-id}
11883Summarize available information about any running process. If a
11884process ID is specified by @var{process-id}, display information about
11885that process; otherwise display information about the program being
11886debugged. The summary includes the debugged process ID, the command
11887line used to invoke it, its current working directory, and its
11888executable file's absolute file name.
11889
11890On some systems, @var{process-id} can be of the form
11891@samp{[@var{pid}]/@var{tid}} which specifies a certain thread ID
11892within a process. If the optional @var{pid} part is missing, it means
11893a thread from the process being debugged (the leading @samp{/} still
11894needs to be present, or else @value{GDBN} will interpret the number as
11895a process ID rather than a thread ID).
6cf7e474 11896
8e04817f 11897@item info proc mappings
60bf7e09
EZ
11898@cindex memory address space mappings
11899Report the memory address space ranges accessible in the program, with
11900information on whether the process has read, write, or execute access
11901rights to each range. On @sc{gnu}/Linux systems, each memory range
11902includes the object file which is mapped to that range, instead of the
11903memory access rights to that range.
11904
11905@item info proc stat
11906@itemx info proc status
11907@cindex process detailed status information
11908These subcommands are specific to @sc{gnu}/Linux systems. They show
11909the process-related information, including the user ID and group ID;
11910how many threads are there in the process; its virtual memory usage;
11911the signals that are pending, blocked, and ignored; its TTY; its
11912consumption of system and user time; its stack size; its @samp{nice}
11913value; etc. For more information, see the @samp{proc(5)} man page
11914(type @kbd{man 5 proc} from your shell prompt).
11915
11916@item info proc all
11917Show all the information about the process described under all of the
11918above @code{info proc} subcommands.
11919
8e04817f
AC
11920@ignore
11921@comment These sub-options of 'info proc' were not included when
11922@comment procfs.c was re-written. Keep their descriptions around
11923@comment against the day when someone finds the time to put them back in.
11924@kindex info proc times
11925@item info proc times
11926Starting time, user CPU time, and system CPU time for your program and
11927its children.
6cf7e474 11928
8e04817f
AC
11929@kindex info proc id
11930@item info proc id
11931Report on the process IDs related to your program: its own process ID,
11932the ID of its parent, the process group ID, and the session ID.
8e04817f
AC
11933@end ignore
11934@end table
104c1213 11935
8e04817f
AC
11936@node DJGPP Native
11937@subsection Features for Debugging @sc{djgpp} Programs
11938@cindex @sc{djgpp} debugging
11939@cindex native @sc{djgpp} debugging
11940@cindex MS-DOS-specific commands
104c1213 11941
8e04817f
AC
11942@sc{djgpp} is the port of @sc{gnu} development tools to MS-DOS and
11943MS-Windows. @sc{djgpp} programs are 32-bit protected-mode programs
11944that use the @dfn{DPMI} (DOS Protected-Mode Interface) API to run on
11945top of real-mode DOS systems and their emulations.
104c1213 11946
8e04817f
AC
11947@value{GDBN} supports native debugging of @sc{djgpp} programs, and
11948defines a few commands specific to the @sc{djgpp} port. This
11949subsection describes those commands.
104c1213 11950
8e04817f
AC
11951@table @code
11952@kindex info dos
11953@item info dos
11954This is a prefix of @sc{djgpp}-specific commands which print
11955information about the target system and important OS structures.
f1251bdd 11956
8e04817f
AC
11957@kindex sysinfo
11958@cindex MS-DOS system info
11959@cindex free memory information (MS-DOS)
11960@item info dos sysinfo
11961This command displays assorted information about the underlying
11962platform: the CPU type and features, the OS version and flavor, the
11963DPMI version, and the available conventional and DPMI memory.
104c1213 11964
8e04817f
AC
11965@cindex GDT
11966@cindex LDT
11967@cindex IDT
11968@cindex segment descriptor tables
11969@cindex descriptor tables display
11970@item info dos gdt
11971@itemx info dos ldt
11972@itemx info dos idt
11973These 3 commands display entries from, respectively, Global, Local,
11974and Interrupt Descriptor Tables (GDT, LDT, and IDT). The descriptor
11975tables are data structures which store a descriptor for each segment
11976that is currently in use. The segment's selector is an index into a
11977descriptor table; the table entry for that index holds the
11978descriptor's base address and limit, and its attributes and access
11979rights.
104c1213 11980
8e04817f
AC
11981A typical @sc{djgpp} program uses 3 segments: a code segment, a data
11982segment (used for both data and the stack), and a DOS segment (which
11983allows access to DOS/BIOS data structures and absolute addresses in
11984conventional memory). However, the DPMI host will usually define
11985additional segments in order to support the DPMI environment.
d4f3574e 11986
8e04817f
AC
11987@cindex garbled pointers
11988These commands allow to display entries from the descriptor tables.
11989Without an argument, all entries from the specified table are
11990displayed. An argument, which should be an integer expression, means
11991display a single entry whose index is given by the argument. For
11992example, here's a convenient way to display information about the
11993debugged program's data segment:
104c1213 11994
8e04817f
AC
11995@smallexample
11996@exdent @code{(@value{GDBP}) info dos ldt $ds}
11997@exdent @code{0x13f: base=0x11970000 limit=0x0009ffff 32-Bit Data (Read/Write, Exp-up)}
11998@end smallexample
104c1213 11999
8e04817f
AC
12000@noindent
12001This comes in handy when you want to see whether a pointer is outside
12002the data segment's limit (i.e.@: @dfn{garbled}).
104c1213 12003
8e04817f
AC
12004@cindex page tables display (MS-DOS)
12005@item info dos pde
12006@itemx info dos pte
12007These two commands display entries from, respectively, the Page
12008Directory and the Page Tables. Page Directories and Page Tables are
12009data structures which control how virtual memory addresses are mapped
12010into physical addresses. A Page Table includes an entry for every
12011page of memory that is mapped into the program's address space; there
12012may be several Page Tables, each one holding up to 4096 entries. A
12013Page Directory has up to 4096 entries, one each for every Page Table
12014that is currently in use.
104c1213 12015
8e04817f
AC
12016Without an argument, @kbd{info dos pde} displays the entire Page
12017Directory, and @kbd{info dos pte} displays all the entries in all of
12018the Page Tables. An argument, an integer expression, given to the
12019@kbd{info dos pde} command means display only that entry from the Page
12020Directory table. An argument given to the @kbd{info dos pte} command
12021means display entries from a single Page Table, the one pointed to by
12022the specified entry in the Page Directory.
104c1213 12023
8e04817f
AC
12024@cindex direct memory access (DMA) on MS-DOS
12025These commands are useful when your program uses @dfn{DMA} (Direct
12026Memory Access), which needs physical addresses to program the DMA
12027controller.
104c1213 12028
8e04817f 12029These commands are supported only with some DPMI servers.
104c1213 12030
8e04817f
AC
12031@cindex physical address from linear address
12032@item info dos address-pte @var{addr}
12033This command displays the Page Table entry for a specified linear
12034address. The argument linear address @var{addr} should already have the
12035appropriate segment's base address added to it, because this command
12036accepts addresses which may belong to @emph{any} segment. For
12037example, here's how to display the Page Table entry for the page where
12038the variable @code{i} is stored:
104c1213 12039
b383017d 12040@smallexample
8e04817f
AC
12041@exdent @code{(@value{GDBP}) info dos address-pte __djgpp_base_address + (char *)&i}
12042@exdent @code{Page Table entry for address 0x11a00d30:}
b383017d 12043@exdent @code{Base=0x02698000 Dirty Acc. Not-Cached Write-Back Usr Read-Write +0xd30}
8e04817f 12044@end smallexample
104c1213 12045
8e04817f
AC
12046@noindent
12047This says that @code{i} is stored at offset @code{0xd30} from the page
12048whose physical base address is @code{0x02698000}, and prints all the
12049attributes of that page.
104c1213 12050
8e04817f
AC
12051Note that you must cast the addresses of variables to a @code{char *},
12052since otherwise the value of @code{__djgpp_base_address}, the base
12053address of all variables and functions in a @sc{djgpp} program, will
12054be added using the rules of C pointer arithmetics: if @code{i} is
12055declared an @code{int}, @value{GDBN} will add 4 times the value of
12056@code{__djgpp_base_address} to the address of @code{i}.
104c1213 12057
8e04817f
AC
12058Here's another example, it displays the Page Table entry for the
12059transfer buffer:
104c1213 12060
8e04817f
AC
12061@smallexample
12062@exdent @code{(@value{GDBP}) info dos address-pte *((unsigned *)&_go32_info_block + 3)}
12063@exdent @code{Page Table entry for address 0x29110:}
12064@exdent @code{Base=0x00029000 Dirty Acc. Not-Cached Write-Back Usr Read-Write +0x110}
12065@end smallexample
104c1213 12066
8e04817f
AC
12067@noindent
12068(The @code{+ 3} offset is because the transfer buffer's address is the
120693rd member of the @code{_go32_info_block} structure.) The output of
12070this command clearly shows that addresses in conventional memory are
12071mapped 1:1, i.e.@: the physical and linear addresses are identical.
104c1213 12072
8e04817f
AC
12073This command is supported only with some DPMI servers.
12074@end table
104c1213 12075
78c47bea
PM
12076@node Cygwin Native
12077@subsection Features for Debugging MS Windows PE executables
12078@cindex MS Windows debugging
12079@cindex native Cygwin debugging
12080@cindex Cygwin-specific commands
12081
be448670
CF
12082@value{GDBN} supports native debugging of MS Windows programs, including
12083DLLs with and without symbolic debugging information. There are various
12084additional Cygwin-specific commands, described in this subsection. The
12085subsubsection @pxref{Non-debug DLL symbols} describes working with DLLs
12086that have no debugging symbols.
12087
78c47bea
PM
12088
12089@table @code
12090@kindex info w32
12091@item info w32
12092This is a prefix of MS Windows specific commands which print
12093information about the target system and important OS structures.
12094
12095@item info w32 selector
12096This command displays information returned by
12097the Win32 API @code{GetThreadSelectorEntry} function.
12098It takes an optional argument that is evaluated to
12099a long value to give the information about this given selector.
12100Without argument, this command displays information
12101about the the six segment registers.
12102
12103@kindex info dll
12104@item info dll
12105This is a Cygwin specific alias of info shared.
12106
12107@kindex dll-symbols
12108@item dll-symbols
12109This command loads symbols from a dll similarly to
12110add-sym command but without the need to specify a base address.
12111
b383017d 12112@kindex set new-console
78c47bea 12113@item set new-console @var{mode}
b383017d 12114If @var{mode} is @code{on} the debuggee will
78c47bea
PM
12115be started in a new console on next start.
12116If @var{mode} is @code{off}i, the debuggee will
12117be started in the same console as the debugger.
12118
12119@kindex show new-console
12120@item show new-console
12121Displays whether a new console is used
12122when the debuggee is started.
12123
12124@kindex set new-group
12125@item set new-group @var{mode}
12126This boolean value controls whether the debuggee should
12127start a new group or stay in the same group as the debugger.
12128This affects the way the Windows OS handles
12129Ctrl-C.
12130
12131@kindex show new-group
12132@item show new-group
12133Displays current value of new-group boolean.
12134
12135@kindex set debugevents
12136@item set debugevents
12137This boolean value adds debug output concerning events seen by the debugger.
12138
12139@kindex set debugexec
12140@item set debugexec
b383017d 12141This boolean value adds debug output concerning execute events
78c47bea
PM
12142seen by the debugger.
12143
12144@kindex set debugexceptions
12145@item set debugexceptions
b383017d 12146This boolean value adds debug ouptut concerning exception events
78c47bea
PM
12147seen by the debugger.
12148
12149@kindex set debugmemory
12150@item set debugmemory
b383017d 12151This boolean value adds debug ouptut concerning memory events
78c47bea
PM
12152seen by the debugger.
12153
12154@kindex set shell
12155@item set shell
12156This boolean values specifies whether the debuggee is called
12157via a shell or directly (default value is on).
12158
12159@kindex show shell
12160@item show shell
12161Displays if the debuggee will be started with a shell.
12162
12163@end table
12164
be448670
CF
12165@menu
12166* Non-debug DLL symbols:: Support for DLLs without debugging symbols
12167@end menu
12168
12169@node Non-debug DLL symbols
12170@subsubsection Support for DLLs without debugging symbols
12171@cindex DLLs with no debugging symbols
12172@cindex Minimal symbols and DLLs
12173
12174Very often on windows, some of the DLLs that your program relies on do
12175not include symbolic debugging information (for example,
12176@file{kernel32.dll}). When @value{GDBN} doesn't recognize any debugging
12177symbols in a DLL, it relies on the minimal amount of symbolic
12178information contained in the DLL's export table. This subsubsection
12179describes working with such symbols, known internally to @value{GDBN} as
12180``minimal symbols''.
12181
12182Note that before the debugged program has started execution, no DLLs
12183will have been loaded. The easiest way around this problem is simply to
12184start the program --- either by setting a breakpoint or letting the
12185program run once to completion. It is also possible to force
12186@value{GDBN} to load a particular DLL before starting the executable ---
12187see the shared library information in @pxref{Files} or the
12188@code{dll-symbols} command in @pxref{Cygwin Native}. Currently,
12189explicitly loading symbols from a DLL with no debugging information will
12190cause the symbol names to be duplicated in @value{GDBN}'s lookup table,
12191which may adversely affect symbol lookup performance.
12192
12193@subsubsection DLL name prefixes
12194
12195In keeping with the naming conventions used by the Microsoft debugging
12196tools, DLL export symbols are made available with a prefix based on the
12197DLL name, for instance @code{KERNEL32!CreateFileA}. The plain name is
12198also entered into the symbol table, so @code{CreateFileA} is often
12199sufficient. In some cases there will be name clashes within a program
12200(particularly if the executable itself includes full debugging symbols)
12201necessitating the use of the fully qualified name when referring to the
12202contents of the DLL. Use single-quotes around the name to avoid the
12203exclamation mark (``!'') being interpreted as a language operator.
12204
12205Note that the internal name of the DLL may be all upper-case, even
12206though the file name of the DLL is lower-case, or vice-versa. Since
12207symbols within @value{GDBN} are @emph{case-sensitive} this may cause
12208some confusion. If in doubt, try the @code{info functions} and
12209@code{info variables} commands or even @code{maint print msymbols} (see
12210@pxref{Symbols}). Here's an example:
12211
12212@smallexample
f7dc1244 12213(@value{GDBP}) info function CreateFileA
be448670
CF
12214All functions matching regular expression "CreateFileA":
12215
12216Non-debugging symbols:
122170x77e885f4 CreateFileA
122180x77e885f4 KERNEL32!CreateFileA
12219@end smallexample
12220
12221@smallexample
f7dc1244 12222(@value{GDBP}) info function !
be448670
CF
12223All functions matching regular expression "!":
12224
12225Non-debugging symbols:
122260x6100114c cygwin1!__assert
122270x61004034 cygwin1!_dll_crt0@@0
122280x61004240 cygwin1!dll_crt0(per_process *)
12229[etc...]
12230@end smallexample
12231
12232@subsubsection Working with minimal symbols
12233
12234Symbols extracted from a DLL's export table do not contain very much
12235type information. All that @value{GDBN} can do is guess whether a symbol
12236refers to a function or variable depending on the linker section that
12237contains the symbol. Also note that the actual contents of the memory
12238contained in a DLL are not available unless the program is running. This
12239means that you cannot examine the contents of a variable or disassemble
12240a function within a DLL without a running program.
12241
12242Variables are generally treated as pointers and dereferenced
12243automatically. For this reason, it is often necessary to prefix a
12244variable name with the address-of operator (``&'') and provide explicit
12245type information in the command. Here's an example of the type of
12246problem:
12247
12248@smallexample
f7dc1244 12249(@value{GDBP}) print 'cygwin1!__argv'
be448670
CF
12250$1 = 268572168
12251@end smallexample
12252
12253@smallexample
f7dc1244 12254(@value{GDBP}) x 'cygwin1!__argv'
be448670
CF
122550x10021610: "\230y\""
12256@end smallexample
12257
12258And two possible solutions:
12259
12260@smallexample
f7dc1244 12261(@value{GDBP}) print ((char **)'cygwin1!__argv')[0]
be448670
CF
12262$2 = 0x22fd98 "/cygdrive/c/mydirectory/myprogram"
12263@end smallexample
12264
12265@smallexample
f7dc1244 12266(@value{GDBP}) x/2x &'cygwin1!__argv'
be448670 122670x610c0aa8 <cygwin1!__argv>: 0x10021608 0x00000000
f7dc1244 12268(@value{GDBP}) x/x 0x10021608
be448670 122690x10021608: 0x0022fd98
f7dc1244 12270(@value{GDBP}) x/s 0x0022fd98
be448670
CF
122710x22fd98: "/cygdrive/c/mydirectory/myprogram"
12272@end smallexample
12273
12274Setting a break point within a DLL is possible even before the program
12275starts execution. However, under these circumstances, @value{GDBN} can't
12276examine the initial instructions of the function in order to skip the
12277function's frame set-up code. You can work around this by using ``*&''
12278to set the breakpoint at a raw memory address:
12279
12280@smallexample
f7dc1244 12281(@value{GDBP}) break *&'python22!PyOS_Readline'
be448670
CF
12282Breakpoint 1 at 0x1e04eff0
12283@end smallexample
12284
12285The author of these extensions is not entirely convinced that setting a
12286break point within a shared DLL like @file{kernel32.dll} is completely
12287safe.
12288
8e04817f
AC
12289@node Embedded OS
12290@section Embedded Operating Systems
104c1213 12291
8e04817f
AC
12292This section describes configurations involving the debugging of
12293embedded operating systems that are available for several different
12294architectures.
d4f3574e 12295
8e04817f
AC
12296@menu
12297* VxWorks:: Using @value{GDBN} with VxWorks
12298@end menu
104c1213 12299
8e04817f
AC
12300@value{GDBN} includes the ability to debug programs running on
12301various real-time operating systems.
104c1213 12302
8e04817f
AC
12303@node VxWorks
12304@subsection Using @value{GDBN} with VxWorks
104c1213 12305
8e04817f 12306@cindex VxWorks
104c1213 12307
8e04817f 12308@table @code
104c1213 12309
8e04817f
AC
12310@kindex target vxworks
12311@item target vxworks @var{machinename}
12312A VxWorks system, attached via TCP/IP. The argument @var{machinename}
12313is the target system's machine name or IP address.
104c1213 12314
8e04817f 12315@end table
104c1213 12316
8e04817f
AC
12317On VxWorks, @code{load} links @var{filename} dynamically on the
12318current target system as well as adding its symbols in @value{GDBN}.
104c1213 12319
8e04817f
AC
12320@value{GDBN} enables developers to spawn and debug tasks running on networked
12321VxWorks targets from a Unix host. Already-running tasks spawned from
12322the VxWorks shell can also be debugged. @value{GDBN} uses code that runs on
12323both the Unix host and on the VxWorks target. The program
12324@code{@value{GDBP}} is installed and executed on the Unix host. (It may be
12325installed with the name @code{vxgdb}, to distinguish it from a
12326@value{GDBN} for debugging programs on the host itself.)
104c1213 12327
8e04817f
AC
12328@table @code
12329@item VxWorks-timeout @var{args}
12330@kindex vxworks-timeout
12331All VxWorks-based targets now support the option @code{vxworks-timeout}.
12332This option is set by the user, and @var{args} represents the number of
12333seconds @value{GDBN} waits for responses to rpc's. You might use this if
12334your VxWorks target is a slow software simulator or is on the far side
12335of a thin network line.
12336@end table
104c1213 12337
8e04817f
AC
12338The following information on connecting to VxWorks was current when
12339this manual was produced; newer releases of VxWorks may use revised
12340procedures.
104c1213 12341
4644b6e3 12342@findex INCLUDE_RDB
8e04817f
AC
12343To use @value{GDBN} with VxWorks, you must rebuild your VxWorks kernel
12344to include the remote debugging interface routines in the VxWorks
12345library @file{rdb.a}. To do this, define @code{INCLUDE_RDB} in the
12346VxWorks configuration file @file{configAll.h} and rebuild your VxWorks
12347kernel. The resulting kernel contains @file{rdb.a}, and spawns the
12348source debugging task @code{tRdbTask} when VxWorks is booted. For more
12349information on configuring and remaking VxWorks, see the manufacturer's
12350manual.
12351@c VxWorks, see the @cite{VxWorks Programmer's Guide}.
104c1213 12352
8e04817f
AC
12353Once you have included @file{rdb.a} in your VxWorks system image and set
12354your Unix execution search path to find @value{GDBN}, you are ready to
12355run @value{GDBN}. From your Unix host, run @code{@value{GDBP}} (or
12356@code{vxgdb}, depending on your installation).
104c1213 12357
8e04817f 12358@value{GDBN} comes up showing the prompt:
104c1213 12359
474c8240 12360@smallexample
8e04817f 12361(vxgdb)
474c8240 12362@end smallexample
104c1213 12363
8e04817f
AC
12364@menu
12365* VxWorks Connection:: Connecting to VxWorks
12366* VxWorks Download:: VxWorks download
12367* VxWorks Attach:: Running tasks
12368@end menu
104c1213 12369
8e04817f
AC
12370@node VxWorks Connection
12371@subsubsection Connecting to VxWorks
104c1213 12372
8e04817f
AC
12373The @value{GDBN} command @code{target} lets you connect to a VxWorks target on the
12374network. To connect to a target whose host name is ``@code{tt}'', type:
104c1213 12375
474c8240 12376@smallexample
8e04817f 12377(vxgdb) target vxworks tt
474c8240 12378@end smallexample
104c1213 12379
8e04817f
AC
12380@need 750
12381@value{GDBN} displays messages like these:
104c1213 12382
8e04817f
AC
12383@smallexample
12384Attaching remote machine across net...
12385Connected to tt.
12386@end smallexample
104c1213 12387
8e04817f
AC
12388@need 1000
12389@value{GDBN} then attempts to read the symbol tables of any object modules
12390loaded into the VxWorks target since it was last booted. @value{GDBN} locates
12391these files by searching the directories listed in the command search
12392path (@pxref{Environment, ,Your program's environment}); if it fails
12393to find an object file, it displays a message such as:
5d161b24 12394
474c8240 12395@smallexample
8e04817f 12396prog.o: No such file or directory.
474c8240 12397@end smallexample
104c1213 12398
8e04817f
AC
12399When this happens, add the appropriate directory to the search path with
12400the @value{GDBN} command @code{path}, and execute the @code{target}
12401command again.
104c1213 12402
8e04817f
AC
12403@node VxWorks Download
12404@subsubsection VxWorks download
104c1213 12405
8e04817f
AC
12406@cindex download to VxWorks
12407If you have connected to the VxWorks target and you want to debug an
12408object that has not yet been loaded, you can use the @value{GDBN}
12409@code{load} command to download a file from Unix to VxWorks
12410incrementally. The object file given as an argument to the @code{load}
12411command is actually opened twice: first by the VxWorks target in order
12412to download the code, then by @value{GDBN} in order to read the symbol
12413table. This can lead to problems if the current working directories on
12414the two systems differ. If both systems have NFS mounted the same
12415filesystems, you can avoid these problems by using absolute paths.
12416Otherwise, it is simplest to set the working directory on both systems
12417to the directory in which the object file resides, and then to reference
12418the file by its name, without any path. For instance, a program
12419@file{prog.o} may reside in @file{@var{vxpath}/vw/demo/rdb} in VxWorks
12420and in @file{@var{hostpath}/vw/demo/rdb} on the host. To load this
12421program, type this on VxWorks:
104c1213 12422
474c8240 12423@smallexample
8e04817f 12424-> cd "@var{vxpath}/vw/demo/rdb"
474c8240 12425@end smallexample
104c1213 12426
8e04817f
AC
12427@noindent
12428Then, in @value{GDBN}, type:
104c1213 12429
474c8240 12430@smallexample
8e04817f
AC
12431(vxgdb) cd @var{hostpath}/vw/demo/rdb
12432(vxgdb) load prog.o
474c8240 12433@end smallexample
104c1213 12434
8e04817f 12435@value{GDBN} displays a response similar to this:
104c1213 12436
8e04817f
AC
12437@smallexample
12438Reading symbol data from wherever/vw/demo/rdb/prog.o... done.
12439@end smallexample
104c1213 12440
8e04817f
AC
12441You can also use the @code{load} command to reload an object module
12442after editing and recompiling the corresponding source file. Note that
12443this makes @value{GDBN} delete all currently-defined breakpoints,
12444auto-displays, and convenience variables, and to clear the value
12445history. (This is necessary in order to preserve the integrity of
12446debugger's data structures that reference the target system's symbol
12447table.)
104c1213 12448
8e04817f
AC
12449@node VxWorks Attach
12450@subsubsection Running tasks
104c1213
JM
12451
12452@cindex running VxWorks tasks
12453You can also attach to an existing task using the @code{attach} command as
12454follows:
12455
474c8240 12456@smallexample
104c1213 12457(vxgdb) attach @var{task}
474c8240 12458@end smallexample
104c1213
JM
12459
12460@noindent
12461where @var{task} is the VxWorks hexadecimal task ID. The task can be running
12462or suspended when you attach to it. Running tasks are suspended at
12463the time of attachment.
12464
6d2ebf8b 12465@node Embedded Processors
104c1213
JM
12466@section Embedded Processors
12467
12468This section goes into details specific to particular embedded
12469configurations.
12470
7d86b5d5 12471
104c1213 12472@menu
104c1213 12473* ARM:: ARM
172c2a43
KI
12474* H8/300:: Renesas H8/300
12475* H8/500:: Renesas H8/500
12476* M32R/D:: Renesas M32R/D
104c1213 12477* M68K:: Motorola M68K
104c1213 12478* MIPS Embedded:: MIPS Embedded
a37295f9 12479* OpenRISC 1000:: OpenRisc 1000
104c1213
JM
12480* PA:: HP PA Embedded
12481* PowerPC: PowerPC
172c2a43 12482* SH:: Renesas SH
104c1213
JM
12483* Sparclet:: Tsqware Sparclet
12484* Sparclite:: Fujitsu Sparclite
12485* ST2000:: Tandem ST2000
12486* Z8000:: Zilog Z8000
12487@end menu
12488
6d2ebf8b 12489@node ARM
104c1213
JM
12490@subsection ARM
12491
12492@table @code
12493
8e04817f
AC
12494@kindex target rdi
12495@item target rdi @var{dev}
12496ARM Angel monitor, via RDI library interface to ADP protocol. You may
12497use this target to communicate with both boards running the Angel
12498monitor, or with the EmbeddedICE JTAG debug device.
12499
12500@kindex target rdp
12501@item target rdp @var{dev}
12502ARM Demon monitor.
12503
12504@end table
12505
12506@node H8/300
172c2a43 12507@subsection Renesas H8/300
8e04817f
AC
12508
12509@table @code
12510
12511@kindex target hms@r{, with H8/300}
12512@item target hms @var{dev}
172c2a43 12513A Renesas SH, H8/300, or H8/500 board, attached via serial line to your host.
8e04817f
AC
12514Use special commands @code{device} and @code{speed} to control the serial
12515line and the communications speed used.
12516
12517@kindex target e7000@r{, with H8/300}
12518@item target e7000 @var{dev}
172c2a43 12519E7000 emulator for Renesas H8 and SH.
8e04817f
AC
12520
12521@kindex target sh3@r{, with H8/300}
12522@kindex target sh3e@r{, with H8/300}
12523@item target sh3 @var{dev}
12524@itemx target sh3e @var{dev}
172c2a43 12525Renesas SH-3 and SH-3E target systems.
8e04817f
AC
12526
12527@end table
12528
12529@cindex download to H8/300 or H8/500
12530@cindex H8/300 or H8/500 download
172c2a43
KI
12531@cindex download to Renesas SH
12532@cindex Renesas SH download
12533When you select remote debugging to a Renesas SH, H8/300, or H8/500
12534board, the @code{load} command downloads your program to the Renesas
8e04817f
AC
12535board and also opens it as the current executable target for
12536@value{GDBN} on your host (like the @code{file} command).
12537
12538@value{GDBN} needs to know these things to talk to your
172c2a43 12539Renesas SH, H8/300, or H8/500:
8e04817f
AC
12540
12541@enumerate
12542@item
12543that you want to use @samp{target hms}, the remote debugging interface
172c2a43
KI
12544for Renesas microprocessors, or @samp{target e7000}, the in-circuit
12545emulator for the Renesas SH and the Renesas 300H. (@samp{target hms} is
12546the default when @value{GDBN} is configured specifically for the Renesas SH,
8e04817f
AC
12547H8/300, or H8/500.)
12548
12549@item
172c2a43 12550what serial device connects your host to your Renesas board (the first
8e04817f
AC
12551serial device available on your host is the default).
12552
12553@item
12554what speed to use over the serial device.
12555@end enumerate
12556
12557@menu
172c2a43
KI
12558* Renesas Boards:: Connecting to Renesas boards.
12559* Renesas ICE:: Using the E7000 In-Circuit Emulator.
12560* Renesas Special:: Special @value{GDBN} commands for Renesas micros.
8e04817f
AC
12561@end menu
12562
172c2a43
KI
12563@node Renesas Boards
12564@subsubsection Connecting to Renesas boards
8e04817f
AC
12565
12566@c only for Unix hosts
12567@kindex device
172c2a43 12568@cindex serial device, Renesas micros
8e04817f
AC
12569Use the special @code{@value{GDBN}} command @samp{device @var{port}} if you
12570need to explicitly set the serial device. The default @var{port} is the
12571first available port on your host. This is only necessary on Unix
12572hosts, where it is typically something like @file{/dev/ttya}.
12573
12574@kindex speed
172c2a43 12575@cindex serial line speed, Renesas micros
8e04817f
AC
12576@code{@value{GDBN}} has another special command to set the communications
12577speed: @samp{speed @var{bps}}. This command also is only used from Unix
12578hosts; on DOS hosts, set the line speed as usual from outside @value{GDBN} with
12579the DOS @code{mode} command (for instance,
12580@w{@kbd{mode com2:9600,n,8,1,p}} for a 9600@dmn{bps} connection).
12581
12582The @samp{device} and @samp{speed} commands are available only when you
172c2a43 12583use a Unix host to debug your Renesas microprocessor programs. If you
8e04817f
AC
12584use a DOS host,
12585@value{GDBN} depends on an auxiliary terminate-and-stay-resident program
12586called @code{asynctsr} to communicate with the development board
12587through a PC serial port. You must also use the DOS @code{mode} command
12588to set up the serial port on the DOS side.
12589
12590The following sample session illustrates the steps needed to start a
12591program under @value{GDBN} control on an H8/300. The example uses a
12592sample H8/300 program called @file{t.x}. The procedure is the same for
172c2a43 12593the Renesas SH and the H8/500.
8e04817f
AC
12594
12595First hook up your development board. In this example, we use a
12596board attached to serial port @code{COM2}; if you use a different serial
12597port, substitute its name in the argument of the @code{mode} command.
12598When you call @code{asynctsr}, the auxiliary comms program used by the
12599debugger, you give it just the numeric part of the serial port's name;
12600for example, @samp{asyncstr 2} below runs @code{asyncstr} on
12601@code{COM2}.
12602
474c8240 12603@smallexample
8e04817f
AC
12604C:\H8300\TEST> asynctsr 2
12605C:\H8300\TEST> mode com2:9600,n,8,1,p
12606
12607Resident portion of MODE loaded
12608
12609COM2: 9600, n, 8, 1, p
12610
474c8240 12611@end smallexample
8e04817f
AC
12612
12613@quotation
12614@emph{Warning:} We have noticed a bug in PC-NFS that conflicts with
12615@code{asynctsr}. If you also run PC-NFS on your DOS host, you may need to
12616disable it, or even boot without it, to use @code{asynctsr} to control
12617your development board.
12618@end quotation
12619
12620@kindex target hms@r{, and serial protocol}
12621Now that serial communications are set up, and the development board is
12622connected, you can start up @value{GDBN}. Call @code{@value{GDBP}} with
12623the name of your program as the argument. @code{@value{GDBN}} prompts
12624you, as usual, with the prompt @samp{(@value{GDBP})}. Use two special
12625commands to begin your debugging session: @samp{target hms} to specify
172c2a43 12626cross-debugging to the Renesas board, and the @code{load} command to
8e04817f
AC
12627download your program to the board. @code{load} displays the names of
12628the program's sections, and a @samp{*} for each 2K of data downloaded.
12629(If you want to refresh @value{GDBN} data on symbols or on the
12630executable file without downloading, use the @value{GDBN} commands
12631@code{file} or @code{symbol-file}. These commands, and @code{load}
12632itself, are described in @ref{Files,,Commands to specify files}.)
12633
12634@smallexample
12635(eg-C:\H8300\TEST) @value{GDBP} t.x
12636@value{GDBN} is free software and you are welcome to distribute copies
12637 of it under certain conditions; type "show copying" to see
12638 the conditions.
12639There is absolutely no warranty for @value{GDBN}; type "show warranty"
12640for details.
12641@value{GDBN} @value{GDBVN}, Copyright 1992 Free Software Foundation, Inc...
12642(@value{GDBP}) target hms
12643Connected to remote H8/300 HMS system.
12644(@value{GDBP}) load t.x
12645.text : 0x8000 .. 0xabde ***********
12646.data : 0xabde .. 0xad30 *
12647.stack : 0xf000 .. 0xf014 *
12648@end smallexample
12649
12650At this point, you're ready to run or debug your program. From here on,
12651you can use all the usual @value{GDBN} commands. The @code{break} command
12652sets breakpoints; the @code{run} command starts your program;
12653@code{print} or @code{x} display data; the @code{continue} command
12654resumes execution after stopping at a breakpoint. You can use the
12655@code{help} command at any time to find out more about @value{GDBN} commands.
12656
12657Remember, however, that @emph{operating system} facilities aren't
12658available on your development board; for example, if your program hangs,
12659you can't send an interrupt---but you can press the @sc{reset} switch!
12660
12661Use the @sc{reset} button on the development board
12662@itemize @bullet
12663@item
12664to interrupt your program (don't use @kbd{ctl-C} on the DOS host---it has
12665no way to pass an interrupt signal to the development board); and
12666
12667@item
12668to return to the @value{GDBN} command prompt after your program finishes
12669normally. The communications protocol provides no other way for @value{GDBN}
12670to detect program completion.
12671@end itemize
12672
12673In either case, @value{GDBN} sees the effect of a @sc{reset} on the
12674development board as a ``normal exit'' of your program.
12675
172c2a43 12676@node Renesas ICE
8e04817f
AC
12677@subsubsection Using the E7000 in-circuit emulator
12678
172c2a43 12679@kindex target e7000@r{, with Renesas ICE}
8e04817f 12680You can use the E7000 in-circuit emulator to develop code for either the
172c2a43 12681Renesas SH or the H8/300H. Use one of these forms of the @samp{target
8e04817f
AC
12682e7000} command to connect @value{GDBN} to your E7000:
12683
12684@table @code
12685@item target e7000 @var{port} @var{speed}
12686Use this form if your E7000 is connected to a serial port. The
12687@var{port} argument identifies what serial port to use (for example,
12688@samp{com2}). The third argument is the line speed in bits per second
12689(for example, @samp{9600}).
12690
12691@item target e7000 @var{hostname}
12692If your E7000 is installed as a host on a TCP/IP network, you can just
12693specify its hostname; @value{GDBN} uses @code{telnet} to connect.
12694@end table
12695
172c2a43
KI
12696@node Renesas Special
12697@subsubsection Special @value{GDBN} commands for Renesas micros
8e04817f
AC
12698
12699Some @value{GDBN} commands are available only for the H8/300:
12700
12701@table @code
12702
12703@kindex set machine
12704@kindex show machine
12705@item set machine h8300
12706@itemx set machine h8300h
12707Condition @value{GDBN} for one of the two variants of the H8/300
12708architecture with @samp{set machine}. You can use @samp{show machine}
12709to check which variant is currently in effect.
104c1213
JM
12710
12711@end table
12712
8e04817f
AC
12713@node H8/500
12714@subsection H8/500
104c1213
JM
12715
12716@table @code
12717
8e04817f
AC
12718@kindex set memory @var{mod}
12719@cindex memory models, H8/500
12720@item set memory @var{mod}
12721@itemx show memory
12722Specify which H8/500 memory model (@var{mod}) you are using with
12723@samp{set memory}; check which memory model is in effect with @samp{show
12724memory}. The accepted values for @var{mod} are @code{small},
12725@code{big}, @code{medium}, and @code{compact}.
104c1213 12726
8e04817f 12727@end table
104c1213 12728
8e04817f 12729@node M32R/D
172c2a43 12730@subsection Renesas M32R/D
8e04817f
AC
12731
12732@table @code
12733
12734@kindex target m32r
12735@item target m32r @var{dev}
172c2a43 12736Renesas M32R/D ROM monitor.
8e04817f 12737
fb3e19c0
KI
12738@kindex target m32rsdi
12739@item target m32rsdi @var{dev}
12740Renesas M32R SDI server, connected via parallel port to the board.
12741
8e04817f
AC
12742@end table
12743
12744@node M68K
12745@subsection M68k
12746
12747The Motorola m68k configuration includes ColdFire support, and
12748target command for the following ROM monitors.
12749
12750@table @code
12751
12752@kindex target abug
12753@item target abug @var{dev}
12754ABug ROM monitor for M68K.
12755
12756@kindex target cpu32bug
12757@item target cpu32bug @var{dev}
12758CPU32BUG monitor, running on a CPU32 (M68K) board.
12759
12760@kindex target dbug
12761@item target dbug @var{dev}
12762dBUG ROM monitor for Motorola ColdFire.
12763
12764@kindex target est
12765@item target est @var{dev}
12766EST-300 ICE monitor, running on a CPU32 (M68K) board.
12767
12768@kindex target rom68k
12769@item target rom68k @var{dev}
12770ROM 68K monitor, running on an M68K IDP board.
12771
12772@end table
12773
8e04817f
AC
12774@table @code
12775
12776@kindex target rombug
12777@item target rombug @var{dev}
12778ROMBUG ROM monitor for OS/9000.
12779
12780@end table
12781
8e04817f
AC
12782@node MIPS Embedded
12783@subsection MIPS Embedded
12784
12785@cindex MIPS boards
12786@value{GDBN} can use the MIPS remote debugging protocol to talk to a
12787MIPS board attached to a serial line. This is available when
12788you configure @value{GDBN} with @samp{--target=mips-idt-ecoff}.
104c1213 12789
8e04817f
AC
12790@need 1000
12791Use these @value{GDBN} commands to specify the connection to your target board:
104c1213 12792
8e04817f
AC
12793@table @code
12794@item target mips @var{port}
12795@kindex target mips @var{port}
12796To run a program on the board, start up @code{@value{GDBP}} with the
12797name of your program as the argument. To connect to the board, use the
12798command @samp{target mips @var{port}}, where @var{port} is the name of
12799the serial port connected to the board. If the program has not already
12800been downloaded to the board, you may use the @code{load} command to
12801download it. You can then use all the usual @value{GDBN} commands.
104c1213 12802
8e04817f
AC
12803For example, this sequence connects to the target board through a serial
12804port, and loads and runs a program called @var{prog} through the
12805debugger:
104c1213 12806
474c8240 12807@smallexample
8e04817f
AC
12808host$ @value{GDBP} @var{prog}
12809@value{GDBN} is free software and @dots{}
12810(@value{GDBP}) target mips /dev/ttyb
12811(@value{GDBP}) load @var{prog}
12812(@value{GDBP}) run
474c8240 12813@end smallexample
104c1213 12814
8e04817f
AC
12815@item target mips @var{hostname}:@var{portnumber}
12816On some @value{GDBN} host configurations, you can specify a TCP
12817connection (for instance, to a serial line managed by a terminal
12818concentrator) instead of a serial port, using the syntax
12819@samp{@var{hostname}:@var{portnumber}}.
104c1213 12820
8e04817f
AC
12821@item target pmon @var{port}
12822@kindex target pmon @var{port}
12823PMON ROM monitor.
104c1213 12824
8e04817f
AC
12825@item target ddb @var{port}
12826@kindex target ddb @var{port}
12827NEC's DDB variant of PMON for Vr4300.
104c1213 12828
8e04817f
AC
12829@item target lsi @var{port}
12830@kindex target lsi @var{port}
12831LSI variant of PMON.
104c1213 12832
8e04817f
AC
12833@kindex target r3900
12834@item target r3900 @var{dev}
12835Densan DVE-R3900 ROM monitor for Toshiba R3900 Mips.
104c1213 12836
8e04817f
AC
12837@kindex target array
12838@item target array @var{dev}
12839Array Tech LSI33K RAID controller board.
104c1213 12840
8e04817f 12841@end table
104c1213 12842
104c1213 12843
8e04817f
AC
12844@noindent
12845@value{GDBN} also supports these special commands for MIPS targets:
104c1213 12846
8e04817f
AC
12847@table @code
12848@item set processor @var{args}
12849@itemx show processor
12850@kindex set processor @var{args}
12851@kindex show processor
12852Use the @code{set processor} command to set the type of MIPS
12853processor when you want to access processor-type-specific registers.
12854For example, @code{set processor @var{r3041}} tells @value{GDBN}
12855to use the CPU registers appropriate for the 3041 chip.
12856Use the @code{show processor} command to see what MIPS processor @value{GDBN}
12857is using. Use the @code{info reg} command to see what registers
12858@value{GDBN} is using.
104c1213 12859
8e04817f
AC
12860@item set mipsfpu double
12861@itemx set mipsfpu single
12862@itemx set mipsfpu none
12863@itemx show mipsfpu
12864@kindex set mipsfpu
12865@kindex show mipsfpu
12866@cindex MIPS remote floating point
12867@cindex floating point, MIPS remote
12868If your target board does not support the MIPS floating point
12869coprocessor, you should use the command @samp{set mipsfpu none} (if you
12870need this, you may wish to put the command in your @value{GDBN} init
12871file). This tells @value{GDBN} how to find the return value of
12872functions which return floating point values. It also allows
12873@value{GDBN} to avoid saving the floating point registers when calling
12874functions on the board. If you are using a floating point coprocessor
12875with only single precision floating point support, as on the @sc{r4650}
12876processor, use the command @samp{set mipsfpu single}. The default
12877double precision floating point coprocessor may be selected using
12878@samp{set mipsfpu double}.
104c1213 12879
8e04817f
AC
12880In previous versions the only choices were double precision or no
12881floating point, so @samp{set mipsfpu on} will select double precision
12882and @samp{set mipsfpu off} will select no floating point.
104c1213 12883
8e04817f
AC
12884As usual, you can inquire about the @code{mipsfpu} variable with
12885@samp{show mipsfpu}.
104c1213 12886
8e04817f
AC
12887@item set remotedebug @var{n}
12888@itemx show remotedebug
12889@kindex set remotedebug@r{, MIPS protocol}
12890@kindex show remotedebug@r{, MIPS protocol}
12891@cindex @code{remotedebug}, MIPS protocol
12892@cindex MIPS @code{remotedebug} protocol
12893@c FIXME! For this to be useful, you must know something about the MIPS
12894@c FIXME...protocol. Where is it described?
12895You can see some debugging information about communications with the board
12896by setting the @code{remotedebug} variable. If you set it to @code{1} using
12897@samp{set remotedebug 1}, every packet is displayed. If you set it
12898to @code{2}, every character is displayed. You can check the current value
12899at any time with the command @samp{show remotedebug}.
104c1213 12900
8e04817f
AC
12901@item set timeout @var{seconds}
12902@itemx set retransmit-timeout @var{seconds}
12903@itemx show timeout
12904@itemx show retransmit-timeout
12905@cindex @code{timeout}, MIPS protocol
12906@cindex @code{retransmit-timeout}, MIPS protocol
12907@kindex set timeout
12908@kindex show timeout
12909@kindex set retransmit-timeout
12910@kindex show retransmit-timeout
12911You can control the timeout used while waiting for a packet, in the MIPS
12912remote protocol, with the @code{set timeout @var{seconds}} command. The
12913default is 5 seconds. Similarly, you can control the timeout used while
12914waiting for an acknowledgement of a packet with the @code{set
12915retransmit-timeout @var{seconds}} command. The default is 3 seconds.
12916You can inspect both values with @code{show timeout} and @code{show
12917retransmit-timeout}. (These commands are @emph{only} available when
12918@value{GDBN} is configured for @samp{--target=mips-idt-ecoff}.)
104c1213 12919
8e04817f
AC
12920The timeout set by @code{set timeout} does not apply when @value{GDBN}
12921is waiting for your program to stop. In that case, @value{GDBN} waits
12922forever because it has no way of knowing how long the program is going
12923to run before stopping.
12924@end table
104c1213 12925
a37295f9
MM
12926@node OpenRISC 1000
12927@subsection OpenRISC 1000
12928@cindex OpenRISC 1000
12929
12930@cindex or1k boards
12931See OR1k Architecture document (@uref{www.opencores.org}) for more information
12932about platform and commands.
12933
12934@table @code
12935
12936@kindex target jtag
12937@item target jtag jtag://@var{host}:@var{port}
12938
12939Connects to remote JTAG server.
12940JTAG remote server can be either an or1ksim or JTAG server,
12941connected via parallel port to the board.
12942
12943Example: @code{target jtag jtag://localhost:9999}
12944
12945@kindex or1ksim
12946@item or1ksim @var{command}
12947If connected to @code{or1ksim} OpenRISC 1000 Architectural
12948Simulator, proprietary commands can be executed.
12949
12950@kindex info or1k spr
12951@item info or1k spr
12952Displays spr groups.
12953
12954@item info or1k spr @var{group}
12955@itemx info or1k spr @var{groupno}
12956Displays register names in selected group.
12957
12958@item info or1k spr @var{group} @var{register}
12959@itemx info or1k spr @var{register}
12960@itemx info or1k spr @var{groupno} @var{registerno}
12961@itemx info or1k spr @var{registerno}
12962Shows information about specified spr register.
12963
12964@kindex spr
12965@item spr @var{group} @var{register} @var{value}
12966@itemx spr @var{register @var{value}}
12967@itemx spr @var{groupno} @var{registerno @var{value}}
12968@itemx spr @var{registerno @var{value}}
12969Writes @var{value} to specified spr register.
12970@end table
12971
12972Some implementations of OpenRISC 1000 Architecture also have hardware trace.
12973It is very similar to @value{GDBN} trace, except it does not interfere with normal
12974program execution and is thus much faster. Hardware breakpoints/watchpoint
12975triggers can be set using:
12976@table @code
12977@item $LEA/$LDATA
12978Load effective address/data
12979@item $SEA/$SDATA
12980Store effective address/data
12981@item $AEA/$ADATA
12982Access effective address ($SEA or $LEA) or data ($SDATA/$LDATA)
12983@item $FETCH
12984Fetch data
12985@end table
12986
12987When triggered, it can capture low level data, like: @code{PC}, @code{LSEA},
12988@code{LDATA}, @code{SDATA}, @code{READSPR}, @code{WRITESPR}, @code{INSTR}.
12989
12990@code{htrace} commands:
12991@cindex OpenRISC 1000 htrace
12992@table @code
12993@kindex hwatch
12994@item hwatch @var{conditional}
12995Set hardware watchpoint on combination of Load/Store Effecive Address(es)
12996or Data. For example:
12997
12998@code{hwatch ($LEA == my_var) && ($LDATA < 50) || ($SEA == my_var) && ($SDATA >= 50)}
12999
13000@code{hwatch ($LEA == my_var) && ($LDATA < 50) || ($SEA == my_var) && ($SDATA >= 50)}
13001
4644b6e3 13002@kindex htrace
a37295f9
MM
13003@item htrace info
13004Display information about current HW trace configuration.
13005
a37295f9
MM
13006@item htrace trigger @var{conditional}
13007Set starting criteria for HW trace.
13008
a37295f9
MM
13009@item htrace qualifier @var{conditional}
13010Set acquisition qualifier for HW trace.
13011
a37295f9
MM
13012@item htrace stop @var{conditional}
13013Set HW trace stopping criteria.
13014
f153cc92 13015@item htrace record [@var{data}]*
a37295f9
MM
13016Selects the data to be recorded, when qualifier is met and HW trace was
13017triggered.
13018
a37295f9 13019@item htrace enable
a37295f9
MM
13020@itemx htrace disable
13021Enables/disables the HW trace.
13022
f153cc92 13023@item htrace rewind [@var{filename}]
a37295f9
MM
13024Clears currently recorded trace data.
13025
13026If filename is specified, new trace file is made and any newly collected data
13027will be written there.
13028
f153cc92 13029@item htrace print [@var{start} [@var{len}]]
a37295f9
MM
13030Prints trace buffer, using current record configuration.
13031
a37295f9
MM
13032@item htrace mode continuous
13033Set continuous trace mode.
13034
a37295f9
MM
13035@item htrace mode suspend
13036Set suspend trace mode.
13037
13038@end table
13039
8e04817f
AC
13040@node PowerPC
13041@subsection PowerPC
104c1213
JM
13042
13043@table @code
104c1213 13044
8e04817f
AC
13045@kindex target dink32
13046@item target dink32 @var{dev}
13047DINK32 ROM monitor.
104c1213 13048
8e04817f
AC
13049@kindex target ppcbug
13050@item target ppcbug @var{dev}
13051@kindex target ppcbug1
13052@item target ppcbug1 @var{dev}
13053PPCBUG ROM monitor for PowerPC.
104c1213 13054
8e04817f
AC
13055@kindex target sds
13056@item target sds @var{dev}
13057SDS monitor, running on a PowerPC board (such as Motorola's ADS).
13058
13059@end table
13060
13061@node PA
13062@subsection HP PA Embedded
104c1213
JM
13063
13064@table @code
13065
8e04817f
AC
13066@kindex target op50n
13067@item target op50n @var{dev}
13068OP50N monitor, running on an OKI HPPA board.
13069
13070@kindex target w89k
13071@item target w89k @var{dev}
13072W89K monitor, running on a Winbond HPPA board.
104c1213
JM
13073
13074@end table
13075
8e04817f 13076@node SH
172c2a43 13077@subsection Renesas SH
104c1213
JM
13078
13079@table @code
13080
172c2a43 13081@kindex target hms@r{, with Renesas SH}
8e04817f 13082@item target hms @var{dev}
172c2a43 13083A Renesas SH board attached via serial line to your host. Use special
8e04817f
AC
13084commands @code{device} and @code{speed} to control the serial line and
13085the communications speed used.
104c1213 13086
172c2a43 13087@kindex target e7000@r{, with Renesas SH}
8e04817f 13088@item target e7000 @var{dev}
172c2a43 13089E7000 emulator for Renesas SH.
104c1213 13090
8e04817f
AC
13091@kindex target sh3@r{, with SH}
13092@kindex target sh3e@r{, with SH}
13093@item target sh3 @var{dev}
13094@item target sh3e @var{dev}
172c2a43 13095Renesas SH-3 and SH-3E target systems.
104c1213 13096
8e04817f 13097@end table
104c1213 13098
8e04817f
AC
13099@node Sparclet
13100@subsection Tsqware Sparclet
104c1213 13101
8e04817f
AC
13102@cindex Sparclet
13103
13104@value{GDBN} enables developers to debug tasks running on
13105Sparclet targets from a Unix host.
13106@value{GDBN} uses code that runs on
13107both the Unix host and on the Sparclet target. The program
13108@code{@value{GDBP}} is installed and executed on the Unix host.
104c1213 13109
8e04817f
AC
13110@table @code
13111@item remotetimeout @var{args}
13112@kindex remotetimeout
13113@value{GDBN} supports the option @code{remotetimeout}.
13114This option is set by the user, and @var{args} represents the number of
13115seconds @value{GDBN} waits for responses.
104c1213
JM
13116@end table
13117
8e04817f
AC
13118@cindex compiling, on Sparclet
13119When compiling for debugging, include the options @samp{-g} to get debug
13120information and @samp{-Ttext} to relocate the program to where you wish to
13121load it on the target. You may also want to add the options @samp{-n} or
13122@samp{-N} in order to reduce the size of the sections. Example:
104c1213 13123
474c8240 13124@smallexample
8e04817f 13125sparclet-aout-gcc prog.c -Ttext 0x12010000 -g -o prog -N
474c8240 13126@end smallexample
104c1213 13127
8e04817f 13128You can use @code{objdump} to verify that the addresses are what you intended:
104c1213 13129
474c8240 13130@smallexample
8e04817f 13131sparclet-aout-objdump --headers --syms prog
474c8240 13132@end smallexample
104c1213 13133
8e04817f
AC
13134@cindex running, on Sparclet
13135Once you have set
13136your Unix execution search path to find @value{GDBN}, you are ready to
13137run @value{GDBN}. From your Unix host, run @code{@value{GDBP}}
13138(or @code{sparclet-aout-gdb}, depending on your installation).
104c1213 13139
8e04817f
AC
13140@value{GDBN} comes up showing the prompt:
13141
474c8240 13142@smallexample
8e04817f 13143(gdbslet)
474c8240 13144@end smallexample
104c1213
JM
13145
13146@menu
8e04817f
AC
13147* Sparclet File:: Setting the file to debug
13148* Sparclet Connection:: Connecting to Sparclet
13149* Sparclet Download:: Sparclet download
13150* Sparclet Execution:: Running and debugging
104c1213
JM
13151@end menu
13152
8e04817f
AC
13153@node Sparclet File
13154@subsubsection Setting file to debug
104c1213 13155
8e04817f 13156The @value{GDBN} command @code{file} lets you choose with program to debug.
104c1213 13157
474c8240 13158@smallexample
8e04817f 13159(gdbslet) file prog
474c8240 13160@end smallexample
104c1213 13161
8e04817f
AC
13162@need 1000
13163@value{GDBN} then attempts to read the symbol table of @file{prog}.
13164@value{GDBN} locates
13165the file by searching the directories listed in the command search
13166path.
13167If the file was compiled with debug information (option "-g"), source
13168files will be searched as well.
13169@value{GDBN} locates
13170the source files by searching the directories listed in the directory search
13171path (@pxref{Environment, ,Your program's environment}).
13172If it fails
13173to find a file, it displays a message such as:
104c1213 13174
474c8240 13175@smallexample
8e04817f 13176prog: No such file or directory.
474c8240 13177@end smallexample
104c1213 13178
8e04817f
AC
13179When this happens, add the appropriate directories to the search paths with
13180the @value{GDBN} commands @code{path} and @code{dir}, and execute the
13181@code{target} command again.
104c1213 13182
8e04817f
AC
13183@node Sparclet Connection
13184@subsubsection Connecting to Sparclet
104c1213 13185
8e04817f
AC
13186The @value{GDBN} command @code{target} lets you connect to a Sparclet target.
13187To connect to a target on serial port ``@code{ttya}'', type:
104c1213 13188
474c8240 13189@smallexample
8e04817f
AC
13190(gdbslet) target sparclet /dev/ttya
13191Remote target sparclet connected to /dev/ttya
13192main () at ../prog.c:3
474c8240 13193@end smallexample
104c1213 13194
8e04817f
AC
13195@need 750
13196@value{GDBN} displays messages like these:
104c1213 13197
474c8240 13198@smallexample
8e04817f 13199Connected to ttya.
474c8240 13200@end smallexample
104c1213 13201
8e04817f
AC
13202@node Sparclet Download
13203@subsubsection Sparclet download
104c1213 13204
8e04817f
AC
13205@cindex download to Sparclet
13206Once connected to the Sparclet target,
13207you can use the @value{GDBN}
13208@code{load} command to download the file from the host to the target.
13209The file name and load offset should be given as arguments to the @code{load}
13210command.
13211Since the file format is aout, the program must be loaded to the starting
13212address. You can use @code{objdump} to find out what this value is. The load
13213offset is an offset which is added to the VMA (virtual memory address)
13214of each of the file's sections.
13215For instance, if the program
13216@file{prog} was linked to text address 0x1201000, with data at 0x12010160
13217and bss at 0x12010170, in @value{GDBN}, type:
104c1213 13218
474c8240 13219@smallexample
8e04817f
AC
13220(gdbslet) load prog 0x12010000
13221Loading section .text, size 0xdb0 vma 0x12010000
474c8240 13222@end smallexample
104c1213 13223
8e04817f
AC
13224If the code is loaded at a different address then what the program was linked
13225to, you may need to use the @code{section} and @code{add-symbol-file} commands
13226to tell @value{GDBN} where to map the symbol table.
13227
13228@node Sparclet Execution
13229@subsubsection Running and debugging
13230
13231@cindex running and debugging Sparclet programs
13232You can now begin debugging the task using @value{GDBN}'s execution control
13233commands, @code{b}, @code{step}, @code{run}, etc. See the @value{GDBN}
13234manual for the list of commands.
13235
474c8240 13236@smallexample
8e04817f
AC
13237(gdbslet) b main
13238Breakpoint 1 at 0x12010000: file prog.c, line 3.
13239(gdbslet) run
13240Starting program: prog
13241Breakpoint 1, main (argc=1, argv=0xeffff21c) at prog.c:3
132423 char *symarg = 0;
13243(gdbslet) step
132444 char *execarg = "hello!";
13245(gdbslet)
474c8240 13246@end smallexample
8e04817f
AC
13247
13248@node Sparclite
13249@subsection Fujitsu Sparclite
104c1213
JM
13250
13251@table @code
13252
8e04817f
AC
13253@kindex target sparclite
13254@item target sparclite @var{dev}
13255Fujitsu sparclite boards, used only for the purpose of loading.
13256You must use an additional command to debug the program.
13257For example: target remote @var{dev} using @value{GDBN} standard
13258remote protocol.
104c1213
JM
13259
13260@end table
13261
8e04817f
AC
13262@node ST2000
13263@subsection Tandem ST2000
104c1213 13264
8e04817f
AC
13265@value{GDBN} may be used with a Tandem ST2000 phone switch, running Tandem's
13266STDBUG protocol.
104c1213 13267
8e04817f
AC
13268To connect your ST2000 to the host system, see the manufacturer's
13269manual. Once the ST2000 is physically attached, you can run:
104c1213 13270
474c8240 13271@smallexample
8e04817f 13272target st2000 @var{dev} @var{speed}
474c8240 13273@end smallexample
104c1213 13274
8e04817f
AC
13275@noindent
13276to establish it as your debugging environment. @var{dev} is normally
13277the name of a serial device, such as @file{/dev/ttya}, connected to the
13278ST2000 via a serial line. You can instead specify @var{dev} as a TCP
13279connection (for example, to a serial line attached via a terminal
13280concentrator) using the syntax @code{@var{hostname}:@var{portnumber}}.
104c1213 13281
8e04817f
AC
13282The @code{load} and @code{attach} commands are @emph{not} defined for
13283this target; you must load your program into the ST2000 as you normally
13284would for standalone operation. @value{GDBN} reads debugging information
13285(such as symbols) from a separate, debugging version of the program
13286available on your host computer.
13287@c FIXME!! This is terribly vague; what little content is here is
13288@c basically hearsay.
104c1213 13289
8e04817f
AC
13290@cindex ST2000 auxiliary commands
13291These auxiliary @value{GDBN} commands are available to help you with the ST2000
13292environment:
104c1213 13293
8e04817f
AC
13294@table @code
13295@item st2000 @var{command}
13296@kindex st2000 @var{cmd}
13297@cindex STDBUG commands (ST2000)
13298@cindex commands to STDBUG (ST2000)
13299Send a @var{command} to the STDBUG monitor. See the manufacturer's
13300manual for available commands.
104c1213 13301
8e04817f
AC
13302@item connect
13303@cindex connect (to STDBUG)
13304Connect the controlling terminal to the STDBUG command monitor. When
13305you are done interacting with STDBUG, typing either of two character
13306sequences gets you back to the @value{GDBN} command prompt:
13307@kbd{@key{RET}~.} (Return, followed by tilde and period) or
13308@kbd{@key{RET}~@key{C-d}} (Return, followed by tilde and control-D).
104c1213
JM
13309@end table
13310
8e04817f
AC
13311@node Z8000
13312@subsection Zilog Z8000
104c1213 13313
8e04817f
AC
13314@cindex Z8000
13315@cindex simulator, Z8000
13316@cindex Zilog Z8000 simulator
104c1213 13317
8e04817f
AC
13318When configured for debugging Zilog Z8000 targets, @value{GDBN} includes
13319a Z8000 simulator.
13320
13321For the Z8000 family, @samp{target sim} simulates either the Z8002 (the
13322unsegmented variant of the Z8000 architecture) or the Z8001 (the
13323segmented variant). The simulator recognizes which architecture is
13324appropriate by inspecting the object code.
104c1213 13325
8e04817f
AC
13326@table @code
13327@item target sim @var{args}
13328@kindex sim
13329@kindex target sim@r{, with Z8000}
13330Debug programs on a simulated CPU. If the simulator supports setup
13331options, specify them via @var{args}.
104c1213
JM
13332@end table
13333
8e04817f
AC
13334@noindent
13335After specifying this target, you can debug programs for the simulated
13336CPU in the same style as programs for your host computer; use the
13337@code{file} command to load a new program image, the @code{run} command
13338to run your program, and so on.
13339
13340As well as making available all the usual machine registers
13341(@pxref{Registers, ,Registers}), the Z8000 simulator provides three
13342additional items of information as specially named registers:
104c1213
JM
13343
13344@table @code
13345
8e04817f
AC
13346@item cycles
13347Counts clock-ticks in the simulator.
104c1213 13348
8e04817f
AC
13349@item insts
13350Counts instructions run in the simulator.
104c1213 13351
8e04817f
AC
13352@item time
13353Execution time in 60ths of a second.
104c1213 13354
8e04817f 13355@end table
104c1213 13356
8e04817f
AC
13357You can refer to these values in @value{GDBN} expressions with the usual
13358conventions; for example, @w{@samp{b fputc if $cycles>5000}} sets a
13359conditional breakpoint that suspends only after at least 5000
13360simulated clock ticks.
104c1213 13361
8e04817f
AC
13362@node Architectures
13363@section Architectures
104c1213 13364
8e04817f
AC
13365This section describes characteristics of architectures that affect
13366all uses of @value{GDBN} with the architecture, both native and cross.
104c1213 13367
8e04817f
AC
13368@menu
13369* A29K::
13370* Alpha::
13371* MIPS::
13372@end menu
104c1213 13373
8e04817f
AC
13374@node A29K
13375@subsection A29K
104c1213
JM
13376
13377@table @code
104c1213 13378
8e04817f
AC
13379@kindex set rstack_high_address
13380@cindex AMD 29K register stack
13381@cindex register stack, AMD29K
13382@item set rstack_high_address @var{address}
13383On AMD 29000 family processors, registers are saved in a separate
13384@dfn{register stack}. There is no way for @value{GDBN} to determine the
13385extent of this stack. Normally, @value{GDBN} just assumes that the
13386stack is ``large enough''. This may result in @value{GDBN} referencing
13387memory locations that do not exist. If necessary, you can get around
13388this problem by specifying the ending address of the register stack with
13389the @code{set rstack_high_address} command. The argument should be an
13390address, which you probably want to precede with @samp{0x} to specify in
13391hexadecimal.
104c1213 13392
8e04817f
AC
13393@kindex show rstack_high_address
13394@item show rstack_high_address
13395Display the current limit of the register stack, on AMD 29000 family
13396processors.
104c1213 13397
8e04817f 13398@end table
104c1213 13399
8e04817f
AC
13400@node Alpha
13401@subsection Alpha
104c1213 13402
8e04817f 13403See the following section.
104c1213 13404
8e04817f
AC
13405@node MIPS
13406@subsection MIPS
104c1213 13407
8e04817f
AC
13408@cindex stack on Alpha
13409@cindex stack on MIPS
13410@cindex Alpha stack
13411@cindex MIPS stack
13412Alpha- and MIPS-based computers use an unusual stack frame, which
13413sometimes requires @value{GDBN} to search backward in the object code to
13414find the beginning of a function.
104c1213 13415
8e04817f
AC
13416@cindex response time, MIPS debugging
13417To improve response time (especially for embedded applications, where
13418@value{GDBN} may be restricted to a slow serial line for this search)
13419you may want to limit the size of this search, using one of these
13420commands:
104c1213 13421
8e04817f
AC
13422@table @code
13423@cindex @code{heuristic-fence-post} (Alpha, MIPS)
13424@item set heuristic-fence-post @var{limit}
13425Restrict @value{GDBN} to examining at most @var{limit} bytes in its
13426search for the beginning of a function. A value of @var{0} (the
13427default) means there is no limit. However, except for @var{0}, the
13428larger the limit the more bytes @code{heuristic-fence-post} must search
13429and therefore the longer it takes to run.
104c1213 13430
8e04817f
AC
13431@item show heuristic-fence-post
13432Display the current limit.
13433@end table
104c1213
JM
13434
13435@noindent
8e04817f
AC
13436These commands are available @emph{only} when @value{GDBN} is configured
13437for debugging programs on Alpha or MIPS processors.
104c1213 13438
104c1213 13439
8e04817f
AC
13440@node Controlling GDB
13441@chapter Controlling @value{GDBN}
13442
13443You can alter the way @value{GDBN} interacts with you by using the
13444@code{set} command. For commands controlling how @value{GDBN} displays
13445data, see @ref{Print Settings, ,Print settings}. Other settings are
13446described here.
13447
13448@menu
13449* Prompt:: Prompt
13450* Editing:: Command editing
13451* History:: Command history
13452* Screen Size:: Screen size
13453* Numbers:: Numbers
1e698235 13454* ABI:: Configuring the current ABI
8e04817f
AC
13455* Messages/Warnings:: Optional warnings and messages
13456* Debugging Output:: Optional messages about internal happenings
13457@end menu
13458
13459@node Prompt
13460@section Prompt
104c1213 13461
8e04817f 13462@cindex prompt
104c1213 13463
8e04817f
AC
13464@value{GDBN} indicates its readiness to read a command by printing a string
13465called the @dfn{prompt}. This string is normally @samp{(@value{GDBP})}. You
13466can change the prompt string with the @code{set prompt} command. For
13467instance, when debugging @value{GDBN} with @value{GDBN}, it is useful to change
13468the prompt in one of the @value{GDBN} sessions so that you can always tell
13469which one you are talking to.
104c1213 13470
8e04817f
AC
13471@emph{Note:} @code{set prompt} does not add a space for you after the
13472prompt you set. This allows you to set a prompt which ends in a space
13473or a prompt that does not.
104c1213 13474
8e04817f
AC
13475@table @code
13476@kindex set prompt
13477@item set prompt @var{newprompt}
13478Directs @value{GDBN} to use @var{newprompt} as its prompt string henceforth.
104c1213 13479
8e04817f
AC
13480@kindex show prompt
13481@item show prompt
13482Prints a line of the form: @samp{Gdb's prompt is: @var{your-prompt}}
104c1213
JM
13483@end table
13484
8e04817f
AC
13485@node Editing
13486@section Command editing
13487@cindex readline
13488@cindex command line editing
104c1213 13489
703663ab 13490@value{GDBN} reads its input commands via the @dfn{Readline} interface. This
8e04817f
AC
13491@sc{gnu} library provides consistent behavior for programs which provide a
13492command line interface to the user. Advantages are @sc{gnu} Emacs-style
13493or @dfn{vi}-style inline editing of commands, @code{csh}-like history
13494substitution, and a storage and recall of command history across
13495debugging sessions.
104c1213 13496
8e04817f
AC
13497You may control the behavior of command line editing in @value{GDBN} with the
13498command @code{set}.
104c1213 13499
8e04817f
AC
13500@table @code
13501@kindex set editing
13502@cindex editing
13503@item set editing
13504@itemx set editing on
13505Enable command line editing (enabled by default).
104c1213 13506
8e04817f
AC
13507@item set editing off
13508Disable command line editing.
104c1213 13509
8e04817f
AC
13510@kindex show editing
13511@item show editing
13512Show whether command line editing is enabled.
104c1213
JM
13513@end table
13514
703663ab
EZ
13515@xref{Command Line Editing}, for more details about the Readline
13516interface. Users unfamiliar with @sc{gnu} Emacs or @code{vi} are
13517encouraged to read that chapter.
13518
8e04817f
AC
13519@node History
13520@section Command history
703663ab 13521@cindex command history
8e04817f
AC
13522
13523@value{GDBN} can keep track of the commands you type during your
13524debugging sessions, so that you can be certain of precisely what
13525happened. Use these commands to manage the @value{GDBN} command
13526history facility.
104c1213 13527
703663ab
EZ
13528@value{GDBN} uses the @sc{gnu} History library, a part of the Readline
13529package, to provide the history facility. @xref{Using History
13530Interactively}, for the detailed description of the History library.
13531
13532Here is the description of @value{GDBN} commands related to command
13533history.
13534
104c1213 13535@table @code
8e04817f
AC
13536@cindex history substitution
13537@cindex history file
13538@kindex set history filename
4644b6e3 13539@cindex @env{GDBHISTFILE}, environment variable
8e04817f
AC
13540@item set history filename @var{fname}
13541Set the name of the @value{GDBN} command history file to @var{fname}.
13542This is the file where @value{GDBN} reads an initial command history
13543list, and where it writes the command history from this session when it
13544exits. You can access this list through history expansion or through
13545the history command editing characters listed below. This file defaults
13546to the value of the environment variable @code{GDBHISTFILE}, or to
13547@file{./.gdb_history} (@file{./_gdb_history} on MS-DOS) if this variable
13548is not set.
104c1213 13549
8e04817f 13550@cindex history save
4644b6e3 13551@kindex set history
8e04817f
AC
13552@item set history save
13553@itemx set history save on
13554Record command history in a file, whose name may be specified with the
13555@code{set history filename} command. By default, this option is disabled.
104c1213 13556
8e04817f
AC
13557@item set history save off
13558Stop recording command history in a file.
104c1213 13559
8e04817f 13560@cindex history size
8e04817f
AC
13561@item set history size @var{size}
13562Set the number of commands which @value{GDBN} keeps in its history list.
13563This defaults to the value of the environment variable
13564@code{HISTSIZE}, or to 256 if this variable is not set.
104c1213
JM
13565@end table
13566
8e04817f 13567History expansion assigns special meaning to the character @kbd{!}.
703663ab 13568@xref{Event Designators}, for more details.
8e04817f 13569
703663ab 13570@cindex history expansion, turn on/off
8e04817f
AC
13571Since @kbd{!} is also the logical not operator in C, history expansion
13572is off by default. If you decide to enable history expansion with the
13573@code{set history expansion on} command, you may sometimes need to
13574follow @kbd{!} (when it is used as logical not, in an expression) with
13575a space or a tab to prevent it from being expanded. The readline
13576history facilities do not attempt substitution on the strings
13577@kbd{!=} and @kbd{!(}, even when history expansion is enabled.
13578
13579The commands to control history expansion are:
104c1213
JM
13580
13581@table @code
8e04817f
AC
13582@item set history expansion on
13583@itemx set history expansion
703663ab 13584@kindex set history expansion
8e04817f 13585Enable history expansion. History expansion is off by default.
104c1213 13586
8e04817f
AC
13587@item set history expansion off
13588Disable history expansion.
104c1213 13589
8e04817f
AC
13590@c @group
13591@kindex show history
13592@item show history
13593@itemx show history filename
13594@itemx show history save
13595@itemx show history size
13596@itemx show history expansion
13597These commands display the state of the @value{GDBN} history parameters.
13598@code{show history} by itself displays all four states.
13599@c @end group
13600@end table
13601
13602@table @code
13603@kindex shows
13604@item show commands
13605Display the last ten commands in the command history.
104c1213 13606
8e04817f
AC
13607@item show commands @var{n}
13608Print ten commands centered on command number @var{n}.
13609
13610@item show commands +
13611Print ten commands just after the commands last printed.
104c1213
JM
13612@end table
13613
8e04817f
AC
13614@node Screen Size
13615@section Screen size
13616@cindex size of screen
13617@cindex pauses in output
104c1213 13618
8e04817f
AC
13619Certain commands to @value{GDBN} may produce large amounts of
13620information output to the screen. To help you read all of it,
13621@value{GDBN} pauses and asks you for input at the end of each page of
13622output. Type @key{RET} when you want to continue the output, or @kbd{q}
13623to discard the remaining output. Also, the screen width setting
13624determines when to wrap lines of output. Depending on what is being
13625printed, @value{GDBN} tries to break the line at a readable place,
13626rather than simply letting it overflow onto the following line.
13627
13628Normally @value{GDBN} knows the size of the screen from the terminal
13629driver software. For example, on Unix @value{GDBN} uses the termcap data base
13630together with the value of the @code{TERM} environment variable and the
13631@code{stty rows} and @code{stty cols} settings. If this is not correct,
13632you can override it with the @code{set height} and @code{set
13633width} commands:
13634
13635@table @code
13636@kindex set height
13637@kindex set width
13638@kindex show width
13639@kindex show height
13640@item set height @var{lpp}
13641@itemx show height
13642@itemx set width @var{cpl}
13643@itemx show width
13644These @code{set} commands specify a screen height of @var{lpp} lines and
13645a screen width of @var{cpl} characters. The associated @code{show}
13646commands display the current settings.
104c1213 13647
8e04817f
AC
13648If you specify a height of zero lines, @value{GDBN} does not pause during
13649output no matter how long the output is. This is useful if output is to a
13650file or to an editor buffer.
104c1213 13651
8e04817f
AC
13652Likewise, you can specify @samp{set width 0} to prevent @value{GDBN}
13653from wrapping its output.
104c1213
JM
13654@end table
13655
8e04817f
AC
13656@node Numbers
13657@section Numbers
13658@cindex number representation
13659@cindex entering numbers
104c1213 13660
8e04817f
AC
13661You can always enter numbers in octal, decimal, or hexadecimal in
13662@value{GDBN} by the usual conventions: octal numbers begin with
13663@samp{0}, decimal numbers end with @samp{.}, and hexadecimal numbers
13664begin with @samp{0x}. Numbers that begin with none of these are, by
13665default, entered in base 10; likewise, the default display for
13666numbers---when no particular format is specified---is base 10. You can
13667change the default base for both input and output with the @code{set
13668radix} command.
104c1213 13669
8e04817f
AC
13670@table @code
13671@kindex set input-radix
13672@item set input-radix @var{base}
13673Set the default base for numeric input. Supported choices
13674for @var{base} are decimal 8, 10, or 16. @var{base} must itself be
13675specified either unambiguously or using the current default radix; for
13676example, any of
104c1213 13677
8e04817f
AC
13678@smallexample
13679set radix 012
13680set radix 10.
13681set radix 0xa
13682@end smallexample
104c1213 13683
8e04817f
AC
13684@noindent
13685sets the base to decimal. On the other hand, @samp{set radix 10}
13686leaves the radix unchanged no matter what it was.
104c1213 13687
8e04817f
AC
13688@kindex set output-radix
13689@item set output-radix @var{base}
13690Set the default base for numeric display. Supported choices
13691for @var{base} are decimal 8, 10, or 16. @var{base} must itself be
13692specified either unambiguously or using the current default radix.
104c1213 13693
8e04817f
AC
13694@kindex show input-radix
13695@item show input-radix
13696Display the current default base for numeric input.
104c1213 13697
8e04817f
AC
13698@kindex show output-radix
13699@item show output-radix
13700Display the current default base for numeric display.
13701@end table
104c1213 13702
1e698235
DJ
13703@node ABI
13704@section Configuring the current ABI
13705
13706@value{GDBN} can determine the @dfn{ABI} (Application Binary Interface) of your
13707application automatically. However, sometimes you need to override its
13708conclusions. Use these commands to manage @value{GDBN}'s view of the
13709current ABI.
13710
98b45e30
DJ
13711@cindex OS ABI
13712@kindex set osabi
b4e9345d 13713@kindex show osabi
98b45e30
DJ
13714
13715One @value{GDBN} configuration can debug binaries for multiple operating
b383017d 13716system targets, either via remote debugging or native emulation.
98b45e30
DJ
13717@value{GDBN} will autodetect the @dfn{OS ABI} (Operating System ABI) in use,
13718but you can override its conclusion using the @code{set osabi} command.
13719One example where this is useful is in debugging of binaries which use
13720an alternate C library (e.g.@: @sc{uClibc} for @sc{gnu}/Linux) which does
13721not have the same identifying marks that the standard C library for your
13722platform provides.
13723
13724@table @code
13725@item show osabi
13726Show the OS ABI currently in use.
13727
13728@item set osabi
13729With no argument, show the list of registered available OS ABI's.
13730
13731@item set osabi @var{abi}
13732Set the current OS ABI to @var{abi}.
13733@end table
13734
1e698235
DJ
13735@cindex float promotion
13736@kindex set coerce-float-to-double
13737
13738Generally, the way that an argument of type @code{float} is passed to a
13739function depends on whether the function is prototyped. For a prototyped
13740(i.e.@: ANSI/ISO style) function, @code{float} arguments are passed unchanged,
13741according to the architecture's convention for @code{float}. For unprototyped
13742(i.e.@: K&R style) functions, @code{float} arguments are first promoted to type
13743@code{double} and then passed.
13744
13745Unfortunately, some forms of debug information do not reliably indicate whether
13746a function is prototyped. If @value{GDBN} calls a function that is not marked
13747as prototyped, it consults @kbd{set coerce-float-to-double}.
13748
13749@table @code
13750@item set coerce-float-to-double
13751@itemx set coerce-float-to-double on
13752Arguments of type @code{float} will be promoted to @code{double} when passed
13753to an unprototyped function. This is the default setting.
13754
13755@item set coerce-float-to-double off
13756Arguments of type @code{float} will be passed directly to unprototyped
13757functions.
13758@end table
13759
f1212245
DJ
13760@kindex set cp-abi
13761@kindex show cp-abi
13762@value{GDBN} needs to know the ABI used for your program's C@t{++}
13763objects. The correct C@t{++} ABI depends on which C@t{++} compiler was
13764used to build your application. @value{GDBN} only fully supports
13765programs with a single C@t{++} ABI; if your program contains code using
13766multiple C@t{++} ABI's or if @value{GDBN} can not identify your
13767program's ABI correctly, you can tell @value{GDBN} which ABI to use.
13768Currently supported ABI's include ``gnu-v2'', for @code{g++} versions
13769before 3.0, ``gnu-v3'', for @code{g++} versions 3.0 and later, and
13770``hpaCC'' for the HP ANSI C@t{++} compiler. Other C@t{++} compilers may
13771use the ``gnu-v2'' or ``gnu-v3'' ABI's as well. The default setting is
13772``auto''.
13773
13774@table @code
13775@item show cp-abi
13776Show the C@t{++} ABI currently in use.
13777
13778@item set cp-abi
13779With no argument, show the list of supported C@t{++} ABI's.
13780
13781@item set cp-abi @var{abi}
13782@itemx set cp-abi auto
13783Set the current C@t{++} ABI to @var{abi}, or return to automatic detection.
13784@end table
13785
8e04817f
AC
13786@node Messages/Warnings
13787@section Optional warnings and messages
104c1213 13788
8e04817f
AC
13789By default, @value{GDBN} is silent about its inner workings. If you are
13790running on a slow machine, you may want to use the @code{set verbose}
13791command. This makes @value{GDBN} tell you when it does a lengthy
13792internal operation, so you will not think it has crashed.
104c1213 13793
8e04817f
AC
13794Currently, the messages controlled by @code{set verbose} are those
13795which announce that the symbol table for a source file is being read;
13796see @code{symbol-file} in @ref{Files, ,Commands to specify files}.
104c1213 13797
8e04817f
AC
13798@table @code
13799@kindex set verbose
13800@item set verbose on
13801Enables @value{GDBN} output of certain informational messages.
104c1213 13802
8e04817f
AC
13803@item set verbose off
13804Disables @value{GDBN} output of certain informational messages.
104c1213 13805
8e04817f
AC
13806@kindex show verbose
13807@item show verbose
13808Displays whether @code{set verbose} is on or off.
13809@end table
104c1213 13810
8e04817f
AC
13811By default, if @value{GDBN} encounters bugs in the symbol table of an
13812object file, it is silent; but if you are debugging a compiler, you may
13813find this information useful (@pxref{Symbol Errors, ,Errors reading
13814symbol files}).
104c1213 13815
8e04817f 13816@table @code
104c1213 13817
8e04817f
AC
13818@kindex set complaints
13819@item set complaints @var{limit}
13820Permits @value{GDBN} to output @var{limit} complaints about each type of
13821unusual symbols before becoming silent about the problem. Set
13822@var{limit} to zero to suppress all complaints; set it to a large number
13823to prevent complaints from being suppressed.
104c1213 13824
8e04817f
AC
13825@kindex show complaints
13826@item show complaints
13827Displays how many symbol complaints @value{GDBN} is permitted to produce.
104c1213 13828
8e04817f 13829@end table
104c1213 13830
8e04817f
AC
13831By default, @value{GDBN} is cautious, and asks what sometimes seems to be a
13832lot of stupid questions to confirm certain commands. For example, if
13833you try to run a program which is already running:
104c1213 13834
474c8240 13835@smallexample
8e04817f
AC
13836(@value{GDBP}) run
13837The program being debugged has been started already.
13838Start it from the beginning? (y or n)
474c8240 13839@end smallexample
104c1213 13840
8e04817f
AC
13841If you are willing to unflinchingly face the consequences of your own
13842commands, you can disable this ``feature'':
104c1213 13843
8e04817f 13844@table @code
104c1213 13845
8e04817f
AC
13846@kindex set confirm
13847@cindex flinching
13848@cindex confirmation
13849@cindex stupid questions
13850@item set confirm off
13851Disables confirmation requests.
104c1213 13852
8e04817f
AC
13853@item set confirm on
13854Enables confirmation requests (the default).
104c1213 13855
8e04817f
AC
13856@kindex show confirm
13857@item show confirm
13858Displays state of confirmation requests.
13859
13860@end table
104c1213 13861
8e04817f
AC
13862@node Debugging Output
13863@section Optional messages about internal happenings
4644b6e3
EZ
13864@cindex optional debugging messages
13865
104c1213 13866@table @code
4644b6e3
EZ
13867@kindex set debug
13868@cindex gdbarch debugging info
8e04817f
AC
13869@item set debug arch
13870Turns on or off display of gdbarch debugging info. The default is off
4644b6e3 13871@kindex show debug
8e04817f
AC
13872@item show debug arch
13873Displays the current state of displaying gdbarch debugging info.
8e04817f 13874@item set debug event
4644b6e3 13875@cindex event debugging info
8e04817f
AC
13876Turns on or off display of @value{GDBN} event debugging info. The
13877default is off.
8e04817f
AC
13878@item show debug event
13879Displays the current state of displaying @value{GDBN} event debugging
13880info.
8e04817f 13881@item set debug expression
4644b6e3 13882@cindex expression debugging info
8e04817f
AC
13883Turns on or off display of @value{GDBN} expression debugging info. The
13884default is off.
8e04817f
AC
13885@item show debug expression
13886Displays the current state of displaying @value{GDBN} expression
13887debugging info.
7453dc06 13888@item set debug frame
4644b6e3 13889@cindex frame debugging info
7453dc06
AC
13890Turns on or off display of @value{GDBN} frame debugging info. The
13891default is off.
7453dc06
AC
13892@item show debug frame
13893Displays the current state of displaying @value{GDBN} frame debugging
13894info.
30e91e0b
RC
13895@item set debug infrun
13896@cindex inferior debugging info
13897Turns on or off display of @value{GDBN} debugging info for running the inferior.
13898The default is off. @file{infrun.c} contains GDB's runtime state machine used
13899for implementing operations such as single-stepping the inferior.
13900@item show debug infrun
13901Displays the current state of @value{GDBN} inferior debugging.
2b4855ab 13902@item set debug observer
4644b6e3 13903@cindex observer debugging info
2b4855ab
AC
13904Turns on or off display of @value{GDBN} observer debugging. This
13905includes info such as the notification of observable events.
2b4855ab
AC
13906@item show debug observer
13907Displays the current state of observer debugging.
8e04817f 13908@item set debug overload
4644b6e3 13909@cindex C@t{++} overload debugging info
8e04817f
AC
13910Turns on or off display of @value{GDBN} C@t{++} overload debugging
13911info. This includes info such as ranking of functions, etc. The default
13912is off.
8e04817f
AC
13913@item show debug overload
13914Displays the current state of displaying @value{GDBN} C@t{++} overload
13915debugging info.
8e04817f
AC
13916@cindex packets, reporting on stdout
13917@cindex serial connections, debugging
13918@item set debug remote
13919Turns on or off display of reports on all packets sent back and forth across
13920the serial line to the remote machine. The info is printed on the
13921@value{GDBN} standard output stream. The default is off.
8e04817f
AC
13922@item show debug remote
13923Displays the state of display of remote packets.
8e04817f
AC
13924@item set debug serial
13925Turns on or off display of @value{GDBN} serial debugging info. The
13926default is off.
8e04817f
AC
13927@item show debug serial
13928Displays the current state of displaying @value{GDBN} serial debugging
13929info.
8e04817f 13930@item set debug target
4644b6e3 13931@cindex target debugging info
8e04817f
AC
13932Turns on or off display of @value{GDBN} target debugging info. This info
13933includes what is going on at the target level of GDB, as it happens. The
701b08bb
DJ
13934default is 0. Set it to 1 to track events, and to 2 to also track the
13935value of large memory transfers. Changes to this flag do not take effect
13936until the next time you connect to a target or use the @code{run} command.
8e04817f
AC
13937@item show debug target
13938Displays the current state of displaying @value{GDBN} target debugging
13939info.
8e04817f 13940@item set debug varobj
4644b6e3 13941@cindex variable object debugging info
8e04817f
AC
13942Turns on or off display of @value{GDBN} variable object debugging
13943info. The default is off.
8e04817f
AC
13944@item show debug varobj
13945Displays the current state of displaying @value{GDBN} variable object
13946debugging info.
13947@end table
104c1213 13948
8e04817f
AC
13949@node Sequences
13950@chapter Canned Sequences of Commands
104c1213 13951
8e04817f
AC
13952Aside from breakpoint commands (@pxref{Break Commands, ,Breakpoint
13953command lists}), @value{GDBN} provides two ways to store sequences of
13954commands for execution as a unit: user-defined commands and command
13955files.
104c1213 13956
8e04817f
AC
13957@menu
13958* Define:: User-defined commands
13959* Hooks:: User-defined command hooks
13960* Command Files:: Command files
13961* Output:: Commands for controlled output
13962@end menu
104c1213 13963
8e04817f
AC
13964@node Define
13965@section User-defined commands
104c1213 13966
8e04817f
AC
13967@cindex user-defined command
13968A @dfn{user-defined command} is a sequence of @value{GDBN} commands to
13969which you assign a new name as a command. This is done with the
13970@code{define} command. User commands may accept up to 10 arguments
13971separated by whitespace. Arguments are accessed within the user command
13972via @var{$arg0@dots{}$arg9}. A trivial example:
104c1213 13973
8e04817f
AC
13974@smallexample
13975define adder
13976 print $arg0 + $arg1 + $arg2
13977@end smallexample
104c1213
JM
13978
13979@noindent
8e04817f 13980To execute the command use:
104c1213 13981
8e04817f
AC
13982@smallexample
13983adder 1 2 3
13984@end smallexample
104c1213 13985
8e04817f
AC
13986@noindent
13987This defines the command @code{adder}, which prints the sum of
13988its three arguments. Note the arguments are text substitutions, so they may
13989reference variables, use complex expressions, or even perform inferior
13990functions calls.
104c1213
JM
13991
13992@table @code
104c1213 13993
8e04817f
AC
13994@kindex define
13995@item define @var{commandname}
13996Define a command named @var{commandname}. If there is already a command
13997by that name, you are asked to confirm that you want to redefine it.
104c1213 13998
8e04817f
AC
13999The definition of the command is made up of other @value{GDBN} command lines,
14000which are given following the @code{define} command. The end of these
14001commands is marked by a line containing @code{end}.
104c1213 14002
8e04817f
AC
14003@kindex if
14004@kindex else
14005@item if
14006Takes a single argument, which is an expression to evaluate.
14007It is followed by a series of commands that are executed
14008only if the expression is true (nonzero).
14009There can then optionally be a line @code{else}, followed
14010by a series of commands that are only executed if the expression
14011was false. The end of the list is marked by a line containing @code{end}.
104c1213 14012
8e04817f
AC
14013@kindex while
14014@item while
14015The syntax is similar to @code{if}: the command takes a single argument,
14016which is an expression to evaluate, and must be followed by the commands to
14017execute, one per line, terminated by an @code{end}.
14018The commands are executed repeatedly as long as the expression
14019evaluates to true.
104c1213 14020
8e04817f
AC
14021@kindex document
14022@item document @var{commandname}
14023Document the user-defined command @var{commandname}, so that it can be
14024accessed by @code{help}. The command @var{commandname} must already be
14025defined. This command reads lines of documentation just as @code{define}
14026reads the lines of the command definition, ending with @code{end}.
14027After the @code{document} command is finished, @code{help} on command
14028@var{commandname} displays the documentation you have written.
104c1213 14029
8e04817f
AC
14030You may use the @code{document} command again to change the
14031documentation of a command. Redefining the command with @code{define}
14032does not change the documentation.
104c1213 14033
8e04817f
AC
14034@kindex help user-defined
14035@item help user-defined
14036List all user-defined commands, with the first line of the documentation
14037(if any) for each.
104c1213 14038
8e04817f
AC
14039@kindex show user
14040@item show user
14041@itemx show user @var{commandname}
14042Display the @value{GDBN} commands used to define @var{commandname} (but
14043not its documentation). If no @var{commandname} is given, display the
14044definitions for all user-defined commands.
104c1213 14045
20f01a46
DH
14046@kindex show max-user-call-depth
14047@kindex set max-user-call-depth
14048@item show max-user-call-depth
5ca0cb28
DH
14049@itemx set max-user-call-depth
14050The value of @code{max-user-call-depth} controls how many recursion
14051levels are allowed in user-defined commands before GDB suspects an
14052infinite recursion and aborts the command.
20f01a46 14053
104c1213
JM
14054@end table
14055
8e04817f
AC
14056When user-defined commands are executed, the
14057commands of the definition are not printed. An error in any command
14058stops execution of the user-defined command.
104c1213 14059
8e04817f
AC
14060If used interactively, commands that would ask for confirmation proceed
14061without asking when used inside a user-defined command. Many @value{GDBN}
14062commands that normally print messages to say what they are doing omit the
14063messages when used in a user-defined command.
104c1213 14064
8e04817f
AC
14065@node Hooks
14066@section User-defined command hooks
14067@cindex command hooks
14068@cindex hooks, for commands
14069@cindex hooks, pre-command
104c1213 14070
8e04817f 14071@kindex hook
8e04817f
AC
14072You may define @dfn{hooks}, which are a special kind of user-defined
14073command. Whenever you run the command @samp{foo}, if the user-defined
14074command @samp{hook-foo} exists, it is executed (with no arguments)
14075before that command.
104c1213 14076
8e04817f
AC
14077@cindex hooks, post-command
14078@kindex hookpost
8e04817f
AC
14079A hook may also be defined which is run after the command you executed.
14080Whenever you run the command @samp{foo}, if the user-defined command
14081@samp{hookpost-foo} exists, it is executed (with no arguments) after
14082that command. Post-execution hooks may exist simultaneously with
14083pre-execution hooks, for the same command.
104c1213 14084
8e04817f
AC
14085It is valid for a hook to call the command which it hooks. If this
14086occurs, the hook is not re-executed, thereby avoiding infinte recursion.
104c1213 14087
8e04817f
AC
14088@c It would be nice if hookpost could be passed a parameter indicating
14089@c if the command it hooks executed properly or not. FIXME!
104c1213 14090
8e04817f
AC
14091@kindex stop@r{, a pseudo-command}
14092In addition, a pseudo-command, @samp{stop} exists. Defining
14093(@samp{hook-stop}) makes the associated commands execute every time
14094execution stops in your program: before breakpoint commands are run,
14095displays are printed, or the stack frame is printed.
104c1213 14096
8e04817f
AC
14097For example, to ignore @code{SIGALRM} signals while
14098single-stepping, but treat them normally during normal execution,
14099you could define:
104c1213 14100
474c8240 14101@smallexample
8e04817f
AC
14102define hook-stop
14103handle SIGALRM nopass
14104end
104c1213 14105
8e04817f
AC
14106define hook-run
14107handle SIGALRM pass
14108end
104c1213 14109
8e04817f
AC
14110define hook-continue
14111handle SIGLARM pass
14112end
474c8240 14113@end smallexample
104c1213 14114
8e04817f 14115As a further example, to hook at the begining and end of the @code{echo}
b383017d 14116command, and to add extra text to the beginning and end of the message,
8e04817f 14117you could define:
104c1213 14118
474c8240 14119@smallexample
8e04817f
AC
14120define hook-echo
14121echo <<<---
14122end
104c1213 14123
8e04817f
AC
14124define hookpost-echo
14125echo --->>>\n
14126end
104c1213 14127
8e04817f
AC
14128(@value{GDBP}) echo Hello World
14129<<<---Hello World--->>>
14130(@value{GDBP})
104c1213 14131
474c8240 14132@end smallexample
104c1213 14133
8e04817f
AC
14134You can define a hook for any single-word command in @value{GDBN}, but
14135not for command aliases; you should define a hook for the basic command
14136name, e.g. @code{backtrace} rather than @code{bt}.
14137@c FIXME! So how does Joe User discover whether a command is an alias
14138@c or not?
14139If an error occurs during the execution of your hook, execution of
14140@value{GDBN} commands stops and @value{GDBN} issues a prompt
14141(before the command that you actually typed had a chance to run).
104c1213 14142
8e04817f
AC
14143If you try to define a hook which does not match any known command, you
14144get a warning from the @code{define} command.
c906108c 14145
8e04817f
AC
14146@node Command Files
14147@section Command files
c906108c 14148
8e04817f
AC
14149@cindex command files
14150A command file for @value{GDBN} is a file of lines that are @value{GDBN}
14151commands. Comments (lines starting with @kbd{#}) may also be included.
14152An empty line in a command file does nothing; it does not mean to repeat
14153the last command, as it would from the terminal.
c906108c 14154
8e04817f
AC
14155@cindex init file
14156@cindex @file{.gdbinit}
14157@cindex @file{gdb.ini}
14158When you start @value{GDBN}, it automatically executes commands from its
14159@dfn{init files}, normally called @file{.gdbinit}@footnote{The DJGPP
14160port of @value{GDBN} uses the name @file{gdb.ini} instead, due to the
14161limitations of file names imposed by DOS filesystems.}.
14162During startup, @value{GDBN} does the following:
c906108c 14163
8e04817f
AC
14164@enumerate
14165@item
14166Reads the init file (if any) in your home directory@footnote{On
14167DOS/Windows systems, the home directory is the one pointed to by the
14168@code{HOME} environment variable.}.
c906108c 14169
8e04817f
AC
14170@item
14171Processes command line options and operands.
c906108c 14172
8e04817f
AC
14173@item
14174Reads the init file (if any) in the current working directory.
c906108c 14175
8e04817f
AC
14176@item
14177Reads command files specified by the @samp{-x} option.
14178@end enumerate
c906108c 14179
8e04817f
AC
14180The init file in your home directory can set options (such as @samp{set
14181complaints}) that affect subsequent processing of command line options
14182and operands. Init files are not executed if you use the @samp{-nx}
14183option (@pxref{Mode Options, ,Choosing modes}).
c906108c 14184
8e04817f
AC
14185@cindex init file name
14186On some configurations of @value{GDBN}, the init file is known by a
14187different name (these are typically environments where a specialized
14188form of @value{GDBN} may need to coexist with other forms, hence a
14189different name for the specialized version's init file). These are the
14190environments with special init file names:
c906108c 14191
8e04817f
AC
14192@cindex @file{.vxgdbinit}
14193@itemize @bullet
14194@item
14195VxWorks (Wind River Systems real-time OS): @file{.vxgdbinit}
c906108c 14196
8e04817f
AC
14197@cindex @file{.os68gdbinit}
14198@item
14199OS68K (Enea Data Systems real-time OS): @file{.os68gdbinit}
c906108c 14200
8e04817f
AC
14201@cindex @file{.esgdbinit}
14202@item
14203ES-1800 (Ericsson Telecom AB M68000 emulator): @file{.esgdbinit}
14204@end itemize
c906108c 14205
8e04817f
AC
14206You can also request the execution of a command file with the
14207@code{source} command:
c906108c 14208
8e04817f
AC
14209@table @code
14210@kindex source
14211@item source @var{filename}
14212Execute the command file @var{filename}.
c906108c
SS
14213@end table
14214
8e04817f 14215The lines in a command file are executed sequentially. They are not
a71ec265
DH
14216printed as they are executed. An error in any command terminates
14217execution of the command file and control is returned to the console.
c906108c 14218
8e04817f
AC
14219Commands that would ask for confirmation if used interactively proceed
14220without asking when used in a command file. Many @value{GDBN} commands that
14221normally print messages to say what they are doing omit the messages
14222when called from command files.
c906108c 14223
8e04817f
AC
14224@value{GDBN} also accepts command input from standard input. In this
14225mode, normal output goes to standard output and error output goes to
14226standard error. Errors in a command file supplied on standard input do
14227not terminate execution of the command file --- execution continues with
14228the next command.
c906108c 14229
474c8240 14230@smallexample
8e04817f 14231gdb < cmds > log 2>&1
474c8240 14232@end smallexample
c906108c 14233
8e04817f
AC
14234(The syntax above will vary depending on the shell used.) This example
14235will execute commands from the file @file{cmds}. All output and errors
14236would be directed to @file{log}.
c906108c 14237
8e04817f
AC
14238@node Output
14239@section Commands for controlled output
c906108c 14240
8e04817f
AC
14241During the execution of a command file or a user-defined command, normal
14242@value{GDBN} output is suppressed; the only output that appears is what is
14243explicitly printed by the commands in the definition. This section
14244describes three commands useful for generating exactly the output you
14245want.
c906108c
SS
14246
14247@table @code
8e04817f
AC
14248@kindex echo
14249@item echo @var{text}
14250@c I do not consider backslash-space a standard C escape sequence
14251@c because it is not in ANSI.
14252Print @var{text}. Nonprinting characters can be included in
14253@var{text} using C escape sequences, such as @samp{\n} to print a
14254newline. @strong{No newline is printed unless you specify one.}
14255In addition to the standard C escape sequences, a backslash followed
14256by a space stands for a space. This is useful for displaying a
14257string with spaces at the beginning or the end, since leading and
14258trailing spaces are otherwise trimmed from all arguments.
14259To print @samp{@w{ }and foo =@w{ }}, use the command
14260@samp{echo \@w{ }and foo = \@w{ }}.
c906108c 14261
8e04817f
AC
14262A backslash at the end of @var{text} can be used, as in C, to continue
14263the command onto subsequent lines. For example,
c906108c 14264
474c8240 14265@smallexample
8e04817f
AC
14266echo This is some text\n\
14267which is continued\n\
14268onto several lines.\n
474c8240 14269@end smallexample
c906108c 14270
8e04817f 14271produces the same output as
c906108c 14272
474c8240 14273@smallexample
8e04817f
AC
14274echo This is some text\n
14275echo which is continued\n
14276echo onto several lines.\n
474c8240 14277@end smallexample
c906108c 14278
8e04817f
AC
14279@kindex output
14280@item output @var{expression}
14281Print the value of @var{expression} and nothing but that value: no
14282newlines, no @samp{$@var{nn} = }. The value is not entered in the
14283value history either. @xref{Expressions, ,Expressions}, for more information
14284on expressions.
c906108c 14285
8e04817f
AC
14286@item output/@var{fmt} @var{expression}
14287Print the value of @var{expression} in format @var{fmt}. You can use
14288the same formats as for @code{print}. @xref{Output Formats,,Output
14289formats}, for more information.
c906108c 14290
8e04817f
AC
14291@kindex printf
14292@item printf @var{string}, @var{expressions}@dots{}
14293Print the values of the @var{expressions} under the control of
14294@var{string}. The @var{expressions} are separated by commas and may be
14295either numbers or pointers. Their values are printed as specified by
14296@var{string}, exactly as if your program were to execute the C
14297subroutine
14298@c FIXME: the above implies that at least all ANSI C formats are
14299@c supported, but it isn't true: %E and %G don't work (or so it seems).
14300@c Either this is a bug, or the manual should document what formats are
14301@c supported.
c906108c 14302
474c8240 14303@smallexample
8e04817f 14304printf (@var{string}, @var{expressions}@dots{});
474c8240 14305@end smallexample
c906108c 14306
8e04817f 14307For example, you can print two values in hex like this:
c906108c 14308
8e04817f
AC
14309@smallexample
14310printf "foo, bar-foo = 0x%x, 0x%x\n", foo, bar-foo
14311@end smallexample
c906108c 14312
8e04817f
AC
14313The only backslash-escape sequences that you can use in the format
14314string are the simple ones that consist of backslash followed by a
14315letter.
c906108c
SS
14316@end table
14317
21c294e6
AC
14318@node Interpreters
14319@chapter Command Interpreters
14320@cindex command interpreters
14321
14322@value{GDBN} supports multiple command interpreters, and some command
14323infrastructure to allow users or user interface writers to switch
14324between interpreters or run commands in other interpreters.
14325
14326@value{GDBN} currently supports two command interpreters, the console
14327interpreter (sometimes called the command-line interpreter or @sc{cli})
14328and the machine interface interpreter (or @sc{gdb/mi}). This manual
14329describes both of these interfaces in great detail.
14330
14331By default, @value{GDBN} will start with the console interpreter.
14332However, the user may choose to start @value{GDBN} with another
14333interpreter by specifying the @option{-i} or @option{--interpreter}
14334startup options. Defined interpreters include:
14335
14336@table @code
14337@item console
14338@cindex console interpreter
14339The traditional console or command-line interpreter. This is the most often
14340used interpreter with @value{GDBN}. With no interpreter specified at runtime,
14341@value{GDBN} will use this interpreter.
14342
14343@item mi
14344@cindex mi interpreter
14345The newest @sc{gdb/mi} interface (currently @code{mi2}). Used primarily
14346by programs wishing to use @value{GDBN} as a backend for a debugger GUI
14347or an IDE. For more information, see @ref{GDB/MI, ,The @sc{gdb/mi}
14348Interface}.
14349
14350@item mi2
14351@cindex mi2 interpreter
14352The current @sc{gdb/mi} interface.
14353
14354@item mi1
14355@cindex mi1 interpreter
14356The @sc{gdb/mi} interface included in @value{GDBN} 5.1, 5.2, and 5.3.
14357
14358@end table
14359
14360@cindex invoke another interpreter
14361The interpreter being used by @value{GDBN} may not be dynamically
14362switched at runtime. Although possible, this could lead to a very
14363precarious situation. Consider an IDE using @sc{gdb/mi}. If a user
14364enters the command "interpreter-set console" in a console view,
14365@value{GDBN} would switch to using the console interpreter, rendering
14366the IDE inoperable!
14367
14368@kindex interpreter-exec
14369Although you may only choose a single interpreter at startup, you may execute
14370commands in any interpreter from the current interpreter using the appropriate
14371command. If you are running the console interpreter, simply use the
14372@code{interpreter-exec} command:
14373
14374@smallexample
14375interpreter-exec mi "-data-list-register-names"
14376@end smallexample
14377
14378@sc{gdb/mi} has a similar command, although it is only available in versions of
14379@value{GDBN} which support @sc{gdb/mi} version 2 (or greater).
14380
8e04817f
AC
14381@node TUI
14382@chapter @value{GDBN} Text User Interface
14383@cindex TUI
d0d5df6f 14384@cindex Text User Interface
c906108c 14385
8e04817f
AC
14386@menu
14387* TUI Overview:: TUI overview
14388* TUI Keys:: TUI key bindings
7cf36c78 14389* TUI Single Key Mode:: TUI single key mode
8e04817f
AC
14390* TUI Commands:: TUI specific commands
14391* TUI Configuration:: TUI configuration variables
14392@end menu
c906108c 14393
d0d5df6f
AC
14394The @value{GDBN} Text User Interface, TUI in short, is a terminal
14395interface which uses the @code{curses} library to show the source
14396file, the assembly output, the program registers and @value{GDBN}
14397commands in separate text windows.
14398
14399The TUI is enabled by invoking @value{GDBN} using either
14400@pindex gdbtui
14401@samp{gdbtui} or @samp{gdb -tui}.
c906108c 14402
8e04817f
AC
14403@node TUI Overview
14404@section TUI overview
c906108c 14405
8e04817f
AC
14406The TUI has two display modes that can be switched while
14407@value{GDBN} runs:
c906108c 14408
8e04817f
AC
14409@itemize @bullet
14410@item
14411A curses (or TUI) mode in which it displays several text
14412windows on the terminal.
c906108c 14413
8e04817f
AC
14414@item
14415A standard mode which corresponds to the @value{GDBN} configured without
14416the TUI.
14417@end itemize
c906108c 14418
8e04817f
AC
14419In the TUI mode, @value{GDBN} can display several text window
14420on the terminal:
c906108c 14421
8e04817f
AC
14422@table @emph
14423@item command
14424This window is the @value{GDBN} command window with the @value{GDBN}
14425prompt and the @value{GDBN} outputs. The @value{GDBN} input is still
14426managed using readline but through the TUI. The @emph{command}
14427window is always visible.
c906108c 14428
8e04817f
AC
14429@item source
14430The source window shows the source file of the program. The current
14431line as well as active breakpoints are displayed in this window.
c906108c 14432
8e04817f
AC
14433@item assembly
14434The assembly window shows the disassembly output of the program.
c906108c 14435
8e04817f
AC
14436@item register
14437This window shows the processor registers. It detects when
14438a register is changed and when this is the case, registers that have
6a1b180d 14439changed are highlighted.
c906108c 14440
c906108c
SS
14441@end table
14442
269c21fe
SC
14443The source and assembly windows show the current program position
14444by highlighting the current line and marking them with the @samp{>} marker.
14445Breakpoints are also indicated with two markers. A first one
14446indicates the breakpoint type:
14447
14448@table @code
14449@item B
14450Breakpoint which was hit at least once.
14451
14452@item b
14453Breakpoint which was never hit.
14454
14455@item H
14456Hardware breakpoint which was hit at least once.
14457
14458@item h
14459Hardware breakpoint which was never hit.
14460
14461@end table
14462
14463The second marker indicates whether the breakpoint is enabled or not:
14464
14465@table @code
14466@item +
14467Breakpoint is enabled.
14468
14469@item -
14470Breakpoint is disabled.
14471
14472@end table
14473
8e04817f
AC
14474The source, assembly and register windows are attached to the thread
14475and the frame position. They are updated when the current thread
14476changes, when the frame changes or when the program counter changes.
14477These three windows are arranged by the TUI according to several
14478layouts. The layout defines which of these three windows are visible.
14479The following layouts are available:
c906108c 14480
8e04817f
AC
14481@itemize @bullet
14482@item
14483source
2df3850c 14484
8e04817f
AC
14485@item
14486assembly
14487
14488@item
14489source and assembly
14490
14491@item
14492source and registers
c906108c 14493
8e04817f
AC
14494@item
14495assembly and registers
2df3850c 14496
8e04817f 14497@end itemize
c906108c 14498
b7bb15bc
SC
14499On top of the command window a status line gives various information
14500concerning the current process begin debugged. The status line is
14501updated when the information it shows changes. The following fields
14502are displayed:
14503
14504@table @emph
14505@item target
14506Indicates the current gdb target
14507(@pxref{Targets, ,Specifying a Debugging Target}).
14508
14509@item process
14510Gives information about the current process or thread number.
14511When no process is being debugged, this field is set to @code{No process}.
14512
14513@item function
14514Gives the current function name for the selected frame.
14515The name is demangled if demangling is turned on (@pxref{Print Settings}).
14516When there is no symbol corresponding to the current program counter
14517the string @code{??} is displayed.
14518
14519@item line
14520Indicates the current line number for the selected frame.
14521When the current line number is not known the string @code{??} is displayed.
14522
14523@item pc
14524Indicates the current program counter address.
14525
14526@end table
14527
8e04817f
AC
14528@node TUI Keys
14529@section TUI Key Bindings
14530@cindex TUI key bindings
c906108c 14531
8e04817f
AC
14532The TUI installs several key bindings in the readline keymaps
14533(@pxref{Command Line Editing}).
14534They allow to leave or enter in the TUI mode or they operate
7cf36c78
SC
14535directly on the TUI layout and windows. The TUI also provides
14536a @emph{SingleKey} keymap which binds several keys directly to
14537@value{GDBN} commands. The following key bindings
8e04817f 14538are installed for both TUI mode and the @value{GDBN} standard mode.
c906108c 14539
8e04817f
AC
14540@table @kbd
14541@kindex C-x C-a
14542@item C-x C-a
14543@kindex C-x a
14544@itemx C-x a
14545@kindex C-x A
14546@itemx C-x A
14547Enter or leave the TUI mode. When the TUI mode is left,
14548the curses window management is left and @value{GDBN} operates using
14549its standard mode writing on the terminal directly. When the TUI
14550mode is entered, the control is given back to the curses windows.
14551The screen is then refreshed.
c906108c 14552
8e04817f
AC
14553@kindex C-x 1
14554@item C-x 1
14555Use a TUI layout with only one window. The layout will
14556either be @samp{source} or @samp{assembly}. When the TUI mode
14557is not active, it will switch to the TUI mode.
2df3850c 14558
8e04817f 14559Think of this key binding as the Emacs @kbd{C-x 1} binding.
c906108c 14560
8e04817f
AC
14561@kindex C-x 2
14562@item C-x 2
14563Use a TUI layout with at least two windows. When the current
14564layout shows already two windows, a next layout with two windows is used.
14565When a new layout is chosen, one window will always be common to the
14566previous layout and the new one.
c906108c 14567
8e04817f 14568Think of it as the Emacs @kbd{C-x 2} binding.
2df3850c 14569
72ffddc9
SC
14570@kindex C-x o
14571@item C-x o
14572Change the active window. The TUI associates several key bindings
14573(like scrolling and arrow keys) to the active window. This command
14574gives the focus to the next TUI window.
14575
14576Think of it as the Emacs @kbd{C-x o} binding.
14577
7cf36c78
SC
14578@kindex C-x s
14579@item C-x s
14580Use the TUI @emph{SingleKey} keymap that binds single key to gdb commands
14581(@pxref{TUI Single Key Mode}).
14582
c906108c
SS
14583@end table
14584
8e04817f 14585The following key bindings are handled only by the TUI mode:
5d161b24 14586
8e04817f
AC
14587@table @key
14588@kindex PgUp
14589@item PgUp
14590Scroll the active window one page up.
c906108c 14591
8e04817f
AC
14592@kindex PgDn
14593@item PgDn
14594Scroll the active window one page down.
c906108c 14595
8e04817f
AC
14596@kindex Up
14597@item Up
14598Scroll the active window one line up.
c906108c 14599
8e04817f
AC
14600@kindex Down
14601@item Down
14602Scroll the active window one line down.
c906108c 14603
8e04817f
AC
14604@kindex Left
14605@item Left
14606Scroll the active window one column left.
c906108c 14607
8e04817f
AC
14608@kindex Right
14609@item Right
14610Scroll the active window one column right.
c906108c 14611
8e04817f
AC
14612@kindex C-L
14613@item C-L
14614Refresh the screen.
c906108c 14615
8e04817f 14616@end table
c906108c 14617
8e04817f 14618In the TUI mode, the arrow keys are used by the active window
72ffddc9
SC
14619for scrolling. This means they are available for readline when the
14620active window is the command window. When the command window
14621does not have the focus, it is necessary to use other readline
14622key bindings such as @key{C-p}, @key{C-n}, @key{C-b} and @key{C-f}.
8e04817f 14623
7cf36c78
SC
14624@node TUI Single Key Mode
14625@section TUI Single Key Mode
14626@cindex TUI single key mode
14627
14628The TUI provides a @emph{SingleKey} mode in which it installs a particular
14629key binding in the readline keymaps to connect single keys to
b383017d 14630some gdb commands.
7cf36c78
SC
14631
14632@table @kbd
14633@kindex c @r{(SingleKey TUI key)}
14634@item c
14635continue
14636
14637@kindex d @r{(SingleKey TUI key)}
14638@item d
14639down
14640
14641@kindex f @r{(SingleKey TUI key)}
14642@item f
14643finish
14644
14645@kindex n @r{(SingleKey TUI key)}
14646@item n
14647next
14648
14649@kindex q @r{(SingleKey TUI key)}
14650@item q
14651exit the @emph{SingleKey} mode.
14652
14653@kindex r @r{(SingleKey TUI key)}
14654@item r
14655run
14656
14657@kindex s @r{(SingleKey TUI key)}
14658@item s
14659step
14660
14661@kindex u @r{(SingleKey TUI key)}
14662@item u
14663up
14664
14665@kindex v @r{(SingleKey TUI key)}
14666@item v
14667info locals
14668
14669@kindex w @r{(SingleKey TUI key)}
14670@item w
14671where
14672
14673@end table
14674
14675Other keys temporarily switch to the @value{GDBN} command prompt.
14676The key that was pressed is inserted in the editing buffer so that
14677it is possible to type most @value{GDBN} commands without interaction
14678with the TUI @emph{SingleKey} mode. Once the command is entered the TUI
14679@emph{SingleKey} mode is restored. The only way to permanently leave
14680this mode is by hitting @key{q} or @samp{@key{C-x} @key{s}}.
14681
14682
8e04817f
AC
14683@node TUI Commands
14684@section TUI specific commands
14685@cindex TUI commands
14686
14687The TUI has specific commands to control the text windows.
14688These commands are always available, that is they do not depend on
14689the current terminal mode in which @value{GDBN} runs. When @value{GDBN}
14690is in the standard mode, using these commands will automatically switch
14691in the TUI mode.
c906108c
SS
14692
14693@table @code
3d757584
SC
14694@item info win
14695@kindex info win
14696List and give the size of all displayed windows.
14697
8e04817f 14698@item layout next
4644b6e3 14699@kindex layout
8e04817f 14700Display the next layout.
2df3850c 14701
8e04817f 14702@item layout prev
8e04817f 14703Display the previous layout.
c906108c 14704
8e04817f 14705@item layout src
8e04817f 14706Display the source window only.
c906108c 14707
8e04817f 14708@item layout asm
8e04817f 14709Display the assembly window only.
c906108c 14710
8e04817f 14711@item layout split
8e04817f 14712Display the source and assembly window.
c906108c 14713
8e04817f 14714@item layout regs
8e04817f
AC
14715Display the register window together with the source or assembly window.
14716
14717@item focus next | prev | src | asm | regs | split
14718@kindex focus
14719Set the focus to the named window.
14720This command allows to change the active window so that scrolling keys
14721can be affected to another window.
c906108c 14722
8e04817f
AC
14723@item refresh
14724@kindex refresh
14725Refresh the screen. This is similar to using @key{C-L} key.
c906108c 14726
6a1b180d
SC
14727@item tui reg float
14728@kindex tui reg
14729Show the floating point registers in the register window.
14730
14731@item tui reg general
14732Show the general registers in the register window.
14733
14734@item tui reg next
14735Show the next register group. The list of register groups as well as
14736their order is target specific. The predefined register groups are the
14737following: @code{general}, @code{float}, @code{system}, @code{vector},
14738@code{all}, @code{save}, @code{restore}.
14739
14740@item tui reg system
14741Show the system registers in the register window.
14742
8e04817f
AC
14743@item update
14744@kindex update
14745Update the source window and the current execution point.
c906108c 14746
8e04817f
AC
14747@item winheight @var{name} +@var{count}
14748@itemx winheight @var{name} -@var{count}
14749@kindex winheight
14750Change the height of the window @var{name} by @var{count}
14751lines. Positive counts increase the height, while negative counts
14752decrease it.
2df3850c 14753
c906108c
SS
14754@end table
14755
8e04817f
AC
14756@node TUI Configuration
14757@section TUI configuration variables
14758@cindex TUI configuration variables
c906108c 14759
8e04817f
AC
14760The TUI has several configuration variables that control the
14761appearance of windows on the terminal.
c906108c 14762
8e04817f
AC
14763@table @code
14764@item set tui border-kind @var{kind}
14765@kindex set tui border-kind
14766Select the border appearance for the source, assembly and register windows.
14767The possible values are the following:
14768@table @code
14769@item space
14770Use a space character to draw the border.
c906108c 14771
8e04817f
AC
14772@item ascii
14773Use ascii characters + - and | to draw the border.
c906108c 14774
8e04817f
AC
14775@item acs
14776Use the Alternate Character Set to draw the border. The border is
14777drawn using character line graphics if the terminal supports them.
c78b4128 14778
8e04817f 14779@end table
c78b4128 14780
8e04817f
AC
14781@item set tui active-border-mode @var{mode}
14782@kindex set tui active-border-mode
14783Select the attributes to display the border of the active window.
14784The possible values are @code{normal}, @code{standout}, @code{reverse},
14785@code{half}, @code{half-standout}, @code{bold} and @code{bold-standout}.
c78b4128 14786
8e04817f
AC
14787@item set tui border-mode @var{mode}
14788@kindex set tui border-mode
14789Select the attributes to display the border of other windows.
14790The @var{mode} can be one of the following:
14791@table @code
14792@item normal
14793Use normal attributes to display the border.
c906108c 14794
8e04817f
AC
14795@item standout
14796Use standout mode.
c906108c 14797
8e04817f
AC
14798@item reverse
14799Use reverse video mode.
c906108c 14800
8e04817f
AC
14801@item half
14802Use half bright mode.
c906108c 14803
8e04817f
AC
14804@item half-standout
14805Use half bright and standout mode.
c906108c 14806
8e04817f
AC
14807@item bold
14808Use extra bright or bold mode.
c78b4128 14809
8e04817f
AC
14810@item bold-standout
14811Use extra bright or bold and standout mode.
c78b4128 14812
8e04817f 14813@end table
c78b4128 14814
8e04817f 14815@end table
c78b4128 14816
8e04817f
AC
14817@node Emacs
14818@chapter Using @value{GDBN} under @sc{gnu} Emacs
c78b4128 14819
8e04817f
AC
14820@cindex Emacs
14821@cindex @sc{gnu} Emacs
14822A special interface allows you to use @sc{gnu} Emacs to view (and
14823edit) the source files for the program you are debugging with
14824@value{GDBN}.
c906108c 14825
8e04817f
AC
14826To use this interface, use the command @kbd{M-x gdb} in Emacs. Give the
14827executable file you want to debug as an argument. This command starts
14828@value{GDBN} as a subprocess of Emacs, with input and output through a newly
14829created Emacs buffer.
14830@c (Do not use the @code{-tui} option to run @value{GDBN} from Emacs.)
c906108c 14831
8e04817f
AC
14832Using @value{GDBN} under Emacs is just like using @value{GDBN} normally except for two
14833things:
c906108c 14834
8e04817f
AC
14835@itemize @bullet
14836@item
14837All ``terminal'' input and output goes through the Emacs buffer.
14838@end itemize
c906108c 14839
8e04817f
AC
14840This applies both to @value{GDBN} commands and their output, and to the input
14841and output done by the program you are debugging.
bf0184be 14842
8e04817f
AC
14843This is useful because it means that you can copy the text of previous
14844commands and input them again; you can even use parts of the output
14845in this way.
bf0184be 14846
8e04817f
AC
14847All the facilities of Emacs' Shell mode are available for interacting
14848with your program. In particular, you can send signals the usual
14849way---for example, @kbd{C-c C-c} for an interrupt, @kbd{C-c C-z} for a
14850stop.
bf0184be 14851
8e04817f 14852@itemize @bullet
bf0184be 14853@item
8e04817f
AC
14854@value{GDBN} displays source code through Emacs.
14855@end itemize
bf0184be 14856
8e04817f
AC
14857Each time @value{GDBN} displays a stack frame, Emacs automatically finds the
14858source file for that frame and puts an arrow (@samp{=>}) at the
14859left margin of the current line. Emacs uses a separate buffer for
14860source display, and splits the screen to show both your @value{GDBN} session
14861and the source.
bf0184be 14862
8e04817f
AC
14863Explicit @value{GDBN} @code{list} or search commands still produce output as
14864usual, but you probably have no reason to use them from Emacs.
c906108c 14865
64fabec2
AC
14866If you specify an absolute file name when prompted for the @kbd{M-x
14867gdb} argument, then Emacs sets your current working directory to where
14868your program resides. If you only specify the file name, then Emacs
14869sets your current working directory to to the directory associated
14870with the previous buffer. In this case, @value{GDBN} may find your
14871program by searching your environment's @code{PATH} variable, but on
14872some operating systems it might not find the source. So, although the
14873@value{GDBN} input and output session proceeds normally, the auxiliary
14874buffer does not display the current source and line of execution.
14875
14876The initial working directory of @value{GDBN} is printed on the top
14877line of the @value{GDBN} I/O buffer and this serves as a default for
14878the commands that specify files for @value{GDBN} to operate
14879on. @xref{Files, ,Commands to specify files}.
14880
14881By default, @kbd{M-x gdb} calls the program called @file{gdb}. If you
14882need to call @value{GDBN} by a different name (for example, if you
14883keep several configurations around, with different names) you can
14884customize the Emacs variable @code{gud-gdb-command-name} to run the
14885one you want.
8e04817f
AC
14886
14887In the @value{GDBN} I/O buffer, you can use these special Emacs commands in
14888addition to the standard Shell mode commands:
c906108c 14889
8e04817f
AC
14890@table @kbd
14891@item C-h m
14892Describe the features of Emacs' @value{GDBN} Mode.
c906108c 14893
64fabec2 14894@item C-c C-s
8e04817f
AC
14895Execute to another source line, like the @value{GDBN} @code{step} command; also
14896update the display window to show the current file and location.
c906108c 14897
64fabec2 14898@item C-c C-n
8e04817f
AC
14899Execute to next source line in this function, skipping all function
14900calls, like the @value{GDBN} @code{next} command. Then update the display window
14901to show the current file and location.
c906108c 14902
64fabec2 14903@item C-c C-i
8e04817f
AC
14904Execute one instruction, like the @value{GDBN} @code{stepi} command; update
14905display window accordingly.
c906108c 14906
8e04817f
AC
14907@item C-c C-f
14908Execute until exit from the selected stack frame, like the @value{GDBN}
14909@code{finish} command.
c906108c 14910
64fabec2 14911@item C-c C-r
8e04817f
AC
14912Continue execution of your program, like the @value{GDBN} @code{continue}
14913command.
b433d00b 14914
64fabec2 14915@item C-c <
8e04817f
AC
14916Go up the number of frames indicated by the numeric argument
14917(@pxref{Arguments, , Numeric Arguments, Emacs, The @sc{gnu} Emacs Manual}),
14918like the @value{GDBN} @code{up} command.
b433d00b 14919
64fabec2 14920@item C-c >
8e04817f
AC
14921Go down the number of frames indicated by the numeric argument, like the
14922@value{GDBN} @code{down} command.
8e04817f 14923@end table
c906108c 14924
64fabec2 14925In any source file, the Emacs command @kbd{C-x SPC} (@code{gud-break})
8e04817f 14926tells @value{GDBN} to set a breakpoint on the source line point is on.
c906108c 14927
64fabec2
AC
14928If you type @kbd{M-x speedbar}, then Emacs displays a separate frame which
14929shows a backtrace when the @value{GDBN} I/O buffer is current. Move
14930point to any frame in the stack and type @key{RET} to make it become the
14931current frame and display the associated source in the source buffer.
14932Alternatively, click @kbd{Mouse-2} to make the selected frame become the
14933current one.
14934
8e04817f
AC
14935If you accidentally delete the source-display buffer, an easy way to get
14936it back is to type the command @code{f} in the @value{GDBN} buffer, to
14937request a frame display; when you run under Emacs, this recreates
14938the source buffer if necessary to show you the context of the current
14939frame.
c906108c 14940
8e04817f
AC
14941The source files displayed in Emacs are in ordinary Emacs buffers
14942which are visiting the source files in the usual way. You can edit
14943the files with these buffers if you wish; but keep in mind that @value{GDBN}
14944communicates with Emacs in terms of line numbers. If you add or
14945delete lines from the text, the line numbers that @value{GDBN} knows cease
14946to correspond properly with the code.
b383017d 14947
64fabec2
AC
14948The description given here is for GNU Emacs version 21.3 and a more
14949detailed description of its interaction with @value{GDBN} is given in
14950the Emacs manual (@pxref{Debuggers,,, Emacs, The @sc{gnu} Emacs Manual}).
c906108c 14951
8e04817f
AC
14952@c The following dropped because Epoch is nonstandard. Reactivate
14953@c if/when v19 does something similar. ---doc@cygnus.com 19dec1990
14954@ignore
14955@kindex Emacs Epoch environment
14956@kindex Epoch
14957@kindex inspect
c906108c 14958
8e04817f
AC
14959Version 18 of @sc{gnu} Emacs has a built-in window system
14960called the @code{epoch}
14961environment. Users of this environment can use a new command,
14962@code{inspect} which performs identically to @code{print} except that
14963each value is printed in its own window.
14964@end ignore
c906108c 14965
922fbb7b
AC
14966
14967@node GDB/MI
14968@chapter The @sc{gdb/mi} Interface
14969
14970@unnumberedsec Function and Purpose
14971
14972@cindex @sc{gdb/mi}, its purpose
14973@sc{gdb/mi} is a line based machine oriented text interface to @value{GDBN}. It is
14974specifically intended to support the development of systems which use
14975the debugger as just one small component of a larger system.
14976
14977This chapter is a specification of the @sc{gdb/mi} interface. It is written
14978in the form of a reference manual.
14979
14980Note that @sc{gdb/mi} is still under construction, so some of the
14981features described below are incomplete and subject to change.
14982
14983@unnumberedsec Notation and Terminology
14984
14985@cindex notational conventions, for @sc{gdb/mi}
14986This chapter uses the following notation:
14987
14988@itemize @bullet
14989@item
14990@code{|} separates two alternatives.
14991
14992@item
14993@code{[ @var{something} ]} indicates that @var{something} is optional:
14994it may or may not be given.
14995
14996@item
14997@code{( @var{group} )*} means that @var{group} inside the parentheses
14998may repeat zero or more times.
14999
15000@item
15001@code{( @var{group} )+} means that @var{group} inside the parentheses
15002may repeat one or more times.
15003
15004@item
15005@code{"@var{string}"} means a literal @var{string}.
15006@end itemize
15007
15008@ignore
15009@heading Dependencies
15010@end ignore
15011
15012@heading Acknowledgments
15013
15014In alphabetic order: Andrew Cagney, Fernando Nasser, Stan Shebs and
15015Elena Zannoni.
15016
15017@menu
15018* GDB/MI Command Syntax::
15019* GDB/MI Compatibility with CLI::
15020* GDB/MI Output Records::
15021* GDB/MI Command Description Format::
15022* GDB/MI Breakpoint Table Commands::
15023* GDB/MI Data Manipulation::
15024* GDB/MI Program Control::
15025* GDB/MI Miscellaneous Commands::
15026@ignore
15027* GDB/MI Kod Commands::
15028* GDB/MI Memory Overlay Commands::
15029* GDB/MI Signal Handling Commands::
15030@end ignore
15031* GDB/MI Stack Manipulation::
15032* GDB/MI Symbol Query::
15033* GDB/MI Target Manipulation::
15034* GDB/MI Thread Commands::
15035* GDB/MI Tracepoint Commands::
15036* GDB/MI Variable Objects::
15037@end menu
15038
15039@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
15040@node GDB/MI Command Syntax
15041@section @sc{gdb/mi} Command Syntax
15042
15043@menu
15044* GDB/MI Input Syntax::
15045* GDB/MI Output Syntax::
15046* GDB/MI Simple Examples::
15047@end menu
15048
15049@node GDB/MI Input Syntax
15050@subsection @sc{gdb/mi} Input Syntax
15051
15052@cindex input syntax for @sc{gdb/mi}
15053@cindex @sc{gdb/mi}, input syntax
15054@table @code
15055@item @var{command} @expansion{}
15056@code{@var{cli-command} | @var{mi-command}}
15057
15058@item @var{cli-command} @expansion{}
15059@code{[ @var{token} ] @var{cli-command} @var{nl}}, where
15060@var{cli-command} is any existing @value{GDBN} CLI command.
15061
15062@item @var{mi-command} @expansion{}
15063@code{[ @var{token} ] "-" @var{operation} ( " " @var{option} )*
15064@code{[} " --" @code{]} ( " " @var{parameter} )* @var{nl}}
15065
15066@item @var{token} @expansion{}
15067"any sequence of digits"
15068
15069@item @var{option} @expansion{}
15070@code{"-" @var{parameter} [ " " @var{parameter} ]}
15071
15072@item @var{parameter} @expansion{}
15073@code{@var{non-blank-sequence} | @var{c-string}}
15074
15075@item @var{operation} @expansion{}
15076@emph{any of the operations described in this chapter}
15077
15078@item @var{non-blank-sequence} @expansion{}
15079@emph{anything, provided it doesn't contain special characters such as
15080"-", @var{nl}, """ and of course " "}
15081
15082@item @var{c-string} @expansion{}
15083@code{""" @var{seven-bit-iso-c-string-content} """}
15084
15085@item @var{nl} @expansion{}
15086@code{CR | CR-LF}
15087@end table
15088
15089@noindent
15090Notes:
15091
15092@itemize @bullet
15093@item
15094The CLI commands are still handled by the @sc{mi} interpreter; their
15095output is described below.
15096
15097@item
15098The @code{@var{token}}, when present, is passed back when the command
15099finishes.
15100
15101@item
15102Some @sc{mi} commands accept optional arguments as part of the parameter
15103list. Each option is identified by a leading @samp{-} (dash) and may be
15104followed by an optional argument parameter. Options occur first in the
15105parameter list and can be delimited from normal parameters using
15106@samp{--} (this is useful when some parameters begin with a dash).
15107@end itemize
15108
15109Pragmatics:
15110
15111@itemize @bullet
15112@item
15113We want easy access to the existing CLI syntax (for debugging).
15114
15115@item
15116We want it to be easy to spot a @sc{mi} operation.
15117@end itemize
15118
15119@node GDB/MI Output Syntax
15120@subsection @sc{gdb/mi} Output Syntax
15121
15122@cindex output syntax of @sc{gdb/mi}
15123@cindex @sc{gdb/mi}, output syntax
15124The output from @sc{gdb/mi} consists of zero or more out-of-band records
15125followed, optionally, by a single result record. This result record
15126is for the most recent command. The sequence of output records is
15127terminated by @samp{(@value{GDBP})}.
15128
15129If an input command was prefixed with a @code{@var{token}} then the
15130corresponding output for that command will also be prefixed by that same
15131@var{token}.
15132
15133@table @code
15134@item @var{output} @expansion{}
f7dc1244 15135@code{( @var{out-of-band-record} )* [ @var{result-record} ] "(@value{GDBP})" @var{nl}}
922fbb7b
AC
15136
15137@item @var{result-record} @expansion{}
15138@code{ [ @var{token} ] "^" @var{result-class} ( "," @var{result} )* @var{nl}}
15139
15140@item @var{out-of-band-record} @expansion{}
15141@code{@var{async-record} | @var{stream-record}}
15142
15143@item @var{async-record} @expansion{}
15144@code{@var{exec-async-output} | @var{status-async-output} | @var{notify-async-output}}
15145
15146@item @var{exec-async-output} @expansion{}
15147@code{[ @var{token} ] "*" @var{async-output}}
15148
15149@item @var{status-async-output} @expansion{}
15150@code{[ @var{token} ] "+" @var{async-output}}
15151
15152@item @var{notify-async-output} @expansion{}
15153@code{[ @var{token} ] "=" @var{async-output}}
15154
15155@item @var{async-output} @expansion{}
15156@code{@var{async-class} ( "," @var{result} )* @var{nl}}
15157
15158@item @var{result-class} @expansion{}
15159@code{"done" | "running" | "connected" | "error" | "exit"}
15160
15161@item @var{async-class} @expansion{}
15162@code{"stopped" | @var{others}} (where @var{others} will be added
15163depending on the needs---this is still in development).
15164
15165@item @var{result} @expansion{}
15166@code{ @var{variable} "=" @var{value}}
15167
15168@item @var{variable} @expansion{}
15169@code{ @var{string} }
15170
15171@item @var{value} @expansion{}
15172@code{ @var{const} | @var{tuple} | @var{list} }
15173
15174@item @var{const} @expansion{}
15175@code{@var{c-string}}
15176
15177@item @var{tuple} @expansion{}
15178@code{ "@{@}" | "@{" @var{result} ( "," @var{result} )* "@}" }
15179
15180@item @var{list} @expansion{}
15181@code{ "[]" | "[" @var{value} ( "," @var{value} )* "]" | "["
15182@var{result} ( "," @var{result} )* "]" }
15183
15184@item @var{stream-record} @expansion{}
15185@code{@var{console-stream-output} | @var{target-stream-output} | @var{log-stream-output}}
15186
15187@item @var{console-stream-output} @expansion{}
15188@code{"~" @var{c-string}}
15189
15190@item @var{target-stream-output} @expansion{}
15191@code{"@@" @var{c-string}}
15192
15193@item @var{log-stream-output} @expansion{}
15194@code{"&" @var{c-string}}
15195
15196@item @var{nl} @expansion{}
15197@code{CR | CR-LF}
15198
15199@item @var{token} @expansion{}
15200@emph{any sequence of digits}.
15201@end table
15202
15203@noindent
15204Notes:
15205
15206@itemize @bullet
15207@item
15208All output sequences end in a single line containing a period.
15209
15210@item
15211The @code{@var{token}} is from the corresponding request. If an execution
15212command is interrupted by the @samp{-exec-interrupt} command, the
15213@var{token} associated with the @samp{*stopped} message is the one of the
15214original execution command, not the one of the interrupt command.
15215
15216@item
15217@cindex status output in @sc{gdb/mi}
15218@var{status-async-output} contains on-going status information about the
15219progress of a slow operation. It can be discarded. All status output is
15220prefixed by @samp{+}.
15221
15222@item
15223@cindex async output in @sc{gdb/mi}
15224@var{exec-async-output} contains asynchronous state change on the target
15225(stopped, started, disappeared). All async output is prefixed by
15226@samp{*}.
15227
15228@item
15229@cindex notify output in @sc{gdb/mi}
15230@var{notify-async-output} contains supplementary information that the
15231client should handle (e.g., a new breakpoint information). All notify
15232output is prefixed by @samp{=}.
15233
15234@item
15235@cindex console output in @sc{gdb/mi}
15236@var{console-stream-output} is output that should be displayed as is in the
15237console. It is the textual response to a CLI command. All the console
15238output is prefixed by @samp{~}.
15239
15240@item
15241@cindex target output in @sc{gdb/mi}
15242@var{target-stream-output} is the output produced by the target program.
15243All the target output is prefixed by @samp{@@}.
15244
15245@item
15246@cindex log output in @sc{gdb/mi}
15247@var{log-stream-output} is output text coming from @value{GDBN}'s internals, for
15248instance messages that should be displayed as part of an error log. All
15249the log output is prefixed by @samp{&}.
15250
15251@item
15252@cindex list output in @sc{gdb/mi}
15253New @sc{gdb/mi} commands should only output @var{lists} containing
15254@var{values}.
15255
15256
15257@end itemize
15258
15259@xref{GDB/MI Stream Records, , @sc{gdb/mi} Stream Records}, for more
15260details about the various output records.
15261
15262@node GDB/MI Simple Examples
15263@subsection Simple Examples of @sc{gdb/mi} Interaction
15264@cindex @sc{gdb/mi}, simple examples
15265
15266This subsection presents several simple examples of interaction using
15267the @sc{gdb/mi} interface. In these examples, @samp{->} means that the
15268following line is passed to @sc{gdb/mi} as input, while @samp{<-} means
15269the output received from @sc{gdb/mi}.
15270
15271@subsubheading Target Stop
15272@c Ummm... There is no "-stop" command. This assumes async, no?
15273Here's an example of stopping the inferior process:
15274
15275@smallexample
15276-> -stop
15277<- (@value{GDBP})
15278@end smallexample
15279
15280@noindent
15281and later:
15282
15283@smallexample
15284<- *stop,reason="stop",address="0x123",source="a.c:123"
15285<- (@value{GDBP})
15286@end smallexample
15287
15288@subsubheading Simple CLI Command
15289
15290Here's an example of a simple CLI command being passed through
15291@sc{gdb/mi} and on to the CLI.
15292
15293@smallexample
15294-> print 1+2
15295<- &"print 1+2\n"
15296<- ~"$1 = 3\n"
15297<- ^done
15298<- (@value{GDBP})
15299@end smallexample
15300
15301@subsubheading Command With Side Effects
15302
15303@smallexample
15304-> -symbol-file xyz.exe
15305<- *breakpoint,nr="3",address="0x123",source="a.c:123"
15306<- (@value{GDBP})
15307@end smallexample
15308
15309@subsubheading A Bad Command
15310
15311Here's what happens if you pass a non-existent command:
15312
15313@smallexample
15314-> -rubbish
15315<- ^error,msg="Undefined MI command: rubbish"
15316<- (@value{GDBP})
15317@end smallexample
15318
15319@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
15320@node GDB/MI Compatibility with CLI
15321@section @sc{gdb/mi} Compatibility with CLI
15322
15323@cindex compatibility, @sc{gdb/mi} and CLI
15324@cindex @sc{gdb/mi}, compatibility with CLI
15325To help users familiar with @value{GDBN}'s existing CLI interface, @sc{gdb/mi}
15326accepts existing CLI commands. As specified by the syntax, such
15327commands can be directly entered into the @sc{gdb/mi} interface and @value{GDBN} will
15328respond.
15329
15330This mechanism is provided as an aid to developers of @sc{gdb/mi}
15331clients and not as a reliable interface into the CLI. Since the command
15332is being interpreteted in an environment that assumes @sc{gdb/mi}
15333behaviour, the exact output of such commands is likely to end up being
15334an un-supported hybrid of @sc{gdb/mi} and CLI output.
15335
15336@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
15337@node GDB/MI Output Records
15338@section @sc{gdb/mi} Output Records
15339
15340@menu
15341* GDB/MI Result Records::
15342* GDB/MI Stream Records::
15343* GDB/MI Out-of-band Records::
15344@end menu
15345
15346@node GDB/MI Result Records
15347@subsection @sc{gdb/mi} Result Records
15348
15349@cindex result records in @sc{gdb/mi}
15350@cindex @sc{gdb/mi}, result records
15351In addition to a number of out-of-band notifications, the response to a
15352@sc{gdb/mi} command includes one of the following result indications:
15353
15354@table @code
15355@findex ^done
15356@item "^done" [ "," @var{results} ]
15357The synchronous operation was successful, @code{@var{results}} are the return
15358values.
15359
15360@item "^running"
15361@findex ^running
15362@c Is this one correct? Should it be an out-of-band notification?
15363The asynchronous operation was successfully started. The target is
15364running.
15365
15366@item "^error" "," @var{c-string}
15367@findex ^error
15368The operation failed. The @code{@var{c-string}} contains the corresponding
15369error message.
15370@end table
15371
15372@node GDB/MI Stream Records
15373@subsection @sc{gdb/mi} Stream Records
15374
15375@cindex @sc{gdb/mi}, stream records
15376@cindex stream records in @sc{gdb/mi}
15377@value{GDBN} internally maintains a number of output streams: the console, the
15378target, and the log. The output intended for each of these streams is
15379funneled through the @sc{gdb/mi} interface using @dfn{stream records}.
15380
15381Each stream record begins with a unique @dfn{prefix character} which
15382identifies its stream (@pxref{GDB/MI Output Syntax, , @sc{gdb/mi} Output
15383Syntax}). In addition to the prefix, each stream record contains a
15384@code{@var{string-output}}. This is either raw text (with an implicit new
15385line) or a quoted C string (which does not contain an implicit newline).
15386
15387@table @code
15388@item "~" @var{string-output}
15389The console output stream contains text that should be displayed in the
15390CLI console window. It contains the textual responses to CLI commands.
15391
15392@item "@@" @var{string-output}
15393The target output stream contains any textual output from the running
15394target.
15395
15396@item "&" @var{string-output}
15397The log stream contains debugging messages being produced by @value{GDBN}'s
15398internals.
15399@end table
15400
15401@node GDB/MI Out-of-band Records
15402@subsection @sc{gdb/mi} Out-of-band Records
15403
15404@cindex out-of-band records in @sc{gdb/mi}
15405@cindex @sc{gdb/mi}, out-of-band records
15406@dfn{Out-of-band} records are used to notify the @sc{gdb/mi} client of
15407additional changes that have occurred. Those changes can either be a
15408consequence of @sc{gdb/mi} (e.g., a breakpoint modified) or a result of
15409target activity (e.g., target stopped).
15410
15411The following is a preliminary list of possible out-of-band records.
15412
15413@table @code
15414@item "*" "stop"
15415@end table
15416
15417
15418@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
15419@node GDB/MI Command Description Format
15420@section @sc{gdb/mi} Command Description Format
15421
15422The remaining sections describe blocks of commands. Each block of
15423commands is laid out in a fashion similar to this section.
15424
15425Note the the line breaks shown in the examples are here only for
15426readability. They don't appear in the real output.
15427Also note that the commands with a non-available example (N.A.@:) are
15428not yet implemented.
15429
15430@subheading Motivation
15431
15432The motivation for this collection of commands.
15433
15434@subheading Introduction
15435
15436A brief introduction to this collection of commands as a whole.
15437
15438@subheading Commands
15439
15440For each command in the block, the following is described:
15441
15442@subsubheading Synopsis
15443
15444@smallexample
15445 -command @var{args}@dots{}
15446@end smallexample
15447
15448@subsubheading @value{GDBN} Command
15449
15450The corresponding @value{GDBN} CLI command.
15451
15452@subsubheading Result
15453
15454@subsubheading Out-of-band
15455
15456@subsubheading Notes
15457
15458@subsubheading Example
15459
15460
15461@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
15462@node GDB/MI Breakpoint Table Commands
15463@section @sc{gdb/mi} Breakpoint table commands
15464
15465@cindex breakpoint commands for @sc{gdb/mi}
15466@cindex @sc{gdb/mi}, breakpoint commands
15467This section documents @sc{gdb/mi} commands for manipulating
15468breakpoints.
15469
15470@subheading The @code{-break-after} Command
15471@findex -break-after
15472
15473@subsubheading Synopsis
15474
15475@smallexample
15476 -break-after @var{number} @var{count}
15477@end smallexample
15478
15479The breakpoint number @var{number} is not in effect until it has been
15480hit @var{count} times. To see how this is reflected in the output of
15481the @samp{-break-list} command, see the description of the
15482@samp{-break-list} command below.
15483
15484@subsubheading @value{GDBN} Command
15485
15486The corresponding @value{GDBN} command is @samp{ignore}.
15487
15488@subsubheading Example
15489
15490@smallexample
15491(@value{GDBP})
15492-break-insert main
15493^done,bkpt=@{number="1",addr="0x000100d0",file="hello.c",line="5"@}
15494(@value{GDBP})
15495-break-after 1 3
15496~
15497^done
15498(@value{GDBP})
15499-break-list
15500^done,BreakpointTable=@{nr_rows="1",nr_cols="6",
15501hdr=[@{width="3",alignment="-1",col_name="number",colhdr="Num"@},
15502@{width="14",alignment="-1",col_name="type",colhdr="Type"@},
15503@{width="4",alignment="-1",col_name="disp",colhdr="Disp"@},
15504@{width="3",alignment="-1",col_name="enabled",colhdr="Enb"@},
15505@{width="10",alignment="-1",col_name="addr",colhdr="Address"@},
15506@{width="40",alignment="2",col_name="what",colhdr="What"@}],
15507body=[bkpt=@{number="1",type="breakpoint",disp="keep",enabled="y",
15508addr="0x000100d0",func="main",file="hello.c",line="5",times="0",
15509ignore="3"@}]@}
15510(@value{GDBP})
15511@end smallexample
15512
15513@ignore
15514@subheading The @code{-break-catch} Command
15515@findex -break-catch
15516
15517@subheading The @code{-break-commands} Command
15518@findex -break-commands
15519@end ignore
15520
15521
15522@subheading The @code{-break-condition} Command
15523@findex -break-condition
15524
15525@subsubheading Synopsis
15526
15527@smallexample
15528 -break-condition @var{number} @var{expr}
15529@end smallexample
15530
15531Breakpoint @var{number} will stop the program only if the condition in
15532@var{expr} is true. The condition becomes part of the
15533@samp{-break-list} output (see the description of the @samp{-break-list}
15534command below).
15535
15536@subsubheading @value{GDBN} Command
15537
15538The corresponding @value{GDBN} command is @samp{condition}.
15539
15540@subsubheading Example
15541
15542@smallexample
15543(@value{GDBP})
15544-break-condition 1 1
15545^done
15546(@value{GDBP})
15547-break-list
15548^done,BreakpointTable=@{nr_rows="1",nr_cols="6",
15549hdr=[@{width="3",alignment="-1",col_name="number",colhdr="Num"@},
15550@{width="14",alignment="-1",col_name="type",colhdr="Type"@},
15551@{width="4",alignment="-1",col_name="disp",colhdr="Disp"@},
15552@{width="3",alignment="-1",col_name="enabled",colhdr="Enb"@},
15553@{width="10",alignment="-1",col_name="addr",colhdr="Address"@},
15554@{width="40",alignment="2",col_name="what",colhdr="What"@}],
15555body=[bkpt=@{number="1",type="breakpoint",disp="keep",enabled="y",
15556addr="0x000100d0",func="main",file="hello.c",line="5",cond="1",
15557times="0",ignore="3"@}]@}
15558(@value{GDBP})
15559@end smallexample
15560
15561@subheading The @code{-break-delete} Command
15562@findex -break-delete
15563
15564@subsubheading Synopsis
15565
15566@smallexample
15567 -break-delete ( @var{breakpoint} )+
15568@end smallexample
15569
15570Delete the breakpoint(s) whose number(s) are specified in the argument
15571list. This is obviously reflected in the breakpoint list.
15572
15573@subsubheading @value{GDBN} command
15574
15575The corresponding @value{GDBN} command is @samp{delete}.
15576
15577@subsubheading Example
15578
15579@smallexample
15580(@value{GDBP})
15581-break-delete 1
15582^done
15583(@value{GDBP})
15584-break-list
15585^done,BreakpointTable=@{nr_rows="0",nr_cols="6",
15586hdr=[@{width="3",alignment="-1",col_name="number",colhdr="Num"@},
15587@{width="14",alignment="-1",col_name="type",colhdr="Type"@},
15588@{width="4",alignment="-1",col_name="disp",colhdr="Disp"@},
15589@{width="3",alignment="-1",col_name="enabled",colhdr="Enb"@},
15590@{width="10",alignment="-1",col_name="addr",colhdr="Address"@},
15591@{width="40",alignment="2",col_name="what",colhdr="What"@}],
15592body=[]@}
15593(@value{GDBP})
15594@end smallexample
15595
15596@subheading The @code{-break-disable} Command
15597@findex -break-disable
15598
15599@subsubheading Synopsis
15600
15601@smallexample
15602 -break-disable ( @var{breakpoint} )+
15603@end smallexample
15604
15605Disable the named @var{breakpoint}(s). The field @samp{enabled} in the
15606break list is now set to @samp{n} for the named @var{breakpoint}(s).
15607
15608@subsubheading @value{GDBN} Command
15609
15610The corresponding @value{GDBN} command is @samp{disable}.
15611
15612@subsubheading Example
15613
15614@smallexample
15615(@value{GDBP})
15616-break-disable 2
15617^done
15618(@value{GDBP})
15619-break-list
15620^done,BreakpointTable=@{nr_rows="1",nr_cols="6",
15621hdr=[@{width="3",alignment="-1",col_name="number",colhdr="Num"@},
15622@{width="14",alignment="-1",col_name="type",colhdr="Type"@},
15623@{width="4",alignment="-1",col_name="disp",colhdr="Disp"@},
15624@{width="3",alignment="-1",col_name="enabled",colhdr="Enb"@},
15625@{width="10",alignment="-1",col_name="addr",colhdr="Address"@},
15626@{width="40",alignment="2",col_name="what",colhdr="What"@}],
15627body=[bkpt=@{number="2",type="breakpoint",disp="keep",enabled="n",
15628addr="0x000100d0",func="main",file="hello.c",line="5",times="0"@}]@}
15629(@value{GDBP})
15630@end smallexample
15631
15632@subheading The @code{-break-enable} Command
15633@findex -break-enable
15634
15635@subsubheading Synopsis
15636
15637@smallexample
15638 -break-enable ( @var{breakpoint} )+
15639@end smallexample
15640
15641Enable (previously disabled) @var{breakpoint}(s).
15642
15643@subsubheading @value{GDBN} Command
15644
15645The corresponding @value{GDBN} command is @samp{enable}.
15646
15647@subsubheading Example
15648
15649@smallexample
15650(@value{GDBP})
15651-break-enable 2
15652^done
15653(@value{GDBP})
15654-break-list
15655^done,BreakpointTable=@{nr_rows="1",nr_cols="6",
15656hdr=[@{width="3",alignment="-1",col_name="number",colhdr="Num"@},
15657@{width="14",alignment="-1",col_name="type",colhdr="Type"@},
15658@{width="4",alignment="-1",col_name="disp",colhdr="Disp"@},
15659@{width="3",alignment="-1",col_name="enabled",colhdr="Enb"@},
15660@{width="10",alignment="-1",col_name="addr",colhdr="Address"@},
15661@{width="40",alignment="2",col_name="what",colhdr="What"@}],
15662body=[bkpt=@{number="2",type="breakpoint",disp="keep",enabled="y",
15663addr="0x000100d0",func="main",file="hello.c",line="5",times="0"@}]@}
15664(@value{GDBP})
15665@end smallexample
15666
15667@subheading The @code{-break-info} Command
15668@findex -break-info
15669
15670@subsubheading Synopsis
15671
15672@smallexample
15673 -break-info @var{breakpoint}
15674@end smallexample
15675
15676@c REDUNDANT???
15677Get information about a single breakpoint.
15678
15679@subsubheading @value{GDBN} command
15680
15681The corresponding @value{GDBN} command is @samp{info break @var{breakpoint}}.
15682
15683@subsubheading Example
15684N.A.
15685
15686@subheading The @code{-break-insert} Command
15687@findex -break-insert
15688
15689@subsubheading Synopsis
15690
15691@smallexample
15692 -break-insert [ -t ] [ -h ] [ -r ]
15693 [ -c @var{condition} ] [ -i @var{ignore-count} ]
15694 [ -p @var{thread} ] [ @var{line} | @var{addr} ]
15695@end smallexample
15696
15697@noindent
15698If specified, @var{line}, can be one of:
15699
15700@itemize @bullet
15701@item function
15702@c @item +offset
15703@c @item -offset
15704@c @item linenum
15705@item filename:linenum
15706@item filename:function
15707@item *address
15708@end itemize
15709
15710The possible optional parameters of this command are:
15711
15712@table @samp
15713@item -t
15714Insert a tempoary breakpoint.
15715@item -h
15716Insert a hardware breakpoint.
15717@item -c @var{condition}
15718Make the breakpoint conditional on @var{condition}.
15719@item -i @var{ignore-count}
15720Initialize the @var{ignore-count}.
15721@item -r
15722Insert a regular breakpoint in all the functions whose names match the
15723given regular expression. Other flags are not applicable to regular
15724expresson.
15725@end table
15726
15727@subsubheading Result
15728
15729The result is in the form:
15730
15731@smallexample
15732 ^done,bkptno="@var{number}",func="@var{funcname}",
15733 file="@var{filename}",line="@var{lineno}"
15734@end smallexample
15735
15736@noindent
15737where @var{number} is the @value{GDBN} number for this breakpoint, @var{funcname}
15738is the name of the function where the breakpoint was inserted,
15739@var{filename} is the name of the source file which contains this
15740function, and @var{lineno} is the source line number within that file.
15741
15742Note: this format is open to change.
15743@c An out-of-band breakpoint instead of part of the result?
15744
15745@subsubheading @value{GDBN} Command
15746
15747The corresponding @value{GDBN} commands are @samp{break}, @samp{tbreak},
15748@samp{hbreak}, @samp{thbreak}, and @samp{rbreak}.
15749
15750@subsubheading Example
15751
15752@smallexample
15753(@value{GDBP})
15754-break-insert main
15755^done,bkpt=@{number="1",addr="0x0001072c",file="recursive2.c",line="4"@}
15756(@value{GDBP})
15757-break-insert -t foo
15758^done,bkpt=@{number="2",addr="0x00010774",file="recursive2.c",line="11"@}
15759(@value{GDBP})
15760-break-list
15761^done,BreakpointTable=@{nr_rows="2",nr_cols="6",
15762hdr=[@{width="3",alignment="-1",col_name="number",colhdr="Num"@},
15763@{width="14",alignment="-1",col_name="type",colhdr="Type"@},
15764@{width="4",alignment="-1",col_name="disp",colhdr="Disp"@},
15765@{width="3",alignment="-1",col_name="enabled",colhdr="Enb"@},
15766@{width="10",alignment="-1",col_name="addr",colhdr="Address"@},
15767@{width="40",alignment="2",col_name="what",colhdr="What"@}],
15768body=[bkpt=@{number="1",type="breakpoint",disp="keep",enabled="y",
15769addr="0x0001072c", func="main",file="recursive2.c",line="4",times="0"@},
15770bkpt=@{number="2",type="breakpoint",disp="del",enabled="y",
15771addr="0x00010774",func="foo",file="recursive2.c",line="11",times="0"@}]@}
15772(@value{GDBP})
15773-break-insert -r foo.*
15774~int foo(int, int);
15775^done,bkpt=@{number="3",addr="0x00010774",file="recursive2.c",line="11"@}
15776(@value{GDBP})
15777@end smallexample
15778
15779@subheading The @code{-break-list} Command
15780@findex -break-list
15781
15782@subsubheading Synopsis
15783
15784@smallexample
15785 -break-list
15786@end smallexample
15787
15788Displays the list of inserted breakpoints, showing the following fields:
15789
15790@table @samp
15791@item Number
15792number of the breakpoint
15793@item Type
15794type of the breakpoint: @samp{breakpoint} or @samp{watchpoint}
15795@item Disposition
15796should the breakpoint be deleted or disabled when it is hit: @samp{keep}
15797or @samp{nokeep}
15798@item Enabled
15799is the breakpoint enabled or no: @samp{y} or @samp{n}
15800@item Address
15801memory location at which the breakpoint is set
15802@item What
15803logical location of the breakpoint, expressed by function name, file
15804name, line number
15805@item Times
15806number of times the breakpoint has been hit
15807@end table
15808
15809If there are no breakpoints or watchpoints, the @code{BreakpointTable}
15810@code{body} field is an empty list.
15811
15812@subsubheading @value{GDBN} Command
15813
15814The corresponding @value{GDBN} command is @samp{info break}.
15815
15816@subsubheading Example
15817
15818@smallexample
15819(@value{GDBP})
15820-break-list
15821^done,BreakpointTable=@{nr_rows="2",nr_cols="6",
15822hdr=[@{width="3",alignment="-1",col_name="number",colhdr="Num"@},
15823@{width="14",alignment="-1",col_name="type",colhdr="Type"@},
15824@{width="4",alignment="-1",col_name="disp",colhdr="Disp"@},
15825@{width="3",alignment="-1",col_name="enabled",colhdr="Enb"@},
15826@{width="10",alignment="-1",col_name="addr",colhdr="Address"@},
15827@{width="40",alignment="2",col_name="what",colhdr="What"@}],
15828body=[bkpt=@{number="1",type="breakpoint",disp="keep",enabled="y",
15829addr="0x000100d0",func="main",file="hello.c",line="5",times="0"@},
15830bkpt=@{number="2",type="breakpoint",disp="keep",enabled="y",
15831addr="0x00010114",func="foo",file="hello.c",line="13",times="0"@}]@}
15832(@value{GDBP})
15833@end smallexample
15834
15835Here's an example of the result when there are no breakpoints:
15836
15837@smallexample
15838(@value{GDBP})
15839-break-list
15840^done,BreakpointTable=@{nr_rows="0",nr_cols="6",
15841hdr=[@{width="3",alignment="-1",col_name="number",colhdr="Num"@},
15842@{width="14",alignment="-1",col_name="type",colhdr="Type"@},
15843@{width="4",alignment="-1",col_name="disp",colhdr="Disp"@},
15844@{width="3",alignment="-1",col_name="enabled",colhdr="Enb"@},
15845@{width="10",alignment="-1",col_name="addr",colhdr="Address"@},
15846@{width="40",alignment="2",col_name="what",colhdr="What"@}],
15847body=[]@}
15848(@value{GDBP})
15849@end smallexample
15850
15851@subheading The @code{-break-watch} Command
15852@findex -break-watch
15853
15854@subsubheading Synopsis
15855
15856@smallexample
15857 -break-watch [ -a | -r ]
15858@end smallexample
15859
15860Create a watchpoint. With the @samp{-a} option it will create an
15861@dfn{access} watchpoint, i.e. a watchpoint that triggers either on a
15862read from or on a write to the memory location. With the @samp{-r}
15863option, the watchpoint created is a @dfn{read} watchpoint, i.e. it will
15864trigger only when the memory location is accessed for reading. Without
15865either of the options, the watchpoint created is a regular watchpoint,
15866i.e. it will trigger when the memory location is accessed for writing.
15867@xref{Set Watchpoints, , Setting watchpoints}.
15868
15869Note that @samp{-break-list} will report a single list of watchpoints and
15870breakpoints inserted.
15871
15872@subsubheading @value{GDBN} Command
15873
15874The corresponding @value{GDBN} commands are @samp{watch}, @samp{awatch}, and
15875@samp{rwatch}.
15876
15877@subsubheading Example
15878
15879Setting a watchpoint on a variable in the @code{main} function:
15880
15881@smallexample
15882(@value{GDBP})
15883-break-watch x
15884^done,wpt=@{number="2",exp="x"@}
15885(@value{GDBP})
15886-exec-continue
15887^running
15888^done,reason="watchpoint-trigger",wpt=@{number="2",exp="x"@},
15889value=@{old="-268439212",new="55"@},
15890frame=@{func="main",args=[],file="recursive2.c",line="5"@}
15891(@value{GDBP})
15892@end smallexample
15893
15894Setting a watchpoint on a variable local to a function. @value{GDBN} will stop
15895the program execution twice: first for the variable changing value, then
15896for the watchpoint going out of scope.
15897
15898@smallexample
15899(@value{GDBP})
15900-break-watch C
15901^done,wpt=@{number="5",exp="C"@}
15902(@value{GDBP})
15903-exec-continue
15904^running
15905^done,reason="watchpoint-trigger",
15906wpt=@{number="5",exp="C"@},value=@{old="-276895068",new="3"@},
15907frame=@{func="callee4",args=[],
15908file="../../../devo/gdb/testsuite/gdb.mi/basics.c",line="13"@}
15909(@value{GDBP})
15910-exec-continue
15911^running
15912^done,reason="watchpoint-scope",wpnum="5",
15913frame=@{func="callee3",args=[@{name="strarg",
15914value="0x11940 \"A string argument.\""@}],
15915file="../../../devo/gdb/testsuite/gdb.mi/basics.c",line="18"@}
15916(@value{GDBP})
15917@end smallexample
15918
15919Listing breakpoints and watchpoints, at different points in the program
15920execution. Note that once the watchpoint goes out of scope, it is
15921deleted.
15922
15923@smallexample
15924(@value{GDBP})
15925-break-watch C
15926^done,wpt=@{number="2",exp="C"@}
15927(@value{GDBP})
15928-break-list
15929^done,BreakpointTable=@{nr_rows="2",nr_cols="6",
15930hdr=[@{width="3",alignment="-1",col_name="number",colhdr="Num"@},
15931@{width="14",alignment="-1",col_name="type",colhdr="Type"@},
15932@{width="4",alignment="-1",col_name="disp",colhdr="Disp"@},
15933@{width="3",alignment="-1",col_name="enabled",colhdr="Enb"@},
15934@{width="10",alignment="-1",col_name="addr",colhdr="Address"@},
15935@{width="40",alignment="2",col_name="what",colhdr="What"@}],
15936body=[bkpt=@{number="1",type="breakpoint",disp="keep",enabled="y",
15937addr="0x00010734",func="callee4",
15938file="../../../devo/gdb/testsuite/gdb.mi/basics.c",line="8",times="1"@},
15939bkpt=@{number="2",type="watchpoint",disp="keep",
15940enabled="y",addr="",what="C",times="0"@}]@}
15941(@value{GDBP})
15942-exec-continue
15943^running
15944^done,reason="watchpoint-trigger",wpt=@{number="2",exp="C"@},
15945value=@{old="-276895068",new="3"@},
15946frame=@{func="callee4",args=[],
15947file="../../../devo/gdb/testsuite/gdb.mi/basics.c",line="13"@}
15948(@value{GDBP})
15949-break-list
15950^done,BreakpointTable=@{nr_rows="2",nr_cols="6",
15951hdr=[@{width="3",alignment="-1",col_name="number",colhdr="Num"@},
15952@{width="14",alignment="-1",col_name="type",colhdr="Type"@},
15953@{width="4",alignment="-1",col_name="disp",colhdr="Disp"@},
15954@{width="3",alignment="-1",col_name="enabled",colhdr="Enb"@},
15955@{width="10",alignment="-1",col_name="addr",colhdr="Address"@},
15956@{width="40",alignment="2",col_name="what",colhdr="What"@}],
15957body=[bkpt=@{number="1",type="breakpoint",disp="keep",enabled="y",
15958addr="0x00010734",func="callee4",
15959file="../../../devo/gdb/testsuite/gdb.mi/basics.c",line="8",times="1"@},
15960bkpt=@{number="2",type="watchpoint",disp="keep",
15961enabled="y",addr="",what="C",times="-5"@}]@}
15962(@value{GDBP})
15963-exec-continue
15964^running
15965^done,reason="watchpoint-scope",wpnum="2",
15966frame=@{func="callee3",args=[@{name="strarg",
15967value="0x11940 \"A string argument.\""@}],
15968file="../../../devo/gdb/testsuite/gdb.mi/basics.c",line="18"@}
15969(@value{GDBP})
15970-break-list
15971^done,BreakpointTable=@{nr_rows="1",nr_cols="6",
15972hdr=[@{width="3",alignment="-1",col_name="number",colhdr="Num"@},
15973@{width="14",alignment="-1",col_name="type",colhdr="Type"@},
15974@{width="4",alignment="-1",col_name="disp",colhdr="Disp"@},
15975@{width="3",alignment="-1",col_name="enabled",colhdr="Enb"@},
15976@{width="10",alignment="-1",col_name="addr",colhdr="Address"@},
15977@{width="40",alignment="2",col_name="what",colhdr="What"@}],
15978body=[bkpt=@{number="1",type="breakpoint",disp="keep",enabled="y",
15979addr="0x00010734",func="callee4",
15980file="../../../devo/gdb/testsuite/gdb.mi/basics.c",line="8",times="1"@}]@}
15981(@value{GDBP})
15982@end smallexample
15983
15984@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
15985@node GDB/MI Data Manipulation
15986@section @sc{gdb/mi} Data Manipulation
15987
15988@cindex data manipulation, in @sc{gdb/mi}
15989@cindex @sc{gdb/mi}, data manipulation
15990This section describes the @sc{gdb/mi} commands that manipulate data:
15991examine memory and registers, evaluate expressions, etc.
15992
15993@c REMOVED FROM THE INTERFACE.
15994@c @subheading -data-assign
15995@c Change the value of a program variable. Plenty of side effects.
15996@c @subsubheading GDB command
15997@c set variable
15998@c @subsubheading Example
15999@c N.A.
16000
16001@subheading The @code{-data-disassemble} Command
16002@findex -data-disassemble
16003
16004@subsubheading Synopsis
16005
16006@smallexample
16007 -data-disassemble
16008 [ -s @var{start-addr} -e @var{end-addr} ]
16009 | [ -f @var{filename} -l @var{linenum} [ -n @var{lines} ] ]
16010 -- @var{mode}
16011@end smallexample
16012
16013@noindent
16014Where:
16015
16016@table @samp
16017@item @var{start-addr}
16018is the beginning address (or @code{$pc})
16019@item @var{end-addr}
16020is the end address
16021@item @var{filename}
16022is the name of the file to disassemble
16023@item @var{linenum}
16024is the line number to disassemble around
16025@item @var{lines}
16026is the the number of disassembly lines to be produced. If it is -1,
16027the whole function will be disassembled, in case no @var{end-addr} is
16028specified. If @var{end-addr} is specified as a non-zero value, and
16029@var{lines} is lower than the number of disassembly lines between
16030@var{start-addr} and @var{end-addr}, only @var{lines} lines are
16031displayed; if @var{lines} is higher than the number of lines between
16032@var{start-addr} and @var{end-addr}, only the lines up to @var{end-addr}
16033are displayed.
16034@item @var{mode}
16035is either 0 (meaning only disassembly) or 1 (meaning mixed source and
16036disassembly).
16037@end table
16038
16039@subsubheading Result
16040
16041The output for each instruction is composed of four fields:
16042
16043@itemize @bullet
16044@item Address
16045@item Func-name
16046@item Offset
16047@item Instruction
16048@end itemize
16049
16050Note that whatever included in the instruction field, is not manipulated
16051directely by @sc{gdb/mi}, i.e. it is not possible to adjust its format.
16052
16053@subsubheading @value{GDBN} Command
16054
16055There's no direct mapping from this command to the CLI.
16056
16057@subsubheading Example
16058
16059Disassemble from the current value of @code{$pc} to @code{$pc + 20}:
16060
16061@smallexample
16062(@value{GDBP})
16063-data-disassemble -s $pc -e "$pc + 20" -- 0
16064^done,
16065asm_insns=[
16066@{address="0x000107c0",func-name="main",offset="4",
16067inst="mov 2, %o0"@},
16068@{address="0x000107c4",func-name="main",offset="8",
16069inst="sethi %hi(0x11800), %o2"@},
16070@{address="0x000107c8",func-name="main",offset="12",
16071inst="or %o2, 0x140, %o1\t! 0x11940 <_lib_version+8>"@},
16072@{address="0x000107cc",func-name="main",offset="16",
16073inst="sethi %hi(0x11800), %o2"@},
16074@{address="0x000107d0",func-name="main",offset="20",
16075inst="or %o2, 0x168, %o4\t! 0x11968 <_lib_version+48>"@}]
16076(@value{GDBP})
16077@end smallexample
16078
16079Disassemble the whole @code{main} function. Line 32 is part of
16080@code{main}.
16081
16082@smallexample
16083-data-disassemble -f basics.c -l 32 -- 0
16084^done,asm_insns=[
16085@{address="0x000107bc",func-name="main",offset="0",
16086inst="save %sp, -112, %sp"@},
16087@{address="0x000107c0",func-name="main",offset="4",
16088inst="mov 2, %o0"@},
16089@{address="0x000107c4",func-name="main",offset="8",
16090inst="sethi %hi(0x11800), %o2"@},
16091[@dots{}]
16092@{address="0x0001081c",func-name="main",offset="96",inst="ret "@},
16093@{address="0x00010820",func-name="main",offset="100",inst="restore "@}]
16094(@value{GDBP})
16095@end smallexample
16096
16097Disassemble 3 instructions from the start of @code{main}:
16098
16099@smallexample
16100(@value{GDBP})
16101-data-disassemble -f basics.c -l 32 -n 3 -- 0
16102^done,asm_insns=[
16103@{address="0x000107bc",func-name="main",offset="0",
16104inst="save %sp, -112, %sp"@},
16105@{address="0x000107c0",func-name="main",offset="4",
16106inst="mov 2, %o0"@},
16107@{address="0x000107c4",func-name="main",offset="8",
16108inst="sethi %hi(0x11800), %o2"@}]
16109(@value{GDBP})
16110@end smallexample
16111
16112Disassemble 3 instructions from the start of @code{main} in mixed mode:
16113
16114@smallexample
16115(@value{GDBP})
16116-data-disassemble -f basics.c -l 32 -n 3 -- 1
16117^done,asm_insns=[
16118src_and_asm_line=@{line="31",
16119file="/kwikemart/marge/ezannoni/flathead-dev/devo/gdb/ \
16120 testsuite/gdb.mi/basics.c",line_asm_insn=[
16121@{address="0x000107bc",func-name="main",offset="0",
16122inst="save %sp, -112, %sp"@}]@},
16123src_and_asm_line=@{line="32",
16124file="/kwikemart/marge/ezannoni/flathead-dev/devo/gdb/ \
16125 testsuite/gdb.mi/basics.c",line_asm_insn=[
16126@{address="0x000107c0",func-name="main",offset="4",
16127inst="mov 2, %o0"@},
16128@{address="0x000107c4",func-name="main",offset="8",
16129inst="sethi %hi(0x11800), %o2"@}]@}]
16130(@value{GDBP})
16131@end smallexample
16132
16133
16134@subheading The @code{-data-evaluate-expression} Command
16135@findex -data-evaluate-expression
16136
16137@subsubheading Synopsis
16138
16139@smallexample
16140 -data-evaluate-expression @var{expr}
16141@end smallexample
16142
16143Evaluate @var{expr} as an expression. The expression could contain an
16144inferior function call. The function call will execute synchronously.
16145If the expression contains spaces, it must be enclosed in double quotes.
16146
16147@subsubheading @value{GDBN} Command
16148
16149The corresponding @value{GDBN} commands are @samp{print}, @samp{output}, and
16150@samp{call}. In @code{gdbtk} only, there's a corresponding
16151@samp{gdb_eval} command.
16152
16153@subsubheading Example
16154
16155In the following example, the numbers that precede the commands are the
16156@dfn{tokens} described in @ref{GDB/MI Command Syntax, ,@sc{gdb/mi}
16157Command Syntax}. Notice how @sc{gdb/mi} returns the same tokens in its
16158output.
16159
16160@smallexample
16161211-data-evaluate-expression A
16162211^done,value="1"
16163(@value{GDBP})
16164311-data-evaluate-expression &A
16165311^done,value="0xefffeb7c"
16166(@value{GDBP})
16167411-data-evaluate-expression A+3
16168411^done,value="4"
16169(@value{GDBP})
16170511-data-evaluate-expression "A + 3"
16171511^done,value="4"
16172(@value{GDBP})
16173@end smallexample
16174
16175
16176@subheading The @code{-data-list-changed-registers} Command
16177@findex -data-list-changed-registers
16178
16179@subsubheading Synopsis
16180
16181@smallexample
16182 -data-list-changed-registers
16183@end smallexample
16184
16185Display a list of the registers that have changed.
16186
16187@subsubheading @value{GDBN} Command
16188
16189@value{GDBN} doesn't have a direct analog for this command; @code{gdbtk}
16190has the corresponding command @samp{gdb_changed_register_list}.
16191
16192@subsubheading Example
16193
16194On a PPC MBX board:
16195
16196@smallexample
16197(@value{GDBP})
16198-exec-continue
16199^running
16200
16201(@value{GDBP})
16202*stopped,reason="breakpoint-hit",bkptno="1",frame=@{func="main",
16203args=[],file="try.c",line="5"@}
16204(@value{GDBP})
16205-data-list-changed-registers
16206^done,changed-registers=["0","1","2","4","5","6","7","8","9",
16207"10","11","13","14","15","16","17","18","19","20","21","22","23",
16208"24","25","26","27","28","30","31","64","65","66","67","69"]
16209(@value{GDBP})
16210@end smallexample
16211
16212
16213@subheading The @code{-data-list-register-names} Command
16214@findex -data-list-register-names
16215
16216@subsubheading Synopsis
16217
16218@smallexample
16219 -data-list-register-names [ ( @var{regno} )+ ]
16220@end smallexample
16221
16222Show a list of register names for the current target. If no arguments
16223are given, it shows a list of the names of all the registers. If
16224integer numbers are given as arguments, it will print a list of the
16225names of the registers corresponding to the arguments. To ensure
16226consistency between a register name and its number, the output list may
16227include empty register names.
16228
16229@subsubheading @value{GDBN} Command
16230
16231@value{GDBN} does not have a command which corresponds to
16232@samp{-data-list-register-names}. In @code{gdbtk} there is a
16233corresponding command @samp{gdb_regnames}.
16234
16235@subsubheading Example
16236
16237For the PPC MBX board:
16238@smallexample
16239(@value{GDBP})
16240-data-list-register-names
16241^done,register-names=["r0","r1","r2","r3","r4","r5","r6","r7",
16242"r8","r9","r10","r11","r12","r13","r14","r15","r16","r17","r18",
16243"r19","r20","r21","r22","r23","r24","r25","r26","r27","r28","r29",
16244"r30","r31","f0","f1","f2","f3","f4","f5","f6","f7","f8","f9",
16245"f10","f11","f12","f13","f14","f15","f16","f17","f18","f19","f20",
16246"f21","f22","f23","f24","f25","f26","f27","f28","f29","f30","f31",
16247"", "pc","ps","cr","lr","ctr","xer"]
16248(@value{GDBP})
16249-data-list-register-names 1 2 3
16250^done,register-names=["r1","r2","r3"]
16251(@value{GDBP})
16252@end smallexample
16253
16254@subheading The @code{-data-list-register-values} Command
16255@findex -data-list-register-values
16256
16257@subsubheading Synopsis
16258
16259@smallexample
16260 -data-list-register-values @var{fmt} [ ( @var{regno} )*]
16261@end smallexample
16262
16263Display the registers' contents. @var{fmt} is the format according to
16264which the registers' contents are to be returned, followed by an optional
16265list of numbers specifying the registers to display. A missing list of
16266numbers indicates that the contents of all the registers must be returned.
16267
16268Allowed formats for @var{fmt} are:
16269
16270@table @code
16271@item x
16272Hexadecimal
16273@item o
16274Octal
16275@item t
16276Binary
16277@item d
16278Decimal
16279@item r
16280Raw
16281@item N
16282Natural
16283@end table
16284
16285@subsubheading @value{GDBN} Command
16286
16287The corresponding @value{GDBN} commands are @samp{info reg}, @samp{info
16288all-reg}, and (in @code{gdbtk}) @samp{gdb_fetch_registers}.
16289
16290@subsubheading Example
16291
16292For a PPC MBX board (note: line breaks are for readability only, they
16293don't appear in the actual output):
16294
16295@smallexample
16296(@value{GDBP})
16297-data-list-register-values r 64 65
16298^done,register-values=[@{number="64",value="0xfe00a300"@},
16299@{number="65",value="0x00029002"@}]
16300(@value{GDBP})
16301-data-list-register-values x
16302^done,register-values=[@{number="0",value="0xfe0043c8"@},
16303@{number="1",value="0x3fff88"@},@{number="2",value="0xfffffffe"@},
16304@{number="3",value="0x0"@},@{number="4",value="0xa"@},
16305@{number="5",value="0x3fff68"@},@{number="6",value="0x3fff58"@},
16306@{number="7",value="0xfe011e98"@},@{number="8",value="0x2"@},
16307@{number="9",value="0xfa202820"@},@{number="10",value="0xfa202808"@},
16308@{number="11",value="0x1"@},@{number="12",value="0x0"@},
16309@{number="13",value="0x4544"@},@{number="14",value="0xffdfffff"@},
16310@{number="15",value="0xffffffff"@},@{number="16",value="0xfffffeff"@},
16311@{number="17",value="0xefffffed"@},@{number="18",value="0xfffffffe"@},
16312@{number="19",value="0xffffffff"@},@{number="20",value="0xffffffff"@},
16313@{number="21",value="0xffffffff"@},@{number="22",value="0xfffffff7"@},
16314@{number="23",value="0xffffffff"@},@{number="24",value="0xffffffff"@},
16315@{number="25",value="0xffffffff"@},@{number="26",value="0xfffffffb"@},
16316@{number="27",value="0xffffffff"@},@{number="28",value="0xf7bfffff"@},
16317@{number="29",value="0x0"@},@{number="30",value="0xfe010000"@},
16318@{number="31",value="0x0"@},@{number="32",value="0x0"@},
16319@{number="33",value="0x0"@},@{number="34",value="0x0"@},
16320@{number="35",value="0x0"@},@{number="36",value="0x0"@},
16321@{number="37",value="0x0"@},@{number="38",value="0x0"@},
16322@{number="39",value="0x0"@},@{number="40",value="0x0"@},
16323@{number="41",value="0x0"@},@{number="42",value="0x0"@},
16324@{number="43",value="0x0"@},@{number="44",value="0x0"@},
16325@{number="45",value="0x0"@},@{number="46",value="0x0"@},
16326@{number="47",value="0x0"@},@{number="48",value="0x0"@},
16327@{number="49",value="0x0"@},@{number="50",value="0x0"@},
16328@{number="51",value="0x0"@},@{number="52",value="0x0"@},
16329@{number="53",value="0x0"@},@{number="54",value="0x0"@},
16330@{number="55",value="0x0"@},@{number="56",value="0x0"@},
16331@{number="57",value="0x0"@},@{number="58",value="0x0"@},
16332@{number="59",value="0x0"@},@{number="60",value="0x0"@},
16333@{number="61",value="0x0"@},@{number="62",value="0x0"@},
16334@{number="63",value="0x0"@},@{number="64",value="0xfe00a300"@},
16335@{number="65",value="0x29002"@},@{number="66",value="0x202f04b5"@},
16336@{number="67",value="0xfe0043b0"@},@{number="68",value="0xfe00b3e4"@},
16337@{number="69",value="0x20002b03"@}]
16338(@value{GDBP})
16339@end smallexample
16340
16341
16342@subheading The @code{-data-read-memory} Command
16343@findex -data-read-memory
16344
16345@subsubheading Synopsis
16346
16347@smallexample
16348 -data-read-memory [ -o @var{byte-offset} ]
16349 @var{address} @var{word-format} @var{word-size}
16350 @var{nr-rows} @var{nr-cols} [ @var{aschar} ]
16351@end smallexample
16352
16353@noindent
16354where:
16355
16356@table @samp
16357@item @var{address}
16358An expression specifying the address of the first memory word to be
16359read. Complex expressions containing embedded white space should be
16360quoted using the C convention.
16361
16362@item @var{word-format}
16363The format to be used to print the memory words. The notation is the
16364same as for @value{GDBN}'s @code{print} command (@pxref{Output Formats,
16365,Output formats}).
16366
16367@item @var{word-size}
16368The size of each memory word in bytes.
16369
16370@item @var{nr-rows}
16371The number of rows in the output table.
16372
16373@item @var{nr-cols}
16374The number of columns in the output table.
16375
16376@item @var{aschar}
16377If present, indicates that each row should include an @sc{ascii} dump. The
16378value of @var{aschar} is used as a padding character when a byte is not a
16379member of the printable @sc{ascii} character set (printable @sc{ascii}
16380characters are those whose code is between 32 and 126, inclusively).
16381
16382@item @var{byte-offset}
16383An offset to add to the @var{address} before fetching memory.
16384@end table
16385
16386This command displays memory contents as a table of @var{nr-rows} by
16387@var{nr-cols} words, each word being @var{word-size} bytes. In total,
16388@code{@var{nr-rows} * @var{nr-cols} * @var{word-size}} bytes are read
16389(returned as @samp{total-bytes}). Should less than the requested number
16390of bytes be returned by the target, the missing words are identified
16391using @samp{N/A}. The number of bytes read from the target is returned
16392in @samp{nr-bytes} and the starting address used to read memory in
16393@samp{addr}.
16394
16395The address of the next/previous row or page is available in
16396@samp{next-row} and @samp{prev-row}, @samp{next-page} and
16397@samp{prev-page}.
16398
16399@subsubheading @value{GDBN} Command
16400
16401The corresponding @value{GDBN} command is @samp{x}. @code{gdbtk} has
16402@samp{gdb_get_mem} memory read command.
16403
16404@subsubheading Example
16405
16406Read six bytes of memory starting at @code{bytes+6} but then offset by
16407@code{-6} bytes. Format as three rows of two columns. One byte per
16408word. Display each word in hex.
16409
16410@smallexample
16411(@value{GDBP})
164129-data-read-memory -o -6 -- bytes+6 x 1 3 2
164139^done,addr="0x00001390",nr-bytes="6",total-bytes="6",
16414next-row="0x00001396",prev-row="0x0000138e",next-page="0x00001396",
16415prev-page="0x0000138a",memory=[
16416@{addr="0x00001390",data=["0x00","0x01"]@},
16417@{addr="0x00001392",data=["0x02","0x03"]@},
16418@{addr="0x00001394",data=["0x04","0x05"]@}]
16419(@value{GDBP})
16420@end smallexample
16421
16422Read two bytes of memory starting at address @code{shorts + 64} and
16423display as a single word formatted in decimal.
16424
16425@smallexample
16426(@value{GDBP})
164275-data-read-memory shorts+64 d 2 1 1
164285^done,addr="0x00001510",nr-bytes="2",total-bytes="2",
16429next-row="0x00001512",prev-row="0x0000150e",
16430next-page="0x00001512",prev-page="0x0000150e",memory=[
16431@{addr="0x00001510",data=["128"]@}]
16432(@value{GDBP})
16433@end smallexample
16434
16435Read thirty two bytes of memory starting at @code{bytes+16} and format
16436as eight rows of four columns. Include a string encoding with @samp{x}
16437used as the non-printable character.
16438
16439@smallexample
16440(@value{GDBP})
164414-data-read-memory bytes+16 x 1 8 4 x
164424^done,addr="0x000013a0",nr-bytes="32",total-bytes="32",
16443next-row="0x000013c0",prev-row="0x0000139c",
16444next-page="0x000013c0",prev-page="0x00001380",memory=[
16445@{addr="0x000013a0",data=["0x10","0x11","0x12","0x13"],ascii="xxxx"@},
16446@{addr="0x000013a4",data=["0x14","0x15","0x16","0x17"],ascii="xxxx"@},
16447@{addr="0x000013a8",data=["0x18","0x19","0x1a","0x1b"],ascii="xxxx"@},
16448@{addr="0x000013ac",data=["0x1c","0x1d","0x1e","0x1f"],ascii="xxxx"@},
16449@{addr="0x000013b0",data=["0x20","0x21","0x22","0x23"],ascii=" !\"#"@},
16450@{addr="0x000013b4",data=["0x24","0x25","0x26","0x27"],ascii="$%&'"@},
16451@{addr="0x000013b8",data=["0x28","0x29","0x2a","0x2b"],ascii="()*+"@},
16452@{addr="0x000013bc",data=["0x2c","0x2d","0x2e","0x2f"],ascii=",-./"@}]
16453(@value{GDBP})
16454@end smallexample
16455
16456@subheading The @code{-display-delete} Command
16457@findex -display-delete
16458
16459@subsubheading Synopsis
16460
16461@smallexample
16462 -display-delete @var{number}
16463@end smallexample
16464
16465Delete the display @var{number}.
16466
16467@subsubheading @value{GDBN} Command
16468
16469The corresponding @value{GDBN} command is @samp{delete display}.
16470
16471@subsubheading Example
16472N.A.
16473
16474
16475@subheading The @code{-display-disable} Command
16476@findex -display-disable
16477
16478@subsubheading Synopsis
16479
16480@smallexample
16481 -display-disable @var{number}
16482@end smallexample
16483
16484Disable display @var{number}.
16485
16486@subsubheading @value{GDBN} Command
16487
16488The corresponding @value{GDBN} command is @samp{disable display}.
16489
16490@subsubheading Example
16491N.A.
16492
16493
16494@subheading The @code{-display-enable} Command
16495@findex -display-enable
16496
16497@subsubheading Synopsis
16498
16499@smallexample
16500 -display-enable @var{number}
16501@end smallexample
16502
16503Enable display @var{number}.
16504
16505@subsubheading @value{GDBN} Command
16506
16507The corresponding @value{GDBN} command is @samp{enable display}.
16508
16509@subsubheading Example
16510N.A.
16511
16512
16513@subheading The @code{-display-insert} Command
16514@findex -display-insert
16515
16516@subsubheading Synopsis
16517
16518@smallexample
16519 -display-insert @var{expression}
16520@end smallexample
16521
16522Display @var{expression} every time the program stops.
16523
16524@subsubheading @value{GDBN} Command
16525
16526The corresponding @value{GDBN} command is @samp{display}.
16527
16528@subsubheading Example
16529N.A.
16530
16531
16532@subheading The @code{-display-list} Command
16533@findex -display-list
16534
16535@subsubheading Synopsis
16536
16537@smallexample
16538 -display-list
16539@end smallexample
16540
16541List the displays. Do not show the current values.
16542
16543@subsubheading @value{GDBN} Command
16544
16545The corresponding @value{GDBN} command is @samp{info display}.
16546
16547@subsubheading Example
16548N.A.
16549
16550
16551@subheading The @code{-environment-cd} Command
16552@findex -environment-cd
16553
16554@subsubheading Synopsis
16555
16556@smallexample
16557 -environment-cd @var{pathdir}
16558@end smallexample
16559
16560Set @value{GDBN}'s working directory.
16561
16562@subsubheading @value{GDBN} Command
16563
16564The corresponding @value{GDBN} command is @samp{cd}.
16565
16566@subsubheading Example
16567
16568@smallexample
16569(@value{GDBP})
16570-environment-cd /kwikemart/marge/ezannoni/flathead-dev/devo/gdb
16571^done
16572(@value{GDBP})
16573@end smallexample
16574
16575
16576@subheading The @code{-environment-directory} Command
16577@findex -environment-directory
16578
16579@subsubheading Synopsis
16580
16581@smallexample
16582 -environment-directory [ -r ] [ @var{pathdir} ]+
16583@end smallexample
16584
16585Add directories @var{pathdir} to beginning of search path for source files.
16586If the @samp{-r} option is used, the search path is reset to the default
b383017d 16587search path. If directories @var{pathdir} are supplied in addition to the
922fbb7b
AC
16588@samp{-r} option, the search path is first reset and then addition
16589occurs as normal.
b383017d 16590Multiple directories may be specified, separated by blanks. Specifying
922fbb7b
AC
16591multiple directories in a single command
16592results in the directories added to the beginning of the
16593search path in the same order they were presented in the command.
16594If blanks are needed as
16595part of a directory name, double-quotes should be used around
16596the name. In the command output, the path will show up separated
b383017d 16597by the system directory-separator character. The directory-seperator
922fbb7b
AC
16598character must not be used
16599in any directory name.
16600If no directories are specified, the current search path is displayed.
16601
16602@subsubheading @value{GDBN} Command
16603
16604The corresponding @value{GDBN} command is @samp{dir}.
16605
16606@subsubheading Example
16607
16608@smallexample
16609(@value{GDBP})
16610-environment-directory /kwikemart/marge/ezannoni/flathead-dev/devo/gdb
16611^done,source-path="/kwikemart/marge/ezannoni/flathead-dev/devo/gdb:$cdir:$cwd"
16612(@value{GDBP})
16613-environment-directory ""
16614^done,source-path="/kwikemart/marge/ezannoni/flathead-dev/devo/gdb:$cdir:$cwd"
16615(@value{GDBP})
16616-environment-directory -r /home/jjohnstn/src/gdb /usr/src
16617^done,source-path="/home/jjohnstn/src/gdb:/usr/src:$cdir:$cwd"
16618(@value{GDBP})
16619-environment-directory -r
16620^done,source-path="$cdir:$cwd"
16621(@value{GDBP})
16622@end smallexample
16623
16624
16625@subheading The @code{-environment-path} Command
16626@findex -environment-path
16627
16628@subsubheading Synopsis
16629
16630@smallexample
16631 -environment-path [ -r ] [ @var{pathdir} ]+
16632@end smallexample
16633
16634Add directories @var{pathdir} to beginning of search path for object files.
16635If the @samp{-r} option is used, the search path is reset to the original
b383017d
RM
16636search path that existed at gdb start-up. If directories @var{pathdir} are
16637supplied in addition to the
922fbb7b
AC
16638@samp{-r} option, the search path is first reset and then addition
16639occurs as normal.
b383017d 16640Multiple directories may be specified, separated by blanks. Specifying
922fbb7b
AC
16641multiple directories in a single command
16642results in the directories added to the beginning of the
16643search path in the same order they were presented in the command.
16644If blanks are needed as
16645part of a directory name, double-quotes should be used around
16646the name. In the command output, the path will show up separated
b383017d 16647by the system directory-separator character. The directory-seperator
922fbb7b
AC
16648character must not be used
16649in any directory name.
16650If no directories are specified, the current path is displayed.
16651
16652
16653@subsubheading @value{GDBN} Command
16654
16655The corresponding @value{GDBN} command is @samp{path}.
16656
16657@subsubheading Example
16658
16659@smallexample
16660(@value{GDBP})
b383017d 16661-environment-path
922fbb7b
AC
16662^done,path="/usr/bin"
16663(@value{GDBP})
16664-environment-path /kwikemart/marge/ezannoni/flathead-dev/ppc-eabi/gdb /bin
16665^done,path="/kwikemart/marge/ezannoni/flathead-dev/ppc-eabi/gdb:/bin:/usr/bin"
16666(@value{GDBP})
16667-environment-path -r /usr/local/bin
16668^done,path="/usr/local/bin:/usr/bin"
16669(@value{GDBP})
16670@end smallexample
16671
16672
16673@subheading The @code{-environment-pwd} Command
16674@findex -environment-pwd
16675
16676@subsubheading Synopsis
16677
16678@smallexample
16679 -environment-pwd
16680@end smallexample
16681
16682Show the current working directory.
16683
16684@subsubheading @value{GDBN} command
16685
16686The corresponding @value{GDBN} command is @samp{pwd}.
16687
16688@subsubheading Example
16689
16690@smallexample
16691(@value{GDBP})
16692-environment-pwd
16693^done,cwd="/kwikemart/marge/ezannoni/flathead-dev/devo/gdb"
16694(@value{GDBP})
16695@end smallexample
16696
16697@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
16698@node GDB/MI Program Control
16699@section @sc{gdb/mi} Program control
16700
16701@subsubheading Program termination
16702
16703As a result of execution, the inferior program can run to completion, if
16704it doesn't encounter any breakpoints. In this case the output will
16705include an exit code, if the program has exited exceptionally.
16706
16707@subsubheading Examples
16708
16709@noindent
16710Program exited normally:
16711
16712@smallexample
16713(@value{GDBP})
16714-exec-run
16715^running
16716(@value{GDBP})
16717x = 55
16718*stopped,reason="exited-normally"
16719(@value{GDBP})
16720@end smallexample
16721
16722@noindent
16723Program exited exceptionally:
16724
16725@smallexample
16726(@value{GDBP})
16727-exec-run
16728^running
16729(@value{GDBP})
16730x = 55
16731*stopped,reason="exited",exit-code="01"
16732(@value{GDBP})
16733@end smallexample
16734
16735Another way the program can terminate is if it receives a signal such as
16736@code{SIGINT}. In this case, @sc{gdb/mi} displays this:
16737
16738@smallexample
16739(@value{GDBP})
16740*stopped,reason="exited-signalled",signal-name="SIGINT",
16741signal-meaning="Interrupt"
16742@end smallexample
16743
16744
16745@subheading The @code{-exec-abort} Command
16746@findex -exec-abort
16747
16748@subsubheading Synopsis
16749
16750@smallexample
16751 -exec-abort
16752@end smallexample
16753
16754Kill the inferior running program.
16755
16756@subsubheading @value{GDBN} Command
16757
16758The corresponding @value{GDBN} command is @samp{kill}.
16759
16760@subsubheading Example
16761N.A.
16762
16763
16764@subheading The @code{-exec-arguments} Command
16765@findex -exec-arguments
16766
16767@subsubheading Synopsis
16768
16769@smallexample
16770 -exec-arguments @var{args}
16771@end smallexample
16772
16773Set the inferior program arguments, to be used in the next
16774@samp{-exec-run}.
16775
16776@subsubheading @value{GDBN} Command
16777
16778The corresponding @value{GDBN} command is @samp{set args}.
16779
16780@subsubheading Example
16781
16782@c FIXME!
16783Don't have one around.
16784
16785
16786@subheading The @code{-exec-continue} Command
16787@findex -exec-continue
16788
16789@subsubheading Synopsis
16790
16791@smallexample
16792 -exec-continue
16793@end smallexample
16794
16795Asynchronous command. Resumes the execution of the inferior program
16796until a breakpoint is encountered, or until the inferior exits.
16797
16798@subsubheading @value{GDBN} Command
16799
16800The corresponding @value{GDBN} corresponding is @samp{continue}.
16801
16802@subsubheading Example
16803
16804@smallexample
16805-exec-continue
16806^running
16807(@value{GDBP})
16808@@Hello world
16809*stopped,reason="breakpoint-hit",bkptno="2",frame=@{func="foo",args=[],
16810file="hello.c",line="13"@}
16811(@value{GDBP})
16812@end smallexample
16813
16814
16815@subheading The @code{-exec-finish} Command
16816@findex -exec-finish
16817
16818@subsubheading Synopsis
16819
16820@smallexample
16821 -exec-finish
16822@end smallexample
16823
16824Asynchronous command. Resumes the execution of the inferior program
16825until the current function is exited. Displays the results returned by
16826the function.
16827
16828@subsubheading @value{GDBN} Command
16829
16830The corresponding @value{GDBN} command is @samp{finish}.
16831
16832@subsubheading Example
16833
16834Function returning @code{void}.
16835
16836@smallexample
16837-exec-finish
16838^running
16839(@value{GDBP})
16840@@hello from foo
16841*stopped,reason="function-finished",frame=@{func="main",args=[],
16842file="hello.c",line="7"@}
16843(@value{GDBP})
16844@end smallexample
16845
16846Function returning other than @code{void}. The name of the internal
16847@value{GDBN} variable storing the result is printed, together with the
16848value itself.
16849
16850@smallexample
16851-exec-finish
16852^running
16853(@value{GDBP})
16854*stopped,reason="function-finished",frame=@{addr="0x000107b0",func="foo",
16855args=[@{name="a",value="1"],@{name="b",value="9"@}@},
16856file="recursive2.c",line="14"@},
16857gdb-result-var="$1",return-value="0"
16858(@value{GDBP})
16859@end smallexample
16860
16861
16862@subheading The @code{-exec-interrupt} Command
16863@findex -exec-interrupt
16864
16865@subsubheading Synopsis
16866
16867@smallexample
16868 -exec-interrupt
16869@end smallexample
16870
16871Asynchronous command. Interrupts the background execution of the target.
16872Note how the token associated with the stop message is the one for the
16873execution command that has been interrupted. The token for the interrupt
16874itself only appears in the @samp{^done} output. If the user is trying to
16875interrupt a non-running program, an error message will be printed.
16876
16877@subsubheading @value{GDBN} Command
16878
16879The corresponding @value{GDBN} command is @samp{interrupt}.
16880
16881@subsubheading Example
16882
16883@smallexample
16884(@value{GDBP})
16885111-exec-continue
16886111^running
16887
16888(@value{GDBP})
16889222-exec-interrupt
16890222^done
16891(@value{GDBP})
16892111*stopped,signal-name="SIGINT",signal-meaning="Interrupt",
16893frame=@{addr="0x00010140",func="foo",args=[],file="try.c",line="13"@}
16894(@value{GDBP})
16895
16896(@value{GDBP})
16897-exec-interrupt
16898^error,msg="mi_cmd_exec_interrupt: Inferior not executing."
16899(@value{GDBP})
16900@end smallexample
16901
16902
16903@subheading The @code{-exec-next} Command
16904@findex -exec-next
16905
16906@subsubheading Synopsis
16907
16908@smallexample
16909 -exec-next
16910@end smallexample
16911
16912Asynchronous command. Resumes execution of the inferior program, stopping
16913when the beginning of the next source line is reached.
16914
16915@subsubheading @value{GDBN} Command
16916
16917The corresponding @value{GDBN} command is @samp{next}.
16918
16919@subsubheading Example
16920
16921@smallexample
16922-exec-next
16923^running
16924(@value{GDBP})
16925*stopped,reason="end-stepping-range",line="8",file="hello.c"
16926(@value{GDBP})
16927@end smallexample
16928
16929
16930@subheading The @code{-exec-next-instruction} Command
16931@findex -exec-next-instruction
16932
16933@subsubheading Synopsis
16934
16935@smallexample
16936 -exec-next-instruction
16937@end smallexample
16938
16939Asynchronous command. Executes one machine instruction. If the
16940instruction is a function call continues until the function returns. If
16941the program stops at an instruction in the middle of a source line, the
16942address will be printed as well.
16943
16944@subsubheading @value{GDBN} Command
16945
16946The corresponding @value{GDBN} command is @samp{nexti}.
16947
16948@subsubheading Example
16949
16950@smallexample
16951(@value{GDBP})
16952-exec-next-instruction
16953^running
16954
16955(@value{GDBP})
16956*stopped,reason="end-stepping-range",
16957addr="0x000100d4",line="5",file="hello.c"
16958(@value{GDBP})
16959@end smallexample
16960
16961
16962@subheading The @code{-exec-return} Command
16963@findex -exec-return
16964
16965@subsubheading Synopsis
16966
16967@smallexample
16968 -exec-return
16969@end smallexample
16970
16971Makes current function return immediately. Doesn't execute the inferior.
16972Displays the new current frame.
16973
16974@subsubheading @value{GDBN} Command
16975
16976The corresponding @value{GDBN} command is @samp{return}.
16977
16978@subsubheading Example
16979
16980@smallexample
16981(@value{GDBP})
16982200-break-insert callee4
16983200^done,bkpt=@{number="1",addr="0x00010734",
16984file="../../../devo/gdb/testsuite/gdb.mi/basics.c",line="8"@}
16985(@value{GDBP})
16986000-exec-run
16987000^running
16988(@value{GDBP})
16989000*stopped,reason="breakpoint-hit",bkptno="1",
16990frame=@{func="callee4",args=[],
16991file="../../../devo/gdb/testsuite/gdb.mi/basics.c",line="8"@}
16992(@value{GDBP})
16993205-break-delete
16994205^done
16995(@value{GDBP})
16996111-exec-return
16997111^done,frame=@{level="0",func="callee3",
16998args=[@{name="strarg",
16999value="0x11940 \"A string argument.\""@}],
17000file="../../../devo/gdb/testsuite/gdb.mi/basics.c",line="18"@}
17001(@value{GDBP})
17002@end smallexample
17003
17004
17005@subheading The @code{-exec-run} Command
17006@findex -exec-run
17007
17008@subsubheading Synopsis
17009
17010@smallexample
17011 -exec-run
17012@end smallexample
17013
17014Asynchronous command. Starts execution of the inferior from the
17015beginning. The inferior executes until either a breakpoint is
17016encountered or the program exits.
17017
17018@subsubheading @value{GDBN} Command
17019
17020The corresponding @value{GDBN} command is @samp{run}.
17021
17022@subsubheading Example
17023
17024@smallexample
17025(@value{GDBP})
17026-break-insert main
17027^done,bkpt=@{number="1",addr="0x0001072c",file="recursive2.c",line="4"@}
17028(@value{GDBP})
17029-exec-run
17030^running
17031(@value{GDBP})
17032*stopped,reason="breakpoint-hit",bkptno="1",
17033frame=@{func="main",args=[],file="recursive2.c",line="4"@}
17034(@value{GDBP})
17035@end smallexample
17036
17037
17038@subheading The @code{-exec-show-arguments} Command
17039@findex -exec-show-arguments
17040
17041@subsubheading Synopsis
17042
17043@smallexample
17044 -exec-show-arguments
17045@end smallexample
17046
17047Print the arguments of the program.
17048
17049@subsubheading @value{GDBN} Command
17050
17051The corresponding @value{GDBN} command is @samp{show args}.
17052
17053@subsubheading Example
17054N.A.
17055
17056@c @subheading -exec-signal
17057
17058@subheading The @code{-exec-step} Command
17059@findex -exec-step
17060
17061@subsubheading Synopsis
17062
17063@smallexample
17064 -exec-step
17065@end smallexample
17066
17067Asynchronous command. Resumes execution of the inferior program, stopping
17068when the beginning of the next source line is reached, if the next
17069source line is not a function call. If it is, stop at the first
17070instruction of the called function.
17071
17072@subsubheading @value{GDBN} Command
17073
17074The corresponding @value{GDBN} command is @samp{step}.
17075
17076@subsubheading Example
17077
17078Stepping into a function:
17079
17080@smallexample
17081-exec-step
17082^running
17083(@value{GDBP})
17084*stopped,reason="end-stepping-range",
17085frame=@{func="foo",args=[@{name="a",value="10"@},
17086@{name="b",value="0"@}],file="recursive2.c",line="11"@}
17087(@value{GDBP})
17088@end smallexample
17089
17090Regular stepping:
17091
17092@smallexample
17093-exec-step
17094^running
17095(@value{GDBP})
17096*stopped,reason="end-stepping-range",line="14",file="recursive2.c"
17097(@value{GDBP})
17098@end smallexample
17099
17100
17101@subheading The @code{-exec-step-instruction} Command
17102@findex -exec-step-instruction
17103
17104@subsubheading Synopsis
17105
17106@smallexample
17107 -exec-step-instruction
17108@end smallexample
17109
17110Asynchronous command. Resumes the inferior which executes one machine
17111instruction. The output, once @value{GDBN} has stopped, will vary depending on
17112whether we have stopped in the middle of a source line or not. In the
17113former case, the address at which the program stopped will be printed as
17114well.
17115
17116@subsubheading @value{GDBN} Command
17117
17118The corresponding @value{GDBN} command is @samp{stepi}.
17119
17120@subsubheading Example
17121
17122@smallexample
17123(@value{GDBP})
17124-exec-step-instruction
17125^running
17126
17127(@value{GDBP})
17128*stopped,reason="end-stepping-range",
17129frame=@{func="foo",args=[],file="try.c",line="10"@}
17130(@value{GDBP})
17131-exec-step-instruction
17132^running
17133
17134(@value{GDBP})
17135*stopped,reason="end-stepping-range",
17136frame=@{addr="0x000100f4",func="foo",args=[],file="try.c",line="10"@}
17137(@value{GDBP})
17138@end smallexample
17139
17140
17141@subheading The @code{-exec-until} Command
17142@findex -exec-until
17143
17144@subsubheading Synopsis
17145
17146@smallexample
17147 -exec-until [ @var{location} ]
17148@end smallexample
17149
17150Asynchronous command. Executes the inferior until the @var{location}
17151specified in the argument is reached. If there is no argument, the inferior
17152executes until a source line greater than the current one is reached.
17153The reason for stopping in this case will be @samp{location-reached}.
17154
17155@subsubheading @value{GDBN} Command
17156
17157The corresponding @value{GDBN} command is @samp{until}.
17158
17159@subsubheading Example
17160
17161@smallexample
17162(@value{GDBP})
17163-exec-until recursive2.c:6
17164^running
17165(@value{GDBP})
17166x = 55
17167*stopped,reason="location-reached",frame=@{func="main",args=[],
17168file="recursive2.c",line="6"@}
17169(@value{GDBP})
17170@end smallexample
17171
17172@ignore
17173@subheading -file-clear
17174Is this going away????
17175@end ignore
17176
17177
17178@subheading The @code{-file-exec-and-symbols} Command
17179@findex -file-exec-and-symbols
17180
17181@subsubheading Synopsis
17182
17183@smallexample
17184 -file-exec-and-symbols @var{file}
17185@end smallexample
17186
17187Specify the executable file to be debugged. This file is the one from
17188which the symbol table is also read. If no file is specified, the
17189command clears the executable and symbol information. If breakpoints
17190are set when using this command with no arguments, @value{GDBN} will produce
17191error messages. Otherwise, no output is produced, except a completion
17192notification.
17193
17194@subsubheading @value{GDBN} Command
17195
17196The corresponding @value{GDBN} command is @samp{file}.
17197
17198@subsubheading Example
17199
17200@smallexample
17201(@value{GDBP})
17202-file-exec-and-symbols /kwikemart/marge/ezannoni/TRUNK/mbx/hello.mbx
17203^done
17204(@value{GDBP})
17205@end smallexample
17206
17207
17208@subheading The @code{-file-exec-file} Command
17209@findex -file-exec-file
17210
17211@subsubheading Synopsis
17212
17213@smallexample
17214 -file-exec-file @var{file}
17215@end smallexample
17216
17217Specify the executable file to be debugged. Unlike
17218@samp{-file-exec-and-symbols}, the symbol table is @emph{not} read
17219from this file. If used without argument, @value{GDBN} clears the information
17220about the executable file. No output is produced, except a completion
17221notification.
17222
17223@subsubheading @value{GDBN} Command
17224
17225The corresponding @value{GDBN} command is @samp{exec-file}.
17226
17227@subsubheading Example
17228
17229@smallexample
17230(@value{GDBP})
17231-file-exec-file /kwikemart/marge/ezannoni/TRUNK/mbx/hello.mbx
17232^done
17233(@value{GDBP})
17234@end smallexample
17235
17236
17237@subheading The @code{-file-list-exec-sections} Command
17238@findex -file-list-exec-sections
17239
17240@subsubheading Synopsis
17241
17242@smallexample
17243 -file-list-exec-sections
17244@end smallexample
17245
17246List the sections of the current executable file.
17247
17248@subsubheading @value{GDBN} Command
17249
17250The @value{GDBN} command @samp{info file} shows, among the rest, the same
17251information as this command. @code{gdbtk} has a corresponding command
17252@samp{gdb_load_info}.
17253
17254@subsubheading Example
17255N.A.
17256
17257
1abaf70c
BR
17258@subheading The @code{-file-list-exec-source-file} Command
17259@findex -file-list-exec-source-file
17260
17261@subsubheading Synopsis
17262
17263@smallexample
17264 -file-list-exec-source-file
17265@end smallexample
17266
b383017d 17267List the line number, the current source file, and the absolute path
1abaf70c
BR
17268to the current source file for the current executable.
17269
17270@subsubheading @value{GDBN} Command
17271
17272There's no @value{GDBN} command which directly corresponds to this one.
17273
17274@subsubheading Example
17275
17276@smallexample
17277(@value{GDBP})
17278123-file-list-exec-source-file
17279123^done,line="1",file="foo.c",fullname="/home/bar/foo.c"
17280(@value{GDBP})
17281@end smallexample
17282
17283
922fbb7b
AC
17284@subheading The @code{-file-list-exec-source-files} Command
17285@findex -file-list-exec-source-files
17286
17287@subsubheading Synopsis
17288
17289@smallexample
17290 -file-list-exec-source-files
17291@end smallexample
17292
17293List the source files for the current executable.
17294
57c22c6c
BR
17295It will always output the filename, but only when GDB can find the absolute
17296file name of a source file, will it output the fullname.
17297
922fbb7b
AC
17298@subsubheading @value{GDBN} Command
17299
17300There's no @value{GDBN} command which directly corresponds to this one.
17301@code{gdbtk} has an analogous command @samp{gdb_listfiles}.
17302
17303@subsubheading Example
57c22c6c
BR
17304@smallexample
17305(@value{GDBP})
17306-file-list-exec-source-files
17307^done,files=[
17308@{file=foo.c,fullname=/home/foo.c@},
17309@{file=/home/bar.c,fullname=/home/bar.c@},
17310@{file=gdb_could_not_find_fullpath.c@}]
17311(@value{GDBP})
17312@end smallexample
922fbb7b
AC
17313
17314@subheading The @code{-file-list-shared-libraries} Command
17315@findex -file-list-shared-libraries
17316
17317@subsubheading Synopsis
17318
17319@smallexample
17320 -file-list-shared-libraries
17321@end smallexample
17322
17323List the shared libraries in the program.
17324
17325@subsubheading @value{GDBN} Command
17326
17327The corresponding @value{GDBN} command is @samp{info shared}.
17328
17329@subsubheading Example
17330N.A.
17331
17332
17333@subheading The @code{-file-list-symbol-files} Command
17334@findex -file-list-symbol-files
17335
17336@subsubheading Synopsis
17337
17338@smallexample
17339 -file-list-symbol-files
17340@end smallexample
17341
17342List symbol files.
17343
17344@subsubheading @value{GDBN} Command
17345
17346The corresponding @value{GDBN} command is @samp{info file} (part of it).
17347
17348@subsubheading Example
17349N.A.
17350
17351
17352@subheading The @code{-file-symbol-file} Command
17353@findex -file-symbol-file
17354
17355@subsubheading Synopsis
17356
17357@smallexample
17358 -file-symbol-file @var{file}
17359@end smallexample
17360
17361Read symbol table info from the specified @var{file} argument. When
17362used without arguments, clears @value{GDBN}'s symbol table info. No output is
17363produced, except for a completion notification.
17364
17365@subsubheading @value{GDBN} Command
17366
17367The corresponding @value{GDBN} command is @samp{symbol-file}.
17368
17369@subsubheading Example
17370
17371@smallexample
17372(@value{GDBP})
17373-file-symbol-file /kwikemart/marge/ezannoni/TRUNK/mbx/hello.mbx
17374^done
17375(@value{GDBP})
17376@end smallexample
17377
17378@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
17379@node GDB/MI Miscellaneous Commands
17380@section Miscellaneous @value{GDBN} commands in @sc{gdb/mi}
17381
17382@c @subheading -gdb-complete
17383
17384@subheading The @code{-gdb-exit} Command
17385@findex -gdb-exit
17386
17387@subsubheading Synopsis
17388
17389@smallexample
17390 -gdb-exit
17391@end smallexample
17392
17393Exit @value{GDBN} immediately.
17394
17395@subsubheading @value{GDBN} Command
17396
17397Approximately corresponds to @samp{quit}.
17398
17399@subsubheading Example
17400
17401@smallexample
17402(@value{GDBP})
17403-gdb-exit
17404@end smallexample
17405
17406@subheading The @code{-gdb-set} Command
17407@findex -gdb-set
17408
17409@subsubheading Synopsis
17410
17411@smallexample
17412 -gdb-set
17413@end smallexample
17414
17415Set an internal @value{GDBN} variable.
17416@c IS THIS A DOLLAR VARIABLE? OR SOMETHING LIKE ANNOTATE ?????
17417
17418@subsubheading @value{GDBN} Command
17419
17420The corresponding @value{GDBN} command is @samp{set}.
17421
17422@subsubheading Example
17423
17424@smallexample
17425(@value{GDBP})
17426-gdb-set $foo=3
17427^done
17428(@value{GDBP})
17429@end smallexample
17430
17431
17432@subheading The @code{-gdb-show} Command
17433@findex -gdb-show
17434
17435@subsubheading Synopsis
17436
17437@smallexample
17438 -gdb-show
17439@end smallexample
17440
17441Show the current value of a @value{GDBN} variable.
17442
17443@subsubheading @value{GDBN} command
17444
17445The corresponding @value{GDBN} command is @samp{show}.
17446
17447@subsubheading Example
17448
17449@smallexample
17450(@value{GDBP})
17451-gdb-show annotate
17452^done,value="0"
17453(@value{GDBP})
17454@end smallexample
17455
17456@c @subheading -gdb-source
17457
17458
17459@subheading The @code{-gdb-version} Command
17460@findex -gdb-version
17461
17462@subsubheading Synopsis
17463
17464@smallexample
17465 -gdb-version
17466@end smallexample
17467
17468Show version information for @value{GDBN}. Used mostly in testing.
17469
17470@subsubheading @value{GDBN} Command
17471
17472There's no equivalent @value{GDBN} command. @value{GDBN} by default shows this
17473information when you start an interactive session.
17474
17475@subsubheading Example
17476
17477@c This example modifies the actual output from GDB to avoid overfull
17478@c box in TeX.
17479@smallexample
17480(@value{GDBP})
17481-gdb-version
17482~GNU gdb 5.2.1
17483~Copyright 2000 Free Software Foundation, Inc.
17484~GDB is free software, covered by the GNU General Public License, and
17485~you are welcome to change it and/or distribute copies of it under
17486~ certain conditions.
17487~Type "show copying" to see the conditions.
17488~There is absolutely no warranty for GDB. Type "show warranty" for
17489~ details.
b383017d 17490~This GDB was configured as
922fbb7b
AC
17491 "--host=sparc-sun-solaris2.5.1 --target=ppc-eabi".
17492^done
17493(@value{GDBP})
17494@end smallexample
17495
17496@subheading The @code{-interpreter-exec} Command
17497@findex -interpreter-exec
17498
17499@subheading Synopsis
17500
17501@smallexample
17502-interpreter-exec @var{interpreter} @var{command}
17503@end smallexample
17504
17505Execute the specified @var{command} in the given @var{interpreter}.
17506
17507@subheading @value{GDBN} Command
17508
17509The corresponding @value{GDBN} command is @samp{interpreter-exec}.
17510
17511@subheading Example
17512
17513@smallexample
17514(@value{GDBP})
17515-interpreter-exec console "break main"
17516&"During symbol reading, couldn't parse type; debugger out of date?.\n"
17517&"During symbol reading, bad structure-type format.\n"
17518~"Breakpoint 1 at 0x8074fc6: file ../../src/gdb/main.c, line 743.\n"
17519^done
17520(@value{GDBP})
17521@end smallexample
17522
17523@ignore
17524@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
17525@node GDB/MI Kod Commands
17526@section @sc{gdb/mi} Kod Commands
17527
17528The Kod commands are not implemented.
17529
17530@c @subheading -kod-info
17531
17532@c @subheading -kod-list
17533
17534@c @subheading -kod-list-object-types
17535
17536@c @subheading -kod-show
17537
17538@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
17539@node GDB/MI Memory Overlay Commands
17540@section @sc{gdb/mi} Memory Overlay Commands
17541
17542The memory overlay commands are not implemented.
17543
17544@c @subheading -overlay-auto
17545
17546@c @subheading -overlay-list-mapping-state
17547
17548@c @subheading -overlay-list-overlays
17549
17550@c @subheading -overlay-map
17551
17552@c @subheading -overlay-off
17553
17554@c @subheading -overlay-on
17555
17556@c @subheading -overlay-unmap
17557
17558@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
17559@node GDB/MI Signal Handling Commands
17560@section @sc{gdb/mi} Signal Handling Commands
17561
17562Signal handling commands are not implemented.
17563
17564@c @subheading -signal-handle
17565
17566@c @subheading -signal-list-handle-actions
17567
17568@c @subheading -signal-list-signal-types
17569@end ignore
17570
17571
17572@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
17573@node GDB/MI Stack Manipulation
17574@section @sc{gdb/mi} Stack Manipulation Commands
17575
17576
17577@subheading The @code{-stack-info-frame} Command
17578@findex -stack-info-frame
17579
17580@subsubheading Synopsis
17581
17582@smallexample
17583 -stack-info-frame
17584@end smallexample
17585
17586Get info on the current frame.
17587
17588@subsubheading @value{GDBN} Command
17589
17590The corresponding @value{GDBN} command is @samp{info frame} or @samp{frame}
17591(without arguments).
17592
17593@subsubheading Example
17594N.A.
17595
17596@subheading The @code{-stack-info-depth} Command
17597@findex -stack-info-depth
17598
17599@subsubheading Synopsis
17600
17601@smallexample
17602 -stack-info-depth [ @var{max-depth} ]
17603@end smallexample
17604
17605Return the depth of the stack. If the integer argument @var{max-depth}
17606is specified, do not count beyond @var{max-depth} frames.
17607
17608@subsubheading @value{GDBN} Command
17609
17610There's no equivalent @value{GDBN} command.
17611
17612@subsubheading Example
17613
17614For a stack with frame levels 0 through 11:
17615
17616@smallexample
17617(@value{GDBP})
17618-stack-info-depth
17619^done,depth="12"
17620(@value{GDBP})
17621-stack-info-depth 4
17622^done,depth="4"
17623(@value{GDBP})
17624-stack-info-depth 12
17625^done,depth="12"
17626(@value{GDBP})
17627-stack-info-depth 11
17628^done,depth="11"
17629(@value{GDBP})
17630-stack-info-depth 13
17631^done,depth="12"
17632(@value{GDBP})
17633@end smallexample
17634
17635@subheading The @code{-stack-list-arguments} Command
17636@findex -stack-list-arguments
17637
17638@subsubheading Synopsis
17639
17640@smallexample
17641 -stack-list-arguments @var{show-values}
17642 [ @var{low-frame} @var{high-frame} ]
17643@end smallexample
17644
17645Display a list of the arguments for the frames between @var{low-frame}
17646and @var{high-frame} (inclusive). If @var{low-frame} and
17647@var{high-frame} are not provided, list the arguments for the whole call
17648stack.
17649
17650The @var{show-values} argument must have a value of 0 or 1. A value of
176510 means that only the names of the arguments are listed, a value of 1
17652means that both names and values of the arguments are printed.
17653
17654@subsubheading @value{GDBN} Command
17655
17656@value{GDBN} does not have an equivalent command. @code{gdbtk} has a
17657@samp{gdb_get_args} command which partially overlaps with the
17658functionality of @samp{-stack-list-arguments}.
17659
17660@subsubheading Example
17661
17662@smallexample
17663(@value{GDBP})
17664-stack-list-frames
17665^done,
17666stack=[
17667frame=@{level="0",addr="0x00010734",func="callee4",
17668file="../../../devo/gdb/testsuite/gdb.mi/basics.c",line="8"@},
17669frame=@{level="1",addr="0x0001076c",func="callee3",
17670file="../../../devo/gdb/testsuite/gdb.mi/basics.c",line="17"@},
17671frame=@{level="2",addr="0x0001078c",func="callee2",
17672file="../../../devo/gdb/testsuite/gdb.mi/basics.c",line="22"@},
17673frame=@{level="3",addr="0x000107b4",func="callee1",
17674file="../../../devo/gdb/testsuite/gdb.mi/basics.c",line="27"@},
17675frame=@{level="4",addr="0x000107e0",func="main",
17676file="../../../devo/gdb/testsuite/gdb.mi/basics.c",line="32"@}]
17677(@value{GDBP})
17678-stack-list-arguments 0
17679^done,
17680stack-args=[
17681frame=@{level="0",args=[]@},
17682frame=@{level="1",args=[name="strarg"]@},
17683frame=@{level="2",args=[name="intarg",name="strarg"]@},
17684frame=@{level="3",args=[name="intarg",name="strarg",name="fltarg"]@},
17685frame=@{level="4",args=[]@}]
17686(@value{GDBP})
17687-stack-list-arguments 1
17688^done,
17689stack-args=[
17690frame=@{level="0",args=[]@},
17691frame=@{level="1",
17692 args=[@{name="strarg",value="0x11940 \"A string argument.\""@}]@},
17693frame=@{level="2",args=[
17694@{name="intarg",value="2"@},
17695@{name="strarg",value="0x11940 \"A string argument.\""@}]@},
17696@{frame=@{level="3",args=[
17697@{name="intarg",value="2"@},
17698@{name="strarg",value="0x11940 \"A string argument.\""@},
17699@{name="fltarg",value="3.5"@}]@},
17700frame=@{level="4",args=[]@}]
17701(@value{GDBP})
17702-stack-list-arguments 0 2 2
17703^done,stack-args=[frame=@{level="2",args=[name="intarg",name="strarg"]@}]
17704(@value{GDBP})
17705-stack-list-arguments 1 2 2
17706^done,stack-args=[frame=@{level="2",
17707args=[@{name="intarg",value="2"@},
17708@{name="strarg",value="0x11940 \"A string argument.\""@}]@}]
17709(@value{GDBP})
17710@end smallexample
17711
17712@c @subheading -stack-list-exception-handlers
17713
17714
17715@subheading The @code{-stack-list-frames} Command
17716@findex -stack-list-frames
17717
17718@subsubheading Synopsis
17719
17720@smallexample
17721 -stack-list-frames [ @var{low-frame} @var{high-frame} ]
17722@end smallexample
17723
17724List the frames currently on the stack. For each frame it displays the
17725following info:
17726
17727@table @samp
17728@item @var{level}
17729The frame number, 0 being the topmost frame, i.e. the innermost function.
17730@item @var{addr}
17731The @code{$pc} value for that frame.
17732@item @var{func}
17733Function name.
17734@item @var{file}
17735File name of the source file where the function lives.
17736@item @var{line}
17737Line number corresponding to the @code{$pc}.
17738@end table
17739
17740If invoked without arguments, this command prints a backtrace for the
17741whole stack. If given two integer arguments, it shows the frames whose
17742levels are between the two arguments (inclusive). If the two arguments
17743are equal, it shows the single frame at the corresponding level.
17744
17745@subsubheading @value{GDBN} Command
17746
17747The corresponding @value{GDBN} commands are @samp{backtrace} and @samp{where}.
17748
17749@subsubheading Example
17750
17751Full stack backtrace:
17752
17753@smallexample
17754(@value{GDBP})
17755-stack-list-frames
17756^done,stack=
17757[frame=@{level="0",addr="0x0001076c",func="foo",
17758 file="recursive2.c",line="11"@},
17759frame=@{level="1",addr="0x000107a4",func="foo",
17760 file="recursive2.c",line="14"@},
17761frame=@{level="2",addr="0x000107a4",func="foo",
17762 file="recursive2.c",line="14"@},
17763frame=@{level="3",addr="0x000107a4",func="foo",
17764 file="recursive2.c",line="14"@},
17765frame=@{level="4",addr="0x000107a4",func="foo",
17766 file="recursive2.c",line="14"@},
17767frame=@{level="5",addr="0x000107a4",func="foo",
17768 file="recursive2.c",line="14"@},
17769frame=@{level="6",addr="0x000107a4",func="foo",
17770 file="recursive2.c",line="14"@},
17771frame=@{level="7",addr="0x000107a4",func="foo",
17772 file="recursive2.c",line="14"@},
17773frame=@{level="8",addr="0x000107a4",func="foo",
17774 file="recursive2.c",line="14"@},
17775frame=@{level="9",addr="0x000107a4",func="foo",
17776 file="recursive2.c",line="14"@},
17777frame=@{level="10",addr="0x000107a4",func="foo",
17778 file="recursive2.c",line="14"@},
17779frame=@{level="11",addr="0x00010738",func="main",
17780 file="recursive2.c",line="4"@}]
17781(@value{GDBP})
17782@end smallexample
17783
17784Show frames between @var{low_frame} and @var{high_frame}:
17785
17786@smallexample
17787(@value{GDBP})
17788-stack-list-frames 3 5
17789^done,stack=
17790[frame=@{level="3",addr="0x000107a4",func="foo",
17791 file="recursive2.c",line="14"@},
17792frame=@{level="4",addr="0x000107a4",func="foo",
17793 file="recursive2.c",line="14"@},
17794frame=@{level="5",addr="0x000107a4",func="foo",
17795 file="recursive2.c",line="14"@}]
17796(@value{GDBP})
17797@end smallexample
17798
17799Show a single frame:
17800
17801@smallexample
17802(@value{GDBP})
17803-stack-list-frames 3 3
17804^done,stack=
17805[frame=@{level="3",addr="0x000107a4",func="foo",
17806 file="recursive2.c",line="14"@}]
17807(@value{GDBP})
17808@end smallexample
17809
17810
17811@subheading The @code{-stack-list-locals} Command
17812@findex -stack-list-locals
17813
17814@subsubheading Synopsis
17815
17816@smallexample
17817 -stack-list-locals @var{print-values}
17818@end smallexample
17819
17820Display the local variable names for the current frame. With an
bc8ced35
NR
17821argument of 0 or @code{--no-values}, prints only the names of the variables.
17822With argument of 1 or @code{--all-values}, prints also their values. With
17823argument of 2 or @code{--simple-values}, prints the name, type and value for
17824simple data types and the name and type for arrays, structures and
17825unions. In this last case, the idea is that the user can see the
17826value of simple data types immediately and he can create variable
17827objects for other data types if he wishes to explore their values in
17828more detail.
922fbb7b
AC
17829
17830@subsubheading @value{GDBN} Command
17831
17832@samp{info locals} in @value{GDBN}, @samp{gdb_get_locals} in @code{gdbtk}.
17833
17834@subsubheading Example
17835
17836@smallexample
17837(@value{GDBP})
17838-stack-list-locals 0
17839^done,locals=[name="A",name="B",name="C"]
17840(@value{GDBP})
bc8ced35 17841-stack-list-locals --all-values
922fbb7b 17842^done,locals=[@{name="A",value="1"@},@{name="B",value="2"@},
bc8ced35
NR
17843 @{name="C",value="@{1, 2, 3@}"@}]
17844-stack-list-locals --simple-values
17845^done,locals=[@{name="A",type="int",value="1"@},
17846 @{name="B",type="int",value="2"@},@{name="C",type="int [3]"@}]
922fbb7b
AC
17847(@value{GDBP})
17848@end smallexample
17849
17850
17851@subheading The @code{-stack-select-frame} Command
17852@findex -stack-select-frame
17853
17854@subsubheading Synopsis
17855
17856@smallexample
17857 -stack-select-frame @var{framenum}
17858@end smallexample
17859
17860Change the current frame. Select a different frame @var{framenum} on
17861the stack.
17862
17863@subsubheading @value{GDBN} Command
17864
17865The corresponding @value{GDBN} commands are @samp{frame}, @samp{up},
17866@samp{down}, @samp{select-frame}, @samp{up-silent}, and @samp{down-silent}.
17867
17868@subsubheading Example
17869
17870@smallexample
17871(@value{GDBP})
17872-stack-select-frame 2
17873^done
17874(@value{GDBP})
17875@end smallexample
17876
17877@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
17878@node GDB/MI Symbol Query
17879@section @sc{gdb/mi} Symbol Query Commands
17880
17881
17882@subheading The @code{-symbol-info-address} Command
17883@findex -symbol-info-address
17884
17885@subsubheading Synopsis
17886
17887@smallexample
17888 -symbol-info-address @var{symbol}
17889@end smallexample
17890
17891Describe where @var{symbol} is stored.
17892
17893@subsubheading @value{GDBN} Command
17894
17895The corresponding @value{GDBN} command is @samp{info address}.
17896
17897@subsubheading Example
17898N.A.
17899
17900
17901@subheading The @code{-symbol-info-file} Command
17902@findex -symbol-info-file
17903
17904@subsubheading Synopsis
17905
17906@smallexample
17907 -symbol-info-file
17908@end smallexample
17909
17910Show the file for the symbol.
17911
17912@subsubheading @value{GDBN} Command
17913
17914There's no equivalent @value{GDBN} command. @code{gdbtk} has
17915@samp{gdb_find_file}.
17916
17917@subsubheading Example
17918N.A.
17919
17920
17921@subheading The @code{-symbol-info-function} Command
17922@findex -symbol-info-function
17923
17924@subsubheading Synopsis
17925
17926@smallexample
17927 -symbol-info-function
17928@end smallexample
17929
17930Show which function the symbol lives in.
17931
17932@subsubheading @value{GDBN} Command
17933
17934@samp{gdb_get_function} in @code{gdbtk}.
17935
17936@subsubheading Example
17937N.A.
17938
17939
17940@subheading The @code{-symbol-info-line} Command
17941@findex -symbol-info-line
17942
17943@subsubheading Synopsis
17944
17945@smallexample
17946 -symbol-info-line
17947@end smallexample
17948
17949Show the core addresses of the code for a source line.
17950
17951@subsubheading @value{GDBN} Command
17952
71952f4c 17953The corresponding @value{GDBN} command is @samp{info line}.
922fbb7b
AC
17954@code{gdbtk} has the @samp{gdb_get_line} and @samp{gdb_get_file} commands.
17955
17956@subsubheading Example
17957N.A.
17958
17959
17960@subheading The @code{-symbol-info-symbol} Command
17961@findex -symbol-info-symbol
17962
17963@subsubheading Synopsis
17964
17965@smallexample
17966 -symbol-info-symbol @var{addr}
17967@end smallexample
17968
17969Describe what symbol is at location @var{addr}.
17970
17971@subsubheading @value{GDBN} Command
17972
17973The corresponding @value{GDBN} command is @samp{info symbol}.
17974
17975@subsubheading Example
17976N.A.
17977
17978
17979@subheading The @code{-symbol-list-functions} Command
17980@findex -symbol-list-functions
17981
17982@subsubheading Synopsis
17983
17984@smallexample
17985 -symbol-list-functions
17986@end smallexample
17987
17988List the functions in the executable.
17989
17990@subsubheading @value{GDBN} Command
17991
17992@samp{info functions} in @value{GDBN}, @samp{gdb_listfunc} and
17993@samp{gdb_search} in @code{gdbtk}.
17994
17995@subsubheading Example
17996N.A.
17997
17998
32e7087d
JB
17999@subheading The @code{-symbol-list-lines} Command
18000@findex -symbol-list-lines
18001
18002@subsubheading Synopsis
18003
18004@smallexample
18005 -symbol-list-lines @var{filename}
18006@end smallexample
18007
18008Print the list of lines that contain code and their associated program
18009addresses for the given source filename. The entries are sorted in
18010ascending PC order.
18011
18012@subsubheading @value{GDBN} Command
18013
18014There is no corresponding @value{GDBN} command.
18015
18016@subsubheading Example
18017@smallexample
18018(@value{GDBP})
18019-symbol-list-lines basics.c
54ff5908 18020^done,lines=[@{pc="0x08048554",line="7"@},@{pc="0x0804855a",line="8"@}]
32e7087d
JB
18021(@value{GDBP})
18022@end smallexample
18023
18024
922fbb7b
AC
18025@subheading The @code{-symbol-list-types} Command
18026@findex -symbol-list-types
18027
18028@subsubheading Synopsis
18029
18030@smallexample
18031 -symbol-list-types
18032@end smallexample
18033
18034List all the type names.
18035
18036@subsubheading @value{GDBN} Command
18037
18038The corresponding commands are @samp{info types} in @value{GDBN},
18039@samp{gdb_search} in @code{gdbtk}.
18040
18041@subsubheading Example
18042N.A.
18043
18044
18045@subheading The @code{-symbol-list-variables} Command
18046@findex -symbol-list-variables
18047
18048@subsubheading Synopsis
18049
18050@smallexample
18051 -symbol-list-variables
18052@end smallexample
18053
18054List all the global and static variable names.
18055
18056@subsubheading @value{GDBN} Command
18057
18058@samp{info variables} in @value{GDBN}, @samp{gdb_search} in @code{gdbtk}.
18059
18060@subsubheading Example
18061N.A.
18062
18063
18064@subheading The @code{-symbol-locate} Command
18065@findex -symbol-locate
18066
18067@subsubheading Synopsis
18068
18069@smallexample
18070 -symbol-locate
18071@end smallexample
18072
18073@subsubheading @value{GDBN} Command
18074
18075@samp{gdb_loc} in @code{gdbtk}.
18076
18077@subsubheading Example
18078N.A.
18079
18080
18081@subheading The @code{-symbol-type} Command
18082@findex -symbol-type
18083
18084@subsubheading Synopsis
18085
18086@smallexample
18087 -symbol-type @var{variable}
18088@end smallexample
18089
18090Show type of @var{variable}.
18091
18092@subsubheading @value{GDBN} Command
18093
18094The corresponding @value{GDBN} command is @samp{ptype}, @code{gdbtk} has
18095@samp{gdb_obj_variable}.
18096
18097@subsubheading Example
18098N.A.
18099
18100
18101@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
18102@node GDB/MI Target Manipulation
18103@section @sc{gdb/mi} Target Manipulation Commands
18104
18105
18106@subheading The @code{-target-attach} Command
18107@findex -target-attach
18108
18109@subsubheading Synopsis
18110
18111@smallexample
18112 -target-attach @var{pid} | @var{file}
18113@end smallexample
18114
18115Attach to a process @var{pid} or a file @var{file} outside of @value{GDBN}.
18116
18117@subsubheading @value{GDBN} command
18118
18119The corresponding @value{GDBN} command is @samp{attach}.
18120
18121@subsubheading Example
18122N.A.
18123
18124
18125@subheading The @code{-target-compare-sections} Command
18126@findex -target-compare-sections
18127
18128@subsubheading Synopsis
18129
18130@smallexample
18131 -target-compare-sections [ @var{section} ]
18132@end smallexample
18133
18134Compare data of section @var{section} on target to the exec file.
18135Without the argument, all sections are compared.
18136
18137@subsubheading @value{GDBN} Command
18138
18139The @value{GDBN} equivalent is @samp{compare-sections}.
18140
18141@subsubheading Example
18142N.A.
18143
18144
18145@subheading The @code{-target-detach} Command
18146@findex -target-detach
18147
18148@subsubheading Synopsis
18149
18150@smallexample
18151 -target-detach
18152@end smallexample
18153
18154Disconnect from the remote target. There's no output.
18155
18156@subsubheading @value{GDBN} command
18157
18158The corresponding @value{GDBN} command is @samp{detach}.
18159
18160@subsubheading Example
18161
18162@smallexample
18163(@value{GDBP})
18164-target-detach
18165^done
18166(@value{GDBP})
18167@end smallexample
18168
18169
07f31aa6
DJ
18170@subheading The @code{-target-disconnect} Command
18171@findex -target-disconnect
18172
18173@subsubheading Synopsis
18174
18175@example
18176 -target-disconnect
18177@end example
18178
18179Disconnect from the remote target. There's no output.
18180
18181@subsubheading @value{GDBN} command
18182
18183The corresponding @value{GDBN} command is @samp{disconnect}.
18184
18185@subsubheading Example
18186
18187@smallexample
18188(@value{GDBP})
18189-target-disconnect
18190^done
18191(@value{GDBP})
18192@end smallexample
18193
18194
922fbb7b
AC
18195@subheading The @code{-target-download} Command
18196@findex -target-download
18197
18198@subsubheading Synopsis
18199
18200@smallexample
18201 -target-download
18202@end smallexample
18203
18204Loads the executable onto the remote target.
18205It prints out an update message every half second, which includes the fields:
18206
18207@table @samp
18208@item section
18209The name of the section.
18210@item section-sent
18211The size of what has been sent so far for that section.
18212@item section-size
18213The size of the section.
18214@item total-sent
18215The total size of what was sent so far (the current and the previous sections).
18216@item total-size
18217The size of the overall executable to download.
18218@end table
18219
18220@noindent
18221Each message is sent as status record (@pxref{GDB/MI Output Syntax, ,
18222@sc{gdb/mi} Output Syntax}).
18223
18224In addition, it prints the name and size of the sections, as they are
18225downloaded. These messages include the following fields:
18226
18227@table @samp
18228@item section
18229The name of the section.
18230@item section-size
18231The size of the section.
18232@item total-size
18233The size of the overall executable to download.
18234@end table
18235
18236@noindent
18237At the end, a summary is printed.
18238
18239@subsubheading @value{GDBN} Command
18240
18241The corresponding @value{GDBN} command is @samp{load}.
18242
18243@subsubheading Example
18244
18245Note: each status message appears on a single line. Here the messages
18246have been broken down so that they can fit onto a page.
18247
18248@smallexample
18249(@value{GDBP})
18250-target-download
18251+download,@{section=".text",section-size="6668",total-size="9880"@}
18252+download,@{section=".text",section-sent="512",section-size="6668",
18253total-sent="512",total-size="9880"@}
18254+download,@{section=".text",section-sent="1024",section-size="6668",
18255total-sent="1024",total-size="9880"@}
18256+download,@{section=".text",section-sent="1536",section-size="6668",
18257total-sent="1536",total-size="9880"@}
18258+download,@{section=".text",section-sent="2048",section-size="6668",
18259total-sent="2048",total-size="9880"@}
18260+download,@{section=".text",section-sent="2560",section-size="6668",
18261total-sent="2560",total-size="9880"@}
18262+download,@{section=".text",section-sent="3072",section-size="6668",
18263total-sent="3072",total-size="9880"@}
18264+download,@{section=".text",section-sent="3584",section-size="6668",
18265total-sent="3584",total-size="9880"@}
18266+download,@{section=".text",section-sent="4096",section-size="6668",
18267total-sent="4096",total-size="9880"@}
18268+download,@{section=".text",section-sent="4608",section-size="6668",
18269total-sent="4608",total-size="9880"@}
18270+download,@{section=".text",section-sent="5120",section-size="6668",
18271total-sent="5120",total-size="9880"@}
18272+download,@{section=".text",section-sent="5632",section-size="6668",
18273total-sent="5632",total-size="9880"@}
18274+download,@{section=".text",section-sent="6144",section-size="6668",
18275total-sent="6144",total-size="9880"@}
18276+download,@{section=".text",section-sent="6656",section-size="6668",
18277total-sent="6656",total-size="9880"@}
18278+download,@{section=".init",section-size="28",total-size="9880"@}
18279+download,@{section=".fini",section-size="28",total-size="9880"@}
18280+download,@{section=".data",section-size="3156",total-size="9880"@}
18281+download,@{section=".data",section-sent="512",section-size="3156",
18282total-sent="7236",total-size="9880"@}
18283+download,@{section=".data",section-sent="1024",section-size="3156",
18284total-sent="7748",total-size="9880"@}
18285+download,@{section=".data",section-sent="1536",section-size="3156",
18286total-sent="8260",total-size="9880"@}
18287+download,@{section=".data",section-sent="2048",section-size="3156",
18288total-sent="8772",total-size="9880"@}
18289+download,@{section=".data",section-sent="2560",section-size="3156",
18290total-sent="9284",total-size="9880"@}
18291+download,@{section=".data",section-sent="3072",section-size="3156",
18292total-sent="9796",total-size="9880"@}
18293^done,address="0x10004",load-size="9880",transfer-rate="6586",
18294write-rate="429"
18295(@value{GDBP})
18296@end smallexample
18297
18298
18299@subheading The @code{-target-exec-status} Command
18300@findex -target-exec-status
18301
18302@subsubheading Synopsis
18303
18304@smallexample
18305 -target-exec-status
18306@end smallexample
18307
18308Provide information on the state of the target (whether it is running or
18309not, for instance).
18310
18311@subsubheading @value{GDBN} Command
18312
18313There's no equivalent @value{GDBN} command.
18314
18315@subsubheading Example
18316N.A.
18317
18318
18319@subheading The @code{-target-list-available-targets} Command
18320@findex -target-list-available-targets
18321
18322@subsubheading Synopsis
18323
18324@smallexample
18325 -target-list-available-targets
18326@end smallexample
18327
18328List the possible targets to connect to.
18329
18330@subsubheading @value{GDBN} Command
18331
18332The corresponding @value{GDBN} command is @samp{help target}.
18333
18334@subsubheading Example
18335N.A.
18336
18337
18338@subheading The @code{-target-list-current-targets} Command
18339@findex -target-list-current-targets
18340
18341@subsubheading Synopsis
18342
18343@smallexample
18344 -target-list-current-targets
18345@end smallexample
18346
18347Describe the current target.
18348
18349@subsubheading @value{GDBN} Command
18350
18351The corresponding information is printed by @samp{info file} (among
18352other things).
18353
18354@subsubheading Example
18355N.A.
18356
18357
18358@subheading The @code{-target-list-parameters} Command
18359@findex -target-list-parameters
18360
18361@subsubheading Synopsis
18362
18363@smallexample
18364 -target-list-parameters
18365@end smallexample
18366
18367@c ????
18368
18369@subsubheading @value{GDBN} Command
18370
18371No equivalent.
18372
18373@subsubheading Example
18374N.A.
18375
18376
18377@subheading The @code{-target-select} Command
18378@findex -target-select
18379
18380@subsubheading Synopsis
18381
18382@smallexample
18383 -target-select @var{type} @var{parameters @dots{}}
18384@end smallexample
18385
18386Connect @value{GDBN} to the remote target. This command takes two args:
18387
18388@table @samp
18389@item @var{type}
18390The type of target, for instance @samp{async}, @samp{remote}, etc.
18391@item @var{parameters}
18392Device names, host names and the like. @xref{Target Commands, ,
18393Commands for managing targets}, for more details.
18394@end table
18395
18396The output is a connection notification, followed by the address at
18397which the target program is, in the following form:
18398
18399@smallexample
18400^connected,addr="@var{address}",func="@var{function name}",
18401 args=[@var{arg list}]
18402@end smallexample
18403
18404@subsubheading @value{GDBN} Command
18405
18406The corresponding @value{GDBN} command is @samp{target}.
18407
18408@subsubheading Example
18409
18410@smallexample
18411(@value{GDBP})
18412-target-select async /dev/ttya
18413^connected,addr="0xfe00a300",func="??",args=[]
18414(@value{GDBP})
18415@end smallexample
18416
18417@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
18418@node GDB/MI Thread Commands
18419@section @sc{gdb/mi} Thread Commands
18420
18421
18422@subheading The @code{-thread-info} Command
18423@findex -thread-info
18424
18425@subsubheading Synopsis
18426
18427@smallexample
18428 -thread-info
18429@end smallexample
18430
18431@subsubheading @value{GDBN} command
18432
18433No equivalent.
18434
18435@subsubheading Example
18436N.A.
18437
18438
18439@subheading The @code{-thread-list-all-threads} Command
18440@findex -thread-list-all-threads
18441
18442@subsubheading Synopsis
18443
18444@smallexample
18445 -thread-list-all-threads
18446@end smallexample
18447
18448@subsubheading @value{GDBN} Command
18449
18450The equivalent @value{GDBN} command is @samp{info threads}.
18451
18452@subsubheading Example
18453N.A.
18454
18455
18456@subheading The @code{-thread-list-ids} Command
18457@findex -thread-list-ids
18458
18459@subsubheading Synopsis
18460
18461@smallexample
18462 -thread-list-ids
18463@end smallexample
18464
18465Produces a list of the currently known @value{GDBN} thread ids. At the
18466end of the list it also prints the total number of such threads.
18467
18468@subsubheading @value{GDBN} Command
18469
18470Part of @samp{info threads} supplies the same information.
18471
18472@subsubheading Example
18473
18474No threads present, besides the main process:
18475
18476@smallexample
18477(@value{GDBP})
18478-thread-list-ids
18479^done,thread-ids=@{@},number-of-threads="0"
18480(@value{GDBP})
18481@end smallexample
18482
18483
18484Several threads:
18485
18486@smallexample
18487(@value{GDBP})
18488-thread-list-ids
18489^done,thread-ids=@{thread-id="3",thread-id="2",thread-id="1"@},
18490number-of-threads="3"
18491(@value{GDBP})
18492@end smallexample
18493
18494
18495@subheading The @code{-thread-select} Command
18496@findex -thread-select
18497
18498@subsubheading Synopsis
18499
18500@smallexample
18501 -thread-select @var{threadnum}
18502@end smallexample
18503
18504Make @var{threadnum} the current thread. It prints the number of the new
18505current thread, and the topmost frame for that thread.
18506
18507@subsubheading @value{GDBN} Command
18508
18509The corresponding @value{GDBN} command is @samp{thread}.
18510
18511@subsubheading Example
18512
18513@smallexample
18514(@value{GDBP})
18515-exec-next
18516^running
18517(@value{GDBP})
18518*stopped,reason="end-stepping-range",thread-id="2",line="187",
18519file="../../../devo/gdb/testsuite/gdb.threads/linux-dp.c"
18520(@value{GDBP})
18521-thread-list-ids
18522^done,
18523thread-ids=@{thread-id="3",thread-id="2",thread-id="1"@},
18524number-of-threads="3"
18525(@value{GDBP})
18526-thread-select 3
18527^done,new-thread-id="3",
18528frame=@{level="0",func="vprintf",
18529args=[@{name="format",value="0x8048e9c \"%*s%c %d %c\\n\""@},
18530@{name="arg",value="0x2"@}],file="vprintf.c",line="31"@}
18531(@value{GDBP})
18532@end smallexample
18533
18534@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
18535@node GDB/MI Tracepoint Commands
18536@section @sc{gdb/mi} Tracepoint Commands
18537
18538The tracepoint commands are not yet implemented.
18539
18540@c @subheading -trace-actions
18541
18542@c @subheading -trace-delete
18543
18544@c @subheading -trace-disable
18545
18546@c @subheading -trace-dump
18547
18548@c @subheading -trace-enable
18549
18550@c @subheading -trace-exists
18551
18552@c @subheading -trace-find
18553
18554@c @subheading -trace-frame-number
18555
18556@c @subheading -trace-info
18557
18558@c @subheading -trace-insert
18559
18560@c @subheading -trace-list
18561
18562@c @subheading -trace-pass-count
18563
18564@c @subheading -trace-save
18565
18566@c @subheading -trace-start
18567
18568@c @subheading -trace-stop
18569
18570
18571@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
18572@node GDB/MI Variable Objects
18573@section @sc{gdb/mi} Variable Objects
18574
18575
18576@subheading Motivation for Variable Objects in @sc{gdb/mi}
18577
18578For the implementation of a variable debugger window (locals, watched
18579expressions, etc.), we are proposing the adaptation of the existing code
18580used by @code{Insight}.
18581
18582The two main reasons for that are:
18583
18584@enumerate 1
18585@item
18586It has been proven in practice (it is already on its second generation).
18587
18588@item
18589It will shorten development time (needless to say how important it is
18590now).
18591@end enumerate
18592
18593The original interface was designed to be used by Tcl code, so it was
18594slightly changed so it could be used through @sc{gdb/mi}. This section
18595describes the @sc{gdb/mi} operations that will be available and gives some
18596hints about their use.
18597
18598@emph{Note}: In addition to the set of operations described here, we
18599expect the @sc{gui} implementation of a variable window to require, at
18600least, the following operations:
18601
18602@itemize @bullet
18603@item @code{-gdb-show} @code{output-radix}
18604@item @code{-stack-list-arguments}
18605@item @code{-stack-list-locals}
18606@item @code{-stack-select-frame}
18607@end itemize
18608
18609@subheading Introduction to Variable Objects in @sc{gdb/mi}
18610
18611@cindex variable objects in @sc{gdb/mi}
18612The basic idea behind variable objects is the creation of a named object
18613to represent a variable, an expression, a memory location or even a CPU
18614register. For each object created, a set of operations is available for
18615examining or changing its properties.
18616
18617Furthermore, complex data types, such as C structures, are represented
18618in a tree format. For instance, the @code{struct} type variable is the
18619root and the children will represent the struct members. If a child
18620is itself of a complex type, it will also have children of its own.
18621Appropriate language differences are handled for C, C@t{++} and Java.
18622
18623When returning the actual values of the objects, this facility allows
18624for the individual selection of the display format used in the result
18625creation. It can be chosen among: binary, decimal, hexadecimal, octal
18626and natural. Natural refers to a default format automatically
18627chosen based on the variable type (like decimal for an @code{int}, hex
18628for pointers, etc.).
18629
18630The following is the complete set of @sc{gdb/mi} operations defined to
18631access this functionality:
18632
18633@multitable @columnfractions .4 .6
18634@item @strong{Operation}
18635@tab @strong{Description}
18636
18637@item @code{-var-create}
18638@tab create a variable object
18639@item @code{-var-delete}
18640@tab delete the variable object and its children
18641@item @code{-var-set-format}
18642@tab set the display format of this variable
18643@item @code{-var-show-format}
18644@tab show the display format of this variable
18645@item @code{-var-info-num-children}
18646@tab tells how many children this object has
18647@item @code{-var-list-children}
18648@tab return a list of the object's children
18649@item @code{-var-info-type}
18650@tab show the type of this variable object
18651@item @code{-var-info-expression}
18652@tab print what this variable object represents
18653@item @code{-var-show-attributes}
18654@tab is this variable editable? does it exist here?
18655@item @code{-var-evaluate-expression}
18656@tab get the value of this variable
18657@item @code{-var-assign}
18658@tab set the value of this variable
18659@item @code{-var-update}
18660@tab update the variable and its children
18661@end multitable
18662
18663In the next subsection we describe each operation in detail and suggest
18664how it can be used.
18665
18666@subheading Description And Use of Operations on Variable Objects
18667
18668@subheading The @code{-var-create} Command
18669@findex -var-create
18670
18671@subsubheading Synopsis
18672
18673@smallexample
18674 -var-create @{@var{name} | "-"@}
18675 @{@var{frame-addr} | "*"@} @var{expression}
18676@end smallexample
18677
18678This operation creates a variable object, which allows the monitoring of
18679a variable, the result of an expression, a memory cell or a CPU
18680register.
18681
18682The @var{name} parameter is the string by which the object can be
18683referenced. It must be unique. If @samp{-} is specified, the varobj
18684system will generate a string ``varNNNNNN'' automatically. It will be
18685unique provided that one does not specify @var{name} on that format.
18686The command fails if a duplicate name is found.
18687
18688The frame under which the expression should be evaluated can be
18689specified by @var{frame-addr}. A @samp{*} indicates that the current
18690frame should be used.
18691
18692@var{expression} is any expression valid on the current language set (must not
18693begin with a @samp{*}), or one of the following:
18694
18695@itemize @bullet
18696@item
18697@samp{*@var{addr}}, where @var{addr} is the address of a memory cell
18698
18699@item
18700@samp{*@var{addr}-@var{addr}} --- a memory address range (TBD)
18701
18702@item
18703@samp{$@var{regname}} --- a CPU register name
18704@end itemize
18705
18706@subsubheading Result
18707
18708This operation returns the name, number of children and the type of the
18709object created. Type is returned as a string as the ones generated by
18710the @value{GDBN} CLI:
18711
18712@smallexample
18713 name="@var{name}",numchild="N",type="@var{type}"
18714@end smallexample
18715
18716
18717@subheading The @code{-var-delete} Command
18718@findex -var-delete
18719
18720@subsubheading Synopsis
18721
18722@smallexample
18723 -var-delete @var{name}
18724@end smallexample
18725
18726Deletes a previously created variable object and all of its children.
18727
18728Returns an error if the object @var{name} is not found.
18729
18730
18731@subheading The @code{-var-set-format} Command
18732@findex -var-set-format
18733
18734@subsubheading Synopsis
18735
18736@smallexample
18737 -var-set-format @var{name} @var{format-spec}
18738@end smallexample
18739
18740Sets the output format for the value of the object @var{name} to be
18741@var{format-spec}.
18742
18743The syntax for the @var{format-spec} is as follows:
18744
18745@smallexample
18746 @var{format-spec} @expansion{}
18747 @{binary | decimal | hexadecimal | octal | natural@}
18748@end smallexample
18749
18750
18751@subheading The @code{-var-show-format} Command
18752@findex -var-show-format
18753
18754@subsubheading Synopsis
18755
18756@smallexample
18757 -var-show-format @var{name}
18758@end smallexample
18759
18760Returns the format used to display the value of the object @var{name}.
18761
18762@smallexample
18763 @var{format} @expansion{}
18764 @var{format-spec}
18765@end smallexample
18766
18767
18768@subheading The @code{-var-info-num-children} Command
18769@findex -var-info-num-children
18770
18771@subsubheading Synopsis
18772
18773@smallexample
18774 -var-info-num-children @var{name}
18775@end smallexample
18776
18777Returns the number of children of a variable object @var{name}:
18778
18779@smallexample
18780 numchild=@var{n}
18781@end smallexample
18782
18783
18784@subheading The @code{-var-list-children} Command
18785@findex -var-list-children
18786
18787@subsubheading Synopsis
18788
18789@smallexample
bc8ced35 18790 -var-list-children [@var{print-values}] @var{name}
922fbb7b
AC
18791@end smallexample
18792
bc8ced35
NR
18793Returns a list of the children of the specified variable object. With
18794just the variable object name as an argument or with an optional
18795preceding argument of 0 or @code{--no-values}, prints only the names of the
18796variables. With an optional preceding argument of 1 or @code{--all-values},
18797also prints their values.
18798
18799@subsubheading Example
922fbb7b
AC
18800
18801@smallexample
bc8ced35
NR
18802(@value{GDBP})
18803 -var-list-children n
922fbb7b
AC
18804 numchild=@var{n},children=[@{name=@var{name},
18805 numchild=@var{n},type=@var{type}@},@r{(repeats N times)}]
bc8ced35
NR
18806(@value{GDBP})
18807 -var-list-children --all-values n
18808 numchild=@var{n},children=[@{name=@var{name},
18809 numchild=@var{n},value=@var{value},type=@var{type}@},@r{(repeats N times)}]
922fbb7b
AC
18810@end smallexample
18811
18812
18813@subheading The @code{-var-info-type} Command
18814@findex -var-info-type
18815
18816@subsubheading Synopsis
18817
18818@smallexample
18819 -var-info-type @var{name}
18820@end smallexample
18821
18822Returns the type of the specified variable @var{name}. The type is
18823returned as a string in the same format as it is output by the
18824@value{GDBN} CLI:
18825
18826@smallexample
18827 type=@var{typename}
18828@end smallexample
18829
18830
18831@subheading The @code{-var-info-expression} Command
18832@findex -var-info-expression
18833
18834@subsubheading Synopsis
18835
18836@smallexample
18837 -var-info-expression @var{name}
18838@end smallexample
18839
18840Returns what is represented by the variable object @var{name}:
18841
18842@smallexample
18843 lang=@var{lang-spec},exp=@var{expression}
18844@end smallexample
18845
18846@noindent
18847where @var{lang-spec} is @code{@{"C" | "C++" | "Java"@}}.
18848
18849@subheading The @code{-var-show-attributes} Command
18850@findex -var-show-attributes
18851
18852@subsubheading Synopsis
18853
18854@smallexample
18855 -var-show-attributes @var{name}
18856@end smallexample
18857
18858List attributes of the specified variable object @var{name}:
18859
18860@smallexample
18861 status=@var{attr} [ ( ,@var{attr} )* ]
18862@end smallexample
18863
18864@noindent
18865where @var{attr} is @code{@{ @{ editable | noneditable @} | TBD @}}.
18866
18867@subheading The @code{-var-evaluate-expression} Command
18868@findex -var-evaluate-expression
18869
18870@subsubheading Synopsis
18871
18872@smallexample
18873 -var-evaluate-expression @var{name}
18874@end smallexample
18875
18876Evaluates the expression that is represented by the specified variable
18877object and returns its value as a string in the current format specified
18878for the object:
18879
18880@smallexample
18881 value=@var{value}
18882@end smallexample
18883
18884Note that one must invoke @code{-var-list-children} for a variable
18885before the value of a child variable can be evaluated.
18886
18887@subheading The @code{-var-assign} Command
18888@findex -var-assign
18889
18890@subsubheading Synopsis
18891
18892@smallexample
18893 -var-assign @var{name} @var{expression}
18894@end smallexample
18895
18896Assigns the value of @var{expression} to the variable object specified
18897by @var{name}. The object must be @samp{editable}. If the variable's
b383017d 18898value is altered by the assign, the variable will show up in any
922fbb7b
AC
18899subsequent @code{-var-update} list.
18900
18901@subsubheading Example
18902
18903@smallexample
18904(@value{GDBP})
18905-var-assign var1 3
18906^done,value="3"
18907(@value{GDBP})
18908-var-update *
18909^done,changelist=[@{name="var1",in_scope="true",type_changed="false"@}]
18910(@value{GDBP})
18911@end smallexample
18912
18913@subheading The @code{-var-update} Command
18914@findex -var-update
18915
18916@subsubheading Synopsis
18917
18918@smallexample
18919 -var-update @{@var{name} | "*"@}
18920@end smallexample
18921
18922Update the value of the variable object @var{name} by evaluating its
18923expression after fetching all the new values from memory or registers.
18924A @samp{*} causes all existing variable objects to be updated.
18925
18926
18927@node Annotations
18928@chapter @value{GDBN} Annotations
18929
086432e2
AC
18930This chapter describes annotations in @value{GDBN}. Annotations were
18931designed to interface @value{GDBN} to graphical user interfaces or other
18932similar programs which want to interact with @value{GDBN} at a
922fbb7b
AC
18933relatively high level.
18934
086432e2
AC
18935The annotation mechanism has largely been superseeded by @sc{gdb/mi}
18936(@pxref{GDB/MI}).
18937
922fbb7b
AC
18938@ignore
18939This is Edition @value{EDITION}, @value{DATE}.
18940@end ignore
18941
18942@menu
18943* Annotations Overview:: What annotations are; the general syntax.
18944* Server Prefix:: Issuing a command without affecting user state.
922fbb7b
AC
18945* Prompting:: Annotations marking @value{GDBN}'s need for input.
18946* Errors:: Annotations for error messages.
922fbb7b
AC
18947* Invalidation:: Some annotations describe things now invalid.
18948* Annotations for Running::
18949 Whether the program is running, how it stopped, etc.
18950* Source Annotations:: Annotations describing source code.
922fbb7b
AC
18951@end menu
18952
18953@node Annotations Overview
18954@section What is an Annotation?
18955@cindex annotations
18956
922fbb7b
AC
18957Annotations start with a newline character, two @samp{control-z}
18958characters, and the name of the annotation. If there is no additional
18959information associated with this annotation, the name of the annotation
18960is followed immediately by a newline. If there is additional
18961information, the name of the annotation is followed by a space, the
18962additional information, and a newline. The additional information
18963cannot contain newline characters.
18964
18965Any output not beginning with a newline and two @samp{control-z}
18966characters denotes literal output from @value{GDBN}. Currently there is
18967no need for @value{GDBN} to output a newline followed by two
18968@samp{control-z} characters, but if there was such a need, the
18969annotations could be extended with an @samp{escape} annotation which
18970means those three characters as output.
18971
086432e2
AC
18972The annotation @var{level}, which is specified using the
18973@option{--annotate} command line option (@pxref{Mode Options}), controls
18974how much information @value{GDBN} prints together with its prompt,
18975values of expressions, source lines, and other types of output. Level 0
18976is for no anntations, level 1 is for use when @value{GDBN} is run as a
18977subprocess of @sc{gnu} Emacs, level 3 is the maximum annotation suitable
18978for programs that control @value{GDBN}, and level 2 annotations have
18979been made obsolete (@pxref{Limitations, , Limitations of the Annotation
18980Interface, annotate, GDB's Obsolete Annotations}). This chapter
18981describes level 3 annotations.
18982
922fbb7b
AC
18983A simple example of starting up @value{GDBN} with annotations is:
18984
18985@smallexample
086432e2
AC
18986$ @kbd{gdb --annotate=3}
18987GNU gdb 6.0
18988Copyright 2003 Free Software Foundation, Inc.
922fbb7b
AC
18989GDB is free software, covered by the GNU General Public License,
18990and you are welcome to change it and/or distribute copies of it
18991under certain conditions.
18992Type "show copying" to see the conditions.
18993There is absolutely no warranty for GDB. Type "show warranty"
18994for details.
086432e2 18995This GDB was configured as "i386-pc-linux-gnu"
922fbb7b
AC
18996
18997^Z^Zpre-prompt
f7dc1244 18998(@value{GDBP})
922fbb7b 18999^Z^Zprompt
086432e2 19000@kbd{quit}
922fbb7b
AC
19001
19002^Z^Zpost-prompt
b383017d 19003$
922fbb7b
AC
19004@end smallexample
19005
19006Here @samp{quit} is input to @value{GDBN}; the rest is output from
19007@value{GDBN}. The three lines beginning @samp{^Z^Z} (where @samp{^Z}
19008denotes a @samp{control-z} character) are annotations; the rest is
19009output from @value{GDBN}.
19010
19011@node Server Prefix
19012@section The Server Prefix
19013@cindex server prefix for annotations
19014
19015To issue a command to @value{GDBN} without affecting certain aspects of
19016the state which is seen by users, prefix it with @samp{server }. This
19017means that this command will not affect the command history, nor will it
19018affect @value{GDBN}'s notion of which command to repeat if @key{RET} is
19019pressed on a line by itself.
19020
19021The server prefix does not affect the recording of values into the value
19022history; to print a value without recording it into the value history,
19023use the @code{output} command instead of the @code{print} command.
19024
922fbb7b
AC
19025@node Prompting
19026@section Annotation for @value{GDBN} Input
19027
19028@cindex annotations for prompts
19029When @value{GDBN} prompts for input, it annotates this fact so it is possible
19030to know when to send output, when the output from a given command is
19031over, etc.
19032
19033Different kinds of input each have a different @dfn{input type}. Each
19034input type has three annotations: a @code{pre-} annotation, which
19035denotes the beginning of any prompt which is being output, a plain
19036annotation, which denotes the end of the prompt, and then a @code{post-}
19037annotation which denotes the end of any echo which may (or may not) be
19038associated with the input. For example, the @code{prompt} input type
19039features the following annotations:
19040
19041@smallexample
19042^Z^Zpre-prompt
19043^Z^Zprompt
19044^Z^Zpost-prompt
19045@end smallexample
19046
19047The input types are
19048
19049@table @code
19050@findex pre-prompt
19051@findex prompt
19052@findex post-prompt
19053@item prompt
19054When @value{GDBN} is prompting for a command (the main @value{GDBN} prompt).
19055
19056@findex pre-commands
19057@findex commands
19058@findex post-commands
19059@item commands
19060When @value{GDBN} prompts for a set of commands, like in the @code{commands}
19061command. The annotations are repeated for each command which is input.
19062
19063@findex pre-overload-choice
19064@findex overload-choice
19065@findex post-overload-choice
19066@item overload-choice
19067When @value{GDBN} wants the user to select between various overloaded functions.
19068
19069@findex pre-query
19070@findex query
19071@findex post-query
19072@item query
19073When @value{GDBN} wants the user to confirm a potentially dangerous operation.
19074
19075@findex pre-prompt-for-continue
19076@findex prompt-for-continue
19077@findex post-prompt-for-continue
19078@item prompt-for-continue
19079When @value{GDBN} is asking the user to press return to continue. Note: Don't
19080expect this to work well; instead use @code{set height 0} to disable
19081prompting. This is because the counting of lines is buggy in the
19082presence of annotations.
19083@end table
19084
19085@node Errors
19086@section Errors
19087@cindex annotations for errors, warnings and interrupts
19088
19089@findex quit
19090@smallexample
19091^Z^Zquit
19092@end smallexample
19093
19094This annotation occurs right before @value{GDBN} responds to an interrupt.
19095
19096@findex error
19097@smallexample
19098^Z^Zerror
19099@end smallexample
19100
19101This annotation occurs right before @value{GDBN} responds to an error.
19102
19103Quit and error annotations indicate that any annotations which @value{GDBN} was
19104in the middle of may end abruptly. For example, if a
19105@code{value-history-begin} annotation is followed by a @code{error}, one
19106cannot expect to receive the matching @code{value-history-end}. One
19107cannot expect not to receive it either, however; an error annotation
19108does not necessarily mean that @value{GDBN} is immediately returning all the way
19109to the top level.
19110
19111@findex error-begin
19112A quit or error annotation may be preceded by
19113
19114@smallexample
19115^Z^Zerror-begin
19116@end smallexample
19117
19118Any output between that and the quit or error annotation is the error
19119message.
19120
19121Warning messages are not yet annotated.
19122@c If we want to change that, need to fix warning(), type_error(),
19123@c range_error(), and possibly other places.
19124
922fbb7b
AC
19125@node Invalidation
19126@section Invalidation Notices
19127
19128@cindex annotations for invalidation messages
19129The following annotations say that certain pieces of state may have
19130changed.
19131
19132@table @code
19133@findex frames-invalid
19134@item ^Z^Zframes-invalid
19135
19136The frames (for example, output from the @code{backtrace} command) may
19137have changed.
19138
19139@findex breakpoints-invalid
19140@item ^Z^Zbreakpoints-invalid
19141
19142The breakpoints may have changed. For example, the user just added or
19143deleted a breakpoint.
19144@end table
19145
19146@node Annotations for Running
19147@section Running the Program
19148@cindex annotations for running programs
19149
19150@findex starting
19151@findex stopping
19152When the program starts executing due to a @value{GDBN} command such as
b383017d 19153@code{step} or @code{continue},
922fbb7b
AC
19154
19155@smallexample
19156^Z^Zstarting
19157@end smallexample
19158
b383017d 19159is output. When the program stops,
922fbb7b
AC
19160
19161@smallexample
19162^Z^Zstopped
19163@end smallexample
19164
19165is output. Before the @code{stopped} annotation, a variety of
19166annotations describe how the program stopped.
19167
19168@table @code
19169@findex exited
19170@item ^Z^Zexited @var{exit-status}
19171The program exited, and @var{exit-status} is the exit status (zero for
19172successful exit, otherwise nonzero).
19173
19174@findex signalled
19175@findex signal-name
19176@findex signal-name-end
19177@findex signal-string
19178@findex signal-string-end
19179@item ^Z^Zsignalled
19180The program exited with a signal. After the @code{^Z^Zsignalled}, the
19181annotation continues:
19182
19183@smallexample
19184@var{intro-text}
19185^Z^Zsignal-name
19186@var{name}
19187^Z^Zsignal-name-end
19188@var{middle-text}
19189^Z^Zsignal-string
19190@var{string}
19191^Z^Zsignal-string-end
19192@var{end-text}
19193@end smallexample
19194
19195@noindent
19196where @var{name} is the name of the signal, such as @code{SIGILL} or
19197@code{SIGSEGV}, and @var{string} is the explanation of the signal, such
19198as @code{Illegal Instruction} or @code{Segmentation fault}.
19199@var{intro-text}, @var{middle-text}, and @var{end-text} are for the
19200user's benefit and have no particular format.
19201
19202@findex signal
19203@item ^Z^Zsignal
19204The syntax of this annotation is just like @code{signalled}, but @value{GDBN} is
19205just saying that the program received the signal, not that it was
19206terminated with it.
19207
19208@findex breakpoint
19209@item ^Z^Zbreakpoint @var{number}
19210The program hit breakpoint number @var{number}.
19211
19212@findex watchpoint
19213@item ^Z^Zwatchpoint @var{number}
19214The program hit watchpoint number @var{number}.
19215@end table
19216
19217@node Source Annotations
19218@section Displaying Source
19219@cindex annotations for source display
19220
19221@findex source
19222The following annotation is used instead of displaying source code:
19223
19224@smallexample
19225^Z^Zsource @var{filename}:@var{line}:@var{character}:@var{middle}:@var{addr}
19226@end smallexample
19227
19228where @var{filename} is an absolute file name indicating which source
19229file, @var{line} is the line number within that file (where 1 is the
19230first line in the file), @var{character} is the character position
19231within the file (where 0 is the first character in the file) (for most
19232debug formats this will necessarily point to the beginning of a line),
19233@var{middle} is @samp{middle} if @var{addr} is in the middle of the
19234line, or @samp{beg} if @var{addr} is at the beginning of the line, and
19235@var{addr} is the address in the target program associated with the
19236source which is being displayed. @var{addr} is in the form @samp{0x}
19237followed by one or more lowercase hex digits (note that this does not
19238depend on the language).
19239
8e04817f
AC
19240@node GDB Bugs
19241@chapter Reporting Bugs in @value{GDBN}
19242@cindex bugs in @value{GDBN}
19243@cindex reporting bugs in @value{GDBN}
c906108c 19244
8e04817f 19245Your bug reports play an essential role in making @value{GDBN} reliable.
c906108c 19246
8e04817f
AC
19247Reporting a bug may help you by bringing a solution to your problem, or it
19248may not. But in any case the principal function of a bug report is to help
19249the entire community by making the next version of @value{GDBN} work better. Bug
19250reports are your contribution to the maintenance of @value{GDBN}.
c906108c 19251
8e04817f
AC
19252In order for a bug report to serve its purpose, you must include the
19253information that enables us to fix the bug.
c4555f82
SC
19254
19255@menu
8e04817f
AC
19256* Bug Criteria:: Have you found a bug?
19257* Bug Reporting:: How to report bugs
c4555f82
SC
19258@end menu
19259
8e04817f
AC
19260@node Bug Criteria
19261@section Have you found a bug?
19262@cindex bug criteria
c4555f82 19263
8e04817f 19264If you are not sure whether you have found a bug, here are some guidelines:
c4555f82
SC
19265
19266@itemize @bullet
8e04817f
AC
19267@cindex fatal signal
19268@cindex debugger crash
19269@cindex crash of debugger
c4555f82 19270@item
8e04817f
AC
19271If the debugger gets a fatal signal, for any input whatever, that is a
19272@value{GDBN} bug. Reliable debuggers never crash.
19273
19274@cindex error on valid input
19275@item
19276If @value{GDBN} produces an error message for valid input, that is a
19277bug. (Note that if you're cross debugging, the problem may also be
19278somewhere in the connection to the target.)
c4555f82 19279
8e04817f 19280@cindex invalid input
c4555f82 19281@item
8e04817f
AC
19282If @value{GDBN} does not produce an error message for invalid input,
19283that is a bug. However, you should note that your idea of
19284``invalid input'' might be our idea of ``an extension'' or ``support
19285for traditional practice''.
19286
19287@item
19288If you are an experienced user of debugging tools, your suggestions
19289for improvement of @value{GDBN} are welcome in any case.
c4555f82
SC
19290@end itemize
19291
8e04817f
AC
19292@node Bug Reporting
19293@section How to report bugs
19294@cindex bug reports
19295@cindex @value{GDBN} bugs, reporting
19296
19297A number of companies and individuals offer support for @sc{gnu} products.
19298If you obtained @value{GDBN} from a support organization, we recommend you
19299contact that organization first.
19300
19301You can find contact information for many support companies and
19302individuals in the file @file{etc/SERVICE} in the @sc{gnu} Emacs
19303distribution.
19304@c should add a web page ref...
19305
129188f6
AC
19306In any event, we also recommend that you submit bug reports for
19307@value{GDBN}. The prefered method is to submit them directly using
19308@uref{http://www.gnu.org/software/gdb/bugs/, @value{GDBN}'s Bugs web
19309page}. Alternatively, the @email{bug-gdb@@gnu.org, e-mail gateway} can
19310be used.
8e04817f
AC
19311
19312@strong{Do not send bug reports to @samp{info-gdb}, or to
19313@samp{help-gdb}, or to any newsgroups.} Most users of @value{GDBN} do
19314not want to receive bug reports. Those that do have arranged to receive
19315@samp{bug-gdb}.
19316
19317The mailing list @samp{bug-gdb} has a newsgroup @samp{gnu.gdb.bug} which
19318serves as a repeater. The mailing list and the newsgroup carry exactly
19319the same messages. Often people think of posting bug reports to the
19320newsgroup instead of mailing them. This appears to work, but it has one
19321problem which can be crucial: a newsgroup posting often lacks a mail
19322path back to the sender. Thus, if we need to ask for more information,
19323we may be unable to reach you. For this reason, it is better to send
19324bug reports to the mailing list.
c4555f82 19325
8e04817f
AC
19326The fundamental principle of reporting bugs usefully is this:
19327@strong{report all the facts}. If you are not sure whether to state a
19328fact or leave it out, state it!
c4555f82 19329
8e04817f
AC
19330Often people omit facts because they think they know what causes the
19331problem and assume that some details do not matter. Thus, you might
19332assume that the name of the variable you use in an example does not matter.
19333Well, probably it does not, but one cannot be sure. Perhaps the bug is a
19334stray memory reference which happens to fetch from the location where that
19335name is stored in memory; perhaps, if the name were different, the contents
19336of that location would fool the debugger into doing the right thing despite
19337the bug. Play it safe and give a specific, complete example. That is the
19338easiest thing for you to do, and the most helpful.
c4555f82 19339
8e04817f
AC
19340Keep in mind that the purpose of a bug report is to enable us to fix the
19341bug. It may be that the bug has been reported previously, but neither
19342you nor we can know that unless your bug report is complete and
19343self-contained.
c4555f82 19344
8e04817f
AC
19345Sometimes people give a few sketchy facts and ask, ``Does this ring a
19346bell?'' Those bug reports are useless, and we urge everyone to
19347@emph{refuse to respond to them} except to chide the sender to report
19348bugs properly.
19349
19350To enable us to fix the bug, you should include all these things:
c4555f82
SC
19351
19352@itemize @bullet
19353@item
8e04817f
AC
19354The version of @value{GDBN}. @value{GDBN} announces it if you start
19355with no arguments; you can also print it at any time using @code{show
19356version}.
c4555f82 19357
8e04817f
AC
19358Without this, we will not know whether there is any point in looking for
19359the bug in the current version of @value{GDBN}.
c4555f82
SC
19360
19361@item
8e04817f
AC
19362The type of machine you are using, and the operating system name and
19363version number.
c4555f82
SC
19364
19365@item
8e04817f
AC
19366What compiler (and its version) was used to compile @value{GDBN}---e.g.
19367``@value{GCC}--2.8.1''.
c4555f82
SC
19368
19369@item
8e04817f
AC
19370What compiler (and its version) was used to compile the program you are
19371debugging---e.g. ``@value{GCC}--2.8.1'', or ``HP92453-01 A.10.32.03 HP
19372C Compiler''. For GCC, you can say @code{gcc --version} to get this
19373information; for other compilers, see the documentation for those
19374compilers.
c4555f82 19375
8e04817f
AC
19376@item
19377The command arguments you gave the compiler to compile your example and
19378observe the bug. For example, did you use @samp{-O}? To guarantee
19379you will not omit something important, list them all. A copy of the
19380Makefile (or the output from make) is sufficient.
c4555f82 19381
8e04817f
AC
19382If we were to try to guess the arguments, we would probably guess wrong
19383and then we might not encounter the bug.
c4555f82 19384
8e04817f
AC
19385@item
19386A complete input script, and all necessary source files, that will
19387reproduce the bug.
c4555f82 19388
8e04817f
AC
19389@item
19390A description of what behavior you observe that you believe is
19391incorrect. For example, ``It gets a fatal signal.''
c4555f82 19392
8e04817f
AC
19393Of course, if the bug is that @value{GDBN} gets a fatal signal, then we
19394will certainly notice it. But if the bug is incorrect output, we might
19395not notice unless it is glaringly wrong. You might as well not give us
19396a chance to make a mistake.
c4555f82 19397
8e04817f
AC
19398Even if the problem you experience is a fatal signal, you should still
19399say so explicitly. Suppose something strange is going on, such as, your
19400copy of @value{GDBN} is out of synch, or you have encountered a bug in
19401the C library on your system. (This has happened!) Your copy might
19402crash and ours would not. If you told us to expect a crash, then when
19403ours fails to crash, we would know that the bug was not happening for
19404us. If you had not told us to expect a crash, then we would not be able
19405to draw any conclusion from our observations.
c4555f82 19406
e0c07bf0
MC
19407@pindex script
19408@cindex recording a session script
19409To collect all this information, you can use a session recording program
19410such as @command{script}, which is available on many Unix systems.
19411Just run your @value{GDBN} session inside @command{script} and then
19412include the @file{typescript} file with your bug report.
19413
19414Another way to record a @value{GDBN} session is to run @value{GDBN}
19415inside Emacs and then save the entire buffer to a file.
19416
8e04817f
AC
19417@item
19418If you wish to suggest changes to the @value{GDBN} source, send us context
19419diffs. If you even discuss something in the @value{GDBN} source, refer to
19420it by context, not by line number.
c4555f82 19421
8e04817f
AC
19422The line numbers in our development sources will not match those in your
19423sources. Your line numbers would convey no useful information to us.
c4555f82 19424
8e04817f 19425@end itemize
c4555f82 19426
8e04817f 19427Here are some things that are not necessary:
c4555f82 19428
8e04817f
AC
19429@itemize @bullet
19430@item
19431A description of the envelope of the bug.
c4555f82 19432
8e04817f
AC
19433Often people who encounter a bug spend a lot of time investigating
19434which changes to the input file will make the bug go away and which
19435changes will not affect it.
c4555f82 19436
8e04817f
AC
19437This is often time consuming and not very useful, because the way we
19438will find the bug is by running a single example under the debugger
19439with breakpoints, not by pure deduction from a series of examples.
19440We recommend that you save your time for something else.
c4555f82 19441
8e04817f
AC
19442Of course, if you can find a simpler example to report @emph{instead}
19443of the original one, that is a convenience for us. Errors in the
19444output will be easier to spot, running under the debugger will take
19445less time, and so on.
c4555f82 19446
8e04817f
AC
19447However, simplification is not vital; if you do not want to do this,
19448report the bug anyway and send us the entire test case you used.
c4555f82 19449
8e04817f
AC
19450@item
19451A patch for the bug.
c4555f82 19452
8e04817f
AC
19453A patch for the bug does help us if it is a good one. But do not omit
19454the necessary information, such as the test case, on the assumption that
19455a patch is all we need. We might see problems with your patch and decide
19456to fix the problem another way, or we might not understand it at all.
c4555f82 19457
8e04817f
AC
19458Sometimes with a program as complicated as @value{GDBN} it is very hard to
19459construct an example that will make the program follow a certain path
19460through the code. If you do not send us the example, we will not be able
19461to construct one, so we will not be able to verify that the bug is fixed.
c4555f82 19462
8e04817f
AC
19463And if we cannot understand what bug you are trying to fix, or why your
19464patch should be an improvement, we will not install it. A test case will
19465help us to understand.
c4555f82 19466
8e04817f
AC
19467@item
19468A guess about what the bug is or what it depends on.
c4555f82 19469
8e04817f
AC
19470Such guesses are usually wrong. Even we cannot guess right about such
19471things without first using the debugger to find the facts.
19472@end itemize
c4555f82 19473
8e04817f
AC
19474@c The readline documentation is distributed with the readline code
19475@c and consists of the two following files:
19476@c rluser.texinfo
19477@c inc-hist.texinfo
19478@c Use -I with makeinfo to point to the appropriate directory,
19479@c environment var TEXINPUTS with TeX.
19480@include rluser.texinfo
19481@include inc-hist.texinfo
c4555f82 19482
c4555f82 19483
8e04817f
AC
19484@node Formatting Documentation
19485@appendix Formatting Documentation
c4555f82 19486
8e04817f
AC
19487@cindex @value{GDBN} reference card
19488@cindex reference card
19489The @value{GDBN} 4 release includes an already-formatted reference card, ready
19490for printing with PostScript or Ghostscript, in the @file{gdb}
19491subdirectory of the main source directory@footnote{In
19492@file{gdb-@value{GDBVN}/gdb/refcard.ps} of the version @value{GDBVN}
19493release.}. If you can use PostScript or Ghostscript with your printer,
19494you can print the reference card immediately with @file{refcard.ps}.
c4555f82 19495
8e04817f
AC
19496The release also includes the source for the reference card. You
19497can format it, using @TeX{}, by typing:
c4555f82 19498
474c8240 19499@smallexample
8e04817f 19500make refcard.dvi
474c8240 19501@end smallexample
c4555f82 19502
8e04817f
AC
19503The @value{GDBN} reference card is designed to print in @dfn{landscape}
19504mode on US ``letter'' size paper;
19505that is, on a sheet 11 inches wide by 8.5 inches
19506high. You will need to specify this form of printing as an option to
19507your @sc{dvi} output program.
c4555f82 19508
8e04817f 19509@cindex documentation
c4555f82 19510
8e04817f
AC
19511All the documentation for @value{GDBN} comes as part of the machine-readable
19512distribution. The documentation is written in Texinfo format, which is
19513a documentation system that uses a single source file to produce both
19514on-line information and a printed manual. You can use one of the Info
19515formatting commands to create the on-line version of the documentation
19516and @TeX{} (or @code{texi2roff}) to typeset the printed version.
c4555f82 19517
8e04817f
AC
19518@value{GDBN} includes an already formatted copy of the on-line Info
19519version of this manual in the @file{gdb} subdirectory. The main Info
19520file is @file{gdb-@value{GDBVN}/gdb/gdb.info}, and it refers to
19521subordinate files matching @samp{gdb.info*} in the same directory. If
19522necessary, you can print out these files, or read them with any editor;
19523but they are easier to read using the @code{info} subsystem in @sc{gnu}
19524Emacs or the standalone @code{info} program, available as part of the
19525@sc{gnu} Texinfo distribution.
c4555f82 19526
8e04817f
AC
19527If you want to format these Info files yourself, you need one of the
19528Info formatting programs, such as @code{texinfo-format-buffer} or
19529@code{makeinfo}.
c4555f82 19530
8e04817f
AC
19531If you have @code{makeinfo} installed, and are in the top level
19532@value{GDBN} source directory (@file{gdb-@value{GDBVN}}, in the case of
19533version @value{GDBVN}), you can make the Info file by typing:
c4555f82 19534
474c8240 19535@smallexample
8e04817f
AC
19536cd gdb
19537make gdb.info
474c8240 19538@end smallexample
c4555f82 19539
8e04817f
AC
19540If you want to typeset and print copies of this manual, you need @TeX{},
19541a program to print its @sc{dvi} output files, and @file{texinfo.tex}, the
19542Texinfo definitions file.
c4555f82 19543
8e04817f
AC
19544@TeX{} is a typesetting program; it does not print files directly, but
19545produces output files called @sc{dvi} files. To print a typeset
19546document, you need a program to print @sc{dvi} files. If your system
19547has @TeX{} installed, chances are it has such a program. The precise
19548command to use depends on your system; @kbd{lpr -d} is common; another
19549(for PostScript devices) is @kbd{dvips}. The @sc{dvi} print command may
19550require a file name without any extension or a @samp{.dvi} extension.
c4555f82 19551
8e04817f
AC
19552@TeX{} also requires a macro definitions file called
19553@file{texinfo.tex}. This file tells @TeX{} how to typeset a document
19554written in Texinfo format. On its own, @TeX{} cannot either read or
19555typeset a Texinfo file. @file{texinfo.tex} is distributed with GDB
19556and is located in the @file{gdb-@var{version-number}/texinfo}
19557directory.
c4555f82 19558
8e04817f
AC
19559If you have @TeX{} and a @sc{dvi} printer program installed, you can
19560typeset and print this manual. First switch to the the @file{gdb}
19561subdirectory of the main source directory (for example, to
19562@file{gdb-@value{GDBVN}/gdb}) and type:
c4555f82 19563
474c8240 19564@smallexample
8e04817f 19565make gdb.dvi
474c8240 19566@end smallexample
c4555f82 19567
8e04817f 19568Then give @file{gdb.dvi} to your @sc{dvi} printing program.
c4555f82 19569
8e04817f
AC
19570@node Installing GDB
19571@appendix Installing @value{GDBN}
19572@cindex configuring @value{GDBN}
19573@cindex installation
94e91d6d 19574@cindex configuring @value{GDBN}, and source tree subdirectories
c4555f82 19575
8e04817f
AC
19576@value{GDBN} comes with a @code{configure} script that automates the process
19577of preparing @value{GDBN} for installation; you can then use @code{make} to
19578build the @code{gdb} program.
19579@iftex
19580@c irrelevant in info file; it's as current as the code it lives with.
19581@footnote{If you have a more recent version of @value{GDBN} than @value{GDBVN},
19582look at the @file{README} file in the sources; we may have improved the
19583installation procedures since publishing this manual.}
19584@end iftex
c4555f82 19585
8e04817f
AC
19586The @value{GDBN} distribution includes all the source code you need for
19587@value{GDBN} in a single directory, whose name is usually composed by
19588appending the version number to @samp{gdb}.
c4555f82 19589
8e04817f
AC
19590For example, the @value{GDBN} version @value{GDBVN} distribution is in the
19591@file{gdb-@value{GDBVN}} directory. That directory contains:
c4555f82 19592
8e04817f
AC
19593@table @code
19594@item gdb-@value{GDBVN}/configure @r{(and supporting files)}
19595script for configuring @value{GDBN} and all its supporting libraries
c4555f82 19596
8e04817f
AC
19597@item gdb-@value{GDBVN}/gdb
19598the source specific to @value{GDBN} itself
c4555f82 19599
8e04817f
AC
19600@item gdb-@value{GDBVN}/bfd
19601source for the Binary File Descriptor library
c906108c 19602
8e04817f
AC
19603@item gdb-@value{GDBVN}/include
19604@sc{gnu} include files
c906108c 19605
8e04817f
AC
19606@item gdb-@value{GDBVN}/libiberty
19607source for the @samp{-liberty} free software library
c906108c 19608
8e04817f
AC
19609@item gdb-@value{GDBVN}/opcodes
19610source for the library of opcode tables and disassemblers
c906108c 19611
8e04817f
AC
19612@item gdb-@value{GDBVN}/readline
19613source for the @sc{gnu} command-line interface
c906108c 19614
8e04817f
AC
19615@item gdb-@value{GDBVN}/glob
19616source for the @sc{gnu} filename pattern-matching subroutine
c906108c 19617
8e04817f
AC
19618@item gdb-@value{GDBVN}/mmalloc
19619source for the @sc{gnu} memory-mapped malloc package
19620@end table
c906108c 19621
8e04817f
AC
19622The simplest way to configure and build @value{GDBN} is to run @code{configure}
19623from the @file{gdb-@var{version-number}} source directory, which in
19624this example is the @file{gdb-@value{GDBVN}} directory.
c906108c 19625
8e04817f
AC
19626First switch to the @file{gdb-@var{version-number}} source directory
19627if you are not already in it; then run @code{configure}. Pass the
19628identifier for the platform on which @value{GDBN} will run as an
19629argument.
c906108c 19630
8e04817f 19631For example:
c906108c 19632
474c8240 19633@smallexample
8e04817f
AC
19634cd gdb-@value{GDBVN}
19635./configure @var{host}
19636make
474c8240 19637@end smallexample
c906108c 19638
8e04817f
AC
19639@noindent
19640where @var{host} is an identifier such as @samp{sun4} or
19641@samp{decstation}, that identifies the platform where @value{GDBN} will run.
19642(You can often leave off @var{host}; @code{configure} tries to guess the
19643correct value by examining your system.)
c906108c 19644
8e04817f
AC
19645Running @samp{configure @var{host}} and then running @code{make} builds the
19646@file{bfd}, @file{readline}, @file{mmalloc}, and @file{libiberty}
19647libraries, then @code{gdb} itself. The configured source files, and the
19648binaries, are left in the corresponding source directories.
c906108c 19649
8e04817f
AC
19650@need 750
19651@code{configure} is a Bourne-shell (@code{/bin/sh}) script; if your
19652system does not recognize this automatically when you run a different
19653shell, you may need to run @code{sh} on it explicitly:
c906108c 19654
474c8240 19655@smallexample
8e04817f 19656sh configure @var{host}
474c8240 19657@end smallexample
c906108c 19658
8e04817f
AC
19659If you run @code{configure} from a directory that contains source
19660directories for multiple libraries or programs, such as the
19661@file{gdb-@value{GDBVN}} source directory for version @value{GDBVN}, @code{configure}
19662creates configuration files for every directory level underneath (unless
19663you tell it not to, with the @samp{--norecursion} option).
19664
94e91d6d
MC
19665You should run the @code{configure} script from the top directory in the
19666source tree, the @file{gdb-@var{version-number}} directory. If you run
19667@code{configure} from one of the subdirectories, you will configure only
19668that subdirectory. That is usually not what you want. In particular,
19669if you run the first @code{configure} from the @file{gdb} subdirectory
19670of the @file{gdb-@var{version-number}} directory, you will omit the
19671configuration of @file{bfd}, @file{readline}, and other sibling
19672directories of the @file{gdb} subdirectory. This leads to build errors
19673about missing include files such as @file{bfd/bfd.h}.
c906108c 19674
8e04817f
AC
19675You can install @code{@value{GDBP}} anywhere; it has no hardwired paths.
19676However, you should make sure that the shell on your path (named by
19677the @samp{SHELL} environment variable) is publicly readable. Remember
19678that @value{GDBN} uses the shell to start your program---some systems refuse to
19679let @value{GDBN} debug child processes whose programs are not readable.
c906108c 19680
8e04817f
AC
19681@menu
19682* Separate Objdir:: Compiling @value{GDBN} in another directory
19683* Config Names:: Specifying names for hosts and targets
19684* Configure Options:: Summary of options for configure
19685@end menu
c906108c 19686
8e04817f
AC
19687@node Separate Objdir
19688@section Compiling @value{GDBN} in another directory
c906108c 19689
8e04817f
AC
19690If you want to run @value{GDBN} versions for several host or target machines,
19691you need a different @code{gdb} compiled for each combination of
19692host and target. @code{configure} is designed to make this easy by
19693allowing you to generate each configuration in a separate subdirectory,
19694rather than in the source directory. If your @code{make} program
19695handles the @samp{VPATH} feature (@sc{gnu} @code{make} does), running
19696@code{make} in each of these directories builds the @code{gdb}
19697program specified there.
c906108c 19698
8e04817f
AC
19699To build @code{gdb} in a separate directory, run @code{configure}
19700with the @samp{--srcdir} option to specify where to find the source.
19701(You also need to specify a path to find @code{configure}
19702itself from your working directory. If the path to @code{configure}
19703would be the same as the argument to @samp{--srcdir}, you can leave out
19704the @samp{--srcdir} option; it is assumed.)
c906108c 19705
8e04817f
AC
19706For example, with version @value{GDBVN}, you can build @value{GDBN} in a
19707separate directory for a Sun 4 like this:
c906108c 19708
474c8240 19709@smallexample
8e04817f
AC
19710@group
19711cd gdb-@value{GDBVN}
19712mkdir ../gdb-sun4
19713cd ../gdb-sun4
19714../gdb-@value{GDBVN}/configure sun4
19715make
19716@end group
474c8240 19717@end smallexample
c906108c 19718
8e04817f
AC
19719When @code{configure} builds a configuration using a remote source
19720directory, it creates a tree for the binaries with the same structure
19721(and using the same names) as the tree under the source directory. In
19722the example, you'd find the Sun 4 library @file{libiberty.a} in the
19723directory @file{gdb-sun4/libiberty}, and @value{GDBN} itself in
19724@file{gdb-sun4/gdb}.
c906108c 19725
94e91d6d
MC
19726Make sure that your path to the @file{configure} script has just one
19727instance of @file{gdb} in it. If your path to @file{configure} looks
19728like @file{../gdb-@value{GDBVN}/gdb/configure}, you are configuring only
19729one subdirectory of @value{GDBN}, not the whole package. This leads to
19730build errors about missing include files such as @file{bfd/bfd.h}.
19731
8e04817f
AC
19732One popular reason to build several @value{GDBN} configurations in separate
19733directories is to configure @value{GDBN} for cross-compiling (where
19734@value{GDBN} runs on one machine---the @dfn{host}---while debugging
19735programs that run on another machine---the @dfn{target}).
19736You specify a cross-debugging target by
19737giving the @samp{--target=@var{target}} option to @code{configure}.
c906108c 19738
8e04817f
AC
19739When you run @code{make} to build a program or library, you must run
19740it in a configured directory---whatever directory you were in when you
19741called @code{configure} (or one of its subdirectories).
c906108c 19742
8e04817f
AC
19743The @code{Makefile} that @code{configure} generates in each source
19744directory also runs recursively. If you type @code{make} in a source
19745directory such as @file{gdb-@value{GDBVN}} (or in a separate configured
19746directory configured with @samp{--srcdir=@var{dirname}/gdb-@value{GDBVN}}), you
19747will build all the required libraries, and then build GDB.
c906108c 19748
8e04817f
AC
19749When you have multiple hosts or targets configured in separate
19750directories, you can run @code{make} on them in parallel (for example,
19751if they are NFS-mounted on each of the hosts); they will not interfere
19752with each other.
c906108c 19753
8e04817f
AC
19754@node Config Names
19755@section Specifying names for hosts and targets
c906108c 19756
8e04817f
AC
19757The specifications used for hosts and targets in the @code{configure}
19758script are based on a three-part naming scheme, but some short predefined
19759aliases are also supported. The full naming scheme encodes three pieces
19760of information in the following pattern:
c906108c 19761
474c8240 19762@smallexample
8e04817f 19763@var{architecture}-@var{vendor}-@var{os}
474c8240 19764@end smallexample
c906108c 19765
8e04817f
AC
19766For example, you can use the alias @code{sun4} as a @var{host} argument,
19767or as the value for @var{target} in a @code{--target=@var{target}}
19768option. The equivalent full name is @samp{sparc-sun-sunos4}.
c906108c 19769
8e04817f
AC
19770The @code{configure} script accompanying @value{GDBN} does not provide
19771any query facility to list all supported host and target names or
19772aliases. @code{configure} calls the Bourne shell script
19773@code{config.sub} to map abbreviations to full names; you can read the
19774script, if you wish, or you can use it to test your guesses on
19775abbreviations---for example:
c906108c 19776
8e04817f
AC
19777@smallexample
19778% sh config.sub i386-linux
19779i386-pc-linux-gnu
19780% sh config.sub alpha-linux
19781alpha-unknown-linux-gnu
19782% sh config.sub hp9k700
19783hppa1.1-hp-hpux
19784% sh config.sub sun4
19785sparc-sun-sunos4.1.1
19786% sh config.sub sun3
19787m68k-sun-sunos4.1.1
19788% sh config.sub i986v
19789Invalid configuration `i986v': machine `i986v' not recognized
19790@end smallexample
c906108c 19791
8e04817f
AC
19792@noindent
19793@code{config.sub} is also distributed in the @value{GDBN} source
19794directory (@file{gdb-@value{GDBVN}}, for version @value{GDBVN}).
d700128c 19795
8e04817f
AC
19796@node Configure Options
19797@section @code{configure} options
c906108c 19798
8e04817f
AC
19799Here is a summary of the @code{configure} options and arguments that
19800are most often useful for building @value{GDBN}. @code{configure} also has
19801several other options not listed here. @inforef{What Configure
19802Does,,configure.info}, for a full explanation of @code{configure}.
c906108c 19803
474c8240 19804@smallexample
8e04817f
AC
19805configure @r{[}--help@r{]}
19806 @r{[}--prefix=@var{dir}@r{]}
19807 @r{[}--exec-prefix=@var{dir}@r{]}
19808 @r{[}--srcdir=@var{dirname}@r{]}
19809 @r{[}--norecursion@r{]} @r{[}--rm@r{]}
19810 @r{[}--target=@var{target}@r{]}
19811 @var{host}
474c8240 19812@end smallexample
c906108c 19813
8e04817f
AC
19814@noindent
19815You may introduce options with a single @samp{-} rather than
19816@samp{--} if you prefer; but you may abbreviate option names if you use
19817@samp{--}.
c906108c 19818
8e04817f
AC
19819@table @code
19820@item --help
19821Display a quick summary of how to invoke @code{configure}.
c906108c 19822
8e04817f
AC
19823@item --prefix=@var{dir}
19824Configure the source to install programs and files under directory
19825@file{@var{dir}}.
c906108c 19826
8e04817f
AC
19827@item --exec-prefix=@var{dir}
19828Configure the source to install programs under directory
19829@file{@var{dir}}.
c906108c 19830
8e04817f
AC
19831@c avoid splitting the warning from the explanation:
19832@need 2000
19833@item --srcdir=@var{dirname}
19834@strong{Warning: using this option requires @sc{gnu} @code{make}, or another
19835@code{make} that implements the @code{VPATH} feature.}@*
19836Use this option to make configurations in directories separate from the
19837@value{GDBN} source directories. Among other things, you can use this to
19838build (or maintain) several configurations simultaneously, in separate
19839directories. @code{configure} writes configuration specific files in
19840the current directory, but arranges for them to use the source in the
19841directory @var{dirname}. @code{configure} creates directories under
19842the working directory in parallel to the source directories below
19843@var{dirname}.
c906108c 19844
8e04817f
AC
19845@item --norecursion
19846Configure only the directory level where @code{configure} is executed; do not
19847propagate configuration to subdirectories.
c906108c 19848
8e04817f
AC
19849@item --target=@var{target}
19850Configure @value{GDBN} for cross-debugging programs running on the specified
19851@var{target}. Without this option, @value{GDBN} is configured to debug
19852programs that run on the same machine (@var{host}) as @value{GDBN} itself.
c906108c 19853
8e04817f 19854There is no convenient way to generate a list of all available targets.
c906108c 19855
8e04817f
AC
19856@item @var{host} @dots{}
19857Configure @value{GDBN} to run on the specified @var{host}.
c906108c 19858
8e04817f
AC
19859There is no convenient way to generate a list of all available hosts.
19860@end table
c906108c 19861
8e04817f
AC
19862There are many other options available as well, but they are generally
19863needed for special purposes only.
c906108c 19864
8e04817f
AC
19865@node Maintenance Commands
19866@appendix Maintenance Commands
19867@cindex maintenance commands
19868@cindex internal commands
c906108c 19869
8e04817f
AC
19870In addition to commands intended for @value{GDBN} users, @value{GDBN}
19871includes a number of commands intended for @value{GDBN} developers.
19872These commands are provided here for reference.
c906108c 19873
8e04817f
AC
19874@table @code
19875@kindex maint info breakpoints
19876@item @anchor{maint info breakpoints}maint info breakpoints
19877Using the same format as @samp{info breakpoints}, display both the
19878breakpoints you've set explicitly, and those @value{GDBN} is using for
19879internal purposes. Internal breakpoints are shown with negative
19880breakpoint numbers. The type column identifies what kind of breakpoint
19881is shown:
c906108c 19882
8e04817f
AC
19883@table @code
19884@item breakpoint
19885Normal, explicitly set breakpoint.
c906108c 19886
8e04817f
AC
19887@item watchpoint
19888Normal, explicitly set watchpoint.
c906108c 19889
8e04817f
AC
19890@item longjmp
19891Internal breakpoint, used to handle correctly stepping through
19892@code{longjmp} calls.
c906108c 19893
8e04817f
AC
19894@item longjmp resume
19895Internal breakpoint at the target of a @code{longjmp}.
c906108c 19896
8e04817f
AC
19897@item until
19898Temporary internal breakpoint used by the @value{GDBN} @code{until} command.
c906108c 19899
8e04817f
AC
19900@item finish
19901Temporary internal breakpoint used by the @value{GDBN} @code{finish} command.
c906108c 19902
8e04817f
AC
19903@item shlib events
19904Shared library events.
c906108c 19905
8e04817f 19906@end table
c906108c 19907
8d30a00d
AC
19908@kindex maint internal-error
19909@kindex maint internal-warning
19910@item maint internal-error
19911@itemx maint internal-warning
19912Cause @value{GDBN} to call the internal function @code{internal_error}
19913or @code{internal_warning} and hence behave as though an internal error
19914or internal warning has been detected. In addition to reporting the
19915internal problem, these functions give the user the opportunity to
19916either quit @value{GDBN} or create a core file of the current
19917@value{GDBN} session.
19918
19919@smallexample
f7dc1244 19920(@value{GDBP}) @kbd{maint internal-error testing, 1, 2}
8d30a00d
AC
19921@dots{}/maint.c:121: internal-error: testing, 1, 2
19922A problem internal to GDB has been detected. Further
19923debugging may prove unreliable.
19924Quit this debugging session? (y or n) @kbd{n}
19925Create a core file? (y or n) @kbd{n}
f7dc1244 19926(@value{GDBP})
8d30a00d
AC
19927@end smallexample
19928
19929Takes an optional parameter that is used as the text of the error or
19930warning message.
19931
00905d52
AC
19932@kindex maint print dummy-frames
19933@item maint print dummy-frames
19934
19935Prints the contents of @value{GDBN}'s internal dummy-frame stack.
19936
19937@smallexample
f7dc1244 19938(@value{GDBP}) @kbd{b add}
00905d52 19939@dots{}
f7dc1244 19940(@value{GDBP}) @kbd{print add(2,3)}
00905d52
AC
19941Breakpoint 2, add (a=2, b=3) at @dots{}
1994258 return (a + b);
19943The program being debugged stopped while in a function called from GDB.
19944@dots{}
f7dc1244 19945(@value{GDBP}) @kbd{maint print dummy-frames}
00905d52
AC
199460x1a57c80: pc=0x01014068 fp=0x0200bddc sp=0x0200bdd6
19947 top=0x0200bdd4 id=@{stack=0x200bddc,code=0x101405c@}
19948 call_lo=0x01014000 call_hi=0x01014001
f7dc1244 19949(@value{GDBP})
00905d52
AC
19950@end smallexample
19951
19952Takes an optional file parameter.
19953
0680b120
AC
19954@kindex maint print registers
19955@kindex maint print raw-registers
19956@kindex maint print cooked-registers
617073a9 19957@kindex maint print register-groups
0680b120
AC
19958@item maint print registers
19959@itemx maint print raw-registers
19960@itemx maint print cooked-registers
617073a9 19961@itemx maint print register-groups
0680b120
AC
19962Print @value{GDBN}'s internal register data structures.
19963
617073a9
AC
19964The command @code{maint print raw-registers} includes the contents of
19965the raw register cache; the command @code{maint print cooked-registers}
19966includes the (cooked) value of all registers; and the command
19967@code{maint print register-groups} includes the groups that each
19968register is a member of. @xref{Registers,, Registers, gdbint,
19969@value{GDBN} Internals}.
0680b120
AC
19970
19971Takes an optional file parameter.
19972
617073a9
AC
19973@kindex maint print reggroups
19974@item maint print reggroups
19975Print @value{GDBN}'s internal register group data structures.
19976
19977Takes an optional file parameter.
19978
19979@smallexample
f7dc1244 19980(@value{GDBP}) @kbd{maint print reggroups}
b383017d
RM
19981 Group Type
19982 general user
19983 float user
19984 all user
19985 vector user
19986 system user
19987 save internal
19988 restore internal
617073a9
AC
19989@end smallexample
19990
e7ba9c65
DJ
19991@kindex maint set profile
19992@kindex maint show profile
19993@cindex profiling GDB
19994@item maint set profile
19995@itemx maint show profile
19996Control profiling of @value{GDBN}.
19997
19998Profiling will be disabled until you use the @samp{maint set profile}
19999command to enable it. When you enable profiling, the system will begin
20000collecting timing and execution count data; when you disable profiling or
20001exit @value{GDBN}, the results will be written to a log file. Remember that
20002if you use profiling, @value{GDBN} will overwrite the profiling log file
20003(often called @file{gmon.out}). If you have a record of important profiling
20004data in a @file{gmon.out} file, be sure to move it to a safe location.
20005
20006Configuring with @samp{--enable-profiling} arranges for @value{GDBN} to be
b383017d 20007compiled with the @samp{-pg} compiler option.
e7ba9c65 20008
ae038cb0
DJ
20009@kindex maint set dwarf2 max-cache-age
20010@kindex maint show dwarf2 max-cache-age
20011@item maint set dwarf2 max-cache-age
20012@itemx maint show dwarf2 max-cache-age
20013Control the DWARF 2 compilation unit cache.
20014
20015In object files with inter-compilation-unit references, such as those
20016produced by the GCC option @samp{-feliminate-dwarf2-dups}, the DWARF 2
20017reader needs to frequently refer to previously read compilation units.
20018This setting controls how long a compilation unit will remain in the cache
20019if it is not referenced. Setting it to zero disables caching, which will
20020slow down @value{GDBN} startup but reduce memory consumption.
20021
8e04817f 20022@end table
c906108c 20023
c906108c 20024
e0ce93ac 20025@node Remote Protocol
8e04817f 20026@appendix @value{GDBN} Remote Serial Protocol
c906108c 20027
ee2d5c50
AC
20028@menu
20029* Overview::
20030* Packets::
20031* Stop Reply Packets::
20032* General Query Packets::
20033* Register Packet Format::
20034* Examples::
0ce1b118 20035* File-I/O remote protocol extension::
ee2d5c50
AC
20036@end menu
20037
20038@node Overview
20039@section Overview
20040
8e04817f
AC
20041There may be occasions when you need to know something about the
20042protocol---for example, if there is only one serial port to your target
20043machine, you might want your program to do something special if it
20044recognizes a packet meant for @value{GDBN}.
c906108c 20045
d2c6833e 20046In the examples below, @samp{->} and @samp{<-} are used to indicate
8e04817f 20047transmitted and received data respectfully.
c906108c 20048
8e04817f
AC
20049@cindex protocol, @value{GDBN} remote serial
20050@cindex serial protocol, @value{GDBN} remote
20051@cindex remote serial protocol
20052All @value{GDBN} commands and responses (other than acknowledgments) are
20053sent as a @var{packet}. A @var{packet} is introduced with the character
20054@samp{$}, the actual @var{packet-data}, and the terminating character
20055@samp{#} followed by a two-digit @var{checksum}:
c906108c 20056
474c8240 20057@smallexample
8e04817f 20058@code{$}@var{packet-data}@code{#}@var{checksum}
474c8240 20059@end smallexample
8e04817f 20060@noindent
c906108c 20061
8e04817f
AC
20062@cindex checksum, for @value{GDBN} remote
20063@noindent
20064The two-digit @var{checksum} is computed as the modulo 256 sum of all
20065characters between the leading @samp{$} and the trailing @samp{#} (an
20066eight bit unsigned checksum).
c906108c 20067
8e04817f
AC
20068Implementors should note that prior to @value{GDBN} 5.0 the protocol
20069specification also included an optional two-digit @var{sequence-id}:
c906108c 20070
474c8240 20071@smallexample
8e04817f 20072@code{$}@var{sequence-id}@code{:}@var{packet-data}@code{#}@var{checksum}
474c8240 20073@end smallexample
c906108c 20074
8e04817f
AC
20075@cindex sequence-id, for @value{GDBN} remote
20076@noindent
20077That @var{sequence-id} was appended to the acknowledgment. @value{GDBN}
20078has never output @var{sequence-id}s. Stubs that handle packets added
20079since @value{GDBN} 5.0 must not accept @var{sequence-id}.
c906108c 20080
8e04817f
AC
20081@cindex acknowledgment, for @value{GDBN} remote
20082When either the host or the target machine receives a packet, the first
20083response expected is an acknowledgment: either @samp{+} (to indicate
20084the package was received correctly) or @samp{-} (to request
20085retransmission):
c906108c 20086
474c8240 20087@smallexample
d2c6833e
AC
20088-> @code{$}@var{packet-data}@code{#}@var{checksum}
20089<- @code{+}
474c8240 20090@end smallexample
8e04817f 20091@noindent
53a5351d 20092
8e04817f
AC
20093The host (@value{GDBN}) sends @var{command}s, and the target (the
20094debugging stub incorporated in your program) sends a @var{response}. In
20095the case of step and continue @var{command}s, the response is only sent
20096when the operation has completed (the target has again stopped).
c906108c 20097
8e04817f
AC
20098@var{packet-data} consists of a sequence of characters with the
20099exception of @samp{#} and @samp{$} (see @samp{X} packet for additional
20100exceptions).
c906108c 20101
8e04817f 20102Fields within the packet should be separated using @samp{,} @samp{;} or
ee2d5c50 20103@cindex remote protocol, field separator
8e04817f 20104@samp{:}. Except where otherwise noted all numbers are represented in
ee2d5c50 20105@sc{hex} with leading zeros suppressed.
c906108c 20106
8e04817f
AC
20107Implementors should note that prior to @value{GDBN} 5.0, the character
20108@samp{:} could not appear as the third character in a packet (as it
20109would potentially conflict with the @var{sequence-id}).
c906108c 20110
8e04817f
AC
20111Response @var{data} can be run-length encoded to save space. A @samp{*}
20112means that the next character is an @sc{ascii} encoding giving a repeat count
20113which stands for that many repetitions of the character preceding the
20114@samp{*}. The encoding is @code{n+29}, yielding a printable character
20115where @code{n >=3} (which is where rle starts to win). The printable
20116characters @samp{$}, @samp{#}, @samp{+} and @samp{-} or with a numeric
20117value greater than 126 should not be used.
c906108c 20118
8e04817f 20119So:
474c8240 20120@smallexample
8e04817f 20121"@code{0* }"
474c8240 20122@end smallexample
8e04817f
AC
20123@noindent
20124means the same as "0000".
c906108c 20125
8e04817f
AC
20126The error response returned for some packets includes a two character
20127error number. That number is not well defined.
c906108c 20128
8e04817f
AC
20129For any @var{command} not supported by the stub, an empty response
20130(@samp{$#00}) should be returned. That way it is possible to extend the
20131protocol. A newer @value{GDBN} can tell if a packet is supported based
20132on that response.
c906108c 20133
b383017d
RM
20134A stub is required to support the @samp{g}, @samp{G}, @samp{m}, @samp{M},
20135@samp{c}, and @samp{s} @var{command}s. All other @var{command}s are
8e04817f 20136optional.
c906108c 20137
ee2d5c50
AC
20138@node Packets
20139@section Packets
20140
20141The following table provides a complete list of all currently defined
20142@var{command}s and their corresponding response @var{data}.
20143
20144@table @r
20145
20146@item @code{!} --- extended mode
20147@cindex @code{!} packet
20148
8e04817f
AC
20149Enable extended mode. In extended mode, the remote server is made
20150persistent. The @samp{R} packet is used to restart the program being
20151debugged.
ee2d5c50
AC
20152
20153Reply:
20154@table @samp
20155@item OK
8e04817f 20156The remote target both supports and has enabled extended mode.
ee2d5c50 20157@end table
c906108c 20158
ee2d5c50
AC
20159@item @code{?} --- last signal
20160@cindex @code{?} packet
c906108c 20161
ee2d5c50
AC
20162Indicate the reason the target halted. The reply is the same as for
20163step and continue.
c906108c 20164
ee2d5c50
AC
20165Reply:
20166@xref{Stop Reply Packets}, for the reply specifications.
20167
20168@item @code{a} --- reserved
20169
20170Reserved for future use.
20171
20172@item @code{A}@var{arglen}@code{,}@var{argnum}@code{,}@var{arg}@code{,@dots{}} --- set program arguments @strong{(reserved)}
20173@cindex @code{A} packet
c906108c 20174
8e04817f
AC
20175Initialized @samp{argv[]} array passed into program. @var{arglen}
20176specifies the number of bytes in the hex encoded byte stream @var{arg}.
ee2d5c50
AC
20177See @code{gdbserver} for more details.
20178
20179Reply:
20180@table @samp
20181@item OK
20182@item E@var{NN}
20183@end table
20184
20185@item @code{b}@var{baud} --- set baud @strong{(deprecated)}
20186@cindex @code{b} packet
20187
20188Change the serial line speed to @var{baud}.
20189
20190JTC: @emph{When does the transport layer state change? When it's
20191received, or after the ACK is transmitted. In either case, there are
20192problems if the command or the acknowledgment packet is dropped.}
20193
20194Stan: @emph{If people really wanted to add something like this, and get
20195it working for the first time, they ought to modify ser-unix.c to send
20196some kind of out-of-band message to a specially-setup stub and have the
20197switch happen "in between" packets, so that from remote protocol's point
20198of view, nothing actually happened.}
20199
20200@item @code{B}@var{addr},@var{mode} --- set breakpoint @strong{(deprecated)}
20201@cindex @code{B} packet
20202
8e04817f 20203Set (@var{mode} is @samp{S}) or clear (@var{mode} is @samp{C}) a
2f870471
AC
20204breakpoint at @var{addr}.
20205
20206This packet has been replaced by the @samp{Z} and @samp{z} packets
20207(@pxref{insert breakpoint or watchpoint packet}).
c906108c 20208
ee2d5c50
AC
20209@item @code{c}@var{addr} --- continue
20210@cindex @code{c} packet
20211
20212@var{addr} is address to resume. If @var{addr} is omitted, resume at
8e04817f 20213current address.
c906108c 20214
ee2d5c50
AC
20215Reply:
20216@xref{Stop Reply Packets}, for the reply specifications.
20217
20218@item @code{C}@var{sig}@code{;}@var{addr} --- continue with signal
20219@cindex @code{C} packet
20220
8e04817f
AC
20221Continue with signal @var{sig} (hex signal number). If
20222@code{;}@var{addr} is omitted, resume at same address.
c906108c 20223
ee2d5c50
AC
20224Reply:
20225@xref{Stop Reply Packets}, for the reply specifications.
c906108c 20226
ee2d5c50
AC
20227@item @code{d} --- toggle debug @strong{(deprecated)}
20228@cindex @code{d} packet
20229
20230Toggle debug flag.
20231
20232@item @code{D} --- detach
20233@cindex @code{D} packet
20234
20235Detach @value{GDBN} from the remote system. Sent to the remote target
07f31aa6 20236before @value{GDBN} disconnects via the @code{detach} command.
ee2d5c50
AC
20237
20238Reply:
20239@table @samp
20240@item @emph{no response}
8e04817f 20241@value{GDBN} does not check for any response after sending this packet.
ee2d5c50 20242@end table
c906108c 20243
ee2d5c50 20244@item @code{e} --- reserved
c906108c 20245
ee2d5c50 20246Reserved for future use.
c906108c 20247
ee2d5c50 20248@item @code{E} --- reserved
c906108c 20249
ee2d5c50 20250Reserved for future use.
c906108c 20251
ee2d5c50
AC
20252@item @code{f} --- reserved
20253
20254Reserved for future use.
20255
0ce1b118
CV
20256@item @code{F}@var{RC}@code{,}@var{EE}@code{,}@var{CF}@code{;}@var{XX} --- Reply to target's F packet.
20257@cindex @code{F} packet
ee2d5c50 20258
0ce1b118
CV
20259This packet is send by @value{GDBN} as reply to a @code{F} request packet
20260sent by the target. This is part of the File-I/O protocol extension.
20261@xref{File-I/O remote protocol extension}, for the specification.
ee2d5c50
AC
20262
20263@item @code{g} --- read registers
20264@anchor{read registers packet}
20265@cindex @code{g} packet
20266
20267Read general registers.
20268
20269Reply:
20270@table @samp
20271@item @var{XX@dots{}}
8e04817f
AC
20272Each byte of register data is described by two hex digits. The bytes
20273with the register are transmitted in target byte order. The size of
20274each register and their position within the @samp{g} @var{packet} are
12c266ea
AC
20275determined by the @value{GDBN} internal macros
20276@var{DEPRECATED_REGISTER_RAW_SIZE} and @var{REGISTER_NAME} macros. The
20277specification of several standard @code{g} packets is specified below.
ee2d5c50
AC
20278@item E@var{NN}
20279for an error.
20280@end table
c906108c 20281
ee2d5c50
AC
20282@item @code{G}@var{XX@dots{}} --- write regs
20283@cindex @code{G} packet
c906108c 20284
ee2d5c50
AC
20285@xref{read registers packet}, for a description of the @var{XX@dots{}}
20286data.
20287
20288Reply:
20289@table @samp
20290@item OK
20291for success
20292@item E@var{NN}
20293for an error
20294@end table
20295
20296@item @code{h} --- reserved
20297
20298Reserved for future use.
20299
b383017d 20300@item @code{H}@var{c}@var{t@dots{}} --- set thread
ee2d5c50 20301@cindex @code{H} packet
c906108c 20302
8e04817f 20303Set thread for subsequent operations (@samp{m}, @samp{M}, @samp{g},
ee2d5c50
AC
20304@samp{G}, et.al.). @var{c} depends on the operation to be performed: it
20305should be @samp{c} for step and continue operations, @samp{g} for other
20306operations. The thread designator @var{t@dots{}} may be -1, meaning all
20307the threads, a thread number, or zero which means pick any thread.
20308
20309Reply:
20310@table @samp
20311@item OK
20312for success
20313@item E@var{NN}
20314for an error
20315@end table
c906108c 20316
8e04817f
AC
20317@c FIXME: JTC:
20318@c 'H': How restrictive (or permissive) is the thread model. If a
20319@c thread is selected and stopped, are other threads allowed
20320@c to continue to execute? As I mentioned above, I think the
20321@c semantics of each command when a thread is selected must be
20322@c described. For example:
20323@c
20324@c 'g': If the stub supports threads and a specific thread is
20325@c selected, returns the register block from that thread;
20326@c otherwise returns current registers.
20327@c
20328@c 'G' If the stub supports threads and a specific thread is
20329@c selected, sets the registers of the register block of
20330@c that thread; otherwise sets current registers.
c906108c 20331
ee2d5c50
AC
20332@item @code{i}@var{addr}@code{,}@var{nnn} --- cycle step @strong{(draft)}
20333@anchor{cycle step packet}
20334@cindex @code{i} packet
20335
8e04817f
AC
20336Step the remote target by a single clock cycle. If @code{,}@var{nnn} is
20337present, cycle step @var{nnn} cycles. If @var{addr} is present, cycle
20338step starting at that address.
c906108c 20339
ee2d5c50
AC
20340@item @code{I} --- signal then cycle step @strong{(reserved)}
20341@cindex @code{I} packet
20342
20343@xref{step with signal packet}. @xref{cycle step packet}.
20344
20345@item @code{j} --- reserved
20346
20347Reserved for future use.
20348
20349@item @code{J} --- reserved
c906108c 20350
ee2d5c50 20351Reserved for future use.
c906108c 20352
ee2d5c50
AC
20353@item @code{k} --- kill request
20354@cindex @code{k} packet
c906108c 20355
ac282366 20356FIXME: @emph{There is no description of how to operate when a specific
ee2d5c50
AC
20357thread context has been selected (i.e.@: does 'k' kill only that
20358thread?)}.
c906108c 20359
ee2d5c50 20360@item @code{K} --- reserved
c906108c 20361
ee2d5c50
AC
20362Reserved for future use.
20363
20364@item @code{l} --- reserved
20365
20366Reserved for future use.
20367
20368@item @code{L} --- reserved
20369
20370Reserved for future use.
20371
20372@item @code{m}@var{addr}@code{,}@var{length} --- read memory
20373@cindex @code{m} packet
c906108c 20374
8e04817f 20375Read @var{length} bytes of memory starting at address @var{addr}.
ee2d5c50 20376Neither @value{GDBN} nor the stub assume that sized memory transfers are
2e834e49 20377assumed using word aligned accesses. FIXME: @emph{A word aligned memory
8e04817f 20378transfer mechanism is needed.}
c906108c 20379
ee2d5c50
AC
20380Reply:
20381@table @samp
20382@item @var{XX@dots{}}
20383@var{XX@dots{}} is mem contents. Can be fewer bytes than requested if able
20384to read only part of the data. Neither @value{GDBN} nor the stub assume
2e834e49 20385that sized memory transfers are assumed using word aligned
ee2d5c50
AC
20386accesses. FIXME: @emph{A word aligned memory transfer mechanism is
20387needed.}
20388@item E@var{NN}
20389@var{NN} is errno
20390@end table
20391
20392@item @code{M}@var{addr},@var{length}@code{:}@var{XX@dots{}} --- write mem
20393@cindex @code{M} packet
20394
8e04817f 20395Write @var{length} bytes of memory starting at address @var{addr}.
ee2d5c50
AC
20396@var{XX@dots{}} is the data.
20397
20398Reply:
20399@table @samp
20400@item OK
20401for success
20402@item E@var{NN}
8e04817f
AC
20403for an error (this includes the case where only part of the data was
20404written).
ee2d5c50 20405@end table
c906108c 20406
ee2d5c50 20407@item @code{n} --- reserved
c906108c 20408
ee2d5c50 20409Reserved for future use.
c906108c 20410
ee2d5c50 20411@item @code{N} --- reserved
c906108c 20412
ee2d5c50 20413Reserved for future use.
c906108c 20414
ee2d5c50
AC
20415@item @code{o} --- reserved
20416
20417Reserved for future use.
20418
20419@item @code{O} --- reserved
20420
2e868123 20421@item @code{p}@var{hex number of register} --- read register packet
ee2d5c50
AC
20422@cindex @code{p} packet
20423
2e868123
AC
20424@xref{read registers packet}, for a description of how the returned
20425register value is encoded.
ee2d5c50
AC
20426
20427Reply:
20428@table @samp
2e868123
AC
20429@item @var{XX@dots{}}
20430the register's value
20431@item E@var{NN}
20432for an error
20433@item
20434Indicating an unrecognized @var{query}.
ee2d5c50
AC
20435@end table
20436
20437@item @code{P}@var{n@dots{}}@code{=}@var{r@dots{}} --- write register
20438@anchor{write register packet}
20439@cindex @code{P} packet
20440
20441Write register @var{n@dots{}} with value @var{r@dots{}}, which contains two hex
8e04817f 20442digits for each byte in the register (target byte order).
c906108c 20443
ee2d5c50
AC
20444Reply:
20445@table @samp
20446@item OK
20447for success
20448@item E@var{NN}
20449for an error
20450@end table
20451
20452@item @code{q}@var{query} --- general query
20453@anchor{general query packet}
20454@cindex @code{q} packet
20455
20456Request info about @var{query}. In general @value{GDBN} queries have a
20457leading upper case letter. Custom vendor queries should use a company
20458prefix (in lower case) ex: @samp{qfsf.var}. @var{query} may optionally
20459be followed by a @samp{,} or @samp{;} separated list. Stubs must ensure
20460that they match the full @var{query} name.
20461
20462Reply:
20463@table @samp
20464@item @var{XX@dots{}}
20465Hex encoded data from query. The reply can not be empty.
20466@item E@var{NN}
20467error reply
8e04817f 20468@item
ee2d5c50
AC
20469Indicating an unrecognized @var{query}.
20470@end table
20471
20472@item @code{Q}@var{var}@code{=}@var{val} --- general set
20473@cindex @code{Q} packet
20474
20475Set value of @var{var} to @var{val}.
20476
20477@xref{general query packet}, for a discussion of naming conventions.
c906108c 20478
ee2d5c50
AC
20479@item @code{r} --- reset @strong{(deprecated)}
20480@cindex @code{r} packet
c906108c 20481
8e04817f 20482Reset the entire system.
c906108c 20483
ee2d5c50
AC
20484@item @code{R}@var{XX} --- remote restart
20485@cindex @code{R} packet
20486
8e04817f
AC
20487Restart the program being debugged. @var{XX}, while needed, is ignored.
20488This packet is only available in extended mode.
ee2d5c50
AC
20489
20490Reply:
20491@table @samp
20492@item @emph{no reply}
8e04817f 20493The @samp{R} packet has no reply.
ee2d5c50
AC
20494@end table
20495
20496@item @code{s}@var{addr} --- step
20497@cindex @code{s} packet
c906108c 20498
8e04817f
AC
20499@var{addr} is address to resume. If @var{addr} is omitted, resume at
20500same address.
c906108c 20501
ee2d5c50
AC
20502Reply:
20503@xref{Stop Reply Packets}, for the reply specifications.
20504
20505@item @code{S}@var{sig}@code{;}@var{addr} --- step with signal
20506@anchor{step with signal packet}
20507@cindex @code{S} packet
20508
8e04817f 20509Like @samp{C} but step not continue.
c906108c 20510
ee2d5c50
AC
20511Reply:
20512@xref{Stop Reply Packets}, for the reply specifications.
20513
b383017d 20514@item @code{t}@var{addr}@code{:}@var{PP}@code{,}@var{MM} --- search
ee2d5c50
AC
20515@cindex @code{t} packet
20516
8e04817f 20517Search backwards starting at address @var{addr} for a match with pattern
ee2d5c50
AC
20518@var{PP} and mask @var{MM}. @var{PP} and @var{MM} are 4 bytes.
20519@var{addr} must be at least 3 digits.
c906108c 20520
ee2d5c50
AC
20521@item @code{T}@var{XX} --- thread alive
20522@cindex @code{T} packet
c906108c 20523
ee2d5c50 20524Find out if the thread XX is alive.
c906108c 20525
ee2d5c50
AC
20526Reply:
20527@table @samp
20528@item OK
20529thread is still alive
20530@item E@var{NN}
20531thread is dead
20532@end table
20533
20534@item @code{u} --- reserved
20535
20536Reserved for future use.
20537
20538@item @code{U} --- reserved
20539
20540Reserved for future use.
20541
86d30acc 20542@item @code{v} --- verbose packet prefix
ee2d5c50 20543
86d30acc
DJ
20544Packets starting with @code{v} are identified by a multi-letter name,
20545up to the first @code{;} or @code{?} (or the end of the packet).
20546
20547@item @code{vCont}[;@var{action}[@code{:}@var{tid}]]... --- extended resume
20548@cindex @code{vCont} packet
20549
20550Resume the inferior. Different actions may be specified for each thread.
20551If an action is specified with no @var{tid}, then it is applied to any
20552threads that don't have a specific action specified; if no default action is
20553specified then other threads should remain stopped. Specifying multiple
20554default actions is an error; specifying no actions is also an error.
20555Thread IDs are specified in hexadecimal. Currently supported actions are:
20556
20557@table @code
20558@item c
20559Continue.
20560@item C@var{sig}
20561Continue with signal @var{sig}. @var{sig} should be two hex digits.
20562@item s
20563Step.
20564@item S@var{sig}
20565Step with signal @var{sig}. @var{sig} should be two hex digits.
20566@end table
20567
20568The optional @var{addr} argument normally associated with these packets is
20569not supported in @code{vCont}.
20570
20571Reply:
20572@xref{Stop Reply Packets}, for the reply specifications.
20573
20574@item @code{vCont?} --- extended resume query
20575@cindex @code{vCont?} packet
20576
20577Query support for the @code{vCont} packet.
20578
20579Reply:
20580@table @samp
20581@item @code{vCont}[;@var{action}]...
20582The @code{vCont} packet is supported. Each @var{action} is a supported
20583command in the @code{vCont} packet.
20584@item
20585The @code{vCont} packet is not supported.
20586@end table
ee2d5c50
AC
20587
20588@item @code{V} --- reserved
c906108c 20589
ee2d5c50 20590Reserved for future use.
c906108c 20591
ee2d5c50 20592@item @code{w} --- reserved
c906108c 20593
ee2d5c50 20594Reserved for future use.
c906108c 20595
ee2d5c50 20596@item @code{W} --- reserved
c906108c 20597
ee2d5c50 20598Reserved for future use.
c906108c 20599
ee2d5c50
AC
20600@item @code{x} --- reserved
20601
20602Reserved for future use.
20603
20604@item @code{X}@var{addr}@code{,}@var{length}@var{:}@var{XX@dots{}} --- write mem (binary)
20605@cindex @code{X} packet
20606
20607@var{addr} is address, @var{length} is number of bytes, @var{XX@dots{}}
20608is binary data. The characters @code{$}, @code{#}, and @code{0x7d} are
69065f5d
AC
20609escaped using @code{0x7d}, and then XORed with @code{0x20}.
20610For example, @code{0x7d} would be transmitted as @code{0x7d 0x5d}.
c906108c 20611
ee2d5c50
AC
20612Reply:
20613@table @samp
20614@item OK
20615for success
20616@item E@var{NN}
20617for an error
20618@end table
20619
20620@item @code{y} --- reserved
c906108c 20621
ee2d5c50 20622Reserved for future use.
c906108c 20623
ee2d5c50
AC
20624@item @code{Y} reserved
20625
20626Reserved for future use.
20627
2f870471
AC
20628@item @code{z}@var{type}@code{,}@var{addr}@code{,}@var{length} --- remove breakpoint or watchpoint @strong{(draft)}
20629@itemx @code{Z}@var{type}@code{,}@var{addr}@code{,}@var{length} --- insert breakpoint or watchpoint @strong{(draft)}
20630@anchor{insert breakpoint or watchpoint packet}
ee2d5c50 20631@cindex @code{z} packet
2f870471 20632@cindex @code{Z} packets
ee2d5c50 20633
2f870471
AC
20634Insert (@code{Z}) or remove (@code{z}) a @var{type} breakpoint or
20635watchpoint starting at address @var{address} and covering the next
20636@var{length} bytes.
ee2d5c50 20637
2f870471
AC
20638Each breakpoint and watchpoint packet @var{type} is documented
20639separately.
20640
512217c7
AC
20641@emph{Implementation notes: A remote target shall return an empty string
20642for an unrecognized breakpoint or watchpoint packet @var{type}. A
20643remote target shall support either both or neither of a given
2f870471
AC
20644@code{Z}@var{type}@dots{} and @code{z}@var{type}@dots{} packet pair. To
20645avoid potential problems with duplicate packets, the operations should
20646be implemented in an idempotent way.}
20647
20648@item @code{z}@code{0}@code{,}@var{addr}@code{,}@var{length} --- remove memory breakpoint @strong{(draft)}
20649@item @code{Z}@code{0}@code{,}@var{addr}@code{,}@var{length} --- insert memory breakpoint @strong{(draft)}
20650@cindex @code{z0} packet
20651@cindex @code{Z0} packet
20652
20653Insert (@code{Z0}) or remove (@code{z0}) a memory breakpoint at address
20654@code{addr} of size @code{length}.
20655
20656A memory breakpoint is implemented by replacing the instruction at
20657@var{addr} with a software breakpoint or trap instruction. The
20658@code{length} is used by targets that indicates the size of the
20659breakpoint (in bytes) that should be inserted (e.g., the @sc{arm} and
20660@sc{mips} can insert either a 2 or 4 byte breakpoint).
c906108c 20661
2f870471
AC
20662@emph{Implementation note: It is possible for a target to copy or move
20663code that contains memory breakpoints (e.g., when implementing
20664overlays). The behavior of this packet, in the presence of such a
20665target, is not defined.}
c906108c 20666
ee2d5c50
AC
20667Reply:
20668@table @samp
2f870471
AC
20669@item OK
20670success
20671@item
20672not supported
ee2d5c50
AC
20673@item E@var{NN}
20674for an error
2f870471
AC
20675@end table
20676
20677@item @code{z}@code{1}@code{,}@var{addr}@code{,}@var{length} --- remove hardware breakpoint @strong{(draft)}
20678@item @code{Z}@code{1}@code{,}@var{addr}@code{,}@var{length} --- insert hardware breakpoint @strong{(draft)}
20679@cindex @code{z1} packet
20680@cindex @code{Z1} packet
20681
20682Insert (@code{Z1}) or remove (@code{z1}) a hardware breakpoint at
20683address @code{addr} of size @code{length}.
20684
20685A hardware breakpoint is implemented using a mechanism that is not
20686dependant on being able to modify the target's memory.
20687
20688@emph{Implementation note: A hardware breakpoint is not affected by code
20689movement.}
20690
20691Reply:
20692@table @samp
ee2d5c50 20693@item OK
2f870471
AC
20694success
20695@item
20696not supported
20697@item E@var{NN}
20698for an error
20699@end table
20700
20701@item @code{z}@code{2}@code{,}@var{addr}@code{,}@var{length} --- remove write watchpoint @strong{(draft)}
20702@item @code{Z}@code{2}@code{,}@var{addr}@code{,}@var{length} --- insert write watchpoint @strong{(draft)}
20703@cindex @code{z2} packet
20704@cindex @code{Z2} packet
20705
20706Insert (@code{Z2}) or remove (@code{z2}) a write watchpoint.
20707
20708Reply:
20709@table @samp
20710@item OK
20711success
20712@item
20713not supported
20714@item E@var{NN}
20715for an error
20716@end table
20717
20718@item @code{z}@code{3}@code{,}@var{addr}@code{,}@var{length} --- remove read watchpoint @strong{(draft)}
20719@item @code{Z}@code{3}@code{,}@var{addr}@code{,}@var{length} --- insert read watchpoint @strong{(draft)}
20720@cindex @code{z3} packet
20721@cindex @code{Z3} packet
20722
2e834e49 20723Insert (@code{Z3}) or remove (@code{z3}) a read watchpoint.
2f870471
AC
20724
20725Reply:
20726@table @samp
20727@item OK
20728success
20729@item
20730not supported
20731@item E@var{NN}
20732for an error
20733@end table
20734
2e834e49
HPN
20735@item @code{z}@code{4}@code{,}@var{addr}@code{,}@var{length} --- remove access watchpoint @strong{(draft)}
20736@item @code{Z}@code{4}@code{,}@var{addr}@code{,}@var{length} --- insert access watchpoint @strong{(draft)}
2f870471
AC
20737@cindex @code{z4} packet
20738@cindex @code{Z4} packet
20739
20740Insert (@code{Z4}) or remove (@code{z4}) an access watchpoint.
20741
20742Reply:
20743@table @samp
20744@item OK
20745success
20746@item
20747not supported
20748@item E@var{NN}
20749for an error
ee2d5c50
AC
20750@end table
20751
20752@end table
c906108c 20753
ee2d5c50
AC
20754@node Stop Reply Packets
20755@section Stop Reply Packets
20756@cindex stop reply packets
c906108c 20757
8e04817f
AC
20758The @samp{C}, @samp{c}, @samp{S}, @samp{s} and @samp{?} packets can
20759receive any of the below as a reply. In the case of the @samp{C},
20760@samp{c}, @samp{S} and @samp{s} packets, that reply is only returned
20761when the target halts. In the below the exact meaning of @samp{signal
20762number} is poorly defined. In general one of the UNIX signal numbering
20763conventions is used.
c906108c 20764
ee2d5c50 20765@table @samp
c906108c 20766
ee2d5c50
AC
20767@item S@var{AA}
20768@var{AA} is the signal number
c906108c 20769
8e04817f 20770@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
20771@cindex @code{T} packet reply
20772
8e04817f
AC
20773@var{AA} = two hex digit signal number; @var{n...} = register number
20774(hex), @var{r...} = target byte ordered register contents, size defined
12c266ea
AC
20775by @code{DEPRECATED_REGISTER_RAW_SIZE}; @var{n...} = @samp{thread},
20776@var{r...} = thread process ID, this is a hex integer; @var{n...} =
20777(@samp{watch} | @samp{rwatch} | @samp{awatch}, @var{r...} = data
20778address, this is a hex integer; @var{n...} = other string not starting
20779with valid hex digit. @value{GDBN} should ignore this @var{n...},
20780@var{r...} pair and go on to the next. This way we can extend the
20781protocol.
c906108c 20782
ee2d5c50
AC
20783@item W@var{AA}
20784
8e04817f 20785The process exited, and @var{AA} is the exit status. This is only
ee2d5c50
AC
20786applicable to certain targets.
20787
20788@item X@var{AA}
c906108c 20789
8e04817f 20790The process terminated with signal @var{AA}.
c906108c 20791
ee2d5c50 20792@item O@var{XX@dots{}}
c906108c 20793
ee2d5c50
AC
20794@var{XX@dots{}} is hex encoding of @sc{ascii} data. This can happen at
20795any time while the program is running and the debugger should continue
20796to wait for @samp{W}, @samp{T}, etc.
20797
0ce1b118
CV
20798@item F@var{call-id}@code{,}@var{parameter@dots{}}
20799
20800@var{call-id} is the identifier which says which host system call should
20801be called. This is just the name of the function. Translation into the
20802correct system call is only applicable as it's defined in @value{GDBN}.
20803@xref{File-I/O remote protocol extension}, for a list of implemented
20804system calls.
20805
20806@var{parameter@dots{}} is a list of parameters as defined for this very
20807system call.
20808
20809The target replies with this packet when it expects @value{GDBN} to call
20810a host system call on behalf of the target. @value{GDBN} replies with
20811an appropriate @code{F} packet and keeps up waiting for the next reply
20812packet from the target. The latest @samp{C}, @samp{c}, @samp{S} or
20813@samp{s} action is expected to be continued.
20814@xref{File-I/O remote protocol extension}, for more details.
20815
ee2d5c50
AC
20816@end table
20817
20818@node General Query Packets
20819@section General Query Packets
c906108c 20820
8e04817f 20821The following set and query packets have already been defined.
c906108c 20822
ee2d5c50 20823@table @r
c906108c 20824
ee2d5c50
AC
20825@item @code{q}@code{C} --- current thread
20826
20827Return the current thread id.
20828
20829Reply:
20830@table @samp
20831@item @code{QC}@var{pid}
8e04817f 20832Where @var{pid} is a HEX encoded 16 bit process id.
ee2d5c50
AC
20833@item *
20834Any other reply implies the old pid.
20835@end table
20836
20837@item @code{q}@code{fThreadInfo} -- all thread ids
20838
20839@code{q}@code{sThreadInfo}
c906108c 20840
8e04817f
AC
20841Obtain a list of active thread ids from the target (OS). Since there
20842may be too many active threads to fit into one reply packet, this query
20843works iteratively: it may require more than one query/reply sequence to
20844obtain the entire list of threads. The first query of the sequence will
20845be the @code{qf}@code{ThreadInfo} query; subsequent queries in the
20846sequence will be the @code{qs}@code{ThreadInfo} query.
ee2d5c50
AC
20847
20848NOTE: replaces the @code{qL} query (see below).
20849
20850Reply:
20851@table @samp
20852@item @code{m}@var{id}
20853A single thread id
20854@item @code{m}@var{id},@var{id}@dots{}
20855a comma-separated list of thread ids
20856@item @code{l}
20857(lower case 'el') denotes end of list.
20858@end table
20859
20860In response to each query, the target will reply with a list of one or
20861more thread ids, in big-endian hex, separated by commas. @value{GDBN}
20862will respond to each reply with a request for more thread ids (using the
8e04817f
AC
20863@code{qs} form of the query), until the target responds with @code{l}
20864(lower-case el, for @code{'last'}).
c906108c 20865
ee2d5c50
AC
20866@item @code{q}@code{ThreadExtraInfo}@code{,}@var{id} --- extra thread info
20867
20868Where @var{id} is a thread-id in big-endian hex. Obtain a printable
20869string description of a thread's attributes from the target OS. This
20870string may contain anything that the target OS thinks is interesting for
20871@value{GDBN} to tell the user about the thread. The string is displayed
20872in @value{GDBN}'s @samp{info threads} display. Some examples of
20873possible thread extra info strings are ``Runnable'', or ``Blocked on
20874Mutex''.
20875
20876Reply:
20877@table @samp
20878@item @var{XX@dots{}}
20879Where @var{XX@dots{}} is a hex encoding of @sc{ascii} data, comprising
20880the printable string containing the extra information about the thread's
8e04817f 20881attributes.
ee2d5c50
AC
20882@end table
20883
20884@item @code{q}@code{L}@var{startflag}@var{threadcount}@var{nextthread} --- query @var{LIST} or @var{threadLIST} @strong{(deprecated)}
c906108c 20885
8e04817f
AC
20886Obtain thread information from RTOS. Where: @var{startflag} (one hex
20887digit) is one to indicate the first query and zero to indicate a
20888subsequent query; @var{threadcount} (two hex digits) is the maximum
20889number of threads the response packet can contain; and @var{nextthread}
20890(eight hex digits), for subsequent queries (@var{startflag} is zero), is
20891returned in the response as @var{argthread}.
ee2d5c50
AC
20892
20893NOTE: this query is replaced by the @code{q}@code{fThreadInfo} query
20894(see above).
20895
20896Reply:
20897@table @samp
20898@item @code{q}@code{M}@var{count}@var{done}@var{argthread}@var{thread@dots{}}
8e04817f
AC
20899Where: @var{count} (two hex digits) is the number of threads being
20900returned; @var{done} (one hex digit) is zero to indicate more threads
20901and one indicates no further threads; @var{argthreadid} (eight hex
ee2d5c50
AC
20902digits) is @var{nextthread} from the request packet; @var{thread@dots{}}
20903is a sequence of thread IDs from the target. @var{threadid} (eight hex
8e04817f 20904digits). See @code{remote.c:parse_threadlist_response()}.
ee2d5c50 20905@end table
c906108c 20906
ee2d5c50
AC
20907@item @code{q}@code{CRC:}@var{addr}@code{,}@var{length} --- compute CRC of memory block
20908
20909Reply:
20910@table @samp
20911@item @code{E}@var{NN}
20912An error (such as memory fault)
20913@item @code{C}@var{CRC32}
20914A 32 bit cyclic redundancy check of the specified memory region.
20915@end table
20916
20917@item @code{q}@code{Offsets} --- query sect offs
c906108c 20918
8e04817f
AC
20919Get section offsets that the target used when re-locating the downloaded
20920image. @emph{Note: while a @code{Bss} offset is included in the
20921response, @value{GDBN} ignores this and instead applies the @code{Data}
20922offset to the @code{Bss} section.}
c906108c 20923
ee2d5c50
AC
20924Reply:
20925@table @samp
20926@item @code{Text=}@var{xxx}@code{;Data=}@var{yyy}@code{;Bss=}@var{zzz}
20927@end table
20928
20929@item @code{q}@code{P}@var{mode}@var{threadid} --- thread info request
20930
8e04817f
AC
20931Returns information on @var{threadid}. Where: @var{mode} is a hex
20932encoded 32 bit mode; @var{threadid} is a hex encoded 64 bit thread ID.
ee2d5c50
AC
20933
20934Reply:
20935@table @samp
20936@item *
20937@end table
20938
8e04817f 20939See @code{remote.c:remote_unpack_thread_info_response()}.
c906108c 20940
ee2d5c50
AC
20941@item @code{q}@code{Rcmd,}@var{command} --- remote command
20942
20943@var{command} (hex encoded) is passed to the local interpreter for
8e04817f
AC
20944execution. Invalid commands should be reported using the output string.
20945Before the final result packet, the target may also respond with a
ee2d5c50
AC
20946number of intermediate @code{O}@var{output} console output packets.
20947@emph{Implementors should note that providing access to a stubs's
20948interpreter may have security implications}.
20949
20950Reply:
20951@table @samp
20952@item OK
8e04817f 20953A command response with no output.
ee2d5c50 20954@item @var{OUTPUT}
8e04817f 20955A command response with the hex encoded output string @var{OUTPUT}.
ee2d5c50 20956@item @code{E}@var{NN}
8e04817f 20957Indicate a badly formed request.
ee2d5c50 20958@item @samp{}
8e04817f 20959When @samp{q}@samp{Rcmd} is not recognized.
ee2d5c50
AC
20960@end table
20961
20962@item @code{qSymbol::} --- symbol lookup
c906108c 20963
8e04817f
AC
20964Notify the target that @value{GDBN} is prepared to serve symbol lookup
20965requests. Accept requests from the target for the values of symbols.
ee2d5c50
AC
20966
20967Reply:
20968@table @samp
20969@item @code{OK}
8e04817f 20970The target does not need to look up any (more) symbols.
ee2d5c50
AC
20971@item @code{qSymbol:}@var{sym_name}
20972The target requests the value of symbol @var{sym_name} (hex encoded).
20973@value{GDBN} may provide the value by using the
20974@code{qSymbol:}@var{sym_value}:@var{sym_name} message, described below.
20975@end table
20976
20977@item @code{qSymbol:}@var{sym_value}:@var{sym_name} --- symbol value
20978
20979Set the value of @var{sym_name} to @var{sym_value}.
20980
20981@var{sym_name} (hex encoded) is the name of a symbol whose value the
20982target has previously requested.
20983
20984@var{sym_value} (hex) is the value for symbol @var{sym_name}. If
20985@value{GDBN} cannot supply a value for @var{sym_name}, then this field
20986will be empty.
20987
20988Reply:
20989@table @samp
20990@item @code{OK}
8e04817f 20991The target does not need to look up any (more) symbols.
ee2d5c50
AC
20992@item @code{qSymbol:}@var{sym_name}
20993The target requests the value of a new symbol @var{sym_name} (hex
20994encoded). @value{GDBN} will continue to supply the values of symbols
20995(if available), until the target ceases to request them.
20996@end table
eb12ee30 20997
649e03f6
RM
20998@item @code{qPart}:@var{object}:@code{read}:@var{annex}:@var{offset},@var{length} --- read special data
20999
21000Read uninterpreted bytes from the target's special data area
21001identified by the keyword @code{object}.
21002Request @var{length} bytes starting at @var{offset} bytes into the data.
21003The content and encoding of @var{annex} is specific to the object;
21004it can supply additional details about what data to access.
21005
21006Here are the specific requests of this form defined so far.
21007All @samp{@code{qPart}:@var{object}:@code{read}:@dots{}}
21008requests use the same reply formats, listed below.
21009
21010@table @asis
21011@item @code{qPart}:@code{auxv}:@code{read}::@var{offset},@var{length}
21012Access the target's @dfn{auxiliary vector}. @xref{Auxiliary Vector}.
21013Note @var{annex} must be empty.
21014@end table
21015
21016Reply:
21017@table @asis
21018@item @code{OK}
21019The @var{offset} in the request is at the end of the data.
21020There is no more data to be read.
21021
21022@item @var{XX@dots{}}
21023Hex encoded data bytes read.
21024This may be fewer bytes than the @var{length} in the request.
21025
21026@item @code{E00}
21027The request was malformed, or @var{annex} was invalid.
21028
21029@item @code{E}@var{nn}
21030The offset was invalid, or there was an error encountered reading the data.
21031@var{nn} is a hex-encoded @code{errno} value.
21032
21033@item @code{""} (empty)
21034An empty reply indicates the @var{object} or @var{annex} string was not
21035recognized by the stub.
21036@end table
21037
21038@item @code{qPart}:@var{object}:@code{write}:@var{annex}:@var{offset}:@var{data@dots{}}
21039
21040Write uninterpreted bytes into the target's special data area
21041identified by the keyword @code{object},
21042starting at @var{offset} bytes into the data.
21043@var{data@dots{}} is the hex-encoded data to be written.
21044The content and encoding of @var{annex} is specific to the object;
21045it can supply additional details about what data to access.
21046
21047No requests of this form are presently in use. This specification
21048serves as a placeholder to document the common format that new
21049specific request specifications ought to use.
21050
21051Reply:
21052@table @asis
21053@item @var{nn}
21054@var{nn} (hex encoded) is the number of bytes written.
21055This may be fewer bytes than supplied in the request.
21056
21057@item @code{E00}
21058The request was malformed, or @var{annex} was invalid.
21059
21060@item @code{E}@var{nn}
21061The offset was invalid, or there was an error encountered writing the data.
21062@var{nn} is a hex-encoded @code{errno} value.
21063
21064@item @code{""} (empty)
21065An empty reply indicates the @var{object} or @var{annex} string was not
21066recognized by the stub, or that the object does not support writing.
21067@end table
21068
21069@item @code{qPart}:@var{object}:@var{operation}:@dots{}
21070Requests of this form may be added in the future. When a stub does
21071not recognize the @var{object} keyword, or its support for
21072@var{object} does not recognize the @var{operation} keyword,
21073the stub must respond with an empty packet.
ee2d5c50
AC
21074@end table
21075
21076@node Register Packet Format
21077@section Register Packet Format
eb12ee30 21078
8e04817f 21079The following @samp{g}/@samp{G} packets have previously been defined.
ee2d5c50
AC
21080In the below, some thirty-two bit registers are transferred as
21081sixty-four bits. Those registers should be zero/sign extended (which?)
21082to fill the space allocated. Register bytes are transfered in target
21083byte order. The two nibbles within a register byte are transfered
21084most-significant - least-significant.
eb12ee30 21085
ee2d5c50 21086@table @r
eb12ee30 21087
8e04817f 21088@item MIPS32
ee2d5c50 21089
8e04817f
AC
21090All registers are transfered as thirty-two bit quantities in the order:
2109132 general-purpose; sr; lo; hi; bad; cause; pc; 32 floating-point
21092registers; fsr; fir; fp.
eb12ee30 21093
8e04817f 21094@item MIPS64
ee2d5c50 21095
8e04817f
AC
21096All registers are transfered as sixty-four bit quantities (including
21097thirty-two bit registers such as @code{sr}). The ordering is the same
21098as @code{MIPS32}.
eb12ee30 21099
ee2d5c50
AC
21100@end table
21101
21102@node Examples
21103@section Examples
eb12ee30 21104
8e04817f
AC
21105Example sequence of a target being re-started. Notice how the restart
21106does not get any direct output:
eb12ee30 21107
474c8240 21108@smallexample
d2c6833e
AC
21109-> @code{R00}
21110<- @code{+}
8e04817f 21111@emph{target restarts}
d2c6833e 21112-> @code{?}
8e04817f 21113<- @code{+}
d2c6833e
AC
21114<- @code{T001:1234123412341234}
21115-> @code{+}
474c8240 21116@end smallexample
eb12ee30 21117
8e04817f 21118Example sequence of a target being stepped by a single instruction:
eb12ee30 21119
474c8240 21120@smallexample
d2c6833e 21121-> @code{G1445@dots{}}
8e04817f 21122<- @code{+}
d2c6833e
AC
21123-> @code{s}
21124<- @code{+}
21125@emph{time passes}
21126<- @code{T001:1234123412341234}
8e04817f 21127-> @code{+}
d2c6833e 21128-> @code{g}
8e04817f 21129<- @code{+}
d2c6833e
AC
21130<- @code{1455@dots{}}
21131-> @code{+}
474c8240 21132@end smallexample
eb12ee30 21133
0ce1b118
CV
21134@node File-I/O remote protocol extension
21135@section File-I/O remote protocol extension
21136@cindex File-I/O remote protocol extension
21137
21138@menu
21139* File-I/O Overview::
21140* Protocol basics::
1d8b2f28
JB
21141* The F request packet::
21142* The F reply packet::
0ce1b118
CV
21143* Memory transfer::
21144* The Ctrl-C message::
21145* Console I/O::
21146* The isatty call::
21147* The system call::
21148* List of supported calls::
21149* Protocol specific representation of datatypes::
21150* Constants::
21151* File-I/O Examples::
21152@end menu
21153
21154@node File-I/O Overview
21155@subsection File-I/O Overview
21156@cindex file-i/o overview
21157
21158The File I/O remote protocol extension (short: File-I/O) allows the
21159target to use the hosts file system and console I/O when calling various
21160system calls. System calls on the target system are translated into a
21161remote protocol packet to the host system which then performs the needed
21162actions and returns with an adequate response packet to the target system.
21163This simulates file system operations even on targets that lack file systems.
21164
21165The protocol is defined host- and target-system independent. It uses
21166it's own independent representation of datatypes and values. Both,
21167@value{GDBN} and the target's @value{GDBN} stub are responsible for
21168translating the system dependent values into the unified protocol values
21169when data is transmitted.
21170
21171The communication is synchronous. A system call is possible only
21172when GDB is waiting for the @samp{C}, @samp{c}, @samp{S} or @samp{s}
21173packets. While @value{GDBN} handles the request for a system call,
21174the target is stopped to allow deterministic access to the target's
21175memory. Therefore File-I/O is not interuptible by target signals. It
21176is possible to interrupt File-I/O by a user interrupt (Ctrl-C), though.
21177
21178The target's request to perform a host system call does not finish
21179the latest @samp{C}, @samp{c}, @samp{S} or @samp{s} action. That means,
21180after finishing the system call, the target returns to continuing the
21181previous activity (continue, step). No additional continue or step
21182request from @value{GDBN} is required.
21183
21184@smallexample
f7dc1244 21185(@value{GDBP}) continue
0ce1b118
CV
21186 <- target requests 'system call X'
21187 target is stopped, @value{GDBN} executes system call
21188 -> GDB returns result
21189 ... target continues, GDB returns to wait for the target
21190 <- target hits breakpoint and sends a Txx packet
21191@end smallexample
21192
21193The protocol is only used for files on the host file system and
21194for I/O on the console. Character or block special devices, pipes,
21195named pipes or sockets or any other communication method on the host
21196system are not supported by this protocol.
21197
21198@node Protocol basics
21199@subsection Protocol basics
21200@cindex protocol basics, file-i/o
21201
21202The File-I/O protocol uses the @code{F} packet, as request as well
21203as as reply packet. Since a File-I/O system call can only occur when
b383017d 21204@value{GDBN} is waiting for the continuing or stepping target, the
0ce1b118
CV
21205File-I/O request is a reply that @value{GDBN} has to expect as a result
21206of a former @samp{C}, @samp{c}, @samp{S} or @samp{s} packet.
21207This @code{F} packet contains all information needed to allow @value{GDBN}
21208to call the appropriate host system call:
21209
21210@itemize @bullet
b383017d 21211@item
0ce1b118
CV
21212A unique identifier for the requested system call.
21213
21214@item
21215All parameters to the system call. Pointers are given as addresses
21216in the target memory address space. Pointers to strings are given as
b383017d 21217pointer/length pair. Numerical values are given as they are.
0ce1b118
CV
21218Numerical control values are given in a protocol specific representation.
21219
21220@end itemize
21221
21222At that point @value{GDBN} has to perform the following actions.
21223
21224@itemize @bullet
b383017d 21225@item
0ce1b118
CV
21226If parameter pointer values are given, which point to data needed as input
21227to a system call, @value{GDBN} requests this data from the target with a
21228standard @code{m} packet request. This additional communication has to be
21229expected by the target implementation and is handled as any other @code{m}
21230packet.
21231
21232@item
21233@value{GDBN} translates all value from protocol representation to host
21234representation as needed. Datatypes are coerced into the host types.
21235
21236@item
21237@value{GDBN} calls the system call
21238
21239@item
21240It then coerces datatypes back to protocol representation.
21241
21242@item
21243If pointer parameters in the request packet point to buffer space in which
21244a system call is expected to copy data to, the data is transmitted to the
21245target using a @code{M} or @code{X} packet. This packet has to be expected
21246by the target implementation and is handled as any other @code{M} or @code{X}
21247packet.
21248
21249@end itemize
21250
21251Eventually @value{GDBN} replies with another @code{F} packet which contains all
21252necessary information for the target to continue. This at least contains
21253
21254@itemize @bullet
21255@item
21256Return value.
21257
21258@item
21259@code{errno}, if has been changed by the system call.
21260
21261@item
21262``Ctrl-C'' flag.
21263
21264@end itemize
21265
21266After having done the needed type and value coercion, the target continues
21267the latest continue or step action.
21268
1d8b2f28 21269@node The F request packet
0ce1b118
CV
21270@subsection The @code{F} request packet
21271@cindex file-i/o request packet
21272@cindex @code{F} request packet
21273
21274The @code{F} request packet has the following format:
21275
21276@table @samp
21277
21278@smallexample
21279@code{F}@var{call-id}@code{,}@var{parameter@dots{}}
21280@end smallexample
21281
21282@var{call-id} is the identifier to indicate the host system call to be called.
21283This is just the name of the function.
21284
21285@var{parameter@dots{}} are the parameters to the system call.
21286
b383017d 21287@end table
0ce1b118
CV
21288
21289Parameters are hexadecimal integer values, either the real values in case
21290of scalar datatypes, as pointers to target buffer space in case of compound
21291datatypes and unspecified memory areas or as pointer/length pairs in case
21292of string parameters. These are appended to the call-id, each separated
21293from its predecessor by a comma. All values are transmitted in ASCII
21294string representation, pointer/length pairs separated by a slash.
21295
1d8b2f28 21296@node The F reply packet
0ce1b118
CV
21297@subsection The @code{F} reply packet
21298@cindex file-i/o reply packet
21299@cindex @code{F} reply packet
21300
21301The @code{F} reply packet has the following format:
21302
21303@table @samp
21304
21305@smallexample
21306@code{F}@var{retcode}@code{,}@var{errno}@code{,}@var{Ctrl-C flag}@code{;}@var{call specific attachment}
21307@end smallexample
21308
21309@var{retcode} is the return code of the system call as hexadecimal value.
21310
21311@var{errno} is the errno set by the call, in protocol specific representation.
21312This parameter can be omitted if the call was successful.
21313
21314@var{Ctrl-C flag} is only send if the user requested a break. In this
21315case, @var{errno} must be send as well, even if the call was successful.
21316The @var{Ctrl-C flag} itself consists of the character 'C':
21317
21318@smallexample
21319F0,0,C
21320@end smallexample
21321
21322@noindent
21323or, if the call was interupted before the host call has been performed:
21324
21325@smallexample
21326F-1,4,C
21327@end smallexample
21328
21329@noindent
21330assuming 4 is the protocol specific representation of @code{EINTR}.
21331
21332@end table
21333
21334@node Memory transfer
21335@subsection Memory transfer
21336@cindex memory transfer, in file-i/o protocol
21337
21338Structured data which is transferred using a memory read or write as e.g.@:
21339a @code{struct stat} is expected to be in a protocol specific format with
21340all scalar multibyte datatypes being big endian. This should be done by
21341the target before the @code{F} packet is sent resp.@: by @value{GDBN} before
21342it transfers memory to the target. Transferred pointers to structured
21343data should point to the already coerced data at any time.
21344
21345@node The Ctrl-C message
21346@subsection The Ctrl-C message
21347@cindex ctrl-c message, in file-i/o protocol
21348
21349A special case is, if the @var{Ctrl-C flag} is set in the @value{GDBN}
21350reply packet. In this case the target should behave, as if it had
21351gotten a break message. The meaning for the target is ``system call
21352interupted by @code{SIGINT}''. Consequentially, the target should actually stop
21353(as with a break message) and return to @value{GDBN} with a @code{T02}
b383017d 21354packet. In this case, it's important for the target to know, in which
0ce1b118
CV
21355state the system call was interrupted. Since this action is by design
21356not an atomic operation, we have to differ between two cases:
21357
21358@itemize @bullet
21359@item
21360The system call hasn't been performed on the host yet.
21361
21362@item
21363The system call on the host has been finished.
21364
21365@end itemize
21366
21367These two states can be distinguished by the target by the value of the
21368returned @code{errno}. If it's the protocol representation of @code{EINTR}, the system
21369call hasn't been performed. This is equivalent to the @code{EINTR} handling
21370on POSIX systems. In any other case, the target may presume that the
21371system call has been finished --- successful or not --- and should behave
21372as if the break message arrived right after the system call.
21373
21374@value{GDBN} must behave reliable. If the system call has not been called
21375yet, @value{GDBN} may send the @code{F} reply immediately, setting @code{EINTR} as
21376@code{errno} in the packet. If the system call on the host has been finished
21377before the user requests a break, the full action must be finshed by
21378@value{GDBN}. This requires sending @code{M} or @code{X} packets as they fit.
21379The @code{F} packet may only be send when either nothing has happened
21380or the full action has been completed.
21381
21382@node Console I/O
21383@subsection Console I/O
21384@cindex console i/o as part of file-i/o
21385
21386By default and if not explicitely closed by the target system, the file
21387descriptors 0, 1 and 2 are connected to the @value{GDBN} console. Output
21388on the @value{GDBN} console is handled as any other file output operation
21389(@code{write(1, @dots{})} or @code{write(2, @dots{})}). Console input is handled
21390by @value{GDBN} so that after the target read request from file descriptor
213910 all following typing is buffered until either one of the following
21392conditions is met:
21393
21394@itemize @bullet
21395@item
21396The user presses @kbd{Ctrl-C}. The behaviour is as explained above, the
21397@code{read}
21398system call is treated as finished.
21399
21400@item
21401The user presses @kbd{Enter}. This is treated as end of input with a trailing
21402line feed.
21403
21404@item
21405The user presses @kbd{Ctrl-D}. This is treated as end of input. No trailing
21406character, especially no Ctrl-D is appended to the input.
21407
21408@end itemize
21409
21410If the user has typed more characters as fit in the buffer given to
21411the read call, the trailing characters are buffered in @value{GDBN} until
21412either another @code{read(0, @dots{})} is requested by the target or debugging
21413is stopped on users request.
21414
21415@node The isatty call
21416@subsection The isatty(3) call
21417@cindex isatty call, file-i/o protocol
21418
21419A special case in this protocol is the library call @code{isatty} which
21420is implemented as it's own call inside of this protocol. It returns
214211 to the target if the file descriptor given as parameter is attached
21422to the @value{GDBN} console, 0 otherwise. Implementing through system calls
21423would require implementing @code{ioctl} and would be more complex than
21424needed.
21425
21426@node The system call
21427@subsection The system(3) call
21428@cindex system call, file-i/o protocol
21429
21430The other special case in this protocol is the @code{system} call which
21431is implemented as it's own call, too. @value{GDBN} is taking over the full
21432task of calling the necessary host calls to perform the @code{system}
21433call. The return value of @code{system} is simplified before it's returned
21434to the target. Basically, the only signal transmitted back is @code{EINTR}
21435in case the user pressed @kbd{Ctrl-C}. Otherwise the return value consists
21436entirely of the exit status of the called command.
21437
21438Due to security concerns, the @code{system} call is refused to be called
b383017d 21439by @value{GDBN} by default. The user has to allow this call explicitly by
0ce1b118
CV
21440entering
21441
21442@table @samp
21443@kindex set remote system-call-allowed 1
21444@item @code{set remote system-call-allowed 1}
21445@end table
21446
21447Disabling the @code{system} call is done by
21448
21449@table @samp
21450@kindex set remote system-call-allowed 0
21451@item @code{set remote system-call-allowed 0}
21452@end table
21453
21454The current setting is shown by typing
21455
21456@table @samp
21457@kindex show remote system-call-allowed
21458@item @code{show remote system-call-allowed}
21459@end table
21460
21461@node List of supported calls
21462@subsection List of supported calls
21463@cindex list of supported file-i/o calls
21464
21465@menu
21466* open::
21467* close::
21468* read::
21469* write::
21470* lseek::
21471* rename::
21472* unlink::
21473* stat/fstat::
21474* gettimeofday::
21475* isatty::
21476* system::
21477@end menu
21478
21479@node open
21480@unnumberedsubsubsec open
21481@cindex open, file-i/o system call
21482
21483@smallexample
21484@exdent Synopsis:
21485int open(const char *pathname, int flags);
21486int open(const char *pathname, int flags, mode_t mode);
21487
b383017d 21488@exdent Request:
0ce1b118
CV
21489Fopen,pathptr/len,flags,mode
21490@end smallexample
21491
21492@noindent
21493@code{flags} is the bitwise or of the following values:
21494
21495@table @code
b383017d 21496@item O_CREAT
0ce1b118
CV
21497If the file does not exist it will be created. The host
21498rules apply as far as file ownership and time stamps
21499are concerned.
21500
b383017d 21501@item O_EXCL
0ce1b118
CV
21502When used with O_CREAT, if the file already exists it is
21503an error and open() fails.
21504
b383017d 21505@item O_TRUNC
0ce1b118
CV
21506If the file already exists and the open mode allows
21507writing (O_RDWR or O_WRONLY is given) it will be
21508truncated to length 0.
21509
b383017d 21510@item O_APPEND
0ce1b118
CV
21511The file is opened in append mode.
21512
b383017d 21513@item O_RDONLY
0ce1b118
CV
21514The file is opened for reading only.
21515
b383017d 21516@item O_WRONLY
0ce1b118
CV
21517The file is opened for writing only.
21518
b383017d 21519@item O_RDWR
0ce1b118
CV
21520The file is opened for reading and writing.
21521
21522@noindent
21523Each other bit is silently ignored.
21524
21525@end table
21526
21527@noindent
21528@code{mode} is the bitwise or of the following values:
21529
21530@table @code
b383017d 21531@item S_IRUSR
0ce1b118
CV
21532User has read permission.
21533
b383017d 21534@item S_IWUSR
0ce1b118
CV
21535User has write permission.
21536
b383017d 21537@item S_IRGRP
0ce1b118
CV
21538Group has read permission.
21539
b383017d 21540@item S_IWGRP
0ce1b118
CV
21541Group has write permission.
21542
b383017d 21543@item S_IROTH
0ce1b118
CV
21544Others have read permission.
21545
b383017d 21546@item S_IWOTH
0ce1b118
CV
21547Others have write permission.
21548
21549@noindent
21550Each other bit is silently ignored.
21551
21552@end table
21553
21554@smallexample
21555@exdent Return value:
21556open returns the new file descriptor or -1 if an error
21557occured.
21558
21559@exdent Errors:
21560@end smallexample
21561
21562@table @code
b383017d 21563@item EEXIST
0ce1b118
CV
21564pathname already exists and O_CREAT and O_EXCL were used.
21565
b383017d 21566@item EISDIR
0ce1b118
CV
21567pathname refers to a directory.
21568
b383017d 21569@item EACCES
0ce1b118
CV
21570The requested access is not allowed.
21571
21572@item ENAMETOOLONG
21573pathname was too long.
21574
b383017d 21575@item ENOENT
0ce1b118
CV
21576A directory component in pathname does not exist.
21577
b383017d 21578@item ENODEV
0ce1b118
CV
21579pathname refers to a device, pipe, named pipe or socket.
21580
b383017d 21581@item EROFS
0ce1b118
CV
21582pathname refers to a file on a read-only filesystem and
21583write access was requested.
21584
b383017d 21585@item EFAULT
0ce1b118
CV
21586pathname is an invalid pointer value.
21587
b383017d 21588@item ENOSPC
0ce1b118
CV
21589No space on device to create the file.
21590
b383017d 21591@item EMFILE
0ce1b118
CV
21592The process already has the maximum number of files open.
21593
b383017d 21594@item ENFILE
0ce1b118
CV
21595The limit on the total number of files open on the system
21596has been reached.
21597
b383017d 21598@item EINTR
0ce1b118
CV
21599The call was interrupted by the user.
21600@end table
21601
21602@node close
21603@unnumberedsubsubsec close
21604@cindex close, file-i/o system call
21605
21606@smallexample
b383017d 21607@exdent Synopsis:
0ce1b118
CV
21608int close(int fd);
21609
b383017d 21610@exdent Request:
0ce1b118
CV
21611Fclose,fd
21612
21613@exdent Return value:
21614close returns zero on success, or -1 if an error occurred.
21615
21616@exdent Errors:
21617@end smallexample
21618
21619@table @code
b383017d 21620@item EBADF
0ce1b118
CV
21621fd isn't a valid open file descriptor.
21622
b383017d 21623@item EINTR
0ce1b118
CV
21624The call was interrupted by the user.
21625@end table
21626
21627@node read
21628@unnumberedsubsubsec read
21629@cindex read, file-i/o system call
21630
21631@smallexample
b383017d 21632@exdent Synopsis:
0ce1b118
CV
21633int read(int fd, void *buf, unsigned int count);
21634
b383017d 21635@exdent Request:
0ce1b118
CV
21636Fread,fd,bufptr,count
21637
21638@exdent Return value:
21639On success, the number of bytes read is returned.
21640Zero indicates end of file. If count is zero, read
b383017d 21641returns zero as well. On error, -1 is returned.
0ce1b118
CV
21642
21643@exdent Errors:
21644@end smallexample
21645
21646@table @code
b383017d 21647@item EBADF
0ce1b118
CV
21648fd is not a valid file descriptor or is not open for
21649reading.
21650
b383017d 21651@item EFAULT
0ce1b118
CV
21652buf is an invalid pointer value.
21653
b383017d 21654@item EINTR
0ce1b118
CV
21655The call was interrupted by the user.
21656@end table
21657
21658@node write
21659@unnumberedsubsubsec write
21660@cindex write, file-i/o system call
21661
21662@smallexample
b383017d 21663@exdent Synopsis:
0ce1b118
CV
21664int write(int fd, const void *buf, unsigned int count);
21665
b383017d 21666@exdent Request:
0ce1b118
CV
21667Fwrite,fd,bufptr,count
21668
21669@exdent Return value:
21670On success, the number of bytes written are returned.
21671Zero indicates nothing was written. On error, -1
21672is returned.
21673
21674@exdent Errors:
21675@end smallexample
21676
21677@table @code
b383017d 21678@item EBADF
0ce1b118
CV
21679fd is not a valid file descriptor or is not open for
21680writing.
21681
b383017d 21682@item EFAULT
0ce1b118
CV
21683buf is an invalid pointer value.
21684
b383017d 21685@item EFBIG
0ce1b118
CV
21686An attempt was made to write a file that exceeds the
21687host specific maximum file size allowed.
21688
b383017d 21689@item ENOSPC
0ce1b118
CV
21690No space on device to write the data.
21691
b383017d 21692@item EINTR
0ce1b118
CV
21693The call was interrupted by the user.
21694@end table
21695
21696@node lseek
21697@unnumberedsubsubsec lseek
21698@cindex lseek, file-i/o system call
21699
21700@smallexample
b383017d 21701@exdent Synopsis:
0ce1b118
CV
21702long lseek (int fd, long offset, int flag);
21703
b383017d 21704@exdent Request:
0ce1b118
CV
21705Flseek,fd,offset,flag
21706@end smallexample
21707
21708@code{flag} is one of:
21709
21710@table @code
b383017d 21711@item SEEK_SET
0ce1b118
CV
21712The offset is set to offset bytes.
21713
b383017d 21714@item SEEK_CUR
0ce1b118
CV
21715The offset is set to its current location plus offset
21716bytes.
21717
b383017d 21718@item SEEK_END
0ce1b118
CV
21719The offset is set to the size of the file plus offset
21720bytes.
21721@end table
21722
21723@smallexample
21724@exdent Return value:
21725On success, the resulting unsigned offset in bytes from
21726the beginning of the file is returned. Otherwise, a
21727value of -1 is returned.
21728
21729@exdent Errors:
21730@end smallexample
21731
21732@table @code
b383017d 21733@item EBADF
0ce1b118
CV
21734fd is not a valid open file descriptor.
21735
b383017d 21736@item ESPIPE
0ce1b118
CV
21737fd is associated with the @value{GDBN} console.
21738
b383017d 21739@item EINVAL
0ce1b118
CV
21740flag is not a proper value.
21741
b383017d 21742@item EINTR
0ce1b118
CV
21743The call was interrupted by the user.
21744@end table
21745
21746@node rename
21747@unnumberedsubsubsec rename
21748@cindex rename, file-i/o system call
21749
21750@smallexample
b383017d 21751@exdent Synopsis:
0ce1b118
CV
21752int rename(const char *oldpath, const char *newpath);
21753
b383017d 21754@exdent Request:
0ce1b118
CV
21755Frename,oldpathptr/len,newpathptr/len
21756
21757@exdent Return value:
21758On success, zero is returned. On error, -1 is returned.
21759
21760@exdent Errors:
21761@end smallexample
21762
21763@table @code
b383017d 21764@item EISDIR
0ce1b118
CV
21765newpath is an existing directory, but oldpath is not a
21766directory.
21767
b383017d 21768@item EEXIST
0ce1b118
CV
21769newpath is a non-empty directory.
21770
b383017d 21771@item EBUSY
0ce1b118
CV
21772oldpath or newpath is a directory that is in use by some
21773process.
21774
b383017d 21775@item EINVAL
0ce1b118
CV
21776An attempt was made to make a directory a subdirectory
21777of itself.
21778
b383017d 21779@item ENOTDIR
0ce1b118
CV
21780A component used as a directory in oldpath or new
21781path is not a directory. Or oldpath is a directory
21782and newpath exists but is not a directory.
21783
b383017d 21784@item EFAULT
0ce1b118
CV
21785oldpathptr or newpathptr are invalid pointer values.
21786
b383017d 21787@item EACCES
0ce1b118
CV
21788No access to the file or the path of the file.
21789
21790@item ENAMETOOLONG
b383017d 21791
0ce1b118
CV
21792oldpath or newpath was too long.
21793
b383017d 21794@item ENOENT
0ce1b118
CV
21795A directory component in oldpath or newpath does not exist.
21796
b383017d 21797@item EROFS
0ce1b118
CV
21798The file is on a read-only filesystem.
21799
b383017d 21800@item ENOSPC
0ce1b118
CV
21801The device containing the file has no room for the new
21802directory entry.
21803
b383017d 21804@item EINTR
0ce1b118
CV
21805The call was interrupted by the user.
21806@end table
21807
21808@node unlink
21809@unnumberedsubsubsec unlink
21810@cindex unlink, file-i/o system call
21811
21812@smallexample
b383017d 21813@exdent Synopsis:
0ce1b118
CV
21814int unlink(const char *pathname);
21815
b383017d 21816@exdent Request:
0ce1b118
CV
21817Funlink,pathnameptr/len
21818
21819@exdent Return value:
21820On success, zero is returned. On error, -1 is returned.
21821
21822@exdent Errors:
21823@end smallexample
21824
21825@table @code
b383017d 21826@item EACCES
0ce1b118
CV
21827No access to the file or the path of the file.
21828
b383017d 21829@item EPERM
0ce1b118
CV
21830The system does not allow unlinking of directories.
21831
b383017d 21832@item EBUSY
0ce1b118
CV
21833The file pathname cannot be unlinked because it's
21834being used by another process.
21835
b383017d 21836@item EFAULT
0ce1b118
CV
21837pathnameptr is an invalid pointer value.
21838
21839@item ENAMETOOLONG
21840pathname was too long.
21841
b383017d 21842@item ENOENT
0ce1b118
CV
21843A directory component in pathname does not exist.
21844
b383017d 21845@item ENOTDIR
0ce1b118
CV
21846A component of the path is not a directory.
21847
b383017d 21848@item EROFS
0ce1b118
CV
21849The file is on a read-only filesystem.
21850
b383017d 21851@item EINTR
0ce1b118
CV
21852The call was interrupted by the user.
21853@end table
21854
21855@node stat/fstat
21856@unnumberedsubsubsec stat/fstat
21857@cindex fstat, file-i/o system call
21858@cindex stat, file-i/o system call
21859
21860@smallexample
b383017d 21861@exdent Synopsis:
0ce1b118
CV
21862int stat(const char *pathname, struct stat *buf);
21863int fstat(int fd, struct stat *buf);
21864
b383017d 21865@exdent Request:
0ce1b118
CV
21866Fstat,pathnameptr/len,bufptr
21867Ffstat,fd,bufptr
21868
21869@exdent Return value:
21870On success, zero is returned. On error, -1 is returned.
21871
21872@exdent Errors:
21873@end smallexample
21874
21875@table @code
b383017d 21876@item EBADF
0ce1b118
CV
21877fd is not a valid open file.
21878
b383017d 21879@item ENOENT
0ce1b118
CV
21880A directory component in pathname does not exist or the
21881path is an empty string.
21882
b383017d 21883@item ENOTDIR
0ce1b118
CV
21884A component of the path is not a directory.
21885
b383017d 21886@item EFAULT
0ce1b118
CV
21887pathnameptr is an invalid pointer value.
21888
b383017d 21889@item EACCES
0ce1b118
CV
21890No access to the file or the path of the file.
21891
21892@item ENAMETOOLONG
21893pathname was too long.
21894
b383017d 21895@item EINTR
0ce1b118
CV
21896The call was interrupted by the user.
21897@end table
21898
21899@node gettimeofday
21900@unnumberedsubsubsec gettimeofday
21901@cindex gettimeofday, file-i/o system call
21902
21903@smallexample
b383017d 21904@exdent Synopsis:
0ce1b118
CV
21905int gettimeofday(struct timeval *tv, void *tz);
21906
b383017d 21907@exdent Request:
0ce1b118
CV
21908Fgettimeofday,tvptr,tzptr
21909
21910@exdent Return value:
21911On success, 0 is returned, -1 otherwise.
21912
21913@exdent Errors:
21914@end smallexample
21915
21916@table @code
b383017d 21917@item EINVAL
0ce1b118
CV
21918tz is a non-NULL pointer.
21919
b383017d 21920@item EFAULT
0ce1b118
CV
21921tvptr and/or tzptr is an invalid pointer value.
21922@end table
21923
21924@node isatty
21925@unnumberedsubsubsec isatty
21926@cindex isatty, file-i/o system call
21927
21928@smallexample
b383017d 21929@exdent Synopsis:
0ce1b118
CV
21930int isatty(int fd);
21931
b383017d 21932@exdent Request:
0ce1b118
CV
21933Fisatty,fd
21934
21935@exdent Return value:
21936Returns 1 if fd refers to the @value{GDBN} console, 0 otherwise.
21937
21938@exdent Errors:
21939@end smallexample
21940
21941@table @code
b383017d 21942@item EINTR
0ce1b118
CV
21943The call was interrupted by the user.
21944@end table
21945
21946@node system
21947@unnumberedsubsubsec system
21948@cindex system, file-i/o system call
21949
21950@smallexample
b383017d 21951@exdent Synopsis:
0ce1b118
CV
21952int system(const char *command);
21953
b383017d 21954@exdent Request:
0ce1b118
CV
21955Fsystem,commandptr/len
21956
21957@exdent Return value:
21958The value returned is -1 on error and the return status
21959of the command otherwise. Only the exit status of the
21960command is returned, which is extracted from the hosts
21961system return value by calling WEXITSTATUS(retval).
21962In case /bin/sh could not be executed, 127 is returned.
21963
21964@exdent Errors:
21965@end smallexample
21966
21967@table @code
b383017d 21968@item EINTR
0ce1b118
CV
21969The call was interrupted by the user.
21970@end table
21971
21972@node Protocol specific representation of datatypes
21973@subsection Protocol specific representation of datatypes
21974@cindex protocol specific representation of datatypes, in file-i/o protocol
21975
21976@menu
21977* Integral datatypes::
21978* Pointer values::
21979* struct stat::
21980* struct timeval::
21981@end menu
21982
21983@node Integral datatypes
21984@unnumberedsubsubsec Integral datatypes
21985@cindex integral datatypes, in file-i/o protocol
21986
21987The integral datatypes used in the system calls are
21988
21989@smallexample
21990int@r{,} unsigned int@r{,} long@r{,} unsigned long@r{,} mode_t @r{and} time_t
21991@end smallexample
21992
21993@code{Int}, @code{unsigned int}, @code{mode_t} and @code{time_t} are
21994implemented as 32 bit values in this protocol.
21995
b383017d
RM
21996@code{Long} and @code{unsigned long} are implemented as 64 bit types.
21997
0ce1b118
CV
21998@xref{Limits}, for corresponding MIN and MAX values (similar to those
21999in @file{limits.h}) to allow range checking on host and target.
22000
22001@code{time_t} datatypes are defined as seconds since the Epoch.
22002
22003All integral datatypes transferred as part of a memory read or write of a
22004structured datatype e.g.@: a @code{struct stat} have to be given in big endian
22005byte order.
22006
22007@node Pointer values
22008@unnumberedsubsubsec Pointer values
22009@cindex pointer values, in file-i/o protocol
22010
22011Pointers to target data are transmitted as they are. An exception
22012is made for pointers to buffers for which the length isn't
22013transmitted as part of the function call, namely strings. Strings
22014are transmitted as a pointer/length pair, both as hex values, e.g.@:
22015
22016@smallexample
22017@code{1aaf/12}
22018@end smallexample
22019
22020@noindent
22021which is a pointer to data of length 18 bytes at position 0x1aaf.
22022The length is defined as the full string length in bytes, including
22023the trailing null byte. Example:
22024
22025@smallexample
22026``hello, world'' at address 0x123456
22027@end smallexample
22028
22029@noindent
22030is transmitted as
22031
22032@smallexample
22033@code{123456/d}
22034@end smallexample
22035
22036@node struct stat
22037@unnumberedsubsubsec struct stat
22038@cindex struct stat, in file-i/o protocol
22039
22040The buffer of type struct stat used by the target and @value{GDBN} is defined
22041as follows:
22042
22043@smallexample
22044struct stat @{
22045 unsigned int st_dev; /* device */
22046 unsigned int st_ino; /* inode */
22047 mode_t st_mode; /* protection */
22048 unsigned int st_nlink; /* number of hard links */
22049 unsigned int st_uid; /* user ID of owner */
22050 unsigned int st_gid; /* group ID of owner */
22051 unsigned int st_rdev; /* device type (if inode device) */
22052 unsigned long st_size; /* total size, in bytes */
22053 unsigned long st_blksize; /* blocksize for filesystem I/O */
22054 unsigned long st_blocks; /* number of blocks allocated */
22055 time_t st_atime; /* time of last access */
22056 time_t st_mtime; /* time of last modification */
22057 time_t st_ctime; /* time of last change */
22058@};
22059@end smallexample
22060
22061The integral datatypes are conforming to the definitions given in the
22062approriate section (see @ref{Integral datatypes}, for details) so this
22063structure is of size 64 bytes.
22064
22065The values of several fields have a restricted meaning and/or
22066range of values.
22067
22068@smallexample
22069st_dev: 0 file
22070 1 console
22071
22072st_ino: No valid meaning for the target. Transmitted unchanged.
22073
22074st_mode: Valid mode bits are described in Appendix C. Any other
22075 bits have currently no meaning for the target.
22076
22077st_uid: No valid meaning for the target. Transmitted unchanged.
22078
22079st_gid: No valid meaning for the target. Transmitted unchanged.
22080
22081st_rdev: No valid meaning for the target. Transmitted unchanged.
22082
22083st_atime, st_mtime, st_ctime:
22084 These values have a host and file system dependent
22085 accuracy. Especially on Windows hosts the file systems
22086 don't support exact timing values.
22087@end smallexample
22088
22089The target gets a struct stat of the above representation and is
22090responsible to coerce it to the target representation before
22091continuing.
22092
22093Note that due to size differences between the host and target
22094representation of stat members, these members could eventually
22095get truncated on the target.
22096
22097@node struct timeval
22098@unnumberedsubsubsec struct timeval
22099@cindex struct timeval, in file-i/o protocol
22100
22101The buffer of type struct timeval used by the target and @value{GDBN}
22102is defined as follows:
22103
22104@smallexample
b383017d 22105struct timeval @{
0ce1b118
CV
22106 time_t tv_sec; /* second */
22107 long tv_usec; /* microsecond */
22108@};
22109@end smallexample
22110
22111The integral datatypes are conforming to the definitions given in the
22112approriate section (see @ref{Integral datatypes}, for details) so this
22113structure is of size 8 bytes.
22114
22115@node Constants
22116@subsection Constants
22117@cindex constants, in file-i/o protocol
22118
22119The following values are used for the constants inside of the
22120protocol. @value{GDBN} and target are resposible to translate these
22121values before and after the call as needed.
22122
22123@menu
22124* Open flags::
22125* mode_t values::
22126* Errno values::
22127* Lseek flags::
22128* Limits::
22129@end menu
22130
22131@node Open flags
22132@unnumberedsubsubsec Open flags
22133@cindex open flags, in file-i/o protocol
22134
22135All values are given in hexadecimal representation.
22136
22137@smallexample
22138 O_RDONLY 0x0
22139 O_WRONLY 0x1
22140 O_RDWR 0x2
22141 O_APPEND 0x8
22142 O_CREAT 0x200
22143 O_TRUNC 0x400
22144 O_EXCL 0x800
22145@end smallexample
22146
22147@node mode_t values
22148@unnumberedsubsubsec mode_t values
22149@cindex mode_t values, in file-i/o protocol
22150
22151All values are given in octal representation.
22152
22153@smallexample
22154 S_IFREG 0100000
22155 S_IFDIR 040000
22156 S_IRUSR 0400
22157 S_IWUSR 0200
22158 S_IXUSR 0100
22159 S_IRGRP 040
22160 S_IWGRP 020
22161 S_IXGRP 010
22162 S_IROTH 04
22163 S_IWOTH 02
22164 S_IXOTH 01
22165@end smallexample
22166
22167@node Errno values
22168@unnumberedsubsubsec Errno values
22169@cindex errno values, in file-i/o protocol
22170
22171All values are given in decimal representation.
22172
22173@smallexample
22174 EPERM 1
22175 ENOENT 2
22176 EINTR 4
22177 EBADF 9
22178 EACCES 13
22179 EFAULT 14
22180 EBUSY 16
22181 EEXIST 17
22182 ENODEV 19
22183 ENOTDIR 20
22184 EISDIR 21
22185 EINVAL 22
22186 ENFILE 23
22187 EMFILE 24
22188 EFBIG 27
22189 ENOSPC 28
22190 ESPIPE 29
22191 EROFS 30
22192 ENAMETOOLONG 91
22193 EUNKNOWN 9999
22194@end smallexample
22195
22196 EUNKNOWN is used as a fallback error value if a host system returns
22197 any error value not in the list of supported error numbers.
22198
22199@node Lseek flags
22200@unnumberedsubsubsec Lseek flags
22201@cindex lseek flags, in file-i/o protocol
22202
22203@smallexample
22204 SEEK_SET 0
22205 SEEK_CUR 1
22206 SEEK_END 2
22207@end smallexample
22208
22209@node Limits
22210@unnumberedsubsubsec Limits
22211@cindex limits, in file-i/o protocol
22212
22213All values are given in decimal representation.
22214
22215@smallexample
22216 INT_MIN -2147483648
22217 INT_MAX 2147483647
22218 UINT_MAX 4294967295
22219 LONG_MIN -9223372036854775808
22220 LONG_MAX 9223372036854775807
22221 ULONG_MAX 18446744073709551615
22222@end smallexample
22223
22224@node File-I/O Examples
22225@subsection File-I/O Examples
22226@cindex file-i/o examples
22227
22228Example sequence of a write call, file descriptor 3, buffer is at target
22229address 0x1234, 6 bytes should be written:
22230
22231@smallexample
22232<- @code{Fwrite,3,1234,6}
22233@emph{request memory read from target}
22234-> @code{m1234,6}
22235<- XXXXXX
22236@emph{return "6 bytes written"}
22237-> @code{F6}
22238@end smallexample
22239
22240Example sequence of a read call, file descriptor 3, buffer is at target
22241address 0x1234, 6 bytes should be read:
22242
22243@smallexample
22244<- @code{Fread,3,1234,6}
22245@emph{request memory write to target}
22246-> @code{X1234,6:XXXXXX}
22247@emph{return "6 bytes read"}
22248-> @code{F6}
22249@end smallexample
22250
22251Example sequence of a read call, call fails on the host due to invalid
22252file descriptor (EBADF):
22253
22254@smallexample
22255<- @code{Fread,3,1234,6}
22256-> @code{F-1,9}
22257@end smallexample
22258
22259Example sequence of a read call, user presses Ctrl-C before syscall on
22260host is called:
22261
22262@smallexample
22263<- @code{Fread,3,1234,6}
22264-> @code{F-1,4,C}
22265<- @code{T02}
22266@end smallexample
22267
22268Example sequence of a read call, user presses Ctrl-C after syscall on
22269host is called:
22270
22271@smallexample
22272<- @code{Fread,3,1234,6}
22273-> @code{X1234,6:XXXXXX}
22274<- @code{T02}
22275@end smallexample
22276
f418dd93
DJ
22277@include agentexpr.texi
22278
aab4e0ec 22279@include gpl.texi
eb12ee30 22280
2154891a 22281@raisesections
6826cf00 22282@include fdl.texi
2154891a 22283@lowersections
6826cf00 22284
6d2ebf8b 22285@node Index
c906108c
SS
22286@unnumbered Index
22287
22288@printindex cp
22289
22290@tex
22291% I think something like @colophon should be in texinfo. In the
22292% meantime:
22293\long\def\colophon{\hbox to0pt{}\vfill
22294\centerline{The body of this manual is set in}
22295\centerline{\fontname\tenrm,}
22296\centerline{with headings in {\bf\fontname\tenbf}}
22297\centerline{and examples in {\tt\fontname\tentt}.}
22298\centerline{{\it\fontname\tenit\/},}
22299\centerline{{\bf\fontname\tenbf}, and}
22300\centerline{{\sl\fontname\tensl\/}}
22301\centerline{are used for emphasis.}\vfill}
22302\page\colophon
22303% Blame: doc@cygnus.com, 1991.
22304@end tex
22305
c906108c 22306@bye