2005-04-01 Michael Snyder <msnyder@redhat.com>
[deliverable/binutils-gdb.git] / gdb / doc / gdb.texinfo
CommitLineData
c906108c 1\input texinfo @c -*-texinfo-*-
b6ba6518 2@c Copyright 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1998,
7d51c7de 3@c 1999, 2000, 2001, 2002, 2003, 2004, 2005
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,@*
7d51c7de
BR
55 1999, 2000, 2001, 2002, 2003, 2004, 2005@*
56 Free Software Foundation, Inc.
c906108c 57
e9c75b65
EZ
58Permission is granted to copy, distribute and/or modify this document
59under the terms of the GNU Free Documentation License, Version 1.1 or
60any later version published by the Free Software Foundation; with the
959acfd1
EZ
61Invariant Sections being ``Free Software'' and ``Free Software Needs
62Free Documentation'', with the Front-Cover Texts being ``A GNU Manual,''
63and with the Back-Cover Texts as in (a) below.
c906108c 64
6826cf00
EZ
65(a) The Free Software Foundation's Back-Cover Text is: ``You have
66freedom to copy and modify this GNU Manual, like GNU software. Copies
67published by the Free Software Foundation raise funds for GNU
68development.''
c906108c
SS
69@end ifinfo
70
71@titlepage
72@title Debugging with @value{GDBN}
73@subtitle The @sc{gnu} Source-Level Debugger
c906108c 74@sp 1
c906108c 75@subtitle @value{EDITION} Edition, for @value{GDBN} version @value{GDBVN}
9e9c5ae7 76@author Richard Stallman, Roland Pesch, Stan Shebs, et al.
c906108c 77@page
c906108c
SS
78@tex
79{\parskip=0pt
53a5351d 80\hfill (Send bugs and comments on @value{GDBN} to bug-gdb\@gnu.org.)\par
c906108c
SS
81\hfill {\it Debugging with @value{GDBN}}\par
82\hfill \TeX{}info \texinfoversion\par
83}
84@end tex
53a5351d 85
c906108c 86@vskip 0pt plus 1filll
8a037dd7 87Copyright @copyright{} 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995,
7d51c7de
BR
881996, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005
89Free Software Foundation, Inc.
c906108c 90@sp 2
c906108c
SS
91Published by the Free Software Foundation @*
9259 Temple Place - Suite 330, @*
93Boston, MA 02111-1307 USA @*
6d2ebf8b 94ISBN 1-882114-77-9 @*
e9c75b65
EZ
95
96Permission is granted to copy, distribute and/or modify this document
97under the terms of the GNU Free Documentation License, Version 1.1 or
98any later version published by the Free Software Foundation; with the
959acfd1
EZ
99Invariant Sections being ``Free Software'' and ``Free Software Needs
100Free Documentation'', with the Front-Cover Texts being ``A GNU Manual,''
101and with the Back-Cover Texts as in (a) below.
e9c75b65 102
6826cf00
EZ
103(a) The Free Software Foundation's Back-Cover Text is: ``You have
104freedom to copy and modify this GNU Manual, like GNU software. Copies
105published by the Free Software Foundation raise funds for GNU
106development.''
c906108c
SS
107@end titlepage
108@page
109
6c0e9fb3 110@ifnottex
6d2ebf8b
SS
111@node Top, Summary, (dir), (dir)
112
c906108c
SS
113@top Debugging with @value{GDBN}
114
115This file describes @value{GDBN}, the @sc{gnu} symbolic debugger.
116
9fe8321b 117This is the @value{EDITION} Edition, for @value{GDBN} Version
c906108c
SS
118@value{GDBVN}.
119
7d51c7de 120Copyright (C) 1988-2005 Free Software Foundation, Inc.
6d2ebf8b
SS
121
122@menu
123* Summary:: Summary of @value{GDBN}
124* Sample Session:: A sample @value{GDBN} session
125
126* Invocation:: Getting in and out of @value{GDBN}
127* Commands:: @value{GDBN} commands
128* Running:: Running programs under @value{GDBN}
129* Stopping:: Stopping and continuing
130* Stack:: Examining the stack
131* Source:: Examining source files
132* Data:: Examining data
e2e0bcd1 133* Macros:: Preprocessor Macros
b37052ae 134* Tracepoints:: Debugging remote targets non-intrusively
df0cd8c5 135* Overlays:: Debugging programs that use overlays
6d2ebf8b
SS
136
137* Languages:: Using @value{GDBN} with different languages
138
139* Symbols:: Examining the symbol table
140* Altering:: Altering execution
141* GDB Files:: @value{GDBN} files
142* Targets:: Specifying a debugging target
6b2f586d 143* Remote Debugging:: Debugging remote programs
6d2ebf8b
SS
144* Configurations:: Configuration-specific information
145* Controlling GDB:: Controlling @value{GDBN}
146* Sequences:: Canned sequences of commands
c4555f82 147* TUI:: @value{GDBN} Text User Interface
21c294e6 148* Interpreters:: Command Interpreters
6d2ebf8b
SS
149* Emacs:: Using @value{GDBN} under @sc{gnu} Emacs
150* Annotations:: @value{GDBN}'s annotation interface.
7162c0ca 151* GDB/MI:: @value{GDBN}'s Machine Interface.
6d2ebf8b
SS
152
153* GDB Bugs:: Reporting bugs in @value{GDBN}
154* Formatting Documentation:: How to format and print @value{GDBN} documentation
155
156* Command Line Editing:: Command Line Editing
157* Using History Interactively:: Using History Interactively
158* Installing GDB:: Installing GDB
eb12ee30 159* Maintenance Commands:: Maintenance Commands
e0ce93ac 160* Remote Protocol:: GDB Remote Serial Protocol
f418dd93 161* Agent Expressions:: The GDB Agent Expression Mechanism
aab4e0ec
AC
162* Copying:: GNU General Public License says
163 how you can copy and share GDB
6826cf00 164* GNU Free Documentation License:: The license for this documentation
6d2ebf8b
SS
165* Index:: Index
166@end menu
167
6c0e9fb3 168@end ifnottex
c906108c 169
449f3b6c 170@contents
449f3b6c 171
6d2ebf8b 172@node Summary
c906108c
SS
173@unnumbered Summary of @value{GDBN}
174
175The purpose of a debugger such as @value{GDBN} is to allow you to see what is
176going on ``inside'' another program while it executes---or what another
177program was doing at the moment it crashed.
178
179@value{GDBN} can do four main kinds of things (plus other things in support of
180these) to help you catch bugs in the act:
181
182@itemize @bullet
183@item
184Start your program, specifying anything that might affect its behavior.
185
186@item
187Make your program stop on specified conditions.
188
189@item
190Examine what has happened, when your program has stopped.
191
192@item
193Change things in your program, so you can experiment with correcting the
194effects of one bug and go on to learn about another.
195@end itemize
196
49efadf5 197You can use @value{GDBN} to debug programs written in C and C@t{++}.
c906108c 198For more information, see @ref{Support,,Supported languages}.
c906108c
SS
199For more information, see @ref{C,,C and C++}.
200
cce74817 201@cindex Modula-2
e632838e
AC
202Support for Modula-2 is partial. For information on Modula-2, see
203@ref{Modula-2,,Modula-2}.
c906108c 204
cce74817
JM
205@cindex Pascal
206Debugging Pascal programs which use sets, subranges, file variables, or
207nested functions does not currently work. @value{GDBN} does not support
208entering expressions, printing values, or similar features using Pascal
209syntax.
c906108c 210
c906108c
SS
211@cindex Fortran
212@value{GDBN} can be used to debug programs written in Fortran, although
53a5351d 213it may be necessary to refer to some variables with a trailing
cce74817 214underscore.
c906108c 215
b37303ee
AF
216@value{GDBN} can be used to debug programs written in Objective-C,
217using either the Apple/NeXT or the GNU Objective-C runtime.
218
c906108c
SS
219@menu
220* Free Software:: Freely redistributable software
221* Contributors:: Contributors to GDB
222@end menu
223
6d2ebf8b 224@node Free Software
c906108c
SS
225@unnumberedsec Free software
226
5d161b24 227@value{GDBN} is @dfn{free software}, protected by the @sc{gnu}
c906108c
SS
228General Public License
229(GPL). The GPL gives you the freedom to copy or adapt a licensed
230program---but every person getting a copy also gets with it the
231freedom to modify that copy (which means that they must get access to
232the source code), and the freedom to distribute further copies.
233Typical software companies use copyrights to limit your freedoms; the
234Free Software Foundation uses the GPL to preserve these freedoms.
235
236Fundamentally, the General Public License is a license which says that
237you have these freedoms and that you cannot take these freedoms away
238from anyone else.
239
2666264b 240@unnumberedsec Free Software Needs Free Documentation
959acfd1
EZ
241
242The biggest deficiency in the free software community today is not in
243the software---it is the lack of good free documentation that we can
244include with the free software. Many of our most important
245programs do not come with free reference manuals and free introductory
246texts. Documentation is an essential part of any software package;
247when an important free software package does not come with a free
248manual and a free tutorial, that is a major gap. We have many such
249gaps today.
250
251Consider Perl, for instance. The tutorial manuals that people
252normally use are non-free. How did this come about? Because the
253authors of those manuals published them with restrictive terms---no
254copying, no modification, source files not available---which exclude
255them from the free software world.
256
257That wasn't the first time this sort of thing happened, and it was far
258from the last. Many times we have heard a GNU user eagerly describe a
259manual that he is writing, his intended contribution to the community,
260only to learn that he had ruined everything by signing a publication
261contract to make it non-free.
262
263Free documentation, like free software, is a matter of freedom, not
264price. The problem with the non-free manual is not that publishers
265charge a price for printed copies---that in itself is fine. (The Free
266Software Foundation sells printed copies of manuals, too.) The
267problem is the restrictions on the use of the manual. Free manuals
268are available in source code form, and give you permission to copy and
269modify. Non-free manuals do not allow this.
270
271The criteria of freedom for a free manual are roughly the same as for
272free software. Redistribution (including the normal kinds of
273commercial redistribution) must be permitted, so that the manual can
274accompany every copy of the program, both on-line and on paper.
275
276Permission for modification of the technical content is crucial too.
277When people modify the software, adding or changing features, if they
278are conscientious they will change the manual too---so they can
279provide accurate and clear documentation for the modified program. A
280manual that leaves you no choice but to write a new manual to document
281a changed version of the program is not really available to our
282community.
283
284Some kinds of limits on the way modification is handled are
285acceptable. For example, requirements to preserve the original
286author's copyright notice, the distribution terms, or the list of
287authors, are ok. It is also no problem to require modified versions
288to include notice that they were modified. Even entire sections that
289may not be deleted or changed are acceptable, as long as they deal
290with nontechnical topics (like this one). These kinds of restrictions
291are acceptable because they don't obstruct the community's normal use
292of the manual.
293
294However, it must be possible to modify all the @emph{technical}
295content of the manual, and then distribute the result in all the usual
296media, through all the usual channels. Otherwise, the restrictions
297obstruct the use of the manual, it is not free, and we need another
298manual to replace it.
299
300Please spread the word about this issue. Our community continues to
301lose manuals to proprietary publishing. If we spread the word that
302free software needs free reference manuals and free tutorials, perhaps
303the next person who wants to contribute by writing documentation will
304realize, before it is too late, that only free manuals contribute to
305the free software community.
306
307If you are writing documentation, please insist on publishing it under
308the GNU Free Documentation License or another free documentation
309license. Remember that this decision requires your approval---you
310don't have to let the publisher decide. Some commercial publishers
311will use a free license if you insist, but they will not propose the
312option; it is up to you to raise the issue and say firmly that this is
313what you want. If the publisher you are dealing with refuses, please
314try other publishers. If you're not sure whether a proposed license
42584a72 315is free, write to @email{licensing@@gnu.org}.
959acfd1
EZ
316
317You can encourage commercial publishers to sell more free, copylefted
318manuals and tutorials by buying them, and particularly by buying
319copies from the publishers that paid for their writing or for major
320improvements. Meanwhile, try to avoid buying non-free documentation
321at all. Check the distribution terms of a manual before you buy it,
322and insist that whoever seeks your business must respect your freedom.
72c9928d
EZ
323Check the history of the book, and try to reward the publishers that
324have paid or pay the authors to work on it.
959acfd1
EZ
325
326The Free Software Foundation maintains a list of free documentation
327published by other publishers, at
328@url{http://www.fsf.org/doc/other-free-books.html}.
329
6d2ebf8b 330@node Contributors
96a2c332
SS
331@unnumberedsec Contributors to @value{GDBN}
332
333Richard Stallman was the original author of @value{GDBN}, and of many
334other @sc{gnu} programs. Many others have contributed to its
335development. This section attempts to credit major contributors. One
336of the virtues of free software is that everyone is free to contribute
337to it; with regret, we cannot actually acknowledge everyone here. The
338file @file{ChangeLog} in the @value{GDBN} distribution approximates a
c906108c
SS
339blow-by-blow account.
340
341Changes much prior to version 2.0 are lost in the mists of time.
342
343@quotation
344@emph{Plea:} Additions to this section are particularly welcome. If you
345or your friends (or enemies, to be evenhanded) have been unfairly
346omitted from this list, we would like to add your names!
347@end quotation
348
349So that they may not regard their many labors as thankless, we
350particularly thank those who shepherded @value{GDBN} through major
351releases:
faae5abe 352Andrew Cagney (releases 6.1, 6.0, 5.3, 5.2, 5.1 and 5.0);
c906108c
SS
353Jim Blandy (release 4.18);
354Jason Molenda (release 4.17);
355Stan Shebs (release 4.14);
356Fred Fish (releases 4.16, 4.15, 4.13, 4.12, 4.11, 4.10, and 4.9);
357Stu Grossman and John Gilmore (releases 4.8, 4.7, 4.6, 4.5, and 4.4);
358John Gilmore (releases 4.3, 4.2, 4.1, 4.0, and 3.9);
359Jim Kingdon (releases 3.5, 3.4, and 3.3);
360and Randy Smith (releases 3.2, 3.1, and 3.0).
361
362Richard Stallman, assisted at various times by Peter TerMaat, Chris
363Hanson, and Richard Mlynarik, handled releases through 2.8.
364
b37052ae
EZ
365Michael Tiemann is the author of most of the @sc{gnu} C@t{++} support
366in @value{GDBN}, with significant additional contributions from Per
367Bothner and Daniel Berlin. James Clark wrote the @sc{gnu} C@t{++}
368demangler. Early work on C@t{++} was by Peter TerMaat (who also did
369much general update work leading to release 3.0).
c906108c 370
b37052ae 371@value{GDBN} uses the BFD subroutine library to examine multiple
c906108c
SS
372object-file formats; BFD was a joint project of David V.
373Henkel-Wallace, Rich Pixley, Steve Chamberlain, and John Gilmore.
374
375David Johnson wrote the original COFF support; Pace Willison did
376the original support for encapsulated COFF.
377
0179ffac 378Brent Benson of Harris Computer Systems contributed DWARF 2 support.
c906108c
SS
379
380Adam de Boor and Bradley Davis contributed the ISI Optimum V support.
381Per Bothner, Noboyuki Hikichi, and Alessandro Forin contributed MIPS
382support.
383Jean-Daniel Fekete contributed Sun 386i support.
384Chris Hanson improved the HP9000 support.
385Noboyuki Hikichi and Tomoyuki Hasei contributed Sony/News OS 3 support.
386David Johnson contributed Encore Umax support.
387Jyrki Kuoppala contributed Altos 3068 support.
388Jeff Law contributed HP PA and SOM support.
389Keith Packard contributed NS32K support.
390Doug Rabson contributed Acorn Risc Machine support.
391Bob Rusk contributed Harris Nighthawk CX-UX support.
392Chris Smith contributed Convex support (and Fortran debugging).
393Jonathan Stone contributed Pyramid support.
394Michael Tiemann contributed SPARC support.
395Tim Tucker contributed support for the Gould NP1 and Gould Powernode.
396Pace Willison contributed Intel 386 support.
397Jay Vosburgh contributed Symmetry support.
a37295f9 398Marko Mlinar contributed OpenRISC 1000 support.
c906108c 399
1104b9e7 400Andreas Schwab contributed M68K @sc{gnu}/Linux support.
c906108c
SS
401
402Rich Schaefer and Peter Schauer helped with support of SunOS shared
403libraries.
404
405Jay Fenlason and Roland McGrath ensured that @value{GDBN} and GAS agree
406about several machine instruction sets.
407
408Patrick Duval, Ted Goldstein, Vikram Koka and Glenn Engel helped develop
409remote debugging. Intel Corporation, Wind River Systems, AMD, and ARM
410contributed remote debugging modules for the i960, VxWorks, A29K UDI,
411and RDI targets, respectively.
412
413Brian Fox is the author of the readline libraries providing
414command-line editing and command history.
415
7a292a7a
SS
416Andrew Beers of SUNY Buffalo wrote the language-switching code, the
417Modula-2 support, and contributed the Languages chapter of this manual.
c906108c 418
5d161b24 419Fred Fish wrote most of the support for Unix System Vr4.
b37052ae 420He also enhanced the command-completion support to cover C@t{++} overloaded
c906108c 421symbols.
c906108c 422
f24c5e49
KI
423Hitachi America (now Renesas America), Ltd. sponsored the support for
424H8/300, H8/500, and Super-H processors.
c906108c
SS
425
426NEC sponsored the support for the v850, Vr4xxx, and Vr5xxx processors.
427
f24c5e49
KI
428Mitsubishi (now Renesas) sponsored the support for D10V, D30V, and M32R/D
429processors.
c906108c
SS
430
431Toshiba sponsored the support for the TX39 Mips processor.
432
433Matsushita sponsored the support for the MN10200 and MN10300 processors.
434
96a2c332 435Fujitsu sponsored the support for SPARClite and FR30 processors.
c906108c
SS
436
437Kung Hsu, Jeff Law, and Rick Sladkey added support for hardware
438watchpoints.
439
440Michael Snyder added support for tracepoints.
441
442Stu Grossman wrote gdbserver.
443
444Jim Kingdon, Peter Schauer, Ian Taylor, and Stu Grossman made
96a2c332 445nearly innumerable bug fixes and cleanups throughout @value{GDBN}.
c906108c
SS
446
447The following people at the Hewlett-Packard Company contributed
448support for the PA-RISC 2.0 architecture, HP-UX 10.20, 10.30, and 11.0
b37052ae 449(narrow mode), HP's implementation of kernel threads, HP's aC@t{++}
d0d5df6f
AC
450compiler, and the Text User Interface (nee Terminal User Interface):
451Ben Krepp, Richard Title, John Bishop, Susan Macchia, Kathy Mann,
452Satish Pai, India Paul, Steve Rehrauer, and Elena Zannoni. Kim Haase
453provided HP-specific information in this manual.
c906108c 454
b37052ae
EZ
455DJ Delorie ported @value{GDBN} to MS-DOS, for the DJGPP project.
456Robert Hoehne made significant contributions to the DJGPP port.
457
96a2c332
SS
458Cygnus Solutions has sponsored @value{GDBN} maintenance and much of its
459development since 1991. Cygnus engineers who have worked on @value{GDBN}
2df3850c
JM
460fulltime include Mark Alexander, Jim Blandy, Per Bothner, Kevin
461Buettner, Edith Epstein, Chris Faylor, Fred Fish, Martin Hunt, Jim
462Ingham, John Gilmore, Stu Grossman, Kung Hsu, Jim Kingdon, John Metzler,
463Fernando Nasser, Geoffrey Noer, Dawn Perchik, Rich Pixley, Zdenek
464Radouch, Keith Seitz, Stan Shebs, David Taylor, and Elena Zannoni. In
465addition, Dave Brolley, Ian Carmichael, Steve Chamberlain, Nick Clifton,
466JT Conklin, Stan Cox, DJ Delorie, Ulrich Drepper, Frank Eigler, Doug
467Evans, Sean Fagan, David Henkel-Wallace, Richard Henderson, Jeff
468Holcomb, Jeff Law, Jim Lemke, Tom Lord, Bob Manson, Michael Meissner,
469Jason Merrill, Catherine Moore, Drew Moseley, Ken Raeburn, Gavin
470Romig-Koch, Rob Savoye, Jamie Smith, Mike Stump, Ian Taylor, Angela
471Thomas, Michael Tiemann, Tom Tromey, Ron Unrau, Jim Wilson, and David
472Zuhn have made contributions both large and small.
c906108c 473
e2e0bcd1
JB
474Jim Blandy added support for preprocessor macros, while working for Red
475Hat.
c906108c 476
6d2ebf8b 477@node Sample Session
c906108c
SS
478@chapter A Sample @value{GDBN} Session
479
480You can use this manual at your leisure to read all about @value{GDBN}.
481However, a handful of commands are enough to get started using the
482debugger. This chapter illustrates those commands.
483
484@iftex
485In this sample session, we emphasize user input like this: @b{input},
486to make it easier to pick out from the surrounding output.
487@end iftex
488
489@c FIXME: this example may not be appropriate for some configs, where
490@c FIXME...primary interest is in remote use.
491
492One of the preliminary versions of @sc{gnu} @code{m4} (a generic macro
493processor) exhibits the following bug: sometimes, when we change its
494quote strings from the default, the commands used to capture one macro
495definition within another stop working. In the following short @code{m4}
496session, we define a macro @code{foo} which expands to @code{0000}; we
497then use the @code{m4} built-in @code{defn} to define @code{bar} as the
498same thing. However, when we change the open quote string to
499@code{<QUOTE>} and the close quote string to @code{<UNQUOTE>}, the same
500procedure fails to define a new synonym @code{baz}:
501
502@smallexample
503$ @b{cd gnu/m4}
504$ @b{./m4}
505@b{define(foo,0000)}
506
507@b{foo}
5080000
509@b{define(bar,defn(`foo'))}
510
511@b{bar}
5120000
513@b{changequote(<QUOTE>,<UNQUOTE>)}
514
515@b{define(baz,defn(<QUOTE>foo<UNQUOTE>))}
516@b{baz}
517@b{C-d}
518m4: End of input: 0: fatal error: EOF in string
519@end smallexample
520
521@noindent
522Let us use @value{GDBN} to try to see what is going on.
523
c906108c
SS
524@smallexample
525$ @b{@value{GDBP} m4}
526@c FIXME: this falsifies the exact text played out, to permit smallbook
527@c FIXME... format to come out better.
528@value{GDBN} is free software and you are welcome to distribute copies
5d161b24 529 of it under certain conditions; type "show copying" to see
c906108c 530 the conditions.
5d161b24 531There is absolutely no warranty for @value{GDBN}; type "show warranty"
c906108c
SS
532 for details.
533
534@value{GDBN} @value{GDBVN}, Copyright 1999 Free Software Foundation, Inc...
535(@value{GDBP})
536@end smallexample
c906108c
SS
537
538@noindent
539@value{GDBN} reads only enough symbol data to know where to find the
540rest when needed; as a result, the first prompt comes up very quickly.
541We now tell @value{GDBN} to use a narrower display width than usual, so
542that examples fit in this manual.
543
544@smallexample
545(@value{GDBP}) @b{set width 70}
546@end smallexample
547
548@noindent
549We need to see how the @code{m4} built-in @code{changequote} works.
550Having looked at the source, we know the relevant subroutine is
551@code{m4_changequote}, so we set a breakpoint there with the @value{GDBN}
552@code{break} command.
553
554@smallexample
555(@value{GDBP}) @b{break m4_changequote}
556Breakpoint 1 at 0x62f4: file builtin.c, line 879.
557@end smallexample
558
559@noindent
560Using the @code{run} command, we start @code{m4} running under @value{GDBN}
561control; as long as control does not reach the @code{m4_changequote}
562subroutine, the program runs as usual:
563
564@smallexample
565(@value{GDBP}) @b{run}
566Starting program: /work/Editorial/gdb/gnu/m4/m4
567@b{define(foo,0000)}
568
569@b{foo}
5700000
571@end smallexample
572
573@noindent
574To trigger the breakpoint, we call @code{changequote}. @value{GDBN}
575suspends execution of @code{m4}, displaying information about the
576context where it stops.
577
578@smallexample
579@b{changequote(<QUOTE>,<UNQUOTE>)}
580
5d161b24 581Breakpoint 1, m4_changequote (argc=3, argv=0x33c70)
c906108c
SS
582 at builtin.c:879
583879 if (bad_argc(TOKEN_DATA_TEXT(argv[0]),argc,1,3))
584@end smallexample
585
586@noindent
587Now we use the command @code{n} (@code{next}) to advance execution to
588the next line of the current function.
589
590@smallexample
591(@value{GDBP}) @b{n}
592882 set_quotes((argc >= 2) ? TOKEN_DATA_TEXT(argv[1])\
593 : nil,
594@end smallexample
595
596@noindent
597@code{set_quotes} looks like a promising subroutine. We can go into it
598by using the command @code{s} (@code{step}) instead of @code{next}.
599@code{step} goes to the next line to be executed in @emph{any}
600subroutine, so it steps into @code{set_quotes}.
601
602@smallexample
603(@value{GDBP}) @b{s}
604set_quotes (lq=0x34c78 "<QUOTE>", rq=0x34c88 "<UNQUOTE>")
605 at input.c:530
606530 if (lquote != def_lquote)
607@end smallexample
608
609@noindent
610The display that shows the subroutine where @code{m4} is now
611suspended (and its arguments) is called a stack frame display. It
612shows a summary of the stack. We can use the @code{backtrace}
613command (which can also be spelled @code{bt}), to see where we are
614in the stack as a whole: the @code{backtrace} command displays a
615stack frame for each active subroutine.
616
617@smallexample
618(@value{GDBP}) @b{bt}
619#0 set_quotes (lq=0x34c78 "<QUOTE>", rq=0x34c88 "<UNQUOTE>")
620 at input.c:530
5d161b24 621#1 0x6344 in m4_changequote (argc=3, argv=0x33c70)
c906108c
SS
622 at builtin.c:882
623#2 0x8174 in expand_macro (sym=0x33320) at macro.c:242
624#3 0x7a88 in expand_token (obs=0x0, t=209696, td=0xf7fffa30)
625 at macro.c:71
626#4 0x79dc in expand_input () at macro.c:40
627#5 0x2930 in main (argc=0, argv=0xf7fffb20) at m4.c:195
628@end smallexample
629
630@noindent
631We step through a few more lines to see what happens. The first two
632times, we can use @samp{s}; the next two times we use @code{n} to avoid
633falling into the @code{xstrdup} subroutine.
634
635@smallexample
636(@value{GDBP}) @b{s}
6370x3b5c 532 if (rquote != def_rquote)
638(@value{GDBP}) @b{s}
6390x3b80 535 lquote = (lq == nil || *lq == '\0') ? \
640def_lquote : xstrdup(lq);
641(@value{GDBP}) @b{n}
642536 rquote = (rq == nil || *rq == '\0') ? def_rquote\
643 : xstrdup(rq);
644(@value{GDBP}) @b{n}
645538 len_lquote = strlen(rquote);
646@end smallexample
647
648@noindent
649The last line displayed looks a little odd; we can examine the variables
650@code{lquote} and @code{rquote} to see if they are in fact the new left
651and right quotes we specified. We use the command @code{p}
652(@code{print}) to see their values.
653
654@smallexample
655(@value{GDBP}) @b{p lquote}
656$1 = 0x35d40 "<QUOTE>"
657(@value{GDBP}) @b{p rquote}
658$2 = 0x35d50 "<UNQUOTE>"
659@end smallexample
660
661@noindent
662@code{lquote} and @code{rquote} are indeed the new left and right quotes.
663To look at some context, we can display ten lines of source
664surrounding the current line with the @code{l} (@code{list}) command.
665
666@smallexample
667(@value{GDBP}) @b{l}
668533 xfree(rquote);
669534
670535 lquote = (lq == nil || *lq == '\0') ? def_lquote\
671 : xstrdup (lq);
672536 rquote = (rq == nil || *rq == '\0') ? def_rquote\
673 : xstrdup (rq);
674537
675538 len_lquote = strlen(rquote);
676539 len_rquote = strlen(lquote);
677540 @}
678541
679542 void
680@end smallexample
681
682@noindent
683Let us step past the two lines that set @code{len_lquote} and
684@code{len_rquote}, and then examine the values of those variables.
685
686@smallexample
687(@value{GDBP}) @b{n}
688539 len_rquote = strlen(lquote);
689(@value{GDBP}) @b{n}
690540 @}
691(@value{GDBP}) @b{p len_lquote}
692$3 = 9
693(@value{GDBP}) @b{p len_rquote}
694$4 = 7
695@end smallexample
696
697@noindent
698That certainly looks wrong, assuming @code{len_lquote} and
699@code{len_rquote} are meant to be the lengths of @code{lquote} and
700@code{rquote} respectively. We can set them to better values using
701the @code{p} command, since it can print the value of
702any expression---and that expression can include subroutine calls and
703assignments.
704
705@smallexample
706(@value{GDBP}) @b{p len_lquote=strlen(lquote)}
707$5 = 7
708(@value{GDBP}) @b{p len_rquote=strlen(rquote)}
709$6 = 9
710@end smallexample
711
712@noindent
713Is that enough to fix the problem of using the new quotes with the
714@code{m4} built-in @code{defn}? We can allow @code{m4} to continue
715executing with the @code{c} (@code{continue}) command, and then try the
716example that caused trouble initially:
717
718@smallexample
719(@value{GDBP}) @b{c}
720Continuing.
721
722@b{define(baz,defn(<QUOTE>foo<UNQUOTE>))}
723
724baz
7250000
726@end smallexample
727
728@noindent
729Success! The new quotes now work just as well as the default ones. The
730problem seems to have been just the two typos defining the wrong
731lengths. We allow @code{m4} exit by giving it an EOF as input:
732
733@smallexample
734@b{C-d}
735Program exited normally.
736@end smallexample
737
738@noindent
739The message @samp{Program exited normally.} is from @value{GDBN}; it
740indicates @code{m4} has finished executing. We can end our @value{GDBN}
741session with the @value{GDBN} @code{quit} command.
742
743@smallexample
744(@value{GDBP}) @b{quit}
745@end smallexample
c906108c 746
6d2ebf8b 747@node Invocation
c906108c
SS
748@chapter Getting In and Out of @value{GDBN}
749
750This chapter discusses how to start @value{GDBN}, and how to get out of it.
5d161b24 751The essentials are:
c906108c 752@itemize @bullet
5d161b24 753@item
53a5351d 754type @samp{@value{GDBP}} to start @value{GDBN}.
5d161b24 755@item
c906108c
SS
756type @kbd{quit} or @kbd{C-d} to exit.
757@end itemize
758
759@menu
760* Invoking GDB:: How to start @value{GDBN}
761* Quitting GDB:: How to quit @value{GDBN}
762* Shell Commands:: How to use shell commands inside @value{GDBN}
0fac0b41 763* Logging output:: How to log @value{GDBN}'s output to a file
c906108c
SS
764@end menu
765
6d2ebf8b 766@node Invoking GDB
c906108c
SS
767@section Invoking @value{GDBN}
768
c906108c
SS
769Invoke @value{GDBN} by running the program @code{@value{GDBP}}. Once started,
770@value{GDBN} reads commands from the terminal until you tell it to exit.
771
772You can also run @code{@value{GDBP}} with a variety of arguments and options,
773to specify more of your debugging environment at the outset.
774
c906108c
SS
775The command-line options described here are designed
776to cover a variety of situations; in some environments, some of these
5d161b24 777options may effectively be unavailable.
c906108c
SS
778
779The most usual way to start @value{GDBN} is with one argument,
780specifying an executable program:
781
474c8240 782@smallexample
c906108c 783@value{GDBP} @var{program}
474c8240 784@end smallexample
c906108c 785
c906108c
SS
786@noindent
787You can also start with both an executable program and a core file
788specified:
789
474c8240 790@smallexample
c906108c 791@value{GDBP} @var{program} @var{core}
474c8240 792@end smallexample
c906108c
SS
793
794You can, instead, specify a process ID as a second argument, if you want
795to debug a running process:
796
474c8240 797@smallexample
c906108c 798@value{GDBP} @var{program} 1234
474c8240 799@end smallexample
c906108c
SS
800
801@noindent
802would attach @value{GDBN} to process @code{1234} (unless you also have a file
803named @file{1234}; @value{GDBN} does check for a core file first).
804
c906108c 805Taking advantage of the second command-line argument requires a fairly
2df3850c
JM
806complete operating system; when you use @value{GDBN} as a remote
807debugger attached to a bare board, there may not be any notion of
808``process'', and there is often no way to get a core dump. @value{GDBN}
809will warn you if it is unable to attach or to read core dumps.
c906108c 810
aa26fa3a
TT
811You can optionally have @code{@value{GDBP}} pass any arguments after the
812executable file to the inferior using @code{--args}. This option stops
813option processing.
474c8240 814@smallexample
aa26fa3a 815gdb --args gcc -O2 -c foo.c
474c8240 816@end smallexample
aa26fa3a
TT
817This will cause @code{@value{GDBP}} to debug @code{gcc}, and to set
818@code{gcc}'s command-line arguments (@pxref{Arguments}) to @samp{-O2 -c foo.c}.
819
96a2c332 820You can run @code{@value{GDBP}} without printing the front material, which describes
c906108c
SS
821@value{GDBN}'s non-warranty, by specifying @code{-silent}:
822
823@smallexample
824@value{GDBP} -silent
825@end smallexample
826
827@noindent
828You can further control how @value{GDBN} starts up by using command-line
829options. @value{GDBN} itself can remind you of the options available.
830
831@noindent
832Type
833
474c8240 834@smallexample
c906108c 835@value{GDBP} -help
474c8240 836@end smallexample
c906108c
SS
837
838@noindent
839to display all available options and briefly describe their use
840(@samp{@value{GDBP} -h} is a shorter equivalent).
841
842All options and command line arguments you give are processed
843in sequential order. The order makes a difference when the
844@samp{-x} option is used.
845
846
847@menu
c906108c
SS
848* File Options:: Choosing files
849* Mode Options:: Choosing modes
850@end menu
851
6d2ebf8b 852@node File Options
c906108c
SS
853@subsection Choosing files
854
2df3850c 855When @value{GDBN} starts, it reads any arguments other than options as
c906108c
SS
856specifying an executable file and core file (or process ID). This is
857the same as if the arguments were specified by the @samp{-se} and
19837790
MS
858@samp{-c} (or @samp{-p} options respectively. (@value{GDBN} reads the
859first argument that does not have an associated option flag as
860equivalent to the @samp{-se} option followed by that argument; and the
861second argument that does not have an associated option flag, if any, as
862equivalent to the @samp{-c}/@samp{-p} option followed by that argument.)
863If the second argument begins with a decimal digit, @value{GDBN} will
864first attempt to attach to it as a process, and if that fails, attempt
865to open it as a corefile. If you have a corefile whose name begins with
b383017d 866a digit, you can prevent @value{GDBN} from treating it as a pid by
79f12247 867prefixing it with @file{./}, eg. @file{./12345}.
7a292a7a
SS
868
869If @value{GDBN} has not been configured to included core file support,
870such as for most embedded targets, then it will complain about a second
871argument and ignore it.
c906108c
SS
872
873Many options have both long and short forms; both are shown in the
874following list. @value{GDBN} also recognizes the long forms if you truncate
875them, so long as enough of the option is present to be unambiguous.
876(If you prefer, you can flag option arguments with @samp{--} rather
877than @samp{-}, though we illustrate the more usual convention.)
878
d700128c
EZ
879@c NOTE: the @cindex entries here use double dashes ON PURPOSE. This
880@c way, both those who look for -foo and --foo in the index, will find
881@c it.
882
c906108c
SS
883@table @code
884@item -symbols @var{file}
885@itemx -s @var{file}
d700128c
EZ
886@cindex @code{--symbols}
887@cindex @code{-s}
c906108c
SS
888Read symbol table from file @var{file}.
889
890@item -exec @var{file}
891@itemx -e @var{file}
d700128c
EZ
892@cindex @code{--exec}
893@cindex @code{-e}
7a292a7a
SS
894Use file @var{file} as the executable file to execute when appropriate,
895and for examining pure data in conjunction with a core dump.
c906108c
SS
896
897@item -se @var{file}
d700128c 898@cindex @code{--se}
c906108c
SS
899Read symbol table from file @var{file} and use it as the executable
900file.
901
c906108c
SS
902@item -core @var{file}
903@itemx -c @var{file}
d700128c
EZ
904@cindex @code{--core}
905@cindex @code{-c}
b383017d 906Use file @var{file} as a core dump to examine.
c906108c
SS
907
908@item -c @var{number}
19837790
MS
909@item -pid @var{number}
910@itemx -p @var{number}
911@cindex @code{--pid}
912@cindex @code{-p}
913Connect to process ID @var{number}, as with the @code{attach} command.
914If there is no such process, @value{GDBN} will attempt to open a core
915file named @var{number}.
c906108c
SS
916
917@item -command @var{file}
918@itemx -x @var{file}
d700128c
EZ
919@cindex @code{--command}
920@cindex @code{-x}
c906108c
SS
921Execute @value{GDBN} commands from file @var{file}. @xref{Command
922Files,, Command files}.
923
924@item -directory @var{directory}
925@itemx -d @var{directory}
d700128c
EZ
926@cindex @code{--directory}
927@cindex @code{-d}
c906108c
SS
928Add @var{directory} to the path to search for source files.
929
c906108c
SS
930@item -m
931@itemx -mapped
d700128c
EZ
932@cindex @code{--mapped}
933@cindex @code{-m}
c906108c
SS
934@emph{Warning: this option depends on operating system facilities that are not
935supported on all systems.}@*
936If memory-mapped files are available on your system through the @code{mmap}
5d161b24 937system call, you can use this option
c906108c
SS
938to have @value{GDBN} write the symbols from your
939program into a reusable file in the current directory. If the program you are debugging is
96a2c332 940called @file{/tmp/fred}, the mapped symbol file is @file{/tmp/fred.syms}.
c906108c
SS
941Future @value{GDBN} debugging sessions notice the presence of this file,
942and can quickly map in symbol information from it, rather than reading
943the symbol table from the executable program.
944
945The @file{.syms} file is specific to the host machine where @value{GDBN}
946is run. It holds an exact image of the internal @value{GDBN} symbol
947table. It cannot be shared across multiple host platforms.
c906108c 948
c906108c
SS
949@item -r
950@itemx -readnow
d700128c
EZ
951@cindex @code{--readnow}
952@cindex @code{-r}
c906108c
SS
953Read each symbol file's entire symbol table immediately, rather than
954the default, which is to read it incrementally as it is needed.
955This makes startup slower, but makes future operations faster.
53a5351d 956
c906108c
SS
957@end table
958
2df3850c 959You typically combine the @code{-mapped} and @code{-readnow} options in
c906108c 960order to build a @file{.syms} file that contains complete symbol
2df3850c
JM
961information. (@xref{Files,,Commands to specify files}, for information
962on @file{.syms} files.) A simple @value{GDBN} invocation to do nothing
963but build a @file{.syms} file for future use is:
c906108c 964
474c8240 965@smallexample
2df3850c 966gdb -batch -nx -mapped -readnow programname
474c8240 967@end smallexample
c906108c 968
6d2ebf8b 969@node Mode Options
c906108c
SS
970@subsection Choosing modes
971
972You can run @value{GDBN} in various alternative modes---for example, in
973batch mode or quiet mode.
974
975@table @code
976@item -nx
977@itemx -n
d700128c
EZ
978@cindex @code{--nx}
979@cindex @code{-n}
96565e91 980Do not execute commands found in any initialization files. Normally,
2df3850c
JM
981@value{GDBN} executes the commands in these files after all the command
982options and arguments have been processed. @xref{Command Files,,Command
983files}.
c906108c
SS
984
985@item -quiet
d700128c 986@itemx -silent
c906108c 987@itemx -q
d700128c
EZ
988@cindex @code{--quiet}
989@cindex @code{--silent}
990@cindex @code{-q}
c906108c
SS
991``Quiet''. Do not print the introductory and copyright messages. These
992messages are also suppressed in batch mode.
993
994@item -batch
d700128c 995@cindex @code{--batch}
c906108c
SS
996Run in batch mode. Exit with status @code{0} after processing all the
997command files specified with @samp{-x} (and all commands from
998initialization files, if not inhibited with @samp{-n}). Exit with
999nonzero status if an error occurs in executing the @value{GDBN} commands
1000in the command files.
1001
2df3850c
JM
1002Batch mode may be useful for running @value{GDBN} as a filter, for
1003example to download and run a program on another computer; in order to
1004make this more useful, the message
c906108c 1005
474c8240 1006@smallexample
c906108c 1007Program exited normally.
474c8240 1008@end smallexample
c906108c
SS
1009
1010@noindent
2df3850c
JM
1011(which is ordinarily issued whenever a program running under
1012@value{GDBN} control terminates) is not issued when running in batch
1013mode.
1014
1015@item -nowindows
1016@itemx -nw
d700128c
EZ
1017@cindex @code{--nowindows}
1018@cindex @code{-nw}
2df3850c 1019``No windows''. If @value{GDBN} comes with a graphical user interface
96a2c332 1020(GUI) built in, then this option tells @value{GDBN} to only use the command-line
2df3850c
JM
1021interface. If no GUI is available, this option has no effect.
1022
1023@item -windows
1024@itemx -w
d700128c
EZ
1025@cindex @code{--windows}
1026@cindex @code{-w}
2df3850c
JM
1027If @value{GDBN} includes a GUI, then this option requires it to be
1028used if possible.
c906108c
SS
1029
1030@item -cd @var{directory}
d700128c 1031@cindex @code{--cd}
c906108c
SS
1032Run @value{GDBN} using @var{directory} as its working directory,
1033instead of the current directory.
1034
c906108c
SS
1035@item -fullname
1036@itemx -f
d700128c
EZ
1037@cindex @code{--fullname}
1038@cindex @code{-f}
7a292a7a
SS
1039@sc{gnu} Emacs sets this option when it runs @value{GDBN} as a
1040subprocess. It tells @value{GDBN} to output the full file name and line
1041number in a standard, recognizable fashion each time a stack frame is
1042displayed (which includes each time your program stops). This
1043recognizable format looks like two @samp{\032} characters, followed by
1044the file name, line number and character position separated by colons,
1045and a newline. The Emacs-to-@value{GDBN} interface program uses the two
1046@samp{\032} characters as a signal to display the source code for the
1047frame.
c906108c 1048
d700128c
EZ
1049@item -epoch
1050@cindex @code{--epoch}
1051The Epoch Emacs-@value{GDBN} interface sets this option when it runs
1052@value{GDBN} as a subprocess. It tells @value{GDBN} to modify its print
1053routines so as to allow Epoch to display values of expressions in a
1054separate window.
1055
1056@item -annotate @var{level}
1057@cindex @code{--annotate}
1058This option sets the @dfn{annotation level} inside @value{GDBN}. Its
1059effect is identical to using @samp{set annotate @var{level}}
086432e2
AC
1060(@pxref{Annotations}). The annotation @var{level} controls how much
1061information @value{GDBN} prints together with its prompt, values of
1062expressions, source lines, and other types of output. Level 0 is the
1063normal, level 1 is for use when @value{GDBN} is run as a subprocess of
1064@sc{gnu} Emacs, level 3 is the maximum annotation suitable for programs
1065that control @value{GDBN}, and level 2 has been deprecated.
1066
1067The annotation mechanism has largely been superseeded by @sc{gdb/mi}
1068(@pxref{GDB/MI}).
d700128c 1069
aa26fa3a
TT
1070@item --args
1071@cindex @code{--args}
1072Change interpretation of command line so that arguments following the
1073executable file are passed as command line arguments to the inferior.
1074This option stops option processing.
1075
2df3850c
JM
1076@item -baud @var{bps}
1077@itemx -b @var{bps}
d700128c
EZ
1078@cindex @code{--baud}
1079@cindex @code{-b}
c906108c
SS
1080Set the line speed (baud rate or bits per second) of any serial
1081interface used by @value{GDBN} for remote debugging.
c906108c 1082
f47b1503
AS
1083@item -l @var{timeout}
1084@cindex @code{-l}
1085Set the timeout (in seconds) of any communication used by @value{GDBN}
1086for remote debugging.
1087
c906108c 1088@item -tty @var{device}
d700128c
EZ
1089@itemx -t @var{device}
1090@cindex @code{--tty}
1091@cindex @code{-t}
c906108c
SS
1092Run using @var{device} for your program's standard input and output.
1093@c FIXME: kingdon thinks there is more to -tty. Investigate.
c906108c 1094
53a5351d 1095@c resolve the situation of these eventually
c4555f82
SC
1096@item -tui
1097@cindex @code{--tui}
d0d5df6f
AC
1098Activate the @dfn{Text User Interface} when starting. The Text User
1099Interface manages several text windows on the terminal, showing
1100source, assembly, registers and @value{GDBN} command outputs
1101(@pxref{TUI, ,@value{GDBN} Text User Interface}). Alternatively, the
1102Text User Interface can be enabled by invoking the program
1103@samp{gdbtui}. Do not use this option if you run @value{GDBN} from
1104Emacs (@pxref{Emacs, ,Using @value{GDBN} under @sc{gnu} Emacs}).
53a5351d
JM
1105
1106@c @item -xdb
d700128c 1107@c @cindex @code{--xdb}
53a5351d
JM
1108@c Run in XDB compatibility mode, allowing the use of certain XDB commands.
1109@c For information, see the file @file{xdb_trans.html}, which is usually
1110@c installed in the directory @code{/opt/langtools/wdb/doc} on HP-UX
1111@c systems.
1112
d700128c
EZ
1113@item -interpreter @var{interp}
1114@cindex @code{--interpreter}
1115Use the interpreter @var{interp} for interface with the controlling
1116program or device. This option is meant to be set by programs which
94bbb2c0 1117communicate with @value{GDBN} using it as a back end.
21c294e6 1118@xref{Interpreters, , Command Interpreters}.
94bbb2c0 1119
da0f9dcd 1120@samp{--interpreter=mi} (or @samp{--interpreter=mi2}) causes
2fcf52f0 1121@value{GDBN} to use the @dfn{@sc{gdb/mi} interface} (@pxref{GDB/MI, ,
6c74ac8b
AC
1122The @sc{gdb/mi} Interface}) included since @var{GDBN} version 6.0. The
1123previous @sc{gdb/mi} interface, included in @value{GDBN} version 5.3 and
1124selected with @samp{--interpreter=mi1}, is deprecated. Earlier
1125@sc{gdb/mi} interfaces are no longer supported.
d700128c
EZ
1126
1127@item -write
1128@cindex @code{--write}
1129Open the executable and core files for both reading and writing. This
1130is equivalent to the @samp{set write on} command inside @value{GDBN}
1131(@pxref{Patching}).
1132
1133@item -statistics
1134@cindex @code{--statistics}
1135This option causes @value{GDBN} to print statistics about time and
1136memory usage after it completes each command and returns to the prompt.
1137
1138@item -version
1139@cindex @code{--version}
1140This option causes @value{GDBN} to print its version number and
1141no-warranty blurb, and exit.
1142
c906108c
SS
1143@end table
1144
6d2ebf8b 1145@node Quitting GDB
c906108c
SS
1146@section Quitting @value{GDBN}
1147@cindex exiting @value{GDBN}
1148@cindex leaving @value{GDBN}
1149
1150@table @code
1151@kindex quit @r{[}@var{expression}@r{]}
41afff9a 1152@kindex q @r{(@code{quit})}
96a2c332
SS
1153@item quit @r{[}@var{expression}@r{]}
1154@itemx q
1155To exit @value{GDBN}, use the @code{quit} command (abbreviated
1156@code{q}), or type an end-of-file character (usually @kbd{C-d}). If you
1157do not supply @var{expression}, @value{GDBN} will terminate normally;
1158otherwise it will terminate using the result of @var{expression} as the
1159error code.
c906108c
SS
1160@end table
1161
1162@cindex interrupt
1163An interrupt (often @kbd{C-c}) does not exit from @value{GDBN}, but rather
1164terminates the action of any @value{GDBN} command that is in progress and
1165returns to @value{GDBN} command level. It is safe to type the interrupt
1166character at any time because @value{GDBN} does not allow it to take effect
1167until a time when it is safe.
1168
c906108c
SS
1169If you have been using @value{GDBN} to control an attached process or
1170device, you can release it with the @code{detach} command
1171(@pxref{Attach, ,Debugging an already-running process}).
c906108c 1172
6d2ebf8b 1173@node Shell Commands
c906108c
SS
1174@section Shell commands
1175
1176If you need to execute occasional shell commands during your
1177debugging session, there is no need to leave or suspend @value{GDBN}; you can
1178just use the @code{shell} command.
1179
1180@table @code
1181@kindex shell
1182@cindex shell escape
1183@item shell @var{command string}
1184Invoke a standard shell to execute @var{command string}.
c906108c 1185If it exists, the environment variable @code{SHELL} determines which
d4f3574e
SS
1186shell to run. Otherwise @value{GDBN} uses the default shell
1187(@file{/bin/sh} on Unix systems, @file{COMMAND.COM} on MS-DOS, etc.).
c906108c
SS
1188@end table
1189
1190The utility @code{make} is often needed in development environments.
1191You do not have to use the @code{shell} command for this purpose in
1192@value{GDBN}:
1193
1194@table @code
1195@kindex make
1196@cindex calling make
1197@item make @var{make-args}
1198Execute the @code{make} program with the specified
1199arguments. This is equivalent to @samp{shell make @var{make-args}}.
1200@end table
1201
0fac0b41
DJ
1202@node Logging output
1203@section Logging output
1204@cindex logging @value{GDBN} output
1205
1206You may want to save the output of @value{GDBN} commands to a file.
1207There are several commands to control @value{GDBN}'s logging.
1208
1209@table @code
1210@kindex set logging
1211@item set logging on
1212Enable logging.
1213@item set logging off
1214Disable logging.
1215@item set logging file @var{file}
1216Change the name of the current logfile. The default logfile is @file{gdb.txt}.
1217@item set logging overwrite [on|off]
1218By default, @value{GDBN} will append to the logfile. Set @code{overwrite} if
1219you want @code{set logging on} to overwrite the logfile instead.
1220@item set logging redirect [on|off]
1221By default, @value{GDBN} output will go to both the terminal and the logfile.
1222Set @code{redirect} if you want output to go only to the log file.
1223@kindex show logging
1224@item show logging
1225Show the current values of the logging settings.
1226@end table
1227
6d2ebf8b 1228@node Commands
c906108c
SS
1229@chapter @value{GDBN} Commands
1230
1231You can abbreviate a @value{GDBN} command to the first few letters of the command
1232name, if that abbreviation is unambiguous; and you can repeat certain
1233@value{GDBN} commands by typing just @key{RET}. You can also use the @key{TAB}
1234key to get @value{GDBN} to fill out the rest of a word in a command (or to
1235show you the alternatives available, if there is more than one possibility).
1236
1237@menu
1238* Command Syntax:: How to give commands to @value{GDBN}
1239* Completion:: Command completion
1240* Help:: How to ask @value{GDBN} for help
1241@end menu
1242
6d2ebf8b 1243@node Command Syntax
c906108c
SS
1244@section Command syntax
1245
1246A @value{GDBN} command is a single line of input. There is no limit on
1247how long it can be. It starts with a command name, which is followed by
1248arguments whose meaning depends on the command name. For example, the
1249command @code{step} accepts an argument which is the number of times to
1250step, as in @samp{step 5}. You can also use the @code{step} command
96a2c332 1251with no arguments. Some commands do not allow any arguments.
c906108c
SS
1252
1253@cindex abbreviation
1254@value{GDBN} command names may always be truncated if that abbreviation is
1255unambiguous. Other possible command abbreviations are listed in the
1256documentation for individual commands. In some cases, even ambiguous
1257abbreviations are allowed; for example, @code{s} is specially defined as
1258equivalent to @code{step} even though there are other commands whose
1259names start with @code{s}. You can test abbreviations by using them as
1260arguments to the @code{help} command.
1261
1262@cindex repeating commands
41afff9a 1263@kindex RET @r{(repeat last command)}
c906108c 1264A blank line as input to @value{GDBN} (typing just @key{RET}) means to
96a2c332 1265repeat the previous command. Certain commands (for example, @code{run})
c906108c
SS
1266will not repeat this way; these are commands whose unintentional
1267repetition might cause trouble and which you are unlikely to want to
1268repeat.
1269
1270The @code{list} and @code{x} commands, when you repeat them with
1271@key{RET}, construct new arguments rather than repeating
1272exactly as typed. This permits easy scanning of source or memory.
1273
1274@value{GDBN} can also use @key{RET} in another way: to partition lengthy
1275output, in a way similar to the common utility @code{more}
1276(@pxref{Screen Size,,Screen size}). Since it is easy to press one
1277@key{RET} too many in this situation, @value{GDBN} disables command
1278repetition after any command that generates this sort of display.
1279
41afff9a 1280@kindex # @r{(a comment)}
c906108c
SS
1281@cindex comment
1282Any text from a @kbd{#} to the end of the line is a comment; it does
1283nothing. This is useful mainly in command files (@pxref{Command
1284Files,,Command files}).
1285
88118b3a
TT
1286@cindex repeating command sequences
1287@kindex C-o @r{(operate-and-get-next)}
1288The @kbd{C-o} binding is useful for repeating a complex sequence of
1289commands. This command accepts the current line, like @kbd{RET}, and
1290then fetches the next line relative to the current line from the history
1291for editing.
1292
6d2ebf8b 1293@node Completion
c906108c
SS
1294@section Command completion
1295
1296@cindex completion
1297@cindex word completion
1298@value{GDBN} can fill in the rest of a word in a command for you, if there is
1299only one possibility; it can also show you what the valid possibilities
1300are for the next word in a command, at any time. This works for @value{GDBN}
1301commands, @value{GDBN} subcommands, and the names of symbols in your program.
1302
1303Press the @key{TAB} key whenever you want @value{GDBN} to fill out the rest
1304of a word. If there is only one possibility, @value{GDBN} fills in the
1305word, and waits for you to finish the command (or press @key{RET} to
1306enter it). For example, if you type
1307
1308@c FIXME "@key" does not distinguish its argument sufficiently to permit
1309@c complete accuracy in these examples; space introduced for clarity.
1310@c If texinfo enhancements make it unnecessary, it would be nice to
1311@c replace " @key" by "@key" in the following...
474c8240 1312@smallexample
c906108c 1313(@value{GDBP}) info bre @key{TAB}
474c8240 1314@end smallexample
c906108c
SS
1315
1316@noindent
1317@value{GDBN} fills in the rest of the word @samp{breakpoints}, since that is
1318the only @code{info} subcommand beginning with @samp{bre}:
1319
474c8240 1320@smallexample
c906108c 1321(@value{GDBP}) info breakpoints
474c8240 1322@end smallexample
c906108c
SS
1323
1324@noindent
1325You can either press @key{RET} at this point, to run the @code{info
1326breakpoints} command, or backspace and enter something else, if
1327@samp{breakpoints} does not look like the command you expected. (If you
1328were sure you wanted @code{info breakpoints} in the first place, you
1329might as well just type @key{RET} immediately after @samp{info bre},
1330to exploit command abbreviations rather than command completion).
1331
1332If there is more than one possibility for the next word when you press
1333@key{TAB}, @value{GDBN} sounds a bell. You can either supply more
1334characters and try again, or just press @key{TAB} a second time;
1335@value{GDBN} displays all the possible completions for that word. For
1336example, you might want to set a breakpoint on a subroutine whose name
1337begins with @samp{make_}, but when you type @kbd{b make_@key{TAB}} @value{GDBN}
1338just sounds the bell. Typing @key{TAB} again displays all the
1339function names in your program that begin with those characters, for
1340example:
1341
474c8240 1342@smallexample
c906108c
SS
1343(@value{GDBP}) b make_ @key{TAB}
1344@exdent @value{GDBN} sounds bell; press @key{TAB} again, to see:
5d161b24
DB
1345make_a_section_from_file make_environ
1346make_abs_section make_function_type
1347make_blockvector make_pointer_type
1348make_cleanup make_reference_type
c906108c
SS
1349make_command make_symbol_completion_list
1350(@value{GDBP}) b make_
474c8240 1351@end smallexample
c906108c
SS
1352
1353@noindent
1354After displaying the available possibilities, @value{GDBN} copies your
1355partial input (@samp{b make_} in the example) so you can finish the
1356command.
1357
1358If you just want to see the list of alternatives in the first place, you
b37052ae 1359can press @kbd{M-?} rather than pressing @key{TAB} twice. @kbd{M-?}
7a292a7a 1360means @kbd{@key{META} ?}. You can type this either by holding down a
c906108c 1361key designated as the @key{META} shift on your keyboard (if there is
7a292a7a 1362one) while typing @kbd{?}, or as @key{ESC} followed by @kbd{?}.
c906108c
SS
1363
1364@cindex quotes in commands
1365@cindex completion of quoted strings
1366Sometimes the string you need, while logically a ``word'', may contain
7a292a7a
SS
1367parentheses or other characters that @value{GDBN} normally excludes from
1368its notion of a word. To permit word completion to work in this
1369situation, you may enclose words in @code{'} (single quote marks) in
1370@value{GDBN} commands.
c906108c 1371
c906108c 1372The most likely situation where you might need this is in typing the
b37052ae
EZ
1373name of a C@t{++} function. This is because C@t{++} allows function
1374overloading (multiple definitions of the same function, distinguished
1375by argument type). For example, when you want to set a breakpoint you
1376may need to distinguish whether you mean the version of @code{name}
1377that takes an @code{int} parameter, @code{name(int)}, or the version
1378that takes a @code{float} parameter, @code{name(float)}. To use the
1379word-completion facilities in this situation, type a single quote
1380@code{'} at the beginning of the function name. This alerts
1381@value{GDBN} that it may need to consider more information than usual
1382when you press @key{TAB} or @kbd{M-?} to request word completion:
c906108c 1383
474c8240 1384@smallexample
96a2c332 1385(@value{GDBP}) b 'bubble( @kbd{M-?}
c906108c
SS
1386bubble(double,double) bubble(int,int)
1387(@value{GDBP}) b 'bubble(
474c8240 1388@end smallexample
c906108c
SS
1389
1390In some cases, @value{GDBN} can tell that completing a name requires using
1391quotes. When this happens, @value{GDBN} inserts the quote for you (while
1392completing as much as it can) if you do not type the quote in the first
1393place:
1394
474c8240 1395@smallexample
c906108c
SS
1396(@value{GDBP}) b bub @key{TAB}
1397@exdent @value{GDBN} alters your input line to the following, and rings a bell:
1398(@value{GDBP}) b 'bubble(
474c8240 1399@end smallexample
c906108c
SS
1400
1401@noindent
1402In general, @value{GDBN} can tell that a quote is needed (and inserts it) if
1403you have not yet started typing the argument list when you ask for
1404completion on an overloaded symbol.
1405
d4f3574e 1406For more information about overloaded functions, see @ref{C plus plus
b37052ae 1407expressions, ,C@t{++} expressions}. You can use the command @code{set
c906108c 1408overload-resolution off} to disable overload resolution;
b37052ae 1409see @ref{Debugging C plus plus, ,@value{GDBN} features for C@t{++}}.
c906108c
SS
1410
1411
6d2ebf8b 1412@node Help
c906108c
SS
1413@section Getting help
1414@cindex online documentation
1415@kindex help
1416
5d161b24 1417You can always ask @value{GDBN} itself for information on its commands,
c906108c
SS
1418using the command @code{help}.
1419
1420@table @code
41afff9a 1421@kindex h @r{(@code{help})}
c906108c
SS
1422@item help
1423@itemx h
1424You can use @code{help} (abbreviated @code{h}) with no arguments to
1425display a short list of named classes of commands:
1426
1427@smallexample
1428(@value{GDBP}) help
1429List of classes of commands:
1430
2df3850c 1431aliases -- Aliases of other commands
c906108c 1432breakpoints -- Making program stop at certain points
2df3850c 1433data -- Examining data
c906108c 1434files -- Specifying and examining files
2df3850c
JM
1435internals -- Maintenance commands
1436obscure -- Obscure features
1437running -- Running the program
1438stack -- Examining the stack
c906108c
SS
1439status -- Status inquiries
1440support -- Support facilities
96a2c332
SS
1441tracepoints -- Tracing of program execution without@*
1442 stopping the program
c906108c 1443user-defined -- User-defined commands
c906108c 1444
5d161b24 1445Type "help" followed by a class name for a list of
c906108c 1446commands in that class.
5d161b24 1447Type "help" followed by command name for full
c906108c
SS
1448documentation.
1449Command name abbreviations are allowed if unambiguous.
1450(@value{GDBP})
1451@end smallexample
96a2c332 1452@c the above line break eliminates huge line overfull...
c906108c
SS
1453
1454@item help @var{class}
1455Using one of the general help classes as an argument, you can get a
1456list of the individual commands in that class. For example, here is the
1457help display for the class @code{status}:
1458
1459@smallexample
1460(@value{GDBP}) help status
1461Status inquiries.
1462
1463List of commands:
1464
1465@c Line break in "show" line falsifies real output, but needed
1466@c to fit in smallbook page size.
2df3850c
JM
1467info -- Generic command for showing things
1468 about the program being debugged
1469show -- Generic command for showing things
1470 about the debugger
c906108c 1471
5d161b24 1472Type "help" followed by command name for full
c906108c
SS
1473documentation.
1474Command name abbreviations are allowed if unambiguous.
1475(@value{GDBP})
1476@end smallexample
1477
1478@item help @var{command}
1479With a command name as @code{help} argument, @value{GDBN} displays a
1480short paragraph on how to use that command.
1481
6837a0a2
DB
1482@kindex apropos
1483@item apropos @var{args}
1484The @code{apropos @var{args}} command searches through all of the @value{GDBN}
1485commands, and their documentation, for the regular expression specified in
1486@var{args}. It prints out all matches found. For example:
1487
1488@smallexample
1489apropos reload
1490@end smallexample
1491
b37052ae
EZ
1492@noindent
1493results in:
6837a0a2
DB
1494
1495@smallexample
6d2ebf8b
SS
1496@c @group
1497set symbol-reloading -- Set dynamic symbol table reloading
1498 multiple times in one run
1499show symbol-reloading -- Show dynamic symbol table reloading
1500 multiple times in one run
1501@c @end group
6837a0a2
DB
1502@end smallexample
1503
c906108c
SS
1504@kindex complete
1505@item complete @var{args}
1506The @code{complete @var{args}} command lists all the possible completions
1507for the beginning of a command. Use @var{args} to specify the beginning of the
1508command you want completed. For example:
1509
1510@smallexample
1511complete i
1512@end smallexample
1513
1514@noindent results in:
1515
1516@smallexample
1517@group
2df3850c
JM
1518if
1519ignore
c906108c
SS
1520info
1521inspect
c906108c
SS
1522@end group
1523@end smallexample
1524
1525@noindent This is intended for use by @sc{gnu} Emacs.
1526@end table
1527
1528In addition to @code{help}, you can use the @value{GDBN} commands @code{info}
1529and @code{show} to inquire about the state of your program, or the state
1530of @value{GDBN} itself. Each command supports many topics of inquiry; this
1531manual introduces each of them in the appropriate context. The listings
1532under @code{info} and under @code{show} in the Index point to
1533all the sub-commands. @xref{Index}.
1534
1535@c @group
1536@table @code
1537@kindex info
41afff9a 1538@kindex i @r{(@code{info})}
c906108c
SS
1539@item info
1540This command (abbreviated @code{i}) is for describing the state of your
1541program. For example, you can list the arguments given to your program
1542with @code{info args}, list the registers currently in use with @code{info
1543registers}, or list the breakpoints you have set with @code{info breakpoints}.
1544You can get a complete list of the @code{info} sub-commands with
1545@w{@code{help info}}.
1546
1547@kindex set
1548@item set
5d161b24 1549You can assign the result of an expression to an environment variable with
c906108c
SS
1550@code{set}. For example, you can set the @value{GDBN} prompt to a $-sign with
1551@code{set prompt $}.
1552
1553@kindex show
1554@item show
5d161b24 1555In contrast to @code{info}, @code{show} is for describing the state of
c906108c
SS
1556@value{GDBN} itself.
1557You can change most of the things you can @code{show}, by using the
1558related command @code{set}; for example, you can control what number
1559system is used for displays with @code{set radix}, or simply inquire
1560which is currently in use with @code{show radix}.
1561
1562@kindex info set
1563To display all the settable parameters and their current
1564values, you can use @code{show} with no arguments; you may also use
1565@code{info set}. Both commands produce the same display.
1566@c FIXME: "info set" violates the rule that "info" is for state of
1567@c FIXME...program. Ck w/ GNU: "info set" to be called something else,
1568@c FIXME...or change desc of rule---eg "state of prog and debugging session"?
1569@end table
1570@c @end group
1571
1572Here are three miscellaneous @code{show} subcommands, all of which are
1573exceptional in lacking corresponding @code{set} commands:
1574
1575@table @code
1576@kindex show version
1577@cindex version number
1578@item show version
1579Show what version of @value{GDBN} is running. You should include this
2df3850c
JM
1580information in @value{GDBN} bug-reports. If multiple versions of
1581@value{GDBN} are in use at your site, you may need to determine which
1582version of @value{GDBN} you are running; as @value{GDBN} evolves, new
1583commands are introduced, and old ones may wither away. Also, many
1584system vendors ship variant versions of @value{GDBN}, and there are
96a2c332 1585variant versions of @value{GDBN} in @sc{gnu}/Linux distributions as well.
2df3850c
JM
1586The version number is the same as the one announced when you start
1587@value{GDBN}.
c906108c
SS
1588
1589@kindex show copying
1590@item show copying
1591Display information about permission for copying @value{GDBN}.
1592
1593@kindex show warranty
1594@item show warranty
2df3850c 1595Display the @sc{gnu} ``NO WARRANTY'' statement, or a warranty,
96a2c332 1596if your version of @value{GDBN} comes with one.
2df3850c 1597
c906108c
SS
1598@end table
1599
6d2ebf8b 1600@node Running
c906108c
SS
1601@chapter Running Programs Under @value{GDBN}
1602
1603When you run a program under @value{GDBN}, you must first generate
1604debugging information when you compile it.
7a292a7a
SS
1605
1606You may start @value{GDBN} with its arguments, if any, in an environment
1607of your choice. If you are doing native debugging, you may redirect
1608your program's input and output, debug an already running process, or
1609kill a child process.
c906108c
SS
1610
1611@menu
1612* Compilation:: Compiling for debugging
1613* Starting:: Starting your program
c906108c
SS
1614* Arguments:: Your program's arguments
1615* Environment:: Your program's environment
c906108c
SS
1616
1617* Working Directory:: Your program's working directory
1618* Input/Output:: Your program's input and output
1619* Attach:: Debugging an already-running process
1620* Kill Process:: Killing the child process
c906108c
SS
1621
1622* Threads:: Debugging programs with multiple threads
1623* Processes:: Debugging programs with multiple processes
1624@end menu
1625
6d2ebf8b 1626@node Compilation
c906108c
SS
1627@section Compiling for debugging
1628
1629In order to debug a program effectively, you need to generate
1630debugging information when you compile it. This debugging information
1631is stored in the object file; it describes the data type of each
1632variable or function and the correspondence between source line numbers
1633and addresses in the executable code.
1634
1635To request debugging information, specify the @samp{-g} option when you run
1636the compiler.
1637
e2e0bcd1
JB
1638Most compilers do not include information about preprocessor macros in
1639the debugging information if you specify the @option{-g} flag alone,
1640because this information is rather large. Version 3.1 of @value{NGCC},
1641the @sc{gnu} C compiler, provides macro information if you specify the
1642options @option{-gdwarf-2} and @option{-g3}; the former option requests
1643debugging information in the Dwarf 2 format, and the latter requests
1644``extra information''. In the future, we hope to find more compact ways
1645to represent macro information, so that it can be included with
1646@option{-g} alone.
1647
c906108c
SS
1648Many C compilers are unable to handle the @samp{-g} and @samp{-O}
1649options together. Using those compilers, you cannot generate optimized
1650executables containing debugging information.
1651
53a5351d
JM
1652@value{NGCC}, the @sc{gnu} C compiler, supports @samp{-g} with or
1653without @samp{-O}, making it possible to debug optimized code. We
1654recommend that you @emph{always} use @samp{-g} whenever you compile a
1655program. You may think your program is correct, but there is no sense
1656in pushing your luck.
c906108c
SS
1657
1658@cindex optimized code, debugging
1659@cindex debugging optimized code
1660When you debug a program compiled with @samp{-g -O}, remember that the
1661optimizer is rearranging your code; the debugger shows you what is
1662really there. Do not be too surprised when the execution path does not
1663exactly match your source file! An extreme example: if you define a
1664variable, but never use it, @value{GDBN} never sees that
1665variable---because the compiler optimizes it out of existence.
1666
1667Some things do not work as well with @samp{-g -O} as with just
1668@samp{-g}, particularly on machines with instruction scheduling. If in
1669doubt, recompile with @samp{-g} alone, and if this fixes the problem,
1670please report it to us as a bug (including a test case!).
15387254 1671@xref{Variables}, for more information about debugging optimized code.
c906108c
SS
1672
1673Older versions of the @sc{gnu} C compiler permitted a variant option
1674@w{@samp{-gg}} for debugging information. @value{GDBN} no longer supports this
1675format; if your @sc{gnu} C compiler has this option, do not use it.
1676
1677@need 2000
6d2ebf8b 1678@node Starting
c906108c
SS
1679@section Starting your program
1680@cindex starting
1681@cindex running
1682
1683@table @code
1684@kindex run
41afff9a 1685@kindex r @r{(@code{run})}
c906108c
SS
1686@item run
1687@itemx r
7a292a7a
SS
1688Use the @code{run} command to start your program under @value{GDBN}.
1689You must first specify the program name (except on VxWorks) with an
1690argument to @value{GDBN} (@pxref{Invocation, ,Getting In and Out of
1691@value{GDBN}}), or by using the @code{file} or @code{exec-file} command
1692(@pxref{Files, ,Commands to specify files}).
c906108c
SS
1693
1694@end table
1695
c906108c
SS
1696If you are running your program in an execution environment that
1697supports processes, @code{run} creates an inferior process and makes
1698that process run your program. (In environments without processes,
1699@code{run} jumps to the start of your program.)
1700
1701The execution of a program is affected by certain information it
1702receives from its superior. @value{GDBN} provides ways to specify this
1703information, which you must do @emph{before} starting your program. (You
1704can change it after starting your program, but such changes only affect
1705your program the next time you start it.) This information may be
1706divided into four categories:
1707
1708@table @asis
1709@item The @emph{arguments.}
1710Specify the arguments to give your program as the arguments of the
1711@code{run} command. If a shell is available on your target, the shell
1712is used to pass the arguments, so that you may use normal conventions
1713(such as wildcard expansion or variable substitution) in describing
1714the arguments.
1715In Unix systems, you can control which shell is used with the
1716@code{SHELL} environment variable.
1717@xref{Arguments, ,Your program's arguments}.
1718
1719@item The @emph{environment.}
1720Your program normally inherits its environment from @value{GDBN}, but you can
1721use the @value{GDBN} commands @code{set environment} and @code{unset
1722environment} to change parts of the environment that affect
1723your program. @xref{Environment, ,Your program's environment}.
1724
1725@item The @emph{working directory.}
1726Your program inherits its working directory from @value{GDBN}. You can set
1727the @value{GDBN} working directory with the @code{cd} command in @value{GDBN}.
1728@xref{Working Directory, ,Your program's working directory}.
1729
1730@item The @emph{standard input and output.}
1731Your program normally uses the same device for standard input and
1732standard output as @value{GDBN} is using. You can redirect input and output
1733in the @code{run} command line, or you can use the @code{tty} command to
1734set a different device for your program.
1735@xref{Input/Output, ,Your program's input and output}.
1736
1737@cindex pipes
1738@emph{Warning:} While input and output redirection work, you cannot use
1739pipes to pass the output of the program you are debugging to another
1740program; if you attempt this, @value{GDBN} is likely to wind up debugging the
1741wrong program.
1742@end table
c906108c
SS
1743
1744When you issue the @code{run} command, your program begins to execute
1745immediately. @xref{Stopping, ,Stopping and continuing}, for discussion
1746of how to arrange for your program to stop. Once your program has
1747stopped, you may call functions in your program, using the @code{print}
1748or @code{call} commands. @xref{Data, ,Examining Data}.
1749
1750If the modification time of your symbol file has changed since the last
1751time @value{GDBN} read its symbols, @value{GDBN} discards its symbol
1752table, and reads it again. When it does this, @value{GDBN} tries to retain
1753your current breakpoints.
1754
4e8b0763
JB
1755@table @code
1756@kindex start
1757@item start
1758@cindex run to main procedure
1759The name of the main procedure can vary from language to language.
1760With C or C@t{++}, the main procedure name is always @code{main}, but
1761other languages such as Ada do not require a specific name for their
1762main procedure. The debugger provides a convenient way to start the
1763execution of the program and to stop at the beginning of the main
1764procedure, depending on the language used.
1765
1766The @samp{start} command does the equivalent of setting a temporary
1767breakpoint at the beginning of the main procedure and then invoking
1768the @samp{run} command.
1769
f018e82f
EZ
1770@cindex elaboration phase
1771Some programs contain an @dfn{elaboration} phase where some startup code is
1772executed before the main procedure is called. This depends on the
1773languages used to write your program. In C@t{++}, for instance,
4e8b0763
JB
1774constructors for static and global objects are executed before
1775@code{main} is called. It is therefore possible that the debugger stops
1776before reaching the main procedure. However, the temporary breakpoint
1777will remain to halt execution.
1778
1779Specify the arguments to give to your program as arguments to the
1780@samp{start} command. These arguments will be given verbatim to the
1781underlying @samp{run} command. Note that the same arguments will be
1782reused if no argument is provided during subsequent calls to
1783@samp{start} or @samp{run}.
1784
1785It is sometimes necessary to debug the program during elaboration. In
1786these cases, using the @code{start} command would stop the execution of
1787your program too late, as the program would have already completed the
1788elaboration phase. Under these circumstances, insert breakpoints in your
1789elaboration code before running your program.
1790@end table
1791
6d2ebf8b 1792@node Arguments
c906108c
SS
1793@section Your program's arguments
1794
1795@cindex arguments (to your program)
1796The arguments to your program can be specified by the arguments of the
5d161b24 1797@code{run} command.
c906108c
SS
1798They are passed to a shell, which expands wildcard characters and
1799performs redirection of I/O, and thence to your program. Your
1800@code{SHELL} environment variable (if it exists) specifies what shell
1801@value{GDBN} uses. If you do not define @code{SHELL}, @value{GDBN} uses
d4f3574e
SS
1802the default shell (@file{/bin/sh} on Unix).
1803
1804On non-Unix systems, the program is usually invoked directly by
1805@value{GDBN}, which emulates I/O redirection via the appropriate system
1806calls, and the wildcard characters are expanded by the startup code of
1807the program, not by the shell.
c906108c
SS
1808
1809@code{run} with no arguments uses the same arguments used by the previous
1810@code{run}, or those set by the @code{set args} command.
1811
c906108c 1812@table @code
41afff9a 1813@kindex set args
c906108c
SS
1814@item set args
1815Specify the arguments to be used the next time your program is run. If
1816@code{set args} has no arguments, @code{run} executes your program
1817with no arguments. Once you have run your program with arguments,
1818using @code{set args} before the next @code{run} is the only way to run
1819it again without arguments.
1820
1821@kindex show args
1822@item show args
1823Show the arguments to give your program when it is started.
1824@end table
1825
6d2ebf8b 1826@node Environment
c906108c
SS
1827@section Your program's environment
1828
1829@cindex environment (of your program)
1830The @dfn{environment} consists of a set of environment variables and
1831their values. Environment variables conventionally record such things as
1832your user name, your home directory, your terminal type, and your search
1833path for programs to run. Usually you set up environment variables with
1834the shell and they are inherited by all the other programs you run. When
1835debugging, it can be useful to try running your program with a modified
1836environment without having to start @value{GDBN} over again.
1837
1838@table @code
1839@kindex path
1840@item path @var{directory}
1841Add @var{directory} to the front of the @code{PATH} environment variable
17cc6a06
EZ
1842(the search path for executables) that will be passed to your program.
1843The value of @code{PATH} used by @value{GDBN} does not change.
d4f3574e
SS
1844You may specify several directory names, separated by whitespace or by a
1845system-dependent separator character (@samp{:} on Unix, @samp{;} on
1846MS-DOS and MS-Windows). If @var{directory} is already in the path, it
1847is moved to the front, so it is searched sooner.
c906108c
SS
1848
1849You can use the string @samp{$cwd} to refer to whatever is the current
1850working directory at the time @value{GDBN} searches the path. If you
1851use @samp{.} instead, it refers to the directory where you executed the
1852@code{path} command. @value{GDBN} replaces @samp{.} in the
1853@var{directory} argument (with the current path) before adding
1854@var{directory} to the search path.
1855@c 'path' is explicitly nonrepeatable, but RMS points out it is silly to
1856@c document that, since repeating it would be a no-op.
1857
1858@kindex show paths
1859@item show paths
1860Display the list of search paths for executables (the @code{PATH}
1861environment variable).
1862
1863@kindex show environment
1864@item show environment @r{[}@var{varname}@r{]}
1865Print the value of environment variable @var{varname} to be given to
1866your program when it starts. If you do not supply @var{varname},
1867print the names and values of all environment variables to be given to
1868your program. You can abbreviate @code{environment} as @code{env}.
1869
1870@kindex set environment
53a5351d 1871@item set environment @var{varname} @r{[}=@var{value}@r{]}
c906108c
SS
1872Set environment variable @var{varname} to @var{value}. The value
1873changes for your program only, not for @value{GDBN} itself. @var{value} may
1874be any string; the values of environment variables are just strings, and
1875any interpretation is supplied by your program itself. The @var{value}
1876parameter is optional; if it is eliminated, the variable is set to a
1877null value.
1878@c "any string" here does not include leading, trailing
1879@c blanks. Gnu asks: does anyone care?
1880
1881For example, this command:
1882
474c8240 1883@smallexample
c906108c 1884set env USER = foo
474c8240 1885@end smallexample
c906108c
SS
1886
1887@noindent
d4f3574e 1888tells the debugged program, when subsequently run, that its user is named
c906108c
SS
1889@samp{foo}. (The spaces around @samp{=} are used for clarity here; they
1890are not actually required.)
1891
1892@kindex unset environment
1893@item unset environment @var{varname}
1894Remove variable @var{varname} from the environment to be passed to your
1895program. This is different from @samp{set env @var{varname} =};
1896@code{unset environment} removes the variable from the environment,
1897rather than assigning it an empty value.
1898@end table
1899
d4f3574e
SS
1900@emph{Warning:} On Unix systems, @value{GDBN} runs your program using
1901the shell indicated
c906108c
SS
1902by your @code{SHELL} environment variable if it exists (or
1903@code{/bin/sh} if not). If your @code{SHELL} variable names a shell
1904that runs an initialization file---such as @file{.cshrc} for C-shell, or
1905@file{.bashrc} for BASH---any variables you set in that file affect
1906your program. You may wish to move setting of environment variables to
1907files that are only run when you sign on, such as @file{.login} or
1908@file{.profile}.
1909
6d2ebf8b 1910@node Working Directory
c906108c
SS
1911@section Your program's working directory
1912
1913@cindex working directory (of your program)
1914Each time you start your program with @code{run}, it inherits its
1915working directory from the current working directory of @value{GDBN}.
1916The @value{GDBN} working directory is initially whatever it inherited
1917from its parent process (typically the shell), but you can specify a new
1918working directory in @value{GDBN} with the @code{cd} command.
1919
1920The @value{GDBN} working directory also serves as a default for the commands
1921that specify files for @value{GDBN} to operate on. @xref{Files, ,Commands to
1922specify files}.
1923
1924@table @code
1925@kindex cd
1926@item cd @var{directory}
1927Set the @value{GDBN} working directory to @var{directory}.
1928
1929@kindex pwd
1930@item pwd
1931Print the @value{GDBN} working directory.
1932@end table
1933
60bf7e09
EZ
1934It is generally impossible to find the current working directory of
1935the process being debugged (since a program can change its directory
1936during its run). If you work on a system where @value{GDBN} is
1937configured with the @file{/proc} support, you can use the @code{info
1938proc} command (@pxref{SVR4 Process Information}) to find out the
1939current working directory of the debuggee.
1940
6d2ebf8b 1941@node Input/Output
c906108c
SS
1942@section Your program's input and output
1943
1944@cindex redirection
1945@cindex i/o
1946@cindex terminal
1947By default, the program you run under @value{GDBN} does input and output to
5d161b24 1948the same terminal that @value{GDBN} uses. @value{GDBN} switches the terminal
c906108c
SS
1949to its own terminal modes to interact with you, but it records the terminal
1950modes your program was using and switches back to them when you continue
1951running your program.
1952
1953@table @code
1954@kindex info terminal
1955@item info terminal
1956Displays information recorded by @value{GDBN} about the terminal modes your
1957program is using.
1958@end table
1959
1960You can redirect your program's input and/or output using shell
1961redirection with the @code{run} command. For example,
1962
474c8240 1963@smallexample
c906108c 1964run > outfile
474c8240 1965@end smallexample
c906108c
SS
1966
1967@noindent
1968starts your program, diverting its output to the file @file{outfile}.
1969
1970@kindex tty
1971@cindex controlling terminal
1972Another way to specify where your program should do input and output is
1973with the @code{tty} command. This command accepts a file name as
1974argument, and causes this file to be the default for future @code{run}
1975commands. It also resets the controlling terminal for the child
1976process, for future @code{run} commands. For example,
1977
474c8240 1978@smallexample
c906108c 1979tty /dev/ttyb
474c8240 1980@end smallexample
c906108c
SS
1981
1982@noindent
1983directs that processes started with subsequent @code{run} commands
1984default to do input and output on the terminal @file{/dev/ttyb} and have
1985that as their controlling terminal.
1986
1987An explicit redirection in @code{run} overrides the @code{tty} command's
1988effect on the input/output device, but not its effect on the controlling
1989terminal.
1990
1991When you use the @code{tty} command or redirect input in the @code{run}
1992command, only the input @emph{for your program} is affected. The input
1993for @value{GDBN} still comes from your terminal.
1994
6d2ebf8b 1995@node Attach
c906108c
SS
1996@section Debugging an already-running process
1997@kindex attach
1998@cindex attach
1999
2000@table @code
2001@item attach @var{process-id}
2002This command attaches to a running process---one that was started
2003outside @value{GDBN}. (@code{info files} shows your active
2004targets.) The command takes as argument a process ID. The usual way to
2005find out the process-id of a Unix process is with the @code{ps} utility,
2006or with the @samp{jobs -l} shell command.
2007
2008@code{attach} does not repeat if you press @key{RET} a second time after
2009executing the command.
2010@end table
2011
2012To use @code{attach}, your program must be running in an environment
2013which supports processes; for example, @code{attach} does not work for
2014programs on bare-board targets that lack an operating system. You must
2015also have permission to send the process a signal.
2016
2017When you use @code{attach}, the debugger finds the program running in
2018the process first by looking in the current working directory, then (if
2019the program is not found) by using the source file search path
2020(@pxref{Source Path, ,Specifying source directories}). You can also use
2021the @code{file} command to load the program. @xref{Files, ,Commands to
2022Specify Files}.
2023
2024The first thing @value{GDBN} does after arranging to debug the specified
2025process is to stop it. You can examine and modify an attached process
53a5351d
JM
2026with all the @value{GDBN} commands that are ordinarily available when
2027you start processes with @code{run}. You can insert breakpoints; you
2028can step and continue; you can modify storage. If you would rather the
2029process continue running, you may use the @code{continue} command after
c906108c
SS
2030attaching @value{GDBN} to the process.
2031
2032@table @code
2033@kindex detach
2034@item detach
2035When you have finished debugging the attached process, you can use the
2036@code{detach} command to release it from @value{GDBN} control. Detaching
2037the process continues its execution. After the @code{detach} command,
2038that process and @value{GDBN} become completely independent once more, and you
2039are ready to @code{attach} another process or start one with @code{run}.
2040@code{detach} does not repeat if you press @key{RET} again after
2041executing the command.
2042@end table
2043
2044If you exit @value{GDBN} or use the @code{run} command while you have an
2045attached process, you kill that process. By default, @value{GDBN} asks
2046for confirmation if you try to do either of these things; you can
2047control whether or not you need to confirm by using the @code{set
2048confirm} command (@pxref{Messages/Warnings, ,Optional warnings and
2049messages}).
2050
6d2ebf8b 2051@node Kill Process
c906108c 2052@section Killing the child process
c906108c
SS
2053
2054@table @code
2055@kindex kill
2056@item kill
2057Kill the child process in which your program is running under @value{GDBN}.
2058@end table
2059
2060This command is useful if you wish to debug a core dump instead of a
2061running process. @value{GDBN} ignores any core dump file while your program
2062is running.
2063
2064On some operating systems, a program cannot be executed outside @value{GDBN}
2065while you have breakpoints set on it inside @value{GDBN}. You can use the
2066@code{kill} command in this situation to permit running your program
2067outside the debugger.
2068
2069The @code{kill} command is also useful if you wish to recompile and
2070relink your program, since on many systems it is impossible to modify an
2071executable file while it is running in a process. In this case, when you
2072next type @code{run}, @value{GDBN} notices that the file has changed, and
2073reads the symbol table again (while trying to preserve your current
2074breakpoint settings).
2075
6d2ebf8b 2076@node Threads
c906108c 2077@section Debugging programs with multiple threads
c906108c
SS
2078
2079@cindex threads of execution
2080@cindex multiple threads
2081@cindex switching threads
2082In some operating systems, such as HP-UX and Solaris, a single program
2083may have more than one @dfn{thread} of execution. The precise semantics
2084of threads differ from one operating system to another, but in general
2085the threads of a single program are akin to multiple processes---except
2086that they share one address space (that is, they can all examine and
2087modify the same variables). On the other hand, each thread has its own
2088registers and execution stack, and perhaps private memory.
2089
2090@value{GDBN} provides these facilities for debugging multi-thread
2091programs:
2092
2093@itemize @bullet
2094@item automatic notification of new threads
2095@item @samp{thread @var{threadno}}, a command to switch among threads
2096@item @samp{info threads}, a command to inquire about existing threads
5d161b24 2097@item @samp{thread apply [@var{threadno}] [@var{all}] @var{args}},
c906108c
SS
2098a command to apply a command to a list of threads
2099@item thread-specific breakpoints
2100@end itemize
2101
c906108c
SS
2102@quotation
2103@emph{Warning:} These facilities are not yet available on every
2104@value{GDBN} configuration where the operating system supports threads.
2105If your @value{GDBN} does not support threads, these commands have no
2106effect. For example, a system without thread support shows no output
2107from @samp{info threads}, and always rejects the @code{thread} command,
2108like this:
2109
2110@smallexample
2111(@value{GDBP}) info threads
2112(@value{GDBP}) thread 1
2113Thread ID 1 not known. Use the "info threads" command to
2114see the IDs of currently known threads.
2115@end smallexample
2116@c FIXME to implementors: how hard would it be to say "sorry, this GDB
2117@c doesn't support threads"?
2118@end quotation
c906108c
SS
2119
2120@cindex focus of debugging
2121@cindex current thread
2122The @value{GDBN} thread debugging facility allows you to observe all
2123threads while your program runs---but whenever @value{GDBN} takes
2124control, one thread in particular is always the focus of debugging.
2125This thread is called the @dfn{current thread}. Debugging commands show
2126program information from the perspective of the current thread.
2127
41afff9a 2128@cindex @code{New} @var{systag} message
c906108c
SS
2129@cindex thread identifier (system)
2130@c FIXME-implementors!! It would be more helpful if the [New...] message
2131@c included GDB's numeric thread handle, so you could just go to that
2132@c thread without first checking `info threads'.
2133Whenever @value{GDBN} detects a new thread in your program, it displays
2134the target system's identification for the thread with a message in the
2135form @samp{[New @var{systag}]}. @var{systag} is a thread identifier
2136whose form varies depending on the particular system. For example, on
2137LynxOS, you might see
2138
474c8240 2139@smallexample
c906108c 2140[New process 35 thread 27]
474c8240 2141@end smallexample
c906108c
SS
2142
2143@noindent
2144when @value{GDBN} notices a new thread. In contrast, on an SGI system,
2145the @var{systag} is simply something like @samp{process 368}, with no
2146further qualifier.
2147
2148@c FIXME!! (1) Does the [New...] message appear even for the very first
2149@c thread of a program, or does it only appear for the
6ca652b0 2150@c second---i.e.@: when it becomes obvious we have a multithread
c906108c
SS
2151@c program?
2152@c (2) *Is* there necessarily a first thread always? Or do some
2153@c multithread systems permit starting a program with multiple
5d161b24 2154@c threads ab initio?
c906108c
SS
2155
2156@cindex thread number
2157@cindex thread identifier (GDB)
2158For debugging purposes, @value{GDBN} associates its own thread
2159number---always a single integer---with each thread in your program.
2160
2161@table @code
2162@kindex info threads
2163@item info threads
2164Display a summary of all threads currently in your
2165program. @value{GDBN} displays for each thread (in this order):
2166
2167@enumerate
2168@item the thread number assigned by @value{GDBN}
2169
2170@item the target system's thread identifier (@var{systag})
2171
2172@item the current stack frame summary for that thread
2173@end enumerate
2174
2175@noindent
2176An asterisk @samp{*} to the left of the @value{GDBN} thread number
2177indicates the current thread.
2178
5d161b24 2179For example,
c906108c
SS
2180@end table
2181@c end table here to get a little more width for example
2182
2183@smallexample
2184(@value{GDBP}) info threads
2185 3 process 35 thread 27 0x34e5 in sigpause ()
2186 2 process 35 thread 23 0x34e5 in sigpause ()
2187* 1 process 35 thread 13 main (argc=1, argv=0x7ffffff8)
2188 at threadtest.c:68
2189@end smallexample
53a5351d
JM
2190
2191On HP-UX systems:
c906108c 2192
4644b6e3
EZ
2193@cindex debugging multithreaded programs (on HP-UX)
2194@cindex thread identifier (GDB), on HP-UX
c906108c
SS
2195For debugging purposes, @value{GDBN} associates its own thread
2196number---a small integer assigned in thread-creation order---with each
2197thread in your program.
2198
41afff9a
EZ
2199@cindex @code{New} @var{systag} message, on HP-UX
2200@cindex thread identifier (system), on HP-UX
c906108c
SS
2201@c FIXME-implementors!! It would be more helpful if the [New...] message
2202@c included GDB's numeric thread handle, so you could just go to that
2203@c thread without first checking `info threads'.
2204Whenever @value{GDBN} detects a new thread in your program, it displays
2205both @value{GDBN}'s thread number and the target system's identification for the thread with a message in the
2206form @samp{[New @var{systag}]}. @var{systag} is a thread identifier
2207whose form varies depending on the particular system. For example, on
2208HP-UX, you see
2209
474c8240 2210@smallexample
c906108c 2211[New thread 2 (system thread 26594)]
474c8240 2212@end smallexample
c906108c
SS
2213
2214@noindent
5d161b24 2215when @value{GDBN} notices a new thread.
c906108c
SS
2216
2217@table @code
4644b6e3 2218@kindex info threads (HP-UX)
c906108c
SS
2219@item info threads
2220Display a summary of all threads currently in your
2221program. @value{GDBN} displays for each thread (in this order):
2222
2223@enumerate
2224@item the thread number assigned by @value{GDBN}
2225
2226@item the target system's thread identifier (@var{systag})
2227
2228@item the current stack frame summary for that thread
2229@end enumerate
2230
2231@noindent
2232An asterisk @samp{*} to the left of the @value{GDBN} thread number
2233indicates the current thread.
2234
5d161b24 2235For example,
c906108c
SS
2236@end table
2237@c end table here to get a little more width for example
2238
474c8240 2239@smallexample
c906108c 2240(@value{GDBP}) info threads
6d2ebf8b
SS
2241 * 3 system thread 26607 worker (wptr=0x7b09c318 "@@") \@*
2242 at quicksort.c:137
2243 2 system thread 26606 0x7b0030d8 in __ksleep () \@*
2244 from /usr/lib/libc.2
2245 1 system thread 27905 0x7b003498 in _brk () \@*
2246 from /usr/lib/libc.2
474c8240 2247@end smallexample
c906108c
SS
2248
2249@table @code
2250@kindex thread @var{threadno}
2251@item thread @var{threadno}
2252Make thread number @var{threadno} the current thread. The command
2253argument @var{threadno} is the internal @value{GDBN} thread number, as
2254shown in the first field of the @samp{info threads} display.
2255@value{GDBN} responds by displaying the system identifier of the thread
2256you selected, and its current stack frame summary:
2257
2258@smallexample
2259@c FIXME!! This example made up; find a @value{GDBN} w/threads and get real one
2260(@value{GDBP}) thread 2
c906108c 2261[Switching to process 35 thread 23]
c906108c
SS
22620x34e5 in sigpause ()
2263@end smallexample
2264
2265@noindent
2266As with the @samp{[New @dots{}]} message, the form of the text after
2267@samp{Switching to} depends on your system's conventions for identifying
5d161b24 2268threads.
c906108c 2269
c906108c
SS
2270@item thread apply [@var{threadno}] [@var{all}] @var{args}
2271The @code{thread apply} command allows you to apply a command to one or
2272more threads. Specify the numbers of the threads that you want affected
2273with the command argument @var{threadno}. @var{threadno} is the internal
2274@value{GDBN} thread number, as shown in the first field of the @samp{info
5d161b24
DB
2275threads} display. To apply a command to all threads, use
2276@code{thread apply all} @var{args}.
c906108c
SS
2277@end table
2278
2279@cindex automatic thread selection
2280@cindex switching threads automatically
2281@cindex threads, automatic switching
2282Whenever @value{GDBN} stops your program, due to a breakpoint or a
2283signal, it automatically selects the thread where that breakpoint or
2284signal happened. @value{GDBN} alerts you to the context switch with a
2285message of the form @samp{[Switching to @var{systag}]} to identify the
2286thread.
2287
2288@xref{Thread Stops,,Stopping and starting multi-thread programs}, for
2289more information about how @value{GDBN} behaves when you stop and start
2290programs with multiple threads.
2291
2292@xref{Set Watchpoints,,Setting watchpoints}, for information about
2293watchpoints in programs with multiple threads.
c906108c 2294
6d2ebf8b 2295@node Processes
c906108c
SS
2296@section Debugging programs with multiple processes
2297
2298@cindex fork, debugging programs which call
2299@cindex multiple processes
2300@cindex processes, multiple
53a5351d
JM
2301On most systems, @value{GDBN} has no special support for debugging
2302programs which create additional processes using the @code{fork}
2303function. When a program forks, @value{GDBN} will continue to debug the
2304parent process and the child process will run unimpeded. If you have
2305set a breakpoint in any code which the child then executes, the child
2306will get a @code{SIGTRAP} signal which (unless it catches the signal)
2307will cause it to terminate.
c906108c
SS
2308
2309However, if you want to debug the child process there is a workaround
2310which isn't too painful. Put a call to @code{sleep} in the code which
2311the child process executes after the fork. It may be useful to sleep
2312only if a certain environment variable is set, or a certain file exists,
2313so that the delay need not occur when you don't want to run @value{GDBN}
2314on the child. While the child is sleeping, use the @code{ps} program to
2315get its process ID. Then tell @value{GDBN} (a new invocation of
2316@value{GDBN} if you are also debugging the parent process) to attach to
d4f3574e 2317the child process (@pxref{Attach}). From that point on you can debug
c906108c 2318the child process just like any other process which you attached to.
c906108c 2319
b51970ac
DJ
2320On some systems, @value{GDBN} provides support for debugging programs that
2321create additional processes using the @code{fork} or @code{vfork} functions.
2322Currently, the only platforms with this feature are HP-UX (11.x and later
2323only?) and GNU/Linux (kernel version 2.5.60 and later).
c906108c
SS
2324
2325By default, when a program forks, @value{GDBN} will continue to debug
2326the parent process and the child process will run unimpeded.
2327
2328If you want to follow the child process instead of the parent process,
2329use the command @w{@code{set follow-fork-mode}}.
2330
2331@table @code
2332@kindex set follow-fork-mode
2333@item set follow-fork-mode @var{mode}
2334Set the debugger response to a program call of @code{fork} or
2335@code{vfork}. A call to @code{fork} or @code{vfork} creates a new
2336process. The @var{mode} can be:
2337
2338@table @code
2339@item parent
2340The original process is debugged after a fork. The child process runs
2df3850c 2341unimpeded. This is the default.
c906108c
SS
2342
2343@item child
2344The new process is debugged after a fork. The parent process runs
2345unimpeded.
2346
c906108c
SS
2347@end table
2348
2349@item show follow-fork-mode
2df3850c 2350Display the current debugger response to a @code{fork} or @code{vfork} call.
c906108c
SS
2351@end table
2352
2353If you ask to debug a child process and a @code{vfork} is followed by an
2354@code{exec}, @value{GDBN} executes the new target up to the first
2355breakpoint in the new target. If you have a breakpoint set on
2356@code{main} in your original program, the breakpoint will also be set on
2357the child process's @code{main}.
2358
2359When a child process is spawned by @code{vfork}, you cannot debug the
2360child or parent until an @code{exec} call completes.
2361
2362If you issue a @code{run} command to @value{GDBN} after an @code{exec}
2363call executes, the new target restarts. To restart the parent process,
2364use the @code{file} command with the parent executable name as its
2365argument.
2366
2367You can use the @code{catch} command to make @value{GDBN} stop whenever
2368a @code{fork}, @code{vfork}, or @code{exec} call is made. @xref{Set
2369Catchpoints, ,Setting catchpoints}.
c906108c 2370
6d2ebf8b 2371@node Stopping
c906108c
SS
2372@chapter Stopping and Continuing
2373
2374The principal purposes of using a debugger are so that you can stop your
2375program before it terminates; or so that, if your program runs into
2376trouble, you can investigate and find out why.
2377
7a292a7a
SS
2378Inside @value{GDBN}, your program may stop for any of several reasons,
2379such as a signal, a breakpoint, or reaching a new line after a
2380@value{GDBN} command such as @code{step}. You may then examine and
2381change variables, set new breakpoints or remove old ones, and then
2382continue execution. Usually, the messages shown by @value{GDBN} provide
2383ample explanation of the status of your program---but you can also
2384explicitly request this information at any time.
c906108c
SS
2385
2386@table @code
2387@kindex info program
2388@item info program
2389Display information about the status of your program: whether it is
7a292a7a 2390running or not, what process it is, and why it stopped.
c906108c
SS
2391@end table
2392
2393@menu
2394* Breakpoints:: Breakpoints, watchpoints, and catchpoints
2395* Continuing and Stepping:: Resuming execution
c906108c 2396* Signals:: Signals
c906108c 2397* Thread Stops:: Stopping and starting multi-thread programs
c906108c
SS
2398@end menu
2399
6d2ebf8b 2400@node Breakpoints
c906108c
SS
2401@section Breakpoints, watchpoints, and catchpoints
2402
2403@cindex breakpoints
2404A @dfn{breakpoint} makes your program stop whenever a certain point in
2405the program is reached. For each breakpoint, you can add conditions to
2406control in finer detail whether your program stops. You can set
2407breakpoints with the @code{break} command and its variants (@pxref{Set
2408Breaks, ,Setting breakpoints}), to specify the place where your program
2409should stop by line number, function name or exact address in the
2410program.
2411
2412In HP-UX, SunOS 4.x, SVR4, and Alpha OSF/1 configurations, you can set
2413breakpoints in shared libraries before the executable is run. There is
2414a minor limitation on HP-UX systems: you must wait until the executable
2415is run in order to set breakpoints in shared library routines that are
2416not called directly by the program (for example, routines that are
2417arguments in a @code{pthread_create} call).
2418
2419@cindex watchpoints
2420@cindex memory tracing
2421@cindex breakpoint on memory address
2422@cindex breakpoint on variable modification
2423A @dfn{watchpoint} is a special breakpoint that stops your program
2424when the value of an expression changes. You must use a different
2425command to set watchpoints (@pxref{Set Watchpoints, ,Setting
2426watchpoints}), but aside from that, you can manage a watchpoint like
2427any other breakpoint: you enable, disable, and delete both breakpoints
2428and watchpoints using the same commands.
2429
2430You can arrange to have values from your program displayed automatically
2431whenever @value{GDBN} stops at a breakpoint. @xref{Auto Display,,
2432Automatic display}.
2433
2434@cindex catchpoints
2435@cindex breakpoint on events
2436A @dfn{catchpoint} is another special breakpoint that stops your program
b37052ae 2437when a certain kind of event occurs, such as the throwing of a C@t{++}
c906108c
SS
2438exception or the loading of a library. As with watchpoints, you use a
2439different command to set a catchpoint (@pxref{Set Catchpoints, ,Setting
2440catchpoints}), but aside from that, you can manage a catchpoint like any
2441other breakpoint. (To stop when your program receives a signal, use the
d4f3574e 2442@code{handle} command; see @ref{Signals, ,Signals}.)
c906108c
SS
2443
2444@cindex breakpoint numbers
2445@cindex numbers for breakpoints
2446@value{GDBN} assigns a number to each breakpoint, watchpoint, or
2447catchpoint when you create it; these numbers are successive integers
2448starting with one. In many of the commands for controlling various
2449features of breakpoints you use the breakpoint number to say which
2450breakpoint you want to change. Each breakpoint may be @dfn{enabled} or
2451@dfn{disabled}; if disabled, it has no effect on your program until you
2452enable it again.
2453
c5394b80
JM
2454@cindex breakpoint ranges
2455@cindex ranges of breakpoints
2456Some @value{GDBN} commands accept a range of breakpoints on which to
2457operate. A breakpoint range is either a single breakpoint number, like
2458@samp{5}, or two such numbers, in increasing order, separated by a
2459hyphen, like @samp{5-7}. When a breakpoint range is given to a command,
2460all breakpoint in that range are operated on.
2461
c906108c
SS
2462@menu
2463* Set Breaks:: Setting breakpoints
2464* Set Watchpoints:: Setting watchpoints
2465* Set Catchpoints:: Setting catchpoints
2466* Delete Breaks:: Deleting breakpoints
2467* Disabling:: Disabling breakpoints
2468* Conditions:: Break conditions
2469* Break Commands:: Breakpoint command lists
c906108c 2470* Breakpoint Menus:: Breakpoint menus
d4f3574e 2471* Error in Breakpoints:: ``Cannot insert breakpoints''
e4d5f7e1 2472* Breakpoint related warnings:: ``Breakpoint address adjusted...''
c906108c
SS
2473@end menu
2474
6d2ebf8b 2475@node Set Breaks
c906108c
SS
2476@subsection Setting breakpoints
2477
5d161b24 2478@c FIXME LMB what does GDB do if no code on line of breakpt?
c906108c
SS
2479@c consider in particular declaration with/without initialization.
2480@c
2481@c FIXME 2 is there stuff on this already? break at fun start, already init?
2482
2483@kindex break
41afff9a
EZ
2484@kindex b @r{(@code{break})}
2485@vindex $bpnum@r{, convenience variable}
c906108c
SS
2486@cindex latest breakpoint
2487Breakpoints are set with the @code{break} command (abbreviated
5d161b24 2488@code{b}). The debugger convenience variable @samp{$bpnum} records the
f3b28801 2489number of the breakpoint you've set most recently; see @ref{Convenience
c906108c
SS
2490Vars,, Convenience variables}, for a discussion of what you can do with
2491convenience variables.
2492
2493You have several ways to say where the breakpoint should go.
2494
2495@table @code
2496@item break @var{function}
5d161b24 2497Set a breakpoint at entry to function @var{function}.
c906108c 2498When using source languages that permit overloading of symbols, such as
b37052ae 2499C@t{++}, @var{function} may refer to more than one possible place to break.
c906108c 2500@xref{Breakpoint Menus,,Breakpoint menus}, for a discussion of that situation.
c906108c
SS
2501
2502@item break +@var{offset}
2503@itemx break -@var{offset}
2504Set a breakpoint some number of lines forward or back from the position
d4f3574e 2505at which execution stopped in the currently selected @dfn{stack frame}.
2df3850c 2506(@xref{Frames, ,Frames}, for a description of stack frames.)
c906108c
SS
2507
2508@item break @var{linenum}
2509Set a breakpoint at line @var{linenum} in the current source file.
d4f3574e
SS
2510The current source file is the last file whose source text was printed.
2511The breakpoint will stop your program just before it executes any of the
c906108c
SS
2512code on that line.
2513
2514@item break @var{filename}:@var{linenum}
2515Set a breakpoint at line @var{linenum} in source file @var{filename}.
2516
2517@item break @var{filename}:@var{function}
2518Set a breakpoint at entry to function @var{function} found in file
2519@var{filename}. Specifying a file name as well as a function name is
2520superfluous except when multiple files contain similarly named
2521functions.
2522
2523@item break *@var{address}
2524Set a breakpoint at address @var{address}. You can use this to set
2525breakpoints in parts of your program which do not have debugging
2526information or source files.
2527
2528@item break
2529When called without any arguments, @code{break} sets a breakpoint at
2530the next instruction to be executed in the selected stack frame
2531(@pxref{Stack, ,Examining the Stack}). In any selected frame but the
2532innermost, this makes your program stop as soon as control
2533returns to that frame. This is similar to the effect of a
2534@code{finish} command in the frame inside the selected frame---except
2535that @code{finish} does not leave an active breakpoint. If you use
2536@code{break} without an argument in the innermost frame, @value{GDBN} stops
2537the next time it reaches the current location; this may be useful
2538inside loops.
2539
2540@value{GDBN} normally ignores breakpoints when it resumes execution, until at
2541least one instruction has been executed. If it did not do this, you
2542would be unable to proceed past a breakpoint without first disabling the
2543breakpoint. This rule applies whether or not the breakpoint already
2544existed when your program stopped.
2545
2546@item break @dots{} if @var{cond}
2547Set a breakpoint with condition @var{cond}; evaluate the expression
2548@var{cond} each time the breakpoint is reached, and stop only if the
2549value is nonzero---that is, if @var{cond} evaluates as true.
2550@samp{@dots{}} stands for one of the possible arguments described
2551above (or no argument) specifying where to break. @xref{Conditions,
2552,Break conditions}, for more information on breakpoint conditions.
2553
2554@kindex tbreak
2555@item tbreak @var{args}
2556Set a breakpoint enabled only for one stop. @var{args} are the
2557same as for the @code{break} command, and the breakpoint is set in the same
2558way, but the breakpoint is automatically deleted after the first time your
2559program stops there. @xref{Disabling, ,Disabling breakpoints}.
2560
c906108c
SS
2561@kindex hbreak
2562@item hbreak @var{args}
d4f3574e
SS
2563Set a hardware-assisted breakpoint. @var{args} are the same as for the
2564@code{break} command and the breakpoint is set in the same way, but the
c906108c
SS
2565breakpoint requires hardware support and some target hardware may not
2566have this support. The main purpose of this is EPROM/ROM code
d4f3574e
SS
2567debugging, so you can set a breakpoint at an instruction without
2568changing the instruction. This can be used with the new trap-generation
2569provided by SPARClite DSU and some x86-based targets. These targets
2570will generate traps when a program accesses some data or instruction
2571address that is assigned to the debug registers. However the hardware
2572breakpoint registers can take a limited number of breakpoints. For
2573example, on the DSU, only two data breakpoints can be set at a time, and
2574@value{GDBN} will reject this command if more than two are used. Delete
2575or disable unused hardware breakpoints before setting new ones
2576(@pxref{Disabling, ,Disabling}). @xref{Conditions, ,Break conditions}.
501eef12
AC
2577@xref{set remote hardware-breakpoint-limit}.
2578
c906108c
SS
2579
2580@kindex thbreak
2581@item thbreak @var{args}
2582Set a hardware-assisted breakpoint enabled only for one stop. @var{args}
2583are the same as for the @code{hbreak} command and the breakpoint is set in
5d161b24 2584the same way. However, like the @code{tbreak} command,
c906108c
SS
2585the breakpoint is automatically deleted after the
2586first time your program stops there. Also, like the @code{hbreak}
5d161b24
DB
2587command, the breakpoint requires hardware support and some target hardware
2588may not have this support. @xref{Disabling, ,Disabling breakpoints}.
d4f3574e 2589See also @ref{Conditions, ,Break conditions}.
c906108c
SS
2590
2591@kindex rbreak
2592@cindex regular expression
2593@item rbreak @var{regex}
c906108c 2594Set breakpoints on all functions matching the regular expression
11cf8741
JM
2595@var{regex}. This command sets an unconditional breakpoint on all
2596matches, printing a list of all breakpoints it set. Once these
2597breakpoints are set, they are treated just like the breakpoints set with
2598the @code{break} command. You can delete them, disable them, or make
2599them conditional the same way as any other breakpoint.
2600
2601The syntax of the regular expression is the standard one used with tools
2602like @file{grep}. Note that this is different from the syntax used by
2603shells, so for instance @code{foo*} matches all functions that include
2604an @code{fo} followed by zero or more @code{o}s. There is an implicit
2605@code{.*} leading and trailing the regular expression you supply, so to
2606match only functions that begin with @code{foo}, use @code{^foo}.
c906108c 2607
f7dc1244 2608@cindex non-member C@t{++} functions, set breakpoint in
b37052ae 2609When debugging C@t{++} programs, @code{rbreak} is useful for setting
c906108c
SS
2610breakpoints on overloaded functions that are not members of any special
2611classes.
c906108c 2612
f7dc1244
EZ
2613@cindex set breakpoints on all functions
2614The @code{rbreak} command can be used to set breakpoints in
2615@strong{all} the functions in a program, like this:
2616
2617@smallexample
2618(@value{GDBP}) rbreak .
2619@end smallexample
2620
c906108c
SS
2621@kindex info breakpoints
2622@cindex @code{$_} and @code{info breakpoints}
2623@item info breakpoints @r{[}@var{n}@r{]}
2624@itemx info break @r{[}@var{n}@r{]}
2625@itemx info watchpoints @r{[}@var{n}@r{]}
2626Print a table of all breakpoints, watchpoints, and catchpoints set and
2627not deleted, with the following columns for each breakpoint:
2628
2629@table @emph
2630@item Breakpoint Numbers
2631@item Type
2632Breakpoint, watchpoint, or catchpoint.
2633@item Disposition
2634Whether the breakpoint is marked to be disabled or deleted when hit.
2635@item Enabled or Disabled
2636Enabled breakpoints are marked with @samp{y}. @samp{n} marks breakpoints
2637that are not enabled.
2638@item Address
2650777c
JJ
2639Where the breakpoint is in your program, as a memory address. If the
2640breakpoint is pending (see below for details) on a future load of a shared library, the address
2641will be listed as @samp{<PENDING>}.
c906108c
SS
2642@item What
2643Where the breakpoint is in the source for your program, as a file and
2650777c
JJ
2644line number. For a pending breakpoint, the original string passed to
2645the breakpoint command will be listed as it cannot be resolved until
2646the appropriate shared library is loaded in the future.
c906108c
SS
2647@end table
2648
2649@noindent
2650If a breakpoint is conditional, @code{info break} shows the condition on
2651the line following the affected breakpoint; breakpoint commands, if any,
2650777c
JJ
2652are listed after that. A pending breakpoint is allowed to have a condition
2653specified for it. The condition is not parsed for validity until a shared
2654library is loaded that allows the pending breakpoint to resolve to a
2655valid location.
c906108c
SS
2656
2657@noindent
2658@code{info break} with a breakpoint
2659number @var{n} as argument lists only that breakpoint. The
2660convenience variable @code{$_} and the default examining-address for
2661the @code{x} command are set to the address of the last breakpoint
5d161b24 2662listed (@pxref{Memory, ,Examining memory}).
c906108c
SS
2663
2664@noindent
2665@code{info break} displays a count of the number of times the breakpoint
2666has been hit. This is especially useful in conjunction with the
2667@code{ignore} command. You can ignore a large number of breakpoint
2668hits, look at the breakpoint info to see how many times the breakpoint
2669was hit, and then run again, ignoring one less than that number. This
2670will get you quickly to the last hit of that breakpoint.
2671@end table
2672
2673@value{GDBN} allows you to set any number of breakpoints at the same place in
2674your program. There is nothing silly or meaningless about this. When
2675the breakpoints are conditional, this is even useful
2676(@pxref{Conditions, ,Break conditions}).
2677
2650777c 2678@cindex pending breakpoints
dd79a6cf
JJ
2679If a specified breakpoint location cannot be found, it may be due to the fact
2680that the location is in a shared library that is yet to be loaded. In such
2681a case, you may want @value{GDBN} to create a special breakpoint (known as
2682a @dfn{pending breakpoint}) that
2683attempts to resolve itself in the future when an appropriate shared library
2684gets loaded.
2685
2686Pending breakpoints are useful to set at the start of your
2650777c
JJ
2687@value{GDBN} session for locations that you know will be dynamically loaded
2688later by the program being debugged. When shared libraries are loaded,
dd79a6cf
JJ
2689a check is made to see if the load resolves any pending breakpoint locations.
2690If a pending breakpoint location gets resolved,
2691a regular breakpoint is created and the original pending breakpoint is removed.
2692
2693@value{GDBN} provides some additional commands for controlling pending
2694breakpoint support:
2695
2696@kindex set breakpoint pending
2697@kindex show breakpoint pending
2698@table @code
2699@item set breakpoint pending auto
2700This is the default behavior. When @value{GDBN} cannot find the breakpoint
2701location, it queries you whether a pending breakpoint should be created.
2702
2703@item set breakpoint pending on
2704This indicates that an unrecognized breakpoint location should automatically
2705result in a pending breakpoint being created.
2706
2707@item set breakpoint pending off
2708This indicates that pending breakpoints are not to be created. Any
2709unrecognized breakpoint location results in an error. This setting does
2710not affect any pending breakpoints previously created.
2711
2712@item show breakpoint pending
2713Show the current behavior setting for creating pending breakpoints.
2714@end table
2650777c 2715
649e03f6
RM
2716@cindex operations allowed on pending breakpoints
2717Normal breakpoint operations apply to pending breakpoints as well. You may
2718specify a condition for a pending breakpoint and/or commands to run when the
2650777c
JJ
2719breakpoint is reached. You can also enable or disable
2720the pending breakpoint. When you specify a condition for a pending breakpoint,
2721the parsing of the condition will be deferred until the point where the
2722pending breakpoint location is resolved. Disabling a pending breakpoint
2723tells @value{GDBN} to not attempt to resolve the breakpoint on any subsequent
2724shared library load. When a pending breakpoint is re-enabled,
649e03f6 2725@value{GDBN} checks to see if the location is already resolved.
2650777c
JJ
2726This is done because any number of shared library loads could have
2727occurred since the time the breakpoint was disabled and one or more
2728of these loads could resolve the location.
2729
c906108c
SS
2730@cindex negative breakpoint numbers
2731@cindex internal @value{GDBN} breakpoints
eb12ee30
AC
2732@value{GDBN} itself sometimes sets breakpoints in your program for
2733special purposes, such as proper handling of @code{longjmp} (in C
2734programs). These internal breakpoints are assigned negative numbers,
2735starting with @code{-1}; @samp{info breakpoints} does not display them.
c906108c 2736You can see these breakpoints with the @value{GDBN} maintenance command
eb12ee30 2737@samp{maint info breakpoints} (@pxref{maint info breakpoints}).
c906108c
SS
2738
2739
6d2ebf8b 2740@node Set Watchpoints
c906108c
SS
2741@subsection Setting watchpoints
2742
2743@cindex setting watchpoints
2744@cindex software watchpoints
2745@cindex hardware watchpoints
2746You can use a watchpoint to stop execution whenever the value of an
2747expression changes, without having to predict a particular place where
2748this may happen.
2749
2750Depending on your system, watchpoints may be implemented in software or
2df3850c 2751hardware. @value{GDBN} does software watchpointing by single-stepping your
c906108c
SS
2752program and testing the variable's value each time, which is hundreds of
2753times slower than normal execution. (But this may still be worth it, to
2754catch errors where you have no clue what part of your program is the
2755culprit.)
2756
1104b9e7 2757On some systems, such as HP-UX, @sc{gnu}/Linux and some other x86-based targets,
2df3850c 2758@value{GDBN} includes support for
c906108c
SS
2759hardware watchpoints, which do not slow down the running of your
2760program.
2761
2762@table @code
2763@kindex watch
2764@item watch @var{expr}
2765Set a watchpoint for an expression. @value{GDBN} will break when @var{expr}
2766is written into by the program and its value changes.
2767
2768@kindex rwatch
2769@item rwatch @var{expr}
2770Set a watchpoint that will break when watch @var{expr} is read by the program.
c906108c
SS
2771
2772@kindex awatch
2773@item awatch @var{expr}
2df3850c 2774Set a watchpoint that will break when @var{expr} is either read or written into
7be570e7 2775by the program.
c906108c
SS
2776
2777@kindex info watchpoints
2778@item info watchpoints
2779This command prints a list of watchpoints, breakpoints, and catchpoints;
2780it is the same as @code{info break}.
2781@end table
2782
2783@value{GDBN} sets a @dfn{hardware watchpoint} if possible. Hardware
2784watchpoints execute very quickly, and the debugger reports a change in
2785value at the exact instruction where the change occurs. If @value{GDBN}
2786cannot set a hardware watchpoint, it sets a software watchpoint, which
2787executes more slowly and reports the change in value at the next
2788statement, not the instruction, after the change occurs.
2789
2790When you issue the @code{watch} command, @value{GDBN} reports
2791
474c8240 2792@smallexample
c906108c 2793Hardware watchpoint @var{num}: @var{expr}
474c8240 2794@end smallexample
c906108c
SS
2795
2796@noindent
2797if it was able to set a hardware watchpoint.
2798
7be570e7
JM
2799Currently, the @code{awatch} and @code{rwatch} commands can only set
2800hardware watchpoints, because accesses to data that don't change the
2801value of the watched expression cannot be detected without examining
2802every instruction as it is being executed, and @value{GDBN} does not do
2803that currently. If @value{GDBN} finds that it is unable to set a
2804hardware breakpoint with the @code{awatch} or @code{rwatch} command, it
2805will print a message like this:
2806
2807@smallexample
2808Expression cannot be implemented with read/access watchpoint.
2809@end smallexample
2810
2811Sometimes, @value{GDBN} cannot set a hardware watchpoint because the
2812data type of the watched expression is wider than what a hardware
2813watchpoint on the target machine can handle. For example, some systems
2814can only watch regions that are up to 4 bytes wide; on such systems you
2815cannot set hardware watchpoints for an expression that yields a
2816double-precision floating-point number (which is typically 8 bytes
2817wide). As a work-around, it might be possible to break the large region
2818into a series of smaller ones and watch them with separate watchpoints.
2819
2820If you set too many hardware watchpoints, @value{GDBN} might be unable
2821to insert all of them when you resume the execution of your program.
2822Since the precise number of active watchpoints is unknown until such
2823time as the program is about to be resumed, @value{GDBN} might not be
2824able to warn you about this when you set the watchpoints, and the
2825warning will be printed only when the program is resumed:
2826
2827@smallexample
2828Hardware watchpoint @var{num}: Could not insert watchpoint
2829@end smallexample
2830
2831@noindent
2832If this happens, delete or disable some of the watchpoints.
2833
2834The SPARClite DSU will generate traps when a program accesses some data
2835or instruction address that is assigned to the debug registers. For the
2836data addresses, DSU facilitates the @code{watch} command. However the
2837hardware breakpoint registers can only take two data watchpoints, and
2838both watchpoints must be the same kind. For example, you can set two
2839watchpoints with @code{watch} commands, two with @code{rwatch} commands,
2840@strong{or} two with @code{awatch} commands, but you cannot set one
2841watchpoint with one command and the other with a different command.
c906108c
SS
2842@value{GDBN} will reject the command if you try to mix watchpoints.
2843Delete or disable unused watchpoint commands before setting new ones.
2844
2845If you call a function interactively using @code{print} or @code{call},
2df3850c 2846any watchpoints you have set will be inactive until @value{GDBN} reaches another
c906108c
SS
2847kind of breakpoint or the call completes.
2848
7be570e7
JM
2849@value{GDBN} automatically deletes watchpoints that watch local
2850(automatic) variables, or expressions that involve such variables, when
2851they go out of scope, that is, when the execution leaves the block in
2852which these variables were defined. In particular, when the program
2853being debugged terminates, @emph{all} local variables go out of scope,
2854and so only watchpoints that watch global variables remain set. If you
2855rerun the program, you will need to set all such watchpoints again. One
2856way of doing that would be to set a code breakpoint at the entry to the
2857@code{main} function and when it breaks, set all the watchpoints.
2858
c906108c
SS
2859@quotation
2860@cindex watchpoints and threads
2861@cindex threads and watchpoints
c906108c
SS
2862@emph{Warning:} In multi-thread programs, watchpoints have only limited
2863usefulness. With the current watchpoint implementation, @value{GDBN}
2864can only watch the value of an expression @emph{in a single thread}. If
2865you are confident that the expression can only change due to the current
2866thread's activity (and if you are also confident that no other thread
2867can become current), then you can use watchpoints as usual. However,
2868@value{GDBN} may not notice when a non-current thread's activity changes
2869the expression.
53a5351d 2870
d4f3574e 2871@c FIXME: this is almost identical to the previous paragraph.
53a5351d
JM
2872@emph{HP-UX Warning:} In multi-thread programs, software watchpoints
2873have only limited usefulness. If @value{GDBN} creates a software
2874watchpoint, it can only watch the value of an expression @emph{in a
2875single thread}. If you are confident that the expression can only
2876change due to the current thread's activity (and if you are also
2877confident that no other thread can become current), then you can use
2878software watchpoints as usual. However, @value{GDBN} may not notice
2879when a non-current thread's activity changes the expression. (Hardware
2880watchpoints, in contrast, watch an expression in all threads.)
c906108c 2881@end quotation
c906108c 2882
501eef12
AC
2883@xref{set remote hardware-watchpoint-limit}.
2884
6d2ebf8b 2885@node Set Catchpoints
c906108c 2886@subsection Setting catchpoints
d4f3574e 2887@cindex catchpoints, setting
c906108c
SS
2888@cindex exception handlers
2889@cindex event handling
2890
2891You can use @dfn{catchpoints} to cause the debugger to stop for certain
b37052ae 2892kinds of program events, such as C@t{++} exceptions or the loading of a
c906108c
SS
2893shared library. Use the @code{catch} command to set a catchpoint.
2894
2895@table @code
2896@kindex catch
2897@item catch @var{event}
2898Stop when @var{event} occurs. @var{event} can be any of the following:
2899@table @code
2900@item throw
4644b6e3 2901@cindex stop on C@t{++} exceptions
b37052ae 2902The throwing of a C@t{++} exception.
c906108c
SS
2903
2904@item catch
b37052ae 2905The catching of a C@t{++} exception.
c906108c
SS
2906
2907@item exec
4644b6e3 2908@cindex break on fork/exec
c906108c
SS
2909A call to @code{exec}. This is currently only available for HP-UX.
2910
2911@item fork
c906108c
SS
2912A call to @code{fork}. This is currently only available for HP-UX.
2913
2914@item vfork
c906108c
SS
2915A call to @code{vfork}. This is currently only available for HP-UX.
2916
2917@item load
2918@itemx load @var{libname}
4644b6e3 2919@cindex break on load/unload of shared library
c906108c
SS
2920The dynamic loading of any shared library, or the loading of the library
2921@var{libname}. This is currently only available for HP-UX.
2922
2923@item unload
2924@itemx unload @var{libname}
c906108c
SS
2925The unloading of any dynamically loaded shared library, or the unloading
2926of the library @var{libname}. This is currently only available for HP-UX.
2927@end table
2928
2929@item tcatch @var{event}
2930Set a catchpoint that is enabled only for one stop. The catchpoint is
2931automatically deleted after the first time the event is caught.
2932
2933@end table
2934
2935Use the @code{info break} command to list the current catchpoints.
2936
b37052ae 2937There are currently some limitations to C@t{++} exception handling
c906108c
SS
2938(@code{catch throw} and @code{catch catch}) in @value{GDBN}:
2939
2940@itemize @bullet
2941@item
2942If you call a function interactively, @value{GDBN} normally returns
2943control to you when the function has finished executing. If the call
2944raises an exception, however, the call may bypass the mechanism that
2945returns control to you and cause your program either to abort or to
2946simply continue running until it hits a breakpoint, catches a signal
2947that @value{GDBN} is listening for, or exits. This is the case even if
2948you set a catchpoint for the exception; catchpoints on exceptions are
2949disabled within interactive calls.
2950
2951@item
2952You cannot raise an exception interactively.
2953
2954@item
2955You cannot install an exception handler interactively.
2956@end itemize
2957
2958@cindex raise exceptions
2959Sometimes @code{catch} is not the best way to debug exception handling:
2960if you need to know exactly where an exception is raised, it is better to
2961stop @emph{before} the exception handler is called, since that way you
2962can see the stack before any unwinding takes place. If you set a
2963breakpoint in an exception handler instead, it may not be easy to find
2964out where the exception was raised.
2965
2966To stop just before an exception handler is called, you need some
b37052ae 2967knowledge of the implementation. In the case of @sc{gnu} C@t{++}, exceptions are
c906108c
SS
2968raised by calling a library function named @code{__raise_exception}
2969which has the following ANSI C interface:
2970
474c8240 2971@smallexample
c906108c 2972 /* @var{addr} is where the exception identifier is stored.
d4f3574e
SS
2973 @var{id} is the exception identifier. */
2974 void __raise_exception (void **addr, void *id);
474c8240 2975@end smallexample
c906108c
SS
2976
2977@noindent
2978To make the debugger catch all exceptions before any stack
2979unwinding takes place, set a breakpoint on @code{__raise_exception}
2980(@pxref{Breakpoints, ,Breakpoints; watchpoints; and exceptions}).
2981
2982With a conditional breakpoint (@pxref{Conditions, ,Break conditions})
2983that depends on the value of @var{id}, you can stop your program when
2984a specific exception is raised. You can use multiple conditional
2985breakpoints to stop your program when any of a number of exceptions are
2986raised.
2987
2988
6d2ebf8b 2989@node Delete Breaks
c906108c
SS
2990@subsection Deleting breakpoints
2991
2992@cindex clearing breakpoints, watchpoints, catchpoints
2993@cindex deleting breakpoints, watchpoints, catchpoints
2994It is often necessary to eliminate a breakpoint, watchpoint, or
2995catchpoint once it has done its job and you no longer want your program
2996to stop there. This is called @dfn{deleting} the breakpoint. A
2997breakpoint that has been deleted no longer exists; it is forgotten.
2998
2999With the @code{clear} command you can delete breakpoints according to
3000where they are in your program. With the @code{delete} command you can
3001delete individual breakpoints, watchpoints, or catchpoints by specifying
3002their breakpoint numbers.
3003
3004It is not necessary to delete a breakpoint to proceed past it. @value{GDBN}
3005automatically ignores breakpoints on the first instruction to be executed
3006when you continue execution without changing the execution address.
3007
3008@table @code
3009@kindex clear
3010@item clear
3011Delete any breakpoints at the next instruction to be executed in the
3012selected stack frame (@pxref{Selection, ,Selecting a frame}). When
3013the innermost frame is selected, this is a good way to delete a
3014breakpoint where your program just stopped.
3015
3016@item clear @var{function}
3017@itemx clear @var{filename}:@var{function}
3018Delete any breakpoints set at entry to the function @var{function}.
3019
3020@item clear @var{linenum}
3021@itemx clear @var{filename}:@var{linenum}
3022Delete any breakpoints set at or within the code of the specified line.
3023
3024@cindex delete breakpoints
3025@kindex delete
41afff9a 3026@kindex d @r{(@code{delete})}
c5394b80
JM
3027@item delete @r{[}breakpoints@r{]} @r{[}@var{range}@dots{}@r{]}
3028Delete the breakpoints, watchpoints, or catchpoints of the breakpoint
3029ranges specified as arguments. If no argument is specified, delete all
c906108c
SS
3030breakpoints (@value{GDBN} asks confirmation, unless you have @code{set
3031confirm off}). You can abbreviate this command as @code{d}.
3032@end table
3033
6d2ebf8b 3034@node Disabling
c906108c
SS
3035@subsection Disabling breakpoints
3036
4644b6e3 3037@cindex enable/disable a breakpoint
c906108c
SS
3038Rather than deleting a breakpoint, watchpoint, or catchpoint, you might
3039prefer to @dfn{disable} it. This makes the breakpoint inoperative as if
3040it had been deleted, but remembers the information on the breakpoint so
3041that you can @dfn{enable} it again later.
3042
3043You disable and enable breakpoints, watchpoints, and catchpoints with
3044the @code{enable} and @code{disable} commands, optionally specifying one
3045or more breakpoint numbers as arguments. Use @code{info break} or
3046@code{info watch} to print a list of breakpoints, watchpoints, and
3047catchpoints if you do not know which numbers to use.
3048
3049A breakpoint, watchpoint, or catchpoint can have any of four different
3050states of enablement:
3051
3052@itemize @bullet
3053@item
3054Enabled. The breakpoint stops your program. A breakpoint set
3055with the @code{break} command starts out in this state.
3056@item
3057Disabled. The breakpoint has no effect on your program.
3058@item
3059Enabled once. The breakpoint stops your program, but then becomes
d4f3574e 3060disabled.
c906108c
SS
3061@item
3062Enabled for deletion. The breakpoint stops your program, but
d4f3574e
SS
3063immediately after it does so it is deleted permanently. A breakpoint
3064set with the @code{tbreak} command starts out in this state.
c906108c
SS
3065@end itemize
3066
3067You can use the following commands to enable or disable breakpoints,
3068watchpoints, and catchpoints:
3069
3070@table @code
c906108c 3071@kindex disable
41afff9a 3072@kindex dis @r{(@code{disable})}
c5394b80 3073@item disable @r{[}breakpoints@r{]} @r{[}@var{range}@dots{}@r{]}
c906108c
SS
3074Disable the specified breakpoints---or all breakpoints, if none are
3075listed. A disabled breakpoint has no effect but is not forgotten. All
3076options such as ignore-counts, conditions and commands are remembered in
3077case the breakpoint is enabled again later. You may abbreviate
3078@code{disable} as @code{dis}.
3079
c906108c 3080@kindex enable
c5394b80 3081@item enable @r{[}breakpoints@r{]} @r{[}@var{range}@dots{}@r{]}
c906108c
SS
3082Enable the specified breakpoints (or all defined breakpoints). They
3083become effective once again in stopping your program.
3084
c5394b80 3085@item enable @r{[}breakpoints@r{]} once @var{range}@dots{}
c906108c
SS
3086Enable the specified breakpoints temporarily. @value{GDBN} disables any
3087of these breakpoints immediately after stopping your program.
3088
c5394b80 3089@item enable @r{[}breakpoints@r{]} delete @var{range}@dots{}
c906108c
SS
3090Enable the specified breakpoints to work once, then die. @value{GDBN}
3091deletes any of these breakpoints as soon as your program stops there.
3092@end table
3093
d4f3574e
SS
3094@c FIXME: I think the following ``Except for [...] @code{tbreak}'' is
3095@c confusing: tbreak is also initially enabled.
c906108c
SS
3096Except for a breakpoint set with @code{tbreak} (@pxref{Set Breaks,
3097,Setting breakpoints}), breakpoints that you set are initially enabled;
3098subsequently, they become disabled or enabled only when you use one of
3099the commands above. (The command @code{until} can set and delete a
3100breakpoint of its own, but it does not change the state of your other
3101breakpoints; see @ref{Continuing and Stepping, ,Continuing and
3102stepping}.)
3103
6d2ebf8b 3104@node Conditions
c906108c
SS
3105@subsection Break conditions
3106@cindex conditional breakpoints
3107@cindex breakpoint conditions
3108
3109@c FIXME what is scope of break condition expr? Context where wanted?
5d161b24 3110@c in particular for a watchpoint?
c906108c
SS
3111The simplest sort of breakpoint breaks every time your program reaches a
3112specified place. You can also specify a @dfn{condition} for a
3113breakpoint. A condition is just a Boolean expression in your
3114programming language (@pxref{Expressions, ,Expressions}). A breakpoint with
3115a condition evaluates the expression each time your program reaches it,
3116and your program stops only if the condition is @emph{true}.
3117
3118This is the converse of using assertions for program validation; in that
3119situation, you want to stop when the assertion is violated---that is,
3120when the condition is false. In C, if you want to test an assertion expressed
3121by the condition @var{assert}, you should set the condition
3122@samp{! @var{assert}} on the appropriate breakpoint.
3123
3124Conditions are also accepted for watchpoints; you may not need them,
3125since a watchpoint is inspecting the value of an expression anyhow---but
3126it might be simpler, say, to just set a watchpoint on a variable name,
3127and specify a condition that tests whether the new value is an interesting
3128one.
3129
3130Break conditions can have side effects, and may even call functions in
3131your program. This can be useful, for example, to activate functions
3132that log program progress, or to use your own print functions to
3133format special data structures. The effects are completely predictable
3134unless there is another enabled breakpoint at the same address. (In
3135that case, @value{GDBN} might see the other breakpoint first and stop your
3136program without checking the condition of this one.) Note that
d4f3574e
SS
3137breakpoint commands are usually more convenient and flexible than break
3138conditions for the
c906108c
SS
3139purpose of performing side effects when a breakpoint is reached
3140(@pxref{Break Commands, ,Breakpoint command lists}).
3141
3142Break conditions can be specified when a breakpoint is set, by using
3143@samp{if} in the arguments to the @code{break} command. @xref{Set
3144Breaks, ,Setting breakpoints}. They can also be changed at any time
3145with the @code{condition} command.
53a5351d 3146
c906108c
SS
3147You can also use the @code{if} keyword with the @code{watch} command.
3148The @code{catch} command does not recognize the @code{if} keyword;
3149@code{condition} is the only way to impose a further condition on a
3150catchpoint.
c906108c
SS
3151
3152@table @code
3153@kindex condition
3154@item condition @var{bnum} @var{expression}
3155Specify @var{expression} as the break condition for breakpoint,
3156watchpoint, or catchpoint number @var{bnum}. After you set a condition,
3157breakpoint @var{bnum} stops your program only if the value of
3158@var{expression} is true (nonzero, in C). When you use
3159@code{condition}, @value{GDBN} checks @var{expression} immediately for
3160syntactic correctness, and to determine whether symbols in it have
d4f3574e
SS
3161referents in the context of your breakpoint. If @var{expression} uses
3162symbols not referenced in the context of the breakpoint, @value{GDBN}
3163prints an error message:
3164
474c8240 3165@smallexample
d4f3574e 3166No symbol "foo" in current context.
474c8240 3167@end smallexample
d4f3574e
SS
3168
3169@noindent
c906108c
SS
3170@value{GDBN} does
3171not actually evaluate @var{expression} at the time the @code{condition}
d4f3574e
SS
3172command (or a command that sets a breakpoint with a condition, like
3173@code{break if @dots{}}) is given, however. @xref{Expressions, ,Expressions}.
c906108c
SS
3174
3175@item condition @var{bnum}
3176Remove the condition from breakpoint number @var{bnum}. It becomes
3177an ordinary unconditional breakpoint.
3178@end table
3179
3180@cindex ignore count (of breakpoint)
3181A special case of a breakpoint condition is to stop only when the
3182breakpoint has been reached a certain number of times. This is so
3183useful that there is a special way to do it, using the @dfn{ignore
3184count} of the breakpoint. Every breakpoint has an ignore count, which
3185is an integer. Most of the time, the ignore count is zero, and
3186therefore has no effect. But if your program reaches a breakpoint whose
3187ignore count is positive, then instead of stopping, it just decrements
3188the ignore count by one and continues. As a result, if the ignore count
3189value is @var{n}, the breakpoint does not stop the next @var{n} times
3190your program reaches it.
3191
3192@table @code
3193@kindex ignore
3194@item ignore @var{bnum} @var{count}
3195Set the ignore count of breakpoint number @var{bnum} to @var{count}.
3196The next @var{count} times the breakpoint is reached, your program's
3197execution does not stop; other than to decrement the ignore count, @value{GDBN}
3198takes no action.
3199
3200To make the breakpoint stop the next time it is reached, specify
3201a count of zero.
3202
3203When you use @code{continue} to resume execution of your program from a
3204breakpoint, you can specify an ignore count directly as an argument to
3205@code{continue}, rather than using @code{ignore}. @xref{Continuing and
3206Stepping,,Continuing and stepping}.
3207
3208If a breakpoint has a positive ignore count and a condition, the
3209condition is not checked. Once the ignore count reaches zero,
3210@value{GDBN} resumes checking the condition.
3211
3212You could achieve the effect of the ignore count with a condition such
3213as @w{@samp{$foo-- <= 0}} using a debugger convenience variable that
3214is decremented each time. @xref{Convenience Vars, ,Convenience
3215variables}.
3216@end table
3217
3218Ignore counts apply to breakpoints, watchpoints, and catchpoints.
3219
3220
6d2ebf8b 3221@node Break Commands
c906108c
SS
3222@subsection Breakpoint command lists
3223
3224@cindex breakpoint commands
3225You can give any breakpoint (or watchpoint or catchpoint) a series of
3226commands to execute when your program stops due to that breakpoint. For
3227example, you might want to print the values of certain expressions, or
3228enable other breakpoints.
3229
3230@table @code
3231@kindex commands
3232@kindex end
3233@item commands @r{[}@var{bnum}@r{]}
3234@itemx @dots{} @var{command-list} @dots{}
3235@itemx end
3236Specify a list of commands for breakpoint number @var{bnum}. The commands
3237themselves appear on the following lines. Type a line containing just
3238@code{end} to terminate the commands.
3239
3240To remove all commands from a breakpoint, type @code{commands} and
3241follow it immediately with @code{end}; that is, give no commands.
3242
3243With no @var{bnum} argument, @code{commands} refers to the last
3244breakpoint, watchpoint, or catchpoint set (not to the breakpoint most
3245recently encountered).
3246@end table
3247
3248Pressing @key{RET} as a means of repeating the last @value{GDBN} command is
3249disabled within a @var{command-list}.
3250
3251You can use breakpoint commands to start your program up again. Simply
3252use the @code{continue} command, or @code{step}, or any other command
3253that resumes execution.
3254
3255Any other commands in the command list, after a command that resumes
3256execution, are ignored. This is because any time you resume execution
3257(even with a simple @code{next} or @code{step}), you may encounter
3258another breakpoint---which could have its own command list, leading to
3259ambiguities about which list to execute.
3260
3261@kindex silent
3262If the first command you specify in a command list is @code{silent}, the
3263usual message about stopping at a breakpoint is not printed. This may
3264be desirable for breakpoints that are to print a specific message and
3265then continue. If none of the remaining commands print anything, you
3266see no sign that the breakpoint was reached. @code{silent} is
3267meaningful only at the beginning of a breakpoint command list.
3268
3269The commands @code{echo}, @code{output}, and @code{printf} allow you to
3270print precisely controlled output, and are often useful in silent
3271breakpoints. @xref{Output, ,Commands for controlled output}.
3272
3273For example, here is how you could use breakpoint commands to print the
3274value of @code{x} at entry to @code{foo} whenever @code{x} is positive.
3275
474c8240 3276@smallexample
c906108c
SS
3277break foo if x>0
3278commands
3279silent
3280printf "x is %d\n",x
3281cont
3282end
474c8240 3283@end smallexample
c906108c
SS
3284
3285One application for breakpoint commands is to compensate for one bug so
3286you can test for another. Put a breakpoint just after the erroneous line
3287of code, give it a condition to detect the case in which something
3288erroneous has been done, and give it commands to assign correct values
3289to any variables that need them. End with the @code{continue} command
3290so that your program does not stop, and start with the @code{silent}
3291command so that no output is produced. Here is an example:
3292
474c8240 3293@smallexample
c906108c
SS
3294break 403
3295commands
3296silent
3297set x = y + 4
3298cont
3299end
474c8240 3300@end smallexample
c906108c 3301
6d2ebf8b 3302@node Breakpoint Menus
c906108c
SS
3303@subsection Breakpoint menus
3304@cindex overloading
3305@cindex symbol overloading
3306
b383017d 3307Some programming languages (notably C@t{++} and Objective-C) permit a
b37303ee 3308single function name
c906108c
SS
3309to be defined several times, for application in different contexts.
3310This is called @dfn{overloading}. When a function name is overloaded,
3311@samp{break @var{function}} is not enough to tell @value{GDBN} where you want
3312a breakpoint. If you realize this is a problem, you can use
3313something like @samp{break @var{function}(@var{types})} to specify which
3314particular version of the function you want. Otherwise, @value{GDBN} offers
3315you a menu of numbered choices for different possible breakpoints, and
3316waits for your selection with the prompt @samp{>}. The first two
3317options are always @samp{[0] cancel} and @samp{[1] all}. Typing @kbd{1}
3318sets a breakpoint at each definition of @var{function}, and typing
3319@kbd{0} aborts the @code{break} command without setting any new
3320breakpoints.
3321
3322For example, the following session excerpt shows an attempt to set a
3323breakpoint at the overloaded symbol @code{String::after}.
3324We choose three particular definitions of that function name:
3325
3326@c FIXME! This is likely to change to show arg type lists, at least
3327@smallexample
3328@group
3329(@value{GDBP}) b String::after
3330[0] cancel
3331[1] all
3332[2] file:String.cc; line number:867
3333[3] file:String.cc; line number:860
3334[4] file:String.cc; line number:875
3335[5] file:String.cc; line number:853
3336[6] file:String.cc; line number:846
3337[7] file:String.cc; line number:735
3338> 2 4 6
3339Breakpoint 1 at 0xb26c: file String.cc, line 867.
3340Breakpoint 2 at 0xb344: file String.cc, line 875.
3341Breakpoint 3 at 0xafcc: file String.cc, line 846.
3342Multiple breakpoints were set.
3343Use the "delete" command to delete unwanted
3344 breakpoints.
3345(@value{GDBP})
3346@end group
3347@end smallexample
c906108c
SS
3348
3349@c @ifclear BARETARGET
6d2ebf8b 3350@node Error in Breakpoints
d4f3574e 3351@subsection ``Cannot insert breakpoints''
c906108c
SS
3352@c
3353@c FIXME!! 14/6/95 Is there a real example of this? Let's use it.
3354@c
d4f3574e
SS
3355Under some operating systems, breakpoints cannot be used in a program if
3356any other process is running that program. In this situation,
5d161b24 3357attempting to run or continue a program with a breakpoint causes
d4f3574e
SS
3358@value{GDBN} to print an error message:
3359
474c8240 3360@smallexample
d4f3574e
SS
3361Cannot insert breakpoints.
3362The same program may be running in another process.
474c8240 3363@end smallexample
d4f3574e
SS
3364
3365When this happens, you have three ways to proceed:
3366
3367@enumerate
3368@item
3369Remove or disable the breakpoints, then continue.
3370
3371@item
5d161b24 3372Suspend @value{GDBN}, and copy the file containing your program to a new
d4f3574e 3373name. Resume @value{GDBN} and use the @code{exec-file} command to specify
5d161b24 3374that @value{GDBN} should run your program under that name.
d4f3574e
SS
3375Then start your program again.
3376
3377@item
3378Relink your program so that the text segment is nonsharable, using the
3379linker option @samp{-N}. The operating system limitation may not apply
3380to nonsharable executables.
3381@end enumerate
c906108c
SS
3382@c @end ifclear
3383
d4f3574e
SS
3384A similar message can be printed if you request too many active
3385hardware-assisted breakpoints and watchpoints:
3386
3387@c FIXME: the precise wording of this message may change; the relevant
3388@c source change is not committed yet (Sep 3, 1999).
3389@smallexample
3390Stopped; cannot insert breakpoints.
3391You may have requested too many hardware breakpoints and watchpoints.
3392@end smallexample
3393
3394@noindent
3395This message is printed when you attempt to resume the program, since
3396only then @value{GDBN} knows exactly how many hardware breakpoints and
3397watchpoints it needs to insert.
3398
3399When this message is printed, you need to disable or remove some of the
3400hardware-assisted breakpoints and watchpoints, and then continue.
3401
1485d690
KB
3402@node Breakpoint related warnings
3403@subsection ``Breakpoint address adjusted...''
3404@cindex breakpoint address adjusted
3405
3406Some processor architectures place constraints on the addresses at
3407which breakpoints may be placed. For architectures thus constrained,
3408@value{GDBN} will attempt to adjust the breakpoint's address to comply
3409with the constraints dictated by the architecture.
3410
3411One example of such an architecture is the Fujitsu FR-V. The FR-V is
3412a VLIW architecture in which a number of RISC-like instructions may be
3413bundled together for parallel execution. The FR-V architecture
3414constrains the location of a breakpoint instruction within such a
3415bundle to the instruction with the lowest address. @value{GDBN}
3416honors this constraint by adjusting a breakpoint's address to the
3417first in the bundle.
3418
3419It is not uncommon for optimized code to have bundles which contain
3420instructions from different source statements, thus it may happen that
3421a breakpoint's address will be adjusted from one source statement to
3422another. Since this adjustment may significantly alter @value{GDBN}'s
3423breakpoint related behavior from what the user expects, a warning is
3424printed when the breakpoint is first set and also when the breakpoint
3425is hit.
3426
3427A warning like the one below is printed when setting a breakpoint
3428that's been subject to address adjustment:
3429
3430@smallexample
3431warning: Breakpoint address adjusted from 0x00010414 to 0x00010410.
3432@end smallexample
3433
3434Such warnings are printed both for user settable and @value{GDBN}'s
3435internal breakpoints. If you see one of these warnings, you should
3436verify that a breakpoint set at the adjusted address will have the
3437desired affect. If not, the breakpoint in question may be removed and
b383017d 3438other breakpoints may be set which will have the desired behavior.
1485d690
KB
3439E.g., it may be sufficient to place the breakpoint at a later
3440instruction. A conditional breakpoint may also be useful in some
3441cases to prevent the breakpoint from triggering too often.
3442
3443@value{GDBN} will also issue a warning when stopping at one of these
3444adjusted breakpoints:
3445
3446@smallexample
3447warning: Breakpoint 1 address previously adjusted from 0x00010414
3448to 0x00010410.
3449@end smallexample
3450
3451When this warning is encountered, it may be too late to take remedial
3452action except in cases where the breakpoint is hit earlier or more
3453frequently than expected.
d4f3574e 3454
6d2ebf8b 3455@node Continuing and Stepping
c906108c
SS
3456@section Continuing and stepping
3457
3458@cindex stepping
3459@cindex continuing
3460@cindex resuming execution
3461@dfn{Continuing} means resuming program execution until your program
3462completes normally. In contrast, @dfn{stepping} means executing just
3463one more ``step'' of your program, where ``step'' may mean either one
3464line of source code, or one machine instruction (depending on what
7a292a7a
SS
3465particular command you use). Either when continuing or when stepping,
3466your program may stop even sooner, due to a breakpoint or a signal. (If
d4f3574e
SS
3467it stops due to a signal, you may want to use @code{handle}, or use
3468@samp{signal 0} to resume execution. @xref{Signals, ,Signals}.)
c906108c
SS
3469
3470@table @code
3471@kindex continue
41afff9a
EZ
3472@kindex c @r{(@code{continue})}
3473@kindex fg @r{(resume foreground execution)}
c906108c
SS
3474@item continue @r{[}@var{ignore-count}@r{]}
3475@itemx c @r{[}@var{ignore-count}@r{]}
3476@itemx fg @r{[}@var{ignore-count}@r{]}
3477Resume program execution, at the address where your program last stopped;
3478any breakpoints set at that address are bypassed. The optional argument
3479@var{ignore-count} allows you to specify a further number of times to
3480ignore a breakpoint at this location; its effect is like that of
3481@code{ignore} (@pxref{Conditions, ,Break conditions}).
3482
3483The argument @var{ignore-count} is meaningful only when your program
3484stopped due to a breakpoint. At other times, the argument to
3485@code{continue} is ignored.
3486
d4f3574e
SS
3487The synonyms @code{c} and @code{fg} (for @dfn{foreground}, as the
3488debugged program is deemed to be the foreground program) are provided
3489purely for convenience, and have exactly the same behavior as
3490@code{continue}.
c906108c
SS
3491@end table
3492
3493To resume execution at a different place, you can use @code{return}
3494(@pxref{Returning, ,Returning from a function}) to go back to the
3495calling function; or @code{jump} (@pxref{Jumping, ,Continuing at a
3496different address}) to go to an arbitrary location in your program.
3497
3498A typical technique for using stepping is to set a breakpoint
3499(@pxref{Breakpoints, ,Breakpoints; watchpoints; and catchpoints}) at the
3500beginning of the function or the section of your program where a problem
3501is believed to lie, run your program until it stops at that breakpoint,
3502and then step through the suspect area, examining the variables that are
3503interesting, until you see the problem happen.
3504
3505@table @code
3506@kindex step
41afff9a 3507@kindex s @r{(@code{step})}
c906108c
SS
3508@item step
3509Continue running your program until control reaches a different source
3510line, then stop it and return control to @value{GDBN}. This command is
3511abbreviated @code{s}.
3512
3513@quotation
3514@c "without debugging information" is imprecise; actually "without line
3515@c numbers in the debugging information". (gcc -g1 has debugging info but
3516@c not line numbers). But it seems complex to try to make that
3517@c distinction here.
3518@emph{Warning:} If you use the @code{step} command while control is
3519within a function that was compiled without debugging information,
3520execution proceeds until control reaches a function that does have
3521debugging information. Likewise, it will not step into a function which
3522is compiled without debugging information. To step through functions
3523without debugging information, use the @code{stepi} command, described
3524below.
3525@end quotation
3526
4a92d011
EZ
3527The @code{step} command only stops at the first instruction of a source
3528line. This prevents the multiple stops that could otherwise occur in
3529@code{switch} statements, @code{for} loops, etc. @code{step} continues
3530to stop if a function that has debugging information is called within
3531the line. In other words, @code{step} @emph{steps inside} any functions
3532called within the line.
c906108c 3533
d4f3574e
SS
3534Also, the @code{step} command only enters a function if there is line
3535number information for the function. Otherwise it acts like the
5d161b24 3536@code{next} command. This avoids problems when using @code{cc -gl}
c906108c 3537on MIPS machines. Previously, @code{step} entered subroutines if there
5d161b24 3538was any debugging information about the routine.
c906108c
SS
3539
3540@item step @var{count}
3541Continue running as in @code{step}, but do so @var{count} times. If a
7a292a7a
SS
3542breakpoint is reached, or a signal not related to stepping occurs before
3543@var{count} steps, stepping stops right away.
c906108c
SS
3544
3545@kindex next
41afff9a 3546@kindex n @r{(@code{next})}
c906108c
SS
3547@item next @r{[}@var{count}@r{]}
3548Continue to the next source line in the current (innermost) stack frame.
7a292a7a
SS
3549This is similar to @code{step}, but function calls that appear within
3550the line of code are executed without stopping. Execution stops when
3551control reaches a different line of code at the original stack level
3552that was executing when you gave the @code{next} command. This command
3553is abbreviated @code{n}.
c906108c
SS
3554
3555An argument @var{count} is a repeat count, as for @code{step}.
3556
3557
3558@c FIX ME!! Do we delete this, or is there a way it fits in with
3559@c the following paragraph? --- Vctoria
3560@c
3561@c @code{next} within a function that lacks debugging information acts like
3562@c @code{step}, but any function calls appearing within the code of the
3563@c function are executed without stopping.
3564
d4f3574e
SS
3565The @code{next} command only stops at the first instruction of a
3566source line. This prevents multiple stops that could otherwise occur in
4a92d011 3567@code{switch} statements, @code{for} loops, etc.
c906108c 3568
b90a5f51
CF
3569@kindex set step-mode
3570@item set step-mode
3571@cindex functions without line info, and stepping
3572@cindex stepping into functions with no line info
3573@itemx set step-mode on
4a92d011 3574The @code{set step-mode on} command causes the @code{step} command to
b90a5f51
CF
3575stop at the first instruction of a function which contains no debug line
3576information rather than stepping over it.
3577
4a92d011
EZ
3578This is useful in cases where you may be interested in inspecting the
3579machine instructions of a function which has no symbolic info and do not
3580want @value{GDBN} to automatically skip over this function.
b90a5f51
CF
3581
3582@item set step-mode off
4a92d011 3583Causes the @code{step} command to step over any functions which contains no
b90a5f51
CF
3584debug information. This is the default.
3585
c906108c
SS
3586@kindex finish
3587@item finish
3588Continue running until just after function in the selected stack frame
3589returns. Print the returned value (if any).
3590
3591Contrast this with the @code{return} command (@pxref{Returning,
3592,Returning from a function}).
3593
3594@kindex until
41afff9a 3595@kindex u @r{(@code{until})}
c906108c
SS
3596@item until
3597@itemx u
3598Continue running until a source line past the current line, in the
3599current stack frame, is reached. This command is used to avoid single
3600stepping through a loop more than once. It is like the @code{next}
3601command, except that when @code{until} encounters a jump, it
3602automatically continues execution until the program counter is greater
3603than the address of the jump.
3604
3605This means that when you reach the end of a loop after single stepping
3606though it, @code{until} makes your program continue execution until it
3607exits the loop. In contrast, a @code{next} command at the end of a loop
3608simply steps back to the beginning of the loop, which forces you to step
3609through the next iteration.
3610
3611@code{until} always stops your program if it attempts to exit the current
3612stack frame.
3613
3614@code{until} may produce somewhat counterintuitive results if the order
3615of machine code does not match the order of the source lines. For
3616example, in the following excerpt from a debugging session, the @code{f}
3617(@code{frame}) command shows that execution is stopped at line
3618@code{206}; yet when we use @code{until}, we get to line @code{195}:
3619
474c8240 3620@smallexample
c906108c
SS
3621(@value{GDBP}) f
3622#0 main (argc=4, argv=0xf7fffae8) at m4.c:206
3623206 expand_input();
3624(@value{GDBP}) until
3625195 for ( ; argc > 0; NEXTARG) @{
474c8240 3626@end smallexample
c906108c
SS
3627
3628This happened because, for execution efficiency, the compiler had
3629generated code for the loop closure test at the end, rather than the
3630start, of the loop---even though the test in a C @code{for}-loop is
3631written before the body of the loop. The @code{until} command appeared
3632to step back to the beginning of the loop when it advanced to this
3633expression; however, it has not really gone to an earlier
3634statement---not in terms of the actual machine code.
3635
3636@code{until} with no argument works by means of single
3637instruction stepping, and hence is slower than @code{until} with an
3638argument.
3639
3640@item until @var{location}
3641@itemx u @var{location}
3642Continue running your program until either the specified location is
3643reached, or the current stack frame returns. @var{location} is any of
3644the forms of argument acceptable to @code{break} (@pxref{Set Breaks,
c60eb6f1
EZ
3645,Setting breakpoints}). This form of the command uses breakpoints, and
3646hence is quicker than @code{until} without an argument. The specified
3647location is actually reached only if it is in the current frame. This
3648implies that @code{until} can be used to skip over recursive function
3649invocations. For instance in the code below, if the current location is
3650line @code{96}, issuing @code{until 99} will execute the program up to
3651line @code{99} in the same invocation of factorial, i.e. after the inner
3652invocations have returned.
3653
3654@smallexample
365594 int factorial (int value)
365695 @{
365796 if (value > 1) @{
365897 value *= factorial (value - 1);
365998 @}
366099 return (value);
3661100 @}
3662@end smallexample
3663
3664
3665@kindex advance @var{location}
3666@itemx advance @var{location}
3667Continue running the program up to the given location. An argument is
3668required, anything of the same form as arguments for the @code{break}
3669command. Execution will also stop upon exit from the current stack
3670frame. This command is similar to @code{until}, but @code{advance} will
3671not skip over recursive function calls, and the target location doesn't
3672have to be in the same frame as the current one.
3673
c906108c
SS
3674
3675@kindex stepi
41afff9a 3676@kindex si @r{(@code{stepi})}
c906108c 3677@item stepi
96a2c332 3678@itemx stepi @var{arg}
c906108c
SS
3679@itemx si
3680Execute one machine instruction, then stop and return to the debugger.
3681
3682It is often useful to do @samp{display/i $pc} when stepping by machine
3683instructions. This makes @value{GDBN} automatically display the next
3684instruction to be executed, each time your program stops. @xref{Auto
3685Display,, Automatic display}.
3686
3687An argument is a repeat count, as in @code{step}.
3688
3689@need 750
3690@kindex nexti
41afff9a 3691@kindex ni @r{(@code{nexti})}
c906108c 3692@item nexti
96a2c332 3693@itemx nexti @var{arg}
c906108c
SS
3694@itemx ni
3695Execute one machine instruction, but if it is a function call,
3696proceed until the function returns.
3697
3698An argument is a repeat count, as in @code{next}.
3699@end table
3700
6d2ebf8b 3701@node Signals
c906108c
SS
3702@section Signals
3703@cindex signals
3704
3705A signal is an asynchronous event that can happen in a program. The
3706operating system defines the possible kinds of signals, and gives each
3707kind a name and a number. For example, in Unix @code{SIGINT} is the
d4f3574e 3708signal a program gets when you type an interrupt character (often @kbd{C-c});
c906108c
SS
3709@code{SIGSEGV} is the signal a program gets from referencing a place in
3710memory far away from all the areas in use; @code{SIGALRM} occurs when
3711the alarm clock timer goes off (which happens only if your program has
3712requested an alarm).
3713
3714@cindex fatal signals
3715Some signals, including @code{SIGALRM}, are a normal part of the
3716functioning of your program. Others, such as @code{SIGSEGV}, indicate
d4f3574e 3717errors; these signals are @dfn{fatal} (they kill your program immediately) if the
c906108c
SS
3718program has not specified in advance some other way to handle the signal.
3719@code{SIGINT} does not indicate an error in your program, but it is normally
3720fatal so it can carry out the purpose of the interrupt: to kill the program.
3721
3722@value{GDBN} has the ability to detect any occurrence of a signal in your
3723program. You can tell @value{GDBN} in advance what to do for each kind of
3724signal.
3725
3726@cindex handling signals
24f93129
EZ
3727Normally, @value{GDBN} is set up to let the non-erroneous signals like
3728@code{SIGALRM} be silently passed to your program
3729(so as not to interfere with their role in the program's functioning)
c906108c
SS
3730but to stop your program immediately whenever an error signal happens.
3731You can change these settings with the @code{handle} command.
3732
3733@table @code
3734@kindex info signals
3735@item info signals
96a2c332 3736@itemx info handle
c906108c
SS
3737Print a table of all the kinds of signals and how @value{GDBN} has been told to
3738handle each one. You can use this to see the signal numbers of all
3739the defined types of signals.
3740
d4f3574e 3741@code{info handle} is an alias for @code{info signals}.
c906108c
SS
3742
3743@kindex handle
3744@item handle @var{signal} @var{keywords}@dots{}
5ece1a18
EZ
3745Change the way @value{GDBN} handles signal @var{signal}. @var{signal}
3746can be the number of a signal or its name (with or without the
24f93129 3747@samp{SIG} at the beginning); a list of signal numbers of the form
5ece1a18
EZ
3748@samp{@var{low}-@var{high}}; or the word @samp{all}, meaning all the
3749known signals. The @var{keywords} say what change to make.
c906108c
SS
3750@end table
3751
3752@c @group
3753The keywords allowed by the @code{handle} command can be abbreviated.
3754Their full names are:
3755
3756@table @code
3757@item nostop
3758@value{GDBN} should not stop your program when this signal happens. It may
3759still print a message telling you that the signal has come in.
3760
3761@item stop
3762@value{GDBN} should stop your program when this signal happens. This implies
3763the @code{print} keyword as well.
3764
3765@item print
3766@value{GDBN} should print a message when this signal happens.
3767
3768@item noprint
3769@value{GDBN} should not mention the occurrence of the signal at all. This
3770implies the @code{nostop} keyword as well.
3771
3772@item pass
5ece1a18 3773@itemx noignore
c906108c
SS
3774@value{GDBN} should allow your program to see this signal; your program
3775can handle the signal, or else it may terminate if the signal is fatal
5ece1a18 3776and not handled. @code{pass} and @code{noignore} are synonyms.
c906108c
SS
3777
3778@item nopass
5ece1a18 3779@itemx ignore
c906108c 3780@value{GDBN} should not allow your program to see this signal.
5ece1a18 3781@code{nopass} and @code{ignore} are synonyms.
c906108c
SS
3782@end table
3783@c @end group
3784
d4f3574e
SS
3785When a signal stops your program, the signal is not visible to the
3786program until you
c906108c
SS
3787continue. Your program sees the signal then, if @code{pass} is in
3788effect for the signal in question @emph{at that time}. In other words,
3789after @value{GDBN} reports a signal, you can use the @code{handle}
3790command with @code{pass} or @code{nopass} to control whether your
3791program sees that signal when you continue.
3792
24f93129
EZ
3793The default is set to @code{nostop}, @code{noprint}, @code{pass} for
3794non-erroneous signals such as @code{SIGALRM}, @code{SIGWINCH} and
3795@code{SIGCHLD}, and to @code{stop}, @code{print}, @code{pass} for the
3796erroneous signals.
3797
c906108c
SS
3798You can also use the @code{signal} command to prevent your program from
3799seeing a signal, or cause it to see a signal it normally would not see,
3800or to give it any signal at any time. For example, if your program stopped
3801due to some sort of memory reference error, you might store correct
3802values into the erroneous variables and continue, hoping to see more
3803execution; but your program would probably terminate immediately as
3804a result of the fatal signal once it saw the signal. To prevent this,
3805you can continue with @samp{signal 0}. @xref{Signaling, ,Giving your
5d161b24 3806program a signal}.
c906108c 3807
6d2ebf8b 3808@node Thread Stops
c906108c
SS
3809@section Stopping and starting multi-thread programs
3810
3811When your program has multiple threads (@pxref{Threads,, Debugging
3812programs with multiple threads}), you can choose whether to set
3813breakpoints on all threads, or on a particular thread.
3814
3815@table @code
3816@cindex breakpoints and threads
3817@cindex thread breakpoints
3818@kindex break @dots{} thread @var{threadno}
3819@item break @var{linespec} thread @var{threadno}
3820@itemx break @var{linespec} thread @var{threadno} if @dots{}
3821@var{linespec} specifies source lines; there are several ways of
3822writing them, but the effect is always to specify some source line.
3823
3824Use the qualifier @samp{thread @var{threadno}} with a breakpoint command
3825to specify that you only want @value{GDBN} to stop the program when a
3826particular thread reaches this breakpoint. @var{threadno} is one of the
3827numeric thread identifiers assigned by @value{GDBN}, shown in the first
3828column of the @samp{info threads} display.
3829
3830If you do not specify @samp{thread @var{threadno}} when you set a
3831breakpoint, the breakpoint applies to @emph{all} threads of your
3832program.
3833
3834You can use the @code{thread} qualifier on conditional breakpoints as
3835well; in this case, place @samp{thread @var{threadno}} before the
3836breakpoint condition, like this:
3837
3838@smallexample
2df3850c 3839(@value{GDBP}) break frik.c:13 thread 28 if bartab > lim
c906108c
SS
3840@end smallexample
3841
3842@end table
3843
3844@cindex stopped threads
3845@cindex threads, stopped
3846Whenever your program stops under @value{GDBN} for any reason,
3847@emph{all} threads of execution stop, not just the current thread. This
3848allows you to examine the overall state of the program, including
3849switching between threads, without worrying that things may change
3850underfoot.
3851
36d86913
MC
3852@cindex thread breakpoints and system calls
3853@cindex system calls and thread breakpoints
3854@cindex premature return from system calls
3855There is an unfortunate side effect. If one thread stops for a
3856breakpoint, or for some other reason, and another thread is blocked in a
3857system call, then the system call may return prematurely. This is a
3858consequence of the interaction between multiple threads and the signals
3859that @value{GDBN} uses to implement breakpoints and other events that
3860stop execution.
3861
3862To handle this problem, your program should check the return value of
3863each system call and react appropriately. This is good programming
3864style anyways.
3865
3866For example, do not write code like this:
3867
3868@smallexample
3869 sleep (10);
3870@end smallexample
3871
3872The call to @code{sleep} will return early if a different thread stops
3873at a breakpoint or for some other reason.
3874
3875Instead, write this:
3876
3877@smallexample
3878 int unslept = 10;
3879 while (unslept > 0)
3880 unslept = sleep (unslept);
3881@end smallexample
3882
3883A system call is allowed to return early, so the system is still
3884conforming to its specification. But @value{GDBN} does cause your
3885multi-threaded program to behave differently than it would without
3886@value{GDBN}.
3887
3888Also, @value{GDBN} uses internal breakpoints in the thread library to
3889monitor certain events such as thread creation and thread destruction.
3890When such an event happens, a system call in another thread may return
3891prematurely, even though your program does not appear to stop.
3892
c906108c
SS
3893@cindex continuing threads
3894@cindex threads, continuing
3895Conversely, whenever you restart the program, @emph{all} threads start
3896executing. @emph{This is true even when single-stepping} with commands
5d161b24 3897like @code{step} or @code{next}.
c906108c
SS
3898
3899In particular, @value{GDBN} cannot single-step all threads in lockstep.
3900Since thread scheduling is up to your debugging target's operating
3901system (not controlled by @value{GDBN}), other threads may
3902execute more than one statement while the current thread completes a
3903single step. Moreover, in general other threads stop in the middle of a
3904statement, rather than at a clean statement boundary, when the program
3905stops.
3906
3907You might even find your program stopped in another thread after
3908continuing or even single-stepping. This happens whenever some other
3909thread runs into a breakpoint, a signal, or an exception before the
3910first thread completes whatever you requested.
3911
3912On some OSes, you can lock the OS scheduler and thus allow only a single
3913thread to run.
3914
3915@table @code
3916@item set scheduler-locking @var{mode}
3917Set the scheduler locking mode. If it is @code{off}, then there is no
3918locking and any thread may run at any time. If @code{on}, then only the
3919current thread may run when the inferior is resumed. The @code{step}
3920mode optimizes for single-stepping. It stops other threads from
3921``seizing the prompt'' by preempting the current thread while you are
3922stepping. Other threads will only rarely (or never) get a chance to run
d4f3574e 3923when you step. They are more likely to run when you @samp{next} over a
c906108c 3924function call, and they are completely free to run when you use commands
d4f3574e 3925like @samp{continue}, @samp{until}, or @samp{finish}. However, unless another
c906108c 3926thread hits a breakpoint during its timeslice, they will never steal the
2df3850c 3927@value{GDBN} prompt away from the thread that you are debugging.
c906108c
SS
3928
3929@item show scheduler-locking
3930Display the current scheduler locking mode.
3931@end table
3932
c906108c 3933
6d2ebf8b 3934@node Stack
c906108c
SS
3935@chapter Examining the Stack
3936
3937When your program has stopped, the first thing you need to know is where it
3938stopped and how it got there.
3939
3940@cindex call stack
5d161b24
DB
3941Each time your program performs a function call, information about the call
3942is generated.
3943That information includes the location of the call in your program,
3944the arguments of the call,
c906108c 3945and the local variables of the function being called.
5d161b24 3946The information is saved in a block of data called a @dfn{stack frame}.
c906108c
SS
3947The stack frames are allocated in a region of memory called the @dfn{call
3948stack}.
3949
3950When your program stops, the @value{GDBN} commands for examining the
3951stack allow you to see all of this information.
3952
3953@cindex selected frame
3954One of the stack frames is @dfn{selected} by @value{GDBN} and many
3955@value{GDBN} commands refer implicitly to the selected frame. In
3956particular, whenever you ask @value{GDBN} for the value of a variable in
3957your program, the value is found in the selected frame. There are
3958special @value{GDBN} commands to select whichever frame you are
3959interested in. @xref{Selection, ,Selecting a frame}.
3960
3961When your program stops, @value{GDBN} automatically selects the
5d161b24 3962currently executing frame and describes it briefly, similar to the
c906108c
SS
3963@code{frame} command (@pxref{Frame Info, ,Information about a frame}).
3964
3965@menu
3966* Frames:: Stack frames
3967* Backtrace:: Backtraces
3968* Selection:: Selecting a frame
3969* Frame Info:: Information on a frame
c906108c
SS
3970
3971@end menu
3972
6d2ebf8b 3973@node Frames
c906108c
SS
3974@section Stack frames
3975
d4f3574e 3976@cindex frame, definition
c906108c
SS
3977@cindex stack frame
3978The call stack is divided up into contiguous pieces called @dfn{stack
3979frames}, or @dfn{frames} for short; each frame is the data associated
3980with one call to one function. The frame contains the arguments given
3981to the function, the function's local variables, and the address at
3982which the function is executing.
3983
3984@cindex initial frame
3985@cindex outermost frame
3986@cindex innermost frame
3987When your program is started, the stack has only one frame, that of the
3988function @code{main}. This is called the @dfn{initial} frame or the
3989@dfn{outermost} frame. Each time a function is called, a new frame is
3990made. Each time a function returns, the frame for that function invocation
3991is eliminated. If a function is recursive, there can be many frames for
3992the same function. The frame for the function in which execution is
3993actually occurring is called the @dfn{innermost} frame. This is the most
3994recently created of all the stack frames that still exist.
3995
3996@cindex frame pointer
3997Inside your program, stack frames are identified by their addresses. A
3998stack frame consists of many bytes, each of which has its own address; each
3999kind of computer has a convention for choosing one byte whose
4000address serves as the address of the frame. Usually this address is kept
4001in a register called the @dfn{frame pointer register} while execution is
4002going on in that frame.
4003
4004@cindex frame number
4005@value{GDBN} assigns numbers to all existing stack frames, starting with
4006zero for the innermost frame, one for the frame that called it,
4007and so on upward. These numbers do not really exist in your program;
4008they are assigned by @value{GDBN} to give you a way of designating stack
4009frames in @value{GDBN} commands.
4010
6d2ebf8b
SS
4011@c The -fomit-frame-pointer below perennially causes hbox overflow
4012@c underflow problems.
c906108c
SS
4013@cindex frameless execution
4014Some compilers provide a way to compile functions so that they operate
6d2ebf8b 4015without stack frames. (For example, the @value{GCC} option
474c8240 4016@smallexample
6d2ebf8b 4017@samp{-fomit-frame-pointer}
474c8240 4018@end smallexample
6d2ebf8b 4019generates functions without a frame.)
c906108c
SS
4020This is occasionally done with heavily used library functions to save
4021the frame setup time. @value{GDBN} has limited facilities for dealing
4022with these function invocations. If the innermost function invocation
4023has no stack frame, @value{GDBN} nevertheless regards it as though
4024it had a separate frame, which is numbered zero as usual, allowing
4025correct tracing of the function call chain. However, @value{GDBN} has
4026no provision for frameless functions elsewhere in the stack.
4027
4028@table @code
d4f3574e 4029@kindex frame@r{, command}
41afff9a 4030@cindex current stack frame
c906108c 4031@item frame @var{args}
5d161b24 4032The @code{frame} command allows you to move from one stack frame to another,
c906108c 4033and to print the stack frame you select. @var{args} may be either the
5d161b24
DB
4034address of the frame or the stack frame number. Without an argument,
4035@code{frame} prints the current stack frame.
c906108c
SS
4036
4037@kindex select-frame
41afff9a 4038@cindex selecting frame silently
c906108c
SS
4039@item select-frame
4040The @code{select-frame} command allows you to move from one stack frame
4041to another without printing the frame. This is the silent version of
4042@code{frame}.
4043@end table
4044
6d2ebf8b 4045@node Backtrace
c906108c
SS
4046@section Backtraces
4047
4048@cindex backtraces
4049@cindex tracebacks
4050@cindex stack traces
4051A backtrace is a summary of how your program got where it is. It shows one
4052line per frame, for many frames, starting with the currently executing
4053frame (frame zero), followed by its caller (frame one), and on up the
4054stack.
4055
4056@table @code
4057@kindex backtrace
41afff9a 4058@kindex bt @r{(@code{backtrace})}
c906108c
SS
4059@item backtrace
4060@itemx bt
4061Print a backtrace of the entire stack: one line per frame for all
4062frames in the stack.
4063
4064You can stop the backtrace at any time by typing the system interrupt
4065character, normally @kbd{C-c}.
4066
4067@item backtrace @var{n}
4068@itemx bt @var{n}
4069Similar, but print only the innermost @var{n} frames.
4070
4071@item backtrace -@var{n}
4072@itemx bt -@var{n}
4073Similar, but print only the outermost @var{n} frames.
4074@end table
4075
4076@kindex where
4077@kindex info stack
c906108c
SS
4078The names @code{where} and @code{info stack} (abbreviated @code{info s})
4079are additional aliases for @code{backtrace}.
4080
4081Each line in the backtrace shows the frame number and the function name.
4082The program counter value is also shown---unless you use @code{set
4083print address off}. The backtrace also shows the source file name and
4084line number, as well as the arguments to the function. The program
4085counter value is omitted if it is at the beginning of the code for that
4086line number.
4087
4088Here is an example of a backtrace. It was made with the command
4089@samp{bt 3}, so it shows the innermost three frames.
4090
4091@smallexample
4092@group
5d161b24 4093#0 m4_traceon (obs=0x24eb0, argc=1, argv=0x2b8c8)
c906108c
SS
4094 at builtin.c:993
4095#1 0x6e38 in expand_macro (sym=0x2b600) at macro.c:242
4096#2 0x6840 in expand_token (obs=0x0, t=177664, td=0xf7fffb08)
4097 at macro.c:71
4098(More stack frames follow...)
4099@end group
4100@end smallexample
4101
4102@noindent
4103The display for frame zero does not begin with a program counter
4104value, indicating that your program has stopped at the beginning of the
4105code for line @code{993} of @code{builtin.c}.
4106
25d29d70
AC
4107Most programs have a standard user entry point---a place where system
4108libraries and startup code transition into user code. For C this is
4109@code{main}. When @value{GDBN} finds the entry function in a backtrace
4110it will terminate the backtrace, to avoid tracing into highly
4111system-specific (and generally uninteresting) code.
4112
4113If you need to examine the startup code, or limit the number of levels
4114in a backtrace, you can change this behavior:
95f90d25
DJ
4115
4116@table @code
25d29d70
AC
4117@item set backtrace past-main
4118@itemx set backtrace past-main on
4644b6e3 4119@kindex set backtrace
25d29d70
AC
4120Backtraces will continue past the user entry point.
4121
4122@item set backtrace past-main off
95f90d25
DJ
4123Backtraces will stop when they encounter the user entry point. This is the
4124default.
4125
25d29d70 4126@item show backtrace past-main
4644b6e3 4127@kindex show backtrace
25d29d70
AC
4128Display the current user entry point backtrace policy.
4129
2315ffec
RC
4130@item set backtrace past-entry
4131@itemx set backtrace past-entry on
4132Backtraces will continue past the internal entry point of an application.
4133This entry point is encoded by the linker when the application is built,
4134and is likely before the user entry point @code{main} (or equivalent) is called.
4135
4136@item set backtrace past-entry off
4137Backtraces will stop when they encouter the internal entry point of an
4138application. This is the default.
4139
4140@item show backtrace past-entry
4141Display the current internal entry point backtrace policy.
4142
25d29d70
AC
4143@item set backtrace limit @var{n}
4144@itemx set backtrace limit 0
4145@cindex backtrace limit
4146Limit the backtrace to @var{n} levels. A value of zero means
4147unlimited.
95f90d25 4148
25d29d70
AC
4149@item show backtrace limit
4150Display the current limit on backtrace levels.
95f90d25
DJ
4151@end table
4152
6d2ebf8b 4153@node Selection
c906108c
SS
4154@section Selecting a frame
4155
4156Most commands for examining the stack and other data in your program work on
4157whichever stack frame is selected at the moment. Here are the commands for
4158selecting a stack frame; all of them finish by printing a brief description
4159of the stack frame just selected.
4160
4161@table @code
d4f3574e 4162@kindex frame@r{, selecting}
41afff9a 4163@kindex f @r{(@code{frame})}
c906108c
SS
4164@item frame @var{n}
4165@itemx f @var{n}
4166Select frame number @var{n}. Recall that frame zero is the innermost
4167(currently executing) frame, frame one is the frame that called the
4168innermost one, and so on. The highest-numbered frame is the one for
4169@code{main}.
4170
4171@item frame @var{addr}
4172@itemx f @var{addr}
4173Select the frame at address @var{addr}. This is useful mainly if the
4174chaining of stack frames has been damaged by a bug, making it
4175impossible for @value{GDBN} to assign numbers properly to all frames. In
4176addition, this can be useful when your program has multiple stacks and
4177switches between them.
4178
c906108c
SS
4179On the SPARC architecture, @code{frame} needs two addresses to
4180select an arbitrary frame: a frame pointer and a stack pointer.
4181
4182On the MIPS and Alpha architecture, it needs two addresses: a stack
4183pointer and a program counter.
4184
4185On the 29k architecture, it needs three addresses: a register stack
4186pointer, a program counter, and a memory stack pointer.
4187@c note to future updaters: this is conditioned on a flag
4188@c SETUP_ARBITRARY_FRAME in the tm-*.h files. The above is up to date
4189@c as of 27 Jan 1994.
c906108c
SS
4190
4191@kindex up
4192@item up @var{n}
4193Move @var{n} frames up the stack. For positive numbers @var{n}, this
4194advances toward the outermost frame, to higher frame numbers, to frames
4195that have existed longer. @var{n} defaults to one.
4196
4197@kindex down
41afff9a 4198@kindex do @r{(@code{down})}
c906108c
SS
4199@item down @var{n}
4200Move @var{n} frames down the stack. For positive numbers @var{n}, this
4201advances toward the innermost frame, to lower frame numbers, to frames
4202that were created more recently. @var{n} defaults to one. You may
4203abbreviate @code{down} as @code{do}.
4204@end table
4205
4206All of these commands end by printing two lines of output describing the
4207frame. The first line shows the frame number, the function name, the
4208arguments, and the source file and line number of execution in that
5d161b24 4209frame. The second line shows the text of that source line.
c906108c
SS
4210
4211@need 1000
4212For example:
4213
4214@smallexample
4215@group
4216(@value{GDBP}) up
4217#1 0x22f0 in main (argc=1, argv=0xf7fffbf4, env=0xf7fffbfc)
4218 at env.c:10
421910 read_input_file (argv[i]);
4220@end group
4221@end smallexample
4222
4223After such a printout, the @code{list} command with no arguments
4224prints ten lines centered on the point of execution in the frame.
87885426
FN
4225You can also edit the program at the point of execution with your favorite
4226editing program by typing @code{edit}.
4227@xref{List, ,Printing source lines},
4228for details.
c906108c
SS
4229
4230@table @code
4231@kindex down-silently
4232@kindex up-silently
4233@item up-silently @var{n}
4234@itemx down-silently @var{n}
4235These two commands are variants of @code{up} and @code{down},
4236respectively; they differ in that they do their work silently, without
4237causing display of the new frame. They are intended primarily for use
4238in @value{GDBN} command scripts, where the output might be unnecessary and
4239distracting.
4240@end table
4241
6d2ebf8b 4242@node Frame Info
c906108c
SS
4243@section Information about a frame
4244
4245There are several other commands to print information about the selected
4246stack frame.
4247
4248@table @code
4249@item frame
4250@itemx f
4251When used without any argument, this command does not change which
4252frame is selected, but prints a brief description of the currently
4253selected stack frame. It can be abbreviated @code{f}. With an
4254argument, this command is used to select a stack frame.
4255@xref{Selection, ,Selecting a frame}.
4256
4257@kindex info frame
41afff9a 4258@kindex info f @r{(@code{info frame})}
c906108c
SS
4259@item info frame
4260@itemx info f
4261This command prints a verbose description of the selected stack frame,
4262including:
4263
4264@itemize @bullet
5d161b24
DB
4265@item
4266the address of the frame
c906108c
SS
4267@item
4268the address of the next frame down (called by this frame)
4269@item
4270the address of the next frame up (caller of this frame)
4271@item
4272the language in which the source code corresponding to this frame is written
4273@item
4274the address of the frame's arguments
4275@item
d4f3574e
SS
4276the address of the frame's local variables
4277@item
c906108c
SS
4278the program counter saved in it (the address of execution in the caller frame)
4279@item
4280which registers were saved in the frame
4281@end itemize
4282
4283@noindent The verbose description is useful when
4284something has gone wrong that has made the stack format fail to fit
4285the usual conventions.
4286
4287@item info frame @var{addr}
4288@itemx info f @var{addr}
4289Print a verbose description of the frame at address @var{addr}, without
4290selecting that frame. The selected frame remains unchanged by this
4291command. This requires the same kind of address (more than one for some
4292architectures) that you specify in the @code{frame} command.
4293@xref{Selection, ,Selecting a frame}.
4294
4295@kindex info args
4296@item info args
4297Print the arguments of the selected frame, each on a separate line.
4298
4299@item info locals
4300@kindex info locals
4301Print the local variables of the selected frame, each on a separate
4302line. These are all variables (declared either static or automatic)
4303accessible at the point of execution of the selected frame.
4304
c906108c 4305@kindex info catch
d4f3574e
SS
4306@cindex catch exceptions, list active handlers
4307@cindex exception handlers, how to list
c906108c
SS
4308@item info catch
4309Print a list of all the exception handlers that are active in the
4310current stack frame at the current point of execution. To see other
4311exception handlers, visit the associated frame (using the @code{up},
4312@code{down}, or @code{frame} commands); then type @code{info catch}.
4313@xref{Set Catchpoints, , Setting catchpoints}.
53a5351d 4314
c906108c
SS
4315@end table
4316
c906108c 4317
6d2ebf8b 4318@node Source
c906108c
SS
4319@chapter Examining Source Files
4320
4321@value{GDBN} can print parts of your program's source, since the debugging
4322information recorded in the program tells @value{GDBN} what source files were
4323used to build it. When your program stops, @value{GDBN} spontaneously prints
4324the line where it stopped. Likewise, when you select a stack frame
4325(@pxref{Selection, ,Selecting a frame}), @value{GDBN} prints the line where
4326execution in that frame has stopped. You can print other portions of
4327source files by explicit command.
4328
7a292a7a 4329If you use @value{GDBN} through its @sc{gnu} Emacs interface, you may
d4f3574e 4330prefer to use Emacs facilities to view source; see @ref{Emacs, ,Using
7a292a7a 4331@value{GDBN} under @sc{gnu} Emacs}.
c906108c
SS
4332
4333@menu
4334* List:: Printing source lines
87885426 4335* Edit:: Editing source files
c906108c 4336* Search:: Searching source files
c906108c
SS
4337* Source Path:: Specifying source directories
4338* Machine Code:: Source and machine code
4339@end menu
4340
6d2ebf8b 4341@node List
c906108c
SS
4342@section Printing source lines
4343
4344@kindex list
41afff9a 4345@kindex l @r{(@code{list})}
c906108c 4346To print lines from a source file, use the @code{list} command
5d161b24 4347(abbreviated @code{l}). By default, ten lines are printed.
c906108c
SS
4348There are several ways to specify what part of the file you want to print.
4349
4350Here are the forms of the @code{list} command most commonly used:
4351
4352@table @code
4353@item list @var{linenum}
4354Print lines centered around line number @var{linenum} in the
4355current source file.
4356
4357@item list @var{function}
4358Print lines centered around the beginning of function
4359@var{function}.
4360
4361@item list
4362Print more lines. If the last lines printed were printed with a
4363@code{list} command, this prints lines following the last lines
4364printed; however, if the last line printed was a solitary line printed
4365as part of displaying a stack frame (@pxref{Stack, ,Examining the
4366Stack}), this prints lines centered around that line.
4367
4368@item list -
4369Print lines just before the lines last printed.
4370@end table
4371
4372By default, @value{GDBN} prints ten source lines with any of these forms of
4373the @code{list} command. You can change this using @code{set listsize}:
4374
4375@table @code
4376@kindex set listsize
4377@item set listsize @var{count}
4378Make the @code{list} command display @var{count} source lines (unless
4379the @code{list} argument explicitly specifies some other number).
4380
4381@kindex show listsize
4382@item show listsize
4383Display the number of lines that @code{list} prints.
4384@end table
4385
4386Repeating a @code{list} command with @key{RET} discards the argument,
4387so it is equivalent to typing just @code{list}. This is more useful
4388than listing the same lines again. An exception is made for an
4389argument of @samp{-}; that argument is preserved in repetition so that
4390each repetition moves up in the source file.
4391
4392@cindex linespec
4393In general, the @code{list} command expects you to supply zero, one or two
4394@dfn{linespecs}. Linespecs specify source lines; there are several ways
d4f3574e 4395of writing them, but the effect is always to specify some source line.
c906108c
SS
4396Here is a complete description of the possible arguments for @code{list}:
4397
4398@table @code
4399@item list @var{linespec}
4400Print lines centered around the line specified by @var{linespec}.
4401
4402@item list @var{first},@var{last}
4403Print lines from @var{first} to @var{last}. Both arguments are
4404linespecs.
4405
4406@item list ,@var{last}
4407Print lines ending with @var{last}.
4408
4409@item list @var{first},
4410Print lines starting with @var{first}.
4411
4412@item list +
4413Print lines just after the lines last printed.
4414
4415@item list -
4416Print lines just before the lines last printed.
4417
4418@item list
4419As described in the preceding table.
4420@end table
4421
4422Here are the ways of specifying a single source line---all the
4423kinds of linespec.
4424
4425@table @code
4426@item @var{number}
4427Specifies line @var{number} of the current source file.
4428When a @code{list} command has two linespecs, this refers to
4429the same source file as the first linespec.
4430
4431@item +@var{offset}
4432Specifies the line @var{offset} lines after the last line printed.
4433When used as the second linespec in a @code{list} command that has
4434two, this specifies the line @var{offset} lines down from the
4435first linespec.
4436
4437@item -@var{offset}
4438Specifies the line @var{offset} lines before the last line printed.
4439
4440@item @var{filename}:@var{number}
4441Specifies line @var{number} in the source file @var{filename}.
4442
4443@item @var{function}
4444Specifies the line that begins the body of the function @var{function}.
4445For example: in C, this is the line with the open brace.
4446
4447@item @var{filename}:@var{function}
4448Specifies the line of the open-brace that begins the body of the
4449function @var{function} in the file @var{filename}. You only need the
4450file name with a function name to avoid ambiguity when there are
4451identically named functions in different source files.
4452
4453@item *@var{address}
4454Specifies the line containing the program address @var{address}.
4455@var{address} may be any expression.
4456@end table
4457
87885426
FN
4458@node Edit
4459@section Editing source files
4460@cindex editing source files
4461
4462@kindex edit
4463@kindex e @r{(@code{edit})}
4464To edit the lines in a source file, use the @code{edit} command.
4465The editing program of your choice
4466is invoked with the current line set to
4467the active line in the program.
4468Alternatively, there are several ways to specify what part of the file you
4469want to print if you want to see other parts of the program.
4470
4471Here are the forms of the @code{edit} command most commonly used:
4472
4473@table @code
4474@item edit
4475Edit the current source file at the active line number in the program.
4476
4477@item edit @var{number}
4478Edit the current source file with @var{number} as the active line number.
4479
4480@item edit @var{function}
4481Edit the file containing @var{function} at the beginning of its definition.
4482
4483@item edit @var{filename}:@var{number}
4484Specifies line @var{number} in the source file @var{filename}.
4485
4486@item edit @var{filename}:@var{function}
4487Specifies the line that begins the body of the
4488function @var{function} in the file @var{filename}. You only need the
4489file name with a function name to avoid ambiguity when there are
4490identically named functions in different source files.
4491
4492@item edit *@var{address}
4493Specifies the line containing the program address @var{address}.
4494@var{address} may be any expression.
4495@end table
4496
4497@subsection Choosing your editor
4498You can customize @value{GDBN} to use any editor you want
4499@footnote{
4500The only restriction is that your editor (say @code{ex}), recognizes the
4501following command-line syntax:
10998722 4502@smallexample
87885426 4503ex +@var{number} file
10998722 4504@end smallexample
15387254
EZ
4505The optional numeric value +@var{number} specifies the number of the line in
4506the file where to start editing.}.
4507By default, it is @file{@value{EDITOR}}, but you can change this
10998722
AC
4508by setting the environment variable @code{EDITOR} before using
4509@value{GDBN}. For example, to configure @value{GDBN} to use the
4510@code{vi} editor, you could use these commands with the @code{sh} shell:
4511@smallexample
87885426
FN
4512EDITOR=/usr/bin/vi
4513export EDITOR
15387254 4514gdb @dots{}
10998722 4515@end smallexample
87885426 4516or in the @code{csh} shell,
10998722 4517@smallexample
87885426 4518setenv EDITOR /usr/bin/vi
15387254 4519gdb @dots{}
10998722 4520@end smallexample
87885426 4521
6d2ebf8b 4522@node Search
c906108c 4523@section Searching source files
15387254 4524@cindex searching source files
c906108c
SS
4525@kindex reverse-search
4526
4527There are two commands for searching through the current source file for a
4528regular expression.
4529
4530@table @code
4531@kindex search
4532@kindex forward-search
4533@item forward-search @var{regexp}
4534@itemx search @var{regexp}
4535The command @samp{forward-search @var{regexp}} checks each line,
4536starting with the one following the last line listed, for a match for
5d161b24 4537@var{regexp}. It lists the line that is found. You can use the
c906108c
SS
4538synonym @samp{search @var{regexp}} or abbreviate the command name as
4539@code{fo}.
4540
4541@item reverse-search @var{regexp}
4542The command @samp{reverse-search @var{regexp}} checks each line, starting
4543with the one before the last line listed and going backward, for a match
4544for @var{regexp}. It lists the line that is found. You can abbreviate
4545this command as @code{rev}.
4546@end table
c906108c 4547
6d2ebf8b 4548@node Source Path
c906108c
SS
4549@section Specifying source directories
4550
4551@cindex source path
4552@cindex directories for source files
4553Executable programs sometimes do not record the directories of the source
4554files from which they were compiled, just the names. Even when they do,
4555the directories could be moved between the compilation and your debugging
4556session. @value{GDBN} has a list of directories to search for source files;
4557this is called the @dfn{source path}. Each time @value{GDBN} wants a source file,
4558it tries all the directories in the list, in the order they are present
0b66e38c
EZ
4559in the list, until it finds a file with the desired name.
4560
4561For example, suppose an executable references the file
4562@file{/usr/src/foo-1.0/lib/foo.c}, and our source path is
4563@file{/mnt/cross}. The file is first looked up literally; if this
4564fails, @file{/mnt/cross/usr/src/foo-1.0/lib/foo.c} is tried; if this
4565fails, @file{/mnt/cross/foo.c} is opened; if this fails, an error
4566message is printed. @value{GDBN} does not look up the parts of the
4567source file name, such as @file{/mnt/cross/src/foo-1.0/lib/foo.c}.
4568Likewise, the subdirectories of the source path are not searched: if
4569the source path is @file{/mnt/cross}, and the binary refers to
4570@file{foo.c}, @value{GDBN} would not find it under
4571@file{/mnt/cross/usr/src/foo-1.0/lib}.
4572
4573Plain file names, relative file names with leading directories, file
4574names containing dots, etc.@: are all treated as described above; for
4575instance, if the source path is @file{/mnt/cross}, and the source file
4576is recorded as @file{../lib/foo.c}, @value{GDBN} would first try
4577@file{../lib/foo.c}, then @file{/mnt/cross/../lib/foo.c}, and after
4578that---@file{/mnt/cross/foo.c}.
4579
4580Note that the executable search path is @emph{not} used to locate the
4581source files. Neither is the current working directory, unless it
4582happens to be in the source path.
c906108c
SS
4583
4584Whenever you reset or rearrange the source path, @value{GDBN} clears out
4585any information it has cached about where source files are found and where
4586each line is in the file.
4587
4588@kindex directory
4589@kindex dir
d4f3574e
SS
4590When you start @value{GDBN}, its source path includes only @samp{cdir}
4591and @samp{cwd}, in that order.
c906108c
SS
4592To add other directories, use the @code{directory} command.
4593
4594@table @code
4595@item directory @var{dirname} @dots{}
4596@item dir @var{dirname} @dots{}
4597Add directory @var{dirname} to the front of the source path. Several
d4f3574e
SS
4598directory names may be given to this command, separated by @samp{:}
4599(@samp{;} on MS-DOS and MS-Windows, where @samp{:} usually appears as
4600part of absolute file names) or
c906108c
SS
4601whitespace. You may specify a directory that is already in the source
4602path; this moves it forward, so @value{GDBN} searches it sooner.
4603
4604@kindex cdir
4605@kindex cwd
41afff9a
EZ
4606@vindex $cdir@r{, convenience variable}
4607@vindex $cwdr@r{, convenience variable}
c906108c
SS
4608@cindex compilation directory
4609@cindex current directory
4610@cindex working directory
4611@cindex directory, current
4612@cindex directory, compilation
4613You can use the string @samp{$cdir} to refer to the compilation
4614directory (if one is recorded), and @samp{$cwd} to refer to the current
4615working directory. @samp{$cwd} is not the same as @samp{.}---the former
4616tracks the current working directory as it changes during your @value{GDBN}
4617session, while the latter is immediately expanded to the current
4618directory at the time you add an entry to the source path.
4619
4620@item directory
4621Reset the source path to empty again. This requires confirmation.
4622
4623@c RET-repeat for @code{directory} is explicitly disabled, but since
4624@c repeating it would be a no-op we do not say that. (thanks to RMS)
4625
4626@item show directories
4627@kindex show directories
4628Print the source path: show which directories it contains.
4629@end table
4630
4631If your source path is cluttered with directories that are no longer of
4632interest, @value{GDBN} may sometimes cause confusion by finding the wrong
4633versions of source. You can correct the situation as follows:
4634
4635@enumerate
4636@item
4637Use @code{directory} with no argument to reset the source path to empty.
4638
4639@item
4640Use @code{directory} with suitable arguments to reinstall the
4641directories you want in the source path. You can add all the
4642directories in one command.
4643@end enumerate
4644
6d2ebf8b 4645@node Machine Code
c906108c 4646@section Source and machine code
15387254 4647@cindex source line and its code address
c906108c
SS
4648
4649You can use the command @code{info line} to map source lines to program
4650addresses (and vice versa), and the command @code{disassemble} to display
4651a range of addresses as machine instructions. When run under @sc{gnu} Emacs
d4f3574e 4652mode, the @code{info line} command causes the arrow to point to the
5d161b24 4653line specified. Also, @code{info line} prints addresses in symbolic form as
c906108c
SS
4654well as hex.
4655
4656@table @code
4657@kindex info line
4658@item info line @var{linespec}
4659Print the starting and ending addresses of the compiled code for
4660source line @var{linespec}. You can specify source lines in any of
4661the ways understood by the @code{list} command (@pxref{List, ,Printing
4662source lines}).
4663@end table
4664
4665For example, we can use @code{info line} to discover the location of
4666the object code for the first line of function
4667@code{m4_changequote}:
4668
d4f3574e
SS
4669@c FIXME: I think this example should also show the addresses in
4670@c symbolic form, as they usually would be displayed.
c906108c 4671@smallexample
96a2c332 4672(@value{GDBP}) info line m4_changequote
c906108c
SS
4673Line 895 of "builtin.c" starts at pc 0x634c and ends at 0x6350.
4674@end smallexample
4675
4676@noindent
15387254 4677@cindex code address and its source line
c906108c
SS
4678We can also inquire (using @code{*@var{addr}} as the form for
4679@var{linespec}) what source line covers a particular address:
4680@smallexample
4681(@value{GDBP}) info line *0x63ff
4682Line 926 of "builtin.c" starts at pc 0x63e4 and ends at 0x6404.
4683@end smallexample
4684
4685@cindex @code{$_} and @code{info line}
15387254 4686@cindex @code{x} command, default address
41afff9a 4687@kindex x@r{(examine), and} info line
c906108c
SS
4688After @code{info line}, the default address for the @code{x} command
4689is changed to the starting address of the line, so that @samp{x/i} is
4690sufficient to begin examining the machine code (@pxref{Memory,
4691,Examining memory}). Also, this address is saved as the value of the
4692convenience variable @code{$_} (@pxref{Convenience Vars, ,Convenience
4693variables}).
4694
4695@table @code
4696@kindex disassemble
4697@cindex assembly instructions
4698@cindex instructions, assembly
4699@cindex machine instructions
4700@cindex listing machine instructions
4701@item disassemble
4702This specialized command dumps a range of memory as machine
4703instructions. The default memory range is the function surrounding the
4704program counter of the selected frame. A single argument to this
4705command is a program counter value; @value{GDBN} dumps the function
4706surrounding this value. Two arguments specify a range of addresses
4707(first inclusive, second exclusive) to dump.
4708@end table
4709
c906108c
SS
4710The following example shows the disassembly of a range of addresses of
4711HP PA-RISC 2.0 code:
4712
4713@smallexample
4714(@value{GDBP}) disas 0x32c4 0x32e4
4715Dump of assembler code from 0x32c4 to 0x32e4:
47160x32c4 <main+204>: addil 0,dp
47170x32c8 <main+208>: ldw 0x22c(sr0,r1),r26
47180x32cc <main+212>: ldil 0x3000,r31
47190x32d0 <main+216>: ble 0x3f8(sr4,r31)
47200x32d4 <main+220>: ldo 0(r31),rp
47210x32d8 <main+224>: addil -0x800,dp
47220x32dc <main+228>: ldo 0x588(r1),r26
47230x32e0 <main+232>: ldil 0x3000,r31
4724End of assembler dump.
4725@end smallexample
c906108c
SS
4726
4727Some architectures have more than one commonly-used set of instruction
4728mnemonics or other syntax.
4729
4730@table @code
d4f3574e 4731@kindex set disassembly-flavor
d4f3574e
SS
4732@cindex Intel disassembly flavor
4733@cindex AT&T disassembly flavor
4734@item set disassembly-flavor @var{instruction-set}
c906108c
SS
4735Select the instruction set to use when disassembling the
4736program via the @code{disassemble} or @code{x/i} commands.
4737
4738Currently this command is only defined for the Intel x86 family. You
d4f3574e
SS
4739can set @var{instruction-set} to either @code{intel} or @code{att}.
4740The default is @code{att}, the AT&T flavor used by default by Unix
4741assemblers for x86-based targets.
c906108c
SS
4742@end table
4743
4744
6d2ebf8b 4745@node Data
c906108c
SS
4746@chapter Examining Data
4747
4748@cindex printing data
4749@cindex examining data
4750@kindex print
4751@kindex inspect
4752@c "inspect" is not quite a synonym if you are using Epoch, which we do not
4753@c document because it is nonstandard... Under Epoch it displays in a
4754@c different window or something like that.
4755The usual way to examine data in your program is with the @code{print}
7a292a7a
SS
4756command (abbreviated @code{p}), or its synonym @code{inspect}. It
4757evaluates and prints the value of an expression of the language your
4758program is written in (@pxref{Languages, ,Using @value{GDBN} with
4759Different Languages}).
c906108c
SS
4760
4761@table @code
d4f3574e
SS
4762@item print @var{expr}
4763@itemx print /@var{f} @var{expr}
4764@var{expr} is an expression (in the source language). By default the
4765value of @var{expr} is printed in a format appropriate to its data type;
c906108c 4766you can choose a different format by specifying @samp{/@var{f}}, where
d4f3574e 4767@var{f} is a letter specifying the format; see @ref{Output Formats,,Output
c906108c
SS
4768formats}.
4769
4770@item print
4771@itemx print /@var{f}
15387254 4772@cindex reprint the last value
d4f3574e 4773If you omit @var{expr}, @value{GDBN} displays the last value again (from the
c906108c
SS
4774@dfn{value history}; @pxref{Value History, ,Value history}). This allows you to
4775conveniently inspect the same value in an alternative format.
4776@end table
4777
4778A more low-level way of examining data is with the @code{x} command.
4779It examines data in memory at a specified address and prints it in a
4780specified format. @xref{Memory, ,Examining memory}.
4781
7a292a7a 4782If you are interested in information about types, or about how the
d4f3574e
SS
4783fields of a struct or a class are declared, use the @code{ptype @var{exp}}
4784command rather than @code{print}. @xref{Symbols, ,Examining the Symbol
7a292a7a 4785Table}.
c906108c
SS
4786
4787@menu
4788* Expressions:: Expressions
4789* Variables:: Program variables
4790* Arrays:: Artificial arrays
4791* Output Formats:: Output formats
4792* Memory:: Examining memory
4793* Auto Display:: Automatic display
4794* Print Settings:: Print settings
4795* Value History:: Value history
4796* Convenience Vars:: Convenience variables
4797* Registers:: Registers
c906108c 4798* Floating Point Hardware:: Floating point hardware
53c69bd7 4799* Vector Unit:: Vector Unit
b383017d 4800* Auxiliary Vector:: Auxiliary data provided by operating system
29e57380 4801* Memory Region Attributes:: Memory region attributes
16d9dec6 4802* Dump/Restore Files:: Copy between memory and a file
384ee23f 4803* Core File Generation:: Cause a program dump its core
a0eb71c5
KB
4804* Character Sets:: Debugging programs that use a different
4805 character set than GDB does
c906108c
SS
4806@end menu
4807
6d2ebf8b 4808@node Expressions
c906108c
SS
4809@section Expressions
4810
4811@cindex expressions
4812@code{print} and many other @value{GDBN} commands accept an expression and
4813compute its value. Any kind of constant, variable or operator defined
4814by the programming language you are using is valid in an expression in
e2e0bcd1
JB
4815@value{GDBN}. This includes conditional expressions, function calls,
4816casts, and string constants. It also includes preprocessor macros, if
4817you compiled your program to include this information; see
4818@ref{Compilation}.
c906108c 4819
15387254 4820@cindex arrays in expressions
d4f3574e
SS
4821@value{GDBN} supports array constants in expressions input by
4822the user. The syntax is @{@var{element}, @var{element}@dots{}@}. For example,
5d161b24 4823you can use the command @code{print @{1, 2, 3@}} to build up an array in
d4f3574e 4824memory that is @code{malloc}ed in the target program.
c906108c 4825
c906108c
SS
4826Because C is so widespread, most of the expressions shown in examples in
4827this manual are in C. @xref{Languages, , Using @value{GDBN} with Different
4828Languages}, for information on how to use expressions in other
4829languages.
4830
4831In this section, we discuss operators that you can use in @value{GDBN}
4832expressions regardless of your programming language.
4833
15387254 4834@cindex casts, in expressions
c906108c
SS
4835Casts are supported in all languages, not just in C, because it is so
4836useful to cast a number into a pointer in order to examine a structure
4837at that address in memory.
4838@c FIXME: casts supported---Mod2 true?
c906108c
SS
4839
4840@value{GDBN} supports these operators, in addition to those common
4841to programming languages:
4842
4843@table @code
4844@item @@
4845@samp{@@} is a binary operator for treating parts of memory as arrays.
4846@xref{Arrays, ,Artificial arrays}, for more information.
4847
4848@item ::
4849@samp{::} allows you to specify a variable in terms of the file or
4850function where it is defined. @xref{Variables, ,Program variables}.
4851
4852@cindex @{@var{type}@}
4853@cindex type casting memory
4854@cindex memory, viewing as typed object
4855@cindex casts, to view memory
4856@item @{@var{type}@} @var{addr}
4857Refers to an object of type @var{type} stored at address @var{addr} in
4858memory. @var{addr} may be any expression whose value is an integer or
4859pointer (but parentheses are required around binary operators, just as in
4860a cast). This construct is allowed regardless of what kind of data is
4861normally supposed to reside at @var{addr}.
4862@end table
4863
6d2ebf8b 4864@node Variables
c906108c
SS
4865@section Program variables
4866
4867The most common kind of expression to use is the name of a variable
4868in your program.
4869
4870Variables in expressions are understood in the selected stack frame
4871(@pxref{Selection, ,Selecting a frame}); they must be either:
4872
4873@itemize @bullet
4874@item
4875global (or file-static)
4876@end itemize
4877
5d161b24 4878@noindent or
c906108c
SS
4879
4880@itemize @bullet
4881@item
4882visible according to the scope rules of the
4883programming language from the point of execution in that frame
5d161b24 4884@end itemize
c906108c
SS
4885
4886@noindent This means that in the function
4887
474c8240 4888@smallexample
c906108c
SS
4889foo (a)
4890 int a;
4891@{
4892 bar (a);
4893 @{
4894 int b = test ();
4895 bar (b);
4896 @}
4897@}
474c8240 4898@end smallexample
c906108c
SS
4899
4900@noindent
4901you can examine and use the variable @code{a} whenever your program is
4902executing within the function @code{foo}, but you can only use or
4903examine the variable @code{b} while your program is executing inside
4904the block where @code{b} is declared.
4905
4906@cindex variable name conflict
4907There is an exception: you can refer to a variable or function whose
4908scope is a single source file even if the current execution point is not
4909in this file. But it is possible to have more than one such variable or
4910function with the same name (in different source files). If that
4911happens, referring to that name has unpredictable effects. If you wish,
4912you can specify a static variable in a particular function or file,
15387254 4913using the colon-colon (@code{::}) notation:
c906108c 4914
d4f3574e 4915@cindex colon-colon, context for variables/functions
c906108c
SS
4916@iftex
4917@c info cannot cope with a :: index entry, but why deprive hard copy readers?
41afff9a 4918@cindex @code{::}, context for variables/functions
c906108c 4919@end iftex
474c8240 4920@smallexample
c906108c
SS
4921@var{file}::@var{variable}
4922@var{function}::@var{variable}
474c8240 4923@end smallexample
c906108c
SS
4924
4925@noindent
4926Here @var{file} or @var{function} is the name of the context for the
4927static @var{variable}. In the case of file names, you can use quotes to
4928make sure @value{GDBN} parses the file name as a single word---for example,
4929to print a global value of @code{x} defined in @file{f2.c}:
4930
474c8240 4931@smallexample
c906108c 4932(@value{GDBP}) p 'f2.c'::x
474c8240 4933@end smallexample
c906108c 4934
b37052ae 4935@cindex C@t{++} scope resolution
c906108c 4936This use of @samp{::} is very rarely in conflict with the very similar
b37052ae 4937use of the same notation in C@t{++}. @value{GDBN} also supports use of the C@t{++}
c906108c
SS
4938scope resolution operator in @value{GDBN} expressions.
4939@c FIXME: Um, so what happens in one of those rare cases where it's in
4940@c conflict?? --mew
c906108c
SS
4941
4942@cindex wrong values
4943@cindex variable values, wrong
15387254
EZ
4944@cindex function entry/exit, wrong values of variables
4945@cindex optimized code, wrong values of variables
c906108c
SS
4946@quotation
4947@emph{Warning:} Occasionally, a local variable may appear to have the
4948wrong value at certain points in a function---just after entry to a new
4949scope, and just before exit.
4950@end quotation
4951You may see this problem when you are stepping by machine instructions.
4952This is because, on most machines, it takes more than one instruction to
4953set up a stack frame (including local variable definitions); if you are
4954stepping by machine instructions, variables may appear to have the wrong
4955values until the stack frame is completely built. On exit, it usually
4956also takes more than one machine instruction to destroy a stack frame;
4957after you begin stepping through that group of instructions, local
4958variable definitions may be gone.
4959
4960This may also happen when the compiler does significant optimizations.
4961To be sure of always seeing accurate values, turn off all optimization
4962when compiling.
4963
d4f3574e
SS
4964@cindex ``No symbol "foo" in current context''
4965Another possible effect of compiler optimizations is to optimize
4966unused variables out of existence, or assign variables to registers (as
4967opposed to memory addresses). Depending on the support for such cases
4968offered by the debug info format used by the compiler, @value{GDBN}
4969might not be able to display values for such local variables. If that
4970happens, @value{GDBN} will print a message like this:
4971
474c8240 4972@smallexample
d4f3574e 4973No symbol "foo" in current context.
474c8240 4974@end smallexample
d4f3574e
SS
4975
4976To solve such problems, either recompile without optimizations, or use a
4977different debug info format, if the compiler supports several such
15387254 4978formats. For example, @value{NGCC}, the @sc{gnu} C/C@t{++} compiler,
0179ffac
DC
4979usually supports the @option{-gstabs+} option. @option{-gstabs+}
4980produces debug info in a format that is superior to formats such as
4981COFF. You may be able to use DWARF 2 (@option{-gdwarf-2}), which is also
4982an effective form for debug info. @xref{Debugging Options,,Options
4983for Debugging Your Program or @sc{gnu} CC, gcc.info, Using @sc{gnu} CC}.
15387254
EZ
4984@xref{C, , Debugging C++}, for more info about debug info formats
4985that are best suited to C@t{++} programs.
d4f3574e 4986
6d2ebf8b 4987@node Arrays
c906108c
SS
4988@section Artificial arrays
4989
4990@cindex artificial array
15387254 4991@cindex arrays
41afff9a 4992@kindex @@@r{, referencing memory as an array}
c906108c
SS
4993It is often useful to print out several successive objects of the
4994same type in memory; a section of an array, or an array of
4995dynamically determined size for which only a pointer exists in the
4996program.
4997
4998You can do this by referring to a contiguous span of memory as an
4999@dfn{artificial array}, using the binary operator @samp{@@}. The left
5000operand of @samp{@@} should be the first element of the desired array
5001and be an individual object. The right operand should be the desired length
5002of the array. The result is an array value whose elements are all of
5003the type of the left argument. The first element is actually the left
5004argument; the second element comes from bytes of memory immediately
5005following those that hold the first element, and so on. Here is an
5006example. If a program says
5007
474c8240 5008@smallexample
c906108c 5009int *array = (int *) malloc (len * sizeof (int));
474c8240 5010@end smallexample
c906108c
SS
5011
5012@noindent
5013you can print the contents of @code{array} with
5014
474c8240 5015@smallexample
c906108c 5016p *array@@len
474c8240 5017@end smallexample
c906108c
SS
5018
5019The left operand of @samp{@@} must reside in memory. Array values made
5020with @samp{@@} in this way behave just like other arrays in terms of
5021subscripting, and are coerced to pointers when used in expressions.
5022Artificial arrays most often appear in expressions via the value history
5023(@pxref{Value History, ,Value history}), after printing one out.
5024
5025Another way to create an artificial array is to use a cast.
5026This re-interprets a value as if it were an array.
5027The value need not be in memory:
474c8240 5028@smallexample
c906108c
SS
5029(@value{GDBP}) p/x (short[2])0x12345678
5030$1 = @{0x1234, 0x5678@}
474c8240 5031@end smallexample
c906108c
SS
5032
5033As a convenience, if you leave the array length out (as in
c3f6f71d 5034@samp{(@var{type}[])@var{value}}) @value{GDBN} calculates the size to fill
c906108c 5035the value (as @samp{sizeof(@var{value})/sizeof(@var{type})}:
474c8240 5036@smallexample
c906108c
SS
5037(@value{GDBP}) p/x (short[])0x12345678
5038$2 = @{0x1234, 0x5678@}
474c8240 5039@end smallexample
c906108c
SS
5040
5041Sometimes the artificial array mechanism is not quite enough; in
5042moderately complex data structures, the elements of interest may not
5043actually be adjacent---for example, if you are interested in the values
5044of pointers in an array. One useful work-around in this situation is
5045to use a convenience variable (@pxref{Convenience Vars, ,Convenience
5046variables}) as a counter in an expression that prints the first
5047interesting value, and then repeat that expression via @key{RET}. For
5048instance, suppose you have an array @code{dtab} of pointers to
5049structures, and you are interested in the values of a field @code{fv}
5050in each structure. Here is an example of what you might type:
5051
474c8240 5052@smallexample
c906108c
SS
5053set $i = 0
5054p dtab[$i++]->fv
5055@key{RET}
5056@key{RET}
5057@dots{}
474c8240 5058@end smallexample
c906108c 5059
6d2ebf8b 5060@node Output Formats
c906108c
SS
5061@section Output formats
5062
5063@cindex formatted output
5064@cindex output formats
5065By default, @value{GDBN} prints a value according to its data type. Sometimes
5066this is not what you want. For example, you might want to print a number
5067in hex, or a pointer in decimal. Or you might want to view data in memory
5068at a certain address as a character string or as an instruction. To do
5069these things, specify an @dfn{output format} when you print a value.
5070
5071The simplest use of output formats is to say how to print a value
5072already computed. This is done by starting the arguments of the
5073@code{print} command with a slash and a format letter. The format
5074letters supported are:
5075
5076@table @code
5077@item x
5078Regard the bits of the value as an integer, and print the integer in
5079hexadecimal.
5080
5081@item d
5082Print as integer in signed decimal.
5083
5084@item u
5085Print as integer in unsigned decimal.
5086
5087@item o
5088Print as integer in octal.
5089
5090@item t
5091Print as integer in binary. The letter @samp{t} stands for ``two''.
5092@footnote{@samp{b} cannot be used because these format letters are also
5093used with the @code{x} command, where @samp{b} stands for ``byte'';
d4f3574e 5094see @ref{Memory,,Examining memory}.}
c906108c
SS
5095
5096@item a
5097@cindex unknown address, locating
3d67e040 5098@cindex locate address
c906108c
SS
5099Print as an address, both absolute in hexadecimal and as an offset from
5100the nearest preceding symbol. You can use this format used to discover
5101where (in what function) an unknown address is located:
5102
474c8240 5103@smallexample
c906108c
SS
5104(@value{GDBP}) p/a 0x54320
5105$3 = 0x54320 <_initialize_vx+396>
474c8240 5106@end smallexample
c906108c 5107
3d67e040
EZ
5108@noindent
5109The command @code{info symbol 0x54320} yields similar results.
5110@xref{Symbols, info symbol}.
5111
c906108c
SS
5112@item c
5113Regard as an integer and print it as a character constant.
5114
5115@item f
5116Regard the bits of the value as a floating point number and print
5117using typical floating point syntax.
5118@end table
5119
5120For example, to print the program counter in hex (@pxref{Registers}), type
5121
474c8240 5122@smallexample
c906108c 5123p/x $pc
474c8240 5124@end smallexample
c906108c
SS
5125
5126@noindent
5127Note that no space is required before the slash; this is because command
5128names in @value{GDBN} cannot contain a slash.
5129
5130To reprint the last value in the value history with a different format,
5131you can use the @code{print} command with just a format and no
5132expression. For example, @samp{p/x} reprints the last value in hex.
5133
6d2ebf8b 5134@node Memory
c906108c
SS
5135@section Examining memory
5136
5137You can use the command @code{x} (for ``examine'') to examine memory in
5138any of several formats, independently of your program's data types.
5139
5140@cindex examining memory
5141@table @code
41afff9a 5142@kindex x @r{(examine memory)}
c906108c
SS
5143@item x/@var{nfu} @var{addr}
5144@itemx x @var{addr}
5145@itemx x
5146Use the @code{x} command to examine memory.
5147@end table
5148
5149@var{n}, @var{f}, and @var{u} are all optional parameters that specify how
5150much memory to display and how to format it; @var{addr} is an
5151expression giving the address where you want to start displaying memory.
5152If you use defaults for @var{nfu}, you need not type the slash @samp{/}.
5153Several commands set convenient defaults for @var{addr}.
5154
5155@table @r
5156@item @var{n}, the repeat count
5157The repeat count is a decimal integer; the default is 1. It specifies
5158how much memory (counting by units @var{u}) to display.
5159@c This really is **decimal**; unaffected by 'set radix' as of GDB
5160@c 4.1.2.
5161
5162@item @var{f}, the display format
5163The display format is one of the formats used by @code{print},
5164@samp{s} (null-terminated string), or @samp{i} (machine instruction).
5165The default is @samp{x} (hexadecimal) initially.
5166The default changes each time you use either @code{x} or @code{print}.
5167
5168@item @var{u}, the unit size
5169The unit size is any of
5170
5171@table @code
5172@item b
5173Bytes.
5174@item h
5175Halfwords (two bytes).
5176@item w
5177Words (four bytes). This is the initial default.
5178@item g
5179Giant words (eight bytes).
5180@end table
5181
5182Each time you specify a unit size with @code{x}, that size becomes the
5183default unit the next time you use @code{x}. (For the @samp{s} and
5184@samp{i} formats, the unit size is ignored and is normally not written.)
5185
5186@item @var{addr}, starting display address
5187@var{addr} is the address where you want @value{GDBN} to begin displaying
5188memory. The expression need not have a pointer value (though it may);
5189it is always interpreted as an integer address of a byte of memory.
5190@xref{Expressions, ,Expressions}, for more information on expressions. The default for
5191@var{addr} is usually just after the last address examined---but several
5192other commands also set the default address: @code{info breakpoints} (to
5193the address of the last breakpoint listed), @code{info line} (to the
5194starting address of a line), and @code{print} (if you use it to display
5195a value from memory).
5196@end table
5197
5198For example, @samp{x/3uh 0x54320} is a request to display three halfwords
5199(@code{h}) of memory, formatted as unsigned decimal integers (@samp{u}),
5200starting at address @code{0x54320}. @samp{x/4xw $sp} prints the four
5201words (@samp{w}) of memory above the stack pointer (here, @samp{$sp};
d4f3574e 5202@pxref{Registers, ,Registers}) in hexadecimal (@samp{x}).
c906108c
SS
5203
5204Since the letters indicating unit sizes are all distinct from the
5205letters specifying output formats, you do not have to remember whether
5206unit size or format comes first; either order works. The output
5207specifications @samp{4xw} and @samp{4wx} mean exactly the same thing.
5208(However, the count @var{n} must come first; @samp{wx4} does not work.)
5209
5210Even though the unit size @var{u} is ignored for the formats @samp{s}
5211and @samp{i}, you might still want to use a count @var{n}; for example,
5212@samp{3i} specifies that you want to see three machine instructions,
5213including any operands. The command @code{disassemble} gives an
d4f3574e 5214alternative way of inspecting machine instructions; see @ref{Machine
c906108c
SS
5215Code,,Source and machine code}.
5216
5217All the defaults for the arguments to @code{x} are designed to make it
5218easy to continue scanning memory with minimal specifications each time
5219you use @code{x}. For example, after you have inspected three machine
5220instructions with @samp{x/3i @var{addr}}, you can inspect the next seven
5221with just @samp{x/7}. If you use @key{RET} to repeat the @code{x} command,
5222the repeat count @var{n} is used again; the other arguments default as
5223for successive uses of @code{x}.
5224
5225@cindex @code{$_}, @code{$__}, and value history
5226The addresses and contents printed by the @code{x} command are not saved
5227in the value history because there is often too much of them and they
5228would get in the way. Instead, @value{GDBN} makes these values available for
5229subsequent use in expressions as values of the convenience variables
5230@code{$_} and @code{$__}. After an @code{x} command, the last address
5231examined is available for use in expressions in the convenience variable
5232@code{$_}. The contents of that address, as examined, are available in
5233the convenience variable @code{$__}.
5234
5235If the @code{x} command has a repeat count, the address and contents saved
5236are from the last memory unit printed; this is not the same as the last
5237address printed if several units were printed on the last line of output.
5238
6d2ebf8b 5239@node Auto Display
c906108c
SS
5240@section Automatic display
5241@cindex automatic display
5242@cindex display of expressions
5243
5244If you find that you want to print the value of an expression frequently
5245(to see how it changes), you might want to add it to the @dfn{automatic
5246display list} so that @value{GDBN} prints its value each time your program stops.
5247Each expression added to the list is given a number to identify it;
5248to remove an expression from the list, you specify that number.
5249The automatic display looks like this:
5250
474c8240 5251@smallexample
c906108c
SS
52522: foo = 38
52533: bar[5] = (struct hack *) 0x3804
474c8240 5254@end smallexample
c906108c
SS
5255
5256@noindent
5257This display shows item numbers, expressions and their current values. As with
5258displays you request manually using @code{x} or @code{print}, you can
5259specify the output format you prefer; in fact, @code{display} decides
5260whether to use @code{print} or @code{x} depending on how elaborate your
5261format specification is---it uses @code{x} if you specify a unit size,
5262or one of the two formats (@samp{i} and @samp{s}) that are only
5263supported by @code{x}; otherwise it uses @code{print}.
5264
5265@table @code
5266@kindex display
d4f3574e
SS
5267@item display @var{expr}
5268Add the expression @var{expr} to the list of expressions to display
c906108c
SS
5269each time your program stops. @xref{Expressions, ,Expressions}.
5270
5271@code{display} does not repeat if you press @key{RET} again after using it.
5272
d4f3574e 5273@item display/@var{fmt} @var{expr}
c906108c 5274For @var{fmt} specifying only a display format and not a size or
d4f3574e 5275count, add the expression @var{expr} to the auto-display list but
c906108c
SS
5276arrange to display it each time in the specified format @var{fmt}.
5277@xref{Output Formats,,Output formats}.
5278
5279@item display/@var{fmt} @var{addr}
5280For @var{fmt} @samp{i} or @samp{s}, or including a unit-size or a
5281number of units, add the expression @var{addr} as a memory address to
5282be examined each time your program stops. Examining means in effect
5283doing @samp{x/@var{fmt} @var{addr}}. @xref{Memory, ,Examining memory}.
5284@end table
5285
5286For example, @samp{display/i $pc} can be helpful, to see the machine
5287instruction about to be executed each time execution stops (@samp{$pc}
d4f3574e 5288is a common name for the program counter; @pxref{Registers, ,Registers}).
c906108c
SS
5289
5290@table @code
5291@kindex delete display
5292@kindex undisplay
5293@item undisplay @var{dnums}@dots{}
5294@itemx delete display @var{dnums}@dots{}
5295Remove item numbers @var{dnums} from the list of expressions to display.
5296
5297@code{undisplay} does not repeat if you press @key{RET} after using it.
5298(Otherwise you would just get the error @samp{No display number @dots{}}.)
5299
5300@kindex disable display
5301@item disable display @var{dnums}@dots{}
5302Disable the display of item numbers @var{dnums}. A disabled display
5303item is not printed automatically, but is not forgotten. It may be
5304enabled again later.
5305
5306@kindex enable display
5307@item enable display @var{dnums}@dots{}
5308Enable display of item numbers @var{dnums}. It becomes effective once
5309again in auto display of its expression, until you specify otherwise.
5310
5311@item display
5312Display the current values of the expressions on the list, just as is
5313done when your program stops.
5314
5315@kindex info display
5316@item info display
5317Print the list of expressions previously set up to display
5318automatically, each one with its item number, but without showing the
5319values. This includes disabled expressions, which are marked as such.
5320It also includes expressions which would not be displayed right now
5321because they refer to automatic variables not currently available.
5322@end table
5323
15387254 5324@cindex display disabled out of scope
c906108c
SS
5325If a display expression refers to local variables, then it does not make
5326sense outside the lexical context for which it was set up. Such an
5327expression is disabled when execution enters a context where one of its
5328variables is not defined. For example, if you give the command
5329@code{display last_char} while inside a function with an argument
5330@code{last_char}, @value{GDBN} displays this argument while your program
5331continues to stop inside that function. When it stops elsewhere---where
5332there is no variable @code{last_char}---the display is disabled
5333automatically. The next time your program stops where @code{last_char}
5334is meaningful, you can enable the display expression once again.
5335
6d2ebf8b 5336@node Print Settings
c906108c
SS
5337@section Print settings
5338
5339@cindex format options
5340@cindex print settings
5341@value{GDBN} provides the following ways to control how arrays, structures,
5342and symbols are printed.
5343
5344@noindent
5345These settings are useful for debugging programs in any language:
5346
5347@table @code
4644b6e3 5348@kindex set print
c906108c
SS
5349@item set print address
5350@itemx set print address on
4644b6e3 5351@cindex print/don't print memory addresses
c906108c
SS
5352@value{GDBN} prints memory addresses showing the location of stack
5353traces, structure values, pointer values, breakpoints, and so forth,
5354even when it also displays the contents of those addresses. The default
5355is @code{on}. For example, this is what a stack frame display looks like with
5356@code{set print address on}:
5357
5358@smallexample
5359@group
5360(@value{GDBP}) f
5361#0 set_quotes (lq=0x34c78 "<<", rq=0x34c88 ">>")
5362 at input.c:530
5363530 if (lquote != def_lquote)
5364@end group
5365@end smallexample
5366
5367@item set print address off
5368Do not print addresses when displaying their contents. For example,
5369this is the same stack frame displayed with @code{set print address off}:
5370
5371@smallexample
5372@group
5373(@value{GDBP}) set print addr off
5374(@value{GDBP}) f
5375#0 set_quotes (lq="<<", rq=">>") at input.c:530
5376530 if (lquote != def_lquote)
5377@end group
5378@end smallexample
5379
5380You can use @samp{set print address off} to eliminate all machine
5381dependent displays from the @value{GDBN} interface. For example, with
5382@code{print address off}, you should get the same text for backtraces on
5383all machines---whether or not they involve pointer arguments.
5384
4644b6e3 5385@kindex show print
c906108c
SS
5386@item show print address
5387Show whether or not addresses are to be printed.
5388@end table
5389
5390When @value{GDBN} prints a symbolic address, it normally prints the
5391closest earlier symbol plus an offset. If that symbol does not uniquely
5392identify the address (for example, it is a name whose scope is a single
5393source file), you may need to clarify. One way to do this is with
5394@code{info line}, for example @samp{info line *0x4537}. Alternately,
5395you can set @value{GDBN} to print the source file and line number when
5396it prints a symbolic address:
5397
5398@table @code
c906108c 5399@item set print symbol-filename on
4644b6e3 5400@cindex closest symbol and offset for an address
c906108c
SS
5401Tell @value{GDBN} to print the source file name and line number of a
5402symbol in the symbolic form of an address.
5403
5404@item set print symbol-filename off
5405Do not print source file name and line number of a symbol. This is the
5406default.
5407
c906108c
SS
5408@item show print symbol-filename
5409Show whether or not @value{GDBN} will print the source file name and
5410line number of a symbol in the symbolic form of an address.
5411@end table
5412
5413Another situation where it is helpful to show symbol filenames and line
5414numbers is when disassembling code; @value{GDBN} shows you the line
5415number and source file that corresponds to each instruction.
5416
5417Also, you may wish to see the symbolic form only if the address being
5418printed is reasonably close to the closest earlier symbol:
5419
5420@table @code
c906108c 5421@item set print max-symbolic-offset @var{max-offset}
4644b6e3 5422@cindex maximum value for offset of closest symbol
c906108c
SS
5423Tell @value{GDBN} to only display the symbolic form of an address if the
5424offset between the closest earlier symbol and the address is less than
5d161b24 5425@var{max-offset}. The default is 0, which tells @value{GDBN}
c906108c
SS
5426to always print the symbolic form of an address if any symbol precedes it.
5427
c906108c
SS
5428@item show print max-symbolic-offset
5429Ask how large the maximum offset is that @value{GDBN} prints in a
5430symbolic address.
5431@end table
5432
5433@cindex wild pointer, interpreting
5434@cindex pointer, finding referent
5435If you have a pointer and you are not sure where it points, try
5436@samp{set print symbol-filename on}. Then you can determine the name
5437and source file location of the variable where it points, using
5438@samp{p/a @var{pointer}}. This interprets the address in symbolic form.
5439For example, here @value{GDBN} shows that a variable @code{ptt} points
5440at another variable @code{t}, defined in @file{hi2.c}:
5441
474c8240 5442@smallexample
c906108c
SS
5443(@value{GDBP}) set print symbol-filename on
5444(@value{GDBP}) p/a ptt
5445$4 = 0xe008 <t in hi2.c>
474c8240 5446@end smallexample
c906108c
SS
5447
5448@quotation
5449@emph{Warning:} For pointers that point to a local variable, @samp{p/a}
5450does not show the symbol name and filename of the referent, even with
5451the appropriate @code{set print} options turned on.
5452@end quotation
5453
5454Other settings control how different kinds of objects are printed:
5455
5456@table @code
c906108c
SS
5457@item set print array
5458@itemx set print array on
4644b6e3 5459@cindex pretty print arrays
c906108c
SS
5460Pretty print arrays. This format is more convenient to read,
5461but uses more space. The default is off.
5462
5463@item set print array off
5464Return to compressed format for arrays.
5465
c906108c
SS
5466@item show print array
5467Show whether compressed or pretty format is selected for displaying
5468arrays.
5469
c906108c 5470@item set print elements @var{number-of-elements}
4644b6e3 5471@cindex number of array elements to print
c906108c
SS
5472Set a limit on how many elements of an array @value{GDBN} will print.
5473If @value{GDBN} is printing a large array, it stops printing after it has
5474printed the number of elements set by the @code{set print elements} command.
5475This limit also applies to the display of strings.
d4f3574e 5476When @value{GDBN} starts, this limit is set to 200.
c906108c
SS
5477Setting @var{number-of-elements} to zero means that the printing is unlimited.
5478
c906108c
SS
5479@item show print elements
5480Display the number of elements of a large array that @value{GDBN} will print.
5481If the number is 0, then the printing is unlimited.
5482
c906108c 5483@item set print null-stop
4644b6e3 5484@cindex @sc{null} elements in arrays
c906108c 5485Cause @value{GDBN} to stop printing the characters of an array when the first
d4f3574e 5486@sc{null} is encountered. This is useful when large arrays actually
c906108c 5487contain only short strings.
d4f3574e 5488The default is off.
c906108c 5489
c906108c 5490@item set print pretty on
5d161b24 5491Cause @value{GDBN} to print structures in an indented format with one member
c906108c
SS
5492per line, like this:
5493
5494@smallexample
5495@group
5496$1 = @{
5497 next = 0x0,
5498 flags = @{
5499 sweet = 1,
5500 sour = 1
5501 @},
5502 meat = 0x54 "Pork"
5503@}
5504@end group
5505@end smallexample
5506
5507@item set print pretty off
5508Cause @value{GDBN} to print structures in a compact format, like this:
5509
5510@smallexample
5511@group
5512$1 = @{next = 0x0, flags = @{sweet = 1, sour = 1@}, \
5513meat = 0x54 "Pork"@}
5514@end group
5515@end smallexample
5516
5517@noindent
5518This is the default format.
5519
c906108c
SS
5520@item show print pretty
5521Show which format @value{GDBN} is using to print structures.
5522
c906108c 5523@item set print sevenbit-strings on
4644b6e3
EZ
5524@cindex eight-bit characters in strings
5525@cindex octal escapes in strings
c906108c
SS
5526Print using only seven-bit characters; if this option is set,
5527@value{GDBN} displays any eight-bit characters (in strings or
5528character values) using the notation @code{\}@var{nnn}. This setting is
5529best if you are working in English (@sc{ascii}) and you use the
5530high-order bit of characters as a marker or ``meta'' bit.
5531
5532@item set print sevenbit-strings off
5533Print full eight-bit characters. This allows the use of more
5534international character sets, and is the default.
5535
c906108c
SS
5536@item show print sevenbit-strings
5537Show whether or not @value{GDBN} is printing only seven-bit characters.
5538
c906108c 5539@item set print union on
4644b6e3 5540@cindex unions in structures, printing
5d161b24 5541Tell @value{GDBN} to print unions which are contained in structures. This
c906108c
SS
5542is the default setting.
5543
5544@item set print union off
5545Tell @value{GDBN} not to print unions which are contained in structures.
5546
c906108c
SS
5547@item show print union
5548Ask @value{GDBN} whether or not it will print unions which are contained in
5549structures.
5550
5551For example, given the declarations
5552
5553@smallexample
5554typedef enum @{Tree, Bug@} Species;
5555typedef enum @{Big_tree, Acorn, Seedling@} Tree_forms;
5d161b24 5556typedef enum @{Caterpillar, Cocoon, Butterfly@}
c906108c
SS
5557 Bug_forms;
5558
5559struct thing @{
5560 Species it;
5561 union @{
5562 Tree_forms tree;
5563 Bug_forms bug;
5564 @} form;
5565@};
5566
5567struct thing foo = @{Tree, @{Acorn@}@};
5568@end smallexample
5569
5570@noindent
5571with @code{set print union on} in effect @samp{p foo} would print
5572
5573@smallexample
5574$1 = @{it = Tree, form = @{tree = Acorn, bug = Cocoon@}@}
5575@end smallexample
5576
5577@noindent
5578and with @code{set print union off} in effect it would print
5579
5580@smallexample
5581$1 = @{it = Tree, form = @{...@}@}
5582@end smallexample
5583@end table
5584
c906108c
SS
5585@need 1000
5586@noindent
b37052ae 5587These settings are of interest when debugging C@t{++} programs:
c906108c
SS
5588
5589@table @code
4644b6e3 5590@cindex demangling C@t{++} names
c906108c
SS
5591@item set print demangle
5592@itemx set print demangle on
b37052ae 5593Print C@t{++} names in their source form rather than in the encoded
c906108c 5594(``mangled'') form passed to the assembler and linker for type-safe
d4f3574e 5595linkage. The default is on.
c906108c 5596
c906108c 5597@item show print demangle
b37052ae 5598Show whether C@t{++} names are printed in mangled or demangled form.
c906108c 5599
c906108c
SS
5600@item set print asm-demangle
5601@itemx set print asm-demangle on
b37052ae 5602Print C@t{++} names in their source form rather than their mangled form, even
c906108c
SS
5603in assembler code printouts such as instruction disassemblies.
5604The default is off.
5605
c906108c 5606@item show print asm-demangle
b37052ae 5607Show whether C@t{++} names in assembly listings are printed in mangled
c906108c
SS
5608or demangled form.
5609
b37052ae
EZ
5610@cindex C@t{++} symbol decoding style
5611@cindex symbol decoding style, C@t{++}
c906108c
SS
5612@item set demangle-style @var{style}
5613Choose among several encoding schemes used by different compilers to
b37052ae 5614represent C@t{++} names. The choices for @var{style} are currently:
c906108c
SS
5615
5616@table @code
5617@item auto
5618Allow @value{GDBN} to choose a decoding style by inspecting your program.
5619
5620@item gnu
b37052ae 5621Decode based on the @sc{gnu} C@t{++} compiler (@code{g++}) encoding algorithm.
c906108c 5622This is the default.
c906108c
SS
5623
5624@item hp
b37052ae 5625Decode based on the HP ANSI C@t{++} (@code{aCC}) encoding algorithm.
c906108c
SS
5626
5627@item lucid
b37052ae 5628Decode based on the Lucid C@t{++} compiler (@code{lcc}) encoding algorithm.
c906108c
SS
5629
5630@item arm
b37052ae 5631Decode using the algorithm in the @cite{C@t{++} Annotated Reference Manual}.
c906108c
SS
5632@strong{Warning:} this setting alone is not sufficient to allow
5633debugging @code{cfront}-generated executables. @value{GDBN} would
5634require further enhancement to permit that.
5635
5636@end table
5637If you omit @var{style}, you will see a list of possible formats.
5638
c906108c 5639@item show demangle-style
b37052ae 5640Display the encoding style currently in use for decoding C@t{++} symbols.
c906108c 5641
c906108c
SS
5642@item set print object
5643@itemx set print object on
4644b6e3 5644@cindex derived type of an object, printing
c906108c
SS
5645When displaying a pointer to an object, identify the @emph{actual}
5646(derived) type of the object rather than the @emph{declared} type, using
5647the virtual function table.
5648
5649@item set print object off
5650Display only the declared type of objects, without reference to the
5651virtual function table. This is the default setting.
5652
c906108c
SS
5653@item show print object
5654Show whether actual, or declared, object types are displayed.
5655
c906108c
SS
5656@item set print static-members
5657@itemx set print static-members on
4644b6e3 5658@cindex static members of C@t{++} objects
b37052ae 5659Print static members when displaying a C@t{++} object. The default is on.
c906108c
SS
5660
5661@item set print static-members off
b37052ae 5662Do not print static members when displaying a C@t{++} object.
c906108c 5663
c906108c 5664@item show print static-members
b37052ae 5665Show whether C@t{++} static members are printed, or not.
c906108c
SS
5666
5667@c These don't work with HP ANSI C++ yet.
c906108c
SS
5668@item set print vtbl
5669@itemx set print vtbl on
4644b6e3 5670@cindex pretty print C@t{++} virtual function tables
b37052ae 5671Pretty print C@t{++} virtual function tables. The default is off.
c906108c 5672(The @code{vtbl} commands do not work on programs compiled with the HP
b37052ae 5673ANSI C@t{++} compiler (@code{aCC}).)
c906108c
SS
5674
5675@item set print vtbl off
b37052ae 5676Do not pretty print C@t{++} virtual function tables.
c906108c 5677
c906108c 5678@item show print vtbl
b37052ae 5679Show whether C@t{++} virtual function tables are pretty printed, or not.
c906108c 5680@end table
c906108c 5681
6d2ebf8b 5682@node Value History
c906108c
SS
5683@section Value history
5684
5685@cindex value history
5d161b24
DB
5686Values printed by the @code{print} command are saved in the @value{GDBN}
5687@dfn{value history}. This allows you to refer to them in other expressions.
5688Values are kept until the symbol table is re-read or discarded
5689(for example with the @code{file} or @code{symbol-file} commands).
5690When the symbol table changes, the value history is discarded,
5691since the values may contain pointers back to the types defined in the
c906108c
SS
5692symbol table.
5693
5694@cindex @code{$}
5695@cindex @code{$$}
5696@cindex history number
5697The values printed are given @dfn{history numbers} by which you can
5698refer to them. These are successive integers starting with one.
5699@code{print} shows you the history number assigned to a value by
5700printing @samp{$@var{num} = } before the value; here @var{num} is the
5701history number.
5702
5703To refer to any previous value, use @samp{$} followed by the value's
5704history number. The way @code{print} labels its output is designed to
5705remind you of this. Just @code{$} refers to the most recent value in
5706the history, and @code{$$} refers to the value before that.
5707@code{$$@var{n}} refers to the @var{n}th value from the end; @code{$$2}
5708is the value just prior to @code{$$}, @code{$$1} is equivalent to
5709@code{$$}, and @code{$$0} is equivalent to @code{$}.
5710
5711For example, suppose you have just printed a pointer to a structure and
5712want to see the contents of the structure. It suffices to type
5713
474c8240 5714@smallexample
c906108c 5715p *$
474c8240 5716@end smallexample
c906108c
SS
5717
5718If you have a chain of structures where the component @code{next} points
5719to the next one, you can print the contents of the next one with this:
5720
474c8240 5721@smallexample
c906108c 5722p *$.next
474c8240 5723@end smallexample
c906108c
SS
5724
5725@noindent
5726You can print successive links in the chain by repeating this
5727command---which you can do by just typing @key{RET}.
5728
5729Note that the history records values, not expressions. If the value of
5730@code{x} is 4 and you type these commands:
5731
474c8240 5732@smallexample
c906108c
SS
5733print x
5734set x=5
474c8240 5735@end smallexample
c906108c
SS
5736
5737@noindent
5738then the value recorded in the value history by the @code{print} command
5739remains 4 even though the value of @code{x} has changed.
5740
5741@table @code
5742@kindex show values
5743@item show values
5744Print the last ten values in the value history, with their item numbers.
5745This is like @samp{p@ $$9} repeated ten times, except that @code{show
5746values} does not change the history.
5747
5748@item show values @var{n}
5749Print ten history values centered on history item number @var{n}.
5750
5751@item show values +
5752Print ten history values just after the values last printed. If no more
5753values are available, @code{show values +} produces no display.
5754@end table
5755
5756Pressing @key{RET} to repeat @code{show values @var{n}} has exactly the
5757same effect as @samp{show values +}.
5758
6d2ebf8b 5759@node Convenience Vars
c906108c
SS
5760@section Convenience variables
5761
5762@cindex convenience variables
5763@value{GDBN} provides @dfn{convenience variables} that you can use within
5764@value{GDBN} to hold on to a value and refer to it later. These variables
5765exist entirely within @value{GDBN}; they are not part of your program, and
5766setting a convenience variable has no direct effect on further execution
5767of your program. That is why you can use them freely.
5768
5769Convenience variables are prefixed with @samp{$}. Any name preceded by
5770@samp{$} can be used for a convenience variable, unless it is one of
d4f3574e 5771the predefined machine-specific register names (@pxref{Registers, ,Registers}).
c906108c
SS
5772(Value history references, in contrast, are @emph{numbers} preceded
5773by @samp{$}. @xref{Value History, ,Value history}.)
5774
5775You can save a value in a convenience variable with an assignment
5776expression, just as you would set a variable in your program.
5777For example:
5778
474c8240 5779@smallexample
c906108c 5780set $foo = *object_ptr
474c8240 5781@end smallexample
c906108c
SS
5782
5783@noindent
5784would save in @code{$foo} the value contained in the object pointed to by
5785@code{object_ptr}.
5786
5787Using a convenience variable for the first time creates it, but its
5788value is @code{void} until you assign a new value. You can alter the
5789value with another assignment at any time.
5790
5791Convenience variables have no fixed types. You can assign a convenience
5792variable any type of value, including structures and arrays, even if
5793that variable already has a value of a different type. The convenience
5794variable, when used as an expression, has the type of its current value.
5795
5796@table @code
5797@kindex show convenience
5798@item show convenience
5799Print a list of convenience variables used so far, and their values.
d4f3574e 5800Abbreviated @code{show conv}.
c906108c
SS
5801@end table
5802
5803One of the ways to use a convenience variable is as a counter to be
5804incremented or a pointer to be advanced. For example, to print
5805a field from successive elements of an array of structures:
5806
474c8240 5807@smallexample
c906108c
SS
5808set $i = 0
5809print bar[$i++]->contents
474c8240 5810@end smallexample
c906108c 5811
d4f3574e
SS
5812@noindent
5813Repeat that command by typing @key{RET}.
c906108c
SS
5814
5815Some convenience variables are created automatically by @value{GDBN} and given
5816values likely to be useful.
5817
5818@table @code
41afff9a 5819@vindex $_@r{, convenience variable}
c906108c
SS
5820@item $_
5821The variable @code{$_} is automatically set by the @code{x} command to
5822the last address examined (@pxref{Memory, ,Examining memory}). Other
5823commands which provide a default address for @code{x} to examine also
5824set @code{$_} to that address; these commands include @code{info line}
5825and @code{info breakpoint}. The type of @code{$_} is @code{void *}
5826except when set by the @code{x} command, in which case it is a pointer
5827to the type of @code{$__}.
5828
41afff9a 5829@vindex $__@r{, convenience variable}
c906108c
SS
5830@item $__
5831The variable @code{$__} is automatically set by the @code{x} command
5832to the value found in the last address examined. Its type is chosen
5833to match the format in which the data was printed.
5834
5835@item $_exitcode
41afff9a 5836@vindex $_exitcode@r{, convenience variable}
c906108c
SS
5837The variable @code{$_exitcode} is automatically set to the exit code when
5838the program being debugged terminates.
5839@end table
5840
53a5351d
JM
5841On HP-UX systems, if you refer to a function or variable name that
5842begins with a dollar sign, @value{GDBN} searches for a user or system
5843name first, before it searches for a convenience variable.
c906108c 5844
6d2ebf8b 5845@node Registers
c906108c
SS
5846@section Registers
5847
5848@cindex registers
5849You can refer to machine register contents, in expressions, as variables
5850with names starting with @samp{$}. The names of registers are different
5851for each machine; use @code{info registers} to see the names used on
5852your machine.
5853
5854@table @code
5855@kindex info registers
5856@item info registers
5857Print the names and values of all registers except floating-point
c85508ee 5858and vector registers (in the selected stack frame).
c906108c
SS
5859
5860@kindex info all-registers
5861@cindex floating point registers
5862@item info all-registers
5863Print the names and values of all registers, including floating-point
c85508ee 5864and vector registers (in the selected stack frame).
c906108c
SS
5865
5866@item info registers @var{regname} @dots{}
5867Print the @dfn{relativized} value of each specified register @var{regname}.
5d161b24
DB
5868As discussed in detail below, register values are normally relative to
5869the selected stack frame. @var{regname} may be any register name valid on
c906108c
SS
5870the machine you are using, with or without the initial @samp{$}.
5871@end table
5872
5873@value{GDBN} has four ``standard'' register names that are available (in
5874expressions) on most machines---whenever they do not conflict with an
5875architecture's canonical mnemonics for registers. The register names
5876@code{$pc} and @code{$sp} are used for the program counter register and
5877the stack pointer. @code{$fp} is used for a register that contains a
5878pointer to the current stack frame, and @code{$ps} is used for a
5879register that contains the processor status. For example,
5880you could print the program counter in hex with
5881
474c8240 5882@smallexample
c906108c 5883p/x $pc
474c8240 5884@end smallexample
c906108c
SS
5885
5886@noindent
5887or print the instruction to be executed next with
5888
474c8240 5889@smallexample
c906108c 5890x/i $pc
474c8240 5891@end smallexample
c906108c
SS
5892
5893@noindent
5894or add four to the stack pointer@footnote{This is a way of removing
5895one word from the stack, on machines where stacks grow downward in
5896memory (most machines, nowadays). This assumes that the innermost
5897stack frame is selected; setting @code{$sp} is not allowed when other
5898stack frames are selected. To pop entire frames off the stack,
5899regardless of machine architecture, use @code{return};
d4f3574e 5900see @ref{Returning, ,Returning from a function}.} with
c906108c 5901
474c8240 5902@smallexample
c906108c 5903set $sp += 4
474c8240 5904@end smallexample
c906108c
SS
5905
5906Whenever possible, these four standard register names are available on
5907your machine even though the machine has different canonical mnemonics,
5908so long as there is no conflict. The @code{info registers} command
5909shows the canonical names. For example, on the SPARC, @code{info
5910registers} displays the processor status register as @code{$psr} but you
d4f3574e
SS
5911can also refer to it as @code{$ps}; and on x86-based machines @code{$ps}
5912is an alias for the @sc{eflags} register.
c906108c
SS
5913
5914@value{GDBN} always considers the contents of an ordinary register as an
5915integer when the register is examined in this way. Some machines have
5916special registers which can hold nothing but floating point; these
5917registers are considered to have floating point values. There is no way
5918to refer to the contents of an ordinary register as floating point value
5919(although you can @emph{print} it as a floating point value with
5920@samp{print/f $@var{regname}}).
5921
5922Some registers have distinct ``raw'' and ``virtual'' data formats. This
5923means that the data format in which the register contents are saved by
5924the operating system is not the same one that your program normally
5925sees. For example, the registers of the 68881 floating point
5926coprocessor are always saved in ``extended'' (raw) format, but all C
5927programs expect to work with ``double'' (virtual) format. In such
5d161b24 5928cases, @value{GDBN} normally works with the virtual format only (the format
c906108c
SS
5929that makes sense for your program), but the @code{info registers} command
5930prints the data in both formats.
5931
5932Normally, register values are relative to the selected stack frame
5933(@pxref{Selection, ,Selecting a frame}). This means that you get the
5934value that the register would contain if all stack frames farther in
5935were exited and their saved registers restored. In order to see the
5936true contents of hardware registers, you must select the innermost
5937frame (with @samp{frame 0}).
5938
5939However, @value{GDBN} must deduce where registers are saved, from the machine
5940code generated by your compiler. If some registers are not saved, or if
5941@value{GDBN} is unable to locate the saved registers, the selected stack
5942frame makes no difference.
5943
6d2ebf8b 5944@node Floating Point Hardware
c906108c
SS
5945@section Floating point hardware
5946@cindex floating point
5947
5948Depending on the configuration, @value{GDBN} may be able to give
5949you more information about the status of the floating point hardware.
5950
5951@table @code
5952@kindex info float
5953@item info float
5954Display hardware-dependent information about the floating
5955point unit. The exact contents and layout vary depending on the
5956floating point chip. Currently, @samp{info float} is supported on
5957the ARM and x86 machines.
5958@end table
c906108c 5959
e76f1f2e
AC
5960@node Vector Unit
5961@section Vector Unit
5962@cindex vector unit
5963
5964Depending on the configuration, @value{GDBN} may be able to give you
5965more information about the status of the vector unit.
5966
5967@table @code
5968@kindex info vector
5969@item info vector
5970Display information about the vector unit. The exact contents and
5971layout vary depending on the hardware.
5972@end table
5973
b383017d
RM
5974@node Auxiliary Vector
5975@section Operating system auxiliary vector
5976@cindex auxiliary vector
5977@cindex vector, auxiliary
5978
5979Some operating systems supply an @dfn{auxiliary vector} to programs at
5980startup. This is akin to the arguments and environment that you
5981specify for a program, but contains a system-dependent variety of
5982binary values that tell system libraries important details about the
5983hardware, operating system, and process. Each value's purpose is
5984identified by an integer tag; the meanings are well-known but system-specific.
5985Depending on the configuration and operating system facilities,
5986@value{GDBN} may be able to show you this information.
5987
5988@table @code
5989@kindex info auxv
5990@item info auxv
5991Display the auxiliary vector of the inferior, which can be either a
e4937fc1 5992live process or a core dump file. @value{GDBN} prints each tag value
b383017d
RM
5993numerically, and also shows names and text descriptions for recognized
5994tags. Some values in the vector are numbers, some bit masks, and some
e4937fc1 5995pointers to strings or other data. @value{GDBN} displays each value in the
b383017d
RM
5996most appropriate form for a recognized tag, and in hexadecimal for
5997an unrecognized tag.
5998@end table
5999
29e57380 6000@node Memory Region Attributes
b383017d 6001@section Memory region attributes
29e57380
C
6002@cindex memory region attributes
6003
b383017d
RM
6004@dfn{Memory region attributes} allow you to describe special handling
6005required by regions of your target's memory. @value{GDBN} uses attributes
29e57380
C
6006to determine whether to allow certain types of memory accesses; whether to
6007use specific width accesses; and whether to cache target memory.
6008
6009Defined memory regions can be individually enabled and disabled. When a
6010memory region is disabled, @value{GDBN} uses the default attributes when
6011accessing memory in that region. Similarly, if no memory regions have
6012been defined, @value{GDBN} uses the default attributes when accessing
6013all memory.
6014
b383017d 6015When a memory region is defined, it is given a number to identify it;
29e57380
C
6016to enable, disable, or remove a memory region, you specify that number.
6017
6018@table @code
6019@kindex mem
bfac230e
DH
6020@item mem @var{lower} @var{upper} @var{attributes}@dots{}
6021Define memory region bounded by @var{lower} and @var{upper} with
6022attributes @var{attributes}@dots{}. Note that @var{upper} == 0 is a
6023special case: it is treated as the the target's maximum memory address.
6024(0xffff on 16 bit targets, 0xffffffff on 32 bit targets, etc.)
29e57380
C
6025
6026@kindex delete mem
6027@item delete mem @var{nums}@dots{}
59649f2e 6028Remove memory regions @var{nums}@dots{}.
29e57380
C
6029
6030@kindex disable mem
6031@item disable mem @var{nums}@dots{}
59649f2e 6032Disable memory regions @var{nums}@dots{}.
b383017d 6033A disabled memory region is not forgotten.
29e57380
C
6034It may be enabled again later.
6035
6036@kindex enable mem
6037@item enable mem @var{nums}@dots{}
59649f2e 6038Enable memory regions @var{nums}@dots{}.
29e57380
C
6039
6040@kindex info mem
6041@item info mem
6042Print a table of all defined memory regions, with the following columns
6043for each region.
6044
6045@table @emph
6046@item Memory Region Number
6047@item Enabled or Disabled.
b383017d 6048Enabled memory regions are marked with @samp{y}.
29e57380
C
6049Disabled memory regions are marked with @samp{n}.
6050
6051@item Lo Address
6052The address defining the inclusive lower bound of the memory region.
6053
6054@item Hi Address
6055The address defining the exclusive upper bound of the memory region.
6056
6057@item Attributes
6058The list of attributes set for this memory region.
6059@end table
6060@end table
6061
6062
6063@subsection Attributes
6064
b383017d 6065@subsubsection Memory Access Mode
29e57380
C
6066The access mode attributes set whether @value{GDBN} may make read or
6067write accesses to a memory region.
6068
6069While these attributes prevent @value{GDBN} from performing invalid
6070memory accesses, they do nothing to prevent the target system, I/O DMA,
6071etc. from accessing memory.
6072
6073@table @code
6074@item ro
6075Memory is read only.
6076@item wo
6077Memory is write only.
6078@item rw
6ca652b0 6079Memory is read/write. This is the default.
29e57380
C
6080@end table
6081
6082@subsubsection Memory Access Size
6083The acccess size attributes tells @value{GDBN} to use specific sized
6084accesses in the memory region. Often memory mapped device registers
6085require specific sized accesses. If no access size attribute is
6086specified, @value{GDBN} may use accesses of any size.
6087
6088@table @code
6089@item 8
6090Use 8 bit memory accesses.
6091@item 16
6092Use 16 bit memory accesses.
6093@item 32
6094Use 32 bit memory accesses.
6095@item 64
6096Use 64 bit memory accesses.
6097@end table
6098
6099@c @subsubsection Hardware/Software Breakpoints
6100@c The hardware/software breakpoint attributes set whether @value{GDBN}
6101@c will use hardware or software breakpoints for the internal breakpoints
6102@c used by the step, next, finish, until, etc. commands.
6103@c
6104@c @table @code
6105@c @item hwbreak
b383017d 6106@c Always use hardware breakpoints
29e57380
C
6107@c @item swbreak (default)
6108@c @end table
6109
6110@subsubsection Data Cache
6111The data cache attributes set whether @value{GDBN} will cache target
6112memory. While this generally improves performance by reducing debug
6113protocol overhead, it can lead to incorrect results because @value{GDBN}
6114does not know about volatile variables or memory mapped device
6115registers.
6116
6117@table @code
6118@item cache
b383017d 6119Enable @value{GDBN} to cache target memory.
6ca652b0
EZ
6120@item nocache
6121Disable @value{GDBN} from caching target memory. This is the default.
29e57380
C
6122@end table
6123
6124@c @subsubsection Memory Write Verification
b383017d 6125@c The memory write verification attributes set whether @value{GDBN}
29e57380
C
6126@c will re-reads data after each write to verify the write was successful.
6127@c
6128@c @table @code
6129@c @item verify
6130@c @item noverify (default)
6131@c @end table
6132
16d9dec6
MS
6133@node Dump/Restore Files
6134@section Copy between memory and a file
6135@cindex dump/restore files
6136@cindex append data to a file
6137@cindex dump data to a file
6138@cindex restore data from a file
16d9dec6 6139
df5215a6
JB
6140You can use the commands @code{dump}, @code{append}, and
6141@code{restore} to copy data between target memory and a file. The
6142@code{dump} and @code{append} commands write data to a file, and the
6143@code{restore} command reads data from a file back into the inferior's
6144memory. Files may be in binary, Motorola S-record, Intel hex, or
6145Tektronix Hex format; however, @value{GDBN} can only append to binary
6146files.
6147
6148@table @code
6149
6150@kindex dump
6151@item dump @r{[}@var{format}@r{]} memory @var{filename} @var{start_addr} @var{end_addr}
6152@itemx dump @r{[}@var{format}@r{]} value @var{filename} @var{expr}
6153Dump the contents of memory from @var{start_addr} to @var{end_addr},
6154or the value of @var{expr}, to @var{filename} in the given format.
16d9dec6 6155
df5215a6 6156The @var{format} parameter may be any one of:
16d9dec6 6157@table @code
df5215a6
JB
6158@item binary
6159Raw binary form.
6160@item ihex
6161Intel hex format.
6162@item srec
6163Motorola S-record format.
6164@item tekhex
6165Tektronix Hex format.
6166@end table
6167
6168@value{GDBN} uses the same definitions of these formats as the
6169@sc{gnu} binary utilities, like @samp{objdump} and @samp{objcopy}. If
6170@var{format} is omitted, @value{GDBN} dumps the data in raw binary
6171form.
6172
6173@kindex append
6174@item append @r{[}binary@r{]} memory @var{filename} @var{start_addr} @var{end_addr}
6175@itemx append @r{[}binary@r{]} value @var{filename} @var{expr}
6176Append the contents of memory from @var{start_addr} to @var{end_addr},
6177or the value of @var{expr}, to @var{filename}, in raw binary form.
6178(@value{GDBN} can only append data to files in raw binary form.)
6179
6180@kindex restore
6181@item restore @var{filename} @r{[}binary@r{]} @var{bias} @var{start} @var{end}
6182Restore the contents of file @var{filename} into memory. The
6183@code{restore} command can automatically recognize any known @sc{bfd}
6184file format, except for raw binary. To restore a raw binary file you
6185must specify the optional keyword @code{binary} after the filename.
16d9dec6 6186
b383017d 6187If @var{bias} is non-zero, its value will be added to the addresses
16d9dec6
MS
6188contained in the file. Binary files always start at address zero, so
6189they will be restored at address @var{bias}. Other bfd files have
6190a built-in location; they will be restored at offset @var{bias}
6191from that location.
6192
6193If @var{start} and/or @var{end} are non-zero, then only data between
6194file offset @var{start} and file offset @var{end} will be restored.
b383017d 6195These offsets are relative to the addresses in the file, before
16d9dec6
MS
6196the @var{bias} argument is applied.
6197
6198@end table
6199
384ee23f
EZ
6200@node Core File Generation
6201@section How to Produce a Core File from Your Program
6202@cindex dump core from inferior
6203
6204A @dfn{core file} or @dfn{core dump} is a file that records the memory
6205image of a running process and its process status (register values
6206etc.). Its primary use is post-mortem debugging of a program that
6207crashed while it ran outside a debugger. A program that crashes
6208automatically produces a core file, unless this feature is disabled by
6209the user. @xref{Files}, for information on invoking @value{GDBN} in
6210the post-mortem debugging mode.
6211
6212Occasionally, you may wish to produce a core file of the program you
6213are debugging in order to preserve a snapshot of its state.
6214@value{GDBN} has a special command for that.
6215
6216@table @code
6217@kindex gcore
6218@kindex generate-core-file
6219@item generate-core-file [@var{file}]
6220@itemx gcore [@var{file}]
6221Produce a core dump of the inferior process. The optional argument
6222@var{file} specifies the file name where to put the core dump. If not
6223specified, the file name defaults to @file{core.@var{pid}}, where
6224@var{pid} is the inferior process ID.
6225
6226Note that this command is implemented only for some systems (as of
6227this writing, @sc{gnu}/Linux, FreeBSD, Solaris, Unixware, and S390).
6228@end table
6229
a0eb71c5
KB
6230@node Character Sets
6231@section Character Sets
6232@cindex character sets
6233@cindex charset
6234@cindex translating between character sets
6235@cindex host character set
6236@cindex target character set
6237
6238If the program you are debugging uses a different character set to
6239represent characters and strings than the one @value{GDBN} uses itself,
6240@value{GDBN} can automatically translate between the character sets for
6241you. The character set @value{GDBN} uses we call the @dfn{host
6242character set}; the one the inferior program uses we call the
6243@dfn{target character set}.
6244
6245For example, if you are running @value{GDBN} on a @sc{gnu}/Linux system, which
6246uses the ISO Latin 1 character set, but you are using @value{GDBN}'s
6247remote protocol (@pxref{Remote,Remote Debugging}) to debug a program
6248running on an IBM mainframe, which uses the @sc{ebcdic} character set,
6249then the host character set is Latin-1, and the target character set is
6250@sc{ebcdic}. If you give @value{GDBN} the command @code{set
e33d66ec 6251target-charset EBCDIC-US}, then @value{GDBN} translates between
a0eb71c5
KB
6252@sc{ebcdic} and Latin 1 as you print character or string values, or use
6253character and string literals in expressions.
6254
6255@value{GDBN} has no way to automatically recognize which character set
6256the inferior program uses; you must tell it, using the @code{set
6257target-charset} command, described below.
6258
6259Here are the commands for controlling @value{GDBN}'s character set
6260support:
6261
6262@table @code
6263@item set target-charset @var{charset}
6264@kindex set target-charset
6265Set the current target character set to @var{charset}. We list the
e33d66ec
EZ
6266character set names @value{GDBN} recognizes below, but if you type
6267@code{set target-charset} followed by @key{TAB}@key{TAB}, @value{GDBN} will
6268list the target character sets it supports.
a0eb71c5
KB
6269@end table
6270
6271@table @code
6272@item set host-charset @var{charset}
6273@kindex set host-charset
6274Set the current host character set to @var{charset}.
6275
6276By default, @value{GDBN} uses a host character set appropriate to the
6277system it is running on; you can override that default using the
6278@code{set host-charset} command.
6279
6280@value{GDBN} can only use certain character sets as its host character
6281set. We list the character set names @value{GDBN} recognizes below, and
e33d66ec
EZ
6282indicate which can be host character sets, but if you type
6283@code{set target-charset} followed by @key{TAB}@key{TAB}, @value{GDBN} will
6284list the host character sets it supports.
a0eb71c5
KB
6285
6286@item set charset @var{charset}
6287@kindex set charset
e33d66ec
EZ
6288Set the current host and target character sets to @var{charset}. As
6289above, if you type @code{set charset} followed by @key{TAB}@key{TAB},
6290@value{GDBN} will list the name of the character sets that can be used
6291for both host and target.
6292
a0eb71c5
KB
6293
6294@item show charset
a0eb71c5 6295@kindex show charset
b383017d 6296Show the names of the current host and target charsets.
e33d66ec
EZ
6297
6298@itemx show host-charset
a0eb71c5 6299@kindex show host-charset
b383017d 6300Show the name of the current host charset.
e33d66ec
EZ
6301
6302@itemx show target-charset
a0eb71c5 6303@kindex show target-charset
b383017d 6304Show the name of the current target charset.
a0eb71c5
KB
6305
6306@end table
6307
6308@value{GDBN} currently includes support for the following character
6309sets:
6310
6311@table @code
6312
6313@item ASCII
6314@cindex ASCII character set
6315Seven-bit U.S. @sc{ascii}. @value{GDBN} can use this as its host
6316character set.
6317
6318@item ISO-8859-1
6319@cindex ISO 8859-1 character set
6320@cindex ISO Latin 1 character set
e33d66ec 6321The ISO Latin 1 character set. This extends @sc{ascii} with accented
a0eb71c5
KB
6322characters needed for French, German, and Spanish. @value{GDBN} can use
6323this as its host character set.
6324
6325@item EBCDIC-US
6326@itemx IBM1047
6327@cindex EBCDIC character set
6328@cindex IBM1047 character set
6329Variants of the @sc{ebcdic} character set, used on some of IBM's
6330mainframe operating systems. (@sc{gnu}/Linux on the S/390 uses U.S. @sc{ascii}.)
6331@value{GDBN} cannot use these as its host character set.
6332
6333@end table
6334
6335Note that these are all single-byte character sets. More work inside
6336GDB is needed to support multi-byte or variable-width character
6337encodings, like the UTF-8 and UCS-2 encodings of Unicode.
6338
6339Here is an example of @value{GDBN}'s character set support in action.
6340Assume that the following source code has been placed in the file
6341@file{charset-test.c}:
6342
6343@smallexample
6344#include <stdio.h>
6345
6346char ascii_hello[]
6347 = @{72, 101, 108, 108, 111, 44, 32, 119,
6348 111, 114, 108, 100, 33, 10, 0@};
6349char ibm1047_hello[]
6350 = @{200, 133, 147, 147, 150, 107, 64, 166,
6351 150, 153, 147, 132, 90, 37, 0@};
6352
6353main ()
6354@{
6355 printf ("Hello, world!\n");
6356@}
10998722 6357@end smallexample
a0eb71c5
KB
6358
6359In this program, @code{ascii_hello} and @code{ibm1047_hello} are arrays
6360containing the string @samp{Hello, world!} followed by a newline,
6361encoded in the @sc{ascii} and @sc{ibm1047} character sets.
6362
6363We compile the program, and invoke the debugger on it:
6364
6365@smallexample
6366$ gcc -g charset-test.c -o charset-test
6367$ gdb -nw charset-test
6368GNU gdb 2001-12-19-cvs
6369Copyright 2001 Free Software Foundation, Inc.
6370@dots{}
f7dc1244 6371(@value{GDBP})
10998722 6372@end smallexample
a0eb71c5
KB
6373
6374We can use the @code{show charset} command to see what character sets
6375@value{GDBN} is currently using to interpret and display characters and
6376strings:
6377
6378@smallexample
f7dc1244 6379(@value{GDBP}) show charset
e33d66ec 6380The current host and target character set is `ISO-8859-1'.
f7dc1244 6381(@value{GDBP})
10998722 6382@end smallexample
a0eb71c5
KB
6383
6384For the sake of printing this manual, let's use @sc{ascii} as our
6385initial character set:
6386@smallexample
f7dc1244
EZ
6387(@value{GDBP}) set charset ASCII
6388(@value{GDBP}) show charset
e33d66ec 6389The current host and target character set is `ASCII'.
f7dc1244 6390(@value{GDBP})
10998722 6391@end smallexample
a0eb71c5
KB
6392
6393Let's assume that @sc{ascii} is indeed the correct character set for our
6394host system --- in other words, let's assume that if @value{GDBN} prints
6395characters using the @sc{ascii} character set, our terminal will display
6396them properly. Since our current target character set is also
6397@sc{ascii}, the contents of @code{ascii_hello} print legibly:
6398
6399@smallexample
f7dc1244 6400(@value{GDBP}) print ascii_hello
a0eb71c5 6401$1 = 0x401698 "Hello, world!\n"
f7dc1244 6402(@value{GDBP}) print ascii_hello[0]
a0eb71c5 6403$2 = 72 'H'
f7dc1244 6404(@value{GDBP})
10998722 6405@end smallexample
a0eb71c5
KB
6406
6407@value{GDBN} uses the target character set for character and string
6408literals you use in expressions:
6409
6410@smallexample
f7dc1244 6411(@value{GDBP}) print '+'
a0eb71c5 6412$3 = 43 '+'
f7dc1244 6413(@value{GDBP})
10998722 6414@end smallexample
a0eb71c5
KB
6415
6416The @sc{ascii} character set uses the number 43 to encode the @samp{+}
6417character.
6418
6419@value{GDBN} relies on the user to tell it which character set the
6420target program uses. If we print @code{ibm1047_hello} while our target
6421character set is still @sc{ascii}, we get jibberish:
6422
6423@smallexample
f7dc1244 6424(@value{GDBP}) print ibm1047_hello
a0eb71c5 6425$4 = 0x4016a8 "\310\205\223\223\226k@@\246\226\231\223\204Z%"
f7dc1244 6426(@value{GDBP}) print ibm1047_hello[0]
a0eb71c5 6427$5 = 200 '\310'
f7dc1244 6428(@value{GDBP})
10998722 6429@end smallexample
a0eb71c5 6430
e33d66ec 6431If we invoke the @code{set target-charset} followed by @key{TAB}@key{TAB},
a0eb71c5
KB
6432@value{GDBN} tells us the character sets it supports:
6433
6434@smallexample
f7dc1244 6435(@value{GDBP}) set target-charset
b383017d 6436ASCII EBCDIC-US IBM1047 ISO-8859-1
f7dc1244 6437(@value{GDBP}) set target-charset
10998722 6438@end smallexample
a0eb71c5
KB
6439
6440We can select @sc{ibm1047} as our target character set, and examine the
6441program's strings again. Now the @sc{ascii} string is wrong, but
6442@value{GDBN} translates the contents of @code{ibm1047_hello} from the
6443target character set, @sc{ibm1047}, to the host character set,
6444@sc{ascii}, and they display correctly:
6445
6446@smallexample
f7dc1244
EZ
6447(@value{GDBP}) set target-charset IBM1047
6448(@value{GDBP}) show charset
e33d66ec
EZ
6449The current host character set is `ASCII'.
6450The current target character set is `IBM1047'.
f7dc1244 6451(@value{GDBP}) print ascii_hello
a0eb71c5 6452$6 = 0x401698 "\110\145%%?\054\040\167?\162%\144\041\012"
f7dc1244 6453(@value{GDBP}) print ascii_hello[0]
a0eb71c5 6454$7 = 72 '\110'
f7dc1244 6455(@value{GDBP}) print ibm1047_hello
a0eb71c5 6456$8 = 0x4016a8 "Hello, world!\n"
f7dc1244 6457(@value{GDBP}) print ibm1047_hello[0]
a0eb71c5 6458$9 = 200 'H'
f7dc1244 6459(@value{GDBP})
10998722 6460@end smallexample
a0eb71c5
KB
6461
6462As above, @value{GDBN} uses the target character set for character and
6463string literals you use in expressions:
6464
6465@smallexample
f7dc1244 6466(@value{GDBP}) print '+'
a0eb71c5 6467$10 = 78 '+'
f7dc1244 6468(@value{GDBP})
10998722 6469@end smallexample
a0eb71c5 6470
e33d66ec 6471The @sc{ibm1047} character set uses the number 78 to encode the @samp{+}
a0eb71c5
KB
6472character.
6473
6474
e2e0bcd1
JB
6475@node Macros
6476@chapter C Preprocessor Macros
6477
49efadf5 6478Some languages, such as C and C@t{++}, provide a way to define and invoke
e2e0bcd1
JB
6479``preprocessor macros'' which expand into strings of tokens.
6480@value{GDBN} can evaluate expressions containing macro invocations, show
6481the result of macro expansion, and show a macro's definition, including
6482where it was defined.
6483
6484You may need to compile your program specially to provide @value{GDBN}
6485with information about preprocessor macros. Most compilers do not
6486include macros in their debugging information, even when you compile
6487with the @option{-g} flag. @xref{Compilation}.
6488
6489A program may define a macro at one point, remove that definition later,
6490and then provide a different definition after that. Thus, at different
6491points in the program, a macro may have different definitions, or have
6492no definition at all. If there is a current stack frame, @value{GDBN}
6493uses the macros in scope at that frame's source code line. Otherwise,
6494@value{GDBN} uses the macros in scope at the current listing location;
6495see @ref{List}.
6496
6497At the moment, @value{GDBN} does not support the @code{##}
6498token-splicing operator, the @code{#} stringification operator, or
6499variable-arity macros.
6500
6501Whenever @value{GDBN} evaluates an expression, it always expands any
6502macro invocations present in the expression. @value{GDBN} also provides
6503the following commands for working with macros explicitly.
6504
6505@table @code
6506
6507@kindex macro expand
6508@cindex macro expansion, showing the results of preprocessor
6509@cindex preprocessor macro expansion, showing the results of
6510@cindex expanding preprocessor macros
6511@item macro expand @var{expression}
6512@itemx macro exp @var{expression}
6513Show the results of expanding all preprocessor macro invocations in
6514@var{expression}. Since @value{GDBN} simply expands macros, but does
6515not parse the result, @var{expression} need not be a valid expression;
6516it can be any string of tokens.
6517
e2e0bcd1
JB
6518@item macro expand-once @var{expression}
6519@itemx macro exp1 @var{expression}
4644b6e3 6520@cindex expand macro once
e2e0bcd1
JB
6521@i{(This command is not yet implemented.)} Show the results of
6522expanding those preprocessor macro invocations that appear explicitly in
6523@var{expression}. Macro invocations appearing in that expansion are
6524left unchanged. This command allows you to see the effect of a
6525particular macro more clearly, without being confused by further
6526expansions. Since @value{GDBN} simply expands macros, but does not
6527parse the result, @var{expression} need not be a valid expression; it
6528can be any string of tokens.
6529
475b0867 6530@kindex info macro
e2e0bcd1
JB
6531@cindex macro definition, showing
6532@cindex definition, showing a macro's
475b0867 6533@item info macro @var{macro}
e2e0bcd1
JB
6534Show the definition of the macro named @var{macro}, and describe the
6535source location where that definition was established.
6536
6537@kindex macro define
6538@cindex user-defined macros
6539@cindex defining macros interactively
6540@cindex macros, user-defined
6541@item macro define @var{macro} @var{replacement-list}
6542@itemx macro define @var{macro}(@var{arglist}) @var{replacement-list}
6543@i{(This command is not yet implemented.)} Introduce a definition for a
6544preprocessor macro named @var{macro}, invocations of which are replaced
6545by the tokens given in @var{replacement-list}. The first form of this
6546command defines an ``object-like'' macro, which takes no arguments; the
6547second form defines a ``function-like'' macro, which takes the arguments
6548given in @var{arglist}.
6549
6550A definition introduced by this command is in scope in every expression
6551evaluated in @value{GDBN}, until it is removed with the @command{macro
6552undef} command, described below. The definition overrides all
6553definitions for @var{macro} present in the program being debugged, as
6554well as any previous user-supplied definition.
6555
6556@kindex macro undef
6557@item macro undef @var{macro}
6558@i{(This command is not yet implemented.)} Remove any user-supplied
6559definition for the macro named @var{macro}. This command only affects
6560definitions provided with the @command{macro define} command, described
6561above; it cannot remove definitions present in the program being
6562debugged.
6563
6564@end table
6565
6566@cindex macros, example of debugging with
6567Here is a transcript showing the above commands in action. First, we
6568show our source files:
6569
6570@smallexample
6571$ cat sample.c
6572#include <stdio.h>
6573#include "sample.h"
6574
6575#define M 42
6576#define ADD(x) (M + x)
6577
6578main ()
6579@{
6580#define N 28
6581 printf ("Hello, world!\n");
6582#undef N
6583 printf ("We're so creative.\n");
6584#define N 1729
6585 printf ("Goodbye, world!\n");
6586@}
6587$ cat sample.h
6588#define Q <
6589$
6590@end smallexample
6591
6592Now, we compile the program using the @sc{gnu} C compiler, @value{NGCC}.
6593We pass the @option{-gdwarf-2} and @option{-g3} flags to ensure the
6594compiler includes information about preprocessor macros in the debugging
6595information.
6596
6597@smallexample
6598$ gcc -gdwarf-2 -g3 sample.c -o sample
6599$
6600@end smallexample
6601
6602Now, we start @value{GDBN} on our sample program:
6603
6604@smallexample
6605$ gdb -nw sample
6606GNU gdb 2002-05-06-cvs
6607Copyright 2002 Free Software Foundation, Inc.
6608GDB is free software, @dots{}
f7dc1244 6609(@value{GDBP})
e2e0bcd1
JB
6610@end smallexample
6611
6612We can expand macros and examine their definitions, even when the
6613program is not running. @value{GDBN} uses the current listing position
6614to decide which macro definitions are in scope:
6615
6616@smallexample
f7dc1244 6617(@value{GDBP}) list main
e2e0bcd1
JB
66183
66194 #define M 42
66205 #define ADD(x) (M + x)
66216
66227 main ()
66238 @{
66249 #define N 28
662510 printf ("Hello, world!\n");
662611 #undef N
662712 printf ("We're so creative.\n");
f7dc1244 6628(@value{GDBP}) info macro ADD
e2e0bcd1
JB
6629Defined at /home/jimb/gdb/macros/play/sample.c:5
6630#define ADD(x) (M + x)
f7dc1244 6631(@value{GDBP}) info macro Q
e2e0bcd1
JB
6632Defined at /home/jimb/gdb/macros/play/sample.h:1
6633 included at /home/jimb/gdb/macros/play/sample.c:2
6634#define Q <
f7dc1244 6635(@value{GDBP}) macro expand ADD(1)
e2e0bcd1 6636expands to: (42 + 1)
f7dc1244 6637(@value{GDBP}) macro expand-once ADD(1)
e2e0bcd1 6638expands to: once (M + 1)
f7dc1244 6639(@value{GDBP})
e2e0bcd1
JB
6640@end smallexample
6641
6642In the example above, note that @command{macro expand-once} expands only
6643the macro invocation explicit in the original text --- the invocation of
6644@code{ADD} --- but does not expand the invocation of the macro @code{M},
6645which was introduced by @code{ADD}.
6646
6647Once the program is running, GDB uses the macro definitions in force at
6648the source line of the current stack frame:
6649
6650@smallexample
f7dc1244 6651(@value{GDBP}) break main
e2e0bcd1 6652Breakpoint 1 at 0x8048370: file sample.c, line 10.
f7dc1244 6653(@value{GDBP}) run
b383017d 6654Starting program: /home/jimb/gdb/macros/play/sample
e2e0bcd1
JB
6655
6656Breakpoint 1, main () at sample.c:10
665710 printf ("Hello, world!\n");
f7dc1244 6658(@value{GDBP})
e2e0bcd1
JB
6659@end smallexample
6660
6661At line 10, the definition of the macro @code{N} at line 9 is in force:
6662
6663@smallexample
f7dc1244 6664(@value{GDBP}) info macro N
e2e0bcd1
JB
6665Defined at /home/jimb/gdb/macros/play/sample.c:9
6666#define N 28
f7dc1244 6667(@value{GDBP}) macro expand N Q M
e2e0bcd1 6668expands to: 28 < 42
f7dc1244 6669(@value{GDBP}) print N Q M
e2e0bcd1 6670$1 = 1
f7dc1244 6671(@value{GDBP})
e2e0bcd1
JB
6672@end smallexample
6673
6674As we step over directives that remove @code{N}'s definition, and then
6675give it a new definition, @value{GDBN} finds the definition (or lack
6676thereof) in force at each point:
6677
6678@smallexample
f7dc1244 6679(@value{GDBP}) next
e2e0bcd1
JB
6680Hello, world!
668112 printf ("We're so creative.\n");
f7dc1244 6682(@value{GDBP}) info macro N
e2e0bcd1
JB
6683The symbol `N' has no definition as a C/C++ preprocessor macro
6684at /home/jimb/gdb/macros/play/sample.c:12
f7dc1244 6685(@value{GDBP}) next
e2e0bcd1
JB
6686We're so creative.
668714 printf ("Goodbye, world!\n");
f7dc1244 6688(@value{GDBP}) info macro N
e2e0bcd1
JB
6689Defined at /home/jimb/gdb/macros/play/sample.c:13
6690#define N 1729
f7dc1244 6691(@value{GDBP}) macro expand N Q M
e2e0bcd1 6692expands to: 1729 < 42
f7dc1244 6693(@value{GDBP}) print N Q M
e2e0bcd1 6694$2 = 0
f7dc1244 6695(@value{GDBP})
e2e0bcd1
JB
6696@end smallexample
6697
6698
b37052ae
EZ
6699@node Tracepoints
6700@chapter Tracepoints
6701@c This chapter is based on the documentation written by Michael
6702@c Snyder, David Taylor, Jim Blandy, and Elena Zannoni.
6703
6704@cindex tracepoints
6705In some applications, it is not feasible for the debugger to interrupt
6706the program's execution long enough for the developer to learn
6707anything helpful about its behavior. If the program's correctness
6708depends on its real-time behavior, delays introduced by a debugger
6709might cause the program to change its behavior drastically, or perhaps
6710fail, even when the code itself is correct. It is useful to be able
6711to observe the program's behavior without interrupting it.
6712
6713Using @value{GDBN}'s @code{trace} and @code{collect} commands, you can
6714specify locations in the program, called @dfn{tracepoints}, and
6715arbitrary expressions to evaluate when those tracepoints are reached.
6716Later, using the @code{tfind} command, you can examine the values
6717those expressions had when the program hit the tracepoints. The
6718expressions may also denote objects in memory---structures or arrays,
6719for example---whose values @value{GDBN} should record; while visiting
6720a particular tracepoint, you may inspect those objects as if they were
6721in memory at that moment. However, because @value{GDBN} records these
6722values without interacting with you, it can do so quickly and
6723unobtrusively, hopefully not disturbing the program's behavior.
6724
6725The tracepoint facility is currently available only for remote
2c0069bb
EZ
6726targets. @xref{Targets}. In addition, your remote target must know how
6727to collect trace data. This functionality is implemented in the remote
6728stub; however, none of the stubs distributed with @value{GDBN} support
6729tracepoints as of this writing.
b37052ae
EZ
6730
6731This chapter describes the tracepoint commands and features.
6732
6733@menu
b383017d
RM
6734* Set Tracepoints::
6735* Analyze Collected Data::
6736* Tracepoint Variables::
b37052ae
EZ
6737@end menu
6738
6739@node Set Tracepoints
6740@section Commands to Set Tracepoints
6741
6742Before running such a @dfn{trace experiment}, an arbitrary number of
6743tracepoints can be set. Like a breakpoint (@pxref{Set Breaks}), a
6744tracepoint has a number assigned to it by @value{GDBN}. Like with
6745breakpoints, tracepoint numbers are successive integers starting from
6746one. Many of the commands associated with tracepoints take the
6747tracepoint number as their argument, to identify which tracepoint to
6748work on.
6749
6750For each tracepoint, you can specify, in advance, some arbitrary set
6751of data that you want the target to collect in the trace buffer when
6752it hits that tracepoint. The collected data can include registers,
6753local variables, or global data. Later, you can use @value{GDBN}
6754commands to examine the values these data had at the time the
6755tracepoint was hit.
6756
6757This section describes commands to set tracepoints and associated
6758conditions and actions.
6759
6760@menu
b383017d
RM
6761* Create and Delete Tracepoints::
6762* Enable and Disable Tracepoints::
6763* Tracepoint Passcounts::
6764* Tracepoint Actions::
6765* Listing Tracepoints::
6766* Starting and Stopping Trace Experiment::
b37052ae
EZ
6767@end menu
6768
6769@node Create and Delete Tracepoints
6770@subsection Create and Delete Tracepoints
6771
6772@table @code
6773@cindex set tracepoint
6774@kindex trace
6775@item trace
6776The @code{trace} command is very similar to the @code{break} command.
6777Its argument can be a source line, a function name, or an address in
6778the target program. @xref{Set Breaks}. The @code{trace} command
6779defines a tracepoint, which is a point in the target program where the
6780debugger will briefly stop, collect some data, and then allow the
6781program to continue. Setting a tracepoint or changing its commands
6782doesn't take effect until the next @code{tstart} command; thus, you
6783cannot change the tracepoint attributes once a trace experiment is
6784running.
6785
6786Here are some examples of using the @code{trace} command:
6787
6788@smallexample
6789(@value{GDBP}) @b{trace foo.c:121} // a source file and line number
6790
6791(@value{GDBP}) @b{trace +2} // 2 lines forward
6792
6793(@value{GDBP}) @b{trace my_function} // first source line of function
6794
6795(@value{GDBP}) @b{trace *my_function} // EXACT start address of function
6796
6797(@value{GDBP}) @b{trace *0x2117c4} // an address
6798@end smallexample
6799
6800@noindent
6801You can abbreviate @code{trace} as @code{tr}.
6802
6803@vindex $tpnum
6804@cindex last tracepoint number
6805@cindex recent tracepoint number
6806@cindex tracepoint number
6807The convenience variable @code{$tpnum} records the tracepoint number
6808of the most recently set tracepoint.
6809
6810@kindex delete tracepoint
6811@cindex tracepoint deletion
6812@item delete tracepoint @r{[}@var{num}@r{]}
6813Permanently delete one or more tracepoints. With no argument, the
6814default is to delete all tracepoints.
6815
6816Examples:
6817
6818@smallexample
6819(@value{GDBP}) @b{delete trace 1 2 3} // remove three tracepoints
6820
6821(@value{GDBP}) @b{delete trace} // remove all tracepoints
6822@end smallexample
6823
6824@noindent
6825You can abbreviate this command as @code{del tr}.
6826@end table
6827
6828@node Enable and Disable Tracepoints
6829@subsection Enable and Disable Tracepoints
6830
6831@table @code
6832@kindex disable tracepoint
6833@item disable tracepoint @r{[}@var{num}@r{]}
6834Disable tracepoint @var{num}, or all tracepoints if no argument
6835@var{num} is given. A disabled tracepoint will have no effect during
6836the next trace experiment, but it is not forgotten. You can re-enable
6837a disabled tracepoint using the @code{enable tracepoint} command.
6838
6839@kindex enable tracepoint
6840@item enable tracepoint @r{[}@var{num}@r{]}
6841Enable tracepoint @var{num}, or all tracepoints. The enabled
6842tracepoints will become effective the next time a trace experiment is
6843run.
6844@end table
6845
6846@node Tracepoint Passcounts
6847@subsection Tracepoint Passcounts
6848
6849@table @code
6850@kindex passcount
6851@cindex tracepoint pass count
6852@item passcount @r{[}@var{n} @r{[}@var{num}@r{]]}
6853Set the @dfn{passcount} of a tracepoint. The passcount is a way to
6854automatically stop a trace experiment. If a tracepoint's passcount is
6855@var{n}, then the trace experiment will be automatically stopped on
6856the @var{n}'th time that tracepoint is hit. If the tracepoint number
6857@var{num} is not specified, the @code{passcount} command sets the
6858passcount of the most recently defined tracepoint. If no passcount is
6859given, the trace experiment will run until stopped explicitly by the
6860user.
6861
6862Examples:
6863
6864@smallexample
b383017d 6865(@value{GDBP}) @b{passcount 5 2} // Stop on the 5th execution of
6826cf00 6866@exdent @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @code{// tracepoint 2}
b37052ae
EZ
6867
6868(@value{GDBP}) @b{passcount 12} // Stop on the 12th execution of the
6826cf00 6869@exdent @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @code{// most recently defined tracepoint.}
b37052ae
EZ
6870(@value{GDBP}) @b{trace foo}
6871(@value{GDBP}) @b{pass 3}
6872(@value{GDBP}) @b{trace bar}
6873(@value{GDBP}) @b{pass 2}
6874(@value{GDBP}) @b{trace baz}
6875(@value{GDBP}) @b{pass 1} // Stop tracing when foo has been
6826cf00
EZ
6876@exdent @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @code{// executed 3 times OR when bar has}
6877@exdent @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @code{// been executed 2 times}
6878@exdent @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @code{// OR when baz has been executed 1 time.}
b37052ae
EZ
6879@end smallexample
6880@end table
6881
6882@node Tracepoint Actions
6883@subsection Tracepoint Action Lists
6884
6885@table @code
6886@kindex actions
6887@cindex tracepoint actions
6888@item actions @r{[}@var{num}@r{]}
6889This command will prompt for a list of actions to be taken when the
6890tracepoint is hit. If the tracepoint number @var{num} is not
6891specified, this command sets the actions for the one that was most
6892recently defined (so that you can define a tracepoint and then say
6893@code{actions} without bothering about its number). You specify the
6894actions themselves on the following lines, one action at a time, and
6895terminate the actions list with a line containing just @code{end}. So
6896far, the only defined actions are @code{collect} and
6897@code{while-stepping}.
6898
6899@cindex remove actions from a tracepoint
6900To remove all actions from a tracepoint, type @samp{actions @var{num}}
6901and follow it immediately with @samp{end}.
6902
6903@smallexample
6904(@value{GDBP}) @b{collect @var{data}} // collect some data
6905
6826cf00 6906(@value{GDBP}) @b{while-stepping 5} // single-step 5 times, collect data
b37052ae 6907
6826cf00 6908(@value{GDBP}) @b{end} // signals the end of actions.
b37052ae
EZ
6909@end smallexample
6910
6911In the following example, the action list begins with @code{collect}
6912commands indicating the things to be collected when the tracepoint is
6913hit. Then, in order to single-step and collect additional data
6914following the tracepoint, a @code{while-stepping} command is used,
6915followed by the list of things to be collected while stepping. The
6916@code{while-stepping} command is terminated by its own separate
6917@code{end} command. Lastly, the action list is terminated by an
6918@code{end} command.
6919
6920@smallexample
6921(@value{GDBP}) @b{trace foo}
6922(@value{GDBP}) @b{actions}
6923Enter actions for tracepoint 1, one per line:
6924> collect bar,baz
6925> collect $regs
6926> while-stepping 12
6927 > collect $fp, $sp
6928 > end
6929end
6930@end smallexample
6931
6932@kindex collect @r{(tracepoints)}
6933@item collect @var{expr1}, @var{expr2}, @dots{}
6934Collect values of the given expressions when the tracepoint is hit.
6935This command accepts a comma-separated list of any valid expressions.
6936In addition to global, static, or local variables, the following
6937special arguments are supported:
6938
6939@table @code
6940@item $regs
6941collect all registers
6942
6943@item $args
6944collect all function arguments
6945
6946@item $locals
6947collect all local variables.
6948@end table
6949
6950You can give several consecutive @code{collect} commands, each one
6951with a single argument, or one @code{collect} command with several
6952arguments separated by commas: the effect is the same.
6953
f5c37c66
EZ
6954The command @code{info scope} (@pxref{Symbols, info scope}) is
6955particularly useful for figuring out what data to collect.
6956
b37052ae
EZ
6957@kindex while-stepping @r{(tracepoints)}
6958@item while-stepping @var{n}
6959Perform @var{n} single-step traces after the tracepoint, collecting
6960new data at each step. The @code{while-stepping} command is
6961followed by the list of what to collect while stepping (followed by
6962its own @code{end} command):
6963
6964@smallexample
6965> while-stepping 12
6966 > collect $regs, myglobal
6967 > end
6968>
6969@end smallexample
6970
6971@noindent
6972You may abbreviate @code{while-stepping} as @code{ws} or
6973@code{stepping}.
6974@end table
6975
6976@node Listing Tracepoints
6977@subsection Listing Tracepoints
6978
6979@table @code
6980@kindex info tracepoints
6981@cindex information about tracepoints
6982@item info tracepoints @r{[}@var{num}@r{]}
8a037dd7 6983Display information about the tracepoint @var{num}. If you don't specify
798c8bc6 6984a tracepoint number, displays information about all the tracepoints
b37052ae
EZ
6985defined so far. For each tracepoint, the following information is
6986shown:
6987
6988@itemize @bullet
6989@item
6990its number
6991@item
6992whether it is enabled or disabled
6993@item
6994its address
6995@item
6996its passcount as given by the @code{passcount @var{n}} command
6997@item
6998its step count as given by the @code{while-stepping @var{n}} command
6999@item
7000where in the source files is the tracepoint set
7001@item
7002its action list as given by the @code{actions} command
7003@end itemize
7004
7005@smallexample
7006(@value{GDBP}) @b{info trace}
7007Num Enb Address PassC StepC What
70081 y 0x002117c4 0 0 <gdb_asm>
6826cf00
EZ
70092 y 0x0020dc64 0 0 in g_test at g_test.c:1375
70103 y 0x0020b1f4 0 0 in get_data at ../foo.c:41
b37052ae
EZ
7011(@value{GDBP})
7012@end smallexample
7013
7014@noindent
7015This command can be abbreviated @code{info tp}.
7016@end table
7017
7018@node Starting and Stopping Trace Experiment
7019@subsection Starting and Stopping Trace Experiment
7020
7021@table @code
7022@kindex tstart
7023@cindex start a new trace experiment
7024@cindex collected data discarded
7025@item tstart
7026This command takes no arguments. It starts the trace experiment, and
7027begins collecting data. This has the side effect of discarding all
7028the data collected in the trace buffer during the previous trace
7029experiment.
7030
7031@kindex tstop
7032@cindex stop a running trace experiment
7033@item tstop
7034This command takes no arguments. It ends the trace experiment, and
7035stops collecting data.
7036
68c71a2e 7037@strong{Note}: a trace experiment and data collection may stop
b37052ae
EZ
7038automatically if any tracepoint's passcount is reached
7039(@pxref{Tracepoint Passcounts}), or if the trace buffer becomes full.
7040
7041@kindex tstatus
7042@cindex status of trace data collection
7043@cindex trace experiment, status of
7044@item tstatus
7045This command displays the status of the current trace data
7046collection.
7047@end table
7048
7049Here is an example of the commands we described so far:
7050
7051@smallexample
7052(@value{GDBP}) @b{trace gdb_c_test}
7053(@value{GDBP}) @b{actions}
7054Enter actions for tracepoint #1, one per line.
7055> collect $regs,$locals,$args
7056> while-stepping 11
7057 > collect $regs
7058 > end
7059> end
7060(@value{GDBP}) @b{tstart}
7061 [time passes @dots{}]
7062(@value{GDBP}) @b{tstop}
7063@end smallexample
7064
7065
7066@node Analyze Collected Data
7067@section Using the collected data
7068
7069After the tracepoint experiment ends, you use @value{GDBN} commands
7070for examining the trace data. The basic idea is that each tracepoint
7071collects a trace @dfn{snapshot} every time it is hit and another
7072snapshot every time it single-steps. All these snapshots are
7073consecutively numbered from zero and go into a buffer, and you can
7074examine them later. The way you examine them is to @dfn{focus} on a
7075specific trace snapshot. When the remote stub is focused on a trace
7076snapshot, it will respond to all @value{GDBN} requests for memory and
7077registers by reading from the buffer which belongs to that snapshot,
7078rather than from @emph{real} memory or registers of the program being
7079debugged. This means that @strong{all} @value{GDBN} commands
7080(@code{print}, @code{info registers}, @code{backtrace}, etc.) will
7081behave as if we were currently debugging the program state as it was
7082when the tracepoint occurred. Any requests for data that are not in
7083the buffer will fail.
7084
7085@menu
7086* tfind:: How to select a trace snapshot
7087* tdump:: How to display all data for a snapshot
7088* save-tracepoints:: How to save tracepoints for a future run
7089@end menu
7090
7091@node tfind
7092@subsection @code{tfind @var{n}}
7093
7094@kindex tfind
7095@cindex select trace snapshot
7096@cindex find trace snapshot
7097The basic command for selecting a trace snapshot from the buffer is
7098@code{tfind @var{n}}, which finds trace snapshot number @var{n},
7099counting from zero. If no argument @var{n} is given, the next
7100snapshot is selected.
7101
7102Here are the various forms of using the @code{tfind} command.
7103
7104@table @code
7105@item tfind start
7106Find the first snapshot in the buffer. This is a synonym for
7107@code{tfind 0} (since 0 is the number of the first snapshot).
7108
7109@item tfind none
7110Stop debugging trace snapshots, resume @emph{live} debugging.
7111
7112@item tfind end
7113Same as @samp{tfind none}.
7114
7115@item tfind
7116No argument means find the next trace snapshot.
7117
7118@item tfind -
7119Find the previous trace snapshot before the current one. This permits
7120retracing earlier steps.
7121
7122@item tfind tracepoint @var{num}
7123Find the next snapshot associated with tracepoint @var{num}. Search
7124proceeds forward from the last examined trace snapshot. If no
7125argument @var{num} is given, it means find the next snapshot collected
7126for the same tracepoint as the current snapshot.
7127
7128@item tfind pc @var{addr}
7129Find the next snapshot associated with the value @var{addr} of the
7130program counter. Search proceeds forward from the last examined trace
7131snapshot. If no argument @var{addr} is given, it means find the next
7132snapshot with the same value of PC as the current snapshot.
7133
7134@item tfind outside @var{addr1}, @var{addr2}
7135Find the next snapshot whose PC is outside the given range of
7136addresses.
7137
7138@item tfind range @var{addr1}, @var{addr2}
7139Find the next snapshot whose PC is between @var{addr1} and
7140@var{addr2}. @c FIXME: Is the range inclusive or exclusive?
7141
7142@item tfind line @r{[}@var{file}:@r{]}@var{n}
7143Find the next snapshot associated with the source line @var{n}. If
7144the optional argument @var{file} is given, refer to line @var{n} in
7145that source file. Search proceeds forward from the last examined
7146trace snapshot. If no argument @var{n} is given, it means find the
7147next line other than the one currently being examined; thus saying
7148@code{tfind line} repeatedly can appear to have the same effect as
7149stepping from line to line in a @emph{live} debugging session.
7150@end table
7151
7152The default arguments for the @code{tfind} commands are specifically
7153designed to make it easy to scan through the trace buffer. For
7154instance, @code{tfind} with no argument selects the next trace
7155snapshot, and @code{tfind -} with no argument selects the previous
7156trace snapshot. So, by giving one @code{tfind} command, and then
7157simply hitting @key{RET} repeatedly you can examine all the trace
7158snapshots in order. Or, by saying @code{tfind -} and then hitting
7159@key{RET} repeatedly you can examine the snapshots in reverse order.
7160The @code{tfind line} command with no argument selects the snapshot
7161for the next source line executed. The @code{tfind pc} command with
7162no argument selects the next snapshot with the same program counter
7163(PC) as the current frame. The @code{tfind tracepoint} command with
7164no argument selects the next trace snapshot collected by the same
7165tracepoint as the current one.
7166
7167In addition to letting you scan through the trace buffer manually,
7168these commands make it easy to construct @value{GDBN} scripts that
7169scan through the trace buffer and print out whatever collected data
7170you are interested in. Thus, if we want to examine the PC, FP, and SP
7171registers from each trace frame in the buffer, we can say this:
7172
7173@smallexample
7174(@value{GDBP}) @b{tfind start}
7175(@value{GDBP}) @b{while ($trace_frame != -1)}
7176> printf "Frame %d, PC = %08X, SP = %08X, FP = %08X\n", \
7177 $trace_frame, $pc, $sp, $fp
7178> tfind
7179> end
7180
7181Frame 0, PC = 0020DC64, SP = 0030BF3C, FP = 0030BF44
7182Frame 1, PC = 0020DC6C, SP = 0030BF38, FP = 0030BF44
7183Frame 2, PC = 0020DC70, SP = 0030BF34, FP = 0030BF44
7184Frame 3, PC = 0020DC74, SP = 0030BF30, FP = 0030BF44
7185Frame 4, PC = 0020DC78, SP = 0030BF2C, FP = 0030BF44
7186Frame 5, PC = 0020DC7C, SP = 0030BF28, FP = 0030BF44
7187Frame 6, PC = 0020DC80, SP = 0030BF24, FP = 0030BF44
7188Frame 7, PC = 0020DC84, SP = 0030BF20, FP = 0030BF44
7189Frame 8, PC = 0020DC88, SP = 0030BF1C, FP = 0030BF44
7190Frame 9, PC = 0020DC8E, SP = 0030BF18, FP = 0030BF44
7191Frame 10, PC = 00203F6C, SP = 0030BE3C, FP = 0030BF14
7192@end smallexample
7193
7194Or, if we want to examine the variable @code{X} at each source line in
7195the buffer:
7196
7197@smallexample
7198(@value{GDBP}) @b{tfind start}
7199(@value{GDBP}) @b{while ($trace_frame != -1)}
7200> printf "Frame %d, X == %d\n", $trace_frame, X
7201> tfind line
7202> end
7203
7204Frame 0, X = 1
7205Frame 7, X = 2
7206Frame 13, X = 255
7207@end smallexample
7208
7209@node tdump
7210@subsection @code{tdump}
7211@kindex tdump
7212@cindex dump all data collected at tracepoint
7213@cindex tracepoint data, display
7214
7215This command takes no arguments. It prints all the data collected at
7216the current trace snapshot.
7217
7218@smallexample
7219(@value{GDBP}) @b{trace 444}
7220(@value{GDBP}) @b{actions}
7221Enter actions for tracepoint #2, one per line:
7222> collect $regs, $locals, $args, gdb_long_test
7223> end
7224
7225(@value{GDBP}) @b{tstart}
7226
7227(@value{GDBP}) @b{tfind line 444}
7228#0 gdb_test (p1=0x11, p2=0x22, p3=0x33, p4=0x44, p5=0x55, p6=0x66)
7229at gdb_test.c:444
7230444 printp( "%s: arguments = 0x%X 0x%X 0x%X 0x%X 0x%X 0x%X\n", )
7231
7232(@value{GDBP}) @b{tdump}
7233Data collected at tracepoint 2, trace frame 1:
7234d0 0xc4aa0085 -995491707
7235d1 0x18 24
7236d2 0x80 128
7237d3 0x33 51
7238d4 0x71aea3d 119204413
7239d5 0x22 34
7240d6 0xe0 224
7241d7 0x380035 3670069
7242a0 0x19e24a 1696330
7243a1 0x3000668 50333288
7244a2 0x100 256
7245a3 0x322000 3284992
7246a4 0x3000698 50333336
7247a5 0x1ad3cc 1758156
7248fp 0x30bf3c 0x30bf3c
7249sp 0x30bf34 0x30bf34
7250ps 0x0 0
7251pc 0x20b2c8 0x20b2c8
7252fpcontrol 0x0 0
7253fpstatus 0x0 0
7254fpiaddr 0x0 0
7255p = 0x20e5b4 "gdb-test"
7256p1 = (void *) 0x11
7257p2 = (void *) 0x22
7258p3 = (void *) 0x33
7259p4 = (void *) 0x44
7260p5 = (void *) 0x55
7261p6 = (void *) 0x66
7262gdb_long_test = 17 '\021'
7263
7264(@value{GDBP})
7265@end smallexample
7266
7267@node save-tracepoints
7268@subsection @code{save-tracepoints @var{filename}}
7269@kindex save-tracepoints
7270@cindex save tracepoints for future sessions
7271
7272This command saves all current tracepoint definitions together with
7273their actions and passcounts, into a file @file{@var{filename}}
7274suitable for use in a later debugging session. To read the saved
7275tracepoint definitions, use the @code{source} command (@pxref{Command
7276Files}).
7277
7278@node Tracepoint Variables
7279@section Convenience Variables for Tracepoints
7280@cindex tracepoint variables
7281@cindex convenience variables for tracepoints
7282
7283@table @code
7284@vindex $trace_frame
7285@item (int) $trace_frame
7286The current trace snapshot (a.k.a.@: @dfn{frame}) number, or -1 if no
7287snapshot is selected.
7288
7289@vindex $tracepoint
7290@item (int) $tracepoint
7291The tracepoint for the current trace snapshot.
7292
7293@vindex $trace_line
7294@item (int) $trace_line
7295The line number for the current trace snapshot.
7296
7297@vindex $trace_file
7298@item (char []) $trace_file
7299The source file for the current trace snapshot.
7300
7301@vindex $trace_func
7302@item (char []) $trace_func
7303The name of the function containing @code{$tracepoint}.
7304@end table
7305
7306Note: @code{$trace_file} is not suitable for use in @code{printf},
7307use @code{output} instead.
7308
7309Here's a simple example of using these convenience variables for
7310stepping through all the trace snapshots and printing some of their
7311data.
7312
7313@smallexample
7314(@value{GDBP}) @b{tfind start}
7315
7316(@value{GDBP}) @b{while $trace_frame != -1}
7317> output $trace_file
7318> printf ", line %d (tracepoint #%d)\n", $trace_line, $tracepoint
7319> tfind
7320> end
7321@end smallexample
7322
df0cd8c5
JB
7323@node Overlays
7324@chapter Debugging Programs That Use Overlays
7325@cindex overlays
7326
7327If your program is too large to fit completely in your target system's
7328memory, you can sometimes use @dfn{overlays} to work around this
7329problem. @value{GDBN} provides some support for debugging programs that
7330use overlays.
7331
7332@menu
7333* How Overlays Work:: A general explanation of overlays.
7334* Overlay Commands:: Managing overlays in @value{GDBN}.
7335* Automatic Overlay Debugging:: @value{GDBN} can find out which overlays are
7336 mapped by asking the inferior.
7337* Overlay Sample Program:: A sample program using overlays.
7338@end menu
7339
7340@node How Overlays Work
7341@section How Overlays Work
7342@cindex mapped overlays
7343@cindex unmapped overlays
7344@cindex load address, overlay's
7345@cindex mapped address
7346@cindex overlay area
7347
7348Suppose you have a computer whose instruction address space is only 64
7349kilobytes long, but which has much more memory which can be accessed by
7350other means: special instructions, segment registers, or memory
7351management hardware, for example. Suppose further that you want to
7352adapt a program which is larger than 64 kilobytes to run on this system.
7353
7354One solution is to identify modules of your program which are relatively
7355independent, and need not call each other directly; call these modules
7356@dfn{overlays}. Separate the overlays from the main program, and place
7357their machine code in the larger memory. Place your main program in
7358instruction memory, but leave at least enough space there to hold the
7359largest overlay as well.
7360
7361Now, to call a function located in an overlay, you must first copy that
7362overlay's machine code from the large memory into the space set aside
7363for it in the instruction memory, and then jump to its entry point
7364there.
7365
c928edc0
AC
7366@c NB: In the below the mapped area's size is greater or equal to the
7367@c size of all overlays. This is intentional to remind the developer
7368@c that overlays don't necessarily need to be the same size.
7369
474c8240 7370@smallexample
df0cd8c5 7371@group
c928edc0
AC
7372 Data Instruction Larger
7373Address Space Address Space Address Space
7374+-----------+ +-----------+ +-----------+
7375| | | | | |
7376+-----------+ +-----------+ +-----------+<-- overlay 1
7377| program | | main | .----| overlay 1 | load address
7378| variables | | program | | +-----------+
7379| and heap | | | | | |
7380+-----------+ | | | +-----------+<-- overlay 2
7381| | +-----------+ | | | load address
7382+-----------+ | | | .-| overlay 2 |
7383 | | | | | |
7384 mapped --->+-----------+ | | +-----------+
7385 address | | | | | |
7386 | overlay | <-' | | |
7387 | area | <---' +-----------+<-- overlay 3
7388 | | <---. | | load address
7389 +-----------+ `--| overlay 3 |
7390 | | | |
7391 +-----------+ | |
7392 +-----------+
7393 | |
7394 +-----------+
7395
7396 @anchor{A code overlay}A code overlay
df0cd8c5 7397@end group
474c8240 7398@end smallexample
df0cd8c5 7399
c928edc0
AC
7400The diagram (@pxref{A code overlay}) shows a system with separate data
7401and instruction address spaces. To map an overlay, the program copies
7402its code from the larger address space to the instruction address space.
7403Since the overlays shown here all use the same mapped address, only one
7404may be mapped at a time. For a system with a single address space for
7405data and instructions, the diagram would be similar, except that the
7406program variables and heap would share an address space with the main
7407program and the overlay area.
df0cd8c5
JB
7408
7409An overlay loaded into instruction memory and ready for use is called a
7410@dfn{mapped} overlay; its @dfn{mapped address} is its address in the
7411instruction memory. An overlay not present (or only partially present)
7412in instruction memory is called @dfn{unmapped}; its @dfn{load address}
7413is its address in the larger memory. The mapped address is also called
7414the @dfn{virtual memory address}, or @dfn{VMA}; the load address is also
7415called the @dfn{load memory address}, or @dfn{LMA}.
7416
7417Unfortunately, overlays are not a completely transparent way to adapt a
7418program to limited instruction memory. They introduce a new set of
7419global constraints you must keep in mind as you design your program:
7420
7421@itemize @bullet
7422
7423@item
7424Before calling or returning to a function in an overlay, your program
7425must make sure that overlay is actually mapped. Otherwise, the call or
7426return will transfer control to the right address, but in the wrong
7427overlay, and your program will probably crash.
7428
7429@item
7430If the process of mapping an overlay is expensive on your system, you
7431will need to choose your overlays carefully to minimize their effect on
7432your program's performance.
7433
7434@item
7435The executable file you load onto your system must contain each
7436overlay's instructions, appearing at the overlay's load address, not its
7437mapped address. However, each overlay's instructions must be relocated
7438and its symbols defined as if the overlay were at its mapped address.
7439You can use GNU linker scripts to specify different load and relocation
7440addresses for pieces of your program; see @ref{Overlay Description,,,
7441ld.info, Using ld: the GNU linker}.
7442
7443@item
7444The procedure for loading executable files onto your system must be able
7445to load their contents into the larger address space as well as the
7446instruction and data spaces.
7447
7448@end itemize
7449
7450The overlay system described above is rather simple, and could be
7451improved in many ways:
7452
7453@itemize @bullet
7454
7455@item
7456If your system has suitable bank switch registers or memory management
7457hardware, you could use those facilities to make an overlay's load area
7458contents simply appear at their mapped address in instruction space.
7459This would probably be faster than copying the overlay to its mapped
7460area in the usual way.
7461
7462@item
7463If your overlays are small enough, you could set aside more than one
7464overlay area, and have more than one overlay mapped at a time.
7465
7466@item
7467You can use overlays to manage data, as well as instructions. In
7468general, data overlays are even less transparent to your design than
7469code overlays: whereas code overlays only require care when you call or
7470return to functions, data overlays require care every time you access
7471the data. Also, if you change the contents of a data overlay, you
7472must copy its contents back out to its load address before you can copy a
7473different data overlay into the same mapped area.
7474
7475@end itemize
7476
7477
7478@node Overlay Commands
7479@section Overlay Commands
7480
7481To use @value{GDBN}'s overlay support, each overlay in your program must
7482correspond to a separate section of the executable file. The section's
7483virtual memory address and load memory address must be the overlay's
7484mapped and load addresses. Identifying overlays with sections allows
7485@value{GDBN} to determine the appropriate address of a function or
7486variable, depending on whether the overlay is mapped or not.
7487
7488@value{GDBN}'s overlay commands all start with the word @code{overlay};
7489you can abbreviate this as @code{ov} or @code{ovly}. The commands are:
7490
7491@table @code
7492@item overlay off
4644b6e3 7493@kindex overlay
df0cd8c5
JB
7494Disable @value{GDBN}'s overlay support. When overlay support is
7495disabled, @value{GDBN} assumes that all functions and variables are
7496always present at their mapped addresses. By default, @value{GDBN}'s
7497overlay support is disabled.
7498
7499@item overlay manual
df0cd8c5
JB
7500@cindex manual overlay debugging
7501Enable @dfn{manual} overlay debugging. In this mode, @value{GDBN}
7502relies on you to tell it which overlays are mapped, and which are not,
7503using the @code{overlay map-overlay} and @code{overlay unmap-overlay}
7504commands described below.
7505
7506@item overlay map-overlay @var{overlay}
7507@itemx overlay map @var{overlay}
df0cd8c5
JB
7508@cindex map an overlay
7509Tell @value{GDBN} that @var{overlay} is now mapped; @var{overlay} must
7510be the name of the object file section containing the overlay. When an
7511overlay is mapped, @value{GDBN} assumes it can find the overlay's
7512functions and variables at their mapped addresses. @value{GDBN} assumes
7513that any other overlays whose mapped ranges overlap that of
7514@var{overlay} are now unmapped.
7515
7516@item overlay unmap-overlay @var{overlay}
7517@itemx overlay unmap @var{overlay}
df0cd8c5
JB
7518@cindex unmap an overlay
7519Tell @value{GDBN} that @var{overlay} is no longer mapped; @var{overlay}
7520must be the name of the object file section containing the overlay.
7521When an overlay is unmapped, @value{GDBN} assumes it can find the
7522overlay's functions and variables at their load addresses.
7523
7524@item overlay auto
df0cd8c5
JB
7525Enable @dfn{automatic} overlay debugging. In this mode, @value{GDBN}
7526consults a data structure the overlay manager maintains in the inferior
7527to see which overlays are mapped. For details, see @ref{Automatic
7528Overlay Debugging}.
7529
7530@item overlay load-target
7531@itemx overlay load
df0cd8c5
JB
7532@cindex reloading the overlay table
7533Re-read the overlay table from the inferior. Normally, @value{GDBN}
7534re-reads the table @value{GDBN} automatically each time the inferior
7535stops, so this command should only be necessary if you have changed the
7536overlay mapping yourself using @value{GDBN}. This command is only
7537useful when using automatic overlay debugging.
7538
7539@item overlay list-overlays
7540@itemx overlay list
7541@cindex listing mapped overlays
7542Display a list of the overlays currently mapped, along with their mapped
7543addresses, load addresses, and sizes.
7544
7545@end table
7546
7547Normally, when @value{GDBN} prints a code address, it includes the name
7548of the function the address falls in:
7549
474c8240 7550@smallexample
f7dc1244 7551(@value{GDBP}) print main
df0cd8c5 7552$3 = @{int ()@} 0x11a0 <main>
474c8240 7553@end smallexample
df0cd8c5
JB
7554@noindent
7555When overlay debugging is enabled, @value{GDBN} recognizes code in
7556unmapped overlays, and prints the names of unmapped functions with
7557asterisks around them. For example, if @code{foo} is a function in an
7558unmapped overlay, @value{GDBN} prints it this way:
7559
474c8240 7560@smallexample
f7dc1244 7561(@value{GDBP}) overlay list
df0cd8c5 7562No sections are mapped.
f7dc1244 7563(@value{GDBP}) print foo
df0cd8c5 7564$5 = @{int (int)@} 0x100000 <*foo*>
474c8240 7565@end smallexample
df0cd8c5
JB
7566@noindent
7567When @code{foo}'s overlay is mapped, @value{GDBN} prints the function's
7568name normally:
7569
474c8240 7570@smallexample
f7dc1244 7571(@value{GDBP}) overlay list
b383017d 7572Section .ov.foo.text, loaded at 0x100000 - 0x100034,
df0cd8c5 7573 mapped at 0x1016 - 0x104a
f7dc1244 7574(@value{GDBP}) print foo
df0cd8c5 7575$6 = @{int (int)@} 0x1016 <foo>
474c8240 7576@end smallexample
df0cd8c5
JB
7577
7578When overlay debugging is enabled, @value{GDBN} can find the correct
7579address for functions and variables in an overlay, whether or not the
7580overlay is mapped. This allows most @value{GDBN} commands, like
7581@code{break} and @code{disassemble}, to work normally, even on unmapped
7582code. However, @value{GDBN}'s breakpoint support has some limitations:
7583
7584@itemize @bullet
7585@item
7586@cindex breakpoints in overlays
7587@cindex overlays, setting breakpoints in
7588You can set breakpoints in functions in unmapped overlays, as long as
7589@value{GDBN} can write to the overlay at its load address.
7590@item
7591@value{GDBN} can not set hardware or simulator-based breakpoints in
7592unmapped overlays. However, if you set a breakpoint at the end of your
7593overlay manager (and tell @value{GDBN} which overlays are now mapped, if
7594you are using manual overlay management), @value{GDBN} will re-set its
7595breakpoints properly.
7596@end itemize
7597
7598
7599@node Automatic Overlay Debugging
7600@section Automatic Overlay Debugging
7601@cindex automatic overlay debugging
7602
7603@value{GDBN} can automatically track which overlays are mapped and which
7604are not, given some simple co-operation from the overlay manager in the
7605inferior. If you enable automatic overlay debugging with the
7606@code{overlay auto} command (@pxref{Overlay Commands}), @value{GDBN}
7607looks in the inferior's memory for certain variables describing the
7608current state of the overlays.
7609
7610Here are the variables your overlay manager must define to support
7611@value{GDBN}'s automatic overlay debugging:
7612
7613@table @asis
7614
7615@item @code{_ovly_table}:
7616This variable must be an array of the following structures:
7617
474c8240 7618@smallexample
df0cd8c5
JB
7619struct
7620@{
7621 /* The overlay's mapped address. */
7622 unsigned long vma;
7623
7624 /* The size of the overlay, in bytes. */
7625 unsigned long size;
7626
7627 /* The overlay's load address. */
7628 unsigned long lma;
7629
7630 /* Non-zero if the overlay is currently mapped;
7631 zero otherwise. */
7632 unsigned long mapped;
7633@}
474c8240 7634@end smallexample
df0cd8c5
JB
7635
7636@item @code{_novlys}:
7637This variable must be a four-byte signed integer, holding the total
7638number of elements in @code{_ovly_table}.
7639
7640@end table
7641
7642To decide whether a particular overlay is mapped or not, @value{GDBN}
7643looks for an entry in @w{@code{_ovly_table}} whose @code{vma} and
7644@code{lma} members equal the VMA and LMA of the overlay's section in the
7645executable file. When @value{GDBN} finds a matching entry, it consults
7646the entry's @code{mapped} member to determine whether the overlay is
7647currently mapped.
7648
81d46470 7649In addition, your overlay manager may define a function called
def71bfa 7650@code{_ovly_debug_event}. If this function is defined, @value{GDBN}
81d46470
MS
7651will silently set a breakpoint there. If the overlay manager then
7652calls this function whenever it has changed the overlay table, this
7653will enable @value{GDBN} to accurately keep track of which overlays
7654are in program memory, and update any breakpoints that may be set
b383017d 7655in overlays. This will allow breakpoints to work even if the
81d46470
MS
7656overlays are kept in ROM or other non-writable memory while they
7657are not being executed.
df0cd8c5
JB
7658
7659@node Overlay Sample Program
7660@section Overlay Sample Program
7661@cindex overlay example program
7662
7663When linking a program which uses overlays, you must place the overlays
7664at their load addresses, while relocating them to run at their mapped
7665addresses. To do this, you must write a linker script (@pxref{Overlay
7666Description,,, ld.info, Using ld: the GNU linker}). Unfortunately,
7667since linker scripts are specific to a particular host system, target
7668architecture, and target memory layout, this manual cannot provide
7669portable sample code demonstrating @value{GDBN}'s overlay support.
7670
7671However, the @value{GDBN} source distribution does contain an overlaid
7672program, with linker scripts for a few systems, as part of its test
7673suite. The program consists of the following files from
7674@file{gdb/testsuite/gdb.base}:
7675
7676@table @file
7677@item overlays.c
7678The main program file.
7679@item ovlymgr.c
7680A simple overlay manager, used by @file{overlays.c}.
7681@item foo.c
7682@itemx bar.c
7683@itemx baz.c
7684@itemx grbx.c
7685Overlay modules, loaded and used by @file{overlays.c}.
7686@item d10v.ld
7687@itemx m32r.ld
7688Linker scripts for linking the test program on the @code{d10v-elf}
7689and @code{m32r-elf} targets.
7690@end table
7691
7692You can build the test program using the @code{d10v-elf} GCC
7693cross-compiler like this:
7694
474c8240 7695@smallexample
df0cd8c5
JB
7696$ d10v-elf-gcc -g -c overlays.c
7697$ d10v-elf-gcc -g -c ovlymgr.c
7698$ d10v-elf-gcc -g -c foo.c
7699$ d10v-elf-gcc -g -c bar.c
7700$ d10v-elf-gcc -g -c baz.c
7701$ d10v-elf-gcc -g -c grbx.c
7702$ d10v-elf-gcc -g overlays.o ovlymgr.o foo.o bar.o \
7703 baz.o grbx.o -Wl,-Td10v.ld -o overlays
474c8240 7704@end smallexample
df0cd8c5
JB
7705
7706The build process is identical for any other architecture, except that
7707you must substitute the appropriate compiler and linker script for the
7708target system for @code{d10v-elf-gcc} and @code{d10v.ld}.
7709
7710
6d2ebf8b 7711@node Languages
c906108c
SS
7712@chapter Using @value{GDBN} with Different Languages
7713@cindex languages
7714
c906108c
SS
7715Although programming languages generally have common aspects, they are
7716rarely expressed in the same manner. For instance, in ANSI C,
7717dereferencing a pointer @code{p} is accomplished by @code{*p}, but in
7718Modula-2, it is accomplished by @code{p^}. Values can also be
5d161b24 7719represented (and displayed) differently. Hex numbers in C appear as
c906108c 7720@samp{0x1ae}, while in Modula-2 they appear as @samp{1AEH}.
c906108c
SS
7721
7722@cindex working language
7723Language-specific information is built into @value{GDBN} for some languages,
7724allowing you to express operations like the above in your program's
7725native language, and allowing @value{GDBN} to output values in a manner
7726consistent with the syntax of your program's native language. The
7727language you use to build expressions is called the @dfn{working
7728language}.
7729
7730@menu
7731* Setting:: Switching between source languages
7732* Show:: Displaying the language
c906108c 7733* Checks:: Type and range checks
c906108c 7734* Support:: Supported languages
4e562065 7735* Unsupported languages:: Unsupported languages
c906108c
SS
7736@end menu
7737
6d2ebf8b 7738@node Setting
c906108c
SS
7739@section Switching between source languages
7740
7741There are two ways to control the working language---either have @value{GDBN}
7742set it automatically, or select it manually yourself. You can use the
7743@code{set language} command for either purpose. On startup, @value{GDBN}
7744defaults to setting the language automatically. The working language is
7745used to determine how expressions you type are interpreted, how values
7746are printed, etc.
7747
7748In addition to the working language, every source file that
7749@value{GDBN} knows about has its own working language. For some object
7750file formats, the compiler might indicate which language a particular
7751source file is in. However, most of the time @value{GDBN} infers the
7752language from the name of the file. The language of a source file
b37052ae 7753controls whether C@t{++} names are demangled---this way @code{backtrace} can
c906108c 7754show each frame appropriately for its own language. There is no way to
d4f3574e
SS
7755set the language of a source file from within @value{GDBN}, but you can
7756set the language associated with a filename extension. @xref{Show, ,
7757Displaying the language}.
c906108c
SS
7758
7759This is most commonly a problem when you use a program, such
5d161b24 7760as @code{cfront} or @code{f2c}, that generates C but is written in
c906108c
SS
7761another language. In that case, make the
7762program use @code{#line} directives in its C output; that way
7763@value{GDBN} will know the correct language of the source code of the original
7764program, and will display that source code, not the generated C code.
7765
7766@menu
7767* Filenames:: Filename extensions and languages.
7768* Manually:: Setting the working language manually
7769* Automatically:: Having @value{GDBN} infer the source language
7770@end menu
7771
6d2ebf8b 7772@node Filenames
c906108c
SS
7773@subsection List of filename extensions and languages
7774
7775If a source file name ends in one of the following extensions, then
7776@value{GDBN} infers that its language is the one indicated.
7777
7778@table @file
e07c999f
PH
7779@item .ada
7780@itemx .ads
7781@itemx .adb
7782@itemx .a
7783Ada source file.
c906108c
SS
7784
7785@item .c
7786C source file
7787
7788@item .C
7789@itemx .cc
7790@itemx .cp
7791@itemx .cpp
7792@itemx .cxx
7793@itemx .c++
b37052ae 7794C@t{++} source file
c906108c 7795
b37303ee
AF
7796@item .m
7797Objective-C source file
7798
c906108c
SS
7799@item .f
7800@itemx .F
7801Fortran source file
7802
c906108c
SS
7803@item .mod
7804Modula-2 source file
c906108c
SS
7805
7806@item .s
7807@itemx .S
7808Assembler source file. This actually behaves almost like C, but
7809@value{GDBN} does not skip over function prologues when stepping.
7810@end table
7811
7812In addition, you may set the language associated with a filename
7813extension. @xref{Show, , Displaying the language}.
7814
6d2ebf8b 7815@node Manually
c906108c
SS
7816@subsection Setting the working language
7817
7818If you allow @value{GDBN} to set the language automatically,
7819expressions are interpreted the same way in your debugging session and
7820your program.
7821
7822@kindex set language
7823If you wish, you may set the language manually. To do this, issue the
7824command @samp{set language @var{lang}}, where @var{lang} is the name of
5d161b24 7825a language, such as
c906108c 7826@code{c} or @code{modula-2}.
c906108c
SS
7827For a list of the supported languages, type @samp{set language}.
7828
c906108c
SS
7829Setting the language manually prevents @value{GDBN} from updating the working
7830language automatically. This can lead to confusion if you try
7831to debug a program when the working language is not the same as the
7832source language, when an expression is acceptable to both
7833languages---but means different things. For instance, if the current
7834source file were written in C, and @value{GDBN} was parsing Modula-2, a
7835command such as:
7836
474c8240 7837@smallexample
c906108c 7838print a = b + c
474c8240 7839@end smallexample
c906108c
SS
7840
7841@noindent
7842might not have the effect you intended. In C, this means to add
7843@code{b} and @code{c} and place the result in @code{a}. The result
7844printed would be the value of @code{a}. In Modula-2, this means to compare
7845@code{a} to the result of @code{b+c}, yielding a @code{BOOLEAN} value.
c906108c 7846
6d2ebf8b 7847@node Automatically
c906108c
SS
7848@subsection Having @value{GDBN} infer the source language
7849
7850To have @value{GDBN} set the working language automatically, use
7851@samp{set language local} or @samp{set language auto}. @value{GDBN}
7852then infers the working language. That is, when your program stops in a
7853frame (usually by encountering a breakpoint), @value{GDBN} sets the
7854working language to the language recorded for the function in that
7855frame. If the language for a frame is unknown (that is, if the function
7856or block corresponding to the frame was defined in a source file that
7857does not have a recognized extension), the current working language is
7858not changed, and @value{GDBN} issues a warning.
7859
7860This may not seem necessary for most programs, which are written
7861entirely in one source language. However, program modules and libraries
7862written in one source language can be used by a main program written in
7863a different source language. Using @samp{set language auto} in this
7864case frees you from having to set the working language manually.
7865
6d2ebf8b 7866@node Show
c906108c 7867@section Displaying the language
c906108c
SS
7868
7869The following commands help you find out which language is the
7870working language, and also what language source files were written in.
7871
7872@kindex show language
c906108c
SS
7873@table @code
7874@item show language
7875Display the current working language. This is the
7876language you can use with commands such as @code{print} to
7877build and compute expressions that may involve variables in your program.
7878
7879@item info frame
4644b6e3 7880@kindex info frame@r{, show the source language}
5d161b24 7881Display the source language for this frame. This language becomes the
c906108c 7882working language if you use an identifier from this frame.
5d161b24 7883@xref{Frame Info, ,Information about a frame}, to identify the other
c906108c
SS
7884information listed here.
7885
7886@item info source
4644b6e3 7887@kindex info source@r{, show the source language}
c906108c 7888Display the source language of this source file.
5d161b24 7889@xref{Symbols, ,Examining the Symbol Table}, to identify the other
c906108c
SS
7890information listed here.
7891@end table
7892
7893In unusual circumstances, you may have source files with extensions
7894not in the standard list. You can then set the extension associated
7895with a language explicitly:
7896
7897@kindex set extension-language
7898@kindex info extensions
7899@table @code
7900@item set extension-language @var{.ext} @var{language}
7901Set source files with extension @var{.ext} to be assumed to be in
7902the source language @var{language}.
7903
7904@item info extensions
7905List all the filename extensions and the associated languages.
7906@end table
7907
6d2ebf8b 7908@node Checks
c906108c
SS
7909@section Type and range checking
7910
7911@quotation
7912@emph{Warning:} In this release, the @value{GDBN} commands for type and range
7913checking are included, but they do not yet have any effect. This
7914section documents the intended facilities.
7915@end quotation
7916@c FIXME remove warning when type/range code added
7917
7918Some languages are designed to guard you against making seemingly common
7919errors through a series of compile- and run-time checks. These include
7920checking the type of arguments to functions and operators, and making
7921sure mathematical overflows are caught at run time. Checks such as
7922these help to ensure a program's correctness once it has been compiled
7923by eliminating type mismatches, and providing active checks for range
7924errors when your program is running.
7925
7926@value{GDBN} can check for conditions like the above if you wish.
7927Although @value{GDBN} does not check the statements in your program, it
7928can check expressions entered directly into @value{GDBN} for evaluation via
7929the @code{print} command, for example. As with the working language,
7930@value{GDBN} can also decide whether or not to check automatically based on
7931your program's source language. @xref{Support, ,Supported languages},
7932for the default settings of supported languages.
7933
7934@menu
7935* Type Checking:: An overview of type checking
7936* Range Checking:: An overview of range checking
7937@end menu
7938
7939@cindex type checking
7940@cindex checks, type
6d2ebf8b 7941@node Type Checking
c906108c
SS
7942@subsection An overview of type checking
7943
7944Some languages, such as Modula-2, are strongly typed, meaning that the
7945arguments to operators and functions have to be of the correct type,
7946otherwise an error occurs. These checks prevent type mismatch
7947errors from ever causing any run-time problems. For example,
7948
7949@smallexample
79501 + 2 @result{} 3
7951@exdent but
7952@error{} 1 + 2.3
7953@end smallexample
7954
7955The second example fails because the @code{CARDINAL} 1 is not
7956type-compatible with the @code{REAL} 2.3.
7957
5d161b24
DB
7958For the expressions you use in @value{GDBN} commands, you can tell the
7959@value{GDBN} type checker to skip checking;
7960to treat any mismatches as errors and abandon the expression;
7961or to only issue warnings when type mismatches occur,
c906108c
SS
7962but evaluate the expression anyway. When you choose the last of
7963these, @value{GDBN} evaluates expressions like the second example above, but
7964also issues a warning.
7965
5d161b24
DB
7966Even if you turn type checking off, there may be other reasons
7967related to type that prevent @value{GDBN} from evaluating an expression.
7968For instance, @value{GDBN} does not know how to add an @code{int} and
7969a @code{struct foo}. These particular type errors have nothing to do
7970with the language in use, and usually arise from expressions, such as
c906108c
SS
7971the one described above, which make little sense to evaluate anyway.
7972
7973Each language defines to what degree it is strict about type. For
7974instance, both Modula-2 and C require the arguments to arithmetical
7975operators to be numbers. In C, enumerated types and pointers can be
7976represented as numbers, so that they are valid arguments to mathematical
7977operators. @xref{Support, ,Supported languages}, for further
7978details on specific languages.
7979
7980@value{GDBN} provides some additional commands for controlling the type checker:
7981
c906108c
SS
7982@kindex set check type
7983@kindex show check type
7984@table @code
7985@item set check type auto
7986Set type checking on or off based on the current working language.
7987@xref{Support, ,Supported languages}, for the default settings for
7988each language.
7989
7990@item set check type on
7991@itemx set check type off
7992Set type checking on or off, overriding the default setting for the
7993current working language. Issue a warning if the setting does not
7994match the language default. If any type mismatches occur in
d4f3574e 7995evaluating an expression while type checking is on, @value{GDBN} prints a
c906108c
SS
7996message and aborts evaluation of the expression.
7997
7998@item set check type warn
7999Cause the type checker to issue warnings, but to always attempt to
8000evaluate the expression. Evaluating the expression may still
8001be impossible for other reasons. For example, @value{GDBN} cannot add
8002numbers and structures.
8003
8004@item show type
5d161b24 8005Show the current setting of the type checker, and whether or not @value{GDBN}
c906108c
SS
8006is setting it automatically.
8007@end table
8008
8009@cindex range checking
8010@cindex checks, range
6d2ebf8b 8011@node Range Checking
c906108c
SS
8012@subsection An overview of range checking
8013
8014In some languages (such as Modula-2), it is an error to exceed the
8015bounds of a type; this is enforced with run-time checks. Such range
8016checking is meant to ensure program correctness by making sure
8017computations do not overflow, or indices on an array element access do
8018not exceed the bounds of the array.
8019
8020For expressions you use in @value{GDBN} commands, you can tell
8021@value{GDBN} to treat range errors in one of three ways: ignore them,
8022always treat them as errors and abandon the expression, or issue
8023warnings but evaluate the expression anyway.
8024
8025A range error can result from numerical overflow, from exceeding an
8026array index bound, or when you type a constant that is not a member
8027of any type. Some languages, however, do not treat overflows as an
8028error. In many implementations of C, mathematical overflow causes the
8029result to ``wrap around'' to lower values---for example, if @var{m} is
8030the largest integer value, and @var{s} is the smallest, then
8031
474c8240 8032@smallexample
c906108c 8033@var{m} + 1 @result{} @var{s}
474c8240 8034@end smallexample
c906108c
SS
8035
8036This, too, is specific to individual languages, and in some cases
8037specific to individual compilers or machines. @xref{Support, ,
8038Supported languages}, for further details on specific languages.
8039
8040@value{GDBN} provides some additional commands for controlling the range checker:
8041
c906108c
SS
8042@kindex set check range
8043@kindex show check range
8044@table @code
8045@item set check range auto
8046Set range checking on or off based on the current working language.
8047@xref{Support, ,Supported languages}, for the default settings for
8048each language.
8049
8050@item set check range on
8051@itemx set check range off
8052Set range checking on or off, overriding the default setting for the
8053current working language. A warning is issued if the setting does not
c3f6f71d
JM
8054match the language default. If a range error occurs and range checking is on,
8055then a message is printed and evaluation of the expression is aborted.
c906108c
SS
8056
8057@item set check range warn
8058Output messages when the @value{GDBN} range checker detects a range error,
8059but attempt to evaluate the expression anyway. Evaluating the
8060expression may still be impossible for other reasons, such as accessing
8061memory that the process does not own (a typical example from many Unix
8062systems).
8063
8064@item show range
8065Show the current setting of the range checker, and whether or not it is
8066being set automatically by @value{GDBN}.
8067@end table
c906108c 8068
6d2ebf8b 8069@node Support
c906108c 8070@section Supported languages
c906108c 8071
e07c999f 8072@value{GDBN} supports C, C@t{++}, Objective-C, Fortran, Java, assembly, Modula-2, and Ada.
cce74817 8073@c This is false ...
c906108c
SS
8074Some @value{GDBN} features may be used in expressions regardless of the
8075language you use: the @value{GDBN} @code{@@} and @code{::} operators,
8076and the @samp{@{type@}addr} construct (@pxref{Expressions,
8077,Expressions}) can be used with the constructs of any supported
8078language.
8079
8080The following sections detail to what degree each source language is
8081supported by @value{GDBN}. These sections are not meant to be language
8082tutorials or references, but serve only as a reference guide to what the
8083@value{GDBN} expression parser accepts, and what input and output
8084formats should look like for different languages. There are many good
8085books written on each of these languages; please look to these for a
8086language reference or tutorial.
8087
c906108c 8088@menu
b37303ee 8089* C:: C and C@t{++}
b383017d 8090* Objective-C:: Objective-C
b37303ee 8091* Modula-2:: Modula-2
e07c999f 8092* Ada:: Ada
c906108c
SS
8093@end menu
8094
6d2ebf8b 8095@node C
b37052ae 8096@subsection C and C@t{++}
7a292a7a 8097
b37052ae
EZ
8098@cindex C and C@t{++}
8099@cindex expressions in C or C@t{++}
c906108c 8100
b37052ae 8101Since C and C@t{++} are so closely related, many features of @value{GDBN} apply
c906108c
SS
8102to both languages. Whenever this is the case, we discuss those languages
8103together.
8104
41afff9a
EZ
8105@cindex C@t{++}
8106@cindex @code{g++}, @sc{gnu} C@t{++} compiler
b37052ae
EZ
8107@cindex @sc{gnu} C@t{++}
8108The C@t{++} debugging facilities are jointly implemented by the C@t{++}
8109compiler and @value{GDBN}. Therefore, to debug your C@t{++} code
8110effectively, you must compile your C@t{++} programs with a supported
8111C@t{++} compiler, such as @sc{gnu} @code{g++}, or the HP ANSI C@t{++}
c906108c
SS
8112compiler (@code{aCC}).
8113
0179ffac
DC
8114For best results when using @sc{gnu} C@t{++}, use the DWARF 2 debugging
8115format; if it doesn't work on your system, try the stabs+ debugging
8116format. You can select those formats explicitly with the @code{g++}
8117command-line options @option{-gdwarf-2} and @option{-gstabs+}.
8118@xref{Debugging Options,,Options for Debugging Your Program or @sc{gnu}
8119CC, gcc.info, Using @sc{gnu} CC}.
c906108c 8120
c906108c 8121@menu
b37052ae
EZ
8122* C Operators:: C and C@t{++} operators
8123* C Constants:: C and C@t{++} constants
8124* C plus plus expressions:: C@t{++} expressions
8125* C Defaults:: Default settings for C and C@t{++}
8126* C Checks:: C and C@t{++} type and range checks
c906108c 8127* Debugging C:: @value{GDBN} and C
b37052ae 8128* Debugging C plus plus:: @value{GDBN} features for C@t{++}
c906108c 8129@end menu
c906108c 8130
6d2ebf8b 8131@node C Operators
b37052ae 8132@subsubsection C and C@t{++} operators
7a292a7a 8133
b37052ae 8134@cindex C and C@t{++} operators
c906108c
SS
8135
8136Operators must be defined on values of specific types. For instance,
8137@code{+} is defined on numbers, but not on structures. Operators are
5d161b24 8138often defined on groups of types.
c906108c 8139
b37052ae 8140For the purposes of C and C@t{++}, the following definitions hold:
c906108c
SS
8141
8142@itemize @bullet
53a5351d 8143
c906108c 8144@item
c906108c 8145@emph{Integral types} include @code{int} with any of its storage-class
b37052ae 8146specifiers; @code{char}; @code{enum}; and, for C@t{++}, @code{bool}.
c906108c
SS
8147
8148@item
d4f3574e
SS
8149@emph{Floating-point types} include @code{float}, @code{double}, and
8150@code{long double} (if supported by the target platform).
c906108c
SS
8151
8152@item
53a5351d 8153@emph{Pointer types} include all types defined as @code{(@var{type} *)}.
c906108c
SS
8154
8155@item
8156@emph{Scalar types} include all of the above.
53a5351d 8157
c906108c
SS
8158@end itemize
8159
8160@noindent
8161The following operators are supported. They are listed here
8162in order of increasing precedence:
8163
8164@table @code
8165@item ,
8166The comma or sequencing operator. Expressions in a comma-separated list
8167are evaluated from left to right, with the result of the entire
8168expression being the last expression evaluated.
8169
8170@item =
8171Assignment. The value of an assignment expression is the value
8172assigned. Defined on scalar types.
8173
8174@item @var{op}=
8175Used in an expression of the form @w{@code{@var{a} @var{op}= @var{b}}},
8176and translated to @w{@code{@var{a} = @var{a op b}}}.
d4f3574e 8177@w{@code{@var{op}=}} and @code{=} have the same precedence.
c906108c
SS
8178@var{op} is any one of the operators @code{|}, @code{^}, @code{&},
8179@code{<<}, @code{>>}, @code{+}, @code{-}, @code{*}, @code{/}, @code{%}.
8180
8181@item ?:
8182The ternary operator. @code{@var{a} ? @var{b} : @var{c}} can be thought
8183of as: if @var{a} then @var{b} else @var{c}. @var{a} should be of an
8184integral type.
8185
8186@item ||
8187Logical @sc{or}. Defined on integral types.
8188
8189@item &&
8190Logical @sc{and}. Defined on integral types.
8191
8192@item |
8193Bitwise @sc{or}. Defined on integral types.
8194
8195@item ^
8196Bitwise exclusive-@sc{or}. Defined on integral types.
8197
8198@item &
8199Bitwise @sc{and}. Defined on integral types.
8200
8201@item ==@r{, }!=
8202Equality and inequality. Defined on scalar types. The value of these
8203expressions is 0 for false and non-zero for true.
8204
8205@item <@r{, }>@r{, }<=@r{, }>=
8206Less than, greater than, less than or equal, greater than or equal.
8207Defined on scalar types. The value of these expressions is 0 for false
8208and non-zero for true.
8209
8210@item <<@r{, }>>
8211left shift, and right shift. Defined on integral types.
8212
8213@item @@
8214The @value{GDBN} ``artificial array'' operator (@pxref{Expressions, ,Expressions}).
8215
8216@item +@r{, }-
8217Addition and subtraction. Defined on integral types, floating-point types and
8218pointer types.
8219
8220@item *@r{, }/@r{, }%
8221Multiplication, division, and modulus. Multiplication and division are
8222defined on integral and floating-point types. Modulus is defined on
8223integral types.
8224
8225@item ++@r{, }--
8226Increment and decrement. When appearing before a variable, the
8227operation is performed before the variable is used in an expression;
8228when appearing after it, the variable's value is used before the
8229operation takes place.
8230
8231@item *
8232Pointer dereferencing. Defined on pointer types. Same precedence as
8233@code{++}.
8234
8235@item &
8236Address operator. Defined on variables. Same precedence as @code{++}.
8237
b37052ae
EZ
8238For debugging C@t{++}, @value{GDBN} implements a use of @samp{&} beyond what is
8239allowed in the C@t{++} language itself: you can use @samp{&(&@var{ref})}
c906108c 8240(or, if you prefer, simply @samp{&&@var{ref}}) to examine the address
b37052ae 8241where a C@t{++} reference variable (declared with @samp{&@var{ref}}) is
c906108c 8242stored.
c906108c
SS
8243
8244@item -
8245Negative. Defined on integral and floating-point types. Same
8246precedence as @code{++}.
8247
8248@item !
8249Logical negation. Defined on integral types. Same precedence as
8250@code{++}.
8251
8252@item ~
8253Bitwise complement operator. Defined on integral types. Same precedence as
8254@code{++}.
8255
8256
8257@item .@r{, }->
8258Structure member, and pointer-to-structure member. For convenience,
8259@value{GDBN} regards the two as equivalent, choosing whether to dereference a
8260pointer based on the stored type information.
8261Defined on @code{struct} and @code{union} data.
8262
c906108c
SS
8263@item .*@r{, }->*
8264Dereferences of pointers to members.
c906108c
SS
8265
8266@item []
8267Array indexing. @code{@var{a}[@var{i}]} is defined as
8268@code{*(@var{a}+@var{i})}. Same precedence as @code{->}.
8269
8270@item ()
8271Function parameter list. Same precedence as @code{->}.
8272
c906108c 8273@item ::
b37052ae 8274C@t{++} scope resolution operator. Defined on @code{struct}, @code{union},
7a292a7a 8275and @code{class} types.
c906108c
SS
8276
8277@item ::
7a292a7a
SS
8278Doubled colons also represent the @value{GDBN} scope operator
8279(@pxref{Expressions, ,Expressions}). Same precedence as @code{::},
8280above.
c906108c
SS
8281@end table
8282
c906108c
SS
8283If an operator is redefined in the user code, @value{GDBN} usually
8284attempts to invoke the redefined version instead of using the operator's
8285predefined meaning.
c906108c 8286
c906108c 8287@menu
5d161b24 8288* C Constants::
c906108c
SS
8289@end menu
8290
6d2ebf8b 8291@node C Constants
b37052ae 8292@subsubsection C and C@t{++} constants
c906108c 8293
b37052ae 8294@cindex C and C@t{++} constants
c906108c 8295
b37052ae 8296@value{GDBN} allows you to express the constants of C and C@t{++} in the
c906108c 8297following ways:
c906108c
SS
8298
8299@itemize @bullet
8300@item
8301Integer constants are a sequence of digits. Octal constants are
6ca652b0
EZ
8302specified by a leading @samp{0} (i.e.@: zero), and hexadecimal constants
8303by a leading @samp{0x} or @samp{0X}. Constants may also end with a letter
c906108c
SS
8304@samp{l}, specifying that the constant should be treated as a
8305@code{long} value.
8306
8307@item
8308Floating point constants are a sequence of digits, followed by a decimal
8309point, followed by a sequence of digits, and optionally followed by an
8310exponent. An exponent is of the form:
8311@samp{@w{e@r{[[}+@r{]|}-@r{]}@var{nnn}}}, where @var{nnn} is another
8312sequence of digits. The @samp{+} is optional for positive exponents.
d4f3574e
SS
8313A floating-point constant may also end with a letter @samp{f} or
8314@samp{F}, specifying that the constant should be treated as being of
8315the @code{float} (as opposed to the default @code{double}) type; or with
8316a letter @samp{l} or @samp{L}, which specifies a @code{long double}
8317constant.
c906108c
SS
8318
8319@item
8320Enumerated constants consist of enumerated identifiers, or their
8321integral equivalents.
8322
8323@item
8324Character constants are a single character surrounded by single quotes
8325(@code{'}), or a number---the ordinal value of the corresponding character
d4f3574e 8326(usually its @sc{ascii} value). Within quotes, the single character may
c906108c
SS
8327be represented by a letter or by @dfn{escape sequences}, which are of
8328the form @samp{\@var{nnn}}, where @var{nnn} is the octal representation
8329of the character's ordinal value; or of the form @samp{\@var{x}}, where
8330@samp{@var{x}} is a predefined special character---for example,
8331@samp{\n} for newline.
8332
8333@item
96a2c332
SS
8334String constants are a sequence of character constants surrounded by
8335double quotes (@code{"}). Any valid character constant (as described
8336above) may appear. Double quotes within the string must be preceded by
8337a backslash, so for instance @samp{"a\"b'c"} is a string of five
8338characters.
c906108c
SS
8339
8340@item
8341Pointer constants are an integral value. You can also write pointers
8342to constants using the C operator @samp{&}.
8343
8344@item
8345Array constants are comma-separated lists surrounded by braces @samp{@{}
8346and @samp{@}}; for example, @samp{@{1,2,3@}} is a three-element array of
8347integers, @samp{@{@{1,2@}, @{3,4@}, @{5,6@}@}} is a three-by-two array,
8348and @samp{@{&"hi", &"there", &"fred"@}} is a three-element array of pointers.
8349@end itemize
8350
c906108c 8351@menu
5d161b24
DB
8352* C plus plus expressions::
8353* C Defaults::
8354* C Checks::
c906108c 8355
5d161b24 8356* Debugging C::
c906108c
SS
8357@end menu
8358
6d2ebf8b 8359@node C plus plus expressions
b37052ae
EZ
8360@subsubsection C@t{++} expressions
8361
8362@cindex expressions in C@t{++}
8363@value{GDBN} expression handling can interpret most C@t{++} expressions.
8364
0179ffac
DC
8365@cindex debugging C@t{++} programs
8366@cindex C@t{++} compilers
8367@cindex debug formats and C@t{++}
8368@cindex @value{NGCC} and C@t{++}
c906108c 8369@quotation
b37052ae 8370@emph{Warning:} @value{GDBN} can only debug C@t{++} code if you use the
0179ffac
DC
8371proper compiler and the proper debug format. Currently, @value{GDBN}
8372works best when debugging C@t{++} code that is compiled with
8373@value{NGCC} 2.95.3 or with @value{NGCC} 3.1 or newer, using the options
8374@option{-gdwarf-2} or @option{-gstabs+}. DWARF 2 is preferred over
8375stabs+. Most configurations of @value{NGCC} emit either DWARF 2 or
8376stabs+ as their default debug format, so you usually don't need to
8377specify a debug format explicitly. Other compilers and/or debug formats
8378are likely to work badly or not at all when using @value{GDBN} to debug
8379C@t{++} code.
c906108c 8380@end quotation
c906108c
SS
8381
8382@enumerate
8383
8384@cindex member functions
8385@item
8386Member function calls are allowed; you can use expressions like
8387
474c8240 8388@smallexample
c906108c 8389count = aml->GetOriginal(x, y)
474c8240 8390@end smallexample
c906108c 8391
41afff9a 8392@vindex this@r{, inside C@t{++} member functions}
b37052ae 8393@cindex namespace in C@t{++}
c906108c
SS
8394@item
8395While a member function is active (in the selected stack frame), your
8396expressions have the same namespace available as the member function;
8397that is, @value{GDBN} allows implicit references to the class instance
b37052ae 8398pointer @code{this} following the same rules as C@t{++}.
c906108c 8399
c906108c 8400@cindex call overloaded functions
d4f3574e 8401@cindex overloaded functions, calling
b37052ae 8402@cindex type conversions in C@t{++}
c906108c
SS
8403@item
8404You can call overloaded functions; @value{GDBN} resolves the function
d4f3574e 8405call to the right definition, with some restrictions. @value{GDBN} does not
c906108c
SS
8406perform overload resolution involving user-defined type conversions,
8407calls to constructors, or instantiations of templates that do not exist
8408in the program. It also cannot handle ellipsis argument lists or
8409default arguments.
8410
8411It does perform integral conversions and promotions, floating-point
8412promotions, arithmetic conversions, pointer conversions, conversions of
8413class objects to base classes, and standard conversions such as those of
8414functions or arrays to pointers; it requires an exact match on the
8415number of function arguments.
8416
8417Overload resolution is always performed, unless you have specified
8418@code{set overload-resolution off}. @xref{Debugging C plus plus,
b37052ae 8419,@value{GDBN} features for C@t{++}}.
c906108c 8420
d4f3574e 8421You must specify @code{set overload-resolution off} in order to use an
c906108c
SS
8422explicit function signature to call an overloaded function, as in
8423@smallexample
8424p 'foo(char,int)'('x', 13)
8425@end smallexample
d4f3574e 8426
c906108c 8427The @value{GDBN} command-completion facility can simplify this;
d4f3574e 8428see @ref{Completion, ,Command completion}.
c906108c 8429
c906108c
SS
8430@cindex reference declarations
8431@item
b37052ae
EZ
8432@value{GDBN} understands variables declared as C@t{++} references; you can use
8433them in expressions just as you do in C@t{++} source---they are automatically
c906108c
SS
8434dereferenced.
8435
8436In the parameter list shown when @value{GDBN} displays a frame, the values of
8437reference variables are not displayed (unlike other variables); this
8438avoids clutter, since references are often used for large structures.
8439The @emph{address} of a reference variable is always shown, unless
8440you have specified @samp{set print address off}.
8441
8442@item
b37052ae 8443@value{GDBN} supports the C@t{++} name resolution operator @code{::}---your
c906108c
SS
8444expressions can use it just as expressions in your program do. Since
8445one scope may be defined in another, you can use @code{::} repeatedly if
8446necessary, for example in an expression like
8447@samp{@var{scope1}::@var{scope2}::@var{name}}. @value{GDBN} also allows
b37052ae 8448resolving name scope by reference to source files, in both C and C@t{++}
c906108c
SS
8449debugging (@pxref{Variables, ,Program variables}).
8450@end enumerate
8451
b37052ae 8452In addition, when used with HP's C@t{++} compiler, @value{GDBN} supports
53a5351d
JM
8453calling virtual functions correctly, printing out virtual bases of
8454objects, calling functions in a base subobject, casting objects, and
8455invoking user-defined operators.
c906108c 8456
6d2ebf8b 8457@node C Defaults
b37052ae 8458@subsubsection C and C@t{++} defaults
7a292a7a 8459
b37052ae 8460@cindex C and C@t{++} defaults
c906108c 8461
c906108c
SS
8462If you allow @value{GDBN} to set type and range checking automatically, they
8463both default to @code{off} whenever the working language changes to
b37052ae 8464C or C@t{++}. This happens regardless of whether you or @value{GDBN}
c906108c 8465selects the working language.
c906108c
SS
8466
8467If you allow @value{GDBN} to set the language automatically, it
8468recognizes source files whose names end with @file{.c}, @file{.C}, or
8469@file{.cc}, etc, and when @value{GDBN} enters code compiled from one of
b37052ae 8470these files, it sets the working language to C or C@t{++}.
c906108c
SS
8471@xref{Automatically, ,Having @value{GDBN} infer the source language},
8472for further details.
8473
c906108c
SS
8474@c Type checking is (a) primarily motivated by Modula-2, and (b)
8475@c unimplemented. If (b) changes, it might make sense to let this node
8476@c appear even if Mod-2 does not, but meanwhile ignore it. roland 16jul93.
7a292a7a 8477
6d2ebf8b 8478@node C Checks
b37052ae 8479@subsubsection C and C@t{++} type and range checks
7a292a7a 8480
b37052ae 8481@cindex C and C@t{++} checks
c906108c 8482
b37052ae 8483By default, when @value{GDBN} parses C or C@t{++} expressions, type checking
c906108c
SS
8484is not used. However, if you turn type checking on, @value{GDBN}
8485considers two variables type equivalent if:
8486
8487@itemize @bullet
8488@item
8489The two variables are structured and have the same structure, union, or
8490enumerated tag.
8491
8492@item
8493The two variables have the same type name, or types that have been
8494declared equivalent through @code{typedef}.
8495
8496@ignore
8497@c leaving this out because neither J Gilmore nor R Pesch understand it.
8498@c FIXME--beers?
8499@item
8500The two @code{struct}, @code{union}, or @code{enum} variables are
8501declared in the same declaration. (Note: this may not be true for all C
8502compilers.)
8503@end ignore
8504@end itemize
8505
8506Range checking, if turned on, is done on mathematical operations. Array
8507indices are not checked, since they are often used to index a pointer
8508that is not itself an array.
c906108c 8509
6d2ebf8b 8510@node Debugging C
c906108c 8511@subsubsection @value{GDBN} and C
c906108c
SS
8512
8513The @code{set print union} and @code{show print union} commands apply to
8514the @code{union} type. When set to @samp{on}, any @code{union} that is
7a292a7a
SS
8515inside a @code{struct} or @code{class} is also printed. Otherwise, it
8516appears as @samp{@{...@}}.
c906108c
SS
8517
8518The @code{@@} operator aids in the debugging of dynamic arrays, formed
8519with pointers and a memory allocation function. @xref{Expressions,
8520,Expressions}.
8521
c906108c 8522@menu
5d161b24 8523* Debugging C plus plus::
c906108c
SS
8524@end menu
8525
6d2ebf8b 8526@node Debugging C plus plus
b37052ae 8527@subsubsection @value{GDBN} features for C@t{++}
c906108c 8528
b37052ae 8529@cindex commands for C@t{++}
7a292a7a 8530
b37052ae
EZ
8531Some @value{GDBN} commands are particularly useful with C@t{++}, and some are
8532designed specifically for use with C@t{++}. Here is a summary:
c906108c
SS
8533
8534@table @code
8535@cindex break in overloaded functions
8536@item @r{breakpoint menus}
8537When you want a breakpoint in a function whose name is overloaded,
8538@value{GDBN} breakpoint menus help you specify which function definition
8539you want. @xref{Breakpoint Menus,,Breakpoint menus}.
8540
b37052ae 8541@cindex overloading in C@t{++}
c906108c
SS
8542@item rbreak @var{regex}
8543Setting breakpoints using regular expressions is helpful for setting
8544breakpoints on overloaded functions that are not members of any special
8545classes.
8546@xref{Set Breaks, ,Setting breakpoints}.
8547
b37052ae 8548@cindex C@t{++} exception handling
c906108c
SS
8549@item catch throw
8550@itemx catch catch
b37052ae 8551Debug C@t{++} exception handling using these commands. @xref{Set
c906108c
SS
8552Catchpoints, , Setting catchpoints}.
8553
8554@cindex inheritance
8555@item ptype @var{typename}
8556Print inheritance relationships as well as other information for type
8557@var{typename}.
8558@xref{Symbols, ,Examining the Symbol Table}.
8559
b37052ae 8560@cindex C@t{++} symbol display
c906108c
SS
8561@item set print demangle
8562@itemx show print demangle
8563@itemx set print asm-demangle
8564@itemx show print asm-demangle
b37052ae
EZ
8565Control whether C@t{++} symbols display in their source form, both when
8566displaying code as C@t{++} source and when displaying disassemblies.
c906108c
SS
8567@xref{Print Settings, ,Print settings}.
8568
8569@item set print object
8570@itemx show print object
8571Choose whether to print derived (actual) or declared types of objects.
8572@xref{Print Settings, ,Print settings}.
8573
8574@item set print vtbl
8575@itemx show print vtbl
8576Control the format for printing virtual function tables.
8577@xref{Print Settings, ,Print settings}.
c906108c 8578(The @code{vtbl} commands do not work on programs compiled with the HP
b37052ae 8579ANSI C@t{++} compiler (@code{aCC}).)
c906108c
SS
8580
8581@kindex set overload-resolution
d4f3574e 8582@cindex overloaded functions, overload resolution
c906108c 8583@item set overload-resolution on
b37052ae 8584Enable overload resolution for C@t{++} expression evaluation. The default
c906108c
SS
8585is on. For overloaded functions, @value{GDBN} evaluates the arguments
8586and searches for a function whose signature matches the argument types,
b37052ae 8587using the standard C@t{++} conversion rules (see @ref{C plus plus expressions, ,C@t{++}
d4f3574e 8588expressions}, for details). If it cannot find a match, it emits a
c906108c
SS
8589message.
8590
8591@item set overload-resolution off
b37052ae 8592Disable overload resolution for C@t{++} expression evaluation. For
c906108c
SS
8593overloaded functions that are not class member functions, @value{GDBN}
8594chooses the first function of the specified name that it finds in the
8595symbol table, whether or not its arguments are of the correct type. For
8596overloaded functions that are class member functions, @value{GDBN}
8597searches for a function whose signature @emph{exactly} matches the
8598argument types.
c906108c
SS
8599
8600@item @r{Overloaded symbol names}
8601You can specify a particular definition of an overloaded symbol, using
b37052ae 8602the same notation that is used to declare such symbols in C@t{++}: type
c906108c
SS
8603@code{@var{symbol}(@var{types})} rather than just @var{symbol}. You can
8604also use the @value{GDBN} command-line word completion facilities to list the
8605available choices, or to finish the type list for you.
8606@xref{Completion,, Command completion}, for details on how to do this.
8607@end table
c906108c 8608
b37303ee
AF
8609@node Objective-C
8610@subsection Objective-C
8611
8612@cindex Objective-C
8613This section provides information about some commands and command
8614options that are useful for debugging Objective-C code.
8615
8616@menu
b383017d
RM
8617* Method Names in Commands::
8618* The Print Command with Objective-C::
b37303ee
AF
8619@end menu
8620
8621@node Method Names in Commands, The Print Command with Objective-C, Objective-C, Objective-C
8622@subsubsection Method Names in Commands
8623
8624The following commands have been extended to accept Objective-C method
8625names as line specifications:
8626
8627@kindex clear@r{, and Objective-C}
8628@kindex break@r{, and Objective-C}
8629@kindex info line@r{, and Objective-C}
8630@kindex jump@r{, and Objective-C}
8631@kindex list@r{, and Objective-C}
8632@itemize
8633@item @code{clear}
8634@item @code{break}
8635@item @code{info line}
8636@item @code{jump}
8637@item @code{list}
8638@end itemize
8639
8640A fully qualified Objective-C method name is specified as
8641
8642@smallexample
8643-[@var{Class} @var{methodName}]
8644@end smallexample
8645
c552b3bb
JM
8646where the minus sign is used to indicate an instance method and a
8647plus sign (not shown) is used to indicate a class method. The class
8648name @var{Class} and method name @var{methodName} are enclosed in
8649brackets, similar to the way messages are specified in Objective-C
8650source code. For example, to set a breakpoint at the @code{create}
8651instance method of class @code{Fruit} in the program currently being
8652debugged, enter:
b37303ee
AF
8653
8654@smallexample
8655break -[Fruit create]
8656@end smallexample
8657
8658To list ten program lines around the @code{initialize} class method,
8659enter:
8660
8661@smallexample
8662list +[NSText initialize]
8663@end smallexample
8664
c552b3bb
JM
8665In the current version of @value{GDBN}, the plus or minus sign is
8666required. In future versions of @value{GDBN}, the plus or minus
8667sign will be optional, but you can use it to narrow the search. It
8668is also possible to specify just a method name:
b37303ee
AF
8669
8670@smallexample
8671break create
8672@end smallexample
8673
8674You must specify the complete method name, including any colons. If
8675your program's source files contain more than one @code{create} method,
8676you'll be presented with a numbered list of classes that implement that
8677method. Indicate your choice by number, or type @samp{0} to exit if
8678none apply.
8679
8680As another example, to clear a breakpoint established at the
8681@code{makeKeyAndOrderFront:} method of the @code{NSWindow} class, enter:
8682
8683@smallexample
8684clear -[NSWindow makeKeyAndOrderFront:]
8685@end smallexample
8686
8687@node The Print Command with Objective-C
8688@subsubsection The Print Command With Objective-C
c552b3bb
JM
8689@kindex print-object
8690@kindex po @r{(@code{print-object})}
b37303ee 8691
c552b3bb 8692The print command has also been extended to accept methods. For example:
b37303ee
AF
8693
8694@smallexample
c552b3bb 8695print -[@var{object} hash]
b37303ee
AF
8696@end smallexample
8697
8698@cindex print an Objective-C object description
c552b3bb
JM
8699@cindex @code{_NSPrintForDebugger}, and printing Objective-C objects
8700@noindent
8701will tell @value{GDBN} to send the @code{hash} message to @var{object}
8702and print the result. Also, an additional command has been added,
8703@code{print-object} or @code{po} for short, which is meant to print
8704the description of an object. However, this command may only work
8705with certain Objective-C libraries that have a particular hook
8706function, @code{_NSPrintForDebugger}, defined.
b37303ee 8707
e07c999f 8708@node Modula-2, Ada, Objective-C, Support
c906108c 8709@subsection Modula-2
7a292a7a 8710
d4f3574e 8711@cindex Modula-2, @value{GDBN} support
c906108c
SS
8712
8713The extensions made to @value{GDBN} to support Modula-2 only support
8714output from the @sc{gnu} Modula-2 compiler (which is currently being
8715developed). Other Modula-2 compilers are not currently supported, and
8716attempting to debug executables produced by them is most likely
8717to give an error as @value{GDBN} reads in the executable's symbol
8718table.
8719
8720@cindex expressions in Modula-2
8721@menu
8722* M2 Operators:: Built-in operators
8723* Built-In Func/Proc:: Built-in functions and procedures
8724* M2 Constants:: Modula-2 constants
8725* M2 Defaults:: Default settings for Modula-2
8726* Deviations:: Deviations from standard Modula-2
8727* M2 Checks:: Modula-2 type and range checks
8728* M2 Scope:: The scope operators @code{::} and @code{.}
8729* GDB/M2:: @value{GDBN} and Modula-2
8730@end menu
8731
6d2ebf8b 8732@node M2 Operators
c906108c
SS
8733@subsubsection Operators
8734@cindex Modula-2 operators
8735
8736Operators must be defined on values of specific types. For instance,
8737@code{+} is defined on numbers, but not on structures. Operators are
8738often defined on groups of types. For the purposes of Modula-2, the
8739following definitions hold:
8740
8741@itemize @bullet
8742
8743@item
8744@emph{Integral types} consist of @code{INTEGER}, @code{CARDINAL}, and
8745their subranges.
8746
8747@item
8748@emph{Character types} consist of @code{CHAR} and its subranges.
8749
8750@item
8751@emph{Floating-point types} consist of @code{REAL}.
8752
8753@item
8754@emph{Pointer types} consist of anything declared as @code{POINTER TO
8755@var{type}}.
8756
8757@item
8758@emph{Scalar types} consist of all of the above.
8759
8760@item
8761@emph{Set types} consist of @code{SET} and @code{BITSET} types.
8762
8763@item
8764@emph{Boolean types} consist of @code{BOOLEAN}.
8765@end itemize
8766
8767@noindent
8768The following operators are supported, and appear in order of
8769increasing precedence:
8770
8771@table @code
8772@item ,
8773Function argument or array index separator.
8774
8775@item :=
8776Assignment. The value of @var{var} @code{:=} @var{value} is
8777@var{value}.
8778
8779@item <@r{, }>
8780Less than, greater than on integral, floating-point, or enumerated
8781types.
8782
8783@item <=@r{, }>=
96a2c332 8784Less than or equal to, greater than or equal to
c906108c
SS
8785on integral, floating-point and enumerated types, or set inclusion on
8786set types. Same precedence as @code{<}.
8787
8788@item =@r{, }<>@r{, }#
8789Equality and two ways of expressing inequality, valid on scalar types.
8790Same precedence as @code{<}. In @value{GDBN} scripts, only @code{<>} is
8791available for inequality, since @code{#} conflicts with the script
8792comment character.
8793
8794@item IN
8795Set membership. Defined on set types and the types of their members.
8796Same precedence as @code{<}.
8797
8798@item OR
8799Boolean disjunction. Defined on boolean types.
8800
8801@item AND@r{, }&
d4f3574e 8802Boolean conjunction. Defined on boolean types.
c906108c
SS
8803
8804@item @@
8805The @value{GDBN} ``artificial array'' operator (@pxref{Expressions, ,Expressions}).
8806
8807@item +@r{, }-
8808Addition and subtraction on integral and floating-point types, or union
8809and difference on set types.
8810
8811@item *
8812Multiplication on integral and floating-point types, or set intersection
8813on set types.
8814
8815@item /
8816Division on floating-point types, or symmetric set difference on set
8817types. Same precedence as @code{*}.
8818
8819@item DIV@r{, }MOD
8820Integer division and remainder. Defined on integral types. Same
8821precedence as @code{*}.
8822
8823@item -
8824Negative. Defined on @code{INTEGER} and @code{REAL} data.
8825
8826@item ^
8827Pointer dereferencing. Defined on pointer types.
8828
8829@item NOT
8830Boolean negation. Defined on boolean types. Same precedence as
8831@code{^}.
8832
8833@item .
8834@code{RECORD} field selector. Defined on @code{RECORD} data. Same
8835precedence as @code{^}.
8836
8837@item []
8838Array indexing. Defined on @code{ARRAY} data. Same precedence as @code{^}.
8839
8840@item ()
8841Procedure argument list. Defined on @code{PROCEDURE} objects. Same precedence
8842as @code{^}.
8843
8844@item ::@r{, }.
8845@value{GDBN} and Modula-2 scope operators.
8846@end table
8847
8848@quotation
8849@emph{Warning:} Sets and their operations are not yet supported, so @value{GDBN}
8850treats the use of the operator @code{IN}, or the use of operators
8851@code{+}, @code{-}, @code{*}, @code{/}, @code{=}, , @code{<>}, @code{#},
8852@code{<=}, and @code{>=} on sets as an error.
8853@end quotation
8854
cb51c4e0 8855
6d2ebf8b 8856@node Built-In Func/Proc
c906108c 8857@subsubsection Built-in functions and procedures
cb51c4e0 8858@cindex Modula-2 built-ins
c906108c
SS
8859
8860Modula-2 also makes available several built-in procedures and functions.
8861In describing these, the following metavariables are used:
8862
8863@table @var
8864
8865@item a
8866represents an @code{ARRAY} variable.
8867
8868@item c
8869represents a @code{CHAR} constant or variable.
8870
8871@item i
8872represents a variable or constant of integral type.
8873
8874@item m
8875represents an identifier that belongs to a set. Generally used in the
8876same function with the metavariable @var{s}. The type of @var{s} should
8877be @code{SET OF @var{mtype}} (where @var{mtype} is the type of @var{m}).
8878
8879@item n
8880represents a variable or constant of integral or floating-point type.
8881
8882@item r
8883represents a variable or constant of floating-point type.
8884
8885@item t
8886represents a type.
8887
8888@item v
8889represents a variable.
8890
8891@item x
8892represents a variable or constant of one of many types. See the
8893explanation of the function for details.
8894@end table
8895
8896All Modula-2 built-in procedures also return a result, described below.
8897
8898@table @code
8899@item ABS(@var{n})
8900Returns the absolute value of @var{n}.
8901
8902@item CAP(@var{c})
8903If @var{c} is a lower case letter, it returns its upper case
c3f6f71d 8904equivalent, otherwise it returns its argument.
c906108c
SS
8905
8906@item CHR(@var{i})
8907Returns the character whose ordinal value is @var{i}.
8908
8909@item DEC(@var{v})
c3f6f71d 8910Decrements the value in the variable @var{v} by one. Returns the new value.
c906108c
SS
8911
8912@item DEC(@var{v},@var{i})
8913Decrements the value in the variable @var{v} by @var{i}. Returns the
8914new value.
8915
8916@item EXCL(@var{m},@var{s})
8917Removes the element @var{m} from the set @var{s}. Returns the new
8918set.
8919
8920@item FLOAT(@var{i})
8921Returns the floating point equivalent of the integer @var{i}.
8922
8923@item HIGH(@var{a})
8924Returns the index of the last member of @var{a}.
8925
8926@item INC(@var{v})
c3f6f71d 8927Increments the value in the variable @var{v} by one. Returns the new value.
c906108c
SS
8928
8929@item INC(@var{v},@var{i})
8930Increments the value in the variable @var{v} by @var{i}. Returns the
8931new value.
8932
8933@item INCL(@var{m},@var{s})
8934Adds the element @var{m} to the set @var{s} if it is not already
8935there. Returns the new set.
8936
8937@item MAX(@var{t})
8938Returns the maximum value of the type @var{t}.
8939
8940@item MIN(@var{t})
8941Returns the minimum value of the type @var{t}.
8942
8943@item ODD(@var{i})
8944Returns boolean TRUE if @var{i} is an odd number.
8945
8946@item ORD(@var{x})
8947Returns the ordinal value of its argument. For example, the ordinal
c3f6f71d
JM
8948value of a character is its @sc{ascii} value (on machines supporting the
8949@sc{ascii} character set). @var{x} must be of an ordered type, which include
c906108c
SS
8950integral, character and enumerated types.
8951
8952@item SIZE(@var{x})
8953Returns the size of its argument. @var{x} can be a variable or a type.
8954
8955@item TRUNC(@var{r})
8956Returns the integral part of @var{r}.
8957
8958@item VAL(@var{t},@var{i})
8959Returns the member of the type @var{t} whose ordinal value is @var{i}.
8960@end table
8961
8962@quotation
8963@emph{Warning:} Sets and their operations are not yet supported, so
8964@value{GDBN} treats the use of procedures @code{INCL} and @code{EXCL} as
8965an error.
8966@end quotation
8967
8968@cindex Modula-2 constants
6d2ebf8b 8969@node M2 Constants
c906108c
SS
8970@subsubsection Constants
8971
8972@value{GDBN} allows you to express the constants of Modula-2 in the following
8973ways:
8974
8975@itemize @bullet
8976
8977@item
8978Integer constants are simply a sequence of digits. When used in an
8979expression, a constant is interpreted to be type-compatible with the
8980rest of the expression. Hexadecimal integers are specified by a
8981trailing @samp{H}, and octal integers by a trailing @samp{B}.
8982
8983@item
8984Floating point constants appear as a sequence of digits, followed by a
8985decimal point and another sequence of digits. An optional exponent can
8986then be specified, in the form @samp{E@r{[}+@r{|}-@r{]}@var{nnn}}, where
8987@samp{@r{[}+@r{|}-@r{]}@var{nnn}} is the desired exponent. All of the
8988digits of the floating point constant must be valid decimal (base 10)
8989digits.
8990
8991@item
8992Character constants consist of a single character enclosed by a pair of
8993like quotes, either single (@code{'}) or double (@code{"}). They may
c3f6f71d 8994also be expressed by their ordinal value (their @sc{ascii} value, usually)
c906108c
SS
8995followed by a @samp{C}.
8996
8997@item
8998String constants consist of a sequence of characters enclosed by a
8999pair of like quotes, either single (@code{'}) or double (@code{"}).
9000Escape sequences in the style of C are also allowed. @xref{C
b37052ae 9001Constants, ,C and C@t{++} constants}, for a brief explanation of escape
c906108c
SS
9002sequences.
9003
9004@item
9005Enumerated constants consist of an enumerated identifier.
9006
9007@item
9008Boolean constants consist of the identifiers @code{TRUE} and
9009@code{FALSE}.
9010
9011@item
9012Pointer constants consist of integral values only.
9013
9014@item
9015Set constants are not yet supported.
9016@end itemize
9017
6d2ebf8b 9018@node M2 Defaults
c906108c
SS
9019@subsubsection Modula-2 defaults
9020@cindex Modula-2 defaults
9021
9022If type and range checking are set automatically by @value{GDBN}, they
9023both default to @code{on} whenever the working language changes to
d4f3574e 9024Modula-2. This happens regardless of whether you or @value{GDBN}
c906108c
SS
9025selected the working language.
9026
9027If you allow @value{GDBN} to set the language automatically, then entering
9028code compiled from a file whose name ends with @file{.mod} sets the
d4f3574e 9029working language to Modula-2. @xref{Automatically, ,Having @value{GDBN} set
c906108c
SS
9030the language automatically}, for further details.
9031
6d2ebf8b 9032@node Deviations
c906108c
SS
9033@subsubsection Deviations from standard Modula-2
9034@cindex Modula-2, deviations from
9035
9036A few changes have been made to make Modula-2 programs easier to debug.
9037This is done primarily via loosening its type strictness:
9038
9039@itemize @bullet
9040@item
9041Unlike in standard Modula-2, pointer constants can be formed by
9042integers. This allows you to modify pointer variables during
9043debugging. (In standard Modula-2, the actual address contained in a
9044pointer variable is hidden from you; it can only be modified
9045through direct assignment to another pointer variable or expression that
9046returned a pointer.)
9047
9048@item
9049C escape sequences can be used in strings and characters to represent
9050non-printable characters. @value{GDBN} prints out strings with these
9051escape sequences embedded. Single non-printable characters are
9052printed using the @samp{CHR(@var{nnn})} format.
9053
9054@item
9055The assignment operator (@code{:=}) returns the value of its right-hand
9056argument.
9057
9058@item
9059All built-in procedures both modify @emph{and} return their argument.
9060@end itemize
9061
6d2ebf8b 9062@node M2 Checks
c906108c
SS
9063@subsubsection Modula-2 type and range checks
9064@cindex Modula-2 checks
9065
9066@quotation
9067@emph{Warning:} in this release, @value{GDBN} does not yet perform type or
9068range checking.
9069@end quotation
9070@c FIXME remove warning when type/range checks added
9071
9072@value{GDBN} considers two Modula-2 variables type equivalent if:
9073
9074@itemize @bullet
9075@item
9076They are of types that have been declared equivalent via a @code{TYPE
9077@var{t1} = @var{t2}} statement
9078
9079@item
9080They have been declared on the same line. (Note: This is true of the
9081@sc{gnu} Modula-2 compiler, but it may not be true of other compilers.)
9082@end itemize
9083
9084As long as type checking is enabled, any attempt to combine variables
9085whose types are not equivalent is an error.
9086
9087Range checking is done on all mathematical operations, assignment, array
9088index bounds, and all built-in functions and procedures.
9089
6d2ebf8b 9090@node M2 Scope
c906108c
SS
9091@subsubsection The scope operators @code{::} and @code{.}
9092@cindex scope
41afff9a 9093@cindex @code{.}, Modula-2 scope operator
c906108c
SS
9094@cindex colon, doubled as scope operator
9095@ifinfo
41afff9a 9096@vindex colon-colon@r{, in Modula-2}
c906108c
SS
9097@c Info cannot handle :: but TeX can.
9098@end ifinfo
9099@iftex
41afff9a 9100@vindex ::@r{, in Modula-2}
c906108c
SS
9101@end iftex
9102
9103There are a few subtle differences between the Modula-2 scope operator
9104(@code{.}) and the @value{GDBN} scope operator (@code{::}). The two have
9105similar syntax:
9106
474c8240 9107@smallexample
c906108c
SS
9108
9109@var{module} . @var{id}
9110@var{scope} :: @var{id}
474c8240 9111@end smallexample
c906108c
SS
9112
9113@noindent
9114where @var{scope} is the name of a module or a procedure,
9115@var{module} the name of a module, and @var{id} is any declared
9116identifier within your program, except another module.
9117
9118Using the @code{::} operator makes @value{GDBN} search the scope
9119specified by @var{scope} for the identifier @var{id}. If it is not
9120found in the specified scope, then @value{GDBN} searches all scopes
9121enclosing the one specified by @var{scope}.
9122
9123Using the @code{.} operator makes @value{GDBN} search the current scope for
9124the identifier specified by @var{id} that was imported from the
9125definition module specified by @var{module}. With this operator, it is
9126an error if the identifier @var{id} was not imported from definition
9127module @var{module}, or if @var{id} is not an identifier in
9128@var{module}.
9129
6d2ebf8b 9130@node GDB/M2
c906108c
SS
9131@subsubsection @value{GDBN} and Modula-2
9132
9133Some @value{GDBN} commands have little use when debugging Modula-2 programs.
9134Five subcommands of @code{set print} and @code{show print} apply
b37052ae 9135specifically to C and C@t{++}: @samp{vtbl}, @samp{demangle},
c906108c 9136@samp{asm-demangle}, @samp{object}, and @samp{union}. The first four
b37052ae 9137apply to C@t{++}, and the last to the C @code{union} type, which has no direct
c906108c
SS
9138analogue in Modula-2.
9139
9140The @code{@@} operator (@pxref{Expressions, ,Expressions}), while available
d4f3574e 9141with any language, is not useful with Modula-2. Its
c906108c 9142intent is to aid the debugging of @dfn{dynamic arrays}, which cannot be
b37052ae 9143created in Modula-2 as they can in C or C@t{++}. However, because an
c906108c 9144address can be specified by an integral constant, the construct
d4f3574e 9145@samp{@{@var{type}@}@var{adrexp}} is still useful.
c906108c
SS
9146
9147@cindex @code{#} in Modula-2
9148In @value{GDBN} scripts, the Modula-2 inequality operator @code{#} is
9149interpreted as the beginning of a comment. Use @code{<>} instead.
c906108c 9150
e07c999f
PH
9151@node Ada
9152@subsection Ada
9153@cindex Ada
9154
9155The extensions made to @value{GDBN} for Ada only support
9156output from the @sc{gnu} Ada (GNAT) compiler.
9157Other Ada compilers are not currently supported, and
9158attempting to debug executables produced by them is most likely
9159to be difficult.
9160
9161
9162@cindex expressions in Ada
9163@menu
9164* Ada Mode Intro:: General remarks on the Ada syntax
9165 and semantics supported by Ada mode
9166 in @value{GDBN}.
9167* Omissions from Ada:: Restrictions on the Ada expression syntax.
9168* Additions to Ada:: Extensions of the Ada expression syntax.
9169* Stopping Before Main Program:: Debugging the program during elaboration.
9170* Ada Glitches:: Known peculiarities of Ada mode.
9171@end menu
9172
9173@node Ada Mode Intro
9174@subsubsection Introduction
9175@cindex Ada mode, general
9176
9177The Ada mode of @value{GDBN} supports a fairly large subset of Ada expression
9178syntax, with some extensions.
9179The philosophy behind the design of this subset is
9180
9181@itemize @bullet
9182@item
9183That @value{GDBN} should provide basic literals and access to operations for
9184arithmetic, dereferencing, field selection, indexing, and subprogram calls,
9185leaving more sophisticated computations to subprograms written into the
9186program (which therefore may be called from @value{GDBN}).
9187
9188@item
9189That type safety and strict adherence to Ada language restrictions
9190are not particularly important to the @value{GDBN} user.
9191
9192@item
9193That brevity is important to the @value{GDBN} user.
9194@end itemize
9195
9196Thus, for brevity, the debugger acts as if there were
9197implicit @code{with} and @code{use} clauses in effect for all user-written
9198packages, making it unnecessary to fully qualify most names with
9199their packages, regardless of context. Where this causes ambiguity,
9200@value{GDBN} asks the user's intent.
9201
9202The debugger will start in Ada mode if it detects an Ada main program.
9203As for other languages, it will enter Ada mode when stopped in a program that
9204was translated from an Ada source file.
9205
9206While in Ada mode, you may use `@t{--}' for comments. This is useful
9207mostly for documenting command files. The standard @value{GDBN} comment
9208(@samp{#}) still works at the beginning of a line in Ada mode, but not in the
9209middle (to allow based literals).
9210
9211The debugger supports limited overloading. Given a subprogram call in which
9212the function symbol has multiple definitions, it will use the number of
9213actual parameters and some information about their types to attempt to narrow
9214the set of definitions. It also makes very limited use of context, preferring
9215procedures to functions in the context of the @code{call} command, and
9216functions to procedures elsewhere.
9217
9218@node Omissions from Ada
9219@subsubsection Omissions from Ada
9220@cindex Ada, omissions from
9221
9222Here are the notable omissions from the subset:
9223
9224@itemize @bullet
9225@item
9226Only a subset of the attributes are supported:
9227
9228@itemize @minus
9229@item
9230@t{'First}, @t{'Last}, and @t{'Length}
9231 on array objects (not on types and subtypes).
9232
9233@item
9234@t{'Min} and @t{'Max}.
9235
9236@item
9237@t{'Pos} and @t{'Val}.
9238
9239@item
9240@t{'Tag}.
9241
9242@item
9243@t{'Range} on array objects (not subtypes), but only as the right
9244operand of the membership (@code{in}) operator.
9245
9246@item
9247@t{'Access}, @t{'Unchecked_Access}, and
9248@t{'Unrestricted_Access} (a GNAT extension).
9249
9250@item
9251@t{'Address}.
9252@end itemize
9253
9254@item
9255The names in
9256@code{Characters.Latin_1} are not available and
9257concatenation is not implemented. Thus, escape characters in strings are
9258not currently available.
9259
9260@item
9261Equality tests (@samp{=} and @samp{/=}) on arrays test for bitwise
9262equality of representations. They will generally work correctly
9263for strings and arrays whose elements have integer or enumeration types.
9264They may not work correctly for arrays whose element
9265types have user-defined equality, for arrays of real values
9266(in particular, IEEE-conformant floating point, because of negative
9267zeroes and NaNs), and for arrays whose elements contain unused bits with
9268indeterminate values.
9269
9270@item
9271The other component-by-component array operations (@code{and}, @code{or},
9272@code{xor}, @code{not}, and relational tests other than equality)
9273are not implemented.
9274
9275@item
9276There are no record or array aggregates.
9277
9278@item
9279Calls to dispatching subprograms are not implemented.
9280
9281@item
9282The overloading algorithm is much more limited (i.e., less selective)
9283than that of real Ada. It makes only limited use of the context in which a subexpression
9284appears to resolve its meaning, and it is much looser in its rules for allowing
9285type matches. As a result, some function calls will be ambiguous, and the user
9286will be asked to choose the proper resolution.
9287
9288@item
9289The @code{new} operator is not implemented.
9290
9291@item
9292Entry calls are not implemented.
9293
9294@item
9295Aside from printing, arithmetic operations on the native VAX floating-point
9296formats are not supported.
9297
9298@item
9299It is not possible to slice a packed array.
9300@end itemize
9301
9302@node Additions to Ada
9303@subsubsection Additions to Ada
9304@cindex Ada, deviations from
9305
9306As it does for other languages, @value{GDBN} makes certain generic
9307extensions to Ada (@pxref{Expressions}):
9308
9309@itemize @bullet
9310@item
9311If the expression @var{E} is a variable residing in memory
9312(typically a local variable or array element) and @var{N} is
9313a positive integer, then @code{@var{E}@@@var{N}} displays the values of
9314@var{E} and the @var{N}-1 adjacent variables following it in memory as an array.
9315In Ada, this operator is generally not necessary, since its prime use
9316is in displaying parts of an array, and slicing will usually do this in Ada.
9317However, there are occasional uses when debugging programs
9318in which certain debugging information has been optimized away.
9319
9320@item
9321@code{@var{B}::@var{var}} means ``the variable named @var{var} that appears
9322in function or file @var{B}.'' When @var{B} is a file name, you must typically
9323surround it in single quotes.
9324
9325@item
9326The expression @code{@{@var{type}@} @var{addr}} means ``the variable of type
9327@var{type} that appears at address @var{addr}.''
9328
9329@item
9330A name starting with @samp{$} is a convenience variable
9331(@pxref{Convenience Vars}) or a machine register (@pxref{Registers}).
9332@end itemize
9333
9334In addition, @value{GDBN} provides a few other shortcuts and outright additions specific
9335to Ada:
9336
9337@itemize @bullet
9338@item
9339The assignment statement is allowed as an expression, returning
9340its right-hand operand as its value. Thus, you may enter
9341
9342@smallexample
9343set x := y + 3
9344print A(tmp := y + 1)
9345@end smallexample
9346
9347@item
9348The semicolon is allowed as an ``operator,'' returning as its value
9349the value of its right-hand operand.
9350This allows, for example,
9351complex conditional breaks:
9352
9353@smallexample
9354break f
9355condition 1 (report(i); k += 1; A(k) > 100)
9356@end smallexample
9357
9358@item
9359Rather than use catenation and symbolic character names to introduce special
9360characters into strings, one may instead use a special bracket notation,
9361which is also used to print strings. A sequence of characters of the form
9362@samp{["@var{XX}"]} within a string or character literal denotes the
9363(single) character whose numeric encoding is @var{XX} in hexadecimal. The
9364sequence of characters @samp{["""]} also denotes a single quotation mark
9365in strings. For example,
9366@smallexample
9367 "One line.["0a"]Next line.["0a"]"
9368@end smallexample
9369@noindent
9370contains an ASCII newline character (@code{Ada.Characters.Latin_1.LF}) after each
9371period.
9372
9373@item
9374The subtype used as a prefix for the attributes @t{'Pos}, @t{'Min}, and
9375@t{'Max} is optional (and is ignored in any case). For example, it is valid
9376to write
9377
9378@smallexample
9379print 'max(x, y)
9380@end smallexample
9381
9382@item
9383When printing arrays, @value{GDBN} uses positional notation when the
9384array has a lower bound of 1, and uses a modified named notation otherwise.
9385For example, a one-dimensional array of three integers with a lower bound of 3 might print as
9386
9387@smallexample
9388(3 => 10, 17, 1)
9389@end smallexample
9390
9391@noindent
9392That is, in contrast to valid Ada, only the first component has a @code{=>}
9393clause.
9394
9395@item
9396You may abbreviate attributes in expressions with any unique,
9397multi-character subsequence of
9398their names (an exact match gets preference).
9399For example, you may use @t{a'len}, @t{a'gth}, or @t{a'lh}
9400in place of @t{a'length}.
9401
9402@item
9403@cindex quoting Ada internal identifiers
9404Since Ada is case-insensitive, the debugger normally maps identifiers you type
9405to lower case. The GNAT compiler uses upper-case characters for
9406some of its internal identifiers, which are normally of no interest to users.
9407For the rare occasions when you actually have to look at them,
9408enclose them in angle brackets to avoid the lower-case mapping.
9409For example,
9410@smallexample
9411@value{GDBP} print <JMPBUF_SAVE>[0]
9412@end smallexample
9413
9414@item
9415Printing an object of class-wide type or dereferencing an
9416access-to-class-wide value will display all the components of the object's
9417specific type (as indicated by its run-time tag). Likewise, component
9418selection on such a value will operate on the specific type of the
9419object.
9420
9421@end itemize
9422
9423@node Stopping Before Main Program
9424@subsubsection Stopping at the Very Beginning
9425
9426@cindex breakpointing Ada elaboration code
9427It is sometimes necessary to debug the program during elaboration, and
9428before reaching the main procedure.
9429As defined in the Ada Reference
9430Manual, the elaboration code is invoked from a procedure called
9431@code{adainit}. To run your program up to the beginning of
9432elaboration, simply use the following two commands:
9433@code{tbreak adainit} and @code{run}.
9434
9435@node Ada Glitches
9436@subsubsection Known Peculiarities of Ada Mode
9437@cindex Ada, problems
9438
9439Besides the omissions listed previously (@pxref{Omissions from Ada}),
9440we know of several problems with and limitations of Ada mode in
9441@value{GDBN},
9442some of which will be fixed with planned future releases of the debugger
9443and the GNU Ada compiler.
9444
9445@itemize @bullet
9446@item
9447Currently, the debugger
9448has insufficient information to determine whether certain pointers represent
9449pointers to objects or the objects themselves.
9450Thus, the user may have to tack an extra @code{.all} after an expression
9451to get it printed properly.
9452
9453@item
9454Static constants that the compiler chooses not to materialize as objects in
9455storage are invisible to the debugger.
9456
9457@item
9458Named parameter associations in function argument lists are ignored (the
9459argument lists are treated as positional).
9460
9461@item
9462Many useful library packages are currently invisible to the debugger.
9463
9464@item
9465Fixed-point arithmetic, conversions, input, and output is carried out using
9466floating-point arithmetic, and may give results that only approximate those on
9467the host machine.
9468
9469@item
9470The type of the @t{'Address} attribute may not be @code{System.Address}.
9471
9472@item
9473The GNAT compiler never generates the prefix @code{Standard} for any of
9474the standard symbols defined by the Ada language. @value{GDBN} knows about
9475this: it will strip the prefix from names when you use it, and will never
9476look for a name you have so qualified among local symbols, nor match against
9477symbols in other packages or subprograms. If you have
9478defined entities anywhere in your program other than parameters and
9479local variables whose simple names match names in @code{Standard},
9480GNAT's lack of qualification here can cause confusion. When this happens,
9481you can usually resolve the confusion
9482by qualifying the problematic names with package
9483@code{Standard} explicitly.
9484@end itemize
9485
4e562065
JB
9486@node Unsupported languages
9487@section Unsupported languages
9488
9489@cindex unsupported languages
9490@cindex minimal language
9491In addition to the other fully-supported programming languages,
9492@value{GDBN} also provides a pseudo-language, called @code{minimal}.
9493It does not represent a real programming language, but provides a set
9494of capabilities close to what the C or assembly languages provide.
9495This should allow most simple operations to be performed while debugging
9496an application that uses a language currently not supported by @value{GDBN}.
9497
9498If the language is set to @code{auto}, @value{GDBN} will automatically
9499select this language if the current frame corresponds to an unsupported
9500language.
9501
6d2ebf8b 9502@node Symbols
c906108c
SS
9503@chapter Examining the Symbol Table
9504
d4f3574e 9505The commands described in this chapter allow you to inquire about the
c906108c
SS
9506symbols (names of variables, functions and types) defined in your
9507program. This information is inherent in the text of your program and
9508does not change as your program executes. @value{GDBN} finds it in your
9509program's symbol table, in the file indicated when you started @value{GDBN}
9510(@pxref{File Options, ,Choosing files}), or by one of the
9511file-management commands (@pxref{Files, ,Commands to specify files}).
9512
9513@cindex symbol names
9514@cindex names of symbols
9515@cindex quoting names
9516Occasionally, you may need to refer to symbols that contain unusual
9517characters, which @value{GDBN} ordinarily treats as word delimiters. The
9518most frequent case is in referring to static variables in other
9519source files (@pxref{Variables,,Program variables}). File names
9520are recorded in object files as debugging symbols, but @value{GDBN} would
9521ordinarily parse a typical file name, like @file{foo.c}, as the three words
9522@samp{foo} @samp{.} @samp{c}. To allow @value{GDBN} to recognize
9523@samp{foo.c} as a single symbol, enclose it in single quotes; for example,
9524
474c8240 9525@smallexample
c906108c 9526p 'foo.c'::x
474c8240 9527@end smallexample
c906108c
SS
9528
9529@noindent
9530looks up the value of @code{x} in the scope of the file @file{foo.c}.
9531
9532@table @code
9533@kindex info address
b37052ae 9534@cindex address of a symbol
c906108c
SS
9535@item info address @var{symbol}
9536Describe where the data for @var{symbol} is stored. For a register
9537variable, this says which register it is kept in. For a non-register
9538local variable, this prints the stack-frame offset at which the variable
9539is always stored.
9540
9541Note the contrast with @samp{print &@var{symbol}}, which does not work
9542at all for a register variable, and for a stack local variable prints
9543the exact address of the current instantiation of the variable.
9544
3d67e040 9545@kindex info symbol
b37052ae 9546@cindex symbol from address
3d67e040
EZ
9547@item info symbol @var{addr}
9548Print the name of a symbol which is stored at the address @var{addr}.
9549If no symbol is stored exactly at @var{addr}, @value{GDBN} prints the
9550nearest symbol and an offset from it:
9551
474c8240 9552@smallexample
3d67e040
EZ
9553(@value{GDBP}) info symbol 0x54320
9554_initialize_vx + 396 in section .text
474c8240 9555@end smallexample
3d67e040
EZ
9556
9557@noindent
9558This is the opposite of the @code{info address} command. You can use
9559it to find out the name of a variable or a function given its address.
9560
c906108c 9561@kindex whatis
d4f3574e
SS
9562@item whatis @var{expr}
9563Print the data type of expression @var{expr}. @var{expr} is not
c906108c
SS
9564actually evaluated, and any side-effecting operations (such as
9565assignments or function calls) inside it do not take place.
9566@xref{Expressions, ,Expressions}.
9567
9568@item whatis
9569Print the data type of @code{$}, the last value in the value history.
9570
9571@kindex ptype
9572@item ptype @var{typename}
9573Print a description of data type @var{typename}. @var{typename} may be
7a292a7a
SS
9574the name of a type, or for C code it may have the form @samp{class
9575@var{class-name}}, @samp{struct @var{struct-tag}}, @samp{union
9576@var{union-tag}} or @samp{enum @var{enum-tag}}.
c906108c 9577
d4f3574e 9578@item ptype @var{expr}
c906108c 9579@itemx ptype
d4f3574e 9580Print a description of the type of expression @var{expr}. @code{ptype}
c906108c
SS
9581differs from @code{whatis} by printing a detailed description, instead
9582of just the name of the type.
9583
9584For example, for this variable declaration:
9585
474c8240 9586@smallexample
c906108c 9587struct complex @{double real; double imag;@} v;
474c8240 9588@end smallexample
c906108c
SS
9589
9590@noindent
9591the two commands give this output:
9592
474c8240 9593@smallexample
c906108c
SS
9594@group
9595(@value{GDBP}) whatis v
9596type = struct complex
9597(@value{GDBP}) ptype v
9598type = struct complex @{
9599 double real;
9600 double imag;
9601@}
9602@end group
474c8240 9603@end smallexample
c906108c
SS
9604
9605@noindent
9606As with @code{whatis}, using @code{ptype} without an argument refers to
9607the type of @code{$}, the last value in the value history.
9608
9609@kindex info types
9610@item info types @var{regexp}
9611@itemx info types
d4f3574e 9612Print a brief description of all types whose names match @var{regexp}
c906108c
SS
9613(or all types in your program, if you supply no argument). Each
9614complete typename is matched as though it were a complete line; thus,
9615@samp{i type value} gives information on all types in your program whose
d4f3574e 9616names include the string @code{value}, but @samp{i type ^value$} gives
c906108c
SS
9617information only on types whose complete name is @code{value}.
9618
9619This command differs from @code{ptype} in two ways: first, like
9620@code{whatis}, it does not print a detailed description; second, it
9621lists all source files where a type is defined.
9622
b37052ae
EZ
9623@kindex info scope
9624@cindex local variables
9625@item info scope @var{addr}
9626List all the variables local to a particular scope. This command
9627accepts a location---a function name, a source line, or an address
9628preceded by a @samp{*}, and prints all the variables local to the
9629scope defined by that location. For example:
9630
9631@smallexample
9632(@value{GDBP}) @b{info scope command_line_handler}
9633Scope for command_line_handler:
9634Symbol rl is an argument at stack/frame offset 8, length 4.
9635Symbol linebuffer is in static storage at address 0x150a18, length 4.
9636Symbol linelength is in static storage at address 0x150a1c, length 4.
9637Symbol p is a local variable in register $esi, length 4.
9638Symbol p1 is a local variable in register $ebx, length 4.
9639Symbol nline is a local variable in register $edx, length 4.
9640Symbol repeat is a local variable at frame offset -8, length 4.
9641@end smallexample
9642
f5c37c66
EZ
9643@noindent
9644This command is especially useful for determining what data to collect
9645during a @dfn{trace experiment}, see @ref{Tracepoint Actions,
9646collect}.
9647
c906108c
SS
9648@kindex info source
9649@item info source
919d772c
JB
9650Show information about the current source file---that is, the source file for
9651the function containing the current point of execution:
9652@itemize @bullet
9653@item
9654the name of the source file, and the directory containing it,
9655@item
9656the directory it was compiled in,
9657@item
9658its length, in lines,
9659@item
9660which programming language it is written in,
9661@item
9662whether the executable includes debugging information for that file, and
9663if so, what format the information is in (e.g., STABS, Dwarf 2, etc.), and
9664@item
9665whether the debugging information includes information about
9666preprocessor macros.
9667@end itemize
9668
c906108c
SS
9669
9670@kindex info sources
9671@item info sources
9672Print the names of all source files in your program for which there is
9673debugging information, organized into two lists: files whose symbols
9674have already been read, and files whose symbols will be read when needed.
9675
9676@kindex info functions
9677@item info functions
9678Print the names and data types of all defined functions.
9679
9680@item info functions @var{regexp}
9681Print the names and data types of all defined functions
9682whose names contain a match for regular expression @var{regexp}.
9683Thus, @samp{info fun step} finds all functions whose names
9684include @code{step}; @samp{info fun ^step} finds those whose names
b383017d
RM
9685start with @code{step}. If a function name contains characters
9686that conflict with the regular expression language (eg.
1c5dfdad 9687@samp{operator*()}), they may be quoted with a backslash.
c906108c
SS
9688
9689@kindex info variables
9690@item info variables
9691Print the names and data types of all variables that are declared
6ca652b0 9692outside of functions (i.e.@: excluding local variables).
c906108c
SS
9693
9694@item info variables @var{regexp}
9695Print the names and data types of all variables (except for local
9696variables) whose names contain a match for regular expression
9697@var{regexp}.
9698
b37303ee
AF
9699@kindex info classes
9700@item info classes
9701@itemx info classes @var{regexp}
9702Display all Objective-C classes in your program, or
9703(with the @var{regexp} argument) all those matching a particular regular
9704expression.
9705
9706@kindex info selectors
9707@item info selectors
9708@itemx info selectors @var{regexp}
9709Display all Objective-C selectors in your program, or
9710(with the @var{regexp} argument) all those matching a particular regular
9711expression.
9712
c906108c
SS
9713@ignore
9714This was never implemented.
9715@kindex info methods
9716@item info methods
9717@itemx info methods @var{regexp}
9718The @code{info methods} command permits the user to examine all defined
b37052ae
EZ
9719methods within C@t{++} program, or (with the @var{regexp} argument) a
9720specific set of methods found in the various C@t{++} classes. Many
9721C@t{++} classes provide a large number of methods. Thus, the output
c906108c
SS
9722from the @code{ptype} command can be overwhelming and hard to use. The
9723@code{info-methods} command filters the methods, printing only those
9724which match the regular-expression @var{regexp}.
9725@end ignore
9726
c906108c
SS
9727@cindex reloading symbols
9728Some systems allow individual object files that make up your program to
7a292a7a
SS
9729be replaced without stopping and restarting your program. For example,
9730in VxWorks you can simply recompile a defective object file and keep on
9731running. If you are running on one of these systems, you can allow
9732@value{GDBN} to reload the symbols for automatically relinked modules:
c906108c
SS
9733
9734@table @code
9735@kindex set symbol-reloading
9736@item set symbol-reloading on
9737Replace symbol definitions for the corresponding source file when an
9738object file with a particular name is seen again.
9739
9740@item set symbol-reloading off
6d2ebf8b
SS
9741Do not replace symbol definitions when encountering object files of the
9742same name more than once. This is the default state; if you are not
9743running on a system that permits automatic relinking of modules, you
9744should leave @code{symbol-reloading} off, since otherwise @value{GDBN}
9745may discard symbols when linking large programs, that may contain
9746several modules (from different directories or libraries) with the same
9747name.
c906108c
SS
9748
9749@kindex show symbol-reloading
9750@item show symbol-reloading
9751Show the current @code{on} or @code{off} setting.
9752@end table
c906108c 9753
c906108c
SS
9754@kindex set opaque-type-resolution
9755@item set opaque-type-resolution on
9756Tell @value{GDBN} to resolve opaque types. An opaque type is a type
9757declared as a pointer to a @code{struct}, @code{class}, or
9758@code{union}---for example, @code{struct MyType *}---that is used in one
9759source file although the full declaration of @code{struct MyType} is in
9760another source file. The default is on.
9761
9762A change in the setting of this subcommand will not take effect until
9763the next time symbols for a file are loaded.
9764
9765@item set opaque-type-resolution off
9766Tell @value{GDBN} not to resolve opaque types. In this case, the type
9767is printed as follows:
9768@smallexample
9769@{<no data fields>@}
9770@end smallexample
9771
9772@kindex show opaque-type-resolution
9773@item show opaque-type-resolution
9774Show whether opaque types are resolved or not.
c906108c
SS
9775
9776@kindex maint print symbols
9777@cindex symbol dump
9778@kindex maint print psymbols
9779@cindex partial symbol dump
9780@item maint print symbols @var{filename}
9781@itemx maint print psymbols @var{filename}
9782@itemx maint print msymbols @var{filename}
9783Write a dump of debugging symbol data into the file @var{filename}.
9784These commands are used to debug the @value{GDBN} symbol-reading code. Only
9785symbols with debugging data are included. If you use @samp{maint print
9786symbols}, @value{GDBN} includes all the symbols for which it has already
9787collected full details: that is, @var{filename} reflects symbols for
9788only those files whose symbols @value{GDBN} has read. You can use the
9789command @code{info sources} to find out which files these are. If you
9790use @samp{maint print psymbols} instead, the dump shows information about
9791symbols that @value{GDBN} only knows partially---that is, symbols defined in
9792files that @value{GDBN} has skimmed, but not yet read completely. Finally,
9793@samp{maint print msymbols} dumps just the minimal symbol information
9794required for each object file from which @value{GDBN} has read some symbols.
9795@xref{Files, ,Commands to specify files}, for a discussion of how
9796@value{GDBN} reads symbols (in the description of @code{symbol-file}).
44ea7b70 9797
5e7b2f39
JB
9798@kindex maint info symtabs
9799@kindex maint info psymtabs
44ea7b70
JB
9800@cindex listing @value{GDBN}'s internal symbol tables
9801@cindex symbol tables, listing @value{GDBN}'s internal
9802@cindex full symbol tables, listing @value{GDBN}'s internal
9803@cindex partial symbol tables, listing @value{GDBN}'s internal
5e7b2f39
JB
9804@item maint info symtabs @r{[} @var{regexp} @r{]}
9805@itemx maint info psymtabs @r{[} @var{regexp} @r{]}
44ea7b70
JB
9806
9807List the @code{struct symtab} or @code{struct partial_symtab}
9808structures whose names match @var{regexp}. If @var{regexp} is not
9809given, list them all. The output includes expressions which you can
9810copy into a @value{GDBN} debugging this one to examine a particular
9811structure in more detail. For example:
9812
9813@smallexample
5e7b2f39 9814(@value{GDBP}) maint info psymtabs dwarf2read
44ea7b70
JB
9815@{ objfile /home/gnu/build/gdb/gdb
9816 ((struct objfile *) 0x82e69d0)
b383017d 9817 @{ psymtab /home/gnu/src/gdb/dwarf2read.c
44ea7b70
JB
9818 ((struct partial_symtab *) 0x8474b10)
9819 readin no
9820 fullname (null)
9821 text addresses 0x814d3c8 -- 0x8158074
9822 globals (* (struct partial_symbol **) 0x8507a08 @@ 9)
9823 statics (* (struct partial_symbol **) 0x40e95b78 @@ 2882)
9824 dependencies (none)
9825 @}
9826@}
5e7b2f39 9827(@value{GDBP}) maint info symtabs
44ea7b70
JB
9828(@value{GDBP})
9829@end smallexample
9830@noindent
9831We see that there is one partial symbol table whose filename contains
9832the string @samp{dwarf2read}, belonging to the @samp{gdb} executable;
9833and we see that @value{GDBN} has not read in any symtabs yet at all.
9834If we set a breakpoint on a function, that will cause @value{GDBN} to
9835read the symtab for the compilation unit containing that function:
9836
9837@smallexample
9838(@value{GDBP}) break dwarf2_psymtab_to_symtab
9839Breakpoint 1 at 0x814e5da: file /home/gnu/src/gdb/dwarf2read.c,
9840line 1574.
5e7b2f39 9841(@value{GDBP}) maint info symtabs
b383017d 9842@{ objfile /home/gnu/build/gdb/gdb
44ea7b70 9843 ((struct objfile *) 0x82e69d0)
b383017d 9844 @{ symtab /home/gnu/src/gdb/dwarf2read.c
44ea7b70
JB
9845 ((struct symtab *) 0x86c1f38)
9846 dirname (null)
9847 fullname (null)
9848 blockvector ((struct blockvector *) 0x86c1bd0) (primary)
9849 debugformat DWARF 2
9850 @}
9851@}
b383017d 9852(@value{GDBP})
44ea7b70 9853@end smallexample
c906108c
SS
9854@end table
9855
44ea7b70 9856
6d2ebf8b 9857@node Altering
c906108c
SS
9858@chapter Altering Execution
9859
9860Once you think you have found an error in your program, you might want to
9861find out for certain whether correcting the apparent error would lead to
9862correct results in the rest of the run. You can find the answer by
9863experiment, using the @value{GDBN} features for altering execution of the
9864program.
9865
9866For example, you can store new values into variables or memory
7a292a7a
SS
9867locations, give your program a signal, restart it at a different
9868address, or even return prematurely from a function.
c906108c
SS
9869
9870@menu
9871* Assignment:: Assignment to variables
9872* Jumping:: Continuing at a different address
c906108c 9873* Signaling:: Giving your program a signal
c906108c
SS
9874* Returning:: Returning from a function
9875* Calling:: Calling your program's functions
9876* Patching:: Patching your program
9877@end menu
9878
6d2ebf8b 9879@node Assignment
c906108c
SS
9880@section Assignment to variables
9881
9882@cindex assignment
9883@cindex setting variables
9884To alter the value of a variable, evaluate an assignment expression.
9885@xref{Expressions, ,Expressions}. For example,
9886
474c8240 9887@smallexample
c906108c 9888print x=4
474c8240 9889@end smallexample
c906108c
SS
9890
9891@noindent
9892stores the value 4 into the variable @code{x}, and then prints the
5d161b24 9893value of the assignment expression (which is 4).
c906108c
SS
9894@xref{Languages, ,Using @value{GDBN} with Different Languages}, for more
9895information on operators in supported languages.
c906108c
SS
9896
9897@kindex set variable
9898@cindex variables, setting
9899If you are not interested in seeing the value of the assignment, use the
9900@code{set} command instead of the @code{print} command. @code{set} is
9901really the same as @code{print} except that the expression's value is
9902not printed and is not put in the value history (@pxref{Value History,
9903,Value history}). The expression is evaluated only for its effects.
9904
c906108c
SS
9905If the beginning of the argument string of the @code{set} command
9906appears identical to a @code{set} subcommand, use the @code{set
9907variable} command instead of just @code{set}. This command is identical
9908to @code{set} except for its lack of subcommands. For example, if your
9909program has a variable @code{width}, you get an error if you try to set
9910a new value with just @samp{set width=13}, because @value{GDBN} has the
9911command @code{set width}:
9912
474c8240 9913@smallexample
c906108c
SS
9914(@value{GDBP}) whatis width
9915type = double
9916(@value{GDBP}) p width
9917$4 = 13
9918(@value{GDBP}) set width=47
9919Invalid syntax in expression.
474c8240 9920@end smallexample
c906108c
SS
9921
9922@noindent
9923The invalid expression, of course, is @samp{=47}. In
9924order to actually set the program's variable @code{width}, use
9925
474c8240 9926@smallexample
c906108c 9927(@value{GDBP}) set var width=47
474c8240 9928@end smallexample
53a5351d 9929
c906108c
SS
9930Because the @code{set} command has many subcommands that can conflict
9931with the names of program variables, it is a good idea to use the
9932@code{set variable} command instead of just @code{set}. For example, if
9933your program has a variable @code{g}, you run into problems if you try
9934to set a new value with just @samp{set g=4}, because @value{GDBN} has
9935the command @code{set gnutarget}, abbreviated @code{set g}:
9936
474c8240 9937@smallexample
c906108c
SS
9938@group
9939(@value{GDBP}) whatis g
9940type = double
9941(@value{GDBP}) p g
9942$1 = 1
9943(@value{GDBP}) set g=4
2df3850c 9944(@value{GDBP}) p g
c906108c
SS
9945$2 = 1
9946(@value{GDBP}) r
9947The program being debugged has been started already.
9948Start it from the beginning? (y or n) y
9949Starting program: /home/smith/cc_progs/a.out
6d2ebf8b
SS
9950"/home/smith/cc_progs/a.out": can't open to read symbols:
9951 Invalid bfd target.
c906108c
SS
9952(@value{GDBP}) show g
9953The current BFD target is "=4".
9954@end group
474c8240 9955@end smallexample
c906108c
SS
9956
9957@noindent
9958The program variable @code{g} did not change, and you silently set the
9959@code{gnutarget} to an invalid value. In order to set the variable
9960@code{g}, use
9961
474c8240 9962@smallexample
c906108c 9963(@value{GDBP}) set var g=4
474c8240 9964@end smallexample
c906108c
SS
9965
9966@value{GDBN} allows more implicit conversions in assignments than C; you can
9967freely store an integer value into a pointer variable or vice versa,
9968and you can convert any structure to any other structure that is the
9969same length or shorter.
9970@comment FIXME: how do structs align/pad in these conversions?
9971@comment /doc@cygnus.com 18dec1990
9972
9973To store values into arbitrary places in memory, use the @samp{@{@dots{}@}}
9974construct to generate a value of specified type at a specified address
9975(@pxref{Expressions, ,Expressions}). For example, @code{@{int@}0x83040} refers
9976to memory location @code{0x83040} as an integer (which implies a certain size
9977and representation in memory), and
9978
474c8240 9979@smallexample
c906108c 9980set @{int@}0x83040 = 4
474c8240 9981@end smallexample
c906108c
SS
9982
9983@noindent
9984stores the value 4 into that memory location.
9985
6d2ebf8b 9986@node Jumping
c906108c
SS
9987@section Continuing at a different address
9988
9989Ordinarily, when you continue your program, you do so at the place where
9990it stopped, with the @code{continue} command. You can instead continue at
9991an address of your own choosing, with the following commands:
9992
9993@table @code
9994@kindex jump
9995@item jump @var{linespec}
9996Resume execution at line @var{linespec}. Execution stops again
9997immediately if there is a breakpoint there. @xref{List, ,Printing
9998source lines}, for a description of the different forms of
9999@var{linespec}. It is common practice to use the @code{tbreak} command
10000in conjunction with @code{jump}. @xref{Set Breaks, ,Setting
10001breakpoints}.
10002
10003The @code{jump} command does not change the current stack frame, or
10004the stack pointer, or the contents of any memory location or any
10005register other than the program counter. If line @var{linespec} is in
10006a different function from the one currently executing, the results may
10007be bizarre if the two functions expect different patterns of arguments or
10008of local variables. For this reason, the @code{jump} command requests
10009confirmation if the specified line is not in the function currently
10010executing. However, even bizarre results are predictable if you are
10011well acquainted with the machine-language code of your program.
10012
10013@item jump *@var{address}
10014Resume execution at the instruction at address @var{address}.
10015@end table
10016
c906108c 10017@c Doesn't work on HP-UX; have to set $pcoqh and $pcoqt.
53a5351d
JM
10018On many systems, you can get much the same effect as the @code{jump}
10019command by storing a new value into the register @code{$pc}. The
10020difference is that this does not start your program running; it only
10021changes the address of where it @emph{will} run when you continue. For
10022example,
c906108c 10023
474c8240 10024@smallexample
c906108c 10025set $pc = 0x485
474c8240 10026@end smallexample
c906108c
SS
10027
10028@noindent
10029makes the next @code{continue} command or stepping command execute at
10030address @code{0x485}, rather than at the address where your program stopped.
10031@xref{Continuing and Stepping, ,Continuing and stepping}.
c906108c
SS
10032
10033The most common occasion to use the @code{jump} command is to back
10034up---perhaps with more breakpoints set---over a portion of a program
10035that has already executed, in order to examine its execution in more
10036detail.
10037
c906108c 10038@c @group
6d2ebf8b 10039@node Signaling
c906108c
SS
10040@section Giving your program a signal
10041
10042@table @code
10043@kindex signal
10044@item signal @var{signal}
10045Resume execution where your program stopped, but immediately give it the
10046signal @var{signal}. @var{signal} can be the name or the number of a
10047signal. For example, on many systems @code{signal 2} and @code{signal
10048SIGINT} are both ways of sending an interrupt signal.
10049
10050Alternatively, if @var{signal} is zero, continue execution without
10051giving a signal. This is useful when your program stopped on account of
10052a signal and would ordinary see the signal when resumed with the
10053@code{continue} command; @samp{signal 0} causes it to resume without a
10054signal.
10055
10056@code{signal} does not repeat when you press @key{RET} a second time
10057after executing the command.
10058@end table
10059@c @end group
10060
10061Invoking the @code{signal} command is not the same as invoking the
10062@code{kill} utility from the shell. Sending a signal with @code{kill}
10063causes @value{GDBN} to decide what to do with the signal depending on
10064the signal handling tables (@pxref{Signals}). The @code{signal} command
10065passes the signal directly to your program.
10066
c906108c 10067
6d2ebf8b 10068@node Returning
c906108c
SS
10069@section Returning from a function
10070
10071@table @code
10072@cindex returning from a function
10073@kindex return
10074@item return
10075@itemx return @var{expression}
10076You can cancel execution of a function call with the @code{return}
10077command. If you give an
10078@var{expression} argument, its value is used as the function's return
10079value.
10080@end table
10081
10082When you use @code{return}, @value{GDBN} discards the selected stack frame
10083(and all frames within it). You can think of this as making the
10084discarded frame return prematurely. If you wish to specify a value to
10085be returned, give that value as the argument to @code{return}.
10086
10087This pops the selected stack frame (@pxref{Selection, ,Selecting a
10088frame}), and any other frames inside of it, leaving its caller as the
10089innermost remaining frame. That frame becomes selected. The
10090specified value is stored in the registers used for returning values
10091of functions.
10092
10093The @code{return} command does not resume execution; it leaves the
10094program stopped in the state that would exist if the function had just
10095returned. In contrast, the @code{finish} command (@pxref{Continuing
10096and Stepping, ,Continuing and stepping}) resumes execution until the
10097selected stack frame returns naturally.
10098
6d2ebf8b 10099@node Calling
c906108c
SS
10100@section Calling program functions
10101
f8568604 10102@table @code
c906108c 10103@cindex calling functions
f8568604
EZ
10104@cindex inferior functions, calling
10105@item print @var{expr}
10106Evaluate the expression @var{expr} and displaying the resuling value.
10107@var{expr} may include calls to functions in the program being
10108debugged.
10109
c906108c 10110@kindex call
c906108c
SS
10111@item call @var{expr}
10112Evaluate the expression @var{expr} without displaying @code{void}
10113returned values.
c906108c
SS
10114
10115You can use this variant of the @code{print} command if you want to
f8568604
EZ
10116execute a function from your program that does not return anything
10117(a.k.a.@: @dfn{a void function}), but without cluttering the output
10118with @code{void} returned values that @value{GDBN} will otherwise
10119print. If the result is not void, it is printed and saved in the
10120value history.
10121@end table
10122
10123@cindex weak alias functions
10124Sometimes, a function you wish to call is actually a @dfn{weak alias}
10125for another function. In such case, @value{GDBN} might not pick up
10126the type information, including the types of the function arguments,
10127which causes @value{GDBN} to call the inferior function incorrectly.
10128As a result, the called function will function erroneously and may
10129even crash. A solution to that is to use the name of the aliased
10130function instead.
c906108c 10131
6d2ebf8b 10132@node Patching
c906108c 10133@section Patching programs
7a292a7a 10134
c906108c
SS
10135@cindex patching binaries
10136@cindex writing into executables
c906108c 10137@cindex writing into corefiles
c906108c 10138
7a292a7a
SS
10139By default, @value{GDBN} opens the file containing your program's
10140executable code (or the corefile) read-only. This prevents accidental
10141alterations to machine code; but it also prevents you from intentionally
10142patching your program's binary.
c906108c
SS
10143
10144If you'd like to be able to patch the binary, you can specify that
10145explicitly with the @code{set write} command. For example, you might
10146want to turn on internal debugging flags, or even to make emergency
10147repairs.
10148
10149@table @code
10150@kindex set write
10151@item set write on
10152@itemx set write off
7a292a7a
SS
10153If you specify @samp{set write on}, @value{GDBN} opens executable and
10154core files for both reading and writing; if you specify @samp{set write
c906108c
SS
10155off} (the default), @value{GDBN} opens them read-only.
10156
10157If you have already loaded a file, you must load it again (using the
7a292a7a
SS
10158@code{exec-file} or @code{core-file} command) after changing @code{set
10159write}, for your new setting to take effect.
c906108c
SS
10160
10161@item show write
10162@kindex show write
7a292a7a
SS
10163Display whether executable files and core files are opened for writing
10164as well as reading.
c906108c
SS
10165@end table
10166
6d2ebf8b 10167@node GDB Files
c906108c
SS
10168@chapter @value{GDBN} Files
10169
7a292a7a
SS
10170@value{GDBN} needs to know the file name of the program to be debugged,
10171both in order to read its symbol table and in order to start your
10172program. To debug a core dump of a previous run, you must also tell
10173@value{GDBN} the name of the core dump file.
c906108c
SS
10174
10175@menu
10176* Files:: Commands to specify files
5b5d99cf 10177* Separate Debug Files:: Debugging information in separate files
c906108c
SS
10178* Symbol Errors:: Errors reading symbol files
10179@end menu
10180
6d2ebf8b 10181@node Files
c906108c 10182@section Commands to specify files
c906108c 10183
7a292a7a 10184@cindex symbol table
c906108c 10185@cindex core dump file
7a292a7a
SS
10186
10187You may want to specify executable and core dump file names. The usual
10188way to do this is at start-up time, using the arguments to
10189@value{GDBN}'s start-up commands (@pxref{Invocation, , Getting In and
10190Out of @value{GDBN}}).
c906108c
SS
10191
10192Occasionally it is necessary to change to a different file during a
10193@value{GDBN} session. Or you may run @value{GDBN} and forget to specify
10194a file you want to use. In these situations the @value{GDBN} commands
10195to specify new files are useful.
10196
10197@table @code
10198@cindex executable file
10199@kindex file
10200@item file @var{filename}
10201Use @var{filename} as the program to be debugged. It is read for its
10202symbols and for the contents of pure memory. It is also the program
10203executed when you use the @code{run} command. If you do not specify a
5d161b24
DB
10204directory and the file is not found in the @value{GDBN} working directory,
10205@value{GDBN} uses the environment variable @code{PATH} as a list of
10206directories to search, just as the shell does when looking for a program
10207to run. You can change the value of this variable, for both @value{GDBN}
c906108c
SS
10208and your program, using the @code{path} command.
10209
6d2ebf8b 10210On systems with memory-mapped files, an auxiliary file named
c906108c
SS
10211@file{@var{filename}.syms} may hold symbol table information for
10212@var{filename}. If so, @value{GDBN} maps in the symbol table from
10213@file{@var{filename}.syms}, starting up more quickly. See the
10214descriptions of the file options @samp{-mapped} and @samp{-readnow}
7b5ba0cc
EZ
10215(available on the command line, see @ref{File Options, , -readnow},
10216and with the commands @code{file}, @code{symbol-file}, or
10217@code{add-symbol-file}, described below), for more information.
c906108c
SS
10218
10219@item file
10220@code{file} with no argument makes @value{GDBN} discard any information it
10221has on both executable file and the symbol table.
10222
10223@kindex exec-file
10224@item exec-file @r{[} @var{filename} @r{]}
10225Specify that the program to be run (but not the symbol table) is found
10226in @var{filename}. @value{GDBN} searches the environment variable @code{PATH}
10227if necessary to locate your program. Omitting @var{filename} means to
10228discard information on the executable file.
10229
10230@kindex symbol-file
10231@item symbol-file @r{[} @var{filename} @r{]}
10232Read symbol table information from file @var{filename}. @code{PATH} is
10233searched when necessary. Use the @code{file} command to get both symbol
10234table and program to run from the same file.
10235
10236@code{symbol-file} with no argument clears out @value{GDBN} information on your
10237program's symbol table.
10238
5d161b24 10239The @code{symbol-file} command causes @value{GDBN} to forget the contents
c906108c
SS
10240of its convenience variables, the value history, and all breakpoints and
10241auto-display expressions. This is because they may contain pointers to
10242the internal data recording symbols and data types, which are part of
10243the old symbol table data being discarded inside @value{GDBN}.
10244
10245@code{symbol-file} does not repeat if you press @key{RET} again after
10246executing it once.
10247
10248When @value{GDBN} is configured for a particular environment, it
10249understands debugging information in whatever format is the standard
10250generated for that environment; you may use either a @sc{gnu} compiler, or
10251other compilers that adhere to the local conventions.
c906108c
SS
10252Best results are usually obtained from @sc{gnu} compilers; for example,
10253using @code{@value{GCC}} you can generate debugging information for
10254optimized code.
c906108c
SS
10255
10256For most kinds of object files, with the exception of old SVR3 systems
10257using COFF, the @code{symbol-file} command does not normally read the
10258symbol table in full right away. Instead, it scans the symbol table
10259quickly to find which source files and which symbols are present. The
10260details are read later, one source file at a time, as they are needed.
10261
10262The purpose of this two-stage reading strategy is to make @value{GDBN}
10263start up faster. For the most part, it is invisible except for
10264occasional pauses while the symbol table details for a particular source
10265file are being read. (The @code{set verbose} command can turn these
10266pauses into messages if desired. @xref{Messages/Warnings, ,Optional
10267warnings and messages}.)
10268
c906108c
SS
10269We have not implemented the two-stage strategy for COFF yet. When the
10270symbol table is stored in COFF format, @code{symbol-file} reads the
10271symbol table data in full right away. Note that ``stabs-in-COFF''
10272still does the two-stage strategy, since the debug info is actually
10273in stabs format.
10274
10275@kindex readnow
10276@cindex reading symbols immediately
10277@cindex symbols, reading immediately
10278@kindex mapped
10279@cindex memory-mapped symbol file
10280@cindex saving symbol table
10281@item symbol-file @var{filename} @r{[} -readnow @r{]} @r{[} -mapped @r{]}
10282@itemx file @var{filename} @r{[} -readnow @r{]} @r{[} -mapped @r{]}
10283You can override the @value{GDBN} two-stage strategy for reading symbol
10284tables by using the @samp{-readnow} option with any of the commands that
10285load symbol table information, if you want to be sure @value{GDBN} has the
5d161b24 10286entire symbol table available.
c906108c 10287
c906108c
SS
10288If memory-mapped files are available on your system through the
10289@code{mmap} system call, you can use another option, @samp{-mapped}, to
10290cause @value{GDBN} to write the symbols for your program into a reusable
10291file. Future @value{GDBN} debugging sessions map in symbol information
10292from this auxiliary symbol file (if the program has not changed), rather
10293than spending time reading the symbol table from the executable
10294program. Using the @samp{-mapped} option has the same effect as
10295starting @value{GDBN} with the @samp{-mapped} command-line option.
10296
10297You can use both options together, to make sure the auxiliary symbol
10298file has all the symbol information for your program.
10299
10300The auxiliary symbol file for a program called @var{myprog} is called
10301@samp{@var{myprog}.syms}. Once this file exists (so long as it is newer
10302than the corresponding executable), @value{GDBN} always attempts to use
10303it when you debug @var{myprog}; no special options or commands are
10304needed.
10305
10306The @file{.syms} file is specific to the host machine where you run
10307@value{GDBN}. It holds an exact image of the internal @value{GDBN}
10308symbol table. It cannot be shared across multiple host platforms.
c906108c
SS
10309
10310@c FIXME: for now no mention of directories, since this seems to be in
10311@c flux. 13mar1992 status is that in theory GDB would look either in
10312@c current dir or in same dir as myprog; but issues like competing
10313@c GDB's, or clutter in system dirs, mean that in practice right now
10314@c only current dir is used. FFish says maybe a special GDB hierarchy
10315@c (eg rooted in val of env var GDBSYMS) could exist for mappable symbol
10316@c files.
10317
c906108c
SS
10318@kindex core-file
10319@item core-file @r{[} @var{filename} @r{]}
4644b6e3 10320@itemx core
c906108c
SS
10321Specify the whereabouts of a core dump file to be used as the ``contents
10322of memory''. Traditionally, core files contain only some parts of the
10323address space of the process that generated them; @value{GDBN} can access the
10324executable file itself for other parts.
10325
10326@code{core-file} with no argument specifies that no core file is
10327to be used.
10328
10329Note that the core file is ignored when your program is actually running
7a292a7a
SS
10330under @value{GDBN}. So, if you have been running your program and you
10331wish to debug a core file instead, you must kill the subprocess in which
10332the program is running. To do this, use the @code{kill} command
c906108c 10333(@pxref{Kill Process, ,Killing the child process}).
c906108c 10334
c906108c
SS
10335@kindex add-symbol-file
10336@cindex dynamic linking
10337@item add-symbol-file @var{filename} @var{address}
10338@itemx add-symbol-file @var{filename} @var{address} @r{[} -readnow @r{]} @r{[} -mapped @r{]}
17d9d558 10339@itemx add-symbol-file @var{filename} @r{-s}@var{section} @var{address} @dots{}
96a2c332
SS
10340The @code{add-symbol-file} command reads additional symbol table
10341information from the file @var{filename}. You would use this command
10342when @var{filename} has been dynamically loaded (by some other means)
10343into the program that is running. @var{address} should be the memory
10344address at which the file has been loaded; @value{GDBN} cannot figure
d167840f
EZ
10345this out for itself. You can additionally specify an arbitrary number
10346of @samp{@r{-s}@var{section} @var{address}} pairs, to give an explicit
10347section name and base address for that section. You can specify any
10348@var{address} as an expression.
c906108c
SS
10349
10350The symbol table of the file @var{filename} is added to the symbol table
10351originally read with the @code{symbol-file} command. You can use the
96a2c332
SS
10352@code{add-symbol-file} command any number of times; the new symbol data
10353thus read keeps adding to the old. To discard all old symbol data
10354instead, use the @code{symbol-file} command without any arguments.
c906108c 10355
17d9d558
JB
10356@cindex relocatable object files, reading symbols from
10357@cindex object files, relocatable, reading symbols from
10358@cindex reading symbols from relocatable object files
10359@cindex symbols, reading from relocatable object files
10360@cindex @file{.o} files, reading symbols from
10361Although @var{filename} is typically a shared library file, an
10362executable file, or some other object file which has been fully
10363relocated for loading into a process, you can also load symbolic
10364information from relocatable @file{.o} files, as long as:
10365
10366@itemize @bullet
10367@item
10368the file's symbolic information refers only to linker symbols defined in
10369that file, not to symbols defined by other object files,
10370@item
10371every section the file's symbolic information refers to has actually
10372been loaded into the inferior, as it appears in the file, and
10373@item
10374you can determine the address at which every section was loaded, and
10375provide these to the @code{add-symbol-file} command.
10376@end itemize
10377
10378@noindent
10379Some embedded operating systems, like Sun Chorus and VxWorks, can load
10380relocatable files into an already running program; such systems
10381typically make the requirements above easy to meet. However, it's
10382important to recognize that many native systems use complex link
49efadf5 10383procedures (@code{.linkonce} section factoring and C@t{++} constructor table
17d9d558
JB
10384assembly, for example) that make the requirements difficult to meet. In
10385general, one cannot assume that using @code{add-symbol-file} to read a
10386relocatable object file's symbolic information will have the same effect
10387as linking the relocatable object file into the program in the normal
10388way.
10389
c906108c
SS
10390@code{add-symbol-file} does not repeat if you press @key{RET} after using it.
10391
10392You can use the @samp{-mapped} and @samp{-readnow} options just as with
10393the @code{symbol-file} command, to change how @value{GDBN} manages the symbol
10394table information for @var{filename}.
10395
10396@kindex add-shared-symbol-file
10397@item add-shared-symbol-file
10398The @code{add-shared-symbol-file} command can be used only under Harris' CXUX
5d161b24
DB
10399operating system for the Motorola 88k. @value{GDBN} automatically looks for
10400shared libraries, however if @value{GDBN} does not find yours, you can run
c906108c 10401@code{add-shared-symbol-file}. It takes no arguments.
c906108c 10402
c906108c
SS
10403@kindex section
10404@item section
5d161b24
DB
10405The @code{section} command changes the base address of section SECTION of
10406the exec file to ADDR. This can be used if the exec file does not contain
10407section addresses, (such as in the a.out format), or when the addresses
10408specified in the file itself are wrong. Each section must be changed
d4f3574e
SS
10409separately. The @code{info files} command, described below, lists all
10410the sections and their addresses.
c906108c
SS
10411
10412@kindex info files
10413@kindex info target
10414@item info files
10415@itemx info target
7a292a7a
SS
10416@code{info files} and @code{info target} are synonymous; both print the
10417current target (@pxref{Targets, ,Specifying a Debugging Target}),
10418including the names of the executable and core dump files currently in
10419use by @value{GDBN}, and the files from which symbols were loaded. The
10420command @code{help target} lists all possible targets rather than
10421current ones.
10422
fe95c787
MS
10423@kindex maint info sections
10424@item maint info sections
10425Another command that can give you extra information about program sections
10426is @code{maint info sections}. In addition to the section information
10427displayed by @code{info files}, this command displays the flags and file
10428offset of each section in the executable and core dump files. In addition,
10429@code{maint info sections} provides the following command options (which
10430may be arbitrarily combined):
10431
10432@table @code
10433@item ALLOBJ
10434Display sections for all loaded object files, including shared libraries.
10435@item @var{sections}
6600abed 10436Display info only for named @var{sections}.
fe95c787
MS
10437@item @var{section-flags}
10438Display info only for sections for which @var{section-flags} are true.
10439The section flags that @value{GDBN} currently knows about are:
10440@table @code
10441@item ALLOC
10442Section will have space allocated in the process when loaded.
10443Set for all sections except those containing debug information.
10444@item LOAD
10445Section will be loaded from the file into the child process memory.
10446Set for pre-initialized code and data, clear for @code{.bss} sections.
10447@item RELOC
10448Section needs to be relocated before loading.
10449@item READONLY
10450Section cannot be modified by the child process.
10451@item CODE
10452Section contains executable code only.
6600abed 10453@item DATA
fe95c787
MS
10454Section contains data only (no executable code).
10455@item ROM
10456Section will reside in ROM.
10457@item CONSTRUCTOR
10458Section contains data for constructor/destructor lists.
10459@item HAS_CONTENTS
10460Section is not empty.
10461@item NEVER_LOAD
10462An instruction to the linker to not output the section.
10463@item COFF_SHARED_LIBRARY
10464A notification to the linker that the section contains
10465COFF shared library information.
10466@item IS_COMMON
10467Section contains common symbols.
10468@end table
10469@end table
6763aef9
MS
10470@kindex set trust-readonly-sections
10471@item set trust-readonly-sections on
10472Tell @value{GDBN} that readonly sections in your object file
6ca652b0 10473really are read-only (i.e.@: that their contents will not change).
6763aef9
MS
10474In that case, @value{GDBN} can fetch values from these sections
10475out of the object file, rather than from the target program.
10476For some targets (notably embedded ones), this can be a significant
10477enhancement to debugging performance.
10478
10479The default is off.
10480
10481@item set trust-readonly-sections off
15110bc3 10482Tell @value{GDBN} not to trust readonly sections. This means that
6763aef9
MS
10483the contents of the section might change while the program is running,
10484and must therefore be fetched from the target when needed.
c906108c
SS
10485@end table
10486
10487All file-specifying commands allow both absolute and relative file names
10488as arguments. @value{GDBN} always converts the file name to an absolute file
10489name and remembers it that way.
10490
c906108c 10491@cindex shared libraries
c906108c
SS
10492@value{GDBN} supports HP-UX, SunOS, SVr4, Irix 5, and IBM RS/6000 shared
10493libraries.
53a5351d 10494
c906108c
SS
10495@value{GDBN} automatically loads symbol definitions from shared libraries
10496when you use the @code{run} command, or when you examine a core file.
10497(Before you issue the @code{run} command, @value{GDBN} does not understand
10498references to a function in a shared library, however---unless you are
10499debugging a core file).
53a5351d
JM
10500
10501On HP-UX, if the program loads a library explicitly, @value{GDBN}
10502automatically loads the symbols at the time of the @code{shl_load} call.
10503
c906108c
SS
10504@c FIXME: some @value{GDBN} release may permit some refs to undef
10505@c FIXME...symbols---eg in a break cmd---assuming they are from a shared
10506@c FIXME...lib; check this from time to time when updating manual
10507
b7209cb4
FF
10508There are times, however, when you may wish to not automatically load
10509symbol definitions from shared libraries, such as when they are
10510particularly large or there are many of them.
10511
10512To control the automatic loading of shared library symbols, use the
10513commands:
10514
10515@table @code
10516@kindex set auto-solib-add
10517@item set auto-solib-add @var{mode}
10518If @var{mode} is @code{on}, symbols from all shared object libraries
10519will be loaded automatically when the inferior begins execution, you
10520attach to an independently started inferior, or when the dynamic linker
10521informs @value{GDBN} that a new library has been loaded. If @var{mode}
10522is @code{off}, symbols must be loaded manually, using the
10523@code{sharedlibrary} command. The default value is @code{on}.
10524
dcaf7c2c
EZ
10525@cindex memory used for symbol tables
10526If your program uses lots of shared libraries with debug info that
10527takes large amounts of memory, you can decrease the @value{GDBN}
10528memory footprint by preventing it from automatically loading the
10529symbols from shared libraries. To that end, type @kbd{set
10530auto-solib-add off} before running the inferior, then load each
10531library whose debug symbols you do need with @kbd{sharedlibrary
10532@var{regexp}}, where @var{regexp} is a regular expresion that matches
10533the libraries whose symbols you want to be loaded.
10534
b7209cb4
FF
10535@kindex show auto-solib-add
10536@item show auto-solib-add
10537Display the current autoloading mode.
10538@end table
10539
10540To explicitly load shared library symbols, use the @code{sharedlibrary}
10541command:
10542
c906108c
SS
10543@table @code
10544@kindex info sharedlibrary
10545@kindex info share
10546@item info share
10547@itemx info sharedlibrary
10548Print the names of the shared libraries which are currently loaded.
10549
10550@kindex sharedlibrary
10551@kindex share
10552@item sharedlibrary @var{regex}
10553@itemx share @var{regex}
c906108c
SS
10554Load shared object library symbols for files matching a
10555Unix regular expression.
10556As with files loaded automatically, it only loads shared libraries
10557required by your program for a core file or after typing @code{run}. If
10558@var{regex} is omitted all shared libraries required by your program are
10559loaded.
10560@end table
10561
b7209cb4
FF
10562On some systems, such as HP-UX systems, @value{GDBN} supports
10563autoloading shared library symbols until a limiting threshold size is
10564reached. This provides the benefit of allowing autoloading to remain on
10565by default, but avoids autoloading excessively large shared libraries,
10566up to a threshold that is initially set, but which you can modify if you
10567wish.
c906108c
SS
10568
10569Beyond that threshold, symbols from shared libraries must be explicitly
d4f3574e
SS
10570loaded. To load these symbols, use the command @code{sharedlibrary
10571@var{filename}}. The base address of the shared library is determined
c906108c
SS
10572automatically by @value{GDBN} and need not be specified.
10573
10574To display or set the threshold, use the commands:
10575
10576@table @code
b7209cb4
FF
10577@kindex set auto-solib-limit
10578@item set auto-solib-limit @var{threshold}
10579Set the autoloading size threshold, in an integral number of megabytes.
10580If @var{threshold} is nonzero and shared library autoloading is enabled,
10581symbols from all shared object libraries will be loaded until the total
10582size of the loaded shared library symbols exceeds this threshold.
c906108c 10583Otherwise, symbols must be loaded manually, using the
6ca652b0 10584@code{sharedlibrary} command. The default threshold is 100 (i.e.@: 100
b7209cb4 10585Mb).
c906108c 10586
b7209cb4
FF
10587@kindex show auto-solib-limit
10588@item show auto-solib-limit
c906108c
SS
10589Display the current autoloading size threshold, in megabytes.
10590@end table
c906108c 10591
f5ebfba0
DJ
10592Shared libraries are also supported in many cross or remote debugging
10593configurations. A copy of the target's libraries need to be present on the
10594host system; they need to be the same as the target libraries, although the
10595copies on the target can be stripped as long as the copies on the host are
10596not.
10597
10598You need to tell @value{GDBN} where the target libraries are, so that it can
10599load the correct copies---otherwise, it may try to load the host's libraries.
10600@value{GDBN} has two variables to specify the search directories for target
10601libraries.
10602
10603@table @code
10604@kindex set solib-absolute-prefix
10605@item set solib-absolute-prefix @var{path}
10606If this variable is set, @var{path} will be used as a prefix for any
10607absolute shared library paths; many runtime loaders store the absolute
10608paths to the shared library in the target program's memory. If you use
10609@samp{solib-absolute-prefix} to find shared libraries, they need to be laid
10610out in the same way that they are on the target, with e.g.@: a
10611@file{/usr/lib} hierarchy under @var{path}.
10612
10613You can set the default value of @samp{solib-absolute-prefix} by using the
10614configure-time @samp{--with-sysroot} option.
10615
10616@kindex show solib-absolute-prefix
10617@item show solib-absolute-prefix
10618Display the current shared library prefix.
10619
10620@kindex set solib-search-path
10621@item set solib-search-path @var{path}
10622If this variable is set, @var{path} is a colon-separated list of directories
10623to search for shared libraries. @samp{solib-search-path} is used after
10624@samp{solib-absolute-prefix} fails to locate the library, or if the path to
10625the library is relative instead of absolute. If you want to use
10626@samp{solib-search-path} instead of @samp{solib-absolute-prefix}, be sure to
10627set @samp{solib-absolute-prefix} to a nonexistant directory to prevent
10628@value{GDBN} from finding your host's libraries.
10629
10630@kindex show solib-search-path
10631@item show solib-search-path
10632Display the current shared library search path.
10633@end table
10634
5b5d99cf
JB
10635
10636@node Separate Debug Files
10637@section Debugging Information in Separate Files
10638@cindex separate debugging information files
10639@cindex debugging information in separate files
10640@cindex @file{.debug} subdirectories
10641@cindex debugging information directory, global
10642@cindex global debugging information directory
10643
10644@value{GDBN} allows you to put a program's debugging information in a
10645file separate from the executable itself, in a way that allows
10646@value{GDBN} to find and load the debugging information automatically.
10647Since debugging information can be very large --- sometimes larger
10648than the executable code itself --- some systems distribute debugging
10649information for their executables in separate files, which users can
10650install only when they need to debug a problem.
10651
10652If an executable's debugging information has been extracted to a
10653separate file, the executable should contain a @dfn{debug link} giving
10654the name of the debugging information file (with no directory
10655components), and a checksum of its contents. (The exact form of a
10656debug link is described below.) If the full name of the directory
10657containing the executable is @var{execdir}, and the executable has a
10658debug link that specifies the name @var{debugfile}, then @value{GDBN}
10659will automatically search for the debugging information file in three
10660places:
10661
10662@itemize @bullet
10663@item
10664the directory containing the executable file (that is, it will look
10665for a file named @file{@var{execdir}/@var{debugfile}},
10666@item
10667a subdirectory of that directory named @file{.debug} (that is, the
10668file @file{@var{execdir}/.debug/@var{debugfile}}, and
10669@item
10670a subdirectory of the global debug file directory that includes the
10671executable's full path, and the name from the link (that is, the file
10672@file{@var{globaldebugdir}/@var{execdir}/@var{debugfile}}, where
10673@var{globaldebugdir} is the global debug file directory, and
10674@var{execdir} has been turned into a relative path).
10675@end itemize
10676@noindent
10677@value{GDBN} checks under each of these names for a debugging
10678information file whose checksum matches that given in the link, and
10679reads the debugging information from the first one it finds.
10680
10681So, for example, if you ask @value{GDBN} to debug @file{/usr/bin/ls},
10682which has a link containing the name @file{ls.debug}, and the global
10683debug directory is @file{/usr/lib/debug}, then @value{GDBN} will look
10684for debug information in @file{/usr/bin/ls.debug},
10685@file{/usr/bin/.debug/ls.debug}, and
10686@file{/usr/lib/debug/usr/bin/ls.debug}.
10687
10688You can set the global debugging info directory's name, and view the
10689name @value{GDBN} is currently using.
10690
10691@table @code
10692
10693@kindex set debug-file-directory
10694@item set debug-file-directory @var{directory}
10695Set the directory which @value{GDBN} searches for separate debugging
10696information files to @var{directory}.
10697
10698@kindex show debug-file-directory
10699@item show debug-file-directory
10700Show the directory @value{GDBN} searches for separate debugging
10701information files.
10702
10703@end table
10704
10705@cindex @code{.gnu_debuglink} sections
10706@cindex debug links
10707A debug link is a special section of the executable file named
10708@code{.gnu_debuglink}. The section must contain:
10709
10710@itemize
10711@item
10712A filename, with any leading directory components removed, followed by
10713a zero byte,
10714@item
10715zero to three bytes of padding, as needed to reach the next four-byte
10716boundary within the section, and
10717@item
10718a four-byte CRC checksum, stored in the same endianness used for the
10719executable file itself. The checksum is computed on the debugging
10720information file's full contents by the function given below, passing
10721zero as the @var{crc} argument.
10722@end itemize
10723
10724Any executable file format can carry a debug link, as long as it can
10725contain a section named @code{.gnu_debuglink} with the contents
10726described above.
10727
10728The debugging information file itself should be an ordinary
10729executable, containing a full set of linker symbols, sections, and
10730debugging information. The sections of the debugging information file
10731should have the same names, addresses and sizes as the original file,
10732but they need not contain any data --- much like a @code{.bss} section
10733in an ordinary executable.
10734
10735As of December 2002, there is no standard GNU utility to produce
10736separated executable / debugging information file pairs. Ulrich
10737Drepper's @file{elfutils} package, starting with version 0.53,
10738contains a version of the @code{strip} command such that the command
10739@kbd{strip foo -f foo.debug} removes the debugging information from
10740the executable file @file{foo}, places it in the file
10741@file{foo.debug}, and leaves behind a debug link in @file{foo}.
10742
10743Since there are many different ways to compute CRC's (different
10744polynomials, reversals, byte ordering, etc.), the simplest way to
10745describe the CRC used in @code{.gnu_debuglink} sections is to give the
10746complete code for a function that computes it:
10747
4644b6e3 10748@kindex gnu_debuglink_crc32
5b5d99cf
JB
10749@smallexample
10750unsigned long
10751gnu_debuglink_crc32 (unsigned long crc,
10752 unsigned char *buf, size_t len)
10753@{
10754 static const unsigned long crc32_table[256] =
10755 @{
10756 0x00000000, 0x77073096, 0xee0e612c, 0x990951ba, 0x076dc419,
10757 0x706af48f, 0xe963a535, 0x9e6495a3, 0x0edb8832, 0x79dcb8a4,
10758 0xe0d5e91e, 0x97d2d988, 0x09b64c2b, 0x7eb17cbd, 0xe7b82d07,
10759 0x90bf1d91, 0x1db71064, 0x6ab020f2, 0xf3b97148, 0x84be41de,
10760 0x1adad47d, 0x6ddde4eb, 0xf4d4b551, 0x83d385c7, 0x136c9856,
10761 0x646ba8c0, 0xfd62f97a, 0x8a65c9ec, 0x14015c4f, 0x63066cd9,
10762 0xfa0f3d63, 0x8d080df5, 0x3b6e20c8, 0x4c69105e, 0xd56041e4,
10763 0xa2677172, 0x3c03e4d1, 0x4b04d447, 0xd20d85fd, 0xa50ab56b,
10764 0x35b5a8fa, 0x42b2986c, 0xdbbbc9d6, 0xacbcf940, 0x32d86ce3,
10765 0x45df5c75, 0xdcd60dcf, 0xabd13d59, 0x26d930ac, 0x51de003a,
10766 0xc8d75180, 0xbfd06116, 0x21b4f4b5, 0x56b3c423, 0xcfba9599,
10767 0xb8bda50f, 0x2802b89e, 0x5f058808, 0xc60cd9b2, 0xb10be924,
10768 0x2f6f7c87, 0x58684c11, 0xc1611dab, 0xb6662d3d, 0x76dc4190,
10769 0x01db7106, 0x98d220bc, 0xefd5102a, 0x71b18589, 0x06b6b51f,
10770 0x9fbfe4a5, 0xe8b8d433, 0x7807c9a2, 0x0f00f934, 0x9609a88e,
10771 0xe10e9818, 0x7f6a0dbb, 0x086d3d2d, 0x91646c97, 0xe6635c01,
10772 0x6b6b51f4, 0x1c6c6162, 0x856530d8, 0xf262004e, 0x6c0695ed,
10773 0x1b01a57b, 0x8208f4c1, 0xf50fc457, 0x65b0d9c6, 0x12b7e950,
10774 0x8bbeb8ea, 0xfcb9887c, 0x62dd1ddf, 0x15da2d49, 0x8cd37cf3,
10775 0xfbd44c65, 0x4db26158, 0x3ab551ce, 0xa3bc0074, 0xd4bb30e2,
10776 0x4adfa541, 0x3dd895d7, 0xa4d1c46d, 0xd3d6f4fb, 0x4369e96a,
10777 0x346ed9fc, 0xad678846, 0xda60b8d0, 0x44042d73, 0x33031de5,
10778 0xaa0a4c5f, 0xdd0d7cc9, 0x5005713c, 0x270241aa, 0xbe0b1010,
10779 0xc90c2086, 0x5768b525, 0x206f85b3, 0xb966d409, 0xce61e49f,
10780 0x5edef90e, 0x29d9c998, 0xb0d09822, 0xc7d7a8b4, 0x59b33d17,
10781 0x2eb40d81, 0xb7bd5c3b, 0xc0ba6cad, 0xedb88320, 0x9abfb3b6,
10782 0x03b6e20c, 0x74b1d29a, 0xead54739, 0x9dd277af, 0x04db2615,
10783 0x73dc1683, 0xe3630b12, 0x94643b84, 0x0d6d6a3e, 0x7a6a5aa8,
10784 0xe40ecf0b, 0x9309ff9d, 0x0a00ae27, 0x7d079eb1, 0xf00f9344,
10785 0x8708a3d2, 0x1e01f268, 0x6906c2fe, 0xf762575d, 0x806567cb,
10786 0x196c3671, 0x6e6b06e7, 0xfed41b76, 0x89d32be0, 0x10da7a5a,
10787 0x67dd4acc, 0xf9b9df6f, 0x8ebeeff9, 0x17b7be43, 0x60b08ed5,
10788 0xd6d6a3e8, 0xa1d1937e, 0x38d8c2c4, 0x4fdff252, 0xd1bb67f1,
10789 0xa6bc5767, 0x3fb506dd, 0x48b2364b, 0xd80d2bda, 0xaf0a1b4c,
10790 0x36034af6, 0x41047a60, 0xdf60efc3, 0xa867df55, 0x316e8eef,
10791 0x4669be79, 0xcb61b38c, 0xbc66831a, 0x256fd2a0, 0x5268e236,
10792 0xcc0c7795, 0xbb0b4703, 0x220216b9, 0x5505262f, 0xc5ba3bbe,
10793 0xb2bd0b28, 0x2bb45a92, 0x5cb36a04, 0xc2d7ffa7, 0xb5d0cf31,
10794 0x2cd99e8b, 0x5bdeae1d, 0x9b64c2b0, 0xec63f226, 0x756aa39c,
10795 0x026d930a, 0x9c0906a9, 0xeb0e363f, 0x72076785, 0x05005713,
10796 0x95bf4a82, 0xe2b87a14, 0x7bb12bae, 0x0cb61b38, 0x92d28e9b,
10797 0xe5d5be0d, 0x7cdcefb7, 0x0bdbdf21, 0x86d3d2d4, 0xf1d4e242,
10798 0x68ddb3f8, 0x1fda836e, 0x81be16cd, 0xf6b9265b, 0x6fb077e1,
10799 0x18b74777, 0x88085ae6, 0xff0f6a70, 0x66063bca, 0x11010b5c,
10800 0x8f659eff, 0xf862ae69, 0x616bffd3, 0x166ccf45, 0xa00ae278,
10801 0xd70dd2ee, 0x4e048354, 0x3903b3c2, 0xa7672661, 0xd06016f7,
10802 0x4969474d, 0x3e6e77db, 0xaed16a4a, 0xd9d65adc, 0x40df0b66,
10803 0x37d83bf0, 0xa9bcae53, 0xdebb9ec5, 0x47b2cf7f, 0x30b5ffe9,
10804 0xbdbdf21c, 0xcabac28a, 0x53b39330, 0x24b4a3a6, 0xbad03605,
10805 0xcdd70693, 0x54de5729, 0x23d967bf, 0xb3667a2e, 0xc4614ab8,
10806 0x5d681b02, 0x2a6f2b94, 0xb40bbe37, 0xc30c8ea1, 0x5a05df1b,
10807 0x2d02ef8d
10808 @};
10809 unsigned char *end;
10810
10811 crc = ~crc & 0xffffffff;
10812 for (end = buf + len; buf < end; ++buf)
10813 crc = crc32_table[(crc ^ *buf) & 0xff] ^ (crc >> 8);
e7a3abfc 10814 return ~crc & 0xffffffff;
5b5d99cf
JB
10815@}
10816@end smallexample
10817
10818
6d2ebf8b 10819@node Symbol Errors
c906108c
SS
10820@section Errors reading symbol files
10821
10822While reading a symbol file, @value{GDBN} occasionally encounters problems,
10823such as symbol types it does not recognize, or known bugs in compiler
10824output. By default, @value{GDBN} does not notify you of such problems, since
10825they are relatively common and primarily of interest to people
10826debugging compilers. If you are interested in seeing information
10827about ill-constructed symbol tables, you can either ask @value{GDBN} to print
10828only one message about each such type of problem, no matter how many
10829times the problem occurs; or you can ask @value{GDBN} to print more messages,
10830to see how many times the problems occur, with the @code{set
10831complaints} command (@pxref{Messages/Warnings, ,Optional warnings and
10832messages}).
10833
10834The messages currently printed, and their meanings, include:
10835
10836@table @code
10837@item inner block not inside outer block in @var{symbol}
10838
10839The symbol information shows where symbol scopes begin and end
10840(such as at the start of a function or a block of statements). This
10841error indicates that an inner scope block is not fully contained
10842in its outer scope blocks.
10843
10844@value{GDBN} circumvents the problem by treating the inner block as if it had
10845the same scope as the outer block. In the error message, @var{symbol}
10846may be shown as ``@code{(don't know)}'' if the outer block is not a
10847function.
10848
10849@item block at @var{address} out of order
10850
10851The symbol information for symbol scope blocks should occur in
10852order of increasing addresses. This error indicates that it does not
10853do so.
10854
10855@value{GDBN} does not circumvent this problem, and has trouble
10856locating symbols in the source file whose symbols it is reading. (You
10857can often determine what source file is affected by specifying
10858@code{set verbose on}. @xref{Messages/Warnings, ,Optional warnings and
10859messages}.)
10860
10861@item bad block start address patched
10862
10863The symbol information for a symbol scope block has a start address
10864smaller than the address of the preceding source line. This is known
10865to occur in the SunOS 4.1.1 (and earlier) C compiler.
10866
10867@value{GDBN} circumvents the problem by treating the symbol scope block as
10868starting on the previous source line.
10869
10870@item bad string table offset in symbol @var{n}
10871
10872@cindex foo
10873Symbol number @var{n} contains a pointer into the string table which is
10874larger than the size of the string table.
10875
10876@value{GDBN} circumvents the problem by considering the symbol to have the
10877name @code{foo}, which may cause other problems if many symbols end up
10878with this name.
10879
10880@item unknown symbol type @code{0x@var{nn}}
10881
7a292a7a
SS
10882The symbol information contains new data types that @value{GDBN} does
10883not yet know how to read. @code{0x@var{nn}} is the symbol type of the
d4f3574e 10884uncomprehended information, in hexadecimal.
c906108c 10885
7a292a7a
SS
10886@value{GDBN} circumvents the error by ignoring this symbol information.
10887This usually allows you to debug your program, though certain symbols
c906108c 10888are not accessible. If you encounter such a problem and feel like
7a292a7a
SS
10889debugging it, you can debug @code{@value{GDBP}} with itself, breakpoint
10890on @code{complain}, then go up to the function @code{read_dbx_symtab}
10891and examine @code{*bufp} to see the symbol.
c906108c
SS
10892
10893@item stub type has NULL name
c906108c 10894
7a292a7a 10895@value{GDBN} could not find the full definition for a struct or class.
c906108c 10896
7a292a7a 10897@item const/volatile indicator missing (ok if using g++ v1.x), got@dots{}
b37052ae 10898The symbol information for a C@t{++} member function is missing some
7a292a7a
SS
10899information that recent versions of the compiler should have output for
10900it.
c906108c
SS
10901
10902@item info mismatch between compiler and debugger
10903
10904@value{GDBN} could not parse a type specification output by the compiler.
7a292a7a 10905
c906108c
SS
10906@end table
10907
6d2ebf8b 10908@node Targets
c906108c 10909@chapter Specifying a Debugging Target
7a292a7a 10910
c906108c
SS
10911@cindex debugging target
10912@kindex target
10913
10914A @dfn{target} is the execution environment occupied by your program.
53a5351d
JM
10915
10916Often, @value{GDBN} runs in the same host environment as your program;
10917in that case, the debugging target is specified as a side effect when
10918you use the @code{file} or @code{core} commands. When you need more
c906108c
SS
10919flexibility---for example, running @value{GDBN} on a physically separate
10920host, or controlling a standalone system over a serial port or a
53a5351d
JM
10921realtime system over a TCP/IP connection---you can use the @code{target}
10922command to specify one of the target types configured for @value{GDBN}
10923(@pxref{Target Commands, ,Commands for managing targets}).
c906108c
SS
10924
10925@menu
10926* Active Targets:: Active targets
10927* Target Commands:: Commands for managing targets
c906108c
SS
10928* Byte Order:: Choosing target byte order
10929* Remote:: Remote debugging
96baa820 10930* KOD:: Kernel Object Display
c906108c
SS
10931
10932@end menu
10933
6d2ebf8b 10934@node Active Targets
c906108c 10935@section Active targets
7a292a7a 10936
c906108c
SS
10937@cindex stacking targets
10938@cindex active targets
10939@cindex multiple targets
10940
c906108c 10941There are three classes of targets: processes, core files, and
7a292a7a
SS
10942executable files. @value{GDBN} can work concurrently on up to three
10943active targets, one in each class. This allows you to (for example)
10944start a process and inspect its activity without abandoning your work on
10945a core file.
c906108c
SS
10946
10947For example, if you execute @samp{gdb a.out}, then the executable file
10948@code{a.out} is the only active target. If you designate a core file as
10949well---presumably from a prior run that crashed and coredumped---then
10950@value{GDBN} has two active targets and uses them in tandem, looking
10951first in the corefile target, then in the executable file, to satisfy
10952requests for memory addresses. (Typically, these two classes of target
10953are complementary, since core files contain only a program's
10954read-write memory---variables and so on---plus machine status, while
10955executable files contain only the program text and initialized data.)
c906108c
SS
10956
10957When you type @code{run}, your executable file becomes an active process
7a292a7a
SS
10958target as well. When a process target is active, all @value{GDBN}
10959commands requesting memory addresses refer to that target; addresses in
10960an active core file or executable file target are obscured while the
10961process target is active.
c906108c 10962
7a292a7a
SS
10963Use the @code{core-file} and @code{exec-file} commands to select a new
10964core file or executable target (@pxref{Files, ,Commands to specify
c906108c 10965files}). To specify as a target a process that is already running, use
7a292a7a
SS
10966the @code{attach} command (@pxref{Attach, ,Debugging an already-running
10967process}).
c906108c 10968
6d2ebf8b 10969@node Target Commands
c906108c
SS
10970@section Commands for managing targets
10971
10972@table @code
10973@item target @var{type} @var{parameters}
7a292a7a
SS
10974Connects the @value{GDBN} host environment to a target machine or
10975process. A target is typically a protocol for talking to debugging
10976facilities. You use the argument @var{type} to specify the type or
10977protocol of the target machine.
c906108c
SS
10978
10979Further @var{parameters} are interpreted by the target protocol, but
10980typically include things like device names or host names to connect
10981with, process numbers, and baud rates.
c906108c
SS
10982
10983The @code{target} command does not repeat if you press @key{RET} again
10984after executing the command.
10985
10986@kindex help target
10987@item help target
10988Displays the names of all targets available. To display targets
10989currently selected, use either @code{info target} or @code{info files}
10990(@pxref{Files, ,Commands to specify files}).
10991
10992@item help target @var{name}
10993Describe a particular target, including any parameters necessary to
10994select it.
10995
10996@kindex set gnutarget
10997@item set gnutarget @var{args}
5d161b24 10998@value{GDBN} uses its own library BFD to read your files. @value{GDBN}
c906108c 10999knows whether it is reading an @dfn{executable},
5d161b24
DB
11000a @dfn{core}, or a @dfn{.o} file; however, you can specify the file format
11001with the @code{set gnutarget} command. Unlike most @code{target} commands,
c906108c
SS
11002with @code{gnutarget} the @code{target} refers to a program, not a machine.
11003
d4f3574e 11004@quotation
c906108c
SS
11005@emph{Warning:} To specify a file format with @code{set gnutarget},
11006you must know the actual BFD name.
d4f3574e 11007@end quotation
c906108c 11008
d4f3574e
SS
11009@noindent
11010@xref{Files, , Commands to specify files}.
c906108c 11011
5d161b24 11012@kindex show gnutarget
c906108c
SS
11013@item show gnutarget
11014Use the @code{show gnutarget} command to display what file format
11015@code{gnutarget} is set to read. If you have not set @code{gnutarget},
11016@value{GDBN} will determine the file format for each file automatically,
11017and @code{show gnutarget} displays @samp{The current BDF target is "auto"}.
11018@end table
11019
4644b6e3 11020@cindex common targets
c906108c
SS
11021Here are some common targets (available, or not, depending on the GDB
11022configuration):
c906108c
SS
11023
11024@table @code
4644b6e3 11025@kindex target
c906108c 11026@item target exec @var{program}
4644b6e3 11027@cindex executable file target
c906108c
SS
11028An executable file. @samp{target exec @var{program}} is the same as
11029@samp{exec-file @var{program}}.
11030
c906108c 11031@item target core @var{filename}
4644b6e3 11032@cindex core dump file target
c906108c
SS
11033A core dump file. @samp{target core @var{filename}} is the same as
11034@samp{core-file @var{filename}}.
c906108c 11035
c906108c 11036@item target remote @var{dev}
4644b6e3 11037@cindex remote target
c906108c
SS
11038Remote serial target in GDB-specific protocol. The argument @var{dev}
11039specifies what serial device to use for the connection (e.g.
11040@file{/dev/ttya}). @xref{Remote, ,Remote debugging}. @code{target remote}
d4f3574e 11041supports the @code{load} command. This is only useful if you have
c906108c
SS
11042some other way of getting the stub to the target system, and you can put
11043it somewhere in memory where it won't get clobbered by the download.
11044
c906108c 11045@item target sim
4644b6e3 11046@cindex built-in simulator target
2df3850c 11047Builtin CPU simulator. @value{GDBN} includes simulators for most architectures.
104c1213 11048In general,
474c8240 11049@smallexample
104c1213
JM
11050 target sim
11051 load
11052 run
474c8240 11053@end smallexample
d4f3574e 11054@noindent
104c1213 11055works; however, you cannot assume that a specific memory map, device
d4f3574e 11056drivers, or even basic I/O is available, although some simulators do
104c1213
JM
11057provide these. For info about any processor-specific simulator details,
11058see the appropriate section in @ref{Embedded Processors, ,Embedded
11059Processors}.
11060
c906108c
SS
11061@end table
11062
104c1213 11063Some configurations may include these targets as well:
c906108c
SS
11064
11065@table @code
11066
c906108c 11067@item target nrom @var{dev}
4644b6e3 11068@cindex NetROM ROM emulator target
c906108c
SS
11069NetROM ROM emulator. This target only supports downloading.
11070
c906108c
SS
11071@end table
11072
5d161b24 11073Different targets are available on different configurations of @value{GDBN};
c906108c 11074your configuration may have more or fewer targets.
c906108c
SS
11075
11076Many remote targets require you to download the executable's code
11077once you've successfully established a connection.
11078
11079@table @code
11080
11081@kindex load @var{filename}
11082@item load @var{filename}
c906108c
SS
11083Depending on what remote debugging facilities are configured into
11084@value{GDBN}, the @code{load} command may be available. Where it exists, it
11085is meant to make @var{filename} (an executable) available for debugging
11086on the remote system---by downloading, or dynamic linking, for example.
11087@code{load} also records the @var{filename} symbol table in @value{GDBN}, like
11088the @code{add-symbol-file} command.
11089
11090If your @value{GDBN} does not have a @code{load} command, attempting to
11091execute it gets the error message ``@code{You can't do that when your
11092target is @dots{}}''
c906108c
SS
11093
11094The file is loaded at whatever address is specified in the executable.
11095For some object file formats, you can specify the load address when you
11096link the program; for other formats, like a.out, the object file format
11097specifies a fixed address.
11098@c FIXME! This would be a good place for an xref to the GNU linker doc.
11099
c906108c
SS
11100@code{load} does not repeat if you press @key{RET} again after using it.
11101@end table
11102
6d2ebf8b 11103@node Byte Order
c906108c 11104@section Choosing target byte order
7a292a7a 11105
c906108c
SS
11106@cindex choosing target byte order
11107@cindex target byte order
c906108c 11108
172c2a43 11109Some types of processors, such as the MIPS, PowerPC, and Renesas SH,
c906108c
SS
11110offer the ability to run either big-endian or little-endian byte
11111orders. Usually the executable or symbol will include a bit to
11112designate the endian-ness, and you will not need to worry about
11113which to use. However, you may still find it useful to adjust
d4f3574e 11114@value{GDBN}'s idea of processor endian-ness manually.
c906108c
SS
11115
11116@table @code
4644b6e3 11117@kindex set endian
c906108c
SS
11118@item set endian big
11119Instruct @value{GDBN} to assume the target is big-endian.
11120
c906108c
SS
11121@item set endian little
11122Instruct @value{GDBN} to assume the target is little-endian.
11123
c906108c
SS
11124@item set endian auto
11125Instruct @value{GDBN} to use the byte order associated with the
11126executable.
11127
11128@item show endian
11129Display @value{GDBN}'s current idea of the target byte order.
11130
11131@end table
11132
11133Note that these commands merely adjust interpretation of symbolic
11134data on the host, and that they have absolutely no effect on the
11135target system.
11136
6d2ebf8b 11137@node Remote
c906108c
SS
11138@section Remote debugging
11139@cindex remote debugging
11140
11141If you are trying to debug a program running on a machine that cannot run
5d161b24
DB
11142@value{GDBN} in the usual way, it is often useful to use remote debugging.
11143For example, you might use remote debugging on an operating system kernel,
c906108c
SS
11144or on a small system which does not have a general purpose operating system
11145powerful enough to run a full-featured debugger.
11146
11147Some configurations of @value{GDBN} have special serial or TCP/IP interfaces
11148to make this work with particular debugging targets. In addition,
5d161b24 11149@value{GDBN} comes with a generic serial protocol (specific to @value{GDBN},
c906108c
SS
11150but not specific to any particular target system) which you can use if you
11151write the remote stubs---the code that runs on the remote system to
11152communicate with @value{GDBN}.
11153
11154Other remote targets may be available in your
11155configuration of @value{GDBN}; use @code{help target} to list them.
c906108c 11156
6f05cf9f
AC
11157@node KOD
11158@section Kernel Object Display
6f05cf9f 11159@cindex kernel object display
6f05cf9f
AC
11160@cindex KOD
11161
11162Some targets support kernel object display. Using this facility,
11163@value{GDBN} communicates specially with the underlying operating system
11164and can display information about operating system-level objects such as
11165mutexes and other synchronization objects. Exactly which objects can be
11166displayed is determined on a per-OS basis.
11167
3bbe9696 11168@kindex set os
6f05cf9f
AC
11169Use the @code{set os} command to set the operating system. This tells
11170@value{GDBN} which kernel object display module to initialize:
11171
474c8240 11172@smallexample
6f05cf9f 11173(@value{GDBP}) set os cisco
474c8240 11174@end smallexample
6f05cf9f 11175
3bbe9696
EZ
11176@kindex show os
11177The associated command @code{show os} displays the operating system
11178set with the @code{set os} command; if no operating system has been
11179set, @code{show os} will display an empty string @samp{""}.
11180
6f05cf9f
AC
11181If @code{set os} succeeds, @value{GDBN} will display some information
11182about the operating system, and will create a new @code{info} command
11183which can be used to query the target. The @code{info} command is named
11184after the operating system:
c906108c 11185
3bbe9696 11186@kindex info cisco
474c8240 11187@smallexample
6f05cf9f
AC
11188(@value{GDBP}) info cisco
11189List of Cisco Kernel Objects
11190Object Description
11191any Any and all objects
474c8240 11192@end smallexample
6f05cf9f
AC
11193
11194Further subcommands can be used to query about particular objects known
11195by the kernel.
11196
3bbe9696
EZ
11197There is currently no way to determine whether a given operating
11198system is supported other than to try setting it with @kbd{set os
11199@var{name}}, where @var{name} is the name of the operating system you
11200want to try.
6f05cf9f
AC
11201
11202
11203@node Remote Debugging
11204@chapter Debugging remote programs
11205
6b2f586d 11206@menu
07f31aa6 11207* Connecting:: Connecting to a remote target
6b2f586d
AC
11208* Server:: Using the gdbserver program
11209* NetWare:: Using the gdbserve.nlm program
501eef12 11210* Remote configuration:: Remote configuration
6b2f586d 11211* remote stub:: Implementing a remote stub
6b2f586d
AC
11212@end menu
11213
07f31aa6
DJ
11214@node Connecting
11215@section Connecting to a remote target
11216
11217On the @value{GDBN} host machine, you will need an unstripped copy of
11218your program, since @value{GDBN} needs symobl and debugging information.
11219Start up @value{GDBN} as usual, using the name of the local copy of your
11220program as the first argument.
11221
11222@cindex serial line, @code{target remote}
11223If you're using a serial line, you may want to give @value{GDBN} the
11224@w{@samp{--baud}} option, or use the @code{set remotebaud} command
11225before the @code{target} command.
11226
11227After that, use @code{target remote} to establish communications with
11228the target machine. Its argument specifies how to communicate---either
11229via a devicename attached to a direct serial line, or a TCP or UDP port
11230(possibly to a terminal server which in turn has a serial line to the
11231target). For example, to use a serial line connected to the device
11232named @file{/dev/ttyb}:
11233
11234@smallexample
11235target remote /dev/ttyb
11236@end smallexample
11237
11238@cindex TCP port, @code{target remote}
11239To use a TCP connection, use an argument of the form
11240@code{@var{host}:@var{port}} or @code{tcp:@var{host}:@var{port}}.
11241For example, to connect to port 2828 on a
11242terminal server named @code{manyfarms}:
11243
11244@smallexample
11245target remote manyfarms:2828
11246@end smallexample
11247
11248If your remote target is actually running on the same machine as
11249your debugger session (e.g.@: a simulator of your target running on
11250the same host), you can omit the hostname. For example, to connect
11251to port 1234 on your local machine:
11252
11253@smallexample
11254target remote :1234
11255@end smallexample
11256@noindent
11257
11258Note that the colon is still required here.
11259
11260@cindex UDP port, @code{target remote}
11261To use a UDP connection, use an argument of the form
11262@code{udp:@var{host}:@var{port}}. For example, to connect to UDP port 2828
11263on a terminal server named @code{manyfarms}:
11264
11265@smallexample
11266target remote udp:manyfarms:2828
11267@end smallexample
11268
11269When using a UDP connection for remote debugging, you should keep in mind
11270that the `U' stands for ``Unreliable''. UDP can silently drop packets on
11271busy or unreliable networks, which will cause havoc with your debugging
11272session.
11273
11274Now you can use all the usual commands to examine and change data and to
11275step and continue the remote program.
11276
11277@cindex interrupting remote programs
11278@cindex remote programs, interrupting
11279Whenever @value{GDBN} is waiting for the remote program, if you type the
11280interrupt character (often @key{C-C}), @value{GDBN} attempts to stop the
11281program. This may or may not succeed, depending in part on the hardware
11282and the serial drivers the remote system uses. If you type the
11283interrupt character once again, @value{GDBN} displays this prompt:
11284
11285@smallexample
11286Interrupted while waiting for the program.
11287Give up (and stop debugging it)? (y or n)
11288@end smallexample
11289
11290If you type @kbd{y}, @value{GDBN} abandons the remote debugging session.
11291(If you decide you want to try again later, you can use @samp{target
11292remote} again to connect once more.) If you type @kbd{n}, @value{GDBN}
11293goes back to waiting.
11294
11295@table @code
11296@kindex detach (remote)
11297@item detach
11298When you have finished debugging the remote program, you can use the
11299@code{detach} command to release it from @value{GDBN} control.
11300Detaching from the target normally resumes its execution, but the results
11301will depend on your particular remote stub. After the @code{detach}
11302command, @value{GDBN} is free to connect to another target.
11303
11304@kindex disconnect
11305@item disconnect
11306The @code{disconnect} command behaves like @code{detach}, except that
11307the target is generally not resumed. It will wait for @value{GDBN}
11308(this instance or another one) to connect and continue debugging. After
11309the @code{disconnect} command, @value{GDBN} is again free to connect to
11310another target.
11311@end table
11312
6f05cf9f
AC
11313@node Server
11314@section Using the @code{gdbserver} program
11315
11316@kindex gdbserver
11317@cindex remote connection without stubs
11318@code{gdbserver} is a control program for Unix-like systems, which
11319allows you to connect your program with a remote @value{GDBN} via
11320@code{target remote}---but without linking in the usual debugging stub.
11321
11322@code{gdbserver} is not a complete replacement for the debugging stubs,
11323because it requires essentially the same operating-system facilities
11324that @value{GDBN} itself does. In fact, a system that can run
11325@code{gdbserver} to connect to a remote @value{GDBN} could also run
11326@value{GDBN} locally! @code{gdbserver} is sometimes useful nevertheless,
11327because it is a much smaller program than @value{GDBN} itself. It is
11328also easier to port than all of @value{GDBN}, so you may be able to get
11329started more quickly on a new system by using @code{gdbserver}.
11330Finally, if you develop code for real-time systems, you may find that
11331the tradeoffs involved in real-time operation make it more convenient to
11332do as much development work as possible on another system, for example
11333by cross-compiling. You can use @code{gdbserver} to make a similar
11334choice for debugging.
11335
11336@value{GDBN} and @code{gdbserver} communicate via either a serial line
11337or a TCP connection, using the standard @value{GDBN} remote serial
11338protocol.
11339
11340@table @emph
11341@item On the target machine,
11342you need to have a copy of the program you want to debug.
11343@code{gdbserver} does not need your program's symbol table, so you can
11344strip the program if necessary to save space. @value{GDBN} on the host
11345system does all the symbol handling.
11346
11347To use the server, you must tell it how to communicate with @value{GDBN};
56460a61 11348the name of your program; and the arguments for your program. The usual
6f05cf9f
AC
11349syntax is:
11350
11351@smallexample
11352target> gdbserver @var{comm} @var{program} [ @var{args} @dots{} ]
11353@end smallexample
11354
11355@var{comm} is either a device name (to use a serial line) or a TCP
11356hostname and portnumber. For example, to debug Emacs with the argument
11357@samp{foo.txt} and communicate with @value{GDBN} over the serial port
11358@file{/dev/com1}:
11359
11360@smallexample
11361target> gdbserver /dev/com1 emacs foo.txt
11362@end smallexample
11363
11364@code{gdbserver} waits passively for the host @value{GDBN} to communicate
11365with it.
11366
11367To use a TCP connection instead of a serial line:
11368
11369@smallexample
11370target> gdbserver host:2345 emacs foo.txt
11371@end smallexample
11372
11373The only difference from the previous example is the first argument,
11374specifying that you are communicating with the host @value{GDBN} via
11375TCP. The @samp{host:2345} argument means that @code{gdbserver} is to
11376expect a TCP connection from machine @samp{host} to local TCP port 2345.
11377(Currently, the @samp{host} part is ignored.) You can choose any number
11378you want for the port number as long as it does not conflict with any
11379TCP ports already in use on the target system (for example, @code{23} is
11380reserved for @code{telnet}).@footnote{If you choose a port number that
11381conflicts with another service, @code{gdbserver} prints an error message
11382and exits.} You must use the same port number with the host @value{GDBN}
11383@code{target remote} command.
11384
56460a61
DJ
11385On some targets, @code{gdbserver} can also attach to running programs.
11386This is accomplished via the @code{--attach} argument. The syntax is:
11387
11388@smallexample
11389target> gdbserver @var{comm} --attach @var{pid}
11390@end smallexample
11391
11392@var{pid} is the process ID of a currently running process. It isn't necessary
11393to point @code{gdbserver} at a binary for the running process.
11394
b1fe9455
DJ
11395@pindex pidof
11396@cindex attach to a program by name
11397You can debug processes by name instead of process ID if your target has the
11398@code{pidof} utility:
11399
11400@smallexample
11401target> gdbserver @var{comm} --attach `pidof @var{PROGRAM}`
11402@end smallexample
11403
11404In case more than one copy of @var{PROGRAM} is running, or @var{PROGRAM}
11405has multiple threads, most versions of @code{pidof} support the
11406@code{-s} option to only return the first process ID.
11407
07f31aa6
DJ
11408@item On the host machine,
11409connect to your target (@pxref{Connecting,,Connecting to a remote target}).
6f05cf9f
AC
11410For TCP connections, you must start up @code{gdbserver} prior to using
11411the @code{target remote} command. Otherwise you may get an error whose
11412text depends on the host system, but which usually looks something like
07f31aa6
DJ
11413@samp{Connection refused}. You don't need to use the @code{load}
11414command in @value{GDBN} when using gdbserver, since the program is
11415already on the target.
11416
6f05cf9f
AC
11417@end table
11418
11419@node NetWare
11420@section Using the @code{gdbserve.nlm} program
11421
11422@kindex gdbserve.nlm
11423@code{gdbserve.nlm} is a control program for NetWare systems, which
11424allows you to connect your program with a remote @value{GDBN} via
11425@code{target remote}.
11426
11427@value{GDBN} and @code{gdbserve.nlm} communicate via a serial line,
11428using the standard @value{GDBN} remote serial protocol.
11429
11430@table @emph
11431@item On the target machine,
11432you need to have a copy of the program you want to debug.
11433@code{gdbserve.nlm} does not need your program's symbol table, so you
11434can strip the program if necessary to save space. @value{GDBN} on the
11435host system does all the symbol handling.
11436
11437To use the server, you must tell it how to communicate with
11438@value{GDBN}; the name of your program; and the arguments for your
11439program. The syntax is:
11440
11441@smallexample
11442load gdbserve [ BOARD=@var{board} ] [ PORT=@var{port} ]
11443 [ BAUD=@var{baud} ] @var{program} [ @var{args} @dots{} ]
11444@end smallexample
11445
11446@var{board} and @var{port} specify the serial line; @var{baud} specifies
11447the baud rate used by the connection. @var{port} and @var{node} default
11448to 0, @var{baud} defaults to 9600@dmn{bps}.
11449
11450For example, to debug Emacs with the argument @samp{foo.txt}and
11451communicate with @value{GDBN} over serial port number 2 or board 1
11452using a 19200@dmn{bps} connection:
11453
11454@smallexample
11455load gdbserve BOARD=1 PORT=2 BAUD=19200 emacs foo.txt
11456@end smallexample
11457
07f31aa6
DJ
11458@item
11459On the @value{GDBN} host machine, connect to your target (@pxref{Connecting,,
11460Connecting to a remote target}).
6f05cf9f 11461
6f05cf9f
AC
11462@end table
11463
501eef12
AC
11464@node Remote configuration
11465@section Remote configuration
11466
11467The following configuration options are available when debugging remote
11468programs:
11469
11470@table @code
11471@kindex set remote hardware-watchpoint-limit
11472@kindex set remote hardware-breakpoint-limit
11473@anchor{set remote hardware-watchpoint-limit}
11474@anchor{set remote hardware-breakpoint-limit}
11475@item set remote hardware-watchpoint-limit @var{limit}
11476@itemx set remote hardware-breakpoint-limit @var{limit}
11477Restrict @value{GDBN} to using @var{limit} remote hardware breakpoint or
11478watchpoints. A limit of -1, the default, is treated as unlimited.
11479@end table
11480
6f05cf9f
AC
11481@node remote stub
11482@section Implementing a remote stub
7a292a7a 11483
8e04817f
AC
11484@cindex debugging stub, example
11485@cindex remote stub, example
11486@cindex stub example, remote debugging
11487The stub files provided with @value{GDBN} implement the target side of the
11488communication protocol, and the @value{GDBN} side is implemented in the
11489@value{GDBN} source file @file{remote.c}. Normally, you can simply allow
11490these subroutines to communicate, and ignore the details. (If you're
11491implementing your own stub file, you can still ignore the details: start
11492with one of the existing stub files. @file{sparc-stub.c} is the best
11493organized, and therefore the easiest to read.)
11494
104c1213
JM
11495@cindex remote serial debugging, overview
11496To debug a program running on another machine (the debugging
11497@dfn{target} machine), you must first arrange for all the usual
11498prerequisites for the program to run by itself. For example, for a C
11499program, you need:
c906108c 11500
104c1213
JM
11501@enumerate
11502@item
11503A startup routine to set up the C runtime environment; these usually
11504have a name like @file{crt0}. The startup routine may be supplied by
11505your hardware supplier, or you may have to write your own.
96baa820 11506
5d161b24 11507@item
d4f3574e 11508A C subroutine library to support your program's
104c1213 11509subroutine calls, notably managing input and output.
96baa820 11510
104c1213
JM
11511@item
11512A way of getting your program to the other machine---for example, a
11513download program. These are often supplied by the hardware
11514manufacturer, but you may have to write your own from hardware
11515documentation.
11516@end enumerate
96baa820 11517
104c1213
JM
11518The next step is to arrange for your program to use a serial port to
11519communicate with the machine where @value{GDBN} is running (the @dfn{host}
11520machine). In general terms, the scheme looks like this:
96baa820 11521
104c1213
JM
11522@table @emph
11523@item On the host,
11524@value{GDBN} already understands how to use this protocol; when everything
11525else is set up, you can simply use the @samp{target remote} command
11526(@pxref{Targets,,Specifying a Debugging Target}).
11527
11528@item On the target,
11529you must link with your program a few special-purpose subroutines that
11530implement the @value{GDBN} remote serial protocol. The file containing these
11531subroutines is called a @dfn{debugging stub}.
11532
11533On certain remote targets, you can use an auxiliary program
11534@code{gdbserver} instead of linking a stub into your program.
11535@xref{Server,,Using the @code{gdbserver} program}, for details.
11536@end table
96baa820 11537
104c1213
JM
11538The debugging stub is specific to the architecture of the remote
11539machine; for example, use @file{sparc-stub.c} to debug programs on
11540@sc{sparc} boards.
96baa820 11541
104c1213
JM
11542@cindex remote serial stub list
11543These working remote stubs are distributed with @value{GDBN}:
96baa820 11544
104c1213
JM
11545@table @code
11546
11547@item i386-stub.c
41afff9a 11548@cindex @file{i386-stub.c}
104c1213
JM
11549@cindex Intel
11550@cindex i386
11551For Intel 386 and compatible architectures.
11552
11553@item m68k-stub.c
41afff9a 11554@cindex @file{m68k-stub.c}
104c1213
JM
11555@cindex Motorola 680x0
11556@cindex m680x0
11557For Motorola 680x0 architectures.
11558
11559@item sh-stub.c
41afff9a 11560@cindex @file{sh-stub.c}
172c2a43 11561@cindex Renesas
104c1213 11562@cindex SH
172c2a43 11563For Renesas SH architectures.
104c1213
JM
11564
11565@item sparc-stub.c
41afff9a 11566@cindex @file{sparc-stub.c}
104c1213
JM
11567@cindex Sparc
11568For @sc{sparc} architectures.
11569
11570@item sparcl-stub.c
41afff9a 11571@cindex @file{sparcl-stub.c}
104c1213
JM
11572@cindex Fujitsu
11573@cindex SparcLite
11574For Fujitsu @sc{sparclite} architectures.
11575
11576@end table
11577
11578The @file{README} file in the @value{GDBN} distribution may list other
11579recently added stubs.
11580
11581@menu
11582* Stub Contents:: What the stub can do for you
11583* Bootstrapping:: What you must do for the stub
11584* Debug Session:: Putting it all together
104c1213
JM
11585@end menu
11586
6d2ebf8b 11587@node Stub Contents
6f05cf9f 11588@subsection What the stub can do for you
104c1213
JM
11589
11590@cindex remote serial stub
11591The debugging stub for your architecture supplies these three
11592subroutines:
11593
11594@table @code
11595@item set_debug_traps
4644b6e3 11596@findex set_debug_traps
104c1213
JM
11597@cindex remote serial stub, initialization
11598This routine arranges for @code{handle_exception} to run when your
11599program stops. You must call this subroutine explicitly near the
11600beginning of your program.
11601
11602@item handle_exception
4644b6e3 11603@findex handle_exception
104c1213
JM
11604@cindex remote serial stub, main routine
11605This is the central workhorse, but your program never calls it
11606explicitly---the setup code arranges for @code{handle_exception} to
11607run when a trap is triggered.
11608
11609@code{handle_exception} takes control when your program stops during
11610execution (for example, on a breakpoint), and mediates communications
11611with @value{GDBN} on the host machine. This is where the communications
11612protocol is implemented; @code{handle_exception} acts as the @value{GDBN}
d4f3574e 11613representative on the target machine. It begins by sending summary
104c1213
JM
11614information on the state of your program, then continues to execute,
11615retrieving and transmitting any information @value{GDBN} needs, until you
11616execute a @value{GDBN} command that makes your program resume; at that point,
11617@code{handle_exception} returns control to your own code on the target
5d161b24 11618machine.
104c1213
JM
11619
11620@item breakpoint
11621@cindex @code{breakpoint} subroutine, remote
11622Use this auxiliary subroutine to make your program contain a
11623breakpoint. Depending on the particular situation, this may be the only
11624way for @value{GDBN} to get control. For instance, if your target
11625machine has some sort of interrupt button, you won't need to call this;
11626pressing the interrupt button transfers control to
11627@code{handle_exception}---in effect, to @value{GDBN}. On some machines,
11628simply receiving characters on the serial port may also trigger a trap;
11629again, in that situation, you don't need to call @code{breakpoint} from
11630your own program---simply running @samp{target remote} from the host
5d161b24 11631@value{GDBN} session gets control.
104c1213
JM
11632
11633Call @code{breakpoint} if none of these is true, or if you simply want
11634to make certain your program stops at a predetermined point for the
11635start of your debugging session.
11636@end table
11637
6d2ebf8b 11638@node Bootstrapping
6f05cf9f 11639@subsection What you must do for the stub
104c1213
JM
11640
11641@cindex remote stub, support routines
11642The debugging stubs that come with @value{GDBN} are set up for a particular
11643chip architecture, but they have no information about the rest of your
11644debugging target machine.
11645
11646First of all you need to tell the stub how to communicate with the
11647serial port.
11648
11649@table @code
11650@item int getDebugChar()
4644b6e3 11651@findex getDebugChar
104c1213
JM
11652Write this subroutine to read a single character from the serial port.
11653It may be identical to @code{getchar} for your target system; a
11654different name is used to allow you to distinguish the two if you wish.
11655
11656@item void putDebugChar(int)
4644b6e3 11657@findex putDebugChar
104c1213 11658Write this subroutine to write a single character to the serial port.
5d161b24 11659It may be identical to @code{putchar} for your target system; a
104c1213
JM
11660different name is used to allow you to distinguish the two if you wish.
11661@end table
11662
11663@cindex control C, and remote debugging
11664@cindex interrupting remote targets
11665If you want @value{GDBN} to be able to stop your program while it is
11666running, you need to use an interrupt-driven serial driver, and arrange
11667for it to stop when it receives a @code{^C} (@samp{\003}, the control-C
11668character). That is the character which @value{GDBN} uses to tell the
11669remote system to stop.
11670
11671Getting the debugging target to return the proper status to @value{GDBN}
11672probably requires changes to the standard stub; one quick and dirty way
11673is to just execute a breakpoint instruction (the ``dirty'' part is that
11674@value{GDBN} reports a @code{SIGTRAP} instead of a @code{SIGINT}).
11675
11676Other routines you need to supply are:
11677
11678@table @code
11679@item void exceptionHandler (int @var{exception_number}, void *@var{exception_address})
4644b6e3 11680@findex exceptionHandler
104c1213
JM
11681Write this function to install @var{exception_address} in the exception
11682handling tables. You need to do this because the stub does not have any
11683way of knowing what the exception handling tables on your target system
11684are like (for example, the processor's table might be in @sc{rom},
11685containing entries which point to a table in @sc{ram}).
11686@var{exception_number} is the exception number which should be changed;
11687its meaning is architecture-dependent (for example, different numbers
11688might represent divide by zero, misaligned access, etc). When this
11689exception occurs, control should be transferred directly to
11690@var{exception_address}, and the processor state (stack, registers,
11691and so on) should be just as it is when a processor exception occurs. So if
11692you want to use a jump instruction to reach @var{exception_address}, it
11693should be a simple jump, not a jump to subroutine.
11694
11695For the 386, @var{exception_address} should be installed as an interrupt
11696gate so that interrupts are masked while the handler runs. The gate
11697should be at privilege level 0 (the most privileged level). The
11698@sc{sparc} and 68k stubs are able to mask interrupts themselves without
11699help from @code{exceptionHandler}.
11700
11701@item void flush_i_cache()
4644b6e3 11702@findex flush_i_cache
d4f3574e 11703On @sc{sparc} and @sc{sparclite} only, write this subroutine to flush the
104c1213
JM
11704instruction cache, if any, on your target machine. If there is no
11705instruction cache, this subroutine may be a no-op.
11706
11707On target machines that have instruction caches, @value{GDBN} requires this
11708function to make certain that the state of your program is stable.
11709@end table
11710
11711@noindent
11712You must also make sure this library routine is available:
11713
11714@table @code
11715@item void *memset(void *, int, int)
4644b6e3 11716@findex memset
104c1213
JM
11717This is the standard library function @code{memset} that sets an area of
11718memory to a known value. If you have one of the free versions of
11719@code{libc.a}, @code{memset} can be found there; otherwise, you must
11720either obtain it from your hardware manufacturer, or write your own.
11721@end table
11722
11723If you do not use the GNU C compiler, you may need other standard
11724library subroutines as well; this varies from one stub to another,
11725but in general the stubs are likely to use any of the common library
d4f3574e 11726subroutines which @code{@value{GCC}} generates as inline code.
104c1213
JM
11727
11728
6d2ebf8b 11729@node Debug Session
6f05cf9f 11730@subsection Putting it all together
104c1213
JM
11731
11732@cindex remote serial debugging summary
11733In summary, when your program is ready to debug, you must follow these
11734steps.
11735
11736@enumerate
11737@item
6d2ebf8b 11738Make sure you have defined the supporting low-level routines
104c1213
JM
11739(@pxref{Bootstrapping,,What you must do for the stub}):
11740@display
11741@code{getDebugChar}, @code{putDebugChar},
11742@code{flush_i_cache}, @code{memset}, @code{exceptionHandler}.
11743@end display
11744
11745@item
11746Insert these lines near the top of your program:
11747
474c8240 11748@smallexample
104c1213
JM
11749set_debug_traps();
11750breakpoint();
474c8240 11751@end smallexample
104c1213
JM
11752
11753@item
11754For the 680x0 stub only, you need to provide a variable called
11755@code{exceptionHook}. Normally you just use:
11756
474c8240 11757@smallexample
104c1213 11758void (*exceptionHook)() = 0;
474c8240 11759@end smallexample
104c1213 11760
d4f3574e 11761@noindent
104c1213 11762but if before calling @code{set_debug_traps}, you set it to point to a
598ca718 11763function in your program, that function is called when
104c1213
JM
11764@code{@value{GDBN}} continues after stopping on a trap (for example, bus
11765error). The function indicated by @code{exceptionHook} is called with
11766one parameter: an @code{int} which is the exception number.
11767
11768@item
11769Compile and link together: your program, the @value{GDBN} debugging stub for
11770your target architecture, and the supporting subroutines.
11771
11772@item
11773Make sure you have a serial connection between your target machine and
11774the @value{GDBN} host, and identify the serial port on the host.
11775
11776@item
11777@c The "remote" target now provides a `load' command, so we should
11778@c document that. FIXME.
11779Download your program to your target machine (or get it there by
11780whatever means the manufacturer provides), and start it.
11781
11782@item
07f31aa6
DJ
11783Start @value{GDBN} on the host, and connect to the target
11784(@pxref{Connecting,,Connecting to a remote target}).
9db8d71f 11785
104c1213
JM
11786@end enumerate
11787
8e04817f
AC
11788@node Configurations
11789@chapter Configuration-Specific Information
104c1213 11790
8e04817f
AC
11791While nearly all @value{GDBN} commands are available for all native and
11792cross versions of the debugger, there are some exceptions. This chapter
11793describes things that are only available in certain configurations.
104c1213 11794
8e04817f
AC
11795There are three major categories of configurations: native
11796configurations, where the host and target are the same, embedded
11797operating system configurations, which are usually the same for several
11798different processor architectures, and bare embedded processors, which
11799are quite different from each other.
104c1213 11800
8e04817f
AC
11801@menu
11802* Native::
11803* Embedded OS::
11804* Embedded Processors::
11805* Architectures::
11806@end menu
104c1213 11807
8e04817f
AC
11808@node Native
11809@section Native
104c1213 11810
8e04817f
AC
11811This section describes details specific to particular native
11812configurations.
6cf7e474 11813
8e04817f
AC
11814@menu
11815* HP-UX:: HP-UX
7561d450 11816* BSD libkvm Interface:: Debugging BSD kernel memory images
8e04817f
AC
11817* SVR4 Process Information:: SVR4 process information
11818* DJGPP Native:: Features specific to the DJGPP port
78c47bea 11819* Cygwin Native:: Features specific to the Cygwin port
8e04817f 11820@end menu
6cf7e474 11821
8e04817f
AC
11822@node HP-UX
11823@subsection HP-UX
104c1213 11824
8e04817f
AC
11825On HP-UX systems, if you refer to a function or variable name that
11826begins with a dollar sign, @value{GDBN} searches for a user or system
11827name first, before it searches for a convenience variable.
104c1213 11828
7561d450
MK
11829@node BSD libkvm Interface
11830@subsection BSD libkvm Interface
11831
11832@cindex libkvm
11833@cindex kernel memory image
11834@cindex kernel crash dump
11835
11836BSD-derived systems (FreeBSD/NetBSD/OpenBSD) have a kernel memory
11837interface that provides a uniform interface for accessing kernel virtual
11838memory images, including live systems and crash dumps. @value{GDBN}
11839uses this interface to allow you to debug live kernels and kernel crash
11840dumps on many native BSD configurations. This is implemented as a
11841special @code{kvm} debugging target. For debugging a live system, load
11842the currently running kernel into @value{GDBN} and connect to the
11843@code{kvm} target:
11844
11845@smallexample
11846(@value{GDBP}) @b{target kvm}
11847@end smallexample
11848
11849For debugging crash dumps, provide the file name of the crash dump as an
11850argument:
11851
11852@smallexample
11853(@value{GDBP}) @b{target kvm /var/crash/bsd.0}
11854@end smallexample
11855
11856Once connected to the @code{kvm} target, the following commands are
11857available:
11858
11859@table @code
11860@kindex kvm
11861@item kvm pcb
11862Set current context from pcb address.
11863
11864@item kvm proc
11865Set current context from proc address. This command isn't available on
11866modern FreeBSD systems.
11867@end table
11868
8e04817f
AC
11869@node SVR4 Process Information
11870@subsection SVR4 process information
60bf7e09
EZ
11871@cindex /proc
11872@cindex examine process image
11873@cindex process info via @file{/proc}
104c1213 11874
60bf7e09
EZ
11875Many versions of SVR4 and compatible systems provide a facility called
11876@samp{/proc} that can be used to examine the image of a running
11877process using file-system subroutines. If @value{GDBN} is configured
11878for an operating system with this facility, the command @code{info
11879proc} is available to report information about the process running
11880your program, or about any process running on your system. @code{info
11881proc} works only on SVR4 systems that include the @code{procfs} code.
11882This includes, as of this writing, @sc{gnu}/Linux, OSF/1 (Digital
11883Unix), Solaris, Irix, and Unixware, but not HP-UX, for example.
104c1213 11884
8e04817f
AC
11885@table @code
11886@kindex info proc
60bf7e09 11887@cindex process ID
8e04817f 11888@item info proc
60bf7e09
EZ
11889@itemx info proc @var{process-id}
11890Summarize available information about any running process. If a
11891process ID is specified by @var{process-id}, display information about
11892that process; otherwise display information about the program being
11893debugged. The summary includes the debugged process ID, the command
11894line used to invoke it, its current working directory, and its
11895executable file's absolute file name.
11896
11897On some systems, @var{process-id} can be of the form
11898@samp{[@var{pid}]/@var{tid}} which specifies a certain thread ID
11899within a process. If the optional @var{pid} part is missing, it means
11900a thread from the process being debugged (the leading @samp{/} still
11901needs to be present, or else @value{GDBN} will interpret the number as
11902a process ID rather than a thread ID).
6cf7e474 11903
8e04817f 11904@item info proc mappings
60bf7e09
EZ
11905@cindex memory address space mappings
11906Report the memory address space ranges accessible in the program, with
11907information on whether the process has read, write, or execute access
11908rights to each range. On @sc{gnu}/Linux systems, each memory range
11909includes the object file which is mapped to that range, instead of the
11910memory access rights to that range.
11911
11912@item info proc stat
11913@itemx info proc status
11914@cindex process detailed status information
11915These subcommands are specific to @sc{gnu}/Linux systems. They show
11916the process-related information, including the user ID and group ID;
11917how many threads are there in the process; its virtual memory usage;
11918the signals that are pending, blocked, and ignored; its TTY; its
11919consumption of system and user time; its stack size; its @samp{nice}
11920value; etc. For more information, see the @samp{proc(5)} man page
11921(type @kbd{man 5 proc} from your shell prompt).
11922
11923@item info proc all
11924Show all the information about the process described under all of the
11925above @code{info proc} subcommands.
11926
8e04817f
AC
11927@ignore
11928@comment These sub-options of 'info proc' were not included when
11929@comment procfs.c was re-written. Keep their descriptions around
11930@comment against the day when someone finds the time to put them back in.
11931@kindex info proc times
11932@item info proc times
11933Starting time, user CPU time, and system CPU time for your program and
11934its children.
6cf7e474 11935
8e04817f
AC
11936@kindex info proc id
11937@item info proc id
11938Report on the process IDs related to your program: its own process ID,
11939the ID of its parent, the process group ID, and the session ID.
8e04817f
AC
11940@end ignore
11941@end table
104c1213 11942
8e04817f
AC
11943@node DJGPP Native
11944@subsection Features for Debugging @sc{djgpp} Programs
11945@cindex @sc{djgpp} debugging
11946@cindex native @sc{djgpp} debugging
11947@cindex MS-DOS-specific commands
104c1213 11948
8e04817f
AC
11949@sc{djgpp} is the port of @sc{gnu} development tools to MS-DOS and
11950MS-Windows. @sc{djgpp} programs are 32-bit protected-mode programs
11951that use the @dfn{DPMI} (DOS Protected-Mode Interface) API to run on
11952top of real-mode DOS systems and their emulations.
104c1213 11953
8e04817f
AC
11954@value{GDBN} supports native debugging of @sc{djgpp} programs, and
11955defines a few commands specific to the @sc{djgpp} port. This
11956subsection describes those commands.
104c1213 11957
8e04817f
AC
11958@table @code
11959@kindex info dos
11960@item info dos
11961This is a prefix of @sc{djgpp}-specific commands which print
11962information about the target system and important OS structures.
f1251bdd 11963
8e04817f
AC
11964@kindex sysinfo
11965@cindex MS-DOS system info
11966@cindex free memory information (MS-DOS)
11967@item info dos sysinfo
11968This command displays assorted information about the underlying
11969platform: the CPU type and features, the OS version and flavor, the
11970DPMI version, and the available conventional and DPMI memory.
104c1213 11971
8e04817f
AC
11972@cindex GDT
11973@cindex LDT
11974@cindex IDT
11975@cindex segment descriptor tables
11976@cindex descriptor tables display
11977@item info dos gdt
11978@itemx info dos ldt
11979@itemx info dos idt
11980These 3 commands display entries from, respectively, Global, Local,
11981and Interrupt Descriptor Tables (GDT, LDT, and IDT). The descriptor
11982tables are data structures which store a descriptor for each segment
11983that is currently in use. The segment's selector is an index into a
11984descriptor table; the table entry for that index holds the
11985descriptor's base address and limit, and its attributes and access
11986rights.
104c1213 11987
8e04817f
AC
11988A typical @sc{djgpp} program uses 3 segments: a code segment, a data
11989segment (used for both data and the stack), and a DOS segment (which
11990allows access to DOS/BIOS data structures and absolute addresses in
11991conventional memory). However, the DPMI host will usually define
11992additional segments in order to support the DPMI environment.
d4f3574e 11993
8e04817f
AC
11994@cindex garbled pointers
11995These commands allow to display entries from the descriptor tables.
11996Without an argument, all entries from the specified table are
11997displayed. An argument, which should be an integer expression, means
11998display a single entry whose index is given by the argument. For
11999example, here's a convenient way to display information about the
12000debugged program's data segment:
104c1213 12001
8e04817f
AC
12002@smallexample
12003@exdent @code{(@value{GDBP}) info dos ldt $ds}
12004@exdent @code{0x13f: base=0x11970000 limit=0x0009ffff 32-Bit Data (Read/Write, Exp-up)}
12005@end smallexample
104c1213 12006
8e04817f
AC
12007@noindent
12008This comes in handy when you want to see whether a pointer is outside
12009the data segment's limit (i.e.@: @dfn{garbled}).
104c1213 12010
8e04817f
AC
12011@cindex page tables display (MS-DOS)
12012@item info dos pde
12013@itemx info dos pte
12014These two commands display entries from, respectively, the Page
12015Directory and the Page Tables. Page Directories and Page Tables are
12016data structures which control how virtual memory addresses are mapped
12017into physical addresses. A Page Table includes an entry for every
12018page of memory that is mapped into the program's address space; there
12019may be several Page Tables, each one holding up to 4096 entries. A
12020Page Directory has up to 4096 entries, one each for every Page Table
12021that is currently in use.
104c1213 12022
8e04817f
AC
12023Without an argument, @kbd{info dos pde} displays the entire Page
12024Directory, and @kbd{info dos pte} displays all the entries in all of
12025the Page Tables. An argument, an integer expression, given to the
12026@kbd{info dos pde} command means display only that entry from the Page
12027Directory table. An argument given to the @kbd{info dos pte} command
12028means display entries from a single Page Table, the one pointed to by
12029the specified entry in the Page Directory.
104c1213 12030
8e04817f
AC
12031@cindex direct memory access (DMA) on MS-DOS
12032These commands are useful when your program uses @dfn{DMA} (Direct
12033Memory Access), which needs physical addresses to program the DMA
12034controller.
104c1213 12035
8e04817f 12036These commands are supported only with some DPMI servers.
104c1213 12037
8e04817f
AC
12038@cindex physical address from linear address
12039@item info dos address-pte @var{addr}
12040This command displays the Page Table entry for a specified linear
12041address. The argument linear address @var{addr} should already have the
12042appropriate segment's base address added to it, because this command
12043accepts addresses which may belong to @emph{any} segment. For
12044example, here's how to display the Page Table entry for the page where
12045the variable @code{i} is stored:
104c1213 12046
b383017d 12047@smallexample
8e04817f
AC
12048@exdent @code{(@value{GDBP}) info dos address-pte __djgpp_base_address + (char *)&i}
12049@exdent @code{Page Table entry for address 0x11a00d30:}
b383017d 12050@exdent @code{Base=0x02698000 Dirty Acc. Not-Cached Write-Back Usr Read-Write +0xd30}
8e04817f 12051@end smallexample
104c1213 12052
8e04817f
AC
12053@noindent
12054This says that @code{i} is stored at offset @code{0xd30} from the page
12055whose physical base address is @code{0x02698000}, and prints all the
12056attributes of that page.
104c1213 12057
8e04817f
AC
12058Note that you must cast the addresses of variables to a @code{char *},
12059since otherwise the value of @code{__djgpp_base_address}, the base
12060address of all variables and functions in a @sc{djgpp} program, will
12061be added using the rules of C pointer arithmetics: if @code{i} is
12062declared an @code{int}, @value{GDBN} will add 4 times the value of
12063@code{__djgpp_base_address} to the address of @code{i}.
104c1213 12064
8e04817f
AC
12065Here's another example, it displays the Page Table entry for the
12066transfer buffer:
104c1213 12067
8e04817f
AC
12068@smallexample
12069@exdent @code{(@value{GDBP}) info dos address-pte *((unsigned *)&_go32_info_block + 3)}
12070@exdent @code{Page Table entry for address 0x29110:}
12071@exdent @code{Base=0x00029000 Dirty Acc. Not-Cached Write-Back Usr Read-Write +0x110}
12072@end smallexample
104c1213 12073
8e04817f
AC
12074@noindent
12075(The @code{+ 3} offset is because the transfer buffer's address is the
120763rd member of the @code{_go32_info_block} structure.) The output of
12077this command clearly shows that addresses in conventional memory are
12078mapped 1:1, i.e.@: the physical and linear addresses are identical.
104c1213 12079
8e04817f
AC
12080This command is supported only with some DPMI servers.
12081@end table
104c1213 12082
78c47bea
PM
12083@node Cygwin Native
12084@subsection Features for Debugging MS Windows PE executables
12085@cindex MS Windows debugging
12086@cindex native Cygwin debugging
12087@cindex Cygwin-specific commands
12088
be448670
CF
12089@value{GDBN} supports native debugging of MS Windows programs, including
12090DLLs with and without symbolic debugging information. There are various
12091additional Cygwin-specific commands, described in this subsection. The
12092subsubsection @pxref{Non-debug DLL symbols} describes working with DLLs
12093that have no debugging symbols.
12094
78c47bea
PM
12095
12096@table @code
12097@kindex info w32
12098@item info w32
12099This is a prefix of MS Windows specific commands which print
12100information about the target system and important OS structures.
12101
12102@item info w32 selector
12103This command displays information returned by
12104the Win32 API @code{GetThreadSelectorEntry} function.
12105It takes an optional argument that is evaluated to
12106a long value to give the information about this given selector.
12107Without argument, this command displays information
12108about the the six segment registers.
12109
12110@kindex info dll
12111@item info dll
12112This is a Cygwin specific alias of info shared.
12113
12114@kindex dll-symbols
12115@item dll-symbols
12116This command loads symbols from a dll similarly to
12117add-sym command but without the need to specify a base address.
12118
b383017d 12119@kindex set new-console
78c47bea 12120@item set new-console @var{mode}
b383017d 12121If @var{mode} is @code{on} the debuggee will
78c47bea
PM
12122be started in a new console on next start.
12123If @var{mode} is @code{off}i, the debuggee will
12124be started in the same console as the debugger.
12125
12126@kindex show new-console
12127@item show new-console
12128Displays whether a new console is used
12129when the debuggee is started.
12130
12131@kindex set new-group
12132@item set new-group @var{mode}
12133This boolean value controls whether the debuggee should
12134start a new group or stay in the same group as the debugger.
12135This affects the way the Windows OS handles
12136Ctrl-C.
12137
12138@kindex show new-group
12139@item show new-group
12140Displays current value of new-group boolean.
12141
12142@kindex set debugevents
12143@item set debugevents
12144This boolean value adds debug output concerning events seen by the debugger.
12145
12146@kindex set debugexec
12147@item set debugexec
b383017d 12148This boolean value adds debug output concerning execute events
78c47bea
PM
12149seen by the debugger.
12150
12151@kindex set debugexceptions
12152@item set debugexceptions
b383017d 12153This boolean value adds debug ouptut concerning exception events
78c47bea
PM
12154seen by the debugger.
12155
12156@kindex set debugmemory
12157@item set debugmemory
b383017d 12158This boolean value adds debug ouptut concerning memory events
78c47bea
PM
12159seen by the debugger.
12160
12161@kindex set shell
12162@item set shell
12163This boolean values specifies whether the debuggee is called
12164via a shell or directly (default value is on).
12165
12166@kindex show shell
12167@item show shell
12168Displays if the debuggee will be started with a shell.
12169
12170@end table
12171
be448670
CF
12172@menu
12173* Non-debug DLL symbols:: Support for DLLs without debugging symbols
12174@end menu
12175
12176@node Non-debug DLL symbols
12177@subsubsection Support for DLLs without debugging symbols
12178@cindex DLLs with no debugging symbols
12179@cindex Minimal symbols and DLLs
12180
12181Very often on windows, some of the DLLs that your program relies on do
12182not include symbolic debugging information (for example,
12183@file{kernel32.dll}). When @value{GDBN} doesn't recognize any debugging
12184symbols in a DLL, it relies on the minimal amount of symbolic
12185information contained in the DLL's export table. This subsubsection
12186describes working with such symbols, known internally to @value{GDBN} as
12187``minimal symbols''.
12188
12189Note that before the debugged program has started execution, no DLLs
12190will have been loaded. The easiest way around this problem is simply to
12191start the program --- either by setting a breakpoint or letting the
12192program run once to completion. It is also possible to force
12193@value{GDBN} to load a particular DLL before starting the executable ---
12194see the shared library information in @pxref{Files} or the
12195@code{dll-symbols} command in @pxref{Cygwin Native}. Currently,
12196explicitly loading symbols from a DLL with no debugging information will
12197cause the symbol names to be duplicated in @value{GDBN}'s lookup table,
12198which may adversely affect symbol lookup performance.
12199
12200@subsubsection DLL name prefixes
12201
12202In keeping with the naming conventions used by the Microsoft debugging
12203tools, DLL export symbols are made available with a prefix based on the
12204DLL name, for instance @code{KERNEL32!CreateFileA}. The plain name is
12205also entered into the symbol table, so @code{CreateFileA} is often
12206sufficient. In some cases there will be name clashes within a program
12207(particularly if the executable itself includes full debugging symbols)
12208necessitating the use of the fully qualified name when referring to the
12209contents of the DLL. Use single-quotes around the name to avoid the
12210exclamation mark (``!'') being interpreted as a language operator.
12211
12212Note that the internal name of the DLL may be all upper-case, even
12213though the file name of the DLL is lower-case, or vice-versa. Since
12214symbols within @value{GDBN} are @emph{case-sensitive} this may cause
12215some confusion. If in doubt, try the @code{info functions} and
12216@code{info variables} commands or even @code{maint print msymbols} (see
12217@pxref{Symbols}). Here's an example:
12218
12219@smallexample
f7dc1244 12220(@value{GDBP}) info function CreateFileA
be448670
CF
12221All functions matching regular expression "CreateFileA":
12222
12223Non-debugging symbols:
122240x77e885f4 CreateFileA
122250x77e885f4 KERNEL32!CreateFileA
12226@end smallexample
12227
12228@smallexample
f7dc1244 12229(@value{GDBP}) info function !
be448670
CF
12230All functions matching regular expression "!":
12231
12232Non-debugging symbols:
122330x6100114c cygwin1!__assert
122340x61004034 cygwin1!_dll_crt0@@0
122350x61004240 cygwin1!dll_crt0(per_process *)
12236[etc...]
12237@end smallexample
12238
12239@subsubsection Working with minimal symbols
12240
12241Symbols extracted from a DLL's export table do not contain very much
12242type information. All that @value{GDBN} can do is guess whether a symbol
12243refers to a function or variable depending on the linker section that
12244contains the symbol. Also note that the actual contents of the memory
12245contained in a DLL are not available unless the program is running. This
12246means that you cannot examine the contents of a variable or disassemble
12247a function within a DLL without a running program.
12248
12249Variables are generally treated as pointers and dereferenced
12250automatically. For this reason, it is often necessary to prefix a
12251variable name with the address-of operator (``&'') and provide explicit
12252type information in the command. Here's an example of the type of
12253problem:
12254
12255@smallexample
f7dc1244 12256(@value{GDBP}) print 'cygwin1!__argv'
be448670
CF
12257$1 = 268572168
12258@end smallexample
12259
12260@smallexample
f7dc1244 12261(@value{GDBP}) x 'cygwin1!__argv'
be448670
CF
122620x10021610: "\230y\""
12263@end smallexample
12264
12265And two possible solutions:
12266
12267@smallexample
f7dc1244 12268(@value{GDBP}) print ((char **)'cygwin1!__argv')[0]
be448670
CF
12269$2 = 0x22fd98 "/cygdrive/c/mydirectory/myprogram"
12270@end smallexample
12271
12272@smallexample
f7dc1244 12273(@value{GDBP}) x/2x &'cygwin1!__argv'
be448670 122740x610c0aa8 <cygwin1!__argv>: 0x10021608 0x00000000
f7dc1244 12275(@value{GDBP}) x/x 0x10021608
be448670 122760x10021608: 0x0022fd98
f7dc1244 12277(@value{GDBP}) x/s 0x0022fd98
be448670
CF
122780x22fd98: "/cygdrive/c/mydirectory/myprogram"
12279@end smallexample
12280
12281Setting a break point within a DLL is possible even before the program
12282starts execution. However, under these circumstances, @value{GDBN} can't
12283examine the initial instructions of the function in order to skip the
12284function's frame set-up code. You can work around this by using ``*&''
12285to set the breakpoint at a raw memory address:
12286
12287@smallexample
f7dc1244 12288(@value{GDBP}) break *&'python22!PyOS_Readline'
be448670
CF
12289Breakpoint 1 at 0x1e04eff0
12290@end smallexample
12291
12292The author of these extensions is not entirely convinced that setting a
12293break point within a shared DLL like @file{kernel32.dll} is completely
12294safe.
12295
8e04817f
AC
12296@node Embedded OS
12297@section Embedded Operating Systems
104c1213 12298
8e04817f
AC
12299This section describes configurations involving the debugging of
12300embedded operating systems that are available for several different
12301architectures.
d4f3574e 12302
8e04817f
AC
12303@menu
12304* VxWorks:: Using @value{GDBN} with VxWorks
12305@end menu
104c1213 12306
8e04817f
AC
12307@value{GDBN} includes the ability to debug programs running on
12308various real-time operating systems.
104c1213 12309
8e04817f
AC
12310@node VxWorks
12311@subsection Using @value{GDBN} with VxWorks
104c1213 12312
8e04817f 12313@cindex VxWorks
104c1213 12314
8e04817f 12315@table @code
104c1213 12316
8e04817f
AC
12317@kindex target vxworks
12318@item target vxworks @var{machinename}
12319A VxWorks system, attached via TCP/IP. The argument @var{machinename}
12320is the target system's machine name or IP address.
104c1213 12321
8e04817f 12322@end table
104c1213 12323
8e04817f
AC
12324On VxWorks, @code{load} links @var{filename} dynamically on the
12325current target system as well as adding its symbols in @value{GDBN}.
104c1213 12326
8e04817f
AC
12327@value{GDBN} enables developers to spawn and debug tasks running on networked
12328VxWorks targets from a Unix host. Already-running tasks spawned from
12329the VxWorks shell can also be debugged. @value{GDBN} uses code that runs on
12330both the Unix host and on the VxWorks target. The program
12331@code{@value{GDBP}} is installed and executed on the Unix host. (It may be
12332installed with the name @code{vxgdb}, to distinguish it from a
12333@value{GDBN} for debugging programs on the host itself.)
104c1213 12334
8e04817f
AC
12335@table @code
12336@item VxWorks-timeout @var{args}
12337@kindex vxworks-timeout
12338All VxWorks-based targets now support the option @code{vxworks-timeout}.
12339This option is set by the user, and @var{args} represents the number of
12340seconds @value{GDBN} waits for responses to rpc's. You might use this if
12341your VxWorks target is a slow software simulator or is on the far side
12342of a thin network line.
12343@end table
104c1213 12344
8e04817f
AC
12345The following information on connecting to VxWorks was current when
12346this manual was produced; newer releases of VxWorks may use revised
12347procedures.
104c1213 12348
4644b6e3 12349@findex INCLUDE_RDB
8e04817f
AC
12350To use @value{GDBN} with VxWorks, you must rebuild your VxWorks kernel
12351to include the remote debugging interface routines in the VxWorks
12352library @file{rdb.a}. To do this, define @code{INCLUDE_RDB} in the
12353VxWorks configuration file @file{configAll.h} and rebuild your VxWorks
12354kernel. The resulting kernel contains @file{rdb.a}, and spawns the
12355source debugging task @code{tRdbTask} when VxWorks is booted. For more
12356information on configuring and remaking VxWorks, see the manufacturer's
12357manual.
12358@c VxWorks, see the @cite{VxWorks Programmer's Guide}.
104c1213 12359
8e04817f
AC
12360Once you have included @file{rdb.a} in your VxWorks system image and set
12361your Unix execution search path to find @value{GDBN}, you are ready to
12362run @value{GDBN}. From your Unix host, run @code{@value{GDBP}} (or
12363@code{vxgdb}, depending on your installation).
104c1213 12364
8e04817f 12365@value{GDBN} comes up showing the prompt:
104c1213 12366
474c8240 12367@smallexample
8e04817f 12368(vxgdb)
474c8240 12369@end smallexample
104c1213 12370
8e04817f
AC
12371@menu
12372* VxWorks Connection:: Connecting to VxWorks
12373* VxWorks Download:: VxWorks download
12374* VxWorks Attach:: Running tasks
12375@end menu
104c1213 12376
8e04817f
AC
12377@node VxWorks Connection
12378@subsubsection Connecting to VxWorks
104c1213 12379
8e04817f
AC
12380The @value{GDBN} command @code{target} lets you connect to a VxWorks target on the
12381network. To connect to a target whose host name is ``@code{tt}'', type:
104c1213 12382
474c8240 12383@smallexample
8e04817f 12384(vxgdb) target vxworks tt
474c8240 12385@end smallexample
104c1213 12386
8e04817f
AC
12387@need 750
12388@value{GDBN} displays messages like these:
104c1213 12389
8e04817f
AC
12390@smallexample
12391Attaching remote machine across net...
12392Connected to tt.
12393@end smallexample
104c1213 12394
8e04817f
AC
12395@need 1000
12396@value{GDBN} then attempts to read the symbol tables of any object modules
12397loaded into the VxWorks target since it was last booted. @value{GDBN} locates
12398these files by searching the directories listed in the command search
12399path (@pxref{Environment, ,Your program's environment}); if it fails
12400to find an object file, it displays a message such as:
5d161b24 12401
474c8240 12402@smallexample
8e04817f 12403prog.o: No such file or directory.
474c8240 12404@end smallexample
104c1213 12405
8e04817f
AC
12406When this happens, add the appropriate directory to the search path with
12407the @value{GDBN} command @code{path}, and execute the @code{target}
12408command again.
104c1213 12409
8e04817f
AC
12410@node VxWorks Download
12411@subsubsection VxWorks download
104c1213 12412
8e04817f
AC
12413@cindex download to VxWorks
12414If you have connected to the VxWorks target and you want to debug an
12415object that has not yet been loaded, you can use the @value{GDBN}
12416@code{load} command to download a file from Unix to VxWorks
12417incrementally. The object file given as an argument to the @code{load}
12418command is actually opened twice: first by the VxWorks target in order
12419to download the code, then by @value{GDBN} in order to read the symbol
12420table. This can lead to problems if the current working directories on
12421the two systems differ. If both systems have NFS mounted the same
12422filesystems, you can avoid these problems by using absolute paths.
12423Otherwise, it is simplest to set the working directory on both systems
12424to the directory in which the object file resides, and then to reference
12425the file by its name, without any path. For instance, a program
12426@file{prog.o} may reside in @file{@var{vxpath}/vw/demo/rdb} in VxWorks
12427and in @file{@var{hostpath}/vw/demo/rdb} on the host. To load this
12428program, type this on VxWorks:
104c1213 12429
474c8240 12430@smallexample
8e04817f 12431-> cd "@var{vxpath}/vw/demo/rdb"
474c8240 12432@end smallexample
104c1213 12433
8e04817f
AC
12434@noindent
12435Then, in @value{GDBN}, type:
104c1213 12436
474c8240 12437@smallexample
8e04817f
AC
12438(vxgdb) cd @var{hostpath}/vw/demo/rdb
12439(vxgdb) load prog.o
474c8240 12440@end smallexample
104c1213 12441
8e04817f 12442@value{GDBN} displays a response similar to this:
104c1213 12443
8e04817f
AC
12444@smallexample
12445Reading symbol data from wherever/vw/demo/rdb/prog.o... done.
12446@end smallexample
104c1213 12447
8e04817f
AC
12448You can also use the @code{load} command to reload an object module
12449after editing and recompiling the corresponding source file. Note that
12450this makes @value{GDBN} delete all currently-defined breakpoints,
12451auto-displays, and convenience variables, and to clear the value
12452history. (This is necessary in order to preserve the integrity of
12453debugger's data structures that reference the target system's symbol
12454table.)
104c1213 12455
8e04817f
AC
12456@node VxWorks Attach
12457@subsubsection Running tasks
104c1213
JM
12458
12459@cindex running VxWorks tasks
12460You can also attach to an existing task using the @code{attach} command as
12461follows:
12462
474c8240 12463@smallexample
104c1213 12464(vxgdb) attach @var{task}
474c8240 12465@end smallexample
104c1213
JM
12466
12467@noindent
12468where @var{task} is the VxWorks hexadecimal task ID. The task can be running
12469or suspended when you attach to it. Running tasks are suspended at
12470the time of attachment.
12471
6d2ebf8b 12472@node Embedded Processors
104c1213
JM
12473@section Embedded Processors
12474
12475This section goes into details specific to particular embedded
12476configurations.
12477
7d86b5d5 12478
104c1213 12479@menu
104c1213 12480* ARM:: ARM
172c2a43
KI
12481* H8/300:: Renesas H8/300
12482* H8/500:: Renesas H8/500
12483* M32R/D:: Renesas M32R/D
104c1213 12484* M68K:: Motorola M68K
104c1213 12485* MIPS Embedded:: MIPS Embedded
a37295f9 12486* OpenRISC 1000:: OpenRisc 1000
104c1213
JM
12487* PA:: HP PA Embedded
12488* PowerPC: PowerPC
172c2a43 12489* SH:: Renesas SH
104c1213
JM
12490* Sparclet:: Tsqware Sparclet
12491* Sparclite:: Fujitsu Sparclite
12492* ST2000:: Tandem ST2000
12493* Z8000:: Zilog Z8000
12494@end menu
12495
6d2ebf8b 12496@node ARM
104c1213
JM
12497@subsection ARM
12498
12499@table @code
12500
8e04817f
AC
12501@kindex target rdi
12502@item target rdi @var{dev}
12503ARM Angel monitor, via RDI library interface to ADP protocol. You may
12504use this target to communicate with both boards running the Angel
12505monitor, or with the EmbeddedICE JTAG debug device.
12506
12507@kindex target rdp
12508@item target rdp @var{dev}
12509ARM Demon monitor.
12510
12511@end table
12512
12513@node H8/300
172c2a43 12514@subsection Renesas H8/300
8e04817f
AC
12515
12516@table @code
12517
12518@kindex target hms@r{, with H8/300}
12519@item target hms @var{dev}
172c2a43 12520A Renesas SH, H8/300, or H8/500 board, attached via serial line to your host.
8e04817f
AC
12521Use special commands @code{device} and @code{speed} to control the serial
12522line and the communications speed used.
12523
12524@kindex target e7000@r{, with H8/300}
12525@item target e7000 @var{dev}
172c2a43 12526E7000 emulator for Renesas H8 and SH.
8e04817f
AC
12527
12528@kindex target sh3@r{, with H8/300}
12529@kindex target sh3e@r{, with H8/300}
12530@item target sh3 @var{dev}
12531@itemx target sh3e @var{dev}
172c2a43 12532Renesas SH-3 and SH-3E target systems.
8e04817f
AC
12533
12534@end table
12535
12536@cindex download to H8/300 or H8/500
12537@cindex H8/300 or H8/500 download
172c2a43
KI
12538@cindex download to Renesas SH
12539@cindex Renesas SH download
12540When you select remote debugging to a Renesas SH, H8/300, or H8/500
12541board, the @code{load} command downloads your program to the Renesas
8e04817f
AC
12542board and also opens it as the current executable target for
12543@value{GDBN} on your host (like the @code{file} command).
12544
12545@value{GDBN} needs to know these things to talk to your
172c2a43 12546Renesas SH, H8/300, or H8/500:
8e04817f
AC
12547
12548@enumerate
12549@item
12550that you want to use @samp{target hms}, the remote debugging interface
172c2a43
KI
12551for Renesas microprocessors, or @samp{target e7000}, the in-circuit
12552emulator for the Renesas SH and the Renesas 300H. (@samp{target hms} is
12553the default when @value{GDBN} is configured specifically for the Renesas SH,
8e04817f
AC
12554H8/300, or H8/500.)
12555
12556@item
172c2a43 12557what serial device connects your host to your Renesas board (the first
8e04817f
AC
12558serial device available on your host is the default).
12559
12560@item
12561what speed to use over the serial device.
12562@end enumerate
12563
12564@menu
172c2a43
KI
12565* Renesas Boards:: Connecting to Renesas boards.
12566* Renesas ICE:: Using the E7000 In-Circuit Emulator.
12567* Renesas Special:: Special @value{GDBN} commands for Renesas micros.
8e04817f
AC
12568@end menu
12569
172c2a43
KI
12570@node Renesas Boards
12571@subsubsection Connecting to Renesas boards
8e04817f
AC
12572
12573@c only for Unix hosts
12574@kindex device
172c2a43 12575@cindex serial device, Renesas micros
8e04817f
AC
12576Use the special @code{@value{GDBN}} command @samp{device @var{port}} if you
12577need to explicitly set the serial device. The default @var{port} is the
12578first available port on your host. This is only necessary on Unix
12579hosts, where it is typically something like @file{/dev/ttya}.
12580
12581@kindex speed
172c2a43 12582@cindex serial line speed, Renesas micros
8e04817f
AC
12583@code{@value{GDBN}} has another special command to set the communications
12584speed: @samp{speed @var{bps}}. This command also is only used from Unix
12585hosts; on DOS hosts, set the line speed as usual from outside @value{GDBN} with
12586the DOS @code{mode} command (for instance,
12587@w{@kbd{mode com2:9600,n,8,1,p}} for a 9600@dmn{bps} connection).
12588
12589The @samp{device} and @samp{speed} commands are available only when you
172c2a43 12590use a Unix host to debug your Renesas microprocessor programs. If you
8e04817f
AC
12591use a DOS host,
12592@value{GDBN} depends on an auxiliary terminate-and-stay-resident program
12593called @code{asynctsr} to communicate with the development board
12594through a PC serial port. You must also use the DOS @code{mode} command
12595to set up the serial port on the DOS side.
12596
12597The following sample session illustrates the steps needed to start a
12598program under @value{GDBN} control on an H8/300. The example uses a
12599sample H8/300 program called @file{t.x}. The procedure is the same for
172c2a43 12600the Renesas SH and the H8/500.
8e04817f
AC
12601
12602First hook up your development board. In this example, we use a
12603board attached to serial port @code{COM2}; if you use a different serial
12604port, substitute its name in the argument of the @code{mode} command.
12605When you call @code{asynctsr}, the auxiliary comms program used by the
12606debugger, you give it just the numeric part of the serial port's name;
12607for example, @samp{asyncstr 2} below runs @code{asyncstr} on
12608@code{COM2}.
12609
474c8240 12610@smallexample
8e04817f
AC
12611C:\H8300\TEST> asynctsr 2
12612C:\H8300\TEST> mode com2:9600,n,8,1,p
12613
12614Resident portion of MODE loaded
12615
12616COM2: 9600, n, 8, 1, p
12617
474c8240 12618@end smallexample
8e04817f
AC
12619
12620@quotation
12621@emph{Warning:} We have noticed a bug in PC-NFS that conflicts with
12622@code{asynctsr}. If you also run PC-NFS on your DOS host, you may need to
12623disable it, or even boot without it, to use @code{asynctsr} to control
12624your development board.
12625@end quotation
12626
12627@kindex target hms@r{, and serial protocol}
12628Now that serial communications are set up, and the development board is
12629connected, you can start up @value{GDBN}. Call @code{@value{GDBP}} with
12630the name of your program as the argument. @code{@value{GDBN}} prompts
12631you, as usual, with the prompt @samp{(@value{GDBP})}. Use two special
12632commands to begin your debugging session: @samp{target hms} to specify
172c2a43 12633cross-debugging to the Renesas board, and the @code{load} command to
8e04817f
AC
12634download your program to the board. @code{load} displays the names of
12635the program's sections, and a @samp{*} for each 2K of data downloaded.
12636(If you want to refresh @value{GDBN} data on symbols or on the
12637executable file without downloading, use the @value{GDBN} commands
12638@code{file} or @code{symbol-file}. These commands, and @code{load}
12639itself, are described in @ref{Files,,Commands to specify files}.)
12640
12641@smallexample
12642(eg-C:\H8300\TEST) @value{GDBP} t.x
12643@value{GDBN} is free software and you are welcome to distribute copies
12644 of it under certain conditions; type "show copying" to see
12645 the conditions.
12646There is absolutely no warranty for @value{GDBN}; type "show warranty"
12647for details.
12648@value{GDBN} @value{GDBVN}, Copyright 1992 Free Software Foundation, Inc...
12649(@value{GDBP}) target hms
12650Connected to remote H8/300 HMS system.
12651(@value{GDBP}) load t.x
12652.text : 0x8000 .. 0xabde ***********
12653.data : 0xabde .. 0xad30 *
12654.stack : 0xf000 .. 0xf014 *
12655@end smallexample
12656
12657At this point, you're ready to run or debug your program. From here on,
12658you can use all the usual @value{GDBN} commands. The @code{break} command
12659sets breakpoints; the @code{run} command starts your program;
12660@code{print} or @code{x} display data; the @code{continue} command
12661resumes execution after stopping at a breakpoint. You can use the
12662@code{help} command at any time to find out more about @value{GDBN} commands.
12663
12664Remember, however, that @emph{operating system} facilities aren't
12665available on your development board; for example, if your program hangs,
12666you can't send an interrupt---but you can press the @sc{reset} switch!
12667
12668Use the @sc{reset} button on the development board
12669@itemize @bullet
12670@item
12671to interrupt your program (don't use @kbd{ctl-C} on the DOS host---it has
12672no way to pass an interrupt signal to the development board); and
12673
12674@item
12675to return to the @value{GDBN} command prompt after your program finishes
12676normally. The communications protocol provides no other way for @value{GDBN}
12677to detect program completion.
12678@end itemize
12679
12680In either case, @value{GDBN} sees the effect of a @sc{reset} on the
12681development board as a ``normal exit'' of your program.
12682
172c2a43 12683@node Renesas ICE
8e04817f
AC
12684@subsubsection Using the E7000 in-circuit emulator
12685
172c2a43 12686@kindex target e7000@r{, with Renesas ICE}
8e04817f 12687You can use the E7000 in-circuit emulator to develop code for either the
172c2a43 12688Renesas SH or the H8/300H. Use one of these forms of the @samp{target
8e04817f
AC
12689e7000} command to connect @value{GDBN} to your E7000:
12690
12691@table @code
12692@item target e7000 @var{port} @var{speed}
12693Use this form if your E7000 is connected to a serial port. The
12694@var{port} argument identifies what serial port to use (for example,
12695@samp{com2}). The third argument is the line speed in bits per second
12696(for example, @samp{9600}).
12697
12698@item target e7000 @var{hostname}
12699If your E7000 is installed as a host on a TCP/IP network, you can just
12700specify its hostname; @value{GDBN} uses @code{telnet} to connect.
12701@end table
12702
172c2a43
KI
12703@node Renesas Special
12704@subsubsection Special @value{GDBN} commands for Renesas micros
8e04817f
AC
12705
12706Some @value{GDBN} commands are available only for the H8/300:
12707
12708@table @code
12709
12710@kindex set machine
12711@kindex show machine
12712@item set machine h8300
12713@itemx set machine h8300h
12714Condition @value{GDBN} for one of the two variants of the H8/300
12715architecture with @samp{set machine}. You can use @samp{show machine}
12716to check which variant is currently in effect.
104c1213
JM
12717
12718@end table
12719
8e04817f
AC
12720@node H8/500
12721@subsection H8/500
104c1213
JM
12722
12723@table @code
12724
8e04817f
AC
12725@kindex set memory @var{mod}
12726@cindex memory models, H8/500
12727@item set memory @var{mod}
12728@itemx show memory
12729Specify which H8/500 memory model (@var{mod}) you are using with
12730@samp{set memory}; check which memory model is in effect with @samp{show
12731memory}. The accepted values for @var{mod} are @code{small},
12732@code{big}, @code{medium}, and @code{compact}.
104c1213 12733
8e04817f 12734@end table
104c1213 12735
8e04817f 12736@node M32R/D
172c2a43 12737@subsection Renesas M32R/D
8e04817f
AC
12738
12739@table @code
12740
12741@kindex target m32r
12742@item target m32r @var{dev}
172c2a43 12743Renesas M32R/D ROM monitor.
8e04817f 12744
fb3e19c0
KI
12745@kindex target m32rsdi
12746@item target m32rsdi @var{dev}
12747Renesas M32R SDI server, connected via parallel port to the board.
12748
8e04817f
AC
12749@end table
12750
12751@node M68K
12752@subsection M68k
12753
12754The Motorola m68k configuration includes ColdFire support, and
12755target command for the following ROM monitors.
12756
12757@table @code
12758
12759@kindex target abug
12760@item target abug @var{dev}
12761ABug ROM monitor for M68K.
12762
12763@kindex target cpu32bug
12764@item target cpu32bug @var{dev}
12765CPU32BUG monitor, running on a CPU32 (M68K) board.
12766
12767@kindex target dbug
12768@item target dbug @var{dev}
12769dBUG ROM monitor for Motorola ColdFire.
12770
12771@kindex target est
12772@item target est @var{dev}
12773EST-300 ICE monitor, running on a CPU32 (M68K) board.
12774
12775@kindex target rom68k
12776@item target rom68k @var{dev}
12777ROM 68K monitor, running on an M68K IDP board.
12778
12779@end table
12780
8e04817f
AC
12781@table @code
12782
12783@kindex target rombug
12784@item target rombug @var{dev}
12785ROMBUG ROM monitor for OS/9000.
12786
12787@end table
12788
8e04817f
AC
12789@node MIPS Embedded
12790@subsection MIPS Embedded
12791
12792@cindex MIPS boards
12793@value{GDBN} can use the MIPS remote debugging protocol to talk to a
12794MIPS board attached to a serial line. This is available when
12795you configure @value{GDBN} with @samp{--target=mips-idt-ecoff}.
104c1213 12796
8e04817f
AC
12797@need 1000
12798Use these @value{GDBN} commands to specify the connection to your target board:
104c1213 12799
8e04817f
AC
12800@table @code
12801@item target mips @var{port}
12802@kindex target mips @var{port}
12803To run a program on the board, start up @code{@value{GDBP}} with the
12804name of your program as the argument. To connect to the board, use the
12805command @samp{target mips @var{port}}, where @var{port} is the name of
12806the serial port connected to the board. If the program has not already
12807been downloaded to the board, you may use the @code{load} command to
12808download it. You can then use all the usual @value{GDBN} commands.
104c1213 12809
8e04817f
AC
12810For example, this sequence connects to the target board through a serial
12811port, and loads and runs a program called @var{prog} through the
12812debugger:
104c1213 12813
474c8240 12814@smallexample
8e04817f
AC
12815host$ @value{GDBP} @var{prog}
12816@value{GDBN} is free software and @dots{}
12817(@value{GDBP}) target mips /dev/ttyb
12818(@value{GDBP}) load @var{prog}
12819(@value{GDBP}) run
474c8240 12820@end smallexample
104c1213 12821
8e04817f
AC
12822@item target mips @var{hostname}:@var{portnumber}
12823On some @value{GDBN} host configurations, you can specify a TCP
12824connection (for instance, to a serial line managed by a terminal
12825concentrator) instead of a serial port, using the syntax
12826@samp{@var{hostname}:@var{portnumber}}.
104c1213 12827
8e04817f
AC
12828@item target pmon @var{port}
12829@kindex target pmon @var{port}
12830PMON ROM monitor.
104c1213 12831
8e04817f
AC
12832@item target ddb @var{port}
12833@kindex target ddb @var{port}
12834NEC's DDB variant of PMON for Vr4300.
104c1213 12835
8e04817f
AC
12836@item target lsi @var{port}
12837@kindex target lsi @var{port}
12838LSI variant of PMON.
104c1213 12839
8e04817f
AC
12840@kindex target r3900
12841@item target r3900 @var{dev}
12842Densan DVE-R3900 ROM monitor for Toshiba R3900 Mips.
104c1213 12843
8e04817f
AC
12844@kindex target array
12845@item target array @var{dev}
12846Array Tech LSI33K RAID controller board.
104c1213 12847
8e04817f 12848@end table
104c1213 12849
104c1213 12850
8e04817f
AC
12851@noindent
12852@value{GDBN} also supports these special commands for MIPS targets:
104c1213 12853
8e04817f
AC
12854@table @code
12855@item set processor @var{args}
12856@itemx show processor
12857@kindex set processor @var{args}
12858@kindex show processor
12859Use the @code{set processor} command to set the type of MIPS
12860processor when you want to access processor-type-specific registers.
12861For example, @code{set processor @var{r3041}} tells @value{GDBN}
12862to use the CPU registers appropriate for the 3041 chip.
12863Use the @code{show processor} command to see what MIPS processor @value{GDBN}
12864is using. Use the @code{info reg} command to see what registers
12865@value{GDBN} is using.
104c1213 12866
8e04817f
AC
12867@item set mipsfpu double
12868@itemx set mipsfpu single
12869@itemx set mipsfpu none
12870@itemx show mipsfpu
12871@kindex set mipsfpu
12872@kindex show mipsfpu
12873@cindex MIPS remote floating point
12874@cindex floating point, MIPS remote
12875If your target board does not support the MIPS floating point
12876coprocessor, you should use the command @samp{set mipsfpu none} (if you
12877need this, you may wish to put the command in your @value{GDBN} init
12878file). This tells @value{GDBN} how to find the return value of
12879functions which return floating point values. It also allows
12880@value{GDBN} to avoid saving the floating point registers when calling
12881functions on the board. If you are using a floating point coprocessor
12882with only single precision floating point support, as on the @sc{r4650}
12883processor, use the command @samp{set mipsfpu single}. The default
12884double precision floating point coprocessor may be selected using
12885@samp{set mipsfpu double}.
104c1213 12886
8e04817f
AC
12887In previous versions the only choices were double precision or no
12888floating point, so @samp{set mipsfpu on} will select double precision
12889and @samp{set mipsfpu off} will select no floating point.
104c1213 12890
8e04817f
AC
12891As usual, you can inquire about the @code{mipsfpu} variable with
12892@samp{show mipsfpu}.
104c1213 12893
8e04817f
AC
12894@item set remotedebug @var{n}
12895@itemx show remotedebug
12896@kindex set remotedebug@r{, MIPS protocol}
12897@kindex show remotedebug@r{, MIPS protocol}
12898@cindex @code{remotedebug}, MIPS protocol
12899@cindex MIPS @code{remotedebug} protocol
12900@c FIXME! For this to be useful, you must know something about the MIPS
12901@c FIXME...protocol. Where is it described?
12902You can see some debugging information about communications with the board
12903by setting the @code{remotedebug} variable. If you set it to @code{1} using
12904@samp{set remotedebug 1}, every packet is displayed. If you set it
12905to @code{2}, every character is displayed. You can check the current value
12906at any time with the command @samp{show remotedebug}.
104c1213 12907
8e04817f
AC
12908@item set timeout @var{seconds}
12909@itemx set retransmit-timeout @var{seconds}
12910@itemx show timeout
12911@itemx show retransmit-timeout
12912@cindex @code{timeout}, MIPS protocol
12913@cindex @code{retransmit-timeout}, MIPS protocol
12914@kindex set timeout
12915@kindex show timeout
12916@kindex set retransmit-timeout
12917@kindex show retransmit-timeout
12918You can control the timeout used while waiting for a packet, in the MIPS
12919remote protocol, with the @code{set timeout @var{seconds}} command. The
12920default is 5 seconds. Similarly, you can control the timeout used while
12921waiting for an acknowledgement of a packet with the @code{set
12922retransmit-timeout @var{seconds}} command. The default is 3 seconds.
12923You can inspect both values with @code{show timeout} and @code{show
12924retransmit-timeout}. (These commands are @emph{only} available when
12925@value{GDBN} is configured for @samp{--target=mips-idt-ecoff}.)
104c1213 12926
8e04817f
AC
12927The timeout set by @code{set timeout} does not apply when @value{GDBN}
12928is waiting for your program to stop. In that case, @value{GDBN} waits
12929forever because it has no way of knowing how long the program is going
12930to run before stopping.
12931@end table
104c1213 12932
a37295f9
MM
12933@node OpenRISC 1000
12934@subsection OpenRISC 1000
12935@cindex OpenRISC 1000
12936
12937@cindex or1k boards
12938See OR1k Architecture document (@uref{www.opencores.org}) for more information
12939about platform and commands.
12940
12941@table @code
12942
12943@kindex target jtag
12944@item target jtag jtag://@var{host}:@var{port}
12945
12946Connects to remote JTAG server.
12947JTAG remote server can be either an or1ksim or JTAG server,
12948connected via parallel port to the board.
12949
12950Example: @code{target jtag jtag://localhost:9999}
12951
12952@kindex or1ksim
12953@item or1ksim @var{command}
12954If connected to @code{or1ksim} OpenRISC 1000 Architectural
12955Simulator, proprietary commands can be executed.
12956
12957@kindex info or1k spr
12958@item info or1k spr
12959Displays spr groups.
12960
12961@item info or1k spr @var{group}
12962@itemx info or1k spr @var{groupno}
12963Displays register names in selected group.
12964
12965@item info or1k spr @var{group} @var{register}
12966@itemx info or1k spr @var{register}
12967@itemx info or1k spr @var{groupno} @var{registerno}
12968@itemx info or1k spr @var{registerno}
12969Shows information about specified spr register.
12970
12971@kindex spr
12972@item spr @var{group} @var{register} @var{value}
12973@itemx spr @var{register @var{value}}
12974@itemx spr @var{groupno} @var{registerno @var{value}}
12975@itemx spr @var{registerno @var{value}}
12976Writes @var{value} to specified spr register.
12977@end table
12978
12979Some implementations of OpenRISC 1000 Architecture also have hardware trace.
12980It is very similar to @value{GDBN} trace, except it does not interfere with normal
12981program execution and is thus much faster. Hardware breakpoints/watchpoint
12982triggers can be set using:
12983@table @code
12984@item $LEA/$LDATA
12985Load effective address/data
12986@item $SEA/$SDATA
12987Store effective address/data
12988@item $AEA/$ADATA
12989Access effective address ($SEA or $LEA) or data ($SDATA/$LDATA)
12990@item $FETCH
12991Fetch data
12992@end table
12993
12994When triggered, it can capture low level data, like: @code{PC}, @code{LSEA},
12995@code{LDATA}, @code{SDATA}, @code{READSPR}, @code{WRITESPR}, @code{INSTR}.
12996
12997@code{htrace} commands:
12998@cindex OpenRISC 1000 htrace
12999@table @code
13000@kindex hwatch
13001@item hwatch @var{conditional}
13002Set hardware watchpoint on combination of Load/Store Effecive Address(es)
13003or Data. For example:
13004
13005@code{hwatch ($LEA == my_var) && ($LDATA < 50) || ($SEA == my_var) && ($SDATA >= 50)}
13006
13007@code{hwatch ($LEA == my_var) && ($LDATA < 50) || ($SEA == my_var) && ($SDATA >= 50)}
13008
4644b6e3 13009@kindex htrace
a37295f9
MM
13010@item htrace info
13011Display information about current HW trace configuration.
13012
a37295f9
MM
13013@item htrace trigger @var{conditional}
13014Set starting criteria for HW trace.
13015
a37295f9
MM
13016@item htrace qualifier @var{conditional}
13017Set acquisition qualifier for HW trace.
13018
a37295f9
MM
13019@item htrace stop @var{conditional}
13020Set HW trace stopping criteria.
13021
f153cc92 13022@item htrace record [@var{data}]*
a37295f9
MM
13023Selects the data to be recorded, when qualifier is met and HW trace was
13024triggered.
13025
a37295f9 13026@item htrace enable
a37295f9
MM
13027@itemx htrace disable
13028Enables/disables the HW trace.
13029
f153cc92 13030@item htrace rewind [@var{filename}]
a37295f9
MM
13031Clears currently recorded trace data.
13032
13033If filename is specified, new trace file is made and any newly collected data
13034will be written there.
13035
f153cc92 13036@item htrace print [@var{start} [@var{len}]]
a37295f9
MM
13037Prints trace buffer, using current record configuration.
13038
a37295f9
MM
13039@item htrace mode continuous
13040Set continuous trace mode.
13041
a37295f9
MM
13042@item htrace mode suspend
13043Set suspend trace mode.
13044
13045@end table
13046
8e04817f
AC
13047@node PowerPC
13048@subsection PowerPC
104c1213
JM
13049
13050@table @code
104c1213 13051
8e04817f
AC
13052@kindex target dink32
13053@item target dink32 @var{dev}
13054DINK32 ROM monitor.
104c1213 13055
8e04817f
AC
13056@kindex target ppcbug
13057@item target ppcbug @var{dev}
13058@kindex target ppcbug1
13059@item target ppcbug1 @var{dev}
13060PPCBUG ROM monitor for PowerPC.
104c1213 13061
8e04817f
AC
13062@kindex target sds
13063@item target sds @var{dev}
13064SDS monitor, running on a PowerPC board (such as Motorola's ADS).
13065
13066@end table
13067
13068@node PA
13069@subsection HP PA Embedded
104c1213
JM
13070
13071@table @code
13072
8e04817f
AC
13073@kindex target op50n
13074@item target op50n @var{dev}
13075OP50N monitor, running on an OKI HPPA board.
13076
13077@kindex target w89k
13078@item target w89k @var{dev}
13079W89K monitor, running on a Winbond HPPA board.
104c1213
JM
13080
13081@end table
13082
8e04817f 13083@node SH
172c2a43 13084@subsection Renesas SH
104c1213
JM
13085
13086@table @code
13087
172c2a43 13088@kindex target hms@r{, with Renesas SH}
8e04817f 13089@item target hms @var{dev}
172c2a43 13090A Renesas SH board attached via serial line to your host. Use special
8e04817f
AC
13091commands @code{device} and @code{speed} to control the serial line and
13092the communications speed used.
104c1213 13093
172c2a43 13094@kindex target e7000@r{, with Renesas SH}
8e04817f 13095@item target e7000 @var{dev}
172c2a43 13096E7000 emulator for Renesas SH.
104c1213 13097
8e04817f
AC
13098@kindex target sh3@r{, with SH}
13099@kindex target sh3e@r{, with SH}
13100@item target sh3 @var{dev}
13101@item target sh3e @var{dev}
172c2a43 13102Renesas SH-3 and SH-3E target systems.
104c1213 13103
8e04817f 13104@end table
104c1213 13105
8e04817f
AC
13106@node Sparclet
13107@subsection Tsqware Sparclet
104c1213 13108
8e04817f
AC
13109@cindex Sparclet
13110
13111@value{GDBN} enables developers to debug tasks running on
13112Sparclet targets from a Unix host.
13113@value{GDBN} uses code that runs on
13114both the Unix host and on the Sparclet target. The program
13115@code{@value{GDBP}} is installed and executed on the Unix host.
104c1213 13116
8e04817f
AC
13117@table @code
13118@item remotetimeout @var{args}
13119@kindex remotetimeout
13120@value{GDBN} supports the option @code{remotetimeout}.
13121This option is set by the user, and @var{args} represents the number of
13122seconds @value{GDBN} waits for responses.
104c1213
JM
13123@end table
13124
8e04817f
AC
13125@cindex compiling, on Sparclet
13126When compiling for debugging, include the options @samp{-g} to get debug
13127information and @samp{-Ttext} to relocate the program to where you wish to
13128load it on the target. You may also want to add the options @samp{-n} or
13129@samp{-N} in order to reduce the size of the sections. Example:
104c1213 13130
474c8240 13131@smallexample
8e04817f 13132sparclet-aout-gcc prog.c -Ttext 0x12010000 -g -o prog -N
474c8240 13133@end smallexample
104c1213 13134
8e04817f 13135You can use @code{objdump} to verify that the addresses are what you intended:
104c1213 13136
474c8240 13137@smallexample
8e04817f 13138sparclet-aout-objdump --headers --syms prog
474c8240 13139@end smallexample
104c1213 13140
8e04817f
AC
13141@cindex running, on Sparclet
13142Once you have set
13143your Unix execution search path to find @value{GDBN}, you are ready to
13144run @value{GDBN}. From your Unix host, run @code{@value{GDBP}}
13145(or @code{sparclet-aout-gdb}, depending on your installation).
104c1213 13146
8e04817f
AC
13147@value{GDBN} comes up showing the prompt:
13148
474c8240 13149@smallexample
8e04817f 13150(gdbslet)
474c8240 13151@end smallexample
104c1213
JM
13152
13153@menu
8e04817f
AC
13154* Sparclet File:: Setting the file to debug
13155* Sparclet Connection:: Connecting to Sparclet
13156* Sparclet Download:: Sparclet download
13157* Sparclet Execution:: Running and debugging
104c1213
JM
13158@end menu
13159
8e04817f
AC
13160@node Sparclet File
13161@subsubsection Setting file to debug
104c1213 13162
8e04817f 13163The @value{GDBN} command @code{file} lets you choose with program to debug.
104c1213 13164
474c8240 13165@smallexample
8e04817f 13166(gdbslet) file prog
474c8240 13167@end smallexample
104c1213 13168
8e04817f
AC
13169@need 1000
13170@value{GDBN} then attempts to read the symbol table of @file{prog}.
13171@value{GDBN} locates
13172the file by searching the directories listed in the command search
13173path.
13174If the file was compiled with debug information (option "-g"), source
13175files will be searched as well.
13176@value{GDBN} locates
13177the source files by searching the directories listed in the directory search
13178path (@pxref{Environment, ,Your program's environment}).
13179If it fails
13180to find a file, it displays a message such as:
104c1213 13181
474c8240 13182@smallexample
8e04817f 13183prog: No such file or directory.
474c8240 13184@end smallexample
104c1213 13185
8e04817f
AC
13186When this happens, add the appropriate directories to the search paths with
13187the @value{GDBN} commands @code{path} and @code{dir}, and execute the
13188@code{target} command again.
104c1213 13189
8e04817f
AC
13190@node Sparclet Connection
13191@subsubsection Connecting to Sparclet
104c1213 13192
8e04817f
AC
13193The @value{GDBN} command @code{target} lets you connect to a Sparclet target.
13194To connect to a target on serial port ``@code{ttya}'', type:
104c1213 13195
474c8240 13196@smallexample
8e04817f
AC
13197(gdbslet) target sparclet /dev/ttya
13198Remote target sparclet connected to /dev/ttya
13199main () at ../prog.c:3
474c8240 13200@end smallexample
104c1213 13201
8e04817f
AC
13202@need 750
13203@value{GDBN} displays messages like these:
104c1213 13204
474c8240 13205@smallexample
8e04817f 13206Connected to ttya.
474c8240 13207@end smallexample
104c1213 13208
8e04817f
AC
13209@node Sparclet Download
13210@subsubsection Sparclet download
104c1213 13211
8e04817f
AC
13212@cindex download to Sparclet
13213Once connected to the Sparclet target,
13214you can use the @value{GDBN}
13215@code{load} command to download the file from the host to the target.
13216The file name and load offset should be given as arguments to the @code{load}
13217command.
13218Since the file format is aout, the program must be loaded to the starting
13219address. You can use @code{objdump} to find out what this value is. The load
13220offset is an offset which is added to the VMA (virtual memory address)
13221of each of the file's sections.
13222For instance, if the program
13223@file{prog} was linked to text address 0x1201000, with data at 0x12010160
13224and bss at 0x12010170, in @value{GDBN}, type:
104c1213 13225
474c8240 13226@smallexample
8e04817f
AC
13227(gdbslet) load prog 0x12010000
13228Loading section .text, size 0xdb0 vma 0x12010000
474c8240 13229@end smallexample
104c1213 13230
8e04817f
AC
13231If the code is loaded at a different address then what the program was linked
13232to, you may need to use the @code{section} and @code{add-symbol-file} commands
13233to tell @value{GDBN} where to map the symbol table.
13234
13235@node Sparclet Execution
13236@subsubsection Running and debugging
13237
13238@cindex running and debugging Sparclet programs
13239You can now begin debugging the task using @value{GDBN}'s execution control
13240commands, @code{b}, @code{step}, @code{run}, etc. See the @value{GDBN}
13241manual for the list of commands.
13242
474c8240 13243@smallexample
8e04817f
AC
13244(gdbslet) b main
13245Breakpoint 1 at 0x12010000: file prog.c, line 3.
13246(gdbslet) run
13247Starting program: prog
13248Breakpoint 1, main (argc=1, argv=0xeffff21c) at prog.c:3
132493 char *symarg = 0;
13250(gdbslet) step
132514 char *execarg = "hello!";
13252(gdbslet)
474c8240 13253@end smallexample
8e04817f
AC
13254
13255@node Sparclite
13256@subsection Fujitsu Sparclite
104c1213
JM
13257
13258@table @code
13259
8e04817f
AC
13260@kindex target sparclite
13261@item target sparclite @var{dev}
13262Fujitsu sparclite boards, used only for the purpose of loading.
13263You must use an additional command to debug the program.
13264For example: target remote @var{dev} using @value{GDBN} standard
13265remote protocol.
104c1213
JM
13266
13267@end table
13268
8e04817f
AC
13269@node ST2000
13270@subsection Tandem ST2000
104c1213 13271
8e04817f
AC
13272@value{GDBN} may be used with a Tandem ST2000 phone switch, running Tandem's
13273STDBUG protocol.
104c1213 13274
8e04817f
AC
13275To connect your ST2000 to the host system, see the manufacturer's
13276manual. Once the ST2000 is physically attached, you can run:
104c1213 13277
474c8240 13278@smallexample
8e04817f 13279target st2000 @var{dev} @var{speed}
474c8240 13280@end smallexample
104c1213 13281
8e04817f
AC
13282@noindent
13283to establish it as your debugging environment. @var{dev} is normally
13284the name of a serial device, such as @file{/dev/ttya}, connected to the
13285ST2000 via a serial line. You can instead specify @var{dev} as a TCP
13286connection (for example, to a serial line attached via a terminal
13287concentrator) using the syntax @code{@var{hostname}:@var{portnumber}}.
104c1213 13288
8e04817f
AC
13289The @code{load} and @code{attach} commands are @emph{not} defined for
13290this target; you must load your program into the ST2000 as you normally
13291would for standalone operation. @value{GDBN} reads debugging information
13292(such as symbols) from a separate, debugging version of the program
13293available on your host computer.
13294@c FIXME!! This is terribly vague; what little content is here is
13295@c basically hearsay.
104c1213 13296
8e04817f
AC
13297@cindex ST2000 auxiliary commands
13298These auxiliary @value{GDBN} commands are available to help you with the ST2000
13299environment:
104c1213 13300
8e04817f
AC
13301@table @code
13302@item st2000 @var{command}
13303@kindex st2000 @var{cmd}
13304@cindex STDBUG commands (ST2000)
13305@cindex commands to STDBUG (ST2000)
13306Send a @var{command} to the STDBUG monitor. See the manufacturer's
13307manual for available commands.
104c1213 13308
8e04817f
AC
13309@item connect
13310@cindex connect (to STDBUG)
13311Connect the controlling terminal to the STDBUG command monitor. When
13312you are done interacting with STDBUG, typing either of two character
13313sequences gets you back to the @value{GDBN} command prompt:
13314@kbd{@key{RET}~.} (Return, followed by tilde and period) or
13315@kbd{@key{RET}~@key{C-d}} (Return, followed by tilde and control-D).
104c1213
JM
13316@end table
13317
8e04817f
AC
13318@node Z8000
13319@subsection Zilog Z8000
104c1213 13320
8e04817f
AC
13321@cindex Z8000
13322@cindex simulator, Z8000
13323@cindex Zilog Z8000 simulator
104c1213 13324
8e04817f
AC
13325When configured for debugging Zilog Z8000 targets, @value{GDBN} includes
13326a Z8000 simulator.
13327
13328For the Z8000 family, @samp{target sim} simulates either the Z8002 (the
13329unsegmented variant of the Z8000 architecture) or the Z8001 (the
13330segmented variant). The simulator recognizes which architecture is
13331appropriate by inspecting the object code.
104c1213 13332
8e04817f
AC
13333@table @code
13334@item target sim @var{args}
13335@kindex sim
13336@kindex target sim@r{, with Z8000}
13337Debug programs on a simulated CPU. If the simulator supports setup
13338options, specify them via @var{args}.
104c1213
JM
13339@end table
13340
8e04817f
AC
13341@noindent
13342After specifying this target, you can debug programs for the simulated
13343CPU in the same style as programs for your host computer; use the
13344@code{file} command to load a new program image, the @code{run} command
13345to run your program, and so on.
13346
13347As well as making available all the usual machine registers
13348(@pxref{Registers, ,Registers}), the Z8000 simulator provides three
13349additional items of information as specially named registers:
104c1213
JM
13350
13351@table @code
13352
8e04817f
AC
13353@item cycles
13354Counts clock-ticks in the simulator.
104c1213 13355
8e04817f
AC
13356@item insts
13357Counts instructions run in the simulator.
104c1213 13358
8e04817f
AC
13359@item time
13360Execution time in 60ths of a second.
104c1213 13361
8e04817f 13362@end table
104c1213 13363
8e04817f
AC
13364You can refer to these values in @value{GDBN} expressions with the usual
13365conventions; for example, @w{@samp{b fputc if $cycles>5000}} sets a
13366conditional breakpoint that suspends only after at least 5000
13367simulated clock ticks.
104c1213 13368
8e04817f
AC
13369@node Architectures
13370@section Architectures
104c1213 13371
8e04817f
AC
13372This section describes characteristics of architectures that affect
13373all uses of @value{GDBN} with the architecture, both native and cross.
104c1213 13374
8e04817f
AC
13375@menu
13376* A29K::
13377* Alpha::
13378* MIPS::
13379@end menu
104c1213 13380
8e04817f
AC
13381@node A29K
13382@subsection A29K
104c1213
JM
13383
13384@table @code
104c1213 13385
8e04817f
AC
13386@kindex set rstack_high_address
13387@cindex AMD 29K register stack
13388@cindex register stack, AMD29K
13389@item set rstack_high_address @var{address}
13390On AMD 29000 family processors, registers are saved in a separate
13391@dfn{register stack}. There is no way for @value{GDBN} to determine the
13392extent of this stack. Normally, @value{GDBN} just assumes that the
13393stack is ``large enough''. This may result in @value{GDBN} referencing
13394memory locations that do not exist. If necessary, you can get around
13395this problem by specifying the ending address of the register stack with
13396the @code{set rstack_high_address} command. The argument should be an
13397address, which you probably want to precede with @samp{0x} to specify in
13398hexadecimal.
104c1213 13399
8e04817f
AC
13400@kindex show rstack_high_address
13401@item show rstack_high_address
13402Display the current limit of the register stack, on AMD 29000 family
13403processors.
104c1213 13404
8e04817f 13405@end table
104c1213 13406
8e04817f
AC
13407@node Alpha
13408@subsection Alpha
104c1213 13409
8e04817f 13410See the following section.
104c1213 13411
8e04817f
AC
13412@node MIPS
13413@subsection MIPS
104c1213 13414
8e04817f
AC
13415@cindex stack on Alpha
13416@cindex stack on MIPS
13417@cindex Alpha stack
13418@cindex MIPS stack
13419Alpha- and MIPS-based computers use an unusual stack frame, which
13420sometimes requires @value{GDBN} to search backward in the object code to
13421find the beginning of a function.
104c1213 13422
8e04817f
AC
13423@cindex response time, MIPS debugging
13424To improve response time (especially for embedded applications, where
13425@value{GDBN} may be restricted to a slow serial line for this search)
13426you may want to limit the size of this search, using one of these
13427commands:
104c1213 13428
8e04817f
AC
13429@table @code
13430@cindex @code{heuristic-fence-post} (Alpha, MIPS)
13431@item set heuristic-fence-post @var{limit}
13432Restrict @value{GDBN} to examining at most @var{limit} bytes in its
13433search for the beginning of a function. A value of @var{0} (the
13434default) means there is no limit. However, except for @var{0}, the
13435larger the limit the more bytes @code{heuristic-fence-post} must search
13436and therefore the longer it takes to run.
104c1213 13437
8e04817f
AC
13438@item show heuristic-fence-post
13439Display the current limit.
13440@end table
104c1213
JM
13441
13442@noindent
8e04817f
AC
13443These commands are available @emph{only} when @value{GDBN} is configured
13444for debugging programs on Alpha or MIPS processors.
104c1213 13445
104c1213 13446
8e04817f
AC
13447@node Controlling GDB
13448@chapter Controlling @value{GDBN}
13449
13450You can alter the way @value{GDBN} interacts with you by using the
13451@code{set} command. For commands controlling how @value{GDBN} displays
13452data, see @ref{Print Settings, ,Print settings}. Other settings are
13453described here.
13454
13455@menu
13456* Prompt:: Prompt
13457* Editing:: Command editing
13458* History:: Command history
13459* Screen Size:: Screen size
13460* Numbers:: Numbers
1e698235 13461* ABI:: Configuring the current ABI
8e04817f
AC
13462* Messages/Warnings:: Optional warnings and messages
13463* Debugging Output:: Optional messages about internal happenings
13464@end menu
13465
13466@node Prompt
13467@section Prompt
104c1213 13468
8e04817f 13469@cindex prompt
104c1213 13470
8e04817f
AC
13471@value{GDBN} indicates its readiness to read a command by printing a string
13472called the @dfn{prompt}. This string is normally @samp{(@value{GDBP})}. You
13473can change the prompt string with the @code{set prompt} command. For
13474instance, when debugging @value{GDBN} with @value{GDBN}, it is useful to change
13475the prompt in one of the @value{GDBN} sessions so that you can always tell
13476which one you are talking to.
104c1213 13477
8e04817f
AC
13478@emph{Note:} @code{set prompt} does not add a space for you after the
13479prompt you set. This allows you to set a prompt which ends in a space
13480or a prompt that does not.
104c1213 13481
8e04817f
AC
13482@table @code
13483@kindex set prompt
13484@item set prompt @var{newprompt}
13485Directs @value{GDBN} to use @var{newprompt} as its prompt string henceforth.
104c1213 13486
8e04817f
AC
13487@kindex show prompt
13488@item show prompt
13489Prints a line of the form: @samp{Gdb's prompt is: @var{your-prompt}}
104c1213
JM
13490@end table
13491
8e04817f
AC
13492@node Editing
13493@section Command editing
13494@cindex readline
13495@cindex command line editing
104c1213 13496
703663ab 13497@value{GDBN} reads its input commands via the @dfn{Readline} interface. This
8e04817f
AC
13498@sc{gnu} library provides consistent behavior for programs which provide a
13499command line interface to the user. Advantages are @sc{gnu} Emacs-style
13500or @dfn{vi}-style inline editing of commands, @code{csh}-like history
13501substitution, and a storage and recall of command history across
13502debugging sessions.
104c1213 13503
8e04817f
AC
13504You may control the behavior of command line editing in @value{GDBN} with the
13505command @code{set}.
104c1213 13506
8e04817f
AC
13507@table @code
13508@kindex set editing
13509@cindex editing
13510@item set editing
13511@itemx set editing on
13512Enable command line editing (enabled by default).
104c1213 13513
8e04817f
AC
13514@item set editing off
13515Disable command line editing.
104c1213 13516
8e04817f
AC
13517@kindex show editing
13518@item show editing
13519Show whether command line editing is enabled.
104c1213
JM
13520@end table
13521
703663ab
EZ
13522@xref{Command Line Editing}, for more details about the Readline
13523interface. Users unfamiliar with @sc{gnu} Emacs or @code{vi} are
13524encouraged to read that chapter.
13525
8e04817f
AC
13526@node History
13527@section Command history
703663ab 13528@cindex command history
8e04817f
AC
13529
13530@value{GDBN} can keep track of the commands you type during your
13531debugging sessions, so that you can be certain of precisely what
13532happened. Use these commands to manage the @value{GDBN} command
13533history facility.
104c1213 13534
703663ab
EZ
13535@value{GDBN} uses the @sc{gnu} History library, a part of the Readline
13536package, to provide the history facility. @xref{Using History
13537Interactively}, for the detailed description of the History library.
13538
13539Here is the description of @value{GDBN} commands related to command
13540history.
13541
104c1213 13542@table @code
8e04817f
AC
13543@cindex history substitution
13544@cindex history file
13545@kindex set history filename
4644b6e3 13546@cindex @env{GDBHISTFILE}, environment variable
8e04817f
AC
13547@item set history filename @var{fname}
13548Set the name of the @value{GDBN} command history file to @var{fname}.
13549This is the file where @value{GDBN} reads an initial command history
13550list, and where it writes the command history from this session when it
13551exits. You can access this list through history expansion or through
13552the history command editing characters listed below. This file defaults
13553to the value of the environment variable @code{GDBHISTFILE}, or to
13554@file{./.gdb_history} (@file{./_gdb_history} on MS-DOS) if this variable
13555is not set.
104c1213 13556
8e04817f 13557@cindex history save
4644b6e3 13558@kindex set history
8e04817f
AC
13559@item set history save
13560@itemx set history save on
13561Record command history in a file, whose name may be specified with the
13562@code{set history filename} command. By default, this option is disabled.
104c1213 13563
8e04817f
AC
13564@item set history save off
13565Stop recording command history in a file.
104c1213 13566
8e04817f 13567@cindex history size
8e04817f
AC
13568@item set history size @var{size}
13569Set the number of commands which @value{GDBN} keeps in its history list.
13570This defaults to the value of the environment variable
13571@code{HISTSIZE}, or to 256 if this variable is not set.
104c1213
JM
13572@end table
13573
8e04817f 13574History expansion assigns special meaning to the character @kbd{!}.
703663ab 13575@xref{Event Designators}, for more details.
8e04817f 13576
703663ab 13577@cindex history expansion, turn on/off
8e04817f
AC
13578Since @kbd{!} is also the logical not operator in C, history expansion
13579is off by default. If you decide to enable history expansion with the
13580@code{set history expansion on} command, you may sometimes need to
13581follow @kbd{!} (when it is used as logical not, in an expression) with
13582a space or a tab to prevent it from being expanded. The readline
13583history facilities do not attempt substitution on the strings
13584@kbd{!=} and @kbd{!(}, even when history expansion is enabled.
13585
13586The commands to control history expansion are:
104c1213
JM
13587
13588@table @code
8e04817f
AC
13589@item set history expansion on
13590@itemx set history expansion
703663ab 13591@kindex set history expansion
8e04817f 13592Enable history expansion. History expansion is off by default.
104c1213 13593
8e04817f
AC
13594@item set history expansion off
13595Disable history expansion.
104c1213 13596
8e04817f
AC
13597@c @group
13598@kindex show history
13599@item show history
13600@itemx show history filename
13601@itemx show history save
13602@itemx show history size
13603@itemx show history expansion
13604These commands display the state of the @value{GDBN} history parameters.
13605@code{show history} by itself displays all four states.
13606@c @end group
13607@end table
13608
13609@table @code
13610@kindex shows
13611@item show commands
13612Display the last ten commands in the command history.
104c1213 13613
8e04817f
AC
13614@item show commands @var{n}
13615Print ten commands centered on command number @var{n}.
13616
13617@item show commands +
13618Print ten commands just after the commands last printed.
104c1213
JM
13619@end table
13620
8e04817f
AC
13621@node Screen Size
13622@section Screen size
13623@cindex size of screen
13624@cindex pauses in output
104c1213 13625
8e04817f
AC
13626Certain commands to @value{GDBN} may produce large amounts of
13627information output to the screen. To help you read all of it,
13628@value{GDBN} pauses and asks you for input at the end of each page of
13629output. Type @key{RET} when you want to continue the output, or @kbd{q}
13630to discard the remaining output. Also, the screen width setting
13631determines when to wrap lines of output. Depending on what is being
13632printed, @value{GDBN} tries to break the line at a readable place,
13633rather than simply letting it overflow onto the following line.
13634
13635Normally @value{GDBN} knows the size of the screen from the terminal
13636driver software. For example, on Unix @value{GDBN} uses the termcap data base
13637together with the value of the @code{TERM} environment variable and the
13638@code{stty rows} and @code{stty cols} settings. If this is not correct,
13639you can override it with the @code{set height} and @code{set
13640width} commands:
13641
13642@table @code
13643@kindex set height
13644@kindex set width
13645@kindex show width
13646@kindex show height
13647@item set height @var{lpp}
13648@itemx show height
13649@itemx set width @var{cpl}
13650@itemx show width
13651These @code{set} commands specify a screen height of @var{lpp} lines and
13652a screen width of @var{cpl} characters. The associated @code{show}
13653commands display the current settings.
104c1213 13654
8e04817f
AC
13655If you specify a height of zero lines, @value{GDBN} does not pause during
13656output no matter how long the output is. This is useful if output is to a
13657file or to an editor buffer.
104c1213 13658
8e04817f
AC
13659Likewise, you can specify @samp{set width 0} to prevent @value{GDBN}
13660from wrapping its output.
104c1213
JM
13661@end table
13662
8e04817f
AC
13663@node Numbers
13664@section Numbers
13665@cindex number representation
13666@cindex entering numbers
104c1213 13667
8e04817f
AC
13668You can always enter numbers in octal, decimal, or hexadecimal in
13669@value{GDBN} by the usual conventions: octal numbers begin with
13670@samp{0}, decimal numbers end with @samp{.}, and hexadecimal numbers
13671begin with @samp{0x}. Numbers that begin with none of these are, by
13672default, entered in base 10; likewise, the default display for
13673numbers---when no particular format is specified---is base 10. You can
13674change the default base for both input and output with the @code{set
13675radix} command.
104c1213 13676
8e04817f
AC
13677@table @code
13678@kindex set input-radix
13679@item set input-radix @var{base}
13680Set the default base for numeric input. Supported choices
13681for @var{base} are decimal 8, 10, or 16. @var{base} must itself be
13682specified either unambiguously or using the current default radix; for
13683example, any of
104c1213 13684
8e04817f
AC
13685@smallexample
13686set radix 012
13687set radix 10.
13688set radix 0xa
13689@end smallexample
104c1213 13690
8e04817f
AC
13691@noindent
13692sets the base to decimal. On the other hand, @samp{set radix 10}
13693leaves the radix unchanged no matter what it was.
104c1213 13694
8e04817f
AC
13695@kindex set output-radix
13696@item set output-radix @var{base}
13697Set the default base for numeric display. Supported choices
13698for @var{base} are decimal 8, 10, or 16. @var{base} must itself be
13699specified either unambiguously or using the current default radix.
104c1213 13700
8e04817f
AC
13701@kindex show input-radix
13702@item show input-radix
13703Display the current default base for numeric input.
104c1213 13704
8e04817f
AC
13705@kindex show output-radix
13706@item show output-radix
13707Display the current default base for numeric display.
13708@end table
104c1213 13709
1e698235
DJ
13710@node ABI
13711@section Configuring the current ABI
13712
13713@value{GDBN} can determine the @dfn{ABI} (Application Binary Interface) of your
13714application automatically. However, sometimes you need to override its
13715conclusions. Use these commands to manage @value{GDBN}'s view of the
13716current ABI.
13717
98b45e30
DJ
13718@cindex OS ABI
13719@kindex set osabi
b4e9345d 13720@kindex show osabi
98b45e30
DJ
13721
13722One @value{GDBN} configuration can debug binaries for multiple operating
b383017d 13723system targets, either via remote debugging or native emulation.
98b45e30
DJ
13724@value{GDBN} will autodetect the @dfn{OS ABI} (Operating System ABI) in use,
13725but you can override its conclusion using the @code{set osabi} command.
13726One example where this is useful is in debugging of binaries which use
13727an alternate C library (e.g.@: @sc{uClibc} for @sc{gnu}/Linux) which does
13728not have the same identifying marks that the standard C library for your
13729platform provides.
13730
13731@table @code
13732@item show osabi
13733Show the OS ABI currently in use.
13734
13735@item set osabi
13736With no argument, show the list of registered available OS ABI's.
13737
13738@item set osabi @var{abi}
13739Set the current OS ABI to @var{abi}.
13740@end table
13741
1e698235
DJ
13742@cindex float promotion
13743@kindex set coerce-float-to-double
13744
13745Generally, the way that an argument of type @code{float} is passed to a
13746function depends on whether the function is prototyped. For a prototyped
13747(i.e.@: ANSI/ISO style) function, @code{float} arguments are passed unchanged,
13748according to the architecture's convention for @code{float}. For unprototyped
13749(i.e.@: K&R style) functions, @code{float} arguments are first promoted to type
13750@code{double} and then passed.
13751
13752Unfortunately, some forms of debug information do not reliably indicate whether
13753a function is prototyped. If @value{GDBN} calls a function that is not marked
13754as prototyped, it consults @kbd{set coerce-float-to-double}.
13755
13756@table @code
13757@item set coerce-float-to-double
13758@itemx set coerce-float-to-double on
13759Arguments of type @code{float} will be promoted to @code{double} when passed
13760to an unprototyped function. This is the default setting.
13761
13762@item set coerce-float-to-double off
13763Arguments of type @code{float} will be passed directly to unprototyped
13764functions.
13765@end table
13766
f1212245
DJ
13767@kindex set cp-abi
13768@kindex show cp-abi
13769@value{GDBN} needs to know the ABI used for your program's C@t{++}
13770objects. The correct C@t{++} ABI depends on which C@t{++} compiler was
13771used to build your application. @value{GDBN} only fully supports
13772programs with a single C@t{++} ABI; if your program contains code using
13773multiple C@t{++} ABI's or if @value{GDBN} can not identify your
13774program's ABI correctly, you can tell @value{GDBN} which ABI to use.
13775Currently supported ABI's include ``gnu-v2'', for @code{g++} versions
13776before 3.0, ``gnu-v3'', for @code{g++} versions 3.0 and later, and
13777``hpaCC'' for the HP ANSI C@t{++} compiler. Other C@t{++} compilers may
13778use the ``gnu-v2'' or ``gnu-v3'' ABI's as well. The default setting is
13779``auto''.
13780
13781@table @code
13782@item show cp-abi
13783Show the C@t{++} ABI currently in use.
13784
13785@item set cp-abi
13786With no argument, show the list of supported C@t{++} ABI's.
13787
13788@item set cp-abi @var{abi}
13789@itemx set cp-abi auto
13790Set the current C@t{++} ABI to @var{abi}, or return to automatic detection.
13791@end table
13792
8e04817f
AC
13793@node Messages/Warnings
13794@section Optional warnings and messages
104c1213 13795
8e04817f
AC
13796By default, @value{GDBN} is silent about its inner workings. If you are
13797running on a slow machine, you may want to use the @code{set verbose}
13798command. This makes @value{GDBN} tell you when it does a lengthy
13799internal operation, so you will not think it has crashed.
104c1213 13800
8e04817f
AC
13801Currently, the messages controlled by @code{set verbose} are those
13802which announce that the symbol table for a source file is being read;
13803see @code{symbol-file} in @ref{Files, ,Commands to specify files}.
104c1213 13804
8e04817f
AC
13805@table @code
13806@kindex set verbose
13807@item set verbose on
13808Enables @value{GDBN} output of certain informational messages.
104c1213 13809
8e04817f
AC
13810@item set verbose off
13811Disables @value{GDBN} output of certain informational messages.
104c1213 13812
8e04817f
AC
13813@kindex show verbose
13814@item show verbose
13815Displays whether @code{set verbose} is on or off.
13816@end table
104c1213 13817
8e04817f
AC
13818By default, if @value{GDBN} encounters bugs in the symbol table of an
13819object file, it is silent; but if you are debugging a compiler, you may
13820find this information useful (@pxref{Symbol Errors, ,Errors reading
13821symbol files}).
104c1213 13822
8e04817f 13823@table @code
104c1213 13824
8e04817f
AC
13825@kindex set complaints
13826@item set complaints @var{limit}
13827Permits @value{GDBN} to output @var{limit} complaints about each type of
13828unusual symbols before becoming silent about the problem. Set
13829@var{limit} to zero to suppress all complaints; set it to a large number
13830to prevent complaints from being suppressed.
104c1213 13831
8e04817f
AC
13832@kindex show complaints
13833@item show complaints
13834Displays how many symbol complaints @value{GDBN} is permitted to produce.
104c1213 13835
8e04817f 13836@end table
104c1213 13837
8e04817f
AC
13838By default, @value{GDBN} is cautious, and asks what sometimes seems to be a
13839lot of stupid questions to confirm certain commands. For example, if
13840you try to run a program which is already running:
104c1213 13841
474c8240 13842@smallexample
8e04817f
AC
13843(@value{GDBP}) run
13844The program being debugged has been started already.
13845Start it from the beginning? (y or n)
474c8240 13846@end smallexample
104c1213 13847
8e04817f
AC
13848If you are willing to unflinchingly face the consequences of your own
13849commands, you can disable this ``feature'':
104c1213 13850
8e04817f 13851@table @code
104c1213 13852
8e04817f
AC
13853@kindex set confirm
13854@cindex flinching
13855@cindex confirmation
13856@cindex stupid questions
13857@item set confirm off
13858Disables confirmation requests.
104c1213 13859
8e04817f
AC
13860@item set confirm on
13861Enables confirmation requests (the default).
104c1213 13862
8e04817f
AC
13863@kindex show confirm
13864@item show confirm
13865Displays state of confirmation requests.
13866
13867@end table
104c1213 13868
8e04817f
AC
13869@node Debugging Output
13870@section Optional messages about internal happenings
4644b6e3
EZ
13871@cindex optional debugging messages
13872
104c1213 13873@table @code
4644b6e3
EZ
13874@kindex set debug
13875@cindex gdbarch debugging info
8e04817f
AC
13876@item set debug arch
13877Turns on or off display of gdbarch debugging info. The default is off
4644b6e3 13878@kindex show debug
8e04817f
AC
13879@item show debug arch
13880Displays the current state of displaying gdbarch debugging info.
8e04817f 13881@item set debug event
4644b6e3 13882@cindex event debugging info
8e04817f
AC
13883Turns on or off display of @value{GDBN} event debugging info. The
13884default is off.
8e04817f
AC
13885@item show debug event
13886Displays the current state of displaying @value{GDBN} event debugging
13887info.
8e04817f 13888@item set debug expression
4644b6e3 13889@cindex expression debugging info
8e04817f
AC
13890Turns on or off display of @value{GDBN} expression debugging info. The
13891default is off.
8e04817f
AC
13892@item show debug expression
13893Displays the current state of displaying @value{GDBN} expression
13894debugging info.
7453dc06 13895@item set debug frame
4644b6e3 13896@cindex frame debugging info
7453dc06
AC
13897Turns on or off display of @value{GDBN} frame debugging info. The
13898default is off.
7453dc06
AC
13899@item show debug frame
13900Displays the current state of displaying @value{GDBN} frame debugging
13901info.
30e91e0b
RC
13902@item set debug infrun
13903@cindex inferior debugging info
13904Turns on or off display of @value{GDBN} debugging info for running the inferior.
13905The default is off. @file{infrun.c} contains GDB's runtime state machine used
13906for implementing operations such as single-stepping the inferior.
13907@item show debug infrun
13908Displays the current state of @value{GDBN} inferior debugging.
2b4855ab 13909@item set debug observer
4644b6e3 13910@cindex observer debugging info
2b4855ab
AC
13911Turns on or off display of @value{GDBN} observer debugging. This
13912includes info such as the notification of observable events.
2b4855ab
AC
13913@item show debug observer
13914Displays the current state of observer debugging.
8e04817f 13915@item set debug overload
4644b6e3 13916@cindex C@t{++} overload debugging info
8e04817f
AC
13917Turns on or off display of @value{GDBN} C@t{++} overload debugging
13918info. This includes info such as ranking of functions, etc. The default
13919is off.
8e04817f
AC
13920@item show debug overload
13921Displays the current state of displaying @value{GDBN} C@t{++} overload
13922debugging info.
8e04817f
AC
13923@cindex packets, reporting on stdout
13924@cindex serial connections, debugging
13925@item set debug remote
13926Turns on or off display of reports on all packets sent back and forth across
13927the serial line to the remote machine. The info is printed on the
13928@value{GDBN} standard output stream. The default is off.
8e04817f
AC
13929@item show debug remote
13930Displays the state of display of remote packets.
8e04817f
AC
13931@item set debug serial
13932Turns on or off display of @value{GDBN} serial debugging info. The
13933default is off.
8e04817f
AC
13934@item show debug serial
13935Displays the current state of displaying @value{GDBN} serial debugging
13936info.
8e04817f 13937@item set debug target
4644b6e3 13938@cindex target debugging info
8e04817f
AC
13939Turns on or off display of @value{GDBN} target debugging info. This info
13940includes what is going on at the target level of GDB, as it happens. The
701b08bb
DJ
13941default is 0. Set it to 1 to track events, and to 2 to also track the
13942value of large memory transfers. Changes to this flag do not take effect
13943until the next time you connect to a target or use the @code{run} command.
8e04817f
AC
13944@item show debug target
13945Displays the current state of displaying @value{GDBN} target debugging
13946info.
8e04817f 13947@item set debug varobj
4644b6e3 13948@cindex variable object debugging info
8e04817f
AC
13949Turns on or off display of @value{GDBN} variable object debugging
13950info. The default is off.
8e04817f
AC
13951@item show debug varobj
13952Displays the current state of displaying @value{GDBN} variable object
13953debugging info.
13954@end table
104c1213 13955
8e04817f
AC
13956@node Sequences
13957@chapter Canned Sequences of Commands
104c1213 13958
8e04817f
AC
13959Aside from breakpoint commands (@pxref{Break Commands, ,Breakpoint
13960command lists}), @value{GDBN} provides two ways to store sequences of
13961commands for execution as a unit: user-defined commands and command
13962files.
104c1213 13963
8e04817f
AC
13964@menu
13965* Define:: User-defined commands
13966* Hooks:: User-defined command hooks
13967* Command Files:: Command files
13968* Output:: Commands for controlled output
13969@end menu
104c1213 13970
8e04817f
AC
13971@node Define
13972@section User-defined commands
104c1213 13973
8e04817f
AC
13974@cindex user-defined command
13975A @dfn{user-defined command} is a sequence of @value{GDBN} commands to
13976which you assign a new name as a command. This is done with the
13977@code{define} command. User commands may accept up to 10 arguments
13978separated by whitespace. Arguments are accessed within the user command
13979via @var{$arg0@dots{}$arg9}. A trivial example:
104c1213 13980
8e04817f
AC
13981@smallexample
13982define adder
13983 print $arg0 + $arg1 + $arg2
13984@end smallexample
104c1213
JM
13985
13986@noindent
8e04817f 13987To execute the command use:
104c1213 13988
8e04817f
AC
13989@smallexample
13990adder 1 2 3
13991@end smallexample
104c1213 13992
8e04817f
AC
13993@noindent
13994This defines the command @code{adder}, which prints the sum of
13995its three arguments. Note the arguments are text substitutions, so they may
13996reference variables, use complex expressions, or even perform inferior
13997functions calls.
104c1213
JM
13998
13999@table @code
104c1213 14000
8e04817f
AC
14001@kindex define
14002@item define @var{commandname}
14003Define a command named @var{commandname}. If there is already a command
14004by that name, you are asked to confirm that you want to redefine it.
104c1213 14005
8e04817f
AC
14006The definition of the command is made up of other @value{GDBN} command lines,
14007which are given following the @code{define} command. The end of these
14008commands is marked by a line containing @code{end}.
104c1213 14009
8e04817f
AC
14010@kindex if
14011@kindex else
14012@item if
14013Takes a single argument, which is an expression to evaluate.
14014It is followed by a series of commands that are executed
14015only if the expression is true (nonzero).
14016There can then optionally be a line @code{else}, followed
14017by a series of commands that are only executed if the expression
14018was false. The end of the list is marked by a line containing @code{end}.
104c1213 14019
8e04817f
AC
14020@kindex while
14021@item while
14022The syntax is similar to @code{if}: the command takes a single argument,
14023which is an expression to evaluate, and must be followed by the commands to
14024execute, one per line, terminated by an @code{end}.
14025The commands are executed repeatedly as long as the expression
14026evaluates to true.
104c1213 14027
8e04817f
AC
14028@kindex document
14029@item document @var{commandname}
14030Document the user-defined command @var{commandname}, so that it can be
14031accessed by @code{help}. The command @var{commandname} must already be
14032defined. This command reads lines of documentation just as @code{define}
14033reads the lines of the command definition, ending with @code{end}.
14034After the @code{document} command is finished, @code{help} on command
14035@var{commandname} displays the documentation you have written.
104c1213 14036
8e04817f
AC
14037You may use the @code{document} command again to change the
14038documentation of a command. Redefining the command with @code{define}
14039does not change the documentation.
104c1213 14040
8e04817f
AC
14041@kindex help user-defined
14042@item help user-defined
14043List all user-defined commands, with the first line of the documentation
14044(if any) for each.
104c1213 14045
8e04817f
AC
14046@kindex show user
14047@item show user
14048@itemx show user @var{commandname}
14049Display the @value{GDBN} commands used to define @var{commandname} (but
14050not its documentation). If no @var{commandname} is given, display the
14051definitions for all user-defined commands.
104c1213 14052
20f01a46
DH
14053@kindex show max-user-call-depth
14054@kindex set max-user-call-depth
14055@item show max-user-call-depth
5ca0cb28
DH
14056@itemx set max-user-call-depth
14057The value of @code{max-user-call-depth} controls how many recursion
14058levels are allowed in user-defined commands before GDB suspects an
14059infinite recursion and aborts the command.
20f01a46 14060
104c1213
JM
14061@end table
14062
8e04817f
AC
14063When user-defined commands are executed, the
14064commands of the definition are not printed. An error in any command
14065stops execution of the user-defined command.
104c1213 14066
8e04817f
AC
14067If used interactively, commands that would ask for confirmation proceed
14068without asking when used inside a user-defined command. Many @value{GDBN}
14069commands that normally print messages to say what they are doing omit the
14070messages when used in a user-defined command.
104c1213 14071
8e04817f
AC
14072@node Hooks
14073@section User-defined command hooks
14074@cindex command hooks
14075@cindex hooks, for commands
14076@cindex hooks, pre-command
104c1213 14077
8e04817f 14078@kindex hook
8e04817f
AC
14079You may define @dfn{hooks}, which are a special kind of user-defined
14080command. Whenever you run the command @samp{foo}, if the user-defined
14081command @samp{hook-foo} exists, it is executed (with no arguments)
14082before that command.
104c1213 14083
8e04817f
AC
14084@cindex hooks, post-command
14085@kindex hookpost
8e04817f
AC
14086A hook may also be defined which is run after the command you executed.
14087Whenever you run the command @samp{foo}, if the user-defined command
14088@samp{hookpost-foo} exists, it is executed (with no arguments) after
14089that command. Post-execution hooks may exist simultaneously with
14090pre-execution hooks, for the same command.
104c1213 14091
8e04817f 14092It is valid for a hook to call the command which it hooks. If this
9f1c6395 14093occurs, the hook is not re-executed, thereby avoiding infinite recursion.
104c1213 14094
8e04817f
AC
14095@c It would be nice if hookpost could be passed a parameter indicating
14096@c if the command it hooks executed properly or not. FIXME!
104c1213 14097
8e04817f
AC
14098@kindex stop@r{, a pseudo-command}
14099In addition, a pseudo-command, @samp{stop} exists. Defining
14100(@samp{hook-stop}) makes the associated commands execute every time
14101execution stops in your program: before breakpoint commands are run,
14102displays are printed, or the stack frame is printed.
104c1213 14103
8e04817f
AC
14104For example, to ignore @code{SIGALRM} signals while
14105single-stepping, but treat them normally during normal execution,
14106you could define:
104c1213 14107
474c8240 14108@smallexample
8e04817f
AC
14109define hook-stop
14110handle SIGALRM nopass
14111end
104c1213 14112
8e04817f
AC
14113define hook-run
14114handle SIGALRM pass
14115end
104c1213 14116
8e04817f
AC
14117define hook-continue
14118handle SIGLARM pass
14119end
474c8240 14120@end smallexample
104c1213 14121
8e04817f 14122As a further example, to hook at the begining and end of the @code{echo}
b383017d 14123command, and to add extra text to the beginning and end of the message,
8e04817f 14124you could define:
104c1213 14125
474c8240 14126@smallexample
8e04817f
AC
14127define hook-echo
14128echo <<<---
14129end
104c1213 14130
8e04817f
AC
14131define hookpost-echo
14132echo --->>>\n
14133end
104c1213 14134
8e04817f
AC
14135(@value{GDBP}) echo Hello World
14136<<<---Hello World--->>>
14137(@value{GDBP})
104c1213 14138
474c8240 14139@end smallexample
104c1213 14140
8e04817f
AC
14141You can define a hook for any single-word command in @value{GDBN}, but
14142not for command aliases; you should define a hook for the basic command
14143name, e.g. @code{backtrace} rather than @code{bt}.
14144@c FIXME! So how does Joe User discover whether a command is an alias
14145@c or not?
14146If an error occurs during the execution of your hook, execution of
14147@value{GDBN} commands stops and @value{GDBN} issues a prompt
14148(before the command that you actually typed had a chance to run).
104c1213 14149
8e04817f
AC
14150If you try to define a hook which does not match any known command, you
14151get a warning from the @code{define} command.
c906108c 14152
8e04817f
AC
14153@node Command Files
14154@section Command files
c906108c 14155
8e04817f
AC
14156@cindex command files
14157A command file for @value{GDBN} is a file of lines that are @value{GDBN}
14158commands. Comments (lines starting with @kbd{#}) may also be included.
14159An empty line in a command file does nothing; it does not mean to repeat
14160the last command, as it would from the terminal.
c906108c 14161
8e04817f
AC
14162@cindex init file
14163@cindex @file{.gdbinit}
14164@cindex @file{gdb.ini}
14165When you start @value{GDBN}, it automatically executes commands from its
14166@dfn{init files}, normally called @file{.gdbinit}@footnote{The DJGPP
14167port of @value{GDBN} uses the name @file{gdb.ini} instead, due to the
14168limitations of file names imposed by DOS filesystems.}.
14169During startup, @value{GDBN} does the following:
c906108c 14170
8e04817f
AC
14171@enumerate
14172@item
14173Reads the init file (if any) in your home directory@footnote{On
14174DOS/Windows systems, the home directory is the one pointed to by the
14175@code{HOME} environment variable.}.
c906108c 14176
8e04817f
AC
14177@item
14178Processes command line options and operands.
c906108c 14179
8e04817f
AC
14180@item
14181Reads the init file (if any) in the current working directory.
c906108c 14182
8e04817f
AC
14183@item
14184Reads command files specified by the @samp{-x} option.
14185@end enumerate
c906108c 14186
8e04817f
AC
14187The init file in your home directory can set options (such as @samp{set
14188complaints}) that affect subsequent processing of command line options
14189and operands. Init files are not executed if you use the @samp{-nx}
14190option (@pxref{Mode Options, ,Choosing modes}).
c906108c 14191
8e04817f
AC
14192@cindex init file name
14193On some configurations of @value{GDBN}, the init file is known by a
14194different name (these are typically environments where a specialized
14195form of @value{GDBN} may need to coexist with other forms, hence a
14196different name for the specialized version's init file). These are the
14197environments with special init file names:
c906108c 14198
8e04817f
AC
14199@cindex @file{.vxgdbinit}
14200@itemize @bullet
14201@item
14202VxWorks (Wind River Systems real-time OS): @file{.vxgdbinit}
c906108c 14203
8e04817f
AC
14204@cindex @file{.os68gdbinit}
14205@item
14206OS68K (Enea Data Systems real-time OS): @file{.os68gdbinit}
c906108c 14207
8e04817f
AC
14208@cindex @file{.esgdbinit}
14209@item
14210ES-1800 (Ericsson Telecom AB M68000 emulator): @file{.esgdbinit}
14211@end itemize
c906108c 14212
8e04817f
AC
14213You can also request the execution of a command file with the
14214@code{source} command:
c906108c 14215
8e04817f
AC
14216@table @code
14217@kindex source
14218@item source @var{filename}
14219Execute the command file @var{filename}.
c906108c
SS
14220@end table
14221
8e04817f 14222The lines in a command file are executed sequentially. They are not
a71ec265
DH
14223printed as they are executed. An error in any command terminates
14224execution of the command file and control is returned to the console.
c906108c 14225
8e04817f
AC
14226Commands that would ask for confirmation if used interactively proceed
14227without asking when used in a command file. Many @value{GDBN} commands that
14228normally print messages to say what they are doing omit the messages
14229when called from command files.
c906108c 14230
8e04817f
AC
14231@value{GDBN} also accepts command input from standard input. In this
14232mode, normal output goes to standard output and error output goes to
14233standard error. Errors in a command file supplied on standard input do
14234not terminate execution of the command file --- execution continues with
14235the next command.
c906108c 14236
474c8240 14237@smallexample
8e04817f 14238gdb < cmds > log 2>&1
474c8240 14239@end smallexample
c906108c 14240
8e04817f
AC
14241(The syntax above will vary depending on the shell used.) This example
14242will execute commands from the file @file{cmds}. All output and errors
14243would be directed to @file{log}.
c906108c 14244
8e04817f
AC
14245@node Output
14246@section Commands for controlled output
c906108c 14247
8e04817f
AC
14248During the execution of a command file or a user-defined command, normal
14249@value{GDBN} output is suppressed; the only output that appears is what is
14250explicitly printed by the commands in the definition. This section
14251describes three commands useful for generating exactly the output you
14252want.
c906108c
SS
14253
14254@table @code
8e04817f
AC
14255@kindex echo
14256@item echo @var{text}
14257@c I do not consider backslash-space a standard C escape sequence
14258@c because it is not in ANSI.
14259Print @var{text}. Nonprinting characters can be included in
14260@var{text} using C escape sequences, such as @samp{\n} to print a
14261newline. @strong{No newline is printed unless you specify one.}
14262In addition to the standard C escape sequences, a backslash followed
14263by a space stands for a space. This is useful for displaying a
14264string with spaces at the beginning or the end, since leading and
14265trailing spaces are otherwise trimmed from all arguments.
14266To print @samp{@w{ }and foo =@w{ }}, use the command
14267@samp{echo \@w{ }and foo = \@w{ }}.
c906108c 14268
8e04817f
AC
14269A backslash at the end of @var{text} can be used, as in C, to continue
14270the command onto subsequent lines. For example,
c906108c 14271
474c8240 14272@smallexample
8e04817f
AC
14273echo This is some text\n\
14274which is continued\n\
14275onto several lines.\n
474c8240 14276@end smallexample
c906108c 14277
8e04817f 14278produces the same output as
c906108c 14279
474c8240 14280@smallexample
8e04817f
AC
14281echo This is some text\n
14282echo which is continued\n
14283echo onto several lines.\n
474c8240 14284@end smallexample
c906108c 14285
8e04817f
AC
14286@kindex output
14287@item output @var{expression}
14288Print the value of @var{expression} and nothing but that value: no
14289newlines, no @samp{$@var{nn} = }. The value is not entered in the
14290value history either. @xref{Expressions, ,Expressions}, for more information
14291on expressions.
c906108c 14292
8e04817f
AC
14293@item output/@var{fmt} @var{expression}
14294Print the value of @var{expression} in format @var{fmt}. You can use
14295the same formats as for @code{print}. @xref{Output Formats,,Output
14296formats}, for more information.
c906108c 14297
8e04817f
AC
14298@kindex printf
14299@item printf @var{string}, @var{expressions}@dots{}
14300Print the values of the @var{expressions} under the control of
14301@var{string}. The @var{expressions} are separated by commas and may be
14302either numbers or pointers. Their values are printed as specified by
14303@var{string}, exactly as if your program were to execute the C
14304subroutine
14305@c FIXME: the above implies that at least all ANSI C formats are
14306@c supported, but it isn't true: %E and %G don't work (or so it seems).
14307@c Either this is a bug, or the manual should document what formats are
14308@c supported.
c906108c 14309
474c8240 14310@smallexample
8e04817f 14311printf (@var{string}, @var{expressions}@dots{});
474c8240 14312@end smallexample
c906108c 14313
8e04817f 14314For example, you can print two values in hex like this:
c906108c 14315
8e04817f
AC
14316@smallexample
14317printf "foo, bar-foo = 0x%x, 0x%x\n", foo, bar-foo
14318@end smallexample
c906108c 14319
8e04817f
AC
14320The only backslash-escape sequences that you can use in the format
14321string are the simple ones that consist of backslash followed by a
14322letter.
c906108c
SS
14323@end table
14324
21c294e6
AC
14325@node Interpreters
14326@chapter Command Interpreters
14327@cindex command interpreters
14328
14329@value{GDBN} supports multiple command interpreters, and some command
14330infrastructure to allow users or user interface writers to switch
14331between interpreters or run commands in other interpreters.
14332
14333@value{GDBN} currently supports two command interpreters, the console
14334interpreter (sometimes called the command-line interpreter or @sc{cli})
14335and the machine interface interpreter (or @sc{gdb/mi}). This manual
14336describes both of these interfaces in great detail.
14337
14338By default, @value{GDBN} will start with the console interpreter.
14339However, the user may choose to start @value{GDBN} with another
14340interpreter by specifying the @option{-i} or @option{--interpreter}
14341startup options. Defined interpreters include:
14342
14343@table @code
14344@item console
14345@cindex console interpreter
14346The traditional console or command-line interpreter. This is the most often
14347used interpreter with @value{GDBN}. With no interpreter specified at runtime,
14348@value{GDBN} will use this interpreter.
14349
14350@item mi
14351@cindex mi interpreter
14352The newest @sc{gdb/mi} interface (currently @code{mi2}). Used primarily
14353by programs wishing to use @value{GDBN} as a backend for a debugger GUI
14354or an IDE. For more information, see @ref{GDB/MI, ,The @sc{gdb/mi}
14355Interface}.
14356
14357@item mi2
14358@cindex mi2 interpreter
14359The current @sc{gdb/mi} interface.
14360
14361@item mi1
14362@cindex mi1 interpreter
14363The @sc{gdb/mi} interface included in @value{GDBN} 5.1, 5.2, and 5.3.
14364
14365@end table
14366
14367@cindex invoke another interpreter
14368The interpreter being used by @value{GDBN} may not be dynamically
14369switched at runtime. Although possible, this could lead to a very
14370precarious situation. Consider an IDE using @sc{gdb/mi}. If a user
14371enters the command "interpreter-set console" in a console view,
14372@value{GDBN} would switch to using the console interpreter, rendering
14373the IDE inoperable!
14374
14375@kindex interpreter-exec
14376Although you may only choose a single interpreter at startup, you may execute
14377commands in any interpreter from the current interpreter using the appropriate
14378command. If you are running the console interpreter, simply use the
14379@code{interpreter-exec} command:
14380
14381@smallexample
14382interpreter-exec mi "-data-list-register-names"
14383@end smallexample
14384
14385@sc{gdb/mi} has a similar command, although it is only available in versions of
14386@value{GDBN} which support @sc{gdb/mi} version 2 (or greater).
14387
8e04817f
AC
14388@node TUI
14389@chapter @value{GDBN} Text User Interface
14390@cindex TUI
d0d5df6f 14391@cindex Text User Interface
c906108c 14392
8e04817f
AC
14393@menu
14394* TUI Overview:: TUI overview
14395* TUI Keys:: TUI key bindings
7cf36c78 14396* TUI Single Key Mode:: TUI single key mode
8e04817f
AC
14397* TUI Commands:: TUI specific commands
14398* TUI Configuration:: TUI configuration variables
14399@end menu
c906108c 14400
d0d5df6f
AC
14401The @value{GDBN} Text User Interface, TUI in short, is a terminal
14402interface which uses the @code{curses} library to show the source
14403file, the assembly output, the program registers and @value{GDBN}
14404commands in separate text windows.
14405
14406The TUI is enabled by invoking @value{GDBN} using either
14407@pindex gdbtui
14408@samp{gdbtui} or @samp{gdb -tui}.
c906108c 14409
8e04817f
AC
14410@node TUI Overview
14411@section TUI overview
c906108c 14412
8e04817f
AC
14413The TUI has two display modes that can be switched while
14414@value{GDBN} runs:
c906108c 14415
8e04817f
AC
14416@itemize @bullet
14417@item
14418A curses (or TUI) mode in which it displays several text
14419windows on the terminal.
c906108c 14420
8e04817f
AC
14421@item
14422A standard mode which corresponds to the @value{GDBN} configured without
14423the TUI.
14424@end itemize
c906108c 14425
8e04817f
AC
14426In the TUI mode, @value{GDBN} can display several text window
14427on the terminal:
c906108c 14428
8e04817f
AC
14429@table @emph
14430@item command
14431This window is the @value{GDBN} command window with the @value{GDBN}
14432prompt and the @value{GDBN} outputs. The @value{GDBN} input is still
14433managed using readline but through the TUI. The @emph{command}
14434window is always visible.
c906108c 14435
8e04817f
AC
14436@item source
14437The source window shows the source file of the program. The current
14438line as well as active breakpoints are displayed in this window.
c906108c 14439
8e04817f
AC
14440@item assembly
14441The assembly window shows the disassembly output of the program.
c906108c 14442
8e04817f
AC
14443@item register
14444This window shows the processor registers. It detects when
14445a register is changed and when this is the case, registers that have
6a1b180d 14446changed are highlighted.
c906108c 14447
c906108c
SS
14448@end table
14449
269c21fe
SC
14450The source and assembly windows show the current program position
14451by highlighting the current line and marking them with the @samp{>} marker.
14452Breakpoints are also indicated with two markers. A first one
14453indicates the breakpoint type:
14454
14455@table @code
14456@item B
14457Breakpoint which was hit at least once.
14458
14459@item b
14460Breakpoint which was never hit.
14461
14462@item H
14463Hardware breakpoint which was hit at least once.
14464
14465@item h
14466Hardware breakpoint which was never hit.
14467
14468@end table
14469
14470The second marker indicates whether the breakpoint is enabled or not:
14471
14472@table @code
14473@item +
14474Breakpoint is enabled.
14475
14476@item -
14477Breakpoint is disabled.
14478
14479@end table
14480
8e04817f
AC
14481The source, assembly and register windows are attached to the thread
14482and the frame position. They are updated when the current thread
14483changes, when the frame changes or when the program counter changes.
14484These three windows are arranged by the TUI according to several
14485layouts. The layout defines which of these three windows are visible.
14486The following layouts are available:
c906108c 14487
8e04817f
AC
14488@itemize @bullet
14489@item
14490source
2df3850c 14491
8e04817f
AC
14492@item
14493assembly
14494
14495@item
14496source and assembly
14497
14498@item
14499source and registers
c906108c 14500
8e04817f
AC
14501@item
14502assembly and registers
2df3850c 14503
8e04817f 14504@end itemize
c906108c 14505
b7bb15bc
SC
14506On top of the command window a status line gives various information
14507concerning the current process begin debugged. The status line is
14508updated when the information it shows changes. The following fields
14509are displayed:
14510
14511@table @emph
14512@item target
14513Indicates the current gdb target
14514(@pxref{Targets, ,Specifying a Debugging Target}).
14515
14516@item process
14517Gives information about the current process or thread number.
14518When no process is being debugged, this field is set to @code{No process}.
14519
14520@item function
14521Gives the current function name for the selected frame.
14522The name is demangled if demangling is turned on (@pxref{Print Settings}).
14523When there is no symbol corresponding to the current program counter
14524the string @code{??} is displayed.
14525
14526@item line
14527Indicates the current line number for the selected frame.
14528When the current line number is not known the string @code{??} is displayed.
14529
14530@item pc
14531Indicates the current program counter address.
14532
14533@end table
14534
8e04817f
AC
14535@node TUI Keys
14536@section TUI Key Bindings
14537@cindex TUI key bindings
c906108c 14538
8e04817f
AC
14539The TUI installs several key bindings in the readline keymaps
14540(@pxref{Command Line Editing}).
14541They allow to leave or enter in the TUI mode or they operate
7cf36c78
SC
14542directly on the TUI layout and windows. The TUI also provides
14543a @emph{SingleKey} keymap which binds several keys directly to
14544@value{GDBN} commands. The following key bindings
8e04817f 14545are installed for both TUI mode and the @value{GDBN} standard mode.
c906108c 14546
8e04817f
AC
14547@table @kbd
14548@kindex C-x C-a
14549@item C-x C-a
14550@kindex C-x a
14551@itemx C-x a
14552@kindex C-x A
14553@itemx C-x A
14554Enter or leave the TUI mode. When the TUI mode is left,
14555the curses window management is left and @value{GDBN} operates using
14556its standard mode writing on the terminal directly. When the TUI
14557mode is entered, the control is given back to the curses windows.
14558The screen is then refreshed.
c906108c 14559
8e04817f
AC
14560@kindex C-x 1
14561@item C-x 1
14562Use a TUI layout with only one window. The layout will
14563either be @samp{source} or @samp{assembly}. When the TUI mode
14564is not active, it will switch to the TUI mode.
2df3850c 14565
8e04817f 14566Think of this key binding as the Emacs @kbd{C-x 1} binding.
c906108c 14567
8e04817f
AC
14568@kindex C-x 2
14569@item C-x 2
14570Use a TUI layout with at least two windows. When the current
14571layout shows already two windows, a next layout with two windows is used.
14572When a new layout is chosen, one window will always be common to the
14573previous layout and the new one.
c906108c 14574
8e04817f 14575Think of it as the Emacs @kbd{C-x 2} binding.
2df3850c 14576
72ffddc9
SC
14577@kindex C-x o
14578@item C-x o
14579Change the active window. The TUI associates several key bindings
14580(like scrolling and arrow keys) to the active window. This command
14581gives the focus to the next TUI window.
14582
14583Think of it as the Emacs @kbd{C-x o} binding.
14584
7cf36c78
SC
14585@kindex C-x s
14586@item C-x s
14587Use the TUI @emph{SingleKey} keymap that binds single key to gdb commands
14588(@pxref{TUI Single Key Mode}).
14589
c906108c
SS
14590@end table
14591
8e04817f 14592The following key bindings are handled only by the TUI mode:
5d161b24 14593
8e04817f
AC
14594@table @key
14595@kindex PgUp
14596@item PgUp
14597Scroll the active window one page up.
c906108c 14598
8e04817f
AC
14599@kindex PgDn
14600@item PgDn
14601Scroll the active window one page down.
c906108c 14602
8e04817f
AC
14603@kindex Up
14604@item Up
14605Scroll the active window one line up.
c906108c 14606
8e04817f
AC
14607@kindex Down
14608@item Down
14609Scroll the active window one line down.
c906108c 14610
8e04817f
AC
14611@kindex Left
14612@item Left
14613Scroll the active window one column left.
c906108c 14614
8e04817f
AC
14615@kindex Right
14616@item Right
14617Scroll the active window one column right.
c906108c 14618
8e04817f
AC
14619@kindex C-L
14620@item C-L
14621Refresh the screen.
c906108c 14622
8e04817f 14623@end table
c906108c 14624
8e04817f 14625In the TUI mode, the arrow keys are used by the active window
72ffddc9
SC
14626for scrolling. This means they are available for readline when the
14627active window is the command window. When the command window
14628does not have the focus, it is necessary to use other readline
14629key bindings such as @key{C-p}, @key{C-n}, @key{C-b} and @key{C-f}.
8e04817f 14630
7cf36c78
SC
14631@node TUI Single Key Mode
14632@section TUI Single Key Mode
14633@cindex TUI single key mode
14634
14635The TUI provides a @emph{SingleKey} mode in which it installs a particular
14636key binding in the readline keymaps to connect single keys to
b383017d 14637some gdb commands.
7cf36c78
SC
14638
14639@table @kbd
14640@kindex c @r{(SingleKey TUI key)}
14641@item c
14642continue
14643
14644@kindex d @r{(SingleKey TUI key)}
14645@item d
14646down
14647
14648@kindex f @r{(SingleKey TUI key)}
14649@item f
14650finish
14651
14652@kindex n @r{(SingleKey TUI key)}
14653@item n
14654next
14655
14656@kindex q @r{(SingleKey TUI key)}
14657@item q
14658exit the @emph{SingleKey} mode.
14659
14660@kindex r @r{(SingleKey TUI key)}
14661@item r
14662run
14663
14664@kindex s @r{(SingleKey TUI key)}
14665@item s
14666step
14667
14668@kindex u @r{(SingleKey TUI key)}
14669@item u
14670up
14671
14672@kindex v @r{(SingleKey TUI key)}
14673@item v
14674info locals
14675
14676@kindex w @r{(SingleKey TUI key)}
14677@item w
14678where
14679
14680@end table
14681
14682Other keys temporarily switch to the @value{GDBN} command prompt.
14683The key that was pressed is inserted in the editing buffer so that
14684it is possible to type most @value{GDBN} commands without interaction
14685with the TUI @emph{SingleKey} mode. Once the command is entered the TUI
14686@emph{SingleKey} mode is restored. The only way to permanently leave
14687this mode is by hitting @key{q} or @samp{@key{C-x} @key{s}}.
14688
14689
8e04817f
AC
14690@node TUI Commands
14691@section TUI specific commands
14692@cindex TUI commands
14693
14694The TUI has specific commands to control the text windows.
14695These commands are always available, that is they do not depend on
14696the current terminal mode in which @value{GDBN} runs. When @value{GDBN}
14697is in the standard mode, using these commands will automatically switch
14698in the TUI mode.
c906108c
SS
14699
14700@table @code
3d757584
SC
14701@item info win
14702@kindex info win
14703List and give the size of all displayed windows.
14704
8e04817f 14705@item layout next
4644b6e3 14706@kindex layout
8e04817f 14707Display the next layout.
2df3850c 14708
8e04817f 14709@item layout prev
8e04817f 14710Display the previous layout.
c906108c 14711
8e04817f 14712@item layout src
8e04817f 14713Display the source window only.
c906108c 14714
8e04817f 14715@item layout asm
8e04817f 14716Display the assembly window only.
c906108c 14717
8e04817f 14718@item layout split
8e04817f 14719Display the source and assembly window.
c906108c 14720
8e04817f 14721@item layout regs
8e04817f
AC
14722Display the register window together with the source or assembly window.
14723
14724@item focus next | prev | src | asm | regs | split
14725@kindex focus
14726Set the focus to the named window.
14727This command allows to change the active window so that scrolling keys
14728can be affected to another window.
c906108c 14729
8e04817f
AC
14730@item refresh
14731@kindex refresh
14732Refresh the screen. This is similar to using @key{C-L} key.
c906108c 14733
6a1b180d
SC
14734@item tui reg float
14735@kindex tui reg
14736Show the floating point registers in the register window.
14737
14738@item tui reg general
14739Show the general registers in the register window.
14740
14741@item tui reg next
14742Show the next register group. The list of register groups as well as
14743their order is target specific. The predefined register groups are the
14744following: @code{general}, @code{float}, @code{system}, @code{vector},
14745@code{all}, @code{save}, @code{restore}.
14746
14747@item tui reg system
14748Show the system registers in the register window.
14749
8e04817f
AC
14750@item update
14751@kindex update
14752Update the source window and the current execution point.
c906108c 14753
8e04817f
AC
14754@item winheight @var{name} +@var{count}
14755@itemx winheight @var{name} -@var{count}
14756@kindex winheight
14757Change the height of the window @var{name} by @var{count}
14758lines. Positive counts increase the height, while negative counts
14759decrease it.
2df3850c 14760
c906108c
SS
14761@end table
14762
8e04817f
AC
14763@node TUI Configuration
14764@section TUI configuration variables
14765@cindex TUI configuration variables
c906108c 14766
8e04817f
AC
14767The TUI has several configuration variables that control the
14768appearance of windows on the terminal.
c906108c 14769
8e04817f
AC
14770@table @code
14771@item set tui border-kind @var{kind}
14772@kindex set tui border-kind
14773Select the border appearance for the source, assembly and register windows.
14774The possible values are the following:
14775@table @code
14776@item space
14777Use a space character to draw the border.
c906108c 14778
8e04817f
AC
14779@item ascii
14780Use ascii characters + - and | to draw the border.
c906108c 14781
8e04817f
AC
14782@item acs
14783Use the Alternate Character Set to draw the border. The border is
14784drawn using character line graphics if the terminal supports them.
c78b4128 14785
8e04817f 14786@end table
c78b4128 14787
8e04817f
AC
14788@item set tui active-border-mode @var{mode}
14789@kindex set tui active-border-mode
14790Select the attributes to display the border of the active window.
14791The possible values are @code{normal}, @code{standout}, @code{reverse},
14792@code{half}, @code{half-standout}, @code{bold} and @code{bold-standout}.
c78b4128 14793
8e04817f
AC
14794@item set tui border-mode @var{mode}
14795@kindex set tui border-mode
14796Select the attributes to display the border of other windows.
14797The @var{mode} can be one of the following:
14798@table @code
14799@item normal
14800Use normal attributes to display the border.
c906108c 14801
8e04817f
AC
14802@item standout
14803Use standout mode.
c906108c 14804
8e04817f
AC
14805@item reverse
14806Use reverse video mode.
c906108c 14807
8e04817f
AC
14808@item half
14809Use half bright mode.
c906108c 14810
8e04817f
AC
14811@item half-standout
14812Use half bright and standout mode.
c906108c 14813
8e04817f
AC
14814@item bold
14815Use extra bright or bold mode.
c78b4128 14816
8e04817f
AC
14817@item bold-standout
14818Use extra bright or bold and standout mode.
c78b4128 14819
8e04817f 14820@end table
c78b4128 14821
8e04817f 14822@end table
c78b4128 14823
8e04817f
AC
14824@node Emacs
14825@chapter Using @value{GDBN} under @sc{gnu} Emacs
c78b4128 14826
8e04817f
AC
14827@cindex Emacs
14828@cindex @sc{gnu} Emacs
14829A special interface allows you to use @sc{gnu} Emacs to view (and
14830edit) the source files for the program you are debugging with
14831@value{GDBN}.
c906108c 14832
8e04817f
AC
14833To use this interface, use the command @kbd{M-x gdb} in Emacs. Give the
14834executable file you want to debug as an argument. This command starts
14835@value{GDBN} as a subprocess of Emacs, with input and output through a newly
14836created Emacs buffer.
14837@c (Do not use the @code{-tui} option to run @value{GDBN} from Emacs.)
c906108c 14838
8e04817f
AC
14839Using @value{GDBN} under Emacs is just like using @value{GDBN} normally except for two
14840things:
c906108c 14841
8e04817f
AC
14842@itemize @bullet
14843@item
14844All ``terminal'' input and output goes through the Emacs buffer.
14845@end itemize
c906108c 14846
8e04817f
AC
14847This applies both to @value{GDBN} commands and their output, and to the input
14848and output done by the program you are debugging.
bf0184be 14849
8e04817f
AC
14850This is useful because it means that you can copy the text of previous
14851commands and input them again; you can even use parts of the output
14852in this way.
bf0184be 14853
8e04817f
AC
14854All the facilities of Emacs' Shell mode are available for interacting
14855with your program. In particular, you can send signals the usual
14856way---for example, @kbd{C-c C-c} for an interrupt, @kbd{C-c C-z} for a
14857stop.
bf0184be 14858
8e04817f 14859@itemize @bullet
bf0184be 14860@item
8e04817f
AC
14861@value{GDBN} displays source code through Emacs.
14862@end itemize
bf0184be 14863
8e04817f
AC
14864Each time @value{GDBN} displays a stack frame, Emacs automatically finds the
14865source file for that frame and puts an arrow (@samp{=>}) at the
14866left margin of the current line. Emacs uses a separate buffer for
14867source display, and splits the screen to show both your @value{GDBN} session
14868and the source.
bf0184be 14869
8e04817f
AC
14870Explicit @value{GDBN} @code{list} or search commands still produce output as
14871usual, but you probably have no reason to use them from Emacs.
c906108c 14872
64fabec2
AC
14873If you specify an absolute file name when prompted for the @kbd{M-x
14874gdb} argument, then Emacs sets your current working directory to where
14875your program resides. If you only specify the file name, then Emacs
14876sets your current working directory to to the directory associated
14877with the previous buffer. In this case, @value{GDBN} may find your
14878program by searching your environment's @code{PATH} variable, but on
14879some operating systems it might not find the source. So, although the
14880@value{GDBN} input and output session proceeds normally, the auxiliary
14881buffer does not display the current source and line of execution.
14882
14883The initial working directory of @value{GDBN} is printed on the top
14884line of the @value{GDBN} I/O buffer and this serves as a default for
14885the commands that specify files for @value{GDBN} to operate
14886on. @xref{Files, ,Commands to specify files}.
14887
14888By default, @kbd{M-x gdb} calls the program called @file{gdb}. If you
14889need to call @value{GDBN} by a different name (for example, if you
14890keep several configurations around, with different names) you can
14891customize the Emacs variable @code{gud-gdb-command-name} to run the
14892one you want.
8e04817f
AC
14893
14894In the @value{GDBN} I/O buffer, you can use these special Emacs commands in
14895addition to the standard Shell mode commands:
c906108c 14896
8e04817f
AC
14897@table @kbd
14898@item C-h m
14899Describe the features of Emacs' @value{GDBN} Mode.
c906108c 14900
64fabec2 14901@item C-c C-s
8e04817f
AC
14902Execute to another source line, like the @value{GDBN} @code{step} command; also
14903update the display window to show the current file and location.
c906108c 14904
64fabec2 14905@item C-c C-n
8e04817f
AC
14906Execute to next source line in this function, skipping all function
14907calls, like the @value{GDBN} @code{next} command. Then update the display window
14908to show the current file and location.
c906108c 14909
64fabec2 14910@item C-c C-i
8e04817f
AC
14911Execute one instruction, like the @value{GDBN} @code{stepi} command; update
14912display window accordingly.
c906108c 14913
8e04817f
AC
14914@item C-c C-f
14915Execute until exit from the selected stack frame, like the @value{GDBN}
14916@code{finish} command.
c906108c 14917
64fabec2 14918@item C-c C-r
8e04817f
AC
14919Continue execution of your program, like the @value{GDBN} @code{continue}
14920command.
b433d00b 14921
64fabec2 14922@item C-c <
8e04817f
AC
14923Go up the number of frames indicated by the numeric argument
14924(@pxref{Arguments, , Numeric Arguments, Emacs, The @sc{gnu} Emacs Manual}),
14925like the @value{GDBN} @code{up} command.
b433d00b 14926
64fabec2 14927@item C-c >
8e04817f
AC
14928Go down the number of frames indicated by the numeric argument, like the
14929@value{GDBN} @code{down} command.
8e04817f 14930@end table
c906108c 14931
64fabec2 14932In any source file, the Emacs command @kbd{C-x SPC} (@code{gud-break})
8e04817f 14933tells @value{GDBN} to set a breakpoint on the source line point is on.
c906108c 14934
64fabec2
AC
14935If you type @kbd{M-x speedbar}, then Emacs displays a separate frame which
14936shows a backtrace when the @value{GDBN} I/O buffer is current. Move
14937point to any frame in the stack and type @key{RET} to make it become the
14938current frame and display the associated source in the source buffer.
14939Alternatively, click @kbd{Mouse-2} to make the selected frame become the
14940current one.
14941
8e04817f
AC
14942If you accidentally delete the source-display buffer, an easy way to get
14943it back is to type the command @code{f} in the @value{GDBN} buffer, to
14944request a frame display; when you run under Emacs, this recreates
14945the source buffer if necessary to show you the context of the current
14946frame.
c906108c 14947
8e04817f
AC
14948The source files displayed in Emacs are in ordinary Emacs buffers
14949which are visiting the source files in the usual way. You can edit
14950the files with these buffers if you wish; but keep in mind that @value{GDBN}
14951communicates with Emacs in terms of line numbers. If you add or
14952delete lines from the text, the line numbers that @value{GDBN} knows cease
14953to correspond properly with the code.
b383017d 14954
64fabec2
AC
14955The description given here is for GNU Emacs version 21.3 and a more
14956detailed description of its interaction with @value{GDBN} is given in
14957the Emacs manual (@pxref{Debuggers,,, Emacs, The @sc{gnu} Emacs Manual}).
c906108c 14958
8e04817f
AC
14959@c The following dropped because Epoch is nonstandard. Reactivate
14960@c if/when v19 does something similar. ---doc@cygnus.com 19dec1990
14961@ignore
14962@kindex Emacs Epoch environment
14963@kindex Epoch
14964@kindex inspect
c906108c 14965
8e04817f
AC
14966Version 18 of @sc{gnu} Emacs has a built-in window system
14967called the @code{epoch}
14968environment. Users of this environment can use a new command,
14969@code{inspect} which performs identically to @code{print} except that
14970each value is printed in its own window.
14971@end ignore
c906108c 14972
922fbb7b
AC
14973
14974@node GDB/MI
14975@chapter The @sc{gdb/mi} Interface
14976
14977@unnumberedsec Function and Purpose
14978
14979@cindex @sc{gdb/mi}, its purpose
14980@sc{gdb/mi} is a line based machine oriented text interface to @value{GDBN}. It is
14981specifically intended to support the development of systems which use
14982the debugger as just one small component of a larger system.
14983
14984This chapter is a specification of the @sc{gdb/mi} interface. It is written
14985in the form of a reference manual.
14986
14987Note that @sc{gdb/mi} is still under construction, so some of the
14988features described below are incomplete and subject to change.
14989
14990@unnumberedsec Notation and Terminology
14991
14992@cindex notational conventions, for @sc{gdb/mi}
14993This chapter uses the following notation:
14994
14995@itemize @bullet
14996@item
14997@code{|} separates two alternatives.
14998
14999@item
15000@code{[ @var{something} ]} indicates that @var{something} is optional:
15001it may or may not be given.
15002
15003@item
15004@code{( @var{group} )*} means that @var{group} inside the parentheses
15005may repeat zero or more times.
15006
15007@item
15008@code{( @var{group} )+} means that @var{group} inside the parentheses
15009may repeat one or more times.
15010
15011@item
15012@code{"@var{string}"} means a literal @var{string}.
15013@end itemize
15014
15015@ignore
15016@heading Dependencies
15017@end ignore
15018
15019@heading Acknowledgments
15020
15021In alphabetic order: Andrew Cagney, Fernando Nasser, Stan Shebs and
15022Elena Zannoni.
15023
15024@menu
15025* GDB/MI Command Syntax::
15026* GDB/MI Compatibility with CLI::
15027* GDB/MI Output Records::
15028* GDB/MI Command Description Format::
15029* GDB/MI Breakpoint Table Commands::
15030* GDB/MI Data Manipulation::
15031* GDB/MI Program Control::
15032* GDB/MI Miscellaneous Commands::
15033@ignore
15034* GDB/MI Kod Commands::
15035* GDB/MI Memory Overlay Commands::
15036* GDB/MI Signal Handling Commands::
15037@end ignore
15038* GDB/MI Stack Manipulation::
15039* GDB/MI Symbol Query::
15040* GDB/MI Target Manipulation::
15041* GDB/MI Thread Commands::
15042* GDB/MI Tracepoint Commands::
15043* GDB/MI Variable Objects::
15044@end menu
15045
15046@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
15047@node GDB/MI Command Syntax
15048@section @sc{gdb/mi} Command Syntax
15049
15050@menu
15051* GDB/MI Input Syntax::
15052* GDB/MI Output Syntax::
15053* GDB/MI Simple Examples::
15054@end menu
15055
15056@node GDB/MI Input Syntax
15057@subsection @sc{gdb/mi} Input Syntax
15058
15059@cindex input syntax for @sc{gdb/mi}
15060@cindex @sc{gdb/mi}, input syntax
15061@table @code
15062@item @var{command} @expansion{}
15063@code{@var{cli-command} | @var{mi-command}}
15064
15065@item @var{cli-command} @expansion{}
15066@code{[ @var{token} ] @var{cli-command} @var{nl}}, where
15067@var{cli-command} is any existing @value{GDBN} CLI command.
15068
15069@item @var{mi-command} @expansion{}
15070@code{[ @var{token} ] "-" @var{operation} ( " " @var{option} )*
15071@code{[} " --" @code{]} ( " " @var{parameter} )* @var{nl}}
15072
15073@item @var{token} @expansion{}
15074"any sequence of digits"
15075
15076@item @var{option} @expansion{}
15077@code{"-" @var{parameter} [ " " @var{parameter} ]}
15078
15079@item @var{parameter} @expansion{}
15080@code{@var{non-blank-sequence} | @var{c-string}}
15081
15082@item @var{operation} @expansion{}
15083@emph{any of the operations described in this chapter}
15084
15085@item @var{non-blank-sequence} @expansion{}
15086@emph{anything, provided it doesn't contain special characters such as
15087"-", @var{nl}, """ and of course " "}
15088
15089@item @var{c-string} @expansion{}
15090@code{""" @var{seven-bit-iso-c-string-content} """}
15091
15092@item @var{nl} @expansion{}
15093@code{CR | CR-LF}
15094@end table
15095
15096@noindent
15097Notes:
15098
15099@itemize @bullet
15100@item
15101The CLI commands are still handled by the @sc{mi} interpreter; their
15102output is described below.
15103
15104@item
15105The @code{@var{token}}, when present, is passed back when the command
15106finishes.
15107
15108@item
15109Some @sc{mi} commands accept optional arguments as part of the parameter
15110list. Each option is identified by a leading @samp{-} (dash) and may be
15111followed by an optional argument parameter. Options occur first in the
15112parameter list and can be delimited from normal parameters using
15113@samp{--} (this is useful when some parameters begin with a dash).
15114@end itemize
15115
15116Pragmatics:
15117
15118@itemize @bullet
15119@item
15120We want easy access to the existing CLI syntax (for debugging).
15121
15122@item
15123We want it to be easy to spot a @sc{mi} operation.
15124@end itemize
15125
15126@node GDB/MI Output Syntax
15127@subsection @sc{gdb/mi} Output Syntax
15128
15129@cindex output syntax of @sc{gdb/mi}
15130@cindex @sc{gdb/mi}, output syntax
15131The output from @sc{gdb/mi} consists of zero or more out-of-band records
15132followed, optionally, by a single result record. This result record
15133is for the most recent command. The sequence of output records is
15134terminated by @samp{(@value{GDBP})}.
15135
15136If an input command was prefixed with a @code{@var{token}} then the
15137corresponding output for that command will also be prefixed by that same
15138@var{token}.
15139
15140@table @code
15141@item @var{output} @expansion{}
f7dc1244 15142@code{( @var{out-of-band-record} )* [ @var{result-record} ] "(@value{GDBP})" @var{nl}}
922fbb7b
AC
15143
15144@item @var{result-record} @expansion{}
15145@code{ [ @var{token} ] "^" @var{result-class} ( "," @var{result} )* @var{nl}}
15146
15147@item @var{out-of-band-record} @expansion{}
15148@code{@var{async-record} | @var{stream-record}}
15149
15150@item @var{async-record} @expansion{}
15151@code{@var{exec-async-output} | @var{status-async-output} | @var{notify-async-output}}
15152
15153@item @var{exec-async-output} @expansion{}
15154@code{[ @var{token} ] "*" @var{async-output}}
15155
15156@item @var{status-async-output} @expansion{}
15157@code{[ @var{token} ] "+" @var{async-output}}
15158
15159@item @var{notify-async-output} @expansion{}
15160@code{[ @var{token} ] "=" @var{async-output}}
15161
15162@item @var{async-output} @expansion{}
15163@code{@var{async-class} ( "," @var{result} )* @var{nl}}
15164
15165@item @var{result-class} @expansion{}
15166@code{"done" | "running" | "connected" | "error" | "exit"}
15167
15168@item @var{async-class} @expansion{}
15169@code{"stopped" | @var{others}} (where @var{others} will be added
15170depending on the needs---this is still in development).
15171
15172@item @var{result} @expansion{}
15173@code{ @var{variable} "=" @var{value}}
15174
15175@item @var{variable} @expansion{}
15176@code{ @var{string} }
15177
15178@item @var{value} @expansion{}
15179@code{ @var{const} | @var{tuple} | @var{list} }
15180
15181@item @var{const} @expansion{}
15182@code{@var{c-string}}
15183
15184@item @var{tuple} @expansion{}
15185@code{ "@{@}" | "@{" @var{result} ( "," @var{result} )* "@}" }
15186
15187@item @var{list} @expansion{}
15188@code{ "[]" | "[" @var{value} ( "," @var{value} )* "]" | "["
15189@var{result} ( "," @var{result} )* "]" }
15190
15191@item @var{stream-record} @expansion{}
15192@code{@var{console-stream-output} | @var{target-stream-output} | @var{log-stream-output}}
15193
15194@item @var{console-stream-output} @expansion{}
15195@code{"~" @var{c-string}}
15196
15197@item @var{target-stream-output} @expansion{}
15198@code{"@@" @var{c-string}}
15199
15200@item @var{log-stream-output} @expansion{}
15201@code{"&" @var{c-string}}
15202
15203@item @var{nl} @expansion{}
15204@code{CR | CR-LF}
15205
15206@item @var{token} @expansion{}
15207@emph{any sequence of digits}.
15208@end table
15209
15210@noindent
15211Notes:
15212
15213@itemize @bullet
15214@item
15215All output sequences end in a single line containing a period.
15216
15217@item
15218The @code{@var{token}} is from the corresponding request. If an execution
15219command is interrupted by the @samp{-exec-interrupt} command, the
15220@var{token} associated with the @samp{*stopped} message is the one of the
15221original execution command, not the one of the interrupt command.
15222
15223@item
15224@cindex status output in @sc{gdb/mi}
15225@var{status-async-output} contains on-going status information about the
15226progress of a slow operation. It can be discarded. All status output is
15227prefixed by @samp{+}.
15228
15229@item
15230@cindex async output in @sc{gdb/mi}
15231@var{exec-async-output} contains asynchronous state change on the target
15232(stopped, started, disappeared). All async output is prefixed by
15233@samp{*}.
15234
15235@item
15236@cindex notify output in @sc{gdb/mi}
15237@var{notify-async-output} contains supplementary information that the
15238client should handle (e.g., a new breakpoint information). All notify
15239output is prefixed by @samp{=}.
15240
15241@item
15242@cindex console output in @sc{gdb/mi}
15243@var{console-stream-output} is output that should be displayed as is in the
15244console. It is the textual response to a CLI command. All the console
15245output is prefixed by @samp{~}.
15246
15247@item
15248@cindex target output in @sc{gdb/mi}
15249@var{target-stream-output} is the output produced by the target program.
15250All the target output is prefixed by @samp{@@}.
15251
15252@item
15253@cindex log output in @sc{gdb/mi}
15254@var{log-stream-output} is output text coming from @value{GDBN}'s internals, for
15255instance messages that should be displayed as part of an error log. All
15256the log output is prefixed by @samp{&}.
15257
15258@item
15259@cindex list output in @sc{gdb/mi}
15260New @sc{gdb/mi} commands should only output @var{lists} containing
15261@var{values}.
15262
15263
15264@end itemize
15265
15266@xref{GDB/MI Stream Records, , @sc{gdb/mi} Stream Records}, for more
15267details about the various output records.
15268
15269@node GDB/MI Simple Examples
15270@subsection Simple Examples of @sc{gdb/mi} Interaction
15271@cindex @sc{gdb/mi}, simple examples
15272
15273This subsection presents several simple examples of interaction using
15274the @sc{gdb/mi} interface. In these examples, @samp{->} means that the
15275following line is passed to @sc{gdb/mi} as input, while @samp{<-} means
15276the output received from @sc{gdb/mi}.
15277
15278@subsubheading Target Stop
15279@c Ummm... There is no "-stop" command. This assumes async, no?
15280Here's an example of stopping the inferior process:
15281
15282@smallexample
15283-> -stop
15284<- (@value{GDBP})
15285@end smallexample
15286
15287@noindent
15288and later:
15289
15290@smallexample
15291<- *stop,reason="stop",address="0x123",source="a.c:123"
15292<- (@value{GDBP})
15293@end smallexample
15294
15295@subsubheading Simple CLI Command
15296
15297Here's an example of a simple CLI command being passed through
15298@sc{gdb/mi} and on to the CLI.
15299
15300@smallexample
15301-> print 1+2
15302<- &"print 1+2\n"
15303<- ~"$1 = 3\n"
15304<- ^done
15305<- (@value{GDBP})
15306@end smallexample
15307
15308@subsubheading Command With Side Effects
15309
15310@smallexample
15311-> -symbol-file xyz.exe
15312<- *breakpoint,nr="3",address="0x123",source="a.c:123"
15313<- (@value{GDBP})
15314@end smallexample
15315
15316@subsubheading A Bad Command
15317
15318Here's what happens if you pass a non-existent command:
15319
15320@smallexample
15321-> -rubbish
15322<- ^error,msg="Undefined MI command: rubbish"
15323<- (@value{GDBP})
15324@end smallexample
15325
15326@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
15327@node GDB/MI Compatibility with CLI
15328@section @sc{gdb/mi} Compatibility with CLI
15329
15330@cindex compatibility, @sc{gdb/mi} and CLI
15331@cindex @sc{gdb/mi}, compatibility with CLI
15332To help users familiar with @value{GDBN}'s existing CLI interface, @sc{gdb/mi}
15333accepts existing CLI commands. As specified by the syntax, such
15334commands can be directly entered into the @sc{gdb/mi} interface and @value{GDBN} will
15335respond.
15336
15337This mechanism is provided as an aid to developers of @sc{gdb/mi}
15338clients and not as a reliable interface into the CLI. Since the command
15339is being interpreteted in an environment that assumes @sc{gdb/mi}
15340behaviour, the exact output of such commands is likely to end up being
15341an un-supported hybrid of @sc{gdb/mi} and CLI output.
15342
15343@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
15344@node GDB/MI Output Records
15345@section @sc{gdb/mi} Output Records
15346
15347@menu
15348* GDB/MI Result Records::
15349* GDB/MI Stream Records::
15350* GDB/MI Out-of-band Records::
15351@end menu
15352
15353@node GDB/MI Result Records
15354@subsection @sc{gdb/mi} Result Records
15355
15356@cindex result records in @sc{gdb/mi}
15357@cindex @sc{gdb/mi}, result records
15358In addition to a number of out-of-band notifications, the response to a
15359@sc{gdb/mi} command includes one of the following result indications:
15360
15361@table @code
15362@findex ^done
15363@item "^done" [ "," @var{results} ]
15364The synchronous operation was successful, @code{@var{results}} are the return
15365values.
15366
15367@item "^running"
15368@findex ^running
15369@c Is this one correct? Should it be an out-of-band notification?
15370The asynchronous operation was successfully started. The target is
15371running.
15372
15373@item "^error" "," @var{c-string}
15374@findex ^error
15375The operation failed. The @code{@var{c-string}} contains the corresponding
15376error message.
15377@end table
15378
15379@node GDB/MI Stream Records
15380@subsection @sc{gdb/mi} Stream Records
15381
15382@cindex @sc{gdb/mi}, stream records
15383@cindex stream records in @sc{gdb/mi}
15384@value{GDBN} internally maintains a number of output streams: the console, the
15385target, and the log. The output intended for each of these streams is
15386funneled through the @sc{gdb/mi} interface using @dfn{stream records}.
15387
15388Each stream record begins with a unique @dfn{prefix character} which
15389identifies its stream (@pxref{GDB/MI Output Syntax, , @sc{gdb/mi} Output
15390Syntax}). In addition to the prefix, each stream record contains a
15391@code{@var{string-output}}. This is either raw text (with an implicit new
15392line) or a quoted C string (which does not contain an implicit newline).
15393
15394@table @code
15395@item "~" @var{string-output}
15396The console output stream contains text that should be displayed in the
15397CLI console window. It contains the textual responses to CLI commands.
15398
15399@item "@@" @var{string-output}
15400The target output stream contains any textual output from the running
15401target.
15402
15403@item "&" @var{string-output}
15404The log stream contains debugging messages being produced by @value{GDBN}'s
15405internals.
15406@end table
15407
15408@node GDB/MI Out-of-band Records
15409@subsection @sc{gdb/mi} Out-of-band Records
15410
15411@cindex out-of-band records in @sc{gdb/mi}
15412@cindex @sc{gdb/mi}, out-of-band records
15413@dfn{Out-of-band} records are used to notify the @sc{gdb/mi} client of
15414additional changes that have occurred. Those changes can either be a
15415consequence of @sc{gdb/mi} (e.g., a breakpoint modified) or a result of
15416target activity (e.g., target stopped).
15417
15418The following is a preliminary list of possible out-of-band records.
15419
15420@table @code
15421@item "*" "stop"
15422@end table
15423
15424
15425@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
15426@node GDB/MI Command Description Format
15427@section @sc{gdb/mi} Command Description Format
15428
15429The remaining sections describe blocks of commands. Each block of
15430commands is laid out in a fashion similar to this section.
15431
15432Note the the line breaks shown in the examples are here only for
15433readability. They don't appear in the real output.
15434Also note that the commands with a non-available example (N.A.@:) are
15435not yet implemented.
15436
15437@subheading Motivation
15438
15439The motivation for this collection of commands.
15440
15441@subheading Introduction
15442
15443A brief introduction to this collection of commands as a whole.
15444
15445@subheading Commands
15446
15447For each command in the block, the following is described:
15448
15449@subsubheading Synopsis
15450
15451@smallexample
15452 -command @var{args}@dots{}
15453@end smallexample
15454
15455@subsubheading @value{GDBN} Command
15456
15457The corresponding @value{GDBN} CLI command.
15458
15459@subsubheading Result
15460
15461@subsubheading Out-of-band
15462
15463@subsubheading Notes
15464
15465@subsubheading Example
15466
15467
15468@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
15469@node GDB/MI Breakpoint Table Commands
15470@section @sc{gdb/mi} Breakpoint table commands
15471
15472@cindex breakpoint commands for @sc{gdb/mi}
15473@cindex @sc{gdb/mi}, breakpoint commands
15474This section documents @sc{gdb/mi} commands for manipulating
15475breakpoints.
15476
15477@subheading The @code{-break-after} Command
15478@findex -break-after
15479
15480@subsubheading Synopsis
15481
15482@smallexample
15483 -break-after @var{number} @var{count}
15484@end smallexample
15485
15486The breakpoint number @var{number} is not in effect until it has been
15487hit @var{count} times. To see how this is reflected in the output of
15488the @samp{-break-list} command, see the description of the
15489@samp{-break-list} command below.
15490
15491@subsubheading @value{GDBN} Command
15492
15493The corresponding @value{GDBN} command is @samp{ignore}.
15494
15495@subsubheading Example
15496
15497@smallexample
15498(@value{GDBP})
15499-break-insert main
15500^done,bkpt=@{number="1",addr="0x000100d0",file="hello.c",line="5"@}
15501(@value{GDBP})
15502-break-after 1 3
15503~
15504^done
15505(@value{GDBP})
15506-break-list
15507^done,BreakpointTable=@{nr_rows="1",nr_cols="6",
15508hdr=[@{width="3",alignment="-1",col_name="number",colhdr="Num"@},
15509@{width="14",alignment="-1",col_name="type",colhdr="Type"@},
15510@{width="4",alignment="-1",col_name="disp",colhdr="Disp"@},
15511@{width="3",alignment="-1",col_name="enabled",colhdr="Enb"@},
15512@{width="10",alignment="-1",col_name="addr",colhdr="Address"@},
15513@{width="40",alignment="2",col_name="what",colhdr="What"@}],
15514body=[bkpt=@{number="1",type="breakpoint",disp="keep",enabled="y",
15515addr="0x000100d0",func="main",file="hello.c",line="5",times="0",
15516ignore="3"@}]@}
15517(@value{GDBP})
15518@end smallexample
15519
15520@ignore
15521@subheading The @code{-break-catch} Command
15522@findex -break-catch
15523
15524@subheading The @code{-break-commands} Command
15525@findex -break-commands
15526@end ignore
15527
15528
15529@subheading The @code{-break-condition} Command
15530@findex -break-condition
15531
15532@subsubheading Synopsis
15533
15534@smallexample
15535 -break-condition @var{number} @var{expr}
15536@end smallexample
15537
15538Breakpoint @var{number} will stop the program only if the condition in
15539@var{expr} is true. The condition becomes part of the
15540@samp{-break-list} output (see the description of the @samp{-break-list}
15541command below).
15542
15543@subsubheading @value{GDBN} Command
15544
15545The corresponding @value{GDBN} command is @samp{condition}.
15546
15547@subsubheading Example
15548
15549@smallexample
15550(@value{GDBP})
15551-break-condition 1 1
15552^done
15553(@value{GDBP})
15554-break-list
15555^done,BreakpointTable=@{nr_rows="1",nr_cols="6",
15556hdr=[@{width="3",alignment="-1",col_name="number",colhdr="Num"@},
15557@{width="14",alignment="-1",col_name="type",colhdr="Type"@},
15558@{width="4",alignment="-1",col_name="disp",colhdr="Disp"@},
15559@{width="3",alignment="-1",col_name="enabled",colhdr="Enb"@},
15560@{width="10",alignment="-1",col_name="addr",colhdr="Address"@},
15561@{width="40",alignment="2",col_name="what",colhdr="What"@}],
15562body=[bkpt=@{number="1",type="breakpoint",disp="keep",enabled="y",
15563addr="0x000100d0",func="main",file="hello.c",line="5",cond="1",
15564times="0",ignore="3"@}]@}
15565(@value{GDBP})
15566@end smallexample
15567
15568@subheading The @code{-break-delete} Command
15569@findex -break-delete
15570
15571@subsubheading Synopsis
15572
15573@smallexample
15574 -break-delete ( @var{breakpoint} )+
15575@end smallexample
15576
15577Delete the breakpoint(s) whose number(s) are specified in the argument
15578list. This is obviously reflected in the breakpoint list.
15579
15580@subsubheading @value{GDBN} command
15581
15582The corresponding @value{GDBN} command is @samp{delete}.
15583
15584@subsubheading Example
15585
15586@smallexample
15587(@value{GDBP})
15588-break-delete 1
15589^done
15590(@value{GDBP})
15591-break-list
15592^done,BreakpointTable=@{nr_rows="0",nr_cols="6",
15593hdr=[@{width="3",alignment="-1",col_name="number",colhdr="Num"@},
15594@{width="14",alignment="-1",col_name="type",colhdr="Type"@},
15595@{width="4",alignment="-1",col_name="disp",colhdr="Disp"@},
15596@{width="3",alignment="-1",col_name="enabled",colhdr="Enb"@},
15597@{width="10",alignment="-1",col_name="addr",colhdr="Address"@},
15598@{width="40",alignment="2",col_name="what",colhdr="What"@}],
15599body=[]@}
15600(@value{GDBP})
15601@end smallexample
15602
15603@subheading The @code{-break-disable} Command
15604@findex -break-disable
15605
15606@subsubheading Synopsis
15607
15608@smallexample
15609 -break-disable ( @var{breakpoint} )+
15610@end smallexample
15611
15612Disable the named @var{breakpoint}(s). The field @samp{enabled} in the
15613break list is now set to @samp{n} for the named @var{breakpoint}(s).
15614
15615@subsubheading @value{GDBN} Command
15616
15617The corresponding @value{GDBN} command is @samp{disable}.
15618
15619@subsubheading Example
15620
15621@smallexample
15622(@value{GDBP})
15623-break-disable 2
15624^done
15625(@value{GDBP})
15626-break-list
15627^done,BreakpointTable=@{nr_rows="1",nr_cols="6",
15628hdr=[@{width="3",alignment="-1",col_name="number",colhdr="Num"@},
15629@{width="14",alignment="-1",col_name="type",colhdr="Type"@},
15630@{width="4",alignment="-1",col_name="disp",colhdr="Disp"@},
15631@{width="3",alignment="-1",col_name="enabled",colhdr="Enb"@},
15632@{width="10",alignment="-1",col_name="addr",colhdr="Address"@},
15633@{width="40",alignment="2",col_name="what",colhdr="What"@}],
15634body=[bkpt=@{number="2",type="breakpoint",disp="keep",enabled="n",
15635addr="0x000100d0",func="main",file="hello.c",line="5",times="0"@}]@}
15636(@value{GDBP})
15637@end smallexample
15638
15639@subheading The @code{-break-enable} Command
15640@findex -break-enable
15641
15642@subsubheading Synopsis
15643
15644@smallexample
15645 -break-enable ( @var{breakpoint} )+
15646@end smallexample
15647
15648Enable (previously disabled) @var{breakpoint}(s).
15649
15650@subsubheading @value{GDBN} Command
15651
15652The corresponding @value{GDBN} command is @samp{enable}.
15653
15654@subsubheading Example
15655
15656@smallexample
15657(@value{GDBP})
15658-break-enable 2
15659^done
15660(@value{GDBP})
15661-break-list
15662^done,BreakpointTable=@{nr_rows="1",nr_cols="6",
15663hdr=[@{width="3",alignment="-1",col_name="number",colhdr="Num"@},
15664@{width="14",alignment="-1",col_name="type",colhdr="Type"@},
15665@{width="4",alignment="-1",col_name="disp",colhdr="Disp"@},
15666@{width="3",alignment="-1",col_name="enabled",colhdr="Enb"@},
15667@{width="10",alignment="-1",col_name="addr",colhdr="Address"@},
15668@{width="40",alignment="2",col_name="what",colhdr="What"@}],
15669body=[bkpt=@{number="2",type="breakpoint",disp="keep",enabled="y",
15670addr="0x000100d0",func="main",file="hello.c",line="5",times="0"@}]@}
15671(@value{GDBP})
15672@end smallexample
15673
15674@subheading The @code{-break-info} Command
15675@findex -break-info
15676
15677@subsubheading Synopsis
15678
15679@smallexample
15680 -break-info @var{breakpoint}
15681@end smallexample
15682
15683@c REDUNDANT???
15684Get information about a single breakpoint.
15685
15686@subsubheading @value{GDBN} command
15687
15688The corresponding @value{GDBN} command is @samp{info break @var{breakpoint}}.
15689
15690@subsubheading Example
15691N.A.
15692
15693@subheading The @code{-break-insert} Command
15694@findex -break-insert
15695
15696@subsubheading Synopsis
15697
15698@smallexample
15699 -break-insert [ -t ] [ -h ] [ -r ]
15700 [ -c @var{condition} ] [ -i @var{ignore-count} ]
15701 [ -p @var{thread} ] [ @var{line} | @var{addr} ]
15702@end smallexample
15703
15704@noindent
15705If specified, @var{line}, can be one of:
15706
15707@itemize @bullet
15708@item function
15709@c @item +offset
15710@c @item -offset
15711@c @item linenum
15712@item filename:linenum
15713@item filename:function
15714@item *address
15715@end itemize
15716
15717The possible optional parameters of this command are:
15718
15719@table @samp
15720@item -t
15721Insert a tempoary breakpoint.
15722@item -h
15723Insert a hardware breakpoint.
15724@item -c @var{condition}
15725Make the breakpoint conditional on @var{condition}.
15726@item -i @var{ignore-count}
15727Initialize the @var{ignore-count}.
15728@item -r
15729Insert a regular breakpoint in all the functions whose names match the
15730given regular expression. Other flags are not applicable to regular
15731expresson.
15732@end table
15733
15734@subsubheading Result
15735
15736The result is in the form:
15737
15738@smallexample
15739 ^done,bkptno="@var{number}",func="@var{funcname}",
15740 file="@var{filename}",line="@var{lineno}"
15741@end smallexample
15742
15743@noindent
15744where @var{number} is the @value{GDBN} number for this breakpoint, @var{funcname}
15745is the name of the function where the breakpoint was inserted,
15746@var{filename} is the name of the source file which contains this
15747function, and @var{lineno} is the source line number within that file.
15748
15749Note: this format is open to change.
15750@c An out-of-band breakpoint instead of part of the result?
15751
15752@subsubheading @value{GDBN} Command
15753
15754The corresponding @value{GDBN} commands are @samp{break}, @samp{tbreak},
15755@samp{hbreak}, @samp{thbreak}, and @samp{rbreak}.
15756
15757@subsubheading Example
15758
15759@smallexample
15760(@value{GDBP})
15761-break-insert main
15762^done,bkpt=@{number="1",addr="0x0001072c",file="recursive2.c",line="4"@}
15763(@value{GDBP})
15764-break-insert -t foo
15765^done,bkpt=@{number="2",addr="0x00010774",file="recursive2.c",line="11"@}
15766(@value{GDBP})
15767-break-list
15768^done,BreakpointTable=@{nr_rows="2",nr_cols="6",
15769hdr=[@{width="3",alignment="-1",col_name="number",colhdr="Num"@},
15770@{width="14",alignment="-1",col_name="type",colhdr="Type"@},
15771@{width="4",alignment="-1",col_name="disp",colhdr="Disp"@},
15772@{width="3",alignment="-1",col_name="enabled",colhdr="Enb"@},
15773@{width="10",alignment="-1",col_name="addr",colhdr="Address"@},
15774@{width="40",alignment="2",col_name="what",colhdr="What"@}],
15775body=[bkpt=@{number="1",type="breakpoint",disp="keep",enabled="y",
15776addr="0x0001072c", func="main",file="recursive2.c",line="4",times="0"@},
15777bkpt=@{number="2",type="breakpoint",disp="del",enabled="y",
15778addr="0x00010774",func="foo",file="recursive2.c",line="11",times="0"@}]@}
15779(@value{GDBP})
15780-break-insert -r foo.*
15781~int foo(int, int);
15782^done,bkpt=@{number="3",addr="0x00010774",file="recursive2.c",line="11"@}
15783(@value{GDBP})
15784@end smallexample
15785
15786@subheading The @code{-break-list} Command
15787@findex -break-list
15788
15789@subsubheading Synopsis
15790
15791@smallexample
15792 -break-list
15793@end smallexample
15794
15795Displays the list of inserted breakpoints, showing the following fields:
15796
15797@table @samp
15798@item Number
15799number of the breakpoint
15800@item Type
15801type of the breakpoint: @samp{breakpoint} or @samp{watchpoint}
15802@item Disposition
15803should the breakpoint be deleted or disabled when it is hit: @samp{keep}
15804or @samp{nokeep}
15805@item Enabled
15806is the breakpoint enabled or no: @samp{y} or @samp{n}
15807@item Address
15808memory location at which the breakpoint is set
15809@item What
15810logical location of the breakpoint, expressed by function name, file
15811name, line number
15812@item Times
15813number of times the breakpoint has been hit
15814@end table
15815
15816If there are no breakpoints or watchpoints, the @code{BreakpointTable}
15817@code{body} field is an empty list.
15818
15819@subsubheading @value{GDBN} Command
15820
15821The corresponding @value{GDBN} command is @samp{info break}.
15822
15823@subsubheading Example
15824
15825@smallexample
15826(@value{GDBP})
15827-break-list
15828^done,BreakpointTable=@{nr_rows="2",nr_cols="6",
15829hdr=[@{width="3",alignment="-1",col_name="number",colhdr="Num"@},
15830@{width="14",alignment="-1",col_name="type",colhdr="Type"@},
15831@{width="4",alignment="-1",col_name="disp",colhdr="Disp"@},
15832@{width="3",alignment="-1",col_name="enabled",colhdr="Enb"@},
15833@{width="10",alignment="-1",col_name="addr",colhdr="Address"@},
15834@{width="40",alignment="2",col_name="what",colhdr="What"@}],
15835body=[bkpt=@{number="1",type="breakpoint",disp="keep",enabled="y",
15836addr="0x000100d0",func="main",file="hello.c",line="5",times="0"@},
15837bkpt=@{number="2",type="breakpoint",disp="keep",enabled="y",
15838addr="0x00010114",func="foo",file="hello.c",line="13",times="0"@}]@}
15839(@value{GDBP})
15840@end smallexample
15841
15842Here's an example of the result when there are no breakpoints:
15843
15844@smallexample
15845(@value{GDBP})
15846-break-list
15847^done,BreakpointTable=@{nr_rows="0",nr_cols="6",
15848hdr=[@{width="3",alignment="-1",col_name="number",colhdr="Num"@},
15849@{width="14",alignment="-1",col_name="type",colhdr="Type"@},
15850@{width="4",alignment="-1",col_name="disp",colhdr="Disp"@},
15851@{width="3",alignment="-1",col_name="enabled",colhdr="Enb"@},
15852@{width="10",alignment="-1",col_name="addr",colhdr="Address"@},
15853@{width="40",alignment="2",col_name="what",colhdr="What"@}],
15854body=[]@}
15855(@value{GDBP})
15856@end smallexample
15857
15858@subheading The @code{-break-watch} Command
15859@findex -break-watch
15860
15861@subsubheading Synopsis
15862
15863@smallexample
15864 -break-watch [ -a | -r ]
15865@end smallexample
15866
15867Create a watchpoint. With the @samp{-a} option it will create an
15868@dfn{access} watchpoint, i.e. a watchpoint that triggers either on a
15869read from or on a write to the memory location. With the @samp{-r}
15870option, the watchpoint created is a @dfn{read} watchpoint, i.e. it will
15871trigger only when the memory location is accessed for reading. Without
15872either of the options, the watchpoint created is a regular watchpoint,
15873i.e. it will trigger when the memory location is accessed for writing.
15874@xref{Set Watchpoints, , Setting watchpoints}.
15875
15876Note that @samp{-break-list} will report a single list of watchpoints and
15877breakpoints inserted.
15878
15879@subsubheading @value{GDBN} Command
15880
15881The corresponding @value{GDBN} commands are @samp{watch}, @samp{awatch}, and
15882@samp{rwatch}.
15883
15884@subsubheading Example
15885
15886Setting a watchpoint on a variable in the @code{main} function:
15887
15888@smallexample
15889(@value{GDBP})
15890-break-watch x
15891^done,wpt=@{number="2",exp="x"@}
15892(@value{GDBP})
15893-exec-continue
15894^running
15895^done,reason="watchpoint-trigger",wpt=@{number="2",exp="x"@},
15896value=@{old="-268439212",new="55"@},
15897frame=@{func="main",args=[],file="recursive2.c",line="5"@}
15898(@value{GDBP})
15899@end smallexample
15900
15901Setting a watchpoint on a variable local to a function. @value{GDBN} will stop
15902the program execution twice: first for the variable changing value, then
15903for the watchpoint going out of scope.
15904
15905@smallexample
15906(@value{GDBP})
15907-break-watch C
15908^done,wpt=@{number="5",exp="C"@}
15909(@value{GDBP})
15910-exec-continue
15911^running
15912^done,reason="watchpoint-trigger",
15913wpt=@{number="5",exp="C"@},value=@{old="-276895068",new="3"@},
15914frame=@{func="callee4",args=[],
15915file="../../../devo/gdb/testsuite/gdb.mi/basics.c",line="13"@}
15916(@value{GDBP})
15917-exec-continue
15918^running
15919^done,reason="watchpoint-scope",wpnum="5",
15920frame=@{func="callee3",args=[@{name="strarg",
15921value="0x11940 \"A string argument.\""@}],
15922file="../../../devo/gdb/testsuite/gdb.mi/basics.c",line="18"@}
15923(@value{GDBP})
15924@end smallexample
15925
15926Listing breakpoints and watchpoints, at different points in the program
15927execution. Note that once the watchpoint goes out of scope, it is
15928deleted.
15929
15930@smallexample
15931(@value{GDBP})
15932-break-watch C
15933^done,wpt=@{number="2",exp="C"@}
15934(@value{GDBP})
15935-break-list
15936^done,BreakpointTable=@{nr_rows="2",nr_cols="6",
15937hdr=[@{width="3",alignment="-1",col_name="number",colhdr="Num"@},
15938@{width="14",alignment="-1",col_name="type",colhdr="Type"@},
15939@{width="4",alignment="-1",col_name="disp",colhdr="Disp"@},
15940@{width="3",alignment="-1",col_name="enabled",colhdr="Enb"@},
15941@{width="10",alignment="-1",col_name="addr",colhdr="Address"@},
15942@{width="40",alignment="2",col_name="what",colhdr="What"@}],
15943body=[bkpt=@{number="1",type="breakpoint",disp="keep",enabled="y",
15944addr="0x00010734",func="callee4",
15945file="../../../devo/gdb/testsuite/gdb.mi/basics.c",line="8",times="1"@},
15946bkpt=@{number="2",type="watchpoint",disp="keep",
15947enabled="y",addr="",what="C",times="0"@}]@}
15948(@value{GDBP})
15949-exec-continue
15950^running
15951^done,reason="watchpoint-trigger",wpt=@{number="2",exp="C"@},
15952value=@{old="-276895068",new="3"@},
15953frame=@{func="callee4",args=[],
15954file="../../../devo/gdb/testsuite/gdb.mi/basics.c",line="13"@}
15955(@value{GDBP})
15956-break-list
15957^done,BreakpointTable=@{nr_rows="2",nr_cols="6",
15958hdr=[@{width="3",alignment="-1",col_name="number",colhdr="Num"@},
15959@{width="14",alignment="-1",col_name="type",colhdr="Type"@},
15960@{width="4",alignment="-1",col_name="disp",colhdr="Disp"@},
15961@{width="3",alignment="-1",col_name="enabled",colhdr="Enb"@},
15962@{width="10",alignment="-1",col_name="addr",colhdr="Address"@},
15963@{width="40",alignment="2",col_name="what",colhdr="What"@}],
15964body=[bkpt=@{number="1",type="breakpoint",disp="keep",enabled="y",
15965addr="0x00010734",func="callee4",
15966file="../../../devo/gdb/testsuite/gdb.mi/basics.c",line="8",times="1"@},
15967bkpt=@{number="2",type="watchpoint",disp="keep",
15968enabled="y",addr="",what="C",times="-5"@}]@}
15969(@value{GDBP})
15970-exec-continue
15971^running
15972^done,reason="watchpoint-scope",wpnum="2",
15973frame=@{func="callee3",args=[@{name="strarg",
15974value="0x11940 \"A string argument.\""@}],
15975file="../../../devo/gdb/testsuite/gdb.mi/basics.c",line="18"@}
15976(@value{GDBP})
15977-break-list
15978^done,BreakpointTable=@{nr_rows="1",nr_cols="6",
15979hdr=[@{width="3",alignment="-1",col_name="number",colhdr="Num"@},
15980@{width="14",alignment="-1",col_name="type",colhdr="Type"@},
15981@{width="4",alignment="-1",col_name="disp",colhdr="Disp"@},
15982@{width="3",alignment="-1",col_name="enabled",colhdr="Enb"@},
15983@{width="10",alignment="-1",col_name="addr",colhdr="Address"@},
15984@{width="40",alignment="2",col_name="what",colhdr="What"@}],
15985body=[bkpt=@{number="1",type="breakpoint",disp="keep",enabled="y",
15986addr="0x00010734",func="callee4",
15987file="../../../devo/gdb/testsuite/gdb.mi/basics.c",line="8",times="1"@}]@}
15988(@value{GDBP})
15989@end smallexample
15990
15991@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
15992@node GDB/MI Data Manipulation
15993@section @sc{gdb/mi} Data Manipulation
15994
15995@cindex data manipulation, in @sc{gdb/mi}
15996@cindex @sc{gdb/mi}, data manipulation
15997This section describes the @sc{gdb/mi} commands that manipulate data:
15998examine memory and registers, evaluate expressions, etc.
15999
16000@c REMOVED FROM THE INTERFACE.
16001@c @subheading -data-assign
16002@c Change the value of a program variable. Plenty of side effects.
16003@c @subsubheading GDB command
16004@c set variable
16005@c @subsubheading Example
16006@c N.A.
16007
16008@subheading The @code{-data-disassemble} Command
16009@findex -data-disassemble
16010
16011@subsubheading Synopsis
16012
16013@smallexample
16014 -data-disassemble
16015 [ -s @var{start-addr} -e @var{end-addr} ]
16016 | [ -f @var{filename} -l @var{linenum} [ -n @var{lines} ] ]
16017 -- @var{mode}
16018@end smallexample
16019
16020@noindent
16021Where:
16022
16023@table @samp
16024@item @var{start-addr}
16025is the beginning address (or @code{$pc})
16026@item @var{end-addr}
16027is the end address
16028@item @var{filename}
16029is the name of the file to disassemble
16030@item @var{linenum}
16031is the line number to disassemble around
16032@item @var{lines}
16033is the the number of disassembly lines to be produced. If it is -1,
16034the whole function will be disassembled, in case no @var{end-addr} is
16035specified. If @var{end-addr} is specified as a non-zero value, and
16036@var{lines} is lower than the number of disassembly lines between
16037@var{start-addr} and @var{end-addr}, only @var{lines} lines are
16038displayed; if @var{lines} is higher than the number of lines between
16039@var{start-addr} and @var{end-addr}, only the lines up to @var{end-addr}
16040are displayed.
16041@item @var{mode}
16042is either 0 (meaning only disassembly) or 1 (meaning mixed source and
16043disassembly).
16044@end table
16045
16046@subsubheading Result
16047
16048The output for each instruction is composed of four fields:
16049
16050@itemize @bullet
16051@item Address
16052@item Func-name
16053@item Offset
16054@item Instruction
16055@end itemize
16056
16057Note that whatever included in the instruction field, is not manipulated
16058directely by @sc{gdb/mi}, i.e. it is not possible to adjust its format.
16059
16060@subsubheading @value{GDBN} Command
16061
16062There's no direct mapping from this command to the CLI.
16063
16064@subsubheading Example
16065
16066Disassemble from the current value of @code{$pc} to @code{$pc + 20}:
16067
16068@smallexample
16069(@value{GDBP})
16070-data-disassemble -s $pc -e "$pc + 20" -- 0
16071^done,
16072asm_insns=[
16073@{address="0x000107c0",func-name="main",offset="4",
16074inst="mov 2, %o0"@},
16075@{address="0x000107c4",func-name="main",offset="8",
16076inst="sethi %hi(0x11800), %o2"@},
16077@{address="0x000107c8",func-name="main",offset="12",
16078inst="or %o2, 0x140, %o1\t! 0x11940 <_lib_version+8>"@},
16079@{address="0x000107cc",func-name="main",offset="16",
16080inst="sethi %hi(0x11800), %o2"@},
16081@{address="0x000107d0",func-name="main",offset="20",
16082inst="or %o2, 0x168, %o4\t! 0x11968 <_lib_version+48>"@}]
16083(@value{GDBP})
16084@end smallexample
16085
16086Disassemble the whole @code{main} function. Line 32 is part of
16087@code{main}.
16088
16089@smallexample
16090-data-disassemble -f basics.c -l 32 -- 0
16091^done,asm_insns=[
16092@{address="0x000107bc",func-name="main",offset="0",
16093inst="save %sp, -112, %sp"@},
16094@{address="0x000107c0",func-name="main",offset="4",
16095inst="mov 2, %o0"@},
16096@{address="0x000107c4",func-name="main",offset="8",
16097inst="sethi %hi(0x11800), %o2"@},
16098[@dots{}]
16099@{address="0x0001081c",func-name="main",offset="96",inst="ret "@},
16100@{address="0x00010820",func-name="main",offset="100",inst="restore "@}]
16101(@value{GDBP})
16102@end smallexample
16103
16104Disassemble 3 instructions from the start of @code{main}:
16105
16106@smallexample
16107(@value{GDBP})
16108-data-disassemble -f basics.c -l 32 -n 3 -- 0
16109^done,asm_insns=[
16110@{address="0x000107bc",func-name="main",offset="0",
16111inst="save %sp, -112, %sp"@},
16112@{address="0x000107c0",func-name="main",offset="4",
16113inst="mov 2, %o0"@},
16114@{address="0x000107c4",func-name="main",offset="8",
16115inst="sethi %hi(0x11800), %o2"@}]
16116(@value{GDBP})
16117@end smallexample
16118
16119Disassemble 3 instructions from the start of @code{main} in mixed mode:
16120
16121@smallexample
16122(@value{GDBP})
16123-data-disassemble -f basics.c -l 32 -n 3 -- 1
16124^done,asm_insns=[
16125src_and_asm_line=@{line="31",
16126file="/kwikemart/marge/ezannoni/flathead-dev/devo/gdb/ \
16127 testsuite/gdb.mi/basics.c",line_asm_insn=[
16128@{address="0x000107bc",func-name="main",offset="0",
16129inst="save %sp, -112, %sp"@}]@},
16130src_and_asm_line=@{line="32",
16131file="/kwikemart/marge/ezannoni/flathead-dev/devo/gdb/ \
16132 testsuite/gdb.mi/basics.c",line_asm_insn=[
16133@{address="0x000107c0",func-name="main",offset="4",
16134inst="mov 2, %o0"@},
16135@{address="0x000107c4",func-name="main",offset="8",
16136inst="sethi %hi(0x11800), %o2"@}]@}]
16137(@value{GDBP})
16138@end smallexample
16139
16140
16141@subheading The @code{-data-evaluate-expression} Command
16142@findex -data-evaluate-expression
16143
16144@subsubheading Synopsis
16145
16146@smallexample
16147 -data-evaluate-expression @var{expr}
16148@end smallexample
16149
16150Evaluate @var{expr} as an expression. The expression could contain an
16151inferior function call. The function call will execute synchronously.
16152If the expression contains spaces, it must be enclosed in double quotes.
16153
16154@subsubheading @value{GDBN} Command
16155
16156The corresponding @value{GDBN} commands are @samp{print}, @samp{output}, and
16157@samp{call}. In @code{gdbtk} only, there's a corresponding
16158@samp{gdb_eval} command.
16159
16160@subsubheading Example
16161
16162In the following example, the numbers that precede the commands are the
16163@dfn{tokens} described in @ref{GDB/MI Command Syntax, ,@sc{gdb/mi}
16164Command Syntax}. Notice how @sc{gdb/mi} returns the same tokens in its
16165output.
16166
16167@smallexample
16168211-data-evaluate-expression A
16169211^done,value="1"
16170(@value{GDBP})
16171311-data-evaluate-expression &A
16172311^done,value="0xefffeb7c"
16173(@value{GDBP})
16174411-data-evaluate-expression A+3
16175411^done,value="4"
16176(@value{GDBP})
16177511-data-evaluate-expression "A + 3"
16178511^done,value="4"
16179(@value{GDBP})
16180@end smallexample
16181
16182
16183@subheading The @code{-data-list-changed-registers} Command
16184@findex -data-list-changed-registers
16185
16186@subsubheading Synopsis
16187
16188@smallexample
16189 -data-list-changed-registers
16190@end smallexample
16191
16192Display a list of the registers that have changed.
16193
16194@subsubheading @value{GDBN} Command
16195
16196@value{GDBN} doesn't have a direct analog for this command; @code{gdbtk}
16197has the corresponding command @samp{gdb_changed_register_list}.
16198
16199@subsubheading Example
16200
16201On a PPC MBX board:
16202
16203@smallexample
16204(@value{GDBP})
16205-exec-continue
16206^running
16207
16208(@value{GDBP})
16209*stopped,reason="breakpoint-hit",bkptno="1",frame=@{func="main",
16210args=[],file="try.c",line="5"@}
16211(@value{GDBP})
16212-data-list-changed-registers
16213^done,changed-registers=["0","1","2","4","5","6","7","8","9",
16214"10","11","13","14","15","16","17","18","19","20","21","22","23",
16215"24","25","26","27","28","30","31","64","65","66","67","69"]
16216(@value{GDBP})
16217@end smallexample
16218
16219
16220@subheading The @code{-data-list-register-names} Command
16221@findex -data-list-register-names
16222
16223@subsubheading Synopsis
16224
16225@smallexample
16226 -data-list-register-names [ ( @var{regno} )+ ]
16227@end smallexample
16228
16229Show a list of register names for the current target. If no arguments
16230are given, it shows a list of the names of all the registers. If
16231integer numbers are given as arguments, it will print a list of the
16232names of the registers corresponding to the arguments. To ensure
16233consistency between a register name and its number, the output list may
16234include empty register names.
16235
16236@subsubheading @value{GDBN} Command
16237
16238@value{GDBN} does not have a command which corresponds to
16239@samp{-data-list-register-names}. In @code{gdbtk} there is a
16240corresponding command @samp{gdb_regnames}.
16241
16242@subsubheading Example
16243
16244For the PPC MBX board:
16245@smallexample
16246(@value{GDBP})
16247-data-list-register-names
16248^done,register-names=["r0","r1","r2","r3","r4","r5","r6","r7",
16249"r8","r9","r10","r11","r12","r13","r14","r15","r16","r17","r18",
16250"r19","r20","r21","r22","r23","r24","r25","r26","r27","r28","r29",
16251"r30","r31","f0","f1","f2","f3","f4","f5","f6","f7","f8","f9",
16252"f10","f11","f12","f13","f14","f15","f16","f17","f18","f19","f20",
16253"f21","f22","f23","f24","f25","f26","f27","f28","f29","f30","f31",
16254"", "pc","ps","cr","lr","ctr","xer"]
16255(@value{GDBP})
16256-data-list-register-names 1 2 3
16257^done,register-names=["r1","r2","r3"]
16258(@value{GDBP})
16259@end smallexample
16260
16261@subheading The @code{-data-list-register-values} Command
16262@findex -data-list-register-values
16263
16264@subsubheading Synopsis
16265
16266@smallexample
16267 -data-list-register-values @var{fmt} [ ( @var{regno} )*]
16268@end smallexample
16269
16270Display the registers' contents. @var{fmt} is the format according to
16271which the registers' contents are to be returned, followed by an optional
16272list of numbers specifying the registers to display. A missing list of
16273numbers indicates that the contents of all the registers must be returned.
16274
16275Allowed formats for @var{fmt} are:
16276
16277@table @code
16278@item x
16279Hexadecimal
16280@item o
16281Octal
16282@item t
16283Binary
16284@item d
16285Decimal
16286@item r
16287Raw
16288@item N
16289Natural
16290@end table
16291
16292@subsubheading @value{GDBN} Command
16293
16294The corresponding @value{GDBN} commands are @samp{info reg}, @samp{info
16295all-reg}, and (in @code{gdbtk}) @samp{gdb_fetch_registers}.
16296
16297@subsubheading Example
16298
16299For a PPC MBX board (note: line breaks are for readability only, they
16300don't appear in the actual output):
16301
16302@smallexample
16303(@value{GDBP})
16304-data-list-register-values r 64 65
16305^done,register-values=[@{number="64",value="0xfe00a300"@},
16306@{number="65",value="0x00029002"@}]
16307(@value{GDBP})
16308-data-list-register-values x
16309^done,register-values=[@{number="0",value="0xfe0043c8"@},
16310@{number="1",value="0x3fff88"@},@{number="2",value="0xfffffffe"@},
16311@{number="3",value="0x0"@},@{number="4",value="0xa"@},
16312@{number="5",value="0x3fff68"@},@{number="6",value="0x3fff58"@},
16313@{number="7",value="0xfe011e98"@},@{number="8",value="0x2"@},
16314@{number="9",value="0xfa202820"@},@{number="10",value="0xfa202808"@},
16315@{number="11",value="0x1"@},@{number="12",value="0x0"@},
16316@{number="13",value="0x4544"@},@{number="14",value="0xffdfffff"@},
16317@{number="15",value="0xffffffff"@},@{number="16",value="0xfffffeff"@},
16318@{number="17",value="0xefffffed"@},@{number="18",value="0xfffffffe"@},
16319@{number="19",value="0xffffffff"@},@{number="20",value="0xffffffff"@},
16320@{number="21",value="0xffffffff"@},@{number="22",value="0xfffffff7"@},
16321@{number="23",value="0xffffffff"@},@{number="24",value="0xffffffff"@},
16322@{number="25",value="0xffffffff"@},@{number="26",value="0xfffffffb"@},
16323@{number="27",value="0xffffffff"@},@{number="28",value="0xf7bfffff"@},
16324@{number="29",value="0x0"@},@{number="30",value="0xfe010000"@},
16325@{number="31",value="0x0"@},@{number="32",value="0x0"@},
16326@{number="33",value="0x0"@},@{number="34",value="0x0"@},
16327@{number="35",value="0x0"@},@{number="36",value="0x0"@},
16328@{number="37",value="0x0"@},@{number="38",value="0x0"@},
16329@{number="39",value="0x0"@},@{number="40",value="0x0"@},
16330@{number="41",value="0x0"@},@{number="42",value="0x0"@},
16331@{number="43",value="0x0"@},@{number="44",value="0x0"@},
16332@{number="45",value="0x0"@},@{number="46",value="0x0"@},
16333@{number="47",value="0x0"@},@{number="48",value="0x0"@},
16334@{number="49",value="0x0"@},@{number="50",value="0x0"@},
16335@{number="51",value="0x0"@},@{number="52",value="0x0"@},
16336@{number="53",value="0x0"@},@{number="54",value="0x0"@},
16337@{number="55",value="0x0"@},@{number="56",value="0x0"@},
16338@{number="57",value="0x0"@},@{number="58",value="0x0"@},
16339@{number="59",value="0x0"@},@{number="60",value="0x0"@},
16340@{number="61",value="0x0"@},@{number="62",value="0x0"@},
16341@{number="63",value="0x0"@},@{number="64",value="0xfe00a300"@},
16342@{number="65",value="0x29002"@},@{number="66",value="0x202f04b5"@},
16343@{number="67",value="0xfe0043b0"@},@{number="68",value="0xfe00b3e4"@},
16344@{number="69",value="0x20002b03"@}]
16345(@value{GDBP})
16346@end smallexample
16347
16348
16349@subheading The @code{-data-read-memory} Command
16350@findex -data-read-memory
16351
16352@subsubheading Synopsis
16353
16354@smallexample
16355 -data-read-memory [ -o @var{byte-offset} ]
16356 @var{address} @var{word-format} @var{word-size}
16357 @var{nr-rows} @var{nr-cols} [ @var{aschar} ]
16358@end smallexample
16359
16360@noindent
16361where:
16362
16363@table @samp
16364@item @var{address}
16365An expression specifying the address of the first memory word to be
16366read. Complex expressions containing embedded white space should be
16367quoted using the C convention.
16368
16369@item @var{word-format}
16370The format to be used to print the memory words. The notation is the
16371same as for @value{GDBN}'s @code{print} command (@pxref{Output Formats,
16372,Output formats}).
16373
16374@item @var{word-size}
16375The size of each memory word in bytes.
16376
16377@item @var{nr-rows}
16378The number of rows in the output table.
16379
16380@item @var{nr-cols}
16381The number of columns in the output table.
16382
16383@item @var{aschar}
16384If present, indicates that each row should include an @sc{ascii} dump. The
16385value of @var{aschar} is used as a padding character when a byte is not a
16386member of the printable @sc{ascii} character set (printable @sc{ascii}
16387characters are those whose code is between 32 and 126, inclusively).
16388
16389@item @var{byte-offset}
16390An offset to add to the @var{address} before fetching memory.
16391@end table
16392
16393This command displays memory contents as a table of @var{nr-rows} by
16394@var{nr-cols} words, each word being @var{word-size} bytes. In total,
16395@code{@var{nr-rows} * @var{nr-cols} * @var{word-size}} bytes are read
16396(returned as @samp{total-bytes}). Should less than the requested number
16397of bytes be returned by the target, the missing words are identified
16398using @samp{N/A}. The number of bytes read from the target is returned
16399in @samp{nr-bytes} and the starting address used to read memory in
16400@samp{addr}.
16401
16402The address of the next/previous row or page is available in
16403@samp{next-row} and @samp{prev-row}, @samp{next-page} and
16404@samp{prev-page}.
16405
16406@subsubheading @value{GDBN} Command
16407
16408The corresponding @value{GDBN} command is @samp{x}. @code{gdbtk} has
16409@samp{gdb_get_mem} memory read command.
16410
16411@subsubheading Example
16412
16413Read six bytes of memory starting at @code{bytes+6} but then offset by
16414@code{-6} bytes. Format as three rows of two columns. One byte per
16415word. Display each word in hex.
16416
16417@smallexample
16418(@value{GDBP})
164199-data-read-memory -o -6 -- bytes+6 x 1 3 2
164209^done,addr="0x00001390",nr-bytes="6",total-bytes="6",
16421next-row="0x00001396",prev-row="0x0000138e",next-page="0x00001396",
16422prev-page="0x0000138a",memory=[
16423@{addr="0x00001390",data=["0x00","0x01"]@},
16424@{addr="0x00001392",data=["0x02","0x03"]@},
16425@{addr="0x00001394",data=["0x04","0x05"]@}]
16426(@value{GDBP})
16427@end smallexample
16428
16429Read two bytes of memory starting at address @code{shorts + 64} and
16430display as a single word formatted in decimal.
16431
16432@smallexample
16433(@value{GDBP})
164345-data-read-memory shorts+64 d 2 1 1
164355^done,addr="0x00001510",nr-bytes="2",total-bytes="2",
16436next-row="0x00001512",prev-row="0x0000150e",
16437next-page="0x00001512",prev-page="0x0000150e",memory=[
16438@{addr="0x00001510",data=["128"]@}]
16439(@value{GDBP})
16440@end smallexample
16441
16442Read thirty two bytes of memory starting at @code{bytes+16} and format
16443as eight rows of four columns. Include a string encoding with @samp{x}
16444used as the non-printable character.
16445
16446@smallexample
16447(@value{GDBP})
164484-data-read-memory bytes+16 x 1 8 4 x
164494^done,addr="0x000013a0",nr-bytes="32",total-bytes="32",
16450next-row="0x000013c0",prev-row="0x0000139c",
16451next-page="0x000013c0",prev-page="0x00001380",memory=[
16452@{addr="0x000013a0",data=["0x10","0x11","0x12","0x13"],ascii="xxxx"@},
16453@{addr="0x000013a4",data=["0x14","0x15","0x16","0x17"],ascii="xxxx"@},
16454@{addr="0x000013a8",data=["0x18","0x19","0x1a","0x1b"],ascii="xxxx"@},
16455@{addr="0x000013ac",data=["0x1c","0x1d","0x1e","0x1f"],ascii="xxxx"@},
16456@{addr="0x000013b0",data=["0x20","0x21","0x22","0x23"],ascii=" !\"#"@},
16457@{addr="0x000013b4",data=["0x24","0x25","0x26","0x27"],ascii="$%&'"@},
16458@{addr="0x000013b8",data=["0x28","0x29","0x2a","0x2b"],ascii="()*+"@},
16459@{addr="0x000013bc",data=["0x2c","0x2d","0x2e","0x2f"],ascii=",-./"@}]
16460(@value{GDBP})
16461@end smallexample
16462
16463@subheading The @code{-display-delete} Command
16464@findex -display-delete
16465
16466@subsubheading Synopsis
16467
16468@smallexample
16469 -display-delete @var{number}
16470@end smallexample
16471
16472Delete the display @var{number}.
16473
16474@subsubheading @value{GDBN} Command
16475
16476The corresponding @value{GDBN} command is @samp{delete display}.
16477
16478@subsubheading Example
16479N.A.
16480
16481
16482@subheading The @code{-display-disable} Command
16483@findex -display-disable
16484
16485@subsubheading Synopsis
16486
16487@smallexample
16488 -display-disable @var{number}
16489@end smallexample
16490
16491Disable display @var{number}.
16492
16493@subsubheading @value{GDBN} Command
16494
16495The corresponding @value{GDBN} command is @samp{disable display}.
16496
16497@subsubheading Example
16498N.A.
16499
16500
16501@subheading The @code{-display-enable} Command
16502@findex -display-enable
16503
16504@subsubheading Synopsis
16505
16506@smallexample
16507 -display-enable @var{number}
16508@end smallexample
16509
16510Enable display @var{number}.
16511
16512@subsubheading @value{GDBN} Command
16513
16514The corresponding @value{GDBN} command is @samp{enable display}.
16515
16516@subsubheading Example
16517N.A.
16518
16519
16520@subheading The @code{-display-insert} Command
16521@findex -display-insert
16522
16523@subsubheading Synopsis
16524
16525@smallexample
16526 -display-insert @var{expression}
16527@end smallexample
16528
16529Display @var{expression} every time the program stops.
16530
16531@subsubheading @value{GDBN} Command
16532
16533The corresponding @value{GDBN} command is @samp{display}.
16534
16535@subsubheading Example
16536N.A.
16537
16538
16539@subheading The @code{-display-list} Command
16540@findex -display-list
16541
16542@subsubheading Synopsis
16543
16544@smallexample
16545 -display-list
16546@end smallexample
16547
16548List the displays. Do not show the current values.
16549
16550@subsubheading @value{GDBN} Command
16551
16552The corresponding @value{GDBN} command is @samp{info display}.
16553
16554@subsubheading Example
16555N.A.
16556
16557
16558@subheading The @code{-environment-cd} Command
16559@findex -environment-cd
16560
16561@subsubheading Synopsis
16562
16563@smallexample
16564 -environment-cd @var{pathdir}
16565@end smallexample
16566
16567Set @value{GDBN}'s working directory.
16568
16569@subsubheading @value{GDBN} Command
16570
16571The corresponding @value{GDBN} command is @samp{cd}.
16572
16573@subsubheading Example
16574
16575@smallexample
16576(@value{GDBP})
16577-environment-cd /kwikemart/marge/ezannoni/flathead-dev/devo/gdb
16578^done
16579(@value{GDBP})
16580@end smallexample
16581
16582
16583@subheading The @code{-environment-directory} Command
16584@findex -environment-directory
16585
16586@subsubheading Synopsis
16587
16588@smallexample
16589 -environment-directory [ -r ] [ @var{pathdir} ]+
16590@end smallexample
16591
16592Add directories @var{pathdir} to beginning of search path for source files.
16593If the @samp{-r} option is used, the search path is reset to the default
b383017d 16594search path. If directories @var{pathdir} are supplied in addition to the
922fbb7b
AC
16595@samp{-r} option, the search path is first reset and then addition
16596occurs as normal.
b383017d 16597Multiple directories may be specified, separated by blanks. Specifying
922fbb7b
AC
16598multiple directories in a single command
16599results in the directories added to the beginning of the
16600search path in the same order they were presented in the command.
16601If blanks are needed as
16602part of a directory name, double-quotes should be used around
16603the name. In the command output, the path will show up separated
b383017d 16604by the system directory-separator character. The directory-seperator
922fbb7b
AC
16605character must not be used
16606in any directory name.
16607If no directories are specified, the current search path is displayed.
16608
16609@subsubheading @value{GDBN} Command
16610
16611The corresponding @value{GDBN} command is @samp{dir}.
16612
16613@subsubheading Example
16614
16615@smallexample
16616(@value{GDBP})
16617-environment-directory /kwikemart/marge/ezannoni/flathead-dev/devo/gdb
16618^done,source-path="/kwikemart/marge/ezannoni/flathead-dev/devo/gdb:$cdir:$cwd"
16619(@value{GDBP})
16620-environment-directory ""
16621^done,source-path="/kwikemart/marge/ezannoni/flathead-dev/devo/gdb:$cdir:$cwd"
16622(@value{GDBP})
16623-environment-directory -r /home/jjohnstn/src/gdb /usr/src
16624^done,source-path="/home/jjohnstn/src/gdb:/usr/src:$cdir:$cwd"
16625(@value{GDBP})
16626-environment-directory -r
16627^done,source-path="$cdir:$cwd"
16628(@value{GDBP})
16629@end smallexample
16630
16631
16632@subheading The @code{-environment-path} Command
16633@findex -environment-path
16634
16635@subsubheading Synopsis
16636
16637@smallexample
16638 -environment-path [ -r ] [ @var{pathdir} ]+
16639@end smallexample
16640
16641Add directories @var{pathdir} to beginning of search path for object files.
16642If the @samp{-r} option is used, the search path is reset to the original
b383017d
RM
16643search path that existed at gdb start-up. If directories @var{pathdir} are
16644supplied in addition to the
922fbb7b
AC
16645@samp{-r} option, the search path is first reset and then addition
16646occurs as normal.
b383017d 16647Multiple directories may be specified, separated by blanks. Specifying
922fbb7b
AC
16648multiple directories in a single command
16649results in the directories added to the beginning of the
16650search path in the same order they were presented in the command.
16651If blanks are needed as
16652part of a directory name, double-quotes should be used around
16653the name. In the command output, the path will show up separated
b383017d 16654by the system directory-separator character. The directory-seperator
922fbb7b
AC
16655character must not be used
16656in any directory name.
16657If no directories are specified, the current path is displayed.
16658
16659
16660@subsubheading @value{GDBN} Command
16661
16662The corresponding @value{GDBN} command is @samp{path}.
16663
16664@subsubheading Example
16665
16666@smallexample
16667(@value{GDBP})
b383017d 16668-environment-path
922fbb7b
AC
16669^done,path="/usr/bin"
16670(@value{GDBP})
16671-environment-path /kwikemart/marge/ezannoni/flathead-dev/ppc-eabi/gdb /bin
16672^done,path="/kwikemart/marge/ezannoni/flathead-dev/ppc-eabi/gdb:/bin:/usr/bin"
16673(@value{GDBP})
16674-environment-path -r /usr/local/bin
16675^done,path="/usr/local/bin:/usr/bin"
16676(@value{GDBP})
16677@end smallexample
16678
16679
16680@subheading The @code{-environment-pwd} Command
16681@findex -environment-pwd
16682
16683@subsubheading Synopsis
16684
16685@smallexample
16686 -environment-pwd
16687@end smallexample
16688
16689Show the current working directory.
16690
16691@subsubheading @value{GDBN} command
16692
16693The corresponding @value{GDBN} command is @samp{pwd}.
16694
16695@subsubheading Example
16696
16697@smallexample
16698(@value{GDBP})
16699-environment-pwd
16700^done,cwd="/kwikemart/marge/ezannoni/flathead-dev/devo/gdb"
16701(@value{GDBP})
16702@end smallexample
16703
16704@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
16705@node GDB/MI Program Control
16706@section @sc{gdb/mi} Program control
16707
16708@subsubheading Program termination
16709
16710As a result of execution, the inferior program can run to completion, if
16711it doesn't encounter any breakpoints. In this case the output will
16712include an exit code, if the program has exited exceptionally.
16713
16714@subsubheading Examples
16715
16716@noindent
16717Program exited normally:
16718
16719@smallexample
16720(@value{GDBP})
16721-exec-run
16722^running
16723(@value{GDBP})
16724x = 55
16725*stopped,reason="exited-normally"
16726(@value{GDBP})
16727@end smallexample
16728
16729@noindent
16730Program exited exceptionally:
16731
16732@smallexample
16733(@value{GDBP})
16734-exec-run
16735^running
16736(@value{GDBP})
16737x = 55
16738*stopped,reason="exited",exit-code="01"
16739(@value{GDBP})
16740@end smallexample
16741
16742Another way the program can terminate is if it receives a signal such as
16743@code{SIGINT}. In this case, @sc{gdb/mi} displays this:
16744
16745@smallexample
16746(@value{GDBP})
16747*stopped,reason="exited-signalled",signal-name="SIGINT",
16748signal-meaning="Interrupt"
16749@end smallexample
16750
16751
16752@subheading The @code{-exec-abort} Command
16753@findex -exec-abort
16754
16755@subsubheading Synopsis
16756
16757@smallexample
16758 -exec-abort
16759@end smallexample
16760
16761Kill the inferior running program.
16762
16763@subsubheading @value{GDBN} Command
16764
16765The corresponding @value{GDBN} command is @samp{kill}.
16766
16767@subsubheading Example
16768N.A.
16769
16770
16771@subheading The @code{-exec-arguments} Command
16772@findex -exec-arguments
16773
16774@subsubheading Synopsis
16775
16776@smallexample
16777 -exec-arguments @var{args}
16778@end smallexample
16779
16780Set the inferior program arguments, to be used in the next
16781@samp{-exec-run}.
16782
16783@subsubheading @value{GDBN} Command
16784
16785The corresponding @value{GDBN} command is @samp{set args}.
16786
16787@subsubheading Example
16788
16789@c FIXME!
16790Don't have one around.
16791
16792
16793@subheading The @code{-exec-continue} Command
16794@findex -exec-continue
16795
16796@subsubheading Synopsis
16797
16798@smallexample
16799 -exec-continue
16800@end smallexample
16801
16802Asynchronous command. Resumes the execution of the inferior program
16803until a breakpoint is encountered, or until the inferior exits.
16804
16805@subsubheading @value{GDBN} Command
16806
16807The corresponding @value{GDBN} corresponding is @samp{continue}.
16808
16809@subsubheading Example
16810
16811@smallexample
16812-exec-continue
16813^running
16814(@value{GDBP})
16815@@Hello world
16816*stopped,reason="breakpoint-hit",bkptno="2",frame=@{func="foo",args=[],
16817file="hello.c",line="13"@}
16818(@value{GDBP})
16819@end smallexample
16820
16821
16822@subheading The @code{-exec-finish} Command
16823@findex -exec-finish
16824
16825@subsubheading Synopsis
16826
16827@smallexample
16828 -exec-finish
16829@end smallexample
16830
16831Asynchronous command. Resumes the execution of the inferior program
16832until the current function is exited. Displays the results returned by
16833the function.
16834
16835@subsubheading @value{GDBN} Command
16836
16837The corresponding @value{GDBN} command is @samp{finish}.
16838
16839@subsubheading Example
16840
16841Function returning @code{void}.
16842
16843@smallexample
16844-exec-finish
16845^running
16846(@value{GDBP})
16847@@hello from foo
16848*stopped,reason="function-finished",frame=@{func="main",args=[],
16849file="hello.c",line="7"@}
16850(@value{GDBP})
16851@end smallexample
16852
16853Function returning other than @code{void}. The name of the internal
16854@value{GDBN} variable storing the result is printed, together with the
16855value itself.
16856
16857@smallexample
16858-exec-finish
16859^running
16860(@value{GDBP})
16861*stopped,reason="function-finished",frame=@{addr="0x000107b0",func="foo",
16862args=[@{name="a",value="1"],@{name="b",value="9"@}@},
16863file="recursive2.c",line="14"@},
16864gdb-result-var="$1",return-value="0"
16865(@value{GDBP})
16866@end smallexample
16867
16868
16869@subheading The @code{-exec-interrupt} Command
16870@findex -exec-interrupt
16871
16872@subsubheading Synopsis
16873
16874@smallexample
16875 -exec-interrupt
16876@end smallexample
16877
16878Asynchronous command. Interrupts the background execution of the target.
16879Note how the token associated with the stop message is the one for the
16880execution command that has been interrupted. The token for the interrupt
16881itself only appears in the @samp{^done} output. If the user is trying to
16882interrupt a non-running program, an error message will be printed.
16883
16884@subsubheading @value{GDBN} Command
16885
16886The corresponding @value{GDBN} command is @samp{interrupt}.
16887
16888@subsubheading Example
16889
16890@smallexample
16891(@value{GDBP})
16892111-exec-continue
16893111^running
16894
16895(@value{GDBP})
16896222-exec-interrupt
16897222^done
16898(@value{GDBP})
16899111*stopped,signal-name="SIGINT",signal-meaning="Interrupt",
16900frame=@{addr="0x00010140",func="foo",args=[],file="try.c",line="13"@}
16901(@value{GDBP})
16902
16903(@value{GDBP})
16904-exec-interrupt
16905^error,msg="mi_cmd_exec_interrupt: Inferior not executing."
16906(@value{GDBP})
16907@end smallexample
16908
16909
16910@subheading The @code{-exec-next} Command
16911@findex -exec-next
16912
16913@subsubheading Synopsis
16914
16915@smallexample
16916 -exec-next
16917@end smallexample
16918
16919Asynchronous command. Resumes execution of the inferior program, stopping
16920when the beginning of the next source line is reached.
16921
16922@subsubheading @value{GDBN} Command
16923
16924The corresponding @value{GDBN} command is @samp{next}.
16925
16926@subsubheading Example
16927
16928@smallexample
16929-exec-next
16930^running
16931(@value{GDBP})
16932*stopped,reason="end-stepping-range",line="8",file="hello.c"
16933(@value{GDBP})
16934@end smallexample
16935
16936
16937@subheading The @code{-exec-next-instruction} Command
16938@findex -exec-next-instruction
16939
16940@subsubheading Synopsis
16941
16942@smallexample
16943 -exec-next-instruction
16944@end smallexample
16945
16946Asynchronous command. Executes one machine instruction. If the
16947instruction is a function call continues until the function returns. If
16948the program stops at an instruction in the middle of a source line, the
16949address will be printed as well.
16950
16951@subsubheading @value{GDBN} Command
16952
16953The corresponding @value{GDBN} command is @samp{nexti}.
16954
16955@subsubheading Example
16956
16957@smallexample
16958(@value{GDBP})
16959-exec-next-instruction
16960^running
16961
16962(@value{GDBP})
16963*stopped,reason="end-stepping-range",
16964addr="0x000100d4",line="5",file="hello.c"
16965(@value{GDBP})
16966@end smallexample
16967
16968
16969@subheading The @code{-exec-return} Command
16970@findex -exec-return
16971
16972@subsubheading Synopsis
16973
16974@smallexample
16975 -exec-return
16976@end smallexample
16977
16978Makes current function return immediately. Doesn't execute the inferior.
16979Displays the new current frame.
16980
16981@subsubheading @value{GDBN} Command
16982
16983The corresponding @value{GDBN} command is @samp{return}.
16984
16985@subsubheading Example
16986
16987@smallexample
16988(@value{GDBP})
16989200-break-insert callee4
16990200^done,bkpt=@{number="1",addr="0x00010734",
16991file="../../../devo/gdb/testsuite/gdb.mi/basics.c",line="8"@}
16992(@value{GDBP})
16993000-exec-run
16994000^running
16995(@value{GDBP})
16996000*stopped,reason="breakpoint-hit",bkptno="1",
16997frame=@{func="callee4",args=[],
16998file="../../../devo/gdb/testsuite/gdb.mi/basics.c",line="8"@}
16999(@value{GDBP})
17000205-break-delete
17001205^done
17002(@value{GDBP})
17003111-exec-return
17004111^done,frame=@{level="0",func="callee3",
17005args=[@{name="strarg",
17006value="0x11940 \"A string argument.\""@}],
17007file="../../../devo/gdb/testsuite/gdb.mi/basics.c",line="18"@}
17008(@value{GDBP})
17009@end smallexample
17010
17011
17012@subheading The @code{-exec-run} Command
17013@findex -exec-run
17014
17015@subsubheading Synopsis
17016
17017@smallexample
17018 -exec-run
17019@end smallexample
17020
17021Asynchronous command. Starts execution of the inferior from the
17022beginning. The inferior executes until either a breakpoint is
17023encountered or the program exits.
17024
17025@subsubheading @value{GDBN} Command
17026
17027The corresponding @value{GDBN} command is @samp{run}.
17028
17029@subsubheading Example
17030
17031@smallexample
17032(@value{GDBP})
17033-break-insert main
17034^done,bkpt=@{number="1",addr="0x0001072c",file="recursive2.c",line="4"@}
17035(@value{GDBP})
17036-exec-run
17037^running
17038(@value{GDBP})
17039*stopped,reason="breakpoint-hit",bkptno="1",
17040frame=@{func="main",args=[],file="recursive2.c",line="4"@}
17041(@value{GDBP})
17042@end smallexample
17043
17044
17045@subheading The @code{-exec-show-arguments} Command
17046@findex -exec-show-arguments
17047
17048@subsubheading Synopsis
17049
17050@smallexample
17051 -exec-show-arguments
17052@end smallexample
17053
17054Print the arguments of the program.
17055
17056@subsubheading @value{GDBN} Command
17057
17058The corresponding @value{GDBN} command is @samp{show args}.
17059
17060@subsubheading Example
17061N.A.
17062
17063@c @subheading -exec-signal
17064
17065@subheading The @code{-exec-step} Command
17066@findex -exec-step
17067
17068@subsubheading Synopsis
17069
17070@smallexample
17071 -exec-step
17072@end smallexample
17073
17074Asynchronous command. Resumes execution of the inferior program, stopping
17075when the beginning of the next source line is reached, if the next
17076source line is not a function call. If it is, stop at the first
17077instruction of the called function.
17078
17079@subsubheading @value{GDBN} Command
17080
17081The corresponding @value{GDBN} command is @samp{step}.
17082
17083@subsubheading Example
17084
17085Stepping into a function:
17086
17087@smallexample
17088-exec-step
17089^running
17090(@value{GDBP})
17091*stopped,reason="end-stepping-range",
17092frame=@{func="foo",args=[@{name="a",value="10"@},
17093@{name="b",value="0"@}],file="recursive2.c",line="11"@}
17094(@value{GDBP})
17095@end smallexample
17096
17097Regular stepping:
17098
17099@smallexample
17100-exec-step
17101^running
17102(@value{GDBP})
17103*stopped,reason="end-stepping-range",line="14",file="recursive2.c"
17104(@value{GDBP})
17105@end smallexample
17106
17107
17108@subheading The @code{-exec-step-instruction} Command
17109@findex -exec-step-instruction
17110
17111@subsubheading Synopsis
17112
17113@smallexample
17114 -exec-step-instruction
17115@end smallexample
17116
17117Asynchronous command. Resumes the inferior which executes one machine
17118instruction. The output, once @value{GDBN} has stopped, will vary depending on
17119whether we have stopped in the middle of a source line or not. In the
17120former case, the address at which the program stopped will be printed as
17121well.
17122
17123@subsubheading @value{GDBN} Command
17124
17125The corresponding @value{GDBN} command is @samp{stepi}.
17126
17127@subsubheading Example
17128
17129@smallexample
17130(@value{GDBP})
17131-exec-step-instruction
17132^running
17133
17134(@value{GDBP})
17135*stopped,reason="end-stepping-range",
17136frame=@{func="foo",args=[],file="try.c",line="10"@}
17137(@value{GDBP})
17138-exec-step-instruction
17139^running
17140
17141(@value{GDBP})
17142*stopped,reason="end-stepping-range",
17143frame=@{addr="0x000100f4",func="foo",args=[],file="try.c",line="10"@}
17144(@value{GDBP})
17145@end smallexample
17146
17147
17148@subheading The @code{-exec-until} Command
17149@findex -exec-until
17150
17151@subsubheading Synopsis
17152
17153@smallexample
17154 -exec-until [ @var{location} ]
17155@end smallexample
17156
17157Asynchronous command. Executes the inferior until the @var{location}
17158specified in the argument is reached. If there is no argument, the inferior
17159executes until a source line greater than the current one is reached.
17160The reason for stopping in this case will be @samp{location-reached}.
17161
17162@subsubheading @value{GDBN} Command
17163
17164The corresponding @value{GDBN} command is @samp{until}.
17165
17166@subsubheading Example
17167
17168@smallexample
17169(@value{GDBP})
17170-exec-until recursive2.c:6
17171^running
17172(@value{GDBP})
17173x = 55
17174*stopped,reason="location-reached",frame=@{func="main",args=[],
17175file="recursive2.c",line="6"@}
17176(@value{GDBP})
17177@end smallexample
17178
17179@ignore
17180@subheading -file-clear
17181Is this going away????
17182@end ignore
17183
17184
17185@subheading The @code{-file-exec-and-symbols} Command
17186@findex -file-exec-and-symbols
17187
17188@subsubheading Synopsis
17189
17190@smallexample
17191 -file-exec-and-symbols @var{file}
17192@end smallexample
17193
17194Specify the executable file to be debugged. This file is the one from
17195which the symbol table is also read. If no file is specified, the
17196command clears the executable and symbol information. If breakpoints
17197are set when using this command with no arguments, @value{GDBN} will produce
17198error messages. Otherwise, no output is produced, except a completion
17199notification.
17200
17201@subsubheading @value{GDBN} Command
17202
17203The corresponding @value{GDBN} command is @samp{file}.
17204
17205@subsubheading Example
17206
17207@smallexample
17208(@value{GDBP})
17209-file-exec-and-symbols /kwikemart/marge/ezannoni/TRUNK/mbx/hello.mbx
17210^done
17211(@value{GDBP})
17212@end smallexample
17213
17214
17215@subheading The @code{-file-exec-file} Command
17216@findex -file-exec-file
17217
17218@subsubheading Synopsis
17219
17220@smallexample
17221 -file-exec-file @var{file}
17222@end smallexample
17223
17224Specify the executable file to be debugged. Unlike
17225@samp{-file-exec-and-symbols}, the symbol table is @emph{not} read
17226from this file. If used without argument, @value{GDBN} clears the information
17227about the executable file. No output is produced, except a completion
17228notification.
17229
17230@subsubheading @value{GDBN} Command
17231
17232The corresponding @value{GDBN} command is @samp{exec-file}.
17233
17234@subsubheading Example
17235
17236@smallexample
17237(@value{GDBP})
17238-file-exec-file /kwikemart/marge/ezannoni/TRUNK/mbx/hello.mbx
17239^done
17240(@value{GDBP})
17241@end smallexample
17242
17243
17244@subheading The @code{-file-list-exec-sections} Command
17245@findex -file-list-exec-sections
17246
17247@subsubheading Synopsis
17248
17249@smallexample
17250 -file-list-exec-sections
17251@end smallexample
17252
17253List the sections of the current executable file.
17254
17255@subsubheading @value{GDBN} Command
17256
17257The @value{GDBN} command @samp{info file} shows, among the rest, the same
17258information as this command. @code{gdbtk} has a corresponding command
17259@samp{gdb_load_info}.
17260
17261@subsubheading Example
17262N.A.
17263
17264
1abaf70c
BR
17265@subheading The @code{-file-list-exec-source-file} Command
17266@findex -file-list-exec-source-file
17267
17268@subsubheading Synopsis
17269
17270@smallexample
17271 -file-list-exec-source-file
17272@end smallexample
17273
b383017d 17274List the line number, the current source file, and the absolute path
1abaf70c
BR
17275to the current source file for the current executable.
17276
17277@subsubheading @value{GDBN} Command
17278
17279There's no @value{GDBN} command which directly corresponds to this one.
17280
17281@subsubheading Example
17282
17283@smallexample
17284(@value{GDBP})
17285123-file-list-exec-source-file
17286123^done,line="1",file="foo.c",fullname="/home/bar/foo.c"
17287(@value{GDBP})
17288@end smallexample
17289
17290
922fbb7b
AC
17291@subheading The @code{-file-list-exec-source-files} Command
17292@findex -file-list-exec-source-files
17293
17294@subsubheading Synopsis
17295
17296@smallexample
17297 -file-list-exec-source-files
17298@end smallexample
17299
17300List the source files for the current executable.
17301
57c22c6c
BR
17302It will always output the filename, but only when GDB can find the absolute
17303file name of a source file, will it output the fullname.
17304
922fbb7b
AC
17305@subsubheading @value{GDBN} Command
17306
17307There's no @value{GDBN} command which directly corresponds to this one.
17308@code{gdbtk} has an analogous command @samp{gdb_listfiles}.
17309
17310@subsubheading Example
57c22c6c
BR
17311@smallexample
17312(@value{GDBP})
17313-file-list-exec-source-files
17314^done,files=[
17315@{file=foo.c,fullname=/home/foo.c@},
17316@{file=/home/bar.c,fullname=/home/bar.c@},
17317@{file=gdb_could_not_find_fullpath.c@}]
17318(@value{GDBP})
17319@end smallexample
922fbb7b
AC
17320
17321@subheading The @code{-file-list-shared-libraries} Command
17322@findex -file-list-shared-libraries
17323
17324@subsubheading Synopsis
17325
17326@smallexample
17327 -file-list-shared-libraries
17328@end smallexample
17329
17330List the shared libraries in the program.
17331
17332@subsubheading @value{GDBN} Command
17333
17334The corresponding @value{GDBN} command is @samp{info shared}.
17335
17336@subsubheading Example
17337N.A.
17338
17339
17340@subheading The @code{-file-list-symbol-files} Command
17341@findex -file-list-symbol-files
17342
17343@subsubheading Synopsis
17344
17345@smallexample
17346 -file-list-symbol-files
17347@end smallexample
17348
17349List symbol files.
17350
17351@subsubheading @value{GDBN} Command
17352
17353The corresponding @value{GDBN} command is @samp{info file} (part of it).
17354
17355@subsubheading Example
17356N.A.
17357
17358
17359@subheading The @code{-file-symbol-file} Command
17360@findex -file-symbol-file
17361
17362@subsubheading Synopsis
17363
17364@smallexample
17365 -file-symbol-file @var{file}
17366@end smallexample
17367
17368Read symbol table info from the specified @var{file} argument. When
17369used without arguments, clears @value{GDBN}'s symbol table info. No output is
17370produced, except for a completion notification.
17371
17372@subsubheading @value{GDBN} Command
17373
17374The corresponding @value{GDBN} command is @samp{symbol-file}.
17375
17376@subsubheading Example
17377
17378@smallexample
17379(@value{GDBP})
17380-file-symbol-file /kwikemart/marge/ezannoni/TRUNK/mbx/hello.mbx
17381^done
17382(@value{GDBP})
17383@end smallexample
17384
17385@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
17386@node GDB/MI Miscellaneous Commands
17387@section Miscellaneous @value{GDBN} commands in @sc{gdb/mi}
17388
17389@c @subheading -gdb-complete
17390
17391@subheading The @code{-gdb-exit} Command
17392@findex -gdb-exit
17393
17394@subsubheading Synopsis
17395
17396@smallexample
17397 -gdb-exit
17398@end smallexample
17399
17400Exit @value{GDBN} immediately.
17401
17402@subsubheading @value{GDBN} Command
17403
17404Approximately corresponds to @samp{quit}.
17405
17406@subsubheading Example
17407
17408@smallexample
17409(@value{GDBP})
17410-gdb-exit
17411@end smallexample
17412
17413@subheading The @code{-gdb-set} Command
17414@findex -gdb-set
17415
17416@subsubheading Synopsis
17417
17418@smallexample
17419 -gdb-set
17420@end smallexample
17421
17422Set an internal @value{GDBN} variable.
17423@c IS THIS A DOLLAR VARIABLE? OR SOMETHING LIKE ANNOTATE ?????
17424
17425@subsubheading @value{GDBN} Command
17426
17427The corresponding @value{GDBN} command is @samp{set}.
17428
17429@subsubheading Example
17430
17431@smallexample
17432(@value{GDBP})
17433-gdb-set $foo=3
17434^done
17435(@value{GDBP})
17436@end smallexample
17437
17438
17439@subheading The @code{-gdb-show} Command
17440@findex -gdb-show
17441
17442@subsubheading Synopsis
17443
17444@smallexample
17445 -gdb-show
17446@end smallexample
17447
17448Show the current value of a @value{GDBN} variable.
17449
17450@subsubheading @value{GDBN} command
17451
17452The corresponding @value{GDBN} command is @samp{show}.
17453
17454@subsubheading Example
17455
17456@smallexample
17457(@value{GDBP})
17458-gdb-show annotate
17459^done,value="0"
17460(@value{GDBP})
17461@end smallexample
17462
17463@c @subheading -gdb-source
17464
17465
17466@subheading The @code{-gdb-version} Command
17467@findex -gdb-version
17468
17469@subsubheading Synopsis
17470
17471@smallexample
17472 -gdb-version
17473@end smallexample
17474
17475Show version information for @value{GDBN}. Used mostly in testing.
17476
17477@subsubheading @value{GDBN} Command
17478
17479There's no equivalent @value{GDBN} command. @value{GDBN} by default shows this
17480information when you start an interactive session.
17481
17482@subsubheading Example
17483
17484@c This example modifies the actual output from GDB to avoid overfull
17485@c box in TeX.
17486@smallexample
17487(@value{GDBP})
17488-gdb-version
17489~GNU gdb 5.2.1
17490~Copyright 2000 Free Software Foundation, Inc.
17491~GDB is free software, covered by the GNU General Public License, and
17492~you are welcome to change it and/or distribute copies of it under
17493~ certain conditions.
17494~Type "show copying" to see the conditions.
17495~There is absolutely no warranty for GDB. Type "show warranty" for
17496~ details.
b383017d 17497~This GDB was configured as
922fbb7b
AC
17498 "--host=sparc-sun-solaris2.5.1 --target=ppc-eabi".
17499^done
17500(@value{GDBP})
17501@end smallexample
17502
17503@subheading The @code{-interpreter-exec} Command
17504@findex -interpreter-exec
17505
17506@subheading Synopsis
17507
17508@smallexample
17509-interpreter-exec @var{interpreter} @var{command}
17510@end smallexample
17511
17512Execute the specified @var{command} in the given @var{interpreter}.
17513
17514@subheading @value{GDBN} Command
17515
17516The corresponding @value{GDBN} command is @samp{interpreter-exec}.
17517
17518@subheading Example
17519
17520@smallexample
17521(@value{GDBP})
17522-interpreter-exec console "break main"
17523&"During symbol reading, couldn't parse type; debugger out of date?.\n"
17524&"During symbol reading, bad structure-type format.\n"
17525~"Breakpoint 1 at 0x8074fc6: file ../../src/gdb/main.c, line 743.\n"
17526^done
17527(@value{GDBP})
17528@end smallexample
17529
17530@ignore
17531@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
17532@node GDB/MI Kod Commands
17533@section @sc{gdb/mi} Kod Commands
17534
17535The Kod commands are not implemented.
17536
17537@c @subheading -kod-info
17538
17539@c @subheading -kod-list
17540
17541@c @subheading -kod-list-object-types
17542
17543@c @subheading -kod-show
17544
17545@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
17546@node GDB/MI Memory Overlay Commands
17547@section @sc{gdb/mi} Memory Overlay Commands
17548
17549The memory overlay commands are not implemented.
17550
17551@c @subheading -overlay-auto
17552
17553@c @subheading -overlay-list-mapping-state
17554
17555@c @subheading -overlay-list-overlays
17556
17557@c @subheading -overlay-map
17558
17559@c @subheading -overlay-off
17560
17561@c @subheading -overlay-on
17562
17563@c @subheading -overlay-unmap
17564
17565@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
17566@node GDB/MI Signal Handling Commands
17567@section @sc{gdb/mi} Signal Handling Commands
17568
17569Signal handling commands are not implemented.
17570
17571@c @subheading -signal-handle
17572
17573@c @subheading -signal-list-handle-actions
17574
17575@c @subheading -signal-list-signal-types
17576@end ignore
17577
17578
17579@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
17580@node GDB/MI Stack Manipulation
17581@section @sc{gdb/mi} Stack Manipulation Commands
17582
17583
17584@subheading The @code{-stack-info-frame} Command
17585@findex -stack-info-frame
17586
17587@subsubheading Synopsis
17588
17589@smallexample
17590 -stack-info-frame
17591@end smallexample
17592
17593Get info on the current frame.
17594
17595@subsubheading @value{GDBN} Command
17596
17597The corresponding @value{GDBN} command is @samp{info frame} or @samp{frame}
17598(without arguments).
17599
17600@subsubheading Example
17601N.A.
17602
17603@subheading The @code{-stack-info-depth} Command
17604@findex -stack-info-depth
17605
17606@subsubheading Synopsis
17607
17608@smallexample
17609 -stack-info-depth [ @var{max-depth} ]
17610@end smallexample
17611
17612Return the depth of the stack. If the integer argument @var{max-depth}
17613is specified, do not count beyond @var{max-depth} frames.
17614
17615@subsubheading @value{GDBN} Command
17616
17617There's no equivalent @value{GDBN} command.
17618
17619@subsubheading Example
17620
17621For a stack with frame levels 0 through 11:
17622
17623@smallexample
17624(@value{GDBP})
17625-stack-info-depth
17626^done,depth="12"
17627(@value{GDBP})
17628-stack-info-depth 4
17629^done,depth="4"
17630(@value{GDBP})
17631-stack-info-depth 12
17632^done,depth="12"
17633(@value{GDBP})
17634-stack-info-depth 11
17635^done,depth="11"
17636(@value{GDBP})
17637-stack-info-depth 13
17638^done,depth="12"
17639(@value{GDBP})
17640@end smallexample
17641
17642@subheading The @code{-stack-list-arguments} Command
17643@findex -stack-list-arguments
17644
17645@subsubheading Synopsis
17646
17647@smallexample
17648 -stack-list-arguments @var{show-values}
17649 [ @var{low-frame} @var{high-frame} ]
17650@end smallexample
17651
17652Display a list of the arguments for the frames between @var{low-frame}
17653and @var{high-frame} (inclusive). If @var{low-frame} and
17654@var{high-frame} are not provided, list the arguments for the whole call
17655stack.
17656
17657The @var{show-values} argument must have a value of 0 or 1. A value of
176580 means that only the names of the arguments are listed, a value of 1
17659means that both names and values of the arguments are printed.
17660
17661@subsubheading @value{GDBN} Command
17662
17663@value{GDBN} does not have an equivalent command. @code{gdbtk} has a
17664@samp{gdb_get_args} command which partially overlaps with the
17665functionality of @samp{-stack-list-arguments}.
17666
17667@subsubheading Example
17668
17669@smallexample
17670(@value{GDBP})
17671-stack-list-frames
17672^done,
17673stack=[
17674frame=@{level="0",addr="0x00010734",func="callee4",
17675file="../../../devo/gdb/testsuite/gdb.mi/basics.c",line="8"@},
17676frame=@{level="1",addr="0x0001076c",func="callee3",
17677file="../../../devo/gdb/testsuite/gdb.mi/basics.c",line="17"@},
17678frame=@{level="2",addr="0x0001078c",func="callee2",
17679file="../../../devo/gdb/testsuite/gdb.mi/basics.c",line="22"@},
17680frame=@{level="3",addr="0x000107b4",func="callee1",
17681file="../../../devo/gdb/testsuite/gdb.mi/basics.c",line="27"@},
17682frame=@{level="4",addr="0x000107e0",func="main",
17683file="../../../devo/gdb/testsuite/gdb.mi/basics.c",line="32"@}]
17684(@value{GDBP})
17685-stack-list-arguments 0
17686^done,
17687stack-args=[
17688frame=@{level="0",args=[]@},
17689frame=@{level="1",args=[name="strarg"]@},
17690frame=@{level="2",args=[name="intarg",name="strarg"]@},
17691frame=@{level="3",args=[name="intarg",name="strarg",name="fltarg"]@},
17692frame=@{level="4",args=[]@}]
17693(@value{GDBP})
17694-stack-list-arguments 1
17695^done,
17696stack-args=[
17697frame=@{level="0",args=[]@},
17698frame=@{level="1",
17699 args=[@{name="strarg",value="0x11940 \"A string argument.\""@}]@},
17700frame=@{level="2",args=[
17701@{name="intarg",value="2"@},
17702@{name="strarg",value="0x11940 \"A string argument.\""@}]@},
17703@{frame=@{level="3",args=[
17704@{name="intarg",value="2"@},
17705@{name="strarg",value="0x11940 \"A string argument.\""@},
17706@{name="fltarg",value="3.5"@}]@},
17707frame=@{level="4",args=[]@}]
17708(@value{GDBP})
17709-stack-list-arguments 0 2 2
17710^done,stack-args=[frame=@{level="2",args=[name="intarg",name="strarg"]@}]
17711(@value{GDBP})
17712-stack-list-arguments 1 2 2
17713^done,stack-args=[frame=@{level="2",
17714args=[@{name="intarg",value="2"@},
17715@{name="strarg",value="0x11940 \"A string argument.\""@}]@}]
17716(@value{GDBP})
17717@end smallexample
17718
17719@c @subheading -stack-list-exception-handlers
17720
17721
17722@subheading The @code{-stack-list-frames} Command
17723@findex -stack-list-frames
17724
17725@subsubheading Synopsis
17726
17727@smallexample
17728 -stack-list-frames [ @var{low-frame} @var{high-frame} ]
17729@end smallexample
17730
17731List the frames currently on the stack. For each frame it displays the
17732following info:
17733
17734@table @samp
17735@item @var{level}
17736The frame number, 0 being the topmost frame, i.e. the innermost function.
17737@item @var{addr}
17738The @code{$pc} value for that frame.
17739@item @var{func}
17740Function name.
17741@item @var{file}
17742File name of the source file where the function lives.
17743@item @var{line}
17744Line number corresponding to the @code{$pc}.
17745@end table
17746
17747If invoked without arguments, this command prints a backtrace for the
17748whole stack. If given two integer arguments, it shows the frames whose
17749levels are between the two arguments (inclusive). If the two arguments
17750are equal, it shows the single frame at the corresponding level.
17751
17752@subsubheading @value{GDBN} Command
17753
17754The corresponding @value{GDBN} commands are @samp{backtrace} and @samp{where}.
17755
17756@subsubheading Example
17757
17758Full stack backtrace:
17759
17760@smallexample
17761(@value{GDBP})
17762-stack-list-frames
17763^done,stack=
17764[frame=@{level="0",addr="0x0001076c",func="foo",
17765 file="recursive2.c",line="11"@},
17766frame=@{level="1",addr="0x000107a4",func="foo",
17767 file="recursive2.c",line="14"@},
17768frame=@{level="2",addr="0x000107a4",func="foo",
17769 file="recursive2.c",line="14"@},
17770frame=@{level="3",addr="0x000107a4",func="foo",
17771 file="recursive2.c",line="14"@},
17772frame=@{level="4",addr="0x000107a4",func="foo",
17773 file="recursive2.c",line="14"@},
17774frame=@{level="5",addr="0x000107a4",func="foo",
17775 file="recursive2.c",line="14"@},
17776frame=@{level="6",addr="0x000107a4",func="foo",
17777 file="recursive2.c",line="14"@},
17778frame=@{level="7",addr="0x000107a4",func="foo",
17779 file="recursive2.c",line="14"@},
17780frame=@{level="8",addr="0x000107a4",func="foo",
17781 file="recursive2.c",line="14"@},
17782frame=@{level="9",addr="0x000107a4",func="foo",
17783 file="recursive2.c",line="14"@},
17784frame=@{level="10",addr="0x000107a4",func="foo",
17785 file="recursive2.c",line="14"@},
17786frame=@{level="11",addr="0x00010738",func="main",
17787 file="recursive2.c",line="4"@}]
17788(@value{GDBP})
17789@end smallexample
17790
17791Show frames between @var{low_frame} and @var{high_frame}:
17792
17793@smallexample
17794(@value{GDBP})
17795-stack-list-frames 3 5
17796^done,stack=
17797[frame=@{level="3",addr="0x000107a4",func="foo",
17798 file="recursive2.c",line="14"@},
17799frame=@{level="4",addr="0x000107a4",func="foo",
17800 file="recursive2.c",line="14"@},
17801frame=@{level="5",addr="0x000107a4",func="foo",
17802 file="recursive2.c",line="14"@}]
17803(@value{GDBP})
17804@end smallexample
17805
17806Show a single frame:
17807
17808@smallexample
17809(@value{GDBP})
17810-stack-list-frames 3 3
17811^done,stack=
17812[frame=@{level="3",addr="0x000107a4",func="foo",
17813 file="recursive2.c",line="14"@}]
17814(@value{GDBP})
17815@end smallexample
17816
17817
17818@subheading The @code{-stack-list-locals} Command
17819@findex -stack-list-locals
17820
17821@subsubheading Synopsis
17822
17823@smallexample
17824 -stack-list-locals @var{print-values}
17825@end smallexample
17826
17827Display the local variable names for the current frame. With an
bc8ced35
NR
17828argument of 0 or @code{--no-values}, prints only the names of the variables.
17829With argument of 1 or @code{--all-values}, prints also their values. With
17830argument of 2 or @code{--simple-values}, prints the name, type and value for
17831simple data types and the name and type for arrays, structures and
17832unions. In this last case, the idea is that the user can see the
17833value of simple data types immediately and he can create variable
17834objects for other data types if he wishes to explore their values in
17835more detail.
922fbb7b
AC
17836
17837@subsubheading @value{GDBN} Command
17838
17839@samp{info locals} in @value{GDBN}, @samp{gdb_get_locals} in @code{gdbtk}.
17840
17841@subsubheading Example
17842
17843@smallexample
17844(@value{GDBP})
17845-stack-list-locals 0
17846^done,locals=[name="A",name="B",name="C"]
17847(@value{GDBP})
bc8ced35 17848-stack-list-locals --all-values
922fbb7b 17849^done,locals=[@{name="A",value="1"@},@{name="B",value="2"@},
bc8ced35
NR
17850 @{name="C",value="@{1, 2, 3@}"@}]
17851-stack-list-locals --simple-values
17852^done,locals=[@{name="A",type="int",value="1"@},
17853 @{name="B",type="int",value="2"@},@{name="C",type="int [3]"@}]
922fbb7b
AC
17854(@value{GDBP})
17855@end smallexample
17856
17857
17858@subheading The @code{-stack-select-frame} Command
17859@findex -stack-select-frame
17860
17861@subsubheading Synopsis
17862
17863@smallexample
17864 -stack-select-frame @var{framenum}
17865@end smallexample
17866
17867Change the current frame. Select a different frame @var{framenum} on
17868the stack.
17869
17870@subsubheading @value{GDBN} Command
17871
17872The corresponding @value{GDBN} commands are @samp{frame}, @samp{up},
17873@samp{down}, @samp{select-frame}, @samp{up-silent}, and @samp{down-silent}.
17874
17875@subsubheading Example
17876
17877@smallexample
17878(@value{GDBP})
17879-stack-select-frame 2
17880^done
17881(@value{GDBP})
17882@end smallexample
17883
17884@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
17885@node GDB/MI Symbol Query
17886@section @sc{gdb/mi} Symbol Query Commands
17887
17888
17889@subheading The @code{-symbol-info-address} Command
17890@findex -symbol-info-address
17891
17892@subsubheading Synopsis
17893
17894@smallexample
17895 -symbol-info-address @var{symbol}
17896@end smallexample
17897
17898Describe where @var{symbol} is stored.
17899
17900@subsubheading @value{GDBN} Command
17901
17902The corresponding @value{GDBN} command is @samp{info address}.
17903
17904@subsubheading Example
17905N.A.
17906
17907
17908@subheading The @code{-symbol-info-file} Command
17909@findex -symbol-info-file
17910
17911@subsubheading Synopsis
17912
17913@smallexample
17914 -symbol-info-file
17915@end smallexample
17916
17917Show the file for the symbol.
17918
17919@subsubheading @value{GDBN} Command
17920
17921There's no equivalent @value{GDBN} command. @code{gdbtk} has
17922@samp{gdb_find_file}.
17923
17924@subsubheading Example
17925N.A.
17926
17927
17928@subheading The @code{-symbol-info-function} Command
17929@findex -symbol-info-function
17930
17931@subsubheading Synopsis
17932
17933@smallexample
17934 -symbol-info-function
17935@end smallexample
17936
17937Show which function the symbol lives in.
17938
17939@subsubheading @value{GDBN} Command
17940
17941@samp{gdb_get_function} in @code{gdbtk}.
17942
17943@subsubheading Example
17944N.A.
17945
17946
17947@subheading The @code{-symbol-info-line} Command
17948@findex -symbol-info-line
17949
17950@subsubheading Synopsis
17951
17952@smallexample
17953 -symbol-info-line
17954@end smallexample
17955
17956Show the core addresses of the code for a source line.
17957
17958@subsubheading @value{GDBN} Command
17959
71952f4c 17960The corresponding @value{GDBN} command is @samp{info line}.
922fbb7b
AC
17961@code{gdbtk} has the @samp{gdb_get_line} and @samp{gdb_get_file} commands.
17962
17963@subsubheading Example
17964N.A.
17965
17966
17967@subheading The @code{-symbol-info-symbol} Command
17968@findex -symbol-info-symbol
17969
17970@subsubheading Synopsis
17971
17972@smallexample
17973 -symbol-info-symbol @var{addr}
17974@end smallexample
17975
17976Describe what symbol is at location @var{addr}.
17977
17978@subsubheading @value{GDBN} Command
17979
17980The corresponding @value{GDBN} command is @samp{info symbol}.
17981
17982@subsubheading Example
17983N.A.
17984
17985
17986@subheading The @code{-symbol-list-functions} Command
17987@findex -symbol-list-functions
17988
17989@subsubheading Synopsis
17990
17991@smallexample
17992 -symbol-list-functions
17993@end smallexample
17994
17995List the functions in the executable.
17996
17997@subsubheading @value{GDBN} Command
17998
17999@samp{info functions} in @value{GDBN}, @samp{gdb_listfunc} and
18000@samp{gdb_search} in @code{gdbtk}.
18001
18002@subsubheading Example
18003N.A.
18004
18005
32e7087d
JB
18006@subheading The @code{-symbol-list-lines} Command
18007@findex -symbol-list-lines
18008
18009@subsubheading Synopsis
18010
18011@smallexample
18012 -symbol-list-lines @var{filename}
18013@end smallexample
18014
18015Print the list of lines that contain code and their associated program
18016addresses for the given source filename. The entries are sorted in
18017ascending PC order.
18018
18019@subsubheading @value{GDBN} Command
18020
18021There is no corresponding @value{GDBN} command.
18022
18023@subsubheading Example
18024@smallexample
18025(@value{GDBP})
18026-symbol-list-lines basics.c
54ff5908 18027^done,lines=[@{pc="0x08048554",line="7"@},@{pc="0x0804855a",line="8"@}]
32e7087d
JB
18028(@value{GDBP})
18029@end smallexample
18030
18031
922fbb7b
AC
18032@subheading The @code{-symbol-list-types} Command
18033@findex -symbol-list-types
18034
18035@subsubheading Synopsis
18036
18037@smallexample
18038 -symbol-list-types
18039@end smallexample
18040
18041List all the type names.
18042
18043@subsubheading @value{GDBN} Command
18044
18045The corresponding commands are @samp{info types} in @value{GDBN},
18046@samp{gdb_search} in @code{gdbtk}.
18047
18048@subsubheading Example
18049N.A.
18050
18051
18052@subheading The @code{-symbol-list-variables} Command
18053@findex -symbol-list-variables
18054
18055@subsubheading Synopsis
18056
18057@smallexample
18058 -symbol-list-variables
18059@end smallexample
18060
18061List all the global and static variable names.
18062
18063@subsubheading @value{GDBN} Command
18064
18065@samp{info variables} in @value{GDBN}, @samp{gdb_search} in @code{gdbtk}.
18066
18067@subsubheading Example
18068N.A.
18069
18070
18071@subheading The @code{-symbol-locate} Command
18072@findex -symbol-locate
18073
18074@subsubheading Synopsis
18075
18076@smallexample
18077 -symbol-locate
18078@end smallexample
18079
18080@subsubheading @value{GDBN} Command
18081
18082@samp{gdb_loc} in @code{gdbtk}.
18083
18084@subsubheading Example
18085N.A.
18086
18087
18088@subheading The @code{-symbol-type} Command
18089@findex -symbol-type
18090
18091@subsubheading Synopsis
18092
18093@smallexample
18094 -symbol-type @var{variable}
18095@end smallexample
18096
18097Show type of @var{variable}.
18098
18099@subsubheading @value{GDBN} Command
18100
18101The corresponding @value{GDBN} command is @samp{ptype}, @code{gdbtk} has
18102@samp{gdb_obj_variable}.
18103
18104@subsubheading Example
18105N.A.
18106
18107
18108@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
18109@node GDB/MI Target Manipulation
18110@section @sc{gdb/mi} Target Manipulation Commands
18111
18112
18113@subheading The @code{-target-attach} Command
18114@findex -target-attach
18115
18116@subsubheading Synopsis
18117
18118@smallexample
18119 -target-attach @var{pid} | @var{file}
18120@end smallexample
18121
18122Attach to a process @var{pid} or a file @var{file} outside of @value{GDBN}.
18123
18124@subsubheading @value{GDBN} command
18125
18126The corresponding @value{GDBN} command is @samp{attach}.
18127
18128@subsubheading Example
18129N.A.
18130
18131
18132@subheading The @code{-target-compare-sections} Command
18133@findex -target-compare-sections
18134
18135@subsubheading Synopsis
18136
18137@smallexample
18138 -target-compare-sections [ @var{section} ]
18139@end smallexample
18140
18141Compare data of section @var{section} on target to the exec file.
18142Without the argument, all sections are compared.
18143
18144@subsubheading @value{GDBN} Command
18145
18146The @value{GDBN} equivalent is @samp{compare-sections}.
18147
18148@subsubheading Example
18149N.A.
18150
18151
18152@subheading The @code{-target-detach} Command
18153@findex -target-detach
18154
18155@subsubheading Synopsis
18156
18157@smallexample
18158 -target-detach
18159@end smallexample
18160
18161Disconnect from the remote target. There's no output.
18162
18163@subsubheading @value{GDBN} command
18164
18165The corresponding @value{GDBN} command is @samp{detach}.
18166
18167@subsubheading Example
18168
18169@smallexample
18170(@value{GDBP})
18171-target-detach
18172^done
18173(@value{GDBP})
18174@end smallexample
18175
18176
07f31aa6
DJ
18177@subheading The @code{-target-disconnect} Command
18178@findex -target-disconnect
18179
18180@subsubheading Synopsis
18181
18182@example
18183 -target-disconnect
18184@end example
18185
18186Disconnect from the remote target. There's no output.
18187
18188@subsubheading @value{GDBN} command
18189
18190The corresponding @value{GDBN} command is @samp{disconnect}.
18191
18192@subsubheading Example
18193
18194@smallexample
18195(@value{GDBP})
18196-target-disconnect
18197^done
18198(@value{GDBP})
18199@end smallexample
18200
18201
922fbb7b
AC
18202@subheading The @code{-target-download} Command
18203@findex -target-download
18204
18205@subsubheading Synopsis
18206
18207@smallexample
18208 -target-download
18209@end smallexample
18210
18211Loads the executable onto the remote target.
18212It prints out an update message every half second, which includes the fields:
18213
18214@table @samp
18215@item section
18216The name of the section.
18217@item section-sent
18218The size of what has been sent so far for that section.
18219@item section-size
18220The size of the section.
18221@item total-sent
18222The total size of what was sent so far (the current and the previous sections).
18223@item total-size
18224The size of the overall executable to download.
18225@end table
18226
18227@noindent
18228Each message is sent as status record (@pxref{GDB/MI Output Syntax, ,
18229@sc{gdb/mi} Output Syntax}).
18230
18231In addition, it prints the name and size of the sections, as they are
18232downloaded. These messages include the following fields:
18233
18234@table @samp
18235@item section
18236The name of the section.
18237@item section-size
18238The size of the section.
18239@item total-size
18240The size of the overall executable to download.
18241@end table
18242
18243@noindent
18244At the end, a summary is printed.
18245
18246@subsubheading @value{GDBN} Command
18247
18248The corresponding @value{GDBN} command is @samp{load}.
18249
18250@subsubheading Example
18251
18252Note: each status message appears on a single line. Here the messages
18253have been broken down so that they can fit onto a page.
18254
18255@smallexample
18256(@value{GDBP})
18257-target-download
18258+download,@{section=".text",section-size="6668",total-size="9880"@}
18259+download,@{section=".text",section-sent="512",section-size="6668",
18260total-sent="512",total-size="9880"@}
18261+download,@{section=".text",section-sent="1024",section-size="6668",
18262total-sent="1024",total-size="9880"@}
18263+download,@{section=".text",section-sent="1536",section-size="6668",
18264total-sent="1536",total-size="9880"@}
18265+download,@{section=".text",section-sent="2048",section-size="6668",
18266total-sent="2048",total-size="9880"@}
18267+download,@{section=".text",section-sent="2560",section-size="6668",
18268total-sent="2560",total-size="9880"@}
18269+download,@{section=".text",section-sent="3072",section-size="6668",
18270total-sent="3072",total-size="9880"@}
18271+download,@{section=".text",section-sent="3584",section-size="6668",
18272total-sent="3584",total-size="9880"@}
18273+download,@{section=".text",section-sent="4096",section-size="6668",
18274total-sent="4096",total-size="9880"@}
18275+download,@{section=".text",section-sent="4608",section-size="6668",
18276total-sent="4608",total-size="9880"@}
18277+download,@{section=".text",section-sent="5120",section-size="6668",
18278total-sent="5120",total-size="9880"@}
18279+download,@{section=".text",section-sent="5632",section-size="6668",
18280total-sent="5632",total-size="9880"@}
18281+download,@{section=".text",section-sent="6144",section-size="6668",
18282total-sent="6144",total-size="9880"@}
18283+download,@{section=".text",section-sent="6656",section-size="6668",
18284total-sent="6656",total-size="9880"@}
18285+download,@{section=".init",section-size="28",total-size="9880"@}
18286+download,@{section=".fini",section-size="28",total-size="9880"@}
18287+download,@{section=".data",section-size="3156",total-size="9880"@}
18288+download,@{section=".data",section-sent="512",section-size="3156",
18289total-sent="7236",total-size="9880"@}
18290+download,@{section=".data",section-sent="1024",section-size="3156",
18291total-sent="7748",total-size="9880"@}
18292+download,@{section=".data",section-sent="1536",section-size="3156",
18293total-sent="8260",total-size="9880"@}
18294+download,@{section=".data",section-sent="2048",section-size="3156",
18295total-sent="8772",total-size="9880"@}
18296+download,@{section=".data",section-sent="2560",section-size="3156",
18297total-sent="9284",total-size="9880"@}
18298+download,@{section=".data",section-sent="3072",section-size="3156",
18299total-sent="9796",total-size="9880"@}
18300^done,address="0x10004",load-size="9880",transfer-rate="6586",
18301write-rate="429"
18302(@value{GDBP})
18303@end smallexample
18304
18305
18306@subheading The @code{-target-exec-status} Command
18307@findex -target-exec-status
18308
18309@subsubheading Synopsis
18310
18311@smallexample
18312 -target-exec-status
18313@end smallexample
18314
18315Provide information on the state of the target (whether it is running or
18316not, for instance).
18317
18318@subsubheading @value{GDBN} Command
18319
18320There's no equivalent @value{GDBN} command.
18321
18322@subsubheading Example
18323N.A.
18324
18325
18326@subheading The @code{-target-list-available-targets} Command
18327@findex -target-list-available-targets
18328
18329@subsubheading Synopsis
18330
18331@smallexample
18332 -target-list-available-targets
18333@end smallexample
18334
18335List the possible targets to connect to.
18336
18337@subsubheading @value{GDBN} Command
18338
18339The corresponding @value{GDBN} command is @samp{help target}.
18340
18341@subsubheading Example
18342N.A.
18343
18344
18345@subheading The @code{-target-list-current-targets} Command
18346@findex -target-list-current-targets
18347
18348@subsubheading Synopsis
18349
18350@smallexample
18351 -target-list-current-targets
18352@end smallexample
18353
18354Describe the current target.
18355
18356@subsubheading @value{GDBN} Command
18357
18358The corresponding information is printed by @samp{info file} (among
18359other things).
18360
18361@subsubheading Example
18362N.A.
18363
18364
18365@subheading The @code{-target-list-parameters} Command
18366@findex -target-list-parameters
18367
18368@subsubheading Synopsis
18369
18370@smallexample
18371 -target-list-parameters
18372@end smallexample
18373
18374@c ????
18375
18376@subsubheading @value{GDBN} Command
18377
18378No equivalent.
18379
18380@subsubheading Example
18381N.A.
18382
18383
18384@subheading The @code{-target-select} Command
18385@findex -target-select
18386
18387@subsubheading Synopsis
18388
18389@smallexample
18390 -target-select @var{type} @var{parameters @dots{}}
18391@end smallexample
18392
18393Connect @value{GDBN} to the remote target. This command takes two args:
18394
18395@table @samp
18396@item @var{type}
18397The type of target, for instance @samp{async}, @samp{remote}, etc.
18398@item @var{parameters}
18399Device names, host names and the like. @xref{Target Commands, ,
18400Commands for managing targets}, for more details.
18401@end table
18402
18403The output is a connection notification, followed by the address at
18404which the target program is, in the following form:
18405
18406@smallexample
18407^connected,addr="@var{address}",func="@var{function name}",
18408 args=[@var{arg list}]
18409@end smallexample
18410
18411@subsubheading @value{GDBN} Command
18412
18413The corresponding @value{GDBN} command is @samp{target}.
18414
18415@subsubheading Example
18416
18417@smallexample
18418(@value{GDBP})
18419-target-select async /dev/ttya
18420^connected,addr="0xfe00a300",func="??",args=[]
18421(@value{GDBP})
18422@end smallexample
18423
18424@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
18425@node GDB/MI Thread Commands
18426@section @sc{gdb/mi} Thread Commands
18427
18428
18429@subheading The @code{-thread-info} Command
18430@findex -thread-info
18431
18432@subsubheading Synopsis
18433
18434@smallexample
18435 -thread-info
18436@end smallexample
18437
18438@subsubheading @value{GDBN} command
18439
18440No equivalent.
18441
18442@subsubheading Example
18443N.A.
18444
18445
18446@subheading The @code{-thread-list-all-threads} Command
18447@findex -thread-list-all-threads
18448
18449@subsubheading Synopsis
18450
18451@smallexample
18452 -thread-list-all-threads
18453@end smallexample
18454
18455@subsubheading @value{GDBN} Command
18456
18457The equivalent @value{GDBN} command is @samp{info threads}.
18458
18459@subsubheading Example
18460N.A.
18461
18462
18463@subheading The @code{-thread-list-ids} Command
18464@findex -thread-list-ids
18465
18466@subsubheading Synopsis
18467
18468@smallexample
18469 -thread-list-ids
18470@end smallexample
18471
18472Produces a list of the currently known @value{GDBN} thread ids. At the
18473end of the list it also prints the total number of such threads.
18474
18475@subsubheading @value{GDBN} Command
18476
18477Part of @samp{info threads} supplies the same information.
18478
18479@subsubheading Example
18480
18481No threads present, besides the main process:
18482
18483@smallexample
18484(@value{GDBP})
18485-thread-list-ids
18486^done,thread-ids=@{@},number-of-threads="0"
18487(@value{GDBP})
18488@end smallexample
18489
18490
18491Several threads:
18492
18493@smallexample
18494(@value{GDBP})
18495-thread-list-ids
18496^done,thread-ids=@{thread-id="3",thread-id="2",thread-id="1"@},
18497number-of-threads="3"
18498(@value{GDBP})
18499@end smallexample
18500
18501
18502@subheading The @code{-thread-select} Command
18503@findex -thread-select
18504
18505@subsubheading Synopsis
18506
18507@smallexample
18508 -thread-select @var{threadnum}
18509@end smallexample
18510
18511Make @var{threadnum} the current thread. It prints the number of the new
18512current thread, and the topmost frame for that thread.
18513
18514@subsubheading @value{GDBN} Command
18515
18516The corresponding @value{GDBN} command is @samp{thread}.
18517
18518@subsubheading Example
18519
18520@smallexample
18521(@value{GDBP})
18522-exec-next
18523^running
18524(@value{GDBP})
18525*stopped,reason="end-stepping-range",thread-id="2",line="187",
18526file="../../../devo/gdb/testsuite/gdb.threads/linux-dp.c"
18527(@value{GDBP})
18528-thread-list-ids
18529^done,
18530thread-ids=@{thread-id="3",thread-id="2",thread-id="1"@},
18531number-of-threads="3"
18532(@value{GDBP})
18533-thread-select 3
18534^done,new-thread-id="3",
18535frame=@{level="0",func="vprintf",
18536args=[@{name="format",value="0x8048e9c \"%*s%c %d %c\\n\""@},
18537@{name="arg",value="0x2"@}],file="vprintf.c",line="31"@}
18538(@value{GDBP})
18539@end smallexample
18540
18541@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
18542@node GDB/MI Tracepoint Commands
18543@section @sc{gdb/mi} Tracepoint Commands
18544
18545The tracepoint commands are not yet implemented.
18546
18547@c @subheading -trace-actions
18548
18549@c @subheading -trace-delete
18550
18551@c @subheading -trace-disable
18552
18553@c @subheading -trace-dump
18554
18555@c @subheading -trace-enable
18556
18557@c @subheading -trace-exists
18558
18559@c @subheading -trace-find
18560
18561@c @subheading -trace-frame-number
18562
18563@c @subheading -trace-info
18564
18565@c @subheading -trace-insert
18566
18567@c @subheading -trace-list
18568
18569@c @subheading -trace-pass-count
18570
18571@c @subheading -trace-save
18572
18573@c @subheading -trace-start
18574
18575@c @subheading -trace-stop
18576
18577
18578@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
18579@node GDB/MI Variable Objects
18580@section @sc{gdb/mi} Variable Objects
18581
18582
18583@subheading Motivation for Variable Objects in @sc{gdb/mi}
18584
18585For the implementation of a variable debugger window (locals, watched
18586expressions, etc.), we are proposing the adaptation of the existing code
18587used by @code{Insight}.
18588
18589The two main reasons for that are:
18590
18591@enumerate 1
18592@item
18593It has been proven in practice (it is already on its second generation).
18594
18595@item
18596It will shorten development time (needless to say how important it is
18597now).
18598@end enumerate
18599
18600The original interface was designed to be used by Tcl code, so it was
18601slightly changed so it could be used through @sc{gdb/mi}. This section
18602describes the @sc{gdb/mi} operations that will be available and gives some
18603hints about their use.
18604
18605@emph{Note}: In addition to the set of operations described here, we
18606expect the @sc{gui} implementation of a variable window to require, at
18607least, the following operations:
18608
18609@itemize @bullet
18610@item @code{-gdb-show} @code{output-radix}
18611@item @code{-stack-list-arguments}
18612@item @code{-stack-list-locals}
18613@item @code{-stack-select-frame}
18614@end itemize
18615
18616@subheading Introduction to Variable Objects in @sc{gdb/mi}
18617
18618@cindex variable objects in @sc{gdb/mi}
18619The basic idea behind variable objects is the creation of a named object
18620to represent a variable, an expression, a memory location or even a CPU
18621register. For each object created, a set of operations is available for
18622examining or changing its properties.
18623
18624Furthermore, complex data types, such as C structures, are represented
18625in a tree format. For instance, the @code{struct} type variable is the
18626root and the children will represent the struct members. If a child
18627is itself of a complex type, it will also have children of its own.
18628Appropriate language differences are handled for C, C@t{++} and Java.
18629
18630When returning the actual values of the objects, this facility allows
18631for the individual selection of the display format used in the result
18632creation. It can be chosen among: binary, decimal, hexadecimal, octal
18633and natural. Natural refers to a default format automatically
18634chosen based on the variable type (like decimal for an @code{int}, hex
18635for pointers, etc.).
18636
18637The following is the complete set of @sc{gdb/mi} operations defined to
18638access this functionality:
18639
18640@multitable @columnfractions .4 .6
18641@item @strong{Operation}
18642@tab @strong{Description}
18643
18644@item @code{-var-create}
18645@tab create a variable object
18646@item @code{-var-delete}
18647@tab delete the variable object and its children
18648@item @code{-var-set-format}
18649@tab set the display format of this variable
18650@item @code{-var-show-format}
18651@tab show the display format of this variable
18652@item @code{-var-info-num-children}
18653@tab tells how many children this object has
18654@item @code{-var-list-children}
18655@tab return a list of the object's children
18656@item @code{-var-info-type}
18657@tab show the type of this variable object
18658@item @code{-var-info-expression}
18659@tab print what this variable object represents
18660@item @code{-var-show-attributes}
18661@tab is this variable editable? does it exist here?
18662@item @code{-var-evaluate-expression}
18663@tab get the value of this variable
18664@item @code{-var-assign}
18665@tab set the value of this variable
18666@item @code{-var-update}
18667@tab update the variable and its children
18668@end multitable
18669
18670In the next subsection we describe each operation in detail and suggest
18671how it can be used.
18672
18673@subheading Description And Use of Operations on Variable Objects
18674
18675@subheading The @code{-var-create} Command
18676@findex -var-create
18677
18678@subsubheading Synopsis
18679
18680@smallexample
18681 -var-create @{@var{name} | "-"@}
18682 @{@var{frame-addr} | "*"@} @var{expression}
18683@end smallexample
18684
18685This operation creates a variable object, which allows the monitoring of
18686a variable, the result of an expression, a memory cell or a CPU
18687register.
18688
18689The @var{name} parameter is the string by which the object can be
18690referenced. It must be unique. If @samp{-} is specified, the varobj
18691system will generate a string ``varNNNNNN'' automatically. It will be
18692unique provided that one does not specify @var{name} on that format.
18693The command fails if a duplicate name is found.
18694
18695The frame under which the expression should be evaluated can be
18696specified by @var{frame-addr}. A @samp{*} indicates that the current
18697frame should be used.
18698
18699@var{expression} is any expression valid on the current language set (must not
18700begin with a @samp{*}), or one of the following:
18701
18702@itemize @bullet
18703@item
18704@samp{*@var{addr}}, where @var{addr} is the address of a memory cell
18705
18706@item
18707@samp{*@var{addr}-@var{addr}} --- a memory address range (TBD)
18708
18709@item
18710@samp{$@var{regname}} --- a CPU register name
18711@end itemize
18712
18713@subsubheading Result
18714
18715This operation returns the name, number of children and the type of the
18716object created. Type is returned as a string as the ones generated by
18717the @value{GDBN} CLI:
18718
18719@smallexample
18720 name="@var{name}",numchild="N",type="@var{type}"
18721@end smallexample
18722
18723
18724@subheading The @code{-var-delete} Command
18725@findex -var-delete
18726
18727@subsubheading Synopsis
18728
18729@smallexample
18730 -var-delete @var{name}
18731@end smallexample
18732
18733Deletes a previously created variable object and all of its children.
18734
18735Returns an error if the object @var{name} is not found.
18736
18737
18738@subheading The @code{-var-set-format} Command
18739@findex -var-set-format
18740
18741@subsubheading Synopsis
18742
18743@smallexample
18744 -var-set-format @var{name} @var{format-spec}
18745@end smallexample
18746
18747Sets the output format for the value of the object @var{name} to be
18748@var{format-spec}.
18749
18750The syntax for the @var{format-spec} is as follows:
18751
18752@smallexample
18753 @var{format-spec} @expansion{}
18754 @{binary | decimal | hexadecimal | octal | natural@}
18755@end smallexample
18756
18757
18758@subheading The @code{-var-show-format} Command
18759@findex -var-show-format
18760
18761@subsubheading Synopsis
18762
18763@smallexample
18764 -var-show-format @var{name}
18765@end smallexample
18766
18767Returns the format used to display the value of the object @var{name}.
18768
18769@smallexample
18770 @var{format} @expansion{}
18771 @var{format-spec}
18772@end smallexample
18773
18774
18775@subheading The @code{-var-info-num-children} Command
18776@findex -var-info-num-children
18777
18778@subsubheading Synopsis
18779
18780@smallexample
18781 -var-info-num-children @var{name}
18782@end smallexample
18783
18784Returns the number of children of a variable object @var{name}:
18785
18786@smallexample
18787 numchild=@var{n}
18788@end smallexample
18789
18790
18791@subheading The @code{-var-list-children} Command
18792@findex -var-list-children
18793
18794@subsubheading Synopsis
18795
18796@smallexample
bc8ced35 18797 -var-list-children [@var{print-values}] @var{name}
922fbb7b
AC
18798@end smallexample
18799
bc8ced35
NR
18800Returns a list of the children of the specified variable object. With
18801just the variable object name as an argument or with an optional
18802preceding argument of 0 or @code{--no-values}, prints only the names of the
18803variables. With an optional preceding argument of 1 or @code{--all-values},
18804also prints their values.
18805
18806@subsubheading Example
922fbb7b
AC
18807
18808@smallexample
bc8ced35
NR
18809(@value{GDBP})
18810 -var-list-children n
922fbb7b
AC
18811 numchild=@var{n},children=[@{name=@var{name},
18812 numchild=@var{n},type=@var{type}@},@r{(repeats N times)}]
bc8ced35
NR
18813(@value{GDBP})
18814 -var-list-children --all-values n
18815 numchild=@var{n},children=[@{name=@var{name},
18816 numchild=@var{n},value=@var{value},type=@var{type}@},@r{(repeats N times)}]
922fbb7b
AC
18817@end smallexample
18818
18819
18820@subheading The @code{-var-info-type} Command
18821@findex -var-info-type
18822
18823@subsubheading Synopsis
18824
18825@smallexample
18826 -var-info-type @var{name}
18827@end smallexample
18828
18829Returns the type of the specified variable @var{name}. The type is
18830returned as a string in the same format as it is output by the
18831@value{GDBN} CLI:
18832
18833@smallexample
18834 type=@var{typename}
18835@end smallexample
18836
18837
18838@subheading The @code{-var-info-expression} Command
18839@findex -var-info-expression
18840
18841@subsubheading Synopsis
18842
18843@smallexample
18844 -var-info-expression @var{name}
18845@end smallexample
18846
18847Returns what is represented by the variable object @var{name}:
18848
18849@smallexample
18850 lang=@var{lang-spec},exp=@var{expression}
18851@end smallexample
18852
18853@noindent
18854where @var{lang-spec} is @code{@{"C" | "C++" | "Java"@}}.
18855
18856@subheading The @code{-var-show-attributes} Command
18857@findex -var-show-attributes
18858
18859@subsubheading Synopsis
18860
18861@smallexample
18862 -var-show-attributes @var{name}
18863@end smallexample
18864
18865List attributes of the specified variable object @var{name}:
18866
18867@smallexample
18868 status=@var{attr} [ ( ,@var{attr} )* ]
18869@end smallexample
18870
18871@noindent
18872where @var{attr} is @code{@{ @{ editable | noneditable @} | TBD @}}.
18873
18874@subheading The @code{-var-evaluate-expression} Command
18875@findex -var-evaluate-expression
18876
18877@subsubheading Synopsis
18878
18879@smallexample
18880 -var-evaluate-expression @var{name}
18881@end smallexample
18882
18883Evaluates the expression that is represented by the specified variable
18884object and returns its value as a string in the current format specified
18885for the object:
18886
18887@smallexample
18888 value=@var{value}
18889@end smallexample
18890
18891Note that one must invoke @code{-var-list-children} for a variable
18892before the value of a child variable can be evaluated.
18893
18894@subheading The @code{-var-assign} Command
18895@findex -var-assign
18896
18897@subsubheading Synopsis
18898
18899@smallexample
18900 -var-assign @var{name} @var{expression}
18901@end smallexample
18902
18903Assigns the value of @var{expression} to the variable object specified
18904by @var{name}. The object must be @samp{editable}. If the variable's
b383017d 18905value is altered by the assign, the variable will show up in any
922fbb7b
AC
18906subsequent @code{-var-update} list.
18907
18908@subsubheading Example
18909
18910@smallexample
18911(@value{GDBP})
18912-var-assign var1 3
18913^done,value="3"
18914(@value{GDBP})
18915-var-update *
18916^done,changelist=[@{name="var1",in_scope="true",type_changed="false"@}]
18917(@value{GDBP})
18918@end smallexample
18919
18920@subheading The @code{-var-update} Command
18921@findex -var-update
18922
18923@subsubheading Synopsis
18924
18925@smallexample
18926 -var-update @{@var{name} | "*"@}
18927@end smallexample
18928
18929Update the value of the variable object @var{name} by evaluating its
18930expression after fetching all the new values from memory or registers.
18931A @samp{*} causes all existing variable objects to be updated.
18932
18933
18934@node Annotations
18935@chapter @value{GDBN} Annotations
18936
086432e2
AC
18937This chapter describes annotations in @value{GDBN}. Annotations were
18938designed to interface @value{GDBN} to graphical user interfaces or other
18939similar programs which want to interact with @value{GDBN} at a
922fbb7b
AC
18940relatively high level.
18941
086432e2
AC
18942The annotation mechanism has largely been superseeded by @sc{gdb/mi}
18943(@pxref{GDB/MI}).
18944
922fbb7b
AC
18945@ignore
18946This is Edition @value{EDITION}, @value{DATE}.
18947@end ignore
18948
18949@menu
18950* Annotations Overview:: What annotations are; the general syntax.
18951* Server Prefix:: Issuing a command without affecting user state.
922fbb7b
AC
18952* Prompting:: Annotations marking @value{GDBN}'s need for input.
18953* Errors:: Annotations for error messages.
922fbb7b
AC
18954* Invalidation:: Some annotations describe things now invalid.
18955* Annotations for Running::
18956 Whether the program is running, how it stopped, etc.
18957* Source Annotations:: Annotations describing source code.
922fbb7b
AC
18958@end menu
18959
18960@node Annotations Overview
18961@section What is an Annotation?
18962@cindex annotations
18963
922fbb7b
AC
18964Annotations start with a newline character, two @samp{control-z}
18965characters, and the name of the annotation. If there is no additional
18966information associated with this annotation, the name of the annotation
18967is followed immediately by a newline. If there is additional
18968information, the name of the annotation is followed by a space, the
18969additional information, and a newline. The additional information
18970cannot contain newline characters.
18971
18972Any output not beginning with a newline and two @samp{control-z}
18973characters denotes literal output from @value{GDBN}. Currently there is
18974no need for @value{GDBN} to output a newline followed by two
18975@samp{control-z} characters, but if there was such a need, the
18976annotations could be extended with an @samp{escape} annotation which
18977means those three characters as output.
18978
086432e2
AC
18979The annotation @var{level}, which is specified using the
18980@option{--annotate} command line option (@pxref{Mode Options}), controls
18981how much information @value{GDBN} prints together with its prompt,
18982values of expressions, source lines, and other types of output. Level 0
18983is for no anntations, level 1 is for use when @value{GDBN} is run as a
18984subprocess of @sc{gnu} Emacs, level 3 is the maximum annotation suitable
18985for programs that control @value{GDBN}, and level 2 annotations have
18986been made obsolete (@pxref{Limitations, , Limitations of the Annotation
18987Interface, annotate, GDB's Obsolete Annotations}). This chapter
18988describes level 3 annotations.
18989
922fbb7b
AC
18990A simple example of starting up @value{GDBN} with annotations is:
18991
18992@smallexample
086432e2
AC
18993$ @kbd{gdb --annotate=3}
18994GNU gdb 6.0
18995Copyright 2003 Free Software Foundation, Inc.
922fbb7b
AC
18996GDB is free software, covered by the GNU General Public License,
18997and you are welcome to change it and/or distribute copies of it
18998under certain conditions.
18999Type "show copying" to see the conditions.
19000There is absolutely no warranty for GDB. Type "show warranty"
19001for details.
086432e2 19002This GDB was configured as "i386-pc-linux-gnu"
922fbb7b
AC
19003
19004^Z^Zpre-prompt
f7dc1244 19005(@value{GDBP})
922fbb7b 19006^Z^Zprompt
086432e2 19007@kbd{quit}
922fbb7b
AC
19008
19009^Z^Zpost-prompt
b383017d 19010$
922fbb7b
AC
19011@end smallexample
19012
19013Here @samp{quit} is input to @value{GDBN}; the rest is output from
19014@value{GDBN}. The three lines beginning @samp{^Z^Z} (where @samp{^Z}
19015denotes a @samp{control-z} character) are annotations; the rest is
19016output from @value{GDBN}.
19017
19018@node Server Prefix
19019@section The Server Prefix
19020@cindex server prefix for annotations
19021
19022To issue a command to @value{GDBN} without affecting certain aspects of
19023the state which is seen by users, prefix it with @samp{server }. This
19024means that this command will not affect the command history, nor will it
19025affect @value{GDBN}'s notion of which command to repeat if @key{RET} is
19026pressed on a line by itself.
19027
19028The server prefix does not affect the recording of values into the value
19029history; to print a value without recording it into the value history,
19030use the @code{output} command instead of the @code{print} command.
19031
922fbb7b
AC
19032@node Prompting
19033@section Annotation for @value{GDBN} Input
19034
19035@cindex annotations for prompts
19036When @value{GDBN} prompts for input, it annotates this fact so it is possible
19037to know when to send output, when the output from a given command is
19038over, etc.
19039
19040Different kinds of input each have a different @dfn{input type}. Each
19041input type has three annotations: a @code{pre-} annotation, which
19042denotes the beginning of any prompt which is being output, a plain
19043annotation, which denotes the end of the prompt, and then a @code{post-}
19044annotation which denotes the end of any echo which may (or may not) be
19045associated with the input. For example, the @code{prompt} input type
19046features the following annotations:
19047
19048@smallexample
19049^Z^Zpre-prompt
19050^Z^Zprompt
19051^Z^Zpost-prompt
19052@end smallexample
19053
19054The input types are
19055
19056@table @code
19057@findex pre-prompt
19058@findex prompt
19059@findex post-prompt
19060@item prompt
19061When @value{GDBN} is prompting for a command (the main @value{GDBN} prompt).
19062
19063@findex pre-commands
19064@findex commands
19065@findex post-commands
19066@item commands
19067When @value{GDBN} prompts for a set of commands, like in the @code{commands}
19068command. The annotations are repeated for each command which is input.
19069
19070@findex pre-overload-choice
19071@findex overload-choice
19072@findex post-overload-choice
19073@item overload-choice
19074When @value{GDBN} wants the user to select between various overloaded functions.
19075
19076@findex pre-query
19077@findex query
19078@findex post-query
19079@item query
19080When @value{GDBN} wants the user to confirm a potentially dangerous operation.
19081
19082@findex pre-prompt-for-continue
19083@findex prompt-for-continue
19084@findex post-prompt-for-continue
19085@item prompt-for-continue
19086When @value{GDBN} is asking the user to press return to continue. Note: Don't
19087expect this to work well; instead use @code{set height 0} to disable
19088prompting. This is because the counting of lines is buggy in the
19089presence of annotations.
19090@end table
19091
19092@node Errors
19093@section Errors
19094@cindex annotations for errors, warnings and interrupts
19095
19096@findex quit
19097@smallexample
19098^Z^Zquit
19099@end smallexample
19100
19101This annotation occurs right before @value{GDBN} responds to an interrupt.
19102
19103@findex error
19104@smallexample
19105^Z^Zerror
19106@end smallexample
19107
19108This annotation occurs right before @value{GDBN} responds to an error.
19109
19110Quit and error annotations indicate that any annotations which @value{GDBN} was
19111in the middle of may end abruptly. For example, if a
19112@code{value-history-begin} annotation is followed by a @code{error}, one
19113cannot expect to receive the matching @code{value-history-end}. One
19114cannot expect not to receive it either, however; an error annotation
19115does not necessarily mean that @value{GDBN} is immediately returning all the way
19116to the top level.
19117
19118@findex error-begin
19119A quit or error annotation may be preceded by
19120
19121@smallexample
19122^Z^Zerror-begin
19123@end smallexample
19124
19125Any output between that and the quit or error annotation is the error
19126message.
19127
19128Warning messages are not yet annotated.
19129@c If we want to change that, need to fix warning(), type_error(),
19130@c range_error(), and possibly other places.
19131
922fbb7b
AC
19132@node Invalidation
19133@section Invalidation Notices
19134
19135@cindex annotations for invalidation messages
19136The following annotations say that certain pieces of state may have
19137changed.
19138
19139@table @code
19140@findex frames-invalid
19141@item ^Z^Zframes-invalid
19142
19143The frames (for example, output from the @code{backtrace} command) may
19144have changed.
19145
19146@findex breakpoints-invalid
19147@item ^Z^Zbreakpoints-invalid
19148
19149The breakpoints may have changed. For example, the user just added or
19150deleted a breakpoint.
19151@end table
19152
19153@node Annotations for Running
19154@section Running the Program
19155@cindex annotations for running programs
19156
19157@findex starting
19158@findex stopping
19159When the program starts executing due to a @value{GDBN} command such as
b383017d 19160@code{step} or @code{continue},
922fbb7b
AC
19161
19162@smallexample
19163^Z^Zstarting
19164@end smallexample
19165
b383017d 19166is output. When the program stops,
922fbb7b
AC
19167
19168@smallexample
19169^Z^Zstopped
19170@end smallexample
19171
19172is output. Before the @code{stopped} annotation, a variety of
19173annotations describe how the program stopped.
19174
19175@table @code
19176@findex exited
19177@item ^Z^Zexited @var{exit-status}
19178The program exited, and @var{exit-status} is the exit status (zero for
19179successful exit, otherwise nonzero).
19180
19181@findex signalled
19182@findex signal-name
19183@findex signal-name-end
19184@findex signal-string
19185@findex signal-string-end
19186@item ^Z^Zsignalled
19187The program exited with a signal. After the @code{^Z^Zsignalled}, the
19188annotation continues:
19189
19190@smallexample
19191@var{intro-text}
19192^Z^Zsignal-name
19193@var{name}
19194^Z^Zsignal-name-end
19195@var{middle-text}
19196^Z^Zsignal-string
19197@var{string}
19198^Z^Zsignal-string-end
19199@var{end-text}
19200@end smallexample
19201
19202@noindent
19203where @var{name} is the name of the signal, such as @code{SIGILL} or
19204@code{SIGSEGV}, and @var{string} is the explanation of the signal, such
19205as @code{Illegal Instruction} or @code{Segmentation fault}.
19206@var{intro-text}, @var{middle-text}, and @var{end-text} are for the
19207user's benefit and have no particular format.
19208
19209@findex signal
19210@item ^Z^Zsignal
19211The syntax of this annotation is just like @code{signalled}, but @value{GDBN} is
19212just saying that the program received the signal, not that it was
19213terminated with it.
19214
19215@findex breakpoint
19216@item ^Z^Zbreakpoint @var{number}
19217The program hit breakpoint number @var{number}.
19218
19219@findex watchpoint
19220@item ^Z^Zwatchpoint @var{number}
19221The program hit watchpoint number @var{number}.
19222@end table
19223
19224@node Source Annotations
19225@section Displaying Source
19226@cindex annotations for source display
19227
19228@findex source
19229The following annotation is used instead of displaying source code:
19230
19231@smallexample
19232^Z^Zsource @var{filename}:@var{line}:@var{character}:@var{middle}:@var{addr}
19233@end smallexample
19234
19235where @var{filename} is an absolute file name indicating which source
19236file, @var{line} is the line number within that file (where 1 is the
19237first line in the file), @var{character} is the character position
19238within the file (where 0 is the first character in the file) (for most
19239debug formats this will necessarily point to the beginning of a line),
19240@var{middle} is @samp{middle} if @var{addr} is in the middle of the
19241line, or @samp{beg} if @var{addr} is at the beginning of the line, and
19242@var{addr} is the address in the target program associated with the
19243source which is being displayed. @var{addr} is in the form @samp{0x}
19244followed by one or more lowercase hex digits (note that this does not
19245depend on the language).
19246
8e04817f
AC
19247@node GDB Bugs
19248@chapter Reporting Bugs in @value{GDBN}
19249@cindex bugs in @value{GDBN}
19250@cindex reporting bugs in @value{GDBN}
c906108c 19251
8e04817f 19252Your bug reports play an essential role in making @value{GDBN} reliable.
c906108c 19253
8e04817f
AC
19254Reporting a bug may help you by bringing a solution to your problem, or it
19255may not. But in any case the principal function of a bug report is to help
19256the entire community by making the next version of @value{GDBN} work better. Bug
19257reports are your contribution to the maintenance of @value{GDBN}.
c906108c 19258
8e04817f
AC
19259In order for a bug report to serve its purpose, you must include the
19260information that enables us to fix the bug.
c4555f82
SC
19261
19262@menu
8e04817f
AC
19263* Bug Criteria:: Have you found a bug?
19264* Bug Reporting:: How to report bugs
c4555f82
SC
19265@end menu
19266
8e04817f
AC
19267@node Bug Criteria
19268@section Have you found a bug?
19269@cindex bug criteria
c4555f82 19270
8e04817f 19271If you are not sure whether you have found a bug, here are some guidelines:
c4555f82
SC
19272
19273@itemize @bullet
8e04817f
AC
19274@cindex fatal signal
19275@cindex debugger crash
19276@cindex crash of debugger
c4555f82 19277@item
8e04817f
AC
19278If the debugger gets a fatal signal, for any input whatever, that is a
19279@value{GDBN} bug. Reliable debuggers never crash.
19280
19281@cindex error on valid input
19282@item
19283If @value{GDBN} produces an error message for valid input, that is a
19284bug. (Note that if you're cross debugging, the problem may also be
19285somewhere in the connection to the target.)
c4555f82 19286
8e04817f 19287@cindex invalid input
c4555f82 19288@item
8e04817f
AC
19289If @value{GDBN} does not produce an error message for invalid input,
19290that is a bug. However, you should note that your idea of
19291``invalid input'' might be our idea of ``an extension'' or ``support
19292for traditional practice''.
19293
19294@item
19295If you are an experienced user of debugging tools, your suggestions
19296for improvement of @value{GDBN} are welcome in any case.
c4555f82
SC
19297@end itemize
19298
8e04817f
AC
19299@node Bug Reporting
19300@section How to report bugs
19301@cindex bug reports
19302@cindex @value{GDBN} bugs, reporting
19303
19304A number of companies and individuals offer support for @sc{gnu} products.
19305If you obtained @value{GDBN} from a support organization, we recommend you
19306contact that organization first.
19307
19308You can find contact information for many support companies and
19309individuals in the file @file{etc/SERVICE} in the @sc{gnu} Emacs
19310distribution.
19311@c should add a web page ref...
19312
129188f6
AC
19313In any event, we also recommend that you submit bug reports for
19314@value{GDBN}. The prefered method is to submit them directly using
19315@uref{http://www.gnu.org/software/gdb/bugs/, @value{GDBN}'s Bugs web
19316page}. Alternatively, the @email{bug-gdb@@gnu.org, e-mail gateway} can
19317be used.
8e04817f
AC
19318
19319@strong{Do not send bug reports to @samp{info-gdb}, or to
19320@samp{help-gdb}, or to any newsgroups.} Most users of @value{GDBN} do
19321not want to receive bug reports. Those that do have arranged to receive
19322@samp{bug-gdb}.
19323
19324The mailing list @samp{bug-gdb} has a newsgroup @samp{gnu.gdb.bug} which
19325serves as a repeater. The mailing list and the newsgroup carry exactly
19326the same messages. Often people think of posting bug reports to the
19327newsgroup instead of mailing them. This appears to work, but it has one
19328problem which can be crucial: a newsgroup posting often lacks a mail
19329path back to the sender. Thus, if we need to ask for more information,
19330we may be unable to reach you. For this reason, it is better to send
19331bug reports to the mailing list.
c4555f82 19332
8e04817f
AC
19333The fundamental principle of reporting bugs usefully is this:
19334@strong{report all the facts}. If you are not sure whether to state a
19335fact or leave it out, state it!
c4555f82 19336
8e04817f
AC
19337Often people omit facts because they think they know what causes the
19338problem and assume that some details do not matter. Thus, you might
19339assume that the name of the variable you use in an example does not matter.
19340Well, probably it does not, but one cannot be sure. Perhaps the bug is a
19341stray memory reference which happens to fetch from the location where that
19342name is stored in memory; perhaps, if the name were different, the contents
19343of that location would fool the debugger into doing the right thing despite
19344the bug. Play it safe and give a specific, complete example. That is the
19345easiest thing for you to do, and the most helpful.
c4555f82 19346
8e04817f
AC
19347Keep in mind that the purpose of a bug report is to enable us to fix the
19348bug. It may be that the bug has been reported previously, but neither
19349you nor we can know that unless your bug report is complete and
19350self-contained.
c4555f82 19351
8e04817f
AC
19352Sometimes people give a few sketchy facts and ask, ``Does this ring a
19353bell?'' Those bug reports are useless, and we urge everyone to
19354@emph{refuse to respond to them} except to chide the sender to report
19355bugs properly.
19356
19357To enable us to fix the bug, you should include all these things:
c4555f82
SC
19358
19359@itemize @bullet
19360@item
8e04817f
AC
19361The version of @value{GDBN}. @value{GDBN} announces it if you start
19362with no arguments; you can also print it at any time using @code{show
19363version}.
c4555f82 19364
8e04817f
AC
19365Without this, we will not know whether there is any point in looking for
19366the bug in the current version of @value{GDBN}.
c4555f82
SC
19367
19368@item
8e04817f
AC
19369The type of machine you are using, and the operating system name and
19370version number.
c4555f82
SC
19371
19372@item
8e04817f
AC
19373What compiler (and its version) was used to compile @value{GDBN}---e.g.
19374``@value{GCC}--2.8.1''.
c4555f82
SC
19375
19376@item
8e04817f
AC
19377What compiler (and its version) was used to compile the program you are
19378debugging---e.g. ``@value{GCC}--2.8.1'', or ``HP92453-01 A.10.32.03 HP
19379C Compiler''. For GCC, you can say @code{gcc --version} to get this
19380information; for other compilers, see the documentation for those
19381compilers.
c4555f82 19382
8e04817f
AC
19383@item
19384The command arguments you gave the compiler to compile your example and
19385observe the bug. For example, did you use @samp{-O}? To guarantee
19386you will not omit something important, list them all. A copy of the
19387Makefile (or the output from make) is sufficient.
c4555f82 19388
8e04817f
AC
19389If we were to try to guess the arguments, we would probably guess wrong
19390and then we might not encounter the bug.
c4555f82 19391
8e04817f
AC
19392@item
19393A complete input script, and all necessary source files, that will
19394reproduce the bug.
c4555f82 19395
8e04817f
AC
19396@item
19397A description of what behavior you observe that you believe is
19398incorrect. For example, ``It gets a fatal signal.''
c4555f82 19399
8e04817f
AC
19400Of course, if the bug is that @value{GDBN} gets a fatal signal, then we
19401will certainly notice it. But if the bug is incorrect output, we might
19402not notice unless it is glaringly wrong. You might as well not give us
19403a chance to make a mistake.
c4555f82 19404
8e04817f
AC
19405Even if the problem you experience is a fatal signal, you should still
19406say so explicitly. Suppose something strange is going on, such as, your
19407copy of @value{GDBN} is out of synch, or you have encountered a bug in
19408the C library on your system. (This has happened!) Your copy might
19409crash and ours would not. If you told us to expect a crash, then when
19410ours fails to crash, we would know that the bug was not happening for
19411us. If you had not told us to expect a crash, then we would not be able
19412to draw any conclusion from our observations.
c4555f82 19413
e0c07bf0
MC
19414@pindex script
19415@cindex recording a session script
19416To collect all this information, you can use a session recording program
19417such as @command{script}, which is available on many Unix systems.
19418Just run your @value{GDBN} session inside @command{script} and then
19419include the @file{typescript} file with your bug report.
19420
19421Another way to record a @value{GDBN} session is to run @value{GDBN}
19422inside Emacs and then save the entire buffer to a file.
19423
8e04817f
AC
19424@item
19425If you wish to suggest changes to the @value{GDBN} source, send us context
19426diffs. If you even discuss something in the @value{GDBN} source, refer to
19427it by context, not by line number.
c4555f82 19428
8e04817f
AC
19429The line numbers in our development sources will not match those in your
19430sources. Your line numbers would convey no useful information to us.
c4555f82 19431
8e04817f 19432@end itemize
c4555f82 19433
8e04817f 19434Here are some things that are not necessary:
c4555f82 19435
8e04817f
AC
19436@itemize @bullet
19437@item
19438A description of the envelope of the bug.
c4555f82 19439
8e04817f
AC
19440Often people who encounter a bug spend a lot of time investigating
19441which changes to the input file will make the bug go away and which
19442changes will not affect it.
c4555f82 19443
8e04817f
AC
19444This is often time consuming and not very useful, because the way we
19445will find the bug is by running a single example under the debugger
19446with breakpoints, not by pure deduction from a series of examples.
19447We recommend that you save your time for something else.
c4555f82 19448
8e04817f
AC
19449Of course, if you can find a simpler example to report @emph{instead}
19450of the original one, that is a convenience for us. Errors in the
19451output will be easier to spot, running under the debugger will take
19452less time, and so on.
c4555f82 19453
8e04817f
AC
19454However, simplification is not vital; if you do not want to do this,
19455report the bug anyway and send us the entire test case you used.
c4555f82 19456
8e04817f
AC
19457@item
19458A patch for the bug.
c4555f82 19459
8e04817f
AC
19460A patch for the bug does help us if it is a good one. But do not omit
19461the necessary information, such as the test case, on the assumption that
19462a patch is all we need. We might see problems with your patch and decide
19463to fix the problem another way, or we might not understand it at all.
c4555f82 19464
8e04817f
AC
19465Sometimes with a program as complicated as @value{GDBN} it is very hard to
19466construct an example that will make the program follow a certain path
19467through the code. If you do not send us the example, we will not be able
19468to construct one, so we will not be able to verify that the bug is fixed.
c4555f82 19469
8e04817f
AC
19470And if we cannot understand what bug you are trying to fix, or why your
19471patch should be an improvement, we will not install it. A test case will
19472help us to understand.
c4555f82 19473
8e04817f
AC
19474@item
19475A guess about what the bug is or what it depends on.
c4555f82 19476
8e04817f
AC
19477Such guesses are usually wrong. Even we cannot guess right about such
19478things without first using the debugger to find the facts.
19479@end itemize
c4555f82 19480
8e04817f
AC
19481@c The readline documentation is distributed with the readline code
19482@c and consists of the two following files:
19483@c rluser.texinfo
19484@c inc-hist.texinfo
19485@c Use -I with makeinfo to point to the appropriate directory,
19486@c environment var TEXINPUTS with TeX.
19487@include rluser.texinfo
19488@include inc-hist.texinfo
c4555f82 19489
c4555f82 19490
8e04817f
AC
19491@node Formatting Documentation
19492@appendix Formatting Documentation
c4555f82 19493
8e04817f
AC
19494@cindex @value{GDBN} reference card
19495@cindex reference card
19496The @value{GDBN} 4 release includes an already-formatted reference card, ready
19497for printing with PostScript or Ghostscript, in the @file{gdb}
19498subdirectory of the main source directory@footnote{In
19499@file{gdb-@value{GDBVN}/gdb/refcard.ps} of the version @value{GDBVN}
19500release.}. If you can use PostScript or Ghostscript with your printer,
19501you can print the reference card immediately with @file{refcard.ps}.
c4555f82 19502
8e04817f
AC
19503The release also includes the source for the reference card. You
19504can format it, using @TeX{}, by typing:
c4555f82 19505
474c8240 19506@smallexample
8e04817f 19507make refcard.dvi
474c8240 19508@end smallexample
c4555f82 19509
8e04817f
AC
19510The @value{GDBN} reference card is designed to print in @dfn{landscape}
19511mode on US ``letter'' size paper;
19512that is, on a sheet 11 inches wide by 8.5 inches
19513high. You will need to specify this form of printing as an option to
19514your @sc{dvi} output program.
c4555f82 19515
8e04817f 19516@cindex documentation
c4555f82 19517
8e04817f
AC
19518All the documentation for @value{GDBN} comes as part of the machine-readable
19519distribution. The documentation is written in Texinfo format, which is
19520a documentation system that uses a single source file to produce both
19521on-line information and a printed manual. You can use one of the Info
19522formatting commands to create the on-line version of the documentation
19523and @TeX{} (or @code{texi2roff}) to typeset the printed version.
c4555f82 19524
8e04817f
AC
19525@value{GDBN} includes an already formatted copy of the on-line Info
19526version of this manual in the @file{gdb} subdirectory. The main Info
19527file is @file{gdb-@value{GDBVN}/gdb/gdb.info}, and it refers to
19528subordinate files matching @samp{gdb.info*} in the same directory. If
19529necessary, you can print out these files, or read them with any editor;
19530but they are easier to read using the @code{info} subsystem in @sc{gnu}
19531Emacs or the standalone @code{info} program, available as part of the
19532@sc{gnu} Texinfo distribution.
c4555f82 19533
8e04817f
AC
19534If you want to format these Info files yourself, you need one of the
19535Info formatting programs, such as @code{texinfo-format-buffer} or
19536@code{makeinfo}.
c4555f82 19537
8e04817f
AC
19538If you have @code{makeinfo} installed, and are in the top level
19539@value{GDBN} source directory (@file{gdb-@value{GDBVN}}, in the case of
19540version @value{GDBVN}), you can make the Info file by typing:
c4555f82 19541
474c8240 19542@smallexample
8e04817f
AC
19543cd gdb
19544make gdb.info
474c8240 19545@end smallexample
c4555f82 19546
8e04817f
AC
19547If you want to typeset and print copies of this manual, you need @TeX{},
19548a program to print its @sc{dvi} output files, and @file{texinfo.tex}, the
19549Texinfo definitions file.
c4555f82 19550
8e04817f
AC
19551@TeX{} is a typesetting program; it does not print files directly, but
19552produces output files called @sc{dvi} files. To print a typeset
19553document, you need a program to print @sc{dvi} files. If your system
19554has @TeX{} installed, chances are it has such a program. The precise
19555command to use depends on your system; @kbd{lpr -d} is common; another
19556(for PostScript devices) is @kbd{dvips}. The @sc{dvi} print command may
19557require a file name without any extension or a @samp{.dvi} extension.
c4555f82 19558
8e04817f
AC
19559@TeX{} also requires a macro definitions file called
19560@file{texinfo.tex}. This file tells @TeX{} how to typeset a document
19561written in Texinfo format. On its own, @TeX{} cannot either read or
19562typeset a Texinfo file. @file{texinfo.tex} is distributed with GDB
19563and is located in the @file{gdb-@var{version-number}/texinfo}
19564directory.
c4555f82 19565
8e04817f
AC
19566If you have @TeX{} and a @sc{dvi} printer program installed, you can
19567typeset and print this manual. First switch to the the @file{gdb}
19568subdirectory of the main source directory (for example, to
19569@file{gdb-@value{GDBVN}/gdb}) and type:
c4555f82 19570
474c8240 19571@smallexample
8e04817f 19572make gdb.dvi
474c8240 19573@end smallexample
c4555f82 19574
8e04817f 19575Then give @file{gdb.dvi} to your @sc{dvi} printing program.
c4555f82 19576
8e04817f
AC
19577@node Installing GDB
19578@appendix Installing @value{GDBN}
19579@cindex configuring @value{GDBN}
19580@cindex installation
94e91d6d 19581@cindex configuring @value{GDBN}, and source tree subdirectories
c4555f82 19582
8e04817f
AC
19583@value{GDBN} comes with a @code{configure} script that automates the process
19584of preparing @value{GDBN} for installation; you can then use @code{make} to
19585build the @code{gdb} program.
19586@iftex
19587@c irrelevant in info file; it's as current as the code it lives with.
19588@footnote{If you have a more recent version of @value{GDBN} than @value{GDBVN},
19589look at the @file{README} file in the sources; we may have improved the
19590installation procedures since publishing this manual.}
19591@end iftex
c4555f82 19592
8e04817f
AC
19593The @value{GDBN} distribution includes all the source code you need for
19594@value{GDBN} in a single directory, whose name is usually composed by
19595appending the version number to @samp{gdb}.
c4555f82 19596
8e04817f
AC
19597For example, the @value{GDBN} version @value{GDBVN} distribution is in the
19598@file{gdb-@value{GDBVN}} directory. That directory contains:
c4555f82 19599
8e04817f
AC
19600@table @code
19601@item gdb-@value{GDBVN}/configure @r{(and supporting files)}
19602script for configuring @value{GDBN} and all its supporting libraries
c4555f82 19603
8e04817f
AC
19604@item gdb-@value{GDBVN}/gdb
19605the source specific to @value{GDBN} itself
c4555f82 19606
8e04817f
AC
19607@item gdb-@value{GDBVN}/bfd
19608source for the Binary File Descriptor library
c906108c 19609
8e04817f
AC
19610@item gdb-@value{GDBVN}/include
19611@sc{gnu} include files
c906108c 19612
8e04817f
AC
19613@item gdb-@value{GDBVN}/libiberty
19614source for the @samp{-liberty} free software library
c906108c 19615
8e04817f
AC
19616@item gdb-@value{GDBVN}/opcodes
19617source for the library of opcode tables and disassemblers
c906108c 19618
8e04817f
AC
19619@item gdb-@value{GDBVN}/readline
19620source for the @sc{gnu} command-line interface
c906108c 19621
8e04817f
AC
19622@item gdb-@value{GDBVN}/glob
19623source for the @sc{gnu} filename pattern-matching subroutine
c906108c 19624
8e04817f
AC
19625@item gdb-@value{GDBVN}/mmalloc
19626source for the @sc{gnu} memory-mapped malloc package
19627@end table
c906108c 19628
8e04817f
AC
19629The simplest way to configure and build @value{GDBN} is to run @code{configure}
19630from the @file{gdb-@var{version-number}} source directory, which in
19631this example is the @file{gdb-@value{GDBVN}} directory.
c906108c 19632
8e04817f
AC
19633First switch to the @file{gdb-@var{version-number}} source directory
19634if you are not already in it; then run @code{configure}. Pass the
19635identifier for the platform on which @value{GDBN} will run as an
19636argument.
c906108c 19637
8e04817f 19638For example:
c906108c 19639
474c8240 19640@smallexample
8e04817f
AC
19641cd gdb-@value{GDBVN}
19642./configure @var{host}
19643make
474c8240 19644@end smallexample
c906108c 19645
8e04817f
AC
19646@noindent
19647where @var{host} is an identifier such as @samp{sun4} or
19648@samp{decstation}, that identifies the platform where @value{GDBN} will run.
19649(You can often leave off @var{host}; @code{configure} tries to guess the
19650correct value by examining your system.)
c906108c 19651
8e04817f
AC
19652Running @samp{configure @var{host}} and then running @code{make} builds the
19653@file{bfd}, @file{readline}, @file{mmalloc}, and @file{libiberty}
19654libraries, then @code{gdb} itself. The configured source files, and the
19655binaries, are left in the corresponding source directories.
c906108c 19656
8e04817f
AC
19657@need 750
19658@code{configure} is a Bourne-shell (@code{/bin/sh}) script; if your
19659system does not recognize this automatically when you run a different
19660shell, you may need to run @code{sh} on it explicitly:
c906108c 19661
474c8240 19662@smallexample
8e04817f 19663sh configure @var{host}
474c8240 19664@end smallexample
c906108c 19665
8e04817f
AC
19666If you run @code{configure} from a directory that contains source
19667directories for multiple libraries or programs, such as the
19668@file{gdb-@value{GDBVN}} source directory for version @value{GDBVN}, @code{configure}
19669creates configuration files for every directory level underneath (unless
19670you tell it not to, with the @samp{--norecursion} option).
19671
94e91d6d
MC
19672You should run the @code{configure} script from the top directory in the
19673source tree, the @file{gdb-@var{version-number}} directory. If you run
19674@code{configure} from one of the subdirectories, you will configure only
19675that subdirectory. That is usually not what you want. In particular,
19676if you run the first @code{configure} from the @file{gdb} subdirectory
19677of the @file{gdb-@var{version-number}} directory, you will omit the
19678configuration of @file{bfd}, @file{readline}, and other sibling
19679directories of the @file{gdb} subdirectory. This leads to build errors
19680about missing include files such as @file{bfd/bfd.h}.
c906108c 19681
8e04817f
AC
19682You can install @code{@value{GDBP}} anywhere; it has no hardwired paths.
19683However, you should make sure that the shell on your path (named by
19684the @samp{SHELL} environment variable) is publicly readable. Remember
19685that @value{GDBN} uses the shell to start your program---some systems refuse to
19686let @value{GDBN} debug child processes whose programs are not readable.
c906108c 19687
8e04817f
AC
19688@menu
19689* Separate Objdir:: Compiling @value{GDBN} in another directory
19690* Config Names:: Specifying names for hosts and targets
19691* Configure Options:: Summary of options for configure
19692@end menu
c906108c 19693
8e04817f
AC
19694@node Separate Objdir
19695@section Compiling @value{GDBN} in another directory
c906108c 19696
8e04817f
AC
19697If you want to run @value{GDBN} versions for several host or target machines,
19698you need a different @code{gdb} compiled for each combination of
19699host and target. @code{configure} is designed to make this easy by
19700allowing you to generate each configuration in a separate subdirectory,
19701rather than in the source directory. If your @code{make} program
19702handles the @samp{VPATH} feature (@sc{gnu} @code{make} does), running
19703@code{make} in each of these directories builds the @code{gdb}
19704program specified there.
c906108c 19705
8e04817f
AC
19706To build @code{gdb} in a separate directory, run @code{configure}
19707with the @samp{--srcdir} option to specify where to find the source.
19708(You also need to specify a path to find @code{configure}
19709itself from your working directory. If the path to @code{configure}
19710would be the same as the argument to @samp{--srcdir}, you can leave out
19711the @samp{--srcdir} option; it is assumed.)
c906108c 19712
8e04817f
AC
19713For example, with version @value{GDBVN}, you can build @value{GDBN} in a
19714separate directory for a Sun 4 like this:
c906108c 19715
474c8240 19716@smallexample
8e04817f
AC
19717@group
19718cd gdb-@value{GDBVN}
19719mkdir ../gdb-sun4
19720cd ../gdb-sun4
19721../gdb-@value{GDBVN}/configure sun4
19722make
19723@end group
474c8240 19724@end smallexample
c906108c 19725
8e04817f
AC
19726When @code{configure} builds a configuration using a remote source
19727directory, it creates a tree for the binaries with the same structure
19728(and using the same names) as the tree under the source directory. In
19729the example, you'd find the Sun 4 library @file{libiberty.a} in the
19730directory @file{gdb-sun4/libiberty}, and @value{GDBN} itself in
19731@file{gdb-sun4/gdb}.
c906108c 19732
94e91d6d
MC
19733Make sure that your path to the @file{configure} script has just one
19734instance of @file{gdb} in it. If your path to @file{configure} looks
19735like @file{../gdb-@value{GDBVN}/gdb/configure}, you are configuring only
19736one subdirectory of @value{GDBN}, not the whole package. This leads to
19737build errors about missing include files such as @file{bfd/bfd.h}.
19738
8e04817f
AC
19739One popular reason to build several @value{GDBN} configurations in separate
19740directories is to configure @value{GDBN} for cross-compiling (where
19741@value{GDBN} runs on one machine---the @dfn{host}---while debugging
19742programs that run on another machine---the @dfn{target}).
19743You specify a cross-debugging target by
19744giving the @samp{--target=@var{target}} option to @code{configure}.
c906108c 19745
8e04817f
AC
19746When you run @code{make} to build a program or library, you must run
19747it in a configured directory---whatever directory you were in when you
19748called @code{configure} (or one of its subdirectories).
c906108c 19749
8e04817f
AC
19750The @code{Makefile} that @code{configure} generates in each source
19751directory also runs recursively. If you type @code{make} in a source
19752directory such as @file{gdb-@value{GDBVN}} (or in a separate configured
19753directory configured with @samp{--srcdir=@var{dirname}/gdb-@value{GDBVN}}), you
19754will build all the required libraries, and then build GDB.
c906108c 19755
8e04817f
AC
19756When you have multiple hosts or targets configured in separate
19757directories, you can run @code{make} on them in parallel (for example,
19758if they are NFS-mounted on each of the hosts); they will not interfere
19759with each other.
c906108c 19760
8e04817f
AC
19761@node Config Names
19762@section Specifying names for hosts and targets
c906108c 19763
8e04817f
AC
19764The specifications used for hosts and targets in the @code{configure}
19765script are based on a three-part naming scheme, but some short predefined
19766aliases are also supported. The full naming scheme encodes three pieces
19767of information in the following pattern:
c906108c 19768
474c8240 19769@smallexample
8e04817f 19770@var{architecture}-@var{vendor}-@var{os}
474c8240 19771@end smallexample
c906108c 19772
8e04817f
AC
19773For example, you can use the alias @code{sun4} as a @var{host} argument,
19774or as the value for @var{target} in a @code{--target=@var{target}}
19775option. The equivalent full name is @samp{sparc-sun-sunos4}.
c906108c 19776
8e04817f
AC
19777The @code{configure} script accompanying @value{GDBN} does not provide
19778any query facility to list all supported host and target names or
19779aliases. @code{configure} calls the Bourne shell script
19780@code{config.sub} to map abbreviations to full names; you can read the
19781script, if you wish, or you can use it to test your guesses on
19782abbreviations---for example:
c906108c 19783
8e04817f
AC
19784@smallexample
19785% sh config.sub i386-linux
19786i386-pc-linux-gnu
19787% sh config.sub alpha-linux
19788alpha-unknown-linux-gnu
19789% sh config.sub hp9k700
19790hppa1.1-hp-hpux
19791% sh config.sub sun4
19792sparc-sun-sunos4.1.1
19793% sh config.sub sun3
19794m68k-sun-sunos4.1.1
19795% sh config.sub i986v
19796Invalid configuration `i986v': machine `i986v' not recognized
19797@end smallexample
c906108c 19798
8e04817f
AC
19799@noindent
19800@code{config.sub} is also distributed in the @value{GDBN} source
19801directory (@file{gdb-@value{GDBVN}}, for version @value{GDBVN}).
d700128c 19802
8e04817f
AC
19803@node Configure Options
19804@section @code{configure} options
c906108c 19805
8e04817f
AC
19806Here is a summary of the @code{configure} options and arguments that
19807are most often useful for building @value{GDBN}. @code{configure} also has
19808several other options not listed here. @inforef{What Configure
19809Does,,configure.info}, for a full explanation of @code{configure}.
c906108c 19810
474c8240 19811@smallexample
8e04817f
AC
19812configure @r{[}--help@r{]}
19813 @r{[}--prefix=@var{dir}@r{]}
19814 @r{[}--exec-prefix=@var{dir}@r{]}
19815 @r{[}--srcdir=@var{dirname}@r{]}
19816 @r{[}--norecursion@r{]} @r{[}--rm@r{]}
19817 @r{[}--target=@var{target}@r{]}
19818 @var{host}
474c8240 19819@end smallexample
c906108c 19820
8e04817f
AC
19821@noindent
19822You may introduce options with a single @samp{-} rather than
19823@samp{--} if you prefer; but you may abbreviate option names if you use
19824@samp{--}.
c906108c 19825
8e04817f
AC
19826@table @code
19827@item --help
19828Display a quick summary of how to invoke @code{configure}.
c906108c 19829
8e04817f
AC
19830@item --prefix=@var{dir}
19831Configure the source to install programs and files under directory
19832@file{@var{dir}}.
c906108c 19833
8e04817f
AC
19834@item --exec-prefix=@var{dir}
19835Configure the source to install programs under directory
19836@file{@var{dir}}.
c906108c 19837
8e04817f
AC
19838@c avoid splitting the warning from the explanation:
19839@need 2000
19840@item --srcdir=@var{dirname}
19841@strong{Warning: using this option requires @sc{gnu} @code{make}, or another
19842@code{make} that implements the @code{VPATH} feature.}@*
19843Use this option to make configurations in directories separate from the
19844@value{GDBN} source directories. Among other things, you can use this to
19845build (or maintain) several configurations simultaneously, in separate
19846directories. @code{configure} writes configuration specific files in
19847the current directory, but arranges for them to use the source in the
19848directory @var{dirname}. @code{configure} creates directories under
19849the working directory in parallel to the source directories below
19850@var{dirname}.
c906108c 19851
8e04817f
AC
19852@item --norecursion
19853Configure only the directory level where @code{configure} is executed; do not
19854propagate configuration to subdirectories.
c906108c 19855
8e04817f
AC
19856@item --target=@var{target}
19857Configure @value{GDBN} for cross-debugging programs running on the specified
19858@var{target}. Without this option, @value{GDBN} is configured to debug
19859programs that run on the same machine (@var{host}) as @value{GDBN} itself.
c906108c 19860
8e04817f 19861There is no convenient way to generate a list of all available targets.
c906108c 19862
8e04817f
AC
19863@item @var{host} @dots{}
19864Configure @value{GDBN} to run on the specified @var{host}.
c906108c 19865
8e04817f
AC
19866There is no convenient way to generate a list of all available hosts.
19867@end table
c906108c 19868
8e04817f
AC
19869There are many other options available as well, but they are generally
19870needed for special purposes only.
c906108c 19871
8e04817f
AC
19872@node Maintenance Commands
19873@appendix Maintenance Commands
19874@cindex maintenance commands
19875@cindex internal commands
c906108c 19876
8e04817f
AC
19877In addition to commands intended for @value{GDBN} users, @value{GDBN}
19878includes a number of commands intended for @value{GDBN} developers.
19879These commands are provided here for reference.
c906108c 19880
8e04817f
AC
19881@table @code
19882@kindex maint info breakpoints
19883@item @anchor{maint info breakpoints}maint info breakpoints
19884Using the same format as @samp{info breakpoints}, display both the
19885breakpoints you've set explicitly, and those @value{GDBN} is using for
19886internal purposes. Internal breakpoints are shown with negative
19887breakpoint numbers. The type column identifies what kind of breakpoint
19888is shown:
c906108c 19889
8e04817f
AC
19890@table @code
19891@item breakpoint
19892Normal, explicitly set breakpoint.
c906108c 19893
8e04817f
AC
19894@item watchpoint
19895Normal, explicitly set watchpoint.
c906108c 19896
8e04817f
AC
19897@item longjmp
19898Internal breakpoint, used to handle correctly stepping through
19899@code{longjmp} calls.
c906108c 19900
8e04817f
AC
19901@item longjmp resume
19902Internal breakpoint at the target of a @code{longjmp}.
c906108c 19903
8e04817f
AC
19904@item until
19905Temporary internal breakpoint used by the @value{GDBN} @code{until} command.
c906108c 19906
8e04817f
AC
19907@item finish
19908Temporary internal breakpoint used by the @value{GDBN} @code{finish} command.
c906108c 19909
8e04817f
AC
19910@item shlib events
19911Shared library events.
c906108c 19912
8e04817f 19913@end table
c906108c 19914
8d30a00d
AC
19915@kindex maint internal-error
19916@kindex maint internal-warning
19917@item maint internal-error
19918@itemx maint internal-warning
19919Cause @value{GDBN} to call the internal function @code{internal_error}
19920or @code{internal_warning} and hence behave as though an internal error
19921or internal warning has been detected. In addition to reporting the
19922internal problem, these functions give the user the opportunity to
19923either quit @value{GDBN} or create a core file of the current
19924@value{GDBN} session.
19925
19926@smallexample
f7dc1244 19927(@value{GDBP}) @kbd{maint internal-error testing, 1, 2}
8d30a00d
AC
19928@dots{}/maint.c:121: internal-error: testing, 1, 2
19929A problem internal to GDB has been detected. Further
19930debugging may prove unreliable.
19931Quit this debugging session? (y or n) @kbd{n}
19932Create a core file? (y or n) @kbd{n}
f7dc1244 19933(@value{GDBP})
8d30a00d
AC
19934@end smallexample
19935
19936Takes an optional parameter that is used as the text of the error or
19937warning message.
19938
00905d52
AC
19939@kindex maint print dummy-frames
19940@item maint print dummy-frames
19941
19942Prints the contents of @value{GDBN}'s internal dummy-frame stack.
19943
19944@smallexample
f7dc1244 19945(@value{GDBP}) @kbd{b add}
00905d52 19946@dots{}
f7dc1244 19947(@value{GDBP}) @kbd{print add(2,3)}
00905d52
AC
19948Breakpoint 2, add (a=2, b=3) at @dots{}
1994958 return (a + b);
19950The program being debugged stopped while in a function called from GDB.
19951@dots{}
f7dc1244 19952(@value{GDBP}) @kbd{maint print dummy-frames}
00905d52
AC
199530x1a57c80: pc=0x01014068 fp=0x0200bddc sp=0x0200bdd6
19954 top=0x0200bdd4 id=@{stack=0x200bddc,code=0x101405c@}
19955 call_lo=0x01014000 call_hi=0x01014001
f7dc1244 19956(@value{GDBP})
00905d52
AC
19957@end smallexample
19958
19959Takes an optional file parameter.
19960
0680b120
AC
19961@kindex maint print registers
19962@kindex maint print raw-registers
19963@kindex maint print cooked-registers
617073a9 19964@kindex maint print register-groups
0680b120
AC
19965@item maint print registers
19966@itemx maint print raw-registers
19967@itemx maint print cooked-registers
617073a9 19968@itemx maint print register-groups
0680b120
AC
19969Print @value{GDBN}'s internal register data structures.
19970
617073a9
AC
19971The command @code{maint print raw-registers} includes the contents of
19972the raw register cache; the command @code{maint print cooked-registers}
19973includes the (cooked) value of all registers; and the command
19974@code{maint print register-groups} includes the groups that each
19975register is a member of. @xref{Registers,, Registers, gdbint,
19976@value{GDBN} Internals}.
0680b120
AC
19977
19978Takes an optional file parameter.
19979
617073a9
AC
19980@kindex maint print reggroups
19981@item maint print reggroups
19982Print @value{GDBN}'s internal register group data structures.
19983
19984Takes an optional file parameter.
19985
19986@smallexample
f7dc1244 19987(@value{GDBP}) @kbd{maint print reggroups}
b383017d
RM
19988 Group Type
19989 general user
19990 float user
19991 all user
19992 vector user
19993 system user
19994 save internal
19995 restore internal
617073a9
AC
19996@end smallexample
19997
e7ba9c65
DJ
19998@kindex maint set profile
19999@kindex maint show profile
20000@cindex profiling GDB
20001@item maint set profile
20002@itemx maint show profile
20003Control profiling of @value{GDBN}.
20004
20005Profiling will be disabled until you use the @samp{maint set profile}
20006command to enable it. When you enable profiling, the system will begin
20007collecting timing and execution count data; when you disable profiling or
20008exit @value{GDBN}, the results will be written to a log file. Remember that
20009if you use profiling, @value{GDBN} will overwrite the profiling log file
20010(often called @file{gmon.out}). If you have a record of important profiling
20011data in a @file{gmon.out} file, be sure to move it to a safe location.
20012
20013Configuring with @samp{--enable-profiling} arranges for @value{GDBN} to be
b383017d 20014compiled with the @samp{-pg} compiler option.
e7ba9c65 20015
ae038cb0
DJ
20016@kindex maint set dwarf2 max-cache-age
20017@kindex maint show dwarf2 max-cache-age
20018@item maint set dwarf2 max-cache-age
20019@itemx maint show dwarf2 max-cache-age
20020Control the DWARF 2 compilation unit cache.
20021
20022In object files with inter-compilation-unit references, such as those
20023produced by the GCC option @samp{-feliminate-dwarf2-dups}, the DWARF 2
20024reader needs to frequently refer to previously read compilation units.
20025This setting controls how long a compilation unit will remain in the cache
20026if it is not referenced. Setting it to zero disables caching, which will
20027slow down @value{GDBN} startup but reduce memory consumption.
20028
8e04817f 20029@end table
c906108c 20030
c906108c 20031
e0ce93ac 20032@node Remote Protocol
8e04817f 20033@appendix @value{GDBN} Remote Serial Protocol
c906108c 20034
ee2d5c50
AC
20035@menu
20036* Overview::
20037* Packets::
20038* Stop Reply Packets::
20039* General Query Packets::
20040* Register Packet Format::
20041* Examples::
0ce1b118 20042* File-I/O remote protocol extension::
ee2d5c50
AC
20043@end menu
20044
20045@node Overview
20046@section Overview
20047
8e04817f
AC
20048There may be occasions when you need to know something about the
20049protocol---for example, if there is only one serial port to your target
20050machine, you might want your program to do something special if it
20051recognizes a packet meant for @value{GDBN}.
c906108c 20052
d2c6833e 20053In the examples below, @samp{->} and @samp{<-} are used to indicate
8e04817f 20054transmitted and received data respectfully.
c906108c 20055
8e04817f
AC
20056@cindex protocol, @value{GDBN} remote serial
20057@cindex serial protocol, @value{GDBN} remote
20058@cindex remote serial protocol
20059All @value{GDBN} commands and responses (other than acknowledgments) are
20060sent as a @var{packet}. A @var{packet} is introduced with the character
20061@samp{$}, the actual @var{packet-data}, and the terminating character
20062@samp{#} followed by a two-digit @var{checksum}:
c906108c 20063
474c8240 20064@smallexample
8e04817f 20065@code{$}@var{packet-data}@code{#}@var{checksum}
474c8240 20066@end smallexample
8e04817f 20067@noindent
c906108c 20068
8e04817f
AC
20069@cindex checksum, for @value{GDBN} remote
20070@noindent
20071The two-digit @var{checksum} is computed as the modulo 256 sum of all
20072characters between the leading @samp{$} and the trailing @samp{#} (an
20073eight bit unsigned checksum).
c906108c 20074
8e04817f
AC
20075Implementors should note that prior to @value{GDBN} 5.0 the protocol
20076specification also included an optional two-digit @var{sequence-id}:
c906108c 20077
474c8240 20078@smallexample
8e04817f 20079@code{$}@var{sequence-id}@code{:}@var{packet-data}@code{#}@var{checksum}
474c8240 20080@end smallexample
c906108c 20081
8e04817f
AC
20082@cindex sequence-id, for @value{GDBN} remote
20083@noindent
20084That @var{sequence-id} was appended to the acknowledgment. @value{GDBN}
20085has never output @var{sequence-id}s. Stubs that handle packets added
20086since @value{GDBN} 5.0 must not accept @var{sequence-id}.
c906108c 20087
8e04817f
AC
20088@cindex acknowledgment, for @value{GDBN} remote
20089When either the host or the target machine receives a packet, the first
20090response expected is an acknowledgment: either @samp{+} (to indicate
20091the package was received correctly) or @samp{-} (to request
20092retransmission):
c906108c 20093
474c8240 20094@smallexample
d2c6833e
AC
20095-> @code{$}@var{packet-data}@code{#}@var{checksum}
20096<- @code{+}
474c8240 20097@end smallexample
8e04817f 20098@noindent
53a5351d 20099
8e04817f
AC
20100The host (@value{GDBN}) sends @var{command}s, and the target (the
20101debugging stub incorporated in your program) sends a @var{response}. In
20102the case of step and continue @var{command}s, the response is only sent
20103when the operation has completed (the target has again stopped).
c906108c 20104
8e04817f
AC
20105@var{packet-data} consists of a sequence of characters with the
20106exception of @samp{#} and @samp{$} (see @samp{X} packet for additional
20107exceptions).
c906108c 20108
8e04817f 20109Fields within the packet should be separated using @samp{,} @samp{;} or
ee2d5c50 20110@cindex remote protocol, field separator
8e04817f 20111@samp{:}. Except where otherwise noted all numbers are represented in
ee2d5c50 20112@sc{hex} with leading zeros suppressed.
c906108c 20113
8e04817f
AC
20114Implementors should note that prior to @value{GDBN} 5.0, the character
20115@samp{:} could not appear as the third character in a packet (as it
20116would potentially conflict with the @var{sequence-id}).
c906108c 20117
8e04817f
AC
20118Response @var{data} can be run-length encoded to save space. A @samp{*}
20119means that the next character is an @sc{ascii} encoding giving a repeat count
20120which stands for that many repetitions of the character preceding the
20121@samp{*}. The encoding is @code{n+29}, yielding a printable character
20122where @code{n >=3} (which is where rle starts to win). The printable
20123characters @samp{$}, @samp{#}, @samp{+} and @samp{-} or with a numeric
20124value greater than 126 should not be used.
c906108c 20125
8e04817f 20126So:
474c8240 20127@smallexample
8e04817f 20128"@code{0* }"
474c8240 20129@end smallexample
8e04817f
AC
20130@noindent
20131means the same as "0000".
c906108c 20132
8e04817f
AC
20133The error response returned for some packets includes a two character
20134error number. That number is not well defined.
c906108c 20135
8e04817f
AC
20136For any @var{command} not supported by the stub, an empty response
20137(@samp{$#00}) should be returned. That way it is possible to extend the
20138protocol. A newer @value{GDBN} can tell if a packet is supported based
20139on that response.
c906108c 20140
b383017d
RM
20141A stub is required to support the @samp{g}, @samp{G}, @samp{m}, @samp{M},
20142@samp{c}, and @samp{s} @var{command}s. All other @var{command}s are
8e04817f 20143optional.
c906108c 20144
ee2d5c50
AC
20145@node Packets
20146@section Packets
20147
20148The following table provides a complete list of all currently defined
20149@var{command}s and their corresponding response @var{data}.
20150
20151@table @r
20152
20153@item @code{!} --- extended mode
20154@cindex @code{!} packet
20155
8e04817f
AC
20156Enable extended mode. In extended mode, the remote server is made
20157persistent. The @samp{R} packet is used to restart the program being
20158debugged.
ee2d5c50
AC
20159
20160Reply:
20161@table @samp
20162@item OK
8e04817f 20163The remote target both supports and has enabled extended mode.
ee2d5c50 20164@end table
c906108c 20165
ee2d5c50
AC
20166@item @code{?} --- last signal
20167@cindex @code{?} packet
c906108c 20168
ee2d5c50
AC
20169Indicate the reason the target halted. The reply is the same as for
20170step and continue.
c906108c 20171
ee2d5c50
AC
20172Reply:
20173@xref{Stop Reply Packets}, for the reply specifications.
20174
20175@item @code{a} --- reserved
20176
20177Reserved for future use.
20178
20179@item @code{A}@var{arglen}@code{,}@var{argnum}@code{,}@var{arg}@code{,@dots{}} --- set program arguments @strong{(reserved)}
20180@cindex @code{A} packet
c906108c 20181
8e04817f
AC
20182Initialized @samp{argv[]} array passed into program. @var{arglen}
20183specifies the number of bytes in the hex encoded byte stream @var{arg}.
ee2d5c50
AC
20184See @code{gdbserver} for more details.
20185
20186Reply:
20187@table @samp
20188@item OK
20189@item E@var{NN}
20190@end table
20191
20192@item @code{b}@var{baud} --- set baud @strong{(deprecated)}
20193@cindex @code{b} packet
20194
20195Change the serial line speed to @var{baud}.
20196
20197JTC: @emph{When does the transport layer state change? When it's
20198received, or after the ACK is transmitted. In either case, there are
20199problems if the command or the acknowledgment packet is dropped.}
20200
20201Stan: @emph{If people really wanted to add something like this, and get
20202it working for the first time, they ought to modify ser-unix.c to send
20203some kind of out-of-band message to a specially-setup stub and have the
20204switch happen "in between" packets, so that from remote protocol's point
20205of view, nothing actually happened.}
20206
20207@item @code{B}@var{addr},@var{mode} --- set breakpoint @strong{(deprecated)}
20208@cindex @code{B} packet
20209
8e04817f 20210Set (@var{mode} is @samp{S}) or clear (@var{mode} is @samp{C}) a
2f870471
AC
20211breakpoint at @var{addr}.
20212
20213This packet has been replaced by the @samp{Z} and @samp{z} packets
20214(@pxref{insert breakpoint or watchpoint packet}).
c906108c 20215
ee2d5c50
AC
20216@item @code{c}@var{addr} --- continue
20217@cindex @code{c} packet
20218
20219@var{addr} is address to resume. If @var{addr} is omitted, resume at
8e04817f 20220current address.
c906108c 20221
ee2d5c50
AC
20222Reply:
20223@xref{Stop Reply Packets}, for the reply specifications.
20224
20225@item @code{C}@var{sig}@code{;}@var{addr} --- continue with signal
20226@cindex @code{C} packet
20227
8e04817f
AC
20228Continue with signal @var{sig} (hex signal number). If
20229@code{;}@var{addr} is omitted, resume at same address.
c906108c 20230
ee2d5c50
AC
20231Reply:
20232@xref{Stop Reply Packets}, for the reply specifications.
c906108c 20233
ee2d5c50
AC
20234@item @code{d} --- toggle debug @strong{(deprecated)}
20235@cindex @code{d} packet
20236
20237Toggle debug flag.
20238
20239@item @code{D} --- detach
20240@cindex @code{D} packet
20241
20242Detach @value{GDBN} from the remote system. Sent to the remote target
07f31aa6 20243before @value{GDBN} disconnects via the @code{detach} command.
ee2d5c50
AC
20244
20245Reply:
20246@table @samp
20247@item @emph{no response}
8e04817f 20248@value{GDBN} does not check for any response after sending this packet.
ee2d5c50 20249@end table
c906108c 20250
ee2d5c50 20251@item @code{e} --- reserved
c906108c 20252
ee2d5c50 20253Reserved for future use.
c906108c 20254
ee2d5c50 20255@item @code{E} --- reserved
c906108c 20256
ee2d5c50 20257Reserved for future use.
c906108c 20258
ee2d5c50
AC
20259@item @code{f} --- reserved
20260
20261Reserved for future use.
20262
0ce1b118
CV
20263@item @code{F}@var{RC}@code{,}@var{EE}@code{,}@var{CF}@code{;}@var{XX} --- Reply to target's F packet.
20264@cindex @code{F} packet
ee2d5c50 20265
0ce1b118
CV
20266This packet is send by @value{GDBN} as reply to a @code{F} request packet
20267sent by the target. This is part of the File-I/O protocol extension.
20268@xref{File-I/O remote protocol extension}, for the specification.
ee2d5c50
AC
20269
20270@item @code{g} --- read registers
20271@anchor{read registers packet}
20272@cindex @code{g} packet
20273
20274Read general registers.
20275
20276Reply:
20277@table @samp
20278@item @var{XX@dots{}}
8e04817f
AC
20279Each byte of register data is described by two hex digits. The bytes
20280with the register are transmitted in target byte order. The size of
20281each register and their position within the @samp{g} @var{packet} are
12c266ea
AC
20282determined by the @value{GDBN} internal macros
20283@var{DEPRECATED_REGISTER_RAW_SIZE} and @var{REGISTER_NAME} macros. The
20284specification of several standard @code{g} packets is specified below.
ee2d5c50
AC
20285@item E@var{NN}
20286for an error.
20287@end table
c906108c 20288
ee2d5c50
AC
20289@item @code{G}@var{XX@dots{}} --- write regs
20290@cindex @code{G} packet
c906108c 20291
ee2d5c50
AC
20292@xref{read registers packet}, for a description of the @var{XX@dots{}}
20293data.
20294
20295Reply:
20296@table @samp
20297@item OK
20298for success
20299@item E@var{NN}
20300for an error
20301@end table
20302
20303@item @code{h} --- reserved
20304
20305Reserved for future use.
20306
b383017d 20307@item @code{H}@var{c}@var{t@dots{}} --- set thread
ee2d5c50 20308@cindex @code{H} packet
c906108c 20309
8e04817f 20310Set thread for subsequent operations (@samp{m}, @samp{M}, @samp{g},
ee2d5c50
AC
20311@samp{G}, et.al.). @var{c} depends on the operation to be performed: it
20312should be @samp{c} for step and continue operations, @samp{g} for other
20313operations. The thread designator @var{t@dots{}} may be -1, meaning all
20314the threads, a thread number, or zero which means pick any thread.
20315
20316Reply:
20317@table @samp
20318@item OK
20319for success
20320@item E@var{NN}
20321for an error
20322@end table
c906108c 20323
8e04817f
AC
20324@c FIXME: JTC:
20325@c 'H': How restrictive (or permissive) is the thread model. If a
20326@c thread is selected and stopped, are other threads allowed
20327@c to continue to execute? As I mentioned above, I think the
20328@c semantics of each command when a thread is selected must be
20329@c described. For example:
20330@c
20331@c 'g': If the stub supports threads and a specific thread is
20332@c selected, returns the register block from that thread;
20333@c otherwise returns current registers.
20334@c
20335@c 'G' If the stub supports threads and a specific thread is
20336@c selected, sets the registers of the register block of
20337@c that thread; otherwise sets current registers.
c906108c 20338
ee2d5c50
AC
20339@item @code{i}@var{addr}@code{,}@var{nnn} --- cycle step @strong{(draft)}
20340@anchor{cycle step packet}
20341@cindex @code{i} packet
20342
8e04817f
AC
20343Step the remote target by a single clock cycle. If @code{,}@var{nnn} is
20344present, cycle step @var{nnn} cycles. If @var{addr} is present, cycle
20345step starting at that address.
c906108c 20346
ee2d5c50
AC
20347@item @code{I} --- signal then cycle step @strong{(reserved)}
20348@cindex @code{I} packet
20349
20350@xref{step with signal packet}. @xref{cycle step packet}.
20351
20352@item @code{j} --- reserved
20353
20354Reserved for future use.
20355
20356@item @code{J} --- reserved
c906108c 20357
ee2d5c50 20358Reserved for future use.
c906108c 20359
ee2d5c50
AC
20360@item @code{k} --- kill request
20361@cindex @code{k} packet
c906108c 20362
ac282366 20363FIXME: @emph{There is no description of how to operate when a specific
ee2d5c50
AC
20364thread context has been selected (i.e.@: does 'k' kill only that
20365thread?)}.
c906108c 20366
ee2d5c50 20367@item @code{K} --- reserved
c906108c 20368
ee2d5c50
AC
20369Reserved for future use.
20370
20371@item @code{l} --- reserved
20372
20373Reserved for future use.
20374
20375@item @code{L} --- reserved
20376
20377Reserved for future use.
20378
20379@item @code{m}@var{addr}@code{,}@var{length} --- read memory
20380@cindex @code{m} packet
c906108c 20381
8e04817f 20382Read @var{length} bytes of memory starting at address @var{addr}.
ee2d5c50 20383Neither @value{GDBN} nor the stub assume that sized memory transfers are
2e834e49 20384assumed using word aligned accesses. FIXME: @emph{A word aligned memory
8e04817f 20385transfer mechanism is needed.}
c906108c 20386
ee2d5c50
AC
20387Reply:
20388@table @samp
20389@item @var{XX@dots{}}
20390@var{XX@dots{}} is mem contents. Can be fewer bytes than requested if able
20391to read only part of the data. Neither @value{GDBN} nor the stub assume
2e834e49 20392that sized memory transfers are assumed using word aligned
ee2d5c50
AC
20393accesses. FIXME: @emph{A word aligned memory transfer mechanism is
20394needed.}
20395@item E@var{NN}
20396@var{NN} is errno
20397@end table
20398
20399@item @code{M}@var{addr},@var{length}@code{:}@var{XX@dots{}} --- write mem
20400@cindex @code{M} packet
20401
8e04817f 20402Write @var{length} bytes of memory starting at address @var{addr}.
ee2d5c50
AC
20403@var{XX@dots{}} is the data.
20404
20405Reply:
20406@table @samp
20407@item OK
20408for success
20409@item E@var{NN}
8e04817f
AC
20410for an error (this includes the case where only part of the data was
20411written).
ee2d5c50 20412@end table
c906108c 20413
ee2d5c50 20414@item @code{n} --- reserved
c906108c 20415
ee2d5c50 20416Reserved for future use.
c906108c 20417
ee2d5c50 20418@item @code{N} --- reserved
c906108c 20419
ee2d5c50 20420Reserved for future use.
c906108c 20421
ee2d5c50
AC
20422@item @code{o} --- reserved
20423
20424Reserved for future use.
20425
20426@item @code{O} --- reserved
20427
2e868123 20428@item @code{p}@var{hex number of register} --- read register packet
ee2d5c50
AC
20429@cindex @code{p} packet
20430
2e868123
AC
20431@xref{read registers packet}, for a description of how the returned
20432register value is encoded.
ee2d5c50
AC
20433
20434Reply:
20435@table @samp
2e868123
AC
20436@item @var{XX@dots{}}
20437the register's value
20438@item E@var{NN}
20439for an error
20440@item
20441Indicating an unrecognized @var{query}.
ee2d5c50
AC
20442@end table
20443
20444@item @code{P}@var{n@dots{}}@code{=}@var{r@dots{}} --- write register
20445@anchor{write register packet}
20446@cindex @code{P} packet
20447
20448Write register @var{n@dots{}} with value @var{r@dots{}}, which contains two hex
8e04817f 20449digits for each byte in the register (target byte order).
c906108c 20450
ee2d5c50
AC
20451Reply:
20452@table @samp
20453@item OK
20454for success
20455@item E@var{NN}
20456for an error
20457@end table
20458
20459@item @code{q}@var{query} --- general query
20460@anchor{general query packet}
20461@cindex @code{q} packet
20462
20463Request info about @var{query}. In general @value{GDBN} queries have a
20464leading upper case letter. Custom vendor queries should use a company
20465prefix (in lower case) ex: @samp{qfsf.var}. @var{query} may optionally
20466be followed by a @samp{,} or @samp{;} separated list. Stubs must ensure
20467that they match the full @var{query} name.
20468
20469Reply:
20470@table @samp
20471@item @var{XX@dots{}}
20472Hex encoded data from query. The reply can not be empty.
20473@item E@var{NN}
20474error reply
8e04817f 20475@item
ee2d5c50
AC
20476Indicating an unrecognized @var{query}.
20477@end table
20478
20479@item @code{Q}@var{var}@code{=}@var{val} --- general set
20480@cindex @code{Q} packet
20481
20482Set value of @var{var} to @var{val}.
20483
20484@xref{general query packet}, for a discussion of naming conventions.
c906108c 20485
ee2d5c50
AC
20486@item @code{r} --- reset @strong{(deprecated)}
20487@cindex @code{r} packet
c906108c 20488
8e04817f 20489Reset the entire system.
c906108c 20490
ee2d5c50
AC
20491@item @code{R}@var{XX} --- remote restart
20492@cindex @code{R} packet
20493
8e04817f
AC
20494Restart the program being debugged. @var{XX}, while needed, is ignored.
20495This packet is only available in extended mode.
ee2d5c50
AC
20496
20497Reply:
20498@table @samp
20499@item @emph{no reply}
8e04817f 20500The @samp{R} packet has no reply.
ee2d5c50
AC
20501@end table
20502
20503@item @code{s}@var{addr} --- step
20504@cindex @code{s} packet
c906108c 20505
8e04817f
AC
20506@var{addr} is address to resume. If @var{addr} is omitted, resume at
20507same address.
c906108c 20508
ee2d5c50
AC
20509Reply:
20510@xref{Stop Reply Packets}, for the reply specifications.
20511
20512@item @code{S}@var{sig}@code{;}@var{addr} --- step with signal
20513@anchor{step with signal packet}
20514@cindex @code{S} packet
20515
8e04817f 20516Like @samp{C} but step not continue.
c906108c 20517
ee2d5c50
AC
20518Reply:
20519@xref{Stop Reply Packets}, for the reply specifications.
20520
b383017d 20521@item @code{t}@var{addr}@code{:}@var{PP}@code{,}@var{MM} --- search
ee2d5c50
AC
20522@cindex @code{t} packet
20523
8e04817f 20524Search backwards starting at address @var{addr} for a match with pattern
ee2d5c50
AC
20525@var{PP} and mask @var{MM}. @var{PP} and @var{MM} are 4 bytes.
20526@var{addr} must be at least 3 digits.
c906108c 20527
ee2d5c50
AC
20528@item @code{T}@var{XX} --- thread alive
20529@cindex @code{T} packet
c906108c 20530
ee2d5c50 20531Find out if the thread XX is alive.
c906108c 20532
ee2d5c50
AC
20533Reply:
20534@table @samp
20535@item OK
20536thread is still alive
20537@item E@var{NN}
20538thread is dead
20539@end table
20540
20541@item @code{u} --- reserved
20542
20543Reserved for future use.
20544
20545@item @code{U} --- reserved
20546
20547Reserved for future use.
20548
86d30acc 20549@item @code{v} --- verbose packet prefix
ee2d5c50 20550
86d30acc
DJ
20551Packets starting with @code{v} are identified by a multi-letter name,
20552up to the first @code{;} or @code{?} (or the end of the packet).
20553
20554@item @code{vCont}[;@var{action}[@code{:}@var{tid}]]... --- extended resume
20555@cindex @code{vCont} packet
20556
20557Resume the inferior. Different actions may be specified for each thread.
20558If an action is specified with no @var{tid}, then it is applied to any
20559threads that don't have a specific action specified; if no default action is
20560specified then other threads should remain stopped. Specifying multiple
20561default actions is an error; specifying no actions is also an error.
20562Thread IDs are specified in hexadecimal. Currently supported actions are:
20563
20564@table @code
20565@item c
20566Continue.
20567@item C@var{sig}
20568Continue with signal @var{sig}. @var{sig} should be two hex digits.
20569@item s
20570Step.
20571@item S@var{sig}
20572Step with signal @var{sig}. @var{sig} should be two hex digits.
20573@end table
20574
20575The optional @var{addr} argument normally associated with these packets is
20576not supported in @code{vCont}.
20577
20578Reply:
20579@xref{Stop Reply Packets}, for the reply specifications.
20580
20581@item @code{vCont?} --- extended resume query
20582@cindex @code{vCont?} packet
20583
20584Query support for the @code{vCont} packet.
20585
20586Reply:
20587@table @samp
20588@item @code{vCont}[;@var{action}]...
20589The @code{vCont} packet is supported. Each @var{action} is a supported
20590command in the @code{vCont} packet.
20591@item
20592The @code{vCont} packet is not supported.
20593@end table
ee2d5c50
AC
20594
20595@item @code{V} --- reserved
c906108c 20596
ee2d5c50 20597Reserved for future use.
c906108c 20598
ee2d5c50 20599@item @code{w} --- reserved
c906108c 20600
ee2d5c50 20601Reserved for future use.
c906108c 20602
ee2d5c50 20603@item @code{W} --- reserved
c906108c 20604
ee2d5c50 20605Reserved for future use.
c906108c 20606
ee2d5c50
AC
20607@item @code{x} --- reserved
20608
20609Reserved for future use.
20610
20611@item @code{X}@var{addr}@code{,}@var{length}@var{:}@var{XX@dots{}} --- write mem (binary)
20612@cindex @code{X} packet
20613
20614@var{addr} is address, @var{length} is number of bytes, @var{XX@dots{}}
20615is binary data. The characters @code{$}, @code{#}, and @code{0x7d} are
69065f5d
AC
20616escaped using @code{0x7d}, and then XORed with @code{0x20}.
20617For example, @code{0x7d} would be transmitted as @code{0x7d 0x5d}.
c906108c 20618
ee2d5c50
AC
20619Reply:
20620@table @samp
20621@item OK
20622for success
20623@item E@var{NN}
20624for an error
20625@end table
20626
20627@item @code{y} --- reserved
c906108c 20628
ee2d5c50 20629Reserved for future use.
c906108c 20630
ee2d5c50
AC
20631@item @code{Y} reserved
20632
20633Reserved for future use.
20634
2f870471
AC
20635@item @code{z}@var{type}@code{,}@var{addr}@code{,}@var{length} --- remove breakpoint or watchpoint @strong{(draft)}
20636@itemx @code{Z}@var{type}@code{,}@var{addr}@code{,}@var{length} --- insert breakpoint or watchpoint @strong{(draft)}
20637@anchor{insert breakpoint or watchpoint packet}
ee2d5c50 20638@cindex @code{z} packet
2f870471 20639@cindex @code{Z} packets
ee2d5c50 20640
2f870471
AC
20641Insert (@code{Z}) or remove (@code{z}) a @var{type} breakpoint or
20642watchpoint starting at address @var{address} and covering the next
20643@var{length} bytes.
ee2d5c50 20644
2f870471
AC
20645Each breakpoint and watchpoint packet @var{type} is documented
20646separately.
20647
512217c7
AC
20648@emph{Implementation notes: A remote target shall return an empty string
20649for an unrecognized breakpoint or watchpoint packet @var{type}. A
20650remote target shall support either both or neither of a given
2f870471
AC
20651@code{Z}@var{type}@dots{} and @code{z}@var{type}@dots{} packet pair. To
20652avoid potential problems with duplicate packets, the operations should
20653be implemented in an idempotent way.}
20654
20655@item @code{z}@code{0}@code{,}@var{addr}@code{,}@var{length} --- remove memory breakpoint @strong{(draft)}
20656@item @code{Z}@code{0}@code{,}@var{addr}@code{,}@var{length} --- insert memory breakpoint @strong{(draft)}
20657@cindex @code{z0} packet
20658@cindex @code{Z0} packet
20659
20660Insert (@code{Z0}) or remove (@code{z0}) a memory breakpoint at address
20661@code{addr} of size @code{length}.
20662
20663A memory breakpoint is implemented by replacing the instruction at
20664@var{addr} with a software breakpoint or trap instruction. The
20665@code{length} is used by targets that indicates the size of the
20666breakpoint (in bytes) that should be inserted (e.g., the @sc{arm} and
20667@sc{mips} can insert either a 2 or 4 byte breakpoint).
c906108c 20668
2f870471
AC
20669@emph{Implementation note: It is possible for a target to copy or move
20670code that contains memory breakpoints (e.g., when implementing
20671overlays). The behavior of this packet, in the presence of such a
20672target, is not defined.}
c906108c 20673
ee2d5c50
AC
20674Reply:
20675@table @samp
2f870471
AC
20676@item OK
20677success
20678@item
20679not supported
ee2d5c50
AC
20680@item E@var{NN}
20681for an error
2f870471
AC
20682@end table
20683
20684@item @code{z}@code{1}@code{,}@var{addr}@code{,}@var{length} --- remove hardware breakpoint @strong{(draft)}
20685@item @code{Z}@code{1}@code{,}@var{addr}@code{,}@var{length} --- insert hardware breakpoint @strong{(draft)}
20686@cindex @code{z1} packet
20687@cindex @code{Z1} packet
20688
20689Insert (@code{Z1}) or remove (@code{z1}) a hardware breakpoint at
20690address @code{addr} of size @code{length}.
20691
20692A hardware breakpoint is implemented using a mechanism that is not
20693dependant on being able to modify the target's memory.
20694
20695@emph{Implementation note: A hardware breakpoint is not affected by code
20696movement.}
20697
20698Reply:
20699@table @samp
ee2d5c50 20700@item OK
2f870471
AC
20701success
20702@item
20703not supported
20704@item E@var{NN}
20705for an error
20706@end table
20707
20708@item @code{z}@code{2}@code{,}@var{addr}@code{,}@var{length} --- remove write watchpoint @strong{(draft)}
20709@item @code{Z}@code{2}@code{,}@var{addr}@code{,}@var{length} --- insert write watchpoint @strong{(draft)}
20710@cindex @code{z2} packet
20711@cindex @code{Z2} packet
20712
20713Insert (@code{Z2}) or remove (@code{z2}) a write watchpoint.
20714
20715Reply:
20716@table @samp
20717@item OK
20718success
20719@item
20720not supported
20721@item E@var{NN}
20722for an error
20723@end table
20724
20725@item @code{z}@code{3}@code{,}@var{addr}@code{,}@var{length} --- remove read watchpoint @strong{(draft)}
20726@item @code{Z}@code{3}@code{,}@var{addr}@code{,}@var{length} --- insert read watchpoint @strong{(draft)}
20727@cindex @code{z3} packet
20728@cindex @code{Z3} packet
20729
2e834e49 20730Insert (@code{Z3}) or remove (@code{z3}) a read watchpoint.
2f870471
AC
20731
20732Reply:
20733@table @samp
20734@item OK
20735success
20736@item
20737not supported
20738@item E@var{NN}
20739for an error
20740@end table
20741
2e834e49
HPN
20742@item @code{z}@code{4}@code{,}@var{addr}@code{,}@var{length} --- remove access watchpoint @strong{(draft)}
20743@item @code{Z}@code{4}@code{,}@var{addr}@code{,}@var{length} --- insert access watchpoint @strong{(draft)}
2f870471
AC
20744@cindex @code{z4} packet
20745@cindex @code{Z4} packet
20746
20747Insert (@code{Z4}) or remove (@code{z4}) an access watchpoint.
20748
20749Reply:
20750@table @samp
20751@item OK
20752success
20753@item
20754not supported
20755@item E@var{NN}
20756for an error
ee2d5c50
AC
20757@end table
20758
20759@end table
c906108c 20760
ee2d5c50
AC
20761@node Stop Reply Packets
20762@section Stop Reply Packets
20763@cindex stop reply packets
c906108c 20764
8e04817f
AC
20765The @samp{C}, @samp{c}, @samp{S}, @samp{s} and @samp{?} packets can
20766receive any of the below as a reply. In the case of the @samp{C},
20767@samp{c}, @samp{S} and @samp{s} packets, that reply is only returned
20768when the target halts. In the below the exact meaning of @samp{signal
20769number} is poorly defined. In general one of the UNIX signal numbering
20770conventions is used.
c906108c 20771
ee2d5c50 20772@table @samp
c906108c 20773
ee2d5c50
AC
20774@item S@var{AA}
20775@var{AA} is the signal number
c906108c 20776
8e04817f 20777@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
20778@cindex @code{T} packet reply
20779
8e04817f
AC
20780@var{AA} = two hex digit signal number; @var{n...} = register number
20781(hex), @var{r...} = target byte ordered register contents, size defined
12c266ea
AC
20782by @code{DEPRECATED_REGISTER_RAW_SIZE}; @var{n...} = @samp{thread},
20783@var{r...} = thread process ID, this is a hex integer; @var{n...} =
20784(@samp{watch} | @samp{rwatch} | @samp{awatch}, @var{r...} = data
20785address, this is a hex integer; @var{n...} = other string not starting
20786with valid hex digit. @value{GDBN} should ignore this @var{n...},
20787@var{r...} pair and go on to the next. This way we can extend the
20788protocol.
c906108c 20789
ee2d5c50
AC
20790@item W@var{AA}
20791
8e04817f 20792The process exited, and @var{AA} is the exit status. This is only
ee2d5c50
AC
20793applicable to certain targets.
20794
20795@item X@var{AA}
c906108c 20796
8e04817f 20797The process terminated with signal @var{AA}.
c906108c 20798
ee2d5c50 20799@item O@var{XX@dots{}}
c906108c 20800
ee2d5c50
AC
20801@var{XX@dots{}} is hex encoding of @sc{ascii} data. This can happen at
20802any time while the program is running and the debugger should continue
20803to wait for @samp{W}, @samp{T}, etc.
20804
0ce1b118
CV
20805@item F@var{call-id}@code{,}@var{parameter@dots{}}
20806
20807@var{call-id} is the identifier which says which host system call should
20808be called. This is just the name of the function. Translation into the
20809correct system call is only applicable as it's defined in @value{GDBN}.
20810@xref{File-I/O remote protocol extension}, for a list of implemented
20811system calls.
20812
20813@var{parameter@dots{}} is a list of parameters as defined for this very
20814system call.
20815
20816The target replies with this packet when it expects @value{GDBN} to call
20817a host system call on behalf of the target. @value{GDBN} replies with
20818an appropriate @code{F} packet and keeps up waiting for the next reply
20819packet from the target. The latest @samp{C}, @samp{c}, @samp{S} or
20820@samp{s} action is expected to be continued.
20821@xref{File-I/O remote protocol extension}, for more details.
20822
ee2d5c50
AC
20823@end table
20824
20825@node General Query Packets
20826@section General Query Packets
c906108c 20827
8e04817f 20828The following set and query packets have already been defined.
c906108c 20829
ee2d5c50 20830@table @r
c906108c 20831
ee2d5c50
AC
20832@item @code{q}@code{C} --- current thread
20833
20834Return the current thread id.
20835
20836Reply:
20837@table @samp
20838@item @code{QC}@var{pid}
e1aac25b 20839Where @var{pid} is an unsigned hexidecimal process id.
ee2d5c50
AC
20840@item *
20841Any other reply implies the old pid.
20842@end table
20843
20844@item @code{q}@code{fThreadInfo} -- all thread ids
20845
20846@code{q}@code{sThreadInfo}
c906108c 20847
8e04817f
AC
20848Obtain a list of active thread ids from the target (OS). Since there
20849may be too many active threads to fit into one reply packet, this query
20850works iteratively: it may require more than one query/reply sequence to
20851obtain the entire list of threads. The first query of the sequence will
20852be the @code{qf}@code{ThreadInfo} query; subsequent queries in the
20853sequence will be the @code{qs}@code{ThreadInfo} query.
ee2d5c50
AC
20854
20855NOTE: replaces the @code{qL} query (see below).
20856
20857Reply:
20858@table @samp
20859@item @code{m}@var{id}
20860A single thread id
20861@item @code{m}@var{id},@var{id}@dots{}
20862a comma-separated list of thread ids
20863@item @code{l}
20864(lower case 'el') denotes end of list.
20865@end table
20866
20867In response to each query, the target will reply with a list of one or
e1aac25b
JB
20868more thread ids, in big-endian unsigned hex, separated by commas.
20869@value{GDBN} will respond to each reply with a request for more thread
20870ids (using the @code{qs} form of the query), until the target responds
20871with @code{l} (lower-case el, for @code{'last'}).
c906108c 20872
ee2d5c50
AC
20873@item @code{q}@code{ThreadExtraInfo}@code{,}@var{id} --- extra thread info
20874
20875Where @var{id} is a thread-id in big-endian hex. Obtain a printable
20876string description of a thread's attributes from the target OS. This
20877string may contain anything that the target OS thinks is interesting for
20878@value{GDBN} to tell the user about the thread. The string is displayed
20879in @value{GDBN}'s @samp{info threads} display. Some examples of
20880possible thread extra info strings are ``Runnable'', or ``Blocked on
20881Mutex''.
20882
20883Reply:
20884@table @samp
20885@item @var{XX@dots{}}
20886Where @var{XX@dots{}} is a hex encoding of @sc{ascii} data, comprising
20887the printable string containing the extra information about the thread's
8e04817f 20888attributes.
ee2d5c50
AC
20889@end table
20890
20891@item @code{q}@code{L}@var{startflag}@var{threadcount}@var{nextthread} --- query @var{LIST} or @var{threadLIST} @strong{(deprecated)}
c906108c 20892
8e04817f
AC
20893Obtain thread information from RTOS. Where: @var{startflag} (one hex
20894digit) is one to indicate the first query and zero to indicate a
20895subsequent query; @var{threadcount} (two hex digits) is the maximum
20896number of threads the response packet can contain; and @var{nextthread}
20897(eight hex digits), for subsequent queries (@var{startflag} is zero), is
20898returned in the response as @var{argthread}.
ee2d5c50
AC
20899
20900NOTE: this query is replaced by the @code{q}@code{fThreadInfo} query
20901(see above).
20902
20903Reply:
20904@table @samp
20905@item @code{q}@code{M}@var{count}@var{done}@var{argthread}@var{thread@dots{}}
8e04817f
AC
20906Where: @var{count} (two hex digits) is the number of threads being
20907returned; @var{done} (one hex digit) is zero to indicate more threads
20908and one indicates no further threads; @var{argthreadid} (eight hex
ee2d5c50
AC
20909digits) is @var{nextthread} from the request packet; @var{thread@dots{}}
20910is a sequence of thread IDs from the target. @var{threadid} (eight hex
8e04817f 20911digits). See @code{remote.c:parse_threadlist_response()}.
ee2d5c50 20912@end table
c906108c 20913
ee2d5c50
AC
20914@item @code{q}@code{CRC:}@var{addr}@code{,}@var{length} --- compute CRC of memory block
20915
20916Reply:
20917@table @samp
20918@item @code{E}@var{NN}
20919An error (such as memory fault)
20920@item @code{C}@var{CRC32}
20921A 32 bit cyclic redundancy check of the specified memory region.
20922@end table
20923
20924@item @code{q}@code{Offsets} --- query sect offs
c906108c 20925
8e04817f
AC
20926Get section offsets that the target used when re-locating the downloaded
20927image. @emph{Note: while a @code{Bss} offset is included in the
20928response, @value{GDBN} ignores this and instead applies the @code{Data}
20929offset to the @code{Bss} section.}
c906108c 20930
ee2d5c50
AC
20931Reply:
20932@table @samp
20933@item @code{Text=}@var{xxx}@code{;Data=}@var{yyy}@code{;Bss=}@var{zzz}
20934@end table
20935
20936@item @code{q}@code{P}@var{mode}@var{threadid} --- thread info request
20937
8e04817f
AC
20938Returns information on @var{threadid}. Where: @var{mode} is a hex
20939encoded 32 bit mode; @var{threadid} is a hex encoded 64 bit thread ID.
ee2d5c50
AC
20940
20941Reply:
20942@table @samp
20943@item *
20944@end table
20945
8e04817f 20946See @code{remote.c:remote_unpack_thread_info_response()}.
c906108c 20947
ee2d5c50
AC
20948@item @code{q}@code{Rcmd,}@var{command} --- remote command
20949
20950@var{command} (hex encoded) is passed to the local interpreter for
8e04817f
AC
20951execution. Invalid commands should be reported using the output string.
20952Before the final result packet, the target may also respond with a
ee2d5c50
AC
20953number of intermediate @code{O}@var{output} console output packets.
20954@emph{Implementors should note that providing access to a stubs's
20955interpreter may have security implications}.
20956
20957Reply:
20958@table @samp
20959@item OK
8e04817f 20960A command response with no output.
ee2d5c50 20961@item @var{OUTPUT}
8e04817f 20962A command response with the hex encoded output string @var{OUTPUT}.
ee2d5c50 20963@item @code{E}@var{NN}
8e04817f 20964Indicate a badly formed request.
ee2d5c50 20965@item @samp{}
8e04817f 20966When @samp{q}@samp{Rcmd} is not recognized.
ee2d5c50
AC
20967@end table
20968
20969@item @code{qSymbol::} --- symbol lookup
c906108c 20970
8e04817f
AC
20971Notify the target that @value{GDBN} is prepared to serve symbol lookup
20972requests. Accept requests from the target for the values of symbols.
ee2d5c50
AC
20973
20974Reply:
20975@table @samp
20976@item @code{OK}
8e04817f 20977The target does not need to look up any (more) symbols.
ee2d5c50
AC
20978@item @code{qSymbol:}@var{sym_name}
20979The target requests the value of symbol @var{sym_name} (hex encoded).
20980@value{GDBN} may provide the value by using the
20981@code{qSymbol:}@var{sym_value}:@var{sym_name} message, described below.
20982@end table
20983
20984@item @code{qSymbol:}@var{sym_value}:@var{sym_name} --- symbol value
20985
20986Set the value of @var{sym_name} to @var{sym_value}.
20987
20988@var{sym_name} (hex encoded) is the name of a symbol whose value the
20989target has previously requested.
20990
20991@var{sym_value} (hex) is the value for symbol @var{sym_name}. If
20992@value{GDBN} cannot supply a value for @var{sym_name}, then this field
20993will be empty.
20994
20995Reply:
20996@table @samp
20997@item @code{OK}
8e04817f 20998The target does not need to look up any (more) symbols.
ee2d5c50
AC
20999@item @code{qSymbol:}@var{sym_name}
21000The target requests the value of a new symbol @var{sym_name} (hex
21001encoded). @value{GDBN} will continue to supply the values of symbols
21002(if available), until the target ceases to request them.
21003@end table
eb12ee30 21004
649e03f6
RM
21005@item @code{qPart}:@var{object}:@code{read}:@var{annex}:@var{offset},@var{length} --- read special data
21006
21007Read uninterpreted bytes from the target's special data area
21008identified by the keyword @code{object}.
21009Request @var{length} bytes starting at @var{offset} bytes into the data.
21010The content and encoding of @var{annex} is specific to the object;
21011it can supply additional details about what data to access.
21012
21013Here are the specific requests of this form defined so far.
21014All @samp{@code{qPart}:@var{object}:@code{read}:@dots{}}
21015requests use the same reply formats, listed below.
21016
21017@table @asis
21018@item @code{qPart}:@code{auxv}:@code{read}::@var{offset},@var{length}
21019Access the target's @dfn{auxiliary vector}. @xref{Auxiliary Vector}.
21020Note @var{annex} must be empty.
21021@end table
21022
21023Reply:
21024@table @asis
21025@item @code{OK}
21026The @var{offset} in the request is at the end of the data.
21027There is no more data to be read.
21028
21029@item @var{XX@dots{}}
21030Hex encoded data bytes read.
21031This may be fewer bytes than the @var{length} in the request.
21032
21033@item @code{E00}
21034The request was malformed, or @var{annex} was invalid.
21035
21036@item @code{E}@var{nn}
21037The offset was invalid, or there was an error encountered reading the data.
21038@var{nn} is a hex-encoded @code{errno} value.
21039
21040@item @code{""} (empty)
21041An empty reply indicates the @var{object} or @var{annex} string was not
21042recognized by the stub.
21043@end table
21044
21045@item @code{qPart}:@var{object}:@code{write}:@var{annex}:@var{offset}:@var{data@dots{}}
21046
21047Write uninterpreted bytes into the target's special data area
21048identified by the keyword @code{object},
21049starting at @var{offset} bytes into the data.
21050@var{data@dots{}} is the hex-encoded data to be written.
21051The content and encoding of @var{annex} is specific to the object;
21052it can supply additional details about what data to access.
21053
21054No requests of this form are presently in use. This specification
21055serves as a placeholder to document the common format that new
21056specific request specifications ought to use.
21057
21058Reply:
21059@table @asis
21060@item @var{nn}
21061@var{nn} (hex encoded) is the number of bytes written.
21062This may be fewer bytes than supplied in the request.
21063
21064@item @code{E00}
21065The request was malformed, or @var{annex} was invalid.
21066
21067@item @code{E}@var{nn}
21068The offset was invalid, or there was an error encountered writing the data.
21069@var{nn} is a hex-encoded @code{errno} value.
21070
21071@item @code{""} (empty)
21072An empty reply indicates the @var{object} or @var{annex} string was not
21073recognized by the stub, or that the object does not support writing.
21074@end table
21075
21076@item @code{qPart}:@var{object}:@var{operation}:@dots{}
21077Requests of this form may be added in the future. When a stub does
21078not recognize the @var{object} keyword, or its support for
21079@var{object} does not recognize the @var{operation} keyword,
21080the stub must respond with an empty packet.
83761cbd
KB
21081
21082@item @code{qGetTLSAddr}:@var{thread-id},@var{offset},@var{lm} --- get thread local storage address
21083
21084Fetch the address associated with thread local storage specified
21085by @var{thread-id}, @var{offset}, and @var{lm}.
21086
21087@var{thread-id} is the (big endian, hex encoded) thread id associated with the
21088thread for which to fetch the TLS address.
21089
21090@var{offset} is the (big endian, hex encoded) offset associated with the
21091thread local variable. (This offset is obtained from the debug
21092information associated with the variable.)
21093
21094@var{lm} is the (big endian, hex encoded) OS/ABI specific encoding of the
21095the load module associated with the thread local storage. For example,
21096a @sc{gnu}/Linux system will pass the link map address of the shared
21097object associated with the thread local storage under consideration.
21098Other operating environments may choose to represent the load module
21099differently, so the precise meaning of this parameter will vary.
21100
21101Reply:
21102@table @asis
68c71a2e 21103@item @var{XX@dots{}}
83761cbd
KB
21104Hex encoded (big endian) bytes representing the address of the thread
21105local storage requested.
21106
21107@item @code{E}@var{nn} (where @var{nn} are hex digits)
21108An error occurred.
21109
21110@item @code{""} (empty)
21111An empty reply indicates that @code{qGetTLSAddr} is not supported by the stub.
21112@end table
21113
ee2d5c50
AC
21114@end table
21115
21116@node Register Packet Format
21117@section Register Packet Format
eb12ee30 21118
8e04817f 21119The following @samp{g}/@samp{G} packets have previously been defined.
ee2d5c50
AC
21120In the below, some thirty-two bit registers are transferred as
21121sixty-four bits. Those registers should be zero/sign extended (which?)
21122to fill the space allocated. Register bytes are transfered in target
21123byte order. The two nibbles within a register byte are transfered
21124most-significant - least-significant.
eb12ee30 21125
ee2d5c50 21126@table @r
eb12ee30 21127
8e04817f 21128@item MIPS32
ee2d5c50 21129
8e04817f
AC
21130All registers are transfered as thirty-two bit quantities in the order:
2113132 general-purpose; sr; lo; hi; bad; cause; pc; 32 floating-point
21132registers; fsr; fir; fp.
eb12ee30 21133
8e04817f 21134@item MIPS64
ee2d5c50 21135
8e04817f
AC
21136All registers are transfered as sixty-four bit quantities (including
21137thirty-two bit registers such as @code{sr}). The ordering is the same
21138as @code{MIPS32}.
eb12ee30 21139
ee2d5c50
AC
21140@end table
21141
21142@node Examples
21143@section Examples
eb12ee30 21144
8e04817f
AC
21145Example sequence of a target being re-started. Notice how the restart
21146does not get any direct output:
eb12ee30 21147
474c8240 21148@smallexample
d2c6833e
AC
21149-> @code{R00}
21150<- @code{+}
8e04817f 21151@emph{target restarts}
d2c6833e 21152-> @code{?}
8e04817f 21153<- @code{+}
d2c6833e
AC
21154<- @code{T001:1234123412341234}
21155-> @code{+}
474c8240 21156@end smallexample
eb12ee30 21157
8e04817f 21158Example sequence of a target being stepped by a single instruction:
eb12ee30 21159
474c8240 21160@smallexample
d2c6833e 21161-> @code{G1445@dots{}}
8e04817f 21162<- @code{+}
d2c6833e
AC
21163-> @code{s}
21164<- @code{+}
21165@emph{time passes}
21166<- @code{T001:1234123412341234}
8e04817f 21167-> @code{+}
d2c6833e 21168-> @code{g}
8e04817f 21169<- @code{+}
d2c6833e
AC
21170<- @code{1455@dots{}}
21171-> @code{+}
474c8240 21172@end smallexample
eb12ee30 21173
0ce1b118
CV
21174@node File-I/O remote protocol extension
21175@section File-I/O remote protocol extension
21176@cindex File-I/O remote protocol extension
21177
21178@menu
21179* File-I/O Overview::
21180* Protocol basics::
1d8b2f28
JB
21181* The F request packet::
21182* The F reply packet::
0ce1b118
CV
21183* Memory transfer::
21184* The Ctrl-C message::
21185* Console I/O::
21186* The isatty call::
21187* The system call::
21188* List of supported calls::
21189* Protocol specific representation of datatypes::
21190* Constants::
21191* File-I/O Examples::
21192@end menu
21193
21194@node File-I/O Overview
21195@subsection File-I/O Overview
21196@cindex file-i/o overview
21197
21198The File I/O remote protocol extension (short: File-I/O) allows the
21199target to use the hosts file system and console I/O when calling various
21200system calls. System calls on the target system are translated into a
21201remote protocol packet to the host system which then performs the needed
21202actions and returns with an adequate response packet to the target system.
21203This simulates file system operations even on targets that lack file systems.
21204
21205The protocol is defined host- and target-system independent. It uses
21206it's own independent representation of datatypes and values. Both,
21207@value{GDBN} and the target's @value{GDBN} stub are responsible for
21208translating the system dependent values into the unified protocol values
21209when data is transmitted.
21210
21211The communication is synchronous. A system call is possible only
21212when GDB is waiting for the @samp{C}, @samp{c}, @samp{S} or @samp{s}
21213packets. While @value{GDBN} handles the request for a system call,
21214the target is stopped to allow deterministic access to the target's
21215memory. Therefore File-I/O is not interuptible by target signals. It
21216is possible to interrupt File-I/O by a user interrupt (Ctrl-C), though.
21217
21218The target's request to perform a host system call does not finish
21219the latest @samp{C}, @samp{c}, @samp{S} or @samp{s} action. That means,
21220after finishing the system call, the target returns to continuing the
21221previous activity (continue, step). No additional continue or step
21222request from @value{GDBN} is required.
21223
21224@smallexample
f7dc1244 21225(@value{GDBP}) continue
0ce1b118
CV
21226 <- target requests 'system call X'
21227 target is stopped, @value{GDBN} executes system call
21228 -> GDB returns result
21229 ... target continues, GDB returns to wait for the target
21230 <- target hits breakpoint and sends a Txx packet
21231@end smallexample
21232
21233The protocol is only used for files on the host file system and
21234for I/O on the console. Character or block special devices, pipes,
21235named pipes or sockets or any other communication method on the host
21236system are not supported by this protocol.
21237
21238@node Protocol basics
21239@subsection Protocol basics
21240@cindex protocol basics, file-i/o
21241
21242The File-I/O protocol uses the @code{F} packet, as request as well
21243as as reply packet. Since a File-I/O system call can only occur when
b383017d 21244@value{GDBN} is waiting for the continuing or stepping target, the
0ce1b118
CV
21245File-I/O request is a reply that @value{GDBN} has to expect as a result
21246of a former @samp{C}, @samp{c}, @samp{S} or @samp{s} packet.
21247This @code{F} packet contains all information needed to allow @value{GDBN}
21248to call the appropriate host system call:
21249
21250@itemize @bullet
b383017d 21251@item
0ce1b118
CV
21252A unique identifier for the requested system call.
21253
21254@item
21255All parameters to the system call. Pointers are given as addresses
21256in the target memory address space. Pointers to strings are given as
b383017d 21257pointer/length pair. Numerical values are given as they are.
0ce1b118
CV
21258Numerical control values are given in a protocol specific representation.
21259
21260@end itemize
21261
21262At that point @value{GDBN} has to perform the following actions.
21263
21264@itemize @bullet
b383017d 21265@item
0ce1b118
CV
21266If parameter pointer values are given, which point to data needed as input
21267to a system call, @value{GDBN} requests this data from the target with a
21268standard @code{m} packet request. This additional communication has to be
21269expected by the target implementation and is handled as any other @code{m}
21270packet.
21271
21272@item
21273@value{GDBN} translates all value from protocol representation to host
21274representation as needed. Datatypes are coerced into the host types.
21275
21276@item
21277@value{GDBN} calls the system call
21278
21279@item
21280It then coerces datatypes back to protocol representation.
21281
21282@item
21283If pointer parameters in the request packet point to buffer space in which
21284a system call is expected to copy data to, the data is transmitted to the
21285target using a @code{M} or @code{X} packet. This packet has to be expected
21286by the target implementation and is handled as any other @code{M} or @code{X}
21287packet.
21288
21289@end itemize
21290
21291Eventually @value{GDBN} replies with another @code{F} packet which contains all
21292necessary information for the target to continue. This at least contains
21293
21294@itemize @bullet
21295@item
21296Return value.
21297
21298@item
21299@code{errno}, if has been changed by the system call.
21300
21301@item
21302``Ctrl-C'' flag.
21303
21304@end itemize
21305
21306After having done the needed type and value coercion, the target continues
21307the latest continue or step action.
21308
1d8b2f28 21309@node The F request packet
0ce1b118
CV
21310@subsection The @code{F} request packet
21311@cindex file-i/o request packet
21312@cindex @code{F} request packet
21313
21314The @code{F} request packet has the following format:
21315
21316@table @samp
21317
21318@smallexample
21319@code{F}@var{call-id}@code{,}@var{parameter@dots{}}
21320@end smallexample
21321
21322@var{call-id} is the identifier to indicate the host system call to be called.
21323This is just the name of the function.
21324
21325@var{parameter@dots{}} are the parameters to the system call.
21326
b383017d 21327@end table
0ce1b118
CV
21328
21329Parameters are hexadecimal integer values, either the real values in case
21330of scalar datatypes, as pointers to target buffer space in case of compound
21331datatypes and unspecified memory areas or as pointer/length pairs in case
21332of string parameters. These are appended to the call-id, each separated
21333from its predecessor by a comma. All values are transmitted in ASCII
21334string representation, pointer/length pairs separated by a slash.
21335
1d8b2f28 21336@node The F reply packet
0ce1b118
CV
21337@subsection The @code{F} reply packet
21338@cindex file-i/o reply packet
21339@cindex @code{F} reply packet
21340
21341The @code{F} reply packet has the following format:
21342
21343@table @samp
21344
21345@smallexample
21346@code{F}@var{retcode}@code{,}@var{errno}@code{,}@var{Ctrl-C flag}@code{;}@var{call specific attachment}
21347@end smallexample
21348
21349@var{retcode} is the return code of the system call as hexadecimal value.
21350
21351@var{errno} is the errno set by the call, in protocol specific representation.
21352This parameter can be omitted if the call was successful.
21353
21354@var{Ctrl-C flag} is only send if the user requested a break. In this
21355case, @var{errno} must be send as well, even if the call was successful.
21356The @var{Ctrl-C flag} itself consists of the character 'C':
21357
21358@smallexample
21359F0,0,C
21360@end smallexample
21361
21362@noindent
21363or, if the call was interupted before the host call has been performed:
21364
21365@smallexample
21366F-1,4,C
21367@end smallexample
21368
21369@noindent
21370assuming 4 is the protocol specific representation of @code{EINTR}.
21371
21372@end table
21373
21374@node Memory transfer
21375@subsection Memory transfer
21376@cindex memory transfer, in file-i/o protocol
21377
21378Structured data which is transferred using a memory read or write as e.g.@:
21379a @code{struct stat} is expected to be in a protocol specific format with
21380all scalar multibyte datatypes being big endian. This should be done by
21381the target before the @code{F} packet is sent resp.@: by @value{GDBN} before
21382it transfers memory to the target. Transferred pointers to structured
21383data should point to the already coerced data at any time.
21384
21385@node The Ctrl-C message
21386@subsection The Ctrl-C message
21387@cindex ctrl-c message, in file-i/o protocol
21388
21389A special case is, if the @var{Ctrl-C flag} is set in the @value{GDBN}
21390reply packet. In this case the target should behave, as if it had
21391gotten a break message. The meaning for the target is ``system call
21392interupted by @code{SIGINT}''. Consequentially, the target should actually stop
21393(as with a break message) and return to @value{GDBN} with a @code{T02}
b383017d 21394packet. In this case, it's important for the target to know, in which
0ce1b118
CV
21395state the system call was interrupted. Since this action is by design
21396not an atomic operation, we have to differ between two cases:
21397
21398@itemize @bullet
21399@item
21400The system call hasn't been performed on the host yet.
21401
21402@item
21403The system call on the host has been finished.
21404
21405@end itemize
21406
21407These two states can be distinguished by the target by the value of the
21408returned @code{errno}. If it's the protocol representation of @code{EINTR}, the system
21409call hasn't been performed. This is equivalent to the @code{EINTR} handling
21410on POSIX systems. In any other case, the target may presume that the
21411system call has been finished --- successful or not --- and should behave
21412as if the break message arrived right after the system call.
21413
21414@value{GDBN} must behave reliable. If the system call has not been called
21415yet, @value{GDBN} may send the @code{F} reply immediately, setting @code{EINTR} as
21416@code{errno} in the packet. If the system call on the host has been finished
21417before the user requests a break, the full action must be finshed by
21418@value{GDBN}. This requires sending @code{M} or @code{X} packets as they fit.
21419The @code{F} packet may only be send when either nothing has happened
21420or the full action has been completed.
21421
21422@node Console I/O
21423@subsection Console I/O
21424@cindex console i/o as part of file-i/o
21425
21426By default and if not explicitely closed by the target system, the file
21427descriptors 0, 1 and 2 are connected to the @value{GDBN} console. Output
21428on the @value{GDBN} console is handled as any other file output operation
21429(@code{write(1, @dots{})} or @code{write(2, @dots{})}). Console input is handled
21430by @value{GDBN} so that after the target read request from file descriptor
214310 all following typing is buffered until either one of the following
21432conditions is met:
21433
21434@itemize @bullet
21435@item
21436The user presses @kbd{Ctrl-C}. The behaviour is as explained above, the
21437@code{read}
21438system call is treated as finished.
21439
21440@item
21441The user presses @kbd{Enter}. This is treated as end of input with a trailing
21442line feed.
21443
21444@item
21445The user presses @kbd{Ctrl-D}. This is treated as end of input. No trailing
21446character, especially no Ctrl-D is appended to the input.
21447
21448@end itemize
21449
21450If the user has typed more characters as fit in the buffer given to
21451the read call, the trailing characters are buffered in @value{GDBN} until
21452either another @code{read(0, @dots{})} is requested by the target or debugging
21453is stopped on users request.
21454
21455@node The isatty call
21456@subsection The isatty(3) call
21457@cindex isatty call, file-i/o protocol
21458
21459A special case in this protocol is the library call @code{isatty} which
21460is implemented as it's own call inside of this protocol. It returns
214611 to the target if the file descriptor given as parameter is attached
21462to the @value{GDBN} console, 0 otherwise. Implementing through system calls
21463would require implementing @code{ioctl} and would be more complex than
21464needed.
21465
21466@node The system call
21467@subsection The system(3) call
21468@cindex system call, file-i/o protocol
21469
21470The other special case in this protocol is the @code{system} call which
21471is implemented as it's own call, too. @value{GDBN} is taking over the full
21472task of calling the necessary host calls to perform the @code{system}
21473call. The return value of @code{system} is simplified before it's returned
21474to the target. Basically, the only signal transmitted back is @code{EINTR}
21475in case the user pressed @kbd{Ctrl-C}. Otherwise the return value consists
21476entirely of the exit status of the called command.
21477
21478Due to security concerns, the @code{system} call is refused to be called
b383017d 21479by @value{GDBN} by default. The user has to allow this call explicitly by
0ce1b118
CV
21480entering
21481
21482@table @samp
21483@kindex set remote system-call-allowed 1
21484@item @code{set remote system-call-allowed 1}
21485@end table
21486
21487Disabling the @code{system} call is done by
21488
21489@table @samp
21490@kindex set remote system-call-allowed 0
21491@item @code{set remote system-call-allowed 0}
21492@end table
21493
21494The current setting is shown by typing
21495
21496@table @samp
21497@kindex show remote system-call-allowed
21498@item @code{show remote system-call-allowed}
21499@end table
21500
21501@node List of supported calls
21502@subsection List of supported calls
21503@cindex list of supported file-i/o calls
21504
21505@menu
21506* open::
21507* close::
21508* read::
21509* write::
21510* lseek::
21511* rename::
21512* unlink::
21513* stat/fstat::
21514* gettimeofday::
21515* isatty::
21516* system::
21517@end menu
21518
21519@node open
21520@unnumberedsubsubsec open
21521@cindex open, file-i/o system call
21522
21523@smallexample
21524@exdent Synopsis:
21525int open(const char *pathname, int flags);
21526int open(const char *pathname, int flags, mode_t mode);
21527
b383017d 21528@exdent Request:
0ce1b118
CV
21529Fopen,pathptr/len,flags,mode
21530@end smallexample
21531
21532@noindent
21533@code{flags} is the bitwise or of the following values:
21534
21535@table @code
b383017d 21536@item O_CREAT
0ce1b118
CV
21537If the file does not exist it will be created. The host
21538rules apply as far as file ownership and time stamps
21539are concerned.
21540
b383017d 21541@item O_EXCL
0ce1b118
CV
21542When used with O_CREAT, if the file already exists it is
21543an error and open() fails.
21544
b383017d 21545@item O_TRUNC
0ce1b118
CV
21546If the file already exists and the open mode allows
21547writing (O_RDWR or O_WRONLY is given) it will be
21548truncated to length 0.
21549
b383017d 21550@item O_APPEND
0ce1b118
CV
21551The file is opened in append mode.
21552
b383017d 21553@item O_RDONLY
0ce1b118
CV
21554The file is opened for reading only.
21555
b383017d 21556@item O_WRONLY
0ce1b118
CV
21557The file is opened for writing only.
21558
b383017d 21559@item O_RDWR
0ce1b118
CV
21560The file is opened for reading and writing.
21561
21562@noindent
21563Each other bit is silently ignored.
21564
21565@end table
21566
21567@noindent
21568@code{mode} is the bitwise or of the following values:
21569
21570@table @code
b383017d 21571@item S_IRUSR
0ce1b118
CV
21572User has read permission.
21573
b383017d 21574@item S_IWUSR
0ce1b118
CV
21575User has write permission.
21576
b383017d 21577@item S_IRGRP
0ce1b118
CV
21578Group has read permission.
21579
b383017d 21580@item S_IWGRP
0ce1b118
CV
21581Group has write permission.
21582
b383017d 21583@item S_IROTH
0ce1b118
CV
21584Others have read permission.
21585
b383017d 21586@item S_IWOTH
0ce1b118
CV
21587Others have write permission.
21588
21589@noindent
21590Each other bit is silently ignored.
21591
21592@end table
21593
21594@smallexample
21595@exdent Return value:
21596open returns the new file descriptor or -1 if an error
21597occured.
21598
21599@exdent Errors:
21600@end smallexample
21601
21602@table @code
b383017d 21603@item EEXIST
0ce1b118
CV
21604pathname already exists and O_CREAT and O_EXCL were used.
21605
b383017d 21606@item EISDIR
0ce1b118
CV
21607pathname refers to a directory.
21608
b383017d 21609@item EACCES
0ce1b118
CV
21610The requested access is not allowed.
21611
21612@item ENAMETOOLONG
21613pathname was too long.
21614
b383017d 21615@item ENOENT
0ce1b118
CV
21616A directory component in pathname does not exist.
21617
b383017d 21618@item ENODEV
0ce1b118
CV
21619pathname refers to a device, pipe, named pipe or socket.
21620
b383017d 21621@item EROFS
0ce1b118
CV
21622pathname refers to a file on a read-only filesystem and
21623write access was requested.
21624
b383017d 21625@item EFAULT
0ce1b118
CV
21626pathname is an invalid pointer value.
21627
b383017d 21628@item ENOSPC
0ce1b118
CV
21629No space on device to create the file.
21630
b383017d 21631@item EMFILE
0ce1b118
CV
21632The process already has the maximum number of files open.
21633
b383017d 21634@item ENFILE
0ce1b118
CV
21635The limit on the total number of files open on the system
21636has been reached.
21637
b383017d 21638@item EINTR
0ce1b118
CV
21639The call was interrupted by the user.
21640@end table
21641
21642@node close
21643@unnumberedsubsubsec close
21644@cindex close, file-i/o system call
21645
21646@smallexample
b383017d 21647@exdent Synopsis:
0ce1b118
CV
21648int close(int fd);
21649
b383017d 21650@exdent Request:
0ce1b118
CV
21651Fclose,fd
21652
21653@exdent Return value:
21654close returns zero on success, or -1 if an error occurred.
21655
21656@exdent Errors:
21657@end smallexample
21658
21659@table @code
b383017d 21660@item EBADF
0ce1b118
CV
21661fd isn't a valid open file descriptor.
21662
b383017d 21663@item EINTR
0ce1b118
CV
21664The call was interrupted by the user.
21665@end table
21666
21667@node read
21668@unnumberedsubsubsec read
21669@cindex read, file-i/o system call
21670
21671@smallexample
b383017d 21672@exdent Synopsis:
0ce1b118
CV
21673int read(int fd, void *buf, unsigned int count);
21674
b383017d 21675@exdent Request:
0ce1b118
CV
21676Fread,fd,bufptr,count
21677
21678@exdent Return value:
21679On success, the number of bytes read is returned.
21680Zero indicates end of file. If count is zero, read
b383017d 21681returns zero as well. On error, -1 is returned.
0ce1b118
CV
21682
21683@exdent Errors:
21684@end smallexample
21685
21686@table @code
b383017d 21687@item EBADF
0ce1b118
CV
21688fd is not a valid file descriptor or is not open for
21689reading.
21690
b383017d 21691@item EFAULT
0ce1b118
CV
21692buf is an invalid pointer value.
21693
b383017d 21694@item EINTR
0ce1b118
CV
21695The call was interrupted by the user.
21696@end table
21697
21698@node write
21699@unnumberedsubsubsec write
21700@cindex write, file-i/o system call
21701
21702@smallexample
b383017d 21703@exdent Synopsis:
0ce1b118
CV
21704int write(int fd, const void *buf, unsigned int count);
21705
b383017d 21706@exdent Request:
0ce1b118
CV
21707Fwrite,fd,bufptr,count
21708
21709@exdent Return value:
21710On success, the number of bytes written are returned.
21711Zero indicates nothing was written. On error, -1
21712is returned.
21713
21714@exdent Errors:
21715@end smallexample
21716
21717@table @code
b383017d 21718@item EBADF
0ce1b118
CV
21719fd is not a valid file descriptor or is not open for
21720writing.
21721
b383017d 21722@item EFAULT
0ce1b118
CV
21723buf is an invalid pointer value.
21724
b383017d 21725@item EFBIG
0ce1b118
CV
21726An attempt was made to write a file that exceeds the
21727host specific maximum file size allowed.
21728
b383017d 21729@item ENOSPC
0ce1b118
CV
21730No space on device to write the data.
21731
b383017d 21732@item EINTR
0ce1b118
CV
21733The call was interrupted by the user.
21734@end table
21735
21736@node lseek
21737@unnumberedsubsubsec lseek
21738@cindex lseek, file-i/o system call
21739
21740@smallexample
b383017d 21741@exdent Synopsis:
0ce1b118
CV
21742long lseek (int fd, long offset, int flag);
21743
b383017d 21744@exdent Request:
0ce1b118
CV
21745Flseek,fd,offset,flag
21746@end smallexample
21747
21748@code{flag} is one of:
21749
21750@table @code
b383017d 21751@item SEEK_SET
0ce1b118
CV
21752The offset is set to offset bytes.
21753
b383017d 21754@item SEEK_CUR
0ce1b118
CV
21755The offset is set to its current location plus offset
21756bytes.
21757
b383017d 21758@item SEEK_END
0ce1b118
CV
21759The offset is set to the size of the file plus offset
21760bytes.
21761@end table
21762
21763@smallexample
21764@exdent Return value:
21765On success, the resulting unsigned offset in bytes from
21766the beginning of the file is returned. Otherwise, a
21767value of -1 is returned.
21768
21769@exdent Errors:
21770@end smallexample
21771
21772@table @code
b383017d 21773@item EBADF
0ce1b118
CV
21774fd is not a valid open file descriptor.
21775
b383017d 21776@item ESPIPE
0ce1b118
CV
21777fd is associated with the @value{GDBN} console.
21778
b383017d 21779@item EINVAL
0ce1b118
CV
21780flag is not a proper value.
21781
b383017d 21782@item EINTR
0ce1b118
CV
21783The call was interrupted by the user.
21784@end table
21785
21786@node rename
21787@unnumberedsubsubsec rename
21788@cindex rename, file-i/o system call
21789
21790@smallexample
b383017d 21791@exdent Synopsis:
0ce1b118
CV
21792int rename(const char *oldpath, const char *newpath);
21793
b383017d 21794@exdent Request:
0ce1b118
CV
21795Frename,oldpathptr/len,newpathptr/len
21796
21797@exdent Return value:
21798On success, zero is returned. On error, -1 is returned.
21799
21800@exdent Errors:
21801@end smallexample
21802
21803@table @code
b383017d 21804@item EISDIR
0ce1b118
CV
21805newpath is an existing directory, but oldpath is not a
21806directory.
21807
b383017d 21808@item EEXIST
0ce1b118
CV
21809newpath is a non-empty directory.
21810
b383017d 21811@item EBUSY
0ce1b118
CV
21812oldpath or newpath is a directory that is in use by some
21813process.
21814
b383017d 21815@item EINVAL
0ce1b118
CV
21816An attempt was made to make a directory a subdirectory
21817of itself.
21818
b383017d 21819@item ENOTDIR
0ce1b118
CV
21820A component used as a directory in oldpath or new
21821path is not a directory. Or oldpath is a directory
21822and newpath exists but is not a directory.
21823
b383017d 21824@item EFAULT
0ce1b118
CV
21825oldpathptr or newpathptr are invalid pointer values.
21826
b383017d 21827@item EACCES
0ce1b118
CV
21828No access to the file or the path of the file.
21829
21830@item ENAMETOOLONG
b383017d 21831
0ce1b118
CV
21832oldpath or newpath was too long.
21833
b383017d 21834@item ENOENT
0ce1b118
CV
21835A directory component in oldpath or newpath does not exist.
21836
b383017d 21837@item EROFS
0ce1b118
CV
21838The file is on a read-only filesystem.
21839
b383017d 21840@item ENOSPC
0ce1b118
CV
21841The device containing the file has no room for the new
21842directory entry.
21843
b383017d 21844@item EINTR
0ce1b118
CV
21845The call was interrupted by the user.
21846@end table
21847
21848@node unlink
21849@unnumberedsubsubsec unlink
21850@cindex unlink, file-i/o system call
21851
21852@smallexample
b383017d 21853@exdent Synopsis:
0ce1b118
CV
21854int unlink(const char *pathname);
21855
b383017d 21856@exdent Request:
0ce1b118
CV
21857Funlink,pathnameptr/len
21858
21859@exdent Return value:
21860On success, zero is returned. On error, -1 is returned.
21861
21862@exdent Errors:
21863@end smallexample
21864
21865@table @code
b383017d 21866@item EACCES
0ce1b118
CV
21867No access to the file or the path of the file.
21868
b383017d 21869@item EPERM
0ce1b118
CV
21870The system does not allow unlinking of directories.
21871
b383017d 21872@item EBUSY
0ce1b118
CV
21873The file pathname cannot be unlinked because it's
21874being used by another process.
21875
b383017d 21876@item EFAULT
0ce1b118
CV
21877pathnameptr is an invalid pointer value.
21878
21879@item ENAMETOOLONG
21880pathname was too long.
21881
b383017d 21882@item ENOENT
0ce1b118
CV
21883A directory component in pathname does not exist.
21884
b383017d 21885@item ENOTDIR
0ce1b118
CV
21886A component of the path is not a directory.
21887
b383017d 21888@item EROFS
0ce1b118
CV
21889The file is on a read-only filesystem.
21890
b383017d 21891@item EINTR
0ce1b118
CV
21892The call was interrupted by the user.
21893@end table
21894
21895@node stat/fstat
21896@unnumberedsubsubsec stat/fstat
21897@cindex fstat, file-i/o system call
21898@cindex stat, file-i/o system call
21899
21900@smallexample
b383017d 21901@exdent Synopsis:
0ce1b118
CV
21902int stat(const char *pathname, struct stat *buf);
21903int fstat(int fd, struct stat *buf);
21904
b383017d 21905@exdent Request:
0ce1b118
CV
21906Fstat,pathnameptr/len,bufptr
21907Ffstat,fd,bufptr
21908
21909@exdent Return value:
21910On success, zero is returned. On error, -1 is returned.
21911
21912@exdent Errors:
21913@end smallexample
21914
21915@table @code
b383017d 21916@item EBADF
0ce1b118
CV
21917fd is not a valid open file.
21918
b383017d 21919@item ENOENT
0ce1b118
CV
21920A directory component in pathname does not exist or the
21921path is an empty string.
21922
b383017d 21923@item ENOTDIR
0ce1b118
CV
21924A component of the path is not a directory.
21925
b383017d 21926@item EFAULT
0ce1b118
CV
21927pathnameptr is an invalid pointer value.
21928
b383017d 21929@item EACCES
0ce1b118
CV
21930No access to the file or the path of the file.
21931
21932@item ENAMETOOLONG
21933pathname was too long.
21934
b383017d 21935@item EINTR
0ce1b118
CV
21936The call was interrupted by the user.
21937@end table
21938
21939@node gettimeofday
21940@unnumberedsubsubsec gettimeofday
21941@cindex gettimeofday, file-i/o system call
21942
21943@smallexample
b383017d 21944@exdent Synopsis:
0ce1b118
CV
21945int gettimeofday(struct timeval *tv, void *tz);
21946
b383017d 21947@exdent Request:
0ce1b118
CV
21948Fgettimeofday,tvptr,tzptr
21949
21950@exdent Return value:
21951On success, 0 is returned, -1 otherwise.
21952
21953@exdent Errors:
21954@end smallexample
21955
21956@table @code
b383017d 21957@item EINVAL
0ce1b118
CV
21958tz is a non-NULL pointer.
21959
b383017d 21960@item EFAULT
0ce1b118
CV
21961tvptr and/or tzptr is an invalid pointer value.
21962@end table
21963
21964@node isatty
21965@unnumberedsubsubsec isatty
21966@cindex isatty, file-i/o system call
21967
21968@smallexample
b383017d 21969@exdent Synopsis:
0ce1b118
CV
21970int isatty(int fd);
21971
b383017d 21972@exdent Request:
0ce1b118
CV
21973Fisatty,fd
21974
21975@exdent Return value:
21976Returns 1 if fd refers to the @value{GDBN} console, 0 otherwise.
21977
21978@exdent Errors:
21979@end smallexample
21980
21981@table @code
b383017d 21982@item EINTR
0ce1b118
CV
21983The call was interrupted by the user.
21984@end table
21985
21986@node system
21987@unnumberedsubsubsec system
21988@cindex system, file-i/o system call
21989
21990@smallexample
b383017d 21991@exdent Synopsis:
0ce1b118
CV
21992int system(const char *command);
21993
b383017d 21994@exdent Request:
0ce1b118
CV
21995Fsystem,commandptr/len
21996
21997@exdent Return value:
21998The value returned is -1 on error and the return status
21999of the command otherwise. Only the exit status of the
22000command is returned, which is extracted from the hosts
22001system return value by calling WEXITSTATUS(retval).
22002In case /bin/sh could not be executed, 127 is returned.
22003
22004@exdent Errors:
22005@end smallexample
22006
22007@table @code
b383017d 22008@item EINTR
0ce1b118
CV
22009The call was interrupted by the user.
22010@end table
22011
22012@node Protocol specific representation of datatypes
22013@subsection Protocol specific representation of datatypes
22014@cindex protocol specific representation of datatypes, in file-i/o protocol
22015
22016@menu
22017* Integral datatypes::
22018* Pointer values::
22019* struct stat::
22020* struct timeval::
22021@end menu
22022
22023@node Integral datatypes
22024@unnumberedsubsubsec Integral datatypes
22025@cindex integral datatypes, in file-i/o protocol
22026
22027The integral datatypes used in the system calls are
22028
22029@smallexample
22030int@r{,} unsigned int@r{,} long@r{,} unsigned long@r{,} mode_t @r{and} time_t
22031@end smallexample
22032
22033@code{Int}, @code{unsigned int}, @code{mode_t} and @code{time_t} are
22034implemented as 32 bit values in this protocol.
22035
b383017d
RM
22036@code{Long} and @code{unsigned long} are implemented as 64 bit types.
22037
0ce1b118
CV
22038@xref{Limits}, for corresponding MIN and MAX values (similar to those
22039in @file{limits.h}) to allow range checking on host and target.
22040
22041@code{time_t} datatypes are defined as seconds since the Epoch.
22042
22043All integral datatypes transferred as part of a memory read or write of a
22044structured datatype e.g.@: a @code{struct stat} have to be given in big endian
22045byte order.
22046
22047@node Pointer values
22048@unnumberedsubsubsec Pointer values
22049@cindex pointer values, in file-i/o protocol
22050
22051Pointers to target data are transmitted as they are. An exception
22052is made for pointers to buffers for which the length isn't
22053transmitted as part of the function call, namely strings. Strings
22054are transmitted as a pointer/length pair, both as hex values, e.g.@:
22055
22056@smallexample
22057@code{1aaf/12}
22058@end smallexample
22059
22060@noindent
22061which is a pointer to data of length 18 bytes at position 0x1aaf.
22062The length is defined as the full string length in bytes, including
22063the trailing null byte. Example:
22064
22065@smallexample
22066``hello, world'' at address 0x123456
22067@end smallexample
22068
22069@noindent
22070is transmitted as
22071
22072@smallexample
22073@code{123456/d}
22074@end smallexample
22075
22076@node struct stat
22077@unnumberedsubsubsec struct stat
22078@cindex struct stat, in file-i/o protocol
22079
22080The buffer of type struct stat used by the target and @value{GDBN} is defined
22081as follows:
22082
22083@smallexample
22084struct stat @{
22085 unsigned int st_dev; /* device */
22086 unsigned int st_ino; /* inode */
22087 mode_t st_mode; /* protection */
22088 unsigned int st_nlink; /* number of hard links */
22089 unsigned int st_uid; /* user ID of owner */
22090 unsigned int st_gid; /* group ID of owner */
22091 unsigned int st_rdev; /* device type (if inode device) */
22092 unsigned long st_size; /* total size, in bytes */
22093 unsigned long st_blksize; /* blocksize for filesystem I/O */
22094 unsigned long st_blocks; /* number of blocks allocated */
22095 time_t st_atime; /* time of last access */
22096 time_t st_mtime; /* time of last modification */
22097 time_t st_ctime; /* time of last change */
22098@};
22099@end smallexample
22100
22101The integral datatypes are conforming to the definitions given in the
22102approriate section (see @ref{Integral datatypes}, for details) so this
22103structure is of size 64 bytes.
22104
22105The values of several fields have a restricted meaning and/or
22106range of values.
22107
22108@smallexample
22109st_dev: 0 file
22110 1 console
22111
22112st_ino: No valid meaning for the target. Transmitted unchanged.
22113
22114st_mode: Valid mode bits are described in Appendix C. Any other
22115 bits have currently no meaning for the target.
22116
22117st_uid: No valid meaning for the target. Transmitted unchanged.
22118
22119st_gid: No valid meaning for the target. Transmitted unchanged.
22120
22121st_rdev: No valid meaning for the target. Transmitted unchanged.
22122
22123st_atime, st_mtime, st_ctime:
22124 These values have a host and file system dependent
22125 accuracy. Especially on Windows hosts the file systems
22126 don't support exact timing values.
22127@end smallexample
22128
22129The target gets a struct stat of the above representation and is
22130responsible to coerce it to the target representation before
22131continuing.
22132
22133Note that due to size differences between the host and target
22134representation of stat members, these members could eventually
22135get truncated on the target.
22136
22137@node struct timeval
22138@unnumberedsubsubsec struct timeval
22139@cindex struct timeval, in file-i/o protocol
22140
22141The buffer of type struct timeval used by the target and @value{GDBN}
22142is defined as follows:
22143
22144@smallexample
b383017d 22145struct timeval @{
0ce1b118
CV
22146 time_t tv_sec; /* second */
22147 long tv_usec; /* microsecond */
22148@};
22149@end smallexample
22150
22151The integral datatypes are conforming to the definitions given in the
22152approriate section (see @ref{Integral datatypes}, for details) so this
22153structure is of size 8 bytes.
22154
22155@node Constants
22156@subsection Constants
22157@cindex constants, in file-i/o protocol
22158
22159The following values are used for the constants inside of the
22160protocol. @value{GDBN} and target are resposible to translate these
22161values before and after the call as needed.
22162
22163@menu
22164* Open flags::
22165* mode_t values::
22166* Errno values::
22167* Lseek flags::
22168* Limits::
22169@end menu
22170
22171@node Open flags
22172@unnumberedsubsubsec Open flags
22173@cindex open flags, in file-i/o protocol
22174
22175All values are given in hexadecimal representation.
22176
22177@smallexample
22178 O_RDONLY 0x0
22179 O_WRONLY 0x1
22180 O_RDWR 0x2
22181 O_APPEND 0x8
22182 O_CREAT 0x200
22183 O_TRUNC 0x400
22184 O_EXCL 0x800
22185@end smallexample
22186
22187@node mode_t values
22188@unnumberedsubsubsec mode_t values
22189@cindex mode_t values, in file-i/o protocol
22190
22191All values are given in octal representation.
22192
22193@smallexample
22194 S_IFREG 0100000
22195 S_IFDIR 040000
22196 S_IRUSR 0400
22197 S_IWUSR 0200
22198 S_IXUSR 0100
22199 S_IRGRP 040
22200 S_IWGRP 020
22201 S_IXGRP 010
22202 S_IROTH 04
22203 S_IWOTH 02
22204 S_IXOTH 01
22205@end smallexample
22206
22207@node Errno values
22208@unnumberedsubsubsec Errno values
22209@cindex errno values, in file-i/o protocol
22210
22211All values are given in decimal representation.
22212
22213@smallexample
22214 EPERM 1
22215 ENOENT 2
22216 EINTR 4
22217 EBADF 9
22218 EACCES 13
22219 EFAULT 14
22220 EBUSY 16
22221 EEXIST 17
22222 ENODEV 19
22223 ENOTDIR 20
22224 EISDIR 21
22225 EINVAL 22
22226 ENFILE 23
22227 EMFILE 24
22228 EFBIG 27
22229 ENOSPC 28
22230 ESPIPE 29
22231 EROFS 30
22232 ENAMETOOLONG 91
22233 EUNKNOWN 9999
22234@end smallexample
22235
22236 EUNKNOWN is used as a fallback error value if a host system returns
22237 any error value not in the list of supported error numbers.
22238
22239@node Lseek flags
22240@unnumberedsubsubsec Lseek flags
22241@cindex lseek flags, in file-i/o protocol
22242
22243@smallexample
22244 SEEK_SET 0
22245 SEEK_CUR 1
22246 SEEK_END 2
22247@end smallexample
22248
22249@node Limits
22250@unnumberedsubsubsec Limits
22251@cindex limits, in file-i/o protocol
22252
22253All values are given in decimal representation.
22254
22255@smallexample
22256 INT_MIN -2147483648
22257 INT_MAX 2147483647
22258 UINT_MAX 4294967295
22259 LONG_MIN -9223372036854775808
22260 LONG_MAX 9223372036854775807
22261 ULONG_MAX 18446744073709551615
22262@end smallexample
22263
22264@node File-I/O Examples
22265@subsection File-I/O Examples
22266@cindex file-i/o examples
22267
22268Example sequence of a write call, file descriptor 3, buffer is at target
22269address 0x1234, 6 bytes should be written:
22270
22271@smallexample
22272<- @code{Fwrite,3,1234,6}
22273@emph{request memory read from target}
22274-> @code{m1234,6}
22275<- XXXXXX
22276@emph{return "6 bytes written"}
22277-> @code{F6}
22278@end smallexample
22279
22280Example sequence of a read call, file descriptor 3, buffer is at target
22281address 0x1234, 6 bytes should be read:
22282
22283@smallexample
22284<- @code{Fread,3,1234,6}
22285@emph{request memory write to target}
22286-> @code{X1234,6:XXXXXX}
22287@emph{return "6 bytes read"}
22288-> @code{F6}
22289@end smallexample
22290
22291Example sequence of a read call, call fails on the host due to invalid
22292file descriptor (EBADF):
22293
22294@smallexample
22295<- @code{Fread,3,1234,6}
22296-> @code{F-1,9}
22297@end smallexample
22298
22299Example sequence of a read call, user presses Ctrl-C before syscall on
22300host is called:
22301
22302@smallexample
22303<- @code{Fread,3,1234,6}
22304-> @code{F-1,4,C}
22305<- @code{T02}
22306@end smallexample
22307
22308Example sequence of a read call, user presses Ctrl-C after syscall on
22309host is called:
22310
22311@smallexample
22312<- @code{Fread,3,1234,6}
22313-> @code{X1234,6:XXXXXX}
22314<- @code{T02}
22315@end smallexample
22316
f418dd93
DJ
22317@include agentexpr.texi
22318
aab4e0ec 22319@include gpl.texi
eb12ee30 22320
2154891a 22321@raisesections
6826cf00 22322@include fdl.texi
2154891a 22323@lowersections
6826cf00 22324
6d2ebf8b 22325@node Index
c906108c
SS
22326@unnumbered Index
22327
22328@printindex cp
22329
22330@tex
22331% I think something like @colophon should be in texinfo. In the
22332% meantime:
22333\long\def\colophon{\hbox to0pt{}\vfill
22334\centerline{The body of this manual is set in}
22335\centerline{\fontname\tenrm,}
22336\centerline{with headings in {\bf\fontname\tenbf}}
22337\centerline{and examples in {\tt\fontname\tentt}.}
22338\centerline{{\it\fontname\tenit\/},}
22339\centerline{{\bf\fontname\tenbf}, and}
22340\centerline{{\sl\fontname\tensl\/}}
22341\centerline{are used for emphasis.}\vfill}
22342\page\colophon
22343% Blame: doc@cygnus.com, 1991.
22344@end tex
22345
c906108c 22346@bye
This page took 2.689123 seconds and 4 git commands to generate.